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

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