in reply to get the size of a special device (drive)

How much OS-independence do you need?

Since you're probably on linux, parsing the output of df or df -h would be very easy. Maybe look at /sys/block/*drivename*/size

I don't think this can be solved completely OS-independently, but I'd be interested in something that worked better on all/most POSIX systems

Replies are listed 'Best First'.
Re^2: get the size of a special device (drive)
by exodist (Monk) on May 30, 2007 at 21:35 UTC
    /sys/block/*drivename*/size is useful, it looks liek it uses 512k block size?
        Personally, I'd go with `du -h` or `du -B 1` (for bytes)

        But AFAICT du is for mounted filesystems. He was asking about raw devices. I suppose the answer is somewhere in the docs for sysfs. (The kernel's?)

        unfortunately du requires the filesystem to be mounted, not an option in this case :-(