2005-04-21 16:53:53 +02:00
|
|
|
/* mount - mount a file system Author: Andy Tanenbaum */
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <dirent.h>
|
|
|
|
#include <string.h>
|
2009-08-12 21:57:37 +02:00
|
|
|
#include <sys/mount.h>
|
2009-08-18 13:36:01 +02:00
|
|
|
#include <unistd.h>
|
2005-04-21 16:53:53 +02:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <minix/config.h>
|
|
|
|
#include <minix/const.h>
|
|
|
|
#include <minix/minlib.h>
|
|
|
|
#include <sys/svrctl.h>
|
|
|
|
#include <stdio.h>
|
2009-05-08 22:37:06 +02:00
|
|
|
#include "../../servers/mfs/const.h"
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2009-05-13 17:39:44 +02:00
|
|
|
#define MINIX_FS_TYPE "mfs"
|
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
_PROTOTYPE(int main, (int argc, char **argv));
|
|
|
|
_PROTOTYPE(void list, (void));
|
|
|
|
_PROTOTYPE(void usage, (void));
|
|
|
|
_PROTOTYPE(void tell, (char *this));
|
|
|
|
|
|
|
|
int main(argc, argv)
|
|
|
|
int argc;
|
|
|
|
char *argv[];
|
|
|
|
{
|
2010-01-05 20:39:27 +01:00
|
|
|
int i, n, v, mountflags;
|
2009-05-13 17:39:44 +02:00
|
|
|
char **ap, *vs, *opt, *err, *type, *args;
|
2005-04-21 16:53:53 +02:00
|
|
|
char special[PATH_MAX+1], mounted_on[PATH_MAX+1], version[10], rw_flag[10];
|
|
|
|
|
|
|
|
if (argc == 1) list(); /* just list /etc/mtab */
|
2009-08-18 13:36:01 +02:00
|
|
|
mountflags = 0;
|
2009-05-13 17:39:44 +02:00
|
|
|
type = NULL;
|
|
|
|
args = NULL;
|
2005-04-21 16:53:53 +02:00
|
|
|
ap = argv+1;
|
|
|
|
for (i = 1; i < argc; i++) {
|
|
|
|
if (argv[i][0] == '-') {
|
|
|
|
opt = argv[i]+1;
|
|
|
|
while (*opt != 0) switch (*opt++) {
|
2009-08-18 13:36:01 +02:00
|
|
|
case 'r': mountflags |= MS_RDONLY; break;
|
2009-05-13 17:39:44 +02:00
|
|
|
case 't': if (++i == argc) usage();
|
|
|
|
type = argv[i];
|
|
|
|
break;
|
2009-08-18 13:36:01 +02:00
|
|
|
case 'i': mountflags |= MS_REUSE; break;
|
2009-05-13 17:39:44 +02:00
|
|
|
case 'o': if (++i == argc) usage();
|
|
|
|
args = argv[i];
|
|
|
|
break;
|
2005-04-21 16:53:53 +02:00
|
|
|
default: usage();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
*ap++ = argv[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*ap = NULL;
|
|
|
|
argc = (ap - argv);
|
|
|
|
|
2010-01-05 20:39:27 +01:00
|
|
|
if (argc != 3) usage();
|
|
|
|
if (mount(argv[1], argv[2], mountflags, type, args) < 0) {
|
|
|
|
err = strerror(errno);
|
|
|
|
std_err("mount: Can't mount ");
|
|
|
|
std_err(argv[1]);
|
|
|
|
std_err(" on ");
|
|
|
|
std_err(argv[2]);
|
|
|
|
std_err(": ");
|
|
|
|
std_err(err);
|
|
|
|
std_err("\n");
|
|
|
|
exit(1);
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
2010-01-05 20:39:27 +01:00
|
|
|
/* The mount has completed successfully. Tell the user. */
|
|
|
|
tell(argv[1]);
|
|
|
|
tell(" is read-");
|
|
|
|
tell(mountflags & MS_RDONLY ? "only" : "write");
|
|
|
|
tell(" mounted on ");
|
|
|
|
tell(argv[2]);
|
|
|
|
tell("\n");
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
/* Update /etc/mtab. */
|
|
|
|
n = load_mtab("mount");
|
|
|
|
if (n < 0) exit(1); /* something is wrong. */
|
|
|
|
|
|
|
|
/* Loop on all the /etc/mtab entries, copying each one to the output buf. */
|
|
|
|
while (1) {
|
|
|
|
n = get_mtab_entry(special, mounted_on, version, rw_flag);
|
|
|
|
if (n < 0) break;
|
|
|
|
n = put_mtab_entry(special, mounted_on, version, rw_flag);
|
|
|
|
if (n < 0) {
|
|
|
|
std_err("mount: /etc/mtab has grown too large\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
2010-01-05 20:39:27 +01:00
|
|
|
/* 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";
|
2005-04-21 16:53:53 +02:00
|
|
|
} else {
|
2010-01-05 20:39:27 +01:00
|
|
|
/* Keep the version field sufficiently short. */
|
|
|
|
if (strlen(type) < sizeof(version))
|
|
|
|
vs = type;
|
|
|
|
else
|
|
|
|
vs = "-";
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
2010-01-05 20:39:27 +01:00
|
|
|
n = put_mtab_entry(argv[1], argv[2], vs,
|
2009-08-18 13:36:01 +02:00
|
|
|
(mountflags & MS_RDONLY ? "ro" : "rw") );
|
2005-04-21 16:53:53 +02:00
|
|
|
if (n < 0) {
|
|
|
|
std_err("mount: /etc/mtab has grown too large\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
n = rewrite_mtab("mount");
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void list()
|
|
|
|
{
|
|
|
|
int n;
|
|
|
|
char special[PATH_MAX+1], mounted_on[PATH_MAX+1], version[10], rw_flag[10];
|
|
|
|
|
|
|
|
/* Read and print /etc/mtab. */
|
|
|
|
n = load_mtab("mount");
|
|
|
|
if (n < 0) exit(1);
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
n = get_mtab_entry(special, mounted_on, version, rw_flag);
|
|
|
|
if (n < 0) break;
|
|
|
|
write(1, special, strlen(special));
|
2010-01-05 20:39:27 +01:00
|
|
|
tell(" is read-");
|
|
|
|
tell(strcmp(rw_flag, "rw") == 0 ? "write" : "only");
|
|
|
|
tell(" mounted on ");
|
|
|
|
tell(mounted_on);
|
|
|
|
tell("\n");
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void usage()
|
|
|
|
{
|
2010-01-05 20:39:27 +01:00
|
|
|
std_err("Usage: mount [-r] [-t type] [-o options] special name\n");
|
2005-04-21 16:53:53 +02:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void tell(this)
|
|
|
|
char *this;
|
|
|
|
{
|
|
|
|
write(1, this, strlen(this));
|
|
|
|
}
|