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 struct _FD_s * FD_t;
00040
00043 typedef 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
00058
00059
00060 ;
00061
00064 typedef ssize_t (*fdio_write_function_t) (void *cookie, const char *buf, size_t nbytes)
00065
00066 ;
00067
00070 typedef int (*fdio_seek_function_t) (void *cookie, _libio_pos_t pos, int whence)
00071
00072 ;
00073
00076 typedef int (*fdio_close_function_t) (void *cookie)
00077
00078 ;
00079
00082 typedef FD_t (*fdio_fopen_function_t) (const char * path, const char * fmode)
00083
00084 ;
00085
00088 typedef FD_t (*fdio_fdopen_function_t) (void * cookie, const char * fmode)
00089
00090 ;
00091
00094 typedef int (*fdio_flush_function_t) (void * cookie)
00095
00096 ;
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
00109 fdio_fopen_function_t _fopen;
00110
00111 fdio_fdopen_function_t _fdopen;
00112
00113 fdio_flush_function_t _flush;
00114 };
00115
00116
00121
00125 const char * Fstrerror( FD_t fd)
00126 ;
00127
00131
00132 size_t Fread( void * buf, size_t size, size_t nmemb, FD_t fd)
00133
00134
00135 ;
00136
00137
00141
00142 size_t Fwrite(const void * buf, size_t size, size_t nmemb, FD_t fd)
00143
00144
00145 ;
00146
00147
00151 int Fseek(FD_t fd, _libio_off_t offset, int whence)
00152
00153 ;
00154
00158 int Fclose( FD_t fd)
00159
00160 ;
00161
00164 FD_t Fdopen(FD_t ofd, const char * fmode)
00165
00166 ;
00167
00171 FD_t Fopen( const char * path,
00172 const char * fmode)
00173
00174 ;
00175
00176
00180 int Fflush( FD_t fd)
00181
00182 ;
00183
00187 int Ferror( FD_t fd)
00188 ;
00189
00193 int Fileno(FD_t fd)
00194
00195 ;
00196
00200
00201 int Fcntl(FD_t fd, int op, void *lip)
00202
00203 ;
00204
00211
00215 int Mkdir(const char * path, mode_t mode)
00216
00217 ;
00218
00222 int Chdir(const char * path)
00223
00224 ;
00225
00229 int Rmdir(const char * path)
00230
00231 ;
00232
00233
00234 extern const char * _chroot_prefix;
00235
00240 int Chroot(const char * path)
00241
00242 ;
00243
00248 int Open(const char * path, int flags, mode_t mode)
00249
00250 ;
00251
00255 int Rename(const char * oldpath, const char * newpath)
00256
00257 ;
00258
00262 int Link(const char * oldpath, const char * newpath)
00263
00264 ;
00265
00269 int Unlink(const char * path)
00270
00271 ;
00272
00276 int Stat(const char * path, struct stat * st)
00277
00278 ;
00279
00283 int Lstat(const char * path, struct stat * st)
00284
00285 ;
00286
00290 int Fstat(FD_t fd, struct stat * st)
00291
00292 ;
00293
00298 int Chown(const char * path, uid_t owner, gid_t group)
00299
00300 ;
00301
00306 int Fchown(FD_t fd, uid_t owner, gid_t group)
00307
00308 ;
00309
00314 int Lchown(const char * path, uid_t owner, gid_t group)
00315
00316 ;
00317
00322 int Chmod(const char * path, mode_t mode)
00323
00324 ;
00325
00330 int Fchmod(FD_t fd, mode_t mode)
00331
00332 ;
00333
00338 int Mkfifo(const char * path, mode_t mode)
00339
00340 ;
00341
00346 int Mknod(const char * path, mode_t mode, dev_t dev)
00347
00348 ;
00349
00354 struct utimbuf;
00355 int Utime(const char * path, const struct utimbuf * buf)
00356
00357 ;
00358
00363 int Utimes(const char * path, const struct timeval * times)
00364
00365 ;
00366
00371 int Symlink(const char * oldpath, const char * newpath)
00372
00373 ;
00374
00379
00380 int Readlink(const char * path, char * buf, size_t bufsiz)
00381
00382 ;
00383
00384
00389 int Access(const char * path, int amode)
00390
00391 ;
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
00401 ;
00402
00406 int Umount(const char *target)
00407
00408 ;
00409
00413 int Umount2(const char *target, int flags)
00414
00415 ;
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 void * _pglob)
00436
00437 ;
00438
00442 void Globfree( void * _pglob)
00443
00444 ;
00445
00446
00450
00451 DIR * Opendir(const char * path)
00452
00453 ;
00454
00458
00459 struct dirent * Readdir(DIR * dir)
00460
00461 ;
00462
00466 int Closedir( DIR * dir)
00467
00468 ;
00469
00473
00474
00475 char * Realpath(const char * path, char * resolved_path)
00476
00477 ;
00478
00479
00484 off_t Lseek(int fdno, off_t offset, int whence)
00485
00486 ;
00487
00495
00498 FD_t fdDup(int fdno)
00499
00500 ;
00501
00502
00505 ssize_t fdRead(void * cookie, char * buf, size_t count)
00506
00507 ;
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
00514 ;
00515 #define fdWrite(_fd, _buf, _count) fdio->write((_fd), (_buf), (_count))
00516
00519 int fdClose( void * cookie)
00520
00521 ;
00522 #define fdClose(_fd) fdio->close(_fd)
00523
00526 FD_t fdOpen(const char *path, int flags, mode_t mode)
00527
00528 ;
00529 #define fdOpen(_path, _flags, _mode) fdio->_open((_path), (_flags), (_mode))
00530
00533
00534
00535 FD_t fdLink (void * cookie, const char * msg)
00536
00537 ;
00538 #define fdLink(_fd, _msg) \
00539 ((FD_t)rpmioLinkPoolItem((rpmioItem)(_fd), _msg, __FILE__, __LINE__))
00540
00543
00544 FD_t fdFree( FD_t fd, const char * msg)
00545
00546 ;
00547 #define fdFree(_fd, _msg) \
00548 ((FD_t)rpmioFreePoolItem((rpmioItem)(_fd), _msg, __FILE__, __LINE__))
00549
00552
00553
00554 FD_t fdNew (const char * msg)
00555
00556 ;
00557
00558 FD_t XfdNew (const char * msg, const char * fn, unsigned ln)
00559
00560 ;
00561 #define fdNew(_msg) XfdNew(_msg, __FILE__, __LINE__)
00562
00565 int fdWritable(FD_t fd, int secs)
00566
00567 ;
00568
00571 int fdReadable(FD_t fd, int secs)
00572
00573 ;
00574
00575
00584 int rpmioMkpath(const char * path, mode_t mode, uid_t uid, gid_t gid)
00585
00586 ;
00587
00595 int rpmioAccess(const char *FN, const char * path, int mode)
00596
00597 ;
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
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
00640
00643
00644
00645 const char * ftpStrerror(int errorNumber)
00646 ;
00647
00648
00651
00652
00653 void * ufdGetUrlinfo(FD_t fd)
00654
00655 ;
00656
00659
00660
00661
00662 const char * urlStrerror(const char * url)
00663
00664 ;
00665
00666
00669
00670 int ufdCopy(FD_t sfd, FD_t tfd)
00671
00672 ;
00673
00674
00677 int ufdGetFile( FD_t sfd, FD_t tfd)
00678
00679 ;
00680
00681
00684 extern FDIO_t fdio;
00685
00688 extern FDIO_t fpio;
00689
00692 extern FDIO_t ufdio;
00693
00696 extern FDIO_t gzdio;
00697
00700 extern FDIO_t bzdio;
00701
00704 extern FDIO_t lzdio;
00705
00708 extern FDIO_t xzdio;
00709
00710
00713
00714 extern rpmioPool _fdPool;
00715
00719 void rpmioClean(void)
00720
00721 ;
00722
00728
00729 rpmioPool rpmioFreePool( rpmioPool pool)
00730
00731 ;
00732
00744 rpmioPool rpmioNewPool( const char * name,
00745 size_t size, int limit, int flags,
00746 const char * (*dbg) (void *item),
00747 void (*init) (void *item),
00748 void (*fini) (void *item))
00749
00750 ;
00751
00760
00761 rpmioItem rpmioUnlinkPoolItem( rpmioItem item,
00762 const char * msg, const char * fn, unsigned ln)
00763
00764 ;
00765
00774
00775 rpmioItem rpmioLinkPoolItem( rpmioItem item,
00776 const char * msg, const char * fn, unsigned ln)
00777
00778 ;
00779
00788
00789 void * rpmioFreePoolItem( rpmioItem item,
00790 const char * msg, const char * fn, unsigned ln)
00791
00792 ;
00793
00800 rpmioItem rpmioGetPool( rpmioPool pool, size_t size)
00801
00802 ;
00803
00809
00810 rpmioItem rpmioPutPool(rpmioItem item)
00811
00812 ;
00813
00814 #ifdef __cplusplus
00815 }
00816 #endif
00817
00818 #endif