xargs.isdirect = LIBXFS_DIRECT;
xargs.isreadonly = LIBXFS_ISREADONLY;
- if (source_is_file) {
- xargs.dname = source_name;
- xargs.disfile = 1;
- } else
- xargs.volname = source_name;
+ xargs.dname = source_name;
+ xargs.disfile = source_is_file;
if (!libxfs_init(&xargs)) {
do_log(_("%s: couldn't initialize XFS library\n"
struct xfs_fsop_geom geo;
libxfs_fs_geometry(mp, &geo, XFS_FS_GEOM_MAX_STRUCT_VER);
- xfs_report_geom(&geo, fsdevice, x.logname, x.rtname);
+ xfs_report_geom(&geo, x.dname, x.logname, x.rtname);
return 0;
}
static char **cmdline;
static int ncmdline;
-char *fsdevice;
int blkbb;
int exitcode;
int expert_mode;
if (optind + 1 != argc)
usage();
- fsdevice = argv[optind];
- if (!x.disfile)
- x.volname = fsdevice;
- else
- x.dname = fsdevice;
+ x.dname = argv[optind];
x.isdirect = LIBXFS_DIRECT;
x.bcache_flags = CACHE_MISCOMPARE_PURGE;
1 << (XFS_MAX_SECTORSIZE_LOG - BBSHIFT), 0, &bp, NULL);
if (error) {
fprintf(stderr, _("%s: %s is invalid (cannot read first 512 "
- "bytes)\n"), progname, fsdevice);
+ "bytes)\n"), progname, x.dname);
exit(1);
}
sbp = &xmount.m_sb;
if (sbp->sb_magicnum != XFS_SB_MAGIC) {
fprintf(stderr, _("%s: %s is not a valid XFS filesystem (unexpected SB magic number 0x%08x)\n"),
- progname, fsdevice, sbp->sb_magicnum);
+ progname, x.dname, sbp->sb_magicnum);
if (!force) {
fprintf(stderr, _("Use -F to force a read attempt.\n"));
exit(EXIT_FAILURE);
if (!mp) {
fprintf(stderr,
_("%s: device %s unusable (not an XFS filesystem?)\n"),
- progname, fsdevice);
+ progname, x.dname);
exit(1);
}
mp->m_log = &xlog;
* All Rights Reserved.
*/
-extern char *fsdevice;
extern int blkbb;
extern int exitcode;
extern int expert_mode;
blockint();
i = 0;
if (dbprefix)
- i += printf("%s: ", fsdevice);
+ i += printf("%s: ", x.dname);
i += vprintf(fmt, ap);
unblockint();
va_end(ap);
*/
typedef struct libxfs_xinit {
/* input parameters */
- char *volname; /* pathname of volume */
char *dname; /* pathname of data "subvolume" */
char *logname; /* pathname of log "subvolume" */
char *rtname; /* pathname of realtime "subvolume" */
libxfs_init(libxfs_init_t *a)
{
char *dname;
- int fd;
char *logname;
char *rtname;
- int rval = 0;
int flags;
dname = a->dname;
a->dsize = a->lbsize = a->rtbsize = 0;
a->dbsize = a->logBBsize = a->logBBstart = a->rtsize = 0;
- fd = -1;
flags = (a->isreadonly | a->isdirect);
rcu_init();
rcu_register_thread();
radix_tree_init();
- if (a->volname) {
- if (!check_open(a->volname, flags))
- goto done;
- fd = open(a->volname, O_RDONLY);
- dname = a->dname = a->volname;
- a->volname = NULL;
- }
if (dname) {
if (a->disfile) {
a->ddev= libxfs_device_open(dname, a->dcreat, flags,
use_xfs_buf_lock = a->usebuflock;
xfs_dir_startup();
init_caches();
- rval = 1;
-done:
- if (fd >= 0)
- close(fd);
- if (!rval) {
- libxfs_close_devices(a);
- rcu_unregister_thread();
- }
+ return 1;
- return rval;
+done:
+ libxfs_close_devices(a);
+ rcu_unregister_thread();
+ return 0;
}
int force_overwrite)
{
struct stat statbuf;
- char *dfile = xi->volname ? xi->volname : xi->dname;
/*
* If our target is a regular file, use platform_findsizes
* for direct IO; we'll set our sector size to that if possible.
*/
if (xi->disfile ||
- (!stat(dfile, &statbuf) && S_ISREG(statbuf.st_mode))) {
+ (!stat(xi->dname, &statbuf) && S_ISREG(statbuf.st_mode))) {
int fd;
int flags = O_RDONLY;
long long dummy;
if (xi->disfile)
flags |= O_CREAT;
- fd = open(dfile, flags, 0666);
+ fd = open(xi->dname, flags, 0666);
if (fd >= 0) {
- platform_findsizes(dfile, fd, &dummy, &ft->lsectorsize);
+ platform_findsizes(xi->dname, fd, &dummy,
+ &ft->lsectorsize);
close(fd);
ft->psectorsize = ft->lsectorsize;
} else
ft->psectorsize = ft->lsectorsize = BBSIZE;
} else {
- blkid_get_topology(dfile, &ft->dsunit, &ft->dswidth,
+ blkid_get_topology(xi->dname, &ft->dsunit, &ft->dswidth,
&ft->lsectorsize, &ft->psectorsize,
force_overwrite);
}
struct cli_params *cli,
struct mkfs_default_params *dft,
struct fs_topology *ft,
- char *dfile,
int dry_run,
int force_overwrite)
{
* Before anything else, verify that we are correctly operating on
* files or block devices and set the control parameters correctly.
*/
- check_device_type(dfile, &cli->xi->disfile, !cli->dsize, !dfile,
+ check_device_type(cli->xi->dname, &cli->xi->disfile,
+ !cli->dsize, !cli->xi->dname,
dry_run ? NULL : &cli->xi->dcreat, "d");
if (!cli->loginternal)
check_device_type(cli->xi->logname, &cli->xi->lisfile,
}
}
-/*
- * This is more complex than it needs to be because we still support volume
- * based external logs. They are only discovered *after* the devices have been
- * opened, hence the crazy "is this really an internal log" checks here.
- */
static void
validate_logdev(
struct mkfs_params *cfg,
- struct cli_params *cli,
- char **devname)
+ struct cli_params *cli)
{
struct libxfs_xinit *xi = cli->xi;
- *devname = NULL;
-
- /* check for volume log first */
- if (cli->loginternal && xi->volname && xi->logdev) {
- *devname = _("volume log");
- cfg->loginternal = false;
- } else
- cfg->loginternal = cli->loginternal;
+ cfg->loginternal = cli->loginternal;
/* now run device checks */
if (cfg->loginternal) {
- if (xi->logdev) {
- fprintf(stderr,
-_("can't have both external and internal logs\n"));
- usage();
- }
-
/*
* if no sector size has been specified on the command line,
* use what has been configured and validated for the data
(long long)cfg->logblocks);
usage();
}
- *devname = _("internal log");
return;
}
/* External/log subvolume checks */
- if (xi->logname)
- *devname = xi->logname;
- if (!*devname || !xi->logdev) {
+ if (!*xi->logname || !xi->logdev) {
fprintf(stderr, _("no log subvolume or external log.\n"));
usage();
}
static void
validate_rtdev(
struct mkfs_params *cfg,
- struct cli_params *cli,
- char **devname)
+ struct cli_params *cli)
{
struct libxfs_xinit *xi = cli->xi;
- *devname = NULL;
-
if (!xi->rtdev) {
if (cli->rtsize) {
fprintf(stderr,
usage();
}
- *devname = _("none");
cfg->rtblocks = 0;
cfg->rtextents = 0;
cfg->rtbmblocks = 0;
usage();
}
- /* volume rtdev */
- if (xi->volname)
- *devname = _("volume rt");
- else
- *devname = xi->rtname;
-
if (cli->rtsize) {
if (cfg->rtblocks > DTOBT(xi->rtsize, cfg->blocklog)) {
fprintf(stderr,
xfs_agnumber_t agno;
struct xfs_buf *buf;
int c;
- char *dfile = NULL;
- char *logfile = NULL;
- char *rtfile = NULL;
int dry_run = 0;
int discard = 1;
int force_overwrite = 0;
fprintf(stderr, _("extra arguments\n"));
usage();
} else if (argc - optind == 1) {
- dfile = xi.volname = getstr(argv[optind], &dopts, D_NAME);
- } else
- dfile = xi.dname;
+ xi.dname = getstr(argv[optind], &dopts, D_NAME);
+ }
/*
* Now we have all the options parsed, we can read in the option file
* before opening the libxfs devices.
*/
validate_blocksize(&cfg, &cli, &dft);
- validate_sectorsize(&cfg, &cli, &dft, &ft, dfile, dry_run,
- force_overwrite);
+ validate_sectorsize(&cfg, &cli, &dft, &ft, dry_run, force_overwrite);
/*
* XXX: we still need to set block size and sector size global variables
* Open and validate the device configurations
*/
open_devices(&cfg, &xi);
- validate_overwrite(dfile, force_overwrite);
+ validate_overwrite(xi.dname, force_overwrite);
validate_datadev(&cfg, &cli);
- validate_logdev(&cfg, &cli, &logfile);
- validate_rtdev(&cfg, &cli, &rtfile);
+ validate_logdev(&cfg, &cli);
+ validate_rtdev(&cfg, &cli);
calc_stripe_factors(&cfg, &cli, &ft);
/*
struct xfs_fsop_geom geo;
libxfs_fs_geometry(mp, &geo, XFS_FS_GEOM_MAX_STRUCT_VER);
- xfs_report_geom(&geo, dfile, logfile, rtfile);
+ xfs_report_geom(&geo, xi.dname, xi.logname, xi.rtname);
if (dry_run)
exit(0);
}
{
memset(args, 0, sizeof(libxfs_init_t));
- if (isa_file) {
- args->disfile = 1;
- args->dname = fs_name;
- args->volname = NULL;
- } else {
- args->disfile = 0;
- args->volname = fs_name;
- args->dname = NULL;
- }
+ args->dname = fs_name;
+ args->disfile = isa_file;
if (log_spec) { /* External log specified */
args->logname = log_name;