Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!elroy.jpl.nasa.gov!jpl-devvax!lwall From: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Newsgroups: comp.lang.perl Subject: Re: PERL PL28 and reading raw devices (problem) Message-ID: <9681@jpl-devvax.JPL.NASA.GOV> Date: 26 Sep 90 17:57:50 GMT References: <1990Sep26.122859.18935@uvaarpa.Virginia.EDU> Reply-To: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Organization: Jet Propulsion Laboratory, Pasadena, CA Lines: 38 In article <1990Sep26.122859.18935@uvaarpa.Virginia.EDU> telxon!ping!gorpong@uunet.uu.net writes: : I am writing a perl program which will handle tape copying from remote or : local devices. The scheme I use for a local source device is to open up : the device via: : open(SRC_TAPE, "< $SRC_TAPE"); : I then open up a pipe to write the remote tape (or pipe to read the remote). : When going remote for the device, I use the 'dd' command to do the reading : and/or writing. Enough background, now to the question. : : When copying a tape which is in boot format, the program tells me that it : has read and written the exact same number of bytes. When attempting to : boot this tape, it fails every time, on every tape drive. When forcing : the program to use 'dd' to read the tape and write the tape, it also tells : me that the correct number of bytes have been written. However, the : copy made with 'dd' on both ends boots correctly. : : I am reading the tape with the perl read(SRC_TAPE, $_, $blksize); and : SRC_TAPE is opened either "< device" or "dd if=device |" : The exact same code works when the open is opening up a 'dd' command to : read the device. Is there something which perl is doing to the bytes : read in from the raw device which it does not do when reading from a pipe? : : I should note that when copying things like 'tar' format tapes, it is still : in tar format, and it unarchives correctly. It really screws up boot : format tapes. My question is, why? It is perl patchlevel 28 on a Sun 3/50 : or 3/anything (or 4/anything) running SunOS 4.1. Any help you may be able : to give me would be greatly appreciated. The problem is that read is actually a call to standard I/O's fread(), and how many bytes fread() chooses to read has little relation to how many bytes you said to read. For this very reason, Perl 4.0 has a sysread() and a syswrite() function. For now, you can call a real read() using syscall(), if you have it available. Larry