layout.h 97 KB

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