Changeset View
Changeset View
Standalone View
Standalone View
sys/compat/linux/linux_stats.c
Show First 20 Lines • Show All 166 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
#ifdef LINUX_LEGACY_SYSCALLS | #ifdef LINUX_LEGACY_SYSCALLS | ||||
int | int | ||||
linux_newstat(struct thread *td, struct linux_newstat_args *args) | linux_newstat(struct thread *td, struct linux_newstat_args *args) | ||||
{ | { | ||||
struct stat buf; | struct stat buf; | ||||
char *path; | |||||
int error; | int error; | ||||
if (!LUSECONVPATH(td)) { | |||||
error = linux_kern_stat(td, args->path, UIO_USERSPACE, &buf); | error = linux_kern_stat(td, args->path, UIO_USERSPACE, &buf); | ||||
} else { | |||||
LCONVPATHEXIST(args->path, &path); | |||||
error = linux_kern_stat(td, path, UIO_SYSSPACE, &buf); | |||||
LFREEPATH(path); | |||||
} | |||||
if (error) | if (error) | ||||
return (error); | return (error); | ||||
return (newstat_copyout(&buf, args->buf)); | return (newstat_copyout(&buf, args->buf)); | ||||
} | } | ||||
int | int | ||||
linux_newlstat(struct thread *td, struct linux_newlstat_args *args) | linux_newlstat(struct thread *td, struct linux_newlstat_args *args) | ||||
{ | { | ||||
struct stat sb; | struct stat sb; | ||||
char *path; | |||||
int error; | int error; | ||||
if (!LUSECONVPATH(td)) { | |||||
error = linux_kern_lstat(td, args->path, UIO_USERSPACE, &sb); | error = linux_kern_lstat(td, args->path, UIO_USERSPACE, &sb); | ||||
} else { | |||||
LCONVPATHEXIST(args->path, &path); | |||||
error = linux_kern_lstat(td, path, UIO_SYSSPACE, &sb); | |||||
LFREEPATH(path); | |||||
} | |||||
if (error) | if (error) | ||||
return (error); | return (error); | ||||
return (newstat_copyout(&sb, args->buf)); | return (newstat_copyout(&sb, args->buf)); | ||||
} | } | ||||
#endif | #endif | ||||
int | int | ||||
linux_newfstat(struct thread *td, struct linux_newfstat_args *args) | linux_newfstat(struct thread *td, struct linux_newfstat_args *args) | ||||
▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | old_stat_copyout(struct stat *buf, void *ubuf) | ||||
return (copyout(&lbuf, ubuf, sizeof(lbuf))); | return (copyout(&lbuf, ubuf, sizeof(lbuf))); | ||||
} | } | ||||
int | int | ||||
linux_stat(struct thread *td, struct linux_stat_args *args) | linux_stat(struct thread *td, struct linux_stat_args *args) | ||||
{ | { | ||||
struct stat buf; | struct stat buf; | ||||
char *path; | |||||
int error; | int error; | ||||
if (!LUSECONVPATH(td)) { | |||||
error = linux_kern_stat(td, args->path, UIO_USERSPACE, &buf); | error = linux_kern_stat(td, args->path, UIO_USERSPACE, &buf); | ||||
} else { | |||||
LCONVPATHEXIST(args->path, &path); | |||||
error = linux_kern_stat(td, path, UIO_SYSSPACE, &buf); | |||||
LFREEPATH(path); | |||||
} | |||||
if (error) { | if (error) { | ||||
return (error); | return (error); | ||||
} | } | ||||
return (old_stat_copyout(&buf, args->up)); | return (old_stat_copyout(&buf, args->up)); | ||||
} | } | ||||
int | int | ||||
linux_lstat(struct thread *td, struct linux_lstat_args *args) | linux_lstat(struct thread *td, struct linux_lstat_args *args) | ||||
{ | { | ||||
struct stat buf; | struct stat buf; | ||||
char *path; | |||||
int error; | int error; | ||||
if (!LUSECONVPATH(td)) { | |||||
error = linux_kern_lstat(td, args->path, UIO_USERSPACE, &buf); | error = linux_kern_lstat(td, args->path, UIO_USERSPACE, &buf); | ||||
} else { | |||||
LCONVPATHEXIST(args->path, &path); | |||||
error = linux_kern_lstat(td, path, UIO_SYSSPACE, &buf); | |||||
LFREEPATH(path); | |||||
} | |||||
if (error) { | if (error) { | ||||
return (error); | return (error); | ||||
} | } | ||||
return (old_stat_copyout(&buf, args->up)); | return (old_stat_copyout(&buf, args->up)); | ||||
} | } | ||||
#endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */ | #endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */ | ||||
struct l_statfs { | struct l_statfs { | ||||
▲ Show 20 Lines • Show All 102 Lines • ▼ Show 20 Lines | #endif | ||||
return (0); | return (0); | ||||
} | } | ||||
int | int | ||||
linux_statfs(struct thread *td, struct linux_statfs_args *args) | linux_statfs(struct thread *td, struct linux_statfs_args *args) | ||||
{ | { | ||||
struct l_statfs linux_statfs; | struct l_statfs linux_statfs; | ||||
struct statfs *bsd_statfs; | struct statfs *bsd_statfs; | ||||
char *path; | |||||
int error; | int error; | ||||
if (!LUSECONVPATH(td)) { | |||||
bsd_statfs = malloc(sizeof(struct statfs), M_STATFS, M_WAITOK); | bsd_statfs = malloc(sizeof(struct statfs), M_STATFS, M_WAITOK); | ||||
error = kern_statfs(td, args->path, UIO_USERSPACE, bsd_statfs); | error = kern_statfs(td, args->path, UIO_USERSPACE, bsd_statfs); | ||||
} else { | |||||
LCONVPATHEXIST(args->path, &path); | |||||
bsd_statfs = malloc(sizeof(struct statfs), M_STATFS, M_WAITOK); | |||||
error = kern_statfs(td, path, UIO_SYSSPACE, bsd_statfs); | |||||
LFREEPATH(path); | |||||
} | |||||
if (error == 0) | if (error == 0) | ||||
error = bsd_to_linux_statfs(bsd_statfs, &linux_statfs); | error = bsd_to_linux_statfs(bsd_statfs, &linux_statfs); | ||||
free(bsd_statfs, M_STATFS); | free(bsd_statfs, M_STATFS); | ||||
if (error != 0) | if (error != 0) | ||||
return (error); | return (error); | ||||
return (copyout(&linux_statfs, args->buf, sizeof(linux_statfs))); | return (copyout(&linux_statfs, args->buf, sizeof(linux_statfs))); | ||||
} | } | ||||
Show All 17 Lines | bsd_to_linux_statfs64(struct statfs *bsd_statfs, struct l_statfs64 *linux_statfs) | ||||
memset(linux_statfs->f_spare, 0, sizeof(linux_statfs->f_spare)); | memset(linux_statfs->f_spare, 0, sizeof(linux_statfs->f_spare)); | ||||
} | } | ||||
int | int | ||||
linux_statfs64(struct thread *td, struct linux_statfs64_args *args) | linux_statfs64(struct thread *td, struct linux_statfs64_args *args) | ||||
{ | { | ||||
struct l_statfs64 linux_statfs; | struct l_statfs64 linux_statfs; | ||||
struct statfs *bsd_statfs; | struct statfs *bsd_statfs; | ||||
char *path; | |||||
int error; | int error; | ||||
if (args->bufsize != sizeof(struct l_statfs64)) | if (args->bufsize != sizeof(struct l_statfs64)) | ||||
return (EINVAL); | return (EINVAL); | ||||
if (!LUSECONVPATH(td)) { | |||||
bsd_statfs = malloc(sizeof(struct statfs), M_STATFS, M_WAITOK); | bsd_statfs = malloc(sizeof(struct statfs), M_STATFS, M_WAITOK); | ||||
error = kern_statfs(td, args->path, UIO_USERSPACE, bsd_statfs); | error = kern_statfs(td, args->path, UIO_USERSPACE, bsd_statfs); | ||||
} else { | |||||
LCONVPATHEXIST(args->path, &path); | |||||
bsd_statfs = malloc(sizeof(struct statfs), M_STATFS, M_WAITOK); | |||||
error = kern_statfs(td, path, UIO_SYSSPACE, bsd_statfs); | |||||
LFREEPATH(path); | |||||
} | |||||
if (error == 0) | if (error == 0) | ||||
bsd_to_linux_statfs64(bsd_statfs, &linux_statfs); | bsd_to_linux_statfs64(bsd_statfs, &linux_statfs); | ||||
free(bsd_statfs, M_STATFS); | free(bsd_statfs, M_STATFS); | ||||
if (error != 0) | if (error != 0) | ||||
return (error); | return (error); | ||||
return (copyout(&linux_statfs, args->buf, sizeof(linux_statfs))); | return (copyout(&linux_statfs, args->buf, sizeof(linux_statfs))); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 87 Lines • ▼ Show 20 Lines | stat64_copyout(struct stat *buf, void *ubuf) | ||||
return (copyout(&lbuf, ubuf, sizeof(lbuf))); | return (copyout(&lbuf, ubuf, sizeof(lbuf))); | ||||
} | } | ||||
int | int | ||||
linux_stat64(struct thread *td, struct linux_stat64_args *args) | linux_stat64(struct thread *td, struct linux_stat64_args *args) | ||||
{ | { | ||||
struct stat buf; | struct stat buf; | ||||
char *filename; | |||||
int error; | int error; | ||||
if (!LUSECONVPATH(td)) { | |||||
error = linux_kern_stat(td, args->filename, UIO_USERSPACE, &buf); | error = linux_kern_stat(td, args->filename, UIO_USERSPACE, &buf); | ||||
} else { | |||||
LCONVPATHEXIST(args->filename, &filename); | |||||
error = linux_kern_stat(td, filename, UIO_SYSSPACE, &buf); | |||||
LFREEPATH(filename); | |||||
} | |||||
if (error) | if (error) | ||||
return (error); | return (error); | ||||
return (stat64_copyout(&buf, args->statbuf)); | return (stat64_copyout(&buf, args->statbuf)); | ||||
} | } | ||||
int | int | ||||
linux_lstat64(struct thread *td, struct linux_lstat64_args *args) | linux_lstat64(struct thread *td, struct linux_lstat64_args *args) | ||||
{ | { | ||||
struct stat sb; | struct stat sb; | ||||
char *filename; | |||||
int error; | int error; | ||||
if (!LUSECONVPATH(td)) { | |||||
error = linux_kern_lstat(td, args->filename, UIO_USERSPACE, &sb); | error = linux_kern_lstat(td, args->filename, UIO_USERSPACE, &sb); | ||||
} else { | |||||
LCONVPATHEXIST(args->filename, &filename); | |||||
error = linux_kern_lstat(td, filename, UIO_SYSSPACE, &sb); | |||||
LFREEPATH(filename); | |||||
} | |||||
if (error) | if (error) | ||||
return (error); | return (error); | ||||
return (stat64_copyout(&sb, args->statbuf)); | return (stat64_copyout(&sb, args->statbuf)); | ||||
} | } | ||||
int | int | ||||
linux_fstat64(struct thread *td, struct linux_fstat64_args *args) | linux_fstat64(struct thread *td, struct linux_fstat64_args *args) | ||||
{ | { | ||||
struct stat buf; | struct stat buf; | ||||
int error; | int error; | ||||
error = linux_kern_fstat(td, args->fd, &buf); | error = linux_kern_fstat(td, args->fd, &buf); | ||||
if (!error) | if (!error) | ||||
error = stat64_copyout(&buf, args->statbuf); | error = stat64_copyout(&buf, args->statbuf); | ||||
return (error); | return (error); | ||||
} | } | ||||
int | int | ||||
linux_fstatat64(struct thread *td, struct linux_fstatat64_args *args) | linux_fstatat64(struct thread *td, struct linux_fstatat64_args *args) | ||||
{ | { | ||||
char *path; | |||||
int error, dfd, flag, unsupported; | int error, dfd, flag, unsupported; | ||||
struct stat buf; | struct stat buf; | ||||
unsupported = args->flag & ~(LINUX_AT_SYMLINK_NOFOLLOW | LINUX_AT_EMPTY_PATH); | unsupported = args->flag & ~(LINUX_AT_SYMLINK_NOFOLLOW | LINUX_AT_EMPTY_PATH); | ||||
if (unsupported != 0) { | if (unsupported != 0) { | ||||
linux_msg(td, "fstatat64 unsupported flag 0x%x", unsupported); | linux_msg(td, "fstatat64 unsupported flag 0x%x", unsupported); | ||||
return (EINVAL); | return (EINVAL); | ||||
} | } | ||||
flag = (args->flag & LINUX_AT_SYMLINK_NOFOLLOW) ? | flag = (args->flag & LINUX_AT_SYMLINK_NOFOLLOW) ? | ||||
AT_SYMLINK_NOFOLLOW : 0; | AT_SYMLINK_NOFOLLOW : 0; | ||||
flag |= (args->flag & LINUX_AT_EMPTY_PATH) ? | flag |= (args->flag & LINUX_AT_EMPTY_PATH) ? | ||||
AT_EMPTY_PATH : 0; | AT_EMPTY_PATH : 0; | ||||
dfd = (args->dfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->dfd; | dfd = (args->dfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->dfd; | ||||
if (!LUSECONVPATH(td)) { | |||||
error = linux_kern_statat(td, flag, dfd, args->pathname, | error = linux_kern_statat(td, flag, dfd, args->pathname, | ||||
UIO_USERSPACE, &buf); | UIO_USERSPACE, &buf); | ||||
} else { | |||||
LCONVPATHEXIST_AT(args->pathname, &path, dfd); | |||||
error = linux_kern_statat(td, flag, dfd, path, UIO_SYSSPACE, &buf); | |||||
LFREEPATH(path); | |||||
} | |||||
if (error == 0) | if (error == 0) | ||||
error = stat64_copyout(&buf, args->statbuf); | error = stat64_copyout(&buf, args->statbuf); | ||||
return (error); | return (error); | ||||
} | } | ||||
#else /* __amd64__ && !COMPAT_LINUX32 */ | #else /* __amd64__ && !COMPAT_LINUX32 */ | ||||
int | int | ||||
linux_newfstatat(struct thread *td, struct linux_newfstatat_args *args) | linux_newfstatat(struct thread *td, struct linux_newfstatat_args *args) | ||||
{ | { | ||||
char *path; | |||||
int error, dfd, flag, unsupported; | int error, dfd, flag, unsupported; | ||||
struct stat buf; | struct stat buf; | ||||
unsupported = args->flag & ~(LINUX_AT_SYMLINK_NOFOLLOW | LINUX_AT_EMPTY_PATH); | unsupported = args->flag & ~(LINUX_AT_SYMLINK_NOFOLLOW | LINUX_AT_EMPTY_PATH); | ||||
if (unsupported != 0) { | if (unsupported != 0) { | ||||
linux_msg(td, "fstatat unsupported flag 0x%x", unsupported); | linux_msg(td, "fstatat unsupported flag 0x%x", unsupported); | ||||
return (EINVAL); | return (EINVAL); | ||||
} | } | ||||
flag = (args->flag & LINUX_AT_SYMLINK_NOFOLLOW) ? | flag = (args->flag & LINUX_AT_SYMLINK_NOFOLLOW) ? | ||||
AT_SYMLINK_NOFOLLOW : 0; | AT_SYMLINK_NOFOLLOW : 0; | ||||
flag |= (args->flag & LINUX_AT_EMPTY_PATH) ? | flag |= (args->flag & LINUX_AT_EMPTY_PATH) ? | ||||
AT_EMPTY_PATH : 0; | AT_EMPTY_PATH : 0; | ||||
dfd = (args->dfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->dfd; | dfd = (args->dfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->dfd; | ||||
if (!LUSECONVPATH(td)) { | |||||
error = linux_kern_statat(td, flag, dfd, args->pathname, | error = linux_kern_statat(td, flag, dfd, args->pathname, | ||||
UIO_USERSPACE, &buf); | UIO_USERSPACE, &buf); | ||||
} else { | |||||
LCONVPATHEXIST_AT(args->pathname, &path, dfd); | |||||
error = linux_kern_statat(td, flag, dfd, path, UIO_SYSSPACE, &buf); | |||||
LFREEPATH(path); | |||||
} | |||||
if (error == 0) | if (error == 0) | ||||
error = newstat_copyout(&buf, args->statbuf); | error = newstat_copyout(&buf, args->statbuf); | ||||
return (error); | return (error); | ||||
} | } | ||||
#endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */ | #endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */ | ||||
▲ Show 20 Lines • Show All 67 Lines • ▼ Show 20 Lines | statx_copyout(struct stat *buf, void *ubuf) | ||||
tbuf.stx_dev_minor = linux_encode_minor(buf->st_dev); | tbuf.stx_dev_minor = linux_encode_minor(buf->st_dev); | ||||
return (copyout(&tbuf, ubuf, sizeof(tbuf))); | return (copyout(&tbuf, ubuf, sizeof(tbuf))); | ||||
} | } | ||||
int | int | ||||
linux_statx(struct thread *td, struct linux_statx_args *args) | linux_statx(struct thread *td, struct linux_statx_args *args) | ||||
{ | { | ||||
char *path; | |||||
int error, dirfd, flags, unsupported; | int error, dirfd, flags, unsupported; | ||||
struct stat buf; | struct stat buf; | ||||
unsupported = args->flags & ~(LINUX_AT_SYMLINK_NOFOLLOW | | unsupported = args->flags & ~(LINUX_AT_SYMLINK_NOFOLLOW | | ||||
LINUX_AT_EMPTY_PATH | LINUX_AT_NO_AUTOMOUNT); | LINUX_AT_EMPTY_PATH | LINUX_AT_NO_AUTOMOUNT); | ||||
if (unsupported != 0) { | if (unsupported != 0) { | ||||
linux_msg(td, "statx unsupported flags 0x%x", unsupported); | linux_msg(td, "statx unsupported flags 0x%x", unsupported); | ||||
return (EINVAL); | return (EINVAL); | ||||
} | } | ||||
flags = (args->flags & LINUX_AT_SYMLINK_NOFOLLOW) ? | flags = (args->flags & LINUX_AT_SYMLINK_NOFOLLOW) ? | ||||
AT_SYMLINK_NOFOLLOW : 0; | AT_SYMLINK_NOFOLLOW : 0; | ||||
flags |= (args->flags & LINUX_AT_EMPTY_PATH) ? | flags |= (args->flags & LINUX_AT_EMPTY_PATH) ? | ||||
AT_EMPTY_PATH : 0; | AT_EMPTY_PATH : 0; | ||||
dirfd = (args->dirfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->dirfd; | dirfd = (args->dirfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->dirfd; | ||||
if (!LUSECONVPATH(td)) { | |||||
error = linux_kern_statat(td, flags, dirfd, args->pathname, | error = linux_kern_statat(td, flags, dirfd, args->pathname, | ||||
UIO_USERSPACE, &buf); | UIO_USERSPACE, &buf); | ||||
} else { | |||||
LCONVPATHEXIST_AT(args->pathname, &path, dirfd); | |||||
error = linux_kern_statat(td, flags, dirfd, path, UIO_SYSSPACE, &buf); | |||||
LFREEPATH(path); | |||||
} | |||||
if (error == 0) | if (error == 0) | ||||
error = statx_copyout(&buf, args->statxbuf); | error = statx_copyout(&buf, args->statxbuf); | ||||
return (error); | return (error); | ||||
} | } |