Refactor USTAR class and comments in FAT header

This commit is contained in:
EnderIce2 2024-04-01 04:33:36 +03:00
parent 74cf1cee47
commit bbb67b6a88
Signed by untrusted user who does not match committer: enderice2
GPG Key ID: EACC3AD603BAB4DD
3 changed files with 85 additions and 54 deletions

View File

@ -38,33 +38,73 @@ namespace vfs
/* https://wiki.osdev.org/FAT */
struct BIOSParameterBlock
{
/** @brief The first three bytes EB 3C 90 disassemble to JMP SHORT 3C NOP. (The 3C value may be different.) The reason for this is to jump over the disk format information (the BPB and EBPB). Since the first sector of the disk is loaded into ram at location 0x0000:0x7c00 and executed, without this jump, the processor would attempt to execute data that isn't code. Even for non-bootable volumes, code matching this pattern (or using the E9 jump opcode) is required to be present by both Windows and OS X. To fulfil this requirement, an infinite loop can be placed here with the bytes EB FE 90. */
/** The first three bytes EB 3C 90 disassemble to JMP SHORT 3C NOP.
* (The 3C value may be different.) The reason for this is to jump
* over the disk format information (the BPB and EBPB). Since the
* first sector of the disk is loaded into ram at location
* 0x0000:0x7c00 and executed, without this jump, the processor
* would attempt to execute data that isn't code. Even for
* non-bootable volumes, code matching this pattern (or using the
* E9 jump opcode) is required to be present by both Windows and
* OS X. To fulfil this requirement, an infinite loop can be placed
* here with the bytes EB FE 90. */
uint8_t JumpBoot[3];
/** @brief OEM identifier. The first 8 Bytes (3 - 10) is the version of DOS being used. The next eight Bytes 29 3A 63 7E 2D 49 48 and 43 read out the name of the version. The official FAT Specification from Microsoft says that this field is really meaningless and is ignored by MS FAT Modules, however it does recommend the value "MSWIN4.1" as some 3rd party drivers supposedly check it and expect it to have that value. Older versions of dos also report MSDOS5.1, linux-formatted floppy will likely to carry "mkdosfs" here, and FreeDOS formatted disks have been observed to have "FRDOS5.1" here. If the string is less than 8 bytes, it is padded with spaces. */
/** OEM identifier. The first 8 Bytes (3 - 10) is the version of DOS
* being used. The next eight Bytes 29 3A 63 7E 2D 49 48 and 43 read
* out the name of the version. The official FAT Specification from
* Microsoft says that this field is really meaningless and is ignored
* by MS FAT Modules, however it does recommend the value "MSWIN4.1"
* as some 3rd party drivers supposedly check it and expect it to
* have that value. Older versions of dos also report MSDOS5.1,
* linux-formatted floppy will likely to carry "mkdosfs" here, and
* FreeDOS formatted disks have been observed to have "FRDOS5.1" here.
* If the string is less than 8 bytes, it is padded with spaces. */
uint8_t OEM[8];
/** @brief The number of Bytes per sector (remember, all numbers are in the little-endian format). */
/** The number of Bytes per sector (remember, all numbers are in the
* little-endian format). */
uint16_t BytesPerSector;
/** @brief Number of sectors per cluster. */
/** Number of sectors per cluster. */
uint8_t SectorsPerCluster;
/** @brief Number of reserved sectors. The boot record sectors are included in this value. */
/** Number of reserved sectors. The boot record sectors are included
* in this value. */
uint16_t ReservedSectors;
/** @brief Number of File Allocation Tables (FAT's) on the storage media. Often this value is 2. */
/** Number of File Allocation Tables (FAT's) on the storage media.
* Often this value is 2. */
uint8_t NumberOfFATs;
/** @brief Number of root directory entries (must be set so that the root directory occupies entire sectors). */
/** Number of root directory entries (must be set so that the root
* directory occupies entire sectors). */
uint16_t RootDirectoryEntries;
/** @brief The total sectors in the logical volume. If this value is 0, it means there are more than 65535 sectors in the volume, and the actual count is stored in the Large Sector Count entry at 0x20. */
/** The total sectors in the logical volume. If this value is 0, it
* means there are more than 65535 sectors in the volume, and the
* actual count is stored in the Large Sector Count entry at 0x20. */
uint16_t Sectors16;
/** @brief This Byte indicates the media descriptor type. */
/** This Byte indicates the media descriptor type. */
uint8_t Media;
/** @brief Number of sectors per FAT. FAT12/FAT16 only. */
/** Number of sectors per FAT. FAT12/FAT16 only. */
uint16_t SectorsPerFAT;
/** @brief Number of sectors per track. */
/** Number of sectors per track. */
uint16_t SectorsPerTrack;
/** @brief Number of heads or sides on the storage media. */
/** Number of heads or sides on the storage media. */
uint16_t NumberOfHeads;
/** @brief Number of hidden sectors. (i.e. the LBA of the beginning of the partition). */
/** Number of hidden sectors. (i.e. the LBA of the beginning of
* the partition). */
uint32_t HiddenSectors;
/** @brief Large sector count. This field is set if there are more than 65535 sectors in the volume, resulting in a value which does not fit in the Number of Sectors entry at 0x13. */
/** Large sector count. This field is set if there are more than
* 65535 sectors in the volume, resulting in a value which does not
* fit in the Number of Sectors entry at 0x13. */
uint32_t Sectors32;
} __packed;

View File

@ -30,13 +30,9 @@ namespace vfs
uintptr_t Address;
public:
size_t read(uint8_t *Buffer,
size_t Size,
off_t Offset);
size_t read(uint8_t *Buffer, size_t Size, off_t Offset) final;
USTARNode(uintptr_t Address,
const char *Name,
NodeType Type,
USTARNode(uintptr_t Address, const char *Name, NodeType Type,
Virtual *vfs_ctx);
~USTARNode();
@ -78,24 +74,24 @@ namespace vfs
};
private:
uint32_t getsize(const char *s)
inline uint32_t GetSize(const char *String)
{
uint32_t ret = 0;
while (*s)
while (*String)
{
ret *= 8;
ret += *s - '0';
s++;
ret += *String - '0';
String++;
}
return ret;
}
int string2int(const char *str)
inline int StringToInt(const char *String)
{
int res = 0;
for (int i = 0; str[i] != '\0'; ++i)
res = res * 10 + str[i] - '0';
return res;
int ret = 0;
for (int i = 0; String[i] != '\0'; ++i)
ret = ret * 10 + String[i] - '0';
return ret;
}
public:

View File

@ -44,16 +44,9 @@ namespace vfs
return Size;
}
USTARNode::USTARNode(uintptr_t Address,
const char *Name,
NodeType Type,
Virtual *vfs_ctx)
: Node(nullptr,
Name,
Type,
true,
vfs_ctx,
nullptr),
USTARNode::USTARNode(uintptr_t Address, const char *Name,
NodeType Type, Virtual *vfs_ctx)
: Node(nullptr, Name, Type, true, vfs_ctx, nullptr),
Address(Address)
{
}
@ -88,10 +81,17 @@ namespace vfs
debug("USTAR signature valid! Name:%s Signature:%s Mode:%d Size:%lu",
header->name, header->signature,
string2int(header->mode), header->size);
StringToInt(header->mode), header->size);
Memory::Virtual vmm;
for (size_t i = 0;; i++)
{
if (!vmm.Check((void *)header))
{
error("Address %#lx is not mapped!", header);
return;
}
if (memcmp(header->signature, "ustar", 5) != 0)
break;
@ -105,12 +105,7 @@ namespace vfs
header->name[strlen(header->name) - 1] = 0;
}
// if (!isempty((char *)header->name))
// KPrint("Adding file \e88AACC%s\eCCCCCC (\e88AACC%lu \eCCCCCCbytes)", header->name, size);
// else
// goto NextFileAddress;
size_t size = getsize(header->size);
size_t size = GetSize(header->size);
Node *node;
NodeType type = NODE_TYPE_NONE;
if (isempty((char *)header->name))
@ -143,16 +138,16 @@ namespace vfs
// debug("%s %d KiB, Type:%c", header->name,
// TO_KiB(size), header->typeflag[0]);
node->Mode = string2int(header->mode);
node->Mode = StringToInt(header->mode);
node->Size = size;
node->GroupIdentifier = getsize(header->gid);
node->UserIdentifier = getsize(header->uid);
node->DeviceMajor = getsize(header->dev_maj);
node->DeviceMinor = getsize(header->dev_min);
node->GroupIdentifier = GetSize(header->gid);
node->UserIdentifier = GetSize(header->uid);
node->DeviceMajor = GetSize(header->dev_maj);
node->DeviceMinor = GetSize(header->dev_min);
node->AccessTime = getsize(header->mtime);
node->ModifyTime = getsize(header->mtime);
node->ChangeTime = getsize(header->mtime);
node->AccessTime = GetSize(header->mtime);
node->ModifyTime = GetSize(header->mtime);
node->ChangeTime = GetSize(header->mtime);
node->IndexNode = i;
if (type == NodeType::SYMLINK)