1 | /* $Id: lnkops.c 76939 2019-01-22 16:51:28Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * vboxsf - VBox Linux Shared Folders VFS, operations for symbolic links.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2010-2019 Oracle Corporation
|
---|
8 | *
|
---|
9 | * Permission is hereby granted, free of charge, to any person
|
---|
10 | * obtaining a copy of this software and associated documentation
|
---|
11 | * files (the "Software"), to deal in the Software without
|
---|
12 | * restriction, including without limitation the rights to use,
|
---|
13 | * copy, modify, merge, publish, distribute, sublicense, and/or sell
|
---|
14 | * copies of the Software, and to permit persons to whom the
|
---|
15 | * Software is furnished to do so, subject to the following
|
---|
16 | * conditions:
|
---|
17 | *
|
---|
18 | * The above copyright notice and this permission notice shall be
|
---|
19 | * included in all copies or substantial portions of the Software.
|
---|
20 | *
|
---|
21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
---|
22 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
---|
23 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
---|
24 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
---|
25 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
---|
26 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
---|
27 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
---|
28 | * OTHER DEALINGS IN THE SOFTWARE.
|
---|
29 | */
|
---|
30 |
|
---|
31 | #include "vfsmod.h"
|
---|
32 |
|
---|
33 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
|
---|
34 |
|
---|
35 | # if LINUX_VERSION_CODE < KERNEL_VERSION(4, 5, 0)
|
---|
36 | # if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 2, 0)
|
---|
37 | static const char *sf_follow_link(struct dentry *dentry, void **cookie)
|
---|
38 | # else
|
---|
39 | static void *sf_follow_link(struct dentry *dentry, struct nameidata *nd)
|
---|
40 | # endif
|
---|
41 | {
|
---|
42 | struct inode *inode = dentry->d_inode;
|
---|
43 | struct sf_glob_info *sf_g = GET_GLOB_INFO(inode->i_sb);
|
---|
44 | struct sf_inode_info *sf_i = GET_INODE_INFO(inode);
|
---|
45 | int error = -ENOMEM;
|
---|
46 | char *path = (char *)get_zeroed_page(GFP_KERNEL);
|
---|
47 | int rc;
|
---|
48 |
|
---|
49 | if (path) {
|
---|
50 | error = 0;
|
---|
51 | rc = VbglR0SfReadLink(&client_handle, &sf_g->map, sf_i->path,
|
---|
52 | PATH_MAX, path);
|
---|
53 | if (RT_FAILURE(rc)) {
|
---|
54 | LogFunc(("VbglR0SfReadLink failed, caller=%s, rc=%Rrc\n", __func__, rc));
|
---|
55 | free_page((unsigned long)path);
|
---|
56 | error = -EPROTO;
|
---|
57 | }
|
---|
58 | }
|
---|
59 | # if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 2, 0)
|
---|
60 | return error ? ERR_PTR(error) : (*cookie = path);
|
---|
61 | # else
|
---|
62 | nd_set_link(nd, error ? ERR_PTR(error) : path);
|
---|
63 | return NULL;
|
---|
64 | # endif
|
---|
65 | }
|
---|
66 |
|
---|
67 | # if LINUX_VERSION_CODE < KERNEL_VERSION(4, 2, 0)
|
---|
68 | static void sf_put_link(struct dentry *dentry, struct nameidata *nd,
|
---|
69 | void *cookie)
|
---|
70 | {
|
---|
71 | char *page = nd_get_link(nd);
|
---|
72 | if (!IS_ERR(page))
|
---|
73 | free_page((unsigned long)page);
|
---|
74 | }
|
---|
75 | # endif
|
---|
76 |
|
---|
77 | # else /* LINUX_VERSION_CODE >= 4.5.0 */
|
---|
78 | static const char *sf_get_link(struct dentry *dentry, struct inode *inode,
|
---|
79 | struct delayed_call *done)
|
---|
80 | {
|
---|
81 | struct sf_glob_info *sf_g = GET_GLOB_INFO(inode->i_sb);
|
---|
82 | struct sf_inode_info *sf_i = GET_INODE_INFO(inode);
|
---|
83 | char *path;
|
---|
84 | int rc;
|
---|
85 |
|
---|
86 | if (!dentry)
|
---|
87 | return ERR_PTR(-ECHILD);
|
---|
88 | path = kzalloc(PAGE_SIZE, GFP_KERNEL);
|
---|
89 | if (!path)
|
---|
90 | return ERR_PTR(-ENOMEM);
|
---|
91 | rc = VbglR0SfReadLink(&client_handle, &sf_g->map, sf_i->path, PATH_MAX,
|
---|
92 | path);
|
---|
93 | if (RT_FAILURE(rc)) {
|
---|
94 | LogFunc(("VbglR0SfReadLink failed, caller=%s, rc=%Rrc\n",
|
---|
95 | __func__, rc));
|
---|
96 | kfree(path);
|
---|
97 | return ERR_PTR(-EPROTO);
|
---|
98 | }
|
---|
99 | set_delayed_call(done, kfree_link, path);
|
---|
100 | return path;
|
---|
101 | }
|
---|
102 | # endif /* LINUX_VERSION_CODE >= 4.5.0 */
|
---|
103 |
|
---|
104 | struct inode_operations sf_lnk_iops = {
|
---|
105 | # if LINUX_VERSION_CODE < KERNEL_VERSION(4, 10, 0)
|
---|
106 | .readlink = generic_readlink,
|
---|
107 | # endif
|
---|
108 | # if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 5, 0)
|
---|
109 | .get_link = sf_get_link
|
---|
110 | # elif LINUX_VERSION_CODE >= KERNEL_VERSION(4, 2, 0)
|
---|
111 | .follow_link = sf_follow_link,
|
---|
112 | .put_link = free_page_put_link,
|
---|
113 | # else
|
---|
114 | .follow_link = sf_follow_link,
|
---|
115 | .put_link = sf_put_link
|
---|
116 | # endif
|
---|
117 | };
|
---|
118 |
|
---|
119 | #endif /* LINUX_VERSION_CODE >= 2.6.0 */
|
---|