Mount updates:
- allow mounting with "none" block device - allow unmounting by mountpoint - make VFS aware of file system process labels - allow m3_ca1 to use the full available message size - use *printf in u/mount(1), as mount(2) uses it already - fix reference leaks for some mount error cases in VFS
This commit is contained in:
+15
-30
@@ -21,14 +21,13 @@
|
||||
_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[];
|
||||
{
|
||||
int i, n, v, mountflags;
|
||||
char **ap, *vs, *opt, *err, *type, *args;
|
||||
char **ap, *vs, *opt, *err, *type, *args, *device;
|
||||
char special[PATH_MAX+1], mounted_on[PATH_MAX+1], version[10], rw_flag[10];
|
||||
|
||||
if (argc == 1) list(); /* just list /etc/mtab */
|
||||
@@ -57,25 +56,21 @@ char *argv[];
|
||||
*ap = NULL;
|
||||
argc = (ap - argv);
|
||||
|
||||
if (argc != 3) usage();
|
||||
if (mount(argv[1], argv[2], mountflags, type, args) < 0) {
|
||||
if (argc != 3 || *argv[1] == 0) usage();
|
||||
|
||||
device = argv[1];
|
||||
if (!strcmp(device, "none")) device = NULL;
|
||||
|
||||
if (mount(device, 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");
|
||||
fprintf(stderr, "mount: Can't mount %s on %s: %s\n",
|
||||
argv[1], argv[2], err);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* 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");
|
||||
printf("%s is read-%s mounted on %s\n",
|
||||
argv[1], mountflags & MS_RDONLY ? "only" : "write", argv[2]);
|
||||
|
||||
/* Update /etc/mtab. */
|
||||
n = load_mtab("mount");
|
||||
@@ -133,12 +128,9 @@ void list()
|
||||
while (1) {
|
||||
n = get_mtab_entry(special, mounted_on, version, rw_flag);
|
||||
if (n < 0) break;
|
||||
write(1, special, strlen(special));
|
||||
tell(" is read-");
|
||||
tell(strcmp(rw_flag, "rw") == 0 ? "write" : "only");
|
||||
tell(" mounted on ");
|
||||
tell(mounted_on);
|
||||
tell("\n");
|
||||
printf("%s is read-%s mounted on %s (type %s)\n",
|
||||
special, strcmp(rw_flag, "rw") == 0 ? "write" : "only",
|
||||
mounted_on, version);
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
@@ -149,10 +141,3 @@ void usage()
|
||||
std_err("Usage: mount [-r] [-t type] [-o options] special name\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
void tell(this)
|
||||
char *this;
|
||||
{
|
||||
write(1, this, strlen(this));
|
||||
}
|
||||
|
||||
+52
-28
@@ -5,7 +5,7 @@
|
||||
|
||||
#include <minix/type.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/svrctl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
@@ -17,55 +17,85 @@
|
||||
#include <stdio.h>
|
||||
|
||||
_PROTOTYPE(int main, (int argc, char **argv));
|
||||
_PROTOTYPE(void update_mtab, (char *devname));
|
||||
_PROTOTYPE(int find_mtab_entry, (char *name));
|
||||
_PROTOTYPE(void update_mtab, (void));
|
||||
_PROTOTYPE(void usage, (void));
|
||||
_PROTOTYPE(void tell, (char *this));
|
||||
|
||||
static char mountpoint[PATH_MAX+1];
|
||||
static char device[PATH_MAX+1], mountpoint[PATH_MAX+1], vs[10], rw[10];
|
||||
|
||||
int main(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
int found;
|
||||
|
||||
if (argc != 2) usage();
|
||||
found = find_mtab_entry(argv[1]);
|
||||
if (umount(argv[1]) < 0) {
|
||||
if (errno == EINVAL)
|
||||
std_err("Device not mounted\n");
|
||||
std_err("umount: Device not mounted\n");
|
||||
else if (errno == ENOTBLK)
|
||||
std_err("unount: Not a mountpoint\n");
|
||||
else
|
||||
perror("umount");
|
||||
exit(1);
|
||||
}
|
||||
update_mtab(argv[1]);
|
||||
tell(argv[1]);
|
||||
tell(" unmounted");
|
||||
if (*mountpoint != '\0') {
|
||||
tell(" from ");
|
||||
tell(mountpoint);
|
||||
if (found) {
|
||||
printf("%s unmounted from %s\n", device, mountpoint);
|
||||
update_mtab();
|
||||
}
|
||||
tell("\n");
|
||||
else printf("%s unmounted (mtab not updated)\n", argv[1]);
|
||||
return(0);
|
||||
}
|
||||
|
||||
void update_mtab(devname)
|
||||
char *devname;
|
||||
int find_mtab_entry(name)
|
||||
char *name;
|
||||
{
|
||||
/* Remove an entry from /etc/mtab. */
|
||||
int n;
|
||||
/* Find a matching mtab entry for 'name' which may be a special or a path,
|
||||
* and generate a new mtab file without this entry on the fly. Do not write
|
||||
* out the result yet. Return whether we found a matching entry.
|
||||
*/
|
||||
char special[PATH_MAX+1], mounted_on[PATH_MAX+1], version[10], rw_flag[10];
|
||||
struct stat nstat, mstat;
|
||||
int n, found;
|
||||
|
||||
if (load_mtab("umount") < 0) {
|
||||
std_err("/etc/mtab not updated.\n");
|
||||
exit(1);
|
||||
}
|
||||
if (load_mtab("umount") < 0) return 0;
|
||||
|
||||
if (stat(name, &nstat) != 0) return 0;
|
||||
|
||||
found = 0;
|
||||
while (1) {
|
||||
n = get_mtab_entry(special, mounted_on, version, rw_flag);
|
||||
if (n < 0) break;
|
||||
if (strcmp(devname, special) == 0) {
|
||||
if (strcmp(name, special) == 0 || (stat(mounted_on, &mstat) == 0 &&
|
||||
mstat.st_dev == nstat.st_dev && mstat.st_ino == nstat.st_ino))
|
||||
{
|
||||
/* If we found an earlier match, keep that one. Mountpoints
|
||||
* may be stacked on top of each other, and unmounting should
|
||||
* take place in the reverse order of mounting.
|
||||
*/
|
||||
if (found) {
|
||||
(void) put_mtab_entry(device, mountpoint, vs, rw);
|
||||
}
|
||||
|
||||
strcpy(device, special);
|
||||
strcpy(mountpoint, mounted_on);
|
||||
strcpy(vs, version);
|
||||
strcpy(rw, rw_flag);
|
||||
found = 1;
|
||||
continue;
|
||||
}
|
||||
(void) put_mtab_entry(special, mounted_on, version, rw_flag);
|
||||
}
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
void update_mtab()
|
||||
{
|
||||
/* Write out the new mtab file. */
|
||||
int n;
|
||||
|
||||
n = rewrite_mtab("umount");
|
||||
if (n < 0) {
|
||||
std_err("/etc/mtab not updated.\n");
|
||||
@@ -75,12 +105,6 @@ char *devname;
|
||||
|
||||
void usage()
|
||||
{
|
||||
std_err("Usage: umount special\n");
|
||||
std_err("Usage: umount name\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void tell(this)
|
||||
char *this;
|
||||
{
|
||||
write(1, this, strlen(this));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user