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