From mboxrd@z Thu Jan 1 00:00:00 1970 To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net> In-reply-to: Your message of "Sat, 05 Dec 2009 15:03:44 EST." References: <<20091205194741.0697D5B76@mail.bitblocks.com>> From: Bakul Shah Date: Sat, 5 Dec 2009 12:24:20 -0800 Message-Id: <20091205202420.855AD5B77@mail.bitblocks.com> Subject: Re: [9fans] ideas for helpful system io functions Topicbox-Message-UUID: a8d081a4-ead5-11e9-9d60-3106f5b1d025 On Sat, 05 Dec 2009 15:03:44 EST erik quanstrom wrote: > > The OS support I am talking about: > > a) the fork behavior on an open file should be available > > *without* forking. dup() doesn't cut it (both fds share > > the same offset on the underlying file). I'd call the new > > syscall fdfork(). That is, if I do > > > > int newfd = fdfork(oldfd); > > > > reading N bytes each from newfd and oldfd will return > > identical data. > > i can't think of a way to do this correctly. buffering in the > kernel would only work if each process issued exactly the > same set of reads. there is no requirement that the data > from 2 reads of 100 bytes each be the same as the data > return with 1 200 byte read. To be precise, both fds have their own pointer (or offset) and reading N bytes from some offset O must return the same bytes. The semantics I'd choose is first read gets bufferred and reads get satisfied first from buffered data and only then from the underlying object. Same with writes. They are 'write through". If synthetic files do weird things at different offsets or for different read/write counts, I'd consider them uncacheable (and you shouldn't use fdfork with them). For disk based files and fifos there should be no problem. Note that Haskell streams are basically cacheable! > before you bother with "but that's a wierd case", remember > that the success of unix and plan 9 has been built on the > fact that there aren't syscalls that fail in "wierd" cases. I completely agree. But hey, I just came up with the idea and haven't worked out all the design bugs (and may never)! It seemed worth sharing to elicit exactly the kind of feedback you are giving.