Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.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 will not open block-special files Message-ID: <7070@jpl-devvax.JPL.NASA.GOV> Date: 14 Feb 90 01:42:15 GMT References: <1108@etnibsd.UUCP> Reply-To: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Organization: Jet Propulsion Laboratory, Pasadena, CA Lines: 57 In article <1108@etnibsd.UUCP> vsh@etnibsd.UUCP (Steve Harris) writes: : I wrote a little script to read disk blocks. It starts with : the following two lines: : : $DEV = "<" . $ARGV[0]; # make sure DEV is opened for reading : open DEV || die "cannot open $DEV"; : : The open works fine when I open a character device, but fails when I : try to open a block device: : : perl test.pl /dev/xy0c # fails; xy0c is block-special : perl test.pl /dev/rxy0c # okay; rxy0c is character-special : : If I open stdin and use shell redirection to associate stdin with the : file, the open succeeds: : : perl test.pl - < /dev/rxy0c # okay; open stdin : : So I dug into the source, and found, in "doio.c", the following code: : : /**********************************************************/ : if (stio->type && : stio->type != '|' && stio->type != '-') { : if (fstat(fileno(fp),&statbuf) < 0) { : (void)fclose(fp); : return FALSE; : } : if ((statbuf.st_mode & S_IFMT) != S_IFREG && : #ifdef S_IFSOCK : (statbuf.st_mode & S_IFMT) != S_IFSOCK && : #endif : #ifdef S_IFFIFO : (statbuf.st_mode & S_IFMT) != S_IFFIFO && : #endif : (statbuf.st_mode & S_IFMT) != S_IFCHR) { : (void)fclose(fp); : return FALSE; : } : } : /**********************************************************/ : : I'm not sure what's going on here, but it sure looks like perl wants : the device to be either regular, character-special, socket, or fifo. : : Why is this? Is it necessary? Is this "fixed" with a patch I haven't : had time to obtain and install? (I'm running 3.0, patch level 1; I : know I should get up to date but it works well enough that I have not : done so, yet.) This was a holdover from when perl only processed text files. Now that binary files won't blow things sky high, the paranoia check is unnecessary. >>patch9 as usual [For once, a change that deletes code rather than adding it...] Larry