3 * File state machine to handle a payload from a package.
8 #include <rpmio_internal.h>
15 #define _RPMFI_INTERNAL
30 #define alloca_strdup(_s) strcpy(alloca(strlen(_s)+1), (_s))
35 /* XXX Failure to remove is not (yet) cause for failure. */
36 /*@-exportlocal -exportheadervar@*/
38 int strict_erasures = 0;
39 /*@=exportlocal =exportheadervar@*/
41 rpmts fsmGetTs(const FSM_t fsm) {
42 const FSMI_t iter = fsm->iter;
43 /*@-compdef -refcounttrans -retexpose -usereleased @*/
44 return (iter ? iter->ts : NULL);
45 /*@=compdef =refcounttrans =retexpose =usereleased @*/
48 rpmfi fsmGetFi(const FSM_t fsm)
50 const FSMI_t iter = fsm->iter;
51 /*@-compdef -refcounttrans -retexpose -usereleased @*/
52 return (iter ? iter->fi : NULL);
53 /*@=compdef =refcounttrans =retexpose =usereleased @*/
56 #define SUFFIX_RPMORIG ".rpmorig"
57 #define SUFFIX_RPMSAVE ".rpmsave"
58 #define SUFFIX_RPMNEW ".rpmnew"
61 * Build path to file from file info, ornamented with subdir and suffix.
62 * @param fsm file state machine data
63 * @param st file stat info
64 * @param subdir subdir to use (NULL disables)
65 * @param suffix suffix to use (NULL disables)
66 * @retval path to file
68 static /*@only@*//*@null@*/
69 const char * fsmFsPath(/*@special@*/ /*@null@*/ const FSM_t fsm,
70 /*@null@*/ const struct stat * st,
71 /*@null@*/ const char * subdir,
72 /*@null@*/ const char * suffix)
73 /*@uses fsm->dirName, fsm->baseName */
76 const char * s = NULL;
81 nb = strlen(fsm->dirName) +
82 (st && !S_ISDIR(st->st_mode) ? (subdir ? strlen(subdir) : 0) : 0) +
83 (st && !S_ISDIR(st->st_mode) ? (suffix ? strlen(suffix) : 0) : 0) +
84 strlen(fsm->baseName) + 1;
87 t = stpcpy(t, fsm->dirName);
88 if (st && !S_ISDIR(st->st_mode))
89 if (subdir) t = stpcpy(t, subdir);
90 t = stpcpy(t, fsm->baseName);
91 if (st && !S_ISDIR(st->st_mode))
92 if (suffix) t = stpcpy(t, suffix);
99 * Destroy file info iterator.
100 * @param p file info iterator
101 * @retval NULL always
103 static /*@null@*/ void * mapFreeIterator(/*@only@*//*@null@*/ void * p)
108 iter->ts = rpmtsUnlink(iter->ts, "mapIterator");
109 iter->fi = rpmfiUnlink(iter->fi, "mapIterator");
115 * Create file info iterator.
116 * @param ts transaction set
117 * @param fi transaction element file info
118 * @return file info iterator
121 mapInitIterator(rpmts ts, rpmfi fi)
122 /*@modifies ts, fi @*/
126 iter = xcalloc(1, sizeof(*iter));
127 iter->ts = rpmtsLink(ts, "mapIterator");
128 iter->fi = rpmfiLink(fi, "mapIterator");
129 iter->reverse = (rpmteType(fi->te) == TR_REMOVED && fi->action != FA_COPYOUT);
130 iter->i = (iter->reverse ? (fi->fc - 1) : 0);
131 iter->isave = iter->i;
136 * Return next index into file info.
137 * @param a file info iterator
138 * @return next index, -1 on termination
140 static int mapNextIterator(/*@null@*/ void * a)
147 const rpmfi fi = iter->fi;
149 if (iter->i >= 0) i = iter->i--;
151 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);
180 * Locate archive path in file info.
181 * @param iter file info iterator
182 * @param fsmPath archive path
183 * @return index into file info, -1 if archive path was not found
186 static int mapFind(/*@null@*/ FSMI_t iter, const char * fsmPath)
192 const rpmfi fi = iter->fi;
193 if (fi && fi->fc > 0 && fi->apath && fsmPath && *fsmPath) {
194 const char ** p = NULL;
197 if (fi->apath != NULL)
198 p = bsearch(&fsmPath, fi->apath, fi->fc, sizeof(fsmPath),
202 iter->i = p - fi->apath;
203 ix = mapNextIterator(iter);
212 * Directory name iterator.
214 typedef struct dnli_s {
216 /*@only@*/ /*@null@*/
224 * Destroy directory name iterator.
225 * @param a directory name iterator
226 * @retval NULL always
228 static /*@null@*/ void * dnlFreeIterator(/*@only@*//*@null@*/ const void * a)
232 DNLI_t dnli = (void *)a;
233 if (dnli->active) free(dnli->active);
240 static inline int dnlCount(const DNLI_t dnli)
243 return (dnli ? dnli->fi->dc : 0);
248 static inline int dnlIndex(const DNLI_t dnli)
251 return (dnli ? dnli->isave : -1);
255 * Create directory name iterator.
256 * @param fsm file state machine data
257 * @param reverse traverse directory names in reverse order?
258 * @return directory name iterator
262 static /*@only@*/ void * dnlInitIterator(/*@special@*/ const FSM_t fsm,
264 /*@uses fsm->iter @*/
267 rpmfi fi = fsmGetFi(fsm);
273 dnli = xcalloc(1, sizeof(*dnli));
275 dnli->reverse = reverse;
277 dnli->i = (reverse ? fi->dc : 0);
281 dnli->active = xcalloc(fi->dc, sizeof(*dnli->active));
283 /* Identify parent directories not skipped. */
285 for (i = 0; i < fi->fc; i++)
286 if (!XFA_SKIPPING(fi->actions[i])) dnli->active[fi->dil[i]] = 1;
289 /* Exclude parent directories that are explicitly included. */
290 for (i = 0; i < fi->fc; i++) {
291 int dil, dnlen, bnlen;
293 if (!S_ISDIR(fi->fmodes[i]))
297 dnlen = strlen(fi->dnl[dil]);
298 bnlen = strlen(fi->bnl[i]);
300 for (j = 0; j < fi->dc; j++) {
304 if (!dnli->active[j] || j == dil)
305 /*@innercontinue@*/ continue;
308 if (jlen != (dnlen+bnlen+1))
309 /*@innercontinue@*/ continue;
310 if (strncmp(dnl, fi->dnl[dil], dnlen))
311 /*@innercontinue@*/ continue;
312 if (strncmp(dnl+dnlen, fi->bnl[i], bnlen))
313 /*@innercontinue@*/ continue;
314 if (dnl[dnlen+bnlen] != '/' || dnl[dnlen+bnlen+1] != '\0')
315 /*@innercontinue@*/ continue;
316 /* This directory is included in the package. */
320 /*@innerbreak@*/ break;
324 /* Print only once per package. */
327 for (i = 0; i < fi->dc; i++) {
328 if (!dnli->active[i]) continue;
331 rpmMessage(RPMMESS_DEBUG,
332 _("========== Directories not explictly included in package:\n"));
334 rpmMessage(RPMMESS_DEBUG, _("%10d %s\n"), i, fi->dnl[i]);
337 rpmMessage(RPMMESS_DEBUG, "==========\n");
346 * Return next directory name (from file info).
347 * @param dnli directory name iterator
348 * @return next directory name
351 static /*@observer@*/ const char * dnlNextIterator(/*@null@*/ DNLI_t dnli)
354 const char * dn = NULL;
362 i = (!dnli->reverse ? dnli->i++ : --dnli->i);
363 } while (i >= 0 && i < fi->dc && !dnli->active[i]);
365 if (i >= 0 && i < fi->dc)
376 * Save hard link in chain.
377 * @param fsm file state machine data
378 * @return Is chain only partially filled?
381 static int saveHardLink(/*@special@*/ /*@partial@*/ FSM_t fsm)
382 /*@uses fsm->links, fsm->ix, fsm->sb, fsm->goal, fsm->nsuffix @*/
383 /*@defines fsm->li @*/
384 /*@releases fsm->path @*/
385 /*@globals fileSystem, internalState @*/
386 /*@modifies fsm, fileSystem, internalState @*/
388 struct stat * st = &fsm->sb;
393 /* Find hard link set. */
395 for (fsm->li = fsm->links; fsm->li; fsm->li = fsm->li->next) {
396 if (fsm->li->sb.st_ino == st->st_ino && fsm->li->sb.st_dev == st->st_dev)
401 /* New hard link encountered, add new link to set. */
404 if (fsm->li == NULL) {
405 fsm->li = xcalloc(1, sizeof(*fsm->li));
406 fsm->li->next = NULL;
407 fsm->li->sb = *st; /* structure assignment */
408 fsm->li->nlink = st->st_nlink;
409 fsm->li->linkIndex = fsm->ix;
410 fsm->li->createdPath = -1;
412 fsm->li->filex = xcalloc(st->st_nlink, sizeof(fsm->li->filex[0]));
413 memset(fsm->li->filex, -1, (st->st_nlink * sizeof(fsm->li->filex[0])));
414 fsm->li->nsuffix = xcalloc(st->st_nlink, sizeof(*fsm->li->nsuffix));
416 if (fsm->goal == FSM_PKGBUILD)
417 fsm->li->linksLeft = st->st_nlink;
418 if (fsm->goal == FSM_PKGINSTALL)
419 fsm->li->linksLeft = 0;
422 fsm->li->next = fsm->links;
424 fsm->links = fsm->li;
429 if (fsm->goal == FSM_PKGBUILD) --fsm->li->linksLeft;
431 fsm->li->filex[fsm->li->linksLeft] = fsm->ix;
432 /*@-observertrans -dependenttrans@*/
433 fsm->li->nsuffix[fsm->li->linksLeft] = fsm->nsuffix;
434 /*@=observertrans =dependenttrans@*/
436 if (fsm->goal == FSM_PKGINSTALL) fsm->li->linksLeft++;
438 if (fsm->goal == FSM_PKGBUILD)
439 return (fsm->li->linksLeft > 0);
441 if (fsm->goal != FSM_PKGINSTALL)
444 if (!(st->st_size || fsm->li->linksLeft == st->st_nlink))
447 /* Here come the bits, time to choose a non-skipped file name. */
448 { rpmfi fi = fsmGetFi(fsm);
450 for (j = fsm->li->linksLeft - 1; j >= 0; j--) {
451 ix = fsm->li->filex[j];
452 if (ix < 0 || XFA_SKIPPING(fi->actions[ix]))
458 /* Are all links skipped or not encountered yet? */
460 return 1; /* XXX W2DO? */
462 /* Save the non-skipped file name and map index. */
463 fsm->li->linkIndex = j;
464 fsm->path = _free(fsm->path);
466 rc = fsmStage(fsm, FSM_MAP);
472 * Destroy set of hard links.
473 * @param li set of hard links
474 * @return NULL always
476 static /*@null@*/ void * freeHardLink(/*@only@*/ /*@null@*/ struct hardLink_s * li)
480 li->nsuffix = _free(li->nsuffix); /* XXX elements are shared */
481 li->filex = _free(li->filex);
488 FSM_t fsm = xcalloc(1, sizeof(*fsm));
492 FSM_t freeFSM(FSM_t fsm)
495 fsm->path = _free(fsm->path);
497 while ((fsm->li = fsm->links) != NULL) {
498 fsm->links = fsm->li->next;
499 fsm->li->next = NULL;
500 fsm->li = freeHardLink(fsm->li);
503 fsm->dnlx = _free(fsm->dnlx);
504 fsm->ldn = _free(fsm->ldn);
505 fsm->iter = mapFreeIterator(fsm->iter);
510 int fsmSetup(FSM_t fsm, fileStage goal,
511 const rpmts ts, const rpmfi fi, FD_t cfd,
512 unsigned int * archiveSize, const char ** failedFile)
519 /*@-type@*/ /* FIX: cast? */
520 fsm->cfd = fdLink(cfd, "persist (fsm)");
522 pos = fdGetCpioPos(fsm->cfd);
523 fdSetCpioPos(fsm->cfd, 0);
525 fsm->iter = mapInitIterator(ts, fi);
527 if (fsm->goal == FSM_PKGINSTALL || fsm->goal == FSM_PKGBUILD) {
530 ptr = rpmtsNotify(ts, fi->te,
531 RPMCALLBACK_INST_START, fi->archivePos, fi->archiveSize);
536 fsm->archiveSize = archiveSize;
537 if (fsm->archiveSize)
538 *fsm->archiveSize = 0;
539 fsm->failedFile = failedFile;
541 *fsm->failedFile = NULL;
545 memset(fsm->sufbuf, 0, sizeof(fsm->sufbuf));
546 if (fsm->goal == FSM_PKGINSTALL) {
547 if (ts && rpmtsGetTid(ts) > 0)
548 sprintf(fsm->sufbuf, ";%08x", (unsigned)rpmtsGetTid(ts));
552 rc = fsmStage(fsm, FSM_CREATE);
553 if (rc && !ec) ec = rc;
555 rc = fsmStage(fsm, fsm->goal);
556 if (rc && !ec) ec = rc;
559 if (fsm->archiveSize && ec == 0)
560 *fsm->archiveSize = (fdGetCpioPos(fsm->cfd) - pos);
566 int fsmTeardown(FSM_t fsm)
571 rc = fsmStage(fsm, FSM_DESTROY);
573 fsm->iter = mapFreeIterator(fsm->iter);
575 /*@-type@*/ /* FIX: cast? */
576 fsm->cfd = fdFree(fsm->cfd, "persist (fsm)");
580 fsm->failedFile = NULL;
584 int fsmMapPath(FSM_t fsm)
586 rpmfi fi = fsmGetFi(fsm); /* XXX const except for fstates */
593 fsm->action = FA_UNKNOWN;
597 if (fi && i >= 0 && i < fi->fc) {
600 fsm->astriplen = fi->astriplen;
601 fsm->action = (fi->actions ? fi->actions[i] : fi->action);
602 fsm->fflags = (fi->fflags ? fi->fflags[i] : fi->flags);
603 fsm->mapFlags = (fi->fmapflags ? fi->fmapflags[i] : fi->mapflags);
605 /* src rpms have simple base name in payload. */
606 fsm->dirName = fi->dnl[fi->dil[i]];
607 fsm->baseName = fi->bnl[i];
611 switch (fsm->action) {
614 case FA_SKIPMULTILIB: /* XXX RPMFILE_STATE_MULTILIB? */
623 assert(rpmteType(fi->te) == TR_ADDED);
627 if (fi->fstates && rpmteType(fi->te) == TR_ADDED)
628 fi->fstates[i] = RPMFILE_STATE_NOTINSTALLED;
631 case FA_SKIPNETSHARED:
632 if (fi->fstates && rpmteType(fi->te) == TR_ADDED)
633 fi->fstates[i] = RPMFILE_STATE_NETSHARED;
637 if (!(fsm->fflags & RPMFILE_GHOST)) /* XXX Don't if %ghost file. */
638 switch (rpmteType(fi->te)) {
640 fsm->osuffix = SUFFIX_RPMORIG;
641 /*@innerbreak@*/ break;
643 fsm->osuffix = SUFFIX_RPMSAVE;
644 /*@innerbreak@*/ break;
649 assert(rpmteType(fi->te) == TR_ADDED);
650 if (!(fsm->fflags & RPMFILE_GHOST)) /* XXX Don't if %ghost file. */
651 fsm->nsuffix = SUFFIX_RPMNEW;
655 assert(rpmteType(fi->te) == TR_ADDED);
656 if (!(fsm->fflags & RPMFILE_GHOST)) /* XXX Don't if %ghost file. */
657 fsm->osuffix = SUFFIX_RPMSAVE;
660 assert(rpmteType(fi->te) == TR_REMOVED);
662 * XXX TODO: %ghost probably shouldn't be removed, but that changes
663 * legacy rpm behavior.
671 if ((fsm->mapFlags & CPIO_MAP_PATH) || fsm->nsuffix) {
672 const struct stat * st = &fsm->sb;
673 fsm->path = _free(fsm->path);
674 fsm->path = fsmFsPath(fsm, st, fsm->subdir,
675 (fsm->suffix ? fsm->suffix : fsm->nsuffix));
681 int fsmMapAttrs(FSM_t fsm)
683 struct stat * st = &fsm->sb;
684 rpmfi fi = fsmGetFi(fsm);
687 if (fi && i >= 0 && i < fi->fc) {
689 (S_ISDIR(st->st_mode) ? fi->dperms : fi->fperms);
691 (fi->fmodes ? fi->fmodes[i] : perms);
693 (fi->fuids ? fi->fuids[i] : fi->uid); /* XXX chmod u-s */
695 (fi->fgids ? fi->fgids[i] : fi->gid); /* XXX chmod g-s */
697 (fi->frdevs ? fi->frdevs[i] : 0);
699 (fi->fmtimes ? fi->fmtimes[i] : 0);
701 if (fsm->mapFlags & CPIO_MAP_MODE)
702 st->st_mode = (st->st_mode & S_IFMT) | (finalMode & ~S_IFMT);
703 if (fsm->mapFlags & CPIO_MAP_TYPE) {
704 st->st_mode = (st->st_mode & ~S_IFMT) | (finalMode & S_IFMT);
705 if ((S_ISCHR(st->st_mode) || S_ISBLK(st->st_mode))
706 && st->st_nlink == 0)
708 st->st_rdev = finalRdev;
709 st->st_mtime = finalMtime;
711 if (fsm->mapFlags & CPIO_MAP_UID)
712 st->st_uid = finalUid;
713 if (fsm->mapFlags & CPIO_MAP_GID)
714 st->st_gid = finalGid;
716 { rpmts ts = fsmGetTs(fsm);
718 if (ts != NULL && !(rpmtsFlags(ts) & RPMTRANS_FLAG_NOMD5)) {
719 fsm->fmd5sum = (fi->fmd5s ? fi->fmd5s[i] : NULL);
720 fsm->md5sum = (fi->md5s ? (fi->md5s + (16 * i)) : NULL);
732 * Create file from payload stream.
733 * @param fsm file state machine data
734 * @return 0 on success
736 static int expandRegular(/*@special@*/ FSM_t fsm)
738 /*@globals fileSystem, internalState @*/
739 /*@modifies fsm, fileSystem, internalState @*/
741 const struct stat * st = &fsm->sb;
742 int left = st->st_size;
745 rc = fsmStage(fsm, FSM_WOPEN);
749 if (st->st_size > 0 && (fsm->fmd5sum || fsm->md5sum))
750 fdInitDigest(fsm->wfd, PGPHASHALGO_MD5, 0);
754 fsm->wrlen = (left > fsm->wrsize ? fsm->wrsize : left);
755 rc = fsmStage(fsm, FSM_DREAD);
759 rc = fsmStage(fsm, FSM_WRITE);
765 /* don't call this with fileSize == fileComplete */
767 (void) fsmStage(fsm, FSM_NOTIFY);
770 if (st->st_size > 0 && (fsm->fmd5sum || fsm->md5sum)) {
771 void * md5sum = NULL;
772 int asAscii = (fsm->md5sum == NULL ? 1 : 0);
774 (void) Fflush(fsm->wfd);
775 fdFiniDigest(fsm->wfd, PGPHASHALGO_MD5, &md5sum, NULL, asAscii);
777 if (md5sum == NULL) {
778 rc = CPIOERR_MD5SUM_MISMATCH;
782 if (fsm->md5sum != NULL) {
783 if (memcmp(md5sum, fsm->md5sum, 16))
784 rc = CPIOERR_MD5SUM_MISMATCH;
786 if (strcmp(md5sum, fsm->fmd5sum))
787 rc = CPIOERR_MD5SUM_MISMATCH;
789 md5sum = _free(md5sum);
793 (void) fsmStage(fsm, FSM_WCLOSE);
798 * Write next item to payload stream.
799 * @param fsm file state machine data
800 * @param writeData should data be written?
801 * @return 0 on success
803 static int writeFile(/*@special@*/ FSM_t fsm, int writeData)
804 /*@uses fsm->path, fsm->opath, fsm->sb, fsm->osb, fsm->cfd @*/
805 /*@globals fileSystem, internalState @*/
806 /*@modifies fsm, fileSystem, internalState @*/
808 const char * path = fsm->path;
809 const char * opath = fsm->opath;
810 struct stat * st = &fsm->sb;
811 struct stat * ost = &fsm->osb;
812 char * symbuf = NULL;
817 st->st_size = (writeData ? ost->st_size : 0);
820 if (S_ISDIR(st->st_mode)) {
822 } else if (S_ISLNK(st->st_mode)) {
824 * While linux puts the size of a symlink in the st_size field,
825 * I don't think that's a specified standard.
827 /* XXX NUL terminated result in fsm->rdbuf, len in fsm->rdnb. */
828 rc = fsmStage(fsm, FSM_READLINK);
830 st->st_size = fsm->rdnb;
831 symbuf = alloca_strdup(fsm->rdbuf); /* XXX save readlink return. */
835 if (fsm->mapFlags & CPIO_MAP_ABSOLUTE) {
836 /*@-compdef@*/ /* FIX: dirName/baseName annotations ? */
838 int nb = strlen(fsm->dirName) + strlen(fsm->baseName) + sizeof(".");
839 char * t = alloca(nb);
842 if (fsm->mapFlags & CPIO_MAP_ADDDOT)
844 t = stpcpy( stpcpy(t, fsm->dirName), fsm->baseName);
847 } else if (fsm->mapFlags & CPIO_MAP_PATH) {
848 rpmfi fi = fsmGetFi(fsm);
850 (fi->apath ? fi->apath[fsm->ix] + fi->striplen : fi->bnl[fsm->ix]);
853 rc = fsmStage(fsm, FSM_HWRITE);
857 if (writeData && S_ISREG(st->st_mode)) {
860 void * mapped = (void *)-1;
864 rc = fsmStage(fsm, FSM_ROPEN);
867 /* XXX unbuffered mmap generates *lots* of fdio debugging */
870 mapped = mmap(NULL, st->st_size, PROT_READ, MAP_SHARED, Fileno(fsm->rfd), 0);
871 if (mapped != (void *)-1) {
873 fsm->rdbuf = (char *) mapped;
874 fsm->rdlen = nmapped = st->st_size;
875 #if defined(MADV_DONTNEED)
876 xx = madvise(mapped, nmapped, MADV_DONTNEED);
885 if (mapped != (void *)-1) {
890 fsm->rdlen = (left > fsm->rdsize ? fsm->rdsize : left),
891 rc = fsmStage(fsm, FSM_READ);
895 /* XXX DWRITE uses rdnb for I/O length. */
896 rc = fsmStage(fsm, FSM_DWRITE);
903 if (mapped != (void *)-1) {
904 xx = msync(mapped, nmapped, MS_ASYNC);
905 #if defined(MADV_DONTNEED)
906 xx = madvise(mapped, nmapped, MADV_DONTNEED);
908 /*@-noeffect@*/ xx = munmap(mapped, nmapped) /*@=noeffect@*/;
913 } else if (writeData && S_ISLNK(st->st_mode)) {
914 /* XXX DWRITE uses rdnb for I/O length. */
916 strcpy(fsm->rdbuf, symbuf); /* XXX restore readlink buffer. */
918 fsm->rdnb = strlen(symbuf);
919 rc = fsmStage(fsm, FSM_DWRITE);
923 rc = fsmStage(fsm, FSM_PAD);
930 (void) fsmStage(fsm, FSM_RCLOSE);
931 /*@-dependenttrans@*/
934 /*@=dependenttrans@*/
939 * Write set of linked files to payload stream.
940 * @param fsm file state machine data
941 * @return 0 on success
943 static int writeLinkedFile(/*@special@*/ FSM_t fsm)
944 /*@uses fsm->path, fsm->nsuffix, fsm->ix, fsm->li, fsm->failedFile @*/
945 /*@globals fileSystem, internalState @*/
946 /*@modifies fsm, fileSystem, internalState @*/
948 const char * path = fsm->path;
949 const char * nsuffix = fsm->nsuffix;
950 int iterIndex = fsm->ix;
960 for (i = fsm->li->nlink - 1; i >= 0; i--) {
962 if (fsm->li->filex[i] < 0) continue;
964 fsm->ix = fsm->li->filex[i];
965 rc = fsmStage(fsm, FSM_MAP);
967 /* Write data after last link. */
968 rc = writeFile(fsm, (i == 0));
969 if (fsm->failedFile && rc != 0 && *fsm->failedFile == NULL) {
971 *fsm->failedFile = xstrdup(fsm->path);
974 fsm->path = _free(fsm->path);
975 fsm->li->filex[i] = -1;
980 fsm->nsuffix = nsuffix;
986 * Create pending hard links to existing file.
987 * @param fsm file state machine data
988 * @return 0 on success
991 static int fsmMakeLinks(/*@special@*/ FSM_t fsm)
992 /*@uses fsm->path, fsm->opath, fsm->nsuffix, fsm->ix, fsm->li @*/
993 /*@globals fileSystem, internalState @*/
994 /*@modifies fsm, fileSystem, internalState @*/
996 const char * path = fsm->path;
997 const char * opath = fsm->opath;
998 const char * nsuffix = fsm->nsuffix;
999 int iterIndex = fsm->ix;
1006 fsm->nsuffix = NULL;
1009 fsm->ix = fsm->li->filex[fsm->li->createdPath];
1010 rc = fsmStage(fsm, FSM_MAP);
1011 fsm->opath = fsm->path;
1014 for (i = 0; i < fsm->li->nlink; i++) {
1015 if (fsm->li->filex[i] < 0) continue;
1016 if (fsm->li->createdPath == i) continue;
1018 fsm->ix = fsm->li->filex[i];
1019 fsm->path = _free(fsm->path);
1020 rc = fsmStage(fsm, FSM_MAP);
1021 if (XFA_SKIPPING(fsm->action)) continue;
1023 rc = fsmStage(fsm, FSM_VERIFY);
1025 if (rc != CPIOERR_LSTAT_FAILED) break;
1027 /* XXX link(fsm->opath, fsm->path) */
1028 rc = fsmStage(fsm, FSM_LINK);
1029 if (fsm->failedFile && rc != 0 && *fsm->failedFile == NULL) {
1032 *fsm->failedFile = xstrdup(fsm->path);
1036 fsm->li->linksLeft--;
1039 fsm->path = _free(fsm->path);
1040 fsm->opath = _free(fsm->opath);
1042 fsm->ix = iterIndex;
1043 fsm->nsuffix = nsuffix;
1050 /** \ingroup payload
1051 * Commit hard linked file set atomically.
1052 * @param fsm file state machine data
1053 * @return 0 on success
1055 static int fsmCommitLinks(/*@special@*/ FSM_t fsm)
1056 /*@uses fsm->path, fsm->nsuffix, fsm->ix, fsm->sb,
1057 fsm->li, fsm->links @*/
1058 /*@globals fileSystem, internalState @*/
1059 /*@modifies fsm, fileSystem, internalState @*/
1061 const char * path = fsm->path;
1062 const char * nsuffix = fsm->nsuffix;
1063 int iterIndex = fsm->ix;
1064 struct stat * st = &fsm->sb;
1069 fsm->nsuffix = NULL;
1073 for (fsm->li = fsm->links; fsm->li; fsm->li = fsm->li->next) {
1074 if (fsm->li->sb.st_ino == st->st_ino && fsm->li->sb.st_dev == st->st_dev)
1080 for (i = 0; i < fsm->li->nlink; i++) {
1081 if (fsm->li->filex[i] < 0) continue;
1082 fsm->ix = fsm->li->filex[i];
1083 rc = fsmStage(fsm, FSM_MAP);
1084 if (!XFA_SKIPPING(fsm->action))
1085 rc = fsmStage(fsm, FSM_COMMIT);
1086 fsm->path = _free(fsm->path);
1087 fsm->li->filex[i] = -1;
1091 fsm->ix = iterIndex;
1092 fsm->nsuffix = nsuffix;
1098 * Remove (if created) directories not explicitly included in package.
1099 * @param fsm file state machine data
1100 * @return 0 on success
1102 static int fsmRmdirs(/*@special@*/ FSM_t fsm)
1103 /*@uses fsm->path, fsm->dnlx, fsm->ldn, fsm->rdbuf, fsm->iter @*/
1104 /*@globals fileSystem, internalState @*/
1105 /*@modifies fsm, fileSystem, internalState @*/
1107 const char * path = fsm->path;
1108 void * dnli = dnlInitIterator(fsm, 1);
1109 char * dn = fsm->rdbuf;
1110 int dc = dnlCount(dnli);
1116 /*@-observertrans -dependenttrans@*/
1117 if (fsm->ldn != NULL && fsm->dnlx != NULL)
1118 while ((fsm->path = dnlNextIterator(dnli)) != NULL) {
1119 int dnlen = strlen(fsm->path);
1122 dc = dnlIndex(dnli);
1123 if (fsm->dnlx[dc] < 1 || fsm->dnlx[dc] >= dnlen)
1126 /* Copy to avoid const on fsm->path. */
1127 te = stpcpy(dn, fsm->path) - 1;
1130 /* Remove generated directories. */
1131 /*@-usereleased@*/ /* LCL: te used after release? */
1135 rc = fsmStage(fsm, FSM_RMDIR);
1139 /*@innerbreak@*/ break;
1141 } while ((te - fsm->path) > fsm->dnlx[dc]);
1145 dnli = dnlFreeIterator(dnli);
1146 /*@=observertrans =dependenttrans@*/
1153 * Create (if necessary) directories not explicitly included in package.
1154 * @param fsm file state machine data
1155 * @return 0 on success
1157 static int fsmMkdirs(/*@special@*/ FSM_t fsm)
1158 /*@uses fsm->path, fsm->sb, fsm->osb, fsm->rdbuf, fsm->iter,
1159 fsm->ldn, fsm->ldnlen, fsm->ldnalloc @*/
1160 /*@defines fsm->dnlx, fsm->ldn @*/
1161 /*@globals fileSystem, internalState @*/
1162 /*@modifies fsm, fileSystem, internalState @*/
1164 struct stat * st = &fsm->sb;
1165 struct stat * ost = &fsm->osb;
1166 const char * path = fsm->path;
1167 mode_t st_mode = st->st_mode;
1168 void * dnli = dnlInitIterator(fsm, 0);
1169 char * dn = fsm->rdbuf;
1170 int dc = dnlCount(dnli);
1178 fsm->dnlx = (dc ? xcalloc(dc, sizeof(*fsm->dnlx)) : NULL);
1179 /*@-observertrans -dependenttrans@*/
1180 if (fsm->dnlx != NULL)
1181 while ((fsm->path = dnlNextIterator(dnli)) != NULL) {
1182 int dnlen = strlen(fsm->path);
1185 dc = dnlIndex(dnli);
1186 if (dc < 0) continue;
1187 fsm->dnlx[dc] = dnlen;
1191 /*@-compdef -nullpass@*/ /* FIX: fsm->ldn not defined ??? */
1192 if (dnlen <= fsm->ldnlen && !strcmp(fsm->path, fsm->ldn))
1194 /*@=compdef =nullpass@*/
1196 /* Copy to avoid const on fsm->path. */
1197 (void) stpcpy(dn, fsm->path);
1200 /* Assume '/' directory exists, "mkdir -p" for others if non-existent */
1201 for (i = 1, te = dn + 1; *te != '\0'; te++, i++) {
1203 /*@innercontinue@*/ continue;
1207 /* Already validated? */
1208 /*@-usedef -compdef -nullpass -nullderef@*/
1209 if (i < fsm->ldnlen &&
1210 (fsm->ldn[i] == '/' || fsm->ldn[i] == '\0') &&
1211 !strncmp(fsm->path, fsm->ldn, i))
1214 /* Move pre-existing path marker forward. */
1215 fsm->dnlx[dc] = (te - dn);
1216 /*@innercontinue@*/ continue;
1218 /*@=usedef =compdef =nullpass =nullderef@*/
1220 /* Validate next component of path. */
1221 rc = fsmStage(fsm, FSM_LSTAT);
1224 /* Directory already exists? */
1225 if (rc == 0 && S_ISDIR(ost->st_mode)) {
1226 /* Move pre-existing path marker forward. */
1227 fsm->dnlx[dc] = (te - dn);
1228 } else if (rc == CPIOERR_LSTAT_FAILED) {
1229 rpmfi fi = fsmGetFi(fsm);
1231 st->st_mode = S_IFDIR | (fi->dperms & 07777);
1232 rc = fsmStage(fsm, FSM_MKDIR);
1234 rpmMessage(RPMMESS_DEBUG,
1235 _("%s directory created with perms %04o.\n"),
1236 fsm->path, (unsigned)(st->st_mode & 07777));
1240 /*@innerbreak@*/ break;
1244 /* Save last validated path. */
1245 /*@-compdef@*/ /* FIX: ldn/path annotations ? */
1246 if (fsm->ldnalloc < (dnlen + 1)) {
1247 fsm->ldnalloc = dnlen + 100;
1248 fsm->ldn = xrealloc(fsm->ldn, fsm->ldnalloc);
1250 if (fsm->ldn != NULL) { /* XXX can't happen */
1251 strcpy(fsm->ldn, fsm->path);
1252 fsm->ldnlen = dnlen;
1257 dnli = dnlFreeIterator(dnli);
1258 /*@=observertrans =dependenttrans@*/
1261 st->st_mode = st_mode; /* XXX restore st->st_mode */
1262 /*@-compdef@*/ /* FIX: ldn/path annotations ? */
1269 * Check for file on disk.
1270 * @param fsm file state machine data
1271 * @return 0 on success
1273 static int fsmStat(FSM_t fsm)
1275 int saveerrno = errno;
1278 if (fsm->path != NULL) {
1279 int saveernno = errno;
1280 rc = fsmStage(fsm, (!(fsm->mapFlags & CPIO_FOLLOW_SYMLINKS)
1281 ? FSM_LSTAT : FSM_STAT));
1282 if (rc == CPIOERR_LSTAT_FAILED && errno == ENOENT) {
1286 } else if (rc == 0) {
1290 /* Skip %ghost files on build. */
1297 #define IS_DEV_LOG(_x) \
1298 ((_x) != NULL && strlen(_x) >= (sizeof("/dev/log")-1) && \
1299 !strncmp((_x), "/dev/log", sizeof("/dev/log")-1) && \
1300 ((_x)[sizeof("/dev/log")-1] == '\0' || \
1301 (_x)[sizeof("/dev/log")-1] == ';'))
1305 int fsmStage(FSM_t fsm, fileStage stage)
1308 fileStage prevStage = fsm->stage;
1309 const char * const prev = fileStageString(prevStage);
1311 static int modulo = 4;
1312 const char * const cur = fileStageString(stage);
1313 struct stat * st = &fsm->sb;
1314 struct stat * ost = &fsm->osb;
1315 int saveerrno = errno;
1320 #define _fafilter(_a) \
1321 (!((_a) == FA_CREATE || (_a) == FA_ERASE || (_a) == FA_COPYIN || (_a) == FA_COPYOUT) \
1322 ? fileActionString(_a) : "")
1324 if (stage & FSM_DEAD) {
1326 } else if (stage & FSM_INTERNAL) {
1327 if (_fsm_debug && !(stage & FSM_SYSCALL))
1328 rpmMessage(RPMMESS_DEBUG, " %8s %06o%3d (%4d,%4d)%10d %s %s\n",
1330 (unsigned)st->st_mode, (int)st->st_nlink,
1331 (int)st->st_uid, (int)st->st_gid, (int)st->st_size,
1332 (fsm->path ? fsm->path : ""),
1333 _fafilter(fsm->action));
1336 if (_fsm_debug || !(stage & FSM_VERBOSE))
1337 rpmMessage(RPMMESS_DEBUG, "%-8s %06o%3d (%4d,%4d)%10d %s %s\n",
1339 (unsigned)st->st_mode, (int)st->st_nlink,
1340 (int)st->st_uid, (int)st->st_gid, (int)st->st_size,
1341 (fsm->path ? fsm->path + fsm->astriplen : ""),
1342 _fafilter(fsm->action));
1350 case FSM_PKGINSTALL:
1352 /* Clean fsm, free'ing memory. Read next archive header. */
1353 rc = fsmStage(fsm, FSM_INIT);
1355 /* Exit on end-of-payload. */
1356 if (rc == CPIOERR_HDR_TRAILER) {
1358 /*@loopbreak@*/ break;
1361 /* Exit on error. */
1364 (void) fsmStage(fsm, FSM_UNDO);
1365 /*@loopbreak@*/ break;
1368 /* Extract file from archive. */
1369 rc = fsmStage(fsm, FSM_PROCESS);
1371 (void) fsmStage(fsm, FSM_UNDO);
1372 /*@loopbreak@*/ break;
1375 /* Notify on success. */
1376 (void) fsmStage(fsm, FSM_NOTIFY);
1378 rc = fsmStage(fsm, FSM_FINI);
1380 /*@loopbreak@*/ break;
1387 /* Clean fsm, free'ing memory. */
1388 rc = fsmStage(fsm, FSM_INIT);
1390 /* Exit on end-of-payload. */
1391 if (rc == CPIOERR_HDR_TRAILER) {
1393 /*@loopbreak@*/ break;
1396 /* Rename/erase next item. */
1397 if (fsmStage(fsm, FSM_FINI))
1398 /*@loopbreak@*/ break;
1404 rc = fsmStage(fsm, FSM_INIT);
1406 /* Exit on end-of-payload. */
1407 if (rc == CPIOERR_HDR_TRAILER) {
1409 /*@loopbreak@*/ break;
1412 /* Exit on error. */
1415 (void) fsmStage(fsm, FSM_UNDO);
1416 /*@loopbreak@*/ break;
1419 /* Copy file into archive. */
1420 rc = fsmStage(fsm, FSM_PROCESS);
1422 (void) fsmStage(fsm, FSM_UNDO);
1423 /*@loopbreak@*/ break;
1426 /* Notify on success. */
1427 (void) fsmStage(fsm, FSM_NOTIFY);
1429 if (fsmStage(fsm, FSM_FINI))
1430 /*@loopbreak@*/ break;
1433 /* Flush partial sets of hard linked files. */
1434 if (!(fsm->mapFlags & CPIO_ALL_HARDLINKS)) {
1436 while ((fsm->li = fsm->links) != NULL) {
1437 fsm->links = fsm->li->next;
1438 fsm->li->next = NULL;
1440 /* Re-calculate link count for archive header. */
1441 for (j = -1, nlink = 0, i = 0; i < fsm->li->nlink; i++) {
1442 if (fsm->li->filex[i] < 0)
1443 /*@innercontinue@*/ continue;
1447 /* XXX force the contents out as well. */
1450 fsm->li->filex[0] = fsm->li->filex[j];
1451 fsm->li->filex[j] = -1;
1454 fsm->li->sb.st_nlink = nlink;
1456 fsm->sb = fsm->li->sb; /* structure assignment */
1457 fsm->osb = fsm->sb; /* structure assignment */
1459 if (!rc) rc = writeLinkedFile(fsm);
1461 fsm->li = freeHardLink(fsm->li);
1466 rc = fsmStage(fsm, FSM_TRAILER);
1470 { rpmts ts = fsmGetTs(fsm);
1471 #define _tsmask (RPMTRANS_FLAG_PKGCOMMIT | RPMTRANS_FLAG_COMMIT)
1472 fsm->commit = ((ts && (rpmtsFlags(ts) & _tsmask) &&
1473 fsm->goal != FSM_PKGCOMMIT) ? 0 : 1);
1476 fsm->path = _free(fsm->path);
1477 fsm->opath = _free(fsm->opath);
1478 fsm->dnlx = _free(fsm->dnlx);
1480 fsm->ldn = _free(fsm->ldn);
1481 fsm->ldnalloc = fsm->ldnlen = 0;
1483 fsm->rdsize = fsm->wrsize = 0;
1484 fsm->rdbuf = fsm->rdb = _free(fsm->rdb);
1485 fsm->wrbuf = fsm->wrb = _free(fsm->wrb);
1486 if (fsm->goal == FSM_PKGINSTALL || fsm->goal == FSM_PKGBUILD) {
1487 fsm->rdsize = 8 * BUFSIZ;
1488 fsm->rdbuf = fsm->rdb = xmalloc(fsm->rdsize);
1489 fsm->wrsize = 8 * BUFSIZ;
1490 fsm->wrbuf = fsm->wrb = xmalloc(fsm->wrsize);
1493 fsm->mkdirsdone = 0;
1498 errno = 0; /* XXX get rid of EBADF */
1501 /* Detect and create directories not explicitly in package. */
1502 if (fsm->goal == FSM_PKGINSTALL) {
1503 rc = fsmStage(fsm, FSM_MKDIRS);
1504 if (!rc) fsm->mkdirsdone = 1;
1509 fsm->path = _free(fsm->path);
1511 fsm->diskchecked = fsm->exists = 0;
1513 fsm->suffix = (fsm->sufbuf[0] != '\0' ? fsm->sufbuf : NULL);
1514 fsm->action = FA_UNKNOWN;
1515 fsm->osuffix = NULL;
1516 fsm->nsuffix = NULL;
1518 if (fsm->goal == FSM_PKGINSTALL) {
1519 /* Read next header from payload, checking for end-of-payload. */
1520 rc = fsmStage(fsm, FSM_NEXT);
1524 /* Identify mapping index. */
1525 fsm->ix = ((fsm->goal == FSM_PKGINSTALL)
1526 ? mapFind(fsm->iter, fsm->path) : mapNextIterator(fsm->iter));
1528 /* Detect end-of-loop and/or mapping error. */
1530 if (fsm->goal == FSM_PKGINSTALL) {
1532 rpmMessage(RPMMESS_WARNING,
1533 _("archive file %s was not found in header file list\n"),
1537 if (fsm->failedFile && *fsm->failedFile == NULL)
1538 *fsm->failedFile = xstrdup(fsm->path);
1540 rc = CPIOERR_UNMAPPED_FILE;
1542 rc = CPIOERR_HDR_TRAILER;
1547 /* On non-install, mode must be known so that dirs don't get suffix. */
1548 if (fsm->goal != FSM_PKGINSTALL) {
1549 rpmfi fi = fsmGetFi(fsm);
1550 st->st_mode = fi->fmodes[fsm->ix];
1553 /* Generate file path. */
1554 rc = fsmStage(fsm, FSM_MAP);
1557 /* Perform lstat/stat for disk file. */
1561 if (fsm->path != NULL &&
1562 !(fsm->goal == FSM_PKGINSTALL && S_ISREG(st->st_mode)))
1564 rc = fsmStage(fsm, (!(fsm->mapFlags & CPIO_FOLLOW_SYMLINKS)
1565 ? FSM_LSTAT : FSM_STAT));
1566 if (rc == CPIOERR_LSTAT_FAILED && errno == ENOENT) {
1572 } else if (rc == 0) {
1576 /* Skip %ghost files on build. */
1580 fsm->diskchecked = 1;
1583 /* On non-install, the disk file stat is what's remapped. */
1585 if (fsm->goal != FSM_PKGINSTALL)
1586 *st = *ost; /* structure assignment */
1589 /* Remap file perms, owner, and group. */
1590 rc = fsmMapAttrs(fsm);
1593 fsm->postpone = XFA_SKIPPING(fsm->action);
1594 if (fsm->goal == FSM_PKGINSTALL || fsm->goal == FSM_PKGBUILD) {
1595 /*@-evalorder@*/ /* FIX: saveHardLink can modify fsm */
1596 if (!S_ISDIR(st->st_mode) && st->st_nlink > 1)
1597 fsm->postpone = saveHardLink(fsm);
1604 rc = fsmMapPath(fsm);
1607 rc = fsmMkdirs(fsm);
1611 rc = fsmRmdirs(fsm);
1614 if (fsm->postpone) {
1615 if (fsm->goal == FSM_PKGINSTALL)
1616 rc = fsmStage(fsm, FSM_EAT);
1620 if (fsm->goal == FSM_PKGBUILD) {
1621 if (!S_ISDIR(st->st_mode) && st->st_nlink > 1) {
1622 struct hardLink_s * li, * prev;
1624 if (!(fsm->mapFlags & CPIO_ALL_HARDLINKS)) break;
1625 rc = writeLinkedFile(fsm);
1626 if (rc) break; /* W2DO? */
1628 for (li = fsm->links, prev = NULL; li; prev = li, li = li->next)
1630 /*@loopbreak@*/ break;
1633 fsm->links = fsm->li->next;
1635 prev->next = fsm->li->next;
1636 fsm->li->next = NULL;
1637 fsm->li = freeHardLink(fsm->li);
1639 rc = writeFile(fsm, 1);
1644 if (fsm->goal != FSM_PKGINSTALL)
1647 if (S_ISREG(st->st_mode)) {
1648 const char * path = fsm->path;
1650 fsm->path = fsmFsPath(fsm, st, NULL, NULL);
1651 rc = fsmStage(fsm, FSM_VERIFY);
1653 if (rc == 0 && fsm->osuffix) {
1654 const char * opath = fsm->opath;
1655 fsm->opath = fsm->path;
1656 fsm->path = fsmFsPath(fsm, st, NULL, fsm->osuffix);
1657 rc = fsmStage(fsm, FSM_RENAME);
1659 rpmMessage(RPMMESS_WARNING,
1660 _("%s saved as %s\n"), fsm->opath, fsm->path);
1661 fsm->path = _free(fsm->path);
1665 /*@-dependenttrans@*/
1667 /*@=dependenttrans@*/
1668 if (rc != CPIOERR_LSTAT_FAILED) return rc;
1669 rc = expandRegular(fsm);
1670 } else if (S_ISDIR(st->st_mode)) {
1671 mode_t st_mode = st->st_mode;
1672 rc = fsmStage(fsm, FSM_VERIFY);
1673 if (rc == CPIOERR_LSTAT_FAILED) {
1674 st->st_mode &= ~07777; /* XXX abuse st->st_mode */
1675 st->st_mode |= 00700;
1676 rc = fsmStage(fsm, FSM_MKDIR);
1677 st->st_mode = st_mode; /* XXX restore st->st_mode */
1679 } else if (S_ISLNK(st->st_mode)) {
1680 const char * opath = fsm->opath;
1682 if ((st->st_size + 1) > fsm->rdsize) {
1683 rc = CPIOERR_HDR_SIZE;
1687 fsm->wrlen = st->st_size;
1688 rc = fsmStage(fsm, FSM_DREAD);
1689 if (!rc && fsm->rdnb != fsm->wrlen)
1690 rc = CPIOERR_READ_FAILED;
1694 fsm->wrbuf[st->st_size] = '\0';
1696 /* XXX symlink(fsm->opath, fsm->path) */
1697 /*@-dependenttrans@*/
1698 fsm->opath = fsm->wrbuf;
1699 /*@=dependenttrans@*/
1700 rc = fsmStage(fsm, FSM_VERIFY);
1701 if (rc == CPIOERR_LSTAT_FAILED)
1702 rc = fsmStage(fsm, FSM_SYMLINK);
1703 fsm->opath = opath; /* XXX restore fsm->path */
1704 } else if (S_ISFIFO(st->st_mode)) {
1705 mode_t st_mode = st->st_mode;
1706 /* This mimics cpio S_ISSOCK() behavior but probably isnt' right */
1707 rc = fsmStage(fsm, FSM_VERIFY);
1708 if (rc == CPIOERR_LSTAT_FAILED) {
1709 st->st_mode = 0000; /* XXX abuse st->st_mode */
1710 rc = fsmStage(fsm, FSM_MKFIFO);
1711 st->st_mode = st_mode; /* XXX restore st->st_mode */
1713 } else if (S_ISCHR(st->st_mode) ||
1714 S_ISBLK(st->st_mode) ||
1715 /*@-unrecog@*/ S_ISSOCK(st->st_mode) /*@=unrecog@*/)
1717 rc = fsmStage(fsm, FSM_VERIFY);
1718 if (rc == CPIOERR_LSTAT_FAILED)
1719 rc = fsmStage(fsm, FSM_MKNOD);
1721 /* XXX Special case /dev/log, which shouldn't be packaged anyways */
1722 if (!IS_DEV_LOG(fsm->path))
1723 rc = CPIOERR_UNKNOWN_FILETYPE;
1725 if (!S_ISDIR(st->st_mode) && st->st_nlink > 1) {
1726 fsm->li->createdPath = fsm->li->linkIndex;
1727 rc = fsmMakeLinks(fsm);
1733 rc = fsmMakeLinks(fsm);
1735 case FSM_NOTIFY: /* XXX move from fsm to psm -> tsm */
1736 if (fsm->goal == FSM_PKGINSTALL || fsm->goal == FSM_PKGBUILD) {
1737 rpmts ts = fsmGetTs(fsm);
1738 rpmfi fi = fsmGetFi(fsm);
1740 unsigned int archivePos = fdGetCpioPos(fsm->cfd);
1741 if (archivePos > fi->archivePos) {
1742 fi->archivePos = archivePos;
1743 ptr = rpmtsNotify(ts, fi->te, RPMCALLBACK_INST_PROGRESS,
1744 fi->archivePos, fi->archiveSize);
1751 if (fsm->goal == FSM_PKGINSTALL) {
1752 (void) fsmStage(fsm,
1753 (S_ISDIR(st->st_mode) ? FSM_RMDIR : FSM_UNLINK));
1755 #ifdef NOTYET /* XXX remove only dirs just created, not all. */
1757 (void) fsmStage(fsm, FSM_RMDIRS);
1764 if (fsm->failedFile && *fsm->failedFile == NULL)
1765 *fsm->failedFile = xstrdup(fsm->path);
1769 if (!fsm->postpone && fsm->commit) {
1770 if (fsm->goal == FSM_PKGINSTALL)
1771 rc = ((!S_ISDIR(st->st_mode) && st->st_nlink > 1)
1772 ? fsmCommitLinks(fsm) : fsmStage(fsm, FSM_COMMIT));
1773 if (fsm->goal == FSM_PKGCOMMIT)
1774 rc = fsmStage(fsm, FSM_COMMIT);
1775 if (fsm->goal == FSM_PKGERASE)
1776 rc = fsmStage(fsm, FSM_COMMIT);
1778 fsm->path = _free(fsm->path);
1779 fsm->opath = _free(fsm->opath);
1781 memset(st, 0, sizeof(*st));
1782 memset(ost, 0, sizeof(*ost));
1786 /* Rename pre-existing modified or unmanaged file. */
1787 if (fsm->osuffix && fsm->diskchecked &&
1788 (fsm->exists || (fsm->goal == FSM_PKGINSTALL && S_ISREG(st->st_mode))))
1790 const char * opath = fsm->opath;
1791 const char * path = fsm->path;
1792 fsm->opath = fsmFsPath(fsm, st, NULL, NULL);
1793 fsm->path = fsmFsPath(fsm, st, NULL, fsm->osuffix);
1794 rc = fsmStage(fsm, FSM_RENAME);
1796 rpmMessage(RPMMESS_WARNING, _("%s saved as %s\n"),
1797 fsm->opath, fsm->path);
1799 fsm->path = _free(fsm->path);
1801 fsm->opath = _free(fsm->opath);
1805 /* Remove erased files. */
1806 if (fsm->goal == FSM_PKGERASE) {
1807 if (fsm->action == FA_ERASE) {
1808 rpmfi fi = fsmGetFi(fsm);
1809 if (S_ISDIR(st->st_mode)) {
1810 rc = fsmStage(fsm, FSM_RMDIR);
1813 case ENOENT: /* XXX rmdir("/") linux 2.2.x kernel hack */
1815 /* XXX make sure that build side permits %missingok on directories. */
1816 if (fsm->fflags & RPMFILE_MISSINGOK)
1817 /*@innerbreak@*/ break;
1819 /* XXX common error message. */
1821 (strict_erasures ? RPMERR_RMDIR : RPMDEBUG_RMDIR),
1822 _("%s rmdir of %s failed: Directory not empty\n"),
1823 rpmfiTypeString(fi), fsm->path);
1824 /*@innerbreak@*/ break;
1827 (strict_erasures ? RPMERR_RMDIR : RPMDEBUG_RMDIR),
1828 _("%s rmdir of %s failed: %s\n"),
1829 rpmfiTypeString(fi), fsm->path, strerror(errno));
1830 /*@innerbreak@*/ break;
1833 rc = fsmStage(fsm, FSM_UNLINK);
1835 if (!(errno == ENOENT && (fsm->fflags & RPMFILE_MISSINGOK)))
1837 (strict_erasures ? RPMERR_UNLINK : RPMDEBUG_UNLINK),
1838 _("%s unlink of %s failed: %s\n"),
1839 rpmfiTypeString(fi), fsm->path, strerror(errno));
1842 /* XXX Failure to remove is not (yet) cause for failure. */
1843 if (!strict_erasures) rc = 0;
1847 /* XXX Special case /dev/log, which shouldn't be packaged anyways */
1848 if (!S_ISSOCK(st->st_mode) && !IS_DEV_LOG(fsm->path)) {
1849 /* Rename temporary to final file name. */
1850 if (!S_ISDIR(st->st_mode) &&
1851 (fsm->subdir || fsm->suffix || fsm->nsuffix))
1853 fsm->opath = fsm->path;
1854 fsm->path = fsmFsPath(fsm, st, NULL, fsm->nsuffix);
1855 rc = fsmStage(fsm, FSM_RENAME);
1856 if (!rc && fsm->nsuffix) {
1857 const char * opath = fsmFsPath(fsm, st, NULL, NULL);
1858 rpmMessage(RPMMESS_WARNING, _("%s created as %s\n"),
1859 (opath ? opath : ""), fsm->path);
1860 opath = _free(opath);
1862 fsm->opath = _free(fsm->opath);
1864 if (S_ISLNK(st->st_mode)) {
1865 if (!rc && !getuid())
1866 rc = fsmStage(fsm, FSM_LCHOWN);
1868 if (!rc && !getuid())
1869 rc = fsmStage(fsm, FSM_CHOWN);
1871 rc = fsmStage(fsm, FSM_CHMOD);
1873 time_t mtime = st->st_mtime;
1874 rpmfi fi = fsmGetFi(fsm);
1876 st->st_mtime = fi->fmtimes[fsm->ix];
1877 rc = fsmStage(fsm, FSM_UTIME);
1878 st->st_mtime = mtime;
1883 /* Notify on success. */
1884 if (!rc) rc = fsmStage(fsm, FSM_NOTIFY);
1885 else if (fsm->failedFile && *fsm->failedFile == NULL) {
1887 *fsm->failedFile = fsm->path;
1893 fsm->path = _free(fsm->path);
1895 /* Check for hard links missing from payload. */
1896 while ((fsm->li = fsm->links) != NULL) {
1897 fsm->links = fsm->li->next;
1898 fsm->li->next = NULL;
1899 if (fsm->goal == FSM_PKGINSTALL &&
1900 fsm->commit && fsm->li->linksLeft)
1902 for (i = 0 ; i < fsm->li->linksLeft; i++) {
1903 if (fsm->li->filex[i] < 0)
1904 /*@innercontinue@*/ continue;
1905 rc = CPIOERR_MISSING_HARDLINK;
1906 if (fsm->failedFile && *fsm->failedFile == NULL) {
1907 fsm->ix = fsm->li->filex[i];
1908 if (!fsmStage(fsm, FSM_MAP)) {
1910 *fsm->failedFile = fsm->path;
1915 /*@loopbreak@*/ break;
1918 if (fsm->goal == FSM_PKGBUILD &&
1919 (fsm->mapFlags & CPIO_ALL_HARDLINKS))
1921 rc = CPIOERR_MISSING_HARDLINK;
1923 fsm->li = freeHardLink(fsm->li);
1925 fsm->ldn = _free(fsm->ldn);
1926 fsm->ldnalloc = fsm->ldnlen = 0;
1927 fsm->rdbuf = fsm->rdb = _free(fsm->rdb);
1928 fsm->wrbuf = fsm->wrb = _free(fsm->wrb);
1931 if (fsm->diskchecked && !fsm->exists) {
1932 rc = CPIOERR_LSTAT_FAILED;
1935 if (S_ISREG(st->st_mode)) {
1936 char * path = alloca(strlen(fsm->path) + sizeof("-RPMDELETE"));
1938 (void) stpcpy( stpcpy(path, fsm->path), "-RPMDELETE");
1941 * XXX HP-UX (and other os'es) don't permit unlink on busy
1944 fsm->opath = fsm->path;
1946 rc = fsmStage(fsm, FSM_RENAME);
1948 (void) fsmStage(fsm, FSM_UNLINK);
1950 rc = CPIOERR_UNLINK_FAILED;
1951 fsm->path = fsm->opath;
1953 return (rc ? rc : CPIOERR_LSTAT_FAILED); /* XXX HACK */
1954 /*@notreached@*/ break;
1955 } else if (S_ISDIR(st->st_mode)) {
1956 if (S_ISDIR(ost->st_mode)) return 0;
1957 if (S_ISLNK(ost->st_mode)) {
1958 rc = fsmStage(fsm, FSM_STAT);
1959 if (rc == CPIOERR_STAT_FAILED && errno == ENOENT) rc = 0;
1964 if (S_ISDIR(ost->st_mode)) return 0;
1966 } else if (S_ISLNK(st->st_mode)) {
1967 if (S_ISLNK(ost->st_mode)) {
1968 /* XXX NUL terminated result in fsm->rdbuf, len in fsm->rdnb. */
1969 rc = fsmStage(fsm, FSM_READLINK);
1974 if (!strcmp(fsm->opath, fsm->rdbuf)) return 0;
1976 } else if (S_ISFIFO(st->st_mode)) {
1977 if (S_ISFIFO(ost->st_mode)) return 0;
1978 } else if (S_ISCHR(st->st_mode) || S_ISBLK(st->st_mode)) {
1979 if ((S_ISCHR(ost->st_mode) || S_ISBLK(ost->st_mode)) &&
1980 (ost->st_rdev == st->st_rdev)) return 0;
1981 } else if (S_ISSOCK(st->st_mode)) {
1982 if (S_ISSOCK(ost->st_mode)) return 0;
1984 /* XXX shouldn't do this with commit/undo. */
1986 if (fsm->stage == FSM_PROCESS) rc = fsmStage(fsm, FSM_UNLINK);
1987 if (rc == 0) rc = CPIOERR_LSTAT_FAILED;
1988 return (rc ? rc : CPIOERR_LSTAT_FAILED); /* XXX HACK */
1989 /*@notreached@*/ break;
1992 rc = Unlink(fsm->path);
1993 if (_fsm_debug && (stage & FSM_SYSCALL))
1994 rpmMessage(RPMMESS_DEBUG, " %8s (%s) %s\n", cur,
1995 fsm->path, (rc < 0 ? strerror(errno) : ""));
1996 if (rc < 0) rc = CPIOERR_UNLINK_FAILED;
1999 rc = Rename(fsm->opath, fsm->path);
2000 if (_fsm_debug && (stage & FSM_SYSCALL))
2001 rpmMessage(RPMMESS_DEBUG, " %8s (%s, %s) %s\n", cur,
2002 fsm->opath, fsm->path, (rc < 0 ? strerror(errno) : ""));
2003 if (rc < 0) rc = CPIOERR_RENAME_FAILED;
2006 rc = Mkdir(fsm->path, (st->st_mode & 07777));
2007 if (_fsm_debug && (stage & FSM_SYSCALL))
2008 rpmMessage(RPMMESS_DEBUG, " %8s (%s, 0%04o) %s\n", cur,
2009 fsm->path, (unsigned)(st->st_mode & 07777),
2010 (rc < 0 ? strerror(errno) : ""));
2011 if (rc < 0) rc = CPIOERR_MKDIR_FAILED;
2014 rc = Rmdir(fsm->path);
2015 if (_fsm_debug && (stage & FSM_SYSCALL))
2016 rpmMessage(RPMMESS_DEBUG, " %8s (%s) %s\n", cur,
2017 fsm->path, (rc < 0 ? strerror(errno) : ""));
2018 if (rc < 0) rc = CPIOERR_RMDIR_FAILED;
2021 rc = chown(fsm->path, st->st_uid, st->st_gid);
2022 if (_fsm_debug && (stage & FSM_SYSCALL))
2023 rpmMessage(RPMMESS_DEBUG, " %8s (%s, %d, %d) %s\n", cur,
2024 fsm->path, (int)st->st_uid, (int)st->st_gid,
2025 (rc < 0 ? strerror(errno) : ""));
2026 if (rc < 0) rc = CPIOERR_CHOWN_FAILED;
2029 #if ! CHOWN_FOLLOWS_SYMLINK
2030 rc = lchown(fsm->path, st->st_uid, st->st_gid);
2031 if (_fsm_debug && (stage & FSM_SYSCALL))
2032 rpmMessage(RPMMESS_DEBUG, " %8s (%s, %d, %d) %s\n", cur,
2033 fsm->path, (int)st->st_uid, (int)st->st_gid,
2034 (rc < 0 ? strerror(errno) : ""));
2035 if (rc < 0) rc = CPIOERR_CHOWN_FAILED;
2039 rc = chmod(fsm->path, (st->st_mode & 07777));
2040 if (_fsm_debug && (stage & FSM_SYSCALL))
2041 rpmMessage(RPMMESS_DEBUG, " %8s (%s, 0%04o) %s\n", cur,
2042 fsm->path, (unsigned)(st->st_mode & 07777),
2043 (rc < 0 ? strerror(errno) : ""));
2044 if (rc < 0) rc = CPIOERR_CHMOD_FAILED;
2047 { struct utimbuf stamp;
2048 stamp.actime = st->st_mtime;
2049 stamp.modtime = st->st_mtime;
2050 rc = utime(fsm->path, &stamp);
2051 if (_fsm_debug && (stage & FSM_SYSCALL))
2052 rpmMessage(RPMMESS_DEBUG, " %8s (%s, 0x%x) %s\n", cur,
2053 fsm->path, (unsigned)st->st_mtime,
2054 (rc < 0 ? strerror(errno) : ""));
2055 if (rc < 0) rc = CPIOERR_UTIME_FAILED;
2059 rc = symlink(fsm->opath, fsm->path);
2060 if (_fsm_debug && (stage & FSM_SYSCALL))
2061 rpmMessage(RPMMESS_DEBUG, " %8s (%s, %s) %s\n", cur,
2062 fsm->opath, fsm->path, (rc < 0 ? strerror(errno) : ""));
2063 if (rc < 0) rc = CPIOERR_SYMLINK_FAILED;
2066 rc = Link(fsm->opath, fsm->path);
2067 if (_fsm_debug && (stage & FSM_SYSCALL))
2068 rpmMessage(RPMMESS_DEBUG, " %8s (%s, %s) %s\n", cur,
2069 fsm->opath, fsm->path, (rc < 0 ? strerror(errno) : ""));
2070 if (rc < 0) rc = CPIOERR_LINK_FAILED;
2073 rc = mkfifo(fsm->path, (st->st_mode & 07777));
2074 if (_fsm_debug && (stage & FSM_SYSCALL))
2075 rpmMessage(RPMMESS_DEBUG, " %8s (%s, 0%04o) %s\n", cur,
2076 fsm->path, (unsigned)(st->st_mode & 07777),
2077 (rc < 0 ? strerror(errno) : ""));
2078 if (rc < 0) rc = CPIOERR_MKFIFO_FAILED;
2081 /*@-unrecog -portability @*/ /* FIX: check S_IFIFO or dev != 0 */
2082 rc = mknod(fsm->path, (st->st_mode & ~07777), st->st_rdev);
2083 /*@=unrecog =portability @*/
2084 if (_fsm_debug && (stage & FSM_SYSCALL))
2085 rpmMessage(RPMMESS_DEBUG, " %8s (%s, 0%o, 0x%x) %s\n", cur,
2086 fsm->path, (unsigned)(st->st_mode & ~07777),
2087 (unsigned)st->st_rdev,
2088 (rc < 0 ? strerror(errno) : ""));
2089 if (rc < 0) rc = CPIOERR_MKNOD_FAILED;
2092 rc = Lstat(fsm->path, ost);
2093 if (_fsm_debug && (stage & FSM_SYSCALL) && rc && errno != ENOENT)
2094 rpmMessage(RPMMESS_DEBUG, " %8s (%s, ost) %s\n", cur,
2095 fsm->path, (rc < 0 ? strerror(errno) : ""));
2096 if (rc < 0) rc = CPIOERR_LSTAT_FAILED;
2099 rc = Stat(fsm->path, ost);
2100 if (_fsm_debug && (stage & FSM_SYSCALL) && rc && errno != ENOENT)
2101 rpmMessage(RPMMESS_DEBUG, " %8s (%s, ost) %s\n", cur,
2102 fsm->path, (rc < 0 ? strerror(errno) : ""));
2103 if (rc < 0) rc = CPIOERR_STAT_FAILED;
2106 /* XXX NUL terminated result in fsm->rdbuf, len in fsm->rdnb. */
2108 rc = Readlink(fsm->path, fsm->rdbuf, fsm->rdsize - 1);
2110 if (_fsm_debug && (stage & FSM_SYSCALL))
2111 rpmMessage(RPMMESS_DEBUG, " %8s (%s, rdbuf, %d) %s\n", cur,
2112 fsm->path, (int)(fsm->rdsize -1), (rc < 0 ? strerror(errno) : ""));
2113 if (rc < 0) rc = CPIOERR_READLINK_FAILED;
2117 fsm->rdbuf[fsm->rdnb] = '\0';
2126 rc = fsmStage(fsm, FSM_HREAD);
2128 if (!strcmp(fsm->path, CPIO_TRAILER)) { /* Detect end-of-payload. */
2129 fsm->path = _free(fsm->path);
2130 rc = CPIOERR_HDR_TRAILER;
2133 rc = fsmStage(fsm, FSM_POS);
2136 for (left = st->st_size; left > 0; left -= fsm->rdnb) {
2137 fsm->wrlen = (left > fsm->wrsize ? fsm->wrsize : left);
2138 rc = fsmStage(fsm, FSM_DREAD);
2140 /*@loopbreak@*/ break;
2144 left = (modulo - (fdGetCpioPos(fsm->cfd) % modulo)) % modulo;
2147 (void) fsmStage(fsm, FSM_DREAD);
2151 left = (modulo - (fdGetCpioPos(fsm->cfd) % modulo)) % modulo;
2154 memset(fsm->rdbuf, 0, left);
2156 /* XXX DWRITE uses rdnb for I/O length. */
2158 (void) fsmStage(fsm, FSM_DWRITE);
2162 rc = cpioTrailerWrite(fsm);
2165 rc = fsmStage(fsm, FSM_POS);
2167 rc = cpioHeaderRead(fsm, st); /* Read next payload header. */
2170 rc = cpioHeaderWrite(fsm, st); /* Write next payload header. */
2174 fsm->rdnb = Fread(fsm->wrbuf, sizeof(*fsm->wrbuf), fsm->wrlen, fsm->cfd);
2176 if (_fsm_debug && (stage & FSM_SYSCALL))
2177 rpmMessage(RPMMESS_DEBUG, " %8s (%s, %d, cfd)\trdnb %d\n",
2178 cur, (fsm->wrbuf == fsm->wrb ? "wrbuf" : "mmap"),
2179 (int)fsm->wrlen, (int)fsm->rdnb);
2180 if (fsm->rdnb != fsm->wrlen || Ferror(fsm->cfd))
2181 rc = CPIOERR_READ_FAILED;
2183 fdSetCpioPos(fsm->cfd, fdGetCpioPos(fsm->cfd) + fsm->rdnb);
2186 fsm->wrnb = Fwrite(fsm->rdbuf, sizeof(*fsm->rdbuf), fsm->rdnb, fsm->cfd);
2187 if (_fsm_debug && (stage & FSM_SYSCALL))
2188 rpmMessage(RPMMESS_DEBUG, " %8s (%s, %d, cfd)\twrnb %d\n",
2189 cur, (fsm->rdbuf == fsm->rdb ? "rdbuf" : "mmap"),
2190 (int)fsm->rdnb, (int)fsm->wrnb);
2191 if (fsm->rdnb != fsm->wrnb || Ferror(fsm->cfd))
2192 rc = CPIOERR_WRITE_FAILED;
2194 fdSetCpioPos(fsm->cfd, fdGetCpioPos(fsm->cfd) + fsm->wrnb);
2198 fsm->rfd = Fopen(fsm->path, "r.ufdio");
2199 if (fsm->rfd == NULL || Ferror(fsm->rfd)) {
2200 if (fsm->rfd) (void) fsmStage(fsm, FSM_RCLOSE);
2202 rc = CPIOERR_OPEN_FAILED;
2205 if (_fsm_debug && (stage & FSM_SYSCALL))
2206 rpmMessage(RPMMESS_DEBUG, " %8s (%s, \"r\") rfd %p rdbuf %p\n", cur,
2207 fsm->path, fsm->rfd, fsm->rdbuf);
2211 fsm->rdnb = Fread(fsm->rdbuf, sizeof(*fsm->rdbuf), fsm->rdlen, fsm->rfd);
2213 if (_fsm_debug && (stage & FSM_SYSCALL))
2214 rpmMessage(RPMMESS_DEBUG, " %8s (rdbuf, %d, rfd)\trdnb %d\n",
2215 cur, (int)fsm->rdlen, (int)fsm->rdnb);
2216 if (fsm->rdnb != fsm->rdlen || Ferror(fsm->rfd))
2217 rc = CPIOERR_READ_FAILED;
2221 if (_fsm_debug && (stage & FSM_SYSCALL))
2222 rpmMessage(RPMMESS_DEBUG, " %8s (%p)\n", cur, fsm->rfd);
2223 (void) Fclose(fsm->rfd);
2231 fsm->wfd = Fopen(fsm->path, "w.ufdio");
2232 if (fsm->wfd == NULL || Ferror(fsm->wfd)) {
2233 if (fsm->wfd) (void) fsmStage(fsm, FSM_WCLOSE);
2235 rc = CPIOERR_OPEN_FAILED;
2237 if (_fsm_debug && (stage & FSM_SYSCALL))
2238 rpmMessage(RPMMESS_DEBUG, " %8s (%s, \"w\") wfd %p wrbuf %p\n", cur,
2239 fsm->path, fsm->wfd, fsm->wrbuf);
2242 fsm->wrnb = Fwrite(fsm->wrbuf, sizeof(*fsm->wrbuf), fsm->rdnb, fsm->wfd);
2243 if (_fsm_debug && (stage & FSM_SYSCALL))
2244 rpmMessage(RPMMESS_DEBUG, " %8s (wrbuf, %d, wfd)\twrnb %d\n",
2245 cur, (int)fsm->rdnb, (int)fsm->wrnb);
2246 if (fsm->rdnb != fsm->wrnb || Ferror(fsm->wfd))
2247 rc = CPIOERR_WRITE_FAILED;
2251 if (_fsm_debug && (stage & FSM_SYSCALL))
2252 rpmMessage(RPMMESS_DEBUG, " %8s (%p)\n", cur, fsm->wfd);
2253 (void) Fclose(fsm->wfd);
2266 if (!(stage & FSM_INTERNAL)) {
2267 fsm->rc = (rc == CPIOERR_HDR_TRAILER ? 0 : rc);
2274 /*@obserever@*/ const char *const fileActionString(fileAction a)
2277 case FA_UNKNOWN: return "unknown";
2278 case FA_CREATE: return "create";
2279 case FA_COPYOUT: return "copyout";
2280 case FA_COPYIN: return "copyin";
2281 case FA_BACKUP: return "backup";
2282 case FA_SAVE: return "save";
2283 case FA_SKIP: return "skip";
2284 case FA_ALTNAME: return "altname";
2285 case FA_ERASE: return "erase";
2286 case FA_SKIPNSTATE: return "skipnstate";
2287 case FA_SKIPNETSHARED: return "skipnetshared";
2288 case FA_SKIPMULTILIB: return "skipmultilib";
2289 default: return "???";
2294 /*@observer@*/ const char *const fileStageString(fileStage a) {
2296 case FSM_UNKNOWN: return "unknown";
2298 case FSM_PKGINSTALL:return "INSTALL";
2299 case FSM_PKGERASE: return "ERASE";
2300 case FSM_PKGBUILD: return "BUILD";
2301 case FSM_PKGCOMMIT: return "COMMIT";
2302 case FSM_PKGUNDO: return "UNDO";
2304 case FSM_CREATE: return "create";
2305 case FSM_INIT: return "init";
2306 case FSM_MAP: return "map";
2307 case FSM_MKDIRS: return "mkdirs";
2308 case FSM_RMDIRS: return "rmdirs";
2309 case FSM_PRE: return "pre";
2310 case FSM_PROCESS: return "process";
2311 case FSM_POST: return "post";
2312 case FSM_MKLINKS: return "mklinks";
2313 case FSM_NOTIFY: return "notify";
2314 case FSM_UNDO: return "undo";
2315 case FSM_FINI: return "fini";
2316 case FSM_COMMIT: return "commit";
2317 case FSM_DESTROY: return "destroy";
2318 case FSM_VERIFY: return "verify";
2320 case FSM_UNLINK: return "Unlink";
2321 case FSM_RENAME: return "Rename";
2322 case FSM_MKDIR: return "Mkdir";
2323 case FSM_RMDIR: return "rmdir";
2324 case FSM_CHOWN: return "chown";
2325 case FSM_LCHOWN: return "lchown";
2326 case FSM_CHMOD: return "chmod";
2327 case FSM_UTIME: return "utime";
2328 case FSM_SYMLINK: return "symlink";
2329 case FSM_LINK: return "Link";
2330 case FSM_MKFIFO: return "mkfifo";
2331 case FSM_MKNOD: return "mknod";
2332 case FSM_LSTAT: return "Lstat";
2333 case FSM_STAT: return "Stat";
2334 case FSM_READLINK: return "Readlink";
2335 case FSM_CHROOT: return "chroot";
2337 case FSM_NEXT: return "next";
2338 case FSM_EAT: return "eat";
2339 case FSM_POS: return "pos";
2340 case FSM_PAD: return "pad";
2341 case FSM_TRAILER: return "trailer";
2342 case FSM_HREAD: return "hread";
2343 case FSM_HWRITE: return "hwrite";
2344 case FSM_DREAD: return "Fread";
2345 case FSM_DWRITE: return "Fwrite";
2347 case FSM_ROPEN: return "Fopen";
2348 case FSM_READ: return "Fread";
2349 case FSM_RCLOSE: return "Fclose";
2350 case FSM_WOPEN: return "Fopen";
2351 case FSM_WRITE: return "Fwrite";
2352 case FSM_WCLOSE: return "Fclose";
2354 default: return "???";