asmlinkage ssize_t sys_pwrite_wrapper(unsigned int fd, const char * buf, size_t count, long dummy, loff_t pos) { extern asmlinkage ssize_t sys_pwrite(unsigned int fd, const char * buf, size_t count, loff_t pos); return sys_pwrite(fd, buf, count, pos); }
int svr4_sys_pwrite64(struct lwp *l, const struct svr4_sys_pwrite64_args *uap, register_t *retval) { struct sys_pwrite_args pwa; /* * Just translate the args structure and call the NetBSD * pwrite(2) system call (offset type is 64-bit in NetBSD). */ SCARG(&pwa, fd) = SCARG(uap, fd); SCARG(&pwa, buf) = SCARG(uap, buf); SCARG(&pwa, nbyte) = SCARG(uap, nbyte); SCARG(&pwa, offset) = SCARG(uap, off); return (sys_pwrite(l, &pwa, retval)); }
static struct tevent_req *aio_posix_pwrite_send( struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx, struct tevent_context *ev, struct files_struct *fsp, const void *data, size_t n, off_t offset) { struct tevent_req *req; struct aio_posix_state *state; struct aiocb *a; int ret; req = tevent_req_create(mem_ctx, &state, struct aio_posix_state); if (req == NULL) { return NULL; } a = &state->acb; a->aio_fildes = fsp->fh->fd; a->aio_buf = discard_const(data); a->aio_nbytes = n; a->aio_offset = offset; a->aio_sigevent.sigev_notify = SIGEV_SIGNAL; a->aio_sigevent.sigev_signo = RT_SIGNAL_AIO; a->aio_sigevent.sigev_value.sival_ptr = req; ret = aio_write(a); if (ret == 0) { talloc_set_destructor(state, aio_posix_state_destructor); return req; } if (errno == EAGAIN) { /* * aio overloaded, do the sync fallback */ state->ret = sys_pwrite(fsp->fh->fd, data, n, offset); if (state->ret == -1) { state->err = errno; } tevent_req_done(req); return tevent_req_post(req, ev); } tevent_req_error(req, errno); return tevent_req_post(req, ev); }
/* * pwrite(2). */ int linux_sys_pwrite(struct lwp *l, const struct linux_sys_pwrite_args *uap, register_t *retval) { /* { syscallarg(int) fd; syscallarg(void *) buf; syscallarg(size_t) nbyte; syscallarg(off_t) offset; } */ struct sys_pwrite_args pra; SCARG(&pra, fd) = SCARG(uap, fd); SCARG(&pra, buf) = SCARG(uap, buf); SCARG(&pra, nbyte) = SCARG(uap, nbyte); SCARG(&pra, PAD) = 0; SCARG(&pra, offset) = SCARG(uap, offset); return sys_pwrite(l, &pra, retval); }
int main() { char* buf; size_t buflen = 4096; char* data = "aaaaaaaaaaaaaaaaaaaa"; int datalen = strlen(data); int fd; ssize_t got; err_t err; buf = malloc(buflen); assert(buf); // open file fd = open("tmp.data", O_RDWR | O_CREAT, S_IRWXU); assert(fd>=0); // copy data to buf memset(buf, 0, buflen); memcpy(buf, data, datalen); // write data err = sys_pwrite(fd, buf, datalen, 0, &got); assert(!err); assert(got == datalen); // clear buf memset(buf, 0, buflen); // read data err = sys_pread(fd, buf, buflen, 0, &got); assert(!err); assert(got == datalen); // check data assert(0 == memcmp(data, buf, datalen)); close(fd); unlink("tmp.data"); printf("OK\n"); return 0; }
ssize_t vfswrap_pwrite(vfs_handle_struct *handle, files_struct *fsp, int fd, const void *data, size_t n, SMB_OFF_T offset) { ssize_t result; #if defined(HAVE_PWRITE) || defined(HAVE_PRWITE64) START_PROFILE_BYTES(syscall_pwrite, n); result = sys_pwrite(fd, data, n, offset); END_PROFILE(syscall_pwrite); if (result == -1 && errno == ESPIPE) { /* Maintain the fiction that pipes can be sought on. */ result = SMB_VFS_WRITE(fsp, fd, data, n); } #else /* HAVE_PWRITE */ SMB_OFF_T curr; int lerrno; curr = SMB_VFS_LSEEK(fsp, fd, 0, SEEK_CUR); if (curr == -1) { return -1; } if (SMB_VFS_LSEEK(fsp, fd, offset, SEEK_SET) == -1) { return -1; } result = SMB_VFS_WRITE(fsp, fd, data, n); lerrno = errno; SMB_VFS_LSEEK(fsp, fd, curr, SEEK_SET); errno = lerrno; #endif /* HAVE_PWRITE */ return result; }
static void aio_worker(void *private_data) { struct aio_private_data *pd = (struct aio_private_data *)private_data; if (pd->write_command) { pd->ret_size = sys_pwrite(pd->aiocb->aio_fildes, (const void *)pd->aiocb->aio_buf, pd->aiocb->aio_nbytes, pd->aiocb->aio_offset); if (pd->ret_size == -1 && errno == ESPIPE) { /* Maintain the fiction that pipes can be seeked (sought?) on. */ pd->ret_size = sys_write(pd->aiocb->aio_fildes, (const void *)pd->aiocb->aio_buf, pd->aiocb->aio_nbytes); } } else { pd->ret_size = sys_pread(pd->aiocb->aio_fildes, (void *)pd->aiocb->aio_buf, pd->aiocb->aio_nbytes, pd->aiocb->aio_offset); if (pd->ret_size == -1 && errno == ESPIPE) { /* Maintain the fiction that pipes can be seeked (sought?) on. */ pd->ret_size = sys_read(pd->aiocb->aio_fildes, (void *)pd->aiocb->aio_buf, pd->aiocb->aio_nbytes); } } if (pd->ret_size == -1) { pd->ret_errno = errno; } else { pd->ret_errno = 0; } }