Import 2.3.1pre2
[davej-history.git] / fs / ext2 / symlink.c
blobf01224b687c13835f0254d02aed6374f4efbd5cc
1 /*
2 * linux/fs/ext2/symlink.c
4 * Copyright (C) 1992, 1993, 1994, 1995
5 * Remy Card (card@masi.ibp.fr)
6 * Laboratoire MASI - Institut Blaise Pascal
7 * Universite Pierre et Marie Curie (Paris VI)
9 * from
11 * linux/fs/minix/symlink.c
13 * Copyright (C) 1991, 1992 Linus Torvalds
15 * ext2 symlink handling code
18 #include <asm/uaccess.h>
20 #include <linux/errno.h>
21 #include <linux/fs.h>
22 #include <linux/ext2_fs.h>
23 #include <linux/sched.h>
24 #include <linux/mm.h>
25 #include <linux/stat.h>
27 static int ext2_readlink (struct dentry *, char *, int);
28 static struct dentry *ext2_follow_link(struct dentry *, struct dentry *, unsigned int);
31 * symlinks can't do much...
33 struct inode_operations ext2_symlink_inode_operations = {
34 NULL, /* no file-operations */
35 NULL, /* create */
36 NULL, /* lookup */
37 NULL, /* link */
38 NULL, /* unlink */
39 NULL, /* symlink */
40 NULL, /* mkdir */
41 NULL, /* rmdir */
42 NULL, /* mknod */
43 NULL, /* rename */
44 ext2_readlink, /* readlink */
45 ext2_follow_link, /* follow_link */
46 NULL, /* readpage */
47 NULL, /* writepage */
48 NULL, /* bmap */
49 NULL, /* truncate */
50 NULL, /* permission */
51 NULL /* smap */
54 static struct dentry * ext2_follow_link(struct dentry * dentry,
55 struct dentry *base,
56 unsigned int follow)
58 struct inode *inode = dentry->d_inode;
59 struct buffer_head * bh = NULL;
60 int error;
61 char * link;
63 link = (char *) inode->u.ext2_i.i_data;
64 if (inode->i_blocks) {
65 if (!(bh = ext2_bread (inode, 0, 0, &error))) {
66 dput(base);
67 return ERR_PTR(-EIO);
69 link = bh->b_data;
71 UPDATE_ATIME(inode);
72 base = lookup_dentry(link, base, follow);
73 if (bh)
74 brelse(bh);
75 return base;
78 static int ext2_readlink (struct dentry * dentry, char * buffer, int buflen)
80 struct inode *inode = dentry->d_inode;
81 struct buffer_head * bh = NULL;
82 char * link;
83 int i;
85 if (buflen > inode->i_sb->s_blocksize - 1)
86 buflen = inode->i_sb->s_blocksize - 1;
88 link = (char *) inode->u.ext2_i.i_data;
89 if (inode->i_blocks) {
90 int err;
91 bh = ext2_bread (inode, 0, 0, &err);
92 if (!bh) {
93 if(err < 0) /* indicate type of error */
94 return err;
95 return 0;
97 link = bh->b_data;
100 i = 0;
101 while (i < buflen && link[i])
102 i++;
103 if (copy_to_user(buffer, link, i))
104 i = -EFAULT;
105 UPDATE_ATIME(inode);
106 if (bh)
107 brelse (bh);
108 return i;