shithub: lwext4

Download patch

ref: c8e804846cda63d86b70a705c3be57d378447e1e
parent: 52eb9e1a099b937f814427a3af3d02021746e67f
author: gkostka <kostka.grzegorz@gmail.com>
date: Tue Dec 8 12:47:43 EST 2015

Add lock/unlock functions to blockdev_iface

Since one blockdev_iface could be shared by multi block devices
lock/unlock functions is needed. Locks are not needed in single
partition mode.

--- a/blockdev/blockdev.c
+++ b/blockdev/blockdev.c
@@ -39,10 +39,13 @@
 static int blockdev_bwrite(struct ext4_blockdev *bdev, const void *buf,
 			  uint64_t blk_id, uint32_t blk_cnt);
 static int blockdev_close(struct ext4_blockdev *bdev);
+static int blockdev_lock(struct ext4_blockdev *bdev);
+static int blockdev_unlock(struct ext4_blockdev *bdev);
 
 /******************************************************************************/
 EXT4_BLOCKDEV_STATIC_INSTANCE(blockdev, 512, 0, blockdev_open,
-			      blockdev_bread, blockdev_bwrite, blockdev_close);
+			      blockdev_bread, blockdev_bwrite, blockdev_close,
+			      blockdev_lock, blockdev_unlock);
 
 /******************************************************************************/
 static int blockdev_open(struct ext4_blockdev *bdev)
@@ -72,6 +75,18 @@
 static int blockdev_close(struct ext4_blockdev *bdev)
 {
 	/*blockdev_close: skeleton*/
+	return EIO;
+}
+
+static int blockdev_lock(struct ext4_blockdev *bdev)
+{
+	/*blockdev_lock: skeleton*/
+	return EIO;
+}
+
+static int blockdev_unlock(struct ext4_blockdev *bdev)
+{
+	/*blockdev_unlock: skeleton*/
 	return EIO;
 }
 
--- a/blockdev/linux/ext4_filedev.c
+++ b/blockdev/linux/ext4_filedev.c
@@ -58,7 +58,7 @@
 
 /******************************************************************************/
 EXT4_BLOCKDEV_STATIC_INSTANCE(_filedev, EXT4_FILEDEV_BSIZE, 0, filedev_open,
-			      filedev_bread, filedev_bwrite, filedev_close);
+		filedev_bread, filedev_bwrite, filedev_close, 0, 0);
 
 /******************************************************************************/
 static int filedev_open(struct ext4_blockdev *bdev)
--- a/blockdev/windows/io_raw.c
+++ b/blockdev/windows/io_raw.c
@@ -1,161 +1,161 @@
-/*
- * Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com)
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <ext4_config.h>
-#include <ext4_blockdev.h>
-#include <ext4_errno.h>
-#include <stdio.h>
-#include <stdbool.h>
-#include <string.h>
-
-#ifdef WIN32
-#include <windows.h>
-#include <winioctl.h>
-
-/**@brief   Default filename.*/
-static const char *fname = "ext2";
-
-/**@brief   IO block size.*/
-#define EXT4_IORAW_BSIZE 512
-
-/**@brief   Image file descriptor.*/
-static HANDLE dev_file;
-
-/**********************BLOCKDEV INTERFACE**************************************/
-static int io_raw_open(struct ext4_blockdev *bdev);
-static int io_raw_bread(struct ext4_blockdev *bdev, void *buf, uint64_t blk_id,
-			uint32_t blk_cnt);
-static int io_raw_bwrite(struct ext4_blockdev *bdev, const void *buf,
-			 uint64_t blk_id, uint32_t blk_cnt);
-static int io_raw_close(struct ext4_blockdev *bdev);
-
-/******************************************************************************/
-EXT4_BLOCKDEV_STATIC_INSTANCE(_filedev, EXT4_IORAW_BSIZE, 0, io_raw_open,
-			      io_raw_bread, io_raw_bwrite, io_raw_close);
-
-/******************************************************************************/
-static int io_raw_open(struct ext4_blockdev *bdev)
-{
-	char path[64];
-	DISK_GEOMETRY pdg;
-	uint64_t disk_size;
-	BOOL bResult = FALSE;
-	DWORD junk;
-
-	sprintf(path, "\\\\.\\%s", fname);
-
-	dev_file =
-	    CreateFile(path, GENERIC_READ | GENERIC_WRITE,
-		       FILE_SHARE_WRITE | FILE_SHARE_READ, NULL, OPEN_EXISTING,
-		       FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH, NULL);
-
-	if (dev_file == INVALID_HANDLE_VALUE) {
-		return EIO;
-	}
-
-	bResult =
-	    DeviceIoControl(dev_file, IOCTL_DISK_GET_DRIVE_GEOMETRY, NULL, 0,
-			    &pdg, sizeof(pdg), &junk, (LPOVERLAPPED)NULL);
-
-	if (bResult == FALSE) {
-		CloseHandle(dev_file);
-		return EIO;
-	}
-
-	disk_size = pdg.Cylinders.QuadPart * (ULONG)pdg.TracksPerCylinder *
-		    (ULONG)pdg.SectorsPerTrack * (ULONG)pdg.BytesPerSector;
-
-	_filedev.ph_bsize = pdg.BytesPerSector;
-	_filedev.ph_bcnt = disk_size / pdg.BytesPerSector;
-
-	return EOK;
-}
-
-/******************************************************************************/
-
-static int io_raw_bread(struct ext4_blockdev *bdev, void *buf, uint64_t blk_id,
-			uint32_t blk_cnt)
-{
-	long hipart = blk_id >> (32 - 9);
-	long lopart = blk_id << 9;
-	long err;
-
-	SetLastError(0);
-	lopart = SetFilePointer(dev_file, lopart, &hipart, FILE_BEGIN);
-
-	if (lopart == -1 && NO_ERROR != (err = GetLastError())) {
-		return EIO;
-	}
-
-	DWORD n;
-
-	if (!ReadFile(dev_file, buf, blk_cnt * 512, &n, NULL)) {
-		err = GetLastError();
-		return EIO;
-	}
-	return EOK;
-}
-
-/******************************************************************************/
-static int io_raw_bwrite(struct ext4_blockdev *bdev, const void *buf,
-			 uint64_t blk_id, uint32_t blk_cnt)
-{
-	long hipart = blk_id >> (32 - 9);
-	long lopart = blk_id << 9;
-	long err;
-
-	SetLastError(0);
-	lopart = SetFilePointer(dev_file, lopart, &hipart, FILE_BEGIN);
-
-	if (lopart == -1 && NO_ERROR != (err = GetLastError())) {
-		return EIO;
-	}
-
-	DWORD n;
-
-	if (!WriteFile(dev_file, buf, blk_cnt * 512, &n, NULL)) {
-		err = GetLastError();
-		return EIO;
-	}
-	return EOK;
-}
-
-/******************************************************************************/
-static int io_raw_close(struct ext4_blockdev *bdev)
-{
-	CloseHandle(dev_file);
-	return EOK;
-}
-
-/******************************************************************************/
-struct ext4_blockdev *ext4_io_raw_dev_get(void) { return &_filedev; }
-/******************************************************************************/
-void ext4_io_raw_filename(const char *n) { fname = n; }
-
-/******************************************************************************/
-#endif
+/*
+ * Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <ext4_config.h>
+#include <ext4_blockdev.h>
+#include <ext4_errno.h>
+#include <stdio.h>
+#include <stdbool.h>
+#include <string.h>
+
+#ifdef WIN32
+#include <windows.h>
+#include <winioctl.h>
+
+/**@brief   Default filename.*/
+static const char *fname = "ext2";
+
+/**@brief   IO block size.*/
+#define EXT4_IORAW_BSIZE 512
+
+/**@brief   Image file descriptor.*/
+static HANDLE dev_file;
+
+/**********************BLOCKDEV INTERFACE**************************************/
+static int io_raw_open(struct ext4_blockdev *bdev);
+static int io_raw_bread(struct ext4_blockdev *bdev, void *buf, uint64_t blk_id,
+			uint32_t blk_cnt);
+static int io_raw_bwrite(struct ext4_blockdev *bdev, const void *buf,
+			 uint64_t blk_id, uint32_t blk_cnt);
+static int io_raw_close(struct ext4_blockdev *bdev);
+
+/******************************************************************************/
+EXT4_BLOCKDEV_STATIC_INSTANCE(_filedev, EXT4_IORAW_BSIZE, 0, io_raw_open,
+			      io_raw_bread, io_raw_bwrite, io_raw_close, 0, 0);
+
+/******************************************************************************/
+static int io_raw_open(struct ext4_blockdev *bdev)
+{
+	char path[64];
+	DISK_GEOMETRY pdg;
+	uint64_t disk_size;
+	BOOL bResult = FALSE;
+	DWORD junk;
+
+	sprintf(path, "\\\\.\\%s", fname);
+
+	dev_file =
+	    CreateFile(path, GENERIC_READ | GENERIC_WRITE,
+		       FILE_SHARE_WRITE | FILE_SHARE_READ, NULL, OPEN_EXISTING,
+		       FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH, NULL);
+
+	if (dev_file == INVALID_HANDLE_VALUE) {
+		return EIO;
+	}
+
+	bResult =
+	    DeviceIoControl(dev_file, IOCTL_DISK_GET_DRIVE_GEOMETRY, NULL, 0,
+			    &pdg, sizeof(pdg), &junk, (LPOVERLAPPED)NULL);
+
+	if (bResult == FALSE) {
+		CloseHandle(dev_file);
+		return EIO;
+	}
+
+	disk_size = pdg.Cylinders.QuadPart * (ULONG)pdg.TracksPerCylinder *
+		    (ULONG)pdg.SectorsPerTrack * (ULONG)pdg.BytesPerSector;
+
+	_filedev.bdif->ph_bsize = pdg.BytesPerSector;
+	_filedev.bdif->ph_bcnt = disk_size / pdg.BytesPerSector;
+
+	return EOK;
+}
+
+/******************************************************************************/
+
+static int io_raw_bread(struct ext4_blockdev *bdev, void *buf, uint64_t blk_id,
+			uint32_t blk_cnt)
+{
+	long hipart = blk_id >> (32 - 9);
+	long lopart = blk_id << 9;
+	long err;
+
+	SetLastError(0);
+	lopart = SetFilePointer(dev_file, lopart, &hipart, FILE_BEGIN);
+
+	if (lopart == -1 && NO_ERROR != (err = GetLastError())) {
+		return EIO;
+	}
+
+	DWORD n;
+
+	if (!ReadFile(dev_file, buf, blk_cnt * 512, &n, NULL)) {
+		err = GetLastError();
+		return EIO;
+	}
+	return EOK;
+}
+
+/******************************************************************************/
+static int io_raw_bwrite(struct ext4_blockdev *bdev, const void *buf,
+			 uint64_t blk_id, uint32_t blk_cnt)
+{
+	long hipart = blk_id >> (32 - 9);
+	long lopart = blk_id << 9;
+	long err;
+
+	SetLastError(0);
+	lopart = SetFilePointer(dev_file, lopart, &hipart, FILE_BEGIN);
+
+	if (lopart == -1 && NO_ERROR != (err = GetLastError())) {
+		return EIO;
+	}
+
+	DWORD n;
+
+	if (!WriteFile(dev_file, buf, blk_cnt * 512, &n, NULL)) {
+		err = GetLastError();
+		return EIO;
+	}
+	return EOK;
+}
+
+/******************************************************************************/
+static int io_raw_close(struct ext4_blockdev *bdev)
+{
+	CloseHandle(dev_file);
+	return EOK;
+}
+
+/******************************************************************************/
+struct ext4_blockdev *ext4_io_raw_dev_get(void) { return &_filedev; }
+/******************************************************************************/
+void ext4_io_raw_filename(const char *n) { fname = n; }
+
+/******************************************************************************/
+#endif
--- a/blockdev/windows/io_raw.h
+++ b/blockdev/windows/io_raw.h
@@ -1,44 +1,44 @@
-/*
- * Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com)
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-#ifndef IO_RAW_H_
-#define IO_RAW_H_
-
-#include <ext4_config.h>
-#include <ext4_blockdev.h>
-
-#include <stdint.h>
-#include <stdbool.h>
-
-/**@brief   IO raw blockdev get.*/
-struct ext4_blockdev *ext4_io_raw_dev_get(void);
-
-/**@brief   Set filrname to open.*/
-void ext4_io_raw_filename(const char *n);
-
-
-#endif /* IO_RAW_H_ */
+/*
+ * Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef IO_RAW_H_
+#define IO_RAW_H_
+
+#include <ext4_config.h>
+#include <ext4_blockdev.h>
+
+#include <stdint.h>
+#include <stdbool.h>
+
+/**@brief   IO raw blockdev get.*/
+struct ext4_blockdev *ext4_io_raw_dev_get(void);
+
+/**@brief   Set filrname to open.*/
+void ext4_io_raw_filename(const char *n);
+
+
+#endif /* IO_RAW_H_ */
--- a/lwext4/ext4_blockdev.c
+++ b/lwext4/ext4_blockdev.c
@@ -42,6 +42,42 @@
 #include <string.h>
 #include <stdlib.h>
 
+static void ext4_bdif_lock(struct ext4_blockdev *bdev)
+{
+	if (!bdev->bdif->lock)
+		return;
+
+	int r = bdev->bdif->lock(bdev);
+	ext4_assert(r == EOK);
+}
+
+static void ext4_bdif_unlock(struct ext4_blockdev *bdev)
+{
+	if (!bdev->bdif->unlock)
+		return;
+
+	int r = bdev->bdif->unlock(bdev);
+	ext4_assert(r == EOK);
+}
+
+static int ext4_bdif_bread(struct ext4_blockdev *bdev, void *buf,
+			   uint64_t blk_id, uint32_t blk_cnt)
+{
+	ext4_bdif_lock(bdev);
+	int r = bdev->bdif->bread(bdev, buf, blk_id, blk_cnt);
+	ext4_bdif_unlock(bdev);
+	return r;
+}
+
+static int ext4_bdif_bwrite(struct ext4_blockdev *bdev, const void *buf,
+			    uint64_t blk_id, uint32_t blk_cnt)
+{
+	ext4_bdif_lock(bdev);
+	int r = bdev->bdif->bwrite(bdev, buf, blk_id, blk_cnt);
+	ext4_bdif_unlock(bdev);
+	return r;
+}
+
 int ext4_block_init(struct ext4_blockdev *bdev)
 {
 	int rc;
@@ -225,7 +261,7 @@
 	pb_cnt = bdev->lg_bsize / bdev->bdif->ph_bsize;
 
 	bdev->bread_ctr++;
-	return bdev->bdif->bread(bdev, buf, pba, pb_cnt * cnt);
+	return ext4_bdif_bread(bdev, buf, pba, pb_cnt * cnt);
 }
 
 int ext4_blocks_set_direct(struct ext4_blockdev *bdev, const void *buf,
@@ -241,8 +277,7 @@
 	pb_cnt = bdev->lg_bsize / bdev->bdif->ph_bsize;
 
 	bdev->bwrite_ctr++;
-
-	return bdev->bdif->bwrite(bdev, buf, pba, pb_cnt * cnt);
+	return ext4_bdif_bwrite(bdev, buf, pba, pb_cnt * cnt);
 }
 
 int ext4_block_writebytes(struct ext4_blockdev *bdev, uint64_t off,
@@ -275,13 +310,12 @@
 				    ? len
 				    : (bdev->bdif->ph_bsize - unalg);
 
-		r = bdev->bdif->bread(bdev, bdev->bdif->ph_bbuf, block_idx, 1);
+		r = ext4_bdif_bread(bdev, bdev->bdif->ph_bbuf, block_idx, 1);
 		if (r != EOK)
 			return r;
 
 		memcpy(bdev->bdif->ph_bbuf + unalg, p, wlen);
-
-		r = bdev->bdif->bwrite(bdev, bdev->bdif->ph_bbuf, block_idx, 1);
+		r = ext4_bdif_bwrite(bdev, bdev->bdif->ph_bbuf, block_idx, 1);
 		if (r != EOK)
 			return r;
 
@@ -292,7 +326,7 @@
 
 	/*Aligned data*/
 	blen = len / bdev->bdif->ph_bsize;
-	r = bdev->bdif->bwrite(bdev, p, block_idx, blen);
+	r = ext4_bdif_bwrite(bdev, p, block_idx, blen);
 	if (r != EOK)
 		return r;
 
@@ -303,13 +337,12 @@
 
 	/*Rest of the data*/
 	if (len) {
-		r = bdev->bdif->bread(bdev, bdev->bdif->ph_bbuf, block_idx, 1);
+		r = ext4_bdif_bread(bdev, bdev->bdif->ph_bbuf, block_idx, 1);
 		if (r != EOK)
 			return r;
 
 		memcpy(bdev->bdif->ph_bbuf, p, len);
-
-		r = bdev->bdif->bwrite(bdev, bdev->bdif->ph_bbuf, block_idx, 1);
+		r = ext4_bdif_bwrite(bdev, bdev->bdif->ph_bbuf, block_idx, 1);
 		if (r != EOK)
 			return r;
 	}
@@ -347,7 +380,7 @@
 				    ? len
 				    : (bdev->bdif->ph_bsize - unalg);
 
-		r = bdev->bdif->bread(bdev, bdev->bdif->ph_bbuf, block_idx, 1);
+		r = ext4_bdif_bread(bdev, bdev->bdif->ph_bbuf, block_idx, 1);
 		if (r != EOK)
 			return r;
 
@@ -361,7 +394,7 @@
 	/*Aligned data*/
 	blen = len / bdev->bdif->ph_bsize;
 
-	r = bdev->bdif->bread(bdev, p, block_idx, blen);
+	r = ext4_bdif_bread(bdev, p, block_idx, blen);
 	if (r != EOK)
 		return r;
 
@@ -372,7 +405,7 @@
 
 	/*Rest of the data*/
 	if (len) {
-		r = bdev->bdif->bread(bdev, bdev->bdif->ph_bbuf, block_idx, 1);
+		r = ext4_bdif_bread(bdev, bdev->bdif->ph_bbuf, block_idx, 1);
 		if (r != EOK)
 			return r;
 
--- a/lwext4/ext4_blockdev.h
+++ b/lwext4/ext4_blockdev.h
@@ -71,6 +71,16 @@
 	 * @param   bdev block device.*/
 	int (*close)(struct ext4_blockdev *bdev);
 
+	/**@brief   Lock block device. Required in multi partition mode
+	 *          operations. Not mandatory field.
+	 * @param   bdev block device.*/
+	int (*lock)(struct ext4_blockdev *bdev);
+
+	/**@brief   Unlock block device. Required in multi partition mode
+	 *          operations. Not mandatory field.
+	 * @param   bdev block device.*/
+	int (*unlock)(struct ext4_blockdev *bdev);
+
 	/**@brief   Block size (bytes): physical*/
 	uint32_t ph_bsize;
 
@@ -112,8 +122,8 @@
 };
 
 /**@brief   Static initialization of the block device.*/
-#define EXT4_BLOCKDEV_STATIC_INSTANCE(__name, __bsize, __bcnt, __open,         \
-				      __bread, __bwrite, __close)              \
+#define EXT4_BLOCKDEV_STATIC_INSTANCE(__name, __bsize, __bcnt, __open, __bread,\
+				      __bwrite, __close, __lock, __unlock)     \
 	static uint8_t __name##_ph_bbuf[(__bsize)];                            \
 	static struct ext4_blockdev_iface __name##_iface = {                   \
 		.open = __open,                                                \
@@ -120,6 +130,8 @@
 		.bread = __bread,                                              \
 		.bwrite = __bwrite,                                            \
 		.close = __close,                                              \
+		.lock = __lock,                                                \
+		.unlock = __unlock,                                            \
 		.ph_bsize = __bsize,                                           \
 		.ph_bcnt = __bcnt,                                             \
 		.ph_bbuf = __name##_ph_bbuf,                                   \