xref: /illumos-gate/usr/src/uts/common/sys/dirent.h (revision b4203d75)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
58b4cf837Sjv  * Common Development and Distribution License (the "License").
68b4cf837Sjv  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
22*b4203d75SMarcel Telka /*	  All Rights Reserved	*/
237c478bd9Sstevel@tonic-gate 
247c478bd9Sstevel@tonic-gate 
257c478bd9Sstevel@tonic-gate /*
26ba3594baSGarrett D'Amore  * Copyright 2014 Garrett D'Amore <garrett@damore.org>
27ba3594baSGarrett D'Amore  *
288b4cf837Sjv  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
297c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
307c478bd9Sstevel@tonic-gate  */
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #ifndef _SYS_DIRENT_H
337c478bd9Sstevel@tonic-gate #define	_SYS_DIRENT_H
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate #include <sys/feature_tests.h>
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
387c478bd9Sstevel@tonic-gate extern "C" {
397c478bd9Sstevel@tonic-gate #endif
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate /*
427c478bd9Sstevel@tonic-gate  * File-system independent directory entry.
437c478bd9Sstevel@tonic-gate  */
447c478bd9Sstevel@tonic-gate typedef struct dirent {
457c478bd9Sstevel@tonic-gate 	ino_t		d_ino;		/* "inode number" of entry */
467c478bd9Sstevel@tonic-gate 	off_t		d_off;		/* offset of disk directory entry */
477c478bd9Sstevel@tonic-gate 	unsigned short	d_reclen;	/* length of this record */
487c478bd9Sstevel@tonic-gate 	char		d_name[1];	/* name of file */
497c478bd9Sstevel@tonic-gate } dirent_t;
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate #if defined(_SYSCALL32)
527c478bd9Sstevel@tonic-gate 
537c478bd9Sstevel@tonic-gate /* kernel's view of user ILP32 dirent */
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate typedef	struct dirent32 {
567c478bd9Sstevel@tonic-gate 	ino32_t		d_ino;		/* "inode number" of entry */
577c478bd9Sstevel@tonic-gate 	off32_t		d_off;		/* offset of disk directory entry */
587c478bd9Sstevel@tonic-gate 	uint16_t	d_reclen;	/* length of this record */
597c478bd9Sstevel@tonic-gate 	char		d_name[1];	/* name of file */
607c478bd9Sstevel@tonic-gate } dirent32_t;
617c478bd9Sstevel@tonic-gate 
627c478bd9Sstevel@tonic-gate #endif	/* _SYSCALL32 */
637c478bd9Sstevel@tonic-gate 
647c478bd9Sstevel@tonic-gate #ifdef	_LARGEFILE64_SOURCE
657c478bd9Sstevel@tonic-gate 
667c478bd9Sstevel@tonic-gate /*
677c478bd9Sstevel@tonic-gate  * transitional large file interface version AND kernel internal version
687c478bd9Sstevel@tonic-gate  */
697c478bd9Sstevel@tonic-gate typedef struct dirent64 {
707c478bd9Sstevel@tonic-gate 	ino64_t		d_ino;		/* "inode number" of entry */
717c478bd9Sstevel@tonic-gate 	off64_t		d_off;		/* offset of disk directory entry */
727c478bd9Sstevel@tonic-gate 	unsigned short	d_reclen;	/* length of this record */
737c478bd9Sstevel@tonic-gate 	char		d_name[1];	/* name of file */
747c478bd9Sstevel@tonic-gate } dirent64_t;
757c478bd9Sstevel@tonic-gate 
767c478bd9Sstevel@tonic-gate #endif	/* _LARGEFILE64_SOURCE */
777c478bd9Sstevel@tonic-gate 
787c478bd9Sstevel@tonic-gate #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
797c478bd9Sstevel@tonic-gate #if defined(_KERNEL)
807c478bd9Sstevel@tonic-gate #define	DIRENT64_RECLEN(namelen)	\
817c478bd9Sstevel@tonic-gate 	((offsetof(dirent64_t, d_name[0]) + 1 + (namelen) + 7) & ~ 7)
827c478bd9Sstevel@tonic-gate #define	DIRENT64_NAMELEN(reclen)	\
837c478bd9Sstevel@tonic-gate 	((reclen) - (offsetof(dirent64_t, d_name[0])))
847c478bd9Sstevel@tonic-gate #define	DIRENT32_RECLEN(namelen)	\
857c478bd9Sstevel@tonic-gate 	((offsetof(dirent32_t, d_name[0]) + 1 + (namelen) + 3) & ~ 3)
867c478bd9Sstevel@tonic-gate #define	DIRENT32_NAMELEN(reclen)	\
877c478bd9Sstevel@tonic-gate 	((reclen) - (offsetof(dirent32_t, d_name[0])))
887c478bd9Sstevel@tonic-gate #endif
897c478bd9Sstevel@tonic-gate 
908b4cf837Sjv /*
918b4cf837Sjv  * This is the maximum number of bytes that getdents(2) will store in
928b4cf837Sjv  * user-supplied dirent buffers.
938b4cf837Sjv  */
948b4cf837Sjv #define	MAXGETDENTS_SIZE	(64 * 1024)
958b4cf837Sjv 
967c478bd9Sstevel@tonic-gate #if !defined(_KERNEL)
977c478bd9Sstevel@tonic-gate 
987c478bd9Sstevel@tonic-gate /*
997c478bd9Sstevel@tonic-gate  * large file compilation environment setup
1007c478bd9Sstevel@tonic-gate  *
1017c478bd9Sstevel@tonic-gate  * In the LP64 compilation environment, map large file interfaces
1027c478bd9Sstevel@tonic-gate  * back to native versions where possible. (This only works because
1037c478bd9Sstevel@tonic-gate  * a 'struct dirent' == 'struct dirent64').
1047c478bd9Sstevel@tonic-gate  */
1057c478bd9Sstevel@tonic-gate 
1067c478bd9Sstevel@tonic-gate #if !defined(_LP64) && _FILE_OFFSET_BITS == 64
1077c478bd9Sstevel@tonic-gate #ifdef	__PRAGMA_REDEFINE_EXTNAME
1087c478bd9Sstevel@tonic-gate #pragma redefine_extname	getdents	getdents64
1097c478bd9Sstevel@tonic-gate #else
1107c478bd9Sstevel@tonic-gate #define	getdents		getdents64
1117c478bd9Sstevel@tonic-gate #endif
1127c478bd9Sstevel@tonic-gate #endif	/* !_LP64 && _FILE_OFFSET_BITS == 64 */
1137c478bd9Sstevel@tonic-gate 
1147c478bd9Sstevel@tonic-gate #if defined(_LP64) && defined(_LARGEFILE64_SOURCE)
1157c478bd9Sstevel@tonic-gate #ifdef	__PRAGMA_REDEFINE_EXTNAME
1167c478bd9Sstevel@tonic-gate #pragma	redefine_extname	getdents64	getdents
1177c478bd9Sstevel@tonic-gate #else
1187c478bd9Sstevel@tonic-gate #define	getdents64		getdents
1197c478bd9Sstevel@tonic-gate #define	dirent64		dirent
1207c478bd9Sstevel@tonic-gate #define	dirent64_t		dirent_t
1217c478bd9Sstevel@tonic-gate #endif
1227c478bd9Sstevel@tonic-gate #endif	/* _LP64 && _LARGEFILE64_SOURCE */
1237c478bd9Sstevel@tonic-gate 
1247c478bd9Sstevel@tonic-gate extern int getdents(int, struct dirent *, size_t);
1257c478bd9Sstevel@tonic-gate 
1267c478bd9Sstevel@tonic-gate /* N.B.: transitional large file interface version deliberately not provided */
1277c478bd9Sstevel@tonic-gate 
1287c478bd9Sstevel@tonic-gate #endif /* !defined(_KERNEL) */
1297c478bd9Sstevel@tonic-gate #endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
1307c478bd9Sstevel@tonic-gate 
1317c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1327c478bd9Sstevel@tonic-gate }
1337c478bd9Sstevel@tonic-gate #endif
1347c478bd9Sstevel@tonic-gate 
1357c478bd9Sstevel@tonic-gate #endif	/* _SYS_DIRENT_H */
136