Deleted Added
full compact
linux_stats.c (175107) linux_stats.c (177997)
1/*-
2 * Copyright (c) 1994-1995 S�ren Schmidt
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 13 unchanged lines hidden (view full) ---

22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 1994-1995 S�ren Schmidt
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 13 unchanged lines hidden (view full) ---

22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include <sys/cdefs.h>
30__FBSDID("$FreeBSD: head/sys/compat/linux/linux_stats.c 175107 2008-01-05 12:36:35Z kib $");
30__FBSDID("$FreeBSD: head/sys/compat/linux/linux_stats.c 177997 2008-04-08 09:45:49Z kib $");
31
32#include "opt_compat.h"
33#include "opt_mac.h"
34
35#include <sys/param.h>
36#include <sys/dirent.h>
37#include <sys/file.h>
38#include <sys/filedesc.h>

--- 13 unchanged lines hidden (view full) ---

52#include <machine/../linux32/linux.h>
53#include <machine/../linux32/linux32_proto.h>
54#else
55#include <machine/../linux/linux.h>
56#include <machine/../linux/linux_proto.h>
57#endif
58
59#include <compat/linux/linux_util.h>
31
32#include "opt_compat.h"
33#include "opt_mac.h"
34
35#include <sys/param.h>
36#include <sys/dirent.h>
37#include <sys/file.h>
38#include <sys/filedesc.h>

--- 13 unchanged lines hidden (view full) ---

52#include <machine/../linux32/linux.h>
53#include <machine/../linux32/linux32_proto.h>
54#else
55#include <machine/../linux/linux.h>
56#include <machine/../linux/linux_proto.h>
57#endif
58
59#include <compat/linux/linux_util.h>
60#include <compat/linux/linux_file.h>
60
61#include <security/mac/mac_framework.h>
62
63/*
64 * XXX: This was removed from newstat_copyout(), and almost identical
65 * XXX: code was in stat64_copyout(). findcdev() needs to be replaced
66 * XXX: with something that does lookup and locking properly.
67 * XXX: When somebody fixes this: please try to avoid duplicating it.

--- 41 unchanged lines hidden (view full) ---

109 fp->f_vnode->v_un.vu_cdev != NULL &&
110 linux_driver_get_major_minor(fp->f_vnode->v_un.vu_cdev->si_name,
111 &major, &minor) == 0)
112 buf->st_rdev = (major << 8 | minor);
113 fdrop(fp, td);
114}
115
116static void
61
62#include <security/mac/mac_framework.h>
63
64/*
65 * XXX: This was removed from newstat_copyout(), and almost identical
66 * XXX: code was in stat64_copyout(). findcdev() needs to be replaced
67 * XXX: with something that does lookup and locking properly.
68 * XXX: When somebody fixes this: please try to avoid duplicating it.

--- 41 unchanged lines hidden (view full) ---

110 fp->f_vnode->v_un.vu_cdev != NULL &&
111 linux_driver_get_major_minor(fp->f_vnode->v_un.vu_cdev->si_name,
112 &major, &minor) == 0)
113 buf->st_rdev = (major << 8 | minor);
114 fdrop(fp, td);
115}
116
117static void
117translate_path_major_minor(struct thread *td, char *path, struct stat *buf)
118translate_path_major_minor_at(struct thread *td, char *path,
119 struct stat *buf, int dfd)
118{
120{
119 struct proc *p = td->td_proc;
121 struct proc *p = td->td_proc;
120 struct filedesc *fdp = p->p_fd;
121 int fd;
122 int temp;
123
124 if (!S_ISCHR(buf->st_mode) && !S_ISBLK(buf->st_mode))
125 return;
126 temp = td->td_retval[0];
122 struct filedesc *fdp = p->p_fd;
123 int fd;
124 int temp;
125
126 if (!S_ISCHR(buf->st_mode) && !S_ISBLK(buf->st_mode))
127 return;
128 temp = td->td_retval[0];
127 if (kern_open(td, path, UIO_SYSSPACE, O_RDONLY, 0) != 0)
129 if (kern_openat(td, dfd, path, UIO_SYSSPACE, O_RDONLY, 0) != 0)
128 return;
129 fd = td->td_retval[0];
130 td->td_retval[0] = temp;
131 translate_fd_major_minor(td, fd, buf);
132 fdclose(fdp, fdp->fd_ofiles[fd], fd, td);
133}
134
130 return;
131 fd = td->td_retval[0];
132 td->td_retval[0] = temp;
133 translate_fd_major_minor(td, fd, buf);
134 fdclose(fdp, fdp->fd_ofiles[fd], fd, td);
135}
136
137static inline void
138translate_path_major_minor(struct thread *td, char *path, struct stat *buf)
139{
140 translate_path_major_minor_at(td, path, buf, AT_FDCWD);
141}
142
135static int
136newstat_copyout(struct stat *buf, void *ubuf)
137{
138 struct l_newstat tbuf;
139
140 bzero(&tbuf, sizeof(tbuf));
141 tbuf.st_dev = uminor(buf->st_dev) | (umajor(buf->st_dev) << 8);
142 tbuf.st_ino = buf->st_ino;

--- 433 unchanged lines hidden (view full) ---

576 error = kern_fstat(td, args->fd, &buf);
577 translate_fd_major_minor(td, args->fd, &buf);
578 if (!error)
579 error = stat64_copyout(&buf, args->statbuf);
580
581 return (error);
582}
583
143static int
144newstat_copyout(struct stat *buf, void *ubuf)
145{
146 struct l_newstat tbuf;
147
148 bzero(&tbuf, sizeof(tbuf));
149 tbuf.st_dev = uminor(buf->st_dev) | (umajor(buf->st_dev) << 8);
150 tbuf.st_ino = buf->st_ino;

--- 433 unchanged lines hidden (view full) ---

584 error = kern_fstat(td, args->fd, &buf);
585 translate_fd_major_minor(td, args->fd, &buf);
586 if (!error)
587 error = stat64_copyout(&buf, args->statbuf);
588
589 return (error);
590}
591
592int
593linux_fstatat64(struct thread *td, struct linux_fstatat64_args *args)
594{
595 char *path;
596 int error, dfd, flag;
597 struct stat buf;
598
599 if (args->flag & ~LINUX_AT_SYMLINK_NOFOLLOW)
600 return (EINVAL);
601 flag = (args->flag & LINUX_AT_SYMLINK_NOFOLLOW) ?
602 AT_SYMLINK_NOFOLLOW : 0;
603
604 dfd = (args->dfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->dfd;
605 LCONVPATHEXIST_AT(td, args->pathname, &path, dfd);
606
607#ifdef DEBUG
608 if (ldebug(fstatat64))
609 printf(ARGS(fstatat64, "%i, %s, %i"), args->dfd, path, args->flag);
610#endif
611
612 error = kern_statat(td, flag, dfd, path, UIO_SYSSPACE, &buf);
613 translate_path_major_minor_at(td, args->pathname, &buf, dfd);
614 if (!error)
615 error = stat64_copyout(&buf, args->statbuf);
616 LFREEPATH(path);
617
618 return (error);
619}
620
584#endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */
621#endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */