3 * File state machine to handle a payload from a package.
8 #include <rpmio_internal.h>
15 #include "psm.h" /* XXX fiTypeString */
18 #define _RPMFI_INTERNAL
33 #define alloca_strdup(_s) strcpy(alloca(strlen(_s)+1), (_s))
38 /* XXX Failure to remove is not (yet) cause for failure. */
39 /*@-exportlocal -exportheadervar@*/
41 int strict_erasures = 0;
42 /*@=exportlocal =exportheadervar@*/
44 rpmts fsmGetTs(const FSM_t fsm) {
45 const FSMI_t iter = fsm->iter;
46 /*@-compdef -refcounttrans -retexpose -usereleased @*/
47 return (iter ? iter->ts : NULL);
48 /*@=compdef =refcounttrans =retexpose =usereleased @*/
51 rpmfi fsmGetFi(const FSM_t fsm)
53 const FSMI_t iter = fsm->iter;
54 /*@-compdef -refcounttrans -retexpose -usereleased @*/
55 return (iter ? iter->fi : NULL);
56 /*@=compdef =refcounttrans =retexpose =usereleased @*/
59 #define SUFFIX_RPMORIG ".rpmorig"
60 #define SUFFIX_RPMSAVE ".rpmsave"
61 #define SUFFIX_RPMNEW ".rpmnew"
64 * Build path to file from file info, ornamented with subdir and suffix.
65 * @param fsm file state machine data
66 * @param st file stat info
67 * @param subdir subdir to use (NULL disables)
68 * @param suffix suffix to use (NULL disables)
69 * @retval path to file
71 static /*@only@*//*@null@*/
72 const char * fsmFsPath(/*@special@*/ /*@null@*/ const FSM_t fsm,
73 /*@null@*/ const struct stat * st,
74 /*@null@*/ const char * subdir,
75 /*@null@*/ const char * suffix)
76 /*@uses fsm->dirName, fsm->baseName */
79 const char * s = NULL;
84 nb = strlen(fsm->dirName) +
85 (st && !S_ISDIR(st->st_mode) ? (subdir ? strlen(subdir) : 0) : 0) +
86 (st && !S_ISDIR(st->st_mode) ? (suffix ? strlen(suffix) : 0) : 0) +
87 strlen(fsm->baseName) + 1;
90 t = stpcpy(t, fsm->dirName);
91 if (st && !S_ISDIR(st->st_mode))
92 if (subdir) t = stpcpy(t, subdir);
93 t = stpcpy(t, fsm->baseName);
94 if (st && !S_ISDIR(st->st_mode))
95 if (suffix) t = stpcpy(t, suffix);
102 * Destroy file info iterator.
103 * @param p file info iterator
104 * @retval NULL always
106 static /*@null@*/ void * mapFreeIterator(/*@only@*//*@null@*/ void * p)
111 iter->ts = rpmtsUnlink(iter->ts, "mapIterator");
112 iter->fi = rpmfiUnlink(iter->fi, "mapIterator");
118 * Create file info iterator.
119 * @param ts transaction set
120 * @param fi transaction element file info
121 * @return file info iterator
124 mapInitIterator(rpmts ts, rpmfi fi)
125 /*@modifies ts, fi @*/
129 iter = xcalloc(1, sizeof(*iter));
130 iter->ts = rpmtsLink(ts, "mapIterator");
131 iter->fi = rpmfiLink(fi, "mapIterator");
132 iter->reverse = (rpmteType(fi->te) == TR_REMOVED && fi->action != FA_COPYOUT);
133 iter->i = (iter->reverse ? (fi->fc - 1) : 0);
134 iter->isave = iter->i;
139 * Return next index into file info.
140 * @param a file info iterator
141 * @return next index, -1 on termination
143 static int mapNextIterator(/*@null@*/ void * a)
150 const rpmfi fi = iter->fi;
152 if (iter->i >= 0) i = iter->i--;
154 if (iter->i < fi->fc) i = iter->i++;
164 static int cpioStrCmp(const void * a, const void * b)
167 const char * afn = *(const char **)a;
168 const char * bfn = *(const char **)b;
170 /* Match rpm-4.0 payloads with ./ prefixes. */
171 if (afn[0] == '.' && afn[1] == '/') afn += 2;
172 if (bfn[0] == '.' && bfn[1] == '/') bfn += 2;
174 /* If either path is absolute, make it relative. */
175 if (afn[0] == '/') afn += 1;
176 if (bfn[0] == '/') bfn += 1;
178 return strcmp(afn, bfn);
183 * Locate archive path in file info.
184 * @param iter file info iterator
185 * @param fsmPath archive path
186 * @return index into file info, -1 if archive path was not found
189 static int mapFind(/*@null@*/ FSMI_t iter, const char * fsmPath)
195 const rpmfi fi = iter->fi;
196 if (fi && fi->fc > 0 && fi->apath && fsmPath && *fsmPath) {
197 const char ** p = NULL;
200 if (fi->apath != NULL)
201 p = bsearch(&fsmPath, fi->apath, fi->fc, sizeof(fsmPath),
205 iter->i = p - fi->apath;
206 ix = mapNextIterator(iter);
215 * Directory name iterator.
217 typedef struct dnli_s {
219 /*@only@*/ /*@null@*/ char * active;
226 * Destroy directory name iterator.
227 * @param a directory name iterator
228 * @retval NULL always
230 static /*@null@*/ void * dnlFreeIterator(/*@only@*//*@null@*/ const void * a)
234 DNLI_t dnli = (void *)a;
235 if (dnli->active) free(dnli->active);
242 static inline int dnlCount(const DNLI_t dnli)
245 return (dnli ? dnli->fi->dc : 0);
250 static inline int dnlIndex(const DNLI_t dnli)
253 return (dnli ? dnli->isave : -1);
257 * Create directory name iterator.
258 * @param fsm file state machine data
259 * @param reverse traverse directory names in reverse order?
260 * @return directory name iterator
264 static /*@only@*/ void * dnlInitIterator(/*@special@*/ const FSM_t fsm,
266 /*@uses fsm->iter @*/
269 rpmfi fi = fsmGetFi(fsm);
275 dnli = xcalloc(1, sizeof(*dnli));
277 dnli->reverse = reverse;
279 dnli->i = (reverse ? fi->dc : 0);
283 dnli->active = xcalloc(fi->dc, sizeof(*dnli->active));
285 /* Identify parent directories not skipped. */
287 for (i = 0; i < fi->fc; i++)
288 if (!XFA_SKIPPING(fi->actions[i])) dnli->active[fi->dil[i]] = 1;
291 /* Exclude parent directories that are explicitly included. */
292 for (i = 0; i < fi->fc; i++) {
293 int dil, dnlen, bnlen;
295 if (!S_ISDIR(fi->fmodes[i]))
299 dnlen = strlen(fi->dnl[dil]);
300 bnlen = strlen(fi->bnl[i]);
302 for (j = 0; j < fi->dc; j++) {
306 if (!dnli->active[j] || j == dil)
307 /*@innercontinue@*/ continue;
310 if (jlen != (dnlen+bnlen+1))
311 /*@innercontinue@*/ continue;
312 if (strncmp(dnl, fi->dnl[dil], dnlen))
313 /*@innercontinue@*/ continue;
314 if (strncmp(dnl+dnlen, fi->bnl[i], bnlen))
315 /*@innercontinue@*/ continue;
316 if (dnl[dnlen+bnlen] != '/' || dnl[dnlen+bnlen+1] != '\0')
317 /*@innercontinue@*/ continue;
318 /* This directory is included in the package. */
322 /*@innerbreak@*/ break;
326 /* Print only once per package. */
329 for (i = 0; i < fi->dc; i++) {
330 if (!dnli->active[i]) continue;
333 rpmMessage(RPMMESS_DEBUG,
334 _("========== Directories not explictly included in package:\n"));
336 rpmMessage(RPMMESS_DEBUG, _("%10d %s\n"), i, fi->dnl[i]);
339 rpmMessage(RPMMESS_DEBUG, "==========\n");
348 * Return next directory name (from file info).
349 * @param dnli directory name iterator
350 * @return next directory name
353 static /*@observer@*/ const char * dnlNextIterator(/*@null@*/ DNLI_t dnli)
356 const char * dn = NULL;
364 i = (!dnli->reverse ? dnli->i++ : --dnli->i);
365 } while (i >= 0 && i < fi->dc && !dnli->active[i]);
367 if (i >= 0 && i < fi->dc)
378 * Save hard link in chain.
379 * @param fsm file state machine data
380 * @return Is chain only partially filled?
383 static int saveHardLink(/*@special@*/ /*@partial@*/ FSM_t fsm)
384 /*@uses fsm->links, fsm->ix, fsm->sb, fsm->goal, fsm->nsuffix @*/
385 /*@defines fsm->li @*/
386 /*@releases fsm->path @*/
387 /*@globals fileSystem@*/
388 /*@modifies fsm, fileSystem @*/
390 struct stat * st = &fsm->sb;
395 /* Find hard link set. */
397 for (fsm->li = fsm->links; fsm->li; fsm->li = fsm->li->next) {
398 if (fsm->li->sb.st_ino == st->st_ino && fsm->li->sb.st_dev == st->st_dev)
403 /* New hard link encountered, add new link to set. */
406 if (fsm->li == NULL) {
407 fsm->li = xcalloc(1, sizeof(*fsm->li));
408 fsm->li->next = NULL;
409 fsm->li->sb = *st; /* structure assignment */
410 fsm->li->nlink = st->st_nlink;
411 fsm->li->linkIndex = fsm->ix;
412 fsm->li->createdPath = -1;
414 fsm->li->filex = xcalloc(st->st_nlink, sizeof(fsm->li->filex[0]));
415 memset(fsm->li->filex, -1, (st->st_nlink * sizeof(fsm->li->filex[0])));
416 fsm->li->nsuffix = xcalloc(st->st_nlink, sizeof(*fsm->li->nsuffix));
418 if (fsm->goal == FSM_PKGBUILD)
419 fsm->li->linksLeft = st->st_nlink;
420 if (fsm->goal == FSM_PKGINSTALL)
421 fsm->li->linksLeft = 0;
424 fsm->li->next = fsm->links;
426 fsm->links = fsm->li;
431 if (fsm->goal == FSM_PKGBUILD) --fsm->li->linksLeft;
433 fsm->li->filex[fsm->li->linksLeft] = fsm->ix;
434 /*@-observertrans -dependenttrans@*/
435 fsm->li->nsuffix[fsm->li->linksLeft] = fsm->nsuffix;
436 /*@=observertrans =dependenttrans@*/
438 if (fsm->goal == FSM_PKGINSTALL) fsm->li->linksLeft++;
440 if (fsm->goal == FSM_PKGBUILD)
441 return (fsm->li->linksLeft > 0);
443 if (fsm->goal != FSM_PKGINSTALL)
446 if (!(st->st_size || fsm->li->linksLeft == st->st_nlink))
449 /* Here come the bits, time to choose a non-skipped file name. */
450 { rpmfi fi = fsmGetFi(fsm);
452 for (j = fsm->li->linksLeft - 1; j >= 0; j--) {
453 ix = fsm->li->filex[j];
454 if (ix < 0 || XFA_SKIPPING(fi->actions[ix]))
460 /* Are all links skipped or not encountered yet? */
462 return 1; /* XXX W2DO? */
464 /* Save the non-skipped file name and map index. */
465 fsm->li->linkIndex = j;
466 fsm->path = _free(fsm->path);
468 rc = fsmStage(fsm, FSM_MAP);
474 * Destroy set of hard links.
475 * @param li set of hard links
476 * @return NULL always
478 static /*@null@*/ void * freeHardLink(/*@only@*/ /*@null@*/ struct hardLink_s * li)
482 li->nsuffix = _free(li->nsuffix); /* XXX elements are shared */
483 li->filex = _free(li->filex);
490 FSM_t fsm = xcalloc(1, sizeof(*fsm));
494 FSM_t freeFSM(FSM_t fsm)
497 fsm->path = _free(fsm->path);
499 while ((fsm->li = fsm->links) != NULL) {
500 fsm->links = fsm->li->next;
501 fsm->li->next = NULL;
502 fsm->li = freeHardLink(fsm->li);
505 fsm->dnlx = _free(fsm->dnlx);
506 fsm->ldn = _free(fsm->ldn);
507 fsm->iter = mapFreeIterator(fsm->iter);
512 int fsmSetup(FSM_t fsm, fileStage goal,
513 const rpmts ts, const rpmfi fi, FD_t cfd,
514 unsigned int * archiveSize, const char ** failedFile)
521 /*@-type@*/ /* FIX: cast? */
522 fsm->cfd = fdLink(cfd, "persist (fsm)");
524 pos = fdGetCpioPos(fsm->cfd);
525 fdSetCpioPos(fsm->cfd, 0);
527 fsm->iter = mapInitIterator(ts, fi);
529 if (fsm->goal == FSM_PKGINSTALL) {
531 ptr = rpmtsNotify(ts, fi->te,
532 RPMCALLBACK_INST_START, 0, fi->archiveSize);
537 fsm->archiveSize = archiveSize;
538 if (fsm->archiveSize)
539 *fsm->archiveSize = 0;
540 fsm->failedFile = failedFile;
542 *fsm->failedFile = NULL;
546 memset(fsm->sufbuf, 0, sizeof(fsm->sufbuf));
547 if (fsm->goal == FSM_PKGINSTALL) {
548 if (ts && rpmtsGetTid(ts) > 0)
549 sprintf(fsm->sufbuf, ";%08x", (unsigned)rpmtsGetTid(ts));
553 rc = fsmStage(fsm, FSM_CREATE);
554 if (rc && !ec) ec = rc;
556 rc = fsmStage(fsm, fsm->goal);
557 if (rc && !ec) ec = rc;
560 if (fsm->archiveSize && ec == 0)
561 *fsm->archiveSize = (fdGetCpioPos(fsm->cfd) - pos);
567 int fsmTeardown(FSM_t fsm)
572 rc = fsmStage(fsm, FSM_DESTROY);
574 fsm->iter = mapFreeIterator(fsm->iter);
576 /*@-type@*/ /* FIX: cast? */
577 fsm->cfd = fdFree(fsm->cfd, "persist (fsm)");
581 fsm->failedFile = NULL;
585 int fsmMapPath(FSM_t fsm)
587 rpmfi fi = fsmGetFi(fsm); /* XXX const except for fstates */
594 fsm->action = FA_UNKNOWN;
598 if (fi && i >= 0 && i < fi->fc) {
601 fsm->astriplen = fi->astriplen;
602 fsm->action = (fi->actions ? fi->actions[i] : fi->action);
603 fsm->fflags = (fi->fflags ? fi->fflags[i] : fi->flags);
604 fsm->mapFlags = (fi->fmapflags ? fi->fmapflags[i] : fi->mapflags);
606 /* src rpms have simple base name in payload. */
607 fsm->dirName = fi->dnl[fi->dil[i]];
608 fsm->baseName = fi->bnl[i];
612 switch (fsm->action) {
615 case FA_SKIPMULTILIB: /* XXX RPMFILE_STATE_MULTILIB? */
624 assert(rpmteType(fi->te) == TR_ADDED);
628 if (fi->fstates && rpmteType(fi->te) == TR_ADDED)
629 fi->fstates[i] = RPMFILE_STATE_NOTINSTALLED;
632 case FA_SKIPNETSHARED:
633 if (fi->fstates && rpmteType(fi->te) == TR_ADDED)
634 fi->fstates[i] = RPMFILE_STATE_NETSHARED;
638 if (!(fsm->fflags & RPMFILE_GHOST)) /* XXX Don't if %ghost file. */
639 switch (rpmteType(fi->te)) {
641 fsm->osuffix = SUFFIX_RPMORIG;
642 /*@innerbreak@*/ break;
644 fsm->osuffix = SUFFIX_RPMSAVE;
645 /*@innerbreak@*/ break;
650 assert(rpmteType(fi->te) == TR_ADDED);
651 if (!(fsm->fflags & RPMFILE_GHOST)) /* XXX Don't if %ghost file. */
652 fsm->nsuffix = SUFFIX_RPMNEW;
656 assert(rpmteType(fi->te) == TR_ADDED);
657 if (!(fsm->fflags & RPMFILE_GHOST)) /* XXX Don't if %ghost file. */
658 fsm->osuffix = SUFFIX_RPMSAVE;
661 assert(rpmteType(fi->te) == TR_REMOVED);
663 * XXX TODO: %ghost probably shouldn't be removed, but that changes
664 * legacy rpm behavior.
672 if ((fsm->mapFlags & CPIO_MAP_PATH) || fsm->nsuffix) {
673 const struct stat * st = &fsm->sb;
674 fsm->path = _free(fsm->path);
675 fsm->path = fsmFsPath(fsm, st, fsm->subdir,
676 (fsm->suffix ? fsm->suffix : fsm->nsuffix));
682 int fsmMapAttrs(FSM_t fsm)
684 struct stat * st = &fsm->sb;
685 rpmfi fi = fsmGetFi(fsm);
688 if (fi && i >= 0 && i < fi->fc) {
690 (S_ISDIR(st->st_mode) ? fi->dperms : fi->fperms);
692 (fi->fmodes ? fi->fmodes[i] : perms);
694 (fi->fuids ? fi->fuids[i] : fi->uid); /* XXX chmod u-s */
696 (fi->fgids ? fi->fgids[i] : fi->gid); /* XXX chmod g-s */
698 (fi->frdevs ? fi->frdevs[i] : 0);
700 (fi->fmtimes ? fi->fmtimes[i] : 0);
702 if (fsm->mapFlags & CPIO_MAP_MODE)
703 st->st_mode = (st->st_mode & S_IFMT) | (finalMode & ~S_IFMT);
704 if (fsm->mapFlags & CPIO_MAP_TYPE) {
705 st->st_mode = (st->st_mode & ~S_IFMT) | (finalMode & S_IFMT);
706 if ((S_ISCHR(st->st_mode) || S_ISBLK(st->st_mode))
707 && st->st_nlink == 0)
709 st->st_rdev = finalRdev;
710 st->st_mtime = finalMtime;
712 if (fsm->mapFlags & CPIO_MAP_UID)
713 st->st_uid = finalUid;
714 if (fsm->mapFlags & CPIO_MAP_GID)
715 st->st_gid = finalGid;
717 { rpmts ts = fsmGetTs(fsm);
719 if (ts != NULL && !(rpmtsFlags(ts) & RPMTRANS_FLAG_NOMD5)) {
720 fsm->fmd5sum = (fi->fmd5s ? fi->fmd5s[i] : NULL);
721 fsm->md5sum = (fi->md5s ? (fi->md5s + (16 * i)) : NULL);
733 * Create file from payload stream.
734 * @param fsm file state machine data
735 * @return 0 on success
737 static int expandRegular(/*@special@*/ FSM_t fsm)
739 /*@globals fileSystem@*/
740 /*@modifies fsm, fileSystem @*/
742 const struct stat * st = &fsm->sb;
743 int left = st->st_size;
746 rc = fsmStage(fsm, FSM_WOPEN);
750 if (st->st_size > 0 && (fsm->fmd5sum || fsm->md5sum))
751 fdInitDigest(fsm->wfd, PGPHASHALGO_MD5, 0);
755 fsm->wrlen = (left > fsm->wrsize ? fsm->wrsize : left);
756 rc = fsmStage(fsm, FSM_DREAD);
760 rc = fsmStage(fsm, FSM_WRITE);
766 /* don't call this with fileSize == fileComplete */
768 (void) fsmStage(fsm, FSM_NOTIFY);
771 if (st->st_size > 0 && (fsm->fmd5sum || fsm->md5sum)) {
772 void * md5sum = NULL;
773 int asAscii = (fsm->md5sum == NULL ? 1 : 0);
775 (void) Fflush(fsm->wfd);
776 fdFiniDigest(fsm->wfd, PGPHASHALGO_MD5, &md5sum, NULL, asAscii);
778 if (md5sum == NULL) {
779 rc = CPIOERR_MD5SUM_MISMATCH;
783 if (fsm->md5sum != NULL) {
784 if (memcmp(md5sum, fsm->md5sum, 16))
785 rc = CPIOERR_MD5SUM_MISMATCH;
787 if (strcmp(md5sum, fsm->fmd5sum))
788 rc = CPIOERR_MD5SUM_MISMATCH;
790 md5sum = _free(md5sum);
794 (void) fsmStage(fsm, FSM_WCLOSE);
799 * Write next item to payload stream.
800 * @param fsm file state machine data
801 * @param writeData should data be written?
802 * @return 0 on success
804 static int writeFile(/*@special@*/ FSM_t fsm, int writeData)
805 /*@uses fsm->path, fsm->opath, fsm->sb, fsm->osb, fsm->cfd @*/
806 /*@globals fileSystem@*/
807 /*@modifies fsm, fileSystem @*/
809 const char * path = fsm->path;
810 const char * opath = fsm->opath;
811 struct stat * st = &fsm->sb;
812 struct stat * ost = &fsm->osb;
813 size_t pos = fdGetCpioPos(fsm->cfd);
814 char * symbuf = NULL;
819 st->st_size = (writeData ? ost->st_size : 0);
822 if (S_ISDIR(st->st_mode)) {
824 } else if (S_ISLNK(st->st_mode)) {
826 * While linux puts the size of a symlink in the st_size field,
827 * I don't think that's a specified standard.
829 /* XXX NUL terminated result in fsm->rdbuf, len in fsm->rdnb. */
830 rc = fsmStage(fsm, FSM_READLINK);
832 st->st_size = fsm->rdnb;
833 symbuf = alloca_strdup(fsm->rdbuf); /* XXX save readlink return. */
837 if (fsm->mapFlags & CPIO_MAP_ABSOLUTE) {
838 /*@-compdef@*/ /* FIX: dirName/baseName annotations ? */
840 int nb = strlen(fsm->dirName) + strlen(fsm->baseName) + sizeof(".");
841 char * t = alloca(nb);
844 if (fsm->mapFlags & CPIO_MAP_ADDDOT)
846 t = stpcpy( stpcpy(t, fsm->dirName), fsm->baseName);
849 } else if (fsm->mapFlags & CPIO_MAP_PATH) {
850 rpmfi fi = fsmGetFi(fsm);
852 (fi->apath ? fi->apath[fsm->ix] + fi->striplen : fi->bnl[fsm->ix]);
855 rc = fsmStage(fsm, FSM_HWRITE);
859 if (writeData && S_ISREG(st->st_mode)) {
862 void * mapped = (void *)-1;
866 rc = fsmStage(fsm, FSM_ROPEN);
869 /* XXX unbuffered mmap generates *lots* of fdio debugging */
872 mapped = mmap(NULL, st->st_size, PROT_READ, MAP_SHARED, Fileno(fsm->rfd), 0);
873 if (mapped != (void *)-1) {
875 fsm->rdbuf = (char *) mapped;
876 fsm->rdlen = nmapped = st->st_size;
877 #if defined(MADV_DONTNEED)
878 xx = madvise(mapped, nmapped, MADV_DONTNEED);
887 if (mapped != (void *)-1) {
892 fsm->rdlen = (left > fsm->rdsize ? fsm->rdsize : left),
893 rc = fsmStage(fsm, FSM_READ);
897 /* XXX DWRITE uses rdnb for I/O length. */
898 rc = fsmStage(fsm, FSM_DWRITE);
905 if (mapped != (void *)-1) {
906 xx = msync(mapped, nmapped, MS_ASYNC);
907 #if defined(MADV_DONTNEED)
908 xx = madvise(mapped, nmapped, MADV_DONTNEED);
910 /*@-noeffect@*/ xx = munmap(mapped, nmapped) /*@=noeffect@*/;
915 } else if (writeData && S_ISLNK(st->st_mode)) {
916 /* XXX DWRITE uses rdnb for I/O length. */
918 strcpy(fsm->rdbuf, symbuf); /* XXX restore readlink buffer. */
920 fsm->rdnb = strlen(symbuf);
921 rc = fsmStage(fsm, FSM_DWRITE);
925 rc = fsmStage(fsm, FSM_PAD);
928 { const rpmts ts = fsmGetTs(fsm);
929 rpmfi fi = fsmGetFi(fsm);
930 size_t size = (fdGetCpioPos(fsm->cfd) - pos);
932 ptr = rpmtsNotify(ts, fi->te, RPMCALLBACK_INST_PROGRESS, size, size);
939 (void) fsmStage(fsm, FSM_RCLOSE);
940 /*@-dependenttrans@*/
943 /*@=dependenttrans@*/
948 * Write set of linked files to payload stream.
949 * @param fsm file state machine data
950 * @return 0 on success
952 static int writeLinkedFile(/*@special@*/ FSM_t fsm)
953 /*@uses fsm->path, fsm->nsuffix, fsm->ix, fsm->li, fsm->failedFile @*/
954 /*@globals fileSystem@*/
955 /*@modifies fsm, fileSystem @*/
957 const char * path = fsm->path;
958 const char * nsuffix = fsm->nsuffix;
959 int iterIndex = fsm->ix;
969 for (i = fsm->li->nlink - 1; i >= 0; i--) {
971 if (fsm->li->filex[i] < 0) continue;
973 fsm->ix = fsm->li->filex[i];
974 rc = fsmStage(fsm, FSM_MAP);
976 /* Write data after last link. */
977 rc = writeFile(fsm, (i == 0));
978 if (fsm->failedFile && rc != 0 && *fsm->failedFile == NULL) {
980 *fsm->failedFile = xstrdup(fsm->path);
983 fsm->path = _free(fsm->path);
984 fsm->li->filex[i] = -1;
989 fsm->nsuffix = nsuffix;
995 * Create pending hard links to existing file.
996 * @param fsm file state machine data
997 * @return 0 on success
1000 static int fsmMakeLinks(/*@special@*/ FSM_t fsm)
1001 /*@uses fsm->path, fsm->opath, fsm->nsuffix, fsm->ix, fsm->li @*/
1002 /*@globals fileSystem@*/
1003 /*@modifies fsm, fileSystem @*/
1005 const char * path = fsm->path;
1006 const char * opath = fsm->opath;
1007 const char * nsuffix = fsm->nsuffix;
1008 int iterIndex = fsm->ix;
1015 fsm->nsuffix = NULL;
1018 fsm->ix = fsm->li->filex[fsm->li->createdPath];
1019 rc = fsmStage(fsm, FSM_MAP);
1020 fsm->opath = fsm->path;
1023 for (i = 0; i < fsm->li->nlink; i++) {
1024 if (fsm->li->filex[i] < 0) continue;
1025 if (fsm->li->createdPath == i) continue;
1027 fsm->ix = fsm->li->filex[i];
1028 fsm->path = _free(fsm->path);
1029 rc = fsmStage(fsm, FSM_MAP);
1030 if (XFA_SKIPPING(fsm->action)) continue;
1032 rc = fsmStage(fsm, FSM_VERIFY);
1034 if (rc != CPIOERR_LSTAT_FAILED) break;
1036 /* XXX link(fsm->opath, fsm->path) */
1037 rc = fsmStage(fsm, FSM_LINK);
1038 if (fsm->failedFile && rc != 0 && *fsm->failedFile == NULL) {
1041 *fsm->failedFile = xstrdup(fsm->path);
1045 fsm->li->linksLeft--;
1048 fsm->path = _free(fsm->path);
1049 fsm->opath = _free(fsm->opath);
1051 fsm->ix = iterIndex;
1052 fsm->nsuffix = nsuffix;
1059 /** \ingroup payload
1060 * Commit hard linked file set atomically.
1061 * @param fsm file state machine data
1062 * @return 0 on success
1064 static int fsmCommitLinks(/*@special@*/ FSM_t fsm)
1065 /*@uses fsm->path, fsm->nsuffix, fsm->ix, fsm->sb,
1066 fsm->li, fsm->links @*/
1067 /*@globals fileSystem@*/
1068 /*@modifies fsm, fileSystem @*/
1070 const char * path = fsm->path;
1071 const char * nsuffix = fsm->nsuffix;
1072 int iterIndex = fsm->ix;
1073 struct stat * st = &fsm->sb;
1078 fsm->nsuffix = NULL;
1082 for (fsm->li = fsm->links; fsm->li; fsm->li = fsm->li->next) {
1083 if (fsm->li->sb.st_ino == st->st_ino && fsm->li->sb.st_dev == st->st_dev)
1089 for (i = 0; i < fsm->li->nlink; i++) {
1090 if (fsm->li->filex[i] < 0) continue;
1091 fsm->ix = fsm->li->filex[i];
1092 rc = fsmStage(fsm, FSM_MAP);
1093 if (!XFA_SKIPPING(fsm->action))
1094 rc = fsmStage(fsm, FSM_COMMIT);
1095 fsm->path = _free(fsm->path);
1096 fsm->li->filex[i] = -1;
1100 fsm->ix = iterIndex;
1101 fsm->nsuffix = nsuffix;
1107 * Remove (if created) directories not explicitly included in package.
1108 * @param fsm file state machine data
1109 * @return 0 on success
1111 static int fsmRmdirs(/*@special@*/ FSM_t fsm)
1112 /*@uses fsm->path, fsm->dnlx, fsm->ldn, fsm->rdbuf, fsm->iter @*/
1113 /*@globals fileSystem@*/
1114 /*@modifies fsm, fileSystem @*/
1116 const char * path = fsm->path;
1117 void * dnli = dnlInitIterator(fsm, 1);
1118 char * dn = fsm->rdbuf;
1119 int dc = dnlCount(dnli);
1125 /*@-observertrans -dependenttrans@*/
1126 if (fsm->ldn != NULL && fsm->dnlx != NULL)
1127 while ((fsm->path = dnlNextIterator(dnli)) != NULL) {
1128 int dnlen = strlen(fsm->path);
1131 dc = dnlIndex(dnli);
1132 if (fsm->dnlx[dc] < 1 || fsm->dnlx[dc] >= dnlen)
1135 /* Copy to avoid const on fsm->path. */
1136 te = stpcpy(dn, fsm->path) - 1;
1139 /* Remove generated directories. */
1140 /*@-usereleased@*/ /* LCL: te used after release? */
1144 rc = fsmStage(fsm, FSM_RMDIR);
1148 /*@innerbreak@*/ break;
1150 } while ((te - fsm->path) > fsm->dnlx[dc]);
1154 dnli = dnlFreeIterator(dnli);
1155 /*@=observertrans =dependenttrans@*/
1162 * Create (if necessary) directories not explicitly included in package.
1163 * @param fsm file state machine data
1164 * @return 0 on success
1166 static int fsmMkdirs(/*@special@*/ FSM_t fsm)
1167 /*@uses fsm->path, fsm->sb, fsm->osb, fsm->rdbuf, fsm->iter,
1168 fsm->ldn, fsm->ldnlen, fsm->ldnalloc @*/
1169 /*@defines fsm->dnlx, fsm->ldn @*/
1170 /*@globals fileSystem@*/
1171 /*@modifies fsm, fileSystem @*/
1173 struct stat * st = &fsm->sb;
1174 struct stat * ost = &fsm->osb;
1175 const char * path = fsm->path;
1176 mode_t st_mode = st->st_mode;
1177 void * dnli = dnlInitIterator(fsm, 0);
1178 char * dn = fsm->rdbuf;
1179 int dc = dnlCount(dnli);
1187 fsm->dnlx = (dc ? xcalloc(dc, sizeof(*fsm->dnlx)) : NULL);
1188 /*@-observertrans -dependenttrans@*/
1189 if (fsm->dnlx != NULL)
1190 while ((fsm->path = dnlNextIterator(dnli)) != NULL) {
1191 int dnlen = strlen(fsm->path);
1194 dc = dnlIndex(dnli);
1195 if (dc < 0) continue;
1196 fsm->dnlx[dc] = dnlen;
1200 /*@-compdef -nullpass@*/ /* FIX: fsm->ldn not defined ??? */
1201 if (dnlen <= fsm->ldnlen && !strcmp(fsm->path, fsm->ldn))
1203 /*@=compdef =nullpass@*/
1205 /* Copy to avoid const on fsm->path. */
1206 (void) stpcpy(dn, fsm->path);
1209 /* Assume '/' directory exists, "mkdir -p" for others if non-existent */
1210 for (i = 1, te = dn + 1; *te != '\0'; te++, i++) {
1212 /*@innercontinue@*/ continue;
1216 /* Already validated? */
1217 /*@-usedef -compdef -nullpass -nullderef@*/
1218 if (i < fsm->ldnlen &&
1219 (fsm->ldn[i] == '/' || fsm->ldn[i] == '\0') &&
1220 !strncmp(fsm->path, fsm->ldn, i))
1223 /* Move pre-existing path marker forward. */
1224 fsm->dnlx[dc] = (te - dn);
1225 /*@innercontinue@*/ continue;
1227 /*@=usedef =compdef =nullpass =nullderef@*/
1229 /* Validate next component of path. */
1230 rc = fsmStage(fsm, FSM_LSTAT);
1233 /* Directory already exists? */
1234 if (rc == 0 && S_ISDIR(ost->st_mode)) {
1235 /* Move pre-existing path marker forward. */
1236 fsm->dnlx[dc] = (te - dn);
1237 } else if (rc == CPIOERR_LSTAT_FAILED) {
1238 rpmfi fi = fsmGetFi(fsm);
1240 st->st_mode = S_IFDIR | (fi->dperms & 07777);
1241 rc = fsmStage(fsm, FSM_MKDIR);
1243 rpmMessage(RPMMESS_DEBUG,
1244 _("%s directory created with perms %04o.\n"),
1245 fsm->path, (unsigned)(st->st_mode & 07777));
1249 /*@innerbreak@*/ break;
1253 /* Save last validated path. */
1254 /*@-compdef@*/ /* FIX: ldn/path annotations ? */
1255 if (fsm->ldnalloc < (dnlen + 1)) {
1256 fsm->ldnalloc = dnlen + 100;
1257 fsm->ldn = xrealloc(fsm->ldn, fsm->ldnalloc);
1259 if (fsm->ldn != NULL) { /* XXX can't happen */
1260 strcpy(fsm->ldn, fsm->path);
1261 fsm->ldnlen = dnlen;
1266 dnli = dnlFreeIterator(dnli);
1267 /*@=observertrans =dependenttrans@*/
1270 st->st_mode = st_mode; /* XXX restore st->st_mode */
1271 /*@-compdef@*/ /* FIX: ldn/path annotations ? */
1278 * Check for file on disk.
1279 * @param fsm file state machine data
1280 * @return 0 on success
1282 static int fsmStat(FSM_t fsm)
1284 int saveerrno = errno;
1287 if (fsm->path != NULL) {
1288 int saveernno = errno;
1289 rc = fsmStage(fsm, (!(fsm->mapFlags & CPIO_FOLLOW_SYMLINKS)
1290 ? FSM_LSTAT : FSM_STAT));
1291 if (rc == CPIOERR_LSTAT_FAILED && errno == ENOENT) {
1295 } else if (rc == 0) {
1299 /* Skip %ghost files on build. */
1306 #define IS_DEV_LOG(_x) \
1307 ((_x) != NULL && strlen(_x) >= (sizeof("/dev/log")-1) && \
1308 !strncmp((_x), "/dev/log", sizeof("/dev/log")-1) && \
1309 ((_x)[sizeof("/dev/log")-1] == '\0' || \
1310 (_x)[sizeof("/dev/log")-1] == ';'))
1314 int fsmStage(FSM_t fsm, fileStage stage)
1317 fileStage prevStage = fsm->stage;
1318 const char * const prev = fileStageString(prevStage);
1320 static int modulo = 4;
1321 const char * const cur = fileStageString(stage);
1322 struct stat * st = &fsm->sb;
1323 struct stat * ost = &fsm->osb;
1324 int saveerrno = errno;
1329 #define _fafilter(_a) \
1330 (!((_a) == FA_CREATE || (_a) == FA_ERASE || (_a) == FA_COPYIN || (_a) == FA_COPYOUT) \
1331 ? fileActionString(_a) : "")
1333 if (stage & FSM_DEAD) {
1335 } else if (stage & FSM_INTERNAL) {
1336 if (_fsm_debug && !(stage & FSM_SYSCALL))
1337 rpmMessage(RPMMESS_DEBUG, " %8s %06o%3d (%4d,%4d)%10d %s %s\n",
1339 (unsigned)st->st_mode, (int)st->st_nlink,
1340 (int)st->st_uid, (int)st->st_gid, (int)st->st_size,
1341 (fsm->path ? fsm->path : ""),
1342 _fafilter(fsm->action));
1345 if (_fsm_debug || !(stage & FSM_VERBOSE))
1346 rpmMessage(RPMMESS_DEBUG, "%-8s %06o%3d (%4d,%4d)%10d %s %s\n",
1348 (unsigned)st->st_mode, (int)st->st_nlink,
1349 (int)st->st_uid, (int)st->st_gid, (int)st->st_size,
1350 (fsm->path ? fsm->path + fsm->astriplen : ""),
1351 _fafilter(fsm->action));
1359 case FSM_PKGINSTALL:
1361 /* Clean fsm, free'ing memory. Read next archive header. */
1362 rc = fsmStage(fsm, FSM_INIT);
1364 /* Exit on end-of-payload. */
1365 if (rc == CPIOERR_HDR_TRAILER) {
1367 /*@loopbreak@*/ break;
1370 /* Exit on error. */
1373 (void) fsmStage(fsm, FSM_UNDO);
1374 /*@loopbreak@*/ break;
1377 /* Extract file from archive. */
1378 rc = fsmStage(fsm, FSM_PROCESS);
1380 (void) fsmStage(fsm, FSM_UNDO);
1381 /*@loopbreak@*/ break;
1384 /* Notify on success. */
1385 (void) fsmStage(fsm, FSM_NOTIFY);
1387 rc = fsmStage(fsm, FSM_FINI);
1389 /*@loopbreak@*/ break;
1396 /* Clean fsm, free'ing memory. */
1397 rc = fsmStage(fsm, FSM_INIT);
1399 /* Exit on end-of-payload. */
1400 if (rc == CPIOERR_HDR_TRAILER) {
1402 /*@loopbreak@*/ break;
1405 /* Rename/erase next item. */
1406 if (fsmStage(fsm, FSM_FINI))
1407 /*@loopbreak@*/ break;
1413 rc = fsmStage(fsm, FSM_INIT);
1415 /* Exit on end-of-payload. */
1416 if (rc == CPIOERR_HDR_TRAILER) {
1418 /*@loopbreak@*/ break;
1421 /* Exit on error. */
1424 (void) fsmStage(fsm, FSM_UNDO);
1425 /*@loopbreak@*/ break;
1428 /* Copy file into archive. */
1429 rc = fsmStage(fsm, FSM_PROCESS);
1431 (void) fsmStage(fsm, FSM_UNDO);
1432 /*@loopbreak@*/ break;
1435 if (fsmStage(fsm, FSM_FINI))
1436 /*@loopbreak@*/ break;
1439 /* Flush partial sets of hard linked files. */
1440 if (!(fsm->mapFlags & CPIO_ALL_HARDLINKS)) {
1442 while ((fsm->li = fsm->links) != NULL) {
1443 fsm->links = fsm->li->next;
1444 fsm->li->next = NULL;
1446 /* Re-calculate link count for archive header. */
1447 for (j = -1, nlink = 0, i = 0; i < fsm->li->nlink; i++) {
1448 if (fsm->li->filex[i] < 0)
1449 /*@innercontinue@*/ continue;
1453 /* XXX force the contents out as well. */
1456 fsm->li->filex[0] = fsm->li->filex[j];
1457 fsm->li->filex[j] = -1;
1460 fsm->li->sb.st_nlink = nlink;
1462 fsm->sb = fsm->li->sb; /* structure assignment */
1463 fsm->osb = fsm->sb; /* structure assignment */
1465 if (!rc) rc = writeLinkedFile(fsm);
1467 fsm->li = freeHardLink(fsm->li);
1472 rc = fsmStage(fsm, FSM_TRAILER);
1476 { rpmts ts = fsmGetTs(fsm);
1477 #define _tsmask (RPMTRANS_FLAG_PKGCOMMIT | RPMTRANS_FLAG_COMMIT)
1478 fsm->commit = ((ts && (rpmtsFlags(ts) & _tsmask) &&
1479 fsm->goal != FSM_PKGCOMMIT) ? 0 : 1);
1482 fsm->path = _free(fsm->path);
1483 fsm->opath = _free(fsm->opath);
1484 fsm->dnlx = _free(fsm->dnlx);
1486 fsm->ldn = _free(fsm->ldn);
1487 fsm->ldnalloc = fsm->ldnlen = 0;
1489 fsm->rdsize = fsm->wrsize = 0;
1490 fsm->rdbuf = fsm->rdb = _free(fsm->rdb);
1491 fsm->wrbuf = fsm->wrb = _free(fsm->wrb);
1492 if (fsm->goal == FSM_PKGINSTALL || fsm->goal == FSM_PKGBUILD) {
1493 fsm->rdsize = 8 * BUFSIZ;
1494 fsm->rdbuf = fsm->rdb = xmalloc(fsm->rdsize);
1495 fsm->wrsize = 8 * BUFSIZ;
1496 fsm->wrbuf = fsm->wrb = xmalloc(fsm->wrsize);
1499 fsm->mkdirsdone = 0;
1504 errno = 0; /* XXX get rid of EBADF */
1507 /* Detect and create directories not explicitly in package. */
1508 if (fsm->goal == FSM_PKGINSTALL) {
1509 rc = fsmStage(fsm, FSM_MKDIRS);
1510 if (!rc) fsm->mkdirsdone = 1;
1515 fsm->path = _free(fsm->path);
1517 fsm->diskchecked = fsm->exists = 0;
1519 fsm->suffix = (fsm->sufbuf[0] != '\0' ? fsm->sufbuf : NULL);
1520 fsm->action = FA_UNKNOWN;
1521 fsm->osuffix = NULL;
1522 fsm->nsuffix = NULL;
1524 if (fsm->goal == FSM_PKGINSTALL) {
1525 /* Read next header from payload, checking for end-of-payload. */
1526 rc = fsmStage(fsm, FSM_NEXT);
1530 /* Identify mapping index. */
1531 fsm->ix = ((fsm->goal == FSM_PKGINSTALL)
1532 ? mapFind(fsm->iter, fsm->path) : mapNextIterator(fsm->iter));
1534 /* Detect end-of-loop and/or mapping error. */
1536 if (fsm->goal == FSM_PKGINSTALL) {
1538 rpmMessage(RPMMESS_WARNING,
1539 _("archive file %s was not found in header file list\n"),
1543 if (fsm->failedFile && *fsm->failedFile == NULL)
1544 *fsm->failedFile = xstrdup(fsm->path);
1546 rc = CPIOERR_UNMAPPED_FILE;
1548 rc = CPIOERR_HDR_TRAILER;
1553 /* On non-install, mode must be known so that dirs don't get suffix. */
1554 if (fsm->goal != FSM_PKGINSTALL) {
1555 rpmfi fi = fsmGetFi(fsm);
1556 st->st_mode = fi->fmodes[fsm->ix];
1559 /* Generate file path. */
1560 rc = fsmStage(fsm, FSM_MAP);
1563 /* Perform lstat/stat for disk file. */
1567 if (fsm->path != NULL &&
1568 !(fsm->goal == FSM_PKGINSTALL && S_ISREG(st->st_mode)))
1570 rc = fsmStage(fsm, (!(fsm->mapFlags & CPIO_FOLLOW_SYMLINKS)
1571 ? FSM_LSTAT : FSM_STAT));
1572 if (rc == CPIOERR_LSTAT_FAILED && errno == ENOENT) {
1578 } else if (rc == 0) {
1582 /* Skip %ghost files on build. */
1586 fsm->diskchecked = 1;
1589 /* On non-install, the disk file stat is what's remapped. */
1591 if (fsm->goal != FSM_PKGINSTALL)
1592 *st = *ost; /* structure assignment */
1595 /* Remap file perms, owner, and group. */
1596 rc = fsmMapAttrs(fsm);
1599 fsm->postpone = XFA_SKIPPING(fsm->action);
1600 if (fsm->goal == FSM_PKGINSTALL || fsm->goal == FSM_PKGBUILD) {
1601 /*@-evalorder@*/ /* FIX: saveHardLink can modify fsm */
1602 if (!S_ISDIR(st->st_mode) && st->st_nlink > 1)
1603 fsm->postpone = saveHardLink(fsm);
1610 rc = fsmMapPath(fsm);
1613 rc = fsmMkdirs(fsm);
1617 rc = fsmRmdirs(fsm);
1620 if (fsm->postpone) {
1621 if (fsm->goal == FSM_PKGINSTALL)
1622 rc = fsmStage(fsm, FSM_EAT);
1626 if (fsm->goal == FSM_PKGBUILD) {
1627 if (!S_ISDIR(st->st_mode) && st->st_nlink > 1) {
1628 struct hardLink_s * li, * prev;
1630 if (!(fsm->mapFlags & CPIO_ALL_HARDLINKS)) break;
1631 rc = writeLinkedFile(fsm);
1632 if (rc) break; /* W2DO? */
1634 for (li = fsm->links, prev = NULL; li; prev = li, li = li->next)
1636 /*@loopbreak@*/ break;
1639 fsm->links = fsm->li->next;
1641 prev->next = fsm->li->next;
1642 fsm->li->next = NULL;
1643 fsm->li = freeHardLink(fsm->li);
1645 rc = writeFile(fsm, 1);
1650 if (fsm->goal != FSM_PKGINSTALL)
1653 if (S_ISREG(st->st_mode)) {
1654 const char * path = fsm->path;
1656 fsm->path = fsmFsPath(fsm, st, NULL, NULL);
1657 rc = fsmStage(fsm, FSM_VERIFY);
1659 if (rc == 0 && fsm->osuffix) {
1660 const char * opath = fsm->opath;
1661 fsm->opath = fsm->path;
1662 fsm->path = fsmFsPath(fsm, st, NULL, fsm->osuffix);
1663 rc = fsmStage(fsm, FSM_RENAME);
1665 rpmMessage(RPMMESS_WARNING,
1666 _("%s saved as %s\n"), fsm->opath, fsm->path);
1667 fsm->path = _free(fsm->path);
1671 /*@-dependenttrans@*/
1673 /*@=dependenttrans@*/
1674 if (rc != CPIOERR_LSTAT_FAILED) return rc;
1675 rc = expandRegular(fsm);
1676 } else if (S_ISDIR(st->st_mode)) {
1677 mode_t st_mode = st->st_mode;
1678 rc = fsmStage(fsm, FSM_VERIFY);
1679 if (rc == CPIOERR_LSTAT_FAILED) {
1680 st->st_mode &= ~07777; /* XXX abuse st->st_mode */
1681 st->st_mode |= 00700;
1682 rc = fsmStage(fsm, FSM_MKDIR);
1683 st->st_mode = st_mode; /* XXX restore st->st_mode */
1685 } else if (S_ISLNK(st->st_mode)) {
1686 const char * opath = fsm->opath;
1688 if ((st->st_size + 1) > fsm->rdsize) {
1689 rc = CPIOERR_HDR_SIZE;
1693 fsm->wrlen = st->st_size;
1694 rc = fsmStage(fsm, FSM_DREAD);
1695 if (!rc && fsm->rdnb != fsm->wrlen)
1696 rc = CPIOERR_READ_FAILED;
1700 fsm->wrbuf[st->st_size] = '\0';
1702 /* XXX symlink(fsm->opath, fsm->path) */
1703 /*@-dependenttrans@*/
1704 fsm->opath = fsm->wrbuf;
1705 /*@=dependenttrans@*/
1706 rc = fsmStage(fsm, FSM_VERIFY);
1707 if (rc == CPIOERR_LSTAT_FAILED)
1708 rc = fsmStage(fsm, FSM_SYMLINK);
1709 fsm->opath = opath; /* XXX restore fsm->path */
1710 } else if (S_ISFIFO(st->st_mode)) {
1711 mode_t st_mode = st->st_mode;
1712 /* This mimics cpio S_ISSOCK() behavior but probably isnt' right */
1713 rc = fsmStage(fsm, FSM_VERIFY);
1714 if (rc == CPIOERR_LSTAT_FAILED) {
1715 st->st_mode = 0000; /* XXX abuse st->st_mode */
1716 rc = fsmStage(fsm, FSM_MKFIFO);
1717 st->st_mode = st_mode; /* XXX restore st->st_mode */
1719 } else if (S_ISCHR(st->st_mode) ||
1720 S_ISBLK(st->st_mode) ||
1721 /*@-unrecog@*/ S_ISSOCK(st->st_mode) /*@=unrecog@*/)
1723 rc = fsmStage(fsm, FSM_VERIFY);
1724 if (rc == CPIOERR_LSTAT_FAILED)
1725 rc = fsmStage(fsm, FSM_MKNOD);
1727 /* XXX Special case /dev/log, which shouldn't be packaged anyways */
1728 if (!IS_DEV_LOG(fsm->path))
1729 rc = CPIOERR_UNKNOWN_FILETYPE;
1731 if (!S_ISDIR(st->st_mode) && st->st_nlink > 1) {
1732 fsm->li->createdPath = fsm->li->linkIndex;
1733 rc = fsmMakeLinks(fsm);
1739 rc = fsmMakeLinks(fsm);
1741 case FSM_NOTIFY: /* XXX move from fsm to psm -> tsm */
1742 if (fsm->goal == FSM_PKGINSTALL || fsm->goal == FSM_PKGBUILD) {
1743 rpmts ts = fsmGetTs(fsm);
1744 rpmfi fi = fsmGetFi(fsm);
1746 ptr = rpmtsNotify(ts, fi->te, RPMCALLBACK_INST_PROGRESS,
1747 fdGetCpioPos(fsm->cfd), fi->archiveSize);
1753 if (fsm->goal == FSM_PKGINSTALL) {
1754 (void) fsmStage(fsm,
1755 (S_ISDIR(st->st_mode) ? FSM_RMDIR : FSM_UNLINK));
1757 #ifdef NOTYET /* XXX remove only dirs just created, not all. */
1759 (void) fsmStage(fsm, FSM_RMDIRS);
1766 if (fsm->failedFile && *fsm->failedFile == NULL)
1767 *fsm->failedFile = xstrdup(fsm->path);
1771 if (!fsm->postpone && fsm->commit) {
1772 if (fsm->goal == FSM_PKGINSTALL)
1773 rc = ((!S_ISDIR(st->st_mode) && st->st_nlink > 1)
1774 ? fsmCommitLinks(fsm) : fsmStage(fsm, FSM_COMMIT));
1775 if (fsm->goal == FSM_PKGCOMMIT)
1776 rc = fsmStage(fsm, FSM_COMMIT);
1777 if (fsm->goal == FSM_PKGERASE)
1778 rc = fsmStage(fsm, FSM_COMMIT);
1780 fsm->path = _free(fsm->path);
1781 fsm->opath = _free(fsm->opath);
1783 memset(st, 0, sizeof(*st));
1784 memset(ost, 0, sizeof(*ost));
1788 /* Rename pre-existing modified or unmanaged file. */
1789 if (fsm->osuffix && fsm->diskchecked &&
1790 (fsm->exists || (fsm->goal == FSM_PKGINSTALL && S_ISREG(st->st_mode))))
1792 const char * opath = fsm->opath;
1793 const char * path = fsm->path;
1794 fsm->opath = fsmFsPath(fsm, st, NULL, NULL);
1795 fsm->path = fsmFsPath(fsm, st, NULL, fsm->osuffix);
1796 rc = fsmStage(fsm, FSM_RENAME);
1798 rpmMessage(RPMMESS_WARNING, _("%s saved as %s\n"),
1799 fsm->opath, fsm->path);
1801 fsm->path = _free(fsm->path);
1803 fsm->opath = _free(fsm->opath);
1807 /* Remove erased files. */
1808 if (fsm->goal == FSM_PKGERASE) {
1809 if (fsm->action == FA_ERASE) {
1810 rpmfi fi = fsmGetFi(fsm);
1811 if (S_ISDIR(st->st_mode)) {
1812 rc = fsmStage(fsm, FSM_RMDIR);
1815 case ENOENT: /* XXX rmdir("/") linux 2.2.x kernel hack */
1817 /* XXX make sure that build side permits %missingok on directories. */
1818 if (fsm->fflags & RPMFILE_MISSINGOK)
1819 /*@innerbreak@*/ break;
1821 /* XXX common error message. */
1823 (strict_erasures ? RPMERR_RMDIR : RPMDEBUG_RMDIR),
1824 _("%s rmdir of %s failed: Directory not empty\n"),
1825 fiTypeString(fi), fsm->path);
1826 /*@innerbreak@*/ break;
1829 (strict_erasures ? RPMERR_RMDIR : RPMDEBUG_RMDIR),
1830 _("%s rmdir of %s failed: %s\n"),
1831 fiTypeString(fi), fsm->path, strerror(errno));
1832 /*@innerbreak@*/ break;
1835 rc = fsmStage(fsm, FSM_UNLINK);
1837 if (!(errno == ENOENT && (fsm->fflags & RPMFILE_MISSINGOK)))
1839 (strict_erasures ? RPMERR_UNLINK : RPMDEBUG_UNLINK),
1840 _("%s unlink of %s failed: %s\n"),
1841 fiTypeString(fi), fsm->path, strerror(errno));
1844 /* XXX Failure to remove is not (yet) cause for failure. */
1845 if (!strict_erasures) rc = 0;
1849 /* XXX Special case /dev/log, which shouldn't be packaged anyways */
1850 if (!S_ISSOCK(st->st_mode) && !IS_DEV_LOG(fsm->path)) {
1851 /* Rename temporary to final file name. */
1852 if (!S_ISDIR(st->st_mode) &&
1853 (fsm->subdir || fsm->suffix || fsm->nsuffix))
1855 fsm->opath = fsm->path;
1856 fsm->path = fsmFsPath(fsm, st, NULL, fsm->nsuffix);
1857 rc = fsmStage(fsm, FSM_RENAME);
1858 if (!rc && fsm->nsuffix) {
1859 const char * opath = fsmFsPath(fsm, st, NULL, NULL);
1860 rpmMessage(RPMMESS_WARNING, _("%s created as %s\n"),
1861 (opath ? opath : ""), fsm->path);
1862 opath = _free(opath);
1864 fsm->opath = _free(fsm->opath);
1866 if (S_ISLNK(st->st_mode)) {
1867 if (!rc && !getuid())
1868 rc = fsmStage(fsm, FSM_LCHOWN);
1870 if (!rc && !getuid())
1871 rc = fsmStage(fsm, FSM_CHOWN);
1873 rc = fsmStage(fsm, FSM_CHMOD);
1875 time_t mtime = st->st_mtime;
1876 rpmfi fi = fsmGetFi(fsm);
1878 st->st_mtime = fi->fmtimes[fsm->ix];
1879 rc = fsmStage(fsm, FSM_UTIME);
1880 st->st_mtime = mtime;
1885 /* Notify on success. */
1886 if (!rc) rc = fsmStage(fsm, FSM_NOTIFY);
1887 else if (fsm->failedFile && *fsm->failedFile == NULL) {
1889 *fsm->failedFile = fsm->path;
1895 fsm->path = _free(fsm->path);
1897 /* Check for hard links missing from payload. */
1898 while ((fsm->li = fsm->links) != NULL) {
1899 fsm->links = fsm->li->next;
1900 fsm->li->next = NULL;
1901 if (fsm->goal == FSM_PKGINSTALL &&
1902 fsm->commit && fsm->li->linksLeft)
1904 for (i = 0 ; i < fsm->li->linksLeft; i++) {
1905 if (fsm->li->filex[i] < 0)
1906 /*@innercontinue@*/ continue;
1907 rc = CPIOERR_MISSING_HARDLINK;
1908 if (fsm->failedFile && *fsm->failedFile == NULL) {
1909 fsm->ix = fsm->li->filex[i];
1910 if (!fsmStage(fsm, FSM_MAP)) {
1912 *fsm->failedFile = fsm->path;
1917 /*@loopbreak@*/ break;
1920 if (fsm->goal == FSM_PKGBUILD &&
1921 (fsm->mapFlags & CPIO_ALL_HARDLINKS))
1923 rc = CPIOERR_MISSING_HARDLINK;
1925 fsm->li = freeHardLink(fsm->li);
1927 fsm->ldn = _free(fsm->ldn);
1928 fsm->ldnalloc = fsm->ldnlen = 0;
1929 fsm->rdbuf = fsm->rdb = _free(fsm->rdb);
1930 fsm->wrbuf = fsm->wrb = _free(fsm->wrb);
1933 if (fsm->diskchecked && !fsm->exists) {
1934 rc = CPIOERR_LSTAT_FAILED;
1937 if (S_ISREG(st->st_mode)) {
1938 char * path = alloca(strlen(fsm->path) + sizeof("-RPMDELETE"));
1940 (void) stpcpy( stpcpy(path, fsm->path), "-RPMDELETE");
1943 * XXX HP-UX (and other os'es) don't permit unlink on busy
1946 fsm->opath = fsm->path;
1948 rc = fsmStage(fsm, FSM_RENAME);
1950 (void) fsmStage(fsm, FSM_UNLINK);
1952 rc = CPIOERR_UNLINK_FAILED;
1953 fsm->path = fsm->opath;
1955 return (rc ? rc : CPIOERR_LSTAT_FAILED); /* XXX HACK */
1956 /*@notreached@*/ break;
1957 } else if (S_ISDIR(st->st_mode)) {
1958 if (S_ISDIR(ost->st_mode)) return 0;
1959 if (S_ISLNK(ost->st_mode)) {
1960 rc = fsmStage(fsm, FSM_STAT);
1961 if (rc == CPIOERR_STAT_FAILED && errno == ENOENT) rc = 0;
1966 if (S_ISDIR(ost->st_mode)) return 0;
1968 } else if (S_ISLNK(st->st_mode)) {
1969 if (S_ISLNK(ost->st_mode)) {
1970 /* XXX NUL terminated result in fsm->rdbuf, len in fsm->rdnb. */
1971 rc = fsmStage(fsm, FSM_READLINK);
1976 if (!strcmp(fsm->opath, fsm->rdbuf)) return 0;
1978 } else if (S_ISFIFO(st->st_mode)) {
1979 if (S_ISFIFO(ost->st_mode)) return 0;
1980 } else if (S_ISCHR(st->st_mode) || S_ISBLK(st->st_mode)) {
1981 if ((S_ISCHR(ost->st_mode) || S_ISBLK(ost->st_mode)) &&
1982 (ost->st_rdev == st->st_rdev)) return 0;
1983 } else if (S_ISSOCK(st->st_mode)) {
1984 if (S_ISSOCK(ost->st_mode)) return 0;
1986 /* XXX shouldn't do this with commit/undo. */
1988 if (fsm->stage == FSM_PROCESS) rc = fsmStage(fsm, FSM_UNLINK);
1989 if (rc == 0) rc = CPIOERR_LSTAT_FAILED;
1990 return (rc ? rc : CPIOERR_LSTAT_FAILED); /* XXX HACK */
1991 /*@notreached@*/ break;
1994 rc = Unlink(fsm->path);
1995 if (_fsm_debug && (stage & FSM_SYSCALL))
1996 rpmMessage(RPMMESS_DEBUG, " %8s (%s) %s\n", cur,
1997 fsm->path, (rc < 0 ? strerror(errno) : ""));
1998 if (rc < 0) rc = CPIOERR_UNLINK_FAILED;
2001 rc = Rename(fsm->opath, fsm->path);
2002 if (_fsm_debug && (stage & FSM_SYSCALL))
2003 rpmMessage(RPMMESS_DEBUG, " %8s (%s, %s) %s\n", cur,
2004 fsm->opath, fsm->path, (rc < 0 ? strerror(errno) : ""));
2005 if (rc < 0) rc = CPIOERR_RENAME_FAILED;
2008 rc = Mkdir(fsm->path, (st->st_mode & 07777));
2009 if (_fsm_debug && (stage & FSM_SYSCALL))
2010 rpmMessage(RPMMESS_DEBUG, " %8s (%s, 0%04o) %s\n", cur,
2011 fsm->path, (unsigned)(st->st_mode & 07777),
2012 (rc < 0 ? strerror(errno) : ""));
2013 if (rc < 0) rc = CPIOERR_MKDIR_FAILED;
2016 rc = Rmdir(fsm->path);
2017 if (_fsm_debug && (stage & FSM_SYSCALL))
2018 rpmMessage(RPMMESS_DEBUG, " %8s (%s) %s\n", cur,
2019 fsm->path, (rc < 0 ? strerror(errno) : ""));
2020 if (rc < 0) rc = CPIOERR_RMDIR_FAILED;
2023 rc = chown(fsm->path, st->st_uid, st->st_gid);
2024 if (_fsm_debug && (stage & FSM_SYSCALL))
2025 rpmMessage(RPMMESS_DEBUG, " %8s (%s, %d, %d) %s\n", cur,
2026 fsm->path, (int)st->st_uid, (int)st->st_gid,
2027 (rc < 0 ? strerror(errno) : ""));
2028 if (rc < 0) rc = CPIOERR_CHOWN_FAILED;
2031 #if ! CHOWN_FOLLOWS_SYMLINK
2032 rc = lchown(fsm->path, st->st_uid, st->st_gid);
2033 if (_fsm_debug && (stage & FSM_SYSCALL))
2034 rpmMessage(RPMMESS_DEBUG, " %8s (%s, %d, %d) %s\n", cur,
2035 fsm->path, (int)st->st_uid, (int)st->st_gid,
2036 (rc < 0 ? strerror(errno) : ""));
2037 if (rc < 0) rc = CPIOERR_CHOWN_FAILED;
2041 rc = chmod(fsm->path, (st->st_mode & 07777));
2042 if (_fsm_debug && (stage & FSM_SYSCALL))
2043 rpmMessage(RPMMESS_DEBUG, " %8s (%s, 0%04o) %s\n", cur,
2044 fsm->path, (unsigned)(st->st_mode & 07777),
2045 (rc < 0 ? strerror(errno) : ""));
2046 if (rc < 0) rc = CPIOERR_CHMOD_FAILED;
2049 { struct utimbuf stamp;
2050 stamp.actime = st->st_mtime;
2051 stamp.modtime = st->st_mtime;
2052 rc = utime(fsm->path, &stamp);
2053 if (_fsm_debug && (stage & FSM_SYSCALL))
2054 rpmMessage(RPMMESS_DEBUG, " %8s (%s, 0x%x) %s\n", cur,
2055 fsm->path, (unsigned)st->st_mtime,
2056 (rc < 0 ? strerror(errno) : ""));
2057 if (rc < 0) rc = CPIOERR_UTIME_FAILED;
2061 rc = symlink(fsm->opath, fsm->path);
2062 if (_fsm_debug && (stage & FSM_SYSCALL))
2063 rpmMessage(RPMMESS_DEBUG, " %8s (%s, %s) %s\n", cur,
2064 fsm->opath, fsm->path, (rc < 0 ? strerror(errno) : ""));
2065 if (rc < 0) rc = CPIOERR_SYMLINK_FAILED;
2068 rc = Link(fsm->opath, fsm->path);
2069 if (_fsm_debug && (stage & FSM_SYSCALL))
2070 rpmMessage(RPMMESS_DEBUG, " %8s (%s, %s) %s\n", cur,
2071 fsm->opath, fsm->path, (rc < 0 ? strerror(errno) : ""));
2072 if (rc < 0) rc = CPIOERR_LINK_FAILED;
2075 rc = mkfifo(fsm->path, (st->st_mode & 07777));
2076 if (_fsm_debug && (stage & FSM_SYSCALL))
2077 rpmMessage(RPMMESS_DEBUG, " %8s (%s, 0%04o) %s\n", cur,
2078 fsm->path, (unsigned)(st->st_mode & 07777),
2079 (rc < 0 ? strerror(errno) : ""));
2080 if (rc < 0) rc = CPIOERR_MKFIFO_FAILED;
2083 /*@-unrecog -portability @*/ /* FIX: check S_IFIFO or dev != 0 */
2084 rc = mknod(fsm->path, (st->st_mode & ~07777), st->st_rdev);
2085 /*@=unrecog =portability @*/
2086 if (_fsm_debug && (stage & FSM_SYSCALL))
2087 rpmMessage(RPMMESS_DEBUG, " %8s (%s, 0%o, 0x%x) %s\n", cur,
2088 fsm->path, (unsigned)(st->st_mode & ~07777),
2089 (unsigned)st->st_rdev,
2090 (rc < 0 ? strerror(errno) : ""));
2091 if (rc < 0) rc = CPIOERR_MKNOD_FAILED;
2094 rc = Lstat(fsm->path, ost);
2095 if (_fsm_debug && (stage & FSM_SYSCALL) && rc && errno != ENOENT)
2096 rpmMessage(RPMMESS_DEBUG, " %8s (%s, ost) %s\n", cur,
2097 fsm->path, (rc < 0 ? strerror(errno) : ""));
2098 if (rc < 0) rc = CPIOERR_LSTAT_FAILED;
2101 rc = Stat(fsm->path, ost);
2102 if (_fsm_debug && (stage & FSM_SYSCALL) && rc && errno != ENOENT)
2103 rpmMessage(RPMMESS_DEBUG, " %8s (%s, ost) %s\n", cur,
2104 fsm->path, (rc < 0 ? strerror(errno) : ""));
2105 if (rc < 0) rc = CPIOERR_STAT_FAILED;
2108 /* XXX NUL terminated result in fsm->rdbuf, len in fsm->rdnb. */
2110 rc = Readlink(fsm->path, fsm->rdbuf, fsm->rdsize - 1);
2112 if (_fsm_debug && (stage & FSM_SYSCALL))
2113 rpmMessage(RPMMESS_DEBUG, " %8s (%s, rdbuf, %d) %s\n", cur,
2114 fsm->path, (int)(fsm->rdsize -1), (rc < 0 ? strerror(errno) : ""));
2115 if (rc < 0) rc = CPIOERR_READLINK_FAILED;
2119 fsm->rdbuf[fsm->rdnb] = '\0';
2128 rc = fsmStage(fsm, FSM_HREAD);
2130 if (!strcmp(fsm->path, CPIO_TRAILER)) { /* Detect end-of-payload. */
2131 fsm->path = _free(fsm->path);
2132 rc = CPIOERR_HDR_TRAILER;
2135 rc = fsmStage(fsm, FSM_POS);
2138 for (left = st->st_size; left > 0; left -= fsm->rdnb) {
2139 fsm->wrlen = (left > fsm->wrsize ? fsm->wrsize : left);
2140 rc = fsmStage(fsm, FSM_DREAD);
2142 /*@loopbreak@*/ break;
2146 left = (modulo - (fdGetCpioPos(fsm->cfd) % modulo)) % modulo;
2149 (void) fsmStage(fsm, FSM_DREAD);
2153 left = (modulo - (fdGetCpioPos(fsm->cfd) % modulo)) % modulo;
2156 memset(fsm->rdbuf, 0, left);
2158 /* XXX DWRITE uses rdnb for I/O length. */
2160 (void) fsmStage(fsm, FSM_DWRITE);
2164 rc = cpioTrailerWrite(fsm);
2167 rc = fsmStage(fsm, FSM_POS);
2169 rc = cpioHeaderRead(fsm, st); /* Read next payload header. */
2172 rc = cpioHeaderWrite(fsm, st); /* Write next payload header. */
2176 fsm->rdnb = Fread(fsm->wrbuf, sizeof(*fsm->wrbuf), fsm->wrlen, fsm->cfd);
2178 if (_fsm_debug && (stage & FSM_SYSCALL))
2179 rpmMessage(RPMMESS_DEBUG, " %8s (%s, %d, cfd)\trdnb %d\n",
2180 cur, (fsm->wrbuf == fsm->wrb ? "wrbuf" : "mmap"),
2181 (int)fsm->wrlen, (int)fsm->rdnb);
2182 if (fsm->rdnb != fsm->wrlen || Ferror(fsm->cfd))
2183 rc = CPIOERR_READ_FAILED;
2185 fdSetCpioPos(fsm->cfd, fdGetCpioPos(fsm->cfd) + fsm->rdnb);
2188 fsm->wrnb = Fwrite(fsm->rdbuf, sizeof(*fsm->rdbuf), fsm->rdnb, fsm->cfd);
2189 if (_fsm_debug && (stage & FSM_SYSCALL))
2190 rpmMessage(RPMMESS_DEBUG, " %8s (%s, %d, cfd)\twrnb %d\n",
2191 cur, (fsm->rdbuf == fsm->rdb ? "rdbuf" : "mmap"),
2192 (int)fsm->rdnb, (int)fsm->wrnb);
2193 if (fsm->rdnb != fsm->wrnb || Ferror(fsm->cfd))
2194 rc = CPIOERR_WRITE_FAILED;
2196 fdSetCpioPos(fsm->cfd, fdGetCpioPos(fsm->cfd) + fsm->wrnb);
2200 fsm->rfd = Fopen(fsm->path, "r.ufdio");
2201 if (fsm->rfd == NULL || Ferror(fsm->rfd)) {
2202 if (fsm->rfd) (void) fsmStage(fsm, FSM_RCLOSE);
2204 rc = CPIOERR_OPEN_FAILED;
2207 if (_fsm_debug && (stage & FSM_SYSCALL))
2208 rpmMessage(RPMMESS_DEBUG, " %8s (%s, \"r\") rfd %p rdbuf %p\n", cur,
2209 fsm->path, fsm->rfd, fsm->rdbuf);
2213 fsm->rdnb = Fread(fsm->rdbuf, sizeof(*fsm->rdbuf), fsm->rdlen, fsm->rfd);
2215 if (_fsm_debug && (stage & FSM_SYSCALL))
2216 rpmMessage(RPMMESS_DEBUG, " %8s (rdbuf, %d, rfd)\trdnb %d\n",
2217 cur, (int)fsm->rdlen, (int)fsm->rdnb);
2218 if (fsm->rdnb != fsm->rdlen || Ferror(fsm->rfd))
2219 rc = CPIOERR_READ_FAILED;
2223 if (_fsm_debug && (stage & FSM_SYSCALL))
2224 rpmMessage(RPMMESS_DEBUG, " %8s (%p)\n", cur, fsm->rfd);
2225 (void) Fclose(fsm->rfd);
2233 fsm->wfd = Fopen(fsm->path, "w.ufdio");
2234 if (fsm->wfd == NULL || Ferror(fsm->wfd)) {
2235 if (fsm->wfd) (void) fsmStage(fsm, FSM_WCLOSE);
2237 rc = CPIOERR_OPEN_FAILED;
2239 if (_fsm_debug && (stage & FSM_SYSCALL))
2240 rpmMessage(RPMMESS_DEBUG, " %8s (%s, \"w\") wfd %p wrbuf %p\n", cur,
2241 fsm->path, fsm->wfd, fsm->wrbuf);
2244 fsm->wrnb = Fwrite(fsm->wrbuf, sizeof(*fsm->wrbuf), fsm->rdnb, fsm->wfd);
2245 if (_fsm_debug && (stage & FSM_SYSCALL))
2246 rpmMessage(RPMMESS_DEBUG, " %8s (wrbuf, %d, wfd)\twrnb %d\n",
2247 cur, (int)fsm->rdnb, (int)fsm->wrnb);
2248 if (fsm->rdnb != fsm->wrnb || Ferror(fsm->wfd))
2249 rc = CPIOERR_WRITE_FAILED;
2253 if (_fsm_debug && (stage & FSM_SYSCALL))
2254 rpmMessage(RPMMESS_DEBUG, " %8s (%p)\n", cur, fsm->wfd);
2255 (void) Fclose(fsm->wfd);
2268 if (!(stage & FSM_INTERNAL)) {
2269 fsm->rc = (rc == CPIOERR_HDR_TRAILER ? 0 : rc);
2276 /*@obserever@*/ const char *const fileActionString(fileAction a)
2279 case FA_UNKNOWN: return "unknown";
2280 case FA_CREATE: return "create";
2281 case FA_COPYOUT: return "copyout";
2282 case FA_COPYIN: return "copyin";
2283 case FA_BACKUP: return "backup";
2284 case FA_SAVE: return "save";
2285 case FA_SKIP: return "skip";
2286 case FA_ALTNAME: return "altname";
2287 case FA_ERASE: return "erase";
2288 case FA_SKIPNSTATE: return "skipnstate";
2289 case FA_SKIPNETSHARED: return "skipnetshared";
2290 case FA_SKIPMULTILIB: return "skipmultilib";
2291 default: return "???";
2296 /*@observer@*/ const char *const fileStageString(fileStage a) {
2298 case FSM_UNKNOWN: return "unknown";
2300 case FSM_PKGINSTALL:return "INSTALL";
2301 case FSM_PKGERASE: return "ERASE";
2302 case FSM_PKGBUILD: return "BUILD";
2303 case FSM_PKGCOMMIT: return "COMMIT";
2304 case FSM_PKGUNDO: return "UNDO";
2306 case FSM_CREATE: return "create";
2307 case FSM_INIT: return "init";
2308 case FSM_MAP: return "map";
2309 case FSM_MKDIRS: return "mkdirs";
2310 case FSM_RMDIRS: return "rmdirs";
2311 case FSM_PRE: return "pre";
2312 case FSM_PROCESS: return "process";
2313 case FSM_POST: return "post";
2314 case FSM_MKLINKS: return "mklinks";
2315 case FSM_NOTIFY: return "notify";
2316 case FSM_UNDO: return "undo";
2317 case FSM_FINI: return "fini";
2318 case FSM_COMMIT: return "commit";
2319 case FSM_DESTROY: return "destroy";
2320 case FSM_VERIFY: return "verify";
2322 case FSM_UNLINK: return "Unlink";
2323 case FSM_RENAME: return "Rename";
2324 case FSM_MKDIR: return "Mkdir";
2325 case FSM_RMDIR: return "rmdir";
2326 case FSM_CHOWN: return "chown";
2327 case FSM_LCHOWN: return "lchown";
2328 case FSM_CHMOD: return "chmod";
2329 case FSM_UTIME: return "utime";
2330 case FSM_SYMLINK: return "symlink";
2331 case FSM_LINK: return "Link";
2332 case FSM_MKFIFO: return "mkfifo";
2333 case FSM_MKNOD: return "mknod";
2334 case FSM_LSTAT: return "Lstat";
2335 case FSM_STAT: return "Stat";
2336 case FSM_READLINK: return "Readlink";
2337 case FSM_CHROOT: return "chroot";
2339 case FSM_NEXT: return "next";
2340 case FSM_EAT: return "eat";
2341 case FSM_POS: return "pos";
2342 case FSM_PAD: return "pad";
2343 case FSM_TRAILER: return "trailer";
2344 case FSM_HREAD: return "hread";
2345 case FSM_HWRITE: return "hwrite";
2346 case FSM_DREAD: return "Fread";
2347 case FSM_DWRITE: return "Fwrite";
2349 case FSM_ROPEN: return "Fopen";
2350 case FSM_READ: return "Fread";
2351 case FSM_RCLOSE: return "Fclose";
2352 case FSM_WOPEN: return "Fopen";
2353 case FSM_WRITE: return "Fwrite";
2354 case FSM_WCLOSE: return "Fclose";
2356 default: return "???";