xdr_fs.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /* AFS fileserver XDR types
  3. *
  4. * Copyright (C) 2018 Red Hat, Inc. All Rights Reserved.
  5. * Written by David Howells ([email protected])
  6. */
  7. #ifndef XDR_FS_H
  8. #define XDR_FS_H
  9. struct afs_xdr_AFSFetchStatus {
  10. __be32 if_version;
  11. #define AFS_FSTATUS_VERSION 1
  12. __be32 type;
  13. __be32 nlink;
  14. __be32 size_lo;
  15. __be32 data_version_lo;
  16. __be32 author;
  17. __be32 owner;
  18. __be32 caller_access;
  19. __be32 anon_access;
  20. __be32 mode;
  21. __be32 parent_vnode;
  22. __be32 parent_unique;
  23. __be32 seg_size;
  24. __be32 mtime_client;
  25. __be32 mtime_server;
  26. __be32 group;
  27. __be32 sync_counter;
  28. __be32 data_version_hi;
  29. __be32 lock_count;
  30. __be32 size_hi;
  31. __be32 abort_code;
  32. } __packed;
  33. #define AFS_DIR_HASHTBL_SIZE 128
  34. #define AFS_DIR_DIRENT_SIZE 32
  35. #define AFS_DIR_SLOTS_PER_BLOCK 64
  36. #define AFS_DIR_BLOCK_SIZE 2048
  37. #define AFS_DIR_BLOCKS_PER_PAGE (PAGE_SIZE / AFS_DIR_BLOCK_SIZE)
  38. #define AFS_DIR_MAX_SLOTS 65536
  39. #define AFS_DIR_BLOCKS_WITH_CTR 128
  40. #define AFS_DIR_MAX_BLOCKS 1023
  41. #define AFS_DIR_RESV_BLOCKS 1
  42. #define AFS_DIR_RESV_BLOCKS0 13
  43. /*
  44. * Directory entry structure.
  45. */
  46. union afs_xdr_dirent {
  47. struct {
  48. u8 valid;
  49. u8 unused[1];
  50. __be16 hash_next;
  51. __be32 vnode;
  52. __be32 unique;
  53. u8 name[];
  54. /* When determining the number of dirent slots needed to
  55. * represent a directory entry, name should be assumed to be 16
  56. * bytes, due to a now-standardised (mis)calculation, but it is
  57. * in fact 20 bytes in size. afs_dir_calc_slots() should be
  58. * used for this.
  59. *
  60. * For names longer than (16 or) 20 bytes, extra slots should
  61. * be annexed to this one using the extended_name format.
  62. */
  63. } u;
  64. u8 extended_name[32];
  65. } __packed;
  66. /*
  67. * Directory block header (one at the beginning of every 2048-byte block).
  68. */
  69. struct afs_xdr_dir_hdr {
  70. __be16 npages;
  71. __be16 magic;
  72. #define AFS_DIR_MAGIC htons(1234)
  73. u8 reserved;
  74. u8 bitmap[8];
  75. u8 pad[19];
  76. } __packed;
  77. /*
  78. * Directory block layout
  79. */
  80. union afs_xdr_dir_block {
  81. struct afs_xdr_dir_hdr hdr;
  82. struct {
  83. struct afs_xdr_dir_hdr hdr;
  84. u8 alloc_ctrs[AFS_DIR_MAX_BLOCKS];
  85. __be16 hashtable[AFS_DIR_HASHTBL_SIZE];
  86. } meta;
  87. union afs_xdr_dirent dirents[AFS_DIR_SLOTS_PER_BLOCK];
  88. } __packed;
  89. /*
  90. * Directory layout on a linux VM page.
  91. */
  92. struct afs_xdr_dir_page {
  93. union afs_xdr_dir_block blocks[AFS_DIR_BLOCKS_PER_PAGE];
  94. };
  95. /*
  96. * Calculate the number of dirent slots required for any given name length.
  97. * The calculation is made assuming the part of the name in the first slot is
  98. * 16 bytes, rather than 20, but this miscalculation is now standardised.
  99. */
  100. static inline unsigned int afs_dir_calc_slots(size_t name_len)
  101. {
  102. name_len++; /* NUL-terminated */
  103. return 1 + ((name_len + 15) / AFS_DIR_DIRENT_SIZE);
  104. }
  105. #endif /* XDR_FS_H */