3 * File state machine to handle a payload from a package.
8 #include <rpmio_internal.h>
15 #define _RPMFI_INTERNAL
22 /*@access FD_t @*/ /* XXX void ptr args */
28 #define alloca_strdup(_s) strcpy(alloca(strlen(_s)+1), (_s))
32 int _fsm_debug = _FSM_DEBUG;
34 /* XXX Failure to remove is not (yet) cause for failure. */
35 /*@-exportlocal -exportheadervar@*/
37 int strict_erasures = 0;
38 /*@=exportlocal =exportheadervar@*/
40 rpmts fsmGetTs(const FSM_t fsm) {
41 const FSMI_t iter = fsm->iter;
42 /*@-compdef -refcounttrans -retexpose -usereleased @*/
43 return (iter ? iter->ts : NULL);
44 /*@=compdef =refcounttrans =retexpose =usereleased @*/
47 rpmfi fsmGetFi(const FSM_t fsm)
49 const FSMI_t iter = fsm->iter;
50 /*@-compdef -refcounttrans -retexpose -usereleased @*/
51 return (iter ? iter->fi : NULL);
52 /*@=compdef =refcounttrans =retexpose =usereleased @*/
55 #define SUFFIX_RPMORIG ".rpmorig"
56 #define SUFFIX_RPMSAVE ".rpmsave"
57 #define SUFFIX_RPMNEW ".rpmnew"
60 * Build path to file from file info, ornamented with subdir and suffix.
61 * @param fsm file state machine data
62 * @param st file stat info
63 * @param subdir subdir to use (NULL disables)
64 * @param suffix suffix to use (NULL disables)
65 * @retval path to file
67 static /*@only@*//*@null@*/
68 const char * fsmFsPath(/*@special@*/ /*@null@*/ const FSM_t fsm,
69 /*@null@*/ const struct stat * st,
70 /*@null@*/ const char * subdir,
71 /*@null@*/ const char * suffix)
72 /*@uses fsm->dirName, fsm->baseName */
75 const char * s = NULL;
80 nb = strlen(fsm->dirName) +
81 (st && !S_ISDIR(st->st_mode) ? (subdir ? strlen(subdir) : 0) : 0) +
82 (st && !S_ISDIR(st->st_mode) ? (suffix ? strlen(suffix) : 0) : 0) +
83 strlen(fsm->baseName) + 1;
86 t = stpcpy(t, fsm->dirName);
87 if (st && !S_ISDIR(st->st_mode))
88 if (subdir) t = stpcpy(t, subdir);
89 t = stpcpy(t, fsm->baseName);
90 if (st && !S_ISDIR(st->st_mode))
91 if (suffix) t = stpcpy(t, suffix);
98 * Destroy file info iterator.
99 * @param p file info iterator
100 * @retval NULL always
102 static /*@null@*/ void * mapFreeIterator(/*@only@*//*@null@*/ void * p)
103 /*@globals fileSystem @*/
104 /*@modifies fileSystem @*/
108 iter->ts = rpmtsFree(iter->ts);
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 /* XXX Some 4+ year old rpm packages have basename only in payloads. */
168 #ifdef VERY_OLD_BUGGY_RPM_PACKAGES
169 if (strchr(afn, '/') == NULL)
170 bfn = strrchr(bfn, '/') + 1;
173 /* Match rpm-4.0 payloads with ./ prefixes. */
174 if (afn[0] == '.' && afn[1] == '/') afn += 2;
175 if (bfn[0] == '.' && bfn[1] == '/') bfn += 2;
177 /* If either path is absolute, make it relative. */
178 if (afn[0] == '/') afn += 1;
179 if (bfn[0] == '/') bfn += 1;
181 return strcmp(afn, bfn);
186 * Locate archive path in file info.
187 * @param iter file info iterator
188 * @param fsmPath archive path
189 * @return index into file info, -1 if archive path was not found
192 static int mapFind(/*@null@*/ FSMI_t iter, const char * fsmPath)
198 const rpmfi fi = iter->fi;
199 if (fi && fi->fc > 0 && fi->apath && fsmPath && *fsmPath) {
200 const char ** p = NULL;
203 if (fi->apath != NULL)
204 p = bsearch(&fsmPath, fi->apath, fi->fc, sizeof(fsmPath),
208 iter->i = p - fi->apath;
209 ix = mapNextIterator(iter);
218 * Directory name iterator.
220 typedef struct dnli_s {
222 /*@only@*/ /*@null@*/
230 * Destroy directory name iterator.
231 * @param a directory name iterator
232 * @retval NULL always
234 static /*@null@*/ void * dnlFreeIterator(/*@only@*//*@null@*/ const void * a)
238 DNLI_t dnli = (void *)a;
239 if (dnli->active) free(dnli->active);
246 static inline int dnlCount(const DNLI_t dnli)
249 return (dnli ? dnli->fi->dc : 0);
254 static inline int dnlIndex(const DNLI_t dnli)
257 return (dnli ? dnli->isave : -1);
261 * Create directory name iterator.
262 * @param fsm file state machine data
263 * @param reverse traverse directory names in reverse order?
264 * @return directory name iterator
268 static /*@only@*/ void * dnlInitIterator(/*@special@*/ const FSM_t fsm,
270 /*@uses fsm->iter @*/
273 rpmfi fi = fsmGetFi(fsm);
279 dnli = xcalloc(1, sizeof(*dnli));
281 dnli->reverse = reverse;
283 dnli->i = (reverse ? fi->dc : 0);
287 dnli->active = xcalloc(fi->dc, sizeof(*dnli->active));
289 /* Identify parent directories not skipped. */
291 for (i = 0; i < fi->fc; i++)
292 if (!XFA_SKIPPING(fi->actions[i])) dnli->active[fi->dil[i]] = 1;
295 /* Exclude parent directories that are explicitly included. */
296 for (i = 0; i < fi->fc; i++) {
297 int dil, dnlen, bnlen;
299 if (!S_ISDIR(fi->fmodes[i]))
303 dnlen = strlen(fi->dnl[dil]);
304 bnlen = strlen(fi->bnl[i]);
306 for (j = 0; j < fi->dc; j++) {
310 if (!dnli->active[j] || j == dil)
311 /*@innercontinue@*/ continue;
314 if (jlen != (dnlen+bnlen+1))
315 /*@innercontinue@*/ continue;
316 if (strncmp(dnl, fi->dnl[dil], dnlen))
317 /*@innercontinue@*/ continue;
318 if (strncmp(dnl+dnlen, fi->bnl[i], bnlen))
319 /*@innercontinue@*/ continue;
320 if (dnl[dnlen+bnlen] != '/' || dnl[dnlen+bnlen+1] != '\0')
321 /*@innercontinue@*/ continue;
322 /* This directory is included in the package. */
326 /*@innerbreak@*/ break;
330 /* Print only once per package. */
333 for (i = 0; i < fi->dc; i++) {
334 if (!dnli->active[i]) continue;
337 rpmMessage(RPMMESS_DEBUG,
338 _("========== Directories not explictly included in package:\n"));
340 rpmMessage(RPMMESS_DEBUG, _("%10d %s\n"), i, fi->dnl[i]);
343 rpmMessage(RPMMESS_DEBUG, "==========\n");
352 * Return next directory name (from file info).
353 * @param dnli directory name iterator
354 * @return next directory name
357 static /*@observer@*/ const char * dnlNextIterator(/*@null@*/ DNLI_t dnli)
360 const char * dn = NULL;
368 i = (!dnli->reverse ? dnli->i++ : --dnli->i);
369 } while (i >= 0 && i < fi->dc && !dnli->active[i]);
371 if (i >= 0 && i < fi->dc)
382 * Save hard link in chain.
383 * @param fsm file state machine data
384 * @return Is chain only partially filled?
387 static int saveHardLink(/*@special@*/ /*@partial@*/ FSM_t fsm)
388 /*@uses fsm->links, fsm->ix, fsm->sb, fsm->goal, fsm->nsuffix @*/
389 /*@defines fsm->li @*/
390 /*@releases fsm->path @*/
391 /*@globals errno, fileSystem, internalState @*/
392 /*@modifies errno, fsm, fileSystem, internalState @*/
394 struct stat * st = &fsm->sb;
399 /* Find hard link set. */
401 for (fsm->li = fsm->links; fsm->li; fsm->li = fsm->li->next) {
402 if (fsm->li->sb.st_ino == st->st_ino && fsm->li->sb.st_dev == st->st_dev)
407 /* New hard link encountered, add new link to set. */
410 if (fsm->li == NULL) {
411 fsm->li = xcalloc(1, sizeof(*fsm->li));
412 fsm->li->next = NULL;
413 fsm->li->sb = *st; /* structure assignment */
414 fsm->li->nlink = st->st_nlink;
415 fsm->li->linkIndex = fsm->ix;
416 fsm->li->createdPath = -1;
418 fsm->li->filex = xcalloc(st->st_nlink, sizeof(fsm->li->filex[0]));
419 memset(fsm->li->filex, -1, (st->st_nlink * sizeof(fsm->li->filex[0])));
420 fsm->li->nsuffix = xcalloc(st->st_nlink, sizeof(*fsm->li->nsuffix));
422 if (fsm->goal == FSM_PKGBUILD)
423 fsm->li->linksLeft = st->st_nlink;
424 if (fsm->goal == FSM_PKGINSTALL)
425 fsm->li->linksLeft = 0;
428 fsm->li->next = fsm->links;
430 fsm->links = fsm->li;
435 if (fsm->goal == FSM_PKGBUILD) --fsm->li->linksLeft;
437 fsm->li->filex[fsm->li->linksLeft] = fsm->ix;
438 /*@-observertrans -dependenttrans@*/
439 fsm->li->nsuffix[fsm->li->linksLeft] = fsm->nsuffix;
440 /*@=observertrans =dependenttrans@*/
442 if (fsm->goal == FSM_PKGINSTALL) fsm->li->linksLeft++;
444 if (fsm->goal == FSM_PKGBUILD)
445 return (fsm->li->linksLeft > 0);
447 if (fsm->goal != FSM_PKGINSTALL)
450 if (!(st->st_size || fsm->li->linksLeft == st->st_nlink))
453 /* Here come the bits, time to choose a non-skipped file name. */
454 { rpmfi fi = fsmGetFi(fsm);
456 for (j = fsm->li->linksLeft - 1; j >= 0; j--) {
457 ix = fsm->li->filex[j];
458 if (ix < 0 || XFA_SKIPPING(fi->actions[ix]))
464 /* Are all links skipped or not encountered yet? */
466 return 1; /* XXX W2DO? */
468 /* Save the non-skipped file name and map index. */
469 fsm->li->linkIndex = j;
470 fsm->path = _free(fsm->path);
472 rc = fsmStage(fsm, FSM_MAP);
478 * Destroy set of hard links.
479 * @param li set of hard links
480 * @return NULL always
482 static /*@null@*/ void * freeHardLink(/*@only@*/ /*@null@*/ struct hardLink_s * li)
486 li->nsuffix = _free(li->nsuffix); /* XXX elements are shared */
487 li->filex = _free(li->filex);
494 FSM_t fsm = xcalloc(1, sizeof(*fsm));
498 FSM_t freeFSM(FSM_t fsm)
501 fsm->path = _free(fsm->path);
503 while ((fsm->li = fsm->links) != NULL) {
504 fsm->links = fsm->li->next;
505 fsm->li->next = NULL;
506 fsm->li = freeHardLink(fsm->li);
509 fsm->dnlx = _free(fsm->dnlx);
510 fsm->ldn = _free(fsm->ldn);
511 fsm->iter = mapFreeIterator(fsm->iter);
516 int fsmSetup(FSM_t fsm, fileStage goal,
517 const rpmts ts, const rpmfi fi, FD_t cfd,
518 unsigned int * archiveSize, const char ** failedFile)
525 fsm->cfd = fdLink(cfd, "persist (fsm)");
526 pos = fdGetCpioPos(fsm->cfd);
527 fdSetCpioPos(fsm->cfd, 0);
529 fsm->iter = mapInitIterator(ts, fi);
531 if (fsm->goal == FSM_PKGINSTALL || fsm->goal == FSM_PKGBUILD) {
534 ptr = rpmtsNotify(ts, fi->te,
535 RPMCALLBACK_INST_START, fi->archivePos, fi->archiveSize);
540 fsm->archiveSize = archiveSize;
541 if (fsm->archiveSize)
542 *fsm->archiveSize = 0;
543 fsm->failedFile = failedFile;
545 *fsm->failedFile = NULL;
549 memset(fsm->sufbuf, 0, sizeof(fsm->sufbuf));
550 if (fsm->goal == FSM_PKGINSTALL) {
551 if (ts && rpmtsGetTid(ts) > 0)
552 sprintf(fsm->sufbuf, ";%08x", (unsigned)rpmtsGetTid(ts));
556 rc = fsmStage(fsm, FSM_CREATE);
557 if (rc && !ec) ec = rc;
559 rc = fsmStage(fsm, fsm->goal);
560 if (rc && !ec) ec = rc;
563 if (fsm->archiveSize && ec == 0)
564 *fsm->archiveSize = (fdGetCpioPos(fsm->cfd) - pos);
570 int fsmTeardown(FSM_t fsm)
575 rc = fsmStage(fsm, FSM_DESTROY);
577 fsm->iter = mapFreeIterator(fsm->iter);
578 if (fsm->cfd != NULL) {
579 fsm->cfd = fdFree(fsm->cfd, "persist (fsm)");
582 fsm->failedFile = NULL;
586 int fsmMapPath(FSM_t fsm)
588 rpmfi fi = fsmGetFi(fsm); /* XXX const except for fstates */
595 fsm->action = FA_UNKNOWN;
599 if (fi && i >= 0 && i < fi->fc) {
602 fsm->astriplen = fi->astriplen;
603 fsm->action = (fi->actions ? fi->actions[i] : fi->action);
604 fsm->fflags = (fi->fflags ? fi->fflags[i] : fi->flags);
605 fsm->mapFlags = (fi->fmapflags ? fi->fmapflags[i] : fi->mapflags);
607 /* src rpms have simple base name in payload. */
608 fsm->dirName = fi->dnl[fi->dil[i]];
609 fsm->baseName = fi->bnl[i];
613 switch (fsm->action) {
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 (fi->fstates && rpmteType(fi->te) == TR_ADDED)
638 fi->fstates[i] = RPMFILE_STATE_WRONGCOLOR;
642 if (!(fsm->fflags & RPMFILE_GHOST)) /* XXX Don't if %ghost file. */
643 switch (rpmteType(fi->te)) {
645 fsm->osuffix = SUFFIX_RPMORIG;
646 /*@innerbreak@*/ break;
648 fsm->osuffix = SUFFIX_RPMSAVE;
649 /*@innerbreak@*/ break;
654 assert(rpmteType(fi->te) == TR_ADDED);
655 if (!(fsm->fflags & RPMFILE_GHOST)) /* XXX Don't if %ghost file. */
656 fsm->nsuffix = SUFFIX_RPMNEW;
660 assert(rpmteType(fi->te) == TR_ADDED);
661 if (!(fsm->fflags & RPMFILE_GHOST)) /* XXX Don't if %ghost file. */
662 fsm->osuffix = SUFFIX_RPMSAVE;
665 #if 0 /* XXX is this a genhdlist fix? */
666 assert(rpmteType(fi->te) == TR_REMOVED);
669 * XXX TODO: %ghost probably shouldn't be removed, but that changes
670 * legacy rpm behavior.
678 if ((fsm->mapFlags & CPIO_MAP_PATH) || fsm->nsuffix) {
679 const struct stat * st = &fsm->sb;
680 fsm->path = _free(fsm->path);
681 fsm->path = fsmFsPath(fsm, st, fsm->subdir,
682 (fsm->suffix ? fsm->suffix : fsm->nsuffix));
688 int fsmMapAttrs(FSM_t fsm)
690 struct stat * st = &fsm->sb;
691 rpmfi fi = fsmGetFi(fsm);
694 if (fi && i >= 0 && i < fi->fc) {
696 (S_ISDIR(st->st_mode) ? fi->dperms : fi->fperms);
698 (fi->fmodes ? fi->fmodes[i] : perms);
700 (fi->fuids ? fi->fuids[i] : fi->uid); /* XXX chmod u-s */
702 (fi->fgids ? fi->fgids[i] : fi->gid); /* XXX chmod g-s */
704 (fi->frdevs ? fi->frdevs[i] : 0);
706 (fi->fmtimes ? fi->fmtimes[i] : 0);
708 if (fsm->mapFlags & CPIO_MAP_MODE)
709 st->st_mode = (st->st_mode & S_IFMT) | (finalMode & ~S_IFMT);
710 if (fsm->mapFlags & CPIO_MAP_TYPE) {
711 st->st_mode = (st->st_mode & ~S_IFMT) | (finalMode & S_IFMT);
712 if ((S_ISCHR(st->st_mode) || S_ISBLK(st->st_mode))
713 && st->st_nlink == 0)
715 st->st_rdev = finalRdev;
716 st->st_mtime = finalMtime;
718 if (fsm->mapFlags & CPIO_MAP_UID)
719 st->st_uid = finalUid;
720 if (fsm->mapFlags & CPIO_MAP_GID)
721 st->st_gid = finalGid;
723 { rpmts ts = fsmGetTs(fsm);
725 if (ts != NULL && !(rpmtsFlags(ts) & RPMTRANS_FLAG_NOMD5)) {
726 fsm->fmd5sum = (fi->fmd5s ? fi->fmd5s[i] : NULL);
727 fsm->md5sum = (fi->md5s ? (fi->md5s + (16 * i)) : NULL);
739 * Create file from payload stream.
740 * @param fsm file state machine data
741 * @return 0 on success
743 static int expandRegular(/*@special@*/ FSM_t fsm)
745 /*@globals errno, fileSystem, internalState @*/
746 /*@modifies fsm, errno, fileSystem, internalState @*/
748 const struct stat * st = &fsm->sb;
749 int left = st->st_size;
752 rc = fsmStage(fsm, FSM_WOPEN);
756 if (st->st_size > 0 && (fsm->fmd5sum || fsm->md5sum))
757 fdInitDigest(fsm->wfd, PGPHASHALGO_MD5, 0);
761 fsm->wrlen = (left > fsm->wrsize ? fsm->wrsize : left);
762 rc = fsmStage(fsm, FSM_DREAD);
766 rc = fsmStage(fsm, FSM_WRITE);
772 /* don't call this with fileSize == fileComplete */
774 (void) fsmStage(fsm, FSM_NOTIFY);
777 if (st->st_size > 0 && (fsm->fmd5sum || fsm->md5sum)) {
778 void * md5sum = NULL;
779 int asAscii = (fsm->md5sum == NULL ? 1 : 0);
781 (void) Fflush(fsm->wfd);
782 fdFiniDigest(fsm->wfd, PGPHASHALGO_MD5, &md5sum, NULL, asAscii);
784 if (md5sum == NULL) {
785 rc = CPIOERR_MD5SUM_MISMATCH;
789 if (fsm->md5sum != NULL) {
790 if (memcmp(md5sum, fsm->md5sum, 16))
791 rc = CPIOERR_MD5SUM_MISMATCH;
793 if (strcmp(md5sum, fsm->fmd5sum))
794 rc = CPIOERR_MD5SUM_MISMATCH;
796 md5sum = _free(md5sum);
800 (void) fsmStage(fsm, FSM_WCLOSE);
805 * Write next item to payload stream.
806 * @param fsm file state machine data
807 * @param writeData should data be written?
808 * @return 0 on success
810 static int writeFile(/*@special@*/ FSM_t fsm, int writeData)
811 /*@uses fsm->path, fsm->opath, fsm->sb, fsm->osb, fsm->cfd @*/
812 /*@globals errno, fileSystem, internalState @*/
813 /*@modifies fsm, errno, fileSystem, internalState @*/
815 const char * path = fsm->path;
816 const char * opath = fsm->opath;
817 struct stat * st = &fsm->sb;
818 struct stat * ost = &fsm->osb;
819 char * symbuf = NULL;
824 st->st_size = (writeData ? ost->st_size : 0);
827 if (S_ISDIR(st->st_mode)) {
829 } else if (S_ISLNK(st->st_mode)) {
831 * While linux puts the size of a symlink in the st_size field,
832 * I don't think that's a specified standard.
834 /* XXX NUL terminated result in fsm->rdbuf, len in fsm->rdnb. */
835 rc = fsmStage(fsm, FSM_READLINK);
837 st->st_size = fsm->rdnb;
838 symbuf = alloca_strdup(fsm->rdbuf); /* XXX save readlink return. */
842 if (fsm->mapFlags & CPIO_MAP_ABSOLUTE) {
843 /*@-compdef@*/ /* FIX: dirName/baseName annotations ? */
845 int nb = strlen(fsm->dirName) + strlen(fsm->baseName) + sizeof(".");
846 char * t = alloca(nb);
849 if (fsm->mapFlags & CPIO_MAP_ADDDOT)
851 t = stpcpy( stpcpy(t, fsm->dirName), fsm->baseName);
854 } else if (fsm->mapFlags & CPIO_MAP_PATH) {
855 rpmfi fi = fsmGetFi(fsm);
857 (fi->apath ? fi->apath[fsm->ix] + fi->striplen : fi->bnl[fsm->ix]);
860 rc = fsmStage(fsm, FSM_HWRITE);
864 if (writeData && S_ISREG(st->st_mode)) {
867 void * mapped = (void *)-1;
871 rc = fsmStage(fsm, FSM_ROPEN);
874 /* XXX unbuffered mmap generates *lots* of fdio debugging */
877 mapped = mmap(NULL, st->st_size, PROT_READ, MAP_SHARED, Fileno(fsm->rfd), 0);
878 if (mapped != (void *)-1) {
880 fsm->rdbuf = (char *) mapped;
881 fsm->rdlen = nmapped = st->st_size;
882 #if defined(MADV_DONTNEED)
883 xx = madvise(mapped, nmapped, MADV_DONTNEED);
892 if (mapped != (void *)-1) {
897 fsm->rdlen = (left > fsm->rdsize ? fsm->rdsize : left),
898 rc = fsmStage(fsm, FSM_READ);
902 /* XXX DWRITE uses rdnb for I/O length. */
903 rc = fsmStage(fsm, FSM_DWRITE);
910 if (mapped != (void *)-1) {
911 xx = msync(mapped, nmapped, MS_ASYNC);
912 #if defined(MADV_DONTNEED)
913 xx = madvise(mapped, nmapped, MADV_DONTNEED);
915 /*@-noeffect@*/ xx = munmap(mapped, nmapped) /*@=noeffect@*/;
920 } else if (writeData && S_ISLNK(st->st_mode)) {
921 /* XXX DWRITE uses rdnb for I/O length. */
923 strcpy(fsm->rdbuf, symbuf); /* XXX restore readlink buffer. */
925 fsm->rdnb = strlen(symbuf);
926 rc = fsmStage(fsm, FSM_DWRITE);
930 rc = fsmStage(fsm, FSM_PAD);
936 if (fsm->rfd != NULL)
937 (void) fsmStage(fsm, FSM_RCLOSE);
938 /*@-dependenttrans@*/
941 /*@=dependenttrans@*/
946 * Write set of linked files to payload stream.
947 * @param fsm file state machine data
948 * @return 0 on success
950 static int writeLinkedFile(/*@special@*/ FSM_t fsm)
951 /*@uses fsm->path, fsm->nsuffix, fsm->ix, fsm->li, fsm->failedFile @*/
952 /*@globals errno, fileSystem, internalState @*/
953 /*@modifies fsm, errno, fileSystem, internalState @*/
955 const char * path = fsm->path;
956 const char * nsuffix = fsm->nsuffix;
957 int iterIndex = fsm->ix;
967 for (i = fsm->li->nlink - 1; i >= 0; i--) {
969 if (fsm->li->filex[i] < 0) continue;
971 fsm->ix = fsm->li->filex[i];
972 rc = fsmStage(fsm, FSM_MAP);
974 /* Write data after last link. */
975 rc = writeFile(fsm, (i == 0));
976 if (fsm->failedFile && rc != 0 && *fsm->failedFile == NULL) {
978 *fsm->failedFile = xstrdup(fsm->path);
981 fsm->path = _free(fsm->path);
982 fsm->li->filex[i] = -1;
987 fsm->nsuffix = nsuffix;
993 * Create pending hard links to existing file.
994 * @param fsm file state machine data
995 * @return 0 on success
998 static int fsmMakeLinks(/*@special@*/ FSM_t fsm)
999 /*@uses fsm->path, fsm->opath, fsm->nsuffix, fsm->ix, fsm->li @*/
1000 /*@globals errno, fileSystem, internalState @*/
1001 /*@modifies fsm, errno, fileSystem, internalState @*/
1003 const char * path = fsm->path;
1004 const char * opath = fsm->opath;
1005 const char * nsuffix = fsm->nsuffix;
1006 int iterIndex = fsm->ix;
1013 fsm->nsuffix = NULL;
1016 fsm->ix = fsm->li->filex[fsm->li->createdPath];
1017 rc = fsmStage(fsm, FSM_MAP);
1018 fsm->opath = fsm->path;
1021 for (i = 0; i < fsm->li->nlink; i++) {
1022 if (fsm->li->filex[i] < 0) continue;
1023 if (fsm->li->createdPath == i) continue;
1025 fsm->ix = fsm->li->filex[i];
1026 fsm->path = _free(fsm->path);
1027 rc = fsmStage(fsm, FSM_MAP);
1028 if (XFA_SKIPPING(fsm->action)) continue;
1030 rc = fsmStage(fsm, FSM_VERIFY);
1032 if (rc != CPIOERR_LSTAT_FAILED) break;
1034 /* XXX link(fsm->opath, fsm->path) */
1035 rc = fsmStage(fsm, FSM_LINK);
1036 if (fsm->failedFile && rc != 0 && *fsm->failedFile == NULL) {
1039 *fsm->failedFile = xstrdup(fsm->path);
1043 fsm->li->linksLeft--;
1046 fsm->path = _free(fsm->path);
1047 fsm->opath = _free(fsm->opath);
1049 fsm->ix = iterIndex;
1050 fsm->nsuffix = nsuffix;
1057 /** \ingroup payload
1058 * Commit hard linked file set atomically.
1059 * @param fsm file state machine data
1060 * @return 0 on success
1062 static int fsmCommitLinks(/*@special@*/ FSM_t fsm)
1063 /*@uses fsm->path, fsm->nsuffix, fsm->ix, fsm->sb,
1064 fsm->li, fsm->links @*/
1065 /*@globals errno, fileSystem, internalState @*/
1066 /*@modifies fsm, errno, fileSystem, internalState @*/
1068 const char * path = fsm->path;
1069 const char * nsuffix = fsm->nsuffix;
1070 int iterIndex = fsm->ix;
1071 struct stat * st = &fsm->sb;
1076 fsm->nsuffix = NULL;
1080 for (fsm->li = fsm->links; fsm->li; fsm->li = fsm->li->next) {
1081 if (fsm->li->sb.st_ino == st->st_ino && fsm->li->sb.st_dev == st->st_dev)
1087 for (i = 0; i < fsm->li->nlink; i++) {
1088 if (fsm->li->filex[i] < 0) continue;
1089 fsm->ix = fsm->li->filex[i];
1090 rc = fsmStage(fsm, FSM_MAP);
1091 if (!XFA_SKIPPING(fsm->action))
1092 rc = fsmStage(fsm, FSM_COMMIT);
1093 fsm->path = _free(fsm->path);
1094 fsm->li->filex[i] = -1;
1098 fsm->ix = iterIndex;
1099 fsm->nsuffix = nsuffix;
1105 * Remove (if created) directories not explicitly included in package.
1106 * @param fsm file state machine data
1107 * @return 0 on success
1109 static int fsmRmdirs(/*@special@*/ FSM_t fsm)
1110 /*@uses fsm->path, fsm->dnlx, fsm->ldn, fsm->rdbuf, fsm->iter @*/
1111 /*@globals errno, fileSystem, internalState @*/
1112 /*@modifies fsm, errno, fileSystem, internalState @*/
1114 const char * path = fsm->path;
1115 void * dnli = dnlInitIterator(fsm, 1);
1116 char * dn = fsm->rdbuf;
1117 int dc = dnlCount(dnli);
1123 /*@-observertrans -dependenttrans@*/
1124 if (fsm->ldn != NULL && fsm->dnlx != NULL)
1125 while ((fsm->path = dnlNextIterator(dnli)) != NULL) {
1126 int dnlen = strlen(fsm->path);
1129 dc = dnlIndex(dnli);
1130 if (fsm->dnlx[dc] < 1 || fsm->dnlx[dc] >= dnlen)
1133 /* Copy to avoid const on fsm->path. */
1134 te = stpcpy(dn, fsm->path) - 1;
1137 /* Remove generated directories. */
1138 /*@-usereleased@*/ /* LCL: te used after release? */
1142 rc = fsmStage(fsm, FSM_RMDIR);
1146 /*@innerbreak@*/ break;
1148 } while ((te - fsm->path) > fsm->dnlx[dc]);
1152 dnli = dnlFreeIterator(dnli);
1153 /*@=observertrans =dependenttrans@*/
1160 * Create (if necessary) directories not explicitly included in package.
1161 * @param fsm file state machine data
1162 * @return 0 on success
1164 static int fsmMkdirs(/*@special@*/ FSM_t fsm)
1165 /*@uses fsm->path, fsm->sb, fsm->osb, fsm->rdbuf, fsm->iter,
1166 fsm->ldn, fsm->ldnlen, fsm->ldnalloc @*/
1167 /*@defines fsm->dnlx, fsm->ldn @*/
1168 /*@globals errno, fileSystem, internalState @*/
1169 /*@modifies fsm, errno, fileSystem, internalState @*/
1171 struct stat * st = &fsm->sb;
1172 struct stat * ost = &fsm->osb;
1173 const char * path = fsm->path;
1174 mode_t st_mode = st->st_mode;
1175 void * dnli = dnlInitIterator(fsm, 0);
1176 char * dn = fsm->rdbuf;
1177 int dc = dnlCount(dnli);
1185 fsm->dnlx = (dc ? xcalloc(dc, sizeof(*fsm->dnlx)) : NULL);
1186 /*@-observertrans -dependenttrans@*/
1187 if (fsm->dnlx != NULL)
1188 while ((fsm->path = dnlNextIterator(dnli)) != NULL) {
1189 int dnlen = strlen(fsm->path);
1192 dc = dnlIndex(dnli);
1193 if (dc < 0) continue;
1194 fsm->dnlx[dc] = dnlen;
1198 /*@-compdef -nullpass@*/ /* FIX: fsm->ldn not defined ??? */
1199 if (dnlen <= fsm->ldnlen && !strcmp(fsm->path, fsm->ldn))
1201 /*@=compdef =nullpass@*/
1203 /* Copy to avoid const on fsm->path. */
1204 (void) stpcpy(dn, fsm->path);
1207 /* Assume '/' directory exists, "mkdir -p" for others if non-existent */
1208 for (i = 1, te = dn + 1; *te != '\0'; te++, i++) {
1210 /*@innercontinue@*/ continue;
1214 /* Already validated? */
1215 /*@-usedef -compdef -nullpass -nullderef@*/
1216 if (i < fsm->ldnlen &&
1217 (fsm->ldn[i] == '/' || fsm->ldn[i] == '\0') &&
1218 !strncmp(fsm->path, fsm->ldn, i))
1221 /* Move pre-existing path marker forward. */
1222 fsm->dnlx[dc] = (te - dn);
1223 /*@innercontinue@*/ continue;
1225 /*@=usedef =compdef =nullpass =nullderef@*/
1227 /* Validate next component of path. */
1228 rc = fsmStage(fsm, FSM_LSTAT);
1231 /* Directory already exists? */
1232 if (rc == 0 && S_ISDIR(ost->st_mode)) {
1233 /* Move pre-existing path marker forward. */
1234 fsm->dnlx[dc] = (te - dn);
1235 } else if (rc == CPIOERR_LSTAT_FAILED) {
1236 rpmfi fi = fsmGetFi(fsm);
1238 st->st_mode = S_IFDIR | (fi->dperms & 07777);
1239 rc = fsmStage(fsm, FSM_MKDIR);
1241 rpmMessage(RPMMESS_DEBUG,
1242 _("%s directory created with perms %04o.\n"),
1243 fsm->path, (unsigned)(st->st_mode & 07777));
1247 /*@innerbreak@*/ break;
1251 /* Save last validated path. */
1252 /*@-compdef@*/ /* FIX: ldn/path annotations ? */
1253 if (fsm->ldnalloc < (dnlen + 1)) {
1254 fsm->ldnalloc = dnlen + 100;
1255 fsm->ldn = xrealloc(fsm->ldn, fsm->ldnalloc);
1257 if (fsm->ldn != NULL) { /* XXX can't happen */
1258 strcpy(fsm->ldn, fsm->path);
1259 fsm->ldnlen = dnlen;
1264 dnli = dnlFreeIterator(dnli);
1265 /*@=observertrans =dependenttrans@*/
1268 st->st_mode = st_mode; /* XXX restore st->st_mode */
1269 /*@-compdef@*/ /* FIX: ldn/path annotations ? */
1276 * Check for file on disk.
1277 * @param fsm file state machine data
1278 * @return 0 on success
1280 static int fsmStat(FSM_t fsm)
1281 /*@globals errno, fileSystem, internalState @*/
1282 /*@modifies fsm, errno, fileSystem, internalState @*/
1284 int saveerrno = errno;
1287 if (fsm->path != NULL) {
1288 int saveernno = errno;
1289 rc = fsmStage(fsm, (!(fsm->mapFlags & CPIO_FOLLOW_SYMLINKS)
1290 ? FSM_LSTAT : FSM_STAT));
1291 if (rc == CPIOERR_LSTAT_FAILED && errno == ENOENT) {
1295 } else if (rc == 0) {
1299 /* Skip %ghost files on build. */
1306 #define IS_DEV_LOG(_x) \
1307 ((_x) != NULL && strlen(_x) >= (sizeof("/dev/log")-1) && \
1308 !strncmp((_x), "/dev/log", sizeof("/dev/log")-1) && \
1309 ((_x)[sizeof("/dev/log")-1] == '\0' || \
1310 (_x)[sizeof("/dev/log")-1] == ';'))
1314 int fsmStage(FSM_t fsm, fileStage stage)
1317 fileStage prevStage = fsm->stage;
1318 const char * const prev = fileStageString(prevStage);
1320 static int modulo = 4;
1321 const char * const cur = fileStageString(stage);
1322 struct stat * st = &fsm->sb;
1323 struct stat * ost = &fsm->osb;
1324 int saveerrno = errno;
1329 #define _fafilter(_a) \
1330 (!((_a) == FA_CREATE || (_a) == FA_ERASE || (_a) == FA_COPYIN || (_a) == FA_COPYOUT) \
1331 ? fileActionString(_a) : "")
1333 if (stage & FSM_DEAD) {
1335 } else if (stage & FSM_INTERNAL) {
1336 if (_fsm_debug && !(stage & FSM_SYSCALL))
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 : ""),
1342 _fafilter(fsm->action));
1345 if (_fsm_debug || !(stage & FSM_VERBOSE))
1346 rpmMessage(RPMMESS_DEBUG, "%-8s %06o%3d (%4d,%4d)%10d %s %s\n",
1348 (unsigned)st->st_mode, (int)st->st_nlink,
1349 (int)st->st_uid, (int)st->st_gid, (int)st->st_size,
1350 (fsm->path ? fsm->path + fsm->astriplen : ""),
1351 _fafilter(fsm->action));
1359 case FSM_PKGINSTALL:
1361 /* Clean fsm, free'ing memory. Read next archive header. */
1362 rc = fsmStage(fsm, FSM_INIT);
1364 /* Exit on end-of-payload. */
1365 if (rc == CPIOERR_HDR_TRAILER) {
1367 /*@loopbreak@*/ break;
1370 /* Exit on error. */
1373 (void) fsmStage(fsm, FSM_UNDO);
1374 /*@loopbreak@*/ break;
1377 /* Extract file from archive. */
1378 rc = fsmStage(fsm, FSM_PROCESS);
1380 (void) fsmStage(fsm, FSM_UNDO);
1381 /*@loopbreak@*/ break;
1384 /* Notify on success. */
1385 (void) fsmStage(fsm, FSM_NOTIFY);
1387 rc = fsmStage(fsm, FSM_FINI);
1389 /*@loopbreak@*/ break;
1396 /* Clean fsm, free'ing memory. */
1397 rc = fsmStage(fsm, FSM_INIT);
1399 /* Exit on end-of-payload. */
1400 if (rc == CPIOERR_HDR_TRAILER) {
1402 /*@loopbreak@*/ break;
1405 /* Rename/erase next item. */
1406 if (fsmStage(fsm, FSM_FINI))
1407 /*@loopbreak@*/ break;
1413 rc = fsmStage(fsm, FSM_INIT);
1415 /* Exit on end-of-payload. */
1416 if (rc == CPIOERR_HDR_TRAILER) {
1418 /*@loopbreak@*/ break;
1421 /* Exit on error. */
1424 (void) fsmStage(fsm, FSM_UNDO);
1425 /*@loopbreak@*/ break;
1428 /* Copy file into archive. */
1429 rc = fsmStage(fsm, FSM_PROCESS);
1431 (void) fsmStage(fsm, FSM_UNDO);
1432 /*@loopbreak@*/ break;
1435 /* Notify on success. */
1436 (void) fsmStage(fsm, FSM_NOTIFY);
1438 if (fsmStage(fsm, FSM_FINI))
1439 /*@loopbreak@*/ break;
1442 /* Flush partial sets of hard linked files. */
1443 if (!(fsm->mapFlags & CPIO_ALL_HARDLINKS)) {
1445 while ((fsm->li = fsm->links) != NULL) {
1446 fsm->links = fsm->li->next;
1447 fsm->li->next = NULL;
1449 /* Re-calculate link count for archive header. */
1450 for (j = -1, nlink = 0, i = 0; i < fsm->li->nlink; i++) {
1451 if (fsm->li->filex[i] < 0)
1452 /*@innercontinue@*/ continue;
1456 /* XXX force the contents out as well. */
1459 fsm->li->filex[0] = fsm->li->filex[j];
1460 fsm->li->filex[j] = -1;
1463 fsm->li->sb.st_nlink = nlink;
1465 fsm->sb = fsm->li->sb; /* structure assignment */
1466 fsm->osb = fsm->sb; /* structure assignment */
1468 if (!rc) rc = writeLinkedFile(fsm);
1470 fsm->li = freeHardLink(fsm->li);
1475 rc = fsmStage(fsm, FSM_TRAILER);
1479 { rpmts ts = fsmGetTs(fsm);
1480 #define _tsmask (RPMTRANS_FLAG_PKGCOMMIT | RPMTRANS_FLAG_COMMIT)
1481 fsm->commit = ((ts && (rpmtsFlags(ts) & _tsmask) &&
1482 fsm->goal != FSM_PKGCOMMIT) ? 0 : 1);
1485 fsm->path = _free(fsm->path);
1486 fsm->opath = _free(fsm->opath);
1487 fsm->dnlx = _free(fsm->dnlx);
1489 fsm->ldn = _free(fsm->ldn);
1490 fsm->ldnalloc = fsm->ldnlen = 0;
1492 fsm->rdsize = fsm->wrsize = 0;
1493 fsm->rdbuf = fsm->rdb = _free(fsm->rdb);
1494 fsm->wrbuf = fsm->wrb = _free(fsm->wrb);
1495 if (fsm->goal == FSM_PKGINSTALL || fsm->goal == FSM_PKGBUILD) {
1496 fsm->rdsize = 8 * BUFSIZ;
1497 fsm->rdbuf = fsm->rdb = xmalloc(fsm->rdsize);
1498 fsm->wrsize = 8 * BUFSIZ;
1499 fsm->wrbuf = fsm->wrb = xmalloc(fsm->wrsize);
1502 fsm->mkdirsdone = 0;
1506 errno = 0; /* XXX get rid of EBADF */
1508 /* Detect and create directories not explicitly in package. */
1509 if (fsm->goal == FSM_PKGINSTALL) {
1510 rc = fsmStage(fsm, FSM_MKDIRS);
1511 if (!rc) fsm->mkdirsdone = 1;
1516 fsm->path = _free(fsm->path);
1518 fsm->diskchecked = fsm->exists = 0;
1520 fsm->suffix = (fsm->sufbuf[0] != '\0' ? fsm->sufbuf : NULL);
1521 fsm->action = FA_UNKNOWN;
1522 fsm->osuffix = NULL;
1523 fsm->nsuffix = NULL;
1525 if (fsm->goal == FSM_PKGINSTALL) {
1526 /* Read next header from payload, checking for end-of-payload. */
1527 rc = fsmStage(fsm, FSM_NEXT);
1531 /* Identify mapping index. */
1532 fsm->ix = ((fsm->goal == FSM_PKGINSTALL)
1533 ? mapFind(fsm->iter, fsm->path) : mapNextIterator(fsm->iter));
1535 /* Detect end-of-loop and/or mapping error. */
1537 if (fsm->goal == FSM_PKGINSTALL) {
1539 rpmMessage(RPMMESS_WARNING,
1540 _("archive file %s was not found in header file list\n"),
1544 if (fsm->failedFile && *fsm->failedFile == NULL)
1545 *fsm->failedFile = xstrdup(fsm->path);
1547 rc = CPIOERR_UNMAPPED_FILE;
1549 rc = CPIOERR_HDR_TRAILER;
1554 /* On non-install, mode must be known so that dirs don't get suffix. */
1555 if (fsm->goal != FSM_PKGINSTALL) {
1556 rpmfi fi = fsmGetFi(fsm);
1557 st->st_mode = fi->fmodes[fsm->ix];
1560 /* Generate file path. */
1561 rc = fsmStage(fsm, FSM_MAP);
1564 /* Perform lstat/stat for disk file. */
1568 if (fsm->path != NULL &&
1569 !(fsm->goal == FSM_PKGINSTALL && S_ISREG(st->st_mode)))
1571 rc = fsmStage(fsm, (!(fsm->mapFlags & CPIO_FOLLOW_SYMLINKS)
1572 ? FSM_LSTAT : FSM_STAT));
1573 if (rc == CPIOERR_LSTAT_FAILED && errno == ENOENT) {
1577 } else if (rc == 0) {
1581 /* Skip %ghost files on build. */
1585 fsm->diskchecked = 1;
1588 /* On non-install, the disk file stat is what's remapped. */
1590 if (fsm->goal != FSM_PKGINSTALL)
1591 *st = *ost; /* structure assignment */
1594 /* Remap file perms, owner, and group. */
1595 rc = fsmMapAttrs(fsm);
1598 fsm->postpone = XFA_SKIPPING(fsm->action);
1599 if (fsm->goal == FSM_PKGINSTALL || fsm->goal == FSM_PKGBUILD) {
1600 /*@-evalorder@*/ /* FIX: saveHardLink can modify fsm */
1601 if (!S_ISDIR(st->st_mode) && st->st_nlink > 1)
1602 fsm->postpone = saveHardLink(fsm);
1609 rc = fsmMapPath(fsm);
1612 rc = fsmMkdirs(fsm);
1616 rc = fsmRmdirs(fsm);
1619 if (fsm->postpone) {
1620 if (fsm->goal == FSM_PKGINSTALL)
1621 rc = fsmStage(fsm, FSM_EAT);
1625 if (fsm->goal == FSM_PKGBUILD) {
1626 if (fsm->fflags & RPMFILE_GHOST) /* XXX Don't if %ghost file. */
1628 if (!S_ISDIR(st->st_mode) && st->st_nlink > 1) {
1629 struct hardLink_s * li, * prev;
1631 if (!(fsm->mapFlags & CPIO_ALL_HARDLINKS)) break;
1632 rc = writeLinkedFile(fsm);
1633 if (rc) break; /* W2DO? */
1635 for (li = fsm->links, prev = NULL; li; prev = li, li = li->next)
1637 /*@loopbreak@*/ break;
1640 fsm->links = fsm->li->next;
1642 prev->next = fsm->li->next;
1643 fsm->li->next = NULL;
1644 fsm->li = freeHardLink(fsm->li);
1646 rc = writeFile(fsm, 1);
1651 if (fsm->goal != FSM_PKGINSTALL)
1654 if (S_ISREG(st->st_mode)) {
1655 const char * path = fsm->path;
1657 fsm->path = fsmFsPath(fsm, st, NULL, NULL);
1658 rc = fsmStage(fsm, FSM_VERIFY);
1660 if (rc == 0 && fsm->osuffix) {
1661 const char * opath = fsm->opath;
1662 fsm->opath = fsm->path;
1663 fsm->path = fsmFsPath(fsm, st, NULL, fsm->osuffix);
1664 rc = fsmStage(fsm, FSM_RENAME);
1666 rpmMessage(RPMMESS_WARNING,
1667 _("%s saved as %s\n"), fsm->opath, fsm->path);
1668 fsm->path = _free(fsm->path);
1672 /*@-dependenttrans@*/
1674 /*@=dependenttrans@*/
1675 if (rc != CPIOERR_LSTAT_FAILED) return rc;
1676 rc = expandRegular(fsm);
1677 } else if (S_ISDIR(st->st_mode)) {
1678 mode_t st_mode = st->st_mode;
1679 rc = fsmStage(fsm, FSM_VERIFY);
1680 if (rc == CPIOERR_LSTAT_FAILED) {
1681 st->st_mode &= ~07777; /* XXX abuse st->st_mode */
1682 st->st_mode |= 00700;
1683 rc = fsmStage(fsm, FSM_MKDIR);
1684 st->st_mode = st_mode; /* XXX restore st->st_mode */
1686 } else if (S_ISLNK(st->st_mode)) {
1687 const char * opath = fsm->opath;
1689 if ((st->st_size + 1) > fsm->rdsize) {
1690 rc = CPIOERR_HDR_SIZE;
1694 fsm->wrlen = st->st_size;
1695 rc = fsmStage(fsm, FSM_DREAD);
1696 if (!rc && fsm->rdnb != fsm->wrlen)
1697 rc = CPIOERR_READ_FAILED;
1701 fsm->wrbuf[st->st_size] = '\0';
1703 /* XXX symlink(fsm->opath, fsm->path) */
1704 /*@-dependenttrans@*/
1705 fsm->opath = fsm->wrbuf;
1706 /*@=dependenttrans@*/
1707 rc = fsmStage(fsm, FSM_VERIFY);
1708 if (rc == CPIOERR_LSTAT_FAILED)
1709 rc = fsmStage(fsm, FSM_SYMLINK);
1710 fsm->opath = opath; /* XXX restore fsm->path */
1711 } else if (S_ISFIFO(st->st_mode)) {
1712 mode_t st_mode = st->st_mode;
1713 /* This mimics cpio S_ISSOCK() behavior but probably isnt' right */
1714 rc = fsmStage(fsm, FSM_VERIFY);
1715 if (rc == CPIOERR_LSTAT_FAILED) {
1716 st->st_mode = 0000; /* XXX abuse st->st_mode */
1717 rc = fsmStage(fsm, FSM_MKFIFO);
1718 st->st_mode = st_mode; /* XXX restore st->st_mode */
1720 } else if (S_ISCHR(st->st_mode) ||
1721 S_ISBLK(st->st_mode) ||
1722 /*@-unrecog@*/ S_ISSOCK(st->st_mode) /*@=unrecog@*/)
1724 rc = fsmStage(fsm, FSM_VERIFY);
1725 if (rc == CPIOERR_LSTAT_FAILED)
1726 rc = fsmStage(fsm, FSM_MKNOD);
1728 /* XXX Special case /dev/log, which shouldn't be packaged anyways */
1729 if (!IS_DEV_LOG(fsm->path))
1730 rc = CPIOERR_UNKNOWN_FILETYPE;
1732 if (!S_ISDIR(st->st_mode) && st->st_nlink > 1) {
1733 fsm->li->createdPath = fsm->li->linkIndex;
1734 rc = fsmMakeLinks(fsm);
1740 rc = fsmMakeLinks(fsm);
1742 case FSM_NOTIFY: /* XXX move from fsm to psm -> tsm */
1743 if (fsm->goal == FSM_PKGINSTALL || fsm->goal == FSM_PKGBUILD) {
1744 rpmts ts = fsmGetTs(fsm);
1745 rpmfi fi = fsmGetFi(fsm);
1747 unsigned int archivePos = fdGetCpioPos(fsm->cfd);
1748 if (archivePos > fi->archivePos) {
1749 fi->archivePos = archivePos;
1750 ptr = rpmtsNotify(ts, fi->te, RPMCALLBACK_INST_PROGRESS,
1751 fi->archivePos, fi->archiveSize);
1758 if (fsm->goal == FSM_PKGINSTALL) {
1759 (void) fsmStage(fsm,
1760 (S_ISDIR(st->st_mode) ? FSM_RMDIR : FSM_UNLINK));
1762 #ifdef NOTYET /* XXX remove only dirs just created, not all. */
1764 (void) fsmStage(fsm, FSM_RMDIRS);
1769 if (fsm->failedFile && *fsm->failedFile == NULL)
1770 *fsm->failedFile = xstrdup(fsm->path);
1774 if (!fsm->postpone && fsm->commit) {
1775 if (fsm->goal == FSM_PKGINSTALL)
1776 rc = ((!S_ISDIR(st->st_mode) && st->st_nlink > 1)
1777 ? fsmCommitLinks(fsm) : fsmStage(fsm, FSM_COMMIT));
1778 if (fsm->goal == FSM_PKGCOMMIT)
1779 rc = fsmStage(fsm, FSM_COMMIT);
1780 if (fsm->goal == FSM_PKGERASE)
1781 rc = fsmStage(fsm, FSM_COMMIT);
1783 fsm->path = _free(fsm->path);
1784 fsm->opath = _free(fsm->opath);
1786 memset(st, 0, sizeof(*st));
1787 memset(ost, 0, sizeof(*ost));
1791 /* Rename pre-existing modified or unmanaged file. */
1792 if (fsm->osuffix && fsm->diskchecked &&
1793 (fsm->exists || (fsm->goal == FSM_PKGINSTALL && S_ISREG(st->st_mode))))
1795 const char * opath = fsm->opath;
1796 const char * path = fsm->path;
1797 fsm->opath = fsmFsPath(fsm, st, NULL, NULL);
1798 fsm->path = fsmFsPath(fsm, st, NULL, fsm->osuffix);
1799 rc = fsmStage(fsm, FSM_RENAME);
1801 rpmMessage(RPMMESS_WARNING, _("%s saved as %s\n"),
1802 fsm->opath, fsm->path);
1804 fsm->path = _free(fsm->path);
1806 fsm->opath = _free(fsm->opath);
1810 /* Remove erased files. */
1811 if (fsm->goal == FSM_PKGERASE) {
1812 if (fsm->action == FA_ERASE) {
1813 rpmfi fi = fsmGetFi(fsm);
1814 if (S_ISDIR(st->st_mode)) {
1815 rc = fsmStage(fsm, FSM_RMDIR);
1818 case ENOENT: /* XXX rmdir("/") linux 2.2.x kernel hack */
1820 /* XXX make sure that build side permits %missingok on directories. */
1821 if (fsm->fflags & RPMFILE_MISSINGOK)
1822 /*@innerbreak@*/ break;
1824 /* XXX common error message. */
1826 (strict_erasures ? RPMERR_RMDIR : RPMDEBUG_RMDIR),
1827 _("%s rmdir of %s failed: Directory not empty\n"),
1828 rpmfiTypeString(fi), fsm->path);
1829 /*@innerbreak@*/ break;
1832 (strict_erasures ? RPMERR_RMDIR : RPMDEBUG_RMDIR),
1833 _("%s rmdir of %s failed: %s\n"),
1834 rpmfiTypeString(fi), fsm->path, strerror(errno));
1835 /*@innerbreak@*/ break;
1838 rc = fsmStage(fsm, FSM_UNLINK);
1840 if (!(errno == ENOENT && (fsm->fflags & RPMFILE_MISSINGOK)))
1842 (strict_erasures ? RPMERR_UNLINK : RPMDEBUG_UNLINK),
1843 _("%s unlink of %s failed: %s\n"),
1844 rpmfiTypeString(fi), fsm->path, strerror(errno));
1847 /* XXX Failure to remove is not (yet) cause for failure. */
1848 if (!strict_erasures) rc = 0;
1852 /* XXX Special case /dev/log, which shouldn't be packaged anyways */
1853 if (!S_ISSOCK(st->st_mode) && !IS_DEV_LOG(fsm->path)) {
1854 /* Rename temporary to final file name. */
1855 if (!S_ISDIR(st->st_mode) &&
1856 (fsm->subdir || fsm->suffix || fsm->nsuffix))
1858 fsm->opath = fsm->path;
1859 fsm->path = fsmFsPath(fsm, st, NULL, fsm->nsuffix);
1860 rc = fsmStage(fsm, FSM_RENAME);
1861 if (!rc && fsm->nsuffix) {
1862 const char * opath = fsmFsPath(fsm, st, NULL, NULL);
1863 rpmMessage(RPMMESS_WARNING, _("%s created as %s\n"),
1864 (opath ? opath : ""), fsm->path);
1865 opath = _free(opath);
1867 fsm->opath = _free(fsm->opath);
1869 if (S_ISLNK(st->st_mode)) {
1870 if (!rc && !getuid())
1871 rc = fsmStage(fsm, FSM_LCHOWN);
1873 if (!rc && !getuid())
1874 rc = fsmStage(fsm, FSM_CHOWN);
1876 rc = fsmStage(fsm, FSM_CHMOD);
1878 time_t mtime = st->st_mtime;
1879 rpmfi fi = fsmGetFi(fsm);
1881 st->st_mtime = fi->fmtimes[fsm->ix];
1882 rc = fsmStage(fsm, FSM_UTIME);
1883 st->st_mtime = mtime;
1888 /* Notify on success. */
1889 if (!rc) rc = fsmStage(fsm, FSM_NOTIFY);
1890 else if (fsm->failedFile && *fsm->failedFile == NULL) {
1892 *fsm->failedFile = fsm->path;
1898 fsm->path = _free(fsm->path);
1900 /* Check for hard links missing from payload. */
1901 while ((fsm->li = fsm->links) != NULL) {
1902 fsm->links = fsm->li->next;
1903 fsm->li->next = NULL;
1904 if (fsm->goal == FSM_PKGINSTALL &&
1905 fsm->commit && fsm->li->linksLeft)
1907 for (i = 0 ; i < fsm->li->linksLeft; i++) {
1908 if (fsm->li->filex[i] < 0)
1909 /*@innercontinue@*/ continue;
1910 rc = CPIOERR_MISSING_HARDLINK;
1911 if (fsm->failedFile && *fsm->failedFile == NULL) {
1912 fsm->ix = fsm->li->filex[i];
1913 if (!fsmStage(fsm, FSM_MAP)) {
1915 *fsm->failedFile = fsm->path;
1920 /*@loopbreak@*/ break;
1923 if (fsm->goal == FSM_PKGBUILD &&
1924 (fsm->mapFlags & CPIO_ALL_HARDLINKS))
1926 rc = CPIOERR_MISSING_HARDLINK;
1928 fsm->li = freeHardLink(fsm->li);
1930 fsm->ldn = _free(fsm->ldn);
1931 fsm->ldnalloc = fsm->ldnlen = 0;
1932 fsm->rdbuf = fsm->rdb = _free(fsm->rdb);
1933 fsm->wrbuf = fsm->wrb = _free(fsm->wrb);
1936 if (fsm->diskchecked && !fsm->exists) {
1937 rc = CPIOERR_LSTAT_FAILED;
1940 if (S_ISREG(st->st_mode)) {
1941 char * path = alloca(strlen(fsm->path) + sizeof("-RPMDELETE"));
1943 (void) stpcpy( stpcpy(path, fsm->path), "-RPMDELETE");
1946 * XXX HP-UX (and other os'es) don't permit unlink on busy
1949 fsm->opath = fsm->path;
1951 rc = fsmStage(fsm, FSM_RENAME);
1953 (void) fsmStage(fsm, FSM_UNLINK);
1955 rc = CPIOERR_UNLINK_FAILED;
1956 fsm->path = fsm->opath;
1958 return (rc ? rc : CPIOERR_LSTAT_FAILED); /* XXX HACK */
1959 /*@notreached@*/ break;
1960 } else if (S_ISDIR(st->st_mode)) {
1961 if (S_ISDIR(ost->st_mode)) return 0;
1962 if (S_ISLNK(ost->st_mode)) {
1963 rc = fsmStage(fsm, FSM_STAT);
1964 if (rc == CPIOERR_STAT_FAILED && errno == ENOENT) rc = 0;
1967 if (S_ISDIR(ost->st_mode)) return 0;
1969 } else if (S_ISLNK(st->st_mode)) {
1970 if (S_ISLNK(ost->st_mode)) {
1971 /* XXX NUL terminated result in fsm->rdbuf, len in fsm->rdnb. */
1972 rc = fsmStage(fsm, FSM_READLINK);
1975 if (!strcmp(fsm->opath, fsm->rdbuf)) return 0;
1977 } else if (S_ISFIFO(st->st_mode)) {
1978 if (S_ISFIFO(ost->st_mode)) return 0;
1979 } else if (S_ISCHR(st->st_mode) || S_ISBLK(st->st_mode)) {
1980 if ((S_ISCHR(ost->st_mode) || S_ISBLK(ost->st_mode)) &&
1981 (ost->st_rdev == st->st_rdev)) return 0;
1982 } else if (S_ISSOCK(st->st_mode)) {
1983 if (S_ISSOCK(ost->st_mode)) return 0;
1985 /* XXX shouldn't do this with commit/undo. */
1987 if (fsm->stage == FSM_PROCESS) rc = fsmStage(fsm, FSM_UNLINK);
1988 if (rc == 0) rc = CPIOERR_LSTAT_FAILED;
1989 return (rc ? rc : CPIOERR_LSTAT_FAILED); /* XXX HACK */
1990 /*@notreached@*/ break;
1993 rc = Unlink(fsm->path);
1994 if (_fsm_debug && (stage & FSM_SYSCALL))
1995 rpmMessage(RPMMESS_DEBUG, " %8s (%s) %s\n", cur,
1996 fsm->path, (rc < 0 ? strerror(errno) : ""));
1997 if (rc < 0) rc = CPIOERR_UNLINK_FAILED;
2000 rc = Rename(fsm->opath, fsm->path);
2001 #if defined(ETXTBSY)
2002 if (rc && errno == ETXTBSY) {
2003 char * path = alloca(strlen(fsm->path) + sizeof("-RPMDELETE"));
2004 (void) stpcpy( stpcpy(path, fsm->path), "-RPMDELETE");
2006 * XXX HP-UX (and other os'es) don't permit rename to busy
2009 rc = Rename(fsm->path, path);
2010 if (!rc) rc = Rename(fsm->opath, fsm->path);
2013 if (_fsm_debug && (stage & FSM_SYSCALL))
2014 rpmMessage(RPMMESS_DEBUG, " %8s (%s, %s) %s\n", cur,
2015 fsm->opath, fsm->path, (rc < 0 ? strerror(errno) : ""));
2016 if (rc < 0) rc = CPIOERR_RENAME_FAILED;
2019 rc = Mkdir(fsm->path, (st->st_mode & 07777));
2020 if (_fsm_debug && (stage & FSM_SYSCALL))
2021 rpmMessage(RPMMESS_DEBUG, " %8s (%s, 0%04o) %s\n", cur,
2022 fsm->path, (unsigned)(st->st_mode & 07777),
2023 (rc < 0 ? strerror(errno) : ""));
2024 if (rc < 0) rc = CPIOERR_MKDIR_FAILED;
2027 rc = Rmdir(fsm->path);
2028 if (_fsm_debug && (stage & FSM_SYSCALL))
2029 rpmMessage(RPMMESS_DEBUG, " %8s (%s) %s\n", cur,
2030 fsm->path, (rc < 0 ? strerror(errno) : ""));
2031 if (rc < 0) rc = CPIOERR_RMDIR_FAILED;
2034 rc = chown(fsm->path, st->st_uid, st->st_gid);
2035 if (_fsm_debug && (stage & FSM_SYSCALL))
2036 rpmMessage(RPMMESS_DEBUG, " %8s (%s, %d, %d) %s\n", cur,
2037 fsm->path, (int)st->st_uid, (int)st->st_gid,
2038 (rc < 0 ? strerror(errno) : ""));
2039 if (rc < 0) rc = CPIOERR_CHOWN_FAILED;
2042 #if ! CHOWN_FOLLOWS_SYMLINK
2043 rc = lchown(fsm->path, st->st_uid, st->st_gid);
2044 if (_fsm_debug && (stage & FSM_SYSCALL))
2045 rpmMessage(RPMMESS_DEBUG, " %8s (%s, %d, %d) %s\n", cur,
2046 fsm->path, (int)st->st_uid, (int)st->st_gid,
2047 (rc < 0 ? strerror(errno) : ""));
2048 if (rc < 0) rc = CPIOERR_CHOWN_FAILED;
2052 rc = chmod(fsm->path, (st->st_mode & 07777));
2053 if (_fsm_debug && (stage & FSM_SYSCALL))
2054 rpmMessage(RPMMESS_DEBUG, " %8s (%s, 0%04o) %s\n", cur,
2055 fsm->path, (unsigned)(st->st_mode & 07777),
2056 (rc < 0 ? strerror(errno) : ""));
2057 if (rc < 0) rc = CPIOERR_CHMOD_FAILED;
2060 { struct utimbuf stamp;
2061 stamp.actime = st->st_mtime;
2062 stamp.modtime = st->st_mtime;
2063 rc = utime(fsm->path, &stamp);
2064 if (_fsm_debug && (stage & FSM_SYSCALL))
2065 rpmMessage(RPMMESS_DEBUG, " %8s (%s, 0x%x) %s\n", cur,
2066 fsm->path, (unsigned)st->st_mtime,
2067 (rc < 0 ? strerror(errno) : ""));
2068 if (rc < 0) rc = CPIOERR_UTIME_FAILED;
2072 rc = symlink(fsm->opath, fsm->path);
2073 if (_fsm_debug && (stage & FSM_SYSCALL))
2074 rpmMessage(RPMMESS_DEBUG, " %8s (%s, %s) %s\n", cur,
2075 fsm->opath, fsm->path, (rc < 0 ? strerror(errno) : ""));
2076 if (rc < 0) rc = CPIOERR_SYMLINK_FAILED;
2079 rc = Link(fsm->opath, fsm->path);
2080 if (_fsm_debug && (stage & FSM_SYSCALL))
2081 rpmMessage(RPMMESS_DEBUG, " %8s (%s, %s) %s\n", cur,
2082 fsm->opath, fsm->path, (rc < 0 ? strerror(errno) : ""));
2083 if (rc < 0) rc = CPIOERR_LINK_FAILED;
2086 rc = mkfifo(fsm->path, (st->st_mode & 07777));
2087 if (_fsm_debug && (stage & FSM_SYSCALL))
2088 rpmMessage(RPMMESS_DEBUG, " %8s (%s, 0%04o) %s\n", cur,
2089 fsm->path, (unsigned)(st->st_mode & 07777),
2090 (rc < 0 ? strerror(errno) : ""));
2091 if (rc < 0) rc = CPIOERR_MKFIFO_FAILED;
2094 /*@-unrecog -portability @*/ /* FIX: check S_IFIFO or dev != 0 */
2095 rc = mknod(fsm->path, (st->st_mode & ~07777), st->st_rdev);
2096 /*@=unrecog =portability @*/
2097 if (_fsm_debug && (stage & FSM_SYSCALL))
2098 rpmMessage(RPMMESS_DEBUG, " %8s (%s, 0%o, 0x%x) %s\n", cur,
2099 fsm->path, (unsigned)(st->st_mode & ~07777),
2100 (unsigned)st->st_rdev,
2101 (rc < 0 ? strerror(errno) : ""));
2102 if (rc < 0) rc = CPIOERR_MKNOD_FAILED;
2105 rc = Lstat(fsm->path, ost);
2106 if (_fsm_debug && (stage & FSM_SYSCALL) && rc && errno != ENOENT)
2107 rpmMessage(RPMMESS_DEBUG, " %8s (%s, ost) %s\n", cur,
2108 fsm->path, (rc < 0 ? strerror(errno) : ""));
2109 if (rc < 0) rc = CPIOERR_LSTAT_FAILED;
2112 rc = Stat(fsm->path, ost);
2113 if (_fsm_debug && (stage & FSM_SYSCALL) && rc && errno != ENOENT)
2114 rpmMessage(RPMMESS_DEBUG, " %8s (%s, ost) %s\n", cur,
2115 fsm->path, (rc < 0 ? strerror(errno) : ""));
2116 if (rc < 0) rc = CPIOERR_STAT_FAILED;
2119 /* XXX NUL terminated result in fsm->rdbuf, len in fsm->rdnb. */
2121 rc = Readlink(fsm->path, fsm->rdbuf, fsm->rdsize - 1);
2123 if (_fsm_debug && (stage & FSM_SYSCALL))
2124 rpmMessage(RPMMESS_DEBUG, " %8s (%s, rdbuf, %d) %s\n", cur,
2125 fsm->path, (int)(fsm->rdsize -1), (rc < 0 ? strerror(errno) : ""));
2126 if (rc < 0) rc = CPIOERR_READLINK_FAILED;
2130 fsm->rdbuf[fsm->rdnb] = '\0';
2139 rc = fsmStage(fsm, FSM_HREAD);
2141 if (!strcmp(fsm->path, CPIO_TRAILER)) { /* Detect end-of-payload. */
2142 fsm->path = _free(fsm->path);
2143 rc = CPIOERR_HDR_TRAILER;
2146 rc = fsmStage(fsm, FSM_POS);
2149 for (left = st->st_size; left > 0; left -= fsm->rdnb) {
2150 fsm->wrlen = (left > fsm->wrsize ? fsm->wrsize : left);
2151 rc = fsmStage(fsm, FSM_DREAD);
2153 /*@loopbreak@*/ break;
2157 left = (modulo - (fdGetCpioPos(fsm->cfd) % modulo)) % modulo;
2160 (void) fsmStage(fsm, FSM_DREAD);
2164 left = (modulo - (fdGetCpioPos(fsm->cfd) % modulo)) % modulo;
2167 memset(fsm->rdbuf, 0, left);
2169 /* XXX DWRITE uses rdnb for I/O length. */
2171 (void) fsmStage(fsm, FSM_DWRITE);
2175 rc = cpioTrailerWrite(fsm);
2178 rc = fsmStage(fsm, FSM_POS);
2180 rc = cpioHeaderRead(fsm, st); /* Read next payload header. */
2183 rc = cpioHeaderWrite(fsm, st); /* Write next payload header. */
2187 fsm->rdnb = Fread(fsm->wrbuf, sizeof(*fsm->wrbuf), fsm->wrlen, fsm->cfd);
2189 if (_fsm_debug && (stage & FSM_SYSCALL))
2190 rpmMessage(RPMMESS_DEBUG, " %8s (%s, %d, cfd)\trdnb %d\n",
2191 cur, (fsm->wrbuf == fsm->wrb ? "wrbuf" : "mmap"),
2192 (int)fsm->wrlen, (int)fsm->rdnb);
2193 if (fsm->rdnb != fsm->wrlen || Ferror(fsm->cfd))
2194 rc = CPIOERR_READ_FAILED;
2196 fdSetCpioPos(fsm->cfd, fdGetCpioPos(fsm->cfd) + fsm->rdnb);
2199 fsm->wrnb = Fwrite(fsm->rdbuf, sizeof(*fsm->rdbuf), fsm->rdnb, fsm->cfd);
2200 if (_fsm_debug && (stage & FSM_SYSCALL))
2201 rpmMessage(RPMMESS_DEBUG, " %8s (%s, %d, cfd)\twrnb %d\n",
2202 cur, (fsm->rdbuf == fsm->rdb ? "rdbuf" : "mmap"),
2203 (int)fsm->rdnb, (int)fsm->wrnb);
2204 if (fsm->rdnb != fsm->wrnb || Ferror(fsm->cfd))
2205 rc = CPIOERR_WRITE_FAILED;
2207 fdSetCpioPos(fsm->cfd, fdGetCpioPos(fsm->cfd) + fsm->wrnb);
2211 fsm->rfd = Fopen(fsm->path, "r.ufdio");
2212 if (fsm->rfd == NULL || Ferror(fsm->rfd)) {
2213 if (fsm->rfd != NULL) (void) fsmStage(fsm, FSM_RCLOSE);
2215 rc = CPIOERR_OPEN_FAILED;
2219 if (_fsm_debug && (stage & FSM_SYSCALL))
2220 rpmMessage(RPMMESS_DEBUG, " %8s (%s, \"r\") rfd %p rdbuf %p\n", cur,
2221 fsm->path, fsm->rfd, fsm->rdbuf);
2225 fsm->rdnb = Fread(fsm->rdbuf, sizeof(*fsm->rdbuf), fsm->rdlen, fsm->rfd);
2227 if (_fsm_debug && (stage & FSM_SYSCALL))
2228 rpmMessage(RPMMESS_DEBUG, " %8s (rdbuf, %d, rfd)\trdnb %d\n",
2229 cur, (int)fsm->rdlen, (int)fsm->rdnb);
2230 if (fsm->rdnb != fsm->rdlen || Ferror(fsm->rfd))
2231 rc = CPIOERR_READ_FAILED;
2234 if (fsm->rfd != NULL) {
2235 if (_fsm_debug && (stage & FSM_SYSCALL))
2236 rpmMessage(RPMMESS_DEBUG, " %8s (%p)\n", cur, fsm->rfd);
2237 (void) Fclose(fsm->rfd);
2243 fsm->wfd = Fopen(fsm->path, "w.ufdio");
2244 if (fsm->wfd == NULL || Ferror(fsm->wfd)) {
2245 if (fsm->wfd != NULL) (void) fsmStage(fsm, FSM_WCLOSE);
2247 rc = CPIOERR_OPEN_FAILED;
2249 if (_fsm_debug && (stage & FSM_SYSCALL))
2250 rpmMessage(RPMMESS_DEBUG, " %8s (%s, \"w\") wfd %p wrbuf %p\n", cur,
2251 fsm->path, fsm->wfd, fsm->wrbuf);
2254 fsm->wrnb = Fwrite(fsm->wrbuf, sizeof(*fsm->wrbuf), fsm->rdnb, fsm->wfd);
2255 if (_fsm_debug && (stage & FSM_SYSCALL))
2256 rpmMessage(RPMMESS_DEBUG, " %8s (wrbuf, %d, wfd)\twrnb %d\n",
2257 cur, (int)fsm->rdnb, (int)fsm->wrnb);
2258 if (fsm->rdnb != fsm->wrnb || Ferror(fsm->wfd))
2259 rc = CPIOERR_WRITE_FAILED;
2262 if (fsm->wfd != NULL) {
2263 if (_fsm_debug && (stage & FSM_SYSCALL))
2264 rpmMessage(RPMMESS_DEBUG, " %8s (%p)\n", cur, fsm->wfd);
2265 (void) Fclose(fsm->wfd);
2276 if (!(stage & FSM_INTERNAL)) {
2277 fsm->rc = (rc == CPIOERR_HDR_TRAILER ? 0 : rc);
2284 /*@obserever@*/ const char *const fileActionString(fileAction a)
2287 case FA_UNKNOWN: return "unknown";
2288 case FA_CREATE: return "create";
2289 case FA_COPYOUT: return "copyout";
2290 case FA_COPYIN: return "copyin";
2291 case FA_BACKUP: return "backup";
2292 case FA_SAVE: return "save";
2293 case FA_SKIP: return "skip";
2294 case FA_ALTNAME: return "altname";
2295 case FA_ERASE: return "erase";
2296 case FA_SKIPNSTATE: return "skipnstate";
2297 case FA_SKIPNETSHARED: return "skipnetshared";
2298 case FA_SKIPCOLOR: return "skipcolor";
2299 default: return "???";
2304 /*@observer@*/ const char *const fileStageString(fileStage a) {
2306 case FSM_UNKNOWN: return "unknown";
2308 case FSM_PKGINSTALL:return "INSTALL";
2309 case FSM_PKGERASE: return "ERASE";
2310 case FSM_PKGBUILD: return "BUILD";
2311 case FSM_PKGCOMMIT: return "COMMIT";
2312 case FSM_PKGUNDO: return "UNDO";
2314 case FSM_CREATE: return "create";
2315 case FSM_INIT: return "init";
2316 case FSM_MAP: return "map";
2317 case FSM_MKDIRS: return "mkdirs";
2318 case FSM_RMDIRS: return "rmdirs";
2319 case FSM_PRE: return "pre";
2320 case FSM_PROCESS: return "process";
2321 case FSM_POST: return "post";
2322 case FSM_MKLINKS: return "mklinks";
2323 case FSM_NOTIFY: return "notify";
2324 case FSM_UNDO: return "undo";
2325 case FSM_FINI: return "fini";
2326 case FSM_COMMIT: return "commit";
2327 case FSM_DESTROY: return "destroy";
2328 case FSM_VERIFY: return "verify";
2330 case FSM_UNLINK: return "Unlink";
2331 case FSM_RENAME: return "Rename";
2332 case FSM_MKDIR: return "Mkdir";
2333 case FSM_RMDIR: return "rmdir";
2334 case FSM_CHOWN: return "chown";
2335 case FSM_LCHOWN: return "lchown";
2336 case FSM_CHMOD: return "chmod";
2337 case FSM_UTIME: return "utime";
2338 case FSM_SYMLINK: return "symlink";
2339 case FSM_LINK: return "Link";
2340 case FSM_MKFIFO: return "mkfifo";
2341 case FSM_MKNOD: return "mknod";
2342 case FSM_LSTAT: return "Lstat";
2343 case FSM_STAT: return "Stat";
2344 case FSM_READLINK: return "Readlink";
2345 case FSM_CHROOT: return "chroot";
2347 case FSM_NEXT: return "next";
2348 case FSM_EAT: return "eat";
2349 case FSM_POS: return "pos";
2350 case FSM_PAD: return "pad";
2351 case FSM_TRAILER: return "trailer";
2352 case FSM_HREAD: return "hread";
2353 case FSM_HWRITE: return "hwrite";
2354 case FSM_DREAD: return "Fread";
2355 case FSM_DWRITE: return "Fwrite";
2357 case FSM_ROPEN: return "Fopen";
2358 case FSM_READ: return "Fread";
2359 case FSM_RCLOSE: return "Fclose";
2360 case FSM_WOPEN: return "Fopen";
2361 case FSM_WRITE: return "Fwrite";
2362 case FSM_WCLOSE: return "Fclose";
2364 default: return "???";