xref: /illumos-gate/usr/src/uts/common/sys/dirent.h (revision 8b4cf837)
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
5*8b4cf837Sjv  * Common Development and Distribution License (the "License").
6*8b4cf837Sjv  * 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	*/
227c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
237c478bd9Sstevel@tonic-gate 
247c478bd9Sstevel@tonic-gate 
257c478bd9Sstevel@tonic-gate /*
26*8b4cf837Sjv  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
277c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
287c478bd9Sstevel@tonic-gate  */
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #ifndef _SYS_DIRENT_H
317c478bd9Sstevel@tonic-gate #define	_SYS_DIRENT_H
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #include <sys/feature_tests.h>
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
367c478bd9Sstevel@tonic-gate extern "C" {
377c478bd9Sstevel@tonic-gate #endif
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate /*
407c478bd9Sstevel@tonic-gate  * File-system independent directory entry.
417c478bd9Sstevel@tonic-gate  */
427c478bd9Sstevel@tonic-gate typedef struct dirent {
437c478bd9Sstevel@tonic-gate 	ino_t		d_ino;		/* "inode number" of entry */
447c478bd9Sstevel@tonic-gate 	off_t		d_off;		/* offset of disk directory entry */
457c478bd9Sstevel@tonic-gate 	unsigned short	d_reclen;	/* length of this record */
467c478bd9Sstevel@tonic-gate 	char		d_name[1];	/* name of file */
477c478bd9Sstevel@tonic-gate } dirent_t;
487c478bd9Sstevel@tonic-gate 
497c478bd9Sstevel@tonic-gate #if defined(_SYSCALL32)
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate /* kernel's view of user ILP32 dirent */
527c478bd9Sstevel@tonic-gate 
537c478bd9Sstevel@tonic-gate typedef	struct dirent32 {
547c478bd9Sstevel@tonic-gate 	ino32_t		d_ino;		/* "inode number" of entry */
557c478bd9Sstevel@tonic-gate 	off32_t		d_off;		/* offset of disk directory entry */
567c478bd9Sstevel@tonic-gate 	uint16_t	d_reclen;	/* length of this record */
577c478bd9Sstevel@tonic-gate 	char		d_name[1];	/* name of file */
587c478bd9Sstevel@tonic-gate } dirent32_t;
597c478bd9Sstevel@tonic-gate 
607c478bd9Sstevel@tonic-gate #endif	/* _SYSCALL32 */
617c478bd9Sstevel@tonic-gate 
627c478bd9Sstevel@tonic-gate #ifdef	_LARGEFILE64_SOURCE
637c478bd9Sstevel@tonic-gate 
647c478bd9Sstevel@tonic-gate /*
657c478bd9Sstevel@tonic-gate  * transitional large file interface version AND kernel internal version
667c478bd9Sstevel@tonic-gate  */
677c478bd9Sstevel@tonic-gate typedef struct dirent64 {
687c478bd9Sstevel@tonic-gate 	ino64_t		d_ino;		/* "inode number" of entry */
697c478bd9Sstevel@tonic-gate 	off64_t		d_off;		/* offset of disk directory entry */
707c478bd9Sstevel@tonic-gate 	unsigned short	d_reclen;	/* length of this record */
717c478bd9Sstevel@tonic-gate 	char		d_name[1];	/* name of file */
727c478bd9Sstevel@tonic-gate } dirent64_t;
737c478bd9Sstevel@tonic-gate 
747c478bd9Sstevel@tonic-gate #endif	/* _LARGEFILE64_SOURCE */
757c478bd9Sstevel@tonic-gate 
767c478bd9Sstevel@tonic-gate #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
777c478bd9Sstevel@tonic-gate #if defined(_KERNEL)
787c478bd9Sstevel@tonic-gate #define	DIRENT64_RECLEN(namelen)	\
797c478bd9Sstevel@tonic-gate 	((offsetof(dirent64_t, d_name[0]) + 1 + (namelen) + 7) & ~ 7)
807c478bd9Sstevel@tonic-gate #define	DIRENT64_NAMELEN(reclen)	\
817c478bd9Sstevel@tonic-gate 	((reclen) - (offsetof(dirent64_t, d_name[0])))
827c478bd9Sstevel@tonic-gate #define	DIRENT32_RECLEN(namelen)	\
837c478bd9Sstevel@tonic-gate 	((offsetof(dirent32_t, d_name[0]) + 1 + (namelen) + 3) & ~ 3)
847c478bd9Sstevel@tonic-gate #define	DIRENT32_NAMELEN(reclen)	\
857c478bd9Sstevel@tonic-gate 	((reclen) - (offsetof(dirent32_t, d_name[0])))
867c478bd9Sstevel@tonic-gate #endif
877c478bd9Sstevel@tonic-gate 
88*8b4cf837Sjv /*
89*8b4cf837Sjv  * This is the maximum number of bytes that getdents(2) will store in
90*8b4cf837Sjv  * user-supplied dirent buffers.
91*8b4cf837Sjv  */
92*8b4cf837Sjv #define	MAXGETDENTS_SIZE	(64 * 1024)
93*8b4cf837Sjv 
947c478bd9Sstevel@tonic-gate #if !defined(_KERNEL)
957c478bd9Sstevel@tonic-gate 
967c478bd9Sstevel@tonic-gate /*
977c478bd9Sstevel@tonic-gate  * large file compilation environment setup
987c478bd9Sstevel@tonic-gate  *
997c478bd9Sstevel@tonic-gate  * In the LP64 compilation environment, map large file interfaces
1007c478bd9Sstevel@tonic-gate  * back to native versions where possible. (This only works because
1017c478bd9Sstevel@tonic-gate  * a 'struct dirent' == 'struct dirent64').
1027c478bd9Sstevel@tonic-gate  */
1037c478bd9Sstevel@tonic-gate 
1047c478bd9Sstevel@tonic-gate #if !defined(_LP64) && _FILE_OFFSET_BITS == 64
1057c478bd9Sstevel@tonic-gate #ifdef	__PRAGMA_REDEFINE_EXTNAME
1067c478bd9Sstevel@tonic-gate #pragma redefine_extname	getdents	getdents64
1077c478bd9Sstevel@tonic-gate #else
1087c478bd9Sstevel@tonic-gate #define	getdents		getdents64
1097c478bd9Sstevel@tonic-gate #endif
1107c478bd9Sstevel@tonic-gate #endif	/* !_LP64 && _FILE_OFFSET_BITS == 64 */
1117c478bd9Sstevel@tonic-gate 
1127c478bd9Sstevel@tonic-gate #if defined(_LP64) && defined(_LARGEFILE64_SOURCE)
1137c478bd9Sstevel@tonic-gate #ifdef	__PRAGMA_REDEFINE_EXTNAME
1147c478bd9Sstevel@tonic-gate #pragma	redefine_extname	getdents64	getdents
1157c478bd9Sstevel@tonic-gate #else
1167c478bd9Sstevel@tonic-gate #define	getdents64		getdents
1177c478bd9Sstevel@tonic-gate #define	dirent64		dirent
1187c478bd9Sstevel@tonic-gate #define	dirent64_t		dirent_t
1197c478bd9Sstevel@tonic-gate #endif
1207c478bd9Sstevel@tonic-gate #endif	/* _LP64 && _LARGEFILE64_SOURCE */
1217c478bd9Sstevel@tonic-gate 
1227c478bd9Sstevel@tonic-gate #if defined(__STDC__)
1237c478bd9Sstevel@tonic-gate extern int getdents(int, struct dirent *, size_t);
1247c478bd9Sstevel@tonic-gate #else
1257c478bd9Sstevel@tonic-gate extern int getdents();
1267c478bd9Sstevel@tonic-gate #endif
1277c478bd9Sstevel@tonic-gate 
1287c478bd9Sstevel@tonic-gate /* N.B.: transitional large file interface version deliberately not provided */
1297c478bd9Sstevel@tonic-gate 
1307c478bd9Sstevel@tonic-gate #endif /* !defined(_KERNEL) */
1317c478bd9Sstevel@tonic-gate #endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
1327c478bd9Sstevel@tonic-gate 
1337c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1347c478bd9Sstevel@tonic-gate }
1357c478bd9Sstevel@tonic-gate #endif
1367c478bd9Sstevel@tonic-gate 
1377c478bd9Sstevel@tonic-gate #endif	/* _SYS_DIRENT_H */
138