199767f8919635c4928607450d9e0abb932109ceToomas Soome/*-
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Copyright (c) 1989, 1993
199767f8919635c4928607450d9e0abb932109ceToomas Soome * The Regents of the University of California. All rights reserved.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Redistribution and use in source and binary forms, with or without
199767f8919635c4928607450d9e0abb932109ceToomas Soome * modification, are permitted provided that the following conditions
199767f8919635c4928607450d9e0abb932109ceToomas Soome * are met:
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 1. Redistributions of source code must retain the above copyright
199767f8919635c4928607450d9e0abb932109ceToomas Soome * notice, this list of conditions and the following disclaimer.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 2. Redistributions in binary form must reproduce the above copyright
199767f8919635c4928607450d9e0abb932109ceToomas Soome * notice, this list of conditions and the following disclaimer in the
199767f8919635c4928607450d9e0abb932109ceToomas Soome * documentation and/or other materials provided with the distribution.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 4. Neither the name of the University nor the names of its contributors
199767f8919635c4928607450d9e0abb932109ceToomas Soome * may be used to endorse or promote products derived from this software
199767f8919635c4928607450d9e0abb932109ceToomas Soome * without specific prior written permission.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
199767f8919635c4928607450d9e0abb932109ceToomas Soome * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
199767f8919635c4928607450d9e0abb932109ceToomas Soome * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
199767f8919635c4928607450d9e0abb932109ceToomas Soome * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
199767f8919635c4928607450d9e0abb932109ceToomas Soome * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
199767f8919635c4928607450d9e0abb932109ceToomas Soome * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
199767f8919635c4928607450d9e0abb932109ceToomas Soome * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
199767f8919635c4928607450d9e0abb932109ceToomas Soome * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
199767f8919635c4928607450d9e0abb932109ceToomas Soome * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
199767f8919635c4928607450d9e0abb932109ceToomas Soome * SUCH DAMAGE.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * @(#)dirent.h 8.3 (Berkeley) 8/10/94
199767f8919635c4928607450d9e0abb932109ceToomas Soome * $FreeBSD$
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifndef _SYS_DIRENT_H_
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define _SYS_DIRENT_H_
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include <sys/cdefs.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include <sys/_types.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * The dirent structure defines the format of directory entries returned by
199767f8919635c4928607450d9e0abb932109ceToomas Soome * the getdirentries(2) system call.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * A directory entry has a struct dirent at the front of it, containing its
199767f8919635c4928607450d9e0abb932109ceToomas Soome * inode number, the length of the entry, and the length of the name
199767f8919635c4928607450d9e0abb932109ceToomas Soome * contained in the entry. These are followed by the name padded to a 4
199767f8919635c4928607450d9e0abb932109ceToomas Soome * byte boundary with null bytes. All names are guaranteed null terminated.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * The maximum length of a name in a directory is MAXNAMLEN.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct dirent {
199767f8919635c4928607450d9e0abb932109ceToomas Soome __uint32_t d_fileno; /* file number of entry */
199767f8919635c4928607450d9e0abb932109ceToomas Soome __uint16_t d_reclen; /* length of this record */
199767f8919635c4928607450d9e0abb932109ceToomas Soome __uint8_t d_type; /* file type, see below */
199767f8919635c4928607450d9e0abb932109ceToomas Soome __uint8_t d_namlen; /* length of string in d_name */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if __BSD_VISIBLE
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define MAXNAMLEN 255
199767f8919635c4928607450d9e0abb932109ceToomas Soome char d_name[MAXNAMLEN + 1]; /* name must be no longer than this */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#else
199767f8919635c4928607450d9e0abb932109ceToomas Soome char d_name[255 + 1]; /* name must be no longer than this */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome};
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if __BSD_VISIBLE
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * File types
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define DT_UNKNOWN 0
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define DT_FIFO 1
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define DT_CHR 2
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define DT_DIR 4
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define DT_BLK 6
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define DT_REG 8
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define DT_LNK 10
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define DT_SOCK 12
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define DT_WHT 14
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Convert between stat structure types and directory types.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define IFTODT(mode) (((mode) & 0170000) >> 12)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define DTTOIF(dirtype) ((dirtype) << 12)
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * The _GENERIC_DIRSIZ macro gives the minimum record length which will hold
199767f8919635c4928607450d9e0abb932109ceToomas Soome * the directory entry. This returns the amount of space in struct direct
199767f8919635c4928607450d9e0abb932109ceToomas Soome * without the d_name field, plus enough space for the name with a terminating
199767f8919635c4928607450d9e0abb932109ceToomas Soome * null byte (dp->d_namlen+1), rounded up to a 4 byte boundary.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * XXX although this macro is in the implementation namespace, it requires
199767f8919635c4928607450d9e0abb932109ceToomas Soome * a manifest constant that is not.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define _GENERIC_DIRSIZ(dp) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome ((sizeof (struct dirent) - (MAXNAMLEN+1)) + (((dp)->d_namlen+1 + 3) &~ 3))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif /* __BSD_VISIBLE */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef _KERNEL
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define GENERIC_DIRSIZ(dp) _GENERIC_DIRSIZ(dp)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif /* !_SYS_DIRENT_H_ */