root/fs/ext2/symlink.c

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

DEFINITIONS

This source file includes following definitions.
  1. ext2_follow_link
  2. ext2_readlink

   1 /*
   2  *  linux/fs/ext2/symlink.c
   3  *
   4  *  Copyright (C) 1992, 1993, 1994  Remy Card (card@masi.ibp.fr)
   5  *                                  Laboratoire MASI - Institut Blaise Pascal
   6  *                                  Universite Pierre et Marie Curie (Paris VI)
   7  *
   8  *  from
   9  *
  10  *  linux/fs/minix/symlink.c
  11  *
  12  *  Copyright (C) 1991, 1992  Linus Torvalds
  13  *
  14  *  ext2 symlink handling code
  15  */
  16 
  17 #include <asm/segment.h>
  18 
  19 #include <linux/errno.h>
  20 #include <linux/fs.h>
  21 #include <linux/ext2_fs.h>
  22 #include <linux/sched.h>
  23 #include <linux/stat.h>
  24 
  25 static int ext2_readlink (struct inode *, char *, int);
  26 static int ext2_follow_link (struct inode *, struct inode *, int, int,
  27                                struct inode **);
  28 
  29 /*
  30  * symlinks can't do much...
  31  */
  32 struct inode_operations ext2_symlink_inode_operations = {
  33         NULL,                   /* no file-operations */
  34         NULL,                   /* create */
  35         NULL,                   /* lookup */
  36         NULL,                   /* link */
  37         NULL,                   /* unlink */
  38         NULL,                   /* symlink */
  39         NULL,                   /* mkdir */
  40         NULL,                   /* rmdir */
  41         NULL,                   /* mknod */
  42         NULL,                   /* rename */
  43         ext2_readlink,          /* readlink */
  44         ext2_follow_link,       /* follow_link */
  45         NULL,                   /* bmap */
  46         NULL,                   /* truncate */
  47         NULL                    /* permission */
  48 };
  49 
  50 static int ext2_follow_link(struct inode * dir, struct inode * inode,
     /* [previous][next][first][last][top][bottom][index][help] */
  51                             int flag, int mode, struct inode ** res_inode)
  52 {
  53         int error;
  54         struct buffer_head * bh = NULL;
  55         char * link;
  56 
  57         *res_inode = NULL;
  58         if (!dir) {
  59                 dir = current->root;
  60                 dir->i_count++;
  61         }
  62         if (!inode) {
  63                 iput (dir);
  64                 return -ENOENT;
  65         }
  66         if (!S_ISLNK(inode->i_mode)) {
  67                 iput (dir);
  68                 *res_inode = inode;
  69                 return 0;
  70         }
  71         if (current->link_count > 5) {
  72                 iput (dir);
  73                 iput (inode);
  74                 return -ELOOP;
  75         }
  76         if (inode->i_blocks) {
  77                 if (!(bh = ext2_bread (inode, 0, 0, &error))) {
  78                         iput (dir);
  79                         iput (inode);
  80                         return -EIO;
  81                 }
  82                 link = bh->b_data;
  83         } else
  84                 link = (char *) inode->u.ext2_i.i_data;
  85         current->link_count++;
  86         error = open_namei (link, flag, mode, res_inode, dir);
  87         current->link_count--;
  88         iput (inode);
  89         if (bh)
  90                 brelse (bh);
  91         return error;
  92 }
  93 
  94 static int ext2_readlink (struct inode * inode, char * buffer, int buflen)
     /* [previous][next][first][last][top][bottom][index][help] */
  95 {
  96         struct buffer_head * bh = NULL;
  97         char * link;
  98         int i, err;
  99         char c;
 100 
 101         if (!S_ISLNK(inode->i_mode)) {
 102                 iput (inode);
 103                 return -EINVAL;
 104         }
 105         if (buflen > inode->i_sb->s_blocksize - 1)
 106                 buflen = inode->i_sb->s_blocksize - 1;
 107         if (inode->i_blocks) {
 108                 bh = ext2_bread (inode, 0, 0, &err);
 109                 if (!bh) {
 110                         iput (inode);
 111                         return 0;
 112                 }
 113                 link = bh->b_data;
 114         }
 115         else
 116                 link = (char *) inode->u.ext2_i.i_data;
 117         i = 0;
 118         while (i < buflen && (c = link[i])) {
 119                 i++;
 120                 put_fs_byte (c, buffer++);
 121         }
 122         iput (inode);
 123         if (bh)
 124                 brelse (bh);
 125         return i;
 126 }

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