aboutsummaryrefslogtreecommitdiffstats
path: root/fs/namei.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/namei.c')
-rw-r--r--fs/namei.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/fs/namei.c b/fs/namei.c
index 561db47ae041..a94a7f9a03ea 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -642,7 +642,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
642 cond_resched(); 642 cond_resched();
643 current->total_link_count++; 643 current->total_link_count++;
644 644
645 touch_atime(link->mnt, dentry); 645 touch_atime(link);
646 nd_set_link(nd, NULL); 646 nd_set_link(nd, NULL);
647 647
648 error = security_inode_follow_link(link->dentry, nd); 648 error = security_inode_follow_link(link->dentry, nd);
@@ -2697,6 +2697,7 @@ SYSCALL_DEFINE3(mknod, const char __user *, filename, umode_t, mode, unsigned, d
2697int vfs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) 2697int vfs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
2698{ 2698{
2699 int error = may_create(dir, dentry); 2699 int error = may_create(dir, dentry);
2700 unsigned max_links = dir->i_sb->s_max_links;
2700 2701
2701 if (error) 2702 if (error)
2702 return error; 2703 return error;
@@ -2709,6 +2710,9 @@ int vfs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
2709 if (error) 2710 if (error)
2710 return error; 2711 return error;
2711 2712
2713 if (max_links && dir->i_nlink >= max_links)
2714 return -EMLINK;
2715
2712 error = dir->i_op->mkdir(dir, dentry, mode); 2716 error = dir->i_op->mkdir(dir, dentry, mode);
2713 if (!error) 2717 if (!error)
2714 fsnotify_mkdir(dir, dentry); 2718 fsnotify_mkdir(dir, dentry);
@@ -3039,6 +3043,7 @@ SYSCALL_DEFINE2(symlink, const char __user *, oldname, const char __user *, newn
3039int vfs_link(struct dentry *old_dentry, struct inode *dir, struct dentry *new_dentry) 3043int vfs_link(struct dentry *old_dentry, struct inode *dir, struct dentry *new_dentry)
3040{ 3044{
3041 struct inode *inode = old_dentry->d_inode; 3045 struct inode *inode = old_dentry->d_inode;
3046 unsigned max_links = dir->i_sb->s_max_links;
3042 int error; 3047 int error;
3043 3048
3044 if (!inode) 3049 if (!inode)
@@ -3069,6 +3074,8 @@ int vfs_link(struct dentry *old_dentry, struct inode *dir, struct dentry *new_de
3069 /* Make sure we don't allow creating hardlink to an unlinked file */ 3074 /* Make sure we don't allow creating hardlink to an unlinked file */
3070 if (inode->i_nlink == 0) 3075 if (inode->i_nlink == 0)
3071 error = -ENOENT; 3076 error = -ENOENT;
3077 else if (max_links && inode->i_nlink >= max_links)
3078 error = -EMLINK;
3072 else 3079 else
3073 error = dir->i_op->link(old_dentry, dir, new_dentry); 3080 error = dir->i_op->link(old_dentry, dir, new_dentry);
3074 mutex_unlock(&inode->i_mutex); 3081 mutex_unlock(&inode->i_mutex);
@@ -3178,6 +3185,7 @@ static int vfs_rename_dir(struct inode *old_dir, struct dentry *old_dentry,
3178{ 3185{
3179 int error = 0; 3186 int error = 0;
3180 struct inode *target = new_dentry->d_inode; 3187 struct inode *target = new_dentry->d_inode;
3188 unsigned max_links = new_dir->i_sb->s_max_links;
3181 3189
3182 /* 3190 /*
3183 * If we are going to change the parent - check write permissions, 3191 * If we are going to change the parent - check write permissions,
@@ -3201,6 +3209,11 @@ static int vfs_rename_dir(struct inode *old_dir, struct dentry *old_dentry,
3201 if (d_mountpoint(old_dentry) || d_mountpoint(new_dentry)) 3209 if (d_mountpoint(old_dentry) || d_mountpoint(new_dentry))
3202 goto out; 3210 goto out;
3203 3211
3212 error = -EMLINK;
3213 if (max_links && !target && new_dir != old_dir &&
3214 new_dir->i_nlink >= max_links)
3215 goto out;
3216
3204 if (target) 3217 if (target)
3205 shrink_dcache_parent(new_dentry); 3218 shrink_dcache_parent(new_dentry);
3206 error = old_dir->i_op->rename(old_dir, old_dentry, new_dir, new_dentry); 3219 error = old_dir->i_op->rename(old_dir, old_dentry, new_dir, new_dentry);