Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setxattr fails with Operation not supported

Tags:

c

linux

I am trying to set the file attributes as follows:

  1. create file foo.txt with 0644 permissions
  2. when I am trying to setxattr for this as

    if (setxattr("foo.txt", "user.test", "test", 4, XATTR_CREATE) == -1)
        perror("");
    

I am getting the error as Operation not supported

Is there any thing to enable? How to resolve this?

like image 930
Venkat S A Avatar asked Oct 28 '25 08:10

Venkat S A


1 Answers

From setxattr

RETURN VALUE

   On success, zero is returned.  On failure, -1 is returned and errno is set
   appropriately.  
   ...  
   If extended attributes are not supported by the file system, or are disabled,
   errno is set to ENOTSUP.

So, either your file system doesn't support extended attributes (ext[234], cifs, btrfs do, for example) or they are disabled at the kernel build or at mount time.

For NFS there is no separate switch to enable extended attributes in the kernel config. From the source fs/nfs/dir.c, it seems to be enabled, when you enable support for CONFIG_NFS_V3 or CONFIG_NFS_V4. But NFS still depends on the underlying file system. So you must enable extended attributes on the server side as well.

From man mount

Mount options for ext2
...
user_xattr|nouser_xattr
Support "user." extended attributes (or not).

like image 82
Olaf Dietsche Avatar answered Oct 29 '25 23:10

Olaf Dietsche