rpm 5.3.12
rpmio/iosm.h
Go to the documentation of this file.
00001 #ifndef H_IOSM
00002 #define H_IOSM
00003 
00009 #define _IOSM_INTERNAL  /* XXX expose internals for unit tests. */
00010 #include <rpmiotypes.h>
00011 #include <rpmio.h>      /* XXX FD_t */
00012 #include <rpmsw.h>
00013 
00017 typedef /*@abstract@*/ struct iosm_s * IOSM_t;
00018 
00019 /*@-exportlocal@*/
00020 /*@unchecked@*/
00021 extern int _iosm_debug;
00022 /*@=exportlocal@*/
00023 
00027 typedef enum iosmFileAction_e {
00028     FA_UNKNOWN = 0,     
00029     FA_CREATE,          
00030     FA_COPYIN,          
00031     FA_COPYOUT,         
00032     FA_BACKUP,          
00033     FA_SAVE,            
00034     FA_SKIP,            
00035     FA_ALTNAME,         
00036     FA_ERASE,           
00037     FA_SKIPNSTATE,      
00038     FA_SKIPNETSHARED,   
00039     FA_SKIPCOLOR        
00040 } iosmFileAction;
00041 
00044 typedef enum iosmMapFlags_e {
00045     IOSM_MAP_PATH       = (1 <<  0),
00046     IOSM_MAP_MODE       = (1 <<  1),
00047     IOSM_MAP_UID        = (1 <<  2),
00048     IOSM_MAP_GID        = (1 <<  3),
00049     IOSM_FOLLOW_SYMLINKS= (1 <<  4), 
00050     IOSM_MAP_ABSOLUTE   = (1 <<  5),
00051     IOSM_MAP_ADDDOT     = (1 <<  6),
00052     IOSM_ALL_HARDLINKS  = (1 <<  7), 
00053     IOSM_MAP_TYPE       = (1 <<  8), 
00054     IOSM_SBIT_CHECK     = (1 <<  9),
00055     IOSM_PAYLOAD_LIST   = (1 << 10),
00056     IOSM_PAYLOAD_EXTRACT= (1 << 11),
00057     IOSM_PAYLOAD_CREATE = (1 << 12)
00058 } iosmMapFlags;
00059 
00060 #if defined(_IOSM_INTERNAL)
00061 
00064 #define IOSMERR_CHECK_ERRNO     0x00008000
00065 
00068 enum iosmErrorReturns_e {
00069         IOSMERR_BAD_MAGIC       = (2                    ),
00070         IOSMERR_BAD_HEADER      = (3                    ),
00071         IOSMERR_OPEN_FAILED     = (4    | IOSMERR_CHECK_ERRNO),
00072         IOSMERR_CHMOD_FAILED    = (5    | IOSMERR_CHECK_ERRNO),
00073         IOSMERR_CHOWN_FAILED    = (6    | IOSMERR_CHECK_ERRNO),
00074         IOSMERR_WRITE_FAILED    = (7    | IOSMERR_CHECK_ERRNO),
00075         IOSMERR_UTIME_FAILED    = (8    | IOSMERR_CHECK_ERRNO),
00076         IOSMERR_UNLINK_FAILED   = (9    | IOSMERR_CHECK_ERRNO),
00077 
00078         IOSMERR_RENAME_FAILED   = (10   | IOSMERR_CHECK_ERRNO),
00079         IOSMERR_SYMLINK_FAILED  = (11   | IOSMERR_CHECK_ERRNO),
00080         IOSMERR_STAT_FAILED     = (12   | IOSMERR_CHECK_ERRNO),
00081         IOSMERR_LSTAT_FAILED    = (13   | IOSMERR_CHECK_ERRNO),
00082         IOSMERR_MKDIR_FAILED    = (14   | IOSMERR_CHECK_ERRNO),
00083         IOSMERR_RMDIR_FAILED    = (15   | IOSMERR_CHECK_ERRNO),
00084         IOSMERR_MKNOD_FAILED    = (16   | IOSMERR_CHECK_ERRNO),
00085         IOSMERR_MKFIFO_FAILED   = (17   | IOSMERR_CHECK_ERRNO),
00086         IOSMERR_LINK_FAILED     = (18   | IOSMERR_CHECK_ERRNO),
00087         IOSMERR_READLINK_FAILED = (19   | IOSMERR_CHECK_ERRNO),
00088         IOSMERR_READ_FAILED     = (20   | IOSMERR_CHECK_ERRNO),
00089         IOSMERR_COPY_FAILED     = (21   | IOSMERR_CHECK_ERRNO),
00090         IOSMERR_LSETFCON_FAILED = (22   | IOSMERR_CHECK_ERRNO),
00091         IOSMERR_HDR_SIZE        = (23                   ),
00092         IOSMERR_HDR_TRAILER     = (24                   ),
00093         IOSMERR_UNKNOWN_FILETYPE= (25                   ),
00094         IOSMERR_MISSING_HARDLINK= (26                   ),
00095         IOSMERR_DIGEST_MISMATCH = (27                   ),
00096         IOSMERR_INTERNAL        = (28                   ),
00097         IOSMERR_UNMAPPED_FILE   = (29                   ),
00098         IOSMERR_ENOENT          = (30                   ),
00099         IOSMERR_ENOTEMPTY       = (31                   )
00100 };
00101 #endif
00102 
00105 #define IOSM_VERBOSE    0x8000
00106 #define IOSM_INTERNAL   0x4000
00107 #define IOSM_SYSCALL    0x2000
00108 #define IOSM_DEAD       0x1000
00109 
00110 #define _fv(_a)         ((_a) | IOSM_VERBOSE)
00111 #define _fi(_a)         ((_a) | IOSM_INTERNAL)
00112 #define _fs(_a)         ((_a) | (IOSM_INTERNAL | IOSM_SYSCALL))
00113 #define _fd(_a)         ((_a) | (IOSM_INTERNAL | IOSM_DEAD))
00114 
00115 typedef enum iosmFileStage_e {
00116     IOSM_UNKNOWN =   0,
00117     IOSM_INIT   =  _fd(1),
00118     IOSM_PRE    =  _fd(2),
00119     IOSM_PROCESS=  _fv(3),
00120     IOSM_POST   =  _fd(4),
00121     IOSM_UNDO   =  5,
00122     IOSM_FINI   =  6,
00123 
00124     IOSM_PKGINSTALL     = _fd(7),
00125     IOSM_PKGERASE       = _fd(8),
00126     IOSM_PKGBUILD       = _fd(9),
00127     IOSM_PKGCOMMIT      = _fd(10),
00128     IOSM_PKGUNDO        = _fd(11),
00129 
00130     IOSM_CREATE =  _fd(17),
00131     IOSM_MAP    =  _fd(18),
00132     IOSM_MKDIRS =  _fi(19),
00133     IOSM_RMDIRS =  _fi(20),
00134     IOSM_MKLINKS=  _fi(21),
00135     IOSM_NOTIFY =  _fd(22),
00136     IOSM_DESTROY=  _fd(23),
00137     IOSM_VERIFY =  _fd(24),
00138     IOSM_COMMIT =  _fd(25),
00139 
00140     IOSM_UNLINK =  _fs(33),
00141     IOSM_RENAME =  _fs(34),
00142     IOSM_MKDIR  =  _fs(35),
00143     IOSM_RMDIR  =  _fs(36),
00144     IOSM_LSETFCON= _fs(39),
00145     IOSM_CHOWN  =  _fs(40),
00146     IOSM_LCHOWN =  _fs(41),
00147     IOSM_CHMOD  =  _fs(42),
00148     IOSM_UTIME  =  _fs(43),
00149     IOSM_SYMLINK=  _fs(44),
00150     IOSM_LINK   =  _fs(45),
00151     IOSM_MKFIFO =  _fs(46),
00152     IOSM_MKNOD  =  _fs(47),
00153     IOSM_LSTAT  =  _fs(48),
00154     IOSM_STAT   =  _fs(49),
00155     IOSM_READLINK= _fs(50),
00156     IOSM_CHROOT =  _fs(51),
00157 
00158     IOSM_NEXT   =  _fd(65),
00159     IOSM_EAT    =  _fd(66),
00160     IOSM_POS    =  _fd(67),
00161     IOSM_PAD    =  _fd(68),
00162     IOSM_TRAILER=  _fd(69),
00163     IOSM_HREAD  =  _fd(70),
00164     IOSM_HWRITE =  _fd(71),
00165     IOSM_DREAD  =  _fs(72),
00166     IOSM_DWRITE =  _fs(73),
00167 
00168     IOSM_ROPEN  =  _fs(129),
00169     IOSM_READ   =  _fs(130),
00170     IOSM_RCLOSE =  _fs(131),
00171     IOSM_WOPEN  =  _fs(132),
00172     IOSM_WRITE  =  _fs(133),
00173     IOSM_WCLOSE =  _fs(134)
00174 } iosmFileStage;
00175 #undef  _fv
00176 #undef  _fi
00177 #undef  _fs
00178 #undef  _fd
00179 
00180 #if defined(_IOSM_INTERNAL)
00181 
00184 typedef /*@abstract@*/ struct iosmIterator_s * IOSMI_t;
00185 
00189 struct hardLink_s {
00190 /*@owned@*/ /*@relnull@*/
00191     struct hardLink_s * next;
00192 /*@owned@*/
00193     const char ** nsuffix;
00194 /*@owned@*/
00195     int * filex;
00196     struct stat sb;
00197     int nlink;
00198     int linksLeft;
00199     int linkIndex;
00200     int createdPath;
00201 };
00202 
00207 struct iosmIterator_s {
00208     void * ts;                  
00209     void * fi;                  
00210     int reverse;                
00211     int isave;                  
00212     int i;                      
00213 };
00214 
00218 struct iosm_s {
00219 /*@owned@*/ /*@relnull@*/
00220     const char * path;          
00221 /*@owned@*/ /*@relnull@*/
00222     const char * lpath;         
00223 /*@owned@*/ /*@relnull@*/
00224     const char * opath;         
00225 /*@relnull@*/
00226     FD_t cfd;                   
00227 /*@relnull@*/
00228     FD_t rfd;                   
00229 /*@dependent@*/ /*@relnull@*/
00230     char * rdbuf;               
00231 /*@owned@*/ /*@relnull@*/
00232     char * rdb;                 
00233     size_t rdsize;              
00234     size_t rdlen;               
00235     size_t rdnb;                
00236     FD_t wfd;                   
00237 /*@dependent@*/ /*@relnull@*/
00238     char * wrbuf;               
00239 /*@owned@*/ /*@relnull@*/
00240     char * wrb;                 
00241     size_t wrsize;              
00242     size_t wrlen;               
00243     size_t wrnb;                
00244 /*@only@*/ /*@relnull@*/
00245     IOSMI_t iter;               
00246     int ix;                     
00247 /*@only@*/ /*@relnull@*/
00248     struct hardLink_s * links;  
00249 /*@only@*/ /*@relnull@*/
00250     struct hardLink_s * li;     
00251 /*@kept@*/ /*@null@*/
00252     unsigned int * archiveSize; 
00253 /*@kept@*/ /*@null@*/
00254     const char ** failedFile;   
00255 /*@shared@*/ /*@relnull@*/
00256     const char * subdir;        
00257 /*@unused@*/
00258     char subbuf[64];    /* XXX eliminate */
00259 /*@observer@*/ /*@relnull@*/
00260     const char * osuffix;       
00261 /*@observer@*/ /*@relnull@*/
00262     const char * nsuffix;       
00263 /*@shared@*/ /*@relnull@*/
00264     const char * suffix;        
00265     char sufbuf[64];    /* XXX eliminate */
00266 /*@only@*/ /*@null@*/
00267     unsigned short * dnlx;      
00268 /*@only@*/ /*@null@*/
00269     char * ldn;                 
00270     size_t ldnlen;              
00271     size_t ldnalloc;            
00272     int postpone;               
00273     int diskchecked;            
00274     int exists;                 
00275     int mkdirsdone;             
00276     size_t astriplen;           
00277     int rc;                     
00278     int commit;                 
00279     int repackaged;             
00280     int strict_erasures;        
00281     int multithreaded;          
00282     int adding;                 
00283     int debug;                  
00284     int nofdigests;             
00285     int nofcontexts;            
00286     iosmMapFlags mapFlags;      
00287     rpmuint32_t fdigestalgo;    
00288     rpmuint32_t digestlen;      
00289 /*@shared@*/ /*@relnull@*/
00290     const char * dirName;       
00291 /*@shared@*/ /*@relnull@*/
00292     const char * baseName;      
00293 /*@shared@*/ /*@relnull@*/
00294     const char * fdigest;       
00295 /*@shared@*/ /*@relnull@*/
00296     const unsigned char * digest;
00297 /*@dependent@*/ /*@observer@*/ /*@null@*/
00298     const char * fcontext;      
00300     rpmuint32_t fflags;         
00301     iosmFileAction action;      
00302     iosmFileStage goal;         
00303     iosmFileStage stage;        
00304     iosmFileStage nstage;       
00305     struct stat sb;             
00306     struct stat osb;            
00308     unsigned blksize;           
00309     int (*headerRead) (void * _iosm, struct stat *st)
00310         /*@modifies _iosm, st @*/;
00311     int (*headerWrite) (void * _iosm, struct stat *st)
00312         /*@modifies _iosm, st @*/;
00313     int (*trailerWrite) (void * _iosm)
00314         /*@modifies _iosm @*/;
00315 
00316 /*@null@*/
00317     char * lmtab;               
00318     size_t lmtablen;            
00319     size_t lmtaboff;            
00321     struct rpmop_s op_digest;   
00322 };
00323 #endif
00324 
00325 #ifdef __cplusplus
00326 extern "C" {
00327 #endif
00328 
00329 /*@-exportlocal@*/
00335 /*@observer@*/ const char * iosmFileStageString(iosmFileStage a)        /*@*/;
00336 
00342 /*@observer@*/ const char * iosmFileActionString(iosmFileAction a)      /*@*/;
00343 /*@=exportlocal@*/
00344 
00350 /*@only@*/
00351 char * iosmStrerror(int rc)
00352         /*@*/;
00353 
00354 #if defined(_IOSM_INTERNAL)
00355 
00359 /*@only@*/ IOSM_t newIOSM(void)
00360         /*@*/;
00361 
00367 /*@null@*/ IOSM_t freeIOSM(/*@only@*/ /*@null@*/ IOSM_t iosm)
00368         /*@modifies iosm @*/;
00369 #endif
00370 
00383 int iosmSetup(IOSM_t iosm, iosmFileStage goal, /*@null@*/ const char * afmt,
00384                 const void * _ts,
00385                 const void * _fi,
00386                 FD_t cfd,
00387                 /*@out@*/ /*@null@*/ unsigned int * archiveSize,
00388                 /*@out@*/ /*@null@*/ const char ** failedFile)
00389         /*@globals h_errno, fileSystem, internalState @*/
00390         /*@modifies iosm, _ts, _fi, cfd, *archiveSize, *failedFile,
00391                 fileSystem, internalState @*/;
00392 
00398 int iosmTeardown(IOSM_t iosm)
00399         /*@globals h_errno, fileSystem, internalState @*/
00400         /*@modifies iosm, fileSystem, internalState @*/;
00401 
00402 #if defined(_IOSM_INTERNAL)
00403 /*@-exportlocal@*/
00409 void * iosmGetTs(const IOSM_t iosm)
00410         /*@*/;
00411 
00417 void * iosmGetFi(/*@partial@*/ const IOSM_t iosm)
00418         /*@*/;
00419 
00424 int iosmMapPath(IOSM_t iosm)
00425         /*@modifies iosm @*/;
00426 
00431 int iosmMapAttrs(IOSM_t iosm)
00432         /*@modifies iosm @*/;
00433 /*@=exportlocal@*/
00434 
00438 extern int (*_iosmNext) (IOSM_t iosm, iosmFileStage nstage)
00439         /*@modifies iosm @*/;
00440 #endif
00441 
00447 int iosmFileActionSkipped(iosmFileAction action)
00448         /*@*/;
00449 
00456 int iosmNext(IOSM_t iosm, iosmFileStage nstage)
00457         /*@globals errno, h_errno, fileSystem, internalState @*/
00458         /*@modifies iosm, errno, fileSystem, internalState @*/;
00459 
00466 /*@-exportlocal@*/
00467 int iosmStage(/*@partial@*/ IOSM_t iosm, iosmFileStage stage)
00468         /*@globals errno, h_errno, fileSystem, internalState @*/
00469         /*@modifies iosm, errno, fileSystem, internalState @*/;
00470 /*@=exportlocal@*/
00471 
00472 #ifdef __cplusplus
00473 }
00474 #endif
00475 
00476 #endif  /* H_IOSM */