COPYSERVER(1)                                       COPYSERVER(1)

     NAME
          copyserver - file copying between a source and a destination

     SYNOPSIS
          copyserver [ -d ] mntdir

     DESCRIPTION
          copyserver starts a styxservers(2) server and mounts it at
          mntdir (replacing the old binding, if any).  Once done, the
          server is ready to accept copy requests. Unmounting mntdir
          will cleanly shutdown the server.

          Copy requests are written into the (virtual) control file of
          the server, named ctl , using the following format:

               copy
                   [srcmntopt] srcfname srcoff
                   [dstmntopt] dstfname dstoff
                   nofbytes iounit delay ctlfile

          If the source and destination files are successfully opened,
          the copy commences. The write operation on the server con-
          trol file blocks until the copy terminates, or it is killed
          (discussed in the sequel), or an r/w error occurs.  Also, a
          copy is aborted if the process that writes the request to
          the server control file is killed (this is detected by the
          server via the receipt of a flush(5) message for the write
          operation).

          Here is a brief explanation of the copy request arguments:

          srcfname and dstfname specify the source and destination
          file name, relative to the root of the source and destina-
          tion file system, respectively. srcfname must point to an
          existing file.  If dstfname points to an existing file, this
          will be truncated and overwritten, else a new file will be
          created.

          srcoff and dstoff specify the offset from which to start
          reading the source and writing the destination file, respec-
          tively. These values must be equal or greater than zero.
          The file position is adjusted based on the rules for sys-seek(2) (using Sys->SEEKSTART ).

          nofbytes specifies the number of bytes to copy from the
          source to the destination file. The copy operation will ter-
          minate in case the end of the source file is reached ear-
          lier. If nofbytes is zero, the copy will not terminate
          unless the end of the source file is reached. If the source
          points to the reading end of an endless stream, the copy

     COPYSERVER(1)                                       COPYSERVER(1)

          will run "for ever", until it is aborted or killed.

          iounit specifies the size of the data buffer used to read
          bytes from the source file and write them to the destination
          file.

          delay specifies the number of milliseconds to wait between
          two successive r/w operations. Combined with a small iounit
          value (e.g. 1 byte), this makes it possible to test the copy
          server in an interactive fashion and using small files. If
          delay is zero, the copy will be performed at full speed.

          For both the source and destination, an option, srcmntopt
          and dstmntopt , respectively, can be used to specify whether
          the corresponding file systems need to be mounted, and how
          this should be achieved.  The mount option has the following
          format:

               (-s[A] | -o[A]) addr

          Option -s is specifies a conventional mount via styx(2) ,
          and option -o specifies a mount via ofs(4) to a remote
          oxport(4) server. In both cases, the -A option is used to
          turn authentication off.  addr specifies the address to be
          dialed.  If no mount option is used, the server interprets
          the filename relative to its local name space (no mount is
          done).

          For each ongoing copy, the server "creates" a (virtual) con-
          trol file, using the ctlfname that was supplied in the
          request. The server "removes" the control file when the copy
          terminates (or is aborted or is killed).

          Reading the copy control file returns the number of bytes
          copied so far as a string value. Writing the string value
          "kill" in the file kills the copy (the server will notify
          the blocked process that issued the copy request via an
          error(5) message).

     EXAMPLE
          To mount a copy server on /cpsrv with debugging output
          enabled:

               ./copyserver -d /cpsrv

          To (background) copy file /d1/f1 exported by an oxport file
          server which does not require authentication and listens on
          tcp!127.0.0.1!4242 , to file /d2/f2 in the file system of
          the copy server, using a r/w buffer of 512 bytes, with an
          artificial delay of 50 ms between each r/w operation, and
          cp1 being the name of the copy control file:

     COPYSERVER(1)                                       COPYSERVER(1)

               echo copy -oA tcp!127.0.0.1!4242 /d1/f1 0
                                                /d2/f2 0
                         0 512 50 cp1 > /cpsrv/ctl &

          Or to (background) copy file /d1/f1 exported by a styx file
          server which does not require authentication and listens on
          tcp!127.0.0.1!4243 , to file /d2/f2 in the file system
          exported by the same oxport server as above, using the same
          request settings:

               echo copy -sA tcp!127.0.0.1!4243 /d1/f1 0
                         -oA tcp!127.0.0.1!4242 /d2/f2 0
                         0 512 50 cp1 > /cpsrv/ctl &

          To check the progress of the copy:

               cat /cpsrv/cp1

          To abort the copy, one may kill the process that issued the
          request (and remains blocked waiting for the write operation
          to return). Alternatively, one may use the corresponding
          control file to kill the copy (this will also unblock the
          background process):

               echo kill > /cpsrv/cp1

          Finally, to unmount the copy server:

               unmount /cpsrv

          Note that the copy server will shutdown when all processes
          have unmounted it from their name space.

     SOURCE
          /usr/octopus/varia/copyserver.b

     SEE ALSO
          styx(2) , mount(2) , ofs(4) , and oxport(4)

     BUGS
          There is no access control for the copy control files "cre-
          ated" by the server. Any process can read and write every
          copy control file (e.g. kill any ongoing copy, if it so
          desires).  Also, the ownership and access rights of the des-
          tination files created as a side effect of a copy are not
          properly set.

          There is a subtle race condition when reading the copy con-
          trol file, which may result in occasionally delivering a

     COPYSERVER(1)                                       COPYSERVER(1)

          wrong value for the number of bytes that have been copied so
          far. The probability for this is (very) small.

          For simplicity, dialing and mounting (and unmounting) file
          systems is currently done via shell commands (instead of a
          direct invocation of the corresponding primitives). This
          means that changes in the command syntax will "brake" the
          copyserver code. Also, the failure of a shell command is
          inferred indirectly, by checking whether any output was
          written on standard error.

          Killing/aborting a copy is asynchronous, i.e. it may be per-
          formed with a (small) delay, after having sent the corre-
          sponding reply message to the entity that triggered this
          action.