2004-10-24 18:18:03 +04:00
/*
Unix SMB / CIFS implementation .
POSIX NTVFS backend - seek
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
2007-07-10 06:07:03 +04:00
the Free Software Foundation ; either version 3 of the License , or
2004-10-24 18:18:03 +04:00
( 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
2007-07-10 06:07:03 +04:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2004-10-24 18:18:03 +04:00
*/
2004-11-05 10:24:25 +03:00
# include "includes.h"
2004-10-24 18:18:03 +04:00
# include "vfs_posix.h"
/*
seek in a file
*/
NTSTATUS pvfs_seek ( struct ntvfs_module_context * ntvfs ,
2006-03-10 23:49:20 +03:00
struct ntvfs_request * req ,
union smb_seek * io )
2004-10-24 18:18:03 +04:00
{
2009-02-04 10:52:41 +03:00
struct pvfs_state * pvfs = talloc_get_type ( ntvfs - > private_data ,
struct pvfs_state ) ;
2004-10-24 18:18:03 +04:00
struct pvfs_file * f ;
2004-11-08 06:54:12 +03:00
struct pvfs_file_handle * h ;
2004-10-24 18:18:03 +04:00
NTSTATUS status ;
2006-05-20 12:15:22 +04:00
f = pvfs_find_fd ( pvfs , req , io - > lseek . in . file . ntvfs ) ;
2004-10-24 18:18:03 +04:00
if ( ! f ) {
return NT_STATUS_INVALID_HANDLE ;
}
2004-11-08 06:54:12 +03:00
h = f - > handle ;
2004-10-24 18:18:03 +04:00
status = NT_STATUS_OK ;
2006-03-10 23:49:20 +03:00
switch ( io - > lseek . in . mode ) {
2004-10-24 18:18:03 +04:00
case SEEK_MODE_START :
2006-03-10 23:49:20 +03:00
h - > seek_offset = io - > lseek . in . offset ;
2004-10-24 18:18:03 +04:00
break ;
case SEEK_MODE_CURRENT :
2006-03-10 23:49:20 +03:00
h - > seek_offset + = io - > lseek . in . offset ;
2004-10-24 18:18:03 +04:00
break ;
case SEEK_MODE_END :
2008-05-05 14:18:47 +04:00
status = pvfs_resolve_name_fd ( pvfs , h - > fd , h - > name , PVFS_RESOLVE_NO_OPENDB ) ;
2006-03-10 23:49:20 +03:00
h - > seek_offset = h - > name - > st . st_size + io - > lseek . in . offset ;
2004-10-24 18:18:03 +04:00
break ;
}
2006-03-10 23:49:20 +03:00
io - > lseek . out . offset = h - > seek_offset ;
2004-10-24 18:18:03 +04:00
return status ;
}