2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License (the "License").
2N/A * You may not use this file except in compliance with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A
2N/A/*
2N/A * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
2N/A */
2N/A
2N/A
2N/A#include <stdio.h>
2N/A#include <strings.h>
2N/A#include <fcntl.h>
2N/A#include <stddef.h>
2N/A#include <sys/types.h>
2N/A#include <sys/dirent.h>
2N/A#include <libuvfs_impl.h>
2N/A
2N/A/*
2N/A * This comes from sys/dirent.h, but is wrapped around ifdef _KERNEL
2N/A * need to fix that, but need to be cautious to not expose it when
2N/A * we aren't suppose to or we may break a header issue with one of the
2N/A * POSIX tests, such as vsx?
2N/A */
2N/A#define DIRENT64_RECLEN(namelen) \
2N/A ((offsetof(dirent64_t, d_name[0]) + 1 + (namelen) + 7) & ~ 7)
2N/A#define DIRENT64_NAMELEN(reclen) \
2N/A ((reclen) - (offsetof(dirent64_t, d_name[0])))
2N/A
2N/Asize_t
2N/Alibuvfs_add_direntry(void *data_buf, size_t buflen, const char *name,
2N/A ino64_t ino, off64_t off, void **cookie)
2N/A{
2N/A dirent64_t *dp;
2N/A int reclen;
2N/A
2N/A /*
2N/A * Remember to add edirent_t support.
2N/A * need to fix sys/extdirent.h to allow it to be included in
2N/A * user space
2N/A */
2N/A if (*cookie == NULL) {
2N/A dp = (dirent64_t *)data_buf;
2N/A *cookie = (void *)dp;
2N/A } else
2N/A dp = (dirent64_t *)*cookie;
2N/A
2N/A reclen = DIRENT64_RECLEN(strlen(name));
2N/A
2N/A if (((char *)*cookie + reclen) > ((char *)data_buf + buflen))
2N/A return (0);
2N/A *cookie = (void **)((uintptr_t)*cookie + reclen);
2N/A dp->d_ino = ino;
2N/A dp->d_reclen = reclen;
2N/A dp->d_off = (off == -1) ? (uintptr_t)*cookie - (uintptr_t)data_buf :
2N/A off;
2N/A (void) strlcpy(dp->d_name, name, DIRENT64_NAMELEN(reclen));
2N/A return (reclen);
2N/A}