/*
 *  linux/fs/xip2/symlink.c, Version 1
 *
 * (C) Copyright IBM Corp. 2002,2004
 * Author(s): Carsten Otte <cotte@de.ibm.com>
 * derived from second extended filesystem (ext2)
 */

#include <linux/fs.h>
#include <linux/xip2_fs.h>
#include <linux/mm.h>

static char *xip2_getlink(struct dentry * dentry)
{
	char *res;
	unsigned long blockno;

	if (xip2_get_block(dentry->d_inode, 0, &blockno, 0)) {
		printk ("XIP2-FS: could not resolve symbolic link\n");
		return NULL;
	}
	res = (char*) xip2_maread (dentry->d_inode->i_sb->u.xip2_sb.mem_area,
			blockno, PAGE_SIZE);
        if (!res)
               return (char*)empty_zero_page;
        return (char*)res;
}


static int xip2_readlink(struct dentry *dentry, char *buffer, int buflen)
{
        char *s = xip2_getlink(dentry);
        int res = vfs_readlink(dentry,buffer,buflen,s);

        return res;
}

static int xip2_follow_link(struct dentry *dentry, struct nameidata *nd)
{
        char *s = xip2_getlink(dentry);
        int res = vfs_follow_link(nd, s);

        return res;
}

static int xip2_fast_readlink(struct dentry *dentry, char *buffer, int buflen)
{
	char *s = (char *)dentry->d_inode->u.ext2_i.i_data;
	return vfs_readlink(dentry, buffer, buflen, s);
}

static int xip2_fast_follow_link(struct dentry *dentry, struct nameidata *nd)
{
	char *s = (char *)dentry->d_inode->u.ext2_i.i_data;
	return vfs_follow_link(nd, s);
}

struct inode_operations xip2_fast_symlink_inode_operations = {
	readlink:	xip2_fast_readlink,
	follow_link:	xip2_fast_follow_link,
};

struct inode_operations xip2_symlink_inode_operations = {
	readlink:	xip2_readlink,
	follow_link:	xip2_follow_link,
};
