如何在FUSE中建立符号链接?
我正在开发一个 FUSE 应用程序,它采用一个包含 mp3 的目录,并在另一个具有以下结构的目录中安装文件系统(根据其标签):
Artist1
|
-----> Album11
|
-----> Track01
-----> Track02
-----> Track03
-----> Track04
-----> Track05
-----> Album12
....
Artist2
|
-----> Album21
-----> Album22
....
Artist3
.....
我正在使用 sqlite3 数据库来维护到真实文件的链接。艺术家和专辑元素是文件夹,曲目元素是指向真实元素的链接。
我已经成功地为艺术家和专辑创建了文件夹。但现在我有一个问题。
我有这个:
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);
}
.....
}
现在,当我进入曲目目录时,您会收到一条消息,告诉我该功能未实现(链接功能)。我必须实现哪个函数才能知道链接指向哪里?或者我必须在哪里填充指针的方向?
谢谢!
I'm developing a FUSE app that takes a directory 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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这似乎对我有用:
添加一个
int my_readlink(const char *path, char *buf, size_t size)
函数,您的struct fusion_operations
成员.readlink
应该指向。对于符号链接路径,您的函数应使用一个以零结尾的字符串填充缓冲区buf
,该字符串是链接目标的路径。不要写入超过size
字节。例如,做类似的事情:在您的
my_getattr()
函数中(其中struct fusion_operations
成员.getattr
应该指向),对于符号链接路径,在第二个参数中设置(struct stat * stbuf ):
stbuf->st_mod
到S_IFLNK |第0777章
stbuf->st_nlink
到1
stbuf->st_size
为目标路径的长度(长度中不包括字符串的零终止符)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: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)要实现符号链接,您需要实现 readlink() 函数 - 使用作为链接目标的空终止字符串填充提供的缓冲区。
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.您需要实现一个
readdir
函数,请参阅:libfuse:fuse_operations Struct Reference
You need to implement a
readdir
function, see:libfuse: fuse_operations Struct Reference