. pci driver now returns devices, even when they have been pci_reserve()d
[minix3.git] / lib / posix / _mount.c
blob5d38b471eba408b447c3f788528c0303570edfab
2 #include <lib.h>
3 #define mount _mount
4 #define umount _umount
5 #include <string.h>
6 #include <unistd.h>
7 #include <stdlib.h>
8 #include <stdio.h>
9 #include <sys/stat.h>
10 #include <minix/syslib.h>
11 #include <minix/rs.h>
12 #include <minix/paths.h>
13 #define OK 0
15 #define MFSNAME "mfs"
16 #define MFSPATH "/sbin/"
18 PRIVATE int rs_down(char *label)
20 char cmd[200];
21 message m;
22 if(strlen(_PATH_SERVICE)+strlen(label)+50 >= sizeof(cmd))
23 return -1;
24 sprintf(cmd, _PATH_SERVICE " down %s", label);
25 return system(cmd);
28 PRIVATE char *makelabel(_CONST char *special)
30 static char label[40];
31 _CONST char *dev;
33 /* Make label name. */
34 dev = strrchr(special, '/');
35 if(dev) dev++;
36 else dev = special;
37 if(strlen(dev)+strlen(MFSNAME)+3 >= sizeof(label))
38 return NULL;
39 sprintf(label, MFSNAME "_%s", dev);
40 return label;
43 PUBLIC int mount(special, name, rwflag)
44 char *name, *special;
45 int rwflag;
47 int r;
48 message m;
49 struct rs_start rs_start;
50 char *label;
51 char cmd[200];
52 FILE *pipe;
53 int ep;
55 /* Make MFS process label for RS from special name. */
56 if(!(label=makelabel(special))) {
57 errno = E2BIG;
58 return -1;
61 if(strlen(_PATH_SERVICE)+strlen(MFSPATH)+strlen(MFSNAME)+
62 strlen(label)+50 >= sizeof(cmd)) {
63 errno = E2BIG;
64 return -1;
67 sprintf(cmd, _PATH_SERVICE " up " MFSPATH MFSNAME
68 " -label \"%s\" -config " _PATH_DRIVERS_CONF " -printep yes",
69 label);
71 if(!(pipe = popen(cmd, "r"))) {
72 fprintf(stderr, "mount: couldn't run %s\n", cmd);
73 return -1;
75 if(fscanf(pipe, "%d", &ep) != 1 || ep <= 0) {
76 fprintf(stderr, "mount: couldn't parse endpoint from %s\n", cmd);
77 errno = EINVAL;
78 pclose(pipe);
79 return -1;
81 pclose(pipe);
83 /* Now perform mount(). */
84 m.m1_i1 = strlen(special) + 1;
85 m.m1_i2 = strlen(name) + 1;
86 m.m1_i3 = rwflag;
87 m.m1_p1 = special;
88 m.m1_p2 = name;
89 m.m1_p3 = (char*) ep;
90 r = _syscall(FS, MOUNT, &m);
92 if(r != OK) {
93 /* If mount() failed, tell RS to shutdown MFS process.
94 * No error check - won't do anything with this error anyway.
96 rs_down(label);
99 return r;
102 PUBLIC int umount(name)
103 _CONST char *name;
105 message m;
106 char *label;
107 int r;
109 /* Make MFS process label for RS from special name. */
110 if(!(label=makelabel(name))) {
111 errno = E2BIG;
112 return -1;
115 _loadname(name, &m);
116 r = _syscall(FS, UMOUNT, &m);
118 if(r == OK) {
119 rs_down(label);
122 return r;