How to make symbolic links in FUSE?
I'm developing a FUSE app that takes a director开发者_StackOverflow中文版y with mp3's and mounts a filesystem in another directory with the following structure (according to their tag's):
Artist1
|
-----> Album11
|
-----> Track01
-----> Track02
-----> Track03
-----> Track04
-----> Track05
-----> Album12
....
Artist2
|
-----> Album21
-----> Album22
....
Artist3
.....
I'm using a sqlite3 database to mantain the links to the real files. The artists and albums elements are folders, and the tracks elements are links to the real ones.
I have achieved to create the folders for the artists and the albums. But now I have a problem.
I have this:
static int getattr(...) {
....
else if ( level == 0 || level == 1 || level == 2 )
{
// Estamos en el primer nivel. Son artistas, y por lo tanto, carpetas.
stbuf->st_mode = S_IFDIR | 0755;
stbuf->st_nlink = 2;
lstat(path, stbuf);
}
else if (level == 3) {
// Estamos en el tercer nivel. Son canciones, por lo que son enlaces
stbuf->st_mode = S_IFLNK | 0755;
stbuf->st_nlink = 2;
lstat(path, stbuf);
}
.....
}
And now, When I ls in the tracks directory y get a message that tells me that the function is not implemented (the links functions). Which function do I have to implement to know where the link points? Or where do I have to fill the direction of the pointer?
Thanks!
This seems to work for me:
Add a
int my_readlink(const char *path, char *buf, size_t size)
function, which yourstruct fuse_operations
member.readlink
should point to. For the symbolic link path, your function should fill the bufferbuf
with a zero-terminated string which is the path of the link target. Don't write more thansize
bytes. E.g. do something like:strncpy(buf, "/target/path", size);
In your
my_getattr()
function (whichstruct fuse_operations
member.getattr
should point to), for the symbolic link path, set in the 2nd parameter (struct stat * stbuf
):stbuf->st_mod
toS_IFLNK | 0777
stbuf->st_nlink
to1
stbuf->st_size
to the length of the target path (don't include the string's zero terminator in the length)
To implement symbolic links, you need to implement the readlink()
function - you fill a supplied buffer with a null-terminated string that is the target of the link.
You need to implement a readdir
function, see:
libfuse: fuse_operations Struct Reference
精彩评论