diff options
author | Andreas Baumann <abaumann@yahoo.com> | 2013-04-15 15:27:31 +0200 |
---|---|---|
committer | Andreas Baumann <abaumann@yahoo.com> | 2013-04-15 15:27:31 +0200 |
commit | 30b23afb5fca43110f09201897742c378eccb285 (patch) | |
tree | 3a584c9e708e5ecd09357fa8415b916a694d33a3 /pgsql.c | |
parent | 8f92530fd96cadff64fabc711c6b523ffb27fe29 (diff) | |
download | pgfuse-30b23afb5fca43110f09201897742c378eccb285.tar.gz pgfuse-30b23afb5fca43110f09201897742c378eccb285.tar.bz2 |
added statsfs patch from Роман Бородин
Diffstat (limited to 'pgsql.c')
-rw-r--r-- | pgsql.c | 51 |
1 files changed, 51 insertions, 0 deletions
@@ -928,3 +928,54 @@ 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 ) +{ + PGresult *res; + char *data; + size_t fs_used; + res = PQexec( conn, "SELECT SUM(size) FROM dir;" ); + if( PQresultStatus( res ) != PGRES_TUPLES_OK ) { + syslog( LOG_ERR, "Error in psql_get_fs_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; + } + + data = PQgetvalue( res, 0, 0 ); + fs_used = atol( data ); + + PQclear( res ); + + return fs_used; +} + +size_t psql_get_fs_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; + } + + /* empty, this is ok, any blocksize acceptable after initialization */ + if( PQntuples( res ) == 0 ) { + PQclear( res ); + return -EIO; + } + + data = PQgetvalue( res, 0, 0 ); + fs_free = atol( data ); + + PQclear( res ); + + return fs_free; +} |