Main Page   Modules   Data Structures   File List   Data Fields   Globals   Related Pages  

lib/fsm.c

Go to the documentation of this file.
00001 
00006 #include "system.h"
00007 
00008 #include <rpmio_internal.h>
00009 #include <rpmlib.h>
00010 
00011 #include "cpio.h"
00012 #include "fsm.h"
00013 #include "rpmerr.h"
00014 
00015 #define _RPMFI_INTERNAL
00016 #include "rpmfi.h"
00017 #include "rpmte.h"
00018 #include "rpmts.h"
00019 
00020 #include "debug.h"
00021 
00022 /*@access FD_t @*/
00023 /*@access FSMI_t @*/
00024 /*@access FSM_t @*/
00025 
00026 /*@access rpmfi @*/
00027 /*@access rpmte @*/
00028 /*@access rpmts @*/
00029 
00030 #define alloca_strdup(_s)       strcpy(alloca(strlen(_s)+1), (_s))
00031 
00032 /*@unchecked@*/
00033 int _fsm_debug = 0;
00034 
00035 /* XXX Failure to remove is not (yet) cause for failure. */
00036 /*@-exportlocal -exportheadervar@*/
00037 /*@unchecked@*/
00038 int strict_erasures = 0;
00039 /*@=exportlocal =exportheadervar@*/
00040 
00041 rpmts fsmGetTs(const FSM_t fsm) {
00042     const FSMI_t iter = fsm->iter;
00043     /*@-compdef -refcounttrans -retexpose -usereleased @*/
00044     return (iter ? iter->ts : NULL);
00045     /*@=compdef =refcounttrans =retexpose =usereleased @*/
00046 }
00047 
00048 rpmfi fsmGetFi(const FSM_t fsm)
00049 {
00050     const FSMI_t iter = fsm->iter;
00051     /*@-compdef -refcounttrans -retexpose -usereleased @*/
00052     return (iter ? iter->fi : NULL);
00053     /*@=compdef =refcounttrans =retexpose =usereleased @*/
00054 }
00055 
00056 #define SUFFIX_RPMORIG  ".rpmorig"
00057 #define SUFFIX_RPMSAVE  ".rpmsave"
00058 #define SUFFIX_RPMNEW   ".rpmnew"
00059 
00068 static /*@only@*//*@null@*/
00069 const char * fsmFsPath(/*@special@*/ /*@null@*/ const FSM_t fsm,
00070                 /*@null@*/ const struct stat * st,
00071                 /*@null@*/ const char * subdir,
00072                 /*@null@*/ const char * suffix)
00073         /*@uses fsm->dirName, fsm->baseName */
00074         /*@*/
00075 {
00076     const char * s = NULL;
00077 
00078     if (fsm) {
00079         int nb;
00080         char * t;
00081         nb = strlen(fsm->dirName) +
00082             (st && !S_ISDIR(st->st_mode) ? (subdir ? strlen(subdir) : 0) : 0) +
00083             (st && !S_ISDIR(st->st_mode) ? (suffix ? strlen(suffix) : 0) : 0) +
00084             strlen(fsm->baseName) + 1;
00085 /*@-boundswrite@*/
00086         s = t = xmalloc(nb);
00087         t = stpcpy(t, fsm->dirName);
00088         if (st && !S_ISDIR(st->st_mode))
00089             if (subdir) t = stpcpy(t, subdir);
00090         t = stpcpy(t, fsm->baseName);
00091         if (st && !S_ISDIR(st->st_mode))
00092             if (suffix) t = stpcpy(t, suffix);
00093 /*@=boundswrite@*/
00094     }
00095     return s;
00096 }
00097 
00103 static /*@null@*/ void * mapFreeIterator(/*@only@*//*@null@*/ void * p)
00104         /*@globals fileSystem @*/
00105         /*@modifies fileSystem @*/
00106 {
00107     FSMI_t iter = p;
00108     if (iter) {
00109         iter->ts = rpmtsFree(iter->ts);
00110         iter->fi = rpmfiUnlink(iter->fi, "mapIterator");
00111     }
00112     return _free(p);
00113 }
00114 
00121 static void *
00122 mapInitIterator(rpmts ts, rpmfi fi)
00123         /*@modifies ts, fi @*/
00124 {
00125     FSMI_t iter = NULL;
00126 
00127     iter = xcalloc(1, sizeof(*iter));
00128     iter->ts = rpmtsLink(ts, "mapIterator");
00129     iter->fi = rpmfiLink(fi, "mapIterator");
00130     iter->reverse = (rpmteType(fi->te) == TR_REMOVED && fi->action != FA_COPYOUT);
00131     iter->i = (iter->reverse ? (fi->fc - 1) : 0);
00132     iter->isave = iter->i;
00133     return iter;
00134 }
00135 
00141 static int mapNextIterator(/*@null@*/ void * a)
00142         /*@*/
00143 {
00144     FSMI_t iter = a;
00145     int i = -1;
00146 
00147     if (iter) {
00148         const rpmfi fi = iter->fi;
00149         if (iter->reverse) {
00150             if (iter->i >= 0)   i = iter->i--;
00151         } else {
00152             if (iter->i < fi->fc)       i = iter->i++;
00153         }
00154         iter->isave = i;
00155     }
00156     return i;
00157 }
00158 
00161 /*@-boundsread@*/
00162 static int cpioStrCmp(const void * a, const void * b)
00163         /*@*/
00164 {
00165     const char * afn = *(const char **)a;
00166     const char * bfn = *(const char **)b;
00167 
00168     /* XXX Some 4+ year old rpm packages have basename only in payloads. */
00169 #ifdef  VERY_OLD_BUGGY_RPM_PACKAGES
00170     if (strchr(afn, '/') == NULL)
00171         bfn = strrchr(bfn, '/') + 1;
00172 #endif
00173 
00174     /* Match rpm-4.0 payloads with ./ prefixes. */
00175     if (afn[0] == '.' && afn[1] == '/') afn += 2;
00176     if (bfn[0] == '.' && bfn[1] == '/') bfn += 2;
00177 
00178     /* If either path is absolute, make it relative. */
00179     if (afn[0] == '/')  afn += 1;
00180     if (bfn[0] == '/')  bfn += 1;
00181 
00182     return strcmp(afn, bfn);
00183 }
00184 /*@=boundsread@*/
00185 
00192 /*@-boundsread@*/
00193 static int mapFind(/*@null@*/ FSMI_t iter, const char * fsmPath)
00194         /*@modifies iter @*/
00195 {
00196     int ix = -1;
00197 
00198     if (iter) {
00199         const rpmfi fi = iter->fi;
00200         if (fi && fi->fc > 0 && fi->apath && fsmPath && *fsmPath) {
00201             const char ** p = NULL;
00202 
00203 /*@-boundswrite@*/
00204             if (fi->apath != NULL)
00205                 p = bsearch(&fsmPath, fi->apath, fi->fc, sizeof(fsmPath),
00206                         cpioStrCmp);
00207 /*@=boundswrite@*/
00208             if (p) {
00209                 iter->i = p - fi->apath;
00210                 ix = mapNextIterator(iter);
00211             }
00212         }
00213     }
00214     return ix;
00215 }
00216 /*@=boundsread@*/
00217 
00221 typedef struct dnli_s {
00222     rpmfi fi;
00223 /*@only@*/ /*@null@*/
00224     char * active;
00225     int reverse;
00226     int isave;
00227     int i;
00228 } * DNLI_t;
00229 
00235 static /*@null@*/ void * dnlFreeIterator(/*@only@*//*@null@*/ const void * a)
00236         /*@modifies a @*/
00237 {
00238     if (a) {
00239         DNLI_t dnli = (void *)a;
00240         if (dnli->active) free(dnli->active);
00241     }
00242     return _free(a);
00243 }
00244 
00247 static inline int dnlCount(const DNLI_t dnli)
00248         /*@*/
00249 {
00250     return (dnli ? dnli->fi->dc : 0);
00251 }
00252 
00255 static inline int dnlIndex(const DNLI_t dnli)
00256         /*@*/
00257 {
00258     return (dnli ? dnli->isave : -1);
00259 }
00260 
00267 /*@-boundsread@*/
00268 /*@-usereleased@*/
00269 static /*@only@*/ void * dnlInitIterator(/*@special@*/ const FSM_t fsm,
00270                 int reverse)
00271         /*@uses fsm->iter @*/ 
00272         /*@*/
00273 {
00274     rpmfi fi = fsmGetFi(fsm);
00275     DNLI_t dnli;
00276     int i, j;
00277 
00278     if (fi == NULL)
00279         return NULL;
00280     dnli = xcalloc(1, sizeof(*dnli));
00281     dnli->fi = fi;
00282     dnli->reverse = reverse;
00283     /*@-branchstate@*/
00284     dnli->i = (reverse ? fi->dc : 0);
00285     /*@=branchstate@*/
00286 
00287     if (fi->dc) {
00288         dnli->active = xcalloc(fi->dc, sizeof(*dnli->active));
00289 
00290         /* Identify parent directories not skipped. */
00291 /*@-boundswrite@*/
00292         for (i = 0; i < fi->fc; i++)
00293             if (!XFA_SKIPPING(fi->actions[i])) dnli->active[fi->dil[i]] = 1;
00294 /*@=boundswrite@*/
00295 
00296         /* Exclude parent directories that are explicitly included. */
00297         for (i = 0; i < fi->fc; i++) {
00298             int dil, dnlen, bnlen;
00299 
00300             if (!S_ISDIR(fi->fmodes[i]))
00301                 continue;
00302 
00303             dil = fi->dil[i];
00304             dnlen = strlen(fi->dnl[dil]);
00305             bnlen = strlen(fi->bnl[i]);
00306 
00307             for (j = 0; j < fi->dc; j++) {
00308                 const char * dnl;
00309                 int jlen;
00310 
00311                 if (!dnli->active[j] || j == dil)
00312                     /*@innercontinue@*/ continue;
00313                 dnl = fi->dnl[j];
00314                 jlen = strlen(dnl);
00315                 if (jlen != (dnlen+bnlen+1))
00316                     /*@innercontinue@*/ continue;
00317                 if (strncmp(dnl, fi->dnl[dil], dnlen))
00318                     /*@innercontinue@*/ continue;
00319                 if (strncmp(dnl+dnlen, fi->bnl[i], bnlen))
00320                     /*@innercontinue@*/ continue;
00321                 if (dnl[dnlen+bnlen] != '/' || dnl[dnlen+bnlen+1] != '\0')
00322                     /*@innercontinue@*/ continue;
00323                 /* This directory is included in the package. */
00324 /*@-boundswrite@*/
00325                 dnli->active[j] = 0;
00326 /*@=boundswrite@*/
00327                 /*@innerbreak@*/ break;
00328             }
00329         }
00330 
00331         /* Print only once per package. */
00332         if (!reverse) {
00333             j = 0;
00334             for (i = 0; i < fi->dc; i++) {
00335                 if (!dnli->active[i]) continue;
00336                 if (j == 0) {
00337                     j = 1;
00338                     rpmMessage(RPMMESS_DEBUG,
00339         _("========== Directories not explictly included in package:\n"));
00340                 }
00341                 rpmMessage(RPMMESS_DEBUG, _("%10d %s\n"), i, fi->dnl[i]);
00342             }
00343             if (j)
00344                 rpmMessage(RPMMESS_DEBUG, "==========\n");
00345         }
00346     }
00347     return dnli;
00348 }
00349 /*@=usereleased@*/
00350 /*@=boundsread@*/
00351 
00357 /*@-boundsread@*/
00358 static /*@observer@*/ const char * dnlNextIterator(/*@null@*/ DNLI_t dnli)
00359         /*@modifies dnli @*/
00360 {
00361     const char * dn = NULL;
00362 
00363     if (dnli) {
00364         rpmfi fi = dnli->fi;
00365         int i = -1;
00366 
00367         if (dnli->active)
00368         do {
00369             i = (!dnli->reverse ? dnli->i++ : --dnli->i);
00370         } while (i >= 0 && i < fi->dc && !dnli->active[i]);
00371 
00372         if (i >= 0 && i < fi->dc)
00373             dn = fi->dnl[i];
00374         else
00375             i = -1;
00376         dnli->isave = i;
00377     }
00378     return dn;
00379 }
00380 /*@=boundsread@*/
00381 
00387 /*@-boundsread@*/
00388 static int saveHardLink(/*@special@*/ /*@partial@*/ FSM_t fsm)
00389         /*@uses fsm->links, fsm->ix, fsm->sb, fsm->goal, fsm->nsuffix @*/
00390         /*@defines fsm->li @*/
00391         /*@releases fsm->path @*/
00392         /*@globals fileSystem, internalState @*/
00393         /*@modifies fsm, fileSystem, internalState @*/
00394 {
00395     struct stat * st = &fsm->sb;
00396     int rc = 0;
00397     int ix = -1;
00398     int j;
00399 
00400     /* Find hard link set. */
00401     /*@-branchstate@*/
00402     for (fsm->li = fsm->links; fsm->li; fsm->li = fsm->li->next) {
00403         if (fsm->li->sb.st_ino == st->st_ino && fsm->li->sb.st_dev == st->st_dev)
00404             break;
00405     }
00406     /*@=branchstate@*/
00407 
00408     /* New hard link encountered, add new link to set. */
00409 /*@-boundswrite@*/
00410     /*@-branchstate@*/
00411     if (fsm->li == NULL) {
00412         fsm->li = xcalloc(1, sizeof(*fsm->li));
00413         fsm->li->next = NULL;
00414         fsm->li->sb = *st;      /* structure assignment */
00415         fsm->li->nlink = st->st_nlink;
00416         fsm->li->linkIndex = fsm->ix;
00417         fsm->li->createdPath = -1;
00418 
00419         fsm->li->filex = xcalloc(st->st_nlink, sizeof(fsm->li->filex[0]));
00420         memset(fsm->li->filex, -1, (st->st_nlink * sizeof(fsm->li->filex[0])));
00421         fsm->li->nsuffix = xcalloc(st->st_nlink, sizeof(*fsm->li->nsuffix));
00422 
00423         if (fsm->goal == FSM_PKGBUILD)
00424             fsm->li->linksLeft = st->st_nlink;
00425         if (fsm->goal == FSM_PKGINSTALL)
00426             fsm->li->linksLeft = 0;
00427 
00428         /*@-kepttrans@*/
00429         fsm->li->next = fsm->links;
00430         /*@=kepttrans@*/
00431         fsm->links = fsm->li;
00432     }
00433     /*@=branchstate@*/
00434 /*@=boundswrite@*/
00435 
00436     if (fsm->goal == FSM_PKGBUILD) --fsm->li->linksLeft;
00437 /*@-boundswrite@*/
00438     fsm->li->filex[fsm->li->linksLeft] = fsm->ix;
00439     /*@-observertrans -dependenttrans@*/
00440     fsm->li->nsuffix[fsm->li->linksLeft] = fsm->nsuffix;
00441     /*@=observertrans =dependenttrans@*/
00442 /*@=boundswrite@*/
00443     if (fsm->goal == FSM_PKGINSTALL) fsm->li->linksLeft++;
00444 
00445     if (fsm->goal == FSM_PKGBUILD)
00446         return (fsm->li->linksLeft > 0);
00447 
00448     if (fsm->goal != FSM_PKGINSTALL)
00449         return 0;
00450 
00451     if (!(st->st_size || fsm->li->linksLeft == st->st_nlink))
00452         return 1;
00453 
00454     /* Here come the bits, time to choose a non-skipped file name. */
00455     {   rpmfi fi = fsmGetFi(fsm);
00456 
00457         for (j = fsm->li->linksLeft - 1; j >= 0; j--) {
00458             ix = fsm->li->filex[j];
00459             if (ix < 0 || XFA_SKIPPING(fi->actions[ix]))
00460                 continue;
00461             break;
00462         }
00463     }
00464 
00465     /* Are all links skipped or not encountered yet? */
00466     if (ix < 0 || j < 0)
00467         return 1;       /* XXX W2DO? */
00468 
00469     /* Save the non-skipped file name and map index. */
00470     fsm->li->linkIndex = j;
00471     fsm->path = _free(fsm->path);
00472     fsm->ix = ix;
00473     rc = fsmStage(fsm, FSM_MAP);
00474     return rc;
00475 }
00476 /*@=boundsread@*/
00477 
00483 static /*@null@*/ void * freeHardLink(/*@only@*/ /*@null@*/ struct hardLink_s * li)
00484         /*@modifies li @*/
00485 {
00486     if (li) {
00487         li->nsuffix = _free(li->nsuffix);       /* XXX elements are shared */
00488         li->filex = _free(li->filex);
00489     }
00490     return _free(li);
00491 }
00492 
00493 FSM_t newFSM(void)
00494 {
00495     FSM_t fsm = xcalloc(1, sizeof(*fsm));
00496     return fsm;
00497 }
00498 
00499 FSM_t freeFSM(FSM_t fsm)
00500 {
00501     if (fsm) {
00502         fsm->path = _free(fsm->path);
00503         /*@-branchstate@*/
00504         while ((fsm->li = fsm->links) != NULL) {
00505             fsm->links = fsm->li->next;
00506             fsm->li->next = NULL;
00507             fsm->li = freeHardLink(fsm->li);
00508         }
00509         /*@=branchstate@*/
00510         fsm->dnlx = _free(fsm->dnlx);
00511         fsm->ldn = _free(fsm->ldn);
00512         fsm->iter = mapFreeIterator(fsm->iter);
00513     }
00514     return _free(fsm);
00515 }
00516 
00517 int fsmSetup(FSM_t fsm, fileStage goal,
00518                 const rpmts ts, const rpmfi fi, FD_t cfd,
00519                 unsigned int * archiveSize, const char ** failedFile)
00520 {
00521     size_t pos = 0;
00522     int rc, ec = 0;
00523 
00524     fsm->goal = goal;
00525     if (cfd) {
00526         /*@-type@*/ /* FIX: cast? */
00527         fsm->cfd = fdLink(cfd, "persist (fsm)");
00528         /*@=type@*/
00529         pos = fdGetCpioPos(fsm->cfd);
00530         fdSetCpioPos(fsm->cfd, 0);
00531     }
00532     fsm->iter = mapInitIterator(ts, fi);
00533 
00534     if (fsm->goal == FSM_PKGINSTALL || fsm->goal == FSM_PKGBUILD) {
00535         void * ptr;
00536         fi->archivePos = 0;
00537         ptr = rpmtsNotify(ts, fi->te,
00538                 RPMCALLBACK_INST_START, fi->archivePos, fi->archiveSize);
00539     }
00540 
00541 /*@-boundswrite@*/
00542     /*@-assignexpose@*/
00543     fsm->archiveSize = archiveSize;
00544     if (fsm->archiveSize)
00545         *fsm->archiveSize = 0;
00546     fsm->failedFile = failedFile;
00547     if (fsm->failedFile)
00548         *fsm->failedFile = NULL;
00549     /*@=assignexpose@*/
00550 /*@=boundswrite@*/
00551 
00552     memset(fsm->sufbuf, 0, sizeof(fsm->sufbuf));
00553     if (fsm->goal == FSM_PKGINSTALL) {
00554         if (ts && rpmtsGetTid(ts) > 0)
00555             sprintf(fsm->sufbuf, ";%08x", (unsigned)rpmtsGetTid(ts));
00556     }
00557 
00558     ec = fsm->rc = 0;
00559     rc = fsmStage(fsm, FSM_CREATE);
00560     if (rc && !ec) ec = rc;
00561 
00562     rc = fsmStage(fsm, fsm->goal);
00563     if (rc && !ec) ec = rc;
00564 
00565 /*@-boundswrite@*/
00566     if (fsm->archiveSize && ec == 0)
00567         *fsm->archiveSize = (fdGetCpioPos(fsm->cfd) - pos);
00568 /*@=boundswrite@*/
00569 
00570    return ec;
00571 }
00572 
00573 int fsmTeardown(FSM_t fsm)
00574 {
00575     int rc = fsm->rc;
00576 
00577     if (!rc)
00578         rc = fsmStage(fsm, FSM_DESTROY);
00579 
00580     fsm->iter = mapFreeIterator(fsm->iter);
00581     if (fsm->cfd) {
00582         /*@-type@*/ /* FIX: cast? */
00583         fsm->cfd = fdFree(fsm->cfd, "persist (fsm)");
00584         /*@=type@*/
00585         fsm->cfd = NULL;
00586     }
00587     fsm->failedFile = NULL;
00588     return rc;
00589 }
00590 
00591 int fsmMapPath(FSM_t fsm)
00592 {
00593     rpmfi fi = fsmGetFi(fsm);   /* XXX const except for fstates */
00594     int rc = 0;
00595     int i;
00596 
00597     fsm->osuffix = NULL;
00598     fsm->nsuffix = NULL;
00599     fsm->astriplen = 0;
00600     fsm->action = FA_UNKNOWN;
00601     fsm->mapFlags = 0;
00602 
00603     i = fsm->ix;
00604     if (fi && i >= 0 && i < fi->fc) {
00605 
00606 /*@-boundsread@*/
00607         fsm->astriplen = fi->astriplen;
00608         fsm->action = (fi->actions ? fi->actions[i] : fi->action);
00609         fsm->fflags = (fi->fflags ? fi->fflags[i] : fi->flags);
00610         fsm->mapFlags = (fi->fmapflags ? fi->fmapflags[i] : fi->mapflags);
00611 
00612         /* src rpms have simple base name in payload. */
00613         fsm->dirName = fi->dnl[fi->dil[i]];
00614         fsm->baseName = fi->bnl[i];
00615 /*@=boundsread@*/
00616 
00617 /*@-boundswrite@*/
00618         switch (fsm->action) {
00619         case FA_SKIP:
00620             break;
00621         case FA_SKIPMULTILIB:   /* XXX RPMFILE_STATE_MULTILIB? */
00622             break;
00623         case FA_UNKNOWN:
00624             break;
00625 
00626         case FA_COPYOUT:
00627             break;
00628         case FA_COPYIN:
00629         case FA_CREATE:
00630 assert(rpmteType(fi->te) == TR_ADDED);
00631             break;
00632 
00633         case FA_SKIPNSTATE:
00634             if (fi->fstates && rpmteType(fi->te) == TR_ADDED)
00635                 fi->fstates[i] = RPMFILE_STATE_NOTINSTALLED;
00636             break;
00637 
00638         case FA_SKIPNETSHARED:
00639             if (fi->fstates && rpmteType(fi->te) == TR_ADDED)
00640                 fi->fstates[i] = RPMFILE_STATE_NETSHARED;
00641             break;
00642 
00643         case FA_BACKUP:
00644             if (!(fsm->fflags & RPMFILE_GHOST)) /* XXX Don't if %ghost file. */
00645             switch (rpmteType(fi->te)) {
00646             case TR_ADDED:
00647                 fsm->osuffix = SUFFIX_RPMORIG;
00648                 /*@innerbreak@*/ break;
00649             case TR_REMOVED:
00650                 fsm->osuffix = SUFFIX_RPMSAVE;
00651                 /*@innerbreak@*/ break;
00652             }
00653             break;
00654 
00655         case FA_ALTNAME:
00656 assert(rpmteType(fi->te) == TR_ADDED);
00657             if (!(fsm->fflags & RPMFILE_GHOST)) /* XXX Don't if %ghost file. */
00658                 fsm->nsuffix = SUFFIX_RPMNEW;
00659             break;
00660 
00661         case FA_SAVE:
00662 assert(rpmteType(fi->te) == TR_ADDED);
00663             if (!(fsm->fflags & RPMFILE_GHOST)) /* XXX Don't if %ghost file. */
00664                 fsm->osuffix = SUFFIX_RPMSAVE;
00665             break;
00666         case FA_ERASE:
00667             assert(rpmteType(fi->te) == TR_REMOVED);
00668             /*
00669              * XXX TODO: %ghost probably shouldn't be removed, but that changes
00670              * legacy rpm behavior.
00671              */
00672             break;
00673         default:
00674             break;
00675         }
00676 /*@=boundswrite@*/
00677 
00678         if ((fsm->mapFlags & CPIO_MAP_PATH) || fsm->nsuffix) {
00679             const struct stat * st = &fsm->sb;
00680             fsm->path = _free(fsm->path);
00681             fsm->path = fsmFsPath(fsm, st, fsm->subdir,
00682                 (fsm->suffix ? fsm->suffix : fsm->nsuffix));
00683         }
00684     }
00685     return rc;
00686 }
00687 
00688 int fsmMapAttrs(FSM_t fsm)
00689 {
00690     struct stat * st = &fsm->sb;
00691     rpmfi fi = fsmGetFi(fsm);
00692     int i = fsm->ix;
00693 
00694     if (fi && i >= 0 && i < fi->fc) {
00695         mode_t perms =
00696                 (S_ISDIR(st->st_mode) ? fi->dperms : fi->fperms);
00697         mode_t finalMode =
00698                 (fi->fmodes ? fi->fmodes[i] : perms);
00699         uid_t finalUid =
00700                 (fi->fuids ? fi->fuids[i] : fi->uid); /* XXX chmod u-s */
00701         gid_t finalGid =
00702                 (fi->fgids ? fi->fgids[i] : fi->gid); /* XXX chmod g-s */
00703         dev_t finalRdev =
00704                 (fi->frdevs ? fi->frdevs[i] : 0);
00705         int_32 finalMtime =
00706                 (fi->fmtimes ? fi->fmtimes[i] : 0);
00707 
00708         if (fsm->mapFlags & CPIO_MAP_MODE)
00709             st->st_mode = (st->st_mode & S_IFMT) | (finalMode & ~S_IFMT);
00710         if (fsm->mapFlags & CPIO_MAP_TYPE) {
00711             st->st_mode = (st->st_mode & ~S_IFMT) | (finalMode & S_IFMT);
00712             if ((S_ISCHR(st->st_mode) || S_ISBLK(st->st_mode))
00713             && st->st_nlink == 0)
00714                 st->st_nlink = 1;
00715             st->st_rdev = finalRdev;
00716             st->st_mtime = finalMtime;
00717         }
00718         if (fsm->mapFlags & CPIO_MAP_UID)
00719             st->st_uid = finalUid;
00720         if (fsm->mapFlags & CPIO_MAP_GID)
00721             st->st_gid = finalGid;
00722 
00723         {   rpmts ts = fsmGetTs(fsm);
00724 
00725             if (ts != NULL && !(rpmtsFlags(ts) & RPMTRANS_FLAG_NOMD5)) {
00726                 fsm->fmd5sum = (fi->fmd5s ? fi->fmd5s[i] : NULL);
00727                 fsm->md5sum = (fi->md5s ? (fi->md5s + (16 * i)) : NULL);
00728             } else {
00729                 fsm->fmd5sum = NULL;
00730                 fsm->md5sum = NULL;
00731             }
00732         }
00733 
00734     }
00735     return 0;
00736 }
00737 
00743 static int expandRegular(/*@special@*/ FSM_t fsm)
00744         /*@uses fsm->sb @*/
00745         /*@globals fileSystem, internalState @*/
00746         /*@modifies fsm, fileSystem, internalState @*/
00747 {
00748     const struct stat * st = &fsm->sb;
00749     int left = st->st_size;
00750     int rc = 0;
00751 
00752     rc = fsmStage(fsm, FSM_WOPEN);
00753     if (rc)
00754         goto exit;
00755 
00756     if (st->st_size > 0 && (fsm->fmd5sum || fsm->md5sum))
00757         fdInitDigest(fsm->wfd, PGPHASHALGO_MD5, 0);
00758 
00759     while (left) {
00760 
00761         fsm->wrlen = (left > fsm->wrsize ? fsm->wrsize : left);
00762         rc = fsmStage(fsm, FSM_DREAD);
00763         if (rc)
00764             goto exit;
00765 
00766         rc = fsmStage(fsm, FSM_WRITE);
00767         if (rc)
00768             goto exit;
00769 
00770         left -= fsm->wrnb;
00771 
00772         /* don't call this with fileSize == fileComplete */
00773         if (!rc && left)
00774             (void) fsmStage(fsm, FSM_NOTIFY);
00775     }
00776 
00777     if (st->st_size > 0 && (fsm->fmd5sum || fsm->md5sum)) {
00778         void * md5sum = NULL;
00779         int asAscii = (fsm->md5sum == NULL ? 1 : 0);
00780 
00781         (void) Fflush(fsm->wfd);
00782         fdFiniDigest(fsm->wfd, PGPHASHALGO_MD5, &md5sum, NULL, asAscii);
00783 
00784         if (md5sum == NULL) {
00785             rc = CPIOERR_MD5SUM_MISMATCH;
00786             goto exit;
00787         }
00788 
00789         if (fsm->md5sum != NULL) {
00790             if (memcmp(md5sum, fsm->md5sum, 16))
00791                 rc = CPIOERR_MD5SUM_MISMATCH;
00792         } else {
00793             if (strcmp(md5sum, fsm->fmd5sum))
00794                 rc = CPIOERR_MD5SUM_MISMATCH;
00795         }
00796         md5sum = _free(md5sum);
00797     }
00798 
00799 exit:
00800     (void) fsmStage(fsm, FSM_WCLOSE);
00801     return rc;
00802 }
00803 
00810 static int writeFile(/*@special@*/ FSM_t fsm, int writeData)
00811         /*@uses fsm->path, fsm->opath, fsm->sb, fsm->osb, fsm->cfd @*/
00812         /*@globals fileSystem, internalState @*/
00813         /*@modifies fsm, fileSystem, internalState @*/
00814 {
00815     const char * path = fsm->path;
00816     const char * opath = fsm->opath;
00817     struct stat * st = &fsm->sb;
00818     struct stat * ost = &fsm->osb;
00819     char * symbuf = NULL;
00820     int left;
00821     int xx;
00822     int rc;
00823 
00824     st->st_size = (writeData ? ost->st_size : 0);
00825 
00826     /*@-branchstate@*/
00827     if (S_ISDIR(st->st_mode)) {
00828         st->st_size = 0;
00829     } else if (S_ISLNK(st->st_mode)) {
00830         /*
00831          * While linux puts the size of a symlink in the st_size field,
00832          * I don't think that's a specified standard.
00833          */
00834         /* XXX NUL terminated result in fsm->rdbuf, len in fsm->rdnb. */
00835         rc = fsmStage(fsm, FSM_READLINK);
00836         if (rc) goto exit;
00837         st->st_size = fsm->rdnb;
00838         symbuf = alloca_strdup(fsm->rdbuf);     /* XXX save readlink return. */
00839     }
00840     /*@=branchstate@*/
00841 
00842     if (fsm->mapFlags & CPIO_MAP_ABSOLUTE) {
00843 /*@-compdef@*/ /* FIX: dirName/baseName annotations ? */
00844 /*@-boundswrite@*/
00845         int nb = strlen(fsm->dirName) + strlen(fsm->baseName) + sizeof(".");
00846         char * t = alloca(nb);
00847         *t = '\0';
00848         fsm->path = t;
00849         if (fsm->mapFlags & CPIO_MAP_ADDDOT)
00850             *t++ = '.';
00851         t = stpcpy( stpcpy(t, fsm->dirName), fsm->baseName);
00852 /*@=boundswrite@*/
00853 /*@=compdef@*/
00854     } else if (fsm->mapFlags & CPIO_MAP_PATH) {
00855         rpmfi fi = fsmGetFi(fsm);
00856         fsm->path =
00857             (fi->apath ? fi->apath[fsm->ix] + fi->striplen : fi->bnl[fsm->ix]);
00858     }
00859 
00860     rc = fsmStage(fsm, FSM_HWRITE);
00861     fsm->path = path;
00862     if (rc) goto exit;
00863 
00864     if (writeData && S_ISREG(st->st_mode)) {
00865 #if HAVE_MMAP
00866         char * rdbuf = NULL;
00867         void * mapped = (void *)-1;
00868         size_t nmapped;
00869 #endif
00870 
00871         rc = fsmStage(fsm, FSM_ROPEN);
00872         if (rc) goto exit;
00873 
00874         /* XXX unbuffered mmap generates *lots* of fdio debugging */
00875 #if HAVE_MMAP
00876         nmapped = 0;
00877         mapped = mmap(NULL, st->st_size, PROT_READ, MAP_SHARED, Fileno(fsm->rfd), 0);
00878         if (mapped != (void *)-1) {
00879             rdbuf = fsm->rdbuf;
00880             fsm->rdbuf = (char *) mapped;
00881             fsm->rdlen = nmapped = st->st_size;
00882 #if defined(MADV_DONTNEED)
00883             xx = madvise(mapped, nmapped, MADV_DONTNEED);
00884 #endif
00885         }
00886 #endif
00887 
00888         left = st->st_size;
00889 
00890         while (left) {
00891 #if HAVE_MMAP
00892           if (mapped != (void *)-1) {
00893             fsm->rdnb = nmapped;
00894           } else
00895 #endif
00896           {
00897             fsm->rdlen = (left > fsm->rdsize ? fsm->rdsize : left),
00898             rc = fsmStage(fsm, FSM_READ);
00899             if (rc) goto exit;
00900           }
00901 
00902             /* XXX DWRITE uses rdnb for I/O length. */
00903             rc = fsmStage(fsm, FSM_DWRITE);
00904             if (rc) goto exit;
00905 
00906             left -= fsm->wrnb;
00907         }
00908 
00909 #if HAVE_MMAP
00910         if (mapped != (void *)-1) {
00911             xx = msync(mapped, nmapped, MS_ASYNC);
00912 #if defined(MADV_DONTNEED)
00913             xx = madvise(mapped, nmapped, MADV_DONTNEED);
00914 #endif
00915             /*@-noeffect@*/ xx = munmap(mapped, nmapped) /*@=noeffect@*/;
00916             fsm->rdbuf = rdbuf;
00917         }
00918 #endif
00919 
00920     } else if (writeData && S_ISLNK(st->st_mode)) {
00921         /* XXX DWRITE uses rdnb for I/O length. */
00922 /*@-boundswrite@*/
00923         strcpy(fsm->rdbuf, symbuf);     /* XXX restore readlink buffer. */
00924 /*@=boundswrite@*/
00925         fsm->rdnb = strlen(symbuf);
00926         rc = fsmStage(fsm, FSM_DWRITE);
00927         if (rc) goto exit;
00928     }
00929 
00930     rc = fsmStage(fsm, FSM_PAD);
00931     if (rc) goto exit;
00932 
00933     rc = 0;
00934 
00935 exit:
00936     if (fsm->rfd)
00937         (void) fsmStage(fsm, FSM_RCLOSE);
00938     /*@-dependenttrans@*/
00939     fsm->opath = opath;
00940     fsm->path = path;
00941     /*@=dependenttrans@*/
00942     return rc;
00943 }
00944 
00950 static int writeLinkedFile(/*@special@*/ FSM_t fsm)
00951         /*@uses fsm->path, fsm->nsuffix, fsm->ix, fsm->li, fsm->failedFile @*/
00952         /*@globals fileSystem, internalState @*/
00953         /*@modifies fsm, fileSystem, internalState @*/
00954 {
00955     const char * path = fsm->path;
00956     const char * nsuffix = fsm->nsuffix;
00957     int iterIndex = fsm->ix;
00958     int ec = 0;
00959     int rc;
00960     int i;
00961 
00962     fsm->path = NULL;
00963     fsm->nsuffix = NULL;
00964     fsm->ix = -1;
00965 
00966 /*@-boundswrite@*/
00967     for (i = fsm->li->nlink - 1; i >= 0; i--) {
00968 
00969         if (fsm->li->filex[i] < 0) continue;
00970 
00971         fsm->ix = fsm->li->filex[i];
00972         rc = fsmStage(fsm, FSM_MAP);
00973 
00974         /* Write data after last link. */
00975         rc = writeFile(fsm, (i == 0));
00976         if (fsm->failedFile && rc != 0 && *fsm->failedFile == NULL) {
00977             ec = rc;
00978             *fsm->failedFile = xstrdup(fsm->path);
00979         }
00980 
00981         fsm->path = _free(fsm->path);
00982         fsm->li->filex[i] = -1;
00983     }
00984 /*@=boundswrite@*/
00985 
00986     fsm->ix = iterIndex;
00987     fsm->nsuffix = nsuffix;
00988     fsm->path = path;
00989     return ec;
00990 }
00991 
00997 /*@-boundsread@*/
00998 static int fsmMakeLinks(/*@special@*/ FSM_t fsm)
00999         /*@uses fsm->path, fsm->opath, fsm->nsuffix, fsm->ix, fsm->li @*/
01000         /*@globals fileSystem, internalState @*/
01001         /*@modifies fsm, fileSystem, internalState @*/
01002 {
01003     const char * path = fsm->path;
01004     const char * opath = fsm->opath;
01005     const char * nsuffix = fsm->nsuffix;
01006     int iterIndex = fsm->ix;
01007     int ec = 0;
01008     int rc;
01009     int i;
01010 
01011     fsm->path = NULL;
01012     fsm->opath = NULL;
01013     fsm->nsuffix = NULL;
01014     fsm->ix = -1;
01015 
01016     fsm->ix = fsm->li->filex[fsm->li->createdPath];
01017     rc = fsmStage(fsm, FSM_MAP);
01018     fsm->opath = fsm->path;
01019     fsm->path = NULL;
01020     /*@-branchstate@*/
01021     for (i = 0; i < fsm->li->nlink; i++) {
01022         if (fsm->li->filex[i] < 0) continue;
01023         if (fsm->li->createdPath == i) continue;
01024 
01025         fsm->ix = fsm->li->filex[i];
01026         fsm->path = _free(fsm->path);
01027         rc = fsmStage(fsm, FSM_MAP);
01028         if (XFA_SKIPPING(fsm->action)) continue;
01029 
01030         rc = fsmStage(fsm, FSM_VERIFY);
01031         if (!rc) continue;
01032         if (rc != CPIOERR_LSTAT_FAILED) break;
01033 
01034         /* XXX link(fsm->opath, fsm->path) */
01035         rc = fsmStage(fsm, FSM_LINK);
01036         if (fsm->failedFile && rc != 0 && *fsm->failedFile == NULL) {
01037             ec = rc;
01038 /*@-boundswrite@*/
01039             *fsm->failedFile = xstrdup(fsm->path);
01040 /*@=boundswrite@*/
01041         }
01042 
01043         fsm->li->linksLeft--;
01044     }
01045     /*@=branchstate@*/
01046     fsm->path = _free(fsm->path);
01047     fsm->opath = _free(fsm->opath);
01048 
01049     fsm->ix = iterIndex;
01050     fsm->nsuffix = nsuffix;
01051     fsm->path = path;
01052     fsm->opath = opath;
01053     return ec;
01054 }
01055 /*@=boundsread@*/
01056 
01062 static int fsmCommitLinks(/*@special@*/ FSM_t fsm)
01063         /*@uses fsm->path, fsm->nsuffix, fsm->ix, fsm->sb,
01064                 fsm->li, fsm->links @*/
01065         /*@globals fileSystem, internalState @*/
01066         /*@modifies fsm, fileSystem, internalState @*/
01067 {
01068     const char * path = fsm->path;
01069     const char * nsuffix = fsm->nsuffix;
01070     int iterIndex = fsm->ix;
01071     struct stat * st = &fsm->sb;
01072     int rc = 0;
01073     int i;
01074 
01075     fsm->path = NULL;
01076     fsm->nsuffix = NULL;
01077     fsm->ix = -1;
01078 
01079     /*@-branchstate@*/
01080     for (fsm->li = fsm->links; fsm->li; fsm->li = fsm->li->next) {
01081         if (fsm->li->sb.st_ino == st->st_ino && fsm->li->sb.st_dev == st->st_dev)
01082             break;
01083     }
01084     /*@=branchstate@*/
01085 
01086 /*@-boundswrite@*/
01087     for (i = 0; i < fsm->li->nlink; i++) {
01088         if (fsm->li->filex[i] < 0) continue;
01089         fsm->ix = fsm->li->filex[i];
01090         rc = fsmStage(fsm, FSM_MAP);
01091         if (!XFA_SKIPPING(fsm->action))
01092             rc = fsmStage(fsm, FSM_COMMIT);
01093         fsm->path = _free(fsm->path);
01094         fsm->li->filex[i] = -1;
01095     }
01096 /*@=boundswrite@*/
01097 
01098     fsm->ix = iterIndex;
01099     fsm->nsuffix = nsuffix;
01100     fsm->path = path;
01101     return rc;
01102 }
01103 
01109 static int fsmRmdirs(/*@special@*/ FSM_t fsm)
01110         /*@uses fsm->path, fsm->dnlx, fsm->ldn, fsm->rdbuf, fsm->iter @*/
01111         /*@globals fileSystem, internalState @*/
01112         /*@modifies fsm, fileSystem, internalState @*/
01113 {
01114     const char * path = fsm->path;
01115     void * dnli = dnlInitIterator(fsm, 1);
01116     char * dn = fsm->rdbuf;
01117     int dc = dnlCount(dnli);
01118     int rc = 0;
01119 
01120     fsm->path = NULL;
01121 /*@-boundswrite@*/
01122     dn[0] = '\0';
01123     /*@-observertrans -dependenttrans@*/
01124     if (fsm->ldn != NULL && fsm->dnlx != NULL)
01125     while ((fsm->path = dnlNextIterator(dnli)) != NULL) {
01126         int dnlen = strlen(fsm->path);
01127         char * te;
01128 
01129         dc = dnlIndex(dnli);
01130         if (fsm->dnlx[dc] < 1 || fsm->dnlx[dc] >= dnlen)
01131             continue;
01132 
01133         /* Copy to avoid const on fsm->path. */
01134         te = stpcpy(dn, fsm->path) - 1;
01135         fsm->path = dn;
01136 
01137         /* Remove generated directories. */
01138         /*@-usereleased@*/ /* LCL: te used after release? */
01139         do {
01140             if (*te == '/') {
01141                 *te = '\0';
01142                 rc = fsmStage(fsm, FSM_RMDIR);
01143                 *te = '/';
01144             }
01145             if (rc)
01146                 /*@innerbreak@*/ break;
01147             te--;
01148         } while ((te - fsm->path) > fsm->dnlx[dc]);
01149         /*@=usereleased@*/
01150     }
01151 /*@=boundswrite@*/
01152     dnli = dnlFreeIterator(dnli);
01153     /*@=observertrans =dependenttrans@*/
01154 
01155     fsm->path = path;
01156     return rc;
01157 }
01158 
01164 static int fsmMkdirs(/*@special@*/ FSM_t fsm)
01165         /*@uses fsm->path, fsm->sb, fsm->osb, fsm->rdbuf, fsm->iter,
01166                 fsm->ldn, fsm->ldnlen, fsm->ldnalloc @*/
01167         /*@defines fsm->dnlx, fsm->ldn @*/
01168         /*@globals fileSystem, internalState @*/
01169         /*@modifies fsm, fileSystem, internalState @*/
01170 {
01171     struct stat * st = &fsm->sb;
01172     struct stat * ost = &fsm->osb;
01173     const char * path = fsm->path;
01174     mode_t st_mode = st->st_mode;
01175     void * dnli = dnlInitIterator(fsm, 0);
01176     char * dn = fsm->rdbuf;
01177     int dc = dnlCount(dnli);
01178     int rc = 0;
01179     int i;
01180 
01181     fsm->path = NULL;
01182 
01183 /*@-boundswrite@*/
01184     dn[0] = '\0';
01185     fsm->dnlx = (dc ? xcalloc(dc, sizeof(*fsm->dnlx)) : NULL);
01186     /*@-observertrans -dependenttrans@*/
01187     if (fsm->dnlx != NULL)
01188     while ((fsm->path = dnlNextIterator(dnli)) != NULL) {
01189         int dnlen = strlen(fsm->path);
01190         char * te;
01191 
01192         dc = dnlIndex(dnli);
01193         if (dc < 0) continue;
01194         fsm->dnlx[dc] = dnlen;
01195         if (dnlen <= 1)
01196             continue;
01197 
01198         /*@-compdef -nullpass@*/        /* FIX: fsm->ldn not defined ??? */
01199         if (dnlen <= fsm->ldnlen && !strcmp(fsm->path, fsm->ldn))
01200             continue;
01201         /*@=compdef =nullpass@*/
01202 
01203         /* Copy to avoid const on fsm->path. */
01204         (void) stpcpy(dn, fsm->path);
01205         fsm->path = dn;
01206 
01207         /* Assume '/' directory exists, "mkdir -p" for others if non-existent */
01208         for (i = 1, te = dn + 1; *te != '\0'; te++, i++) {
01209             if (*te != '/')
01210                 /*@innercontinue@*/ continue;
01211 
01212             *te = '\0';
01213 
01214             /* Already validated? */
01215             /*@-usedef -compdef -nullpass -nullderef@*/
01216             if (i < fsm->ldnlen &&
01217                 (fsm->ldn[i] == '/' || fsm->ldn[i] == '\0') &&
01218                 !strncmp(fsm->path, fsm->ldn, i))
01219             {
01220                 *te = '/';
01221                 /* Move pre-existing path marker forward. */
01222                 fsm->dnlx[dc] = (te - dn);
01223                 /*@innercontinue@*/ continue;
01224             }
01225             /*@=usedef =compdef =nullpass =nullderef@*/
01226 
01227             /* Validate next component of path. */
01228             rc = fsmStage(fsm, FSM_LSTAT);
01229             *te = '/';
01230 
01231             /* Directory already exists? */
01232             if (rc == 0 && S_ISDIR(ost->st_mode)) {
01233                 /* Move pre-existing path marker forward. */
01234                 fsm->dnlx[dc] = (te - dn);
01235             } else if (rc == CPIOERR_LSTAT_FAILED) {
01236                 rpmfi fi = fsmGetFi(fsm);
01237                 *te = '\0';
01238                 st->st_mode = S_IFDIR | (fi->dperms & 07777);
01239                 rc = fsmStage(fsm, FSM_MKDIR);
01240                 if (!rc)
01241                     rpmMessage(RPMMESS_DEBUG,
01242                         _("%s directory created with perms %04o.\n"),
01243                         fsm->path, (unsigned)(st->st_mode & 07777));
01244                 *te = '/';
01245             }
01246             if (rc)
01247                 /*@innerbreak@*/ break;
01248         }
01249         if (rc) break;
01250 
01251         /* Save last validated path. */
01252 /*@-compdef@*/ /* FIX: ldn/path annotations ? */
01253         if (fsm->ldnalloc < (dnlen + 1)) {
01254             fsm->ldnalloc = dnlen + 100;
01255             fsm->ldn = xrealloc(fsm->ldn, fsm->ldnalloc);
01256         }
01257         if (fsm->ldn != NULL) { /* XXX can't happen */
01258             strcpy(fsm->ldn, fsm->path);
01259             fsm->ldnlen = dnlen;
01260         }
01261 /*@=compdef@*/
01262     }
01263 /*@=boundswrite@*/
01264     dnli = dnlFreeIterator(dnli);
01265     /*@=observertrans =dependenttrans@*/
01266 
01267     fsm->path = path;
01268     st->st_mode = st_mode;              /* XXX restore st->st_mode */
01269 /*@-compdef@*/ /* FIX: ldn/path annotations ? */
01270     return rc;
01271 /*@=compdef@*/
01272 }
01273 
01274 #ifdef  NOTYET
01275 
01280 static int fsmStat(FSM_t fsm)
01281 {
01282     int saveerrno = errno;
01283     int rc = 0;
01284 
01285     if (fsm->path != NULL) {
01286         int saveernno = errno;
01287         rc = fsmStage(fsm, (!(fsm->mapFlags & CPIO_FOLLOW_SYMLINKS)
01288                         ? FSM_LSTAT : FSM_STAT));
01289         if (rc == CPIOERR_LSTAT_FAILED && errno == ENOENT) {
01290             errno = saveerrno;
01291             rc = 0;
01292             fsm->exists = 0;
01293         } else if (rc == 0) {
01294             fsm->exists = 1;
01295         }
01296     } else {
01297         /* Skip %ghost files on build. */
01298         fsm->exists = 0;
01299     }
01300     return rc;
01301 }
01302 #endif
01303 
01304 #define IS_DEV_LOG(_x)  \
01305         ((_x) != NULL && strlen(_x) >= (sizeof("/dev/log")-1) && \
01306         !strncmp((_x), "/dev/log", sizeof("/dev/log")-1) && \
01307         ((_x)[sizeof("/dev/log")-1] == '\0' || \
01308          (_x)[sizeof("/dev/log")-1] == ';'))
01309 
01310 /*@-boundsread@*/
01311 /*@-compmempass@*/
01312 int fsmStage(FSM_t fsm, fileStage stage)
01313 {
01314 #ifdef  UNUSED
01315     fileStage prevStage = fsm->stage;
01316     const char * const prev = fileStageString(prevStage);
01317 #endif
01318     static int modulo = 4;
01319     const char * const cur = fileStageString(stage);
01320     struct stat * st = &fsm->sb;
01321     struct stat * ost = &fsm->osb;
01322     int saveerrno = errno;
01323     int rc = fsm->rc;
01324     size_t left;
01325     int i;
01326 
01327 #define _fafilter(_a)   \
01328     (!((_a) == FA_CREATE || (_a) == FA_ERASE || (_a) == FA_COPYIN || (_a) == FA_COPYOUT) \
01329         ? fileActionString(_a) : "")
01330 
01331     if (stage & FSM_DEAD) {
01332         /* do nothing */
01333     } else if (stage & FSM_INTERNAL) {
01334         if (_fsm_debug && !(stage & FSM_SYSCALL))
01335             rpmMessage(RPMMESS_DEBUG, " %8s %06o%3d (%4d,%4d)%10d %s %s\n",
01336                 cur,
01337                 (unsigned)st->st_mode, (int)st->st_nlink,
01338                 (int)st->st_uid, (int)st->st_gid, (int)st->st_size,
01339                 (fsm->path ? fsm->path : ""),
01340                 _fafilter(fsm->action));
01341     } else {
01342         fsm->stage = stage;
01343         if (_fsm_debug || !(stage & FSM_VERBOSE))
01344             rpmMessage(RPMMESS_DEBUG, "%-8s  %06o%3d (%4d,%4d)%10d %s %s\n",
01345                 cur,
01346                 (unsigned)st->st_mode, (int)st->st_nlink,
01347                 (int)st->st_uid, (int)st->st_gid, (int)st->st_size,
01348                 (fsm->path ? fsm->path + fsm->astriplen : ""),
01349                 _fafilter(fsm->action));
01350     }
01351 #undef  _fafilter
01352 
01353     /*@-branchstate@*/
01354     switch (stage) {
01355     case FSM_UNKNOWN:
01356         break;
01357     case FSM_PKGINSTALL:
01358         while (1) {
01359             /* Clean fsm, free'ing memory. Read next archive header. */
01360             rc = fsmStage(fsm, FSM_INIT);
01361 
01362             /* Exit on end-of-payload. */
01363             if (rc == CPIOERR_HDR_TRAILER) {
01364                 rc = 0;
01365                 /*@loopbreak@*/ break;
01366             }
01367 
01368             /* Exit on error. */
01369             if (rc) {
01370                 fsm->postpone = 1;
01371                 (void) fsmStage(fsm, FSM_UNDO);
01372                 /*@loopbreak@*/ break;
01373             }
01374 
01375             /* Extract file from archive. */
01376             rc = fsmStage(fsm, FSM_PROCESS);
01377             if (rc) {
01378                 (void) fsmStage(fsm, FSM_UNDO);
01379                 /*@loopbreak@*/ break;
01380             }
01381 
01382             /* Notify on success. */
01383             (void) fsmStage(fsm, FSM_NOTIFY);
01384 
01385             rc = fsmStage(fsm, FSM_FINI);
01386             if (rc) {
01387                 /*@loopbreak@*/ break;
01388             }
01389         }
01390         break;
01391     case FSM_PKGERASE:
01392     case FSM_PKGCOMMIT:
01393         while (1) {
01394             /* Clean fsm, free'ing memory. */
01395             rc = fsmStage(fsm, FSM_INIT);
01396 
01397             /* Exit on end-of-payload. */
01398             if (rc == CPIOERR_HDR_TRAILER) {
01399                 rc = 0;
01400                 /*@loopbreak@*/ break;
01401             }
01402 
01403             /* Rename/erase next item. */
01404             if (fsmStage(fsm, FSM_FINI))
01405                 /*@loopbreak@*/ break;
01406         }
01407         break;
01408     case FSM_PKGBUILD:
01409         while (1) {
01410 
01411             rc = fsmStage(fsm, FSM_INIT);
01412 
01413             /* Exit on end-of-payload. */
01414             if (rc == CPIOERR_HDR_TRAILER) {
01415                 rc = 0;
01416                 /*@loopbreak@*/ break;
01417             }
01418 
01419             /* Exit on error. */
01420             if (rc) {
01421                 fsm->postpone = 1;
01422                 (void) fsmStage(fsm, FSM_UNDO);
01423                 /*@loopbreak@*/ break;
01424             }
01425 
01426             /* Copy file into archive. */
01427             rc = fsmStage(fsm, FSM_PROCESS);
01428             if (rc) {
01429                 (void) fsmStage(fsm, FSM_UNDO);
01430                 /*@loopbreak@*/ break;
01431             }
01432 
01433             /* Notify on success. */
01434             (void) fsmStage(fsm, FSM_NOTIFY);
01435 
01436             if (fsmStage(fsm, FSM_FINI))
01437                 /*@loopbreak@*/ break;
01438         }
01439 
01440         /* Flush partial sets of hard linked files. */
01441         if (!(fsm->mapFlags & CPIO_ALL_HARDLINKS)) {
01442             int nlink, j;
01443             while ((fsm->li = fsm->links) != NULL) {
01444                 fsm->links = fsm->li->next;
01445                 fsm->li->next = NULL;
01446 
01447                 /* Re-calculate link count for archive header. */
01448                 for (j = -1, nlink = 0, i = 0; i < fsm->li->nlink; i++) {
01449                     if (fsm->li->filex[i] < 0)
01450                         /*@innercontinue@*/ continue;
01451                     nlink++;
01452                     if (j == -1) j = i;
01453                 }
01454                 /* XXX force the contents out as well. */
01455 /*@-boundswrite@*/
01456                 if (j != 0) {
01457                     fsm->li->filex[0] = fsm->li->filex[j];
01458                     fsm->li->filex[j] = -1;
01459                 }
01460 /*@=boundswrite@*/
01461                 fsm->li->sb.st_nlink = nlink;
01462 
01463                 fsm->sb = fsm->li->sb;  /* structure assignment */
01464                 fsm->osb = fsm->sb;     /* structure assignment */
01465 
01466                 if (!rc) rc = writeLinkedFile(fsm);
01467 
01468                 fsm->li = freeHardLink(fsm->li);
01469             }
01470         }
01471 
01472         if (!rc)
01473             rc = fsmStage(fsm, FSM_TRAILER);
01474 
01475         break;
01476     case FSM_CREATE:
01477         {   rpmts ts = fsmGetTs(fsm);
01478 #define _tsmask (RPMTRANS_FLAG_PKGCOMMIT | RPMTRANS_FLAG_COMMIT)
01479             fsm->commit = ((ts && (rpmtsFlags(ts) & _tsmask) &&
01480                         fsm->goal != FSM_PKGCOMMIT) ? 0 : 1);
01481 #undef _tsmask
01482         }
01483         fsm->path = _free(fsm->path);
01484         fsm->opath = _free(fsm->opath);
01485         fsm->dnlx = _free(fsm->dnlx);
01486 
01487         fsm->ldn = _free(fsm->ldn);
01488         fsm->ldnalloc = fsm->ldnlen = 0;
01489 
01490         fsm->rdsize = fsm->wrsize = 0;
01491         fsm->rdbuf = fsm->rdb = _free(fsm->rdb);
01492         fsm->wrbuf = fsm->wrb = _free(fsm->wrb);
01493         if (fsm->goal == FSM_PKGINSTALL || fsm->goal == FSM_PKGBUILD) {
01494             fsm->rdsize = 8 * BUFSIZ;
01495             fsm->rdbuf = fsm->rdb = xmalloc(fsm->rdsize);
01496             fsm->wrsize = 8 * BUFSIZ;
01497             fsm->wrbuf = fsm->wrb = xmalloc(fsm->wrsize);
01498         }
01499 
01500         fsm->mkdirsdone = 0;
01501         fsm->ix = -1;
01502         fsm->links = NULL;
01503         fsm->li = NULL;
01504         /*@-mods@*/
01505         errno = 0;      /* XXX get rid of EBADF */
01506         /*@=mods@*/
01507 
01508         /* Detect and create directories not explicitly in package. */
01509         if (fsm->goal == FSM_PKGINSTALL) {
01510             rc = fsmStage(fsm, FSM_MKDIRS);
01511             if (!rc) fsm->mkdirsdone = 1;
01512         }
01513 
01514         break;
01515     case FSM_INIT:
01516         fsm->path = _free(fsm->path);
01517         fsm->postpone = 0;
01518         fsm->diskchecked = fsm->exists = 0;
01519         fsm->subdir = NULL;
01520         fsm->suffix = (fsm->sufbuf[0] != '\0' ? fsm->sufbuf : NULL);
01521         fsm->action = FA_UNKNOWN;
01522         fsm->osuffix = NULL;
01523         fsm->nsuffix = NULL;
01524 
01525         if (fsm->goal == FSM_PKGINSTALL) {
01526             /* Read next header from payload, checking for end-of-payload. */
01527             rc = fsmStage(fsm, FSM_NEXT);
01528         }
01529         if (rc) break;
01530 
01531         /* Identify mapping index. */
01532         fsm->ix = ((fsm->goal == FSM_PKGINSTALL)
01533                 ? mapFind(fsm->iter, fsm->path) : mapNextIterator(fsm->iter));
01534 
01535         /* Detect end-of-loop and/or mapping error. */
01536         if (fsm->ix < 0) {
01537             if (fsm->goal == FSM_PKGINSTALL) {
01538 #if 0
01539                 rpmMessage(RPMMESS_WARNING,
01540                     _("archive file %s was not found in header file list\n"),
01541                         fsm->path);
01542 #endif
01543 /*@-boundswrite@*/
01544                 if (fsm->failedFile && *fsm->failedFile == NULL)
01545                     *fsm->failedFile = xstrdup(fsm->path);
01546 /*@=boundswrite@*/
01547                 rc = CPIOERR_UNMAPPED_FILE;
01548             } else {
01549                 rc = CPIOERR_HDR_TRAILER;
01550             }
01551             break;
01552         }
01553 
01554         /* On non-install, mode must be known so that dirs don't get suffix. */
01555         if (fsm->goal != FSM_PKGINSTALL) {
01556             rpmfi fi = fsmGetFi(fsm);
01557             st->st_mode = fi->fmodes[fsm->ix];
01558         }
01559 
01560         /* Generate file path. */
01561         rc = fsmStage(fsm, FSM_MAP);
01562         if (rc) break;
01563 
01564         /* Perform lstat/stat for disk file. */
01565 #ifdef  NOTYET
01566         rc = fsmStat(fsm);
01567 #else
01568         if (fsm->path != NULL &&
01569             !(fsm->goal == FSM_PKGINSTALL && S_ISREG(st->st_mode)))
01570         {
01571             rc = fsmStage(fsm, (!(fsm->mapFlags & CPIO_FOLLOW_SYMLINKS)
01572                         ? FSM_LSTAT : FSM_STAT));
01573             if (rc == CPIOERR_LSTAT_FAILED && errno == ENOENT) {
01574                 /*@-mods@*/
01575                 errno = saveerrno;
01576                 /*@=mods@*/
01577                 rc = 0;
01578                 fsm->exists = 0;
01579             } else if (rc == 0) {
01580                 fsm->exists = 1;
01581             }
01582         } else {
01583             /* Skip %ghost files on build. */
01584             fsm->exists = 0;
01585         }
01586 #endif
01587         fsm->diskchecked = 1;
01588         if (rc) break;
01589 
01590         /* On non-install, the disk file stat is what's remapped. */
01591 /*@-boundswrite@*/
01592         if (fsm->goal != FSM_PKGINSTALL)
01593             *st = *ost;                 /* structure assignment */
01594 /*@=boundswrite@*/
01595 
01596         /* Remap file perms, owner, and group. */
01597         rc = fsmMapAttrs(fsm);
01598         if (rc) break;
01599 
01600         fsm->postpone = XFA_SKIPPING(fsm->action);
01601         if (fsm->goal == FSM_PKGINSTALL || fsm->goal == FSM_PKGBUILD) {
01602             /*@-evalorder@*/ /* FIX: saveHardLink can modify fsm */
01603             if (!S_ISDIR(st->st_mode) && st->st_nlink > 1)
01604                 fsm->postpone = saveHardLink(fsm);
01605             /*@=evalorder@*/
01606         }
01607         break;
01608     case FSM_PRE:
01609         break;
01610     case FSM_MAP:
01611         rc = fsmMapPath(fsm);
01612         break;
01613     case FSM_MKDIRS:
01614         rc = fsmMkdirs(fsm);
01615         break;
01616     case FSM_RMDIRS:
01617         if (fsm->dnlx)
01618             rc = fsmRmdirs(fsm);
01619         break;
01620     case FSM_PROCESS:
01621         if (fsm->postpone) {
01622             if (fsm->goal == FSM_PKGINSTALL)
01623                 rc = fsmStage(fsm, FSM_EAT);
01624             break;
01625         }
01626 
01627         if (fsm->goal == FSM_PKGBUILD) {
01628             if (fsm->fflags & RPMFILE_GHOST) /* XXX Don't if %ghost file. */
01629                 break;
01630             if (!S_ISDIR(st->st_mode) && st->st_nlink > 1) {
01631                 struct hardLink_s * li, * prev;
01632 
01633 if (!(fsm->mapFlags & CPIO_ALL_HARDLINKS)) break;
01634                 rc = writeLinkedFile(fsm);
01635                 if (rc) break;  /* W2DO? */
01636 
01637                 for (li = fsm->links, prev = NULL; li; prev = li, li = li->next)
01638                      if (li == fsm->li)
01639                         /*@loopbreak@*/ break;
01640 
01641                 if (prev == NULL)
01642                     fsm->links = fsm->li->next;
01643                 else
01644                     prev->next = fsm->li->next;
01645                 fsm->li->next = NULL;
01646                 fsm->li = freeHardLink(fsm->li);
01647             } else {
01648                 rc = writeFile(fsm, 1);
01649             }
01650             break;
01651         }
01652 
01653         if (fsm->goal != FSM_PKGINSTALL)
01654             break;
01655 
01656         if (S_ISREG(st->st_mode)) {
01657             const char * path = fsm->path;
01658             if (fsm->osuffix)
01659                 fsm->path = fsmFsPath(fsm, st, NULL, NULL);
01660             rc = fsmStage(fsm, FSM_VERIFY);
01661 
01662             if (rc == 0 && fsm->osuffix) {
01663                 const char * opath = fsm->opath;
01664                 fsm->opath = fsm->path;
01665                 fsm->path = fsmFsPath(fsm, st, NULL, fsm->osuffix);
01666                 rc = fsmStage(fsm, FSM_RENAME);
01667                 if (!rc)
01668                     rpmMessage(RPMMESS_WARNING,
01669                         _("%s saved as %s\n"), fsm->opath, fsm->path);
01670                 fsm->path = _free(fsm->path);
01671                 fsm->opath = opath;
01672             }
01673 
01674             /*@-dependenttrans@*/
01675             fsm->path = path;
01676             /*@=dependenttrans@*/
01677             if (rc != CPIOERR_LSTAT_FAILED) return rc;
01678             rc = expandRegular(fsm);
01679         } else if (S_ISDIR(st->st_mode)) {
01680             mode_t st_mode = st->st_mode;
01681             rc = fsmStage(fsm, FSM_VERIFY);
01682             if (rc == CPIOERR_LSTAT_FAILED) {
01683                 st->st_mode &= ~07777;          /* XXX abuse st->st_mode */
01684                 st->st_mode |=  00700;
01685                 rc = fsmStage(fsm, FSM_MKDIR);
01686                 st->st_mode = st_mode;          /* XXX restore st->st_mode */
01687             }
01688         } else if (S_ISLNK(st->st_mode)) {
01689             const char * opath = fsm->opath;
01690 
01691             if ((st->st_size + 1) > fsm->rdsize) {
01692                 rc = CPIOERR_HDR_SIZE;
01693                 break;
01694             }
01695 
01696             fsm->wrlen = st->st_size;
01697             rc = fsmStage(fsm, FSM_DREAD);
01698             if (!rc && fsm->rdnb != fsm->wrlen)
01699                 rc = CPIOERR_READ_FAILED;
01700             if (rc) break;
01701 
01702 /*@-boundswrite@*/
01703             fsm->wrbuf[st->st_size] = '\0';
01704 /*@=boundswrite@*/
01705             /* XXX symlink(fsm->opath, fsm->path) */
01706             /*@-dependenttrans@*/
01707             fsm->opath = fsm->wrbuf;
01708             /*@=dependenttrans@*/
01709             rc = fsmStage(fsm, FSM_VERIFY);
01710             if (rc == CPIOERR_LSTAT_FAILED)
01711                 rc = fsmStage(fsm, FSM_SYMLINK);
01712             fsm->opath = opath;         /* XXX restore fsm->path */
01713         } else if (S_ISFIFO(st->st_mode)) {
01714             mode_t st_mode = st->st_mode;
01715             /* This mimics cpio S_ISSOCK() behavior but probably isnt' right */
01716             rc = fsmStage(fsm, FSM_VERIFY);
01717             if (rc == CPIOERR_LSTAT_FAILED) {
01718                 st->st_mode = 0000;             /* XXX abuse st->st_mode */
01719                 rc = fsmStage(fsm, FSM_MKFIFO);
01720                 st->st_mode = st_mode;  /* XXX restore st->st_mode */
01721             }
01722         } else if (S_ISCHR(st->st_mode) ||
01723                    S_ISBLK(st->st_mode) ||
01724     /*@-unrecog@*/ S_ISSOCK(st->st_mode) /*@=unrecog@*/)
01725         {
01726             rc = fsmStage(fsm, FSM_VERIFY);
01727             if (rc == CPIOERR_LSTAT_FAILED)
01728                 rc = fsmStage(fsm, FSM_MKNOD);
01729         } else {
01730             /* XXX Special case /dev/log, which shouldn't be packaged anyways */
01731             if (!IS_DEV_LOG(fsm->path))
01732                 rc = CPIOERR_UNKNOWN_FILETYPE;
01733         }
01734         if (!S_ISDIR(st->st_mode) && st->st_nlink > 1) {
01735             fsm->li->createdPath = fsm->li->linkIndex;
01736             rc = fsmMakeLinks(fsm);
01737         }
01738         break;
01739     case FSM_POST:
01740         break;
01741     case FSM_MKLINKS:
01742         rc = fsmMakeLinks(fsm);
01743         break;
01744     case FSM_NOTIFY:            /* XXX move from fsm to psm -> tsm */
01745         if (fsm->goal == FSM_PKGINSTALL || fsm->goal == FSM_PKGBUILD) {
01746             rpmts ts = fsmGetTs(fsm);
01747             rpmfi fi = fsmGetFi(fsm);
01748             void * ptr;
01749             unsigned int archivePos = fdGetCpioPos(fsm->cfd);
01750             if (archivePos > fi->archivePos) {
01751                 fi->archivePos = archivePos;
01752                 ptr = rpmtsNotify(ts, fi->te, RPMCALLBACK_INST_PROGRESS,
01753                         fi->archivePos, fi->archiveSize);
01754             }
01755         }
01756         break;
01757     case FSM_UNDO:
01758         if (fsm->postpone)
01759             break;
01760         if (fsm->goal == FSM_PKGINSTALL) {
01761             (void) fsmStage(fsm,
01762                 (S_ISDIR(st->st_mode) ? FSM_RMDIR : FSM_UNLINK));
01763 
01764 #ifdef  NOTYET  /* XXX remove only dirs just created, not all. */
01765             if (fsm->dnlx)
01766                 (void) fsmStage(fsm, FSM_RMDIRS);
01767 #endif
01768             /*@-mods@*/
01769             errno = saveerrno;
01770             /*@=mods@*/
01771         }
01772 /*@-boundswrite@*/
01773         if (fsm->failedFile && *fsm->failedFile == NULL)
01774             *fsm->failedFile = xstrdup(fsm->path);
01775 /*@=boundswrite@*/
01776         break;
01777     case FSM_FINI:
01778         if (!fsm->postpone && fsm->commit) {
01779             if (fsm->goal == FSM_PKGINSTALL)
01780                 rc = ((!S_ISDIR(st->st_mode) && st->st_nlink > 1)
01781                         ? fsmCommitLinks(fsm) : fsmStage(fsm, FSM_COMMIT));
01782             if (fsm->goal == FSM_PKGCOMMIT)
01783                 rc = fsmStage(fsm, FSM_COMMIT);
01784             if (fsm->goal == FSM_PKGERASE)
01785                 rc = fsmStage(fsm, FSM_COMMIT);
01786         }
01787         fsm->path = _free(fsm->path);
01788         fsm->opath = _free(fsm->opath);
01789 /*@-boundswrite@*/
01790         memset(st, 0, sizeof(*st));
01791         memset(ost, 0, sizeof(*ost));
01792 /*@=boundswrite@*/
01793         break;
01794     case FSM_COMMIT:
01795         /* Rename pre-existing modified or unmanaged file. */
01796         if (fsm->osuffix && fsm->diskchecked &&
01797           (fsm->exists || (fsm->goal == FSM_PKGINSTALL && S_ISREG(st->st_mode))))
01798         {
01799             const char * opath = fsm->opath;
01800             const char * path = fsm->path;
01801             fsm->opath = fsmFsPath(fsm, st, NULL, NULL);
01802             fsm->path = fsmFsPath(fsm, st, NULL, fsm->osuffix);
01803             rc = fsmStage(fsm, FSM_RENAME);
01804             if (!rc) {
01805                 rpmMessage(RPMMESS_WARNING, _("%s saved as %s\n"),
01806                                 fsm->opath, fsm->path);
01807             }
01808             fsm->path = _free(fsm->path);
01809             fsm->path = path;
01810             fsm->opath = _free(fsm->opath);
01811             fsm->opath = opath;
01812         }
01813 
01814         /* Remove erased files. */
01815         if (fsm->goal == FSM_PKGERASE) {
01816             if (fsm->action == FA_ERASE) {
01817                 rpmfi fi = fsmGetFi(fsm);
01818                 if (S_ISDIR(st->st_mode)) {
01819                     rc = fsmStage(fsm, FSM_RMDIR);
01820                     if (!rc) break;
01821                     switch (errno) {
01822                     case ENOENT: /* XXX rmdir("/") linux 2.2.x kernel hack */
01823                     case ENOTEMPTY:
01824         /* XXX make sure that build side permits %missingok on directories. */
01825                         if (fsm->fflags & RPMFILE_MISSINGOK)
01826                             /*@innerbreak@*/ break;
01827 
01828                         /* XXX common error message. */
01829                         rpmError(
01830                             (strict_erasures ? RPMERR_RMDIR : RPMDEBUG_RMDIR),
01831                             _("%s rmdir of %s failed: Directory not empty\n"), 
01832                                 rpmfiTypeString(fi), fsm->path);
01833                         /*@innerbreak@*/ break;
01834                     default:
01835                         rpmError(
01836                             (strict_erasures ? RPMERR_RMDIR : RPMDEBUG_RMDIR),
01837                                 _("%s rmdir of %s failed: %s\n"),
01838                                 rpmfiTypeString(fi), fsm->path, strerror(errno));
01839                         /*@innerbreak@*/ break;
01840                     }
01841                 } else {
01842                     rc = fsmStage(fsm, FSM_UNLINK);
01843                     if (!rc) break;
01844                     if (!(errno == ENOENT && (fsm->fflags & RPMFILE_MISSINGOK)))
01845                         rpmError(
01846                             (strict_erasures ? RPMERR_UNLINK : RPMDEBUG_UNLINK),
01847                                 _("%s unlink of %s failed: %s\n"),
01848                                 rpmfiTypeString(fi), fsm->path, strerror(errno));
01849                 }
01850             }
01851             /* XXX Failure to remove is not (yet) cause for failure. */
01852             if (!strict_erasures) rc = 0;
01853             break;
01854         }
01855 
01856         /* XXX Special case /dev/log, which shouldn't be packaged anyways */
01857         if (!S_ISSOCK(st->st_mode) && !IS_DEV_LOG(fsm->path)) {
01858             /* Rename temporary to final file name. */
01859             if (!S_ISDIR(st->st_mode) &&
01860                 (fsm->subdir || fsm->suffix || fsm->nsuffix))
01861             {
01862                 fsm->opath = fsm->path;
01863                 fsm->path = fsmFsPath(fsm, st, NULL, fsm->nsuffix);
01864                 rc = fsmStage(fsm, FSM_RENAME);
01865                 if (!rc && fsm->nsuffix) {
01866                     const char * opath = fsmFsPath(fsm, st, NULL, NULL);
01867                     rpmMessage(RPMMESS_WARNING, _("%s created as %s\n"),
01868                                 (opath ? opath : ""), fsm->path);
01869                     opath = _free(opath);
01870                 }
01871                 fsm->opath = _free(fsm->opath);
01872             }
01873             if (S_ISLNK(st->st_mode)) {
01874                 if (!rc && !getuid())
01875                     rc = fsmStage(fsm, FSM_LCHOWN);
01876             } else {
01877                 if (!rc && !getuid())
01878                     rc = fsmStage(fsm, FSM_CHOWN);
01879                 if (!rc)
01880                     rc = fsmStage(fsm, FSM_CHMOD);
01881                 if (!rc) {
01882                     time_t mtime = st->st_mtime;
01883                     rpmfi fi = fsmGetFi(fsm);
01884                     if (fi->fmtimes)
01885                         st->st_mtime = fi->fmtimes[fsm->ix];
01886                     rc = fsmStage(fsm, FSM_UTIME);
01887                     st->st_mtime = mtime;
01888                 }
01889             }
01890         }
01891 
01892         /* Notify on success. */
01893         if (!rc)                rc = fsmStage(fsm, FSM_NOTIFY);
01894         else if (fsm->failedFile && *fsm->failedFile == NULL) {
01895 /*@-boundswrite@*/
01896             *fsm->failedFile = fsm->path;
01897 /*@=boundswrite@*/
01898             fsm->path = NULL;
01899         }
01900         break;
01901     case FSM_DESTROY:
01902         fsm->path = _free(fsm->path);
01903 
01904         /* Check for hard links missing from payload. */
01905         while ((fsm->li = fsm->links) != NULL) {
01906             fsm->links = fsm->li->next;
01907             fsm->li->next = NULL;
01908             if (fsm->goal == FSM_PKGINSTALL &&
01909                         fsm->commit && fsm->li->linksLeft)
01910             {
01911                 for (i = 0 ; i < fsm->li->linksLeft; i++) {
01912                     if (fsm->li->filex[i] < 0)
01913                         /*@innercontinue@*/ continue;
01914                     rc = CPIOERR_MISSING_HARDLINK;
01915                     if (fsm->failedFile && *fsm->failedFile == NULL) {
01916                         fsm->ix = fsm->li->filex[i];
01917                         if (!fsmStage(fsm, FSM_MAP)) {
01918 /*@-boundswrite@*/
01919                             *fsm->failedFile = fsm->path;
01920 /*@=boundswrite@*/
01921                             fsm->path = NULL;
01922                         }
01923                     }
01924                     /*@loopbreak@*/ break;
01925                 }
01926             }
01927             if (fsm->goal == FSM_PKGBUILD &&
01928                 (fsm->mapFlags & CPIO_ALL_HARDLINKS))
01929             {
01930                 rc = CPIOERR_MISSING_HARDLINK;
01931             }
01932             fsm->li = freeHardLink(fsm->li);
01933         }
01934         fsm->ldn = _free(fsm->ldn);
01935         fsm->ldnalloc = fsm->ldnlen = 0;
01936         fsm->rdbuf = fsm->rdb = _free(fsm->rdb);
01937         fsm->wrbuf = fsm->wrb = _free(fsm->wrb);
01938         break;
01939     case FSM_VERIFY:
01940         if (fsm->diskchecked && !fsm->exists) {
01941             rc = CPIOERR_LSTAT_FAILED;
01942             break;
01943         }
01944         if (S_ISREG(st->st_mode)) {
01945             char * path = alloca(strlen(fsm->path) + sizeof("-RPMDELETE"));
01946 /*@-boundswrite@*/
01947             (void) stpcpy( stpcpy(path, fsm->path), "-RPMDELETE");
01948 /*@=boundswrite@*/
01949             /*
01950              * XXX HP-UX (and other os'es) don't permit unlink on busy
01951              * XXX files.
01952              */
01953             fsm->opath = fsm->path;
01954             fsm->path = path;
01955             rc = fsmStage(fsm, FSM_RENAME);
01956             if (!rc)
01957                     (void) fsmStage(fsm, FSM_UNLINK);
01958             else
01959                     rc = CPIOERR_UNLINK_FAILED;
01960             fsm->path = fsm->opath;
01961             fsm->opath = NULL;
01962             return (rc ? rc : CPIOERR_LSTAT_FAILED);    /* XXX HACK */
01963             /*@notreached@*/ break;
01964         } else if (S_ISDIR(st->st_mode)) {
01965             if (S_ISDIR(ost->st_mode))          return 0;
01966             if (S_ISLNK(ost->st_mode)) {
01967                 rc = fsmStage(fsm, FSM_STAT);
01968                 if (rc == CPIOERR_STAT_FAILED && errno == ENOENT) rc = 0;
01969                 if (rc) break;
01970                 /*@-mods@*/
01971                 errno = saveerrno;
01972                 /*@=mods@*/
01973                 if (S_ISDIR(ost->st_mode))      return 0;
01974             }
01975         } else if (S_ISLNK(st->st_mode)) {
01976             if (S_ISLNK(ost->st_mode)) {
01977         /* XXX NUL terminated result in fsm->rdbuf, len in fsm->rdnb. */
01978                 rc = fsmStage(fsm, FSM_READLINK);
01979                 /*@-mods@*/
01980                 errno = saveerrno;
01981                 /*@=mods@*/
01982                 if (rc) break;
01983                 if (!strcmp(fsm->opath, fsm->rdbuf))    return 0;
01984             }
01985         } else if (S_ISFIFO(st->st_mode)) {
01986             if (S_ISFIFO(ost->st_mode))         return 0;
01987         } else if (S_ISCHR(st->st_mode) || S_ISBLK(st->st_mode)) {
01988             if ((S_ISCHR(ost->st_mode) || S_ISBLK(ost->st_mode)) &&
01989                 (ost->st_rdev == st->st_rdev))  return 0;
01990         } else if (S_ISSOCK(st->st_mode)) {
01991             if (S_ISSOCK(ost->st_mode))         return 0;
01992         }
01993             /* XXX shouldn't do this with commit/undo. */
01994         rc = 0;
01995         if (fsm->stage == FSM_PROCESS) rc = fsmStage(fsm, FSM_UNLINK);
01996         if (rc == 0)    rc = CPIOERR_LSTAT_FAILED;
01997         return (rc ? rc : CPIOERR_LSTAT_FAILED);        /* XXX HACK */
01998         /*@notreached@*/ break;
01999 
02000     case FSM_UNLINK:
02001         rc = Unlink(fsm->path);
02002         if (_fsm_debug && (stage & FSM_SYSCALL))
02003             rpmMessage(RPMMESS_DEBUG, " %8s (%s) %s\n", cur,
02004                 fsm->path, (rc < 0 ? strerror(errno) : ""));
02005         if (rc < 0)     rc = CPIOERR_UNLINK_FAILED;
02006         break;
02007     case FSM_RENAME:
02008         rc = Rename(fsm->opath, fsm->path);
02009 #if defined(ETXTBSY)
02010         if (rc && errno == ETXTBSY) {
02011             char * path = alloca(strlen(fsm->path) + sizeof("-RPMDELETE"));
02012             (void) stpcpy( stpcpy(path, fsm->path), "-RPMDELETE");
02013             /*
02014              * XXX HP-UX (and other os'es) don't permit rename to busy
02015              * XXX files.
02016              */
02017             rc = Rename(fsm->path, path);
02018             if (!rc) rc = Rename(fsm->opath, fsm->path);
02019         }
02020 #endif
02021         if (_fsm_debug && (stage & FSM_SYSCALL))
02022             rpmMessage(RPMMESS_DEBUG, " %8s (%s, %s) %s\n", cur,
02023                 fsm->opath, fsm->path, (rc < 0 ? strerror(errno) : ""));
02024         if (rc < 0)     rc = CPIOERR_RENAME_FAILED;
02025         break;
02026     case FSM_MKDIR:
02027         rc = Mkdir(fsm->path, (st->st_mode & 07777));
02028         if (_fsm_debug && (stage & FSM_SYSCALL))
02029             rpmMessage(RPMMESS_DEBUG, " %8s (%s, 0%04o) %s\n", cur,
02030                 fsm->path, (unsigned)(st->st_mode & 07777),
02031                 (rc < 0 ? strerror(errno) : ""));
02032         if (rc < 0)     rc = CPIOERR_MKDIR_FAILED;
02033         break;
02034     case FSM_RMDIR:
02035         rc = Rmdir(fsm->path);
02036         if (_fsm_debug && (stage & FSM_SYSCALL))
02037             rpmMessage(RPMMESS_DEBUG, " %8s (%s) %s\n", cur,
02038                 fsm->path, (rc < 0 ? strerror(errno) : ""));
02039         if (rc < 0)     rc = CPIOERR_RMDIR_FAILED;
02040         break;
02041     case FSM_CHOWN:
02042         rc = chown(fsm->path, st->st_uid, st->st_gid);
02043         if (_fsm_debug && (stage & FSM_SYSCALL))
02044             rpmMessage(RPMMESS_DEBUG, " %8s (%s, %d, %d) %s\n", cur,
02045                 fsm->path, (int)st->st_uid, (int)st->st_gid,
02046                 (rc < 0 ? strerror(errno) : ""));
02047         if (rc < 0)     rc = CPIOERR_CHOWN_FAILED;
02048         break;
02049     case FSM_LCHOWN:
02050 #if ! CHOWN_FOLLOWS_SYMLINK
02051         rc = lchown(fsm->path, st->st_uid, st->st_gid);
02052         if (_fsm_debug && (stage & FSM_SYSCALL))
02053             rpmMessage(RPMMESS_DEBUG, " %8s (%s, %d, %d) %s\n", cur,
02054                 fsm->path, (int)st->st_uid, (int)st->st_gid,
02055                 (rc < 0 ? strerror(errno) : ""));
02056         if (rc < 0)     rc = CPIOERR_CHOWN_FAILED;
02057 #endif
02058         break;
02059     case FSM_CHMOD:
02060         rc = chmod(fsm->path, (st->st_mode & 07777));
02061         if (_fsm_debug && (stage & FSM_SYSCALL))
02062             rpmMessage(RPMMESS_DEBUG, " %8s (%s, 0%04o) %s\n", cur,
02063                 fsm->path, (unsigned)(st->st_mode & 07777),
02064                 (rc < 0 ? strerror(errno) : ""));
02065         if (rc < 0)     rc = CPIOERR_CHMOD_FAILED;
02066         break;
02067     case FSM_UTIME:
02068         {   struct utimbuf stamp;
02069             stamp.actime = st->st_mtime;
02070             stamp.modtime = st->st_mtime;
02071             rc = utime(fsm->path, &stamp);
02072             if (_fsm_debug && (stage & FSM_SYSCALL))
02073                 rpmMessage(RPMMESS_DEBUG, " %8s (%s, 0x%x) %s\n", cur,
02074                         fsm->path, (unsigned)st->st_mtime,
02075                         (rc < 0 ? strerror(errno) : ""));
02076             if (rc < 0) rc = CPIOERR_UTIME_FAILED;
02077         }
02078         break;
02079     case FSM_SYMLINK:
02080         rc = symlink(fsm->opath, fsm->path);
02081         if (_fsm_debug && (stage & FSM_SYSCALL))
02082             rpmMessage(RPMMESS_DEBUG, " %8s (%s, %s) %s\n", cur,
02083                 fsm->opath, fsm->path, (rc < 0 ? strerror(errno) : ""));
02084         if (rc < 0)     rc = CPIOERR_SYMLINK_FAILED;
02085         break;
02086     case FSM_LINK:
02087         rc = Link(fsm->opath, fsm->path);
02088         if (_fsm_debug && (stage & FSM_SYSCALL))
02089             rpmMessage(RPMMESS_DEBUG, " %8s (%s, %s) %s\n", cur,
02090                 fsm->opath, fsm->path, (rc < 0 ? strerror(errno) : ""));
02091         if (rc < 0)     rc = CPIOERR_LINK_FAILED;
02092         break;
02093     case FSM_MKFIFO:
02094         rc = mkfifo(fsm->path, (st->st_mode & 07777));
02095         if (_fsm_debug && (stage & FSM_SYSCALL))
02096             rpmMessage(RPMMESS_DEBUG, " %8s (%s, 0%04o) %s\n", cur,
02097                 fsm->path, (unsigned)(st->st_mode & 07777),
02098                 (rc < 0 ? strerror(errno) : ""));
02099         if (rc < 0)     rc = CPIOERR_MKFIFO_FAILED;
02100         break;
02101     case FSM_MKNOD:
02102         /*@-unrecog -portability @*/ /* FIX: check S_IFIFO or dev != 0 */
02103         rc = mknod(fsm->path, (st->st_mode & ~07777), st->st_rdev);
02104         /*@=unrecog =portability @*/
02105         if (_fsm_debug && (stage & FSM_SYSCALL))
02106             rpmMessage(RPMMESS_DEBUG, " %8s (%s, 0%o, 0x%x) %s\n", cur,
02107                 fsm->path, (unsigned)(st->st_mode & ~07777),
02108                 (unsigned)st->st_rdev,
02109                 (rc < 0 ? strerror(errno) : ""));
02110         if (rc < 0)     rc = CPIOERR_MKNOD_FAILED;
02111         break;
02112     case FSM_LSTAT:
02113         rc = Lstat(fsm->path, ost);
02114         if (_fsm_debug && (stage & FSM_SYSCALL) && rc && errno != ENOENT)
02115             rpmMessage(RPMMESS_DEBUG, " %8s (%s, ost) %s\n", cur,
02116                 fsm->path, (rc < 0 ? strerror(errno) : ""));
02117         if (rc < 0)     rc = CPIOERR_LSTAT_FAILED;
02118         break;
02119     case FSM_STAT:
02120         rc = Stat(fsm->path, ost);
02121         if (_fsm_debug && (stage & FSM_SYSCALL) && rc && errno != ENOENT)
02122             rpmMessage(RPMMESS_DEBUG, " %8s (%s, ost) %s\n", cur,
02123                 fsm->path, (rc < 0 ? strerror(errno) : ""));
02124         if (rc < 0)     rc = CPIOERR_STAT_FAILED;
02125         break;
02126     case FSM_READLINK:
02127         /* XXX NUL terminated result in fsm->rdbuf, len in fsm->rdnb. */
02128 /*@-boundswrite@*/
02129         rc = Readlink(fsm->path, fsm->rdbuf, fsm->rdsize - 1);
02130 /*@=boundswrite@*/
02131         if (_fsm_debug && (stage & FSM_SYSCALL))
02132             rpmMessage(RPMMESS_DEBUG, " %8s (%s, rdbuf, %d) %s\n", cur,
02133                 fsm->path, (int)(fsm->rdsize -1), (rc < 0 ? strerror(errno) : ""));
02134         if (rc < 0)     rc = CPIOERR_READLINK_FAILED;
02135         else {
02136             fsm->rdnb = rc;
02137 /*@-boundswrite@*/
02138             fsm->rdbuf[fsm->rdnb] = '\0';
02139 /*@=boundswrite@*/
02140             rc = 0;
02141         }
02142         break;
02143     case FSM_CHROOT:
02144         break;
02145 
02146     case FSM_NEXT:
02147         rc = fsmStage(fsm, FSM_HREAD);
02148         if (rc) break;
02149         if (!strcmp(fsm->path, CPIO_TRAILER)) { /* Detect end-of-payload. */
02150             fsm->path = _free(fsm->path);
02151             rc = CPIOERR_HDR_TRAILER;
02152         }
02153         if (!rc)
02154             rc = fsmStage(fsm, FSM_POS);
02155         break;
02156     case FSM_EAT:
02157         for (left = st->st_size; left > 0; left -= fsm->rdnb) {
02158             fsm->wrlen = (left > fsm->wrsize ? fsm->wrsize : left);
02159             rc = fsmStage(fsm, FSM_DREAD);
02160             if (rc)
02161                 /*@loopbreak@*/ break;
02162         }
02163         break;
02164     case FSM_POS:
02165         left = (modulo - (fdGetCpioPos(fsm->cfd) % modulo)) % modulo;
02166         if (left) {
02167             fsm->wrlen = left;
02168             (void) fsmStage(fsm, FSM_DREAD);
02169         }
02170         break;
02171     case FSM_PAD:
02172         left = (modulo - (fdGetCpioPos(fsm->cfd) % modulo)) % modulo;
02173         if (left) {
02174 /*@-boundswrite@*/
02175             memset(fsm->rdbuf, 0, left);
02176 /*@=boundswrite@*/
02177             /* XXX DWRITE uses rdnb for I/O length. */
02178             fsm->rdnb = left;
02179             (void) fsmStage(fsm, FSM_DWRITE);
02180         }
02181         break;
02182     case FSM_TRAILER:
02183         rc = cpioTrailerWrite(fsm);
02184         break;
02185     case FSM_HREAD:
02186         rc = fsmStage(fsm, FSM_POS);
02187         if (!rc)
02188             rc = cpioHeaderRead(fsm, st);       /* Read next payload header. */
02189         break;
02190     case FSM_HWRITE:
02191         rc = cpioHeaderWrite(fsm, st);          /* Write next payload header. */
02192         break;
02193     case FSM_DREAD:
02194 /*@-boundswrite@*/
02195         fsm->rdnb = Fread(fsm->wrbuf, sizeof(*fsm->wrbuf), fsm->wrlen, fsm->cfd);
02196 /*@=boundswrite@*/
02197         if (_fsm_debug && (stage & FSM_SYSCALL))
02198             rpmMessage(RPMMESS_DEBUG, " %8s (%s, %d, cfd)\trdnb %d\n",
02199                 cur, (fsm->wrbuf == fsm->wrb ? "wrbuf" : "mmap"),
02200                 (int)fsm->wrlen, (int)fsm->rdnb);
02201         if (fsm->rdnb != fsm->wrlen || Ferror(fsm->cfd))
02202             rc = CPIOERR_READ_FAILED;
02203         if (fsm->rdnb > 0)
02204             fdSetCpioPos(fsm->cfd, fdGetCpioPos(fsm->cfd) + fsm->rdnb);
02205         break;
02206     case FSM_DWRITE:
02207         fsm->wrnb = Fwrite(fsm->rdbuf, sizeof(*fsm->rdbuf), fsm->rdnb, fsm->cfd);
02208         if (_fsm_debug && (stage & FSM_SYSCALL))
02209             rpmMessage(RPMMESS_DEBUG, " %8s (%s, %d, cfd)\twrnb %d\n",
02210                 cur, (fsm->rdbuf == fsm->rdb ? "rdbuf" : "mmap"),
02211                 (int)fsm->rdnb, (int)fsm->wrnb);
02212         if (fsm->rdnb != fsm->wrnb || Ferror(fsm->cfd))
02213             rc = CPIOERR_WRITE_FAILED;
02214         if (fsm->wrnb > 0)
02215             fdSetCpioPos(fsm->cfd, fdGetCpioPos(fsm->cfd) + fsm->wrnb);
02216         break;
02217 
02218     case FSM_ROPEN:
02219         fsm->rfd = Fopen(fsm->path, "r.ufdio");
02220         if (fsm->rfd == NULL || Ferror(fsm->rfd)) {
02221             if (fsm->rfd)       (void) fsmStage(fsm, FSM_RCLOSE);
02222             fsm->rfd = NULL;
02223             rc = CPIOERR_OPEN_FAILED;
02224             break;
02225         }
02226         if (_fsm_debug && (stage & FSM_SYSCALL))
02227             rpmMessage(RPMMESS_DEBUG, " %8s (%s, \"r\") rfd %p rdbuf %p\n", cur,
02228                 fsm->path, fsm->rfd, fsm->rdbuf);
02229         break;
02230     case FSM_READ:
02231 /*@-boundswrite@*/
02232         fsm->rdnb = Fread(fsm->rdbuf, sizeof(*fsm->rdbuf), fsm->rdlen, fsm->rfd);
02233 /*@=boundswrite@*/
02234         if (_fsm_debug && (stage & FSM_SYSCALL))
02235             rpmMessage(RPMMESS_DEBUG, " %8s (rdbuf, %d, rfd)\trdnb %d\n",
02236                 cur, (int)fsm->rdlen, (int)fsm->rdnb);
02237         if (fsm->rdnb != fsm->rdlen || Ferror(fsm->rfd))
02238             rc = CPIOERR_READ_FAILED;
02239         break;
02240     case FSM_RCLOSE:
02241         if (fsm->rfd) {
02242             if (_fsm_debug && (stage & FSM_SYSCALL))
02243                 rpmMessage(RPMMESS_DEBUG, " %8s (%p)\n", cur, fsm->rfd);
02244             (void) Fclose(fsm->rfd);
02245             /*@-mods@*/
02246             errno = saveerrno;
02247             /*@=mods@*/
02248         }
02249         fsm->rfd = NULL;
02250         break;
02251     case FSM_WOPEN:
02252         fsm->wfd = Fopen(fsm->path, "w.ufdio");
02253         if (fsm->wfd == NULL || Ferror(fsm->wfd)) {
02254             if (fsm->wfd)       (void) fsmStage(fsm, FSM_WCLOSE);
02255             fsm->wfd = NULL;
02256             rc = CPIOERR_OPEN_FAILED;
02257         }
02258         if (_fsm_debug && (stage & FSM_SYSCALL))
02259             rpmMessage(RPMMESS_DEBUG, " %8s (%s, \"w\") wfd %p wrbuf %p\n", cur,
02260                 fsm->path, fsm->wfd, fsm->wrbuf);
02261         break;
02262     case FSM_WRITE:
02263         fsm->wrnb = Fwrite(fsm->wrbuf, sizeof(*fsm->wrbuf), fsm->rdnb, fsm->wfd);
02264         if (_fsm_debug && (stage & FSM_SYSCALL))
02265             rpmMessage(RPMMESS_DEBUG, " %8s (wrbuf, %d, wfd)\twrnb %d\n",
02266                 cur, (int)fsm->rdnb, (int)fsm->wrnb);
02267         if (fsm->rdnb != fsm->wrnb || Ferror(fsm->wfd))
02268             rc = CPIOERR_WRITE_FAILED;
02269         break;
02270     case FSM_WCLOSE:
02271         if (fsm->wfd) {
02272             if (_fsm_debug && (stage & FSM_SYSCALL))
02273                 rpmMessage(RPMMESS_DEBUG, " %8s (%p)\n", cur, fsm->wfd);
02274             (void) Fclose(fsm->wfd);
02275             /*@-mods@*/
02276             errno = saveerrno;
02277             /*@=mods@*/
02278         }
02279         fsm->wfd = NULL;
02280         break;
02281 
02282     default:
02283         break;
02284     }
02285     /*@=branchstate@*/
02286 
02287     if (!(stage & FSM_INTERNAL)) {
02288         fsm->rc = (rc == CPIOERR_HDR_TRAILER ? 0 : rc);
02289     }
02290     return rc;
02291 }
02292 /*@=compmempass@*/
02293 /*@=boundsread@*/
02294 
02295 /*@obserever@*/ const char *const fileActionString(fileAction a)
02296 {
02297     switch (a) {
02298     case FA_UNKNOWN:    return "unknown";
02299     case FA_CREATE:     return "create";
02300     case FA_COPYOUT:    return "copyout";
02301     case FA_COPYIN:     return "copyin";
02302     case FA_BACKUP:     return "backup";
02303     case FA_SAVE:       return "save";
02304     case FA_SKIP:       return "skip";
02305     case FA_ALTNAME:    return "altname";
02306     case FA_ERASE:      return "erase";
02307     case FA_SKIPNSTATE: return "skipnstate";
02308     case FA_SKIPNETSHARED: return "skipnetshared";
02309     case FA_SKIPMULTILIB: return "skipmultilib";
02310     default:            return "???";
02311     }
02312     /*@notreached@*/
02313 }
02314 
02315 /*@observer@*/ const char *const fileStageString(fileStage a) {
02316     switch(a) {
02317     case FSM_UNKNOWN:   return "unknown";
02318 
02319     case FSM_PKGINSTALL:return "INSTALL";
02320     case FSM_PKGERASE:  return "ERASE";
02321     case FSM_PKGBUILD:  return "BUILD";
02322     case FSM_PKGCOMMIT: return "COMMIT";
02323     case FSM_PKGUNDO:   return "UNDO";
02324 
02325     case FSM_CREATE:    return "create";
02326     case FSM_INIT:      return "init";
02327     case FSM_MAP:       return "map";
02328     case FSM_MKDIRS:    return "mkdirs";
02329     case FSM_RMDIRS:    return "rmdirs";
02330     case FSM_PRE:       return "pre";
02331     case FSM_PROCESS:   return "process";
02332     case FSM_POST:      return "post";
02333     case FSM_MKLINKS:   return "mklinks";
02334     case FSM_NOTIFY:    return "notify";
02335     case FSM_UNDO:      return "undo";
02336     case FSM_FINI:      return "fini";
02337     case FSM_COMMIT:    return "commit";
02338     case FSM_DESTROY:   return "destroy";
02339     case FSM_VERIFY:    return "verify";
02340 
02341     case FSM_UNLINK:    return "Unlink";
02342     case FSM_RENAME:    return "Rename";
02343     case FSM_MKDIR:     return "Mkdir";
02344     case FSM_RMDIR:     return "rmdir";
02345     case FSM_CHOWN:     return "chown";
02346     case FSM_LCHOWN:    return "lchown";
02347     case FSM_CHMOD:     return "chmod";
02348     case FSM_UTIME:     return "utime";
02349     case FSM_SYMLINK:   return "symlink";
02350     case FSM_LINK:      return "Link";
02351     case FSM_MKFIFO:    return "mkfifo";
02352     case FSM_MKNOD:     return "mknod";
02353     case FSM_LSTAT:     return "Lstat";
02354     case FSM_STAT:      return "Stat";
02355     case FSM_READLINK:  return "Readlink";
02356     case FSM_CHROOT:    return "chroot";
02357 
02358     case FSM_NEXT:      return "next";
02359     case FSM_EAT:       return "eat";
02360     case FSM_POS:       return "pos";
02361     case FSM_PAD:       return "pad";
02362     case FSM_TRAILER:   return "trailer";
02363     case FSM_HREAD:     return "hread";
02364     case FSM_HWRITE:    return "hwrite";
02365     case FSM_DREAD:     return "Fread";
02366     case FSM_DWRITE:    return "Fwrite";
02367 
02368     case FSM_ROPEN:     return "Fopen";
02369     case FSM_READ:      return "Fread";
02370     case FSM_RCLOSE:    return "Fclose";
02371     case FSM_WOPEN:     return "Fopen";
02372     case FSM_WRITE:     return "Fwrite";
02373     case FSM_WCLOSE:    return "Fclose";
02374 
02375     default:            return "???";
02376     }
02377     /*@noteached@*/
02378 }

Generated on Wed Sep 4 12:49:50 2002 for rpm by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002