From 56f70fa76186e99d067380fb71530ec259365ba6 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Thu, 7 May 2015 09:20:44 +0200 Subject: printing more open flags. hadling of O_CREAT and O_EXCL --- pgfuse.c | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) (limited to 'pgfuse.c') diff --git a/pgfuse.c b/pgfuse.c index 553e9e4..f41e6b7 100644 --- a/pgfuse.c +++ b/pgfuse.c @@ -274,12 +274,15 @@ static char *flags_to_string( int flags ) s = (char *)malloc( 100 ); if( s == NULL ) return ""; - snprintf( s, 100, "access_mode=%s, flags=%s%s%s%s", + snprintf( s, 100, "access_mode=%s, flags=%s%s%s%s%s%s%s", mode_s, ( flags & O_CREAT ) ? "O_CREAT " : "", ( flags & O_TRUNC ) ? "O_TRUNC " : "", ( flags & O_EXCL ) ? "O_EXCL " : "", - ( flags & O_APPEND ) ? "O_APPEND " : ""); + ( flags & O_NOFOLLOW ) ? "O_NOFOLLOW " : "", + ( flags & O_CLOEXEC ) ? "O_CLOEXEC " : "", + ( flags & O_DIRECTORY ) ? "O_DIRECTORY " : "", + ( flags & O_APPEND ) ? "O_APPEND " : "" ); return s; } @@ -323,13 +326,29 @@ static int pgfuse_create( const char *path, mode_t mode, struct fuse_file_info * path, id, THREAD_ID ); } - if( S_ISDIR(meta.mode ) ) { + if( S_ISDIR( meta.mode ) ) { PSQL_ROLLBACK( conn ); RELEASE( conn ); return -EISDIR; } + + if( ( fi->flags & O_CREAT ) && (fi->flags & O_EXCL ) ) { + PSQL_ROLLBACK( conn ); RELEASE( conn ); + return -EEXIST; + } + + res = psql_truncate( conn, data->block_size, id, path, 0 ); + if( res < 0 ) { + PSQL_ROLLBACK( conn ); RELEASE( conn ); + return res; + } + + meta.size = 0; + res = psql_write_meta( conn, id, path, meta ); + if( res < 0 ) { + PSQL_ROLLBACK( conn ); RELEASE( conn ); + return res; + } - PSQL_ROLLBACK( conn ); RELEASE( conn ); - return -EEXIST; } copy_path = strdup( path ); -- cgit v1.2.3-54-g00ecf