rpm 5.3.7
|
00001 #ifndef H_RPMIO 00002 #define H_RPMIO 00003 00009 #include <sys/types.h> 00010 #include <sys/stat.h> 00011 #include <stdio.h> 00012 #include <stdlib.h> 00013 #include <unistd.h> 00014 00015 #include <rpmiotypes.h> 00016 #include <rpmzlog.h> 00017 00025 #if !defined(__LCLINT__) && !defined(__UCLIBC__) && defined(__GLIBC__) && \ 00026 (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2)) 00027 #define USE_COOKIE_SEEK_POINTER 1 00028 typedef _IO_off64_t _libio_off_t; 00029 typedef _libio_off_t * _libio_pos_t; 00030 #else 00031 typedef off_t _libio_off_t; 00032 typedef off_t _libio_pos_t; 00033 #endif 00034 00038 /*@unchecked@*/ 00039 extern int _rpmio_debug; 00040 00043 typedef /*@abstract@*/ /*@refcounted@*/ struct _FD_s * FD_t; 00044 00047 typedef /*@observer@*/ struct FDIO_s * FDIO_t; 00048 00049 #ifdef __cplusplus 00050 extern "C" { 00051 #endif 00052 00057 00060 typedef ssize_t (*fdio_read_function_t) (void *cookie, char *buf, size_t nbytes) 00061 /*@globals errno, fileSystem @*/ 00062 /*@modifies *cookie, errno, fileSystem @*/ 00063 /*@requires maxSet(buf) >= (nbytes - 1) @*/ 00064 /*@ensures maxRead(buf) == result @*/ ; 00065 00068 typedef ssize_t (*fdio_write_function_t) (void *cookie, const char *buf, size_t nbytes) 00069 /*@globals errno, fileSystem @*/ 00070 /*@modifies *cookie, errno, fileSystem @*/; 00071 00074 typedef int (*fdio_seek_function_t) (void *cookie, _libio_pos_t pos, int whence) 00075 /*@globals errno, fileSystem @*/ 00076 /*@modifies *cookie, errno, fileSystem @*/; 00077 00080 typedef int (*fdio_close_function_t) (void *cookie) 00081 /*@globals errno, fileSystem, systemState @*/ 00082 /*@modifies *cookie, errno, fileSystem, systemState @*/; 00083 00086 typedef FD_t (*fdio_fopen_function_t) (const char * path, const char * fmode) 00087 /*@globals errno, fileSystem @*/ 00088 /*@modifies errno, fileSystem @*/; 00089 00092 typedef FD_t (*fdio_fdopen_function_t) (void * cookie, const char * fmode) 00093 /*@globals errno, fileSystem @*/ 00094 /*@modifies errno, fileSystem @*/; 00095 00098 typedef int (*fdio_flush_function_t) (void * cookie) 00099 /*@globals errno, fileSystem @*/ 00100 /*@modifies errno, fileSystem @*/; 00101 00107 struct FDIO_s { 00108 fdio_read_function_t read; 00109 fdio_write_function_t write; 00110 fdio_seek_function_t seek; 00111 fdio_close_function_t close; 00112 /*@null@*/ 00113 fdio_fopen_function_t _fopen; 00114 /*@null@*/ 00115 fdio_fdopen_function_t _fdopen; 00116 /*@null@*/ 00117 fdio_flush_function_t _flush; 00118 }; 00119 00120 00125 00129 /*@observer@*/ const char * Fstrerror(/*@null@*/ FD_t fd) 00130 /*@*/; 00131 00135 /*@-incondefs@*/ 00136 size_t Fread(/*@out@*/ void * buf, size_t size, size_t nmemb, FD_t fd) 00137 /*@globals fileSystem @*/ 00138 /*@modifies fd, *buf, fileSystem @*/ 00139 /*@requires maxSet(buf) >= (nmemb - 1) @*/; 00140 /*@=incondefs@*/ 00141 00145 /*@-incondefs@*/ 00146 size_t Fwrite(const void * buf, size_t size, size_t nmemb, FD_t fd) 00147 /*@globals fileSystem @*/ 00148 /*@modifies fd, fileSystem @*/ 00149 /*@requires maxRead(buf) >= nmemb @*/; 00150 /*@=incondefs@*/ 00151 00155 int Fseek(FD_t fd, _libio_off_t offset, int whence) 00156 /*@globals fileSystem @*/ 00157 /*@modifies fileSystem @*/; 00158 long Ftell(FD_t fd) 00159 /*@*/; 00160 void Rewind(FD_t fd) 00161 /*@*/; 00162 int Fgetpos(FD_t fd, fpos_t *pos) 00163 /*@*/; 00164 int Fsetpos(FD_t fd, fpos_t *pos) 00165 /*@*/; 00166 00170 int Fclose( /*@killref@*/ FD_t fd) 00171 /*@globals fileSystem, internalState @*/ 00172 /*@modifies fd, fileSystem, internalState @*/; 00173 00176 /*@null@*/ FD_t Fdopen(FD_t ofd, const char * fmode) 00177 /*@globals fileSystem, internalState @*/ 00178 /*@modifies ofd, fileSystem, internalState @*/; 00179 00183 /*@null@*/ FD_t Fopen(/*@null@*/ const char * path, 00184 /*@null@*/ const char * fmode) 00185 /*@globals h_errno, fileSystem, internalState @*/ 00186 /*@modifies fileSystem, internalState @*/; 00187 00188 00192 int Fflush(/*@null@*/ FD_t fd) 00193 /*@globals fileSystem @*/ 00194 /*@modifies fd, fileSystem @*/; 00195 00199 int Ferror(/*@null@*/ FD_t fd) 00200 /*@*/; 00201 00205 int Fileno(FD_t fd) 00206 /*@globals fileSystem @*/ 00207 /*@modifies fileSystem@*/; 00208 00212 /*@unused@*/ 00213 int Fcntl(FD_t fd, int op, void *lip) 00214 /*@globals errno, fileSystem @*/ 00215 /*@modifies fd, *lip, errno, fileSystem @*/; 00216 00223 00227 int Mkdir(const char * path, mode_t mode) 00228 /*@globals errno, h_errno, fileSystem, internalState @*/ 00229 /*@modifies errno, fileSystem, internalState @*/; 00230 00234 int Chdir(const char * path) 00235 /*@globals errno, h_errno, fileSystem, internalState @*/ 00236 /*@modifies errno, fileSystem, internalState @*/; 00237 00241 int Rmdir(const char * path) 00242 /*@globals errno, h_errno, fileSystem, internalState @*/ 00243 /*@modifies errno, fileSystem, internalState @*/; 00244 00245 /*@unchecked@*/ /*@observer@*/ /*@null@*/ 00246 extern const char * _chroot_prefix; 00247 00252 int Chroot(const char * path) 00253 /*@globals _chroot_prefix, errno, fileSystem, internalState @*/ 00254 /*@modifies _chroot_prefix, errno, fileSystem, internalState @*/; 00255 00260 int Open(const char * path, int flags, mode_t mode) 00261 /*@globals errno, fileSystem, internalState @*/ 00262 /*@modifies errno, fileSystem, internalState @*/; 00263 00267 int Rename(const char * oldpath, const char * newpath) 00268 /*@globals errno, h_errno, fileSystem, internalState @*/ 00269 /*@modifies errno, fileSystem, internalState @*/; 00270 00274 int Link(const char * oldpath, const char * newpath) 00275 /*@globals errno, fileSystem, internalState @*/ 00276 /*@modifies errno, fileSystem, internalState @*/; 00277 00281 int Unlink(const char * path) 00282 /*@globals errno, h_errno, fileSystem, internalState @*/ 00283 /*@modifies errno, fileSystem, internalState @*/; 00284 00288 int Stat(const char * path, /*@out@*/ struct stat * st) 00289 /*@globals errno, h_errno, fileSystem, internalState @*/ 00290 /*@modifies *st, errno, fileSystem, internalState @*/; 00291 00295 int Lstat(const char * path, /*@out@*/ struct stat * st) 00296 /*@globals errno, h_errno, fileSystem, internalState @*/ 00297 /*@modifies *st, errno, fileSystem, internalState @*/; 00298 00302 int Fstat(FD_t fd, /*@out@*/ struct stat * st) 00303 /*@globals errno, fileSystem, internalState @*/ 00304 /*@modifies *st, errno, fileSystem, internalState @*/; 00305 00309 int Fadvise(FD_t fd, off_t offset, off_t length, int advice) 00310 /*@globals fileSystem, internalState @*/ 00311 /*@modifies fileSystem, internalState @*/; 00312 00316 int Fallocate(FD_t fd, off_t offset, off_t length) 00317 /*@globals fileSystem, internalState @*/ 00318 /*@modifies fileSystem, internalState @*/; 00319 00324 int Chown(const char * path, uid_t owner, gid_t group) 00325 /*@globals errno, fileSystem, internalState @*/ 00326 /*@modifies errno, fileSystem, internalState @*/; 00327 00332 int Fchown(FD_t fd, uid_t owner, gid_t group) 00333 /*@globals errno, fileSystem, internalState @*/ 00334 /*@modifies errno, fileSystem, internalState @*/; 00335 00340 int Lchown(const char * path, uid_t owner, gid_t group) 00341 /*@globals errno, fileSystem, internalState @*/ 00342 /*@modifies errno, fileSystem, internalState @*/; 00343 00348 int Chmod(const char * path, mode_t mode) 00349 /*@globals errno, fileSystem, internalState @*/ 00350 /*@modifies errno, fileSystem, internalState @*/; 00351 00356 int Lchmod(const char * path, mode_t mode) 00357 /*@globals errno, fileSystem, internalState @*/ 00358 /*@modifies errno, fileSystem, internalState @*/; 00359 00364 int Fchmod(FD_t fd, mode_t mode) 00365 /*@globals errno, fileSystem, internalState @*/ 00366 /*@modifies errno, fileSystem, internalState @*/; 00367 00372 int Chflags(const char * path, unsigned int flags) 00373 /*@globals errno, fileSystem, internalState @*/ 00374 /*@modifies errno, fileSystem, internalState @*/; 00375 00380 int Lchflags(const char * path, unsigned int flags) 00381 /*@globals errno, fileSystem, internalState @*/ 00382 /*@modifies errno, fileSystem, internalState @*/; 00383 00388 int Fchflags(FD_t fd, unsigned int flags) 00389 /*@globals errno, fileSystem, internalState @*/ 00390 /*@modifies errno, fileSystem, internalState @*/; 00391 00396 int Mkfifo(const char * path, mode_t mode) 00397 /*@globals errno, fileSystem, internalState @*/ 00398 /*@modifies errno, fileSystem, internalState @*/; 00399 00404 int Mknod(const char * path, mode_t mode, dev_t dev) 00405 /*@globals errno, fileSystem, internalState @*/ 00406 /*@modifies errno, fileSystem, internalState @*/; 00407 00412 struct utimbuf; 00413 int Utime(const char * path, const struct utimbuf * buf) 00414 /*@globals errno, fileSystem, internalState @*/ 00415 /*@modifies errno, fileSystem, internalState @*/; 00416 00421 int Utimes(const char * path, const struct timeval * times) 00422 /*@globals errno, fileSystem, internalState @*/ 00423 /*@modifies errno, fileSystem, internalState @*/; 00424 00429 int Lutimes(const char * path, const struct timeval * times) 00430 /*@globals errno, fileSystem, internalState @*/ 00431 /*@modifies errno, fileSystem, internalState @*/; 00432 00437 int Symlink(const char * oldpath, const char * newpath) 00438 /*@globals errno, fileSystem, internalState @*/ 00439 /*@modifies errno, fileSystem, internalState @*/; 00440 00445 /*@-incondefs@*/ 00446 int Readlink(const char * path, /*@out@*/ char * buf, size_t bufsiz) 00447 /*@globals errno, h_errno, fileSystem, internalState @*/ 00448 /*@modifies *buf, errno, fileSystem, internalState @*/; 00449 /*@=incondefs@*/ 00450 00455 int Access(const char * path, int amode) 00456 /*@globals errno, fileSystem @*/ 00457 /*@modifies errno, fileSystem @*/; 00458 00459 #if defined(__linux__) 00460 00463 int Mount(const char *source, const char *target, 00464 const char *filesystemtype, unsigned long mountflags, 00465 const void *data) 00466 /*@globals errno, fileSystem @*/ 00467 /*@modifies errno, fileSystem @*/; 00468 00472 int Umount(const char *target) 00473 /*@globals errno, fileSystem @*/ 00474 /*@modifies errno, fileSystem @*/; 00475 00479 int Umount2(const char *target, int flags) 00480 /*@globals errno, fileSystem @*/ 00481 /*@modifies errno, fileSystem @*/; 00482 #endif 00483 00487 int Glob_pattern_p (const char *pattern, int quote) 00488 /*@*/; 00489 00493 int Glob_error(const char * epath, int eerrno) 00494 /*@*/; 00495 00499 int Glob(const char * pattern, int flags, 00500 int errfunc(const char * epath, int eerrno), 00501 /*@out@*/ void * _pglob) 00502 /*@globals fileSystem @*/ 00503 /*@modifies *_pglob, fileSystem @*/; 00504 00508 void Globfree( /*@only@*/ void * _pglob) 00509 /*@globals fileSystem @*/ 00510 /*@modifies *_pglob, fileSystem @*/; 00511 00512 00516 /*@-globuse@*/ 00517 /*@null@*/ 00518 char * Realpath(const char * path, /*@out@*/ /*@null@*/ char * resolved_path) 00519 /*@globals errno, fileSystem, internalState @*/ 00520 /*@modifies resolved_path, errno, fileSystem, internalState @*/; 00521 /*@=globuse@*/ 00522 00527 off_t Lseek(int fdno, off_t offset, int whence) 00528 /*@globals errno, fileSystem @*/ 00529 /*@modifies errno, fileSystem @*/; 00530 00538 00541 /*@null@*/ FD_t fdDup(int fdno) 00542 /*@globals fileSystem, internalState @*/ 00543 /*@modifies fileSystem, internalState @*/; 00544 00545 /*@-exportlocal@*/ 00548 ssize_t fdRead(void * cookie, /*@out@*/ char * buf, size_t count) 00549 /*@globals errno, fileSystem, internalState @*/ 00550 /*@modifies *cookie, *buf, errno, fileSystem, internalState @*/; 00551 #define fdRead(_fd, _buf, _count) fdio->read((_fd), (_buf), (_count)) 00552 00555 ssize_t fdWrite(void * cookie, const char * buf, size_t count) 00556 /*@globals errno, fileSystem, internalState @*/ 00557 /*@modifies *cookie, errno, fileSystem, internalState @*/; 00558 #define fdWrite(_fd, _buf, _count) fdio->write((_fd), (_buf), (_count)) 00559 00562 int fdClose( /*@only@*/ void * cookie) 00563 /*@globals errno, fileSystem, systemState, internalState @*/ 00564 /*@modifies *cookie, errno, fileSystem, systemState, internalState @*/; 00565 #define fdClose(_fd) fdio->close(_fd) 00566 00569 /*@null@*/ FD_t fdOpen(const char *path, int flags, mode_t mode) 00570 /*@globals errno, fileSystem, internalState @*/ 00571 /*@modifies errno, fileSystem, internalState @*/; 00572 #define fdOpen(_path, _flags, _mode) fdio->_open((_path), (_flags), (_mode)) 00573 00576 /*@unused@*/ 00577 /*@newref@*/ /*@null@*/ 00578 FD_t fdLink (void * cookie, const char * msg) 00579 /*@globals fileSystem @*/ 00580 /*@modifies *cookie, fileSystem @*/; 00581 #define fdLink(_fd, _msg) \ 00582 ((FD_t)rpmioLinkPoolItem((rpmioItem)(_fd), _msg, __FILE__, __LINE__)) 00583 00586 /*@unused@*/ /*@null@*/ 00587 FD_t fdFree(/*@killref@*/ FD_t fd, const char * msg) 00588 /*@globals fileSystem @*/ 00589 /*@modifies fd, fileSystem @*/; 00590 #define fdFree(_fd, _msg) \ 00591 ((FD_t)rpmioFreePoolItem((rpmioItem)(_fd), _msg, __FILE__, __LINE__)) 00592 00595 /*@unused@*/ 00596 /*@newref@*/ /*@null@*/ 00597 FD_t fdNew (const char * msg) 00598 /*@globals fileSystem @*/ 00599 /*@modifies fileSystem @*/; 00600 /*@newref@*/ /*@null@*/ 00601 FD_t XfdNew (const char * msg, const char * fn, unsigned ln) 00602 /*@globals fileSystem @*/ 00603 /*@modifies fileSystem @*/; 00604 #define fdNew(_msg) XfdNew(_msg, __FILE__, __LINE__) 00605 00608 int fdWritable(FD_t fd, int secs) 00609 /*@globals errno, fileSystem @*/ 00610 /*@modifies fd, errno, fileSystem @*/; 00611 00614 int fdReadable(FD_t fd, int secs) 00615 /*@globals errno @*/ 00616 /*@modifies fd, errno @*/; 00617 /*@=exportlocal@*/ 00618 00627 int rpmioMkpath(const char * path, mode_t mode, uid_t uid, gid_t gid) 00628 /*@globals h_errno, fileSystem, internalState @*/ 00629 /*@modifies fileSystem, internalState @*/; 00630 00638 int rpmioAccess(const char *FN, /*@null@*/ const char * path, int mode) 00639 /*@globals fileSystem, internalState @*/ 00640 /*@modifies fileSystem, internalState @*/; 00641 00647 extern char * (*Getpass) (const char * prompt) 00648 /*@*/; 00649 char * _GetPass (const char * prompt) 00650 /*@*/; 00651 char * _RequestPass (const char * prompt) 00652 /*@*/; 00653 00657 /*@-typeuse@*/ 00658 typedef enum ftperrCode_e { 00659 FTPERR_NE_ERROR = -1, 00660 FTPERR_NE_LOOKUP = -2, 00661 FTPERR_NE_AUTH = -3, 00662 FTPERR_NE_PROXYAUTH = -4, 00663 FTPERR_NE_CONNECT = -5, 00664 FTPERR_NE_TIMEOUT = -6, 00665 FTPERR_NE_FAILED = -7, 00666 FTPERR_NE_RETRY = -8, 00667 FTPERR_NE_REDIRECT = -9, 00669 FTPERR_BAD_SERVER_RESPONSE = -81, 00670 FTPERR_SERVER_IO_ERROR = -82, 00671 FTPERR_SERVER_TIMEOUT = -83, 00672 FTPERR_BAD_HOST_ADDR = -84, 00673 FTPERR_BAD_HOSTNAME = -85, 00674 FTPERR_FAILED_CONNECT = -86, 00675 FTPERR_FILE_IO_ERROR = -87, 00676 FTPERR_PASSIVE_ERROR = -88, 00677 FTPERR_FAILED_DATA_CONNECT = -89, 00678 FTPERR_FILE_NOT_FOUND = -90, 00679 FTPERR_NIC_ABORT_IN_PROGRESS= -91, 00680 FTPERR_UNKNOWN = -100 00681 } ftperrCode; 00682 /*@=typeuse@*/ 00683 00686 /*@-redecl@*/ 00687 /*@observer@*/ 00688 const char * ftpStrerror(int errorNumber) 00689 /*@*/; 00690 /*@=redecl@*/ 00691 00694 /*@unused@*/ 00695 /*@dependent@*/ /*@null@*/ 00696 void * ufdGetUrlinfo(FD_t fd) 00697 /*@globals fileSystem @*/ 00698 /*@modifies fd, fileSystem @*/; 00699 00702 /*@-redecl@*/ 00703 /*@unused@*/ 00704 /*@observer@*/ 00705 const char * urlStrerror(const char * url) 00706 /*@globals h_errno, internalState @*/ 00707 /*@modifies internalState @*/; 00708 /*@=redecl@*/ 00709 00712 /*@-exportlocal@*/ 00713 int ufdCopy(FD_t sfd, FD_t tfd) 00714 /*@globals fileSystem @*/ 00715 /*@modifies sfd, tfd, fileSystem @*/; 00716 /*@=exportlocal@*/ 00717 00720 int ufdGetFile( /*@killref@*/ FD_t sfd, FD_t tfd) 00721 /*@globals fileSystem, internalState @*/ 00722 /*@modifies sfd, tfd, fileSystem, internalState @*/; 00723 00724 /*@-exportlocal@*/ 00727 /*@observer@*/ /*@unchecked@*/ extern FDIO_t fdio; 00728 00731 /*@observer@*/ /*@unchecked@*/ extern FDIO_t fpio; 00732 00735 /*@observer@*/ /*@unchecked@*/ extern FDIO_t ufdio; 00736 00739 /*@observer@*/ /*@unchecked@*/ extern FDIO_t gzdio; 00740 00743 /*@observer@*/ /*@unchecked@*/ extern FDIO_t bzdio; 00744 00747 /*@observer@*/ /*@unchecked@*/ extern FDIO_t lzdio; 00748 00751 /*@observer@*/ /*@unchecked@*/ extern FDIO_t xzdio; 00752 00753 /*@=exportlocal@*/ 00756 /*@unchecked@*/ /*@only@*/ /*@null@*/ 00757 extern rpmioPool _fdPool; 00758 00762 void rpmioClean(void) 00763 /*@globals _fdPool, fileSystem, internalState @*/ 00764 /*@modifies _fdPool, fileSystem, internalState @*/; 00765 00771 /*@null@*/ 00772 rpmioPool rpmioFreePool(/*@only@*//*@null@*/ rpmioPool pool) 00773 /*@globals fileSystem, internalState @*/ 00774 /*@modifies pool, fileSystem, internalState @*/; 00775 00787 rpmioPool rpmioNewPool(/*@observer@*/ const char * name, 00788 size_t size, int limit, int flags, 00789 /*@null@*/ char * (*dbg) (void *item), 00790 /*@null@*/ void (*init) (void *item), 00791 /*@null@*/ void (*fini) (void *item)) 00792 /*@globals fileSystem @*/ 00793 /*@modifies fileSystem @*/; 00794 00803 /*@null@*/ 00804 rpmioItem rpmioUnlinkPoolItem(/*@killref@*/ /*@null@*/ rpmioItem item, 00805 const char * msg, const char * fn, unsigned ln) 00806 /*@globals fileSystem @*/ 00807 /*@modifies item, fileSystem @*/; 00808 00817 /*@newref@*/ /*@null@*/ 00818 rpmioItem rpmioLinkPoolItem(/*@returned@*/ /*@null@*/ rpmioItem item, 00819 const char * msg, const char * fn, unsigned ln) 00820 /*@globals fileSystem @*/ 00821 /*@modifies item, fileSystem @*/; 00822 00831 /*@null@*/ 00832 void * rpmioFreePoolItem(/*@killref@*/ /*@null@*/ rpmioItem item, 00833 const char * msg, const char * fn, unsigned ln) 00834 /*@globals fileSystem @*/ 00835 /*@modifies item, fileSystem @*/; 00836 00843 rpmioItem rpmioGetPool(/*@kept@*/ /*@null@*/ rpmioPool pool, size_t size) 00844 /*@globals fileSystem @*/ 00845 /*@modifies pool, fileSystem @*/; 00846 00852 /*@null@*/ 00853 rpmioItem rpmioPutPool(rpmioItem item) 00854 /*@globals fileSystem @*/ 00855 /*@modifies item, fileSystem @*/; 00856 00857 #ifdef __cplusplus 00858 } 00859 #endif 00860 00861 #endif /* H_RPMIO */