3 * File state machine to handle a payload from a package.
8 #include <rpmio_internal.h>
15 #include "psm.h" /* XXX fiTypeString */
18 #define _RPMFI_INTERNAL
33 #define alloca_strdup(_s) strcpy(alloca(strlen(_s)+1), (_s))
38 /* XXX Failure to remove is not (yet) cause for failure. */
39 /*@-exportlocal -exportheadervar@*/
41 int strict_erasures = 0;
42 /*@=exportlocal =exportheadervar@*/
44 rpmts fsmGetTs(const FSM_t fsm) {
45 const FSMI_t iter = fsm->iter;
46 /*@-compdef -refcounttrans -retexpose -usereleased @*/
47 return (iter ? iter->ts : NULL);
48 /*@=compdef =refcounttrans =retexpose =usereleased @*/
51 rpmfi fsmGetFi(const FSM_t fsm)
53 const FSMI_t iter = fsm->iter;
54 /*@-compdef -refcounttrans -retexpose -usereleased @*/
55 return (iter ? iter->fi : NULL);
56 /*@=compdef =refcounttrans =retexpose =usereleased @*/
59 #define SUFFIX_RPMORIG ".rpmorig"
60 #define SUFFIX_RPMSAVE ".rpmsave"
61 #define SUFFIX_RPMNEW ".rpmnew"
64 * Build path to file from file info, ornamented with subdir and suffix.
65 * @param fsm file state machine data
66 * @param st file stat info
67 * @param subdir subdir to use (NULL disables)
68 * @param suffix suffix to use (NULL disables)
69 * @retval path to file
71 static /*@only@*//*@null@*/
72 const char * fsmFsPath(/*@special@*/ /*@null@*/ const FSM_t fsm,
73 /*@null@*/ const struct stat * st,
74 /*@null@*/ const char * subdir,
75 /*@null@*/ const char * suffix)
76 /*@uses fsm->dirName, fsm->baseName */
79 const char * s = NULL;
84 nb = strlen(fsm->dirName) +
85 (st && !S_ISDIR(st->st_mode) ? (subdir ? strlen(subdir) : 0) : 0) +
86 (st && !S_ISDIR(st->st_mode) ? (suffix ? strlen(suffix) : 0) : 0) +
87 strlen(fsm->baseName) + 1;
89 t = stpcpy(t, fsm->dirName);
90 if (st && !S_ISDIR(st->st_mode))
91 if (subdir) t = stpcpy(t, subdir);
92 t = stpcpy(t, fsm->baseName);
93 if (st && !S_ISDIR(st->st_mode))
94 if (suffix) t = stpcpy(t, suffix);
100 * Destroy file info iterator.
101 * @param p file info iterator
102 * @retval NULL always
104 static /*@null@*/ void * mapFreeIterator(/*@only@*//*@null@*/ void * p)
109 iter->ts = rpmtsUnlink(iter->ts, "mapIterator");
110 iter->fi = rpmfiUnlink(iter->fi, "mapIterator");
116 * Create file info iterator.
117 * @param ts transaction set
118 * @param fi transaction element file info
119 * @return file info iterator
122 mapInitIterator(rpmts ts, rpmfi fi)
123 /*@modifies ts, fi @*/
127 iter = xcalloc(1, sizeof(*iter));
128 iter->ts = rpmtsLink(ts, "mapIterator");
129 iter->fi = rpmfiLink(fi, "mapIterator");
130 iter->reverse = (rpmteType(fi->te) == TR_REMOVED && fi->action != FA_COPYOUT);
131 iter->i = (iter->reverse ? (fi->fc - 1) : 0);
132 iter->isave = iter->i;
137 * Return next index into file info.
138 * @param a file info iterator
139 * @return next index, -1 on termination
141 static int mapNextIterator(/*@null@*/ void * a)
148 const rpmfi fi = iter->fi;
150 if (iter->i >= 0) i = iter->i--;
152 if (iter->i < fi->fc) i = iter->i++;
161 static int cpioStrCmp(const void * a, const void * b)
164 const char * afn = *(const char **)a;
165 const char * bfn = *(const char **)b;
167 /* Match rpm-4.0 payloads with ./ prefixes. */
168 if (afn[0] == '.' && afn[1] == '/') afn += 2;
169 if (bfn[0] == '.' && bfn[1] == '/') bfn += 2;
171 /* If either path is absolute, make it relative. */
172 if (afn[0] == '/') afn += 1;
173 if (bfn[0] == '/') bfn += 1;
175 return strcmp(afn, bfn);
179 * Locate archive path in file info.
180 * @param iter file info iterator
181 * @param fsmPath archive path
182 * @return index into file info, -1 if archive path was not found
184 static int mapFind(/*@null@*/ FSMI_t iter, const char * fsmPath)
190 const rpmfi fi = iter->fi;
191 if (fi && fi->fc > 0 && fi->apath && fsmPath && *fsmPath) {
192 const char ** p = NULL;
194 if (fi->apath != NULL)
195 p = bsearch(&fsmPath, fi->apath, fi->fc, sizeof(fsmPath),
198 iter->i = p - fi->apath;
199 ix = mapNextIterator(iter);
207 * Directory name iterator.
209 typedef struct dnli_s {
211 /*@only@*/ /*@null@*/ char * active;
218 * Destroy directory name iterator.
219 * @param a directory name iterator
220 * @retval NULL always
222 static /*@null@*/ void * dnlFreeIterator(/*@only@*//*@null@*/ const void * a)
226 DNLI_t dnli = (void *)a;
227 if (dnli->active) free(dnli->active);
234 static inline int dnlCount(const DNLI_t dnli)
237 return (dnli ? dnli->fi->dc : 0);
242 static inline int dnlIndex(const DNLI_t dnli)
245 return (dnli ? dnli->isave : -1);
249 * Create directory name iterator.
250 * @param fsm file state machine data
251 * @param reverse traverse directory names in reverse order?
252 * @return directory name iterator
255 static /*@only@*/ void * dnlInitIterator(/*@special@*/ const FSM_t fsm,
257 /*@uses fsm->iter @*/
260 rpmfi fi = fsmGetFi(fsm);
266 dnli = xcalloc(1, sizeof(*dnli));
268 dnli->reverse = reverse;
270 dnli->i = (reverse ? fi->dc : 0);
274 dnli->active = xcalloc(fi->dc, sizeof(*dnli->active));
276 /* Identify parent directories not skipped. */
277 for (i = 0; i < fi->fc; i++)
278 if (!XFA_SKIPPING(fi->actions[i])) dnli->active[fi->dil[i]] = 1;
280 /* Exclude parent directories that are explicitly included. */
281 for (i = 0; i < fi->fc; i++) {
282 int dil, dnlen, bnlen;
284 if (!S_ISDIR(fi->fmodes[i]))
288 dnlen = strlen(fi->dnl[dil]);
289 bnlen = strlen(fi->bnl[i]);
291 for (j = 0; j < fi->dc; j++) {
295 if (!dnli->active[j] || j == dil)
296 /*@innercontinue@*/ continue;
299 if (jlen != (dnlen+bnlen+1))
300 /*@innercontinue@*/ continue;
301 if (strncmp(dnl, fi->dnl[dil], dnlen))
302 /*@innercontinue@*/ continue;
303 if (strncmp(dnl+dnlen, fi->bnl[i], bnlen))
304 /*@innercontinue@*/ continue;
305 if (dnl[dnlen+bnlen] != '/' || dnl[dnlen+bnlen+1] != '\0')
306 /*@innercontinue@*/ continue;
307 /* This directory is included in the package. */
309 /*@innerbreak@*/ break;
313 /* Print only once per package. */
316 for (i = 0; i < fi->dc; i++) {
317 if (!dnli->active[i]) continue;
320 rpmMessage(RPMMESS_DEBUG,
321 _("========== Directories not explictly included in package:\n"));
323 rpmMessage(RPMMESS_DEBUG, _("%10d %s\n"), i, fi->dnl[i]);
326 rpmMessage(RPMMESS_DEBUG, "==========\n");
334 * Return next directory name (from file info).
335 * @param dnli directory name iterator
336 * @return next directory name
338 static /*@observer@*/ const char * dnlNextIterator(/*@null@*/ DNLI_t dnli)
341 const char * dn = NULL;
349 i = (!dnli->reverse ? dnli->i++ : --dnli->i);
350 } while (i >= 0 && i < fi->dc && !dnli->active[i]);
352 if (i >= 0 && i < fi->dc)
362 * Save hard link in chain.
363 * @param fsm file state machine data
364 * @return Is chain only partially filled?
366 static int saveHardLink(/*@special@*/ /*@partial@*/ FSM_t fsm)
367 /*@uses fsm->links, fsm->ix, fsm->sb, fsm->goal, fsm->nsuffix @*/
368 /*@defines fsm->li @*/
369 /*@releases fsm->path @*/
370 /*@globals fileSystem@*/
371 /*@modifies fsm, fileSystem @*/
373 struct stat * st = &fsm->sb;
378 /* Find hard link set. */
380 for (fsm->li = fsm->links; fsm->li; fsm->li = fsm->li->next) {
381 if (fsm->li->sb.st_ino == st->st_ino && fsm->li->sb.st_dev == st->st_dev)
386 /* New hard link encountered, add new link to set. */
388 if (fsm->li == NULL) {
389 fsm->li = xcalloc(1, sizeof(*fsm->li));
390 fsm->li->next = NULL;
391 fsm->li->sb = *st; /* structure assignment */
392 fsm->li->nlink = st->st_nlink;
393 fsm->li->linkIndex = fsm->ix;
394 fsm->li->createdPath = -1;
396 fsm->li->filex = xcalloc(st->st_nlink, sizeof(fsm->li->filex[0]));
397 memset(fsm->li->filex, -1, (st->st_nlink * sizeof(fsm->li->filex[0])));
398 fsm->li->nsuffix = xcalloc(st->st_nlink, sizeof(*fsm->li->nsuffix));
400 if (fsm->goal == FSM_PKGBUILD)
401 fsm->li->linksLeft = st->st_nlink;
402 if (fsm->goal == FSM_PKGINSTALL)
403 fsm->li->linksLeft = 0;
406 fsm->li->next = fsm->links;
408 fsm->links = fsm->li;
412 if (fsm->goal == FSM_PKGBUILD) --fsm->li->linksLeft;
413 fsm->li->filex[fsm->li->linksLeft] = fsm->ix;
414 /*@-observertrans -dependenttrans@*/
415 fsm->li->nsuffix[fsm->li->linksLeft] = fsm->nsuffix;
416 /*@=observertrans =dependenttrans@*/
417 if (fsm->goal == FSM_PKGINSTALL) fsm->li->linksLeft++;
419 if (fsm->goal == FSM_PKGBUILD)
420 return (fsm->li->linksLeft > 0);
422 if (fsm->goal != FSM_PKGINSTALL)
425 if (!(st->st_size || fsm->li->linksLeft == st->st_nlink))
428 /* Here come the bits, time to choose a non-skipped file name. */
429 { rpmfi fi = fsmGetFi(fsm);
431 for (j = fsm->li->linksLeft - 1; j >= 0; j--) {
432 ix = fsm->li->filex[j];
433 if (ix < 0 || XFA_SKIPPING(fi->actions[ix]))
439 /* Are all links skipped or not encountered yet? */
441 return 1; /* XXX W2DO? */
443 /* Save the non-skipped file name and map index. */
444 fsm->li->linkIndex = j;
445 fsm->path = _free(fsm->path);
447 rc = fsmStage(fsm, FSM_MAP);
452 * Destroy set of hard links.
453 * @param li set of hard links
455 static /*@null@*/ void * freeHardLink(/*@only@*/ /*@null@*/ struct hardLink_s * li)
459 li->nsuffix = _free(li->nsuffix); /* XXX elements are shared */
460 li->filex = _free(li->filex);
467 FSM_t fsm = xcalloc(1, sizeof(*fsm));
471 FSM_t freeFSM(FSM_t fsm)
474 fsm->path = _free(fsm->path);
476 while ((fsm->li = fsm->links) != NULL) {
477 fsm->links = fsm->li->next;
478 fsm->li->next = NULL;
479 fsm->li = freeHardLink(fsm->li);
482 fsm->dnlx = _free(fsm->dnlx);
483 fsm->ldn = _free(fsm->ldn);
484 fsm->iter = mapFreeIterator(fsm->iter);
489 int fsmSetup(FSM_t fsm, fileStage goal,
490 const rpmts ts, const rpmfi fi, FD_t cfd,
491 unsigned int * archiveSize, const char ** failedFile)
498 /*@-type@*/ /* FIX: cast? */
499 fsm->cfd = fdLink(cfd, "persist (fsm)");
501 pos = fdGetCpioPos(fsm->cfd);
502 fdSetCpioPos(fsm->cfd, 0);
504 fsm->iter = mapInitIterator(ts, fi);
506 if (fsm->goal == FSM_PKGINSTALL) {
508 ptr = rpmtsNotify(ts, fi->te,
509 RPMCALLBACK_INST_START, 0, fi->archiveSize);
513 fsm->archiveSize = archiveSize;
514 if (fsm->archiveSize)
515 *fsm->archiveSize = 0;
516 fsm->failedFile = failedFile;
518 *fsm->failedFile = NULL;
521 memset(fsm->sufbuf, 0, sizeof(fsm->sufbuf));
522 if (fsm->goal == FSM_PKGINSTALL) {
523 if (ts && rpmtsGetTid(ts) > 0)
524 sprintf(fsm->sufbuf, ";%08x", (unsigned)rpmtsGetTid(ts));
528 rc = fsmStage(fsm, FSM_CREATE);
529 if (rc && !ec) ec = rc;
531 rc = fsmStage(fsm, fsm->goal);
532 if (rc && !ec) ec = rc;
534 if (fsm->archiveSize && ec == 0)
535 *fsm->archiveSize = (fdGetCpioPos(fsm->cfd) - pos);
540 int fsmTeardown(FSM_t fsm)
545 rc = fsmStage(fsm, FSM_DESTROY);
547 fsm->iter = mapFreeIterator(fsm->iter);
549 /*@-type@*/ /* FIX: cast? */
550 fsm->cfd = fdFree(fsm->cfd, "persist (fsm)");
554 fsm->failedFile = NULL;
558 int fsmMapPath(FSM_t fsm)
560 rpmfi fi = fsmGetFi(fsm); /* XXX const except for fstates */
567 fsm->action = FA_UNKNOWN;
571 if (fi && i >= 0 && i < fi->fc) {
573 fsm->astriplen = fi->astriplen;
574 fsm->action = (fi->actions ? fi->actions[i] : fi->action);
575 fsm->fflags = (fi->fflags ? fi->fflags[i] : fi->flags);
576 fsm->mapFlags = (fi->fmapflags ? fi->fmapflags[i] : fi->mapflags);
578 /* src rpms have simple base name in payload. */
579 fsm->dirName = fi->dnl[fi->dil[i]];
580 fsm->baseName = fi->bnl[i];
582 switch (fsm->action) {
585 case FA_SKIPMULTILIB: /* XXX RPMFILE_STATE_MULTILIB? */
594 assert(rpmteType(fi->te) == TR_ADDED);
598 if (fi->fstates && rpmteType(fi->te) == TR_ADDED)
599 fi->fstates[i] = RPMFILE_STATE_NOTINSTALLED;
602 case FA_SKIPNETSHARED:
603 if (fi->fstates && rpmteType(fi->te) == TR_ADDED)
604 fi->fstates[i] = RPMFILE_STATE_NETSHARED;
608 if (!(fsm->fflags & RPMFILE_GHOST)) /* XXX Don't if %ghost file. */
609 switch (rpmteType(fi->te)) {
611 fsm->osuffix = SUFFIX_RPMORIG;
612 /*@innerbreak@*/ break;
614 fsm->osuffix = SUFFIX_RPMSAVE;
615 /*@innerbreak@*/ break;
620 assert(rpmteType(fi->te) == TR_ADDED);
621 if (!(fsm->fflags & RPMFILE_GHOST)) /* XXX Don't if %ghost file. */
622 fsm->nsuffix = SUFFIX_RPMNEW;
626 assert(rpmteType(fi->te) == TR_ADDED);
627 if (!(fsm->fflags & RPMFILE_GHOST)) /* XXX Don't if %ghost file. */
628 fsm->osuffix = SUFFIX_RPMSAVE;
631 assert(rpmteType(fi->te) == TR_REMOVED);
633 * XXX TODO: %ghost probably shouldn't be removed, but that changes
634 * legacy rpm behavior.
641 if ((fsm->mapFlags & CPIO_MAP_PATH) || fsm->nsuffix) {
642 const struct stat * st = &fsm->sb;
643 fsm->path = _free(fsm->path);
644 fsm->path = fsmFsPath(fsm, st, fsm->subdir,
645 (fsm->suffix ? fsm->suffix : fsm->nsuffix));
651 int fsmMapAttrs(FSM_t fsm)
653 struct stat * st = &fsm->sb;
654 rpmfi fi = fsmGetFi(fsm);
657 if (fi && i >= 0 && i < fi->fc) {
659 (S_ISDIR(st->st_mode) ? fi->dperms : fi->fperms);
661 (fi->fmodes ? fi->fmodes[i] : perms);
663 (fi->fuids ? fi->fuids[i] : fi->uid); /* XXX chmod u-s */
665 (fi->fgids ? fi->fgids[i] : fi->gid); /* XXX chmod g-s */
667 (fi->frdevs ? fi->frdevs[i] : 0);
669 (fi->fmtimes ? fi->fmtimes[i] : 0);
671 if (fsm->mapFlags & CPIO_MAP_MODE)
672 st->st_mode = (st->st_mode & S_IFMT) | (finalMode & ~S_IFMT);
673 if (fsm->mapFlags & CPIO_MAP_TYPE) {
674 st->st_mode = (st->st_mode & ~S_IFMT) | (finalMode & S_IFMT);
675 if ((S_ISCHR(st->st_mode) || S_ISBLK(st->st_mode))
676 && st->st_nlink == 0)
678 st->st_rdev = finalRdev;
679 st->st_mtime = finalMtime;
681 if (fsm->mapFlags & CPIO_MAP_UID)
682 st->st_uid = finalUid;
683 if (fsm->mapFlags & CPIO_MAP_GID)
684 st->st_gid = finalGid;
686 { rpmts ts = fsmGetTs(fsm);
688 if (ts != NULL && !(rpmtsFlags(ts) & RPMTRANS_FLAG_NOMD5)) {
689 fsm->fmd5sum = (fi->fmd5s ? fi->fmd5s[i] : NULL);
690 fsm->md5sum = (fi->md5s ? (fi->md5s + (16 * i)) : NULL);
702 * Create file from payload stream.
703 * @param fsm file state machine data
704 * @return 0 on success
706 static int expandRegular(/*@special@*/ FSM_t fsm)
708 /*@globals fileSystem@*/
709 /*@modifies fsm, fileSystem @*/
711 const struct stat * st = &fsm->sb;
712 int left = st->st_size;
715 rc = fsmStage(fsm, FSM_WOPEN);
719 if (st->st_size > 0 && (fsm->fmd5sum || fsm->md5sum))
720 fdInitDigest(fsm->wfd, PGPHASHALGO_MD5, 0);
724 fsm->wrlen = (left > fsm->wrsize ? fsm->wrsize : left);
725 rc = fsmStage(fsm, FSM_DREAD);
729 rc = fsmStage(fsm, FSM_WRITE);
735 /* don't call this with fileSize == fileComplete */
737 (void) fsmStage(fsm, FSM_NOTIFY);
740 if (st->st_size > 0 && (fsm->fmd5sum || fsm->md5sum)) {
741 void * md5sum = NULL;
742 int asAscii = (fsm->md5sum == NULL ? 1 : 0);
744 (void) Fflush(fsm->wfd);
745 fdFiniDigest(fsm->wfd, PGPHASHALGO_MD5, &md5sum, NULL, asAscii);
747 if (md5sum == NULL) {
748 rc = CPIOERR_MD5SUM_MISMATCH;
752 if (fsm->md5sum != NULL) {
753 if (memcmp(md5sum, fsm->md5sum, 16))
754 rc = CPIOERR_MD5SUM_MISMATCH;
756 if (strcmp(md5sum, fsm->fmd5sum))
757 rc = CPIOERR_MD5SUM_MISMATCH;
759 md5sum = _free(md5sum);
763 (void) fsmStage(fsm, FSM_WCLOSE);
768 * Write next item to payload stream.
769 * @param fsm file state machine data
770 * @param writeData should data be written?
771 * @return 0 on success
773 static int writeFile(/*@special@*/ FSM_t fsm, int writeData)
774 /*@uses fsm->path, fsm->opath, fsm->sb, fsm->osb, fsm->cfd @*/
775 /*@globals fileSystem@*/
776 /*@modifies fsm, fileSystem @*/
778 const char * path = fsm->path;
779 const char * opath = fsm->opath;
780 struct stat * st = &fsm->sb;
781 struct stat * ost = &fsm->osb;
782 size_t pos = fdGetCpioPos(fsm->cfd);
783 char * symbuf = NULL;
788 st->st_size = (writeData ? ost->st_size : 0);
791 if (S_ISDIR(st->st_mode)) {
793 } else if (S_ISLNK(st->st_mode)) {
795 * While linux puts the size of a symlink in the st_size field,
796 * I don't think that's a specified standard.
798 /* XXX NUL terminated result in fsm->rdbuf, len in fsm->rdnb. */
799 rc = fsmStage(fsm, FSM_READLINK);
801 st->st_size = fsm->rdnb;
802 symbuf = alloca_strdup(fsm->rdbuf); /* XXX save readlink return. */
806 if (fsm->mapFlags & CPIO_MAP_ABSOLUTE) {
807 /*@-compdef@*/ /* FIX: dirName/baseName annotations ? */
808 int nb = strlen(fsm->dirName) + strlen(fsm->baseName) + sizeof(".");
809 char * t = alloca(nb);
812 if (fsm->mapFlags & CPIO_MAP_ADDDOT)
814 t = stpcpy( stpcpy(t, fsm->dirName), fsm->baseName);
816 } else if (fsm->mapFlags & CPIO_MAP_PATH) {
817 rpmfi fi = fsmGetFi(fsm);
819 (fi->apath ? fi->apath[fsm->ix] + fi->striplen : fi->bnl[fsm->ix]);
822 rc = fsmStage(fsm, FSM_HWRITE);
826 if (writeData && S_ISREG(st->st_mode)) {
829 void * mapped = (void *)-1;
833 rc = fsmStage(fsm, FSM_ROPEN);
836 /* XXX unbuffered mmap generates *lots* of fdio debugging */
839 mapped = mmap(NULL, st->st_size, PROT_READ, MAP_SHARED, Fileno(fsm->rfd), 0);
840 if (mapped != (void *)-1) {
842 fsm->rdbuf = (char *) mapped;
843 fsm->rdlen = nmapped = st->st_size;
844 #if defined(MADV_DONTNEED)
845 xx = madvise(mapped, nmapped, MADV_DONTNEED);
854 if (mapped != (void *)-1) {
859 fsm->rdlen = (left > fsm->rdsize ? fsm->rdsize : left),
860 rc = fsmStage(fsm, FSM_READ);
864 /* XXX DWRITE uses rdnb for I/O length. */
865 rc = fsmStage(fsm, FSM_DWRITE);
872 if (mapped != (void *)-1) {
873 xx = msync(mapped, nmapped, MS_ASYNC);
874 #if defined(MADV_DONTNEED)
875 xx = madvise(mapped, nmapped, MADV_DONTNEED);
877 /*@-noeffect@*/ xx = munmap(mapped, nmapped) /*@=noeffect@*/;
882 } else if (writeData && S_ISLNK(st->st_mode)) {
883 /* XXX DWRITE uses rdnb for I/O length. */
884 strcpy(fsm->rdbuf, symbuf); /* XXX restore readlink buffer. */
885 fsm->rdnb = strlen(symbuf);
886 rc = fsmStage(fsm, FSM_DWRITE);
890 rc = fsmStage(fsm, FSM_PAD);
893 { const rpmts ts = fsmGetTs(fsm);
894 rpmfi fi = fsmGetFi(fsm);
895 size_t size = (fdGetCpioPos(fsm->cfd) - pos);
897 ptr = rpmtsNotify(ts, fi->te, RPMCALLBACK_INST_PROGRESS, size, size);
904 (void) fsmStage(fsm, FSM_RCLOSE);
905 /*@-dependenttrans@*/
908 /*@=dependenttrans@*/
913 * Write set of linked files to payload stream.
914 * @param fsm file state machine data
915 * @return 0 on success
917 static int writeLinkedFile(/*@special@*/ FSM_t fsm)
918 /*@uses fsm->path, fsm->nsuffix, fsm->ix, fsm->li, fsm->failedFile @*/
919 /*@globals fileSystem@*/
920 /*@modifies fsm, fileSystem @*/
922 const char * path = fsm->path;
923 const char * nsuffix = fsm->nsuffix;
924 int iterIndex = fsm->ix;
933 for (i = fsm->li->nlink - 1; i >= 0; i--) {
935 if (fsm->li->filex[i] < 0) continue;
937 fsm->ix = fsm->li->filex[i];
938 rc = fsmStage(fsm, FSM_MAP);
940 /* Write data after last link. */
941 rc = writeFile(fsm, (i == 0));
942 if (fsm->failedFile && rc != 0 && *fsm->failedFile == NULL) {
944 *fsm->failedFile = xstrdup(fsm->path);
947 fsm->path = _free(fsm->path);
948 fsm->li->filex[i] = -1;
952 fsm->nsuffix = nsuffix;
958 * Create pending hard links to existing file.
959 * @param fsm file state machine data
960 * @return 0 on success
962 static int fsmMakeLinks(/*@special@*/ FSM_t fsm)
963 /*@uses fsm->path, fsm->opath, fsm->nsuffix, fsm->ix, fsm->li @*/
964 /*@globals fileSystem@*/
965 /*@modifies fsm, fileSystem @*/
967 const char * path = fsm->path;
968 const char * opath = fsm->opath;
969 const char * nsuffix = fsm->nsuffix;
970 int iterIndex = fsm->ix;
980 fsm->ix = fsm->li->filex[fsm->li->createdPath];
981 rc = fsmStage(fsm, FSM_MAP);
982 fsm->opath = fsm->path;
985 for (i = 0; i < fsm->li->nlink; i++) {
986 if (fsm->li->filex[i] < 0) continue;
987 if (fsm->li->createdPath == i) continue;
989 fsm->ix = fsm->li->filex[i];
990 fsm->path = _free(fsm->path);
991 rc = fsmStage(fsm, FSM_MAP);
992 if (XFA_SKIPPING(fsm->action)) continue;
994 rc = fsmStage(fsm, FSM_VERIFY);
996 if (rc != CPIOERR_LSTAT_FAILED) break;
998 /* XXX link(fsm->opath, fsm->path) */
999 rc = fsmStage(fsm, FSM_LINK);
1000 if (fsm->failedFile && rc != 0 && *fsm->failedFile == NULL) {
1002 *fsm->failedFile = xstrdup(fsm->path);
1005 fsm->li->linksLeft--;
1008 fsm->path = _free(fsm->path);
1009 fsm->opath = _free(fsm->opath);
1011 fsm->ix = iterIndex;
1012 fsm->nsuffix = nsuffix;
1018 /** \ingroup payload
1019 * Commit hard linked file set atomically.
1020 * @param fsm file state machine data
1021 * @return 0 on success
1023 static int fsmCommitLinks(/*@special@*/ FSM_t fsm)
1024 /*@uses fsm->path, fsm->nsuffix, fsm->ix, fsm->sb,
1025 fsm->li, fsm->links @*/
1026 /*@globals fileSystem@*/
1027 /*@modifies fsm, fileSystem @*/
1029 const char * path = fsm->path;
1030 const char * nsuffix = fsm->nsuffix;
1031 int iterIndex = fsm->ix;
1032 struct stat * st = &fsm->sb;
1037 fsm->nsuffix = NULL;
1041 for (fsm->li = fsm->links; fsm->li; fsm->li = fsm->li->next) {
1042 if (fsm->li->sb.st_ino == st->st_ino && fsm->li->sb.st_dev == st->st_dev)
1047 for (i = 0; i < fsm->li->nlink; i++) {
1048 if (fsm->li->filex[i] < 0) continue;
1049 fsm->ix = fsm->li->filex[i];
1050 rc = fsmStage(fsm, FSM_MAP);
1051 if (!XFA_SKIPPING(fsm->action))
1052 rc = fsmStage(fsm, FSM_COMMIT);
1053 fsm->path = _free(fsm->path);
1054 fsm->li->filex[i] = -1;
1057 fsm->ix = iterIndex;
1058 fsm->nsuffix = nsuffix;
1064 * Remove (if created) directories not explicitly included in package.
1065 * @param fsm file state machine data
1066 * @return 0 on success
1068 static int fsmRmdirs(/*@special@*/ FSM_t fsm)
1069 /*@uses fsm->path, fsm->dnlx, fsm->ldn, fsm->rdbuf, fsm->iter @*/
1070 /*@globals fileSystem@*/
1071 /*@modifies fsm, fileSystem @*/
1073 const char * path = fsm->path;
1074 void * dnli = dnlInitIterator(fsm, 1);
1075 char * dn = fsm->rdbuf;
1076 int dc = dnlCount(dnli);
1081 /*@-observertrans -dependenttrans@*/
1082 if (fsm->ldn != NULL && fsm->dnlx != NULL)
1083 while ((fsm->path = dnlNextIterator(dnli)) != NULL) {
1084 int dnlen = strlen(fsm->path);
1087 dc = dnlIndex(dnli);
1088 if (fsm->dnlx[dc] < 1 || fsm->dnlx[dc] >= dnlen)
1091 /* Copy to avoid const on fsm->path. */
1092 te = stpcpy(dn, fsm->path) - 1;
1095 /* Remove generated directories. */
1096 /*@-usereleased@*/ /* LCL: te used after release? */
1100 rc = fsmStage(fsm, FSM_RMDIR);
1104 /*@innerbreak@*/ break;
1106 } while ((te - fsm->path) > fsm->dnlx[dc]);
1109 dnli = dnlFreeIterator(dnli);
1110 /*@=observertrans =dependenttrans@*/
1117 * Create (if necessary) directories not explicitly included in package.
1118 * @param fsm file state machine data
1119 * @return 0 on success
1121 static int fsmMkdirs(/*@special@*/ FSM_t fsm)
1122 /*@uses fsm->path, fsm->sb, fsm->osb, fsm->rdbuf, fsm->iter,
1123 fsm->ldn, fsm->ldnlen, fsm->ldnalloc @*/
1124 /*@defines fsm->dnlx, fsm->ldn @*/
1125 /*@globals fileSystem@*/
1126 /*@modifies fsm, fileSystem @*/
1128 struct stat * st = &fsm->sb;
1129 struct stat * ost = &fsm->osb;
1130 const char * path = fsm->path;
1131 mode_t st_mode = st->st_mode;
1132 void * dnli = dnlInitIterator(fsm, 0);
1133 char * dn = fsm->rdbuf;
1134 int dc = dnlCount(dnli);
1141 fsm->dnlx = (dc ? xcalloc(dc, sizeof(*fsm->dnlx)) : NULL);
1142 /*@-observertrans -dependenttrans@*/
1143 if (fsm->dnlx != NULL)
1144 while ((fsm->path = dnlNextIterator(dnli)) != NULL) {
1145 int dnlen = strlen(fsm->path);
1148 dc = dnlIndex(dnli);
1149 if (dc < 0) continue;
1150 fsm->dnlx[dc] = dnlen;
1154 /*@-compdef -nullpass@*/ /* FIX: fsm->ldn not defined ??? */
1155 if (dnlen <= fsm->ldnlen && !strcmp(fsm->path, fsm->ldn))
1157 /*@=compdef =nullpass@*/
1159 /* Copy to avoid const on fsm->path. */
1160 (void) stpcpy(dn, fsm->path);
1163 /* Assume '/' directory exists, "mkdir -p" for others if non-existent */
1164 for (i = 1, te = dn + 1; *te != '\0'; te++, i++) {
1166 /*@innercontinue@*/ continue;
1170 /* Already validated? */
1171 /*@-usedef -compdef -nullpass -nullderef@*/
1172 if (i < fsm->ldnlen &&
1173 (fsm->ldn[i] == '/' || fsm->ldn[i] == '\0') &&
1174 !strncmp(fsm->path, fsm->ldn, i))
1177 /* Move pre-existing path marker forward. */
1178 fsm->dnlx[dc] = (te - dn);
1179 /*@innercontinue@*/ continue;
1181 /*@=usedef =compdef =nullpass =nullderef@*/
1183 /* Validate next component of path. */
1184 rc = fsmStage(fsm, FSM_LSTAT);
1187 /* Directory already exists? */
1188 if (rc == 0 && S_ISDIR(ost->st_mode)) {
1189 /* Move pre-existing path marker forward. */
1190 fsm->dnlx[dc] = (te - dn);
1191 } else if (rc == CPIOERR_LSTAT_FAILED) {
1192 rpmfi fi = fsmGetFi(fsm);
1194 st->st_mode = S_IFDIR | (fi->dperms & 07777);
1195 rc = fsmStage(fsm, FSM_MKDIR);
1197 rpmMessage(RPMMESS_DEBUG,
1198 _("%s directory created with perms %04o.\n"),
1199 fsm->path, (unsigned)(st->st_mode & 07777));
1203 /*@innerbreak@*/ break;
1207 /* Save last validated path. */
1208 /*@-compdef@*/ /* FIX: ldn/path annotations ? */
1209 if (fsm->ldnalloc < (dnlen + 1)) {
1210 fsm->ldnalloc = dnlen + 100;
1211 fsm->ldn = xrealloc(fsm->ldn, fsm->ldnalloc);
1213 if (fsm->ldn != NULL) { /* XXX can't happen */
1214 strcpy(fsm->ldn, fsm->path);
1215 fsm->ldnlen = dnlen;
1219 dnli = dnlFreeIterator(dnli);
1220 /*@=observertrans =dependenttrans@*/
1223 st->st_mode = st_mode; /* XXX restore st->st_mode */
1224 /*@-compdef@*/ /* FIX: ldn/path annotations ? */
1231 * Check for file on disk.
1232 * @param fsm file state machine data
1233 * @return 0 on success
1235 static int fsmStat(FSM_t fsm)
1237 int saveerrno = errno;
1240 if (fsm->path != NULL) {
1241 int saveernno = errno;
1242 rc = fsmStage(fsm, (!(fsm->mapFlags & CPIO_FOLLOW_SYMLINKS)
1243 ? FSM_LSTAT : FSM_STAT));
1244 if (rc == CPIOERR_LSTAT_FAILED && errno == ENOENT) {
1248 } else if (rc == 0) {
1252 /* Skip %ghost files on build. */
1259 #define IS_DEV_LOG(_x) \
1260 ((_x) != NULL && strlen(_x) >= (sizeof("/dev/log")-1) && \
1261 !strncmp((_x), "/dev/log", sizeof("/dev/log")-1) && \
1262 ((_x)[sizeof("/dev/log")-1] == '\0' || \
1263 (_x)[sizeof("/dev/log")-1] == ';'))
1266 int fsmStage(FSM_t fsm, fileStage stage)
1269 fileStage prevStage = fsm->stage;
1270 const char * const prev = fileStageString(prevStage);
1272 static int modulo = 4;
1273 const char * const cur = fileStageString(stage);
1274 struct stat * st = &fsm->sb;
1275 struct stat * ost = &fsm->osb;
1276 int saveerrno = errno;
1281 #define _fafilter(_a) \
1282 (!((_a) == FA_CREATE || (_a) == FA_ERASE || (_a) == FA_COPYIN || (_a) == FA_COPYOUT) \
1283 ? fileActionString(_a) : "")
1285 if (stage & FSM_DEAD) {
1287 } else if (stage & FSM_INTERNAL) {
1288 if (_fsm_debug && !(stage & FSM_SYSCALL))
1289 rpmMessage(RPMMESS_DEBUG, " %8s %06o%3d (%4d,%4d)%10d %s %s\n",
1291 (unsigned)st->st_mode, (int)st->st_nlink,
1292 (int)st->st_uid, (int)st->st_gid, (int)st->st_size,
1293 (fsm->path ? fsm->path : ""),
1294 _fafilter(fsm->action));
1297 if (_fsm_debug || !(stage & FSM_VERBOSE))
1298 rpmMessage(RPMMESS_DEBUG, "%-8s %06o%3d (%4d,%4d)%10d %s %s\n",
1300 (unsigned)st->st_mode, (int)st->st_nlink,
1301 (int)st->st_uid, (int)st->st_gid, (int)st->st_size,
1302 (fsm->path ? fsm->path + fsm->astriplen : ""),
1303 _fafilter(fsm->action));
1311 case FSM_PKGINSTALL:
1313 /* Clean fsm, free'ing memory. Read next archive header. */
1314 rc = fsmStage(fsm, FSM_INIT);
1316 /* Exit on end-of-payload. */
1317 if (rc == CPIOERR_HDR_TRAILER) {
1319 /*@loopbreak@*/ break;
1322 /* Exit on error. */
1325 (void) fsmStage(fsm, FSM_UNDO);
1326 /*@loopbreak@*/ break;
1329 /* Extract file from archive. */
1330 rc = fsmStage(fsm, FSM_PROCESS);
1332 (void) fsmStage(fsm, FSM_UNDO);
1333 /*@loopbreak@*/ break;
1336 /* Notify on success. */
1337 (void) fsmStage(fsm, FSM_NOTIFY);
1339 rc = fsmStage(fsm, FSM_FINI);
1341 /*@loopbreak@*/ break;
1348 /* Clean fsm, free'ing memory. */
1349 rc = fsmStage(fsm, FSM_INIT);
1351 /* Exit on end-of-payload. */
1352 if (rc == CPIOERR_HDR_TRAILER) {
1354 /*@loopbreak@*/ break;
1357 /* Rename/erase next item. */
1358 if (fsmStage(fsm, FSM_FINI))
1359 /*@loopbreak@*/ break;
1365 rc = fsmStage(fsm, FSM_INIT);
1367 /* Exit on end-of-payload. */
1368 if (rc == CPIOERR_HDR_TRAILER) {
1370 /*@loopbreak@*/ break;
1373 /* Exit on error. */
1376 (void) fsmStage(fsm, FSM_UNDO);
1377 /*@loopbreak@*/ break;
1380 /* Copy file into archive. */
1381 rc = fsmStage(fsm, FSM_PROCESS);
1383 (void) fsmStage(fsm, FSM_UNDO);
1384 /*@loopbreak@*/ break;
1387 if (fsmStage(fsm, FSM_FINI))
1388 /*@loopbreak@*/ break;
1391 /* Flush partial sets of hard linked files. */
1392 if (!(fsm->mapFlags & CPIO_ALL_HARDLINKS)) {
1394 while ((fsm->li = fsm->links) != NULL) {
1395 fsm->links = fsm->li->next;
1396 fsm->li->next = NULL;
1398 /* Re-calculate link count for archive header. */
1399 for (j = -1, nlink = 0, i = 0; i < fsm->li->nlink; i++) {
1400 if (fsm->li->filex[i] < 0)
1401 /*@innercontinue@*/ continue;
1405 /* XXX force the contents out as well. */
1407 fsm->li->filex[0] = fsm->li->filex[j];
1408 fsm->li->filex[j] = -1;
1410 fsm->li->sb.st_nlink = nlink;
1412 fsm->sb = fsm->li->sb; /* structure assignment */
1413 fsm->osb = fsm->sb; /* structure assignment */
1415 if (!rc) rc = writeLinkedFile(fsm);
1417 fsm->li = freeHardLink(fsm->li);
1422 rc = fsmStage(fsm, FSM_TRAILER);
1426 { rpmts ts = fsmGetTs(fsm);
1427 #define _tsmask (RPMTRANS_FLAG_PKGCOMMIT | RPMTRANS_FLAG_COMMIT)
1428 fsm->commit = ((ts && (rpmtsFlags(ts) & _tsmask) &&
1429 fsm->goal != FSM_PKGCOMMIT) ? 0 : 1);
1432 fsm->path = _free(fsm->path);
1433 fsm->opath = _free(fsm->opath);
1434 fsm->dnlx = _free(fsm->dnlx);
1436 fsm->ldn = _free(fsm->ldn);
1437 fsm->ldnalloc = fsm->ldnlen = 0;
1439 fsm->rdsize = fsm->wrsize = 0;
1440 fsm->rdbuf = fsm->rdb = _free(fsm->rdb);
1441 fsm->wrbuf = fsm->wrb = _free(fsm->wrb);
1442 if (fsm->goal == FSM_PKGINSTALL || fsm->goal == FSM_PKGBUILD) {
1443 fsm->rdsize = 8 * BUFSIZ;
1444 fsm->rdbuf = fsm->rdb = xmalloc(fsm->rdsize);
1445 fsm->wrsize = 8 * BUFSIZ;
1446 fsm->wrbuf = fsm->wrb = xmalloc(fsm->wrsize);
1449 fsm->mkdirsdone = 0;
1454 errno = 0; /* XXX get rid of EBADF */
1457 /* Detect and create directories not explicitly in package. */
1458 if (fsm->goal == FSM_PKGINSTALL) {
1459 rc = fsmStage(fsm, FSM_MKDIRS);
1460 if (!rc) fsm->mkdirsdone = 1;
1465 fsm->path = _free(fsm->path);
1467 fsm->diskchecked = fsm->exists = 0;
1469 fsm->suffix = (fsm->sufbuf[0] != '\0' ? fsm->sufbuf : NULL);
1470 fsm->action = FA_UNKNOWN;
1471 fsm->osuffix = NULL;
1472 fsm->nsuffix = NULL;
1474 if (fsm->goal == FSM_PKGINSTALL) {
1475 /* Read next header from payload, checking for end-of-payload. */
1476 rc = fsmStage(fsm, FSM_NEXT);
1480 /* Identify mapping index. */
1481 fsm->ix = ((fsm->goal == FSM_PKGINSTALL)
1482 ? mapFind(fsm->iter, fsm->path) : mapNextIterator(fsm->iter));
1484 /* Detect end-of-loop and/or mapping error. */
1486 if (fsm->goal == FSM_PKGINSTALL) {
1488 rpmMessage(RPMMESS_WARNING,
1489 _("archive file %s was not found in header file list\n"),
1492 if (fsm->failedFile && *fsm->failedFile == NULL)
1493 *fsm->failedFile = xstrdup(fsm->path);
1494 rc = CPIOERR_UNMAPPED_FILE;
1496 rc = CPIOERR_HDR_TRAILER;
1501 /* On non-install, mode must be known so that dirs don't get suffix. */
1502 if (fsm->goal != FSM_PKGINSTALL) {
1503 rpmfi fi = fsmGetFi(fsm);
1504 st->st_mode = fi->fmodes[fsm->ix];
1507 /* Generate file path. */
1508 rc = fsmStage(fsm, FSM_MAP);
1511 /* Perform lstat/stat for disk file. */
1515 if (fsm->path != NULL &&
1516 !(fsm->goal == FSM_PKGINSTALL && S_ISREG(st->st_mode)))
1518 rc = fsmStage(fsm, (!(fsm->mapFlags & CPIO_FOLLOW_SYMLINKS)
1519 ? FSM_LSTAT : FSM_STAT));
1520 if (rc == CPIOERR_LSTAT_FAILED && errno == ENOENT) {
1526 } else if (rc == 0) {
1530 /* Skip %ghost files on build. */
1534 fsm->diskchecked = 1;
1537 /* On non-install, the disk file stat is what's remapped. */
1538 if (fsm->goal != FSM_PKGINSTALL)
1539 *st = *ost; /* structure assignment */
1541 /* Remap file perms, owner, and group. */
1542 rc = fsmMapAttrs(fsm);
1545 fsm->postpone = XFA_SKIPPING(fsm->action);
1546 if (fsm->goal == FSM_PKGINSTALL || fsm->goal == FSM_PKGBUILD) {
1547 /*@-evalorder@*/ /* FIX: saveHardLink can modify fsm */
1548 if (!S_ISDIR(st->st_mode) && st->st_nlink > 1)
1549 fsm->postpone = saveHardLink(fsm);
1556 rc = fsmMapPath(fsm);
1559 rc = fsmMkdirs(fsm);
1563 rc = fsmRmdirs(fsm);
1566 if (fsm->postpone) {
1567 if (fsm->goal == FSM_PKGINSTALL)
1568 rc = fsmStage(fsm, FSM_EAT);
1572 if (fsm->goal == FSM_PKGBUILD) {
1573 if (!S_ISDIR(st->st_mode) && st->st_nlink > 1) {
1574 struct hardLink_s * li, * prev;
1576 if (!(fsm->mapFlags & CPIO_ALL_HARDLINKS)) break;
1577 rc = writeLinkedFile(fsm);
1578 if (rc) break; /* W2DO? */
1580 for (li = fsm->links, prev = NULL; li; prev = li, li = li->next)
1582 /*@loopbreak@*/ break;
1585 fsm->links = fsm->li->next;
1587 prev->next = fsm->li->next;
1588 fsm->li->next = NULL;
1589 fsm->li = freeHardLink(fsm->li);
1591 rc = writeFile(fsm, 1);
1596 if (fsm->goal != FSM_PKGINSTALL)
1599 if (S_ISREG(st->st_mode)) {
1600 const char * path = fsm->path;
1602 fsm->path = fsmFsPath(fsm, st, NULL, NULL);
1603 rc = fsmStage(fsm, FSM_VERIFY);
1605 if (rc == 0 && fsm->osuffix) {
1606 const char * opath = fsm->opath;
1607 fsm->opath = fsm->path;
1608 fsm->path = fsmFsPath(fsm, st, NULL, fsm->osuffix);
1609 rc = fsmStage(fsm, FSM_RENAME);
1611 rpmMessage(RPMMESS_WARNING,
1612 _("%s saved as %s\n"), fsm->opath, fsm->path);
1613 fsm->path = _free(fsm->path);
1617 /*@-dependenttrans@*/
1619 /*@=dependenttrans@*/
1620 if (rc != CPIOERR_LSTAT_FAILED) return rc;
1621 rc = expandRegular(fsm);
1622 } else if (S_ISDIR(st->st_mode)) {
1623 mode_t st_mode = st->st_mode;
1624 rc = fsmStage(fsm, FSM_VERIFY);
1625 if (rc == CPIOERR_LSTAT_FAILED) {
1626 st->st_mode &= ~07777; /* XXX abuse st->st_mode */
1627 st->st_mode |= 00700;
1628 rc = fsmStage(fsm, FSM_MKDIR);
1629 st->st_mode = st_mode; /* XXX restore st->st_mode */
1631 } else if (S_ISLNK(st->st_mode)) {
1632 const char * opath = fsm->opath;
1634 if ((st->st_size + 1) > fsm->rdsize) {
1635 rc = CPIOERR_HDR_SIZE;
1639 fsm->wrlen = st->st_size;
1640 rc = fsmStage(fsm, FSM_DREAD);
1641 if (!rc && fsm->rdnb != fsm->wrlen)
1642 rc = CPIOERR_READ_FAILED;
1645 fsm->wrbuf[st->st_size] = '\0';
1646 /* XXX symlink(fsm->opath, fsm->path) */
1647 /*@-dependenttrans@*/
1648 fsm->opath = fsm->wrbuf;
1649 /*@=dependenttrans@*/
1650 rc = fsmStage(fsm, FSM_VERIFY);
1651 if (rc == CPIOERR_LSTAT_FAILED)
1652 rc = fsmStage(fsm, FSM_SYMLINK);
1653 fsm->opath = opath; /* XXX restore fsm->path */
1654 } else if (S_ISFIFO(st->st_mode)) {
1655 mode_t st_mode = st->st_mode;
1656 /* This mimics cpio S_ISSOCK() behavior but probably isnt' right */
1657 rc = fsmStage(fsm, FSM_VERIFY);
1658 if (rc == CPIOERR_LSTAT_FAILED) {
1659 st->st_mode = 0000; /* XXX abuse st->st_mode */
1660 rc = fsmStage(fsm, FSM_MKFIFO);
1661 st->st_mode = st_mode; /* XXX restore st->st_mode */
1663 } else if (S_ISCHR(st->st_mode) ||
1664 S_ISBLK(st->st_mode) ||
1665 /*@-unrecog@*/ S_ISSOCK(st->st_mode) /*@=unrecog@*/)
1667 rc = fsmStage(fsm, FSM_VERIFY);
1668 if (rc == CPIOERR_LSTAT_FAILED)
1669 rc = fsmStage(fsm, FSM_MKNOD);
1671 /* XXX Special case /dev/log, which shouldn't be packaged anyways */
1672 if (!IS_DEV_LOG(fsm->path))
1673 rc = CPIOERR_UNKNOWN_FILETYPE;
1675 if (!S_ISDIR(st->st_mode) && st->st_nlink > 1) {
1676 fsm->li->createdPath = fsm->li->linkIndex;
1677 rc = fsmMakeLinks(fsm);
1683 rc = fsmMakeLinks(fsm);
1685 case FSM_NOTIFY: /* XXX move from fsm to psm -> tsm */
1686 if (fsm->goal == FSM_PKGINSTALL || fsm->goal == FSM_PKGBUILD) {
1687 rpmts ts = fsmGetTs(fsm);
1688 rpmfi fi = fsmGetFi(fsm);
1690 ptr = rpmtsNotify(ts, fi->te, RPMCALLBACK_INST_PROGRESS,
1691 fdGetCpioPos(fsm->cfd), fi->archiveSize);
1697 if (fsm->goal == FSM_PKGINSTALL) {
1698 (void) fsmStage(fsm,
1699 (S_ISDIR(st->st_mode) ? FSM_RMDIR : FSM_UNLINK));
1701 #ifdef NOTYET /* XXX remove only dirs just created, not all. */
1703 (void) fsmStage(fsm, FSM_RMDIRS);
1709 if (fsm->failedFile && *fsm->failedFile == NULL)
1710 *fsm->failedFile = xstrdup(fsm->path);
1713 if (!fsm->postpone && fsm->commit) {
1714 if (fsm->goal == FSM_PKGINSTALL)
1715 rc = ((!S_ISDIR(st->st_mode) && st->st_nlink > 1)
1716 ? fsmCommitLinks(fsm) : fsmStage(fsm, FSM_COMMIT));
1717 if (fsm->goal == FSM_PKGCOMMIT)
1718 rc = fsmStage(fsm, FSM_COMMIT);
1719 if (fsm->goal == FSM_PKGERASE)
1720 rc = fsmStage(fsm, FSM_COMMIT);
1722 fsm->path = _free(fsm->path);
1723 fsm->opath = _free(fsm->opath);
1724 memset(st, 0, sizeof(*st));
1725 memset(ost, 0, sizeof(*ost));
1728 /* Rename pre-existing modified or unmanaged file. */
1729 if (fsm->osuffix && fsm->diskchecked &&
1730 (fsm->exists || (fsm->goal == FSM_PKGINSTALL && S_ISREG(st->st_mode))))
1732 const char * opath = fsm->opath;
1733 const char * path = fsm->path;
1734 fsm->opath = fsmFsPath(fsm, st, NULL, NULL);
1735 fsm->path = fsmFsPath(fsm, st, NULL, fsm->osuffix);
1736 rc = fsmStage(fsm, FSM_RENAME);
1738 rpmMessage(RPMMESS_WARNING, _("%s saved as %s\n"),
1739 fsm->opath, fsm->path);
1741 fsm->path = _free(fsm->path);
1743 fsm->opath = _free(fsm->opath);
1747 /* Remove erased files. */
1748 if (fsm->goal == FSM_PKGERASE) {
1749 if (fsm->action == FA_ERASE) {
1750 rpmfi fi = fsmGetFi(fsm);
1751 if (S_ISDIR(st->st_mode)) {
1752 rc = fsmStage(fsm, FSM_RMDIR);
1755 case ENOENT: /* XXX rmdir("/") linux 2.2.x kernel hack */
1757 /* XXX make sure that build side permits %missingok on directories. */
1758 if (fsm->fflags & RPMFILE_MISSINGOK)
1759 /*@innerbreak@*/ break;
1761 /* XXX common error message. */
1763 (strict_erasures ? RPMERR_RMDIR : RPMDEBUG_RMDIR),
1764 _("%s rmdir of %s failed: Directory not empty\n"),
1765 fiTypeString(fi), fsm->path);
1766 /*@innerbreak@*/ break;
1769 (strict_erasures ? RPMERR_RMDIR : RPMDEBUG_RMDIR),
1770 _("%s rmdir of %s failed: %s\n"),
1771 fiTypeString(fi), fsm->path, strerror(errno));
1772 /*@innerbreak@*/ break;
1775 rc = fsmStage(fsm, FSM_UNLINK);
1777 if (!(errno == ENOENT && (fsm->fflags & RPMFILE_MISSINGOK)))
1779 (strict_erasures ? RPMERR_UNLINK : RPMDEBUG_UNLINK),
1780 _("%s unlink of %s failed: %s\n"),
1781 fiTypeString(fi), fsm->path, strerror(errno));
1784 /* XXX Failure to remove is not (yet) cause for failure. */
1785 if (!strict_erasures) rc = 0;
1789 /* XXX Special case /dev/log, which shouldn't be packaged anyways */
1790 if (!S_ISSOCK(st->st_mode) && !IS_DEV_LOG(fsm->path)) {
1791 /* Rename temporary to final file name. */
1792 if (!S_ISDIR(st->st_mode) &&
1793 (fsm->subdir || fsm->suffix || fsm->nsuffix))
1795 fsm->opath = fsm->path;
1796 fsm->path = fsmFsPath(fsm, st, NULL, fsm->nsuffix);
1797 rc = fsmStage(fsm, FSM_RENAME);
1798 if (!rc && fsm->nsuffix) {
1799 const char * opath = fsmFsPath(fsm, st, NULL, NULL);
1800 rpmMessage(RPMMESS_WARNING, _("%s created as %s\n"),
1801 (opath ? opath : ""), fsm->path);
1802 opath = _free(opath);
1804 fsm->opath = _free(fsm->opath);
1806 if (S_ISLNK(st->st_mode)) {
1807 if (!rc && !getuid())
1808 rc = fsmStage(fsm, FSM_LCHOWN);
1810 if (!rc && !getuid())
1811 rc = fsmStage(fsm, FSM_CHOWN);
1813 rc = fsmStage(fsm, FSM_CHMOD);
1815 time_t mtime = st->st_mtime;
1816 rpmfi fi = fsmGetFi(fsm);
1818 st->st_mtime = fi->fmtimes[fsm->ix];
1819 rc = fsmStage(fsm, FSM_UTIME);
1820 st->st_mtime = mtime;
1825 /* Notify on success. */
1826 if (!rc) rc = fsmStage(fsm, FSM_NOTIFY);
1827 else if (fsm->failedFile && *fsm->failedFile == NULL) {
1828 *fsm->failedFile = fsm->path;
1833 fsm->path = _free(fsm->path);
1835 /* Check for hard links missing from payload. */
1836 while ((fsm->li = fsm->links) != NULL) {
1837 fsm->links = fsm->li->next;
1838 fsm->li->next = NULL;
1839 if (fsm->goal == FSM_PKGINSTALL &&
1840 fsm->commit && fsm->li->linksLeft)
1842 for (i = 0 ; i < fsm->li->linksLeft; i++) {
1843 if (fsm->li->filex[i] < 0)
1844 /*@innercontinue@*/ continue;
1845 rc = CPIOERR_MISSING_HARDLINK;
1846 if (fsm->failedFile && *fsm->failedFile == NULL) {
1847 fsm->ix = fsm->li->filex[i];
1848 if (!fsmStage(fsm, FSM_MAP)) {
1849 *fsm->failedFile = fsm->path;
1853 /*@loopbreak@*/ break;
1856 if (fsm->goal == FSM_PKGBUILD &&
1857 (fsm->mapFlags & CPIO_ALL_HARDLINKS))
1859 rc = CPIOERR_MISSING_HARDLINK;
1861 fsm->li = freeHardLink(fsm->li);
1863 fsm->ldn = _free(fsm->ldn);
1864 fsm->ldnalloc = fsm->ldnlen = 0;
1865 fsm->rdbuf = fsm->rdb = _free(fsm->rdb);
1866 fsm->wrbuf = fsm->wrb = _free(fsm->wrb);
1869 if (fsm->diskchecked && !fsm->exists) {
1870 rc = CPIOERR_LSTAT_FAILED;
1873 if (S_ISREG(st->st_mode)) {
1874 char * path = alloca(strlen(fsm->path) + sizeof("-RPMDELETE"));
1875 (void) stpcpy( stpcpy(path, fsm->path), "-RPMDELETE");
1877 * XXX HP-UX (and other os'es) don't permit unlink on busy
1880 fsm->opath = fsm->path;
1882 rc = fsmStage(fsm, FSM_RENAME);
1884 (void) fsmStage(fsm, FSM_UNLINK);
1886 rc = CPIOERR_UNLINK_FAILED;
1887 fsm->path = fsm->opath;
1889 return (rc ? rc : CPIOERR_LSTAT_FAILED); /* XXX HACK */
1890 /*@notreached@*/ break;
1891 } else if (S_ISDIR(st->st_mode)) {
1892 if (S_ISDIR(ost->st_mode)) return 0;
1893 if (S_ISLNK(ost->st_mode)) {
1894 rc = fsmStage(fsm, FSM_STAT);
1895 if (rc == CPIOERR_STAT_FAILED && errno == ENOENT) rc = 0;
1900 if (S_ISDIR(ost->st_mode)) return 0;
1902 } else if (S_ISLNK(st->st_mode)) {
1903 if (S_ISLNK(ost->st_mode)) {
1904 /* XXX NUL terminated result in fsm->rdbuf, len in fsm->rdnb. */
1905 rc = fsmStage(fsm, FSM_READLINK);
1910 if (!strcmp(fsm->opath, fsm->rdbuf)) return 0;
1912 } else if (S_ISFIFO(st->st_mode)) {
1913 if (S_ISFIFO(ost->st_mode)) return 0;
1914 } else if (S_ISCHR(st->st_mode) || S_ISBLK(st->st_mode)) {
1915 if ((S_ISCHR(ost->st_mode) || S_ISBLK(ost->st_mode)) &&
1916 (ost->st_rdev == st->st_rdev)) return 0;
1917 } else if (S_ISSOCK(st->st_mode)) {
1918 if (S_ISSOCK(ost->st_mode)) return 0;
1920 /* XXX shouldn't do this with commit/undo. */
1922 if (fsm->stage == FSM_PROCESS) rc = fsmStage(fsm, FSM_UNLINK);
1923 if (rc == 0) rc = CPIOERR_LSTAT_FAILED;
1924 return (rc ? rc : CPIOERR_LSTAT_FAILED); /* XXX HACK */
1925 /*@notreached@*/ break;
1928 rc = Unlink(fsm->path);
1929 if (_fsm_debug && (stage & FSM_SYSCALL))
1930 rpmMessage(RPMMESS_DEBUG, " %8s (%s) %s\n", cur,
1931 fsm->path, (rc < 0 ? strerror(errno) : ""));
1932 if (rc < 0) rc = CPIOERR_UNLINK_FAILED;
1935 rc = Rename(fsm->opath, fsm->path);
1936 if (_fsm_debug && (stage & FSM_SYSCALL))
1937 rpmMessage(RPMMESS_DEBUG, " %8s (%s, %s) %s\n", cur,
1938 fsm->opath, fsm->path, (rc < 0 ? strerror(errno) : ""));
1939 if (rc < 0) rc = CPIOERR_RENAME_FAILED;
1942 rc = Mkdir(fsm->path, (st->st_mode & 07777));
1943 if (_fsm_debug && (stage & FSM_SYSCALL))
1944 rpmMessage(RPMMESS_DEBUG, " %8s (%s, 0%04o) %s\n", cur,
1945 fsm->path, (unsigned)(st->st_mode & 07777),
1946 (rc < 0 ? strerror(errno) : ""));
1947 if (rc < 0) rc = CPIOERR_MKDIR_FAILED;
1950 rc = Rmdir(fsm->path);
1951 if (_fsm_debug && (stage & FSM_SYSCALL))
1952 rpmMessage(RPMMESS_DEBUG, " %8s (%s) %s\n", cur,
1953 fsm->path, (rc < 0 ? strerror(errno) : ""));
1954 if (rc < 0) rc = CPIOERR_RMDIR_FAILED;
1957 rc = chown(fsm->path, st->st_uid, st->st_gid);
1958 if (_fsm_debug && (stage & FSM_SYSCALL))
1959 rpmMessage(RPMMESS_DEBUG, " %8s (%s, %d, %d) %s\n", cur,
1960 fsm->path, (int)st->st_uid, (int)st->st_gid,
1961 (rc < 0 ? strerror(errno) : ""));
1962 if (rc < 0) rc = CPIOERR_CHOWN_FAILED;
1965 #if ! CHOWN_FOLLOWS_SYMLINK
1966 rc = lchown(fsm->path, st->st_uid, st->st_gid);
1967 if (_fsm_debug && (stage & FSM_SYSCALL))
1968 rpmMessage(RPMMESS_DEBUG, " %8s (%s, %d, %d) %s\n", cur,
1969 fsm->path, (int)st->st_uid, (int)st->st_gid,
1970 (rc < 0 ? strerror(errno) : ""));
1971 if (rc < 0) rc = CPIOERR_CHOWN_FAILED;
1975 rc = chmod(fsm->path, (st->st_mode & 07777));
1976 if (_fsm_debug && (stage & FSM_SYSCALL))
1977 rpmMessage(RPMMESS_DEBUG, " %8s (%s, 0%04o) %s\n", cur,
1978 fsm->path, (unsigned)(st->st_mode & 07777),
1979 (rc < 0 ? strerror(errno) : ""));
1980 if (rc < 0) rc = CPIOERR_CHMOD_FAILED;
1983 { struct utimbuf stamp;
1984 stamp.actime = st->st_mtime;
1985 stamp.modtime = st->st_mtime;
1986 rc = utime(fsm->path, &stamp);
1987 if (_fsm_debug && (stage & FSM_SYSCALL))
1988 rpmMessage(RPMMESS_DEBUG, " %8s (%s, 0x%x) %s\n", cur,
1989 fsm->path, (unsigned)st->st_mtime,
1990 (rc < 0 ? strerror(errno) : ""));
1991 if (rc < 0) rc = CPIOERR_UTIME_FAILED;
1995 rc = symlink(fsm->opath, fsm->path);
1996 if (_fsm_debug && (stage & FSM_SYSCALL))
1997 rpmMessage(RPMMESS_DEBUG, " %8s (%s, %s) %s\n", cur,
1998 fsm->opath, fsm->path, (rc < 0 ? strerror(errno) : ""));
1999 if (rc < 0) rc = CPIOERR_SYMLINK_FAILED;
2002 rc = Link(fsm->opath, fsm->path);
2003 if (_fsm_debug && (stage & FSM_SYSCALL))
2004 rpmMessage(RPMMESS_DEBUG, " %8s (%s, %s) %s\n", cur,
2005 fsm->opath, fsm->path, (rc < 0 ? strerror(errno) : ""));
2006 if (rc < 0) rc = CPIOERR_LINK_FAILED;
2009 rc = mkfifo(fsm->path, (st->st_mode & 07777));
2010 if (_fsm_debug && (stage & FSM_SYSCALL))
2011 rpmMessage(RPMMESS_DEBUG, " %8s (%s, 0%04o) %s\n", cur,
2012 fsm->path, (unsigned)(st->st_mode & 07777),
2013 (rc < 0 ? strerror(errno) : ""));
2014 if (rc < 0) rc = CPIOERR_MKFIFO_FAILED;
2017 /*@-unrecog -portability @*/ /* FIX: check S_IFIFO or dev != 0 */
2018 rc = mknod(fsm->path, (st->st_mode & ~07777), st->st_rdev);
2019 /*@=unrecog =portability @*/
2020 if (_fsm_debug && (stage & FSM_SYSCALL))
2021 rpmMessage(RPMMESS_DEBUG, " %8s (%s, 0%o, 0x%x) %s\n", cur,
2022 fsm->path, (unsigned)(st->st_mode & ~07777),
2023 (unsigned)st->st_rdev,
2024 (rc < 0 ? strerror(errno) : ""));
2025 if (rc < 0) rc = CPIOERR_MKNOD_FAILED;
2028 rc = Lstat(fsm->path, ost);
2029 if (_fsm_debug && (stage & FSM_SYSCALL) && rc && errno != ENOENT)
2030 rpmMessage(RPMMESS_DEBUG, " %8s (%s, ost) %s\n", cur,
2031 fsm->path, (rc < 0 ? strerror(errno) : ""));
2032 if (rc < 0) rc = CPIOERR_LSTAT_FAILED;
2035 rc = Stat(fsm->path, ost);
2036 if (_fsm_debug && (stage & FSM_SYSCALL) && rc && errno != ENOENT)
2037 rpmMessage(RPMMESS_DEBUG, " %8s (%s, ost) %s\n", cur,
2038 fsm->path, (rc < 0 ? strerror(errno) : ""));
2039 if (rc < 0) rc = CPIOERR_STAT_FAILED;
2042 /* XXX NUL terminated result in fsm->rdbuf, len in fsm->rdnb. */
2043 rc = Readlink(fsm->path, fsm->rdbuf, fsm->rdsize - 1);
2044 if (_fsm_debug && (stage & FSM_SYSCALL))
2045 rpmMessage(RPMMESS_DEBUG, " %8s (%s, rdbuf, %d) %s\n", cur,
2046 fsm->path, (int)(fsm->rdsize -1), (rc < 0 ? strerror(errno) : ""));
2047 if (rc < 0) rc = CPIOERR_READLINK_FAILED;
2050 fsm->rdbuf[fsm->rdnb] = '\0';
2058 rc = fsmStage(fsm, FSM_HREAD);
2060 if (!strcmp(fsm->path, CPIO_TRAILER)) { /* Detect end-of-payload. */
2061 fsm->path = _free(fsm->path);
2062 rc = CPIOERR_HDR_TRAILER;
2065 rc = fsmStage(fsm, FSM_POS);
2068 for (left = st->st_size; left > 0; left -= fsm->rdnb) {
2069 fsm->wrlen = (left > fsm->wrsize ? fsm->wrsize : left);
2070 rc = fsmStage(fsm, FSM_DREAD);
2072 /*@loopbreak@*/ break;
2076 left = (modulo - (fdGetCpioPos(fsm->cfd) % modulo)) % modulo;
2079 (void) fsmStage(fsm, FSM_DREAD);
2083 left = (modulo - (fdGetCpioPos(fsm->cfd) % modulo)) % modulo;
2085 memset(fsm->rdbuf, 0, left);
2086 /* XXX DWRITE uses rdnb for I/O length. */
2088 (void) fsmStage(fsm, FSM_DWRITE);
2092 rc = cpioTrailerWrite(fsm);
2095 rc = fsmStage(fsm, FSM_POS);
2097 rc = cpioHeaderRead(fsm, st); /* Read next payload header. */
2100 rc = cpioHeaderWrite(fsm, st); /* Write next payload header. */
2103 fsm->rdnb = Fread(fsm->wrbuf, sizeof(*fsm->wrbuf), fsm->wrlen, fsm->cfd);
2104 if (_fsm_debug && (stage & FSM_SYSCALL))
2105 rpmMessage(RPMMESS_DEBUG, " %8s (%s, %d, cfd)\trdnb %d\n",
2106 cur, (fsm->wrbuf == fsm->wrb ? "wrbuf" : "mmap"),
2107 (int)fsm->wrlen, (int)fsm->rdnb);
2108 if (fsm->rdnb != fsm->wrlen || Ferror(fsm->cfd))
2109 rc = CPIOERR_READ_FAILED;
2111 fdSetCpioPos(fsm->cfd, fdGetCpioPos(fsm->cfd) + fsm->rdnb);
2114 fsm->wrnb = Fwrite(fsm->rdbuf, sizeof(*fsm->rdbuf), fsm->rdnb, fsm->cfd);
2115 if (_fsm_debug && (stage & FSM_SYSCALL))
2116 rpmMessage(RPMMESS_DEBUG, " %8s (%s, %d, cfd)\twrnb %d\n",
2117 cur, (fsm->rdbuf == fsm->rdb ? "rdbuf" : "mmap"),
2118 (int)fsm->rdnb, (int)fsm->wrnb);
2119 if (fsm->rdnb != fsm->wrnb || Ferror(fsm->cfd))
2120 rc = CPIOERR_WRITE_FAILED;
2122 fdSetCpioPos(fsm->cfd, fdGetCpioPos(fsm->cfd) + fsm->wrnb);
2126 fsm->rfd = Fopen(fsm->path, "r.ufdio");
2127 if (fsm->rfd == NULL || Ferror(fsm->rfd)) {
2128 if (fsm->rfd) (void) fsmStage(fsm, FSM_RCLOSE);
2130 rc = CPIOERR_OPEN_FAILED;
2133 if (_fsm_debug && (stage & FSM_SYSCALL))
2134 rpmMessage(RPMMESS_DEBUG, " %8s (%s, \"r\") rfd %p rdbuf %p\n", cur,
2135 fsm->path, fsm->rfd, fsm->rdbuf);
2138 fsm->rdnb = Fread(fsm->rdbuf, sizeof(*fsm->rdbuf), fsm->rdlen, fsm->rfd);
2139 if (_fsm_debug && (stage & FSM_SYSCALL))
2140 rpmMessage(RPMMESS_DEBUG, " %8s (rdbuf, %d, rfd)\trdnb %d\n",
2141 cur, (int)fsm->rdlen, (int)fsm->rdnb);
2142 if (fsm->rdnb != fsm->rdlen || Ferror(fsm->rfd))
2143 rc = CPIOERR_READ_FAILED;
2147 if (_fsm_debug && (stage & FSM_SYSCALL))
2148 rpmMessage(RPMMESS_DEBUG, " %8s (%p)\n", cur, fsm->rfd);
2149 (void) Fclose(fsm->rfd);
2157 fsm->wfd = Fopen(fsm->path, "w.ufdio");
2158 if (fsm->wfd == NULL || Ferror(fsm->wfd)) {
2159 if (fsm->wfd) (void) fsmStage(fsm, FSM_WCLOSE);
2161 rc = CPIOERR_OPEN_FAILED;
2163 if (_fsm_debug && (stage & FSM_SYSCALL))
2164 rpmMessage(RPMMESS_DEBUG, " %8s (%s, \"w\") wfd %p wrbuf %p\n", cur,
2165 fsm->path, fsm->wfd, fsm->wrbuf);
2168 fsm->wrnb = Fwrite(fsm->wrbuf, sizeof(*fsm->wrbuf), fsm->rdnb, fsm->wfd);
2169 if (_fsm_debug && (stage & FSM_SYSCALL))
2170 rpmMessage(RPMMESS_DEBUG, " %8s (wrbuf, %d, wfd)\twrnb %d\n",
2171 cur, (int)fsm->rdnb, (int)fsm->wrnb);
2172 if (fsm->rdnb != fsm->wrnb || Ferror(fsm->wfd))
2173 rc = CPIOERR_WRITE_FAILED;
2177 if (_fsm_debug && (stage & FSM_SYSCALL))
2178 rpmMessage(RPMMESS_DEBUG, " %8s (%p)\n", cur, fsm->wfd);
2179 (void) Fclose(fsm->wfd);
2192 if (!(stage & FSM_INTERNAL)) {
2193 fsm->rc = (rc == CPIOERR_HDR_TRAILER ? 0 : rc);
2199 /*@obserever@*/ const char *const fileActionString(fileAction a)
2202 case FA_UNKNOWN: return "unknown";
2203 case FA_CREATE: return "create";
2204 case FA_COPYOUT: return "copyout";
2205 case FA_COPYIN: return "copyin";
2206 case FA_BACKUP: return "backup";
2207 case FA_SAVE: return "save";
2208 case FA_SKIP: return "skip";
2209 case FA_ALTNAME: return "altname";
2210 case FA_ERASE: return "erase";
2211 case FA_SKIPNSTATE: return "skipnstate";
2212 case FA_SKIPNETSHARED: return "skipnetshared";
2213 case FA_SKIPMULTILIB: return "skipmultilib";
2214 default: return "???";
2219 /*@observer@*/ const char *const fileStageString(fileStage a) {
2221 case FSM_UNKNOWN: return "unknown";
2223 case FSM_PKGINSTALL:return "INSTALL";
2224 case FSM_PKGERASE: return "ERASE";
2225 case FSM_PKGBUILD: return "BUILD";
2226 case FSM_PKGCOMMIT: return "COMMIT";
2227 case FSM_PKGUNDO: return "UNDO";
2229 case FSM_CREATE: return "create";
2230 case FSM_INIT: return "init";
2231 case FSM_MAP: return "map";
2232 case FSM_MKDIRS: return "mkdirs";
2233 case FSM_RMDIRS: return "rmdirs";
2234 case FSM_PRE: return "pre";
2235 case FSM_PROCESS: return "process";
2236 case FSM_POST: return "post";
2237 case FSM_MKLINKS: return "mklinks";
2238 case FSM_NOTIFY: return "notify";
2239 case FSM_UNDO: return "undo";
2240 case FSM_FINI: return "fini";
2241 case FSM_COMMIT: return "commit";
2242 case FSM_DESTROY: return "destroy";
2243 case FSM_VERIFY: return "verify";
2245 case FSM_UNLINK: return "Unlink";
2246 case FSM_RENAME: return "Rename";
2247 case FSM_MKDIR: return "Mkdir";
2248 case FSM_RMDIR: return "rmdir";
2249 case FSM_CHOWN: return "chown";
2250 case FSM_LCHOWN: return "lchown";
2251 case FSM_CHMOD: return "chmod";
2252 case FSM_UTIME: return "utime";
2253 case FSM_SYMLINK: return "symlink";
2254 case FSM_LINK: return "Link";
2255 case FSM_MKFIFO: return "mkfifo";
2256 case FSM_MKNOD: return "mknod";
2257 case FSM_LSTAT: return "Lstat";
2258 case FSM_STAT: return "Stat";
2259 case FSM_READLINK: return "Readlink";
2260 case FSM_CHROOT: return "chroot";
2262 case FSM_NEXT: return "next";
2263 case FSM_EAT: return "eat";
2264 case FSM_POS: return "pos";
2265 case FSM_PAD: return "pad";
2266 case FSM_TRAILER: return "trailer";
2267 case FSM_HREAD: return "hread";
2268 case FSM_HWRITE: return "hwrite";
2269 case FSM_DREAD: return "Fread";
2270 case FSM_DWRITE: return "Fwrite";
2272 case FSM_ROPEN: return "Fopen";
2273 case FSM_READ: return "Fread";
2274 case FSM_RCLOSE: return "Fclose";
2275 case FSM_WOPEN: return "Fopen";
2276 case FSM_WRITE: return "Fwrite";
2277 case FSM_WCLOSE: return "Fclose";
2279 default: return "???";