Import 2.3.26pre2
[davej-history.git] / fs / sysv / symlink.c
blobdf611d589944bfa6f9d295e0d75acff1ccbe93f5
1 /*
2 * linux/fs/sysv/symlink.c
4 * minix/symlink.c
5 * Copyright (C) 1991, 1992 Linus Torvalds
7 * coh/symlink.c
8 * Copyright (C) 1993 Pascal Haible, Bruno Haible
10 * sysv/symlink.c
11 * Copyright (C) 1993 Bruno Haible
13 * SystemV/Coherent symlink handling code
16 #include <linux/errno.h>
17 #include <linux/sched.h>
18 #include <linux/sysv_fs.h>
19 #include <linux/stat.h>
21 #include <asm/uaccess.h>
23 static int sysv_readlink(struct dentry *, char *, int);
24 static struct dentry *sysv_follow_link(struct dentry *, struct dentry *, unsigned int);
27 * symlinks can't do much...
29 struct inode_operations sysv_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 sysv_readlink, /* readlink */
41 sysv_follow_link, /* follow_link */
42 NULL, /* get_block */
43 NULL, /* readpage */
44 NULL, /* writepage */
45 NULL, /* flushpage */
46 NULL, /* truncate */
47 NULL, /* permission */
48 NULL, /* smap */
49 NULL /* revalidate */
52 static struct dentry *sysv_follow_link(struct dentry * dentry,
53 struct dentry * base,
54 unsigned int follow)
56 struct inode *inode = dentry->d_inode;
57 struct buffer_head * bh;
59 bh = sysv_file_bread(inode, 0, 0);
60 if (!bh) {
61 dput(base);
62 return ERR_PTR(-EIO);
64 UPDATE_ATIME(inode);
65 base = lookup_dentry(bh->b_data, base, follow);
66 brelse(bh);
67 return base;
70 static int sysv_readlink(struct dentry * dentry, char * buffer, int buflen)
72 struct inode *inode = dentry->d_inode;
73 struct buffer_head * bh;
74 char * bh_data;
75 int i;
76 char c;
78 if (buflen > inode->i_sb->sv_block_size_1)
79 buflen = inode->i_sb->sv_block_size_1;
80 bh = sysv_file_bread(inode, 0, 0);
81 if (!bh)
82 return 0;
83 bh_data = bh->b_data;
84 i = 0;
85 while (i<buflen && (c = bh_data[i])) {
86 i++;
87 put_user(c,buffer++);
89 brelse(bh);
90 return i;