Import 2.1.112pre1
[davej-history.git] / fs / ufs / symlink.c
blob9d18c5f53fbff3a2a0c36951f59942edc25f9e8f
1 /*
2 * linux/ufs/ufs/symlink.c
4 * Copyright (C) 1998
5 * Daniel Pirkl <daniel.pirkl@emai.cz>
6 * Charles University, Faculty of Mathematics and Physics
8 * from
10 * linux/fs/ext2/symlink.c
12 * Copyright (C) 1992, 1993, 1994, 1995
13 * Remy Card (card@masi.ibp.fr)
14 * Laboratoire MASI - Institut Blaise Pascal
15 * Universite Pierre et Marie Curie (Paris VI)
17 * from
19 * linux/fs/minix/symlink.c
21 * Copyright (C) 1991, 1992 Linus Torvalds
23 * ext2 symlink handling code
26 #include <asm/uaccess.h>
28 #include <linux/errno.h>
29 #include <linux/fs.h>
30 #include <linux/ext2_fs.h>
31 #include <linux/sched.h>
32 #include <linux/mm.h>
33 #include <linux/stat.h>
36 #undef UFS_SYMLINK_DEBUG
38 #ifdef UFS_SYMLINK_DEBUG
39 #define UFSD(x) printk("(%s, %d), %s:", __FILE__, __LINE__, __FUNCTION__); printk x;
40 #else
41 #define UFSD(x)
42 #endif
45 static struct dentry * ufs_follow_link(struct dentry * dentry,
46 struct dentry * base)
48 struct inode * inode;
49 struct buffer_head * bh;
50 int error;
51 char * link;
53 UFSD(("ENTER\n"))
55 inode = dentry->d_inode;
56 bh = NULL;
57 /* slow symlink */
58 if (inode->i_blocks) {
59 if (!(bh = ufs_bread (inode, 0, 0, &error))) {
60 dput(base);
61 return ERR_PTR(-EIO);
63 link = bh->b_data;
65 /* fast symlink */
66 else {
67 link = (char *) inode->u.ufs_i.i_u1.i_symlink;
69 UPDATE_ATIME(inode);
70 base = lookup_dentry(link, base, 1);
71 if (bh)
72 brelse(bh);
73 UFSD(("EXIT\n"))
74 return base;
77 static int ufs_readlink (struct dentry * dentry, char * buffer, int buflen)
79 struct super_block * sb;
80 struct inode * inode;
81 struct buffer_head * bh;
82 char * link;
83 int i;
85 UFSD(("ENTER\n"))
87 inode = dentry->d_inode;
88 sb = inode->i_sb;
89 bh = NULL;
90 if (buflen > sb->s_blocksize - 1)
91 buflen = sb->s_blocksize - 1;
92 /* slow symlink */
93 if (inode->i_blocks) {
94 int err;
95 bh = ufs_bread (inode, 0, 0, &err);
96 if (!bh) {
97 if(err < 0) /* indicate type of error */
98 return err;
99 return 0;
101 link = bh->b_data;
103 /* fast symlink */
104 else {
105 link = (char *) inode->u.ufs_i.i_u1.i_symlink;
107 i = 0;
108 while (i < buflen && link[i])
109 i++;
110 if (copy_to_user(buffer, link, i))
111 i = -EFAULT;
112 UPDATE_ATIME(inode);
113 if (bh)
114 brelse (bh);
115 UFSD(("ENTER\n"))
116 return i;
119 struct inode_operations ufs_symlink_inode_operations = {
120 NULL, /* no file-operations */
121 NULL, /* create */
122 NULL, /* lookup */
123 NULL, /* link */
124 NULL, /* unlink */
125 NULL, /* symlink */
126 NULL, /* mkdir */
127 NULL, /* rmdir */
128 NULL, /* mknod */
129 NULL, /* rename */
130 ufs_readlink, /* readlink */
131 ufs_follow_link, /* follow_link */
132 NULL, /* readpage */
133 NULL, /* writepage */
134 NULL, /* bmap */
135 NULL, /* truncate */
136 NULL, /* permission */
137 NULL /* smap */