4 * File state machine to handle a payload from a package.
9 #include <rpmio_internal.h>
16 #include "psm.h" /* XXX fiTypeString */
19 #define _RPMFI_INTERNAL
34 #define alloca_strdup(_s) strcpy(alloca(strlen(_s)+1), (_s))
39 /* XXX Failure to remove is not (yet) cause for failure. */
40 /*@-exportlocal -exportheadervar@*/
42 int strict_erasures = 0;
43 /*@=exportlocal =exportheadervar@*/
45 rpmts fsmGetTs(const FSM_t fsm) {
46 const FSMI_t iter = fsm->iter;
47 /*@-compdef -refcounttrans -retexpose -usereleased @*/
48 return (iter ? iter->ts : NULL);
49 /*@=compdef =refcounttrans =retexpose =usereleased @*/
52 rpmfi fsmGetFi(const FSM_t fsm)
54 const FSMI_t iter = fsm->iter;
55 /*@-compdef -refcounttrans -retexpose -usereleased @*/
56 return (iter ? iter->fi : NULL);
57 /*@=compdef =refcounttrans =retexpose =usereleased @*/
60 #define SUFFIX_RPMORIG ".rpmorig"
61 #define SUFFIX_RPMSAVE ".rpmsave"
62 #define SUFFIX_RPMNEW ".rpmnew"
65 * Build path to file from file info, ornamented with subdir and suffix.
66 * @param fsm file state machine data
67 * @param st file stat info
68 * @param subdir subdir to use (NULL disables)
69 * @param suffix suffix to use (NULL disables)
70 * @retval path to file
72 static /*@only@*//*@null@*/
73 const char * fsmFsPath(/*@special@*/ /*@null@*/ const FSM_t fsm,
74 /*@null@*/ const struct stat * st,
75 /*@null@*/ const char * subdir,
76 /*@null@*/ const char * suffix)
77 /*@uses fsm->dirName, fsm->baseName */
80 const char * s = NULL;
85 nb = strlen(fsm->dirName) +
86 (st && !S_ISDIR(st->st_mode) ? (subdir ? strlen(subdir) : 0) : 0) +
87 (st && !S_ISDIR(st->st_mode) ? (suffix ? strlen(suffix) : 0) : 0) +
88 strlen(fsm->baseName) + 1;
91 t = stpcpy(t, fsm->dirName);
92 if (st && !S_ISDIR(st->st_mode))
93 if (subdir) t = stpcpy(t, subdir);
94 t = stpcpy(t, fsm->baseName);
95 if (st && !S_ISDIR(st->st_mode))
96 if (suffix) t = stpcpy(t, suffix);
103 * Destroy file info iterator.
104 * @param p file info iterator
105 * @retval NULL always
107 static /*@null@*/ void * mapFreeIterator(/*@only@*//*@null@*/ void * p)
112 iter->ts = rpmtsUnlink(iter->ts, "mapIterator");
113 iter->fi = rpmfiUnlink(iter->fi, "mapIterator");
119 * Create file info iterator.
120 * @param ts transaction set
121 * @param fi transaction element file info
122 * @return file info iterator
125 mapInitIterator(rpmts ts, rpmfi fi)
126 /*@modifies ts, fi @*/
130 iter = xcalloc(1, sizeof(*iter));
131 iter->ts = rpmtsLink(ts, "mapIterator");
132 iter->fi = rpmfiLink(fi, "mapIterator");
133 iter->reverse = (rpmteType(fi->te) == TR_REMOVED && fi->action != FA_COPYOUT);
134 iter->i = (iter->reverse ? (fi->fc - 1) : 0);
135 iter->isave = iter->i;
140 * Return next index into file info.
141 * @param a file info iterator
142 * @return next index, -1 on termination
144 static int mapNextIterator(/*@null@*/ void * a)
151 const rpmfi fi = iter->fi;
153 if (iter->i >= 0) i = iter->i--;
155 if (iter->i < fi->fc) i = iter->i++;
164 static int cpioStrCmp(const void * a, const void * b)
167 const char * afn = *(const char **)a;
168 const char * bfn = *(const char **)b;
170 /* Match rpm-4.0 payloads with ./ prefixes. */
171 if (afn[0] == '.' && afn[1] == '/') afn += 2;
172 if (bfn[0] == '.' && bfn[1] == '/') bfn += 2;
174 /* If either path is absolute, make it relative. */
175 if (afn[0] == '/') afn += 1;
176 if (bfn[0] == '/') bfn += 1;
178 return strcmp(afn, bfn);
182 * Locate archive path in file info.
183 * @param iter file info iterator
184 * @param fsmPath archive path
185 * @return index into file info, -1 if archive path was not found
187 static int mapFind(/*@null@*/ FSMI_t iter, const char * fsmPath)
193 const rpmfi fi = iter->fi;
194 if (fi && fi->fc > 0 && fi->apath && fsmPath && *fsmPath) {
195 const char ** p = NULL;
198 if (fi->apath != NULL)
199 p = bsearch(&fsmPath, fi->apath, fi->fc, sizeof(fsmPath),
203 iter->i = p - fi->apath;
204 ix = mapNextIterator(iter);
212 * Directory name iterator.
214 typedef struct dnli_s {
216 /*@only@*/ /*@null@*/ char * active;
223 * Destroy directory name iterator.
224 * @param a directory name iterator
225 * @retval NULL always
227 static /*@null@*/ void * dnlFreeIterator(/*@only@*//*@null@*/ const void * a)
231 DNLI_t dnli = (void *)a;
232 if (dnli->active) free(dnli->active);
239 static inline int dnlCount(const DNLI_t dnli)
242 return (dnli ? dnli->fi->dc : 0);
247 static inline int dnlIndex(const DNLI_t dnli)
250 return (dnli ? dnli->isave : -1);
254 * Create directory name iterator.
255 * @param fsm file state machine data
256 * @param reverse traverse directory names in reverse order?
257 * @return directory name iterator
260 static /*@only@*/ void * dnlInitIterator(/*@special@*/ const FSM_t fsm,
262 /*@uses fsm->iter @*/
265 rpmfi fi = fsmGetFi(fsm);
271 dnli = xcalloc(1, sizeof(*dnli));
273 dnli->reverse = reverse;
275 dnli->i = (reverse ? fi->dc : 0);
279 dnli->active = xcalloc(fi->dc, sizeof(*dnli->active));
281 /* Identify parent directories not skipped. */
283 for (i = 0; i < fi->fc; i++)
284 if (!XFA_SKIPPING(fi->actions[i])) dnli->active[fi->dil[i]] = 1;
287 /* Exclude parent directories that are explicitly included. */
288 for (i = 0; i < fi->fc; i++) {
289 int dil, dnlen, bnlen;
291 if (!S_ISDIR(fi->fmodes[i]))
295 dnlen = strlen(fi->dnl[dil]);
296 bnlen = strlen(fi->bnl[i]);
298 for (j = 0; j < fi->dc; j++) {
302 if (!dnli->active[j] || j == dil)
303 /*@innercontinue@*/ continue;
306 if (jlen != (dnlen+bnlen+1))
307 /*@innercontinue@*/ continue;
308 if (strncmp(dnl, fi->dnl[dil], dnlen))
309 /*@innercontinue@*/ continue;
310 if (strncmp(dnl+dnlen, fi->bnl[i], bnlen))
311 /*@innercontinue@*/ continue;
312 if (dnl[dnlen+bnlen] != '/' || dnl[dnlen+bnlen+1] != '\0')
313 /*@innercontinue@*/ continue;
314 /* This directory is included in the package. */
318 /*@innerbreak@*/ break;
322 /* Print only once per package. */
325 for (i = 0; i < fi->dc; i++) {
326 if (!dnli->active[i]) continue;
329 rpmMessage(RPMMESS_DEBUG,
330 _("========== Directories not explictly included in package:\n"));
332 rpmMessage(RPMMESS_DEBUG, _("%10d %s\n"), i, fi->dnl[i]);
335 rpmMessage(RPMMESS_DEBUG, "==========\n");
343 * Return next directory name (from file info).
344 * @param dnli directory name iterator
345 * @return next directory name
347 static /*@observer@*/ const char * dnlNextIterator(/*@null@*/ DNLI_t dnli)
350 const char * dn = NULL;
358 i = (!dnli->reverse ? dnli->i++ : --dnli->i);
359 } while (i >= 0 && i < fi->dc && !dnli->active[i]);
361 if (i >= 0 && i < fi->dc)
371 * Save hard link in chain.
372 * @param fsm file state machine data
373 * @return Is chain only partially filled?
375 static int saveHardLink(/*@special@*/ /*@partial@*/ FSM_t fsm)
376 /*@uses fsm->links, fsm->ix, fsm->sb, fsm->goal, fsm->nsuffix @*/
377 /*@defines fsm->li @*/
378 /*@releases fsm->path @*/
379 /*@globals fileSystem@*/
380 /*@modifies fsm, fileSystem @*/
382 struct stat * st = &fsm->sb;
387 /* Find hard link set. */
389 for (fsm->li = fsm->links; fsm->li; fsm->li = fsm->li->next) {
390 if (fsm->li->sb.st_ino == st->st_ino && fsm->li->sb.st_dev == st->st_dev)
395 /* New hard link encountered, add new link to set. */
398 if (fsm->li == NULL) {
399 fsm->li = xcalloc(1, sizeof(*fsm->li));
400 fsm->li->next = NULL;
401 fsm->li->sb = *st; /* structure assignment */
402 fsm->li->nlink = st->st_nlink;
403 fsm->li->linkIndex = fsm->ix;
404 fsm->li->createdPath = -1;
406 fsm->li->filex = xcalloc(st->st_nlink, sizeof(fsm->li->filex[0]));
407 memset(fsm->li->filex, -1, (st->st_nlink * sizeof(fsm->li->filex[0])));
408 fsm->li->nsuffix = xcalloc(st->st_nlink, sizeof(*fsm->li->nsuffix));
410 if (fsm->goal == FSM_PKGBUILD)
411 fsm->li->linksLeft = st->st_nlink;
412 if (fsm->goal == FSM_PKGINSTALL)
413 fsm->li->linksLeft = 0;
416 fsm->li->next = fsm->links;
418 fsm->links = fsm->li;
423 if (fsm->goal == FSM_PKGBUILD) --fsm->li->linksLeft;
425 fsm->li->filex[fsm->li->linksLeft] = fsm->ix;
426 /*@-observertrans -dependenttrans@*/
427 fsm->li->nsuffix[fsm->li->linksLeft] = fsm->nsuffix;
428 /*@=observertrans =dependenttrans@*/
430 if (fsm->goal == FSM_PKGINSTALL) fsm->li->linksLeft++;
432 if (fsm->goal == FSM_PKGBUILD)
433 return (fsm->li->linksLeft > 0);
435 if (fsm->goal != FSM_PKGINSTALL)
438 if (!(st->st_size || fsm->li->linksLeft == st->st_nlink))
441 /* Here come the bits, time to choose a non-skipped file name. */
442 { rpmfi fi = fsmGetFi(fsm);
444 for (j = fsm->li->linksLeft - 1; j >= 0; j--) {
445 ix = fsm->li->filex[j];
446 if (ix < 0 || XFA_SKIPPING(fi->actions[ix]))
452 /* Are all links skipped or not encountered yet? */
454 return 1; /* XXX W2DO? */
456 /* Save the non-skipped file name and map index. */
457 fsm->li->linkIndex = j;
458 fsm->path = _free(fsm->path);
460 rc = fsmStage(fsm, FSM_MAP);
465 * Destroy set of hard links.
466 * @param li set of hard links
467 * @return NULL always
469 static /*@null@*/ void * freeHardLink(/*@only@*/ /*@null@*/ struct hardLink_s * li)
473 li->nsuffix = _free(li->nsuffix); /* XXX elements are shared */
474 li->filex = _free(li->filex);
481 FSM_t fsm = xcalloc(1, sizeof(*fsm));
485 FSM_t freeFSM(FSM_t fsm)
488 fsm->path = _free(fsm->path);
490 while ((fsm->li = fsm->links) != NULL) {
491 fsm->links = fsm->li->next;
492 fsm->li->next = NULL;
493 fsm->li = freeHardLink(fsm->li);
496 fsm->dnlx = _free(fsm->dnlx);
497 fsm->ldn = _free(fsm->ldn);
498 fsm->iter = mapFreeIterator(fsm->iter);
503 int fsmSetup(FSM_t fsm, fileStage goal,
504 const rpmts ts, const rpmfi fi, FD_t cfd,
505 unsigned int * archiveSize, const char ** failedFile)
512 /*@-type@*/ /* FIX: cast? */
513 fsm->cfd = fdLink(cfd, "persist (fsm)");
515 pos = fdGetCpioPos(fsm->cfd);
516 fdSetCpioPos(fsm->cfd, 0);
518 fsm->iter = mapInitIterator(ts, fi);
520 if (fsm->goal == FSM_PKGINSTALL) {
522 ptr = rpmtsNotify(ts, fi->te,
523 RPMCALLBACK_INST_START, 0, fi->archiveSize);
528 fsm->archiveSize = archiveSize;
529 if (fsm->archiveSize)
530 *fsm->archiveSize = 0;
531 fsm->failedFile = failedFile;
533 *fsm->failedFile = NULL;
537 memset(fsm->sufbuf, 0, sizeof(fsm->sufbuf));
538 if (fsm->goal == FSM_PKGINSTALL) {
539 if (ts && rpmtsGetTid(ts) > 0)
540 sprintf(fsm->sufbuf, ";%08x", (unsigned)rpmtsGetTid(ts));
544 rc = fsmStage(fsm, FSM_CREATE);
545 if (rc && !ec) ec = rc;
547 rc = fsmStage(fsm, fsm->goal);
548 if (rc && !ec) ec = rc;
551 if (fsm->archiveSize && ec == 0)
552 *fsm->archiveSize = (fdGetCpioPos(fsm->cfd) - pos);
558 int fsmTeardown(FSM_t fsm)
563 rc = fsmStage(fsm, FSM_DESTROY);
565 fsm->iter = mapFreeIterator(fsm->iter);
567 /*@-type@*/ /* FIX: cast? */
568 fsm->cfd = fdFree(fsm->cfd, "persist (fsm)");
572 fsm->failedFile = NULL;
576 int fsmMapPath(FSM_t fsm)
578 rpmfi fi = fsmGetFi(fsm); /* XXX const except for fstates */
585 fsm->action = FA_UNKNOWN;
589 if (fi && i >= 0 && i < fi->fc) {
591 fsm->astriplen = fi->astriplen;
592 fsm->action = (fi->actions ? fi->actions[i] : fi->action);
593 fsm->fflags = (fi->fflags ? fi->fflags[i] : fi->flags);
594 fsm->mapFlags = (fi->fmapflags ? fi->fmapflags[i] : fi->mapflags);
596 /* src rpms have simple base name in payload. */
597 fsm->dirName = fi->dnl[fi->dil[i]];
598 fsm->baseName = fi->bnl[i];
601 switch (fsm->action) {
604 case FA_SKIPMULTILIB: /* XXX RPMFILE_STATE_MULTILIB? */
613 assert(rpmteType(fi->te) == TR_ADDED);
617 if (fi->fstates && rpmteType(fi->te) == TR_ADDED)
618 fi->fstates[i] = RPMFILE_STATE_NOTINSTALLED;
621 case FA_SKIPNETSHARED:
622 if (fi->fstates && rpmteType(fi->te) == TR_ADDED)
623 fi->fstates[i] = RPMFILE_STATE_NETSHARED;
627 if (!(fsm->fflags & RPMFILE_GHOST)) /* XXX Don't if %ghost file. */
628 switch (rpmteType(fi->te)) {
630 fsm->osuffix = SUFFIX_RPMORIG;
631 /*@innerbreak@*/ break;
633 fsm->osuffix = SUFFIX_RPMSAVE;
634 /*@innerbreak@*/ break;
639 assert(rpmteType(fi->te) == TR_ADDED);
640 if (!(fsm->fflags & RPMFILE_GHOST)) /* XXX Don't if %ghost file. */
641 fsm->nsuffix = SUFFIX_RPMNEW;
645 assert(rpmteType(fi->te) == TR_ADDED);
646 if (!(fsm->fflags & RPMFILE_GHOST)) /* XXX Don't if %ghost file. */
647 fsm->osuffix = SUFFIX_RPMSAVE;
650 assert(rpmteType(fi->te) == TR_REMOVED);
652 * XXX TODO: %ghost probably shouldn't be removed, but that changes
653 * legacy rpm behavior.
661 if ((fsm->mapFlags & CPIO_MAP_PATH) || fsm->nsuffix) {
662 const struct stat * st = &fsm->sb;
663 fsm->path = _free(fsm->path);
664 fsm->path = fsmFsPath(fsm, st, fsm->subdir,
665 (fsm->suffix ? fsm->suffix : fsm->nsuffix));
671 int fsmMapAttrs(FSM_t fsm)
673 struct stat * st = &fsm->sb;
674 rpmfi fi = fsmGetFi(fsm);
677 if (fi && i >= 0 && i < fi->fc) {
679 (S_ISDIR(st->st_mode) ? fi->dperms : fi->fperms);
681 (fi->fmodes ? fi->fmodes[i] : perms);
683 (fi->fuids ? fi->fuids[i] : fi->uid); /* XXX chmod u-s */
685 (fi->fgids ? fi->fgids[i] : fi->gid); /* XXX chmod g-s */
687 (fi->frdevs ? fi->frdevs[i] : 0);
689 (fi->fmtimes ? fi->fmtimes[i] : 0);
691 if (fsm->mapFlags & CPIO_MAP_MODE)
692 st->st_mode = (st->st_mode & S_IFMT) | (finalMode & ~S_IFMT);
693 if (fsm->mapFlags & CPIO_MAP_TYPE) {
694 st->st_mode = (st->st_mode & ~S_IFMT) | (finalMode & S_IFMT);
695 if ((S_ISCHR(st->st_mode) || S_ISBLK(st->st_mode))
696 && st->st_nlink == 0)
698 st->st_rdev = finalRdev;
699 st->st_mtime = finalMtime;
701 if (fsm->mapFlags & CPIO_MAP_UID)
702 st->st_uid = finalUid;
703 if (fsm->mapFlags & CPIO_MAP_GID)
704 st->st_gid = finalGid;
706 { rpmts ts = fsmGetTs(fsm);
708 if (ts != NULL && !(rpmtsFlags(ts) & RPMTRANS_FLAG_NOMD5)) {
709 fsm->fmd5sum = (fi->fmd5s ? fi->fmd5s[i] : NULL);
710 fsm->md5sum = (fi->md5s ? (fi->md5s + (16 * i)) : NULL);
722 * Create file from payload stream.
723 * @param fsm file state machine data
724 * @return 0 on success
726 static int expandRegular(/*@special@*/ FSM_t fsm)
728 /*@globals fileSystem@*/
729 /*@modifies fsm, fileSystem @*/
731 const struct stat * st = &fsm->sb;
732 int left = st->st_size;
735 rc = fsmStage(fsm, FSM_WOPEN);
739 if (st->st_size > 0 && (fsm->fmd5sum || fsm->md5sum))
740 fdInitDigest(fsm->wfd, PGPHASHALGO_MD5, 0);
744 fsm->wrlen = (left > fsm->wrsize ? fsm->wrsize : left);
745 rc = fsmStage(fsm, FSM_DREAD);
749 rc = fsmStage(fsm, FSM_WRITE);
755 /* don't call this with fileSize == fileComplete */
757 (void) fsmStage(fsm, FSM_NOTIFY);
760 if (st->st_size > 0 && (fsm->fmd5sum || fsm->md5sum)) {
761 void * md5sum = NULL;
762 int asAscii = (fsm->md5sum == NULL ? 1 : 0);
764 (void) Fflush(fsm->wfd);
765 fdFiniDigest(fsm->wfd, PGPHASHALGO_MD5, &md5sum, NULL, asAscii);
767 if (md5sum == NULL) {
768 rc = CPIOERR_MD5SUM_MISMATCH;
772 if (fsm->md5sum != NULL) {
773 if (memcmp(md5sum, fsm->md5sum, 16))
774 rc = CPIOERR_MD5SUM_MISMATCH;
776 if (strcmp(md5sum, fsm->fmd5sum))
777 rc = CPIOERR_MD5SUM_MISMATCH;
779 md5sum = _free(md5sum);
783 (void) fsmStage(fsm, FSM_WCLOSE);
788 * Write next item to payload stream.
789 * @param fsm file state machine data
790 * @param writeData should data be written?
791 * @return 0 on success
793 static int writeFile(/*@special@*/ FSM_t fsm, int writeData)
794 /*@uses fsm->path, fsm->opath, fsm->sb, fsm->osb, fsm->cfd @*/
795 /*@globals fileSystem@*/
796 /*@modifies fsm, fileSystem @*/
798 const char * path = fsm->path;
799 const char * opath = fsm->opath;
800 struct stat * st = &fsm->sb;
801 struct stat * ost = &fsm->osb;
802 size_t pos = fdGetCpioPos(fsm->cfd);
803 char * symbuf = NULL;
808 st->st_size = (writeData ? ost->st_size : 0);
811 if (S_ISDIR(st->st_mode)) {
813 } else if (S_ISLNK(st->st_mode)) {
815 * While linux puts the size of a symlink in the st_size field,
816 * I don't think that's a specified standard.
818 /* XXX NUL terminated result in fsm->rdbuf, len in fsm->rdnb. */
819 rc = fsmStage(fsm, FSM_READLINK);
821 st->st_size = fsm->rdnb;
822 symbuf = alloca_strdup(fsm->rdbuf); /* XXX save readlink return. */
826 if (fsm->mapFlags & CPIO_MAP_ABSOLUTE) {
827 /*@-compdef@*/ /* FIX: dirName/baseName annotations ? */
829 int nb = strlen(fsm->dirName) + strlen(fsm->baseName) + sizeof(".");
830 char * t = alloca(nb);
833 if (fsm->mapFlags & CPIO_MAP_ADDDOT)
835 t = stpcpy( stpcpy(t, fsm->dirName), fsm->baseName);
838 } else if (fsm->mapFlags & CPIO_MAP_PATH) {
839 rpmfi fi = fsmGetFi(fsm);
841 (fi->apath ? fi->apath[fsm->ix] + fi->striplen : fi->bnl[fsm->ix]);
844 rc = fsmStage(fsm, FSM_HWRITE);
848 if (writeData && S_ISREG(st->st_mode)) {
851 void * mapped = (void *)-1;
855 rc = fsmStage(fsm, FSM_ROPEN);
858 /* XXX unbuffered mmap generates *lots* of fdio debugging */
861 mapped = mmap(NULL, st->st_size, PROT_READ, MAP_SHARED, Fileno(fsm->rfd), 0);
862 if (mapped != (void *)-1) {
864 fsm->rdbuf = (char *) mapped;
865 fsm->rdlen = nmapped = st->st_size;
866 #if defined(MADV_DONTNEED)
867 xx = madvise(mapped, nmapped, MADV_DONTNEED);
876 if (mapped != (void *)-1) {
881 fsm->rdlen = (left > fsm->rdsize ? fsm->rdsize : left),
882 rc = fsmStage(fsm, FSM_READ);
886 /* XXX DWRITE uses rdnb for I/O length. */
887 rc = fsmStage(fsm, FSM_DWRITE);
894 if (mapped != (void *)-1) {
895 xx = msync(mapped, nmapped, MS_ASYNC);
896 #if defined(MADV_DONTNEED)
897 xx = madvise(mapped, nmapped, MADV_DONTNEED);
899 /*@-noeffect@*/ xx = munmap(mapped, nmapped) /*@=noeffect@*/;
904 } else if (writeData && S_ISLNK(st->st_mode)) {
905 /* XXX DWRITE uses rdnb for I/O length. */
907 strcpy(fsm->rdbuf, symbuf); /* XXX restore readlink buffer. */
909 fsm->rdnb = strlen(symbuf);
910 rc = fsmStage(fsm, FSM_DWRITE);
914 rc = fsmStage(fsm, FSM_PAD);
917 { const rpmts ts = fsmGetTs(fsm);
918 rpmfi fi = fsmGetFi(fsm);
919 size_t size = (fdGetCpioPos(fsm->cfd) - pos);
921 ptr = rpmtsNotify(ts, fi->te, RPMCALLBACK_INST_PROGRESS, size, size);
928 (void) fsmStage(fsm, FSM_RCLOSE);
929 /*@-dependenttrans@*/
932 /*@=dependenttrans@*/
937 * Write set of linked files to payload stream.
938 * @param fsm file state machine data
939 * @return 0 on success
941 static int writeLinkedFile(/*@special@*/ FSM_t fsm)
942 /*@uses fsm->path, fsm->nsuffix, fsm->ix, fsm->li, fsm->failedFile @*/
943 /*@globals fileSystem@*/
944 /*@modifies fsm, fileSystem @*/
946 const char * path = fsm->path;
947 const char * nsuffix = fsm->nsuffix;
948 int iterIndex = fsm->ix;
958 for (i = fsm->li->nlink - 1; i >= 0; i--) {
960 if (fsm->li->filex[i] < 0) continue;
962 fsm->ix = fsm->li->filex[i];
963 rc = fsmStage(fsm, FSM_MAP);
965 /* Write data after last link. */
966 rc = writeFile(fsm, (i == 0));
967 if (fsm->failedFile && rc != 0 && *fsm->failedFile == NULL) {
969 *fsm->failedFile = xstrdup(fsm->path);
972 fsm->path = _free(fsm->path);
973 fsm->li->filex[i] = -1;
978 fsm->nsuffix = nsuffix;
984 * Create pending hard links to existing file.
985 * @param fsm file state machine data
986 * @return 0 on success
988 static int fsmMakeLinks(/*@special@*/ FSM_t fsm)
989 /*@uses fsm->path, fsm->opath, fsm->nsuffix, fsm->ix, fsm->li @*/
990 /*@globals fileSystem@*/
991 /*@modifies fsm, fileSystem @*/
993 const char * path = fsm->path;
994 const char * opath = fsm->opath;
995 const char * nsuffix = fsm->nsuffix;
996 int iterIndex = fsm->ix;
1003 fsm->nsuffix = NULL;
1006 fsm->ix = fsm->li->filex[fsm->li->createdPath];
1007 rc = fsmStage(fsm, FSM_MAP);
1008 fsm->opath = fsm->path;
1011 for (i = 0; i < fsm->li->nlink; i++) {
1012 if (fsm->li->filex[i] < 0) continue;
1013 if (fsm->li->createdPath == i) continue;
1015 fsm->ix = fsm->li->filex[i];
1016 fsm->path = _free(fsm->path);
1017 rc = fsmStage(fsm, FSM_MAP);
1018 if (XFA_SKIPPING(fsm->action)) continue;
1020 rc = fsmStage(fsm, FSM_VERIFY);
1022 if (rc != CPIOERR_LSTAT_FAILED) break;
1024 /* XXX link(fsm->opath, fsm->path) */
1025 rc = fsmStage(fsm, FSM_LINK);
1026 if (fsm->failedFile && rc != 0 && *fsm->failedFile == NULL) {
1029 *fsm->failedFile = xstrdup(fsm->path);
1033 fsm->li->linksLeft--;
1036 fsm->path = _free(fsm->path);
1037 fsm->opath = _free(fsm->opath);
1039 fsm->ix = iterIndex;
1040 fsm->nsuffix = nsuffix;
1046 /** \ingroup payload
1047 * Commit hard linked file set atomically.
1048 * @param fsm file state machine data
1049 * @return 0 on success
1051 static int fsmCommitLinks(/*@special@*/ FSM_t fsm)
1052 /*@uses fsm->path, fsm->nsuffix, fsm->ix, fsm->sb,
1053 fsm->li, fsm->links @*/
1054 /*@globals fileSystem@*/
1055 /*@modifies fsm, fileSystem @*/
1057 const char * path = fsm->path;
1058 const char * nsuffix = fsm->nsuffix;
1059 int iterIndex = fsm->ix;
1060 struct stat * st = &fsm->sb;
1065 fsm->nsuffix = NULL;
1069 for (fsm->li = fsm->links; fsm->li; fsm->li = fsm->li->next) {
1070 if (fsm->li->sb.st_ino == st->st_ino && fsm->li->sb.st_dev == st->st_dev)
1076 for (i = 0; i < fsm->li->nlink; i++) {
1077 if (fsm->li->filex[i] < 0) continue;
1078 fsm->ix = fsm->li->filex[i];
1079 rc = fsmStage(fsm, FSM_MAP);
1080 if (!XFA_SKIPPING(fsm->action))
1081 rc = fsmStage(fsm, FSM_COMMIT);
1082 fsm->path = _free(fsm->path);
1083 fsm->li->filex[i] = -1;
1087 fsm->ix = iterIndex;
1088 fsm->nsuffix = nsuffix;
1094 * Remove (if created) directories not explicitly included in package.
1095 * @param fsm file state machine data
1096 * @return 0 on success
1098 static int fsmRmdirs(/*@special@*/ FSM_t fsm)
1099 /*@uses fsm->path, fsm->dnlx, fsm->ldn, fsm->rdbuf, fsm->iter @*/
1100 /*@globals fileSystem@*/
1101 /*@modifies fsm, fileSystem @*/
1103 const char * path = fsm->path;
1104 void * dnli = dnlInitIterator(fsm, 1);
1105 char * dn = fsm->rdbuf;
1106 int dc = dnlCount(dnli);
1112 /*@-observertrans -dependenttrans@*/
1113 if (fsm->ldn != NULL && fsm->dnlx != NULL)
1114 while ((fsm->path = dnlNextIterator(dnli)) != NULL) {
1115 int dnlen = strlen(fsm->path);
1118 dc = dnlIndex(dnli);
1119 if (fsm->dnlx[dc] < 1 || fsm->dnlx[dc] >= dnlen)
1122 /* Copy to avoid const on fsm->path. */
1123 te = stpcpy(dn, fsm->path) - 1;
1126 /* Remove generated directories. */
1127 /*@-usereleased@*/ /* LCL: te used after release? */
1131 rc = fsmStage(fsm, FSM_RMDIR);
1135 /*@innerbreak@*/ break;
1137 } while ((te - fsm->path) > fsm->dnlx[dc]);
1141 dnli = dnlFreeIterator(dnli);
1142 /*@=observertrans =dependenttrans@*/
1149 * Create (if necessary) directories not explicitly included in package.
1150 * @param fsm file state machine data
1151 * @return 0 on success
1153 static int fsmMkdirs(/*@special@*/ FSM_t fsm)
1154 /*@uses fsm->path, fsm->sb, fsm->osb, fsm->rdbuf, fsm->iter,
1155 fsm->ldn, fsm->ldnlen, fsm->ldnalloc @*/
1156 /*@defines fsm->dnlx, fsm->ldn @*/
1157 /*@globals fileSystem@*/
1158 /*@modifies fsm, fileSystem @*/
1160 struct stat * st = &fsm->sb;
1161 struct stat * ost = &fsm->osb;
1162 const char * path = fsm->path;
1163 mode_t st_mode = st->st_mode;
1164 void * dnli = dnlInitIterator(fsm, 0);
1165 char * dn = fsm->rdbuf;
1166 int dc = dnlCount(dnli);
1174 fsm->dnlx = (dc ? xcalloc(dc, sizeof(*fsm->dnlx)) : NULL);
1175 /*@-observertrans -dependenttrans@*/
1176 if (fsm->dnlx != NULL)
1177 while ((fsm->path = dnlNextIterator(dnli)) != NULL) {
1178 int dnlen = strlen(fsm->path);
1181 dc = dnlIndex(dnli);
1182 if (dc < 0) continue;
1183 fsm->dnlx[dc] = dnlen;
1187 /*@-compdef -nullpass@*/ /* FIX: fsm->ldn not defined ??? */
1188 if (dnlen <= fsm->ldnlen && !strcmp(fsm->path, fsm->ldn))
1190 /*@=compdef =nullpass@*/
1192 /* Copy to avoid const on fsm->path. */
1193 (void) stpcpy(dn, fsm->path);
1196 /* Assume '/' directory exists, "mkdir -p" for others if non-existent */
1197 for (i = 1, te = dn + 1; *te != '\0'; te++, i++) {
1199 /*@innercontinue@*/ continue;
1203 /* Already validated? */
1204 /*@-usedef -compdef -nullpass -nullderef@*/
1205 if (i < fsm->ldnlen &&
1206 (fsm->ldn[i] == '/' || fsm->ldn[i] == '\0') &&
1207 !strncmp(fsm->path, fsm->ldn, i))
1210 /* Move pre-existing path marker forward. */
1211 fsm->dnlx[dc] = (te - dn);
1212 /*@innercontinue@*/ continue;
1214 /*@=usedef =compdef =nullpass =nullderef@*/
1216 /* Validate next component of path. */
1217 rc = fsmStage(fsm, FSM_LSTAT);
1220 /* Directory already exists? */
1221 if (rc == 0 && S_ISDIR(ost->st_mode)) {
1222 /* Move pre-existing path marker forward. */
1223 fsm->dnlx[dc] = (te - dn);
1224 } else if (rc == CPIOERR_LSTAT_FAILED) {
1225 rpmfi fi = fsmGetFi(fsm);
1227 st->st_mode = S_IFDIR | (fi->dperms & 07777);
1228 rc = fsmStage(fsm, FSM_MKDIR);
1230 rpmMessage(RPMMESS_DEBUG,
1231 _("%s directory created with perms %04o.\n"),
1232 fsm->path, (unsigned)(st->st_mode & 07777));
1236 /*@innerbreak@*/ break;
1240 /* Save last validated path. */
1241 /*@-compdef@*/ /* FIX: ldn/path annotations ? */
1242 if (fsm->ldnalloc < (dnlen + 1)) {
1243 fsm->ldnalloc = dnlen + 100;
1244 fsm->ldn = xrealloc(fsm->ldn, fsm->ldnalloc);
1246 if (fsm->ldn != NULL) { /* XXX can't happen */
1247 strcpy(fsm->ldn, fsm->path);
1248 fsm->ldnlen = dnlen;
1253 dnli = dnlFreeIterator(dnli);
1254 /*@=observertrans =dependenttrans@*/
1257 st->st_mode = st_mode; /* XXX restore st->st_mode */
1258 /*@-compdef@*/ /* FIX: ldn/path annotations ? */
1265 * Check for file on disk.
1266 * @param fsm file state machine data
1267 * @return 0 on success
1269 static int fsmStat(FSM_t fsm)
1271 int saveerrno = errno;
1274 if (fsm->path != NULL) {
1275 int saveernno = errno;
1276 rc = fsmStage(fsm, (!(fsm->mapFlags & CPIO_FOLLOW_SYMLINKS)
1277 ? FSM_LSTAT : FSM_STAT));
1278 if (rc == CPIOERR_LSTAT_FAILED && errno == ENOENT) {
1282 } else if (rc == 0) {
1286 /* Skip %ghost files on build. */
1293 #define IS_DEV_LOG(_x) \
1294 ((_x) != NULL && strlen(_x) >= (sizeof("/dev/log")-1) && \
1295 !strncmp((_x), "/dev/log", sizeof("/dev/log")-1) && \
1296 ((_x)[sizeof("/dev/log")-1] == '\0' || \
1297 (_x)[sizeof("/dev/log")-1] == ';'))
1300 int fsmStage(FSM_t fsm, fileStage stage)
1303 fileStage prevStage = fsm->stage;
1304 const char * const prev = fileStageString(prevStage);
1306 static int modulo = 4;
1307 const char * const cur = fileStageString(stage);
1308 struct stat * st = &fsm->sb;
1309 struct stat * ost = &fsm->osb;
1310 int saveerrno = errno;
1315 #define _fafilter(_a) \
1316 (!((_a) == FA_CREATE || (_a) == FA_ERASE || (_a) == FA_COPYIN || (_a) == FA_COPYOUT) \
1317 ? fileActionString(_a) : "")
1319 if (stage & FSM_DEAD) {
1321 } else if (stage & FSM_INTERNAL) {
1322 if (_fsm_debug && !(stage & FSM_SYSCALL))
1323 rpmMessage(RPMMESS_DEBUG, " %8s %06o%3d (%4d,%4d)%10d %s %s\n",
1325 (unsigned)st->st_mode, (int)st->st_nlink,
1326 (int)st->st_uid, (int)st->st_gid, (int)st->st_size,
1327 (fsm->path ? fsm->path : ""),
1328 _fafilter(fsm->action));
1331 if (_fsm_debug || !(stage & FSM_VERBOSE))
1332 rpmMessage(RPMMESS_DEBUG, "%-8s %06o%3d (%4d,%4d)%10d %s %s\n",
1334 (unsigned)st->st_mode, (int)st->st_nlink,
1335 (int)st->st_uid, (int)st->st_gid, (int)st->st_size,
1336 (fsm->path ? fsm->path + fsm->astriplen : ""),
1337 _fafilter(fsm->action));
1345 case FSM_PKGINSTALL:
1347 /* Clean fsm, free'ing memory. Read next archive header. */
1348 rc = fsmStage(fsm, FSM_INIT);
1350 /* Exit on end-of-payload. */
1351 if (rc == CPIOERR_HDR_TRAILER) {
1353 /*@loopbreak@*/ break;
1356 /* Exit on error. */
1359 (void) fsmStage(fsm, FSM_UNDO);
1360 /*@loopbreak@*/ break;
1363 /* Extract file from archive. */
1364 rc = fsmStage(fsm, FSM_PROCESS);
1366 (void) fsmStage(fsm, FSM_UNDO);
1367 /*@loopbreak@*/ break;
1370 /* Notify on success. */
1371 (void) fsmStage(fsm, FSM_NOTIFY);
1373 rc = fsmStage(fsm, FSM_FINI);
1375 /*@loopbreak@*/ break;
1382 /* Clean fsm, free'ing memory. */
1383 rc = fsmStage(fsm, FSM_INIT);
1385 /* Exit on end-of-payload. */
1386 if (rc == CPIOERR_HDR_TRAILER) {
1388 /*@loopbreak@*/ break;
1391 /* Rename/erase next item. */
1392 if (fsmStage(fsm, FSM_FINI))
1393 /*@loopbreak@*/ break;
1399 rc = fsmStage(fsm, FSM_INIT);
1401 /* Exit on end-of-payload. */
1402 if (rc == CPIOERR_HDR_TRAILER) {
1404 /*@loopbreak@*/ break;
1407 /* Exit on error. */
1410 (void) fsmStage(fsm, FSM_UNDO);
1411 /*@loopbreak@*/ break;
1414 /* Copy file into archive. */
1415 rc = fsmStage(fsm, FSM_PROCESS);
1417 (void) fsmStage(fsm, FSM_UNDO);
1418 /*@loopbreak@*/ break;
1421 if (fsmStage(fsm, FSM_FINI))
1422 /*@loopbreak@*/ break;
1425 /* Flush partial sets of hard linked files. */
1426 if (!(fsm->mapFlags & CPIO_ALL_HARDLINKS)) {
1428 while ((fsm->li = fsm->links) != NULL) {
1429 fsm->links = fsm->li->next;
1430 fsm->li->next = NULL;
1432 /* Re-calculate link count for archive header. */
1433 for (j = -1, nlink = 0, i = 0; i < fsm->li->nlink; i++) {
1434 if (fsm->li->filex[i] < 0)
1435 /*@innercontinue@*/ continue;
1439 /* XXX force the contents out as well. */
1442 fsm->li->filex[0] = fsm->li->filex[j];
1443 fsm->li->filex[j] = -1;
1446 fsm->li->sb.st_nlink = nlink;
1448 fsm->sb = fsm->li->sb; /* structure assignment */
1449 fsm->osb = fsm->sb; /* structure assignment */
1451 if (!rc) rc = writeLinkedFile(fsm);
1453 fsm->li = freeHardLink(fsm->li);
1458 rc = fsmStage(fsm, FSM_TRAILER);
1462 { rpmts ts = fsmGetTs(fsm);
1463 #define _tsmask (RPMTRANS_FLAG_PKGCOMMIT | RPMTRANS_FLAG_COMMIT)
1464 fsm->commit = ((ts && (rpmtsFlags(ts) & _tsmask) &&
1465 fsm->goal != FSM_PKGCOMMIT) ? 0 : 1);
1468 fsm->path = _free(fsm->path);
1469 fsm->opath = _free(fsm->opath);
1470 fsm->dnlx = _free(fsm->dnlx);
1472 fsm->ldn = _free(fsm->ldn);
1473 fsm->ldnalloc = fsm->ldnlen = 0;
1475 fsm->rdsize = fsm->wrsize = 0;
1476 fsm->rdbuf = fsm->rdb = _free(fsm->rdb);
1477 fsm->wrbuf = fsm->wrb = _free(fsm->wrb);
1478 if (fsm->goal == FSM_PKGINSTALL || fsm->goal == FSM_PKGBUILD) {
1479 fsm->rdsize = 8 * BUFSIZ;
1480 fsm->rdbuf = fsm->rdb = xmalloc(fsm->rdsize);
1481 fsm->wrsize = 8 * BUFSIZ;
1482 fsm->wrbuf = fsm->wrb = xmalloc(fsm->wrsize);
1485 fsm->mkdirsdone = 0;
1490 errno = 0; /* XXX get rid of EBADF */
1493 /* Detect and create directories not explicitly in package. */
1494 if (fsm->goal == FSM_PKGINSTALL) {
1495 rc = fsmStage(fsm, FSM_MKDIRS);
1496 if (!rc) fsm->mkdirsdone = 1;
1501 fsm->path = _free(fsm->path);
1503 fsm->diskchecked = fsm->exists = 0;
1505 fsm->suffix = (fsm->sufbuf[0] != '\0' ? fsm->sufbuf : NULL);
1506 fsm->action = FA_UNKNOWN;
1507 fsm->osuffix = NULL;
1508 fsm->nsuffix = NULL;
1510 if (fsm->goal == FSM_PKGINSTALL) {
1511 /* Read next header from payload, checking for end-of-payload. */
1512 rc = fsmStage(fsm, FSM_NEXT);
1516 /* Identify mapping index. */
1517 fsm->ix = ((fsm->goal == FSM_PKGINSTALL)
1518 ? mapFind(fsm->iter, fsm->path) : mapNextIterator(fsm->iter));
1520 /* Detect end-of-loop and/or mapping error. */
1522 if (fsm->goal == FSM_PKGINSTALL) {
1524 rpmMessage(RPMMESS_WARNING,
1525 _("archive file %s was not found in header file list\n"),
1529 if (fsm->failedFile && *fsm->failedFile == NULL)
1530 *fsm->failedFile = xstrdup(fsm->path);
1532 rc = CPIOERR_UNMAPPED_FILE;
1534 rc = CPIOERR_HDR_TRAILER;
1539 /* On non-install, mode must be known so that dirs don't get suffix. */
1540 if (fsm->goal != FSM_PKGINSTALL) {
1541 rpmfi fi = fsmGetFi(fsm);
1542 st->st_mode = fi->fmodes[fsm->ix];
1545 /* Generate file path. */
1546 rc = fsmStage(fsm, FSM_MAP);
1549 /* Perform lstat/stat for disk file. */
1553 if (fsm->path != NULL &&
1554 !(fsm->goal == FSM_PKGINSTALL && S_ISREG(st->st_mode)))
1556 rc = fsmStage(fsm, (!(fsm->mapFlags & CPIO_FOLLOW_SYMLINKS)
1557 ? FSM_LSTAT : FSM_STAT));
1558 if (rc == CPIOERR_LSTAT_FAILED && errno == ENOENT) {
1564 } else if (rc == 0) {
1568 /* Skip %ghost files on build. */
1572 fsm->diskchecked = 1;
1575 /* On non-install, the disk file stat is what's remapped. */
1577 if (fsm->goal != FSM_PKGINSTALL)
1578 *st = *ost; /* structure assignment */
1581 /* Remap file perms, owner, and group. */
1582 rc = fsmMapAttrs(fsm);
1585 fsm->postpone = XFA_SKIPPING(fsm->action);
1586 if (fsm->goal == FSM_PKGINSTALL || fsm->goal == FSM_PKGBUILD) {
1587 /*@-evalorder@*/ /* FIX: saveHardLink can modify fsm */
1588 if (!S_ISDIR(st->st_mode) && st->st_nlink > 1)
1589 fsm->postpone = saveHardLink(fsm);
1596 rc = fsmMapPath(fsm);
1599 rc = fsmMkdirs(fsm);
1603 rc = fsmRmdirs(fsm);
1606 if (fsm->postpone) {
1607 if (fsm->goal == FSM_PKGINSTALL)
1608 rc = fsmStage(fsm, FSM_EAT);
1612 if (fsm->goal == FSM_PKGBUILD) {
1613 if (!S_ISDIR(st->st_mode) && st->st_nlink > 1) {
1614 struct hardLink_s * li, * prev;
1616 if (!(fsm->mapFlags & CPIO_ALL_HARDLINKS)) break;
1617 rc = writeLinkedFile(fsm);
1618 if (rc) break; /* W2DO? */
1620 for (li = fsm->links, prev = NULL; li; prev = li, li = li->next)
1622 /*@loopbreak@*/ break;
1625 fsm->links = fsm->li->next;
1627 prev->next = fsm->li->next;
1628 fsm->li->next = NULL;
1629 fsm->li = freeHardLink(fsm->li);
1631 rc = writeFile(fsm, 1);
1636 if (fsm->goal != FSM_PKGINSTALL)
1639 if (S_ISREG(st->st_mode)) {
1640 const char * path = fsm->path;
1642 fsm->path = fsmFsPath(fsm, st, NULL, NULL);
1643 rc = fsmStage(fsm, FSM_VERIFY);
1645 if (rc == 0 && fsm->osuffix) {
1646 const char * opath = fsm->opath;
1647 fsm->opath = fsm->path;
1648 fsm->path = fsmFsPath(fsm, st, NULL, fsm->osuffix);
1649 rc = fsmStage(fsm, FSM_RENAME);
1651 rpmMessage(RPMMESS_WARNING,
1652 _("%s saved as %s\n"), fsm->opath, fsm->path);
1653 fsm->path = _free(fsm->path);
1657 /*@-dependenttrans@*/
1659 /*@=dependenttrans@*/
1660 if (rc != CPIOERR_LSTAT_FAILED) return rc;
1661 rc = expandRegular(fsm);
1662 } else if (S_ISDIR(st->st_mode)) {
1663 mode_t st_mode = st->st_mode;
1664 rc = fsmStage(fsm, FSM_VERIFY);
1665 if (rc == CPIOERR_LSTAT_FAILED) {
1666 st->st_mode &= ~07777; /* XXX abuse st->st_mode */
1667 st->st_mode |= 00700;
1668 rc = fsmStage(fsm, FSM_MKDIR);
1669 st->st_mode = st_mode; /* XXX restore st->st_mode */
1671 } else if (S_ISLNK(st->st_mode)) {
1672 const char * opath = fsm->opath;
1674 if ((st->st_size + 1) > fsm->rdsize) {
1675 rc = CPIOERR_HDR_SIZE;
1679 fsm->wrlen = st->st_size;
1680 rc = fsmStage(fsm, FSM_DREAD);
1681 if (!rc && fsm->rdnb != fsm->wrlen)
1682 rc = CPIOERR_READ_FAILED;
1686 fsm->wrbuf[st->st_size] = '\0';
1688 /* XXX symlink(fsm->opath, fsm->path) */
1689 /*@-dependenttrans@*/
1690 fsm->opath = fsm->wrbuf;
1691 /*@=dependenttrans@*/
1692 rc = fsmStage(fsm, FSM_VERIFY);
1693 if (rc == CPIOERR_LSTAT_FAILED)
1694 rc = fsmStage(fsm, FSM_SYMLINK);
1695 fsm->opath = opath; /* XXX restore fsm->path */
1696 } else if (S_ISFIFO(st->st_mode)) {
1697 mode_t st_mode = st->st_mode;
1698 /* This mimics cpio S_ISSOCK() behavior but probably isnt' right */
1699 rc = fsmStage(fsm, FSM_VERIFY);
1700 if (rc == CPIOERR_LSTAT_FAILED) {
1701 st->st_mode = 0000; /* XXX abuse st->st_mode */
1702 rc = fsmStage(fsm, FSM_MKFIFO);
1703 st->st_mode = st_mode; /* XXX restore st->st_mode */
1705 } else if (S_ISCHR(st->st_mode) ||
1706 S_ISBLK(st->st_mode) ||
1707 /*@-unrecog@*/ S_ISSOCK(st->st_mode) /*@=unrecog@*/)
1709 rc = fsmStage(fsm, FSM_VERIFY);
1710 if (rc == CPIOERR_LSTAT_FAILED)
1711 rc = fsmStage(fsm, FSM_MKNOD);
1713 /* XXX Special case /dev/log, which shouldn't be packaged anyways */
1714 if (!IS_DEV_LOG(fsm->path))
1715 rc = CPIOERR_UNKNOWN_FILETYPE;
1717 if (!S_ISDIR(st->st_mode) && st->st_nlink > 1) {
1718 fsm->li->createdPath = fsm->li->linkIndex;
1719 rc = fsmMakeLinks(fsm);
1725 rc = fsmMakeLinks(fsm);
1727 case FSM_NOTIFY: /* XXX move from fsm to psm -> tsm */
1728 if (fsm->goal == FSM_PKGINSTALL || fsm->goal == FSM_PKGBUILD) {
1729 rpmts ts = fsmGetTs(fsm);
1730 rpmfi fi = fsmGetFi(fsm);
1732 ptr = rpmtsNotify(ts, fi->te, RPMCALLBACK_INST_PROGRESS,
1733 fdGetCpioPos(fsm->cfd), fi->archiveSize);
1739 if (fsm->goal == FSM_PKGINSTALL) {
1740 (void) fsmStage(fsm,
1741 (S_ISDIR(st->st_mode) ? FSM_RMDIR : FSM_UNLINK));
1743 #ifdef NOTYET /* XXX remove only dirs just created, not all. */
1745 (void) fsmStage(fsm, FSM_RMDIRS);
1752 if (fsm->failedFile && *fsm->failedFile == NULL)
1753 *fsm->failedFile = xstrdup(fsm->path);
1757 if (!fsm->postpone && fsm->commit) {
1758 if (fsm->goal == FSM_PKGINSTALL)
1759 rc = ((!S_ISDIR(st->st_mode) && st->st_nlink > 1)
1760 ? fsmCommitLinks(fsm) : fsmStage(fsm, FSM_COMMIT));
1761 if (fsm->goal == FSM_PKGCOMMIT)
1762 rc = fsmStage(fsm, FSM_COMMIT);
1763 if (fsm->goal == FSM_PKGERASE)
1764 rc = fsmStage(fsm, FSM_COMMIT);
1766 fsm->path = _free(fsm->path);
1767 fsm->opath = _free(fsm->opath);
1769 memset(st, 0, sizeof(*st));
1770 memset(ost, 0, sizeof(*ost));
1774 /* Rename pre-existing modified or unmanaged file. */
1775 if (fsm->osuffix && fsm->diskchecked &&
1776 (fsm->exists || (fsm->goal == FSM_PKGINSTALL && S_ISREG(st->st_mode))))
1778 const char * opath = fsm->opath;
1779 const char * path = fsm->path;
1780 fsm->opath = fsmFsPath(fsm, st, NULL, NULL);
1781 fsm->path = fsmFsPath(fsm, st, NULL, fsm->osuffix);
1782 rc = fsmStage(fsm, FSM_RENAME);
1784 rpmMessage(RPMMESS_WARNING, _("%s saved as %s\n"),
1785 fsm->opath, fsm->path);
1787 fsm->path = _free(fsm->path);
1789 fsm->opath = _free(fsm->opath);
1793 /* Remove erased files. */
1794 if (fsm->goal == FSM_PKGERASE) {
1795 if (fsm->action == FA_ERASE) {
1796 rpmfi fi = fsmGetFi(fsm);
1797 if (S_ISDIR(st->st_mode)) {
1798 rc = fsmStage(fsm, FSM_RMDIR);
1801 case ENOENT: /* XXX rmdir("/") linux 2.2.x kernel hack */
1803 /* XXX make sure that build side permits %missingok on directories. */
1804 if (fsm->fflags & RPMFILE_MISSINGOK)
1805 /*@innerbreak@*/ break;
1807 /* XXX common error message. */
1809 (strict_erasures ? RPMERR_RMDIR : RPMDEBUG_RMDIR),
1810 _("%s rmdir of %s failed: Directory not empty\n"),
1811 fiTypeString(fi), fsm->path);
1812 /*@innerbreak@*/ break;
1815 (strict_erasures ? RPMERR_RMDIR : RPMDEBUG_RMDIR),
1816 _("%s rmdir of %s failed: %s\n"),
1817 fiTypeString(fi), fsm->path, strerror(errno));
1818 /*@innerbreak@*/ break;
1821 rc = fsmStage(fsm, FSM_UNLINK);
1823 if (!(errno == ENOENT && (fsm->fflags & RPMFILE_MISSINGOK)))
1825 (strict_erasures ? RPMERR_UNLINK : RPMDEBUG_UNLINK),
1826 _("%s unlink of %s failed: %s\n"),
1827 fiTypeString(fi), fsm->path, strerror(errno));
1830 /* XXX Failure to remove is not (yet) cause for failure. */
1831 if (!strict_erasures) rc = 0;
1835 /* XXX Special case /dev/log, which shouldn't be packaged anyways */
1836 if (!S_ISSOCK(st->st_mode) && !IS_DEV_LOG(fsm->path)) {
1837 /* Rename temporary to final file name. */
1838 if (!S_ISDIR(st->st_mode) &&
1839 (fsm->subdir || fsm->suffix || fsm->nsuffix))
1841 fsm->opath = fsm->path;
1842 fsm->path = fsmFsPath(fsm, st, NULL, fsm->nsuffix);
1843 rc = fsmStage(fsm, FSM_RENAME);
1844 if (!rc && fsm->nsuffix) {
1845 const char * opath = fsmFsPath(fsm, st, NULL, NULL);
1846 rpmMessage(RPMMESS_WARNING, _("%s created as %s\n"),
1847 (opath ? opath : ""), fsm->path);
1848 opath = _free(opath);
1850 fsm->opath = _free(fsm->opath);
1852 if (S_ISLNK(st->st_mode)) {
1853 if (!rc && !getuid())
1854 rc = fsmStage(fsm, FSM_LCHOWN);
1856 if (!rc && !getuid())
1857 rc = fsmStage(fsm, FSM_CHOWN);
1859 rc = fsmStage(fsm, FSM_CHMOD);
1861 time_t mtime = st->st_mtime;
1862 rpmfi fi = fsmGetFi(fsm);
1864 st->st_mtime = fi->fmtimes[fsm->ix];
1865 rc = fsmStage(fsm, FSM_UTIME);
1866 st->st_mtime = mtime;
1871 /* Notify on success. */
1872 if (!rc) rc = fsmStage(fsm, FSM_NOTIFY);
1873 else if (fsm->failedFile && *fsm->failedFile == NULL) {
1875 *fsm->failedFile = fsm->path;
1881 fsm->path = _free(fsm->path);
1883 /* Check for hard links missing from payload. */
1884 while ((fsm->li = fsm->links) != NULL) {
1885 fsm->links = fsm->li->next;
1886 fsm->li->next = NULL;
1887 if (fsm->goal == FSM_PKGINSTALL &&
1888 fsm->commit && fsm->li->linksLeft)
1890 for (i = 0 ; i < fsm->li->linksLeft; i++) {
1891 if (fsm->li->filex[i] < 0)
1892 /*@innercontinue@*/ continue;
1893 rc = CPIOERR_MISSING_HARDLINK;
1894 if (fsm->failedFile && *fsm->failedFile == NULL) {
1895 fsm->ix = fsm->li->filex[i];
1896 if (!fsmStage(fsm, FSM_MAP)) {
1898 *fsm->failedFile = fsm->path;
1903 /*@loopbreak@*/ break;
1906 if (fsm->goal == FSM_PKGBUILD &&
1907 (fsm->mapFlags & CPIO_ALL_HARDLINKS))
1909 rc = CPIOERR_MISSING_HARDLINK;
1911 fsm->li = freeHardLink(fsm->li);
1913 fsm->ldn = _free(fsm->ldn);
1914 fsm->ldnalloc = fsm->ldnlen = 0;
1915 fsm->rdbuf = fsm->rdb = _free(fsm->rdb);
1916 fsm->wrbuf = fsm->wrb = _free(fsm->wrb);
1919 if (fsm->diskchecked && !fsm->exists) {
1920 rc = CPIOERR_LSTAT_FAILED;
1923 if (S_ISREG(st->st_mode)) {
1924 char * path = alloca(strlen(fsm->path) + sizeof("-RPMDELETE"));
1926 (void) stpcpy( stpcpy(path, fsm->path), "-RPMDELETE");
1929 * XXX HP-UX (and other os'es) don't permit unlink on busy
1932 fsm->opath = fsm->path;
1934 rc = fsmStage(fsm, FSM_RENAME);
1936 (void) fsmStage(fsm, FSM_UNLINK);
1938 rc = CPIOERR_UNLINK_FAILED;
1939 fsm->path = fsm->opath;
1941 return (rc ? rc : CPIOERR_LSTAT_FAILED); /* XXX HACK */
1942 /*@notreached@*/ break;
1943 } else if (S_ISDIR(st->st_mode)) {
1944 if (S_ISDIR(ost->st_mode)) return 0;
1945 if (S_ISLNK(ost->st_mode)) {
1946 rc = fsmStage(fsm, FSM_STAT);
1947 if (rc == CPIOERR_STAT_FAILED && errno == ENOENT) rc = 0;
1952 if (S_ISDIR(ost->st_mode)) return 0;
1954 } else if (S_ISLNK(st->st_mode)) {
1955 if (S_ISLNK(ost->st_mode)) {
1956 /* XXX NUL terminated result in fsm->rdbuf, len in fsm->rdnb. */
1957 rc = fsmStage(fsm, FSM_READLINK);
1962 if (!strcmp(fsm->opath, fsm->rdbuf)) return 0;
1964 } else if (S_ISFIFO(st->st_mode)) {
1965 if (S_ISFIFO(ost->st_mode)) return 0;
1966 } else if (S_ISCHR(st->st_mode) || S_ISBLK(st->st_mode)) {
1967 if ((S_ISCHR(ost->st_mode) || S_ISBLK(ost->st_mode)) &&
1968 (ost->st_rdev == st->st_rdev)) return 0;
1969 } else if (S_ISSOCK(st->st_mode)) {
1970 if (S_ISSOCK(ost->st_mode)) return 0;
1972 /* XXX shouldn't do this with commit/undo. */
1974 if (fsm->stage == FSM_PROCESS) rc = fsmStage(fsm, FSM_UNLINK);
1975 if (rc == 0) rc = CPIOERR_LSTAT_FAILED;
1976 return (rc ? rc : CPIOERR_LSTAT_FAILED); /* XXX HACK */
1977 /*@notreached@*/ break;
1980 rc = Unlink(fsm->path);
1981 if (_fsm_debug && (stage & FSM_SYSCALL))
1982 rpmMessage(RPMMESS_DEBUG, " %8s (%s) %s\n", cur,
1983 fsm->path, (rc < 0 ? strerror(errno) : ""));
1984 if (rc < 0) rc = CPIOERR_UNLINK_FAILED;
1987 rc = Rename(fsm->opath, fsm->path);
1988 if (_fsm_debug && (stage & FSM_SYSCALL))
1989 rpmMessage(RPMMESS_DEBUG, " %8s (%s, %s) %s\n", cur,
1990 fsm->opath, fsm->path, (rc < 0 ? strerror(errno) : ""));
1991 if (rc < 0) rc = CPIOERR_RENAME_FAILED;
1994 rc = Mkdir(fsm->path, (st->st_mode & 07777));
1995 if (_fsm_debug && (stage & FSM_SYSCALL))
1996 rpmMessage(RPMMESS_DEBUG, " %8s (%s, 0%04o) %s\n", cur,
1997 fsm->path, (unsigned)(st->st_mode & 07777),
1998 (rc < 0 ? strerror(errno) : ""));
1999 if (rc < 0) rc = CPIOERR_MKDIR_FAILED;
2002 rc = Rmdir(fsm->path);
2003 if (_fsm_debug && (stage & FSM_SYSCALL))
2004 rpmMessage(RPMMESS_DEBUG, " %8s (%s) %s\n", cur,
2005 fsm->path, (rc < 0 ? strerror(errno) : ""));
2006 if (rc < 0) rc = CPIOERR_RMDIR_FAILED;
2009 rc = chown(fsm->path, st->st_uid, st->st_gid);
2010 if (_fsm_debug && (stage & FSM_SYSCALL))
2011 rpmMessage(RPMMESS_DEBUG, " %8s (%s, %d, %d) %s\n", cur,
2012 fsm->path, (int)st->st_uid, (int)st->st_gid,
2013 (rc < 0 ? strerror(errno) : ""));
2014 if (rc < 0) rc = CPIOERR_CHOWN_FAILED;
2017 #if ! CHOWN_FOLLOWS_SYMLINK
2018 rc = lchown(fsm->path, st->st_uid, st->st_gid);
2019 if (_fsm_debug && (stage & FSM_SYSCALL))
2020 rpmMessage(RPMMESS_DEBUG, " %8s (%s, %d, %d) %s\n", cur,
2021 fsm->path, (int)st->st_uid, (int)st->st_gid,
2022 (rc < 0 ? strerror(errno) : ""));
2023 if (rc < 0) rc = CPIOERR_CHOWN_FAILED;
2027 rc = chmod(fsm->path, (st->st_mode & 07777));
2028 if (_fsm_debug && (stage & FSM_SYSCALL))
2029 rpmMessage(RPMMESS_DEBUG, " %8s (%s, 0%04o) %s\n", cur,
2030 fsm->path, (unsigned)(st->st_mode & 07777),
2031 (rc < 0 ? strerror(errno) : ""));
2032 if (rc < 0) rc = CPIOERR_CHMOD_FAILED;
2035 { struct utimbuf stamp;
2036 stamp.actime = st->st_mtime;
2037 stamp.modtime = st->st_mtime;
2038 rc = utime(fsm->path, &stamp);
2039 if (_fsm_debug && (stage & FSM_SYSCALL))
2040 rpmMessage(RPMMESS_DEBUG, " %8s (%s, 0x%x) %s\n", cur,
2041 fsm->path, (unsigned)st->st_mtime,
2042 (rc < 0 ? strerror(errno) : ""));
2043 if (rc < 0) rc = CPIOERR_UTIME_FAILED;
2047 rc = symlink(fsm->opath, fsm->path);
2048 if (_fsm_debug && (stage & FSM_SYSCALL))
2049 rpmMessage(RPMMESS_DEBUG, " %8s (%s, %s) %s\n", cur,
2050 fsm->opath, fsm->path, (rc < 0 ? strerror(errno) : ""));
2051 if (rc < 0) rc = CPIOERR_SYMLINK_FAILED;
2054 rc = Link(fsm->opath, fsm->path);
2055 if (_fsm_debug && (stage & FSM_SYSCALL))
2056 rpmMessage(RPMMESS_DEBUG, " %8s (%s, %s) %s\n", cur,
2057 fsm->opath, fsm->path, (rc < 0 ? strerror(errno) : ""));
2058 if (rc < 0) rc = CPIOERR_LINK_FAILED;
2061 rc = mkfifo(fsm->path, (st->st_mode & 07777));
2062 if (_fsm_debug && (stage & FSM_SYSCALL))
2063 rpmMessage(RPMMESS_DEBUG, " %8s (%s, 0%04o) %s\n", cur,
2064 fsm->path, (unsigned)(st->st_mode & 07777),
2065 (rc < 0 ? strerror(errno) : ""));
2066 if (rc < 0) rc = CPIOERR_MKFIFO_FAILED;
2069 /*@-unrecog -portability @*/ /* FIX: check S_IFIFO or dev != 0 */
2070 rc = mknod(fsm->path, (st->st_mode & ~07777), st->st_rdev);
2071 /*@=unrecog =portability @*/
2072 if (_fsm_debug && (stage & FSM_SYSCALL))
2073 rpmMessage(RPMMESS_DEBUG, " %8s (%s, 0%o, 0x%x) %s\n", cur,
2074 fsm->path, (unsigned)(st->st_mode & ~07777),
2075 (unsigned)st->st_rdev,
2076 (rc < 0 ? strerror(errno) : ""));
2077 if (rc < 0) rc = CPIOERR_MKNOD_FAILED;
2080 rc = Lstat(fsm->path, ost);
2081 if (_fsm_debug && (stage & FSM_SYSCALL) && rc && errno != ENOENT)
2082 rpmMessage(RPMMESS_DEBUG, " %8s (%s, ost) %s\n", cur,
2083 fsm->path, (rc < 0 ? strerror(errno) : ""));
2084 if (rc < 0) rc = CPIOERR_LSTAT_FAILED;
2087 rc = Stat(fsm->path, ost);
2088 if (_fsm_debug && (stage & FSM_SYSCALL) && rc && errno != ENOENT)
2089 rpmMessage(RPMMESS_DEBUG, " %8s (%s, ost) %s\n", cur,
2090 fsm->path, (rc < 0 ? strerror(errno) : ""));
2091 if (rc < 0) rc = CPIOERR_STAT_FAILED;
2094 /* XXX NUL terminated result in fsm->rdbuf, len in fsm->rdnb. */
2096 rc = Readlink(fsm->path, fsm->rdbuf, fsm->rdsize - 1);
2098 if (_fsm_debug && (stage & FSM_SYSCALL))
2099 rpmMessage(RPMMESS_DEBUG, " %8s (%s, rdbuf, %d) %s\n", cur,
2100 fsm->path, (int)(fsm->rdsize -1), (rc < 0 ? strerror(errno) : ""));
2101 if (rc < 0) rc = CPIOERR_READLINK_FAILED;
2105 fsm->rdbuf[fsm->rdnb] = '\0';
2114 rc = fsmStage(fsm, FSM_HREAD);
2116 if (!strcmp(fsm->path, CPIO_TRAILER)) { /* Detect end-of-payload. */
2117 fsm->path = _free(fsm->path);
2118 rc = CPIOERR_HDR_TRAILER;
2121 rc = fsmStage(fsm, FSM_POS);
2124 for (left = st->st_size; left > 0; left -= fsm->rdnb) {
2125 fsm->wrlen = (left > fsm->wrsize ? fsm->wrsize : left);
2126 rc = fsmStage(fsm, FSM_DREAD);
2128 /*@loopbreak@*/ break;
2132 left = (modulo - (fdGetCpioPos(fsm->cfd) % modulo)) % modulo;
2135 (void) fsmStage(fsm, FSM_DREAD);
2139 left = (modulo - (fdGetCpioPos(fsm->cfd) % modulo)) % modulo;
2142 memset(fsm->rdbuf, 0, left);
2144 /* XXX DWRITE uses rdnb for I/O length. */
2146 (void) fsmStage(fsm, FSM_DWRITE);
2150 rc = cpioTrailerWrite(fsm);
2153 rc = fsmStage(fsm, FSM_POS);
2155 rc = cpioHeaderRead(fsm, st); /* Read next payload header. */
2158 rc = cpioHeaderWrite(fsm, st); /* Write next payload header. */
2161 fsm->rdnb = Fread(fsm->wrbuf, sizeof(*fsm->wrbuf), fsm->wrlen, fsm->cfd);
2162 if (_fsm_debug && (stage & FSM_SYSCALL))
2163 rpmMessage(RPMMESS_DEBUG, " %8s (%s, %d, cfd)\trdnb %d\n",
2164 cur, (fsm->wrbuf == fsm->wrb ? "wrbuf" : "mmap"),
2165 (int)fsm->wrlen, (int)fsm->rdnb);
2166 if (fsm->rdnb != fsm->wrlen || Ferror(fsm->cfd))
2167 rc = CPIOERR_READ_FAILED;
2169 fdSetCpioPos(fsm->cfd, fdGetCpioPos(fsm->cfd) + fsm->rdnb);
2172 fsm->wrnb = Fwrite(fsm->rdbuf, sizeof(*fsm->rdbuf), fsm->rdnb, fsm->cfd);
2173 if (_fsm_debug && (stage & FSM_SYSCALL))
2174 rpmMessage(RPMMESS_DEBUG, " %8s (%s, %d, cfd)\twrnb %d\n",
2175 cur, (fsm->rdbuf == fsm->rdb ? "rdbuf" : "mmap"),
2176 (int)fsm->rdnb, (int)fsm->wrnb);
2177 if (fsm->rdnb != fsm->wrnb || Ferror(fsm->cfd))
2178 rc = CPIOERR_WRITE_FAILED;
2180 fdSetCpioPos(fsm->cfd, fdGetCpioPos(fsm->cfd) + fsm->wrnb);
2184 fsm->rfd = Fopen(fsm->path, "r.ufdio");
2185 if (fsm->rfd == NULL || Ferror(fsm->rfd)) {
2186 if (fsm->rfd) (void) fsmStage(fsm, FSM_RCLOSE);
2188 rc = CPIOERR_OPEN_FAILED;
2191 if (_fsm_debug && (stage & FSM_SYSCALL))
2192 rpmMessage(RPMMESS_DEBUG, " %8s (%s, \"r\") rfd %p rdbuf %p\n", cur,
2193 fsm->path, fsm->rfd, fsm->rdbuf);
2196 fsm->rdnb = Fread(fsm->rdbuf, sizeof(*fsm->rdbuf), fsm->rdlen, fsm->rfd);
2197 if (_fsm_debug && (stage & FSM_SYSCALL))
2198 rpmMessage(RPMMESS_DEBUG, " %8s (rdbuf, %d, rfd)\trdnb %d\n",
2199 cur, (int)fsm->rdlen, (int)fsm->rdnb);
2200 if (fsm->rdnb != fsm->rdlen || Ferror(fsm->rfd))
2201 rc = CPIOERR_READ_FAILED;
2205 if (_fsm_debug && (stage & FSM_SYSCALL))
2206 rpmMessage(RPMMESS_DEBUG, " %8s (%p)\n", cur, fsm->rfd);
2207 (void) Fclose(fsm->rfd);
2215 fsm->wfd = Fopen(fsm->path, "w.ufdio");
2216 if (fsm->wfd == NULL || Ferror(fsm->wfd)) {
2217 if (fsm->wfd) (void) fsmStage(fsm, FSM_WCLOSE);
2219 rc = CPIOERR_OPEN_FAILED;
2221 if (_fsm_debug && (stage & FSM_SYSCALL))
2222 rpmMessage(RPMMESS_DEBUG, " %8s (%s, \"w\") wfd %p wrbuf %p\n", cur,
2223 fsm->path, fsm->wfd, fsm->wrbuf);
2226 fsm->wrnb = Fwrite(fsm->wrbuf, sizeof(*fsm->wrbuf), fsm->rdnb, fsm->wfd);
2227 if (_fsm_debug && (stage & FSM_SYSCALL))
2228 rpmMessage(RPMMESS_DEBUG, " %8s (wrbuf, %d, wfd)\twrnb %d\n",
2229 cur, (int)fsm->rdnb, (int)fsm->wrnb);
2230 if (fsm->rdnb != fsm->wrnb || Ferror(fsm->wfd))
2231 rc = CPIOERR_WRITE_FAILED;
2235 if (_fsm_debug && (stage & FSM_SYSCALL))
2236 rpmMessage(RPMMESS_DEBUG, " %8s (%p)\n", cur, fsm->wfd);
2237 (void) Fclose(fsm->wfd);
2250 if (!(stage & FSM_INTERNAL)) {
2251 fsm->rc = (rc == CPIOERR_HDR_TRAILER ? 0 : rc);
2257 /*@obserever@*/ const char *const fileActionString(fileAction a)
2260 case FA_UNKNOWN: return "unknown";
2261 case FA_CREATE: return "create";
2262 case FA_COPYOUT: return "copyout";
2263 case FA_COPYIN: return "copyin";
2264 case FA_BACKUP: return "backup";
2265 case FA_SAVE: return "save";
2266 case FA_SKIP: return "skip";
2267 case FA_ALTNAME: return "altname";
2268 case FA_ERASE: return "erase";
2269 case FA_SKIPNSTATE: return "skipnstate";
2270 case FA_SKIPNETSHARED: return "skipnetshared";
2271 case FA_SKIPMULTILIB: return "skipmultilib";
2272 default: return "???";
2277 /*@observer@*/ const char *const fileStageString(fileStage a) {
2279 case FSM_UNKNOWN: return "unknown";
2281 case FSM_PKGINSTALL:return "INSTALL";
2282 case FSM_PKGERASE: return "ERASE";
2283 case FSM_PKGBUILD: return "BUILD";
2284 case FSM_PKGCOMMIT: return "COMMIT";
2285 case FSM_PKGUNDO: return "UNDO";
2287 case FSM_CREATE: return "create";
2288 case FSM_INIT: return "init";
2289 case FSM_MAP: return "map";
2290 case FSM_MKDIRS: return "mkdirs";
2291 case FSM_RMDIRS: return "rmdirs";
2292 case FSM_PRE: return "pre";
2293 case FSM_PROCESS: return "process";
2294 case FSM_POST: return "post";
2295 case FSM_MKLINKS: return "mklinks";
2296 case FSM_NOTIFY: return "notify";
2297 case FSM_UNDO: return "undo";
2298 case FSM_FINI: return "fini";
2299 case FSM_COMMIT: return "commit";
2300 case FSM_DESTROY: return "destroy";
2301 case FSM_VERIFY: return "verify";
2303 case FSM_UNLINK: return "Unlink";
2304 case FSM_RENAME: return "Rename";
2305 case FSM_MKDIR: return "Mkdir";
2306 case FSM_RMDIR: return "rmdir";
2307 case FSM_CHOWN: return "chown";
2308 case FSM_LCHOWN: return "lchown";
2309 case FSM_CHMOD: return "chmod";
2310 case FSM_UTIME: return "utime";
2311 case FSM_SYMLINK: return "symlink";
2312 case FSM_LINK: return "Link";
2313 case FSM_MKFIFO: return "mkfifo";
2314 case FSM_MKNOD: return "mknod";
2315 case FSM_LSTAT: return "Lstat";
2316 case FSM_STAT: return "Stat";
2317 case FSM_READLINK: return "Readlink";
2318 case FSM_CHROOT: return "chroot";
2320 case FSM_NEXT: return "next";
2321 case FSM_EAT: return "eat";
2322 case FSM_POS: return "pos";
2323 case FSM_PAD: return "pad";
2324 case FSM_TRAILER: return "trailer";
2325 case FSM_HREAD: return "hread";
2326 case FSM_HWRITE: return "hwrite";
2327 case FSM_DREAD: return "Fread";
2328 case FSM_DWRITE: return "Fwrite";
2330 case FSM_ROPEN: return "Fopen";
2331 case FSM_READ: return "Fread";
2332 case FSM_RCLOSE: return "Fclose";
2333 case FSM_WOPEN: return "Fopen";
2334 case FSM_WRITE: return "Fwrite";
2335 case FSM_WCLOSE: return "Fclose";
2337 default: return "???";