Patch for configuring root device read-only

Todd J Derr (infidel+@pitt.edu)
Thu, 6 Jul 1995 22:27:06 -0400 (EDT)


Linus: can you put this in for the next 1.3? It's just a small patch to
allow setting the root dev to read-only from the top level makefile.

The patch is pretty small, it looks big since I re-indented the root
device parsing code. It basically just passes another (optional) flag to
tools/build, either READ_ONLY or READ_WRITE. I pass this before the
root device in the makefile because the code is a little simpler that
way. However, if we add more options like this, things are going to get
messy in a hurry, and probably have to be changed. If it doesn't see
READ_ONLY or READ_WRITE, it just passes it along to the rootdev code.

The other architectures makefiles don't seem to use ROOT_DEV at all, so
I didn't bother with anything other than x86.

todd.

PS. if you'd rather, you can ftp this patch from:
ftp.pitt.edu:/users/i/n/infidel/linux/rootdev-1.3.6.diff

------------------------------------------------------------------------
diff -u --recursive linux-1.3.6/Makefile linux/Makefile
--- linux-1.3.6/Makefile Thu Jul 6 21:58:28 1995
+++ linux/Makefile Thu Jul 6 21:58:28 1995
@@ -49,6 +49,12 @@

ROOT_DEV = CURRENT

+# ROOT_DEV_MOUNT specifies whether the root device should be mounted
+# read-only at boot. This must be either READ_WRITE, READ_ONLY, or empty,
+# in which case the default of READ_WRITE is used by 'build'.
+
+ROOT_DEV_MOUNT = READ_WRITE
+
#
# INSTALL_PATH specifies where to place the updated kernel and system map
# images. Uncomment if you want to place them anywhere other than root.
diff -u --recursive linux-1.3.6/arch/i386/boot/Makefile linux/arch/i386/boot/Makefile
--- linux-1.3.6/arch/i386/boot/Makefile Thu Jul 6 21:59:02 1995
+++ linux/arch/i386/boot/Makefile Thu Jul 6 21:59:02 1995
@@ -18,9 +18,9 @@
zImage: $(CONFIGURE) bootsect setup compressed/vmlinux tools/build
ifdef CONFIG_KERNEL_ELF
$(OBJDUMP) $(OBJDUMP_FLAGS) -o $(ZIMAGE_OFFSET) compressed/vmlinux > compressed/vmlinux.out
- tools/build bootsect setup compressed/vmlinux.out $(ROOT_DEV) > zImage
+ tools/build bootsect setup compressed/vmlinux.out $(ROOT_DEV_MOUNT) $(ROOT_DEV) > zImage
else
- tools/build bootsect setup compressed/vmlinux $(ROOT_DEV) > zImage
+ tools/build bootsect setup compressed/vmlinux $(ROOT_DEV_MOUNT) $(ROOT_DEV) > zImage
endif
sync

diff -u --recursive linux-1.3.6/arch/i386/boot/tools/build.c linux/arch/i386/boot/tools/build.c
--- linux-1.3.6/arch/i386/boot/tools/build.c Thu Jul 6 21:58:58 1995
+++ linux/arch/i386/boot/tools/build.c Thu Jul 6 21:58:58 1995
@@ -18,6 +18,7 @@

/*
* Changes by tytso to allow root device specification
+ * Changes by tjd@barefoot.org to allow read-only root device.
*/

#include <stdio.h> /* fprintf */
@@ -43,6 +44,7 @@

#define DEFAULT_MAJOR_ROOT 0
#define DEFAULT_MINOR_ROOT 0
+#define DEFAULT_MOUNT_FLAG 0

/* max nr of sectors of setup: don't change unless you also change
* bootsect etc */
@@ -84,7 +86,7 @@

void usage(void)
{
- die("Usage: build bootsect setup system [rootdev] [> image]");
+ die("Usage: build bootsect setup system [mountflag] [rootdev] [> image]");
}

int main(int argc, char ** argv)
@@ -95,36 +97,58 @@
#ifndef __BFD__
struct exec *ex = (struct exec *)buf;
#endif
- char major_root, minor_root;
+ char major_root, minor_root, mount_flag;
struct stat sb;
unsigned char setup_sectors;
+ int dev_argv;

- if ((argc < 4) || (argc > 5))
+ if ((argc < 4) || (argc > 6))
usage();
if (argc > 4) {
- if (!strcmp(argv[4], "CURRENT")) {
- if (stat("/", &sb)) {
- perror("/");
- die("Couldn't stat /");
- }
- major_root = major(sb.st_dev);
- minor_root = minor(sb.st_dev);
- } else if (strcmp(argv[4], "FLOPPY")) {
- if (stat(argv[4], &sb)) {
- perror(argv[4]);
- die("Couldn't stat root device.");
+ dev_argv=5;
+ if(!strcmp(argv[4],"READ_WRITE")) {
+ mount_flag=0;
+ } else if(!strcmp(argv[4],"READ_ONLY")) {
+ mount_flag=1;
+ } else {
+ mount_flag=DEFAULT_MOUNT_FLAG;
+ dev_argv=4;
+ if(argc > dev_argv+1)
+ usage();
+ }
+ if(argc > dev_argv)
+ {
+ if (!strcmp(argv[dev_argv], "CURRENT")) {
+ if (stat("/", &sb)) {
+ perror("/");
+ die("Couldn't stat /");
+ }
+ major_root = major(sb.st_dev);
+ minor_root = minor(sb.st_dev);
+ } else if (strcmp(argv[dev_argv], "FLOPPY")) {
+ if (stat(argv[4], &sb)) {
+ perror(argv[dev_argv]);
+ die("Couldn't stat root device.");
+ }
+ major_root = major(sb.st_rdev);
+ minor_root = minor(sb.st_rdev);
+ } else {
+ major_root = 0;
+ minor_root = 0;
}
- major_root = major(sb.st_rdev);
- minor_root = minor(sb.st_rdev);
} else {
- major_root = 0;
- minor_root = 0;
+ major_root = DEFAULT_MAJOR_ROOT;
+ minor_root = DEFAULT_MINOR_ROOT;
}
} else {
major_root = DEFAULT_MAJOR_ROOT;
minor_root = DEFAULT_MINOR_ROOT;
+ mount_flag = DEFAULT_MOUNT_FLAG;
}
- fprintf(stderr, "Root device is (%d, %d)\n", major_root, minor_root);
+
+ fprintf(stderr, "Root device is (%d, %d) [%s]\n",
+ major_root, minor_root,
+ (mount_flag ? "read-only" : "read-write"));
for (i=0;i<sizeof buf; i++) buf[i]=0;
if ((id=open(argv[1],O_RDONLY,0))<0)
die("Unable to open 'boot'");
@@ -148,6 +172,7 @@
die("Boot block must be exactly 512 bytes");
if ((*(unsigned short *)(buf+510)) != (unsigned short)intel_short(0xAA55))
die("Boot block hasn't got boot flag (0xAA55)");
+ buf[498] = (char) mount_flag;
buf[508] = (char) minor_root;
buf[509] = (char) major_root;
i=write(1,buf,512);