home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume13 / derez3 / part01 next >
Encoding:
Internet Message Format  |  1988-01-30  |  32.0 KB

  1. Subject:  v13i040:  Derez, remove stale files from system, Part01/02
  2. Newsgroups: comp.sources.unix
  3. Sender: sources
  4. Approved: rsalz@uunet.UU.NET
  5.  
  6. Submitted-by: A. Nonymous
  7. Posting-number: Volume 13, Issue 40
  8. Archive-name: derez3/part01
  9.  
  10. [  This is kind of a fun program, in a sick sort of way.  Consider it a
  11.    tool in the war between system administrators who believe disks should
  12.    be kept empty, and system users, who believe they should be kept full.
  13.    Sorry, but no summary can do the vilification in the documentation
  14.    true justice; you will have to read the manpage and README yourself.
  15.    --r$  ]
  16.  
  17. This is version 3.0 of Derez, the stale file archiver.
  18.  
  19. This version is an upgraded version of the earlier
  20. usenet posting, from the very same anonymous source.
  21. Several tools to spot anti-social uses have been added,
  22. and the context diff to create a custom version of
  23. 4.2 BSD "tar", called rerez, that remembers access dates
  24. in the tape archive has been added.  This version,
  25. as was the earlier version, is in the public domain
  26. and the author will deny being the author of this program.
  27.  
  28. This is part 1 of two parts.
  29.  
  30. : Run this shell script with "sh" not "csh"
  31. PATH=:/bin:/usr/bin:/usr/ucb
  32. export PATH
  33. all=FALSE
  34. if [ x$1 = x-a ]; then
  35.     all=TRUE
  36. fi
  37. /bin/echo 'Extracting README'
  38. sed 's/^X//' <<'//go.sysin dd *' >README
  39. This code is explicitly placed in the public domain by the author and may be
  40. used for fun or profit (the author really enjoys running it).  It is not
  41. copyrighted and contains no references to the author's true name.  This is
  42. by design as the author does not what to become "known" as the author of Derez.
  43.  
  44. This is version 3.0.  It contains several useful options for derez, a special
  45. version of tar (rerez) to allow archives to restore time last accessed and some
  46. useful tooling to help spot antisocial users.  Derez always wins in the
  47. derez/rerez wars.  What! You think files should remain on disk forever????
  48.  
  49. XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  50.  
  51. Caution! Rerez.c is a munged version of 4.2BSD tar and therefore can't
  52. be transmitted to sites without a suitable license.  Any public distributions
  53. of rerez.c should only contain the differences in "patch" format from 4.2BSD
  54. tar to protect AT&T's or UCB's interests.  This distribution contains a file
  55. rerez.c.diff which a context diff to create rerez.c from 4.2BSD tar using
  56. "patch".  Get patch from the USENET archive, or make the changes by hand.
  57. Rerez is simply a version of tar which remembers and restores time last
  58. accessed dates.  If you can't manage to create rerez.c from 4.2BSD tar
  59. send a note to maddog.uucp!root or root@lll-maddog.arpa and we will try
  60. to help you out.
  61.  
  62. The remote tape library patches appearing in rerez are the public
  63. domain rmtlib patches published in the USENET mod.sources.  These
  64. are needed only to access a remote drive.
  65.  
  66. XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  67.  
  68. This version of Derez has a Makefile that conforms to the /usr/local
  69. standard for locally developed software (local rules for MadDog).  All binaries
  70. are installed in the /usr/local/{bin,etc,lib,...} directory tree, with the
  71. exception of the man pages due to reservations in munging man (we recently
  72. munged it).  Each installed item can have its owner and group set though the
  73. OWNER and GROUP parameters on the make comand line.  It must be installed once
  74. by root, but there after the owner of the files can maintain them and install
  75. the new versions.
  76.  
  77. Anyone having problems with derez should send a mail request to
  78. maddog!root for possible help or suggestions, arpa sites can use
  79. root@lll-maddog.arpa.  Anyone who fixes some of derez's bugs or inadequacies
  80. is invited to send maddog!root a copy of the patches.  We can always use a
  81. better, but not necessarily less Draconian, derez on our system.
  82.  
  83. Derez does not contain a mechanism to warn users about the impending
  84. removal of stale files.  We have found that doing this only invites the
  85. users to go and defeat the effects of derez totally without archiving
  86. their stale files to tape and removing them from disk.  On systems with
  87. cooperative users, perhaps a separate program that sends users mail about
  88. their stale files, listing their path names might be helpful.
  89.  
  90.  
  91. DIRECTIONS TO SYSTEM ADMINISTRATORS FOR INSTALLATION:
  92. Derez, Readbyte, Rerez, and Agehist have man pages which describe their use
  93. and abuse.  These man pages contain local system rules on MadDog
  94. and you will probably have your own you want to use.  If so, modify
  95. the man pages to reflect these rules.
  96.  
  97. The default definition for staleness is compiled into derez.  You
  98. may want to change this.  In any event the -t option can set the
  99. stale date to anything you want.
  100.  
  101. 1)  Modify the man pages, derez.c and the Makefile to reflect
  102. system rules, default stale interval and installation targets
  103. for your system.
  104.  
  105. 2)  Type "make install" to compile and install all programs and
  106. manual pages.
  107.  
  108. 3) If you take out the #define of RIPEM in derez.c, derez
  109. will create the appropriate directory tree in MORGUE, including
  110. hard links to the target files, but will not rip off the
  111. originals.  You can use this to first check that derez properly
  112. preserves all modes and ownerships before enabling the RIPEM code.
  113. A debug run of derez with the RIPEM code out is highly suggested
  114. to make sure that some system dependency in the code does not bite
  115. you.  Your users expect and deserve absolute reliability when it comes
  116. to archiving their files.
  117.  
  118.  
  119. DIRECTIONS TO SYSTEM ADMINISTRATORS FOR STANDARD USAGE:
  120.  
  121. 1) You must be root to derez another users files.
  122.  
  123. 2) Cd to the directory where the directories you want to run
  124. derez on reside.  Usually this would be the directory where the
  125. login directories of users reside but does not have to be.
  126.     example: cd /u0
  127.  
  128. 2) If the directory MORGUE does not exist, create it.
  129.     example: mkdir MORGUE
  130.  
  131. 3) Suppose you want to search the entire tree under /u0 for stale
  132. files not accessed in a year and move them to MORGUE.  Type the
  133. command:
  134.     derez -t 360
  135. If on the other hand you want to search only the subdirectories
  136. foo and bar and archive their stale files type the command:
  137.     derez -t 360 foo bar
  138. Foo and bar must reside in the current directory.
  139.  
  140. Derez will search the directories for stale files and create
  141. a list of them with the name MORGUE/DEREZ.  It will then
  142. create a link to each file in MORGUE, and if RIPEM is defined
  143. in derez remove the original link one at a time.  Doing this one
  144. files at a time limits the possibility of overrunning the disk.
  145. Using links makes it fast, and does not change the access dates
  146. of the stale files.
  147.  
  148. An entire directory tree of the stale files will eventually be
  149. built in MORGUE.  All of the directories created in MORGUE should
  150. match the originals with respect to ownership and permissions.
  151. Once the process is complete you can archive the directory
  152. tree in MORGUE onto tape using tar, or rerez, and remove the
  153. directory tree.
  154.     cd MORGUE
  155.     rerez c *
  156.     "remove the tape, remove the write ring, then check the
  157.     tape with rerez t to be sure its okay"
  158.     rm -rf *
  159.     "optionally remove the MORGUE directory"
  160.  
  161. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  162. !MAKE TWO COPIES OF THE TAR OR REREZ ARCHIVE, AND CHECK EACH FOR!
  163. !ABSOLUTE FLAWLESSNESS BEFORE BLOWING THOSE FILES AWAY          !
  164. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  165.  
  166. On a system that has never been derez'ed, there may be more than
  167. one tape full of files that are stale by the desired definition of
  168. staleness.  Derez can incrementally be used to build up stale files
  169. until a tar image of the the MORGUE subdirectory will just fill a tape.
  170. First run derez with say, a 3 year definitition of staleness, and
  171. them check the size of MORGUE using:
  172.     du -s MORGUE
  173. Repeat the derez operations with successively smaller intervals until
  174. du reports that a tar image of MORGUE will fill a tape.  When this
  175. happens archive the enmorgued files using tar or rerez and remove the
  176. files in MORGUE.  Repeat this operation until the desired staleness
  177. interval of say a year or less has been reached.
  178.  
  179.  
  180. Remember to create a listing of the files on each archive tape
  181. in a suitable system directory so users can locate any stale files
  182. they need later.  The location of these files and their naming
  183. convention must be duly recorded in the derez man page.
  184. When incrementally building the MORGE as above,
  185. MORGUE/DEREZ will only contain a list of the last set of files
  186. that were enmorgued with derez.  Use "tar t" or "rerez t" to get the
  187. complete archive list from the tape.
  188.  
  189. The rest of this message is the "sh archive format" of the
  190. derez source.
  191. XXXXXXXXXXXXXXXXXXXXX Cut here and feed to /bin/sh XXXXXXXXXXXXXXXXXXX
  192. //go.sysin dd *
  193. if [ `wc -c < README` != 7387 ]; then
  194.     made=FALSE
  195.     /bin/echo 'error transmitting "README" --'
  196.     /bin/echo 'length should be 7387, not' `wc -c < README`
  197. else
  198.     made=TRUE
  199. fi
  200. if [ $made = TRUE ]; then
  201.     /bin/chmod 644 README
  202.     /bin/echo -n '    '; /bin/ls -ld README
  203. fi
  204. /bin/echo 'Extracting Makefile'
  205. sed 's/^X//' <<'//go.sysin dd *' >Makefile
  206. CFLAGS = -O
  207. PROGSRC = derez.c readbyte.c agehist.c
  208. PROGS = derez readbyte agehist rerez
  209. MANS = derez.1 readbyte.1 agehist.1 rerez.1
  210. MANDIR=/usr/local/man
  211.  
  212. OWNER=root
  213. GROUP=daemon
  214.  
  215. all : $P $(PROGS)
  216.  
  217. install : all $(MANS)
  218.     install -c -o $(OWNER) -g $(GROUP) -m 755 derez /usr/local/bin
  219.     install -c -o $(OWNER) -g $(GROUP) -m 644 derez.1 $(MANDIR)/manl/derez.l
  220.     install -c -o $(OWNER) -g $(GROUP) -m 755 readbyte /usr/local/bin
  221.     install -c -o $(OWNER) -g $(GROUP) -m 644 readbyte.1 $(MANDIR)/manl/readbyte.l
  222.     install -c -o $(OWNER) -g $(GROUP) -m 755 agehist /usr/local/bin
  223.     install -c -o $(OWNER) -g $(GROUP) -m 644 agehist.1 $(MANDIR)/manl/agehist.l
  224.     install -c -o $(OWNER) -g $(GROUP) -m 755 rerez /usr/local/bin
  225.     install -c -o $(OWNER) -g $(GROUP) -m 644 rerez.1 $(MANDIR)/manl/rerez.l
  226.  
  227. clean :
  228.     rm -f *.o
  229.  
  230. clobber : clean
  231.     rm -f $(PROGS) scriptfile
  232.  
  233. derez : derez.c
  234.     cc -o derez derez.c
  235. lintderez :
  236.     lint derez.c
  237.  
  238. readbyte : readbyte.c
  239.     cc -o readbyte readbyte.c
  240.  
  241. agehist : agehist.c
  242.     cc -o agehist agehist.c
  243.  
  244. rerez.o : rmt.h
  245.     cc -c -O -I. rerez.c
  246. rerez : rerez.o rmtlib.o
  247.     cc -o rerez rerez.o rmtlib.o
  248.  
  249. scriptfile : README Makefile $(PROGSRC) rerez.c $(MANS)
  250.     touch scriptfile
  251.     rcsdiff -c -r1.1 rerez.c > rerez.c.diff
  252.     cp README scriptfile
  253.     makescript README Makefile $(PROGSRC) rerez.c.diff rmtlib.c rmt.h $(MANS) >> scriptfile
  254.     cp PART1 usenet1
  255.     makescript README Makefile rerez.c.diff rmtlib.c rmt.h >> usenet1
  256.     cp PART2 usenet2
  257.     makescript $(PROGSRC) $(MANS) >> usenet2
  258. //go.sysin dd *
  259. if [ `wc -c < Makefile` != 1478 ]; then
  260.     made=FALSE
  261.     /bin/echo 'error transmitting "Makefile" --'
  262.     /bin/echo 'length should be 1478, not' `wc -c < Makefile`
  263. else
  264.     made=TRUE
  265. fi
  266. if [ $made = TRUE ]; then
  267.     /bin/chmod 644 Makefile
  268.     /bin/echo -n '    '; /bin/ls -ld Makefile
  269. fi
  270. /bin/echo 'Extracting rerez.c.diff'
  271. sed 's/^X//' <<'//go.sysin dd *' >rerez.c.diff
  272. *** /tmp/,RCSt1012366    Sun Dec  6 11:25:29 1987
  273. --- rerez.c    Tue Jun  9 12:52:33 1987
  274. ***************
  275. *** 6,11
  276.    * Tape Archival Program
  277.    */
  278.   #include <stdio.h>
  279.   #include <sys/param.h>
  280.   #include <sys/stat.h>
  281.   #include <sys/dir.h>
  282.  
  283. --- 6,12 -----
  284.    * Tape Archival Program
  285.    */
  286.   #include <stdio.h>
  287. + #include <rmt.h>    /* remote tape, must come before <sys/stat.h> */
  288.   #include <sys/param.h>
  289.   #include <sys/stat.h>
  290.   #include <sys/dir.h>
  291. ***************
  292. *** 28,33
  293.           char gid[8];
  294.           char size[12];
  295.           char mtime[12];
  296.           char chksum[8];
  297.           char linkflag;
  298.           char linkname[NAMSIZ];
  299.  
  300. --- 29,35 -----
  301.           char gid[8];
  302.           char size[12];
  303.           char mtime[12];
  304. +         char atime[12];
  305.           char chksum[8];
  306.           char linkflag;
  307.           char linkname[NAMSIZ];
  308. ***************
  309. *** 82,88
  310.   FILE    *tfile;
  311.   char    tname[] = "/tmp/tarXXXXXX";
  312.   char    *usefile;
  313. ! char    magtape[] = "/dev/rmt8";
  314.   char    *malloc();
  315.   char    *sprintf();
  316.   char    *strcat();
  317.  
  318. --- 84,94 -----
  319.   FILE    *tfile;
  320.   char    tname[] = "/tmp/tarXXXXXX";
  321.   char    *usefile;
  322. ! #ifdef sun
  323. ! char    magtape[] = "/dev/rmt0";
  324. ! #else
  325. ! char    magtape[] = "/dev/rts0";
  326. ! #endif
  327.   char    *malloc();
  328.   char    *sprintf();
  329.   char    *strcat();
  330. ***************
  331. *** 161,166
  332.               break;
  333.   
  334.           case 'm':
  335.               mflag++;
  336.               break;
  337.   
  338.  
  339. --- 167,174 -----
  340.               break;
  341.   
  342.           case 'm':
  343. +             fprintf(stderr, "You must be joking!\n");
  344. +             exit(1);
  345.               mflag++;
  346.               break;
  347.   
  348. ***************
  349. *** 267,272
  350.           doxtract(argv);
  351.       else
  352.           dotable();
  353.       done(0);
  354.   }
  355.   
  356.  
  357. --- 275,281 -----
  358.           doxtract(argv);
  359.       else
  360.           dotable();
  361. +     close (mt);
  362.       done(0);
  363.   }
  364.   
  365. ***************
  366. *** 373,378
  367.       sp->st_gid = i;
  368.       sscanf(dblock.dbuf.size, "%lo", &sp->st_size);
  369.       sscanf(dblock.dbuf.mtime, "%lo", &sp->st_mtime);
  370.       sscanf(dblock.dbuf.chksum, "%o", &chksum);
  371.       if (chksum != (i = checksum())) {
  372.           fprintf(stderr, "tar: directory checksum error (%d != %d)\n",
  373.  
  374. --- 382,388 -----
  375.       sp->st_gid = i;
  376.       sscanf(dblock.dbuf.size, "%lo", &sp->st_size);
  377.       sscanf(dblock.dbuf.mtime, "%lo", &sp->st_mtime);
  378. +     sscanf(dblock.dbuf.atime, "%lo", &sp->st_atime);
  379.       sscanf(dblock.dbuf.chksum, "%o", &chksum);
  380.       if (chksum != (i = checksum())) {
  381.           fprintf(stderr, "tar: directory checksum error (%d != %d)\n",
  382. ***************
  383. *** 557,562
  384.                   }
  385.                   lp->count--;
  386.                   close(infile);
  387.                   return;
  388.               }
  389.               lp = (struct linkbuf *) malloc(sizeof(*lp));
  390.  
  391. --- 567,581 -----
  392.                   }
  393.                   lp->count--;
  394.                   close(infile);
  395. +                 {
  396. +                     struct timeval tv[2];
  397. +                     tv[0].tv_sec = stbuf.st_atime;
  398. +                     tv[0].tv_usec = 0;
  399. +                     tv[1].tv_sec = stbuf.st_mtime;
  400. +                     tv[1].tv_usec = 0;
  401. +                     utimes(shortname, tv);
  402. +                 }
  403.                   return;
  404.               }
  405.               lp = (struct linkbuf *) malloc(sizeof(*lp));
  406. ***************
  407. *** 588,593
  408.               blocks--;
  409.           }
  410.           close(infile);
  411.           if (blocks != 0 || i != 0)
  412.               fprintf(stderr, "tar: %s: file changed size\n",
  413.                   longname);
  414.  
  415. --- 607,621 -----
  416.               blocks--;
  417.           }
  418.           close(infile);
  419. +         {
  420. +             struct timeval tv[2];
  421. +             tv[0].tv_sec = stbuf.st_atime;
  422. +             tv[0].tv_usec = 0;
  423. +             tv[1].tv_sec = stbuf.st_mtime;
  424. +             tv[1].tv_usec = 0;
  425. +             utimes(shortname, tv);
  426. +         }
  427.           if (blocks != 0 || i != 0)
  428.               fprintf(stderr, "tar: %s: file changed size\n",
  429.                   longname);
  430. ***************
  431. *** 642,648
  432.           if (checkdir(dblock.dbuf.name))
  433.               continue;
  434.           if (dblock.dbuf.linkflag == '2') {
  435. !             unlink(dblock.dbuf.name);
  436.               if (symlink(dblock.dbuf.linkname, dblock.dbuf.name)<0) {
  437.                   fprintf(stderr, "tar: %s: symbolic link failed\n",
  438.                       dblock.dbuf.name);
  439.  
  440. --- 670,682 -----
  441.           if (checkdir(dblock.dbuf.name))
  442.               continue;
  443.           if (dblock.dbuf.linkflag == '2') {
  444. !             /*
  445. !              * only unlink non-directories or empty directories
  446. !              */
  447. !             if (rmdir (dblock.dbuf.name) < 0) {
  448. !                 if (errno == ENOTDIR)
  449. !                     unlink(dblock.dbuf.name);
  450. !             }
  451.               if (symlink(dblock.dbuf.linkname, dblock.dbuf.name)<0) {
  452.                   fprintf(stderr, "tar: %s: symbolic link failed\n",
  453.                       dblock.dbuf.name);
  454. ***************
  455. *** 657,663
  456.               if (mflag == 0) {
  457.                   struct timeval tv[2];
  458.   
  459. !                 tv[0].tv_sec = time(0);
  460.                   tv[0].tv_usec = 0;
  461.                   tv[1].tv_sec = stbuf.st_mtime;
  462.                   tv[1].tv_usec = 0;
  463.  
  464. --- 691,697 -----
  465.               if (mflag == 0) {
  466.                   struct timeval tv[2];
  467.   
  468. !                 tv[0].tv_sec = stbuf.st_mtime;
  469.                   tv[0].tv_usec = 0;
  470.                   tv[1].tv_sec = stbuf.st_mtime;
  471.                   tv[1].tv_usec = 0;
  472. ***************
  473. *** 669,675
  474.               continue;
  475.           }
  476.           if (dblock.dbuf.linkflag == '1') {
  477. !             unlink(dblock.dbuf.name);
  478.               if (link(dblock.dbuf.linkname, dblock.dbuf.name) < 0) {
  479.                   fprintf(stderr, "tar: %s: cannot link\n",
  480.                       dblock.dbuf.name);
  481.  
  482. --- 703,715 -----
  483.               continue;
  484.           }
  485.           if (dblock.dbuf.linkflag == '1') {
  486. !             /*
  487. !              * only unlink non-directories or empty directories
  488. !              */
  489. !             if (rmdir (dblock.dbuf.name) < 0) {
  490. !                 if (errno == ENOTDIR)
  491. !                     unlink(dblock.dbuf.name);
  492. !             }
  493.               if (link(dblock.dbuf.linkname, dblock.dbuf.name) < 0) {
  494.                   fprintf(stderr, "tar: %s: cannot link\n",
  495.                       dblock.dbuf.name);
  496. ***************
  497. *** 713,719
  498.           if (mflag == 0) {
  499.               struct timeval tv[2];
  500.   
  501. !             tv[0].tv_sec = time(0);
  502.               tv[0].tv_usec = 0;
  503.               tv[1].tv_sec = stbuf.st_mtime;
  504.               tv[1].tv_usec = 0;
  505.  
  506. --- 753,759 -----
  507.           if (mflag == 0) {
  508.               struct timeval tv[2];
  509.   
  510. !             tv[0].tv_sec = stbuf.st_atime;
  511.               tv[0].tv_usec = 0;
  512.               tv[1].tv_sec = stbuf.st_mtime;
  513.               tv[1].tv_usec = 0;
  514. ***************
  515. *** 761,766
  516.       printf("%7D", st->st_size);
  517.       cp = ctime(&st->st_mtime);
  518.       printf(" %-12.12s %-4.4s ", cp+4, cp+20);
  519.   }
  520.   
  521.   #define    SUID    04000
  522.  
  523. --- 801,808 -----
  524.       printf("%7D", st->st_size);
  525.       cp = ctime(&st->st_mtime);
  526.       printf(" %-12.12s %-4.4s ", cp+4, cp+20);
  527. +     cp = ctime(&st->st_atime);
  528. +     printf(" %-12.12s %-4.4s ", cp+4, cp+20);
  529.   }
  530.   
  531.   #define    SUID    04000
  532. ***************
  533. *** 884,889
  534.       sprintf(dblock.dbuf.gid, "%6o ", sp->st_gid);
  535.       sprintf(dblock.dbuf.size, "%11lo ", sp->st_size);
  536.       sprintf(dblock.dbuf.mtime, "%11lo ", sp->st_mtime);
  537.   }
  538.   
  539.   checksum()
  540.  
  541. --- 926,932 -----
  542.       sprintf(dblock.dbuf.gid, "%6o ", sp->st_gid);
  543.       sprintf(dblock.dbuf.size, "%11lo ", sp->st_size);
  544.       sprintf(dblock.dbuf.mtime, "%11lo ", sp->st_mtime);
  545. +     sprintf(dblock.dbuf.atime, "%11lo ", sp->st_atime);
  546.   }
  547.   
  548.   checksum()
  549. //go.sysin dd *
  550. if [ `wc -c < rerez.c.diff` != 6250 ]; then
  551.     made=FALSE
  552.     /bin/echo 'error transmitting "rerez.c.diff" --'
  553.     /bin/echo 'length should be 6250, not' `wc -c < rerez.c.diff`
  554. else
  555.     made=TRUE
  556. fi
  557. if [ $made = TRUE ]; then
  558.     /bin/chmod 644 rerez.c.diff
  559.     /bin/echo -n '    '; /bin/ls -ld rerez.c.diff
  560. fi
  561. /bin/echo 'Extracting rmtlib.c'
  562. sed 's/^X//' <<'//go.sysin dd *' >rmtlib.c
  563. X/*
  564.  *    rmt --- remote tape emulator subroutines
  565.  *
  566.  *    Originally written by Jeff Lee, modified some by Arnold Robbins
  567.  *
  568.  *    WARNING:  The man page rmt(8) for /etc/rmt documents the remote mag
  569.  *    tape protocol which rdump and rrestore use.  Unfortunately, the man
  570.  *    page is *WRONG*.  The author of the routines I'm including originally
  571.  *    wrote his code just based on the man page, and it didn't work, so he
  572.  *    went to the rdump source to figure out why.  The only thing he had to
  573.  *    change was to check for the 'F' return code in addition to the 'E',
  574.  *    and to separate the various arguments with \n instead of a space.  I
  575.  *    personally don't think that this is much of a problem, but I wanted to
  576.  *    point it out.
  577.  *    -- Arnold Robbins
  578.  *
  579.  *    Redone as a library that can replace open, read, write, etc, by
  580.  *    Fred Fish, with some additional work by Arnold Robbins.
  581.  */
  582.  
  583. X/*
  584.  *    MAXUNIT --- Maximum number of remote tape file units
  585.  *
  586.  *    READ --- Return the number of the read side file descriptor
  587.  *    WRITE --- Return the number of the write side file descriptor
  588.  */
  589.  
  590. #define RMTIOCTL    1
  591.  
  592. #include <stdio.h>
  593. #include <signal.h>
  594. #include <sys/types.h>
  595.  
  596. #ifdef RMTIOCTL
  597. #include <sys/ioctl.h>
  598. #include <sys/mtio.h>
  599. #endif
  600.  
  601. #include <errno.h>
  602. #include <setjmp.h>
  603. #include <sys/stat.h>
  604.  
  605. #define BUFMAGIC    64    /* a magic number for buffer sizes */
  606. #define MAXUNIT    4
  607.  
  608. #define READ(fd)    (Ctp[fd][0])
  609. #define WRITE(fd)    (Ptc[fd][1])
  610.  
  611. static int Ctp[MAXUNIT][2] = { -1, -1, -1, -1, -1, -1, -1, -1 };
  612. static int Ptc[MAXUNIT][2] = { -1, -1, -1, -1, -1, -1, -1, -1 };
  613.  
  614. static jmp_buf Jmpbuf;
  615. extern int errno;
  616.  
  617. X/*
  618.  *    abort --- close off a remote tape connection
  619.  */
  620.  
  621. static void abort(fildes)
  622. int fildes;
  623. {
  624.     close(READ(fildes));
  625.     close(WRITE(fildes));
  626.     READ(fildes) = -1;
  627.     WRITE(fildes) = -1;
  628. }
  629.  
  630.  
  631.  
  632. X/*
  633.  *    command --- attempt to perform a remote tape command
  634.  */
  635.  
  636. static int command(fildes, buf)
  637. int fildes;
  638. char *buf;
  639. {
  640.     register int blen;
  641.     int (*pstat)();
  642.  
  643. X/*
  644.  *    save current pipe status and try to make the request
  645.  */
  646.  
  647.     blen = strlen(buf);
  648.     pstat = signal(SIGPIPE, SIG_IGN);
  649.     if (write(WRITE(fildes), buf, blen) == blen)
  650.     {
  651.         signal(SIGPIPE, pstat);
  652.         return(0);
  653.     }
  654.  
  655. X/*
  656.  *    something went wrong. close down and go home
  657.  */
  658.  
  659.     signal(SIGPIPE, pstat);
  660.     abort(fildes);
  661.  
  662.     errno = EIO;
  663.     return(-1);
  664. }
  665.  
  666.  
  667.  
  668. X/*
  669.  *    status --- retrieve the status from the pipe
  670.  */
  671.  
  672. static int status(fildes)
  673. int fildes;
  674. {
  675.     int i;
  676.     char c, *cp;
  677.     char buffer[BUFMAGIC];
  678.  
  679. X/*
  680.  *    read the reply command line
  681.  */
  682.  
  683.     for (i = 0, cp = buffer; i < BUFMAGIC; i++, cp++)
  684.     {
  685.         if (read(READ(fildes), cp, 1) != 1)
  686.         {
  687.             abort(fildes);
  688.             errno = EIO;
  689.             return(-1);
  690.         }
  691.         if (*cp == '\n')
  692.         {
  693.             *cp = 0;
  694.             break;
  695.         }
  696.     }
  697.  
  698.     if (i == BUFMAGIC)
  699.     {
  700.         abort(fildes);
  701.         errno = EIO;
  702.         return(-1);
  703.     }
  704.  
  705. X/*
  706.  *    check the return status
  707.  */
  708.  
  709.     for (cp = buffer; *cp; cp++)
  710.         if (*cp != ' ')
  711.             break;
  712.  
  713.     if (*cp == 'E' || *cp == 'F')
  714.     {
  715.         errno = atoi(cp + 1);
  716.         while (read(READ(fildes), &c, 1) == 1)
  717.             if (c == '\n')
  718.                 break;
  719.  
  720.         if (*cp == 'F')
  721.             abort(fildes);
  722.  
  723.         return(-1);
  724.     }
  725.  
  726. X/*
  727.  *    check for mis-synced pipes
  728.  */
  729.  
  730.     if (*cp != 'A')
  731.     {
  732.         abort(fildes);
  733.         errno = EIO;
  734.         return(-1);
  735.     }
  736.  
  737.     return(atoi(cp + 1));
  738. }
  739.  
  740.  
  741.  
  742. X/*
  743.  *    _rmt_open --- open a magtape device on system specified, as given user
  744.  *
  745.  *    file name has the form system[.user]:/dev/????
  746.  */
  747.  
  748. #define MAXHOSTLEN    257    /* BSD allows very long host names... */
  749.  
  750. static int _rmt_open (path, oflag, mode)
  751. char *path;
  752. int oflag;
  753. int mode;
  754. {
  755.     int i, rc;
  756.     char buffer[BUFMAGIC];
  757.     char system[MAXHOSTLEN];
  758.     char device[BUFMAGIC];
  759.     char login[BUFMAGIC];
  760.     char *sys, *dev, *user;
  761.  
  762.     sys = system;
  763.     dev = device;
  764.     user = login;
  765.  
  766. X/*
  767.  *    first, find an open pair of file descriptors
  768.  */
  769.  
  770.     for (i = 0; i < MAXUNIT; i++)
  771.         if (READ(i) == -1 && WRITE(i) == -1)
  772.             break;
  773.  
  774.     if (i == MAXUNIT)
  775.     {
  776.         errno = EMFILE;
  777.         return(-1);
  778.     }
  779.  
  780. X/*
  781.  *    pull apart system and device, and optional user
  782.  *    don't munge original string
  783.  */
  784.     while (*path != '.' && *path != ':') {
  785.         *sys++ = *path++;
  786.     }
  787.     *sys = '\0';
  788.     path++;
  789.  
  790.     if (*(path - 1) == '.')
  791.     {
  792.         while (*path != ':') {
  793.             *user++ = *path++;
  794.         }
  795.         *user = '\0';
  796.         path++;
  797.     }
  798.     else
  799.         *user = '\0';
  800.  
  801.     while (*path) {
  802.         *dev++ = *path++;
  803.     }
  804.     *dev = '\0';
  805.  
  806. X/*
  807.  *    setup the pipes for the 'rsh' command and fork
  808.  */
  809.  
  810.     if (pipe(Ptc[i]) == -1 || pipe(Ctp[i]) == -1)
  811.         return(-1);
  812.  
  813.     if ((rc = fork()) == -1)
  814.         return(-1);
  815.  
  816.     if (rc == 0)
  817.     {
  818.         close(0);
  819.         dup(Ptc[i][0]);
  820.         close(Ptc[i][0]); close(Ptc[i][1]);
  821.         close(1);
  822.         dup(Ctp[i][1]);
  823.         close(Ctp[i][0]); close(Ctp[i][1]);
  824.         (void) setuid (getuid ());
  825.         (void) setgid (getgid ());
  826.         if (*user)
  827.         {
  828.             execl("/usr/ucb/rsh", "rsh", system, "-l", login,
  829.                 "/etc/rmt", (char *) 0);
  830.             execl("/usr/bin/remsh", "remsh", system, "-l", login,
  831.                 "/etc/rmt", (char *) 0);
  832.         }
  833.         else
  834.         {
  835.             execl("/usr/ucb/rsh", "rsh", system,
  836.                 "/etc/rmt", (char *) 0);
  837.             execl("/usr/bin/remsh", "remsh", system,
  838.                 "/etc/rmt", (char *) 0);
  839.         }
  840.  
  841. X/*
  842.  *    bad problems if we get here
  843.  */
  844.  
  845.         perror("exec");
  846.         exit(1);
  847.     }
  848.  
  849.     close(Ptc[i][0]); close(Ctp[i][1]);
  850.  
  851. X/*
  852.  *    now attempt to open the tape device
  853.  */
  854.  
  855.     sprintf(buffer, "O%s\n%d\n", device, oflag);
  856.     if (command(i, buffer) == -1 || status(i) == -1)
  857.         return(-1);
  858.  
  859.     return(i);
  860. }
  861.  
  862.  
  863.  
  864. X/*
  865.  *    _rmt_close --- close a remote magtape unit and shut down
  866.  */
  867.  
  868. static int _rmt_close(fildes)
  869. int fildes;
  870. {
  871.     int rc;
  872.  
  873.     if (command(fildes, "C\n") != -1)
  874.     {
  875.         rc = status(fildes);
  876.  
  877.         abort(fildes);
  878.         return(rc);
  879.     }
  880.  
  881.     return(-1);
  882. }
  883.  
  884.  
  885.  
  886. X/*
  887.  *    _rmt_read --- read a buffer from a remote tape
  888.  */
  889.  
  890. static int _rmt_read(fildes, buf, nbyte)
  891. int fildes;
  892. char *buf;
  893. unsigned int nbyte;
  894. {
  895.     int rc, i;
  896.     char buffer[BUFMAGIC];
  897.  
  898.     sprintf(buffer, "R%d\n", nbyte);
  899.     if (command(fildes, buffer) == -1 || (rc = status(fildes)) == -1)
  900.         return(-1);
  901.  
  902.     for (i = 0; i < rc; i += nbyte, buf += nbyte)
  903.     {
  904.         nbyte = read(READ(fildes), buf, rc);
  905.         if (nbyte <= 0)
  906.         {
  907.             abort(fildes);
  908.             errno = EIO;
  909.             return(-1);
  910.         }
  911.     }
  912.  
  913.     return(rc);
  914. }
  915.  
  916.  
  917.  
  918. X/*
  919.  *    _rmt_write --- write a buffer to the remote tape
  920.  */
  921.  
  922. static int _rmt_write(fildes, buf, nbyte)
  923. int fildes;
  924. char *buf;
  925. unsigned int nbyte;
  926. {
  927.     int rc;
  928.     char buffer[BUFMAGIC];
  929.     int (*pstat)();
  930.  
  931.     sprintf(buffer, "W%d\n", nbyte);
  932.     if (command(fildes, buffer) == -1)
  933.         return(-1);
  934.  
  935.     pstat = signal(SIGPIPE, SIG_IGN);
  936.     if (write(WRITE(fildes), buf, nbyte) == nbyte)
  937.     {
  938.         signal (SIGPIPE, pstat);
  939.         return(status(fildes));
  940.     }
  941.  
  942.     signal (SIGPIPE, pstat);
  943.     abort(fildes);
  944.     errno = EIO;
  945.     return(-1);
  946. }
  947.  
  948.  
  949.  
  950. X/*
  951.  *    _rmt_lseek --- perform an imitation lseek operation remotely
  952.  */
  953.  
  954. static long _rmt_lseek(fildes, offset, whence)
  955. int fildes;
  956. long offset;
  957. int whence;
  958. {
  959.     char buffer[BUFMAGIC];
  960.  
  961.     sprintf(buffer, "L%d\n%d\n", offset, whence);
  962.     if (command(fildes, buffer) == -1)
  963.         return(-1);
  964.  
  965.     return(status(fildes));
  966. }
  967.  
  968.  
  969. X/*
  970.  *    _rmt_ioctl --- perform raw tape operations remotely
  971.  */
  972.  
  973. #ifdef RMTIOCTL
  974. static _rmt_ioctl(fildes, op, arg)
  975. int fildes, op;
  976. char *arg;
  977. {
  978.     char c;
  979.     int rc, cnt;
  980.     char buffer[BUFMAGIC];
  981.  
  982. X/*
  983.  *    MTIOCOP is the easy one. nothing is transfered in binary
  984.  */
  985.  
  986.     if (op == MTIOCTOP)
  987.     {
  988.         sprintf(buffer, "I%d\n%d\n", ((struct mtop *) arg)->mt_op,
  989.             ((struct mtop *) arg)->mt_count);
  990.         if (command(fildes, buffer) == -1)
  991.             return(-1);
  992.         return(status(fildes));
  993.     }
  994.  
  995. X/*
  996.  *    we can only handle 2 ops, if not the other one, punt
  997.  */
  998.  
  999.     if (op != MTIOCGET)
  1000.     {
  1001.         errno = EINVAL;
  1002.         return(-1);
  1003.     }
  1004.  
  1005. X/*
  1006.  *    grab the status and read it directly into the structure
  1007.  *    this assumes that the status buffer is (hopefully) not
  1008.  *    padded and that 2 shorts fit in a long without any word
  1009.  *    alignment problems, ie - the whole struct is contiguous
  1010.  *    NOTE - this is probably NOT a good assumption.
  1011.  */
  1012.  
  1013.     if (command(fildes, "S\n") == -1 || (rc = status(fildes)) == -1)
  1014.         return(-1);
  1015.  
  1016.     for (; rc > 0; rc -= cnt, arg += cnt)
  1017.     {
  1018.         cnt = read(READ(fildes), arg, rc);
  1019.         if (cnt <= 0)
  1020.         {
  1021.             abort(fildes);
  1022.             errno = EIO;
  1023.             return(-1);
  1024.         }
  1025.     }
  1026.  
  1027. X/*
  1028.  *    now we check for byte position. mt_type is a small integer field
  1029.  *    (normally) so we will check its magnitude. if it is larger than
  1030.  *    256, we will assume that the bytes are swapped and go through
  1031.  *    and reverse all the bytes
  1032.  */
  1033.  
  1034.     if (((struct mtget *) arg)->mt_type < 256)
  1035.         return(0);
  1036.  
  1037.     for (cnt = 0; cnt < rc; cnt += 2)
  1038.     {
  1039.         c = arg[cnt];
  1040.         arg[cnt] = arg[cnt+1];
  1041.         arg[cnt+1] = c;
  1042.     }
  1043.  
  1044.     return(0);
  1045.   }
  1046. #endif /* RMTIOCTL */
  1047.  
  1048. X/*
  1049.  *    Added routines to replace open(), close(), lseek(), ioctl(), etc.
  1050.  *    The preprocessor can be used to remap these the rmtopen(), etc
  1051.  *    thus minimizing source changes:
  1052.  *
  1053.  *        #ifdef <something>
  1054.  *        #  define access rmtaccess
  1055.  *        #  define close rmtclose
  1056.  *        #  define creat rmtcreat
  1057.  *        #  define dup rmtdup
  1058.  *        #  define fcntl rmtfcntl
  1059.  *        #  define fstat rmtfstat
  1060.  *        #  define ioctl rmtioctl
  1061.  *        #  define isatty rmtisatty
  1062.  *        #  define lseek rmtlseek
  1063.  *        #  define lstat rmtlstat
  1064.  *        #  define open rmtopen
  1065.  *        #  define read rmtread
  1066.  *        #  define stat rmtstat
  1067.  *        #  define write rmtwrite
  1068.  *        #  define access rmtaccess
  1069.  *        #  define close rmtclose
  1070.  *        #  define creat rmtcreat
  1071.  *        #  define dup rmtdup
  1072.  *        #  define fcntl rmtfcntl
  1073.  *        #  define fstat rmtfstat
  1074.  *        #  define ioctl rmtioctl
  1075.  *        #  define lseek rmtlseek
  1076.  *        #  define open rmtopen
  1077.  *        #  define read rmtread
  1078.  *        #  define stat rmtstat
  1079.  *        #  define write rmtwrite
  1080.  *        #endif
  1081.  *
  1082.  *    -- Fred Fish
  1083.  *
  1084.  *    ADR --- I set up a <rmt.h> include file for this
  1085.  *
  1086.  */
  1087.  
  1088. X/*
  1089.  *    Note that local vs remote file descriptors are distinquished
  1090.  *    by adding a bias to the remote descriptors.  This is a quick
  1091.  *    and dirty trick that may not be portable to some systems.
  1092.  */
  1093.  
  1094. #define REM_BIAS 128
  1095.  
  1096.  
  1097. X/*
  1098.  *    Test pathname to see if it is local or remote.  A remote device
  1099.  *    is any string that contains ":/dev/".  Returns 1 if remote,
  1100.  *    0 otherwise.
  1101.  */
  1102.  
  1103. static int remdev (path)
  1104. register char *path;
  1105. {
  1106. #define strchr    index
  1107.     extern char *strchr ();
  1108.  
  1109.     if ((path = strchr (path, ':')) != NULL)
  1110.     {
  1111.         if (strncmp (path + 1, "/dev/", 5) == 0)
  1112.         {
  1113.             return (1);
  1114.         }
  1115.     }
  1116.     return (0);
  1117. }
  1118.  
  1119.  
  1120. X/*
  1121.  *    Open a local or remote file.  Looks just like open(2) to
  1122.  *    caller.
  1123.  */
  1124.  
  1125. int rmtopen (path, oflag, mode)
  1126. char *path;
  1127. int oflag;
  1128. int mode;
  1129. {
  1130.     if (remdev (path))
  1131.     {
  1132.         return (_rmt_open (path, oflag, mode) + REM_BIAS);
  1133.     }
  1134.     else
  1135.     {
  1136.         return (open (path, oflag, mode));
  1137.     }
  1138. }
  1139.  
  1140. X/*
  1141.  *    Test pathname for specified access.  Looks just like access(2)
  1142.  *    to caller.
  1143.  */
  1144.  
  1145. int rmtaccess (path, amode)
  1146. char *path;
  1147. int amode;
  1148. {
  1149.     if (remdev (path))
  1150.     {
  1151.         return (0);        /* Let /etc/rmt find out */
  1152.     }
  1153.     else
  1154.     {
  1155.         return (access (path, amode));
  1156.     }
  1157. }
  1158.  
  1159.  
  1160. X/*
  1161.  *    Read from stream.  Looks just like read(2) to caller.
  1162.  */
  1163.   
  1164. int rmtread (fildes, buf, nbyte)
  1165. int fildes;
  1166. char *buf;
  1167. unsigned int nbyte;
  1168. {
  1169.     if (isrmt (fildes))
  1170.     {
  1171.         return (_rmt_read (fildes - REM_BIAS, buf, nbyte));
  1172.     }
  1173.     else
  1174.     {
  1175.         return (read (fildes, buf, nbyte));
  1176.     }
  1177. }
  1178.  
  1179.  
  1180. X/*
  1181.  *    Write to stream.  Looks just like write(2) to caller.
  1182.  */
  1183.  
  1184. int rmtwrite (fildes, buf, nbyte)
  1185. int fildes;
  1186. char *buf;
  1187. unsigned int nbyte;
  1188. {
  1189.     if (isrmt (fildes))
  1190.     {
  1191.         return (_rmt_write (fildes - REM_BIAS, buf, nbyte));
  1192.     }
  1193.     else
  1194.     {
  1195.         return (write (fildes, buf, nbyte));
  1196.     }
  1197. }
  1198.  
  1199. X/*
  1200.  *    Perform lseek on file.  Looks just like lseek(2) to caller.
  1201.  */
  1202.  
  1203. long rmtlseek (fildes, offset, whence)
  1204. int fildes;
  1205. long offset;
  1206. int whence;
  1207. {
  1208.     if (isrmt (fildes))
  1209.     {
  1210.         return (_rmt_lseek (fildes - REM_BIAS, offset, whence));
  1211.     }
  1212.     else
  1213.     {
  1214.         return (lseek (fildes, offset, whence));
  1215.     }
  1216. }
  1217.  
  1218.  
  1219. X/*
  1220.  *    Close a file.  Looks just like close(2) to caller.
  1221.  */
  1222.  
  1223. int rmtclose (fildes)
  1224. int fildes;
  1225. {
  1226.     if (isrmt (fildes))
  1227.     {
  1228.         return (_rmt_close (fildes - REM_BIAS));
  1229.     }
  1230.     else
  1231.     {
  1232.         return (close (fildes));
  1233.     }
  1234. }
  1235.  
  1236. X/*
  1237.  *    Do ioctl on file.  Looks just like ioctl(2) to caller.
  1238.  */
  1239.  
  1240. int rmtioctl (fildes, request, arg)
  1241. int fildes, request, arg;
  1242. {
  1243.     if (isrmt (fildes))
  1244.     {
  1245. #ifdef RMTIOCTL
  1246.         return (_rmt_ioctl (fildes, request, arg));
  1247. #else
  1248.         errno = EOPNOTSUPP;
  1249.         return (-1);        /* For now  (fnf) */
  1250. #endif
  1251.     }
  1252.     else
  1253.     {
  1254.         return (ioctl (fildes, request, arg));
  1255.     }
  1256. }
  1257.  
  1258.  
  1259. X/*
  1260.  *    Duplicate an open file descriptor.  Looks just like dup(2)
  1261.  *    to caller.
  1262.  */
  1263.  
  1264. int rmtdup (fildes)
  1265. int fildes;
  1266. {
  1267.     if (isrmt (fildes))
  1268.     {
  1269.         errno = EOPNOTSUPP;
  1270.         return (-1);        /* For now (fnf) */
  1271.     }
  1272.     else
  1273.     {
  1274.         return (dup (fildes));
  1275.     }
  1276. }
  1277.  
  1278. X/*
  1279.  *    Get file status.  Looks just like fstat(2) to caller.
  1280.  */
  1281.  
  1282. int rmtfstat (fildes, buf)
  1283. int fildes;
  1284. struct stat *buf;
  1285. {
  1286.     if (isrmt (fildes))
  1287.     {
  1288.         errno = EOPNOTSUPP;
  1289.         return (-1);        /* For now (fnf) */
  1290.     }
  1291.     else
  1292.     {
  1293.         return (fstat (fildes, buf));
  1294.     }
  1295. }
  1296.  
  1297.  
  1298. X/*
  1299.  *    Get file status.  Looks just like stat(2) to caller.
  1300.  */
  1301.  
  1302. int rmtstat (path, buf)
  1303. char *path;
  1304. struct stat *buf;
  1305. {
  1306.     if (remdev (path))
  1307.     {
  1308.         errno = EOPNOTSUPP;
  1309.         return (-1);        /* For now (fnf) */
  1310.     }
  1311.     else
  1312.     {
  1313.         return (stat (path, buf));
  1314.     }
  1315. }
  1316.  
  1317.  
  1318.  
  1319. X/*
  1320.  *    Create a file from scratch.  Looks just like creat(2) to the caller.
  1321.  */
  1322.  
  1323. #include <sys/file.h>        /* BSD DEPENDANT!!! */
  1324. X/* #include <fcntl.h>        /* use this one for S5 with remote stuff */
  1325.  
  1326. int rmtcreat (path, mode)
  1327. char *path;
  1328. int mode;
  1329. {
  1330.     if (remdev (path))
  1331.     {
  1332.         return (rmtopen (path, 1 | O_CREAT, mode));
  1333.     }
  1334.     else
  1335.     {
  1336.         return (creat (path, mode));
  1337.     }
  1338. }
  1339.  
  1340. X/*
  1341.  *    Isrmt. Let a programmer know he has a remote device.
  1342.  */
  1343.  
  1344. int isrmt (fd)
  1345. int fd;
  1346. {
  1347.     return (fd >= REM_BIAS);
  1348. }
  1349.  
  1350. X/*
  1351.  *    Rmtfcntl. Do a remote fcntl operation.
  1352.  */
  1353.  
  1354. int rmtfcntl (fd, cmd, arg)
  1355. int fd, cmd, arg;
  1356. {
  1357.     if (isrmt (fd))
  1358.     {
  1359.         errno = EOPNOTSUPP;
  1360.         return (-1);
  1361.     }
  1362.     else
  1363.     {
  1364.         return (fcntl (fd, cmd, arg));
  1365.     }
  1366. }
  1367.  
  1368. X/*
  1369.  *    Rmtisatty.  Do the isatty function.
  1370.  */
  1371.  
  1372. int rmtisatty (fd)
  1373. int fd;
  1374. {
  1375.     if (isrmt (fd))
  1376.         return (0);
  1377.     else
  1378.         return (isatty (fd));
  1379. }
  1380.  
  1381.  
  1382. X/*
  1383.  *    Get file status, even if symlink.  Looks just like lstat(2) to caller.
  1384.  */
  1385.  
  1386. int rmtlstat (path, buf)
  1387. char *path;
  1388. struct stat *buf;
  1389. {
  1390.     if (remdev (path))
  1391.     {
  1392.         errno = EOPNOTSUPP;
  1393.         return (-1);        /* For now (fnf) */
  1394.     }
  1395.     else
  1396.     {
  1397.         return (lstat (path, buf));
  1398.     }
  1399. }
  1400. //go.sysin dd *
  1401. if [ `wc -c < rmtlib.c` != 13684 ]; then
  1402.     made=FALSE
  1403.     /bin/echo 'error transmitting "rmtlib.c" --'
  1404.     /bin/echo 'length should be 13684, not' `wc -c < rmtlib.c`
  1405. else
  1406.     made=TRUE
  1407. fi
  1408. if [ $made = TRUE ]; then
  1409.     /bin/chmod 440 rmtlib.c
  1410.     /bin/echo -n '    '; /bin/ls -ld rmtlib.c
  1411. fi
  1412. /bin/echo 'Extracting rmt.h'
  1413. sed 's/^X//' <<'//go.sysin dd *' >rmt.h
  1414. X/*
  1415.  *    rmt.h
  1416.  *
  1417.  *    Added routines to replace open(), close(), lseek(), ioctl(), etc.
  1418.  *    The preprocessor can be used to remap these the rmtopen(), etc
  1419.  *    thus minimizing source changes.
  1420.  *
  1421.  *    This file must be included before <sys/stat.h>, since it redefines
  1422.  *    stat to be rmtstat, so that struct stat xyzzy; declarations work
  1423.  *    properly.
  1424.  *
  1425.  *    -- Fred Fish (w/some changes by Arnold Robbins)
  1426.  */
  1427.  
  1428.  
  1429. #ifndef access        /* avoid multiple redefinition */
  1430. #ifndef lint        /* in this case what lint doesn't know won't hurt it */
  1431. #define access rmtaccess
  1432. #define close rmtclose
  1433. #define creat rmtcreat
  1434. #define dup rmtdup
  1435. #define fcntl rmtfcntl
  1436. #define fstat rmtfstat
  1437. #define ioctl rmtioctl
  1438. #define isatty rmtisatty
  1439. #define lseek rmtlseek
  1440. #define lstat rmtlstat
  1441. #define open rmtopen
  1442. #define read rmtread
  1443. #define stat rmtstat
  1444. #define write rmtwrite
  1445.  
  1446. extern long rmtlseek ();    /* all the rest are int's */
  1447. #endif
  1448. #endif
  1449. //go.sysin dd *
  1450. if [ `wc -c < rmt.h` != 904 ]; then
  1451.     made=FALSE
  1452.     /bin/echo 'error transmitting "rmt.h" --'
  1453.     /bin/echo 'length should be 904, not' `wc -c < rmt.h`
  1454. else
  1455.     made=TRUE
  1456. fi
  1457. if [ $made = TRUE ]; then
  1458.     /bin/chmod 440 rmt.h
  1459.     /bin/echo -n '    '; /bin/ls -ld rmt.h
  1460. fi
  1461.  
  1462.