summaryrefslogtreecommitdiffstats
path: root/sys/compat
diff options
context:
space:
mode:
authorpjd <pjd@FreeBSD.org>2005-06-09 17:44:46 +0000
committerpjd <pjd@FreeBSD.org>2005-06-09 17:44:46 +0000
commit3af857a21ae29e6bd992143c332930401686617d (patch)
tree11a9edf30c5981a81932d35c358f4a0ab56990f8 /sys/compat
parentcd5038ab36b62fd0d3378b0486ebd1c1a0b27b65 (diff)
downloadFreeBSD-src-3af857a21ae29e6bd992143c332930401686617d.zip
FreeBSD-src-3af857a21ae29e6bd992143c332930401686617d.tar.gz
Avoid code duplication in serval places by introducing universal
kern_getfsstat() function. Obtained from: jhb
Diffstat (limited to 'sys/compat')
-rw-r--r--sys/compat/freebsd32/freebsd32_misc.c41
1 files changed, 19 insertions, 22 deletions
diff --git a/sys/compat/freebsd32/freebsd32_misc.c b/sys/compat/freebsd32/freebsd32_misc.c
index 1469c3e..1c003a0 100644
--- a/sys/compat/freebsd32/freebsd32_misc.c
+++ b/sys/compat/freebsd32/freebsd32_misc.c
@@ -156,32 +156,29 @@ copy_statfs(struct statfs *in, struct statfs32 *out)
int
freebsd4_freebsd32_getfsstat(struct thread *td, struct freebsd4_freebsd32_getfsstat_args *uap)
{
+ struct statfs *buf, *sp;
+ struct statfs32 stat32;
+ size_t count, size;
int error;
- caddr_t sg;
- struct statfs32 *sp32, stat32;
- struct statfs *sp = NULL, stat;
- int maxcount, count, i;
-
- sp32 = uap->buf;
- maxcount = uap->bufsize / sizeof(struct statfs32);
- if (sp32) {
- sg = stackgap_init();
- sp = stackgap_alloc(&sg, sizeof(struct statfs) * maxcount);
- uap->buf = (struct statfs32 *)sp;
- }
- error = getfsstat(td, (struct getfsstat_args *) uap);
- if (sp32 && !error) {
+ count = uap->bufsize / sizeof(struct statfs32);
+ size = count * sizeof(struct statfs);
+ if (size > 0)
+ buf = malloc(size, M_TEMP, M_WAITOK);
+ else
+ buf = NULL;
+ error = kern_getfsstat(td, buf, size, UIO_SYSSPACE, uap->flags);
+ if (buf != NULL) {
count = td->td_retval[0];
- for (i = 0; i < count; i++) {
- error = copyin(&sp[i], &stat, sizeof(stat));
- if (error)
- return (error);
- copy_statfs(&stat, &stat32);
- error = copyout(&stat32, &sp32[i], sizeof(stat32));
- if (error)
- return (error);
+ sp = buf;
+ while (count > 0 && error == 0) {
+ copy_statfs(sp, &stat32);
+ error = copyout(&stat32, uap->buf, sizeof(stat32));
+ sp++;
+ uap->buf++;
+ count--;
}
+ free(buf, M_TEMP);
}
return (error);
}
OpenPOWER on IntegriCloud