infra: add mars_readlink()

This commit is contained in:
Thomas Schoebel-Theuer 2012-12-12 15:10:26 +01:00 committed by Thomas Schoebel-Theuer
parent 5cc763cd74
commit 7b998de219
2 changed files with 46 additions and 0 deletions

View File

@ -137,6 +137,7 @@ extern int mars_stat(const char *path, struct kstat *stat, bool use_lstat);
extern int mars_mkdir(const char *path);
extern int mars_unlink(const char *path);
extern int mars_symlink(const char *oldpath, const char *newpath, const struct timespec *stamp, uid_t uid);
extern char *mars_readlink(const char *newpath);
extern int mars_rename(const char *oldpath, const char *newpath);
extern int mars_chmod(const char *path, mode_t mode);
extern int mars_lchown(const char *path, uid_t uid);

View File

@ -167,6 +167,51 @@ done:
}
EXPORT_SYMBOL_GPL(mars_symlink);
char *mars_readlink(const char *newpath)
{
char *res = brick_string_alloc(1024);
struct path path = {};
mm_segment_t oldfs;
struct inode *inode;
int status;
if (unlikely(!res))
goto done;
oldfs = get_fs();
set_fs(get_ds());
status = user_path_at(AT_FDCWD, newpath, 0, &path);
if (unlikely(status < 0)) {
MARS_DBG("link '%s' does not exist, status = %d\n", newpath, status);
goto err;
}
inode = path.dentry->d_inode;
if (unlikely(!inode)) {
MARS_ERR("link '%s' has invalid inode\n", newpath);
goto err;
}
status = inode->i_op->readlink(path.dentry, res, 1024);
if (unlikely(status < 0)) {
MARS_ERR("cannot read link '%s', status = %d\n", newpath, status);
goto err;
}
set_fs(oldfs);
done:
return res;
err:
set_fs(oldfs);
brick_string_free(res);
res = NULL;
goto done;
}
EXPORT_SYMBOL_GPL(mars_readlink);
int mars_rename(const char *oldpath, const char *newpath)
{
mm_segment_t oldfs;