summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarel Zak2006-12-07 00:26:30 +0100
committerKarel Zak2006-12-07 00:26:30 +0100
commita47f2e66141271cde40ee5190acf93d7878bc93d (patch)
treef41145d1e432fdb55aabcf600fb9311b7d83d75c
parentImported from util-linux-2.12l tarball. (diff)
downloadkernel-qcow2-util-linux-a47f2e66141271cde40ee5190acf93d7878bc93d.tar.gz
kernel-qcow2-util-linux-a47f2e66141271cde40ee5190acf93d7878bc93d.tar.xz
kernel-qcow2-util-linux-a47f2e66141271cde40ee5190acf93d7878bc93d.zip
Imported from util-linux-2.12m tarball.
-rw-r--r--HISTORY7
-rw-r--r--VERSION2
-rw-r--r--fdisk/cfdisk.c71
-rw-r--r--fdisk/fdisk.c8
-rw-r--r--fdisk/i386_sys_types.c1
-rw-r--r--mount/mount.8111
-rw-r--r--mount/mount.c41
-rw-r--r--mount/mount_by_label.c5
-rw-r--r--mount/sundries.c14
-rw-r--r--mount/sundries.h1
-rw-r--r--mount/swapon.86
-rw-r--r--mount/swapon.c18
12 files changed, 225 insertions, 60 deletions
diff --git a/HISTORY b/HISTORY
index 3cdcef28a..aea7683b1 100644
--- a/HISTORY
+++ b/HISTORY
@@ -1,3 +1,10 @@
+util-linux 2.12m
+
+* cfdisk: recognize JFS, support reiserfs labels (flavio.stanchina@tin.it)
+* mount: fix option parsing bug
+* mount.8: several updates
+* swapon.8: document -v option
+
util-linux 2.12l
* Makefile: remove cat-id-tbl.c upon make clean
diff --git a/VERSION b/VERSION
index 64d500a2f..14a1f815a 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-2.12l
+2.12m
diff --git a/fdisk/cfdisk.c b/fdisk/cfdisk.c
index 149ee7619..9c0e7875c 100644
--- a/fdisk/cfdisk.c
+++ b/fdisk/cfdisk.c
@@ -51,6 +51,8 @@
* XFS label recognition.
* Thu Nov 22 15:42:56 CET 2001 <flavio.stanchina@tin.it>
* ext3 and ReiserFS recognition.
+ * Sun Oct 12 17:43:43 CEST 2003 <flavio.stanchina@tin.it>
+ * JFS recognition; ReiserFS label recognition.
*
****************************************************************************/
@@ -377,6 +379,8 @@ partition_type_text(int i) {
return _("Linux ext3");
else if (!strcmp(p_info[i].fstype, "xfs"))
return _("Linux XFS");
+ else if (!strcmp(p_info[i].fstype, "jfs"))
+ return _("Linux JFS");
else if (!strcmp(p_info[i].fstype, "reiserfs"))
return _("Linux ReiserFS");
else
@@ -595,17 +599,26 @@ get_dos_label(int i) {
#define REISERFS_SUPER_MAGIC_STRING "ReIsErFs"
#define REISER2FS_SUPER_MAGIC_STRING "ReIsEr2Fs"
struct reiserfs_super_block {
- char s_dummy0[ 52];
- char s_magic [ 12];
- char s_dummy1[140];
+ char s_dummy0[52];
+ char s_magic [10];
+ char s_dummy1[38];
+ u_char s_label[16];
};
+#define REISERFSLABELSZ sizeof(reiserfsb.s_label)
static int
-is_reiserfs_magic_string(const struct reiserfs_super_block *rs) {
- return (!strncmp(rs->s_magic, REISERFS_SUPER_MAGIC_STRING,
- strlen(REISERFS_SUPER_MAGIC_STRING)) ||
- !strncmp(rs->s_magic, REISER2FS_SUPER_MAGIC_STRING,
- strlen(REISER2FS_SUPER_MAGIC_STRING)));
+has_reiserfs_magic_string(const struct reiserfs_super_block *rs, int *is_3_6) {
+ if (!strncmp(rs->s_magic, REISERFS_SUPER_MAGIC_STRING,
+ strlen(REISERFS_SUPER_MAGIC_STRING))) {
+ *is_3_6 = 0;
+ return 1;
+ }
+ if (!strncmp(rs->s_magic, REISER2FS_SUPER_MAGIC_STRING,
+ strlen(REISER2FS_SUPER_MAGIC_STRING))) {
+ *is_3_6 = 1;
+ return 1;
+ }
+ return 0;
}
static void
@@ -627,6 +640,20 @@ get_linux_label(int i) {
#define REISERFS_DISK_OFFSET_IN_BYTES (64 * 1024)
struct reiserfs_super_block reiserfsb;
+ int reiserfs_is_3_6;
+
+#define JFS_SUPER1_OFF 0x8000
+#define JFS_MAGIC "JFS1"
+#define JFSLABELSZ 16
+ struct jfs_super_block {
+ char s_magic[4];
+ u_char s_version[4];
+ u_char s_dummy1[93];
+ char s_fpack[11];
+ u_char s_dummy2[24];
+ u_char s_uuid[16];
+ char s_label[JFSLABELSZ];
+ } jfsb;
#define XFS_SUPER_MAGIC "XFSB"
#define XFSLABELSZ 12
@@ -661,7 +688,7 @@ get_linux_label(int i) {
offset = (p_info[i].first_sector + p_info[i].offset) * SECTOR_SIZE + 0;
if (ext2_llseek(fd, offset, SEEK_SET) == offset
&& read(fd, &xfsb, sizeof(xfsb)) == sizeof(xfsb)
- && !strcmp(xfsb.s_magic, XFS_SUPER_MAGIC)) {
+ && !strncmp(xfsb.s_magic, XFS_SUPER_MAGIC, 4)) {
label = xfsb.s_fname;
for(j=0; j<XFSLABELSZ && j<LABELSZ && isprint(label[j]); j++)
p_info[i].volume_label[j] = label[j];
@@ -670,12 +697,34 @@ get_linux_label(int i) {
return;
}
+ /* jfs? */
+ offset = (p_info[i].first_sector + p_info[i].offset) * SECTOR_SIZE
+ + JFS_SUPER1_OFF;
+ if (ext2_llseek(fd, offset, SEEK_SET) == offset
+ && read(fd, &jfsb, sizeof(jfsb)) == sizeof(jfsb)
+ && !strncmp(jfsb.s_magic, JFS_MAGIC, strlen(JFS_MAGIC))) {
+ label = jfsb.s_label;
+ for(j=0; j<JFSLABELSZ && j<LABELSZ && isprint(label[j]); j++)
+ p_info[i].volume_label[j] = label[j];
+ p_info[i].volume_label[j] = 0;
+ strncpy(p_info[i].fstype, "jfs", FSTYPESZ);
+ return;
+ }
+
/* reiserfs? */
offset = (p_info[i].first_sector + p_info[i].offset) * SECTOR_SIZE
+ REISERFS_DISK_OFFSET_IN_BYTES;
if (ext2_llseek(fd, offset, SEEK_SET) == offset
&& read(fd, &reiserfsb, 1024) == 1024
- && is_reiserfs_magic_string(&reiserfsb)) {
+ && has_reiserfs_magic_string(&reiserfsb, &reiserfs_is_3_6)) {
+ if (reiserfs_is_3_6) {
+ /* label only on version 3.6 onward */
+ label = reiserfsb.s_label;
+ for(j=0; j<REISERFSLABELSZ && j<LABELSZ &&
+ isprint(label[j]); j++)
+ p_info[i].volume_label[j] = label[j];
+ p_info[i].volume_label[j] = 0;
+ }
strncpy(p_info[i].fstype, "reiserfs", FSTYPESZ);
return;
}
@@ -2917,7 +2966,7 @@ main(int argc, char **argv)
break;
default:
usage(argv[0]);
- break;
+ exit(1);
}
}
break;
diff --git a/fdisk/fdisk.c b/fdisk/fdisk.c
index a8385420c..1aafdd286 100644
--- a/fdisk/fdisk.c
+++ b/fdisk/fdisk.c
@@ -580,6 +580,9 @@ static int
warn_geometry(void) {
char *m = NULL;
int prev = 0;
+
+ if (sgi_label) /* cannot set cylinders etc anyway */
+ return 0;
if (!heads)
prev = test_c(&m, _("heads"));
if (!sectors)
@@ -2190,7 +2193,10 @@ reread_partition_table(int leave) {
"information.\n"));
if (leave) {
- close(fd);
+ if (fsync(fd) || close(fd)) {
+ fprintf(stderr, _("\nError closing file\n"));
+ exit(1);
+ }
printf(_("Syncing disks.\n"));
sync();
diff --git a/fdisk/i386_sys_types.c b/fdisk/i386_sys_types.c
index fb70b0851..e08a9b2a5 100644
--- a/fdisk/i386_sys_types.c
+++ b/fdisk/i386_sys_types.c
@@ -59,6 +59,7 @@ struct systypes i386_sys_types[] = {
{0x85, N_("Linux extended")},
{0x86, N_("NTFS volume set")},
{0x87, N_("NTFS volume set")},
+ {0x88, N_("Linux plaintext")},
{0x8e, N_("Linux LVM")},
{0x93, N_("Amoeba")},
{0x94, N_("Amoeba BBT")}, /* (bad block table) */
diff --git a/mount/mount.8 b/mount/mount.8
index b177feb61..767db5f79 100644
--- a/mount/mount.8
+++ b/mount/mount.8
@@ -1,4 +1,4 @@
-.\" Copyright (c) 1996 Andries Brouwer
+.\" Copyright (c) 1996-2004 Andries Brouwer
.\"
.\" This page is somewhat derived from a page that was
.\" (c) 1980, 1989, 1991 The Regents of the University of California
@@ -39,7 +39,7 @@
.\" 010725, Nikita Danilov <NikitaDanilov@Yahoo.COM>: reiserfs options
.\" 011124, Karl Eichwalder <ke@gnu.franken.de>: tmpfs options
.\"
-.TH MOUNT 8 "14 September 1997" "Linux 2.0" "Linux Programmer's Manual"
+.TH MOUNT 8 "2004-12-16" "Linux 2.6" "Linux Programmer's Manual"
.SH NAME
mount \- mount a file system
.SH SYNOPSIS
@@ -183,7 +183,7 @@ However, when
.I fstab
contains the
.B user
-option on a line, then anybody can mount the corresponding system.
+option on a line, anybody can mount the corresponding system.
.LP
Thus, given a line
.RS
@@ -317,7 +317,9 @@ permission to read the disk device (e.g. be suid root) for this to work.
One can set such a label for ext2 or ext3 using the
.BR e2label (8)
utility, or for XFS using
-.BR xfs_admin (8).
+.BR xfs_admin (8),
+or for reiserfs using
+.BR reiserfstune (8).
.TP
.B \-n
Mount without writing in
@@ -361,7 +363,7 @@ These two options require the file
The argument following the
.B \-t
is used to indicate the file system type. The file system types which are
-currently supported are:
+currently supported include:
.IR adfs ,
.IR affs ,
.IR autofs ,
@@ -566,6 +568,10 @@ This option implies the options
(unless overridden by subsequent options, as in the option line
.BR group,dev,suid ).
.TP
+.B mand
+Allow mandatory locks on this filesystem. See
+.BR fcntl (2).
+.TP
.B _netdev
The filesystem resides on a device that requires network access
(used to prevent the system from attempting to mount these filesystems
@@ -589,6 +595,9 @@ Do not allow direct execution of any binaries on the mounted file system.
(Until recently it was possible to run binaries anyway using a command like
/lib/ld*.so /mnt/binary. This trick fails since Linux 2.4.25 / 2.6.0.)
.TP
+.B nomand
+Do not allow mandatory locks on this filesystem.
+.TP
.B nosuid
Do not allow set-user-identifier or set-group-identifier bits to take
effect. (This seems safe, but is in fact rather unsafe if you have
@@ -658,6 +667,11 @@ The following options apply only to certain file systems.
We sort them by file system. They all follow the
.B \-o
flag.
+
+What options are supported depends a bit on the running kernel.
+More info may be found in the kernel source subdirectory
+.IR Documentation/filesystems .
+
.SH "Mount options for adfs"
.TP
\fBuid=\fP\fIvalue\fP and \fBgid=\fP\fIvalue\fP
@@ -877,7 +891,7 @@ Support "user." extended attributes (or not).
.SH "Mount options for ext3"
-The `ext3' file system is version of the ext2 file system which has been
+The `ext3' file system is a version of the ext2 file system which has been
enhanced with journalling. It supports the same options as ext2 as
well as the following additions:
.\" .TP
@@ -899,6 +913,10 @@ Do not load the ext3 file system's journal on mounting.
.TP
.BR data=journal " / " data=ordered " / " data=writeback
Specifies the journalling mode for file data. Metadata is always journaled.
+To use modes other than
+.B ordered
+on the root file system, pass the mode to the kernel as boot parameter, e.g.
+.IR rootflags=data=journal .
.RS
.TP
.B journal
@@ -915,6 +933,12 @@ file system after its metadata has been committed to the journal.
This is rumoured to be the highest-throughput option. It guarantees
internal file system integrity, however it can allow old data to appear
in files after a crash and journal recovery.
+.RE
+.TP
+.BI commit= nrsec
+Sync all data and metadata every
+.I nrsec
+seconds. The default value is 5 seconds. Zero means default.
.SH "Mount options for fat"
(Note:
@@ -930,8 +954,8 @@ filesystems.)
Set blocksize (default 512).
.TP
\fBuid=\fP\fIvalue\fP and \fBgid=\fP\fIvalue\fP
-Set the owner and group of all files. (Default: the uid and gid
-of the current process.)
+Set the owner and group of all files.
+(Default: the uid and gid of the current process.)
.TP
.BI umask= value
Set the umask (the bitmask of the permissions that are
@@ -942,12 +966,14 @@ The value is given in octal.
.BI dmask= value
Set the umask applied to directories only.
The default is the umask of the current process.
-The value is given in octal. Present since 2.5.43.
+The value is given in octal.
+.\" Present since Linux 2.5.43.
.TP
.BI fmask= value
Set the umask applied to regular files only.
The default is the umask of the current process.
-The value is given in octal. Present since 2.5.43.
+The value is given in octal.
+.\" Present since Linux 2.5.43.
.TP
.BI check= value
Three different levels of pickyness can be chosen:
@@ -1040,6 +1066,33 @@ although they fail. Use with caution!
Various misguided attempts to force Unix or DOS conventions
onto a FAT file system.
+.SH "Mount options for hfs"
+.TP
+.BI creator= cccc ", type=" cccc
+Set the creator/type values as shown by the MacOS finder
+used for creating new files. Default values: '????'.
+.TP
+.BI uid= n ", gid=" n
+Set the owner and group of all files.
+(Default: the uid and gid of the current process.)
+.TP
+.BI dir_umask= n ", file_umask=" n ", umask=" n
+Set the umask used for all directories, all regular files, or all
+files and directories. Defaults to the umask of the current process.
+.TP
+.BI session= n
+Select the CDROM session to mount.
+Defaults to leaving that decision to the CDROM driver.
+This option will fail with anything but a CDROM as underlying device.
+.TP
+.BI part= n
+Select partition number n from the device.
+Only makes sense for CDROMS.
+Defaults to not parsing the partition table at all.
+.TP
+.B quiet
+Don't complain about invalid mount options.
+
.SH "Mount options for hpfs"
.TP
\fBuid=\fP\fIvalue\fP and \fBgid=\fP\fIvalue\fP
@@ -1316,7 +1369,13 @@ Do not use locking. Do not start lockd.
.BI iocharset= name
Character set to use when returning file names.
Unlike VFAT, NTFS suppresses names that contain
-unconvertible characters.
+unconvertible characters. Deprecated.
+.\" since 2.5.11
+.TP
+.BI nls= name
+New name for the option earlier called
+.IR iocharset .
+.\" since 2.5.11
.TP
.BR utf8
Use UTF-8 for converting file names.
@@ -1371,7 +1430,7 @@ collisions.
.B tea
A Davis-Meyer function implemented by Jeremy Fitzhardinge.
It uses hash permuting bits in the name. It gets high randomness
-and, therefore, low probability of hash collisions at come CPU cost.
+and, therefore, low probability of hash collisions at some CPU cost.
This may be used if EHASHCOLLISION errors are experienced with the r5 hash.
.TP
.B r5
@@ -1458,7 +1517,7 @@ or
for Ki, Mi, Gi (binary kilo, mega and giga) and can be changed on remount.
.TP
.BI size= nbytes
-Override default size of the filesystem.
+Override default maximum size of the filesystem.
The size is given in bytes, and rounded down to entire pages.
The default is half of the memory.
.TP
@@ -1493,14 +1552,14 @@ Show otherwise hidden files.
.B undelete
Show deleted files in lists.
.TP
-.B strict
-Set strict conformance (unused).
-.TP
-.B utf8
-(unused).
+.B nostrict
+Unset strict conformance.
+.\" .TP
+.\" .B utf8
+.\" (unused).
.TP
.B iocharset
-(unused).
+Set the NLS character set.
.TP
.B bs=
Set the block size. (May not work unless 2048.)
@@ -1724,6 +1783,9 @@ Filesystems mounted
.B norecovery
must be mounted read-only or the mount will fail.
.TP
+.B nouuid
+Ignore the filesystem uuid. This avoids errors for duplicate uuids.
+.TP
.B osyncisdsync
Make writes to files opened with the O_SYNC flag set behave
as if the O_DSYNC flag had been used instead.
@@ -1778,10 +1840,14 @@ to correspond to the file
.IR /tmp/fdimage ,
and then mount this device on
.IR /mnt .
+
This type of mount knows about three options, namely
.BR loop ", " offset " and " encryption ,
that are really options to
-.BR losetup (8).
+.BR \%losetup (8).
+(These options can be used in addition to those specific
+to the filesystem type.)
+
If no explicit loop device is mentioned
(but just an option `\fB\-o loop\fP' is given), then
.B mount
@@ -1885,6 +1951,11 @@ or
.B umask
for the
.IR fatfs ).
+.PP
+Mount by label or uuid will work only if your devices have the names listed in
+.IR /proc/partitions .
+In particular, it may well fail if the kernel was compiled with devfs
+but devfs is not mounted.
.SH HISTORY
A
.B mount
diff --git a/mount/mount.c b/mount/mount.c
index e911133b2..3a59c370c 100644
--- a/mount/mount.c
+++ b/mount/mount.c
@@ -254,7 +254,7 @@ my_free(const void *s) {
* For the options uid= and gid= replace user or group name by its value.
*/
static inline void
-parse_opt (const char *opt, int *mask, char *extra_opts) {
+parse_opt(const char *opt, int *mask, char *extra_opts, int len) {
const struct opt_map *om;
for (om = opt_map; om->opt != NULL; om++)
@@ -278,7 +278,9 @@ parse_opt (const char *opt, int *mask, char *extra_opts) {
return;
}
- if (*extra_opts)
+ len -= strlen(extra_opts);
+
+ if (*extra_opts && --len > 0)
strcat(extra_opts, ",");
/* convert nonnumeric ids to numeric */
@@ -288,7 +290,8 @@ parse_opt (const char *opt, int *mask, char *extra_opts) {
if (pw) {
sprintf(uidbuf, "uid=%d", pw->pw_uid);
- strcat(extra_opts, uidbuf);
+ if ((len -= strlen(uidbuf)) > 0)
+ strcat(extra_opts, uidbuf);
return;
}
}
@@ -298,12 +301,14 @@ parse_opt (const char *opt, int *mask, char *extra_opts) {
if (gr) {
sprintf(gidbuf, "gid=%d", gr->gr_gid);
- strcat(extra_opts, gidbuf);
+ if ((len -= strlen(gidbuf)) > 0)
+ strcat(extra_opts, gidbuf);
return;
}
}
- strcat(extra_opts, opt);
+ if ((len -= strlen(opt)) > 0)
+ strcat(extra_opts, opt);
}
/* Take -o options list and compute 4th and 5th args to mount(2). flags
@@ -318,13 +323,14 @@ parse_opts (const char *options, int *flags, char **extra_opts) {
if (options != NULL) {
char *opts = xstrdup(options);
char *opt;
+ int len = strlen(opts) + 20;
- *extra_opts = xmalloc (strlen (opts) + 1);
+ *extra_opts = xmalloc(len);
**extra_opts = '\0';
- for (opt = strtok (opts, ","); opt; opt = strtok (NULL, ","))
- if (!parse_string_opt (opt))
- parse_opt (opt, flags, *extra_opts);
+ for (opt = strtok(opts, ","); opt; opt = strtok(NULL, ","))
+ if (!parse_string_opt(opt))
+ parse_opt(opt, flags, *extra_opts, len);
free(opts);
}
@@ -957,7 +963,7 @@ retry_nfs:
error (_("mount: %s not mounted already, or bad option"), node);
} else {
error (_("mount: wrong fs type, bad option, bad superblock on %s,\n"
- " missing codepage, or too many mounted file systems"),
+ " missing codepage or other error"),
spec);
if (stat(spec, &statbuf) == 0 && S_ISBLK(statbuf.st_mode)
@@ -965,13 +971,15 @@ retry_nfs:
if (ioctl(fd, BLKGETSIZE, &size) == 0) {
if (size == 0 && !loop) {
warned++;
- error (" (could this be the IDE device where you in fact use\n"
- " ide-scsi so that sr0 or sda or so is needed?)");
+ error(_(
+ " (could this be the IDE device where you in fact use\n"
+ " ide-scsi so that sr0 or sda or so is needed?)"));
}
if (size && size <= 2) {
warned++;
- error (" (aren't you trying to mount an extended partition,\n"
- " instead of some logical partition inside?)");
+ error(_(
+ " (aren't you trying to mount an extended partition,\n"
+ " instead of some logical partition inside?)"));
}
close(fd);
}
@@ -986,6 +994,9 @@ retry_nfs:
}
#endif
}
+ error(_(
+ " In some cases useful info is found in syslog - try\n"
+ " dmesg | tail or so\n"));
}
break;
}
@@ -1055,7 +1066,7 @@ retry_nfs:
types = types0;
}
if (opts) {
- char *opts2 = realloc(xstrdup(opts), strlen(opts)+4);
+ char *opts2 = xrealloc(xstrdup(opts), strlen(opts)+4);
strcat(opts2, ",ro");
my_free(opts1);
opts = opts1 = opts2;
diff --git a/mount/mount_by_label.c b/mount/mount_by_label.c
index cf79fb803..29ec35448 100644
--- a/mount/mount_by_label.c
+++ b/mount/mount_by_label.c
@@ -211,6 +211,9 @@ uuidcache_init(void) {
fseek(procpt, 0, SEEK_SET);
while (fgets(line, sizeof(line), procpt)) {
+ if (!index(line, '\n'))
+ break;
+
if (sscanf (line, " %d %d %d %[^\n ]",
&ma, &mi, &sz, ptname) != 4)
continue;
@@ -229,7 +232,7 @@ uuidcache_init(void) {
/* heuristic: partition name ends in a digit */
/* devfs has .../disc and .../part1 etc. */
- for(s = ptname; *s; s++);
+ for (s = ptname; *s; s++);
if (isdigit(s[-1]) || is_xvm(ptname)) {
/*
diff --git a/mount/sundries.c b/mount/sundries.c
index af5bb884c..2118ce285 100644
--- a/mount/sundries.c
+++ b/mount/sundries.c
@@ -32,6 +32,17 @@ xmalloc (size_t size) {
return t;
}
+void *
+xrealloc (void *p, size_t size) {
+ void *t;
+
+ t = realloc(p, size);
+ if (t == NULL)
+ die (EX_SYSERR, _("not enough memory"));
+
+ return t;
+}
+
char *
xstrdup (const char *s) {
char *t;
@@ -278,11 +289,12 @@ canonicalize (const char *path) {
if (path == NULL)
return NULL;
+#if 1
if (streq(path, "none") ||
streq(path, "proc") ||
streq(path, "devpts"))
return xstrdup(path);
-
+#endif
if (myrealpath (path, canonical, PATH_MAX+1))
return xstrdup(canonical);
diff --git a/mount/sundries.h b/mount/sundries.h
index af0df4e27..a3a762f6f 100644
--- a/mount/sundries.h
+++ b/mount/sundries.h
@@ -26,6 +26,7 @@ void error (const char *fmt, ...);
int matching_type (const char *type, const char *types);
int matching_opts (const char *options, const char *test_opts);
void *xmalloc (size_t size);
+void *xrealloc (void *t, size_t size);
char *xstrdup (const char *s);
char *xstrndup (const char *s, int n);
char *xstrconcat2 (const char *, const char *);
diff --git a/mount/swapon.8 b/mount/swapon.8
index 223ea5064..f1f40263e 100644
--- a/mount/swapon.8
+++ b/mount/swapon.8
@@ -87,8 +87,7 @@ Devices that are already running as swap are silently skipped.
When
.B \-a
is used with swapon,
-.B
-\-e
+.B \-e
makes swapon silently skip devices that
do not exist.
.TP
@@ -107,6 +106,9 @@ to the option field of
.I /etc/fstab
for use with
.BR "swapon -a" .
+.TP
+.B \-v
+Be verbose.
.PP
.B Swapoff
disables swapping on the specified devices and files.
diff --git a/mount/swapon.c b/mount/swapon.c
index 17c45cbdd..dadfc04ef 100644
--- a/mount/swapon.c
+++ b/mount/swapon.c
@@ -101,7 +101,7 @@ static void
read_proc_swaps(void) {
FILE *swaps;
char line[1024];
- char *p;
+ char *p, **q;
numSwaps = 0;
swapFiles = NULL;
@@ -121,10 +121,12 @@ read_proc_swaps(void) {
for (p = line; *p && *p != ' '; p++);
*p = 0;
- numSwaps++;
- swapFiles = realloc(swapFiles,
- numSwaps * sizeof(*swapFiles));
- swapFiles[numSwaps-1] = strdup(line);
+ q = realloc(swapFiles, (numSwaps+1) * sizeof(*swapFiles));
+ if (q == NULL)
+ break;
+ swapFiles = q;
+
+ swapFiles[numSwaps++] = strdup(line);
}
fclose(swaps);
}
@@ -134,7 +136,7 @@ is_in_proc_swaps(char *fname) {
int i;
for (i = 0; i < numSwaps; i++)
- if (!strcmp(fname, swapFiles[i]))
+ if (swapFiles[i] && !strcmp(fname, swapFiles[i]))
return 1;
return 0;
}
@@ -377,7 +379,7 @@ main_swapoff(int argc, char *argv[]) {
if (all) {
/*
- * In case /proc/swaps exists, unmount stuff listed there.
+ * In case /proc/swaps exists, unswap stuff listed there.
* We are quiet but report errors in status.
* Errors might mean that /proc/swaps
* exists as ordinary file, not in procfs.
@@ -388,7 +390,7 @@ main_swapoff(int argc, char *argv[]) {
status |= do_swapoff(swapFiles[i], QUIET);
/*
- * Unmount stuff mentioned in /etc/fstab.
+ * Unswap stuff mentioned in /etc/fstab.
* Probably it was unmounted already, so errors are not bad.
* Doing swapoff -a twice should not give error messages.
*/