[Dovecot] A view quirks

Timo Sirainen tss at iki.fi
Tue Oct 21 13:12:21 EEST 2003


On Tue, 2003-10-21 at 11:50, Andreas Jaekel wrote:
> >that's a bit annoying since either you have to do it always (unnecessary
> >nearly always) or add some extra kludgy checks. You could also be just
> >reading with mmap() or pread() but I'm not sure if it's a good idea to
> >rely on them either.
> 
> 
> Well, always seeking on input and output works, (I tried)
> except it breaks APPEND, which reads from a socket, which
> fails seeking, which I have no clean way of knowing since
> it's all hidden behind the stream wrappers.

There's fstream->file which tells if it's a regular file :)

> I think a clean way may be to change the stream wrappers so
> they remember which streams are dup()s of other streams.

They're not dup()ed, they just use the same file descriptors. But ..
hmm. that would be possible, but that's still quite a lot of code for
cases which are rarely needed..

> Another possible solution is to change output to always use
> pwrite(), avoiding the need for seeks completly.

Changing ostream to use pwrite() would require replacing the one
writev() call too with multiple pwrite()s, not nice .. :)

How about:

diff -u -r1.9 istream-file.c
--- istream-file.c      26 Aug 2003 21:18:16 -0000      1.9
+++ istream-file.c      21 Oct 2003 10:11:25 -0000
@@ -2,6 +2,8 @@
 
 /* @UNSAFE: whole file */
 
+#define _XOPEN_SOURCE 500 /* for pread() / Linux */
+
 #include "lib.h"
 #include "alarm-hup.h"
 #include "istream-internal.h"
@@ -169,7 +171,15 @@
                        return -1;
                }
 
-               ret = read(stream->fd, stream->w_buffer + stream->pos, size);
+               if (fstream->file) {
+                       ret = pread(stream->fd,
+                                   stream->w_buffer + stream->pos, size,
+                                   stream->istream.start_offset +
+                                   stream->istream.v_offset);
+               } else {
+                       ret = read(stream->fd,
+                                  stream->w_buffer + stream->pos, size);
+               }
                if (ret == 0) {
                        /* EOF */
                        stream->istream.stream_errno = 0;




More information about the dovecot mailing list