VirtualBox

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

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

linux/vboxsf: build fix for EL6 pre 10.
ticketref:18646:Guest additions build failure on CentOS 6.6.

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 16.7 KB
 
1/* $Id: vfsmod.h 78660 2019-05-22 13:18:28Z 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 * Logging wrappers.
60 */
61#if 1
62# define TRACE() LogFunc(("tracepoint\n"))
63# define SFLOG(aArgs) Log(aArgs)
64# define SFLOGFLOW(aArgs) LogFlow(aArgs)
65# define SFLOG2(aArgs) Log2(aArgs)
66# define SFLOG3(aArgs) Log3(aArgs)
67# define SFLOGRELBOTH(aArgs) LogRel(aArgs)
68# ifdef LOG_ENABLED
69# define SFLOG_ENABLED 1
70# endif
71#else
72# define TRACE() RTLogBackdoorPrintf("%s: tracepoint\n", __FUNCTION__)
73# define SFLOG(aArgs) RTLogBackdoorPrintf aArgs
74# define SFLOGFLOW(aArgs) RTLogBackdoorPrintf aArgs
75# define SFLOG2(aArgs) RTLogBackdoorPrintf aArgs
76# define SFLOG3(aArgs) RTLogBackdoorPrintf aArgs
77# define SFLOG_ENABLED 1
78# define SFLOGRELBOTH(aArgs) do { RTLogBackdoorPrintf aArgs; printk aArgs; } while (0)
79#endif
80
81
82/*
83 * inode compatibility glue.
84 */
85#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0)
86
87DECLINLINE(loff_t) i_size_read(struct inode *pInode)
88{
89 AssertCompile(sizeof(loff_t) == sizeof(uint64_t));
90 return ASMAtomicReadU64((uint64_t volatile *)&pInode->i_size);
91}
92
93DECLINLINE(void) i_size_write(struct inode *pInode, loff_t cbNew)
94{
95 AssertCompile(sizeof(pInode->i_size) == sizeof(uint64_t));
96 ASMAtomicWriteU64((uint64_t volatile *)&pInode->i_size, cbNew);
97}
98
99#endif /* < 2.6.0 */
100
101#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 2, 0) \
102 && (!defined(RHEL_MAJOR) || RHEL_MAJOR != 6 || RHEL_MINOR < 10)
103DECLINLINE(void) set_nlink(struct inode *pInode, unsigned int cLinks)
104{
105 pInode->i_nlink = cLinks;
106}
107#endif
108
109
110/* global variables */
111extern VBGLSFCLIENT g_SfClient;
112extern spinlock_t g_SfHandleLock;
113extern uint32_t g_uSfLastFunction;
114extern uint64_t g_fSfFeatures;
115
116extern struct inode_operations vbsf_dir_iops;
117extern struct inode_operations vbsf_lnk_iops;
118extern struct inode_operations vbsf_reg_iops;
119extern struct file_operations vbsf_dir_fops;
120extern struct file_operations vbsf_reg_fops;
121extern struct dentry_operations vbsf_dentry_ops;
122extern struct address_space_operations vbsf_reg_aops;
123
124
125/**
126 * VBox specific per-mount (shared folder) information.
127 */
128struct vbsf_super_info {
129 VBGLSFMAP map;
130 struct nls_table *nls;
131 /** Set if the NLS table is UTF-8. */
132 bool fNlsIsUtf8;
133 int uid;
134 int gid;
135 int dmode;
136 int fmode;
137 int dmask;
138 int fmask;
139 /** Maximum number of pages to allow in an I/O buffer with the host.
140 * This applies to read and write operations. */
141 uint32_t cMaxIoPages;
142 /** The default directory buffer size. */
143 uint32_t cbDirBuf;
144 /** The time to live for directory entries in jiffies, zero if disabled. */
145 uint32_t cJiffiesDirCacheTTL;
146 /** The time to live for inode information in jiffies, zero if disabled. */
147 uint32_t cJiffiesInodeTTL;
148 /** The cache and coherency mode. */
149 enum vbsf_cache_mode enmCacheMode;
150 /** Mount tag for VBoxService automounter. @since 6.0 */
151 char szTag[32];
152#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0) && LINUX_VERSION_CODE < KERNEL_VERSION(4, 12, 0)
153 /** The backing device info structure. */
154 struct backing_dev_info bdi;
155#endif
156 /** The mount option value for /proc/mounts. */
157 int32_t msTTL;
158 /** The time to live for directory entries in milliseconds, for /proc/mounts. */
159 int32_t msDirCacheTTL;
160 /** The time to live for inode information in milliseconds, for /proc/mounts. */
161 int32_t msInodeTTL;
162};
163
164/* Following casts are here to prevent assignment of void * to
165 pointers of arbitrary type */
166#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0)
167# define VBSF_GET_SUPER_INFO(sb) ((struct vbsf_super_info *)(sb)->u.generic_sbp)
168# define VBSF_SET_SUPER_INFO(sb, a_pSuperInfo) do { (sb)->u.generic_sbp = a_pSuperInfo; } while (0)
169#else
170# define VBSF_GET_SUPER_INFO(sb) ((struct vbsf_super_info *)(sb)->s_fs_info)
171# define VBSF_SET_SUPER_INFO(sb, a_pSuperInfo) do { (sb)->s_fs_info = a_pSuperInfo;} while (0)
172#endif
173
174
175/**
176 * For associating inodes with host handles.
177 *
178 * This is necessary for address_space_operations::vbsf_writepage and allows
179 * optimizing stat, lookups and other operations on open files and directories.
180 */
181struct vbsf_handle {
182 /** List entry (head vbsf_inode_info::HandleList). */
183 RTLISTNODE Entry;
184 /** Host file/whatever handle. */
185 SHFLHANDLE hHost;
186 /** VBSF_HANDLE_F_XXX */
187 uint32_t fFlags;
188 /** Reference counter.
189 * Close the handle and free the structure when it reaches zero. */
190 uint32_t volatile cRefs;
191#ifdef VBOX_STRICT
192 /** For strictness checks. */
193 struct vbsf_inode_info *pInodeInfo;
194#endif
195};
196
197/** @name VBSF_HANDLE_F_XXX - Handle summary flags (vbsf_handle::fFlags).
198 * @{ */
199#define VBSF_HANDLE_F_READ UINT32_C(0x00000001)
200#define VBSF_HANDLE_F_WRITE UINT32_C(0x00000002)
201#define VBSF_HANDLE_F_APPEND UINT32_C(0x00000004)
202#define VBSF_HANDLE_F_FILE UINT32_C(0x00000010)
203#define VBSF_HANDLE_F_DIR UINT32_C(0x00000020)
204#define VBSF_HANDLE_F_ON_LIST UINT32_C(0x00000080)
205#define VBSF_HANDLE_F_MAGIC_MASK UINT32_C(0xffffff00)
206#define VBSF_HANDLE_F_MAGIC UINT32_C(0x75030700) /**< Maurice Ravel (1875-03-07). */
207#define VBSF_HANDLE_F_MAGIC_DEAD UINT32_C(0x19371228)
208/** @} */
209
210
211/**
212 * VBox specific per-inode information.
213 */
214struct vbsf_inode_info {
215 /** Which file */
216 SHFLSTRING *path;
217 /** Some information was changed, update data on next revalidate */
218 bool force_restat;
219 /** The timestamp (jiffies) where the inode info was last updated. */
220 unsigned long ts_up_to_date;
221 /** The birth time. */
222 RTTIMESPEC BirthTime;
223
224 /** @name Host modification detection stats.
225 * @{ */
226 /** The raw modification time, for mapping invalidation purposes. */
227 RTTIMESPEC ModificationTime;
228 /** Copy of ModificationTime from the last time we wrote to the the file. */
229 RTTIMESPEC ModificationTimeAtOurLastWrite;
230 /** @} */
231
232 /** handle valid if a file was created with vbsf_create_worker until it will
233 * be opened with vbsf_reg_open()
234 * @todo r=bird: figure this one out... */
235 SHFLHANDLE handle;
236
237 /** List of open handles (struct vbsf_handle), protected by g_SfHandleLock. */
238 RTLISTANCHOR HandleList;
239#ifdef VBOX_STRICT
240 uint32_t u32Magic;
241# define SF_INODE_INFO_MAGIC UINT32_C(0x18620822) /**< Claude Debussy */
242# define SF_INODE_INFO_MAGIC_DEAD UINT32_C(0x19180325)
243#endif
244};
245
246#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 19) || defined(KERNEL_FC6)
247/* FC6 kernel 2.6.18, vanilla kernel 2.6.19+ */
248# define VBSF_GET_INODE_INFO(i) ((struct vbsf_inode_info *) (i)->i_private)
249# define VBSF_SET_INODE_INFO(i, sf_i) (i)->i_private = sf_i
250#else
251/* vanilla kernel up to 2.6.18 */
252# define VBSF_GET_INODE_INFO(i) ((struct vbsf_inode_info *) (i)->u.generic_ip)
253# define VBSF_SET_INODE_INFO(i, sf_i) (i)->u.generic_ip = sf_i
254#endif
255
256extern void vbsf_init_inode(struct inode *inode, struct vbsf_inode_info *sf_i, PSHFLFSOBJINFO info,
257 struct vbsf_super_info *pSuperInfo);
258extern void vbsf_update_inode(struct inode *pInode, struct vbsf_inode_info *pInodeInfo, PSHFLFSOBJINFO pObjInfo,
259 struct vbsf_super_info *pSuperInfo, bool fInodeLocked, unsigned fSetAttrs);
260extern int vbsf_inode_revalidate_worker(struct dentry *dentry, bool fForced, bool fInodeLocked);
261extern int vbsf_inode_revalidate_with_handle(struct dentry *dentry, SHFLHANDLE hHostFile, bool fForced, bool fInodeLocked);
262#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 18)
263# if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0)
264extern int vbsf_inode_getattr(const struct path *path, struct kstat *kstat, u32 request_mask, unsigned int query_flags);
265# else
266extern int vbsf_inode_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *kstat);
267# endif
268#else /* < 2.5.44 */
269extern int vbsf_inode_revalidate(struct dentry *dentry);
270#endif /* < 2.5.44 */
271extern int vbsf_inode_setattr(struct dentry *dentry, struct iattr *iattr);
272
273
274extern void vbsf_handle_drop_chain(struct vbsf_inode_info *pInodeInfo);
275extern struct vbsf_handle *vbsf_handle_find(struct vbsf_inode_info *pInodeInfo, uint32_t fFlagsSet, uint32_t fFlagsClear);
276extern uint32_t vbsf_handle_release_slow(struct vbsf_handle *pHandle, struct vbsf_super_info *pSuperInfo,
277 const char *pszCaller);
278extern void vbsf_handle_append(struct vbsf_inode_info *pInodeInfo, struct vbsf_handle *pHandle);
279
280/**
281 * Releases a handle.
282 *
283 * @returns New reference count.
284 * @param pHandle The handle to release.
285 * @param pSuperInfo The info structure for the shared folder associated
286 * with the handle.
287 * @param pszCaller The caller name (for logging failures).
288 */
289DECLINLINE(uint32_t) vbsf_handle_release(struct vbsf_handle *pHandle, struct vbsf_super_info *pSuperInfo, const char *pszCaller)
290{
291 uint32_t cRefs;
292
293 Assert((pHandle->fFlags & VBSF_HANDLE_F_MAGIC_MASK) == VBSF_HANDLE_F_MAGIC);
294 Assert(pHandle->pInodeInfo);
295 Assert(pHandle->pInodeInfo && pHandle->pInodeInfo->u32Magic == SF_INODE_INFO_MAGIC);
296
297 cRefs = ASMAtomicDecU32(&pHandle->cRefs);
298 Assert(cRefs < _64M);
299 if (cRefs)
300 return cRefs;
301 return vbsf_handle_release_slow(pHandle, pSuperInfo, pszCaller);
302}
303
304
305/**
306 * VBox specific information for a regular file.
307 */
308struct vbsf_reg_info {
309 /** Handle tracking structure.
310 * @note Must be first! */
311 struct vbsf_handle Handle;
312};
313
314uint32_t vbsf_linux_oflags_to_vbox(unsigned fLnxOpen, uint32_t *pfHandle, const char *pszCaller);
315
316
317/**
318 * VBox specific information for an open directory.
319 */
320struct vbsf_dir_info {
321 /** Handle tracking structure.
322 * @note Must be first! */
323 struct vbsf_handle Handle;
324 /** Semaphore protecting everything below. */
325 struct semaphore Lock;
326 /** A magic number (VBSF_DIR_INFO_MAGIC). */
327 uint32_t u32Magic;
328 /** Size of the buffer for directory entries. */
329 uint32_t cbBuf;
330 /** Buffer for directory entries on the physical heap. */
331 PSHFLDIRINFO pBuf;
332 /** Number of valid bytes in the buffer. */
333 uint32_t cbValid;
334 /** Number of entries left in the buffer. */
335 uint32_t cEntriesLeft;
336 /** The position of the next entry. Incremented by one for each entry. */
337 loff_t offPos;
338 /** The next entry. */
339 PSHFLDIRINFO pEntry;
340 /** Set if there are no more files. */
341 bool fNoMoreFiles;
342};
343
344/** Magic number for vbsf_dir_info::u32Magic (Robert Anson Heinlein). */
345#define VBSF_DIR_INFO_MAGIC UINT32_C(0x19070707)
346/** Value of vbsf_dir_info::u32Magic when freed. */
347#define VBSF_DIR_INFO_MAGIC_DEAD UINT32_C(0x19880508)
348
349
350/**
351 * Sets the update-jiffies value for a dentry.
352 *
353 * This is used together with vbsf_super_info::cJiffiesDirCacheTTL to reduce
354 * re-validation of dentry structures while walking.
355 *
356 * This used to be living in d_time, but since 4.9.0 that seems to have become
357 * unfashionable and d_fsdata is now used to for this purpose. We do this all
358 * the way back, since d_time seems only to have been used by the file system
359 * specific code (at least going back to 2.4.0).
360 */
361DECLINLINE(void) vbsf_dentry_set_update_jiffies(struct dentry *pDirEntry, unsigned long uToSet)
362{
363 /*SFLOG3(("vbsf_dentry_set_update_jiffies: %p: %lx -> %#lx\n", pDirEntry, (unsigned long)pDirEntry->d_fsdata, uToSet));*/
364 pDirEntry->d_fsdata = (void *)uToSet;
365}
366
367/**
368 * Get the update-jiffies value for a dentry.
369 */
370DECLINLINE(unsigned long) vbsf_dentry_get_update_jiffies(struct dentry *pDirEntry)
371{
372 return (unsigned long)pDirEntry->d_fsdata;
373}
374
375/**
376 * Invalidates the update TTL for the given directory entry so that it is
377 * revalidate the next time it is used.
378 * @param pDirEntry The directory entry cache entry to invalidate.
379 */
380DECLINLINE(void) vbsf_dentry_invalidate_ttl(struct dentry *pDirEntry)
381{
382 vbsf_dentry_set_update_jiffies(pDirEntry, jiffies - INT32_MAX / 2);
383}
384
385/**
386 * Increase the time-to-live of @a pDirEntry and all ancestors.
387 * @param pDirEntry The directory entry cache entry which ancestors
388 * we should increase the TTL for.
389 */
390DECLINLINE(void) vbsf_dentry_chain_increase_ttl(struct dentry *pDirEntry)
391{
392#ifdef VBOX_STRICT
393 struct super_block * const pSuper = pDirEntry->d_sb;
394#endif
395 unsigned long const uToSet = jiffies;
396 do {
397 Assert(pDirEntry->d_sb == pSuper);
398 vbsf_dentry_set_update_jiffies(pDirEntry, uToSet);
399 pDirEntry = pDirEntry->d_parent;
400 } while (!IS_ROOT(pDirEntry));
401}
402
403/**
404 * Increase the time-to-live of all ancestors.
405 * @param pDirEntry The directory entry cache entry which ancestors
406 * we should increase the TTL for.
407 */
408DECLINLINE(void) vbsf_dentry_chain_increase_parent_ttl(struct dentry *pDirEntry)
409{
410 Assert(!pDirEntry->d_parent || pDirEntry->d_parent->d_sb == pDirEntry->d_sb);
411 pDirEntry = pDirEntry->d_parent;
412 if (pDirEntry)
413 vbsf_dentry_chain_increase_ttl(pDirEntry);
414}
415
416/** Macro for getting the dentry for a struct file. */
417#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 6, 0)
418# define VBSF_GET_F_DENTRY(f) file_dentry(f)
419#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 20)
420# define VBSF_GET_F_DENTRY(f) (f->f_path.dentry)
421#else
422# define VBSF_GET_F_DENTRY(f) (f->f_dentry)
423#endif
424
425extern int vbsf_stat(const char *caller, struct vbsf_super_info *pSuperInfo, SHFLSTRING * path, PSHFLFSOBJINFO result,
426 int ok_to_fail);
427extern int vbsf_path_from_dentry(struct vbsf_super_info *pSuperInfo, struct vbsf_inode_info *sf_i, struct dentry *dentry,
428 SHFLSTRING ** result, const char *caller);
429extern int vbsf_nlscpy(struct vbsf_super_info *pSuperInfo, char *name, size_t name_bound_len,
430 const unsigned char *utf8_name, size_t utf8_len);
431extern int vbsf_nls_to_shflstring(struct vbsf_super_info *pSuperInfo, const char *pszNls, PSHFLSTRING *ppString);
432
433
434/**
435 * Converts Linux access permissions to VBox ones (mode & 0777).
436 *
437 * @note Currently identical.
438 * @sa sf_access_permissions_to_linux
439 */
440DECLINLINE(uint32_t) sf_access_permissions_to_vbox(int fAttr)
441{
442 /* Access bits should be the same: */
443 AssertCompile(RTFS_UNIX_IRUSR == S_IRUSR);
444 AssertCompile(RTFS_UNIX_IWUSR == S_IWUSR);
445 AssertCompile(RTFS_UNIX_IXUSR == S_IXUSR);
446 AssertCompile(RTFS_UNIX_IRGRP == S_IRGRP);
447 AssertCompile(RTFS_UNIX_IWGRP == S_IWGRP);
448 AssertCompile(RTFS_UNIX_IXGRP == S_IXGRP);
449 AssertCompile(RTFS_UNIX_IROTH == S_IROTH);
450 AssertCompile(RTFS_UNIX_IWOTH == S_IWOTH);
451 AssertCompile(RTFS_UNIX_IXOTH == S_IXOTH);
452
453 return fAttr & RTFS_UNIX_ALL_ACCESS_PERMS;
454}
455
456#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