2013-02-14 103 views
3

我想設置文件屬性如下:setxattr失敗,不支持的操作

  1. 創建文件foo.txt的有0644權限
  2. 當我試圖爲這個setxattr作爲

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

我收到錯誤的操作,不支持

有什麼要啓用的嗎? 如何解決這個問題?

+2

你的文件系統是否支持它?使用'user_xattr'掛載選項重新掛載可能會有所幫助。 – 2013-02-14 10:19:01

+0

你在使用哪個文件系統? – 2013-02-14 10:19:30

+1

我正在使用nfs文件系統 – 2013-02-14 10:38:24

回答

5

setxattr

返回值

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. 

所以,無論是你的文件系統不支持擴展屬性(分機[234],CIFS,BTRFS做,例如),或者它們在內核構建或安裝時被禁用。

對於NFS,沒有單獨的開關在內核配置中啓用擴展屬性。來源fs/nfs/dir.c,它似乎啓用,當您啓用CONFIG_NFS_V3CONFIG_NFS_V4的支持。但是NFS仍然依賴於底層的文件系統。所以你必須在服務器端啓用擴展屬性。

man mount

安裝選項的ext2
...
user_xattr | nouser_xattr
支持 「用戶」。擴展屬性(或不)。

+0

如何在Linux內核中啓用nfs文件系統的擴展屬性? – 2013-02-14 10:42:50

+1

@AntonKovalenko在'fs/nfs */*。c'中搜索'xattr'。 – 2013-02-14 10:51:30

+0

@Venkat請參閱更新的答案。 – 2013-02-14 11:04:19