From 3387b28a34890ed41d919a01cf95a91605c1dc8e Mon Sep 17 00:00:00 2001 From: Christoph Hellwig Date: Wed, 31 Jul 2024 10:23:01 -0700 Subject: [PATCH] xfs: push down unsigned char casts Source kernel commit: 9392ed7300c3b4e70778156de1bc84a4c40c413b To get us of casting hell, push down the casts to the unsigned char to the low-level hash code and the on-disk format definitions. The hash code is the only place that actually cares about the signedness. The on-disk format would be cleaner by not using it, but using it is a correct headsup to worry about the signedness. Note that right now this only really matters for userspace, as the kernel forces -funsigned-char for all architectures. Signed-off-by: Christoph Hellwig --- libxfs/xfs_attr.c | 4 ++-- libxfs/xfs_attr.h | 4 ++-- libxfs/xfs_attr_leaf.c | 4 ++-- libxfs/xfs_da_btree.c | 3 ++- libxfs/xfs_da_btree.h | 6 +++--- libxfs/xfs_dir2.c | 4 ++-- libxfs/xfs_dir2_block.c | 6 +++--- libxfs/xfs_dir2_data.c | 2 +- libxfs/xfs_parent.c | 6 +++--- libxfs/xfs_parent.h | 6 +++--- libxfs/xfs_types.h | 2 +- 11 files changed, 24 insertions(+), 23 deletions(-) diff --git a/libxfs/xfs_attr.c b/libxfs/xfs_attr.c index 9e1cce577..e89b09d2c 100644 --- a/libxfs/xfs_attr.c +++ b/libxfs/xfs_attr.c @@ -412,7 +412,7 @@ out: /* Compute the hash value for a user/root/secure extended attribute */ xfs_dahash_t xfs_attr_hashname( - const uint8_t *name, + const char *name, int namelen) { return xfs_da_hashname(name, namelen); @@ -423,7 +423,7 @@ xfs_dahash_t xfs_attr_hashval( struct xfs_mount *mp, unsigned int attr_flags, - const uint8_t *name, + const char *name, int namelen, const void *value, int valuelen) diff --git a/libxfs/xfs_attr.h b/libxfs/xfs_attr.h index 0e51d0723..a1079ef94 100644 --- a/libxfs/xfs_attr.h +++ b/libxfs/xfs_attr.h @@ -628,10 +628,10 @@ xfs_attr_init_replace_state(struct xfs_da_args *args) return xfs_attr_init_add_state(args); } -xfs_dahash_t xfs_attr_hashname(const uint8_t *name, int namelen); +xfs_dahash_t xfs_attr_hashname(const char *name, int namelen); xfs_dahash_t xfs_attr_hashval(struct xfs_mount *mp, unsigned int attr_flags, - const uint8_t *name, int namelen, const void *value, + const char *name, int namelen, const void *value, int valuelen); /* Set the hash value for any extended attribute from any namespace. */ diff --git a/libxfs/xfs_attr_leaf.c b/libxfs/xfs_attr_leaf.c index ce20d81a4..684b838b7 100644 --- a/libxfs/xfs_attr_leaf.c +++ b/libxfs/xfs_attr_leaf.c @@ -979,7 +979,7 @@ xfs_attr_shortform_to_leaf( sfe = xfs_attr_sf_firstentry(sf); for (i = 0; i < sf->count; i++) { - nargs.name = sfe->nameval; + nargs.name = (const char *)sfe->nameval; nargs.namelen = sfe->namelen; nargs.value = &sfe->nameval[nargs.namelen]; nargs.valuelen = sfe->valuelen; @@ -1191,7 +1191,7 @@ xfs_attr3_leaf_to_shortform( continue; ASSERT(entry->flags & XFS_ATTR_LOCAL); name_loc = xfs_attr3_leaf_name_local(leaf, i); - nargs.name = name_loc->nameval; + nargs.name = (const char *)name_loc->nameval; nargs.namelen = name_loc->namelen; nargs.value = &name_loc->nameval[nargs.namelen]; nargs.valuelen = be16_to_cpu(name_loc->valuelen); diff --git a/libxfs/xfs_da_btree.c b/libxfs/xfs_da_btree.c index 820e85752..29386c702 100644 --- a/libxfs/xfs_da_btree.c +++ b/libxfs/xfs_da_btree.c @@ -2246,8 +2246,9 @@ xfs_da3_path_shift( * This is implemented with some source-level loop unrolling. */ xfs_dahash_t -xfs_da_hashname(const uint8_t *name, int namelen) +xfs_da_hashname(const char *_name, int namelen) { + const uint8_t *name = (const uint8_t *)_name; xfs_dahash_t hash; /* diff --git a/libxfs/xfs_da_btree.h b/libxfs/xfs_da_btree.h index 354d5d650..aef9bd61c 100644 --- a/libxfs/xfs_da_btree.h +++ b/libxfs/xfs_da_btree.h @@ -54,8 +54,8 @@ enum xfs_dacmp { */ typedef struct xfs_da_args { struct xfs_da_geometry *geo; /* da block geometry */ - const uint8_t *name; /* string (maybe not NULL terminated) */ - const uint8_t *new_name; /* new attr name */ + const char *name; /* string (maybe not NULL terminated) */ + const char *new_name; /* new attr name */ void *value; /* set of bytes (maybe contain NULLs) */ void *new_value; /* new xattr value (may contain NULLs) */ struct xfs_inode *dp; /* directory inode to manipulate */ @@ -224,7 +224,7 @@ int xfs_da_shrink_inode(xfs_da_args_t *args, xfs_dablk_t dead_blkno, void xfs_da_buf_copy(struct xfs_buf *dst, struct xfs_buf *src, size_t size); -uint xfs_da_hashname(const uint8_t *name_string, int name_length); +uint xfs_da_hashname(const char *name_string, int name_length); enum xfs_dacmp xfs_da_compname(struct xfs_da_args *args, const unsigned char *name, int len); diff --git a/libxfs/xfs_dir2.c b/libxfs/xfs_dir2.c index 5f7ebbf16..f5170b75c 100644 --- a/libxfs/xfs_dir2.c +++ b/libxfs/xfs_dir2.c @@ -26,13 +26,13 @@ #include "xfs_ialloc.h" const struct xfs_name xfs_name_dotdot = { - .name = (const unsigned char *)"..", + .name = "..", .len = 2, .type = XFS_DIR3_FT_DIR, }; const struct xfs_name xfs_name_dot = { - .name = (const unsigned char *)".", + .name = ".", .len = 1, .type = XFS_DIR3_FT_DIR, }; diff --git a/libxfs/xfs_dir2_block.c b/libxfs/xfs_dir2_block.c index 82da0d327..f1eeaf26b 100644 --- a/libxfs/xfs_dir2_block.c +++ b/libxfs/xfs_dir2_block.c @@ -37,8 +37,8 @@ static xfs_dahash_t xfs_dir_hash_dot, xfs_dir_hash_dotdot; void xfs_dir_startup(void) { - xfs_dir_hash_dot = xfs_da_hashname((unsigned char *)".", 1); - xfs_dir_hash_dotdot = xfs_da_hashname((unsigned char *)"..", 2); + xfs_dir_hash_dot = xfs_da_hashname(".", 1); + xfs_dir_hash_dotdot = xfs_da_hashname("..", 2); } static xfs_failaddr_t @@ -1246,7 +1246,7 @@ xfs_dir2_sf_to_block( tagp = xfs_dir2_data_entry_tag_p(mp, dep); *tagp = cpu_to_be16(newoffset); xfs_dir2_data_log_entry(args, bp, dep); - name.name = sfep->name; + name.name = (char *)sfep->name; name.len = sfep->namelen; blp[2 + i].hashval = cpu_to_be32(xfs_dir2_hashname(mp, &name)); blp[2 + i].address = diff --git a/libxfs/xfs_dir2_data.c b/libxfs/xfs_dir2_data.c index 65e6ed879..8f15fe54c 100644 --- a/libxfs/xfs_dir2_data.c +++ b/libxfs/xfs_dir2_data.c @@ -252,7 +252,7 @@ __xfs_dir3_data_check( addr = xfs_dir2_db_off_to_dataptr(geo, geo->datablk, (xfs_dir2_data_aoff_t) ((char *)dep - (char *)hdr)); - name.name = dep->name; + name.name = (char *)dep->name; name.len = dep->namelen; hash = xfs_dir2_hashname(mp, &name); for (i = 0; i < be32_to_cpu(btp->count); i++) { diff --git a/libxfs/xfs_parent.c b/libxfs/xfs_parent.c index 84220f10a..8fb98f2f3 100644 --- a/libxfs/xfs_parent.c +++ b/libxfs/xfs_parent.c @@ -96,7 +96,7 @@ xfs_parent_valuecheck( xfs_dahash_t xfs_parent_hashval( struct xfs_mount *mp, - const uint8_t *name, + const char *name, int namelen, xfs_ino_t parent_ino) { @@ -118,7 +118,7 @@ xfs_parent_hashval( xfs_dahash_t xfs_parent_hashattr( struct xfs_mount *mp, - const uint8_t *name, + const char *name, int namelen, const void *value, int valuelen) @@ -266,7 +266,7 @@ int xfs_parent_from_attr( struct xfs_mount *mp, unsigned int attr_flags, - const unsigned char *name, + const char *name, unsigned int namelen, const void *value, unsigned int valuelen, diff --git a/libxfs/xfs_parent.h b/libxfs/xfs_parent.h index b8036527c..650307981 100644 --- a/libxfs/xfs_parent.h +++ b/libxfs/xfs_parent.h @@ -12,9 +12,9 @@ bool xfs_parent_namecheck(unsigned int attr_flags, const void *name, bool xfs_parent_valuecheck(struct xfs_mount *mp, const void *value, size_t valuelen); -xfs_dahash_t xfs_parent_hashval(struct xfs_mount *mp, const uint8_t *name, +xfs_dahash_t xfs_parent_hashval(struct xfs_mount *mp, const char *name, int namelen, xfs_ino_t parent_ino); -xfs_dahash_t xfs_parent_hashattr(struct xfs_mount *mp, const uint8_t *name, +xfs_dahash_t xfs_parent_hashattr(struct xfs_mount *mp, const char *name, int namelen, const void *value, int valuelen); /* Initializes a xfs_parent_rec to be stored as an attribute name. */ @@ -92,7 +92,7 @@ int xfs_parent_replacename(struct xfs_trans *tp, struct xfs_inode *child); int xfs_parent_from_attr(struct xfs_mount *mp, unsigned int attr_flags, - const unsigned char *name, unsigned int namelen, + const char *name, unsigned int namelen, const void *value, unsigned int valuelen, xfs_ino_t *parent_ino, uint32_t *parent_gen); diff --git a/libxfs/xfs_types.h b/libxfs/xfs_types.h index 76eb9e328..250501614 100644 --- a/libxfs/xfs_types.h +++ b/libxfs/xfs_types.h @@ -117,7 +117,7 @@ typedef enum { { XFS_LOOKUP_GEi, "ge" } struct xfs_name { - const unsigned char *name; + const char *name; int len; int type; }; -- 2.50.1