summaryrefslogtreecommitdiff
path: root/fs/statfs.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/statfs.c')
-rw-r--r--fs/statfs.c95
1 files changed, 71 insertions, 24 deletions
diff --git a/fs/statfs.c b/fs/statfs.c
index 4ef021f3b612..30ea8c8a996b 100644
--- a/fs/statfs.c
+++ b/fs/statfs.c
@@ -2,38 +2,83 @@
#include <linux/module.h>
#include <linux/fs.h>
#include <linux/file.h>
+#include <linux/mount.h>
#include <linux/namei.h>
#include <linux/statfs.h>
#include <linux/security.h>
#include <linux/uaccess.h>
-int vfs_statfs(struct dentry *dentry, struct kstatfs *buf)
+static int flags_by_mnt(int mnt_flags)
{
- int retval = -ENODEV;
-
- if (dentry) {
- retval = -ENOSYS;
- if (dentry->d_sb->s_op->statfs) {
- memset(buf, 0, sizeof(*buf));
- retval = security_sb_statfs(dentry);
- if (retval)
- return retval;
- retval = dentry->d_sb->s_op->statfs(dentry, buf);
- if (retval == 0 && buf->f_frsize == 0)
- buf->f_frsize = buf->f_bsize;
- }
- }
+ int flags = 0;
+
+ if (mnt_flags & MNT_READONLY)
+ flags |= ST_RDONLY;
+ if (mnt_flags & MNT_NOSUID)
+ flags |= ST_NOSUID;
+ if (mnt_flags & MNT_NODEV)
+ flags |= ST_NODEV;
+ if (mnt_flags & MNT_NOEXEC)
+ flags |= ST_NOEXEC;
+ if (mnt_flags & MNT_NOATIME)
+ flags |= ST_NOATIME;
+ if (mnt_flags & MNT_NODIRATIME)
+ flags |= ST_NODIRATIME;
+ if (mnt_flags & MNT_RELATIME)
+ flags |= ST_RELATIME;
+ return flags;
+}
+
+static int flags_by_sb(int s_flags)
+{
+ int flags = 0;
+ if (s_flags & MS_SYNCHRONOUS)
+ flags |= ST_SYNCHRONOUS;
+ if (s_flags & MS_MANDLOCK)
+ flags |= ST_MANDLOCK;
+ return flags;
+}
+
+static int calculate_f_flags(struct vfsmount *mnt)
+{
+ return ST_VALID | flags_by_mnt(mnt->mnt_flags) |
+ flags_by_sb(mnt->mnt_sb->s_flags);
+}
+
+int statfs_by_dentry(struct dentry *dentry, struct kstatfs *buf)
+{
+ int retval;
+
+ if (!dentry->d_sb->s_op->statfs)
+ return -ENOSYS;
+
+ memset(buf, 0, sizeof(*buf));
+ retval = security_sb_statfs(dentry);
+ if (retval)
+ return retval;
+ retval = dentry->d_sb->s_op->statfs(dentry, buf);
+ if (retval == 0 && buf->f_frsize == 0)
+ buf->f_frsize = buf->f_bsize;
return retval;
}
+int vfs_statfs(struct path *path, struct kstatfs *buf)
+{
+ int error;
+
+ error = statfs_by_dentry(path->dentry, buf);
+ if (!error)
+ buf->f_flags = calculate_f_flags(path->mnt);
+ return error;
+}
EXPORT_SYMBOL(vfs_statfs);
-static int vfs_statfs_native(struct dentry *dentry, struct statfs *buf)
+static int do_statfs_native(struct path *path, struct statfs *buf)
{
struct kstatfs st;
int retval;
- retval = vfs_statfs(dentry, &st);
+ retval = vfs_statfs(path, &st);
if (retval)
return retval;
@@ -67,17 +112,18 @@ static int vfs_statfs_native(struct dentry *dentry, struct statfs *buf)
buf->f_fsid = st.f_fsid;
buf->f_namelen = st.f_namelen;
buf->f_frsize = st.f_frsize;
+ buf->f_flags = st.f_flags;
memset(buf->f_spare, 0, sizeof(buf->f_spare));
}
return 0;
}
-static int vfs_statfs64(struct dentry *dentry, struct statfs64 *buf)
+static int do_statfs64(struct path *path, struct statfs64 *buf)
{
struct kstatfs st;
int retval;
- retval = vfs_statfs(dentry, &st);
+ retval = vfs_statfs(path, &st);
if (retval)
return retval;
@@ -94,6 +140,7 @@ static int vfs_statfs64(struct dentry *dentry, struct statfs64 *buf)
buf->f_fsid = st.f_fsid;
buf->f_namelen = st.f_namelen;
buf->f_frsize = st.f_frsize;
+ buf->f_flags = st.f_flags;
memset(buf->f_spare, 0, sizeof(buf->f_spare));
}
return 0;
@@ -107,7 +154,7 @@ SYSCALL_DEFINE2(statfs, const char __user *, pathname, struct statfs __user *, b
error = user_path(pathname, &path);
if (!error) {
struct statfs tmp;
- error = vfs_statfs_native(path.dentry, &tmp);
+ error = do_statfs_native(&path, &tmp);
if (!error && copy_to_user(buf, &tmp, sizeof(tmp)))
error = -EFAULT;
path_put(&path);
@@ -125,7 +172,7 @@ SYSCALL_DEFINE3(statfs64, const char __user *, pathname, size_t, sz, struct stat
error = user_path(pathname, &path);
if (!error) {
struct statfs64 tmp;
- error = vfs_statfs64(path.dentry, &tmp);
+ error = do_statfs64(&path, &tmp);
if (!error && copy_to_user(buf, &tmp, sizeof(tmp)))
error = -EFAULT;
path_put(&path);
@@ -143,7 +190,7 @@ SYSCALL_DEFINE2(fstatfs, unsigned int, fd, struct statfs __user *, buf)
file = fget(fd);
if (!file)
goto out;
- error = vfs_statfs_native(file->f_path.dentry, &tmp);
+ error = do_statfs_native(&file->f_path, &tmp);
if (!error && copy_to_user(buf, &tmp, sizeof(tmp)))
error = -EFAULT;
fput(file);
@@ -164,7 +211,7 @@ SYSCALL_DEFINE3(fstatfs64, unsigned int, fd, size_t, sz, struct statfs64 __user
file = fget(fd);
if (!file)
goto out;
- error = vfs_statfs64(file->f_path.dentry, &tmp);
+ error = do_statfs64(&file->f_path, &tmp);
if (!error && copy_to_user(buf, &tmp, sizeof(tmp)))
error = -EFAULT;
fput(file);
@@ -183,7 +230,7 @@ SYSCALL_DEFINE2(ustat, unsigned, dev, struct ustat __user *, ubuf)
if (!s)
return -EINVAL;
- err = vfs_statfs(s->s_root, &sbuf);
+ err = statfs_by_dentry(s->s_root, &sbuf);
drop_super(s);
if (err)
return err;