layout.h 98 KB

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