* better
[mascara-docs.git] / i386 / linux-2.3.21 / fs / ext2 / symlink.c
blob5f73159c39150328e8e574041f88fa2774de1820
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, /* get_block */
47 NULL, /* readpage */
48 NULL, /* writepage */
49 NULL, /* flushpage */
50 NULL, /* truncate */
51 NULL, /* permission */
52 NULL, /* smap */
53 NULL /* revalidate */
56 static struct dentry * ext2_follow_link(struct dentry * dentry,
57 struct dentry *base,
58 unsigned int follow)
60 struct inode *inode = dentry->d_inode;
61 struct buffer_head * bh = NULL;
62 int error;
63 char * link;
65 link = (char *) inode->u.ext2_i.i_data;
66 if (inode->i_blocks) {
67 if (!(bh = ext2_bread (inode, 0, 0, &error))) {
68 dput(base);
69 return ERR_PTR(-EIO);
71 link = bh->b_data;
73 UPDATE_ATIME(inode);
74 base = lookup_dentry(link, base, follow);
75 if (bh)
76 brelse(bh);
77 return base;
80 static int ext2_readlink (struct dentry * dentry, char * buffer, int buflen)
82 struct inode *inode = dentry->d_inode;
83 struct buffer_head * bh = NULL;
84 char * link;
85 int i;
87 if (buflen > inode->i_sb->s_blocksize - 1)
88 buflen = inode->i_sb->s_blocksize - 1;
90 link = (char *) inode->u.ext2_i.i_data;
91 if (inode->i_blocks) {
92 int err;
93 bh = ext2_bread (inode, 0, 0, &err);
94 if (!bh) {
95 if(err < 0) /* indicate type of error */
96 return err;
97 return 0;
99 link = bh->b_data;
102 i = 0;
103 while (i < buflen && link[i])
104 i++;
105 if (copy_to_user(buffer, link, i))
106 i = -EFAULT;
107 if (bh)
108 brelse (bh);
109 return i;