summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Baumann <abaumann@yahoo.com>2012-04-06 16:28:57 +0200
committerAndreas Baumann <abaumann@yahoo.com>2012-04-06 16:28:57 +0200
commit7729917abe968b85775234c5410c21a50ce23bff (patch)
tree9fb89624ffaf99fa35633bea35d2e38f1e3f6051
parent5e01f9c1b7738cecac65d3ab9d6a0d3b81a7da2a (diff)
downloadpgfuse-7729917abe968b85775234c5410c21a50ce23bff.tar.gz
pgfuse-7729917abe968b85775234c5410c21a50ce23bff.tar.bz2
first writing works
-rw-r--r--Makefile1
-rw-r--r--pgfuse.c38
2 files changed, 36 insertions, 3 deletions
diff --git a/Makefile b/Makefile
index 8e492d6..60553b2 100644
--- a/Makefile
+++ b/Makefile
@@ -16,6 +16,7 @@ clean:
rm -f pgfuse pgfuse.o
test: pgfuse
+ psql < test.sql
-./pgfuse -v "" mnt
mount | grep pgfuse
-mkdir mnt/dir
diff --git a/pgfuse.c b/pgfuse.c
index 2ea79c2..8fcd5e9 100644
--- a/pgfuse.c
+++ b/pgfuse.c
@@ -134,11 +134,32 @@ static int psql_get_parent_id( PGconn *conn, const char *path )
return parent_id;
}
+static int psql_create_dir( PGconn *conn, const int parent_id, const char *path, const char *new_dir, mode_t mode )
+{
+ int param1 = htonl( parent_id );
+ const char *values[3] = { (char *)&param1, new_dir, path };
+ int lengths[3] = { sizeof( parent_id), strlen( new_dir ), strlen( path ) };
+ int binary[3] = { 1, 0, 0 };
+ int res;
+
+ res = PQexecParams( conn, "INSERT INTO dir( parent_id, name, path ) VALUES ($1::int4, $2::varchar, $3::varchar)",
+ 3, NULL, values, lengths, binary, 1 );
+
+ if( PQresultStatus( res ) != PGRES_COMMAND_OK ) {
+ syslog( LOG_ERR, "Error in psql_createdir for path '%s'", path );
+ return -EIO;
+ }
+
+ return 0;
+}
+
static int pgfuse_mkdir( const char *path, mode_t mode )
{
PgFuseData *data = (PgFuseData *)fuse_get_context( )->private_data;
char *parent_path;
+ char *new_dir;
int parent_id;
+ int res;
if( data->verbose ) {
syslog( LOG_INFO, "Mkdir '%s' in mode '%o'", path, (unsigned int)mode );
@@ -158,13 +179,24 @@ static int pgfuse_mkdir( const char *path, mode_t mode )
}
if( data->verbose ) {
- syslog( LOG_INFO, "Parent_id for new dir '%s' is %d", path, parent_id );
+ syslog( LOG_DEBUG, "Parent_id for new dir '%s' is %d", path, parent_id );
}
-
+ new_dir = strdup( path );
+ if( new_dir == NULL ) {
+ free( parent_path );
+ syslog( LOG_ERR, "Out of memory in Mkdir '%s'!", path );
+ return -EIO;
+ }
+
+ basename( new_dir );
+
+ res = psql_create_dir( data->conn, parent_id, path, new_dir, mode );
+
+ free( new_dir );
free( parent_path );
- return 0;
+ return res;
}
static struct fuse_operations pgfuse_oper = {