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

Function kern_getfsstat

freebsd/kern/vfs_syscalls.c:424–583  ·  view source on GitHub ↗

* If (bufsize > 0 && bufseg == UIO_SYSSPACE) * The caller is responsible for freeing memory which will be allocated * in '*buf'. */

Source from the content-addressed store, hash-verified

422 * in '*buf'.
423 */
424int
425kern_getfsstat(struct thread *td, struct statfs **buf, size_t bufsize,
426 size_t *countp, enum uio_seg bufseg, int mode)
427{
428 struct mount *mp, *nmp;
429 struct statfs *sfsp, *sp, *sptmp, *tofree;
430 size_t count, maxcount;
431 int error;
432
433 switch (mode) {
434 case MNT_WAIT:
435 case MNT_NOWAIT:
436 break;
437 default:
438 if (bufseg == UIO_SYSSPACE)
439 *buf = NULL;
440 return (EINVAL);
441 }
442restart:
443 maxcount = bufsize / sizeof(struct statfs);
444 if (bufsize == 0) {
445 sfsp = NULL;
446 tofree = NULL;
447 } else if (bufseg == UIO_USERSPACE) {
448 sfsp = *buf;
449 tofree = NULL;
450 } else /* if (bufseg == UIO_SYSSPACE) */ {
451 count = 0;
452 mtx_lock(&mountlist_mtx);
453 TAILQ_FOREACH(mp, &mountlist, mnt_list) {
454 count++;
455 }
456 mtx_unlock(&mountlist_mtx);
457 if (maxcount > count)
458 maxcount = count;
459 tofree = sfsp = *buf = malloc(maxcount * sizeof(struct statfs),
460 M_STATFS, M_WAITOK);
461 }
462
463 count = 0;
464
465 /*
466 * If there is no target buffer they only want the count.
467 *
468 * This could be TAILQ_FOREACH but it is open-coded to match the original
469 * code below.
470 */
471 if (sfsp == NULL) {
472 mtx_lock(&mountlist_mtx);
473 for (mp = TAILQ_FIRST(&mountlist); mp != NULL; mp = nmp) {
474 if (prison_canseemount(td->td_ucred, mp) != 0) {
475 nmp = TAILQ_NEXT(mp, mnt_list);
476 continue;
477 }
478#ifdef MAC
479 if (mac_mount_check_stat(td->td_ucred, mp) != 0) {
480 nmp = TAILQ_NEXT(mp, mnt_list);
481 continue;

Callers 3

sys_getfsstatFunction · 0.85
freebsd4_getfsstatFunction · 0.85
freebsd11_getfsstatFunction · 0.85

Calls 11

mallocFunction · 0.85
prison_canseemountFunction · 0.85
mac_mount_check_statFunction · 0.85
vfs_busyFunction · 0.85
vfs_unbusyFunction · 0.85
prison_enforce_statfsFunction · 0.85
mtx_lockFunction · 0.70
mtx_unlockFunction · 0.70
freeFunction · 0.70
copyoutFunction · 0.50

Tested by

no test coverage detected