2 Unix SMB/CIFS implementation.
4 POSIX NTVFS backend - read
6 Copyright (C) Andrew Tridgell 2004
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include "vfs_posix.h"
25 #include "librpc/gen_ndr/ndr_security.h"
30 NTSTATUS pvfs_read(struct ntvfs_module_context *ntvfs,
31 struct ntvfs_request *req, union smb_read *rd)
33 struct pvfs_state *pvfs = ntvfs->private_data;
40 if (rd->generic.level != RAW_READ_READX) {
41 return ntvfs_map_read(ntvfs, req, rd);
44 f = pvfs_find_fd(pvfs, req, rd->readx.file.fnum);
46 return NT_STATUS_INVALID_HANDLE;
49 if (f->handle->fd == -1) {
50 return NT_STATUS_FILE_IS_A_DIRECTORY;
53 mask = SEC_FILE_READ_DATA;
54 if (req->flags2 & FLAGS2_READ_PERMIT_EXECUTE) {
55 mask |= SEC_FILE_EXECUTE;
57 if (!(f->access_mask & mask)) {
58 return NT_STATUS_ACCESS_DENIED;
61 maxcnt = rd->readx.in.maxcnt;
62 if (maxcnt > UINT16_MAX) {
66 status = pvfs_check_lock(pvfs, f, req->smbpid,
70 if (!NT_STATUS_IS_OK(status)) {
74 if (f->handle->name->stream_name) {
75 ret = pvfs_stream_read(pvfs, f->handle,
76 rd->readx.out.data, maxcnt, rd->readx.in.offset);
78 ret = pread(f->handle->fd,
84 return pvfs_map_errno(pvfs, errno);
87 f->handle->position = f->handle->seek_offset = rd->readx.in.offset + ret;
89 rd->readx.out.nread = ret;
90 rd->readx.out.remaining = 0xFFFF;
91 rd->readx.out.compaction_mode = 0;