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,                   /* bmap */
  43         NULL,                   /* truncate */
  44         NULL                    /* permission */
  45 };
  46 
  47 static int ext_follow_link(struct inode * dir, struct inode * inode,
     /* [previous][next][first][last][top][bottom][index][help] */
  48         int flag, int mode, struct inode ** res_inode)
  49 {
  50         int error;
  51         unsigned short fs;
  52         struct buffer_head * bh;
  53 
  54         *res_inode = NULL;
  55         if (!dir) {
  56                 dir = current->root;
  57                 dir->i_count++;
  58         }
  59         if (!inode) {
  60                 iput(dir);
  61                 return -ENOENT;
  62         }
  63         if (!S_ISLNK(inode->i_mode)) {
  64                 iput(dir);
  65                 *res_inode = inode;
  66                 return 0;
  67         }
  68         if (current->link_count > 5) {
  69                 iput(dir);
  70                 iput(inode);
  71                 return -ELOOP;
  72         }
  73         if (!(bh = ext_bread(inode, 0, 0))) {
  74                 iput(inode);
  75                 iput(dir);
  76                 return -EIO;
  77         }
  78         iput(inode);
  79         current->link_count++;
  80         error = open_namei(bh->b_data,flag,mode,res_inode,dir);
  81         current->link_count--;
  82         brelse(bh);
  83         return error;
  84 }
  85 
  86 static int ext_readlink(struct inode * inode, char * buffer, int buflen)
     /* [previous][next][first][last][top][bottom][index][help] */
  87 {
  88         struct buffer_head * bh;
  89         int i;
  90         char c;
  91 
  92         if (!S_ISLNK(inode->i_mode)) {
  93                 iput(inode);
  94                 return -EINVAL;
  95         }
  96         if (buflen > 1023)
  97                 buflen = 1023;
  98         bh = ext_bread(inode, 0, 0);
  99         iput(inode);
 100         if (!bh)
 101                 return 0;
 102         i = 0;
 103         while (i<buflen && (c = bh->b_data[i])) {
 104                 i++;
 105                 put_fs_byte(c,buffer++);
 106         }
 107         brelse(bh);
 108         return i;
 109 }

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