RHEL5/fs/bad_inode.c
<<
>>
Prefs
   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/module.h>
  13#include <linux/stat.h>
  14#include <linux/time.h>
  15#include <linux/smp_lock.h>
  16#include <linux/namei.h>
  17#include <linux/poll.h>
  18
  19
  20static loff_t bad_file_llseek(struct file *file, loff_t offset, int origin)
  21{
  22        return -EIO;
  23}
  24
  25static ssize_t bad_file_read(struct file *filp, char __user *buf,
  26                        size_t size, loff_t *ppos)
  27{
  28        return -EIO;
  29}
  30
  31static ssize_t bad_file_write(struct file *filp, const char __user *buf,
  32                        size_t siz, loff_t *ppos)
  33{
  34        return -EIO;
  35}
  36
  37static ssize_t bad_file_aio_read(struct kiocb *iocb, char __user *buf,
  38                        size_t count, loff_t pos)
  39{
  40        return -EIO;
  41}
  42
  43static ssize_t bad_file_aio_write(struct kiocb *iocb, const char __user *buf,
  44                        size_t count, loff_t pos)
  45{
  46        return -EIO;
  47}
  48
  49static int bad_file_readdir(struct file *filp, void *dirent, filldir_t filldir)
  50{
  51        return -EIO;
  52}
  53
  54static unsigned int bad_file_poll(struct file *filp, poll_table *wait)
  55{
  56        return POLLERR;
  57}
  58
  59static int bad_file_ioctl (struct inode *inode, struct file *filp,
  60                        unsigned int cmd, unsigned long arg)
  61{
  62        return -EIO;
  63}
  64
  65static long bad_file_unlocked_ioctl(struct file *file, unsigned cmd,
  66                        unsigned long arg)
  67{
  68        return -EIO;
  69}
  70
  71static long bad_file_compat_ioctl(struct file *file, unsigned int cmd,
  72                        unsigned long arg)
  73{
  74        return -EIO;
  75}
  76
  77static int bad_file_mmap(struct file *file, struct vm_area_struct *vma)
  78{
  79        return -EIO;
  80}
  81
  82static int bad_file_open(struct inode *inode, struct file *filp)
  83{
  84        return -EIO;
  85}
  86
  87static int bad_file_flush(struct file *file, fl_owner_t id)
  88{
  89        return -EIO;
  90}
  91
  92static int bad_file_release(struct inode *inode, struct file *filp)
  93{
  94        return -EIO;
  95}
  96
  97static int bad_file_fsync(struct file *file, struct dentry *dentry,
  98                        int datasync)
  99{
 100        return -EIO;
 101}
 102
 103static int bad_file_aio_fsync(struct kiocb *iocb, int datasync)
 104{
 105        return -EIO;
 106}
 107
 108static int bad_file_fasync(int fd, struct file *filp, int on)
 109{
 110        return -EIO;
 111}
 112
 113static int bad_file_lock(struct file *file, int cmd, struct file_lock *fl)
 114{
 115        return -EIO;
 116}
 117
 118static ssize_t bad_file_readv(struct file *filp, const struct iovec *iov,
 119                        unsigned long nr_segs, loff_t *ppos)
 120{
 121        return -EIO;
 122}
 123                        
 124static ssize_t bad_file_writev(struct file *filp, const struct iovec *iov,
 125                        unsigned long nr_segs, loff_t *ppos)
 126{
 127        return -EIO;
 128}
 129
 130static ssize_t bad_file_sendfile(struct file *in_file, loff_t *ppos,
 131                        size_t count, read_actor_t actor, void *target)
 132{
 133        return -EIO;
 134}
 135
 136static ssize_t bad_file_sendpage(struct file *file, struct page *page,
 137                        int off, size_t len, loff_t *pos, int more)
 138{
 139        return -EIO;
 140}
 141
 142static unsigned long bad_file_get_unmapped_area(struct file *file,
 143                                unsigned long addr, unsigned long len,
 144                                unsigned long pgoff, unsigned long flags)
 145{
 146        return -EIO;
 147}
 148
 149static int bad_file_check_flags(int flags)
 150{
 151        return -EIO;
 152}
 153
 154static int bad_file_dir_notify(struct file *file, unsigned long arg)
 155{
 156        return -EIO;
 157}
 158
 159static int bad_file_flock(struct file *filp, int cmd, struct file_lock *fl)
 160{
 161        return -EIO;
 162}
 163
 164static ssize_t bad_file_splice_write(struct pipe_inode_info *pipe,
 165                        struct file *out, loff_t *ppos, size_t len,
 166                        unsigned int flags)
 167{
 168        return -EIO;
 169}
 170
 171static ssize_t bad_file_splice_read(struct file *in, loff_t *ppos,
 172                        struct pipe_inode_info *pipe, size_t len,
 173                        unsigned int flags)
 174{
 175        return -EIO;
 176}
 177
 178static const struct file_operations bad_file_ops =
 179{
 180        .llseek         = bad_file_llseek,
 181        .read           = bad_file_read,
 182        .aio_read       = bad_file_aio_read,
 183        .write          = bad_file_write,
 184        .aio_write      = bad_file_aio_write,
 185        .readdir        = bad_file_readdir,
 186        .poll           = bad_file_poll,
 187        .ioctl          = bad_file_ioctl,
 188        .unlocked_ioctl = bad_file_unlocked_ioctl,
 189        .compat_ioctl   = bad_file_compat_ioctl,
 190        .mmap           = bad_file_mmap,
 191        .open           = bad_file_open,
 192        .flush          = bad_file_flush,
 193        .release        = bad_file_release,
 194        .fsync          = bad_file_fsync,
 195        .aio_fsync      = bad_file_aio_fsync,
 196        .fasync         = bad_file_fasync,
 197        .lock           = bad_file_lock,
 198        .readv          = bad_file_readv,
 199        .writev         = bad_file_writev,
 200        .sendfile       = bad_file_sendfile,
 201        .sendpage       = bad_file_sendpage,
 202        .get_unmapped_area = bad_file_get_unmapped_area,
 203        .check_flags    = bad_file_check_flags,
 204        .dir_notify     = bad_file_dir_notify,
 205        .flock          = bad_file_flock,
 206        .splice_write   = bad_file_splice_write,
 207        .splice_read    = bad_file_splice_read,
 208};
 209
 210static int bad_inode_create (struct inode *dir, struct dentry *dentry,
 211                int mode, struct nameidata *nd)
 212{
 213        return -EIO;
 214}
 215
 216static struct dentry *bad_inode_lookup(struct inode *dir,
 217                        struct dentry *dentry, struct nameidata *nd)
 218{
 219        return ERR_PTR(-EIO);
 220}
 221
 222static int bad_inode_link (struct dentry *old_dentry, struct inode *dir,
 223                struct dentry *dentry)
 224{
 225        return -EIO;
 226}
 227
 228static int bad_inode_unlink(struct inode *dir, struct dentry *dentry)
 229{
 230        return -EIO;
 231}
 232
 233static int bad_inode_symlink (struct inode *dir, struct dentry *dentry,
 234                const char *symname)
 235{
 236        return -EIO;
 237}
 238
 239static int bad_inode_mkdir(struct inode *dir, struct dentry *dentry,
 240                        int mode)
 241{
 242        return -EIO;
 243}
 244
 245static int bad_inode_rmdir (struct inode *dir, struct dentry *dentry)
 246{
 247        return -EIO;
 248}
 249
 250static int bad_inode_mknod (struct inode *dir, struct dentry *dentry,
 251                        int mode, dev_t rdev)
 252{
 253        return -EIO;
 254}
 255
 256static int bad_inode_rename (struct inode *old_dir, struct dentry *old_dentry,
 257                struct inode *new_dir, struct dentry *new_dentry)
 258{
 259        return -EIO;
 260}
 261
 262static int bad_inode_readlink(struct dentry *dentry, char __user *buffer,
 263                int buflen)
 264{
 265        return -EIO;
 266}
 267
 268static int bad_inode_permission(struct inode *inode, int mask,
 269                        struct nameidata *nd)
 270{
 271        return -EIO;
 272}
 273
 274static int bad_inode_getattr(struct vfsmount *mnt, struct dentry *dentry,
 275                        struct kstat *stat)
 276{
 277        return -EIO;
 278}
 279
 280static int bad_inode_setattr(struct dentry *direntry, struct iattr *attrs)
 281{
 282        return -EIO;
 283}
 284
 285static int bad_inode_setxattr(struct dentry *dentry, const char *name,
 286                const void *value, size_t size, int flags)
 287{
 288        return -EIO;
 289}
 290
 291static ssize_t bad_inode_getxattr(struct dentry *dentry, const char *name,
 292                        void *buffer, size_t size)
 293{
 294        return -EIO;
 295}
 296
 297static ssize_t bad_inode_listxattr(struct dentry *dentry, char *buffer,
 298                        size_t buffer_size)
 299{
 300        return -EIO;
 301}
 302
 303static int bad_inode_removexattr(struct dentry *dentry, const char *name)
 304{
 305        return -EIO;
 306}
 307
 308static struct inode_operations bad_inode_ops =
 309{
 310        .create         = bad_inode_create,
 311        .lookup         = bad_inode_lookup,
 312        .link           = bad_inode_link,
 313        .unlink         = bad_inode_unlink,
 314        .symlink        = bad_inode_symlink,
 315        .mkdir          = bad_inode_mkdir,
 316        .rmdir          = bad_inode_rmdir,
 317        .mknod          = bad_inode_mknod,
 318        .rename         = bad_inode_rename,
 319        .readlink       = bad_inode_readlink,
 320        /* follow_link must be no-op, otherwise unmounting this inode
 321           won't work */
 322        /* put_link returns void */
 323        /* truncate returns void */
 324        .permission     = bad_inode_permission,
 325        .getattr        = bad_inode_getattr,
 326        .setattr        = bad_inode_setattr,
 327        .setxattr       = bad_inode_setxattr,
 328        .getxattr       = bad_inode_getxattr,
 329        .listxattr      = bad_inode_listxattr,
 330        .removexattr    = bad_inode_removexattr,
 331        /* truncate_range returns void */
 332};
 333
 334
 335/*
 336 * When a filesystem is unable to read an inode due to an I/O error in
 337 * its read_inode() function, it can call make_bad_inode() to return a
 338 * set of stubs which will return EIO errors as required. 
 339 *
 340 * We only need to do limited initialisation: all other fields are
 341 * preinitialised to zero automatically.
 342 */
 343 
 344/**
 345 *      make_bad_inode - mark an inode bad due to an I/O error
 346 *      @inode: Inode to mark bad
 347 *
 348 *      When an inode cannot be read due to a media or remote network
 349 *      failure this function makes the inode "bad" and causes I/O operations
 350 *      on it to fail from this point on.
 351 */
 352 
 353void make_bad_inode(struct inode *inode) 
 354{
 355        remove_inode_hash(inode);
 356
 357        inode->i_mode = S_IFREG;
 358        inode->i_atime = inode->i_mtime = inode->i_ctime =
 359                current_fs_time(inode->i_sb);
 360        inode->i_op = &bad_inode_ops;   
 361        inode->i_fop = &bad_file_ops;   
 362}
 363EXPORT_SYMBOL(make_bad_inode);
 364
 365/*
 366 * This tests whether an inode has been flagged as bad. The test uses
 367 * &bad_inode_ops to cover the case of invalidated inodes as well as
 368 * those created by make_bad_inode() above.
 369 */
 370 
 371/**
 372 *      is_bad_inode - is an inode errored
 373 *      @inode: inode to test
 374 *
 375 *      Returns true if the inode in question has been marked as bad.
 376 */
 377 
 378int is_bad_inode(struct inode *inode) 
 379{
 380        return (inode->i_op == &bad_inode_ops); 
 381}
 382
 383EXPORT_SYMBOL(is_bad_inode);
 384