-
Notifications
You must be signed in to change notification settings - Fork 9
/
symlink.c
86 lines (74 loc) · 2.08 KB
/
symlink.c
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
/*
* BRIEF DESCRIPTION
*
* Symlink operations
*
* Copyright 2012-2013 Intel Corporation
* Copyright 2009-2011 Marco Stornelli <[email protected]>
* Copyright 2003 Sony Corporation
* Copyright 2003 Matsushita Electric Industrial Co., Ltd.
* 2003-2004 (c) MontaVista Software, Inc. , Steve Longerbeam
* This file is licensed under the terms of the GNU General Public
* License version 2. This program is licensed "as is" without any
* warranty of any kind, whether express or implied.
*/
#include <linux/fs.h>
#include <linux/namei.h>
#include "pmfs.h"
int pmfs_block_symlink(struct inode *inode, const char *symname, int len)
{
struct super_block *sb = inode->i_sb;
u64 block;
char *blockp;
int err;
err = pmfs_alloc_blocks(NULL, inode, 0, 1, false);
if (err)
return err;
block = pmfs_find_data_block(inode, 0);
blockp = pmfs_get_block(sb, block);
pmfs_memunlock_block(sb, blockp);
memcpy(blockp, symname, len);
blockp[len] = '\0';
pmfs_memlock_block(sb, blockp);
pmfs_flush_buffer(blockp, len+1, false);
return 0;
}
/* FIXME: Temporary workaround */
static int pmfs_readlink_copy(char __user *buffer, int buflen, const char *link)
{
int len = PTR_ERR(link);
if (IS_ERR(link))
goto out;
len = strlen(link);
if (len > (unsigned) buflen)
len = buflen;
if (copy_to_user(buffer, link, len))
len = -EFAULT;
out:
return len;
}
static int pmfs_readlink(struct dentry *dentry, char __user *buffer, int buflen)
{
struct inode *inode = dentry->d_inode;
struct super_block *sb = inode->i_sb;
u64 block;
char *blockp;
block = pmfs_find_data_block(inode, 0);
blockp = pmfs_get_block(sb, block);
return pmfs_readlink_copy(buffer, buflen, blockp);
}
static const char *pmfs_get_link(struct dentry *dentry, struct inode *inode,
struct delayed_call *done)
{
struct super_block *sb = inode->i_sb;
off_t block;
char *blockp;
block = pmfs_find_data_block(inode, 0);
blockp = pmfs_get_block(sb, block);
return blockp;
}
const struct inode_operations pmfs_symlink_inode_operations = {
.readlink = pmfs_readlink,
.get_link = pmfs_get_link,
.setattr = pmfs_notify_change,
};