VirtualBox

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

Last change on this file since 77530 was 77530, checked in by vboxsync, 6 years ago

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

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.5 KB
Line 
1/* $Id: vfsmod.h 77530 2019-03-01 14:39:03Z 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/* global variables */
86extern VBGLSFCLIENT g_SfClient;
87extern spinlock_t g_SfHandleLock;
88
89extern struct inode_operations vbsf_dir_iops;
90extern struct inode_operations vbsf_lnk_iops;
91extern struct inode_operations vbsf_reg_iops;
92extern struct file_operations vbsf_dir_fops;
93extern struct file_operations vbsf_reg_fops;
94extern struct dentry_operations vbsf_dentry_ops;
95extern struct address_space_operations vbsf_reg_aops;
96
97
98/**
99 * VBox specific per-mount (shared folder) information.
100 */
101struct vbsf_super_info {
102 VBGLSFMAP map;
103 struct nls_table *nls;
104 /** time-to-live value for direntry and inode info in jiffies.
105 * Zero == disabled. */
106 unsigned long ttl;
107 /** The mount option value for /proc/mounts. */
108 int ttl_msec;
109 int uid;
110 int gid;
111 int dmode;
112 int fmode;
113 int dmask;
114 int fmask;
115 /** Maximum number of pages to allow in an I/O buffer with the host.
116 * This applies to read and write operations. */
117 uint32_t cMaxIoPages;
118 /** Mount tag for VBoxService automounter. @since 6.0 */
119 char tag[32];
120#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0) && LINUX_VERSION_CODE < KERNEL_VERSION(4, 11, 0)
121 /** The backing device info structure. */
122 struct backing_dev_info bdi;
123#endif
124};
125
126/* Following casts are here to prevent assignment of void * to
127 pointers of arbitrary type */
128#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0)
129# define VBSF_GET_SUPER_INFO(sb) ((struct vbsf_super_info *)(sb)->u.generic_sbp)
130# define VBSF_SET_SUPER_INFO(sb, sf_g) do { (sb)->u.generic_sbp = sf_g; } while (0)
131#else
132# define VBSF_GET_SUPER_INFO(sb) ((struct vbsf_super_info *)(sb)->s_fs_info)
133# define VBSF_SET_SUPER_INFO(sb, sf_g) do { (sb)->s_fs_info = sf_g;} while (0)
134#endif
135
136
137/**
138 * For associating inodes with host handles.
139 *
140 * This is necessary for address_space_operations::vbsf_writepage and allows
141 * optimizing stat, lookups and other operations on open files and directories.
142 */
143struct sf_handle {
144 /** List entry (head vbsf_inode_info::HandleList). */
145 RTLISTNODE Entry;
146 /** Host file/whatever handle. */
147 SHFLHANDLE hHost;
148 /** SF_HANDLE_F_XXX */
149 uint32_t fFlags;
150 /** Reference counter.
151 * Close the handle and free the structure when it reaches zero. */
152 uint32_t volatile cRefs;
153#ifdef VBOX_STRICT
154 /** For strictness checks. */
155 struct vbsf_inode_info *pInodeInfo;
156#endif
157};
158
159/** @name SF_HANDLE_F_XXX - Handle summary flags (sf_handle::fFlags).
160 * @{ */
161#define SF_HANDLE_F_READ UINT32_C(0x00000001)
162#define SF_HANDLE_F_WRITE UINT32_C(0x00000002)
163#define SF_HANDLE_F_APPEND UINT32_C(0x00000004)
164#define SF_HANDLE_F_FILE UINT32_C(0x00000010)
165#define SF_HANDLE_F_ON_LIST UINT32_C(0x00000080)
166#define SF_HANDLE_F_MAGIC_MASK UINT32_C(0xffffff00)
167#define SF_HANDLE_F_MAGIC UINT32_C(0x75030700) /**< Maurice Ravel (1875-03-07). */
168#define SF_HANDLE_F_MAGIC_DEAD UINT32_C(0x19371228)
169/** @} */
170
171extern void vbsf_handle_drop_chain(struct vbsf_inode_info *pInodeInfo);
172extern struct sf_handle *vbsf_handle_find(struct vbsf_inode_info *pInodeInfo, uint32_t fFlagsSet, uint32_t fFlagsClear);
173extern uint32_t vbsf_handle_release_slow(struct sf_handle *pHandle, struct vbsf_super_info *sf_g, const char *pszCaller);
174extern void vbsf_handle_append(struct vbsf_inode_info *pInodeInfo, struct sf_handle *pHandle);
175
176/**
177 * Releases a handle.
178 *
179 * @returns New reference count.
180 * @param pHandle The handle to release.
181 * @param sf_g The info structure for the shared folder associated
182 * with the handle.
183 * @param pszCaller The caller name (for logging failures).
184 */
185DECLINLINE(uint32_t) vbsf_handle_release(struct sf_handle *pHandle, struct vbsf_super_info *sf_g, const char *pszCaller)
186{
187 uint32_t cRefs;
188
189 Assert((pHandle->fFlags & SF_HANDLE_F_MAGIC_MASK) == SF_HANDLE_F_MAGIC);
190 Assert(pHandle->pInodeInfo);
191 Assert(pHandle->pInodeInfo && pHandle->pInodeInfo->u32Magic == SF_INODE_INFO_MAGIC);
192
193 cRefs = ASMAtomicDecU32(&pHandle->cRefs);
194 Assert(cRefs < _64M);
195 if (cRefs)
196 return cRefs;
197 return vbsf_handle_release_slow(pHandle, sf_g, pszCaller);
198}
199
200
201/**
202 * VBox specific per-inode information.
203 */
204struct vbsf_inode_info {
205 /** Which file */
206 SHFLSTRING *path;
207 /** Some information was changed, update data on next revalidate */
208 bool force_restat;
209 /** directory content changed, update the whole directory on next vbsf_getdent */
210 bool force_reread;
211 /** The timestamp (jiffies) where the inode info was last updated. */
212 unsigned long ts_up_to_date;
213 /** The birth time. */
214 RTTIMESPEC BirthTime;
215
216 /** handle valid if a file was created with vbsf_create_worker until it will
217 * be opened with vbsf_reg_open()
218 * @todo r=bird: figure this one out... */
219 SHFLHANDLE handle;
220
221 /** List of open handles (struct sf_handle), protected by g_SfHandleLock. */
222 RTLISTANCHOR HandleList;
223#ifdef VBOX_STRICT
224 uint32_t u32Magic;
225# define SF_INODE_INFO_MAGIC UINT32_C(0x18620822) /**< Claude Debussy */
226# define SF_INODE_INFO_MAGIC_DEAD UINT32_C(0x19180325)
227#endif
228};
229
230#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 19) || defined(KERNEL_FC6)
231/* FC6 kernel 2.6.18, vanilla kernel 2.6.19+ */
232# define VBSF_GET_INODE_INFO(i) ((struct vbsf_inode_info *) (i)->i_private)
233# define VBSF_SET_INODE_INFO(i, sf_i) (i)->i_private = sf_i
234#else
235/* vanilla kernel up to 2.6.18 */
236# define VBSF_GET_INODE_INFO(i) ((struct vbsf_inode_info *) (i)->u.generic_ip)
237# define VBSF_SET_INODE_INFO(i, sf_i) (i)->u.generic_ip = sf_i
238#endif
239
240extern void vbsf_init_inode(struct inode *inode, struct vbsf_inode_info *sf_i, PSHFLFSOBJINFO info, struct vbsf_super_info *sf_g);
241extern int vbsf_inode_revalidate(struct dentry *dentry);
242extern int vbsf_inode_revalidate_worker(struct dentry *dentry, bool fForced);
243extern int vbsf_inode_revalidate_with_handle(struct dentry *dentry, SHFLHANDLE hHostFile, bool fForced, bool fInodeLocked);
244#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
245# if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0)
246extern int vbsf_inode_getattr(const struct path *path, struct kstat *kstat, u32 request_mask, unsigned int query_flags);
247# else
248extern int vbsf_inode_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *kstat);
249# endif
250extern int vbsf_inode_setattr(struct dentry *dentry, struct iattr *iattr);
251#endif
252
253
254/**
255 * VBox specific information for a regular file.
256 */
257struct vbsf_reg_info {
258 /** Handle tracking structure. */
259 struct sf_handle Handle;
260};
261
262
263struct vbsf_dir_info {
264 /** @todo sf_handle. */
265 struct list_head info_list;
266};
267
268#define DIR_BUFFER_SIZE (16*_1K)
269struct vbsf_dir_buf {
270 size_t cEntries;
271 size_t cbFree;
272 size_t cbUsed;
273 void *buf;
274 struct list_head head;
275};
276
277extern void vbsf_dir_info_free(struct vbsf_dir_info *p);
278extern void vbsf_dir_info_empty(struct vbsf_dir_info *p);
279extern struct vbsf_dir_info *vbsf_dir_info_alloc(void);
280extern int vbsf_dir_read_all(struct vbsf_super_info *sf_g, struct vbsf_inode_info *sf_i,
281 struct vbsf_dir_info *sf_d, SHFLHANDLE handle);
282
283
284/**
285 * Sets the update-jiffies value for a dentry.
286 *
287 * This is used together with vbsf_super_info::ttl to reduce re-validation of
288 * dentry structures while walking.
289 *
290 * This used to be living in d_time, but since 4.9.0 that seems to have become
291 * unfashionable and d_fsdata is now used to for this purpose. We do this all
292 * the way back, since d_time seems only to have been used by the file system
293 * specific code (at least going back to 2.4.0).
294 */
295DECLINLINE(void) vbsf_dentry_set_update_jiffies(struct dentry *pDirEntry, unsigned long uToSet)
296{
297 pDirEntry->d_fsdata = (void *)uToSet;
298}
299
300/**
301 * Get the update-jiffies value for a dentry.
302 */
303DECLINLINE(unsigned long) vbsf_dentry_get_update_jiffies(struct dentry *pDirEntry)
304{
305 return (unsigned long)pDirEntry->d_fsdata;
306}
307
308/**
309 * Increase the time-to-live of @a pDirEntry and all ancestors.
310 * @param pDirEntry The directory entry cache entry which ancestors
311 * we should increase the TTL for.
312 */
313DECLINLINE(void) vbsf_dentry_chain_increase_ttl(struct dentry *pDirEntry)
314{
315#ifdef VBOX_STRICT
316 struct super_block * const pSuper = pDirEntry->d_sb;
317#endif
318 unsigned long const uToSet = jiffies;
319 do {
320 Assert(pDirEntry->d_sb == pSuper);
321 vbsf_dentry_set_update_jiffies(pDirEntry, uToSet);
322 pDirEntry = pDirEntry->d_parent;
323 } while (!IS_ROOT(pDirEntry));
324}
325
326/**
327 * Increase the time-to-live of all ancestors.
328 * @param pDirEntry The directory entry cache entry which ancestors
329 * we should increase the TTL for.
330 */
331DECLINLINE(void) vbsf_dentry_chain_increase_parent_ttl(struct dentry *pDirEntry)
332{
333 Assert(!pDirEntry->d_parent || pDirEntry->d_parent->d_sb == pDirEntry->d_sb);
334 pDirEntry = pDirEntry->d_parent;
335 if (pDirEntry)
336 vbsf_dentry_chain_increase_ttl(pDirEntry);
337}
338
339#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)
340# define VBSF_GET_F_DENTRY(f) (f->f_path.dentry)
341#else
342# define VBSF_GET_F_DENTRY(f) (f->f_dentry)
343#endif
344
345
346extern int vbsf_stat(const char *caller, struct vbsf_super_info *sf_g, SHFLSTRING * path, PSHFLFSOBJINFO result, int ok_to_fail);
347extern int vbsf_path_from_dentry(const char *caller, struct vbsf_super_info *sf_g, struct vbsf_inode_info *sf_i,
348 struct dentry *dentry, SHFLSTRING ** result);
349extern int vbsf_nlscpy(struct vbsf_super_info *sf_g, char *name, size_t name_bound_len,
350 const unsigned char *utf8_name, size_t utf8_len);
351
352
353#if 1
354# define TRACE() LogFunc(("tracepoint\n"))
355# define SFLOGFLOW(aArgs) Log(aArgs)
356# ifdef LOG_ENABLED
357# define SFLOG_ENABLED 1
358# endif
359#else
360# define TRACE() RTLogBackdoorPrintf("%s: tracepoint\n", __FUNCTION__)
361# define SFLOGFLOW(aArgs) RTLogBackdoorPrintf aArgs
362# define SFLOG_ENABLED 1
363#endif
364
365#endif /* !GA_INCLUDED_SRC_linux_sharedfolders_vfsmod_h */
Note: See TracBrowser for help on using the repository browser.

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