Definitions.h 2.2 KB

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