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)
104 /*@globals fileSystem @*/
105 /*@modifies fileSystem @*/
109 iter->ts = rpmtsFree(iter->ts);
110 iter->fi = rpmfiUnlink(iter->fi, "mapIterator");
116 * Create file info iterator.
117 * @param ts transaction set
118 * @param fi transaction element file info
119 * @return file info iterator
122 mapInitIterator(rpmts ts, rpmfi fi)
123 /*@modifies ts, fi @*/
127 iter = xcalloc(1, sizeof(*iter));
128 iter->ts = rpmtsLink(ts, "mapIterator");
129 iter->fi = rpmfiLink(fi, "mapIterator");
130 iter->reverse = (rpmteType(fi->te) == TR_REMOVED && fi->action != FA_COPYOUT);
131 iter->i = (iter->reverse ? (fi->fc - 1) : 0);
132 iter->isave = iter->i;
137 * Return next index into file info.
138 * @param a file info iterator
139 * @return next index, -1 on termination
141 static int mapNextIterator(/*@null@*/ void * a)
148 const rpmfi fi = iter->fi;
150 if (iter->i >= 0) i = iter->i--;
152 if (iter->i < fi->fc) i = iter->i++;
162 static int cpioStrCmp(const void * a, const void * b)
165 const char * afn = *(const char **)a;
166 const char * bfn = *(const char **)b;
168 /* XXX Some 4+ year old rpm packages have basename only in payloads. */
169 #ifdef VERY_OLD_BUGGY_RPM_PACKAGES
170 if (strchr(afn, '/') == NULL)
171 bfn = strrchr(bfn, '/') + 1;
174 /* Match rpm-4.0 payloads with ./ prefixes. */
175 if (afn[0] == '.' && afn[1] == '/') afn += 2;
176 if (bfn[0] == '.' && bfn[1] == '/') bfn += 2;
178 /* If either path is absolute, make it relative. */
179 if (afn[0] == '/') afn += 1;
180 if (bfn[0] == '/') bfn += 1;
182 return strcmp(afn, bfn);
187 * Locate archive path in file info.
188 * @param iter file info iterator
189 * @param fsmPath archive path
190 * @return index into file info, -1 if archive path was not found
193 static int mapFind(/*@null@*/ FSMI_t iter, const char * fsmPath)
199 const rpmfi fi = iter->fi;
200 if (fi && fi->fc > 0 && fi->apath && fsmPath && *fsmPath) {
201 const char ** p = NULL;
204 if (fi->apath != NULL)
205 p = bsearch(&fsmPath, fi->apath, fi->fc, sizeof(fsmPath),
209 iter->i = p - fi->apath;
210 ix = mapNextIterator(iter);
219 * Directory name iterator.
221 typedef struct dnli_s {
223 /*@only@*/ /*@null@*/
231 * Destroy directory name iterator.
232 * @param a directory name iterator
233 * @retval NULL always
235 static /*@null@*/ void * dnlFreeIterator(/*@only@*//*@null@*/ const void * a)
239 DNLI_t dnli = (void *)a;
240 if (dnli->active) free(dnli->active);
247 static inline int dnlCount(const DNLI_t dnli)
250 return (dnli ? dnli->fi->dc : 0);
255 static inline int dnlIndex(const DNLI_t dnli)
258 return (dnli ? dnli->isave : -1);
262 * Create directory name iterator.
263 * @param fsm file state machine data
264 * @param reverse traverse directory names in reverse order?
265 * @return directory name iterator
269 static /*@only@*/ void * dnlInitIterator(/*@special@*/ const FSM_t fsm,
271 /*@uses fsm->iter @*/
274 rpmfi fi = fsmGetFi(fsm);
280 dnli = xcalloc(1, sizeof(*dnli));
282 dnli->reverse = reverse;
284 dnli->i = (reverse ? fi->dc : 0);
288 dnli->active = xcalloc(fi->dc, sizeof(*dnli->active));
290 /* Identify parent directories not skipped. */
292 for (i = 0; i < fi->fc; i++)
293 if (!XFA_SKIPPING(fi->actions[i])) dnli->active[fi->dil[i]] = 1;
296 /* Exclude parent directories that are explicitly included. */
297 for (i = 0; i < fi->fc; i++) {
298 int dil, dnlen, bnlen;
300 if (!S_ISDIR(fi->fmodes[i]))
304 dnlen = strlen(fi->dnl[dil]);
305 bnlen = strlen(fi->bnl[i]);
307 for (j = 0; j < fi->dc; j++) {
311 if (!dnli->active[j] || j == dil)
312 /*@innercontinue@*/ continue;
315 if (jlen != (dnlen+bnlen+1))
316 /*@innercontinue@*/ continue;
317 if (strncmp(dnl, fi->dnl[dil], dnlen))
318 /*@innercontinue@*/ continue;
319 if (strncmp(dnl+dnlen, fi->bnl[i], bnlen))
320 /*@innercontinue@*/ continue;
321 if (dnl[dnlen+bnlen] != '/' || dnl[dnlen+bnlen+1] != '\0')
322 /*@innercontinue@*/ continue;
323 /* This directory is included in the package. */
327 /*@innerbreak@*/ break;
331 /* Print only once per package. */
334 for (i = 0; i < fi->dc; i++) {
335 if (!dnli->active[i]) continue;
338 rpmMessage(RPMMESS_DEBUG,
339 _("========== Directories not explictly included in package:\n"));
341 rpmMessage(RPMMESS_DEBUG, _("%10d %s\n"), i, fi->dnl[i]);
344 rpmMessage(RPMMESS_DEBUG, "==========\n");
353 * Return next directory name (from file info).
354 * @param dnli directory name iterator
355 * @return next directory name
358 static /*@observer@*/ const char * dnlNextIterator(/*@null@*/ DNLI_t dnli)
361 const char * dn = NULL;
369 i = (!dnli->reverse ? dnli->i++ : --dnli->i);
370 } while (i >= 0 && i < fi->dc && !dnli->active[i]);
372 if (i >= 0 && i < fi->dc)
383 * Save hard link in chain.
384 * @param fsm file state machine data
385 * @return Is chain only partially filled?
388 static int saveHardLink(/*@special@*/ /*@partial@*/ FSM_t fsm)
389 /*@uses fsm->links, fsm->ix, fsm->sb, fsm->goal, fsm->nsuffix @*/
390 /*@defines fsm->li @*/
391 /*@releases fsm->path @*/
392 /*@globals fileSystem, internalState @*/
393 /*@modifies fsm, fileSystem, internalState @*/
395 struct stat * st = &fsm->sb;
400 /* Find hard link set. */
402 for (fsm->li = fsm->links; fsm->li; fsm->li = fsm->li->next) {
403 if (fsm->li->sb.st_ino == st->st_ino && fsm->li->sb.st_dev == st->st_dev)
408 /* New hard link encountered, add new link to set. */
411 if (fsm->li == NULL) {
412 fsm->li = xcalloc(1, sizeof(*fsm->li));
413 fsm->li->next = NULL;
414 fsm->li->sb = *st; /* structure assignment */
415 fsm->li->nlink = st->st_nlink;
416 fsm->li->linkIndex = fsm->ix;
417 fsm->li->createdPath = -1;
419 fsm->li->filex = xcalloc(st->st_nlink, sizeof(fsm->li->filex[0]));
420 memset(fsm->li->filex, -1, (st->st_nlink * sizeof(fsm->li->filex[0])));
421 fsm->li->nsuffix = xcalloc(st->st_nlink, sizeof(*fsm->li->nsuffix));
423 if (fsm->goal == FSM_PKGBUILD)
424 fsm->li->linksLeft = st->st_nlink;
425 if (fsm->goal == FSM_PKGINSTALL)
426 fsm->li->linksLeft = 0;
429 fsm->li->next = fsm->links;
431 fsm->links = fsm->li;
436 if (fsm->goal == FSM_PKGBUILD) --fsm->li->linksLeft;
438 fsm->li->filex[fsm->li->linksLeft] = fsm->ix;
439 /*@-observertrans -dependenttrans@*/
440 fsm->li->nsuffix[fsm->li->linksLeft] = fsm->nsuffix;
441 /*@=observertrans =dependenttrans@*/
443 if (fsm->goal == FSM_PKGINSTALL) fsm->li->linksLeft++;
445 if (fsm->goal == FSM_PKGBUILD)
446 return (fsm->li->linksLeft > 0);
448 if (fsm->goal != FSM_PKGINSTALL)
451 if (!(st->st_size || fsm->li->linksLeft == st->st_nlink))
454 /* Here come the bits, time to choose a non-skipped file name. */
455 { rpmfi fi = fsmGetFi(fsm);
457 for (j = fsm->li->linksLeft - 1; j >= 0; j--) {
458 ix = fsm->li->filex[j];
459 if (ix < 0 || XFA_SKIPPING(fi->actions[ix]))
465 /* Are all links skipped or not encountered yet? */
467 return 1; /* XXX W2DO? */
469 /* Save the non-skipped file name and map index. */
470 fsm->li->linkIndex = j;
471 fsm->path = _free(fsm->path);
473 rc = fsmStage(fsm, FSM_MAP);
479 * Destroy set of hard links.
480 * @param li set of hard links
481 * @return NULL always
483 static /*@null@*/ void * freeHardLink(/*@only@*/ /*@null@*/ struct hardLink_s * li)
487 li->nsuffix = _free(li->nsuffix); /* XXX elements are shared */
488 li->filex = _free(li->filex);
495 FSM_t fsm = xcalloc(1, sizeof(*fsm));
499 FSM_t freeFSM(FSM_t fsm)
502 fsm->path = _free(fsm->path);
504 while ((fsm->li = fsm->links) != NULL) {
505 fsm->links = fsm->li->next;
506 fsm->li->next = NULL;
507 fsm->li = freeHardLink(fsm->li);
510 fsm->dnlx = _free(fsm->dnlx);
511 fsm->ldn = _free(fsm->ldn);
512 fsm->iter = mapFreeIterator(fsm->iter);
517 int fsmSetup(FSM_t fsm, fileStage goal,
518 const rpmts ts, const rpmfi fi, FD_t cfd,
519 unsigned int * archiveSize, const char ** failedFile)
526 /*@-type@*/ /* FIX: cast? */
527 fsm->cfd = fdLink(cfd, "persist (fsm)");
529 pos = fdGetCpioPos(fsm->cfd);
530 fdSetCpioPos(fsm->cfd, 0);
532 fsm->iter = mapInitIterator(ts, fi);
534 if (fsm->goal == FSM_PKGINSTALL || fsm->goal == FSM_PKGBUILD) {
537 ptr = rpmtsNotify(ts, fi->te,
538 RPMCALLBACK_INST_START, fi->archivePos, fi->archiveSize);
543 fsm->archiveSize = archiveSize;
544 if (fsm->archiveSize)
545 *fsm->archiveSize = 0;
546 fsm->failedFile = failedFile;
548 *fsm->failedFile = NULL;
552 memset(fsm->sufbuf, 0, sizeof(fsm->sufbuf));
553 if (fsm->goal == FSM_PKGINSTALL) {
554 if (ts && rpmtsGetTid(ts) > 0)
555 sprintf(fsm->sufbuf, ";%08x", (unsigned)rpmtsGetTid(ts));
559 rc = fsmStage(fsm, FSM_CREATE);
560 if (rc && !ec) ec = rc;
562 rc = fsmStage(fsm, fsm->goal);
563 if (rc && !ec) ec = rc;
566 if (fsm->archiveSize && ec == 0)
567 *fsm->archiveSize = (fdGetCpioPos(fsm->cfd) - pos);
573 int fsmTeardown(FSM_t fsm)
578 rc = fsmStage(fsm, FSM_DESTROY);
580 fsm->iter = mapFreeIterator(fsm->iter);
582 /*@-type@*/ /* FIX: cast? */
583 fsm->cfd = fdFree(fsm->cfd, "persist (fsm)");
587 fsm->failedFile = NULL;
591 int fsmMapPath(FSM_t fsm)
593 rpmfi fi = fsmGetFi(fsm); /* XXX const except for fstates */
600 fsm->action = FA_UNKNOWN;
604 if (fi && i >= 0 && i < fi->fc) {
607 fsm->astriplen = fi->astriplen;
608 fsm->action = (fi->actions ? fi->actions[i] : fi->action);
609 fsm->fflags = (fi->fflags ? fi->fflags[i] : fi->flags);
610 fsm->mapFlags = (fi->fmapflags ? fi->fmapflags[i] : fi->mapflags);
612 /* src rpms have simple base name in payload. */
613 fsm->dirName = fi->dnl[fi->dil[i]];
614 fsm->baseName = fi->bnl[i];
618 switch (fsm->action) {
621 case FA_SKIPMULTILIB: /* XXX RPMFILE_STATE_MULTILIB? */
630 assert(rpmteType(fi->te) == TR_ADDED);
634 if (fi->fstates && rpmteType(fi->te) == TR_ADDED)
635 fi->fstates[i] = RPMFILE_STATE_NOTINSTALLED;
638 case FA_SKIPNETSHARED:
639 if (fi->fstates && rpmteType(fi->te) == TR_ADDED)
640 fi->fstates[i] = RPMFILE_STATE_NETSHARED;
644 if (!(fsm->fflags & RPMFILE_GHOST)) /* XXX Don't if %ghost file. */
645 switch (rpmteType(fi->te)) {
647 fsm->osuffix = SUFFIX_RPMORIG;
648 /*@innerbreak@*/ break;
650 fsm->osuffix = SUFFIX_RPMSAVE;
651 /*@innerbreak@*/ break;
656 assert(rpmteType(fi->te) == TR_ADDED);
657 if (!(fsm->fflags & RPMFILE_GHOST)) /* XXX Don't if %ghost file. */
658 fsm->nsuffix = SUFFIX_RPMNEW;
662 assert(rpmteType(fi->te) == TR_ADDED);
663 if (!(fsm->fflags & RPMFILE_GHOST)) /* XXX Don't if %ghost file. */
664 fsm->osuffix = SUFFIX_RPMSAVE;
667 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 fileSystem, internalState @*/
746 /*@modifies fsm, 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 fileSystem, internalState @*/
813 /*@modifies fsm, 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);
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 fileSystem, internalState @*/
953 /*@modifies fsm, 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 fileSystem, internalState @*/
1001 /*@modifies fsm, 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 fileSystem, internalState @*/
1066 /*@modifies fsm, 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 fileSystem, internalState @*/
1112 /*@modifies fsm, 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 fileSystem, internalState @*/
1169 /*@modifies fsm, 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)
1282 int saveerrno = errno;
1285 if (fsm->path != NULL) {
1286 int saveernno = errno;
1287 rc = fsmStage(fsm, (!(fsm->mapFlags & CPIO_FOLLOW_SYMLINKS)
1288 ? FSM_LSTAT : FSM_STAT));
1289 if (rc == CPIOERR_LSTAT_FAILED && errno == ENOENT) {
1293 } else if (rc == 0) {
1297 /* Skip %ghost files on build. */
1304 #define IS_DEV_LOG(_x) \
1305 ((_x) != NULL && strlen(_x) >= (sizeof("/dev/log")-1) && \
1306 !strncmp((_x), "/dev/log", sizeof("/dev/log")-1) && \
1307 ((_x)[sizeof("/dev/log")-1] == '\0' || \
1308 (_x)[sizeof("/dev/log")-1] == ';'))
1312 int fsmStage(FSM_t fsm, fileStage stage)
1315 fileStage prevStage = fsm->stage;
1316 const char * const prev = fileStageString(prevStage);
1318 static int modulo = 4;
1319 const char * const cur = fileStageString(stage);
1320 struct stat * st = &fsm->sb;
1321 struct stat * ost = &fsm->osb;
1322 int saveerrno = errno;
1327 #define _fafilter(_a) \
1328 (!((_a) == FA_CREATE || (_a) == FA_ERASE || (_a) == FA_COPYIN || (_a) == FA_COPYOUT) \
1329 ? fileActionString(_a) : "")
1331 if (stage & FSM_DEAD) {
1333 } else if (stage & FSM_INTERNAL) {
1334 if (_fsm_debug && !(stage & FSM_SYSCALL))
1335 rpmMessage(RPMMESS_DEBUG, " %8s %06o%3d (%4d,%4d)%10d %s %s\n",
1337 (unsigned)st->st_mode, (int)st->st_nlink,
1338 (int)st->st_uid, (int)st->st_gid, (int)st->st_size,
1339 (fsm->path ? fsm->path : ""),
1340 _fafilter(fsm->action));
1343 if (_fsm_debug || !(stage & FSM_VERBOSE))
1344 rpmMessage(RPMMESS_DEBUG, "%-8s %06o%3d (%4d,%4d)%10d %s %s\n",
1346 (unsigned)st->st_mode, (int)st->st_nlink,
1347 (int)st->st_uid, (int)st->st_gid, (int)st->st_size,
1348 (fsm->path ? fsm->path + fsm->astriplen : ""),
1349 _fafilter(fsm->action));
1357 case FSM_PKGINSTALL:
1359 /* Clean fsm, free'ing memory. Read next archive header. */
1360 rc = fsmStage(fsm, FSM_INIT);
1362 /* Exit on end-of-payload. */
1363 if (rc == CPIOERR_HDR_TRAILER) {
1365 /*@loopbreak@*/ break;
1368 /* Exit on error. */
1371 (void) fsmStage(fsm, FSM_UNDO);
1372 /*@loopbreak@*/ break;
1375 /* Extract file from archive. */
1376 rc = fsmStage(fsm, FSM_PROCESS);
1378 (void) fsmStage(fsm, FSM_UNDO);
1379 /*@loopbreak@*/ break;
1382 /* Notify on success. */
1383 (void) fsmStage(fsm, FSM_NOTIFY);
1385 rc = fsmStage(fsm, FSM_FINI);
1387 /*@loopbreak@*/ break;
1394 /* Clean fsm, free'ing memory. */
1395 rc = fsmStage(fsm, FSM_INIT);
1397 /* Exit on end-of-payload. */
1398 if (rc == CPIOERR_HDR_TRAILER) {
1400 /*@loopbreak@*/ break;
1403 /* Rename/erase next item. */
1404 if (fsmStage(fsm, FSM_FINI))
1405 /*@loopbreak@*/ break;
1411 rc = fsmStage(fsm, FSM_INIT);
1413 /* Exit on end-of-payload. */
1414 if (rc == CPIOERR_HDR_TRAILER) {
1416 /*@loopbreak@*/ break;
1419 /* Exit on error. */
1422 (void) fsmStage(fsm, FSM_UNDO);
1423 /*@loopbreak@*/ break;
1426 /* Copy file into archive. */
1427 rc = fsmStage(fsm, FSM_PROCESS);
1429 (void) fsmStage(fsm, FSM_UNDO);
1430 /*@loopbreak@*/ break;
1433 /* Notify on success. */
1434 (void) fsmStage(fsm, FSM_NOTIFY);
1436 if (fsmStage(fsm, FSM_FINI))
1437 /*@loopbreak@*/ break;
1440 /* Flush partial sets of hard linked files. */
1441 if (!(fsm->mapFlags & CPIO_ALL_HARDLINKS)) {
1443 while ((fsm->li = fsm->links) != NULL) {
1444 fsm->links = fsm->li->next;
1445 fsm->li->next = NULL;
1447 /* Re-calculate link count for archive header. */
1448 for (j = -1, nlink = 0, i = 0; i < fsm->li->nlink; i++) {
1449 if (fsm->li->filex[i] < 0)
1450 /*@innercontinue@*/ continue;
1454 /* XXX force the contents out as well. */
1457 fsm->li->filex[0] = fsm->li->filex[j];
1458 fsm->li->filex[j] = -1;
1461 fsm->li->sb.st_nlink = nlink;
1463 fsm->sb = fsm->li->sb; /* structure assignment */
1464 fsm->osb = fsm->sb; /* structure assignment */
1466 if (!rc) rc = writeLinkedFile(fsm);
1468 fsm->li = freeHardLink(fsm->li);
1473 rc = fsmStage(fsm, FSM_TRAILER);
1477 { rpmts ts = fsmGetTs(fsm);
1478 #define _tsmask (RPMTRANS_FLAG_PKGCOMMIT | RPMTRANS_FLAG_COMMIT)
1479 fsm->commit = ((ts && (rpmtsFlags(ts) & _tsmask) &&
1480 fsm->goal != FSM_PKGCOMMIT) ? 0 : 1);
1483 fsm->path = _free(fsm->path);
1484 fsm->opath = _free(fsm->opath);
1485 fsm->dnlx = _free(fsm->dnlx);
1487 fsm->ldn = _free(fsm->ldn);
1488 fsm->ldnalloc = fsm->ldnlen = 0;
1490 fsm->rdsize = fsm->wrsize = 0;
1491 fsm->rdbuf = fsm->rdb = _free(fsm->rdb);
1492 fsm->wrbuf = fsm->wrb = _free(fsm->wrb);
1493 if (fsm->goal == FSM_PKGINSTALL || fsm->goal == FSM_PKGBUILD) {
1494 fsm->rdsize = 8 * BUFSIZ;
1495 fsm->rdbuf = fsm->rdb = xmalloc(fsm->rdsize);
1496 fsm->wrsize = 8 * BUFSIZ;
1497 fsm->wrbuf = fsm->wrb = xmalloc(fsm->wrsize);
1500 fsm->mkdirsdone = 0;
1505 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) {
1579 } else if (rc == 0) {
1583 /* Skip %ghost files on build. */
1587 fsm->diskchecked = 1;
1590 /* On non-install, the disk file stat is what's remapped. */
1592 if (fsm->goal != FSM_PKGINSTALL)
1593 *st = *ost; /* structure assignment */
1596 /* Remap file perms, owner, and group. */
1597 rc = fsmMapAttrs(fsm);
1600 fsm->postpone = XFA_SKIPPING(fsm->action);
1601 if (fsm->goal == FSM_PKGINSTALL || fsm->goal == FSM_PKGBUILD) {
1602 /*@-evalorder@*/ /* FIX: saveHardLink can modify fsm */
1603 if (!S_ISDIR(st->st_mode) && st->st_nlink > 1)
1604 fsm->postpone = saveHardLink(fsm);
1611 rc = fsmMapPath(fsm);
1614 rc = fsmMkdirs(fsm);
1618 rc = fsmRmdirs(fsm);
1621 if (fsm->postpone) {
1622 if (fsm->goal == FSM_PKGINSTALL)
1623 rc = fsmStage(fsm, FSM_EAT);
1627 if (fsm->goal == FSM_PKGBUILD) {
1628 if (fsm->fflags & RPMFILE_GHOST) /* XXX Don't if %ghost file. */
1630 if (!S_ISDIR(st->st_mode) && st->st_nlink > 1) {
1631 struct hardLink_s * li, * prev;
1633 if (!(fsm->mapFlags & CPIO_ALL_HARDLINKS)) break;
1634 rc = writeLinkedFile(fsm);
1635 if (rc) break; /* W2DO? */
1637 for (li = fsm->links, prev = NULL; li; prev = li, li = li->next)
1639 /*@loopbreak@*/ break;
1642 fsm->links = fsm->li->next;
1644 prev->next = fsm->li->next;
1645 fsm->li->next = NULL;
1646 fsm->li = freeHardLink(fsm->li);
1648 rc = writeFile(fsm, 1);
1653 if (fsm->goal != FSM_PKGINSTALL)
1656 if (S_ISREG(st->st_mode)) {
1657 const char * path = fsm->path;
1659 fsm->path = fsmFsPath(fsm, st, NULL, NULL);
1660 rc = fsmStage(fsm, FSM_VERIFY);
1662 if (rc == 0 && fsm->osuffix) {
1663 const char * opath = fsm->opath;
1664 fsm->opath = fsm->path;
1665 fsm->path = fsmFsPath(fsm, st, NULL, fsm->osuffix);
1666 rc = fsmStage(fsm, FSM_RENAME);
1668 rpmMessage(RPMMESS_WARNING,
1669 _("%s saved as %s\n"), fsm->opath, fsm->path);
1670 fsm->path = _free(fsm->path);
1674 /*@-dependenttrans@*/
1676 /*@=dependenttrans@*/
1677 if (rc != CPIOERR_LSTAT_FAILED) return rc;
1678 rc = expandRegular(fsm);
1679 } else if (S_ISDIR(st->st_mode)) {
1680 mode_t st_mode = st->st_mode;
1681 rc = fsmStage(fsm, FSM_VERIFY);
1682 if (rc == CPIOERR_LSTAT_FAILED) {
1683 st->st_mode &= ~07777; /* XXX abuse st->st_mode */
1684 st->st_mode |= 00700;
1685 rc = fsmStage(fsm, FSM_MKDIR);
1686 st->st_mode = st_mode; /* XXX restore st->st_mode */
1688 } else if (S_ISLNK(st->st_mode)) {
1689 const char * opath = fsm->opath;
1691 if ((st->st_size + 1) > fsm->rdsize) {
1692 rc = CPIOERR_HDR_SIZE;
1696 fsm->wrlen = st->st_size;
1697 rc = fsmStage(fsm, FSM_DREAD);
1698 if (!rc && fsm->rdnb != fsm->wrlen)
1699 rc = CPIOERR_READ_FAILED;
1703 fsm->wrbuf[st->st_size] = '\0';
1705 /* XXX symlink(fsm->opath, fsm->path) */
1706 /*@-dependenttrans@*/
1707 fsm->opath = fsm->wrbuf;
1708 /*@=dependenttrans@*/
1709 rc = fsmStage(fsm, FSM_VERIFY);
1710 if (rc == CPIOERR_LSTAT_FAILED)
1711 rc = fsmStage(fsm, FSM_SYMLINK);
1712 fsm->opath = opath; /* XXX restore fsm->path */
1713 } else if (S_ISFIFO(st->st_mode)) {
1714 mode_t st_mode = st->st_mode;
1715 /* This mimics cpio S_ISSOCK() behavior but probably isnt' right */
1716 rc = fsmStage(fsm, FSM_VERIFY);
1717 if (rc == CPIOERR_LSTAT_FAILED) {
1718 st->st_mode = 0000; /* XXX abuse st->st_mode */
1719 rc = fsmStage(fsm, FSM_MKFIFO);
1720 st->st_mode = st_mode; /* XXX restore st->st_mode */
1722 } else if (S_ISCHR(st->st_mode) ||
1723 S_ISBLK(st->st_mode) ||
1724 /*@-unrecog@*/ S_ISSOCK(st->st_mode) /*@=unrecog@*/)
1726 rc = fsmStage(fsm, FSM_VERIFY);
1727 if (rc == CPIOERR_LSTAT_FAILED)
1728 rc = fsmStage(fsm, FSM_MKNOD);
1730 /* XXX Special case /dev/log, which shouldn't be packaged anyways */
1731 if (!IS_DEV_LOG(fsm->path))
1732 rc = CPIOERR_UNKNOWN_FILETYPE;
1734 if (!S_ISDIR(st->st_mode) && st->st_nlink > 1) {
1735 fsm->li->createdPath = fsm->li->linkIndex;
1736 rc = fsmMakeLinks(fsm);
1742 rc = fsmMakeLinks(fsm);
1744 case FSM_NOTIFY: /* XXX move from fsm to psm -> tsm */
1745 if (fsm->goal == FSM_PKGINSTALL || fsm->goal == FSM_PKGBUILD) {
1746 rpmts ts = fsmGetTs(fsm);
1747 rpmfi fi = fsmGetFi(fsm);
1749 unsigned int archivePos = fdGetCpioPos(fsm->cfd);
1750 if (archivePos > fi->archivePos) {
1751 fi->archivePos = archivePos;
1752 ptr = rpmtsNotify(ts, fi->te, RPMCALLBACK_INST_PROGRESS,
1753 fi->archivePos, fi->archiveSize);
1760 if (fsm->goal == FSM_PKGINSTALL) {
1761 (void) fsmStage(fsm,
1762 (S_ISDIR(st->st_mode) ? FSM_RMDIR : FSM_UNLINK));
1764 #ifdef NOTYET /* XXX remove only dirs just created, not all. */
1766 (void) fsmStage(fsm, FSM_RMDIRS);
1773 if (fsm->failedFile && *fsm->failedFile == NULL)
1774 *fsm->failedFile = xstrdup(fsm->path);
1778 if (!fsm->postpone && fsm->commit) {
1779 if (fsm->goal == FSM_PKGINSTALL)
1780 rc = ((!S_ISDIR(st->st_mode) && st->st_nlink > 1)
1781 ? fsmCommitLinks(fsm) : fsmStage(fsm, FSM_COMMIT));
1782 if (fsm->goal == FSM_PKGCOMMIT)
1783 rc = fsmStage(fsm, FSM_COMMIT);
1784 if (fsm->goal == FSM_PKGERASE)
1785 rc = fsmStage(fsm, FSM_COMMIT);
1787 fsm->path = _free(fsm->path);
1788 fsm->opath = _free(fsm->opath);
1790 memset(st, 0, sizeof(*st));
1791 memset(ost, 0, sizeof(*ost));
1795 /* Rename pre-existing modified or unmanaged file. */
1796 if (fsm->osuffix && fsm->diskchecked &&
1797 (fsm->exists || (fsm->goal == FSM_PKGINSTALL && S_ISREG(st->st_mode))))
1799 const char * opath = fsm->opath;
1800 const char * path = fsm->path;
1801 fsm->opath = fsmFsPath(fsm, st, NULL, NULL);
1802 fsm->path = fsmFsPath(fsm, st, NULL, fsm->osuffix);
1803 rc = fsmStage(fsm, FSM_RENAME);
1805 rpmMessage(RPMMESS_WARNING, _("%s saved as %s\n"),
1806 fsm->opath, fsm->path);
1808 fsm->path = _free(fsm->path);
1810 fsm->opath = _free(fsm->opath);
1814 /* Remove erased files. */
1815 if (fsm->goal == FSM_PKGERASE) {
1816 if (fsm->action == FA_ERASE) {
1817 rpmfi fi = fsmGetFi(fsm);
1818 if (S_ISDIR(st->st_mode)) {
1819 rc = fsmStage(fsm, FSM_RMDIR);
1822 case ENOENT: /* XXX rmdir("/") linux 2.2.x kernel hack */
1824 /* XXX make sure that build side permits %missingok on directories. */
1825 if (fsm->fflags & RPMFILE_MISSINGOK)
1826 /*@innerbreak@*/ break;
1828 /* XXX common error message. */
1830 (strict_erasures ? RPMERR_RMDIR : RPMDEBUG_RMDIR),
1831 _("%s rmdir of %s failed: Directory not empty\n"),
1832 rpmfiTypeString(fi), fsm->path);
1833 /*@innerbreak@*/ break;
1836 (strict_erasures ? RPMERR_RMDIR : RPMDEBUG_RMDIR),
1837 _("%s rmdir of %s failed: %s\n"),
1838 rpmfiTypeString(fi), fsm->path, strerror(errno));
1839 /*@innerbreak@*/ break;
1842 rc = fsmStage(fsm, FSM_UNLINK);
1844 if (!(errno == ENOENT && (fsm->fflags & RPMFILE_MISSINGOK)))
1846 (strict_erasures ? RPMERR_UNLINK : RPMDEBUG_UNLINK),
1847 _("%s unlink of %s failed: %s\n"),
1848 rpmfiTypeString(fi), fsm->path, strerror(errno));
1851 /* XXX Failure to remove is not (yet) cause for failure. */
1852 if (!strict_erasures) rc = 0;
1856 /* XXX Special case /dev/log, which shouldn't be packaged anyways */
1857 if (!S_ISSOCK(st->st_mode) && !IS_DEV_LOG(fsm->path)) {
1858 /* Rename temporary to final file name. */
1859 if (!S_ISDIR(st->st_mode) &&
1860 (fsm->subdir || fsm->suffix || fsm->nsuffix))
1862 fsm->opath = fsm->path;
1863 fsm->path = fsmFsPath(fsm, st, NULL, fsm->nsuffix);
1864 rc = fsmStage(fsm, FSM_RENAME);
1865 if (!rc && fsm->nsuffix) {
1866 const char * opath = fsmFsPath(fsm, st, NULL, NULL);
1867 rpmMessage(RPMMESS_WARNING, _("%s created as %s\n"),
1868 (opath ? opath : ""), fsm->path);
1869 opath = _free(opath);
1871 fsm->opath = _free(fsm->opath);
1873 if (S_ISLNK(st->st_mode)) {
1874 if (!rc && !getuid())
1875 rc = fsmStage(fsm, FSM_LCHOWN);
1877 if (!rc && !getuid())
1878 rc = fsmStage(fsm, FSM_CHOWN);
1880 rc = fsmStage(fsm, FSM_CHMOD);
1882 time_t mtime = st->st_mtime;
1883 rpmfi fi = fsmGetFi(fsm);
1885 st->st_mtime = fi->fmtimes[fsm->ix];
1886 rc = fsmStage(fsm, FSM_UTIME);
1887 st->st_mtime = mtime;
1892 /* Notify on success. */
1893 if (!rc) rc = fsmStage(fsm, FSM_NOTIFY);
1894 else if (fsm->failedFile && *fsm->failedFile == NULL) {
1896 *fsm->failedFile = fsm->path;
1902 fsm->path = _free(fsm->path);
1904 /* Check for hard links missing from payload. */
1905 while ((fsm->li = fsm->links) != NULL) {
1906 fsm->links = fsm->li->next;
1907 fsm->li->next = NULL;
1908 if (fsm->goal == FSM_PKGINSTALL &&
1909 fsm->commit && fsm->li->linksLeft)
1911 for (i = 0 ; i < fsm->li->linksLeft; i++) {
1912 if (fsm->li->filex[i] < 0)
1913 /*@innercontinue@*/ continue;
1914 rc = CPIOERR_MISSING_HARDLINK;
1915 if (fsm->failedFile && *fsm->failedFile == NULL) {
1916 fsm->ix = fsm->li->filex[i];
1917 if (!fsmStage(fsm, FSM_MAP)) {
1919 *fsm->failedFile = fsm->path;
1924 /*@loopbreak@*/ break;
1927 if (fsm->goal == FSM_PKGBUILD &&
1928 (fsm->mapFlags & CPIO_ALL_HARDLINKS))
1930 rc = CPIOERR_MISSING_HARDLINK;
1932 fsm->li = freeHardLink(fsm->li);
1934 fsm->ldn = _free(fsm->ldn);
1935 fsm->ldnalloc = fsm->ldnlen = 0;
1936 fsm->rdbuf = fsm->rdb = _free(fsm->rdb);
1937 fsm->wrbuf = fsm->wrb = _free(fsm->wrb);
1940 if (fsm->diskchecked && !fsm->exists) {
1941 rc = CPIOERR_LSTAT_FAILED;
1944 if (S_ISREG(st->st_mode)) {
1945 char * path = alloca(strlen(fsm->path) + sizeof("-RPMDELETE"));
1947 (void) stpcpy( stpcpy(path, fsm->path), "-RPMDELETE");
1950 * XXX HP-UX (and other os'es) don't permit unlink on busy
1953 fsm->opath = fsm->path;
1955 rc = fsmStage(fsm, FSM_RENAME);
1957 (void) fsmStage(fsm, FSM_UNLINK);
1959 rc = CPIOERR_UNLINK_FAILED;
1960 fsm->path = fsm->opath;
1962 return (rc ? rc : CPIOERR_LSTAT_FAILED); /* XXX HACK */
1963 /*@notreached@*/ break;
1964 } else if (S_ISDIR(st->st_mode)) {
1965 if (S_ISDIR(ost->st_mode)) return 0;
1966 if (S_ISLNK(ost->st_mode)) {
1967 rc = fsmStage(fsm, FSM_STAT);
1968 if (rc == CPIOERR_STAT_FAILED && errno == ENOENT) rc = 0;
1973 if (S_ISDIR(ost->st_mode)) return 0;
1975 } else if (S_ISLNK(st->st_mode)) {
1976 if (S_ISLNK(ost->st_mode)) {
1977 /* XXX NUL terminated result in fsm->rdbuf, len in fsm->rdnb. */
1978 rc = fsmStage(fsm, FSM_READLINK);
1983 if (!strcmp(fsm->opath, fsm->rdbuf)) return 0;
1985 } else if (S_ISFIFO(st->st_mode)) {
1986 if (S_ISFIFO(ost->st_mode)) return 0;
1987 } else if (S_ISCHR(st->st_mode) || S_ISBLK(st->st_mode)) {
1988 if ((S_ISCHR(ost->st_mode) || S_ISBLK(ost->st_mode)) &&
1989 (ost->st_rdev == st->st_rdev)) return 0;
1990 } else if (S_ISSOCK(st->st_mode)) {
1991 if (S_ISSOCK(ost->st_mode)) return 0;
1993 /* XXX shouldn't do this with commit/undo. */
1995 if (fsm->stage == FSM_PROCESS) rc = fsmStage(fsm, FSM_UNLINK);
1996 if (rc == 0) rc = CPIOERR_LSTAT_FAILED;
1997 return (rc ? rc : CPIOERR_LSTAT_FAILED); /* XXX HACK */
1998 /*@notreached@*/ break;
2001 rc = Unlink(fsm->path);
2002 if (_fsm_debug && (stage & FSM_SYSCALL))
2003 rpmMessage(RPMMESS_DEBUG, " %8s (%s) %s\n", cur,
2004 fsm->path, (rc < 0 ? strerror(errno) : ""));
2005 if (rc < 0) rc = CPIOERR_UNLINK_FAILED;
2008 rc = Rename(fsm->opath, fsm->path);
2009 #if defined(ETXTBSY)
2010 if (rc && errno == ETXTBSY) {
2011 char * path = alloca(strlen(fsm->path) + sizeof("-RPMDELETE"));
2012 (void) stpcpy( stpcpy(path, fsm->path), "-RPMDELETE");
2014 * XXX HP-UX (and other os'es) don't permit rename to busy
2017 rc = Rename(fsm->path, path);
2018 if (!rc) rc = Rename(fsm->opath, fsm->path);
2021 if (_fsm_debug && (stage & FSM_SYSCALL))
2022 rpmMessage(RPMMESS_DEBUG, " %8s (%s, %s) %s\n", cur,
2023 fsm->opath, fsm->path, (rc < 0 ? strerror(errno) : ""));
2024 if (rc < 0) rc = CPIOERR_RENAME_FAILED;
2027 rc = Mkdir(fsm->path, (st->st_mode & 07777));
2028 if (_fsm_debug && (stage & FSM_SYSCALL))
2029 rpmMessage(RPMMESS_DEBUG, " %8s (%s, 0%04o) %s\n", cur,
2030 fsm->path, (unsigned)(st->st_mode & 07777),
2031 (rc < 0 ? strerror(errno) : ""));
2032 if (rc < 0) rc = CPIOERR_MKDIR_FAILED;
2035 rc = Rmdir(fsm->path);
2036 if (_fsm_debug && (stage & FSM_SYSCALL))
2037 rpmMessage(RPMMESS_DEBUG, " %8s (%s) %s\n", cur,
2038 fsm->path, (rc < 0 ? strerror(errno) : ""));
2039 if (rc < 0) rc = CPIOERR_RMDIR_FAILED;
2042 rc = chown(fsm->path, st->st_uid, st->st_gid);
2043 if (_fsm_debug && (stage & FSM_SYSCALL))
2044 rpmMessage(RPMMESS_DEBUG, " %8s (%s, %d, %d) %s\n", cur,
2045 fsm->path, (int)st->st_uid, (int)st->st_gid,
2046 (rc < 0 ? strerror(errno) : ""));
2047 if (rc < 0) rc = CPIOERR_CHOWN_FAILED;
2050 #if ! CHOWN_FOLLOWS_SYMLINK
2051 rc = lchown(fsm->path, st->st_uid, st->st_gid);
2052 if (_fsm_debug && (stage & FSM_SYSCALL))
2053 rpmMessage(RPMMESS_DEBUG, " %8s (%s, %d, %d) %s\n", cur,
2054 fsm->path, (int)st->st_uid, (int)st->st_gid,
2055 (rc < 0 ? strerror(errno) : ""));
2056 if (rc < 0) rc = CPIOERR_CHOWN_FAILED;
2060 rc = chmod(fsm->path, (st->st_mode & 07777));
2061 if (_fsm_debug && (stage & FSM_SYSCALL))
2062 rpmMessage(RPMMESS_DEBUG, " %8s (%s, 0%04o) %s\n", cur,
2063 fsm->path, (unsigned)(st->st_mode & 07777),
2064 (rc < 0 ? strerror(errno) : ""));
2065 if (rc < 0) rc = CPIOERR_CHMOD_FAILED;
2068 { struct utimbuf stamp;
2069 stamp.actime = st->st_mtime;
2070 stamp.modtime = st->st_mtime;
2071 rc = utime(fsm->path, &stamp);
2072 if (_fsm_debug && (stage & FSM_SYSCALL))
2073 rpmMessage(RPMMESS_DEBUG, " %8s (%s, 0x%x) %s\n", cur,
2074 fsm->path, (unsigned)st->st_mtime,
2075 (rc < 0 ? strerror(errno) : ""));
2076 if (rc < 0) rc = CPIOERR_UTIME_FAILED;
2080 rc = symlink(fsm->opath, fsm->path);
2081 if (_fsm_debug && (stage & FSM_SYSCALL))
2082 rpmMessage(RPMMESS_DEBUG, " %8s (%s, %s) %s\n", cur,
2083 fsm->opath, fsm->path, (rc < 0 ? strerror(errno) : ""));
2084 if (rc < 0) rc = CPIOERR_SYMLINK_FAILED;
2087 rc = Link(fsm->opath, fsm->path);
2088 if (_fsm_debug && (stage & FSM_SYSCALL))
2089 rpmMessage(RPMMESS_DEBUG, " %8s (%s, %s) %s\n", cur,
2090 fsm->opath, fsm->path, (rc < 0 ? strerror(errno) : ""));
2091 if (rc < 0) rc = CPIOERR_LINK_FAILED;
2094 rc = mkfifo(fsm->path, (st->st_mode & 07777));
2095 if (_fsm_debug && (stage & FSM_SYSCALL))
2096 rpmMessage(RPMMESS_DEBUG, " %8s (%s, 0%04o) %s\n", cur,
2097 fsm->path, (unsigned)(st->st_mode & 07777),
2098 (rc < 0 ? strerror(errno) : ""));
2099 if (rc < 0) rc = CPIOERR_MKFIFO_FAILED;
2102 /*@-unrecog -portability @*/ /* FIX: check S_IFIFO or dev != 0 */
2103 rc = mknod(fsm->path, (st->st_mode & ~07777), st->st_rdev);
2104 /*@=unrecog =portability @*/
2105 if (_fsm_debug && (stage & FSM_SYSCALL))
2106 rpmMessage(RPMMESS_DEBUG, " %8s (%s, 0%o, 0x%x) %s\n", cur,
2107 fsm->path, (unsigned)(st->st_mode & ~07777),
2108 (unsigned)st->st_rdev,
2109 (rc < 0 ? strerror(errno) : ""));
2110 if (rc < 0) rc = CPIOERR_MKNOD_FAILED;
2113 rc = Lstat(fsm->path, ost);
2114 if (_fsm_debug && (stage & FSM_SYSCALL) && rc && errno != ENOENT)
2115 rpmMessage(RPMMESS_DEBUG, " %8s (%s, ost) %s\n", cur,
2116 fsm->path, (rc < 0 ? strerror(errno) : ""));
2117 if (rc < 0) rc = CPIOERR_LSTAT_FAILED;
2120 rc = Stat(fsm->path, ost);
2121 if (_fsm_debug && (stage & FSM_SYSCALL) && rc && errno != ENOENT)
2122 rpmMessage(RPMMESS_DEBUG, " %8s (%s, ost) %s\n", cur,
2123 fsm->path, (rc < 0 ? strerror(errno) : ""));
2124 if (rc < 0) rc = CPIOERR_STAT_FAILED;
2127 /* XXX NUL terminated result in fsm->rdbuf, len in fsm->rdnb. */
2129 rc = Readlink(fsm->path, fsm->rdbuf, fsm->rdsize - 1);
2131 if (_fsm_debug && (stage & FSM_SYSCALL))
2132 rpmMessage(RPMMESS_DEBUG, " %8s (%s, rdbuf, %d) %s\n", cur,
2133 fsm->path, (int)(fsm->rdsize -1), (rc < 0 ? strerror(errno) : ""));
2134 if (rc < 0) rc = CPIOERR_READLINK_FAILED;
2138 fsm->rdbuf[fsm->rdnb] = '\0';
2147 rc = fsmStage(fsm, FSM_HREAD);
2149 if (!strcmp(fsm->path, CPIO_TRAILER)) { /* Detect end-of-payload. */
2150 fsm->path = _free(fsm->path);
2151 rc = CPIOERR_HDR_TRAILER;
2154 rc = fsmStage(fsm, FSM_POS);
2157 for (left = st->st_size; left > 0; left -= fsm->rdnb) {
2158 fsm->wrlen = (left > fsm->wrsize ? fsm->wrsize : left);
2159 rc = fsmStage(fsm, FSM_DREAD);
2161 /*@loopbreak@*/ break;
2165 left = (modulo - (fdGetCpioPos(fsm->cfd) % modulo)) % modulo;
2168 (void) fsmStage(fsm, FSM_DREAD);
2172 left = (modulo - (fdGetCpioPos(fsm->cfd) % modulo)) % modulo;
2175 memset(fsm->rdbuf, 0, left);
2177 /* XXX DWRITE uses rdnb for I/O length. */
2179 (void) fsmStage(fsm, FSM_DWRITE);
2183 rc = cpioTrailerWrite(fsm);
2186 rc = fsmStage(fsm, FSM_POS);
2188 rc = cpioHeaderRead(fsm, st); /* Read next payload header. */
2191 rc = cpioHeaderWrite(fsm, st); /* Write next payload header. */
2195 fsm->rdnb = Fread(fsm->wrbuf, sizeof(*fsm->wrbuf), fsm->wrlen, fsm->cfd);
2197 if (_fsm_debug && (stage & FSM_SYSCALL))
2198 rpmMessage(RPMMESS_DEBUG, " %8s (%s, %d, cfd)\trdnb %d\n",
2199 cur, (fsm->wrbuf == fsm->wrb ? "wrbuf" : "mmap"),
2200 (int)fsm->wrlen, (int)fsm->rdnb);
2201 if (fsm->rdnb != fsm->wrlen || Ferror(fsm->cfd))
2202 rc = CPIOERR_READ_FAILED;
2204 fdSetCpioPos(fsm->cfd, fdGetCpioPos(fsm->cfd) + fsm->rdnb);
2207 fsm->wrnb = Fwrite(fsm->rdbuf, sizeof(*fsm->rdbuf), fsm->rdnb, fsm->cfd);
2208 if (_fsm_debug && (stage & FSM_SYSCALL))
2209 rpmMessage(RPMMESS_DEBUG, " %8s (%s, %d, cfd)\twrnb %d\n",
2210 cur, (fsm->rdbuf == fsm->rdb ? "rdbuf" : "mmap"),
2211 (int)fsm->rdnb, (int)fsm->wrnb);
2212 if (fsm->rdnb != fsm->wrnb || Ferror(fsm->cfd))
2213 rc = CPIOERR_WRITE_FAILED;
2215 fdSetCpioPos(fsm->cfd, fdGetCpioPos(fsm->cfd) + fsm->wrnb);
2219 fsm->rfd = Fopen(fsm->path, "r.ufdio");
2220 if (fsm->rfd == NULL || Ferror(fsm->rfd)) {
2221 if (fsm->rfd) (void) fsmStage(fsm, FSM_RCLOSE);
2223 rc = CPIOERR_OPEN_FAILED;
2226 if (_fsm_debug && (stage & FSM_SYSCALL))
2227 rpmMessage(RPMMESS_DEBUG, " %8s (%s, \"r\") rfd %p rdbuf %p\n", cur,
2228 fsm->path, fsm->rfd, fsm->rdbuf);
2232 fsm->rdnb = Fread(fsm->rdbuf, sizeof(*fsm->rdbuf), fsm->rdlen, fsm->rfd);
2234 if (_fsm_debug && (stage & FSM_SYSCALL))
2235 rpmMessage(RPMMESS_DEBUG, " %8s (rdbuf, %d, rfd)\trdnb %d\n",
2236 cur, (int)fsm->rdlen, (int)fsm->rdnb);
2237 if (fsm->rdnb != fsm->rdlen || Ferror(fsm->rfd))
2238 rc = CPIOERR_READ_FAILED;
2242 if (_fsm_debug && (stage & FSM_SYSCALL))
2243 rpmMessage(RPMMESS_DEBUG, " %8s (%p)\n", cur, fsm->rfd);
2244 (void) Fclose(fsm->rfd);
2252 fsm->wfd = Fopen(fsm->path, "w.ufdio");
2253 if (fsm->wfd == NULL || Ferror(fsm->wfd)) {
2254 if (fsm->wfd) (void) fsmStage(fsm, FSM_WCLOSE);
2256 rc = CPIOERR_OPEN_FAILED;
2258 if (_fsm_debug && (stage & FSM_SYSCALL))
2259 rpmMessage(RPMMESS_DEBUG, " %8s (%s, \"w\") wfd %p wrbuf %p\n", cur,
2260 fsm->path, fsm->wfd, fsm->wrbuf);
2263 fsm->wrnb = Fwrite(fsm->wrbuf, sizeof(*fsm->wrbuf), fsm->rdnb, fsm->wfd);
2264 if (_fsm_debug && (stage & FSM_SYSCALL))
2265 rpmMessage(RPMMESS_DEBUG, " %8s (wrbuf, %d, wfd)\twrnb %d\n",
2266 cur, (int)fsm->rdnb, (int)fsm->wrnb);
2267 if (fsm->rdnb != fsm->wrnb || Ferror(fsm->wfd))
2268 rc = CPIOERR_WRITE_FAILED;
2272 if (_fsm_debug && (stage & FSM_SYSCALL))
2273 rpmMessage(RPMMESS_DEBUG, " %8s (%p)\n", cur, fsm->wfd);
2274 (void) Fclose(fsm->wfd);
2287 if (!(stage & FSM_INTERNAL)) {
2288 fsm->rc = (rc == CPIOERR_HDR_TRAILER ? 0 : rc);
2295 /*@obserever@*/ const char *const fileActionString(fileAction a)
2298 case FA_UNKNOWN: return "unknown";
2299 case FA_CREATE: return "create";
2300 case FA_COPYOUT: return "copyout";
2301 case FA_COPYIN: return "copyin";
2302 case FA_BACKUP: return "backup";
2303 case FA_SAVE: return "save";
2304 case FA_SKIP: return "skip";
2305 case FA_ALTNAME: return "altname";
2306 case FA_ERASE: return "erase";
2307 case FA_SKIPNSTATE: return "skipnstate";
2308 case FA_SKIPNETSHARED: return "skipnetshared";
2309 case FA_SKIPMULTILIB: return "skipmultilib";
2310 default: return "???";
2315 /*@observer@*/ const char *const fileStageString(fileStage a) {
2317 case FSM_UNKNOWN: return "unknown";
2319 case FSM_PKGINSTALL:return "INSTALL";
2320 case FSM_PKGERASE: return "ERASE";
2321 case FSM_PKGBUILD: return "BUILD";
2322 case FSM_PKGCOMMIT: return "COMMIT";
2323 case FSM_PKGUNDO: return "UNDO";
2325 case FSM_CREATE: return "create";
2326 case FSM_INIT: return "init";
2327 case FSM_MAP: return "map";
2328 case FSM_MKDIRS: return "mkdirs";
2329 case FSM_RMDIRS: return "rmdirs";
2330 case FSM_PRE: return "pre";
2331 case FSM_PROCESS: return "process";
2332 case FSM_POST: return "post";
2333 case FSM_MKLINKS: return "mklinks";
2334 case FSM_NOTIFY: return "notify";
2335 case FSM_UNDO: return "undo";
2336 case FSM_FINI: return "fini";
2337 case FSM_COMMIT: return "commit";
2338 case FSM_DESTROY: return "destroy";
2339 case FSM_VERIFY: return "verify";
2341 case FSM_UNLINK: return "Unlink";
2342 case FSM_RENAME: return "Rename";
2343 case FSM_MKDIR: return "Mkdir";
2344 case FSM_RMDIR: return "rmdir";
2345 case FSM_CHOWN: return "chown";
2346 case FSM_LCHOWN: return "lchown";
2347 case FSM_CHMOD: return "chmod";
2348 case FSM_UTIME: return "utime";
2349 case FSM_SYMLINK: return "symlink";
2350 case FSM_LINK: return "Link";
2351 case FSM_MKFIFO: return "mkfifo";
2352 case FSM_MKNOD: return "mknod";
2353 case FSM_LSTAT: return "Lstat";
2354 case FSM_STAT: return "Stat";
2355 case FSM_READLINK: return "Readlink";
2356 case FSM_CHROOT: return "chroot";
2358 case FSM_NEXT: return "next";
2359 case FSM_EAT: return "eat";
2360 case FSM_POS: return "pos";
2361 case FSM_PAD: return "pad";
2362 case FSM_TRAILER: return "trailer";
2363 case FSM_HREAD: return "hread";
2364 case FSM_HWRITE: return "hwrite";
2365 case FSM_DREAD: return "Fread";
2366 case FSM_DWRITE: return "Fwrite";
2368 case FSM_ROPEN: return "Fopen";
2369 case FSM_READ: return "Fread";
2370 case FSM_RCLOSE: return "Fclose";
2371 case FSM_WOPEN: return "Fopen";
2372 case FSM_WRITE: return "Fwrite";
2373 case FSM_WCLOSE: return "Fclose";
2375 default: return "???";