3 * File state machine to handle a payload from a package.
17 /*@access transactionElement @*/
18 /*@access rpmTransactionSet @*/
20 #define alloca_strdup(_s) strcpy(alloca(strlen(_s)+1), (_s))
25 /* XXX Failure to remove is not (yet) cause for failure. */
26 /*@-exportlocal -exportheadervar@*/
28 int strict_erasures = 0;
29 /*@=exportlocal =exportheadervar@*/
31 rpmTransactionSet fsmGetTs(const FSM_t fsm) {
32 const FSMI_t iter = fsm->iter;
33 /*@-compdef -refcounttrans -retexpose -usereleased @*/
34 return (iter ? iter->ts : NULL);
35 /*@=compdef =refcounttrans =retexpose =usereleased @*/
38 TFI_t fsmGetFi(const FSM_t fsm)
40 const FSMI_t iter = fsm->iter;
41 /*@-compdef -refcounttrans -retexpose -usereleased @*/
42 return (iter ? iter->fi : NULL);
43 /*@=compdef =refcounttrans =retexpose =usereleased @*/
46 #define SUFFIX_RPMORIG ".rpmorig"
47 #define SUFFIX_RPMSAVE ".rpmsave"
48 #define SUFFIX_RPMNEW ".rpmnew"
51 * Build path to file from file info, ornamented with subdir and suffix.
52 * @param fsm file state machine data
53 * @param st file stat info
54 * @param subdir subdir to use (NULL disables)
55 * @param suffix suffix to use (NULL disables)
56 * @retval path to file
58 static /*@only@*//*@null@*/
59 const char * fsmFsPath(/*@special@*/ /*@null@*/ const FSM_t fsm,
60 /*@null@*/ const struct stat * st,
61 /*@null@*/ const char * subdir,
62 /*@null@*/ const char * suffix)
63 /*@uses fsm->dirName, fsm->baseName */
66 const char * s = NULL;
71 nb = strlen(fsm->dirName) +
72 (st && !S_ISDIR(st->st_mode) ? (subdir ? strlen(subdir) : 0) : 0) +
73 (st && !S_ISDIR(st->st_mode) ? (suffix ? strlen(suffix) : 0) : 0) +
74 strlen(fsm->baseName) + 1;
76 t = stpcpy(t, fsm->dirName);
77 if (st && !S_ISDIR(st->st_mode))
78 if (subdir) t = stpcpy(t, subdir);
79 t = stpcpy(t, fsm->baseName);
80 if (st && !S_ISDIR(st->st_mode))
81 if (suffix) t = stpcpy(t, suffix);
87 * Destroy file info iterator.
88 * @param p file info iterator
91 static /*@null@*/ void * mapFreeIterator(/*@only@*//*@null@*/ void * p)
96 iter->ts = rpmtsUnlink(iter->ts, "mapIterator");
97 iter->fi = rpmfiUnlink(iter->fi, "mapIterator");
103 * Create file info iterator.
104 * @param ts transaction set
105 * @param fi transaction element file info
106 * @return file info iterator
109 mapInitIterator(rpmTransactionSet ts, TFI_t fi)
110 /*@modifies ts, fi @*/
114 iter = xcalloc(1, sizeof(*iter));
115 iter->ts = rpmtsLink(ts, "mapIterator");
116 iter->fi = rpmfiLink(fi, "mapIterator");
117 iter->reverse = (fi->te->type == TR_REMOVED && fi->action != FA_COPYOUT);
118 iter->i = (iter->reverse ? (fi->fc - 1) : 0);
119 iter->isave = iter->i;
124 * Return next index into file info.
125 * @param a file info iterator
126 * @return next index, -1 on termination
128 static int mapNextIterator(/*@null@*/ void * a)
135 const TFI_t fi = iter->fi;
137 if (iter->i >= 0) i = iter->i--;
139 if (iter->i < fi->fc) i = iter->i++;
148 static int cpioStrCmp(const void * a, const void * b)
151 const char * afn = *(const char **)a;
152 const char * bfn = *(const char **)b;
154 /* Match rpm-4.0 payloads with ./ prefixes. */
155 if (afn[0] == '.' && afn[1] == '/') afn += 2;
156 if (bfn[0] == '.' && bfn[1] == '/') bfn += 2;
158 /* If either path is absolute, make it relative. */
159 if (afn[0] == '/') afn += 1;
160 if (bfn[0] == '/') bfn += 1;
162 return strcmp(afn, bfn);
166 * Locate archive path in file info.
167 * @param iter file info iterator
168 * @param fsmPath archive path
169 * @return index into file info, -1 if archive path was not found
171 static int mapFind(/*@null@*/ FSMI_t iter, const char * fsmPath)
177 const TFI_t fi = iter->fi;
178 if (fi && fi->fc > 0 && fi->apath && fsmPath && *fsmPath) {
179 const char ** p = NULL;
181 if (fi->apath != NULL)
182 p = bsearch(&fsmPath, fi->apath, fi->fc, sizeof(fsmPath),
185 iter->i = p - fi->apath;
186 ix = mapNextIterator(iter);
194 * Directory name iterator.
196 typedef struct dnli_s {
198 /*@only@*/ /*@null@*/ char * active;
205 * Destroy directory name iterator.
206 * @param a directory name iterator
207 * @retval NULL always
209 static /*@null@*/ void * dnlFreeIterator(/*@only@*//*@null@*/ const void * a)
213 DNLI_t dnli = (void *)a;
214 if (dnli->active) free(dnli->active);
221 static inline int dnlCount(const DNLI_t dnli)
224 return (dnli ? dnli->fi->dc : 0);
229 static inline int dnlIndex(const DNLI_t dnli)
232 return (dnli ? dnli->isave : -1);
236 * Create directory name iterator.
237 * @param fsm file state machine data
238 * @param reverse traverse directory names in reverse order?
239 * @return directory name iterator
242 static /*@only@*/ void * dnlInitIterator(/*@special@*/ const FSM_t fsm,
244 /*@uses fsm->iter @*/
247 TFI_t fi = fsmGetFi(fsm);
253 dnli = xcalloc(1, sizeof(*dnli));
255 dnli->reverse = reverse;
257 dnli->i = (reverse ? fi->dc : 0);
261 dnli->active = xcalloc(fi->dc, sizeof(*dnli->active));
263 /* Identify parent directories not skipped. */
264 for (i = 0; i < fi->fc; i++)
265 if (!XFA_SKIPPING(fi->actions[i])) dnli->active[fi->dil[i]] = 1;
267 /* Exclude parent directories that are explicitly included. */
268 for (i = 0; i < fi->fc; i++) {
269 int dil, dnlen, bnlen;
271 if (!S_ISDIR(fi->fmodes[i]))
275 dnlen = strlen(fi->dnl[dil]);
276 bnlen = strlen(fi->bnl[i]);
278 for (j = 0; j < fi->dc; j++) {
282 if (!dnli->active[j] || j == dil)
283 /*@innercontinue@*/ continue;
286 if (jlen != (dnlen+bnlen+1))
287 /*@innercontinue@*/ continue;
288 if (strncmp(dnl, fi->dnl[dil], dnlen))
289 /*@innercontinue@*/ continue;
290 if (strncmp(dnl+dnlen, fi->bnl[i], bnlen))
291 /*@innercontinue@*/ continue;
292 if (dnl[dnlen+bnlen] != '/' || dnl[dnlen+bnlen+1] != '\0')
293 /*@innercontinue@*/ continue;
294 /* This directory is included in the package. */
296 /*@innerbreak@*/ break;
300 /* Print only once per package. */
303 for (i = 0; i < fi->dc; i++) {
304 if (!dnli->active[i]) continue;
307 rpmMessage(RPMMESS_DEBUG,
308 _("========== Directories not explictly included in package:\n"));
310 rpmMessage(RPMMESS_DEBUG, _("%10d %s\n"), i, fi->dnl[i]);
313 rpmMessage(RPMMESS_DEBUG, "==========\n");
321 * Return next directory name (from file info).
322 * @param dnli directory name iterator
323 * @return next directory name
325 static /*@observer@*/ const char * dnlNextIterator(/*@null@*/ DNLI_t dnli)
328 const char * dn = NULL;
336 i = (!dnli->reverse ? dnli->i++ : --dnli->i);
337 } while (i >= 0 && i < fi->dc && !dnli->active[i]);
339 if (i >= 0 && i < fi->dc)
349 * Save hard link in chain.
350 * @param fsm file state machine data
351 * @return Is chain only partially filled?
353 static int saveHardLink(/*@special@*/ /*@partial@*/ FSM_t fsm)
354 /*@uses fsm->links, fsm->ix, fsm->sb, fsm->goal, fsm->nsuffix @*/
355 /*@defines fsm->li @*/
356 /*@releases fsm->path @*/
357 /*@globals fileSystem@*/
358 /*@modifies fsm, fileSystem @*/
360 struct stat * st = &fsm->sb;
365 /* Find hard link set. */
367 for (fsm->li = fsm->links; fsm->li; fsm->li = fsm->li->next) {
368 if (fsm->li->sb.st_ino == st->st_ino && fsm->li->sb.st_dev == st->st_dev)
373 /* New hard link encountered, add new link to set. */
375 if (fsm->li == NULL) {
376 fsm->li = xcalloc(1, sizeof(*fsm->li));
377 fsm->li->next = NULL;
378 fsm->li->sb = *st; /* structure assignment */
379 fsm->li->nlink = st->st_nlink;
380 fsm->li->linkIndex = fsm->ix;
381 fsm->li->createdPath = -1;
383 fsm->li->filex = xcalloc(st->st_nlink, sizeof(fsm->li->filex[0]));
384 memset(fsm->li->filex, -1, (st->st_nlink * sizeof(fsm->li->filex[0])));
385 fsm->li->nsuffix = xcalloc(st->st_nlink, sizeof(*fsm->li->nsuffix));
387 if (fsm->goal == FSM_PKGBUILD)
388 fsm->li->linksLeft = st->st_nlink;
389 if (fsm->goal == FSM_PKGINSTALL)
390 fsm->li->linksLeft = 0;
393 fsm->li->next = fsm->links;
395 fsm->links = fsm->li;
399 if (fsm->goal == FSM_PKGBUILD) --fsm->li->linksLeft;
400 fsm->li->filex[fsm->li->linksLeft] = fsm->ix;
401 /*@-observertrans -dependenttrans@*/
402 fsm->li->nsuffix[fsm->li->linksLeft] = fsm->nsuffix;
403 /*@=observertrans =dependenttrans@*/
404 if (fsm->goal == FSM_PKGINSTALL) fsm->li->linksLeft++;
406 if (fsm->goal == FSM_PKGBUILD)
407 return (fsm->li->linksLeft > 0);
409 if (fsm->goal != FSM_PKGINSTALL)
412 if (!(st->st_size || fsm->li->linksLeft == st->st_nlink))
415 /* Here come the bits, time to choose a non-skipped file name. */
416 { TFI_t fi = fsmGetFi(fsm);
418 for (j = fsm->li->linksLeft - 1; j >= 0; j--) {
419 ix = fsm->li->filex[j];
420 if (ix < 0 || XFA_SKIPPING(fi->actions[ix]))
426 /* Are all links skipped or not encountered yet? */
428 return 1; /* XXX W2DO? */
430 /* Save the non-skipped file name and map index. */
431 fsm->li->linkIndex = j;
432 fsm->path = _free(fsm->path);
434 rc = fsmStage(fsm, FSM_MAP);
439 * Destroy set of hard links.
440 * @param li set of hard links
442 static /*@null@*/ void * freeHardLink(/*@only@*/ /*@null@*/ struct hardLink_s * li)
446 li->nsuffix = _free(li->nsuffix); /* XXX elements are shared */
447 li->filex = _free(li->filex);
454 FSM_t fsm = xcalloc(1, sizeof(*fsm));
458 FSM_t freeFSM(FSM_t fsm)
461 fsm->path = _free(fsm->path);
463 while ((fsm->li = fsm->links) != NULL) {
464 fsm->links = fsm->li->next;
465 fsm->li->next = NULL;
466 fsm->li = freeHardLink(fsm->li);
469 fsm->dnlx = _free(fsm->dnlx);
470 fsm->ldn = _free(fsm->ldn);
471 fsm->iter = mapFreeIterator(fsm->iter);
476 int fsmSetup(FSM_t fsm, fileStage goal,
477 const rpmTransactionSet ts, const TFI_t fi, FD_t cfd,
478 unsigned int * archiveSize, const char ** failedFile)
485 /*@-type@*/ /* FIX: cast? */
486 fsm->cfd = fdLink(cfd, "persist (fsm)");
488 pos = fdGetCpioPos(fsm->cfd);
489 fdSetCpioPos(fsm->cfd, 0);
491 fsm->iter = mapInitIterator(ts, fi);
493 if (fsm->goal == FSM_PKGINSTALL) {
494 if (ts && ts->notify) {
495 /*@-type@*/ /* FIX: cast? */
496 /*@-noeffectuncon @*/ /* FIX: check rc */
497 (void)ts->notify(fi->h, RPMCALLBACK_INST_START, 0, fi->archiveSize,
498 rpmfiGetKey(fi), ts->notifyData);
499 /*@=noeffectuncon @*/
505 fsm->archiveSize = archiveSize;
506 if (fsm->archiveSize)
507 *fsm->archiveSize = 0;
508 fsm->failedFile = failedFile;
510 *fsm->failedFile = NULL;
513 memset(fsm->sufbuf, 0, sizeof(fsm->sufbuf));
514 if (fsm->goal == FSM_PKGINSTALL) {
515 if (ts && ts->id > 0)
516 sprintf(fsm->sufbuf, ";%08x", (unsigned)ts->id);
520 rc = fsmStage(fsm, FSM_CREATE);
521 if (rc && !ec) ec = rc;
523 rc = fsmStage(fsm, fsm->goal);
524 if (rc && !ec) ec = rc;
526 if (fsm->archiveSize && ec == 0)
527 *fsm->archiveSize = (fdGetCpioPos(fsm->cfd) - pos);
532 int fsmTeardown(FSM_t fsm)
537 rc = fsmStage(fsm, FSM_DESTROY);
539 fsm->iter = mapFreeIterator(fsm->iter);
541 /*@-type@*/ /* FIX: cast? */
542 fsm->cfd = fdFree(fsm->cfd, "persist (fsm)");
546 fsm->failedFile = NULL;
550 int fsmMapPath(FSM_t fsm)
552 TFI_t fi = fsmGetFi(fsm); /* XXX const except for fstates */
559 fsm->action = FA_UNKNOWN;
563 if (fi && i >= 0 && i < fi->fc) {
565 fsm->astriplen = fi->astriplen;
566 fsm->action = (fi->actions ? fi->actions[i] : fi->action);
567 fsm->fflags = (fi->fflags ? fi->fflags[i] : fi->flags);
568 fsm->mapFlags = (fi->fmapflags ? fi->fmapflags[i] : fi->mapflags);
570 /* src rpms have simple base name in payload. */
571 fsm->dirName = fi->dnl[fi->dil[i]];
572 fsm->baseName = fi->bnl[i];
574 switch (fsm->action) {
577 case FA_SKIPMULTILIB: /* XXX RPMFILE_STATE_MULTILIB? */
586 assert(fi->te->type == TR_ADDED);
590 if (fi->fstates && fi->te->type == TR_ADDED)
591 fi->fstates[i] = RPMFILE_STATE_NOTINSTALLED;
594 case FA_SKIPNETSHARED:
595 if (fi->fstates && fi->te->type == TR_ADDED)
596 fi->fstates[i] = RPMFILE_STATE_NETSHARED;
600 if (!(fsm->fflags & RPMFILE_GHOST)) /* XXX Don't if %ghost file. */
601 switch (fi->te->type) {
603 fsm->osuffix = SUFFIX_RPMORIG;
604 /*@innerbreak@*/ break;
606 fsm->osuffix = SUFFIX_RPMSAVE;
607 /*@innerbreak@*/ break;
612 assert(fi->te->type == TR_ADDED);
613 if (!(fsm->fflags & RPMFILE_GHOST)) /* XXX Don't if %ghost file. */
614 fsm->nsuffix = SUFFIX_RPMNEW;
618 assert(fi->te->type == TR_ADDED);
619 if (!(fsm->fflags & RPMFILE_GHOST)) /* XXX Don't if %ghost file. */
620 fsm->osuffix = SUFFIX_RPMSAVE;
623 assert(fi->te->type == TR_REMOVED);
625 * XXX TODO: %ghost probably shouldn't be removed, but that changes
626 * legacy rpm behavior.
633 if ((fsm->mapFlags & CPIO_MAP_PATH) || fsm->nsuffix) {
634 const struct stat * st = &fsm->sb;
635 fsm->path = _free(fsm->path);
636 fsm->path = fsmFsPath(fsm, st, fsm->subdir,
637 (fsm->suffix ? fsm->suffix : fsm->nsuffix));
643 int fsmMapAttrs(FSM_t fsm)
645 struct stat * st = &fsm->sb;
646 TFI_t fi = fsmGetFi(fsm);
649 if (fi && i >= 0 && i < fi->fc) {
651 (S_ISDIR(st->st_mode) ? fi->dperms : fi->fperms);
653 (fi->fmodes ? fi->fmodes[i] : perms);
655 (fi->fuids ? fi->fuids[i] : fi->uid); /* XXX chmod u-s */
657 (fi->fgids ? fi->fgids[i] : fi->gid); /* XXX chmod g-s */
659 (fi->frdevs ? fi->frdevs[i] : 0);
661 (fi->fmtimes ? fi->fmtimes[i] : 0);
663 if (fsm->mapFlags & CPIO_MAP_MODE)
664 st->st_mode = (st->st_mode & S_IFMT) | (finalMode & ~S_IFMT);
665 if (fsm->mapFlags & CPIO_MAP_TYPE) {
666 st->st_mode = (st->st_mode & ~S_IFMT) | (finalMode & S_IFMT);
667 if ((S_ISCHR(st->st_mode) || S_ISBLK(st->st_mode))
668 && st->st_nlink == 0)
670 st->st_rdev = finalRdev;
671 st->st_mtime = finalMtime;
673 if (fsm->mapFlags & CPIO_MAP_UID)
674 st->st_uid = finalUid;
675 if (fsm->mapFlags & CPIO_MAP_GID)
676 st->st_gid = finalGid;
678 { rpmTransactionSet ts = fsmGetTs(fsm);
680 if (ts != NULL && !(ts->transFlags & RPMTRANS_FLAG_NOMD5)) {
681 fsm->fmd5sum = (fi->fmd5s ? fi->fmd5s[i] : NULL);
682 fsm->md5sum = (fi->md5s ? (fi->md5s + (16 * i)) : NULL);
694 * Create file from payload stream.
695 * @param fsm file state machine data
696 * @return 0 on success
698 static int expandRegular(/*@special@*/ FSM_t fsm)
700 /*@globals fileSystem@*/
701 /*@modifies fsm, fileSystem @*/
703 const struct stat * st = &fsm->sb;
704 int left = st->st_size;
707 rc = fsmStage(fsm, FSM_WOPEN);
711 if (st->st_size > 0 && (fsm->fmd5sum || fsm->md5sum))
712 fdInitDigest(fsm->wfd, PGPHASHALGO_MD5, 0);
716 fsm->wrlen = (left > fsm->wrsize ? fsm->wrsize : left);
717 rc = fsmStage(fsm, FSM_DREAD);
721 rc = fsmStage(fsm, FSM_WRITE);
727 /* don't call this with fileSize == fileComplete */
729 (void) fsmStage(fsm, FSM_NOTIFY);
732 if (st->st_size > 0 && (fsm->fmd5sum || fsm->md5sum)) {
733 void * md5sum = NULL;
734 int asAscii = (fsm->md5sum == NULL ? 1 : 0);
736 (void) Fflush(fsm->wfd);
737 fdFiniDigest(fsm->wfd, PGPHASHALGO_MD5, &md5sum, NULL, asAscii);
739 if (md5sum == NULL) {
740 rc = CPIOERR_MD5SUM_MISMATCH;
744 if (fsm->md5sum != NULL) {
745 if (memcmp(md5sum, fsm->md5sum, 16))
746 rc = CPIOERR_MD5SUM_MISMATCH;
748 if (strcmp(md5sum, fsm->fmd5sum))
749 rc = CPIOERR_MD5SUM_MISMATCH;
751 md5sum = _free(md5sum);
755 (void) fsmStage(fsm, FSM_WCLOSE);
760 * Write next item to payload stream.
761 * @param fsm file state machine data
762 * @param writeData should data be written?
763 * @return 0 on success
765 static int writeFile(/*@special@*/ FSM_t fsm, int writeData)
766 /*@uses fsm->path, fsm->opath, fsm->sb, fsm->osb, fsm->cfd @*/
767 /*@globals fileSystem@*/
768 /*@modifies fsm, fileSystem @*/
770 const char * path = fsm->path;
771 const char * opath = fsm->opath;
772 struct stat * st = &fsm->sb;
773 struct stat * ost = &fsm->osb;
774 size_t pos = fdGetCpioPos(fsm->cfd);
775 char * symbuf = NULL;
780 st->st_size = (writeData ? ost->st_size : 0);
783 if (S_ISDIR(st->st_mode)) {
785 } else if (S_ISLNK(st->st_mode)) {
787 * While linux puts the size of a symlink in the st_size field,
788 * I don't think that's a specified standard.
790 /* XXX NUL terminated result in fsm->rdbuf, len in fsm->rdnb. */
791 rc = fsmStage(fsm, FSM_READLINK);
793 st->st_size = fsm->rdnb;
794 symbuf = alloca_strdup(fsm->rdbuf); /* XXX save readlink return. */
798 if (fsm->mapFlags & CPIO_MAP_ABSOLUTE) {
799 /*@-compdef@*/ /* FIX: dirName/baseName annotations ? */
800 int nb = strlen(fsm->dirName) + strlen(fsm->baseName) + sizeof(".");
801 char * t = alloca(nb);
804 if (fsm->mapFlags & CPIO_MAP_ADDDOT)
806 t = stpcpy( stpcpy(t, fsm->dirName), fsm->baseName);
808 } else if (fsm->mapFlags & CPIO_MAP_PATH) {
809 TFI_t fi = fsmGetFi(fsm);
811 (fi->apath ? fi->apath[fsm->ix] + fi->striplen : fi->bnl[fsm->ix]);
814 rc = fsmStage(fsm, FSM_HWRITE);
818 if (writeData && S_ISREG(st->st_mode)) {
821 void * mapped = (void *)-1;
825 rc = fsmStage(fsm, FSM_ROPEN);
828 /* XXX unbuffered mmap generates *lots* of fdio debugging */
831 mapped = mmap(NULL, st->st_size, PROT_READ, MAP_SHARED, Fileno(fsm->rfd), 0);
832 if (mapped != (void *)-1) {
834 fsm->rdbuf = (char *) mapped;
835 fsm->rdlen = nmapped = st->st_size;
836 #if defined(MADV_DONTNEED)
837 xx = madvise(mapped, nmapped, MADV_DONTNEED);
846 if (mapped != (void *)-1) {
851 fsm->rdlen = (left > fsm->rdsize ? fsm->rdsize : left),
852 rc = fsmStage(fsm, FSM_READ);
856 /* XXX DWRITE uses rdnb for I/O length. */
857 rc = fsmStage(fsm, FSM_DWRITE);
864 if (mapped != (void *)-1) {
865 xx = msync(mapped, nmapped, MS_ASYNC);
866 #if defined(MADV_DONTNEED)
867 xx = madvise(mapped, nmapped, MADV_DONTNEED);
869 /*@-noeffect@*/ xx = munmap(mapped, nmapped) /*@=noeffect@*/;
874 } else if (writeData && S_ISLNK(st->st_mode)) {
875 /* XXX DWRITE uses rdnb for I/O length. */
876 strcpy(fsm->rdbuf, symbuf); /* XXX restore readlink buffer. */
877 fsm->rdnb = strlen(symbuf);
878 rc = fsmStage(fsm, FSM_DWRITE);
882 rc = fsmStage(fsm, FSM_PAD);
885 { const rpmTransactionSet ts = fsmGetTs(fsm);
886 TFI_t fi = fsmGetFi(fsm);
887 if (ts && ts->notify && fi) {
888 size_t size = (fdGetCpioPos(fsm->cfd) - pos);
889 /*@-type@*/ /* FIX: cast? */
890 /*@-noeffectuncon @*/ /* FIX: check rc */
891 (void)ts->notify(fi->h, RPMCALLBACK_INST_PROGRESS, size, size,
892 rpmfiGetKey(fi), ts->notifyData);
893 /*@=noeffectuncon @*/
902 (void) fsmStage(fsm, FSM_RCLOSE);
903 /*@-dependenttrans@*/
906 /*@=dependenttrans@*/
911 * Write set of linked files to payload stream.
912 * @param fsm file state machine data
913 * @return 0 on success
915 static int writeLinkedFile(/*@special@*/ FSM_t fsm)
916 /*@uses fsm->path, fsm->nsuffix, fsm->ix, fsm->li, fsm->failedFile @*/
917 /*@globals fileSystem@*/
918 /*@modifies fsm, fileSystem @*/
920 const char * path = fsm->path;
921 const char * nsuffix = fsm->nsuffix;
922 int iterIndex = fsm->ix;
931 for (i = fsm->li->nlink - 1; i >= 0; i--) {
933 if (fsm->li->filex[i] < 0) continue;
935 fsm->ix = fsm->li->filex[i];
936 rc = fsmStage(fsm, FSM_MAP);
938 /* Write data after last link. */
939 rc = writeFile(fsm, (i == 0));
940 if (fsm->failedFile && rc != 0 && *fsm->failedFile == NULL) {
942 *fsm->failedFile = xstrdup(fsm->path);
945 fsm->path = _free(fsm->path);
946 fsm->li->filex[i] = -1;
950 fsm->nsuffix = nsuffix;
956 * Create pending hard links to existing file.
957 * @param fsm file state machine data
958 * @return 0 on success
960 static int fsmMakeLinks(/*@special@*/ FSM_t fsm)
961 /*@uses fsm->path, fsm->opath, fsm->nsuffix, fsm->ix, fsm->li @*/
962 /*@globals fileSystem@*/
963 /*@modifies fsm, fileSystem @*/
965 const char * path = fsm->path;
966 const char * opath = fsm->opath;
967 const char * nsuffix = fsm->nsuffix;
968 int iterIndex = fsm->ix;
978 fsm->ix = fsm->li->filex[fsm->li->createdPath];
979 rc = fsmStage(fsm, FSM_MAP);
980 fsm->opath = fsm->path;
983 for (i = 0; i < fsm->li->nlink; i++) {
984 if (fsm->li->filex[i] < 0) continue;
985 if (fsm->li->createdPath == i) continue;
987 fsm->ix = fsm->li->filex[i];
988 fsm->path = _free(fsm->path);
989 rc = fsmStage(fsm, FSM_MAP);
990 if (XFA_SKIPPING(fsm->action)) continue;
992 rc = fsmStage(fsm, FSM_VERIFY);
994 if (rc != CPIOERR_LSTAT_FAILED) break;
996 /* XXX link(fsm->opath, fsm->path) */
997 rc = fsmStage(fsm, FSM_LINK);
998 if (fsm->failedFile && rc != 0 && *fsm->failedFile == NULL) {
1000 *fsm->failedFile = xstrdup(fsm->path);
1003 fsm->li->linksLeft--;
1006 fsm->path = _free(fsm->path);
1007 fsm->opath = _free(fsm->opath);
1009 fsm->ix = iterIndex;
1010 fsm->nsuffix = nsuffix;
1016 /** \ingroup payload
1017 * Commit hard linked file set atomically.
1018 * @param fsm file state machine data
1019 * @return 0 on success
1021 static int fsmCommitLinks(/*@special@*/ FSM_t fsm)
1022 /*@uses fsm->path, fsm->nsuffix, fsm->ix, fsm->sb,
1023 fsm->li, fsm->links @*/
1024 /*@globals fileSystem@*/
1025 /*@modifies fsm, fileSystem @*/
1027 const char * path = fsm->path;
1028 const char * nsuffix = fsm->nsuffix;
1029 int iterIndex = fsm->ix;
1030 struct stat * st = &fsm->sb;
1035 fsm->nsuffix = NULL;
1039 for (fsm->li = fsm->links; fsm->li; fsm->li = fsm->li->next) {
1040 if (fsm->li->sb.st_ino == st->st_ino && fsm->li->sb.st_dev == st->st_dev)
1045 for (i = 0; i < fsm->li->nlink; i++) {
1046 if (fsm->li->filex[i] < 0) continue;
1047 fsm->ix = fsm->li->filex[i];
1048 rc = fsmStage(fsm, FSM_MAP);
1049 if (!XFA_SKIPPING(fsm->action))
1050 rc = fsmStage(fsm, FSM_COMMIT);
1051 fsm->path = _free(fsm->path);
1052 fsm->li->filex[i] = -1;
1055 fsm->ix = iterIndex;
1056 fsm->nsuffix = nsuffix;
1062 * Remove (if created) directories not explicitly included in package.
1063 * @param fsm file state machine data
1064 * @return 0 on success
1066 static int fsmRmdirs(/*@special@*/ FSM_t fsm)
1067 /*@uses fsm->path, fsm->dnlx, fsm->ldn, fsm->rdbuf, fsm->iter @*/
1068 /*@globals fileSystem@*/
1069 /*@modifies fsm, fileSystem @*/
1071 const char * path = fsm->path;
1072 void * dnli = dnlInitIterator(fsm, 1);
1073 char * dn = fsm->rdbuf;
1074 int dc = dnlCount(dnli);
1079 /*@-observertrans -dependenttrans@*/
1080 if (fsm->ldn != NULL && fsm->dnlx != NULL)
1081 while ((fsm->path = dnlNextIterator(dnli)) != NULL) {
1082 int dnlen = strlen(fsm->path);
1085 dc = dnlIndex(dnli);
1086 if (fsm->dnlx[dc] < 1 || fsm->dnlx[dc] >= dnlen)
1089 /* Copy to avoid const on fsm->path. */
1090 te = stpcpy(dn, fsm->path) - 1;
1093 /* Remove generated directories. */
1094 /*@-usereleased@*/ /* LCL: te used after release? */
1098 rc = fsmStage(fsm, FSM_RMDIR);
1102 /*@innerbreak@*/ break;
1104 } while ((te - fsm->path) > fsm->dnlx[dc]);
1107 dnli = dnlFreeIterator(dnli);
1108 /*@=observertrans =dependenttrans@*/
1115 * Create (if necessary) directories not explicitly included in package.
1116 * @param fsm file state machine data
1117 * @return 0 on success
1119 static int fsmMkdirs(/*@special@*/ FSM_t fsm)
1120 /*@uses fsm->path, fsm->sb, fsm->osb, fsm->rdbuf, fsm->iter,
1121 fsm->ldn, fsm->ldnlen, fsm->ldnalloc @*/
1122 /*@defines fsm->dnlx, fsm->ldn @*/
1123 /*@globals fileSystem@*/
1124 /*@modifies fsm, fileSystem @*/
1126 struct stat * st = &fsm->sb;
1127 struct stat * ost = &fsm->osb;
1128 const char * path = fsm->path;
1129 mode_t st_mode = st->st_mode;
1130 void * dnli = dnlInitIterator(fsm, 0);
1131 char * dn = fsm->rdbuf;
1132 int dc = dnlCount(dnli);
1139 fsm->dnlx = (dc ? xcalloc(dc, sizeof(*fsm->dnlx)) : NULL);
1140 /*@-observertrans -dependenttrans@*/
1141 if (fsm->dnlx != NULL)
1142 while ((fsm->path = dnlNextIterator(dnli)) != NULL) {
1143 int dnlen = strlen(fsm->path);
1146 dc = dnlIndex(dnli);
1147 if (dc < 0) continue;
1148 fsm->dnlx[dc] = dnlen;
1152 /*@-compdef -nullpass@*/ /* FIX: fsm->ldn not defined ??? */
1153 if (dnlen <= fsm->ldnlen && !strcmp(fsm->path, fsm->ldn))
1155 /*@=compdef =nullpass@*/
1157 /* Copy to avoid const on fsm->path. */
1158 (void) stpcpy(dn, fsm->path);
1161 /* Assume '/' directory exists, "mkdir -p" for others if non-existent */
1162 for (i = 1, te = dn + 1; *te != '\0'; te++, i++) {
1164 /*@innercontinue@*/ continue;
1168 /* Already validated? */
1169 /*@-usedef -compdef -nullpass -nullderef@*/
1170 if (i < fsm->ldnlen &&
1171 (fsm->ldn[i] == '/' || fsm->ldn[i] == '\0') &&
1172 !strncmp(fsm->path, fsm->ldn, i))
1175 /* Move pre-existing path marker forward. */
1176 fsm->dnlx[dc] = (te - dn);
1177 /*@innercontinue@*/ continue;
1179 /*@=usedef =compdef =nullpass =nullderef@*/
1181 /* Validate next component of path. */
1182 rc = fsmStage(fsm, FSM_LSTAT);
1185 /* Directory already exists? */
1186 if (rc == 0 && S_ISDIR(ost->st_mode)) {
1187 /* Move pre-existing path marker forward. */
1188 fsm->dnlx[dc] = (te - dn);
1189 } else if (rc == CPIOERR_LSTAT_FAILED) {
1190 TFI_t fi = fsmGetFi(fsm);
1192 st->st_mode = S_IFDIR | (fi->dperms & 07777);
1193 rc = fsmStage(fsm, FSM_MKDIR);
1195 rpmMessage(RPMMESS_DEBUG,
1196 _("%s directory created with perms %04o.\n"),
1197 fsm->path, (unsigned)(st->st_mode & 07777));
1201 /*@innerbreak@*/ break;
1205 /* Save last validated path. */
1206 /*@-compdef@*/ /* FIX: ldn/path annotations ? */
1207 if (fsm->ldnalloc < (dnlen + 1)) {
1208 fsm->ldnalloc = dnlen + 100;
1209 fsm->ldn = xrealloc(fsm->ldn, fsm->ldnalloc);
1211 if (fsm->ldn != NULL) { /* XXX can't happen */
1212 strcpy(fsm->ldn, fsm->path);
1213 fsm->ldnlen = dnlen;
1217 dnli = dnlFreeIterator(dnli);
1218 /*@=observertrans =dependenttrans@*/
1221 st->st_mode = st_mode; /* XXX restore st->st_mode */
1222 /*@-compdef@*/ /* FIX: ldn/path annotations ? */
1229 * Check for file on disk.
1230 * @param fsm file state machine data
1231 * @return 0 on success
1233 static int fsmStat(FSM_t fsm)
1235 int saveerrno = errno;
1238 if (fsm->path != NULL) {
1239 int saveernno = errno;
1240 rc = fsmStage(fsm, (!(fsm->mapFlags & CPIO_FOLLOW_SYMLINKS)
1241 ? FSM_LSTAT : FSM_STAT));
1242 if (rc == CPIOERR_LSTAT_FAILED && errno == ENOENT) {
1246 } else if (rc == 0) {
1250 /* Skip %ghost files on build. */
1257 #define IS_DEV_LOG(_x) \
1258 ((_x) != NULL && strlen(_x) >= (sizeof("/dev/log")-1) && \
1259 !strncmp((_x), "/dev/log", sizeof("/dev/log")-1) && \
1260 ((_x)[sizeof("/dev/log")-1] == '\0' || \
1261 (_x)[sizeof("/dev/log")-1] == ';'))
1264 int fsmStage(FSM_t fsm, fileStage stage)
1267 fileStage prevStage = fsm->stage;
1268 const char * const prev = fileStageString(prevStage);
1270 static int modulo = 4;
1271 const char * const cur = fileStageString(stage);
1272 struct stat * st = &fsm->sb;
1273 struct stat * ost = &fsm->osb;
1274 int saveerrno = errno;
1279 #define _fafilter(_a) \
1280 (!((_a) == FA_CREATE || (_a) == FA_ERASE || (_a) == FA_COPYIN || (_a) == FA_COPYOUT) \
1281 ? fileActionString(_a) : "")
1283 if (stage & FSM_DEAD) {
1285 } else if (stage & FSM_INTERNAL) {
1286 if (_fsm_debug && !(stage & FSM_SYSCALL))
1287 rpmMessage(RPMMESS_DEBUG, " %8s %06o%3d (%4d,%4d)%10d %s %s\n",
1289 (unsigned)st->st_mode, (int)st->st_nlink,
1290 (int)st->st_uid, (int)st->st_gid, (int)st->st_size,
1291 (fsm->path ? fsm->path : ""),
1292 _fafilter(fsm->action));
1295 if (_fsm_debug || !(stage & FSM_VERBOSE))
1296 rpmMessage(RPMMESS_DEBUG, "%-8s %06o%3d (%4d,%4d)%10d %s %s\n",
1298 (unsigned)st->st_mode, (int)st->st_nlink,
1299 (int)st->st_uid, (int)st->st_gid, (int)st->st_size,
1300 (fsm->path ? fsm->path + fsm->astriplen : ""),
1301 _fafilter(fsm->action));
1309 case FSM_PKGINSTALL:
1311 /* Clean fsm, free'ing memory. Read next archive header. */
1312 rc = fsmStage(fsm, FSM_INIT);
1314 /* Exit on end-of-payload. */
1315 if (rc == CPIOERR_HDR_TRAILER) {
1317 /*@loopbreak@*/ break;
1320 /* Exit on error. */
1323 (void) fsmStage(fsm, FSM_UNDO);
1324 /*@loopbreak@*/ break;
1327 /* Extract file from archive. */
1328 rc = fsmStage(fsm, FSM_PROCESS);
1330 (void) fsmStage(fsm, FSM_UNDO);
1331 /*@loopbreak@*/ break;
1334 /* Notify on success. */
1335 (void) fsmStage(fsm, FSM_NOTIFY);
1337 rc = fsmStage(fsm, FSM_FINI);
1339 /*@loopbreak@*/ break;
1346 /* Clean fsm, free'ing memory. */
1347 rc = fsmStage(fsm, FSM_INIT);
1349 /* Exit on end-of-payload. */
1350 if (rc == CPIOERR_HDR_TRAILER) {
1352 /*@loopbreak@*/ break;
1355 /* Rename/erase next item. */
1356 if (fsmStage(fsm, FSM_FINI))
1357 /*@loopbreak@*/ break;
1363 rc = fsmStage(fsm, FSM_INIT);
1365 /* Exit on end-of-payload. */
1366 if (rc == CPIOERR_HDR_TRAILER) {
1368 /*@loopbreak@*/ break;
1371 /* Exit on error. */
1374 (void) fsmStage(fsm, FSM_UNDO);
1375 /*@loopbreak@*/ break;
1378 /* Copy file into archive. */
1379 rc = fsmStage(fsm, FSM_PROCESS);
1381 (void) fsmStage(fsm, FSM_UNDO);
1382 /*@loopbreak@*/ break;
1385 if (fsmStage(fsm, FSM_FINI))
1386 /*@loopbreak@*/ break;
1389 /* Flush partial sets of hard linked files. */
1390 if (!(fsm->mapFlags & CPIO_ALL_HARDLINKS)) {
1392 while ((fsm->li = fsm->links) != NULL) {
1393 fsm->links = fsm->li->next;
1394 fsm->li->next = NULL;
1396 /* Re-calculate link count for archive header. */
1397 for (j = -1, nlink = 0, i = 0; i < fsm->li->nlink; i++) {
1398 if (fsm->li->filex[i] < 0)
1399 /*@innercontinue@*/ continue;
1403 /* XXX force the contents out as well. */
1405 fsm->li->filex[0] = fsm->li->filex[j];
1406 fsm->li->filex[j] = -1;
1408 fsm->li->sb.st_nlink = nlink;
1410 fsm->sb = fsm->li->sb; /* structure assignment */
1411 fsm->osb = fsm->sb; /* structure assignment */
1413 if (!rc) rc = writeLinkedFile(fsm);
1415 fsm->li = freeHardLink(fsm->li);
1420 rc = fsmStage(fsm, FSM_TRAILER);
1424 { rpmTransactionSet ts = fsmGetTs(fsm);
1425 #define _tsmask (RPMTRANS_FLAG_PKGCOMMIT | RPMTRANS_FLAG_COMMIT)
1426 fsm->commit = ((ts && (ts->transFlags & _tsmask) &&
1427 fsm->goal != FSM_PKGCOMMIT) ? 0 : 1);
1430 fsm->path = _free(fsm->path);
1431 fsm->opath = _free(fsm->opath);
1432 fsm->dnlx = _free(fsm->dnlx);
1434 fsm->ldn = _free(fsm->ldn);
1435 fsm->ldnalloc = fsm->ldnlen = 0;
1437 fsm->rdsize = fsm->wrsize = 0;
1438 fsm->rdbuf = fsm->rdb = _free(fsm->rdb);
1439 fsm->wrbuf = fsm->wrb = _free(fsm->wrb);
1440 if (fsm->goal == FSM_PKGINSTALL || fsm->goal == FSM_PKGBUILD) {
1441 fsm->rdsize = 8 * BUFSIZ;
1442 fsm->rdbuf = fsm->rdb = xmalloc(fsm->rdsize);
1443 fsm->wrsize = 8 * BUFSIZ;
1444 fsm->wrbuf = fsm->wrb = xmalloc(fsm->wrsize);
1447 fsm->mkdirsdone = 0;
1452 errno = 0; /* XXX get rid of EBADF */
1455 /* Detect and create directories not explicitly in package. */
1456 if (fsm->goal == FSM_PKGINSTALL) {
1457 rc = fsmStage(fsm, FSM_MKDIRS);
1458 if (!rc) fsm->mkdirsdone = 1;
1463 fsm->path = _free(fsm->path);
1465 fsm->diskchecked = fsm->exists = 0;
1467 fsm->suffix = (fsm->sufbuf[0] != '\0' ? fsm->sufbuf : NULL);
1468 fsm->action = FA_UNKNOWN;
1469 fsm->osuffix = NULL;
1470 fsm->nsuffix = NULL;
1472 if (fsm->goal == FSM_PKGINSTALL) {
1473 /* Read next header from payload, checking for end-of-payload. */
1474 rc = fsmStage(fsm, FSM_NEXT);
1478 /* Identify mapping index. */
1479 fsm->ix = ((fsm->goal == FSM_PKGINSTALL)
1480 ? mapFind(fsm->iter, fsm->path) : mapNextIterator(fsm->iter));
1482 /* Detect end-of-loop and/or mapping error. */
1484 if (fsm->goal == FSM_PKGINSTALL) {
1486 rpmMessage(RPMMESS_WARNING,
1487 _("archive file %s was not found in header file list\n"),
1490 if (fsm->failedFile && *fsm->failedFile == NULL)
1491 *fsm->failedFile = xstrdup(fsm->path);
1492 rc = CPIOERR_UNMAPPED_FILE;
1494 rc = CPIOERR_HDR_TRAILER;
1499 /* On non-install, mode must be known so that dirs don't get suffix. */
1500 if (fsm->goal != FSM_PKGINSTALL) {
1501 TFI_t fi = fsmGetFi(fsm);
1502 st->st_mode = fi->fmodes[fsm->ix];
1505 /* Generate file path. */
1506 rc = fsmStage(fsm, FSM_MAP);
1509 /* Perform lstat/stat for disk file. */
1513 if (fsm->path != NULL &&
1514 !(fsm->goal == FSM_PKGINSTALL && S_ISREG(st->st_mode)))
1516 rc = fsmStage(fsm, (!(fsm->mapFlags & CPIO_FOLLOW_SYMLINKS)
1517 ? FSM_LSTAT : FSM_STAT));
1518 if (rc == CPIOERR_LSTAT_FAILED && errno == ENOENT) {
1524 } else if (rc == 0) {
1528 /* Skip %ghost files on build. */
1532 fsm->diskchecked = 1;
1535 /* On non-install, the disk file stat is what's remapped. */
1536 if (fsm->goal != FSM_PKGINSTALL)
1537 *st = *ost; /* structure assignment */
1539 /* Remap file perms, owner, and group. */
1540 rc = fsmMapAttrs(fsm);
1543 fsm->postpone = XFA_SKIPPING(fsm->action);
1544 if (fsm->goal == FSM_PKGINSTALL || fsm->goal == FSM_PKGBUILD) {
1545 /*@-evalorder@*/ /* FIX: saveHardLink can modify fsm */
1546 if (!S_ISDIR(st->st_mode) && st->st_nlink > 1)
1547 fsm->postpone = saveHardLink(fsm);
1554 rc = fsmMapPath(fsm);
1557 rc = fsmMkdirs(fsm);
1561 rc = fsmRmdirs(fsm);
1564 if (fsm->postpone) {
1565 if (fsm->goal == FSM_PKGINSTALL)
1566 rc = fsmStage(fsm, FSM_EAT);
1570 if (fsm->goal == FSM_PKGBUILD) {
1571 if (!S_ISDIR(st->st_mode) && st->st_nlink > 1) {
1572 struct hardLink_s * li, * prev;
1574 if (!(fsm->mapFlags & CPIO_ALL_HARDLINKS)) break;
1575 rc = writeLinkedFile(fsm);
1576 if (rc) break; /* W2DO? */
1578 for (li = fsm->links, prev = NULL; li; prev = li, li = li->next)
1580 /*@loopbreak@*/ break;
1583 fsm->links = fsm->li->next;
1585 prev->next = fsm->li->next;
1586 fsm->li->next = NULL;
1587 fsm->li = freeHardLink(fsm->li);
1589 rc = writeFile(fsm, 1);
1594 if (fsm->goal != FSM_PKGINSTALL)
1597 if (S_ISREG(st->st_mode)) {
1598 const char * path = fsm->path;
1600 fsm->path = fsmFsPath(fsm, st, NULL, NULL);
1601 rc = fsmStage(fsm, FSM_VERIFY);
1603 if (rc == 0 && fsm->osuffix) {
1604 const char * opath = fsm->opath;
1605 fsm->opath = fsm->path;
1606 fsm->path = fsmFsPath(fsm, st, NULL, fsm->osuffix);
1607 rc = fsmStage(fsm, FSM_RENAME);
1609 rpmMessage(RPMMESS_WARNING,
1610 _("%s saved as %s\n"), fsm->opath, fsm->path);
1611 fsm->path = _free(fsm->path);
1615 /*@-dependenttrans@*/
1617 /*@=dependenttrans@*/
1618 if (rc != CPIOERR_LSTAT_FAILED) return rc;
1619 rc = expandRegular(fsm);
1620 } else if (S_ISDIR(st->st_mode)) {
1621 mode_t st_mode = st->st_mode;
1622 rc = fsmStage(fsm, FSM_VERIFY);
1623 if (rc == CPIOERR_LSTAT_FAILED) {
1624 st->st_mode &= ~07777; /* XXX abuse st->st_mode */
1625 st->st_mode |= 00700;
1626 rc = fsmStage(fsm, FSM_MKDIR);
1627 st->st_mode = st_mode; /* XXX restore st->st_mode */
1629 } else if (S_ISLNK(st->st_mode)) {
1630 const char * opath = fsm->opath;
1632 if ((st->st_size + 1) > fsm->rdsize) {
1633 rc = CPIOERR_HDR_SIZE;
1637 fsm->wrlen = st->st_size;
1638 rc = fsmStage(fsm, FSM_DREAD);
1639 if (!rc && fsm->rdnb != fsm->wrlen)
1640 rc = CPIOERR_READ_FAILED;
1643 fsm->wrbuf[st->st_size] = '\0';
1644 /* XXX symlink(fsm->opath, fsm->path) */
1645 /*@-dependenttrans@*/
1646 fsm->opath = fsm->wrbuf;
1647 /*@=dependenttrans@*/
1648 rc = fsmStage(fsm, FSM_VERIFY);
1649 if (rc == CPIOERR_LSTAT_FAILED)
1650 rc = fsmStage(fsm, FSM_SYMLINK);
1651 fsm->opath = opath; /* XXX restore fsm->path */
1652 } else if (S_ISFIFO(st->st_mode)) {
1653 mode_t st_mode = st->st_mode;
1654 /* This mimics cpio S_ISSOCK() behavior but probably isnt' right */
1655 rc = fsmStage(fsm, FSM_VERIFY);
1656 if (rc == CPIOERR_LSTAT_FAILED) {
1657 st->st_mode = 0000; /* XXX abuse st->st_mode */
1658 rc = fsmStage(fsm, FSM_MKFIFO);
1659 st->st_mode = st_mode; /* XXX restore st->st_mode */
1661 } else if (S_ISCHR(st->st_mode) ||
1662 S_ISBLK(st->st_mode) ||
1663 /*@-unrecog@*/ S_ISSOCK(st->st_mode) /*@=unrecog@*/)
1665 rc = fsmStage(fsm, FSM_VERIFY);
1666 if (rc == CPIOERR_LSTAT_FAILED)
1667 rc = fsmStage(fsm, FSM_MKNOD);
1669 /* XXX Special case /dev/log, which shouldn't be packaged anyways */
1670 if (!IS_DEV_LOG(fsm->path))
1671 rc = CPIOERR_UNKNOWN_FILETYPE;
1673 if (!S_ISDIR(st->st_mode) && st->st_nlink > 1) {
1674 fsm->li->createdPath = fsm->li->linkIndex;
1675 rc = fsmMakeLinks(fsm);
1681 rc = fsmMakeLinks(fsm);
1683 case FSM_NOTIFY: /* XXX move from fsm to psm -> tsm */
1684 if (fsm->goal == FSM_PKGINSTALL || fsm->goal == FSM_PKGBUILD) {
1685 rpmTransactionSet ts = fsmGetTs(fsm);
1686 TFI_t fi = fsmGetFi(fsm);
1687 if (ts && ts->notify && fi) {
1688 /*@-type@*/ /* FIX: cast? */
1689 /*@-noeffectuncon @*/ /* FIX: check rc */
1690 (void)ts->notify(fi->h, RPMCALLBACK_INST_PROGRESS,
1691 fdGetCpioPos(fsm->cfd), fi->archiveSize,
1692 rpmfiGetKey(fi), ts->notifyData);
1693 /*@=noeffectuncon @*/
1701 if (fsm->goal == FSM_PKGINSTALL) {
1702 (void) fsmStage(fsm,
1703 (S_ISDIR(st->st_mode) ? FSM_RMDIR : FSM_UNLINK));
1705 #ifdef NOTYET /* XXX remove only dirs just created, not all. */
1707 (void) fsmStage(fsm, FSM_RMDIRS);
1713 if (fsm->failedFile && *fsm->failedFile == NULL)
1714 *fsm->failedFile = xstrdup(fsm->path);
1717 if (!fsm->postpone && fsm->commit) {
1718 if (fsm->goal == FSM_PKGINSTALL)
1719 rc = ((!S_ISDIR(st->st_mode) && st->st_nlink > 1)
1720 ? fsmCommitLinks(fsm) : fsmStage(fsm, FSM_COMMIT));
1721 if (fsm->goal == FSM_PKGCOMMIT)
1722 rc = fsmStage(fsm, FSM_COMMIT);
1723 if (fsm->goal == FSM_PKGERASE)
1724 rc = fsmStage(fsm, FSM_COMMIT);
1726 fsm->path = _free(fsm->path);
1727 fsm->opath = _free(fsm->opath);
1728 memset(st, 0, sizeof(*st));
1729 memset(ost, 0, sizeof(*ost));
1732 /* Rename pre-existing modified or unmanaged file. */
1733 if (fsm->osuffix && fsm->diskchecked &&
1734 (fsm->exists || (fsm->goal == FSM_PKGINSTALL && S_ISREG(st->st_mode))))
1736 const char * opath = fsm->opath;
1737 const char * path = fsm->path;
1738 fsm->opath = fsmFsPath(fsm, st, NULL, NULL);
1739 fsm->path = fsmFsPath(fsm, st, NULL, fsm->osuffix);
1740 rc = fsmStage(fsm, FSM_RENAME);
1742 rpmMessage(RPMMESS_WARNING, _("%s saved as %s\n"),
1743 fsm->opath, fsm->path);
1745 fsm->path = _free(fsm->path);
1747 fsm->opath = _free(fsm->opath);
1751 /* Remove erased files. */
1752 if (fsm->goal == FSM_PKGERASE) {
1753 if (fsm->action == FA_ERASE) {
1754 TFI_t fi = fsmGetFi(fsm);
1755 if (S_ISDIR(st->st_mode)) {
1756 rc = fsmStage(fsm, FSM_RMDIR);
1759 case ENOENT: /* XXX rmdir("/") linux 2.2.x kernel hack */
1761 /* XXX make sure that build side permits %missingok on directories. */
1762 if (fsm->fflags & RPMFILE_MISSINGOK)
1763 /*@innerbreak@*/ break;
1765 /* XXX common error message. */
1767 (strict_erasures ? RPMERR_RMDIR : RPMDEBUG_RMDIR),
1768 _("%s rmdir of %s failed: Directory not empty\n"),
1769 fiTypeString(fi), fsm->path);
1770 /*@innerbreak@*/ break;
1773 (strict_erasures ? RPMERR_RMDIR : RPMDEBUG_RMDIR),
1774 _("%s rmdir of %s failed: %s\n"),
1775 fiTypeString(fi), fsm->path, strerror(errno));
1776 /*@innerbreak@*/ break;
1779 rc = fsmStage(fsm, FSM_UNLINK);
1781 if (!(errno == ENOENT && (fsm->fflags & RPMFILE_MISSINGOK)))
1783 (strict_erasures ? RPMERR_UNLINK : RPMDEBUG_UNLINK),
1784 _("%s unlink of %s failed: %s\n"),
1785 fiTypeString(fi), fsm->path, strerror(errno));
1788 /* XXX Failure to remove is not (yet) cause for failure. */
1789 if (!strict_erasures) rc = 0;
1793 /* XXX Special case /dev/log, which shouldn't be packaged anyways */
1794 if (!S_ISSOCK(st->st_mode) && !IS_DEV_LOG(fsm->path)) {
1795 /* Rename temporary to final file name. */
1796 if (!S_ISDIR(st->st_mode) &&
1797 (fsm->subdir || fsm->suffix || fsm->nsuffix))
1799 fsm->opath = fsm->path;
1800 fsm->path = fsmFsPath(fsm, st, NULL, fsm->nsuffix);
1801 rc = fsmStage(fsm, FSM_RENAME);
1802 if (!rc && fsm->nsuffix) {
1803 const char * opath = fsmFsPath(fsm, st, NULL, NULL);
1804 rpmMessage(RPMMESS_WARNING, _("%s created as %s\n"),
1805 (opath ? opath : ""), fsm->path);
1806 opath = _free(opath);
1808 fsm->opath = _free(fsm->opath);
1810 if (S_ISLNK(st->st_mode)) {
1811 if (!rc && !getuid())
1812 rc = fsmStage(fsm, FSM_LCHOWN);
1814 if (!rc && !getuid())
1815 rc = fsmStage(fsm, FSM_CHOWN);
1817 rc = fsmStage(fsm, FSM_CHMOD);
1819 time_t mtime = st->st_mtime;
1820 TFI_t fi = fsmGetFi(fsm);
1822 st->st_mtime = fi->fmtimes[fsm->ix];
1823 rc = fsmStage(fsm, FSM_UTIME);
1824 st->st_mtime = mtime;
1829 /* Notify on success. */
1830 if (!rc) rc = fsmStage(fsm, FSM_NOTIFY);
1831 else if (fsm->failedFile && *fsm->failedFile == NULL) {
1832 *fsm->failedFile = fsm->path;
1837 fsm->path = _free(fsm->path);
1839 /* Check for hard links missing from payload. */
1840 while ((fsm->li = fsm->links) != NULL) {
1841 fsm->links = fsm->li->next;
1842 fsm->li->next = NULL;
1843 if (fsm->goal == FSM_PKGINSTALL &&
1844 fsm->commit && fsm->li->linksLeft)
1846 for (i = 0 ; i < fsm->li->linksLeft; i++) {
1847 if (fsm->li->filex[i] < 0)
1848 /*@innercontinue@*/ continue;
1849 rc = CPIOERR_MISSING_HARDLINK;
1850 if (fsm->failedFile && *fsm->failedFile == NULL) {
1851 fsm->ix = fsm->li->filex[i];
1852 if (!fsmStage(fsm, FSM_MAP)) {
1853 *fsm->failedFile = fsm->path;
1857 /*@loopbreak@*/ break;
1860 if (fsm->goal == FSM_PKGBUILD &&
1861 (fsm->mapFlags & CPIO_ALL_HARDLINKS))
1863 rc = CPIOERR_MISSING_HARDLINK;
1865 fsm->li = freeHardLink(fsm->li);
1867 fsm->ldn = _free(fsm->ldn);
1868 fsm->ldnalloc = fsm->ldnlen = 0;
1869 fsm->rdbuf = fsm->rdb = _free(fsm->rdb);
1870 fsm->wrbuf = fsm->wrb = _free(fsm->wrb);
1873 if (fsm->diskchecked && !fsm->exists) {
1874 rc = CPIOERR_LSTAT_FAILED;
1877 if (S_ISREG(st->st_mode)) {
1878 char * path = alloca(strlen(fsm->path) + sizeof("-RPMDELETE"));
1879 (void) stpcpy( stpcpy(path, fsm->path), "-RPMDELETE");
1881 * XXX HP-UX (and other os'es) don't permit unlink on busy
1884 fsm->opath = fsm->path;
1886 rc = fsmStage(fsm, FSM_RENAME);
1888 (void) fsmStage(fsm, FSM_UNLINK);
1890 rc = CPIOERR_UNLINK_FAILED;
1891 fsm->path = fsm->opath;
1893 return (rc ? rc : CPIOERR_LSTAT_FAILED); /* XXX HACK */
1894 /*@notreached@*/ break;
1895 } else if (S_ISDIR(st->st_mode)) {
1896 if (S_ISDIR(ost->st_mode)) return 0;
1897 if (S_ISLNK(ost->st_mode)) {
1898 rc = fsmStage(fsm, FSM_STAT);
1899 if (rc == CPIOERR_STAT_FAILED && errno == ENOENT) rc = 0;
1904 if (S_ISDIR(ost->st_mode)) return 0;
1906 } else if (S_ISLNK(st->st_mode)) {
1907 if (S_ISLNK(ost->st_mode)) {
1908 /* XXX NUL terminated result in fsm->rdbuf, len in fsm->rdnb. */
1909 rc = fsmStage(fsm, FSM_READLINK);
1914 if (!strcmp(fsm->opath, fsm->rdbuf)) return 0;
1916 } else if (S_ISFIFO(st->st_mode)) {
1917 if (S_ISFIFO(ost->st_mode)) return 0;
1918 } else if (S_ISCHR(st->st_mode) || S_ISBLK(st->st_mode)) {
1919 if ((S_ISCHR(ost->st_mode) || S_ISBLK(ost->st_mode)) &&
1920 (ost->st_rdev == st->st_rdev)) return 0;
1921 } else if (S_ISSOCK(st->st_mode)) {
1922 if (S_ISSOCK(ost->st_mode)) return 0;
1924 /* XXX shouldn't do this with commit/undo. */
1926 if (fsm->stage == FSM_PROCESS) rc = fsmStage(fsm, FSM_UNLINK);
1927 if (rc == 0) rc = CPIOERR_LSTAT_FAILED;
1928 return (rc ? rc : CPIOERR_LSTAT_FAILED); /* XXX HACK */
1929 /*@notreached@*/ break;
1932 rc = Unlink(fsm->path);
1933 if (_fsm_debug && (stage & FSM_SYSCALL))
1934 rpmMessage(RPMMESS_DEBUG, " %8s (%s) %s\n", cur,
1935 fsm->path, (rc < 0 ? strerror(errno) : ""));
1936 if (rc < 0) rc = CPIOERR_UNLINK_FAILED;
1939 rc = Rename(fsm->opath, fsm->path);
1940 if (_fsm_debug && (stage & FSM_SYSCALL))
1941 rpmMessage(RPMMESS_DEBUG, " %8s (%s, %s) %s\n", cur,
1942 fsm->opath, fsm->path, (rc < 0 ? strerror(errno) : ""));
1943 if (rc < 0) rc = CPIOERR_RENAME_FAILED;
1946 rc = Mkdir(fsm->path, (st->st_mode & 07777));
1947 if (_fsm_debug && (stage & FSM_SYSCALL))
1948 rpmMessage(RPMMESS_DEBUG, " %8s (%s, 0%04o) %s\n", cur,
1949 fsm->path, (unsigned)(st->st_mode & 07777),
1950 (rc < 0 ? strerror(errno) : ""));
1951 if (rc < 0) rc = CPIOERR_MKDIR_FAILED;
1954 rc = Rmdir(fsm->path);
1955 if (_fsm_debug && (stage & FSM_SYSCALL))
1956 rpmMessage(RPMMESS_DEBUG, " %8s (%s) %s\n", cur,
1957 fsm->path, (rc < 0 ? strerror(errno) : ""));
1958 if (rc < 0) rc = CPIOERR_RMDIR_FAILED;
1961 rc = chown(fsm->path, st->st_uid, st->st_gid);
1962 if (_fsm_debug && (stage & FSM_SYSCALL))
1963 rpmMessage(RPMMESS_DEBUG, " %8s (%s, %d, %d) %s\n", cur,
1964 fsm->path, (int)st->st_uid, (int)st->st_gid,
1965 (rc < 0 ? strerror(errno) : ""));
1966 if (rc < 0) rc = CPIOERR_CHOWN_FAILED;
1969 #if ! CHOWN_FOLLOWS_SYMLINK
1970 rc = lchown(fsm->path, st->st_uid, st->st_gid);
1971 if (_fsm_debug && (stage & FSM_SYSCALL))
1972 rpmMessage(RPMMESS_DEBUG, " %8s (%s, %d, %d) %s\n", cur,
1973 fsm->path, (int)st->st_uid, (int)st->st_gid,
1974 (rc < 0 ? strerror(errno) : ""));
1975 if (rc < 0) rc = CPIOERR_CHOWN_FAILED;
1979 rc = chmod(fsm->path, (st->st_mode & 07777));
1980 if (_fsm_debug && (stage & FSM_SYSCALL))
1981 rpmMessage(RPMMESS_DEBUG, " %8s (%s, 0%04o) %s\n", cur,
1982 fsm->path, (unsigned)(st->st_mode & 07777),
1983 (rc < 0 ? strerror(errno) : ""));
1984 if (rc < 0) rc = CPIOERR_CHMOD_FAILED;
1987 { struct utimbuf stamp;
1988 stamp.actime = st->st_mtime;
1989 stamp.modtime = st->st_mtime;
1990 rc = utime(fsm->path, &stamp);
1991 if (_fsm_debug && (stage & FSM_SYSCALL))
1992 rpmMessage(RPMMESS_DEBUG, " %8s (%s, 0x%x) %s\n", cur,
1993 fsm->path, (unsigned)st->st_mtime,
1994 (rc < 0 ? strerror(errno) : ""));
1995 if (rc < 0) rc = CPIOERR_UTIME_FAILED;
1999 rc = symlink(fsm->opath, fsm->path);
2000 if (_fsm_debug && (stage & FSM_SYSCALL))
2001 rpmMessage(RPMMESS_DEBUG, " %8s (%s, %s) %s\n", cur,
2002 fsm->opath, fsm->path, (rc < 0 ? strerror(errno) : ""));
2003 if (rc < 0) rc = CPIOERR_SYMLINK_FAILED;
2006 rc = Link(fsm->opath, fsm->path);
2007 if (_fsm_debug && (stage & FSM_SYSCALL))
2008 rpmMessage(RPMMESS_DEBUG, " %8s (%s, %s) %s\n", cur,
2009 fsm->opath, fsm->path, (rc < 0 ? strerror(errno) : ""));
2010 if (rc < 0) rc = CPIOERR_LINK_FAILED;
2013 rc = mkfifo(fsm->path, (st->st_mode & 07777));
2014 if (_fsm_debug && (stage & FSM_SYSCALL))
2015 rpmMessage(RPMMESS_DEBUG, " %8s (%s, 0%04o) %s\n", cur,
2016 fsm->path, (unsigned)(st->st_mode & 07777),
2017 (rc < 0 ? strerror(errno) : ""));
2018 if (rc < 0) rc = CPIOERR_MKFIFO_FAILED;
2021 /*@-unrecog -portability @*/ /* FIX: check S_IFIFO or dev != 0 */
2022 rc = mknod(fsm->path, (st->st_mode & ~07777), st->st_rdev);
2023 /*@=unrecog =portability @*/
2024 if (_fsm_debug && (stage & FSM_SYSCALL))
2025 rpmMessage(RPMMESS_DEBUG, " %8s (%s, 0%o, 0x%x) %s\n", cur,
2026 fsm->path, (unsigned)(st->st_mode & ~07777),
2027 (unsigned)st->st_rdev,
2028 (rc < 0 ? strerror(errno) : ""));
2029 if (rc < 0) rc = CPIOERR_MKNOD_FAILED;
2032 rc = Lstat(fsm->path, ost);
2033 if (_fsm_debug && (stage & FSM_SYSCALL) && rc && errno != ENOENT)
2034 rpmMessage(RPMMESS_DEBUG, " %8s (%s, ost) %s\n", cur,
2035 fsm->path, (rc < 0 ? strerror(errno) : ""));
2036 if (rc < 0) rc = CPIOERR_LSTAT_FAILED;
2039 rc = Stat(fsm->path, ost);
2040 if (_fsm_debug && (stage & FSM_SYSCALL) && rc && errno != ENOENT)
2041 rpmMessage(RPMMESS_DEBUG, " %8s (%s, ost) %s\n", cur,
2042 fsm->path, (rc < 0 ? strerror(errno) : ""));
2043 if (rc < 0) rc = CPIOERR_STAT_FAILED;
2046 /* XXX NUL terminated result in fsm->rdbuf, len in fsm->rdnb. */
2047 rc = Readlink(fsm->path, fsm->rdbuf, fsm->rdsize - 1);
2048 if (_fsm_debug && (stage & FSM_SYSCALL))
2049 rpmMessage(RPMMESS_DEBUG, " %8s (%s, rdbuf, %d) %s\n", cur,
2050 fsm->path, (int)(fsm->rdsize -1), (rc < 0 ? strerror(errno) : ""));
2051 if (rc < 0) rc = CPIOERR_READLINK_FAILED;
2054 fsm->rdbuf[fsm->rdnb] = '\0';
2062 rc = fsmStage(fsm, FSM_HREAD);
2064 if (!strcmp(fsm->path, CPIO_TRAILER)) { /* Detect end-of-payload. */
2065 fsm->path = _free(fsm->path);
2066 rc = CPIOERR_HDR_TRAILER;
2069 rc = fsmStage(fsm, FSM_POS);
2072 for (left = st->st_size; left > 0; left -= fsm->rdnb) {
2073 fsm->wrlen = (left > fsm->wrsize ? fsm->wrsize : left);
2074 rc = fsmStage(fsm, FSM_DREAD);
2076 /*@loopbreak@*/ break;
2080 left = (modulo - (fdGetCpioPos(fsm->cfd) % modulo)) % modulo;
2083 (void) fsmStage(fsm, FSM_DREAD);
2087 left = (modulo - (fdGetCpioPos(fsm->cfd) % modulo)) % modulo;
2089 memset(fsm->rdbuf, 0, left);
2090 /* XXX DWRITE uses rdnb for I/O length. */
2092 (void) fsmStage(fsm, FSM_DWRITE);
2096 rc = cpioTrailerWrite(fsm);
2099 rc = fsmStage(fsm, FSM_POS);
2101 rc = cpioHeaderRead(fsm, st); /* Read next payload header. */
2104 rc = cpioHeaderWrite(fsm, st); /* Write next payload header. */
2107 fsm->rdnb = Fread(fsm->wrbuf, sizeof(*fsm->wrbuf), fsm->wrlen, fsm->cfd);
2108 if (_fsm_debug && (stage & FSM_SYSCALL))
2109 rpmMessage(RPMMESS_DEBUG, " %8s (%s, %d, cfd)\trdnb %d\n",
2110 cur, (fsm->wrbuf == fsm->wrb ? "wrbuf" : "mmap"),
2111 (int)fsm->wrlen, (int)fsm->rdnb);
2112 if (fsm->rdnb != fsm->wrlen || Ferror(fsm->cfd))
2113 rc = CPIOERR_READ_FAILED;
2115 fdSetCpioPos(fsm->cfd, fdGetCpioPos(fsm->cfd) + fsm->rdnb);
2118 fsm->wrnb = Fwrite(fsm->rdbuf, sizeof(*fsm->rdbuf), fsm->rdnb, fsm->cfd);
2119 if (_fsm_debug && (stage & FSM_SYSCALL))
2120 rpmMessage(RPMMESS_DEBUG, " %8s (%s, %d, cfd)\twrnb %d\n",
2121 cur, (fsm->rdbuf == fsm->rdb ? "rdbuf" : "mmap"),
2122 (int)fsm->rdnb, (int)fsm->wrnb);
2123 if (fsm->rdnb != fsm->wrnb || Ferror(fsm->cfd))
2124 rc = CPIOERR_WRITE_FAILED;
2126 fdSetCpioPos(fsm->cfd, fdGetCpioPos(fsm->cfd) + fsm->wrnb);
2130 fsm->rfd = Fopen(fsm->path, "r.ufdio");
2131 if (fsm->rfd == NULL || Ferror(fsm->rfd)) {
2132 if (fsm->rfd) (void) fsmStage(fsm, FSM_RCLOSE);
2134 rc = CPIOERR_OPEN_FAILED;
2137 if (_fsm_debug && (stage & FSM_SYSCALL))
2138 rpmMessage(RPMMESS_DEBUG, " %8s (%s, \"r\") rfd %p rdbuf %p\n", cur,
2139 fsm->path, fsm->rfd, fsm->rdbuf);
2142 fsm->rdnb = Fread(fsm->rdbuf, sizeof(*fsm->rdbuf), fsm->rdlen, fsm->rfd);
2143 if (_fsm_debug && (stage & FSM_SYSCALL))
2144 rpmMessage(RPMMESS_DEBUG, " %8s (rdbuf, %d, rfd)\trdnb %d\n",
2145 cur, (int)fsm->rdlen, (int)fsm->rdnb);
2146 if (fsm->rdnb != fsm->rdlen || Ferror(fsm->rfd))
2147 rc = CPIOERR_READ_FAILED;
2151 if (_fsm_debug && (stage & FSM_SYSCALL))
2152 rpmMessage(RPMMESS_DEBUG, " %8s (%p)\n", cur, fsm->rfd);
2153 (void) Fclose(fsm->rfd);
2161 fsm->wfd = Fopen(fsm->path, "w.ufdio");
2162 if (fsm->wfd == NULL || Ferror(fsm->wfd)) {
2163 if (fsm->wfd) (void) fsmStage(fsm, FSM_WCLOSE);
2165 rc = CPIOERR_OPEN_FAILED;
2167 if (_fsm_debug && (stage & FSM_SYSCALL))
2168 rpmMessage(RPMMESS_DEBUG, " %8s (%s, \"w\") wfd %p wrbuf %p\n", cur,
2169 fsm->path, fsm->wfd, fsm->wrbuf);
2172 fsm->wrnb = Fwrite(fsm->wrbuf, sizeof(*fsm->wrbuf), fsm->rdnb, fsm->wfd);
2173 if (_fsm_debug && (stage & FSM_SYSCALL))
2174 rpmMessage(RPMMESS_DEBUG, " %8s (wrbuf, %d, wfd)\twrnb %d\n",
2175 cur, (int)fsm->rdnb, (int)fsm->wrnb);
2176 if (fsm->rdnb != fsm->wrnb || Ferror(fsm->wfd))
2177 rc = CPIOERR_WRITE_FAILED;
2181 if (_fsm_debug && (stage & FSM_SYSCALL))
2182 rpmMessage(RPMMESS_DEBUG, " %8s (%p)\n", cur, fsm->wfd);
2183 (void) Fclose(fsm->wfd);
2196 if (!(stage & FSM_INTERNAL)) {
2197 fsm->rc = (rc == CPIOERR_HDR_TRAILER ? 0 : rc);
2203 /*@obserever@*/ const char *const fileActionString(fileAction a)
2206 case FA_UNKNOWN: return "unknown";
2207 case FA_CREATE: return "create";
2208 case FA_COPYOUT: return "copyout";
2209 case FA_COPYIN: return "copyin";
2210 case FA_BACKUP: return "backup";
2211 case FA_SAVE: return "save";
2212 case FA_SKIP: return "skip";
2213 case FA_ALTNAME: return "altname";
2214 case FA_ERASE: return "erase";
2215 case FA_SKIPNSTATE: return "skipnstate";
2216 case FA_SKIPNETSHARED: return "skipnetshared";
2217 case FA_SKIPMULTILIB: return "skipmultilib";
2218 default: return "???";
2223 /*@observer@*/ const char *const fileStageString(fileStage a) {
2225 case FSM_UNKNOWN: return "unknown";
2227 case FSM_PKGINSTALL:return "INSTALL";
2228 case FSM_PKGERASE: return "ERASE";
2229 case FSM_PKGBUILD: return "BUILD";
2230 case FSM_PKGCOMMIT: return "COMMIT";
2231 case FSM_PKGUNDO: return "UNDO";
2233 case FSM_CREATE: return "create";
2234 case FSM_INIT: return "init";
2235 case FSM_MAP: return "map";
2236 case FSM_MKDIRS: return "mkdirs";
2237 case FSM_RMDIRS: return "rmdirs";
2238 case FSM_PRE: return "pre";
2239 case FSM_PROCESS: return "process";
2240 case FSM_POST: return "post";
2241 case FSM_MKLINKS: return "mklinks";
2242 case FSM_NOTIFY: return "notify";
2243 case FSM_UNDO: return "undo";
2244 case FSM_FINI: return "fini";
2245 case FSM_COMMIT: return "commit";
2246 case FSM_DESTROY: return "destroy";
2247 case FSM_VERIFY: return "verify";
2249 case FSM_UNLINK: return "Unlink";
2250 case FSM_RENAME: return "Rename";
2251 case FSM_MKDIR: return "Mkdir";
2252 case FSM_RMDIR: return "rmdir";
2253 case FSM_CHOWN: return "chown";
2254 case FSM_LCHOWN: return "lchown";
2255 case FSM_CHMOD: return "chmod";
2256 case FSM_UTIME: return "utime";
2257 case FSM_SYMLINK: return "symlink";
2258 case FSM_LINK: return "Link";
2259 case FSM_MKFIFO: return "mkfifo";
2260 case FSM_MKNOD: return "mknod";
2261 case FSM_LSTAT: return "Lstat";
2262 case FSM_STAT: return "Stat";
2263 case FSM_READLINK: return "Readlink";
2264 case FSM_CHROOT: return "chroot";
2266 case FSM_NEXT: return "next";
2267 case FSM_EAT: return "eat";
2268 case FSM_POS: return "pos";
2269 case FSM_PAD: return "pad";
2270 case FSM_TRAILER: return "trailer";
2271 case FSM_HREAD: return "hread";
2272 case FSM_HWRITE: return "hwrite";
2273 case FSM_DREAD: return "Fread";
2274 case FSM_DWRITE: return "Fwrite";
2276 case FSM_ROPEN: return "Fopen";
2277 case FSM_READ: return "Fread";
2278 case FSM_RCLOSE: return "Fclose";
2279 case FSM_WOPEN: return "Fopen";
2280 case FSM_WRITE: return "Fwrite";
2281 case FSM_WCLOSE: return "Fclose";
2283 default: return "???";