Path: utzoo!utgpu!watserv1!watmath!att!att!linac!uwm.edu!cs.utexas.edu!yale!mintaka!bloom-beacon!eru!hagbard!sunic!kth.se!news From: rog@speech.kth.se (Roger Lindell) Newsgroups: comp.sys.apollo Subject: Re: Perl op.stat failure Message-ID: Date: 28 Nov 90 15:36:45 GMT References: <3071@nosc.NOSC.MIL> <1219@digi.lonestar.org> <1249@digi.lonestar.org> Sender: news@kth.se (News Administrator) Organization: Royal Institute of Technology Lines: 90 kgallagh@digi.lonestar.org (Kevin Gallagher) writes: >I tried modifying the op.stat perl script by adding the line > close(foo); >immediately before the invocation of stat. Now, it did not matter if I ran it >from my node or some other node, stat always returned 0 as the number of >links. [Stuff deleted] >If I modified the perl op.stat script NOT to open the file before invoking the >stat command, it always returned 0 links, no matter where I was logged in. >It appears that, on the Apollo, perl's stat only works correctly if the file >is opened AND is located on a a disk in the same node where the script is >executed. But this is a preliminary guess. I did not check if the two nodes >I used were on the same or different rings. Maybe it works OK if the nodes >are in the same ring. But I am puzzled why perl stat always returns 0 links >when the file is not opened. Anyway, the problem needs further investigation. >I briefly searched the perl source this evening and suspect that the file >doio.c handles the perl stat processing. >Anyone got a clue what is going on here? The problem is that perl's stat() is the equivalent to Apollo's fstat() and to use this function you need a file descriptor as an argument. This means that the file must be open when you do a stat in perl. I wrote a small C-program which uses fstat() and reports the number of links to a file. The source code follows: #include #include #include #include void main(int argc, char **argv) { int file_d ; struct stat stat_buffer ; if (argc == 2) { file_d = open(argv[1],O_CREAT|O_RDWR|O_APPEND,0644) ; fstat(file_d,&stat_buffer) ; printf("Number of hard links = %d\n",(int)stat_buffer.st_nlink) ; close(file_d) ; } } When I run this program, and as input gives the name of a nonexistent file, I get the answer Number of hard links = 0 if the disk, on which the file gets created, is not local. If on the other hand I run this program on the machine that has the disk, I get Number of hard links = 1 If I run the program, and as input gives the name of an existing file, I get the answer Number of hard links = 1 independently of if the file is on a local disk or not. You can try this with perl's op.stat program, add these two lines before the first open open(foo, ">Op.stat.tmp"); close(foo); If you do this and then run the op.stat program it will report that everthing is OK, but since there is an unlink instruction preceding the original open I don't think that my fix is a "supported" fix. So the problem seems to be with Apollo's fstat(). Is this a genuine Apollo bug or is this something that is allowed by BSD UNIX? Why I ask this is because if you read the man page for fstat and look at the BUGS section it says: Applying fstat to a socket (and thus to a pipe) returns a zeroed buffer, except for the blocksize field, and a unique device and inode number. Roger Lindell -- Roger Lindell rog@speech.kth.se Phone: +46 8 790 75 73 Fax: +46 8 790 78 54 Dept. of Speech Communication and Music Acoustics Royal Institute of Technology Sweden