007-upstream_mkfs_ext2_fixes.patch 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441
  1. --- a/e2fsprogs/e2fs_defs.h
  2. +++ /dev/null
  3. @@ -1,561 +0,0 @@
  4. -/* vi: set sw=4 ts=4: */
  5. -/*
  6. - * linux/include/linux/ext2_fs.h
  7. - *
  8. - * Copyright (C) 1992, 1993, 1994, 1995
  9. - * Remy Card ([email protected])
  10. - * Laboratoire MASI - Institut Blaise Pascal
  11. - * Universite Pierre et Marie Curie (Paris VI)
  12. - *
  13. - * Copyright (C) 1991, 1992 Linus Torvalds
  14. - */
  15. -
  16. -#ifndef LINUX_EXT2_FS_H
  17. -#define LINUX_EXT2_FS_H 1
  18. -
  19. -/*
  20. - * Special inode numbers
  21. - */
  22. -#define EXT2_BAD_INO 1 /* Bad blocks inode */
  23. -#define EXT2_ROOT_INO 2 /* Root inode */
  24. -#define EXT2_ACL_IDX_INO 3 /* ACL inode */
  25. -#define EXT2_ACL_DATA_INO 4 /* ACL inode */
  26. -#define EXT2_BOOT_LOADER_INO 5 /* Boot loader inode */
  27. -#define EXT2_UNDEL_DIR_INO 6 /* Undelete directory inode */
  28. -#define EXT2_RESIZE_INO 7 /* Reserved group descriptors inode */
  29. -#define EXT2_JOURNAL_INO 8 /* Journal inode */
  30. -
  31. -/* First non-reserved inode for old ext2 filesystems */
  32. -#define EXT2_GOOD_OLD_FIRST_INO 11
  33. -
  34. -/*
  35. - * The second extended file system magic number
  36. - */
  37. -#define EXT2_SUPER_MAGIC 0xEF53
  38. -
  39. -/* Assume that user mode programs are passing in an ext2fs superblock, not
  40. - * a kernel struct super_block. This will allow us to call the feature-test
  41. - * macros from user land. */
  42. -#define EXT2_SB(sb) (sb)
  43. -
  44. -/*
  45. - * Maximal count of links to a file
  46. - */
  47. -#define EXT2_LINK_MAX 32000
  48. -
  49. -/*
  50. - * Macro-instructions used to manage several block sizes
  51. - */
  52. -#define EXT2_MIN_BLOCK_LOG_SIZE 10 /* 1024 */
  53. -#define EXT2_MAX_BLOCK_LOG_SIZE 16 /* 65536 */
  54. -#define EXT2_MIN_BLOCK_SIZE (1 << EXT2_MIN_BLOCK_LOG_SIZE)
  55. -#define EXT2_MAX_BLOCK_SIZE (1 << EXT2_MAX_BLOCK_LOG_SIZE)
  56. -#define EXT2_BLOCK_SIZE(s) (EXT2_MIN_BLOCK_SIZE << (s)->s_log_block_size)
  57. -#define EXT2_BLOCK_SIZE_BITS(s) ((s)->s_log_block_size + 10)
  58. -#define EXT2_INODE_SIZE(s) (((s)->s_rev_level == EXT2_GOOD_OLD_REV) ? \
  59. - EXT2_GOOD_OLD_INODE_SIZE : (s)->s_inode_size)
  60. -#define EXT2_FIRST_INO(s) (((s)->s_rev_level == EXT2_GOOD_OLD_REV) ? \
  61. - EXT2_GOOD_OLD_FIRST_INO : (s)->s_first_ino)
  62. -#define EXT2_ADDR_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / sizeof(uint32_t))
  63. -
  64. -/*
  65. - * Macro-instructions used to manage fragments
  66. - */
  67. -#define EXT2_MIN_FRAG_SIZE EXT2_MIN_BLOCK_SIZE
  68. -#define EXT2_MAX_FRAG_SIZE EXT2_MAX_BLOCK_SIZE
  69. -#define EXT2_MIN_FRAG_LOG_SIZE EXT2_MIN_BLOCK_LOG_SIZE
  70. -#define EXT2_FRAG_SIZE(s) (EXT2_MIN_FRAG_SIZE << (s)->s_log_frag_size)
  71. -#define EXT2_FRAGS_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / EXT2_FRAG_SIZE(s))
  72. -
  73. -/*
  74. - * ACL structures
  75. - */
  76. -struct ext2_acl_header { /* Header of Access Control Lists */
  77. - uint32_t aclh_size;
  78. - uint32_t aclh_file_count;
  79. - uint32_t aclh_acle_count;
  80. - uint32_t aclh_first_acle;
  81. -};
  82. -
  83. -struct ext2_acl_entry { /* Access Control List Entry */
  84. - uint32_t acle_size;
  85. - uint16_t acle_perms; /* Access permissions */
  86. - uint16_t acle_type; /* Type of entry */
  87. - uint16_t acle_tag; /* User or group identity */
  88. - uint16_t acle_pad1;
  89. - uint32_t acle_next; /* Pointer on next entry for the */
  90. - /* same inode or on next free entry */
  91. -};
  92. -
  93. -/*
  94. - * Structure of a blocks group descriptor
  95. - */
  96. -struct ext2_group_desc {
  97. - uint32_t bg_block_bitmap; /* Blocks bitmap block */
  98. - uint32_t bg_inode_bitmap; /* Inodes bitmap block */
  99. - uint32_t bg_inode_table; /* Inodes table block */
  100. - uint16_t bg_free_blocks_count; /* Free blocks count */
  101. - uint16_t bg_free_inodes_count; /* Free inodes count */
  102. - uint16_t bg_used_dirs_count; /* Directories count */
  103. - uint16_t bg_pad;
  104. - uint32_t bg_reserved[3];
  105. -};
  106. -
  107. -/*
  108. - * Data structures used by the directory indexing feature
  109. - *
  110. - * Note: all of the multibyte integer fields are little endian.
  111. - */
  112. -
  113. -/*
  114. - * Note: dx_root_info is laid out so that if it should somehow get
  115. - * overlaid by a dirent the two low bits of the hash version will be
  116. - * zero. Therefore, the hash version mod 4 should never be 0.
  117. - * Sincerely, the paranoia department.
  118. - */
  119. -struct ext2_dx_root_info {
  120. - uint32_t reserved_zero;
  121. - uint8_t hash_version; /* 0 now, 1 at release */
  122. - uint8_t info_length; /* 8 */
  123. - uint8_t indirect_levels;
  124. - uint8_t unused_flags;
  125. -};
  126. -
  127. -#define EXT2_HASH_LEGACY 0
  128. -#define EXT2_HASH_HALF_MD4 1
  129. -#define EXT2_HASH_TEA 2
  130. -
  131. -#define EXT2_HASH_FLAG_INCOMPAT 0x1
  132. -
  133. -struct ext2_dx_entry {
  134. - uint32_t hash;
  135. - uint32_t block;
  136. -};
  137. -
  138. -struct ext2_dx_countlimit {
  139. - uint16_t limit;
  140. - uint16_t count;
  141. -};
  142. -
  143. -
  144. -/*
  145. - * Macro-instructions used to manage group descriptors
  146. - */
  147. -#define EXT2_BLOCKS_PER_GROUP(s) (EXT2_SB(s)->s_blocks_per_group)
  148. -#define EXT2_INODES_PER_GROUP(s) (EXT2_SB(s)->s_inodes_per_group)
  149. -#define EXT2_INODES_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s)/EXT2_INODE_SIZE(s))
  150. -/* limits imposed by 16-bit value gd_free_{blocks,inode}_count */
  151. -#define EXT2_MAX_BLOCKS_PER_GROUP(s) ((1 << 16) - 8)
  152. -#define EXT2_MAX_INODES_PER_GROUP(s) ((1 << 16) - EXT2_INODES_PER_BLOCK(s))
  153. -#define EXT2_DESC_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / sizeof (struct ext2_group_desc))
  154. -
  155. -/*
  156. - * Constants relative to the data blocks
  157. - */
  158. -#define EXT2_NDIR_BLOCKS 12
  159. -#define EXT2_IND_BLOCK EXT2_NDIR_BLOCKS
  160. -#define EXT2_DIND_BLOCK (EXT2_IND_BLOCK + 1)
  161. -#define EXT2_TIND_BLOCK (EXT2_DIND_BLOCK + 1)
  162. -#define EXT2_N_BLOCKS (EXT2_TIND_BLOCK + 1)
  163. -
  164. -/*
  165. - * Inode flags
  166. - */
  167. -#define EXT2_SECRM_FL 0x00000001 /* Secure deletion */
  168. -#define EXT2_UNRM_FL 0x00000002 /* Undelete */
  169. -#define EXT2_COMPR_FL 0x00000004 /* Compress file */
  170. -#define EXT2_SYNC_FL 0x00000008 /* Synchronous updates */
  171. -#define EXT2_IMMUTABLE_FL 0x00000010 /* Immutable file */
  172. -#define EXT2_APPEND_FL 0x00000020 /* writes to file may only append */
  173. -#define EXT2_NODUMP_FL 0x00000040 /* do not dump file */
  174. -#define EXT2_NOATIME_FL 0x00000080 /* do not update atime */
  175. -/* Reserved for compression usage... */
  176. -#define EXT2_DIRTY_FL 0x00000100
  177. -#define EXT2_COMPRBLK_FL 0x00000200 /* One or more compressed clusters */
  178. -#define EXT2_NOCOMPR_FL 0x00000400 /* Access raw compressed data */
  179. -#define EXT2_ECOMPR_FL 0x00000800 /* Compression error */
  180. -/* End compression flags --- maybe not all used */
  181. -#define EXT2_BTREE_FL 0x00001000 /* btree format dir */
  182. -#define EXT2_INDEX_FL 0x00001000 /* hash-indexed directory */
  183. -#define EXT2_IMAGIC_FL 0x00002000
  184. -#define EXT3_JOURNAL_DATA_FL 0x00004000 /* file data should be journaled */
  185. -#define EXT2_NOTAIL_FL 0x00008000 /* file tail should not be merged */
  186. -#define EXT2_DIRSYNC_FL 0x00010000 /* Synchronous directory modifications */
  187. -#define EXT2_TOPDIR_FL 0x00020000 /* Top of directory hierarchies*/
  188. -#define EXT3_EXTENTS_FL 0x00080000 /* Inode uses extents */
  189. -#define EXT2_RESERVED_FL 0x80000000 /* reserved for ext2 lib */
  190. -
  191. -#define EXT2_FL_USER_VISIBLE 0x0003DFFF /* User visible flags */
  192. -#define EXT2_FL_USER_MODIFIABLE 0x000080FF /* User modifiable flags */
  193. -
  194. -/*
  195. - * ioctl commands
  196. - */
  197. -#define EXT2_IOC_GETFLAGS _IOR('f', 1, long)
  198. -#define EXT2_IOC_SETFLAGS _IOW('f', 2, long)
  199. -#define EXT2_IOC_GETVERSION _IOR('v', 1, long)
  200. -#define EXT2_IOC_SETVERSION _IOW('v', 2, long)
  201. -
  202. -/*
  203. - * Structure of an inode on the disk
  204. - */
  205. -struct ext2_inode {
  206. - uint16_t i_mode; /* File mode */
  207. - uint16_t i_uid; /* Low 16 bits of Owner Uid */
  208. - uint32_t i_size; /* Size in bytes */
  209. - uint32_t i_atime; /* Access time */
  210. - uint32_t i_ctime; /* Creation time */
  211. - uint32_t i_mtime; /* Modification time */
  212. - uint32_t i_dtime; /* Deletion Time */
  213. - uint16_t i_gid; /* Low 16 bits of Group Id */
  214. - uint16_t i_links_count; /* Links count */
  215. - uint32_t i_blocks; /* Blocks count */
  216. - uint32_t i_flags; /* File flags */
  217. - union {
  218. - struct {
  219. - uint32_t l_i_reserved1;
  220. - } linux1;
  221. - struct {
  222. - uint32_t h_i_translator;
  223. - } hurd1;
  224. - struct {
  225. - uint32_t m_i_reserved1;
  226. - } masix1;
  227. - } osd1; /* OS dependent 1 */
  228. - uint32_t i_block[EXT2_N_BLOCKS];/* Pointers to blocks */
  229. - uint32_t i_generation; /* File version (for NFS) */
  230. - uint32_t i_file_acl; /* File ACL */
  231. - uint32_t i_dir_acl; /* Directory ACL */
  232. - uint32_t i_faddr; /* Fragment address */
  233. - union {
  234. - struct {
  235. - uint8_t l_i_frag; /* Fragment number */
  236. - uint8_t l_i_fsize; /* Fragment size */
  237. - uint16_t i_pad1;
  238. - uint16_t l_i_uid_high; /* these 2 fields */
  239. - uint16_t l_i_gid_high; /* were reserved2[0] */
  240. - uint32_t l_i_reserved2;
  241. - } linux2;
  242. - struct {
  243. - uint8_t h_i_frag; /* Fragment number */
  244. - uint8_t h_i_fsize; /* Fragment size */
  245. - uint16_t h_i_mode_high;
  246. - uint16_t h_i_uid_high;
  247. - uint16_t h_i_gid_high;
  248. - uint32_t h_i_author;
  249. - } hurd2;
  250. - struct {
  251. - uint8_t m_i_frag; /* Fragment number */
  252. - uint8_t m_i_fsize; /* Fragment size */
  253. - uint16_t m_pad1;
  254. - uint32_t m_i_reserved2[2];
  255. - } masix2;
  256. - } osd2; /* OS dependent 2 */
  257. -};
  258. -
  259. -/*
  260. - * Permanent part of an large inode on the disk
  261. - */
  262. -struct ext2_inode_large {
  263. - uint16_t i_mode; /* File mode */
  264. - uint16_t i_uid; /* Low 16 bits of Owner Uid */
  265. - uint32_t i_size; /* Size in bytes */
  266. - uint32_t i_atime; /* Access time */
  267. - uint32_t i_ctime; /* Creation time */
  268. - uint32_t i_mtime; /* Modification time */
  269. - uint32_t i_dtime; /* Deletion Time */
  270. - uint16_t i_gid; /* Low 16 bits of Group Id */
  271. - uint16_t i_links_count; /* Links count */
  272. - uint32_t i_blocks; /* Blocks count */
  273. - uint32_t i_flags; /* File flags */
  274. - union {
  275. - struct {
  276. - uint32_t l_i_reserved1;
  277. - } linux1;
  278. - struct {
  279. - uint32_t h_i_translator;
  280. - } hurd1;
  281. - struct {
  282. - uint32_t m_i_reserved1;
  283. - } masix1;
  284. - } osd1; /* OS dependent 1 */
  285. - uint32_t i_block[EXT2_N_BLOCKS];/* Pointers to blocks */
  286. - uint32_t i_generation; /* File version (for NFS) */
  287. - uint32_t i_file_acl; /* File ACL */
  288. - uint32_t i_dir_acl; /* Directory ACL */
  289. - uint32_t i_faddr; /* Fragment address */
  290. - union {
  291. - struct {
  292. - uint8_t l_i_frag; /* Fragment number */
  293. - uint8_t l_i_fsize; /* Fragment size */
  294. - uint16_t i_pad1;
  295. - uint16_t l_i_uid_high; /* these 2 fields */
  296. - uint16_t l_i_gid_high; /* were reserved2[0] */
  297. - uint32_t l_i_reserved2;
  298. - } linux2;
  299. - struct {
  300. - uint8_t h_i_frag; /* Fragment number */
  301. - uint8_t h_i_fsize; /* Fragment size */
  302. - uint16_t h_i_mode_high;
  303. - uint16_t h_i_uid_high;
  304. - uint16_t h_i_gid_high;
  305. - uint32_t h_i_author;
  306. - } hurd2;
  307. - struct {
  308. - uint8_t m_i_frag; /* Fragment number */
  309. - uint8_t m_i_fsize; /* Fragment size */
  310. - uint16_t m_pad1;
  311. - uint32_t m_i_reserved2[2];
  312. - } masix2;
  313. - } osd2; /* OS dependent 2 */
  314. - uint16_t i_extra_isize;
  315. - uint16_t i_pad1;
  316. -};
  317. -
  318. -#define i_size_high i_dir_acl
  319. -
  320. -/*
  321. - * File system states
  322. - */
  323. -#define EXT2_VALID_FS 0x0001 /* Unmounted cleanly */
  324. -#define EXT2_ERROR_FS 0x0002 /* Errors detected */
  325. -
  326. -/*
  327. - * Mount flags
  328. - */
  329. -#define EXT2_MOUNT_CHECK 0x0001 /* Do mount-time checks */
  330. -#define EXT2_MOUNT_GRPID 0x0004 /* Create files with directory's group */
  331. -#define EXT2_MOUNT_DEBUG 0x0008 /* Some debugging messages */
  332. -#define EXT2_MOUNT_ERRORS_CONT 0x0010 /* Continue on errors */
  333. -#define EXT2_MOUNT_ERRORS_RO 0x0020 /* Remount fs ro on errors */
  334. -#define EXT2_MOUNT_ERRORS_PANIC 0x0040 /* Panic on errors */
  335. -#define EXT2_MOUNT_MINIX_DF 0x0080 /* Mimics the Minix statfs */
  336. -#define EXT2_MOUNT_NO_UID32 0x0200 /* Disable 32-bit UIDs */
  337. -
  338. -#define clear_opt(o, opt) o &= ~EXT2_MOUNT_##opt
  339. -#define set_opt(o, opt) o |= EXT2_MOUNT_##opt
  340. -#define test_opt(sb, opt) (EXT2_SB(sb)->s_mount_opt & \
  341. - EXT2_MOUNT_##opt)
  342. -/*
  343. - * Maximal mount counts between two filesystem checks
  344. - */
  345. -#define EXT2_DFL_MAX_MNT_COUNT 20 /* Allow 20 mounts */
  346. -#define EXT2_DFL_CHECKINTERVAL 0 /* Don't use interval check */
  347. -
  348. -/*
  349. - * Behaviour when detecting errors
  350. - */
  351. -#define EXT2_ERRORS_CONTINUE 1 /* Continue execution */
  352. -#define EXT2_ERRORS_RO 2 /* Remount fs read-only */
  353. -#define EXT2_ERRORS_PANIC 3 /* Panic */
  354. -#define EXT2_ERRORS_DEFAULT EXT2_ERRORS_CONTINUE
  355. -
  356. -/*
  357. - * Structure of the super block
  358. - */
  359. -struct ext2_super_block {
  360. - uint32_t s_inodes_count; /* Inodes count */
  361. - uint32_t s_blocks_count; /* Blocks count */
  362. - uint32_t s_r_blocks_count; /* Reserved blocks count */
  363. - uint32_t s_free_blocks_count; /* Free blocks count */
  364. - uint32_t s_free_inodes_count; /* Free inodes count */
  365. - uint32_t s_first_data_block; /* First Data Block */
  366. - uint32_t s_log_block_size; /* Block size */
  367. - int32_t s_log_frag_size; /* Fragment size */
  368. - uint32_t s_blocks_per_group; /* # Blocks per group */
  369. - uint32_t s_frags_per_group; /* # Fragments per group */
  370. - uint32_t s_inodes_per_group; /* # Inodes per group */
  371. - uint32_t s_mtime; /* Mount time */
  372. - uint32_t s_wtime; /* Write time */
  373. - uint16_t s_mnt_count; /* Mount count */
  374. - int16_t s_max_mnt_count; /* Maximal mount count */
  375. - uint16_t s_magic; /* Magic signature */
  376. - uint16_t s_state; /* File system state */
  377. - uint16_t s_errors; /* Behaviour when detecting errors */
  378. - uint16_t s_minor_rev_level; /* minor revision level */
  379. - uint32_t s_lastcheck; /* time of last check */
  380. - uint32_t s_checkinterval; /* max. time between checks */
  381. - uint32_t s_creator_os; /* OS */
  382. - uint32_t s_rev_level; /* Revision level */
  383. - uint16_t s_def_resuid; /* Default uid for reserved blocks */
  384. - uint16_t s_def_resgid; /* Default gid for reserved blocks */
  385. - /*
  386. - * These fields are for EXT2_DYNAMIC_REV superblocks only.
  387. - *
  388. - * Note: the difference between the compatible feature set and
  389. - * the incompatible feature set is that if there is a bit set
  390. - * in the incompatible feature set that the kernel doesn't
  391. - * know about, it should refuse to mount the filesystem.
  392. - *
  393. - * e2fsck's requirements are more strict; if it doesn't know
  394. - * about a feature in either the compatible or incompatible
  395. - * feature set, it must abort and not try to meddle with
  396. - * things it doesn't understand...
  397. - */
  398. - uint32_t s_first_ino; /* First non-reserved inode */
  399. - uint16_t s_inode_size; /* size of inode structure */
  400. - uint16_t s_block_group_nr; /* block group # of this superblock */
  401. - uint32_t s_feature_compat; /* compatible feature set */
  402. - uint32_t s_feature_incompat; /* incompatible feature set */
  403. - uint32_t s_feature_ro_compat; /* readonly-compatible feature set */
  404. - uint8_t s_uuid[16]; /* 128-bit uuid for volume */
  405. - char s_volume_name[16]; /* volume name */
  406. - char s_last_mounted[64]; /* directory where last mounted */
  407. - uint32_t s_algorithm_usage_bitmap; /* For compression */
  408. - /*
  409. - * Performance hints. Directory preallocation should only
  410. - * happen if the EXT2_FEATURE_COMPAT_DIR_PREALLOC flag is on.
  411. - */
  412. - uint8_t s_prealloc_blocks; /* Nr of blocks to try to preallocate*/
  413. - uint8_t s_prealloc_dir_blocks; /* Nr to preallocate for dirs */
  414. - uint16_t s_reserved_gdt_blocks; /* Per group table for online growth */
  415. - /*
  416. - * Journaling support valid if EXT2_FEATURE_COMPAT_HAS_JOURNAL set.
  417. - */
  418. - uint8_t s_journal_uuid[16]; /* uuid of journal superblock */
  419. - uint32_t s_journal_inum; /* inode number of journal file */
  420. - uint32_t s_journal_dev; /* device number of journal file */
  421. - uint32_t s_last_orphan; /* start of list of inodes to delete */
  422. - uint32_t s_hash_seed[4]; /* HTREE hash seed */
  423. - uint8_t s_def_hash_version; /* Default hash version to use */
  424. - uint8_t s_jnl_backup_type; /* Default type of journal backup */
  425. - uint16_t s_reserved_word_pad;
  426. - uint32_t s_default_mount_opts;
  427. - uint32_t s_first_meta_bg; /* First metablock group */
  428. - uint32_t s_mkfs_time; /* When the filesystem was created */
  429. - uint32_t s_jnl_blocks[17]; /* Backup of the journal inode */
  430. - uint32_t s_reserved[172]; /* Padding to the end of the block */
  431. -};
  432. -
  433. -/*
  434. - * Codes for operating systems
  435. - */
  436. -#define EXT2_OS_LINUX 0
  437. -#define EXT2_OS_HURD 1
  438. -#define EXT2_OS_MASIX 2
  439. -#define EXT2_OS_FREEBSD 3
  440. -#define EXT2_OS_LITES 4
  441. -
  442. -/*
  443. - * Revision levels
  444. - */
  445. -#define EXT2_GOOD_OLD_REV 0 /* The good old (original) format */
  446. -#define EXT2_DYNAMIC_REV 1 /* V2 format w/ dynamic inode sizes */
  447. -
  448. -#define EXT2_CURRENT_REV EXT2_GOOD_OLD_REV
  449. -#define EXT2_MAX_SUPP_REV EXT2_DYNAMIC_REV
  450. -
  451. -#define EXT2_GOOD_OLD_INODE_SIZE 128
  452. -
  453. -/*
  454. - * Journal inode backup types
  455. - */
  456. -#define EXT3_JNL_BACKUP_BLOCKS 1
  457. -
  458. -/*
  459. - * Feature set definitions
  460. - */
  461. -
  462. -#define EXT2_HAS_COMPAT_FEATURE(sb,mask) \
  463. - ( EXT2_SB(sb)->s_feature_compat & (mask) )
  464. -#define EXT2_HAS_RO_COMPAT_FEATURE(sb,mask) \
  465. - ( EXT2_SB(sb)->s_feature_ro_compat & (mask) )
  466. -#define EXT2_HAS_INCOMPAT_FEATURE(sb,mask) \
  467. - ( EXT2_SB(sb)->s_feature_incompat & (mask) )
  468. -
  469. -#define EXT2_FEATURE_COMPAT_DIR_PREALLOC 0x0001
  470. -#define EXT2_FEATURE_COMPAT_IMAGIC_INODES 0x0002
  471. -#define EXT3_FEATURE_COMPAT_HAS_JOURNAL 0x0004
  472. -#define EXT2_FEATURE_COMPAT_EXT_ATTR 0x0008
  473. -#define EXT2_FEATURE_COMPAT_RESIZE_INODE 0x0010
  474. -#define EXT2_FEATURE_COMPAT_DIR_INDEX 0x0020
  475. -
  476. -#define EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER 0x0001
  477. -#define EXT2_FEATURE_RO_COMPAT_LARGE_FILE 0x0002
  478. -/* #define EXT2_FEATURE_RO_COMPAT_BTREE_DIR 0x0004 not used */
  479. -
  480. -#define EXT2_FEATURE_INCOMPAT_COMPRESSION 0x0001
  481. -#define EXT2_FEATURE_INCOMPAT_FILETYPE 0x0002
  482. -#define EXT3_FEATURE_INCOMPAT_RECOVER 0x0004 /* Needs recovery */
  483. -#define EXT3_FEATURE_INCOMPAT_JOURNAL_DEV 0x0008 /* Journal device */
  484. -#define EXT2_FEATURE_INCOMPAT_META_BG 0x0010
  485. -#define EXT3_FEATURE_INCOMPAT_EXTENTS 0x0040
  486. -
  487. -
  488. -#define EXT2_FEATURE_COMPAT_SUPP 0
  489. -#define EXT2_FEATURE_INCOMPAT_SUPP (EXT2_FEATURE_INCOMPAT_FILETYPE)
  490. -#define EXT2_FEATURE_RO_COMPAT_SUPP (EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER| \
  491. - EXT2_FEATURE_RO_COMPAT_LARGE_FILE| \
  492. - EXT2_FEATURE_RO_COMPAT_BTREE_DIR)
  493. -
  494. -/*
  495. - * Default values for user and/or group using reserved blocks
  496. - */
  497. -#define EXT2_DEF_RESUID 0
  498. -#define EXT2_DEF_RESGID 0
  499. -
  500. -/*
  501. - * Default mount options
  502. - */
  503. -#define EXT2_DEFM_DEBUG 0x0001
  504. -#define EXT2_DEFM_BSDGROUPS 0x0002
  505. -#define EXT2_DEFM_XATTR_USER 0x0004
  506. -#define EXT2_DEFM_ACL 0x0008
  507. -#define EXT2_DEFM_UID16 0x0010
  508. -#define EXT3_DEFM_JMODE 0x0060
  509. -#define EXT3_DEFM_JMODE_DATA 0x0020
  510. -#define EXT3_DEFM_JMODE_ORDERED 0x0040
  511. -#define EXT3_DEFM_JMODE_WBACK 0x0060
  512. -
  513. -/*
  514. - * Structure of a directory entry
  515. - */
  516. -#define EXT2_NAME_LEN 255
  517. -
  518. -struct ext2_dir_entry {
  519. - uint32_t inode; /* Inode number */
  520. - uint16_t rec_len; /* Directory entry length */
  521. - uint16_t name_len; /* Name length */
  522. - char name[EXT2_NAME_LEN]; /* File name */
  523. -};
  524. -
  525. -/*
  526. - * The new version of the directory entry. Since EXT2 structures are
  527. - * stored in intel byte order, and the name_len field could never be
  528. - * bigger than 255 chars, it's safe to reclaim the extra byte for the
  529. - * file_type field.
  530. - */
  531. -struct ext2_dir_entry_2 {
  532. - uint32_t inode; /* Inode number */
  533. - uint16_t rec_len; /* Directory entry length */
  534. - uint8_t name_len; /* Name length */
  535. - uint8_t file_type;
  536. - char name[EXT2_NAME_LEN]; /* File name */
  537. -};
  538. -
  539. -/*
  540. - * Ext2 directory file types. Only the low 3 bits are used. The
  541. - * other bits are reserved for now.
  542. - */
  543. -#define EXT2_FT_UNKNOWN 0
  544. -#define EXT2_FT_REG_FILE 1
  545. -#define EXT2_FT_DIR 2
  546. -#define EXT2_FT_CHRDEV 3
  547. -#define EXT2_FT_BLKDEV 4
  548. -#define EXT2_FT_FIFO 5
  549. -#define EXT2_FT_SOCK 6
  550. -#define EXT2_FT_SYMLINK 7
  551. -
  552. -#define EXT2_FT_MAX 8
  553. -
  554. -/*
  555. - * EXT2_DIR_PAD defines the directory entries boundaries
  556. - *
  557. - * NOTE: It must be a multiple of 4
  558. - */
  559. -#define EXT2_DIR_PAD 4
  560. -#define EXT2_DIR_ROUND (EXT2_DIR_PAD - 1)
  561. -#define EXT2_DIR_REC_LEN(name_len) (((name_len) + 8 + EXT2_DIR_ROUND) & \
  562. - ~EXT2_DIR_ROUND)
  563. -
  564. -#endif
  565. --- a/e2fsprogs/e2fs_lib.h
  566. +++ b/e2fsprogs/e2fs_lib.h
  567. @@ -7,7 +7,7 @@
  568. */
  569. /* Constants and structures */
  570. -#include "e2fs_defs.h"
  571. +#include "bb_e2fs_defs.h"
  572. PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN
  573. --- a/e2fsprogs/old_e2fsprogs/e2fsck.c
  574. +++ b/e2fsprogs/old_e2fsprogs/e2fsck.c
  575. @@ -11577,7 +11577,7 @@ static void check_resize_inode(e2fsck_t
  576. * s_reserved_gdt_blocks must be zero.
  577. */
  578. if (!(fs->super->s_feature_compat &
  579. - EXT2_FEATURE_COMPAT_RESIZE_INODE)) {
  580. + EXT2_FEATURE_COMPAT_RESIZE_INO)) {
  581. if (fs->super->s_reserved_gdt_blocks) {
  582. pctx.num = fs->super->s_reserved_gdt_blocks;
  583. if (fix_problem(ctx, PR_0_NONZERO_RESERVED_GDT_BLOCKS,
  584. @@ -11593,7 +11593,7 @@ static void check_resize_inode(e2fsck_t
  585. retval = ext2fs_read_inode(fs, EXT2_RESIZE_INO, &inode);
  586. if (retval) {
  587. if (fs->super->s_feature_compat &
  588. - EXT2_FEATURE_COMPAT_RESIZE_INODE)
  589. + EXT2_FEATURE_COMPAT_RESIZE_INO)
  590. ctx->flags |= E2F_FLAG_RESIZE_INODE;
  591. return;
  592. }
  593. @@ -11603,7 +11603,7 @@ static void check_resize_inode(e2fsck_t
  594. * the resize inode is cleared; then we're done.
  595. */
  596. if (!(fs->super->s_feature_compat &
  597. - EXT2_FEATURE_COMPAT_RESIZE_INODE)) {
  598. + EXT2_FEATURE_COMPAT_RESIZE_INO)) {
  599. for (i=0; i < EXT2_N_BLOCKS; i++) {
  600. if (inode.i_block[i])
  601. break;
  602. --- a/e2fsprogs/old_e2fsprogs/e2p/feature.c
  603. +++ b/e2fsprogs/old_e2fsprogs/e2p/feature.c
  604. @@ -34,7 +34,7 @@ static const struct feature feature_list
  605. "ext_attr" },
  606. { E2P_FEATURE_COMPAT, EXT2_FEATURE_COMPAT_DIR_INDEX,
  607. "dir_index" },
  608. - { E2P_FEATURE_COMPAT, EXT2_FEATURE_COMPAT_RESIZE_INODE,
  609. + { E2P_FEATURE_COMPAT, EXT2_FEATURE_COMPAT_RESIZE_INO,
  610. "resize_inode" },
  611. { E2P_FEATURE_RO_INCOMPAT, EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER,
  612. "sparse_super" },
  613. --- a/e2fsprogs/old_e2fsprogs/ext2fs/ext2_fs.h
  614. +++ b/e2fsprogs/old_e2fsprogs/ext2fs/ext2_fs.h
  615. @@ -475,7 +475,7 @@ struct ext2_super_block {
  616. #define EXT2_FEATURE_COMPAT_IMAGIC_INODES 0x0002
  617. #define EXT3_FEATURE_COMPAT_HAS_JOURNAL 0x0004
  618. #define EXT2_FEATURE_COMPAT_EXT_ATTR 0x0008
  619. -#define EXT2_FEATURE_COMPAT_RESIZE_INODE 0x0010
  620. +#define EXT2_FEATURE_COMPAT_RESIZE_INO 0x0010
  621. #define EXT2_FEATURE_COMPAT_DIR_INDEX 0x0020
  622. #define EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER 0x0001
  623. --- a/e2fsprogs/old_e2fsprogs/ext2fs/ext2fs.h
  624. +++ b/e2fsprogs/old_e2fsprogs/ext2fs/ext2fs.h
  625. @@ -383,7 +383,7 @@ typedef struct ext2_icount *ext2_icount_
  626. #define EXT2_LIB_FEATURE_COMPAT_SUPP (EXT2_FEATURE_COMPAT_DIR_PREALLOC|\
  627. EXT2_FEATURE_COMPAT_IMAGIC_INODES|\
  628. EXT3_FEATURE_COMPAT_HAS_JOURNAL|\
  629. - EXT2_FEATURE_COMPAT_RESIZE_INODE|\
  630. + EXT2_FEATURE_COMPAT_RESIZE_INO|\
  631. EXT2_FEATURE_COMPAT_DIR_INDEX|\
  632. EXT2_FEATURE_COMPAT_EXT_ATTR)
  633. --- a/e2fsprogs/old_e2fsprogs/ext2fs/initialize.c
  634. +++ b/e2fsprogs/old_e2fsprogs/ext2fs/initialize.c
  635. @@ -284,7 +284,7 @@ retry:
  636. /*
  637. * check the number of reserved group descriptor table blocks
  638. */
  639. - if (super->s_feature_compat & EXT2_FEATURE_COMPAT_RESIZE_INODE)
  640. + if (super->s_feature_compat & EXT2_FEATURE_COMPAT_RESIZE_INO)
  641. rsv_gdt = calc_reserved_gdt_blocks(fs);
  642. else
  643. rsv_gdt = 0;
  644. --- a/e2fsprogs/old_e2fsprogs/mke2fs.c
  645. +++ b/e2fsprogs/old_e2fsprogs/mke2fs.c
  646. @@ -757,7 +757,7 @@ static void parse_extended_opts(struct e
  647. if (rsv_gdb > 0) {
  648. sb_param->s_feature_compat |=
  649. - EXT2_FEATURE_COMPAT_RESIZE_INODE;
  650. + EXT2_FEATURE_COMPAT_RESIZE_INO;
  651. sb_param->s_reserved_gdt_blocks = rsv_gdb;
  652. }
  653. @@ -778,7 +778,7 @@ static void parse_extended_opts(struct e
  654. static __u32 ok_features[3] = {
  655. EXT3_FEATURE_COMPAT_HAS_JOURNAL |
  656. - EXT2_FEATURE_COMPAT_RESIZE_INODE |
  657. + EXT2_FEATURE_COMPAT_RESIZE_INO |
  658. EXT2_FEATURE_COMPAT_DIR_INDEX, /* Compat */
  659. EXT2_FEATURE_INCOMPAT_FILETYPE| /* Incompat */
  660. EXT3_FEATURE_INCOMPAT_JOURNAL_DEV|
  661. @@ -1123,7 +1123,7 @@ static int PRS(int argc, char **argv)
  662. /* Since sparse_super is the default, we would only have a problem
  663. * here if it was explicitly disabled.
  664. */
  665. - if ((param.s_feature_compat & EXT2_FEATURE_COMPAT_RESIZE_INODE) &&
  666. + if ((param.s_feature_compat & EXT2_FEATURE_COMPAT_RESIZE_INO) &&
  667. !(param.s_feature_ro_compat&EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER)) {
  668. bb_error_msg_and_die("reserved online resize blocks not supported "
  669. "on non-sparse filesystem");
  670. @@ -1312,7 +1312,7 @@ int mke2fs_main (int argc, char **argv)
  671. reserve_inodes(fs);
  672. create_bad_block_inode(fs, bb_list);
  673. if (fs->super->s_feature_compat &
  674. - EXT2_FEATURE_COMPAT_RESIZE_INODE) {
  675. + EXT2_FEATURE_COMPAT_RESIZE_INO) {
  676. retval = ext2fs_create_resize_inode(fs);
  677. mke2fs_error_msg_and_die(retval, "reserve blocks for online resize");
  678. }
  679. --- a/e2fsprogs/tune2fs.c
  680. +++ b/e2fsprogs/tune2fs.c
  681. @@ -8,7 +8,7 @@
  682. */
  683. #include "libbb.h"
  684. #include <linux/fs.h>
  685. -#include <linux/ext2_fs.h>
  686. +#include "bb_e2fs_defs.h"
  687. // storage helpers
  688. char BUG_wrong_field_size(void);
  689. --- /dev/null
  690. +++ b/include/bb_e2fs_defs.h
  691. @@ -0,0 +1,602 @@
  692. +/* vi: set sw=4 ts=4: */
  693. +/*
  694. + * linux/include/linux/ext2_fs.h
  695. + *
  696. + * Copyright (C) 1992, 1993, 1994, 1995
  697. + * Remy Card ([email protected])
  698. + * Laboratoire MASI - Institut Blaise Pascal
  699. + * Universite Pierre et Marie Curie (Paris VI)
  700. + *
  701. + * Copyright (C) 1991, 1992 Linus Torvalds
  702. + */
  703. +
  704. +#ifndef LINUX_EXT2_FS_H
  705. +#define LINUX_EXT2_FS_H 1
  706. +
  707. +/*
  708. + * Special inode numbers
  709. + */
  710. +#define EXT2_BAD_INO 1 /* Bad blocks inode */
  711. +#define EXT2_ROOT_INO 2 /* Root inode */
  712. +#define EXT2_ACL_IDX_INO 3 /* ACL inode */
  713. +#define EXT2_ACL_DATA_INO 4 /* ACL inode */
  714. +#define EXT2_BOOT_LOADER_INO 5 /* Boot loader inode */
  715. +#define EXT2_UNDEL_DIR_INO 6 /* Undelete directory inode */
  716. +#define EXT2_RESIZE_INO 7 /* Reserved group descriptors inode */
  717. +#define EXT2_JOURNAL_INO 8 /* Journal inode */
  718. +
  719. +/* First non-reserved inode for old ext2 filesystems */
  720. +#define EXT2_GOOD_OLD_FIRST_INO 11
  721. +
  722. +/*
  723. + * The second extended file system magic number
  724. + */
  725. +#define EXT2_SUPER_MAGIC 0xEF53
  726. +
  727. +/* Assume that user mode programs are passing in an ext2fs superblock, not
  728. + * a kernel struct super_block. This will allow us to call the feature-test
  729. + * macros from user land. */
  730. +#define EXT2_SB(sb) (sb)
  731. +
  732. +/*
  733. + * Maximal count of links to a file
  734. + */
  735. +#define EXT2_LINK_MAX 32000
  736. +
  737. +/*
  738. + * Macro-instructions used to manage several block sizes
  739. + */
  740. +#define EXT2_MIN_BLOCK_LOG_SIZE 10 /* 1024 */
  741. +#define EXT2_MAX_BLOCK_LOG_SIZE 16 /* 65536 */
  742. +#define EXT2_MIN_BLOCK_SIZE (1 << EXT2_MIN_BLOCK_LOG_SIZE)
  743. +#define EXT2_MAX_BLOCK_SIZE (1 << EXT2_MAX_BLOCK_LOG_SIZE)
  744. +#define EXT2_BLOCK_SIZE(s) (EXT2_MIN_BLOCK_SIZE << (s)->s_log_block_size)
  745. +#define EXT2_BLOCK_SIZE_BITS(s) ((s)->s_log_block_size + 10)
  746. +#define EXT2_INODE_SIZE(s) (((s)->s_rev_level == EXT2_GOOD_OLD_REV) ? \
  747. + EXT2_GOOD_OLD_INODE_SIZE : (s)->s_inode_size)
  748. +#define EXT2_FIRST_INO(s) (((s)->s_rev_level == EXT2_GOOD_OLD_REV) ? \
  749. + EXT2_GOOD_OLD_FIRST_INO : (s)->s_first_ino)
  750. +#define EXT2_ADDR_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / sizeof(uint32_t))
  751. +
  752. +/*
  753. + * Macro-instructions used to manage fragments
  754. + */
  755. +#define EXT2_MIN_FRAG_SIZE EXT2_MIN_BLOCK_SIZE
  756. +#define EXT2_MAX_FRAG_SIZE EXT2_MAX_BLOCK_SIZE
  757. +#define EXT2_MIN_FRAG_LOG_SIZE EXT2_MIN_BLOCK_LOG_SIZE
  758. +#define EXT2_FRAG_SIZE(s) (EXT2_MIN_FRAG_SIZE << (s)->s_log_frag_size)
  759. +#define EXT2_FRAGS_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / EXT2_FRAG_SIZE(s))
  760. +
  761. +/*
  762. + * ACL structures
  763. + */
  764. +struct ext2_acl_header { /* Header of Access Control Lists */
  765. + uint32_t aclh_size;
  766. + uint32_t aclh_file_count;
  767. + uint32_t aclh_acle_count;
  768. + uint32_t aclh_first_acle;
  769. +};
  770. +
  771. +struct ext2_acl_entry { /* Access Control List Entry */
  772. + uint32_t acle_size;
  773. + uint16_t acle_perms; /* Access permissions */
  774. + uint16_t acle_type; /* Type of entry */
  775. + uint16_t acle_tag; /* User or group identity */
  776. + uint16_t acle_pad1;
  777. + uint32_t acle_next; /* Pointer on next entry for the */
  778. + /* same inode or on next free entry */
  779. +};
  780. +
  781. +/*
  782. + * Structure of a blocks group descriptor
  783. + */
  784. +struct ext2_group_desc {
  785. + uint32_t bg_block_bitmap; /* Blocks bitmap block */
  786. + uint32_t bg_inode_bitmap; /* Inodes bitmap block */
  787. + uint32_t bg_inode_table; /* Inodes table block */
  788. + uint16_t bg_free_blocks_count; /* Free blocks count */
  789. + uint16_t bg_free_inodes_count; /* Free inodes count */
  790. + uint16_t bg_used_dirs_count; /* Directories count */
  791. + uint16_t bg_pad;
  792. + uint32_t bg_reserved[3];
  793. +};
  794. +
  795. +/*
  796. + * Data structures used by the directory indexing feature
  797. + *
  798. + * Note: all of the multibyte integer fields are little endian.
  799. + */
  800. +
  801. +/*
  802. + * Note: dx_root_info is laid out so that if it should somehow get
  803. + * overlaid by a dirent the two low bits of the hash version will be
  804. + * zero. Therefore, the hash version mod 4 should never be 0.
  805. + * Sincerely, the paranoia department.
  806. + */
  807. +struct ext2_dx_root_info {
  808. + uint32_t reserved_zero;
  809. + uint8_t hash_version; /* 0 now, 1 at release */
  810. + uint8_t info_length; /* 8 */
  811. + uint8_t indirect_levels;
  812. + uint8_t unused_flags;
  813. +};
  814. +
  815. +#define EXT2_HASH_LEGACY 0
  816. +#define EXT2_HASH_HALF_MD4 1
  817. +#define EXT2_HASH_TEA 2
  818. +
  819. +#define EXT2_HASH_FLAG_INCOMPAT 0x1
  820. +
  821. +struct ext2_dx_entry {
  822. + uint32_t hash;
  823. + uint32_t block;
  824. +};
  825. +
  826. +struct ext2_dx_countlimit {
  827. + uint16_t limit;
  828. + uint16_t count;
  829. +};
  830. +
  831. +
  832. +/*
  833. + * Macro-instructions used to manage group descriptors
  834. + */
  835. +#define EXT2_BLOCKS_PER_GROUP(s) (EXT2_SB(s)->s_blocks_per_group)
  836. +#define EXT2_INODES_PER_GROUP(s) (EXT2_SB(s)->s_inodes_per_group)
  837. +#define EXT2_INODES_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s)/EXT2_INODE_SIZE(s))
  838. +/* limits imposed by 16-bit value gd_free_{blocks,inode}_count */
  839. +#define EXT2_MAX_BLOCKS_PER_GROUP(s) ((1 << 16) - 8)
  840. +#define EXT2_MAX_INODES_PER_GROUP(s) ((1 << 16) - EXT2_INODES_PER_BLOCK(s))
  841. +#define EXT2_DESC_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / sizeof (struct ext2_group_desc))
  842. +
  843. +/*
  844. + * Constants relative to the data blocks
  845. + */
  846. +#define EXT2_NDIR_BLOCKS 12
  847. +#define EXT2_IND_BLOCK EXT2_NDIR_BLOCKS
  848. +#define EXT2_DIND_BLOCK (EXT2_IND_BLOCK + 1)
  849. +#define EXT2_TIND_BLOCK (EXT2_DIND_BLOCK + 1)
  850. +#define EXT2_N_BLOCKS (EXT2_TIND_BLOCK + 1)
  851. +
  852. +/*
  853. + * Inode flags
  854. + */
  855. +#define EXT2_SECRM_FL 0x00000001 /* Secure deletion */
  856. +#define EXT2_UNRM_FL 0x00000002 /* Undelete */
  857. +#define EXT2_COMPR_FL 0x00000004 /* Compress file */
  858. +#define EXT2_SYNC_FL 0x00000008 /* Synchronous updates */
  859. +#define EXT2_IMMUTABLE_FL 0x00000010 /* Immutable file */
  860. +#define EXT2_APPEND_FL 0x00000020 /* writes to file may only append */
  861. +#define EXT2_NODUMP_FL 0x00000040 /* do not dump file */
  862. +#define EXT2_NOATIME_FL 0x00000080 /* do not update atime */
  863. +/* Reserved for compression usage... */
  864. +#define EXT2_DIRTY_FL 0x00000100
  865. +#define EXT2_COMPRBLK_FL 0x00000200 /* One or more compressed clusters */
  866. +#define EXT2_NOCOMPR_FL 0x00000400 /* Access raw compressed data */
  867. +#define EXT2_ECOMPR_FL 0x00000800 /* Compression error */
  868. +/* End compression flags --- maybe not all used */
  869. +#define EXT2_BTREE_FL 0x00001000 /* btree format dir */
  870. +#define EXT2_INDEX_FL 0x00001000 /* hash-indexed directory */
  871. +#define EXT2_IMAGIC_FL 0x00002000
  872. +#define EXT3_JOURNAL_DATA_FL 0x00004000 /* file data should be journaled */
  873. +#define EXT2_NOTAIL_FL 0x00008000 /* file tail should not be merged */
  874. +#define EXT2_DIRSYNC_FL 0x00010000 /* Synchronous directory modifications */
  875. +#define EXT2_TOPDIR_FL 0x00020000 /* Top of directory hierarchies*/
  876. +#define EXT3_EXTENTS_FL 0x00080000 /* Inode uses extents */
  877. +#define EXT2_RESERVED_FL 0x80000000 /* reserved for ext2 lib */
  878. +
  879. +#define EXT2_FL_USER_VISIBLE 0x0003DFFF /* User visible flags */
  880. +#define EXT2_FL_USER_MODIFIABLE 0x000080FF /* User modifiable flags */
  881. +
  882. +/*
  883. + * ioctl commands
  884. + */
  885. +#define EXT2_IOC_GETFLAGS _IOR('f', 1, long)
  886. +#define EXT2_IOC_SETFLAGS _IOW('f', 2, long)
  887. +#define EXT2_IOC_GETVERSION _IOR('v', 1, long)
  888. +#define EXT2_IOC_SETVERSION _IOW('v', 2, long)
  889. +
  890. +/*
  891. + * Structure of an inode on the disk
  892. + */
  893. +struct ext2_inode {
  894. + uint16_t i_mode; /* File mode */
  895. + uint16_t i_uid; /* Low 16 bits of Owner Uid */
  896. + uint32_t i_size; /* Size in bytes */
  897. + uint32_t i_atime; /* Access time */
  898. + uint32_t i_ctime; /* Creation time */
  899. + uint32_t i_mtime; /* Modification time */
  900. + uint32_t i_dtime; /* Deletion Time */
  901. + uint16_t i_gid; /* Low 16 bits of Group Id */
  902. + uint16_t i_links_count; /* Links count */
  903. + uint32_t i_blocks; /* Blocks count */
  904. + uint32_t i_flags; /* File flags */
  905. + union {
  906. + struct {
  907. + uint32_t l_i_reserved1;
  908. + } linux1;
  909. + struct {
  910. + uint32_t h_i_translator;
  911. + } hurd1;
  912. + struct {
  913. + uint32_t m_i_reserved1;
  914. + } masix1;
  915. + } osd1; /* OS dependent 1 */
  916. + uint32_t i_block[EXT2_N_BLOCKS];/* Pointers to blocks */
  917. + uint32_t i_generation; /* File version (for NFS) */
  918. + uint32_t i_file_acl; /* File ACL */
  919. + uint32_t i_dir_acl; /* Directory ACL */
  920. + uint32_t i_faddr; /* Fragment address */
  921. + union {
  922. + struct {
  923. + uint8_t l_i_frag; /* Fragment number */
  924. + uint8_t l_i_fsize; /* Fragment size */
  925. + uint16_t i_pad1;
  926. + uint16_t l_i_uid_high; /* these 2 fields */
  927. + uint16_t l_i_gid_high; /* were reserved2[0] */
  928. + uint32_t l_i_reserved2;
  929. + } linux2;
  930. + struct {
  931. + uint8_t h_i_frag; /* Fragment number */
  932. + uint8_t h_i_fsize; /* Fragment size */
  933. + uint16_t h_i_mode_high;
  934. + uint16_t h_i_uid_high;
  935. + uint16_t h_i_gid_high;
  936. + uint32_t h_i_author;
  937. + } hurd2;
  938. + struct {
  939. + uint8_t m_i_frag; /* Fragment number */
  940. + uint8_t m_i_fsize; /* Fragment size */
  941. + uint16_t m_pad1;
  942. + uint32_t m_i_reserved2[2];
  943. + } masix2;
  944. + } osd2; /* OS dependent 2 */
  945. +};
  946. +
  947. +/*
  948. + * Permanent part of an large inode on the disk
  949. + */
  950. +struct ext2_inode_large {
  951. + uint16_t i_mode; /* File mode */
  952. + uint16_t i_uid; /* Low 16 bits of Owner Uid */
  953. + uint32_t i_size; /* Size in bytes */
  954. + uint32_t i_atime; /* Access time */
  955. + uint32_t i_ctime; /* Creation time */
  956. + uint32_t i_mtime; /* Modification time */
  957. + uint32_t i_dtime; /* Deletion Time */
  958. + uint16_t i_gid; /* Low 16 bits of Group Id */
  959. + uint16_t i_links_count; /* Links count */
  960. + uint32_t i_blocks; /* Blocks count */
  961. + uint32_t i_flags; /* File flags */
  962. + union {
  963. + struct {
  964. + uint32_t l_i_reserved1;
  965. + } linux1;
  966. + struct {
  967. + uint32_t h_i_translator;
  968. + } hurd1;
  969. + struct {
  970. + uint32_t m_i_reserved1;
  971. + } masix1;
  972. + } osd1; /* OS dependent 1 */
  973. + uint32_t i_block[EXT2_N_BLOCKS];/* Pointers to blocks */
  974. + uint32_t i_generation; /* File version (for NFS) */
  975. + uint32_t i_file_acl; /* File ACL */
  976. + uint32_t i_dir_acl; /* Directory ACL */
  977. + uint32_t i_faddr; /* Fragment address */
  978. + union {
  979. + struct {
  980. + uint8_t l_i_frag; /* Fragment number */
  981. + uint8_t l_i_fsize; /* Fragment size */
  982. + uint16_t i_pad1;
  983. + uint16_t l_i_uid_high; /* these 2 fields */
  984. + uint16_t l_i_gid_high; /* were reserved2[0] */
  985. + uint32_t l_i_reserved2;
  986. + } linux2;
  987. + struct {
  988. + uint8_t h_i_frag; /* Fragment number */
  989. + uint8_t h_i_fsize; /* Fragment size */
  990. + uint16_t h_i_mode_high;
  991. + uint16_t h_i_uid_high;
  992. + uint16_t h_i_gid_high;
  993. + uint32_t h_i_author;
  994. + } hurd2;
  995. + struct {
  996. + uint8_t m_i_frag; /* Fragment number */
  997. + uint8_t m_i_fsize; /* Fragment size */
  998. + uint16_t m_pad1;
  999. + uint32_t m_i_reserved2[2];
  1000. + } masix2;
  1001. + } osd2; /* OS dependent 2 */
  1002. + uint16_t i_extra_isize;
  1003. + uint16_t i_pad1;
  1004. +};
  1005. +
  1006. +#define i_size_high i_dir_acl
  1007. +
  1008. +/*
  1009. + * File system states
  1010. + */
  1011. +#define EXT2_VALID_FS 0x0001 /* Unmounted cleanly */
  1012. +#define EXT2_ERROR_FS 0x0002 /* Errors detected */
  1013. +
  1014. +/*
  1015. + * Mount flags
  1016. + */
  1017. +#define EXT2_MOUNT_CHECK 0x0001 /* Do mount-time checks */
  1018. +#define EXT2_MOUNT_GRPID 0x0004 /* Create files with directory's group */
  1019. +#define EXT2_MOUNT_DEBUG 0x0008 /* Some debugging messages */
  1020. +#define EXT2_MOUNT_ERRORS_CONT 0x0010 /* Continue on errors */
  1021. +#define EXT2_MOUNT_ERRORS_RO 0x0020 /* Remount fs ro on errors */
  1022. +#define EXT2_MOUNT_ERRORS_PANIC 0x0040 /* Panic on errors */
  1023. +#define EXT2_MOUNT_MINIX_DF 0x0080 /* Mimics the Minix statfs */
  1024. +#define EXT2_MOUNT_NO_UID32 0x0200 /* Disable 32-bit UIDs */
  1025. +
  1026. +#define clear_opt(o, opt) o &= ~EXT2_MOUNT_##opt
  1027. +#define set_opt(o, opt) o |= EXT2_MOUNT_##opt
  1028. +#define test_opt(sb, opt) (EXT2_SB(sb)->s_mount_opt & \
  1029. + EXT2_MOUNT_##opt)
  1030. +/*
  1031. + * Maximal mount counts between two filesystem checks
  1032. + */
  1033. +#define EXT2_DFL_MAX_MNT_COUNT 20 /* Allow 20 mounts */
  1034. +#define EXT2_DFL_CHECKINTERVAL 0 /* Don't use interval check */
  1035. +
  1036. +/*
  1037. + * Behaviour when detecting errors
  1038. + */
  1039. +#define EXT2_ERRORS_CONTINUE 1 /* Continue execution */
  1040. +#define EXT2_ERRORS_RO 2 /* Remount fs read-only */
  1041. +#define EXT2_ERRORS_PANIC 3 /* Panic */
  1042. +#define EXT2_ERRORS_DEFAULT EXT2_ERRORS_CONTINUE
  1043. +
  1044. +/*
  1045. + * Structure of the super block
  1046. + */
  1047. +struct ext2_super_block {
  1048. + uint32_t s_inodes_count; /* Inodes count */
  1049. + uint32_t s_blocks_count; /* Blocks count */
  1050. + uint32_t s_r_blocks_count; /* Reserved blocks count */
  1051. + uint32_t s_free_blocks_count; /* Free blocks count */
  1052. + uint32_t s_free_inodes_count; /* Free inodes count */
  1053. + uint32_t s_first_data_block; /* First Data Block */
  1054. + uint32_t s_log_block_size; /* Block size */
  1055. + int32_t s_log_frag_size; /* Fragment size */
  1056. + uint32_t s_blocks_per_group; /* # Blocks per group */
  1057. + uint32_t s_frags_per_group; /* # Fragments per group */
  1058. + uint32_t s_inodes_per_group; /* # Inodes per group */
  1059. + uint32_t s_mtime; /* Mount time */
  1060. + uint32_t s_wtime; /* Write time */
  1061. + uint16_t s_mnt_count; /* Mount count */
  1062. + int16_t s_max_mnt_count; /* Maximal mount count */
  1063. + uint16_t s_magic; /* Magic signature */
  1064. + uint16_t s_state; /* File system state */
  1065. + uint16_t s_errors; /* Behaviour when detecting errors */
  1066. + uint16_t s_minor_rev_level; /* minor revision level */
  1067. + uint32_t s_lastcheck; /* time of last check */
  1068. + uint32_t s_checkinterval; /* max. time between checks */
  1069. + uint32_t s_creator_os; /* OS */
  1070. + uint32_t s_rev_level; /* Revision level */
  1071. + uint16_t s_def_resuid; /* Default uid for reserved blocks */
  1072. + uint16_t s_def_resgid; /* Default gid for reserved blocks */
  1073. + /*
  1074. + * These fields are for EXT2_DYNAMIC_REV superblocks only.
  1075. + *
  1076. + * Note: the difference between the compatible feature set and
  1077. + * the incompatible feature set is that if there is a bit set
  1078. + * in the incompatible feature set that the kernel doesn't
  1079. + * know about, it should refuse to mount the filesystem.
  1080. + *
  1081. + * e2fsck's requirements are more strict; if it doesn't know
  1082. + * about a feature in either the compatible or incompatible
  1083. + * feature set, it must abort and not try to meddle with
  1084. + * things it doesn't understand...
  1085. + */
  1086. + uint32_t s_first_ino; /* First non-reserved inode */
  1087. + uint16_t s_inode_size; /* size of inode structure */
  1088. + uint16_t s_block_group_nr; /* block group # of this superblock */
  1089. + uint32_t s_feature_compat; /* compatible feature set */
  1090. + uint32_t s_feature_incompat; /* incompatible feature set */
  1091. + uint32_t s_feature_ro_compat; /* readonly-compatible feature set */
  1092. + uint8_t s_uuid[16]; /* 128-bit uuid for volume */
  1093. + char s_volume_name[16]; /* volume name */
  1094. + char s_last_mounted[64]; /* directory where last mounted */
  1095. + uint32_t s_algorithm_usage_bitmap; /* For compression */
  1096. + /*
  1097. + * Performance hints. Directory preallocation should only
  1098. + * happen if the EXT2_FEATURE_COMPAT_DIR_PREALLOC flag is on.
  1099. + */
  1100. + uint8_t s_prealloc_blocks; /* Nr of blocks to try to preallocate*/
  1101. + uint8_t s_prealloc_dir_blocks; /* Nr to preallocate for dirs */
  1102. + uint16_t s_reserved_gdt_blocks; /* Per group table for online growth */
  1103. + /*
  1104. + * Journaling support valid if EXT2_FEATURE_COMPAT_HAS_JOURNAL set.
  1105. + */
  1106. +/*D0*/ uint8_t s_journal_uuid[16]; /* uuid of journal superblock */
  1107. +/*E0*/ uint32_t s_journal_inum; /* inode number of journal file */
  1108. + uint32_t s_journal_dev; /* device number of journal file */
  1109. + uint32_t s_last_orphan; /* start of list of inodes to delete */
  1110. + uint32_t s_hash_seed[4]; /* HTREE hash seed */
  1111. + uint8_t s_def_hash_version; /* Default hash version to use */
  1112. + uint8_t s_jnl_backup_type; /* Default type of journal backup */
  1113. + uint16_t s_reserved_word_pad;
  1114. +/*100*/ uint32_t s_default_mount_opts;
  1115. + uint32_t s_first_meta_bg; /* First metablock group */
  1116. + /* ext3 additions */
  1117. + uint32_t s_mkfs_time; /* When the filesystem was created */
  1118. + uint32_t s_jnl_blocks[17]; /* Backup of the journal inode */
  1119. + /* 64bit support valid if EXT4_FEATURE_COMPAT_64BIT */
  1120. +/*150*/ uint32_t s_blocks_count_hi; /* Blocks count */
  1121. + uint32_t s_r_blocks_count_hi; /* Reserved blocks count */
  1122. + uint32_t s_free_blocks_count_hi; /* Free blocks count */
  1123. + uint16_t s_min_extra_isize; /* All inodes have at least # bytes */
  1124. + uint16_t s_want_extra_isize; /* New inodes should reserve # bytes */
  1125. + uint32_t s_flags; /* Miscellaneous flags */
  1126. + uint16_t s_raid_stride; /* RAID stride */
  1127. + uint16_t s_mmp_interval; /* # seconds to wait in MMP checking */
  1128. + uint64_t s_mmp_block; /* Block for multi-mount protection */
  1129. + uint32_t s_raid_stripe_width; /* blocks on all data disks (N*stride)*/
  1130. + uint8_t s_log_groups_per_flex; /* FLEX_BG group size */
  1131. + uint8_t s_reserved_char_pad2;
  1132. + uint16_t s_reserved_pad;
  1133. + uint32_t s_reserved[162]; /* Padding to the end of the block */
  1134. +};
  1135. +struct BUG_ext2_super_block {
  1136. + char bug[sizeof(struct ext2_super_block) == 1024 ? 1 : -1];
  1137. +};
  1138. +
  1139. +/*
  1140. + * Codes for operating systems
  1141. + */
  1142. +#define EXT2_OS_LINUX 0
  1143. +#define EXT2_OS_HURD 1
  1144. +#define EXT2_OS_MASIX 2
  1145. +#define EXT2_OS_FREEBSD 3
  1146. +#define EXT2_OS_LITES 4
  1147. +
  1148. +/*
  1149. + * Revision levels
  1150. + */
  1151. +#define EXT2_GOOD_OLD_REV 0 /* The good old (original) format */
  1152. +#define EXT2_DYNAMIC_REV 1 /* V2 format w/ dynamic inode sizes */
  1153. +
  1154. +#define EXT2_CURRENT_REV EXT2_GOOD_OLD_REV
  1155. +#define EXT2_MAX_SUPP_REV EXT2_DYNAMIC_REV
  1156. +
  1157. +#define EXT2_GOOD_OLD_INODE_SIZE 128
  1158. +
  1159. +/*
  1160. + * Journal inode backup types
  1161. + */
  1162. +#define EXT3_JNL_BACKUP_BLOCKS 1
  1163. +
  1164. +/*
  1165. + * Feature set definitions
  1166. + */
  1167. +
  1168. +#define EXT2_HAS_COMPAT_FEATURE(sb,mask) \
  1169. + ( EXT2_SB(sb)->s_feature_compat & (mask) )
  1170. +#define EXT2_HAS_RO_COMPAT_FEATURE(sb,mask) \
  1171. + ( EXT2_SB(sb)->s_feature_ro_compat & (mask) )
  1172. +#define EXT2_HAS_INCOMPAT_FEATURE(sb,mask) \
  1173. + ( EXT2_SB(sb)->s_feature_incompat & (mask) )
  1174. +
  1175. +/* for s_feature_compat */
  1176. +#define EXT2_FEATURE_COMPAT_DIR_PREALLOC 0x0001
  1177. +#define EXT2_FEATURE_COMPAT_IMAGIC_INODES 0x0002
  1178. +#define EXT3_FEATURE_COMPAT_HAS_JOURNAL 0x0004
  1179. +#define EXT2_FEATURE_COMPAT_EXT_ATTR 0x0008
  1180. +#define EXT2_FEATURE_COMPAT_RESIZE_INO 0x0010
  1181. +#define EXT2_FEATURE_COMPAT_DIR_INDEX 0x0020
  1182. +
  1183. +/* for s_feature_ro_compat */
  1184. +#define EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER 0x0001
  1185. +#define EXT2_FEATURE_RO_COMPAT_LARGE_FILE 0x0002
  1186. +#define EXT2_FEATURE_RO_COMPAT_BTREE_DIR 0x0004 /* not used */
  1187. +#define EXT4_FEATURE_RO_COMPAT_HUGE_FILE 0x0008
  1188. +#define EXT4_FEATURE_RO_COMPAT_GDT_CSUM 0x0010
  1189. +#define EXT4_FEATURE_RO_COMPAT_DIR_NLINK 0x0020
  1190. +#define EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE 0x0040
  1191. +
  1192. +/* for s_feature_incompat */
  1193. +#define EXT2_FEATURE_INCOMPAT_COMPRESSION 0x0001
  1194. +#define EXT2_FEATURE_INCOMPAT_FILETYPE 0x0002
  1195. +#define EXT3_FEATURE_INCOMPAT_RECOVER 0x0004
  1196. +#define EXT3_FEATURE_INCOMPAT_JOURNAL_DEV 0x0008
  1197. +#define EXT2_FEATURE_INCOMPAT_META_BG 0x0010
  1198. +#define EXT4_FEATURE_INCOMPAT_EXTENTS 0x0040
  1199. +#define EXT4_FEATURE_INCOMPAT_64BIT 0x0080
  1200. +#define EXT4_FEATURE_INCOMPAT_MMP 0x0100
  1201. +#define EXT4_FEATURE_INCOMPAT_FLEX_BG 0x0200
  1202. +
  1203. +
  1204. +#define EXT2_FEATURE_COMPAT_SUPP 0
  1205. +#define EXT2_FEATURE_RO_COMPAT_SUPP (EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER| \
  1206. + EXT2_FEATURE_RO_COMPAT_LARGE_FILE| \
  1207. + EXT2_FEATURE_RO_COMPAT_BTREE_DIR)
  1208. +#define EXT2_FEATURE_INCOMPAT_SUPP (EXT2_FEATURE_INCOMPAT_FILETYPE| \
  1209. + EXT2_FEATURE_INCOMPAT_META_BG)
  1210. +#define EXT2_FEATURE_INCOMPAT_UNSUPPORTED (~EXT2_FEATURE_INCOMPAT_SUPP)
  1211. +#define EXT2_FEATURE_RO_COMPAT_UNSUPPORTED (~EXT2_FEATURE_RO_COMPAT_SUPP)
  1212. +
  1213. +#define EXT3_FEATURE_RO_COMPAT_SUPP (EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER| \
  1214. + EXT2_FEATURE_RO_COMPAT_LARGE_FILE| \
  1215. + EXT2_FEATURE_RO_COMPAT_BTREE_DIR)
  1216. +#define EXT3_FEATURE_INCOMPAT_SUPP (EXT2_FEATURE_INCOMPAT_FILETYPE| \
  1217. + EXT3_FEATURE_INCOMPAT_RECOVER| \
  1218. + EXT2_FEATURE_INCOMPAT_META_BG)
  1219. +#define EXT3_FEATURE_INCOMPAT_UNSUPPORTED (~EXT3_FEATURE_INCOMPAT_SUPP)
  1220. +#define EXT3_FEATURE_RO_COMPAT_UNSUPPORTED (~EXT3_FEATURE_RO_COMPAT_SUPP)
  1221. +
  1222. +
  1223. +/*
  1224. + * Default values for user and/or group using reserved blocks
  1225. + */
  1226. +#define EXT2_DEF_RESUID 0
  1227. +#define EXT2_DEF_RESGID 0
  1228. +
  1229. +/*
  1230. + * Default mount options
  1231. + */
  1232. +#define EXT2_DEFM_DEBUG 0x0001
  1233. +#define EXT2_DEFM_BSDGROUPS 0x0002
  1234. +#define EXT2_DEFM_XATTR_USER 0x0004
  1235. +#define EXT2_DEFM_ACL 0x0008
  1236. +#define EXT2_DEFM_UID16 0x0010
  1237. +#define EXT3_DEFM_JMODE 0x0060
  1238. +#define EXT3_DEFM_JMODE_DATA 0x0020
  1239. +#define EXT3_DEFM_JMODE_ORDERED 0x0040
  1240. +#define EXT3_DEFM_JMODE_WBACK 0x0060
  1241. +
  1242. +/*
  1243. + * Structure of a directory entry
  1244. + */
  1245. +#define EXT2_NAME_LEN 255
  1246. +
  1247. +struct ext2_dir_entry {
  1248. + uint32_t inode; /* Inode number */
  1249. + uint16_t rec_len; /* Directory entry length */
  1250. + uint16_t name_len; /* Name length */
  1251. + char name[EXT2_NAME_LEN]; /* File name */
  1252. +};
  1253. +
  1254. +/*
  1255. + * The new version of the directory entry. Since EXT2 structures are
  1256. + * stored in intel byte order, and the name_len field could never be
  1257. + * bigger than 255 chars, it's safe to reclaim the extra byte for the
  1258. + * file_type field.
  1259. + */
  1260. +struct ext2_dir_entry_2 {
  1261. + uint32_t inode; /* Inode number */
  1262. + uint16_t rec_len; /* Directory entry length */
  1263. + uint8_t name_len; /* Name length */
  1264. + uint8_t file_type;
  1265. + char name[EXT2_NAME_LEN]; /* File name */
  1266. +};
  1267. +
  1268. +/*
  1269. + * Ext2 directory file types. Only the low 3 bits are used. The
  1270. + * other bits are reserved for now.
  1271. + */
  1272. +#define EXT2_FT_UNKNOWN 0
  1273. +#define EXT2_FT_REG_FILE 1
  1274. +#define EXT2_FT_DIR 2
  1275. +#define EXT2_FT_CHRDEV 3
  1276. +#define EXT2_FT_BLKDEV 4
  1277. +#define EXT2_FT_FIFO 5
  1278. +#define EXT2_FT_SOCK 6
  1279. +#define EXT2_FT_SYMLINK 7
  1280. +
  1281. +#define EXT2_FT_MAX 8
  1282. +
  1283. +/*
  1284. + * EXT2_DIR_PAD defines the directory entries boundaries
  1285. + *
  1286. + * NOTE: It must be a multiple of 4
  1287. + */
  1288. +#define EXT2_DIR_PAD 4
  1289. +#define EXT2_DIR_ROUND (EXT2_DIR_PAD - 1)
  1290. +#define EXT2_DIR_REC_LEN(name_len) (((name_len) + 8 + EXT2_DIR_ROUND) & \
  1291. + ~EXT2_DIR_ROUND)
  1292. +
  1293. +#endif
  1294. --- a/testsuite/mount.tests
  1295. +++ b/testsuite/mount.tests
  1296. @@ -36,7 +36,8 @@ testing "mount -o remount,mand" \
  1297. "mount -o loop mount.image1m $testdir "\
  1298. "&& grep -Fc $testdir </proc/mounts "\
  1299. "&& mount -o remount,mand $testdir "\
  1300. -"&& grep -F $testdir </proc/mounts | grep -c '[, ]mand[, ]'" \
  1301. +"&& grep -F $testdir </proc/mounts | grep -c '[, ]mand[, ]'"\
  1302. +"|| grep -F $testdir </proc/mounts" \
  1303. "1\n""1\n" \
  1304. "" ""
  1305. @@ -83,4 +84,28 @@ b
  1306. "" ""
  1307. SKIP=
  1308. +
  1309. +testing "mount RO loop" "\
  1310. +exec 2>&1
  1311. +umount -d mount.dir 2>/dev/null
  1312. +rmdir mount.dir 2>/dev/null
  1313. +mkdir -p mount.dir
  1314. +(
  1315. +cd mount.dir || { echo 'cd error'; exit 1; }
  1316. +mkdir z1 z2 || { echo 'mkdir error'; exit 1; }
  1317. +mount -t tmpfs tmpfs z1 || { echo 'mount tmpfs error'; exit 1; }
  1318. +dd if=/dev/zero of=z1/e2img count=10 bs=1M 2>/dev/null || { echo 'dd error'; exit 1; }
  1319. +mke2fs -F z1/e2img 2>/dev/null >&2 || { echo 'mke2fs error'; exit 1; }
  1320. +mount -r -o loop -t ext2 z1/e2img z2 || { echo 'mount -r -o loop error'; exit 1; }
  1321. +mount -o remount,ro z1 || { echo 'mount -o remount,ro error'; exit 1; }
  1322. +)
  1323. +umount -d mount.dir/z2
  1324. +##losetup -d /dev/loop*
  1325. +umount -d mount.dir/z1
  1326. +rm -rf mount.dir
  1327. +echo DONE
  1328. +" \
  1329. +"DONE\n" "" ""
  1330. +
  1331. +
  1332. exit $FAILCOUNT
  1333. --- a/util-linux/mkfs_ext2.c
  1334. +++ b/util-linux/mkfs_ext2.c
  1335. @@ -48,16 +48,11 @@
  1336. #include "libbb.h"
  1337. #include <linux/fs.h>
  1338. -#include <linux/ext2_fs.h>
  1339. +#include "bb_e2fs_defs.h"
  1340. #define ENABLE_FEATURE_MKFS_EXT2_RESERVED_GDT 0
  1341. #define ENABLE_FEATURE_MKFS_EXT2_DIR_INDEX 1
  1342. -// from e2fsprogs
  1343. -#define s_reserved_gdt_blocks s_padding1
  1344. -#define s_mkfs_time s_reserved[0]
  1345. -#define s_flags s_reserved[22]
  1346. -
  1347. #define EXT2_HASH_HALF_MD4 1
  1348. #define EXT2_FLAGS_SIGNED_HASH 0x0001
  1349. #define EXT2_FLAGS_UNSIGNED_HASH 0x0002
  1350. @@ -482,8 +477,10 @@ int mkfs_ext2_main(int argc UNUSED_PARAM
  1351. STORE_LE(sb->s_magic, EXT2_SUPER_MAGIC);
  1352. STORE_LE(sb->s_inode_size, inodesize);
  1353. // set "Required extra isize" and "Desired extra isize" fields to 28
  1354. - if (inodesize != sizeof(*inode))
  1355. - STORE_LE(sb->s_reserved[21], 0x001C001C);
  1356. + if (inodesize != sizeof(*inode)) {
  1357. + STORE_LE(sb->s_min_extra_isize, 0x001c);
  1358. + STORE_LE(sb->s_want_extra_isize, 0x001c);
  1359. + }
  1360. STORE_LE(sb->s_first_ino, EXT2_GOOD_OLD_FIRST_INO);
  1361. STORE_LE(sb->s_log_block_size, blocksize_log2 - EXT2_MIN_BLOCK_LOG_SIZE);
  1362. STORE_LE(sb->s_log_frag_size, blocksize_log2 - EXT2_MIN_BLOCK_LOG_SIZE);
  1363. --- a/util-linux/volume_id/ext.c
  1364. +++ b/util-linux/volume_id/ext.c
  1365. @@ -19,28 +19,8 @@
  1366. */
  1367. #include "volume_id_internal.h"
  1368. +#include "bb_e2fs_defs.h"
  1369. -struct ext2_super_block {
  1370. - uint32_t inodes_count;
  1371. - uint32_t blocks_count;
  1372. - uint32_t r_blocks_count;
  1373. - uint32_t free_blocks_count;
  1374. - uint32_t free_inodes_count;
  1375. - uint32_t first_data_block;
  1376. - uint32_t log_block_size;
  1377. - uint32_t dummy3[7];
  1378. - uint8_t magic[2];
  1379. - uint16_t state;
  1380. - uint32_t dummy5[8];
  1381. - uint32_t feature_compat;
  1382. - uint32_t feature_incompat;
  1383. - uint32_t feature_ro_compat;
  1384. - uint8_t uuid[16];
  1385. - uint8_t volume_name[16];
  1386. -} PACKED;
  1387. -
  1388. -#define EXT3_FEATURE_COMPAT_HAS_JOURNAL 0x00000004
  1389. -#define EXT3_FEATURE_INCOMPAT_JOURNAL_DEV 0x00000008
  1390. #define EXT_SUPERBLOCK_OFFSET 0x400
  1391. int FAST_FUNC volume_id_probe_ext(struct volume_id *id /*,uint64_t off*/)
  1392. @@ -54,23 +34,27 @@ int FAST_FUNC volume_id_probe_ext(struct
  1393. if (es == NULL)
  1394. return -1;
  1395. - if (es->magic[0] != 0123 || es->magic[1] != 0357) {
  1396. + if (es->s_magic != cpu_to_le16(EXT2_SUPER_MAGIC)) {
  1397. dbg("ext: no magic found");
  1398. return -1;
  1399. }
  1400. // volume_id_set_usage(id, VOLUME_ID_FILESYSTEM);
  1401. // volume_id_set_label_raw(id, es->volume_name, 16);
  1402. - volume_id_set_label_string(id, es->volume_name, 16);
  1403. - volume_id_set_uuid(id, es->uuid, UUID_DCE);
  1404. + volume_id_set_label_string(id, (void*)es->s_volume_name, 16);
  1405. + volume_id_set_uuid(id, es->s_uuid, UUID_DCE);
  1406. dbg("ext: label '%s' uuid '%s'", id->label, id->uuid);
  1407. #if ENABLE_FEATURE_BLKID_TYPE
  1408. - if ((le32_to_cpu(es->feature_compat) & EXT3_FEATURE_COMPAT_HAS_JOURNAL) != 0)
  1409. + if ((es->s_feature_ro_compat & cpu_to_le32(EXT4_FEATURE_RO_COMPAT_HUGE_FILE | EXT4_FEATURE_RO_COMPAT_DIR_NLINK))
  1410. + || (es->s_feature_incompat & cpu_to_le32(EXT4_FEATURE_INCOMPAT_EXTENTS | EXT4_FEATURE_INCOMPAT_64BIT))
  1411. + ) {
  1412. + id->type = "ext4";
  1413. + }
  1414. + else if (es->s_feature_compat & cpu_to_le32(EXT3_FEATURE_COMPAT_HAS_JOURNAL))
  1415. id->type = "ext3";
  1416. else
  1417. id->type = "ext2";
  1418. #endif
  1419. -
  1420. return 0;
  1421. }