Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
libmount: fix mount -a for cifs
when mounting a cifs share, the src is actually an UNC path which can in
in several forms:

simple:            //host/share, //host/share/
including subpath: //host/share/sub/path

to check if the cifs fs is mounted we have to extract the subpath and
compare *that* to the root.

Signed-off-by: Aurelien Aptel <aaptel@suse.com>
  • Loading branch information
aaptel authored and karelzak committed Sep 29, 2016
1 parent f20b214 commit 76d4fba
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions libmount/src/tab.c
Expand Up @@ -1329,6 +1329,20 @@ static int get_btrfs_fs_root(struct libmnt_table *tb, struct libmnt_fs *fs, char
}
#endif /* HAVE_BTRFS_SUPPORT */

static const char *get_cifs_unc_subdir_path (const char *unc)
{
/*
* 1 or more slash: %*[/]
* 1 or more non-slash: %*[^/]
* number of byte read: %n
*/
int share_end = 0;
int r = sscanf(unc, "%*[/]%*[^/]%*[/]%*[^/]%n", &share_end);
if (r == EOF || share_end == 0)
return NULL;
return unc + share_end;
}

/*
* tb: /proc/self/mountinfo
* fs: filesystem
Expand Down Expand Up @@ -1563,9 +1577,16 @@ int mnt_table_is_fs_mounted(struct libmnt_table *tb, struct libmnt_fs *fstab_fs)
}

if (root) {
const char *r = mnt_fs_get_root(fs);
if (!r || strcmp(r, root) != 0)
continue;
if (strcmp(mnt_fs_get_fstype(fs), "cifs") == 0) {
const char *unc_subdir = get_cifs_unc_subdir_path(src);
const char *path_on_fs = mnt_fs_get_root(fs);
if (!unc_subdir || !path_on_fs || !streq_paths(unc_subdir, path_on_fs))
continue;
} else {
const char *r = mnt_fs_get_root(fs);
if (!r || strcmp(r, root) != 0)
continue;
}
}

/*
Expand Down

0 comments on commit 76d4fba

Please sign in to comment.