title: FUSE Extended Attributes
body: <p>I'm trying to implement a FUSE file system including the ability to set/get extended file attributes. In this case, the attribute that I am interested in is one to create a boolean condition to mark a file as encrypted. Let's say that I have a file called test.txt. From a terminal window, I can easily do the following:</p>
  <blockquote>
  <p>setfattr -n user.encrypted -v 1 test.txt</p>
  <p>getfattr -n user.encrypted test.txt</p>
  </blockquote>
  <p>and get the output:</p>
  <blockquote>
  <p># file: test.txt</p>
  <p>user.encrypted=&quot;1&quot;</p>
  </blockquote>
  <p>So, I know that my system is correctly set to work with extended attributes.</p>
  <p>But I'm stuck on setting and getting these attributes programatically from within FUSE. For example, I have the following function:</p>
  <pre><code>/* File open operation */
  int bb_open(const char *path, struct fuse_file_info *fi)
  {
      int retstat = 0;
      int fd;
      int isEncrypted;
      char user[] = &quot;user&quot;;
      char encAttr[] = &quot;encrypted&quot;;
      
      fd = open(path, fi-&gt;flags);
      if (fd &lt; 0)
          retstat = bb_error(&quot;bb_open open&quot;);
            
      log_msg(&quot;\nAbout to get encryption attribute\n&quot;);  
      /* get the encryption attribute */
      isEncrypted = fgetxattr(fd, user, encAttr, 1);
      
      log_msg(&quot;\nisEncrypted: %d\n&quot;, isEncrypted);
  
      return retstat;
  }
  </code></pre>
  <p>When I run this, even after setting this attribute from the command line, fgetxattr always fails (i.e. it returns a value of -1). The output in my log file is:</p>
  <blockquote>
  <p>isEncrypted = -1</p>
  </blockquote>
  <p>Clearly I'm calling this function incorrectly, but I don't know how to correct this. Can anyone help? Thanks.</p>