root/fs/sysv/symlink.c

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

DEFINITIONS

This source file includes following definitions.
  1. sysv_follow_link
  2. sysv_readlink

   1 /*
   2  *  linux/fs/sysv/symlink.c
   3  *
   4  *  minix/symlink.c
   5  *  Copyright (C) 1991, 1992  Linus Torvalds
   6  *
   7  *  coh/symlink.c
   8  *  Copyright (C) 1993  Pascal Haible, Bruno Haible
   9  *
  10  *  sysv/symlink.c
  11  *  Copyright (C) 1993  Bruno Haible
  12  *
  13  *  SystemV/Coherent symlink handling code
  14  */
  15 
  16 #include <linux/errno.h>
  17 #include <linux/sched.h>
  18 #include <linux/sysv_fs.h>
  19 #include <linux/stat.h>
  20 
  21 #include <asm/segment.h>
  22 
  23 static int sysv_readlink(struct inode *, char *, int);
  24 static int sysv_follow_link(struct inode *, struct inode *, int, int, struct inode **);
  25 
  26 /*
  27  * symlinks can't do much...
  28  */
  29 struct inode_operations sysv_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         sysv_readlink,          /* readlink */
  41         sysv_follow_link,       /* follow_link */
  42         NULL,                   /* bmap */
  43         NULL,                   /* truncate */
  44         NULL                    /* permission */
  45 };
  46 
  47 static int sysv_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         struct buffer_head * bh;
  52 
  53         *res_inode = NULL;
  54         if (!dir) {
  55                 dir = current->fs->root;
  56                 dir->i_count++;
  57         }
  58         if (!inode) {
  59                 iput(dir);
  60                 return -ENOENT;
  61         }
  62         if (!S_ISLNK(inode->i_mode)) {
  63                 iput(dir);
  64                 *res_inode = inode;
  65                 return 0;
  66         }
  67         if (current->link_count > 5) {
  68                 iput(inode);
  69                 iput(dir);
  70                 return -ELOOP;
  71         }
  72         if (!(bh = sysv_file_bread(inode, 0, 0))) { /* is reading 1 block enough ?? */
  73                 iput(inode);
  74                 iput(dir);
  75                 return -EIO;
  76         }
  77         iput(inode);
  78         current->link_count++;
  79         error = open_namei(bh->b_data,flag,mode,res_inode,dir);
  80         current->link_count--;
  81         brelse(bh);
  82         return error;
  83 }
  84 
  85 static int sysv_readlink(struct inode * inode, char * buffer, int buflen)
     /* [previous][next][first][last][top][bottom][index][help] */
  86 {
  87         struct buffer_head * bh;
  88         char * bh_data;
  89         int i;
  90         char c;
  91 
  92         if (!S_ISLNK(inode->i_mode)) {
  93                 iput(inode);
  94                 return -EINVAL;
  95         }
  96         if (buflen > inode->i_sb->sv_block_size_1)
  97                 buflen = inode->i_sb->sv_block_size_1;
  98         bh = sysv_file_bread(inode, 0, 0);
  99         iput(inode);
 100         if (!bh)
 101                 return 0;
 102         bh_data = bh->b_data;
 103         i = 0;
 104         while (i<buflen && (c = bh_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] */