From mboxrd@z Thu Jan 1 00:00:00 1970 MIME-Version: 1.0 In-Reply-To: <20091205194741.0697D5B76@mail.bitblocks.com> References: <20091205031747.GA8759@nipl.net> <20091205194741.0697D5B76@mail.bitblocks.com> Date: Mon, 7 Dec 2009 12:24:05 +0000 Message-ID: From: roger peppe To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [9fans] ideas for helpful system io functions Topicbox-Message-UUID: a9b9c06c-ead5-11e9-9d60-3106f5b1d025 2009/12/5 Bakul Shah : > =C2=A0 =C2=A0 =C2=A0 int newfd =3D fdfork(oldfd); i'm not sure that there needs to be a new syscall to enable this. a driver would be adequate. here's one possibility: the driver implements "buffered streams" - i.e. reads are lazy, but previous reads can be re-read. bind '#=CE=B24.8192' /mnt/bufstream to get a buffered, read-only stream of fd 4, with an 8K buffer. open /mnt/bufstream/data to get a new window on the stream. if you read at an offset beyond anything previously read, it triggers a read on the underlying fd, which may block. if the offset isn't within the buffer size, then the read returns -1; otherwise the read is satisfied from the buffered data. the underlying assumption is that the fd is stream-, not message-oriented - as with tcp; message boundaries are not preserved. if you wanted it, an "fd join" driver could be simply implemented in a similar way: bind '#j4.5' /mnt/joined open /mnt/joined/data to get a (read-only) fd that satisfies reads from fd = 4 until eof, then fd 5. both of these might make a fun exercise for a rainy day.