Skip to content

Commit 6c3684e

Browse files
fs/ntfs3: Implement super_operations::shutdown
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
1 parent e50f956 commit 6c3684e

7 files changed

Lines changed: 75 additions & 3 deletions

File tree

fs/ntfs3/file.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,9 @@ static int ntfs_file_mmap(struct file *file, struct vm_area_struct *vma)
260260
bool rw = vma->vm_flags & VM_WRITE;
261261
int err;
262262

263+
if (unlikely(ntfs3_forced_shutdown(inode->i_sb)))
264+
return -EIO;
265+
263266
if (is_encrypted(ni)) {
264267
ntfs_inode_warn(inode, "mmap encrypted not supported");
265268
return -EOPNOTSUPP;
@@ -677,6 +680,9 @@ int ntfs3_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
677680
umode_t mode = inode->i_mode;
678681
int err;
679682

683+
if (unlikely(ntfs3_forced_shutdown(inode->i_sb)))
684+
return -EIO;
685+
680686
err = setattr_prepare(idmap, dentry, attr);
681687
if (err)
682688
goto out;
@@ -732,6 +738,9 @@ static ssize_t ntfs_file_read_iter(struct kiocb *iocb, struct iov_iter *iter)
732738
struct inode *inode = file->f_mapping->host;
733739
struct ntfs_inode *ni = ntfs_i(inode);
734740

741+
if (unlikely(ntfs3_forced_shutdown(inode->i_sb)))
742+
return -EIO;
743+
735744
if (is_encrypted(ni)) {
736745
ntfs_inode_warn(inode, "encrypted i/o not supported");
737746
return -EOPNOTSUPP;
@@ -766,6 +775,9 @@ static ssize_t ntfs_file_splice_read(struct file *in, loff_t *ppos,
766775
struct inode *inode = in->f_mapping->host;
767776
struct ntfs_inode *ni = ntfs_i(inode);
768777

778+
if (unlikely(ntfs3_forced_shutdown(inode->i_sb)))
779+
return -EIO;
780+
769781
if (is_encrypted(ni)) {
770782
ntfs_inode_warn(inode, "encrypted i/o not supported");
771783
return -EOPNOTSUPP;
@@ -1058,6 +1070,9 @@ static ssize_t ntfs_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
10581070
int err;
10591071
struct ntfs_inode *ni = ntfs_i(inode);
10601072

1073+
if (unlikely(ntfs3_forced_shutdown(inode->i_sb)))
1074+
return -EIO;
1075+
10611076
if (is_encrypted(ni)) {
10621077
ntfs_inode_warn(inode, "encrypted i/o not supported");
10631078
return -EOPNOTSUPP;
@@ -1118,6 +1133,9 @@ int ntfs_file_open(struct inode *inode, struct file *file)
11181133
{
11191134
struct ntfs_inode *ni = ntfs_i(inode);
11201135

1136+
if (unlikely(ntfs3_forced_shutdown(inode->i_sb)))
1137+
return -EIO;
1138+
11211139
if (unlikely((is_compressed(ni) || is_encrypted(ni)) &&
11221140
(file->f_flags & O_DIRECT))) {
11231141
return -EOPNOTSUPP;

fs/ntfs3/frecord.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3259,6 +3259,9 @@ int ni_write_inode(struct inode *inode, int sync, const char *hint)
32593259
if (is_bad_inode(inode) || sb_rdonly(sb))
32603260
return 0;
32613261

3262+
if (unlikely(ntfs3_forced_shutdown(sb)))
3263+
return -EIO;
3264+
32623265
if (!ni_trylock(ni)) {
32633266
/* 'ni' is under modification, skip for now. */
32643267
mark_inode_dirty_sync(inode);

fs/ntfs3/inode.c

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -852,9 +852,13 @@ static int ntfs_resident_writepage(struct folio *folio,
852852
struct writeback_control *wbc, void *data)
853853
{
854854
struct address_space *mapping = data;
855-
struct ntfs_inode *ni = ntfs_i(mapping->host);
855+
struct inode *inode = mapping->host;
856+
struct ntfs_inode *ni = ntfs_i(inode);
856857
int ret;
857858

859+
if (unlikely(ntfs3_forced_shutdown(inode->i_sb)))
860+
return -EIO;
861+
858862
ni_lock(ni);
859863
ret = attr_data_write_resident(ni, &folio->page);
860864
ni_unlock(ni);
@@ -868,7 +872,12 @@ static int ntfs_resident_writepage(struct folio *folio,
868872
static int ntfs_writepages(struct address_space *mapping,
869873
struct writeback_control *wbc)
870874
{
871-
if (is_resident(ntfs_i(mapping->host)))
875+
struct inode *inode = mapping->host;
876+
877+
if (unlikely(ntfs3_forced_shutdown(inode->i_sb)))
878+
return -EIO;
879+
880+
if (is_resident(ntfs_i(inode)))
872881
return write_cache_pages(mapping, wbc, ntfs_resident_writepage,
873882
mapping);
874883
return mpage_writepages(mapping, wbc, ntfs_get_block);
@@ -888,6 +897,9 @@ int ntfs_write_begin(struct file *file, struct address_space *mapping,
888897
struct inode *inode = mapping->host;
889898
struct ntfs_inode *ni = ntfs_i(inode);
890899

900+
if (unlikely(ntfs3_forced_shutdown(inode->i_sb)))
901+
return -EIO;
902+
891903
*pagep = NULL;
892904
if (is_resident(ni)) {
893905
struct page *page =
@@ -1305,6 +1317,11 @@ struct inode *ntfs_create_inode(struct mnt_idmap *idmap, struct inode *dir,
13051317
goto out1;
13061318
}
13071319

1320+
if (unlikely(ntfs3_forced_shutdown(sb))) {
1321+
err = -EIO;
1322+
goto out2;
1323+
}
1324+
13081325
/* Mark rw ntfs as dirty. it will be cleared at umount. */
13091326
ntfs_set_state(sbi, NTFS_DIRTY_DIRTY);
13101327

fs/ntfs3/namei.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,9 @@ static int ntfs_unlink(struct inode *dir, struct dentry *dentry)
181181
struct ntfs_inode *ni = ntfs_i(dir);
182182
int err;
183183

184+
if (unlikely(ntfs3_forced_shutdown(dir->i_sb)))
185+
return -EIO;
186+
184187
ni_lock_dir(ni);
185188

186189
err = ntfs_unlink_inode(dir, dentry);
@@ -199,6 +202,9 @@ static int ntfs_symlink(struct mnt_idmap *idmap, struct inode *dir,
199202
u32 size = strlen(symname);
200203
struct inode *inode;
201204

205+
if (unlikely(ntfs3_forced_shutdown(dir->i_sb)))
206+
return -EIO;
207+
202208
inode = ntfs_create_inode(idmap, dir, dentry, NULL, S_IFLNK | 0777, 0,
203209
symname, size, NULL);
204210

@@ -227,6 +233,9 @@ static int ntfs_rmdir(struct inode *dir, struct dentry *dentry)
227233
struct ntfs_inode *ni = ntfs_i(dir);
228234
int err;
229235

236+
if (unlikely(ntfs3_forced_shutdown(dir->i_sb)))
237+
return -EIO;
238+
230239
ni_lock_dir(ni);
231240

232241
err = ntfs_unlink_inode(dir, dentry);
@@ -264,6 +273,9 @@ static int ntfs_rename(struct mnt_idmap *idmap, struct inode *dir,
264273
1024);
265274
static_assert(PATH_MAX >= 4 * 1024);
266275

276+
if (unlikely(ntfs3_forced_shutdown(sb)))
277+
return -EIO;
278+
267279
if (flags & ~RENAME_NOREPLACE)
268280
return -EINVAL;
269281

fs/ntfs3/ntfs_fs.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ enum utf16_endian;
6161

6262
/* sbi->flags */
6363
#define NTFS_FLAGS_NODISCARD 0x00000001
64+
/* ntfs in shutdown state. */
65+
#define NTFS_FLAGS_SHUTDOWN 0x00000002
6466
/* Set when LogFile is replaying. */
6567
#define NTFS_FLAGS_LOG_REPLAYING 0x00000008
6668
/* Set when we changed first MFT's which copy must be updated in $MftMirr. */
@@ -226,7 +228,7 @@ struct ntfs_sb_info {
226228
u64 maxbytes; // Maximum size for normal files.
227229
u64 maxbytes_sparse; // Maximum size for sparse file.
228230

229-
u32 flags; // See NTFS_FLAGS_XXX.
231+
unsigned long flags; // See NTFS_FLAGS_
230232

231233
CLST zone_max; // Maximum MFT zone length in clusters
232234
CLST bad_clusters; // The count of marked bad clusters.
@@ -999,6 +1001,11 @@ static inline struct ntfs_sb_info *ntfs_sb(struct super_block *sb)
9991001
return sb->s_fs_info;
10001002
}
10011003

1004+
static inline bool ntfs3_forced_shutdown(struct super_block *sb)
1005+
{
1006+
return test_bit(NTFS_FLAGS_SHUTDOWN, &ntfs_sb(sb)->flags);
1007+
}
1008+
10021009
/*
10031010
* ntfs_up_cluster - Align up on cluster boundary.
10041011
*/

fs/ntfs3/super.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,14 @@ static int ntfs_show_options(struct seq_file *m, struct dentry *root)
714714
return 0;
715715
}
716716

717+
/*
718+
* ntfs_shutdown - super_operations::shutdown
719+
*/
720+
static void ntfs_shutdown(struct super_block *sb)
721+
{
722+
set_bit(NTFS_FLAGS_SHUTDOWN, &ntfs_sb(sb)->flags);
723+
}
724+
717725
/*
718726
* ntfs_sync_fs - super_operations::sync_fs
719727
*/
@@ -724,6 +732,9 @@ static int ntfs_sync_fs(struct super_block *sb, int wait)
724732
struct ntfs_inode *ni;
725733
struct inode *inode;
726734

735+
if (unlikely(ntfs3_forced_shutdown(sb)))
736+
return -EIO;
737+
727738
ni = sbi->security.ni;
728739
if (ni) {
729740
inode = &ni->vfs_inode;
@@ -763,6 +774,7 @@ static const struct super_operations ntfs_sops = {
763774
.put_super = ntfs_put_super,
764775
.statfs = ntfs_statfs,
765776
.show_options = ntfs_show_options,
777+
.shutdown = ntfs_shutdown,
766778
.sync_fs = ntfs_sync_fs,
767779
.write_inode = ntfs3_write_inode,
768780
};

fs/ntfs3/xattr.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,9 @@ static int ntfs_getxattr(const struct xattr_handler *handler, struct dentry *de,
744744
int err;
745745
struct ntfs_inode *ni = ntfs_i(inode);
746746

747+
if (unlikely(ntfs3_forced_shutdown(inode->i_sb)))
748+
return -EIO;
749+
747750
/* Dispatch request. */
748751
if (!strcmp(name, SYSTEM_DOS_ATTRIB)) {
749752
/* system.dos_attrib */

0 commit comments

Comments
 (0)