fixup over ("LiteX: driver for LiteVideo")
[linux/fpc-iii.git] / fs / bad_inode.c
blob54f0ce44427200ba32ba0db078faf120a9b5f172
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * linux/fs/bad_inode.c
5 * Copyright (C) 1997, Stephen Tweedie
7 * Provide stub functions for unreadable inodes
9 * Fabian Frederick : August 2003 - All file operations assigned to EIO
12 #include <linux/fs.h>
13 #include <linux/export.h>
14 #include <linux/stat.h>
15 #include <linux/time.h>
16 #include <linux/namei.h>
17 #include <linux/poll.h>
18 #include <linux/fiemap.h>
20 static int bad_file_open(struct inode *inode, struct file *filp)
22 return -EIO;
25 static const struct file_operations bad_file_ops =
27 .open = bad_file_open,
30 static int bad_inode_create (struct inode *dir, struct dentry *dentry,
31 umode_t mode, bool excl)
33 return -EIO;
36 static struct dentry *bad_inode_lookup(struct inode *dir,
37 struct dentry *dentry, unsigned int flags)
39 return ERR_PTR(-EIO);
42 static int bad_inode_link (struct dentry *old_dentry, struct inode *dir,
43 struct dentry *dentry)
45 return -EIO;
48 static int bad_inode_unlink(struct inode *dir, struct dentry *dentry)
50 return -EIO;
53 static int bad_inode_symlink (struct inode *dir, struct dentry *dentry,
54 const char *symname)
56 return -EIO;
59 static int bad_inode_mkdir(struct inode *dir, struct dentry *dentry,
60 umode_t mode)
62 return -EIO;
65 static int bad_inode_rmdir (struct inode *dir, struct dentry *dentry)
67 return -EIO;
70 static int bad_inode_mknod (struct inode *dir, struct dentry *dentry,
71 umode_t mode, dev_t rdev)
73 return -EIO;
76 static int bad_inode_rename2(struct inode *old_dir, struct dentry *old_dentry,
77 struct inode *new_dir, struct dentry *new_dentry,
78 unsigned int flags)
80 return -EIO;
83 static int bad_inode_readlink(struct dentry *dentry, char __user *buffer,
84 int buflen)
86 return -EIO;
89 static int bad_inode_permission(struct inode *inode, int mask)
91 return -EIO;
94 static int bad_inode_getattr(const struct path *path, struct kstat *stat,
95 u32 request_mask, unsigned int query_flags)
97 return -EIO;
100 static int bad_inode_setattr(struct dentry *direntry, struct iattr *attrs)
102 return -EIO;
105 static ssize_t bad_inode_listxattr(struct dentry *dentry, char *buffer,
106 size_t buffer_size)
108 return -EIO;
111 static const char *bad_inode_get_link(struct dentry *dentry,
112 struct inode *inode,
113 struct delayed_call *done)
115 return ERR_PTR(-EIO);
118 static struct posix_acl *bad_inode_get_acl(struct inode *inode, int type)
120 return ERR_PTR(-EIO);
123 static int bad_inode_fiemap(struct inode *inode,
124 struct fiemap_extent_info *fieinfo, u64 start,
125 u64 len)
127 return -EIO;
130 static int bad_inode_update_time(struct inode *inode, struct timespec64 *time,
131 int flags)
133 return -EIO;
136 static int bad_inode_atomic_open(struct inode *inode, struct dentry *dentry,
137 struct file *file, unsigned int open_flag,
138 umode_t create_mode)
140 return -EIO;
143 static int bad_inode_tmpfile(struct inode *inode, struct dentry *dentry,
144 umode_t mode)
146 return -EIO;
149 static int bad_inode_set_acl(struct inode *inode, struct posix_acl *acl,
150 int type)
152 return -EIO;
155 static const struct inode_operations bad_inode_ops =
157 .create = bad_inode_create,
158 .lookup = bad_inode_lookup,
159 .link = bad_inode_link,
160 .unlink = bad_inode_unlink,
161 .symlink = bad_inode_symlink,
162 .mkdir = bad_inode_mkdir,
163 .rmdir = bad_inode_rmdir,
164 .mknod = bad_inode_mknod,
165 .rename = bad_inode_rename2,
166 .readlink = bad_inode_readlink,
167 .permission = bad_inode_permission,
168 .getattr = bad_inode_getattr,
169 .setattr = bad_inode_setattr,
170 .listxattr = bad_inode_listxattr,
171 .get_link = bad_inode_get_link,
172 .get_acl = bad_inode_get_acl,
173 .fiemap = bad_inode_fiemap,
174 .update_time = bad_inode_update_time,
175 .atomic_open = bad_inode_atomic_open,
176 .tmpfile = bad_inode_tmpfile,
177 .set_acl = bad_inode_set_acl,
182 * When a filesystem is unable to read an inode due to an I/O error in
183 * its read_inode() function, it can call make_bad_inode() to return a
184 * set of stubs which will return EIO errors as required.
186 * We only need to do limited initialisation: all other fields are
187 * preinitialised to zero automatically.
191 * make_bad_inode - mark an inode bad due to an I/O error
192 * @inode: Inode to mark bad
194 * When an inode cannot be read due to a media or remote network
195 * failure this function makes the inode "bad" and causes I/O operations
196 * on it to fail from this point on.
199 void make_bad_inode(struct inode *inode)
201 remove_inode_hash(inode);
203 inode->i_mode = S_IFREG;
204 inode->i_atime = inode->i_mtime = inode->i_ctime =
205 current_time(inode);
206 inode->i_op = &bad_inode_ops;
207 inode->i_opflags &= ~IOP_XATTR;
208 inode->i_fop = &bad_file_ops;
210 EXPORT_SYMBOL(make_bad_inode);
213 * This tests whether an inode has been flagged as bad. The test uses
214 * &bad_inode_ops to cover the case of invalidated inodes as well as
215 * those created by make_bad_inode() above.
219 * is_bad_inode - is an inode errored
220 * @inode: inode to test
222 * Returns true if the inode in question has been marked as bad.
225 bool is_bad_inode(struct inode *inode)
227 return (inode->i_op == &bad_inode_ops);
230 EXPORT_SYMBOL(is_bad_inode);
233 * iget_failed - Mark an under-construction inode as dead and release it
234 * @inode: The inode to discard
236 * Mark an under-construction inode as dead and release it.
238 void iget_failed(struct inode *inode)
240 make_bad_inode(inode);
241 unlock_new_inode(inode);
242 iput(inode);
244 EXPORT_SYMBOL(iget_failed);