@happybeing – good stuff. The polyfuse sample seems a good start. I notice its a bit different than the C api, eg I don’t see a create() call, maybe that is do_mknod() instead.
I’ve had my nose stuck deep in the code all day, so I have a bit of progress to report.
I started making a prototype filesystem
class. This is a super quick/dirty implementation of a simplified fuse API. eg, it doesn’t bother with all the request/reply data structures, etc. The idea is to test/simulate/visualize the basic concepts we’ve been refining.
I was able to implement init(), lookup(), mkdir(), create(), and link(), and then to write a little test case that tries them out.
Code:
function test_fs() {
// initial filesystem
$fs = new filesystem();
$fs->init(new replica());
// display state
$fs->print_current_state();
// get ino for /
$ino_root = $fs->lookup("/");
// create /home/bob
$ino_home = $fs->mkdir($ino_root, "home" );
$ino_bob = $fs->mkdir($ino_home, "bob" );
// create /home/bob/homework.txt and hard-link homework-link.txt
$ino_homework = $fs->create($ino_bob, "homework.txt", 'c' );
$fs->link($ino_homework, $ino_bob, "homework-link.txt");
// display state
$fs->print_current_state();
}
Output:
------- current filesystem state -------
- null => forest
- 1000 => {"name":"root","size":0,"ctime":1596590417,"mtime":1596590417,"kind":"dir"}
- 1001 => {"name":"fileinodes","size":0,"ctime":1596590417,"mtime":1596590417,"kind":"dir"}
- 1002 => {"name":"trash","size":0,"ctime":1596590417,"mtime":1596590417,"kind":"dir"}
local inode entries:
3 => {"ino":3,"tree_id":1000,"ref_count":1,"links":1,"is_file":false}
------- end state -------
------- current filesystem state -------
- null => forest
- 1000 => {"name":"root","size":0,"ctime":1596590417,"mtime":1596590417,"kind":"dir"}
- 1003 => {"name":"home","size":0,"ctime":1596590417,"mtime":1596590417,"kind":"dir"}
- 1004 => {"name":"bob","size":0,"ctime":1596590417,"mtime":1596590417,"kind":"dir"}
- 1006 => {"name":"homework.txt","inode_id":1005}
- 1007 => {"name":"homework-link.txt","inode_id":1005}
- 1001 => {"name":"fileinodes","size":0,"ctime":1596590417,"mtime":1596590417,"kind":"dir"}
- 1005 => {"size":0,"ctime":1596590417,"mtime":1596590417,"kind":"file","xorname":null}
- 1002 => {"name":"trash","size":0,"ctime":1596590417,"mtime":1596590417,"kind":"dir"}
local inode entries:
3 => {"ino":3,"tree_id":1000,"ref_count":2,"links":1,"is_file":false}
4 => {"ino":4,"tree_id":1003,"ref_count":1,"links":1,"is_file":false}
5 => {"ino":5,"tree_id":1004,"ref_count":1,"links":1,"is_file":false}
6 => {"ino":6,"tree_id":1005,"ref_count":1,"links":2,"is_file":true}
------- end state -------
That’s as far as I’ve gotten, but working so far!
Note that the code is NOT creating inode entries for directories (or symlinks) under /fileinodes. This should save some space and a lot of unnecessary move operations.