Re: How to find disk is in use?



Thank you David. Unfortunately it does not work on block device like
/dev/sda, it works provided a partition where a process is running.

For example
Ran fdisk /dev/sdc, without quiting fdisk, I ran fuser -m /dev/sdc, it
did not show me as anybody using it. Actually fdisk was in the process
of making partition.
Later mkfs /dev/sdc1 and ran fuser -m /dev/sdc, it still did not show
me as mkfs using it.
It works on partition though.

Welcome any more suggestions,

-Adar




David Schwartz wrote:
adar wrote:
I am looking for a system call or something similar to check whether
given disk (node /dev/sda, /dev/sdh etc) is in use. This will be
implemented in C language on Linux, so please suggest from C language
point.

For example,

#check-disk-in-use /dev/sda
Yes, in use
#check-disk-in-use /dev/sdh
Not in use

Please understand that user can provide only block device node, not a
partition.

Disk is use means:
A running application is born from this disk
A running application is reading/writing to this disk
Disk or disk partition is mounted and used
RAW read/write is happening on this disk
etc.
Basically if disk is used by any means from system/Linux this program
should be able to identifiy it. My system has 16 disks, and Linux OS
would be born from one of this disk and remaining 15 disk may be used
for data storage and for some application program.

The command 'fuser -m <device>' will do this. If you get no output at
all, then the block device is not in use. If you get output, it is a
list of process IDs of processes using that device along with a code
for how they are using it if appropriate.

If you need to write your own code to do it, obtain the source code to
'fuser' and borrow what you need.

DS

.



Relevant Pages

  • Re: Why would "Create Partition" under Disk Management be greyed out?
    ... I didn't see any such option as "Initialize". ... I could use it to create a partition on the drive and then proceed ... with W2K's Disk Management to format that partition. ... David ...
    (microsoft.public.win2000.general)
  • get partition size of block device from another block device.
    ... I am writing a block device driver that uses another block device for ... there is one 'struct gendisk' per disk. ... Is ther one kobject for each disk or partition? ...
    (Linux-Kernel)
  • Re: int 13h in Linux
    ... Under a UNIX-like system such as Linux, block device files such as ... To read the partition table on an IBM PC, ... openthe disk device, and readthe first 512 byte block. ...
    (comp.os.linux.development.apps)
  • Re: Linux community software-update-anarchy polemic
    ... Remember, I'm just a monkey. ... That implies that if you have one disk per partition, ... Trust the kernel or don't trust the kernel, but either way, both ...
    (comp.os.linux.misc)
  • SUMMARY: Moving /usr From Under Root "/" To Its Own Partition
    ... One of the reasons for doing this is to end up with a smaller root ... Install the boot block and boot off the new drive. ... " In order for the root partition to be fscked and remounted ... D> temporarily on the existing disk. ...
    (SunManagers)