--- a/doc/fuse_db.sql Tue Oct 21 21:42:17 2008 +0300
+++ b/doc/fuse_db.sql Tue Oct 21 21:54:20 2008 +0300
@@ -1,41 +1,39 @@
+
+DROP TABLE IF EXISTS file_tree;
+DROP TABLE IF EXISTS inodes;
+DROP SEQUENCE IF EXISTS ino_seq;
+
+CREATE SEQUENCE ino_seq START 64;
+
CREATE TABLE inodes (
- ino serial4 primary key,
+ ino int4 primary key DEFAULT nextval('ino_seq'::regclass),
type char(3) NOT NULL,
mode int2 NOT NULL,
- data oid
+ data oid,
+ link_path varchar(512)
);
CREATE TABLE file_tree (
"offset" serial4 primary key,
name varchar(256),
- parent int4 references inodes(ino),
- inode int4 references inodes(ino) NOT NULL
+ ino int4 references inodes(ino) NOT NULL UNIQUE,
+ parent int4 references file_tree(ino)
);
-INSERT INTO inodes VALUES
+INSERT INTO inodes (ino, type, mode, data) VALUES
(1, 'DIR', 365, NULL),
(2, 'REG', 292, lo_create(0));
-INSERT INTO file_tree (name, parent, inode) VALUES
+INSERT INTO file_tree (name, parent, ino) VALUES
(NULL, NULL, 1 ),
('foo', 1, 2 );
-CREATE FUNCTION lo_size (oid) RETURNS int4 LANGUAGE SQL STABLE RETURNS NULL ON NULL INPUT AS 'select lo_lseek(lo_open($1, 262144), 0, 2);';
-CREATE FUNCTION lo_pread (IN fd int4, IN len int4, IN "off" int4) RETURNS bytea LANGUAGE SQL STRICT AS 'select lo_lseek($1, $3, 0); select loread($1, $2);';
-CREATE FUNCTION lo_pwrite (IN fd int4, IN buf bytea, IN "off" int4) RETURNS int4 LANGUAGE SQL STRICT AS 'select lo_lseek($1, $3, 0); select lowrite($1, $2);';
-CREATE FUNCTION lo_otruncate (IN oid, IN len int4) RETURNS oid LANGUAGE SQL STRICT AS 'select lo_truncate(lo_open($1, 393216), $2); select $1;';
-
-ALTER TABLE inodes ADD COLUMN link varchar(512);
+CREATE OR REPLACE FUNCTION lo_size (oid) RETURNS int4 LANGUAGE SQL STABLE RETURNS NULL ON NULL INPUT AS 'select lo_lseek(lo_open($1, 262144), 0, 2);';
+CREATE OR REPLACE FUNCTION lo_pread (IN fd int4, IN len int4, IN "off" int4) RETURNS bytea LANGUAGE SQL STRICT AS 'select lo_lseek($1, $3, 0); select loread($1, $2);';
+CREATE OR REPLACE FUNCTION lo_pwrite (IN fd int4, IN buf bytea, IN "off" int4) RETURNS int4 LANGUAGE SQL STRICT AS 'select lo_lseek($1, $3, 0); select lowrite($1, $2);';
+CREATE OR REPLACE FUNCTION lo_otruncate (IN oid, IN len int4) RETURNS oid LANGUAGE SQL STRICT AS 'select lo_truncate(lo_open($1, 393216), $2); select $1;';
-CREATE SEQUENCE ino_seq START 64;
-ALTER TABLE inodes ALTER COLUMN ino SET DEFAULT nextval('ino_seq'::regclass);
-
-ALTER TABLE file_tree ADD COLUMN ino int4;
-ALTER TABLE file_tree ADD CONSTRAINT file_tree_ino_fkey FOREIGN KEY (ino) REFERENCES inodes (ino);
-UPDATE file_tree SET ino = inode;
-ALTER TABLE file_tree DROP COLUMN inode;
-
-CREATE FUNCTION dbfs_size (type char, oid, link varchar) RETURNS int4 LANGUAGE SQL STABLE AS $$
+CREATE OR REPLACE FUNCTION dbfs_size (type char, oid, link varchar) RETURNS int4 LANGUAGE SQL STABLE AS $$
SELECT CASE $1
WHEN 'LNK' THEN char_length($3)
WHEN 'REG' THEN lo_size($2)
--- a/src/dbfs/dbfs.c Tue Oct 21 21:42:17 2008 +0300
+++ b/src/dbfs/dbfs.c Tue Oct 21 21:54:20 2008 +0300
@@ -18,7 +18,7 @@
.mknod = dbfs_mknod,
.mkdir = dbfs_mkdir,
.unlink = dbfs_unlink,
-
+ .rmdir = dbfs_unlink, // this behaves just the same
.symlink = dbfs_symlink,
.rename = dbfs_rename,
--- a/src/dbfs/link.c Tue Oct 21 21:42:17 2008 +0300
+++ b/src/dbfs/link.c Tue Oct 21 21:54:20 2008 +0300
@@ -85,6 +85,7 @@
int err = 0;
// check the results
+ // XXX: reply with ENOTEMPTY if it fails due to this inode being a dir
if ((err = dbfs_check_result(res, 1, 0)))
goto error;
@@ -140,3 +141,4 @@
if ((err = fuse_reply_err(req, err)))
EWARNING(err, "fuse_reply_err");
}
+