author | Tero Marttila <terom@fixme.fi> |
Sat, 13 Dec 2008 20:58:27 +0200 | |
branch | new-evsql |
changeset 55 | 0b92d553400a |
parent 40 | 03017f5f0087 |
permissions | -rw-r--r-- |
37
c3880f3b4de8
update fuse_db.sql, just use dbfs_unlink for rmdir (no special handling)
Tero Marttila <terom@fixme.fi>
parents:
35
diff
changeset
|
1 |
|
c3880f3b4de8
update fuse_db.sql, just use dbfs_unlink for rmdir (no special handling)
Tero Marttila <terom@fixme.fi>
parents:
35
diff
changeset
|
2 |
DROP TABLE IF EXISTS file_tree; |
c3880f3b4de8
update fuse_db.sql, just use dbfs_unlink for rmdir (no special handling)
Tero Marttila <terom@fixme.fi>
parents:
35
diff
changeset
|
3 |
DROP TABLE IF EXISTS inodes; |
c3880f3b4de8
update fuse_db.sql, just use dbfs_unlink for rmdir (no special handling)
Tero Marttila <terom@fixme.fi>
parents:
35
diff
changeset
|
4 |
DROP SEQUENCE IF EXISTS ino_seq; |
c3880f3b4de8
update fuse_db.sql, just use dbfs_unlink for rmdir (no special handling)
Tero Marttila <terom@fixme.fi>
parents:
35
diff
changeset
|
5 |
|
c3880f3b4de8
update fuse_db.sql, just use dbfs_unlink for rmdir (no special handling)
Tero Marttila <terom@fixme.fi>
parents:
35
diff
changeset
|
6 |
CREATE SEQUENCE ino_seq START 64; |
c3880f3b4de8
update fuse_db.sql, just use dbfs_unlink for rmdir (no special handling)
Tero Marttila <terom@fixme.fi>
parents:
35
diff
changeset
|
7 |
|
40
03017f5f0087
add MODE param to makefile, fix INFO_DISABLED, add some constraints to the .sql, fix some -err's, EVSQL_PQ_ARBITRARY_TYPE_OID, and make read/write transactionless
Tero Marttila <terom@fixme.fi>
parents:
38
diff
changeset
|
8 |
-- inodes |
31 | 9 |
CREATE TABLE inodes ( |
37
c3880f3b4de8
update fuse_db.sql, just use dbfs_unlink for rmdir (no special handling)
Tero Marttila <terom@fixme.fi>
parents:
35
diff
changeset
|
10 |
ino int4 primary key DEFAULT nextval('ino_seq'::regclass), |
31 | 11 |
type char(3) NOT NULL, |
12 |
mode int2 NOT NULL, |
|
37
c3880f3b4de8
update fuse_db.sql, just use dbfs_unlink for rmdir (no special handling)
Tero Marttila <terom@fixme.fi>
parents:
35
diff
changeset
|
13 |
data oid, |
40
03017f5f0087
add MODE param to makefile, fix INFO_DISABLED, add some constraints to the .sql, fix some -err's, EVSQL_PQ_ARBITRARY_TYPE_OID, and make read/write transactionless
Tero Marttila <terom@fixme.fi>
parents:
38
diff
changeset
|
14 |
link_path varchar(512), |
03017f5f0087
add MODE param to makefile, fix INFO_DISABLED, add some constraints to the .sql, fix some -err's, EVSQL_PQ_ARBITRARY_TYPE_OID, and make read/write transactionless
Tero Marttila <terom@fixme.fi>
parents:
38
diff
changeset
|
15 |
|
03017f5f0087
add MODE param to makefile, fix INFO_DISABLED, add some constraints to the .sql, fix some -err's, EVSQL_PQ_ARBITRARY_TYPE_OID, and make read/write transactionless
Tero Marttila <terom@fixme.fi>
parents:
38
diff
changeset
|
16 |
-- sanity checks |
03017f5f0087
add MODE param to makefile, fix INFO_DISABLED, add some constraints to the .sql, fix some -err's, EVSQL_PQ_ARBITRARY_TYPE_OID, and make read/write transactionless
Tero Marttila <terom@fixme.fi>
parents:
38
diff
changeset
|
17 |
CONSTRAINT inodes_valid_reg CHECK (data IS NULL OR type = 'REG'), |
03017f5f0087
add MODE param to makefile, fix INFO_DISABLED, add some constraints to the .sql, fix some -err's, EVSQL_PQ_ARBITRARY_TYPE_OID, and make read/write transactionless
Tero Marttila <terom@fixme.fi>
parents:
38
diff
changeset
|
18 |
CONSTRAINT inodes_valid_lnk CHECK (link_path IS NULL OR type = 'LNK') |
31 | 19 |
); |
24 | 20 |
|
40
03017f5f0087
add MODE param to makefile, fix INFO_DISABLED, add some constraints to the .sql, fix some -err's, EVSQL_PQ_ARBITRARY_TYPE_OID, and make read/write transactionless
Tero Marttila <terom@fixme.fi>
parents:
38
diff
changeset
|
21 |
-- filesystem layout |
31 | 22 |
CREATE TABLE file_tree ( |
23 |
"offset" serial4 primary key, |
|
24 |
name varchar(256), |
|
38
1fd4da071575
rework/hack parent to be a FOREIGN KEY (add a dir_ino col), implement dbfs_link
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
25 |
ino int4 references inodes(ino) NOT NULL, |
1fd4da071575
rework/hack parent to be a FOREIGN KEY (add a dir_ino col), implement dbfs_link
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
26 |
ino_dir int4 references inodes(ino), |
1fd4da071575
rework/hack parent to be a FOREIGN KEY (add a dir_ino col), implement dbfs_link
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
27 |
parent int4, |
40
03017f5f0087
add MODE param to makefile, fix INFO_DISABLED, add some constraints to the .sql, fix some -err's, EVSQL_PQ_ARBITRARY_TYPE_OID, and make read/write transactionless
Tero Marttila <terom@fixme.fi>
parents:
38
diff
changeset
|
28 |
|
03017f5f0087
add MODE param to makefile, fix INFO_DISABLED, add some constraints to the .sql, fix some -err's, EVSQL_PQ_ARBITRARY_TYPE_OID, and make read/write transactionless
Tero Marttila <terom@fixme.fi>
parents:
38
diff
changeset
|
29 |
-- structure |
38
1fd4da071575
rework/hack parent to be a FOREIGN KEY (add a dir_ino col), implement dbfs_link
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
30 |
CONSTRAINT file_tree_uniq_direntry UNIQUE (parent, name), |
1fd4da071575
rework/hack parent to be a FOREIGN KEY (add a dir_ino col), implement dbfs_link
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
31 |
CONSTRAINT file_tree_uniq_dir_ino UNIQUE (ino_dir), |
40
03017f5f0087
add MODE param to makefile, fix INFO_DISABLED, add some constraints to the .sql, fix some -err's, EVSQL_PQ_ARBITRARY_TYPE_OID, and make read/write transactionless
Tero Marttila <terom@fixme.fi>
parents:
38
diff
changeset
|
32 |
CONSTRAINT file_tree_exist_parent FOREIGN KEY (parent) REFERENCES file_tree(ino_dir), |
03017f5f0087
add MODE param to makefile, fix INFO_DISABLED, add some constraints to the .sql, fix some -err's, EVSQL_PQ_ARBITRARY_TYPE_OID, and make read/write transactionless
Tero Marttila <terom@fixme.fi>
parents:
38
diff
changeset
|
33 |
|
03017f5f0087
add MODE param to makefile, fix INFO_DISABLED, add some constraints to the .sql, fix some -err's, EVSQL_PQ_ARBITRARY_TYPE_OID, and make read/write transactionless
Tero Marttila <terom@fixme.fi>
parents:
38
diff
changeset
|
34 |
-- sanity checks |
03017f5f0087
add MODE param to makefile, fix INFO_DISABLED, add some constraints to the .sql, fix some -err's, EVSQL_PQ_ARBITRARY_TYPE_OID, and make read/write transactionless
Tero Marttila <terom@fixme.fi>
parents:
38
diff
changeset
|
35 |
CONSTRAINT file_tree_valid_root CHECK ((parent IS NULL AND name IS NULL AND ino = 1) OR (name IS NOT NULL and parent IS NOT NULL AND ino != 1)), |
03017f5f0087
add MODE param to makefile, fix INFO_DISABLED, add some constraints to the .sql, fix some -err's, EVSQL_PQ_ARBITRARY_TYPE_OID, and make read/write transactionless
Tero Marttila <terom@fixme.fi>
parents:
38
diff
changeset
|
36 |
CONSTRAINT file_tree_valid_dir CHECK (ino_dir IS NULL OR ino_dir = ino) |
31 | 37 |
); |
24 | 38 |
|
37
c3880f3b4de8
update fuse_db.sql, just use dbfs_unlink for rmdir (no special handling)
Tero Marttila <terom@fixme.fi>
parents:
35
diff
changeset
|
39 |
INSERT INTO inodes (ino, type, mode, data) VALUES |
31 | 40 |
(1, 'DIR', 365, NULL), |
41 |
(2, 'REG', 292, lo_create(0)); |
|
27 | 42 |
|
38
1fd4da071575
rework/hack parent to be a FOREIGN KEY (add a dir_ino col), implement dbfs_link
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
43 |
INSERT INTO file_tree (name, parent, ino, ino_dir) VALUES |
1fd4da071575
rework/hack parent to be a FOREIGN KEY (add a dir_ino col), implement dbfs_link
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
44 |
(NULL, NULL, 1, 1 ), |
1fd4da071575
rework/hack parent to be a FOREIGN KEY (add a dir_ino col), implement dbfs_link
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
45 |
('foo', 1, 2, NULL ); |
31 | 46 |
|
40
03017f5f0087
add MODE param to makefile, fix INFO_DISABLED, add some constraints to the .sql, fix some -err's, EVSQL_PQ_ARBITRARY_TYPE_OID, and make read/write transactionless
Tero Marttila <terom@fixme.fi>
parents:
38
diff
changeset
|
47 |
-- not sure how these work, I guess statements in functions aren't their own transactions |
03017f5f0087
add MODE param to makefile, fix INFO_DISABLED, add some constraints to the .sql, fix some -err's, EVSQL_PQ_ARBITRARY_TYPE_OID, and make read/write transactionless
Tero Marttila <terom@fixme.fi>
parents:
38
diff
changeset
|
48 |
CREATE OR REPLACE FUNCTION lo_pread_oid (IN obj oid, IN len int4, IN "off" int4) RETURNS bytea LANGUAGE SQL STRICT AS 'select lo_open($1, 393216); select lo_lseek(0, $3, 0); select loread(0, $2);'; |
03017f5f0087
add MODE param to makefile, fix INFO_DISABLED, add some constraints to the .sql, fix some -err's, EVSQL_PQ_ARBITRARY_TYPE_OID, and make read/write transactionless
Tero Marttila <terom@fixme.fi>
parents:
38
diff
changeset
|
49 |
CREATE OR REPLACE FUNCTION lo_pwrite_oid (IN obj oid, IN buf bytea, IN "off" int4) RETURNS int4 LANGUAGE SQL STRICT AS 'select lo_open($1, 393216); select lo_lseek(0, $3, 0); select lowrite(0, $2);'; |
03017f5f0087
add MODE param to makefile, fix INFO_DISABLED, add some constraints to the .sql, fix some -err's, EVSQL_PQ_ARBITRARY_TYPE_OID, and make read/write transactionless
Tero Marttila <terom@fixme.fi>
parents:
38
diff
changeset
|
50 |
|
03017f5f0087
add MODE param to makefile, fix INFO_DISABLED, add some constraints to the .sql, fix some -err's, EVSQL_PQ_ARBITRARY_TYPE_OID, and make read/write transactionless
Tero Marttila <terom@fixme.fi>
parents:
38
diff
changeset
|
51 |
CREATE OR REPLACE FUNCTION lo_otruncate (IN obj oid, IN len int4) RETURNS oid LANGUAGE SQL STRICT AS 'select lo_truncate(lo_open($1, 393216), $2); select $1;'; |
37
c3880f3b4de8
update fuse_db.sql, just use dbfs_unlink for rmdir (no special handling)
Tero Marttila <terom@fixme.fi>
parents:
35
diff
changeset
|
52 |
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);'; |
c3880f3b4de8
update fuse_db.sql, just use dbfs_unlink for rmdir (no special handling)
Tero Marttila <terom@fixme.fi>
parents:
35
diff
changeset
|
53 |
CREATE OR REPLACE FUNCTION dbfs_size (type char, oid, link varchar) RETURNS int4 LANGUAGE SQL STABLE AS $$ |
33 | 54 |
SELECT CASE $1 |
55 |
WHEN 'LNK' THEN char_length($3) |
|
56 |
WHEN 'REG' THEN lo_size($2) |
|
57 |
ELSE 0 |
|
58 |
END; |
|
59 |
$$; |
|
38
1fd4da071575
rework/hack parent to be a FOREIGN KEY (add a dir_ino col), implement dbfs_link
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
60 |
|
1fd4da071575
rework/hack parent to be a FOREIGN KEY (add a dir_ino col), implement dbfs_link
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
61 |
CREATE OR REPLACE FUNCTION dbfs_link ( |
1fd4da071575
rework/hack parent to be a FOREIGN KEY (add a dir_ino col), implement dbfs_link
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
62 |
IN ino int4, IN new_parent int4, IN new_name varchar, |
1fd4da071575
rework/hack parent to be a FOREIGN KEY (add a dir_ino col), implement dbfs_link
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
63 |
OUT ino int4, OUT type char(3), OUT mode int2, OUT size int4, OUT nlink int8 |
1fd4da071575
rework/hack parent to be a FOREIGN KEY (add a dir_ino col), implement dbfs_link
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
64 |
) LANGUAGE SQL VOLATILE AS $$ |
1fd4da071575
rework/hack parent to be a FOREIGN KEY (add a dir_ino col), implement dbfs_link
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
65 |
INSERT INTO file_tree (name, ino, parent) VALUES ($3, $1, $2); |
1fd4da071575
rework/hack parent to be a FOREIGN KEY (add a dir_ino col), implement dbfs_link
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
66 |
SELECT ino, type, mode, dbfs_size(type, data, link_path) AS size, (SELECT COUNT(*) FROM inodes i LEFT JOIN file_tree ft ON (i.ino = ft.ino) WHERE i.ino = inodes.ino) AS nlink |
1fd4da071575
rework/hack parent to be a FOREIGN KEY (add a dir_ino col), implement dbfs_link
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
67 |
FROM inodes WHERE ino = $1; |
1fd4da071575
rework/hack parent to be a FOREIGN KEY (add a dir_ino col), implement dbfs_link
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
68 |
$$; |