summaryrefslogtreecommitdiffstats
path: root/fs/qnx4/symlinks.c
blob: 0b3f9ae03d6cb4459b1c158296a96bc892a9ce02 (plain)
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
/* 
 * QNX4 file system, Linux implementation.
 * 
 * Version : 0.1
 * 
 * Using parts of the xiafs filesystem.
 * 
 * History :
 * 
 * 28-05-1998 by Richard Frowijn : first release.
 * 21-06-1998 by Frank Denis : ugly changes to make it compile on Linux 2.1.99+
 */

/* THIS FILE HAS TO BE REWRITTEN */

#include <linux/string.h>
#include <linux/errno.h>
#include <linux/sched.h>
#include <linux/fs.h>
#include <linux/qnx4_fs.h>
#include <linux/stat.h>

#include <asm/segment.h>
#include <asm/uaccess.h>

static int qnx4_readlink(struct dentry *, char *, int);
static struct dentry *qnx4_follow_link(struct dentry *, struct dentry *, unsigned int follow);

/*
 * symlinks can't do much...
 */
struct inode_operations qnx4_symlink_inode_operations =
{
	NULL,			/* no file-operations */
	NULL,			/* create */
	NULL,			/* lookup */
	NULL,			/* link */
	NULL,			/* unlink */
	NULL,			/* symlink */
	NULL,			/* mkdir */
	NULL,			/* rmdir */
	NULL,			/* mknod */
	NULL,			/* rename */
	qnx4_readlink,		/* readlink */
	qnx4_follow_link,	/* follow_link */
	NULL,			/* get_block */
	NULL,			/* readpage */
	NULL,			/* writepage */
	NULL,			/* flushpage */
	NULL,			/* truncate */
	NULL,			/* permission */
	NULL,			/* smap */
	NULL			/* revalidate */
};

static struct dentry *qnx4_follow_link(struct dentry *dentry,
				       struct dentry *base, unsigned int follow)
{
#if 0
	struct inode *inode = dentry->d_inode;
	struct buffer_head *bh;

	if (!inode) {
		return ERR_PTR(-ENOENT);
	}
	if (current->link_count > 5) {
		return ERR_PTR(-ELOOP);
	}
	if (!(bh = qnx4_bread(inode, 0, 0))) {
		return ERR_PTR(-EIO);
	}
	current->link_count++;
	current->link_count--;
	brelse(bh);
	return 0;
#else
	printk("qnx4: qnx4_follow_link needs to be fixed.\n");
	return ERR_PTR(-EIO);
#endif
}

static int qnx4_readlink(struct dentry *dentry, char *buffer, int buflen)
{
	struct inode *inode = dentry->d_inode;
	struct buffer_head *bh;
	int i;
	char c;
	struct qnx4_inode_info *qnx4_ino;

	QNX4DEBUG(("qnx4: qnx4_readlink() called\n"));

	if (buffer == NULL || inode == NULL || !S_ISLNK(inode->i_mode)) {
		return -EINVAL;
	}
	qnx4_ino = &inode->u.qnx4_i;
	if (buflen > 1023) {
		buflen = 1023;
	}
	bh = bread(inode->i_dev, qnx4_ino->i_first_xtnt.xtnt_blk,
		   QNX4_BLOCK_SIZE);
	if (bh == NULL) {
		QNX4DEBUG(("qnx4: NULL symlink bh\n"));
		return 0;
	}
	QNX4DEBUG(("qnx4: qnx4_bread sym called -> [%s]\n",
		   bh->b_data));
	if (bh->b_data[0] != 0) {
		i = 0;
		while (i < buflen && (c = bh->b_data[i])) {
			i++;
			put_user(c, buffer++);
		}
		brelse(bh);
		return i;
	} else {
		brelse(bh);
		memcpy(buffer, "fixme", 5);
		return 5;
	}
}