How to make symbolic links in FUSE?
Asked Answered
H

3

7

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!

Haruspex answered 23/5, 2011 at 10:50 Comment(0)
N
5

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)
Nisa answered 9/4, 2013 at 5:55 Comment(0)
M
1

You need to implement a readdir function, see:

libfuse: fuse_operations Struct Reference

Malignity answered 23/5, 2011 at 13:24 Comment(1)
It's implemented but I don't know how to implement it to link to the desire filesHaruspex
A
1

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.

Anastasius answered 24/5, 2011 at 3:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.