Skip to contentSkip to conversation

Split ufs.mod into ufs1.mod and ufs2.mod

PATCH In review Vladimir 'phcoder' Serbinenko 2 participants 4 messages Aug 13, 2009 VFS

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 Split ufs.mod into ufs1.mod and ufs2.mod

ufs1 and ufs2 mainly differ by some structure definitions. Putting them into the same module and checking on runtime creates continuous if ( ... == UFS1) { ... }
By using preprocessor it's possible to avoid most of such ifs Additionally user needs only one FS in core so we save some space core.img with ufs.mod: 23793
core.img with ufs1.mod: 23078
core.img with ufs2.mod: 23322

Signature · 4 lines
Regards
Vladimir 'phcoder' Serbinenko

Personal git repository: http://repo.or.cz/w/grub2/phcoder.git
ChangeLog +31 -0
index 675cc6d..8e13775 100644
@@ -1,3 +1,34 @@
+2009-08-13  Vladimir Serbinenko  <[email protected]>
+
+	Split ufs.mod into ufs1.mod and ufs2.mod.
+
+	* conf/common.rmk (grub_probe_SOURCES): Add fs/ufs2.c.
+	(grub_fstest_SOURCES): Likewise.
+	(pkglib_MODULES): Remove ufs.mod. Add ufs1.mod and ufs2.mod.
+	(ufs_mod_SOURCES): Remove.
+	(ufs_mod_CFLAGS): Likewise.
+	(ufs_mod_LDFLAGS): Likewise.
+	(ufs1_mod_SOURCES): New variable.
+	(ufs1_mod_CFLAGS): Likewise.
+	(ufs1_mod_LDFLAGS): Likewise.
+	(ufs1_mod_SOURCES): New variable.
+	(ufs1_mod_CFLAGS): Likewise.
+	(ufs1_mod_LDFLAGS): Likewise.
+	* conf/i386-coreboot.rmk (grub_emu_SOURCES): Add fs/ufs2.c.
+	* conf/i386-efi.rmk (util/i386/efi/grub-mkimage.c_DEPENDENCIES):
+	Likewise.
+	(grub_emu_SOURCES): Likewise.
+	* conf/i386-ieee1275.rmk (grub_emu_SOURCES): Likewise.
+	* conf/i386-pc.rmk (grub_emu_SOURCES): Likewise.
+	(grub_setup_SOURCES): Likewise.
+	* conf/powerpc-ieee1275.rmk (grub_emu_SOURCES): Likewise.
+	* conf/sparc64.rmk (grub_emu_SOURCES): Likewise.
+	(grub_setup_SOURCES): Likewise.	
+	* conf/x86_64-efi.rmk (util/i386/efi/grub-mkimage.c_DEPENDENCIES):
+	Likewise.
+	* fs/ufs2.c: New file.
+	* fs/ufs.c: Separate UFS1 from UFS2 by using preprocessor.
+
 2009-08-10  Robert Millan  <[email protected]>
 
 	* include/grub/i386/bsd.h (KERNEL_TYPE_NONE, KERNEL_TYPE_FREEBSD)
conf/common.rmk +12 -7
index 032517f..819d413 100644
@@ -17,7 +17,7 @@ grub_probe_SOURCES = util/grub-probe.c	\
 	fs/affs.c fs/cpio.c fs/fat.c fs/ext2.c fs/hfs.c		\
 	fs/hfsplus.c fs/iso9660.c fs/udf.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 fs/afs.c fs/befs.c fs/tar.c		\
+	fs/ufs.c fs/ufs2.c fs/xfs.c fs/afs.c fs/befs.c fs/tar.c		\
 	\
 	partmap/pc.c partmap/apple.c partmap/sun.c partmap/gpt.c\
 	kern/fs.c kern/env.c fs/fshelp.c			\
@@ -38,7 +38,7 @@ grub_fstest_SOURCES = util/grub-fstest.c util/hostfs.c util/misc.c 	\
 	fs/affs.c fs/cpio.c fs/fat.c fs/ext2.c fs/hfs.c			\
 	fs/hfsplus.c fs/iso9660.c fs/udf.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 fs/afs.c fs/befs.c fs/tar.c			\
+	fs/ufs.c fs/ufs2.c fs/xfs.c fs/afs.c fs/befs.c fs/tar.c			\
 	\
 	kern/partition.c partmap/pc.c partmap/apple.c partmap/sun.c	\
 	partmap/gpt.c							\
@@ -174,7 +174,7 @@ sbin_SCRIPTS += grub-dumpbios
 CLEANFILES += grub-dumpbios
 
 # Filing systems.
-pkglib_MODULES += fshelp.mod fat.mod ufs.mod ext2.mod ntfs.mod		\
+pkglib_MODULES += fshelp.mod fat.mod ufs1.mod ufs2.mod ext2.mod ntfs.mod \
 	ntfscomp.mod minix.mod hfs.mod jfs.mod iso9660.mod xfs.mod	\
 	affs.mod sfs.mod hfsplus.mod reiserfs.mod cpio.mod tar.mod	\
 	udf.mod	afs.mod befs.mod
@@ -189,10 +189,15 @@ fat_mod_SOURCES = fs/fat.c
 fat_mod_CFLAGS = $(COMMON_CFLAGS)
 fat_mod_LDFLAGS = $(COMMON_LDFLAGS)
 
-# For ufs.mod.
-ufs_mod_SOURCES = fs/ufs.c
-ufs_mod_CFLAGS = $(COMMON_CFLAGS)
-ufs_mod_LDFLAGS = $(COMMON_LDFLAGS)
+# For ufs1.mod.
+ufs1_mod_SOURCES = fs/ufs.c
+ufs1_mod_CFLAGS = $(COMMON_CFLAGS)
+ufs1_mod_LDFLAGS = $(COMMON_LDFLAGS)
+
+# For ufs2.mod.
+ufs2_mod_SOURCES = fs/ufs2.c
+ufs2_mod_CFLAGS = $(COMMON_CFLAGS)
+ufs2_mod_LDFLAGS = $(COMMON_LDFLAGS)
 
 # For ext2.mod.
 ext2_mod_SOURCES = fs/ext2.c
conf/i386-coreboot.rmk +1 -1
index 7ba5737..ce2576b 100644
@@ -116,7 +116,7 @@ grub_emu_SOURCES = commands/minicmd.c commands/cat.c commands/cmp.c	\
 	fs/affs.c fs/cpio.c fs/fat.c fs/ext2.c  fs/hfs.c		\
 	fs/hfsplus.c fs/iso9660.c fs/udf.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 fs/afs.c fs/befs.c fs/tar.c				\
+	fs/ufs.c fs/ufs2.c fs/xfs.c fs/afs.c fs/befs.c fs/tar.c				\
 	\
 	fs/fshelp.c							\
 	io/gzio.c							\
conf/i386-efi.rmk +2 -2
index 9177b9d..6e3cbcf 100644
@@ -24,7 +24,7 @@ util/i386/efi/grub-mkimage.c_DEPENDENCIES = Makefile
 #	util/misc.c util/getroot.c kern/device.c kern/disk.c	\
 #	kern/err.c kern/misc.c fs/fat.c fs/ext2.c fs/xfs.c fs/affs.c	\
 #	fs/sfs.c kern/parser.c kern/partition.c partmap/pc.c		\
-#	fs/ufs.c fs/minix.c fs/hfs.c fs/jfs.c fs/hfsplus.c kern/file.c	\
+#	fs/ufs.c fs/ufs2.c fs/minix.c fs/hfs.c fs/jfs.c fs/hfsplus.c kern/file.c	\
 #	kern/fs.c kern/env.c fs/fshelp.c
 
 # For grub-mkdevicemap.
@@ -44,7 +44,7 @@ grub_emu_SOURCES = commands/minicmd.c commands/cat.c commands/cmp.c 	\
 	fs/affs.c fs/cpio.c fs/ext2.c fs/fat.c fs/hfs.c			\
 	fs/hfsplus.c fs/iso9660.c fs/udf.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 fs/afs.c fs/befs.c fs/tar.c				\
+	fs/ufs.c fs/ufs2.c fs/xfs.c fs/afs.c fs/befs.c fs/tar.c				\
 	\
 	io/gzio.c							\
 	kern/device.c kern/disk.c kern/dl.c kern/elf.c kern/env.c	\
conf/i386-ieee1275.rmk +1 -1
index 0321979..65d1c6b 100644
@@ -71,7 +71,7 @@ grub_emu_SOURCES = commands/minicmd.c commands/cat.c commands/cmp.c	\
 	fs/affs.c fs/cpio.c fs/fat.c fs/ext2.c fs/hfs.c			\
 	fs/hfsplus.c fs/iso9660.c fs/udf.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 fs/afs.c fs/befs.c fs/tar.c				\
+	fs/ufs.c fs/ufs2.c fs/xfs.c fs/afs.c fs/befs.c fs/tar.c				\
 	\
 	fs/fshelp.c							\
 	io/gzio.c							\
conf/i386-pc.rmk +2 -2
index 798aee2..8da134c 100644
@@ -104,7 +104,7 @@ grub_setup_SOURCES = util/i386/pc/grub-setup.c util/hostdisk.c	\
 	fs/affs.c fs/cpio.c fs/ext2.c fs/fat.c fs/hfs.c		\
 	fs/hfsplus.c fs/iso9660.c fs/udf.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 fs/afs.c fs/befs.c fs/tar.c			\
+	fs/ufs.c fs/ufs2.c fs/xfs.c fs/afs.c fs/befs.c fs/tar.c			\
 	\
 	partmap/pc.c partmap/gpt.c				\
 	\
@@ -148,7 +148,7 @@ grub_emu_SOURCES = commands/minicmd.c commands/cat.c commands/cmp.c	\
 	fs/affs.c fs/cpio.c  fs/fat.c fs/ext2.c fs/hfs.c		\
 	fs/hfsplus.c fs/iso9660.c fs/udf.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 fs/afs.c fs/befs.c fs/tar.c				\
+	fs/ufs.c fs/ufs2.c fs/xfs.c fs/afs.c fs/befs.c fs/tar.c				\
 	\
 	util/console.c util/hostfs.c util/grub-emu.c util/misc.c	\
 	util/hostdisk.c util/getroot.c					\
conf/powerpc-ieee1275.rmk +1 -1
index af29d23..c30f61a 100644
@@ -51,7 +51,7 @@ grub_emu_SOURCES = commands/minicmd.c commands/cat.c commands/cmp.c 	\
 	fs/affs.c fs/cpio.c fs/fat.c fs/ext2.c fs/hfs.c			\
 	fs/hfsplus.c fs/iso9660.c fs/udf.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 fs/afs.c fs/befs.c fs/tar.c				\
+	fs/ufs.c fs/ufs2.c fs/xfs.c fs/afs.c fs/befs.c fs/tar.c				\
 	\
 	io/gzio.c							\
 	kern/device.c kern/disk.c kern/dl.c kern/elf.c kern/env.c	\
conf/sparc64-ieee1275.rmk +2 -2
index aabccee..b26496d 100644
@@ -78,7 +78,7 @@ grub_setup_SOURCES = util/sparc64/ieee1275/grub-setup.c util/hostdisk.c	\
 	fs/affs.c fs/cpio.c fs/ext2.c fs/fat.c fs/hfs.c		\
 	fs/hfsplus.c fs/iso9660.c fs/udf.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 fs/afs.c fs/befs.c fs/tar.c			\
+	fs/ufs.c fs/ufs2.c fs/xfs.c fs/afs.c fs/befs.c fs/tar.c			\
 	\
 	partmap/amiga.c	partmap/apple.c partmap/pc.c		\
 	partmap/sun.c partmap/acorn.c				\
@@ -108,7 +108,7 @@ grub_emu_SOURCES = commands/minicmd.c commands/cat.c commands/cmp.c 	\
 	fs/affs.c fs/cpio.c fs/fat.c fs/ext2.c fs/hfs.c			\
 	fs/hfsplus.c fs/iso9660.c fs/udf.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 fs/afs.c fs/befs.c fs/tar.c				\
+	fs/ufs.c fs/ufs2.c fs/xfs.c fs/afs.c fs/befs.c fs/tar.c				\
 	\
 	io/gzio.c							\
 	kern/device.c kern/disk.c kern/dl.c kern/elf.c kern/env.c	\
conf/x86_64-efi.rmk +2 -2
index 21da0e1..71a90ce 100644
@@ -23,7 +23,7 @@ grub_mkimage_SOURCES = util/i386/efi/grub-mkimage.c util/misc.c \
 #	util/misc.c util/getroot.c kern/device.c kern/disk.c	\
 #	kern/err.c kern/misc.c fs/fat.c fs/ext2.c fs/xfs.c fs/affs.c	\
 #	fs/sfs.c kern/parser.c kern/partition.c partmap/pc.c		\
-#	fs/ufs.c fs/minix.c fs/hfs.c fs/jfs.c fs/hfsplus.c kern/file.c	\
+#	fs/ufs.c fs/ufs2.c fs/minix.c fs/hfs.c fs/jfs.c fs/hfsplus.c kern/file.c	\
 #	kern/fs.c kern/env.c fs/fshelp.c
 
 # For grub-mkdevicemap.
@@ -42,7 +42,7 @@ grub_emu_SOURCES = commands/minicmd.c commands/cat.c commands/cmp.c 	\
 	fs/affs.c fs/cpio.c fs/fat.c fs/ext2.c fs/hfs.c			\
 	fs/hfsplus.c fs/iso9660.c fs/udf.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 fs/afs.c					\
+	fs/ufs.c fs/ufs2.c fs/xfs.c fs/afs.c					\
 	\
 	io/gzio.c							\
 	kern/device.c kern/disk.c kern/dl.c kern/elf.c kern/env.c	\
fs/ufs.c +109 -115

408 lines not on this page · raw message

fs/ufs2.c new file +3 -0
new file mode 100644
index 0000000..7f4eb95
@@ -0,0 +1,3 @@
+/* ufs2.c - Unix File System 2 */
+#define MODE_UFS2 1
+#include "ufs.c"
#1 lore raw
Quoted 8 lines · Vladimir 'phcoder' Serbinenko

ufs1 and ufs2 mainly differ by some structure definitions. Putting them into the same module and checking on runtime creates continuous if ( ... == UFS1) { ... }
By using preprocessor it's possible to avoid most of such ifs Additionally user needs only one FS in core so we save some space core.img with ufs.mod: 23793
core.img with ufs1.mod: 23078
core.img with ufs2.mod: 23322

Very nice.

fs/ufs.c line 72

Quoted 10 lines
fs/ufs.c +10 -0
+#ifdef MODE_UFS2
+#define INODE_BLKSZ 8
+#else
+#define INODE_BLKSZ 4
+#endif
+#ifndef MODE_UFS2
+#define UFS_INODE_PER_BLOCK 4
+#else
+#define UFS_INODE_PER_BLOCK 2
+#endif

When you commit this, could you please follow logical order with ifdef/else/endif? The negation is less intuitive to read.

fs/ufs.c grub_ufs_get_file_block (struct grub_ufs_data *data, unsigned int blk) · line 247

Quoted 5 lines
fs/ufs.c +5 -0
+#ifdef MODE_UFS2
+      grub_uint64_t indir[UFS_BLKSZ (sblock) / sizeof (grub_uint64_t)];
+#else
+      grub_uint32_t indir[UFS_BLKSZ (sblock) / sizeof (grub_uint32_t)];
+#endif

Can this be made simpler by using typeof() ? (same for the other one below)

fs/ufs.c grub_ufs_get_file_block (struct grub_ufs_data *data, unsigned int blk) · line 250

Quoted 2 lines
fs/ufs.c +1 -1
-      return (data->ufs_type == UFS1) ? indir[blk] : indir[blk << 1];
+      return indir[blk];

The blk bitshift was accounted for elsewhere? (Btw I assume you've tested on both filesystem types).

fs/ufs.c grub_ufs_find_file (struct grub_ufs_data *data, const char *path) · line 464

Quoted 6 lines
fs/ufs.c +5 -1
-	? dirent.namelen_bsd : grub_le_to_cpu16 (dirent.namelen);
+#ifdef MODE_UFS2
+      namelen = dirent.namelen_bsd;
+#else
+      namelen = grub_le_to_cpu16 (dirent.namelen);
+#endif

I wonder if there was a bug here (native endianess assumed for namelen_bsd?)

Signature · 5 lines
Robert Millan

  The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
  how) you may access your data; but nobody's threatening your freedom: we
  still allow you to remove your data and not access it at all."
#2 lore raw
Quoted 3 lines

When you commit this, could you please follow logical order with ifdef/else/endif?  The negation is less intuitive to read.

Ok

Quoted 9 lines

fs/ufs.c grub_ufs_get_file_block (struct grub_ufs_data *data, unsigned int blk) · line 247

Quoted 6 lines
fs/ufs.c +5 -0
+#ifdef MODE_UFS2
+      grub_uint64_t indir[UFS_BLKSZ (sblock) / sizeof (grub_uint64_t)];
+#else
+      grub_uint32_t indir[UFS_BLKSZ (sblock) / sizeof (grub_uint32_t)];
+#endif

Can this be made simpler by using typeof() ?  (same for the other one below)

I tried using sizeof (indir[0]) but it doesn't work since indir isn't defined at that point.

Quoted 5 lines
Quoted 2 lines

-      return (data->ufs_type == UFS1) ? indir[blk] : indir[blk << 1];
+      return indir[blk];

The blk bitshift was accounted for elsewhere?

By using correct type (grub_uint64_t vs grub_uint32_t)

Quoted 2 lines

(Btw I assume you've tested
on both filesystem types).

I tested on FreeBSD variants of UFS1 and UFS2. For Sun UFS1 I relied on report by Seth Goldberg

Quoted 9 lines

fs/ufs.c grub_ufs_find_file (struct grub_ufs_data *data, const char *path) · line 464

Quoted 6 lines

-     ? dirent.namelen_bsd : grub_le_to_cpu16 (dirent.namelen);

fs/ufs.c +5 -0
+#ifdef MODE_UFS2
+      namelen = dirent.namelen_bsd;
+#else
+      namelen = grub_le_to_cpu16 (dirent.namelen);
+#endif

I wonder if there was a bug here (native endianess assumed for namelen_bsd?)

It's one byte

Quoted 13 lines

--
Robert Millan

 The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."

_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel

Signature · 4 lines
Regards
Vladimir 'phcoder' Serbinenko

Personal git repository: http://repo.or.cz/w/grub2/phcoder.git
#3 lore raw
Quoted 13 lines · Vladimir 'phcoder' Serbinenko
Quoted 3 lines

When you commit this, could you please follow logical order with ifdef/else/endif?  The negation is less intuitive to read.

Ok

Quoted 9 lines

fs/ufs.c grub_ufs_get_file_block (struct grub_ufs_data *data, unsigned int blk) · line 247

Quoted 6 lines
fs/ufs.c +5 -0
+#ifdef MODE_UFS2
+      grub_uint64_t indir[UFS_BLKSZ (sblock) / sizeof (grub_uint64_t)];
+#else
+      grub_uint32_t indir[UFS_BLKSZ (sblock) / sizeof (grub_uint32_t)];
+#endif

Can this be made simpler by using typeof() ?  (same for the other one below)

Quoted 2 lines

I tried using sizeof (indir[0]) but it doesn't work since indir isn't defined at that point.

Ah, of course..

Quoted 19 lines
Quoted 5 lines
Quoted 2 lines

-      return (data->ufs_type == UFS1) ? indir[blk] : indir[blk << 1];
+      return indir[blk];

The blk bitshift was accounted for elsewhere?

By using correct type (grub_uint64_t vs grub_uint32_t)

Quoted 2 lines

(Btw I assume you've tested
on both filesystem types).

I tested on FreeBSD variants of UFS1 and UFS2. For Sun UFS1 I relied on report by Seth Goldberg

Quoted 9 lines

fs/ufs.c grub_ufs_find_file (struct grub_ufs_data *data, const char *path) · line 464

Quoted 6 lines

-     ? dirent.namelen_bsd : grub_le_to_cpu16 (dirent.namelen);

fs/ufs.c +5 -0
+#ifdef MODE_UFS2
+      namelen = dirent.namelen_bsd;
+#else
+      namelen = grub_le_to_cpu16 (dirent.namelen);
+#endif

I wonder if there was a bug here (native endianess assumed for namelen_bsd?)

Quoted 1 line

It's one byte

Ok.

Looks good to me then. Please remember about the ifndef/else/endif thing.

Signature · 5 lines
Robert Millan

  The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
  how) you may access your data; but nobody's threatening your freedom: we
  still allow you to remove your data and not access it at all."