mirror of
https://github.com/torvalds/linux.git
synced 2024-11-23 20:51:44 +00:00
366911cd76
The number of dirent records used by an AFS directory entry should be
calculated using the assumption that there is a 16-byte name field in the
first block, rather than a 20-byte name field (which is actually the case).
This miscalculation is historic and effectively standard, so we have to use
it.
The calculation we need to use is:
1 + (((strlen(name) + 1) + 15) >> 5)
where we are adding one to the strlen() result to account for the NUL
termination.
Fix this by the following means:
(1) Create an inline function to do the calculation for a given name
length.
(2) Use the function to calculate the number of records used for a dirent
in afs_dir_iterate_block().
Use this to move the over-end check out of the loop since it only
needs to be done once.
Further use this to only go through the loop for the 2nd+ records
composing an entry. The only test there now is for if the record is
allocated - and we already checked the first block at the top of the
outer loop.
(3) Add a max name length check in afs_dir_iterate_block().
(4) Make afs_edit_dir_add() and afs_edit_dir_remove() use the function
from (1) to calculate the number of blocks rather than doing it
incorrectly themselves.
Fixes: 63a4681ff3
("afs: Locally edit directory data for mkdir/create/unlink/...")
Fixes: ^1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: David Howells <dhowells@redhat.com>
Tested-by: Marc Dionne <marc.dionne@auristor.com>
117 lines
2.7 KiB
C
117 lines
2.7 KiB
C
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
/* AFS fileserver XDR types
|
|
*
|
|
* Copyright (C) 2018 Red Hat, Inc. All Rights Reserved.
|
|
* Written by David Howells (dhowells@redhat.com)
|
|
*/
|
|
|
|
#ifndef XDR_FS_H
|
|
#define XDR_FS_H
|
|
|
|
struct afs_xdr_AFSFetchStatus {
|
|
__be32 if_version;
|
|
#define AFS_FSTATUS_VERSION 1
|
|
__be32 type;
|
|
__be32 nlink;
|
|
__be32 size_lo;
|
|
__be32 data_version_lo;
|
|
__be32 author;
|
|
__be32 owner;
|
|
__be32 caller_access;
|
|
__be32 anon_access;
|
|
__be32 mode;
|
|
__be32 parent_vnode;
|
|
__be32 parent_unique;
|
|
__be32 seg_size;
|
|
__be32 mtime_client;
|
|
__be32 mtime_server;
|
|
__be32 group;
|
|
__be32 sync_counter;
|
|
__be32 data_version_hi;
|
|
__be32 lock_count;
|
|
__be32 size_hi;
|
|
__be32 abort_code;
|
|
} __packed;
|
|
|
|
#define AFS_DIR_HASHTBL_SIZE 128
|
|
#define AFS_DIR_DIRENT_SIZE 32
|
|
#define AFS_DIR_SLOTS_PER_BLOCK 64
|
|
#define AFS_DIR_BLOCK_SIZE 2048
|
|
#define AFS_DIR_BLOCKS_PER_PAGE (PAGE_SIZE / AFS_DIR_BLOCK_SIZE)
|
|
#define AFS_DIR_MAX_SLOTS 65536
|
|
#define AFS_DIR_BLOCKS_WITH_CTR 128
|
|
#define AFS_DIR_MAX_BLOCKS 1023
|
|
#define AFS_DIR_RESV_BLOCKS 1
|
|
#define AFS_DIR_RESV_BLOCKS0 13
|
|
|
|
/*
|
|
* Directory entry structure.
|
|
*/
|
|
union afs_xdr_dirent {
|
|
struct {
|
|
u8 valid;
|
|
u8 unused[1];
|
|
__be16 hash_next;
|
|
__be32 vnode;
|
|
__be32 unique;
|
|
u8 name[];
|
|
/* When determining the number of dirent slots needed to
|
|
* represent a directory entry, name should be assumed to be 16
|
|
* bytes, due to a now-standardised (mis)calculation, but it is
|
|
* in fact 20 bytes in size. afs_dir_calc_slots() should be
|
|
* used for this.
|
|
*
|
|
* For names longer than (16 or) 20 bytes, extra slots should
|
|
* be annexed to this one using the extended_name format.
|
|
*/
|
|
} u;
|
|
u8 extended_name[32];
|
|
} __packed;
|
|
|
|
/*
|
|
* Directory block header (one at the beginning of every 2048-byte block).
|
|
*/
|
|
struct afs_xdr_dir_hdr {
|
|
__be16 npages;
|
|
__be16 magic;
|
|
#define AFS_DIR_MAGIC htons(1234)
|
|
u8 reserved;
|
|
u8 bitmap[8];
|
|
u8 pad[19];
|
|
} __packed;
|
|
|
|
/*
|
|
* Directory block layout
|
|
*/
|
|
union afs_xdr_dir_block {
|
|
struct afs_xdr_dir_hdr hdr;
|
|
|
|
struct {
|
|
struct afs_xdr_dir_hdr hdr;
|
|
u8 alloc_ctrs[AFS_DIR_MAX_BLOCKS];
|
|
__be16 hashtable[AFS_DIR_HASHTBL_SIZE];
|
|
} meta;
|
|
|
|
union afs_xdr_dirent dirents[AFS_DIR_SLOTS_PER_BLOCK];
|
|
} __packed;
|
|
|
|
/*
|
|
* Directory layout on a linux VM page.
|
|
*/
|
|
struct afs_xdr_dir_page {
|
|
union afs_xdr_dir_block blocks[AFS_DIR_BLOCKS_PER_PAGE];
|
|
};
|
|
|
|
/*
|
|
* Calculate the number of dirent slots required for any given name length.
|
|
* The calculation is made assuming the part of the name in the first slot is
|
|
* 16 bytes, rather than 20, but this miscalculation is now standardised.
|
|
*/
|
|
static inline unsigned int afs_dir_calc_slots(size_t name_len)
|
|
{
|
|
name_len++; /* NUL-terminated */
|
|
return 1 + ((name_len + 15) / AFS_DIR_DIRENT_SIZE);
|
|
}
|
|
|
|
#endif /* XDR_FS_H */
|