diff options
author | Andreas Baumann <abaumann@yahoo.com> | 2012-04-14 18:05:17 +0200 |
---|---|---|
committer | Andreas Baumann <abaumann@yahoo.com> | 2012-04-14 18:05:17 +0200 |
commit | 3c3a241c374e42206ad0b9f67f66e6b80ff73d1b (patch) | |
tree | 209366a289a0aa0cce7788f44ae857b4549cb60f /pgsql.c | |
parent | 556900b8356db38a2dc1347bbf042236052b4ba9 (diff) | |
download | pgfuse-3c3a241c374e42206ad0b9f67f66e6b80ff73d1b.tar.gz pgfuse-3c3a241c374e42206ad0b9f67f66e6b80ff73d1b.tar.bz2 |
mode, uid and gid are stored now
Diffstat (limited to 'pgsql.c')
-rw-r--r-- | pgsql.c | 74 |
1 files changed, 44 insertions, 30 deletions
@@ -27,9 +27,7 @@ int psql_get_meta( PGconn *conn, const char *path, PgMeta *meta ) { PGresult *res; - int i_id; - int i_size; - int i_mode; + int idx; char *iptr; int id; @@ -37,7 +35,7 @@ int psql_get_meta( PGconn *conn, const char *path, PgMeta *meta ) int lengths[1] = { strlen( path ) }; int binary[1] = { 1 }; - res = PQexecParams( conn, "SELECT id, size, mode FROM dir WHERE path = $1::varchar", + res = PQexecParams( conn, "SELECT id, size, mode, uid, gid FROM dir WHERE path = $1::varchar", 1, NULL, values, lengths, binary, 1 ); if( PQresultStatus( res ) != PGRES_TUPLES_OK ) { @@ -57,16 +55,26 @@ int psql_get_meta( PGconn *conn, const char *path, PgMeta *meta ) return -EIO; } - i_id = PQfnumber( res, "id" ); - i_size = PQfnumber( res, "size" ); - i_mode = PQfnumber( res, "mode" ); - iptr = PQgetvalue( res, 0, i_id ); + idx = PQfnumber( res, "id" ); + iptr = PQgetvalue( res, 0, idx ); id = ntohl( *( (uint32_t *)iptr ) ); - iptr = PQgetvalue( res, 0, i_size ); + + idx = PQfnumber( res, "size" ); + iptr = PQgetvalue( res, 0, idx ); meta->size = ntohl( *( (uint32_t *)iptr ) ); - iptr = PQgetvalue( res, 0, i_mode ); + + idx = PQfnumber( res, "mode" ); + iptr = PQgetvalue( res, 0, idx ); meta->mode = ntohl( *( (uint32_t *)iptr ) ); + idx = PQfnumber( res, "uid" ); + iptr = PQgetvalue( res, 0, idx ); + meta->uid = ntohl( *( (uint32_t *)iptr ) ); + + idx = PQfnumber( res, "gid" ); + iptr = PQgetvalue( res, 0, idx ); + meta->gid = ntohl( *( (uint32_t *)iptr ) ); + PQclear( res ); return id; @@ -77,13 +85,15 @@ int psql_write_meta( PGconn *conn, const int id, const char *path, PgMeta meta ) int param1 = htonl( id ); int param2 = htonl( meta.size ); int param3 = htonl( meta.mode ); - const char *values[3] = { (char *)¶m1, (char *)¶m2, (char *)¶m3 }; - int lengths[3] = { sizeof( param1 ), sizeof( param2 ), sizeof( param3 ) }; - int binary[3] = { 1, 1, 1 }; + int param4 = htonl( meta.uid ); + int param5 = htonl( meta.gid ); + const char *values[5] = { (char *)¶m1, (char *)¶m2, (char *)¶m3, (char *)¶m4, (char *)¶m5 }; + int lengths[5] = { sizeof( param1 ), sizeof( param2 ), sizeof( param3 ), sizeof( param4 ), sizeof( param5 ) }; + int binary[5] = { 1, 1, 1, 1, 1 }; PGresult *res; - res = PQexecParams( conn, "UPDATE dir SET size=$2::int4, mode=$3::int4 WHERE id=$1::int4", - 3, NULL, values, lengths, binary, 1 ); + res = PQexecParams( conn, "UPDATE dir SET size=$2::int4, mode=$3::int4, uid=$4::int4, gid=$5::int4 WHERE id=$1::int4", + 5, NULL, values, lengths, binary, 1 ); if( PQresultStatus( res ) != PGRES_COMMAND_OK ) { syslog( LOG_ERR, "Error in psql_write_meta for file '%s': %s", path, PQerrorMessage( conn ) ); @@ -96,17 +106,19 @@ int psql_write_meta( PGconn *conn, const int id, const char *path, PgMeta meta ) return 0; } -int psql_create_file( PGconn *conn, const int parent_id, const char *path, const char *new_file, const mode_t mode ) +int psql_create_file( PGconn *conn, const int parent_id, const char *path, const char *new_file, PgMeta meta ) { int param1 = htonl( parent_id ); - int param2 = htonl( mode ); - const char *values[4] = { (const char *)¶m1, new_file, path, (const char *)¶m2 }; - int lengths[4] = { sizeof( param1 ), strlen( new_file ), strlen( path ), sizeof( param2 ) }; - int binary[4] = { 1, 0, 0, 1 }; + int param2 = htonl( meta.mode ); + int param3 = htonl( meta.uid ); + int param4 = htonl( meta.gid ); + const char *values[6] = { (const char *)¶m1, new_file, path, (const char *)¶m2, (const char *)¶m3, (const char *)¶m4 }; + int lengths[6] = { sizeof( param1 ), strlen( new_file ), strlen( path ), sizeof( param2 ), sizeof( param3 ), sizeof( param4 ) }; + int binary[6] = { 1, 0, 0, 1, 1, 1 }; PGresult *res; - res = PQexecParams( conn, "INSERT INTO dir( parent_id, name, path, mode ) VALUES ($1::int4, $2::varchar, $3::varchar, $4::int4 )", - 4, NULL, values, lengths, binary, 1 ); + res = PQexecParams( conn, "INSERT INTO dir( parent_id, name, path, mode, uid, gid ) VALUES ($1::int4, $2::varchar, $3::varchar, $4::int4, $5::int4, $6::int4 )", + 6, NULL, values, lengths, binary, 1 ); if( PQresultStatus( res ) != PGRES_COMMAND_OK ) { syslog( LOG_ERR, "Error in psql_create_file for path '%s': %s", @@ -116,7 +128,7 @@ int psql_create_file( PGconn *conn, const int parent_id, const char *path, const } PQclear( res ); - + return 0; } @@ -187,17 +199,19 @@ int psql_readdir( PGconn *conn, const int parent_id, void *buf, fuse_fill_dir_t return 0; } -int psql_create_dir( PGconn *conn, const int parent_id, const char *path, const char *new_dir, const mode_t mode ) +int psql_create_dir( PGconn *conn, const int parent_id, const char *path, const char *new_dir, PgMeta meta ) { int param1 = htonl( parent_id ); - int param2 = htonl( mode ); - const char *values[4] = { (char *)¶m1, new_dir, path, (char *)¶m2 }; - int lengths[4] = { sizeof( param1 ), strlen( new_dir ), strlen( path ), sizeof( param2 ) }; - int binary[4] = { 1, 0, 0, 1 }; + int param2 = htonl( meta.mode ); + int param3 = htonl( meta.uid ); + int param4 = htonl( meta.gid ); + const char *values[6] = { (char *)¶m1, new_dir, path, (char *)¶m2, (char *)¶m3, (char *)¶m4 }; + int lengths[6] = { sizeof( param1 ), strlen( new_dir ), strlen( path ), sizeof( param2 ), sizeof( param3 ), sizeof( param4 ) }; + int binary[6] = { 1, 0, 0, 1, 1, 1 }; PGresult *res; - res = PQexecParams( conn, "INSERT INTO dir( parent_id, name, path, mode ) VALUES ($1::int4, $2::varchar, $3::varchar, $4::int4 )", - 4, NULL, values, lengths, binary, 1 ); + res = PQexecParams( conn, "INSERT INTO dir( parent_id, name, path, mode, uid, gid ) VALUES ($1::int4, $2::varchar, $3::varchar, $4::int4, $5::int4, $6::int4 )", + 6, NULL, values, lengths, binary, 1 ); if( PQresultStatus( res ) != PGRES_COMMAND_OK ) { syslog( LOG_ERR, "Error in psql_create_dir for path '%s': %s", path, PQerrorMessage( conn ) ); |