Don't write to /etc/mtab in newroot, may be an issue on read-only filesystems

This commit is contained in:
Erik van der Kouwe 2010-08-03 13:57:58 +00:00
parent 256c37f7fa
commit 4989de6acc
3 changed files with 8 additions and 4 deletions

View file

@ -26,12 +26,13 @@ int main(argc, argv)
int argc;
char *argv[];
{
int i, n, v = 0, mountflags;
int i, n, v = 0, mountflags, write_mtab;
char **ap, *vs, *opt, *err, *type, *args, *device;
char special[PATH_MAX+1], mounted_on[PATH_MAX+1], version[10], rw_flag[10];
if (argc == 1) list(); /* just list /etc/mtab */
mountflags = 0;
write_mtab = 1;
type = NULL;
args = NULL;
ap = argv+1;
@ -43,7 +44,8 @@ char *argv[];
case 't': if (++i == argc) usage();
type = argv[i];
break;
case 'i': mountflags |= MS_REUSE; break;
case 'i': mountflags |= MS_REUSE; break;
case 'n': write_mtab = 0; break;
case 'o': if (++i == argc) usage();
args = argv[i];
break;
@ -82,8 +84,9 @@ char *argv[];
/* The mount has completed successfully. Tell the user. */
printf("%s is read-%s mounted on %s\n",
argv[1], mountflags & MS_RDONLY ? "only" : "write", argv[2]);
/* Update /etc/mtab. */
if (!write_mtab) return 0;
n = load_mtab("mount");
if (n < 0) exit(1); /* something is wrong. */

View file

@ -1,5 +1,5 @@
#!/bin/sh
# Actually, newroot is just like mounting on the root
exec mount "$*" /
exec mount -n "$*" /

View file

@ -17,6 +17,7 @@ mount \- mount a file system
.SH OPTIONS
.FL "\-r" "File system is mounted read-only"
.FL "\-t" "File system type"
.FL "\-n" "Don't update mtab"
.FL "\-o" "Options passed to FS server"
.SH EXAMPLES
.EX "mount /dev/fd1 /user" "Mount diskette 1 on \fI/user\fP"