From fb790b07aeba8e22e4190cf3e1834d11ecde6c96 Mon Sep 17 00:00:00 2001 From: Amlal Date: Fri, 25 Apr 2025 13:08:33 +0200 Subject: dev: better .clang-format, ran format command. Signed-off-by: Amlal --- dev/kernel/FSKit/Defines.h | 4 +- dev/kernel/FSKit/Ext2.h | 206 ++++++------ dev/kernel/FSKit/HeFS.h | 620 +++++++++++++++++------------------ dev/kernel/FSKit/IndexableProperty.h | 98 +++--- dev/kernel/FSKit/NeFS.h | 604 ++++++++++++++++------------------ 5 files changed, 738 insertions(+), 794 deletions(-) (limited to 'dev/kernel/FSKit') diff --git a/dev/kernel/FSKit/Defines.h b/dev/kernel/FSKit/Defines.h index 9ab87e0f..c4c4e497 100644 --- a/dev/kernel/FSKit/Defines.h +++ b/dev/kernel/FSKit/Defines.h @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. + Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. ------------------------------------------- */ @@ -8,5 +8,5 @@ #include -#define FSKIT_VERSION "1.0.0" +#define FSKIT_VERSION "1.0.0" #define FSKIT_VERSION_BCD 0x0100 diff --git a/dev/kernel/FSKit/Ext2.h b/dev/kernel/FSKit/Ext2.h index c27eb5f9..17645139 100644 --- a/dev/kernel/FSKit/Ext2.h +++ b/dev/kernel/FSKit/Ext2.h @@ -1,135 +1,133 @@ /* ------------------------------------------- - Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. + Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. ------------------------------------------- */ #pragma once #include -#include #include #include #include +#include /// @file Ext2.h /// @brief EXT2 filesystem structures and constants. -#define kExt2FSMagic (0xEF53) -#define kExt2FSMaxFileNameLen (255U) +#define kExt2FSMagic (0xEF53) +#define kExt2FSMaxFileNameLen (255U) #define kExt2FSSuperblockOffset (1024) -#define kExt2FSRootInodeNumber (2) +#define kExt2FSRootInodeNumber (2) -#define kExt2FSInodeSize (128U) +#define kExt2FSInodeSize (128U) #define kExt2FSBlockSizeBase (1024U) #define kExt2FSRev0 (0) #define kExt2FSRev1 (1) /// @brief EXT2's file types. -enum -{ - kExt2FileTypeUnknown = 0, - kExt2FileTypeRegular = 1, - kExt2FileTypeDirectory = 2, - kExt2FileTypeCharDevice = 3, - kExt2FileTypeBlockDevice = 4, - kExt2FileTypeFIFO = 5, - kExt2FileTypeSocket = 6, - kExt2FileTypeSymbolicLink = 7 +enum { + kExt2FileTypeUnknown = 0, + kExt2FileTypeRegular = 1, + kExt2FileTypeDirectory = 2, + kExt2FileTypeCharDevice = 3, + kExt2FileTypeBlockDevice = 4, + kExt2FileTypeFIFO = 5, + kExt2FileTypeSocket = 6, + kExt2FileTypeSymbolicLink = 7 }; /// @brief The super block structure, located at LBA 1024. -struct PACKED EXT2_SUPER_BLOCK final -{ - Kernel::UInt32 fInodeCount; - Kernel::UInt32 fBlockCount; - Kernel::UInt32 fReservedBlockCount; - Kernel::UInt32 fFreeBlockCount; - Kernel::UInt32 fFreeInodeCount; - Kernel::UInt32 fFirstDataBlock; - Kernel::UInt32 fLogBlockSize; - Kernel::UInt32 fLogFragmentSize; - Kernel::UInt32 fBlocksPerGroup; - Kernel::UInt32 fFragmentsPerGroup; - Kernel::UInt32 fInodesPerGroup; - Kernel::UInt32 fMountTime; - Kernel::UInt32 fWriteTime; - Kernel::UInt16 fMountCount; - Kernel::UInt16 fMaxMountCount; - Kernel::UInt16 fMagic; // should be 0xEF53 - Kernel::UInt16 fState; - Kernel::UInt16 fErrors; - Kernel::UInt16 fMinorRevision; - Kernel::UInt32 fLastCheck; - Kernel::UInt32 fCheckInterval; - Kernel::UInt32 fCreatorOS; - Kernel::UInt32 fRevisionLevel; - Kernel::UInt16 fDefaultUID; - Kernel::UInt16 fDefaultGID; - - // EXT2_DYNAMIC_REV fields - Kernel::UInt32 fFirstInode; - Kernel::UInt16 fInodeSize; - Kernel::UInt16 fBlockGroupNumber; - Kernel::UInt32 fFeatureCompat; - Kernel::UInt32 fFeatureIncompat; - Kernel::UInt32 fFeatureROCompat; - Kernel::UInt8 fUUID[16]; - Kernel::Char fVolumeName[16]; - Kernel::Char fLastMounted[64]; - Kernel::UInt32 fAlgoBitmap; - - // Optional journal fields and padding - Kernel::UInt8 fPreallocBlocks; - Kernel::UInt8 fPreallocDirBlocks; - Kernel::UInt16 fReservedGDTBlocks; - - Kernel::UInt8 fJournalUUID[16]; - Kernel::UInt32 fJournalInode; - Kernel::UInt32 fJournalDevice; - Kernel::UInt32 fLastOrphan; - - Kernel::UInt32 fHashSeed[4]; - Kernel::UInt8 fDefHashVersion; - Kernel::UInt8 fReservedCharPad; - Kernel::UInt16 fReservedWordPad; - Kernel::UInt32 fDefaultMountOpts; - Kernel::UInt32 fFirstMetaBlockGroup; - - Kernel::UInt8 fReserved[760]; // Padding to make 1024 bytes +struct PACKED EXT2_SUPER_BLOCK final { + Kernel::UInt32 fInodeCount; + Kernel::UInt32 fBlockCount; + Kernel::UInt32 fReservedBlockCount; + Kernel::UInt32 fFreeBlockCount; + Kernel::UInt32 fFreeInodeCount; + Kernel::UInt32 fFirstDataBlock; + Kernel::UInt32 fLogBlockSize; + Kernel::UInt32 fLogFragmentSize; + Kernel::UInt32 fBlocksPerGroup; + Kernel::UInt32 fFragmentsPerGroup; + Kernel::UInt32 fInodesPerGroup; + Kernel::UInt32 fMountTime; + Kernel::UInt32 fWriteTime; + Kernel::UInt16 fMountCount; + Kernel::UInt16 fMaxMountCount; + Kernel::UInt16 fMagic; // should be 0xEF53 + Kernel::UInt16 fState; + Kernel::UInt16 fErrors; + Kernel::UInt16 fMinorRevision; + Kernel::UInt32 fLastCheck; + Kernel::UInt32 fCheckInterval; + Kernel::UInt32 fCreatorOS; + Kernel::UInt32 fRevisionLevel; + Kernel::UInt16 fDefaultUID; + Kernel::UInt16 fDefaultGID; + + // EXT2_DYNAMIC_REV fields + Kernel::UInt32 fFirstInode; + Kernel::UInt16 fInodeSize; + Kernel::UInt16 fBlockGroupNumber; + Kernel::UInt32 fFeatureCompat; + Kernel::UInt32 fFeatureIncompat; + Kernel::UInt32 fFeatureROCompat; + Kernel::UInt8 fUUID[16]; + Kernel::Char fVolumeName[16]; + Kernel::Char fLastMounted[64]; + Kernel::UInt32 fAlgoBitmap; + + // Optional journal fields and padding + Kernel::UInt8 fPreallocBlocks; + Kernel::UInt8 fPreallocDirBlocks; + Kernel::UInt16 fReservedGDTBlocks; + + Kernel::UInt8 fJournalUUID[16]; + Kernel::UInt32 fJournalInode; + Kernel::UInt32 fJournalDevice; + Kernel::UInt32 fLastOrphan; + + Kernel::UInt32 fHashSeed[4]; + Kernel::UInt8 fDefHashVersion; + Kernel::UInt8 fReservedCharPad; + Kernel::UInt16 fReservedWordPad; + Kernel::UInt32 fDefaultMountOpts; + Kernel::UInt32 fFirstMetaBlockGroup; + + Kernel::UInt8 fReserved[760]; // Padding to make 1024 bytes }; -struct PACKED EXT2_INODE final -{ - Kernel::UInt16 fMode; - Kernel::UInt16 fUID; - Kernel::UInt32 fSize; - Kernel::UInt32 fAccessTime; - Kernel::UInt32 fCreateTime; - Kernel::UInt32 fModifyTime; - Kernel::UInt32 fDeleteTime; - Kernel::UInt16 fGID; - Kernel::UInt16 fLinksCount; - Kernel::UInt32 fBlocks; - Kernel::UInt32 fFlags; - Kernel::UInt32 fOSD1; - - Kernel::UInt32 fBlock[15]; // 0-11: direct, 12: indirect, 13: double indirect, 14: triple indirect - - Kernel::UInt32 fGeneration; - Kernel::UInt32 fFileACL; - Kernel::UInt32 fDirACL; // Only for revision 1+ - Kernel::UInt32 fFragmentAddr; - - Kernel::UInt8 fOSD2[12]; +struct PACKED EXT2_INODE final { + Kernel::UInt16 fMode; + Kernel::UInt16 fUID; + Kernel::UInt32 fSize; + Kernel::UInt32 fAccessTime; + Kernel::UInt32 fCreateTime; + Kernel::UInt32 fModifyTime; + Kernel::UInt32 fDeleteTime; + Kernel::UInt16 fGID; + Kernel::UInt16 fLinksCount; + Kernel::UInt32 fBlocks; + Kernel::UInt32 fFlags; + Kernel::UInt32 fOSD1; + + Kernel::UInt32 + fBlock[15]; // 0-11: direct, 12: indirect, 13: double indirect, 14: triple indirect + + Kernel::UInt32 fGeneration; + Kernel::UInt32 fFileACL; + Kernel::UInt32 fDirACL; // Only for revision 1+ + Kernel::UInt32 fFragmentAddr; + + Kernel::UInt8 fOSD2[12]; }; -struct PACKED EXT2_DIR_ENTRY final -{ - Kernel::UInt32 fInode; - Kernel::UInt16 fRecordLength; - Kernel::UInt8 fNameLength; - Kernel::UInt8 fFileType; - Kernel::Char fName[kExt2FSMaxFileNameLen]; // null-terminated, not fixed-length in actual on-disk layout +struct PACKED EXT2_DIR_ENTRY final { + Kernel::UInt32 fInode; + Kernel::UInt16 fRecordLength; + Kernel::UInt8 fNameLength; + Kernel::UInt8 fFileType; + Kernel::Char + fName[kExt2FSMaxFileNameLen]; // null-terminated, not fixed-length in actual on-disk layout }; \ No newline at end of file diff --git a/dev/kernel/FSKit/HeFS.h b/dev/kernel/FSKit/HeFS.h index 0ad47739..e4da9a47 100644 --- a/dev/kernel/FSKit/HeFS.h +++ b/dev/kernel/FSKit/HeFS.h @@ -1,24 +1,24 @@ /* ------------------------------------------- - Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. + Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. ------------------------------------------- */ #pragma once #include -#include #include -#include -#include #include #include +#include +#include +#include /// @file HeFS.h /// @brief HeFS filesystem support. -#define kHeFSVersion (0x0101) -#define kHeFSMagic " HeFS" +#define kHeFSVersion (0x0101) +#define kHeFSMagic " HeFS" #define kHeFSMagicLen (8) #define kHeFSFileNameLen (256U) @@ -34,348 +34,334 @@ struct HEFS_BOOT_NODE; struct HEFS_INDEX_NODE; struct HEFS_INDEX_NODE_DIRECTORY; -enum -{ - kHeFSHardDrive = 0xC0, // Hard Drive - kHeFSSolidStateDrive = 0xC1, // Solid State Drive - kHeFSOpticalDrive = 0x0C, // Blu-Ray/DVD - kHeFSMassStorageDevice = 0xCC, // USB - kHeFSScsiDrive = 0xC4, // SCSI Hard Drive - kHeFSFlashDrive = 0xC6, - kHeFSUnknown = 0xFF, // Unknown device. - kHeFSDriveCount = 7, +enum { + kHeFSHardDrive = 0xC0, // Hard Drive + kHeFSSolidStateDrive = 0xC1, // Solid State Drive + kHeFSOpticalDrive = 0x0C, // Blu-Ray/DVD + kHeFSMassStorageDevice = 0xCC, // USB + kHeFSScsiDrive = 0xC4, // SCSI Hard Drive + kHeFSFlashDrive = 0xC6, + kHeFSUnknown = 0xFF, // Unknown device. + kHeFSDriveCount = 7, }; -enum -{ - kHeFSStatusUnlocked = 0x18, - kHeFSStatusLocked, - kHeFSStatusError, - kHeFSStatusInvalid, - kHeFSStatusCount, +enum { + kHeFSStatusUnlocked = 0x18, + kHeFSStatusLocked, + kHeFSStatusError, + kHeFSStatusInvalid, + kHeFSStatusCount, }; -enum -{ - kHeFSEncodingUTF8 = 0x00, - kHeFSEncodingUTF16, - kHeFSEncodingUTF32, - kHeFSEncodingUTF16BE, - kHeFSEncodingUTF16LE, - kHeFSEncodingUTF32BE, - kHeFSEncodingUTF32LE, - kHeFSEncodingUTF8BE, - kHeFSEncodingUTF8LE, - kHeFSEncodingCount, +enum { + kHeFSEncodingUTF8 = 0x00, + kHeFSEncodingUTF16, + kHeFSEncodingUTF32, + kHeFSEncodingUTF16BE, + kHeFSEncodingUTF16LE, + kHeFSEncodingUTF32BE, + kHeFSEncodingUTF32LE, + kHeFSEncodingUTF8BE, + kHeFSEncodingUTF8LE, + kHeFSEncodingCount, }; -inline constexpr UInt16 kHeFSFileKindRegular = 0x00; -inline constexpr UInt16 kHeFSFileKindDirectory = 0x01; -inline constexpr UInt16 kHeFSFileKindBlock = 0x02; -inline constexpr UInt16 kHeFSFileKindCharacter = 0x03; -inline constexpr UInt16 kHeFSFileKindFIFO = 0x04; -inline constexpr UInt16 kHeFSFileKindSocket = 0x05; +inline constexpr UInt16 kHeFSFileKindRegular = 0x00; +inline constexpr UInt16 kHeFSFileKindDirectory = 0x01; +inline constexpr UInt16 kHeFSFileKindBlock = 0x02; +inline constexpr UInt16 kHeFSFileKindCharacter = 0x03; +inline constexpr UInt16 kHeFSFileKindFIFO = 0x04; +inline constexpr UInt16 kHeFSFileKindSocket = 0x05; inline constexpr UInt16 kHeFSFileKindSymbolicLink = 0x06; -inline constexpr UInt16 kHeFSFileKindUnknown = 0x07; -inline constexpr UInt16 kHeFSFileKindCount = 0x08; +inline constexpr UInt16 kHeFSFileKindUnknown = 0x07; +inline constexpr UInt16 kHeFSFileKindCount = 0x08; /// @brief HeFS blocks are array containing sparse blocks of data. -/// @details The blocks are used to store the data of a file. Each block is a pointer to a block of data on the disk. +/// @details The blocks are used to store the data of a file. Each block is a pointer to a block of +/// data on the disk. inline constexpr UInt16 kHeFSBlockCount = 0x10; inline constexpr UInt16 kHeFSInvalidVID = 0xFFFF; -namespace Kernel -{ - /// @brief Access time type. - /// @details Used to keep track of the INode, INodeDir allocation status. - typedef UInt64 ATime; -} // namespace Kernel +namespace Kernel { +/// @brief Access time type. +/// @details Used to keep track of the INode, INodeDir allocation status. +typedef UInt64 ATime; +} // namespace Kernel /// @brief HeFS Boot node. /// @details Acts like a superblock, it contains the information about the filesystem. /// @note The boot node is the first block of the filesystem. -struct PACKED HEFS_BOOT_NODE final -{ - Kernel::Char fMagic[kHeFSMagicLen]; /// @brief Magic number of the filesystem. - Kernel::Utf16Char fVolName[kHeFSPartNameLen]; /// @brief Volume name. - Kernel::UInt32 fVersion; /// @brief Version of the filesystem. - Kernel::UInt64 fBadSectors; /// @brief Number of bad sectors in the filesystem. - Kernel::UInt64 fSectorCount; /// @brief Number of sectors in the filesystem. - Kernel::UInt64 fSectorSize; /// @brief Size of the sector. - Kernel::UInt32 fChecksum; /// @brief Checksum of the boot node. - Kernel::UInt8 fDriveKind; /// @brief Kind of the drive. (Hard Drive, Solid State Drive, Optical Drive, etc). - Kernel::UInt8 fEncoding; /// @brief Encoding of the filesystem. (UTF-8, UTF-16, etc). - Kernel::UInt64 fStartIND; /// @brief Start of the INode tree. - Kernel::UInt64 fEndIND; /// @brief End of the INode tree. - Kernel::UInt64 fINDCount; /// @brief Number of leafs in the INode tree. - Kernel::UInt64 fDiskSize; /// @brief Size of the disk. (Could be a virtual size, that is not the real size of the disk.) - Kernel::UInt16 fDiskStatus; /// @brief Status of the disk. (locked, unlocked, error, invalid). - Kernel::UInt16 fDiskFlags; /// @brief Flags of the disk. (read-only, read-write, etc). - Kernel::UInt16 fVID; /// @brief Virtual Identification Number within an EPM disk. (0xFFFF if not used). - Kernel::UInt64 fReserved; /// @brief Reserved for future use. - Kernel::UInt64 fReserved2; /// @brief Reserved for future use. - Kernel::UInt64 fReserved3; /// @brief Reserved for future use. - Kernel::UInt64 fReserved4; /// @brief Reserved for future use. +struct PACKED HEFS_BOOT_NODE final { + Kernel::Char fMagic[kHeFSMagicLen]; /// @brief Magic number of the filesystem. + Kernel::Utf16Char fVolName[kHeFSPartNameLen]; /// @brief Volume name. + Kernel::UInt32 fVersion; /// @brief Version of the filesystem. + Kernel::UInt64 fBadSectors; /// @brief Number of bad sectors in the filesystem. + Kernel::UInt64 fSectorCount; /// @brief Number of sectors in the filesystem. + Kernel::UInt64 fSectorSize; /// @brief Size of the sector. + Kernel::UInt32 fChecksum; /// @brief Checksum of the boot node. + Kernel::UInt8 fDriveKind; /// @brief Kind of the drive. (Hard Drive, Solid State Drive, Optical + /// Drive, etc). + Kernel::UInt8 fEncoding; /// @brief Encoding of the filesystem. (UTF-8, UTF-16, etc). + Kernel::UInt64 fStartIND; /// @brief Start of the INode tree. + Kernel::UInt64 fEndIND; /// @brief End of the INode tree. + Kernel::UInt64 fINDCount; /// @brief Number of leafs in the INode tree. + Kernel::UInt64 fDiskSize; /// @brief Size of the disk. (Could be a virtual size, that is not the + /// real size of the disk.) + Kernel::UInt16 fDiskStatus; /// @brief Status of the disk. (locked, unlocked, error, invalid). + Kernel::UInt16 fDiskFlags; /// @brief Flags of the disk. (read-only, read-write, etc). + Kernel::UInt16 + fVID; /// @brief Virtual Identification Number within an EPM disk. (0xFFFF if not used). + Kernel::UInt64 fReserved; /// @brief Reserved for future use. + Kernel::UInt64 fReserved2; /// @brief Reserved for future use. + Kernel::UInt64 fReserved3; /// @brief Reserved for future use. + Kernel::UInt64 fReserved4; /// @brief Reserved for future use. }; inline constexpr Kernel::ATime kHeFSTimeInvalid = 0x0000000000000000; -inline constexpr Kernel::ATime kHeFSTimeMax = 0xFFFFFFFFFFFFFFFF; +inline constexpr Kernel::ATime kHeFSTimeMax = 0xFFFFFFFFFFFFFFFF; /// @brief HeFS index node. /// @details This structure is used to store the file information of a file. /// @note The index node is a special type of INode that contains the file information. /// @note The index node is used to store the file information of a file. -struct PACKED ALIGN(8) HEFS_INDEX_NODE final -{ - Kernel::Utf16Char fName[kHeFSFileNameLen]; /// @brief File name. - Kernel::UInt32 fFlags; /// @brief File flags. - Kernel::UInt16 fKind; /// @brief File kind. (Regular, Directory, Block, Character, FIFO, Socket, Symbolic Link, Unknown). - Kernel::UInt32 fSize; /// @brief File size. - Kernel::UInt32 fChecksum, fRecoverChecksum, fBlockChecksum, fLinkChecksum; /// @brief Checksum of the file, recovery checksum, block checksum, link checksum. - - Kernel::ATime fCreated, fAccessed, fModified, fDeleted; /// @brief File timestamps. - Kernel::UInt32 fUID, fGID; /// @brief User ID and Group ID of the file. - Kernel::UInt32 fMode; /// @brief File mode. (read, write, execute, etc). - - Kernel::UInt64 fBlockLinkStart[kHeFSBlockCount]; /// @brief Start of the block link. - Kernel::UInt64 fBlockLinkEnd[kHeFSBlockCount]; /// @brief End of the block link. - - Kernel::UInt64 fBlockStart[kHeFSBlockCount]; /// @brief Start of the block. - Kernel::UInt64 fBlockEnd[kHeFSBlockCount]; /// @brief End of the block. - - Kernel::UInt64 fBlockRecoveryStart[kHeFSBlockCount]; /// @brief Start of the block recovery. - Kernel::UInt64 fBlockRecoveryEnd[kHeFSBlockCount]; /// @brief End of the block recovery. +struct PACKED ALIGN(8) HEFS_INDEX_NODE final { + Kernel::Utf16Char fName[kHeFSFileNameLen]; /// @brief File name. + Kernel::UInt32 fFlags; /// @brief File flags. + Kernel::UInt16 fKind; /// @brief File kind. (Regular, Directory, Block, Character, FIFO, Socket, + /// Symbolic Link, Unknown). + Kernel::UInt32 fSize; /// @brief File size. + Kernel::UInt32 fChecksum, fRecoverChecksum, fBlockChecksum, + fLinkChecksum; /// @brief Checksum of the file, recovery checksum, block checksum, link + /// checksum. + + Kernel::ATime fCreated, fAccessed, fModified, fDeleted; /// @brief File timestamps. + Kernel::UInt32 fUID, fGID; /// @brief User ID and Group ID of the file. + Kernel::UInt32 fMode; /// @brief File mode. (read, write, execute, etc). + + Kernel::UInt64 fBlockLinkStart[kHeFSBlockCount]; /// @brief Start of the block link. + Kernel::UInt64 fBlockLinkEnd[kHeFSBlockCount]; /// @brief End of the block link. + + Kernel::UInt64 fBlockStart[kHeFSBlockCount]; /// @brief Start of the block. + Kernel::UInt64 fBlockEnd[kHeFSBlockCount]; /// @brief End of the block. + + Kernel::UInt64 fBlockRecoveryStart[kHeFSBlockCount]; /// @brief Start of the block recovery. + Kernel::UInt64 fBlockRecoveryEnd[kHeFSBlockCount]; /// @brief End of the block recovery. }; -enum -{ - kHeFSRed = 100, - kHeFSBlack, - kHeFSColorCount, +enum { + kHeFSRed = 100, + kHeFSBlack, + kHeFSColorCount, }; /// @brief HeFS directory node. /// @details This structure is used to store the directory information of a file. /// @note The directory node is a special type of INode that contains the directory entries. -struct PACKED ALIGN(8) HEFS_INDEX_NODE_DIRECTORY final -{ - Kernel::Utf16Char fName[kHeFSFileNameLen]; /// @brief Directory name. - - Kernel::UInt32 fFlags; /// @brief File flags. - Kernel::UInt16 fKind; /// @brief File kind. (Regular, Directory, Block, Character, FIFO, Socket, Symbolic Link, Unknown). - Kernel::UInt32 fEntryCount; /// @brief Entry Count of this directory inode. - Kernel::UInt32 fChecksum, fIndexNodeChecksum; /// @brief Checksum of the file, index node checksum. - - Kernel::ATime fCreated, fAccessed, fModified, fDeleted; /// @brief File timestamps. - Kernel::UInt32 fUID, fGID; /// @brief User ID and Group ID of the file. - Kernel::UInt32 fMode; /// @brief File mode. (read, write, execute, etc). - - /// @note These slices are organized as: - /// [0] = OFFSET - /// [1] = SIZE - /// @note Thus the += 2 when iterating over them. - Kernel::UInt64 fIndexNodeStart[kHeFSBlockCount]; /// @brief Start of the index node. - Kernel::UInt64 fIndexNodeEnd[kHeFSBlockCount]; /// @brief End of the index node. - - Kernel::UInt8 fColor; /// @brief Color of the node. (Red or Black). - Kernel::Lba fNext, fPrev, fChild, fParent; /// @brief Red-black tree pointers. +struct PACKED ALIGN(8) HEFS_INDEX_NODE_DIRECTORY final { + Kernel::Utf16Char fName[kHeFSFileNameLen]; /// @brief Directory name. + + Kernel::UInt32 fFlags; /// @brief File flags. + Kernel::UInt16 fKind; /// @brief File kind. (Regular, Directory, Block, Character, FIFO, Socket, + /// Symbolic Link, Unknown). + Kernel::UInt32 fEntryCount; /// @brief Entry Count of this directory inode. + Kernel::UInt32 fChecksum, + fIndexNodeChecksum; /// @brief Checksum of the file, index node checksum. + + Kernel::ATime fCreated, fAccessed, fModified, fDeleted; /// @brief File timestamps. + Kernel::UInt32 fUID, fGID; /// @brief User ID and Group ID of the file. + Kernel::UInt32 fMode; /// @brief File mode. (read, write, execute, etc). + + /// @note These slices are organized as: + /// [0] = OFFSET + /// [1] = SIZE + /// @note Thus the += 2 when iterating over them. + Kernel::UInt64 fIndexNodeStart[kHeFSBlockCount]; /// @brief Start of the index node. + Kernel::UInt64 fIndexNodeEnd[kHeFSBlockCount]; /// @brief End of the index node. + + Kernel::UInt8 fColor; /// @brief Color of the node. (Red or Black). + Kernel::Lba fNext, fPrev, fChild, fParent; /// @brief Red-black tree pointers. }; -namespace Kernel::Detail -{ - /// @brief HeFS get year from Kernel::ATime. - /// @param raw_atime the raw Kernel::ATime value. - /// @return the year value. - /// @note The year is stored in the upper 32 bits of the Kernel::ATime value. - inline UInt32 hefs_year_get(Kernel::ATime raw_atime) noexcept - { - return (raw_atime) >> 32; - } - - /// @brief HeFS get month from Kernel::ATime. - /// @param raw_atime the raw Kernel::ATime value. - /// @return the month value. - /// @note The month is stored in the upper 24 bits of the Kernel::ATime value. - inline UInt32 hefs_month_get(Kernel::ATime raw_atime) noexcept - { - return (raw_atime) >> 24; - } - - /// @brief HeFS get day from Kernel::ATime. - /// @param raw_atime the raw Kernel::ATime value. - /// @return the day value. - /// @note The day is stored in the upper 16 bits of the Kernel::ATime value. - inline UInt32 hefs_day_get(Kernel::ATime raw_atime) noexcept - { - return (raw_atime) >> 16; - } - - /// @brief HeFS get hour from Kernel::ATime. - /// @param raw_atime the raw Kernel::ATime value. - /// @return the hour value. - /// @note The hour is stored in the upper 8 bits of the Kernel::ATime value. - inline UInt32 hefs_hour_get(Kernel::ATime raw_atime) noexcept - { - return (raw_atime) >> 8; - } - - /// @brief HeFS get minute from Kernel::ATime. - /// @param raw_atime the raw Kernel::ATime value. - /// @return the minute value. - /// @note The minute is stored in the lower 8 bits of the Kernel::ATime value. - inline UInt32 hefs_minute_get(Kernel::ATime raw_atime) noexcept - { - return (raw_atime)&0xFF; - } - - inline constexpr UInt32 kHeFSBaseYear = 1970; - inline constexpr UInt32 kHeFSBaseMonth = 1; - inline constexpr UInt32 kHeFSBaseDay = 1; - inline constexpr UInt32 kHeFSBaseHour = 0; - inline constexpr UInt32 kHeFSBaseMinute = 0; - - inline const Char* hefs_status_to_string(UInt16 status) noexcept - { - switch (status) - { - case kHeFSStatusUnlocked: - return "Unlocked"; - case kHeFSStatusLocked: - return "Locked"; - case kHeFSStatusError: - return "Error"; - case kHeFSStatusInvalid: - return "Invalid"; - default: - return "Unknown"; - } - } - - inline const Char* hefs_drive_kind_to_string(UInt8 kind) noexcept - { - switch (kind) - { - case kHeFSHardDrive: - return "Hard Drive"; - case kHeFSSolidStateDrive: - return "Solid State Drive"; - case kHeFSOpticalDrive: - return "Optical Drive"; - case kHeFSMassStorageDevice: - return "Mass Storage Device"; - case kHeFSScsiDrive: - return "SCSI/SAS Drive"; - case kHeFSFlashDrive: - return "Flash Drive"; - case kHeFSUnknown: - default: - return "Unknown"; - } - } - - inline const Char* hefs_encoding_to_string(UInt8 encoding) noexcept - { - switch (encoding) - { - case kHeFSEncodingUTF8: - return "UTF-8"; - case kHeFSEncodingUTF16: - return "UTF-16"; - case kHeFSEncodingUTF32: - return "UTF-32"; - case kHeFSEncodingUTF16BE: - return "UTF-16BE"; - case kHeFSEncodingUTF16LE: - return "UTF-16LE"; - case kHeFSEncodingUTF32BE: - return "UTF-32BE"; - case kHeFSEncodingUTF32LE: - return "UTF-32LE"; - case kHeFSEncodingUTF8BE: - return "UTF-8BE"; - case kHeFSEncodingUTF8LE: - return "UTF-8LE"; - default: - return "Unknown"; - } - } - - inline const Char* hefs_file_kind_to_string(UInt16 kind) noexcept - { - switch (kind) - { - case kHeFSFileKindRegular: - return "Regular File"; - case kHeFSFileKindDirectory: - return "Directory"; - case kHeFSFileKindBlock: - return "Block Device"; - case kHeFSFileKindCharacter: - return "Character Device"; - case kHeFSFileKindFIFO: - return "FIFO"; - case kHeFSFileKindSocket: - return "Socket"; - case kHeFSFileKindSymbolicLink: - return "Symbolic Link"; - case kHeFSFileKindUnknown: - default: - return "Unknown"; - } - } - - inline const Char* hefs_file_flags_to_string(UInt32 flags) noexcept - { - switch (flags) - { - case 0x00: - return "No Flags"; - case 0x01: - return "Read Only"; - case 0x02: - return "Hidden"; - case 0x04: - return "System"; - case 0x08: - return "Archive"; - case 0x10: - return "Device"; - default: - return "Unknown"; - } - } -} // namespace Kernel::Detail - -namespace Kernel -{ - /// @brief HeFS filesystem parser class. - /// @details This class is used to parse the HeFS filesystem. - class HeFileSystemParser final - { - public: - HeFileSystemParser() = default; - ~HeFileSystemParser() = default; - - public: - HeFileSystemParser(const HeFileSystemParser&) = delete; - HeFileSystemParser& operator=(const HeFileSystemParser&) = delete; - - HeFileSystemParser(HeFileSystemParser&&) = delete; - HeFileSystemParser& operator=(HeFileSystemParser&&) = delete; - - public: - /// @brief Make a EPM+HeFS drive out of the disk. - /// @param drive The drive to write on. - /// @return If it was sucessful, see err_local_get(). - _Output Bool FormatEPM(_Input _Output DriveTrait* drive, _Input const Lba end_lba, _Input const Int32 flags, const Char* part_name); - - /// @brief Make a GPT+HeFS drive out of the disk. - /// @param drive The drive to write on. - /// @return If it was sucessful, see err_local_get(). - _Output Bool FormatGPT(_Input _Output DriveTrait* drive, _Input const Lba end_lba, _Input const Int32 flags, const Char* part_name); - - public: - UInt32 mDriveIndex{MountpointInterface::kDriveIndexA}; /// @brief The drive index which this filesystem is mounted on. - }; -} // namespace Kernel \ No newline at end of file +namespace Kernel::Detail { +/// @brief HeFS get year from Kernel::ATime. +/// @param raw_atime the raw Kernel::ATime value. +/// @return the year value. +/// @note The year is stored in the upper 32 bits of the Kernel::ATime value. +inline UInt32 hefs_year_get(Kernel::ATime raw_atime) noexcept { + return (raw_atime) >> 32; +} + +/// @brief HeFS get month from Kernel::ATime. +/// @param raw_atime the raw Kernel::ATime value. +/// @return the month value. +/// @note The month is stored in the upper 24 bits of the Kernel::ATime value. +inline UInt32 hefs_month_get(Kernel::ATime raw_atime) noexcept { + return (raw_atime) >> 24; +} + +/// @brief HeFS get day from Kernel::ATime. +/// @param raw_atime the raw Kernel::ATime value. +/// @return the day value. +/// @note The day is stored in the upper 16 bits of the Kernel::ATime value. +inline UInt32 hefs_day_get(Kernel::ATime raw_atime) noexcept { + return (raw_atime) >> 16; +} + +/// @brief HeFS get hour from Kernel::ATime. +/// @param raw_atime the raw Kernel::ATime value. +/// @return the hour value. +/// @note The hour is stored in the upper 8 bits of the Kernel::ATime value. +inline UInt32 hefs_hour_get(Kernel::ATime raw_atime) noexcept { + return (raw_atime) >> 8; +} + +/// @brief HeFS get minute from Kernel::ATime. +/// @param raw_atime the raw Kernel::ATime value. +/// @return the minute value. +/// @note The minute is stored in the lower 8 bits of the Kernel::ATime value. +inline UInt32 hefs_minute_get(Kernel::ATime raw_atime) noexcept { + return (raw_atime) & 0xFF; +} + +inline constexpr UInt32 kHeFSBaseYear = 1970; +inline constexpr UInt32 kHeFSBaseMonth = 1; +inline constexpr UInt32 kHeFSBaseDay = 1; +inline constexpr UInt32 kHeFSBaseHour = 0; +inline constexpr UInt32 kHeFSBaseMinute = 0; + +inline const Char* hefs_status_to_string(UInt16 status) noexcept { + switch (status) { + case kHeFSStatusUnlocked: + return "Unlocked"; + case kHeFSStatusLocked: + return "Locked"; + case kHeFSStatusError: + return "Error"; + case kHeFSStatusInvalid: + return "Invalid"; + default: + return "Unknown"; + } +} + +inline const Char* hefs_drive_kind_to_string(UInt8 kind) noexcept { + switch (kind) { + case kHeFSHardDrive: + return "Hard Drive"; + case kHeFSSolidStateDrive: + return "Solid State Drive"; + case kHeFSOpticalDrive: + return "Optical Drive"; + case kHeFSMassStorageDevice: + return "Mass Storage Device"; + case kHeFSScsiDrive: + return "SCSI/SAS Drive"; + case kHeFSFlashDrive: + return "Flash Drive"; + case kHeFSUnknown: + default: + return "Unknown"; + } +} + +inline const Char* hefs_encoding_to_string(UInt8 encoding) noexcept { + switch (encoding) { + case kHeFSEncodingUTF8: + return "UTF-8"; + case kHeFSEncodingUTF16: + return "UTF-16"; + case kHeFSEncodingUTF32: + return "UTF-32"; + case kHeFSEncodingUTF16BE: + return "UTF-16BE"; + case kHeFSEncodingUTF16LE: + return "UTF-16LE"; + case kHeFSEncodingUTF32BE: + return "UTF-32BE"; + case kHeFSEncodingUTF32LE: + return "UTF-32LE"; + case kHeFSEncodingUTF8BE: + return "UTF-8BE"; + case kHeFSEncodingUTF8LE: + return "UTF-8LE"; + default: + return "Unknown"; + } +} + +inline const Char* hefs_file_kind_to_string(UInt16 kind) noexcept { + switch (kind) { + case kHeFSFileKindRegular: + return "Regular File"; + case kHeFSFileKindDirectory: + return "Directory"; + case kHeFSFileKindBlock: + return "Block Device"; + case kHeFSFileKindCharacter: + return "Character Device"; + case kHeFSFileKindFIFO: + return "FIFO"; + case kHeFSFileKindSocket: + return "Socket"; + case kHeFSFileKindSymbolicLink: + return "Symbolic Link"; + case kHeFSFileKindUnknown: + default: + return "Unknown"; + } +} + +inline const Char* hefs_file_flags_to_string(UInt32 flags) noexcept { + switch (flags) { + case 0x00: + return "No Flags"; + case 0x01: + return "Read Only"; + case 0x02: + return "Hidden"; + case 0x04: + return "System"; + case 0x08: + return "Archive"; + case 0x10: + return "Device"; + default: + return "Unknown"; + } +} +} // namespace Kernel::Detail + +namespace Kernel { +/// @brief HeFS filesystem parser class. +/// @details This class is used to parse the HeFS filesystem. +class HeFileSystemParser final { + public: + HeFileSystemParser() = default; + ~HeFileSystemParser() = default; + + public: + HeFileSystemParser(const HeFileSystemParser&) = delete; + HeFileSystemParser& operator=(const HeFileSystemParser&) = delete; + + HeFileSystemParser(HeFileSystemParser&&) = delete; + HeFileSystemParser& operator=(HeFileSystemParser&&) = delete; + + public: + /// @brief Make a EPM+HeFS drive out of the disk. + /// @param drive The drive to write on. + /// @return If it was sucessful, see err_local_get(). + _Output Bool FormatEPM(_Input _Output DriveTrait* drive, _Input const Lba end_lba, + _Input const Int32 flags, const Char* part_name); + + /// @brief Make a GPT+HeFS drive out of the disk. + /// @param drive The drive to write on. + /// @return If it was sucessful, see err_local_get(). + _Output Bool FormatGPT(_Input _Output DriveTrait* drive, _Input const Lba end_lba, + _Input const Int32 flags, const Char* part_name); + + public: + UInt32 mDriveIndex{MountpointInterface::kDriveIndexA}; /// @brief The drive index which this + /// filesystem is mounted on. +}; +} // namespace Kernel \ No newline at end of file diff --git a/dev/kernel/FSKit/IndexableProperty.h b/dev/kernel/FSKit/IndexableProperty.h index 96853fbc..3f2c42ac 100644 --- a/dev/kernel/FSKit/IndexableProperty.h +++ b/dev/kernel/FSKit/IndexableProperty.h @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. + Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. ------------------------------------------- */ @@ -11,54 +11,48 @@ #include #define kIndexerCatalogNameLength (256U) -#define kIndexerClaimed (0xCF) -#define kIndexerUnclaimed (0xCA) - -namespace Kernel -{ - namespace Indexer - { - struct Index final - { - public: - Char Drive[kDriveNameLen]; - Char Path[kIndexerCatalogNameLength]; - }; - - class IndexableProperty final : public Property - { - public: - explicit IndexableProperty() - : Property() - { - Kernel::KString strProp(kMaxPropLen); - strProp += "/prop/indexable"; - - this->GetKey() = strProp; - } - - ~IndexableProperty() override = default; - - NE_COPY_DEFAULT(IndexableProperty) - - public: - Index& Leak() noexcept; - - public: - void AddFlag(Int16 flag); - void RemoveFlag(Int16 flag); - Int16 HasFlag(Int16 flag); - - private: - Index fIndex; - UInt32 fFlags; - }; - - /// @brief Index a file into the indexer instance. - /// @param filename path - /// @param filenameLen used bytes in path. - /// @param indexer the filesystem indexer. - /// @return none. - Void fs_index_file(const Char* filename, SizeT filenameLen, IndexableProperty& indexer); - } // namespace Indexer -} // namespace Kernel +#define kIndexerClaimed (0xCF) +#define kIndexerUnclaimed (0xCA) + +namespace Kernel { +namespace Indexer { + struct Index final { + public: + Char Drive[kDriveNameLen]; + Char Path[kIndexerCatalogNameLength]; + }; + + class IndexableProperty final : public Property { + public: + explicit IndexableProperty() : Property() { + Kernel::KString strProp(kMaxPropLen); + strProp += "/prop/indexable"; + + this->GetKey() = strProp; + } + + ~IndexableProperty() override = default; + + NE_COPY_DEFAULT(IndexableProperty) + + public: + Index& Leak() noexcept; + + public: + void AddFlag(Int16 flag); + void RemoveFlag(Int16 flag); + Int16 HasFlag(Int16 flag); + + private: + Index fIndex; + UInt32 fFlags; + }; + + /// @brief Index a file into the indexer instance. + /// @param filename path + /// @param filenameLen used bytes in path. + /// @param indexer the filesystem indexer. + /// @return none. + Void fs_index_file(const Char* filename, SizeT filenameLen, IndexableProperty& indexer); +} // namespace Indexer +} // namespace Kernel diff --git a/dev/kernel/FSKit/NeFS.h b/dev/kernel/FSKit/NeFS.h index 6b1849ff..425ab051 100644 --- a/dev/kernel/FSKit/NeFS.h +++ b/dev/kernel/FSKit/NeFS.h @@ -1,15 +1,15 @@ /* ------------------------------------------- - Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. + Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. - FILE: NeFS.h - PURPOSE: NeFS (New extended File System) support. + FILE: NeFS.h + PURPOSE: NeFS (New extended File System) support. - Revision History: + Revision History: - ?/?/?: Added file (amlel) - 12/02/24: Add UUID macro for EPM and GPT partition schemes. - 3/16/24: Add mandatory sector size, kNeFSSectorSz is set to 2048 by + ?/?/?: Added file (amlel) + 12/02/24: Add UUID macro for EPM and GPT partition schemes. + 3/16/24: Add mandatory sector size, kNeFSSectorSz is set to 2048 by default. ------------------------------------------- */ @@ -17,17 +17,17 @@ default. #pragma once #include -#include #include #include #include +#include /** - @brief New extended File System specification. - @author Amlal El Mahrouss (Amlal El Mahrouss, amlalelmahrouss at icloud dot com) + @brief New extended File System specification. + @author Amlal El Mahrouss (Amlal El Mahrouss, amlalelmahrouss at icloud dot com) */ -#define kNeFSInvalidFork (-1) +#define kNeFSInvalidFork (-1) #define kNeFSInvalidCatalog (-1) #define kNeFSCatalogNameLen (256) @@ -36,415 +36,381 @@ default. #define kNeFSSectorSz (512) #define kNeFSIdentLen (8) -#define kNeFSIdent " NeFS" -#define kNeFSPadLen (392) +#define kNeFSIdent " NeFS" +#define kNeFSPadLen (392) #define kNeFSMetaFilePrefix '$' #define kNeFSVersionInteger (0x0129) -#define kNeFSVerionString "1.2.9" +#define kNeFSVerionString "1.2.9" /// @brief Standard fork types. -#define kNeFSDataFork "main_data" +#define kNeFSDataFork "main_data" #define kNeFSResourceFork "main_rsrc" #define kNeFSForkSize (sizeof(NEFS_FORK_STRUCT)) #define kNeFSPartitionTypeStandard (7) -#define kNeFSPartitionTypePage (8) -#define kNeFSPartitionTypeBoot (9) +#define kNeFSPartitionTypePage (8) +#define kNeFSPartitionTypeBoot (9) -#define kNeFSCatalogKindFile (1) -#define kNeFSCatalogKindDir (2) +#define kNeFSCatalogKindFile (1) +#define kNeFSCatalogKindDir (2) #define kNeFSCatalogKindAlias (3) //! Shared between network and/or partitions. Export forks as .zip when copying. #define kNeFSCatalogKindShared (4) -#define kNeFSCatalogKindResource (5) +#define kNeFSCatalogKindResource (5) #define kNeFSCatalogKindExecutable (6) #define kNeFSCatalogKindPage (8) #define kNeFSCatalogKindDevice (9) -#define kNeFSCatalogKindLock (10) +#define kNeFSCatalogKindLock (10) -#define kNeFSCatalogKindRLE (11) +#define kNeFSCatalogKindRLE (11) #define kNeFSCatalogKindMetaFile (12) -#define kNeFSCatalogKindTTF (13) +#define kNeFSCatalogKindTTF (13) #define kNeFSCatalogKindRIFF (14) #define kNeFSCatalogKindMPEG (15) #define kNeFSCatalogKindMOFF (16) -#define kNeFSSeparator '/' +#define kNeFSSeparator '/' #define kNeFSSeparatorAlt '/' -#define kNeFSUpDir ".." -#define kNeFSRoot "/" +#define kNeFSUpDir ".." +#define kNeFSRoot "/" #define kNeFSRootAlt "/" -#define kNeFSLF '\r' +#define kNeFSLF '\r' #define kNeFSEOF (-1) #define kNeFSBitWidth (sizeof(Kernel::Char)) -#define kNeFSLbaType (Kernel::Lba) +#define kNeFSLbaType (Kernel::Lba) /// @note Start after the partition map header. (Virtual addressing) #define kNeFSRootCatalogStartAddress (1024) -#define kNeFSCatalogStartAddress (kNeFSRootCatalogStartAddress + sizeof(NEFS_ROOT_PARTITION_BLOCK)) +#define kNeFSCatalogStartAddress (kNeFSRootCatalogStartAddress + sizeof(NEFS_ROOT_PARTITION_BLOCK)) #define kResourceTypeDialog (10) #define kResourceTypeString (11) -#define kResourceTypeMenu (12) -#define kResourceTypeSound (13) -#define kResourceTypeFont (14) -#define kNeFSPartLen (32) +#define kResourceTypeMenu (12) +#define kResourceTypeSound (13) +#define kResourceTypeFont (14) +#define kNeFSPartLen (32) -#define kNeFSFlagDeleted (70) +#define kNeFSFlagDeleted (70) #define kNeFSFlagUnallocated (0) -#define kNeFSFlagCreated (71) +#define kNeFSFlagCreated (71) #define kNeFSMimeNameLen (200) #define kNeFSForkNameLen (200) -#define kNeFSFrameworkExt ".fwrk/" -#define kNeFSStepsExt ".step/" +#define kNeFSFrameworkExt ".fwrk/" +#define kNeFSStepsExt ".step/" #define kNeFSApplicationExt ".app/" -#define kNeFSJournalExt ".jrnl" +#define kNeFSJournalExt ".jrnl" struct NEFS_CATALOG_STRUCT; struct NEFS_FORK_STRUCT; struct NEFS_ROOT_PARTITION_BLOCK; -enum -{ - kNeFSHardDrive = 0xC0, // Hard Drive - kNeFSSolidStateDrive = 0xC1, // Solid State Drive - kNeFSOpticalDrive = 0x0C, // Blu-Ray/DVD - kNeFSMassStorageDevice = 0xCC, // USB - kNeFSScsiDrive = 0xC4, // SCSI Hard Drive - kNeFSFlashDrive = 0xC6, - kNeFSUnknown = 0xFF, // Unknown device. - kNeFSDriveCount = 7, +enum { + kNeFSHardDrive = 0xC0, // Hard Drive + kNeFSSolidStateDrive = 0xC1, // Solid State Drive + kNeFSOpticalDrive = 0x0C, // Blu-Ray/DVD + kNeFSMassStorageDevice = 0xCC, // USB + kNeFSScsiDrive = 0xC4, // SCSI Hard Drive + kNeFSFlashDrive = 0xC6, + kNeFSUnknown = 0xFF, // Unknown device. + kNeFSDriveCount = 7, }; -enum -{ - kNeFSStatusUnlocked = 0x18, - kNeFSStatusLocked, - kNeFSStatusError, - kNeFSStatusInvalid, - kNeFSStatusCount, +enum { + kNeFSStatusUnlocked = 0x18, + kNeFSStatusLocked, + kNeFSStatusError, + kNeFSStatusInvalid, + kNeFSStatusCount, }; /// @brief Catalog record type. -struct PACKED NEFS_CATALOG_STRUCT final -{ - BOOL ForkOrCatalog : 1 {0}; +struct PACKED NEFS_CATALOG_STRUCT final { + BOOL ForkOrCatalog : 1 {0}; - Kernel::Char Name[kNeFSCatalogNameLen] = {0}; - Kernel::Char Mime[kNeFSMimeNameLen] = {0}; + Kernel::Char Name[kNeFSCatalogNameLen] = {0}; + Kernel::Char Mime[kNeFSMimeNameLen] = {0}; - /// Catalog flags. - Kernel::UInt16 Flags; + /// Catalog flags. + Kernel::UInt16 Flags; - /// Catalog allocation status. - Kernel::UInt16 Status; + /// Catalog allocation status. + Kernel::UInt16 Status; - /// Custom catalog flags. - Kernel::UInt16 CatalogFlags; + /// Custom catalog flags. + Kernel::UInt16 CatalogFlags; - /// Catalog kind. - Kernel::Int32 Kind; + /// Catalog kind. + Kernel::Int32 Kind; - /// Size of the data fork. - Kernel::Lba DataForkSize; + /// Size of the data fork. + Kernel::Lba DataForkSize; - /// Size of all resource forks. - Kernel::Lba ResourceForkSize; + /// Size of all resource forks. + Kernel::Lba ResourceForkSize; - /// Forks LBA. - Kernel::Lba DataFork; - Kernel::Lba ResourceFork; + /// Forks LBA. + Kernel::Lba DataFork; + Kernel::Lba ResourceFork; - /// Buddy allocation tracker. - Kernel::Lba NextSibling; - Kernel::Lba PrevSibling; + /// Buddy allocation tracker. + Kernel::Lba NextSibling; + Kernel::Lba PrevSibling; - /// Best-buddy tracker. - Kernel::Lba NextBestSibling; - Kernel::Lba NextPrevSibling; + /// Best-buddy tracker. + Kernel::Lba NextBestSibling; + Kernel::Lba NextPrevSibling; - Kernel::UInt32 Checksum; + Kernel::UInt32 Checksum; }; /// @brief Fork type, contains a data page. -/// @note The way we store is way different than how other filesystems do, specific chunk of code are -/// written into either the data fork or resource fork, the resource fork is reserved for file metadata. -/// whereas the data fork is reserved for file data. -struct PACKED NEFS_FORK_STRUCT final -{ - BOOL ForkOrCatalog : 1 {1}; +/// @note The way we store is way different than how other filesystems do, specific chunk of code +/// are written into either the data fork or resource fork, the resource fork is reserved for file +/// metadata. whereas the data fork is reserved for file data. +struct PACKED NEFS_FORK_STRUCT final { + BOOL ForkOrCatalog : 1 {1}; - Kernel::Char ForkName[kNeFSForkNameLen] = {0}; - Kernel::Char CatalogName[kNeFSCatalogNameLen] = {0}; + Kernel::Char ForkName[kNeFSForkNameLen] = {0}; + Kernel::Char CatalogName[kNeFSCatalogNameLen] = {0}; - Kernel::Int32 Flags; - Kernel::Int32 Kind; + Kernel::Int32 Flags; + Kernel::Int32 Kind; - Kernel::Int64 ResourceId; - Kernel::Int32 ResourceKind; - Kernel::Int32 ResourceFlags; + Kernel::Int64 ResourceId; + Kernel::Int32 ResourceKind; + Kernel::Int32 ResourceFlags; - Kernel::Lba DataOffset; // 8 Where to look for this data? - Kernel::SizeT DataSize; /// Data size according using sector count. + Kernel::Lba DataOffset; // 8 Where to look for this data? + Kernel::SizeT DataSize; /// Data size according using sector count. - Kernel::Lba NextSibling; - Kernel::Lba PreviousSibling; + Kernel::Lba NextSibling; + Kernel::Lba PreviousSibling; - Kernel::Char Pad[2] = {0}; + Kernel::Char Pad[2] = {0}; }; /// @brief Partition block type -struct PACKED NEFS_ROOT_PARTITION_BLOCK final -{ - Kernel::Char Ident[kNeFSIdentLen] = {0}; - Kernel::Char PartitionName[kNeFSPartLen] = {0}; +struct PACKED NEFS_ROOT_PARTITION_BLOCK final { + Kernel::Char Ident[kNeFSIdentLen] = {0}; + Kernel::Char PartitionName[kNeFSPartLen] = {0}; + + Kernel::Int32 Flags; + Kernel::Int32 Kind; - Kernel::Int32 Flags; - Kernel::Int32 Kind; + Kernel::Lba StartCatalog; + Kernel::SizeT CatalogCount; - Kernel::Lba StartCatalog; - Kernel::SizeT CatalogCount; + Kernel::SizeT DiskSize; - Kernel::SizeT DiskSize; + Kernel::SizeT FreeCatalog; + Kernel::SizeT FreeSectors; - Kernel::SizeT FreeCatalog; - Kernel::SizeT FreeSectors; + Kernel::SizeT SectorCount; + Kernel::SizeT SectorSize; - Kernel::SizeT SectorCount; - Kernel::SizeT SectorSize; + Kernel::UInt64 Version; - Kernel::UInt64 Version; + Kernel::Lba EpmBlock; - Kernel::Lba EpmBlock; + Kernel::Char Pad[kNeFSPadLen]; +}; - Kernel::Char Pad[kNeFSPadLen]; +namespace Kernel { +class NeFileSystemParser; +class NeFileSystemJournal; +class NeFileSystemHelper; + +enum { + kNeFSSubDriveA, + kNeFSSubDriveB, + kNeFSSubDriveC, + kNeFSSubDriveD, + kNeFSSubDriveInvalid, + kNeFSSubDriveCount, }; -namespace Kernel -{ - class NeFileSystemParser; - class NeFileSystemJournal; - class NeFileSystemHelper; - - enum - { - kNeFSSubDriveA, - kNeFSSubDriveB, - kNeFSSubDriveC, - kNeFSSubDriveD, - kNeFSSubDriveInvalid, - kNeFSSubDriveCount, - }; - - /// \brief Resource fork kind. - enum - { - kNeFSRsrcForkKind = 0, - kNeFSDataForkKind = 1 - }; - - /// - /// \name NeFileSystemParser - /// \brief NeFS parser class. (catalog creation, remove removal, root, - /// forks...) Designed like the DOM, detects the filesystem automatically. - /// - class NeFileSystemParser final - { - public: - explicit NeFileSystemParser() = default; - ~NeFileSystemParser() = default; - - public: - NE_COPY_DELETE(NeFileSystemParser) - - NE_MOVE_DELETE(NeFileSystemParser) - - public: - /// @brief Creates a new fork inside the NeFS partition. - /// @param catalog it's catalog - /// @param theFork the fork itself. - /// @return the fork - _Output BOOL CreateFork(_Input NEFS_FORK_STRUCT& in); - - /// @brief Find fork inside New filesystem. - /// @param catalog the catalog. - /// @param name the fork name. - /// @return the fork. - _Output NEFS_FORK_STRUCT* FindFork(_Input NEFS_CATALOG_STRUCT* catalog, - _Input const Char* name, - Boolean data); - - _Output Void RemoveFork(_Input NEFS_FORK_STRUCT* fork); - - _Output Void CloseFork(_Input NEFS_FORK_STRUCT* fork); - - _Output NEFS_CATALOG_STRUCT* FindCatalog(_Input const Char* catalog_name, Lba& ou_lba, Bool search_hidden = YES, Bool local_search = NO); - - _Output NEFS_CATALOG_STRUCT* GetCatalog(_Input const Char* name); - - _Output NEFS_CATALOG_STRUCT* CreateCatalog(_Input const Char* name, - _Input const Int32& flags, - _Input const Int32& kind); - - _Output NEFS_CATALOG_STRUCT* CreateCatalog(_Input const Char* name); - - _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 Seek(_Input _Output NEFS_CATALOG_STRUCT* catalog, SizeT off); - - _Output SizeT Tell(_Input _Output NEFS_CATALOG_STRUCT* catalog); - - _Output Bool RemoveCatalog(_Input const Char* catalog); - - _Output Bool CloseCatalog(_InOut NEFS_CATALOG_STRUCT* catalog); - - /// @brief Make a EPM+NeFS drive out of the disk. - /// @param drive The drive to write on. - /// @return If it was sucessful, see err_local_get(). - _Output Bool FormatEPM(_Input _Output DriveTrait* drive, _Input const Lba end_lba, _Input const Int32 flags, const Char* part_name); - - _Output Bool FormatGPT(_Input _Output DriveTrait* drive, _Input const Lba end_lba, _Input const Int32 flags, const Char* part_name); - - public: - UInt32 mDriveIndex{kNeFSSubDriveA}; - }; - - /// - /// \name NeFileSystemHelper - /// \brief Filesystem helper class. - /// - - class NeFileSystemHelper final - { - public: - STATIC const Char* Root(); - STATIC const Char* UpDir(); - STATIC Char Separator(); - STATIC Char MetaFile(); - }; - - /// @brief Journal class for NeFS. - class NeFileSystemJournal final - { - private: - NEFS_CATALOG_STRUCT* mNode{nullptr}; - - public: - explicit NeFileSystemJournal(const char* stamp = nullptr) - { - if (!stamp) - { - kout << "Invalid: Journal stamp, using default name.\r"; - return; - } - - (Void)(kout << "Info: Journal stamp: " << stamp << kendl); - rt_copy_memory((VoidPtr)stamp, this->mStamp, rt_string_len(stamp)); - } +/// \brief Resource fork kind. +enum { kNeFSRsrcForkKind = 0, kNeFSDataForkKind = 1 }; + +/// +/// \name NeFileSystemParser +/// \brief NeFS parser class. (catalog creation, remove removal, root, +/// forks...) Designed like the DOM, detects the filesystem automatically. +/// +class NeFileSystemParser final { + public: + explicit NeFileSystemParser() = default; + ~NeFileSystemParser() = default; + + public: + NE_COPY_DELETE(NeFileSystemParser) + + NE_MOVE_DELETE(NeFileSystemParser) + + public: + /// @brief Creates a new fork inside the NeFS partition. + /// @param catalog it's catalog + /// @param theFork the fork itself. + /// @return the fork + _Output BOOL CreateFork(_Input NEFS_FORK_STRUCT& in); + + /// @brief Find fork inside New filesystem. + /// @param catalog the catalog. + /// @param name the fork name. + /// @return the fork. + _Output NEFS_FORK_STRUCT* FindFork(_Input NEFS_CATALOG_STRUCT* catalog, _Input const Char* name, + Boolean data); + + _Output Void RemoveFork(_Input NEFS_FORK_STRUCT* fork); + + _Output Void CloseFork(_Input NEFS_FORK_STRUCT* fork); - ~NeFileSystemJournal() = default; + _Output NEFS_CATALOG_STRUCT* FindCatalog(_Input const Char* catalog_name, Lba& ou_lba, + Bool search_hidden = YES, Bool local_search = NO); - NE_COPY_DEFAULT(NeFileSystemJournal) + _Output NEFS_CATALOG_STRUCT* GetCatalog(_Input const Char* name); - Bool CreateJournal(NeFileSystemParser* parser) - { - if (!parser) - return NO; - - delete parser->CreateCatalog("/etc/xml/", 0, kNeFSCatalogKindDir); - mNode = parser->CreateCatalog(mStamp); + _Output NEFS_CATALOG_STRUCT* CreateCatalog(_Input const Char* name, _Input const Int32& flags, + _Input const Int32& kind); - if (!mNode) - return NO; + _Output NEFS_CATALOG_STRUCT* CreateCatalog(_Input const Char* name); - return YES; - } + _Output Bool WriteCatalog(_Input const Char* catalog, _Input Bool rsrc, _Input VoidPtr data, + _Input SizeT sz, _Input const Char* name); - Bool GetJournal(NeFileSystemParser* parser) - { - if (!parser) - return NO; + _Output VoidPtr ReadCatalog(_Input _Output NEFS_CATALOG_STRUCT* catalog, _Input Bool isRsrcFork, + _Input SizeT dataSz, _Input const Char* forkName); + + _Output Bool Seek(_Input _Output NEFS_CATALOG_STRUCT* catalog, SizeT off); + + _Output SizeT Tell(_Input _Output NEFS_CATALOG_STRUCT* catalog); + + _Output Bool RemoveCatalog(_Input const Char* catalog); + + _Output Bool CloseCatalog(_InOut NEFS_CATALOG_STRUCT* catalog); + + /// @brief Make a EPM+NeFS drive out of the disk. + /// @param drive The drive to write on. + /// @return If it was sucessful, see err_local_get(). + _Output Bool FormatEPM(_Input _Output DriveTrait* drive, _Input const Lba end_lba, + _Input const Int32 flags, const Char* part_name); + + _Output Bool FormatGPT(_Input _Output DriveTrait* drive, _Input const Lba end_lba, + _Input const Int32 flags, const Char* part_name); + + public: + UInt32 mDriveIndex{kNeFSSubDriveA}; +}; + +/// +/// \name NeFileSystemHelper +/// \brief Filesystem helper class. +/// + +class NeFileSystemHelper final { + public: + STATIC const Char* Root(); + STATIC const Char* UpDir(); + STATIC Char Separator(); + STATIC Char MetaFile(); +}; - auto node = parser->GetCatalog(mStamp); +/// @brief Journal class for NeFS. +class NeFileSystemJournal final { + private: + NEFS_CATALOG_STRUCT* mNode{nullptr}; - if (node) - { - mNode = node; - return YES; - } + public: + explicit NeFileSystemJournal(const char* stamp = nullptr) { + if (!stamp) { + kout << "Invalid: Journal stamp, using default name.\r"; + return; + } - return NO; - } + (Void)(kout << "Info: Journal stamp: " << stamp << kendl); + rt_copy_memory((VoidPtr) stamp, this->mStamp, rt_string_len(stamp)); + } - Bool ReleaseJournal() - { - if (mNode) - { - delete mNode; - mNode = nullptr; - return YES; - } + ~NeFileSystemJournal() = default; - return NO; - } + NE_COPY_DEFAULT(NeFileSystemJournal) + + Bool CreateJournal(NeFileSystemParser* parser) { + if (!parser) return NO; + + delete parser->CreateCatalog("/etc/xml/", 0, kNeFSCatalogKindDir); + mNode = parser->CreateCatalog(mStamp); + + if (!mNode) return NO; + + return YES; + } + + Bool GetJournal(NeFileSystemParser* parser) { + if (!parser) return NO; + + auto node = parser->GetCatalog(mStamp); + + if (node) { + mNode = node; + return YES; + } + + return NO; + } + + Bool ReleaseJournal() { + if (mNode) { + delete mNode; + mNode = nullptr; + return YES; + } + + return NO; + } + + Bool CommitJournal(NeFileSystemParser* parser, Char* xml_data, Char* journal_name) { + if (!parser || !mNode) return NO; + + NEFS_FORK_STRUCT new_fork{}; + + rt_copy_memory(mStamp, new_fork.CatalogName, rt_string_len(mStamp)); + rt_copy_memory(journal_name, new_fork.ForkName, rt_string_len(journal_name)); + + new_fork.ResourceKind = 0; + new_fork.ResourceId = 0; + new_fork.ResourceFlags = 0; + new_fork.DataSize = rt_string_len(xml_data); + new_fork.Kind = kNeFSRsrcForkKind; + + if (!parser->CreateFork(new_fork)) return NO; + + (Void)(kout << "XML commit: " << xml_data << " to fork: " << journal_name << kendl); + + auto ret = parser->WriteCatalog(new_fork.CatalogName, YES, xml_data, rt_string_len(xml_data), + new_fork.ForkName); + + return ret; + } + + private: + Char mStamp[kNeFSCatalogNameLen] = {"/etc/xml/journal" kNeFSJournalExt}; +}; - Bool CommitJournal(NeFileSystemParser* parser, - Char* xml_data, - Char* journal_name) - { - if (!parser || - !mNode) - return NO; - - NEFS_FORK_STRUCT new_fork{}; - - rt_copy_memory(mStamp, new_fork.CatalogName, rt_string_len(mStamp)); - rt_copy_memory(journal_name, new_fork.ForkName, rt_string_len(journal_name)); - - new_fork.ResourceKind = 0; - new_fork.ResourceId = 0; - new_fork.ResourceFlags = 0; - new_fork.DataSize = rt_string_len(xml_data); - new_fork.Kind = kNeFSRsrcForkKind; - - if (!parser->CreateFork(new_fork)) - return NO; - - (Void)(kout << "XML commit: " << xml_data << " to fork: " << journal_name << kendl); - - auto ret = parser->WriteCatalog(new_fork.CatalogName, YES, xml_data, rt_string_len(xml_data), new_fork.ForkName); - - return ret; - } - - private: - Char mStamp[kNeFSCatalogNameLen] = {"/etc/xml/journal" kNeFSJournalExt}; - }; - - namespace NeFS - { - Boolean fs_init_nefs(Void) noexcept; - } // namespace NeFS -} // namespace Kernel +namespace NeFS { + Boolean fs_init_nefs(Void) noexcept; +} // namespace NeFS +} // namespace Kernel -- cgit v1.2.3