2005-04-21 16:53:53 +02:00
|
|
|
/* umount - unmount a file system Author: Andy Tanenbaum */
|
|
|
|
|
2006-06-20 10:46:45 +02:00
|
|
|
#include <minix/type.h>
|
2005-04-21 16:53:53 +02:00
|
|
|
#include <sys/types.h>
|
2010-01-13 00:08:50 +01:00
|
|
|
#include <sys/stat.h>
|
2005-04-21 16:53:53 +02:00
|
|
|
#include <fcntl.h>
|
2010-11-23 20:34:56 +01:00
|
|
|
#include <getopt.h>
|
2005-04-21 16:53:53 +02:00
|
|
|
#include <errno.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <minix/minlib.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
2009-08-12 21:57:37 +02:00
|
|
|
#include <sys/mount.h>
|
2005-04-21 16:53:53 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2012-03-24 16:16:34 +01:00
|
|
|
int main(int argc, char **argv);
|
|
|
|
int find_mtab_entry(char *name);
|
|
|
|
void update_mtab(void);
|
|
|
|
void usage(void);
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2012-11-22 23:00:00 +01:00
|
|
|
static char device[PATH_MAX], mount_point[PATH_MAX], type[MNTNAMELEN],
|
|
|
|
flags[MNTFLAGLEN];
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
int main(argc, argv)
|
|
|
|
int argc;
|
|
|
|
char *argv[];
|
|
|
|
{
|
2010-01-13 00:08:50 +01:00
|
|
|
int found;
|
2012-11-22 23:00:00 +01:00
|
|
|
int umount_flags = 0UL;
|
2013-02-04 05:09:28 +01:00
|
|
|
int c;
|
2010-11-23 20:34:56 +01:00
|
|
|
char *name;
|
2010-01-13 00:08:50 +01:00
|
|
|
|
2010-11-23 20:34:56 +01:00
|
|
|
while ((c = getopt (argc, argv, "e")) != -1)
|
|
|
|
{
|
|
|
|
switch (c) {
|
2012-11-22 23:00:00 +01:00
|
|
|
case 'e': umount_flags |= MS_EXISTING; break;
|
2010-11-23 20:34:56 +01:00
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argc - optind != 1) {
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
|
|
|
|
name = argv[optind];
|
|
|
|
|
|
|
|
found = find_mtab_entry(name);
|
|
|
|
|
2014-03-17 14:01:22 +01:00
|
|
|
if (minix_umount(name, umount_flags) < 0) {
|
2005-04-21 16:53:53 +02:00
|
|
|
if (errno == EINVAL)
|
2010-01-13 00:08:50 +01:00
|
|
|
std_err("umount: Device not mounted\n");
|
|
|
|
else if (errno == ENOTBLK)
|
2010-06-07 15:46:05 +02:00
|
|
|
std_err("umount: Not a mountpoint\n");
|
2005-04-21 16:53:53 +02:00
|
|
|
else
|
|
|
|
perror("umount");
|
|
|
|
exit(1);
|
|
|
|
}
|
2010-01-13 00:08:50 +01:00
|
|
|
if (found) {
|
2012-11-22 23:00:00 +01:00
|
|
|
printf("%s unmounted from %s\n", device, mount_point);
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
2010-01-13 00:08:50 +01:00
|
|
|
int find_mtab_entry(name)
|
|
|
|
char *name;
|
2005-04-21 16:53:53 +02:00
|
|
|
{
|
2010-01-13 00:08:50 +01:00
|
|
|
/* 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.
|
|
|
|
*/
|
2012-11-22 23:00:00 +01:00
|
|
|
char e_dev[PATH_MAX], e_mount_point[PATH_MAX], e_type[MNTNAMELEN],
|
|
|
|
e_flags[MNTFLAGLEN];
|
2010-01-13 00:08:50 +01:00
|
|
|
struct stat nstat, mstat;
|
|
|
|
int n, found;
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2010-01-13 00:08:50 +01:00
|
|
|
if (load_mtab("umount") < 0) return 0;
|
|
|
|
|
|
|
|
if (stat(name, &nstat) != 0) return 0;
|
|
|
|
|
|
|
|
found = 0;
|
2005-04-21 16:53:53 +02:00
|
|
|
while (1) {
|
2012-11-22 23:00:00 +01:00
|
|
|
n = get_mtab_entry(e_dev, e_mount_point, e_type, e_flags);
|
2005-04-21 16:53:53 +02:00
|
|
|
if (n < 0) break;
|
2012-11-22 23:00:00 +01:00
|
|
|
if (strcmp(name, e_dev) == 0 || (stat(e_mount_point, &mstat) == 0 &&
|
2010-01-13 00:08:50 +01:00
|
|
|
mstat.st_dev == nstat.st_dev && mstat.st_ino == nstat.st_ino))
|
|
|
|
{
|
2012-11-22 23:00:00 +01:00
|
|
|
strlcpy(device, e_dev, PATH_MAX);
|
|
|
|
strlcpy(mount_point, e_mount_point, PATH_MAX);
|
|
|
|
strlcpy(type, e_type, MNTNAMELEN);
|
|
|
|
strlcpy(flags, e_flags, MNTFLAGLEN);
|
2010-01-13 00:08:50 +01:00
|
|
|
found = 1;
|
2012-11-22 23:00:00 +01:00
|
|
|
break;
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
}
|
2010-01-13 00:08:50 +01:00
|
|
|
|
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
void usage()
|
|
|
|
{
|
2010-11-23 20:34:56 +01:00
|
|
|
std_err("Usage: umount [-e] name\n");
|
2005-04-21 16:53:53 +02:00
|
|
|
exit(1);
|
|
|
|
}
|