Skip to contentSkip to conversation

cpio and tar filesystem

PATCH In review Bean 2 participants 7 messages Dec 23, 2007 – Dec 26, 2007 VFS

lore
Share & tools
lore

Bean

author
#0 lore raw

PATCH 1/1 cpio and tar filesystem

I write a filesystem driver for cpio and tar archive file. now you can open the archive with loopback command:

loopback aa (hd0,1)/cpio_file

loopback bb (hd0,1)/tar_file

If you also apply my previous patch on transparent decompression, you can even open a gzip archive, for example:

loopback aa (hd0,1)/aa.tar.gz

I also fix a serious bug in the loopback device.

Note: I only write code for binary mode cpio and new format tar, text mode cpio and old format tar is not supported.

2007-12-24 Bean <[email protected]>

* conf/common.rmk (pkgdata_MODULES): Add cpio.mod. (cpio_mod_SOURCES): New variable. (cpio_mod_CFLAGS): Likewise. (cpio_mod_LDFLAGS): Likewise.

* fs/cpio.c: New file.

* disk/loopback.c (grub_loopback_read): Bug fix.

* conf/i386-pc.rmk (grub_emu_SOURCES): Add cpio.c.

* conf/i386-efi.rmk (grub_emu_SOURCES): Likewise.

* conf/i386-linuxbios.rmk (grub_emu_SOURCES): Likewise.

* conf/powerpc-ieee1275.rmk (grub_emu_SOURCES): Likewise.

conf/common.rmk +6 -1
index 0e6b81b..f7c8fdb 100644
@@ -81,7 +81,7 @@ update-grub_DATA += util/grub.d/README
 # Filing systems.
 pkgdata_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
+	affs.mod sfs.mod hfsplus.mod cpio.mod
 
 # For fshelp.mod.
 fshelp_mod_SOURCES = fs/fshelp.c
@@ -153,6 +153,11 @@ hfsplus_mod_SOURCES = fs/hfsplus.c
 hfsplus_mod_CFLAGS = $(COMMON_CFLAGS)
 hfsplus_mod_LDFLAGS = $(COMMON_LDFLAGS)
 
+# For cpio.mod.
+cpio_mod_SOURCES = fs/cpio.c
+cpio_mod_CFLAGS = $(COMMON_CFLAGS)
+cpio_mod_LDFLAGS = $(COMMON_LDFLAGS)
+
 # Partition maps.
 pkgdata_MODULES += amiga.mod apple.mod pc.mod sun.mod acorn.mod gpt.mod
 
conf/i386-efi.rmk +0 -0
index 305cbe4..397cfbb 100644
@@ -51,7 +51,7 @@ grub_emu_SOURCES = commands/boot.c commands/cat.c

commands/cmp.c \
disk/loopback.c \
fs/affs.c fs/ext2.c fs/fat.c fs/fshelp.c fs/hfs.c fs/iso9660.c \
fs/jfs.c fs/minix.c fs/sfs.c fs/ufs.c fs/xfs.c fs/hfsplus.c \
- fs/ntfs.c fs/ntfscomp.c \
+ fs/ntfs.c fs/ntfscomp.c fs/cpio.c \
io/gzio.c \
kern/device.c kern/disk.c kern/dl.c kern/elf.c kern/env.c \
kern/err.c \

conf/i386-linuxbios.rmk +0 -0
index 8b98d3b..c33d937 100644
@@ -76,7 +76,7 @@ grub_emu_SOURCES = commands/boot.c commands/cat.c

commands/cmp.c \
disk/host.c disk/loopback.c disk/raid.c disk/lvm.c \
fs/affs.c fs/ext2.c fs/fat.c fs/fshelp.c fs/hfs.c fs/iso9660.c \
fs/jfs.c fs/minix.c fs/sfs.c fs/ufs.c fs/xfs.c fs/hfsplus.c \
- fs/ntfs.c fs/ntfscomp.c \
+ fs/ntfs.c fs/ntfscomp.c fs/cpio.c \
io/gzio.c \
kern/device.c kern/disk.c kern/dl.c kern/elf.c kern/env.c \
kern/err.c \

conf/i386-pc.rmk +0 -0
index 8c100d7..8e0f31b 100644
@@ -103,7 +103,7 @@ grub_emu_SOURCES = commands/boot.c commands/cat.c

commands/cmp.c \
disk/host.c disk/loopback.c disk/raid.c disk/lvm.c \
fs/affs.c fs/ext2.c fs/fat.c fs/fshelp.c fs/hfs.c fs/iso9660.c \
fs/jfs.c fs/minix.c fs/sfs.c fs/ufs.c fs/xfs.c fs/hfsplus.c \
- fs/ntfs.c fs/ntfscomp.c \
+ fs/ntfs.c fs/ntfscomp.c fs/cpio.c \
io/gzio.c \
kern/device.c kern/disk.c kern/dl.c kern/elf.c kern/env.c \
kern/err.c \

conf/powerpc-ieee1275.rmk +0 -0
index eb440f1..af0773b 100644
@@ -62,7 +62,7 @@ grub_emu_SOURCES = commands/boot.c commands/cat.c

commands/cmp.c \
disk/loopback.c \
fs/affs.c fs/ext2.c fs/fat.c fs/fshelp.c fs/hfs.c fs/iso9660.c \
fs/jfs.c fs/minix.c fs/sfs.c fs/ufs.c fs/xfs.c fs/hfsplus.c \
- fs/ntfs.c fs/ntfscomp.c \
+ fs/ntfs.c fs/ntfscomp.c fs/cpio.c \
io/gzio.c \
kern/device.c kern/disk.c kern/dl.c kern/elf.c kern/env.c \
kern/err.c kern/file.c kern/fs.c kern/loader.c kern/main.c \

disk/loopback.c +0 -0
index 9d48def..31d8116 100644
@@ -214,7 +214,7 @@ grub_loopback_read (grub_disk_t disk,

grub_disk_addr_t sector,
if (pos > file->size)

     {
       grub_size_t amount = pos - file->size;
-      grub_memset (buf + size - amount, 0, amount);
+      grub_memset (buf + (size << GRUB_DISK_SECTOR_BITS) - amount, 0, amount);
     }

return 0;

Signature · 1 line
Bean
author
#1 lore raw

sorry, forget to add cpio.c, here is the new patch:

2007-12-24 Bean <[email protected]>

* conf/common.rmk (pkgdata_MODULES): Add cpio.mod. (cpio_mod_SOURCES): New variable. (cpio_mod_CFLAGS): Likewise. (cpio_mod_LDFLAGS): Likewise.

* fs/cpio.c: New file.

* disk/loopback.c (grub_loopback_read): Bug fix.

* conf/i386-pc.rmk (grub_emu_SOURCES): Add cpio.c.

* conf/i386-efi.rmk (grub_emu_SOURCES): Likewise.

* conf/i386-linuxbios.rmk (grub_emu_SOURCES): Likewise.

* conf/powerpc-ieee1275.rmk (grub_emu_SOURCES): Likewise.

conf/common.rmk +6 -1
index 0e6b81b..72edb37 100644
@@ -81,7 +81,7 @@ update-grub_DATA += util/grub.d/README
 # Filing systems.
 pkgdata_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
+	affs.mod sfs.mod hfsplus.mod cpio.mod
 
 # For fshelp.mod.
 fshelp_mod_SOURCES = fs/fshelp.c
@@ -153,6 +153,11 @@ hfsplus_mod_SOURCES = fs/hfsplus.c
 hfsplus_mod_CFLAGS = $(COMMON_CFLAGS)
 hfsplus_mod_LDFLAGS = $(COMMON_LDFLAGS)
 
+# For cpio.mod.
+cpio_mod_SOURCES = fs/cpio.c
+cpio_mod_CFLAGS = $(COMMON_CFLAGS)
+cpio_mod_LDFLAGS = $(COMMON_LDFLAGS)
+
 # Partition maps.
 pkgdata_MODULES += amiga.mod apple.mod pc.mod sun.mod acorn.mod gpt.mod
 
conf/i386-efi.rmk +0 -0
index 305cbe4..397cfbb 100644
@@ -51,7 +51,7 @@ grub_emu_SOURCES = commands/boot.c commands/cat.c

commands/cmp.c \
disk/loopback.c \
fs/affs.c fs/ext2.c fs/fat.c fs/fshelp.c fs/hfs.c fs/iso9660.c \
fs/jfs.c fs/minix.c fs/sfs.c fs/ufs.c fs/xfs.c fs/hfsplus.c \
- fs/ntfs.c fs/ntfscomp.c \
+ fs/ntfs.c fs/ntfscomp.c fs/cpio.c \
io/gzio.c \
kern/device.c kern/disk.c kern/dl.c kern/elf.c kern/env.c \
kern/err.c \

conf/i386-linuxbios.rmk +0 -0
index 8b98d3b..c33d937 100644
@@ -76,7 +76,7 @@ grub_emu_SOURCES = commands/boot.c commands/cat.c

commands/cmp.c \
disk/host.c disk/loopback.c disk/raid.c disk/lvm.c \
fs/affs.c fs/ext2.c fs/fat.c fs/fshelp.c fs/hfs.c fs/iso9660.c \
fs/jfs.c fs/minix.c fs/sfs.c fs/ufs.c fs/xfs.c fs/hfsplus.c \
- fs/ntfs.c fs/ntfscomp.c \
+ fs/ntfs.c fs/ntfscomp.c fs/cpio.c \
io/gzio.c \
kern/device.c kern/disk.c kern/dl.c kern/elf.c kern/env.c \
kern/err.c \

conf/i386-pc.rmk +0 -0
index 8c100d7..8e0f31b 100644
@@ -103,7 +103,7 @@ grub_emu_SOURCES = commands/boot.c commands/cat.c

commands/cmp.c \
disk/host.c disk/loopback.c disk/raid.c disk/lvm.c \
fs/affs.c fs/ext2.c fs/fat.c fs/fshelp.c fs/hfs.c fs/iso9660.c \
fs/jfs.c fs/minix.c fs/sfs.c fs/ufs.c fs/xfs.c fs/hfsplus.c \
- fs/ntfs.c fs/ntfscomp.c \
+ fs/ntfs.c fs/ntfscomp.c fs/cpio.c \
io/gzio.c \
kern/device.c kern/disk.c kern/dl.c kern/elf.c kern/env.c \
kern/err.c \

conf/powerpc-ieee1275.rmk +0 -0
index eb440f1..af0773b 100644
@@ -62,7 +62,7 @@ grub_emu_SOURCES = commands/boot.c commands/cat.c

commands/cmp.c \
disk/loopback.c \
fs/affs.c fs/ext2.c fs/fat.c fs/fshelp.c fs/hfs.c fs/iso9660.c \
fs/jfs.c fs/minix.c fs/sfs.c fs/ufs.c fs/xfs.c fs/hfsplus.c \
- fs/ntfs.c fs/ntfscomp.c \
+ fs/ntfs.c fs/ntfscomp.c fs/cpio.c \
io/gzio.c \
kern/device.c kern/disk.c kern/dl.c kern/elf.c kern/env.c \
kern/err.c kern/file.c kern/fs.c kern/loader.c kern/main.c \

disk/loopback.c +0 -0
index 9d48def..31d8116 100644
@@ -214,7 +214,7 @@ grub_loopback_read (grub_disk_t disk,

grub_disk_addr_t sector,
if (pos > file->size)

     {
       grub_size_t amount = pos - file->size;
-      grub_memset (buf + size - amount, 0, amount);
+      grub_memset (buf + (size << GRUB_DISK_SECTOR_BITS) - amount, 0, amount);
     }

return 0;

fs/cpio.c new file +346 -0

346 lines not on this page · raw message

Signature · 1 line
Bean
#2 lore raw
Quoted 8 lines · Bean

* conf/i386-pc.rmk (grub_emu_SOURCES): Add cpio.c.

* conf/i386-efi.rmk (grub_emu_SOURCES): Likewise.

* conf/i386-linuxbios.rmk (grub_emu_SOURCES): Likewise.

* conf/powerpc-ieee1275.rmk (grub_emu_SOURCES): Likewise.

Perhaps it'd be a good idea to move the arch-independant part of grub_emu_SOURCES to common.rmk (as grub_emu_SOURCES += foo), to avoid having to update all the files so often ...

disk/loopback.c grub_loopback_read (grub_disk_t disk, · line 218

Quoted 11 lines
disk/loopback.c +1 -1
index 9d48def..31d8116 100644
@@ -214,7 +214,7 @@ grub_loopback_read (grub_disk_t disk,
 grub_disk_addr_t sector,
   if (pos > file->size)
     {
       grub_size_t amount = pos - file->size;
-      grub_memset (buf + size - amount, 0, amount);
+      grub_memset (buf + (size << GRUB_DISK_SECTOR_BITS) - amount, 0, amount);

Ugh :-) I check this in right now.

Quoted 8 lines
disk/loopback.c +8 -0
+struct HEAD_USTAR
+{
+  char	name[100];
+  char	mode[8];
+  char	uid[8];
+  char	gid[8];
+  char	size[12];
+  char	mtime[12];

disk/loopback.c grub_loopback_read (grub_disk_t disk,

Quoted 10 lines
disk/loopback.c +10 -0
+  char	chksum[8];
+  char	typeflag;
+  char	linkname[100];
+  char	magic[6];
+  char	version[2];
+  char	uname[32];
+  char	gname[32];
+  char	devmajor[8];
+  char	devminor[8];
+  char	prefix[155];

These tabs should be spaces.

disk/loopback.c

Quoted 3 lines
disk/loopback.c +2 -0
+      if (grub_disk_read (data->disk, 0, data->hofs, sizeof(hd), (char*)&hd))
[...]
+      if (grub_disk_read (data->disk, 0, data->hofs, sizeof(hd), (char*)&hd))

`(char *) &hd' here (same for all other casts).

Btw, this line seems to be the same on both cases. It can be moved out of `if (data->mode == MODE_BCPIO)' to save some space?

disk/loopback.c

Quoted 5 lines
disk/loopback.c +4 -0
+      if (hd.namesize & 1)
+        hd.namesize++;
[...]
+      if (data->size & 1)
+        (*ofs)++;

I find this confusing. AFAICT `hd.namesize == 1' would archieve the same and seems to be more consistent with your use of this variable as a counter.

disk/loopback.c

Quoted 3 lines
disk/loopback.c +2 -0
+      if ((*name = grub_malloc (hd.namesize))==NULL)
[...]
+      if ((*name = grub_strdup (hd.name))==NULL)

Please add some spaces: ` == NULL'

disk/loopback.c

Quoted 3 lines
disk/loopback.c +2 -0
+      if (grub_memcmp(hd.magic, MAGIC_USTAR, sizeof(MAGIC_USTAR) - 1))
[...]
+      data->size = grub_strtoul(hd.size, NULL, 8);

grub_memcmp (', grub_strtoul (', etc. Same for other function calls.

disk/loopback.c

Quoted 2 lines
disk/loopback.c +2 -0
+  return (grub_disk_read (data->disk, 0, data->dofs + file->offset,
+                          len, buf))?-1:len;

` ? -1 : len'

disk/loopback.c

Quoted 7 lines
disk/loopback.c +6 -0
+#ifndef GRUB_UTIL
+  grub_dl_unref (my_mod);
+#endif
[...]
+#ifndef GRUB_UTIL
+  my_mod = mod;
+#endif

Are you sure these are still needed? We have a few modules that use them but AFAIK are not necessary at this time.

Signature · 5 lines
Robert Millan

<GPLv2> I know my rights; I want my phone call!
<DRM> What use is a phone call, if you are unable to speak?
(as seen on /.)
author
#3 lore raw
Quoted 3 lines · Robert Millan

Perhaps it'd be a good idea to move the arch-independant part of grub_emu_SOURCES to common.rmk (as grub_emu_SOURCES += foo), to avoid having to update all the files so often ...

yes, but i think it should be in a separate patch.

Quoted 12 lines
Quoted 12 lines
(quoted diff) +12 -0
+struct HEAD_USTAR
+{
+  char       name[100];
+  char       mode[8];
+  char       uid[8];
+  char       gid[8];
+  char       size[12];
+  char       mtime[12];
+  char       chksum[8];
+  char       typeflag;
+  char       linkname[100];
+  char       magic[6];
Quoted 8 lines

Review

Quoted 6 lines
(quoted diff) +6 -0
+  char       version[2];
+  char       uname[32];
+  char       gname[32];
+  char       devmajor[8];
+  char       devminor[8];
+  char       prefix[155];

These tabs should be spaces.

done.

Quoted 10 lines

Review

Quoted 4 lines
(quoted diff) +2 -0
+      if (grub_disk_read (data->disk, 0, data->hofs, sizeof(hd), (char*)&hd))
[...]
+      if (grub_disk_read (data->disk, 0, data->hofs, sizeof(hd), (char*)&hd))

`(char *) &hd' here (same for all other casts).

Btw, this line seems to be the same on both cases. It can be moved out of `if (data->mode == MODE_BCPIO)' to save some space?

In fact, it's not the same, in the first case, hd is of type HEAD_BCPIO, while in the second case, hd is of type HEAD_USTAR.The two structure has different size.

Quoted 9 lines

Review

Quoted 5 lines
(quoted diff) +4 -0
+      if (hd.namesize & 1)
+        hd.namesize++;
[...]
+      if (data->size & 1)
+        (*ofs)++;

I find this confusing. AFAICT `hd.namesize == 1' would archieve the same and seems to be more consistent with your use of this variable as a counter.

When the name size is odd number, cpio pad another byte to make it word align, and the same apply to file size. However, I want to keep the original file size, so it use (*ofs)++ instead of data->size++.

Quoted 10 lines

Review

Quoted 3 lines
(quoted diff) +2 -0
+      if ((*name = grub_malloc (hd.namesize))==NULL)
[...]
+      if ((*name = grub_strdup (hd.name))==NULL)

Please add some spaces: ` == NULL'

Review

Quoted 3 lines
(quoted diff) +2 -0
+      if (grub_memcmp(hd.magic, MAGIC_USTAR, sizeof(MAGIC_USTAR) - 1))
[...]
+      data->size = grub_strtoul(hd.size, NULL, 8);
Quoted 7 lines

grub_memcmp (', grub_strtoul (', etc. Same for other function calls.

Review

Quoted 2 lines
(quoted diff) +2 -0
+  return (grub_disk_read (data->disk, 0, data->dofs + file->offset,
+                          len, buf))?-1:len;

` ? -1 : len'

done.

Quoted 10 lines

Review

Quoted 7 lines
(quoted diff) +6 -0
+#ifndef GRUB_UTIL
+  grub_dl_unref (my_mod);
+#endif
[...]
+#ifndef GRUB_UTIL
+  my_mod = mod;
+#endif

Are you sure these are still needed? We have a few modules that use them but AFAIK are not necessary at this time.

This is needed, the my_mod variable is used to stored the module pointer, and we need it to increase the module reference when a file is opened, so that the modules can't be unloaded.

Here is the new patch.

2007-12-24 Bean <[email protected]>

* conf/common.rmk (pkgdata_MODULES): Add cpio.mod. (cpio_mod_SOURCES): New variable. (cpio_mod_CFLAGS): Likewise. (cpio_mod_LDFLAGS): Likewise.

* fs/cpio.c: New file.

* conf/i386-pc.rmk (grub_emu_SOURCES): Add cpio.c.

* conf/i386-efi.rmk (grub_emu_SOURCES): Likewise.

* conf/i386-linuxbios.rmk (grub_emu_SOURCES): Likewise.

* conf/powerpc-ieee1275.rmk (grub_emu_SOURCES): Likewise.

conf/common.rmk +6 -1
index 0e6b81b..72edb37 100644
@@ -81,7 +81,7 @@ update-grub_DATA += util/grub.d/README
 # Filing systems.
 pkgdata_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
+	affs.mod sfs.mod hfsplus.mod cpio.mod
 
 # For fshelp.mod.
 fshelp_mod_SOURCES = fs/fshelp.c
@@ -153,6 +153,11 @@ hfsplus_mod_SOURCES = fs/hfsplus.c
 hfsplus_mod_CFLAGS = $(COMMON_CFLAGS)
 hfsplus_mod_LDFLAGS = $(COMMON_LDFLAGS)
 
+# For cpio.mod.
+cpio_mod_SOURCES = fs/cpio.c
+cpio_mod_CFLAGS = $(COMMON_CFLAGS)
+cpio_mod_LDFLAGS = $(COMMON_LDFLAGS)
+
 # Partition maps.
 pkgdata_MODULES += amiga.mod apple.mod pc.mod sun.mod acorn.mod gpt.mod
 
conf/i386-efi.rmk +0 -0
index 305cbe4..397cfbb 100644
@@ -51,7 +51,7 @@ grub_emu_SOURCES = commands/boot.c commands/cat.c

commands/cmp.c \
disk/loopback.c \
fs/affs.c fs/ext2.c fs/fat.c fs/fshelp.c fs/hfs.c fs/iso9660.c \
fs/jfs.c fs/minix.c fs/sfs.c fs/ufs.c fs/xfs.c fs/hfsplus.c \
- fs/ntfs.c fs/ntfscomp.c \
+ fs/ntfs.c fs/ntfscomp.c fs/cpio.c \
io/gzio.c \
kern/device.c kern/disk.c kern/dl.c kern/elf.c kern/env.c \
kern/err.c \

conf/i386-linuxbios.rmk +0 -0
index 8b98d3b..c33d937 100644
@@ -76,7 +76,7 @@ grub_emu_SOURCES = commands/boot.c commands/cat.c

commands/cmp.c \
disk/host.c disk/loopback.c disk/raid.c disk/lvm.c \
fs/affs.c fs/ext2.c fs/fat.c fs/fshelp.c fs/hfs.c fs/iso9660.c \
fs/jfs.c fs/minix.c fs/sfs.c fs/ufs.c fs/xfs.c fs/hfsplus.c \
- fs/ntfs.c fs/ntfscomp.c \
+ fs/ntfs.c fs/ntfscomp.c fs/cpio.c \
io/gzio.c \
kern/device.c kern/disk.c kern/dl.c kern/elf.c kern/env.c \
kern/err.c \

conf/i386-pc.rmk +0 -0
index 8c100d7..8e0f31b 100644
@@ -103,7 +103,7 @@ grub_emu_SOURCES = commands/boot.c commands/cat.c

commands/cmp.c \
disk/host.c disk/loopback.c disk/raid.c disk/lvm.c \
fs/affs.c fs/ext2.c fs/fat.c fs/fshelp.c fs/hfs.c fs/iso9660.c \
fs/jfs.c fs/minix.c fs/sfs.c fs/ufs.c fs/xfs.c fs/hfsplus.c \
- fs/ntfs.c fs/ntfscomp.c \
+ fs/ntfs.c fs/ntfscomp.c fs/cpio.c \
io/gzio.c \
kern/device.c kern/disk.c kern/dl.c kern/elf.c kern/env.c \
kern/err.c \

conf/powerpc-ieee1275.rmk +0 -0
index eb440f1..af0773b 100644
@@ -62,7 +62,7 @@ grub_emu_SOURCES = commands/boot.c commands/cat.c

commands/cmp.c \
disk/loopback.c \
fs/affs.c fs/ext2.c fs/fat.c fs/fshelp.c fs/hfs.c fs/iso9660.c \
fs/jfs.c fs/minix.c fs/sfs.c fs/ufs.c fs/xfs.c fs/hfsplus.c \
- fs/ntfs.c fs/ntfscomp.c \
+ fs/ntfs.c fs/ntfscomp.c fs/cpio.c \
io/gzio.c \
kern/device.c kern/disk.c kern/dl.c kern/elf.c kern/env.c \
kern/err.c kern/file.c kern/fs.c kern/loader.c kern/main.c \

fs/cpio.c new file +348 -0

348 lines not on this page · raw message

Signature · 1 line
Bean
#4 lore raw
Quoted 6 lines · Bean
Quoted 3 lines · Robert Millan

Perhaps it'd be a good idea to move the arch-independant part of grub_emu_SOURCES to common.rmk (as grub_emu_SOURCES += foo), to avoid having to update all the files so often ...

yes, but i think it should be in a separate patch.

Agreed.

Quoted 7 lines
Quoted 3 lines

Btw, this line seems to be the same on both cases. It can be moved out of `if (data->mode == MODE_BCPIO)' to save some space?

In fact, it's not the same, in the first case, hd is of type HEAD_BCPIO, while in the second case, hd is of type HEAD_USTAR.The two structure has different size.

Ah, right.

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
fs/cpio.c new file +4 -0
+      if (hd.namesize & 1)
+        hd.namesize++;
[...]
+      if (data->size & 1)
+        (*ofs)++;
Quoted 6 lines
Quoted 3 lines

I find this confusing. AFAICT `hd.namesize == 1' would archieve the same and seems to be more consistent with your use of this variable as a counter.

When the name size is odd number, cpio pad another byte to make it word align, and the same apply to file size. However, I want to keep the original file size, so it use (*ofs)++ instead of data->size++.

Ok.

Quoted 18 lines
Quoted 2 lines

Are you sure these are still needed? We have a few modules that use them but AFAIK are not necessary at this time.

This is needed, the my_mod variable is used to stored the module pointer, and we need it to increase the module reference when a file is opened, so that the modules can't be unloaded.

Here is the new patch.

2007-12-24 Bean <[email protected]>

* conf/common.rmk (pkgdata_MODULES): Add cpio.mod. (cpio_mod_SOURCES): New variable. (cpio_mod_CFLAGS): Likewise. (cpio_mod_LDFLAGS): Likewise.

* fs/cpio.c: New file.

Quoted 7 lines

* conf/i386-pc.rmk (grub_emu_SOURCES): Add cpio.c.

* conf/i386-efi.rmk (grub_emu_SOURCES): Likewise.

* conf/i386-linuxbios.rmk (grub_emu_SOURCES): Likewise.

* conf/powerpc-ieee1275.rmk (grub_emu_SOURCES): Likewise.

Looks good to me. If nobody has any objection, I'll check this in.

Signature · 5 lines
Robert Millan

<GPLv2> I know my rights; I want my phone call!
<DRM> What use is a phone call, if you are unable to speak?
(as seen on /.)
#5 lore raw
Quoted 12 lines · Robert Millan
Quoted 12 lines

2007-12-24 Bean <[email protected]>

* conf/common.rmk (pkgdata_MODULES): Add cpio.mod. (cpio_mod_SOURCES): New variable. (cpio_mod_CFLAGS): Likewise. (cpio_mod_LDFLAGS): Likewise.

* fs/cpio.c: New file.

* conf/i386-pc.rmk (grub_emu_SOURCES): Add cpio.c.

Quoted 7 lines
Quoted 5 lines

* conf/i386-efi.rmk (grub_emu_SOURCES): Likewise.

* conf/i386-linuxbios.rmk (grub_emu_SOURCES): Likewise.

* conf/powerpc-ieee1275.rmk (grub_emu_SOURCES): Likewise.

Looks good to me. If nobody has any objection, I'll check this in.

Done.

Signature · 5 lines
Robert Millan

<GPLv2> I know my rights; I want my phone call!
<DRM> What use is a phone call, if you are unable to speak?
(as seen on /.)
#6 lore raw
In reply to Bean
Quoted 2 lines · Bean

I write a filesystem driver for cpio and tar archive file. now you can open the archive with loopback command:

Wow, you're fast! :-)

I don't know about tar/cpio file format, but I'm impressed about the small size of your code. How is it that the same code is used for both formats? Are they different enough that it'd be an advantage to make them separate modules?

Signature · 5 lines
Robert Millan

<GPLv2> I know my rights; I want my phone call!
<DRM> What use is a phone call, if you are unable to speak?
(as seen on /.)