2007-06-18 00:43:10 +04:00
|
|
|
/* $NetBSD: darwin_attr.c,v 1.18 2007/06/17 20:43:10 dsl Exp $ */
|
2003-12-31 05:55:04 +03:00
|
|
|
|
|
|
|
/*-
|
|
|
|
* 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>
|
2007-06-18 00:43:10 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: darwin_attr.c,v 1.18 2007/06/17 20:43:10 dsl Exp $");
|
2003-12-31 05:55:04 +03:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/mount.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>
|
2007-03-11 00:40:23 +03:00
|
|
|
#include <sys/vfs_syscalls.h>
|
2006-05-15 04:05:16 +04:00
|
|
|
#include <sys/kauth.h>
|
2003-12-31 05:55:04 +03:00
|
|
|
|
2005-09-13 05:42:32 +04:00
|
|
|
#include <compat/sys/signal.h>
|
|
|
|
#include <compat/sys/mount.h>
|
|
|
|
|
2003-12-31 05:55:04 +03:00
|
|
|
#include <compat/common/compat_util.h>
|
|
|
|
|
|
|
|
#include <compat/mach/mach_types.h>
|
|
|
|
#include <compat/mach/mach_vm.h>
|
|
|
|
|
2004-07-29 02:24:06 +04:00
|
|
|
#include <compat/darwin/darwin_audit.h>
|
2003-12-31 05:55:04 +03:00
|
|
|
#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
|
2005-02-27 01:58:54 +03:00
|
|
|
darwin_attr_append(x, size, bp, len)
|
2003-12-31 05:55:04 +03:00
|
|
|
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 darwin_attrlist kalist;
|
2005-05-30 02:08:16 +04:00
|
|
|
char *tbuf;
|
2003-12-31 05:55:04 +03:00
|
|
|
char *bp;
|
|
|
|
size_t len;
|
|
|
|
size_t shift = 0;
|
|
|
|
int null = 0;
|
|
|
|
int error = 0;
|
2007-03-11 00:40:23 +03:00
|
|
|
int follow = NOFOLLOW;
|
2003-12-31 05:55:04 +03:00
|
|
|
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 stat st;
|
2007-06-18 00:43:10 +04:00
|
|
|
struct statvfs *f;
|
2003-12-31 05:55:04 +03:00
|
|
|
struct nameidata nd;
|
|
|
|
struct vnode *vp;
|
2006-05-15 01:19:33 +04:00
|
|
|
kauth_cred_t cred;
|
2003-12-31 05:55:04 +03:00
|
|
|
|
|
|
|
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
|
2005-02-27 01:58:54 +03:00
|
|
|
printf("getattrlist: %08x %08x %08x %08x %08x\n",
|
2003-12-31 05:55:04 +03:00
|
|
|
kalist.commonattr, kalist.volattr, kalist.dirattr,
|
|
|
|
kalist.fileattr, kalist.forkattr);
|
|
|
|
#endif
|
|
|
|
|
2007-06-18 00:43:10 +04:00
|
|
|
/* Allocate buffers now... */
|
|
|
|
f = STATVFSBUF_GET();
|
2005-05-30 02:08:16 +04:00
|
|
|
tbuf = malloc(len, M_TEMP, M_WAITOK);
|
2003-12-31 05:55:04 +03:00
|
|
|
|
2007-06-18 00:43:10 +04:00
|
|
|
/* We are going to need the vnode itself... */
|
2003-12-31 05:55:04 +03:00
|
|
|
|
2006-07-24 02:06:03 +04:00
|
|
|
cred = kauth_cred_dup(l->l_cred);
|
|
|
|
kauth_cred_seteuid(cred, kauth_cred_getuid(l->l_cred));
|
|
|
|
kauth_cred_setegid(cred, kauth_cred_getgid(l->l_cred));
|
2003-12-31 05:55:04 +03:00
|
|
|
|
2007-06-18 00:43:10 +04:00
|
|
|
NDINIT(&nd, LOOKUP, follow | LOCKLEAF | TRYEMULROOT, UIO_USERSPACE,
|
|
|
|
SCARG(uap, path), l);
|
2005-02-27 01:58:54 +03:00
|
|
|
if ((error = namei(&nd)) != 0)
|
|
|
|
goto out2;
|
2003-12-31 05:55:04 +03:00
|
|
|
|
|
|
|
vp = nd.ni_vp;
|
2005-12-11 15:16:03 +03:00
|
|
|
if ((error = VOP_ACCESS(vp, VREAD | VEXEC, cred, l)) != 0)
|
2003-12-31 05:55:04 +03:00
|
|
|
goto out3;
|
|
|
|
|
2007-06-18 00:43:10 +04:00
|
|
|
/* Get the informations for path: file related info */
|
|
|
|
error = vn_stat(vp, &st, l);
|
|
|
|
if (error != 0)
|
|
|
|
goto out3;
|
|
|
|
|
|
|
|
/* filesystem related info */
|
|
|
|
error = dostatvfs(vp->v_mount, f, l, 0, 1);
|
|
|
|
if (error != 0)
|
|
|
|
goto out3;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Prepare the buffer
|
|
|
|
*/
|
|
|
|
bp = tbuf;
|
|
|
|
|
2005-02-27 01:58:54 +03:00
|
|
|
/*
|
2003-12-31 05:55:04 +03:00
|
|
|
* 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;
|
2007-06-18 00:43:10 +04:00
|
|
|
fs = f->f_fsidx;
|
2003-12-31 05:55:04 +03:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kalist.commonattr & DARWIN_ATTR_CMN_CRTIME) {
|
|
|
|
if (ATTR_APPEND(st.st_ctimespec, bp, len) != 0)
|
|
|
|
goto out3;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kalist.commonattr & DARWIN_ATTR_CMN_MODTIME) {
|
|
|
|
if (ATTR_APPEND(st.st_mtimespec, bp, len) != 0)
|
|
|
|
goto out3;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kalist.commonattr & DARWIN_ATTR_CMN_CHGTIME) {
|
|
|
|
if (ATTR_APPEND(st.st_ctimespec, bp, len) != 0)
|
|
|
|
goto out3;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kalist.commonattr & DARWIN_ATTR_CMN_ACCTIME) {
|
|
|
|
if (ATTR_APPEND(st.st_atimespec, bp, len) != 0)
|
|
|
|
goto out3;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kalist.commonattr & DARWIN_ATTR_CMN_BKUPTIME) {
|
|
|
|
struct timespec ts;
|
|
|
|
|
|
|
|
/* XXX no way I can do that one */
|
|
|
|
|
|
|
|
(void)bzero(&ts, sizeof(ts));
|
|
|
|
if (ATTR_APPEND(ts, bp, len) != 0)
|
|
|
|
goto out3;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kalist.commonattr & DARWIN_ATTR_CMN_FNDRINFO) { /* XXX */
|
|
|
|
char data[32];
|
|
|
|
|
|
|
|
(void)bzero(&data, sizeof(data));
|
|
|
|
if (ATTR_APPEND(data, bp, len) != 0)
|
|
|
|
goto out3;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kalist.commonattr & DARWIN_ATTR_CMN_OWNERID) {
|
|
|
|
uid_t uid;
|
|
|
|
|
|
|
|
uid = st.st_uid;
|
|
|
|
if (ATTR_APPEND(uid, bp, len) != 0)
|
|
|
|
goto out3;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kalist.commonattr & DARWIN_ATTR_CMN_GRPID) {
|
|
|
|
gid_t gid;
|
|
|
|
|
|
|
|
gid = st.st_gid;
|
|
|
|
if (ATTR_APPEND(gid, bp, len) != 0)
|
|
|
|
goto out3;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kalist.commonattr & DARWIN_ATTR_CMN_ACCESSMASK) {
|
|
|
|
mode_t mode;
|
|
|
|
|
|
|
|
mode = st.st_mode;
|
|
|
|
if (ATTR_APPEND(mode, bp, len) != 0)
|
|
|
|
goto out3;
|
|
|
|
}
|
|
|
|
|
2005-02-27 01:58:54 +03:00
|
|
|
if (kalist.commonattr & DARWIN_ATTR_CMN_NAMEDATTRCOUNT) {
|
2003-12-31 05:55:04 +03:00
|
|
|
/* Data is unsigned long. Unsupported in Darwin */
|
|
|
|
error = EINVAL;
|
|
|
|
goto out3;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kalist.commonattr & DARWIN_ATTR_CMN_NAMEDATTRLIST) {
|
|
|
|
/* Data is darwin_attrreference_t. Unsupported in Darwin */
|
|
|
|
|
|
|
|
error = EINVAL;
|
|
|
|
goto out3;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kalist.commonattr & DARWIN_ATTR_CMN_FLAGS) {
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
flags = st.st_flags; /* XXX need convertion */
|
|
|
|
if (ATTR_APPEND(flags, bp, len) != 0)
|
|
|
|
goto out3;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kalist.commonattr & DARWIN_ATTR_CMN_USERACCESS) {
|
|
|
|
unsigned long ua = 0;
|
|
|
|
struct sys_access_args cup3;
|
|
|
|
register_t rv;
|
|
|
|
|
|
|
|
SCARG(&cup3, path) = SCARG(uap, path);
|
|
|
|
|
|
|
|
SCARG(&cup3, flags) = R_OK;
|
|
|
|
if (sys_access(l, &cup3, &rv) == 0)
|
|
|
|
ua |= R_OK;
|
2005-02-27 01:58:54 +03:00
|
|
|
|
2003-12-31 05:55:04 +03:00
|
|
|
SCARG(&cup3, flags) = W_OK;
|
|
|
|
if (sys_access(l, &cup3, &rv) == 0)
|
|
|
|
ua |= W_OK;
|
|
|
|
|
|
|
|
SCARG(&cup3, flags) = X_OK;
|
|
|
|
if (sys_access(l, &cup3, &rv) == 0)
|
|
|
|
ua |= X_OK;
|
|
|
|
|
|
|
|
if (ATTR_APPEND(ua, bp, len) != 0)
|
|
|
|
goto out3;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (kalist.volattr & DARWIN_ATTR_VOL_INFO) {
|
|
|
|
/* Nothing added, just skip */
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kalist.volattr & DARWIN_ATTR_VOL_FSTYPE) {
|
|
|
|
unsigned long fstype;
|
|
|
|
|
2007-06-18 00:43:10 +04:00
|
|
|
/* We'd need to convert f_fstypename - done for COMPAT_09 */
|
|
|
|
fstype = 0; /* f->f_type; */
|
2003-12-31 05:55:04 +03:00
|
|
|
if (ATTR_APPEND(fstype, bp, len) != 0)
|
|
|
|
goto out3;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kalist.volattr & DARWIN_ATTR_VOL_SIGNATURE) {
|
|
|
|
unsigned long sign;
|
|
|
|
|
2005-02-27 01:58:54 +03:00
|
|
|
/*
|
2003-12-31 05:55:04 +03:00
|
|
|
* XXX Volume signature, used to distinguish
|
2005-02-27 01:58:54 +03:00
|
|
|
* between volumes inside the same filesystem.
|
2003-12-31 05:55:04 +03:00
|
|
|
*/
|
2007-06-18 00:43:10 +04:00
|
|
|
sign = f->f_fsidx.__fsid_val[0];
|
2003-12-31 05:55:04 +03:00
|
|
|
if (ATTR_APPEND(sign, bp, len) != 0)
|
|
|
|
goto out3;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kalist.volattr & DARWIN_ATTR_VOL_SIZE) {
|
|
|
|
off_t size;
|
|
|
|
|
2007-06-18 00:43:10 +04:00
|
|
|
size = f->f_blocks * f->f_bsize;
|
2003-12-31 05:55:04 +03:00
|
|
|
if (ATTR_APPEND(size, bp, len) != 0)
|
|
|
|
goto out3;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kalist.volattr & DARWIN_ATTR_VOL_SPACEFREE) {
|
2005-05-30 02:08:16 +04:00
|
|
|
off_t ofree;
|
2003-12-31 05:55:04 +03:00
|
|
|
|
2007-06-18 00:43:10 +04:00
|
|
|
ofree = f->f_bfree * f->f_bsize;
|
2005-05-30 02:08:16 +04:00
|
|
|
if (ATTR_APPEND(ofree, bp, len) != 0)
|
2003-12-31 05:55:04 +03:00
|
|
|
goto out3;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kalist.volattr & DARWIN_ATTR_VOL_SPACEAVAIL) {
|
|
|
|
off_t avail;
|
|
|
|
|
2007-06-18 00:43:10 +04:00
|
|
|
avail = f->f_bavail * f->f_bsize;
|
2003-12-31 05:55:04 +03:00
|
|
|
if (ATTR_APPEND(avail, bp, len) != 0)
|
|
|
|
goto out3;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kalist.volattr & DARWIN_ATTR_VOL_MINALLOCATION) {
|
2005-05-30 02:08:16 +04:00
|
|
|
off_t omin;
|
2003-12-31 05:55:04 +03:00
|
|
|
|
2007-06-18 00:43:10 +04:00
|
|
|
omin = f->f_bsize; /* XXX probably wrong */
|
2005-05-30 02:08:16 +04:00
|
|
|
if (ATTR_APPEND(omin, bp, len) != 0)
|
2003-12-31 05:55:04 +03:00
|
|
|
goto out3;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kalist.volattr & DARWIN_ATTR_VOL_ALLOCATIONCLUMP) {
|
|
|
|
off_t clump;
|
|
|
|
|
2007-06-18 00:43:10 +04:00
|
|
|
clump = f->f_bsize; /* XXX proably wrong */
|
2003-12-31 05:55:04 +03:00
|
|
|
if (ATTR_APPEND(clump, bp, len) != 0)
|
|
|
|
goto out3;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kalist.volattr & DARWIN_ATTR_VOL_IOBLOCKSIZE) {
|
|
|
|
unsigned long size;
|
|
|
|
|
2007-06-18 00:43:10 +04:00
|
|
|
size = f->f_iosize;
|
2003-12-31 05:55:04 +03:00
|
|
|
if (ATTR_APPEND(size, bp, len) != 0)
|
|
|
|
goto out3;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kalist.volattr & DARWIN_ATTR_VOL_OBJCOUNT) {
|
|
|
|
unsigned long cnt;
|
|
|
|
|
2007-06-18 00:43:10 +04:00
|
|
|
cnt = f->f_files;
|
2003-12-31 05:55:04 +03:00
|
|
|
if (ATTR_APPEND(cnt, bp, len) != 0)
|
|
|
|
goto out3;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kalist.volattr & DARWIN_ATTR_VOL_FILECOUNT) {
|
|
|
|
unsigned long cnt;
|
|
|
|
|
2007-06-18 00:43:10 +04:00
|
|
|
cnt = f->f_files; /* XXX only files */
|
2003-12-31 05:55:04 +03:00
|
|
|
if (ATTR_APPEND(cnt, bp, len) != 0)
|
|
|
|
goto out3;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kalist.volattr & DARWIN_ATTR_VOL_DIRCOUNT) {
|
|
|
|
unsigned long cnt;
|
|
|
|
|
|
|
|
cnt = 0; /* XXX wrong, of course */
|
|
|
|
if (ATTR_APPEND(cnt, bp, len) != 0)
|
|
|
|
goto out3;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kalist.volattr & DARWIN_ATTR_VOL_MAXOBJCOUNT) {
|
|
|
|
unsigned long cnt;
|
|
|
|
|
2007-06-18 00:43:10 +04:00
|
|
|
cnt = f->f_files + f->f_ffree;
|
2003-12-31 05:55:04 +03:00
|
|
|
if (ATTR_APPEND(cnt, bp, len) != 0)
|
|
|
|
goto out3;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kalist.volattr & DARWIN_ATTR_VOL_MOUNTPOINT) {
|
|
|
|
darwin_attrreference_t dar;
|
|
|
|
|
|
|
|
vol_mountpoint_p = (darwin_attrreference_t *)bp;
|
|
|
|
if (ATTR_APPEND(dar, bp, len) != 0)
|
|
|
|
goto out3;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kalist.volattr & DARWIN_ATTR_VOL_NAME) {
|
|
|
|
darwin_attrreference_t dar;
|
|
|
|
|
|
|
|
vol_name_p = (darwin_attrreference_t *)bp;
|
|
|
|
if (ATTR_APPEND(dar, bp, len) != 0)
|
|
|
|
goto out3;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kalist.volattr & DARWIN_ATTR_VOL_MOUNTFLAGS) {
|
|
|
|
unsigned long flags;
|
|
|
|
|
2007-06-18 00:43:10 +04:00
|
|
|
flags = f->f_flag; /* XXX need convertion? */
|
2003-12-31 05:55:04 +03:00
|
|
|
if (ATTR_APPEND(flags, bp, len) != 0)
|
|
|
|
goto out3;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kalist.volattr & DARWIN_ATTR_VOL_MOUNTEDDEVICE) {
|
|
|
|
darwin_attrreference_t dar;
|
|
|
|
|
|
|
|
vol_mounteddevice_p = (darwin_attrreference_t *)bp;
|
|
|
|
if (ATTR_APPEND(dar, bp, len) != 0)
|
|
|
|
goto out3;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kalist.volattr & DARWIN_ATTR_VOL_ENCODINGSUSED) {
|
|
|
|
unsigned long long data;
|
|
|
|
|
2005-02-27 01:58:54 +03:00
|
|
|
/*
|
|
|
|
* XXX bitmap of encoding used in this volume
|
2003-12-31 05:55:04 +03:00
|
|
|
*/
|
|
|
|
(void)bzero(&data, sizeof(data));
|
|
|
|
if (ATTR_APPEND(data, bp, len) != 0)
|
|
|
|
goto out3;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kalist.volattr & DARWIN_ATTR_VOL_CAPABILITIES) { /* XXX */
|
|
|
|
darwin_vol_capabilities_attr_t data;
|
|
|
|
|
|
|
|
(void)bzero(&data, sizeof(data));
|
|
|
|
if (ATTR_APPEND(data, bp, len) != 0)
|
|
|
|
goto out3;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kalist.volattr & DARWIN_ATTR_VOL_ATTRIBUTES) { /* XXX */
|
|
|
|
darwin_vol_attributes_attr_t data;
|
|
|
|
|
|
|
|
(void)bzero(&data, sizeof(data));
|
|
|
|
if (ATTR_APPEND(data, bp, len) != 0)
|
|
|
|
goto out3;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kalist.dirattr & DARWIN_ATTR_DIR_LINKCOUNT) {
|
|
|
|
unsigned long cnt;
|
|
|
|
|
|
|
|
cnt = st.st_nlink;
|
|
|
|
if (ATTR_APPEND(cnt, bp, len) != 0)
|
|
|
|
goto out3;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kalist.dirattr & DARWIN_ATTR_DIR_ENTRYCOUNT) { /* XXX */
|
|
|
|
unsigned long data;
|
|
|
|
|
|
|
|
(void)bzero(&data, sizeof(data));
|
|
|
|
if (ATTR_APPEND(data, bp, len) != 0)
|
|
|
|
goto out3;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kalist.dirattr & DARWIN_ATTR_DIR_MOUNTSTATUS) { /* XXX */
|
|
|
|
unsigned long data;
|
|
|
|
|
|
|
|
(void)bzero(&data, sizeof(data));
|
|
|
|
if (ATTR_APPEND(data, bp, len) != 0)
|
|
|
|
goto out3;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kalist.fileattr & DARWIN_ATTR_FILE_LINKCOUNT) {
|
|
|
|
unsigned long cnt;
|
|
|
|
|
|
|
|
cnt = st.st_nlink;
|
|
|
|
if (ATTR_APPEND(cnt, bp, len) != 0)
|
|
|
|
goto out3;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kalist.fileattr & DARWIN_ATTR_FILE_TOTALSIZE) {
|
|
|
|
off_t size;
|
|
|
|
|
|
|
|
size = st.st_size;
|
|
|
|
if (ATTR_APPEND(size, bp, len) != 0)
|
|
|
|
goto out3;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kalist.fileattr & DARWIN_ATTR_FILE_ALLOCSIZE) {
|
|
|
|
off_t size;
|
|
|
|
|
2007-06-18 00:43:10 +04:00
|
|
|
size = st.st_blocks * f->f_bsize;
|
2003-12-31 05:55:04 +03:00
|
|
|
if (ATTR_APPEND(size, bp, len) != 0)
|
|
|
|
goto out3;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kalist.fileattr & DARWIN_ATTR_FILE_IOBLOCKSIZE) {
|
|
|
|
unsigned long size;
|
|
|
|
|
|
|
|
size = st.st_blksize;
|
|
|
|
if (ATTR_APPEND(size, bp, len) != 0)
|
|
|
|
goto out3;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kalist.fileattr & DARWIN_ATTR_FILE_CLUMPSIZE) {
|
|
|
|
unsigned long size;
|
|
|
|
|
|
|
|
size = st.st_blksize; /* XXX probably wrong */
|
|
|
|
if (ATTR_APPEND(size, bp, len) != 0)
|
|
|
|
goto out3;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kalist.fileattr & DARWIN_ATTR_FILE_DEVTYPE) {
|
|
|
|
unsigned long type;
|
|
|
|
|
|
|
|
type = st.st_rdev;
|
|
|
|
if (ATTR_APPEND(type, bp, len) != 0)
|
|
|
|
goto out3;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kalist.fileattr & DARWIN_ATTR_FILE_FILETYPE) {
|
|
|
|
unsigned long data;
|
|
|
|
|
|
|
|
/* Reserved, returns 0 */
|
|
|
|
(void)bzero(&data, sizeof(data));
|
|
|
|
if (ATTR_APPEND(data, bp, len) != 0)
|
|
|
|
goto out3;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kalist.fileattr & DARWIN_ATTR_FILE_FORKCOUNT) { /* XXX */
|
|
|
|
unsigned long cnt;
|
|
|
|
|
|
|
|
cnt = 1; /* Only one fork, of course */
|
|
|
|
if (ATTR_APPEND(cnt, bp, len) != 0)
|
|
|
|
goto out3;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kalist.fileattr & DARWIN_ATTR_FILE_FORKLIST) {
|
|
|
|
/* Unsupported in Darwin */
|
|
|
|
error = EINVAL;
|
|
|
|
goto out3;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kalist.fileattr & DARWIN_ATTR_FILE_DATALENGTH) { /* All forks */
|
|
|
|
off_t size;
|
|
|
|
|
|
|
|
size = st.st_size;
|
|
|
|
if (ATTR_APPEND(size, bp, len) != 0)
|
|
|
|
goto out3;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kalist.fileattr & DARWIN_ATTR_FILE_DATAALLOCSIZE) { /* All forks */
|
|
|
|
off_t size;
|
|
|
|
|
2007-06-18 00:43:10 +04:00
|
|
|
size = st.st_blocks * f->f_bsize;
|
2003-12-31 05:55:04 +03:00
|
|
|
if (ATTR_APPEND(size, bp, len) != 0)
|
|
|
|
goto out3;
|
|
|
|
}
|
|
|
|
|
2005-02-27 01:58:54 +03:00
|
|
|
if (kalist.fileattr & DARWIN_ATTR_FILE_DATAEXTENTS) {
|
2003-12-31 05:55:04 +03:00
|
|
|
darwin_extentrecord data;
|
|
|
|
|
|
|
|
/* Obsolete in Darwin */
|
|
|
|
(void)bzero(&data, sizeof(data));
|
|
|
|
if (ATTR_APPEND(data, bp, len) != 0)
|
|
|
|
goto out3;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kalist.fileattr & DARWIN_ATTR_FILE_RSRCLENGTH) {
|
|
|
|
off_t size;
|
|
|
|
|
|
|
|
size = 0;
|
|
|
|
if (ATTR_APPEND(size, bp, len) != 0)
|
|
|
|
goto out3;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kalist.fileattr & DARWIN_ATTR_FILE_RSRCALLOCSIZE) {
|
|
|
|
off_t size;
|
|
|
|
|
|
|
|
size = 0;
|
|
|
|
if (ATTR_APPEND(size, bp, len) != 0)
|
|
|
|
goto out3;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kalist.fileattr & DARWIN_ATTR_FILE_RSRCEXTENTS) {
|
|
|
|
darwin_extentrecord data;
|
|
|
|
|
|
|
|
/* Obsolete in Darwin */
|
|
|
|
(void)bzero(&data, sizeof(data));
|
|
|
|
if (ATTR_APPEND(data, bp, len) != 0)
|
|
|
|
goto out3;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kalist.forkattr & DARWIN_ATTR_FORK_TOTALSIZE) {
|
|
|
|
off_t size;
|
|
|
|
|
|
|
|
size = st.st_size;
|
|
|
|
if (ATTR_APPEND(size, bp, len) != 0)
|
|
|
|
goto out3;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kalist.forkattr & DARWIN_ATTR_FORK_ALLOCSIZE) {
|
|
|
|
off_t size;
|
|
|
|
|
2007-06-18 00:43:10 +04:00
|
|
|
size = st.st_blocks * f->f_bsize;
|
2003-12-31 05:55:04 +03:00
|
|
|
if (ATTR_APPEND(size, bp, len) != 0)
|
|
|
|
goto out3;
|
|
|
|
}
|
|
|
|
|
2005-02-27 01:58:54 +03:00
|
|
|
/*
|
|
|
|
* Now the variable length fields
|
2003-12-31 05:55:04 +03:00
|
|
|
*/
|
2005-02-27 01:58:54 +03:00
|
|
|
|
2003-12-31 05:55:04 +03:00
|
|
|
if (cmn_name_p) { /* DARWIN_ATTR_CMN_NAME */
|
|
|
|
cmn_name_p->attr_dataoffset = (u_long)bp - (u_long)cmn_name_p;
|
|
|
|
cmn_name_p->attr_length = nd.ni_cnd.cn_namelen;
|
2005-02-27 01:58:54 +03:00
|
|
|
if (darwin_attr_append(nd.ni_cnd.cn_nameptr,
|
2003-12-31 05:55:04 +03:00
|
|
|
cmn_name_p->attr_length, &bp, &len) != 0)
|
|
|
|
goto out3;
|
|
|
|
|
|
|
|
/* word alignement */
|
|
|
|
shift = (((u_long)bp & ~0x3UL) + 4) - (u_long)bp;
|
|
|
|
if (darwin_attr_append((char *)null, shift, &bp, &len) != 0)
|
|
|
|
goto out3;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vol_mountpoint_p) { /* DARWIN_ATTR_VOL_MOUNTPOINT */
|
2005-02-27 01:58:54 +03:00
|
|
|
vol_mountpoint_p->attr_dataoffset =
|
2003-12-31 05:55:04 +03:00
|
|
|
(u_long)bp - (u_long)vol_mountpoint_p;
|
2007-06-18 00:43:10 +04:00
|
|
|
vol_mountpoint_p->attr_length = strlen(f->f_mntonname);
|
|
|
|
if (darwin_attr_append(f->f_mntonname,
|
2003-12-31 05:55:04 +03:00
|
|
|
vol_mountpoint_p->attr_length, &bp, &len) != 0)
|
|
|
|
goto out3;
|
|
|
|
|
|
|
|
/* word alignement */
|
|
|
|
shift = (((u_long)bp & ~0x3UL) + 4) - (u_long)bp;
|
|
|
|
if (darwin_attr_append((char *)null, shift, &bp, &len) != 0)
|
|
|
|
goto out3;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vol_mounteddevice_p) { /* DARWIN_ATTR_VOL_MOUNTEDDEVICE */
|
2005-02-27 01:58:54 +03:00
|
|
|
vol_mounteddevice_p->attr_dataoffset =
|
2003-12-31 05:55:04 +03:00
|
|
|
(u_long)bp - (u_long)vol_mounteddevice_p;
|
2007-06-18 00:43:10 +04:00
|
|
|
vol_mounteddevice_p->attr_length = strlen(f->f_mntfromname);
|
|
|
|
if (darwin_attr_append(f->f_mntfromname,
|
2003-12-31 05:55:04 +03:00
|
|
|
vol_mounteddevice_p->attr_length, &bp, &len) != 0)
|
|
|
|
goto out3;
|
|
|
|
|
|
|
|
/* word alignement */
|
|
|
|
shift = (((u_long)bp & ~0x3UL) + 4) - (u_long)bp;
|
|
|
|
if (darwin_attr_append((char *)null, shift, &bp, &len) != 0)
|
|
|
|
goto out3;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vol_name_p) { /* DARWIN_ATTR_VOL_NAME */
|
|
|
|
char name[] = "Volume"; /* XXX We have no volume names... */
|
|
|
|
size_t namelen = strlen(name);
|
|
|
|
|
|
|
|
vol_name_p->attr_dataoffset = (u_long)bp - (u_long)vol_name_p;
|
|
|
|
vol_name_p->attr_length = namelen;
|
|
|
|
if (darwin_attr_append(name, namelen, &bp, &len) != 0)
|
|
|
|
goto out3;
|
|
|
|
|
|
|
|
/* word alignement */
|
|
|
|
shift = (((u_long)bp & ~0x3UL) + 4) - (u_long)bp;
|
|
|
|
if (darwin_attr_append((char *)null, shift, &bp, &len) != 0)
|
|
|
|
goto out3;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* And, finnally, the whole buffer length */
|
|
|
|
if (whole_len_p) {
|
|
|
|
*whole_len_p = SCARG(uap, buflen) - len;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We are done! Copyout the stuff and get away
|
|
|
|
*/
|
|
|
|
if (error == 0)
|
2005-05-30 02:08:16 +04:00
|
|
|
error = copyout(tbuf, SCARG(uap, attributes), *whole_len_p);
|
2003-12-31 05:55:04 +03:00
|
|
|
out3:
|
|
|
|
vput(vp);
|
|
|
|
out2:
|
2006-05-15 01:19:33 +04:00
|
|
|
kauth_cred_free(cred);
|
2005-05-30 02:08:16 +04:00
|
|
|
free(tbuf, M_TEMP);
|
2003-12-31 05:55:04 +03:00
|
|
|
|
2007-06-18 00:43:10 +04:00
|
|
|
STATVFSBUF_PUT(f);
|
2003-12-31 05:55:04 +03:00
|
|
|
return error;
|
|
|
|
}
|