diff options
author | Etienne Brateau <etienne.brateau@gmail.com> | 2022-01-23 05:17:12 +0100 |
---|---|---|
committer | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2022-01-23 12:08:23 +0100 |
commit | 32c57ab52a2232386b4507a53435c97d197d57dc (patch) | |
tree | 79ef68d5e6874d2f49b70072a500b6367b825e96 /ext2fs | |
parent | f40c6335ba84c05417e61696eb8ef1ea2ad5d75f (diff) | |
download | hurd-32c57ab52a2232386b4507a53435c97d197d57dc.tar.gz hurd-32c57ab52a2232386b4507a53435c97d197d57dc.tar.bz2 hurd-32c57ab52a2232386b4507a53435c97d197d57dc.zip |
ext2fs: refactor add a method for dupplicated code
* xattr: introduce xattr_header_valid method
Message-Id: <20220123041715.19402-14-etienne.brateau@gmail.com>
Diffstat (limited to 'ext2fs')
-rw-r--r-- | ext2fs/xattr.c | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/ext2fs/xattr.c b/ext2fs/xattr.c index ab6f5600..31af3b25 100644 --- a/ext2fs/xattr.c +++ b/ext2fs/xattr.c @@ -413,6 +413,16 @@ xattr_entry_replace (struct ext2_xattr_header *header, } +/* Given a xattr header, return 1 if the header is a valid xattr header + * and 0 if the header is not valid. + */ +static int +xattr_header_valid(struct ext2_xattr_header *header) +{ + return header->h_magic != htole32 (EXT2_XATTR_BLOCK_MAGIC) + || header->h_blocks != htole32 (1); +} + /* * Given a node, free extended attributes block associated with @@ -450,8 +460,7 @@ ext2_free_xattr_block (struct node *np) block = disk_cache_block_ref (blkno); header = EXT2_XATTR_HEADER (block); - if (header->h_magic != htole32 (EXT2_XATTR_BLOCK_MAGIC) - || header->h_blocks != htole32 (1)) + if (xattr_header_valid(header)) { ext2_warning ("Invalid extended attribute block."); err = EIO; @@ -536,8 +545,7 @@ ext2_list_xattr (struct node *np, char *buffer, size_t *len) block = disk_cache_block_ref (blkno); header = EXT2_XATTR_HEADER (block); - if (header->h_magic != htole32 (EXT2_XATTR_BLOCK_MAGIC) - || header->h_blocks != htole32 (1)) + if (xattr_header_valid(header)) { ext2_warning ("Invalid extended attribute block."); err = EIO; @@ -611,8 +619,7 @@ ext2_get_xattr (struct node *np, const char *name, char *value, size_t *len) dino_deref (ei); header = EXT2_XATTR_HEADER (block); - if (header->h_magic != htole32 (EXT2_XATTR_BLOCK_MAGIC) - || header->h_blocks != htole32 (1)) + if (xattr_header_valid(header)) { ext2_warning ("Invalid extended attribute block."); err = EIO; @@ -724,8 +731,7 @@ ext2_set_xattr (struct node *np, const char *name, const char *value, { block = disk_cache_block_ref (blkno); header = EXT2_XATTR_HEADER (block); - if (header->h_magic != htole32 (EXT2_XATTR_BLOCK_MAGIC) - || header->h_blocks != htole32 (1)) + if (xattr_header_valid(header)) { ext2_warning ("Invalid extended attribute block."); err = EIO; |