Linux Audio

Check our new training course

Loading...
v6.9.4
  1// SPDX-License-Identifier: GPL-2.0
  2/*
  3 *  linux/fs/bad_inode.c
  4 *
  5 *  Copyright (C) 1997, Stephen Tweedie
  6 *
  7 *  Provide stub functions for unreadable inodes
  8 *
  9 *  Fabian Frederick : August 2003 - All file operations assigned to EIO
 10 */
 11
 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>
 19
 20static int bad_file_open(struct inode *inode, struct file *filp)
 21{
 22	return -EIO;
 23}
 24
 25static const struct file_operations bad_file_ops =
 26{
 27	.open		= bad_file_open,
 28};
 29
 30static int bad_inode_create(struct mnt_idmap *idmap,
 31			    struct inode *dir, struct dentry *dentry,
 32			    umode_t mode, bool excl)
 33{
 34	return -EIO;
 35}
 36
 37static struct dentry *bad_inode_lookup(struct inode *dir,
 38			struct dentry *dentry, unsigned int flags)
 39{
 40	return ERR_PTR(-EIO);
 41}
 42
 43static int bad_inode_link (struct dentry *old_dentry, struct inode *dir,
 44		struct dentry *dentry)
 45{
 46	return -EIO;
 47}
 48
 49static int bad_inode_unlink(struct inode *dir, struct dentry *dentry)
 50{
 51	return -EIO;
 52}
 53
 54static int bad_inode_symlink(struct mnt_idmap *idmap,
 55			     struct inode *dir, struct dentry *dentry,
 56			     const char *symname)
 57{
 58	return -EIO;
 59}
 60
 61static int bad_inode_mkdir(struct mnt_idmap *idmap, struct inode *dir,
 62			   struct dentry *dentry, umode_t mode)
 63{
 64	return -EIO;
 65}
 66
 67static int bad_inode_rmdir (struct inode *dir, struct dentry *dentry)
 68{
 69	return -EIO;
 70}
 71
 72static int bad_inode_mknod(struct mnt_idmap *idmap, struct inode *dir,
 73			   struct dentry *dentry, umode_t mode, dev_t rdev)
 74{
 75	return -EIO;
 76}
 77
 78static int bad_inode_rename2(struct mnt_idmap *idmap,
 79			     struct inode *old_dir, struct dentry *old_dentry,
 80			     struct inode *new_dir, struct dentry *new_dentry,
 81			     unsigned int flags)
 82{
 83	return -EIO;
 84}
 85
 86static int bad_inode_readlink(struct dentry *dentry, char __user *buffer,
 87		int buflen)
 88{
 89	return -EIO;
 90}
 91
 92static int bad_inode_permission(struct mnt_idmap *idmap,
 93				struct inode *inode, int mask)
 94{
 95	return -EIO;
 96}
 97
 98static int bad_inode_getattr(struct mnt_idmap *idmap,
 99			     const struct path *path, struct kstat *stat,
100			     u32 request_mask, unsigned int query_flags)
101{
102	return -EIO;
103}
104
105static int bad_inode_setattr(struct mnt_idmap *idmap,
106			     struct dentry *direntry, struct iattr *attrs)
107{
108	return -EIO;
109}
110
111static ssize_t bad_inode_listxattr(struct dentry *dentry, char *buffer,
112			size_t buffer_size)
113{
114	return -EIO;
115}
116
117static const char *bad_inode_get_link(struct dentry *dentry,
118				      struct inode *inode,
119				      struct delayed_call *done)
120{
121	return ERR_PTR(-EIO);
122}
123
124static struct posix_acl *bad_inode_get_acl(struct inode *inode, int type, bool rcu)
125{
126	return ERR_PTR(-EIO);
127}
128
129static int bad_inode_fiemap(struct inode *inode,
130			    struct fiemap_extent_info *fieinfo, u64 start,
131			    u64 len)
132{
133	return -EIO;
134}
135
136static int bad_inode_update_time(struct inode *inode, int flags)
137{
138	return -EIO;
139}
140
141static int bad_inode_atomic_open(struct inode *inode, struct dentry *dentry,
142				 struct file *file, unsigned int open_flag,
143				 umode_t create_mode)
144{
145	return -EIO;
146}
147
148static int bad_inode_tmpfile(struct mnt_idmap *idmap,
149			     struct inode *inode, struct file *file,
150			     umode_t mode)
151{
152	return -EIO;
153}
154
155static int bad_inode_set_acl(struct mnt_idmap *idmap,
156			     struct dentry *dentry, struct posix_acl *acl,
157			     int type)
158{
159	return -EIO;
160}
161
162static const struct inode_operations bad_inode_ops =
163{
164	.create		= bad_inode_create,
165	.lookup		= bad_inode_lookup,
166	.link		= bad_inode_link,
167	.unlink		= bad_inode_unlink,
168	.symlink	= bad_inode_symlink,
169	.mkdir		= bad_inode_mkdir,
170	.rmdir		= bad_inode_rmdir,
171	.mknod		= bad_inode_mknod,
172	.rename		= bad_inode_rename2,
173	.readlink	= bad_inode_readlink,
 
 
 
 
174	.permission	= bad_inode_permission,
175	.getattr	= bad_inode_getattr,
176	.setattr	= bad_inode_setattr,
 
 
177	.listxattr	= bad_inode_listxattr,
178	.get_link	= bad_inode_get_link,
179	.get_inode_acl	= bad_inode_get_acl,
180	.fiemap		= bad_inode_fiemap,
181	.update_time	= bad_inode_update_time,
182	.atomic_open	= bad_inode_atomic_open,
183	.tmpfile	= bad_inode_tmpfile,
184	.set_acl	= bad_inode_set_acl,
185};
186
187
188/*
189 * When a filesystem is unable to read an inode due to an I/O error in
190 * its read_inode() function, it can call make_bad_inode() to return a
191 * set of stubs which will return EIO errors as required. 
192 *
193 * We only need to do limited initialisation: all other fields are
194 * preinitialised to zero automatically.
195 */
196 
197/**
198 *	make_bad_inode - mark an inode bad due to an I/O error
199 *	@inode: Inode to mark bad
200 *
201 *	When an inode cannot be read due to a media or remote network
202 *	failure this function makes the inode "bad" and causes I/O operations
203 *	on it to fail from this point on.
204 */
205 
206void make_bad_inode(struct inode *inode)
207{
208	remove_inode_hash(inode);
209
210	inode->i_mode = S_IFREG;
211	simple_inode_init_ts(inode);
 
212	inode->i_op = &bad_inode_ops;	
213	inode->i_opflags &= ~IOP_XATTR;
214	inode->i_fop = &bad_file_ops;	
215}
216EXPORT_SYMBOL(make_bad_inode);
217
218/*
219 * This tests whether an inode has been flagged as bad. The test uses
220 * &bad_inode_ops to cover the case of invalidated inodes as well as
221 * those created by make_bad_inode() above.
222 */
223 
224/**
225 *	is_bad_inode - is an inode errored
226 *	@inode: inode to test
227 *
228 *	Returns true if the inode in question has been marked as bad.
229 */
230 
231bool is_bad_inode(struct inode *inode)
232{
233	return (inode->i_op == &bad_inode_ops);	
234}
235
236EXPORT_SYMBOL(is_bad_inode);
237
238/**
239 * iget_failed - Mark an under-construction inode as dead and release it
240 * @inode: The inode to discard
241 *
242 * Mark an under-construction inode as dead and release it.
243 */
244void iget_failed(struct inode *inode)
245{
246	make_bad_inode(inode);
247	unlock_new_inode(inode);
248	iput(inode);
249}
250EXPORT_SYMBOL(iget_failed);
v4.6
 
  1/*
  2 *  linux/fs/bad_inode.c
  3 *
  4 *  Copyright (C) 1997, Stephen Tweedie
  5 *
  6 *  Provide stub functions for unreadable inodes
  7 *
  8 *  Fabian Frederick : August 2003 - All file operations assigned to EIO
  9 */
 10
 11#include <linux/fs.h>
 12#include <linux/export.h>
 13#include <linux/stat.h>
 14#include <linux/time.h>
 15#include <linux/namei.h>
 16#include <linux/poll.h>
 
 17
 18static int bad_file_open(struct inode *inode, struct file *filp)
 19{
 20	return -EIO;
 21}
 22
 23static const struct file_operations bad_file_ops =
 24{
 25	.open		= bad_file_open,
 26};
 27
 28static int bad_inode_create (struct inode *dir, struct dentry *dentry,
 29		umode_t mode, bool excl)
 
 30{
 31	return -EIO;
 32}
 33
 34static struct dentry *bad_inode_lookup(struct inode *dir,
 35			struct dentry *dentry, unsigned int flags)
 36{
 37	return ERR_PTR(-EIO);
 38}
 39
 40static int bad_inode_link (struct dentry *old_dentry, struct inode *dir,
 41		struct dentry *dentry)
 42{
 43	return -EIO;
 44}
 45
 46static int bad_inode_unlink(struct inode *dir, struct dentry *dentry)
 47{
 48	return -EIO;
 49}
 50
 51static int bad_inode_symlink (struct inode *dir, struct dentry *dentry,
 52		const char *symname)
 
 53{
 54	return -EIO;
 55}
 56
 57static int bad_inode_mkdir(struct inode *dir, struct dentry *dentry,
 58			umode_t mode)
 59{
 60	return -EIO;
 61}
 62
 63static int bad_inode_rmdir (struct inode *dir, struct dentry *dentry)
 64{
 65	return -EIO;
 66}
 67
 68static int bad_inode_mknod (struct inode *dir, struct dentry *dentry,
 69			umode_t mode, dev_t rdev)
 70{
 71	return -EIO;
 72}
 73
 74static int bad_inode_rename2(struct inode *old_dir, struct dentry *old_dentry,
 
 75			     struct inode *new_dir, struct dentry *new_dentry,
 76			     unsigned int flags)
 77{
 78	return -EIO;
 79}
 80
 81static int bad_inode_readlink(struct dentry *dentry, char __user *buffer,
 82		int buflen)
 83{
 84	return -EIO;
 85}
 86
 87static int bad_inode_permission(struct inode *inode, int mask)
 
 88{
 89	return -EIO;
 90}
 91
 92static int bad_inode_getattr(struct vfsmount *mnt, struct dentry *dentry,
 93			struct kstat *stat)
 
 94{
 95	return -EIO;
 96}
 97
 98static int bad_inode_setattr(struct dentry *direntry, struct iattr *attrs)
 
 99{
100	return -EIO;
101}
102
103static int bad_inode_setxattr(struct dentry *dentry, const char *name,
104		const void *value, size_t size, int flags)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
105{
106	return -EIO;
107}
108
109static ssize_t bad_inode_getxattr(struct dentry *dentry, const char *name,
110			void *buffer, size_t size)
 
111{
112	return -EIO;
113}
114
115static ssize_t bad_inode_listxattr(struct dentry *dentry, char *buffer,
116			size_t buffer_size)
 
117{
118	return -EIO;
119}
120
121static int bad_inode_removexattr(struct dentry *dentry, const char *name)
 
 
122{
123	return -EIO;
124}
125
126static const struct inode_operations bad_inode_ops =
127{
128	.create		= bad_inode_create,
129	.lookup		= bad_inode_lookup,
130	.link		= bad_inode_link,
131	.unlink		= bad_inode_unlink,
132	.symlink	= bad_inode_symlink,
133	.mkdir		= bad_inode_mkdir,
134	.rmdir		= bad_inode_rmdir,
135	.mknod		= bad_inode_mknod,
136	.rename2	= bad_inode_rename2,
137	.readlink	= bad_inode_readlink,
138	/* follow_link must be no-op, otherwise unmounting this inode
139	   won't work */
140	/* put_link returns void */
141	/* truncate returns void */
142	.permission	= bad_inode_permission,
143	.getattr	= bad_inode_getattr,
144	.setattr	= bad_inode_setattr,
145	.setxattr	= bad_inode_setxattr,
146	.getxattr	= bad_inode_getxattr,
147	.listxattr	= bad_inode_listxattr,
148	.removexattr	= bad_inode_removexattr,
 
 
 
 
 
 
149};
150
151
152/*
153 * When a filesystem is unable to read an inode due to an I/O error in
154 * its read_inode() function, it can call make_bad_inode() to return a
155 * set of stubs which will return EIO errors as required. 
156 *
157 * We only need to do limited initialisation: all other fields are
158 * preinitialised to zero automatically.
159 */
160 
161/**
162 *	make_bad_inode - mark an inode bad due to an I/O error
163 *	@inode: Inode to mark bad
164 *
165 *	When an inode cannot be read due to a media or remote network
166 *	failure this function makes the inode "bad" and causes I/O operations
167 *	on it to fail from this point on.
168 */
169 
170void make_bad_inode(struct inode *inode)
171{
172	remove_inode_hash(inode);
173
174	inode->i_mode = S_IFREG;
175	inode->i_atime = inode->i_mtime = inode->i_ctime =
176		current_fs_time(inode->i_sb);
177	inode->i_op = &bad_inode_ops;	
 
178	inode->i_fop = &bad_file_ops;	
179}
180EXPORT_SYMBOL(make_bad_inode);
181
182/*
183 * This tests whether an inode has been flagged as bad. The test uses
184 * &bad_inode_ops to cover the case of invalidated inodes as well as
185 * those created by make_bad_inode() above.
186 */
187 
188/**
189 *	is_bad_inode - is an inode errored
190 *	@inode: inode to test
191 *
192 *	Returns true if the inode in question has been marked as bad.
193 */
194 
195bool is_bad_inode(struct inode *inode)
196{
197	return (inode->i_op == &bad_inode_ops);	
198}
199
200EXPORT_SYMBOL(is_bad_inode);
201
202/**
203 * iget_failed - Mark an under-construction inode as dead and release it
204 * @inode: The inode to discard
205 *
206 * Mark an under-construction inode as dead and release it.
207 */
208void iget_failed(struct inode *inode)
209{
210	make_bad_inode(inode);
211	unlock_new_inode(inode);
212	iput(inode);
213}
214EXPORT_SYMBOL(iget_failed);