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))
34 int _fsm_debug = _FSM_DEBUG;
36 /* XXX Failure to remove is not (yet) cause for failure. */
37 /*@-exportlocal -exportheadervar@*/
39 int strict_erasures = 0;
40 /*@=exportlocal =exportheadervar@*/
42 rpmts fsmGetTs(const FSM_t fsm) {
43 const FSMI_t iter = fsm->iter;
44 /*@-compdef -refcounttrans -retexpose -usereleased @*/
45 return (iter ? iter->ts : NULL);
46 /*@=compdef =refcounttrans =retexpose =usereleased @*/
49 rpmfi fsmGetFi(const FSM_t fsm)
51 const FSMI_t iter = fsm->iter;
52 /*@-compdef -refcounttrans -retexpose -usereleased @*/
53 return (iter ? iter->fi : NULL);
54 /*@=compdef =refcounttrans =retexpose =usereleased @*/
57 #define SUFFIX_RPMORIG ".rpmorig"
58 #define SUFFIX_RPMSAVE ".rpmsave"
59 #define SUFFIX_RPMNEW ".rpmnew"
62 * Build path to file from file info, ornamented with subdir and suffix.
63 * @param fsm file state machine data
64 * @param st file stat info
65 * @param subdir subdir to use (NULL disables)
66 * @param suffix suffix to use (NULL disables)
67 * @retval path to file
69 static /*@only@*//*@null@*/
70 const char * fsmFsPath(/*@special@*/ /*@null@*/ const FSM_t fsm,
71 /*@null@*/ const struct stat * st,
72 /*@null@*/ const char * subdir,
73 /*@null@*/ const char * suffix)
74 /*@uses fsm->dirName, fsm->baseName */
77 const char * s = NULL;
82 nb = strlen(fsm->dirName) +
83 (st && !S_ISDIR(st->st_mode) ? (subdir ? strlen(subdir) : 0) : 0) +
84 (st && !S_ISDIR(st->st_mode) ? (suffix ? strlen(suffix) : 0) : 0) +
85 strlen(fsm->baseName) + 1;
88 t = stpcpy(t, fsm->dirName);
89 if (st && !S_ISDIR(st->st_mode))
90 if (subdir) t = stpcpy(t, subdir);
91 t = stpcpy(t, fsm->baseName);
92 if (st && !S_ISDIR(st->st_mode))
93 if (suffix) t = stpcpy(t, suffix);
100 * Destroy file info iterator.
101 * @param p file info iterator
102 * @retval NULL always
104 static /*@null@*/ void * mapFreeIterator(/*@only@*//*@null@*/ void * p)
105 /*@globals fileSystem @*/
106 /*@modifies fileSystem @*/
110 iter->ts = rpmtsFree(iter->ts);
111 iter->fi = rpmfiUnlink(iter->fi, "mapIterator");
117 * Create file info iterator.
118 * @param ts transaction set
119 * @param fi transaction element file info
120 * @return file info iterator
123 mapInitIterator(rpmts ts, rpmfi fi)
124 /*@modifies ts, fi @*/
128 iter = xcalloc(1, sizeof(*iter));
129 iter->ts = rpmtsLink(ts, "mapIterator");
130 iter->fi = rpmfiLink(fi, "mapIterator");
131 iter->reverse = (rpmteType(fi->te) == TR_REMOVED && fi->action != FA_COPYOUT);
132 iter->i = (iter->reverse ? (fi->fc - 1) : 0);
133 iter->isave = iter->i;
138 * Return next index into file info.
139 * @param a file info iterator
140 * @return next index, -1 on termination
142 static int mapNextIterator(/*@null@*/ void * a)
149 const rpmfi fi = iter->fi;
151 if (iter->i >= 0) i = iter->i--;
153 if (iter->i < fi->fc) i = iter->i++;
163 static int cpioStrCmp(const void * a, const void * b)
166 const char * afn = *(const char **)a;
167 const char * bfn = *(const char **)b;
169 /* XXX Some 4+ year old rpm packages have basename only in payloads. */
170 #ifdef VERY_OLD_BUGGY_RPM_PACKAGES
171 if (strchr(afn, '/') == NULL)
172 bfn = strrchr(bfn, '/') + 1;
175 /* Match rpm-4.0 payloads with ./ prefixes. */
176 if (afn[0] == '.' && afn[1] == '/') afn += 2;
177 if (bfn[0] == '.' && bfn[1] == '/') bfn += 2;
179 /* If either path is absolute, make it relative. */
180 if (afn[0] == '/') afn += 1;
181 if (bfn[0] == '/') bfn += 1;
183 return strcmp(afn, bfn);
188 * Locate archive path in file info.
189 * @param iter file info iterator
190 * @param fsmPath archive path
191 * @return index into file info, -1 if archive path was not found
194 static int mapFind(/*@null@*/ FSMI_t iter, const char * fsmPath)
200 const rpmfi fi = iter->fi;
201 if (fi && fi->fc > 0 && fi->apath && fsmPath && *fsmPath) {
202 const char ** p = NULL;
205 if (fi->apath != NULL)
206 p = bsearch(&fsmPath, fi->apath, fi->fc, sizeof(fsmPath),
210 iter->i = p - fi->apath;
211 ix = mapNextIterator(iter);
220 * Directory name iterator.
222 typedef struct dnli_s {
224 /*@only@*/ /*@null@*/
232 * Destroy directory name iterator.
233 * @param a directory name iterator
234 * @retval NULL always
236 static /*@null@*/ void * dnlFreeIterator(/*@only@*//*@null@*/ const void * a)
240 DNLI_t dnli = (void *)a;
241 if (dnli->active) free(dnli->active);
248 static inline int dnlCount(const DNLI_t dnli)
251 return (dnli ? dnli->fi->dc : 0);
256 static inline int dnlIndex(const DNLI_t dnli)
259 return (dnli ? dnli->isave : -1);
263 * Create directory name iterator.
264 * @param fsm file state machine data
265 * @param reverse traverse directory names in reverse order?
266 * @return directory name iterator
270 static /*@only@*/ void * dnlInitIterator(/*@special@*/ const FSM_t fsm,
272 /*@uses fsm->iter @*/
275 rpmfi fi = fsmGetFi(fsm);
281 dnli = xcalloc(1, sizeof(*dnli));
283 dnli->reverse = reverse;
285 dnli->i = (reverse ? fi->dc : 0);
289 dnli->active = xcalloc(fi->dc, sizeof(*dnli->active));
291 /* Identify parent directories not skipped. */
293 for (i = 0; i < fi->fc; i++)
294 if (!XFA_SKIPPING(fi->actions[i])) dnli->active[fi->dil[i]] = 1;
297 /* Exclude parent directories that are explicitly included. */
298 for (i = 0; i < fi->fc; i++) {
299 int dil, dnlen, bnlen;
301 if (!S_ISDIR(fi->fmodes[i]))
305 dnlen = strlen(fi->dnl[dil]);
306 bnlen = strlen(fi->bnl[i]);
308 for (j = 0; j < fi->dc; j++) {
312 if (!dnli->active[j] || j == dil)
313 /*@innercontinue@*/ continue;
316 if (jlen != (dnlen+bnlen+1))
317 /*@innercontinue@*/ continue;
318 if (strncmp(dnl, fi->dnl[dil], dnlen))
319 /*@innercontinue@*/ continue;
320 if (strncmp(dnl+dnlen, fi->bnl[i], bnlen))
321 /*@innercontinue@*/ continue;
322 if (dnl[dnlen+bnlen] != '/' || dnl[dnlen+bnlen+1] != '\0')
323 /*@innercontinue@*/ continue;
324 /* This directory is included in the package. */
328 /*@innerbreak@*/ break;
332 /* Print only once per package. */
335 for (i = 0; i < fi->dc; i++) {
336 if (!dnli->active[i]) continue;
339 rpmMessage(RPMMESS_DEBUG,
340 _("========== Directories not explictly included in package:\n"));
342 rpmMessage(RPMMESS_DEBUG, _("%10d %s\n"), i, fi->dnl[i]);
345 rpmMessage(RPMMESS_DEBUG, "==========\n");
354 * Return next directory name (from file info).
355 * @param dnli directory name iterator
356 * @return next directory name
359 static /*@observer@*/ const char * dnlNextIterator(/*@null@*/ DNLI_t dnli)
362 const char * dn = NULL;
370 i = (!dnli->reverse ? dnli->i++ : --dnli->i);
371 } while (i >= 0 && i < fi->dc && !dnli->active[i]);
373 if (i >= 0 && i < fi->dc)
384 * Save hard link in chain.
385 * @param fsm file state machine data
386 * @return Is chain only partially filled?
389 static int saveHardLink(/*@special@*/ /*@partial@*/ FSM_t fsm)
390 /*@uses fsm->links, fsm->ix, fsm->sb, fsm->goal, fsm->nsuffix @*/
391 /*@defines fsm->li @*/
392 /*@releases fsm->path @*/
393 /*@globals fileSystem, internalState @*/
394 /*@modifies fsm, fileSystem, internalState @*/
396 struct stat * st = &fsm->sb;
401 /* Find hard link set. */
403 for (fsm->li = fsm->links; fsm->li; fsm->li = fsm->li->next) {
404 if (fsm->li->sb.st_ino == st->st_ino && fsm->li->sb.st_dev == st->st_dev)
409 /* New hard link encountered, add new link to set. */
412 if (fsm->li == NULL) {
413 fsm->li = xcalloc(1, sizeof(*fsm->li));
414 fsm->li->next = NULL;
415 fsm->li->sb = *st; /* structure assignment */
416 fsm->li->nlink = st->st_nlink;
417 fsm->li->linkIndex = fsm->ix;
418 fsm->li->createdPath = -1;
420 fsm->li->filex = xcalloc(st->st_nlink, sizeof(fsm->li->filex[0]));
421 memset(fsm->li->filex, -1, (st->st_nlink * sizeof(fsm->li->filex[0])));
422 fsm->li->nsuffix = xcalloc(st->st_nlink, sizeof(*fsm->li->nsuffix));
424 if (fsm->goal == FSM_PKGBUILD)
425 fsm->li->linksLeft = st->st_nlink;
426 if (fsm->goal == FSM_PKGINSTALL)
427 fsm->li->linksLeft = 0;
430 fsm->li->next = fsm->links;
432 fsm->links = fsm->li;
437 if (fsm->goal == FSM_PKGBUILD) --fsm->li->linksLeft;
439 fsm->li->filex[fsm->li->linksLeft] = fsm->ix;
440 /*@-observertrans -dependenttrans@*/
441 fsm->li->nsuffix[fsm->li->linksLeft] = fsm->nsuffix;
442 /*@=observertrans =dependenttrans@*/
444 if (fsm->goal == FSM_PKGINSTALL) fsm->li->linksLeft++;
446 if (fsm->goal == FSM_PKGBUILD)
447 return (fsm->li->linksLeft > 0);
449 if (fsm->goal != FSM_PKGINSTALL)
452 if (!(st->st_size || fsm->li->linksLeft == st->st_nlink))
455 /* Here come the bits, time to choose a non-skipped file name. */
456 { rpmfi fi = fsmGetFi(fsm);
458 for (j = fsm->li->linksLeft - 1; j >= 0; j--) {
459 ix = fsm->li->filex[j];
460 if (ix < 0 || XFA_SKIPPING(fi->actions[ix]))
466 /* Are all links skipped or not encountered yet? */
468 return 1; /* XXX W2DO? */
470 /* Save the non-skipped file name and map index. */
471 fsm->li->linkIndex = j;
472 fsm->path = _free(fsm->path);
474 rc = fsmStage(fsm, FSM_MAP);
480 * Destroy set of hard links.
481 * @param li set of hard links
482 * @return NULL always
484 static /*@null@*/ void * freeHardLink(/*@only@*/ /*@null@*/ struct hardLink_s * li)
488 li->nsuffix = _free(li->nsuffix); /* XXX elements are shared */
489 li->filex = _free(li->filex);
496 FSM_t fsm = xcalloc(1, sizeof(*fsm));
500 FSM_t freeFSM(FSM_t fsm)
503 fsm->path = _free(fsm->path);
505 while ((fsm->li = fsm->links) != NULL) {
506 fsm->links = fsm->li->next;
507 fsm->li->next = NULL;
508 fsm->li = freeHardLink(fsm->li);
511 fsm->dnlx = _free(fsm->dnlx);
512 fsm->ldn = _free(fsm->ldn);
513 fsm->iter = mapFreeIterator(fsm->iter);
518 int fsmSetup(FSM_t fsm, fileStage goal,
519 const rpmts ts, const rpmfi fi, FD_t cfd,
520 unsigned int * archiveSize, const char ** failedFile)
527 /*@-type@*/ /* FIX: cast? */
528 fsm->cfd = fdLink(cfd, "persist (fsm)");
530 pos = fdGetCpioPos(fsm->cfd);
531 fdSetCpioPos(fsm->cfd, 0);
533 fsm->iter = mapInitIterator(ts, fi);
535 if (fsm->goal == FSM_PKGINSTALL || fsm->goal == FSM_PKGBUILD) {
538 ptr = rpmtsNotify(ts, fi->te,
539 RPMCALLBACK_INST_START, fi->archivePos, fi->archiveSize);
544 fsm->archiveSize = archiveSize;
545 if (fsm->archiveSize)
546 *fsm->archiveSize = 0;
547 fsm->failedFile = failedFile;
549 *fsm->failedFile = NULL;
553 memset(fsm->sufbuf, 0, sizeof(fsm->sufbuf));
554 if (fsm->goal == FSM_PKGINSTALL) {
555 if (ts && rpmtsGetTid(ts) > 0)
556 sprintf(fsm->sufbuf, ";%08x", (unsigned)rpmtsGetTid(ts));
560 rc = fsmStage(fsm, FSM_CREATE);
561 if (rc && !ec) ec = rc;
563 rc = fsmStage(fsm, fsm->goal);
564 if (rc && !ec) ec = rc;
567 if (fsm->archiveSize && ec == 0)
568 *fsm->archiveSize = (fdGetCpioPos(fsm->cfd) - pos);
574 int fsmTeardown(FSM_t fsm)
579 rc = fsmStage(fsm, FSM_DESTROY);
581 fsm->iter = mapFreeIterator(fsm->iter);
583 /*@-type@*/ /* FIX: cast? */
584 fsm->cfd = fdFree(fsm->cfd, "persist (fsm)");
588 fsm->failedFile = NULL;
592 int fsmMapPath(FSM_t fsm)
594 rpmfi fi = fsmGetFi(fsm); /* XXX const except for fstates */
601 fsm->action = FA_UNKNOWN;
605 if (fi && i >= 0 && i < fi->fc) {
608 fsm->astriplen = fi->astriplen;
609 fsm->action = (fi->actions ? fi->actions[i] : fi->action);
610 fsm->fflags = (fi->fflags ? fi->fflags[i] : fi->flags);
611 fsm->mapFlags = (fi->fmapflags ? fi->fmapflags[i] : fi->mapflags);
613 /* src rpms have simple base name in payload. */
614 fsm->dirName = fi->dnl[fi->dil[i]];
615 fsm->baseName = fi->bnl[i];
619 switch (fsm->action) {
629 assert(rpmteType(fi->te) == TR_ADDED);
633 if (fi->fstates && rpmteType(fi->te) == TR_ADDED)
634 fi->fstates[i] = RPMFILE_STATE_NOTINSTALLED;
637 case FA_SKIPNETSHARED:
638 if (fi->fstates && rpmteType(fi->te) == TR_ADDED)
639 fi->fstates[i] = RPMFILE_STATE_NETSHARED;
643 if (fi->fstates && rpmteType(fi->te) == TR_ADDED)
644 fi->fstates[i] = RPMFILE_STATE_WRONGCOLOR;
648 if (!(fsm->fflags & RPMFILE_GHOST)) /* XXX Don't if %ghost file. */
649 switch (rpmteType(fi->te)) {
651 fsm->osuffix = SUFFIX_RPMORIG;
652 /*@innerbreak@*/ break;
654 fsm->osuffix = SUFFIX_RPMSAVE;
655 /*@innerbreak@*/ break;
660 assert(rpmteType(fi->te) == TR_ADDED);
661 if (!(fsm->fflags & RPMFILE_GHOST)) /* XXX Don't if %ghost file. */
662 fsm->nsuffix = SUFFIX_RPMNEW;
666 assert(rpmteType(fi->te) == TR_ADDED);
667 if (!(fsm->fflags & RPMFILE_GHOST)) /* XXX Don't if %ghost file. */
668 fsm->osuffix = SUFFIX_RPMSAVE;
671 #if 0 /* XXX is this a genhdlist fix? */
672 assert(rpmteType(fi->te) == TR_REMOVED);
675 * XXX TODO: %ghost probably shouldn't be removed, but that changes
676 * legacy rpm behavior.
684 if ((fsm->mapFlags & CPIO_MAP_PATH) || fsm->nsuffix) {
685 const struct stat * st = &fsm->sb;
686 fsm->path = _free(fsm->path);
687 fsm->path = fsmFsPath(fsm, st, fsm->subdir,
688 (fsm->suffix ? fsm->suffix : fsm->nsuffix));
694 int fsmMapAttrs(FSM_t fsm)
696 struct stat * st = &fsm->sb;
697 rpmfi fi = fsmGetFi(fsm);
700 if (fi && i >= 0 && i < fi->fc) {
702 (S_ISDIR(st->st_mode) ? fi->dperms : fi->fperms);
704 (fi->fmodes ? fi->fmodes[i] : perms);
706 (fi->fuids ? fi->fuids[i] : fi->uid); /* XXX chmod u-s */
708 (fi->fgids ? fi->fgids[i] : fi->gid); /* XXX chmod g-s */
710 (fi->frdevs ? fi->frdevs[i] : 0);
712 (fi->fmtimes ? fi->fmtimes[i] : 0);
714 if (fsm->mapFlags & CPIO_MAP_MODE)
715 st->st_mode = (st->st_mode & S_IFMT) | (finalMode & ~S_IFMT);
716 if (fsm->mapFlags & CPIO_MAP_TYPE) {
717 st->st_mode = (st->st_mode & ~S_IFMT) | (finalMode & S_IFMT);
718 if ((S_ISCHR(st->st_mode) || S_ISBLK(st->st_mode))
719 && st->st_nlink == 0)
721 st->st_rdev = finalRdev;
722 st->st_mtime = finalMtime;
724 if (fsm->mapFlags & CPIO_MAP_UID)
725 st->st_uid = finalUid;
726 if (fsm->mapFlags & CPIO_MAP_GID)
727 st->st_gid = finalGid;
729 { rpmts ts = fsmGetTs(fsm);
731 if (ts != NULL && !(rpmtsFlags(ts) & RPMTRANS_FLAG_NOMD5)) {
732 fsm->fmd5sum = (fi->fmd5s ? fi->fmd5s[i] : NULL);
733 fsm->md5sum = (fi->md5s ? (fi->md5s + (16 * i)) : NULL);
745 * Create file from payload stream.
746 * @param fsm file state machine data
747 * @return 0 on success
749 static int expandRegular(/*@special@*/ FSM_t fsm)
751 /*@globals fileSystem, internalState @*/
752 /*@modifies fsm, fileSystem, internalState @*/
754 const struct stat * st = &fsm->sb;
755 int left = st->st_size;
758 rc = fsmStage(fsm, FSM_WOPEN);
762 if (st->st_size > 0 && (fsm->fmd5sum || fsm->md5sum))
763 fdInitDigest(fsm->wfd, PGPHASHALGO_MD5, 0);
767 fsm->wrlen = (left > fsm->wrsize ? fsm->wrsize : left);
768 rc = fsmStage(fsm, FSM_DREAD);
772 rc = fsmStage(fsm, FSM_WRITE);
778 /* don't call this with fileSize == fileComplete */
780 (void) fsmStage(fsm, FSM_NOTIFY);
783 if (st->st_size > 0 && (fsm->fmd5sum || fsm->md5sum)) {
784 void * md5sum = NULL;
785 int asAscii = (fsm->md5sum == NULL ? 1 : 0);
787 (void) Fflush(fsm->wfd);
788 fdFiniDigest(fsm->wfd, PGPHASHALGO_MD5, &md5sum, NULL, asAscii);
790 if (md5sum == NULL) {
791 rc = CPIOERR_MD5SUM_MISMATCH;
795 if (fsm->md5sum != NULL) {
796 if (memcmp(md5sum, fsm->md5sum, 16))
797 rc = CPIOERR_MD5SUM_MISMATCH;
799 if (strcmp(md5sum, fsm->fmd5sum))
800 rc = CPIOERR_MD5SUM_MISMATCH;
802 md5sum = _free(md5sum);
806 (void) fsmStage(fsm, FSM_WCLOSE);
811 * Write next item to payload stream.
812 * @param fsm file state machine data
813 * @param writeData should data be written?
814 * @return 0 on success
816 static int writeFile(/*@special@*/ FSM_t fsm, int writeData)
817 /*@uses fsm->path, fsm->opath, fsm->sb, fsm->osb, fsm->cfd @*/
818 /*@globals fileSystem, internalState @*/
819 /*@modifies fsm, fileSystem, internalState @*/
821 const char * path = fsm->path;
822 const char * opath = fsm->opath;
823 struct stat * st = &fsm->sb;
824 struct stat * ost = &fsm->osb;
825 char * symbuf = NULL;
830 st->st_size = (writeData ? ost->st_size : 0);
833 if (S_ISDIR(st->st_mode)) {
835 } else if (S_ISLNK(st->st_mode)) {
837 * While linux puts the size of a symlink in the st_size field,
838 * I don't think that's a specified standard.
840 /* XXX NUL terminated result in fsm->rdbuf, len in fsm->rdnb. */
841 rc = fsmStage(fsm, FSM_READLINK);
843 st->st_size = fsm->rdnb;
844 symbuf = alloca_strdup(fsm->rdbuf); /* XXX save readlink return. */
848 if (fsm->mapFlags & CPIO_MAP_ABSOLUTE) {
849 /*@-compdef@*/ /* FIX: dirName/baseName annotations ? */
851 int nb = strlen(fsm->dirName) + strlen(fsm->baseName) + sizeof(".");
852 char * t = alloca(nb);
855 if (fsm->mapFlags & CPIO_MAP_ADDDOT)
857 t = stpcpy( stpcpy(t, fsm->dirName), fsm->baseName);
860 } else if (fsm->mapFlags & CPIO_MAP_PATH) {
861 rpmfi fi = fsmGetFi(fsm);
863 (fi->apath ? fi->apath[fsm->ix] + fi->striplen : fi->bnl[fsm->ix]);
866 rc = fsmStage(fsm, FSM_HWRITE);
870 if (writeData && S_ISREG(st->st_mode)) {
873 void * mapped = (void *)-1;
877 rc = fsmStage(fsm, FSM_ROPEN);
880 /* XXX unbuffered mmap generates *lots* of fdio debugging */
883 mapped = mmap(NULL, st->st_size, PROT_READ, MAP_SHARED, Fileno(fsm->rfd), 0);
884 if (mapped != (void *)-1) {
886 fsm->rdbuf = (char *) mapped;
887 fsm->rdlen = nmapped = st->st_size;
888 #if defined(MADV_DONTNEED)
889 xx = madvise(mapped, nmapped, MADV_DONTNEED);
898 if (mapped != (void *)-1) {
903 fsm->rdlen = (left > fsm->rdsize ? fsm->rdsize : left),
904 rc = fsmStage(fsm, FSM_READ);
908 /* XXX DWRITE uses rdnb for I/O length. */
909 rc = fsmStage(fsm, FSM_DWRITE);
916 if (mapped != (void *)-1) {
917 xx = msync(mapped, nmapped, MS_ASYNC);
918 #if defined(MADV_DONTNEED)
919 xx = madvise(mapped, nmapped, MADV_DONTNEED);
921 /*@-noeffect@*/ xx = munmap(mapped, nmapped) /*@=noeffect@*/;
926 } else if (writeData && S_ISLNK(st->st_mode)) {
927 /* XXX DWRITE uses rdnb for I/O length. */
929 strcpy(fsm->rdbuf, symbuf); /* XXX restore readlink buffer. */
931 fsm->rdnb = strlen(symbuf);
932 rc = fsmStage(fsm, FSM_DWRITE);
936 rc = fsmStage(fsm, FSM_PAD);
943 (void) fsmStage(fsm, FSM_RCLOSE);
944 /*@-dependenttrans@*/
947 /*@=dependenttrans@*/
952 * Write set of linked files to payload stream.
953 * @param fsm file state machine data
954 * @return 0 on success
956 static int writeLinkedFile(/*@special@*/ FSM_t fsm)
957 /*@uses fsm->path, fsm->nsuffix, fsm->ix, fsm->li, fsm->failedFile @*/
958 /*@globals fileSystem, internalState @*/
959 /*@modifies fsm, fileSystem, internalState @*/
961 const char * path = fsm->path;
962 const char * nsuffix = fsm->nsuffix;
963 int iterIndex = fsm->ix;
973 for (i = fsm->li->nlink - 1; i >= 0; i--) {
975 if (fsm->li->filex[i] < 0) continue;
977 fsm->ix = fsm->li->filex[i];
978 rc = fsmStage(fsm, FSM_MAP);
980 /* Write data after last link. */
981 rc = writeFile(fsm, (i == 0));
982 if (fsm->failedFile && rc != 0 && *fsm->failedFile == NULL) {
984 *fsm->failedFile = xstrdup(fsm->path);
987 fsm->path = _free(fsm->path);
988 fsm->li->filex[i] = -1;
993 fsm->nsuffix = nsuffix;
999 * Create pending hard links to existing file.
1000 * @param fsm file state machine data
1001 * @return 0 on success
1004 static int fsmMakeLinks(/*@special@*/ FSM_t fsm)
1005 /*@uses fsm->path, fsm->opath, fsm->nsuffix, fsm->ix, fsm->li @*/
1006 /*@globals fileSystem, internalState @*/
1007 /*@modifies fsm, fileSystem, internalState @*/
1009 const char * path = fsm->path;
1010 const char * opath = fsm->opath;
1011 const char * nsuffix = fsm->nsuffix;
1012 int iterIndex = fsm->ix;
1019 fsm->nsuffix = NULL;
1022 fsm->ix = fsm->li->filex[fsm->li->createdPath];
1023 rc = fsmStage(fsm, FSM_MAP);
1024 fsm->opath = fsm->path;
1027 for (i = 0; i < fsm->li->nlink; i++) {
1028 if (fsm->li->filex[i] < 0) continue;
1029 if (fsm->li->createdPath == i) continue;
1031 fsm->ix = fsm->li->filex[i];
1032 fsm->path = _free(fsm->path);
1033 rc = fsmStage(fsm, FSM_MAP);
1034 if (XFA_SKIPPING(fsm->action)) continue;
1036 rc = fsmStage(fsm, FSM_VERIFY);
1038 if (rc != CPIOERR_LSTAT_FAILED) break;
1040 /* XXX link(fsm->opath, fsm->path) */
1041 rc = fsmStage(fsm, FSM_LINK);
1042 if (fsm->failedFile && rc != 0 && *fsm->failedFile == NULL) {
1045 *fsm->failedFile = xstrdup(fsm->path);
1049 fsm->li->linksLeft--;
1052 fsm->path = _free(fsm->path);
1053 fsm->opath = _free(fsm->opath);
1055 fsm->ix = iterIndex;
1056 fsm->nsuffix = nsuffix;
1063 /** \ingroup payload
1064 * Commit hard linked file set atomically.
1065 * @param fsm file state machine data
1066 * @return 0 on success
1068 static int fsmCommitLinks(/*@special@*/ FSM_t fsm)
1069 /*@uses fsm->path, fsm->nsuffix, fsm->ix, fsm->sb,
1070 fsm->li, fsm->links @*/
1071 /*@globals fileSystem, internalState @*/
1072 /*@modifies fsm, fileSystem, internalState @*/
1074 const char * path = fsm->path;
1075 const char * nsuffix = fsm->nsuffix;
1076 int iterIndex = fsm->ix;
1077 struct stat * st = &fsm->sb;
1082 fsm->nsuffix = NULL;
1086 for (fsm->li = fsm->links; fsm->li; fsm->li = fsm->li->next) {
1087 if (fsm->li->sb.st_ino == st->st_ino && fsm->li->sb.st_dev == st->st_dev)
1093 for (i = 0; i < fsm->li->nlink; i++) {
1094 if (fsm->li->filex[i] < 0) continue;
1095 fsm->ix = fsm->li->filex[i];
1096 rc = fsmStage(fsm, FSM_MAP);
1097 if (!XFA_SKIPPING(fsm->action))
1098 rc = fsmStage(fsm, FSM_COMMIT);
1099 fsm->path = _free(fsm->path);
1100 fsm->li->filex[i] = -1;
1104 fsm->ix = iterIndex;
1105 fsm->nsuffix = nsuffix;
1111 * Remove (if created) directories not explicitly included in package.
1112 * @param fsm file state machine data
1113 * @return 0 on success
1115 static int fsmRmdirs(/*@special@*/ FSM_t fsm)
1116 /*@uses fsm->path, fsm->dnlx, fsm->ldn, fsm->rdbuf, fsm->iter @*/
1117 /*@globals fileSystem, internalState @*/
1118 /*@modifies fsm, fileSystem, internalState @*/
1120 const char * path = fsm->path;
1121 void * dnli = dnlInitIterator(fsm, 1);
1122 char * dn = fsm->rdbuf;
1123 int dc = dnlCount(dnli);
1129 /*@-observertrans -dependenttrans@*/
1130 if (fsm->ldn != NULL && fsm->dnlx != NULL)
1131 while ((fsm->path = dnlNextIterator(dnli)) != NULL) {
1132 int dnlen = strlen(fsm->path);
1135 dc = dnlIndex(dnli);
1136 if (fsm->dnlx[dc] < 1 || fsm->dnlx[dc] >= dnlen)
1139 /* Copy to avoid const on fsm->path. */
1140 te = stpcpy(dn, fsm->path) - 1;
1143 /* Remove generated directories. */
1144 /*@-usereleased@*/ /* LCL: te used after release? */
1148 rc = fsmStage(fsm, FSM_RMDIR);
1152 /*@innerbreak@*/ break;
1154 } while ((te - fsm->path) > fsm->dnlx[dc]);
1158 dnli = dnlFreeIterator(dnli);
1159 /*@=observertrans =dependenttrans@*/
1166 * Create (if necessary) directories not explicitly included in package.
1167 * @param fsm file state machine data
1168 * @return 0 on success
1170 static int fsmMkdirs(/*@special@*/ FSM_t fsm)
1171 /*@uses fsm->path, fsm->sb, fsm->osb, fsm->rdbuf, fsm->iter,
1172 fsm->ldn, fsm->ldnlen, fsm->ldnalloc @*/
1173 /*@defines fsm->dnlx, fsm->ldn @*/
1174 /*@globals fileSystem, internalState @*/
1175 /*@modifies fsm, fileSystem, internalState @*/
1177 struct stat * st = &fsm->sb;
1178 struct stat * ost = &fsm->osb;
1179 const char * path = fsm->path;
1180 mode_t st_mode = st->st_mode;
1181 void * dnli = dnlInitIterator(fsm, 0);
1182 char * dn = fsm->rdbuf;
1183 int dc = dnlCount(dnli);
1191 fsm->dnlx = (dc ? xcalloc(dc, sizeof(*fsm->dnlx)) : NULL);
1192 /*@-observertrans -dependenttrans@*/
1193 if (fsm->dnlx != NULL)
1194 while ((fsm->path = dnlNextIterator(dnli)) != NULL) {
1195 int dnlen = strlen(fsm->path);
1198 dc = dnlIndex(dnli);
1199 if (dc < 0) continue;
1200 fsm->dnlx[dc] = dnlen;
1204 /*@-compdef -nullpass@*/ /* FIX: fsm->ldn not defined ??? */
1205 if (dnlen <= fsm->ldnlen && !strcmp(fsm->path, fsm->ldn))
1207 /*@=compdef =nullpass@*/
1209 /* Copy to avoid const on fsm->path. */
1210 (void) stpcpy(dn, fsm->path);
1213 /* Assume '/' directory exists, "mkdir -p" for others if non-existent */
1214 for (i = 1, te = dn + 1; *te != '\0'; te++, i++) {
1216 /*@innercontinue@*/ continue;
1220 /* Already validated? */
1221 /*@-usedef -compdef -nullpass -nullderef@*/
1222 if (i < fsm->ldnlen &&
1223 (fsm->ldn[i] == '/' || fsm->ldn[i] == '\0') &&
1224 !strncmp(fsm->path, fsm->ldn, i))
1227 /* Move pre-existing path marker forward. */
1228 fsm->dnlx[dc] = (te - dn);
1229 /*@innercontinue@*/ continue;
1231 /*@=usedef =compdef =nullpass =nullderef@*/
1233 /* Validate next component of path. */
1234 rc = fsmStage(fsm, FSM_LSTAT);
1237 /* Directory already exists? */
1238 if (rc == 0 && S_ISDIR(ost->st_mode)) {
1239 /* Move pre-existing path marker forward. */
1240 fsm->dnlx[dc] = (te - dn);
1241 } else if (rc == CPIOERR_LSTAT_FAILED) {
1242 rpmfi fi = fsmGetFi(fsm);
1244 st->st_mode = S_IFDIR | (fi->dperms & 07777);
1245 rc = fsmStage(fsm, FSM_MKDIR);
1247 rpmMessage(RPMMESS_DEBUG,
1248 _("%s directory created with perms %04o.\n"),
1249 fsm->path, (unsigned)(st->st_mode & 07777));
1253 /*@innerbreak@*/ break;
1257 /* Save last validated path. */
1258 /*@-compdef@*/ /* FIX: ldn/path annotations ? */
1259 if (fsm->ldnalloc < (dnlen + 1)) {
1260 fsm->ldnalloc = dnlen + 100;
1261 fsm->ldn = xrealloc(fsm->ldn, fsm->ldnalloc);
1263 if (fsm->ldn != NULL) { /* XXX can't happen */
1264 strcpy(fsm->ldn, fsm->path);
1265 fsm->ldnlen = dnlen;
1270 dnli = dnlFreeIterator(dnli);
1271 /*@=observertrans =dependenttrans@*/
1274 st->st_mode = st_mode; /* XXX restore st->st_mode */
1275 /*@-compdef@*/ /* FIX: ldn/path annotations ? */
1282 * Check for file on disk.
1283 * @param fsm file state machine data
1284 * @return 0 on success
1286 static int fsmStat(FSM_t fsm)
1288 int saveerrno = errno;
1291 if (fsm->path != NULL) {
1292 int saveernno = errno;
1293 rc = fsmStage(fsm, (!(fsm->mapFlags & CPIO_FOLLOW_SYMLINKS)
1294 ? FSM_LSTAT : FSM_STAT));
1295 if (rc == CPIOERR_LSTAT_FAILED && errno == ENOENT) {
1299 } else if (rc == 0) {
1303 /* Skip %ghost files on build. */
1310 #define IS_DEV_LOG(_x) \
1311 ((_x) != NULL && strlen(_x) >= (sizeof("/dev/log")-1) && \
1312 !strncmp((_x), "/dev/log", sizeof("/dev/log")-1) && \
1313 ((_x)[sizeof("/dev/log")-1] == '\0' || \
1314 (_x)[sizeof("/dev/log")-1] == ';'))
1318 int fsmStage(FSM_t fsm, fileStage stage)
1321 fileStage prevStage = fsm->stage;
1322 const char * const prev = fileStageString(prevStage);
1324 static int modulo = 4;
1325 const char * const cur = fileStageString(stage);
1326 struct stat * st = &fsm->sb;
1327 struct stat * ost = &fsm->osb;
1328 int saveerrno = errno;
1333 #define _fafilter(_a) \
1334 (!((_a) == FA_CREATE || (_a) == FA_ERASE || (_a) == FA_COPYIN || (_a) == FA_COPYOUT) \
1335 ? fileActionString(_a) : "")
1337 if (stage & FSM_DEAD) {
1339 } else if (stage & FSM_INTERNAL) {
1340 if (_fsm_debug && !(stage & FSM_SYSCALL))
1341 rpmMessage(RPMMESS_DEBUG, " %8s %06o%3d (%4d,%4d)%10d %s %s\n",
1343 (unsigned)st->st_mode, (int)st->st_nlink,
1344 (int)st->st_uid, (int)st->st_gid, (int)st->st_size,
1345 (fsm->path ? fsm->path : ""),
1346 _fafilter(fsm->action));
1349 if (_fsm_debug || !(stage & FSM_VERBOSE))
1350 rpmMessage(RPMMESS_DEBUG, "%-8s %06o%3d (%4d,%4d)%10d %s %s\n",
1352 (unsigned)st->st_mode, (int)st->st_nlink,
1353 (int)st->st_uid, (int)st->st_gid, (int)st->st_size,
1354 (fsm->path ? fsm->path + fsm->astriplen : ""),
1355 _fafilter(fsm->action));
1363 case FSM_PKGINSTALL:
1365 /* Clean fsm, free'ing memory. Read next archive header. */
1366 rc = fsmStage(fsm, FSM_INIT);
1368 /* Exit on end-of-payload. */
1369 if (rc == CPIOERR_HDR_TRAILER) {
1371 /*@loopbreak@*/ break;
1374 /* Exit on error. */
1377 (void) fsmStage(fsm, FSM_UNDO);
1378 /*@loopbreak@*/ break;
1381 /* Extract file from archive. */
1382 rc = fsmStage(fsm, FSM_PROCESS);
1384 (void) fsmStage(fsm, FSM_UNDO);
1385 /*@loopbreak@*/ break;
1388 /* Notify on success. */
1389 (void) fsmStage(fsm, FSM_NOTIFY);
1391 rc = fsmStage(fsm, FSM_FINI);
1393 /*@loopbreak@*/ break;
1400 /* Clean fsm, free'ing memory. */
1401 rc = fsmStage(fsm, FSM_INIT);
1403 /* Exit on end-of-payload. */
1404 if (rc == CPIOERR_HDR_TRAILER) {
1406 /*@loopbreak@*/ break;
1409 /* Rename/erase next item. */
1410 if (fsmStage(fsm, FSM_FINI))
1411 /*@loopbreak@*/ break;
1417 rc = fsmStage(fsm, FSM_INIT);
1419 /* Exit on end-of-payload. */
1420 if (rc == CPIOERR_HDR_TRAILER) {
1422 /*@loopbreak@*/ break;
1425 /* Exit on error. */
1428 (void) fsmStage(fsm, FSM_UNDO);
1429 /*@loopbreak@*/ break;
1432 /* Copy file into archive. */
1433 rc = fsmStage(fsm, FSM_PROCESS);
1435 (void) fsmStage(fsm, FSM_UNDO);
1436 /*@loopbreak@*/ break;
1439 /* Notify on success. */
1440 (void) fsmStage(fsm, FSM_NOTIFY);
1442 if (fsmStage(fsm, FSM_FINI))
1443 /*@loopbreak@*/ break;
1446 /* Flush partial sets of hard linked files. */
1447 if (!(fsm->mapFlags & CPIO_ALL_HARDLINKS)) {
1449 while ((fsm->li = fsm->links) != NULL) {
1450 fsm->links = fsm->li->next;
1451 fsm->li->next = NULL;
1453 /* Re-calculate link count for archive header. */
1454 for (j = -1, nlink = 0, i = 0; i < fsm->li->nlink; i++) {
1455 if (fsm->li->filex[i] < 0)
1456 /*@innercontinue@*/ continue;
1460 /* XXX force the contents out as well. */
1463 fsm->li->filex[0] = fsm->li->filex[j];
1464 fsm->li->filex[j] = -1;
1467 fsm->li->sb.st_nlink = nlink;
1469 fsm->sb = fsm->li->sb; /* structure assignment */
1470 fsm->osb = fsm->sb; /* structure assignment */
1472 if (!rc) rc = writeLinkedFile(fsm);
1474 fsm->li = freeHardLink(fsm->li);
1479 rc = fsmStage(fsm, FSM_TRAILER);
1483 { rpmts ts = fsmGetTs(fsm);
1484 #define _tsmask (RPMTRANS_FLAG_PKGCOMMIT | RPMTRANS_FLAG_COMMIT)
1485 fsm->commit = ((ts && (rpmtsFlags(ts) & _tsmask) &&
1486 fsm->goal != FSM_PKGCOMMIT) ? 0 : 1);
1489 fsm->path = _free(fsm->path);
1490 fsm->opath = _free(fsm->opath);
1491 fsm->dnlx = _free(fsm->dnlx);
1493 fsm->ldn = _free(fsm->ldn);
1494 fsm->ldnalloc = fsm->ldnlen = 0;
1496 fsm->rdsize = fsm->wrsize = 0;
1497 fsm->rdbuf = fsm->rdb = _free(fsm->rdb);
1498 fsm->wrbuf = fsm->wrb = _free(fsm->wrb);
1499 if (fsm->goal == FSM_PKGINSTALL || fsm->goal == FSM_PKGBUILD) {
1500 fsm->rdsize = 8 * BUFSIZ;
1501 fsm->rdbuf = fsm->rdb = xmalloc(fsm->rdsize);
1502 fsm->wrsize = 8 * BUFSIZ;
1503 fsm->wrbuf = fsm->wrb = xmalloc(fsm->wrsize);
1506 fsm->mkdirsdone = 0;
1511 errno = 0; /* XXX get rid of EBADF */
1514 /* Detect and create directories not explicitly in package. */
1515 if (fsm->goal == FSM_PKGINSTALL) {
1516 rc = fsmStage(fsm, FSM_MKDIRS);
1517 if (!rc) fsm->mkdirsdone = 1;
1522 fsm->path = _free(fsm->path);
1524 fsm->diskchecked = fsm->exists = 0;
1526 fsm->suffix = (fsm->sufbuf[0] != '\0' ? fsm->sufbuf : NULL);
1527 fsm->action = FA_UNKNOWN;
1528 fsm->osuffix = NULL;
1529 fsm->nsuffix = NULL;
1531 if (fsm->goal == FSM_PKGINSTALL) {
1532 /* Read next header from payload, checking for end-of-payload. */
1533 rc = fsmStage(fsm, FSM_NEXT);
1537 /* Identify mapping index. */
1538 fsm->ix = ((fsm->goal == FSM_PKGINSTALL)
1539 ? mapFind(fsm->iter, fsm->path) : mapNextIterator(fsm->iter));
1541 /* Detect end-of-loop and/or mapping error. */
1543 if (fsm->goal == FSM_PKGINSTALL) {
1545 rpmMessage(RPMMESS_WARNING,
1546 _("archive file %s was not found in header file list\n"),
1550 if (fsm->failedFile && *fsm->failedFile == NULL)
1551 *fsm->failedFile = xstrdup(fsm->path);
1553 rc = CPIOERR_UNMAPPED_FILE;
1555 rc = CPIOERR_HDR_TRAILER;
1560 /* On non-install, mode must be known so that dirs don't get suffix. */
1561 if (fsm->goal != FSM_PKGINSTALL) {
1562 rpmfi fi = fsmGetFi(fsm);
1563 st->st_mode = fi->fmodes[fsm->ix];
1566 /* Generate file path. */
1567 rc = fsmStage(fsm, FSM_MAP);
1570 /* Perform lstat/stat for disk file. */
1574 if (fsm->path != NULL &&
1575 !(fsm->goal == FSM_PKGINSTALL && S_ISREG(st->st_mode)))
1577 rc = fsmStage(fsm, (!(fsm->mapFlags & CPIO_FOLLOW_SYMLINKS)
1578 ? FSM_LSTAT : FSM_STAT));
1579 if (rc == CPIOERR_LSTAT_FAILED && errno == ENOENT) {
1585 } else if (rc == 0) {
1589 /* Skip %ghost files on build. */
1593 fsm->diskchecked = 1;
1596 /* On non-install, the disk file stat is what's remapped. */
1598 if (fsm->goal != FSM_PKGINSTALL)
1599 *st = *ost; /* structure assignment */
1602 /* Remap file perms, owner, and group. */
1603 rc = fsmMapAttrs(fsm);
1606 fsm->postpone = XFA_SKIPPING(fsm->action);
1607 if (fsm->goal == FSM_PKGINSTALL || fsm->goal == FSM_PKGBUILD) {
1608 /*@-evalorder@*/ /* FIX: saveHardLink can modify fsm */
1609 if (!S_ISDIR(st->st_mode) && st->st_nlink > 1)
1610 fsm->postpone = saveHardLink(fsm);
1617 rc = fsmMapPath(fsm);
1620 rc = fsmMkdirs(fsm);
1624 rc = fsmRmdirs(fsm);
1627 if (fsm->postpone) {
1628 if (fsm->goal == FSM_PKGINSTALL)
1629 rc = fsmStage(fsm, FSM_EAT);
1633 if (fsm->goal == FSM_PKGBUILD) {
1634 if (fsm->fflags & RPMFILE_GHOST) /* XXX Don't if %ghost file. */
1636 if (!S_ISDIR(st->st_mode) && st->st_nlink > 1) {
1637 struct hardLink_s * li, * prev;
1639 if (!(fsm->mapFlags & CPIO_ALL_HARDLINKS)) break;
1640 rc = writeLinkedFile(fsm);
1641 if (rc) break; /* W2DO? */
1643 for (li = fsm->links, prev = NULL; li; prev = li, li = li->next)
1645 /*@loopbreak@*/ break;
1648 fsm->links = fsm->li->next;
1650 prev->next = fsm->li->next;
1651 fsm->li->next = NULL;
1652 fsm->li = freeHardLink(fsm->li);
1654 rc = writeFile(fsm, 1);
1659 if (fsm->goal != FSM_PKGINSTALL)
1662 if (S_ISREG(st->st_mode)) {
1663 const char * path = fsm->path;
1665 fsm->path = fsmFsPath(fsm, st, NULL, NULL);
1666 rc = fsmStage(fsm, FSM_VERIFY);
1668 if (rc == 0 && fsm->osuffix) {
1669 const char * opath = fsm->opath;
1670 fsm->opath = fsm->path;
1671 fsm->path = fsmFsPath(fsm, st, NULL, fsm->osuffix);
1672 rc = fsmStage(fsm, FSM_RENAME);
1674 rpmMessage(RPMMESS_WARNING,
1675 _("%s saved as %s\n"), fsm->opath, fsm->path);
1676 fsm->path = _free(fsm->path);
1680 /*@-dependenttrans@*/
1682 /*@=dependenttrans@*/
1683 if (rc != CPIOERR_LSTAT_FAILED) return rc;
1684 rc = expandRegular(fsm);
1685 } else if (S_ISDIR(st->st_mode)) {
1686 mode_t st_mode = st->st_mode;
1687 rc = fsmStage(fsm, FSM_VERIFY);
1688 if (rc == CPIOERR_LSTAT_FAILED) {
1689 st->st_mode &= ~07777; /* XXX abuse st->st_mode */
1690 st->st_mode |= 00700;
1691 rc = fsmStage(fsm, FSM_MKDIR);
1692 st->st_mode = st_mode; /* XXX restore st->st_mode */
1694 } else if (S_ISLNK(st->st_mode)) {
1695 const char * opath = fsm->opath;
1697 if ((st->st_size + 1) > fsm->rdsize) {
1698 rc = CPIOERR_HDR_SIZE;
1702 fsm->wrlen = st->st_size;
1703 rc = fsmStage(fsm, FSM_DREAD);
1704 if (!rc && fsm->rdnb != fsm->wrlen)
1705 rc = CPIOERR_READ_FAILED;
1709 fsm->wrbuf[st->st_size] = '\0';
1711 /* XXX symlink(fsm->opath, fsm->path) */
1712 /*@-dependenttrans@*/
1713 fsm->opath = fsm->wrbuf;
1714 /*@=dependenttrans@*/
1715 rc = fsmStage(fsm, FSM_VERIFY);
1716 if (rc == CPIOERR_LSTAT_FAILED)
1717 rc = fsmStage(fsm, FSM_SYMLINK);
1718 fsm->opath = opath; /* XXX restore fsm->path */
1719 } else if (S_ISFIFO(st->st_mode)) {
1720 mode_t st_mode = st->st_mode;
1721 /* This mimics cpio S_ISSOCK() behavior but probably isnt' right */
1722 rc = fsmStage(fsm, FSM_VERIFY);
1723 if (rc == CPIOERR_LSTAT_FAILED) {
1724 st->st_mode = 0000; /* XXX abuse st->st_mode */
1725 rc = fsmStage(fsm, FSM_MKFIFO);
1726 st->st_mode = st_mode; /* XXX restore st->st_mode */
1728 } else if (S_ISCHR(st->st_mode) ||
1729 S_ISBLK(st->st_mode) ||
1730 /*@-unrecog@*/ S_ISSOCK(st->st_mode) /*@=unrecog@*/)
1732 rc = fsmStage(fsm, FSM_VERIFY);
1733 if (rc == CPIOERR_LSTAT_FAILED)
1734 rc = fsmStage(fsm, FSM_MKNOD);
1736 /* XXX Special case /dev/log, which shouldn't be packaged anyways */
1737 if (!IS_DEV_LOG(fsm->path))
1738 rc = CPIOERR_UNKNOWN_FILETYPE;
1740 if (!S_ISDIR(st->st_mode) && st->st_nlink > 1) {
1741 fsm->li->createdPath = fsm->li->linkIndex;
1742 rc = fsmMakeLinks(fsm);
1748 rc = fsmMakeLinks(fsm);
1750 case FSM_NOTIFY: /* XXX move from fsm to psm -> tsm */
1751 if (fsm->goal == FSM_PKGINSTALL || fsm->goal == FSM_PKGBUILD) {
1752 rpmts ts = fsmGetTs(fsm);
1753 rpmfi fi = fsmGetFi(fsm);
1755 unsigned int archivePos = fdGetCpioPos(fsm->cfd);
1756 if (archivePos > fi->archivePos) {
1757 fi->archivePos = archivePos;
1758 ptr = rpmtsNotify(ts, fi->te, RPMCALLBACK_INST_PROGRESS,
1759 fi->archivePos, fi->archiveSize);
1766 if (fsm->goal == FSM_PKGINSTALL) {
1767 (void) fsmStage(fsm,
1768 (S_ISDIR(st->st_mode) ? FSM_RMDIR : FSM_UNLINK));
1770 #ifdef NOTYET /* XXX remove only dirs just created, not all. */
1772 (void) fsmStage(fsm, FSM_RMDIRS);
1779 if (fsm->failedFile && *fsm->failedFile == NULL)
1780 *fsm->failedFile = xstrdup(fsm->path);
1784 if (!fsm->postpone && fsm->commit) {
1785 if (fsm->goal == FSM_PKGINSTALL)
1786 rc = ((!S_ISDIR(st->st_mode) && st->st_nlink > 1)
1787 ? fsmCommitLinks(fsm) : fsmStage(fsm, FSM_COMMIT));
1788 if (fsm->goal == FSM_PKGCOMMIT)
1789 rc = fsmStage(fsm, FSM_COMMIT);
1790 if (fsm->goal == FSM_PKGERASE)
1791 rc = fsmStage(fsm, FSM_COMMIT);
1793 fsm->path = _free(fsm->path);
1794 fsm->opath = _free(fsm->opath);
1796 memset(st, 0, sizeof(*st));
1797 memset(ost, 0, sizeof(*ost));
1801 /* Rename pre-existing modified or unmanaged file. */
1802 if (fsm->osuffix && fsm->diskchecked &&
1803 (fsm->exists || (fsm->goal == FSM_PKGINSTALL && S_ISREG(st->st_mode))))
1805 const char * opath = fsm->opath;
1806 const char * path = fsm->path;
1807 fsm->opath = fsmFsPath(fsm, st, NULL, NULL);
1808 fsm->path = fsmFsPath(fsm, st, NULL, fsm->osuffix);
1809 rc = fsmStage(fsm, FSM_RENAME);
1811 rpmMessage(RPMMESS_WARNING, _("%s saved as %s\n"),
1812 fsm->opath, fsm->path);
1814 fsm->path = _free(fsm->path);
1816 fsm->opath = _free(fsm->opath);
1820 /* Remove erased files. */
1821 if (fsm->goal == FSM_PKGERASE) {
1822 if (fsm->action == FA_ERASE) {
1823 rpmfi fi = fsmGetFi(fsm);
1824 if (S_ISDIR(st->st_mode)) {
1825 rc = fsmStage(fsm, FSM_RMDIR);
1828 case ENOENT: /* XXX rmdir("/") linux 2.2.x kernel hack */
1830 /* XXX make sure that build side permits %missingok on directories. */
1831 if (fsm->fflags & RPMFILE_MISSINGOK)
1832 /*@innerbreak@*/ break;
1834 /* XXX common error message. */
1836 (strict_erasures ? RPMERR_RMDIR : RPMDEBUG_RMDIR),
1837 _("%s rmdir of %s failed: Directory not empty\n"),
1838 rpmfiTypeString(fi), fsm->path);
1839 /*@innerbreak@*/ break;
1842 (strict_erasures ? RPMERR_RMDIR : RPMDEBUG_RMDIR),
1843 _("%s rmdir of %s failed: %s\n"),
1844 rpmfiTypeString(fi), fsm->path, strerror(errno));
1845 /*@innerbreak@*/ break;
1848 rc = fsmStage(fsm, FSM_UNLINK);
1850 if (!(errno == ENOENT && (fsm->fflags & RPMFILE_MISSINGOK)))
1852 (strict_erasures ? RPMERR_UNLINK : RPMDEBUG_UNLINK),
1853 _("%s unlink of %s failed: %s\n"),
1854 rpmfiTypeString(fi), fsm->path, strerror(errno));
1857 /* XXX Failure to remove is not (yet) cause for failure. */
1858 if (!strict_erasures) rc = 0;
1862 /* XXX Special case /dev/log, which shouldn't be packaged anyways */
1863 if (!S_ISSOCK(st->st_mode) && !IS_DEV_LOG(fsm->path)) {
1864 /* Rename temporary to final file name. */
1865 if (!S_ISDIR(st->st_mode) &&
1866 (fsm->subdir || fsm->suffix || fsm->nsuffix))
1868 fsm->opath = fsm->path;
1869 fsm->path = fsmFsPath(fsm, st, NULL, fsm->nsuffix);
1870 rc = fsmStage(fsm, FSM_RENAME);
1871 if (!rc && fsm->nsuffix) {
1872 const char * opath = fsmFsPath(fsm, st, NULL, NULL);
1873 rpmMessage(RPMMESS_WARNING, _("%s created as %s\n"),
1874 (opath ? opath : ""), fsm->path);
1875 opath = _free(opath);
1877 fsm->opath = _free(fsm->opath);
1879 if (S_ISLNK(st->st_mode)) {
1880 if (!rc && !getuid())
1881 rc = fsmStage(fsm, FSM_LCHOWN);
1883 if (!rc && !getuid())
1884 rc = fsmStage(fsm, FSM_CHOWN);
1886 rc = fsmStage(fsm, FSM_CHMOD);
1888 time_t mtime = st->st_mtime;
1889 rpmfi fi = fsmGetFi(fsm);
1891 st->st_mtime = fi->fmtimes[fsm->ix];
1892 rc = fsmStage(fsm, FSM_UTIME);
1893 st->st_mtime = mtime;
1898 /* Notify on success. */
1899 if (!rc) rc = fsmStage(fsm, FSM_NOTIFY);
1900 else if (fsm->failedFile && *fsm->failedFile == NULL) {
1902 *fsm->failedFile = fsm->path;
1908 fsm->path = _free(fsm->path);
1910 /* Check for hard links missing from payload. */
1911 while ((fsm->li = fsm->links) != NULL) {
1912 fsm->links = fsm->li->next;
1913 fsm->li->next = NULL;
1914 if (fsm->goal == FSM_PKGINSTALL &&
1915 fsm->commit && fsm->li->linksLeft)
1917 for (i = 0 ; i < fsm->li->linksLeft; i++) {
1918 if (fsm->li->filex[i] < 0)
1919 /*@innercontinue@*/ continue;
1920 rc = CPIOERR_MISSING_HARDLINK;
1921 if (fsm->failedFile && *fsm->failedFile == NULL) {
1922 fsm->ix = fsm->li->filex[i];
1923 if (!fsmStage(fsm, FSM_MAP)) {
1925 *fsm->failedFile = fsm->path;
1930 /*@loopbreak@*/ break;
1933 if (fsm->goal == FSM_PKGBUILD &&
1934 (fsm->mapFlags & CPIO_ALL_HARDLINKS))
1936 rc = CPIOERR_MISSING_HARDLINK;
1938 fsm->li = freeHardLink(fsm->li);
1940 fsm->ldn = _free(fsm->ldn);
1941 fsm->ldnalloc = fsm->ldnlen = 0;
1942 fsm->rdbuf = fsm->rdb = _free(fsm->rdb);
1943 fsm->wrbuf = fsm->wrb = _free(fsm->wrb);
1946 if (fsm->diskchecked && !fsm->exists) {
1947 rc = CPIOERR_LSTAT_FAILED;
1950 if (S_ISREG(st->st_mode)) {
1951 char * path = alloca(strlen(fsm->path) + sizeof("-RPMDELETE"));
1953 (void) stpcpy( stpcpy(path, fsm->path), "-RPMDELETE");
1956 * XXX HP-UX (and other os'es) don't permit unlink on busy
1959 fsm->opath = fsm->path;
1961 rc = fsmStage(fsm, FSM_RENAME);
1963 (void) fsmStage(fsm, FSM_UNLINK);
1965 rc = CPIOERR_UNLINK_FAILED;
1966 fsm->path = fsm->opath;
1968 return (rc ? rc : CPIOERR_LSTAT_FAILED); /* XXX HACK */
1969 /*@notreached@*/ break;
1970 } else if (S_ISDIR(st->st_mode)) {
1971 if (S_ISDIR(ost->st_mode)) return 0;
1972 if (S_ISLNK(ost->st_mode)) {
1973 rc = fsmStage(fsm, FSM_STAT);
1974 if (rc == CPIOERR_STAT_FAILED && errno == ENOENT) rc = 0;
1979 if (S_ISDIR(ost->st_mode)) return 0;
1981 } else if (S_ISLNK(st->st_mode)) {
1982 if (S_ISLNK(ost->st_mode)) {
1983 /* XXX NUL terminated result in fsm->rdbuf, len in fsm->rdnb. */
1984 rc = fsmStage(fsm, FSM_READLINK);
1989 if (!strcmp(fsm->opath, fsm->rdbuf)) return 0;
1991 } else if (S_ISFIFO(st->st_mode)) {
1992 if (S_ISFIFO(ost->st_mode)) return 0;
1993 } else if (S_ISCHR(st->st_mode) || S_ISBLK(st->st_mode)) {
1994 if ((S_ISCHR(ost->st_mode) || S_ISBLK(ost->st_mode)) &&
1995 (ost->st_rdev == st->st_rdev)) return 0;
1996 } else if (S_ISSOCK(st->st_mode)) {
1997 if (S_ISSOCK(ost->st_mode)) return 0;
1999 /* XXX shouldn't do this with commit/undo. */
2001 if (fsm->stage == FSM_PROCESS) rc = fsmStage(fsm, FSM_UNLINK);
2002 if (rc == 0) rc = CPIOERR_LSTAT_FAILED;
2003 return (rc ? rc : CPIOERR_LSTAT_FAILED); /* XXX HACK */
2004 /*@notreached@*/ break;
2007 rc = Unlink(fsm->path);
2008 if (_fsm_debug && (stage & FSM_SYSCALL))
2009 rpmMessage(RPMMESS_DEBUG, " %8s (%s) %s\n", cur,
2010 fsm->path, (rc < 0 ? strerror(errno) : ""));
2011 if (rc < 0) rc = CPIOERR_UNLINK_FAILED;
2014 rc = Rename(fsm->opath, fsm->path);
2015 #if defined(ETXTBSY)
2016 if (rc && errno == ETXTBSY) {
2017 char * path = alloca(strlen(fsm->path) + sizeof("-RPMDELETE"));
2018 (void) stpcpy( stpcpy(path, fsm->path), "-RPMDELETE");
2020 * XXX HP-UX (and other os'es) don't permit rename to busy
2023 rc = Rename(fsm->path, path);
2024 if (!rc) rc = Rename(fsm->opath, fsm->path);
2027 if (_fsm_debug && (stage & FSM_SYSCALL))
2028 rpmMessage(RPMMESS_DEBUG, " %8s (%s, %s) %s\n", cur,
2029 fsm->opath, fsm->path, (rc < 0 ? strerror(errno) : ""));
2030 if (rc < 0) rc = CPIOERR_RENAME_FAILED;
2033 rc = Mkdir(fsm->path, (st->st_mode & 07777));
2034 if (_fsm_debug && (stage & FSM_SYSCALL))
2035 rpmMessage(RPMMESS_DEBUG, " %8s (%s, 0%04o) %s\n", cur,
2036 fsm->path, (unsigned)(st->st_mode & 07777),
2037 (rc < 0 ? strerror(errno) : ""));
2038 if (rc < 0) rc = CPIOERR_MKDIR_FAILED;
2041 rc = Rmdir(fsm->path);
2042 if (_fsm_debug && (stage & FSM_SYSCALL))
2043 rpmMessage(RPMMESS_DEBUG, " %8s (%s) %s\n", cur,
2044 fsm->path, (rc < 0 ? strerror(errno) : ""));
2045 if (rc < 0) rc = CPIOERR_RMDIR_FAILED;
2048 rc = chown(fsm->path, st->st_uid, st->st_gid);
2049 if (_fsm_debug && (stage & FSM_SYSCALL))
2050 rpmMessage(RPMMESS_DEBUG, " %8s (%s, %d, %d) %s\n", cur,
2051 fsm->path, (int)st->st_uid, (int)st->st_gid,
2052 (rc < 0 ? strerror(errno) : ""));
2053 if (rc < 0) rc = CPIOERR_CHOWN_FAILED;
2056 #if ! CHOWN_FOLLOWS_SYMLINK
2057 rc = lchown(fsm->path, st->st_uid, st->st_gid);
2058 if (_fsm_debug && (stage & FSM_SYSCALL))
2059 rpmMessage(RPMMESS_DEBUG, " %8s (%s, %d, %d) %s\n", cur,
2060 fsm->path, (int)st->st_uid, (int)st->st_gid,
2061 (rc < 0 ? strerror(errno) : ""));
2062 if (rc < 0) rc = CPIOERR_CHOWN_FAILED;
2066 rc = chmod(fsm->path, (st->st_mode & 07777));
2067 if (_fsm_debug && (stage & FSM_SYSCALL))
2068 rpmMessage(RPMMESS_DEBUG, " %8s (%s, 0%04o) %s\n", cur,
2069 fsm->path, (unsigned)(st->st_mode & 07777),
2070 (rc < 0 ? strerror(errno) : ""));
2071 if (rc < 0) rc = CPIOERR_CHMOD_FAILED;
2074 { struct utimbuf stamp;
2075 stamp.actime = st->st_mtime;
2076 stamp.modtime = st->st_mtime;
2077 rc = utime(fsm->path, &stamp);
2078 if (_fsm_debug && (stage & FSM_SYSCALL))
2079 rpmMessage(RPMMESS_DEBUG, " %8s (%s, 0x%x) %s\n", cur,
2080 fsm->path, (unsigned)st->st_mtime,
2081 (rc < 0 ? strerror(errno) : ""));
2082 if (rc < 0) rc = CPIOERR_UTIME_FAILED;
2086 rc = symlink(fsm->opath, fsm->path);
2087 if (_fsm_debug && (stage & FSM_SYSCALL))
2088 rpmMessage(RPMMESS_DEBUG, " %8s (%s, %s) %s\n", cur,
2089 fsm->opath, fsm->path, (rc < 0 ? strerror(errno) : ""));
2090 if (rc < 0) rc = CPIOERR_SYMLINK_FAILED;
2093 rc = Link(fsm->opath, fsm->path);
2094 if (_fsm_debug && (stage & FSM_SYSCALL))
2095 rpmMessage(RPMMESS_DEBUG, " %8s (%s, %s) %s\n", cur,
2096 fsm->opath, fsm->path, (rc < 0 ? strerror(errno) : ""));
2097 if (rc < 0) rc = CPIOERR_LINK_FAILED;
2100 rc = mkfifo(fsm->path, (st->st_mode & 07777));
2101 if (_fsm_debug && (stage & FSM_SYSCALL))
2102 rpmMessage(RPMMESS_DEBUG, " %8s (%s, 0%04o) %s\n", cur,
2103 fsm->path, (unsigned)(st->st_mode & 07777),
2104 (rc < 0 ? strerror(errno) : ""));
2105 if (rc < 0) rc = CPIOERR_MKFIFO_FAILED;
2108 /*@-unrecog -portability @*/ /* FIX: check S_IFIFO or dev != 0 */
2109 rc = mknod(fsm->path, (st->st_mode & ~07777), st->st_rdev);
2110 /*@=unrecog =portability @*/
2111 if (_fsm_debug && (stage & FSM_SYSCALL))
2112 rpmMessage(RPMMESS_DEBUG, " %8s (%s, 0%o, 0x%x) %s\n", cur,
2113 fsm->path, (unsigned)(st->st_mode & ~07777),
2114 (unsigned)st->st_rdev,
2115 (rc < 0 ? strerror(errno) : ""));
2116 if (rc < 0) rc = CPIOERR_MKNOD_FAILED;
2119 rc = Lstat(fsm->path, ost);
2120 if (_fsm_debug && (stage & FSM_SYSCALL) && rc && errno != ENOENT)
2121 rpmMessage(RPMMESS_DEBUG, " %8s (%s, ost) %s\n", cur,
2122 fsm->path, (rc < 0 ? strerror(errno) : ""));
2123 if (rc < 0) rc = CPIOERR_LSTAT_FAILED;
2126 rc = Stat(fsm->path, ost);
2127 if (_fsm_debug && (stage & FSM_SYSCALL) && rc && errno != ENOENT)
2128 rpmMessage(RPMMESS_DEBUG, " %8s (%s, ost) %s\n", cur,
2129 fsm->path, (rc < 0 ? strerror(errno) : ""));
2130 if (rc < 0) rc = CPIOERR_STAT_FAILED;
2133 /* XXX NUL terminated result in fsm->rdbuf, len in fsm->rdnb. */
2135 rc = Readlink(fsm->path, fsm->rdbuf, fsm->rdsize - 1);
2137 if (_fsm_debug && (stage & FSM_SYSCALL))
2138 rpmMessage(RPMMESS_DEBUG, " %8s (%s, rdbuf, %d) %s\n", cur,
2139 fsm->path, (int)(fsm->rdsize -1), (rc < 0 ? strerror(errno) : ""));
2140 if (rc < 0) rc = CPIOERR_READLINK_FAILED;
2144 fsm->rdbuf[fsm->rdnb] = '\0';
2153 rc = fsmStage(fsm, FSM_HREAD);
2155 if (!strcmp(fsm->path, CPIO_TRAILER)) { /* Detect end-of-payload. */
2156 fsm->path = _free(fsm->path);
2157 rc = CPIOERR_HDR_TRAILER;
2160 rc = fsmStage(fsm, FSM_POS);
2163 for (left = st->st_size; left > 0; left -= fsm->rdnb) {
2164 fsm->wrlen = (left > fsm->wrsize ? fsm->wrsize : left);
2165 rc = fsmStage(fsm, FSM_DREAD);
2167 /*@loopbreak@*/ break;
2171 left = (modulo - (fdGetCpioPos(fsm->cfd) % modulo)) % modulo;
2174 (void) fsmStage(fsm, FSM_DREAD);
2178 left = (modulo - (fdGetCpioPos(fsm->cfd) % modulo)) % modulo;
2181 memset(fsm->rdbuf, 0, left);
2183 /* XXX DWRITE uses rdnb for I/O length. */
2185 (void) fsmStage(fsm, FSM_DWRITE);
2189 rc = cpioTrailerWrite(fsm);
2192 rc = fsmStage(fsm, FSM_POS);
2194 rc = cpioHeaderRead(fsm, st); /* Read next payload header. */
2197 rc = cpioHeaderWrite(fsm, st); /* Write next payload header. */
2201 fsm->rdnb = Fread(fsm->wrbuf, sizeof(*fsm->wrbuf), fsm->wrlen, fsm->cfd);
2203 if (_fsm_debug && (stage & FSM_SYSCALL))
2204 rpmMessage(RPMMESS_DEBUG, " %8s (%s, %d, cfd)\trdnb %d\n",
2205 cur, (fsm->wrbuf == fsm->wrb ? "wrbuf" : "mmap"),
2206 (int)fsm->wrlen, (int)fsm->rdnb);
2207 if (fsm->rdnb != fsm->wrlen || Ferror(fsm->cfd))
2208 rc = CPIOERR_READ_FAILED;
2210 fdSetCpioPos(fsm->cfd, fdGetCpioPos(fsm->cfd) + fsm->rdnb);
2213 fsm->wrnb = Fwrite(fsm->rdbuf, sizeof(*fsm->rdbuf), fsm->rdnb, fsm->cfd);
2214 if (_fsm_debug && (stage & FSM_SYSCALL))
2215 rpmMessage(RPMMESS_DEBUG, " %8s (%s, %d, cfd)\twrnb %d\n",
2216 cur, (fsm->rdbuf == fsm->rdb ? "rdbuf" : "mmap"),
2217 (int)fsm->rdnb, (int)fsm->wrnb);
2218 if (fsm->rdnb != fsm->wrnb || Ferror(fsm->cfd))
2219 rc = CPIOERR_WRITE_FAILED;
2221 fdSetCpioPos(fsm->cfd, fdGetCpioPos(fsm->cfd) + fsm->wrnb);
2225 fsm->rfd = Fopen(fsm->path, "r.ufdio");
2226 if (fsm->rfd == NULL || Ferror(fsm->rfd)) {
2227 if (fsm->rfd) (void) fsmStage(fsm, FSM_RCLOSE);
2229 rc = CPIOERR_OPEN_FAILED;
2232 if (_fsm_debug && (stage & FSM_SYSCALL))
2233 rpmMessage(RPMMESS_DEBUG, " %8s (%s, \"r\") rfd %p rdbuf %p\n", cur,
2234 fsm->path, fsm->rfd, fsm->rdbuf);
2238 fsm->rdnb = Fread(fsm->rdbuf, sizeof(*fsm->rdbuf), fsm->rdlen, fsm->rfd);
2240 if (_fsm_debug && (stage & FSM_SYSCALL))
2241 rpmMessage(RPMMESS_DEBUG, " %8s (rdbuf, %d, rfd)\trdnb %d\n",
2242 cur, (int)fsm->rdlen, (int)fsm->rdnb);
2243 if (fsm->rdnb != fsm->rdlen || Ferror(fsm->rfd))
2244 rc = CPIOERR_READ_FAILED;
2248 if (_fsm_debug && (stage & FSM_SYSCALL))
2249 rpmMessage(RPMMESS_DEBUG, " %8s (%p)\n", cur, fsm->rfd);
2250 (void) Fclose(fsm->rfd);
2258 fsm->wfd = Fopen(fsm->path, "w.ufdio");
2259 if (fsm->wfd == NULL || Ferror(fsm->wfd)) {
2260 if (fsm->wfd) (void) fsmStage(fsm, FSM_WCLOSE);
2262 rc = CPIOERR_OPEN_FAILED;
2264 if (_fsm_debug && (stage & FSM_SYSCALL))
2265 rpmMessage(RPMMESS_DEBUG, " %8s (%s, \"w\") wfd %p wrbuf %p\n", cur,
2266 fsm->path, fsm->wfd, fsm->wrbuf);
2269 fsm->wrnb = Fwrite(fsm->wrbuf, sizeof(*fsm->wrbuf), fsm->rdnb, fsm->wfd);
2270 if (_fsm_debug && (stage & FSM_SYSCALL))
2271 rpmMessage(RPMMESS_DEBUG, " %8s (wrbuf, %d, wfd)\twrnb %d\n",
2272 cur, (int)fsm->rdnb, (int)fsm->wrnb);
2273 if (fsm->rdnb != fsm->wrnb || Ferror(fsm->wfd))
2274 rc = CPIOERR_WRITE_FAILED;
2278 if (_fsm_debug && (stage & FSM_SYSCALL))
2279 rpmMessage(RPMMESS_DEBUG, " %8s (%p)\n", cur, fsm->wfd);
2280 (void) Fclose(fsm->wfd);
2293 if (!(stage & FSM_INTERNAL)) {
2294 fsm->rc = (rc == CPIOERR_HDR_TRAILER ? 0 : rc);
2301 /*@obserever@*/ const char *const fileActionString(fileAction a)
2304 case FA_UNKNOWN: return "unknown";
2305 case FA_CREATE: return "create";
2306 case FA_COPYOUT: return "copyout";
2307 case FA_COPYIN: return "copyin";
2308 case FA_BACKUP: return "backup";
2309 case FA_SAVE: return "save";
2310 case FA_SKIP: return "skip";
2311 case FA_ALTNAME: return "altname";
2312 case FA_ERASE: return "erase";
2313 case FA_SKIPNSTATE: return "skipnstate";
2314 case FA_SKIPNETSHARED: return "skipnetshared";
2315 case FA_SKIPCOLOR: return "skipcolor";
2316 default: return "???";
2321 /*@observer@*/ const char *const fileStageString(fileStage a) {
2323 case FSM_UNKNOWN: return "unknown";
2325 case FSM_PKGINSTALL:return "INSTALL";
2326 case FSM_PKGERASE: return "ERASE";
2327 case FSM_PKGBUILD: return "BUILD";
2328 case FSM_PKGCOMMIT: return "COMMIT";
2329 case FSM_PKGUNDO: return "UNDO";
2331 case FSM_CREATE: return "create";
2332 case FSM_INIT: return "init";
2333 case FSM_MAP: return "map";
2334 case FSM_MKDIRS: return "mkdirs";
2335 case FSM_RMDIRS: return "rmdirs";
2336 case FSM_PRE: return "pre";
2337 case FSM_PROCESS: return "process";
2338 case FSM_POST: return "post";
2339 case FSM_MKLINKS: return "mklinks";
2340 case FSM_NOTIFY: return "notify";
2341 case FSM_UNDO: return "undo";
2342 case FSM_FINI: return "fini";
2343 case FSM_COMMIT: return "commit";
2344 case FSM_DESTROY: return "destroy";
2345 case FSM_VERIFY: return "verify";
2347 case FSM_UNLINK: return "Unlink";
2348 case FSM_RENAME: return "Rename";
2349 case FSM_MKDIR: return "Mkdir";
2350 case FSM_RMDIR: return "rmdir";
2351 case FSM_CHOWN: return "chown";
2352 case FSM_LCHOWN: return "lchown";
2353 case FSM_CHMOD: return "chmod";
2354 case FSM_UTIME: return "utime";
2355 case FSM_SYMLINK: return "symlink";
2356 case FSM_LINK: return "Link";
2357 case FSM_MKFIFO: return "mkfifo";
2358 case FSM_MKNOD: return "mknod";
2359 case FSM_LSTAT: return "Lstat";
2360 case FSM_STAT: return "Stat";
2361 case FSM_READLINK: return "Readlink";
2362 case FSM_CHROOT: return "chroot";
2364 case FSM_NEXT: return "next";
2365 case FSM_EAT: return "eat";
2366 case FSM_POS: return "pos";
2367 case FSM_PAD: return "pad";
2368 case FSM_TRAILER: return "trailer";
2369 case FSM_HREAD: return "hread";
2370 case FSM_HWRITE: return "hwrite";
2371 case FSM_DREAD: return "Fread";
2372 case FSM_DWRITE: return "Fwrite";
2374 case FSM_ROPEN: return "Fopen";
2375 case FSM_READ: return "Fread";
2376 case FSM_RCLOSE: return "Fclose";
2377 case FSM_WOPEN: return "Fopen";
2378 case FSM_WRITE: return "Fwrite";
2379 case FSM_WCLOSE: return "Fclose";
2381 default: return "???";