summaryrefslogtreecommitdiff
path: root/pgsql.c
diff options
context:
space:
mode:
authorAndreas Baumann <abaumann@yahoo.com>2012-04-20 11:09:02 +0200
committerAndreas Baumann <abaumann@yahoo.com>2012-04-20 11:09:02 +0200
commit7b6fc96d7710b1467420a548a7ae7b1e9b7b56fa (patch)
tree46bf833c57aaae9720084b107cd2f4f7e3a1fc84 /pgsql.c
parentc6ed5885ba8841a746c98a79635998c8890e73f1 (diff)
downloadpgfuse-7b6fc96d7710b1467420a548a7ae7b1e9b7b56fa.tar.gz
pgfuse-7b6fc96d7710b1467420a548a7ae7b1e9b7b56fa.tar.bz2
fixed some nasty bugs
Diffstat (limited to 'pgsql.c')
-rw-r--r--pgsql.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/pgsql.c b/pgsql.c
index dc7cce3..4c6f419 100644
--- a/pgsql.c
+++ b/pgsql.c
@@ -72,7 +72,7 @@ static PgDataInfo compute_block_info( off_t offset, size_t len )
if( nof_blocks == 0 ) {
info.from_len = len;
} else {
- info.from_len = STANDARD_BLOCK_SIZE;
+ info.from_len = STANDARD_BLOCK_SIZE - info.from_offset;
}
info.to_block = info.from_block + nof_blocks;
@@ -286,7 +286,7 @@ int psql_read_buf( PGconn *conn, const int id, const char *path, char *buf, cons
/* first block */
if( block_no == info.from_block ) {
- memcpy( dst, data + info.from_offset, info.from_len );
+ memcpy( dst, data + info.from_offset, info.from_len - info.from_offset );
dst += info.from_len;
copied += info.from_len;
@@ -313,6 +313,12 @@ int psql_read_buf( PGconn *conn, const int id, const char *path, char *buf, cons
PQclear( res );
+ if( copied != size ) {
+ syslog( LOG_ERR, "File '%s', reading block '%d', copied '%d' bytes but expecting '%d'!",
+ path, block_no, copied, size );
+ return -EIO;
+ }
+
return copied;
}
@@ -461,8 +467,8 @@ static int psql_write_block( PGconn *conn, const int id, const char *path, const
/* could actually be an assertion, as this can never happen */
if( offset + len > STANDARD_BLOCK_SIZE ) {
- syslog( LOG_ERR, "Got a too big block write for file '%s': %u + %u > %d!",
- path, (unsigned int)offset, (unsigned int)len, STANDARD_BLOCK_SIZE );
+ syslog( LOG_ERR, "Got a too big block write for file '%s', block '%d': %u + %u > %d!",
+ path, block_no, (unsigned int)offset, (unsigned int)len, STANDARD_BLOCK_SIZE );
return -EIO;
}