Skip to contentSkip to conversation

gen_init_cpio-slink_pipe_sock

PATCH In review Thayne Harbaugh 2 participants 4 messages Nov 12, 2004 – Nov 15, 2004

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gen_init_cpio-slink_pipe_sock

This patch makes gen_init_cpio more complete by adding symlink, pipe and socket support. It updates scripts/gen_initramfs_list.sh to support the new types. The patch applies to the recent mm series that already have the updated gen_init_cpio and gen_initramfs_list.sh.

Signature · 2 lines
Thayne Harbaugh
Linux Networx
Documentation/early-userspace/README +15 -7
diff -ur linux-2.6.10-rc1.orig/Documentation/early-userspace/README linux-2.6.10-rc1/Documentation/early-userspace/README
@@ -1,7 +1,7 @@
 Early userspace support
 =======================
 
-Last update: 2003-08-21
+Last update: 2004-11-12
 
 
 "Early userspace" is a set of libraries and programs that provide
@@ -17,14 +17,22 @@
 - initramfs, a chunk of code that unpacks the compressed cpio image
   midway through the kernel boot process.
 - klibc, a userspace C library, currently packaged separately, that is
-  optimised for correctness and small size.
+  optimized for correctness and small size.
 
 The cpio file format used by initramfs is the "newc" (aka "cpio -c")
-format, and is documented in the file "buffer-format.txt".  If you
-want to generate your own cpio files directly instead of hacking on
-gen_init_cpio, you will need to short-circuit the build process in
-usr/ so that gen_init_cpio does not get run, then simply pop your own
-initramfs_data.cpio.gz file into place.
+format, and is documented in the file "buffer-format.txt".  There are
+three ways to add an early userspace filesystem:
+
+1) Put your gzip'ed cpio in usr/initramfs_data.cpio.gz.
+
+2) Set CONFIG_INITRAMFS_SOURCE to the filename of a gen_init_cpio
+input file.  This provides the most flexibility and allows creation of
+archives with files not owned by the build user.  This means that an
+unprivileged user can create an early userspace with files owned by
+root.
+
+3) Set CONFIG_INITRAMFS_SOURCE to point to a directory containing the
+files for your filesystem.
 
 
 Where's this all leading?
drivers/block/Kconfig +5 -1
diff -ur linux-2.6.10-rc1.orig/drivers/block/Kconfig linux-2.6.10-rc1/drivers/block/Kconfig
@@ -363,10 +363,14 @@
 	    file <name> <location> <mode> <uid> <gid>
 	    dir <name> <mode> <uid> <gid>
 	    nod <name> <mode> <uid> <gid> <dev_type> <maj> <min>
+	    slink <name> <target> <mode> <uid> <gid>
+	    pipe <name> <mode> <uid> <gid>
+	    sock <name> <mode> <uid> <gid>
 
 	  Where:
-	    <name>      name of the file/dir/nod in the archive
+	    <name>      name of the file/dir/nod/etc in the archive
 	    <location>  location of the file in the current filesystem
+	    <target>    link target
 	    <mode>      mode/permissions of the file
 	    <uid>       user id (0=root)
 	    <gid>       group id (0=root)
scripts/gen_initramfs_list.sh +15 -3
diff -ur linux-2.6.10-rc1.orig/scripts/gen_initramfs_list.sh linux-2.6.10-rc1/scripts/gen_initramfs_list.sh
@@ -9,8 +9,6 @@
 #
 # The output is suitable for gen_init_cpio as found in usr/Makefile.
 #
-# TODO:  Add support for symlinks, sockets and pipes when gen_init_cpio
-#        supports them.
 
 simple_initramfs() {
 	cat <<-EOF
@@ -25,12 +23,19 @@
 filetype() {
 	local argv1="$1"
 
-	if [ -f "${argv1}" ]; then
+	# symlink test must come before file test
+	if [ -L "${argv1}" ]; then
+		echo "slink"
+	elif [ -f "${argv1}" ]; then
 		echo "file"
 	elif [ -d "${argv1}" ]; then
 		echo "dir"
 	elif [ -b "${argv1}" -o -c "${argv1}" ]; then
 		echo "nod"
+	elif [ -p "${argv1}" ]; then
+		echo "pipe"
+	elif [ -S "${argv1}" ]; then
+		echo "sock"
 	else
 		echo "invalid"
 	fi
@@ -52,6 +57,8 @@
 parse() {
 	local location="$1"
 	local name="${location/${srcdir}//}"
+	# change '//' into '/'
+	name="${name//\/\///}"
 	local mode="$2"
 	local uid="$3"
 	local gid="$4"
@@ -79,6 +86,11 @@
 			fi
 			str="${ftype} ${name} ${str} ${dev_type} ${maj} ${min}"
 			;;
+		"slink")
+			local target=$(LC_ALL=C ls -l "${location}" | \
+					gawk '{print $11}')
+			str="${ftype} ${name} ${target} ${str}"
+			;;
 		*)
 			str="${ftype} ${name} ${str}"
 			;;
usr/gen_init_cpio.c +123 -13

213 lines not on this page · raw message

#1 lore raw
Quoted 9 lines · Thayne Harbaugh

diff -ur linux-2.6.10-rc1.orig/drivers/block/Kconfig linux-2.6.10-rc1/drivers/block/Kconfig

drivers/block/Kconfig +2 -0
@@ -363,10 +363,14 @@
 	    file <name> <location> <mode> <uid> <gid>
 	    dir <name> <mode> <uid> <gid>
 	    nod <name> <mode> <uid> <gid> <dev_type> <maj> <min>
+	    slink <name> <target> <mode> <uid> <gid>
+	    pipe <name> <mode> <uid> <gid>

drivers/block/Kconfig line 376

Quoted 10 lines
drivers/block/Kconfig +3 -1
+	    sock <name> <mode> <uid> <gid>
 
 	  Where:
-	    <name>      name of the file/dir/nod in the archive
+	    <name>      name of the file/dir/nod/etc in the archive
 	    <location>  location of the file in the current filesystem
+	    <target>    link target
 	    <mode>      mode/permissions of the file
 	    <uid>       user id (0=root)
 	    <gid>       group id (0=root)

This info should get moved out of Kconfig, and into a Documentation/* text file somewhere.

Quoted 2 lines

+/*
+ * Original work by Jeff Garzick

Please spell my last name correctly :)

#2 lore raw
Quoted 12 lines · Jeff Garzik
Quoted 11 lines · Thayne Harbaugh

diff -ur linux-2.6.10-rc1.orig/drivers/block/Kconfig linux-2.6.10-rc1/drivers/block/Kconfig

drivers/block/Kconfig +3 -0
@@ -363,10 +363,14 @@
 	    file <name> <location> <mode> <uid> <gid>
 	    dir <name> <mode> <uid> <gid>
 	    nod <name> <mode> <uid> <gid> <dev_type> <maj> <min>
+	    slink <name> <target> <mode> <uid> <gid>
+	    pipe <name> <mode> <uid> <gid>
+	    sock <name> <mode> <uid> <gid>
 
Quoted 11 lines

drivers/block/Kconfig line 376

Quoted 8 lines
drivers/block/Kconfig +2 -1
 	  Where:
-	    <name>      name of the file/dir/nod in the archive
+	    <name>      name of the file/dir/nod/etc in the archive
 	    <location>  location of the file in the current filesystem
+	    <target>    link target
 	    <mode>      mode/permissions of the file
 	    <uid>       user id (0=root)
 	    <gid>       group id (0=root)

This info should get moved out of Kconfig, and into a Documentation/* text file somewhere.

It's actually redundant with the gen_init_cpio help output. It could be removed from the Kconfig and put in Documentation/early-userspace/README if someone still wants it someplace other than the gen_init_cpio help output.

Quoted 4 lines
Quoted 2 lines

+/*
+ * Original work by Jeff Garzick

Please spell my last name correctly :)

I did - you're the one that spells it incorrectly! B^)

Makes me wonder how I got your email correct since I typed that from memory . . ..

Signature · 2 lines
Thayne Harbaugh
Linux Networx
#3 lore raw
In reply to Jeff Garzik

I didn't see any comments other than these by Jeff. Here's a new patch with the following modifications:

Quoted 12 lines · Jeff Garzik
Quoted 11 lines · Thayne Harbaugh

diff -ur linux-2.6.10-rc1.orig/drivers/block/Kconfig linux-2.6.10-rc1/drivers/block/Kconfig

drivers/block/Kconfig +3 -0
@@ -363,10 +363,14 @@
 	    file <name> <location> <mode> <uid> <gid>
 	    dir <name> <mode> <uid> <gid>
 	    nod <name> <mode> <uid> <gid> <dev_type> <maj> <min>
+	    slink <name> <target> <mode> <uid> <gid>
+	    pipe <name> <mode> <uid> <gid>
+	    sock <name> <mode> <uid> <gid>
 
Quoted 11 lines

drivers/block/Kconfig line 376

Quoted 8 lines
drivers/block/Kconfig +2 -1
 	  Where:
-	    <name>      name of the file/dir/nod in the archive
+	    <name>      name of the file/dir/nod/etc in the archive
 	    <location>  location of the file in the current filesystem
+	    <target>    link target
 	    <mode>      mode/permissions of the file
 	    <uid>       user id (0=root)
 	    <gid>       group id (0=root)

This info should get moved out of Kconfig, and into a Documentation/* text file somewhere.

Now Kconfig and Documentation/early-userspace/README reference the usage output of usr/gen_init_cpio instead of reproducing the file format information. This way there is no redundant information that gets out of synch. The drawback is that usr/gen_init_cpio has to be built before it can be run to obtain the usage information.

Quoted 4 lines
Quoted 2 lines

+/*
+ * Original work by Jeff Garzick

Please spell my last name correctly :)

Jeff refused to change his name to my new spelling so I have reluctantly altered the comment so that it reads "Original work by Jeff Garzik" (sic.). :)

Signature · 2 lines
Thayne Harbaugh
Linux Networx
Documentation/early-userspace/README +15 -7
diff -ur linux-2.6.10-rc1.orig/Documentation/early-userspace/README linux-2.6.10-rc1/Documentation/early-userspace/README
@@ -1,7 +1,7 @@
 Early userspace support
 =======================
 
-Last update: 2003-08-21
+Last update: 2004-11-12
 
 
 "Early userspace" is a set of libraries and programs that provide
@@ -17,14 +17,22 @@
 - initramfs, a chunk of code that unpacks the compressed cpio image
   midway through the kernel boot process.
 - klibc, a userspace C library, currently packaged separately, that is
-  optimised for correctness and small size.
+  optimized for correctness and small size.
 
 The cpio file format used by initramfs is the "newc" (aka "cpio -c")
-format, and is documented in the file "buffer-format.txt".  If you
-want to generate your own cpio files directly instead of hacking on
-gen_init_cpio, you will need to short-circuit the build process in
-usr/ so that gen_init_cpio does not get run, then simply pop your own
-initramfs_data.cpio.gz file into place.
+format, and is documented in the file "buffer-format.txt".  There are
+three ways to add an early userspace filesystem:
+
+1) Put your gzip'ed cpio in usr/initramfs_data.cpio.gz.
+
+2) Set CONFIG_INITRAMFS_SOURCE to the filename of a gen_init_cpio
+input file.  This provides the most flexibility and allows creation of
+archives with files not owned by the build user.  This means that an
+unprivileged user can create an early userspace with files owned by
+root.
+
+3) Set CONFIG_INITRAMFS_SOURCE to point to a directory containing the
+files for your filesystem.
 
 
 Where's this all leading?
drivers/block/Kconfig +3 -18
diff -ur linux-2.6.10-rc1.orig/drivers/block/Kconfig linux-2.6.10-rc1/drivers/block/Kconfig
@@ -355,24 +355,9 @@
 	default ""
 	help
 	  This can be set to either a directory containing files, etc to be
-	  included in the initramfs archive, or a file containing newline
-	  separated entries.
-
-	  If it is a file, it should be in the following format:
-	    # a comment
-	    file <name> <location> <mode> <uid> <gid>
-	    dir <name> <mode> <uid> <gid>
-	    nod <name> <mode> <uid> <gid> <dev_type> <maj> <min>
-
-	  Where:
-	    <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
+	  included in the initramfs archive, or a file containing  entries
+	  according to the format described by the "usr/gen_init_cpio"
+	  program in the kernel tree.
 
 	  If you are not sure, leave it blank.
 
scripts/gen_initramfs_list.sh +15 -3
diff -ur linux-2.6.10-rc1.orig/scripts/gen_initramfs_list.sh linux-2.6.10-rc1/scripts/gen_initramfs_list.sh
@@ -9,8 +9,6 @@
 #
 # The output is suitable for gen_init_cpio as found in usr/Makefile.
 #
-# TODO:  Add support for symlinks, sockets and pipes when gen_init_cpio
-#        supports them.
 
 simple_initramfs() {
 	cat <<-EOF
@@ -25,12 +23,19 @@
 filetype() {
 	local argv1="$1"
 
-	if [ -f "${argv1}" ]; then
+	# symlink test must come before file test
+	if [ -L "${argv1}" ]; then
+		echo "slink"
+	elif [ -f "${argv1}" ]; then
 		echo "file"
 	elif [ -d "${argv1}" ]; then
 		echo "dir"
 	elif [ -b "${argv1}" -o -c "${argv1}" ]; then
 		echo "nod"
+	elif [ -p "${argv1}" ]; then
+		echo "pipe"
+	elif [ -S "${argv1}" ]; then
+		echo "sock"
 	else
 		echo "invalid"
 	fi
@@ -52,6 +57,8 @@
 parse() {
 	local location="$1"
 	local name="${location/${srcdir}//}"
+	# change '//' into '/'
+	name="${name//\/\///}"
 	local mode="$2"
 	local uid="$3"
 	local gid="$4"
@@ -79,6 +86,11 @@
 			fi
 			str="${ftype} ${name} ${str} ${dev_type} ${maj} ${min}"
 			;;
+		"slink")
+			local target=$(LC_ALL=C ls -l "${location}" | \
+					gawk '{print $11}')
+			str="${ftype} ${name} ${target} ${str}"
+			;;
 		*)
 			str="${ftype} ${name} ${str}"
 			;;
usr/gen_init_cpio.c +123 -13

213 lines not on this page · raw message