Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/compat/darwin Added the getattrlist system call. That wa...



details:   https://anonhg.NetBSD.org/src/rev/0e2dbc276d29
branches:  trunk
changeset: 556958:0e2dbc276d29
user:      manu <manu%NetBSD.org@localhost>
date:      Wed Dec 31 02:55:04 2003 +0000

description:
Added the getattrlist system call. That was annoying.

diffstat:

 sys/compat/darwin/darwin_attr.c        |  806 +++++++++++++++++++++++++++++++++
 sys/compat/darwin/darwin_attr.h        |  227 +++++++++
 sys/compat/darwin/darwin_syscall.h     |    7 +-
 sys/compat/darwin/darwin_syscallargs.h |   14 +-
 sys/compat/darwin/darwin_syscalls.c    |    8 +-
 sys/compat/darwin/darwin_sysent.c      |   10 +-
 sys/compat/darwin/files.darwin         |    3 +-
 sys/compat/darwin/syscalls.master      |    6 +-
 8 files changed, 1065 insertions(+), 16 deletions(-)

diffs (truncated from 1206 to 300 lines):

diff -r e5998401a477 -r 0e2dbc276d29 sys/compat/darwin/darwin_attr.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/compat/darwin/darwin_attr.c   Wed Dec 31 02:55:04 2003 +0000
@@ -0,0 +1,806 @@
+/*     $NetBSD: darwin_attr.c,v 1.1 2003/12/31 02:55:04 manu Exp $ */
+
+/*-
+ * Copyright (c) 2003 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Emmanuel Dreyfus.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *        This product includes software developed by the NetBSD
+ *        Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: darwin_attr.c,v 1.1 2003/12/31 02:55:04 manu Exp $");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/types.h>
+#include <sys/proc.h>
+#include <sys/mount.h>
+#include <sys/sa.h>
+#include <sys/lwp.h>
+#include <sys/file.h>
+#include <sys/filedesc.h>
+#include <sys/namei.h>
+#include <sys/vnode.h>
+#include <sys/malloc.h>
+#include <sys/stat.h>
+#include <sys/syscallargs.h>
+
+#include <compat/common/compat_util.h>
+
+#include <compat/mach/mach_types.h>
+#include <compat/mach/mach_vm.h>
+
+#include <compat/darwin/darwin_attr.h>
+#include <compat/darwin/darwin_syscallargs.h>
+
+#define DARWIN_ATTR_MAXBUFLEN  4096
+
+static int darwin_attr_append(const char *, size_t, char **, size_t *);
+
+#define ATTR_APPEND(x, bp, len) \
+    darwin_attr_append((char *)&(x), sizeof(x), &(bp), &(len))
+
+
+static int
+darwin_attr_append(x, size, bp, len) 
+       const char *x;
+       size_t size;
+       char **bp;
+       size_t *len;
+{
+       if (*len < size)
+               return -1;
+
+       (void)memcpy(*bp, x, size);
+
+       *bp += size;
+       *len -= size;
+
+       return 0;
+}
+
+int
+darwin_sys_getattrlist(l, v, retval)
+       struct lwp *l;
+       void *v;
+       register_t *retval;
+{
+       struct darwin_sys_getattrlist_args /* {
+               syscallarg(const char *) path;
+               syscallarg(struct darwin_attrlist *) alist;
+               syscallarg(void *) attributes;
+               syscallarg(size_t) buflen;
+               syscallarg(unsigned long) options;
+       } */ *uap = v;
+       struct proc *p = l->l_proc;
+       struct darwin_attrlist kalist;
+       char *buf;
+       char *bp;
+       size_t len;
+       size_t shift = 0;
+       int null = 0;
+       int error = 0;
+       int follow = 0;
+       u_long *whole_len_p = NULL;
+       darwin_attrreference_t *cmn_name_p = NULL;
+       darwin_attrreference_t *vol_mountpoint_p = NULL;
+       darwin_attrreference_t *vol_name_p = NULL;
+       darwin_attrreference_t *vol_mounteddevice_p = NULL;
+       struct sys___stat13_args cup1;
+       struct stat *ust;
+       struct stat st;
+       struct sys_statfs_args cup2;
+       struct statfs *uf;
+       struct statfs f;
+       struct nameidata nd;
+       struct vnode *vp;
+       struct ucred *cred;
+       const char *path;
+       caddr_t sg = stackgap_init(p, 0);
+       int fl;
+
+       if ((error = copyin(SCARG(uap, alist), &kalist, sizeof(kalist))) != 0)
+               return error;
+
+       if (kalist.bitmapcount != DARWIN_ATTR_BIT_MAP_COUNT)
+               return EINVAL;
+
+       len = SCARG(uap, buflen);
+       if (len > DARWIN_ATTR_MAXBUFLEN)
+               return E2BIG;
+
+       if ((SCARG(uap, options) & DARWIN_FSOPT_NOFOLLOW) != 0)
+               follow = FOLLOW;
+
+#ifdef DEBUG_DARWIN
+       printf("getattrlist: %08x %08x %08x %08x %08x\n", 
+           kalist.commonattr, kalist.volattr, kalist.dirattr,
+           kalist.fileattr, kalist.forkattr);
+#endif
+
+       /*
+        * Lookup emulation shadow tree once
+        */
+       fl = CHECK_ALT_FL_EXISTS;
+       if (follow == 0)
+               fl |= CHECK_ALT_FL_SYMLINK;
+       (void)emul_find(p, &sg, p->p_emul->e_path, SCARG(uap, path), &path, fl);
+
+       /* 
+        * Get the informations for path: file related info
+        */ 
+       ust = stackgap_alloc(p, &sg, sizeof(st));
+       SCARG(&cup1, path) = path;
+       SCARG(&cup1, ub) = ust;
+       if (follow) {
+               if ((error = sys___stat13(l, &cup1, retval)) != 0)
+                       return error;
+       } else {
+               if ((error = sys___lstat13(l, &cup1, retval)) != 0)
+                       return error;
+       }
+
+       if ((error = copyin(ust, &st, sizeof(st))) != 0)
+               return error;
+
+       /*
+        * filesystem related info
+        */
+       uf = stackgap_alloc(p, &sg, sizeof(f));
+       SCARG(&cup2, path) = path;
+       SCARG(&cup2, buf) = uf;
+       if ((error = sys_statfs(l, &cup2, retval)) != 0)
+               return error;
+
+       if ((error = copyin(uf, &f, sizeof(f))) != 0)
+               return error;
+
+       /* 
+        * Prepare the buffer 
+        */
+       buf = malloc(len, M_TEMP, M_WAITOK);
+       bp = buf;
+
+       /*
+        * vnode structure
+        */
+
+       cred = crget();
+       (void)memcpy(cred, p->p_ucred, sizeof(*cred));
+       cred->cr_ref = 1;
+       cred->cr_uid = p->p_cred->p_ruid;
+       cred->cr_gid = p->p_cred->p_rgid;
+
+       NDINIT(&nd, LOOKUP, follow | LOCKLEAF, UIO_USERSPACE, path, p);
+       if ((error = namei(&nd)) != 0) 
+               goto out2;      
+
+       vp = nd.ni_vp;
+       if ((error = VOP_ACCESS(vp, VREAD | VEXEC, cred, p)) != 0)
+               goto out3;
+
+       /* 
+        * Buffer whole length: is always present
+        */
+       if (1) {
+               u_long whole_len;
+
+               whole_len = 0;
+               whole_len_p = (u_long *)bp;
+               if (ATTR_APPEND(whole_len, bp, len) != 0)
+                       goto out3;
+       }
+
+       if (kalist.commonattr & DARWIN_ATTR_CMN_NAME) {
+               darwin_attrreference_t dar;
+
+               cmn_name_p = (darwin_attrreference_t *)bp;
+               if (ATTR_APPEND(dar, bp, len) != 0)
+                       goto out3;
+       }
+
+       if (kalist.commonattr & DARWIN_ATTR_CMN_DEVID) {
+               dev_t device;
+
+               device = st.st_dev;
+               if (ATTR_APPEND(device, bp, len) != 0)
+                       goto out3;
+       }
+
+       if (kalist.commonattr & DARWIN_ATTR_CMN_FSID) {
+               fsid_t fs;
+
+               fs = f.f_fsid;
+               if (ATTR_APPEND(fs, bp, len) != 0)
+                       goto out3;
+       }
+
+       if (kalist.commonattr & DARWIN_ATTR_CMN_OBJTYPE) {
+               darwin_fsobj_type_t dft;
+
+               dft = vp->v_type;
+               if (ATTR_APPEND(dft, bp, len) != 0)
+                       goto out3;
+       }
+
+       if (kalist.commonattr & DARWIN_ATTR_CMN_OBJTAG) {
+               darwin_fsobj_tag_t dft;
+
+               dft = vp->v_tag;
+               if (ATTR_APPEND(dft, bp, len) != 0)
+                       goto out3;
+       }
+
+       if (kalist.commonattr & DARWIN_ATTR_CMN_OBJID) {
+               darwin_fsobj_id_t dfi;
+
+               dfi.fid_objno = st.st_ino;
+               dfi.fid_generation = 0; /* XXX root can read real value */
+               if (ATTR_APPEND(dfi, bp, len) != 0)
+                       goto out3;
+       }
+
+       if (kalist.commonattr & DARWIN_ATTR_CMN_OBJPERMANENTID) {
+               darwin_fsobj_id_t dfi;
+
+               dfi.fid_objno = st.st_ino; /* This is not really persistent */
+               dfi.fid_generation = 0; /* XXX root can read real value */
+               if (ATTR_APPEND(dfi, bp, len) != 0)
+                       goto out3;
+       }
+
+       if (kalist.commonattr & DARWIN_ATTR_CMN_PAROBJID) {
+               darwin_fsobj_id_t dfi;
+
+               dfi.fid_objno = 0;      /* XXX do me */
+               dfi.fid_generation = 0; /* XXX root can read real value */
+               if (ATTR_APPEND(dfi, bp, len) != 0)
+                       goto out3;
+       }
+
+       if (kalist.commonattr & DARWIN_ATTR_CMN_SCRIPT) {
+               darwin_text_encoding_t dte;
+
+               dte = DARWIN_US_ASCII;
+               if (ATTR_APPEND(dte, bp, len) != 0)
+                       goto out3;
+       }



Home | Main Index | Thread Index | Old Index