root/fs/minix/symlink.c

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

DEFINITIONS

This source file includes following definitions.
  1. minix_follow_link
  2. minix_readlink

   1 /*
   2  *  linux/fs/minix/symlink.c
   3  *
   4  *  Copyright (C) 1991, 1992  Linus Torvalds
   5  *
   6  *  minix symlink handling code
   7  */
   8 
   9 #include <asm/segment.h>
  10 
  11 #include <linux/errno.h>
  12 #include <linux/sched.h>
  13 #include <linux/fs.h>
  14 #include <linux/minix_fs.h>
  15 #include <linux/stat.h>
  16 
  17 static int minix_readlink(struct inode *, char *, int);
  18 static int minix_follow_link(struct inode *, struct inode *, int, int, struct inode **);
  19 
  20 /*
  21  * symlinks can't do much...
  22  */
  23 struct inode_operations minix_symlink_inode_operations = {
  24         NULL,                   /* no file-operations */
  25         NULL,                   /* create */
  26         NULL,                   /* lookup */
  27         NULL,                   /* link */
  28         NULL,                   /* unlink */
  29         NULL,                   /* symlink */
  30         NULL,                   /* mkdir */
  31         NULL,                   /* rmdir */
  32         NULL,                   /* mknod */
  33         NULL,                   /* rename */
  34         minix_readlink,         /* readlink */
  35         minix_follow_link,      /* follow_link */
  36         NULL,                   /* bmap */
  37         NULL,                   /* truncate */
  38         NULL                    /* permission */
  39 };
  40 
  41 static int minix_follow_link(struct inode * dir, struct inode * inode,
     /* [previous][next][first][last][top][bottom][index][help] */
  42         int flag, int mode, struct inode ** res_inode)
  43 {
  44         int error;
  45         unsigned short fs;
  46         struct buffer_head * bh;
  47 
  48         *res_inode = NULL;
  49         if (!dir) {
  50                 dir = current->root;
  51                 dir->i_count++;
  52         }
  53         if (!inode) {
  54                 iput(dir);
  55                 return -ENOENT;
  56         }
  57         if (!S_ISLNK(inode->i_mode)) {
  58                 iput(dir);
  59                 *res_inode = inode;
  60                 return 0;
  61         }
  62         if (current->link_count > 5) {
  63                 iput(inode);
  64                 iput(dir);
  65                 return -ELOOP;
  66         }
  67         if (!(bh = minix_bread(inode, 0, 0))) {
  68                 iput(inode);
  69                 iput(dir);
  70                 return -EIO;
  71         }
  72         iput(inode);
  73         __asm__("mov %%fs,%0":"=r" (fs));
  74         __asm__("mov %0,%%fs"::"r" ((unsigned short) 0x10));
  75         current->link_count++;
  76         error = open_namei(bh->b_data,flag,mode,res_inode,dir);
  77         current->link_count--;
  78         __asm__("mov %0,%%fs"::"r" (fs));
  79         brelse(bh);
  80         return error;
  81 }
  82 
  83 static int minix_readlink(struct inode * inode, char * buffer, int buflen)
     /* [previous][next][first][last][top][bottom][index][help] */
  84 {
  85         struct buffer_head * bh;
  86         int i;
  87         char c;
  88 
  89         if (!S_ISLNK(inode->i_mode)) {
  90                 iput(inode);
  91                 return -EINVAL;
  92         }
  93         if (buflen > 1023)
  94                 buflen = 1023;
  95         bh = minix_bread(inode, 0, 0);
  96         iput(inode);
  97         if (!bh)
  98                 return 0;
  99         i = 0;
 100         while (i<buflen && (c = bh->b_data[i])) {
 101                 i++;
 102                 put_fs_byte(c,buffer++);
 103         }
 104         brelse(bh);
 105         return i;
 106 }

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