mirror of
https://github.com/koverstreet/bcachefs-tools.git
synced 2025-02-09 00:00:04 +03:00
check if fs is mounted before running fsck
This commit is contained in:
parent
ddb58076ef
commit
9b08492bc7
@ -385,14 +385,14 @@ int cmd_device_resize(int argc, char *argv[])
|
|||||||
|
|
||||||
struct stat dev_stat = xfstat(dev_fd);
|
struct stat dev_stat = xfstat(dev_fd);
|
||||||
|
|
||||||
char *mount = dev_to_mount(dev);
|
struct mntent *mount = dev_to_mount(dev);
|
||||||
if (mount) {
|
if (mount) {
|
||||||
if (!S_ISBLK(dev_stat.st_mode))
|
if (!S_ISBLK(dev_stat.st_mode))
|
||||||
die("%s is mounted but isn't a block device?!", dev);
|
die("%s is mounted but isn't a block device?!", dev);
|
||||||
|
|
||||||
printf("Doing online resize of %s\n", dev);
|
printf("Doing online resize of %s\n", dev);
|
||||||
|
|
||||||
struct bchfs_handle fs = bcache_fs_open(mount);
|
struct bchfs_handle fs = bcache_fs_open(mount->mnt_dir);
|
||||||
|
|
||||||
unsigned idx = bchu_disk_get_idx(fs, dev_stat.st_rdev);
|
unsigned idx = bchu_disk_get_idx(fs, dev_stat.st_rdev);
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@ static void usage(void)
|
|||||||
int cmd_fsck(int argc, char *argv[])
|
int cmd_fsck(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
struct bch_opts opts = bch2_opts_empty();
|
struct bch_opts opts = bch2_opts_empty();
|
||||||
|
unsigned i;
|
||||||
int opt, ret = 0;
|
int opt, ret = 0;
|
||||||
|
|
||||||
opt_set(opts, degraded, true);
|
opt_set(opts, degraded, true);
|
||||||
@ -56,6 +57,10 @@ int cmd_fsck(int argc, char *argv[])
|
|||||||
if (!argc)
|
if (!argc)
|
||||||
die("Please supply device(s) to check");
|
die("Please supply device(s) to check");
|
||||||
|
|
||||||
|
for (i = 0; i < argc; i++)
|
||||||
|
if (dev_mounted_rw(argv[i]))
|
||||||
|
die("%s is mounted read-write - aborting", argv[i]);
|
||||||
|
|
||||||
struct bch_fs *c = bch2_fs_open(argv, argc, opts);
|
struct bch_fs *c = bch2_fs_open(argv, argc, opts);
|
||||||
if (IS_ERR(c))
|
if (IS_ERR(c))
|
||||||
die("error opening %s: %s", argv[0], strerror(-PTR_ERR(c)));
|
die("error opening %s: %s", argv[0], strerror(-PTR_ERR(c)));
|
||||||
|
28
tools-util.c
28
tools-util.c
@ -610,26 +610,18 @@ char *dev_to_path(dev_t dev)
|
|||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *dev_to_mount(char *dev)
|
struct mntent *dev_to_mount(char *dev)
|
||||||
{
|
{
|
||||||
char *line = NULL, *ret = NULL;
|
struct mntent *mnt, *ret = NULL;
|
||||||
size_t n = 0;
|
FILE *f = setmntent("/proc/mounts", "r");
|
||||||
|
|
||||||
FILE *f = fopen("/proc/mounts", "r");
|
|
||||||
if (!f)
|
if (!f)
|
||||||
die("error opening /proc/mounts: %m");
|
die("error opening /proc/mounts: %m");
|
||||||
|
|
||||||
struct stat d1 = xstat(dev);
|
struct stat d1 = xstat(dev);
|
||||||
|
|
||||||
while (getline(&line, &n, f) != -1) {
|
while ((mnt = getmntent(f))) {
|
||||||
char *d, *p = line;
|
char *d, *p = mnt->mnt_fsname;
|
||||||
char *devs = strsep(&p, " ");
|
|
||||||
char *mount = strsep(&p, " ");
|
|
||||||
|
|
||||||
if (!devs || !mount)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
p = devs;
|
|
||||||
while ((d = strsep(&p, ":"))) {
|
while ((d = strsep(&p, ":"))) {
|
||||||
struct stat d2;
|
struct stat d2;
|
||||||
|
|
||||||
@ -648,12 +640,18 @@ char *dev_to_mount(char *dev)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = strdup(mount);
|
ret = mnt;
|
||||||
goto found;
|
goto found;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
found:
|
found:
|
||||||
fclose(f);
|
fclose(f);
|
||||||
free(line);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool dev_mounted_rw(char *dev)
|
||||||
|
{
|
||||||
|
struct mntent *mnt = dev_to_mount(dev);
|
||||||
|
|
||||||
|
return mnt && !hasmntopt(mnt, "ro");
|
||||||
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#define _TOOLS_UTIL_H
|
#define _TOOLS_UTIL_H
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <mntent.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -153,7 +154,8 @@ u32 crc32c(u32, const void *, size_t);
|
|||||||
|
|
||||||
char *dev_to_name(dev_t);
|
char *dev_to_name(dev_t);
|
||||||
char *dev_to_path(dev_t);
|
char *dev_to_path(dev_t);
|
||||||
char *dev_to_mount(char *);
|
struct mntent *dev_to_mount(char *);
|
||||||
|
bool dev_mounted_rw(char *);
|
||||||
|
|
||||||
#define args_shift(_nr) \
|
#define args_shift(_nr) \
|
||||||
do { \
|
do { \
|
||||||
|
Loading…
Reference in New Issue
Block a user