2004-09-20 11:28:43 +04:00
/*
Unix SMB / CIFS implementation .
POSIX NTVFS backend - read
Copyright ( C ) Andrew Tridgell 2004
This program is free software ; you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation ; either version 2 of the License , or
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
along with this program ; if not , write to the Free Software
Foundation , Inc . , 675 Mass Ave , Cambridge , MA 0213 9 , USA .
*/
# include "include/includes.h"
# include "vfs_posix.h"
/*
read from a file
*/
2004-09-29 17:17:09 +04:00
NTSTATUS pvfs_read ( struct ntvfs_module_context * ntvfs ,
struct smbsrv_request * req , union smb_read * rd )
2004-09-20 11:28:43 +04:00
{
2004-09-29 17:17:09 +04:00
struct pvfs_state * pvfs = ntvfs - > private_data ;
2004-09-20 11:28:43 +04:00
ssize_t ret ;
struct pvfs_file * f ;
2004-10-17 06:55:47 +04:00
NTSTATUS status ;
2004-10-26 10:17:52 +04:00
uint32_t maxcnt ;
2004-10-30 09:53:56 +04:00
uint32_t mask ;
2004-09-20 11:28:43 +04:00
if ( rd - > generic . level ! = RAW_READ_READX ) {
r3081: several updates to ntvfs and server side async request handling in
preparation for the full share modes and ntcreatex code that I am
working on.
highlights include:
- changed the way a backend determines if it is allowed to process a
request asynchronously. The previous method of looking at the
send_fn caused problems when an intermediate ntvfs module disabled
it, and the caller then wanted to finished processing using this
function. The new method is a REQ_CONTROL_MAY_ASYNC flag in
req->control_flags, which is also a bit easier to read
- fixed 2 bugs in the readbraw server code. One related to trying to
answer a readbraw with smb signing (which can't work, and crashed
our signing code), the second related to error handling, which
attempted to send a normal SMB error packet, when readbraw must
send a 0 read reply (as it has no header)
- added several more ntvfs_generic.c generic mapping functions. This
means that backends no longer need to implement such esoteric
functions as SMBwriteunlock() if they don't want to. The backend
can just request the mapping layer turn it into a write followed by
an unlock. This makes the backends considerably simpler as they
only need to implement one style of each function for lock, read,
write, open etc, rather than the full host of functions that SMB
provides. A backend can still choose to implement them
individually, of course, and the CIFS backend does that.
- simplified the generic structures to make them identical to the
principal call for several common SMB calls (such as
RAW_WRITE_GENERIC now being an alias for RAW_WRITE_WRITEX).
- started rewriting the pvfs_open() code in preparation for the full
ntcreatex semantics.
- in pvfs_open and ipc_open, initially allocate the open file
structure as a child of the request, so on error we don't need to
clean up. Then when we are going to succeed the open steal the
pointer into the long term backend context. This makes for much
simpler error handling (and fixes some bugs)
- use a destructor in the ipc backend to make sure that everthing is
cleaned up on receive error conditions.
- switched the ipc backend to using idtree for fnum allocation
- in the ntvfs_generic mapping routines, use a allocated secondary
structure not a stack structure to ensure the request pointer
remains valid even if the backend replies async.
(This used to be commit 3457c1836c09c82956697eb21627dfa2ed37682e)
2004-10-20 12:28:31 +04:00
return ntvfs_map_read ( req , rd , ntvfs ) ;
2004-09-20 11:28:43 +04:00
}
2004-09-29 17:17:09 +04:00
f = pvfs_find_fd ( pvfs , req , rd - > readx . in . fnum ) ;
2004-09-20 11:28:43 +04:00
if ( ! f ) {
return NT_STATUS_INVALID_HANDLE ;
}
r3081: several updates to ntvfs and server side async request handling in
preparation for the full share modes and ntcreatex code that I am
working on.
highlights include:
- changed the way a backend determines if it is allowed to process a
request asynchronously. The previous method of looking at the
send_fn caused problems when an intermediate ntvfs module disabled
it, and the caller then wanted to finished processing using this
function. The new method is a REQ_CONTROL_MAY_ASYNC flag in
req->control_flags, which is also a bit easier to read
- fixed 2 bugs in the readbraw server code. One related to trying to
answer a readbraw with smb signing (which can't work, and crashed
our signing code), the second related to error handling, which
attempted to send a normal SMB error packet, when readbraw must
send a 0 read reply (as it has no header)
- added several more ntvfs_generic.c generic mapping functions. This
means that backends no longer need to implement such esoteric
functions as SMBwriteunlock() if they don't want to. The backend
can just request the mapping layer turn it into a write followed by
an unlock. This makes the backends considerably simpler as they
only need to implement one style of each function for lock, read,
write, open etc, rather than the full host of functions that SMB
provides. A backend can still choose to implement them
individually, of course, and the CIFS backend does that.
- simplified the generic structures to make them identical to the
principal call for several common SMB calls (such as
RAW_WRITE_GENERIC now being an alias for RAW_WRITE_WRITEX).
- started rewriting the pvfs_open() code in preparation for the full
ntcreatex semantics.
- in pvfs_open and ipc_open, initially allocate the open file
structure as a child of the request, so on error we don't need to
clean up. Then when we are going to succeed the open steal the
pointer into the long term backend context. This makes for much
simpler error handling (and fixes some bugs)
- use a destructor in the ipc backend to make sure that everthing is
cleaned up on receive error conditions.
- switched the ipc backend to using idtree for fnum allocation
- in the ntvfs_generic mapping routines, use a allocated secondary
structure not a stack structure to ensure the request pointer
remains valid even if the backend replies async.
(This used to be commit 3457c1836c09c82956697eb21627dfa2ed37682e)
2004-10-20 12:28:31 +04:00
if ( f - > name - > dos . attrib & FILE_ATTRIBUTE_DIRECTORY ) {
return NT_STATUS_FILE_IS_A_DIRECTORY ;
}
2004-10-30 09:53:56 +04:00
mask = SA_RIGHT_FILE_READ_DATA ;
if ( req - > flags2 & FLAGS2_READ_PERMIT_EXECUTE ) {
mask | = SA_RIGHT_FILE_EXECUTE ;
}
if ( ! ( f - > access_mask & mask ) ) {
return NT_STATUS_ACCESS_DENIED ;
2004-10-24 12:31:41 +04:00
}
2004-10-26 10:17:52 +04:00
maxcnt = rd - > readx . in . maxcnt ;
if ( maxcnt > UINT16_MAX ) {
maxcnt = 0 ;
2004-10-26 09:39:54 +04:00
}
2004-10-26 10:17:52 +04:00
2004-10-17 06:55:47 +04:00
status = pvfs_check_lock ( pvfs , f , req - > smbpid ,
rd - > readx . in . offset ,
2004-10-26 10:17:52 +04:00
maxcnt ,
2004-10-17 06:55:47 +04:00
READ_LOCK ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return status ;
}
2004-09-20 11:28:43 +04:00
ret = pread ( f - > fd ,
rd - > readx . out . data ,
2004-10-26 10:17:52 +04:00
maxcnt ,
2004-09-20 11:28:43 +04:00
rd - > readx . in . offset ) ;
if ( ret = = - 1 ) {
return pvfs_map_errno ( pvfs , errno ) ;
}
2004-10-24 18:18:03 +04:00
f - > position = f - > seek_offset = rd - > readx . in . offset + ret ;
2004-09-20 11:28:43 +04:00
rd - > readx . out . nread = ret ;
2004-10-26 09:39:54 +04:00
rd - > readx . out . remaining = 0xFFFF ;
2004-09-20 11:28:43 +04:00
rd - > readx . out . compaction_mode = 0 ;
return NT_STATUS_OK ;
}