mirror of
https://github.com/schoebel/mars
synced 2024-12-12 09:45:41 +00:00
infra: new helper mars_is_mountpoint()
This commit is contained in:
parent
7467aa9939
commit
6d9ffefb84
@ -225,6 +225,7 @@ bool push_link(const char *peer_name,
|
||||
|
||||
/* General fs wrappers (for abstraction)
|
||||
*/
|
||||
extern bool mars_is_mountpoint(const char *pathname);
|
||||
extern int mars_stat(const char *path, struct kstat *stat, bool use_lstat);
|
||||
extern void mars_sync(void);
|
||||
extern int mars_mkdir(const char *path);
|
||||
|
@ -533,6 +533,44 @@ int _length_paranoia(int len, int line)
|
||||
return len;
|
||||
}
|
||||
|
||||
bool mars_is_mountpoint(const char *pathname)
|
||||
{
|
||||
struct path path = {};
|
||||
mm_segment_t oldfs;
|
||||
int status;
|
||||
bool res = false;
|
||||
|
||||
oldfs = get_fs();
|
||||
set_fs(get_ds());
|
||||
|
||||
status = user_path_at(AT_FDCWD, pathname, 0, &path);
|
||||
if (unlikely(status < 0)) {
|
||||
MARS_WRN("pathname '%s' does not exist, status = %d\n",
|
||||
pathname, status);
|
||||
goto done_fs;
|
||||
}
|
||||
if (unlikely(!path.dentry)) {
|
||||
MARS_WRN("path '%s' has invalid dentry\n", pathname);
|
||||
goto done_put;
|
||||
}
|
||||
if (unlikely(!follow_up(&path))) {
|
||||
MARS_WRN("path '%s' has no vfsmnt\n", pathname);
|
||||
goto done_put;
|
||||
}
|
||||
/* the second one may fail when we already are at the root mount */
|
||||
if (!follow_up(&path)) {
|
||||
goto done_put;
|
||||
}
|
||||
res = d_mountpoint(path.dentry);
|
||||
|
||||
done_put:
|
||||
path_put(&path);
|
||||
|
||||
done_fs:
|
||||
set_fs(oldfs);
|
||||
return res;
|
||||
}
|
||||
|
||||
int mars_stat(const char *path, struct kstat *stat, bool use_lstat)
|
||||
{
|
||||
mm_segment_t oldfs;
|
||||
|
Loading…
Reference in New Issue
Block a user