--- libeio/eio.h 2008/10/22 18:15:36 1.18 +++ libeio/eio.h 2009/06/15 05:34:49 1.24 @@ -1,7 +1,7 @@ /* * libeio API header * - * Copyright (c) 2007,2008 Marc Alexander Lehmann + * Copyright (c) 2007,2008,2009 Marc Alexander Lehmann * All rights reserved. * * Redistribution and use in source and binary forms, with or without modifica- @@ -47,7 +47,8 @@ #include #include -typedef struct eio_req eio_req; +typedef struct eio_req eio_req; +typedef struct eio_dirent eio_dirent; typedef int (*eio_cb)(eio_req *req); @@ -59,6 +60,60 @@ # define EIO_STRUCT_STAT struct stat #endif +/* for readdir */ + +/* eio_readdir flags */ +enum { + EIO_READDIR_DENTS = 0x01, /* ptr2 contains eio_dirents, not just the (unsorted) names */ + EIO_READDIR_DIRS_FIRST = 0x02, /* dirents gets sorted into a good stat() ing order to find directories first */ + EIO_READDIR_STAT_ORDER = 0x04, /* dirents gets sorted into a good stat() ing order to quickly stat all files */ + EIO_READDIR_FOUND_UNKNOWN = 0x80, /* set by eio_readdir when *_ARRAY was set and any TYPE=UNKNOWN's were found */ + + EIO_READDIR_CUSTOM1 = 0x100, /* for use by apps */ + EIO_READDIR_CUSTOM2 = 0x200 /* for use by apps */ +}; + +/* using "typical" values in the hope that the compiler will do something sensible */ +enum eio_dtype { + EIO_DT_UNKNOWN = 0, + EIO_DT_FIFO = 1, + EIO_DT_CHR = 2, + EIO_DT_MPC = 3, /* multiplexed char device (v7+coherent) */ + EIO_DT_DIR = 4, + EIO_DT_NAM = 5, /* xenix special named file */ + EIO_DT_BLK = 6, + EIO_DT_MPB = 7, /* multiplexed block device (v7+coherent) */ + EIO_DT_REG = 8, + EIO_DT_NWK = 9, /* HP-UX network special */ + EIO_DT_CMP = 9, /* VxFS compressed */ + EIO_DT_LNK = 10, + /* DT_SHAD = 11,*/ + EIO_DT_SOCK = 12, + EIO_DT_DOOR = 13, /* solaris door */ + EIO_DT_WHT = 14, + EIO_DT_MAX = 15 /* highest DT_VALUE ever, hopefully */ +}; + +struct eio_dirent { + int nameofs; /* offset of null-terminated name string in (char *)req->ptr2 */ + unsigned short namelen; /* size of filename without trailing 0 */ + unsigned char type; /* one of EIO_DT_* */ + signed char score; /* internal use */ + ino_t inode; /* the inode number, if available, otherwise unspecified */ +}; + +/* eio_sync_file_range flags */ + +enum { + EIO_SYNC_FILE_RANGE_WAIT_BEFORE = 1, + EIO_SYNC_FILE_RANGE_WRITE = 2, + EIO_SYNC_FILE_RANGE_WAIT_AFTER = 4 +}; + +typedef double eio_tstamp; /* feel free to use double in your code directly */ + +/* the eio request structure */ + enum { EIO_CUSTOM, EIO_OPEN, EIO_CLOSE, EIO_DUP2, @@ -78,18 +133,9 @@ EIO_BUSY }; -/* eio_sync_file_range flags */ - -enum { - EIO_SYNC_FILE_RANGE_WAIT_BEFORE = 1, - EIO_SYNC_FILE_RANGE_WRITE = 2, - EIO_SYNC_FILE_RANGE_WAIT_AFTER = 4 -}; - -typedef double eio_tstamp; /* feel free to use double in your code directly */ - /* eio request structure */ /* this structure is mostly read-only */ +/* when initialising it, all members must be zero-initialised */ struct eio_req { eio_req volatile *next; /* private ETP */ @@ -97,13 +143,13 @@ ssize_t result; /* result of syscall, e.g. result = read (... */ off_t offs; /* read, write, truncate, readahead, sync_file_range: file offset */ size_t size; /* read, write, readahead, sendfile, msync, sync_file_range: length */ - void *ptr1; /* all applicable requests: pathname, old name */ - void *ptr2; /* all applicable requests: new name or memory buffer */ + void *ptr1; /* all applicable requests: pathname, old name; readdir: optional eio_dirents */ + void *ptr2; /* all applicable requests: new name or memory buffer; readdir: name strings */ eio_tstamp nv1; /* utime, futime: atime; busy: sleep time */ eio_tstamp nv2; /* utime, futime: mtime */ int type; /* EIO_xxx constant ETP */ - int int1; /* all applicable requests: file descriptor; sendfile: output fd; open, msync: flags */ + int int1; /* all applicable requests: file descriptor; sendfile: output fd; open, msync, readdir: flags */ long int2; /* chown, fchown: uid; sendfile: input fd; open, chmod, mkdir, mknod: file mode, sync_file_range: flags */ long int3; /* chown, fchown: gid; mknod: dev_t */ int errorno; /* errno value on syscall return */ @@ -192,7 +238,7 @@ eio_req *eio_chown (const char *path, uid_t uid, gid_t gid, int pri, eio_cb cb, void *data); eio_req *eio_chmod (const char *path, mode_t mode, int pri, eio_cb cb, void *data); eio_req *eio_mkdir (const char *path, mode_t mode, int pri, eio_cb cb, void *data); -eio_req *eio_readdir (const char *path, int pri, eio_cb cb, void *data); /* result=ptr2 allocated dynamically */ +eio_req *eio_readdir (const char *path, int flags, int pri, eio_cb cb, void *data); /* result=ptr2 allocated dynamically */ eio_req *eio_rmdir (const char *path, int pri, eio_cb cb, void *data); eio_req *eio_unlink (const char *path, int pri, eio_cb cb, void *data); eio_req *eio_readlink (const char *path, int pri, eio_cb cb, void *data); /* result=ptr2 allocated dynamically */