From: Robert Millan <rmh@aybabtu.com>
To: grub-devel@gnu.org
Cc: Bean <bean123ch@gmail.com>
Subject: [PATCH] split tar & cpio
Date: Sat, 8 Nov 2008 17:17:15 +0100 [thread overview]
Message-ID: <20081108161715.GA7474@thorin> (raw)
[-- Attachment #1: Type: text/plain, Size: 621 bytes --]
Hi,
I thought it would be a good idea to split tar & cpio into separate modules
to save some space and make things easier to figure out for the users. I
managed to do this without duplicating code, with a bit of pre-processor
magic.
The saved size is not much, though (~400 bytes). But users looking for tar
will find it more easily. How do you feel about this? Is it worth it?
--
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."
[-- Attachment #2: tar.diff --]
[-- Type: text/x-diff, Size: 8399 bytes --]
Index: conf/common.rmk
===================================================================
--- conf/common.rmk (revision 1903)
+++ conf/common.rmk (working copy)
@@ -17,7 +17,7 @@ grub_probe_SOURCES = util/grub-probe.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/ufs.c fs/xfs.c fs/afs.c fs/tar.c \
\
partmap/pc.c partmap/apple.c partmap/gpt.c \
kern/fs.c kern/env.c fs/fshelp.c \
@@ -37,7 +37,7 @@ grub_fstest_SOURCES = util/grub-fstest.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/ufs.c fs/xfs.c fs/afs.c fs/tar.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 \
@@ -150,8 +150,8 @@ grub-mkconfig_DATA += util/grub.d/README
# Filing systems.
pkglib_MODULES += fshelp.mod fat.mod ufs.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 udf.mod \
- afs.mod
+ affs.mod sfs.mod hfsplus.mod reiserfs.mod cpio.mod tar.mod \
+ udf.mod afs.mod
# For fshelp.mod.
fshelp_mod_SOURCES = fs/fshelp.c
@@ -233,6 +233,11 @@ cpio_mod_SOURCES = fs/cpio.c
cpio_mod_CFLAGS = $(COMMON_CFLAGS)
cpio_mod_LDFLAGS = $(COMMON_LDFLAGS)
+# For tar.mod.
+tar_mod_SOURCES = fs/cpio.c
+tar_mod_CFLAGS = $(COMMON_CFLAGS) -DMODE_USTAR
+tar_mod_LDFLAGS = $(COMMON_LDFLAGS)
+
# For udf.mod.
udf_mod_SOURCES = fs/udf.c
udf_mod_CFLAGS = $(COMMON_CFLAGS)
Index: conf/i386-pc.rmk
===================================================================
--- conf/i386-pc.rmk (revision 1903)
+++ conf/i386-pc.rmk (working copy)
@@ -99,7 +99,7 @@ grub_setup_SOURCES = util/i386/pc/grub-s
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/ufs.c fs/xfs.c fs/afs.c fs/tar.c \
\
partmap/pc.c partmap/gpt.c \
\
@@ -136,7 +136,7 @@ grub_emu_SOURCES = commands/boot.c comma
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/ufs.c fs/xfs.c fs/afs.c fs/tar.c \
\
util/console.c util/hostfs.c util/grub-emu.c util/misc.c \
util/hostdisk.c util/getroot.c \
Index: conf/i386-efi.rmk
===================================================================
--- conf/i386-efi.rmk (revision 1903)
+++ conf/i386-efi.rmk (working copy)
@@ -43,7 +43,7 @@ grub_emu_SOURCES = commands/boot.c comma
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/ufs.c fs/xfs.c fs/afs.c fs/tar.c \
\
io/gzio.c \
kern/device.c kern/disk.c kern/dl.c kern/elf.c kern/env.c \
Index: conf/powerpc-ieee1275.rmk
===================================================================
--- conf/powerpc-ieee1275.rmk (revision 1903)
+++ conf/powerpc-ieee1275.rmk (working copy)
@@ -48,7 +48,7 @@ grub_emu_SOURCES = commands/boot.c comma
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/ufs.c fs/xfs.c fs/afs.c fs/tar.c \
\
io/gzio.c \
kern/device.c kern/disk.c kern/dl.c kern/elf.c kern/env.c \
Index: conf/i386-coreboot.rmk
===================================================================
--- conf/i386-coreboot.rmk (revision 1903)
+++ conf/i386-coreboot.rmk (working copy)
@@ -65,7 +65,7 @@ grub_emu_SOURCES = commands/boot.c comma
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/ufs.c fs/xfs.c fs/afs.c fs/tar.c \
\
fs/fshelp.c \
io/gzio.c \
Index: conf/i386-ieee1275.rmk
===================================================================
--- conf/i386-ieee1275.rmk (revision 1903)
+++ conf/i386-ieee1275.rmk (working copy)
@@ -63,7 +63,7 @@ grub_emu_SOURCES = commands/boot.c comma
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/ufs.c fs/xfs.c fs/afs.c fs/tar.c \
\
fs/fshelp.c \
io/gzio.c \
Index: fs/tar.c
===================================================================
--- fs/tar.c (revision 0)
+++ fs/tar.c (revision 0)
@@ -0,0 +1,2 @@
+#define MODE_USTAR 1
+#include "fs/cpio.c"
Index: fs/cpio.c
===================================================================
--- fs/cpio.c (revision 1903)
+++ fs/cpio.c (working copy)
@@ -66,16 +66,12 @@ struct HEAD_USTAR
#define HEAD_LENG sizeof(struct HEAD_USTAR)
-#define MODE_BCPIO 1
-#define MODE_USTAR 2
-
struct grub_cpio_data
{
grub_disk_t disk;
grub_uint32_t hofs;
grub_uint32_t dofs;
grub_uint32_t size;
- int mode;
};
#ifndef GRUB_UTIL
@@ -86,8 +82,7 @@ static grub_err_t
grub_cpio_find_file (struct grub_cpio_data *data, char **name,
grub_uint32_t * ofs)
{
- if (data->mode == MODE_BCPIO)
- {
+#ifndef MODE_USTAR
struct HEAD_BCPIO hd;
if (grub_disk_read
@@ -123,9 +118,7 @@ grub_cpio_find_file (struct grub_cpio_da
*ofs = data->dofs + data->size;
if (data->size & 1)
(*ofs)++;
- }
- else
- {
+#else
struct HEAD_USTAR hd;
if (grub_disk_read
@@ -148,7 +141,7 @@ grub_cpio_find_file (struct grub_cpio_da
data->dofs = data->hofs + GRUB_DISK_SECTOR_SIZE;
*ofs = data->dofs + ((data->size + GRUB_DISK_SECTOR_SIZE - 1) &
~(GRUB_DISK_SECTOR_SIZE - 1));
- }
+#endif
return GRUB_ERR_NONE;
}
@@ -157,17 +150,16 @@ grub_cpio_mount (grub_disk_t disk)
{
char hd[HEAD_LENG];
struct grub_cpio_data *data;
- int mode;
if (grub_disk_read (disk, 0, 0, sizeof (hd), hd))
goto fail;
- if (((struct HEAD_BCPIO *) hd)->magic == MAGIC_BCPIO)
- mode = MODE_BCPIO;
- else if (!grub_memcmp (((struct HEAD_USTAR *) hd)->magic, MAGIC_USTAR,
+#ifndef MODE_USTAR
+ if (((struct HEAD_BCPIO *) hd)->magic != MAGIC_BCPIO)
+#else
+ if (grub_memcmp (((struct HEAD_USTAR *) hd)->magic, MAGIC_USTAR,
sizeof (MAGIC_USTAR) - 1))
- mode = MODE_USTAR;
- else
+#endif
goto fail;
data = (struct grub_cpio_data *) grub_malloc (sizeof (*data));
@@ -175,12 +167,17 @@ grub_cpio_mount (grub_disk_t disk)
goto fail;
data->disk = disk;
- data->mode = mode;
return data;
fail:
- grub_error (GRUB_ERR_BAD_FS, "not a cpio filesystem");
+ grub_error (GRUB_ERR_BAD_FS, "not a "
+#ifdef MODE_USTAR
+ "tar"
+#else
+ "cpio"
+#endif
+ " filesystem");
return 0;
}
@@ -331,16 +328,22 @@ grub_cpio_close (grub_file_t file)
}
static struct grub_fs grub_cpio_fs = {
+#ifdef MODE_USTAR
+ .name = "tarfs",
+#else
.name = "cpiofs",
+#endif
.dir = grub_cpio_dir,
.open = grub_cpio_open,
.read = grub_cpio_read,
.close = grub_cpio_close,
- .label = 0,
- .next = 0
};
+#ifdef MODE_USTAR
GRUB_MOD_INIT (cpio)
+#else
+GRUB_MOD_INIT (tar)
+#endif
{
grub_fs_register (&grub_cpio_fs);
#ifndef GRUB_UTIL
@@ -348,7 +351,11 @@ GRUB_MOD_INIT (cpio)
#endif
}
+#ifdef MODE_USTAR
GRUB_MOD_FINI (cpio)
+#else
+GRUB_MOD_FINI (tar)
+#endif
{
grub_fs_unregister (&grub_cpio_fs);
}
Index: util/i386/pc/grub-mkrescue.in
===================================================================
--- util/i386/pc/grub-mkrescue.in (revision 1903)
+++ util/i386/pc/grub-mkrescue.in (working copy)
@@ -138,7 +138,7 @@ if [ "x${image_type}" = xfloppy -o "x${e
# build core.img
core_img=`mktemp`
- ${grub_mkimage} -d ${input_dir}/ -m ${memdisk_img} -o ${core_img} memdisk cpio
+ ${grub_mkimage} -d ${input_dir}/ -m ${memdisk_img} -o ${core_img} memdisk tar
rm -f ${memdisk_img}
# build floppy image
next reply other threads:[~2008-11-08 16:17 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-11-08 16:17 Robert Millan [this message]
2009-02-07 23:42 ` [PATCH] split tar & cpio Robert Millan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20081108161715.GA7474@thorin \
--to=rmh@aybabtu.com \
--cc=bean123ch@gmail.com \
--cc=grub-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.