summaryrefslogtreecommitdiffstats
path: root/mount
diff options
context:
space:
mode:
authorKarel Zak2006-12-07 00:25:52 +0100
committerKarel Zak2006-12-07 00:25:52 +0100
commit612721dba838fe37af543421278416bb7acf770c (patch)
treec9e54454cd39b2c26604446ee1a91fb2e9443ed4 /mount
parentImported from util-linux-2.11m tarball. (diff)
downloadkernel-qcow2-util-linux-612721dba838fe37af543421278416bb7acf770c.tar.gz
kernel-qcow2-util-linux-612721dba838fe37af543421278416bb7acf770c.tar.xz
kernel-qcow2-util-linux-612721dba838fe37af543421278416bb7acf770c.zip
Imported from util-linux-2.11n tarball.
Diffstat (limited to 'mount')
-rw-r--r--mount/linux_fs.h6
-rw-r--r--mount/mount.846
-rw-r--r--mount/mount.c2
-rw-r--r--mount/mount_by_label.c46
-rw-r--r--mount/mount_guess_fstype.c235
-rw-r--r--mount/pivot_root.c9
6 files changed, 244 insertions, 100 deletions
diff --git a/mount/linux_fs.h b/mount/linux_fs.h
index 1ed02b8c5..53cdf573d 100644
--- a/mount/linux_fs.h
+++ b/mount/linux_fs.h
@@ -13,8 +13,10 @@
#endif
#endif
-#define MINIX_SUPER_MAGIC 0x137F /* original minix fs */
-#define MINIX_SUPER_MAGIC2 0x138F /* minix fs, 30 char names */
+#define MINIX_SUPER_MAGIC 0x137F /* minix v1, 14 char names */
+#define MINIX_SUPER_MAGIC2 0x138F /* minix v1, 30 char names */
+#define MINIX2_SUPER_MAGIC 0x2468 /* minix v2, 14 char names */
+#define MINIX2_SUPER_MAGIC2 0x2478 /* minix v2, 30 char names */
struct minix_super_block {
u_char s_dummy[16];
u_char s_magic[2];
diff --git a/mount/mount.8 b/mount/mount.8
index 0280bb844..7114b2952 100644
--- a/mount/mount.8
+++ b/mount/mount.8
@@ -36,6 +36,7 @@
.\" 990730, Yann Droneaud <lch@multimania.com>: updated page
.\" 991214, Elrond <Elrond@Wunder-Nett.org>: added some docs on devpts
.\" 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"
.SH NAME
@@ -347,6 +348,7 @@ currently supported are:
.IR romfs ,
.IR smbfs ,
.IR sysv ,
+.IR tmpfs ,
.IR udf ,
.IR ufs ,
.IR umsdos ,
@@ -391,9 +393,25 @@ is the default. If no
option is given, or if the
.B auto
type is specified, the superblock is probed for the filesystem type
-.RI ( minix ", " ext ", " ext2 ", " ext3 ", " xiafs ", " iso9660 ,
-.IR jfs ", " reiserfs ", " romfs ", " ufs ", " ntfs ", " qnx4 ", " bfs ,
-.IR xfs ", " cramfs ", " hfs ", " hpfs ", " adfs ", " vxfs
+.RI ( adfs ,
+.IR bfs ,
+.IR cramfs ,
+.IR ext ,
+.IR ext2 ,
+.IR ext3 ,
+.IR hfs ,
+.IR hpfs ,
+.IR iso9660 ,
+.IR jfs ,
+.IR minix ,
+.IR ntfs ,
+.IR qnx4 ,
+.IR reiserfs ,
+.IR romfs ,
+.IR ufs ,
+.IR vxfs ,
+.IR xfs ,
+.IR xiafs
are supported).
If this probe fails, mount will try to read the file
.IR /etc/filesystems ,
@@ -1235,6 +1253,28 @@ and the current version of
.SH "Mount options for sysv"
None.
+.SH "Mount options for tmpfs"
+The following parameters accept a suffix
+.BR k ,
+.B m
+or
+.B g
+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.
+The size is given in bytes, and rounded down to entire pages.
+The default is half of the memory.
+.TP
+.B nr_blocks=
+Set number of blocks.
+.TP
+.B nr_inodes=
+Set number of inodes.
+.TP
+.B mode=
+Set initial permissions of the root directory.
+
.SH "Mount options for udf"
.TP
.B gid=
diff --git a/mount/mount.c b/mount/mount.c
index 8d62087eb..97b8aebba 100644
--- a/mount/mount.c
+++ b/mount/mount.c
@@ -653,7 +653,7 @@ cdrom_setspeed(char *spec) {
int speed = atoi(opt_speed);
if ((cdrom = open(spec, O_RDONLY | O_NONBLOCK)) < 0)
- die(EX_FAIL, _("mount: cannot not open %s for setting speed"),
+ die(EX_FAIL, _("mount: cannot open %s for setting speed"),
spec);
if (ioctl(cdrom, CDROM_SELECT_SPEED, speed) < 0)
die(EX_FAIL, _("mount: cannot set speed: %s"),
diff --git a/mount/mount_by_label.c b/mount/mount_by_label.c
index f4d455d72..988974f77 100644
--- a/mount/mount_by_label.c
+++ b/mount/mount_by_label.c
@@ -9,6 +9,8 @@
* - Added cache for UUID and disk labels
* 2000-11-07 Nathan Scott <nathans@sgi.com>
* - Added XFS support
+ * 2001-11-22 Kirby Bohling <kbohling@birddog.com>
+ * - Added support of labels on LVM
*/
#include <stdio.h>
@@ -16,6 +18,9 @@
#include <ctype.h>
#include <fcntl.h>
#include <unistd.h>
+#include <errno.h>
+#include <sys/types.h> /* needed for opendir */
+#include <dirent.h>
#include "sundries.h" /* for xstrdup */
#include "linux_fs.h"
#include "mount_by_label.h"
@@ -23,6 +28,7 @@
#define PROC_PARTITIONS "/proc/partitions"
#define DEVLABELDIR "/dev"
+#define VG_DIR "/proc/lvm/VGs"
static struct uuidCache_s {
struct uuidCache_s *next;
@@ -87,6 +93,44 @@ uuidcache_addentry(char *device, char *label, char *uuid) {
memcpy(last->uuid, uuid, sizeof(last->uuid));
}
+/* LVM support - Kirby Bohling */
+static void
+uuidcache_init_lvm(void) {
+ char buffer[PATH_MAX];
+ char lvm_device[PATH_MAX];
+ DIR *vg_dir, *lv_list;
+ struct dirent *vg_iter, *lv_iter;
+ char uuid[16], *label;
+
+ vg_dir = opendir(VG_DIR);
+ if (vg_dir == NULL) /* to be expected */
+ return;
+
+ seekdir(vg_dir, 2);
+ while ((vg_iter = readdir(vg_dir)) != 0) {
+ sprintf(buffer, "%s/%s/LVs", VG_DIR, vg_iter->d_name);
+ lv_list = opendir(buffer);
+ if (lv_list == NULL) {
+ perror("mount (init_lvm)");
+ continue;
+ }
+ seekdir(lv_list, 2);
+ while ((lv_iter = readdir(lv_list)) != 0) {
+ /* Now we have the file.. could open it and read out
+ * where the device is, read the first line, second
+ * field... Instead we guess.
+ */
+ sprintf(lvm_device, "%s/%s/%s", DEVLABELDIR,
+ vg_iter->d_name, lv_iter->d_name);
+ if (!get_label_uuid(lvm_device, &label, uuid))
+ uuidcache_addentry(strdup(lvm_device),
+ label, uuid);
+ }
+ closedir(lv_list);
+ }
+ closedir(vg_dir);
+}
+
static void
uuidcache_init(void) {
char line[100];
@@ -152,6 +196,8 @@ uuidcache_init(void) {
}
fclose(procpt);
+
+ uuidcache_init_lvm();
}
#define UUID 1
diff --git a/mount/mount_guess_fstype.c b/mount/mount_guess_fstype.c
index f6940af36..6b8def09f 100644
--- a/mount/mount_guess_fstype.c
+++ b/mount/mount_guess_fstype.c
@@ -76,7 +76,7 @@ assemble4le(unsigned char *p) {
Corrected the test for xiafs - aeb
Read the superblock only once - aeb
Added a very weak heuristic for vfat - aeb
- Added iso9660, romfs, qnx4, udf, vxfs, swap - aeb
+ Added iso9660, minix-v2, romfs, qnx4, udf, vxfs, swap - aeb
Added a test for high sierra (iso9660) - quinlan@bucknell.edu
Added ufs from a patch by jj. But maybe there are several types of ufs?
Added ntfs from a patch by Richard Russon.
@@ -94,14 +94,47 @@ static char
"vxfs", "xfs", "xiafs"
};
+static struct tried {
+ struct tried *next;
+ char *type;
+} *tried = NULL;
+
static int
-tested(const char *device) {
- char **m;
+was_tested(const char *fstype) {
+ char **m;
+ struct tried *t;
+
+ for (m = magic_known; m - magic_known < SIZE(magic_known); m++)
+ if (!strcmp(*m, fstype))
+ return 1;
+ for (t = tried; t; t = t->next) {
+ if (!strcmp(t->type, fstype))
+ return 1;
+ }
+ return 0;
+}
- for (m = magic_known; m - magic_known < SIZE(magic_known); m++)
- if (!strcmp(*m, device))
- return 1;
- return 0;
+static void
+set_tested(const char *fstype) {
+ struct tried *t = xmalloc(sizeof(struct tried));
+
+ t->next = tried;
+ t->type = xstrdup(fstype);
+ tried = t;
+}
+
+static void
+free_tested(void) {
+ struct tried *t, *tt;
+
+ t = tried;
+ while(t) {
+ free(t->type);
+ tt = t->next;
+ free(t);
+ t = tt;
+ }
+ tried = NULL;
}
/* udf magic - I find that trying to mount garbage as an udf fs
@@ -194,57 +227,8 @@ fstype(const char *device) {
if (fd < 0)
return 0;
- if (lseek(fd, 1024, SEEK_SET) != 1024
- || read(fd, (char *) &sb, sizeof(sb)) != sizeof(sb))
- goto io_error;
-
- /* ext2 has magic in little-endian on disk, so "swapped" is
- superfluous; however, there have existed strange byteswapped
- PPC ext2 systems */
- if (ext2magic(sb.e2s) == EXT2_SUPER_MAGIC
- || ext2magic(sb.e2s) == EXT2_PRE_02B_MAGIC
- || ext2magic(sb.e2s) == swapped(EXT2_SUPER_MAGIC)) {
- type = "ext2";
-
- /* maybe even ext3? */
- if ((assemble4le(sb.e2s.s_feature_compat)
- & EXT3_FEATURE_COMPAT_HAS_JOURNAL) &&
- assemble4le(sb.e2s.s_journal_inum) != 0)
- type = "ext3,ext2";
- }
-
- else if (minixmagic(sb.ms) == MINIX_SUPER_MAGIC
- || minixmagic(sb.ms) == MINIX_SUPER_MAGIC2
- || minixmagic(sb.ms) == swapped(MINIX_SUPER_MAGIC2))
- type = "minix";
-
- else if (extmagic(sb.es) == EXT_SUPER_MAGIC)
- type = "ext";
-
- else if (vxfsmagic(sb.vs) == VXFS_SUPER_MAGIC)
- type = "vxfs";
-
- if (!type) {
- /* block 64 */
- if (lseek(fd, REISERFS_DISK_OFFSET_IN_BYTES, SEEK_SET) !=
- REISERFS_DISK_OFFSET_IN_BYTES
- || read(fd, (char *) &reiserfssb, sizeof(reiserfssb)) !=
- sizeof(reiserfssb))
- goto io_error;
- if (is_reiserfs_magic_string(&reiserfssb))
- type = "reiserfs";
- }
-
- if (!type) {
- /* block 8 */
- if (lseek(fd, REISERFS_OLD_DISK_OFFSET_IN_BYTES, SEEK_SET) !=
- REISERFS_OLD_DISK_OFFSET_IN_BYTES
- || read(fd, (char *) &reiserfssb, sizeof(reiserfssb)) !=
- sizeof(reiserfssb))
- goto io_error;
- if (is_reiserfs_magic_string(&reiserfssb))
- type = "reiserfs";
- }
+ /* do seeks and reads in disk order, otherwise a very short
+ partition may cause a failure because of read error */
if (!type) {
/* block 0 */
@@ -291,36 +275,42 @@ fstype(const char *device) {
}
if (!type) {
- /* block 32 */
- if (lseek(fd, JFS_SUPER1_OFF, SEEK_SET) != JFS_SUPER1_OFF
- || read(fd, (char *) &jfssb, sizeof(jfssb)) != sizeof(jfssb))
- goto io_error;
- if (!strncmp(jfssb.s_magic, JFS_MAGIC, 4))
- type = "jfs";
- }
+ /* block 1 */
+ if (lseek(fd, 1024, SEEK_SET) != 1024 ||
+ read(fd, (char *) &sb, sizeof(sb)) != sizeof(sb))
+ goto io_error;
+
+ /* ext2 has magic in little-endian on disk, so "swapped" is
+ superfluous; however, there have existed strange byteswapped
+ PPC ext2 systems */
+ if (ext2magic(sb.e2s) == EXT2_SUPER_MAGIC ||
+ ext2magic(sb.e2s) == EXT2_PRE_02B_MAGIC ||
+ ext2magic(sb.e2s) == swapped(EXT2_SUPER_MAGIC)) {
+ type = "ext2";
+
+ /* maybe even ext3? */
+ if ((assemble4le(sb.e2s.s_feature_compat)
+ & EXT3_FEATURE_COMPAT_HAS_JOURNAL) &&
+ assemble4le(sb.e2s.s_journal_inum) != 0)
+ type = "ext3,ext2";
+ }
- if (!type) {
- if (lseek(fd, 8192, SEEK_SET) != 8192
- || read(fd, (char *) &ufssb, sizeof(ufssb)) != sizeof(ufssb))
- goto io_error;
+ else if (minixmagic(sb.ms) == MINIX_SUPER_MAGIC ||
+ minixmagic(sb.ms) == MINIX_SUPER_MAGIC2 ||
+ minixmagic(sb.ms) == swapped(MINIX_SUPER_MAGIC2) ||
+ minixmagic(sb.ms) == MINIX2_SUPER_MAGIC ||
+ minixmagic(sb.ms) == MINIX2_SUPER_MAGIC2)
+ type = "minix";
- if (ufsmagic(ufssb) == UFS_SUPER_MAGIC) /* also test swapped version? */
- type = "ufs";
- }
-
- if (!type) {
- if (lseek(fd, 0x8000, SEEK_SET) != 0x8000
- || read(fd, (char *) &isosb, sizeof(isosb)) != sizeof(isosb))
- goto io_error;
+ else if (extmagic(sb.es) == EXT_SUPER_MAGIC)
+ type = "ext";
- if(strncmp(isosb.iso.id, ISO_STANDARD_ID, sizeof(isosb.iso.id)) == 0
- || strncmp(isosb.hs.id, HS_STANDARD_ID, sizeof(isosb.hs.id)) == 0)
- type = "iso9660";
- else if (may_be_udf(isosb.iso.id))
- type = "udf";
+ else if (vxfsmagic(sb.vs) == VXFS_SUPER_MAGIC)
+ type = "vxfs";
}
if (!type) {
+ /* block 1 */
if (lseek(fd, 0x400, SEEK_SET) != 0x400
|| read(fd, (char *) &hfssb, sizeof(hfssb)) != sizeof(hfssb))
goto io_error;
@@ -337,6 +327,41 @@ fstype(const char *device) {
}
if (!type) {
+ /* block 3 */
+ if (lseek(fd, 0xc00, SEEK_SET) != 0xc00
+ || read(fd, (char *) &adfssb, sizeof(adfssb)) != sizeof(adfssb))
+ goto io_error;
+
+ /* only a weak test */
+ if (may_be_adfs((u_char *) &adfssb)
+ && (adfsblksize(adfssb) >= 8 &&
+ adfsblksize(adfssb) <= 10))
+ type = "adfs";
+ }
+
+ if (!type) {
+ /* block 8 */
+ if (lseek(fd, 8192, SEEK_SET) != 8192
+ || read(fd, (char *) &ufssb, sizeof(ufssb)) != sizeof(ufssb))
+ goto io_error;
+
+ if (ufsmagic(ufssb) == UFS_SUPER_MAGIC) /* also test swapped version? */
+ type = "ufs";
+ }
+
+ if (!type) {
+ /* block 8 */
+ if (lseek(fd, REISERFS_OLD_DISK_OFFSET_IN_BYTES, SEEK_SET) !=
+ REISERFS_OLD_DISK_OFFSET_IN_BYTES
+ || read(fd, (char *) &reiserfssb, sizeof(reiserfssb)) !=
+ sizeof(reiserfssb))
+ goto io_error;
+ if (is_reiserfs_magic_string(&reiserfssb))
+ type = "reiserfs";
+ }
+
+ if (!type) {
+ /* block 8 */
if (lseek(fd, 0x2000, SEEK_SET) != 0x2000
|| read(fd, (char *) &hpfssb, sizeof(hpfssb)) != sizeof(hpfssb))
goto io_error;
@@ -346,15 +371,36 @@ fstype(const char *device) {
}
if (!type) {
- if (lseek(fd, 0xc00, SEEK_SET) != 0xc00
- || read(fd, (char *) &adfssb, sizeof(adfssb)) != sizeof(adfssb))
- goto io_error;
+ /* block 32 */
+ if (lseek(fd, JFS_SUPER1_OFF, SEEK_SET) != JFS_SUPER1_OFF
+ || read(fd, (char *) &jfssb, sizeof(jfssb)) != sizeof(jfssb))
+ goto io_error;
+ if (!strncmp(jfssb.s_magic, JFS_MAGIC, 4))
+ type = "jfs";
+ }
- /* only a weak test */
- if (may_be_adfs((u_char *) &adfssb)
- && (adfsblksize(adfssb) >= 8 &&
- adfsblksize(adfssb) <= 10))
- type = "adfs";
+ if (!type) {
+ /* block 32 */
+ if (lseek(fd, 0x8000, SEEK_SET) != 0x8000
+ || read(fd, (char *) &isosb, sizeof(isosb)) != sizeof(isosb))
+ goto io_error;
+
+ if(strncmp(isosb.iso.id, ISO_STANDARD_ID, sizeof(isosb.iso.id)) == 0
+ || strncmp(isosb.hs.id, HS_STANDARD_ID, sizeof(isosb.hs.id)) == 0)
+ type = "iso9660";
+ else if (may_be_udf(isosb.iso.id))
+ type = "udf";
+ }
+
+ if (!type) {
+ /* block 64 */
+ if (lseek(fd, REISERFS_DISK_OFFSET_IN_BYTES, SEEK_SET) !=
+ REISERFS_DISK_OFFSET_IN_BYTES
+ || read(fd, (char *) &reiserfssb, sizeof(reiserfssb)) !=
+ sizeof(reiserfssb))
+ goto io_error;
+ if (is_reiserfs_magic_string(&reiserfssb))
+ type = "reiserfs";
}
if (!type) {
@@ -381,7 +427,10 @@ fstype(const char *device) {
return(type);
io_error:
- perror(device);
+ if (errno)
+ perror(device);
+ else
+ fprintf(stderr, _("mount: error while guessing filesystem type\n"));
close(fd);
return 0;
}
@@ -479,10 +528,11 @@ procfsloop(int (*mount_fn)(struct mountargs *), struct mountargs *args,
fclose(procfs);
goto nexti;
}
- if (tested (fsname))
+ if (was_tested (fsname))
continue;
if (no && matching_type(fsname, notypes))
continue;
+ set_tested (fsname);
args->type = fsname;
if (verbose) {
printf(_("Trying %s\n"), fsname);
@@ -500,6 +550,7 @@ procfsloop(int (*mount_fn)(struct mountargs *), struct mountargs *args,
break;
}
}
+ free_tested();
fclose(procfs);
errno = errsv;
return ret;
diff --git a/mount/pivot_root.c b/mount/pivot_root.c
index fd4bef9df..674271ad2 100644
--- a/mount/pivot_root.c
+++ b/mount/pivot_root.c
@@ -4,11 +4,16 @@
#include <stdio.h>
-#include <linux/unistd.h>
+
+#ifdef __ia64__
+# include <sys/syscall.h>
+# define pivot_root(new_root,put_old) syscall(SYS_pivot_root,new_root,put_old)
+#else
+# include <linux/unistd.h>
static
_syscall2(int,pivot_root,const char *,new_root,const char *,put_old)
-
+#endif
int main(int argc,const char **argv)
{