r2751: this is a new ntvfs design which tries to solve:
[samba.git] / source4 / ntvfs / posix / pvfs_read.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    POSIX NTVFS backend - read
5
6    Copyright (C) Andrew Tridgell 2004
7
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.
12    
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.
17    
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.
21 */
22
23 #include "include/includes.h"
24 #include "vfs_posix.h"
25
26 /*
27   read from a file
28 */
29 NTSTATUS pvfs_read(struct ntvfs_module_context *ntvfs,
30                    struct smbsrv_request *req, union smb_read *rd)
31 {
32         struct pvfs_state *pvfs = ntvfs->private_data;
33         ssize_t ret;
34         struct pvfs_file *f;
35
36         if (rd->generic.level != RAW_READ_READX) {
37                 return NT_STATUS_NOT_SUPPORTED;
38         }
39
40
41         f = pvfs_find_fd(pvfs, req, rd->readx.in.fnum);
42         if (!f) {
43                 return NT_STATUS_INVALID_HANDLE;
44         }
45
46         ret = pread(f->fd, 
47                     rd->readx.out.data, 
48                     rd->readx.in.maxcnt,
49                     rd->readx.in.offset);
50         if (ret == -1) {
51                 return pvfs_map_errno(pvfs, errno);
52         }
53
54         rd->readx.out.nread = ret;
55         rd->readx.out.remaining = 0; /* should fill this in? */
56         rd->readx.out.compaction_mode = 0; 
57
58         return NT_STATUS_OK;
59 }