support in 'mount' for specifying file system type and options

This commit is contained in:
David van Moolenbroek 2009-05-13 15:39:44 +00:00
parent 3affa4c796
commit fe8c612aa4
7 changed files with 102 additions and 36 deletions

View file

@ -294,7 +294,7 @@ char *argv[];
} }
/* Mount device. This call may fail. */ /* Mount device. This call may fail. */
mount(dev_name, dir_name, 0); mount(dev_name, dir_name, 0, NULL, NULL);
/* Succes. dev was mounted, try to umount */ /* Succes. dev was mounted, try to umount */
/* Umount device. Playing with the file system while other processes /* Umount device. Playing with the file system while other processes
@ -309,7 +309,7 @@ char *argv[];
strcat(file_name, "/"); strcat(file_name, "/");
strcat(file_name, f_name); strcat(file_name, f_name);
if (mount(dev_name, dir_name, 0) == -1) { /* this call should work */ if (mount(dev_name, dir_name, 0, NULL, NULL) == -1) { /* this call should work */
fprintf(stderr, "Could not mount device anymore\n"); fprintf(stderr, "Could not mount device anymore\n");
done(HARMLESS); done(HARMLESS);
} }

View file

@ -16,6 +16,8 @@
#include <stdio.h> #include <stdio.h>
#include "../../servers/mfs/const.h" #include "../../servers/mfs/const.h"
#define MINIX_FS_TYPE "mfs"
_PROTOTYPE(int main, (int argc, char **argv)); _PROTOTYPE(int main, (int argc, char **argv));
_PROTOTYPE(void list, (void)); _PROTOTYPE(void list, (void));
_PROTOTYPE(void usage, (void)); _PROTOTYPE(void usage, (void));
@ -29,12 +31,14 @@ int argc;
char *argv[]; char *argv[];
{ {
int i, ro, swap, n, v; int i, ro, swap, n, v;
char **ap, *vs, *opt, *err; char **ap, *vs, *opt, *err, *type, *args;
char special[PATH_MAX+1], mounted_on[PATH_MAX+1], version[10], rw_flag[10]; char special[PATH_MAX+1], mounted_on[PATH_MAX+1], version[10], rw_flag[10];
if (argc == 1) list(); /* just list /etc/mtab */ if (argc == 1) list(); /* just list /etc/mtab */
ro = 0; ro = 0;
swap = 0; swap = 0;
type = NULL;
args = NULL;
ap = argv+1; ap = argv+1;
for (i = 1; i < argc; i++) { for (i = 1; i < argc; i++) {
if (argv[i][0] == '-') { if (argv[i][0] == '-') {
@ -42,6 +46,12 @@ char *argv[];
while (*opt != 0) switch (*opt++) { while (*opt != 0) switch (*opt++) {
case 'r': ro = 1; break; case 'r': ro = 1; break;
case 's': swap = 1; break; case 's': swap = 1; break;
case 't': if (++i == argc) usage();
type = argv[i];
break;
case 'o': if (++i == argc) usage();
args = argv[i];
break;
default: usage(); default: usage();
} }
} else { } else {
@ -60,7 +70,7 @@ char *argv[];
tell(" is swapspace\n"); tell(" is swapspace\n");
} else { } else {
if (argc != 3) usage(); if (argc != 3) usage();
if (mount(argv[1], argv[2], ro) < 0) { if (mount(argv[1], argv[2], ro, type, args) < 0) {
err = strerror(errno); err = strerror(errno);
std_err("mount: Can't mount "); std_err("mount: Can't mount ");
std_err(argv[1]); std_err(argv[1]);
@ -97,6 +107,8 @@ char *argv[];
if (swap) { if (swap) {
vs = "swap"; vs = "swap";
} else { } else {
/* For MFS, use a version number. Otherwise, use the FS type name. */
if (type == NULL || !strcmp(type, MINIX_FS_TYPE)) {
v = fsversion(argv[1], "mount"); v = fsversion(argv[1], "mount");
if (v == 1) if (v == 1)
vs = "1"; vs = "1";
@ -106,6 +118,13 @@ char *argv[];
vs = "3"; vs = "3";
else else
vs = "0"; vs = "0";
} else {
/* Keep the version field sufficiently short. */
if (strlen(type) < sizeof(version))
vs = type;
else
vs = "-";
}
} }
n = put_mtab_entry(argv[1], swap ? "swap" : argv[2], vs, (ro ? "ro" : "rw") ); n = put_mtab_entry(argv[1], swap ? "swap" : argv[2], vs, (ro ? "ro" : "rw") );
if (n < 0) { if (n < 0) {
@ -147,7 +166,8 @@ void list()
void usage() void usage()
{ {
std_err("Usage: mount [-r] special name\n mount -s special\n"); std_err("Usage: mount [-r] [-t type] [-o options] special name\n"
" mount -s special\n");
exit(1); exit(1);
} }

View file

@ -21,7 +21,7 @@ int main(int argc, char *argv[])
exit(1); exit(1);
} }
dev= argv[1]; dev= argv[1];
r= mount(dev, "/", 0 /* !ro */); r= mount(dev, "/", 0 /* !ro */, NULL, NULL);
if (r != 0) if (r != 0)
{ {
fprintf(stderr, "newroot: mount failed: %s\n", strerror(errno)); fprintf(stderr, "newroot: mount failed: %s\n", strerror(errno));

View file

@ -171,7 +171,8 @@ _PROTOTYPE( int mknod, (const char *_name, _mnx_Mode_t _mode, Dev_t _addr) );
_PROTOTYPE( int mknod4, (const char *_name, _mnx_Mode_t _mode, Dev_t _addr, _PROTOTYPE( int mknod4, (const char *_name, _mnx_Mode_t _mode, Dev_t _addr,
long _size) ); long _size) );
_PROTOTYPE( char *mktemp, (char *_template) ); _PROTOTYPE( char *mktemp, (char *_template) );
_PROTOTYPE( int mount, (char *_spec, char *_name, int _flag) ); _PROTOTYPE( int mount, (char *_spec, char *_name, int _flag,
char *type, char *args) );
_PROTOTYPE( long ptrace, (int _req, pid_t _pid, long _addr, long _data) ); _PROTOTYPE( long ptrace, (int _req, pid_t _pid, long _addr, long _data) );
_PROTOTYPE( char *sbrk, (int _incr) ); _PROTOTYPE( char *sbrk, (int _incr) );
_PROTOTYPE( int sync, (void) ); _PROTOTYPE( int sync, (void) );

View file

@ -12,8 +12,8 @@
#include <minix/paths.h> #include <minix/paths.h>
#define OK 0 #define OK 0
#define MFSNAME "mfs" #define FSPATH "/sbin/"
#define MFSPATH "/sbin/" #define FSDEFAULT "mfs"
PRIVATE int rs_down(char *label) PRIVATE int rs_down(char *label)
{ {
@ -21,7 +21,7 @@ PRIVATE int rs_down(char *label)
message m; message m;
if(strlen(_PATH_SERVICE)+strlen(label)+50 >= sizeof(cmd)) if(strlen(_PATH_SERVICE)+strlen(label)+50 >= sizeof(cmd))
return -1; return -1;
sprintf(cmd, _PATH_SERVICE " down %s", label); sprintf(cmd, _PATH_SERVICE " down '%s'", label);
return system(cmd); return system(cmd);
} }
@ -34,39 +34,68 @@ PRIVATE char *makelabel(_CONST char *special)
dev = strrchr(special, '/'); dev = strrchr(special, '/');
if(dev) dev++; if(dev) dev++;
else dev = special; else dev = special;
if(strlen(dev)+strlen(MFSNAME)+3 >= sizeof(label)) if(strchr(dev, '\'') != NULL) {
errno = EINVAL;
return NULL; return NULL;
sprintf(label, MFSNAME "_%s", dev); }
if(strlen(dev)+4 >= sizeof(label)) {
errno = E2BIG;
return NULL;
}
sprintf(label, "fs_%s", dev);
return label; return label;
} }
PUBLIC int mount(special, name, rwflag) PUBLIC int mount(special, name, rwflag, type, args)
char *name, *special; char *name, *special, *type, *args;
int rwflag; int rwflag;
{ {
int r; int r;
message m; message m;
struct rs_start rs_start; struct rs_start rs_start;
struct stat statbuf;
char *label; char *label;
char path[60];
char cmd[200]; char cmd[200];
FILE *pipe; FILE *pipe;
int ep; int ep;
/* Make MFS process label for RS from special name. */ /* Default values. */
if (type == NULL) type = FSDEFAULT;
if (args == NULL) args = "";
/* Make FS process label for RS from special name. */
if(!(label=makelabel(special))) { if(!(label=makelabel(special))) {
return -1;
}
/* See if the given type is even remotely valid. */
if(strlen(FSPATH)+strlen(type) >= sizeof(path)) {
errno = E2BIG;
return -1;
}
strcpy(path, FSPATH);
strcat(path, type);
if(stat(path, &statbuf) != 0) {
errno = EINVAL;
return -1;
}
/* Sanity check on user input. */
if(strchr(args, '\'')) {
errno = EINVAL;
return -1;
}
if(strlen(_PATH_SERVICE)+strlen(path)+strlen(label)+
strlen(_PATH_DRIVERS_CONF)+strlen(args)+50 >= sizeof(cmd)) {
errno = E2BIG; errno = E2BIG;
return -1; return -1;
} }
if(strlen(_PATH_SERVICE)+strlen(MFSPATH)+strlen(MFSNAME)+ sprintf(cmd, _PATH_SERVICE " up %s -label '%s' -config " _PATH_DRIVERS_CONF
strlen(label)+50 >= sizeof(cmd)) { " -args '%s%s' -printep yes",
errno = E2BIG; path, label, args[0] ? "-o " : "", args);
return -1;
}
sprintf(cmd, _PATH_SERVICE " up " MFSPATH MFSNAME
" -label \"%s\" -config " _PATH_DRIVERS_CONF " -printep yes",
label);
if(!(pipe = popen(cmd, "r"))) { if(!(pipe = popen(cmd, "r"))) {
fprintf(stderr, "mount: couldn't run %s\n", cmd); fprintf(stderr, "mount: couldn't run %s\n", cmd);
@ -108,7 +137,6 @@ _CONST char *name;
/* Make MFS process label for RS from special name. */ /* Make MFS process label for RS from special name. */
if(!(label=makelabel(name))) { if(!(label=makelabel(name))) {
errno = E2BIG;
return -1; return -1;
} }

View file

@ -2,7 +2,7 @@
.SH NAME .SH NAME
mount \- mount a file system mount \- mount a file system
.SH SYNOPSIS .SH SYNOPSIS
\fBmount [\fB\-r\fR] \fIspecial \fIfile\fR \fBmount [\fB\-r\fR] [\fB\-t \fItype\fR] [\fB\-o \fIoptions\fR] \fIspecial \fIfile\fR
.br .br
\fBmount [\fB\-s\fR] \fIswapfile\fR \fBmount [\fB\-s\fR] \fIswapfile\fR
.br .br
@ -18,6 +18,8 @@ mount \- mount a file system
.. ..
.SH OPTIONS .SH OPTIONS
.FL "\-r" "File system is mounted read-only" .FL "\-r" "File system is mounted read-only"
.FL "\-t" "File system type"
.FL "\-o" "Options passed to FS server"
.FL "\-s" "Mount swap space" .FL "\-s" "Mount swap space"
.SH EXAMPLES .SH EXAMPLES
.EX "mount /dev/fd1 /user" "Mount diskette 1 on \fI/user\fP" .EX "mount /dev/fd1 /user" "Mount diskette 1 on \fI/user\fP"
@ -31,6 +33,14 @@ after the mount.
When the file system is no longer needed, it must be unmounted before being When the file system is no longer needed, it must be unmounted before being
removed from the drive. removed from the drive.
.PP .PP
The
.B \-t
parameter may be used to mount a file system of a type other than the default.
The
.B \-o
flag may be used to pass options to the file system server.
The interpretation of these options is up to the server.
.PP
With the With the
.B \-s .B \-s
flag a device or file is mounted as swap space. flag a device or file is mounted as swap space.

View file

@ -7,7 +7,7 @@ mount, umount \- mount or umount a file system
#include <unistd.h> #include <unistd.h>
#include <sys/mount.h> #include <sys/mount.h>
int mount(char *\fIspecial\fP, char *\fIname\fP, int \fIflag\fP) int mount(char *\fIspecial\fP, char *\fIname\fP, int \fIflag\fP, char *\fItype\fP, char *\fIargs\fP)
int umount(char *\fIname\fP) int umount(char *\fIname\fP)
.fi .fi
.ft P .ft P
@ -34,6 +34,13 @@ mounts a normal file or directory is used for
which must be seen as the root of a virtual device. which must be seen as the root of a virtual device.
.I Flag .I Flag
is 0 for a read-write mount, 1 for read-only. is 0 for a read-write mount, 1 for read-only.
.I Type
is the type of the file system (e.g. "mfs"), used to pick a file system server.
If this parameter is NULL, the default type is used.
.I Args
is a string with arguments passed to the file system server.
Their interpretation is up to the server.
This parameter may be NULL as well.
.PP .PP
.B Umount() .B Umount()
removes the connection between a device and a mount point, removes the connection between a device and a mount point,