[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 14/17] ext2fs: refactor add a method for dupplicated code
From: |
Etienne Brateau |
Subject: |
[PATCH 14/17] ext2fs: refactor add a method for dupplicated code |
Date: |
Sun, 23 Jan 2022 05:17:12 +0100 |
* xattr: introduce xattr_header_valid method
---
ext2fs/xattr.c | 22 ++++++++++++++--------
1 file changed, 14 insertions(+), 8 deletions(-)
diff --git a/ext2fs/xattr.c b/ext2fs/xattr.c
index 0c855616..45f7febe 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;
--
2.34.1
- Re: [PATCH 06/17] ext2fs: reindent files, (continued)
[PATCH 08/17] ext2fs: Take cares of indiannes, Etienne Brateau, 2022/01/22
[PATCH 10/17] ext2fs: set the writing time in the superblock, Etienne Brateau, 2022/01/22
[PATCH 11/17] ext2fs: resolve a todo, check writability before writing, Etienne Brateau, 2022/01/22
[PATCH 14/17] ext2fs: refactor add a method for dupplicated code,
Etienne Brateau <=
[PATCH 17/17] ext2fs: remove 2 unused functions, Etienne Brateau, 2022/01/22
[PATCH 16/17] ext2fs: remove a commented block of code, Etienne Brateau, 2022/01/22
[PATCH 02/17] ext2fs: update ext2_fs.h header, Etienne Brateau, 2022/01/22
[PATCH 13/17] ext2fs: remove a #define not_yet, Etienne Brateau, 2022/01/22