PCI/PM: Resume device before shutdown
[linux-2.6/cjktty.git] / fs / bad_inode.c
blobb1342ffb3cf6e595125252ac82d5bd54ebbe9544
1 /*
2 * linux/fs/bad_inode.c
4 * Copyright (C) 1997, Stephen Tweedie
6 * Provide stub functions for unreadable inodes
8 * Fabian Frederick : August 2003 - All file operations assigned to EIO
9 */
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>
19 static loff_t bad_file_llseek(struct file *file, loff_t offset, int origin)
21 return -EIO;
24 static ssize_t bad_file_read(struct file *filp, char __user *buf,
25 size_t size, loff_t *ppos)
27 return -EIO;
30 static ssize_t bad_file_write(struct file *filp, const char __user *buf,
31 size_t siz, loff_t *ppos)
33 return -EIO;
36 static ssize_t bad_file_aio_read(struct kiocb *iocb, const struct iovec *iov,
37 unsigned long nr_segs, loff_t pos)
39 return -EIO;
42 static ssize_t bad_file_aio_write(struct kiocb *iocb, const struct iovec *iov,
43 unsigned long nr_segs, loff_t pos)
45 return -EIO;
48 static int bad_file_readdir(struct file *filp, void *dirent, filldir_t filldir)
50 return -EIO;
53 static unsigned int bad_file_poll(struct file *filp, poll_table *wait)
55 return POLLERR;
58 static long bad_file_unlocked_ioctl(struct file *file, unsigned cmd,
59 unsigned long arg)
61 return -EIO;
64 static long bad_file_compat_ioctl(struct file *file, unsigned int cmd,
65 unsigned long arg)
67 return -EIO;
70 static int bad_file_mmap(struct file *file, struct vm_area_struct *vma)
72 return -EIO;
75 static int bad_file_open(struct inode *inode, struct file *filp)
77 return -EIO;
80 static int bad_file_flush(struct file *file, fl_owner_t id)
82 return -EIO;
85 static int bad_file_release(struct inode *inode, struct file *filp)
87 return -EIO;
90 static int bad_file_fsync(struct file *file, loff_t start, loff_t end,
91 int datasync)
93 return -EIO;
96 static int bad_file_aio_fsync(struct kiocb *iocb, int datasync)
98 return -EIO;
101 static int bad_file_fasync(int fd, struct file *filp, int on)
103 return -EIO;
106 static int bad_file_lock(struct file *file, int cmd, struct file_lock *fl)
108 return -EIO;
111 static ssize_t bad_file_sendpage(struct file *file, struct page *page,
112 int off, size_t len, loff_t *pos, int more)
114 return -EIO;
117 static unsigned long bad_file_get_unmapped_area(struct file *file,
118 unsigned long addr, unsigned long len,
119 unsigned long pgoff, unsigned long flags)
121 return -EIO;
124 static int bad_file_check_flags(int flags)
126 return -EIO;
129 static int bad_file_flock(struct file *filp, int cmd, struct file_lock *fl)
131 return -EIO;
134 static ssize_t bad_file_splice_write(struct pipe_inode_info *pipe,
135 struct file *out, loff_t *ppos, size_t len,
136 unsigned int flags)
138 return -EIO;
141 static ssize_t bad_file_splice_read(struct file *in, loff_t *ppos,
142 struct pipe_inode_info *pipe, size_t len,
143 unsigned int flags)
145 return -EIO;
148 static const struct file_operations bad_file_ops =
150 .llseek = bad_file_llseek,
151 .read = bad_file_read,
152 .write = bad_file_write,
153 .aio_read = bad_file_aio_read,
154 .aio_write = bad_file_aio_write,
155 .readdir = bad_file_readdir,
156 .poll = bad_file_poll,
157 .unlocked_ioctl = bad_file_unlocked_ioctl,
158 .compat_ioctl = bad_file_compat_ioctl,
159 .mmap = bad_file_mmap,
160 .open = bad_file_open,
161 .flush = bad_file_flush,
162 .release = bad_file_release,
163 .fsync = bad_file_fsync,
164 .aio_fsync = bad_file_aio_fsync,
165 .fasync = bad_file_fasync,
166 .lock = bad_file_lock,
167 .sendpage = bad_file_sendpage,
168 .get_unmapped_area = bad_file_get_unmapped_area,
169 .check_flags = bad_file_check_flags,
170 .flock = bad_file_flock,
171 .splice_write = bad_file_splice_write,
172 .splice_read = bad_file_splice_read,
175 static int bad_inode_create (struct inode *dir, struct dentry *dentry,
176 umode_t mode, bool excl)
178 return -EIO;
181 static struct dentry *bad_inode_lookup(struct inode *dir,
182 struct dentry *dentry, unsigned int flags)
184 return ERR_PTR(-EIO);
187 static int bad_inode_link (struct dentry *old_dentry, struct inode *dir,
188 struct dentry *dentry)
190 return -EIO;
193 static int bad_inode_unlink(struct inode *dir, struct dentry *dentry)
195 return -EIO;
198 static int bad_inode_symlink (struct inode *dir, struct dentry *dentry,
199 const char *symname)
201 return -EIO;
204 static int bad_inode_mkdir(struct inode *dir, struct dentry *dentry,
205 umode_t mode)
207 return -EIO;
210 static int bad_inode_rmdir (struct inode *dir, struct dentry *dentry)
212 return -EIO;
215 static int bad_inode_mknod (struct inode *dir, struct dentry *dentry,
216 umode_t mode, dev_t rdev)
218 return -EIO;
221 static int bad_inode_rename (struct inode *old_dir, struct dentry *old_dentry,
222 struct inode *new_dir, struct dentry *new_dentry)
224 return -EIO;
227 static int bad_inode_readlink(struct dentry *dentry, char __user *buffer,
228 int buflen)
230 return -EIO;
233 static int bad_inode_permission(struct inode *inode, int mask)
235 return -EIO;
238 static int bad_inode_getattr(struct vfsmount *mnt, struct dentry *dentry,
239 struct kstat *stat)
241 return -EIO;
244 static int bad_inode_setattr(struct dentry *direntry, struct iattr *attrs)
246 return -EIO;
249 static int bad_inode_setxattr(struct dentry *dentry, const char *name,
250 const void *value, size_t size, int flags)
252 return -EIO;
255 static ssize_t bad_inode_getxattr(struct dentry *dentry, const char *name,
256 void *buffer, size_t size)
258 return -EIO;
261 static ssize_t bad_inode_listxattr(struct dentry *dentry, char *buffer,
262 size_t buffer_size)
264 return -EIO;
267 static int bad_inode_removexattr(struct dentry *dentry, const char *name)
269 return -EIO;
272 static const struct inode_operations bad_inode_ops =
274 .create = bad_inode_create,
275 .lookup = bad_inode_lookup,
276 .link = bad_inode_link,
277 .unlink = bad_inode_unlink,
278 .symlink = bad_inode_symlink,
279 .mkdir = bad_inode_mkdir,
280 .rmdir = bad_inode_rmdir,
281 .mknod = bad_inode_mknod,
282 .rename = bad_inode_rename,
283 .readlink = bad_inode_readlink,
284 /* follow_link must be no-op, otherwise unmounting this inode
285 won't work */
286 /* put_link returns void */
287 /* truncate returns void */
288 .permission = bad_inode_permission,
289 .getattr = bad_inode_getattr,
290 .setattr = bad_inode_setattr,
291 .setxattr = bad_inode_setxattr,
292 .getxattr = bad_inode_getxattr,
293 .listxattr = bad_inode_listxattr,
294 .removexattr = bad_inode_removexattr,
299 * When a filesystem is unable to read an inode due to an I/O error in
300 * its read_inode() function, it can call make_bad_inode() to return a
301 * set of stubs which will return EIO errors as required.
303 * We only need to do limited initialisation: all other fields are
304 * preinitialised to zero automatically.
308 * make_bad_inode - mark an inode bad due to an I/O error
309 * @inode: Inode to mark bad
311 * When an inode cannot be read due to a media or remote network
312 * failure this function makes the inode "bad" and causes I/O operations
313 * on it to fail from this point on.
316 void make_bad_inode(struct inode *inode)
318 remove_inode_hash(inode);
320 inode->i_mode = S_IFREG;
321 inode->i_atime = inode->i_mtime = inode->i_ctime =
322 current_fs_time(inode->i_sb);
323 inode->i_op = &bad_inode_ops;
324 inode->i_fop = &bad_file_ops;
326 EXPORT_SYMBOL(make_bad_inode);
329 * This tests whether an inode has been flagged as bad. The test uses
330 * &bad_inode_ops to cover the case of invalidated inodes as well as
331 * those created by make_bad_inode() above.
335 * is_bad_inode - is an inode errored
336 * @inode: inode to test
338 * Returns true if the inode in question has been marked as bad.
341 int is_bad_inode(struct inode *inode)
343 return (inode->i_op == &bad_inode_ops);
346 EXPORT_SYMBOL(is_bad_inode);
349 * iget_failed - Mark an under-construction inode as dead and release it
350 * @inode: The inode to discard
352 * Mark an under-construction inode as dead and release it.
354 void iget_failed(struct inode *inode)
356 make_bad_inode(inode);
357 unlock_new_inode(inode);
358 iput(inode);
360 EXPORT_SYMBOL(iget_failed);