PERFORCE change 117109 for review
John Baldwin
jhb at freebsd.org
Mon Apr 2 13:17:50 UTC 2007
On Sunday 01 April 2007 01:36:13 pm Roman Divacky wrote:
> http://perforce.freebsd.org/chv.cgi?CH=117109
>
> Change 117109 by rdivacky at 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);
> +}
Why not use kern_close()?
--
John Baldwin
More information about the p4-projects
mailing list