ntfs.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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. #define FILE_MFT 0
  22. #define FILE_MFTMIRR 1
  23. #define FILE_LOGFILE 2
  24. #define FILE_VOLUME 3
  25. #define FILE_ATTRDEF 4
  26. #define FILE_ROOT 5
  27. #define FILE_BITMAP 6
  28. #define FILE_BOOT 7
  29. #define FILE_BADCLUS 8
  30. #define FILE_QUOTA 9
  31. #define FILE_UPCASE 10
  32. #define AT_STANDARD_INFORMATION 0x10
  33. #define AT_ATTRIBUTE_LIST 0x20
  34. #define AT_FILENAME 0x30
  35. #define AT_OBJECT_ID 0x40
  36. #define AT_SECURITY_DESCRIPTOR 0x50
  37. #define AT_VOLUME_NAME 0x60
  38. #define AT_VOLUME_INFORMATION 0x70
  39. #define AT_DATA 0x80
  40. #define AT_INDEX_ROOT 0x90
  41. #define AT_INDEX_ALLOCATION 0xA0
  42. #define AT_BITMAP 0xB0
  43. #define AT_SYMLINK 0xC0
  44. #define AT_EA_INFORMATION 0xD0
  45. #define AT_EA 0xE0
  46. #define ATTR_READ_ONLY 0x1
  47. #define ATTR_HIDDEN 0x2
  48. #define ATTR_SYSTEM 0x4
  49. #define ATTR_ARCHIVE 0x20
  50. #define ATTR_DEVICE 0x40
  51. #define ATTR_NORMAL 0x80
  52. #define ATTR_TEMPORARY 0x100
  53. #define ATTR_SPARSE 0x200
  54. #define ATTR_REPARSE 0x400
  55. #define ATTR_COMPRESSED 0x800
  56. #define ATTR_OFFLINE 0x1000
  57. #define ATTR_NOT_INDEXED 0x2000
  58. #define ATTR_ENCRYPTED 0x4000
  59. #define ATTR_DIRECTORY 0x10000000
  60. #define ATTR_INDEX_VIEW 0x20000000
  61. #define FLAG_COMPRESSED 1
  62. #define FLAG_ENCRYPTED 0x4000
  63. #define FLAG_SPARSE 0x8000
  64. #define BLK_SHR GRUB_DISK_SECTOR_BITS
  65. #define MAX_MFT (1024 >> BLK_SHR)
  66. #define MAX_IDX (16384 >> BLK_SHR)
  67. #define COM_LEN 4096
  68. #define COM_LOG_LEN 12
  69. #define COM_SEC (COM_LEN >> BLK_SHR)
  70. #define AF_ALST 1
  71. #define AF_MMFT 2
  72. #define AF_GPOS 4
  73. #define RF_COMP 1
  74. #define RF_CBLK 2
  75. #define RF_BLNK 4
  76. #define valueat(buf,ofs,type) *((type*)(((char*)buf)+ofs))
  77. #define u16at(buf,ofs) grub_le_to_cpu16(valueat(buf,ofs,grub_uint16_t))
  78. #define u32at(buf,ofs) grub_le_to_cpu32(valueat(buf,ofs,grub_uint32_t))
  79. #define u64at(buf,ofs) grub_le_to_cpu64(valueat(buf,ofs,grub_uint64_t))
  80. #define v16at(buf,ofs) valueat(buf,ofs,grub_uint16_t)
  81. #define v32at(buf,ofs) valueat(buf,ofs,grub_uint32_t)
  82. #define v64at(buf,ofs) valueat(buf,ofs,grub_uint64_t)
  83. struct grub_ntfs_bpb
  84. {
  85. grub_uint8_t jmp_boot[3];
  86. grub_uint8_t oem_name[8];
  87. grub_uint16_t bytes_per_sector;
  88. grub_uint8_t sectors_per_cluster;
  89. grub_uint8_t reserved_1[7];
  90. grub_uint8_t media;
  91. grub_uint16_t reserved_2;
  92. grub_uint16_t sectors_per_track;
  93. grub_uint16_t num_heads;
  94. grub_uint32_t num_hidden_sectors;
  95. grub_uint32_t reserved_3[2];
  96. grub_uint64_t num_total_sectors;
  97. grub_uint64_t mft_lcn;
  98. grub_uint64_t mft_mirr_lcn;
  99. grub_int8_t clusters_per_mft;
  100. grub_int8_t reserved_4[3];
  101. grub_int8_t clusters_per_index;
  102. grub_int8_t reserved_5[3];
  103. grub_uint64_t num_serial;
  104. grub_uint32_t checksum;
  105. } __attribute__ ((packed));
  106. #define grub_ntfs_file grub_fshelp_node
  107. struct grub_ntfs_attr
  108. {
  109. int flags;
  110. char *emft_buf, *edat_buf;
  111. char *attr_cur, *attr_nxt, *attr_end;
  112. grub_uint32_t save_pos;
  113. char *sbuf;
  114. struct grub_ntfs_file *mft;
  115. };
  116. struct grub_fshelp_node
  117. {
  118. struct grub_ntfs_data *data;
  119. char *buf;
  120. grub_uint64_t size;
  121. grub_uint32_t ino;
  122. int inode_read;
  123. grub_uint32_t sector;
  124. struct grub_ntfs_attr attr;
  125. };
  126. struct grub_ntfs_data
  127. {
  128. struct grub_ntfs_file cmft;
  129. struct grub_ntfs_file mmft;
  130. grub_disk_t disk;
  131. grub_uint32_t mft_size;
  132. grub_uint32_t idx_size;
  133. grub_uint32_t spc;
  134. grub_uint32_t blocksize;
  135. grub_uint32_t mft_start;
  136. grub_uint64_t uuid;
  137. };
  138. struct grub_ntfs_comp
  139. {
  140. grub_disk_t disk;
  141. int comp_head, comp_tail;
  142. grub_uint32_t comp_table[16][2];
  143. grub_uint32_t cbuf_ofs, cbuf_vcn, spc;
  144. char *cbuf;
  145. };
  146. struct grub_ntfs_rlst
  147. {
  148. int flags;
  149. grub_disk_addr_t target_vcn, curr_vcn, next_vcn, curr_lcn;
  150. char *cur_run;
  151. struct grub_ntfs_attr *attr;
  152. struct grub_ntfs_comp comp;
  153. };
  154. typedef grub_err_t (*ntfscomp_func_t) (struct grub_ntfs_attr * at, char *dest,
  155. grub_uint32_t ofs, grub_uint32_t len,
  156. struct grub_ntfs_rlst * ctx,
  157. grub_uint32_t vcn);
  158. extern ntfscomp_func_t grub_ntfscomp_func;
  159. grub_err_t grub_ntfs_read_run_list (struct grub_ntfs_rlst *ctx);
  160. #endif /* ! GRUB_NTFS_H */