Operating System - HP-UX
1753847 Members
8458 Online
108807 Solutions
New Discussion

how can i get size of blcok device file ???

 
nakhoon_Seong
Occasional Visitor

how can i get size of blcok device file ???

hi.

 

I want get size of block device file  using c program    [/dev/vg01/lvol1]

 

for example.  linux

 

long long buf;

int fd =open("/dev/vg01/lvol1, O_RD_ONLY);

ioctl( fd, BLKGETSIZE64, &buf)

 

how can i get size of block device file at the hpux???

please help me;;;;

 

regards,

4 REPLIES 4
Dennis Handly
Acclaimed Contributor

Re: how can I get size of block device file?

Have you tried calling fstat64?  Hmm, that seems to return 0.

You may have to parse the output of bdf.

Or use statvfs(2) but that talks about filesystems, not block devices.

 

This has been asked before here:

http://h30499.www3.hp.com/t5/Languages-and-Scripting/how-can-i-get-size-of-block-device-perl-shell-script/m-p/5340709

nakhoon_Seong
Occasional Visitor

Re: how can I get size of block device file?

thank you for your advice.
but. I tried calling fstat64, stat, statvfs ...... return 0

I want to find solution by C program.
nobody answer??
Dennis Handly
Acclaimed Contributor

Re: how can I get size of block device file?

>I tried calling fstat64, stat, statvfs ...... return 0

 

Yes, I tried fstat64.  But did you try statvfs on a filesystem mount point?

bdf(1) can figure it out and it did a fstat64 then it sent a message to a socket.

 

Did you try the perl code?

Matti_Kurkela
Honored Contributor

Re: how can I get size of block device file?

You may have to find the corresponding character device file ("raw" disk/slice/LV device) and query that to find the size.

 

"man 7 disk" seems to indicate that the DIOC_CAPACITY ioctl might be useful here. It reports the size as a number of DEV_BSIZE blocks. DEV_BSIZE is defined in <sys/param.h>.

 

DIOC_DESCRIBE might be useful too, if more information than just the size is needed.

 

Edit:


I think Linus Torvalds once said that he felt the traditional dualism of block vs. character disk devices was more trouble than it's worth, so he planned to minimize its effects in Linux. Things that in traditional Unix systems work only with character devices can be applied directly to the block devices too whenever it does not cause a conflict. And in Linux, you can open a block device with a special O_DIRECT flag and get the "raw" (character) device behaviour. So, in this particular problem, Linux might be the exception, not the rule.

MK