2004-10-13 02:18:02 +04:00
/*
Unix SMB / CIFS implementation .
POSIX NTVFS backend - flush
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-13 02:18:02 +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-13 02:18:02 +04:00
*/
2004-11-05 10:24:25 +03:00
# include "includes.h"
2004-10-13 02:18:02 +04:00
# include "vfs_posix.h"
/*
flush a single open file
*/
static void pvfs_flush_file ( struct pvfs_state * pvfs , struct pvfs_file * f )
{
2004-11-10 15:40:33 +03:00
if ( f - > handle - > fd = = - 1 ) {
2004-10-29 08:43:28 +04:00
return ;
}
2004-10-13 02:18:02 +04:00
if ( pvfs - > flags & PVFS_FLAG_STRICT_SYNC ) {
2004-11-08 06:54:12 +03:00
fsync ( f - > handle - > fd ) ;
2004-10-13 02:18:02 +04:00
}
}
/*
flush a fnum
*/
NTSTATUS pvfs_flush ( struct ntvfs_module_context * ntvfs ,
2006-03-10 23:49:20 +03:00
struct ntvfs_request * req ,
union smb_flush * io )
2004-10-13 02:18:02 +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-13 02:18:02 +04:00
struct pvfs_file * f ;
2006-05-19 19:10:39 +04:00
switch ( io - > generic . level ) {
case RAW_FLUSH_FLUSH :
2006-05-20 22:57:32 +04:00
case RAW_FLUSH_SMB2 :
/* TODO: take care of io->smb2.in.unknown */
f = pvfs_find_fd ( pvfs , req , io - > generic . in . file . ntvfs ) ;
2004-10-13 02:18:02 +04:00
if ( ! f ) {
return NT_STATUS_INVALID_HANDLE ;
}
pvfs_flush_file ( pvfs , f ) ;
2008-05-26 09:00:27 +04:00
io - > smb2 . out . reserved = 0 ;
2004-10-13 02:18:02 +04:00
return NT_STATUS_OK ;
2006-05-19 19:10:39 +04:00
case RAW_FLUSH_ALL :
if ( ! ( pvfs - > flags & PVFS_FLAG_STRICT_SYNC ) ) {
return NT_STATUS_OK ;
}
2004-10-13 02:18:02 +04:00
2006-08-01 14:11:37 +04:00
/*
* they are asking to flush all open files
* for the given SMBPID
*/
2006-05-19 19:10:39 +04:00
for ( f = pvfs - > files . list ; f ; f = f - > next ) {
2006-08-01 14:58:01 +04:00
if ( f - > ntvfs - > smbpid ! = req - > smbpid ) continue ;
2006-08-01 14:11:37 +04:00
2006-05-19 19:10:39 +04:00
pvfs_flush_file ( pvfs , f ) ;
}
return NT_STATUS_OK ;
2004-10-13 02:18:02 +04:00
}
2006-05-19 19:10:39 +04:00
return NT_STATUS_INVALID_LEVEL ;
2004-10-13 02:18:02 +04:00
}