Add EXT2_FLAG_EXCLUSIVE to the ext2fs library.

This flag when specified to ext2fs_open or ext2fs_initialize indicates 
that the application wants the io_channel to be opened in exclusive mode.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>

diff --git a/lib/ext2fs/ChangeLog b/lib/ext2fs/ChangeLog
index 2227cb8..a93bfb9 100644
--- a/lib/ext2fs/ChangeLog
+++ b/lib/ext2fs/ChangeLog
@@ -1,5 +1,13 @@
 2006-03-18  Theodore Ts'o  <tytso@mit.edu>
 
+	* ext2fs.h (EXT2_FLAG_EXCLUSIVE): Define new flag which requests
+		that the io_channel be opened in exclusive mode.
+
+	* openfs.c (ext2fs_open2), initialize.c (ext2fs_initialize): If
+		EXT2_FLAG_EXCLUSIVE is passed to ext2fs_open or
+		ext2fs_initialize, then pass IO_FLAG_EXCLUSIVE to the
+		io_channel open routine.
+
 	* ext2_io.h (IO_FLAG_EXCLUSIVE), unix_io.c (unix_open): Add new
 		io_channel open flag, IO_FLAG_EXCLUSIVE, which requests
 		that the device be opened in exclusive (O_EXCL) mode.
diff --git a/lib/ext2fs/ext2fs.h b/lib/ext2fs/ext2fs.h
index 809b602..c3d0428 100644
--- a/lib/ext2fs/ext2fs.h
+++ b/lib/ext2fs/ext2fs.h
@@ -188,6 +188,7 @@
 #define EXT2_FLAG_SUPER_ONLY		0x800
 #define EXT2_FLAG_JOURNAL_DEV_OK	0x1000
 #define EXT2_FLAG_IMAGE_FILE		0x2000
+#define EXT2_FLAG_EXCLUSIVE		0x4000
 
 /*
  * Special flag in the ext2 inode i_flag field that means that this is
diff --git a/lib/ext2fs/initialize.c b/lib/ext2fs/initialize.c
index 83eea72..05ba8c8 100644
--- a/lib/ext2fs/initialize.c
+++ b/lib/ext2fs/initialize.c
@@ -104,6 +104,7 @@
 	dgrp_t		i;
 	blk_t		numblocks;
 	int		rsv_gdt;
+	int		io_flags;
 	char		*buf;
 
 	if (!param || !param->s_blocks_count)
@@ -120,7 +121,10 @@
 #ifdef WORDS_BIGENDIAN
 	fs->flags |= EXT2_FLAG_SWAP_BYTES;
 #endif
-	retval = manager->open(name, IO_FLAG_RW, &fs->io);
+	io_flags = IO_FLAG_RW;
+	if (flags & EXT2_FLAG_EXCLUSIVE)
+		io_flags |= IO_FLAG_EXCLUSIVE;
+	retval = manager->open(name, io_flags, &fs->io);
 	if (retval)
 		goto cleanup;
 	fs->image_io = fs->io;
diff --git a/lib/ext2fs/openfs.c b/lib/ext2fs/openfs.c
index 05de84f..4228c6e 100644
--- a/lib/ext2fs/openfs.c
+++ b/lib/ext2fs/openfs.c
@@ -86,7 +86,7 @@
 	ext2_filsys	fs;
 	errcode_t	retval;
 	unsigned long	i;
-	int		j, groups_per_block, blocks_per_group;
+	int		j, groups_per_block, blocks_per_group, io_flags;
 	blk_t		group_block, blk;
 	char		*dest, *cp;
 	struct ext2_group_desc *gdp;
@@ -111,9 +111,12 @@
 		io_options = cp;
 	}
 		
-	retval = manager->open(fs->device_name, 
-			       (flags & EXT2_FLAG_RW) ? IO_FLAG_RW : 0,
-			       &fs->io);
+	io_flags = 0;
+	if (flags & EXT2_FLAG_RW)
+		io_flags |= IO_FLAG_RW;
+	if (flags & EXT2_FLAG_EXCLUSIVE)
+		io_flags |= IO_FLAG_EXCLUSIVE;
+	retval = manager->open(fs->device_name, io_flags, &fs->io);
 	if (retval)
 		goto cleanup;
 	if (io_options &&