23#define NEWLIB_PORT_AWARE
35#ifdef F___fioOpsInitialize
40extern void __fioOpsInitializeImpl(
void);
43static void __fioOpsInitialize(
void)
45 __fioOpsInitializeImpl();
53#ifdef F___fioOpenHelper
54#define IOP_O_RDONLY 0x0001
55#define IOP_O_WRONLY 0x0002
56#define IOP_O_RDWR 0x0003
57#define IOP_O_DIROPEN 0x0008
58#define IOP_O_NBLOCK 0x0010
59#define IOP_O_APPEND 0x0100
60#define IOP_O_CREAT 0x0200
61#define IOP_O_TRUNC 0x0400
62#define IOP_O_EXCL 0x0800
63#define IOP_O_NOWAIT 0x8000
72 if ((flags & 3) == O_RDONLY) iop_flags |= IOP_O_RDONLY;
73 if ((flags & 3) == O_WRONLY) iop_flags |= IOP_O_WRONLY;
74 if ((flags & 3) == O_RDWR ) iop_flags |= IOP_O_RDWR;
75 if (flags & O_NONBLOCK) iop_flags |= IOP_O_NBLOCK;
76 if (flags & O_APPEND) iop_flags |= IOP_O_APPEND;
77 if (flags & O_CREAT) iop_flags |= IOP_O_CREAT;
78 if (flags & O_TRUNC) iop_flags |= IOP_O_TRUNC;
79 if (flags & O_EXCL) iop_flags |= IOP_O_EXCL;
81 if (flags & O_DIRECTORY) {
82 iop_flags |= IOP_O_DIROPEN;
86 iop_fd = is_dir ? fioDopen(buf) : fioOpen(buf, iop_flags);
91 buf_len = strlen(buf);
97 userdata->fd = iop_fd;
98 memcpy(userdata->filename, buf, buf_len);
99 userdata->filename[buf_len] =
'\x00';
100 info->userdata = (
void *)userdata;
101 info->ops = is_dir ? &__fio_fdman_ops_dir : &__fio_fdman_ops_file;
110#ifdef F___fioGetFdHelper
111int __fioGetFdHelper(
void *userdata)
115 if (userdata == NULL)
124int __fioGetFdHelper(
void *userdata);
127#ifdef F___fioGetFilenameHelper
128char *__fioGetFilenameHelper(
void *userdata)
132 if (userdata == NULL)
138 return finfo->filename;
141char *__fioGetFilenameHelper(
void *userdata);
144#ifdef F___fioCloseHelper
145int __fioCloseHelper(
void *userdata)
150 fd = __fioGetFdHelper(userdata);
161int __fioCloseHelper(
void *userdata);
164#ifdef F___fioDcloseHelper
165int __fioDcloseHelper(
void *userdata)
170 fd = __fioGetFdHelper(userdata);
181int __fioDcloseHelper(
void *userdata);
184#ifdef F___fioReadHelper
185int __fioReadHelper(
void *userdata,
void *buf,
int nbytes)
190 fd = __fioGetFdHelper(userdata);
196 rv = fioRead(fd, buf, nbytes);
200int __fioReadHelper(
void *userdata,
void *buf,
int nbytes);
203#ifdef F___fioLseekHelper
204int __fioLseekHelper(
void *userdata,
int offset,
int whence)
209 fd = __fioGetFdHelper(userdata);
215 rv = fioLseek(fd, offset, whence);
219int __fioLseekHelper(
void *userdata,
int offset,
int whence);
222#ifdef F___fioWriteHelper
223int __fioWriteHelper(
void *userdata,
const void *buf,
int nbytes)
228 fd = __fioGetFdHelper(userdata);
234 rv = fioWrite(fd, buf, nbytes);
238int __fioWriteHelper(
void *userdata,
const void *buf,
int nbytes);
241#ifdef F___fioIoctlHelper
242int __fioIoctlHelper(
void *userdata,
int request,
void *data)
247 fd = __fioGetFdHelper(userdata);
253 rv = fioIoctl(fd,
request, data);
257int __fioIoctlHelper(
void *userdata,
int request,
void *data);
260#ifdef F___fioDreadHelper
261int __fioDreadHelper(
void *userdata,
struct dirent *dir)
268 #define __MAXNAMLEN 256
270 fd = __fioGetFdHelper(userdata);
276 rv = fioDread(fd, &iodir);
283 strncpy(dir->d_name, iodir.name, __MAXNAMLEN);
284 dir->d_name[__MAXNAMLEN - 1] = 0;
290 default: dir->d_type = DT_UNKNOWN;
break;
297int __fioDreadHelper(
void *userdata,
struct dirent *dir);
300#ifdef F___fioLseekDirHelper
301int __fioLseekDirHelper(
void *userdata,
int offset,
int whence)
310 fd = __fioGetFdHelper(userdata);
316 filename = __fioGetFilenameHelper(userdata);
318 if (filename == NULL)
323 if (userdata == NULL)
330 if (whence != SEEK_SET)
336 uid = fioDopen(filename);
338 for (i = 0; i < offset; i++) {
339 __fioDreadHelper(userdata, &dir);
345int __fioLseekDirHelper(
void *userdata,
int offset,
int whence);
348#ifdef F___libcglue_init_stdio
353 const char *tty0_str =
"tty0:";
355 fnlen = strlen(tty0_str) + 1;
358 if (userdata == NULL)
363 memcpy(userdata->filename, tty0_str, fnlen - 1);
364 userdata->filename[fnlen - 1] =
'\x00';
365 info->userdata = (
void *)userdata;
366 info->ops = &__fio_fdman_ops_file;
372#ifdef F___fioMkdirHelper
378 return fioMkdir(path);
384#ifdef F___fioGetstatHelper
385static time_t io_to_posix_time(
const unsigned char *ps2time)
388 tim.tm_sec = ps2time[1];
389 tim.tm_min = ps2time[2];
390 tim.tm_hour = ps2time[3];
391 tim.tm_mday = ps2time[4];
392 tim.tm_mon = ps2time[5] - 1;
393 tim.tm_year = ((u16)ps2time[6] | ((u16)ps2time[7] << 8)) - 1900;
397static mode_t io_to_posix_mode(
unsigned int ps2mode)
399 mode_t posixmode = 0;
402 if (ps2mode &
FIO_SO_IROTH) posixmode |= S_IRUSR|S_IRGRP|S_IROTH;
403 if (ps2mode &
FIO_SO_IWOTH) posixmode |= S_IWUSR|S_IWGRP|S_IWOTH;
404 if (ps2mode &
FIO_SO_IXOTH) posixmode |= S_IXUSR|S_IXGRP|S_IXOTH;
408static void __fill_stat(
struct stat *stat,
const io_stat_t *fiostat)
412 stat->st_mode = io_to_posix_mode(fiostat->mode);
417 stat->st_size = ((off_t)fiostat->hisize << 32) | (off_t)fiostat->size;
418 stat->st_atime = io_to_posix_time(fiostat->atime);
419 stat->st_mtime = io_to_posix_time(fiostat->mtime);
420 stat->st_ctime = io_to_posix_time(fiostat->ctime);
421 stat->st_blksize = 16*1024;
422 stat->st_blocks = stat->st_size / 512;
425int __fioGetstatHelper(
const char *path,
struct stat *buf)
429 if (strncmp(path,
"tty", 3) == 0 && path[3] >=
'0' && path[3] <=
'9' && path[4] ==
':')
431 memset(buf, 0,
sizeof(
struct stat));
432 buf->st_mode = S_IFCHR;
436 if (fioGetstat(path, &fiostat) < 0) {
441 __fill_stat(buf, &fiostat);
446int __fioGetstatHelper(
const char *path,
struct stat *buf);
449#ifdef F___fioOpsInitializeImpl
450int __attribute__((weak)) _open(
const char *buf,
int flags, ...);
452int __attribute__((weak)) mkdir(
const char *path, mode_t mode);
454int __attribute__((weak)) _stat(
const char *path,
struct stat *buf);
457int __attribute__((weak)) _read(
int fd,
void *buf,
size_t nbytes);
458off_t
__attribute__((weak)) _lseek(
int fd, off_t offset,
int whence);
459int __attribute__((weak)) _write(
int fd,
const void *buf,
size_t nbytes);
463void __fioOpsInitializeImpl(
void)
465 memset(&__fio_fdman_path_ops, 0,
sizeof(__fio_fdman_path_ops));
467 if (&_open) __fio_fdman_path_ops.open = __fioOpenHelper;
469 if (&_unlink) __fio_fdman_path_ops.remove = fioRemove;
473 if (&rmdir) __fio_fdman_path_ops.rmdir = fioRmdir;
475 if ((&_stat) || (&_fstat)) __fio_fdman_path_ops.stat = __fioGetstatHelper;
477 memset(&__fio_fdman_ops_file, 0,
sizeof(__fio_fdman_ops_file));
478 __fio_fdman_ops_file.getfd = __fioGetFdHelper;
479 __fio_fdman_ops_file.getfilename = __fioGetFilenameHelper;
481 if (&_close) __fio_fdman_ops_file.close = __fioCloseHelper;
483 if (&_read) __fio_fdman_ops_file.read = __fioReadHelper;
485 if (&_lseek) __fio_fdman_ops_file.lseek = __fioLseekHelper;
487 if (&_write) __fio_fdman_ops_file.write = __fioWriteHelper;
489 if (&_ioctl) __fio_fdman_ops_file.ioctl = __fioIoctlHelper;
491 memset(&__fio_fdman_ops_dir, 0,
sizeof(__fio_fdman_ops_dir));
492 __fio_fdman_ops_dir.getfd = __fioGetFdHelper;
493 __fio_fdman_ops_dir.getfilename = __fioGetFilenameHelper;
495 if (&_close) __fio_fdman_ops_dir.close = __fioDcloseHelper;
497 if (&_lseek) __fio_fdman_ops_dir.lseek = __fioLseekDirHelper;
499 if (&getdents) __fio_fdman_ops_dir.dread = __fioDreadHelper;
503#ifdef F__libcglue_fdman_path_ops
507#ifdef F__libcglue_fdman_socket_ops
511#ifdef F__libcglue_fdman_inet_ops
int __fioMkdirHelper(const char *path, int mode)
u32 count
start sector of fragmented bd/file