From f03b8ad8d38634d13e802165cc15917481b47835 Mon Sep 17 00:00:00 2001 From: Miklos Szeredi Date: Tue, 27 Sep 2016 11:03:57 +0200 Subject: fs: support RENAME_NOREPLACE for local filesystems This is trivial to do: - add flags argument to foo_rename() - check if flags doesn't have any other than RENAME_NOREPLACE - assign foo_rename() to .rename2 instead of .rename Filesystems converted: affs, bfs, exofs, ext2, hfs, hfsplus, jffs2, jfs, logfs, minix, msdos, nilfs2, omfs, reiserfs, sysvfs, ubifs, udf, ufs, vfat. Signed-off-by: Miklos Szeredi Acked-by: Boaz Harrosh Acked-by: Richard Weinberger Acked-by: Bob Copeland Acked-by: Jan Kara Cc: Theodore Ts'o Cc: Jaegeuk Kim Cc: OGAWA Hirofumi Cc: Mikulas Patocka Cc: David Woodhouse Cc: Dave Kleikamp Cc: Ryusuke Konishi Cc: Christoph Hellwig --- fs/fat/namei_msdos.c | 8 ++++++-- fs/fat/namei_vfat.c | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) (limited to 'fs/fat') diff --git a/fs/fat/namei_msdos.c b/fs/fat/namei_msdos.c index 664655b..6c81469 100644 --- a/fs/fat/namei_msdos.c +++ b/fs/fat/namei_msdos.c @@ -596,12 +596,16 @@ error_inode: /***** Rename, a wrapper for rename_same_dir & rename_diff_dir */ static int msdos_rename(struct inode *old_dir, struct dentry *old_dentry, - struct inode *new_dir, struct dentry *new_dentry) + struct inode *new_dir, struct dentry *new_dentry, + unsigned int flags) { struct super_block *sb = old_dir->i_sb; unsigned char old_msdos_name[MSDOS_NAME], new_msdos_name[MSDOS_NAME]; int err, is_hid; + if (flags & ~RENAME_NOREPLACE) + return -EINVAL; + mutex_lock(&MSDOS_SB(sb)->s_lock); err = msdos_format_name(old_dentry->d_name.name, @@ -633,7 +637,7 @@ static const struct inode_operations msdos_dir_inode_operations = { .unlink = msdos_unlink, .mkdir = msdos_mkdir, .rmdir = msdos_rmdir, - .rename = msdos_rename, + .rename2 = msdos_rename, .setattr = fat_setattr, .getattr = fat_getattr, }; diff --git a/fs/fat/namei_vfat.c b/fs/fat/namei_vfat.c index 92b7363..ce8986f 100644 --- a/fs/fat/namei_vfat.c +++ b/fs/fat/namei_vfat.c @@ -903,7 +903,8 @@ out: } static int vfat_rename(struct inode *old_dir, struct dentry *old_dentry, - struct inode *new_dir, struct dentry *new_dentry) + struct inode *new_dir, struct dentry *new_dentry, + unsigned int flags) { struct buffer_head *dotdot_bh; struct msdos_dir_entry *dotdot_de; @@ -914,6 +915,9 @@ static int vfat_rename(struct inode *old_dir, struct dentry *old_dentry, int err, is_dir, update_dotdot, corrupt = 0; struct super_block *sb = old_dir->i_sb; + if (flags & ~RENAME_NOREPLACE) + return -EINVAL; + old_sinfo.bh = sinfo.bh = dotdot_bh = NULL; old_inode = d_inode(old_dentry); new_inode = d_inode(new_dentry); @@ -1036,7 +1040,7 @@ static const struct inode_operations vfat_dir_inode_operations = { .unlink = vfat_unlink, .mkdir = vfat_mkdir, .rmdir = vfat_rmdir, - .rename = vfat_rename, + .rename2 = vfat_rename, .setattr = fat_setattr, .getattr = fat_getattr, }; -- cgit v1.1 From 2773bf00aeb9bf39e022463272a61dd0ec9f55f4 Mon Sep 17 00:00:00 2001 From: Miklos Szeredi Date: Tue, 27 Sep 2016 11:03:58 +0200 Subject: fs: rename "rename2" i_op to "rename" Generated patch: sed -i "s/\.rename2\t/\.rename\t\t/" `git grep -wl rename2` sed -i "s/\brename2\b/rename/g" `git grep -wl rename2` Signed-off-by: Miklos Szeredi --- fs/fat/namei_msdos.c | 2 +- fs/fat/namei_vfat.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'fs/fat') diff --git a/fs/fat/namei_msdos.c b/fs/fat/namei_msdos.c index 6c81469..a8f6aa9 100644 --- a/fs/fat/namei_msdos.c +++ b/fs/fat/namei_msdos.c @@ -637,7 +637,7 @@ static const struct inode_operations msdos_dir_inode_operations = { .unlink = msdos_unlink, .mkdir = msdos_mkdir, .rmdir = msdos_rmdir, - .rename2 = msdos_rename, + .rename = msdos_rename, .setattr = fat_setattr, .getattr = fat_getattr, }; diff --git a/fs/fat/namei_vfat.c b/fs/fat/namei_vfat.c index ce8986f..c5e48b8 100644 --- a/fs/fat/namei_vfat.c +++ b/fs/fat/namei_vfat.c @@ -1040,7 +1040,7 @@ static const struct inode_operations vfat_dir_inode_operations = { .unlink = vfat_unlink, .mkdir = vfat_mkdir, .rmdir = vfat_rmdir, - .rename2 = vfat_rename, + .rename = vfat_rename, .setattr = fat_setattr, .getattr = fat_getattr, }; -- cgit v1.1 From 02027d42c3f747945f19111d3da2092ed2148ac8 Mon Sep 17 00:00:00 2001 From: Deepa Dinamani Date: Wed, 14 Sep 2016 07:48:05 -0700 Subject: fs: Replace CURRENT_TIME_SEC with current_time() for inode timestamps CURRENT_TIME_SEC is not y2038 safe. current_time() will be transitioned to use 64 bit time along with vfs in a separate patch. There is no plan to transistion CURRENT_TIME_SEC to use y2038 safe time interfaces. current_time() will also be extended to use superblock range checking parameters when range checking is introduced. This works because alloc_super() fills in the the s_time_gran in super block to NSEC_PER_SEC. Signed-off-by: Deepa Dinamani Acked-by: Jan Kara Signed-off-by: Al Viro --- fs/fat/dir.c | 2 +- fs/fat/file.c | 4 ++-- fs/fat/inode.c | 2 +- fs/fat/namei_msdos.c | 12 ++++++------ fs/fat/namei_vfat.c | 10 +++++----- 5 files changed, 15 insertions(+), 15 deletions(-) (limited to 'fs/fat') diff --git a/fs/fat/dir.c b/fs/fat/dir.c index 663e428..81cecbe 100644 --- a/fs/fat/dir.c +++ b/fs/fat/dir.c @@ -1071,7 +1071,7 @@ int fat_remove_entries(struct inode *dir, struct fat_slot_info *sinfo) } } - dir->i_mtime = dir->i_atime = CURRENT_TIME_SEC; + dir->i_mtime = dir->i_atime = current_time(dir); if (IS_DIRSYNC(dir)) (void)fat_sync_inode(dir); else diff --git a/fs/fat/file.c b/fs/fat/file.c index f701856..811bbe0 100644 --- a/fs/fat/file.c +++ b/fs/fat/file.c @@ -194,7 +194,7 @@ static int fat_cont_expand(struct inode *inode, loff_t size) if (err) goto out; - inode->i_ctime = inode->i_mtime = CURRENT_TIME_SEC; + inode->i_ctime = inode->i_mtime = current_time(inode); mark_inode_dirty(inode); if (IS_SYNC(inode)) { int err2; @@ -297,7 +297,7 @@ static int fat_free(struct inode *inode, int skip) MSDOS_I(inode)->i_logstart = 0; } MSDOS_I(inode)->i_attrs |= ATTR_ARCH; - inode->i_ctime = inode->i_mtime = CURRENT_TIME_SEC; + inode->i_ctime = inode->i_mtime = current_time(inode); if (wait) { err = fat_sync_inode(inode); if (err) { diff --git a/fs/fat/inode.c b/fs/fat/inode.c index da04c02..338d2f7 100644 --- a/fs/fat/inode.c +++ b/fs/fat/inode.c @@ -237,7 +237,7 @@ static int fat_write_end(struct file *file, struct address_space *mapping, if (err < len) fat_write_failed(mapping, pos + len); if (!(err < 0) && !(MSDOS_I(inode)->i_attrs & ATTR_ARCH)) { - inode->i_mtime = inode->i_ctime = CURRENT_TIME_SEC; + inode->i_mtime = inode->i_ctime = current_time(inode); MSDOS_I(inode)->i_attrs |= ATTR_ARCH; mark_inode_dirty(inode); } diff --git a/fs/fat/namei_msdos.c b/fs/fat/namei_msdos.c index 664655b..ccd9f83 100644 --- a/fs/fat/namei_msdos.c +++ b/fs/fat/namei_msdos.c @@ -283,7 +283,7 @@ static int msdos_create(struct inode *dir, struct dentry *dentry, umode_t mode, goto out; } - ts = CURRENT_TIME_SEC; + ts = current_time(dir); err = msdos_add_entry(dir, msdos_name, 0, is_hid, 0, &ts, &sinfo); if (err) goto out; @@ -330,7 +330,7 @@ static int msdos_rmdir(struct inode *dir, struct dentry *dentry) drop_nlink(dir); clear_nlink(inode); - inode->i_ctime = CURRENT_TIME_SEC; + inode->i_ctime = current_time(inode); fat_detach(inode); out: mutex_unlock(&MSDOS_SB(sb)->s_lock); @@ -364,7 +364,7 @@ static int msdos_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) goto out; } - ts = CURRENT_TIME_SEC; + ts = current_time(dir); cluster = fat_alloc_new_dir(dir, &ts); if (cluster < 0) { err = cluster; @@ -416,7 +416,7 @@ static int msdos_unlink(struct inode *dir, struct dentry *dentry) if (err) goto out; clear_nlink(inode); - inode->i_ctime = CURRENT_TIME_SEC; + inode->i_ctime = current_time(inode); fat_detach(inode); out: mutex_unlock(&MSDOS_SB(sb)->s_lock); @@ -481,7 +481,7 @@ static int do_msdos_rename(struct inode *old_dir, unsigned char *old_name, mark_inode_dirty(old_inode); old_dir->i_version++; - old_dir->i_ctime = old_dir->i_mtime = CURRENT_TIME_SEC; + old_dir->i_ctime = old_dir->i_mtime = current_time(old_dir); if (IS_DIRSYNC(old_dir)) (void)fat_sync_inode(old_dir); else @@ -490,7 +490,7 @@ static int do_msdos_rename(struct inode *old_dir, unsigned char *old_name, } } - ts = CURRENT_TIME_SEC; + ts = current_time(old_inode); if (new_inode) { if (err) goto out; diff --git a/fs/fat/namei_vfat.c b/fs/fat/namei_vfat.c index 92b7363..d4a1b2b 100644 --- a/fs/fat/namei_vfat.c +++ b/fs/fat/namei_vfat.c @@ -777,7 +777,7 @@ static int vfat_create(struct inode *dir, struct dentry *dentry, umode_t mode, mutex_lock(&MSDOS_SB(sb)->s_lock); - ts = CURRENT_TIME_SEC; + ts = current_time(dir); err = vfat_add_entry(dir, &dentry->d_name, 0, 0, &ts, &sinfo); if (err) goto out; @@ -821,7 +821,7 @@ static int vfat_rmdir(struct inode *dir, struct dentry *dentry) drop_nlink(dir); clear_nlink(inode); - inode->i_mtime = inode->i_atime = CURRENT_TIME_SEC; + inode->i_mtime = inode->i_atime = current_time(inode); fat_detach(inode); dentry->d_time = dir->i_version; out: @@ -847,7 +847,7 @@ static int vfat_unlink(struct inode *dir, struct dentry *dentry) if (err) goto out; clear_nlink(inode); - inode->i_mtime = inode->i_atime = CURRENT_TIME_SEC; + inode->i_mtime = inode->i_atime = current_time(inode); fat_detach(inode); dentry->d_time = dir->i_version; out: @@ -866,7 +866,7 @@ static int vfat_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) mutex_lock(&MSDOS_SB(sb)->s_lock); - ts = CURRENT_TIME_SEC; + ts = current_time(dir); cluster = fat_alloc_new_dir(dir, &ts); if (cluster < 0) { err = cluster; @@ -931,7 +931,7 @@ static int vfat_rename(struct inode *old_dir, struct dentry *old_dentry, } } - ts = CURRENT_TIME_SEC; + ts = current_time(old_dir); if (new_inode) { if (is_dir) { err = fat_dir_empty(new_inode); -- cgit v1.1 From c2050a454c7f123d7a57fa1d76ff61bd43643abb Mon Sep 17 00:00:00 2001 From: Deepa Dinamani Date: Wed, 14 Sep 2016 07:48:06 -0700 Subject: fs: Replace current_fs_time() with current_time() current_fs_time() uses struct super_block* as an argument. As per Linus's suggestion, this is changed to take struct inode* as a parameter instead. This is because the function is primarily meant for vfs inode timestamps. Also the function was renamed as per Arnd's suggestion. Change all calls to current_fs_time() to use the new current_time() function instead. current_fs_time() will be deleted. Signed-off-by: Deepa Dinamani Signed-off-by: Al Viro --- fs/fat/file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'fs/fat') diff --git a/fs/fat/file.c b/fs/fat/file.c index 811bbe0..fc71ff5 100644 --- a/fs/fat/file.c +++ b/fs/fat/file.c @@ -63,7 +63,7 @@ static int fat_ioctl_set_attributes(struct file *file, u32 __user *user_attr) /* Equivalent to a chmod() */ ia.ia_valid = ATTR_MODE | ATTR_CTIME; - ia.ia_ctime = current_fs_time(inode->i_sb); + ia.ia_ctime = current_time(inode); if (is_dir) ia.ia_mode = fat_make_mode(sbi, attr, S_IRWXUGO); else { -- cgit v1.1