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