linux-old/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
   9#include <linux/fs.h>
  10#include <linux/stat.h>
  11#include <linux/sched.h>
  12
  13/*
  14 * The follow_link operation is special: it must behave as a no-op
  15 * so that a bad root inode can at least be unmounted. To do this
  16 * we must dput() the base and return the dentry with a dget().
  17 */
  18static struct dentry * bad_follow_link(struct dentry *dent, struct dentry *base, unsigned int follow)
  19{
  20        dput(base);
  21        return dget(dent);
  22}
  23
  24static int return_EIO(void)
  25{
  26        return -EIO;
  27}
  28
  29#define EIO_ERROR ((void *) (return_EIO))
  30
  31static struct file_operations bad_file_ops =
  32{
  33        EIO_ERROR,              /* lseek */
  34        EIO_ERROR,              /* read */
  35        EIO_ERROR,              /* write */
  36        EIO_ERROR,              /* readdir */
  37        EIO_ERROR,              /* select */
  38        EIO_ERROR,              /* ioctl */
  39        EIO_ERROR,              /* mmap */
  40        EIO_ERROR,              /* open */
  41        EIO_ERROR,              /* flush */
  42        EIO_ERROR,              /* release */
  43        EIO_ERROR,              /* fsync */
  44        EIO_ERROR,              /* fasync */
  45        EIO_ERROR,              /* check_media_change */
  46        EIO_ERROR               /* revalidate */
  47};
  48
  49struct inode_operations bad_inode_ops =
  50{
  51        &bad_file_ops,          /* default file operations */
  52        EIO_ERROR,              /* create */
  53        EIO_ERROR,              /* lookup */
  54        EIO_ERROR,              /* link */
  55        EIO_ERROR,              /* unlink */
  56        EIO_ERROR,              /* symlink */
  57        EIO_ERROR,              /* mkdir */
  58        EIO_ERROR,              /* rmdir */
  59        EIO_ERROR,              /* mknod */
  60        EIO_ERROR,              /* rename */
  61        EIO_ERROR,              /* readlink */
  62        bad_follow_link,        /* follow_link */
  63        EIO_ERROR,              /* readpage */
  64        EIO_ERROR,              /* writepage */
  65        EIO_ERROR,              /* bmap */
  66        EIO_ERROR,              /* truncate */
  67        EIO_ERROR,              /* permission */
  68        EIO_ERROR,              /* smap */
  69        EIO_ERROR,              /* update_page */
  70        EIO_ERROR               /* revalidate */
  71};
  72
  73
  74/* 
  75 * When a filesystem is unable to read an inode due to an I/O error in
  76 * its read_inode() function, it can call make_bad_inode() to return a
  77 * set of stubs which will return EIO errors as required. 
  78 *
  79 * We only need to do limited initialisation: all other fields are
  80 * preinitialised to zero automatically.
  81 */
  82void make_bad_inode(struct inode * inode) 
  83{
  84        inode->i_mode = S_IFREG;
  85        inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
  86        inode->i_op = &bad_inode_ops;   
  87}
  88
  89/*
  90 * This tests whether an inode has been flagged as bad. The test uses
  91 * &bad_inode_ops to cover the case of invalidated inodes as well as
  92 * those created by make_bad_inode() above.
  93 */
  94int is_bad_inode(struct inode * inode) 
  95{
  96        return (inode->i_op == &bad_inode_ops); 
  97}
  98
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.