MCPcopy Create free account
hub / github.com/F-Stack/f-stack / dirent_exists

Function dirent_exists

freebsd/kern/vfs_default.c:350–391  ·  view source on GitHub ↗

* Check if a named file exists in a given directory vnode. */

Source from the content-addressed store, hash-verified

348 * Check if a named file exists in a given directory vnode.
349 */
350static int
351dirent_exists(struct vnode *vp, const char *dirname, struct thread *td)
352{
353 char *dirbuf, *cpos;
354 int error, eofflag, dirbuflen, len, found;
355 off_t off;
356 struct dirent *dp;
357 struct vattr va;
358
359 KASSERT(VOP_ISLOCKED(vp), ("vp %p is not locked", vp));
360 KASSERT(vp->v_type == VDIR, ("vp %p is not a directory", vp));
361
362 found = 0;
363
364 error = VOP_GETATTR(vp, &va, td->td_ucred);
365 if (error)
366 return (found);
367
368 dirbuflen = DEV_BSIZE;
369 if (dirbuflen < va.va_blocksize)
370 dirbuflen = va.va_blocksize;
371 dirbuf = (char *)malloc(dirbuflen, M_TEMP, M_WAITOK);
372
373 off = 0;
374 len = 0;
375 do {
376 error = get_next_dirent(vp, &dp, dirbuf, dirbuflen, &off,
377 &cpos, &len, &eofflag, td);
378 if (error)
379 goto out;
380
381 if (dp->d_type != DT_WHT && dp->d_fileno != 0 &&
382 strcmp(dp->d_name, dirname) == 0) {
383 found = 1;
384 goto out;
385 }
386 } while (len > 0 || !eofflag);
387
388out:
389 free(dirbuf, M_TEMP);
390 return (found);
391}
392
393int
394vop_stdaccess(struct vop_access_args *ap)

Callers 1

vop_stdvptocnpFunction · 0.85

Calls 5

VOP_GETATTRFunction · 0.85
mallocFunction · 0.85
get_next_direntFunction · 0.85
strcmpFunction · 0.85
freeFunction · 0.70

Tested by

no test coverage detected