Back to home page

LXR

 
 

    


0001 /*
0002  *  linux/fs/bad_inode.c
0003  *
0004  *  Copyright (C) 1997, Stephen Tweedie
0005  *
0006  *  Provide stub functions for unreadable inodes
0007  *
0008  *  Fabian Frederick : August 2003 - All file operations assigned to EIO
0009  */
0010 
0011 #include <linux/fs.h>
0012 #include <linux/export.h>
0013 #include <linux/stat.h>
0014 #include <linux/time.h>
0015 #include <linux/namei.h>
0016 #include <linux/poll.h>
0017 
0018 static int bad_file_open(struct inode *inode, struct file *filp)
0019 {
0020     return -EIO;
0021 }
0022 
0023 static const struct file_operations bad_file_ops =
0024 {
0025     .open       = bad_file_open,
0026 };
0027 
0028 static int bad_inode_create (struct inode *dir, struct dentry *dentry,
0029         umode_t mode, bool excl)
0030 {
0031     return -EIO;
0032 }
0033 
0034 static struct dentry *bad_inode_lookup(struct inode *dir,
0035             struct dentry *dentry, unsigned int flags)
0036 {
0037     return ERR_PTR(-EIO);
0038 }
0039 
0040 static int bad_inode_link (struct dentry *old_dentry, struct inode *dir,
0041         struct dentry *dentry)
0042 {
0043     return -EIO;
0044 }
0045 
0046 static int bad_inode_unlink(struct inode *dir, struct dentry *dentry)
0047 {
0048     return -EIO;
0049 }
0050 
0051 static int bad_inode_symlink (struct inode *dir, struct dentry *dentry,
0052         const char *symname)
0053 {
0054     return -EIO;
0055 }
0056 
0057 static int bad_inode_mkdir(struct inode *dir, struct dentry *dentry,
0058             umode_t mode)
0059 {
0060     return -EIO;
0061 }
0062 
0063 static int bad_inode_rmdir (struct inode *dir, struct dentry *dentry)
0064 {
0065     return -EIO;
0066 }
0067 
0068 static int bad_inode_mknod (struct inode *dir, struct dentry *dentry,
0069             umode_t mode, dev_t rdev)
0070 {
0071     return -EIO;
0072 }
0073 
0074 static int bad_inode_rename2(struct inode *old_dir, struct dentry *old_dentry,
0075                  struct inode *new_dir, struct dentry *new_dentry,
0076                  unsigned int flags)
0077 {
0078     return -EIO;
0079 }
0080 
0081 static int bad_inode_readlink(struct dentry *dentry, char __user *buffer,
0082         int buflen)
0083 {
0084     return -EIO;
0085 }
0086 
0087 static int bad_inode_permission(struct inode *inode, int mask)
0088 {
0089     return -EIO;
0090 }
0091 
0092 static int bad_inode_getattr(struct vfsmount *mnt, struct dentry *dentry,
0093             struct kstat *stat)
0094 {
0095     return -EIO;
0096 }
0097 
0098 static int bad_inode_setattr(struct dentry *direntry, struct iattr *attrs)
0099 {
0100     return -EIO;
0101 }
0102 
0103 static ssize_t bad_inode_listxattr(struct dentry *dentry, char *buffer,
0104             size_t buffer_size)
0105 {
0106     return -EIO;
0107 }
0108 
0109 static const char *bad_inode_get_link(struct dentry *dentry,
0110                       struct inode *inode,
0111                       struct delayed_call *done)
0112 {
0113     return ERR_PTR(-EIO);
0114 }
0115 
0116 static struct posix_acl *bad_inode_get_acl(struct inode *inode, int type)
0117 {
0118     return ERR_PTR(-EIO);
0119 }
0120 
0121 static int bad_inode_fiemap(struct inode *inode,
0122                 struct fiemap_extent_info *fieinfo, u64 start,
0123                 u64 len)
0124 {
0125     return -EIO;
0126 }
0127 
0128 static int bad_inode_update_time(struct inode *inode, struct timespec *time,
0129                  int flags)
0130 {
0131     return -EIO;
0132 }
0133 
0134 static int bad_inode_atomic_open(struct inode *inode, struct dentry *dentry,
0135                  struct file *file, unsigned int open_flag,
0136                  umode_t create_mode, int *opened)
0137 {
0138     return -EIO;
0139 }
0140 
0141 static int bad_inode_tmpfile(struct inode *inode, struct dentry *dentry,
0142                  umode_t mode)
0143 {
0144     return -EIO;
0145 }
0146 
0147 static int bad_inode_set_acl(struct inode *inode, struct posix_acl *acl,
0148                  int type)
0149 {
0150     return -EIO;
0151 }
0152 
0153 static const struct inode_operations bad_inode_ops =
0154 {
0155     .create     = bad_inode_create,
0156     .lookup     = bad_inode_lookup,
0157     .link       = bad_inode_link,
0158     .unlink     = bad_inode_unlink,
0159     .symlink    = bad_inode_symlink,
0160     .mkdir      = bad_inode_mkdir,
0161     .rmdir      = bad_inode_rmdir,
0162     .mknod      = bad_inode_mknod,
0163     .rename     = bad_inode_rename2,
0164     .readlink   = bad_inode_readlink,
0165     .permission = bad_inode_permission,
0166     .getattr    = bad_inode_getattr,
0167     .setattr    = bad_inode_setattr,
0168     .listxattr  = bad_inode_listxattr,
0169     .get_link   = bad_inode_get_link,
0170     .get_acl    = bad_inode_get_acl,
0171     .fiemap     = bad_inode_fiemap,
0172     .update_time    = bad_inode_update_time,
0173     .atomic_open    = bad_inode_atomic_open,
0174     .tmpfile    = bad_inode_tmpfile,
0175     .set_acl    = bad_inode_set_acl,
0176 };
0177 
0178 
0179 /*
0180  * When a filesystem is unable to read an inode due to an I/O error in
0181  * its read_inode() function, it can call make_bad_inode() to return a
0182  * set of stubs which will return EIO errors as required. 
0183  *
0184  * We only need to do limited initialisation: all other fields are
0185  * preinitialised to zero automatically.
0186  */
0187  
0188 /**
0189  *  make_bad_inode - mark an inode bad due to an I/O error
0190  *  @inode: Inode to mark bad
0191  *
0192  *  When an inode cannot be read due to a media or remote network
0193  *  failure this function makes the inode "bad" and causes I/O operations
0194  *  on it to fail from this point on.
0195  */
0196  
0197 void make_bad_inode(struct inode *inode)
0198 {
0199     remove_inode_hash(inode);
0200 
0201     inode->i_mode = S_IFREG;
0202     inode->i_atime = inode->i_mtime = inode->i_ctime =
0203         current_time(inode);
0204     inode->i_op = &bad_inode_ops;   
0205     inode->i_opflags &= ~IOP_XATTR;
0206     inode->i_fop = &bad_file_ops;   
0207 }
0208 EXPORT_SYMBOL(make_bad_inode);
0209 
0210 /*
0211  * This tests whether an inode has been flagged as bad. The test uses
0212  * &bad_inode_ops to cover the case of invalidated inodes as well as
0213  * those created by make_bad_inode() above.
0214  */
0215  
0216 /**
0217  *  is_bad_inode - is an inode errored
0218  *  @inode: inode to test
0219  *
0220  *  Returns true if the inode in question has been marked as bad.
0221  */
0222  
0223 bool is_bad_inode(struct inode *inode)
0224 {
0225     return (inode->i_op == &bad_inode_ops); 
0226 }
0227 
0228 EXPORT_SYMBOL(is_bad_inode);
0229 
0230 /**
0231  * iget_failed - Mark an under-construction inode as dead and release it
0232  * @inode: The inode to discard
0233  *
0234  * Mark an under-construction inode as dead and release it.
0235  */
0236 void iget_failed(struct inode *inode)
0237 {
0238     make_bad_inode(inode);
0239     unlock_new_inode(inode);
0240     iput(inode);
0241 }
0242 EXPORT_SYMBOL(iget_failed);