History log of /freebsd-current/lib/libc/gen/opendir.c
Revision Date Author Comments
# dc36d6f9 23-Nov-2023 Warner Losh <imp@FreeBSD.org>

lib: Remove ancient SCCS tags.

Remove ancient SCCS tags from the tree, automated scripting, with two
minor fixup to keep things compiling. All the common forms in the tree
were removed with a perl script.

Sponsored by: Netflix


# 1d386b48 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

Remove $FreeBSD$: one-line .c pattern

Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/


# 48340ae7 28-Jan-2020 Mateusz Guzik <mjg@FreeBSD.org>

libc: remove forward compat added in r356830 for F_ISUNIONSTACK


# 90910707 17-Jan-2020 Mateusz Guzik <mjg@FreeBSD.org>

libc: fix build after r356830

Apparently building with 'cd lib/libc; make all install' is not the same
as buildworld.

Reported by: Michael Butler


# d3cc5354 17-Jan-2020 Mateusz Guzik <mjg@FreeBSD.org>

vfs: provide F_ISUNIONSTACK as a kludge for libc

Prior to introduction of this op libc's readdir would call fstatfs(2), in
effect unnecessarily copying kilobytes of data just to check fs name and a
mount flag.

Reviewed by: kib (previous version)
Differential Revision: https://reviews.freebsd.org/D23162


# 360af171 17-Jan-2020 Mateusz Guzik <mjg@FreeBSD.org>

libc: assume no union stack if fstatfs fails in readdir

The failure is not really expected, but should it happen it's better to
get some data.

Suggested by: kib


# 0cab2a4a 23-Jun-2019 Alex Richardson <arichardson@FreeBSD.org>

Fix two WARNS=6 warnings in opendir.c and telldir.c

This is in preparation for compiling these files as part of rtld (which is
built with WARNS=6). See https://reviews.freebsd.org/D20663 for more details.


# c1920558 03-Jul-2018 John Baldwin <jhb@FreeBSD.org>

Clean up the vcs ID strings in libc's gen/ directory.

- Move CSRG IDs into __SCCSID().
- When a file has been copied, consistently use 'From: <tag>' for strings
referencing the version of the source file copied from in the license
block comment.
- Some of the 'From:' tags were using $FreeBSD$ that was being expanded on
each checkout. Fix those to hardcode the FreeBSD tag from the file that
was copied at the time of the copy.
- When multiple strings are present list them in "chronological" order,
so CSRG (__SCCSID) before FreeBSD (__FBSDID). If a file came from
OtherBSD and contains a CSRG ID from the OtherBSD file, use the order
CSRG -> OtherBSD -> FreeBSD.

Reviewed by: imp
Differential Revision: https://reviews.freebsd.org/D15831


# 8a16b7a1 20-Nov-2017 Pedro F. Giffuni <pfg@FreeBSD.org>

General further adoption of SPDX licensing ID tags.

Mainly focus on files that use BSD 3-Clause license.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.

Special thanks to Wind River for providing access to "The Duke of
Highlander" tool: an older (2014) run over FreeBSD tree was useful as a
starting point.


# 69921123 23-May-2017 Konstantin Belousov <kib@FreeBSD.org>

Commit the 64-bit inode project.

Extend the ino_t, dev_t, nlink_t types to 64-bit ints. Modify
struct dirent layout to add d_off, increase the size of d_fileno
to 64-bits, increase the size of d_namlen to 16-bits, and change
the required alignment. Increase struct statfs f_mntfromname[] and
f_mntonname[] array length MNAMELEN to 1024.

ABI breakage is mitigated by providing compatibility using versioned
symbols, ingenious use of the existing padding in structures, and
by employing other tricks. Unfortunately, not everything can be
fixed, especially outside the base system. For instance, third-party
APIs which pass struct stat around are broken in backward and
forward incompatible ways.

Kinfo sysctl MIBs ABI is changed in backward-compatible way, but
there is no general mechanism to handle other sysctl MIBS which
return structures where the layout has changed. It was considered
that the breakage is either in the management interfaces, where we
usually allow ABI slip, or is not important.

Struct xvnode changed layout, no compat shims are provided.

For struct xtty, dev_t tty device member was reduced to uint32_t.
It was decided that keeping ABI compat in this case is more useful
than reporting 64-bit dev_t, for the sake of pstat.

Update note: strictly follow the instructions in UPDATING. Build
and install the new kernel with COMPAT_FREEBSD11 option enabled,
then reboot, and only then install new world.

Credits: The 64-bit inode project, also known as ino64, started life
many years ago as a project by Gleb Kurtsou (gleb). Kirk McKusick
(mckusick) then picked up and updated the patch, and acted as a
flag-waver. Feedback, suggestions, and discussions were carried
by Ed Maste (emaste), John Baldwin (jhb), Jilles Tjoelker (jilles),
and Rick Macklem (rmacklem). Kris Moore (kris) performed an initial
ports investigation followed by an exp-run by Antoine Brodin (antoine).
Essential and all-embracing testing was done by Peter Holm (pho).
The heavy lifting of coordinating all these efforts and bringing the
project to completion were done by Konstantin Belousov (kib).

Sponsored by: The FreeBSD Foundation (emaste, kib)
Differential revision: https://reviews.freebsd.org/D10439


# fbbd9655 28-Feb-2017 Warner Losh <imp@FreeBSD.org>

Renumber copyright clause 4

Renumber cluase 4 to 3, per what everybody else did when BSD granted
them permission to remove clause 3. My insistance on keeping the same
numbering for legal reasons is too pedantic, so give up on that point.

Submitted by: Jan Schaumann <jschauma@stevens.edu>
Pull Request: https://github.com/freebsd/freebsd/pull/96


# 513004a2 10-Apr-2016 Pedro F. Giffuni <pfg@FreeBSD.org>

libc: replace 0 with NULL for pointers.

While here also cleanup some surrounding code; particularly
drop some malloc() casts.

Found with devel/coccinelle.

Reviewed by: bde (previous version - all new bugs are mine)


# 9f72c032 11-Jul-2014 John Baldwin <jhb@FreeBSD.org>

Fix some edge cases with rewinddir():
- In the unionfs case, opendir() and fdopendir() read the directory's full
contents and cache it. This cache is not refreshed when rewinddir() is
called, so rewinddir() will not notice updates to a directory. Fix this
by splitting the code to fetch a directory's contents out of
__opendir_common() into a new _filldir() function and call this from
rewinddir() when operating on a unionfs directory.
- If rewinddir() is called on a directory opened with fdopendir() before
any directory entries are fetched, rewinddir() will not adjust the seek
location of the backing file descriptor. If the file descriptor passed
to fdopendir() had a non-zero offset, the rewinddir() will not rewind to
the beginning. Fix this by always seeking back to 0 in rewinddir().
This means the dd_rewind hack can also be removed.

While here, add missing locking to rewinddir().

CR: https://phabric.freebsd.org/D312
Reviewed by: jilles
MFC after: 1 week


# c6344d08 24-Feb-2013 Jilles Tjoelker <jilles@FreeBSD.org>

libc/opendir: Improve behaviour of union uniquifier:

* Reopen the directory using openat(fd, ".", ...) instead of opening the
pathname again. This fixes a race condition where the meaning of the
pathname changes and allows a reopen with fdopendir().
* Always reopen the directory for union stacks, not only when DTF_REWIND
is passed. Applications should be able to fchdir(dirfd(dir)) and
*at(dirfd(dir), ...). DTF_REWIND now does nothing.


# 05eb11cb 29-Sep-2012 Jilles Tjoelker <jilles@FreeBSD.org>

libc: Use O_CLOEXEC for various internal file descriptors.

This fixes a race condition where another thread may fork() before CLOEXEC
is set, unintentionally passing the descriptor to the child process.

This commit only adds O_CLOEXEC flags to open() or openat() calls where no
fcntl(fd, F_SETFD, FD_CLOEXEC) follows. The separate fcntl() call still
leaves a race window so it should be fixed later.


# 0bb2aabf 18-May-2012 Gleb Kurtsou <gleb@FreeBSD.org>

Hide DIR definition by making it an opaque struct typedef.

Introduce dirfd() libc exported symbol replacing macro with same name,
preserve _dirfd() macro for internal use.

Replace dirp->dd_fd with dirfd() call. Avoid using dirfd as variable
name to prevent shadowing global symbol.

Sponsored by: Google Summer Of Code 2011


# 01e49397 02-Mar-2012 Ruslan Ermilov <ru@FreeBSD.org>

Finally removed the stat() and fstat() calls from the opendir() code.
They were made excessive in r205424 by opening with O_DIRECTORY.
Also eliminated the fcntl() call used to set FD_CLOEXEC by opening
with O_CLOEXEC.

(fdopendir() still checks that the passed descriptor is a directory,
and sets FD_CLOEXEC on it.)

Reviewed by: ed


# 38574aa8 22-Nov-2011 Jilles Tjoelker <jilles@FreeBSD.org>

fdopendir(): Do not close the passed file descriptor on failure.

Reviewed by: delphij


# a7d5f7eb 19-Oct-2010 Jamie Gritton <jamie@FreeBSD.org>

A new jail(8) with a configuration file, to replace the work currently done
by /etc/rc.d/jail.


# 070f2a98 21-Mar-2010 Ed Schouten <ed@FreeBSD.org>

Let opendir() use O_DIRECTORY.

I am not removing the fstat() calls here, since we cannot yet assume
people will always run kernels that respect O_DIRECTORY.


# fe0506d7 09-Mar-2010 Marcel Moolenaar <marcel@FreeBSD.org>

Create the altix project branch. The altix project will add support
for the SGI Altix 350 to FreeBSD/ia64. The hardware used for porting
is a two-module system, consisting of a base compute module and a
CPU expansion module. SGI's NUMAFlex architecture can be an excellent
platform to test CPU affinity and NUMA-aware features in FreeBSD.


# b3c4be73 23-Jan-2010 Konstantin Belousov <kib@FreeBSD.org>

Merge scandir(3) interface update to stable/8.

MFC r201512:
Modernize scandir(3) and alphasort(3) interfaces according to the IEEE
Std 1003.1-2008.

MFC r201602:
Move scandir(3) and alphasort(3) into XSI namespace.

MFC r201604:
Use thunks to adapt alphasort-like interface to the comparision function
required by qsort() and qsort_r().

MFC r202556 (by ache):
Use strcoll() in opendir() and alphasort(). Remove some comments.

MFC r202572 (by ache):
Revert to using strcmp() for opendir().

MFC r202677 (by ache):
Style.

MFC r202679 (by ache):
Style: rename internal function to opendir_compar().

MFC r202691 (by ache):
For alphasort(3) add reference to strcoll(3).

MFC r202693 (by ache):
Style: reword comment.


# e5c9c853 20-Jan-2010 Andrey A. Chernov <ache@FreeBSD.org>

Style: rename internal function to opendir_compar()

Pointed by: bde


# b9a74f2a 18-Jan-2010 Andrey A. Chernov <ache@FreeBSD.org>

Double checking my commit I found that comment saying that
POSIX 2008 and XSI 7require strcoll() for opendir() is not true.
I can't find such requirement in POSIX 2008 and XSI 7.

So, back out that part of my commit, returning old strcmp(), and remove
this misleading comment.


# dcdafd0e 18-Jan-2010 Andrey A. Chernov <ache@FreeBSD.org>

a) Use strcoll() in opendir() and alphasort() as POSIX 2008 requires.
It also matches now how our 'ls' works for years.

b) Remove comment expressed 2 fears:
1) One just simple describe how strcoll() works in _any_ context,
not for directories only. Are we plan to remove strcoll() from everything
just because it is little more complex than strcmp()? I doubt, and
directories give nothing different here. Moreover, strcoll() used
in 'ls' for years and nobody complaints yet.

2) Plain wrong statement about undefined strcoll() behaviour. strcoll()
always gives predictable results, falling back to strcmp() on any
trouble, see strcoll(3).

No objections from -current list discussion.


# f5636f88 05-Jan-2010 Konstantin Belousov <kib@FreeBSD.org>

Do not rely on behaviour undefined by ANSI C, use thunks to adapt
alphasort-like interface to the comparision function required by
qsort() and qsort_r().

For opendir() thunk and alphasort(), comment on why we deviated from
POSIX by using strcmp() instead of strcoll().

Requested and reviewed by: bde
MFC after: 2 weeks


# 4176dd52 04-Jan-2010 Konstantin Belousov <kib@FreeBSD.org>

Modernize scandir(3) and alphasort(3) interfaces according to the IEEE
Std 1003.1-2008. Both Linux and Solaris conforms to the new definitions,
so we better follow too (older glibc used old BSDish alphasort prototype
and corresponding type of the comparision function for scandir). While
there, change the definitions of the functions to ANSI C and fix several
style issues nearby.

Remove requirement for "sys/types.h" include for functions from manpage.

POSIX also requires that alphasort(3) sorts as if strcoll(3) was used,
but leave the strcmp(3) call in the function for now.

Adapt in-tree callers of scandir(3) to new declaration. The fact that
select_sections() from catman(1) could modify supplied struct dirent is
a bug.

PR: standards/142255
MFC after: 2 weeks


# d7f03759 19-Oct-2008 Ulf Lilleengen <lulf@FreeBSD.org>

- Import the HEAD csup code which is the basis for the cvsmode work.


# 6fda52ba 16-Apr-2008 Xin LI <delphij@FreeBSD.org>

Implement fdopendir(3) by splitting __opendir2() into two parts, the upper part
deals with the usual __opendir2() calls, and the rest part with an interface
translator to expose fdopendir(3) functionality. Manual page was obtained from
kib@'s work for *at(2) system calls.


# f6386c25 16-Apr-2008 Xin LI <delphij@FreeBSD.org>

Style fixes to opendir.c:
- Use /*- for copyright block;
- ANSIfy.


# c879ae35 08-Jan-2007 Warner Losh <imp@FreeBSD.org>

Per Regents of the University of Calfornia letter, remove advertising
clause.

# If I've done so improperly on a file, please let me know.


# 4eae39bf 14-Aug-2004 Stefan Farfeleder <stefanf@FreeBSD.org>

Avoid using void pointers in additive expressions.

PR: 56653


# 4da7d0f5 25-Dec-2003 Doug Rabson <dfr@FreeBSD.org>

Make sure we initialise dirp->dd_size if we aren't reading a unionfs
directory.

Special thanks to: valgrind


# 6e7988b9 15-May-2003 Tim J. Robbins <tjr@FreeBSD.org>

Catch up with the renaming of the "union" filesystem to "unionfs".
Fixes a problem where directory entries could show up twice: once
on the top layer of the union stack, and once on the bottom layer.

Approved by: re (rwatson)


# 81b3ad59 03-Jan-2003 Tim J. Robbins <tjr@FreeBSD.org>

#include <string.h> for strcmp()'s prototype.


# ea8d448a 31-Jan-2002 David E. O'Brien <obrien@FreeBSD.org>

Fix SCM ID's.


# 6eabd845 10-Oct-2001 Bruce Evans <bde@FreeBSD.org>

Compensate for "Compensate for header dethreading" by backing it out.


# e16138fe 01-May-2001 Mark Murray <markm@FreeBSD.org>

Compensate for header dethreading.


# b2bcd87e 23-Apr-2001 Joerg Wunsch <joerg@FreeBSD.org>

Fix directory reads of MNT_UNION mounts, where entries present in both
layers would be displayed twice.

PR: bin/26498
Submitted by: Olliver Fromme <olli@secnetix.de>


# 8bb47e40 05-Mar-2001 David E. O'Brien <obrien@FreeBSD.org>

Fix style bug that was introduced.


# d201fe46 24-Jan-2001 Daniel Eischen <deischen@FreeBSD.org>

Remove _THREAD_SAFE and make libc thread-safe by default by
adding (weak definitions to) stubs for some of the pthread
functions. If the threads library is linked in, the real
pthread functions will pulled in.

Use the following convention for system calls wrapped by the
threads library:
__sys_foo - actual system call
_foo - weak definition to __sys_foo
foo - weak definition to __sys_foo

Change all libc uses of system calls wrapped by the threads
library from foo to _foo. In order to define the prototypes
for _foo(), we introduce namespace.h and un-namespace.h
(suggested by bde). All files that need to reference these
system calls, should include namespace.h before any standard
includes, then include un-namespace.h after the standard
includes and before any local includes. <db.h> is an exception
and shouldn't be included in between namespace.h and
un-namespace.h namespace.h will define foo to _foo, and
un-namespace.h will undefine foo.

Try to eliminate some of the recursive calls to MT-safe
functions in libc/stdio in preparation for adding a mutex
to FILE. We have recursive mutexes, but would like to avoid
using them if possible.

Remove uneeded includes of <errno.h> from a few files.

Add $FreeBSD$ to a few files in order to pass commitprep.

Approved by: -arch


# 10d1cba0 10-Dec-2000 Daniel Eischen <deischen@FreeBSD.org>

Move telldir position recording type definitions and prototypes
to "telldir.h" in order to prevent namespace pollution in
<dirent.h> (which was including <sys/queue.h>).

Add $FreeBSD$ to rewinddir.c and seekdir.c.


# ef80a534 05-Dec-2000 Daniel Eischen <deischen@FreeBSD.org>

Cleanup XXXdir functions to eliminate global hash table of
telldir positions. This will allow (future) locking on a
per-DIR basis (for MT-safety). For now, this change does
the following:

o Remove the hash table from telldir.c. Recode to use queue
macros.

o Remove 'const' from 'telldir(const DIR *)'.

o Remove 'register' variables as suggested in a recent
thread.

No response from: -current


# 9233c4d9 27-Jan-2000 Jason Evans <jasone@FreeBSD.org>

Simplify sytem call renaming. Instead of _foo() <-- _libc_foo <-- foo(),
just use _foo() <-- foo(). In the case of a libpthread that doesn't do
call conversion (such as linuxthreads and our upcoming libpthread), this
is adequate. In the case of libc_r, we still need three names, which are
now _thread_sys_foo() <-- _foo() <-- foo().

Convert all internal libc usage of: aio_suspend(), close(), fsync(), msync(),
nanosleep(), open(), fcntl(), read(), and write() to _foo() instead of foo().

Remove all internal libc usage of: creat(), pause(), sleep(), system(),
tcdrain(), wait(), and waitpid().

Make thread cancellation fully POSIX-compliant.

Suggested by: deischen


# 92927338 12-Jan-2000 Jason Evans <jasone@FreeBSD.org>

Add three-tier symbol naming in support of POSIX thread cancellation
points. For library functions, the pattern is __sleep() <--
_libc_sleep() <-- sleep(). The arrows represent weak aliases. For
system calls, the pattern is _read() <-- _libc_read() <-- read().


# e8420087 15-Sep-1998 Warner Losh <imp@FreeBSD.org>

Replace memory leaking instances of realloc with non-leaking reallocf.
In some cases replace if (a == null) a = malloc(x); else a =
realloc(a, x); with simple reallocf(a, x). Per ANSI-C, this is
guaranteed to be the same thing.

I've been running these on my system here w/o ill effects for some
time. However, the CTM-express is at part 6 of 34 for the CAM
changes, so I've not been able to do a build world with the CAM in the
tree with these changes. Shouldn't impact anything, but...


# 84d65005 08-Mar-1998 John Birrell <jb@FreeBSD.org>

Cast pointer to a long instead of an int to keep a 64-bit compiler
happy. The code works either way, but I like a clean compile.


# 03dcee8d 11-Mar-1997 Bruce Evans <bde@FreeBSD.org>

Fixed errors in the Lite2 merge. Some style changes were mismerged.
My changes to preserve errno across free() and close() and to report
fstat() errors properly were blown away.

Updated the FreeBSD changes to match the Lite2 style fixes.


# adf6ad9e 11-Mar-1997 Peter Wemm <peter@FreeBSD.org>

Merge from Lite2:
filesystem include updates, duplicate group suppression, cleanups,
filesystem whiteout support (unionfs), bidir popen().


# 662909a7 11-Mar-1997 Peter Wemm <peter@FreeBSD.org>

Import CSRG 4.4BSD-Lite2 lib/libc onto vendor branch


# d71458ee 02-May-1996 Poul-Henning Kamp <phk@FreeBSD.org>

Cache the result of getpagesize() so we only make one syscall.
Use getpagesize instead of CLBYTES.


# 0b50c8d6 28-Mar-1996 Bruce Evans <bde@FreeBSD.org>

stat() before open() because opening of special files may be harmful.


# 55e2b2c6 21-Apr-1995 Bruce Evans <bde@FreeBSD.org>

Fix bugs in opendir():
- it succeeded on non-directories (see POSIX 5.1.2.4).
- it hung on (non-open) named pipes.
- it leaked memory if the second malloc() failed.
- it didn't preserve errno across errors in close().


# 58f0484f 26-May-1994 Rodney W. Grimes <rgrimes@FreeBSD.org>

BSD 4.4 Lite Lib Sources