2010-08-10 22:05:51 +02:00
|
|
|
/* VTreeFS - link.c - by Alen Stojanov and David van Moolenbroek */
|
|
|
|
|
|
|
|
#include "inc.h"
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* fs_rdlink *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
int fs_rdlink(void)
|
2010-08-10 22:05:51 +02:00
|
|
|
{
|
|
|
|
/* Retrieve symbolic link target.
|
|
|
|
*/
|
|
|
|
char path[PATH_MAX];
|
|
|
|
struct inode *node;
|
|
|
|
size_t len;
|
|
|
|
int r;
|
|
|
|
|
2014-04-30 10:20:16 +02:00
|
|
|
if ((node = find_inode(fs_m_in.m_vfs_fs_rdlink.inode)) == NULL)
|
2010-08-10 22:05:51 +02:00
|
|
|
return EINVAL;
|
|
|
|
|
|
|
|
/* Call the rdlink hook. */
|
|
|
|
assert(vtreefs_hooks->rdlink_hook != NULL);
|
|
|
|
assert(!is_inode_deleted(node)); /* symlinks cannot be opened */
|
|
|
|
|
|
|
|
r = vtreefs_hooks->rdlink_hook(node, path, sizeof(path),
|
|
|
|
get_inode_cbdata(node));
|
|
|
|
if (r != OK) return r;
|
|
|
|
|
|
|
|
len = strlen(path);
|
|
|
|
assert(len > 0 && len < sizeof(path));
|
|
|
|
|
2014-04-30 10:20:16 +02:00
|
|
|
if (len > fs_m_in.m_vfs_fs_rdlink.mem_size)
|
|
|
|
len = fs_m_in.m_vfs_fs_rdlink.mem_size;
|
2010-08-10 22:05:51 +02:00
|
|
|
|
|
|
|
/* Copy out the result. */
|
2014-04-30 10:20:16 +02:00
|
|
|
r = sys_safecopyto(fs_m_in.m_source, fs_m_in.m_vfs_fs_rdlink.grant, 0,
|
2012-06-16 03:46:15 +02:00
|
|
|
(vir_bytes) path, len);
|
2010-08-10 22:05:51 +02:00
|
|
|
if (r != OK) return r;
|
|
|
|
|
2014-04-30 10:20:16 +02:00
|
|
|
fs_m_out.m_fs_vfs_rdlink.nbytes = len;
|
2010-08-10 22:05:51 +02:00
|
|
|
return OK;
|
|
|
|
}
|