40#include <sys/select.h>
51 if (
files[i].inuse ==
false)
89 if (
files[fd].inuse == 0 ||
files[fd].inshdn == 1)
105 return (file -
files);
115ssize_t
FileIO::read(
struct _reent *reent,
int fd,
void *buf,
size_t count)
123 ssize_t result = f->
dev->
read(f, buf, count);
139ssize_t
FileIO::write(
struct _reent *reent,
int fd,
const void *buf,
size_t count)
147 ssize_t result = f->
dev->
write(f, buf, count);
163_off_t
FileIO::lseek(
struct _reent *reent,
int fd, _off_t offset,
int whence)
171 off_t result = f->
dev->
lseek(f, offset, whence);
194 ssize_t result = f->
dev->
fstat(f, stat);
217 int result = f->
dev->
ioctl(f, key, data);
249 data &= (O_APPEND | O_NONBLOCK);
250 file->
flags &= ~(O_APPEND | O_NONBLOCK);
261 int result = f->
dev->
fcntl(f, cmd, data);
290 return (off_t)-EINVAL;
331int _open_r(
struct _reent *reent,
const char *path,
int flags,
int mode)
334 if (result < 0 && errno == ENODEV)
360ssize_t
_read_r(
struct _reent *reent,
int fd,
void *buf,
size_t count)
372ssize_t
_write_r(
struct _reent *reent,
int fd,
const void *buf,
size_t count)
383int _stat_r(
struct _reent *reent,
const char *path,
struct stat *stat)
386 if (result < 0 && errno == ENOENT)
400int _fstat_r(
struct _reent *reent,
int fd,
struct stat *stat)
432_off_t
_lseek_r(
struct _reent *reent,
int fd, _off_t offset,
int whence)
452int ioctl(
int fd,
unsigned long int key, ...)
457 int result =
FileIO::ioctl(fd, key, va_arg(ap,
unsigned long));
473int select(
int nfds, fd_set *readfds, fd_set *writefds,
474 fd_set *exceptfds,
struct timeval *timeout)
476 long long time_value = -1;
478 time_value = timeout->tv_sec;
479 time_value *= 1000000;
480 time_value += timeout->tv_usec;
484 return Device::select(nfds, readfds, writefds, exceptfds, time_value);
499 int result =
FileIO::fcntl(fd, cmd, va_arg(ap,
unsigned long));
int _isatty_r(struct _reent *reent, int fd)
Get the tty information of a file or device.
_off_t _lseek_r(struct _reent *reent, int fd, _off_t offset, int whence)
Change the offset index of a file or device.
int _fstat_r(struct _reent *reent, int fd, struct stat *stat)
Get the status information of a file or device.
ssize_t _write_r(struct _reent *reent, int fd, const void *buf, size_t count)
Write to a file or device.
ssize_t _read_r(struct _reent *reent, int fd, void *buf, size_t count)
Read from a file or device.
int fsync(int fd)
Synchronize (flush) a file to disk.
int _close_r(struct _reent *reent, int fd)
Close a file or device.
int fcntl(int fd, int cmd,...)
Manipulate a file descriptor.
int ioctl(int fd, unsigned long int key,...)
Request and ioctl transaction.
int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout)
POSIX select().
int _stat_r(struct _reent *reent, const char *path, struct stat *stat)
Get the status information of a file or device.
int _unlink_r(struct _reent *reent, const char *path)
remove a file.
int _open_r(struct _reent *reent, const char *path, int flags, int mode)
Open a file or device.
static void fd_free(int fd)
Free up a file descriptor.
static File * file_lookup(int fd)
Looks up a reference to a File corresponding to a given file descriptor.
static int fstat(struct _reent *reent, int fd, struct stat *stat)
Get the status information of a file or device.
static int fcntl(int fd, int cmd, unsigned long data)
Manipulate a file descriptor.
static const unsigned int numOpenFiles
static ssize_t read(struct _reent *reent, int fd, void *buf, size_t count)
Read from a file or device.
static bool is_device(int fd)
Test if the file descriptor belongs to a device.
static _off_t lseek(struct _reent *reent, int fd, _off_t offset, int whence)
Change the offset index of a file or device.
static File files[]
File descriptor pool.
static ssize_t write(struct _reent *reent, int fd, const void *buf, size_t count)
Write to a file or device.
static int fd_lookup(File *file)
Looks up a file descriptor corresponding to a given File reference.
static int ioctl(int fd, unsigned long int key, unsigned long data)
Request and ioctl transaction.
static int fd_alloc(void)
Allocate a free file descriptor.
static OSMutex mutex
mutual exclusion for fileio
static int open(struct _reent *reent, const char *path, int flags, int mode)
Open a file or device.
static int fsync(int fd)
Synchronize (flush) a file to disk.
static int close(struct _reent *reent, int fd)
Close a file or device.
static int stat(struct _reent *reent, const char *path, struct stat *stat)
Get the status information of a file or device.
static int unlink(struct _reent *reent, const char *path)
Remove a file.
This class provides a mutex API.
#define HASSERT(x)
Checks that the value of expression x is true, else terminates the current process.
static int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, long long timeout)
POSIX select().
static void select_clear()
Clears the current thread's select bits.
static int stat(struct _reent *reent, const char *path, struct stat *stat)
Get the status information of a file or device.
static int close(struct _reent *reent, int fd)
Close a file or device.
static int open(struct _reent *reent, const char *path, int flags, int mode)
Open a file or device.
uint8_t dirty
true if this file is dirty and needs flush
uint8_t inshdn
true if this fd is in shutdown.
off_t offset
current offset within file
uint8_t dir
true if this is a directory, else false
void * priv
file reference specific data "pointer"
uint8_t device
true if this is a device, false if file system
FileIO * dev
file operations
uint8_t inuse
true if this is an open fd.