summaryrefslogtreecommitdiff
path: root/pgsql.c
diff options
context:
space:
mode:
authorAndreas Baumann <abaumann@yahoo.com>2013-04-15 18:52:51 +0200
committerAndreas Baumann <abaumann@yahoo.com>2013-04-15 18:52:51 +0200
commit906665d02eefdc98b93edab645e8f0c08c5dfdf3 (patch)
tree0256d5dee7a609da5f179c772cb78a8258663d61 /pgsql.c
parent75d12c2bd82cccec8847703e95ceec4fef9588f2 (diff)
downloadpgfuse-906665d02eefdc98b93edab645e8f0c08c5dfdf3.tar.gz
pgfuse-906665d02eefdc98b93edab645e8f0c08c5dfdf3.tar.bz2
started to rewrite, removed dependecy on shell/Perl
resulting a fictive number for free files and free blocks for now added test cases removed function.sql
Diffstat (limited to 'pgsql.c')
-rw-r--r--pgsql.c60
1 files changed, 34 insertions, 26 deletions
diff --git a/pgsql.c b/pgsql.c
index 6b7a263..242c953 100644
--- a/pgsql.c
+++ b/pgsql.c
@@ -25,6 +25,7 @@
#include <arpa/inet.h> /* for htonl, ntohl */
#include <stdint.h> /* for uint64_t */
#include <inttypes.h> /* for PRIxxx macros */
+#include <values.h> /* for INT_MAX */
#include "endian.h" /* for be64toh and htobe64 */
@@ -928,54 +929,61 @@ size_t psql_get_block_size( PGconn *conn, const size_t block_size )
return db_block_size;
}
-size_t psql_get_fs_used( PGconn *conn )
+size_t psql_get_fs_blocks_used( PGconn *conn )
{
PGresult *res;
char *data;
- size_t fs_used;
- res = PQexec( conn, "SELECT SUM(size) FROM dir;" );
+ size_t used;
+
+ res = PQexec( conn, "SELECT (SELECT COUNT(*) FROM data) + (SELECT COUNT(*) FROM dir)" );
if( PQresultStatus( res ) != PGRES_TUPLES_OK ) {
- syslog( LOG_ERR, "Error in psql_get_fs_used: %s", PQerrorMessage( conn ) );
+ syslog( LOG_ERR, "Error in psql_get_fs_blocks_used: %s", PQerrorMessage( conn ) );
PQclear( res );
return -EIO;
}
- /* empty, this is ok, any blocksize acceptable after initialization */
- if( PQntuples( res ) == 0 ) {
- PQclear( res );
- return 0;
- }
-
+ /* we calculate the number of blocks occupied by all data entries
+ * plus all "indoes" (in our case entries in dir),
+ * more like a filesystem would do it. Returning blocks as this is
+ * harder to overflow a size_t (in case it's 32-bit, modern
+ * systems shouldn't care). It's slower though
+ */
data = PQgetvalue( res, 0, 0 );
- fs_used = atol( data );
+ used = atoi( data );
PQclear( res );
- return fs_used;
+ return used;
}
-size_t psql_get_fs_free( PGconn *conn )
+size_t psql_get_fs_blocks_free( PGconn *conn )
{
- PGresult *res;
- char *data;
- size_t fs_free;
- res = PQexec( conn, "SELECT db_disk_free();" );
- if( PQresultStatus( res ) != PGRES_TUPLES_OK ) {
- syslog( LOG_ERR, "Error in psql_get_fs_free: %s", PQerrorMessage( conn ) );
- PQclear( res );
- return -EIO;
- }
+ return 9999;
+}
- /* empty, this is ok, any blocksize acceptable after initialization */
- if( PQntuples( res ) == 0 ) {
+size_t psql_get_fs_files_used( PGconn *conn )
+{
+ PGresult *res;
+ char *data;
+ size_t used;
+
+ res = PQexec( conn, "SELECT COUNT(*) FROM dir" );
+ if( PQresultStatus( res ) != PGRES_TUPLES_OK ) {
+ syslog( LOG_ERR, "Error in psql_get_fs_files_used: %s", PQerrorMessage( conn ) );
PQclear( res );
return -EIO;
}
data = PQgetvalue( res, 0, 0 );
- fs_free = atol( data );
+ used = atoi( data );
PQclear( res );
- return fs_free;
+ return used;
}
+
+size_t psql_get_fs_files_free( PGconn *conn )
+{
+ return 9999;
+}
+