VirtualBox

source: vbox/trunk/src/VBox/Additions/linux/sharedfolders/utils.c@ 77532

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

linux/vboxsf: More cleanups. bugref:9172

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 39.0 KB
Line 
1/* $Id: utils.c 77532 2019-03-01 14:48:05Z 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 SHFLHANDLE hHostFile;
587 int vrc;
588 int err = 0;
589
590 TRACE();
591
592 sf_g = VBSF_GET_SUPER_INFO(dentry->d_inode->i_sb);
593 sf_i = VBSF_GET_INODE_INFO(dentry->d_inode);
594 cbReq = RT_MAX(sizeof(pReq->Info), sizeof(pReq->Create) + SHFLSTRING_HEADER_SIZE + sf_i->path->u16Size);
595 pReq = (union SetAttrReqs *)VbglR0PhysHeapAlloc(cbReq);
596 if (!pReq) {
597 LogFunc(("Failed to allocate %#x byte request buffer!\n", cbReq));
598 return -ENOMEM;
599 }
600
601 RT_ZERO(pReq->Create.CreateParms);
602 pReq->Create.CreateParms.Handle = SHFL_HANDLE_NIL;
603 pReq->Create.CreateParms.CreateFlags = SHFL_CF_ACT_OPEN_IF_EXISTS
604 | SHFL_CF_ACT_FAIL_IF_NEW
605 | SHFL_CF_ACCESS_ATTR_WRITE;
606
607 /* this is at least required for Posix hosts */
608 if (iattr->ia_valid & ATTR_SIZE)
609 pReq->Create.CreateParms.CreateFlags |= SHFL_CF_ACCESS_WRITE;
610
611 memcpy(&pReq->Create.StrPath, sf_i->path, SHFLSTRING_HEADER_SIZE + sf_i->path->u16Size);
612 vrc = VbglR0SfHostReqCreate(sf_g->map.root, &pReq->Create);
613 if (RT_SUCCESS(vrc)) {
614 hHostFile = pReq->Create.CreateParms.Handle;
615 } else {
616 err = -RTErrConvertToErrno(vrc);
617 LogFunc(("VbglR0SfCreate(%s) failed vrc=%Rrc err=%d\n", sf_i->path->String.ach, vrc, err));
618 goto fail2;
619 }
620 if (pReq->Create.CreateParms.Result != SHFL_FILE_EXISTS) {
621 LogFunc(("file %s does not exist\n", sf_i->path->String.utf8));
622 err = -ENOENT;
623 goto fail1;
624 }
625
626 /* Setting the file size and setting the other attributes has to be
627 * handled separately, see implementation of vbsfSetFSInfo() in
628 * vbsf.cpp */
629 if (iattr->ia_valid & (ATTR_MODE | ATTR_ATIME | ATTR_MTIME)) {
630 RT_ZERO(pReq->Info.ObjInfo);
631
632 if (iattr->ia_valid & ATTR_MODE) {
633 pReq->Info.ObjInfo.Attr.fMode = sf_access_permissions_to_vbox(iattr->ia_mode);
634 if (iattr->ia_mode & S_IFDIR)
635 pReq->Info.ObjInfo.Attr.fMode |= RTFS_TYPE_DIRECTORY;
636 else if (iattr->ia_mode & S_IFLNK)
637 pReq->Info.ObjInfo.Attr.fMode |= RTFS_TYPE_SYMLINK;
638 else
639 pReq->Info.ObjInfo.Attr.fMode |= RTFS_TYPE_FILE;
640 }
641
642 if (iattr->ia_valid & ATTR_ATIME)
643 vbsf_time_to_vbox(&pReq->Info.ObjInfo.AccessTime, &iattr->ia_atime);
644 if (iattr->ia_valid & ATTR_MTIME)
645 vbsf_time_to_vbox(&pReq->Info.ObjInfo.ModificationTime, &iattr->ia_mtime);
646 /* ignore ctime (inode change time) as it can't be set from userland anyway */
647
648 vrc = VbglR0SfHostReqSetObjInfo(sf_g->map.root, &pReq->Info, hHostFile);
649 if (RT_FAILURE(vrc)) {
650 err = -RTErrConvertToErrno(vrc);
651 LogFunc(("VbglR0SfHostReqSetObjInfo(%s) failed vrc=%Rrc err=%d\n", sf_i->path->String.ach, vrc, err));
652 goto fail1;
653 }
654 }
655
656 if (iattr->ia_valid & ATTR_SIZE) {
657 vrc = VbglR0SfHostReqSetFileSize(sf_g->map.root, &pReq->SetSize, hHostFile, iattr->ia_size);
658 /** @todo Implement fallback if host is < 6.0? */
659 if (RT_FAILURE(vrc)) {
660 err = -RTErrConvertToErrno(vrc);
661 LogFunc(("VbglR0SfHostReqSetFileSize(%s, %#llx) failed vrc=%Rrc err=%d\n",
662 sf_i->path->String.ach, (unsigned long long)iattr->ia_size, vrc, err));
663 goto fail1;
664 }
665 }
666
667 vrc = VbglR0SfHostReqClose(sf_g->map.root, &pReq->Close, hHostFile);
668 if (RT_FAILURE(vrc))
669 LogFunc(("VbglR0SfHostReqClose(%s [%#llx]) failed vrc=%Rrc\n", sf_i->path->String.utf8, hHostFile, vrc));
670 VbglR0PhysHeapFree(pReq);
671
672 /** @todo r=bird: I guess we're calling revalidate here to update the inode
673 * info. However, due to the TTL optimization this is not guarenteed to happen.
674 *
675 * Also, we already have accurate stat information on the file, either from the
676 * SHFL_FN_CREATE call or from SHFL_FN_INFORMATION, so there is no need to do a
677 * slow stat()-like operation to retrieve the information again.
678 *
679 * What's more, given that the SHFL_FN_CREATE call succeeded, we know that the
680 * dentry and all its parent entries are valid and could touch their timestamps
681 * extending their TTL (CIFS does that). */
682 return vbsf_inode_revalidate_worker(dentry, true /*fForced*/);
683
684 fail1:
685 vrc = VbglR0SfHostReqClose(sf_g->map.root, &pReq->Close, hHostFile);
686 if (RT_FAILURE(vrc))
687 LogFunc(("VbglR0SfHostReqClose(%s [%#llx]) failed vrc=%Rrc; err=%d\n", sf_i->path->String.utf8, hHostFile, vrc, err));
688
689 fail2:
690 VbglR0PhysHeapFree(pReq);
691 return err;
692}
693
694#endif /* >= 2.6.0 */
695
696static int vbsf_make_path(const char *caller, struct vbsf_inode_info *sf_i,
697 const char *d_name, size_t d_len, SHFLSTRING **result)
698{
699 size_t path_len, shflstring_len;
700 SHFLSTRING *tmp;
701 uint16_t p_len;
702 uint8_t *p_name;
703 int fRoot = 0;
704
705 TRACE();
706 p_len = sf_i->path->u16Length;
707 p_name = sf_i->path->String.utf8;
708
709 if (p_len == 1 && *p_name == '/') {
710 path_len = d_len + 1;
711 fRoot = 1;
712 } else {
713 /* lengths of constituents plus terminating zero plus slash */
714 path_len = p_len + d_len + 2;
715 if (path_len > 0xffff) {
716 LogFunc(("path too long. caller=%s, path_len=%zu\n",
717 caller, path_len));
718 return -ENAMETOOLONG;
719 }
720 }
721
722 shflstring_len = offsetof(SHFLSTRING, String.utf8) + path_len;
723 tmp = kmalloc(shflstring_len, GFP_KERNEL);
724 if (!tmp) {
725 LogRelFunc(("kmalloc failed, caller=%s\n", caller));
726 return -ENOMEM;
727 }
728 tmp->u16Length = path_len - 1;
729 tmp->u16Size = path_len;
730
731 if (fRoot)
732 memcpy(&tmp->String.utf8[0], d_name, d_len + 1);
733 else {
734 memcpy(&tmp->String.utf8[0], p_name, p_len);
735 tmp->String.utf8[p_len] = '/';
736 memcpy(&tmp->String.utf8[p_len + 1], d_name, d_len);
737 tmp->String.utf8[p_len + 1 + d_len] = '\0';
738 }
739
740 *result = tmp;
741 return 0;
742}
743
744/**
745 * [dentry] contains string encoded in coding system that corresponds
746 * to [sf_g]->nls, we must convert it to UTF8 here and pass down to
747 * [vbsf_make_path] which will allocate SHFLSTRING and fill it in
748 */
749int vbsf_path_from_dentry(const char *caller, struct vbsf_super_info *sf_g, struct vbsf_inode_info *sf_i,
750 struct dentry *dentry, SHFLSTRING **result)
751{
752 int err;
753 const char *d_name;
754 size_t d_len;
755 const char *name;
756 size_t len = 0;
757
758 TRACE();
759 d_name = dentry->d_name.name;
760 d_len = dentry->d_name.len;
761
762 if (sf_g->nls) {
763 size_t in_len, i, out_bound_len;
764 const char *in;
765 char *out;
766
767 in = d_name;
768 in_len = d_len;
769
770 out_bound_len = PATH_MAX;
771 out = kmalloc(out_bound_len, GFP_KERNEL);
772 name = out;
773
774 for (i = 0; i < d_len; ++i) {
775 /* We renamed the linux kernel wchar_t type to linux_wchar_t in
776 the-linux-kernel.h, as it conflicts with the C++ type of that name. */
777 linux_wchar_t uni;
778 int nb;
779
780 nb = sf_g->nls->char2uni(in, in_len, &uni);
781 if (nb < 0) {
782 LogFunc(("nls->char2uni failed %x %d\n",
783 *in, in_len));
784 err = -EINVAL;
785 goto fail1;
786 }
787 in_len -= nb;
788 in += nb;
789
790#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31)
791 nb = utf32_to_utf8(uni, out, out_bound_len);
792#else
793 nb = utf8_wctomb(out, uni, out_bound_len);
794#endif
795 if (nb < 0) {
796 LogFunc(("nls->uni2char failed %x %d\n",
797 uni, out_bound_len));
798 err = -EINVAL;
799 goto fail1;
800 }
801 out_bound_len -= nb;
802 out += nb;
803 len += nb;
804 }
805 if (len >= PATH_MAX - 1) {
806 err = -ENAMETOOLONG;
807 goto fail1;
808 }
809
810 LogFunc(("result(%d) = %.*s\n", len, len, name));
811 *out = 0;
812 } else {
813 name = d_name;
814 len = d_len;
815 }
816
817 err = vbsf_make_path(caller, sf_i, name, len, result);
818 if (name != d_name)
819 kfree(name);
820
821 return err;
822
823 fail1:
824 kfree(name);
825 return err;
826}
827
828int vbsf_nlscpy(struct vbsf_super_info *sf_g, char *name, size_t name_bound_len, const unsigned char *utf8_name, size_t utf8_len)
829{
830 if (sf_g->nls) {
831 const char *in;
832 char *out;
833 size_t out_len;
834 size_t out_bound_len;
835 size_t in_bound_len;
836
837 in = utf8_name;
838 in_bound_len = utf8_len;
839
840 out = name;
841 out_len = 0;
842 out_bound_len = name_bound_len;
843
844 while (in_bound_len) {
845 int nb;
846#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31)
847 unicode_t uni;
848
849 nb = utf8_to_utf32(in, in_bound_len, &uni);
850#else
851 linux_wchar_t uni;
852
853 nb = utf8_mbtowc(&uni, in, in_bound_len);
854#endif
855 if (nb < 0) {
856 LogFunc(("utf8_mbtowc failed(%s) %x:%d\n",
857 (const char *)utf8_name, *in,
858 in_bound_len));
859 return -EINVAL;
860 }
861 in += nb;
862 in_bound_len -= nb;
863
864 nb = sf_g->nls->uni2char(uni, out, out_bound_len);
865 if (nb < 0) {
866 LogFunc(("nls->uni2char failed(%s) %x:%d\n",
867 utf8_name, uni, out_bound_len));
868 return nb;
869 }
870 out += nb;
871 out_bound_len -= nb;
872 out_len += nb;
873 }
874
875 *out = 0;
876 } else {
877 if (utf8_len + 1 > name_bound_len)
878 return -ENAMETOOLONG;
879
880 memcpy(name, utf8_name, utf8_len + 1);
881 }
882 return 0;
883}
884
885static struct vbsf_dir_buf *vbsf_dir_buf_alloc(void)
886{
887 struct vbsf_dir_buf *b;
888
889 TRACE();
890 b = kmalloc(sizeof(*b), GFP_KERNEL);
891 if (!b) {
892 LogRelFunc(("could not alloc directory buffer\n"));
893 return NULL;
894 }
895 b->buf = kmalloc(DIR_BUFFER_SIZE, GFP_KERNEL);
896 if (!b->buf) {
897 kfree(b);
898 LogRelFunc(("could not alloc directory buffer storage\n"));
899 return NULL;
900 }
901
902 INIT_LIST_HEAD(&b->head);
903 b->cEntries = 0;
904 b->cbUsed = 0;
905 b->cbFree = DIR_BUFFER_SIZE;
906 return b;
907}
908
909static void vbsf_dir_buf_free(struct vbsf_dir_buf *b)
910{
911 BUG_ON(!b || !b->buf);
912
913 TRACE();
914 list_del(&b->head);
915 kfree(b->buf);
916 kfree(b);
917}
918
919/**
920 * Free the directory buffer.
921 */
922void vbsf_dir_info_free(struct vbsf_dir_info *p)
923{
924 struct list_head *list, *pos, *tmp;
925
926 TRACE();
927 list = &p->info_list;
928 list_for_each_safe(pos, tmp, list) {
929 struct vbsf_dir_buf *b;
930
931 b = list_entry(pos, struct vbsf_dir_buf, head);
932 vbsf_dir_buf_free(b);
933 }
934 kfree(p);
935}
936
937/**
938 * Empty (but not free) the directory buffer.
939 */
940void vbsf_dir_info_empty(struct vbsf_dir_info *p)
941{
942 struct list_head *list, *pos, *tmp;
943 TRACE();
944 list = &p->info_list;
945 list_for_each_safe(pos, tmp, list) {
946 struct vbsf_dir_buf *b;
947 b = list_entry(pos, struct vbsf_dir_buf, head);
948 b->cEntries = 0;
949 b->cbUsed = 0;
950 b->cbFree = DIR_BUFFER_SIZE;
951 }
952}
953
954/**
955 * Create a new directory buffer descriptor.
956 */
957struct vbsf_dir_info *vbsf_dir_info_alloc(void)
958{
959 struct vbsf_dir_info *p;
960
961 TRACE();
962 p = kmalloc(sizeof(*p), GFP_KERNEL);
963 if (!p) {
964 LogRelFunc(("could not alloc directory info\n"));
965 return NULL;
966 }
967
968 INIT_LIST_HEAD(&p->info_list);
969 return p;
970}
971
972/**
973 * Search for an empty directory content buffer.
974 */
975static struct vbsf_dir_buf *vbsf_get_empty_dir_buf(struct vbsf_dir_info *sf_d)
976{
977 struct list_head *list, *pos;
978
979 list = &sf_d->info_list;
980 list_for_each(pos, list) {
981 struct vbsf_dir_buf *b;
982
983 b = list_entry(pos, struct vbsf_dir_buf, head);
984 if (!b)
985 return NULL;
986 else {
987 if (b->cbUsed == 0)
988 return b;
989 }
990 }
991
992 return NULL;
993}
994
995/** @todo r=bird: Why on earth do we read in the entire directory??? This
996 * cannot be healthy for like big directory and such... */
997int vbsf_dir_read_all(struct vbsf_super_info *sf_g, struct vbsf_inode_info *sf_i, struct vbsf_dir_info *sf_d, SHFLHANDLE handle)
998{
999 int err;
1000 SHFLSTRING *mask;
1001 VBOXSFLISTDIRREQ *pReq = NULL;
1002
1003 TRACE();
1004 err = vbsf_make_path(__func__, sf_i, "*", 1, &mask);
1005 if (err)
1006 goto fail0;
1007 pReq = (VBOXSFLISTDIRREQ *)VbglR0PhysHeapAlloc(sizeof(*pReq));
1008 if (!pReq)
1009 goto fail1;
1010
1011 for (;;) {
1012 int rc;
1013 struct vbsf_dir_buf *b;
1014
1015 b = vbsf_get_empty_dir_buf(sf_d);
1016 if (!b) {
1017 b = vbsf_dir_buf_alloc();
1018 if (!b) {
1019 err = -ENOMEM;
1020 LogRelFunc(("could not alloc directory buffer\n"));
1021 goto fail2;
1022 }
1023 list_add(&b->head, &sf_d->info_list);
1024 }
1025
1026 rc = VbglR0SfHostReqListDirContig2x(sf_g->map.root, pReq, handle, mask, virt_to_phys(mask),
1027 0 /*fFlags*/, b->buf, virt_to_phys(b->buf), b->cbFree);
1028 if (RT_SUCCESS(rc)) {
1029 b->cEntries += pReq->Parms.c32Entries.u.value32;
1030 b->cbFree -= pReq->Parms.cb32Buffer.u.value32;
1031 b->cbUsed += pReq->Parms.cb32Buffer.u.value32;
1032 } else if (rc == VERR_NO_MORE_FILES) {
1033 break;
1034 } else {
1035 err = -RTErrConvertToErrno(rc);
1036 LogFunc(("VbglR0SfHostReqListDirContig2x failed rc=%Rrc err=%d\n", rc, err));
1037 goto fail2;
1038 }
1039 }
1040 err = 0;
1041
1042 fail2:
1043 VbglR0PhysHeapFree(pReq);
1044 fail1:
1045 kfree(mask);
1046
1047 fail0:
1048 return err;
1049}
1050
1051
1052/**
1053 * This is called during name resolution/lookup to check if the @a dentry in the
1054 * cache is still valid. The actual validation is job is handled by
1055 * vbsf_inode_revalidate_worker().
1056 */
1057#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0)
1058static int vbsf_dentry_revalidate(struct dentry *dentry, unsigned flags)
1059#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
1060static int vbsf_dentry_revalidate(struct dentry *dentry, struct nameidata *nd)
1061#else
1062static int vbsf_dentry_revalidate(struct dentry *dentry, int flags)
1063#endif
1064{
1065#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0) && LINUX_VERSION_CODE < KERNEL_VERSION(3, 6, 0)
1066 int const flags = nd ? nd->flags : 0;
1067#endif
1068
1069 int rc;
1070
1071 Assert(dentry);
1072 SFLOGFLOW(("vbsf_dentry_revalidate: %p %#x %s\n", dentry, flags,
1073 dentry->d_inode ? VBSF_GET_INODE_INFO(dentry->d_inode)->path->String.ach : "<negative>"));
1074
1075 /*
1076 * See Documentation/filesystems/vfs.txt why we skip LOOKUP_RCU.
1077 *
1078 * Also recommended: https://lwn.net/Articles/649115/
1079 * https://lwn.net/Articles/649729/
1080 * https://lwn.net/Articles/650786/
1081 *
1082 */
1083#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 38)
1084 if (flags & LOOKUP_RCU) {
1085 rc = -ECHILD;
1086 SFLOGFLOW(("vbsf_dentry_revalidate: RCU -> -ECHILD\n"));
1087 } else
1088#endif
1089 {
1090 /*
1091 * Do we have an inode or not? If not it's probably a negative cache
1092 * entry, otherwise most likely a positive one.
1093 */
1094 struct inode *pInode = dentry->d_inode;
1095 if (pInode) {
1096 /*
1097 * Positive entry.
1098 *
1099 * Note! We're more aggressive here than other remote file systems,
1100 * current (4.19) CIFS will for instance revalidate the inode
1101 * and ignore the dentry timestamp for positive entries.
1102 */
1103 //struct vbsf_inode_info *sf_i = VBSF_GET_INODE_INFO(pInode);
1104 unsigned long const cJiffiesAge = vbsf_dentry_get_update_jiffies(dentry) - jiffies;
1105 struct vbsf_super_info *sf_g = VBSF_GET_SUPER_INFO(dentry->d_sb);
1106 if (cJiffiesAge < sf_g->ttl) {
1107 SFLOGFLOW(("vbsf_dentry_revalidate: age: %lu vs. TTL %lu -> 1\n", cJiffiesAge, sf_g->ttl));
1108 rc = 1;
1109 } else if (!vbsf_inode_revalidate_worker(dentry, true /*fForced*/)) {
1110 vbsf_dentry_set_update_jiffies(dentry, jiffies); /** @todo get jiffies from inode. */
1111 SFLOGFLOW(("vbsf_dentry_revalidate: age: %lu vs. TTL %lu -> reval -> 1\n", cJiffiesAge, sf_g->ttl));
1112 rc = 1;
1113 } else {
1114 SFLOGFLOW(("vbsf_dentry_revalidate: age: %lu vs. TTL %lu -> reval -> 0\n", cJiffiesAge, sf_g->ttl));
1115 rc = 0;
1116 }
1117 } else {
1118 /*
1119 * Negative entry.
1120 *
1121 * Invalidate dentries for open and renames here as we'll revalidate
1122 * these when taking the actual action (also good for case preservation
1123 * if we do case-insensitive mounts against windows + mac hosts at some
1124 * later point).
1125 */
1126#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28)
1127 if (flags & (LOOKUP_CREATE | LOOKUP_RENAME_TARGET))
1128#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 75)
1129 if (flags & LOOKUP_CREATE)
1130#else
1131 if (0)
1132#endif
1133 {
1134 SFLOGFLOW(("vbsf_dentry_revalidate: negative: create or rename target -> 0\n"));
1135 rc = 0;
1136 } else {
1137 /* Can we skip revalidation based on TTL? */
1138 unsigned long const cJiffiesAge = vbsf_dentry_get_update_jiffies(dentry) - jiffies;
1139 struct vbsf_super_info *sf_g = VBSF_GET_SUPER_INFO(dentry->d_sb);
1140 if (cJiffiesAge < sf_g->ttl) {
1141 SFLOGFLOW(("vbsf_dentry_revalidate: negative: age: %lu vs. TTL %lu -> 1\n", cJiffiesAge, sf_g->ttl));
1142 rc = 1;
1143 } else {
1144 /* We could revalidate it here, but we could instead just
1145 have the caller kick it out. */
1146 /** @todo stat the direntry and see if it exists now. */
1147 SFLOGFLOW(("vbsf_dentry_revalidate: negative: age: %lu vs. TTL %lu -> 0\n", cJiffiesAge, sf_g->ttl));
1148 rc = 0;
1149 }
1150 }
1151 }
1152 }
1153 return rc;
1154}
1155
1156#ifdef SFLOG_ENABLED
1157
1158/** For logging purposes only. */
1159# if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 38)
1160static int vbsf_dentry_delete(const struct dentry *pDirEntry)
1161# else
1162static int vbsf_dentry_delete(struct dentry *pDirEntry)
1163# endif
1164{
1165 SFLOGFLOW(("vbsf_dentry_delete: %p\n", pDirEntry));
1166 return 0;
1167}
1168
1169# if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0)
1170/** For logging purposes only. */
1171static int vbsf_dentry_init(struct dentry *pDirEntry)
1172{
1173 SFLOGFLOW(("vbsf_dentry_init: %p\n", pDirEntry));
1174 return 0;
1175}
1176# endif
1177
1178#endif /* SFLOG_ENABLED */
1179
1180/**
1181 * Directory entry operations.
1182 *
1183 * Since 2.6.38 this is used via the super_block::s_d_op member.
1184 */
1185struct dentry_operations vbsf_dentry_ops = {
1186 .d_revalidate = vbsf_dentry_revalidate,
1187#ifdef SFLOG_ENABLED
1188 .d_delete = vbsf_dentry_delete,
1189# if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0)
1190 .d_init = vbsf_dentry_init,
1191# endif
1192#endif
1193};
1194
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