如何在FUSE中建立符号链接?

发布于 2024-11-09 07:46:44 字数 1250 浏览 0 评论 0原文

我正在开发一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

北凤男飞 2024-11-16 07:46:44

这似乎对我有用:

  1. 添加一个int my_readlink(const char *path, char *buf, size_t size)函数,您的struct fusion_operations成员.readlink 应该指向。对于符号链接路径,您的函数应使用一个以零结尾的字符串填充缓冲区 buf,该字符串是链接目标的路径。不要写入超过 size 字节。例如,做类似的事情:

    strncpy(buf, "/目标/路径", 大小);
    
  2. 在您的 my_getattr() 函数中(其中 struct fusion_operations 成员.getattr 应该指向),对于符号链接路径,在第二个参数中设置(struct stat * stbuf ):

    • stbuf->st_modS_IFLNK |第0777章
    • stbuf->st_nlink1
    • stbuf->st_size 为目标路径的长度(长度中不包括字符串的零终止符)

This seems to work for me:

  1. Add a int my_readlink(const char *path, char *buf, size_t size) function, which your struct fuse_operations member .readlink should point to. For the symbolic link path, your function should fill the buffer buf with a zero-terminated string which is the path of the link target. Don't write more than size bytes. E.g. do something like:

    strncpy(buf, "/target/path", size);
    
  2. In your my_getattr() function (which struct fuse_operations member .getattr should point to), for the symbolic link path, set in the 2nd parameter (struct stat * stbuf):

    • stbuf->st_mod to S_IFLNK | 0777
    • stbuf->st_nlink to 1
    • stbuf->st_size to the length of the target path (don't include the string's zero terminator in the length)
简单气质女生网名 2024-11-16 07:46:44

要实现符号链接,您需要实现 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.

幽梦紫曦~ 2024-11-16 07:46:44

您需要实现一个 readdir 函数,请参阅:

libfuse:fuse_operations Struct Reference

You need to implement a readdir function, see:

libfuse: fuse_operations Struct Reference

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文