root/fs/nfs/inode.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. nfs_put_inode
  2. nfs_put_super
  3. nfs_read_super
  4. nfs_statfs
  5. nfs_fhget
  6. nfs_notify_change

   1 /*
   2  *  linux/fs/nfs/inode.c
   3  *
   4  *  Copyright (C) 1992  Rick Sladkey
   5  *
   6  *  nfs inode and superblock handling functions
   7  */
   8 
   9 #include <asm/system.h>
  10 #include <asm/segment.h>
  11 
  12 #include <linux/sched.h>
  13 #include <linux/nfs_fs.h>
  14 #include <linux/kernel.h>
  15 #include <linux/mm.h>
  16 #include <linux/string.h>
  17 #include <linux/stat.h>
  18 #include <linux/errno.h>
  19 #include <linux/locks.h>
  20 
  21 extern int close_fp(struct file *filp);
  22 
  23 static int nfs_notify_change(int, struct inode *);
  24 static void nfs_put_inode(struct inode *);
  25 static void nfs_put_super(struct super_block *);
  26 static void nfs_statfs(struct super_block *, struct statfs *);
  27 
  28 static struct super_operations nfs_sops = { 
  29         NULL,                   /* read inode */
  30         nfs_notify_change,      /* notify change */
  31         NULL,                   /* write inode */
  32         nfs_put_inode,          /* put inode */
  33         nfs_put_super,          /* put superblock */
  34         NULL,                   /* write superblock */
  35         nfs_statfs              /* stat filesystem */
  36 };
  37 
  38 static void nfs_put_inode(struct inode * inode)
     /* [previous][next][first][last][top][bottom][index][help] */
  39 {
  40         clear_inode(inode);
  41 }
  42 
  43 void nfs_put_super(struct super_block *sb)
     /* [previous][next][first][last][top][bottom][index][help] */
  44 {
  45         close_fp(sb->u.nfs_sb.s_server.file);
  46         lock_super(sb);
  47         sb->s_dev = 0;
  48         unlock_super(sb);
  49 }
  50 
  51 /*
  52  * The way this works is that the mount process passes a structure
  53  * in the data argument which contains an open socket to the NFS
  54  * server and the root file handle obtained from the server's mount
  55  * daemon.  We stash theses away in the private superblock fields.
  56  * Later we can add other mount parameters like caching values.
  57  */
  58 
  59 struct super_block *nfs_read_super(struct super_block *sb, void *raw_data,
     /* [previous][next][first][last][top][bottom][index][help] */
  60                                    int silent)
  61 {
  62         struct nfs_mount_data *data = (struct nfs_mount_data *) raw_data;
  63         struct nfs_server *server;
  64         unsigned int fd;
  65         struct file *filp;
  66         dev_t dev = sb->s_dev;
  67 
  68         if (!data) {
  69                 printk("nfs_read_super: missing data argument\n");
  70                 sb->s_dev = 0;
  71                 return NULL;
  72         }
  73         fd = data->fd;
  74         if (data->version != NFS_MOUNT_VERSION) {
  75                 printk("nfs warning: mount version %s than kernel\n",
  76                         data->version < NFS_MOUNT_VERSION ? "older" : "newer");
  77         }
  78         if (fd >= NR_OPEN || !(filp = current->filp[fd])) {
  79                 printk("nfs_read_super: invalid file descriptor\n");
  80                 sb->s_dev = 0;
  81                 return NULL;
  82         }
  83         if (!S_ISSOCK(filp->f_inode->i_mode)) {
  84                 printk("nfs_read_super: not a socket\n");
  85                 sb->s_dev = 0;
  86                 return NULL;
  87         }
  88         filp->f_count++;
  89         lock_super(sb);
  90         sb->s_blocksize = 1024; /* XXX */
  91         sb->s_magic = NFS_SUPER_MAGIC;
  92         sb->s_dev = dev;
  93         sb->s_op = &nfs_sops;
  94         server = &sb->u.nfs_sb.s_server;
  95         server->file = filp;
  96         server->lock = 0;
  97         server->wait = NULL;
  98         server->flags = data->flags;
  99         server->rsize = data->rsize;
 100         if (server->rsize <= 0)
 101                 server->rsize = NFS_DEF_FILE_IO_BUFFER_SIZE;
 102         else if (server->rsize >= NFS_MAX_FILE_IO_BUFFER_SIZE)
 103                 server->rsize = NFS_MAX_FILE_IO_BUFFER_SIZE;
 104         server->wsize = data->wsize;
 105         if (server->wsize <= 0)
 106                 server->wsize = NFS_DEF_FILE_IO_BUFFER_SIZE;
 107         else if (server->wsize >= NFS_MAX_FILE_IO_BUFFER_SIZE)
 108                 server->wsize = NFS_MAX_FILE_IO_BUFFER_SIZE;
 109         server->timeo = data->timeo*HZ/10;
 110         server->retrans = data->retrans;
 111         server->acregmin = data->acregmin*HZ;
 112         server->acregmax = data->acregmax*HZ;
 113         server->acdirmin = data->acdirmin*HZ;
 114         server->acdirmax = data->acdirmax*HZ;
 115         strcpy(server->hostname, data->hostname);
 116         sb->u.nfs_sb.s_root = data->root;
 117         unlock_super(sb);
 118         if (!(sb->s_mounted = nfs_fhget(sb, &data->root, NULL))) {
 119                 sb->s_dev = 0;
 120                 printk("nfs_read_super: get root inode failed\n");
 121                 return NULL;
 122         }
 123         return sb;
 124 }
 125 
 126 void nfs_statfs(struct super_block *sb, struct statfs *buf)
     /* [previous][next][first][last][top][bottom][index][help] */
 127 {
 128         int error;
 129         struct nfs_fsinfo res;
 130 
 131         put_fs_long(NFS_SUPER_MAGIC, &buf->f_type);
 132         error = nfs_proc_statfs(&sb->u.nfs_sb.s_server, &sb->u.nfs_sb.s_root,
 133                 &res);
 134         if (error) {
 135                 printk("nfs_statfs: statfs error = %d\n", -error);
 136                 res.bsize = res.blocks = res.bfree = res.bavail = 0;
 137         }
 138         put_fs_long(res.bsize, &buf->f_bsize);
 139         put_fs_long(res.blocks, &buf->f_blocks);
 140         put_fs_long(res.bfree, &buf->f_bfree);
 141         put_fs_long(res.bavail, &buf->f_bavail);
 142         put_fs_long(0, &buf->f_files);
 143         put_fs_long(0, &buf->f_ffree);
 144         /* We should really try to interrogate the remote server to find
 145            it's maximum name length here */
 146         put_fs_long(NAME_MAX, &buf->f_namelen);
 147 }
 148 
 149 /*
 150  * This is our own version of iget that looks up inodes by file handle
 151  * instead of inode number.  We use this technique instead of using
 152  * the vfs read_inode function because there is no way to pass the
 153  * file handle or current attributes into the read_inode function.
 154  * We just have to be careful not to subvert iget's special handling
 155  * of mount points.
 156  */
 157 
 158 struct inode *nfs_fhget(struct super_block *sb, struct nfs_fh *fhandle,
     /* [previous][next][first][last][top][bottom][index][help] */
 159                         struct nfs_fattr *fattr)
 160 {
 161         struct nfs_fattr newfattr;
 162         int error;
 163         struct inode *inode;
 164 
 165         if (!sb) {
 166                 printk("nfs_fhget: super block is NULL\n");
 167                 return NULL;
 168         }
 169         if (!fattr) {
 170                 error = nfs_proc_getattr(&sb->u.nfs_sb.s_server, fhandle,
 171                         &newfattr);
 172                 if (error) {
 173                         printk("nfs_fhget: getattr error = %d\n", -error);
 174                         return NULL;
 175                 }
 176                 fattr = &newfattr;
 177         }
 178         if (!(inode = iget(sb, fattr->fileid))) {
 179                 printk("nfs_fhget: iget failed\n");
 180                 return NULL;
 181         }
 182         if (inode->i_dev == sb->s_dev) {
 183                 if (inode->i_ino != fattr->fileid) {
 184                         printk("nfs_fhget: unexpected inode from iget\n");
 185                         return inode;
 186                 }
 187                 *NFS_FH(inode) = *fhandle;
 188                 nfs_refresh_inode(inode, fattr);
 189         }
 190         return inode;
 191 }
 192 
 193 int nfs_notify_change(int flags, struct inode *inode)
     /* [previous][next][first][last][top][bottom][index][help] */
 194 {
 195         struct nfs_sattr sattr;
 196         struct nfs_fattr fattr;
 197         int error;
 198 
 199         if (flags & NOTIFY_MODE)
 200                 sattr.mode = inode->i_mode;
 201         else
 202                 sattr.mode = -1;
 203         if (flags & NOTIFY_UIDGID) {
 204                 sattr.uid = inode->i_uid;
 205                 sattr.gid = inode->i_gid;
 206         }
 207         else
 208                 sattr.uid = sattr.gid = -1;
 209         if (flags & NOTIFY_SIZE)
 210                 sattr.size = S_ISREG(inode->i_mode) ? inode->i_size : -1;
 211         else
 212                 sattr.size = -1;
 213         if (flags & NOTIFY_TIME) {
 214                 sattr.mtime.seconds = inode->i_mtime;
 215                 sattr.mtime.useconds = 0;
 216                 sattr.atime.seconds = inode->i_atime;
 217                 sattr.atime.useconds = 0;
 218         }
 219         else {
 220                 sattr.mtime.seconds = sattr.mtime.useconds = -1;
 221                 sattr.atime.seconds = sattr.atime.useconds = -1;
 222         }
 223         error = nfs_proc_setattr(NFS_SERVER(inode), NFS_FH(inode),
 224                 &sattr, &fattr);
 225         if (!error)
 226                 nfs_refresh_inode(inode, &fattr);
 227         inode->i_dirt = 0;
 228         return error;
 229 }
 230 

/* [previous][next][first][last][top][bottom][index][help] */