Skip to content

Commit 108f1d8

Browse files
committed
add umask handling
1 parent 026dea6 commit 108f1d8

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

nullfsvfs.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
* testing etc..
2424
*/
2525
#include <linux/fs.h>
26+
#include <linux/fs_struct.h>
2627
#include <linux/init.h>
2728
#include <linux/kernel.h>
2829
#include <linux/kobject.h>
@@ -492,6 +493,10 @@ struct inode *nullfs_get_inode(struct super_block *sb, const struct inode *dir,
492493
return inode;
493494
}
494495

496+
static inline umode_t nullfs_apply_umask(umode_t mode) {
497+
return (mode & S_IFMT) | ((mode & S_IALLUGO) & ~current_umask());
498+
}
499+
495500
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 3, 0)
496501
static int nullfs_mknod(struct mnt_idmap *idmap, struct inode *dir,
497502
struct dentry *dentry, umode_t mode, dev_t dev)
@@ -506,7 +511,8 @@ static int nullfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
506511
struct inode *inode;
507512
int error = -ENOSPC;
508513

509-
inode = nullfs_get_inode(dir->i_sb, dir, mode, dev, dentry);
514+
umode_t masked = nullfs_apply_umask(mode);
515+
inode = nullfs_get_inode(dir->i_sb, dir, masked, dev, dentry);
510516

511517
if (inode) {
512518
/**
@@ -647,11 +653,12 @@ static int nullfs_tmpfile(struct inode *dir, struct dentry *dentry,
647653
umode_t mode)
648654
#endif
649655
{
656+
umode_t masked = nullfs_apply_umask(mode);
650657
struct inode *inode;
651658
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 1, 0)
652-
inode = nullfs_get_inode(dir->i_sb, dir, mode, 0, file->f_path.dentry);
659+
inode = nullfs_get_inode(dir->i_sb, dir, masked, 0, file->f_path.dentry);
653660
#else
654-
inode = nullfs_get_inode(dir->i_sb, dir, mode, 0, dentry);
661+
inode = nullfs_get_inode(dir->i_sb, dir, masked, 0, dentry);
655662
#endif
656663
if (!inode)
657664
return -ENOSPC;

0 commit comments

Comments
 (0)