layout.h 96 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * layout.h - All NTFS associated on-disk structures. Part of the Linux-NTFS
  4. * project.
  5. *
  6. * Copyright (c) 2001-2005 Anton Altaparmakov
  7. * Copyright (c) 2002 Richard Russon
  8. */
  9. #ifndef _LINUX_NTFS_LAYOUT_H
  10. #define _LINUX_NTFS_LAYOUT_H
  11. #include <linux/types.h>
  12. #include <linux/bitops.h>
  13. #include <linux/list.h>
  14. #include <asm/byteorder.h>
  15. #include "types.h"
  16. /* The NTFS oem_id "NTFS " */
  17. #define magicNTFS cpu_to_le64(0x202020205346544eULL)
  18. /*
  19. * Location of bootsector on partition:
  20. * The standard NTFS_BOOT_SECTOR is on sector 0 of the partition.
  21. * On NT4 and above there is one backup copy of the boot sector to
  22. * be found on the last sector of the partition (not normally accessible
  23. * from within Windows as the bootsector contained number of sectors
  24. * value is one less than the actual value!).
  25. * On versions of NT 3.51 and earlier, the backup copy was located at
  26. * number of sectors/2 (integer divide), i.e. in the middle of the volume.
  27. */
  28. /*
  29. * BIOS parameter block (bpb) structure.
  30. */
  31. typedef struct {
  32. le16 bytes_per_sector; /* Size of a sector in bytes. */
  33. u8 sectors_per_cluster; /* Size of a cluster in sectors. */
  34. le16 reserved_sectors; /* zero */
  35. u8 fats; /* zero */
  36. le16 root_entries; /* zero */
  37. le16 sectors; /* zero */
  38. u8 media_type; /* 0xf8 = hard disk */
  39. le16 sectors_per_fat; /* zero */
  40. le16 sectors_per_track; /* irrelevant */
  41. le16 heads; /* irrelevant */
  42. le32 hidden_sectors; /* zero */
  43. le32 large_sectors; /* zero */
  44. } __attribute__ ((__packed__)) BIOS_PARAMETER_BLOCK;
  45. /*
  46. * NTFS boot sector structure.
  47. */
  48. typedef struct {
  49. u8 jump[3]; /* Irrelevant (jump to boot up code).*/
  50. le64 oem_id; /* Magic "NTFS ". */
  51. BIOS_PARAMETER_BLOCK bpb; /* See BIOS_PARAMETER_BLOCK. */
  52. u8 unused[4]; /* zero, NTFS diskedit.exe states that
  53. this is actually:
  54. __u8 physical_drive; // 0x80
  55. __u8 current_head; // zero
  56. __u8 extended_boot_signature;
  57. // 0x80
  58. __u8 unused; // zero
  59. */
  60. /*0x28*/sle64 number_of_sectors; /* Number of sectors in volume. Gives
  61. maximum volume size of 2^63 sectors.
  62. Assuming standard sector size of 512
  63. bytes, the maximum byte size is
  64. approx. 4.7x10^21 bytes. (-; */
  65. sle64 mft_lcn; /* Cluster location of mft data. */
  66. sle64 mftmirr_lcn; /* Cluster location of copy of mft. */
  67. s8 clusters_per_mft_record; /* Mft record size in clusters. */
  68. u8 reserved0[3]; /* zero */
  69. s8 clusters_per_index_record; /* Index block size in clusters. */
  70. u8 reserved1[3]; /* zero */
  71. le64 volume_serial_number; /* Irrelevant (serial number). */
  72. le32 checksum; /* Boot sector checksum. */
  73. /*0x54*/u8 bootstrap[426]; /* Irrelevant (boot up code). */
  74. le16 end_of_sector_marker; /* End of bootsector magic. Always is
  75. 0xaa55 in little endian. */
  76. /* sizeof() = 512 (0x200) bytes */
  77. } __attribute__ ((__packed__)) NTFS_BOOT_SECTOR;
  78. /*
  79. * Magic identifiers present at the beginning of all ntfs record containing
  80. * records (like mft records for example).
  81. */
  82. enum {
  83. /* Found in $MFT/$DATA. */
  84. magic_FILE = cpu_to_le32(0x454c4946), /* Mft entry. */
  85. magic_INDX = cpu_to_le32(0x58444e49), /* Index buffer. */
  86. magic_HOLE = cpu_to_le32(0x454c4f48), /* ? (NTFS 3.0+?) */
  87. /* Found in $LogFile/$DATA. */
  88. magic_RSTR = cpu_to_le32(0x52545352), /* Restart page. */
  89. magic_RCRD = cpu_to_le32(0x44524352), /* Log record page. */
  90. /* Found in $LogFile/$DATA. (May be found in $MFT/$DATA, also?) */
  91. magic_CHKD = cpu_to_le32(0x444b4843), /* Modified by chkdsk. */
  92. /* Found in all ntfs record containing records. */
  93. magic_BAAD = cpu_to_le32(0x44414142), /* Failed multi sector
  94. transfer was detected. */
  95. /*
  96. * Found in $LogFile/$DATA when a page is full of 0xff bytes and is
  97. * thus not initialized. Page must be initialized before using it.
  98. */
  99. magic_empty = cpu_to_le32(0xffffffff) /* Record is empty. */
  100. };
  101. typedef le32 NTFS_RECORD_TYPE;
  102. /*
  103. * Generic magic comparison macros. Finally found a use for the ## preprocessor
  104. * operator! (-8
  105. */
  106. static inline bool __ntfs_is_magic(le32 x, NTFS_RECORD_TYPE r)
  107. {
  108. return (x == r);
  109. }
  110. #define ntfs_is_magic(x, m) __ntfs_is_magic(x, magic_##m)
  111. static inline bool __ntfs_is_magicp(le32 *p, NTFS_RECORD_TYPE r)
  112. {
  113. return (*p == r);
  114. }
  115. #define ntfs_is_magicp(p, m) __ntfs_is_magicp(p, magic_##m)
  116. /*
  117. * Specialised magic comparison macros for the NTFS_RECORD_TYPEs defined above.
  118. */
  119. #define ntfs_is_file_record(x) ( ntfs_is_magic (x, FILE) )
  120. #define ntfs_is_file_recordp(p) ( ntfs_is_magicp(p, FILE) )
  121. #define ntfs_is_mft_record(x) ( ntfs_is_file_record (x) )
  122. #define ntfs_is_mft_recordp(p) ( ntfs_is_file_recordp(p) )
  123. #define ntfs_is_indx_record(x) ( ntfs_is_magic (x, INDX) )
  124. #define ntfs_is_indx_recordp(p) ( ntfs_is_magicp(p, INDX) )
  125. #define ntfs_is_hole_record(x) ( ntfs_is_magic (x, HOLE) )
  126. #define ntfs_is_hole_recordp(p) ( ntfs_is_magicp(p, HOLE) )
  127. #define ntfs_is_rstr_record(x) ( ntfs_is_magic (x, RSTR) )
  128. #define ntfs_is_rstr_recordp(p) ( ntfs_is_magicp(p, RSTR) )
  129. #define ntfs_is_rcrd_record(x) ( ntfs_is_magic (x, RCRD) )
  130. #define ntfs_is_rcrd_recordp(p) ( ntfs_is_magicp(p, RCRD) )
  131. #define ntfs_is_chkd_record(x) ( ntfs_is_magic (x, CHKD) )
  132. #define ntfs_is_chkd_recordp(p) ( ntfs_is_magicp(p, CHKD) )
  133. #define ntfs_is_baad_record(x) ( ntfs_is_magic (x, BAAD) )
  134. #define ntfs_is_baad_recordp(p) ( ntfs_is_magicp(p, BAAD) )
  135. #define ntfs_is_empty_record(x) ( ntfs_is_magic (x, empty) )
  136. #define ntfs_is_empty_recordp(p) ( ntfs_is_magicp(p, empty) )
  137. /*
  138. * The Update Sequence Array (usa) is an array of the le16 values which belong
  139. * to the end of each sector protected by the update sequence record in which
  140. * this array is contained. Note that the first entry is the Update Sequence
  141. * Number (usn), a cyclic counter of how many times the protected record has
  142. * been written to disk. The values 0 and -1 (ie. 0xffff) are not used. All
  143. * last le16's of each sector have to be equal to the usn (during reading) or
  144. * are set to it (during writing). If they are not, an incomplete multi sector
  145. * transfer has occurred when the data was written.
  146. * The maximum size for the update sequence array is fixed to:
  147. * maximum size = usa_ofs + (usa_count * 2) = 510 bytes
  148. * The 510 bytes comes from the fact that the last le16 in the array has to
  149. * (obviously) finish before the last le16 of the first 512-byte sector.
  150. * This formula can be used as a consistency check in that usa_ofs +
  151. * (usa_count * 2) has to be less than or equal to 510.
  152. */
  153. typedef struct {
  154. NTFS_RECORD_TYPE magic; /* A four-byte magic identifying the record
  155. type and/or status. */
  156. le16 usa_ofs; /* Offset to the Update Sequence Array (usa)
  157. from the start of the ntfs record. */
  158. le16 usa_count; /* Number of le16 sized entries in the usa
  159. including the Update Sequence Number (usn),
  160. thus the number of fixups is the usa_count
  161. minus 1. */
  162. } __attribute__ ((__packed__)) NTFS_RECORD;
  163. /*
  164. * System files mft record numbers. All these files are always marked as used
  165. * in the bitmap attribute of the mft; presumably in order to avoid accidental
  166. * allocation for random other mft records. Also, the sequence number for each
  167. * of the system files is always equal to their mft record number and it is
  168. * never modified.
  169. */
  170. typedef enum {
  171. FILE_MFT = 0, /* Master file table (mft). Data attribute
  172. contains the entries and bitmap attribute
  173. records which ones are in use (bit==1). */
  174. FILE_MFTMirr = 1, /* Mft mirror: copy of first four mft records
  175. in data attribute. If cluster size > 4kiB,
  176. copy of first N mft records, with
  177. N = cluster_size / mft_record_size. */
  178. FILE_LogFile = 2, /* Journalling log in data attribute. */
  179. FILE_Volume = 3, /* Volume name attribute and volume information
  180. attribute (flags and ntfs version). Windows
  181. refers to this file as volume DASD (Direct
  182. Access Storage Device). */
  183. FILE_AttrDef = 4, /* Array of attribute definitions in data
  184. attribute. */
  185. FILE_root = 5, /* Root directory. */
  186. FILE_Bitmap = 6, /* Allocation bitmap of all clusters (lcns) in
  187. data attribute. */
  188. FILE_Boot = 7, /* Boot sector (always at cluster 0) in data
  189. attribute. */
  190. FILE_BadClus = 8, /* Contains all bad clusters in the non-resident
  191. data attribute. */
  192. FILE_Secure = 9, /* Shared security descriptors in data attribute
  193. and two indexes into the descriptors.
  194. Appeared in Windows 2000. Before that, this
  195. file was named $Quota but was unused. */
  196. FILE_UpCase = 10, /* Uppercase equivalents of all 65536 Unicode
  197. characters in data attribute. */
  198. FILE_Extend = 11, /* Directory containing other system files (eg.
  199. $ObjId, $Quota, $Reparse and $UsnJrnl). This
  200. is new to NTFS3.0. */
  201. FILE_reserved12 = 12, /* Reserved for future use (records 12-15). */
  202. FILE_reserved13 = 13,
  203. FILE_reserved14 = 14,
  204. FILE_reserved15 = 15,
  205. FILE_first_user = 16, /* First user file, used as test limit for
  206. whether to allow opening a file or not. */
  207. } NTFS_SYSTEM_FILES;
  208. /*
  209. * These are the so far known MFT_RECORD_* flags (16-bit) which contain
  210. * information about the mft record in which they are present.
  211. */
  212. enum {
  213. MFT_RECORD_IN_USE = cpu_to_le16(0x0001),
  214. MFT_RECORD_IS_DIRECTORY = cpu_to_le16(0x0002),
  215. } __attribute__ ((__packed__));
  216. typedef le16 MFT_RECORD_FLAGS;
  217. /*
  218. * mft references (aka file references or file record segment references) are
  219. * used whenever a structure needs to refer to a record in the mft.
  220. *
  221. * A reference consists of a 48-bit index into the mft and a 16-bit sequence
  222. * number used to detect stale references.
  223. *
  224. * For error reporting purposes we treat the 48-bit index as a signed quantity.
  225. *
  226. * The sequence number is a circular counter (skipping 0) describing how many
  227. * times the referenced mft record has been (re)used. This has to match the
  228. * sequence number of the mft record being referenced, otherwise the reference
  229. * is considered stale and removed (FIXME: only ntfsck or the driver itself?).
  230. *
  231. * If the sequence number is zero it is assumed that no sequence number
  232. * consistency checking should be performed.
  233. *
  234. * FIXME: Since inodes are 32-bit as of now, the driver needs to always check
  235. * for high_part being 0 and if not either BUG(), cause a panic() or handle
  236. * the situation in some other way. This shouldn't be a problem as a volume has
  237. * to become HUGE in order to need more than 32-bits worth of mft records.
  238. * Assuming the standard mft record size of 1kb only the records (never mind
  239. * the non-resident attributes, etc.) would require 4Tb of space on their own
  240. * for the first 32 bits worth of records. This is only if some strange person
  241. * doesn't decide to foul play and make the mft sparse which would be a really
  242. * horrible thing to do as it would trash our current driver implementation. )-:
  243. * Do I hear screams "we want 64-bit inodes!" ?!? (-;
  244. *
  245. * FIXME: The mft zone is defined as the first 12% of the volume. This space is
  246. * reserved so that the mft can grow contiguously and hence doesn't become
  247. * fragmented. Volume free space includes the empty part of the mft zone and
  248. * when the volume's free 88% are used up, the mft zone is shrunk by a factor
  249. * of 2, thus making more space available for more files/data. This process is
  250. * repeated every time there is no more free space except for the mft zone until
  251. * there really is no more free space.
  252. */
  253. /*
  254. * Typedef the MFT_REF as a 64-bit value for easier handling.
  255. * Also define two unpacking macros to get to the reference (MREF) and
  256. * sequence number (MSEQNO) respectively.
  257. * The _LE versions are to be applied on little endian MFT_REFs.
  258. * Note: The _LE versions will return a CPU endian formatted value!
  259. */
  260. #define MFT_REF_MASK_CPU 0x0000ffffffffffffULL
  261. #define MFT_REF_MASK_LE cpu_to_le64(MFT_REF_MASK_CPU)
  262. typedef u64 MFT_REF;
  263. typedef le64 leMFT_REF;
  264. #define MK_MREF(m, s) ((MFT_REF)(((MFT_REF)(s) << 48) | \
  265. ((MFT_REF)(m) & MFT_REF_MASK_CPU)))
  266. #define MK_LE_MREF(m, s) cpu_to_le64(MK_MREF(m, s))
  267. #define MREF(x) ((unsigned long)((x) & MFT_REF_MASK_CPU))
  268. #define MSEQNO(x) ((u16)(((x) >> 48) & 0xffff))
  269. #define MREF_LE(x) ((unsigned long)(le64_to_cpu(x) & MFT_REF_MASK_CPU))
  270. #define MSEQNO_LE(x) ((u16)((le64_to_cpu(x) >> 48) & 0xffff))
  271. #define IS_ERR_MREF(x) (((x) & 0x0000800000000000ULL) ? true : false)
  272. #define ERR_MREF(x) ((u64)((s64)(x)))
  273. #define MREF_ERR(x) ((int)((s64)(x)))
  274. /*
  275. * The mft record header present at the beginning of every record in the mft.
  276. * This is followed by a sequence of variable length attribute records which
  277. * is terminated by an attribute of type AT_END which is a truncated attribute
  278. * in that it only consists of the attribute type code AT_END and none of the
  279. * other members of the attribute structure are present.
  280. */
  281. typedef struct {
  282. /*Ofs*/
  283. /* 0 NTFS_RECORD; -- Unfolded here as gcc doesn't like unnamed structs. */
  284. NTFS_RECORD_TYPE magic; /* Usually the magic is "FILE". */
  285. le16 usa_ofs; /* See NTFS_RECORD definition above. */
  286. le16 usa_count; /* See NTFS_RECORD definition above. */
  287. /* 8*/ le64 lsn; /* $LogFile sequence number for this record.
  288. Changed every time the record is modified. */
  289. /* 16*/ le16 sequence_number; /* Number of times this mft record has been
  290. reused. (See description for MFT_REF
  291. above.) NOTE: The increment (skipping zero)
  292. is done when the file is deleted. NOTE: If
  293. this is zero it is left zero. */
  294. /* 18*/ le16 link_count; /* Number of hard links, i.e. the number of
  295. directory entries referencing this record.
  296. NOTE: Only used in mft base records.
  297. NOTE: When deleting a directory entry we
  298. check the link_count and if it is 1 we
  299. delete the file. Otherwise we delete the
  300. FILE_NAME_ATTR being referenced by the
  301. directory entry from the mft record and
  302. decrement the link_count.
  303. FIXME: Careful with Win32 + DOS names! */
  304. /* 20*/ le16 attrs_offset; /* Byte offset to the first attribute in this
  305. mft record from the start of the mft record.
  306. NOTE: Must be aligned to 8-byte boundary. */
  307. /* 22*/ MFT_RECORD_FLAGS flags; /* Bit array of MFT_RECORD_FLAGS. When a file
  308. is deleted, the MFT_RECORD_IN_USE flag is
  309. set to zero. */
  310. /* 24*/ le32 bytes_in_use; /* Number of bytes used in this mft record.
  311. NOTE: Must be aligned to 8-byte boundary. */
  312. /* 28*/ le32 bytes_allocated; /* Number of bytes allocated for this mft
  313. record. This should be equal to the mft
  314. record size. */
  315. /* 32*/ leMFT_REF base_mft_record;/* This is zero for base mft records.
  316. When it is not zero it is a mft reference
  317. pointing to the base mft record to which
  318. this record belongs (this is then used to
  319. locate the attribute list attribute present
  320. in the base record which describes this
  321. extension record and hence might need
  322. modification when the extension record
  323. itself is modified, also locating the
  324. attribute list also means finding the other
  325. potential extents, belonging to the non-base
  326. mft record). */
  327. /* 40*/ le16 next_attr_instance;/* The instance number that will be assigned to
  328. the next attribute added to this mft record.
  329. NOTE: Incremented each time after it is used.
  330. NOTE: Every time the mft record is reused
  331. this number is set to zero. NOTE: The first
  332. instance number is always 0. */
  333. /* The below fields are specific to NTFS 3.1+ (Windows XP and above): */
  334. /* 42*/ le16 reserved; /* Reserved/alignment. */
  335. /* 44*/ le32 mft_record_number; /* Number of this mft record. */
  336. /* sizeof() = 48 bytes */
  337. /*
  338. * When (re)using the mft record, we place the update sequence array at this
  339. * offset, i.e. before we start with the attributes. This also makes sense,
  340. * otherwise we could run into problems with the update sequence array
  341. * containing in itself the last two bytes of a sector which would mean that
  342. * multi sector transfer protection wouldn't work. As you can't protect data
  343. * by overwriting it since you then can't get it back...
  344. * When reading we obviously use the data from the ntfs record header.
  345. */
  346. } __attribute__ ((__packed__)) MFT_RECORD;
  347. /* This is the version without the NTFS 3.1+ specific fields. */
  348. typedef struct {
  349. /*Ofs*/
  350. /* 0 NTFS_RECORD; -- Unfolded here as gcc doesn't like unnamed structs. */
  351. NTFS_RECORD_TYPE magic; /* Usually the magic is "FILE". */
  352. le16 usa_ofs; /* See NTFS_RECORD definition above. */
  353. le16 usa_count; /* See NTFS_RECORD definition above. */
  354. /* 8*/ le64 lsn; /* $LogFile sequence number for this record.
  355. Changed every time the record is modified. */
  356. /* 16*/ le16 sequence_number; /* Number of times this mft record has been
  357. reused. (See description for MFT_REF
  358. above.) NOTE: The increment (skipping zero)
  359. is done when the file is deleted. NOTE: If
  360. this is zero it is left zero. */
  361. /* 18*/ le16 link_count; /* Number of hard links, i.e. the number of
  362. directory entries referencing this record.
  363. NOTE: Only used in mft base records.
  364. NOTE: When deleting a directory entry we
  365. check the link_count and if it is 1 we
  366. delete the file. Otherwise we delete the
  367. FILE_NAME_ATTR being referenced by the
  368. directory entry from the mft record and
  369. decrement the link_count.
  370. FIXME: Careful with Win32 + DOS names! */
  371. /* 20*/ le16 attrs_offset; /* Byte offset to the first attribute in this
  372. mft record from the start of the mft record.
  373. NOTE: Must be aligned to 8-byte boundary. */
  374. /* 22*/ MFT_RECORD_FLAGS flags; /* Bit array of MFT_RECORD_FLAGS. When a file
  375. is deleted, the MFT_RECORD_IN_USE flag is
  376. set to zero. */
  377. /* 24*/ le32 bytes_in_use; /* Number of bytes used in this mft record.
  378. NOTE: Must be aligned to 8-byte boundary. */
  379. /* 28*/ le32 bytes_allocated; /* Number of bytes allocated for this mft
  380. record. This should be equal to the mft
  381. record size. */
  382. /* 32*/ leMFT_REF base_mft_record;/* This is zero for base mft records.
  383. When it is not zero it is a mft reference
  384. pointing to the base mft record to which
  385. this record belongs (this is then used to
  386. locate the attribute list attribute present
  387. in the base record which describes this
  388. extension record and hence might need
  389. modification when the extension record
  390. itself is modified, also locating the
  391. attribute list also means finding the other
  392. potential extents, belonging to the non-base
  393. mft record). */
  394. /* 40*/ le16 next_attr_instance;/* The instance number that will be assigned to
  395. the next attribute added to this mft record.
  396. NOTE: Incremented each time after it is used.
  397. NOTE: Every time the mft record is reused
  398. this number is set to zero. NOTE: The first
  399. instance number is always 0. */
  400. /* sizeof() = 42 bytes */
  401. /*
  402. * When (re)using the mft record, we place the update sequence array at this
  403. * offset, i.e. before we start with the attributes. This also makes sense,
  404. * otherwise we could run into problems with the update sequence array
  405. * containing in itself the last two bytes of a sector which would mean that
  406. * multi sector transfer protection wouldn't work. As you can't protect data
  407. * by overwriting it since you then can't get it back...
  408. * When reading we obviously use the data from the ntfs record header.
  409. */
  410. } __attribute__ ((__packed__)) MFT_RECORD_OLD;
  411. /*
  412. * System defined attributes (32-bit). Each attribute type has a corresponding
  413. * attribute name (Unicode string of maximum 64 character length) as described
  414. * by the attribute definitions present in the data attribute of the $AttrDef
  415. * system file. On NTFS 3.0 volumes the names are just as the types are named
  416. * in the below defines exchanging AT_ for the dollar sign ($). If that is not
  417. * a revealing choice of symbol I do not know what is... (-;
  418. */
  419. enum {
  420. AT_UNUSED = cpu_to_le32( 0),
  421. AT_STANDARD_INFORMATION = cpu_to_le32( 0x10),
  422. AT_ATTRIBUTE_LIST = cpu_to_le32( 0x20),
  423. AT_FILE_NAME = cpu_to_le32( 0x30),
  424. AT_OBJECT_ID = cpu_to_le32( 0x40),
  425. AT_SECURITY_DESCRIPTOR = cpu_to_le32( 0x50),
  426. AT_VOLUME_NAME = cpu_to_le32( 0x60),
  427. AT_VOLUME_INFORMATION = cpu_to_le32( 0x70),
  428. AT_DATA = cpu_to_le32( 0x80),
  429. AT_INDEX_ROOT = cpu_to_le32( 0x90),
  430. AT_INDEX_ALLOCATION = cpu_to_le32( 0xa0),
  431. AT_BITMAP = cpu_to_le32( 0xb0),
  432. AT_REPARSE_POINT = cpu_to_le32( 0xc0),
  433. AT_EA_INFORMATION = cpu_to_le32( 0xd0),
  434. AT_EA = cpu_to_le32( 0xe0),
  435. AT_PROPERTY_SET = cpu_to_le32( 0xf0),
  436. AT_LOGGED_UTILITY_STREAM = cpu_to_le32( 0x100),
  437. AT_FIRST_USER_DEFINED_ATTRIBUTE = cpu_to_le32( 0x1000),
  438. AT_END = cpu_to_le32(0xffffffff)
  439. };
  440. typedef le32 ATTR_TYPE;
  441. /*
  442. * The collation rules for sorting views/indexes/etc (32-bit).
  443. *
  444. * COLLATION_BINARY - Collate by binary compare where the first byte is most
  445. * significant.
  446. * COLLATION_UNICODE_STRING - Collate Unicode strings by comparing their binary
  447. * Unicode values, except that when a character can be uppercased, the
  448. * upper case value collates before the lower case one.
  449. * COLLATION_FILE_NAME - Collate file names as Unicode strings. The collation
  450. * is done very much like COLLATION_UNICODE_STRING. In fact I have no idea
  451. * what the difference is. Perhaps the difference is that file names
  452. * would treat some special characters in an odd way (see
  453. * unistr.c::ntfs_collate_names() and unistr.c::legal_ansi_char_array[]
  454. * for what I mean but COLLATION_UNICODE_STRING would not give any special
  455. * treatment to any characters at all, but this is speculation.
  456. * COLLATION_NTOFS_ULONG - Sorting is done according to ascending le32 key
  457. * values. E.g. used for $SII index in FILE_Secure, which sorts by
  458. * security_id (le32).
  459. * COLLATION_NTOFS_SID - Sorting is done according to ascending SID values.
  460. * E.g. used for $O index in FILE_Extend/$Quota.
  461. * COLLATION_NTOFS_SECURITY_HASH - Sorting is done first by ascending hash
  462. * values and second by ascending security_id values. E.g. used for $SDH
  463. * index in FILE_Secure.
  464. * COLLATION_NTOFS_ULONGS - Sorting is done according to a sequence of ascending
  465. * le32 key values. E.g. used for $O index in FILE_Extend/$ObjId, which
  466. * sorts by object_id (16-byte), by splitting up the object_id in four
  467. * le32 values and using them as individual keys. E.g. take the following
  468. * two security_ids, stored as follows on disk:
  469. * 1st: a1 61 65 b7 65 7b d4 11 9e 3d 00 e0 81 10 42 59
  470. * 2nd: 38 14 37 d2 d2 f3 d4 11 a5 21 c8 6b 79 b1 97 45
  471. * To compare them, they are split into four le32 values each, like so:
  472. * 1st: 0xb76561a1 0x11d47b65 0xe0003d9e 0x59421081
  473. * 2nd: 0xd2371438 0x11d4f3d2 0x6bc821a5 0x4597b179
  474. * Now, it is apparent why the 2nd object_id collates after the 1st: the
  475. * first le32 value of the 1st object_id is less than the first le32 of
  476. * the 2nd object_id. If the first le32 values of both object_ids were
  477. * equal then the second le32 values would be compared, etc.
  478. */
  479. enum {
  480. COLLATION_BINARY = cpu_to_le32(0x00),
  481. COLLATION_FILE_NAME = cpu_to_le32(0x01),
  482. COLLATION_UNICODE_STRING = cpu_to_le32(0x02),
  483. COLLATION_NTOFS_ULONG = cpu_to_le32(0x10),
  484. COLLATION_NTOFS_SID = cpu_to_le32(0x11),
  485. COLLATION_NTOFS_SECURITY_HASH = cpu_to_le32(0x12),
  486. COLLATION_NTOFS_ULONGS = cpu_to_le32(0x13),
  487. };
  488. typedef le32 COLLATION_RULE;
  489. /*
  490. * The flags (32-bit) describing attribute properties in the attribute
  491. * definition structure. FIXME: This information is based on Regis's
  492. * information and, according to him, it is not certain and probably
  493. * incomplete. The INDEXABLE flag is fairly certainly correct as only the file
  494. * name attribute has this flag set and this is the only attribute indexed in
  495. * NT4.
  496. */
  497. enum {
  498. ATTR_DEF_INDEXABLE = cpu_to_le32(0x02), /* Attribute can be
  499. indexed. */
  500. ATTR_DEF_MULTIPLE = cpu_to_le32(0x04), /* Attribute type
  501. can be present multiple times in the
  502. mft records of an inode. */
  503. ATTR_DEF_NOT_ZERO = cpu_to_le32(0x08), /* Attribute value
  504. must contain at least one non-zero
  505. byte. */
  506. ATTR_DEF_INDEXED_UNIQUE = cpu_to_le32(0x10), /* Attribute must be
  507. indexed and the attribute value must be
  508. unique for the attribute type in all of
  509. the mft records of an inode. */
  510. ATTR_DEF_NAMED_UNIQUE = cpu_to_le32(0x20), /* Attribute must be
  511. named and the name must be unique for
  512. the attribute type in all of the mft
  513. records of an inode. */
  514. ATTR_DEF_RESIDENT = cpu_to_le32(0x40), /* Attribute must be
  515. resident. */
  516. ATTR_DEF_ALWAYS_LOG = cpu_to_le32(0x80), /* Always log
  517. modifications to this attribute,
  518. regardless of whether it is resident or
  519. non-resident. Without this, only log
  520. modifications if the attribute is
  521. resident. */
  522. };
  523. typedef le32 ATTR_DEF_FLAGS;
  524. /*
  525. * The data attribute of FILE_AttrDef contains a sequence of attribute
  526. * definitions for the NTFS volume. With this, it is supposed to be safe for an
  527. * older NTFS driver to mount a volume containing a newer NTFS version without
  528. * damaging it (that's the theory. In practice it's: not damaging it too much).
  529. * Entries are sorted by attribute type. The flags describe whether the
  530. * attribute can be resident/non-resident and possibly other things, but the
  531. * actual bits are unknown.
  532. */
  533. typedef struct {
  534. /*hex ofs*/
  535. /* 0*/ ntfschar name[0x40]; /* Unicode name of the attribute. Zero
  536. terminated. */
  537. /* 80*/ ATTR_TYPE type; /* Type of the attribute. */
  538. /* 84*/ le32 display_rule; /* Default display rule.
  539. FIXME: What does it mean? (AIA) */
  540. /* 88*/ COLLATION_RULE collation_rule; /* Default collation rule. */
  541. /* 8c*/ ATTR_DEF_FLAGS flags; /* Flags describing the attribute. */
  542. /* 90*/ sle64 min_size; /* Optional minimum attribute size. */
  543. /* 98*/ sle64 max_size; /* Maximum size of attribute. */
  544. /* sizeof() = 0xa0 or 160 bytes */
  545. } __attribute__ ((__packed__)) ATTR_DEF;
  546. /*
  547. * Attribute flags (16-bit).
  548. */
  549. enum {
  550. ATTR_IS_COMPRESSED = cpu_to_le16(0x0001),
  551. ATTR_COMPRESSION_MASK = cpu_to_le16(0x00ff), /* Compression method
  552. mask. Also, first
  553. illegal value. */
  554. ATTR_IS_ENCRYPTED = cpu_to_le16(0x4000),
  555. ATTR_IS_SPARSE = cpu_to_le16(0x8000),
  556. } __attribute__ ((__packed__));
  557. typedef le16 ATTR_FLAGS;
  558. /*
  559. * Attribute compression.
  560. *
  561. * Only the data attribute is ever compressed in the current ntfs driver in
  562. * Windows. Further, compression is only applied when the data attribute is
  563. * non-resident. Finally, to use compression, the maximum allowed cluster size
  564. * on a volume is 4kib.
  565. *
  566. * The compression method is based on independently compressing blocks of X
  567. * clusters, where X is determined from the compression_unit value found in the
  568. * non-resident attribute record header (more precisely: X = 2^compression_unit
  569. * clusters). On Windows NT/2k, X always is 16 clusters (compression_unit = 4).
  570. *
  571. * There are three different cases of how a compression block of X clusters
  572. * can be stored:
  573. *
  574. * 1) The data in the block is all zero (a sparse block):
  575. * This is stored as a sparse block in the runlist, i.e. the runlist
  576. * entry has length = X and lcn = -1. The mapping pairs array actually
  577. * uses a delta_lcn value length of 0, i.e. delta_lcn is not present at
  578. * all, which is then interpreted by the driver as lcn = -1.
  579. * NOTE: Even uncompressed files can be sparse on NTFS 3.0 volumes, then
  580. * the same principles apply as above, except that the length is not
  581. * restricted to being any particular value.
  582. *
  583. * 2) The data in the block is not compressed:
  584. * This happens when compression doesn't reduce the size of the block
  585. * in clusters. I.e. if compression has a small effect so that the
  586. * compressed data still occupies X clusters, then the uncompressed data
  587. * is stored in the block.
  588. * This case is recognised by the fact that the runlist entry has
  589. * length = X and lcn >= 0. The mapping pairs array stores this as
  590. * normal with a run length of X and some specific delta_lcn, i.e.
  591. * delta_lcn has to be present.
  592. *
  593. * 3) The data in the block is compressed:
  594. * The common case. This case is recognised by the fact that the run
  595. * list entry has length L < X and lcn >= 0. The mapping pairs array
  596. * stores this as normal with a run length of X and some specific
  597. * delta_lcn, i.e. delta_lcn has to be present. This runlist entry is
  598. * immediately followed by a sparse entry with length = X - L and
  599. * lcn = -1. The latter entry is to make up the vcn counting to the
  600. * full compression block size X.
  601. *
  602. * In fact, life is more complicated because adjacent entries of the same type
  603. * can be coalesced. This means that one has to keep track of the number of
  604. * clusters handled and work on a basis of X clusters at a time being one
  605. * block. An example: if length L > X this means that this particular runlist
  606. * entry contains a block of length X and part of one or more blocks of length
  607. * L - X. Another example: if length L < X, this does not necessarily mean that
  608. * the block is compressed as it might be that the lcn changes inside the block
  609. * and hence the following runlist entry describes the continuation of the
  610. * potentially compressed block. The block would be compressed if the
  611. * following runlist entry describes at least X - L sparse clusters, thus
  612. * making up the compression block length as described in point 3 above. (Of
  613. * course, there can be several runlist entries with small lengths so that the
  614. * sparse entry does not follow the first data containing entry with
  615. * length < X.)
  616. *
  617. * NOTE: At the end of the compressed attribute value, there most likely is not
  618. * just the right amount of data to make up a compression block, thus this data
  619. * is not even attempted to be compressed. It is just stored as is, unless
  620. * the number of clusters it occupies is reduced when compressed in which case
  621. * it is stored as a compressed compression block, complete with sparse
  622. * clusters at the end.
  623. */
  624. /*
  625. * Flags of resident attributes (8-bit).
  626. */
  627. enum {
  628. RESIDENT_ATTR_IS_INDEXED = 0x01, /* Attribute is referenced in an index
  629. (has implications for deleting and
  630. modifying the attribute). */
  631. } __attribute__ ((__packed__));
  632. typedef u8 RESIDENT_ATTR_FLAGS;
  633. /*
  634. * Attribute record header. Always aligned to 8-byte boundary.
  635. */
  636. typedef struct {
  637. /*Ofs*/
  638. /* 0*/ ATTR_TYPE type; /* The (32-bit) type of the attribute. */
  639. /* 4*/ le32 length; /* Byte size of the resident part of the
  640. attribute (aligned to 8-byte boundary).
  641. Used to get to the next attribute. */
  642. /* 8*/ u8 non_resident; /* If 0, attribute is resident.
  643. If 1, attribute is non-resident. */
  644. /* 9*/ u8 name_length; /* Unicode character size of name of attribute.
  645. 0 if unnamed. */
  646. /* 10*/ le16 name_offset; /* If name_length != 0, the byte offset to the
  647. beginning of the name from the attribute
  648. record. Note that the name is stored as a
  649. Unicode string. When creating, place offset
  650. just at the end of the record header. Then,
  651. follow with attribute value or mapping pairs
  652. array, resident and non-resident attributes
  653. respectively, aligning to an 8-byte
  654. boundary. */
  655. /* 12*/ ATTR_FLAGS flags; /* Flags describing the attribute. */
  656. /* 14*/ le16 instance; /* The instance of this attribute record. This
  657. number is unique within this mft record (see
  658. MFT_RECORD/next_attribute_instance notes in
  659. in mft.h for more details). */
  660. /* 16*/ union {
  661. /* Resident attributes. */
  662. struct {
  663. /* 16 */ le32 value_length;/* Byte size of attribute value. */
  664. /* 20 */ le16 value_offset;/* Byte offset of the attribute
  665. value from the start of the
  666. attribute record. When creating,
  667. align to 8-byte boundary if we
  668. have a name present as this might
  669. not have a length of a multiple
  670. of 8-bytes. */
  671. /* 22 */ RESIDENT_ATTR_FLAGS flags; /* See above. */
  672. /* 23 */ s8 reserved; /* Reserved/alignment to 8-byte
  673. boundary. */
  674. } __attribute__ ((__packed__)) resident;
  675. /* Non-resident attributes. */
  676. struct {
  677. /* 16*/ leVCN lowest_vcn;/* Lowest valid virtual cluster number
  678. for this portion of the attribute value or
  679. 0 if this is the only extent (usually the
  680. case). - Only when an attribute list is used
  681. does lowest_vcn != 0 ever occur. */
  682. /* 24*/ leVCN highest_vcn;/* Highest valid vcn of this extent of
  683. the attribute value. - Usually there is only one
  684. portion, so this usually equals the attribute
  685. value size in clusters minus 1. Can be -1 for
  686. zero length files. Can be 0 for "single extent"
  687. attributes. */
  688. /* 32*/ le16 mapping_pairs_offset; /* Byte offset from the
  689. beginning of the structure to the mapping pairs
  690. array which contains the mappings between the
  691. vcns and the logical cluster numbers (lcns).
  692. When creating, place this at the end of this
  693. record header aligned to 8-byte boundary. */
  694. /* 34*/ u8 compression_unit; /* The compression unit expressed
  695. as the log to the base 2 of the number of
  696. clusters in a compression unit. 0 means not
  697. compressed. (This effectively limits the
  698. compression unit size to be a power of two
  699. clusters.) WinNT4 only uses a value of 4.
  700. Sparse files have this set to 0 on XPSP2. */
  701. /* 35*/ u8 reserved[5]; /* Align to 8-byte boundary. */
  702. /* The sizes below are only used when lowest_vcn is zero, as otherwise it would
  703. be difficult to keep them up-to-date.*/
  704. /* 40*/ sle64 allocated_size; /* Byte size of disk space
  705. allocated to hold the attribute value. Always
  706. is a multiple of the cluster size. When a file
  707. is compressed, this field is a multiple of the
  708. compression block size (2^compression_unit) and
  709. it represents the logically allocated space
  710. rather than the actual on disk usage. For this
  711. use the compressed_size (see below). */
  712. /* 48*/ sle64 data_size; /* Byte size of the attribute
  713. value. Can be larger than allocated_size if
  714. attribute value is compressed or sparse. */
  715. /* 56*/ sle64 initialized_size; /* Byte size of initialized
  716. portion of the attribute value. Usually equals
  717. data_size. */
  718. /* sizeof(uncompressed attr) = 64*/
  719. /* 64*/ sle64 compressed_size; /* Byte size of the attribute
  720. value after compression. Only present when
  721. compressed or sparse. Always is a multiple of
  722. the cluster size. Represents the actual amount
  723. of disk space being used on the disk. */
  724. /* sizeof(compressed attr) = 72*/
  725. } __attribute__ ((__packed__)) non_resident;
  726. } __attribute__ ((__packed__)) data;
  727. } __attribute__ ((__packed__)) ATTR_RECORD;
  728. typedef ATTR_RECORD ATTR_REC;
  729. /*
  730. * File attribute flags (32-bit) appearing in the file_attributes fields of the
  731. * STANDARD_INFORMATION attribute of MFT_RECORDs and the FILENAME_ATTR
  732. * attributes of MFT_RECORDs and directory index entries.
  733. *
  734. * All of the below flags appear in the directory index entries but only some
  735. * appear in the STANDARD_INFORMATION attribute whilst only some others appear
  736. * in the FILENAME_ATTR attribute of MFT_RECORDs. Unless otherwise stated the
  737. * flags appear in all of the above.
  738. */
  739. enum {
  740. FILE_ATTR_READONLY = cpu_to_le32(0x00000001),
  741. FILE_ATTR_HIDDEN = cpu_to_le32(0x00000002),
  742. FILE_ATTR_SYSTEM = cpu_to_le32(0x00000004),
  743. /* Old DOS volid. Unused in NT. = cpu_to_le32(0x00000008), */
  744. FILE_ATTR_DIRECTORY = cpu_to_le32(0x00000010),
  745. /* Note, FILE_ATTR_DIRECTORY is not considered valid in NT. It is
  746. reserved for the DOS SUBDIRECTORY flag. */
  747. FILE_ATTR_ARCHIVE = cpu_to_le32(0x00000020),
  748. FILE_ATTR_DEVICE = cpu_to_le32(0x00000040),
  749. FILE_ATTR_NORMAL = cpu_to_le32(0x00000080),
  750. FILE_ATTR_TEMPORARY = cpu_to_le32(0x00000100),
  751. FILE_ATTR_SPARSE_FILE = cpu_to_le32(0x00000200),
  752. FILE_ATTR_REPARSE_POINT = cpu_to_le32(0x00000400),
  753. FILE_ATTR_COMPRESSED = cpu_to_le32(0x00000800),
  754. FILE_ATTR_OFFLINE = cpu_to_le32(0x00001000),
  755. FILE_ATTR_NOT_CONTENT_INDEXED = cpu_to_le32(0x00002000),
  756. FILE_ATTR_ENCRYPTED = cpu_to_le32(0x00004000),
  757. FILE_ATTR_VALID_FLAGS = cpu_to_le32(0x00007fb7),
  758. /* Note, FILE_ATTR_VALID_FLAGS masks out the old DOS VolId and the
  759. FILE_ATTR_DEVICE and preserves everything else. This mask is used
  760. to obtain all flags that are valid for reading. */
  761. FILE_ATTR_VALID_SET_FLAGS = cpu_to_le32(0x000031a7),
  762. /* Note, FILE_ATTR_VALID_SET_FLAGS masks out the old DOS VolId, the
  763. F_A_DEVICE, F_A_DIRECTORY, F_A_SPARSE_FILE, F_A_REPARSE_POINT,
  764. F_A_COMPRESSED, and F_A_ENCRYPTED and preserves the rest. This mask
  765. is used to obtain all flags that are valid for setting. */
  766. /*
  767. * The flag FILE_ATTR_DUP_FILENAME_INDEX_PRESENT is present in all
  768. * FILENAME_ATTR attributes but not in the STANDARD_INFORMATION
  769. * attribute of an mft record.
  770. */
  771. FILE_ATTR_DUP_FILE_NAME_INDEX_PRESENT = cpu_to_le32(0x10000000),
  772. /* Note, this is a copy of the corresponding bit from the mft record,
  773. telling us whether this is a directory or not, i.e. whether it has
  774. an index root attribute or not. */
  775. FILE_ATTR_DUP_VIEW_INDEX_PRESENT = cpu_to_le32(0x20000000),
  776. /* Note, this is a copy of the corresponding bit from the mft record,
  777. telling us whether this file has a view index present (eg. object id
  778. index, quota index, one of the security indexes or the encrypting
  779. filesystem related indexes). */
  780. };
  781. typedef le32 FILE_ATTR_FLAGS;
  782. /*
  783. * NOTE on times in NTFS: All times are in MS standard time format, i.e. they
  784. * are the number of 100-nanosecond intervals since 1st January 1601, 00:00:00
  785. * universal coordinated time (UTC). (In Linux time starts 1st January 1970,
  786. * 00:00:00 UTC and is stored as the number of 1-second intervals since then.)
  787. */
  788. /*
  789. * Attribute: Standard information (0x10).
  790. *
  791. * NOTE: Always resident.
  792. * NOTE: Present in all base file records on a volume.
  793. * NOTE: There is conflicting information about the meaning of each of the time
  794. * fields but the meaning as defined below has been verified to be
  795. * correct by practical experimentation on Windows NT4 SP6a and is hence
  796. * assumed to be the one and only correct interpretation.
  797. */
  798. typedef struct {
  799. /*Ofs*/
  800. /* 0*/ sle64 creation_time; /* Time file was created. Updated when
  801. a filename is changed(?). */
  802. /* 8*/ sle64 last_data_change_time; /* Time the data attribute was last
  803. modified. */
  804. /* 16*/ sle64 last_mft_change_time; /* Time this mft record was last
  805. modified. */
  806. /* 24*/ sle64 last_access_time; /* Approximate time when the file was
  807. last accessed (obviously this is not
  808. updated on read-only volumes). In
  809. Windows this is only updated when
  810. accessed if some time delta has
  811. passed since the last update. Also,
  812. last access time updates can be
  813. disabled altogether for speed. */
  814. /* 32*/ FILE_ATTR_FLAGS file_attributes; /* Flags describing the file. */
  815. /* 36*/ union {
  816. /* NTFS 1.2 */
  817. struct {
  818. /* 36*/ u8 reserved12[12]; /* Reserved/alignment to 8-byte
  819. boundary. */
  820. } __attribute__ ((__packed__)) v1;
  821. /* sizeof() = 48 bytes */
  822. /* NTFS 3.x */
  823. struct {
  824. /*
  825. * If a volume has been upgraded from a previous NTFS version, then these
  826. * fields are present only if the file has been accessed since the upgrade.
  827. * Recognize the difference by comparing the length of the resident attribute
  828. * value. If it is 48, then the following fields are missing. If it is 72 then
  829. * the fields are present. Maybe just check like this:
  830. * if (resident.ValueLength < sizeof(STANDARD_INFORMATION)) {
  831. * Assume NTFS 1.2- format.
  832. * If (volume version is 3.x)
  833. * Upgrade attribute to NTFS 3.x format.
  834. * else
  835. * Use NTFS 1.2- format for access.
  836. * } else
  837. * Use NTFS 3.x format for access.
  838. * Only problem is that it might be legal to set the length of the value to
  839. * arbitrarily large values thus spoiling this check. - But chkdsk probably
  840. * views that as a corruption, assuming that it behaves like this for all
  841. * attributes.
  842. */
  843. /* 36*/ le32 maximum_versions; /* Maximum allowed versions for
  844. file. Zero if version numbering is disabled. */
  845. /* 40*/ le32 version_number; /* This file's version (if any).
  846. Set to zero if maximum_versions is zero. */
  847. /* 44*/ le32 class_id; /* Class id from bidirectional
  848. class id index (?). */
  849. /* 48*/ le32 owner_id; /* Owner_id of the user owning
  850. the file. Translate via $Q index in FILE_Extend
  851. /$Quota to the quota control entry for the user
  852. owning the file. Zero if quotas are disabled. */
  853. /* 52*/ le32 security_id; /* Security_id for the file.
  854. Translate via $SII index and $SDS data stream
  855. in FILE_Secure to the security descriptor. */
  856. /* 56*/ le64 quota_charged; /* Byte size of the charge to
  857. the quota for all streams of the file. Note: Is
  858. zero if quotas are disabled. */
  859. /* 64*/ leUSN usn; /* Last update sequence number
  860. of the file. This is a direct index into the
  861. transaction log file ($UsnJrnl). It is zero if
  862. the usn journal is disabled or this file has
  863. not been subject to logging yet. See usnjrnl.h
  864. for details. */
  865. } __attribute__ ((__packed__)) v3;
  866. /* sizeof() = 72 bytes (NTFS 3.x) */
  867. } __attribute__ ((__packed__)) ver;
  868. } __attribute__ ((__packed__)) STANDARD_INFORMATION;
  869. /*
  870. * Attribute: Attribute list (0x20).
  871. *
  872. * - Can be either resident or non-resident.
  873. * - Value consists of a sequence of variable length, 8-byte aligned,
  874. * ATTR_LIST_ENTRY records.
  875. * - The list is not terminated by anything at all! The only way to know when
  876. * the end is reached is to keep track of the current offset and compare it to
  877. * the attribute value size.
  878. * - The attribute list attribute contains one entry for each attribute of
  879. * the file in which the list is located, except for the list attribute
  880. * itself. The list is sorted: first by attribute type, second by attribute
  881. * name (if present), third by instance number. The extents of one
  882. * non-resident attribute (if present) immediately follow after the initial
  883. * extent. They are ordered by lowest_vcn and have their instace set to zero.
  884. * It is not allowed to have two attributes with all sorting keys equal.
  885. * - Further restrictions:
  886. * - If not resident, the vcn to lcn mapping array has to fit inside the
  887. * base mft record.
  888. * - The attribute list attribute value has a maximum size of 256kb. This
  889. * is imposed by the Windows cache manager.
  890. * - Attribute lists are only used when the attributes of mft record do not
  891. * fit inside the mft record despite all attributes (that can be made
  892. * non-resident) having been made non-resident. This can happen e.g. when:
  893. * - File has a large number of hard links (lots of file name
  894. * attributes present).
  895. * - The mapping pairs array of some non-resident attribute becomes so
  896. * large due to fragmentation that it overflows the mft record.
  897. * - The security descriptor is very complex (not applicable to
  898. * NTFS 3.0 volumes).
  899. * - There are many named streams.
  900. */
  901. typedef struct {
  902. /*Ofs*/
  903. /* 0*/ ATTR_TYPE type; /* Type of referenced attribute. */
  904. /* 4*/ le16 length; /* Byte size of this entry (8-byte aligned). */
  905. /* 6*/ u8 name_length; /* Size in Unicode chars of the name of the
  906. attribute or 0 if unnamed. */
  907. /* 7*/ u8 name_offset; /* Byte offset to beginning of attribute name
  908. (always set this to where the name would
  909. start even if unnamed). */
  910. /* 8*/ leVCN lowest_vcn; /* Lowest virtual cluster number of this portion
  911. of the attribute value. This is usually 0. It
  912. is non-zero for the case where one attribute
  913. does not fit into one mft record and thus
  914. several mft records are allocated to hold
  915. this attribute. In the latter case, each mft
  916. record holds one extent of the attribute and
  917. there is one attribute list entry for each
  918. extent. NOTE: This is DEFINITELY a signed
  919. value! The windows driver uses cmp, followed
  920. by jg when comparing this, thus it treats it
  921. as signed. */
  922. /* 16*/ leMFT_REF mft_reference;/* The reference of the mft record holding
  923. the ATTR_RECORD for this portion of the
  924. attribute value. */
  925. /* 24*/ le16 instance; /* If lowest_vcn = 0, the instance of the
  926. attribute being referenced; otherwise 0. */
  927. /* 26*/ ntfschar name[0]; /* Use when creating only. When reading use
  928. name_offset to determine the location of the
  929. name. */
  930. /* sizeof() = 26 + (attribute_name_length * 2) bytes */
  931. } __attribute__ ((__packed__)) ATTR_LIST_ENTRY;
  932. /*
  933. * The maximum allowed length for a file name.
  934. */
  935. #define MAXIMUM_FILE_NAME_LENGTH 255
  936. /*
  937. * Possible namespaces for filenames in ntfs (8-bit).
  938. */
  939. enum {
  940. FILE_NAME_POSIX = 0x00,
  941. /* This is the largest namespace. It is case sensitive and allows all
  942. Unicode characters except for: '\0' and '/'. Beware that in
  943. WinNT/2k/2003 by default files which eg have the same name except
  944. for their case will not be distinguished by the standard utilities
  945. and thus a "del filename" will delete both "filename" and "fileName"
  946. without warning. However if for example Services For Unix (SFU) are
  947. installed and the case sensitive option was enabled at installation
  948. time, then you can create/access/delete such files.
  949. Note that even SFU places restrictions on the filenames beyond the
  950. '\0' and '/' and in particular the following set of characters is
  951. not allowed: '"', '/', '<', '>', '\'. All other characters,
  952. including the ones no allowed in WIN32 namespace are allowed.
  953. Tested with SFU 3.5 (this is now free) running on Windows XP. */
  954. FILE_NAME_WIN32 = 0x01,
  955. /* The standard WinNT/2k NTFS long filenames. Case insensitive. All
  956. Unicode chars except: '\0', '"', '*', '/', ':', '<', '>', '?', '\',
  957. and '|'. Further, names cannot end with a '.' or a space. */
  958. FILE_NAME_DOS = 0x02,
  959. /* The standard DOS filenames (8.3 format). Uppercase only. All 8-bit
  960. characters greater space, except: '"', '*', '+', ',', '/', ':', ';',
  961. '<', '=', '>', '?', and '\'. */
  962. FILE_NAME_WIN32_AND_DOS = 0x03,
  963. /* 3 means that both the Win32 and the DOS filenames are identical and
  964. hence have been saved in this single filename record. */
  965. } __attribute__ ((__packed__));
  966. typedef u8 FILE_NAME_TYPE_FLAGS;
  967. /*
  968. * Attribute: Filename (0x30).
  969. *
  970. * NOTE: Always resident.
  971. * NOTE: All fields, except the parent_directory, are only updated when the
  972. * filename is changed. Until then, they just become out of sync with
  973. * reality and the more up to date values are present in the standard
  974. * information attribute.
  975. * NOTE: There is conflicting information about the meaning of each of the time
  976. * fields but the meaning as defined below has been verified to be
  977. * correct by practical experimentation on Windows NT4 SP6a and is hence
  978. * assumed to be the one and only correct interpretation.
  979. */
  980. typedef struct {
  981. /*hex ofs*/
  982. /* 0*/ leMFT_REF parent_directory; /* Directory this filename is
  983. referenced from. */
  984. /* 8*/ sle64 creation_time; /* Time file was created. */
  985. /* 10*/ sle64 last_data_change_time; /* Time the data attribute was last
  986. modified. */
  987. /* 18*/ sle64 last_mft_change_time; /* Time this mft record was last
  988. modified. */
  989. /* 20*/ sle64 last_access_time; /* Time this mft record was last
  990. accessed. */
  991. /* 28*/ sle64 allocated_size; /* Byte size of on-disk allocated space
  992. for the unnamed data attribute. So
  993. for normal $DATA, this is the
  994. allocated_size from the unnamed
  995. $DATA attribute and for compressed
  996. and/or sparse $DATA, this is the
  997. compressed_size from the unnamed
  998. $DATA attribute. For a directory or
  999. other inode without an unnamed $DATA
  1000. attribute, this is always 0. NOTE:
  1001. This is a multiple of the cluster
  1002. size. */
  1003. /* 30*/ sle64 data_size; /* Byte size of actual data in unnamed
  1004. data attribute. For a directory or
  1005. other inode without an unnamed $DATA
  1006. attribute, this is always 0. */
  1007. /* 38*/ FILE_ATTR_FLAGS file_attributes; /* Flags describing the file. */
  1008. /* 3c*/ union {
  1009. /* 3c*/ struct {
  1010. /* 3c*/ le16 packed_ea_size; /* Size of the buffer needed to
  1011. pack the extended attributes
  1012. (EAs), if such are present.*/
  1013. /* 3e*/ le16 reserved; /* Reserved for alignment. */
  1014. } __attribute__ ((__packed__)) ea;
  1015. /* 3c*/ struct {
  1016. /* 3c*/ le32 reparse_point_tag; /* Type of reparse point,
  1017. present only in reparse
  1018. points and only if there are
  1019. no EAs. */
  1020. } __attribute__ ((__packed__)) rp;
  1021. } __attribute__ ((__packed__)) type;
  1022. /* 40*/ u8 file_name_length; /* Length of file name in
  1023. (Unicode) characters. */
  1024. /* 41*/ FILE_NAME_TYPE_FLAGS file_name_type; /* Namespace of the file name.*/
  1025. /* 42*/ ntfschar file_name[0]; /* File name in Unicode. */
  1026. } __attribute__ ((__packed__)) FILE_NAME_ATTR;
  1027. /*
  1028. * GUID structures store globally unique identifiers (GUID). A GUID is a
  1029. * 128-bit value consisting of one group of eight hexadecimal digits, followed
  1030. * by three groups of four hexadecimal digits each, followed by one group of
  1031. * twelve hexadecimal digits. GUIDs are Microsoft's implementation of the
  1032. * distributed computing environment (DCE) universally unique identifier (UUID).
  1033. * Example of a GUID:
  1034. * 1F010768-5A73-BC91-0010A52216A7
  1035. */
  1036. typedef struct {
  1037. le32 data1; /* The first eight hexadecimal digits of the GUID. */
  1038. le16 data2; /* The first group of four hexadecimal digits. */
  1039. le16 data3; /* The second group of four hexadecimal digits. */
  1040. u8 data4[8]; /* The first two bytes are the third group of four
  1041. hexadecimal digits. The remaining six bytes are the
  1042. final 12 hexadecimal digits. */
  1043. } __attribute__ ((__packed__)) GUID;
  1044. /*
  1045. * FILE_Extend/$ObjId contains an index named $O. This index contains all
  1046. * object_ids present on the volume as the index keys and the corresponding
  1047. * mft_record numbers as the index entry data parts. The data part (defined
  1048. * below) also contains three other object_ids:
  1049. * birth_volume_id - object_id of FILE_Volume on which the file was first
  1050. * created. Optional (i.e. can be zero).
  1051. * birth_object_id - object_id of file when it was first created. Usually
  1052. * equals the object_id. Optional (i.e. can be zero).
  1053. * domain_id - Reserved (always zero).
  1054. */
  1055. typedef struct {
  1056. leMFT_REF mft_reference;/* Mft record containing the object_id in
  1057. the index entry key. */
  1058. union {
  1059. struct {
  1060. GUID birth_volume_id;
  1061. GUID birth_object_id;
  1062. GUID domain_id;
  1063. } __attribute__ ((__packed__)) origin;
  1064. u8 extended_info[48];
  1065. } __attribute__ ((__packed__)) opt;
  1066. } __attribute__ ((__packed__)) OBJ_ID_INDEX_DATA;
  1067. /*
  1068. * Attribute: Object id (NTFS 3.0+) (0x40).
  1069. *
  1070. * NOTE: Always resident.
  1071. */
  1072. typedef struct {
  1073. GUID object_id; /* Unique id assigned to the
  1074. file.*/
  1075. /* The following fields are optional. The attribute value size is 16
  1076. bytes, i.e. sizeof(GUID), if these are not present at all. Note,
  1077. the entries can be present but one or more (or all) can be zero
  1078. meaning that that particular value(s) is(are) not defined. */
  1079. union {
  1080. struct {
  1081. GUID birth_volume_id; /* Unique id of volume on which
  1082. the file was first created.*/
  1083. GUID birth_object_id; /* Unique id of file when it was
  1084. first created. */
  1085. GUID domain_id; /* Reserved, zero. */
  1086. } __attribute__ ((__packed__)) origin;
  1087. u8 extended_info[48];
  1088. } __attribute__ ((__packed__)) opt;
  1089. } __attribute__ ((__packed__)) OBJECT_ID_ATTR;
  1090. /*
  1091. * The pre-defined IDENTIFIER_AUTHORITIES used as SID_IDENTIFIER_AUTHORITY in
  1092. * the SID structure (see below).
  1093. */
  1094. //typedef enum { /* SID string prefix. */
  1095. // SECURITY_NULL_SID_AUTHORITY = {0, 0, 0, 0, 0, 0}, /* S-1-0 */
  1096. // SECURITY_WORLD_SID_AUTHORITY = {0, 0, 0, 0, 0, 1}, /* S-1-1 */
  1097. // SECURITY_LOCAL_SID_AUTHORITY = {0, 0, 0, 0, 0, 2}, /* S-1-2 */
  1098. // SECURITY_CREATOR_SID_AUTHORITY = {0, 0, 0, 0, 0, 3}, /* S-1-3 */
  1099. // SECURITY_NON_UNIQUE_AUTHORITY = {0, 0, 0, 0, 0, 4}, /* S-1-4 */
  1100. // SECURITY_NT_SID_AUTHORITY = {0, 0, 0, 0, 0, 5}, /* S-1-5 */
  1101. //} IDENTIFIER_AUTHORITIES;
  1102. /*
  1103. * These relative identifiers (RIDs) are used with the above identifier
  1104. * authorities to make up universal well-known SIDs.
  1105. *
  1106. * Note: The relative identifier (RID) refers to the portion of a SID, which
  1107. * identifies a user or group in relation to the authority that issued the SID.
  1108. * For example, the universal well-known SID Creator Owner ID (S-1-3-0) is
  1109. * made up of the identifier authority SECURITY_CREATOR_SID_AUTHORITY (3) and
  1110. * the relative identifier SECURITY_CREATOR_OWNER_RID (0).
  1111. */
  1112. typedef enum { /* Identifier authority. */
  1113. SECURITY_NULL_RID = 0, /* S-1-0 */
  1114. SECURITY_WORLD_RID = 0, /* S-1-1 */
  1115. SECURITY_LOCAL_RID = 0, /* S-1-2 */
  1116. SECURITY_CREATOR_OWNER_RID = 0, /* S-1-3 */
  1117. SECURITY_CREATOR_GROUP_RID = 1, /* S-1-3 */
  1118. SECURITY_CREATOR_OWNER_SERVER_RID = 2, /* S-1-3 */
  1119. SECURITY_CREATOR_GROUP_SERVER_RID = 3, /* S-1-3 */
  1120. SECURITY_DIALUP_RID = 1,
  1121. SECURITY_NETWORK_RID = 2,
  1122. SECURITY_BATCH_RID = 3,
  1123. SECURITY_INTERACTIVE_RID = 4,
  1124. SECURITY_SERVICE_RID = 6,
  1125. SECURITY_ANONYMOUS_LOGON_RID = 7,
  1126. SECURITY_PROXY_RID = 8,
  1127. SECURITY_ENTERPRISE_CONTROLLERS_RID=9,
  1128. SECURITY_SERVER_LOGON_RID = 9,
  1129. SECURITY_PRINCIPAL_SELF_RID = 0xa,
  1130. SECURITY_AUTHENTICATED_USER_RID = 0xb,
  1131. SECURITY_RESTRICTED_CODE_RID = 0xc,
  1132. SECURITY_TERMINAL_SERVER_RID = 0xd,
  1133. SECURITY_LOGON_IDS_RID = 5,
  1134. SECURITY_LOGON_IDS_RID_COUNT = 3,
  1135. SECURITY_LOCAL_SYSTEM_RID = 0x12,
  1136. SECURITY_NT_NON_UNIQUE = 0x15,
  1137. SECURITY_BUILTIN_DOMAIN_RID = 0x20,
  1138. /*
  1139. * Well-known domain relative sub-authority values (RIDs).
  1140. */
  1141. /* Users. */
  1142. DOMAIN_USER_RID_ADMIN = 0x1f4,
  1143. DOMAIN_USER_RID_GUEST = 0x1f5,
  1144. DOMAIN_USER_RID_KRBTGT = 0x1f6,
  1145. /* Groups. */
  1146. DOMAIN_GROUP_RID_ADMINS = 0x200,
  1147. DOMAIN_GROUP_RID_USERS = 0x201,
  1148. DOMAIN_GROUP_RID_GUESTS = 0x202,
  1149. DOMAIN_GROUP_RID_COMPUTERS = 0x203,
  1150. DOMAIN_GROUP_RID_CONTROLLERS = 0x204,
  1151. DOMAIN_GROUP_RID_CERT_ADMINS = 0x205,
  1152. DOMAIN_GROUP_RID_SCHEMA_ADMINS = 0x206,
  1153. DOMAIN_GROUP_RID_ENTERPRISE_ADMINS= 0x207,
  1154. DOMAIN_GROUP_RID_POLICY_ADMINS = 0x208,
  1155. /* Aliases. */
  1156. DOMAIN_ALIAS_RID_ADMINS = 0x220,
  1157. DOMAIN_ALIAS_RID_USERS = 0x221,
  1158. DOMAIN_ALIAS_RID_GUESTS = 0x222,
  1159. DOMAIN_ALIAS_RID_POWER_USERS = 0x223,
  1160. DOMAIN_ALIAS_RID_ACCOUNT_OPS = 0x224,
  1161. DOMAIN_ALIAS_RID_SYSTEM_OPS = 0x225,
  1162. DOMAIN_ALIAS_RID_PRINT_OPS = 0x226,
  1163. DOMAIN_ALIAS_RID_BACKUP_OPS = 0x227,
  1164. DOMAIN_ALIAS_RID_REPLICATOR = 0x228,
  1165. DOMAIN_ALIAS_RID_RAS_SERVERS = 0x229,
  1166. DOMAIN_ALIAS_RID_PREW2KCOMPACCESS = 0x22a,
  1167. } RELATIVE_IDENTIFIERS;
  1168. /*
  1169. * The universal well-known SIDs:
  1170. *
  1171. * NULL_SID S-1-0-0
  1172. * WORLD_SID S-1-1-0
  1173. * LOCAL_SID S-1-2-0
  1174. * CREATOR_OWNER_SID S-1-3-0
  1175. * CREATOR_GROUP_SID S-1-3-1
  1176. * CREATOR_OWNER_SERVER_SID S-1-3-2
  1177. * CREATOR_GROUP_SERVER_SID S-1-3-3
  1178. *
  1179. * (Non-unique IDs) S-1-4
  1180. *
  1181. * NT well-known SIDs:
  1182. *
  1183. * NT_AUTHORITY_SID S-1-5
  1184. * DIALUP_SID S-1-5-1
  1185. *
  1186. * NETWORD_SID S-1-5-2
  1187. * BATCH_SID S-1-5-3
  1188. * INTERACTIVE_SID S-1-5-4
  1189. * SERVICE_SID S-1-5-6
  1190. * ANONYMOUS_LOGON_SID S-1-5-7 (aka null logon session)
  1191. * PROXY_SID S-1-5-8
  1192. * SERVER_LOGON_SID S-1-5-9 (aka domain controller account)
  1193. * SELF_SID S-1-5-10 (self RID)
  1194. * AUTHENTICATED_USER_SID S-1-5-11
  1195. * RESTRICTED_CODE_SID S-1-5-12 (running restricted code)
  1196. * TERMINAL_SERVER_SID S-1-5-13 (running on terminal server)
  1197. *
  1198. * (Logon IDs) S-1-5-5-X-Y
  1199. *
  1200. * (NT non-unique IDs) S-1-5-0x15-...
  1201. *
  1202. * (Built-in domain) S-1-5-0x20
  1203. */
  1204. /*
  1205. * The SID_IDENTIFIER_AUTHORITY is a 48-bit value used in the SID structure.
  1206. *
  1207. * NOTE: This is stored as a big endian number, hence the high_part comes
  1208. * before the low_part.
  1209. */
  1210. typedef union {
  1211. struct {
  1212. u16 high_part; /* High 16-bits. */
  1213. u32 low_part; /* Low 32-bits. */
  1214. } __attribute__ ((__packed__)) parts;
  1215. u8 value[6]; /* Value as individual bytes. */
  1216. } __attribute__ ((__packed__)) SID_IDENTIFIER_AUTHORITY;
  1217. /*
  1218. * The SID structure is a variable-length structure used to uniquely identify
  1219. * users or groups. SID stands for security identifier.
  1220. *
  1221. * The standard textual representation of the SID is of the form:
  1222. * S-R-I-S-S...
  1223. * Where:
  1224. * - The first "S" is the literal character 'S' identifying the following
  1225. * digits as a SID.
  1226. * - R is the revision level of the SID expressed as a sequence of digits
  1227. * either in decimal or hexadecimal (if the later, prefixed by "0x").
  1228. * - I is the 48-bit identifier_authority, expressed as digits as R above.
  1229. * - S... is one or more sub_authority values, expressed as digits as above.
  1230. *
  1231. * Example SID; the domain-relative SID of the local Administrators group on
  1232. * Windows NT/2k:
  1233. * S-1-5-32-544
  1234. * This translates to a SID with:
  1235. * revision = 1,
  1236. * sub_authority_count = 2,
  1237. * identifier_authority = {0,0,0,0,0,5}, // SECURITY_NT_AUTHORITY
  1238. * sub_authority[0] = 32, // SECURITY_BUILTIN_DOMAIN_RID
  1239. * sub_authority[1] = 544 // DOMAIN_ALIAS_RID_ADMINS
  1240. */
  1241. typedef struct {
  1242. u8 revision;
  1243. u8 sub_authority_count;
  1244. SID_IDENTIFIER_AUTHORITY identifier_authority;
  1245. le32 sub_authority[1]; /* At least one sub_authority. */
  1246. } __attribute__ ((__packed__)) SID;
  1247. /*
  1248. * Current constants for SIDs.
  1249. */
  1250. typedef enum {
  1251. SID_REVISION = 1, /* Current revision level. */
  1252. SID_MAX_SUB_AUTHORITIES = 15, /* Maximum number of those. */
  1253. SID_RECOMMENDED_SUB_AUTHORITIES = 1, /* Will change to around 6 in
  1254. a future revision. */
  1255. } SID_CONSTANTS;
  1256. /*
  1257. * The predefined ACE types (8-bit, see below).
  1258. */
  1259. enum {
  1260. ACCESS_MIN_MS_ACE_TYPE = 0,
  1261. ACCESS_ALLOWED_ACE_TYPE = 0,
  1262. ACCESS_DENIED_ACE_TYPE = 1,
  1263. SYSTEM_AUDIT_ACE_TYPE = 2,
  1264. SYSTEM_ALARM_ACE_TYPE = 3, /* Not implemented as of Win2k. */
  1265. ACCESS_MAX_MS_V2_ACE_TYPE = 3,
  1266. ACCESS_ALLOWED_COMPOUND_ACE_TYPE= 4,
  1267. ACCESS_MAX_MS_V3_ACE_TYPE = 4,
  1268. /* The following are Win2k only. */
  1269. ACCESS_MIN_MS_OBJECT_ACE_TYPE = 5,
  1270. ACCESS_ALLOWED_OBJECT_ACE_TYPE = 5,
  1271. ACCESS_DENIED_OBJECT_ACE_TYPE = 6,
  1272. SYSTEM_AUDIT_OBJECT_ACE_TYPE = 7,
  1273. SYSTEM_ALARM_OBJECT_ACE_TYPE = 8,
  1274. ACCESS_MAX_MS_OBJECT_ACE_TYPE = 8,
  1275. ACCESS_MAX_MS_V4_ACE_TYPE = 8,
  1276. /* This one is for WinNT/2k. */
  1277. ACCESS_MAX_MS_ACE_TYPE = 8,
  1278. } __attribute__ ((__packed__));
  1279. typedef u8 ACE_TYPES;
  1280. /*
  1281. * The ACE flags (8-bit) for audit and inheritance (see below).
  1282. *
  1283. * SUCCESSFUL_ACCESS_ACE_FLAG is only used with system audit and alarm ACE
  1284. * types to indicate that a message is generated (in Windows!) for successful
  1285. * accesses.
  1286. *
  1287. * FAILED_ACCESS_ACE_FLAG is only used with system audit and alarm ACE types
  1288. * to indicate that a message is generated (in Windows!) for failed accesses.
  1289. */
  1290. enum {
  1291. /* The inheritance flags. */
  1292. OBJECT_INHERIT_ACE = 0x01,
  1293. CONTAINER_INHERIT_ACE = 0x02,
  1294. NO_PROPAGATE_INHERIT_ACE = 0x04,
  1295. INHERIT_ONLY_ACE = 0x08,
  1296. INHERITED_ACE = 0x10, /* Win2k only. */
  1297. VALID_INHERIT_FLAGS = 0x1f,
  1298. /* The audit flags. */
  1299. SUCCESSFUL_ACCESS_ACE_FLAG = 0x40,
  1300. FAILED_ACCESS_ACE_FLAG = 0x80,
  1301. } __attribute__ ((__packed__));
  1302. typedef u8 ACE_FLAGS;
  1303. /*
  1304. * An ACE is an access-control entry in an access-control list (ACL).
  1305. * An ACE defines access to an object for a specific user or group or defines
  1306. * the types of access that generate system-administration messages or alarms
  1307. * for a specific user or group. The user or group is identified by a security
  1308. * identifier (SID).
  1309. *
  1310. * Each ACE starts with an ACE_HEADER structure (aligned on 4-byte boundary),
  1311. * which specifies the type and size of the ACE. The format of the subsequent
  1312. * data depends on the ACE type.
  1313. */
  1314. typedef struct {
  1315. /*Ofs*/
  1316. /* 0*/ ACE_TYPES type; /* Type of the ACE. */
  1317. /* 1*/ ACE_FLAGS flags; /* Flags describing the ACE. */
  1318. /* 2*/ le16 size; /* Size in bytes of the ACE. */
  1319. } __attribute__ ((__packed__)) ACE_HEADER;
  1320. /*
  1321. * The access mask (32-bit). Defines the access rights.
  1322. *
  1323. * The specific rights (bits 0 to 15). These depend on the type of the object
  1324. * being secured by the ACE.
  1325. */
  1326. enum {
  1327. /* Specific rights for files and directories are as follows: */
  1328. /* Right to read data from the file. (FILE) */
  1329. FILE_READ_DATA = cpu_to_le32(0x00000001),
  1330. /* Right to list contents of a directory. (DIRECTORY) */
  1331. FILE_LIST_DIRECTORY = cpu_to_le32(0x00000001),
  1332. /* Right to write data to the file. (FILE) */
  1333. FILE_WRITE_DATA = cpu_to_le32(0x00000002),
  1334. /* Right to create a file in the directory. (DIRECTORY) */
  1335. FILE_ADD_FILE = cpu_to_le32(0x00000002),
  1336. /* Right to append data to the file. (FILE) */
  1337. FILE_APPEND_DATA = cpu_to_le32(0x00000004),
  1338. /* Right to create a subdirectory. (DIRECTORY) */
  1339. FILE_ADD_SUBDIRECTORY = cpu_to_le32(0x00000004),
  1340. /* Right to read extended attributes. (FILE/DIRECTORY) */
  1341. FILE_READ_EA = cpu_to_le32(0x00000008),
  1342. /* Right to write extended attributes. (FILE/DIRECTORY) */
  1343. FILE_WRITE_EA = cpu_to_le32(0x00000010),
  1344. /* Right to execute a file. (FILE) */
  1345. FILE_EXECUTE = cpu_to_le32(0x00000020),
  1346. /* Right to traverse the directory. (DIRECTORY) */
  1347. FILE_TRAVERSE = cpu_to_le32(0x00000020),
  1348. /*
  1349. * Right to delete a directory and all the files it contains (its
  1350. * children), even if the files are read-only. (DIRECTORY)
  1351. */
  1352. FILE_DELETE_CHILD = cpu_to_le32(0x00000040),
  1353. /* Right to read file attributes. (FILE/DIRECTORY) */
  1354. FILE_READ_ATTRIBUTES = cpu_to_le32(0x00000080),
  1355. /* Right to change file attributes. (FILE/DIRECTORY) */
  1356. FILE_WRITE_ATTRIBUTES = cpu_to_le32(0x00000100),
  1357. /*
  1358. * The standard rights (bits 16 to 23). These are independent of the
  1359. * type of object being secured.
  1360. */
  1361. /* Right to delete the object. */
  1362. DELETE = cpu_to_le32(0x00010000),
  1363. /*
  1364. * Right to read the information in the object's security descriptor,
  1365. * not including the information in the SACL, i.e. right to read the
  1366. * security descriptor and owner.
  1367. */
  1368. READ_CONTROL = cpu_to_le32(0x00020000),
  1369. /* Right to modify the DACL in the object's security descriptor. */
  1370. WRITE_DAC = cpu_to_le32(0x00040000),
  1371. /* Right to change the owner in the object's security descriptor. */
  1372. WRITE_OWNER = cpu_to_le32(0x00080000),
  1373. /*
  1374. * Right to use the object for synchronization. Enables a process to
  1375. * wait until the object is in the signalled state. Some object types
  1376. * do not support this access right.
  1377. */
  1378. SYNCHRONIZE = cpu_to_le32(0x00100000),
  1379. /*
  1380. * The following STANDARD_RIGHTS_* are combinations of the above for
  1381. * convenience and are defined by the Win32 API.
  1382. */
  1383. /* These are currently defined to READ_CONTROL. */
  1384. STANDARD_RIGHTS_READ = cpu_to_le32(0x00020000),
  1385. STANDARD_RIGHTS_WRITE = cpu_to_le32(0x00020000),
  1386. STANDARD_RIGHTS_EXECUTE = cpu_to_le32(0x00020000),
  1387. /* Combines DELETE, READ_CONTROL, WRITE_DAC, and WRITE_OWNER access. */
  1388. STANDARD_RIGHTS_REQUIRED = cpu_to_le32(0x000f0000),
  1389. /*
  1390. * Combines DELETE, READ_CONTROL, WRITE_DAC, WRITE_OWNER, and
  1391. * SYNCHRONIZE access.
  1392. */
  1393. STANDARD_RIGHTS_ALL = cpu_to_le32(0x001f0000),
  1394. /*
  1395. * The access system ACL and maximum allowed access types (bits 24 to
  1396. * 25, bits 26 to 27 are reserved).
  1397. */
  1398. ACCESS_SYSTEM_SECURITY = cpu_to_le32(0x01000000),
  1399. MAXIMUM_ALLOWED = cpu_to_le32(0x02000000),
  1400. /*
  1401. * The generic rights (bits 28 to 31). These map onto the standard and
  1402. * specific rights.
  1403. */
  1404. /* Read, write, and execute access. */
  1405. GENERIC_ALL = cpu_to_le32(0x10000000),
  1406. /* Execute access. */
  1407. GENERIC_EXECUTE = cpu_to_le32(0x20000000),
  1408. /*
  1409. * Write access. For files, this maps onto:
  1410. * FILE_APPEND_DATA | FILE_WRITE_ATTRIBUTES | FILE_WRITE_DATA |
  1411. * FILE_WRITE_EA | STANDARD_RIGHTS_WRITE | SYNCHRONIZE
  1412. * For directories, the mapping has the same numerical value. See
  1413. * above for the descriptions of the rights granted.
  1414. */
  1415. GENERIC_WRITE = cpu_to_le32(0x40000000),
  1416. /*
  1417. * Read access. For files, this maps onto:
  1418. * FILE_READ_ATTRIBUTES | FILE_READ_DATA | FILE_READ_EA |
  1419. * STANDARD_RIGHTS_READ | SYNCHRONIZE
  1420. * For directories, the mapping has the same numberical value. See
  1421. * above for the descriptions of the rights granted.
  1422. */
  1423. GENERIC_READ = cpu_to_le32(0x80000000),
  1424. };
  1425. typedef le32 ACCESS_MASK;
  1426. /*
  1427. * The generic mapping array. Used to denote the mapping of each generic
  1428. * access right to a specific access mask.
  1429. *
  1430. * FIXME: What exactly is this and what is it for? (AIA)
  1431. */
  1432. typedef struct {
  1433. ACCESS_MASK generic_read;
  1434. ACCESS_MASK generic_write;
  1435. ACCESS_MASK generic_execute;
  1436. ACCESS_MASK generic_all;
  1437. } __attribute__ ((__packed__)) GENERIC_MAPPING;
  1438. /*
  1439. * The predefined ACE type structures are as defined below.
  1440. */
  1441. /*
  1442. * ACCESS_ALLOWED_ACE, ACCESS_DENIED_ACE, SYSTEM_AUDIT_ACE, SYSTEM_ALARM_ACE
  1443. */
  1444. typedef struct {
  1445. /* 0 ACE_HEADER; -- Unfolded here as gcc doesn't like unnamed structs. */
  1446. ACE_TYPES type; /* Type of the ACE. */
  1447. ACE_FLAGS flags; /* Flags describing the ACE. */
  1448. le16 size; /* Size in bytes of the ACE. */
  1449. /* 4*/ ACCESS_MASK mask; /* Access mask associated with the ACE. */
  1450. /* 8*/ SID sid; /* The SID associated with the ACE. */
  1451. } __attribute__ ((__packed__)) ACCESS_ALLOWED_ACE, ACCESS_DENIED_ACE,
  1452. SYSTEM_AUDIT_ACE, SYSTEM_ALARM_ACE;
  1453. /*
  1454. * The object ACE flags (32-bit).
  1455. */
  1456. enum {
  1457. ACE_OBJECT_TYPE_PRESENT = cpu_to_le32(1),
  1458. ACE_INHERITED_OBJECT_TYPE_PRESENT = cpu_to_le32(2),
  1459. };
  1460. typedef le32 OBJECT_ACE_FLAGS;
  1461. typedef struct {
  1462. /* 0 ACE_HEADER; -- Unfolded here as gcc doesn't like unnamed structs. */
  1463. ACE_TYPES type; /* Type of the ACE. */
  1464. ACE_FLAGS flags; /* Flags describing the ACE. */
  1465. le16 size; /* Size in bytes of the ACE. */
  1466. /* 4*/ ACCESS_MASK mask; /* Access mask associated with the ACE. */
  1467. /* 8*/ OBJECT_ACE_FLAGS object_flags; /* Flags describing the object ACE. */
  1468. /* 12*/ GUID object_type;
  1469. /* 28*/ GUID inherited_object_type;
  1470. /* 44*/ SID sid; /* The SID associated with the ACE. */
  1471. } __attribute__ ((__packed__)) ACCESS_ALLOWED_OBJECT_ACE,
  1472. ACCESS_DENIED_OBJECT_ACE,
  1473. SYSTEM_AUDIT_OBJECT_ACE,
  1474. SYSTEM_ALARM_OBJECT_ACE;
  1475. /*
  1476. * An ACL is an access-control list (ACL).
  1477. * An ACL starts with an ACL header structure, which specifies the size of
  1478. * the ACL and the number of ACEs it contains. The ACL header is followed by
  1479. * zero or more access control entries (ACEs). The ACL as well as each ACE
  1480. * are aligned on 4-byte boundaries.
  1481. */
  1482. typedef struct {
  1483. u8 revision; /* Revision of this ACL. */
  1484. u8 alignment1;
  1485. le16 size; /* Allocated space in bytes for ACL. Includes this
  1486. header, the ACEs and the remaining free space. */
  1487. le16 ace_count; /* Number of ACEs in the ACL. */
  1488. le16 alignment2;
  1489. /* sizeof() = 8 bytes */
  1490. } __attribute__ ((__packed__)) ACL;
  1491. /*
  1492. * Current constants for ACLs.
  1493. */
  1494. typedef enum {
  1495. /* Current revision. */
  1496. ACL_REVISION = 2,
  1497. ACL_REVISION_DS = 4,
  1498. /* History of revisions. */
  1499. ACL_REVISION1 = 1,
  1500. MIN_ACL_REVISION = 2,
  1501. ACL_REVISION2 = 2,
  1502. ACL_REVISION3 = 3,
  1503. ACL_REVISION4 = 4,
  1504. MAX_ACL_REVISION = 4,
  1505. } ACL_CONSTANTS;
  1506. /*
  1507. * The security descriptor control flags (16-bit).
  1508. *
  1509. * SE_OWNER_DEFAULTED - This boolean flag, when set, indicates that the SID
  1510. * pointed to by the Owner field was provided by a defaulting mechanism
  1511. * rather than explicitly provided by the original provider of the
  1512. * security descriptor. This may affect the treatment of the SID with
  1513. * respect to inheritance of an owner.
  1514. *
  1515. * SE_GROUP_DEFAULTED - This boolean flag, when set, indicates that the SID in
  1516. * the Group field was provided by a defaulting mechanism rather than
  1517. * explicitly provided by the original provider of the security
  1518. * descriptor. This may affect the treatment of the SID with respect to
  1519. * inheritance of a primary group.
  1520. *
  1521. * SE_DACL_PRESENT - This boolean flag, when set, indicates that the security
  1522. * descriptor contains a discretionary ACL. If this flag is set and the
  1523. * Dacl field of the SECURITY_DESCRIPTOR is null, then a null ACL is
  1524. * explicitly being specified.
  1525. *
  1526. * SE_DACL_DEFAULTED - This boolean flag, when set, indicates that the ACL
  1527. * pointed to by the Dacl field was provided by a defaulting mechanism
  1528. * rather than explicitly provided by the original provider of the
  1529. * security descriptor. This may affect the treatment of the ACL with
  1530. * respect to inheritance of an ACL. This flag is ignored if the
  1531. * DaclPresent flag is not set.
  1532. *
  1533. * SE_SACL_PRESENT - This boolean flag, when set, indicates that the security
  1534. * descriptor contains a system ACL pointed to by the Sacl field. If this
  1535. * flag is set and the Sacl field of the SECURITY_DESCRIPTOR is null, then
  1536. * an empty (but present) ACL is being specified.
  1537. *
  1538. * SE_SACL_DEFAULTED - This boolean flag, when set, indicates that the ACL
  1539. * pointed to by the Sacl field was provided by a defaulting mechanism
  1540. * rather than explicitly provided by the original provider of the
  1541. * security descriptor. This may affect the treatment of the ACL with
  1542. * respect to inheritance of an ACL. This flag is ignored if the
  1543. * SaclPresent flag is not set.
  1544. *
  1545. * SE_SELF_RELATIVE - This boolean flag, when set, indicates that the security
  1546. * descriptor is in self-relative form. In this form, all fields of the
  1547. * security descriptor are contiguous in memory and all pointer fields are
  1548. * expressed as offsets from the beginning of the security descriptor.
  1549. */
  1550. enum {
  1551. SE_OWNER_DEFAULTED = cpu_to_le16(0x0001),
  1552. SE_GROUP_DEFAULTED = cpu_to_le16(0x0002),
  1553. SE_DACL_PRESENT = cpu_to_le16(0x0004),
  1554. SE_DACL_DEFAULTED = cpu_to_le16(0x0008),
  1555. SE_SACL_PRESENT = cpu_to_le16(0x0010),
  1556. SE_SACL_DEFAULTED = cpu_to_le16(0x0020),
  1557. SE_DACL_AUTO_INHERIT_REQ = cpu_to_le16(0x0100),
  1558. SE_SACL_AUTO_INHERIT_REQ = cpu_to_le16(0x0200),
  1559. SE_DACL_AUTO_INHERITED = cpu_to_le16(0x0400),
  1560. SE_SACL_AUTO_INHERITED = cpu_to_le16(0x0800),
  1561. SE_DACL_PROTECTED = cpu_to_le16(0x1000),
  1562. SE_SACL_PROTECTED = cpu_to_le16(0x2000),
  1563. SE_RM_CONTROL_VALID = cpu_to_le16(0x4000),
  1564. SE_SELF_RELATIVE = cpu_to_le16(0x8000)
  1565. } __attribute__ ((__packed__));
  1566. typedef le16 SECURITY_DESCRIPTOR_CONTROL;
  1567. /*
  1568. * Self-relative security descriptor. Contains the owner and group SIDs as well
  1569. * as the sacl and dacl ACLs inside the security descriptor itself.
  1570. */
  1571. typedef struct {
  1572. u8 revision; /* Revision level of the security descriptor. */
  1573. u8 alignment;
  1574. SECURITY_DESCRIPTOR_CONTROL control; /* Flags qualifying the type of
  1575. the descriptor as well as the following fields. */
  1576. le32 owner; /* Byte offset to a SID representing an object's
  1577. owner. If this is NULL, no owner SID is present in
  1578. the descriptor. */
  1579. le32 group; /* Byte offset to a SID representing an object's
  1580. primary group. If this is NULL, no primary group
  1581. SID is present in the descriptor. */
  1582. le32 sacl; /* Byte offset to a system ACL. Only valid, if
  1583. SE_SACL_PRESENT is set in the control field. If
  1584. SE_SACL_PRESENT is set but sacl is NULL, a NULL ACL
  1585. is specified. */
  1586. le32 dacl; /* Byte offset to a discretionary ACL. Only valid, if
  1587. SE_DACL_PRESENT is set in the control field. If
  1588. SE_DACL_PRESENT is set but dacl is NULL, a NULL ACL
  1589. (unconditionally granting access) is specified. */
  1590. /* sizeof() = 0x14 bytes */
  1591. } __attribute__ ((__packed__)) SECURITY_DESCRIPTOR_RELATIVE;
  1592. /*
  1593. * Absolute security descriptor. Does not contain the owner and group SIDs, nor
  1594. * the sacl and dacl ACLs inside the security descriptor. Instead, it contains
  1595. * pointers to these structures in memory. Obviously, absolute security
  1596. * descriptors are only useful for in memory representations of security
  1597. * descriptors. On disk, a self-relative security descriptor is used.
  1598. */
  1599. typedef struct {
  1600. u8 revision; /* Revision level of the security descriptor. */
  1601. u8 alignment;
  1602. SECURITY_DESCRIPTOR_CONTROL control; /* Flags qualifying the type of
  1603. the descriptor as well as the following fields. */
  1604. SID *owner; /* Points to a SID representing an object's owner. If
  1605. this is NULL, no owner SID is present in the
  1606. descriptor. */
  1607. SID *group; /* Points to a SID representing an object's primary
  1608. group. If this is NULL, no primary group SID is
  1609. present in the descriptor. */
  1610. ACL *sacl; /* Points to a system ACL. Only valid, if
  1611. SE_SACL_PRESENT is set in the control field. If
  1612. SE_SACL_PRESENT is set but sacl is NULL, a NULL ACL
  1613. is specified. */
  1614. ACL *dacl; /* Points to a discretionary ACL. Only valid, if
  1615. SE_DACL_PRESENT is set in the control field. If
  1616. SE_DACL_PRESENT is set but dacl is NULL, a NULL ACL
  1617. (unconditionally granting access) is specified. */
  1618. } __attribute__ ((__packed__)) SECURITY_DESCRIPTOR;
  1619. /*
  1620. * Current constants for security descriptors.
  1621. */
  1622. typedef enum {
  1623. /* Current revision. */
  1624. SECURITY_DESCRIPTOR_REVISION = 1,
  1625. SECURITY_DESCRIPTOR_REVISION1 = 1,
  1626. /* The sizes of both the absolute and relative security descriptors is
  1627. the same as pointers, at least on ia32 architecture are 32-bit. */
  1628. SECURITY_DESCRIPTOR_MIN_LENGTH = sizeof(SECURITY_DESCRIPTOR),
  1629. } SECURITY_DESCRIPTOR_CONSTANTS;
  1630. /*
  1631. * Attribute: Security descriptor (0x50). A standard self-relative security
  1632. * descriptor.
  1633. *
  1634. * NOTE: Can be resident or non-resident.
  1635. * NOTE: Not used in NTFS 3.0+, as security descriptors are stored centrally
  1636. * in FILE_Secure and the correct descriptor is found using the security_id
  1637. * from the standard information attribute.
  1638. */
  1639. typedef SECURITY_DESCRIPTOR_RELATIVE SECURITY_DESCRIPTOR_ATTR;
  1640. /*
  1641. * On NTFS 3.0+, all security descriptors are stored in FILE_Secure. Only one
  1642. * referenced instance of each unique security descriptor is stored.
  1643. *
  1644. * FILE_Secure contains no unnamed data attribute, i.e. it has zero length. It
  1645. * does, however, contain two indexes ($SDH and $SII) as well as a named data
  1646. * stream ($SDS).
  1647. *
  1648. * Every unique security descriptor is assigned a unique security identifier
  1649. * (security_id, not to be confused with a SID). The security_id is unique for
  1650. * the NTFS volume and is used as an index into the $SII index, which maps
  1651. * security_ids to the security descriptor's storage location within the $SDS
  1652. * data attribute. The $SII index is sorted by ascending security_id.
  1653. *
  1654. * A simple hash is computed from each security descriptor. This hash is used
  1655. * as an index into the $SDH index, which maps security descriptor hashes to
  1656. * the security descriptor's storage location within the $SDS data attribute.
  1657. * The $SDH index is sorted by security descriptor hash and is stored in a B+
  1658. * tree. When searching $SDH (with the intent of determining whether or not a
  1659. * new security descriptor is already present in the $SDS data stream), if a
  1660. * matching hash is found, but the security descriptors do not match, the
  1661. * search in the $SDH index is continued, searching for a next matching hash.
  1662. *
  1663. * When a precise match is found, the security_id coresponding to the security
  1664. * descriptor in the $SDS attribute is read from the found $SDH index entry and
  1665. * is stored in the $STANDARD_INFORMATION attribute of the file/directory to
  1666. * which the security descriptor is being applied. The $STANDARD_INFORMATION
  1667. * attribute is present in all base mft records (i.e. in all files and
  1668. * directories).
  1669. *
  1670. * If a match is not found, the security descriptor is assigned a new unique
  1671. * security_id and is added to the $SDS data attribute. Then, entries
  1672. * referencing the this security descriptor in the $SDS data attribute are
  1673. * added to the $SDH and $SII indexes.
  1674. *
  1675. * Note: Entries are never deleted from FILE_Secure, even if nothing
  1676. * references an entry any more.
  1677. */
  1678. /*
  1679. * This header precedes each security descriptor in the $SDS data stream.
  1680. * This is also the index entry data part of both the $SII and $SDH indexes.
  1681. */
  1682. typedef struct {
  1683. le32 hash; /* Hash of the security descriptor. */
  1684. le32 security_id; /* The security_id assigned to the descriptor. */
  1685. le64 offset; /* Byte offset of this entry in the $SDS stream. */
  1686. le32 length; /* Size in bytes of this entry in $SDS stream. */
  1687. } __attribute__ ((__packed__)) SECURITY_DESCRIPTOR_HEADER;
  1688. /*
  1689. * The $SDS data stream contains the security descriptors, aligned on 16-byte
  1690. * boundaries, sorted by security_id in a B+ tree. Security descriptors cannot
  1691. * cross 256kib boundaries (this restriction is imposed by the Windows cache
  1692. * manager). Each security descriptor is contained in a SDS_ENTRY structure.
  1693. * Also, each security descriptor is stored twice in the $SDS stream with a
  1694. * fixed offset of 0x40000 bytes (256kib, the Windows cache manager's max size)
  1695. * between them; i.e. if a SDS_ENTRY specifies an offset of 0x51d0, then the
  1696. * the first copy of the security descriptor will be at offset 0x51d0 in the
  1697. * $SDS data stream and the second copy will be at offset 0x451d0.
  1698. */
  1699. typedef struct {
  1700. /*Ofs*/
  1701. /* 0 SECURITY_DESCRIPTOR_HEADER; -- Unfolded here as gcc doesn't like
  1702. unnamed structs. */
  1703. le32 hash; /* Hash of the security descriptor. */
  1704. le32 security_id; /* The security_id assigned to the descriptor. */
  1705. le64 offset; /* Byte offset of this entry in the $SDS stream. */
  1706. le32 length; /* Size in bytes of this entry in $SDS stream. */
  1707. /* 20*/ SECURITY_DESCRIPTOR_RELATIVE sid; /* The self-relative security
  1708. descriptor. */
  1709. } __attribute__ ((__packed__)) SDS_ENTRY;
  1710. /*
  1711. * The index entry key used in the $SII index. The collation type is
  1712. * COLLATION_NTOFS_ULONG.
  1713. */
  1714. typedef struct {
  1715. le32 security_id; /* The security_id assigned to the descriptor. */
  1716. } __attribute__ ((__packed__)) SII_INDEX_KEY;
  1717. /*
  1718. * The index entry key used in the $SDH index. The keys are sorted first by
  1719. * hash and then by security_id. The collation rule is
  1720. * COLLATION_NTOFS_SECURITY_HASH.
  1721. */
  1722. typedef struct {
  1723. le32 hash; /* Hash of the security descriptor. */
  1724. le32 security_id; /* The security_id assigned to the descriptor. */
  1725. } __attribute__ ((__packed__)) SDH_INDEX_KEY;
  1726. /*
  1727. * Attribute: Volume name (0x60).
  1728. *
  1729. * NOTE: Always resident.
  1730. * NOTE: Present only in FILE_Volume.
  1731. */
  1732. typedef struct {
  1733. ntfschar name[0]; /* The name of the volume in Unicode. */
  1734. } __attribute__ ((__packed__)) VOLUME_NAME;
  1735. /*
  1736. * Possible flags for the volume (16-bit).
  1737. */
  1738. enum {
  1739. VOLUME_IS_DIRTY = cpu_to_le16(0x0001),
  1740. VOLUME_RESIZE_LOG_FILE = cpu_to_le16(0x0002),
  1741. VOLUME_UPGRADE_ON_MOUNT = cpu_to_le16(0x0004),
  1742. VOLUME_MOUNTED_ON_NT4 = cpu_to_le16(0x0008),
  1743. VOLUME_DELETE_USN_UNDERWAY = cpu_to_le16(0x0010),
  1744. VOLUME_REPAIR_OBJECT_ID = cpu_to_le16(0x0020),
  1745. VOLUME_CHKDSK_UNDERWAY = cpu_to_le16(0x4000),
  1746. VOLUME_MODIFIED_BY_CHKDSK = cpu_to_le16(0x8000),
  1747. VOLUME_FLAGS_MASK = cpu_to_le16(0xc03f),
  1748. /* To make our life easier when checking if we must mount read-only. */
  1749. VOLUME_MUST_MOUNT_RO_MASK = cpu_to_le16(0xc027),
  1750. } __attribute__ ((__packed__));
  1751. typedef le16 VOLUME_FLAGS;
  1752. /*
  1753. * Attribute: Volume information (0x70).
  1754. *
  1755. * NOTE: Always resident.
  1756. * NOTE: Present only in FILE_Volume.
  1757. * NOTE: Windows 2000 uses NTFS 3.0 while Windows NT4 service pack 6a uses
  1758. * NTFS 1.2. I haven't personally seen other values yet.
  1759. */
  1760. typedef struct {
  1761. le64 reserved; /* Not used (yet?). */
  1762. u8 major_ver; /* Major version of the ntfs format. */
  1763. u8 minor_ver; /* Minor version of the ntfs format. */
  1764. VOLUME_FLAGS flags; /* Bit array of VOLUME_* flags. */
  1765. } __attribute__ ((__packed__)) VOLUME_INFORMATION;
  1766. /*
  1767. * Attribute: Data attribute (0x80).
  1768. *
  1769. * NOTE: Can be resident or non-resident.
  1770. *
  1771. * Data contents of a file (i.e. the unnamed stream) or of a named stream.
  1772. */
  1773. typedef struct {
  1774. u8 data[0]; /* The file's data contents. */
  1775. } __attribute__ ((__packed__)) DATA_ATTR;
  1776. /*
  1777. * Index header flags (8-bit).
  1778. */
  1779. enum {
  1780. /*
  1781. * When index header is in an index root attribute:
  1782. */
  1783. SMALL_INDEX = 0, /* The index is small enough to fit inside the index
  1784. root attribute and there is no index allocation
  1785. attribute present. */
  1786. LARGE_INDEX = 1, /* The index is too large to fit in the index root
  1787. attribute and/or an index allocation attribute is
  1788. present. */
  1789. /*
  1790. * When index header is in an index block, i.e. is part of index
  1791. * allocation attribute:
  1792. */
  1793. LEAF_NODE = 0, /* This is a leaf node, i.e. there are no more nodes
  1794. branching off it. */
  1795. INDEX_NODE = 1, /* This node indexes other nodes, i.e. it is not a leaf
  1796. node. */
  1797. NODE_MASK = 1, /* Mask for accessing the *_NODE bits. */
  1798. } __attribute__ ((__packed__));
  1799. typedef u8 INDEX_HEADER_FLAGS;
  1800. /*
  1801. * This is the header for indexes, describing the INDEX_ENTRY records, which
  1802. * follow the INDEX_HEADER. Together the index header and the index entries
  1803. * make up a complete index.
  1804. *
  1805. * IMPORTANT NOTE: The offset, length and size structure members are counted
  1806. * relative to the start of the index header structure and not relative to the
  1807. * start of the index root or index allocation structures themselves.
  1808. */
  1809. typedef struct {
  1810. le32 entries_offset; /* Byte offset to first INDEX_ENTRY
  1811. aligned to 8-byte boundary. */
  1812. le32 index_length; /* Data size of the index in bytes,
  1813. i.e. bytes used from allocated
  1814. size, aligned to 8-byte boundary. */
  1815. le32 allocated_size; /* Byte size of this index (block),
  1816. multiple of 8 bytes. */
  1817. /* NOTE: For the index root attribute, the above two numbers are always
  1818. equal, as the attribute is resident and it is resized as needed. In
  1819. the case of the index allocation attribute the attribute is not
  1820. resident and hence the allocated_size is a fixed value and must
  1821. equal the index_block_size specified by the INDEX_ROOT attribute
  1822. corresponding to the INDEX_ALLOCATION attribute this INDEX_BLOCK
  1823. belongs to. */
  1824. INDEX_HEADER_FLAGS flags; /* Bit field of INDEX_HEADER_FLAGS. */
  1825. u8 reserved[3]; /* Reserved/align to 8-byte boundary. */
  1826. } __attribute__ ((__packed__)) INDEX_HEADER;
  1827. /*
  1828. * Attribute: Index root (0x90).
  1829. *
  1830. * NOTE: Always resident.
  1831. *
  1832. * This is followed by a sequence of index entries (INDEX_ENTRY structures)
  1833. * as described by the index header.
  1834. *
  1835. * When a directory is small enough to fit inside the index root then this
  1836. * is the only attribute describing the directory. When the directory is too
  1837. * large to fit in the index root, on the other hand, two additional attributes
  1838. * are present: an index allocation attribute, containing sub-nodes of the B+
  1839. * directory tree (see below), and a bitmap attribute, describing which virtual
  1840. * cluster numbers (vcns) in the index allocation attribute are in use by an
  1841. * index block.
  1842. *
  1843. * NOTE: The root directory (FILE_root) contains an entry for itself. Other
  1844. * directories do not contain entries for themselves, though.
  1845. */
  1846. typedef struct {
  1847. ATTR_TYPE type; /* Type of the indexed attribute. Is
  1848. $FILE_NAME for directories, zero
  1849. for view indexes. No other values
  1850. allowed. */
  1851. COLLATION_RULE collation_rule; /* Collation rule used to sort the
  1852. index entries. If type is $FILE_NAME,
  1853. this must be COLLATION_FILE_NAME. */
  1854. le32 index_block_size; /* Size of each index block in bytes (in
  1855. the index allocation attribute). */
  1856. u8 clusters_per_index_block; /* Cluster size of each index block (in
  1857. the index allocation attribute), when
  1858. an index block is >= than a cluster,
  1859. otherwise this will be the log of
  1860. the size (like how the encoding of
  1861. the mft record size and the index
  1862. record size found in the boot sector
  1863. work). Has to be a power of 2. */
  1864. u8 reserved[3]; /* Reserved/align to 8-byte boundary. */
  1865. INDEX_HEADER index; /* Index header describing the
  1866. following index entries. */
  1867. } __attribute__ ((__packed__)) INDEX_ROOT;
  1868. /*
  1869. * Attribute: Index allocation (0xa0).
  1870. *
  1871. * NOTE: Always non-resident (doesn't make sense to be resident anyway!).
  1872. *
  1873. * This is an array of index blocks. Each index block starts with an
  1874. * INDEX_BLOCK structure containing an index header, followed by a sequence of
  1875. * index entries (INDEX_ENTRY structures), as described by the INDEX_HEADER.
  1876. */
  1877. typedef struct {
  1878. /* 0 NTFS_RECORD; -- Unfolded here as gcc doesn't like unnamed structs. */
  1879. NTFS_RECORD_TYPE magic; /* Magic is "INDX". */
  1880. le16 usa_ofs; /* See NTFS_RECORD definition. */
  1881. le16 usa_count; /* See NTFS_RECORD definition. */
  1882. /* 8*/ sle64 lsn; /* $LogFile sequence number of the last
  1883. modification of this index block. */
  1884. /* 16*/ leVCN index_block_vcn; /* Virtual cluster number of the index block.
  1885. If the cluster_size on the volume is <= the
  1886. index_block_size of the directory,
  1887. index_block_vcn counts in units of clusters,
  1888. and in units of sectors otherwise. */
  1889. /* 24*/ INDEX_HEADER index; /* Describes the following index entries. */
  1890. /* sizeof()= 40 (0x28) bytes */
  1891. /*
  1892. * When creating the index block, we place the update sequence array at this
  1893. * offset, i.e. before we start with the index entries. This also makes sense,
  1894. * otherwise we could run into problems with the update sequence array
  1895. * containing in itself the last two bytes of a sector which would mean that
  1896. * multi sector transfer protection wouldn't work. As you can't protect data
  1897. * by overwriting it since you then can't get it back...
  1898. * When reading use the data from the ntfs record header.
  1899. */
  1900. } __attribute__ ((__packed__)) INDEX_BLOCK;
  1901. typedef INDEX_BLOCK INDEX_ALLOCATION;
  1902. /*
  1903. * The system file FILE_Extend/$Reparse contains an index named $R listing
  1904. * all reparse points on the volume. The index entry keys are as defined
  1905. * below. Note, that there is no index data associated with the index entries.
  1906. *
  1907. * The index entries are sorted by the index key file_id. The collation rule is
  1908. * COLLATION_NTOFS_ULONGS. FIXME: Verify whether the reparse_tag is not the
  1909. * primary key / is not a key at all. (AIA)
  1910. */
  1911. typedef struct {
  1912. le32 reparse_tag; /* Reparse point type (inc. flags). */
  1913. leMFT_REF file_id; /* Mft record of the file containing the
  1914. reparse point attribute. */
  1915. } __attribute__ ((__packed__)) REPARSE_INDEX_KEY;
  1916. /*
  1917. * Quota flags (32-bit).
  1918. *
  1919. * The user quota flags. Names explain meaning.
  1920. */
  1921. enum {
  1922. QUOTA_FLAG_DEFAULT_LIMITS = cpu_to_le32(0x00000001),
  1923. QUOTA_FLAG_LIMIT_REACHED = cpu_to_le32(0x00000002),
  1924. QUOTA_FLAG_ID_DELETED = cpu_to_le32(0x00000004),
  1925. QUOTA_FLAG_USER_MASK = cpu_to_le32(0x00000007),
  1926. /* This is a bit mask for the user quota flags. */
  1927. /*
  1928. * These flags are only present in the quota defaults index entry, i.e.
  1929. * in the entry where owner_id = QUOTA_DEFAULTS_ID.
  1930. */
  1931. QUOTA_FLAG_TRACKING_ENABLED = cpu_to_le32(0x00000010),
  1932. QUOTA_FLAG_ENFORCEMENT_ENABLED = cpu_to_le32(0x00000020),
  1933. QUOTA_FLAG_TRACKING_REQUESTED = cpu_to_le32(0x00000040),
  1934. QUOTA_FLAG_LOG_THRESHOLD = cpu_to_le32(0x00000080),
  1935. QUOTA_FLAG_LOG_LIMIT = cpu_to_le32(0x00000100),
  1936. QUOTA_FLAG_OUT_OF_DATE = cpu_to_le32(0x00000200),
  1937. QUOTA_FLAG_CORRUPT = cpu_to_le32(0x00000400),
  1938. QUOTA_FLAG_PENDING_DELETES = cpu_to_le32(0x00000800),
  1939. };
  1940. typedef le32 QUOTA_FLAGS;
  1941. /*
  1942. * The system file FILE_Extend/$Quota contains two indexes $O and $Q. Quotas
  1943. * are on a per volume and per user basis.
  1944. *
  1945. * The $Q index contains one entry for each existing user_id on the volume. The
  1946. * index key is the user_id of the user/group owning this quota control entry,
  1947. * i.e. the key is the owner_id. The user_id of the owner of a file, i.e. the
  1948. * owner_id, is found in the standard information attribute. The collation rule
  1949. * for $Q is COLLATION_NTOFS_ULONG.
  1950. *
  1951. * The $O index contains one entry for each user/group who has been assigned
  1952. * a quota on that volume. The index key holds the SID of the user_id the
  1953. * entry belongs to, i.e. the owner_id. The collation rule for $O is
  1954. * COLLATION_NTOFS_SID.
  1955. *
  1956. * The $O index entry data is the user_id of the user corresponding to the SID.
  1957. * This user_id is used as an index into $Q to find the quota control entry
  1958. * associated with the SID.
  1959. *
  1960. * The $Q index entry data is the quota control entry and is defined below.
  1961. */
  1962. typedef struct {
  1963. le32 version; /* Currently equals 2. */
  1964. QUOTA_FLAGS flags; /* Flags describing this quota entry. */
  1965. le64 bytes_used; /* How many bytes of the quota are in use. */
  1966. sle64 change_time; /* Last time this quota entry was changed. */
  1967. sle64 threshold; /* Soft quota (-1 if not limited). */
  1968. sle64 limit; /* Hard quota (-1 if not limited). */
  1969. sle64 exceeded_time; /* How long the soft quota has been exceeded. */
  1970. SID sid; /* The SID of the user/object associated with
  1971. this quota entry. Equals zero for the quota
  1972. defaults entry (and in fact on a WinXP
  1973. volume, it is not present at all). */
  1974. } __attribute__ ((__packed__)) QUOTA_CONTROL_ENTRY;
  1975. /*
  1976. * Predefined owner_id values (32-bit).
  1977. */
  1978. enum {
  1979. QUOTA_INVALID_ID = cpu_to_le32(0x00000000),
  1980. QUOTA_DEFAULTS_ID = cpu_to_le32(0x00000001),
  1981. QUOTA_FIRST_USER_ID = cpu_to_le32(0x00000100),
  1982. };
  1983. /*
  1984. * Current constants for quota control entries.
  1985. */
  1986. typedef enum {
  1987. /* Current version. */
  1988. QUOTA_VERSION = 2,
  1989. } QUOTA_CONTROL_ENTRY_CONSTANTS;
  1990. /*
  1991. * Index entry flags (16-bit).
  1992. */
  1993. enum {
  1994. INDEX_ENTRY_NODE = cpu_to_le16(1), /* This entry contains a
  1995. sub-node, i.e. a reference to an index block in form of
  1996. a virtual cluster number (see below). */
  1997. INDEX_ENTRY_END = cpu_to_le16(2), /* This signifies the last
  1998. entry in an index block. The index entry does not
  1999. represent a file but it can point to a sub-node. */
  2000. INDEX_ENTRY_SPACE_FILLER = cpu_to_le16(0xffff), /* gcc: Force
  2001. enum bit width to 16-bit. */
  2002. } __attribute__ ((__packed__));
  2003. typedef le16 INDEX_ENTRY_FLAGS;
  2004. /*
  2005. * This the index entry header (see below).
  2006. */
  2007. typedef struct {
  2008. /* 0*/ union {
  2009. struct { /* Only valid when INDEX_ENTRY_END is not set. */
  2010. leMFT_REF indexed_file; /* The mft reference of the file
  2011. described by this index
  2012. entry. Used for directory
  2013. indexes. */
  2014. } __attribute__ ((__packed__)) dir;
  2015. struct { /* Used for views/indexes to find the entry's data. */
  2016. le16 data_offset; /* Data byte offset from this
  2017. INDEX_ENTRY. Follows the
  2018. index key. */
  2019. le16 data_length; /* Data length in bytes. */
  2020. le32 reservedV; /* Reserved (zero). */
  2021. } __attribute__ ((__packed__)) vi;
  2022. } __attribute__ ((__packed__)) data;
  2023. /* 8*/ le16 length; /* Byte size of this index entry, multiple of
  2024. 8-bytes. */
  2025. /* 10*/ le16 key_length; /* Byte size of the key value, which is in the
  2026. index entry. It follows field reserved. Not
  2027. multiple of 8-bytes. */
  2028. /* 12*/ INDEX_ENTRY_FLAGS flags; /* Bit field of INDEX_ENTRY_* flags. */
  2029. /* 14*/ le16 reserved; /* Reserved/align to 8-byte boundary. */
  2030. /* sizeof() = 16 bytes */
  2031. } __attribute__ ((__packed__)) INDEX_ENTRY_HEADER;
  2032. /*
  2033. * This is an index entry. A sequence of such entries follows each INDEX_HEADER
  2034. * structure. Together they make up a complete index. The index follows either
  2035. * an index root attribute or an index allocation attribute.
  2036. *
  2037. * NOTE: Before NTFS 3.0 only filename attributes were indexed.
  2038. */
  2039. typedef struct {
  2040. /*Ofs*/
  2041. /* 0 INDEX_ENTRY_HEADER; -- Unfolded here as gcc dislikes unnamed structs. */
  2042. union {
  2043. struct { /* Only valid when INDEX_ENTRY_END is not set. */
  2044. leMFT_REF indexed_file; /* The mft reference of the file
  2045. described by this index
  2046. entry. Used for directory
  2047. indexes. */
  2048. } __attribute__ ((__packed__)) dir;
  2049. struct { /* Used for views/indexes to find the entry's data. */
  2050. le16 data_offset; /* Data byte offset from this
  2051. INDEX_ENTRY. Follows the
  2052. index key. */
  2053. le16 data_length; /* Data length in bytes. */
  2054. le32 reservedV; /* Reserved (zero). */
  2055. } __attribute__ ((__packed__)) vi;
  2056. } __attribute__ ((__packed__)) data;
  2057. le16 length; /* Byte size of this index entry, multiple of
  2058. 8-bytes. */
  2059. le16 key_length; /* Byte size of the key value, which is in the
  2060. index entry. It follows field reserved. Not
  2061. multiple of 8-bytes. */
  2062. INDEX_ENTRY_FLAGS flags; /* Bit field of INDEX_ENTRY_* flags. */
  2063. le16 reserved; /* Reserved/align to 8-byte boundary. */
  2064. /* 16*/ union { /* The key of the indexed attribute. NOTE: Only present
  2065. if INDEX_ENTRY_END bit in flags is not set. NOTE: On
  2066. NTFS versions before 3.0 the only valid key is the
  2067. FILE_NAME_ATTR. On NTFS 3.0+ the following
  2068. additional index keys are defined: */
  2069. FILE_NAME_ATTR file_name;/* $I30 index in directories. */
  2070. SII_INDEX_KEY sii; /* $SII index in $Secure. */
  2071. SDH_INDEX_KEY sdh; /* $SDH index in $Secure. */
  2072. GUID object_id; /* $O index in FILE_Extend/$ObjId: The
  2073. object_id of the mft record found in
  2074. the data part of the index. */
  2075. REPARSE_INDEX_KEY reparse; /* $R index in
  2076. FILE_Extend/$Reparse. */
  2077. SID sid; /* $O index in FILE_Extend/$Quota:
  2078. SID of the owner of the user_id. */
  2079. le32 owner_id; /* $Q index in FILE_Extend/$Quota:
  2080. user_id of the owner of the quota
  2081. control entry in the data part of
  2082. the index. */
  2083. } __attribute__ ((__packed__)) key;
  2084. /* The (optional) index data is inserted here when creating. */
  2085. // leVCN vcn; /* If INDEX_ENTRY_NODE bit in flags is set, the last
  2086. // eight bytes of this index entry contain the virtual
  2087. // cluster number of the index block that holds the
  2088. // entries immediately preceding the current entry (the
  2089. // vcn references the corresponding cluster in the data
  2090. // of the non-resident index allocation attribute). If
  2091. // the key_length is zero, then the vcn immediately
  2092. // follows the INDEX_ENTRY_HEADER. Regardless of
  2093. // key_length, the address of the 8-byte boundary
  2094. // aligned vcn of INDEX_ENTRY{_HEADER} *ie is given by
  2095. // (char*)ie + le16_to_cpu(ie*)->length) - sizeof(VCN),
  2096. // where sizeof(VCN) can be hardcoded as 8 if wanted. */
  2097. } __attribute__ ((__packed__)) INDEX_ENTRY;
  2098. /*
  2099. * Attribute: Bitmap (0xb0).
  2100. *
  2101. * Contains an array of bits (aka a bitfield).
  2102. *
  2103. * When used in conjunction with the index allocation attribute, each bit
  2104. * corresponds to one index block within the index allocation attribute. Thus
  2105. * the number of bits in the bitmap * index block size / cluster size is the
  2106. * number of clusters in the index allocation attribute.
  2107. */
  2108. typedef struct {
  2109. u8 bitmap[0]; /* Array of bits. */
  2110. } __attribute__ ((__packed__)) BITMAP_ATTR;
  2111. /*
  2112. * The reparse point tag defines the type of the reparse point. It also
  2113. * includes several flags, which further describe the reparse point.
  2114. *
  2115. * The reparse point tag is an unsigned 32-bit value divided in three parts:
  2116. *
  2117. * 1. The least significant 16 bits (i.e. bits 0 to 15) specifiy the type of
  2118. * the reparse point.
  2119. * 2. The 13 bits after this (i.e. bits 16 to 28) are reserved for future use.
  2120. * 3. The most significant three bits are flags describing the reparse point.
  2121. * They are defined as follows:
  2122. * bit 29: Name surrogate bit. If set, the filename is an alias for
  2123. * another object in the system.
  2124. * bit 30: High-latency bit. If set, accessing the first byte of data will
  2125. * be slow. (E.g. the data is stored on a tape drive.)
  2126. * bit 31: Microsoft bit. If set, the tag is owned by Microsoft. User
  2127. * defined tags have to use zero here.
  2128. *
  2129. * These are the predefined reparse point tags:
  2130. */
  2131. enum {
  2132. IO_REPARSE_TAG_IS_ALIAS = cpu_to_le32(0x20000000),
  2133. IO_REPARSE_TAG_IS_HIGH_LATENCY = cpu_to_le32(0x40000000),
  2134. IO_REPARSE_TAG_IS_MICROSOFT = cpu_to_le32(0x80000000),
  2135. IO_REPARSE_TAG_RESERVED_ZERO = cpu_to_le32(0x00000000),
  2136. IO_REPARSE_TAG_RESERVED_ONE = cpu_to_le32(0x00000001),
  2137. IO_REPARSE_TAG_RESERVED_RANGE = cpu_to_le32(0x00000001),
  2138. IO_REPARSE_TAG_NSS = cpu_to_le32(0x68000005),
  2139. IO_REPARSE_TAG_NSS_RECOVER = cpu_to_le32(0x68000006),
  2140. IO_REPARSE_TAG_SIS = cpu_to_le32(0x68000007),
  2141. IO_REPARSE_TAG_DFS = cpu_to_le32(0x68000008),
  2142. IO_REPARSE_TAG_MOUNT_POINT = cpu_to_le32(0x88000003),
  2143. IO_REPARSE_TAG_HSM = cpu_to_le32(0xa8000004),
  2144. IO_REPARSE_TAG_SYMBOLIC_LINK = cpu_to_le32(0xe8000000),
  2145. IO_REPARSE_TAG_VALID_VALUES = cpu_to_le32(0xe000ffff),
  2146. };
  2147. /*
  2148. * Attribute: Reparse point (0xc0).
  2149. *
  2150. * NOTE: Can be resident or non-resident.
  2151. */
  2152. typedef struct {
  2153. le32 reparse_tag; /* Reparse point type (inc. flags). */
  2154. le16 reparse_data_length; /* Byte size of reparse data. */
  2155. le16 reserved; /* Align to 8-byte boundary. */
  2156. u8 reparse_data[0]; /* Meaning depends on reparse_tag. */
  2157. } __attribute__ ((__packed__)) REPARSE_POINT;
  2158. /*
  2159. * Attribute: Extended attribute (EA) information (0xd0).
  2160. *
  2161. * NOTE: Always resident. (Is this true???)
  2162. */
  2163. typedef struct {
  2164. le16 ea_length; /* Byte size of the packed extended
  2165. attributes. */
  2166. le16 need_ea_count; /* The number of extended attributes which have
  2167. the NEED_EA bit set. */
  2168. le32 ea_query_length; /* Byte size of the buffer required to query
  2169. the extended attributes when calling
  2170. ZwQueryEaFile() in Windows NT/2k. I.e. the
  2171. byte size of the unpacked extended
  2172. attributes. */
  2173. } __attribute__ ((__packed__)) EA_INFORMATION;
  2174. /*
  2175. * Extended attribute flags (8-bit).
  2176. */
  2177. enum {
  2178. NEED_EA = 0x80 /* If set the file to which the EA belongs
  2179. cannot be interpreted without understanding
  2180. the associates extended attributes. */
  2181. } __attribute__ ((__packed__));
  2182. typedef u8 EA_FLAGS;
  2183. /*
  2184. * Attribute: Extended attribute (EA) (0xe0).
  2185. *
  2186. * NOTE: Can be resident or non-resident.
  2187. *
  2188. * Like the attribute list and the index buffer list, the EA attribute value is
  2189. * a sequence of EA_ATTR variable length records.
  2190. */
  2191. typedef struct {
  2192. le32 next_entry_offset; /* Offset to the next EA_ATTR. */
  2193. EA_FLAGS flags; /* Flags describing the EA. */
  2194. u8 ea_name_length; /* Length of the name of the EA in bytes
  2195. excluding the '\0' byte terminator. */
  2196. le16 ea_value_length; /* Byte size of the EA's value. */
  2197. u8 ea_name[0]; /* Name of the EA. Note this is ASCII, not
  2198. Unicode and it is zero terminated. */
  2199. u8 ea_value[0]; /* The value of the EA. Immediately follows
  2200. the name. */
  2201. } __attribute__ ((__packed__)) EA_ATTR;
  2202. /*
  2203. * Attribute: Property set (0xf0).
  2204. *
  2205. * Intended to support Native Structure Storage (NSS) - a feature removed from
  2206. * NTFS 3.0 during beta testing.
  2207. */
  2208. typedef struct {
  2209. /* Irrelevant as feature unused. */
  2210. } __attribute__ ((__packed__)) PROPERTY_SET;
  2211. /*
  2212. * Attribute: Logged utility stream (0x100).
  2213. *
  2214. * NOTE: Can be resident or non-resident.
  2215. *
  2216. * Operations on this attribute are logged to the journal ($LogFile) like
  2217. * normal metadata changes.
  2218. *
  2219. * Used by the Encrypting File System (EFS). All encrypted files have this
  2220. * attribute with the name $EFS.
  2221. */
  2222. typedef struct {
  2223. /* Can be anything the creator chooses. */
  2224. /* EFS uses it as follows: */
  2225. // FIXME: Type this info, verifying it along the way. (AIA)
  2226. } __attribute__ ((__packed__)) LOGGED_UTILITY_STREAM, EFS_ATTR;
  2227. #endif /* _LINUX_NTFS_LAYOUT_H */