grub-fs-tester.in 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558
  1. #!@BUILD_SHEBANG@
  2. set -e
  3. fs="$1"
  4. GRUBFSTEST="@builddir@/grub-fstest"
  5. tempdir=`mktemp -d "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1
  6. # This wrapper is to ease insertion of valgrind or time statistics
  7. run_it () {
  8. LC_ALL=C "$GRUBFSTEST" "$@"
  9. }
  10. range() {
  11. range_counter="$1"
  12. while test "$range_counter" -le "$2"; do
  13. echo "$range_counter"
  14. range_counter="$((range_counter + $3))"
  15. done
  16. }
  17. powrange() {
  18. range_counter="$1"
  19. while test "$range_counter" -le "$2"; do
  20. echo "$range_counter"
  21. range_counter="$((range_counter * 2))"
  22. done
  23. }
  24. run_grubfstest () {
  25. need_images=
  26. for i in $(range 0 $((NEED_IMAGES_N-1)) 1); do
  27. need_images="$need_images $FSIMAGEP${i}.img";
  28. done
  29. run_it -c $NEED_IMAGES_N $need_images "$@"
  30. }
  31. # OS LIMITATION: GNU/Linux has no AFS support, so we use a premade image and a reference tar file. I.a. no multiblocksize test
  32. MINLOGSECSIZE=9
  33. MAXLOGSECSIZE=9
  34. case x"$fs" in
  35. xntfs*)
  36. MINLOGSECSIZE=8
  37. MAXLOGSECSIZE=12;;
  38. xvfat*|xmsdos*)
  39. MINLOGSECSIZE=9
  40. # OS LIMITATION: It could go up to 32768 but Linux rejects sector sizes > 4096
  41. MAXLOGSECSIZE=12;;
  42. xext*)
  43. MINLOGSECSIZE=8
  44. MAXLOGSECSIZE=12;;
  45. xbtrfs*)
  46. MINLOGSECSIZE=8
  47. # OS LIMITATION: It could go up to 32768 but Linux rejects sector sizes > 4096
  48. MAXLOGSECSIZE=12;;
  49. xxfs)
  50. MINLOGSECSIZE=9
  51. # OS LIMITATION: GNU/Linux doesn't accept > 4096
  52. MAXLOGSECSIZE=12;;
  53. xxfs_crc)
  54. MINLOGSECSIZE=9
  55. # OS LIMITATION: GNU/Linux doesn't accept > 1024
  56. MAXLOGSECSIZE=10;;
  57. xzfs*)
  58. # OS LIMITATION: zfs-fuse hangs when creating zpool with sectors <=256B.
  59. MINLOGSECSIZE=9
  60. # OS LIMITATION: zfs-fuse fails with >= 32K sectors.
  61. # OS limitation: zfs-fuse always uses ashift=9 with loop devices
  62. MAXLOGSECSIZE=9;;
  63. esac
  64. for LOGSECSIZE in $(range "$MINLOGSECSIZE" "$MAXLOGSECSIZE" 1); do
  65. SECSIZE="$((1 << LOGSECSIZE))"
  66. MINBLKSIZE=512
  67. MAXBLKSIZE=512
  68. BLKSTEP=0
  69. case x"$fs" in
  70. xntfs*)
  71. MINBLKSIZE=$SECSIZE
  72. MAXBLKSIZE=65536
  73. if [ x"$SECSIZE" = x256 ]; then
  74. MINBLKSIZE=512
  75. MAXBLKSIZE=32768
  76. fi
  77. ;;
  78. xvfat* | xmsdos*)
  79. MINBLKSIZE=$SECSIZE
  80. MAXBLKSIZE=$((128*SECSIZE))
  81. ;;
  82. xexfat*)
  83. MINBLKSIZE=$SECSIZE
  84. # It could go further but it requires more and more space
  85. MAXBLKSIZE=8286208
  86. ;;
  87. xhfs)
  88. MINBLKSIZE=512
  89. # OS LIMITATION: should be 1048576 but linux hangs on unmnount with
  90. # >= 524288
  91. MAXBLKSIZE=262144
  92. ;;
  93. xhfsplus | xhfsplus_casesens | xhfsplus_wrap)
  94. MINBLKSIZE=512
  95. MAXBLKSIZE=1048576
  96. ;;
  97. xnilfs2)
  98. # nilfs2 supports blocksizes from 1024 to 4096
  99. # but non-4096 results in kernel oops in some cases,
  100. # avoid it.
  101. MINBLKSIZE=4096
  102. MAXBLKSIZE=4096
  103. ;;
  104. xsfs*)
  105. MINBLKSIZE=512
  106. MAXBLKSIZE=4096
  107. ;;
  108. xaffs | xaffs_intl)
  109. MINBLKSIZE=512
  110. MAXBLKSIZE=4096
  111. ;;
  112. xreiserfs*)
  113. MINBLKSIZE=512
  114. # OS LIMITATION: 8192 isn't supported.
  115. MAXBLKSIZE=4096
  116. ;;
  117. x"mdraid"*)
  118. MINBLKSIZE=4096
  119. # OS LIMITATION: Linux oopses with >=32768K
  120. MAXBLKSIZE=$((16384*1024))
  121. ;;
  122. x"lvm_raid1"* | x"lvm_raid4" | x"lvm_raid5" | x"lvm_raid6")
  123. # OS LIMITATION: Linux crashes with less than 16384
  124. MINBLKSIZE=16384
  125. # Could go further but what's the point?
  126. MAXBLKSIZE=$((65536*1024))
  127. ;;
  128. x"lvm_mirrorall")
  129. MINBLKSIZE=2048
  130. # Could go further but what's the point?
  131. MAXBLKSIZE=$((65536*1024))
  132. ;;
  133. x"lvm_mirror1")
  134. MINBLKSIZE=4096
  135. # Could go further but what's the point?
  136. MAXBLKSIZE=$((65536*1024))
  137. ;;
  138. x"lvm_stripe")
  139. MINBLKSIZE=4096
  140. # Could go further but what's the point?
  141. MAXBLKSIZE=$((65536*1024))
  142. ;;
  143. x"lvm"*)
  144. MINBLKSIZE=1024
  145. # Could go further but what's the point?
  146. MAXBLKSIZE=$((65536*1024))
  147. ;;
  148. xext*)
  149. MINBLKSIZE=1024
  150. if [ $MINBLKSIZE -lt $SECSIZE ]; then
  151. MINBLKSIZE=$SECSIZE
  152. fi
  153. MAXBLKSIZE=4096
  154. ;;
  155. xsquash*)
  156. MINBLKSIZE=4096
  157. MAXBLKSIZE=1048576;;
  158. xxfs)
  159. MINBLKSIZE=$SECSIZE
  160. # OS Limitation: GNU/Linux doesn't accept > 4096
  161. MAXBLKSIZE=4096;;
  162. xxfs_crc)
  163. # OS Limitation: GNU/Linux doesn't accept != 1024
  164. MINBLKSIZE=1024
  165. MAXBLKSIZE=1024;;
  166. xudf)
  167. MINBLKSIZE=1024
  168. MAXBLKSIZE=4096;;
  169. xbfs)
  170. MINBLKSIZE=1024
  171. MAXBLKSIZE=8192;;
  172. xufs*)
  173. MINBLKSIZE=4096
  174. # OS Limitation: Linux rejects 65536 blocks.
  175. MAXBLKSIZE=32768;;
  176. xminix3)
  177. # OS LIMITATION: Linux rejects non-power-of-two blocks.
  178. # OS LIMITATION: Linux rejects > 4096.
  179. MINBLKSIZE=1024
  180. MAXBLKSIZE=4096;;
  181. esac
  182. if test "$BLKSTEP" -eq 0; then
  183. blksizes="$(powrange "$MINBLKSIZE" "$MAXBLKSIZE")"
  184. else
  185. blksizes="$(range "$MINBLKSIZE" "$MAXBLKSIZE" "$BLKSTEP")"
  186. fi
  187. for BLKSIZE in $blksizes; do
  188. MAXDEVICES=1
  189. MINDEVICES=1
  190. export fs
  191. case x"$fs" in
  192. x"zfs_raidz" | x"zfs_stripe" | x"zfs_mirror" | xbtrfs_raid0 \
  193. | xbtrfs_raid1 | x"mdraid"*"_raid4" | x"mdraid"*"_raid5" \
  194. | x"mdraid"*"_linear" \
  195. | x"mdraid"*"_raid10" | xlvm_raid1* | xlvm_mirror1 | xlvm_mirrorall)
  196. MINDEVICES=2
  197. MAXDEVICES=7
  198. ;;
  199. xbtrfs_raid10)
  200. MINDEVICES=4
  201. MAXDEVICES=7
  202. ;;
  203. x"zfs_raidz2"| xlvm_raid5 | xlvm_raid4)
  204. MINDEVICES=3
  205. MAXDEVICES=7;;
  206. x"zfs_raidz3" | x"mdraid"*"_raid6")
  207. MINDEVICES=4
  208. MAXDEVICES=7;;
  209. xlvm_raid6)
  210. MINDEVICES=5
  211. MAXDEVICES=7;;
  212. x"mdraid"*"_raid0" | x"mdraid"*"_raid1" | x"lvm" | xlvm_stripe)
  213. MINDEVICES=1
  214. MAXDEVICES=7;;
  215. esac
  216. for NDEVICES in $(range "$MINDEVICES" "$MAXDEVICES" 1); do
  217. export NDEVICES
  218. unset FSIMAGEP
  219. FSIMAGEP="${tempdir}/${fs}_${SECSIZE}_${BLKSIZE}_${NDEVICES}_"
  220. export FSIMAGEP
  221. unset NEED_IMAGES;
  222. case x$fs in
  223. # RAID 1 has to work with even one device of the set.
  224. xzfs_mirror | x"mdraid"*"_raid1" | xlvm_mirrorall | xlvm_raid1all)
  225. NEED_IMAGES_N=1;;
  226. # Degrade raidz by removing 3 devices
  227. xzfs_raidz3)
  228. NEED_IMAGES_N=$((NDEVICES-3));;
  229. # Degrade raidz by removing 2 devices
  230. xzfs_raidz2 | x"mdraid"*"_raid6" | x"lvm_raid6")
  231. NEED_IMAGES_N=$((NDEVICES-2));;
  232. # Degrade raidz and btrfs RAID1 by removing one device
  233. xbtrfs_raid1 | xbtrfs_raid10 | xzfs_raidz | x"mdraid"*"_raid4" \
  234. | x"mdraid"*"_raid5" | x"mdraid"*"_raid10" | xlvm_mirror1 \
  235. | x"lvm_raid1" | x"lvm_raid4" | x"lvm_raid5")
  236. NEED_IMAGES_N=$((NDEVICES-1));;
  237. *)
  238. NEED_IMAGES_N=$NDEVICES;;
  239. esac
  240. export NEED_IMAGES_N
  241. MNTPOINTRO="${tempdir}/${fs}_ro"
  242. MNTPOINTRW="${tempdir}/${fs}_rw"
  243. MOUNTOPTS=""
  244. MOUNTFS="$fs"
  245. MASTER="${tempdir}/master"
  246. FSLABEL="grub_;/testé莭莽茝😁киритi urewfceniuewruevrewnuuireurevueurnievrewfnerfcnevirivinrewvnirewnivrewiuvcrewvnuewvrrrewniuerwreiuviurewiuviurewnuvewnvrenurnunuvrevuurerejiremvreijnvcreivire nverivnreivrevnureiorfnfrvoeoiroireoireoifrefoieroifoireoifoirefoireoifoijfoirereoireoivoioirevoinvoinreoinvnoieoinreoinveoinveoinreoinvoineoinoinoineoinernoiveoinvreoiioewdioewoirvnoireoivfoirewfewoifoijewoijfoijewfoijfewoijoijoijoijoijoijoijfewceniuewruevrewnuuireurevueurnievrewfnerfcnevirivinrewvnirewnivrewiuvcrewvnuewvrrrewniuerwreiuviurewiuviurewnuvewnvrenurnunuvrevuurerejiremvreijnvcreivire nverivnreivrevnureiorfnfrvoeoiroireoireoifrefoieroifoireoifoirefoireoifoijfoirereoireoivoioirevoinvoinreoinvnoieoinreoinveoinveoinreoinvoineoinoinoineoinernoiveoinvreoiioewdioewoirvnoireoivfoirewfewoifoijewoijfoijewfoijfewoijoijoijoijoijoijoijfewrewfceniuewruevrewnuuireurevueurnievrewfnerfcnevirivinrewvnirewnivrewiuvcrewvnuewvrrrewniuerwreiuviurewiuviurewnuvewnvrenurnunuvrevuurerejiremvreijnvcreivire nverivnreivrevnureiorfnfrvoeoiroireoireoifrefoieroifoireoifoirefoireoifoijfoirereoireoivoioirevoinvoinreoinvnoieoinreoinveoinveoinreoinvoineoinoinoineoinernoiveoinvreoiioewdioewoirvnoireoivfoirewfewoifoijewoijfoijewfoijfewoijoijoijoijoijoijoijfewceniuewruevrewnuuireurevueurnievrewfnerfcnevirivinrewvnirewnivrewiuvcrewvnuewvrrrewniuerwreiuviurewiuviurewnuvewnvrenurnunuvrevuurerejiremvreijnvcreivire nverivnreivrevnureiorfnfrvoeoiroireoireoifrefoieroifoireoifoirefoireoifoijfoirereoireoivoioirevoinvoinreoinvnoieoinreoinveoinveoinreoinvoineoinoinoineoinernoiveoinvreoiioewdioewoirvnoireoivfoirewfewoifoijewoijfoijewfoijfewoijoijoijoijoijoijoijfew"
  247. CFILESRC=
  248. for cand in /usr/share/dict/american-english /usr/share/dict/linux.words /data/data/com.termux/files/usr/share/hunspell/en_US.dic; do
  249. if test -f "$cand" ; then
  250. CFILESRC="$cand"
  251. break
  252. fi
  253. done
  254. if test "$CFILESRC" = "" ; then
  255. echo "Couldn't find compressible file" >&2
  256. exit 1
  257. fi
  258. case x"$fs" in
  259. # FS LIMITATION: 8.3 names
  260. xmsdos*)
  261. CFILE="american.eng";;
  262. xiso9660)
  263. CFILE="american_english";;
  264. *)
  265. CFILE="american-english";;
  266. esac
  267. # OS LIMITATION: Limited by NAME_MAX (usually 255) in GNU/Linux
  268. LONGNAME="qwertzuiopasdfghjklyxcvbnm1234567890qwertzuiopasdfghjklyxcvbnm1234567890oiewqfiewioqoiqoiurqruewqoiuwoieoiiuewqroreqiufieiuwrnureweriuvceoiroiewqoiricdsalkcndsakfirefoiwqeoircorejwoijfreoijojoiewjfwnfcoirenfoirefnreoifenoiwfnoi"
  269. rm -rf "$MASTER"
  270. case x"$fs" in
  271. # FS LIMITATION: HFS+ label is at most 255 UTF-16 chars
  272. # OS LIMITATION: Linux HFS+ tools check UTF-8 length and don't
  273. # handle out-of-BMP characters
  274. x"hfsplus" | x"hfsplus_casesens" | x"hfsplus_wrap")
  275. FSLABEL="grub_;/testé䏌䐓䏕киритi urewfceniuewruevrewnuuireurevueurnievrewfnerfcnevirivinrewvnirewnivrewiuvcrewvnuewvrrrewniuerwreiuviurewiuviurewnuvewnvrenurnunuvrevuurerejiremvreijnvcreivire nverivnreivrevnureiorfnfrvoeoiroireoireoifrefoieroifoireoifoiq"
  276. ;;
  277. # FS LIMITATION: btrfs label is at most 255 UTF-8 chars
  278. x"btrfs"*)
  279. FSLABEL="grub_;/testé莭莽😁киритi urewfceniuewruevrewnuuireurevueurnievrewfnerfcnevirivinrewvnirewnivrewiuvcrewvnuewvrrrewniuerwreiuviurewiuviurewnuvewnvrenurnunuvrevuurerejiremvreijnvcreivire nverivnreivrevnureiorfnfrvoeoiroireoireoifrefoieroifoireoi";;
  280. # FS LIMITATION: exfat is at most 15 UTF-16 chars
  281. x"exfat")
  282. FSLABEL="géт ;/莭莽😁кир";;
  283. # FS LIMITATION: ntfs label is at most ?? UTF-16 chars
  284. x"ntfs"*)
  285. FSLABEL="grub_;/testéтi u莭😁茝кириrewfceniuewruevrewnuuireurevueurnievrewfnerfcnevirivinrewvniwnivrewiuvcrewvnuewvrrrewniureifiuewifjiww";;
  286. # FS LIMITATION: nilfs2 label is at most 80 UTF-8 characters
  287. x"nilfs2")
  288. FSLABEL="grub_;/testéтi u😁莽茝кириrewfceniuewruevrewnuuireurevueurnievrewfne";;
  289. # FS LIMITATION: afs and iso9660 label is at most 32 UTF-8 characters
  290. x"afs" | xiso9660 | xrockridge | xrockridge_joliet\
  291. | xiso9660_1999 | xrockridge_1999 | xrockridge_joliet_1999)
  292. FSLABEL="gr_;/é莭莽😁кирит u";;
  293. # FS LIMITATION: bfs label is at most 32 UTF-8 characters
  294. # OS LIMITATION: bfs label can't contain ; or /
  295. x"bfs")
  296. FSLABEL="grub_é莭莽😁кирит u";;
  297. # FS LIMITATION: Joliet label is at most 16 UTF-16 characters
  298. # OS LIMITATION: xorriso doesn't handle out-of-BMP characters
  299. xjoliet | xjoliet_1999)
  300. FSLABEL="g;/_é䏌䐓䏕䎛䎾䏴кит u"
  301. #FSLABEL="g;/_é莭莽😁кит u"
  302. ;;
  303. # FS LIMITATION: reiserfs, extN and jfs label is at most 16 UTF-8 characters
  304. x"reiserfs_old" | x"reiserfs" | x"ext"* | x"lvm"* | x"mdraid"* | x"jfs" | x"jfs_caseins")
  305. FSLABEL="g;/éт 莭😁";;
  306. # FS LIMITATION: No underscore, space, semicolon, slash or international characters in UFS* in label. Limited to 32 UTF-8 characters
  307. x"ufs1" | x"ufs1_sun" | x"ufs2")
  308. FSLABEL="grubtest""ieurrucnenreeiurueurewf";;
  309. # FS LIMITATION: XFS label is at most 12 UTF-8 characters
  310. x"xfs"|x"xfs_crc")
  311. FSLABEL="géт 😁к";;
  312. # FS LIMITATION: FAT labels limited to 11 characters, no international characters or lowercase
  313. x"vfat"* | xmsdos*)
  314. FSLABEL="GRUBTEST ;_";;
  315. # FS LIMITATION: AFFS is latin1. At most 29 characters
  316. x"affs" | xaffs_intl)
  317. FSLABEL="grub_tt? #*w;/e£@¡¤½¾{[]}<>.,";;
  318. # FS LIMITATION: SFS is latin1. At most 30 characters
  319. x"sfs"*)
  320. FSLABEL="GRUB tt öäüé;/àèç åø¿ª©þð׫»µ¬";;
  321. # FS LIMITATION: HFS is Mac-Roman. At most 27 characters
  322. x"hfs")
  323. FSLABEL="grub_t;/estéàèèéie fiucnree";;
  324. # FS LIMITATION: UDF label is either up to 127 latin1 characters or 63 UTF-16 ones
  325. # OS LIMITATION: Linux UDF tools force ASCII label ...
  326. x"udf")
  327. FSLABEL="grub_;/testurewfceniuewruevrewnuuireurevueurnievr";;
  328. # FS LIMITATION: ZFS doesn't accept non-ASCII in label
  329. # FIXME: since this is used as a path component for mount it's very limited in length
  330. xzfs_* | xzfs)
  331. FSLABEL="grub_testieufiue r";;
  332. esac
  333. case x"$fs" in
  334. xmdraid*)
  335. DISKSIZE=314572800;;
  336. xlvm*)
  337. LVMBLKMUL=$(((5800 * 1048576) / (8 * BLKSIZE * NDEVICES)))
  338. DISKSIZE=$((8*BLKSIZE*LVMBLKMUL));;
  339. # FS LIMITATION: some fs have disk size limit
  340. x"vfat12" | xmsdos12)
  341. DISKSIZE=$((4000*BLKSIZE));;
  342. x"vfat12a" | xmsdos12a)
  343. if [ $BLKSIZE -ge 2048 ]; then
  344. DISKSIZE=$((2500*BLKSIZE))
  345. else
  346. DISKSIZE=$((3000*BLKSIZE))
  347. fi
  348. if [ $DISKSIZE -gt $((60000*SECSIZE)) ]; then
  349. DISKSIZE=$((60000*SECSIZE))
  350. fi;;
  351. x"vfat16" | xmsdos16)
  352. DISKSIZE=$((65000*BLKSIZE));;
  353. x"vfat16a" | xmsdos16a)
  354. DISKSIZE=$((60000*SECSIZE))
  355. ;;
  356. *)
  357. DISKSIZE=10737418240;;
  358. esac
  359. if [ $DISKSIZE -ge $(((5800/NDEVICES)*1048576)) ]; then
  360. DISKSIZE=$(((5800/NDEVICES)*1048576))
  361. fi
  362. case x"$fs" in
  363. xvfat* | xmsdos* | xexfat* | xhfs | xhfsplus | xhfsplus_wrap | xaffs \
  364. | xaffs_intl | xjfs_caseins | xsfs_caseins \
  365. | xzfs_caseins | xiso9660)
  366. CASESENS=n;;
  367. *)
  368. CASESENS=y;;
  369. esac
  370. BIGBLOCKCNT=$((5000 * 1048576))
  371. case x"$fs" in
  372. # FS LIMITATION: small filesystems
  373. x"vfat12" | xmsdos12)
  374. if [ $BLKSIZE -le 4096 ]; then
  375. BIGBLOCKCNT=0
  376. elif [ $BLKSIZE = 8192 ]; then
  377. BIGBLOCKCNT=1500000
  378. else
  379. BIGBLOCKCNT=$((2000*BLKSIZE))
  380. fi
  381. ;;
  382. x"vfat12a" | xmsdos12a)
  383. if [ $BLKSIZE -le 4096 ] || [ $((128*SECSIZE)) = $BLKSIZE ]; then
  384. BIGBLOCKCNT=0
  385. else
  386. BIGBLOCKCNT=700000
  387. fi;;
  388. x"vfat16a" | xmsdos16a)
  389. if [ $((128*SECSIZE)) = $BLKSIZE ]; then
  390. BIGBLOCKCNT=0
  391. else
  392. BIGBLOCKCNT=$((2500*SECSIZE))
  393. fi
  394. ;;
  395. x"vfat16" | xmsdos16)
  396. BIGBLOCKCNT=$((25000 * BLKSIZE))
  397. if [ $BIGBLOCKCNT -gt 4294967295 ]; then
  398. BIGBLOCKCNT=4294967295
  399. fi
  400. ;;
  401. x"minix")
  402. BIGBLOCKCNT=30000000;;
  403. xexfat)
  404. # Big blocks waste really a lot of space.
  405. # Not much is left.
  406. if [ $BLKSIZE = 2097152 ]; then
  407. BIGBLOCKCNT=4500000000
  408. fi
  409. if [ $BLKSIZE = 4194304 ]; then
  410. BIGBLOCKCNT=3500000000
  411. fi
  412. ;;
  413. # FS LIMITATION: romfs image is limited to 4G.
  414. x"romfs")
  415. BIGBLOCKCNT=$((4000 * 1048576));;
  416. # FS LIMITATION: These FS have uint32 as file size field
  417. x"vfat"* | xmsdos* | x"cpio_crc" | x"cpio_newc" | x"cpio_bin" | x"cpio_hpbin" | xsfs*)
  418. BIGBLOCKCNT=4294967295;;
  419. # FS LIMITATION: These FS have int32 as file size field
  420. # FIXME: not so sure about AFFS
  421. # OS LIMITATION: minix2/minix3 could be formatted in a way to permit more.
  422. x"minix3" | x"minix2" | x"hfs"| x"affs" | xaffs_intl | xreiserfs_old | xext2_old)
  423. BIGBLOCKCNT=$((16#7fffffff));;
  424. # FS LIMITATION: redundant storage
  425. # We have only limited space. Mirroring multiplies it very effectively.
  426. xmdraid* | xlvm* | xzfs_mirror | xbtrfs_raid1)
  427. BIGBLOCKCNT=$((100 * 1048576));;
  428. # We already test the FS for big files separately. Save some time here.
  429. x"zfs_raid"* | x"zfs_stripe"* | x"zfs_mirror"* | x"btrfs_raid"*)
  430. BIGBLOCKCNT=$((100 * 1048576));;
  431. # OS LIMITATION: bfs_fuse bugs beyond that
  432. xbfs)
  433. BIGBLOCKCNT=$((800 * 1048576));;
  434. esac
  435. NOSYMLINK=n
  436. case x"$fs" in
  437. # FS LIMITATION: no symlinks on FAT, exFAT, HFS, plain ISO9660 and Joliet
  438. # OS LIMITATION: ntfs-3g creates interix symlinks which aren't real symlinks
  439. x"vfat"* | xmsdos* | x"hfs" | x"exfat" | x"ntfs"* \
  440. | xiso9660 | xjoliet| xiso9660_1999 | xjoliet_1999)
  441. NOSYMLINK=y;;
  442. esac
  443. NOHARDLINK=n
  444. case x"$fs" in
  445. # FS LIMITATION: no hardlinks on BFS, exfat, fat, hfs and SFS
  446. xbfs | xexfat | x"vfat"* | xmsdos* | xhfs | xsfs | xsfs_caseins)
  447. NOHARDLINK=y;;
  448. # GRUB LIMITATION: no hardlink support on newc and hfs+
  449. xcpio_crc | xcpio_newc | xhfsplus*)
  450. NOHARDLINK=y;;
  451. esac
  452. # FS LIMITATION: some filesystems limit file name size
  453. case x"$fs" in
  454. x"cpio_ustar")
  455. LONGNAME="`echo $LONGNAME |head -c 99`";;
  456. x"hfs")
  457. LONGNAME="`echo $LONGNAME |head -c 31`";;
  458. x"minix" | x"minix2" | x"affs" | xaffs_intl | xiso9660)
  459. LONGNAME="`echo $LONGNAME |head -c 30`";;
  460. x"sfs"*)
  461. LONGNAME="`echo $LONGNAME |head -c 105`";;
  462. x"minix3")
  463. LONGNAME="`echo $LONGNAME |head -c 60`";;
  464. x"udf")
  465. LONGNAME="`echo $LONGNAME |head -c 192`";;
  466. # GRUB LIMITATION: GRUB prefers Joliet over ISO9660:1999
  467. xjoliet | xjoliet_1999)
  468. LONGNAME="`echo $LONGNAME |head -c 103`";;
  469. xiso9660_1999)
  470. LONGNAME="`echo $LONGNAME |head -c 207`";;
  471. # FS LIMITATION: 8.3
  472. xmsdos*)
  473. LONGNAME="qwertzui.opa";;
  474. esac
  475. NOFILETIME=n
  476. NOFSTIME=n
  477. case x"$fs" in
  478. # FIXME: Not sure about BtrFS, NTFS, JFS, AFS, UDF and SFS. Check it.
  479. # FS LIMITATION: as far as I know those FS don't store their last modification date.
  480. x"jfs_caseins" | x"jfs" | x"xfs" | x"xfs_crc" | x"btrfs"* | x"reiserfs_old" | x"reiserfs" \
  481. | x"bfs" | x"afs" \
  482. | x"tarfs" | x"cpio_"* | x"minix" | x"minix2" \
  483. | x"minix3" | x"ntfs"* | x"udf" | x"sfs"*)
  484. NOFSTIME=y;;
  485. # OS LIMITATION: Linux doesn't update fstime.
  486. # OS LIMITATION: Linux apparently uses localtime instead of UTC
  487. xhfs)
  488. NOFILETIME=y; NOFSTIME=y;;
  489. # GRUB LIMITATION: FAT and exFAT use localtime. Unusable for GRUB
  490. x"vfat"* | x"msdos"* | x"exfat")
  491. NOFILETIME=y; NOFSTIME=y;;
  492. # FS LIMITATION: romfs has no timestamps.
  493. x"romfs")
  494. NOFILETIME=y; NOFSTIME=y;;
  495. esac
  496. NOFSLABEL=n
  497. case x"$fs" in
  498. # FS LIMITATION: these filesystems have no label.
  499. x"cpio_"* | x"tarfs" | x"squash4_"* | x"minix" | x"minix2" \
  500. | x"minix3" | xreiserfs_old)
  501. NOFSLABEL=y;;
  502. esac
  503. PDIRCOMPNUM=210
  504. PDIR2COMPNUM=210
  505. case x$fs in
  506. # OS LIMITATION: bfs_fuse bugs beyond that
  507. xbfs)
  508. PDIRCOMPNUM=10
  509. PDIR2COMPNUM=10;;
  510. # OS LIMITATION: Linux supports only inline symlinks
  511. xudf)
  512. if [ $BLKSIZE = 1024 ]; then
  513. PDIR2COMPNUM=113
  514. fi ;;
  515. # FS LIMITATION: at most 255 on path length
  516. # FS LIMITATION: at most 100 on symlink length
  517. xcpio_ustar)
  518. PDIRCOMPNUM=84
  519. PDIR2COMPNUM=30;;
  520. # OS LIMITATION: Linux supports only symlink at most one block long on reiserfs
  521. xreiserfs | xreiserfs_old)
  522. if [ $BLKSIZE = 512 ]; then
  523. PDIR2COMPNUM=114
  524. fi ;;
  525. # FS LIMITATION: SFS assumes that symlink
  526. # with header fit in one block.
  527. # FIXME: not sure about it.
  528. xsfs | xsfs_caseins)
  529. if [ $BLKSIZE = 512 ]; then
  530. PDIR2COMPNUM=147
  531. fi ;;
  532. # FS LIMITATION: AFFS assumes that symlink
  533. # with rather larger header fit in one block.
  534. # FIXME: not sure about it.
  535. xaffs | xaffs_intl)
  536. if [ $BLKSIZE = 512 ]; then
  537. PDIR2COMPNUM=97
  538. fi ;;
  539. esac
  540. PDIR=""
  541. # OS LIMITATION: Limited by PATH_MAX (usually 1024)
  542. for i in $(range 0 $((PDIRCOMPNUM-1)) 1); do
  543. PDIR="$PDIR/$i";
  544. if test $((i%3)) = 0; then
  545. PDIR="$PDIR/"
  546. fi
  547. done
  548. PDIR2=""
  549. # OS LIMITATION: Limited by PATH_MAX (usually 1024)
  550. for i in $(range 0 $((PDIR2COMPNUM-1)) 1); do
  551. PDIR2="${PDIR2}/$i";
  552. if test $((i%3)) = 0; then
  553. PDIR2="${PDIR2}/"
  554. fi
  555. done
  556. PFIL="p.img"
  557. unset LODEVICES
  558. GENERATED=n
  559. LODEVICES=
  560. MOUNTDEVICE=
  561. case x"$fs" in
  562. x"tarfs" | x"cpio_"*| x"ziso9660" | x"romfs" | x"squash4_"*\
  563. | x"iso9660" | xjoliet | xrockridge | xrockridge_joliet \
  564. | x"iso9660_1999" | xjoliet_1999 | xrockridge_1999 \
  565. | xrockridge_joliet_1999)
  566. MNTPOINTRW="$MASTER"
  567. MNTPOINTRO="$MASTER"
  568. GENERATED=y
  569. mkdir -p "$MASTER";;
  570. # No mkfs for GNU/Linux. Just unpack preformatted empty image
  571. *)
  572. mkdir -p "$MNTPOINTRW"
  573. mkdir -p "$MNTPOINTRO"
  574. for i in $(range 0 $((NDEVICES-1)) 1); do
  575. dd if=/dev/zero of="$FSIMAGEP${i}.img" count=1 bs=1 seek=$((DISKSIZE-1)) &> /dev/null
  576. LODEVICE="$(losetup -f)"
  577. LODEVICES="$LODEVICES $LODEVICE"
  578. losetup "$LODEVICE" "$FSIMAGEP${i}.img"
  579. if test "$i" = 0; then
  580. MOUNTDEVICE="$LODEVICE"
  581. fi
  582. done ;;
  583. esac
  584. case x"$fs" in
  585. x"afs")
  586. ;;
  587. x"btrfs")
  588. "mkfs.btrfs" -s $SECSIZE -L "$FSLABEL" "${MOUNTDEVICE}" ;;
  589. x"btrfs_zlib" | x"btrfs_lzo")
  590. "mkfs.btrfs" -s $SECSIZE -L "$FSLABEL" "${MOUNTDEVICE}"
  591. MOUNTOPTS="compress=${fs/btrfs_/},"
  592. MOUNTFS="btrfs"
  593. ;;
  594. x"btrfs_raid0")
  595. "mkfs.btrfs" -s $SECSIZE -d raid0 -m raid0 -L "$FSLABEL" $LODEVICES
  596. MOUNTFS="btrfs"
  597. ;;
  598. x"btrfs_raid1")
  599. "mkfs.btrfs" -s $SECSIZE -d raid1 -m raid1 -L "$FSLABEL" $LODEVICES
  600. MOUNTFS="btrfs"
  601. ;;
  602. x"btrfs_raid10")
  603. "mkfs.btrfs" -s $SECSIZE -d raid10 -m raid10 -L "$FSLABEL" $LODEVICES
  604. MOUNTFS="btrfs"
  605. ;;
  606. x"btrfs_single")
  607. "mkfs.btrfs" -s $SECSIZE -d single -L "$FSLABEL" $LODEVICES
  608. MOUNTFS="btrfs"
  609. ;;
  610. x"exfat")
  611. "mkfs.$fs" -s $((BLKSIZE/512)) -n "$FSLABEL" "${MOUNTDEVICE}"
  612. MOUNTOPTS="iocharset=utf8,"
  613. MOUNTFS="exfat-fuse";;
  614. x"minix")
  615. "mkfs.minix" "${MOUNTDEVICE}"
  616. ;;
  617. # mkfs.hfs and mkfs.hfsplus don't fill UUID.
  618. x"hfsplus")
  619. "mkfs.hfsplus" -b $BLKSIZE -v "$FSLABEL" "${MOUNTDEVICE}"
  620. dd if=/dev/urandom of="${MOUNTDEVICE}" bs=1 seek=$((16#468)) conv=notrunc count=8 ;;
  621. x"hfsplus_wrap")
  622. "mkfs.hfsplus" -w -b $BLKSIZE -v "$FSLABEL" "${MOUNTDEVICE}"
  623. dd if=/dev/urandom of="${MOUNTDEVICE}" bs=1 seek=$((16#468)) conv=notrunc count=8
  624. MOUNTFS="hfsplus";;
  625. x"hfsplus_casesens")
  626. "mkfs.hfsplus" -s -b $BLKSIZE -v "$FSLABEL" "${MOUNTDEVICE}"
  627. dd if=/dev/urandom of="${MOUNTDEVICE}" bs=1 seek=$((16#468)) conv=notrunc count=8
  628. MOUNTFS="hfsplus";;
  629. x"hfs")
  630. "mkfs.hfs" -b $BLKSIZE -v "`echo $FSLABEL |recode utf8..macroman`" -h "${MOUNTDEVICE}"
  631. dd if=/dev/urandom of="${MOUNTDEVICE}" bs=1 seek=$((16#474)) conv=notrunc count=8
  632. MOUNTOPTS="iocharset=utf8,codepage=macroman,"
  633. ;;
  634. x"vfat"*|xmsdos*)
  635. BITS="${fs/vfat/}"
  636. BITS="${BITS/msdos/}"
  637. if [ "x${BITS:2:1}" = xa ]; then
  638. A=-A
  639. else
  640. A=
  641. fi
  642. "mkfs.vfat" -a $A -S $SECSIZE -s $((BLKSIZE/SECSIZE)) -F "${BITS:0:2}" -n "$FSLABEL" "${MOUNTDEVICE}"
  643. MOUNTOPTS="iocharset=utf8,codepage=437,"
  644. MOUNTFS="$(echo "$fs"|sed 's,[0-9]*a\?$,,')";;
  645. x"minix2")
  646. "mkfs.minix" -v "${MOUNTDEVICE}"
  647. MOUNTFS="minix";;
  648. x"minix3")
  649. "mkfs.minix" -B $BLKSIZE -3 "${MOUNTDEVICE}"
  650. MOUNTFS="minix";;
  651. x"ntfs"*)
  652. "mkfs.ntfs" -s "$SECSIZE" -c "$BLKSIZE" -L "$FSLABEL" -Q -q "${MOUNTDEVICE}"
  653. MOUNTOPTS="iocharset=utf8,compression,"
  654. MOUNTFS="ntfs-3g";;
  655. x"udf")
  656. "mkudffs" --utf8 -b $BLKSIZE --lvid="$FSLABEL" "${MOUNTDEVICE}"
  657. MOUNTOPTS="iocharset=utf8,bs=$BLKSIZE,";;
  658. x"ufs2")
  659. "mkfs.ufs" -b $BLKSIZE -L "$FSLABEL" -O 2 "${MOUNTDEVICE}"
  660. MOUNTOPTS="ufstype=ufs2,"
  661. MOUNTFS="ufs";;
  662. x"ufs1")
  663. "mkfs.ufs" -b $BLKSIZE -L "$FSLABEL" -O 1 "${MOUNTDEVICE}"
  664. MOUNTOPTS="ufstype=44bsd,"
  665. MOUNTFS="ufs";;
  666. x"ufs1_sun")
  667. "mkfs.ufs" -b $BLKSIZE -L "$FSLABEL" -O 1 "${MOUNTDEVICE}"
  668. MOUNTOPTS="ufstype=sun,"
  669. MOUNTFS="ufs";;
  670. x"zfs")
  671. "zpool" create -R "$MNTPOINTRW" "$FSLABEL" "${MOUNTDEVICE}"
  672. sleep 1
  673. "zfs" create "$FSLABEL"/"grub fs"
  674. sleep 1;;
  675. x"zfs_caseins")
  676. "zpool" create -R "$MNTPOINTRW" "$FSLABEL" "${MOUNTDEVICE}"
  677. sleep 1
  678. "zfs" create -o casesensitivity=insensitive "$FSLABEL"/"grub fs"
  679. sleep 1;;
  680. x"zfs_lzjb" | xzfs_gzip | xzfs_zle)
  681. "zpool" create -O compression=${fs/zfs_/} -R "$MNTPOINTRW" "$FSLABEL" "${MOUNTDEVICE}"
  682. sleep 1
  683. "zfs" create -o compression=${fs/zfs_/} "$FSLABEL"/"grub fs"
  684. sleep 1;;
  685. x"zfs_raidz")
  686. "zpool" create -R "$MNTPOINTRW" "$FSLABEL" raidz1 $LODEVICES
  687. sleep 1
  688. "zfs" create "$FSLABEL"/"grub fs"
  689. sleep 1;;
  690. x"zfs_raidz2")
  691. "zpool" create -R "$MNTPOINTRW" "$FSLABEL" raidz2 $LODEVICES
  692. sleep 1
  693. "zfs" create "$FSLABEL"/"grub fs"
  694. sleep 1;;
  695. x"zfs_raidz3")
  696. "zpool" create -R "$MNTPOINTRW" "$FSLABEL" raidz3 $LODEVICES
  697. sleep 1
  698. "zfs" create "$FSLABEL"/"grub fs"
  699. sleep 1;;
  700. x"zfs_mirror")
  701. "zpool" create -R "$MNTPOINTRW" "$FSLABEL" mirror $LODEVICES
  702. sleep 1
  703. "zfs" create "$FSLABEL"/"grub fs"
  704. sleep 1;;
  705. x"zfs_stripe")
  706. "zpool" create -R "$MNTPOINTRW" "$FSLABEL" $LODEVICES
  707. sleep 1
  708. "zfs" create "$FSLABEL"/"grub fs"
  709. sleep 1;;
  710. x"tarfs" | x"cpio_"* | x"iso9660" | xjoliet | xrockridge | xrockridge_joliet | x"iso9660_1999" | xjoliet_1999 | xrockridge_1999 | xrockridge_joliet_1999 | x"ziso9660" | x"romfs" | x"squash4_"*)
  711. INSTDEVICE=/dev/null;;
  712. x"reiserfs")
  713. "mkfs.reiserfs" --format=3.6 -b $BLKSIZE -l "$FSLABEL" -q "${MOUNTDEVICE}" ;;
  714. x"reiserfs_old")
  715. "mkfs.reiserfs" --format=3.5 -b $BLKSIZE -l "$FSLABEL" -q "${MOUNTDEVICE}"
  716. MOUNTFS=reiserfs;;
  717. x"jfs")
  718. "mkfs.jfs" -L "$FSLABEL" -q "${MOUNTDEVICE}"
  719. MOUNTOPTS="iocharset=utf8,";;
  720. x"jfs_caseins")
  721. "mkfs.jfs" -O -L "$FSLABEL" -q "${MOUNTDEVICE}"
  722. MOUNTFS=jfs
  723. MOUNTOPTS="iocharset=utf8,";;
  724. x"mdraid"*)
  725. mdadm -C --chunk=$((BLKSIZE/1024)) --force -e "${fs:6:1}.${fs:7:1}" "/dev/md/${fs}_${NDEVICES}" --level="${fs:13}" --raid-devices="$NDEVICES" $LODEVICES
  726. MOUNTDEVICE="/dev/md/${fs}_${NDEVICES}"
  727. MOUNTFS=ext2
  728. "mkfs.ext2" -L "$FSLABEL" -q "${MOUNTDEVICE}" ;;
  729. x"lvm"*)
  730. for lodev in $LODEVICES; do
  731. pvcreate "$lodev"
  732. done
  733. vgcreate -s $((BLKSIZE/1024))K grub_test $LODEVICES
  734. if [ x$fs = xlvm ] ; then
  735. lvcreate -l "$((NDEVICES*7*LVMBLKMUL))" -n testvol grub_test
  736. elif [ x$fs = xlvm_stripe ] ; then
  737. lvcreate -l "$((NDEVICES*7*LVMBLKMUL))" -i "$NDEVICES" -n testvol grub_test
  738. elif [ x$fs = xlvm_mirror1 ] || [ x$fs = xlvm_raid1 ] ; then
  739. lvcreate -m 1 -l "$((NDEVICES*2*LVMBLKMUL))" --type "${fs/lvm_/}" -n testvol grub_test
  740. elif [ x$fs = xlvm_mirrorall ] ; then
  741. lvcreate -m "$((NDEVICES-1))" -l "$((6*LVMBLKMUL))" --type mirror -n testvol grub_test
  742. elif [ x$fs = xlvm_raid1all ] ; then
  743. # Until version 2.02.103 LVM counts metadata segments
  744. # twice when checking available space. Reduce segment
  745. # count to work around it.
  746. lvcreate -m "$((NDEVICES-1))" -l "$((6*LVMBLKMUL - 1))" --type raid1 -n testvol grub_test
  747. elif [ x$fs = xlvm_raid4 ] || [ x$fs = xlvm_raid5 ]; then
  748. lvcreate -l "$(((NDEVICES-1) * 5*LVMBLKMUL))" -i "$((NDEVICES-1))" --type "${fs/lvm_/}" -n testvol grub_test
  749. elif [ x$fs = xlvm_raid6 ]; then
  750. lvcreate -l "$(((NDEVICES-2) * 5*LVMBLKMUL))" -i "$((NDEVICES-2))" --type "${fs/lvm_/}" -n testvol grub_test
  751. fi
  752. MOUNTDEVICE="/dev/mapper/grub_test-testvol"
  753. MOUNTFS=ext2
  754. "mkfs.ext2" -L "$FSLABEL" -q "${MOUNTDEVICE}" ;;
  755. xnilfs2)
  756. "mkfs.nilfs2" -L "$FSLABEL" -b $BLKSIZE -q "${MOUNTDEVICE}" ;;
  757. xext2_old)
  758. MKE2FS_DEVICE_SECTSIZE=$SECSIZE "mkfs.ext2" -r 0 -b $BLKSIZE -L "$FSLABEL" -q "${MOUNTDEVICE}"
  759. MOUNTFS=ext2
  760. ;;
  761. xext4_metabg)
  762. MKE2FS_DEVICE_SECTSIZE=$SECSIZE "mkfs.ext4" -O meta_bg,^resize_inode -b $BLKSIZE -L "$FSLABEL" -q "${MOUNTDEVICE}"
  763. MOUNTFS=ext4
  764. ;;
  765. xext*)
  766. MKE2FS_DEVICE_SECTSIZE=$SECSIZE "mkfs.$fs" -b $BLKSIZE -L "$FSLABEL" -q "${MOUNTDEVICE}" ;;
  767. xxfs)
  768. "mkfs.xfs" -m crc=0 -b size=$BLKSIZE -s size=$SECSIZE -L "$FSLABEL" -q "${MOUNTDEVICE}" ;;
  769. xxfs_crc)
  770. MOUNTFS="xfs"
  771. "mkfs.xfs" -m crc=1 -b size=$BLKSIZE -s size=$SECSIZE -L "$FSLABEL" -q "${MOUNTDEVICE}" ;;
  772. *)
  773. echo "Add appropriate mkfs command here"
  774. exit 1
  775. ;;
  776. esac
  777. BASEFILE="1.img"
  778. NASTYFILE=".?*\\!\"#%@\$%&'()+ ,-.:;<=>^{_}[]\`|~."
  779. case x"$fs" in
  780. # FS LIMITATION: AFFS and SFS don't accept :
  781. xsfs*)
  782. NASTYFILE=".?*\\!\"#%@\$%&'()+ ,-.;<=>^{_}[]\`|~.";;
  783. # FS LIMITATION: AFFS is limited in file name length (30)
  784. x"affs" | xaffs_intl)
  785. NASTYFILE=".?*\\!\"#@\$'()+ ,-;<=>^{_}[]\`|~.";;
  786. # FS LIMITATION: hfs, minix and minix2 are limited in file name length (30 or 31)
  787. x"hfs" | x"minix" | x"minix2")
  788. NASTYFILE=".?*\\!\"#@\$&'()+ ,-:;<=>{}[]\`|~.";;
  789. # FS LIMITATION: FAT doesn't accept ?, *, \, ", :, <, >, |
  790. # FS LIMITATION: FAT discards dots at the end.
  791. x"vfat"* | x"exfat")
  792. NASTYFILE=".!#%@\$%&'()+ ,-.;=^{_}[]\`~";;
  793. # FS LIMITATION: 8.3 limitations apply
  794. x"msdos"*)
  795. NASTYFILE="!#%@\$%&.;=^";;
  796. # FS LIMITATION: No ' ', '*', '/', ':', ';', '?', '\\' in joliet
  797. # GRUB LIMITATION: GRUB prefers Joliet over ISO9660:1999
  798. xjoliet | xjoliet_1999)
  799. NASTYFILE=".!\"#%@\$%&'()+,-.<=>^{_}[]\`|~.";;
  800. # FS LIMITATION: iso9660 accepts only [0-9A-Z_]*, 32 characters at most
  801. xiso9660)
  802. NASTYFILE="0123456789_acefghijknopqrvwxyz";;
  803. esac
  804. case x"$fs" in
  805. # FS LIMITATION: HFS, AFFS and SFS use legacy codepage (mac-roman or latin1)
  806. x"sfs"* | x"hfs" | x"affs" | xaffs_intl)
  807. IFILE="éàèüöäëñ"
  808. ISYM="ëñéüöäàè"
  809. ;;
  810. # FS LIMITATION: filename length limitation.
  811. x"minix" | x"minix2")
  812. IFILE="éàèüö😁ñкиΕλκά"
  813. ISYM="Ελκάкиéà😁öäëñ"
  814. ;;
  815. xminix3)
  816. IFILE="éàèüöäëñкирица莭茝Ελλικά😁😜😒"
  817. ISYM="Ελλικά😁😜😒莭茝кирицаéàèüöäëñ";;
  818. # GRUB LIMITATION: HFS+ uses NFD. GRUB doesn't handle NF conversion.
  819. # OS LIMITATION: Linux doesn't handle out-of-BMP characters for UTF-16
  820. x"hfsplus" | x"hfsplus_casesens" | x"hfsplus_wrap")
  821. IFILE="éàèüöäëñкирилица䏌䐓䏕Ελληνικα̍䏌䐓䏕"
  822. ISYM="Ελληνικα̍кирилица䏌䐓䏕éàèüöäëñ䏌䐓䏕"
  823. ;;
  824. # GRUB LIMITATION: On case-insensitive ZFS isn't supported with non-uppercase characters
  825. xzfs_caseins)
  826. IFILE="ÉÀÈÜÖÄËÑКИРИЛИЦА莭莽茝ΕΛΛΗΝΙΚΆ😁😜😒"
  827. ISYM="ΕΛΛΗΝΙΚΆКИРИЛИЦА😁😜😒ÉÀÈÜÖÄËÑ莭莽茝";;
  828. # FS LIMITATION: 8.3 CP437
  829. x"msdos"*)
  830. IFILE="éàèüöäëñ.éàè"
  831. ;;
  832. # FS LIMITATION: iso9660 is ASCII-only.
  833. x"iso9660")
  834. IFILE="abcdefghijkmmnop"
  835. ;;
  836. # OS LIMITATION: Linux doesn't handle out-of-BMP characters for UTF-16
  837. # OS LIMITATION: xorriso doesn't handle out-of-BMP characters
  838. xjoliet | xjoliet_1999 | x"vfat"* | x"jfs"* | x"udf"*)
  839. IFILE="éàèüöäëñкирилица䏌䐓䏕Ελληνικά䏌䐓䏕"
  840. ISYM="Ελληνικάкирилица䏌䐓䏕éàèüöäëñ䏌䐓䏕";;
  841. *)
  842. IFILE="éàèüöäëñкирилица莭莽茝Ελληνικά😁😜😒"
  843. ISYM="Ελληνικάкирилица😁😜😒éàèüöäëñ莭莽茝";;
  844. esac
  845. BIGFILE="big.img"
  846. BASESYM="sym"
  847. BASEHARD="hard"
  848. SSYM="///sdir////ssym"
  849. USYM="///sdir////usym"
  850. LONGSYM="longsym"
  851. PSYM="psym"
  852. OSDIR=""
  853. GRUBDEVICE=loop0
  854. case x"$fs" in
  855. xmdraid*)
  856. GRUBDEVICE="mduuid/`mdadm --detail --export $MOUNTDEVICE | grep MD_UUID=|sed 's,MD_UUID=,,g;s,:,,g'`";;
  857. xlvm*)
  858. GRUBDEVICE="lvm/grub_test-testvol";;
  859. esac
  860. GRUBDIR="($GRUBDEVICE)"
  861. case x"$fs" in
  862. x"zfs"*)
  863. OSDIR="grub fs/"
  864. GRUBDIR="($GRUBDEVICE)/grub fs@";;
  865. x"tarfs" | x"cpio_"* | x"iso9660" | xjoliet | xrockridge | xrockridge_joliet | x"iso9660_1999" | xjoliet_1999 | xrockridge_1999 | xrockridge_joliet_1999 | x"ziso9660" | x"romfs" | x"squash4_"* | xafs)
  866. ;;
  867. *)
  868. if ! mount -t "$MOUNTFS" "${MOUNTDEVICE}" "$MNTPOINTRW" -o ${MOUNTOPTS}${SELINUXOPTS}rw ; then
  869. echo "MOUNT FAILED."
  870. for lodev in $LODEVICES; do
  871. while ! losetup -d "$lodev"; do
  872. sleep 1
  873. done
  874. done
  875. for i in $(range 0 $((NDEVICES-1)) 1); do
  876. rm "$FSIMAGEP${i}.img"
  877. done
  878. exit 1;
  879. fi
  880. ;;
  881. esac
  882. case x"$fs" in
  883. # FS LIMITATION: redundant storage
  884. xmdraid* | xlvm*)
  885. BLOCKCNT=1048576;;
  886. x"zfs_raid"* | x"zfs_stripe"* | x"zfs_mirror"* | x"btrfs_raid"*)
  887. BLOCKCNT=1048576;;
  888. # FS LIMITATION: small filesystems
  889. x"vfat16a" | x"msdos16a")
  890. BLOCKCNT=65536;;
  891. x"vfat12a" | xmsdos12a)
  892. BLOCKCNT=32768;;
  893. xminix)
  894. BLOCKCNT=2621440;;
  895. xvfat16 | xmsdos16)
  896. if [ $BLKSIZE = 512 ] || [ $BLKSIZE = 1024 ]; then
  897. BLOCKCNT=1048576
  898. else
  899. BLOCKCNT=5242880
  900. fi
  901. ;;
  902. xvfat12 | xmsdos12)
  903. BLOCKCNT=$((100*BLKSIZE))
  904. if [ $BLOCKCNT -gt 5242880 ]; then
  905. BLOCKCNT=5242880;
  906. fi
  907. ;;
  908. *)
  909. BLOCKCNT=5242880;;
  910. esac
  911. # Make sure file is not exact multiple of block size. This helps to force
  912. # tail packing in case of squash4.
  913. : $((BLOCKCNT--))
  914. case x"$fs" in
  915. x"ntfscomp")
  916. setfattr -h -v 0x00000800 -n system.ntfs_attrib_be "$MNTPOINTRW/$OSDIR";;
  917. esac
  918. # OS LIMITATION: No AFS support under GNU/Linux
  919. mkdir "$MNTPOINTRW/$OSDIR/sdir"
  920. mkdir -p "$MNTPOINTRW/$OSDIR/$PDIR"
  921. "@builddir@"/garbage-gen $BLOCKCNT > "$MNTPOINTRW/$OSDIR/sdir/2.img"
  922. "@builddir@"/garbage-gen $BLOCKCNT > "$MNTPOINTRW/$OSDIR/$BASEFILE"
  923. "@builddir@"/garbage-gen $BLOCKCNT > "$MNTPOINTRW/$OSDIR/$NASTYFILE"
  924. "@builddir@"/garbage-gen $BLOCKCNT > "$MNTPOINTRW/$OSDIR/$IFILE"
  925. "@builddir@"/garbage-gen $BLOCKCNT > "$MNTPOINTRW/$OSDIR/$LONGNAME"
  926. "@builddir@"/garbage-gen $BLOCKCNT > "$MNTPOINTRW/$OSDIR/$PDIR/$PFIL"
  927. if [ $PDIR != $PDIR2 ]; then
  928. "@builddir@"/garbage-gen $BLOCKCNT > "$MNTPOINTRW/$OSDIR/${PDIR2}/$PFIL"
  929. fi
  930. "@builddir@"/garbage-gen $BLOCKCNT > "$MNTPOINTRW/$OSDIR/CaSe"
  931. if [ x$CASESENS = xy ]; then
  932. "@builddir@"/garbage-gen $BLOCKCNT > "$MNTPOINTRW/$OSDIR/cAsE"
  933. fi
  934. if (test x$fs = xvfat12a || test x$fs = xmsdos12a) && test x$BLKSIZE = x131072; then
  935. # With this config there isn't enough space for full copy.
  936. # Copy as much as we can
  937. cp "${CFILESRC}" "$MNTPOINTRW/$OSDIR/${CFILE}" &> /dev/null;
  938. else
  939. cp "${CFILESRC}" "$MNTPOINTRW/$OSDIR/${CFILE}";
  940. fi
  941. if [ x$NOSYMLINK != xy ]; then
  942. ln -s "$BASEFILE" "$MNTPOINTRW/$OSDIR/$BASESYM"
  943. ln -s "2.img" "$MNTPOINTRW/$OSDIR/$SSYM"
  944. ln -s "../1.img" "$MNTPOINTRW/$OSDIR/$USYM"
  945. ln -s "$LONGNAME" "$MNTPOINTRW/$OSDIR/$LONGSYM"
  946. ln -s "${PDIR2}/$PFIL" "$MNTPOINTRW/$OSDIR/$PSYM"
  947. ln -s "$IFILE" "$MNTPOINTRW/$OSDIR/$ISYM"
  948. fi
  949. if [ x$NOHARDLINK != xy ]; then
  950. ln "$MNTPOINTRW/$OSDIR/$BASEFILE" "$MNTPOINTRW/$OSDIR/$BASEHARD"
  951. fi
  952. case x"$fs" in
  953. x"afs")
  954. ;;
  955. x"zfs"*)
  956. while ! zpool export "$FSLABEL" ; do
  957. sleep 1;
  958. done
  959. sleep 2
  960. ;;
  961. x"tarfs")
  962. (cd "$MASTER"; tar cf "${FSIMAGEP}0.img" .) ;;
  963. x"cpio_"*)
  964. (cd "$MASTER"; find . | cpio -o -H "$(echo ${fs} | sed 's@^cpio_@@')" > "${FSIMAGEP}0.img" ) ;;
  965. x"ziso9660")
  966. FSUUID=$(date -u +%Y-%m-%d-%H-%M-%S-00);
  967. xorriso -compliance rec_mtime -set_filter_r --zisofs -- -zisofs default -as mkisofs -iso-level 3 -graft-points -R -J -joliet-long -V "$FSLABEL" --modification-date=$(echo ${FSUUID} | sed 's/-//g;') -o "${FSIMAGEP}0.img" -- -set_filter_r --zisofs -- -zisofs default -add /="$MASTER" ;;
  968. x"iso9660")
  969. FSUUID=$(date -u +%Y-%m-%d-%H-%M-%S-00);
  970. xorriso --rockridge off -compliance rec_mtime -as mkisofs -iso-level 3 -graft-points -V "$FSLABEL" --modification-date=$(echo ${FSUUID} | sed 's/-//g;') -o "${FSIMAGEP}0.img" /="$MASTER" ;;
  971. x"joliet")
  972. FSUUID=$(date -u +%Y-%m-%d-%H-%M-%S-00);
  973. xorriso --rockridge off -compliance rec_mtime -as mkisofs -iso-level 3 -graft-points -J -joliet-long -V "$FSLABEL" --modification-date=$(echo ${FSUUID} | sed 's/-//g;') -o "${FSIMAGEP}0.img" /="$MASTER" ;;
  974. x"rockridge")
  975. FSUUID=$(date -u +%Y-%m-%d-%H-%M-%S-00);
  976. xorriso --rockridge on -compliance rec_mtime -as mkisofs -iso-level 3 -graft-points -V "$FSLABEL" --modification-date=$(echo ${FSUUID} | sed 's/-//g;') -o "${FSIMAGEP}0.img" /="$MASTER" ;;
  977. x"rockridge_joliet")
  978. FSUUID=$(date -u +%Y-%m-%d-%H-%M-%S-00);
  979. xorriso --rockridge on -compliance rec_mtime -as mkisofs -iso-level 3 -graft-points -J -joliet-long -V "$FSLABEL" --modification-date=$(echo ${FSUUID} | sed 's/-//g;') -o "${FSIMAGEP}0.img" /="$MASTER" ;;
  980. x"iso9660_1999")
  981. FSUUID=$(date -u +%Y-%m-%d-%H-%M-%S-00);
  982. xorriso --rockridge off -compliance rec_mtime -as mkisofs -iso-level 4 -graft-points -V "$FSLABEL" --modification-date=$(echo ${FSUUID} | sed 's/-//g;') -o "${FSIMAGEP}0.img" /="$MASTER" ;;
  983. x"joliet_1999")
  984. FSUUID=$(date -u +%Y-%m-%d-%H-%M-%S-00);
  985. xorriso --rockridge off -compliance rec_mtime -as mkisofs -iso-level 4 -graft-points -J -joliet-long -V "$FSLABEL" --modification-date=$(echo ${FSUUID} | sed 's/-//g;') -o "${FSIMAGEP}0.img" /="$MASTER" ;;
  986. x"rockridge_1999")
  987. FSUUID=$(date -u +%Y-%m-%d-%H-%M-%S-00);
  988. xorriso --rockridge on -compliance rec_mtime -as mkisofs -iso-level 4 -graft-points -V "$FSLABEL" --modification-date=$(echo ${FSUUID} | sed 's/-//g;') -o "${FSIMAGEP}0.img" /="$MASTER" ;;
  989. x"rockridge_joliet_1999")
  990. FSUUID=$(date -u +%Y-%m-%d-%H-%M-%S-00);
  991. xorriso --rockridge on -compliance rec_mtime -as mkisofs -iso-level 4 -graft-points -J -joliet-long -V "$FSLABEL" --modification-date=$(echo ${FSUUID} | sed 's/-//g;') -o "${FSIMAGEP}0.img" /="$MASTER" ;;
  992. x"romfs")
  993. genromfs -V "$FSLABEL" -f "${FSIMAGEP}0.img" -d "$MASTER" ;;
  994. xsquash4_*)
  995. echo mksquashfs "$MASTER" "${FSIMAGEP}0.img" -always-use-fragments -comp "${fs/squash4_/}" -b $BLKSIZE
  996. mksquashfs "$MASTER" "${FSIMAGEP}0.img" -always-use-fragments -comp "${fs/squash4_/}" -b $BLKSIZE ;;
  997. x"bfs")
  998. sleep 1
  999. fusermount -u "$MNTPOINTRW"
  1000. ;;
  1001. xlvm*)
  1002. sleep 1
  1003. for try in $(range 0 20 1); do
  1004. if umount "$MNTPOINTRW" ; then
  1005. break;
  1006. fi
  1007. sleep 1;
  1008. done
  1009. UMOUNT_TIME=$(date -u "+%Y-%m-%d %H:%M:%S")
  1010. sleep 1
  1011. vgchange -a n grub_test
  1012. ;;
  1013. xmdraid*)
  1014. sleep 1
  1015. for try in $(range 0 20 1); do
  1016. if umount "$MNTPOINTRW" ; then
  1017. break;
  1018. fi
  1019. sleep 1;
  1020. done
  1021. UMOUNT_TIME=$(date -u "+%Y-%m-%d %H:%M:%S")
  1022. sleep 1
  1023. mdadm --stop /dev/md/"${fs}_$NDEVICES"
  1024. ;;
  1025. *)
  1026. sleep 1
  1027. for try in $(range 0 20 1); do
  1028. if umount "$MNTPOINTRW" ; then
  1029. break;
  1030. fi
  1031. sleep 1;
  1032. done
  1033. ;;
  1034. esac
  1035. sleep 1
  1036. case x"$fs" in
  1037. x"zfs"*)
  1038. "zpool" import -d /dev -R "$MNTPOINTRO" "$FSLABEL"
  1039. ;;
  1040. x"tarfs")
  1041. ;;
  1042. x"cpio_"*)
  1043. ;;
  1044. x"ziso9660")
  1045. ;;
  1046. xiso9660 | xrockridge | xjoliet | xrockridge_joliet)
  1047. ;;
  1048. xiso9660_1999 | xrockridge_1999 | xjoliet_1999 | xrockridge_joliet_1999)
  1049. ;;
  1050. x"romfs")
  1051. ;;
  1052. xsquash4_*)
  1053. ;;
  1054. xlvm*)
  1055. vgchange -a y grub_test
  1056. sleep 1
  1057. mount -t "$MOUNTFS" "${MOUNTDEVICE}" "$MNTPOINTRO" -o ${MOUNTOPTS}${SELINUXOPTS}ro ;;
  1058. xmdraid*)
  1059. mdadm --assemble /dev/md/"${fs}_$NDEVICES" $LODEVICES
  1060. sleep 1
  1061. mount -t "$MOUNTFS" "${MOUNTDEVICE}" "$MNTPOINTRO" -o ${MOUNTOPTS}${SELINUXOPTS}ro ;;
  1062. *)
  1063. mount -t "$MOUNTFS" "${MOUNTDEVICE}" "$MNTPOINTRO" -o ${MOUNTOPTS}${SELINUXOPTS}ro ;;
  1064. esac
  1065. run_grubfstest ls -- -la
  1066. case x"$fs" in
  1067. x"zfs"*)
  1068. LSROUT=$(run_grubfstest ls -- -la "($GRUBDEVICE)/grub fs@/");;
  1069. *)
  1070. LSROUT=$(run_grubfstest ls -- -la "($GRUBDEVICE)/");;
  1071. esac
  1072. if echo "$LSROUT" | grep -F " $BASEFILE" | grep "$BLOCKCNT" > /dev/null; then
  1073. :
  1074. else
  1075. echo LIST FAIL
  1076. echo "$LSROUT"
  1077. TZ=UTC ls -l "$MNTPOINTRO"
  1078. exit 1
  1079. fi
  1080. if echo "$LSROUT" | grep -F " $NASTYFILE" | grep "$BLOCKCNT"> /dev/null; then
  1081. :
  1082. else
  1083. echo NLIST FAIL
  1084. echo "$LSROUT"
  1085. TZ=UTC ls -lA "$MNTPOINTRO"
  1086. exit 1
  1087. fi
  1088. if echo "$LSROUT" | grep -F " $IFILE" | grep "$BLOCKCNT"> /dev/null; then
  1089. :
  1090. else
  1091. echo ILIST FAIL
  1092. echo "$LSROUT"
  1093. TZ=UTC ls -l "$MNTPOINTRO"
  1094. exit 1
  1095. fi
  1096. if echo "$LSROUT" | grep -F " $LONGNAME" | grep "$BLOCKCNT"> /dev/null; then
  1097. :
  1098. else
  1099. echo LONG LIST FAIL
  1100. echo "$LSROUT"
  1101. TZ=UTC ls -l "$MNTPOINTRO"
  1102. exit 1
  1103. fi
  1104. if [ x$NOFILETIME != xy ]; then
  1105. filtime=$(TZ=UTC ls --time-style=+%Y%m%d%H%M%S -l -d "$MNTPOINTRO/$OSDIR/$BASEFILE"|awk '{print $6; }')
  1106. if echo "$LSROUT" | grep -F "$filtime $BASEFILE" > /dev/null; then
  1107. :
  1108. else
  1109. echo TIME FAIL
  1110. echo "$LSROUT"
  1111. TZ=UTC ls -l "$MNTPOINTRO"
  1112. exit 1
  1113. fi
  1114. filtime=$(TZ=UTC ls --time-style=+%Y%m%d%H%M%S -l -d "$MNTPOINTRO/$OSDIR/$LONGNAME"|awk '{print $6; }')
  1115. if echo "$LSROUT" | grep -F "$filtime $LONGNAME" > /dev/null; then
  1116. :
  1117. else
  1118. echo LONG TIME FAIL
  1119. echo "$LSROUT"
  1120. TZ=UTC ls -l "$MNTPOINTRO"
  1121. exit 1
  1122. fi
  1123. fi
  1124. case x"$fs" in
  1125. x"zfs"*)
  1126. LSROUT=$(run_grubfstest ls -- -la "($GRUBDEVICE)/grub fs@/.");;
  1127. *)
  1128. LSROUT=$(run_grubfstest ls -- -la "($GRUBDEVICE)/.");;
  1129. esac
  1130. if echo "$LSROUT" | grep -F " $BASEFILE" | grep "$BLOCKCNT" > /dev/null; then
  1131. :
  1132. else
  1133. echo DOT IN ROOTDIR FAIL
  1134. echo "$LSROUT"
  1135. TZ=UTC ls -l "$MNTPOINTRO"
  1136. exit 1
  1137. fi
  1138. case x"$fs" in
  1139. x"zfs"*)
  1140. ;;
  1141. *)
  1142. LSROUT=$(run_grubfstest ls -- -la "($GRUBDEVICE)/..");
  1143. if echo "$LSROUT" | grep -F " $BASEFILE" | grep "$BLOCKCNT" > /dev/null; then
  1144. :
  1145. else
  1146. echo DOTDOT IN ROOTDIR FAIL
  1147. echo "$LSROUT"
  1148. TZ=UTC ls -l "$MNTPOINTRO"
  1149. exit 1
  1150. fi
  1151. ;;
  1152. esac
  1153. case x"$fs" in
  1154. x"zfs"*)
  1155. LSROUT=$(run_grubfstest ls -- -l "($GRUBDEVICE)/grub fs@/////sdir");;
  1156. *)
  1157. LSROUT=$(run_grubfstest ls -- -l "($GRUBDEVICE)/////sdir");;
  1158. esac
  1159. if echo "$LSROUT" | grep -F " 2.img" | grep $BLOCKCNT > /dev/null; then
  1160. :
  1161. else
  1162. echo SLIST FAIL
  1163. echo "$LSROUT"
  1164. TZ=UTC ls -l "$MNTPOINTRO/sdir"
  1165. exit 1
  1166. fi
  1167. case x"$fs" in
  1168. x"zfs"*)
  1169. LSROUT=$(run_grubfstest ls -- -l "($GRUBDEVICE)/grub fs@/$PDIR");;
  1170. *)
  1171. LSROUT=$(run_grubfstest ls -- -l "($GRUBDEVICE)/$PDIR");;
  1172. esac
  1173. if echo "$LSROUT" | grep -F " p.img" | grep $BLOCKCNT > /dev/null; then
  1174. :
  1175. else
  1176. echo PLIST FAIL
  1177. echo "$LSROUT"
  1178. TZ=UTC ls -l "$MNTPOINTRO/$PDIR"
  1179. exit 1
  1180. fi
  1181. case x"$fs" in
  1182. x"zfs"*)
  1183. LSROUT=$(run_grubfstest ls -- -l "($GRUBDEVICE)/grub fs@/sdir/.");;
  1184. *)
  1185. LSROUT=$(run_grubfstest ls -- -l "($GRUBDEVICE)/sdir/.");;
  1186. esac
  1187. if echo "$LSROUT" | grep -F " 2.img" | grep $BLOCKCNT > /dev/null; then
  1188. :
  1189. else
  1190. echo DOT IN SUBDIR FAIL
  1191. echo "$LSROUT"
  1192. TZ=UTC ls -l "$MNTPOINTRO/$OSDIR/sdir"
  1193. exit 1
  1194. fi
  1195. case x"$fs" in
  1196. x"zfs"*)
  1197. LSROUT=$(run_grubfstest ls -- -l "($GRUBDEVICE)/grub fs@/sdir/../sdir");;
  1198. *)
  1199. LSROUT=$(run_grubfstest ls -- -l "($GRUBDEVICE)/sdir/../sdir");;
  1200. esac
  1201. if echo "$LSROUT" | grep -F " 2.img" | grep $BLOCKCNT > /dev/null; then
  1202. :
  1203. else
  1204. echo DOTDOT IN SUBDIR FAIL
  1205. echo "$LSROUT"
  1206. TZ=UTC ls -l "$MNTPOINTRO/$OSDIR/ssdir"
  1207. exit 1
  1208. fi
  1209. LSOUT=`run_grubfstest ls -- -l "($GRUBDEVICE)"`
  1210. if [ x"$NOFSLABEL" = xy ]; then
  1211. :
  1212. elif echo "$LSOUT" | grep -F "Label \`$FSLABEL'" > /dev/null; then
  1213. :
  1214. else
  1215. echo LABEL FAIL
  1216. echo "$LSOUT"
  1217. blkid "${MOUNTDEVICE}"
  1218. exit 1
  1219. fi
  1220. # Inconsistencies between GRUB and blkid.
  1221. case x"$fs" in
  1222. x"iso9660" | x"ziso9660" | xrockridge | xjoliet | xrockridge_joliet | x"iso9660_1999" | xrockridge_1999 | xjoliet_1999 | xrockridge_joliet_1999) ;;
  1223. x"zfs"*)
  1224. for lodev in $LODEVICES; do
  1225. FSUUID=$(printf "%016x\n" $(blkid -o export "$lodev" |grep -F UUID=|sed s,UUID=,,g))
  1226. if [ "$FSUUID" != 0000000000000000 ]; then
  1227. break;
  1228. fi
  1229. done;;
  1230. *)
  1231. FSUUID=`blkid -o export "${MOUNTDEVICE}" |grep -F UUID=|sed s,UUID=,,g`
  1232. ;;
  1233. esac
  1234. case x"$fs" in
  1235. x"hfs"*)
  1236. GRUBUUID="`run_grubfstest xnu_uuid "$GRUBDEVICE"`"
  1237. if [ x"$GRUBUUID" = x"$FSUUID" ]; then
  1238. :
  1239. else
  1240. echo UUID FAIL
  1241. echo "$LSOUT"
  1242. echo "$GRUBUUID"
  1243. for lodev in $LODEVICES; do
  1244. blkid "$lodev"
  1245. done
  1246. exit 1
  1247. fi
  1248. ;;
  1249. # FS LIMITATION: romfs, cpio, tar, squash4, minix, AFS, old reiserfs and minix2
  1250. # have no UUID.
  1251. # GRUB LIMITATION: use creation date for squash4, AFFS and SFS?
  1252. # GRUB LIMITATION: use tags serials on UDF?
  1253. # GRUB LIMITATION: use root ctime on cpio, tar, minix*, UDF, reiserfs_old?
  1254. # GRUB LIMITATION: Support Atari UUIDs
  1255. x"romfs" | x"cpio_"* | x"tarfs" | x"squash4_"* | x"minix" \
  1256. | x"minix2" | x"minix3" | x"affs" | xaffs_intl \
  1257. | x"udf" | xvfat12a | xvfat16a | xmsdos12a | xmsdos16a | xafs | xsfs* \
  1258. | xreiserfs_old)
  1259. ;;
  1260. *)
  1261. if [ x"$FSUUID" = x ]; then
  1262. echo "Warning: blkid couldn't retrieve UUID"
  1263. elif echo "$LSOUT" | grep -F 'UUID '"$FSUUID"' ' > /dev/null; then
  1264. :
  1265. else
  1266. echo UUID FAIL
  1267. echo "$FSUUID"
  1268. echo "$LSOUT"
  1269. blkid "${MOUNTDEVICE}"
  1270. exit 1
  1271. fi
  1272. ;;
  1273. esac
  1274. if [ x$NOFSTIME != xy ]; then
  1275. case x$fs in
  1276. xiso9660 | xziso9660 | xrockridge | xjoliet | xrockridge_joliet | xiso9660_1999 | xrockridge_1999 | xjoliet_1999 | xrockridge_joliet_1999)
  1277. FSTIME="$(date -d "$(echo ${FSUUID} | awk -F - '{ print $1"-"$2"-"$3" "$4":"$5":"$6 ;}')" '+%Y-%m-%d %H:%M:%S')";;
  1278. xlvm*|xmdraid*)
  1279. # With some abstractions like mdraid flushing to disk
  1280. # may be delayed for a long time.
  1281. FSTIME="$UMOUNT_TIME";;
  1282. *)
  1283. FSTIME="$(TZ=UTC ls --time-style="+%Y-%m-%d_%H:%M:%S" -l -d "${FSIMAGEP}0.img"|awk '{print $6; }'|sed 's,_, ,g')";;
  1284. esac
  1285. # With some abstractions like mdraid computing of UMOUNT_TIME
  1286. # is not precise. Account for small difference here.
  1287. FSTIMEM1="$(date -d "$FSTIME UTC -1 second" -u "+%Y-%m-%d %H:%M:%S")"
  1288. FSTIMEM2="$(date -d "$FSTIME UTC -2 second" -u "+%Y-%m-%d %H:%M:%S")"
  1289. FSTIMEM3="$(date -d "$FSTIME UTC -3 second" -u "+%Y-%m-%d %H:%M:%S")"
  1290. if echo "$LSOUT" | grep -F 'Last modification time '"$FSTIME" > /dev/null || echo "$LSOUT" | grep -F 'Last modification time '"$FSTIMEM1" > /dev/null || echo "$LSOUT" | grep -F 'Last modification time '"$FSTIMEM2" || echo "$LSOUT" | grep -F 'Last modification time '"$FSTIMEM3" > /dev/null; then
  1291. :
  1292. else
  1293. echo FSTIME FAIL
  1294. echo "$FSTIME"
  1295. echo "$LSOUT"
  1296. exit 1
  1297. fi
  1298. fi
  1299. if [ x$NOHARDLINK != xy ]; then
  1300. if run_grubfstest cmp "$GRUBDIR/$BASEHARD" "$MNTPOINTRO/$OSDIR/$BASEFILE" ; then
  1301. :
  1302. else
  1303. echo HARDLINK FAIL
  1304. exit 1
  1305. fi
  1306. fi
  1307. if [ x$NOSYMLINK != xy ]; then
  1308. if run_grubfstest cmp "$GRUBDIR/$BASESYM" "$MNTPOINTRO/$OSDIR/$BASEFILE" ; then
  1309. :
  1310. else
  1311. echo SYMLINK FAIL
  1312. exit 1
  1313. fi
  1314. if run_grubfstest cmp "$GRUBDIR/$LONGSYM" "$MNTPOINTRO/$OSDIR/$LONGNAME" ; then
  1315. :
  1316. else
  1317. echo LONG SYMLINK FAIL
  1318. exit 1
  1319. fi
  1320. if run_grubfstest cmp "$GRUBDIR/$ISYM" "$MNTPOINTRO/$OSDIR/$IFILE" ; then
  1321. :
  1322. else
  1323. echo INTL SYMLINK FAIL
  1324. exit 1
  1325. fi
  1326. if run_grubfstest cmp "$GRUBDIR/$SSYM" "$MNTPOINTRO/$OSDIR/////sdir/////2.img" ; then
  1327. :
  1328. else
  1329. echo SDIR SYMLINK FAIL
  1330. exit 1
  1331. fi
  1332. if run_grubfstest cmp "$GRUBDIR/$USYM" "$MNTPOINTRO/$OSDIR/1.img" ; then
  1333. :
  1334. else
  1335. echo SDIR SYMLINK FAIL
  1336. exit 1
  1337. fi
  1338. if run_grubfstest cmp "$GRUBDIR/$PSYM" "$MNTPOINTRO/$OSDIR/${PDIR2}/$PFIL" ; then
  1339. :
  1340. else
  1341. echo PATH LONG SYMLINK FAIL
  1342. exit 1
  1343. fi
  1344. fi
  1345. if run_grubfstest cmp "$GRUBDIR/$BASEFILE" "$MNTPOINTRO/$OSDIR/$BASEFILE" ; then
  1346. :
  1347. else
  1348. echo READ FAIL
  1349. exit 1
  1350. fi
  1351. if run_grubfstest cmp "$GRUBDIR/$NASTYFILE" "$MNTPOINTRO/$OSDIR/$NASTYFILE" ; then
  1352. :
  1353. else
  1354. echo NREAD FAIL
  1355. exit 1
  1356. fi
  1357. # Reference archive contains original name
  1358. if run_grubfstest cmp "$GRUBDIR/$LONGNAME" "$MNTPOINTRO/$OSDIR/$LONGNAME" ; then
  1359. :
  1360. else
  1361. echo LONG NAME READ FAIL
  1362. exit 1
  1363. fi
  1364. if run_grubfstest cmp "$GRUBDIR/////sdir/////2.img" "$MNTPOINTRO/$OSDIR/sdir/2.img" ; then
  1365. :
  1366. else
  1367. echo LONG NAME READ FAIL
  1368. exit 1
  1369. fi
  1370. if run_grubfstest cmp "$GRUBDIR/$IFILE" "$MNTPOINTRO/$OSDIR/$IFILE" ; then
  1371. :
  1372. else
  1373. echo IREAD FAIL
  1374. exit 1
  1375. fi
  1376. if run_grubfstest cmp "$GRUBDIR/$PDIR/$PFIL" "$MNTPOINTRO/$OSDIR/$PDIR/$PFIL" ; then
  1377. :
  1378. else
  1379. echo PREAD FAIL
  1380. echo cmp "$GRUBDIR/$PDIR/$PFIL" "$MNTPOINTRO/$OSDIR/$PDIR/$PFIL"
  1381. exit 1
  1382. fi
  1383. ok=true
  1384. if ! run_grubfstest cmp "$GRUBDIR/${CFILE}" "$MNTPOINTRO/$OSDIR/${CFILE}" ; then
  1385. ok=false;
  1386. fi
  1387. if test x$ok = xtrue; then
  1388. :
  1389. else
  1390. echo CREAD FAIL
  1391. exit 1
  1392. fi
  1393. if [ x$CASESENS = xy ]; then
  1394. if run_grubfstest cmp "$GRUBDIR/CaSe" "$MNTPOINTRO/$OSDIR/CaSe" ; then
  1395. :
  1396. else
  1397. echo CASE1 READ FAIL
  1398. exit 1
  1399. fi
  1400. if run_grubfstest cmp "$GRUBDIR/cAsE" "$MNTPOINTRO/$OSDIR/cAsE" ; then
  1401. :
  1402. else
  1403. exit 1
  1404. fi
  1405. if cmp "$MNTPOINTRO/$OSDIR/cAsE" "$MNTPOINTRO/$OSDIR/CaSe" > /dev/null ; then
  1406. exit 1
  1407. fi
  1408. if test x$ok = xtrue; then
  1409. :
  1410. else
  1411. echo CASE READ FAIL
  1412. exit 1
  1413. fi
  1414. else
  1415. # OS LIMITATION: Linux make FAT (partially) case-sensitive...
  1416. # ISO9660 is generated and master doesn't change
  1417. case x$fs in
  1418. xiso9660 | xvfat*)
  1419. CASEX=CaSe;;
  1420. *)
  1421. CASEX=cAsE;;
  1422. esac
  1423. if run_grubfstest cmp "$GRUBDIR/CaSe" "$MNTPOINTRO/$OSDIR/${CASEX}" ; then
  1424. :
  1425. else
  1426. echo CASE1 READ FAIL
  1427. exit 1
  1428. fi
  1429. if run_grubfstest cmp "$GRUBDIR/cAsE" "$MNTPOINTRO/$OSDIR/CaSe" ; then
  1430. :
  1431. else
  1432. echo CASE2 READ FAIL
  1433. exit 1
  1434. fi
  1435. if ! cmp "$MNTPOINTRO/$OSDIR/CaSe" "$MNTPOINTRO/$OSDIR/${CASEX}" > /dev/null ; then
  1436. echo CASE CMP READ FAIL
  1437. exit 1
  1438. fi
  1439. if test x$ok = xtrue; then
  1440. :
  1441. else
  1442. echo CASE READ FAIL
  1443. exit 1
  1444. fi
  1445. fi
  1446. case x"$fs" in
  1447. x"zfs"*)
  1448. while ! zpool export "$FSLABEL" ; do
  1449. sleep 1;
  1450. done
  1451. sleep 5;;
  1452. x"tarfs" | x"cpio_"* | xrockridge | xjoliet | xrockridge_joliet | x"ziso9660" | x"romfs" | x"squash4_"* | xiso9660 | xiso9660_1999 | xrockridge_1999 | xjoliet_1999 | xrockridge_joliet_1999)
  1453. rm -rf "$MNTPOINTRW";;
  1454. x"afs")
  1455. rm -rf "$MNTPOINTRO"
  1456. ;;
  1457. *)
  1458. sleep 1
  1459. umount "$MNTPOINTRO" || true
  1460. umount "$MNTPOINTRW" || true
  1461. esac
  1462. sleep 1
  1463. case x"$fs" in
  1464. xmdraid*)
  1465. mdadm --stop /dev/md/"${fs}_$NDEVICES"
  1466. sleep 1
  1467. ;;
  1468. xlvm*)
  1469. vgchange -a n grub_test
  1470. sleep 1
  1471. ;;
  1472. esac
  1473. case x"$fs" in
  1474. x"tarfs" | x"cpio_"* | x"iso9660" | xrockridge | xjoliet | xrockridge_joliet | x"ziso9660" | x"romfs" | x"squash4_"* | x"iso9660_1999" | xrockridge_1999 | xjoliet_1999 | xrockridge_joliet_1999) ;;
  1475. *)
  1476. for lodev in $LODEVICES; do
  1477. while ! losetup -d "$lodev"; do
  1478. sleep 1
  1479. done
  1480. done;;
  1481. esac
  1482. for i in $(range 0 $((NDEVICES-1)) 1); do
  1483. rm "$FSIMAGEP${i}.img"
  1484. done
  1485. if [ x"$fs" = x"zfs" ]; then
  1486. rmdir "$MNTPOINTRW"/"grub fs" || true
  1487. rmdir "$MNTPOINTRO"/"grub fs" || true
  1488. fi
  1489. rm -rf "$MNTPOINTRW" || true
  1490. rm -rf "$MNTPOINTRO" || true
  1491. done
  1492. done
  1493. done
  1494. rmdir "${tempdir}"