VirtualBox

source: vbox/trunk/src/VBox/Additions/linux/sharedfolders/utils.c@ 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: 38.9 KB
Line 
1/* $Id: utils.c 77530 2019-03-01 14:39:03Z vboxsync $ */
2/** @file
3 * vboxsf - VBox Linux Shared Folders VFS, utility functions.
4 *
5 * Utility functions (mainly conversion from/to VirtualBox/Linux data structures).
6 */
7
8/*
9 * Copyright (C) 2006-2019 Oracle Corporation
10 *
11 * Permission is hereby granted, free of charge, to any person
12 * obtaining a copy of this software and associated documentation
13 * files (the "Software"), to deal in the Software without
14 * restriction, including without limitation the rights to use,
15 * copy, modify, merge, publish, distribute, sublicense, and/or sell
16 * copies of the Software, and to permit persons to whom the
17 * Software is furnished to do so, subject to the following
18 * conditions:
19 *
20 * The above copyright notice and this permission notice shall be
21 * included in all copies or substantial portions of the Software.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
25 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
27 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
28 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
30 * OTHER DEALINGS IN THE SOFTWARE.
31 */
32
33#include "vfsmod.h"
34#include <iprt/asm.h>
35#include <iprt/err.h>
36#include <linux/vfs.h>
37
38
39/**
40 * Convert from VBox to linux time.
41 */
42#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0)
43DECLINLINE(void) vbsf_time_to_linux(time_t *pLinuxDst, PCRTTIMESPEC pVBoxSrc)
44{
45 int64_t t = RTTimeSpecGetNano(pVBoxSrc);
46 do_div(t, RT_NS_1SEC);
47 *pLinuxDst = t;
48}
49#else /* >= 2.6.0 */
50# if LINUX_VERSION_CODE < KERNEL_VERSION(4, 18, 0)
51DECLINLINE(void) vbsf_time_to_linux(struct timespec *pLinuxDst, PCRTTIMESPEC pVBoxSrc)
52# else
53DECLINLINE(void) vbsf_time_to_linux(struct timespec64 *pLinuxDst, PCRTTIMESPEC pVBoxSrc)
54# endif
55{
56 int64_t t = RTTimeSpecGetNano(pVBoxSrc);
57 pLinuxDst->tv_nsec = do_div(t, RT_NS_1SEC);
58 pLinuxDst->tv_sec = t;
59}
60#endif /* >= 2.6.0 */
61
62
63/**
64 * Convert from linux to VBox time.
65 */
66#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0)
67DECLINLINE(void) vbsf_time_to_vbox(PRTTIMESPEC pVBoxDst, time_t *pLinuxSrc)
68{
69 RTTimeSpecSetNano(pVBoxDst, RT_NS_1SEC_64 * *pLinuxSrc);
70}
71#else /* >= 2.6.0 */
72# if LINUX_VERSION_CODE < KERNEL_VERSION(4, 18, 0)
73DECLINLINE(void) vbsf_time_to_vbox(PRTTIMESPEC pVBoxDst, struct timespec const *pLinuxSrc)
74# else
75DECLINLINE(void) vbsf_time_to_vbox(PRTTIMESPEC pVBoxDst, struct timespec64 const *pLinuxSrc)
76# endif
77{
78 RTTimeSpecSetNano(pVBoxDst, pLinuxSrc->tv_nsec + pLinuxSrc->tv_sec * (int64_t)RT_NS_1SEC);
79}
80#endif /* >= 2.6.0 */
81
82
83/**
84 * Converts Linux access permissions to VBox ones (mode & 0777).
85 *
86 * @note Currently identical.
87 */
88DECLINLINE(uint32_t) sf_access_permissions_to_vbox(int fAttr)
89{
90 /* Access bits should be the same: */
91 AssertCompile(RTFS_UNIX_IRUSR == S_IRUSR);
92 AssertCompile(RTFS_UNIX_IWUSR == S_IWUSR);
93 AssertCompile(RTFS_UNIX_IXUSR == S_IXUSR);
94 AssertCompile(RTFS_UNIX_IRGRP == S_IRGRP);
95 AssertCompile(RTFS_UNIX_IWGRP == S_IWGRP);
96 AssertCompile(RTFS_UNIX_IXGRP == S_IXGRP);
97 AssertCompile(RTFS_UNIX_IROTH == S_IROTH);
98 AssertCompile(RTFS_UNIX_IWOTH == S_IWOTH);
99 AssertCompile(RTFS_UNIX_IXOTH == S_IXOTH);
100
101 return fAttr & RTFS_UNIX_ALL_ACCESS_PERMS;
102}
103
104
105/**
106 * Converts VBox access permissions to Linux ones (mode & 0777).
107 *
108 * @note Currently identical.
109 */
110DECLINLINE(int) sf_access_permissions_to_linux(uint32_t fAttr)
111{
112 /* Access bits should be the same: */
113 AssertCompile(RTFS_UNIX_IRUSR == S_IRUSR);
114 AssertCompile(RTFS_UNIX_IWUSR == S_IWUSR);
115 AssertCompile(RTFS_UNIX_IXUSR == S_IXUSR);
116 AssertCompile(RTFS_UNIX_IRGRP == S_IRGRP);
117 AssertCompile(RTFS_UNIX_IWGRP == S_IWGRP);
118 AssertCompile(RTFS_UNIX_IXGRP == S_IXGRP);
119 AssertCompile(RTFS_UNIX_IROTH == S_IROTH);
120 AssertCompile(RTFS_UNIX_IWOTH == S_IWOTH);
121 AssertCompile(RTFS_UNIX_IXOTH == S_IXOTH);
122
123 return fAttr & RTFS_UNIX_ALL_ACCESS_PERMS;
124}
125
126
127/**
128 * Produce the Linux mode mask, given VBox, mount options and file type.
129 */
130DECLINLINE(int) sf_file_mode_to_linux(uint32_t fVBoxMode, int fFixedMode, int fClearMask, int fType)
131{
132 int fLnxMode = sf_access_permissions_to_linux(fVBoxMode);
133 if (fFixedMode != ~0)
134 fLnxMode = fFixedMode & 0777;
135 fLnxMode &= ~fClearMask;
136 fLnxMode |= fType;
137 return fLnxMode;
138}
139
140
141/**
142 * Initializes the @a inode attributes based on @a pObjInfo and @a sf_g options.
143 */
144void vbsf_init_inode(struct inode *inode, struct vbsf_inode_info *sf_i, PSHFLFSOBJINFO pObjInfo, struct vbsf_super_info *sf_g)
145{
146 PCSHFLFSOBJATTR pAttr = &pObjInfo->Attr;
147
148 TRACE();
149
150 sf_i->ts_up_to_date = jiffies;
151 sf_i->force_restat = 0;
152
153#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
154 inode->i_mapping->a_ops = &vbsf_reg_aops;
155# if LINUX_VERSION_CODE <= KERNEL_VERSION(3, 19, 0)
156 inode->i_mapping->backing_dev_info = &sf_g->bdi; /* This is needed for mmap. */
157# endif
158#endif
159 if (RTFS_IS_DIRECTORY(pAttr->fMode)) {
160 inode->i_mode = sf_file_mode_to_linux(pAttr->fMode, sf_g->dmode, sf_g->dmask, S_IFDIR);
161 inode->i_op = &vbsf_dir_iops;
162 inode->i_fop = &vbsf_dir_fops;
163
164 /* XXX: this probably should be set to the number of entries
165 in the directory plus two (. ..) */
166 set_nlink(inode, 1);
167 }
168#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 8)
169 else if (RTFS_IS_SYMLINK(pAttr->fMode)) {
170 /** @todo r=bird: Aren't System V symlinks w/o any mode mask? IIRC there is
171 * no lchmod on Linux. */
172 inode->i_mode = sf_file_mode_to_linux(pAttr->fMode, sf_g->fmode, sf_g->fmask, S_IFLNK);
173 inode->i_op = &vbsf_lnk_iops;
174 set_nlink(inode, 1);
175 }
176#endif
177 else {
178 inode->i_mode = sf_file_mode_to_linux(pAttr->fMode, sf_g->fmode, sf_g->fmask, S_IFREG);
179 inode->i_op = &vbsf_reg_iops;
180 inode->i_fop = &vbsf_reg_fops;
181 set_nlink(inode, 1);
182 }
183
184#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0)
185 inode->i_uid = make_kuid(current_user_ns(), sf_g->uid);
186 inode->i_gid = make_kgid(current_user_ns(), sf_g->gid);
187#else
188 inode->i_uid = sf_g->uid;
189 inode->i_gid = sf_g->gid;
190#endif
191
192 inode->i_size = pObjInfo->cbObject;
193#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 19) && !defined(KERNEL_FC6)
194 inode->i_blksize = 4096;
195#endif
196#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 4, 11)
197 inode->i_blkbits = 12;
198#endif
199 /* i_blocks always in units of 512 bytes! */
200 inode->i_blocks = (pObjInfo->cbAllocated + 511) / 512;
201
202 vbsf_time_to_linux(&inode->i_atime, &pObjInfo->AccessTime);
203 vbsf_time_to_linux(&inode->i_ctime, &pObjInfo->ChangeTime);
204 vbsf_time_to_linux(&inode->i_mtime, &pObjInfo->ModificationTime);
205 sf_i->BirthTime = pObjInfo->BirthTime;
206}
207
208/**
209 * Update the inode with new object info from the host.
210 *
211 * Called by sf_inode_revalidate() and sf_inode_revalidate_with_handle(), the
212 * inode is probably locked...
213 *
214 * @todo sort out the inode locking situation.
215 */
216static void vbsf_update_inode(struct inode *pInode, struct vbsf_inode_info *pInodeInfo, PSHFLFSOBJINFO pObjInfo,
217 struct vbsf_super_info *sf_g, bool fInodeLocked)
218{
219 PCSHFLFSOBJATTR pAttr = &pObjInfo->Attr;
220 int fMode;
221
222 TRACE();
223
224#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 5, 0)
225 if (!fInodeLocked)
226 inode_lock(pInode);
227#endif
228
229 /*
230 * Calc new mode mask and update it if it changed.
231 */
232 if (RTFS_IS_DIRECTORY(pAttr->fMode))
233 fMode = sf_file_mode_to_linux(pAttr->fMode, sf_g->dmode, sf_g->dmask, S_IFDIR);
234#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 8)
235 else if (RTFS_IS_SYMLINK(pAttr->fMode))
236 /** @todo r=bird: Aren't System V symlinks w/o any mode mask? IIRC there is
237 * no lchmod on Linux. */
238 fMode = sf_file_mode_to_linux(pAttr->fMode, sf_g->fmode, sf_g->fmask, S_IFLNK);
239#endif
240 else
241 fMode = sf_file_mode_to_linux(pAttr->fMode, sf_g->fmode, sf_g->fmask, S_IFREG);
242
243 if (fMode == pInode->i_mode) {
244 /* likely */
245 } else {
246 if ((fMode & S_IFMT) == (pInode->i_mode & S_IFMT))
247 pInode->i_mode = fMode;
248 else {
249 SFLOGFLOW(("vbsf_update_inode: Changed from %o to %o (%s)\n",
250 pInode->i_mode & S_IFMT, fMode & S_IFMT, pInodeInfo->path->String.ach));
251 /** @todo we probably need to be more drastic... */
252 vbsf_init_inode(pInode, pInodeInfo, pObjInfo, sf_g);
253
254#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 5, 0)
255 if (!fInodeLocked)
256 inode_unlock(pInode);
257#endif
258 return;
259 }
260 }
261
262 /*
263 * Update the sizes.
264 * Note! i_blocks is always in units of 512 bytes!
265 */
266 pInode->i_blocks = (pObjInfo->cbAllocated + 511) / 512;
267 i_size_write(pInode, pObjInfo->cbObject);
268
269 /*
270 * Update the timestamps.
271 */
272 vbsf_time_to_linux(&pInode->i_atime, &pObjInfo->AccessTime);
273 vbsf_time_to_linux(&pInode->i_ctime, &pObjInfo->ChangeTime);
274 vbsf_time_to_linux(&pInode->i_mtime, &pObjInfo->ModificationTime);
275 pInodeInfo->BirthTime = pObjInfo->BirthTime;
276
277 /*
278 * Mark it as up to date.
279 */
280 pInodeInfo->ts_up_to_date = jiffies;
281 pInodeInfo->force_restat = 0;
282
283#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 5, 0)
284 if (!fInodeLocked)
285 inode_unlock(pInode);
286#endif
287}
288
289
290/** @note Currently only used for the root directory during (re-)mount. */
291int vbsf_stat(const char *caller, struct vbsf_super_info *sf_g, SHFLSTRING *path, PSHFLFSOBJINFO result, int ok_to_fail)
292{
293 int rc;
294 VBOXSFCREATEREQ *pReq;
295 NOREF(caller);
296
297 TRACE();
298
299 pReq = (VBOXSFCREATEREQ *)VbglR0PhysHeapAlloc(sizeof(*pReq) + path->u16Size);
300 if (pReq) {
301 RT_ZERO(*pReq);
302 memcpy(&pReq->StrPath, path, SHFLSTRING_HEADER_SIZE + path->u16Size);
303 pReq->CreateParms.Handle = SHFL_HANDLE_NIL;
304 pReq->CreateParms.CreateFlags = SHFL_CF_LOOKUP | SHFL_CF_ACT_FAIL_IF_NEW;
305
306 LogFunc(("Calling VbglR0SfHostReqCreate on %s\n", path->String.utf8));
307 rc = VbglR0SfHostReqCreate(sf_g->map.root, pReq);
308 if (RT_SUCCESS(rc)) {
309 if (pReq->CreateParms.Result == SHFL_FILE_EXISTS) {
310 *result = pReq->CreateParms.Info;
311 rc = 0;
312 } else {
313 if (!ok_to_fail)
314 LogFunc(("VbglR0SfHostReqCreate on %s: file does not exist: %d (caller=%s)\n",
315 path->String.utf8, pReq->CreateParms.Result, caller));
316 rc = -ENOENT;
317 }
318 } else if (rc == VERR_INVALID_NAME) {
319 rc = -ENOENT; /* this can happen for names like 'foo*' on a Windows host */
320 } else {
321 LogFunc(("VbglR0SfHostReqCreate failed on %s: %Rrc (caller=%s)\n", path->String.utf8, rc, caller));
322 rc = -EPROTO;
323 }
324 VbglR0PhysHeapFree(pReq);
325 }
326 else
327 rc = -ENOMEM;
328 return rc;
329}
330
331/**
332 * Revalidate an inode, inner worker.
333 *
334 * @sa sf_inode_revalidate()
335 */
336int vbsf_inode_revalidate_worker(struct dentry *dentry, bool fForced)
337{
338 int rc;
339 struct inode *pInode = dentry ? dentry->d_inode : NULL;
340 if (pInode) {
341 struct vbsf_inode_info *sf_i = VBSF_GET_INODE_INFO(pInode);
342 struct vbsf_super_info *sf_g = VBSF_GET_SUPER_INFO(pInode->i_sb);
343 AssertReturn(sf_i, -EINVAL);
344 AssertReturn(sf_g, -EINVAL);
345
346 /*
347 * Can we get away without any action here?
348 */
349 if ( !fForced
350 && !sf_i->force_restat
351 && jiffies - sf_i->ts_up_to_date < sf_g->ttl)
352 rc = 0;
353 else {
354 /*
355 * No, we have to query the file info from the host.
356 * Try get a handle we can query, any kind of handle will do here.
357 */
358 struct sf_handle *pHandle = vbsf_handle_find(sf_i, 0, 0);
359 if (pHandle) {
360 /* Query thru pHandle. */
361 VBOXSFOBJINFOREQ *pReq = (VBOXSFOBJINFOREQ *)VbglR0PhysHeapAlloc(sizeof(*pReq));
362 if (pReq) {
363 RT_ZERO(*pReq);
364 rc = VbglR0SfHostReqQueryObjInfo(sf_g->map.root, pReq, pHandle->hHost);
365 if (RT_SUCCESS(rc)) {
366 /*
367 * Reset the TTL and copy the info over into the inode structure.
368 */
369 vbsf_update_inode(pInode, sf_i, &pReq->ObjInfo, sf_g, true /*fInodeLocked??*/);
370 } else if (rc == VERR_INVALID_HANDLE) {
371 rc = -ENOENT; /* Restore.*/
372 } else {
373 LogFunc(("VbglR0SfHostReqQueryObjInfo failed on %#RX64: %Rrc\n", pHandle->hHost, rc));
374 rc = -RTErrConvertToErrno(rc);
375 }
376 VbglR0PhysHeapFree(pReq);
377 } else
378 rc = -ENOMEM;
379 vbsf_handle_release(pHandle, sf_g, "vbsf_inode_revalidate_worker");
380
381 } else {
382 /* Query via path. */
383 SHFLSTRING *pPath = sf_i->path;
384 VBOXSFCREATEREQ *pReq = (VBOXSFCREATEREQ *)VbglR0PhysHeapAlloc(sizeof(*pReq) + pPath->u16Size);
385 if (pReq) {
386 RT_ZERO(*pReq);
387 memcpy(&pReq->StrPath, pPath, SHFLSTRING_HEADER_SIZE + pPath->u16Size);
388 pReq->CreateParms.Handle = SHFL_HANDLE_NIL;
389 pReq->CreateParms.CreateFlags = SHFL_CF_LOOKUP | SHFL_CF_ACT_FAIL_IF_NEW;
390
391 rc = VbglR0SfHostReqCreate(sf_g->map.root, pReq);
392 if (RT_SUCCESS(rc)) {
393 if (pReq->CreateParms.Result == SHFL_FILE_EXISTS) {
394 /*
395 * Reset the TTL and copy the info over into the inode structure.
396 */
397 vbsf_update_inode(pInode, sf_i, &pReq->CreateParms.Info,
398 sf_g, true /*fInodeLocked??*/);
399 rc = 0;
400 } else {
401 rc = -ENOENT;
402 }
403 } else if (rc == VERR_INVALID_NAME) {
404 rc = -ENOENT; /* this can happen for names like 'foo*' on a Windows host */
405 } else {
406 LogFunc(("VbglR0SfHostReqCreate failed on %s: %Rrc\n", pPath->String.ach, rc));
407 rc = -EPROTO;
408 }
409 VbglR0PhysHeapFree(pReq);
410 }
411 else
412 rc = -ENOMEM;
413 }
414 }
415 } else {
416 LogFunc(("no dentry(%p) or inode(%p)\n", dentry, pInode));
417 rc = -EINVAL;
418 }
419 return rc;
420}
421
422
423/**
424 * Revalidate an inode.
425 *
426 * This is called directly as inode-op on 2.4, indirectly as dir-op
427 * vbsf_dentry_revalidate() on 2.4/2.6. The job is to find out whether
428 * dentry/inode is still valid. The test fails if @a dentry does not have an
429 * inode or vbsf_stat() is unsuccessful, otherwise we return success and update
430 * inode attributes.
431 */
432int vbsf_inode_revalidate(struct dentry *dentry)
433{
434 return vbsf_inode_revalidate_worker(dentry, false /*fForced*/);
435}
436
437
438/**
439 * Similar to sf_inode_revalidate, but uses associated host file handle as that
440 * is quite a bit faster.
441 */
442int vbsf_inode_revalidate_with_handle(struct dentry *dentry, SHFLHANDLE hHostFile, bool fForced, bool fInodeLocked)
443{
444 int err;
445 struct inode *pInode = dentry ? dentry->d_inode : NULL;
446 if (!pInode) {
447 LogFunc(("no dentry(%p) or inode(%p)\n", dentry, pInode));
448 err = -EINVAL;
449 } else {
450 struct vbsf_inode_info *sf_i = VBSF_GET_INODE_INFO(pInode);
451 struct vbsf_super_info *sf_g = VBSF_GET_SUPER_INFO(pInode->i_sb);
452 AssertReturn(sf_i, -EINVAL);
453 AssertReturn(sf_g, -EINVAL);
454
455 /*
456 * Can we get away without any action here?
457 */
458 if ( !fForced
459 && !sf_i->force_restat
460 && jiffies - sf_i->ts_up_to_date < sf_g->ttl)
461 err = 0;
462 else {
463 /*
464 * No, we have to query the file info from the host.
465 */
466 VBOXSFOBJINFOREQ *pReq = (VBOXSFOBJINFOREQ *)VbglR0PhysHeapAlloc(sizeof(*pReq));
467 if (pReq) {
468 RT_ZERO(*pReq);
469 err = VbglR0SfHostReqQueryObjInfo(sf_g->map.root, pReq, hHostFile);
470 if (RT_SUCCESS(err)) {
471 /*
472 * Reset the TTL and copy the info over into the inode structure.
473 */
474 vbsf_update_inode(pInode, sf_i, &pReq->ObjInfo, sf_g, fInodeLocked);
475 } else {
476 LogFunc(("VbglR0SfHostReqQueryObjInfo failed on %#RX64: %Rrc\n", hHostFile, err));
477 err = -RTErrConvertToErrno(err);
478 }
479 VbglR0PhysHeapFree(pReq);
480 } else
481 err = -ENOMEM;
482 }
483 }
484 return err;
485}
486
487/* on 2.6 this is a proxy for [sf_inode_revalidate] which (as a side
488 effect) updates inode attributes for [dentry] (given that [dentry]
489 has inode at all) from these new attributes we derive [kstat] via
490 [generic_fillattr] */
491#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
492
493# if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0)
494int vbsf_inode_getattr(const struct path *path, struct kstat *kstat, u32 request_mask, unsigned int flags)
495# else
496int vbsf_inode_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *kstat)
497# endif
498{
499 int rc;
500# if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0)
501 struct dentry *dentry = path->dentry;
502# endif
503
504# if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0)
505 SFLOGFLOW(("vbsf_inode_setattr: dentry=%p request_mask=%#x flags=%#x\n", dentry, request_mask, flags));
506# else
507 SFLOGFLOW(("vbsf_inode_setattr: dentry=%p\n", dentry));
508# endif
509
510# if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0)
511 /*
512 * With the introduction of statx() userland can control whether we
513 * update the inode information or not.
514 */
515 switch (flags & AT_STATX_SYNC_TYPE) {
516 default:
517 rc = vbsf_inode_revalidate_worker(dentry, false /*fForced*/);
518 break;
519
520 case AT_STATX_FORCE_SYNC:
521 rc = vbsf_inode_revalidate_worker(dentry, true /*fForced*/);
522 break;
523
524 case AT_STATX_DONT_SYNC:
525 rc = 0;
526 break;
527 }
528# else
529 rc = vbsf_inode_revalidate_worker(dentry, false /*fForced*/);
530# endif
531 if (rc == 0) {
532 /* Do generic filling in of info. */
533 generic_fillattr(dentry->d_inode, kstat);
534
535 /* Add birth time. */
536#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0)
537 if (dentry->d_inode) {
538 struct vbsf_inode_info *pInodeInfo = VBSF_GET_INODE_INFO(dentry->d_inode);
539 if (pInodeInfo) {
540 vbsf_time_to_linux(&kstat->btime, &pInodeInfo->BirthTime);
541 kstat->result_mask |= STATX_BTIME;
542 }
543 }
544#endif
545
546 /*
547 * FsPerf shows the following numbers for sequential file access against
548 * a tmpfs folder on an AMD 1950X host running debian buster/sid:
549 *
550 * block size = r128600 ----- r128755 -----
551 * reads reads writes
552 * 4096 KB = 2254 MB/s 4953 MB/s 3668 MB/s
553 * 2048 KB = 2368 MB/s 4908 MB/s 3541 MB/s
554 * 1024 KB = 2208 MB/s 4011 MB/s 3291 MB/s
555 * 512 KB = 1908 MB/s 3399 MB/s 2721 MB/s
556 * 256 KB = 1625 MB/s 2679 MB/s 2251 MB/s
557 * 128 KB = 1413 MB/s 1967 MB/s 1684 MB/s
558 * 64 KB = 1152 MB/s 1409 MB/s 1265 MB/s
559 * 32 KB = 726 MB/s 815 MB/s 783 MB/s
560 * 16 KB = 683 MB/s 475 MB/s
561 * 8 KB = 294 MB/s 286 MB/s
562 * 4 KB = 145 MB/s 156 MB/s 149 MB/s
563 *
564 */
565 if (S_ISREG(kstat->mode))
566 kstat->blksize = _1M;
567 else if (S_ISDIR(kstat->mode))
568 /** @todo this may need more tuning after we rewrite the directory handling. */
569 kstat->blksize = _16K;
570 }
571 return rc;
572}
573
574int vbsf_inode_setattr(struct dentry *dentry, struct iattr *iattr)
575{
576 struct vbsf_super_info *sf_g;
577 struct vbsf_inode_info *sf_i;
578 union SetAttrReqs
579 {
580 VBOXSFCREATEREQ Create;
581 VBOXSFOBJINFOREQ Info;
582 VBOXSFSETFILESIZEREQ SetSize;
583 VBOXSFCLOSEREQ Close;
584 } *pReq;
585 size_t cbReq;
586 SHFLCREATEPARMS *pCreateParms;
587 SHFLFSOBJINFO *pInfo;
588 SHFLHANDLE hHostFile;
589 int vrc;
590 int err = 0;
591
592 TRACE();
593
594 sf_g = VBSF_GET_SUPER_INFO(dentry->d_inode->i_sb);
595 sf_i = VBSF_GET_INODE_INFO(dentry->d_inode);
596 cbReq = RT_MAX(sizeof(pReq->Info), sizeof(pReq->Create) + SHFLSTRING_HEADER_SIZE + sf_i->path->u16Size);
597 pReq = (union SetAttrReqs *)VbglR0PhysHeapAlloc(cbReq);
598 if (!pReq) {
599 LogFunc(("Failed to allocate %#x byte request buffer!\n", cbReq));
600 return -ENOMEM;
601 }
602 pCreateParms = &pReq->Create.CreateParms;
603 pInfo = &pReq->Info.ObjInfo;
604
605 RT_ZERO(*pCreateParms);
606 pCreateParms->Handle = SHFL_HANDLE_NIL;
607 pCreateParms->CreateFlags = SHFL_CF_ACT_OPEN_IF_EXISTS
608 | SHFL_CF_ACT_FAIL_IF_NEW
609 | SHFL_CF_ACCESS_ATTR_WRITE;
610
611 /* this is at least required for Posix hosts */
612 if (iattr->ia_valid & ATTR_SIZE)
613 pCreateParms->CreateFlags |= SHFL_CF_ACCESS_WRITE;
614
615 memcpy(&pReq->Create.StrPath, sf_i->path, SHFLSTRING_HEADER_SIZE + sf_i->path->u16Size);
616 vrc = VbglR0SfHostReqCreate(sf_g->map.root, &pReq->Create);
617 if (RT_SUCCESS(vrc)) {
618 hHostFile = pCreateParms->Handle;
619 } else {
620 err = -RTErrConvertToErrno(vrc);
621 LogFunc(("VbglR0SfCreate(%s) failed vrc=%Rrc err=%d\n", sf_i->path->String.ach, vrc, err));
622 goto fail2;
623 }
624 if (pCreateParms->Result != SHFL_FILE_EXISTS) {
625 LogFunc(("file %s does not exist\n", sf_i->path->String.utf8));
626 err = -ENOENT;
627 goto fail1;
628 }
629
630 /* Setting the file size and setting the other attributes has to be
631 * handled separately, see implementation of vbsfSetFSInfo() in
632 * vbsf.cpp */
633 if (iattr->ia_valid & (ATTR_MODE | ATTR_ATIME | ATTR_MTIME)) {
634 RT_ZERO(*pInfo);
635
636 if (iattr->ia_valid & ATTR_MODE) {
637 pInfo->Attr.fMode = sf_access_permissions_to_vbox(iattr->ia_mode);
638 if (iattr->ia_mode & S_IFDIR)
639 pInfo->Attr.fMode |= RTFS_TYPE_DIRECTORY;
640 else if (iattr->ia_mode & S_IFLNK)
641 pInfo->Attr.fMode |= RTFS_TYPE_SYMLINK;
642 else
643 pInfo->Attr.fMode |= RTFS_TYPE_FILE;
644 }
645
646 if (iattr->ia_valid & ATTR_ATIME)
647 vbsf_time_to_vbox(&pInfo->AccessTime, &iattr->ia_atime);
648 if (iattr->ia_valid & ATTR_MTIME)
649 vbsf_time_to_vbox(&pInfo->ModificationTime, &iattr->ia_mtime);
650 /* ignore ctime (inode change time) as it can't be set from userland anyway */
651
652 vrc = VbglR0SfHostReqSetObjInfo(sf_g->map.root, &pReq->Info, hHostFile);
653 if (RT_FAILURE(vrc)) {
654 err = -RTErrConvertToErrno(vrc);
655 LogFunc(("VbglR0SfHostReqSetObjInfo(%s) failed vrc=%Rrc err=%d\n", sf_i->path->String.ach, vrc, err));
656 goto fail1;
657 }
658 }
659
660 if (iattr->ia_valid & ATTR_SIZE) {
661 vrc = VbglR0SfHostReqSetFileSize(sf_g->map.root, &pReq->SetSize, hHostFile, iattr->ia_size);
662 /** @todo Implement fallback if host is < 6.0? */
663 if (RT_FAILURE(vrc)) {
664 err = -RTErrConvertToErrno(vrc);
665 LogFunc(("VbglR0SfHostReqSetFileSize(%s, %#llx) failed vrc=%Rrc err=%d\n",
666 sf_i->path->String.ach, (unsigned long long)iattr->ia_size, vrc, err));
667 goto fail1;
668 }
669 }
670
671 vrc = VbglR0SfHostReqClose(sf_g->map.root, &pReq->Close, hHostFile);
672 if (RT_FAILURE(vrc))
673 LogFunc(("VbglR0SfHostReqClose(%s [%#llx]) failed vrc=%Rrc\n", sf_i->path->String.utf8, hHostFile, vrc));
674 VbglR0PhysHeapFree(pReq);
675
676 /** @todo r=bird: I guess we're calling revalidate here to update the inode
677 * info. However, due to the TTL optimization this is not guarenteed to happen.
678 *
679 * Also, we already have accurate stat information on the file, either from the
680 * SHFL_FN_CREATE call or from SHFL_FN_INFORMATION, so there is no need to do a
681 * slow stat()-like operation to retrieve the information again.
682 *
683 * What's more, given that the SHFL_FN_CREATE call succeeded, we know that the
684 * dentry and all its parent entries are valid and could touch their timestamps
685 * extending their TTL (CIFS does that). */
686 return vbsf_inode_revalidate_worker(dentry, true /*fForced*/);
687
688 fail1:
689 vrc = VbglR0SfHostReqClose(sf_g->map.root, &pReq->Close, hHostFile);
690 if (RT_FAILURE(vrc))
691 LogFunc(("VbglR0SfHostReqClose(%s [%#llx]) failed vrc=%Rrc; err=%d\n", sf_i->path->String.utf8, hHostFile, vrc, err));
692
693 fail2:
694 VbglR0PhysHeapFree(pReq);
695 return err;
696}
697
698#endif /* >= 2.6.0 */
699
700static int vbsf_make_path(const char *caller, struct vbsf_inode_info *sf_i,
701 const char *d_name, size_t d_len, SHFLSTRING **result)
702{
703 size_t path_len, shflstring_len;
704 SHFLSTRING *tmp;
705 uint16_t p_len;
706 uint8_t *p_name;
707 int fRoot = 0;
708
709 TRACE();
710 p_len = sf_i->path->u16Length;
711 p_name = sf_i->path->String.utf8;
712
713 if (p_len == 1 && *p_name == '/') {
714 path_len = d_len + 1;
715 fRoot = 1;
716 } else {
717 /* lengths of constituents plus terminating zero plus slash */
718 path_len = p_len + d_len + 2;
719 if (path_len > 0xffff) {
720 LogFunc(("path too long. caller=%s, path_len=%zu\n",
721 caller, path_len));
722 return -ENAMETOOLONG;
723 }
724 }
725
726 shflstring_len = offsetof(SHFLSTRING, String.utf8) + path_len;
727 tmp = kmalloc(shflstring_len, GFP_KERNEL);
728 if (!tmp) {
729 LogRelFunc(("kmalloc failed, caller=%s\n", caller));
730 return -ENOMEM;
731 }
732 tmp->u16Length = path_len - 1;
733 tmp->u16Size = path_len;
734
735 if (fRoot)
736 memcpy(&tmp->String.utf8[0], d_name, d_len + 1);
737 else {
738 memcpy(&tmp->String.utf8[0], p_name, p_len);
739 tmp->String.utf8[p_len] = '/';
740 memcpy(&tmp->String.utf8[p_len + 1], d_name, d_len);
741 tmp->String.utf8[p_len + 1 + d_len] = '\0';
742 }
743
744 *result = tmp;
745 return 0;
746}
747
748/**
749 * [dentry] contains string encoded in coding system that corresponds
750 * to [sf_g]->nls, we must convert it to UTF8 here and pass down to
751 * [vbsf_make_path] which will allocate SHFLSTRING and fill it in
752 */
753int vbsf_path_from_dentry(const char *caller, struct vbsf_super_info *sf_g, struct vbsf_inode_info *sf_i,
754 struct dentry *dentry, SHFLSTRING **result)
755{
756 int err;
757 const char *d_name;
758 size_t d_len;
759 const char *name;
760 size_t len = 0;
761
762 TRACE();
763 d_name = dentry->d_name.name;
764 d_len = dentry->d_name.len;
765
766 if (sf_g->nls) {
767 size_t in_len, i, out_bound_len;
768 const char *in;
769 char *out;
770
771 in = d_name;
772 in_len = d_len;
773
774 out_bound_len = PATH_MAX;
775 out = kmalloc(out_bound_len, GFP_KERNEL);
776 name = out;
777
778 for (i = 0; i < d_len; ++i) {
779 /* We renamed the linux kernel wchar_t type to linux_wchar_t in
780 the-linux-kernel.h, as it conflicts with the C++ type of that name. */
781 linux_wchar_t uni;
782 int nb;
783
784 nb = sf_g->nls->char2uni(in, in_len, &uni);
785 if (nb < 0) {
786 LogFunc(("nls->char2uni failed %x %d\n",
787 *in, in_len));
788 err = -EINVAL;
789 goto fail1;
790 }
791 in_len -= nb;
792 in += nb;
793
794#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31)
795 nb = utf32_to_utf8(uni, out, out_bound_len);
796#else
797 nb = utf8_wctomb(out, uni, out_bound_len);
798#endif
799 if (nb < 0) {
800 LogFunc(("nls->uni2char failed %x %d\n",
801 uni, out_bound_len));
802 err = -EINVAL;
803 goto fail1;
804 }
805 out_bound_len -= nb;
806 out += nb;
807 len += nb;
808 }
809 if (len >= PATH_MAX - 1) {
810 err = -ENAMETOOLONG;
811 goto fail1;
812 }
813
814 LogFunc(("result(%d) = %.*s\n", len, len, name));
815 *out = 0;
816 } else {
817 name = d_name;
818 len = d_len;
819 }
820
821 err = vbsf_make_path(caller, sf_i, name, len, result);
822 if (name != d_name)
823 kfree(name);
824
825 return err;
826
827 fail1:
828 kfree(name);
829 return err;
830}
831
832int vbsf_nlscpy(struct vbsf_super_info *sf_g, char *name, size_t name_bound_len, const unsigned char *utf8_name, size_t utf8_len)
833{
834 if (sf_g->nls) {
835 const char *in;
836 char *out;
837 size_t out_len;
838 size_t out_bound_len;
839 size_t in_bound_len;
840
841 in = utf8_name;
842 in_bound_len = utf8_len;
843
844 out = name;
845 out_len = 0;
846 out_bound_len = name_bound_len;
847
848 while (in_bound_len) {
849 int nb;
850#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31)
851 unicode_t uni;
852
853 nb = utf8_to_utf32(in, in_bound_len, &uni);
854#else
855 linux_wchar_t uni;
856
857 nb = utf8_mbtowc(&uni, in, in_bound_len);
858#endif
859 if (nb < 0) {
860 LogFunc(("utf8_mbtowc failed(%s) %x:%d\n",
861 (const char *)utf8_name, *in,
862 in_bound_len));
863 return -EINVAL;
864 }
865 in += nb;
866 in_bound_len -= nb;
867
868 nb = sf_g->nls->uni2char(uni, out, out_bound_len);
869 if (nb < 0) {
870 LogFunc(("nls->uni2char failed(%s) %x:%d\n",
871 utf8_name, uni, out_bound_len));
872 return nb;
873 }
874 out += nb;
875 out_bound_len -= nb;
876 out_len += nb;
877 }
878
879 *out = 0;
880 } else {
881 if (utf8_len + 1 > name_bound_len)
882 return -ENAMETOOLONG;
883
884 memcpy(name, utf8_name, utf8_len + 1);
885 }
886 return 0;
887}
888
889static struct vbsf_dir_buf *vbsf_dir_buf_alloc(void)
890{
891 struct vbsf_dir_buf *b;
892
893 TRACE();
894 b = kmalloc(sizeof(*b), GFP_KERNEL);
895 if (!b) {
896 LogRelFunc(("could not alloc directory buffer\n"));
897 return NULL;
898 }
899 b->buf = kmalloc(DIR_BUFFER_SIZE, GFP_KERNEL);
900 if (!b->buf) {
901 kfree(b);
902 LogRelFunc(("could not alloc directory buffer storage\n"));
903 return NULL;
904 }
905
906 INIT_LIST_HEAD(&b->head);
907 b->cEntries = 0;
908 b->cbUsed = 0;
909 b->cbFree = DIR_BUFFER_SIZE;
910 return b;
911}
912
913static void vbsf_dir_buf_free(struct vbsf_dir_buf *b)
914{
915 BUG_ON(!b || !b->buf);
916
917 TRACE();
918 list_del(&b->head);
919 kfree(b->buf);
920 kfree(b);
921}
922
923/**
924 * Free the directory buffer.
925 */
926void vbsf_dir_info_free(struct vbsf_dir_info *p)
927{
928 struct list_head *list, *pos, *tmp;
929
930 TRACE();
931 list = &p->info_list;
932 list_for_each_safe(pos, tmp, list) {
933 struct vbsf_dir_buf *b;
934
935 b = list_entry(pos, struct vbsf_dir_buf, head);
936 vbsf_dir_buf_free(b);
937 }
938 kfree(p);
939}
940
941/**
942 * Empty (but not free) the directory buffer.
943 */
944void vbsf_dir_info_empty(struct vbsf_dir_info *p)
945{
946 struct list_head *list, *pos, *tmp;
947 TRACE();
948 list = &p->info_list;
949 list_for_each_safe(pos, tmp, list) {
950 struct vbsf_dir_buf *b;
951 b = list_entry(pos, struct vbsf_dir_buf, head);
952 b->cEntries = 0;
953 b->cbUsed = 0;
954 b->cbFree = DIR_BUFFER_SIZE;
955 }
956}
957
958/**
959 * Create a new directory buffer descriptor.
960 */
961struct vbsf_dir_info *vbsf_dir_info_alloc(void)
962{
963 struct vbsf_dir_info *p;
964
965 TRACE();
966 p = kmalloc(sizeof(*p), GFP_KERNEL);
967 if (!p) {
968 LogRelFunc(("could not alloc directory info\n"));
969 return NULL;
970 }
971
972 INIT_LIST_HEAD(&p->info_list);
973 return p;
974}
975
976/**
977 * Search for an empty directory content buffer.
978 */
979static struct vbsf_dir_buf *vbsf_get_empty_dir_buf(struct vbsf_dir_info *sf_d)
980{
981 struct list_head *list, *pos;
982
983 list = &sf_d->info_list;
984 list_for_each(pos, list) {
985 struct vbsf_dir_buf *b;
986
987 b = list_entry(pos, struct vbsf_dir_buf, head);
988 if (!b)
989 return NULL;
990 else {
991 if (b->cbUsed == 0)
992 return b;
993 }
994 }
995
996 return NULL;
997}
998
999/** @todo r=bird: Why on earth do we read in the entire directory??? This
1000 * cannot be healthy for like big directory and such... */
1001int vbsf_dir_read_all(struct vbsf_super_info *sf_g, struct vbsf_inode_info *sf_i, struct vbsf_dir_info *sf_d, SHFLHANDLE handle)
1002{
1003 int err;
1004 SHFLSTRING *mask;
1005 VBOXSFLISTDIRREQ *pReq = NULL;
1006
1007 TRACE();
1008 err = vbsf_make_path(__func__, sf_i, "*", 1, &mask);
1009 if (err)
1010 goto fail0;
1011 pReq = (VBOXSFLISTDIRREQ *)VbglR0PhysHeapAlloc(sizeof(*pReq));
1012 if (!pReq)
1013 goto fail1;
1014
1015 for (;;) {
1016 int rc;
1017 struct vbsf_dir_buf *b;
1018
1019 b = vbsf_get_empty_dir_buf(sf_d);
1020 if (!b) {
1021 b = vbsf_dir_buf_alloc();
1022 if (!b) {
1023 err = -ENOMEM;
1024 LogRelFunc(("could not alloc directory buffer\n"));
1025 goto fail2;
1026 }
1027 list_add(&b->head, &sf_d->info_list);
1028 }
1029
1030 rc = VbglR0SfHostReqListDirContig2x(sf_g->map.root, pReq, handle, mask, virt_to_phys(mask),
1031 0 /*fFlags*/, b->buf, virt_to_phys(b->buf), b->cbFree);
1032 if (RT_SUCCESS(rc)) {
1033 b->cEntries += pReq->Parms.c32Entries.u.value32;
1034 b->cbFree -= pReq->Parms.cb32Buffer.u.value32;
1035 b->cbUsed += pReq->Parms.cb32Buffer.u.value32;
1036 } else if (rc == VERR_NO_MORE_FILES) {
1037 break;
1038 } else {
1039 err = -RTErrConvertToErrno(rc);
1040 LogFunc(("VbglR0SfHostReqListDirContig2x failed rc=%Rrc err=%d\n", rc, err));
1041 goto fail2;
1042 }
1043 }
1044 err = 0;
1045
1046 fail2:
1047 VbglR0PhysHeapFree(pReq);
1048 fail1:
1049 kfree(mask);
1050
1051 fail0:
1052 return err;
1053}
1054
1055
1056/**
1057 * This is called during name resolution/lookup to check if the @a dentry in the
1058 * cache is still valid. The actual validation is job is handled by
1059 * vbsf_inode_revalidate_worker().
1060 */
1061#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0)
1062static int vbsf_dentry_revalidate(struct dentry *dentry, unsigned flags)
1063#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
1064static int vbsf_dentry_revalidate(struct dentry *dentry, struct nameidata *nd)
1065#else
1066static int vbsf_dentry_revalidate(struct dentry *dentry, int flags)
1067#endif
1068{
1069#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0) && LINUX_VERSION_CODE < KERNEL_VERSION(3, 6, 0)
1070 int const flags = nd ? nd->flags : 0;
1071#endif
1072
1073 int rc;
1074
1075 Assert(dentry);
1076 SFLOGFLOW(("vbsf_dentry_revalidate: %p %#x %s\n", dentry, flags,
1077 dentry->d_inode ? VBSF_GET_INODE_INFO(dentry->d_inode)->path->String.ach : "<negative>"));
1078
1079 /*
1080 * See Documentation/filesystems/vfs.txt why we skip LOOKUP_RCU.
1081 *
1082 * Also recommended: https://lwn.net/Articles/649115/
1083 * https://lwn.net/Articles/649729/
1084 * https://lwn.net/Articles/650786/
1085 *
1086 */
1087#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 38)
1088 if (flags & LOOKUP_RCU) {
1089 rc = -ECHILD;
1090 SFLOGFLOW(("vbsf_dentry_revalidate: RCU -> -ECHILD\n"));
1091 } else
1092#endif
1093 {
1094 /*
1095 * Do we have an inode or not? If not it's probably a negative cache
1096 * entry, otherwise most likely a positive one.
1097 */
1098 struct inode *pInode = dentry->d_inode;
1099 if (pInode) {
1100 /*
1101 * Positive entry.
1102 *
1103 * Note! We're more aggressive here than other remote file systems,
1104 * current (4.19) CIFS will for instance revalidate the inode
1105 * and ignore the dentry timestamp for positive entries.
1106 */
1107 //struct vbsf_inode_info *sf_i = VBSF_GET_INODE_INFO(pInode);
1108 unsigned long const cJiffiesAge = vbsf_dentry_get_update_jiffies(dentry) - jiffies;
1109 struct vbsf_super_info *sf_g = VBSF_GET_SUPER_INFO(dentry->d_sb);
1110 if (cJiffiesAge < sf_g->ttl) {
1111 SFLOGFLOW(("vbsf_dentry_revalidate: age: %lu vs. TTL %lu -> 1\n", cJiffiesAge, sf_g->ttl));
1112 rc = 1;
1113 } else if (!vbsf_inode_revalidate_worker(dentry, true /*fForced*/)) {
1114 vbsf_dentry_set_update_jiffies(dentry, jiffies); /** @todo get jiffies from inode. */
1115 SFLOGFLOW(("vbsf_dentry_revalidate: age: %lu vs. TTL %lu -> reval -> 1\n", cJiffiesAge, sf_g->ttl));
1116 rc = 1;
1117 } else {
1118 SFLOGFLOW(("vbsf_dentry_revalidate: age: %lu vs. TTL %lu -> reval -> 0\n", cJiffiesAge, sf_g->ttl));
1119 rc = 0;
1120 }
1121 } else {
1122 /*
1123 * Negative entry.
1124 *
1125 * Invalidate dentries for open and renames here as we'll revalidate
1126 * these when taking the actual action (also good for case preservation
1127 * if we do case-insensitive mounts against windows + mac hosts at some
1128 * later point).
1129 */
1130#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28)
1131 if (flags & (LOOKUP_CREATE | LOOKUP_RENAME_TARGET))
1132#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 75)
1133 if (flags & LOOKUP_CREATE)
1134#else
1135 if (0)
1136#endif
1137 {
1138 SFLOGFLOW(("vbsf_dentry_revalidate: negative: create or rename target -> 0\n"));
1139 rc = 0;
1140 } else {
1141 /* Can we skip revalidation based on TTL? */
1142 unsigned long const cJiffiesAge = vbsf_dentry_get_update_jiffies(dentry) - jiffies;
1143 struct vbsf_super_info *sf_g = VBSF_GET_SUPER_INFO(dentry->d_sb);
1144 if (cJiffiesAge < sf_g->ttl) {
1145 SFLOGFLOW(("vbsf_dentry_revalidate: negative: age: %lu vs. TTL %lu -> 1\n", cJiffiesAge, sf_g->ttl));
1146 rc = 1;
1147 } else {
1148 /* We could revalidate it here, but we could instead just
1149 have the caller kick it out. */
1150 /** @todo stat the direntry and see if it exists now. */
1151 SFLOGFLOW(("vbsf_dentry_revalidate: negative: age: %lu vs. TTL %lu -> 0\n", cJiffiesAge, sf_g->ttl));
1152 rc = 0;
1153 }
1154 }
1155 }
1156 }
1157 return rc;
1158}
1159
1160#ifdef SFLOG_ENABLED
1161
1162/** For logging purposes only. */
1163# if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 38)
1164static int vbsf_dentry_delete(const struct dentry *pDirEntry)
1165# else
1166static int vbsf_dentry_delete(struct dentry *pDirEntry)
1167# endif
1168{
1169 SFLOGFLOW(("vbsf_dentry_delete: %p\n", pDirEntry));
1170 return 0;
1171}
1172
1173# if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0)
1174/** For logging purposes only. */
1175static int vbsf_dentry_init(struct dentry *pDirEntry)
1176{
1177 SFLOGFLOW(("vbsf_dentry_init: %p\n", pDirEntry));
1178 return 0;
1179}
1180# endif
1181
1182#endif /* SFLOG_ENABLED */
1183
1184/**
1185 * Directory entry operations.
1186 *
1187 * Since 2.6.38 this is used via the super_block::s_d_op member.
1188 */
1189struct dentry_operations vbsf_dentry_ops = {
1190 .d_revalidate = vbsf_dentry_revalidate,
1191#ifdef SFLOG_ENABLED
1192 .d_delete = vbsf_dentry_delete,
1193# if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0)
1194 .d_init = vbsf_dentry_init,
1195# endif
1196#endif
1197};
1198
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