[
.B \-abCemnTvx
]
-.RI "[" mount-point " | " block-device "]"
+.I mount-point
.br
.B xfs_scrub \-V
.SH DESCRIPTION
return x;
}
-/*
- * Check if the argument is either the device name or mountpoint of a mounted
- * filesystem.
- */
-#define MNTTYPE_XFS "xfs"
-static bool
-find_mountpoint_check(
- struct stat *sb,
- struct mntent *t)
-{
- struct stat ms;
-
- if (S_ISDIR(sb->st_mode)) { /* mount point */
- if (stat(t->mnt_dir, &ms) < 0)
- return false;
- if (sb->st_ino != ms.st_ino)
- return false;
- if (sb->st_dev != ms.st_dev)
- return false;
- if (strcmp(t->mnt_type, MNTTYPE_XFS) != 0)
- return NULL;
- } else { /* device */
- if (stat(t->mnt_fsname, &ms) < 0)
- return false;
- if (sb->st_rdev != ms.st_rdev)
- return false;
- if (strcmp(t->mnt_type, MNTTYPE_XFS) != 0)
- return NULL;
- /*
- * Make sure the mountpoint given by mtab is accessible
- * before using it.
- */
- if (stat(t->mnt_dir, &ms) < 0)
- return false;
- }
-
- return true;
-}
-
-/* Check that our alleged mountpoint is in mtab */
-bool
-find_mountpoint(
- char *mtab,
- struct scrub_ctx *ctx)
-{
- struct mntent_cursor cursor;
- struct mntent *t = NULL;
- bool found = false;
-
- if (platform_mntent_open(&cursor, mtab) != 0) {
- fprintf(stderr, "Error: can't get mntent entries.\n");
- exit(1);
- }
-
- while ((t = platform_mntent_next(&cursor)) != NULL) {
- /*
- * Keep jotting down matching mount details; newer mounts are
- * towards the end of the file (hopefully).
- */
- if (find_mountpoint_check(&ctx->mnt_sb, t)) {
- ctx->mntpoint = strdup(t->mnt_dir);
- ctx->blkdev = strdup(t->mnt_fsname);
- found = true;
- }
- }
- platform_mntent_close(&cursor);
- return found;
-}
-
/*
* Sleep for 100ms * however many -b we got past the initial one.
* This is an (albeit clumsy) way to throttle scrub activity.
}
#endif
-bool find_mountpoint(char *mtab, struct scrub_ctx *ctx);
void background_sleep(void);
char *string_escape(const char *in);
xfs_setup_fs(
struct scrub_ctx *ctx)
{
- struct fs_path *fsp;
int error;
/*
return false;
}
- /* Go find the XFS devices if we have a usable fsmap. */
- fs_table_initialise(0, NULL, 0, NULL);
- errno = 0;
- fsp = fs_table_lookup(ctx->mntpoint, FS_MOUNT_POINT);
- if (!fsp) {
- str_info(ctx, ctx->mntpoint,
-_("Unable to find XFS information."));
- return false;
- }
- memcpy(&ctx->fsinfo, fsp, sizeof(struct fs_path));
-
/* Did we find the log and rt devices, if they're present? */
if (ctx->geo.logstart == 0 && ctx->fsinfo.fs_log == NULL) {
str_info(ctx, ctx->mntpoint,
static void __attribute__((noreturn))
usage(void)
{
- fprintf(stderr, _("Usage: %s [OPTIONS] mountpoint | device\n"), progname);
+ fprintf(stderr, _("Usage: %s [OPTIONS] mountpoint\n"), progname);
fprintf(stderr, "\n");
fprintf(stderr, _("Options:\n"));
fprintf(stderr, _(" -a count Stop after this many errors are found.\n"));
struct phase_rusage all_pi;
char *mtab = NULL;
FILE *progress_fp = NULL;
+ struct fs_path *fsp;
bool moveon = true;
- bool ismnt;
int c;
int fd;
int ret = SCRUB_RET_SUCCESS;
if (optind != argc - 1)
usage();
- ctx.mntpoint = strdup(argv[optind]);
+ ctx.mntpoint = argv[optind];
stdout_isatty = isatty(STDOUT_FILENO);
stderr_isatty = isatty(STDERR_FILENO);
mtab = _PATH_MOUNTED;
}
- ismnt = find_mountpoint(mtab, &ctx);
- if (!ismnt) {
- fprintf(stderr,
-_("%s: Not a XFS mount point or block device.\n"),
- ctx.mntpoint);
+ fs_table_initialise(0, NULL, 0, NULL);
+ fsp = fs_table_lookup_mount(ctx.mntpoint);
+ if (!fsp) {
+ fprintf(stderr, _("%s: Not a XFS mount point.\n"),
+ ctx.mntpoint);
ret |= SCRUB_RET_SYNTAX;
goto out;
}
+ memcpy(&ctx.fsinfo, fsp, sizeof(struct fs_path));
/* How many CPUs? */
nproc = sysconf(_SC_NPROCESSORS_ONLN);
phase_end(&all_pi, 0);
if (progress_fp)
fclose(progress_fp);
- free(ctx.blkdev);
- free(ctx.mntpoint);
/*
* If we're being run as a service, the return code must fit the LSB
/* Strings we need for presentation */
char *mntpoint;
- char *blkdev;
/* Mountpoint info */
struct stat mnt_sb;