VirtualBox

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

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

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

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

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