@@ -1079,7 +1079,8 @@ static int do_receive(struct btrfs_receive *rctx, const char *tomnt,
if (realmnt[0]) {
rctx->root_path = realmnt;
} else {
- ret = find_mount_root(dest_dir_full_path, &rctx->root_path);
+ ret = find_mount_root(dest_dir_full_path, dest_dir_full_path,
+ BTRFS_FIND_ROOT_PATH, &rctx->root_path);
if (ret < 0) {
errno = -ret;
error("failed to determine mount point for %s: %m",
@@ -329,7 +329,8 @@ static int init_root_path(struct btrfs_send *sctx, const char *subvol)
if (sctx->root_path)
goto out;
- ret = find_mount_root(subvol, &sctx->root_path);
+ ret = find_mount_root(subvol, subvol, BTRFS_FIND_ROOT_PATH,
+ &sctx->root_path);
if (ret < 0) {
errno = -ret;
error("failed to determine mount point for %s: %m", subvol);
@@ -659,7 +660,8 @@ static int cmd_send(const struct cmd_struct *cmd, int argc, char **argv)
goto out;
}
- ret = find_mount_root(subvol, &mount_root);
+ ret = find_mount_root(subvol, subvol, BTRFS_FIND_ROOT_PATH,
+ &mount_root);
if (ret < 0) {
errno = -ret;
error("find_mount_root failed on %s: %m", subvol);
@@ -1248,7 +1248,7 @@ int ask_user(const char *question)
* return 1 if a mount point is found but not btrfs
* return <0 if something goes wrong
*/
-int find_mount_root(const char *path, char **mount_root)
+int find_mount_root(const char *path, const char *data, u8 flag, char **mount_root)
{
FILE *mnttab;
int fd;
@@ -1258,6 +1258,10 @@ int find_mount_root(const char *path, char **mount_root)
int not_btrfs = 1;
int longest_matchlen = 0;
char *longest_match = NULL;
+ char *cmp_field = NULL;
+ bool found;
+
+ BUG_ON(flag != BTRFS_FIND_ROOT_PATH);
fd = open(path, O_RDONLY | O_NOATIME);
if (fd < 0)
@@ -1269,8 +1273,13 @@ int find_mount_root(const char *path, char **mount_root)
return -errno;
while ((ent = getmntent(mnttab))) {
- len = strlen(ent->mnt_dir);
- if (strncmp(ent->mnt_dir, path, len) == 0) {
+ cmp_field = ent->mnt_dir;
+
+ len = strlen(cmp_field);
+
+ found = strncmp(cmp_field, data, len) == 0;
+
+ if (found) {
/* match found and use the latest match */
if (longest_matchlen <= len) {
free(longest_match);
@@ -52,6 +52,11 @@
#define UNITS_HUMAN (UNITS_HUMAN_BINARY)
#define UNITS_DEFAULT (UNITS_HUMAN)
+enum btrfs_find_root_flags {
+ /* check mnt_dir of mntent */
+ BTRFS_FIND_ROOT_PATH = 0
+};
+
void units_set_mode(unsigned *units, unsigned mode);
void units_set_base(unsigned *units, unsigned base);
@@ -93,7 +98,8 @@ int csum_tree_block(struct btrfs_fs_info *root, struct extent_buffer *buf,
int ask_user(const char *question);
int lookup_path_rootid(int fd, u64 *rootid);
int get_btrfs_mount(const char *dev, char *mp, size_t mp_size);
-int find_mount_root(const char *path, char **mount_root);
+int find_mount_root(const char *path, const char *data, u8 flag,
+ char **mount_root);
int get_device_info(int fd, u64 devid,
struct btrfs_ioctl_dev_info_args *di_args);
int get_df(int fd, struct btrfs_ioctl_space_args **sargs_ret);