Imported from util-linux-2.12o tarball.
This commit is contained in:
parent
a47f2e6614
commit
756bfd018e
8
HISTORY
8
HISTORY
|
@ -1,3 +1,11 @@
|
|||
util-linux 2.12n,o
|
||||
|
||||
* lomount: revert patch from 2.12j
|
||||
* lptune.8: -T option is obsolete
|
||||
* mkswap, mkswap.8, swapon: support labels
|
||||
(use HAVE_BLKID=no as long as the blkid library doesnt support this)
|
||||
* umount: allow user unmounting repeatedly mounted nfs mounts
|
||||
|
||||
util-linux 2.12m
|
||||
|
||||
* cfdisk: recognize JFS, support reiserfs labels (flavio.stanchina@tin.it)
|
||||
|
|
10
Makefile
10
Makefile
|
@ -52,7 +52,15 @@ distclean: make_include clean
|
|||
cd mount && make distclean
|
||||
-rm -f defines.h make_include
|
||||
|
||||
#
|
||||
tar: make_include clean
|
||||
cd mount && make distclean
|
||||
cd po && make update-po && make util-linux.pot && \
|
||||
mv util-linux.pot ../../util-linux-$(VERSION).pot && \
|
||||
make distclean
|
||||
-rm -f defines.h make_include
|
||||
cd .. && tar cvfz util-linux-$(VERSION).tar.gz ./util-linux-$(VERSION)
|
||||
@echo = made util-linux-$(VERSION).pot and util-linux-$(VERSION).tar.gz
|
||||
|
||||
# dist:
|
||||
# (cd /tmp; \
|
||||
# rm -rf /tmp/util-linux-$(VERSION); \
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
# H4. For nls.h: do we have <locale.h>?
|
||||
# H5. For cal.c: do we have <langinfo.h>?
|
||||
# H6. For mkswap.c: do we have <sys/user.h> or <asm/page.h>?
|
||||
# H6a For mkswap.c: do we have <uuid/uuid.h>?
|
||||
# H7. For nfsmount.c: do we have <rpcsvc/nfs_prot.h>?
|
||||
# H8. For nfsmount.h (nfsmount_xdr.c: int32_t): do we have <asm/types.h>?
|
||||
# H9. For raw.c: do we have <linux/raw.h>?
|
||||
|
@ -163,6 +164,16 @@ else if ./testincl "asm/page.h"; then
|
|||
echo "#define HAVE_asm_page_h" >> defines.h
|
||||
fi; fi
|
||||
|
||||
#
|
||||
# H6a. For mkswap.c: do we have <uuid/uuid.h>?
|
||||
#
|
||||
if ./testincl "uuid/uuid.h"; then
|
||||
echo "#define HAVE_uuid_uuid_h" >> defines.h
|
||||
echo "HAVE_UUID=yes" >> make_include
|
||||
else
|
||||
echo "HAVE_UUID=no" >> make_include
|
||||
fi
|
||||
|
||||
#
|
||||
# H7. For nfsmount.c: do we have <rpcsvc/nfs_prot.h>?
|
||||
#
|
||||
|
|
|
@ -36,6 +36,10 @@ ifeq "$(HAVE_ZLIB)" "yes"
|
|||
SBIN:=$(SBIN) fsck.cramfs mkfs.cramfs
|
||||
endif
|
||||
|
||||
ifeq "$(HAVE_UUID)" "yes"
|
||||
MKSWAP_LIBS=-luuid
|
||||
endif
|
||||
|
||||
all: $(SBIN) $(USRBIN)
|
||||
|
||||
fsck.cramfs: fsck.cramfs.o
|
||||
|
@ -50,6 +54,9 @@ fsck.cramfs.o mkfs.cramfs.o: cramfs.h
|
|||
|
||||
fsck.minix.o mkfs.minix.o: bitops.h minix.h
|
||||
|
||||
mkswap: mkswap.o $(LIB)/xstrncpy.o
|
||||
$(CC) $(LDFLAGS) -o $@ $^ $(MKSWAP_LIBS)
|
||||
|
||||
install: all
|
||||
$(INSTALLDIR) $(SBINDIR) $(USRBINDIR) $(ETCDIR)
|
||||
$(INSTALLBIN) $(SBIN) $(SBINDIR)
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
.SH NAME
|
||||
mkswap \- set up a Linux swap area
|
||||
.SH SYNOPSIS
|
||||
.BI "mkswap [\-c] [\-v" N "] [\-f] [\-p " PSZ "] "device " [" size "]"
|
||||
.BI "mkswap [\-c] [\-v" N "] [\-f] [\-p " PSZ "] [\-L " label "] " device " [" size "]"
|
||||
.SH DESCRIPTION
|
||||
.B mkswap
|
||||
sets up a Linux swap area on a device or in a file.
|
||||
|
@ -131,6 +131,10 @@ as that probably means one is going to erase the partition table.
|
|||
.BI "\-p " PSZ
|
||||
Specify the page size to use.
|
||||
.TP
|
||||
.BI "\-L " label
|
||||
Specify a label, to allow swapon by label.
|
||||
(Only for new style swap areas.)
|
||||
.TP
|
||||
.B \-v0
|
||||
Create an old style swap area.
|
||||
.TP
|
||||
|
|
|
@ -39,8 +39,15 @@
|
|||
#include <sys/ioctl.h> /* for _IO */
|
||||
#include <sys/utsname.h>
|
||||
#include <sys/stat.h>
|
||||
#include "../defines.h"
|
||||
#include "swapheader.h"
|
||||
#include "xstrncpy.h"
|
||||
#include "nls.h"
|
||||
|
||||
#ifdef HAVE_uuid_uuid_h
|
||||
#include <uuid/uuid.h>
|
||||
#endif
|
||||
|
||||
/* Try to get PAGE_SIZE from libc or kernel includes */
|
||||
#ifdef HAVE_sys_user_h
|
||||
/* Note: <sys/user.h> says: for gdb only */
|
||||
|
@ -154,18 +161,11 @@ static int kernel_pagesize; /* obtained via getpagesize(); */
|
|||
static int defined_pagesize = 0; /* PAGE_SIZE, when that exists */
|
||||
static int pagesize;
|
||||
static long *signature_page;
|
||||
|
||||
struct swap_header_v1 {
|
||||
char bootbits[1024]; /* Space for disklabel etc. */
|
||||
unsigned int version;
|
||||
unsigned int last_page;
|
||||
unsigned int nr_badpages;
|
||||
unsigned int padding[125];
|
||||
unsigned int badpages[1];
|
||||
} *p;
|
||||
struct swap_header_v1 *p;
|
||||
|
||||
static void
|
||||
init_signature_page(void) {
|
||||
|
||||
#ifdef PAGE_SIZE
|
||||
defined_pagesize = PAGE_SIZE;
|
||||
#endif
|
||||
|
@ -192,7 +192,7 @@ init_signature_page(void) {
|
|||
pagesize, defined_pagesize);
|
||||
|
||||
signature_page = (long *) malloc(pagesize);
|
||||
memset(signature_page,0,pagesize);
|
||||
memset(signature_page, 0, pagesize);
|
||||
p = (struct swap_header_v1 *) signature_page;
|
||||
}
|
||||
|
||||
|
@ -203,6 +203,62 @@ write_signature(char *sig) {
|
|||
strncpy(sp+pagesize-10, sig, 10);
|
||||
}
|
||||
|
||||
#if 0
|
||||
static int
|
||||
tohex(int a) {
|
||||
return ((a < 10) ? '0'+a : 'a'+a-10);
|
||||
}
|
||||
|
||||
static void
|
||||
uuid_unparse(unsigned char *uuid, char *s) {
|
||||
int i;
|
||||
|
||||
for (i=0; i<16; i++) {
|
||||
if (i == 4 || i == 6 || i == 8 || i == 10)
|
||||
*s++ = '-';
|
||||
*s++ = tohex((uuid[i] >> 4) & 0xf);
|
||||
*s++ = tohex(uuid[i] & 0xf);
|
||||
}
|
||||
*s = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
write_uuid_and_label(char *uuid, char *volume_name) {
|
||||
struct swap_header_v1_2 *h;
|
||||
|
||||
/* Sanity check */
|
||||
if (sizeof(struct swap_header_v1) !=
|
||||
sizeof(struct swap_header_v1_2)) {
|
||||
fprintf(stderr,
|
||||
_("Bad swap header size, no label written.\n"));
|
||||
return;
|
||||
}
|
||||
|
||||
h = (struct swap_header_v1_2 *) signature_page;
|
||||
if (uuid)
|
||||
memcpy(h->uuid, uuid, sizeof(h->uuid));
|
||||
if (volume_name) {
|
||||
xstrncpy(h->volume_name, volume_name, sizeof(h->volume_name));
|
||||
if (strlen(volume_name) > strlen(h->volume_name))
|
||||
fprintf(stderr, _("Label was truncated.\n"));
|
||||
}
|
||||
if (uuid || volume_name) {
|
||||
if (volume_name)
|
||||
printf("LABEL=%s, ", h->volume_name);
|
||||
else
|
||||
printf(_("no label, "));
|
||||
#ifdef HAVE_uuid_uuid_h
|
||||
if (uuid) {
|
||||
char uuid_string[37];
|
||||
uuid_unparse(uuid, uuid_string);
|
||||
printf("UUID=%s\n", uuid_string);
|
||||
} else
|
||||
#endif
|
||||
printf(_("no uuid\n"));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Find out what the maximum amount of swap space is that the kernel will
|
||||
* handle. This wouldn't matter if the kernel just used as much of the
|
||||
|
@ -323,7 +379,7 @@ bit_test_and_clear (unsigned long *addr, unsigned int nr) {
|
|||
static void
|
||||
usage(void) {
|
||||
fprintf(stderr,
|
||||
_("Usage: %s [-c] [-v0|-v1] [-pPAGESZ] /dev/name [blocks]\n"),
|
||||
_("Usage: %s [-c] [-v0|-v1] [-pPAGESZ] [-L label] /dev/name [blocks]\n"),
|
||||
program_name);
|
||||
exit(1);
|
||||
}
|
||||
|
@ -448,8 +504,13 @@ main(int argc, char ** argv) {
|
|||
int force = 0;
|
||||
char *block_count = 0;
|
||||
char *pp;
|
||||
char *opt_label = NULL;
|
||||
char *uuid = NULL;
|
||||
#ifdef HAVE_uuid_uuid_h
|
||||
uuid_t uuid_dat;
|
||||
#endif
|
||||
|
||||
program_name = (argc && *argv) ? argv[0] : "fsck.minix";
|
||||
program_name = (argc && *argv) ? argv[0] : "mkswap";
|
||||
if ((pp = strrchr(program_name, '/')) != NULL)
|
||||
program_name = pp+1;
|
||||
|
||||
|
@ -477,10 +538,16 @@ main(int argc, char ** argv) {
|
|||
if (!*pp && i+1 < argc)
|
||||
pp = argv[++i];
|
||||
if (isnzdigit(*pp))
|
||||
user_pagesize=atoi(pp);
|
||||
user_pagesize = atoi(pp);
|
||||
else
|
||||
usage();
|
||||
break;
|
||||
case 'L':
|
||||
pp = argv[i]+2;
|
||||
if (!*pp && i+1 < argc)
|
||||
pp = argv[++i];
|
||||
opt_label = pp;
|
||||
break;
|
||||
case 'v':
|
||||
version = atoi(argv[i]+2);
|
||||
break;
|
||||
|
@ -495,6 +562,11 @@ main(int argc, char ** argv) {
|
|||
usage();
|
||||
}
|
||||
|
||||
#ifdef HAVE_uuid_uuid_h
|
||||
uuid_generate(uuid_dat);
|
||||
uuid = uuid_dat;
|
||||
#endif
|
||||
|
||||
init_signature_page(); /* get pagesize */
|
||||
|
||||
if (!device_name) {
|
||||
|
@ -525,6 +597,10 @@ main(int argc, char ** argv) {
|
|||
}
|
||||
|
||||
if (version == -1) {
|
||||
/* labels only for v1 */
|
||||
if (opt_label)
|
||||
version = 1;
|
||||
else
|
||||
/* use version 1 as default, if possible */
|
||||
if (PAGES <= V0_MAX_PAGES && PAGES > V1_MAX_PAGES)
|
||||
version = 0;
|
||||
|
@ -564,6 +640,13 @@ main(int argc, char ** argv) {
|
|||
program_name, PAGES * pagesize / 1000);
|
||||
}
|
||||
|
||||
if (opt_label && version == 0) {
|
||||
fprintf(stderr,
|
||||
_("%s: error: label only with v1 swap area\n"),
|
||||
program_name);
|
||||
usage();
|
||||
}
|
||||
|
||||
DEV = open(device_name,O_RDWR);
|
||||
if (DEV < 0 || fstat(DEV, &statbuf) < 0) {
|
||||
perror(device_name);
|
||||
|
@ -618,6 +701,9 @@ the -f option to force it.\n"),
|
|||
version, (unsigned long long)goodpages * pagesize / 1000);
|
||||
write_signature((version == 0) ? "SWAP-SPACE" : "SWAPSPACE2");
|
||||
|
||||
if (version == 1)
|
||||
write_uuid_and_label(uuid, opt_label);
|
||||
|
||||
offset = ((version == 0) ? 0 : 1024);
|
||||
if (lseek(DEV, offset, SEEK_SET) != offset)
|
||||
die(_("unable to rewind swap-device"));
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
struct swap_header_v1 {
|
||||
char bootbits[1024]; /* Space for disklabel etc. */
|
||||
unsigned int version;
|
||||
unsigned int last_page;
|
||||
unsigned int nr_badpages;
|
||||
unsigned int padding[125];
|
||||
unsigned int badpages[1];
|
||||
};
|
||||
|
||||
struct swap_header_v1_2 {
|
||||
char bootbits[1024]; /* Space for disklabel etc. */
|
||||
unsigned int version;
|
||||
unsigned int last_page;
|
||||
unsigned int nr_badpages;
|
||||
unsigned char uuid[16];
|
||||
char volume_name[16];
|
||||
unsigned int padding[117];
|
||||
unsigned int badpages[1];
|
||||
};
|
|
@ -47,18 +47,19 @@ install: $(PROGS)
|
|||
%.o: %.c
|
||||
$(COMPILE) $<
|
||||
|
||||
mount: mount.o fstab.o sundries.o realpath.o mntent.o version.o \
|
||||
mount: mount.o fstab.o sundries.o xmalloc.o realpath.o mntent.o version.o \
|
||||
get_label_uuid.o mount_by_label.o mount_blkid.o mount_guess_fstype.o \
|
||||
getusername.o $(LIB)/setproctitle.o $(LIB)/env.o $(NFS_OBJS) $(LO_OBJS)
|
||||
$(LINK) $^ -o $@ $(BLKID_LIB)
|
||||
|
||||
umount: umount.o fstab.o sundries.o realpath.o mntent.o getusername.o \
|
||||
get_label_uuid.o mount_by_label.o mount_blkid.o version.o \
|
||||
$(LIB)/env.o $(LO_OBJS)
|
||||
umount: umount.o fstab.o sundries.o xmalloc.o realpath.o mntent.o \
|
||||
getusername.o get_label_uuid.o mount_by_label.o mount_blkid.o \
|
||||
version.o $(LIB)/env.o $(LO_OBJS)
|
||||
$(LINK) $^ -o $@ $(BLKID_LIB)
|
||||
|
||||
swapon: swapon.o version.o
|
||||
$(LINK) $^ -o $@
|
||||
swapon: swapon.o version.o xmalloc.o \
|
||||
get_label_uuid.o mount_by_label.o mount_blkid.o
|
||||
$(LINK) $^ -o $@ $(BLKID_LIB)
|
||||
|
||||
main_losetup.o: lomount.c
|
||||
$(COMPILE) -DMAIN lomount.c -o $@
|
||||
|
|
|
@ -11,7 +11,8 @@
|
|||
#include <sys/stat.h>
|
||||
#include "mntent.h"
|
||||
#include "fstab.h"
|
||||
#include "sundries.h" /* for xmalloc() etc */
|
||||
#include "sundries.h"
|
||||
#include "xmalloc.h"
|
||||
#include "mount_blkid.h"
|
||||
#include "paths.h"
|
||||
#include "nls.h"
|
||||
|
@ -411,6 +412,15 @@ setlkw_timeout (int sig) {
|
|||
/* nothing, fcntl will fail anyway */
|
||||
}
|
||||
|
||||
/* Remove lock file. */
|
||||
void
|
||||
unlock_mtab (void) {
|
||||
if (we_created_lockfile) {
|
||||
unlink (MOUNTED_LOCK);
|
||||
we_created_lockfile = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Create the lock file.
|
||||
The lock file will be removed if we catch a signal or when we exit. */
|
||||
/* The old code here used flock on a lock file /etc/mtab~ and deleted
|
||||
|
@ -436,6 +446,8 @@ lock_mtab (void) {
|
|||
int tries = 3;
|
||||
char linktargetfile[MOUNTLOCK_LINKTARGET_LTH];
|
||||
|
||||
at_die = unlock_mtab;
|
||||
|
||||
if (!signals_have_been_setup) {
|
||||
int sig = 0;
|
||||
struct sigaction sa;
|
||||
|
@ -543,15 +555,6 @@ lock_mtab (void) {
|
|||
}
|
||||
}
|
||||
|
||||
/* Remove lock file. */
|
||||
void
|
||||
unlock_mtab (void) {
|
||||
if (we_created_lockfile) {
|
||||
unlink (MOUNTED_LOCK);
|
||||
we_created_lockfile = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Update the mtab.
|
||||
* Used by umount with null INSTEAD: remove the last DIR entry.
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#ifndef HAVE_BLKID
|
||||
/*
|
||||
* Get label. Used by both mount and umount.
|
||||
* Get label. Used by mount, umount and swapon.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
|
@ -8,8 +8,10 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "xmalloc.h"
|
||||
#include "linux_fs.h"
|
||||
#include "get_label_uuid.h"
|
||||
#include "../disk-utils/swapheader.h"
|
||||
|
||||
/*
|
||||
* See whether this device has (the magic of) a RAID superblock at the end.
|
||||
|
@ -60,15 +62,48 @@ reiserfs_magic_version(const char *magic) {
|
|||
return rc;
|
||||
}
|
||||
|
||||
static void
|
||||
store_uuid(char *udest, char *usrc) {
|
||||
if (usrc)
|
||||
memcpy(udest, usrc, 16);
|
||||
else
|
||||
memset(udest, 0, 16);
|
||||
}
|
||||
|
||||
static void
|
||||
store_label(char **ldest, char *lsrc, int len) {
|
||||
*ldest = xmalloc(len+1);
|
||||
memset(*ldest, 0, len+1);
|
||||
memcpy(*ldest, lsrc, len);
|
||||
}
|
||||
|
||||
static int
|
||||
is_v1_swap_partition(int fd, char **label, char *uuid) {
|
||||
int n = getpagesize();
|
||||
char *buf = xmalloc(n);
|
||||
struct swap_header_v1_2 *p = (struct swap_header_v1_2 *) buf;
|
||||
|
||||
if (lseek(fd, 0, SEEK_SET) == 0
|
||||
&& read(fd, buf, n) == n
|
||||
&& !strncmp(buf+n-10, "SWAPSPACE2", 10)
|
||||
&& p->version == 1) {
|
||||
store_uuid(uuid, p->uuid);
|
||||
store_label(label, p->volume_name, 16);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Get both label and uuid.
|
||||
* For now, only ext2, ext3, xfs, ocfs, ocfs2, reiserfs are supported
|
||||
* For now, only ext2, ext3, xfs, ocfs, ocfs2, reiserfs, swap are supported
|
||||
*
|
||||
* Return 0 on success.
|
||||
*/
|
||||
int
|
||||
get_label_uuid(const char *device, char **label, char *uuid) {
|
||||
int fd;
|
||||
int rv = 1;
|
||||
size_t namesize;
|
||||
struct ext2_super_block e2sb;
|
||||
struct xfs_super_block xfsb;
|
||||
struct jfs_super_block jfssb;
|
||||
|
@ -76,47 +111,50 @@ get_label_uuid(const char *device, char **label, char *uuid) {
|
|||
struct ocfs_volume_label olbl;
|
||||
struct ocfs2_super_block osb;
|
||||
struct reiserfs_super_block reiserfssb;
|
||||
int blksize;
|
||||
int rv = 0;
|
||||
|
||||
fd = open(device, O_RDONLY);
|
||||
if (fd < 0)
|
||||
return rv;
|
||||
return -1;
|
||||
|
||||
/* If there is a RAID partition, or an error, ignore this partition */
|
||||
if (is_raid_partition(fd)) {
|
||||
close(fd);
|
||||
return rv;
|
||||
rv = 1;
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (is_v1_swap_partition(fd, label, uuid))
|
||||
goto done;
|
||||
|
||||
if (lseek(fd, 1024, SEEK_SET) == 1024
|
||||
&& read(fd, (char *) &e2sb, sizeof(e2sb)) == sizeof(e2sb)
|
||||
&& (ext2magic(e2sb) == EXT2_SUPER_MAGIC)) {
|
||||
memcpy(uuid, e2sb.s_uuid, sizeof(e2sb.s_uuid));
|
||||
namesize = sizeof(e2sb.s_volume_name);
|
||||
if ((*label = calloc(namesize + 1, 1)) != NULL)
|
||||
memcpy(*label, e2sb.s_volume_name, namesize);
|
||||
rv = 0;
|
||||
store_uuid(uuid, e2sb.s_uuid);
|
||||
store_label(label, e2sb.s_volume_name,
|
||||
sizeof(e2sb.s_volume_name));
|
||||
goto done;
|
||||
}
|
||||
else if (lseek(fd, 0, SEEK_SET) == 0
|
||||
|
||||
if (lseek(fd, 0, SEEK_SET) == 0
|
||||
&& read(fd, (char *) &xfsb, sizeof(xfsb)) == sizeof(xfsb)
|
||||
&& (strncmp(xfsb.s_magic, XFS_SUPER_MAGIC, 4) == 0)) {
|
||||
memcpy(uuid, xfsb.s_uuid, sizeof(xfsb.s_uuid));
|
||||
namesize = sizeof(xfsb.s_fname);
|
||||
if ((*label = calloc(namesize + 1, 1)) != NULL)
|
||||
memcpy(*label, xfsb.s_fname, namesize);
|
||||
rv = 0;
|
||||
store_uuid(uuid, xfsb.s_uuid);
|
||||
store_label(label, xfsb.s_fname, sizeof(xfsb.s_fname));
|
||||
goto done;
|
||||
}
|
||||
else if (lseek(fd, 0, SEEK_SET) == 0
|
||||
|
||||
if (lseek(fd, 0, SEEK_SET) == 0
|
||||
&& read(fd, (char *) &ovh, sizeof(ovh)) == sizeof(ovh)
|
||||
&& (strncmp(ovh.signature, OCFS_MAGIC, sizeof(OCFS_MAGIC)) == 0)
|
||||
&& (lseek(fd, 512, SEEK_SET) == 512)
|
||||
&& read(fd, (char *) &olbl, sizeof(olbl)) == sizeof(olbl)) {
|
||||
uuid[0] = '\0';
|
||||
namesize = ocfslabellen(olbl);
|
||||
if ((*label = calloc(namesize + 1, 1)) != NULL)
|
||||
memcpy(*label, olbl.label, namesize);
|
||||
rv = 0;
|
||||
store_uuid(uuid, NULL);
|
||||
store_label(label, olbl.label, ocfslabellen(olbl));
|
||||
goto done;
|
||||
}
|
||||
else if (lseek(fd, JFS_SUPER1_OFF, SEEK_SET) == JFS_SUPER1_OFF
|
||||
|
||||
if (lseek(fd, JFS_SUPER1_OFF, SEEK_SET) == JFS_SUPER1_OFF
|
||||
&& read(fd, (char *) &jfssb, sizeof(jfssb)) == sizeof(jfssb)
|
||||
&& (strncmp(jfssb.s_magic, JFS_MAGIC, 4) == 0)) {
|
||||
|
||||
|
@ -136,55 +174,47 @@ get_label_uuid(const char *device, char **label, char *uuid) {
|
|||
|
||||
if (assemble4le(jfssb.s_version) == 1 &&
|
||||
strncmp(jfssb.s_label, jfssb.s_fpack, 11) != 0) {
|
||||
memset(uuid, 0, 16);
|
||||
namesize = sizeof(jfssb.s_fpack);
|
||||
if ((*label = calloc(namesize + 1, 1)) != NULL)
|
||||
memcpy(*label, jfssb.s_fpack, namesize);
|
||||
store_uuid(uuid, NULL);
|
||||
store_label(label, jfssb.s_fpack,
|
||||
sizeof(jfssb.s_fpack));
|
||||
} else {
|
||||
memcpy(uuid, jfssb.s_uuid, sizeof(jfssb.s_uuid));
|
||||
namesize = sizeof(jfssb.s_label);
|
||||
if ((*label = calloc(namesize + 1, 1)) != NULL)
|
||||
memcpy(*label, jfssb.s_label, namesize);
|
||||
store_uuid(uuid, jfssb.s_uuid);
|
||||
store_label(label, jfssb.s_label,
|
||||
sizeof(jfssb.s_label));
|
||||
}
|
||||
rv = 0;
|
||||
goto done;
|
||||
}
|
||||
else if (lseek(fd, REISERFS_DISK_OFFSET_IN_BYTES, SEEK_SET)
|
||||
|
||||
if (lseek(fd, REISERFS_DISK_OFFSET_IN_BYTES, SEEK_SET)
|
||||
== REISERFS_DISK_OFFSET_IN_BYTES
|
||||
&& read(fd, (char *) &reiserfssb, sizeof(reiserfssb))
|
||||
== sizeof(reiserfssb)
|
||||
/* Only 3.6.x format supers have labels or uuids.
|
||||
Label and UUID can be set by reiserfstune -l/-u. */
|
||||
&& reiserfs_magic_version(reiserfssb.s_magic) > 1) {
|
||||
namesize = sizeof (reiserfssb.s_label);
|
||||
if ((*label = calloc(namesize + 1, 1)) != NULL)
|
||||
memcpy(*label, reiserfssb.s_label, namesize);
|
||||
memcpy(uuid, reiserfssb.s_uuid, sizeof (reiserfssb.s_uuid));
|
||||
rv = 0;
|
||||
store_uuid(uuid, reiserfssb.s_uuid);
|
||||
store_label(label, reiserfssb.s_label,
|
||||
sizeof(reiserfssb.s_label));
|
||||
goto done;
|
||||
}
|
||||
else {
|
||||
int blksize, blkoff;
|
||||
|
||||
for (blksize = OCFS2_MIN_BLOCKSIZE;
|
||||
blksize <= OCFS2_MAX_BLOCKSIZE;
|
||||
blksize <<= 1) {
|
||||
blkoff = blksize * OCFS2_SUPER_BLOCK_BLKNO;
|
||||
int blkoff = blksize * OCFS2_SUPER_BLOCK_BLKNO;
|
||||
|
||||
if (lseek(fd, blkoff, SEEK_SET) == blkoff
|
||||
&& read(fd, (char *) &osb, sizeof(osb))
|
||||
== sizeof(osb)
|
||||
&& read(fd, (char *) &osb, sizeof(osb)) == sizeof(osb)
|
||||
&& strncmp(osb.signature,
|
||||
OCFS2_SUPER_BLOCK_SIGNATURE,
|
||||
sizeof(OCFS2_SUPER_BLOCK_SIGNATURE))
|
||||
== 0) {
|
||||
memcpy(uuid, osb.s_uuid, sizeof(osb.s_uuid));
|
||||
namesize = sizeof(osb.s_label);
|
||||
if ((*label = calloc(namesize, 1)) != NULL)
|
||||
memcpy(*label, osb.s_label, namesize);
|
||||
rv = 0;
|
||||
break;
|
||||
sizeof(OCFS2_SUPER_BLOCK_SIGNATURE)) == 0) {
|
||||
store_uuid(uuid, osb.s_uuid);
|
||||
store_label(label, osb.s_label, sizeof(osb.s_label));
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
rv = 1;
|
||||
done:
|
||||
close(fd);
|
||||
return rv;
|
||||
}
|
||||
|
|
|
@ -242,7 +242,7 @@ int
|
|||
set_loop(const char *device, const char *file, unsigned long long offset,
|
||||
const char *encryption, int pfd, int *loopro) {
|
||||
struct loop_info64 loopinfo64;
|
||||
int fd, ffd, mode, i, n;
|
||||
int fd, ffd, mode, i;
|
||||
char *pass;
|
||||
|
||||
mode = (*loopro ? O_RDONLY : O_RDWR);
|
||||
|
@ -299,11 +299,10 @@ set_loop(const char *device, const char *file, unsigned long long offset,
|
|||
default:
|
||||
pass = xgetpass(pfd, _("Password: "));
|
||||
gotpass:
|
||||
memset(loopinfo64.lo_encrypt_key, 0, LO_KEY_SIZE);
|
||||
xstrncpy(loopinfo64.lo_encrypt_key, pass, LO_KEY_SIZE);
|
||||
n = strlen(pass);
|
||||
memset(pass, 0, n);
|
||||
loopinfo64.lo_encrypt_key_size =
|
||||
(n < LO_KEY_SIZE) ? n : LO_KEY_SIZE;
|
||||
memset(pass, 0, strlen(pass));
|
||||
loopinfo64.lo_encrypt_key_size = LO_KEY_SIZE;
|
||||
}
|
||||
|
||||
if (ioctl(fd, LOOP_SET_FD, ffd) < 0) {
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include "mount_blkid.h"
|
||||
#include "mount_constants.h"
|
||||
#include "sundries.h"
|
||||
#include "xmalloc.h"
|
||||
#include "mntent.h"
|
||||
#include "fstab.h"
|
||||
#include "lomount.h"
|
||||
|
|
|
@ -74,6 +74,8 @@ mount_get_devname_by_uuid(const char *uuid) {
|
|||
return get_spec_by_uuid(uuid);
|
||||
}
|
||||
|
||||
extern char *progname;
|
||||
|
||||
const char *
|
||||
mount_get_devname_by_label(const char *volumelabel) {
|
||||
const char *spec, *spec2;
|
||||
|
@ -82,9 +84,8 @@ mount_get_devname_by_label(const char *volumelabel) {
|
|||
spec2 = second_occurrence_of_vol_label(volumelabel);
|
||||
if (spec2)
|
||||
die (EX_FAIL,
|
||||
_("mount: the label %s occurs on "
|
||||
"both %s and %s - not mounted\n"),
|
||||
volumelabel, spec, spec2);
|
||||
_("%s: error: the label %s occurs on both %s and %s\n"),
|
||||
progname, volumelabel, spec, spec2);
|
||||
return spec;
|
||||
}
|
||||
|
||||
|
|
|
@ -40,6 +40,8 @@
|
|||
#define EVMS_VOLUME_NAME_SIZE 127
|
||||
#define PROC_EVMS_VOLUMES "/proc/evms/volumes"
|
||||
|
||||
extern char *progname;
|
||||
|
||||
static struct uuidCache_s {
|
||||
struct uuidCache_s *next;
|
||||
char uuid[16];
|
||||
|
@ -82,7 +84,7 @@ uuidcache_init_lvm(void) {
|
|||
sprintf(buffer, "%s/%s/LVs", VG_DIR, vg_iter->d_name);
|
||||
lv_list = opendir(buffer);
|
||||
if (lv_list == NULL) {
|
||||
perror("mount (init_lvm)");
|
||||
perror("uuidcache_init_lvm");
|
||||
continue;
|
||||
}
|
||||
seekdir(lv_list, 2);
|
||||
|
@ -187,9 +189,9 @@ uuidcache_init(void) {
|
|||
if (!procpt) {
|
||||
static int warn = 0;
|
||||
if (!warn++)
|
||||
error (_("mount: could not open %s, so UUID and LABEL "
|
||||
error (_("%s: could not open %s, so UUID and LABEL "
|
||||
"conversion cannot be done.\n"),
|
||||
PROC_PARTITIONS);
|
||||
progname, PROC_PARTITIONS);
|
||||
return;
|
||||
}
|
||||
#if 0
|
||||
|
@ -310,7 +312,7 @@ get_spec_by_uuid(const char *s) {
|
|||
return get_spec_by_x(UUID, uuid);
|
||||
|
||||
bad_uuid:
|
||||
die(EX_USAGE, _("mount: bad UUID"));
|
||||
die(EX_USAGE, _("%s: bad UUID"), progname);
|
||||
return NULL; /* just for gcc */
|
||||
}
|
||||
|
||||
|
|
|
@ -18,46 +18,6 @@
|
|||
#include "nfsmount.h"
|
||||
#include "nls.h"
|
||||
|
||||
void *
|
||||
xmalloc (size_t size) {
|
||||
void *t;
|
||||
|
||||
if (size == 0)
|
||||
return NULL;
|
||||
|
||||
t = malloc (size);
|
||||
if (t == NULL)
|
||||
die (EX_SYSERR, _("not enough memory"));
|
||||
|
||||
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;
|
||||
|
||||
if (s == NULL)
|
||||
return NULL;
|
||||
|
||||
t = strdup (s);
|
||||
|
||||
if (t == NULL)
|
||||
die (EX_SYSERR, _("not enough memory"));
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
char *
|
||||
xstrndup (const char *s, int n) {
|
||||
char *t;
|
||||
|
@ -147,20 +107,6 @@ error (const char *fmt, ...) {
|
|||
free (fmt2);
|
||||
}
|
||||
|
||||
/* Fatal error. Print message and exit. */
|
||||
void
|
||||
die (int err, const char *fmt, ...) {
|
||||
va_list args;
|
||||
|
||||
va_start (args, fmt);
|
||||
vfprintf (stderr, fmt, args);
|
||||
fprintf (stderr, "\n");
|
||||
va_end (args);
|
||||
|
||||
unlock_mtab ();
|
||||
exit (err);
|
||||
}
|
||||
|
||||
/* True if fstypes match. Null *TYPES means match anything,
|
||||
except that swap types always return false. */
|
||||
/* Accept nonfs,proc,devpts and nonfs,noproc,nodevpts
|
||||
|
|
|
@ -26,7 +26,6 @@ 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 *);
|
||||
|
|
|
@ -58,6 +58,15 @@ swapon, swapoff \- enable/disable devices and files for paging and swapping
|
|||
.SH DESCRIPTION
|
||||
.B Swapon
|
||||
is used to specify devices on which paging and swapping are to take place.
|
||||
|
||||
The device or file used is given by the
|
||||
.I specialfile
|
||||
parameter. It may be of the form
|
||||
.BI \-L " label"
|
||||
or
|
||||
.BI \-U " uuid"
|
||||
to indicate a device by label or uuid.
|
||||
|
||||
Calls to
|
||||
.B swapon
|
||||
normally occur in the system multi-user initialization file
|
||||
|
@ -67,16 +76,6 @@ 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 \-s
|
||||
Display swap usage summary by device. Equivalent to "cat /proc/swaps".
|
||||
Not available before Linux 2.1.25.
|
||||
.TP
|
||||
.B \-a
|
||||
All devices marked as ``swap'' swap devices in
|
||||
.I /etc/fstab
|
||||
|
@ -88,8 +87,17 @@ When
|
|||
.B \-a
|
||||
is used with swapon,
|
||||
.B \-e
|
||||
makes swapon silently skip devices that
|
||||
do not exist.
|
||||
makes swapon silently skip devices that do not exist.
|
||||
.TP
|
||||
.B \-h
|
||||
Provide help
|
||||
.TP
|
||||
.BI \-L " label"
|
||||
Use the partition that has the specified
|
||||
.IR label .
|
||||
(For this, access to
|
||||
.I /proc/partitions
|
||||
is needed.)
|
||||
.TP
|
||||
.BI \-p " priority"
|
||||
Specify priority for
|
||||
|
@ -98,7 +106,8 @@ This option is only available if
|
|||
.B swapon
|
||||
was compiled under and is used under a 1.3.2 or later kernel.
|
||||
.I priority
|
||||
is a value between 0 and 32767. See
|
||||
is a value between 0 and 32767. Higher numbers indicate higher
|
||||
priority. See
|
||||
.BR swapon (2)
|
||||
for a full description of swap priorities. Add
|
||||
.BI pri= value
|
||||
|
@ -107,8 +116,22 @@ to the option field of
|
|||
for use with
|
||||
.BR "swapon -a" .
|
||||
.TP
|
||||
.B \-s
|
||||
Display swap usage summary by device. Equivalent to "cat /proc/swaps".
|
||||
Not available before Linux 2.1.25.
|
||||
.TP
|
||||
.BI \-U " uuid"
|
||||
Use the partition that has the specified
|
||||
.IR uuid .
|
||||
(For this, access to
|
||||
.I /proc/partitions
|
||||
is needed.)
|
||||
.TP
|
||||
.B \-v
|
||||
Be verbose.
|
||||
.TP
|
||||
.B \-V
|
||||
Display version
|
||||
.PP
|
||||
.B Swapoff
|
||||
disables swapping on the specified devices and files.
|
||||
|
|
254
mount/swapon.c
254
mount/swapon.c
|
@ -11,9 +11,12 @@
|
|||
#include <mntent.h>
|
||||
#include <errno.h>
|
||||
#include <sys/stat.h>
|
||||
#include "xmalloc.h"
|
||||
#include "swap_constants.h"
|
||||
#include "swapargs.h"
|
||||
#include "nls.h"
|
||||
#include "mount_blkid.h"
|
||||
#include "mount_by_label.h"
|
||||
|
||||
#define streq(s, t) (strcmp ((s), (t)) == 0)
|
||||
|
||||
|
@ -32,7 +35,7 @@ int priority = -1; /* non-prioritized swap by default */
|
|||
int ifexists = 0;
|
||||
|
||||
extern char version[];
|
||||
static char *program_name;
|
||||
char *progname;
|
||||
|
||||
static struct option longswaponopts[] = {
|
||||
/* swapon only */
|
||||
|
@ -53,9 +56,9 @@ static void
|
|||
swapon_usage(FILE *fp, int n) {
|
||||
fprintf(fp, _("usage: %s [-hV]\n"
|
||||
" %s -a [-e] [-v]\n"
|
||||
" %s [-v] [-p priority] special ...\n"
|
||||
" %s [-v] [-p priority] special|LABEL=volume_name ...\n"
|
||||
" %s [-s]\n"),
|
||||
program_name, program_name, program_name, program_name);
|
||||
progname, progname, progname, progname);
|
||||
exit(n);
|
||||
}
|
||||
|
||||
|
@ -64,7 +67,7 @@ swapoff_usage(FILE *fp, int n) {
|
|||
fprintf(fp, _("usage: %s [-hV]\n"
|
||||
" %s -a [-v]\n"
|
||||
" %s [-v] special ...\n"),
|
||||
program_name, program_name, program_name);
|
||||
progname, progname, progname);
|
||||
exit(n);
|
||||
}
|
||||
|
||||
|
@ -132,7 +135,7 @@ read_proc_swaps(void) {
|
|||
}
|
||||
|
||||
static int
|
||||
is_in_proc_swaps(char *fname) {
|
||||
is_in_proc_swaps(const char *fname) {
|
||||
int i;
|
||||
|
||||
for (i = 0; i < numSwaps; i++)
|
||||
|
@ -149,7 +152,7 @@ display_summary(void)
|
|||
|
||||
if ((swaps = fopen(PROC_SWAPS, "r")) == NULL) {
|
||||
int errsv = errno;
|
||||
fprintf(stderr, "%s: %s: %s\n", program_name, PROC_SWAPS,
|
||||
fprintf(stderr, "%s: %s: %s\n", progname, PROC_SWAPS,
|
||||
strerror(errsv));
|
||||
return -1 ;
|
||||
}
|
||||
|
@ -162,17 +165,25 @@ display_summary(void)
|
|||
}
|
||||
|
||||
static int
|
||||
do_swapon(const char *special, int prio) {
|
||||
do_swapon(const char *orig_special, int prio) {
|
||||
int status;
|
||||
struct stat st;
|
||||
const char *special;
|
||||
|
||||
if (verbose)
|
||||
printf(_("%s on %s\n"), program_name, special);
|
||||
printf(_("%s on %s\n"), progname, orig_special);
|
||||
|
||||
special = mount_get_devname(orig_special);
|
||||
if (!special) {
|
||||
fprintf(stderr, _("%s: cannot find the device for %s\n"),
|
||||
progname, orig_special);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (stat(special, &st) < 0) {
|
||||
int errsv = errno;
|
||||
fprintf(stderr, _("swapon: cannot stat %s: %s\n"),
|
||||
special, strerror(errsv));
|
||||
fprintf(stderr, _("%s: cannot stat %s: %s\n"),
|
||||
progname, special, strerror(errsv));
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -182,10 +193,10 @@ do_swapon(const char *special, int prio) {
|
|||
int permMask = (S_ISBLK(st.st_mode) ? 07007 : 07077);
|
||||
|
||||
if ((st.st_mode & permMask) != 0) {
|
||||
fprintf(stderr, _("swapon: warning: %s has "
|
||||
fprintf(stderr, _("%s: warning: %s has "
|
||||
"insecure permissions %04o, "
|
||||
"%04o suggested\n"),
|
||||
special, st.st_mode & 07777,
|
||||
progname, special, st.st_mode & 07777,
|
||||
~permMask & 0666);
|
||||
}
|
||||
}
|
||||
|
@ -194,9 +205,9 @@ do_swapon(const char *special, int prio) {
|
|||
if (S_ISREG(st.st_mode)) {
|
||||
if (st.st_blocks * 512 < st.st_size) {
|
||||
fprintf(stderr,
|
||||
_("swapon: Skipping file %s - it appears "
|
||||
_("%s: Skipping file %s - it appears "
|
||||
"to have holes.\n"),
|
||||
special);
|
||||
progname, special);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
@ -221,17 +232,42 @@ do_swapon(const char *special, int prio) {
|
|||
#endif
|
||||
if (status < 0) {
|
||||
int errsv = errno;
|
||||
fprintf(stderr, "%s: %s: %s\n", program_name,
|
||||
special, strerror(errsv));
|
||||
fprintf(stderr, "%s: %s: %s\n",
|
||||
progname, orig_special, strerror(errsv));
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
static int
|
||||
do_swapoff(const char *special, int quiet) {
|
||||
cannot_find(const char *special) {
|
||||
fprintf(stderr, _("%s: cannot find the device for %s\n"),
|
||||
progname, special);
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int
|
||||
swapon_by_label(const char *label, int prio) {
|
||||
const char *special = mount_get_devname_by_label(label);
|
||||
return special ? do_swapon(special, prio) : cannot_find(label);
|
||||
}
|
||||
|
||||
static int
|
||||
swapon_by_uuid(const char *uuid, int prio) {
|
||||
const char *special = mount_get_devname_by_uuid(uuid);
|
||||
return special ? do_swapon(special, prio) : cannot_find(uuid);
|
||||
}
|
||||
|
||||
static int
|
||||
do_swapoff(const char *orig_special, int quiet) {
|
||||
const char *special;
|
||||
|
||||
if (verbose)
|
||||
printf(_("%s on %s\n"), program_name, special);
|
||||
printf(_("%s on %s\n"), progname, orig_special);
|
||||
|
||||
special = mount_get_devname(orig_special);
|
||||
if (!special)
|
||||
return cannot_find(orig_special);
|
||||
|
||||
if (swapoff(special) == 0)
|
||||
return 0; /* success */
|
||||
|
@ -242,77 +278,55 @@ do_swapoff(const char *special, int quiet) {
|
|||
}
|
||||
|
||||
if (!quiet || errno == ENOMEM) {
|
||||
int errsv = errno;
|
||||
fprintf(stderr, "%s: %s: %s\n", program_name,
|
||||
special, strerror(errsv));
|
||||
fprintf(stderr, "%s: %s: %s\n",
|
||||
progname, orig_special, strerror(errno));
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int
|
||||
main_swapon(int argc, char *argv[]) {
|
||||
swapoff_by_label(const char *label, int quiet) {
|
||||
const char *special = mount_get_devname_by_label(label);
|
||||
return special ? do_swapoff(special, quiet) : cannot_find(label);
|
||||
}
|
||||
|
||||
static int
|
||||
swapoff_by_uuid(const char *uuid, int quiet) {
|
||||
const char *special = mount_get_devname_by_uuid(uuid);
|
||||
return special ? do_swapoff(special, quiet) : cannot_find(uuid);
|
||||
}
|
||||
|
||||
static int
|
||||
swapon_all(void) {
|
||||
FILE *fp;
|
||||
struct mntent *fstab;
|
||||
int status = 0;
|
||||
int c;
|
||||
|
||||
while ((c = getopt_long(argc, argv, "ahep:svV",
|
||||
longswaponopts, NULL)) != -1) {
|
||||
switch (c) {
|
||||
case 'a': /* all */
|
||||
++all;
|
||||
break;
|
||||
case 'h': /* help */
|
||||
swapon_usage(stdout, 0);
|
||||
break;
|
||||
case 'p': /* priority */
|
||||
priority = atoi(optarg);
|
||||
break;
|
||||
case 'e': /* ifexists */
|
||||
ifexists = 1;
|
||||
break;
|
||||
case 's': /* status report */
|
||||
status = display_summary();
|
||||
exit(status);
|
||||
case 'v': /* be chatty */
|
||||
++verbose;
|
||||
break;
|
||||
case 'V': /* version */
|
||||
printf("%s: %s\n", program_name, version);
|
||||
exit(0);
|
||||
case 0:
|
||||
break;
|
||||
case '?':
|
||||
default:
|
||||
swapon_usage(stderr, 1);
|
||||
}
|
||||
}
|
||||
argv += optind;
|
||||
|
||||
if (!all && *argv == NULL)
|
||||
swapon_usage(stderr, 2);
|
||||
|
||||
if (ifexists && (!all || strcmp(program_name, "swapon")))
|
||||
swapon_usage(stderr, 1);
|
||||
|
||||
if (all) {
|
||||
read_proc_swaps();
|
||||
|
||||
fp = setmntent(_PATH_FSTAB, "r");
|
||||
if (fp == NULL) {
|
||||
int errsv = errno;
|
||||
fprintf(stderr, _("%s: cannot open %s: %s\n"),
|
||||
program_name, _PATH_FSTAB, strerror(errsv));
|
||||
progname, _PATH_FSTAB, strerror(errsv));
|
||||
exit(2);
|
||||
}
|
||||
|
||||
while ((fstab = getmntent(fp)) != NULL) {
|
||||
char *special = fstab->mnt_fsname;
|
||||
const char *orig_special = fstab->mnt_fsname;
|
||||
const char *special;
|
||||
int skip = 0;
|
||||
int pri = priority;
|
||||
|
||||
if (streq(fstab->mnt_type, MNTTYPE_SWAP) &&
|
||||
!is_in_proc_swaps(special)
|
||||
&& (!ifexists || !access(special, R_OK))) {
|
||||
if (!streq(fstab->mnt_type, MNTTYPE_SWAP))
|
||||
continue;
|
||||
|
||||
special = mount_get_devname(orig_special);
|
||||
if (!special)
|
||||
continue;
|
||||
|
||||
if (!is_in_proc_swaps(special) &&
|
||||
(!ifexists || !access(special, R_OK))) {
|
||||
/* parse mount options; */
|
||||
char *opt, *opts = strdup(fstab->mnt_opts);
|
||||
|
||||
|
@ -328,7 +342,83 @@ main_swapon(int argc, char *argv[]) {
|
|||
}
|
||||
}
|
||||
fclose(fp);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
static const char **llist = NULL;
|
||||
static int llct = 0;
|
||||
static const char **ulist = NULL;
|
||||
static int ulct = 0;
|
||||
|
||||
static void addl(const char *label) {
|
||||
llist = (const char **) xrealloc(llist, (++llct) * sizeof(char *));
|
||||
llist[llct-1] = label;
|
||||
}
|
||||
|
||||
static void addu(const char *uuid) {
|
||||
ulist = (const char **) xrealloc(ulist, (++ulct) * sizeof(char *));
|
||||
ulist[ulct-1] = uuid;
|
||||
}
|
||||
|
||||
static int
|
||||
main_swapon(int argc, char *argv[]) {
|
||||
int status = 0;
|
||||
int c, i;
|
||||
|
||||
while ((c = getopt_long(argc, argv, "ahep:svVL:U:",
|
||||
longswaponopts, NULL)) != -1) {
|
||||
switch (c) {
|
||||
case 'a': /* all */
|
||||
++all;
|
||||
break;
|
||||
case 'h': /* help */
|
||||
swapon_usage(stdout, 0);
|
||||
break;
|
||||
case 'p': /* priority */
|
||||
priority = atoi(optarg);
|
||||
break;
|
||||
case 'L':
|
||||
addl(optarg);
|
||||
break;
|
||||
case 'U':
|
||||
addu(optarg);
|
||||
break;
|
||||
case 'e': /* ifexists */
|
||||
ifexists = 1;
|
||||
break;
|
||||
case 's': /* status report */
|
||||
status = display_summary();
|
||||
exit(status);
|
||||
case 'v': /* be chatty */
|
||||
++verbose;
|
||||
break;
|
||||
case 'V': /* version */
|
||||
printf("%s: %s\n", progname, version);
|
||||
exit(0);
|
||||
case 0:
|
||||
break;
|
||||
case '?':
|
||||
default:
|
||||
swapon_usage(stderr, 1);
|
||||
}
|
||||
}
|
||||
argv += optind;
|
||||
|
||||
if (!all && !llct && !ulct && *argv == NULL)
|
||||
swapon_usage(stderr, 2);
|
||||
|
||||
if (ifexists && (!all || strcmp(progname, "swapon")))
|
||||
swapon_usage(stderr, 1);
|
||||
|
||||
if (all)
|
||||
status |= swapon_all();
|
||||
|
||||
for (i = 0; i < llct; i++)
|
||||
status |= swapon_by_label(llist[i], priority);
|
||||
|
||||
for (i = 0; i < ulct; i++)
|
||||
status |= swapon_by_uuid(ulist[i], priority);
|
||||
|
||||
while (*argv != NULL)
|
||||
status |= do_swapon(*argv++, priority);
|
||||
|
@ -343,7 +433,7 @@ main_swapoff(int argc, char *argv[]) {
|
|||
int status = 0;
|
||||
int c, i;
|
||||
|
||||
while ((c = getopt_long(argc, argv, "ahvV",
|
||||
while ((c = getopt_long(argc, argv, "ahvVL:U:",
|
||||
longswapoffopts, NULL)) != -1) {
|
||||
switch (c) {
|
||||
case 'a': /* all */
|
||||
|
@ -356,8 +446,14 @@ main_swapoff(int argc, char *argv[]) {
|
|||
++verbose;
|
||||
break;
|
||||
case 'V': /* version */
|
||||
printf("%s: %s\n", program_name, version);
|
||||
printf("%s: %s\n", progname, version);
|
||||
exit(0);
|
||||
case 'L':
|
||||
addl(optarg);
|
||||
break;
|
||||
case 'U':
|
||||
addu(optarg);
|
||||
break;
|
||||
case 0:
|
||||
break;
|
||||
case '?':
|
||||
|
@ -367,13 +463,19 @@ main_swapoff(int argc, char *argv[]) {
|
|||
}
|
||||
argv += optind;
|
||||
|
||||
if (!all && *argv == NULL)
|
||||
if (!all && !llct && !ulct && *argv == NULL)
|
||||
swapoff_usage(stderr, 2);
|
||||
|
||||
/*
|
||||
* swapoff any explicitly given arguments.
|
||||
* Complain in case the swapoff call fails.
|
||||
*/
|
||||
for (i = 0; i < llct; i++)
|
||||
status |= swapoff_by_label(llist[i], !QUIET);
|
||||
|
||||
for (i = 0; i < ulct; i++)
|
||||
status |= swapoff_by_uuid(ulist[i], !QUIET);
|
||||
|
||||
while (*argv != NULL)
|
||||
status |= do_swapoff(*argv++, !QUIET);
|
||||
|
||||
|
@ -398,7 +500,7 @@ main_swapoff(int argc, char *argv[]) {
|
|||
if (fp == NULL) {
|
||||
int errsv = errno;
|
||||
fprintf(stderr, _("%s: cannot open %s: %s\n"),
|
||||
program_name, _PATH_FSTAB, strerror(errsv));
|
||||
progname, _PATH_FSTAB, strerror(errsv));
|
||||
exit(2);
|
||||
}
|
||||
while ((fstab = getmntent(fp)) != NULL) {
|
||||
|
@ -420,12 +522,12 @@ main(int argc, char *argv[]) {
|
|||
bindtextdomain(PACKAGE, LOCALEDIR);
|
||||
textdomain(PACKAGE);
|
||||
|
||||
program_name = argv[0];
|
||||
p = strrchr(program_name, '/');
|
||||
progname = argv[0];
|
||||
p = strrchr(progname, '/');
|
||||
if (p)
|
||||
program_name = p+1;
|
||||
progname = p+1;
|
||||
|
||||
if (streq(program_name, "swapon"))
|
||||
if (streq(progname, "swapon"))
|
||||
return main_swapon(argc, argv);
|
||||
else
|
||||
return main_swapoff(argc, argv);
|
||||
|
|
|
@ -571,7 +571,10 @@ umount_file (char *arg) {
|
|||
die(2,
|
||||
_("umount: %s is not mounted (according to mtab)"),
|
||||
file);
|
||||
if (!is_mounted_once(file))
|
||||
/* The 2.4 kernel will generally refuse to mount the same
|
||||
filesystem on the same mount point, but will accept NFS.
|
||||
So, unmounting must be possible. */
|
||||
if (!is_mounted_once(file) && strcmp(mc->m.mnt_type,"nfs"))
|
||||
die(2,
|
||||
_("umount: it seems %s is mounted multiple times"),
|
||||
file);
|
||||
|
|
|
@ -0,0 +1,66 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h> /* strdup() */
|
||||
#include "xmalloc.h"
|
||||
#include "nls.h" /* _() */
|
||||
#include "sundries.h" /* EX_SYSERR */
|
||||
|
||||
void (*at_die)(void) = NULL;
|
||||
|
||||
/* Fatal error. Print message and exit. */
|
||||
void
|
||||
die(int err, const char *fmt, ...) {
|
||||
va_list args;
|
||||
|
||||
va_start(args, fmt);
|
||||
vfprintf(stderr, fmt, args);
|
||||
fprintf(stderr, "\n");
|
||||
va_end(args);
|
||||
|
||||
if (at_die)
|
||||
(*at_die)();
|
||||
|
||||
exit(err);
|
||||
}
|
||||
|
||||
static void
|
||||
die_if_null(void *t) {
|
||||
if (t == NULL)
|
||||
die(EX_SYSERR, _("not enough memory"));
|
||||
}
|
||||
|
||||
void *
|
||||
xmalloc (size_t size) {
|
||||
void *t;
|
||||
|
||||
if (size == 0)
|
||||
return NULL;
|
||||
|
||||
t = malloc(size);
|
||||
die_if_null(t);
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
void *
|
||||
xrealloc (void *p, size_t size) {
|
||||
void *t;
|
||||
|
||||
t = realloc(p, size);
|
||||
die_if_null(t);
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
char *
|
||||
xstrdup (const char *s) {
|
||||
char *t;
|
||||
|
||||
if (s == NULL)
|
||||
return NULL;
|
||||
|
||||
t = strdup(s);
|
||||
die_if_null(t);
|
||||
|
||||
return t;
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
#include <sys/types.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
extern void *xmalloc(size_t size);
|
||||
extern void *xrealloc(void *p, size_t size);
|
||||
extern char *xstrdup(const char *s);
|
||||
extern void die(int err, const char *fmt, ...);
|
||||
extern void (*at_die)(void);
|
1296
po/pt_BR.po
1296
po/pt_BR.po
File diff suppressed because it is too large
Load Diff
|
@ -110,7 +110,11 @@ current IRQ, is implied.
|
|||
|
||||
.TP
|
||||
.B \-T [on|off]
|
||||
This option tell the lp driver to trust or not the IRQ.
|
||||
This option is obsolete. It was added in Linux 2.1.131,
|
||||
and removed again in Linux 2.3.10. The below is for these
|
||||
old kernels only.
|
||||
|
||||
This option tells the lp driver to trust or not the IRQ.
|
||||
This option makes sense only if you are using interrupts.
|
||||
If you tell the lp driver to trust the irq, then, when the lp driver will
|
||||
get an irq, it will send the next pending character to the printer
|
||||
|
|
Loading…
Reference in New Issue