NeKernel dev
Loading...
Searching...
No Matches
NeFS.h
Go to the documentation of this file.
1/* ========================================
2
3 Copyright (C) 2024-2025, Amlal El Mahrouss, licensed under the Apache 2.0 license.
4
5 FILE: NeFS.h
6 PURPOSE: NeFS (New extended File System) support.
7
8 Revision History:
9
10 ?/?/?: Added file (amlel)
11 12/02/24: Add UUID macro for EPM and GPT partition schemes.
12 3/16/24: Add mandatory sector size, kNeFSSectorSz is set to 2048 by
13default.
14
15======================================== */
16
17#pragma once
18
20#include <KernelKit/DriveMgr.h>
21#include <NeKit/Config.h>
22#include <NeKit/KString.h>
23#include <hint/CompilerHint.h>
24
29
30#define kNeFSInvalidFork (-1)
31#define kNeFSInvalidCatalog (-1)
32#define kNeFSCatalogNameLen (256)
33
34#define kNeFSVolumeName "NeFS Volume"
35
36#define kNeFSMinimumDiskSize (mib_cast(8))
37
38#define kNeFSSectorSz (512)
39
40#define kNeFSIdentLen (8)
41#define kNeFSIdent " NeFS"
42#define kNeFSPadLen (392)
43
44#define kNeFSMetaFilePrefix '$'
45
46#define kNeFSVersionInteger (0x0129)
47#define kNeFSVerionString "1.2.9"
48
50#define kNeFSDataFork "main_data"
51#define kNeFSResourceFork "main_rsrc"
52
53#define kNeFSForkSize (sizeof(NEFS_FORK_STRUCT))
54
55#define kNeFSPartitionTypeStandard (7)
56#define kNeFSPartitionTypePage (8)
57#define kNeFSPartitionTypeBoot (9)
58
59#define kNeFSCatalogKindFile (1)
60#define kNeFSCatalogKindDir (2)
61#define kNeFSCatalogKindAlias (3)
62
64#define kNeFSCatalogKindShared (4)
65
66#define kNeFSCatalogKindResource (5)
67#define kNeFSCatalogKindExecutable (6)
68
69#define kNeFSCatalogKindPage (8)
70
71#define kNeFSCatalogKindDevice (9)
72#define kNeFSCatalogKindLock (10)
73
74#define kNeFSCatalogKindRLE (11)
75#define kNeFSCatalogKindMetaFile (12)
76
77#define kNeFSCatalogKindTTF (13)
78#define kNeFSCatalogKindRIFF (14)
79#define kNeFSCatalogKindMPEG (15)
80#define kNeFSCatalogKindMOFF (16)
81
82#define kNeFSSeparator '/'
83#define kNeFSSeparatorAlt '/'
84
85#define kNeFSUpDir ".."
86#define kNeFSRoot "/"
87#define kNeFSRootAlt "/"
88
89#define kNeFSLF '\r'
90#define kNeFSEOF (-1)
91
92#define kNeFSBitWidth (sizeof(Kernel::Char))
93#define kNeFSLbaType (Kernel::Lba)
94
96#define kNeFSRootCatalogStartAddress (1024)
97#define kNeFSCatalogStartAddress (kNeFSRootCatalogStartAddress + sizeof(NEFS_ROOT_PARTITION_BLOCK))
98
99#define kResourceTypeDialog (10)
100#define kResourceTypeString (11)
101#define kResourceTypeMenu (12)
102#define kResourceTypeSound (13)
103#define kResourceTypeFont (14)
104#define kNeFSPartLen (32)
105
106#define kNeFSFlagDeleted (70)
107#define kNeFSFlagUnallocated (0)
108#define kNeFSFlagCreated (71)
109
110#define kNeFSMimeNameLen (200)
111#define kNeFSForkNameLen (199)
112
113#define kNeFSFrameworkExt ".fwrk/"
114#define kNeFSStepsExt ".step/"
115#define kNeFSApplicationExt ".app/"
116#define kNeFSJournalExt ".jrnl"
117
119struct NEFS_FORK_STRUCT;
121
122enum {
123 kNeFSHardDrive = 0xC0, // Hard Drive
124 kNeFSSolidStateDrive = 0xC1, // Solid State Drive
125 kNeFSOpticalDrive = 0x0C, // Blu-Ray/DVD
127 kNeFSScsiDrive = 0xC4, // SCSI Hard Drive
129 kNeFSUnknown = 0xFF, // Unknown device.
131};
132
133enum {
139};
140
180
204
230
231namespace Kernel {
235
236enum {
243};
244
247
254 public:
255 explicit NeFileSystemParser() = default;
257
258 public:
260
262
263 public:
269
275 Boolean data);
276
278
280
281 _Output NEFS_CATALOG_STRUCT* FindCatalog(_Input const Char* catalog_name, Lba& ou_lba,
282 Bool search_hidden = YES, Bool local_search = NO);
283
285
287 _Input const Int32& kind);
288
290
292 _Input SizeT sz, _Input const Char* name);
293
295 _Input SizeT dataSz, _Input const Char* forkName);
296
298
300
302
304
309 const Char* part_name);
310
311 public:
313};
314
319
321 public:
322 STATIC const Char* Root();
323 STATIC const Char* UpDir();
326};
327
330 private:
332
333 public:
334 explicit NeFileSystemJournal(const char* stamp = nullptr) {
335 if (!stamp) {
336 kout << "Invalid: Journal stamp, using default name.\r";
337 return;
338 }
339
340 (Void)(kout << "Info: Journal stamp: " << stamp << kendl);
341 rt_copy_memory((VoidPtr) stamp, this->mStamp, rt_string_len(stamp));
342 }
343
345
347
349 if (!parser) return NO;
350
351 delete parser->CreateCatalog("/etc/xml/", 0, kNeFSCatalogKindDir);
352 mNode = parser->CreateCatalog(mStamp);
353
354 if (!mNode) return NO;
355
356 return YES;
357 }
358
360 if (!parser) return NO;
361
362 auto node = parser->GetCatalog(mStamp);
363
364 if (node) {
365 mNode = node;
366 return YES;
367 }
368
369 return NO;
370 }
371
373 if (mNode) {
374 delete mNode;
375 mNode = nullptr;
376 return YES;
377 }
378
379 return NO;
380 }
381
382 Bool CommitJournal(NeFileSystemParser* parser, Char* xml_data, Char* journal_name) {
383 if (!parser || !mNode) return NO;
384
385 NEFS_FORK_STRUCT new_fork{};
386
388 rt_copy_memory(journal_name, new_fork.ForkName, rt_string_len(journal_name));
389
390 new_fork.ResourceKind = 0;
391 new_fork.ResourceId = 0;
392 new_fork.ResourceFlags = 0;
393 new_fork.DataSize = rt_string_len(xml_data);
394 new_fork.Kind = kNeFSRsrcForkKind;
395
396 if (!parser->CreateFork(new_fork)) return NO;
397
398 (Void)(kout << "XML commit: " << xml_data << " to fork: " << journal_name << kendl);
399
400 auto ret = parser->WriteCatalog(new_fork.CatalogName, YES, xml_data, rt_string_len(xml_data),
401 new_fork.ForkName);
402
403 return ret;
404 }
405
406 private:
408};
409
410namespace NeFS {
412} // namespace NeFS
413} // namespace Kernel
#define _Output
Definition CompilerHint.h:15
#define _Input
Definition CompilerHint.h:14
#define _InOut
Definition CompilerHint.h:22
#define kendl
Definition DebugOutput.h:195
#define kout
Definition DebugOutput.h:189
#define NE_COPY_DELETE(KLASS)
Definition Detail.h:13
#define NE_MOVE_DELETE(KLASS)
Definition Detail.h:21
#define NE_COPY_DEFAULT(KLASS)
Definition Detail.h:17
Drive Manager.
#define STATIC
#define PACKED
#define YES
#define NO
#define BOOL
#define kNeFSCatalogKindDir
Definition NeFS.h:60
#define kNeFSForkNameLen
Definition NeFS.h:111
#define kNeFSIdentLen
Definition NeFS.h:40
#define kNeFSPartLen
Definition NeFS.h:104
#define kNeFSMimeNameLen
Definition NeFS.h:110
#define kNeFSCatalogNameLen
Definition NeFS.h:32
#define kNeFSPadLen
Definition NeFS.h:42
@ kNeFSSolidStateDrive
Definition NeFS.h:124
@ kNeFSMassStorageDevice
Definition NeFS.h:126
@ kNeFSHardDrive
Definition NeFS.h:123
@ kNeFSFlashDrive
Definition NeFS.h:128
@ kNeFSUnknown
Definition NeFS.h:129
@ kNeFSScsiDrive
Definition NeFS.h:127
@ kNeFSDriveCount
Definition NeFS.h:130
@ kNeFSOpticalDrive
Definition NeFS.h:125
#define kNeFSJournalExt
Definition NeFS.h:116
@ kNeFSStatusError
Definition NeFS.h:136
@ kNeFSStatusLocked
Definition NeFS.h:135
@ kNeFSStatusInvalid
Definition NeFS.h:137
@ kNeFSStatusCount
Definition NeFS.h:138
@ kNeFSStatusUnlocked
Definition NeFS.h:134
Definition NeFS.h:320
STATIC const Char * Root()
STATIC const Char * UpDir()
Journal class for NeFS.
Definition NeFS.h:329
Bool CreateJournal(NeFileSystemParser *parser)
Definition NeFS.h:348
NeFileSystemJournal(const char *stamp=nullptr)
Definition NeFS.h:334
NEFS_CATALOG_STRUCT * mNode
Definition NeFS.h:331
Bool CommitJournal(NeFileSystemParser *parser, Char *xml_data, Char *journal_name)
Definition NeFS.h:382
Char mStamp[kNeFSCatalogNameLen]
Definition NeFS.h:407
Bool ReleaseJournal()
Definition NeFS.h:372
Bool GetJournal(NeFileSystemParser *parser)
Definition NeFS.h:359
Definition NeFS.h:253
_Output Bool Seek(_Input _Output NEFS_CATALOG_STRUCT *catalog, SizeT off)
_Output Bool RemoveCatalog(_Input const Char *catalog)
_Output NEFS_FORK_STRUCT * FindFork(_Input NEFS_CATALOG_STRUCT *catalog, _Input const Char *name, Boolean data)
Find fork inside New filesystem.
_Output BOOL CreateFork(_Input NEFS_FORK_STRUCT &in)
Creates a new fork inside the NeFS partition.
UInt32 mDriveIndex
Definition NeFS.h:312
_Output Void CloseFork(_Input NEFS_FORK_STRUCT *fork)
_Output Void RemoveFork(_Input NEFS_FORK_STRUCT *fork)
_Output NEFS_CATALOG_STRUCT * CreateCatalog(_Input const Char *name)
_Output Bool CloseCatalog(_InOut NEFS_CATALOG_STRUCT *catalog)
_Output NEFS_CATALOG_STRUCT * CreateCatalog(_Input const Char *name, _Input const Int32 &flags, _Input const Int32 &kind)
_Output NEFS_CATALOG_STRUCT * GetCatalog(_Input const Char *name)
_Output NEFS_CATALOG_STRUCT * FindCatalog(_Input const Char *catalog_name, Lba &ou_lba, Bool search_hidden=YES, Bool local_search=NO)
_Output Bool WriteCatalog(_Input const Char *catalog, _Input Bool rsrc, _Input VoidPtr data, _Input SizeT sz, _Input const Char *name)
_Output VoidPtr ReadCatalog(_Input _Output NEFS_CATALOG_STRUCT *catalog, _Input Bool isRsrcFork, _Input SizeT dataSz, _Input const Char *forkName)
_Output Bool Format(_Input _Output DriveTrait *drive, _Input const Int32 flags, const Char *part_name)
Make a EPM+NeFS drive out of the disk.
_Output SizeT Tell(_Input _Output NEFS_CATALOG_STRUCT *catalog)
Definition NeFS.h:410
Boolean fs_init_nefs(Void)
UPS inline definitions.
Definition Device.h:12
char Char
Definition Config.h:51
void Void
Definition Config.h:87
Size rt_string_len(const Char *str)
Definition AsciiUtils.cc:23
__UINT16_TYPE__ UInt16
Definition Config.h:40
__INT64_TYPE__ Int64
Definition Config.h:46
UInt64 Lba
Definition Config.h:90
__SIZE_TYPE__ SizeT
Definition Config.h:60
@ kNeFSSubDriveCount
Definition NeFS.h:242
@ kNeFSSubDriveInvalid
Definition NeFS.h:241
@ kNeFSSubDriveC
Definition NeFS.h:239
@ kNeFSSubDriveB
Definition NeFS.h:238
@ kNeFSSubDriveD
Definition NeFS.h:240
@ kNeFSSubDriveA
Definition NeFS.h:237
__UINT32_TYPE__ UInt32
Definition Config.h:44
void * VoidPtr
Definition Config.h:33
__INT32_TYPE__ Int32
Definition Config.h:38
bool Boolean
Definition Config.h:49
Int rt_copy_memory(const voidPtr src, voidPtr dst, Size len)
ASCII API =========================================================== ///.
Definition AsciiUtils.cc:86
__UINT64_TYPE__ UInt64
Definition Config.h:48
bool Bool
Definition Config.h:50
@ kNeFSDataForkKind
Definition NeFS.h:246
@ kNeFSRsrcForkKind
Definition NeFS.h:246
Media drive trait type.
Definition DriveMgr.h:54
Catalog record type.
Definition NeFS.h:142
BOOL ForkOrCatalog
Definition NeFS.h:143
Kernel::UInt16 CatalogFlags
Custom catalog flags.
Definition NeFS.h:155
Kernel::UInt16 Flags
Catalog flags.
Definition NeFS.h:149
Kernel::Lba NextPrevSibling
Definition NeFS.h:176
Kernel::Lba DataFork
Forks LBA.
Definition NeFS.h:167
Kernel::Lba NextSibling
Buddy allocation tracker.
Definition NeFS.h:171
Kernel::UInt16 Status
Catalog allocation status.
Definition NeFS.h:152
Kernel::Int32 Kind
Catalog kind.
Definition NeFS.h:158
Kernel::Lba NextBestSibling
Best-buddy tracker.
Definition NeFS.h:175
Kernel::Lba ResourceFork
Definition NeFS.h:168
Kernel::Lba DataForkSize
Size of the data fork.
Definition NeFS.h:161
Kernel::UInt32 Checksum
Definition NeFS.h:178
Kernel::Char Name[kNeFSCatalogNameLen]
Definition NeFS.h:145
Kernel::Lba ResourceForkSize
Size of all resource forks.
Definition NeFS.h:164
Kernel::Char Mime[kNeFSMimeNameLen]
Definition NeFS.h:146
Kernel::Lba PrevSibling
Definition NeFS.h:172
Fork type, contains a data page.
Definition NeFS.h:185
Kernel::Int32 Kind
Definition NeFS.h:192
Kernel::Char CatalogName[kNeFSCatalogNameLen]
Definition NeFS.h:189
BOOL ForkOrCatalog
Definition NeFS.h:186
Kernel::Lba PreviousSibling
Definition NeFS.h:202
Kernel::SizeT DataSize
Definition NeFS.h:199
Kernel::Int32 ResourceFlags
Definition NeFS.h:196
Kernel::Int64 ResourceId
Definition NeFS.h:194
Kernel::Int32 ResourceKind
Definition NeFS.h:195
Kernel::Char ForkName[kNeFSForkNameLen]
Definition NeFS.h:188
Kernel::Lba DataOffset
Definition NeFS.h:198
Kernel::Lba NextSibling
Data size according using sector count.
Definition NeFS.h:201
Kernel::Int32 Flags
Definition NeFS.h:191
Partition block type.
Definition NeFS.h:206
Kernel::UInt64 Version
Definition NeFS.h:224
Kernel::SizeT FreeCatalog
Definition NeFS.h:218
Kernel::Char Pad[kNeFSPadLen]
Definition NeFS.h:228
Kernel::SizeT FreeSectors
Definition NeFS.h:219
Kernel::SizeT DiskSize
Definition NeFS.h:216
Kernel::Lba StartCatalog
Definition NeFS.h:213
Kernel::Char Ident[kNeFSIdentLen]
Definition NeFS.h:207
Kernel::SizeT SectorCount
Definition NeFS.h:221
Kernel::Lba EpmBlock
Definition NeFS.h:226
Kernel::Int32 Flags
Definition NeFS.h:210
Kernel::Char PartitionName[kNeFSPartLen]
Definition NeFS.h:208
Kernel::SizeT SectorSize
Definition NeFS.h:222
Kernel::Int32 Kind
Definition NeFS.h:211
Kernel::SizeT CatalogCount
Definition NeFS.h:214