2006-10-25 15:40:36 +02:00
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
#include <lib.h>
|
|
|
|
#define mount _mount
|
2007-01-22 16:25:41 +01:00
|
|
|
#define umount _umount
|
2005-04-21 16:53:53 +02:00
|
|
|
#include <string.h>
|
2009-08-12 21:57:37 +02:00
|
|
|
#include <sys/mount.h>
|
2007-01-22 16:25:41 +01:00
|
|
|
#include <stdlib.h>
|
2006-10-25 15:40:36 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <minix/syslib.h>
|
2007-01-22 16:25:41 +01:00
|
|
|
#include <minix/rs.h>
|
|
|
|
#include <minix/paths.h>
|
2006-10-25 15:40:36 +02:00
|
|
|
#define OK 0
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2009-05-13 17:39:44 +02:00
|
|
|
#define FSPATH "/sbin/"
|
|
|
|
#define FSDEFAULT "mfs"
|
2007-01-22 16:25:41 +01:00
|
|
|
|
|
|
|
PRIVATE int rs_down(char *label)
|
|
|
|
{
|
|
|
|
char cmd[200];
|
|
|
|
message m;
|
|
|
|
if(strlen(_PATH_SERVICE)+strlen(label)+50 >= sizeof(cmd))
|
|
|
|
return -1;
|
2009-05-13 17:39:44 +02:00
|
|
|
sprintf(cmd, _PATH_SERVICE " down '%s'", label);
|
2007-01-22 16:25:41 +01:00
|
|
|
return system(cmd);
|
|
|
|
}
|
|
|
|
|
|
|
|
PRIVATE char *makelabel(_CONST char *special)
|
|
|
|
{
|
|
|
|
static char label[40];
|
|
|
|
_CONST char *dev;
|
|
|
|
|
|
|
|
/* Make label name. */
|
|
|
|
dev = strrchr(special, '/');
|
|
|
|
if(dev) dev++;
|
|
|
|
else dev = special;
|
2009-05-13 17:39:44 +02:00
|
|
|
if(strchr(dev, '\'') != NULL) {
|
|
|
|
errno = EINVAL;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if(strlen(dev)+4 >= sizeof(label)) {
|
|
|
|
errno = E2BIG;
|
2007-01-22 16:25:41 +01:00
|
|
|
return NULL;
|
2009-05-13 17:39:44 +02:00
|
|
|
}
|
|
|
|
sprintf(label, "fs_%s", dev);
|
2007-01-22 16:25:41 +01:00
|
|
|
return label;
|
|
|
|
}
|
|
|
|
|
2009-08-12 21:57:37 +02:00
|
|
|
PUBLIC int mount(special, name, mountflags, type, args)
|
2009-05-13 17:39:44 +02:00
|
|
|
char *name, *special, *type, *args;
|
2009-08-12 21:57:37 +02:00
|
|
|
int mountflags;
|
2005-04-21 16:53:53 +02:00
|
|
|
{
|
2006-11-24 15:01:14 +01:00
|
|
|
int r;
|
2005-04-21 16:53:53 +02:00
|
|
|
message m;
|
2007-01-22 16:25:41 +01:00
|
|
|
struct rs_start rs_start;
|
2009-05-13 17:39:44 +02:00
|
|
|
struct stat statbuf;
|
2007-01-22 16:25:41 +01:00
|
|
|
char *label;
|
2009-05-13 17:39:44 +02:00
|
|
|
char path[60];
|
2007-01-22 16:25:41 +01:00
|
|
|
char cmd[200];
|
|
|
|
FILE *pipe;
|
|
|
|
int ep;
|
2009-08-12 21:57:37 +02:00
|
|
|
int reuse;
|
2007-01-22 16:25:41 +01:00
|
|
|
|
2009-05-13 17:39:44 +02:00
|
|
|
/* Default values. */
|
|
|
|
if (type == NULL) type = FSDEFAULT;
|
|
|
|
if (args == NULL) args = "";
|
2009-08-12 21:57:37 +02:00
|
|
|
reuse = 0;
|
2009-05-13 17:39:44 +02:00
|
|
|
|
2009-08-18 13:36:01 +02:00
|
|
|
/* Check mount flags */
|
|
|
|
if(mountflags & MS_REUSE) {
|
|
|
|
reuse = 1;
|
|
|
|
mountflags &= ~MS_REUSE; /* Temporary: turn off to not confuse VFS */
|
|
|
|
}
|
|
|
|
|
2009-05-13 17:39:44 +02:00
|
|
|
/* Make FS process label for RS from special name. */
|
2007-01-22 16:25:41 +01:00
|
|
|
if(!(label=makelabel(special))) {
|
2009-05-13 17:39:44 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* See if the given type is even remotely valid. */
|
|
|
|
if(strlen(FSPATH)+strlen(type) >= sizeof(path)) {
|
2007-01-22 16:25:41 +01:00
|
|
|
errno = E2BIG;
|
|
|
|
return -1;
|
|
|
|
}
|
2009-05-13 17:39:44 +02:00
|
|
|
strcpy(path, FSPATH);
|
|
|
|
strcat(path, type);
|
2009-08-18 13:36:01 +02:00
|
|
|
|
2009-05-13 17:39:44 +02:00
|
|
|
if(stat(path, &statbuf) != 0) {
|
|
|
|
errno = EINVAL;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Sanity check on user input. */
|
|
|
|
if(strchr(args, '\'')) {
|
|
|
|
errno = EINVAL;
|
|
|
|
return -1;
|
|
|
|
}
|
2007-01-22 16:25:41 +01:00
|
|
|
|
2009-05-13 17:39:44 +02:00
|
|
|
if(strlen(_PATH_SERVICE)+strlen(path)+strlen(label)+
|
2009-12-17 02:53:26 +01:00
|
|
|
strlen(_PATH_SYSTEM_CONF)+strlen(args)+50 >= sizeof(cmd)) {
|
2007-01-22 16:25:41 +01:00
|
|
|
errno = E2BIG;
|
|
|
|
return -1;
|
2006-10-25 15:40:36 +02:00
|
|
|
}
|
2007-01-22 16:25:41 +01:00
|
|
|
|
2009-08-12 21:57:37 +02:00
|
|
|
|
2009-08-18 13:36:01 +02:00
|
|
|
|
2009-12-17 02:53:26 +01:00
|
|
|
sprintf(cmd, _PATH_SERVICE " %sup %s -label '%s' -config " _PATH_SYSTEM_CONF
|
2009-05-13 17:39:44 +02:00
|
|
|
" -args '%s%s' -printep yes",
|
2009-08-18 13:36:01 +02:00
|
|
|
reuse ? "-r ": "", path, label, args[0] ? "-o " : "", args);
|
2007-01-22 16:25:41 +01:00
|
|
|
|
|
|
|
if(!(pipe = popen(cmd, "r"))) {
|
|
|
|
fprintf(stderr, "mount: couldn't run %s\n", cmd);
|
|
|
|
return -1;
|
|
|
|
}
|
2009-08-18 13:36:01 +02:00
|
|
|
|
2007-01-22 16:25:41 +01:00
|
|
|
if(fscanf(pipe, "%d", &ep) != 1 || ep <= 0) {
|
|
|
|
fprintf(stderr, "mount: couldn't parse endpoint from %s\n", cmd);
|
|
|
|
errno = EINVAL;
|
|
|
|
pclose(pipe);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
pclose(pipe);
|
2006-10-25 15:40:36 +02:00
|
|
|
|
2007-01-22 16:25:41 +01:00
|
|
|
/* Now perform mount(). */
|
2005-04-21 16:53:53 +02:00
|
|
|
m.m1_i1 = strlen(special) + 1;
|
|
|
|
m.m1_i2 = strlen(name) + 1;
|
2009-08-12 21:57:37 +02:00
|
|
|
m.m1_i3 = mountflags;
|
2005-04-21 16:53:53 +02:00
|
|
|
m.m1_p1 = special;
|
|
|
|
m.m1_p2 = name;
|
2007-01-22 16:25:41 +01:00
|
|
|
m.m1_p3 = (char*) ep;
|
|
|
|
r = _syscall(FS, MOUNT, &m);
|
|
|
|
|
|
|
|
if(r != OK) {
|
|
|
|
/* If mount() failed, tell RS to shutdown MFS process.
|
|
|
|
* No error check - won't do anything with this error anyway.
|
|
|
|
*/
|
|
|
|
rs_down(label);
|
|
|
|
}
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
PUBLIC int umount(name)
|
|
|
|
_CONST char *name;
|
|
|
|
{
|
|
|
|
message m;
|
|
|
|
char *label;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
/* Make MFS process label for RS from special name. */
|
|
|
|
if(!(label=makelabel(name))) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
_loadname(name, &m);
|
|
|
|
r = _syscall(FS, UMOUNT, &m);
|
|
|
|
|
|
|
|
if(r == OK) {
|
|
|
|
rs_down(label);
|
|
|
|
}
|
|
|
|
|
|
|
|
return r;
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|