* Check if a named file exists in a given directory vnode. */
| 348 | * Check if a named file exists in a given directory vnode. |
| 349 | */ |
| 350 | static int |
| 351 | dirent_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 | |
| 388 | out: |
| 389 | free(dirbuf, M_TEMP); |
| 390 | return (found); |
| 391 | } |
| 392 | |
| 393 | int |
| 394 | vop_stdaccess(struct vop_access_args *ap) |
no test coverage detected