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>
|
2010-11-06 21:40:15 +01:00
|
|
|
#include <paths.h>
|
2011-11-14 12:53:05 +01:00
|
|
|
#include <unistd.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 FSDEFAULT "mfs"
|
2007-01-22 16:25:41 +01:00
|
|
|
|
2011-11-14 12:53:05 +01:00
|
|
|
static char fspath[] = "/sbin/:/usr/pkg/bin/"; /* Must include trailing '/' */
|
|
|
|
|
2007-01-22 16:25:41 +01:00
|
|
|
PRIVATE int rs_down(char *label)
|
|
|
|
{
|
|
|
|
char cmd[200];
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
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;
|
2009-05-13 17:39:44 +02:00
|
|
|
struct stat statbuf;
|
2010-01-13 00:08:50 +01:00
|
|
|
char label[16];
|
2011-11-14 12:53:05 +01:00
|
|
|
char path[PATH_MAX];
|
2007-01-22 16:25:41 +01:00
|
|
|
char cmd[200];
|
2010-01-13 00:08:50 +01:00
|
|
|
char *p;
|
2010-11-23 20:34:56 +01:00
|
|
|
int reuse = 0;
|
|
|
|
int use_existing = 0;
|
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;
|
2011-11-14 12:53:05 +01:00
|
|
|
memset(path, '\0', sizeof(path));
|
2009-05-13 17:39:44 +02:00
|
|
|
|
2009-08-18 13:36:01 +02:00
|
|
|
/* Check mount flags */
|
|
|
|
if(mountflags & MS_REUSE) {
|
2010-01-13 00:08:50 +01:00
|
|
|
reuse = 1;
|
|
|
|
mountflags &= ~MS_REUSE; /* Temporary: turn off to not confuse VFS */
|
2009-08-18 13:36:01 +02:00
|
|
|
}
|
2010-11-23 20:34:56 +01:00
|
|
|
|
|
|
|
if(mountflags & MS_EXISTING) {
|
|
|
|
use_existing = 1;
|
|
|
|
mountflags &= ~MS_EXISTING; /* Temporary: turn off to not confuse VFS */
|
|
|
|
}
|
2009-08-18 13:36:01 +02:00
|
|
|
|
2010-01-13 00:08:50 +01:00
|
|
|
/* Make a label for the file system process. This label must be unique and
|
|
|
|
* may currently not exceed 16 characters including terminating null. For
|
|
|
|
* requests with an associated block device, we use the last path component
|
|
|
|
* name of the block special file (truncated to 12 characters, which is
|
|
|
|
* hopefully enough). For requests with no associated block device, we use
|
|
|
|
* the device number and inode of the mount point, in hexadecimal form.
|
|
|
|
*/
|
2010-11-23 20:34:56 +01:00
|
|
|
if (!use_existing) {
|
|
|
|
if (special) {
|
|
|
|
p = strrchr(special, '/');
|
|
|
|
p = p ? p + 1 : special;
|
|
|
|
if (strchr(p, '\'')) {
|
|
|
|
errno = EINVAL;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
sprintf(label, "fs_%.12s", p);
|
|
|
|
} else {
|
|
|
|
if (stat(name, &statbuf) < 0) return -1;
|
|
|
|
sprintf(label, "fs_%04x%x", statbuf.st_dev, statbuf.st_ino);
|
2010-01-13 00:08:50 +01:00
|
|
|
}
|
|
|
|
} else {
|
2010-11-23 20:34:56 +01:00
|
|
|
/* label to long? */
|
|
|
|
if (strlen(type) < 16) {
|
|
|
|
sprintf(label, "%s", type);
|
|
|
|
} else {
|
|
|
|
errno = ENOMEM;
|
|
|
|
return -1;
|
|
|
|
}
|
2009-05-13 17:39:44 +02:00
|
|
|
}
|
|
|
|
|
2010-01-13 00:08:50 +01:00
|
|
|
/* Tell VFS that we are passing in a 16-byte label. */
|
|
|
|
mountflags |= MS_LABEL16;
|
|
|
|
|
2009-05-13 17:39:44 +02:00
|
|
|
/* Sanity check on user input. */
|
|
|
|
if(strchr(args, '\'')) {
|
|
|
|
errno = EINVAL;
|
|
|
|
return -1;
|
|
|
|
}
|
2010-11-23 20:34:56 +01:00
|
|
|
/* start the fs-server if not using existing one */
|
|
|
|
if (!use_existing) {
|
2011-02-22 18:59:08 +01:00
|
|
|
/* See if the given type is even remotely valid. */
|
2011-11-14 12:53:05 +01:00
|
|
|
|
|
|
|
char *testpath;
|
|
|
|
testpath = strtok(fspath, ":");
|
|
|
|
|
|
|
|
do {
|
|
|
|
if (strlen(testpath) + strlen(type) >= sizeof(path)) {
|
|
|
|
errno = E2BIG;
|
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
strcpy(path, testpath);
|
|
|
|
strcat(path, type);
|
|
|
|
|
|
|
|
if (access(path, F_OK) == 0) break;
|
|
|
|
|
|
|
|
} while ((testpath = strtok(NULL, ":")) != NULL);
|
|
|
|
|
|
|
|
if (testpath == NULL) {
|
|
|
|
/* We were not able to find type somewhere in "fspath" */
|
2011-02-22 18:59:08 +01:00
|
|
|
errno = EINVAL;
|
2011-11-14 12:53:05 +01:00
|
|
|
return(-1);
|
2011-02-22 18:59:08 +01:00
|
|
|
}
|
2011-11-14 12:53:05 +01:00
|
|
|
|
|
|
|
if (strlen(_PATH_SERVICE) + strlen(path) + strlen(label) +
|
|
|
|
strlen(args) + 50 >= sizeof(cmd)) {
|
2010-11-23 20:34:56 +01:00
|
|
|
errno = E2BIG;
|
|
|
|
return -1;
|
|
|
|
}
|
2007-01-22 16:25:41 +01:00
|
|
|
|
2011-11-14 12:53:05 +01:00
|
|
|
sprintf(cmd, _PATH_SERVICE " %sup %s -label '%s' -args '%s %s %s%s'",
|
|
|
|
reuse ? "-r ": "", path, label, special, name,
|
|
|
|
args[0] ? "-o " : "", args);
|
2007-01-22 16:25:41 +01:00
|
|
|
|
2011-11-14 12:53:05 +01:00
|
|
|
if ((r = system(cmd)) != 0) {
|
2010-11-23 20:34:56 +01:00
|
|
|
fprintf(stderr, "mount: couldn't run %s\n", cmd);
|
|
|
|
errno = r;
|
|
|
|
return -1;
|
|
|
|
}
|
2007-01-22 16:25:41 +01:00
|
|
|
}
|
2009-08-18 13:36:01 +02:00
|
|
|
|
2007-01-22 16:25:41 +01:00
|
|
|
/* Now perform mount(). */
|
2010-01-13 00:08:50 +01:00
|
|
|
m.m1_i1 = special ? strlen(special) + 1 : 0;
|
2005-04-21 16:53:53 +02:00
|
|
|
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;
|
2010-01-13 00:08:50 +01:00
|
|
|
m.m1_p3 = label;
|
2010-06-08 15:58:01 +02:00
|
|
|
r = _syscall(VFS_PROC_NR, MOUNT, &m);
|
2007-01-22 16:25:41 +01:00
|
|
|
|
2011-11-14 12:53:05 +01:00
|
|
|
if (r != OK && !use_existing) {
|
|
|
|
/* If mount() failed, tell RS to shutdown FS process.
|
2007-01-22 16:25:41 +01:00
|
|
|
* No error check - won't do anything with this error anyway.
|
|
|
|
*/
|
|
|
|
rs_down(label);
|
|
|
|
}
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
PUBLIC int umount(name)
|
|
|
|
_CONST char *name;
|
2010-11-23 20:34:56 +01:00
|
|
|
{
|
|
|
|
return umount2(name, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
PUBLIC int umount2(name, flags)
|
|
|
|
_CONST char *name;
|
|
|
|
int flags;
|
2007-01-22 16:25:41 +01:00
|
|
|
{
|
|
|
|
message m;
|
|
|
|
int r;
|
|
|
|
|
2010-11-23 20:34:56 +01:00
|
|
|
|
2007-01-22 16:25:41 +01:00
|
|
|
_loadname(name, &m);
|
2010-06-08 15:58:01 +02:00
|
|
|
r = _syscall(VFS_PROC_NR, UMOUNT, &m);
|
2007-01-22 16:25:41 +01:00
|
|
|
|
2010-11-23 20:34:56 +01:00
|
|
|
/* don't shut down the driver when exist flag is set */
|
|
|
|
if (!(flags & MS_EXISTING)) {
|
|
|
|
if (r == OK) {
|
|
|
|
/* VFS returns the label of the unmounted file system in the reply.
|
|
|
|
* As of writing, the size of the m3_ca1 field is 16 bytes.
|
|
|
|
*/
|
|
|
|
rs_down(m.m3_ca1);
|
|
|
|
}
|
2007-01-22 16:25:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return r;
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|