1*ff478f58Smartin /* $NetBSD: readdir.c,v 1.4 2012/12/27 20:21:51 martin Exp $ */
2ba7cbe76Scherry
3ba7cbe76Scherry /*-
4ba7cbe76Scherry * Copyright (c) 1999,2000 Jonathan Lemon <jlemon@freebsd.org>
5ba7cbe76Scherry * All rights reserved.
6ba7cbe76Scherry *
7ba7cbe76Scherry * Redistribution and use in source and binary forms, with or without
8ba7cbe76Scherry * modification, are permitted provided that the following conditions
9ba7cbe76Scherry * are met:
10ba7cbe76Scherry * 1. Redistributions of source code must retain the above copyright
11ba7cbe76Scherry * notice, this list of conditions and the following disclaimer.
12ba7cbe76Scherry * 2. Redistributions in binary form must reproduce the above copyright
13ba7cbe76Scherry * notice, this list of conditions and the following disclaimer in the
14ba7cbe76Scherry * documentation and/or other materials provided with the distribution.
15ba7cbe76Scherry *
16ba7cbe76Scherry * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17ba7cbe76Scherry * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18ba7cbe76Scherry * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19ba7cbe76Scherry * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20ba7cbe76Scherry * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21ba7cbe76Scherry * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22ba7cbe76Scherry * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23ba7cbe76Scherry * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24ba7cbe76Scherry * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25ba7cbe76Scherry * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26ba7cbe76Scherry * SUCH DAMAGE.
27ba7cbe76Scherry */
28ba7cbe76Scherry
29ba7cbe76Scherry #include <sys/cdefs.h>
30ba7cbe76Scherry
31ba7cbe76Scherry
32ba7cbe76Scherry #include <lib/libsa/stand.h>
3393b81f4cSkiyohara #include <lib/libsa/loadfile.h>
34ba7cbe76Scherry
35ba7cbe76Scherry #include <sys/param.h>
36ba7cbe76Scherry #include <sys/dirent.h>
37ba7cbe76Scherry
38*ff478f58Smartin #include <efi/libefi/efifsdev.h>
39ba7cbe76Scherry #include <bootstrap.h>
40ba7cbe76Scherry
41*ff478f58Smartin int skifs_readdir(struct open_file *f, struct dirent *d);
42*ff478f58Smartin
43ba7cbe76Scherry struct dirent *
readdirfd(int fd)44ba7cbe76Scherry readdirfd(int fd)
45ba7cbe76Scherry {
462d00b8d1Scherry static struct dirent dir; /* XXX not thread safe. eh ??? */
47ba7cbe76Scherry struct open_file *f = &files[fd];
48ba7cbe76Scherry
4993b81f4cSkiyohara if ((unsigned)fd >= SOPEN_MAX) {
50ba7cbe76Scherry errno = EBADF;
51ba7cbe76Scherry return (NULL);
52ba7cbe76Scherry }
53ba7cbe76Scherry if (f->f_flags & F_RAW) {
54ba7cbe76Scherry errno = EIO;
55ba7cbe76Scherry return (NULL);
56ba7cbe76Scherry }
57ba7cbe76Scherry
58ba7cbe76Scherry /* XXXwill be f->f_ops->fo_readdir)(f, &dir); when/if we fix stand.h */
59ba7cbe76Scherry errno = FS_READDIR(f, &dir);
60ba7cbe76Scherry
61ba7cbe76Scherry if (errno)
62ba7cbe76Scherry return (NULL);
63ba7cbe76Scherry return (&dir);
64ba7cbe76Scherry }
65