Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /* AFS fileserver XDR types
0003  *
0004  * Copyright (C) 2018 Red Hat, Inc. All Rights Reserved.
0005  * Written by David Howells (dhowells@redhat.com)
0006  */
0007 
0008 #ifndef XDR_FS_H
0009 #define XDR_FS_H
0010 
0011 struct afs_xdr_AFSFetchStatus {
0012     __be32  if_version;
0013 #define AFS_FSTATUS_VERSION 1
0014     __be32  type;
0015     __be32  nlink;
0016     __be32  size_lo;
0017     __be32  data_version_lo;
0018     __be32  author;
0019     __be32  owner;
0020     __be32  caller_access;
0021     __be32  anon_access;
0022     __be32  mode;
0023     __be32  parent_vnode;
0024     __be32  parent_unique;
0025     __be32  seg_size;
0026     __be32  mtime_client;
0027     __be32  mtime_server;
0028     __be32  group;
0029     __be32  sync_counter;
0030     __be32  data_version_hi;
0031     __be32  lock_count;
0032     __be32  size_hi;
0033     __be32  abort_code;
0034 } __packed;
0035 
0036 #define AFS_DIR_HASHTBL_SIZE    128
0037 #define AFS_DIR_DIRENT_SIZE 32
0038 #define AFS_DIR_SLOTS_PER_BLOCK 64
0039 #define AFS_DIR_BLOCK_SIZE  2048
0040 #define AFS_DIR_BLOCKS_PER_PAGE (PAGE_SIZE / AFS_DIR_BLOCK_SIZE)
0041 #define AFS_DIR_MAX_SLOTS   65536
0042 #define AFS_DIR_BLOCKS_WITH_CTR 128
0043 #define AFS_DIR_MAX_BLOCKS  1023
0044 #define AFS_DIR_RESV_BLOCKS 1
0045 #define AFS_DIR_RESV_BLOCKS0    13
0046 
0047 /*
0048  * Directory entry structure.
0049  */
0050 union afs_xdr_dirent {
0051     struct {
0052         u8      valid;
0053         u8      unused[1];
0054         __be16      hash_next;
0055         __be32      vnode;
0056         __be32      unique;
0057         u8      name[];
0058         /* When determining the number of dirent slots needed to
0059          * represent a directory entry, name should be assumed to be 16
0060          * bytes, due to a now-standardised (mis)calculation, but it is
0061          * in fact 20 bytes in size.  afs_dir_calc_slots() should be
0062          * used for this.
0063          *
0064          * For names longer than (16 or) 20 bytes, extra slots should
0065          * be annexed to this one using the extended_name format.
0066          */
0067     } u;
0068     u8          extended_name[32];
0069 } __packed;
0070 
0071 /*
0072  * Directory block header (one at the beginning of every 2048-byte block).
0073  */
0074 struct afs_xdr_dir_hdr {
0075     __be16      npages;
0076     __be16      magic;
0077 #define AFS_DIR_MAGIC htons(1234)
0078     u8      reserved;
0079     u8      bitmap[8];
0080     u8      pad[19];
0081 } __packed;
0082 
0083 /*
0084  * Directory block layout
0085  */
0086 union afs_xdr_dir_block {
0087     struct afs_xdr_dir_hdr      hdr;
0088 
0089     struct {
0090         struct afs_xdr_dir_hdr  hdr;
0091         u8          alloc_ctrs[AFS_DIR_MAX_BLOCKS];
0092         __be16          hashtable[AFS_DIR_HASHTBL_SIZE];
0093     } meta;
0094 
0095     union afs_xdr_dirent    dirents[AFS_DIR_SLOTS_PER_BLOCK];
0096 } __packed;
0097 
0098 /*
0099  * Directory layout on a linux VM page.
0100  */
0101 struct afs_xdr_dir_page {
0102     union afs_xdr_dir_block blocks[AFS_DIR_BLOCKS_PER_PAGE];
0103 };
0104 
0105 /*
0106  * Calculate the number of dirent slots required for any given name length.
0107  * The calculation is made assuming the part of the name in the first slot is
0108  * 16 bytes, rather than 20, but this miscalculation is now standardised.
0109  */
0110 static inline unsigned int afs_dir_calc_slots(size_t name_len)
0111 {
0112     name_len++; /* NUL-terminated */
0113     return 1 + ((name_len + 15) / AFS_DIR_DIRENT_SIZE);
0114 }
0115 
0116 #endif /* XDR_FS_H */