VirtualBox

source: vbox/trunk/src/VBox/Additions/linux/sharedfolders/lnkops.c@ 77529

最後變更 在這個檔案從77529是 77529,由 vboxsync 提交於 6 年 前

linux/vboxsf: Use vbxsf as prefix here - part I. bugref:9172

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 4.2 KB
 
1/* $Id: lnkops.c 77529 2019-03-01 14:13:40Z 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, 8) /* no generic_readlink() before 2.6.8 */
34
35# if LINUX_VERSION_CODE < KERNEL_VERSION(4, 5, 0)
36
37# if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 2, 0)
38static const char *vbsf_follow_link(struct dentry *dentry, void **cookie)
39# elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 13)
40static void *vbsf_follow_link(struct dentry *dentry, struct nameidata *nd)
41# else
42static int vbsf_follow_link(struct dentry *dentry, struct nameidata *nd)
43# endif
44{
45 struct inode *inode = dentry->d_inode;
46 struct vbsf_super_info *sf_g = VBSF_GET_SUPER_INFO(inode->i_sb);
47 struct sf_inode_info *sf_i = GET_INODE_INFO(inode);
48 int error = -ENOMEM;
49 char *path = (char *)get_zeroed_page(GFP_KERNEL);
50 int rc;
51
52 if (path) {
53 error = 0;
54 rc = VbglR0SfReadLink(&g_SfClient, &sf_g->map, sf_i->path,
55 PATH_MAX, path);
56 if (RT_FAILURE(rc)) {
57 LogFunc(("VbglR0SfReadLink failed, caller=%s, rc=%Rrc\n", __func__, rc));
58 free_page((unsigned long)path);
59 error = -EPROTO;
60 }
61 }
62# if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 2, 0)
63 return error ? ERR_PTR(error) : (*cookie = path);
64# else
65 nd_set_link(nd, error ? ERR_PTR(error) : path);
66# if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 13)
67 return NULL;
68# else
69 return 0;
70# endif
71# endif
72}
73
74# if LINUX_VERSION_CODE < KERNEL_VERSION(4, 2, 0)
75# if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 13)
76static void vbsf_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
77# else
78static void vbsf_put_link(struct dentry *dentry, struct nameidata *nd)
79# endif
80{
81 char *page = nd_get_link(nd);
82 if (!IS_ERR(page))
83 free_page((unsigned long)page);
84}
85# endif /* < 4.2.0 */
86
87# else /* >= 4.5.0 */
88
89static const char *vbsf_get_link(struct dentry *dentry, struct inode *inode, struct delayed_call *done)
90{
91 struct vbsf_super_info *sf_g = VBSF_GET_SUPER_INFO(inode->i_sb);
92 struct sf_inode_info *sf_i = GET_INODE_INFO(inode);
93 char *path;
94 int rc;
95
96 if (!dentry)
97 return ERR_PTR(-ECHILD);
98 path = kzalloc(PAGE_SIZE, GFP_KERNEL);
99 if (!path)
100 return ERR_PTR(-ENOMEM);
101 rc = VbglR0SfReadLink(&g_SfClient, &sf_g->map, sf_i->path, PATH_MAX, path);
102 if (RT_FAILURE(rc)) {
103 LogFunc(("VbglR0SfReadLink failed, rc=%Rrc\n", rc));
104 kfree(path);
105 return ERR_PTR(-EPROTO);
106 }
107 set_delayed_call(done, kfree_link, path);
108 return path;
109}
110
111# endif /* >= 4.5.0 */
112
113struct inode_operations vbsf_lnk_iops = {
114# if LINUX_VERSION_CODE < KERNEL_VERSION(4, 10, 0)
115 .readlink = generic_readlink,
116# endif
117# if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 5, 0)
118 .get_link = vbsf_get_link
119# elif LINUX_VERSION_CODE >= KERNEL_VERSION(4, 2, 0)
120 .follow_link = vbsf_follow_link,
121 .put_link = free_page_put_link,
122# else
123 .follow_link = vbsf_follow_link,
124 .put_link = vbsf_put_link
125# endif
126};
127
128#endif /* LINUX_VERSION_CODE >= 2.6.8 */
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette