Serenity Operating System
1/*
2 * Copyright (c) 2022, Undefine <undefine@undefine.pl>
3 *
4 * SPDX-License-Identifier: BSD-2-Clause
5 */
6
7#pragma once
8
9#include <AK/DOSPackedTime.h>
10#include <AK/EnumBits.h>
11#include <AK/Types.h>
12
13namespace Kernel {
14
15struct [[gnu::packed]] FAT32BootRecord {
16 u8 boot_jump[3];
17 char oem_identifier[8];
18 u16 bytes_per_sector;
19 u8 sectors_per_cluster;
20 u16 reserved_sector_count;
21 u8 fat_count;
22 u16 root_directory_entry_count;
23 u16 unused1;
24 u8 media_descriptor_type;
25 u16 unused2;
26 u16 sectors_per_track;
27 u16 head_count;
28 u32 hidden_sector_count;
29 u32 sector_count;
30 u32 sectors_per_fat;
31 u16 flags;
32 u16 fat_version;
33 u32 root_directory_cluster;
34 u16 fs_info_sector;
35 u16 backup_boot_sector;
36 u8 unused3[12];
37 u8 drive_number;
38 u8 unused4;
39 u8 signature;
40 u32 volume_id;
41 char volume_label_string[11];
42 char system_identifier_string[8];
43};
44static_assert(sizeof(FAT32BootRecord) == 90);
45
46enum class FATAttributes : u8 {
47 ReadOnly = 0x01,
48 Hidden = 0x02,
49 System = 0x04,
50 VolumeID = 0x08,
51 Directory = 0x10,
52 Archive = 0x20,
53 LongFileName = 0x0F
54};
55
56AK_ENUM_BITWISE_OPERATORS(FATAttributes);
57
58struct [[gnu::packed]] FATEntry {
59 char filename[8];
60 char extension[3];
61 FATAttributes attributes;
62 u8 unused1;
63 u8 creation_time_seconds;
64 DOSPackedTime creation_time;
65 DOSPackedDate creation_date;
66 DOSPackedDate last_accessed_date;
67 u16 first_cluster_high;
68 DOSPackedTime modification_time;
69 DOSPackedDate modification_date;
70 u16 first_cluster_low;
71 u32 file_size;
72};
73static_assert(sizeof(FATEntry) == 32);
74
75struct [[gnu::packed]] FATLongFileNameEntry {
76 u8 entry_index;
77 u16 characters1[5];
78 FATAttributes attributes;
79 u8 entry_type;
80 u8 checksum;
81 u16 characters2[6];
82 u16 zero;
83 u16 characters3[2];
84};
85static_assert(sizeof(FATLongFileNameEntry) == 32);
86
87}