--- libeio/eio.h 2008/06/17 23:58:48 1.15 +++ libeio/eio.h 2009/06/06 17:25:13 1.19 @@ -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,7 +60,56 @@ # 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_DIR = 4, + EIO_DT_BLK = 6, + EIO_DT_REG = 8, + EIO_DT_LNK = 10, + EIO_DT_SOCK = 12, + EIO_DT_WHT = 14, + EIO_DT_MAX = 15 /* highest DT_VALUE ever, hopefully */ +}; + +struct eio_dirent { + char *name; + ino_t inode; + unsigned short namelen; + unsigned char type; + unsigned char score; /* internal use */ + /* 0-4 bytes padding */ +}; + +/* 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, EIO_READ, EIO_WRITE, EIO_READAHEAD, EIO_SENDFILE, @@ -69,32 +119,32 @@ EIO_CHMOD, EIO_FCHMOD, EIO_CHOWN, EIO_FCHOWN, EIO_SYNC, EIO_FSYNC, EIO_FDATASYNC, + EIO_MSYNC, EIO_MTOUCH, EIO_SYNC_FILE_RANGE, EIO_UNLINK, EIO_RMDIR, EIO_MKDIR, EIO_RENAME, EIO_MKNOD, EIO_READDIR, EIO_LINK, EIO_SYMLINK, EIO_READLINK, EIO_GROUP, EIO_NOP, - EIO_BUSY, EIO_CUSTOM + EIO_BUSY }; -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 */ ssize_t result; /* result of syscall, e.g. result = read (... */ - off_t offs; /* read, write, truncate, readahead: file offset */ - size_t size; /* read, write, readahead, sendfile: length */ + 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 */ 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: flags */ - long int2; /* chown, fchown: uid; sendfile: input fd; open, chmod, mkdir, mknod: file mode */ + 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 */ @@ -111,10 +161,12 @@ eio_req *grp, *grp_prev, *grp_next, *grp_first; /* private */ }; +/* _private_ flags */ enum { EIO_FLAG_CANCELLED = 0x01, /* request was cancelled */ EIO_FLAG_PTR1_FREE = 0x02, /* need to free(ptr1) */ - EIO_FLAG_PTR2_FREE = 0x04 /* need to free(ptr2) */ + EIO_FLAG_PTR2_FREE = 0x04, /* need to free(ptr2) */ + EIO_FLAG_GROUPADD = 0x08 /* some request was added to the group */ }; enum { @@ -160,6 +212,9 @@ eio_req *eio_sync (int pri, eio_cb cb, void *data); eio_req *eio_fsync (int fd, int pri, eio_cb cb, void *data); eio_req *eio_fdatasync (int fd, int pri, eio_cb cb, void *data); +eio_req *eio_msync (void *addr, size_t length, int flags, int pri, eio_cb cb, void *data); +eio_req *eio_mtouch (void *addr, size_t length, int flags, int pri, eio_cb cb, void *data); +eio_req *eio_sync_file_range (int fd, off_t offset, size_t nbytes, unsigned int flags, int pri, eio_cb cb, void *data); eio_req *eio_close (int fd, int pri, eio_cb cb, void *data); eio_req *eio_readahead (int fd, off_t offset, size_t length, int pri, eio_cb cb, void *data); eio_req *eio_read (int fd, void *buf, size_t length, off_t offset, int pri, eio_cb cb, void *data); @@ -177,7 +232,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 */