Blame SOURCES/e2fsprogs-1.44.6-libext2fs-add-ext2fs_-read-write-_inode2.patch

a2a4bc
From 5fef457767fa876e29a5277e6c7428aa36c9ac61 Mon Sep 17 00:00:00 2001
a2a4bc
From: Theodore Ts'o <tytso@mit.edu>
a2a4bc
Date: Thu, 13 Dec 2018 00:51:51 -0500
a2a4bc
Subject: [PATCH 1/4] libext2fs: add ext2fs_{read,write}_inode2()
a2a4bc
a2a4bc
Add new library interface which allows the caller to control whether
a2a4bc
the inode checksum should be checked on inode read, or set on inode
a2a4bc
write.
a2a4bc
a2a4bc
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
a2a4bc
---
a2a4bc
 lib/ext2fs/ext2fs.h | 18 +++++++++++++++-
a2a4bc
 lib/ext2fs/inode.c  | 50 +++++++++++++++++++++++++++++----------------
a2a4bc
 2 files changed, 49 insertions(+), 19 deletions(-)
a2a4bc
a2a4bc
diff --git a/lib/ext2fs/ext2fs.h b/lib/ext2fs/ext2fs.h
a2a4bc
index c86596a6..96735c8e 100644
a2a4bc
--- a/lib/ext2fs/ext2fs.h
a2a4bc
+++ b/lib/ext2fs/ext2fs.h
a2a4bc
@@ -570,6 +570,16 @@ typedef struct ext2_icount *ext2_icount_t;
a2a4bc
  */
a2a4bc
 #define BMAP_RET_UNINIT	0x0001
a2a4bc
 
a2a4bc
+/*
a2a4bc
+ * Flags for ext2fs_read_inode2
a2a4bc
+ */
a2a4bc
+#define READ_INODE_NOCSUM	0x0001
a2a4bc
+
a2a4bc
+/*
a2a4bc
+ * Flags for ext2fs_write_inode2
a2a4bc
+ */
a2a4bc
+#define WRITE_INODE_NOCSUM	0x0001
a2a4bc
+
a2a4bc
 /*
a2a4bc
  * Flags for imager.c functions
a2a4bc
  */
a2a4bc
@@ -1514,13 +1524,19 @@ extern int ext2fs_inode_scan_flags(ext2_inode_scan scan, int set_flags,
a2a4bc
 extern errcode_t ext2fs_read_inode_full(ext2_filsys fs, ext2_ino_t ino,
a2a4bc
 					struct ext2_inode * inode,
a2a4bc
 					int bufsize);
a2a4bc
-extern errcode_t ext2fs_read_inode (ext2_filsys fs, ext2_ino_t ino,
a2a4bc
+extern errcode_t ext2fs_read_inode(ext2_filsys fs, ext2_ino_t ino,
a2a4bc
 			    struct ext2_inode * inode);
a2a4bc
+extern errcode_t ext2fs_read_inode2(ext2_filsys fs, ext2_ino_t ino,
a2a4bc
+				    struct ext2_inode * inode,
a2a4bc
+				    int bufsize, int flags);
a2a4bc
 extern errcode_t ext2fs_write_inode_full(ext2_filsys fs, ext2_ino_t ino,
a2a4bc
 					 struct ext2_inode * inode,
a2a4bc
 					 int bufsize);
a2a4bc
 extern errcode_t ext2fs_write_inode(ext2_filsys fs, ext2_ino_t ino,
a2a4bc
 			    struct ext2_inode * inode);
a2a4bc
+extern errcode_t ext2fs_write_inode2(ext2_filsys fs, ext2_ino_t ino,
a2a4bc
+				     struct ext2_inode * inode,
a2a4bc
+				     int bufsize, int flags);
a2a4bc
 extern errcode_t ext2fs_write_new_inode(ext2_filsys fs, ext2_ino_t ino,
a2a4bc
 			    struct ext2_inode * inode);
a2a4bc
 extern errcode_t ext2fs_get_blocks(ext2_filsys fs, ext2_ino_t ino, blk_t *blocks);
a2a4bc
diff --git a/lib/ext2fs/inode.c b/lib/ext2fs/inode.c
a2a4bc
index 013c658e..2a4be739 100644
a2a4bc
--- a/lib/ext2fs/inode.c
a2a4bc
+++ b/lib/ext2fs/inode.c
a2a4bc
@@ -740,8 +740,9 @@ errcode_t ext2fs_get_next_inode(ext2_inode_scan scan, ext2_ino_t *ino,
a2a4bc
 /*
a2a4bc
  * Functions to read and write a single inode.
a2a4bc
  */
a2a4bc
-errcode_t ext2fs_read_inode_full(ext2_filsys fs, ext2_ino_t ino,
a2a4bc
-				 struct ext2_inode * inode, int bufsize)
a2a4bc
+errcode_t ext2fs_read_inode2(ext2_filsys fs, ext2_ino_t ino,
a2a4bc
+			     struct ext2_inode * inode, int bufsize,
a2a4bc
+			     int flags)
a2a4bc
 {
a2a4bc
 	blk64_t		block_nr;
a2a4bc
 	dgrp_t		group;
a2a4bc
@@ -850,21 +851,29 @@ errcode_t ext2fs_read_inode_full(ext2_filsys fs, ext2_ino_t ino,
a2a4bc
 	}
a2a4bc
 	memcpy(inode, iptr, (bufsize > length) ? length : bufsize);
a2a4bc
 
a2a4bc
-	if (!(fs->flags & EXT2_FLAG_IGNORE_CSUM_ERRORS) && fail_csum)
a2a4bc
+	if (!(fs->flags & EXT2_FLAG_IGNORE_CSUM_ERRORS) &&
a2a4bc
+	    !(flags & READ_INODE_NOCSUM) && fail_csum)
a2a4bc
 		return EXT2_ET_INODE_CSUM_INVALID;
a2a4bc
 
a2a4bc
 	return 0;
a2a4bc
 }
a2a4bc
 
a2a4bc
+errcode_t ext2fs_read_inode_full(ext2_filsys fs, ext2_ino_t ino,
a2a4bc
+				 struct ext2_inode * inode, int bufsize)
a2a4bc
+{
a2a4bc
+	return ext2fs_read_inode2(fs, ino, inode, bufsize, 0);
a2a4bc
+}
a2a4bc
+
a2a4bc
 errcode_t ext2fs_read_inode(ext2_filsys fs, ext2_ino_t ino,
a2a4bc
 			    struct ext2_inode * inode)
a2a4bc
 {
a2a4bc
-	return ext2fs_read_inode_full(fs, ino, inode,
a2a4bc
-					sizeof(struct ext2_inode));
a2a4bc
+	return ext2fs_read_inode2(fs, ino, inode,
a2a4bc
+				  sizeof(struct ext2_inode), 0);
a2a4bc
 }
a2a4bc
 
a2a4bc
-errcode_t ext2fs_write_inode_full(ext2_filsys fs, ext2_ino_t ino,
a2a4bc
-				  struct ext2_inode * inode, int bufsize)
a2a4bc
+errcode_t ext2fs_write_inode2(ext2_filsys fs, ext2_ino_t ino,
a2a4bc
+			      struct ext2_inode * inode, int bufsize,
a2a4bc
+			      int flags)
a2a4bc
 {
a2a4bc
 	blk64_t block_nr;
a2a4bc
 	dgrp_t group;
a2a4bc
@@ -895,12 +904,9 @@ errcode_t ext2fs_write_inode_full(ext2_filsys fs, ext2_ino_t ino,
a2a4bc
 
a2a4bc
 	if (bufsize < length) {
a2a4bc
 		int old_flags = fs->flags;
a2a4bc
-		fs->flags |= EXT2_FLAG_IGNORE_CSUM_ERRORS;
a2a4bc
-		retval = ext2fs_read_inode_full(fs, ino,
a2a4bc
-						(struct ext2_inode *)w_inode,
a2a4bc
-						length);
a2a4bc
-		fs->flags = (old_flags & EXT2_FLAG_IGNORE_CSUM_ERRORS) |
a2a4bc
-			    (fs->flags & ~EXT2_FLAG_IGNORE_CSUM_ERRORS);
a2a4bc
+		retval = ext2fs_read_inode2(fs, ino,
a2a4bc
+					    (struct ext2_inode *)w_inode,
a2a4bc
+					    length, READ_INODE_NOCSUM);
a2a4bc
 		if (retval)
a2a4bc
 			goto errout;
a2a4bc
 	}
a2a4bc
@@ -930,9 +936,11 @@ errcode_t ext2fs_write_inode_full(ext2_filsys fs, ext2_ino_t ino,
a2a4bc
 	ext2fs_swap_inode_full(fs, w_inode, w_inode, 1, length);
a2a4bc
 #endif
a2a4bc
 
a2a4bc
-	retval = ext2fs_inode_csum_set(fs, ino, w_inode);
a2a4bc
-	if (retval)
a2a4bc
-		goto errout;
a2a4bc
+	if ((flags & WRITE_INODE_NOCSUM) == 0) {
a2a4bc
+		retval = ext2fs_inode_csum_set(fs, ino, w_inode);
a2a4bc
+		if (retval)
a2a4bc
+			goto errout;
a2a4bc
+	}
a2a4bc
 
a2a4bc
 	group = (ino - 1) / EXT2_INODES_PER_GROUP(fs->super);
a2a4bc
 	offset = ((ino - 1) % EXT2_INODES_PER_GROUP(fs->super)) *
a2a4bc
@@ -989,11 +997,17 @@ errout:
a2a4bc
 	return retval;
a2a4bc
 }
a2a4bc
 
a2a4bc
+errcode_t ext2fs_write_inode_full(ext2_filsys fs, ext2_ino_t ino,
a2a4bc
+				  struct ext2_inode * inode, int bufsize)
a2a4bc
+{
a2a4bc
+	return ext2fs_write_inode2(fs, ino, inode, bufsize, 0);
a2a4bc
+}
a2a4bc
+
a2a4bc
 errcode_t ext2fs_write_inode(ext2_filsys fs, ext2_ino_t ino,
a2a4bc
 			     struct ext2_inode *inode)
a2a4bc
 {
a2a4bc
-	return ext2fs_write_inode_full(fs, ino, inode,
a2a4bc
-				       sizeof(struct ext2_inode));
a2a4bc
+	return ext2fs_write_inode2(fs, ino, inode,
a2a4bc
+				   sizeof(struct ext2_inode), 0);
a2a4bc
 }
a2a4bc
 
a2a4bc
 /*
a2a4bc
-- 
a2a4bc
2.20.1
a2a4bc