root/fs/xiafs/symlink.c

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

DEFINITIONS

This source file includes following definitions.
  1. xiafs_readlink
  2. xiafs_follow_link

   1 /*
   2  *  linux/fs/xiafs/symlink.c
   3  *
   4  *  Copyright (C) Q. Frank Xia, 1993.
   5  *  
   6  *  Based on Linus' minix/symlink.c
   7  *  Copyright (C) Linus Torvalds, 1991, 1992.
   8  *
   9  *  This software may be redistributed per Linux Copyright.
  10  */
  11 
  12 #include <asm/segment.h>
  13 
  14 #include <linux/errno.h>
  15 #include <linux/sched.h>
  16 #include <linux/fs.h>
  17 #include <linux/xia_fs.h>
  18 #include <linux/stat.h>
  19 
  20 static int 
  21 xiafs_readlink(struct inode *, char *, int);
  22 
  23 static int 
  24 xiafs_follow_link(struct inode *, struct inode *, int, int, struct inode **);
  25 
  26 /*
  27  * symlinks can't do much...
  28  */
  29 struct inode_operations xiafs_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         xiafs_readlink,         /* readlink */
  41         xiafs_follow_link,      /* follow_link */
  42         NULL,                   /* bmap */
  43         NULL,                   /* truncate */
  44         NULL                    /* permission */
  45 };
  46 
  47 static int xiafs_readlink(struct inode * inode, char * buffer, int buflen)
     /* [previous][next][first][last][top][bottom][index][help] */
  48 {
  49     struct buffer_head * bh;
  50     int i;
  51     char c;
  52 
  53     if (!S_ISLNK(inode->i_mode)) {
  54         iput(inode);
  55         return -EINVAL;
  56     }
  57     if (buflen > BLOCK_SIZE)
  58         buflen = BLOCK_SIZE;
  59     bh = xiafs_bread(inode, 0, 0);
  60     if (!IS_RDONLY (inode)) {
  61         inode->i_atime=CURRENT_TIME;
  62         inode->i_dirt=1;
  63     }
  64     iput(inode);
  65     if (!bh)
  66         return 0;
  67     for (i=0; i < buflen && (c=bh->b_data[i]); i++)
  68       put_fs_byte(c, buffer++);
  69     if (i < buflen-1)
  70       put_fs_byte((char)0, buffer);
  71     brelse(bh);
  72     return i;
  73 }
  74 
  75 static int xiafs_follow_link(struct inode * dir, struct inode * inode,
     /* [previous][next][first][last][top][bottom][index][help] */
  76         int flag, int mode, struct inode ** res_inode)
  77 {
  78     int error;
  79     struct buffer_head * bh;
  80 
  81     *res_inode = NULL;
  82     if (!dir) {
  83         dir = current->fs->root;
  84         dir->i_count++;
  85     }
  86     if (!inode) {
  87         iput(dir);
  88         return -ENOENT;
  89     }
  90     if (!S_ISLNK(inode->i_mode)) {
  91         iput(dir);
  92         *res_inode = inode;
  93         return 0;
  94     }
  95     if (!IS_RDONLY (inode)) {
  96         inode->i_atime=CURRENT_TIME;
  97         inode->i_dirt=1;
  98     }
  99     if (current->link_count > 5) {
 100         iput(inode);
 101         iput(dir);
 102         return -ELOOP;
 103     }
 104     if (!(bh = xiafs_bread(inode, 0, 0))) {
 105         iput(inode);
 106         iput(dir);
 107         return -EIO;
 108     }
 109     iput(inode);
 110     current->link_count++;
 111     error = open_namei(bh->b_data,flag,mode,res_inode,dir);
 112     current->link_count--;
 113     brelse(bh);
 114     return error;
 115 }
 116 
 117 
 118 

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