[PATCH v2 02/15] hfsplus: rework hfsplus_submit_bio() method

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Vyacheslav Dubeyko <slava@xxxxxxxxxxx>
Subject: [PATCH v2 02/15] hfsplus: rework hfsplus_submit_bio() method

This patch reworks hfsplus_submit_bio() method with the goal
to get length of data from address of data pointer till the
end of data block.

Signed-off-by: Vyacheslav Dubeyko <slava@xxxxxxxxxxx>
CC: Al Viro <viro@xxxxxxxxxxxxxxxxxx>
CC: Christoph Hellwig <hch@xxxxxxxxxxxxx>
Tested-by: Hin-Tak Leung <htl10@xxxxxxxxxxxxxxxxxxxxx>
---
 fs/hfsplus/hfsplus_fs.h |    2 +-
 fs/hfsplus/part_tbl.c   |    4 ++--
 fs/hfsplus/super.c      |    5 +++--
 fs/hfsplus/wrapper.c    |   28 +++++++++++++++++++++-------
 4 files changed, 27 insertions(+), 12 deletions(-)

diff --git a/fs/hfsplus/hfsplus_fs.h b/fs/hfsplus/hfsplus_fs.h
index 18ca92c..8a6003c 100644
--- a/fs/hfsplus/hfsplus_fs.h
+++ b/fs/hfsplus/hfsplus_fs.h
@@ -537,7 +537,7 @@ int hfsplus_compare_dentry(const struct dentry *parent, const struct dentry *den
 int hfsplus_read_wrapper(struct super_block *);
 int hfs_part_find(struct super_block *, sector_t *, sector_t *);
 int hfsplus_submit_bio(struct super_block *sb, sector_t sector,
-		void *buf, void **data, int rw);
+			void *buf, void **data, int rw, size_t *data_len);
 
 /* time macros */
 #define __hfsp_mt2ut(t)		(be32_to_cpu(t) - 2082844800U)
diff --git a/fs/hfsplus/part_tbl.c b/fs/hfsplus/part_tbl.c
index eb355d8..f7c8ebf 100644
--- a/fs/hfsplus/part_tbl.c
+++ b/fs/hfsplus/part_tbl.c
@@ -112,7 +112,7 @@ static int hfs_parse_new_pmap(struct super_block *sb, void *buf,
 		if ((u8 *)pm - (u8 *)buf >= buf_size) {
 			res = hfsplus_submit_bio(sb,
 						 *part_start + HFS_PMAP_BLK + i,
-						 buf, (void **)&pm, READ);
+						 buf, (void **)&pm, READ, NULL);
 			if (res)
 				return res;
 		}
@@ -136,7 +136,7 @@ int hfs_part_find(struct super_block *sb,
 		return -ENOMEM;
 
 	res = hfsplus_submit_bio(sb, *part_start + HFS_PMAP_BLK,
-				 buf, &data, READ);
+				 buf, &data, READ, NULL);
 	if (res)
 		goto out;
 
diff --git a/fs/hfsplus/super.c b/fs/hfsplus/super.c
index 80875aa..12eaf33 100644
--- a/fs/hfsplus/super.c
+++ b/fs/hfsplus/super.c
@@ -217,7 +217,7 @@ static int hfsplus_sync_fs(struct super_block *sb, int wait)
 
 	error2 = hfsplus_submit_bio(sb,
 				   sbi->part_start + HFSPLUS_VOLHEAD_SECTOR,
-				   sbi->s_vhdr_buf, NULL, WRITE_SYNC);
+				   sbi->s_vhdr_buf, NULL, WRITE_SYNC, NULL);
 	if (!error)
 		error = error2;
 	if (!write_backup)
@@ -225,7 +225,8 @@ static int hfsplus_sync_fs(struct super_block *sb, int wait)
 
 	error2 = hfsplus_submit_bio(sb,
 				  sbi->part_start + sbi->sect_count - 2,
-				  sbi->s_backup_vhdr_buf, NULL, WRITE_SYNC);
+				  sbi->s_backup_vhdr_buf, NULL, WRITE_SYNC,
+				  NULL);
 	if (!error)
 		error2 = error;
 out:
diff --git a/fs/hfsplus/wrapper.c b/fs/hfsplus/wrapper.c
index e9a97a0..68ea5fe 100644
--- a/fs/hfsplus/wrapper.c
+++ b/fs/hfsplus/wrapper.c
@@ -31,6 +31,7 @@ struct hfsplus_wd {
  * @buf: buffer for I/O
  * @data: output pointer for location of requested data
  * @rw: direction of I/O
+ * @data_len: output pointer for length of requested data
  *
  * The unit of I/O is hfsplus_min_io_size(sb), which may be bigger than
  * HFSPLUS_SECTOR_SIZE, and @buf must be sized accordingly. On reads
@@ -44,13 +45,14 @@ struct hfsplus_wd {
  * will work correctly.
  */
 int hfsplus_submit_bio(struct super_block *sb, sector_t sector,
-		void *buf, void **data, int rw)
+			void *buf, void **data, int rw, size_t *data_len)
 {
 	struct bio *bio;
 	int ret = 0;
 	u64 io_size;
 	loff_t start;
 	int offset;
+	unsigned int page_offset;
 
 	/*
 	 * Align sector to hardware sector size and find offset. We
@@ -66,13 +68,25 @@ int hfsplus_submit_bio(struct super_block *sb, sector_t sector,
 	bio->bi_sector = sector;
 	bio->bi_bdev = sb->s_bdev;
 
-	if (!(rw & WRITE) && data)
+	if (!(rw & WRITE) && data) {
 		*data = (u8 *)buf + offset;
 
+		if (data_len) {
+			page_offset = offset_in_page(buf);
+
+			BUG_ON(offset > io_size);
+			BUG_ON((page_offset + offset) > PAGE_SIZE);
+
+			*data_len = min_t(size_t, io_size - offset,
+					  PAGE_SIZE - page_offset - offset);
+		}
+	}
+
 	while (io_size > 0) {
-		unsigned int page_offset = offset_in_page(buf);
-		unsigned int len = min_t(unsigned int, PAGE_SIZE - page_offset,
-					 io_size);
+		unsigned int len;
+
+		page_offset = offset_in_page(buf);
+		len = min_t(unsigned int, PAGE_SIZE - page_offset, io_size);
 
 		ret = bio_add_page(bio, virt_to_page(buf), len, page_offset);
 		if (ret != len) {
@@ -181,7 +195,7 @@ int hfsplus_read_wrapper(struct super_block *sb)
 reread:
 	error = hfsplus_submit_bio(sb, part_start + HFSPLUS_VOLHEAD_SECTOR,
 				   sbi->s_vhdr_buf, (void **)&sbi->s_vhdr,
-				   READ);
+				   READ, NULL);
 	if (error)
 		goto out_free_backup_vhdr;
 
@@ -213,7 +227,7 @@ reread:
 
 	error = hfsplus_submit_bio(sb, part_start + part_size - 2,
 				   sbi->s_backup_vhdr_buf,
-				   (void **)&sbi->s_backup_vhdr, READ);
+				   (void **)&sbi->s_backup_vhdr, READ, NULL);
 	if (error)
 		goto out_free_backup_vhdr;
 
-- 
1.7.9.5



--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [Samba]     [Device Mapper]     [CEPH Development]
  Powered by Linux