extattr.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*-
  2. * Copyright (c) 1999-2001 Robert N. M. Watson
  3. * All rights reserved.
  4. *
  5. * This software was developed by Robert Watson for the TrustedBSD Project.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  17. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  18. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  19. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  20. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  21. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  22. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  23. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  24. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  25. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  26. * SUCH DAMAGE.
  27. *
  28. * $FreeBSD$
  29. */
  30. /*
  31. * Developed by the TrustedBSD Project.
  32. * Support for extended filesystem attributes.
  33. */
  34. #define UFS_EXTATTR_MAGIC 0x00b5d5ec
  35. #define UFS_EXTATTR_VERSION 0x00000003
  36. #define UFS_EXTATTR_FSROOTSUBDIR ".attribute"
  37. #define UFS_EXTATTR_SUBDIR_SYSTEM "system"
  38. #define UFS_EXTATTR_SUBDIR_USER "user"
  39. #define UFS_EXTATTR_MAXEXTATTRNAME 65 /* including null */
  40. #define UFS_EXTATTR_ATTR_FLAG_INUSE 0x00000001 /* attr has been set */
  41. #define UFS_EXTATTR_PERM_KERNEL 0x00000000
  42. #define UFS_EXTATTR_PERM_ROOT 0x00000001
  43. #define UFS_EXTATTR_PERM_OWNER 0x00000002
  44. #define UFS_EXTATTR_PERM_ANYONE 0x00000003
  45. #define UFS_EXTATTR_UEPM_INITIALIZED 0x00000001
  46. #define UFS_EXTATTR_UEPM_STARTED 0x00000002
  47. #define UFS_EXTATTR_CMD_START 0x00000001
  48. #define UFS_EXTATTR_CMD_STOP 0x00000002
  49. #define UFS_EXTATTR_CMD_ENABLE 0x00000003
  50. #define UFS_EXTATTR_CMD_DISABLE 0x00000004
  51. struct ufs_extattr_fileheader {
  52. uint uef_magic; /* magic number for sanity checking */
  53. uint uef_version; /* version of attribute file */
  54. uint uef_size; /* size of attributes, w/o header */
  55. };
  56. struct ufs_extattr_header {
  57. uint ueh_flags; /* flags for attribute */
  58. uint ueh_len; /* local defined length; <= uef_size */
  59. uint32_t ueh_i_gen; /* generation number for sanity */
  60. /* data follows the header */
  61. };
  62. /*
  63. * This structure defines the required fields of an extended-attribute header.
  64. */
  65. struct extattr {
  66. uint32_t ea_length; /* length of this attribute */
  67. uint8_t ea_namespace; /* name space of this attribute */
  68. uint8_t ea_contentpadlen; /* bytes of padding at end of attribute */
  69. uint8_t ea_namelength; /* length of attribute name */
  70. char ea_name[1]; /* attribute name (NOT nul-terminated) */
  71. /* padding, if any, to align attribute content to 8 byte boundary */
  72. /* extended attribute content follows */
  73. };
  74. /*
  75. * These macros are used to access and manipulate an extended attribute:
  76. *
  77. * EXTATTR_NEXT(eap) returns a pointer to the next extended attribute
  78. * following eap.
  79. * EXTATTR_CONTENT(eap) returns a pointer to the extended attribute
  80. * content referenced by eap.
  81. * EXTATTR_CONTENT_SIZE(eap) returns the size of the extended attribute
  82. * content referenced by eap.
  83. */
  84. #define EXTATTR_NEXT(eap) \
  85. ((struct extattr *)(((uint8_t *)(eap)) + (eap)->ea_length))
  86. #define EXTATTR_CONTENT(eap) \
  87. (void *)(((uint8_t *)(eap)) + EXTATTR_BASE_LENGTH(eap))
  88. #define EXTATTR_CONTENT_SIZE(eap) \
  89. ((eap)->ea_length - EXTATTR_BASE_LENGTH(eap) - (eap)->ea_contentpadlen)
  90. /* -1 below compensates for ea_name[1] */
  91. #define EXTATTR_BASE_LENGTH(eap) \
  92. roundup2((sizeof(struct extattr) - 1 + (eap)->ea_namelength), 8)
  93. struct vnode;
  94. LIST_HEAD(ufs_extattr_list_head, ufs_extattr_list_entry);
  95. struct ufs_extattr_list_entry {
  96. LIST_ENTRY(ufs_extattr_list_entry) uele_entries;
  97. struct ufs_extattr_fileheader uele_fileheader;
  98. int uele_attrnamespace;
  99. char uele_attrname[UFS_EXTATTR_MAXEXTATTRNAME];
  100. struct vnode *uele_backing_vnode;
  101. };
  102. struct ucred;
  103. struct ufs_extattr_per_mount {
  104. struct sx uepm_lock;
  105. struct ufs_extattr_list_head uepm_list;
  106. struct ucred *uepm_ucred;
  107. int uepm_flags;
  108. };
  109. struct vop_getextattr_args;
  110. struct vop_deleteextattr_args;
  111. struct vop_setextattr_args;
  112. void ufs_extattr_uepm_init(struct ufs_extattr_per_mount *uepm);
  113. void ufs_extattr_uepm_destroy(struct ufs_extattr_per_mount *uepm);
  114. int ufs_extattr_start(struct mount *mp, struct thread *td);
  115. int ufs_extattr_autostart(struct mount *mp, struct thread *td);
  116. int ufs_extattr_stop(struct mount *mp, struct thread *td);
  117. int ufs_extattrctl(struct mount *mp, int cmd, struct vnode *filename,
  118. int attrnamespace, const char *attrname);
  119. int ufs_getextattr(struct vop_getextattr_args *ap);
  120. int ufs_deleteextattr(struct vop_deleteextattr_args *ap);
  121. int ufs_setextattr(struct vop_setextattr_args *ap);
  122. void ufs_extattr_vnode_inactive(struct vnode *vp, struct thread *td);