xattr.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * Copyright (C) 2021 Samsung Electronics Co., Ltd.
  4. */
  5. #ifndef __XATTR_H__
  6. #define __XATTR_H__
  7. /*
  8. * These are on-disk structures to store additional metadata into xattr to
  9. * reproduce windows filesystem semantics. And they are encoded with NDR to
  10. * compatible with samba's xattr meta format. The compatibility with samba
  11. * is important because it can lose the information(file attribute,
  12. * creation time, acls) about the existing files when switching between
  13. * ksmbd and samba.
  14. */
  15. /*
  16. * Dos attribute flags used for what variable is valid.
  17. */
  18. enum {
  19. XATTR_DOSINFO_ATTRIB = 0x00000001,
  20. XATTR_DOSINFO_EA_SIZE = 0x00000002,
  21. XATTR_DOSINFO_SIZE = 0x00000004,
  22. XATTR_DOSINFO_ALLOC_SIZE = 0x00000008,
  23. XATTR_DOSINFO_CREATE_TIME = 0x00000010,
  24. XATTR_DOSINFO_CHANGE_TIME = 0x00000020,
  25. XATTR_DOSINFO_ITIME = 0x00000040
  26. };
  27. /*
  28. * Dos attribute structure which is compatible with samba's one.
  29. * Storing it into the xattr named "DOSATTRIB" separately from inode
  30. * allows ksmbd to faithfully reproduce windows filesystem semantics
  31. * on top of a POSIX filesystem.
  32. */
  33. struct xattr_dos_attrib {
  34. __u16 version; /* version 3 or version 4 */
  35. __u32 flags; /* valid flags */
  36. __u32 attr; /* Dos attribute */
  37. __u32 ea_size; /* EA size */
  38. __u64 size;
  39. __u64 alloc_size;
  40. __u64 create_time; /* File creation time */
  41. __u64 change_time; /* File change time */
  42. __u64 itime; /* Invented/Initial time */
  43. };
  44. /*
  45. * Enumeration is used for computing posix acl hash.
  46. */
  47. enum {
  48. SMB_ACL_TAG_INVALID = 0,
  49. SMB_ACL_USER,
  50. SMB_ACL_USER_OBJ,
  51. SMB_ACL_GROUP,
  52. SMB_ACL_GROUP_OBJ,
  53. SMB_ACL_OTHER,
  54. SMB_ACL_MASK
  55. };
  56. #define SMB_ACL_READ 4
  57. #define SMB_ACL_WRITE 2
  58. #define SMB_ACL_EXECUTE 1
  59. struct xattr_acl_entry {
  60. int type;
  61. uid_t uid;
  62. gid_t gid;
  63. mode_t perm;
  64. };
  65. /*
  66. * xattr_smb_acl structure is used for computing posix acl hash.
  67. */
  68. struct xattr_smb_acl {
  69. int count;
  70. int next;
  71. struct xattr_acl_entry entries[] __counted_by(count);
  72. };
  73. /* 64bytes hash in xattr_ntacl is computed with sha256 */
  74. #define XATTR_SD_HASH_TYPE_SHA256 0x1
  75. #define XATTR_SD_HASH_SIZE 64
  76. /*
  77. * xattr_ntacl is used for storing ntacl and hashes.
  78. * Hash is used for checking valid posix acl and ntacl in xattr.
  79. */
  80. struct xattr_ntacl {
  81. __u16 version; /* version 4*/
  82. void *sd_buf;
  83. __u32 sd_size;
  84. __u16 hash_type; /* hash type */
  85. __u8 desc[10]; /* posix_acl description */
  86. __u16 desc_len;
  87. __u64 current_time;
  88. __u8 hash[XATTR_SD_HASH_SIZE]; /* 64bytes hash for ntacl */
  89. __u8 posix_acl_hash[XATTR_SD_HASH_SIZE]; /* 64bytes hash for posix acl */
  90. };
  91. /* DOS ATTRIBUTE XATTR PREFIX */
  92. #define DOS_ATTRIBUTE_PREFIX "DOSATTRIB"
  93. #define DOS_ATTRIBUTE_PREFIX_LEN (sizeof(DOS_ATTRIBUTE_PREFIX) - 1)
  94. #define XATTR_NAME_DOS_ATTRIBUTE (XATTR_USER_PREFIX DOS_ATTRIBUTE_PREFIX)
  95. #define XATTR_NAME_DOS_ATTRIBUTE_LEN \
  96. (sizeof(XATTR_USER_PREFIX DOS_ATTRIBUTE_PREFIX) - 1)
  97. /* STREAM XATTR PREFIX */
  98. #define STREAM_PREFIX "DosStream."
  99. #define STREAM_PREFIX_LEN (sizeof(STREAM_PREFIX) - 1)
  100. #define XATTR_NAME_STREAM (XATTR_USER_PREFIX STREAM_PREFIX)
  101. #define XATTR_NAME_STREAM_LEN (sizeof(XATTR_NAME_STREAM) - 1)
  102. /* SECURITY DESCRIPTOR(NTACL) XATTR PREFIX */
  103. #define SD_PREFIX "NTACL"
  104. #define SD_PREFIX_LEN (sizeof(SD_PREFIX) - 1)
  105. #define XATTR_NAME_SD (XATTR_SECURITY_PREFIX SD_PREFIX)
  106. #define XATTR_NAME_SD_LEN \
  107. (sizeof(XATTR_SECURITY_PREFIX SD_PREFIX) - 1)
  108. #endif /* __XATTR_H__ */