ntfs.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /* ntfs.h - header for the NTFS filesystem */
  2. /*
  3. * GRUB -- GRand Unified Bootloader
  4. * Copyright (C) 2007,2009 Free Software Foundation, Inc.
  5. *
  6. * GRUB is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * GRUB is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef GRUB_NTFS_H
  20. #define GRUB_NTFS_H 1
  21. enum
  22. {
  23. GRUB_NTFS_FILE_MFT = 0,
  24. GRUB_NTFS_FILE_MFTMIRR = 1,
  25. GRUB_NTFS_FILE_LOGFILE = 2,
  26. GRUB_NTFS_FILE_VOLUME = 3,
  27. GRUB_NTFS_FILE_ATTRDEF = 4,
  28. GRUB_NTFS_FILE_ROOT = 5,
  29. GRUB_NTFS_FILE_BITMAP = 6,
  30. GRUB_NTFS_FILE_BOOT = 7,
  31. GRUB_NTFS_FILE_BADCLUS = 8,
  32. GRUB_NTFS_FILE_QUOTA = 9,
  33. GRUB_NTFS_FILE_UPCASE = 10,
  34. };
  35. enum
  36. {
  37. GRUB_NTFS_AT_STANDARD_INFORMATION = 0x10,
  38. GRUB_NTFS_AT_ATTRIBUTE_LIST = 0x20,
  39. GRUB_NTFS_AT_FILENAME = 0x30,
  40. GRUB_NTFS_AT_OBJECT_ID = 0x40,
  41. GRUB_NTFS_AT_SECURITY_DESCRIPTOR = 0x50,
  42. GRUB_NTFS_AT_VOLUME_NAME = 0x60,
  43. GRUB_NTFS_AT_VOLUME_INFORMATION = 0x70,
  44. GRUB_NTFS_AT_DATA = 0x80,
  45. GRUB_NTFS_AT_INDEX_ROOT = 0x90,
  46. GRUB_NTFS_AT_INDEX_ALLOCATION = 0xA0,
  47. GRUB_NTFS_AT_BITMAP = 0xB0,
  48. GRUB_NTFS_AT_SYMLINK = 0xC0,
  49. GRUB_NTFS_AT_EA_INFORMATION = 0xD0,
  50. GRUB_NTFS_AT_EA = 0xE0,
  51. };
  52. enum
  53. {
  54. GRUB_NTFS_ATTR_READ_ONLY = 0x1,
  55. GRUB_NTFS_ATTR_HIDDEN = 0x2,
  56. GRUB_NTFS_ATTR_SYSTEM = 0x4,
  57. GRUB_NTFS_ATTR_ARCHIVE = 0x20,
  58. GRUB_NTFS_ATTR_DEVICE = 0x40,
  59. GRUB_NTFS_ATTR_NORMAL = 0x80,
  60. GRUB_NTFS_ATTR_TEMPORARY = 0x100,
  61. GRUB_NTFS_ATTR_SPARSE = 0x200,
  62. GRUB_NTFS_ATTR_REPARSE = 0x400,
  63. GRUB_NTFS_ATTR_COMPRESSED = 0x800,
  64. GRUB_NTFS_ATTR_OFFLINE = 0x1000,
  65. GRUB_NTFS_ATTR_NOT_INDEXED = 0x2000,
  66. GRUB_NTFS_ATTR_ENCRYPTED = 0x4000,
  67. GRUB_NTFS_ATTR_DIRECTORY = 0x10000000,
  68. GRUB_NTFS_ATTR_INDEX_VIEW = 0x20000000
  69. };
  70. enum
  71. {
  72. GRUB_NTFS_FLAG_COMPRESSED = 1,
  73. GRUB_NTFS_FLAG_ENCRYPTED = 0x4000,
  74. GRUB_NTFS_FLAG_SPARSE = 0x8000
  75. };
  76. #define GRUB_NTFS_BLK_SHR GRUB_DISK_SECTOR_BITS
  77. #define GRUB_NTFS_MAX_MFT (4096 >> GRUB_NTFS_BLK_SHR)
  78. #define GRUB_NTFS_MAX_IDX (16384 >> GRUB_NTFS_BLK_SHR)
  79. #define GRUB_NTFS_COM_LEN 4096
  80. #define GRUB_NTFS_COM_LOG_LEN 12
  81. #define GRUB_NTFS_COM_SEC (GRUB_NTFS_COM_LEN >> GRUB_NTFS_BLK_SHR)
  82. #define GRUB_NTFS_LOG_COM_SEC (GRUB_NTFS_COM_LOG_LEN - GRUB_NTFS_BLK_SHR)
  83. enum
  84. {
  85. GRUB_NTFS_AF_ALST = 1,
  86. GRUB_NTFS_AF_MMFT = 2,
  87. GRUB_NTFS_AF_GPOS = 4,
  88. };
  89. enum
  90. {
  91. GRUB_NTFS_RF_BLNK = 1
  92. };
  93. struct grub_ntfs_bpb
  94. {
  95. grub_uint8_t jmp_boot[3];
  96. grub_uint8_t oem_name[8];
  97. grub_uint16_t bytes_per_sector;
  98. grub_uint8_t sectors_per_cluster;
  99. grub_uint8_t reserved_1[7];
  100. grub_uint8_t media;
  101. grub_uint16_t reserved_2;
  102. grub_uint16_t sectors_per_track;
  103. grub_uint16_t num_heads;
  104. grub_uint32_t num_hidden_sectors;
  105. grub_uint32_t reserved_3;
  106. grub_uint8_t bios_drive;
  107. grub_uint8_t reserved_4[3];
  108. grub_uint64_t num_total_sectors;
  109. grub_uint64_t mft_lcn;
  110. grub_uint64_t mft_mirr_lcn;
  111. grub_int8_t clusters_per_mft;
  112. grub_int8_t reserved_5[3];
  113. grub_int8_t clusters_per_index;
  114. grub_int8_t reserved_6[3];
  115. grub_uint64_t num_serial;
  116. grub_uint32_t checksum;
  117. } GRUB_PACKED;
  118. struct grub_ntfs_attr
  119. {
  120. int flags;
  121. grub_uint8_t *emft_buf, *edat_buf;
  122. grub_uint8_t *attr_cur, *attr_nxt, *attr_end;
  123. grub_uint32_t save_pos;
  124. grub_uint8_t *sbuf;
  125. struct grub_ntfs_file *mft;
  126. };
  127. struct grub_ntfs_file
  128. {
  129. struct grub_ntfs_data *data;
  130. grub_uint8_t *buf;
  131. grub_uint64_t size;
  132. grub_uint64_t mtime;
  133. grub_uint64_t ino;
  134. int inode_read;
  135. struct grub_ntfs_attr attr;
  136. };
  137. struct grub_ntfs_data
  138. {
  139. struct grub_ntfs_file cmft;
  140. struct grub_ntfs_file mmft;
  141. grub_disk_t disk;
  142. grub_uint64_t mft_size;
  143. grub_uint64_t idx_size;
  144. int log_spc;
  145. grub_uint64_t mft_start;
  146. grub_uint64_t uuid;
  147. };
  148. struct grub_ntfs_comp_table_element
  149. {
  150. grub_uint32_t next_vcn;
  151. grub_uint32_t next_lcn;
  152. };
  153. struct grub_ntfs_comp
  154. {
  155. grub_disk_t disk;
  156. int comp_head, comp_tail;
  157. struct grub_ntfs_comp_table_element comp_table[16];
  158. grub_uint32_t cbuf_ofs, cbuf_vcn;
  159. int log_spc;
  160. grub_uint8_t *cbuf;
  161. };
  162. struct grub_ntfs_rlst
  163. {
  164. int flags;
  165. grub_disk_addr_t target_vcn, curr_vcn, next_vcn, curr_lcn;
  166. grub_uint8_t *cur_run;
  167. struct grub_ntfs_attr *attr;
  168. struct grub_ntfs_comp comp;
  169. void *file;
  170. };
  171. typedef grub_err_t (*grub_ntfscomp_func_t) (grub_uint8_t *dest,
  172. grub_disk_addr_t ofs,
  173. grub_size_t len,
  174. struct grub_ntfs_rlst * ctx);
  175. extern grub_ntfscomp_func_t grub_ntfscomp_func;
  176. grub_err_t grub_ntfs_read_run_list (struct grub_ntfs_rlst *ctx);
  177. #endif /* ! GRUB_NTFS_H */