}
/* 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 */
/* Umount device. Playing with the file system while other processes
strcat(file_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");
done(HARMLESS);
}
#include <stdio.h>
#include "../../servers/mfs/const.h"
+#define MINIX_FS_TYPE "mfs"
+
_PROTOTYPE(int main, (int argc, char **argv));
_PROTOTYPE(void list, (void));
_PROTOTYPE(void usage, (void));
char *argv[];
{
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];
if (argc == 1) list(); /* just list /etc/mtab */
ro = 0;
swap = 0;
+ type = NULL;
+ args = NULL;
ap = argv+1;
for (i = 1; i < argc; i++) {
if (argv[i][0] == '-') {
while (*opt != 0) switch (*opt++) {
case 'r': ro = 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();
}
} else {
tell(" is swapspace\n");
} else {
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);
std_err("mount: Can't mount ");
std_err(argv[1]);
if (swap) {
vs = "swap";
} else {
- v = fsversion(argv[1], "mount");
- if (v == 1)
- vs = "1";
- else if (v == 2)
- vs = "2";
- else if (v == 3)
- vs = "3";
- else
- vs = "0";
+ /* 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");
+ if (v == 1)
+ vs = "1";
+ else if (v == 2)
+ vs = "2";
+ else if (v == 3)
+ vs = "3";
+ else
+ 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") );
if (n < 0) {
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);
}
dev= argv[1];
- r= mount(dev, "/", 0 /* !ro */);
+ r= mount(dev, "/", 0 /* !ro */, NULL, NULL);
if (r != 0)
{
fprintf(stderr, "newroot: mount failed: %s\n", strerror(errno));
_PROTOTYPE( int mknod4, (const char *_name, _mnx_Mode_t _mode, Dev_t _addr,
long _size) );
_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( char *sbrk, (int _incr) );
_PROTOTYPE( int sync, (void) );
#include <minix/paths.h>
#define OK 0
-#define MFSNAME "mfs"
-#define MFSPATH "/sbin/"
+#define FSPATH "/sbin/"
+#define FSDEFAULT "mfs"
PRIVATE int rs_down(char *label)
{
message m;
if(strlen(_PATH_SERVICE)+strlen(label)+50 >= sizeof(cmd))
return -1;
- sprintf(cmd, _PATH_SERVICE " down %s", label);
+ sprintf(cmd, _PATH_SERVICE " down '%s'", label);
return system(cmd);
}
dev = strrchr(special, '/');
if(dev) dev++;
else dev = special;
- if(strlen(dev)+strlen(MFSNAME)+3 >= sizeof(label))
+ if(strchr(dev, '\'') != NULL) {
+ errno = EINVAL;
+ return NULL;
+ }
+ if(strlen(dev)+4 >= sizeof(label)) {
+ errno = E2BIG;
return NULL;
- sprintf(label, MFSNAME "_%s", dev);
+ }
+ sprintf(label, "fs_%s", dev);
return label;
}
-PUBLIC int mount(special, name, rwflag)
-char *name, *special;
+PUBLIC int mount(special, name, rwflag, type, args)
+char *name, *special, *type, *args;
int rwflag;
{
int r;
message m;
struct rs_start rs_start;
+ struct stat statbuf;
char *label;
+ char path[60];
char cmd[200];
FILE *pipe;
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))) {
+ 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(MFSPATH)+strlen(MFSNAME)+
- strlen(label)+50 >= sizeof(cmd)) {
+ if(strlen(_PATH_SERVICE)+strlen(path)+strlen(label)+
+ strlen(_PATH_DRIVERS_CONF)+strlen(args)+50 >= sizeof(cmd)) {
errno = E2BIG;
return -1;
}
- sprintf(cmd, _PATH_SERVICE " up " MFSPATH MFSNAME
- " -label \"%s\" -config " _PATH_DRIVERS_CONF " -printep yes",
- label);
+ sprintf(cmd, _PATH_SERVICE " up %s -label '%s' -config " _PATH_DRIVERS_CONF
+ " -args '%s%s' -printep yes",
+ path, label, args[0] ? "-o " : "", args);
if(!(pipe = popen(cmd, "r"))) {
fprintf(stderr, "mount: couldn't run %s\n", cmd);
/* Make MFS process label for RS from special name. */
if(!(label=makelabel(name))) {
- errno = E2BIG;
return -1;
}
.SH NAME
mount \- mount a file system
.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
\fBmount [\fB\-s\fR] \fIswapfile\fR
.br
..
.SH OPTIONS
.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"
.SH EXAMPLES
.EX "mount /dev/fd1 /user" "Mount diskette 1 on \fI/user\fP"
When the file system is no longer needed, it must be unmounted before being
removed from the drive.
.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
.B \-s
flag a device or file is mounted as swap space.
#include <unistd.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)
.fi
.ft P
which must be seen as the root of a virtual device.
.I Flag
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
.B Umount()
removes the connection between a device and a mount point,