diff options
author | Karel Zak <kzak@redhat.com> | 2006-12-07 00:25:33 +0100 |
---|---|---|
committer | Karel Zak <kzak@redhat.com> | 2006-12-07 00:25:33 +0100 |
commit | 726f69e29ca9d4842f3acb20fffd2466fda62c09 (patch) | |
tree | abbc1b6e9bfb0dfe32e81a83648e261ccb2d5a5f /mount | |
parent | 6dbe3af945a63f025561abb83275cee9ff06c57b (diff) | |
download | util-linux-old-726f69e29ca9d4842f3acb20fffd2466fda62c09.tar.gz |
Imported from util-linux-2.5 tarball.
Diffstat (limited to 'mount')
-rw-r--r-- | mount/Makefile | 5 | ||||
-rw-r--r-- | mount/fstab.5 | 11 | ||||
-rw-r--r-- | mount/fstab.c | 4 | ||||
-rw-r--r-- | mount/fstab.h | 3 | ||||
-rw-r--r-- | mount/mount.8 | 82 | ||||
-rw-r--r-- | mount/mount.c | 281 | ||||
-rw-r--r-- | mount/nfs.5 | 2 | ||||
-rw-r--r-- | mount/sundries.c | 62 | ||||
-rw-r--r-- | mount/sundries.h | 14 | ||||
-rw-r--r-- | mount/swapon.8 | 32 | ||||
-rw-r--r-- | mount/swapon.c | 80 | ||||
-rw-r--r-- | mount/umount.c | 34 | ||||
-rw-r--r-- | mount/version.c | 2 |
13 files changed, 467 insertions, 145 deletions
diff --git a/mount/Makefile b/mount/Makefile index 737c716a..22c146ce 100644 --- a/mount/Makefile +++ b/mount/Makefile @@ -1,6 +1,7 @@ # To make "ext" the default file system type for mount # (used when no other type is specified), replace \"minix\" by \"ext2\". -DEFAULT_FSTYPE=\"minix\" +# Use iso9660 instead, since CDROMs are popular. +DEFAULT_FSTYPE=\"iso9660\" # you need rpcgen and libc-4.2 or rpclib to compile in the NFS support DEFINES = -DHAVE_NFS -DFSTYPE_DEFAULT=$(DEFAULT_FSTYPE) @@ -57,7 +58,7 @@ install: $(PROGS) $(INSTALLMAN) $(MAN5) $(MAN5DIR) $(INSTALLMAN) $(MAN8) $(MAN8DIR) -.c.o: +%.o: %.c $(COMPILE) $< mount: mount.o fstab.o sundries.o version.o $(NFS_OBJS) $(LO_OBJS) diff --git a/mount/fstab.5 b/mount/fstab.5 index 8f96ee3b..82bf0f4c 100644 --- a/mount/fstab.5 +++ b/mount/fstab.5 @@ -35,6 +35,7 @@ .\" Sat Oct 9 10:07:10 1993: converted to man format by faith@cs.unc.edu .\" Sat Nov 20 20:47:38 1993: hpfs documentation added .\" Sat Nov 27 20:23:32 1993: Updated authorship information +.\" Wed Jul 26 00:00:00 1995: Updated some nfs stuff, joey@infodrom.north.de .\" .TH FSTAB 5 "27 November 1993" "Linux 0.99" "Linux Programmer's Manual" .SH NAME @@ -115,8 +116,11 @@ describes the mount options associated with the filesystem. It is formatted as a comma separated list of options. It contains at least the type of mount plus any additional options appropriate to the filesystem -type. For documentation on all of the available options, see +type. For documentation on the available options for non-nfs file systems, +see .BR mount (8). +For documentation on all nfs-specific options have a look at +.BR nfs (5). The fifth field, .RI ( fs_freq ), @@ -154,14 +158,11 @@ The file resides in .IR /etc . .SH BUGS -Linux does not, currently, support the special fields for -.BR dump " and " fsck . - The documentation in .BR mount (8) is often more up-to-date. .SH "SEE ALSO" -.BR getmntent "(3), " mount "(8), " swapon (8) +.BR getmntent "(3), " mount "(8), " swapon "(8), " nfs (5) .SH HISTORY The .B fstab diff --git a/mount/fstab.c b/mount/fstab.c index 95b0879e..d13280f8 100644 --- a/mount/fstab.c +++ b/mount/fstab.c @@ -1,11 +1,11 @@ -/* /home/faith/cvs/util-linux/mount/fstab.c,v 1.1.1.1 1995/02/22 19:09:21 faith Exp */ +/* $Header: /home/faith/cvs/util-linux/mount/fstab.c,v 1.2 1995/10/07 01:32:03 faith Exp $ */ #include "fstab.h" #include <stdio.h> #define streq(s, t) (strcmp ((s), (t)) == 0) -/* These routines are superceded by mntent(3), but I use them for +/* These routines are superseded by mntent(3), but I use them for convenience. Mntent(3) is used in the implementation, so be very careful about the static buffers that are returned. */ diff --git a/mount/fstab.h b/mount/fstab.h index c3c48b9e..82582259 100644 --- a/mount/fstab.h +++ b/mount/fstab.h @@ -1,7 +1,7 @@ /* The fsent(3) routines are obsoleted by mntent(3). I use them for convenience. Since the implementation uses mntent(3), be very careful with the static buffers returned. - /home/faith/cvs/util-linux/mount/fstab.h,v 1.1.1.1 1995/02/22 19:09:21 faith Exp */ + $Header: /home/faith/cvs/util-linux/mount/fstab.h,v 1.2 1995/09/25 20:57:42 faith Exp $ */ #ifndef _FSTAB_H #include <stdio.h> @@ -14,6 +14,7 @@ #define fstab mntent #define fs_type mnt_type #define fs_spec mnt_fsname +#define fs_mntopts mnt_opts #define FSTAB_SW MNTTYPE_SWAP struct fstab *getfsent (void); diff --git a/mount/mount.8 b/mount/mount.8 index a47091dd..4c197f46 100644 --- a/mount/mount.8 +++ b/mount/mount.8 @@ -47,12 +47,18 @@ .\" Youngdale (eric@tantalus.nrl.navy.mil) and Remy Card .\" (Remy.Card@masi.ibp.fr). .\" Sun Apr 24 19:25:59 1994: Updated per information supplied by Remy Card. -.\" Thu Jul 14 07:44:36 1994: Updated absence of -t -.\" option. (faith@cs.unc.edu) +.\" Thu Jul 14 07:44:36 1994: Updated absence of -t option. +.\" (faith@cs.unc.edu) .\" Thu Jul 14 07:49:14 1994: Updated list of valid filesystems. .\" Wed Feb 8 09:25:48 1995: Updated man pages for Mike Grupenhoff's changes. +.\" Sat Jul 22 01:45:58 1995: Updated list of binary extensions for +.\" msdos conversion. (sl14@cornell.edu) +.\" Wed Jul 26 00:00:00 1995: Updated by Martin Schulze. +.\" (joey@infodrom.north.de) +.\" Tue Sep 26 12:02:03 1995: Updated umount, nfs, proc parts of page. +.\" (aeb@cwi.nl) .\" -.TH MOUNT 8 "8 February 1995" "Linux 1.1" "Linux Programmer's Manual" +.TH MOUNT 8 "26 September 1995" "Linux 1.3" "Linux Programmer's Manual" .SH NAME mount, umount \- mount and dismount file systems .SH SYNOPSIS @@ -62,9 +68,9 @@ mount, umount \- mount and dismount file systems .br .BI "mount [\-frwun] [\-t " vfstype "] [\-o " options "] " "special node" .br -.BI "umount [\-an] [\-t " vfstype ] +.BI "umount [\-ahvV] [\-t " vfstype ] .br -.BI "umount " "special " | " node" +.BI "umount [\-v] " "special " | " node " [...] .\" " for hilit19 .SH DESCRIPTION The @@ -79,13 +85,17 @@ If either .IR special " or " node are not provided, the appropriate information is taken from the .BR fstab (5) -file. The special keyword -.I none +file. The +.I proc +file system is not associated with a special device, and when +mounting it, an arbitrary keyword, such as +.I proc can be used instead of a path or .I node -specification. This is useful when mounting the -.I proc -file system. +specification. (The customary choice +.I none +is less fortunate: the error message `none busy' from umount +can be confusing.) The system maintains a list of currently mounted file systems. If no arguments are given to @@ -196,7 +206,7 @@ or Tells the .I ext2 file sysem kernel code to do some more checks while the file system is -mounted. Currently (0.99.15), the following values can be specified with +mounted. Currently (1.3.11), the following values can be specified with this option: .RS .TP @@ -268,11 +278,12 @@ CRLF<-->NL translation is performed on all files that don't have a "well-known binary" extension. The list of known extensions can be found at the beginning of .I fs/msdos/misc.c -(as of 09913r, the list is: exe, com, bin, app, sys, drv, ovl, ovr, obj, +(as of 1.3.11, the list is: exe, com, bin, app, sys, drv, ovl, ovr, obj, lib, dll, pif, arc, zip, lha, lzh, zoo, tar, z, arj, tz, taz, tzp, tpz, -gif, bmp, tif, gl, jpg, pcx, tfm, vf, gf, pk, pxl, dvi). +gz, tgz, deb, gif, bmp, tif, gl, jpg, pcx, tfm, vf, gf, pk, pxl, dvi). .PP Programs that do computed lseeks won't like in-kernel text conversion. +Several people have had their data ruined by this translation. Beware! For file systems mounted in .B binary @@ -346,7 +357,7 @@ and file systems, give every file a gid equal to .IR value . .TP -B grpid +.B grpid Causes the .I ext2fs to use the BSD behavior when creating files: file are created with the @@ -402,6 +413,19 @@ file system, turn on the flag. Attempts to chown or chmod files do not yield errors, although they fail. Use with caution! .TP +.B soft +For the +.IR nfs +file system this allows the kernel to time out if the nfs server is not +responding for some time, otherwise it will try forever. The time can be +specified with +.BR timeo=time . +For more information look at +.IR nfs (5). + +This option is useful if your nfs server sometimes doesn't respond or will +be rebooted while some process tries to get a file from the server. +.TP .BI sb= value For the .I ext2 @@ -459,8 +483,9 @@ The argument following the is used to indicate the file system type. The file system types which are currently supported are listed in .IR linux/fs/filesystems.c : -.IR minux ", " ext ", " ext2 ", " xiafs ", " msdos ", " hpfs , -.IR proc ", " nfs ", " iso9660 ", " sysv ", " xenix ", " coherent . +.IR minix ", " ext ", " ext2 ", " xiafs ", " msdos ", " umsdos , +.IR hpfs ", " proc ", " nfs ", " iso9660 ", " smbfs , +.IR sysv ", " xenix ", " coherent . Note that that last three are equivalent and that "xenix" and "coherent" will be removed at some point in the future \(em use "sysv" instead. @@ -468,13 +493,16 @@ The type .I minix is the default. If no .B \-t -option is given, the superblock is probed for the filesystem type (minix, -ext, ext2, xia are supported). If this probe fails and +option is given, or if the "auto" type is specified, the superblock is +probed for the filesystem type (minix, ext, ext2, xia are supported). If +this probe fails and .I /proc/filesystems exists, then all of the filesystems listed will be tried, .I except for those that are labeled "nodev" (e.g., "proc" and "nfs"). +Note that the "auto" type may be useful for user-mounted floppies. + For example, the .B mount command: @@ -503,9 +531,9 @@ Mount without writing in .B Umount removes the .I special -device grafted at point -.I node -from file system tree. +device, or the device grafted at point +.IR node , +from the file system tree. Options for the .B umount @@ -524,6 +552,15 @@ the file system types on which no action should be taken. (See example above for the .B mount command.) +.TP +.B \-V +Print version and exit. +.TP +.B \-h +Print help message and exit. +.TP +.B \-v +Verbose mode. .SH FILES .I /etc/fstab @@ -535,7 +572,8 @@ lock file .I /etc/mtab.tmp temporary file .SH "SEE ALSO" -.BR mount "(2), " umount "(2), " fstab "(5), " swapon (8) +.BR mount "(2), " umount "(2), " fstab "(5), " swapon "(8), " nfs (5), +.BR mountd "(8), " nfsd (8) .SH BUGS It is possible for a corrupted file system to cause a crash. .PP diff --git a/mount/mount.c b/mount/mount.c index b6ffbcd6..028848ac 100644 --- a/mount/mount.c +++ b/mount/mount.c @@ -2,7 +2,7 @@ * A mount(8) for Linux 0.99. * mount.c,v 1.1.1.1 1993/11/18 08:40:51 jrs Exp * - * Thu Jul 14 07:32:40 1994: faith@cs.unc.edu added changed from Adam + * Thu Jul 14 07:32:40 1994: faith@cs.unc.edu added changes from Adam * J. Richter (adam@adam.yggdrasil.com) so that /proc/filesystems is used * if no -t option is given. I modified his patches so that, if * /proc/filesystems is not available, the behavior of mount is the same as @@ -20,6 +20,8 @@ * checked. * * Wed Feb 8 12:27:00 1995: Andries.Brouwer@cwi.nl fixed up error messages. + * Sat Jun 3 20:44:38 1995: Patches from Andries.Brouwer@cwi.nl applied. + * Tue Sep 26 22:38:20 1995: aeb@cwi.nl, many changes * */ @@ -33,6 +35,9 @@ #include <sys/stat.h> #include <unistd.h> +#define PROC_FILESYSTEMS "/proc/filesystems" +#define SIZE(a) (sizeof(a)/sizeof(a[0])) + int del_loop (const char *); /* True for fake mount (-f). */ @@ -100,14 +105,20 @@ const struct opt_map opt_map[] = { "sub", 1, MS_NOSUB }, /* allow submounts */ { "nosub", 0, MS_NOSUB }, /* don't allow submounts */ #endif +#ifdef MS_SILENT + { "quiet", 0, MS_SILENT }, /* be quiet */ + { "loud", 1, MS_SILENT }, /* print out messages. */ +#endif { NULL, 0, 0 } }; +int mount_quiet=0; /* Report on a single mount. */ static void print_one (const struct mntent *mnt) { + if (mount_quiet) return; printf ("%s on %s", mnt->mnt_fsname, mnt->mnt_dir); if ((mnt->mnt_type != NULL) && *mnt->mnt_type != '\0') printf (" type %s", mnt->mnt_type); @@ -151,6 +162,12 @@ parse_opt (const char *opt, int *mask, char *extra_opts) *mask |= om->mask; if (om->mask == MS_USER) *mask |= MS_SECURE; +#ifdef MS_SILENT + if (om->mask == MS_SILENT && om->inv) { + mount_quiet = 1; + verbose = 0; + } +#endif return; } if (*extra_opts) @@ -218,97 +235,192 @@ fix_opts_string (int flags, char *extra_opts) /* char *fstype(const char *device); - probes the device and attempts to determine the type of filesystem + Probes the device and attempts to determine the type of filesystem contained within. Original routine by <jmorriso@bogomips.ww.ubc.ca>; made into a function for mount(8) by Mike Grupenhoff <kashmir@umiacs.umd.edu>. + Read the superblock only once - aeb + Added a test for iso9660 - aeb - Currently supports: minix, ext, ext2, xia + Currently supports: minix, ext, ext2, xiafs, iso9660 */ +char *magic_known[] = { "minix", "ext", "ext2", "xiafs", "iso9660" }; + +static int +tested(const char *device) { + char **m; + + for (m = magic_known; m - magic_known < SIZE(magic_known); m++) + if (!strcmp(*m, device)) + return 1; + return 0; +} static char * fstype(const char *device) { int fd; - - /* MINIX */ - struct minix_super_block ms; - /* extended fs */ - struct ext_super_block es; - /* 2nd extended fs */ - struct ext2_super_block e2s; - /* xia fs */ - struct xiafs_super_block xfs; + char ifs_magic[8]; + union { + struct minix_super_block ms; + struct ext_super_block es; + struct ext2_super_block e2s; + struct xiafs_super_block xfs; + } sb; + struct stat statbuf; + + /* opening and reading an arbitrary unknown path can have + undesired side effects - first check that `device' refers + to a block device */ + if (stat (device, &statbuf)) + error("mount: %s does not exist", device); + if (!S_ISBLK(statbuf.st_mode)) + error("mount: %s is not a block device", device); fd = open(device, O_RDONLY); - if (fd < 0) { + if (fd < 0 + || lseek(fd, BLOCK_SIZE, SEEK_SET) < 0 + || read(fd, (char *) &sb, sizeof(sb)) < 0) { perror(device); return 0; } - lseek(fd, BLOCK_SIZE, SEEK_SET); - read(fd, (char *) &ms, sizeof(ms)); - if (ms.s_magic == MINIX_SUPER_MAGIC || ms.s_magic == MINIX_SUPER_MAGIC2) { - close(fd); + + if (sb.ms.s_magic == MINIX_SUPER_MAGIC + || sb.ms.s_magic == MINIX_SUPER_MAGIC2) { + close (fd); return("minix"); } - lseek(fd, BLOCK_SIZE, SEEK_SET); - read(fd, (char *) &es, sizeof(es)); - if (es.s_magic == EXT_SUPER_MAGIC) { - close(fd); + if (sb.es.s_magic == EXT_SUPER_MAGIC) { + close (fd); return("ext"); } - lseek(fd, BLOCK_SIZE, SEEK_SET); - read(fd, (char *) &e2s, sizeof(e2s)); - if (e2s.s_magic == EXT2_SUPER_MAGIC || e2s.s_magic == EXT2_PRE_02B_MAGIC) { - close(fd); +#ifndef EXT2_PRE_02B_MAGIC +#define EXT2_PRE_02B_MAGIC 0xEF51 +#endif + if (sb.e2s.s_magic == EXT2_SUPER_MAGIC + || sb.e2s.s_magic == EXT2_PRE_02B_MAGIC) { + close (fd); return("ext2"); } - lseek(fd, 0, SEEK_SET); - read(fd, (char *) &xfs, sizeof(xfs)); - if (xfs.s_magic == _XIAFS_SUPER_MAGIC) { - close(fd); + if (sb.xfs.s_magic == _XIAFS_SUPER_MAGIC) { + close (fd); return("xiafs"); } - close(fd); + if (lseek (fd, 0100000, SEEK_SET) != -1 + && read (fd, ifs_magic, 8) == 8 + && !strncmp(ifs_magic, "\001CD001\001", 8)) { /* ECMA 119 */ + close (fd); + return("iso9660"); + } + close (fd); return(0); +} +FILE *procfs; + +static void +procclose(void) { + if (procfs) + fclose (procfs); + procfs = 0; +} + +static int +procopen(void) { + return ((procfs = fopen(PROC_FILESYSTEMS, "r")) != NULL); +} + +static char * +procnext(void) { + char line[100]; + static char fsname[50]; + + while (fgets(line, sizeof(line), procfs)) { + if (sscanf (line, "nodev %[^\n]\n", fsname) == 1) continue; + if (sscanf (line, " %[^ \n]\n", fsname) != 1) continue; + return fsname; + } + return 0; } +static int +is_in_proc(char *type) { + char *fsname; + + if (procopen()) { + while ((fsname = procnext()) != NULL) + if (!strcmp(fsname, type)) + return 1; + } + return 0; +} + +static int +already (char *spec, char *node) { + struct mntent *me; + int ret = 1; + + if ((me = getmntfile(node)) != NULL) + error ("mount: according to mtab, %s is already mounted on %s", + me->mnt_fsname, node); + else if ((me = getmntfile(spec)) != NULL) + error ("mount: according to mtab, %s is mounted on %s", + spec, me->mnt_dir); + else + ret = 0; + return ret; +} /* Mount a single file system. Return status, so don't exit on non-fatal errors. */ static int try_mount5 (char *spec, char *node, char **type, int flags, char *mount_opts) { - FILE *procfs_file; - char line[100]; - char fsname[50]; + char *fsname; - if (*type) return mount5 (spec, node, *type, flags & ~MS_NOSYS, mount_opts); - if (( procfs_file = fopen("/proc/filesystems", "r")) == NULL) { - /* If /proc/filesystems is not available, - preserve the old behavior of mount. */ - return mount5 (spec, - node, - FSTYPE_DEFAULT, - flags & ~MS_NOSYS, mount_opts); + if (strcasecmp (*type, "auto") == 0) + *type = NULL; + + if (!*type) { + *type = fstype(spec); + if (!*type && !procopen()) + *type = FSTYPE_DEFAULT; + if (verbose) { + printf ("mount: you didn't specify a filesystem type for %s\n", + spec); + if (*type) + printf (" I will try type %s\n", *type); + else + printf (" I will try all types mentioned in %s\n", + PROC_FILESYSTEMS); + } } - while (fgets(line, sizeof(line), procfs_file)) { - if (sscanf (line, "nodev %[^\n]\n", fsname) == 1) continue; - if (sscanf (line, " %[^ \n]\n", fsname) != 1) continue; + + if (*type) + return mount5 (spec, node, *type, flags & ~MS_NOSYS, mount_opts); + + while ((fsname = procnext()) != NULL) { + if (tested (fsname)) + continue; if (mount5 (spec, node, fsname, flags & ~MS_NOSYS, mount_opts) == 0) { - *type=xstrdup(fsname); - fclose(procfs_file); - return 0; + *type = xstrdup(fsname); + procclose(); + return 0; + } else if (errno != EINVAL) { + *type = "guess"; + procclose(); + return 1; } } - fclose(procfs_file); + procclose(); + *type = NULL; + return -1; } @@ -321,7 +433,7 @@ mount_one (char *spec, char *node, char *type, char *opts, int freq, int pass) int flags; char *extra_opts; char *mount_opts; - int anti_recurse = 0; + static int added_ro = 0; int loop=0; if (type == NULL) @@ -333,8 +445,12 @@ mount_one (char *spec, char *node, char *type, char *opts, int freq, int pass) parse_opts (xstrdup (opts), &flags, &extra_opts); /* root may allow certain types of mounts by ordinary users */ - if (suid && !(flags & MS_USER)) - die (3, "mount: only root can mount %s on %s", spec, node); + if (suid && !(flags & MS_USER)) { + if (already (spec, node)) + die (3, "mount failed"); + else + die (3, "mount: only root can mount %s on %s", spec, node); + } /* quietly succeed for fstab entries that don't get mounted automatically */ if (all && (flags & MS_NOAUTO)) @@ -360,12 +476,9 @@ mount_one (char *spec, char *node, char *type, char *opts, int freq, int pass) if (nfsmount (spec, node, &flags, &extra_opts, &mount_opts) != 0) return 1; #else - die (1, "mount: this version doesn't support the type `nfs'"); + die (1, "mount: this version was compiled without support for the type `nfs'"); #endif - if (!type && !(type = fstype(spec))) - return 1; - block_signals (SIG_BLOCK); if (fake @@ -376,7 +489,7 @@ mount_one (char *spec, char *node, char *type, char *opts, int freq, int pass) { mnt.mnt_fsname = canonicalize (spec); mnt.mnt_dir = canonicalize (node); - mnt.mnt_type = loop?"loop":type; + mnt.mnt_type = loop ? "loop" : type; mnt.mnt_opts = fix_opts_string (flags & ~MS_NOMTAB, loop?opts:extra_opts); mnt.mnt_freq = freq; @@ -411,6 +524,10 @@ mount_one (char *spec, char *node, char *type, char *opts, int freq, int pass) block_signals (SIG_UNBLOCK); /* Mount failed, complain, but don't die. */ + + if (type == 0) + error ("mount: you must specify the filesystem type"); + else switch (mnt_err) { case EPERM: @@ -421,11 +538,15 @@ mount_one (char *spec, char *node, char *type, char *opts, int freq, int pass) break; case EBUSY: error ("mount: %s already mounted or %s busy", spec, node); + already (spec, node); break; case ENOENT: { struct stat statbuf; - if (stat (node, &statbuf)) + if (lstat (node, &statbuf)) error ("mount: mount point %s does not exist", node); + else if (stat (node, &statbuf)) + error ("mount: mount point %s is a symbolic link to nowhere", + node); else if (stat (spec, &statbuf)) error ("mount: special device %s does not exist", spec); else { @@ -433,7 +554,7 @@ mount_one (char *spec, char *node, char *type, char *opts, int freq, int pass) perror("mount"); } break; - } + } case ENOTDIR: error ("mount: mount point %s is not a directory", node); break; case EINVAL: @@ -443,31 +564,37 @@ mount_one (char *spec, char *node, char *type, char *opts, int freq, int pass) case EIO: error ("mount: %s: can't read superblock", spec); break; case ENODEV: - error ("mount: fs type %s not supported by kernel", type); break; + if (is_in_proc(type)) + error("mount: %s has wrong major or minor number", spec); + else if (procfs) + error ("mount: fs type %s not supported by kernel", type); + else + error ("mount: %s has wrong device number or fs type %s not supported", + spec, type); + break; case ENOTBLK: error ("mount: %s is not a block device", spec); break; case ENXIO: error ("mount: %s is not a valid block device", spec); break; case EACCES: /* pre-linux 1.1.38 */ case EROFS: /* linux 1.1.38 and later */ - if (anti_recurse) - { - error ("mount: block device %s is not permitted on its filesystem", spec); + if (added_ro) { + error ("mount: block device %s is not permitted on its filesystem", + spec); break; - } - else - { - anti_recurse++; - if (opts) - { - opts = realloc(xstrdup(opts), strlen(opts)+3); + } else { + added_ro = 1; + if (opts) { + opts = realloc(xstrdup(opts), strlen(opts)+4); strcat(opts, ",ro"); - } - else - opts = "ro"; - error ("mount: block device %s is write-protected, mounting read-only", spec); - return mount_one (spec, node, type, opts, freq, pass); - } + } else + opts = "ro"; + if (type && !strcmp(type, "guess")) + type = 0; + error ("mount: block device %s is write-protected, " + "mounting read-only", spec); + return mount_one (spec, node, type, opts, freq, pass); + } break; default: error ("mount: %s", strerror (mnt_err)); break; @@ -514,6 +641,7 @@ mount_all (string_list types) } status = 0; + if (!setfsent()) return 1; while ((fstab = getfsent ()) != NULL) if (matching_type (fstab->mnt_type, types) && !streq (fstab->mnt_dir, "/") @@ -592,6 +720,7 @@ static void usage (FILE *fp, int n) { fprintf (fp, "%s", usage_string); + unlock_mtab(); exit (n); } @@ -629,7 +758,7 @@ main (int argc, char *argv[]) ++verbose; break; case 'V': /* version */ - printf ("%s\n", version); + printf ("mount: %s\n", version); exit (0); case 'w': /* mount read/write */ ++readwrite; diff --git a/mount/nfs.5 b/mount/nfs.5 index ee5203f5..cdfba803 100644 --- a/mount/nfs.5 +++ b/mount/nfs.5 @@ -195,7 +195,7 @@ interrupted. .SH FILES .I /etc/fstab .SH "SEE ALSO" -.BR fstab "(5), " mount "(8), " umount (8) +.BR fstab "(5), " mount "(8), " umount "(8), " exports (5) .SH AUTHOR "Rick Sladkey" <jrs@world.std.com> .SH BUGS diff --git a/mount/sundries.c b/mount/sundries.c index 45e0e14d..5ebf0195 100644 --- a/mount/sundries.c +++ b/mount/sundries.c @@ -1,9 +1,12 @@ /* * Support functions. Exported functions are prototyped in sundries.h. * sundries.c,v 1.1.1.1 1993/11/18 08:40:51 jrs Exp + * + * added fcntl locking by Kjetil T. (kjetilho@math.uio.no) - aeb, 950927 */ #include "sundries.h" +#include "mount.h" /* File pointer for /etc/mtab. */ FILE *F_mtab = NULL; @@ -14,6 +17,9 @@ FILE *F_temp = NULL; /* File descriptor for lock. Value tested in unlock_mtab() to remove race. */ static int lock = -1; +/* Flag for already existing lock file. */ +static int old_lockfile = 1; + /* String list constructor. (car() and cdr() are defined in "sundries.h"). */ string_list cons (char *a, const string_list b) @@ -75,6 +81,7 @@ error (const char *fmt, ...) { va_list args; + if (mount_quiet) return; va_start (args, fmt); vfprintf (stderr, fmt, args); fprintf (stderr, "\n"); @@ -103,6 +110,12 @@ handler (int sig) die (2, "%s", sys_siglist[sig]); } +static void +setlkw_timeout (int sig) +{ + /* nothing, fcntl will fail anyway */ +} + /* Create the lock file. The lock file will be removed if we catch a signal or when we exit. The value of lock is tested to remove the race. */ void @@ -110,20 +123,54 @@ lock_mtab (void) { int sig = 0; struct sigaction sa; + struct flock flock; /* If this is the first time, ensure that the lock will be removed. */ if (lock < 0) { + struct stat st; sa.sa_handler = handler; sa.sa_flags = 0; sigfillset (&sa.sa_mask); while (sigismember (&sa.sa_mask, ++sig) != -1) - sigaction (sig, &sa, (struct sigaction *) 0); - - if ((lock = open (MOUNTED_LOCK, O_WRONLY|O_CREAT|O_EXCL, 0)) < 0) - die (2, "can't create lock file %s: %s", - MOUNTED_LOCK, strerror (errno)); + { + if (sig == SIGALRM) + sa.sa_handler = setlkw_timeout; + else + sa.sa_handler = handler; + sigaction (sig, &sa, (struct sigaction *) 0); + } + + /* This stat is performed so we know when not to be overly eager + when cleaning up after signals. The window between stat and + open is not significant. */ + if (lstat (MOUNTED_LOCK, &st) < 0 && errno == ENOENT) + old_lockfile = 0; + + lock = open (MOUNTED_LOCK, O_WRONLY|O_CREAT, 0); + if (lock < 0) + { + die (2, "can't create lock file %s: %s", + MOUNTED_LOCK, strerror (errno)); + } + + flock.l_type = F_WRLCK; + flock.l_whence = SEEK_SET; + flock.l_start = 0; + flock.l_len = 0; + + alarm(LOCK_BUSY); + if (fcntl (lock, F_SETLKW, &flock) < 0) + { + close (lock); + /* The file should not be removed */ + lock = -1; + die (2, "can't lock lock file %s: %s", + MOUNTED_LOCK, errno == EINTR ? "timed out" : strerror (errno)); + } + /* We have now access to the lock, and it can always be removed */ + old_lockfile = 0; } } @@ -133,8 +180,9 @@ unlock_mtab (void) { if (lock != -1) { - close( lock ); - unlink (MOUNTED_LOCK); + close (lock); + if (!old_lockfile) + unlink (MOUNTED_LOCK); } } diff --git a/mount/sundries.h b/mount/sundries.h index ba878c9b..77d8d32f 100644 --- a/mount/sundries.h +++ b/mount/sundries.h @@ -18,8 +18,20 @@ #include <string.h> #include <unistd.h> +#if 0 +#include <linux/version.h> +#if LINUX_VERSION_CODE >= 0x010302 +#define SUPPORT_PRIORITIES +#endif +#endif + +#ifdef SUPPORT_PRIORITIES +#include <linux/swap.h> +#endif + #include "fstab.h" +extern int mount_quiet; #define streq(s, t) (strcmp ((s), (t)) == 0) @@ -27,7 +39,7 @@ #define MOUNTED_LOCK "/etc/mtab~" #define MOUNTED_TEMP "/etc/mtab.tmp" #define _PATH_FSTAB "/etc/fstab" -#define LOCK_BUSY 3 +#define LOCK_BUSY 10 /* File pointer for /etc/mtab. */ extern FILE *F_mtab; diff --git a/mount/swapon.8 b/mount/swapon.8 index 44c84168..911855dc 100644 --- a/mount/swapon.8 +++ b/mount/swapon.8 @@ -35,18 +35,23 @@ .\" Sat Mar 6 20:46:02 1993: Modified by faith@cs.unc.edu .\" Sat Oct 9 09:35:30 1993: Converted to man format by faith@cs.unc.edu .\" Sat Nov 27 20:22:42 1993: Updated authorship information, faith@cs.unc.edu +.\" Mon Sep 25 14:12:38 1995: Added -v and -p information .\" -.TH SWAPON 8 "27 November 1993" "Linux 0.99" "Linux Programmer's Manual" +.TH SWAPON 8 "25 September 1995" "Linux 1.x" "Linux Programmer's Manual" .SH NAME swapon, swapoff \- enable/disable devices and files for paging and swapping .SH SYNOPSIS -.B /etc/swapon \-a +.B /sbin/swapon [\-h \-V] .br -.BI /etc/swapon " specialfile " ... +.B /sbin/swapon \-a [\-v] .br -.B /etc/swapoff \-a +.BI "/sbin/swapon [\-v] [\-p " "priority" "] " " specialfile " ... .br -.BI /etc/swapoff " specialfile " ... +.B /sbin/swapoff [\-h \-V] +.br +.B /sbin/swapoff \-a +.br +.BI /sbin/swapoff " specialfile " ... .SH DESCRIPTION .B Swapon is used to specify devices on which paging and swapping are to take place. @@ -59,10 +64,23 @@ is interleaved across several devices and files. Normally, the first form is used: .TP +.B \-h +Provide help +.TP +.B \-V +Display version +.TP .B \-a All devices marked as ``sw'' swap devices in .I /etc/fstab are made available. +.TP +.BI \-p " priority" +Specify priority for +.BR swapon . +This option is only available if +.B swapon +was compiled under and is used under a 1.3.2 or later kernel. .PP .B Swapoff disables swapping on the specified devices and files, or on all swap @@ -75,10 +93,10 @@ flag is given. .BR swapon "(2), " swapoff "(2), " fstab "(5), " init "(8), " mkswap (8), .BR rc "(8), " mount (8) .SH FILES -.I /dev/hd[ab]? +.I /dev/hd?? standard paging devices .br -.I /dev/sd[ab]? +.I /dev/sd?? standard (SCSI) paging devices .br .I /etc/fstab diff --git a/mount/swapon.c b/mount/swapon.c index 58403302..331238f0 100644 --- a/mount/swapon.c +++ b/mount/swapon.c @@ -7,6 +7,9 @@ /* Nonzero for chatty (-v). This is a nonstandard flag (not in BSD). */ int verbose = 0; +#ifdef SUPPORT_PRIORITIES +int priority = -1; /* non-prioritized swap by default */ +#endif extern char version[]; static char *program_name; @@ -14,16 +17,27 @@ static struct option longopts[] = { { "all", 0, 0, 'a' }, { "help", 0, 0, 'h' }, +#ifdef SUPPORT_PRIORITIES + { "priority", required_argument, 0, 'p' }, +#endif { "verbose", 0, 0, 'v' }, { "version", 0, 0, 'V' }, { NULL, 0, 0, 0 } }; +#ifdef SUPPORT_PRIORITIES const char *usage_string = "\ usage: %s [-hV]\n\ %s -a [-v]\n\ - %s [-v] special ...\n\ + %s [-v] [-p priority] special ...\n\ "; +#else +const char *usage_string = "\ +usage: %s [-hV]\n\ + %s -a [-v]\n\ + %s [-v] [-p priority] special ...\n\ +"; +#endif static void usage (FILE *fp, int n) @@ -33,17 +47,33 @@ usage (FILE *fp, int n) } static int +#ifdef SUPPORT_PRIORITIES +swap (const char *special, int prio) +#else swap (const char *special) +#endif { int status; +#ifdef SUPPORT_PRIORITIES + int flags; +#endif if (verbose) printf("%s on device %s\n", program_name, special); - if (streq (program_name, "swapon")) - status = swapon (special); - else - status = swapoff (special); + if (streq (program_name, "swapon")) { +#ifdef SUPPORT_PRIORITIES + flags = 0; + if (prio >= 0) { + flags = SWAP_FLAG_PREFER + | ((prio & SWAP_FLAG_PRIO_MASK) << SWAP_FLAG_PRIO_SHIFT); + } + status = swapon (special, flags); +#else + status = swapon (special); +#endif + } else + status = swapoff (special); if (status < 0) fprintf (stderr, "%s: %s: %s\n", program_name, special, strerror (errno)); @@ -64,7 +94,11 @@ main (int argc, char *argv[]) else program_name = argv[0]; +#ifdef SUPPORT_PRIORITIES + while ((c = getopt_long (argc, argv, "ahp:vV", longopts, NULL)) != EOF) +#else while ((c = getopt_long (argc, argv, "ahvV", longopts, NULL)) != EOF) +#endif switch (c) { case 'a': /* all */ @@ -73,11 +107,16 @@ main (int argc, char *argv[]) case 'h': /* help */ usage (stdout, 0); break; +#ifdef SUPPORT_PRIORITIES + case 'p': /* priority */ + priority = atoi(optarg); + break; +#endif case 'v': /* be chatty */ ++verbose; break; case 'V': /* version */ - printf ("%s\n", version); + printf ("swapon: %s\n", version); exit (0); case 0: break; @@ -94,7 +133,25 @@ main (int argc, char *argv[]) { while ((fstab = getfsent()) != NULL) if (streq (fstab->fs_type, FSTAB_SW)) - status |= swap (fstab->fs_spec); + { +#ifdef SUPPORT_PRIORITIES + /* parse mount options; */ + char *opt, *opts = strdup(fstab->fs_mntopts); + + for (opt = strtok (opts, ","); + opt != NULL; + opt = strtok (NULL, ",")) + { + if (strncmp(opt, "pri=", 4) == 0) + { + priority = atoi(opt+4); + } + } + status |= swap (fstab->fs_spec, priority); +#else + status |= swap (fstab->fs_spec); +#endif + } } else if (*argv == NULL) { @@ -102,8 +159,13 @@ main (int argc, char *argv[]) } else { - while (*argv != NULL) - status |= swap (*argv++); + while (*argv != NULL) { +#ifdef SUPPORT_PRIORITIES + status |= swap (*argv++,priority); +#else + status |= swap (*argv++); +#endif + } } return status; } diff --git a/mount/umount.c b/mount/umount.c index c3cfee71..236f0524 100644 --- a/mount/umount.c +++ b/mount/umount.c @@ -5,6 +5,9 @@ * Wed Sep 14 22:43:54 1994: Sebastian Lederer * (lederer@next-pc.informatik.uni-bonn.de) added support for sending an * unmount RPC call to the server when an NFS-filesystem is unmounted. + * + * Tue Sep 26 16:33:09 1995: Added patches from Greg Page (greg@caldera.com) + * so that NetWare filesystems can be unmounted. */ #include "sundries.h" @@ -44,7 +47,7 @@ static int xdr_dir(XDR *xdrsp, char *dirp) /* Umount a single device. Return a status code, so don't exit on a non-fatal error. We lock/unlock around each umount. */ static int -umount_one (const char *spec, const char *node) +umount_one (const char *spec, const char *node, const char *type) { int umnt_err; int isroot; @@ -75,7 +78,7 @@ umount_one (const char *spec, const char *node) #ifdef HAVE_NFS strcpy(buffer,spec); /* spec is constant so must use own buffer */ - if((p=strchr(buffer,':'))) + if(!strcasecmp(type, "nfs") && (p=strchr(buffer,':'))) { *p='\0'; strcpy(hostname,buffer); @@ -174,7 +177,9 @@ fail: case EIO: error ("umount: %s: can't write superblock", spec); break; case EBUSY: - error ("umount: %s: device is busy", spec); break; + /* Let us hope fstab has a line "proc /proc ..." + and not "none /proc ..."*/ + error ("umount: %s: device is busy", spec); break; case ENOENT: error ("umount: %s: not mounted", spec); break; case EPERM: @@ -197,6 +202,7 @@ umount_all (string_list types) { string_list spec_list = NULL; string_list node_list = NULL; + string_list type_list = NULL; struct mntent *mnt; int errors; @@ -207,6 +213,7 @@ umount_all (string_list types) { spec_list = cons (xstrdup (mnt->mnt_fsname), spec_list); node_list = cons (xstrdup (mnt->mnt_dir), node_list); + type_list = cons (xstrdup (mnt->mnt_type), type_list); } close_mtab (); @@ -214,9 +221,10 @@ umount_all (string_list types) errors = 0; while (spec_list != NULL) { - errors |= umount_one (car (spec_list), car (node_list)); + errors |= umount_one (car (spec_list), car (node_list), car (type_list)); spec_list = cdr (spec_list); node_list = cdr (node_list); + type_list = cdr (type_list); } sync (); @@ -238,7 +246,7 @@ static struct option longopts[] = char *usage_string = "\ usage: umount [-hV]\n\ umount -a [-v] [-t vfstypes]\n\ - umount [-v] special | node\n\ + umount [-v] special | node...\n\ "; static void @@ -248,6 +256,8 @@ usage (FILE *fp, int n) exit (n); } +int mount_quiet = 0; + int main (int argc, char *argv[]) { @@ -281,7 +291,7 @@ main (int argc, char *argv[]) ++verbose; break; case 'V': /* version */ - printf ("%s\n", version); + printf ("umount: %s\n", version); exit (0); case 't': /* specify file system type */ types = parse_list (optarg); @@ -305,9 +315,9 @@ main (int argc, char *argv[]) if (all) result = umount_all (types); - else if (argc != 1) + else if (argc < 1) usage (stderr, 2); - else + else while (argc--) { file = canonicalize (*argv); /* mtab paths are canonicalized */ @@ -326,7 +336,7 @@ main (int argc, char *argv[]) if (suid) { if (!mnt) - die (2, "umount: %s is not mounted", file); + die (2, "umount: %s is not mounted (according to mtab)", file); if (!(fs = getfsspec (file)) && !(fs = getfsfile (file))) die (2, "umount: %s is not in the fstab", file); if (!streq (mnt->mnt_fsname, fs->mnt_fsname) @@ -345,9 +355,11 @@ main (int argc, char *argv[]) } if (mnt) - result = umount_one (xstrdup (mnt->mnt_fsname), xstrdup(mnt->mnt_dir)); + result = umount_one (xstrdup (mnt->mnt_fsname), xstrdup(mnt->mnt_dir), + xstrdup(mnt->mnt_type)); else - result = umount_one (*argv, *argv); + result = umount_one (*argv, *argv, *argv); + } exit (result); } diff --git a/mount/version.c b/mount/version.c index ece944d2..47aed1dc 100644 --- a/mount/version.c +++ b/mount/version.c @@ -1 +1 @@ -char version[] = "(u)mount: version from util-linux-2.2"; +char version[] = "version from util-linux-2.5"; |