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