2004-09-16 22:32:55

by Thayne Harbaugh

[permalink] [raw]
Subject: [PATCH] gen_init_cpio uses external file list

(Apologies to [email protected] for the re-send)

This patch makes gen_init_cpio generate the initramfs_data.cpio from a
file which contains a list of entries: file, dir, nod. I swapped the
order of filename/location for the file arguments so that it would be
more uniform with the dir and nod tyes.

[thayne@torch linux-2.6.8]$ usr/gen_init_cpio --help
ERROR: unable to open '--help': No such file or directory

Usage:
usr/gen_init_cpio <cpio_list>

<cpio_list> is a file containing newline separated entries that
describe the files to be included in the initramfs archive:

file <name> <location> <mode> <uid> <gid>
dir <name> <mode> <uid> <gid>
nod <name> <mode> <uid> <gid> <dev_type> <maj> <min>

<name> name of the file/dir/nod in the archive
<location> location of the file in the current filesystem
<mode> mode/permissions of the file
<uid> user id (0=root)
<gid> group id (0=root)
<dev_type> device type (b=block, c=character)
<maj> major number of nod
<min> minor number of nod

example:
dir /dev 0755 0 0
nod /dev/console 0600 0 0 c 5 1
dir /root 0700 0 0
dir /sbin 0755 0 0
file /sbin/kinit /usr/src/klibc/kinit/kinit 0755 0 0


Attachments:
cpio_list.patch (8.56 kB)

2004-09-16 23:15:39

by Jeff Garzik

[permalink] [raw]
Subject: Re: [PATCH] gen_init_cpio uses external file list

Seems OK to me...

Jeff, the original gen_init_cpio author



2004-09-16 23:14:16

by Thayne Harbaugh

[permalink] [raw]
Subject: Re: [PATCH] gen_init_cpio uses external file list

On Thu, 2004-09-16 at 19:06 -0400, Jeff Garzik wrote:
> Seems OK to me...
>
> Jeff, the original gen_init_cpio author

There's been some minor discussion about the use of _GNU_SOURCE (needed
for getline()). Comments? I can rework the getline() if anyone can
make a case - otherwise I'm a bit lazy.


2004-09-17 00:17:24

by Jeff Garzik

[permalink] [raw]
Subject: Re: [PATCH] gen_init_cpio uses external file list

Thayne Harbaugh wrote:
> On Thu, 2004-09-16 at 19:06 -0400, Jeff Garzik wrote:
>
>>Seems OK to me...
>>
>> Jeff, the original gen_init_cpio author
>
>
> There's been some minor discussion about the use of _GNU_SOURCE (needed
> for getline()). Comments? I can rework the getline() if anyone can
> make a case - otherwise I'm a bit lazy.


I am a bit leery of _GNU_SOURCE but whatever :)

2004-09-17 01:36:11

by H. Peter Anvin

[permalink] [raw]
Subject: Re: [klibc] Re: [PATCH] gen_init_cpio uses external file list

Jeff Garzik wrote:
> Thayne Harbaugh wrote:
>
>> On Thu, 2004-09-16 at 19:06 -0400, Jeff Garzik wrote:
>>
>>> Seems OK to me...
>>>
>>> Jeff, the original gen_init_cpio author
>>
>> There's been some minor discussion about the use of _GNU_SOURCE (needed
>> for getline()). Comments? I can rework the getline() if anyone can
>> make a case - otherwise I'm a bit lazy.
>
> I am a bit leery of _GNU_SOURCE but whatever :)
>

_GNU_SOURCE just means enable all features. Perhaps it should be
something more restrictive, like _XOPEN_SOURCE or _POSIX_SOURCE; both of
those need to be set to specific values.

-hpa

2004-09-17 04:48:38

by Sam Ravnborg

[permalink] [raw]
Subject: Re: [PATCH] gen_init_cpio uses external file list

On Thu, Sep 16, 2004 at 04:11:12PM -0600, Thayne Harbaugh wrote:
>
> This patch makes gen_init_cpio generate the initramfs_data.cpio from a
> file which contains a list of entries: file, dir, nod. I swapped the
> order of filename/location for the file arguments so that it would be
> more uniform with the dir and nod tyes.

Comments already given on klibc list by others, but repeated for lkml readers.

Helper programs like this shall be compatible with at least solaris & cygwin.
Therefore the linux only stuff needs to be avoided.

+ char name[PATH_MAX + 1];
> + unsigned int mode;
> + uid_t uid;
> + gid_t gid;
> + int rc = -1;
> +
> + if (4 != sscanf(line, "%" str(PATH_MAX) "s %o %d %d", name, &mode, &uid, &gid)) {
> + fprintf(stderr, "Unrecognized dir format '%s'", line);
> + goto fail;

Do we know that uid_t and gid_t equals an int here?
Use an int in the sscanf and do explicit type conversion later.


> + while (-1 != getline(&line, &line_sz, cpio_list)) {
> + int type_idx;

fgets() please.

Sam

2004-09-17 22:59:17

by Thayne Harbaugh

[permalink] [raw]
Subject: Re: [PATCH] gen_init_cpio uses external file list

On Fri, 2004-09-17 at 06:49 +0200, Sam Ravnborg wrote:
> On Thu, Sep 16, 2004 at 04:11:12PM -0600, Thayne Harbaugh wrote:
> >
> > This patch makes gen_init_cpio generate the initramfs_data.cpio from a
> > file which contains a list of entries: file, dir, nod. I swapped the
> > order of filename/location for the file arguments so that it would be
> > more uniform with the dir and nod tyes.
>
> Comments already given on klibc list by others, but repeated for lkml readers.
>
> Helper programs like this shall be compatible with at least solaris & cygwin.
> Therefore the linux only stuff needs to be avoided.

More correctly is GNU only stuff - but point taken. _GNU_SOURCE
removed.

> Do we know that uid_t and gid_t equals an int here?
> Use an int in the sscanf and do explicit type conversion later.

fixed.

> fgets() please.

fixed - although it's not as clean and flexible as what was there
(although more portable).

This newer patch also adds skipping of comments (initiated with #) and
blank lines.


Attachments:
cpio_list.3.patch (8.80 kB)

2004-09-23 22:47:15

by Martin Schlemmer

[permalink] [raw]
Subject: gen_initramfs_list.sh (was: Re: [PATCH] gen_init_cpio uses external file list) [u]

On Thu, 2004-09-16 at 16:11 -0600, Thayne Harbaugh wrote:

Hi

>
> This patch makes gen_init_cpio generate the initramfs_data.cpio from a
> file which contains a list of entries: file, dir, nod. I swapped the
> order of filename/location for the file arguments so that it would be
> more uniform with the dir and nod tyes.
>

Attached is a simple script to generate a suitable initramfs_list for
use with gen_init_cpio from an external initramfs source directory, that
could be added to scripts/ if anybody thinks its useful and without
issues. Note the the description at the top of the file might need
some work from somebody more 'literate' than me.

Sample run:

-----
nosferatu linux-2.6.9-rc2-bk7 # ../scripts/gen_initramfs_list.sh /usr/src/initramfs/src/
dir /bin 755 0 0
file /bin/umount /usr/src/initramfs/src/bin/umount 755 0 0
file /bin/sleep /usr/src/initramfs/src/bin/sleep 755 0 0
file /bin/fstype /usr/src/initramfs/src/bin/fstype 755 0 0
file /bin/chroot /usr/src/initramfs/src/bin/chroot 755 0 0
file /bin/dd /usr/src/initramfs/src/bin/dd 755 0 0
file /bin/minips /usr/src/initramfs/src/bin/minips 755 0 0
file /bin/mkdir /usr/src/initramfs/src/bin/mkdir 755 0 0
file /bin/mount /usr/src/initramfs/src/bin/mount 755 0 0
file /bin/ln /usr/src/initramfs/src/bin/ln 755 0 0
file /bin/true /usr/src/initramfs/src/bin/true 755 0 0
file /bin/sh /usr/src/initramfs/src/bin/sh 755 0 0
file /bin/nuke /usr/src/initramfs/src/bin/nuke 755 0 0
file /bin/mkfifo /usr/src/initramfs/src/bin/mkfifo 755 0 0
file /bin/false /usr/src/initramfs/src/bin/false 755 0 0
file /bin/printf /usr/src/initramfs/src/bin/printf 755 0 0
dir /proc 755 0 0
dir /dev 755 0 0
nod /dev/console 600 0 5 c 5 1
dir /etc 755 0 0
file /etc/dmtab /usr/src/initramfs/src/etc/dmtab 644 0 0
dir /etc/udev 755 0 0
file /etc/udev/udev.conf /usr/src/initramfs/src/etc/udev/udev.conf 644 0 0
dir /etc/udev/rules.d 755 0 0
file /etc/udev/rules.d/30-sda.rules /usr/src/initramfs/src/etc/udev/rules.d/30-sda.rules 644 0 0
file /etc/udev/rules.d/40-dm.rules /usr/src/initramfs/src/etc/udev/rules.d/40-dm.rules 644 0 0
file /init /usr/src/initramfs/src/init 755 0 0
dir /sbin 755 0 0
file /sbin/run-init /usr/src/initramfs/src/sbin/run-init 755 0 0
file /sbin/dmsetup /usr/src/initramfs/src/sbin/dmsetup 755 0 0
file /sbin/pivot_root /usr/src/initramfs/src/sbin/pivot_root 755 0 0
file /sbin/kpartx /usr/src/initramfs/src/sbin/kpartx 755 0 0
file /sbin/udev /usr/src/initramfs/src/sbin/udev 755 0 0
file /sbin/udevstart /usr/src/initramfs/src/sbin/udevstart 755 0 0
file /sbin/devmap_name /usr/src/initramfs/src/sbin/devmap_name 755 0 0
dir /sys 755 0 0
dir /rootfs 755 0 0
nosferatu linux-2.6.9-rc2-bk7 # ../scripts/gen_initramfs_list.sh /usr/src/initramfs/src/ > usr/initramfs_list
nosferatu linux-2.6.9-rc2-bk7 #
-----


Regards,

--
Martin Schlemmer


Attachments:
gen_initramfs_list.sh (1.60 kB)
signature.asc (189.00 B)
This is a digitally signed message part
Download all attachments