mirror of
https://github.com/nilfs-dev/nilfs-utils.git
synced 2026-01-26 13:43:15 +00:00
mount: replace EX_* macros with MNT_EX_*
Replace the EX_* exit code macros with their MNT_EX_* equivalents in mount_libmount.c and umount_libmount.c. This aligns the code with libmount conventions and serves as a preparatory step to remove the dependency on sundries.h. A new header libmount_compat.h is added as a transitional measure to define these macros, because they are missing in libmount.h on some older distributions. Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
This commit is contained in:
parent
0ad2cc77af
commit
e371c65c5d
@ -17,7 +17,7 @@ core_sbin_PROGRAMS = mount.nilfs2 umount.nilfs2
|
||||
if CONFIG_LIBMOUNT
|
||||
|
||||
COMMONSOURCES += mount_attrs.c
|
||||
COMMONHEADERS += mount_attrs.h
|
||||
COMMONHEADERS += libmount_compat.h mount_attrs.h
|
||||
|
||||
# Since mount_nilfs2_CFLAGS is defined in the else block, Automake
|
||||
# disables the default AM_CFLAGS. Explicitly include it here.
|
||||
|
||||
45
sbin/mount/libmount_compat.h
Normal file
45
sbin/mount/libmount_compat.h
Normal file
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* sbin/mount/libmount_compat.h - libmount compatibility definitions
|
||||
*/
|
||||
|
||||
#ifndef _LIBMOUNT_COMPAT_H
|
||||
#define _LIBMOUNT_COMPAT_H
|
||||
|
||||
#include <libmount.h>
|
||||
|
||||
/*
|
||||
* If MNT_EX_* macros are not defined in libmount.h, define them here.
|
||||
*/
|
||||
#ifndef MNT_EX_SUCCESS
|
||||
#define MNT_EX_SUCCESS 0
|
||||
#endif
|
||||
|
||||
#ifndef MNT_EX_USAGE
|
||||
#define MNT_EX_USAGE 1
|
||||
#endif
|
||||
|
||||
#ifndef MNT_EX_SYSERR
|
||||
#define MNT_EX_SYSERR 2
|
||||
#endif
|
||||
|
||||
#ifndef MNT_EX_SOFTWARE
|
||||
#define MNT_EX_SOFTWARE 4
|
||||
#endif
|
||||
|
||||
#ifndef MNT_EX_USER
|
||||
#define MNT_EX_USER 8
|
||||
#endif
|
||||
|
||||
#ifndef MNT_EX_FILEIO
|
||||
#define MNT_EX_FILEIO 16
|
||||
#endif
|
||||
|
||||
#ifndef MNT_EX_FAIL
|
||||
#define MNT_EX_FAIL 32
|
||||
#endif
|
||||
|
||||
#ifndef MNT_EX_SOMEOK
|
||||
#define MNT_EX_SOMEOK 64
|
||||
#endif
|
||||
|
||||
#endif /* _LIBMOUNT_COMPAT_H */
|
||||
@ -73,6 +73,7 @@
|
||||
#include <errno.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "libmount_compat.h"
|
||||
#include "sundries.h"
|
||||
#include "xmalloc.h"
|
||||
#include "mount.nilfs2.h"
|
||||
@ -167,7 +168,7 @@ static void nilfs_mount_parse_options(int argc, char *argv[],
|
||||
|
||||
fs = mnt_context_get_fs(cxt);
|
||||
if (!fs)
|
||||
die(EX_SYSERR, _("failed to get fs"));
|
||||
die(MNT_EX_SYSERR, _("failed to get fs"));
|
||||
|
||||
while ((c = getopt(argc, argv, "fvnt:o:rwV")) != EOF) {
|
||||
switch (c) {
|
||||
@ -190,19 +191,23 @@ static void nilfs_mount_parse_options(int argc, char *argv[],
|
||||
|
||||
if (nilfs_mount_attrs_parse(&mi->new_attrs, optarg,
|
||||
NULL, &rest, 0))
|
||||
die(EX_SYSERR, _("failed to parse options"));
|
||||
die(MNT_EX_SYSERR,
|
||||
_("failed to parse options"));
|
||||
if (rest && mnt_context_append_options(cxt, rest))
|
||||
die(EX_SYSERR, _("failed to append options"));
|
||||
die(MNT_EX_SYSERR,
|
||||
_("failed to append options"));
|
||||
free(rest);
|
||||
break;
|
||||
}
|
||||
case 'r':
|
||||
if (mnt_context_append_options(cxt, "ro"))
|
||||
die(EX_SYSERR, _("failed to append options"));
|
||||
die(MNT_EX_SYSERR,
|
||||
_("failed to append options"));
|
||||
break;
|
||||
case 'w':
|
||||
if (mnt_context_append_options(cxt, "rw"))
|
||||
die(EX_SYSERR, _("failed to append options"));
|
||||
die(MNT_EX_SYSERR,
|
||||
_("failed to append options"));
|
||||
break;
|
||||
case 'V':
|
||||
show_version_only = 1;
|
||||
@ -214,7 +219,7 @@ static void nilfs_mount_parse_options(int argc, char *argv[],
|
||||
|
||||
if (show_version_only) {
|
||||
show_version();
|
||||
exit(EXIT_SUCCESS);
|
||||
exit(MNT_EX_SUCCESS);
|
||||
}
|
||||
}
|
||||
|
||||
@ -248,7 +253,7 @@ static struct libmnt_fs *nilfs_find_mount(struct libmnt_context *cxt,
|
||||
struct libmnt_fs *fs = NULL;
|
||||
|
||||
if (!iter)
|
||||
die(EX_SYSERR, _("libmount iterator allocation failed"));
|
||||
die(MNT_EX_SYSERR, _("libmount iterator allocation failed"));
|
||||
|
||||
while (mnt_table_next_fs(mtab, iter, &fs) == 0) {
|
||||
if (mnt_fs_match_fstype(fs, type) &&
|
||||
@ -516,7 +521,7 @@ static int nilfs_update_mount_state(struct nilfs_mount_info *mi)
|
||||
|
||||
static int nilfs_mount_one(struct nilfs_mount_info *mi)
|
||||
{
|
||||
int res, err = EX_FAIL;
|
||||
int res, err = MNT_EX_FAIL;
|
||||
|
||||
res = nilfs_prepare_mount(mi);
|
||||
if (res)
|
||||
@ -553,13 +558,13 @@ int main(int argc, char *argv[])
|
||||
mnt_init_debug(0);
|
||||
mi.cxt = mnt_new_context();
|
||||
if (!mi.cxt)
|
||||
die(EX_SYSERR, _("libmount context allocation failed"));
|
||||
die(MNT_EX_SYSERR, _("libmount context allocation failed"));
|
||||
|
||||
#if 0
|
||||
mnt_context_set_tables_errcb(mi.cxt, nilfs_libmount_table_errcb);
|
||||
#endif
|
||||
if (mnt_context_set_fstype(mi.cxt, fstype))
|
||||
die(EX_SYSERR,
|
||||
die(MNT_EX_SYSERR,
|
||||
_("libmount FS description allocation failed"));
|
||||
mnt_context_disable_helpers(mi.cxt, 1);
|
||||
|
||||
@ -570,24 +575,24 @@ int main(int argc, char *argv[])
|
||||
umask(022);
|
||||
|
||||
if (optind >= argc || !argv[optind])
|
||||
die(EX_USAGE, _("No device specified"));
|
||||
die(MNT_EX_USAGE, _("No device specified"));
|
||||
|
||||
device = argv[optind++];
|
||||
|
||||
if (optind >= argc || !argv[optind])
|
||||
die(EX_USAGE, _("No mountpoint specified"));
|
||||
die(MNT_EX_USAGE, _("No mountpoint specified"));
|
||||
|
||||
mntdir = argv[optind++];
|
||||
|
||||
if (mnt_context_set_source(mi.cxt, device) ||
|
||||
mnt_context_set_target(mi.cxt, mntdir))
|
||||
die(EX_SYSERR, _("Mount entry allocation failed"));
|
||||
die(MNT_EX_SYSERR, _("Mount entry allocation failed"));
|
||||
|
||||
if (mount_fstype && strncmp(mount_fstype, fstype, strlen(fstype)))
|
||||
die(EX_USAGE, _("Unknown filesystem (%s)"), mount_fstype);
|
||||
die(MNT_EX_USAGE, _("Unknown filesystem (%s)"), mount_fstype);
|
||||
|
||||
if (getuid() != geteuid())
|
||||
die(EX_USAGE,
|
||||
die(MNT_EX_USAGE,
|
||||
_("%s: mount by non-root user is not supported yet"),
|
||||
progname);
|
||||
|
||||
|
||||
@ -65,6 +65,7 @@
|
||||
#include <errno.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "libmount_compat.h"
|
||||
#include "sundries.h"
|
||||
#include "xmalloc.h"
|
||||
#include "mount.nilfs2.h"
|
||||
@ -134,7 +135,7 @@ static void nilfs_umount_parse_options(int argc, char *argv[],
|
||||
|
||||
fs = mnt_context_get_fs(cxt);
|
||||
if (!fs)
|
||||
die(EX_SYSERR, _("failed to get fs"));
|
||||
die(MNT_EX_SYSERR, _("failed to get fs"));
|
||||
|
||||
while ((c = getopt(argc, argv, "flnvrV")) != EOF) {
|
||||
switch (c) {
|
||||
@ -164,7 +165,7 @@ static void nilfs_umount_parse_options(int argc, char *argv[],
|
||||
|
||||
if (show_version_only) {
|
||||
show_version();
|
||||
exit(EXIT_SUCCESS);
|
||||
exit(MNT_EX_SUCCESS);
|
||||
}
|
||||
}
|
||||
|
||||
@ -221,7 +222,7 @@ static int nilfs_prepare_umount(struct nilfs_umount_info *umi)
|
||||
if (attrs) {
|
||||
if (nilfs_mount_attrs_parse(&umi->old_attrs, attrs,
|
||||
NULL, NULL, 1))
|
||||
die(EX_SYSERR, _("failed to parse attributes"));
|
||||
die(MNT_EX_SYSERR, _("failed to parse attributes"));
|
||||
}
|
||||
res = 0;
|
||||
failed:
|
||||
@ -316,7 +317,7 @@ int main(int argc, char *argv[])
|
||||
mnt_init_debug(0);
|
||||
umi.cxt = mnt_new_context();
|
||||
if (!umi.cxt)
|
||||
die(EX_SYSERR, _("libmount context allocation failed"));
|
||||
die(MNT_EX_SYSERR, _("libmount context allocation failed"));
|
||||
|
||||
nilfs_umount_parse_options(argc, argv, &umi);
|
||||
|
||||
@ -324,7 +325,7 @@ int main(int argc, char *argv[])
|
||||
mnt_context_set_tables_errcb(umi.cxt, nilfs_libmount_table_errcb);
|
||||
#endif
|
||||
if (mnt_context_set_fstype(umi.cxt, fstype))
|
||||
die(EX_SYSERR,
|
||||
die(MNT_EX_SYSERR,
|
||||
_("libmount FS description allocation failed"));
|
||||
mnt_context_disable_helpers(umi.cxt, 1);
|
||||
|
||||
@ -338,9 +339,9 @@ int main(int argc, char *argv[])
|
||||
#if 0 /* XXX: normal user mount support */
|
||||
if (mnt_context_is_nomtab(mi.cxt) ||
|
||||
mnt_context_is_rdonly_umount(mi.cxt))
|
||||
die(EX_USAGE, _("only root can do that"));
|
||||
die(MNT_EX_USAGE, _("only root can do that"));
|
||||
#else
|
||||
die(EX_USAGE,
|
||||
die(MNT_EX_USAGE,
|
||||
_("%s: umount by non-root user is not supported yet"),
|
||||
progname);
|
||||
#endif
|
||||
@ -350,7 +351,7 @@ int main(int argc, char *argv[])
|
||||
argv += optind;
|
||||
|
||||
if (argc < 1)
|
||||
die(EX_USAGE, _("No mountpoint specified"));
|
||||
die(MNT_EX_USAGE, _("No mountpoint specified"));
|
||||
|
||||
for( ; argc; argc--, argv++) {
|
||||
if (**argv == '\0') {
|
||||
@ -363,7 +364,8 @@ int main(int argc, char *argv[])
|
||||
|
||||
if (mnt_context_set_source(umi.cxt, NULL) ||
|
||||
mnt_context_set_target(umi.cxt, *argv))
|
||||
die(EX_SYSERR, _("Mount entry allocation failed"));
|
||||
die(MNT_EX_SYSERR,
|
||||
_("Mount entry allocation failed"));
|
||||
|
||||
if (nilfs_umount_one(&umi) == 0)
|
||||
no_succ = 0;
|
||||
@ -374,11 +376,11 @@ int main(int argc, char *argv[])
|
||||
mnt_free_context(umi.cxt);
|
||||
|
||||
if (no_fail)
|
||||
status = EXIT_SUCCESS; /* all succeeded */
|
||||
status = MNT_EX_SUCCESS; /* all succeeded */
|
||||
else if (no_succ)
|
||||
status = EX_FAIL; /* all failed */
|
||||
status = MNT_EX_FAIL; /* all failed */
|
||||
else
|
||||
status = EX_SOMEOK; /* some succeeded, some failed */
|
||||
status = MNT_EX_SOMEOK; /* some succeeded, some failed */
|
||||
|
||||
exit(status);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user