1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
/*
* linux/fs/ufs/ufs_symlink.c
*
* Copyright (C) 1996
* Adrian Rodriguez (adrian@franklins-tower.rutgers.edu)
* Laboratory for Computer Science Research Computing Facility
* Rutgers, The State University of New Jersey
*
* Ported to 2.1.62 by Francois-Rene Rideau <rideau@ens.fr> 19971109
*
* 4.4BSD (FreeBSD) support added on February 1st 1998 by
* Niels Kristian Bech Jensen <nkbj@image.dk> partially based
* on code by Martin von Loewis <martin@mira.isdn.cs.tu-berlin.de>.
*/
#include <linux/fs.h>
#include <linux/ufs_fs.h>
#include <linux/sched.h>
#include <asm/uaccess.h>
extern int ufs_bmap (struct inode *, int);
static int
ufs_readlink(struct dentry * dentry, char * buffer, int buflen)
{
struct inode * inode = dentry->d_inode;
struct super_block * sb = inode->i_sb;
unsigned long int block;
struct buffer_head * bh = NULL;
char * link;
int i;
char c;
if (sb->u.ufs_sb.s_flags & (UFS_DEBUG|UFS_DEBUG_LINKS)) {
printk("ufs_readlink: called on ino %lu dev %u/%u\n",
inode->i_ino, MAJOR(inode->i_dev), MINOR(inode->i_dev));
}
if (!S_ISLNK(inode->i_mode)) {
return -EINVAL;
}
if (buflen > sb->s_blocksize - 1)
buflen = sb->s_blocksize - 1;
if (inode->i_blocks) {
/* XXX - error checking */
block = ufs_bmap(inode, 0);
if (sb->u.ufs_sb.s_flags &(UFS_DEBUG|UFS_DEBUG_LINKS)) {
printk("ufs_readlink: bmap got %lu for ino %lu\n",
block, inode->i_ino);
}
bh = bread(inode->i_dev, block, sb->s_blocksize);
if (!bh) {
printk("ufs_readlink: can't read block 0 for ino %lu on dev %u/%u\n",
inode->i_ino, MAJOR(inode->i_dev),
MINOR(inode->i_dev));
return 0;
}
link = bh->b_data;
/* no need to bswap */
} else /* fast symlink */ {
link = (char *)&(inode->u.ufs_i.i_u1.i_symlink[0]);
}
i = 0;
while (i < buflen && (c = link[i])) {
i++;
put_user (c, buffer++);
}
brelse (bh);
return i;
}
/*
* XXX - blatantly stolen from minix fs
*/
static struct dentry *
ufs_follow_link(struct dentry * dentry, struct dentry * base)
{
struct inode * inode = dentry->d_inode;
unsigned long int block;
struct buffer_head * bh = NULL;
char * link;
if (inode->i_sb->u.ufs_sb.s_flags & (UFS_DEBUG|UFS_DEBUG_LINKS)) {
printk("ufs_follow_link: called on ino %lu dev %u/%u\n",
inode->i_ino, MAJOR(inode->i_dev), MINOR(inode->i_dev));
}
if (inode->i_blocks) {
/* read the link from disk */
/* XXX - error checking */
block = ufs_bmap(inode, 0);
bh = bread(inode->i_dev, block, inode->i_sb->s_blocksize);
if (bh == NULL) {
printk("ufs_follow_link: can't read block 0 for ino %lu on dev %u/%u\n",
inode->i_ino, MAJOR(inode->i_dev),
MINOR(inode->i_dev));
dput(base);
return ERR_PTR(-EIO);
}
link = bh->b_data;
} else /* fast symlink */ {
link = (char *)&(inode->u.ufs_i.i_u1.i_symlink[0]);
}
base = lookup_dentry(link, base, 1);
brelse (bh);
return base;
}
static struct file_operations ufs_symlink_operations = {
NULL, /* lseek */
NULL, /* read */
NULL, /* write */
NULL, /* readdir */
NULL, /* select */
NULL, /* ioctl */
NULL, /* mmap */
NULL, /* open */
NULL, /* release */
NULL, /* fsync */ /* XXX - is this ok? */
NULL, /* fasync */
NULL, /* check_media_change */
NULL, /* revalidate */
};
struct inode_operations ufs_symlink_inode_operations = {
&ufs_symlink_operations, /* default directory file operations */
NULL, /* create */
NULL, /* lookup */
NULL, /* link */
NULL, /* unlink */
NULL, /* symlink */
NULL, /* mkdir */
NULL, /* rmdir */
NULL, /* mknod */
NULL, /* rename */
&ufs_readlink, /* readlink */
&ufs_follow_link, /* follow_link */
NULL, /* readpage */
NULL, /* writepage */
NULL, /* bmap */
NULL, /* truncate */
NULL, /* permission */
};
|