henry@utzoo.UUCP (Henry Spencer) (03/31/84)
One of the more interesting things done in System N (N = III or V just now) was that "test" is built into the shell. Although we don't run System V, we do run a slightly-modified System V shell on our V7. We have just discovered a very interesting thing: the test(1) command that is built into the shell is not quite the same as the old separate program. The difference is that the old test(1) tested for accessability by trying to open the file. The in-shell one just uses access(2) to look at the permission bits. What difference is there, you ask? Well... There's a minor difference in the case of "test -w directory". This isn't too important, and the new behavior (actually look at the bits rather than just bouncing it regardless) is arguably better. The *real* fun is when you are doing a test(1) on a device. We discovered this because we had a few things that used to do, for example, "test -r /dev/rmt0" to make the magtape rewind. Don't work no more. This breaks things. Not very many things, mind you, and we don't see this as too serious issue. However, consider the following. Shell file, written on System V, does "test -w /dev/rmt0" to see if it's running on a system with a magtape at a suitable name. On a system with the old-style test(1) command, this will write a tape mark at the beginning of the tape, effectively obliterating any data on the tape! Another fun property of using access(2) for test(1) is that access(2) uses the real, not effective, userid. This could make setuid shell files (if you have them -- we don't) *very* interesting. -- Henry Spencer @ U of Toronto Zoology {allegra,ihnp4,linus,decvax}!utzoo!henry
dmmartindale@watcgl.UUCP (Dave Martindale) (03/31/84)
Re: test -w /dev/rmt0 writes a tape mark on tape in v7 Interesting. You can probably still read much of the data on the tape by skipping over the tape mark. However, if the tape was originally written at one density, and the tape mark gets written at a different density, you won't be able to read anything at all, since drives which handle multiple recording densities usually look at an identification burst (or lack of it) at the beginning of the tape to determine the density of the rest of the tape.