[Ocfs2-tools-commits] manish commits r644 - trunk/mount.ocfs2
svn-commits at oss.oracle.com
svn-commits at oss.oracle.com
Tue Mar 15 22:29:11 CST 2005
Author: manish
Signed-off-by: mfasheh
Date: 2005-03-15 22:29:10 -0600 (Tue, 15 Mar 2005)
New Revision: 644
Added:
trunk/mount.ocfs2/paths.h
trunk/mount.ocfs2/xmalloc.c
trunk/mount.ocfs2/xmalloc.h
Removed:
trunk/mount.ocfs2/get_label_uuid.c
trunk/mount.ocfs2/get_label_uuid.h
trunk/mount.ocfs2/linux_fs.h
Modified:
trunk/mount.ocfs2/CREDITS
trunk/mount.ocfs2/Makefile
trunk/mount.ocfs2/fstab.c
trunk/mount.ocfs2/fstab.h
trunk/mount.ocfs2/mntent.c
trunk/mount.ocfs2/mntent.h
trunk/mount.ocfs2/mount.ocfs2.c
trunk/mount.ocfs2/mount.ocfs2.h
trunk/mount.ocfs2/nls.h
trunk/mount.ocfs2/opts.c
trunk/mount.ocfs2/opts.h
trunk/mount.ocfs2/realpath.c
trunk/mount.ocfs2/sundries.c
trunk/mount.ocfs2/sundries.h
Log:
Update to util-linux 2.12p mount code, and remove a bunch of effectively
dead code.
Signed-off-by: mfasheh
Modified: trunk/mount.ocfs2/CREDITS
===================================================================
--- trunk/mount.ocfs2/CREDITS 2005-03-15 23:38:14 UTC (rev 643)
+++ trunk/mount.ocfs2/CREDITS 2005-03-16 04:29:10 UTC (rev 644)
@@ -1,14 +1,14 @@
-The following files have been copied from util-linux-2.12a/mount:
- fstab.c/h
- get_label_uuid.c/h
- mntent.c/h
+The following files have been copied from util-linux-2.12p/mount:
+ fstab.[ch]
+ mntent.[ch]
mount_constants.h
- linux_fs.h
- realpath.c/h
- sundries.c/h
+ paths.h
+ realpath.[ch]
+ sundries.[ch]
+ xmalloc.[ch]
The following files have code which has been copied from one or more files
-in util-linux-2.12a/mount:
- opts.c/h
+in util-linux-2.12p/mount:
+ opts.[ch]
nls.h
Modified: trunk/mount.ocfs2/Makefile
===================================================================
--- trunk/mount.ocfs2/Makefile 2005-03-15 23:38:14 UTC (rev 643)
+++ trunk/mount.ocfs2/Makefile 2005-03-16 04:29:10 UTC (rev 644)
@@ -23,11 +23,14 @@
DEFINES = -DOCFS2_FLAT_INCLUDES -DO2DLM_FLAT_INCLUDES -DVERSION=\"$(VERSION)\"
CFILES = opts.c mount.ocfs2.c
-CFILES += fstab.c get_label_uuid.c mntent.c sundries.c realpath.c
+CFILES += fstab.c mntent.c realpath.c sundries.c xmalloc.c
+HFILES = $(subst .c,.h,$(CFILES))
+HFILES += mount_constants.h nls.h paths.h
+
OBJS = $(subst .c,.o,$(CFILES))
-DIST_FILES = $(CFILES)
+DIST_FILES = $(CFILES) $(HFILES)
mount.ocfs2: $(OBJS) $(LIBOCFS2_DEPS) $(LIBO2DLM_DEPS)
$(LINK) $(LIBOCFS2_LIBS) $(LIBO2DLM_LIBS) $(COM_ERR_LIBS)
Modified: trunk/mount.ocfs2/fstab.c
===================================================================
--- trunk/mount.ocfs2/fstab.c 2005-03-15 23:38:14 UTC (rev 643)
+++ trunk/mount.ocfs2/fstab.c 2005-03-16 04:29:10 UTC (rev 644)
@@ -11,8 +11,10 @@
#include <sys/stat.h>
#include "mntent.h"
#include "fstab.h"
-#include "sundries.h" /* for xmalloc() etc */
-#include "get_label_uuid.h"
+#include "sundries.h"
+#include "xmalloc.h"
+/* #include "mount_blkid.h" -- OCFS2 modification */
+#include "paths.h"
#include "nls.h"
#define streq(s, t) (strcmp ((s), (t)) == 0)
@@ -76,10 +78,11 @@
struct mntentchn mounttable, fstab;
static int got_mtab = 0;
-static int got_fstab = 0;
-static void read_mounttable(void), read_fstab(void);
+/* static int got_fstab = 0; -- OCFS2 modification */
+static void read_mounttable(void); /*, read_fstab(void); -- OCFS2 modification */
+
struct mntentchn *
mtab_head() {
if (!got_mtab)
@@ -87,19 +90,41 @@
return &mounttable;
}
+#if 0 /* OCFS2 modification */
struct mntentchn *
fstab_head() {
if (!got_fstab)
read_fstab();
return &fstab;
}
+#endif
static void
+my_free(const void *s) {
+ if (s)
+ free((void *) s);
+}
+
+static void
+discard_mntentchn(struct mntentchn *mc0) {
+ struct mntentchn *mc, *mc1;
+
+ for (mc = mc0->nxt; mc && mc != mc0; mc = mc1) {
+ mc1 = mc->nxt;
+ my_free(mc->m.mnt_fsname);
+ my_free(mc->m.mnt_dir);
+ my_free(mc->m.mnt_type);
+ my_free(mc->m.mnt_opts);
+ free(mc);
+ }
+}
+
+static void
read_mntentchn(mntFILE *mfp, const char *fnam, struct mntentchn *mc0) {
struct mntentchn *mc = mc0;
- struct mntent *mnt;
+ struct my_mntent *mnt;
- while ((mnt = my_getmntent (mfp)) != NULL) {
+ while ((mnt = my_getmntent(mfp)) != NULL) {
if (!streq(mnt->mnt_type, MNTTYPE_IGNORE)) {
mc->nxt = (struct mntentchn *) xmalloc(sizeof(*mc));
mc->nxt->prev = mc;
@@ -109,7 +134,7 @@
}
}
mc0->prev = mc;
- if (ferror (mfp->mntent_fp)) {
+ if (ferror(mfp->mntent_fp)) {
int errsv = errno;
error(_("warning: error reading %s: %s"),
fnam, strerror (errsv));
@@ -151,6 +176,7 @@
read_mntentchn(mfp, fnam, mc);
}
+#if 0 /* OCFS2 modification */
static void
read_fstab() {
mntFILE *mfp = NULL;
@@ -170,6 +196,7 @@
}
read_mntentchn(mfp, fnam, mc);
}
+#endif
/* Given the name NAME, try to find it in mtab. */
@@ -239,7 +266,7 @@
struct mntentchn *
getmntoptfile (const char *file) {
struct mntentchn *mc, *mc0;
- char *opts, *s;
+ const char *opts, *s;
int l;
if (!file)
@@ -258,22 +285,27 @@
return NULL;
}
+#if 0 /* OCFS2 modification */
static int
has_label(const char *device, const char *label) {
- char devuuid[16];
- char *devlabel;
+ const char *devlabel;
+ int ret;
- return !get_label_uuid(device, &devlabel, devuuid) &&
- !strcmp(label, devlabel);
+ devlabel = mount_get_volume_label_by_spec(device);
+ ret = !strcmp(label, devlabel);
+ /* free(devlabel); */
+ return ret;
}
static int
has_uuid(const char *device, const char *uuid){
- char devuuid[16];
- char *devlabel;
+ const char *devuuid;
+ int ret;
- return !get_label_uuid(device, &devlabel, devuuid) &&
- !memcmp(uuid, devuuid, sizeof(devuuid));
+ devuuid = mount_get_devname_by_uuid(device);
+ ret = !strcmp(uuid, devuuid);
+ /* free(devuuid); */
+ return ret;
}
/* Find the entry (SPEC,FILE) in fstab */
@@ -364,6 +396,7 @@
return mc;
return NULL;
}
+#endif
/* Updating mtab ----------------------------------------------*/
@@ -374,9 +407,11 @@
static int signals_have_been_setup = 0;
/* Ensure that the lock is released if we are interrupted. */
+extern char *strsignal(int sig); /* not always in <string.h> */
+
static void
handler (int sig) {
- die (EX_USER, "%s", sys_siglist[sig]);
+ die(EX_USER, "%s", strsignal(sig));
}
static void
@@ -384,6 +419,15 @@
/* 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
@@ -400,14 +444,17 @@
/* Where does the link point to? Obvious choices are mtab and mtab~~.
HJLu points out that the latter leads to races. Right now we use
- mtab~.<pid> instead. */
-#define MOUNTLOCK_LINKTARGET MOUNTED_LOCK "%d"
+ mtab~.<pid> instead. Use 20 as upper bound for the length of %d. */
+#define MOUNTLOCK_LINKTARGET MOUNTED_LOCK "%d"
+#define MOUNTLOCK_LINKTARGET_LTH (sizeof(MOUNTED_LOCK)+20)
void
lock_mtab (void) {
int tries = 3;
- char *linktargetfile;
+ char linktargetfile[MOUNTLOCK_LINKTARGET_LTH];
+ at_die = unlock_mtab;
+
if (!signals_have_been_setup) {
int sig = 0;
struct sigaction sa;
@@ -427,9 +474,6 @@
signals_have_been_setup = 1;
}
- /* somewhat clumsy, but some ancient systems do not have snprintf() */
- /* use 20 as upper bound for the length of %d output */
- linktargetfile = xmalloc(strlen(MOUNTLOCK_LINKTARGET) + 20);
sprintf(linktargetfile, MOUNTLOCK_LINKTARGET, getpid ());
/* Repeat until it was us who made the link */
@@ -455,6 +499,9 @@
(void) unlink(linktargetfile);
+ if (j == 0)
+ we_created_lockfile = 1;
+
if (j < 0 && errsv != EEXIST) {
die (EX_FILEIO, _("can't link lock file %s: %s "
"(use -n flag to override)"),
@@ -488,7 +535,6 @@
}
/* proceed anyway */
}
- we_created_lockfile = 1;
} else {
static int tries = 0;
@@ -516,15 +562,6 @@
}
}
-/* 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.
@@ -536,11 +573,11 @@
*/
void
-update_mtab (const char *dir, struct mntent *instead) {
+update_mtab (const char *dir, struct my_mntent *instead) {
mntFILE *mfp, *mftmp;
const char *fnam = MOUNTED;
struct mntentchn mtabhead; /* dummy */
- struct mntentchn *mc, *mc0, absent;
+ struct mntentchn *mc, *mc0, *absent = NULL;
if (mtab_does_not_exist() || mtab_is_a_symlink())
return;
@@ -571,6 +608,7 @@
if (mc && mc != mc0) {
mc->prev->nxt = mc->nxt;
mc->nxt->prev = mc->prev;
+ free(mc);
}
} else {
/* A remount */
@@ -578,12 +616,13 @@
}
} else if (instead) {
/* not found, add a new entry */
- absent.m = *instead;
- absent.nxt = mc0;
- absent.prev = mc0->prev;
- mc0->prev = &absent;
+ absent = xmalloc(sizeof(*absent));
+ absent->m = *instead;
+ absent->nxt = mc0;
+ absent->prev = mc0->prev;
+ mc0->prev = absent;
if (mc0->nxt == NULL)
- mc0->nxt = &absent;
+ mc0->nxt = absent;
}
/* write chain to mtemp */
@@ -603,6 +642,8 @@
}
}
+ discard_mntentchn(mc0);
+
if (fchmod (fileno (mftmp->mntent_fp),
S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH) < 0) {
int errsv = errno;
Modified: trunk/mount.ocfs2/fstab.h
===================================================================
--- trunk/mount.ocfs2/fstab.h 2005-03-15 23:38:14 UTC (rev 643)
+++ trunk/mount.ocfs2/fstab.h 2005-03-16 04:29:10 UTC (rev 644)
@@ -1,14 +1,4 @@
-#include <mntent.h>
-#define _PATH_FSTAB "/etc/fstab"
-#ifdef _PATH_MOUNTED
-#define MOUNTED_LOCK _PATH_MOUNTED "~"
-#define MOUNTED_TEMP _PATH_MOUNTED ".tmp"
-#else
-#define MOUNTED_LOCK "/etc/mtab~"
-#define MOUNTED_TEMP "/etc/mtab.tmp"
-#endif
-#define LOCK_TIMEOUT 10
-
+#include "mntent.h"
int mtab_is_writable(void);
int mtab_does_not_exist(void);
int mtab_is_a_symlink(void);
@@ -16,7 +6,7 @@
struct mntentchn {
struct mntentchn *nxt, *prev;
- struct mntent m;
+ struct my_mntent m;
};
struct mntentchn *mtab_head (void);
@@ -25,14 +15,15 @@
struct mntentchn *getmntdirbackward (const char *dir, struct mntentchn *mc);
struct mntentchn *getmntdevbackward (const char *dev, struct mntentchn *mc);
+#if 0 /* OCFS2 modification */
struct mntentchn *fstab_head (void);
struct mntentchn *getfsfile (const char *file);
struct mntentchn *getfsspec (const char *spec);
struct mntentchn *getfsspecfile (const char *spec, const char *file);
struct mntentchn *getfsuuidspec (const char *uuid);
struct mntentchn *getfsvolspec (const char *label);
+#endif
-#include <mntent.h>
void lock_mtab (void);
void unlock_mtab (void);
-void update_mtab (const char *special, struct mntent *with);
+void update_mtab (const char *special, struct my_mntent *with);
Deleted: trunk/mount.ocfs2/get_label_uuid.c
===================================================================
--- trunk/mount.ocfs2/get_label_uuid.c 2005-03-15 23:38:14 UTC (rev 643)
+++ trunk/mount.ocfs2/get_label_uuid.c 2005-03-16 04:29:10 UTC (rev 644)
@@ -1,174 +0,0 @@
-/*
- * Get label. Used by both mount and umount.
- */
-#define _GNU_SOURCE
-#include <stdio.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-#include <endian.h>
-#include <sys/stat.h>
-#include <errno.h>
-
-#include "linux_fs.h"
-#include "get_label_uuid.h"
-
-/*
- * See whether this device has (the magic of) a RAID superblock at the end.
- * If so, it probably is, or has been, part of a RAID array.
- *
- * For the moment this test is switched off - it causes problems.
- * "Checking for a disk label should only be done on the full raid,
- * not on the disks that form the raid array. This test causes a lot of
- * problems when run on my striped promise fasttrak 100 array."
- */
-
-#if BYTE_ORDER == BIG_ENDIAN
-#define INT32_FROM_LE(val) ((unsigned int) ( \
- (((unsigned int) (val) & (unsigned int) 0x000000ffU) << 24) | \
- (((unsigned int) (val) & (unsigned int) 0x0000ff00U) << 8) | \
- (((unsigned int) (val) & (unsigned int) 0x00ff0000U) >> 8) | \
- (((unsigned int) (val) & (unsigned int) 0xff000000U) >> 24)))
-#else
-#define INT32_FROM_LE(val) (val)
-#endif
-
-typedef struct {
- unsigned int md_magic;
-} mdp_super_t;
-#ifndef MD_SB_MAGIC
-#define MD_SB_MAGIC 0xa92b4efc
-#endif
-#ifndef MD_RESERVED_BYTES
-#define MD_RESERVED_BYTES 65536L
-#endif
-#ifndef MD_NEW_SIZE_BYTES
-#define MD_NEW_SIZE_BYTES(x) ((x & ~(MD_RESERVED_BYTES - 1L)) - MD_RESERVED_BYTES)
-#endif
-
-static int
-is_raid_partition(int fd)
-{
- mdp_super_t mdsb;
- int n;
- struct stat sbuf;
- if(fstat(fd, &sbuf))
- return 2;
- if(!sbuf.st_size) {
- uint64_t bsize64;
- unsigned int bsize32;
- if(!ioctl(fd, BLKGETSIZE64, &bsize64))
- sbuf.st_size = bsize64;
- else if(!ioctl(fd, BLKGETSIZE, &bsize32))
- sbuf.st_size = bsize32;
- }
- if(!sbuf.st_size) return 3;
- /* hardcode 4096 here in various places,
- because that's what it's defined to be.
- Note that even if we used the actual kernel headers,
- sizeof(mdp_super_t) is slightly larger in the 2.2 kernel on 64-bit
- archs, so using that wouldn't work. */
- lseek(fd, MD_NEW_SIZE_BYTES(sbuf.st_size), SEEK_SET);
- n = 4096; if(sizeof(mdsb) < n) n = sizeof(mdsb);
- if(read(fd, &mdsb, n) != n)
- return 4; /* error */
- mdsb.md_magic = INT32_FROM_LE(mdsb.md_magic);
- return (mdsb.md_magic == MD_SB_MAGIC); /* If this device has a
- RAID superblock at
- the end, it must be
- part of a RAID
- array. */
-}
-
-/* for now, only ext2, ext3, xfs, ocfs are supported */
-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;
- struct ocfs_volume_header ovh; /* Oracle */
- struct ocfs_volume_label olbl;
- union {
- struct swap_header_v1_2 hdr;
- char swap_data[1<<16];
- } swap_u;
-
- fd = open(device, O_RDONLY);
- if (fd < 0)
- return rv;
-
- /* If there is a RAID partition, or an error, ignore this partition */
- if (is_raid_partition(fd)) {
- close(fd);
- return rv;
- }
-
- if(getpagesize() > sizeof(swap_u.swap_data)) {
- errno = EFAULT;
- return 1;
- }
-
- 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;
- }
- else 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;
- }
- else 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;
- }
- else 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)) {
- if (assemble4le(jfssb.s_version) == 1) {
- /* old (OS/2 compatible) jfs filesystems don't
- have UUIDs and only have a very small label. */
- memset(uuid, 0, 16);
- namesize = sizeof(jfssb.s_fpack);
- if ((*label = calloc(namesize + 1, 1)) != NULL)
- memcpy(*label, jfssb.s_fpack, namesize);
- } 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);
- }
- rv = 0;
- }
- else if (lseek(fd, 0, SEEK_SET) == 0
- && read(fd, &swap_u, getpagesize()) == getpagesize()
- && !strncmp(swap_u.swap_data+getpagesize()-10, "SWAPSPACE2", strlen("SWAPSPACE2"))) {
- memcpy(uuid, swap_u.hdr.uuid, sizeof(swap_u.hdr.uuid));
- if(label)
- *label = swap_u.hdr.volume_name[0]?strndup(swap_u.hdr.volume_name, sizeof(swap_u.hdr.volume_name)):NULL;
- rv = 0;
- }
-
-
- close(fd);
- return rv;
-}
Deleted: trunk/mount.ocfs2/get_label_uuid.h
===================================================================
--- trunk/mount.ocfs2/get_label_uuid.h 2005-03-15 23:38:14 UTC (rev 643)
+++ trunk/mount.ocfs2/get_label_uuid.h 2005-03-16 04:29:10 UTC (rev 644)
@@ -1 +0,0 @@
-int get_label_uuid(const char *device, char **label, char *uuid);
Deleted: trunk/mount.ocfs2/linux_fs.h
===================================================================
--- trunk/mount.ocfs2/linux_fs.h 2005-03-15 23:38:14 UTC (rev 643)
+++ trunk/mount.ocfs2/linux_fs.h 2005-03-16 04:29:10 UTC (rev 644)
@@ -1,296 +0,0 @@
-/* Including <linux/fs.h> became more and more painful.
- Below a very abbreviated version of some declarations,
- only designed to be able to check a magic number
- in case no filesystem type was given. */
-
-#ifndef BLKGETSIZE
-#ifndef _IO
-/* pre-1.3.45 */
-#define BLKGETSIZE 0x1260 /* return device size */
-#else
-/* same on i386, m68k, arm; different on alpha, mips, sparc, ppc */
-#define BLKGETSIZE _IO(0x12,96)
-#endif
-#endif
-
-#include <inttypes.h>
-#ifndef BLKGETSIZE64
-#include <sys/ioctl.h>
-#define BLKGETSIZE64 _IOR(0x12,114,sizeof(uint64_t))
-#endif
-
-#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];
-};
-#define minixmagic(s) assemble2le(s.s_magic)
-
-#define ISODCL(from, to) (to - from + 1)
-#define ISO_STANDARD_ID "CD001"
-struct iso_volume_descriptor {
- char type[ISODCL(1,1)]; /* 711 */
- char id[ISODCL(2,6)];
- char version[ISODCL(7,7)];
- char data[ISODCL(8,2048)];
-};
-
-#define HS_STANDARD_ID "CDROM"
-struct hs_volume_descriptor {
- char foo[ISODCL ( 1, 8)]; /* 733 */
- char type[ISODCL ( 9, 9)]; /* 711 */
- char id[ISODCL ( 10, 14)];
- char version[ISODCL ( 15, 15)]; /* 711 */
- char data[ISODCL(16,2048)];
-};
-
-#define EXT_SUPER_MAGIC 0x137D
-struct ext_super_block {
- u_char s_dummy[56];
- u_char s_magic[2];
-};
-#define extmagic(s) assemble2le(s.s_magic)
-
-#define EXT2_PRE_02B_MAGIC 0xEF51
-#define EXT2_SUPER_MAGIC 0xEF53
-#define EXT3_FEATURE_COMPAT_HAS_JOURNAL 0x0004
-struct ext2_super_block {
- u_char s_dummy1[56];
- u_char s_magic[2];
- u_char s_dummy2[34];
- u_char s_feature_compat[4];
- u_char s_feature_incompat[4];
- u_char s_feature_ro_compat[4];
- u_char s_uuid[16];
- u_char s_volume_name[16];
- u_char s_dummy3[88];
- u_char s_journal_inum[4]; /* ext3 only */
-};
-#define ext2magic(s) assemble2le(s.s_magic)
-
-struct reiserfs_super_block
-{
- u_char s_block_count[4];
- u_char s_free_blocks[4];
- u_char s_root_block[4];
- u_char s_journal_block[4];
- u_char s_journal_dev[4];
- u_char s_orig_journal_size[4];
- u_char s_journal_trans_max[4];
- u_char s_journal_block_count[4];
- u_char s_journal_max_batch[4];
- u_char s_journal_max_commit_age[4];
- u_char s_journal_max_trans_age[4];
- u_char s_blocksize[2];
- u_char s_oid_maxsize[2];
- u_char s_oid_cursize[2];
- u_char s_state[2];
- u_char s_magic[12];
-};
-#define REISERFS_SUPER_MAGIC_STRING "ReIsErFs"
-#define REISER2FS_SUPER_MAGIC_STRING "ReIsEr2Fs"
-#define REISERFS_DISK_OFFSET_IN_BYTES (64 * 1024)
-/* the spot for the super in versions 3.5 - 3.5.10 (inclusive) */
-#define REISERFS_OLD_DISK_OFFSET_IN_BYTES (8 * 1024)
-
-#define _XIAFS_SUPER_MAGIC 0x012FD16D
-struct xiafs_super_block {
- u_char s_boot_segment[512]; /* 1st sector reserved for boot */
- u_char s_dummy[60];
- u_char s_magic[4];
-};
-#define xiafsmagic(s) assemble4le(s.s_magic)
-
-/* From jj at sunsite.ms.mff.cuni.cz Mon Mar 23 15:19:05 1998 */
-#define UFS_SUPER_MAGIC_LE 0x00011954
-#define UFS_SUPER_MAGIC_BE 0x54190100
-struct ufs_super_block {
- u_char s_dummy[0x55c];
- u_char s_magic[4];
-};
-#define ufsmagic(s) assemble4le(s.s_magic)
-
-/* From Richard.Russon at ait.co.uk Wed Feb 24 08:05:27 1999 */
-#define NTFS_SUPER_MAGIC "NTFS"
-struct ntfs_super_block {
- u_char s_dummy[3];
- u_char s_magic[4];
-};
-
-/* From inspection of a few FAT filesystems - aeb */
-/* Unfortunately I find almost the same thing on an extended partition;
- it looks like a primary has some directory entries where the extended
- has a partition table: IO.SYS, MSDOS.SYS, WINBOOT.SYS */
-struct fat_super_block {
- u_char s_dummy[3];
- u_char s_os[8]; /* "MSDOS5.0" or "MSWIN4.0" or "MSWIN4.1" */
- /* mtools-3.9.4 writes "MTOOL394" */
- u_char s_dummy2[32];
- u_char s_label[11]; /* for DOS? */
- u_char s_fs[8]; /* "FAT12 " or "FAT16 " or all zero */
- /* OS/2 BM has "FAT " here. */
- u_char s_dummy3[9];
- u_char s_label2[11]; /* for Windows? */
- u_char s_fs2[8]; /* garbage or "FAT32 " */
-};
-
-#define XFS_SUPER_MAGIC "XFSB"
-struct xfs_super_block {
- u_char s_magic[4];
- u_char s_dummy[28];
- u_char s_uuid[16];
- u_char s_dummy2[60];
- u_char s_fname[12];
-};
-
-#define CRAMFS_SUPER_MAGIC 0x28cd3d45
-#define CRAMFS_SUPER_MAGIC_BE 0x453dcd28
-struct cramfs_super_block {
- u_char s_magic[4];
- u_char s_dummy[12];
- u_char s_id[16];
-};
-#define cramfsmagic(s) assemble4le(s.s_magic)
-
-#define HFS_SUPER_MAGIC 0x4244
-struct hfs_super_block {
- u_char s_magic[2]; /* drSigWord */
- u_char s_dummy[18];
- u_char s_blksize[4]; /* drAlBlkSiz */
-};
-#define hfsmagic(s) assemble2be(s.s_magic)
-#define hfsblksize(s) assemble4be(s.s_blksize)
-
-#define HPFS_SUPER_MAGIC 0xf995e849
-struct hpfs_super_block {
- u_char s_magic[4];
- u_char s_magic2[4];
-};
-#define hpfsmagic(s) assemble4le(s.s_magic)
-
-struct adfs_super_block {
- u_char s_dummy[448];
- u_char s_blksize[1];
- u_char s_dummy2[62];
- u_char s_checksum[1];
-};
-#define adfsblksize(s) ((uint) s.s_blksize[0])
-
-/* found in first 4 bytes of block 1 */
-struct vxfs_super_block {
- u_char s_magic[4];
-};
-#define vxfsmagic(s) assemble4le(s.s_magic)
-#define VXFS_SUPER_MAGIC 0xa501FCF5
-
-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[16];
-};
-#define JFS_SUPER1_OFF 0x8000
-#define JFS_MAGIC "JFS1"
-
-struct sysv_super_block {
- u_char s_dummy1[504];
- u_char s_magic[4];
- u_char type[4];
-};
-#define sysvmagic(s) assemble4le(s.s_magic)
-#define SYSV_SUPER_MAGIC 0xfd187e20
-
-struct mdp_super_block {
- u_char md_magic[4];
-};
-#define MD_SB_MAGIC 0xa92b4efc
-#define mdsbmagic(s) assemble4le(s.md_magic)
-
-struct ocfs_volume_header {
- u_char minor_version[4];
- u_char major_version[4];
- u_char signature[128];
-};
-
-struct ocfs_volume_label {
- u_char disk_lock[48];
- u_char label[64];
- u_char label_len[2];
-};
-
-#define ocfslabellen(o) assemble2le(o.label_len)
-#define OCFS_MAGIC "OracleCFS"
-
-struct efs_volume_directory { /* size 16 */
- char vd_name[8];
- char vd_lbn[4];
- char vd_nbytes[4];
-};
-
-struct efs_partition_table { /* size 12 */
- char pt_nblks[4];
- char pt_firstlbn[4];
- char pt_type[4];
-};
-
-struct efs_volume_header { /* size 512 */
- char vh_magic[4];
- short vh_rootpt;
- short vh_swappt;
- char vh_bootfile[16];
- char pad[48];
- struct efs_volume_directory vh_vd[15];
- struct efs_partition_table vh_pt[16];
- int vh_csum;
- int vh_fill;
-};
-
-struct efs_super {
- char fs_stuff[512+28];
- char fs_magic[4];
- char fs_fname[6];
- char fs_fpack[6];
- /* ... */
-};
-
-#define EFS_VHMAGIC 0x0be5a941 /* big endian */
-#define EFS_SBMAGIC 0x00072959 /* idem */
-#define EFS_SBMAGIC2 0x0007295a /* idem */
-
-static inline int
-assemble2le(unsigned char *p) {
- return (p[0] | (p[1] << 8));
-}
-
-static inline int
-assemble2be(unsigned char *p) {
- return (p[1] | (p[0] << 8));
-}
-
-static inline int
-assemble4le(unsigned char *p) {
- return (p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24));
-}
-
-static inline int
-assemble4be(unsigned char *p) {
- return (p[3] | (p[2] << 8) | (p[1] << 16) | (p[0] << 24));
-}
-
-/* Linux swap */
-struct swap_header_v1_2 {
- char bootbits[1024]; /* Space for disklabel etc. */
- unsigned int version;
- unsigned int last_page;
- unsigned int nr_badpages;
- char uuid[16];
- char volume_name[16];
- unsigned int padding[117];
- unsigned int badpages[1];
-};
Modified: trunk/mount.ocfs2/mntent.c
===================================================================
--- trunk/mount.ocfs2/mntent.c 2005-03-15 23:38:14 UTC (rev 643)
+++ trunk/mount.ocfs2/mntent.c 2005-03-16 04:29:10 UTC (rev 644)
@@ -21,7 +21,7 @@
static unsigned char need_escaping[] = { ' ', '\t', '\n', '\\' };
static char *
-mangle(unsigned char *s) {
+mangle(const unsigned char *s) {
char *ss, *sp;
int n;
@@ -98,7 +98,7 @@
mntFILE *mfp = xmalloc(sizeof(*mfp));
mode_t old_umask = umask(077);
- mfp->mntent_fp = fopen (file, mode);
+ mfp->mntent_fp = fopen(file, mode);
umask(old_umask);
mfp->mntent_file = xstrdup(file);
mfp->mntent_errs = (mfp->mntent_fp == NULL);
@@ -118,9 +118,8 @@
}
}
-
int
-my_addmntent (mntFILE *mfp, struct mntent *mnt) {
+my_addmntent (mntFILE *mfp, struct my_mntent *mnt) {
char *m1, *m2, *m3, *m4;
int res;
@@ -132,22 +131,21 @@
m3 = mangle(mnt->mnt_type);
m4 = mangle(mnt->mnt_opts);
- res = ((fprintf (mfp->mntent_fp, "%s %s %s %s %d %d\n",
- m1, m2, m3, m4, mnt->mnt_freq, mnt->mnt_passno)
- < 0) ? 1 : 0);
+ res = fprintf (mfp->mntent_fp, "%s %s %s %s %d %d\n",
+ m1, m2, m3, m4, mnt->mnt_freq, mnt->mnt_passno);
free(m1);
free(m2);
free(m3);
free(m4);
- return res;
+ return (res < 0) ? 1 : 0;
}
/* Read the next entry from the file fp. Stop reading at an incorrect entry. */
-struct mntent *
+struct my_mntent *
my_getmntent (mntFILE *mfp) {
static char buf[4096];
- static struct mntent me;
+ static struct my_mntent me;
char *s;
again:
@@ -193,7 +191,7 @@
s = skip_nonspaces(s);
s = skip_spaces(s);
- if(isdigit(*s)) {
+ if (isdigit(*s)) {
me.mnt_freq = atoi(s);
while(isdigit(*s)) s++;
} else
Modified: trunk/mount.ocfs2/mntent.h
===================================================================
--- trunk/mount.ocfs2/mntent.h 2005-03-15 23:38:14 UTC (rev 643)
+++ trunk/mount.ocfs2/mntent.h 2005-03-16 04:29:10 UTC (rev 644)
@@ -1,5 +1,15 @@
-#include <mntent.h> /* for struct mntent */
+#ifndef MY_MNTENT_H
+#define MY_MNTENT_H
+struct my_mntent {
+ const char *mnt_fsname;
+ const char *mnt_dir;
+ const char *mnt_type;
+ const char *mnt_opts;
+ int mnt_freq;
+ int mnt_passno;
+};
+
#define ERR_MAX 5
typedef struct mntFILEstruct {
@@ -12,5 +22,7 @@
mntFILE *my_setmntent (const char *file, char *mode);
void my_endmntent (mntFILE *mfp);
-int my_addmntent (mntFILE *mfp, struct mntent *mnt);
-struct mntent *my_getmntent (mntFILE *mfp);
+int my_addmntent (mntFILE *mfp, struct my_mntent *mnt);
+struct my_mntent *my_getmntent (mntFILE *mfp);
+
+#endif
Modified: trunk/mount.ocfs2/mount.ocfs2.c
===================================================================
--- trunk/mount.ocfs2/mount.ocfs2.c 2005-03-15 23:38:14 UTC (rev 643)
+++ trunk/mount.ocfs2/mount.ocfs2.c 2005-03-16 04:29:10 UTC (rev 644)
@@ -23,11 +23,13 @@
#include "mount.ocfs2.h"
int verbose = 0;
-int mount_quiet=0;
-int nomtab = 0;
+int mount_quiet = 0;
char *progname = NULL;
-char op_buf[PAGE_SIZE];
+static int nomtab = 0;
+
+static char op_buf[PAGE_SIZE];
+
struct mount_options {
char *dev;
char *dir;
@@ -106,10 +108,10 @@
}
/*
- * Code based on similar function in util-linux-2.12a/mount/mount.c
+ * Code based on similar function in util-linux-2.12p/mount/mount.c
*
*/
-static void print_one (const struct mntent *me)
+static void print_one(const struct my_mntent *me)
{
if (mount_quiet)
return ;
@@ -125,15 +127,21 @@
printf ("\n");
}
+
+static void my_free(const void *s)
+{
+ if (s)
+ free((void *) s);
+}
+
/*
- * Code based on similar function in util-linux-2.12a/mount/mount.c
+ * Code based on similar function in util-linux-2.12p/mount/mount.c
*
*/
static void update_mtab_entry(char *spec, char *node, char *type, char *opts,
int flags, int freq, int pass)
{
- struct mntent mnt;
- mntFILE *mfp;
+ struct my_mntent mnt;
mnt.mnt_fsname = canonicalize (spec);
mnt.mnt_dir = canonicalize (node);
@@ -143,38 +151,37 @@
mnt.mnt_passno = pass;
/* We get chatty now rather than after the update to mtab since the
- mount succeeded, even if the write to /etc/mtab should fail. */
+ mount succeeded, even if the write to /etc/mtab should fail. */
if (verbose)
print_one (&mnt);
- if (nomtab || !mtab_is_writable())
- goto bail;
+ if (!nomtab && mtab_is_writable()) {
+#if 0
+ if (flags & MS_REMOUNT)
+ update_mtab (mnt.mnt_dir, &mnt);
+ else
+#endif
+ {
+ mntFILE *mfp;
-// if (flags & MS_REMOUNT) {
-// update_mtab (mnt.mnt_dir, &mnt);
-// goto bail;
-// }
+ lock_mtab();
- lock_mtab();
-
- mfp = my_setmntent(MOUNTED, "a+");
- if (mfp == NULL || mfp->mntent_fp == NULL) {
- com_err(progname, OCFS2_ET_IO, "%s, %s", MOUNTED,
- strerror(errno));
- goto unlock;
+ mfp = my_setmntent(MOUNTED, "a+");
+ if (mfp == NULL || mfp->mntent_fp == NULL) {
+ com_err(progname, OCFS2_ET_IO, "%s, %s",
+ MOUNTED, strerror(errno));
+ } else {
+ if ((my_addmntent (mfp, &mnt)) == 1) {
+ com_err(progname, OCFS2_ET_IO, "%s, %s",
+ MOUNTED, strerror(errno));
+ }
+ }
+ my_endmntent(mfp);
+ unlock_mtab();
+ }
}
-
- if ((my_addmntent (mfp, &mnt)) == 1) {
- com_err(progname, OCFS2_ET_IO, "%s, %s", MOUNTED,
- strerror(errno));
- }
-
- my_endmntent(mfp);
-
-unlock:
- unlock_mtab();
-bail:
- return ;
+ my_free(mnt.mnt_fsname);
+ my_free(mnt.mnt_dir);
}
static int get_my_nodenum(uint8_t *nodenum)
@@ -833,14 +840,10 @@
update_mtab_entry(mo.dev, mo.dir, "ocfs2", mo.xtra_opts, mo.flags, 0, 0);
bail:
- if (mo.dev)
- free(mo.dev);
- if (mo.dir)
- free(mo.dir);
- if (mo.opts)
- free(mo.opts);
- if (mo.xtra_opts)
- free(mo.xtra_opts);
+ free(mo.dev);
+ free(mo.dir);
+ free(mo.opts);
+ free(mo.xtra_opts);
return ret;
}
Modified: trunk/mount.ocfs2/mount.ocfs2.h
===================================================================
--- trunk/mount.ocfs2/mount.ocfs2.h 2005-03-15 23:38:14 UTC (rev 643)
+++ trunk/mount.ocfs2/mount.ocfs2.h 2005-03-16 04:29:10 UTC (rev 644)
@@ -39,11 +39,11 @@
#include <sys/stat.h>
#include "fstab.h"
-#include "get_label_uuid.h"
-#include "linux_fs.h"
#include "nls.h"
+#include "paths.h"
#include "realpath.h"
#include "sundries.h"
+#include "xmalloc.h"
#include "mntent.h"
#include "mount_constants.h"
#include "opts.h"
Modified: trunk/mount.ocfs2/nls.h
===================================================================
--- trunk/mount.ocfs2/nls.h 2005-03-15 23:38:14 UTC (rev 643)
+++ trunk/mount.ocfs2/nls.h 2005-03-16 04:29:10 UTC (rev 644)
@@ -1,7 +1,7 @@
/*
* nls.h
*
- * Code extracted from util-linux-2.12a/mount/nls.h
+ * Code extracted from util-linux-2.12p/mount/nls.h
*
* Copyright (C) 2005 Oracle. All rights reserved.
*
Modified: trunk/mount.ocfs2/opts.c
===================================================================
--- trunk/mount.ocfs2/opts.c 2005-03-15 23:38:14 UTC (rev 643)
+++ trunk/mount.ocfs2/opts.c 2005-03-16 04:29:10 UTC (rev 644)
@@ -28,18 +28,27 @@
#include <grp.h>
#include <pwd.h>
+/* Map from -o and fstab option strings to the flag argument to mount(2). */
+struct opt_map {
+ const char *opt; /* option name */
+ int skip; /* skip in mtab option string */
+ int inv; /* true if flag value should be inverted */
+ int mask; /* flag mask value */
+};
+
/* Custom mount options for our own purposes. */
/* Maybe these should now be freed for kernel use again */
#define MS_NOAUTO 0x80000000
#define MS_USERS 0x40000000
#define MS_USER 0x20000000
#define MS_OWNER 0x10000000
-#define MS_PAMCONSOLE 0x08000000
-#define MS_NETDEV 0x00020000
+#define MS_GROUP 0x08000000
+#define MS_PAMCONSOLE 0x04000000
+#define MS_COMMENT 0x00020000
#define MS_LOOP 0x00010000
/* Options that we keep the mount system call from seeing. */
-#define MS_NOSYS (MS_NOAUTO|MS_USERS|MS_USER|MS_NETDEV|MS_LOOP|MS_PAMCONSOLE)
+#define MS_NOSYS (MS_NOAUTO|MS_USERS|MS_USER|MS_COMMENT|MS_LOOP|MS_PAMCONSOLE)
/* Options that we keep from appearing in the options field in the mtab. */
#define MS_NOMTAB (MS_REMOUNT|MS_NOAUTO|MS_USERS|MS_USER|MS_PAMCONSOLE)
@@ -50,13 +59,6 @@
/* Options that we make owner-mounted devices have by default */
#define MS_OWNERSECURE (MS_NOSUID|MS_NODEV)
-struct opt_map {
- const char *opt; /* option name */
- int skip; /* skip in mtab option string */
- int inv; /* true if flag value should be inverted */
- int mask; /* flag mask value */
-};
-
static const struct opt_map opt_map[] = {
{ "defaults", 0, 0, 0 }, /* default options */
{ "ro", 1, 0, MS_RDONLY }, /* read-only */
@@ -80,7 +82,12 @@
{ "nouser", 0, 1, MS_USER }, /* Forbid ordinary user to mount */
{ "owner", 0, 0, MS_OWNER }, /* Let the owner of the device mount */
{ "noowner", 0, 1, MS_OWNER }, /* Device owner has no special privs */
- { "_netdev", 0, 0, MS_NETDEV }, /* Device accessible only via network */
+ { "group", 0, 0, MS_GROUP }, /* Let the group of the device mount */
+ { "nogroup", 0, 1, MS_GROUP }, /* Device group has no special privs */
+ { "_netdev", 0, 0, MS_COMMENT}, /* Device accessible only via network */
+ { "comment", 0, 0, MS_COMMENT}, /* fstab comment only (kudzu,_netdev)*/
+
+ /* add new options here */
{ "pamconsole", 0, 0, MS_PAMCONSOLE }, /* Allow users at console to mount */
{ "nopamconsole", 0, 1, MS_PAMCONSOLE }, /* Console user has no special privs */
#ifdef MS_NOSUB
@@ -104,14 +111,14 @@
{ "diratime", 0, 1, MS_NODIRATIME }, /* Update dir access times */
{ "nodiratime", 0, 0, MS_NODIRATIME },/* Do not update dir access times */
#endif
- { "kudzu", 0, 0, 0 }, /* Silently remove this option (backwards compat use only) */
- { "managed", 0, 0, 0 }, /* Silently remove this option */
+ { "kudzu", 0, 0, MS_COMMENT }, /* Silently remove this option (backwards compat use only) */
+ { "managed", 0, 0, MS_COMMENT }, /* Silently remove this option */
{ NULL, 0, 0, 0 }
};
static char *opt_loopdev, *opt_vfstype, *opt_offset, *opt_encryption,
- *opt_speed;
+ *opt_speed, *opt_comment;
static struct string_opt_map {
char *tag;
@@ -123,6 +130,7 @@
{ "offset=", 0, &opt_offset },
{ "encryption=", 0, &opt_encryption },
{ "speed=", 0, &opt_speed },
+ { "comment=", 1, &opt_comment },
{ NULL, 0, NULL }
};
@@ -148,12 +156,13 @@
}
return 0;
}
+
/*
* Look for OPT in opt_map table and return mask value.
* If OPT isn't found, tack it onto extra_opts (which is non-NULL).
* 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)
+static inline void parse_opt (const char *opt, int *mask, char *extra_opts, int len)
{
const struct opt_map *om;
@@ -166,9 +175,9 @@
if ((om->mask == MS_USER || om->mask == MS_USERS || om->mask == MS_PAMCONSOLE)
&& !om->inv)
*mask |= MS_SECURE;
- if ((om->mask == MS_OWNER) && !om->inv)
+ if ((om->mask == MS_OWNER || om->mask == MS_GROUP)
+ && !om->inv)
*mask |= MS_OWNERSECURE;
-
#ifdef MS_SILENT
if (om->mask == MS_SILENT && om->inv) {
mount_quiet = 1;
@@ -178,7 +187,9 @@
return;
}
- if (*extra_opts)
+ len -= strlen(extra_opts);
+
+ if (*extra_opts && --len > 0)
strcat(extra_opts, ",");
/* convert nonnumeric ids to numeric */
@@ -188,7 +199,8 @@
if (pw) {
sprintf(uidbuf, "uid=%d", pw->pw_uid);
- strcat(extra_opts, uidbuf);
+ if ((len -= strlen(uidbuf)) > 0)
+ strcat(extra_opts, uidbuf);
return;
}
}
@@ -198,33 +210,40 @@
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
gets the standard options (indicated by bits) and extra_opts all the rest */
-void parse_opts (char *opts, int *flags, char **extra_opts)
+void parse_opts (char *options, int *flags, char **extra_opts)
{
- char *opt;
-
*flags = 0;
*extra_opts = NULL;
clear_string_opts();
- if (opts != NULL) {
- *extra_opts = xmalloc (strlen (opts) + 1);
+ if (options != NULL) {
+ char *opts = xstrdup(options);
+ char *opt;
+ int len = strlen(opts) + 20;
+
+ *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);
+ parse_opt (opt, flags, *extra_opts, len);
+
+ free(opts);
}
+
#if 0
if (readonly)
*flags |= MS_RDONLY;
Modified: trunk/mount.ocfs2/opts.h
===================================================================
--- trunk/mount.ocfs2/opts.h 2005-03-15 23:38:14 UTC (rev 643)
+++ trunk/mount.ocfs2/opts.h 2005-03-16 04:29:10 UTC (rev 644)
@@ -20,4 +20,4 @@
*
*/
-void parse_opts (char *opts, int *flags, char **extra_opts);
+void parse_opts (char *options, int *flags, char **extra_opts);
Added: trunk/mount.ocfs2/paths.h
===================================================================
--- trunk/mount.ocfs2/paths.h 2005-03-15 23:38:14 UTC (rev 643)
+++ trunk/mount.ocfs2/paths.h 2005-03-16 04:29:10 UTC (rev 644)
@@ -0,0 +1,10 @@
+#include <mntent.h>
+#define _PATH_FSTAB "/etc/fstab"
+#ifdef _PATH_MOUNTED
+#define MOUNTED_LOCK _PATH_MOUNTED "~"
+#define MOUNTED_TEMP _PATH_MOUNTED ".tmp"
+#else
+#define MOUNTED_LOCK "/etc/mtab~"
+#define MOUNTED_TEMP "/etc/mtab.tmp"
+#endif
+#define LOCK_TIMEOUT 10
Modified: trunk/mount.ocfs2/realpath.c
===================================================================
--- trunk/mount.ocfs2/realpath.c 2005-03-15 23:38:14 UTC (rev 643)
+++ trunk/mount.ocfs2/realpath.c 2005-03-16 04:29:10 UTC (rev 644)
@@ -32,17 +32,13 @@
#define MAX_READLINKS 32
-/* this leaks some memory - unimportant for mount */
char *
myrealpath(const char *path, char *resolved_path, int maxreslth) {
int readlinks = 0;
char *npath;
char link_path[PATH_MAX+1];
int n;
-#ifdef resolve_symlinks
- char *buf;
- int m;
-#endif
+ char *buf = NULL;
npath = resolved_path;
@@ -83,7 +79,7 @@
while (*path != '\0' && *path != '/') {
if (npath-resolved_path > maxreslth-2) {
errno = ENAMETOOLONG;
- return NULL;
+ goto err;
}
*npath++ = *path++;
}
@@ -91,7 +87,7 @@
/* Protect against infinite loops. */
if (readlinks++ > MAX_READLINKS) {
errno = ELOOP;
- return NULL;
+ goto err;
}
/* See if last pathname component is a symlink. */
@@ -100,9 +96,11 @@
if (n < 0) {
/* EINVAL means the file exists but isn't a symlink. */
if (errno != EINVAL)
- return NULL;
+ goto err;
} else {
#ifdef resolve_symlinks /* Richard Gooch dislikes sl resolution */
+ int m;
+
/* Note: readlink doesn't add the null byte. */
link_path[n] = '\0';
if (*link_path == '/')
@@ -115,6 +113,8 @@
/* Insert symlink contents into path. */
m = strlen(path);
+ if (buf)
+ free(buf);
buf = xmalloc(m + n + 1);
memcpy(buf, link_path, n);
memcpy(buf + n, path, m + 1);
@@ -128,5 +128,13 @@
npath--;
/* Make sure it's null terminated. */
*npath = '\0';
+
+ if (buf)
+ free(buf);
return resolved_path;
+
+ err:
+ if (buf)
+ free(buf);
+ return NULL;
}
Modified: trunk/mount.ocfs2/sundries.c
===================================================================
--- trunk/mount.ocfs2/sundries.c 2005-03-15 23:38:14 UTC (rev 643)
+++ trunk/mount.ocfs2/sundries.c 2005-03-16 04:29:10 UTC (rev 644)
@@ -15,39 +15,10 @@
#include "fstab.h"
#include "sundries.h"
#include "realpath.h"
-//#include "nfsmount.h"
+/* #include "nfsmount.h" -- OCFS2 modification */
#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;
-}
-
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;
@@ -73,6 +44,7 @@
return res;
}
+/* frees its first arg - typical use: s = xstrconcat3(s,t,u); */
char *
xstrconcat3 (const char *s, const char *t, const char *u) {
char *res;
@@ -84,9 +56,11 @@
strcpy(res, s);
strcat(res, t);
strcat(res, u);
+ free((void *) s);
return res;
}
+/* frees its first arg - typical use: s = xstrconcat4(s,t,u,v); */
char *
xstrconcat4 (const char *s, const char *t, const char *u, const char *v) {
char *res;
@@ -100,6 +74,7 @@
strcat(res, t);
strcat(res, u);
strcat(res, v);
+ free((void *) s);
return res;
}
@@ -132,20 +107,6 @@
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
@@ -269,19 +230,19 @@
we return unmodified. */
char *
canonicalize (const char *path) {
- char *canonical;
+ char canonical[PATH_MAX+2];
- if (path == NULL)
- return NULL;
+ if (path == NULL)
+ return NULL;
- if (streq(path, "none") || streq(path, "proc") || streq(path, "devpts"))
- return xstrdup(path);
+#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);
- canonical = xmalloc (PATH_MAX+2);
-
- if (myrealpath (path, canonical, PATH_MAX+1))
- return canonical;
-
- free(canonical);
- return xstrdup(path);
+ return xstrdup(path);
}
Modified: trunk/mount.ocfs2/sundries.h
===================================================================
--- trunk/mount.ocfs2/sundries.h 2005-03-15 23:38:14 UTC (rev 643)
+++ trunk/mount.ocfs2/sundries.h 2005-03-16 04:29:10 UTC (rev 644)
@@ -37,9 +37,6 @@
#ifdef HAVE_NFS
int nfsmount (const char *spec, const char *node, int *flags,
char **orig_opts, char **opt_args, int *version, int running_bg);
-int nfs4mount (const char *spec, const char *node, int *flags,
- char **orig_opts, char **opt_args, int running_bg);
-int nfsumount(const char *spec, const char *opts);
#endif
/* exit status - bits below are ORed */
Added: trunk/mount.ocfs2/xmalloc.c
===================================================================
--- trunk/mount.ocfs2/xmalloc.c 2005-03-15 23:38:14 UTC (rev 643)
+++ trunk/mount.ocfs2/xmalloc.c 2005-03-16 04:29:10 UTC (rev 644)
@@ -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;
+}
Added: trunk/mount.ocfs2/xmalloc.h
===================================================================
--- trunk/mount.ocfs2/xmalloc.h 2005-03-15 23:38:14 UTC (rev 643)
+++ trunk/mount.ocfs2/xmalloc.h 2005-03-16 04:29:10 UTC (rev 644)
@@ -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);
More information about the Ocfs2-tools-commits
mailing list