nio.h

Go to the documentation of this file.
00001 /*              $Id: $          */
00002 
00003 /*
00004  * Copyright (c) 2007 Mark Heily <devel@heily.com>
00005  *
00006  * Permission to use, copy, modify, and distribute this software for any
00007  * purpose with or without fee is hereby granted, provided that the above
00008  * copyright notice and this permission notice appear in all copies.
00009  *
00010  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
00011  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
00012  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
00013  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
00014  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
00015  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
00016  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
00017  */
00018 
00019 #ifndef _NIO_H
00020 #define _NIO_H
00021 
00022 #include <sys/ipc.h>
00023 #include <sys/shm.h>
00024 #include <sys/types.h>
00025 #include <sys/stat.h>
00026 #include <dirent.h>
00027 #include <fcntl.h>
00028 
00035 /* Constants that correspond with syscalls or libc functions */
00036 enum nio_op {
00037         NIO_INVALID = 0,
00038 
00039         /* Disk I/O */
00040         NIO_OPEN,
00041         NIO_CLOSE,
00042         NIO_READ,
00043         NIO_WRITE,
00044         NIO_LSEEK,
00045         NIO_OPENDIR,
00046         NIO_CLOSEDIR,
00047         NIO_REWINDDIR,
00048         NIO_READDIR,
00049         NIO_TELLDIR,
00050         NIO_LINK,
00051         NIO_SYMLINK,
00052         NIO_UNLINK,
00053         NIO_RENAME,
00054         NIO_FCNTL,
00055         NIO_STAT,
00056         NIO_FSTAT,
00057         NIO_LSTAT,
00058         NIO_FDATASYNC,
00059         NIO_FSYNC,
00060         NIO_TRUNCATE,
00061         NIO_FTRUNCATE,
00062 
00063         /* Network I/O */
00064         NIO_GETADDRINFO,
00065         NIO_GETNAMEINFO,
00066 };
00067 
00068 // TODO: split into nio_req and nio_res; have nio_req STAILQ to enqueue requests
00069 //
00070 
00072 struct niocb {
00073 
00074         /* The 'request' data fields filled in by the caller */
00075 
00076         enum nio_op req_op;             
00077         int         req_fd;             
00078         off_t       req_offset;         
00079         size_t      req_len;            
00080         mode_t      req_mode;           
00081         char       *req_path;           
00082         int         req_flags;          
00084         /* The 'response' data fields filled in after the syscall completes */
00085 
00086         union {
00087                 struct stat    st;      
00088                 struct dirent  ent;     
00089                 int            fd;      
00090                 size_t         len;     
00091                 DIR           *dirh;    
00092                 off_t          offset;  
00093         } res_data;
00094         int         res_errno;          
00095         int         res_retval;         
00096         int         res_shmid;          
00097 };
00098 
00099 
00100 /* Replacement for POSIX I/O system calls */
00101 
00102 int nio_open(struct niocb *cb, const char *path, int flags, mode_t mode);
00103 int nio_close(struct niocb *cb, int fd);
00104 int nio_read(struct niocb *cb, int fd, size_t count);
00105 int nio_write(struct niocb *cb, int fd, const void *buf, size_t count);
00106 int nio_lseek(struct niocb *cb, int fd, off_t offset, int whence);
00107 
00108 /* opendir(2) related */
00109 
00110 int nio_opendir(struct niocb *cb, const char *name);
00111 int nio_closedir(struct niocb *cb, DIR *dir);
00112 int nio_rewinddir(struct niocb *cb, DIR *dir);
00113 int nio_readdir(struct niocb *cb, DIR *dir);
00114 int nio_telldir(struct niocb *cb, DIR *dir);
00115 
00116 /* link(2) related */
00117 
00118 int nio_link(struct niocb *cb, const char *oldpath, const char *newpath);
00119 int nio_symlink(struct niocb *cb, const char *oldpath, const char *newpath);
00120 int nio_unlink(struct niocb *cb, const char *path);
00121 int nio_rename(struct niocb *cb, const char *oldpath, const char *newpath);
00122 
00123 /* fnctl(2) file locking */
00124 
00125 int nio_fcntl(struct niocb *cb, int fd, int op, const struct flock *fl);
00126 
00127 /* stat(2) related */
00128 
00129 int nio_stat(struct niocb *cb, const char *path);
00130 int nio_fstat(struct niocb *cb, int fd);
00131 int nio_lstat(struct niocb *cb, const char *path);
00132 
00133 /* sync(2) related */
00134 
00135 int nio_fdatasync(struct niocb *cb, int fd);
00136 int nio_fsync(struct niocb *cb, int fd);
00137 
00138 /* truncate(2) related */
00139 
00140 int nio_truncate(struct niocb *cb, const char *path, off_t length);
00141 int nio_ftruncate(struct niocb *cb, int fd, off_t length);
00142 
00143 /* network I/O */
00144 
00145 int nio_getaddrinfo(struct niocb *cb, 
00146                 const char *node,
00147                 const char *service,
00148                 const struct addrinfo *hints,
00149                 struct addrinfo **res);
00150 
00151 int nio_getnameinfo(struct niocb *cb,
00152                 const struct sockaddr *sa, 
00153                 socklen_t salen,
00154                 char *host,
00155                 size_t hostlen,
00156                 char *serv,
00157                 size_t servlen,
00158                 int flags);
00159 
00160 #endif

Generated on Wed Aug 22 23:15:42 2007 for pnotify by  doxygen 1.5.1