1 | /** @file
|
---|
2 | * vboxsf - VirtualBox Guest Additions for Linux.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2006-2019 Oracle Corporation
|
---|
7 | *
|
---|
8 | * Permission is hereby granted, free of charge, to any person
|
---|
9 | * obtaining a copy of this software and associated documentation
|
---|
10 | * files (the "Software"), to deal in the Software without
|
---|
11 | * restriction, including without limitation the rights to use,
|
---|
12 | * copy, modify, merge, publish, distribute, sublicense, and/or sell
|
---|
13 | * copies of the Software, and to permit persons to whom the
|
---|
14 | * Software is furnished to do so, subject to the following
|
---|
15 | * conditions:
|
---|
16 | *
|
---|
17 | * The above copyright notice and this permission notice shall be
|
---|
18 | * included in all copies or substantial portions of the Software.
|
---|
19 | *
|
---|
20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
---|
21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
---|
22 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
---|
23 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
---|
24 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
---|
25 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
---|
26 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
---|
27 | * OTHER DEALINGS IN THE SOFTWARE.
|
---|
28 | */
|
---|
29 |
|
---|
30 | #ifndef GA_INCLUDED_SRC_linux_sharedfolders_vfsmod_h
|
---|
31 | #define GA_INCLUDED_SRC_linux_sharedfolders_vfsmod_h
|
---|
32 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
33 | # pragma once
|
---|
34 | #endif
|
---|
35 |
|
---|
36 | #define LOG_GROUP LOG_GROUP_SHARED_FOLDERS
|
---|
37 | #include "the-linux-kernel.h"
|
---|
38 | #include <VBox/log.h>
|
---|
39 |
|
---|
40 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
|
---|
41 | #include <linux/backing-dev.h>
|
---|
42 | #endif
|
---|
43 |
|
---|
44 | #include <VBox/VBoxGuestLibSharedFolders.h>
|
---|
45 | #include "vbsfmount.h"
|
---|
46 |
|
---|
47 | #define DIR_BUFFER_SIZE (16*_1K)
|
---|
48 |
|
---|
49 | /* per-shared folder information */
|
---|
50 | struct sf_glob_info {
|
---|
51 | VBGLSFMAP map;
|
---|
52 | struct nls_table *nls;
|
---|
53 | int ttl;
|
---|
54 | int uid;
|
---|
55 | int gid;
|
---|
56 | int dmode;
|
---|
57 | int fmode;
|
---|
58 | int dmask;
|
---|
59 | int fmask;
|
---|
60 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
|
---|
61 | struct backing_dev_info bdi;
|
---|
62 | #endif
|
---|
63 | char tag[32]; /**< Mount tag for VBoxService automounter. @since 6.0 */
|
---|
64 | };
|
---|
65 |
|
---|
66 | /* per-inode information */
|
---|
67 | struct sf_inode_info {
|
---|
68 | /* which file */
|
---|
69 | SHFLSTRING *path;
|
---|
70 | /* some information was changed, update data on next revalidate */
|
---|
71 | int force_restat;
|
---|
72 | /* directory content changed, update the whole directory on next sf_getdent */
|
---|
73 | int force_reread;
|
---|
74 | /* file structure, only valid between open() and release() */
|
---|
75 | struct file *file;
|
---|
76 | /* handle valid if a file was created with sf_create_aux until it will
|
---|
77 | * be opened with sf_reg_open() */
|
---|
78 | SHFLHANDLE handle;
|
---|
79 | };
|
---|
80 |
|
---|
81 | struct sf_dir_info {
|
---|
82 | struct list_head info_list;
|
---|
83 | };
|
---|
84 |
|
---|
85 | struct sf_dir_buf {
|
---|
86 | size_t cEntries;
|
---|
87 | size_t cbFree;
|
---|
88 | size_t cbUsed;
|
---|
89 | void *buf;
|
---|
90 | struct list_head head;
|
---|
91 | };
|
---|
92 |
|
---|
93 | struct sf_reg_info {
|
---|
94 | SHFLHANDLE handle;
|
---|
95 | };
|
---|
96 |
|
---|
97 | /* globals */
|
---|
98 | extern VBGLSFCLIENT client_handle;
|
---|
99 |
|
---|
100 | /* forward declarations */
|
---|
101 | extern struct inode_operations sf_dir_iops;
|
---|
102 | extern struct inode_operations sf_lnk_iops;
|
---|
103 | extern struct inode_operations sf_reg_iops;
|
---|
104 | extern struct file_operations sf_dir_fops;
|
---|
105 | extern struct file_operations sf_reg_fops;
|
---|
106 | extern struct dentry_operations sf_dentry_ops;
|
---|
107 | extern struct address_space_operations sf_reg_aops;
|
---|
108 |
|
---|
109 | extern void sf_init_inode(struct sf_glob_info *sf_g, struct inode *inode,
|
---|
110 | PSHFLFSOBJINFO info);
|
---|
111 | extern int sf_stat(const char *caller, struct sf_glob_info *sf_g,
|
---|
112 | SHFLSTRING * path, PSHFLFSOBJINFO result, int ok_to_fail);
|
---|
113 | extern int sf_inode_revalidate(struct dentry *dentry);
|
---|
114 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
|
---|
115 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0)
|
---|
116 | extern int sf_getattr(const struct path *path, struct kstat *kstat,
|
---|
117 | u32 request_mask, unsigned int query_flags);
|
---|
118 | #else
|
---|
119 | extern int sf_getattr(struct vfsmount *mnt, struct dentry *dentry,
|
---|
120 | struct kstat *kstat);
|
---|
121 | #endif
|
---|
122 | extern int sf_setattr(struct dentry *dentry, struct iattr *iattr);
|
---|
123 | #endif
|
---|
124 | extern int sf_path_from_dentry(const char *caller, struct sf_glob_info *sf_g,
|
---|
125 | struct sf_inode_info *sf_i,
|
---|
126 | struct dentry *dentry, SHFLSTRING ** result);
|
---|
127 | extern int sf_nlscpy(struct sf_glob_info *sf_g, char *name,
|
---|
128 | size_t name_bound_len, const unsigned char *utf8_name,
|
---|
129 | size_t utf8_len);
|
---|
130 | extern void sf_dir_info_free(struct sf_dir_info *p);
|
---|
131 | extern void sf_dir_info_empty(struct sf_dir_info *p);
|
---|
132 | extern struct sf_dir_info *sf_dir_info_alloc(void);
|
---|
133 | extern int sf_dir_read_all(struct sf_glob_info *sf_g,
|
---|
134 | struct sf_inode_info *sf_i, struct sf_dir_info *sf_d,
|
---|
135 | SHFLHANDLE handle);
|
---|
136 | extern int sf_init_backing_dev(struct sf_glob_info *sf_g);
|
---|
137 | extern void sf_done_backing_dev(struct sf_glob_info *sf_g);
|
---|
138 |
|
---|
139 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0)
|
---|
140 | #define STRUCT_STATFS struct statfs
|
---|
141 | #else
|
---|
142 | #define STRUCT_STATFS struct kstatfs
|
---|
143 | #endif
|
---|
144 | int sf_get_volume_info(struct super_block *sb, STRUCT_STATFS * stat);
|
---|
145 |
|
---|
146 | #ifdef __cplusplus
|
---|
147 | #define CMC_API __attribute__ ((cdecl, regparm (0)))
|
---|
148 | #else
|
---|
149 | #define CMC_API __attribute__ ((regparm (0)))
|
---|
150 | #endif
|
---|
151 |
|
---|
152 | #define TRACE() LogFunc(("tracepoint\n"))
|
---|
153 |
|
---|
154 | /* Following casts are here to prevent assignment of void * to
|
---|
155 | pointers of arbitrary type */
|
---|
156 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0)
|
---|
157 | #define GET_GLOB_INFO(sb) ((struct sf_glob_info *) (sb)->u.generic_sbp)
|
---|
158 | #define SET_GLOB_INFO(sb, sf_g) (sb)->u.generic_sbp = sf_g
|
---|
159 | #else
|
---|
160 | #define GET_GLOB_INFO(sb) ((struct sf_glob_info *) (sb)->s_fs_info)
|
---|
161 | #define SET_GLOB_INFO(sb, sf_g) (sb)->s_fs_info = sf_g
|
---|
162 | #endif
|
---|
163 |
|
---|
164 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 19) || defined(KERNEL_FC6)
|
---|
165 | /* FC6 kernel 2.6.18, vanilla kernel 2.6.19+ */
|
---|
166 | #define GET_INODE_INFO(i) ((struct sf_inode_info *) (i)->i_private)
|
---|
167 | #define SET_INODE_INFO(i, sf_i) (i)->i_private = sf_i
|
---|
168 | #else
|
---|
169 | /* vanilla kernel up to 2.6.18 */
|
---|
170 | #define GET_INODE_INFO(i) ((struct sf_inode_info *) (i)->u.generic_ip)
|
---|
171 | #define SET_INODE_INFO(i, sf_i) (i)->u.generic_ip = sf_i
|
---|
172 | #endif
|
---|
173 |
|
---|
174 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)
|
---|
175 | #define GET_F_DENTRY(f) (f->f_path.dentry)
|
---|
176 | #else
|
---|
177 | #define GET_F_DENTRY(f) (f->f_dentry)
|
---|
178 | #endif
|
---|
179 |
|
---|
180 | #endif /* !GA_INCLUDED_SRC_linux_sharedfolders_vfsmod_h */
|
---|