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

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