* fhandler.h (fhandler_base::pread): Declare new function.

(fhandler_base::pwrite): Ditto.
(fhandler_disk_file::pread): Ditto.
(fhandler_disk_file::pwrite): Ditto.
* fhandler.cc (fhandler_base::pread): Define new function.
(fhandler_base::pwrite): Ditto.
* fhandler_disk_file.cc (fhandler_base::pread): Ditto.
(fhandler_base::pwrite): Ditto.
* syscalls.cc (pread): Define new function.
(pwrite): Ditto.
* cygwin.din: Export pread, pwrite.
* include/sys/ioctl.h: Guard some _IO* declarations to avoid conflict with
socket.h.
This commit is contained in:
Christopher Faylor 2005-07-29 17:04:46 +00:00
parent 728b9af5c9
commit 7d7d09aee8
8 changed files with 128 additions and 25 deletions

View File

@ -1,3 +1,20 @@
2005-07-29 Christopher Faylor <cgf@timesys.com>
* fhandler.h (fhandler_base::pread): Declare new function.
(fhandler_base::pwrite): Ditto.
(fhandler_disk_file::pread): Ditto.
(fhandler_disk_file::pwrite): Ditto.
* fhandler.cc (fhandler_base::pread): Define new function.
(fhandler_base::pwrite): Ditto.
* fhandler_disk_file.cc (fhandler_base::pread): Ditto.
(fhandler_base::pwrite): Ditto.
* syscalls.cc (pread): Define new function.
(pwrite): Ditto.
* cygwin.din: Export pread, pwrite.
* include/sys/ioctl.h: Guard some _IO* declarations to avoid conflict
with socket.h.
2005-07-29 Christopher Faylor <cgf@timesys.com>
* include/sys/ioctl.h: Add some linux defines.

View File

@ -348,6 +348,8 @@ rexec = cygwin_rexec SIGFE
rresvport = cygwin_rresvport SIGFE
_select = cygwin_select SIGFE
select = cygwin_select SIGFE
pread SIGFE
pwrite SIGFE
pselect SIGFE
send = cygwin_send SIGFE
sendmsg = cygwin_sendmsg SIGFE

View File

@ -1116,6 +1116,20 @@ fhandler_base::lseek (_off64_t offset, int whence)
return res;
}
ssize_t __stdcall
fhandler_base::pread (void *, size_t, _off64_t)
{
set_errno (ESPIPE);
return -1;
}
ssize_t __stdcall
fhandler_base::pwrite (void *, size_t, _off64_t)
{
set_errno (ESPIPE);
return -1;
}
int
fhandler_base::close ()
{

View File

@ -287,6 +287,8 @@ class fhandler_base
virtual int write (const void *ptr, size_t len);
virtual ssize_t readv (const struct iovec *, int iovcnt, ssize_t tot = -1);
virtual ssize_t writev (const struct iovec *, int iovcnt, ssize_t tot = -1);
virtual ssize_t __stdcall pread (void *, size_t, _off64_t) __attribute__ ((regparm (3)));
virtual ssize_t __stdcall pwrite (void *, size_t, _off64_t) __attribute__ ((regparm (3)));
virtual _off64_t lseek (_off64_t offset, int whence);
virtual int lock (int, struct __flock64 *);
virtual int dup (fhandler_base *child);
@ -673,6 +675,9 @@ class fhandler_disk_file: public fhandler_base
void seekdir (DIR *, _off64_t);
void rewinddir (DIR *);
int closedir (DIR *);
ssize_t __stdcall pread (void *, size_t, _off64_t) __attribute__ ((regparm (3)));
ssize_t __stdcall pwrite (void *, size_t, _off64_t) __attribute__ ((regparm (3)));
};
class fhandler_cygdrive: public fhandler_disk_file

View File

@ -984,6 +984,30 @@ fhandler_base::close_fs ()
return res;
}
ssize_t __stdcall
fhandler_disk_file::pread (void *buf, size_t count, _off64_t offset)
{
ssize_t res = lseek (offset, SEEK_SET);
if (res >= 0)
{
size_t tmp_count = count;
read (buf, tmp_count);
res = (ssize_t) tmp_count;
}
debug_printf ("%d = pread (%p, %d, %d)\n", res, buf, count, offset);
return res;
}
ssize_t __stdcall
fhandler_disk_file::pwrite (void *buf, size_t count, _off64_t offset)
{
ssize_t res = lseek (offset, SEEK_SET);
if (res >= 0)
res = write (buf, count);
debug_printf ("%d = pwrite (%p, %d, %d)\n", res, buf, count, offset);
return res;
}
/* FIXME: The correct way to do this to get POSIX locking semantics is to
keep a linked list of posix lock requests and map them into Win32 locks.
he problem is that Win32 does not deal correctly with overlapping lock

View File

@ -261,12 +261,13 @@ details. */
132: Add GLOB_LIMIT flag to glob.
133: Export __getline, __getdelim.
134: Export getline, getdelim.
135: Export pread, pwrite
*/
/* Note that we forgot to bump the api for ualarm, strtoll, strtoull */
#define CYGWIN_VERSION_API_MAJOR 0
#define CYGWIN_VERSION_API_MINOR 134
#define CYGWIN_VERSION_API_MINOR 135
/* There is also a compatibity version number associated with the
shared memory regions. It is incremented when incompatible

View File

@ -25,38 +25,44 @@ __BEGIN_DECLS
/* Some standard linux defines */
#define _IOC_NRBITS 8
#define _IOC_TYPEBITS 8
#define _IOC_SIZEBITS 14
#define _IOC_DIRBITS 2
#define _IOC_NRBITS 8
#define _IOC_TYPEBITS 8
#define _IOC_SIZEBITS 14
#define _IOC_DIRBITS 2
#define _IOC_NRMASK ((1 << _IOC_NRBITS)-1)
#define _IOC_TYPEMASK ((1 << _IOC_TYPEBITS)-1)
#define _IOC_SIZEMASK ((1 << _IOC_SIZEBITS)-1)
#define _IOC_DIRMASK ((1 << _IOC_DIRBITS)-1)
#define _IOC_NRMASK ((1 << _IOC_NRBITS)-1)
#define _IOC_TYPEMASK ((1 << _IOC_TYPEBITS)-1)
#define _IOC_SIZEMASK ((1 << _IOC_SIZEBITS)-1)
#define _IOC_DIRMASK ((1 << _IOC_DIRBITS)-1)
#define _IOC_NRSHIFT 0
#define _IOC_TYPESHIFT (_IOC_NRSHIFT+_IOC_NRBITS)
#define _IOC_SIZESHIFT (_IOC_TYPESHIFT+_IOC_TYPEBITS)
#define _IOC_DIRSHIFT (_IOC_SIZESHIFT+_IOC_SIZEBITS)
#define _IOC_NRSHIFT 0
#define _IOC_TYPESHIFT (_IOC_NRSHIFT+_IOC_NRBITS)
#define _IOC_SIZESHIFT (_IOC_TYPESHIFT+_IOC_TYPEBITS)
#define _IOC_DIRSHIFT (_IOC_SIZESHIFT+_IOC_SIZEBITS)
#define _IOC_NONE 0U
#define _IOC_WRITE 1U
#define _IOC_READ 2U
#define _IOC_NONE 0U
#define _IOC_WRITE 1U
#define _IOC_READ 2U
#define _IOC(dir,type,nr,size) \
(((dir) << _IOC_DIRSHIFT) | \
+ ((type) << _IOC_TYPESHIFT) | \
+ ((nr) << _IOC_NRSHIFT) | \
+ ((size) << _IOC_SIZESHIFT))
(((dir) << _IOC_DIRSHIFT) | \
+ ((type) << _IOC_TYPESHIFT) | \
+ ((nr) << _IOC_NRSHIFT) | \
+ ((size) << _IOC_SIZESHIFT))
#define _IO(type,nr) _IOC(_IOC_NONE,(type),(nr),0)
#define _IOR(type,nr,size) _IOC(_IOC_READ,(type),(nr),sizeof(size))
#define _IOW(type,nr,size) _IOC(_IOC_WRITE,(type),(nr),sizeof(size))
#define _IOWR(type,nr,size) _IOC(_IOC_READ|_IOC_WRITE,(type),(nr),sizeof(size))
#define _LINUX_IO(type,nr) _IOC(_IOC_NONE,(type),(nr),0)
#define _LINUX_IOR(type,nr,size) _IOC(_IOC_READ,(type),(nr),sizeof(size))
#define _LINUX_IOW(type,nr,size) _IOC(_IOC_WRITE,(type),(nr),sizeof(size))
#define _LINUX_IOWR(type,nr,size) _IOC(_IOC_READ|_IOC_WRITE,(type),(nr),sizeof(size))
#ifdef __USE_LINUX_IOCTL_DEFS
#define _IO _LINUX_IO
#define _IOR _LINUX_IOR
#define _IOW _LINUX_IOW
#define _IOWR _LINUX_IOWR
#endif /*__USE_LINUX_IOCTL_DEFS */
int __cdecl ioctl (int __fd, int __cmd, ...);
__END_DECLS
#endif

View File

@ -20,6 +20,8 @@ details. */
#define _open64 __FOO_open64__
#define _lseek64 __FOO_lseek64__
#define _fstat64 __FOO_fstat64__
#define pread __FOO_pread
#define pwrite __FOO_pwrite
#include "winsup.h"
#include <sys/stat.h>
@ -46,6 +48,8 @@ details. */
#undef fstat
#undef lstat
#undef stat
#undef pread
#undef pwrite
#include <cygwin/version.h>
#include <sys/cygwin.h>
@ -388,6 +392,36 @@ read (int fd, void *ptr, size_t len)
return readv (fd, &iov, 1);
}
extern "C" ssize_t
pread (int fd, void *ptr, size_t len, _off64_t off)
{
ssize_t res;
cygheap_fdget cfd (fd);
if (cfd < 0)
res = -1;
else
res = cfd->pread (ptr, len, off);
syscall_printf ("%d = pread (%d, %p, %d, %d), errno %d",
res, fd, ptr, len, off, get_errno ());
return res;
}
extern "C" ssize_t
pwrite (int fd, void *ptr, size_t len, _off64_t off)
{
ssize_t res;
cygheap_fdget cfd (fd);
if (cfd < 0)
res = -1;
else
res = cfd->pwrite (ptr, len, off);
syscall_printf ("%d = pwrite (%d, %p, %d, %d), errno %d",
res, fd, ptr, len, off, get_errno ());
return res;
}
EXPORT_ALIAS (read, _read)
extern "C" ssize_t