Module Name: othersrc
Committed By: stacktic
Date: Wed Dec 9 16:33:02 UTC 2009
Modified Files:
othersrc/lib/libfsu_mount: fsu_mount.c fsu_mount.h
Log Message:
Removed useless strdup and global vars
To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 othersrc/lib/libfsu_mount/fsu_mount.c
cvs rdiff -u -r1.3 -r1.4 othersrc/lib/libfsu_mount/fsu_mount.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: othersrc/lib/libfsu_mount/fsu_mount.c
diff -u othersrc/lib/libfsu_mount/fsu_mount.c:1.13 othersrc/lib/libfsu_mount/fsu_mount.c:1.14
--- othersrc/lib/libfsu_mount/fsu_mount.c:1.13 Thu Dec 3 15:00:38 2009
+++ othersrc/lib/libfsu_mount/fsu_mount.c Wed Dec 9 16:33:02 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: fsu_mount.c,v 1.13 2009/12/03 15:00:38 pooka Exp $ */
+/* $NetBSD: fsu_mount.c,v 1.14 2009/12/09 16:33:02 stacktic Exp $ */
/*
* Copyright (c) 2008,2009 Arnaud Ysmal. All Rights Reserved.
@@ -67,14 +67,14 @@
#define __UNCONST(a) ((char *)(unsigned long)(const char *)(a))
#endif
-#define ADD_ARG(a) \
+#define ADD_ARG(m, a) \
do { \
char *_tmp = (a); \
if ((_tmp) == NULL) { \
warn(NULL); \
return NULL; \
} \
- mntd.mntd_argv[mntd.mntd_argc++] = (_tmp); \
+ (m)->mntd_argv[(m)->mntd_argc++] = (_tmp); \
} while (0/*CONSTCOND*/)
struct mount_data_s {
fsu_fs_t *mntd_fs;
@@ -86,13 +86,12 @@
int mntd_argv_size;
char *mntd_cwd;
};
-static struct mount_data_s mntd;
-static struct ukfs *mount_alias(struct fsu_fsalias_s *, char *, char *);
-static struct ukfs *mount_fstype(fsu_fs_t *, char *, char *, char *, char *);
-static struct ukfs *mount_struct(_Bool);
-static char *fsdevice, *fstype;
-static _Bool fsu_blockfs = false;
+static struct ukfs *mount_alias(struct fsu_fsalias_s *, char *, char *,
+ struct mount_data_s *);
+static struct ukfs *mount_fstype(fsu_fs_t *, const char *, char *, char *,
+ char *, struct mount_data_s *);
+static struct ukfs *mount_struct(_Bool, struct mount_data_s *);
_Bool fsu_readonly = false;
@@ -100,15 +99,17 @@
* Tries to mount an image.
* if the fstype is not given try every supported types.
*/
-struct ukfs
-*fsu_mount(int *argc, char **argv[])
+struct ukfs *
+fsu_mount(int *argc, char **argv[])
{
struct ukfs *ukfs;
fsu_fs_t *fst;
struct fsu_fsalias_s *alias;
+ struct mount_data_s mntd;
int idx;
char ch, *mntopts, afsdev[MAXPATHLEN], *path, *puffsexec, *specopts;
char *tmp;
+ const char *fsdevice, *fstype;
struct stat sb;
#ifdef WITH_SYSPUFFS
const char options[] = "f:o:p:s:t:";
@@ -117,37 +118,26 @@
#endif
alias = NULL;
- puffsexec = specopts = mntopts = fstype = fsdevice = NULL;
+ puffsexec = specopts = mntopts = NULL;
fst = NULL;
ukfs = NULL;
+ memset(&mntd, 0, sizeof(mntd));
ukfs_init();
ukfs_modload_dir(RUMP_LIBDIR);
/*
- * [-o mnt_args] [[-t] fstype] [ -p puffsexec] fsdevice
+ * [-o mnt_args] [-t fstype] [-p puffsexec] fsdevice
*/
while ((ch = getopt(*argc, *argv, options)) != -1) {
switch (ch) {
case 'f':
- if (fsdevice == NULL) {
- if (stat(optarg, &sb) == 0 &&
- realpath(optarg, afsdev) != NULL) {
- fsdevice = strdup(afsdev);
- fsu_blockfs = true;
- } else
- fsdevice = strdup(optarg);
- if (fsdevice == NULL) {
- warn(NULL);
- return NULL;
- }
- }
+ if (fsdevice == NULL)
+ fsdevice = optarg;
break;
case 'o':
- if (mntopts == NULL) {
+ if (mntopts == NULL)
mntopts = optarg;
- setenv("FSU_MNTOPTS", optarg, 1);
- }
break;
#ifdef WITH_SYSPUFFS
case 'p':
@@ -158,15 +148,11 @@
break;
if (fstype == NULL)
- fstype = strdup(MOUNT_PUFFS);
+ fstype = MOUNT_PUFFS;
else if (strcmp(fstype, MOUNT_PUFFS) != 0) {
warnx("-p is only for puffs");
return NULL;
}
- if (fstype == NULL) {
- warn(NULL);
- return NULL;
- }
}
break;
#endif
@@ -176,11 +162,7 @@
break;
case 't':
if (fstype == NULL)
- fstype = strdup(optarg);
- if (fstype == NULL) {
- warn(NULL);
- return NULL;
- }
+ fstype = optarg;
break;
case '?':
default:
@@ -229,49 +211,36 @@
if (fsdevice == NULL) {
fsdevice = getenv("FSU_DEVICE");
if (fsdevice == NULL) {
- if (idx < *argc && strcmp((*argv)[idx], "--") != 0) {
- if (stat((*argv)[idx], &sb) == 0 &&
- realpath((*argv)[idx], afsdev) != NULL) {
- fsdevice = strdup(afsdev);
- fsu_blockfs = true;
- ++idx;
- } else
- fsdevice = strdup((*argv)[idx++]);
- if (fsdevice == NULL) {
- warn(NULL);
- return NULL;
- }
- } else {
+ if (idx < *argc && strcmp((*argv)[idx], "--") != 0)
+ fsdevice = (*argv)[idx++];
+ else {
errno = 0;
return NULL;
}
- } else {
- tmp = fsdevice;
- fsdevice = strdup(tmp);
- if (fsdevice == NULL) {
- warn(NULL);
- return NULL;
- }
}
build_alias_list();
alias = get_alias(fsdevice);
if (alias != NULL)
- ukfs = mount_alias(alias, mntopts, specopts);
+ ukfs = mount_alias(alias, mntopts, specopts, &mntd);
free_alias_list();
}
- if (ukfs == NULL)
+
+ if (ukfs == NULL) {
+ if (stat(fsdevice, &sb) == 0 &&
+ realpath(fsdevice, afsdev) != NULL)
+ fsdevice = afsdev;
ukfs = mount_fstype(fst, fsdevice, mntopts, puffsexec,
- specopts);
+ specopts, &mntd);
+ }
- free(mntd.mntd_argv[0]); /* strdup(getprogname()) */
- free(mntd.mntd_argv[--mntd.mntd_argc]); /* strdup("/") */
free(mntd.mntd_argv);
mntd.mntd_argv_size = 0;
if (ukfs == NULL)
return NULL;
+ /* Remove the arguments used by fsu_mount and reset getopt*/
if ((*argv)[idx] != NULL && strcmp((*argv)[idx], "--") == 0)
++idx;
@@ -301,124 +270,126 @@
return ukfs;
}
-static struct ukfs
-*mount_fstype(fsu_fs_t *fs, char *fsdev, char *mntopts, char *puffsexec,
- char *specopts)
+static struct ukfs *
+mount_fstype(fsu_fs_t *fs, const char *fsdev, char *mntopts, char *puffsexec,
+ char *specopts, struct mount_data_s *mntdp)
{
struct ukfs *ukfs;
int argvlen;
- mntd.mntd_fs = fs;
- mntd.mntd_argc = mntd.mntd_flags = 0;
+ mntdp->mntd_fs = fs;
+ mntdp->mntd_argc = mntdp->mntd_flags = 0;
ukfs = NULL;
argvlen = 7;
if (specopts != NULL)
argvlen += fsu_str2argc(specopts);
- if (argvlen > mntd.mntd_argv_size) {
+ if (argvlen > mntdp->mntd_argv_size) {
char **tmp;
- tmp = realloc(mntd.mntd_argv, argvlen * sizeof(char *));
+ tmp = realloc(mntdp->mntd_argv, argvlen * sizeof(char *));
if (tmp == NULL) {
- free(mntd.mntd_argv);
+ if (mntdp->mntd_argv != NULL)
+ free(mntdp->mntd_argv);
return NULL;
}
- mntd.mntd_argv = tmp;
- mntd.mntd_argv_size = argvlen;
+ mntdp->mntd_argv = tmp;
+ mntdp->mntd_argv_size = argvlen;
}
/* setting up the argv array */
- ADD_ARG(strdup(getprogname()));
+ ADD_ARG(mntdp, __UNCONST(getprogname()));
#ifdef WITH_SYSPUFFS
if (puffsexec != NULL && fs->fs_name == MOUNT_PUFFS)
- ADD_ARG(puffsexec);
+ ADD_ARG(mntdp, puffsexec);
#endif
if (mntopts != NULL) {
- ADD_ARG(strdup("-o"));
- ADD_ARG(mntopts);
+ ADD_ARG(mntdp, __UNCONST("-o"));
+ ADD_ARG(mntdp, mntopts);
}
if (specopts != NULL) {
int tmpargc;
fsu_str2arg(specopts, &tmpargc,
- mntd.mntd_argv + mntd.mntd_argc, argvlen - 6);
- mntd.mntd_argc += tmpargc;
+ mntdp->mntd_argv + mntdp->mntd_argc, argvlen - 6);
+ mntdp->mntd_argc += tmpargc;
}
- ADD_ARG(fsdev);
- ADD_ARG(strdup("/"));
- mntd.mntd_argv[mntd.mntd_argc] = NULL;
+ ADD_ARG(mntdp, __UNCONST(fsdev));
+ ADD_ARG(mntdp, __UNCONST("/"));
+ mntdp->mntd_argv[mntdp->mntd_argc] = NULL;
/* filesystem given */
if (fs != NULL)
- return mount_struct(1);
+ return mount_struct(1, mntdp);
/* filesystem not given (auto detection) */
for (fs = fslist; fs->fs_name != NULL; ++fs) {
if (fs->fs_flags & FS_NO_AUTO)
continue;
- mntd.mntd_flags = 0;
- mntd.mntd_fs = fs;
- ukfs = mount_struct(0);
+ mntdp->mntd_flags = 0;
+ mntdp->mntd_fs = fs;
+ ukfs = mount_struct(0, mntdp);
if (ukfs != NULL)
return ukfs;
}
return NULL;
}
-static struct ukfs
-*mount_alias(struct fsu_fsalias_s *al, char *mntopts, char *specopts)
+static struct ukfs *
+mount_alias(struct fsu_fsalias_s *al, char *mntopts, char *specopts,
+ struct mount_data_s *mntdp)
{
fsu_fs_t *cur;
int argvlen;
- mntd.mntd_argc = mntd.mntd_flags = 0;
+ mntdp->mntd_argc = mntdp->mntd_flags = 0;
argvlen = 9;
if (specopts != NULL)
argvlen += fsu_str2argc(specopts);
- if (argvlen > mntd.mntd_argv_size) {
+ if (argvlen > mntdp->mntd_argv_size) {
char **tmp;
- tmp = realloc(mntd.mntd_argv, argvlen * sizeof(char *));
+ tmp = realloc(mntdp->mntd_argv, argvlen * sizeof(char *));
if (tmp == NULL) {
- free(mntd.mntd_argv);
+ free(mntdp->mntd_argv);
return NULL;
}
- mntd.mntd_argv = tmp;
- mntd.mntd_argv_size = argvlen;
+ mntdp->mntd_argv = tmp;
+ mntdp->mntd_argv_size = argvlen;
}
- ADD_ARG(strdup(getprogname()));
+ ADD_ARG(mntdp, __UNCONST(getprogname()));
#ifdef WITH_SYSPUFFS
if (al->fsa_puffsexec != NULL)
- ADD_ARG(al->fsa_puffsexec);
+ ADD_ARG(mntdp, al->fsa_puffsexec);
#endif
if (al->fsa_mntopt != NULL) {
- ADD_ARG(strdup("-o"));
- ADD_ARG(al->fsa_mntopt);
+ ADD_ARG(mntdp, __UNCONST("-o"));
+ ADD_ARG(mntdp, al->fsa_mntopt);
setenv("FSU_MNTOPTS", al->fsa_mntopt, 1);
}
if (mntopts != NULL) {
- ADD_ARG(strdup("-o"));
- ADD_ARG(mntopts);
+ ADD_ARG(mntdp, __UNCONST("-o"));
+ ADD_ARG(mntdp, mntopts);
setenv("FSU_MNTOPTS", mntopts, 1);
}
if (specopts != NULL) {
int tmpargc;
fsu_str2arg(specopts, &tmpargc,
- mntd.mntd_argv + mntd.mntd_argc, argvlen - 8);
- mntd.mntd_argc += tmpargc;
+ mntdp->mntd_argv + mntdp->mntd_argc, argvlen - 8);
+ mntdp->mntd_argc += tmpargc;
}
- ADD_ARG(al->fsa_path);
- ADD_ARG(strdup("/"));
- mntd.mntd_argv[mntd.mntd_argc] = NULL;
+ ADD_ARG(mntdp, al->fsa_path);
+ ADD_ARG(mntdp, __UNCONST("/"));
+ mntdp->mntd_argv[mntdp->mntd_argc] = NULL;
for (cur = fslist; cur->fs_name != NULL; ++cur)
if (strcmp(cur->fs_name, al->fsa_type) == 0)
@@ -427,35 +398,35 @@
if (cur->fs_name == NULL)
return NULL;
- mntd.mntd_fs = cur;
+ mntdp->mntd_fs = cur;
- return mount_struct(1);
+ return mount_struct(1, mntdp);
}
-static struct ukfs
-*mount_struct(_Bool verbose)
+static struct ukfs *
+mount_struct(_Bool verbose, struct mount_data_s *mntdp)
{
struct ukfs *ukfs;
fsu_fs_t *fs;
int rv;
ukfs = NULL;
- fs = mntd.mntd_fs;
+ fs = mntdp->mntd_fs;
- rv = fs->fs_parseargs(mntd.mntd_argc, mntd.mntd_argv, fs->fs_args,
- &mntd.mntd_flags, mntd.mntd_canon_dev, mntd.mntd_canon_dir);
+ rv = fs->fs_parseargs(mntdp->mntd_argc, mntdp->mntd_argv, fs->fs_args,
+ &(mntdp->mntd_flags), mntdp->mntd_canon_dev, mntdp->mntd_canon_dir);
if (rv == 0) {
#ifdef HAVE_UKFS_DISKLABEL
- if (fsu_blockfs) {
+ if (fs->fs_flags == 0) {
ukfs = ukfs_mount_disk(fs->fs_name,
- mntd.mntd_canon_dev, ukfs_part_none,
- mntd.mntd_canon_dir, mntd.mntd_flags,
+ mntdp->mntd_canon_dev, ukfs_part_none,
+ mntdp->mntd_canon_dir, mntdp->mntd_flags,
fs->fs_args, fs->fs_args_size);
} else
#endif
ukfs = ukfs_mount(fs->fs_name,
- mntd.mntd_canon_dev, mntd.mntd_canon_dir,
- mntd.mntd_flags, fs->fs_args, fs->fs_args_size);
+ mntdp->mntd_canon_dev, mntdp->mntd_canon_dir,
+ mntdp->mntd_flags, fs->fs_args, fs->fs_args_size);
}
#ifdef WITH_SMBFS
if (strcmp(fs->fs_name, MOUNT_SMBFS) == 0) {
@@ -464,16 +435,9 @@
smb_ctx_done(&sctx);
}
#endif
- if (ukfs == NULL) {
- if (verbose)
- fprintf(stderr, "%s is not a valid %s image\n",
- mntd.mntd_canon_dev, fs->fs_name);
- } else {
- if (fstype == NULL)
- fstype = strdup(fs->fs_name);
- if (fsdevice == NULL)
- fsdevice = strdup(mntd.mntd_canon_dev);
- }
+ if (ukfs == NULL && verbose)
+ fprintf(stderr, "%s is not a valid %s image\n",
+ mntdp->mntd_canon_dev, fs->fs_name);
return ukfs;
}
@@ -483,30 +447,11 @@
if (ukfs == NULL)
return;
- if (fstype != NULL)
- free(fstype);
- if (fsdevice != NULL)
- free(fsdevice);
- fsdevice = fstype = NULL;
ukfs_release(ukfs, 0);
}
-const char
-*fsu_get_device(void)
-{
-
- return fsdevice;
-}
-
-const char
-*fsu_get_fstype(void)
-{
-
- return fstype;
-}
-
-const char
-*fsu_mount_usage(void)
+const char *
+fsu_mount_usage(void)
{
#ifdef WITH_SYSPUFFS
Index: othersrc/lib/libfsu_mount/fsu_mount.h
diff -u othersrc/lib/libfsu_mount/fsu_mount.h:1.3 othersrc/lib/libfsu_mount/fsu_mount.h:1.4
--- othersrc/lib/libfsu_mount/fsu_mount.h:1.3 Thu Nov 5 14:02:42 2009
+++ othersrc/lib/libfsu_mount/fsu_mount.h Wed Dec 9 16:33:02 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: fsu_mount.h,v 1.3 2009/11/05 14:02:42 stacktic Exp $ */
+/* $NetBSD: fsu_mount.h,v 1.4 2009/12/09 16:33:02 stacktic Exp $ */
/*
* Copyright (c) 2008,2009 Arnaud Ysmal. All Rights Reserved.
@@ -32,8 +32,6 @@
struct ukfs;
-const char *fsu_get_device(void);
-const char *fsu_get_fstype(void);
struct ukfs *fsu_mount(int *, char **[]);
const char *fsu_mount_usage(void);
void fsu_unmount(struct ukfs *);