Date: Sun, 1 Apr 2007 17:36:13 GMT From: Roman Divacky <rdivacky@FreeBSD.org> To: Perforce Change Reviews <perforce@FreeBSD.org> Subject: PERFORCE change 117109 for review Message-ID: <200704011736.l31HaDhx068622@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=117109 Change 117109 by rdivacky@rdivacky_witten on 2007/04/01 17:35:45 Semi-implement fstatat64() - only compile tested. Check for fp being a vnode before referencing fp->f_vnode [1] Pointed out by: rwatson I commit this because my harddisk is likely to die in a few hours. Affected files ... .. //depot/projects/linuxolator/src/sys/compat/linux/linux_file.c#20 edit .. //depot/projects/linuxolator/src/sys/compat/linux/linux_stats.c#8 edit .. //depot/projects/linuxolator/src/sys/compat/linux/linux_util.h#5 edit Differences ... ==== //depot/projects/linuxolator/src/sys/compat/linux/linux_file.c#20 (text+ko) ==== @@ -105,6 +105,10 @@ error = fget(td, dirfd, &fp); if (error) return (error); + if (fp->f_type != DTYPE_VNODE) { + fdrop(fp, td); + return (EBADF); + } dvp = fp->f_vnode; /* only a dir can be dfd */ if (dvp->v_type != VDIR) { @@ -144,7 +148,7 @@ } -static int +int linux_common_open(struct thread *td, char *path, int l_flags, int mode, int openat) { struct proc *p = td->td_proc; @@ -1387,12 +1391,6 @@ } int -linux_fstatat64(struct thread *td, struct linux_fstatat64_args *args) -{ - return (ENOSYS); -} - -int linux_fchownat(struct thread *td, struct linux_fchownat_args *args) { return (ENOSYS); ==== //depot/projects/linuxolator/src/sys/compat/linux/linux_stats.c#8 (text+ko) ==== @@ -43,6 +43,7 @@ #include <sys/namei.h> #include <sys/stat.h> #include <sys/syscallsubr.h> +#include <sys/sysproto.h> #include <sys/systm.h> #include <sys/vnode.h> #include <sys/conf.h> @@ -593,4 +594,52 @@ return (error); } +/* XXX: racy? */ +int +linux_fstatat64(struct thread *td, struct linux_fstatat64_args *args) +{ + int error; + char *newpath, *oldpath, *freebuf = NULL, *path; + int fd; + struct close_args cargs; + struct stat buf; + + /* open the file */ + oldpath = malloc(MAXPATHLEN, M_TEMP, M_WAITOK); + error = copyinstr(args->pathname, oldpath, MAXPATHLEN, NULL); +#ifdef DEBUG + if (ldebug(fstatat64)) + printf(ARGS(fstatat64, "%i, %s, %i"), args->dfd, args->pathname, args->flag); +#endif + + error = linux_at(td, args->dfd, oldpath, &newpath, &freebuf); + if (error) + return (error); + LCONVPATH_SEG(td, newpath, &path, 0, UIO_SYSSPACE); + if (freebuf) + free(freebuf, M_TEMP); + if (*oldpath != '/') + free(newpath, M_TEMP); + + error = linux_common_open(td, path, O_RDONLY, 0, 1); + free(oldpath, M_TEMP); + if (error) + return (error); + /* file opened */ + fd = td->td_retval[0]; + td->td_retval[0] = 0; + + /* do the actual fstat */ + + error = kern_fstat(td, fd, &buf); + translate_fd_major_minor(td, fd, &buf); + if (!error) + error = stat64_copyout(&buf, args->statbuf); + + /* close the opened file */ + cargs.fd = fd; + close(td, &cargs); + return (0); +} + #endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */ ==== //depot/projects/linuxolator/src/sys/compat/linux/linux_util.h#5 (text+ko) ==== @@ -106,5 +106,6 @@ /* XXX: doesnt belong here */ int linux_at(struct thread *td, int dirfd, char *filename, char **newpath, char **freebuf); +int linux_common_open(struct thread *td, char *path, int l_flags, int mode, int openat); #endif /* !_LINUX_UTIL_H_ */
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200704011736.l31HaDhx068622>