Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S270833AbTHKCgL (ORCPT ); Sun, 10 Aug 2003 22:36:11 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S270861AbTHKCgL (ORCPT ); Sun, 10 Aug 2003 22:36:11 -0400 Received: from note.orchestra.cse.unsw.EDU.AU ([129.94.242.24]:61352 "HELO note.orchestra.cse.unsw.EDU.AU") by vger.kernel.org with SMTP id S270833AbTHKCgI (ORCPT ); Sun, 10 Aug 2003 22:36:08 -0400 From: NeilBrown To: Linus Torvalds Date: Mon, 11 Aug 2003 12:35:57 +1000 X-face: [Gw_3E*Gng}4rRrKRYotwlE?.2|**#s9D Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1924 Lines: 63 ### Comments for ChangeSet the blockdev layer has a concept of 'claiming' a device, so for example it can be claimed when a filesystem is mounted or when it is included into a raid array. Only one subsystem can claim it at a time. This patch matches this functionality available to user-space via the O_EXCL flag to open. This allows user-space programs to easily test if a device is currently mounted etc, and to prevent a device from being mounted or otherwise claimed. ----------- Diffstat output ------------ ./fs/block_dev.c | 16 +++++++++++++++- 1 files changed, 15 insertions(+), 1 deletion(-) diff ./fs/block_dev.c~current~ ./fs/block_dev.c --- ./fs/block_dev.c~current~ 2003-08-11 09:01:38.000000000 +1000 +++ ./fs/block_dev.c 2003-08-11 09:01:41.000000000 +1000 @@ -643,6 +643,7 @@ int blkdev_get(struct block_device *bdev int blkdev_open(struct inode * inode, struct file * filp) { struct block_device *bdev; + int res; /* * Preserve backwards compatibility and allow large file access @@ -655,7 +656,18 @@ int blkdev_open(struct inode * inode, st bd_acquire(inode); bdev = inode->i_bdev; - return do_open(bdev, inode, filp); + res = do_open(bdev, inode, filp); + if (res) + return res; + + if (!(filp->f_flags & O_EXCL) ) + return 0; + + if (!(res = bd_claim(bdev, filp))) + return 0; + + blkdev_put(bdev, BDEV_FILE); + return res; } int blkdev_put(struct block_device *bdev, int kind) @@ -704,6 +716,8 @@ int blkdev_put(struct block_device *bdev int blkdev_close(struct inode * inode, struct file * filp) { + if (inode->i_bdev->bd_holder == filp) + bd_release(inode->i_bdev); return blkdev_put(inode->i_bdev, BDEV_FILE); } - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/