* fhandler_disk_file.cc (fhandler_base::pread): Don't move file offset pointer

after I/O.
(fhandler_base::pwrite): Ditto.
This commit is contained in:
Christopher Faylor 2005-07-29 17:26:10 +00:00
parent ca48709996
commit 88c5a50f9f
2 changed files with 25 additions and 6 deletions

View File

@ -1,3 +1,9 @@
2005-07-29 Christopher Faylor <cgf@timesys.com>
* fhandler_disk_file.cc (fhandler_base::pread): Don't move file offset
pointer after I/O.
(fhandler_base::pwrite): Ditto.
2005-07-29 Christopher Faylor <cgf@timesys.com> 2005-07-29 Christopher Faylor <cgf@timesys.com>
* fhandler.h (fhandler_base::pread): Declare new function. * fhandler.h (fhandler_base::pread): Declare new function.

View File

@ -987,12 +987,18 @@ fhandler_base::close_fs ()
ssize_t __stdcall ssize_t __stdcall
fhandler_disk_file::pread (void *buf, size_t count, _off64_t offset) fhandler_disk_file::pread (void *buf, size_t count, _off64_t offset)
{ {
ssize_t res = lseek (offset, SEEK_SET); ssize_t res;
if (res >= 0) _off64_t curpos = lseek (0, SEEK_CUR);
if (curpos < 0 || lseek (offset, SEEK_SET) < 0)
res = -1;
else
{ {
size_t tmp_count = count; size_t tmp_count = count;
read (buf, tmp_count); read (buf, tmp_count);
if (lseek (curpos, SEEK_SET) == 0)
res = (ssize_t) tmp_count; res = (ssize_t) tmp_count;
else
res = -1;
} }
debug_printf ("%d = pread (%p, %d, %d)\n", res, buf, count, offset); debug_printf ("%d = pread (%p, %d, %d)\n", res, buf, count, offset);
return res; return res;
@ -1001,9 +1007,16 @@ fhandler_disk_file::pread (void *buf, size_t count, _off64_t offset)
ssize_t __stdcall ssize_t __stdcall
fhandler_disk_file::pwrite (void *buf, size_t count, _off64_t offset) fhandler_disk_file::pwrite (void *buf, size_t count, _off64_t offset)
{ {
ssize_t res = lseek (offset, SEEK_SET); int res;
if (res >= 0) _off64_t curpos = lseek (0, SEEK_CUR);
res = write (buf, count); if (curpos < 0 || lseek (offset, SEEK_SET) < 0)
res = curpos;
else
{
res = (ssize_t) write (buf, count);
if (lseek (curpos, SEEK_SET) < 0)
res = -1;
}
debug_printf ("%d = pwrite (%p, %d, %d)\n", res, buf, count, offset); debug_printf ("%d = pwrite (%p, %d, %d)\n", res, buf, count, offset);
return res; return res;
} }