rpm 5.2.1

rpmio/rpmio.h

Go to the documentation of this file.
00001 #ifndef H_RPMIO
00002 #define H_RPMIO
00003 
00009 #include <sys/types.h>
00010 #include <sys/stat.h>
00011 #include <dirent.h>
00012 #include <stdio.h>
00013 #include <stdlib.h>
00014 #include <unistd.h>
00015 
00016 #include <rpmiotypes.h>
00017 #include <rpmzlog.h>
00018 
00026 #if !defined(__LCLINT__) && !defined(__UCLIBC__) && defined(__GLIBC__) && \
00027         (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2))
00028 #define USE_COOKIE_SEEK_POINTER 1
00029 typedef _IO_off64_t     _libio_off_t;
00030 typedef _libio_off_t *  _libio_pos_t;
00031 #else
00032 typedef off_t           _libio_off_t;
00033 typedef off_t           _libio_pos_t;
00034 #endif
00035 
00039 typedef /*@abstract@*/ /*@refcounted@*/ struct _FD_s * FD_t;
00040 
00043 typedef /*@observer@*/ struct FDIO_s * FDIO_t;
00044 
00045 #ifdef __cplusplus
00046 extern "C" {
00047 #endif
00048 
00053 
00056 typedef ssize_t (*fdio_read_function_t) (void *cookie, char *buf, size_t nbytes)
00057         /*@globals errno, fileSystem @*/
00058         /*@modifies *cookie, errno, fileSystem @*/
00059         /*@requires maxSet(buf) >= (nbytes - 1) @*/
00060         /*@ensures maxRead(buf) == result @*/ ;
00061 
00064 typedef ssize_t (*fdio_write_function_t) (void *cookie, const char *buf, size_t nbytes)
00065         /*@globals errno, fileSystem @*/
00066         /*@modifies *cookie, errno, fileSystem @*/;
00067 
00070 typedef int (*fdio_seek_function_t) (void *cookie, _libio_pos_t pos, int whence)
00071         /*@globals errno, fileSystem @*/
00072         /*@modifies *cookie, errno, fileSystem @*/;
00073 
00076 typedef int (*fdio_close_function_t) (void *cookie)
00077         /*@globals errno, fileSystem, systemState @*/
00078         /*@modifies *cookie, errno, fileSystem, systemState @*/;
00079 
00082 typedef FD_t (*fdio_fopen_function_t) (const char * path, const char * fmode)
00083         /*@globals errno, fileSystem @*/
00084         /*@modifies errno, fileSystem @*/;
00085 
00088 typedef FD_t (*fdio_fdopen_function_t) (void * cookie, const char * fmode)
00089         /*@globals errno, fileSystem @*/
00090         /*@modifies errno, fileSystem @*/;
00091 
00094 typedef int (*fdio_flush_function_t) (void * cookie)
00095         /*@globals errno, fileSystem @*/
00096         /*@modifies errno, fileSystem @*/;
00097 
00103 struct FDIO_s {
00104   fdio_read_function_t          read;
00105   fdio_write_function_t         write;
00106   fdio_seek_function_t          seek;
00107   fdio_close_function_t         close;
00108 /*@null@*/
00109   fdio_fopen_function_t         _fopen;
00110 /*@null@*/
00111   fdio_fdopen_function_t        _fdopen;
00112 /*@null@*/
00113   fdio_flush_function_t         _flush;
00114 };
00115 
00116 
00121 
00125 /*@observer@*/ const char * Fstrerror(/*@null@*/ FD_t fd)
00126         /*@*/;
00127 
00131 /*@-incondefs@*/
00132 size_t Fread(/*@out@*/ void * buf, size_t size, size_t nmemb, FD_t fd)
00133         /*@globals fileSystem @*/
00134         /*@modifies fd, *buf, fileSystem @*/
00135         /*@requires maxSet(buf) >= (nmemb - 1) @*/;
00136 /*@=incondefs@*/
00137 
00141 /*@-incondefs@*/
00142 size_t Fwrite(const void * buf, size_t size, size_t nmemb, FD_t fd)
00143         /*@globals fileSystem @*/
00144         /*@modifies fd, fileSystem @*/
00145         /*@requires maxRead(buf) >= nmemb @*/;
00146 /*@=incondefs@*/
00147 
00151 int Fseek(FD_t fd, _libio_off_t offset, int whence)
00152         /*@globals fileSystem @*/
00153         /*@modifies fileSystem @*/;
00154 
00158 int Fclose( /*@killref@*/ FD_t fd)
00159         /*@globals fileSystem, internalState @*/
00160         /*@modifies fd, fileSystem, internalState @*/;
00161 
00164 /*@null@*/ FD_t Fdopen(FD_t ofd, const char * fmode)
00165         /*@globals fileSystem, internalState @*/
00166         /*@modifies ofd, fileSystem, internalState @*/;
00167 
00171 /*@null@*/ FD_t Fopen(/*@null@*/ const char * path,
00172                         /*@null@*/ const char * fmode)
00173         /*@globals h_errno, fileSystem, internalState @*/
00174         /*@modifies fileSystem, internalState @*/;
00175 
00176 
00180 int Fflush(/*@null@*/ FD_t fd)
00181         /*@globals fileSystem @*/
00182         /*@modifies fd, fileSystem @*/;
00183 
00187 int Ferror(/*@null@*/ FD_t fd)
00188         /*@*/;
00189 
00193 int Fileno(FD_t fd)
00194         /*@globals fileSystem @*/
00195         /*@modifies fileSystem@*/;
00196 
00200 /*@unused@*/
00201 int Fcntl(FD_t fd, int op, void *lip)
00202         /*@globals errno, fileSystem @*/
00203         /*@modifies fd, *lip, errno, fileSystem @*/;
00204 
00211 
00215 int Mkdir(const char * path, mode_t mode)
00216         /*@globals errno, h_errno, fileSystem, internalState @*/
00217         /*@modifies errno, fileSystem, internalState @*/;
00218 
00222 int Chdir(const char * path)
00223         /*@globals errno, h_errno, fileSystem, internalState @*/
00224         /*@modifies errno, fileSystem, internalState @*/;
00225 
00229 int Rmdir(const char * path)
00230         /*@globals errno, h_errno, fileSystem, internalState @*/
00231         /*@modifies errno, fileSystem, internalState @*/;
00232 
00233 /*@unchecked@*/ /*@observer@*/ /*@null@*/
00234 extern const char * _chroot_prefix;
00235 
00240 int Chroot(const char * path)
00241         /*@globals _chroot_prefix, errno, fileSystem, internalState @*/
00242         /*@modifies _chroot_prefix, errno, fileSystem, internalState @*/;
00243 
00248 int Open(const char * path, int flags, mode_t mode)
00249         /*@globals errno, fileSystem, internalState @*/
00250         /*@modifies errno, fileSystem, internalState @*/;
00251 
00255 int Rename(const char * oldpath, const char * newpath)
00256         /*@globals errno, h_errno, fileSystem, internalState @*/
00257         /*@modifies errno, fileSystem, internalState @*/;
00258 
00262 int Link(const char * oldpath, const char * newpath)
00263         /*@globals errno, fileSystem, internalState @*/
00264         /*@modifies errno, fileSystem, internalState @*/;
00265 
00269 int Unlink(const char * path)
00270         /*@globals errno, h_errno, fileSystem, internalState @*/
00271         /*@modifies errno, fileSystem, internalState @*/;
00272 
00276 int Stat(const char * path, /*@out@*/ struct stat * st)
00277         /*@globals errno, h_errno, fileSystem, internalState @*/
00278         /*@modifies *st, errno, fileSystem, internalState @*/;
00279 
00283 int Lstat(const char * path, /*@out@*/ struct stat * st)
00284         /*@globals errno, h_errno, fileSystem, internalState @*/
00285         /*@modifies *st, errno, fileSystem, internalState @*/;
00286 
00290 int Fstat(FD_t fd, /*@out@*/ struct stat * st)
00291         /*@globals errno, fileSystem, internalState @*/
00292         /*@modifies *st, errno, fileSystem, internalState @*/;
00293 
00298 int Chown(const char * path, uid_t owner, gid_t group)
00299         /*@globals errno, fileSystem, internalState @*/
00300         /*@modifies errno, fileSystem, internalState @*/;
00301 
00306 int Fchown(FD_t fd, uid_t owner, gid_t group)
00307         /*@globals errno, fileSystem, internalState @*/
00308         /*@modifies errno, fileSystem, internalState @*/;
00309 
00314 int Lchown(const char * path, uid_t owner, gid_t group)
00315         /*@globals errno, fileSystem, internalState @*/
00316         /*@modifies errno, fileSystem, internalState @*/;
00317 
00322 int Chmod(const char * path, mode_t mode)
00323         /*@globals errno, fileSystem, internalState @*/
00324         /*@modifies errno, fileSystem, internalState @*/;
00325 
00330 int Fchmod(FD_t fd, mode_t mode)
00331         /*@globals errno, fileSystem, internalState @*/
00332         /*@modifies errno, fileSystem, internalState @*/;
00333 
00338 int Mkfifo(const char * path, mode_t mode)
00339         /*@globals errno, fileSystem, internalState @*/
00340         /*@modifies errno, fileSystem, internalState @*/;
00341 
00346 int Mknod(const char * path, mode_t mode, dev_t dev)
00347         /*@globals errno, fileSystem, internalState @*/
00348         /*@modifies errno, fileSystem, internalState @*/;
00349 
00354 struct utimbuf;
00355 int Utime(const char * path, const struct utimbuf * buf)
00356         /*@globals errno, fileSystem, internalState @*/
00357         /*@modifies errno, fileSystem, internalState @*/;
00358 
00363 int Utimes(const char * path, const struct timeval * times)
00364         /*@globals errno, fileSystem, internalState @*/
00365         /*@modifies errno, fileSystem, internalState @*/;
00366 
00371 int Symlink(const char * oldpath, const char * newpath)
00372         /*@globals errno, fileSystem, internalState @*/
00373         /*@modifies errno, fileSystem, internalState @*/;
00374 
00379 /*@-incondefs@*/
00380 int Readlink(const char * path, /*@out@*/ char * buf, size_t bufsiz)
00381         /*@globals errno, h_errno, fileSystem, internalState @*/
00382         /*@modifies *buf, errno, fileSystem, internalState @*/;
00383 /*@=incondefs@*/
00384 
00389 int Access(const char * path, int amode)
00390         /*@globals errno, fileSystem @*/
00391         /*@modifies errno, fileSystem @*/;
00392 
00393 #if defined(__linux__)
00394 
00397 int Mount(const char *source, const char *target,
00398                 const char *filesystemtype, unsigned long mountflags,
00399                 const void *data)
00400         /*@globals errno, fileSystem @*/
00401         /*@modifies errno, fileSystem @*/;
00402 
00406 int Umount(const char *target)
00407         /*@globals errno, fileSystem @*/
00408         /*@modifies errno, fileSystem @*/;
00409 
00413 int Umount2(const char *target, int flags)
00414         /*@globals errno, fileSystem @*/
00415         /*@modifies errno, fileSystem @*/;
00416 #endif
00417 
00421 int Glob_pattern_p (const char *pattern, int quote)
00422         /*@*/;
00423 
00427 int Glob_error(const char * epath, int eerrno)
00428         /*@*/;
00429 
00433 int Glob(const char * pattern, int flags,
00434                 int errfunc(const char * epath, int eerrno),
00435                 /*@out@*/ void * _pglob)
00436         /*@globals fileSystem @*/
00437         /*@modifies *_pglob, fileSystem @*/;
00438 
00442 void Globfree( /*@only@*/ void * _pglob)
00443         /*@globals fileSystem @*/
00444         /*@modifies *_pglob, fileSystem @*/;
00445 
00446 
00450 /*@null@*/
00451 DIR * Opendir(const char * path)
00452         /*@globals errno, h_errno, fileSystem, internalState @*/
00453         /*@modifies errno, fileSystem, internalState @*/;
00454 
00458 /*@dependent@*/ /*@null@*/
00459 struct dirent * Readdir(DIR * dir)
00460         /*@globals errno, fileSystem @*/
00461         /*@modifies *dir, errno, fileSystem @*/;
00462 
00466 int Closedir(/*@only@*/ DIR * dir)
00467         /*@globals errno, fileSystem @*/
00468         /*@modifies *dir, errno, fileSystem @*/;
00469 
00473 /*@-globuse@*/
00474 /*@null@*/
00475 char * Realpath(const char * path, /*@out@*/ /*@null@*/ char * resolved_path)
00476         /*@globals errno, fileSystem, internalState @*/
00477         /*@modifies resolved_path, errno, fileSystem, internalState @*/;
00478 /*@=globuse@*/
00479 
00484 off_t Lseek(int fdno, off_t offset, int whence)
00485         /*@globals errno, fileSystem @*/
00486         /*@modifies errno, fileSystem @*/;
00487 
00495 
00498 /*@null@*/ FD_t fdDup(int fdno)
00499         /*@globals fileSystem, internalState @*/
00500         /*@modifies fileSystem, internalState @*/;
00501 
00502 /*@-exportlocal@*/
00505 ssize_t fdRead(void * cookie, /*@out@*/ char * buf, size_t count)
00506         /*@globals errno, fileSystem, internalState @*/
00507         /*@modifies *cookie, *buf, errno, fileSystem, internalState @*/;
00508 #define fdRead(_fd, _buf, _count)       fdio->read((_fd), (_buf), (_count))
00509 
00512 ssize_t fdWrite(void * cookie, const char * buf, size_t count)
00513         /*@globals errno, fileSystem, internalState @*/
00514         /*@modifies *cookie, errno, fileSystem, internalState @*/;
00515 #define fdWrite(_fd, _buf, _count)      fdio->write((_fd), (_buf), (_count))
00516 
00519 int fdClose( /*@only@*/ void * cookie)
00520         /*@globals errno, fileSystem, systemState, internalState @*/
00521         /*@modifies *cookie, errno, fileSystem, systemState, internalState @*/;
00522 #define fdClose(_fd)            fdio->close(_fd)
00523 
00526 /*@null@*/ FD_t fdOpen(const char *path, int flags, mode_t mode)
00527         /*@globals errno, fileSystem, internalState @*/
00528         /*@modifies errno, fileSystem, internalState @*/;
00529 #define fdOpen(_path, _flags, _mode)    fdio->_open((_path), (_flags), (_mode))
00530 
00533 /*@unused@*/
00534 /*@newref@*/ /*@null@*/
00535 FD_t fdLink (void * cookie, const char * msg)
00536         /*@globals fileSystem @*/
00537         /*@modifies *cookie, fileSystem @*/;
00538 #define fdLink(_fd, _msg)       \
00539         ((FD_t)rpmioLinkPoolItem((rpmioItem)(_fd), _msg, __FILE__, __LINE__))
00540 
00543 /*@unused@*/ /*@null@*/
00544 FD_t fdFree(/*@killref@*/ FD_t fd, const char * msg)
00545         /*@globals fileSystem @*/
00546         /*@modifies fd, fileSystem @*/;
00547 #define fdFree(_fd, _msg)       \
00548         ((FD_t)rpmioFreePoolItem((rpmioItem)(_fd), _msg, __FILE__, __LINE__))
00549 
00552 /*@unused@*/
00553 /*@newref@*/ /*@null@*/
00554 FD_t fdNew (const char * msg)
00555         /*@globals fileSystem @*/
00556         /*@modifies fileSystem @*/;
00557 /*@newref@*/ /*@null@*/
00558 FD_t XfdNew (const char * msg, const char * fn, unsigned ln)
00559         /*@globals fileSystem @*/
00560         /*@modifies fileSystem @*/;
00561 #define fdNew(_msg)             XfdNew(_msg, __FILE__, __LINE__)
00562 
00565 int fdWritable(FD_t fd, int secs)
00566         /*@globals errno, fileSystem @*/
00567         /*@modifies fd, errno, fileSystem @*/;
00568 
00571 int fdReadable(FD_t fd, int secs)
00572         /*@globals errno @*/
00573         /*@modifies fd, errno @*/;
00574 /*@=exportlocal@*/
00575 
00584 int rpmioMkpath(const char * path, mode_t mode, uid_t uid, gid_t gid)
00585         /*@globals h_errno, fileSystem, internalState @*/
00586         /*@modifies fileSystem, internalState @*/;
00587 
00595 int rpmioAccess(const char *FN, /*@null@*/ const char * path, int mode)
00596         /*@globals fileSystem, internalState @*/
00597         /*@modifies fileSystem, internalState @*/;
00598 
00604 extern char * (*Getpass) (const char * prompt)
00605         /*@*/;
00606 char * _GetPass (const char * prompt)
00607         /*@*/;
00608 char * _RequestPass (const char * prompt)
00609         /*@*/;
00610 
00614 /*@-typeuse@*/
00615 typedef enum ftperrCode_e {
00616     FTPERR_NE_ERROR             = -1,   
00617     FTPERR_NE_LOOKUP            = -2,   
00618     FTPERR_NE_AUTH              = -3,   
00619     FTPERR_NE_PROXYAUTH         = -4,   
00620     FTPERR_NE_CONNECT           = -5,   
00621     FTPERR_NE_TIMEOUT           = -6,   
00622     FTPERR_NE_FAILED            = -7,   
00623     FTPERR_NE_RETRY             = -8,   
00624     FTPERR_NE_REDIRECT          = -9,   
00626     FTPERR_BAD_SERVER_RESPONSE  = -81,  
00627     FTPERR_SERVER_IO_ERROR      = -82,  
00628     FTPERR_SERVER_TIMEOUT       = -83,  
00629     FTPERR_BAD_HOST_ADDR        = -84,  
00630     FTPERR_BAD_HOSTNAME         = -85,  
00631     FTPERR_FAILED_CONNECT       = -86,  
00632     FTPERR_FILE_IO_ERROR        = -87,  
00633     FTPERR_PASSIVE_ERROR        = -88,  
00634     FTPERR_FAILED_DATA_CONNECT  = -89,  
00635     FTPERR_FILE_NOT_FOUND       = -90,  
00636     FTPERR_NIC_ABORT_IN_PROGRESS= -91,  
00637     FTPERR_UNKNOWN              = -100  
00638 } ftperrCode;
00639 /*@=typeuse@*/
00640 
00643 /*@-redecl@*/
00644 /*@observer@*/
00645 const char * ftpStrerror(int errorNumber)
00646         /*@*/;
00647 /*@=redecl@*/
00648 
00651 /*@unused@*/
00652 /*@dependent@*/ /*@null@*/
00653 void * ufdGetUrlinfo(FD_t fd)
00654         /*@globals fileSystem @*/
00655         /*@modifies fd, fileSystem @*/;
00656 
00659 /*@-redecl@*/
00660 /*@unused@*/
00661 /*@observer@*/
00662 const char * urlStrerror(const char * url)
00663         /*@globals h_errno, internalState @*/
00664         /*@modifies internalState @*/;
00665 /*@=redecl@*/
00666 
00669 /*@-exportlocal@*/
00670 int ufdCopy(FD_t sfd, FD_t tfd)
00671         /*@globals fileSystem @*/
00672         /*@modifies sfd, tfd, fileSystem @*/;
00673 /*@=exportlocal@*/
00674 
00677 int ufdGetFile( /*@killref@*/ FD_t sfd, FD_t tfd)
00678         /*@globals fileSystem, internalState @*/
00679         /*@modifies sfd, tfd, fileSystem, internalState @*/;
00680 
00681 /*@-exportlocal@*/
00684 /*@observer@*/ /*@unchecked@*/ extern FDIO_t fdio;
00685 
00688 /*@observer@*/ /*@unchecked@*/ extern FDIO_t fpio;
00689 
00692 /*@observer@*/ /*@unchecked@*/ extern FDIO_t ufdio;
00693 
00696 /*@observer@*/ /*@unchecked@*/ extern FDIO_t gzdio;
00697 
00700 /*@observer@*/ /*@unchecked@*/ extern FDIO_t bzdio;
00701 
00704 /*@observer@*/ /*@unchecked@*/ extern FDIO_t lzdio;
00705 
00708 /*@observer@*/ /*@unchecked@*/ extern FDIO_t xzdio;
00709 
00710 /*@=exportlocal@*/
00713 /*@unchecked@*/ /*@only@*/ /*@null@*/
00714 extern rpmioPool _fdPool;
00715 
00719 void rpmioClean(void)
00720         /*@globals _fdPool, fileSystem, internalState @*/
00721         /*@modifies _fdPool, fileSystem, internalState @*/;
00722 
00728 /*@null@*/
00729 rpmioPool rpmioFreePool(/*@only@*//*@null@*/ rpmioPool pool)
00730         /*@globals fileSystem, internalState @*/
00731         /*@modifies pool, fileSystem, internalState @*/;
00732 
00744 rpmioPool rpmioNewPool(/*@observer@*/ const char * name,
00745                 size_t size, int limit, int flags,
00746                 /*@null@*/ const char * (*dbg) (void *item), 
00747                 /*@null@*/ void (*init) (void *item),
00748                 /*@null@*/ void (*fini) (void *item))
00749         /*@globals fileSystem @*/
00750         /*@modifies fileSystem @*/;
00751 
00760 /*@null@*/
00761 rpmioItem rpmioUnlinkPoolItem(/*@killref@*/ /*@null@*/ rpmioItem item,
00762                 const char * msg, const char * fn, unsigned ln)
00763         /*@globals fileSystem @*/
00764         /*@modifies item, fileSystem @*/;
00765 
00774 /*@newref@*/ /*@null@*/
00775 rpmioItem rpmioLinkPoolItem(/*@returned@*/ /*@null@*/ rpmioItem item,
00776                 const char * msg, const char * fn, unsigned ln)
00777         /*@globals fileSystem @*/
00778         /*@modifies item, fileSystem @*/;
00779 
00788 /*@null@*/
00789 void * rpmioFreePoolItem(/*@killref@*/ /*@null@*/ rpmioItem item,
00790                 const char * msg, const char * fn, unsigned ln)
00791         /*@globals fileSystem @*/
00792         /*@modifies item, fileSystem @*/;
00793 
00800 rpmioItem rpmioGetPool(/*@kept@*/ /*@null@*/ rpmioPool pool, size_t size)
00801         /*@globals fileSystem @*/
00802         /*@modifies pool, fileSystem @*/;
00803 
00809 /*@null@*/
00810 rpmioItem rpmioPutPool(rpmioItem item)
00811         /*@globals fileSystem @*/
00812         /*@modifies item, fileSystem @*/;
00813 
00814 #ifdef __cplusplus
00815 }
00816 #endif
00817 
00818 #endif  /* H_RPMIO */