root/fs/nfs/symlink.c

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

DEFINITIONS

This source file includes following definitions.
  1. nfs_follow_link
  2. nfs_readlink

   1 /*
   2  *  linux/fs/nfs/symlink.c
   3  *
   4  *  Copyright (C) 1992  Rick Sladkey
   5  *
   6  *  Optimization changes Copyright (C) 1994 Florian La Roche
   7  *
   8  *  nfs symlink handling code
   9  */
  10 
  11 #include <linux/sched.h>
  12 #include <linux/errno.h>
  13 #include <linux/nfs_fs.h>
  14 #include <linux/stat.h>
  15 #include <linux/mm.h>
  16 #include <linux/malloc.h>
  17 #include <linux/string.h>
  18 
  19 #include <asm/segment.h>
  20 
  21 static int nfs_readlink(struct inode *, char *, int);
  22 static int nfs_follow_link(struct inode *, struct inode *, int, int,
  23                            struct inode **);
  24 
  25 /*
  26  * symlinks can't do much...
  27  */
  28 struct inode_operations nfs_symlink_inode_operations = {
  29         NULL,                   /* no file-operations */
  30         NULL,                   /* create */
  31         NULL,                   /* lookup */
  32         NULL,                   /* link */
  33         NULL,                   /* unlink */
  34         NULL,                   /* symlink */
  35         NULL,                   /* mkdir */
  36         NULL,                   /* rmdir */
  37         NULL,                   /* mknod */
  38         NULL,                   /* rename */
  39         nfs_readlink,           /* readlink */
  40         nfs_follow_link,        /* follow_link */
  41         NULL,                   /* readpage */
  42         NULL,                   /* writepage */
  43         NULL,                   /* bmap */
  44         NULL,                   /* truncate */
  45         NULL                    /* permission */
  46 };
  47 
  48 static int nfs_follow_link(struct inode *dir, struct inode *inode,
     /* [previous][next][first][last][top][bottom][index][help] */
  49                            int flag, int mode, struct inode **res_inode)
  50 {
  51         int error, *mem;
  52         unsigned int len;
  53         char *res, *res2;
  54 
  55         *res_inode = NULL;
  56         if (!dir) {
  57                 dir = current->fs->root;
  58                 dir->i_count++;
  59         }
  60         if (!inode) {
  61                 iput(dir);
  62                 return -ENOENT;
  63         }
  64         if (!S_ISLNK(inode->i_mode)) {
  65                 iput(dir);
  66                 *res_inode = inode;
  67                 return 0;
  68         }
  69         if (current->link_count > 5) {
  70                 iput(inode);
  71                 iput(dir);
  72                 return -ELOOP;
  73         }
  74         error = nfs_proc_readlink(NFS_SERVER(inode), NFS_FH(inode), &mem,
  75                 &res, &len, NFS_MAXPATHLEN);
  76         if (error) {
  77                 iput(inode);
  78                 iput(dir);
  79                 kfree(mem);
  80                 return error;
  81         }
  82         while ((res2 = (char *) kmalloc(NFS_MAXPATHLEN + 1, GFP_NFS)) == NULL) {
  83                 schedule();
  84         }
  85         memcpy(res2, res, len);
  86         res2[len] = '\0';
  87         kfree(mem);
  88         iput(inode);
  89         current->link_count++;
  90         error = open_namei(res2, flag, mode, res_inode, dir);
  91         current->link_count--;
  92         kfree_s(res2, NFS_MAXPATHLEN + 1);
  93         return error;
  94 }
  95 
  96 static int nfs_readlink(struct inode *inode, char *buffer, int buflen)
     /* [previous][next][first][last][top][bottom][index][help] */
  97 {
  98         int error, *mem;
  99         unsigned int len;
 100         char *res;
 101 
 102         if (!S_ISLNK(inode->i_mode)) {
 103                 iput(inode);
 104                 return -EINVAL;
 105         }
 106         if (buflen > NFS_MAXPATHLEN)
 107                 buflen = NFS_MAXPATHLEN;
 108         error = nfs_proc_readlink(NFS_SERVER(inode), NFS_FH(inode), &mem,
 109                 &res, &len, buflen);
 110         iput(inode);
 111         if (! error) {
 112                 memcpy_tofs(buffer, res, len);
 113                 put_user('\0', buffer + len);
 114                 error = len;
 115         }
 116         kfree(mem);
 117         return error;
 118 }

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