Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watmath!clyde!rutgers!mit-eddie!genrad!decvax!decwrl!pyramid!prls!philabs!micomvax!musocs!mcgill-vision!mouse From: mouse@mcgill-vision.UUCP Newsgroups: comp.unix.wizards Subject: Re: a creat() hack Message-ID: <894@mcgill-vision.UUCP> Date: Sat, 19-Sep-87 19:00:14 EDT Article-I.D.: mcgill-v.894 Posted: Sat Sep 19 19:00:14 1987 Date-Received: Sun, 27-Sep-87 23:04:56 EDT References: <3921@cit-vax.Caltech.Edu> <1765@brspyr1.BRS.Com> Organization: McGill University, Montreal Lines: 38 In article <1765@brspyr1.BRS.Com>, tim@brspyr1.BRS.Com (Tim Northrup) writes: > in article <3921@cit-vax.Caltech.Edu>, mangler@cit-vax.Caltech.Edu says: >> Consider an alternate implementation, which instead of truncating >> the file upon creat(), just sets a "deferred truncate" flag. [...] >> If you copy a file over itself, it doesn't clobber the file. > If you open the file for "read" first, then "creat()", the file won't > get clobbered until you close the read end. I believe that even if > the system crashes in the middle of this, the file will not be > clobbered. I assume you are speaking of the way things work now? Close, but no cigar. If you open a file for read, and then creat() it, you will find that all the data has disappeared. If you open it for read, unlink() it, and then creat() it, you will have two files, one of which is full of data but has no directory entry and the other which is new but appears in a directory. If the system crashes fsck will generally trash the unreferenced one and leave the other. I seem to recall a suggestion heard here a while ago, which seems eminently sensible. Have some means to create an anonymous file, and then have a syscall to enter such an anonymous file in a directory. Since the anonymous file must be on the same filesystem as the directory, the first half could be done by using mktemp(), creat(), and unlink(). Then we need a syscall which is sort of like rename() except that the "from" file is a file descriptor instead of a pathname. But using a rename()-style call would lose link information. And none of this helps you where you can write the file but not the directory. I guess you Just Can't Win. der Mouse (mouse@mcgill-vision.uucp)