From 9047bf59b402de40e520bfc2afa1cbfad5508f72 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 5 Oct 1998 02:31:39 +0000 Subject: [PATCH] - added pread pread64 pwrite pwrite64 and open64 - fixed utime() for null tbuf --- source/smbwrapper/realcalls.h | 31 ++++++++++++++++++ source/smbwrapper/smbw.c | 74 +++++++++++++++++++++++++++++++++++++++++-- source/smbwrapper/wrapped.c | 60 +++++++++++++++++++++++++++++++++++ 3 files changed, 162 insertions(+), 3 deletions(-) diff --git a/source/smbwrapper/realcalls.h b/source/smbwrapper/realcalls.h index 9017db3f0a9..9a13ab9300d 100644 --- a/source/smbwrapper/realcalls.h +++ b/source/smbwrapper/realcalls.h @@ -177,6 +177,37 @@ #endif +#ifdef HAVE__OPEN64 +#define real_open64(fn,fl,m) (_open64(fn,fl,m)) +#elif HAVE___OPEN64 +#define real_open64(fn,fl,m) (__open64(fn,fl,m)) +#endif + +#ifdef HAVE__PREAD +#define real_pread(fd,buf,size,ofs) (_pread(fd,buf,size,ofs)) +#elif HAVE___PREAD +#define real_pread(fd,buf,size,ofs) (__pread(fd,buf,size,ofs)) +#endif + +#ifdef HAVE__PREAD64 +#define real_pread64(fd,buf,size,ofs) (_pread64(fd,buf,size,ofs)) +#elif HAVE___PREAD64 +#define real_pread64(fd,buf,size,ofs) (__pread64(fd,buf,size,ofs)) +#endif + +#ifdef HAVE__PWRITE +#define real_pwrite(fd,buf,size,ofs) (_pwrite(fd,buf,size,ofs)) +#elif HAVE___PWRITE +#define real_pwrite(fd,buf,size,ofs) (__pwrite(fd,buf,size,ofs)) +#endif + +#ifdef HAVE__PWRITE64 +#define real_pwrite64(fd,buf,size,ofs) (_pwrite64(fd,buf,size,ofs)) +#elif HAVE___PWRITE64 +#define real_pwrite64(fd,buf,size,ofs) (__pwrite64(fd,buf,size,ofs)) +#endif + + #define real_readlink(fn,buf,len) (syscall(SYS_readlink, (fn), (buf), (len))) #define real_rename(fn1, fn2) (syscall(SYS_rename, (fn1), (fn2))) #define real_symlink(fn1, fn2) (syscall(SYS_symlink, (fn1), (fn2))) diff --git a/source/smbwrapper/smbw.c b/source/smbwrapper/smbw.c index 633e63ef8d5..dbc4e2ddd9b 100644 --- a/source/smbwrapper/smbw.c +++ b/source/smbwrapper/smbw.c @@ -607,6 +607,38 @@ int smbw_open(const char *fname, int flags, mode_t mode) /***************************************************** +a wrapper for pread() +*******************************************************/ +ssize_t smbw_pread(int fd, void *buf, size_t count, off_t ofs) +{ + struct smbw_file *file; + int ret; + + DEBUG(4,("%s %d\n", + __FUNCTION__, (int)count)); + + smbw_busy++; + + file = smbw_file(fd); + if (!file) { + errno = EBADF; + smbw_busy--; + return -1; + } + + ret = cli_read(&file->srv->cli, file->f->cli_fd, buf, ofs, count); + + if (ret == -1) { + errno = smbw_errno(&file->srv->cli); + smbw_busy--; + return -1; + } + + smbw_busy--; + return ret; +} + +/***************************************************** a wrapper for read() *******************************************************/ ssize_t smbw_read(int fd, void *buf, size_t count) @@ -626,7 +658,8 @@ ssize_t smbw_read(int fd, void *buf, size_t count) return -1; } - ret = cli_read(&file->srv->cli, file->f->cli_fd, buf, file->f->offset, count); + ret = cli_read(&file->srv->cli, file->f->cli_fd, buf, + file->f->offset, count); if (ret == -1) { errno = smbw_errno(&file->srv->cli); @@ -640,6 +673,8 @@ ssize_t smbw_read(int fd, void *buf, size_t count) return ret; } + + /***************************************************** a wrapper for write() *******************************************************/ @@ -675,6 +710,38 @@ ssize_t smbw_write(int fd, void *buf, size_t count) } /***************************************************** +a wrapper for pwrite() +*******************************************************/ +ssize_t smbw_pwrite(int fd, void *buf, size_t count, off_t ofs) +{ + struct smbw_file *file; + int ret; + + DEBUG(4,("%s\n", __FUNCTION__)); + + smbw_busy++; + + file = smbw_file(fd); + if (!file) { + DEBUG(3,("bad fd in read\n")); + errno = EBADF; + smbw_busy--; + return -1; + } + + ret = cli_write(&file->srv->cli, file->f->cli_fd, buf, ofs, count); + + if (ret == -1) { + errno = smbw_errno(&file->srv->cli); + smbw_busy--; + return -1; + } + + smbw_busy--; + return ret; +} + +/***************************************************** a wrapper for close() *******************************************************/ int smbw_close(int fd) @@ -877,7 +944,7 @@ int smbw_utime(const char *fname, void *buf) pstring path; uint32 mode; - DEBUG(4,("%s (%s)\n", __FUNCTION__, fname)); + DEBUG(4,("%s (%s, 0x%x)\n", __FUNCTION__, fname, (unsigned)buf)); if (!fname) { errno = EINVAL; @@ -903,7 +970,8 @@ int smbw_utime(const char *fname, void *buf) goto failed; } - if (!cli_setatr(&srv->cli, path, mode, tbuf->modtime)) { + if (!cli_setatr(&srv->cli, path, mode, + tbuf?tbuf->modtime:time(NULL))) { errno = smbw_errno(&srv->cli); goto failed; } diff --git a/source/smbwrapper/wrapped.c b/source/smbwrapper/wrapped.c index 422f3abbf52..025bbcc2db8 100644 --- a/source/smbwrapper/wrapped.c +++ b/source/smbwrapper/wrapped.c @@ -37,6 +37,61 @@ __asm__(".globl __open; __open = open"); return real_open(name, flags, mode); } +#ifdef HAVE_OPEN64 + int open64(const char *name, int flags, mode_t mode) +{ + if (smbw_path(name)) { + return smbw_open(name, flags, mode); + } + + return real_open64(name, flags, mode); +} +#endif + +#ifdef HAVE_PREAD + ssize_t pread(int fd, void *buf, size_t size, off_t ofs) +{ + if (smbw_fd(fd)) { + return smbw_pread(fd, buf, size, ofs); + } + + return real_pread(fd, buf, size, ofs); +} +#endif + +#ifdef HAVE_PREAD64 + ssize_t pread64(int fd, void *buf, size_t size, off64_t ofs) +{ + if (smbw_fd(fd)) { + return smbw_pread(fd, buf, size, ofs); + } + + return real_pread64(fd, buf, size, ofs); +} +#endif + +#ifdef HAVE_PWRITE + ssize_t pwrite(int fd, void *buf, size_t size, off_t ofs) +{ + if (smbw_fd(fd)) { + return smbw_pwrite(fd, buf, size, ofs); + } + + return real_pwrite(fd, buf, size, ofs); +} +#endif + +#ifdef HAVE_PWRITE64 + ssize_t pwrite64(int fd, void *buf, size_t size, off64_t ofs) +{ + if (smbw_fd(fd)) { + return smbw_pwrite(fd, buf, size, ofs); + } + + return real_pwrite64(fd, buf, size, ofs); +} +#endif + #ifdef HAVE___CHDIR __asm__(".globl __chdir; __chdir = chdir"); @@ -628,6 +683,11 @@ __asm__(".globl _write; _write = write"); { return open(path, O_WRONLY|O_CREAT|O_TRUNC, mode); } + + int creat64(const char *path, mode_t mode) +{ + return open64(path, O_WRONLY|O_CREAT|O_TRUNC, mode); +} #endif #ifdef HAVE_STAT64 -- 2.11.4.GIT