Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /*
0003  *   Copyright (C) 2021 Samsung Electronics Co., Ltd.
0004  */
0005 
0006 #ifndef __XATTR_H__
0007 #define __XATTR_H__
0008 
0009 /*
0010  * These are on-disk structures to store additional metadata into xattr to
0011  * reproduce windows filesystem semantics. And they are encoded with NDR to
0012  * compatible with samba's xattr meta format. The compatibility with samba
0013  * is important because it can lose the information(file attribute,
0014  * creation time, acls) about the existing files when switching between
0015  * ksmbd and samba.
0016  */
0017 
0018 /*
0019  * Dos attribute flags used for what variable is valid.
0020  */
0021 enum {
0022     XATTR_DOSINFO_ATTRIB        = 0x00000001,
0023     XATTR_DOSINFO_EA_SIZE       = 0x00000002,
0024     XATTR_DOSINFO_SIZE      = 0x00000004,
0025     XATTR_DOSINFO_ALLOC_SIZE    = 0x00000008,
0026     XATTR_DOSINFO_CREATE_TIME   = 0x00000010,
0027     XATTR_DOSINFO_CHANGE_TIME   = 0x00000020,
0028     XATTR_DOSINFO_ITIME     = 0x00000040
0029 };
0030 
0031 /*
0032  * Dos attribute structure which is compatible with samba's one.
0033  * Storing it into the xattr named "DOSATTRIB" separately from inode
0034  * allows ksmbd to faithfully reproduce windows filesystem semantics
0035  * on top of a POSIX filesystem.
0036  */
0037 struct xattr_dos_attrib {
0038     __u16   version;    /* version 3 or version 4 */
0039     __u32   flags;      /* valid flags */
0040     __u32   attr;       /* Dos attribute */
0041     __u32   ea_size;    /* EA size */
0042     __u64   size;
0043     __u64   alloc_size;
0044     __u64   create_time;    /* File creation time */
0045     __u64   change_time;    /* File change time */
0046     __u64   itime;      /* Invented/Initial time */
0047 };
0048 
0049 /*
0050  * Enumeration is used for computing posix acl hash.
0051  */
0052 enum {
0053     SMB_ACL_TAG_INVALID = 0,
0054     SMB_ACL_USER,
0055     SMB_ACL_USER_OBJ,
0056     SMB_ACL_GROUP,
0057     SMB_ACL_GROUP_OBJ,
0058     SMB_ACL_OTHER,
0059     SMB_ACL_MASK
0060 };
0061 
0062 #define SMB_ACL_READ            4
0063 #define SMB_ACL_WRITE           2
0064 #define SMB_ACL_EXECUTE         1
0065 
0066 struct xattr_acl_entry {
0067     int type;
0068     uid_t uid;
0069     gid_t gid;
0070     mode_t perm;
0071 };
0072 
0073 /*
0074  * xattr_smb_acl structure is used for computing posix acl hash.
0075  */
0076 struct xattr_smb_acl {
0077     int count;
0078     int next;
0079     struct xattr_acl_entry entries[];
0080 };
0081 
0082 /* 64bytes hash in xattr_ntacl is computed with sha256 */
0083 #define XATTR_SD_HASH_TYPE_SHA256   0x1
0084 #define XATTR_SD_HASH_SIZE      64
0085 
0086 /*
0087  * xattr_ntacl is used for storing ntacl and hashes.
0088  * Hash is used for checking valid posix acl and ntacl in xattr.
0089  */
0090 struct xattr_ntacl {
0091     __u16   version; /* version 4*/
0092     void    *sd_buf;
0093     __u32   sd_size;
0094     __u16   hash_type; /* hash type */
0095     __u8    desc[10]; /* posix_acl description */
0096     __u16   desc_len;
0097     __u64   current_time;
0098     __u8    hash[XATTR_SD_HASH_SIZE]; /* 64bytes hash for ntacl */
0099     __u8    posix_acl_hash[XATTR_SD_HASH_SIZE]; /* 64bytes hash for posix acl */
0100 };
0101 
0102 /* DOS ATTRIBUITE XATTR PREFIX */
0103 #define DOS_ATTRIBUTE_PREFIX        "DOSATTRIB"
0104 #define DOS_ATTRIBUTE_PREFIX_LEN    (sizeof(DOS_ATTRIBUTE_PREFIX) - 1)
0105 #define XATTR_NAME_DOS_ATTRIBUTE    (XATTR_USER_PREFIX DOS_ATTRIBUTE_PREFIX)
0106 #define XATTR_NAME_DOS_ATTRIBUTE_LEN    \
0107         (sizeof(XATTR_USER_PREFIX DOS_ATTRIBUTE_PREFIX) - 1)
0108 
0109 /* STREAM XATTR PREFIX */
0110 #define STREAM_PREFIX           "DosStream."
0111 #define STREAM_PREFIX_LEN       (sizeof(STREAM_PREFIX) - 1)
0112 #define XATTR_NAME_STREAM       (XATTR_USER_PREFIX STREAM_PREFIX)
0113 #define XATTR_NAME_STREAM_LEN       (sizeof(XATTR_NAME_STREAM) - 1)
0114 
0115 /* SECURITY DESCRIPTOR(NTACL) XATTR PREFIX */
0116 #define SD_PREFIX           "NTACL"
0117 #define SD_PREFIX_LEN   (sizeof(SD_PREFIX) - 1)
0118 #define XATTR_NAME_SD   (XATTR_SECURITY_PREFIX SD_PREFIX)
0119 #define XATTR_NAME_SD_LEN   \
0120         (sizeof(XATTR_SECURITY_PREFIX SD_PREFIX) - 1)
0121 
0122 #endif /* __XATTR_H__ */