summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2015-05-10 09:55:06 +0200
committerAndreas Baumann <mail@andreasbaumann.cc>2015-05-10 09:55:06 +0200
commit3238ae0a854981637b77ad75ce3aa660d61ed584 (patch)
treeecda70432e2376de9aadf54a2735ea18043e912e
parent922c92704c7ad1e10f4f4d30982857915268a957 (diff)
downloadpgfuse-3238ae0a854981637b77ad75ce3aa660d61ed584.tar.gz
pgfuse-3238ae0a854981637b77ad75ce3aa660d61ed584.tar.bz2
eliminated duplicate code in getattr/fgetattr (root cause for times not being set in fgetattr)
-rw-r--r--pgfuse.c54
1 files changed, 23 insertions, 31 deletions
diff --git a/pgfuse.c b/pgfuse.c
index 562d6f2..289d830 100644
--- a/pgfuse.c
+++ b/pgfuse.c
@@ -154,6 +154,24 @@ static void pgfuse_destroy( void *userdata )
}
}
+static void convert_meta_to_stbuf( struct stat *stbuf, PgMeta *meta, PgFuseData *data, int64_t id )
+{
+ /* TODO: check bits of inodes of the kernel */
+ stbuf->st_ino = id;
+ stbuf->st_blocks = 0;
+ stbuf->st_mode = meta->mode;
+ stbuf->st_size = meta->size;
+ stbuf->st_blksize = data->block_size;
+ stbuf->st_blocks = ( meta->size + data->block_size - 1 ) / data->block_size;
+ /* TODO: set correctly from table */
+ stbuf->st_nlink = 1;
+ stbuf->st_uid = meta->uid;
+ stbuf->st_gid = meta->gid;
+ stbuf->st_atime = meta->atime.tv_sec;
+ stbuf->st_mtime = meta->mtime.tv_sec;
+ stbuf->st_ctime = meta->ctime.tv_sec;
+}
+
static int pgfuse_fgetattr( const char *path, struct stat *stbuf, struct fuse_file_info *fi )
{
PgFuseData *data = (PgFuseData *)fuse_get_context( )->private_data;
@@ -182,22 +200,9 @@ static int pgfuse_fgetattr( const char *path, struct stat *stbuf, struct fuse_fi
S_ISDIR( meta.mode ) ? "dir" : "file", path, id,
THREAD_ID );
}
-
- /* TODO: check bits of inodes of the kernel */
- stbuf->st_ino = id;
- stbuf->st_blocks = 0;
- stbuf->st_mode = meta.mode;
- stbuf->st_size = meta.size;
- stbuf->st_blksize = data->block_size;
- stbuf->st_blocks = ( meta.size + data->block_size - 1 ) / data->block_size;
- /* TODO: set correctly from table */
- stbuf->st_nlink = 1;
- stbuf->st_uid = meta.uid;
- stbuf->st_gid = meta.gid;
- stbuf->st_atime = meta.atime.tv_sec;
- stbuf->st_mtime = meta.mtime.tv_sec;
- stbuf->st_ctime = meta.ctime.tv_sec;
+ convert_meta_to_stbuf( stbuf, &meta, data, id );
+
PSQL_COMMIT( conn ); RELEASE( conn );
return 0;
@@ -231,21 +236,8 @@ static int pgfuse_getattr( const char *path, struct stat *stbuf )
S_ISDIR( meta.mode ) ? "dir" : "file", path, id,
THREAD_ID );
}
-
- /* TODO: check bits of inodes of the kernel */
- stbuf->st_ino = id;
- stbuf->st_blocks = 0;
- stbuf->st_mode = meta.mode;
- stbuf->st_size = meta.size;
- stbuf->st_blksize = data->block_size;
- stbuf->st_blocks = ( meta.size + data->block_size - 1 ) / data->block_size;
- /* TODO: set correctly from table */
- stbuf->st_nlink = 1;
- stbuf->st_uid = meta.uid;
- stbuf->st_gid = meta.gid;
- stbuf->st_atime = meta.atime.tv_sec;
- stbuf->st_mtime = meta.mtime.tv_sec;
- stbuf->st_ctime = meta.ctime.tv_sec;
+
+ convert_meta_to_stbuf( stbuf, &meta, data, id );
PSQL_COMMIT( conn ); RELEASE( conn );
@@ -794,7 +786,7 @@ static int pgfuse_write( const char *path, const char *buf, size_t size,
if( offset + size > meta.size ) {
meta.size = offset + size;
}
-
+
res = psql_write_buf( conn, data->block_size, fi->fh, path, buf, offset, size, data->verbose );
if( res < 0 ) {
PSQL_ROLLBACK( conn ); RELEASE( conn );