layout.h 97 KB

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