vsh@etnibsd.UUCP (Steve Harris) (02/09/90)
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.) Also, in the scripts in the perl library, every comment line begins with ";#", not just "#". Why is this? (Inquiring minds, etc.) -- Steve Harris - Eaton Corp. - Beverly, MA - uunet!etnibsd!vsh
lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) (02/14/90)
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