3 * File state machine to handle a payload from a package.
10 #if defined(HAVE_MMAP)
14 #include <sys/capability.h>
17 #include <rpm/rpmte.h>
18 #include <rpm/rpmts.h>
19 #include <rpm/rpmsq.h>
20 #include <rpm/rpmlog.h>
22 #include "rpmio/rpmio_internal.h" /* fdInit/FiniDigest */
25 #define fsmUNSAFE fsmStage
26 #include "lib/rpmfi_internal.h" /* XXX fi->apath, ... */
27 #include "lib/rpmte_internal.h" /* XXX rpmfs */
28 #include "lib/misc.h" /* XXX unameToUid() and gnameToGid() */
33 int _fsm_debug = _FSM_DEBUG;
35 /* XXX Failure to remove is not (yet) cause for failure. */
36 static int strict_erasures = 0;
39 * Keeps track of the set of all hard links to a file in an archive.
43 const char ** nsuffix;
53 * Iterator across package file info, forward on install, backward on erase.
55 struct fsmIterator_s {
56 rpmts ts; /*!< transaction set. */
57 rpmte te; /*!< transaction element. */
58 rpmfi fi; /*!< transaction element file info. */
59 int reverse; /*!< reversed traversal? */
60 int isave; /*!< last returned iterator index. */
61 int i; /*!< iterator index. */
65 * Retrieve transaction set from file state machine iterator.
66 * @param fsm file state machine
67 * @return transaction set
69 static rpmts fsmGetTs(const FSM_t fsm) {
70 const FSMI_t iter = fsm->iter;
71 return (iter ? iter->ts : NULL);
75 * Retrieve transaction element file info from file state machine iterator.
76 * @param fsm file state machine
77 * @return transaction element file info
79 static rpmfi fsmGetFi(const FSM_t fsm)
81 const FSMI_t iter = fsm->iter;
82 return (iter ? iter->fi : NULL);
85 static rpmte fsmGetTe(const FSM_t fsm)
87 const FSMI_t iter = fsm->iter;
88 return (iter ? iter->te : NULL);
91 #define SUFFIX_RPMORIG ".rpmorig"
92 #define SUFFIX_RPMSAVE ".rpmsave"
93 #define SUFFIX_RPMNEW ".rpmnew"
95 /* Default directory and file permissions if not mapped */
96 #define _dirPerms 0755
97 #define _filePerms 0644
100 * XXX Forward declarations for previously exported functions to avoid moving
101 * things around needlessly
103 static const char * fileStageString(fileStage a);
104 static const char * fileActionString(rpmFileAction a);
105 static int fsmStage(FSM_t fsm, fileStage stage);
108 * Build path to file from file info, ornamented with subdir and suffix.
109 * @param fsm file state machine data
110 * @param st file stat info
111 * @param subdir subdir to use (NULL disables)
112 * @param suffix suffix to use (NULL disables)
113 * @retval path to file (malloced)
115 static char * fsmFsPath(const FSM_t fsm,
116 const struct stat * st,
123 int isDir = (st && S_ISDIR(st->st_mode));
124 s = rstrscat(NULL, fsm->dirName,
125 (!isDir && subdir) ? subdir : "",
127 (!isDir && suffix) ? suffix : "",
134 * Destroy file info iterator.
135 * @param p file info iterator
136 * @retval NULL always
138 static void * mapFreeIterator(void * p)
142 /* XXX rpmswExit() */
143 iter->ts = rpmtsFree(iter->ts);
144 iter->te = NULL; /* XXX rpmte is not refcounted yet */
145 iter->fi = rpmfiUnlink(iter->fi);
151 * Create file info iterator.
152 * @param ts transaction set
153 * @param fi transaction element file info
154 * @return file info iterator
157 mapInitIterator(rpmts ts, rpmte te, rpmfi fi)
161 iter = xcalloc(1, sizeof(*iter));
162 iter->ts = rpmtsLink(ts);
163 iter->te = te; /* XXX rpmte is not refcounted yet */
164 iter->fi = rpmfiLink(fi);
165 iter->reverse = (rpmteType(te) == TR_REMOVED);
166 iter->i = (iter->reverse ? (rpmfiFC(fi) - 1) : 0);
167 iter->isave = iter->i;
172 * Return next index into file info.
173 * @param a file info iterator
174 * @return next index, -1 on termination
176 static int mapNextIterator(void * a)
182 const rpmfi fi = iter->fi;
184 if (iter->i >= 0) i = iter->i--;
186 if (iter->i < rpmfiFC(fi)) i = iter->i++;
195 static int cpioStrCmp(const void * a, const void * b)
197 const char * afn = *(const char **)a;
198 const char * bfn = *(const char **)b;
200 /* Match rpm-4.0 payloads with ./ prefixes. */
201 if (afn[0] == '.' && afn[1] == '/') afn += 2;
202 if (bfn[0] == '.' && bfn[1] == '/') bfn += 2;
204 /* If either path is absolute, make it relative. */
205 if (afn[0] == '/') afn += 1;
206 if (bfn[0] == '/') bfn += 1;
208 return strcmp(afn, bfn);
212 * Locate archive path in file info.
213 * @param iter file info iterator
214 * @param fsmPath archive path
215 * @return index into file info, -1 if archive path was not found
217 static int mapFind(FSMI_t iter, const char * fsmPath)
222 const rpmfi fi = iter->fi;
223 int fc = rpmfiFC(fi);
224 if (fi && fc > 0 && fi->apath && fsmPath && *fsmPath) {
227 if (fi->apath != NULL)
228 p = bsearch(&fsmPath, fi->apath, fc, sizeof(fsmPath),
231 iter->i = p - fi->apath;
232 ix = mapNextIterator(iter);
240 * Directory name iterator.
242 typedef struct dnli_s {
251 * Destroy directory name iterator.
252 * @param a directory name iterator
253 * @retval NULL always
255 static void * dnlFreeIterator(void * a)
258 DNLI_t dnli = (void *)a;
259 if (dnli->active) free(dnli->active);
266 static inline int dnlCount(const DNLI_t dnli)
268 return (dnli ? rpmfiDC(dnli->fi) : 0);
273 static inline int dnlIndex(const DNLI_t dnli)
275 return (dnli ? dnli->isave : -1);
279 * Create directory name iterator.
280 * @param fsm file state machine data
281 * @param reverse traverse directory names in reverse order?
282 * @return directory name iterator
285 void * dnlInitIterator(const FSM_t fsm,
289 rpmfi fi = fsmGetFi(fsm);
290 rpmfs fs = rpmteGetFileStates(fsmGetTe(fsm));
298 dnli = xcalloc(1, sizeof(*dnli));
300 dnli->reverse = reverse;
301 dnli->i = (reverse ? dc : 0);
304 dnli->active = xcalloc(dc, sizeof(*dnli->active));
305 int fc = rpmfiFC(fi);
307 /* Identify parent directories not skipped. */
308 for (i = 0; i < fc; i++)
309 if (!XFA_SKIPPING(rpmfsGetAction(fs, i)))
310 dnli->active[rpmfiDIIndex(fi, i)] = 1;
312 /* Exclude parent directories that are explicitly included. */
313 for (i = 0; i < fc; i++) {
317 if (!S_ISDIR(rpmfiFModeIndex(fi, i)))
320 dil = rpmfiDIIndex(fi, i);
321 dnlen = strlen(rpmfiDNIndex(fi, dil));
322 bnlen = strlen(rpmfiBNIndex(fi, i));
324 for (j = 0; j < dc; j++) {
328 if (!dnli->active[j] || j == dil)
330 dnl = rpmfiDNIndex(fi, j);
332 if (jlen != (dnlen+bnlen+1))
334 if (!rstreqn(dnl, rpmfiDNIndex(fi, dil), dnlen))
336 if (!rstreqn(dnl+dnlen, rpmfiBNIndex(fi, i), bnlen))
338 if (dnl[dnlen+bnlen] != '/' || dnl[dnlen+bnlen+1] != '\0')
340 /* This directory is included in the package. */
346 /* Print only once per package. */
349 for (i = 0; i < dc; i++) {
350 if (!dnli->active[i]) continue;
354 "========== Directories not explicitly included in package:\n");
356 rpmlog(RPMLOG_DEBUG, "%10d %s\n", i, rpmfiDNIndex(fi, i));
359 rpmlog(RPMLOG_DEBUG, "==========\n");
366 * Return next directory name (from file info).
367 * @param dnli directory name iterator
368 * @return next directory name
371 const char * dnlNextIterator(DNLI_t dnli)
373 const char * dn = NULL;
377 int dc = rpmfiDC(fi);
382 i = (!dnli->reverse ? dnli->i++ : --dnli->i);
383 } while (i >= 0 && i < dc && !dnli->active[i]);
385 if (i >= 0 && i < dc)
386 dn = rpmfiDNIndex(fi, i);
394 int fsmNext(FSM_t fsm, fileStage nstage)
396 fsm->nstage = nstage;
397 return fsmStage(fsm, fsm->nstage);
401 * Map next file path and action.
402 * @param fsm file state machine
404 static int fsmMapPath(FSM_t fsm)
406 rpmfi fi = fsmGetFi(fsm); /* XXX const except for fstates */
412 fsm->action = FA_UNKNOWN;
415 if (fi && i >= 0 && i < rpmfiFC(fi)) {
416 rpmte te = fsmGetTe(fsm);
417 rpmfs fs = rpmteGetFileStates(te);
418 /* XXX these should use rpmfiFFlags() etc */
419 fsm->action = rpmfsGetAction(fs, i);
420 fsm->fflags = rpmfiFFlagsIndex(fi, i);
422 /* src rpms have simple base name in payload. */
423 fsm->dirName = rpmfiDNIndex(fi, rpmfiDIIndex(fi, i));
424 fsm->baseName = rpmfiBNIndex(fi, i);
426 if (rpmteType(te) == TR_ADDED) {
427 switch (fsm->action) {
429 rpmfsSetState(fs, i, RPMFILE_STATE_NOTINSTALLED);
431 case FA_SKIPNETSHARED:
432 rpmfsSetState(fs, i, RPMFILE_STATE_NETSHARED);
435 rpmfsSetState(fs, i, RPMFILE_STATE_WRONGCOLOR);
438 if (!(fsm->fflags & RPMFILE_GHOST)) /* XXX Don't if %ghost file. */
439 fsm->nsuffix = SUFFIX_RPMNEW;
442 if (!(fsm->fflags & RPMFILE_GHOST)) /* XXX Don't if %ghost file. */
443 fsm->osuffix = SUFFIX_RPMSAVE;
450 if (fsm->action == FA_BACKUP && !(fsm->fflags & RPMFILE_GHOST)) {
451 /* XXX Don't if %ghost file. */
452 fsm->osuffix = (rpmteType(te) == TR_ADDED) ? SUFFIX_RPMORIG : SUFFIX_RPMSAVE;
455 if ((fsm->mapFlags & CPIO_MAP_PATH) || fsm->nsuffix) {
456 const struct stat * st = &fsm->sb;
457 fsm->path = _free(fsm->path);
458 fsm->path = fsmFsPath(fsm, st, fsm->subdir,
459 (fsm->suffix ? fsm->suffix : fsm->nsuffix));
466 * Save hard link in chain.
467 * @param fsm file state machine data
468 * @return Is chain only partially filled?
470 static int saveHardLink(FSM_t fsm)
472 struct stat * st = &fsm->sb;
477 /* Find hard link set. */
478 for (fsm->li = fsm->links; fsm->li; fsm->li = fsm->li->next) {
479 if (fsm->li->sb.st_ino == st->st_ino && fsm->li->sb.st_dev == st->st_dev)
483 /* New hard link encountered, add new link to set. */
484 if (fsm->li == NULL) {
485 fsm->li = xcalloc(1, sizeof(*fsm->li));
486 fsm->li->next = NULL;
487 fsm->li->sb = *st; /* structure assignment */
488 fsm->li->nlink = st->st_nlink;
489 fsm->li->linkIndex = fsm->ix;
490 fsm->li->createdPath = -1;
492 fsm->li->filex = xcalloc(st->st_nlink, sizeof(fsm->li->filex[0]));
493 memset(fsm->li->filex, -1, (st->st_nlink * sizeof(fsm->li->filex[0])));
494 fsm->li->nsuffix = xcalloc(st->st_nlink, sizeof(*fsm->li->nsuffix));
496 if (fsm->goal == FSM_PKGBUILD)
497 fsm->li->linksLeft = st->st_nlink;
498 if (fsm->goal == FSM_PKGINSTALL)
499 fsm->li->linksLeft = 0;
501 fsm->li->next = fsm->links;
502 fsm->links = fsm->li;
505 if (fsm->goal == FSM_PKGBUILD) --fsm->li->linksLeft;
506 fsm->li->filex[fsm->li->linksLeft] = fsm->ix;
507 fsm->li->nsuffix[fsm->li->linksLeft] = fsm->nsuffix;
508 if (fsm->goal == FSM_PKGINSTALL) fsm->li->linksLeft++;
510 if (fsm->goal == FSM_PKGBUILD)
511 return (fsm->li->linksLeft > 0);
513 if (fsm->goal != FSM_PKGINSTALL)
516 if (!(st->st_size || fsm->li->linksLeft == st->st_nlink))
519 /* Here come the bits, time to choose a non-skipped file name. */
520 { rpmfs fs = rpmteGetFileStates(fsmGetTe(fsm));
522 for (j = fsm->li->linksLeft - 1; j >= 0; j--) {
523 ix = fsm->li->filex[j];
524 if (ix < 0 || XFA_SKIPPING(rpmfsGetAction(fs, ix)))
530 /* Are all links skipped or not encountered yet? */
532 return 1; /* XXX W2DO? */
534 /* Save the non-skipped file name and map index. */
535 fsm->li->linkIndex = j;
536 fsm->path = _free(fsm->path);
538 rc = fsmMapPath(fsm);
543 * Destroy set of hard links.
544 * @param li set of hard links
545 * @return NULL always
547 static void * freeHardLink(hardLink_t li)
550 li->nsuffix = _free(li->nsuffix); /* XXX elements are shared */
551 li->filex = _free(li->filex);
556 FSM_t newFSM(cpioMapFlags mapflags)
558 FSM_t fsm = xcalloc(1, sizeof(*fsm));
559 fsm->mapFlags = mapflags;
563 FSM_t freeFSM(FSM_t fsm)
566 fsm->path = _free(fsm->path);
567 while ((fsm->li = fsm->links) != NULL) {
568 fsm->links = fsm->li->next;
569 fsm->li->next = NULL;
570 fsm->li = freeHardLink(fsm->li);
572 fsm->dnlx = _free(fsm->dnlx);
573 fsm->ldn = _free(fsm->ldn);
574 fsm->iter = mapFreeIterator(fsm->iter);
579 /* forward declaration*/
580 static int fsmMkdirs(FSM_t fsm);
582 static int fsmCreate(FSM_t fsm)
585 { rpmts ts = fsmGetTs(fsm);
586 #define _tsmask (RPMTRANS_FLAG_PKGCOMMIT | RPMTRANS_FLAG_COMMIT)
587 fsm->commit = ((ts && (rpmtsFlags(ts) & _tsmask) &&
588 fsm->goal != FSM_PKGCOMMIT) ? 0 : 1);
591 fsm->path = _free(fsm->path);
592 fsm->opath = _free(fsm->opath);
593 fsm->dnlx = _free(fsm->dnlx);
595 fsm->ldn = _free(fsm->ldn);
596 fsm->ldnalloc = fsm->ldnlen = 0;
598 fsm->rdsize = fsm->wrsize = 0;
599 fsm->rdbuf = fsm->rdb = _free(fsm->rdb);
600 fsm->wrbuf = fsm->wrb = _free(fsm->wrb);
601 if (fsm->goal == FSM_PKGINSTALL || fsm->goal == FSM_PKGBUILD) {
602 fsm->rdsize = 8 * BUFSIZ;
603 fsm->rdbuf = fsm->rdb = xmalloc(fsm->rdsize);
604 fsm->wrsize = 8 * BUFSIZ;
605 fsm->wrbuf = fsm->wrb = xmalloc(fsm->wrsize);
612 errno = 0; /* XXX get rid of EBADF */
614 /* Detect and create directories not explicitly in package. */
615 if (fsm->goal == FSM_PKGINSTALL) {
617 if (!rc) fsm->mkdirsdone = 1;
622 int fsmSetup(FSM_t fsm, fileStage goal,
623 rpmts ts, rpmte te, rpmfi fi, FD_t cfd,
624 rpm_loff_t * archiveSize, char ** failedFile)
630 fsm->cfd = fdLink(cfd);
633 fsm->iter = mapInitIterator(ts, te, fi);
634 fsm->digestalgo = rpmfiDigestAlgo(fi);
636 if (fsm->goal == FSM_PKGINSTALL || fsm->goal == FSM_PKGBUILD) {
639 ptr = rpmtsNotify(ts, te,
640 RPMCALLBACK_INST_START, fsm->archivePos, fi->archiveSize);
643 fsm->archiveSize = archiveSize;
644 if (fsm->archiveSize)
645 *fsm->archiveSize = 0;
646 fsm->failedFile = failedFile;
648 *fsm->failedFile = NULL;
650 memset(fsm->sufbuf, 0, sizeof(fsm->sufbuf));
651 if (fsm->goal == FSM_PKGINSTALL) {
652 if (ts && rpmtsGetTid(ts) != (rpm_tid_t)-1)
653 sprintf(fsm->sufbuf, ";%08x", (unsigned)rpmtsGetTid(ts));
658 if (rc && !ec) ec = rc;
660 rc = fsmUNSAFE(fsm, fsm->goal);
661 if (rc && !ec) ec = rc;
663 if (fsm->archiveSize && ec == 0)
664 *fsm->archiveSize = fsm->cpioPos;
666 /* FIX: *fsm->failedFile may be NULL */
670 int fsmTeardown(FSM_t fsm)
675 rc = fsmUNSAFE(fsm, FSM_DESTROY);
677 fsm->iter = mapFreeIterator(fsm->iter);
678 if (fsm->cfd != NULL) {
679 fsm->cfd = fdFree(fsm->cfd);
682 fsm->failedFile = NULL;
686 static int fsmMapFContext(FSM_t fsm)
688 rpmts ts = fsmGetTs(fsm);
693 * Find file security context (if not disabled).
695 fsm->fcontext = NULL;
696 if (ts != NULL && !(rpmtsFlags(ts) & RPMTRANS_FLAG_NOCONTEXTS) && rpmtsSELabelHandle(ts)) {
697 security_context_t scon = NULL;
699 if (selabel_lookup_raw(rpmtsSELabelHandle(ts), &scon, fsm->path, st->st_mode) == 0 && scon != NULL) {
700 fsm->fcontext = scon;
707 static int fsmMapFCaps(FSM_t fsm)
709 rpmfi fi = fsmGetFi(fsm);
710 const char *captxt = rpmfiFCapsIndex(fi, fsm->ix);
712 if (captxt && *captxt != '\0') {
713 cap_t fcaps = cap_from_text(captxt);
723 * Map file stat(2) info.
724 * @param fsm file state machine
726 static int fsmMapAttrs(FSM_t fsm)
728 struct stat * st = &fsm->sb;
729 rpmfi fi = fsmGetFi(fsm);
732 /* this check is pretty moot, rpmfi accessors check array bounds etc */
733 if (fi && i >= 0 && i < rpmfiFC(fi)) {
734 mode_t finalMode = rpmfiFModeIndex(fi, i);
735 dev_t finalRdev = rpmfiFRdevIndex(fi, i);
736 time_t finalMtime = rpmfiFMtimeIndex(fi, i);
737 const char *user = rpmfiFUserIndex(fi, i);
738 const char *group = rpmfiFGroupIndex(fi, i);
742 if (user && unameToUid(user, &uid)) {
743 if (fsm->goal == FSM_PKGINSTALL)
744 rpmlog(RPMLOG_WARNING,
745 _("user %s does not exist - using root\n"), user);
746 finalMode &= ~S_ISUID; /* turn off suid bit */
749 if (group && gnameToGid(group, &gid)) {
750 if (fsm->goal == FSM_PKGINSTALL)
751 rpmlog(RPMLOG_WARNING,
752 _("group %s does not exist - using root\n"), group);
753 finalMode &= ~S_ISGID; /* turn off sgid bit */
756 if (fsm->mapFlags & CPIO_MAP_MODE)
757 st->st_mode = (st->st_mode & S_IFMT) | (finalMode & ~S_IFMT);
758 if (fsm->mapFlags & CPIO_MAP_TYPE) {
759 st->st_mode = (st->st_mode & ~S_IFMT) | (finalMode & S_IFMT);
760 if ((S_ISCHR(st->st_mode) || S_ISBLK(st->st_mode))
761 && st->st_nlink == 0)
763 st->st_rdev = finalRdev;
764 st->st_mtime = finalMtime;
766 if (fsm->mapFlags & CPIO_MAP_UID)
768 if (fsm->mapFlags & CPIO_MAP_GID)
771 { rpmts ts = fsmGetTs(fsm);
774 * Set file digest (if not disabled).
776 if (ts != NULL && !(rpmtsFlags(ts) & RPMTRANS_FLAG_NOFILEDIGEST)) {
777 fsm->digest = rpmfiFDigestIndex(fi, i, NULL, NULL);
787 * Create file from payload stream.
788 * @param fsm file state machine data
789 * @return 0 on success
791 static int expandRegular(FSM_t fsm)
793 const struct stat * st = &fsm->sb;
794 rpm_loff_t left = st->st_size;
797 rc = fsmNext(fsm, FSM_WOPEN);
801 if (st->st_size > 0 && fsm->digest != NULL)
802 fdInitDigest(fsm->wfd, fsm->digestalgo, 0);
806 fsm->wrlen = (left > fsm->wrsize ? fsm->wrsize : left);
807 rc = fsmNext(fsm, FSM_DREAD);
811 rc = fsmNext(fsm, FSM_WRITE);
817 /* don't call this with fileSize == fileComplete */
819 (void) fsmNext(fsm, FSM_NOTIFY);
822 if (st->st_size > 0 && fsm->digest) {
823 void * digest = NULL;
824 int asAscii = (fsm->digest == NULL ? 1 : 0);
826 (void) Fflush(fsm->wfd);
827 fdFiniDigest(fsm->wfd, fsm->digestalgo, &digest, NULL, asAscii);
829 if (digest == NULL) {
830 rc = CPIOERR_DIGEST_MISMATCH;
834 if (fsm->digest != NULL) {
835 size_t diglen = rpmDigestLength(fsm->digestalgo);
836 if (memcmp(digest, fsm->digest, diglen))
837 rc = CPIOERR_DIGEST_MISMATCH;
839 rc = CPIOERR_DIGEST_MISMATCH;
841 digest = _free(digest);
845 (void) fsmNext(fsm, FSM_WCLOSE);
849 static int fsmReadLink(FSM_t fsm)
852 /* XXX NUL terminated result in fsm->rdbuf, len in fsm->rdnb. */
853 rc = readlink(fsm->path, fsm->rdbuf, fsm->rdsize - 1);
854 if (_fsm_debug && (FSM_READLINK & FSM_SYSCALL))
855 rpmlog(RPMLOG_DEBUG, " %8s (%s, rdbuf, %d) %s\n", fileStageString(FSM_READLINK),
856 fsm->path, (int)(fsm->rdsize -1), (rc < 0 ? strerror(errno) : ""));
857 if (rc < 0) rc = CPIOERR_READLINK_FAILED;
860 fsm->rdbuf[fsm->rdnb] = '\0';
867 * Write next item to payload stream.
868 * @param fsm file state machine data
869 * @param writeData should data be written?
870 * @return 0 on success
872 static int writeFile(FSM_t fsm, int writeData)
874 char * path = fsm->path;
875 char * opath = fsm->opath;
876 struct stat * st = &fsm->sb;
877 struct stat * ost = &fsm->osb;
878 char * symbuf = NULL;
882 st->st_size = (writeData ? ost->st_size : 0);
884 if (S_ISDIR(st->st_mode)) {
886 } else if (S_ISLNK(st->st_mode)) {
888 * While linux puts the size of a symlink in the st_size field,
889 * I don't think that's a specified standard.
891 /* XXX NUL terminated result in fsm->rdbuf, len in fsm->rdnb. */
892 rc = fsmReadLink(fsm);
894 st->st_size = fsm->rdnb;
895 rstrcat(&symbuf, fsm->rdbuf); /* XXX save readlink return. */
898 if (fsm->mapFlags & CPIO_MAP_ABSOLUTE) {
899 fsm->path = rstrscat(NULL, (fsm->mapFlags & CPIO_MAP_ADDDOT) ? "." : "",
900 fsm->dirName, fsm->baseName, NULL);
901 } else if (fsm->mapFlags & CPIO_MAP_PATH) {
902 rpmfi fi = fsmGetFi(fsm);
903 fsm->path = xstrdup((fi->apath ? fi->apath[fsm->ix] :
904 rpmfiBNIndex(fi, fsm->ix)));
907 rc = cpioHeaderWrite(fsm, st);
912 if (writeData && S_ISREG(st->st_mode)) {
915 void * mapped = MAP_FAILED;
920 rc = fsmNext(fsm, FSM_ROPEN);
923 /* XXX unbuffered mmap generates *lots* of fdio debugging */
926 mapped = mmap(NULL, st->st_size, PROT_READ, MAP_SHARED, Fileno(fsm->rfd), 0);
927 if (mapped != MAP_FAILED) {
929 fsm->rdbuf = (char *) mapped;
930 fsm->rdlen = nmapped = st->st_size;
931 #if defined(MADV_DONTNEED)
932 xx = madvise(mapped, nmapped, MADV_DONTNEED);
941 if (mapped != MAP_FAILED) {
946 fsm->rdlen = (left > fsm->rdsize ? fsm->rdsize : left),
947 rc = fsmNext(fsm, FSM_READ);
951 /* XXX DWRITE uses rdnb for I/O length. */
952 rc = fsmNext(fsm, FSM_DWRITE);
959 if (mapped != MAP_FAILED) {
960 xx = msync(mapped, nmapped, MS_ASYNC);
961 #if defined(MADV_DONTNEED)
962 xx = madvise(mapped, nmapped, MADV_DONTNEED);
964 xx = munmap(mapped, nmapped);
969 } else if (writeData && S_ISLNK(st->st_mode)) {
970 /* XXX DWRITE uses rdnb for I/O length. */
971 strcpy(fsm->rdbuf, symbuf); /* XXX restore readlink buffer. */
972 fsm->rdnb = strlen(symbuf);
973 rc = fsmNext(fsm, FSM_DWRITE);
977 rc = fsmNext(fsm, FSM_PAD);
983 if (fsm->rfd != NULL)
984 (void) fsmNext(fsm, FSM_RCLOSE);
992 * Write set of linked files to payload stream.
993 * @param fsm file state machine data
994 * @return 0 on success
996 static int writeLinkedFile(FSM_t fsm)
998 char * path = fsm->path;
999 const char * nsuffix = fsm->nsuffix;
1000 int iterIndex = fsm->ix;
1006 fsm->nsuffix = NULL;
1009 for (i = fsm->li->nlink - 1; i >= 0; i--) {
1011 if (fsm->li->filex[i] < 0) continue;
1013 fsm->ix = fsm->li->filex[i];
1014 rc = fsmMapPath(fsm);
1016 /* Write data after last link. */
1017 rc = writeFile(fsm, (i == 0));
1018 if (fsm->failedFile && rc != 0 && *fsm->failedFile == NULL) {
1020 *fsm->failedFile = xstrdup(fsm->path);
1023 fsm->path = _free(fsm->path);
1024 fsm->li->filex[i] = -1;
1027 fsm->ix = iterIndex;
1028 fsm->nsuffix = nsuffix;
1033 static int fsmStat(FSM_t fsm, int dolstat)
1037 rc = lstat(fsm->path, &fsm->osb);
1039 rc = stat(fsm->path, &fsm->osb);
1041 if (_fsm_debug && (FSM_STAT & FSM_SYSCALL) && rc && errno != ENOENT)
1042 rpmlog(RPMLOG_DEBUG, " %8s (%s, ost) %s\n",
1043 fileStageString(dolstat ? FSM_LSTAT : FSM_STAT),
1044 fsm->path, (rc < 0 ? strerror(errno) : ""));
1046 rc = (errno == ENOENT ? CPIOERR_ENOENT : CPIOERR_LSTAT_FAILED);
1047 memset(&fsm->osb, 0, sizeof(fsm->osb)); /* XXX s390x hackery */
1052 static int fsmVerify(FSM_t fsm);
1054 /** \ingroup payload
1055 * Create pending hard links to existing file.
1056 * @param fsm file state machine data
1057 * @return 0 on success
1059 static int fsmMakeLinks(FSM_t fsm)
1061 char * path = fsm->path;
1062 char * opath = fsm->opath;
1063 const char * nsuffix = fsm->nsuffix;
1064 int iterIndex = fsm->ix;
1071 fsm->nsuffix = NULL;
1074 fsm->ix = fsm->li->filex[fsm->li->createdPath];
1075 rc = fsmMapPath(fsm);
1076 fsm->opath = fsm->path;
1078 for (i = 0; i < fsm->li->nlink; i++) {
1079 if (fsm->li->filex[i] < 0) continue;
1080 if (fsm->li->createdPath == i) continue;
1082 fsm->ix = fsm->li->filex[i];
1083 fsm->path = _free(fsm->path);
1084 rc = fsmMapPath(fsm);
1085 if (XFA_SKIPPING(fsm->action)) continue;
1087 rc = fsmVerify(fsm);
1089 if (!(rc == CPIOERR_ENOENT)) break;
1091 /* XXX link(fsm->opath, fsm->path) */
1092 rc = link(fsm->opath, fsm->path);
1093 if (_fsm_debug && (FSM_LINK & FSM_SYSCALL))
1094 rpmlog(RPMLOG_DEBUG, " %8s (%s, %s) %s\n", fileStageString(FSM_LINK),
1095 fsm->opath, fsm->path, (rc < 0 ? strerror(errno) : ""));
1096 if (rc < 0) rc = CPIOERR_LINK_FAILED;
1098 if (fsm->failedFile && rc != 0 && *fsm->failedFile == NULL) {
1100 *fsm->failedFile = xstrdup(fsm->path);
1103 fsm->li->linksLeft--;
1105 fsm->path = _free(fsm->path);
1106 fsm->opath = _free(fsm->opath);
1108 fsm->ix = iterIndex;
1109 fsm->nsuffix = nsuffix;
1115 /** \ingroup payload
1116 * Commit hard linked file set atomically.
1117 * @param fsm file state machine data
1118 * @return 0 on success
1120 static int fsmCommitLinks(FSM_t fsm)
1122 char * path = fsm->path;
1123 const char * nsuffix = fsm->nsuffix;
1124 int iterIndex = fsm->ix;
1125 struct stat * st = &fsm->sb;
1130 fsm->nsuffix = NULL;
1133 for (fsm->li = fsm->links; fsm->li; fsm->li = fsm->li->next) {
1134 if (fsm->li->sb.st_ino == st->st_ino && fsm->li->sb.st_dev == st->st_dev)
1138 for (i = 0; i < fsm->li->nlink; i++) {
1139 if (fsm->li->filex[i] < 0) continue;
1140 fsm->ix = fsm->li->filex[i];
1141 rc = fsmMapPath(fsm);
1142 if (!XFA_SKIPPING(fsm->action))
1143 rc = fsmNext(fsm, FSM_COMMIT);
1144 fsm->path = _free(fsm->path);
1145 fsm->li->filex[i] = -1;
1148 fsm->ix = iterIndex;
1149 fsm->nsuffix = nsuffix;
1154 static int fsmRmdir(FSM_t fsm)
1156 int rc = rmdir(fsm->path);
1157 if (_fsm_debug && (FSM_RMDIR & FSM_SYSCALL))
1158 rpmlog(RPMLOG_DEBUG, " %8s (%s) %s\n", fileStageString(FSM_RMDIR),
1159 fsm->path, (rc < 0 ? strerror(errno) : ""));
1162 case ENOENT: rc = CPIOERR_ENOENT; break;
1163 case ENOTEMPTY: rc = CPIOERR_ENOTEMPTY; break;
1164 default: rc = CPIOERR_RMDIR_FAILED; break;
1169 static int fsmLsetfcon(FSM_t fsm)
1172 if (fsm->fcontext == NULL || *fsm->fcontext == '\0'
1173 || rstreq(fsm->fcontext, "<<none>>"))
1175 rc = lsetfilecon(fsm->path, (security_context_t)fsm->fcontext);
1176 if (_fsm_debug && (FSM_LSETFCON & FSM_SYSCALL))
1177 rpmlog(RPMLOG_DEBUG, " %8s (%s, %s) %s\n", fileStageString(FSM_LSETFCON),
1178 fsm->path, fsm->fcontext,
1179 (rc < 0 ? strerror(errno) : ""));
1180 if (rc < 0) rc = (errno == EOPNOTSUPP ? 0 : CPIOERR_LSETFCON_FAILED);
1184 static int fsmMkdir(FSM_t fsm)
1186 int rc = mkdir(fsm->path, (fsm->sb.st_mode & 07777));
1187 if (_fsm_debug && (FSM_MKDIR & FSM_SYSCALL))
1188 rpmlog(RPMLOG_DEBUG, " %8s (%s, 0%04o) %s\n", fileStageString(FSM_MKDIR),
1189 fsm->path, (unsigned)(fsm->sb.st_mode & 07777),
1190 (rc < 0 ? strerror(errno) : ""));
1191 if (rc < 0) rc = CPIOERR_MKDIR_FAILED;
1196 * Create (if necessary) directories not explicitly included in package.
1197 * @param fsm file state machine data
1198 * @return 0 on success
1200 static int fsmMkdirs(FSM_t fsm)
1202 struct stat * st = &fsm->sb;
1203 struct stat * ost = &fsm->osb;
1204 char * path = fsm->path;
1206 mode_t st_mode = st->st_mode;
1207 void * dnli = dnlInitIterator(fsm, 0);
1208 int dc = dnlCount(dnli);
1211 rpmts ts = fsmGetTs(fsm);
1212 security_context_t scon = NULL;
1214 fsm->dnlx = (dc ? xcalloc(dc, sizeof(*fsm->dnlx)) : NULL);
1215 if (fsm->dnlx != NULL)
1216 while ((dpath = dnlNextIterator(dnli)) != NULL) {
1217 size_t dnlen = strlen(dpath);
1218 char * te, dn[dnlen+1];
1220 dc = dnlIndex(dnli);
1221 if (dc < 0) continue;
1222 fsm->dnlx[dc] = dnlen;
1226 if (dnlen <= fsm->ldnlen && rstreq(dpath, fsm->ldn))
1229 /* Copy as we need to modify the string */
1230 (void) stpcpy(dn, dpath);
1233 /* Assume '/' directory exists, "mkdir -p" for others if non-existent */
1234 for (i = 1, te = dn + 1; *te != '\0'; te++, i++) {
1240 /* Already validated? */
1241 if (i < fsm->ldnlen &&
1242 (fsm->ldn[i] == '/' || fsm->ldn[i] == '\0') &&
1243 rstreqn(fsm->path, fsm->ldn, i))
1246 /* Move pre-existing path marker forward. */
1247 fsm->dnlx[dc] = (te - dn);
1251 /* Validate next component of path. */
1252 rc = fsmStat(fsm, 1); /* lstat */
1255 /* Directory already exists? */
1256 if (rc == 0 && S_ISDIR(ost->st_mode)) {
1257 /* Move pre-existing path marker forward. */
1258 fsm->dnlx[dc] = (te - dn);
1259 } else if (rc == CPIOERR_ENOENT) {
1261 st->st_mode = S_IFDIR | (_dirPerms & 07777);
1264 /* XXX FIXME? only new dir will have context set. */
1265 /* Get file security context from patterns. */
1266 if (!(rpmtsFlags(ts) & RPMTRANS_FLAG_NOCONTEXTS) && rpmtsSELabelHandle(ts)) {
1267 if (selabel_lookup_raw(rpmtsSELabelHandle(ts), &scon, fsm->path, st->st_mode) == 0 &&
1269 fsm->fcontext = scon;
1270 rc = fsmLsetfcon(fsm);
1274 if (fsm->fcontext == NULL)
1275 rpmlog(RPMLOG_DEBUG,
1276 "%s directory created with perms %04o, no context.\n",
1277 fsm->path, (unsigned)(st->st_mode & 07777));
1279 rpmlog(RPMLOG_DEBUG,
1280 "%s directory created with perms %04o, context %s.\n",
1281 fsm->path, (unsigned)(st->st_mode & 07777),
1283 freecon(fsm->fcontext);
1285 fsm->fcontext = NULL;
1294 /* Save last validated path. */
1295 /* FIX: ldn/path annotations ? */
1296 if (fsm->ldnalloc < (dnlen + 1)) {
1297 fsm->ldnalloc = dnlen + 100;
1298 fsm->ldn = xrealloc(fsm->ldn, fsm->ldnalloc);
1300 if (fsm->ldn != NULL) { /* XXX can't happen */
1301 strcpy(fsm->ldn, fsm->path);
1302 fsm->ldnlen = dnlen;
1305 dnli = dnlFreeIterator(dnli);
1308 st->st_mode = st_mode; /* XXX restore st->st_mode */
1309 /* FIX: ldn/path annotations ? */
1313 static void removeSBITS(const char *path)
1316 if (lstat(path, &stb) == 0 && S_ISREG(stb.st_mode)) {
1317 if ((stb.st_mode & 06000) != 0) {
1318 (void) chmod(path, stb.st_mode & 0777);
1321 if (stb.st_mode & (S_IXUSR|S_IXGRP|S_IXOTH)) {
1322 (void) cap_set_file(path, NULL);
1328 /********************************************************************/
1330 static int fsmInit(FSM_t fsm)
1334 fsm->path = _free(fsm->path);
1336 fsm->diskchecked = fsm->exists = 0;
1338 fsm->suffix = (fsm->sufbuf[0] != '\0' ? fsm->sufbuf : NULL);
1339 fsm->action = FA_UNKNOWN;
1340 fsm->osuffix = NULL;
1341 fsm->nsuffix = NULL;
1343 if (fsm->goal == FSM_PKGINSTALL) {
1344 /* Read next header from payload, checking for end-of-payload. */
1345 rc = fsmUNSAFE(fsm, FSM_NEXT);
1349 /* Identify mapping index. */
1350 fsm->ix = ((fsm->goal == FSM_PKGINSTALL)
1351 ? mapFind(fsm->iter, fsm->path) : mapNextIterator(fsm->iter));
1353 /* Detect end-of-loop and/or mapping error. */
1355 if (fsm->goal == FSM_PKGINSTALL) {
1357 rpmlog(RPMLOG_WARNING,
1358 _("archive file %s was not found in header file list\n"),
1361 if (fsm->failedFile && *fsm->failedFile == NULL)
1362 *fsm->failedFile = xstrdup(fsm->path);
1363 rc = CPIOERR_UNMAPPED_FILE;
1365 rc = CPIOERR_HDR_TRAILER;
1370 /* On non-install, mode must be known so that dirs don't get suffix. */
1371 if (fsm->goal != FSM_PKGINSTALL) {
1372 rpmfi fi = fsmGetFi(fsm);
1373 fsm->sb.st_mode = rpmfiFModeIndex(fi, fsm->ix);
1376 /* Generate file path. */
1377 rc = fsmMapPath(fsm);
1380 /* Perform lstat/stat for disk file. */
1381 if (fsm->path != NULL &&
1382 !(fsm->goal == FSM_PKGINSTALL && S_ISREG(fsm->sb.st_mode)))
1384 rc = fsmStat(fsm, (!(fsm->mapFlags & CPIO_FOLLOW_SYMLINKS)));
1385 if (rc == CPIOERR_ENOENT) {
1386 // errno = saveerrno; XXX temporary commented out
1389 } else if (rc == 0) {
1393 /* Skip %ghost files on build. */
1396 fsm->diskchecked = 1;
1399 /* On non-install, the disk file stat is what's remapped. */
1400 if (fsm->goal != FSM_PKGINSTALL)
1401 fsm->sb = fsm->osb; /* structure assignment */
1403 /* Remap file perms, owner, and group. */
1404 rc = fsmMapAttrs(fsm);
1407 fsm->postpone = XFA_SKIPPING(fsm->action);
1408 if (fsm->goal == FSM_PKGINSTALL || fsm->goal == FSM_PKGBUILD) {
1409 /* FIX: saveHardLink can modify fsm */
1410 if (S_ISREG(fsm->sb.st_mode) && fsm->sb.st_nlink > 1)
1411 fsm->postpone = saveHardLink(fsm);
1417 static int fsmUnlink(FSM_t fsm)
1420 if (fsm->mapFlags & CPIO_SBIT_CHECK)
1421 removeSBITS(fsm->path);
1422 rc = unlink(fsm->path);
1423 if (_fsm_debug && (FSM_UNLINK & FSM_SYSCALL))
1424 rpmlog(RPMLOG_DEBUG, " %8s (%s) %s\n", fileStageString(FSM_UNLINK),
1425 fsm->path, (rc < 0 ? strerror(errno) : ""));
1427 rc = (errno == ENOENT ? CPIOERR_ENOENT : CPIOERR_UNLINK_FAILED);
1431 static int fsmRename(FSM_t fsm)
1433 if (fsm->mapFlags & CPIO_SBIT_CHECK)
1434 removeSBITS(fsm->path);
1435 int rc = rename(fsm->opath, fsm->path);
1436 #if defined(ETXTBSY) && defined(__HPUX__)
1437 if (rc && errno == ETXTBSY) {
1439 rstrscat(&path, fsm->path, "-RPMDELETE", NULL);
1441 * XXX HP-UX (and other os'es) don't permit rename to busy
1444 rc = rename(fsm->path, path);
1445 if (!rc) rc = rename(fsm->opath, fsm->path);
1449 if (_fsm_debug && (FSM_RENAME & FSM_SYSCALL))
1450 rpmlog(RPMLOG_DEBUG, " %8s (%s, %s) %s\n", fileStageString(FSM_RENAME),
1451 fsm->opath, fsm->path, (rc < 0 ? strerror(errno) : ""));
1452 if (rc < 0) rc = CPIOERR_RENAME_FAILED;
1457 static int fsmChown(FSM_t fsm)
1459 int rc = chown(fsm->path, fsm->sb.st_uid, fsm->sb.st_gid);
1460 if (_fsm_debug && (FSM_CHOWN & FSM_SYSCALL))
1461 rpmlog(RPMLOG_DEBUG, " %8s (%s, %d, %d) %s\n", fileStageString(FSM_CHOWN),
1462 fsm->path, (int)fsm->sb.st_uid, (int)fsm->sb.st_gid,
1463 (rc < 0 ? strerror(errno) : ""));
1464 if (rc < 0) rc = CPIOERR_CHOWN_FAILED;
1468 static int fsmLChown(FSM_t fsm)
1471 rc = lchown(fsm->path, fsm->sb.st_uid, fsm->sb.st_gid);
1472 if (_fsm_debug && (FSM_LCHOWN & FSM_SYSCALL))
1473 rpmlog(RPMLOG_DEBUG, " %8s (%s, %d, %d) %s\n", fileStageString(FSM_LCHOWN),
1474 fsm->path, (int)fsm->sb.st_uid, (int)fsm->sb.st_gid,
1475 (rc < 0 ? strerror(errno) : ""));
1476 if (rc < 0) rc = CPIOERR_CHOWN_FAILED;
1480 static int fsmChmod(FSM_t fsm)
1482 int rc = chmod(fsm->path, (fsm->sb.st_mode & 07777));
1483 if (_fsm_debug && (FSM_CHMOD & FSM_SYSCALL))
1484 rpmlog(RPMLOG_DEBUG, " %8s (%s, 0%04o) %s\n", fileStageString(FSM_CHMOD),
1485 fsm->path, (unsigned)(fsm->sb.st_mode & 07777),
1486 (rc < 0 ? strerror(errno) : ""));
1487 if (rc < 0) rc = CPIOERR_CHMOD_FAILED;
1491 static int fsmUtime(FSM_t fsm)
1494 struct utimbuf stamp;
1495 stamp.actime = fsm->sb.st_mtime;
1496 stamp.modtime = fsm->sb.st_mtime;
1497 rc = utime(fsm->path, &stamp);
1498 if (_fsm_debug && (FSM_UTIME & FSM_SYSCALL))
1499 rpmlog(RPMLOG_DEBUG, " %8s (%s, 0x%x) %s\n", fileStageString(FSM_UTIME),
1500 fsm->path, (unsigned)fsm->sb.st_mtime,
1501 (rc < 0 ? strerror(errno) : ""));
1502 if (rc < 0) rc = CPIOERR_UTIME_FAILED;
1507 static int fsmSetcap(FSM_t fsm)
1509 int rc = cap_set_file(fsm->path, fsm->fcaps);
1511 rc = CPIOERR_SETCAP_FAILED;
1515 #endif /* WITH_CAP */
1517 static int fsmVerify(FSM_t fsm)
1520 struct stat * st = &fsm->sb;
1521 struct stat * ost = &fsm->osb;
1522 int saveerrno = errno;
1524 if (fsm->diskchecked && !fsm->exists) {
1525 return CPIOERR_ENOENT;
1527 if (S_ISREG(st->st_mode)) {
1529 * XXX HP-UX (and other os'es) don't permit unlink on busy
1532 fsm->opath = fsm->path;
1533 fsm->path = rstrscat(NULL, fsm->path, "-RPMDELETE", NULL);
1534 rc = fsmRename(fsm);
1536 (void) fsmUnlink(fsm);
1538 rc = CPIOERR_UNLINK_FAILED;
1540 fsm->path = fsm->opath;
1542 return (rc ? rc : CPIOERR_ENOENT); /* XXX HACK */
1543 } else if (S_ISDIR(st->st_mode)) {
1544 if (S_ISDIR(ost->st_mode)) return 0;
1545 if (S_ISLNK(ost->st_mode)) {
1546 rc = fsmStat(fsm, 0);
1547 if (rc == CPIOERR_ENOENT) rc = 0;
1550 if (S_ISDIR(ost->st_mode)) return 0;
1552 } else if (S_ISLNK(st->st_mode)) {
1553 if (S_ISLNK(ost->st_mode)) {
1554 /* XXX NUL terminated result in fsm->rdbuf, len in fsm->rdnb. */
1555 rc = fsmReadLink(fsm);
1558 if (rstreq(fsm->opath, fsm->rdbuf)) return 0;
1560 } else if (S_ISFIFO(st->st_mode)) {
1561 if (S_ISFIFO(ost->st_mode)) return 0;
1562 } else if (S_ISCHR(st->st_mode) || S_ISBLK(st->st_mode)) {
1563 if ((S_ISCHR(ost->st_mode) || S_ISBLK(ost->st_mode)) &&
1564 (ost->st_rdev == st->st_rdev)) return 0;
1565 } else if (S_ISSOCK(st->st_mode)) {
1566 if (S_ISSOCK(ost->st_mode)) return 0;
1568 /* XXX shouldn't do this with commit/undo. */
1570 if (fsm->stage == FSM_PROCESS) rc = fsmUnlink(fsm);
1571 if (rc == 0) rc = CPIOERR_ENOENT;
1572 return (rc ? rc : CPIOERR_ENOENT); /* XXX HACK */
1575 /********************************************************************/
1577 #define IS_DEV_LOG(_x) \
1578 ((_x) != NULL && strlen(_x) >= (sizeof("/dev/log")-1) && \
1579 rstreqn((_x), "/dev/log", sizeof("/dev/log")-1) && \
1580 ((_x)[sizeof("/dev/log")-1] == '\0' || \
1581 (_x)[sizeof("/dev/log")-1] == ';'))
1584 * File state machine driver.
1585 * @param fsm file state machine
1586 * @param stage next stage
1587 * @return 0 on success
1589 static int fsmStage(FSM_t fsm, fileStage stage)
1592 fileStage prevStage = fsm->stage;
1593 const char * const prev = fileStageString(prevStage);
1595 static int modulo = 4;
1596 const char * const cur = fileStageString(stage);
1597 struct stat * st = &fsm->sb;
1598 struct stat * ost = &fsm->osb;
1599 int saveerrno = errno;
1603 #define _fafilter(_a) \
1604 (!((_a) == FA_CREATE || (_a) == FA_ERASE || (_a) == FA_COPYIN || (_a) == FA_COPYOUT) \
1605 ? fileActionString(_a) : "")
1607 if (stage & FSM_DEAD) {
1609 } else if (stage & FSM_INTERNAL) {
1610 if (_fsm_debug && !(stage & FSM_SYSCALL))
1611 rpmlog(RPMLOG_DEBUG, " %8s %06o%3d (%4d,%4d)%10d %s %s\n",
1613 (unsigned)st->st_mode, (int)st->st_nlink,
1614 (int)st->st_uid, (int)st->st_gid, (int)st->st_size,
1615 (fsm->path ? fsm->path : ""),
1616 _fafilter(fsm->action));
1619 if (_fsm_debug || !(stage & FSM_VERBOSE))
1620 rpmlog(RPMLOG_DEBUG, "%-8s %06o%3d (%4d,%4d)%10d %s %s\n",
1622 (unsigned)st->st_mode, (int)st->st_nlink,
1623 (int)st->st_uid, (int)st->st_gid, (int)st->st_size,
1624 (fsm->path ? fsm->path : ""),
1625 _fafilter(fsm->action));
1632 case FSM_PKGINSTALL:
1634 /* Clean fsm, free'ing memory. Read next archive header. */
1637 /* Exit on end-of-payload. */
1638 if (rc == CPIOERR_HDR_TRAILER) {
1643 /* Exit on error. */
1646 (void) fsmNext(fsm, FSM_UNDO);
1650 /* Extract file from archive. */
1651 rc = fsmNext(fsm, FSM_PROCESS);
1653 (void) fsmNext(fsm, FSM_UNDO);
1657 /* Notify on success. */
1658 (void) fsmNext(fsm, FSM_NOTIFY);
1660 rc = fsmNext(fsm, FSM_FINI);
1669 /* Clean fsm, free'ing memory. */
1672 /* Exit on end-of-payload. */
1673 if (rc == CPIOERR_HDR_TRAILER) {
1678 /* Rename/erase next item. */
1679 if (fsmNext(fsm, FSM_FINI))
1688 /* Exit on end-of-payload. */
1689 if (rc == CPIOERR_HDR_TRAILER) {
1694 /* Exit on error. */
1697 (void) fsmNext(fsm, FSM_UNDO);
1701 /* Copy file into archive. */
1702 rc = fsmNext(fsm, FSM_PROCESS);
1704 (void) fsmNext(fsm, FSM_UNDO);
1708 /* Notify on success. */
1709 (void) fsmNext(fsm, FSM_NOTIFY);
1711 if (fsmNext(fsm, FSM_FINI))
1715 /* Flush partial sets of hard linked files. */
1716 if (!(fsm->mapFlags & CPIO_ALL_HARDLINKS)) {
1719 while ((fsm->li = fsm->links) != NULL) {
1720 fsm->links = fsm->li->next;
1721 fsm->li->next = NULL;
1723 /* Re-calculate link count for archive header. */
1724 for (j = -1, nlink = 0, i = 0; i < fsm->li->nlink; i++) {
1725 if (fsm->li->filex[i] < 0)
1730 /* XXX force the contents out as well. */
1732 fsm->li->filex[0] = fsm->li->filex[j];
1733 fsm->li->filex[j] = -1;
1735 fsm->li->sb.st_nlink = nlink;
1737 fsm->sb = fsm->li->sb; /* structure assignment */
1738 fsm->osb = fsm->sb; /* structure assignment */
1740 if (!rc) rc = writeLinkedFile(fsm);
1742 fsm->li = freeHardLink(fsm->li);
1747 rc = cpioTrailerWrite(fsm);
1751 if (fsm->postpone) {
1752 if (fsm->goal == FSM_PKGINSTALL)
1753 rc = fsmNext(fsm, FSM_EAT);
1757 if (fsm->goal == FSM_PKGBUILD) {
1758 if (fsm->fflags & RPMFILE_GHOST) /* XXX Don't if %ghost file. */
1760 if (S_ISREG(st->st_mode) && st->st_nlink > 1) {
1761 hardLink_t li, prev;
1763 if (!(fsm->mapFlags & CPIO_ALL_HARDLINKS)) break;
1764 rc = writeLinkedFile(fsm);
1765 if (rc) break; /* W2DO? */
1767 for (li = fsm->links, prev = NULL; li; prev = li, li = li->next)
1772 fsm->links = fsm->li->next;
1774 prev->next = fsm->li->next;
1775 fsm->li->next = NULL;
1776 fsm->li = freeHardLink(fsm->li);
1778 rc = writeFile(fsm, 1);
1783 if (fsm->goal != FSM_PKGINSTALL)
1786 if (S_ISREG(st->st_mode)) {
1787 char * path = fsm->path;
1789 fsm->path = fsmFsPath(fsm, st, NULL, NULL);
1790 rc = fsmVerify(fsm);
1792 if (rc == 0 && fsm->osuffix) {
1793 char * opath = fsm->opath;
1794 fsm->opath = fsm->path;
1795 fsm->path = fsmFsPath(fsm, st, NULL, fsm->osuffix);
1796 rc = fsmRename(fsm);
1798 rpmlog(RPMLOG_WARNING,
1799 _("%s saved as %s\n"),
1800 (fsm->opath ? fsm->opath : ""),
1801 (fsm->path ? fsm->path : ""));
1802 fsm->path = _free(fsm->path);
1807 if (!(rc == CPIOERR_ENOENT)) return rc;
1808 rc = expandRegular(fsm);
1809 } else if (S_ISDIR(st->st_mode)) {
1810 mode_t st_mode = st->st_mode;
1811 rc = fsmVerify(fsm);
1812 if (rc == CPIOERR_ENOENT) {
1813 st->st_mode &= ~07777; /* XXX abuse st->st_mode */
1814 st->st_mode |= 00700;
1816 st->st_mode = st_mode; /* XXX restore st->st_mode */
1818 } else if (S_ISLNK(st->st_mode)) {
1819 char * opath = fsm->opath;
1821 if ((st->st_size + 1) > fsm->rdsize) {
1822 rc = CPIOERR_HDR_SIZE;
1826 fsm->wrlen = st->st_size;
1827 rc = fsmNext(fsm, FSM_DREAD);
1828 if (!rc && fsm->rdnb != fsm->wrlen)
1829 rc = CPIOERR_READ_FAILED;
1832 fsm->wrbuf[st->st_size] = '\0';
1833 /* XXX symlink(fsm->opath, fsm->path) */
1834 fsm->opath = fsm->wrbuf;
1835 rc = fsmVerify(fsm);
1836 if (rc == CPIOERR_ENOENT) {
1837 rc = symlink(fsm->opath, fsm->path);
1838 if (_fsm_debug && (FSM_SYMLINK & FSM_SYSCALL))
1839 rpmlog(RPMLOG_DEBUG, " %8s (%s, %s) %s\n", fileStageString(FSM_SYMLINK),
1840 fsm->opath, fsm->path, (rc < 0 ? strerror(errno) : ""));
1841 if (rc < 0) rc = CPIOERR_SYMLINK_FAILED;
1843 fsm->opath = opath; /* XXX restore fsm->path */
1844 } else if (S_ISFIFO(st->st_mode)) {
1845 mode_t st_mode = st->st_mode;
1846 /* This mimics cpio S_ISSOCK() behavior but probably isnt' right */
1847 rc = fsmVerify(fsm);
1848 if (rc == CPIOERR_ENOENT) {
1849 st->st_mode = 0000; /* XXX abuse st->st_mode */
1851 rc = mkfifo(fsm->path, (st->st_mode & 07777));
1852 if (_fsm_debug && (FSM_MKFIFO & FSM_SYSCALL))
1853 rpmlog(RPMLOG_DEBUG, " %8s (%s, 0%04o) %s\n", fileStageString(FSM_MKFIFO),
1854 fsm->path, (unsigned)(st->st_mode & 07777),
1855 (rc < 0 ? strerror(errno) : ""));
1856 if (rc < 0) rc = CPIOERR_MKFIFO_FAILED;
1858 st->st_mode = st_mode; /* XXX restore st->st_mode */
1860 } else if (S_ISCHR(st->st_mode) ||
1861 S_ISBLK(st->st_mode) ||
1862 S_ISSOCK(st->st_mode))
1864 rc = fsmVerify(fsm);
1865 if (rc == CPIOERR_ENOENT) {
1866 /* FIX: check S_IFIFO or dev != 0 */
1867 rc = mknod(fsm->path, (fsm->sb.st_mode & ~07777), fsm->sb.st_rdev);
1868 if (_fsm_debug && (FSM_MKNOD & FSM_SYSCALL))
1869 rpmlog(RPMLOG_DEBUG, " %8s (%s, 0%o, 0x%x) %s\n", fileStageString(FSM_MKNOD),
1870 fsm->path, (unsigned)(fsm->sb.st_mode & ~07777),
1871 (unsigned)fsm->sb.st_rdev,
1872 (rc < 0 ? strerror(errno) : ""));
1873 if (rc < 0) rc = CPIOERR_MKNOD_FAILED;
1876 /* XXX Special case /dev/log, which shouldn't be packaged anyways */
1877 if (!IS_DEV_LOG(fsm->path))
1878 rc = CPIOERR_UNKNOWN_FILETYPE;
1880 if (S_ISREG(st->st_mode) && st->st_nlink > 1) {
1881 fsm->li->createdPath = fsm->li->linkIndex;
1882 rc = fsmMakeLinks(fsm);
1888 rc = fsmMakeLinks(fsm);
1890 case FSM_NOTIFY: /* XXX move from fsm to psm -> tsm */
1891 if (fsm->goal == FSM_PKGINSTALL || fsm->goal == FSM_PKGBUILD) {
1892 rpmts ts = fsmGetTs(fsm);
1893 rpmte te = fsmGetTe(fsm);
1894 rpmfi fi = fsmGetFi(fsm);
1896 if (fsm->cpioPos > fsm->archivePos) {
1897 fsm->archivePos = fsm->cpioPos;
1898 ptr = rpmtsNotify(ts, te, RPMCALLBACK_INST_PROGRESS,
1899 fsm->archivePos, fi->archiveSize);
1906 if (fsm->goal == FSM_PKGINSTALL) {
1907 /* XXX only erase if temp fn w suffix is in use */
1908 if (fsm->sufbuf[0] != '\0') {
1909 if (S_ISDIR(st->st_mode)) {
1910 (void) fsmRmdir(fsm);
1912 (void) fsmUnlink(fsm);
1917 if (fsm->failedFile && *fsm->failedFile == NULL)
1918 *fsm->failedFile = xstrdup(fsm->path);
1921 if (!fsm->postpone && fsm->commit) {
1922 if (fsm->goal == FSM_PKGINSTALL)
1923 rc = ((S_ISREG(st->st_mode) && st->st_nlink > 1)
1924 ? fsmCommitLinks(fsm) : fsmNext(fsm, FSM_COMMIT));
1925 if (fsm->goal == FSM_PKGCOMMIT)
1926 rc = fsmNext(fsm, FSM_COMMIT);
1927 if (fsm->goal == FSM_PKGERASE)
1928 rc = fsmNext(fsm, FSM_COMMIT);
1930 fsm->path = _free(fsm->path);
1931 fsm->opath = _free(fsm->opath);
1932 memset(st, 0, sizeof(*st));
1933 memset(ost, 0, sizeof(*ost));
1936 /* Rename pre-existing modified or unmanaged file. */
1937 if (fsm->osuffix && fsm->diskchecked &&
1938 (fsm->exists || (fsm->goal == FSM_PKGINSTALL && S_ISREG(st->st_mode))))
1940 char * opath = fsm->opath;
1941 char * path = fsm->path;
1942 fsm->opath = fsmFsPath(fsm, st, NULL, NULL);
1943 fsm->path = fsmFsPath(fsm, st, NULL, fsm->osuffix);
1944 rc = fsmRename(fsm);
1946 rpmlog(RPMLOG_WARNING, _("%s saved as %s\n"),
1947 (fsm->opath ? fsm->opath : ""),
1948 (fsm->path ? fsm->path : ""));
1950 fsm->path = _free(fsm->path);
1952 fsm->opath = _free(fsm->opath);
1956 /* Remove erased files. */
1957 if (fsm->goal == FSM_PKGERASE) {
1958 if (fsm->action == FA_ERASE) {
1959 rpmte te = fsmGetTe(fsm);
1960 if (S_ISDIR(st->st_mode)) {
1964 case CPIOERR_ENOENT: /* XXX rmdir("/") linux 2.2.x kernel hack */
1965 case CPIOERR_ENOTEMPTY:
1966 /* XXX make sure that build side permits %missingok on directories. */
1967 if (fsm->fflags & RPMFILE_MISSINGOK)
1970 /* XXX common error message. */
1972 (strict_erasures ? RPMLOG_ERR : RPMLOG_DEBUG),
1973 _("%s rmdir of %s failed: Directory not empty\n"),
1974 rpmteTypeString(te), fsm->path);
1978 (strict_erasures ? RPMLOG_ERR : RPMLOG_DEBUG),
1979 _("%s rmdir of %s failed: %s\n"),
1980 rpmteTypeString(te), fsm->path, strerror(errno));
1984 rc = fsmUnlink(fsm);
1987 case CPIOERR_ENOENT:
1988 if (fsm->fflags & RPMFILE_MISSINGOK)
1992 (strict_erasures ? RPMLOG_ERR : RPMLOG_DEBUG),
1993 _("%s unlink of %s failed: %s\n"),
1994 rpmteTypeString(te), fsm->path, strerror(errno));
1999 /* XXX Failure to remove is not (yet) cause for failure. */
2000 if (!strict_erasures) rc = 0;
2004 /* XXX Special case /dev/log, which shouldn't be packaged anyways */
2005 if (!S_ISSOCK(st->st_mode) && !IS_DEV_LOG(fsm->path)) {
2006 /* Rename temporary to final file name. */
2007 if (!S_ISDIR(st->st_mode) &&
2008 (fsm->subdir || fsm->suffix || fsm->nsuffix))
2010 fsm->opath = fsm->path;
2011 fsm->path = fsmFsPath(fsm, st, NULL, fsm->nsuffix);
2012 rc = fsmRename(fsm);
2013 if (!rc && fsm->nsuffix) {
2014 char * opath = fsmFsPath(fsm, st, NULL, NULL);
2015 rpmlog(RPMLOG_WARNING, _("%s created as %s\n"),
2016 (opath ? opath : ""),
2017 (fsm->path ? fsm->path : ""));
2018 opath = _free(opath);
2020 fsm->opath = _free(fsm->opath);
2023 * Set file security context (if not disabled).
2025 if (!rc && !getuid()) {
2026 rc = fsmMapFContext(fsm);
2028 rc = fsmLsetfcon(fsm);
2029 freecon(fsm->fcontext);
2031 fsm->fcontext = NULL;
2033 if (S_ISLNK(st->st_mode)) {
2034 if (!rc && !getuid())
2035 rc = fsmLChown(fsm);
2037 if (!rc && !getuid())
2042 time_t mtime = st->st_mtime;
2043 rpmfi fi = fsmGetFi(fsm);
2044 st->st_mtime = rpmfiFMtimeIndex(fi, fsm->ix);
2046 st->st_mtime = mtime;
2049 if (!rc && !S_ISDIR(st->st_mode) && !getuid()) {
2050 rc = fsmMapFCaps(fsm);
2051 if (!rc && fsm->fcaps) {
2052 rc = fsmSetcap(fsm);
2053 cap_free(fsm->fcaps);
2057 #endif /* WITH_CAP */
2061 /* Notify on success. */
2062 if (!rc) rc = fsmNext(fsm, FSM_NOTIFY);
2063 else if (fsm->failedFile && *fsm->failedFile == NULL) {
2064 *fsm->failedFile = fsm->path;
2069 fsm->path = _free(fsm->path);
2071 /* Check for hard links missing from payload. */
2072 while ((fsm->li = fsm->links) != NULL) {
2073 fsm->links = fsm->li->next;
2074 fsm->li->next = NULL;
2075 if (fsm->goal == FSM_PKGINSTALL &&
2076 fsm->commit && fsm->li->linksLeft)
2078 for (nlink_t i = 0 ; i < fsm->li->linksLeft; i++) {
2079 if (fsm->li->filex[i] < 0)
2081 rc = CPIOERR_MISSING_HARDLINK;
2082 if (fsm->failedFile && *fsm->failedFile == NULL) {
2083 fsm->ix = fsm->li->filex[i];
2084 if (!fsmMapPath(fsm)) {
2085 /* Out-of-sync hardlinks handled as sub-state */
2086 *fsm->failedFile = fsm->path;
2093 if (fsm->goal == FSM_PKGBUILD &&
2094 (fsm->mapFlags & CPIO_ALL_HARDLINKS))
2096 rc = CPIOERR_MISSING_HARDLINK;
2098 fsm->li = freeHardLink(fsm->li);
2100 fsm->ldn = _free(fsm->ldn);
2101 fsm->ldnalloc = fsm->ldnlen = 0;
2102 fsm->rdbuf = fsm->rdb = _free(fsm->rdb);
2103 fsm->wrbuf = fsm->wrb = _free(fsm->wrb);
2106 rc = fsmNext(fsm, FSM_POS);
2108 rc = cpioHeaderRead(fsm, st); /* Read next payload header. */
2110 if (rstreq(fsm->path, CPIO_TRAILER)) { /* Detect end-of-payload. */
2111 fsm->path = _free(fsm->path);
2112 rc = CPIOERR_HDR_TRAILER;
2115 rc = fsmNext(fsm, FSM_POS);
2118 for (left = st->st_size; left > 0; left -= fsm->rdnb) {
2119 fsm->wrlen = (left > fsm->wrsize ? fsm->wrsize : left);
2120 rc = fsmNext(fsm, FSM_DREAD);
2126 left = (modulo - (fsm->cpioPos % modulo)) % modulo;
2129 (void) fsmNext(fsm, FSM_DREAD);
2133 left = (modulo - (fsm->cpioPos % modulo)) % modulo;
2135 memset(fsm->rdbuf, 0, left);
2136 /* XXX DWRITE uses rdnb for I/O length. */
2138 (void) fsmNext(fsm, FSM_DWRITE);
2142 fsm->rdnb = Fread(fsm->wrbuf, sizeof(*fsm->wrbuf), fsm->wrlen, fsm->cfd);
2143 if (_fsm_debug && (stage & FSM_SYSCALL))
2144 rpmlog(RPMLOG_DEBUG, " %8s (%s, %d, cfd)\trdnb %d\n",
2145 cur, (fsm->wrbuf == fsm->wrb ? "wrbuf" : "mmap"),
2146 (int)fsm->wrlen, (int)fsm->rdnb);
2147 if (fsm->rdnb != fsm->wrlen || Ferror(fsm->cfd))
2148 rc = CPIOERR_READ_FAILED;
2150 fsm->cpioPos += fsm->rdnb;
2153 fsm->wrnb = Fwrite(fsm->rdbuf, sizeof(*fsm->rdbuf), fsm->rdnb, fsm->cfd);
2154 if (_fsm_debug && (stage & FSM_SYSCALL))
2155 rpmlog(RPMLOG_DEBUG, " %8s (%s, %d, cfd)\twrnb %d\n",
2156 cur, (fsm->rdbuf == fsm->rdb ? "rdbuf" : "mmap"),
2157 (int)fsm->rdnb, (int)fsm->wrnb);
2158 if (fsm->rdnb != fsm->wrnb || Ferror(fsm->cfd))
2159 rc = CPIOERR_WRITE_FAILED;
2161 fsm->cpioPos += fsm->wrnb;
2165 fsm->rfd = Fopen(fsm->path, "r.ufdio");
2166 if (fsm->rfd == NULL || Ferror(fsm->rfd)) {
2167 if (fsm->rfd != NULL) (void) fsmNext(fsm, FSM_RCLOSE);
2169 rc = CPIOERR_OPEN_FAILED;
2172 if (_fsm_debug && (stage & FSM_SYSCALL))
2173 rpmlog(RPMLOG_DEBUG, " %8s (%s, \"r\") rfd %p rdbuf %p\n", cur,
2174 fsm->path, fsm->rfd, fsm->rdbuf);
2177 fsm->rdnb = Fread(fsm->rdbuf, sizeof(*fsm->rdbuf), fsm->rdlen, fsm->rfd);
2178 if (_fsm_debug && (stage & FSM_SYSCALL))
2179 rpmlog(RPMLOG_DEBUG, " %8s (rdbuf, %d, rfd)\trdnb %d\n",
2180 cur, (int)fsm->rdlen, (int)fsm->rdnb);
2181 if (fsm->rdnb != fsm->rdlen || Ferror(fsm->rfd))
2182 rc = CPIOERR_READ_FAILED;
2185 if (fsm->rfd != NULL) {
2186 if (_fsm_debug && (stage & FSM_SYSCALL))
2187 rpmlog(RPMLOG_DEBUG, " %8s (%p)\n", cur, fsm->rfd);
2188 (void) rpmswAdd(rpmtsOp(fsmGetTs(fsm), RPMTS_OP_DIGEST),
2189 fdOp(fsm->rfd, FDSTAT_DIGEST));
2190 (void) Fclose(fsm->rfd);
2196 fsm->wfd = Fopen(fsm->path, "w.ufdio");
2197 if (fsm->wfd == NULL || Ferror(fsm->wfd)) {
2198 if (fsm->wfd != NULL) (void) fsmNext(fsm, FSM_WCLOSE);
2200 rc = CPIOERR_OPEN_FAILED;
2202 if (_fsm_debug && (stage & FSM_SYSCALL))
2203 rpmlog(RPMLOG_DEBUG, " %8s (%s, \"w\") wfd %p wrbuf %p\n", cur,
2204 fsm->path, fsm->wfd, fsm->wrbuf);
2207 fsm->wrnb = Fwrite(fsm->wrbuf, sizeof(*fsm->wrbuf), fsm->rdnb, fsm->wfd);
2208 if (_fsm_debug && (stage & FSM_SYSCALL))
2209 rpmlog(RPMLOG_DEBUG, " %8s (wrbuf, %d, wfd)\twrnb %d\n",
2210 cur, (int)fsm->rdnb, (int)fsm->wrnb);
2211 if (fsm->rdnb != fsm->wrnb || Ferror(fsm->wfd))
2212 rc = CPIOERR_WRITE_FAILED;
2215 if (fsm->wfd != NULL) {
2216 if (_fsm_debug && (stage & FSM_SYSCALL))
2217 rpmlog(RPMLOG_DEBUG, " %8s (%p)\n", cur, fsm->wfd);
2218 (void) rpmswAdd(rpmtsOp(fsmGetTs(fsm), RPMTS_OP_DIGEST),
2219 fdOp(fsm->wfd, FDSTAT_DIGEST));
2220 (void) Fclose(fsm->wfd);
2230 if (!(stage & FSM_INTERNAL)) {
2231 fsm->rc = (rc == CPIOERR_HDR_TRAILER ? 0 : rc);
2237 * Return formatted string representation of file disposition.
2238 * @param a file dispostion
2239 * @return formatted string
2241 static const char * fileActionString(rpmFileAction a)
2244 case FA_UNKNOWN: return "unknown";
2245 case FA_CREATE: return "create";
2246 case FA_COPYOUT: return "copyout";
2247 case FA_COPYIN: return "copyin";
2248 case FA_BACKUP: return "backup";
2249 case FA_SAVE: return "save";
2250 case FA_SKIP: return "skip";
2251 case FA_ALTNAME: return "altname";
2252 case FA_ERASE: return "erase";
2253 case FA_SKIPNSTATE: return "skipnstate";
2254 case FA_SKIPNETSHARED: return "skipnetshared";
2255 case FA_SKIPCOLOR: return "skipcolor";
2256 default: return "???";
2261 * Return formatted string representation of file stages.
2262 * @param a file stage
2263 * @return formatted string
2265 static const char * fileStageString(fileStage a) {
2267 case FSM_UNKNOWN: return "unknown";
2269 case FSM_PKGINSTALL:return "INSTALL";
2270 case FSM_PKGERASE: return "ERASE";
2271 case FSM_PKGBUILD: return "BUILD";
2272 case FSM_PKGCOMMIT: return "COMMIT";
2273 case FSM_PKGUNDO: return "UNDO";
2275 case FSM_CREATE: return "create";
2276 case FSM_INIT: return "init";
2277 case FSM_MAP: return "map";
2278 case FSM_MKDIRS: return "mkdirs";
2279 case FSM_RMDIRS: return "rmdirs";
2280 case FSM_PRE: return "pre";
2281 case FSM_PROCESS: return "process";
2282 case FSM_POST: return "post";
2283 case FSM_MKLINKS: return "mklinks";
2284 case FSM_NOTIFY: return "notify";
2285 case FSM_UNDO: return "undo";
2286 case FSM_FINI: return "fini";
2287 case FSM_COMMIT: return "commit";
2288 case FSM_DESTROY: return "destroy";
2289 case FSM_VERIFY: return "verify";
2291 case FSM_UNLINK: return "unlink";
2292 case FSM_RENAME: return "rename";
2293 case FSM_MKDIR: return "mkdir";
2294 case FSM_RMDIR: return "rmdir";
2295 case FSM_LSETFCON: return "lsetfcon";
2296 case FSM_CHOWN: return "chown";
2297 case FSM_LCHOWN: return "lchown";
2298 case FSM_CHMOD: return "chmod";
2299 case FSM_UTIME: return "utime";
2300 case FSM_SYMLINK: return "symlink";
2301 case FSM_LINK: return "link";
2302 case FSM_MKFIFO: return "mkfifo";
2303 case FSM_MKNOD: return "mknod";
2304 case FSM_LSTAT: return "lstat";
2305 case FSM_STAT: return "stat";
2306 case FSM_READLINK: return "readlink";
2307 case FSM_SETCAP: return "setcap";
2309 case FSM_NEXT: return "next";
2310 case FSM_EAT: return "eat";
2311 case FSM_POS: return "pos";
2312 case FSM_PAD: return "pad";
2313 case FSM_TRAILER: return "trailer";
2314 case FSM_HREAD: return "hread";
2315 case FSM_HWRITE: return "hwrite";
2316 case FSM_DREAD: return "Fread";
2317 case FSM_DWRITE: return "Fwrite";
2319 case FSM_ROPEN: return "Fopen";
2320 case FSM_READ: return "Fread";
2321 case FSM_RCLOSE: return "Fclose";
2322 case FSM_WOPEN: return "Fopen";
2323 case FSM_WRITE: return "Fwrite";
2324 case FSM_WCLOSE: return "Fclose";
2326 default: return "???";