static NTSTATUS cmd_read(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, const char **argv) { int fd; size_t size, rsize; if (argc != 3) { printf("Usage: read <fd> <size>\n"); return NT_STATUS_OK; } /* do some error checking on these */ fd = atoi(argv[1]); size = atoi(argv[2]); vfs->data = (char *)talloc(mem_ctx, size); if (vfs->data == NULL) { printf("read: error=-1 (not enough memory)"); return NT_STATUS_UNSUCCESSFUL; } vfs->data_size = size; rsize = SMB_VFS_READ(vfs->files[fd], fd, vfs->data, size); if (rsize == -1) { printf("read: error=%d (%s)\n", errno, strerror(errno)); return NT_STATUS_UNSUCCESSFUL; } printf("read: ok\n"); return NT_STATUS_OK; }
ssize_t vfswrap_pread(vfs_handle_struct *handle, files_struct *fsp, int fd, void *data, size_t n, SMB_OFF_T offset) { ssize_t result; #if defined(HAVE_PREAD) || defined(HAVE_PREAD64) START_PROFILE_BYTES(syscall_pread, n); result = sys_pread(fd, data, n, offset); END_PROFILE(syscall_pread); if (result == -1 && errno == ESPIPE) { /* Maintain the fiction that pipes can be seeked (sought?) on. */ result = SMB_VFS_READ(fsp, fd, data, n); fsp->fh->pos = 0; } #else /* HAVE_PREAD */ SMB_OFF_T curr; int lerrno; curr = SMB_VFS_LSEEK(fsp, fd, 0, SEEK_CUR); if (curr == -1 && errno == ESPIPE) { /* Maintain the fiction that pipes can be seeked (sought?) on. */ result = SMB_VFS_READ(fsp, fd, data, n); fsp->fh->pos = 0; return result; } if (SMB_VFS_LSEEK(fsp, fd, offset, SEEK_SET) == -1) { return -1; } errno = 0; result = SMB_VFS_READ(fsp, fd, data, n); lerrno = errno; SMB_VFS_LSEEK(fsp, fd, curr, SEEK_SET); errno = lerrno; #endif /* HAVE_PREAD */ return result; }
ssize_t vfs_read_data(files_struct *fsp, char *buf, size_t byte_count) { size_t total=0; while (total < byte_count) { ssize_t ret = SMB_VFS_READ(fsp, fsp->fh->fd, buf + total, byte_count - total); if (ret == 0) return total; if (ret == -1) { if (errno == EINTR) continue; else return -1; } total += ret; } return (ssize_t)total; }