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 your- struct fuse_operationsmember- .readlinkshould point to. For the symbolic link path, your function should fill the buffer- bufwith a zero-terminated string which is the path of the link target. Don't write more than- sizebytes. E.g. do something like:- strncpy(buf, "/target/path", size);
- In your - my_getattr()function (which- struct fuse_operationsmember- .getattrshould point to), for the symbolic link path, set in the 2nd parameter (- struct stat * stbuf):- stbuf->st_modto- S_IFLNK | 0777
- stbuf->st_nlinkto- 1
- stbuf->st_sizeto 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
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论