2008-02-04 Bean <bean123ch@gmail.com>

* Makefile.in (enable_grub_fstest): New variable.

	* conf/common.rmk (grub_fstest_init.lst): New rule.
	(grub_fstest_init.h): Likewise.
	(grub_fstest_init.c): Likewise.
	(util/grub-fstest.c_DEPENDENCIES): New variable.
	(grub_fstest_SOURCES): Likewise.

	* configure.ac (enable_grub_fstest): Check for --enable-grub-fstest.

	* util/grub-fstest.c: New file.
This commit is contained in:
bean 2008-02-04 08:45:07 +00:00
parent bf567c5067
commit 99fadbaafd
7 changed files with 790 additions and 1 deletions

View file

@ -1,3 +1,17 @@
2008-02-04 Bean <bean123ch@gmail.com>
* Makefile.in (enable_grub_fstest): New variable.
* conf/common.rmk (grub_fstest_init.lst): New rule.
(grub_fstest_init.h): Likewise.
(grub_fstest_init.c): Likewise.
(util/grub-fstest.c_DEPENDENCIES): New variable.
(grub_fstest_SOURCES): Likewise.
* configure.ac (enable_grub_fstest): Check for --enable-grub-fstest.
* util/grub-fstest.c: New file.
2008-02-03 Yoshinori K. Okuji <okuji@enbug.org>
Make grub-setup handle a separate root device.

View file

@ -79,6 +79,7 @@ UNIFONT_HEX = @UNIFONT_HEX@
# Options.
enable_grub_emu = @enable_grub_emu@
enable_grub_fstest = @enable_grub_fstest@
### General variables.

View file

@ -207,6 +207,19 @@ grub_setup_init.c: grub_setup_init.lst $(filter-out grub_setup_init.c,$(grub_set
rm -f $@; sh $(srcdir)/geninit.sh $< $(filter %.c,$^) > $@
DISTCLEANFILES += grub_setup_init.c
# For grub-fstest.
grub_fstest_init.lst: geninit.sh $(filter-out grub_fstest_init.c,$(grub_fstest_SOURCES))
rm -f $@; grep GRUB_MOD_INIT $(filter %.c,$^) /dev/null > $@
DISTCLEANFILES += grub_fstest_init.lst
grub_fstest_init.h: grub_fstest_init.lst $(filter-out grub_fstest_init.c,$(grub_fstest_SOURCES)) geninitheader.sh
rm -f $@; sh $(srcdir)/geninitheader.sh $< > $@
DISTCLEANFILES += grub_fstest_init.h
grub_fstest_init.c: grub_fstest_init.lst $(filter-out grub_fstest_init.c,$(grub_fstest_SOURCES)) geninit.sh grub_fstest_init.h
rm -f $@; sh $(srcdir)/geninit.sh $< $(filter %.c,$^) > $@
DISTCLEANFILES += grub_fstest_init.c
# For update-grub
update-grub: util/update-grub.in config.status
./config.status --file=$@:$<
@ -2513,3 +2526,193 @@ fs-read_mod-commands_read.lst: commands/read.c $(commands/read.c_DEPENDENCIES) g
read_mod_CFLAGS = $(COMMON_CFLAGS)
read_mod_LDFLAGS = $(COMMON_LDFLAGS)
ifeq ($(enable_grub_fstest), yes)
bin_UTILITIES += grub-fstest
endif
# For grub-fstest.
util/grub-fstest.c_DEPENDENCIES = grub_fstest_init.h
grub_fstest_SOURCES = util/grub-fstest.c util/hostfs.c util/misc.c \
kern/file.c kern/device.c kern/disk.c kern/err.c kern/misc.c \
disk/host.c disk/loopback.c normal/arg.c normal/misc.c \
io/gzio.c commands/hexdump.c commands/blocklist.c commands/ls.c \
\
fs/affs.c fs/cpio.c fs/ext2.c fs/fat.c fs/hfs.c \
fs/hfsplus.c fs/iso9660.c fs/jfs.c fs/minix.c \
fs/ntfs.c fs/ntfscomp.c fs/reiserfs.c fs/sfs.c \
fs/ufs.c fs/xfs.c \
\
kern/partition.c partmap/pc.c partmap/apple.c partmap/gpt.c \
kern/fs.c kern/env.c fs/fshelp.c disk/lvm.c disk/raid.c \
grub_fstest_init.c
CLEANFILES += grub-fstest grub_fstest-util_grub_fstest.o grub_fstest-util_hostfs.o grub_fstest-util_misc.o grub_fstest-kern_file.o grub_fstest-kern_device.o grub_fstest-kern_disk.o grub_fstest-kern_err.o grub_fstest-kern_misc.o grub_fstest-disk_host.o grub_fstest-disk_loopback.o grub_fstest-normal_arg.o grub_fstest-normal_misc.o grub_fstest-io_gzio.o grub_fstest-commands_hexdump.o grub_fstest-commands_blocklist.o grub_fstest-commands_ls.o grub_fstest-fs_affs.o grub_fstest-fs_cpio.o grub_fstest-fs_ext2.o grub_fstest-fs_fat.o grub_fstest-fs_hfs.o grub_fstest-fs_hfsplus.o grub_fstest-fs_iso9660.o grub_fstest-fs_jfs.o grub_fstest-fs_minix.o grub_fstest-fs_ntfs.o grub_fstest-fs_ntfscomp.o grub_fstest-fs_reiserfs.o grub_fstest-fs_sfs.o grub_fstest-fs_ufs.o grub_fstest-fs_xfs.o grub_fstest-kern_partition.o grub_fstest-partmap_pc.o grub_fstest-partmap_apple.o grub_fstest-partmap_gpt.o grub_fstest-kern_fs.o grub_fstest-kern_env.o grub_fstest-fs_fshelp.o grub_fstest-disk_lvm.o grub_fstest-disk_raid.o grub_fstest-grub_fstest_init.o
MOSTLYCLEANFILES += grub_fstest-util_grub_fstest.d grub_fstest-util_hostfs.d grub_fstest-util_misc.d grub_fstest-kern_file.d grub_fstest-kern_device.d grub_fstest-kern_disk.d grub_fstest-kern_err.d grub_fstest-kern_misc.d grub_fstest-disk_host.d grub_fstest-disk_loopback.d grub_fstest-normal_arg.d grub_fstest-normal_misc.d grub_fstest-io_gzio.d grub_fstest-commands_hexdump.d grub_fstest-commands_blocklist.d grub_fstest-commands_ls.d grub_fstest-fs_affs.d grub_fstest-fs_cpio.d grub_fstest-fs_ext2.d grub_fstest-fs_fat.d grub_fstest-fs_hfs.d grub_fstest-fs_hfsplus.d grub_fstest-fs_iso9660.d grub_fstest-fs_jfs.d grub_fstest-fs_minix.d grub_fstest-fs_ntfs.d grub_fstest-fs_ntfscomp.d grub_fstest-fs_reiserfs.d grub_fstest-fs_sfs.d grub_fstest-fs_ufs.d grub_fstest-fs_xfs.d grub_fstest-kern_partition.d grub_fstest-partmap_pc.d grub_fstest-partmap_apple.d grub_fstest-partmap_gpt.d grub_fstest-kern_fs.d grub_fstest-kern_env.d grub_fstest-fs_fshelp.d grub_fstest-disk_lvm.d grub_fstest-disk_raid.d grub_fstest-grub_fstest_init.d
grub-fstest: $(grub_fstest_DEPENDENCIES) grub_fstest-util_grub_fstest.o grub_fstest-util_hostfs.o grub_fstest-util_misc.o grub_fstest-kern_file.o grub_fstest-kern_device.o grub_fstest-kern_disk.o grub_fstest-kern_err.o grub_fstest-kern_misc.o grub_fstest-disk_host.o grub_fstest-disk_loopback.o grub_fstest-normal_arg.o grub_fstest-normal_misc.o grub_fstest-io_gzio.o grub_fstest-commands_hexdump.o grub_fstest-commands_blocklist.o grub_fstest-commands_ls.o grub_fstest-fs_affs.o grub_fstest-fs_cpio.o grub_fstest-fs_ext2.o grub_fstest-fs_fat.o grub_fstest-fs_hfs.o grub_fstest-fs_hfsplus.o grub_fstest-fs_iso9660.o grub_fstest-fs_jfs.o grub_fstest-fs_minix.o grub_fstest-fs_ntfs.o grub_fstest-fs_ntfscomp.o grub_fstest-fs_reiserfs.o grub_fstest-fs_sfs.o grub_fstest-fs_ufs.o grub_fstest-fs_xfs.o grub_fstest-kern_partition.o grub_fstest-partmap_pc.o grub_fstest-partmap_apple.o grub_fstest-partmap_gpt.o grub_fstest-kern_fs.o grub_fstest-kern_env.o grub_fstest-fs_fshelp.o grub_fstest-disk_lvm.o grub_fstest-disk_raid.o grub_fstest-grub_fstest_init.o
$(CC) -o $@ grub_fstest-util_grub_fstest.o grub_fstest-util_hostfs.o grub_fstest-util_misc.o grub_fstest-kern_file.o grub_fstest-kern_device.o grub_fstest-kern_disk.o grub_fstest-kern_err.o grub_fstest-kern_misc.o grub_fstest-disk_host.o grub_fstest-disk_loopback.o grub_fstest-normal_arg.o grub_fstest-normal_misc.o grub_fstest-io_gzio.o grub_fstest-commands_hexdump.o grub_fstest-commands_blocklist.o grub_fstest-commands_ls.o grub_fstest-fs_affs.o grub_fstest-fs_cpio.o grub_fstest-fs_ext2.o grub_fstest-fs_fat.o grub_fstest-fs_hfs.o grub_fstest-fs_hfsplus.o grub_fstest-fs_iso9660.o grub_fstest-fs_jfs.o grub_fstest-fs_minix.o grub_fstest-fs_ntfs.o grub_fstest-fs_ntfscomp.o grub_fstest-fs_reiserfs.o grub_fstest-fs_sfs.o grub_fstest-fs_ufs.o grub_fstest-fs_xfs.o grub_fstest-kern_partition.o grub_fstest-partmap_pc.o grub_fstest-partmap_apple.o grub_fstest-partmap_gpt.o grub_fstest-kern_fs.o grub_fstest-kern_env.o grub_fstest-fs_fshelp.o grub_fstest-disk_lvm.o grub_fstest-disk_raid.o grub_fstest-grub_fstest_init.o $(LDFLAGS) $(grub_fstest_LDFLAGS)
grub_fstest-util_grub_fstest.o: util/grub-fstest.c $(util/grub-fstest.c_DEPENDENCIES)
$(CC) -Iutil -I$(srcdir)/util $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 $(grub_fstest_CFLAGS) -MD -c -o $@ $<
-include grub_fstest-util_grub_fstest.d
grub_fstest-util_hostfs.o: util/hostfs.c $(util/hostfs.c_DEPENDENCIES)
$(CC) -Iutil -I$(srcdir)/util $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 $(grub_fstest_CFLAGS) -MD -c -o $@ $<
-include grub_fstest-util_hostfs.d
grub_fstest-util_misc.o: util/misc.c $(util/misc.c_DEPENDENCIES)
$(CC) -Iutil -I$(srcdir)/util $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 $(grub_fstest_CFLAGS) -MD -c -o $@ $<
-include grub_fstest-util_misc.d
grub_fstest-kern_file.o: kern/file.c $(kern/file.c_DEPENDENCIES)
$(CC) -Ikern -I$(srcdir)/kern $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 $(grub_fstest_CFLAGS) -MD -c -o $@ $<
-include grub_fstest-kern_file.d
grub_fstest-kern_device.o: kern/device.c $(kern/device.c_DEPENDENCIES)
$(CC) -Ikern -I$(srcdir)/kern $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 $(grub_fstest_CFLAGS) -MD -c -o $@ $<
-include grub_fstest-kern_device.d
grub_fstest-kern_disk.o: kern/disk.c $(kern/disk.c_DEPENDENCIES)
$(CC) -Ikern -I$(srcdir)/kern $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 $(grub_fstest_CFLAGS) -MD -c -o $@ $<
-include grub_fstest-kern_disk.d
grub_fstest-kern_err.o: kern/err.c $(kern/err.c_DEPENDENCIES)
$(CC) -Ikern -I$(srcdir)/kern $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 $(grub_fstest_CFLAGS) -MD -c -o $@ $<
-include grub_fstest-kern_err.d
grub_fstest-kern_misc.o: kern/misc.c $(kern/misc.c_DEPENDENCIES)
$(CC) -Ikern -I$(srcdir)/kern $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 $(grub_fstest_CFLAGS) -MD -c -o $@ $<
-include grub_fstest-kern_misc.d
grub_fstest-disk_host.o: disk/host.c $(disk/host.c_DEPENDENCIES)
$(CC) -Idisk -I$(srcdir)/disk $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 $(grub_fstest_CFLAGS) -MD -c -o $@ $<
-include grub_fstest-disk_host.d
grub_fstest-disk_loopback.o: disk/loopback.c $(disk/loopback.c_DEPENDENCIES)
$(CC) -Idisk -I$(srcdir)/disk $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 $(grub_fstest_CFLAGS) -MD -c -o $@ $<
-include grub_fstest-disk_loopback.d
grub_fstest-normal_arg.o: normal/arg.c $(normal/arg.c_DEPENDENCIES)
$(CC) -Inormal -I$(srcdir)/normal $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 $(grub_fstest_CFLAGS) -MD -c -o $@ $<
-include grub_fstest-normal_arg.d
grub_fstest-normal_misc.o: normal/misc.c $(normal/misc.c_DEPENDENCIES)
$(CC) -Inormal -I$(srcdir)/normal $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 $(grub_fstest_CFLAGS) -MD -c -o $@ $<
-include grub_fstest-normal_misc.d
grub_fstest-io_gzio.o: io/gzio.c $(io/gzio.c_DEPENDENCIES)
$(CC) -Iio -I$(srcdir)/io $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 $(grub_fstest_CFLAGS) -MD -c -o $@ $<
-include grub_fstest-io_gzio.d
grub_fstest-commands_hexdump.o: commands/hexdump.c $(commands/hexdump.c_DEPENDENCIES)
$(CC) -Icommands -I$(srcdir)/commands $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 $(grub_fstest_CFLAGS) -MD -c -o $@ $<
-include grub_fstest-commands_hexdump.d
grub_fstest-commands_blocklist.o: commands/blocklist.c $(commands/blocklist.c_DEPENDENCIES)
$(CC) -Icommands -I$(srcdir)/commands $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 $(grub_fstest_CFLAGS) -MD -c -o $@ $<
-include grub_fstest-commands_blocklist.d
grub_fstest-commands_ls.o: commands/ls.c $(commands/ls.c_DEPENDENCIES)
$(CC) -Icommands -I$(srcdir)/commands $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 $(grub_fstest_CFLAGS) -MD -c -o $@ $<
-include grub_fstest-commands_ls.d
grub_fstest-fs_affs.o: fs/affs.c $(fs/affs.c_DEPENDENCIES)
$(CC) -Ifs -I$(srcdir)/fs $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 $(grub_fstest_CFLAGS) -MD -c -o $@ $<
-include grub_fstest-fs_affs.d
grub_fstest-fs_cpio.o: fs/cpio.c $(fs/cpio.c_DEPENDENCIES)
$(CC) -Ifs -I$(srcdir)/fs $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 $(grub_fstest_CFLAGS) -MD -c -o $@ $<
-include grub_fstest-fs_cpio.d
grub_fstest-fs_ext2.o: fs/ext2.c $(fs/ext2.c_DEPENDENCIES)
$(CC) -Ifs -I$(srcdir)/fs $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 $(grub_fstest_CFLAGS) -MD -c -o $@ $<
-include grub_fstest-fs_ext2.d
grub_fstest-fs_fat.o: fs/fat.c $(fs/fat.c_DEPENDENCIES)
$(CC) -Ifs -I$(srcdir)/fs $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 $(grub_fstest_CFLAGS) -MD -c -o $@ $<
-include grub_fstest-fs_fat.d
grub_fstest-fs_hfs.o: fs/hfs.c $(fs/hfs.c_DEPENDENCIES)
$(CC) -Ifs -I$(srcdir)/fs $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 $(grub_fstest_CFLAGS) -MD -c -o $@ $<
-include grub_fstest-fs_hfs.d
grub_fstest-fs_hfsplus.o: fs/hfsplus.c $(fs/hfsplus.c_DEPENDENCIES)
$(CC) -Ifs -I$(srcdir)/fs $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 $(grub_fstest_CFLAGS) -MD -c -o $@ $<
-include grub_fstest-fs_hfsplus.d
grub_fstest-fs_iso9660.o: fs/iso9660.c $(fs/iso9660.c_DEPENDENCIES)
$(CC) -Ifs -I$(srcdir)/fs $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 $(grub_fstest_CFLAGS) -MD -c -o $@ $<
-include grub_fstest-fs_iso9660.d
grub_fstest-fs_jfs.o: fs/jfs.c $(fs/jfs.c_DEPENDENCIES)
$(CC) -Ifs -I$(srcdir)/fs $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 $(grub_fstest_CFLAGS) -MD -c -o $@ $<
-include grub_fstest-fs_jfs.d
grub_fstest-fs_minix.o: fs/minix.c $(fs/minix.c_DEPENDENCIES)
$(CC) -Ifs -I$(srcdir)/fs $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 $(grub_fstest_CFLAGS) -MD -c -o $@ $<
-include grub_fstest-fs_minix.d
grub_fstest-fs_ntfs.o: fs/ntfs.c $(fs/ntfs.c_DEPENDENCIES)
$(CC) -Ifs -I$(srcdir)/fs $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 $(grub_fstest_CFLAGS) -MD -c -o $@ $<
-include grub_fstest-fs_ntfs.d
grub_fstest-fs_ntfscomp.o: fs/ntfscomp.c $(fs/ntfscomp.c_DEPENDENCIES)
$(CC) -Ifs -I$(srcdir)/fs $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 $(grub_fstest_CFLAGS) -MD -c -o $@ $<
-include grub_fstest-fs_ntfscomp.d
grub_fstest-fs_reiserfs.o: fs/reiserfs.c $(fs/reiserfs.c_DEPENDENCIES)
$(CC) -Ifs -I$(srcdir)/fs $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 $(grub_fstest_CFLAGS) -MD -c -o $@ $<
-include grub_fstest-fs_reiserfs.d
grub_fstest-fs_sfs.o: fs/sfs.c $(fs/sfs.c_DEPENDENCIES)
$(CC) -Ifs -I$(srcdir)/fs $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 $(grub_fstest_CFLAGS) -MD -c -o $@ $<
-include grub_fstest-fs_sfs.d
grub_fstest-fs_ufs.o: fs/ufs.c $(fs/ufs.c_DEPENDENCIES)
$(CC) -Ifs -I$(srcdir)/fs $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 $(grub_fstest_CFLAGS) -MD -c -o $@ $<
-include grub_fstest-fs_ufs.d
grub_fstest-fs_xfs.o: fs/xfs.c $(fs/xfs.c_DEPENDENCIES)
$(CC) -Ifs -I$(srcdir)/fs $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 $(grub_fstest_CFLAGS) -MD -c -o $@ $<
-include grub_fstest-fs_xfs.d
grub_fstest-kern_partition.o: kern/partition.c $(kern/partition.c_DEPENDENCIES)
$(CC) -Ikern -I$(srcdir)/kern $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 $(grub_fstest_CFLAGS) -MD -c -o $@ $<
-include grub_fstest-kern_partition.d
grub_fstest-partmap_pc.o: partmap/pc.c $(partmap/pc.c_DEPENDENCIES)
$(CC) -Ipartmap -I$(srcdir)/partmap $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 $(grub_fstest_CFLAGS) -MD -c -o $@ $<
-include grub_fstest-partmap_pc.d
grub_fstest-partmap_apple.o: partmap/apple.c $(partmap/apple.c_DEPENDENCIES)
$(CC) -Ipartmap -I$(srcdir)/partmap $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 $(grub_fstest_CFLAGS) -MD -c -o $@ $<
-include grub_fstest-partmap_apple.d
grub_fstest-partmap_gpt.o: partmap/gpt.c $(partmap/gpt.c_DEPENDENCIES)
$(CC) -Ipartmap -I$(srcdir)/partmap $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 $(grub_fstest_CFLAGS) -MD -c -o $@ $<
-include grub_fstest-partmap_gpt.d
grub_fstest-kern_fs.o: kern/fs.c $(kern/fs.c_DEPENDENCIES)
$(CC) -Ikern -I$(srcdir)/kern $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 $(grub_fstest_CFLAGS) -MD -c -o $@ $<
-include grub_fstest-kern_fs.d
grub_fstest-kern_env.o: kern/env.c $(kern/env.c_DEPENDENCIES)
$(CC) -Ikern -I$(srcdir)/kern $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 $(grub_fstest_CFLAGS) -MD -c -o $@ $<
-include grub_fstest-kern_env.d
grub_fstest-fs_fshelp.o: fs/fshelp.c $(fs/fshelp.c_DEPENDENCIES)
$(CC) -Ifs -I$(srcdir)/fs $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 $(grub_fstest_CFLAGS) -MD -c -o $@ $<
-include grub_fstest-fs_fshelp.d
grub_fstest-disk_lvm.o: disk/lvm.c $(disk/lvm.c_DEPENDENCIES)
$(CC) -Idisk -I$(srcdir)/disk $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 $(grub_fstest_CFLAGS) -MD -c -o $@ $<
-include grub_fstest-disk_lvm.d
grub_fstest-disk_raid.o: disk/raid.c $(disk/raid.c_DEPENDENCIES)
$(CC) -Idisk -I$(srcdir)/disk $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 $(grub_fstest_CFLAGS) -MD -c -o $@ $<
-include grub_fstest-disk_raid.d
grub_fstest-grub_fstest_init.o: grub_fstest_init.c $(grub_fstest_init.c_DEPENDENCIES)
$(CC) -I. -I$(srcdir)/. $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 $(grub_fstest_CFLAGS) -MD -c -o $@ $<
-include grub_fstest-grub_fstest_init.d

View file

@ -61,6 +61,19 @@ grub_setup_init.c: grub_setup_init.lst $(filter-out grub_setup_init.c,$(grub_set
rm -f $@; sh $(srcdir)/geninit.sh $< $(filter %.c,$^) > $@
DISTCLEANFILES += grub_setup_init.c
# For grub-fstest.
grub_fstest_init.lst: geninit.sh $(filter-out grub_fstest_init.c,$(grub_fstest_SOURCES))
rm -f $@; grep GRUB_MOD_INIT $(filter %.c,$^) /dev/null > $@
DISTCLEANFILES += grub_fstest_init.lst
grub_fstest_init.h: grub_fstest_init.lst $(filter-out grub_fstest_init.c,$(grub_fstest_SOURCES)) geninitheader.sh
rm -f $@; sh $(srcdir)/geninitheader.sh $< > $@
DISTCLEANFILES += grub_fstest_init.h
grub_fstest_init.c: grub_fstest_init.lst $(filter-out grub_fstest_init.c,$(grub_fstest_SOURCES)) geninit.sh grub_fstest_init.h
rm -f $@; sh $(srcdir)/geninit.sh $< $(filter %.c,$^) > $@
DISTCLEANFILES += grub_fstest_init.c
# For update-grub
update-grub: util/update-grub.in config.status
./config.status --file=$@:$<
@ -331,3 +344,23 @@ gzio_mod_LDFLAGS = $(COMMON_LDFLAGS)
read_mod_SOURCES = commands/read.c
read_mod_CFLAGS = $(COMMON_CFLAGS)
read_mod_LDFLAGS = $(COMMON_LDFLAGS)
ifeq ($(enable_grub_fstest), yes)
bin_UTILITIES += grub-fstest
endif
# For grub-fstest.
util/grub-fstest.c_DEPENDENCIES = grub_fstest_init.h
grub_fstest_SOURCES = util/grub-fstest.c util/hostfs.c util/misc.c \
kern/file.c kern/device.c kern/disk.c kern/err.c kern/misc.c \
disk/host.c disk/loopback.c normal/arg.c normal/misc.c \
io/gzio.c commands/hexdump.c commands/blocklist.c commands/ls.c \
\
fs/affs.c fs/cpio.c fs/ext2.c fs/fat.c fs/hfs.c \
fs/hfsplus.c fs/iso9660.c fs/jfs.c fs/minix.c \
fs/ntfs.c fs/ntfscomp.c fs/reiserfs.c fs/sfs.c \
fs/ufs.c fs/xfs.c \
\
kern/partition.c partmap/pc.c partmap/apple.c partmap/gpt.c \
kern/fs.c kern/env.c fs/fshelp.c disk/lvm.c disk/raid.c \
grub_fstest_init.c

12
configure vendored
View file

@ -311,7 +311,7 @@ ac_includes_default="\
# include <unistd.h>
#endif"
ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS build build_cpu build_vendor build_os host host_cpu host_vendor host_os target target_cpu target_vendor target_os platform CMP YACC UNIFONT_HEX INSTALL_PROGRAM INSTALL_SCRIPT INSTALL_DATA AWK SET_MAKE RUBY CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT CPP EGREP LIBLZO TARGET_CC ac_ct_TARGET_CC OBJCOPY ac_ct_OBJCOPY STRIP ac_ct_STRIP NM ac_ct_NM TARGET_CFLAGS TARGET_CPPFLAGS TARGET_LDFLAGS LIBCURSES enable_grub_emu LIBOBJS LTLIBOBJS'
ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS build build_cpu build_vendor build_os host host_cpu host_vendor host_os target target_cpu target_vendor target_os platform CMP YACC UNIFONT_HEX INSTALL_PROGRAM INSTALL_SCRIPT INSTALL_DATA AWK SET_MAKE RUBY CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT CPP EGREP LIBLZO TARGET_CC ac_ct_TARGET_CC OBJCOPY ac_ct_OBJCOPY STRIP ac_ct_STRIP NM ac_ct_NM TARGET_CFLAGS TARGET_CPPFLAGS TARGET_LDFLAGS LIBCURSES enable_grub_emu enable_grub_fstest LIBOBJS LTLIBOBJS'
ac_subst_files=''
# Initialize some variables set by options.
@ -857,6 +857,8 @@ Optional Features:
--disable-largefile omit support for large files
--enable-mm-debug include memory manager debugging
--enable-grub-emu build and install the `grub-emu' debugging utility
--enable-grub-fstest build and install the `grub-fstest' debugging
utility
Optional Packages:
--with-PACKAGE[=ARG] use PACKAGE [ARG=yes]
@ -7510,6 +7512,13 @@ done
fi
# Check whether --enable-grub-fstest or --disable-grub-fstest was given.
if test "${enable_grub_fstest+set}" = set; then
enableval="$enable_grub_fstest"
fi;
# Output files.
ac_config_links="$ac_config_links include/grub/cpu:include/grub/$target_cpu include/grub/machine:include/grub/$target_cpu/$platform"
@ -8182,6 +8191,7 @@ s,@TARGET_CPPFLAGS@,$TARGET_CPPFLAGS,;t t
s,@TARGET_LDFLAGS@,$TARGET_LDFLAGS,;t t
s,@LIBCURSES@,$LIBCURSES,;t t
s,@enable_grub_emu@,$enable_grub_emu,;t t
s,@enable_grub_fstest@,$enable_grub_fstest,;t t
s,@LIBOBJS@,$LIBOBJS,;t t
s,@LTLIBOBJS@,$LTLIBOBJS,;t t
CEOF

View file

@ -320,6 +320,11 @@ AC_ARG_ENABLE([grub-emu],
[fi]
AC_SUBST([enable_grub_emu])
AC_ARG_ENABLE([grub-fstest],
[AS_HELP_STRING([--enable-grub-fstest],
[build and install the `grub-fstest' debugging utility])])
AC_SUBST([enable_grub_fstest])
# Output files.
AC_CONFIG_LINKS([include/grub/cpu:include/grub/$target_cpu
include/grub/machine:include/grub/$target_cpu/$platform])

523
util/grub-fstest.c Normal file
View file

@ -0,0 +1,523 @@
/* grub-fstest.c - debug tool for filesystem driver */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2008 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <config.h>
#include <grub/types.h>
#include <grub/util/misc.h>
#include <grub/misc.h>
#include <grub/device.h>
#include <grub/disk.h>
#include <grub/file.h>
#include <grub/fs.h>
#include <grub/env.h>
#include <grub/term.h>
#include <grub/mm.h>
#include <grub/normal.h>
#include <grub/script.h>
#include <grub/hexdump.h>
#include <grub_fstest_init.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <getopt.h>
void
grub_putchar (int c)
{
putchar (c);
}
int
grub_getkey (void)
{
return -1;
}
grub_term_t
grub_term_get_current (void)
{
return 0;
}
void
grub_refresh (void)
{
}
static struct grub_command cmd_loopback;
static struct grub_command cmd_blocklist;
static struct grub_command cmd_ls;
grub_command_t
grub_register_command (const char *name,
grub_err_t (*func) (struct grub_arg_list * state,
int argc, char **args),
unsigned flags,
const char *summary __attribute__ ((unused)),
const char *description __attribute__ ((unused)),
const struct grub_arg_option *options)
{
grub_command_t cmd = 0;
if (!grub_strcmp (name, "loopback"))
cmd = &cmd_loopback;
else if (!grub_strcmp (name, "blocklist"))
cmd = &cmd_blocklist;
else if (!grub_strcmp (name, "ls"))
cmd = &cmd_ls;
if (cmd)
{
cmd->func = func;
cmd->flags = flags;
cmd->options = options;
}
return NULL;
}
grub_err_t
execute_command (grub_command_t cmd, int n, char **args)
{
int maxargs = 0;
grub_err_t ret = 0;
struct grub_arg_list *state;
struct grub_arg_option *parser;
char **parsed_arglist;
int numargs;
/* Count the amount of options the command has. */
parser = (struct grub_arg_option *) cmd->options;
while (parser && (parser++)->doc)
maxargs++;
/* Set up the option state. */
state = grub_malloc (sizeof (struct grub_arg_list) * maxargs);
grub_memset (state, 0, sizeof (struct grub_arg_list) * maxargs);
/* Start the command. */
if (!(cmd->flags & GRUB_COMMAND_FLAG_NO_ARG_PARSE))
{
if (grub_arg_parse (cmd, n, args, state, &parsed_arglist, &numargs))
ret = (cmd->func) (state, numargs, parsed_arglist);
}
else
ret = (cmd->func) (state, n, args);
grub_free (state);
return ret;
}
void
grub_unregister_command (const char *name __attribute__ ((unused)))
{
}
#define CMD_LS 1
#define CMD_CP 2
#define CMD_CMP 3
#define CMD_HEX 4
#define CMD_BLOCKLIST 5
#define BUF_SIZE 32256
static grub_off_t skip, leng;
static char *part;
static void
read_file (char *pathname, int (*hook) (grub_off_t ofs, char *buf, int len))
{
static char buf[BUF_SIZE];
grub_file_t file;
grub_off_t ofs, len;
file = grub_file_open (pathname);
if (!file)
{
grub_util_error ("cannot open file %s.\n", pathname);
return;
}
if (skip > file->size)
{
grub_util_error ("invalid skip value %d.\n");
return;
}
ofs = skip;
len = file->size - skip;
if ((leng) && (leng < len))
len = leng;
file->offset = skip;
while (len)
{
grub_ssize_t sz;
sz = grub_file_read (file, buf, (len > BUF_SIZE) ? BUF_SIZE : len);
if (sz < 0)
{
grub_util_error ("read error at offset %llu.\n", ofs);
break;
}
if ((sz == 0) || (hook (ofs, buf, sz)))
break;
ofs += sz;
len -= sz;
}
grub_file_close (file);
}
static void
cmd_cp (char *src, char *dest)
{
FILE *ff;
auto int cp_hook (grub_off_t ofs, char *buf, int len);
int cp_hook (grub_off_t ofs, char *buf, int len)
{
(void) ofs;
if ((int) fwrite (buf, 1, len, ff) != len)
{
grub_util_error ("write error.\n");
return 1;
}
return 0;
}
ff = fopen (dest, "w");
if (ff == NULL)
{
grub_util_error ("open error.\n");
return;
}
read_file (src, cp_hook);
fclose (ff);
}
static void
cmd_cmp (char *src, char *dest)
{
FILE *ff;
static char buf_1[BUF_SIZE];
auto int cmp_hook (grub_off_t ofs, char *buf, int len);
int cmp_hook (grub_off_t ofs, char *buf, int len)
{
if ((int) fread (buf_1, 1, len, ff) != len)
{
grub_util_error ("read error at offset %llu.\n", ofs);
return 1;
}
if (grub_memcmp (buf, buf_1, len))
{
int i;
for (i = 0; i < len; i++, ofs++)
if (buf_1[i] != buf[i])
{
grub_util_error ("compare fail at offset %llu.\n", ofs);
return 1;
}
}
return 0;
}
ff = fopen (dest, "r");
if (ff == NULL)
{
grub_util_error ("open error.\n");
return;
}
if ((skip) && (fseek (ff, skip, SEEK_SET)))
grub_util_error ("fseek error.\n");
read_file (src, cmp_hook);
fclose (ff);
}
static void
cmd_hex (char *pathname)
{
auto int hex_hook (grub_off_t ofs, char *buf, int len);
int hex_hook (grub_off_t ofs, char *buf, int len)
{
hexdump (ofs, buf, len);
return 0;
}
read_file (pathname, hex_hook);
}
static void
fstest (char *image_path, int cmd, int n, char **args)
{
char host_file[7 + grub_strlen (image_path) + 1];
char device_name[(part) ? (6 + grub_strlen (part)) : 5];
char *argv[3] = { "-p", "loop", host_file };
grub_sprintf (host_file, "(host)/%s", image_path);
if (execute_command (&cmd_loopback, 3, argv))
{
grub_util_error ("loopback command fails.\n");
goto fail;
}
if (part)
grub_sprintf (device_name, "loop,%s", part);
else
grub_strcpy (device_name, "loop");
grub_env_set ("root", device_name);
switch (cmd)
{
case CMD_LS:
execute_command (&cmd_ls, n, args);
break;
case CMD_CP:
cmd_cp (args[0], args[1]);
break;
case CMD_CMP:
cmd_cmp (args[0], args[1]);
break;
case CMD_HEX:
cmd_hex (args[0]);
break;
case CMD_BLOCKLIST:
execute_command (&cmd_blocklist, n, args);
grub_printf ("\n");
}
fail:
argv[0] = "-d";
execute_command (&cmd_loopback, 2, argv);
}
static struct option options[] = {
{"part", required_argument, 0, 'p'},
{"skip", required_argument, 0, 's'},
{"length", required_argument, 0, 'n'},
{"debug", required_argument, 0, 'd'},
{"raw", no_argument, 0, 'r'},
{"long", no_argument, 0, 'l'},
{"help", no_argument, 0, 'h'},
{"version", no_argument, 0, 'V'},
{"verbose", no_argument, 0, 'v'},
{0, 0, 0, 0}
};
static void
usage (int status)
{
if (status)
fprintf (stderr, "Try ``grub-fstest --help'' for more information.\n");
else
printf ("\
Usage: grub-fstest [OPTION]... IMAGE_PATH COMMANDS\n\
\n\
Debug tool for filesystem driver.\n\
\nCommands:\n\
ls PATH list files in PATH\n\
cp SRC DEST copy file to local system\n\
cmp SRC DEST compare files\n\
hex FILE hex dump FILE\n\
blocklist FILE display blocklist of FILE\n\
\nOptions:\n\
-p, --part=NUM select partition NUM\n\
-s, --skip=N skip N bytes from output file\n\
-n, --length=N handle N bytes in output file\n\
-d, --debug=S Set debug environment variable\n\
-r, --raw disable auto decompression\n\
-l, --long show long directory list\n\
-h, --help display this message and exit\n\
-V, --version print version information and exit\n\
-v, --verbose print verbose messages\n\
\n\
Report bugs to <%s>.\n", PACKAGE_BUGREPORT);
exit (status);
}
int
main (int argc, char *argv[])
{
char *image_path, *debug_str = 0;
int cmd, is_raw = 0, is_long = 0;
progname = "grub-fstest";
/* Check for options. */
while (1)
{
int c = getopt_long (argc, argv, "p:s:n:d:rlhVv", options, 0);
if (c == -1)
break;
else
switch (c)
{
case 'p':
part = optarg;
break;
case 's':
skip = grub_strtoul (optarg, NULL, 0);
break;
case 'n':
leng = grub_strtoul (optarg, NULL, 0);
break;
case 'd':
debug_str = optarg;
break;
case 'r':
is_raw = 1;
break;
case 'l':
is_long = 1;
break;
case 'h':
usage (0);
break;
case 'V':
printf ("%s (%s) %s\n", progname, PACKAGE_NAME, PACKAGE_VERSION);
return 0;
case 'v':
verbosity++;
break;
default:
usage (1);
break;
}
}
/* Obtain PATH. */
if (optind >= argc)
{
fprintf (stderr, "No path is specified.\n");
usage (1);
}
image_path = argv[optind];
if (*image_path != '/')
{
fprintf (stderr, "Must use absolute path.\n");
usage (1);
}
optind++;
cmd = 0;
if (optind < argc)
{
int nparm = 1;
if (!grub_strcmp (argv[optind], "ls"))
{
cmd = CMD_LS;
if (is_long)
argv[optind--] = "-l";
else
nparm = 0;
}
else if (!grub_strcmp (argv[optind], "cp"))
{
cmd = CMD_CP;
nparm = 2;
}
else if (!grub_strcmp (argv[optind], "cmp"))
{
cmd = CMD_CMP;
nparm = 2;
}
else if (!grub_strcmp (argv[optind], "hex"))
{
cmd = CMD_HEX;
}
else if (!grub_strcmp (argv[optind], "blocklist"))
{
cmd = CMD_BLOCKLIST;
}
else
{
fprintf (stderr, "Invalid command %s.\n", argv[optind]);
usage (1);
}
if (optind + 1 + nparm > argc)
{
fprintf (stderr, "Invalid parameter for command %s.\n",
argv[optind]);
usage (1);
}
optind++;
}
else
{
fprintf (stderr, "No command is specified.\n");
usage (1);
}
grub_hostfs_init ();
/* Initialize all modules. */
grub_init_all ();
if (is_raw)
grub_env_set ("filehook", "0");
if (debug_str)
grub_env_set ("debug", debug_str);
/* Do it. */
fstest (image_path + 1, cmd, argc - optind, argv + optind);
/* Free resources. */
grub_fini_all ();
grub_hostfs_fini ();
return 0;
}