From fa6c653ec3117dd689c8adb4ea2ebfc10f8cdd4a Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Sat, 18 Mar 2006 18:57:44 -0500 Subject: [PATCH] Add IO_FLAG_EXCLUSIVE flag to io_channel abstraction Add a new io_channel open flag, IO_FLAG_EXCLUSIVE,which requests that the device be opened in exclusive (O_EXCL) mode. Add support to the unix_io implementation for this flag. Signed-off-by: "Theodore Ts'o" --- lib/ext2fs/ChangeLog | 4 ++++ lib/ext2fs/ext2_io.h | 3 ++- lib/ext2fs/unix_io.c | 2 ++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/ext2fs/ChangeLog b/lib/ext2fs/ChangeLog index 857cdf0..2227cb8 100644 --- a/lib/ext2fs/ChangeLog +++ b/lib/ext2fs/ChangeLog @@ -1,5 +1,9 @@ 2006-03-18 Theodore Ts'o + * 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. + * ext2fs.h: Fix documentation so that BLOCK_FLAG_TRAVERSE is BLOCK_FLAG_DEPTH_TRAVERSE. (Addresses Debian Bug #351268) diff --git a/lib/ext2fs/ext2_io.h b/lib/ext2fs/ext2_io.h index e17886c..eada278 100644 --- a/lib/ext2fs/ext2_io.h +++ b/lib/ext2fs/ext2_io.h @@ -73,7 +73,8 @@ struct struct_io_manager { int reserved[14]; }; -#define IO_FLAG_RW 1 +#define IO_FLAG_RW 0x0001 +#define IO_FLAG_EXCLUSIVE 0x0002 /* * Convenience functions.... diff --git a/lib/ext2fs/unix_io.c b/lib/ext2fs/unix_io.c index e1df0d6..0f04cfa 100644 --- a/lib/ext2fs/unix_io.c +++ b/lib/ext2fs/unix_io.c @@ -412,6 +412,8 @@ static errcode_t unix_open(const char *name, int flags, io_channel *channel) goto cleanup; open_flags = (flags & IO_FLAG_RW) ? O_RDWR : O_RDONLY; + if (flags & IO_FLAG_EXCLUSIVE) + open_flags |= O_EXCL; #ifdef HAVE_OPEN64 data->dev = open64(io->name, open_flags); #else -- 1.8.3.1