* added 0.99 linux version
[mascara-docs.git] / i386 / linux / linux-0.99 / fs / xiafs / symlink.c
blobe3e963bef3f295153230830965b6ed31bebed50d
1 /*
2 * linux/fs/xiafs/symlink.c
4 * Copyright (C) Q. Frank Xia, 1993.
5 *
6 * Based on Linus' minix/symlink.c
7 * Copyright (C) Linus Torvalds, 1991, 1992.
9 * This software may be redistributed per Linux Copyright.
12 #include <asm/segment.h>
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>
20 static int
21 xiafs_readlink(struct inode *, char *, int);
23 static int
24 xiafs_follow_link(struct inode *, struct inode *, int, int, struct inode **);
27 * symlinks can't do much...
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 */
47 static int xiafs_readlink(struct inode * inode, char * buffer, int buflen)
49 struct buffer_head * bh;
50 int i;
51 char c;
53 if (!S_ISLNK(inode->i_mode)) {
54 iput(inode);
55 return -EINVAL;
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;
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;
75 static int xiafs_follow_link(struct inode * dir, struct inode * inode,
76 int flag, int mode, struct inode ** res_inode)
78 int error;
79 struct buffer_head * bh;
81 *res_inode = NULL;
82 if (!dir) {
83 dir = current->root;
84 dir->i_count++;
86 if (!inode) {
87 iput(dir);
88 return -ENOENT;
90 if (!S_ISLNK(inode->i_mode)) {
91 iput(dir);
92 *res_inode = inode;
93 return 0;
95 if (!IS_RDONLY (inode)) {
96 inode->i_atime=CURRENT_TIME;
97 inode->i_dirt=1;
99 if (current->link_count > 5) {
100 iput(inode);
101 iput(dir);
102 return -ELOOP;
104 if (!(bh = xiafs_bread(inode, 0, 0))) {
105 iput(inode);
106 iput(dir);
107 return -EIO;
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;