VirtualBox

source: vbox/trunk/src/VBox/Additions/linux/sharedfolders/vfsmod.h@ 77523

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

linux/vboxsf: Code cleanups in the super block and module area. bugref:9172

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 11.9 KB
 
1/* $Id: vfsmod.h 77523 2019-03-01 11:42:05Z vboxsync $ */
2/** @file
3 * vboxsf - Linux Shared Folders VFS, internal header.
4 */
5
6/*
7 * Copyright (C) 2006-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#ifndef GA_INCLUDED_SRC_linux_sharedfolders_vfsmod_h
32#define GA_INCLUDED_SRC_linux_sharedfolders_vfsmod_h
33#ifndef RT_WITHOUT_PRAGMA_ONCE
34# pragma once
35#endif
36
37#if 0 /* Enables strict checks. */
38# define RT_STRICT
39# define VBOX_STRICT
40#endif
41
42#define LOG_GROUP LOG_GROUP_SHARED_FOLDERS
43#include "the-linux-kernel.h"
44#include <iprt/list.h>
45#include <iprt/asm.h>
46#include <VBox/log.h>
47
48#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
49# include <linux/backing-dev.h>
50#endif
51
52#include <VBox/VBoxGuestLibSharedFolders.h>
53#include <VBox/VBoxGuestLibSharedFoldersInline.h>
54#include <iprt/asm.h>
55#include "vbsfmount.h"
56
57
58/*
59 * inode compatibility glue.
60 */
61#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0)
62
63DECLINLINE(loff_t) i_size_read(struct inode *pInode)
64{
65 AssertCompile(sizeof(loff_t) == sizeof(uint64_t));
66 return ASMAtomicReadU64((uint64_t volatile *)&pInode->i_size);
67}
68
69DECLINLINE(void) i_size_write(struct inode *pInode, loff_t cbNew)
70{
71 AssertCompile(sizeof(pInode->i_size) == sizeof(uint64_t));
72 ASMAtomicWriteU64((uint64_t volatile *)&pInode->i_size, cbNew);
73}
74
75#endif /* < 2.6.0 */
76
77#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 2, 0)
78DECLINLINE(void) set_nlink(struct inode *pInode, unsigned int cLinks)
79{
80 pInode->i_nlink = cLinks;
81}
82#endif
83
84
85#define DIR_BUFFER_SIZE (16*_1K)
86
87/* per-shared folder information */
88struct sf_glob_info {
89 VBGLSFMAP map;
90 struct nls_table *nls;
91 /** time-to-live value for direntry and inode info in jiffies.
92 * Zero == disabled. */
93 unsigned long ttl;
94 /** The mount option value for /proc/mounts. */
95 int ttl_msec;
96 int uid;
97 int gid;
98 int dmode;
99 int fmode;
100 int dmask;
101 int fmask;
102 /** Maximum number of pages to allow in an I/O buffer with the host.
103 * This applies to read and write operations. */
104 uint32_t cMaxIoPages;
105#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0) && LINUX_VERSION_CODE < KERNEL_VERSION(4, 11, 0)
106 struct backing_dev_info bdi;
107#endif
108 char tag[32]; /**< Mount tag for VBoxService automounter. @since 6.0 */
109};
110
111/**
112 * For associating inodes with host handles.
113 *
114 * This is necessary for address_space_operations::sf_writepage and allows
115 * optimizing stat, lookups and other operations on open files and directories.
116 */
117struct sf_handle {
118 /** List entry (head sf_inode_info::HandleList). */
119 RTLISTNODE Entry;
120 /** Host file/whatever handle. */
121 SHFLHANDLE hHost;
122 /** SF_HANDLE_F_XXX */
123 uint32_t fFlags;
124 /** Reference counter.
125 * Close the handle and free the structure when it reaches zero. */
126 uint32_t volatile cRefs;
127#ifdef VBOX_STRICT
128 /** For strictness checks. */
129 struct sf_inode_info *pInodeInfo;
130#endif
131};
132
133/** @name SF_HANDLE_F_XXX - Handle summary flags (sf_handle::fFlags).
134 * @{ */
135#define SF_HANDLE_F_READ UINT32_C(0x00000001)
136#define SF_HANDLE_F_WRITE UINT32_C(0x00000002)
137#define SF_HANDLE_F_APPEND UINT32_C(0x00000004)
138#define SF_HANDLE_F_FILE UINT32_C(0x00000010)
139#define SF_HANDLE_F_ON_LIST UINT32_C(0x00000080)
140#define SF_HANDLE_F_MAGIC_MASK UINT32_C(0xffffff00)
141#define SF_HANDLE_F_MAGIC UINT32_C(0x75030700) /**< Maurice Ravel (1875-03-07). */
142#define SF_HANDLE_F_MAGIC_DEAD UINT32_C(0x19371228)
143/** @} */
144
145/**
146 * VBox specific per-inode information.
147 */
148struct sf_inode_info {
149 /** Which file */
150 SHFLSTRING *path;
151 /** Some information was changed, update data on next revalidate */
152 bool force_restat;
153 /** directory content changed, update the whole directory on next sf_getdent */
154 bool force_reread;
155 /** The timestamp (jiffies) where the inode info was last updated. */
156 unsigned long ts_up_to_date;
157 /** The birth time. */
158 RTTIMESPEC BirthTime;
159
160 /** handle valid if a file was created with sf_create_aux until it will
161 * be opened with sf_reg_open()
162 * @todo r=bird: figure this one out... */
163 SHFLHANDLE handle;
164
165 /** List of open handles (struct sf_handle), protected by g_SfHandleLock. */
166 RTLISTANCHOR HandleList;
167#ifdef VBOX_STRICT
168 uint32_t u32Magic;
169# define SF_INODE_INFO_MAGIC UINT32_C(0x18620822) /**< Claude Debussy */
170# define SF_INODE_INFO_MAGIC_DEAD UINT32_C(0x19180325)
171#endif
172};
173
174struct sf_dir_info {
175 /** @todo sf_handle. */
176 struct list_head info_list;
177};
178
179struct sf_dir_buf {
180 size_t cEntries;
181 size_t cbFree;
182 size_t cbUsed;
183 void *buf;
184 struct list_head head;
185};
186
187/**
188 * VBox specific information for a regular file.
189 */
190struct sf_reg_info {
191 /** Handle tracking structure. */
192 struct sf_handle Handle;
193};
194
195/**
196 * Sets the update-jiffies value for a dentry.
197 *
198 * This is used together with sf_glob_info::ttl to reduce re-validation of
199 * dentry structures while walking.
200 *
201 * This used to be living in d_time, but since 4.9.0 that seems to have become
202 * unfashionable and d_fsdata is now used to for this purpose. We do this all
203 * the way back, since d_time seems only to have been used by the file system
204 * specific code (at least going back to 2.4.0).
205 */
206DECLINLINE(void) sf_dentry_set_update_jiffies(struct dentry *pDirEntry, unsigned long uToSet)
207{
208 pDirEntry->d_fsdata = (void *)uToSet;
209}
210
211/**
212 * Get the update-jiffies value for a dentry.
213 */
214DECLINLINE(unsigned long) sf_dentry_get_update_jiffies(struct dentry *pDirEntry)
215{
216 return (unsigned long)pDirEntry->d_fsdata;
217}
218
219/**
220 * Increase the time-to-live of @a pDirEntry and all ancestors.
221 * @param pDirEntry The directory entry cache entry which ancestors
222 * we should increase the TTL for.
223 */
224DECLINLINE(void) sf_dentry_chain_increase_ttl(struct dentry *pDirEntry)
225{
226#ifdef VBOX_STRICT
227 struct super_block * const pSuper = pDirEntry->d_sb;
228#endif
229 unsigned long const uToSet = jiffies;
230 do {
231 Assert(pDirEntry->d_sb == pSuper);
232 sf_dentry_set_update_jiffies(pDirEntry, uToSet);
233 pDirEntry = pDirEntry->d_parent;
234 } while (!IS_ROOT(pDirEntry));
235}
236
237/**
238 * Increase the time-to-live of all ancestors.
239 * @param pDirEntry The directory entry cache entry which ancestors
240 * we should increase the TTL for.
241 */
242DECLINLINE(void) sf_dentry_chain_increase_parent_ttl(struct dentry *pDirEntry)
243{
244 Assert(!pDirEntry->d_parent || pDirEntry->d_parent->d_sb == pDirEntry->d_sb);
245 pDirEntry = pDirEntry->d_parent;
246 if (pDirEntry)
247 sf_dentry_chain_increase_ttl(pDirEntry);
248}
249
250
251/* globals */
252extern VBGLSFCLIENT client_handle;
253extern spinlock_t g_SfHandleLock;
254
255
256/* forward declarations */
257extern struct inode_operations sf_dir_iops;
258extern struct inode_operations sf_lnk_iops;
259extern struct inode_operations sf_reg_iops;
260extern struct file_operations sf_dir_fops;
261extern struct file_operations sf_reg_fops;
262extern struct dentry_operations sf_dentry_ops;
263extern struct address_space_operations sf_reg_aops;
264
265extern void sf_handle_drop_chain(struct sf_inode_info *pInodeInfo);
266extern struct sf_handle *sf_handle_find(struct sf_inode_info *pInodeInfo, uint32_t fFlagsSet, uint32_t fFlagsClear);
267extern uint32_t sf_handle_release_slow(struct sf_handle *pHandle, struct sf_glob_info *sf_g, const char *pszCaller);
268extern void sf_handle_append(struct sf_inode_info *pInodeInfo, struct sf_handle *pHandle);
269
270/**
271 * Releases a handle.
272 *
273 * @returns New reference count.
274 * @param pHandle The handle to release.
275 * @param sf_g The info structure for the shared folder associated
276 * with the handle.
277 * @param pszCaller The caller name (for logging failures).
278 */
279DECLINLINE(uint32_t) sf_handle_release(struct sf_handle *pHandle, struct sf_glob_info *sf_g, const char *pszCaller)
280{
281 uint32_t cRefs;
282
283 Assert((pHandle->fFlags & SF_HANDLE_F_MAGIC_MASK) == SF_HANDLE_F_MAGIC);
284 Assert(pHandle->pInodeInfo);
285 Assert(pHandle->pInodeInfo && pHandle->pInodeInfo->u32Magic == SF_INODE_INFO_MAGIC);
286
287 cRefs = ASMAtomicDecU32(&pHandle->cRefs);
288 Assert(cRefs < _64M);
289 if (cRefs)
290 return cRefs;
291 return sf_handle_release_slow(pHandle, sf_g, pszCaller);
292}
293
294extern void sf_init_inode(struct inode *inode, struct sf_inode_info *sf_i, PSHFLFSOBJINFO info, struct sf_glob_info *sf_g);
295extern int sf_stat(const char *caller, struct sf_glob_info *sf_g,
296 SHFLSTRING * path, PSHFLFSOBJINFO result, int ok_to_fail);
297extern int sf_inode_revalidate(struct dentry *dentry);
298extern int sf_inode_revalidate_worker(struct dentry *dentry, bool fForced);
299extern int sf_inode_revalidate_with_handle(struct dentry *dentry, SHFLHANDLE hHostFile, bool fForced, bool fInodeLocked);
300#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
301# if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0)
302extern int sf_getattr(const struct path *path, struct kstat *kstat,
303 u32 request_mask, unsigned int query_flags);
304# else
305extern int sf_getattr(struct vfsmount *mnt, struct dentry *dentry,
306 struct kstat *kstat);
307# endif
308extern int sf_setattr(struct dentry *dentry, struct iattr *iattr);
309#endif
310extern int sf_path_from_dentry(const char *caller, struct sf_glob_info *sf_g,
311 struct sf_inode_info *sf_i,
312 struct dentry *dentry, SHFLSTRING ** result);
313extern int sf_nlscpy(struct sf_glob_info *sf_g, char *name,
314 size_t name_bound_len, const unsigned char *utf8_name,
315 size_t utf8_len);
316extern void sf_dir_info_free(struct sf_dir_info *p);
317extern void sf_dir_info_empty(struct sf_dir_info *p);
318extern struct sf_dir_info *sf_dir_info_alloc(void);
319extern int sf_dir_read_all(struct sf_glob_info *sf_g,
320 struct sf_inode_info *sf_i, struct sf_dir_info *sf_d,
321 SHFLHANDLE handle);
322
323#ifdef __cplusplus
324# define CMC_API __attribute__ ((cdecl, regparm (0)))
325#else
326# define CMC_API __attribute__ ((regparm (0)))
327#endif
328
329#if 1
330# define TRACE() LogFunc(("tracepoint\n"))
331# define SFLOGFLOW(aArgs) Log(aArgs)
332# ifdef LOG_ENABLED
333# define SFLOG_ENABLED 1
334# endif
335#else
336# define TRACE() RTLogBackdoorPrintf("%s: tracepoint\n", __FUNCTION__)
337# define SFLOGFLOW(aArgs) RTLogBackdoorPrintf aArgs
338# define SFLOG_ENABLED 1
339#endif
340
341/* Following casts are here to prevent assignment of void * to
342 pointers of arbitrary type */
343#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0)
344# define GET_GLOB_INFO(sb) ((struct sf_glob_info *) (sb)->u.generic_sbp)
345# define SET_GLOB_INFO(sb, sf_g) (sb)->u.generic_sbp = sf_g
346#else
347# define GET_GLOB_INFO(sb) ((struct sf_glob_info *) (sb)->s_fs_info)
348# define SET_GLOB_INFO(sb, sf_g) (sb)->s_fs_info = sf_g
349#endif
350
351#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 19) || defined(KERNEL_FC6)
352/* FC6 kernel 2.6.18, vanilla kernel 2.6.19+ */
353# define GET_INODE_INFO(i) ((struct sf_inode_info *) (i)->i_private)
354# define SET_INODE_INFO(i, sf_i) (i)->i_private = sf_i
355#else
356/* vanilla kernel up to 2.6.18 */
357# define GET_INODE_INFO(i) ((struct sf_inode_info *) (i)->u.generic_ip)
358# define SET_INODE_INFO(i, sf_i) (i)->u.generic_ip = sf_i
359#endif
360
361#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)
362# define GET_F_DENTRY(f) (f->f_path.dentry)
363#else
364# define GET_F_DENTRY(f) (f->f_dentry)
365#endif
366
367#endif /* !GA_INCLUDED_SRC_linux_sharedfolders_vfsmod_h */
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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