Commit 454abafe authored by Dmitry Monakhov's avatar Dmitry Monakhov Committed by Al Viro

ramfs: replace inode uid,gid,mode initialization with helper function

- seems what ramfs_get_inode is only locally, make it static.
[AV: the hell it is; it's used by shmem, so shmem needed conversion too
and no, that function can't be made static]
Signed-off-by: default avatarDmitry Monakhov <dmonakhov@openvz.org>
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent 6a9e652c
...@@ -52,14 +52,13 @@ static struct backing_dev_info ramfs_backing_dev_info = { ...@@ -52,14 +52,13 @@ static struct backing_dev_info ramfs_backing_dev_info = {
BDI_CAP_READ_MAP | BDI_CAP_WRITE_MAP | BDI_CAP_EXEC_MAP, BDI_CAP_READ_MAP | BDI_CAP_WRITE_MAP | BDI_CAP_EXEC_MAP,
}; };
struct inode *ramfs_get_inode(struct super_block *sb, int mode, dev_t dev) struct inode *ramfs_get_inode(struct super_block *sb,
const struct inode *dir, int mode, dev_t dev)
{ {
struct inode * inode = new_inode(sb); struct inode * inode = new_inode(sb);
if (inode) { if (inode) {
inode->i_mode = mode; inode_init_owner(inode, dir, mode);
inode->i_uid = current_fsuid();
inode->i_gid = current_fsgid();
inode->i_mapping->a_ops = &ramfs_aops; inode->i_mapping->a_ops = &ramfs_aops;
inode->i_mapping->backing_dev_info = &ramfs_backing_dev_info; inode->i_mapping->backing_dev_info = &ramfs_backing_dev_info;
mapping_set_gfp_mask(inode->i_mapping, GFP_HIGHUSER); mapping_set_gfp_mask(inode->i_mapping, GFP_HIGHUSER);
...@@ -95,15 +94,10 @@ struct inode *ramfs_get_inode(struct super_block *sb, int mode, dev_t dev) ...@@ -95,15 +94,10 @@ struct inode *ramfs_get_inode(struct super_block *sb, int mode, dev_t dev)
static int static int
ramfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev) ramfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev)
{ {
struct inode * inode = ramfs_get_inode(dir->i_sb, mode, dev); struct inode * inode = ramfs_get_inode(dir->i_sb, dir, mode, dev);
int error = -ENOSPC; int error = -ENOSPC;
if (inode) { if (inode) {
if (dir->i_mode & S_ISGID) {
inode->i_gid = dir->i_gid;
if (S_ISDIR(mode))
inode->i_mode |= S_ISGID;
}
d_instantiate(dentry, inode); d_instantiate(dentry, inode);
dget(dentry); /* Extra count - pin the dentry in core */ dget(dentry); /* Extra count - pin the dentry in core */
error = 0; error = 0;
...@@ -130,13 +124,11 @@ static int ramfs_symlink(struct inode * dir, struct dentry *dentry, const char * ...@@ -130,13 +124,11 @@ static int ramfs_symlink(struct inode * dir, struct dentry *dentry, const char *
struct inode *inode; struct inode *inode;
int error = -ENOSPC; int error = -ENOSPC;
inode = ramfs_get_inode(dir->i_sb, S_IFLNK|S_IRWXUGO, 0); inode = ramfs_get_inode(dir->i_sb, dir, S_IFLNK|S_IRWXUGO, 0);
if (inode) { if (inode) {
int l = strlen(symname)+1; int l = strlen(symname)+1;
error = page_symlink(inode, symname, l); error = page_symlink(inode, symname, l);
if (!error) { if (!error) {
if (dir->i_mode & S_ISGID)
inode->i_gid = dir->i_gid;
d_instantiate(dentry, inode); d_instantiate(dentry, inode);
dget(dentry); dget(dentry);
dir->i_mtime = dir->i_ctime = CURRENT_TIME; dir->i_mtime = dir->i_ctime = CURRENT_TIME;
...@@ -241,7 +233,7 @@ int ramfs_fill_super(struct super_block *sb, void *data, int silent) ...@@ -241,7 +233,7 @@ int ramfs_fill_super(struct super_block *sb, void *data, int silent)
sb->s_op = &ramfs_ops; sb->s_op = &ramfs_ops;
sb->s_time_gran = 1; sb->s_time_gran = 1;
inode = ramfs_get_inode(sb, S_IFDIR | fsi->mount_opts.mode, 0); inode = ramfs_get_inode(sb, NULL, S_IFDIR | fsi->mount_opts.mode, 0);
if (!inode) { if (!inode) {
err = -ENOMEM; err = -ENOMEM;
goto fail; goto fail;
......
#ifndef _LINUX_RAMFS_H #ifndef _LINUX_RAMFS_H
#define _LINUX_RAMFS_H #define _LINUX_RAMFS_H
struct inode *ramfs_get_inode(struct super_block *sb, int mode, dev_t dev); struct inode *ramfs_get_inode(struct super_block *sb, const struct inode *dir,
int mode, dev_t dev);
extern int ramfs_get_sb(struct file_system_type *fs_type, extern int ramfs_get_sb(struct file_system_type *fs_type,
int flags, const char *dev_name, void *data, struct vfsmount *mnt); int flags, const char *dev_name, void *data, struct vfsmount *mnt);
......
...@@ -1545,8 +1545,8 @@ static int shmem_mmap(struct file *file, struct vm_area_struct *vma) ...@@ -1545,8 +1545,8 @@ static int shmem_mmap(struct file *file, struct vm_area_struct *vma)
return 0; return 0;
} }
static struct inode *shmem_get_inode(struct super_block *sb, int mode, static struct inode *shmem_get_inode(struct super_block *sb, const struct inode *dir,
dev_t dev, unsigned long flags) int mode, dev_t dev, unsigned long flags)
{ {
struct inode *inode; struct inode *inode;
struct shmem_inode_info *info; struct shmem_inode_info *info;
...@@ -1557,9 +1557,7 @@ static struct inode *shmem_get_inode(struct super_block *sb, int mode, ...@@ -1557,9 +1557,7 @@ static struct inode *shmem_get_inode(struct super_block *sb, int mode,
inode = new_inode(sb); inode = new_inode(sb);
if (inode) { if (inode) {
inode->i_mode = mode; inode_init_owner(inode, dir, mode);
inode->i_uid = current_fsuid();
inode->i_gid = current_fsgid();
inode->i_blocks = 0; inode->i_blocks = 0;
inode->i_mapping->backing_dev_info = &shmem_backing_dev_info; inode->i_mapping->backing_dev_info = &shmem_backing_dev_info;
inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME; inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
...@@ -1814,7 +1812,7 @@ shmem_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev) ...@@ -1814,7 +1812,7 @@ shmem_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev)
struct inode *inode; struct inode *inode;
int error = -ENOSPC; int error = -ENOSPC;
inode = shmem_get_inode(dir->i_sb, mode, dev, VM_NORESERVE); inode = shmem_get_inode(dir->i_sb, dir, mode, dev, VM_NORESERVE);
if (inode) { if (inode) {
error = security_inode_init_security(inode, dir, NULL, NULL, error = security_inode_init_security(inode, dir, NULL, NULL,
NULL); NULL);
...@@ -1833,11 +1831,6 @@ shmem_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev) ...@@ -1833,11 +1831,6 @@ shmem_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev)
#else #else
error = 0; error = 0;
#endif #endif
if (dir->i_mode & S_ISGID) {
inode->i_gid = dir->i_gid;
if (S_ISDIR(mode))
inode->i_mode |= S_ISGID;
}
dir->i_size += BOGO_DIRENT_SIZE; dir->i_size += BOGO_DIRENT_SIZE;
dir->i_ctime = dir->i_mtime = CURRENT_TIME; dir->i_ctime = dir->i_mtime = CURRENT_TIME;
d_instantiate(dentry, inode); d_instantiate(dentry, inode);
...@@ -1957,7 +1950,7 @@ static int shmem_symlink(struct inode *dir, struct dentry *dentry, const char *s ...@@ -1957,7 +1950,7 @@ static int shmem_symlink(struct inode *dir, struct dentry *dentry, const char *s
if (len > PAGE_CACHE_SIZE) if (len > PAGE_CACHE_SIZE)
return -ENAMETOOLONG; return -ENAMETOOLONG;
inode = shmem_get_inode(dir->i_sb, S_IFLNK|S_IRWXUGO, 0, VM_NORESERVE); inode = shmem_get_inode(dir->i_sb, dir, S_IFLNK|S_IRWXUGO, 0, VM_NORESERVE);
if (!inode) if (!inode)
return -ENOSPC; return -ENOSPC;
...@@ -1992,8 +1985,6 @@ static int shmem_symlink(struct inode *dir, struct dentry *dentry, const char *s ...@@ -1992,8 +1985,6 @@ static int shmem_symlink(struct inode *dir, struct dentry *dentry, const char *s
unlock_page(page); unlock_page(page);
page_cache_release(page); page_cache_release(page);
} }
if (dir->i_mode & S_ISGID)
inode->i_gid = dir->i_gid;
dir->i_size += BOGO_DIRENT_SIZE; dir->i_size += BOGO_DIRENT_SIZE;
dir->i_ctime = dir->i_mtime = CURRENT_TIME; dir->i_ctime = dir->i_mtime = CURRENT_TIME;
d_instantiate(dentry, inode); d_instantiate(dentry, inode);
...@@ -2366,7 +2357,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent) ...@@ -2366,7 +2357,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
sb->s_flags |= MS_POSIXACL; sb->s_flags |= MS_POSIXACL;
#endif #endif
inode = shmem_get_inode(sb, S_IFDIR | sbinfo->mode, 0, VM_NORESERVE); inode = shmem_get_inode(sb, NULL, S_IFDIR | sbinfo->mode, 0, VM_NORESERVE);
if (!inode) if (!inode)
goto failed; goto failed;
inode->i_uid = sbinfo->uid; inode->i_uid = sbinfo->uid;
...@@ -2611,7 +2602,7 @@ int shmem_lock(struct file *file, int lock, struct user_struct *user) ...@@ -2611,7 +2602,7 @@ int shmem_lock(struct file *file, int lock, struct user_struct *user)
#define shmem_vm_ops generic_file_vm_ops #define shmem_vm_ops generic_file_vm_ops
#define shmem_file_operations ramfs_file_operations #define shmem_file_operations ramfs_file_operations
#define shmem_get_inode(sb, mode, dev, flags) ramfs_get_inode(sb, mode, dev) #define shmem_get_inode(sb, dir, mode, dev, flags) ramfs_get_inode(sb, dir, mode, dev)
#define shmem_acct_size(flags, size) 0 #define shmem_acct_size(flags, size) 0
#define shmem_unacct_size(flags, size) do {} while (0) #define shmem_unacct_size(flags, size) do {} while (0)
#define SHMEM_MAX_BYTES MAX_LFS_FILESIZE #define SHMEM_MAX_BYTES MAX_LFS_FILESIZE
...@@ -2655,7 +2646,7 @@ struct file *shmem_file_setup(const char *name, loff_t size, unsigned long flags ...@@ -2655,7 +2646,7 @@ struct file *shmem_file_setup(const char *name, loff_t size, unsigned long flags
path.mnt = mntget(shm_mnt); path.mnt = mntget(shm_mnt);
error = -ENOSPC; error = -ENOSPC;
inode = shmem_get_inode(root->d_sb, S_IFREG | S_IRWXUGO, 0, flags); inode = shmem_get_inode(root->d_sb, NULL, S_IFREG | S_IRWXUGO, 0, flags);
if (!inode) if (!inode)
goto put_dentry; goto put_dentry;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment