root/fs/ext/symlink.c

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

DEFINITIONS

This source file includes following definitions.
  1. ext_follow_link
  2. ext_readlink

   1 /*
   2  *  linux/fs/ext/symlink.c
   3  *
   4  *  Copyright (C) 1992 Remy Card (card@masi.ibp.fr)
   5  *
   6  *  from
   7  *
   8  *  linux/fs/minix/symlink.c
   9  *
  10  *  Copyright (C) 1991, 1992  Linus Torvalds
  11  *
  12  *  ext symlink handling code
  13  */
  14 
  15 #include <asm/segment.h>
  16 
  17 #include <linux/errno.h>
  18 #include <linux/sched.h>
  19 #include <linux/fs.h>
  20 #include <linux/ext_fs.h>
  21 #include <linux/stat.h>
  22 
  23 static int ext_readlink(struct inode *, char *, int);
  24 static int ext_follow_link(struct inode *, struct inode *, int, int, struct inode **);
  25 
  26 /*
  27  * symlinks can't do much...
  28  */
  29 struct inode_operations ext_symlink_inode_operations = {
  30         NULL,                   /* no file-operations */
  31         NULL,                   /* create */
  32         NULL,                   /* lookup */
  33         NULL,                   /* link */
  34         NULL,                   /* unlink */
  35         NULL,                   /* symlink */
  36         NULL,                   /* mkdir */
  37         NULL,                   /* rmdir */
  38         NULL,                   /* mknod */
  39         NULL,                   /* rename */
  40         ext_readlink,           /* readlink */
  41         ext_follow_link,        /* follow_link */
  42         NULL,                   /* readpage */
  43         NULL,                   /* writepage */
  44         NULL,                   /* bmap */
  45         NULL,                   /* truncate */
  46         NULL                    /* permission */
  47 };
  48 
  49 static int ext_follow_link(struct inode * dir, struct inode * inode,
     /* [previous][next][first][last][top][bottom][index][help] */
  50         int flag, int mode, struct inode ** res_inode)
  51 {
  52         int error;
  53         struct buffer_head * bh;
  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(dir);
  71                 iput(inode);
  72                 return -ELOOP;
  73         }
  74         if (!(bh = ext_bread(inode, 0, 0))) {
  75                 iput(inode);
  76                 iput(dir);
  77                 return -EIO;
  78         }
  79         iput(inode);
  80         current->link_count++;
  81         error = open_namei(bh->b_data,flag,mode,res_inode,dir);
  82         current->link_count--;
  83         brelse(bh);
  84         return error;
  85 }
  86 
  87 static int ext_readlink(struct inode * inode, char * buffer, int buflen)
     /* [previous][next][first][last][top][bottom][index][help] */
  88 {
  89         struct buffer_head * bh;
  90         int i;
  91         char c;
  92 
  93         if (!S_ISLNK(inode->i_mode)) {
  94                 iput(inode);
  95                 return -EINVAL;
  96         }
  97         if (buflen > 1023)
  98                 buflen = 1023;
  99         bh = ext_bread(inode, 0, 0);
 100         iput(inode);
 101         if (!bh)
 102                 return 0;
 103         i = 0;
 104         while (i<buflen && (c = bh->b_data[i])) {
 105                 i++;
 106                 put_user(c,buffer++);
 107         }
 108         brelse(bh);
 109         return i;
 110 }

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