summaryrefslogtreecommitdiffstats
path: root/sys/compat/linux/linux_stats.c
diff options
context:
space:
mode:
Diffstat (limited to 'sys/compat/linux/linux_stats.c')
-rw-r--r--sys/compat/linux/linux_stats.c221
1 files changed, 104 insertions, 117 deletions
diff --git a/sys/compat/linux/linux_stats.c b/sys/compat/linux/linux_stats.c
index e7f9390..bfa11f6 100644
--- a/sys/compat/linux/linux_stats.c
+++ b/sys/compat/linux/linux_stats.c
@@ -25,7 +25,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
- * $Id: linux_stats.c,v 1.11 1999/05/09 10:25:30 phk Exp $
+ * $Id: linux_stats.c,v 1.12 1999/05/11 19:54:20 phk Exp $
*/
#include <sys/param.h>
@@ -46,73 +46,78 @@
#include <i386/linux/linux_util.h>
struct linux_newstat {
- unsigned short stat_dev;
- unsigned short __pad1;
- unsigned long stat_ino;
- unsigned short stat_mode;
- unsigned short stat_nlink;
- unsigned short stat_uid;
- unsigned short stat_gid;
- unsigned short stat_rdev;
- unsigned short __pad2;
- unsigned long stat_size;
- unsigned long stat_blksize;
- unsigned long stat_blocks;
- unsigned long stat_atime;
- unsigned long __unused1;
- unsigned long stat_mtime;
- unsigned long __unused2;
- unsigned long stat_ctime;
- unsigned long __unused3;
- unsigned long __unused4;
- unsigned long __unused5;
+ u_short stat_dev;
+ u_short __pad1;
+ u_long stat_ino;
+ u_short stat_mode;
+ u_short stat_nlink;
+ u_short stat_uid;
+ u_short stat_gid;
+ u_short stat_rdev;
+ u_short __pad2;
+ u_long stat_size;
+ u_long stat_blksize;
+ u_long stat_blocks;
+ u_long stat_atime;
+ u_long __unused1;
+ u_long stat_mtime;
+ u_long __unused2;
+ u_long stat_ctime;
+ u_long __unused3;
+ u_long __unused4;
+ u_long __unused5;
};
-
static int
newstat_copyout(struct stat *buf, void *ubuf)
{
- struct linux_newstat tbuf;
+ struct linux_newstat tbuf;
+
+ tbuf.stat_dev = uminor(buf->st_dev) | (umajor(buf->st_dev) << 10);
+ tbuf.stat_ino = buf->st_ino;
+ tbuf.stat_mode = buf->st_mode;
+ tbuf.stat_nlink = buf->st_nlink;
+ tbuf.stat_uid = buf->st_uid;
+ tbuf.stat_gid = buf->st_gid;
+ tbuf.stat_rdev = buf->st_rdev;
+ tbuf.stat_size = buf->st_size;
+ tbuf.stat_atime = buf->st_atime;
+ tbuf.stat_mtime = buf->st_mtime;
+ tbuf.stat_ctime = buf->st_ctime;
+ tbuf.stat_blksize = buf->st_blksize;
+ tbuf.stat_blocks = buf->st_blocks;
- tbuf.stat_dev = uminor(buf->st_dev) | (umajor(buf->st_dev) << 10);
- tbuf.stat_ino = buf->st_ino;
- tbuf.stat_mode = buf->st_mode;
- tbuf.stat_nlink = buf->st_nlink;
- tbuf.stat_uid = buf->st_uid;
- tbuf.stat_gid = buf->st_gid;
- tbuf.stat_rdev = buf->st_rdev;
- tbuf.stat_size = buf->st_size;
- tbuf.stat_atime = buf->st_atime;
- tbuf.stat_mtime = buf->st_mtime;
- tbuf.stat_ctime = buf->st_ctime;
- tbuf.stat_blksize = buf->st_blksize;
- tbuf.stat_blocks = buf->st_blocks;
- return copyout(&tbuf, ubuf, sizeof(tbuf));
+ return (copyout(&tbuf, ubuf, sizeof(tbuf)));
}
int
linux_newstat(struct proc *p, struct linux_newstat_args *args)
{
- struct stat buf;
- struct nameidata nd;
- int error;
- caddr_t sg;
+ struct stat buf;
+ struct nameidata nd;
+ int error;
+ caddr_t sg;
+
+ sg = stackgap_init();
+ CHECKALTEXIST(p, &sg, args->path);
- sg = stackgap_init();
- CHECKALTEXIST(p, &sg, args->path);
-
#ifdef DEBUG
- printf("Linux-emul(%d): newstat(%s, *)\n", p->p_pid, args->path);
+ printf("Linux-emul(%ld): newstat(%s, *)\n", (long)p->p_pid,
+ args->path);
#endif
- NDINIT(&nd, LOOKUP, LOCKLEAF|FOLLOW, UIO_USERSPACE, args->path, p);
- error = namei(&nd);
- if (!error) {
+
+ NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF | NOOBJ, UIO_USERSPACE,
+ args->path, p);
+ error = namei(&nd);
+ if (error)
+ return (error);
+
error = vn_stat(nd.ni_vp, &buf, p);
vput(nd.ni_vp);
- }
- if (!error)
- error = newstat_copyout(&buf, args->buf);
- return error;
+ if (error)
+ return (error);
+
+ return (newstat_copyout(&buf, args->buf));
}
/*
@@ -124,89 +129,71 @@ linux_newlstat(p, uap)
struct linux_newlstat_args *uap;
{
int error;
- struct vnode *vp, *dvp;
- struct stat sb, sb1;
+ struct vnode *vp;
+ struct stat sb;
struct nameidata nd;
caddr_t sg;
sg = stackgap_init();
CHECKALTEXIST(p, &sg, uap->path);
-
+
#ifdef DEBUG
- printf("Linux-emul(%d): newlstat(%s, *)\n", p->p_pid, uap->path);
+ printf("Linux-emul(%ld): newlstat(%s, *)\n", (long)p->p_pid,
+ uap->path);
#endif
- NDINIT(&nd, LOOKUP, NOFOLLOW | LOCKLEAF | LOCKPARENT, UIO_USERSPACE,
- uap->path, p);
+
+ NDINIT(&nd, LOOKUP, NOFOLLOW | LOCKLEAF | NOOBJ, UIO_USERSPACE,
+ uap->path, p);
error = namei(&nd);
if (error)
return (error);
- /*
- * For symbolic links, always return the attributes of its
- * containing directory, except for mode, size, and links.
- */
+
vp = nd.ni_vp;
- dvp = nd.ni_dvp;
- if (vp->v_type != VLNK) {
- if (dvp == vp)
- vrele(dvp);
- else
- vput(dvp);
- error = vn_stat(vp, &sb, p);
- vput(vp);
- if (error)
- return (error);
- } else {
- error = vn_stat(dvp, &sb, p);
- vput(dvp);
- if (error) {
- vput(vp);
- return (error);
- }
- error = vn_stat(vp, &sb1, p);
- vput(vp);
- if (error)
- return (error);
- sb.st_mode &= ~S_IFDIR;
- sb.st_mode |= S_IFLNK;
- sb.st_nlink = sb1.st_nlink;
- sb.st_size = sb1.st_size;
- sb.st_blocks = sb1.st_blocks;
- }
- error = newstat_copyout(&sb, uap->buf);
- return (error);
+ error = vn_stat(vp, &sb, p);
+ vput(vp);
+ if (error)
+ return (error);
+
+ return (newstat_copyout(&sb, uap->buf));
}
int
linux_newfstat(struct proc *p, struct linux_newfstat_args *args)
{
- struct filedesc *fdp = p->p_fd;
- struct file *fp;
- struct stat buf;
- int error;
-
+ struct filedesc *fdp;
+ struct file *fp;
+ struct stat buf;
+ int error;
+
+ fdp = p->p_fd;
+
#ifdef DEBUG
- printf("Linux-emul(%d): newfstat(%d, *)\n", p->p_pid, args->fd);
+ printf("Linux-emul(%ld): newfstat(%d, *)\n", (long)p->p_pid, args->fd);
#endif
- if ((unsigned)args->fd >= fdp->fd_nfiles
- || (fp = fdp->fd_ofiles[args->fd]) == NULL)
- return EBADF;
- switch (fp->f_type) {
- case DTYPE_FIFO:
- case DTYPE_VNODE:
- error = vn_stat((struct vnode *)fp->f_data, &buf, p);
- break;
- case DTYPE_SOCKET:
- error = soo_stat((struct socket *)fp->f_data, &buf);
- break;
- case DTYPE_PIPE:
- error = pipe_stat((struct pipe *)fp->f_data, &buf);
- break;
- default:
- panic("LINUX newfstat");
- }
- if (!error)
- error = newstat_copyout(&buf, args->buf);
- return error;
+
+ if ((unsigned)args->fd >= fdp->fd_nfiles ||
+ (fp = fdp->fd_ofiles[args->fd]) == NULL)
+ return (EBADF);
+
+ switch (fp->f_type) {
+ case DTYPE_FIFO:
+ case DTYPE_VNODE:
+ error = vn_stat((struct vnode *)fp->f_data, &buf, p);
+ break;
+ case DTYPE_SOCKET:
+ error = soo_stat((struct socket *)fp->f_data, &buf);
+ break;
+ case DTYPE_PIPE:
+ error = pipe_stat((struct pipe *)fp->f_data, &buf);
+ break;
+ default:
+ panic("LINUX newfstat");
+ }
+
+ if (!error)
+ error = newstat_copyout(&buf, args->buf);
+
+ return (error);
}
struct linux_statfs_buf {
OpenPOWER on IntegriCloud