[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to obtain block device size (c/c++)

Posted on 2006-04-21
9
Medium Priority
?
492 Views
Last Modified: 2008-02-01
for eg. with (l)stat i discovered, that /dev/sda1 is a valid block device. What it's capacity?
C/C++ example please.
0
Comment
Question by:ravenpl
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 43

Author Comment

by:ravenpl
ID: 16506473
Apart from opening it and doing lseek() to the end of device ?
0
 
LVL 51

Assisted Solution

by:ahoffmann
ahoffmann earned 800 total points
ID: 16507038
(l)stat is for files and dirs, I guess you need to use somethng like sd()
0
 
LVL 5

Expert Comment

by:Dragon_Krome
ID: 16513667
Try stat()ing the file  (http://www.die.net/doc/linux/man/man2/stat.2.html):


#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>

int main()
{
struct stat st;

stat("/dev/sda1", &st);

printf("\nSize in bytes: %lu", st.st_size);

return 0;
}
0
Transaction-level recovery for Oracle database

Veeam Explore for Oracle delivers low RTOs and RPOs with agentless transaction log backup and transaction-level recovery of Oracle databases. You can restore the database to a precise point in time, even to a specific transaction.

 
LVL 43

Author Comment

by:ravenpl
ID: 16513844
Dragon_Krome: if You read the Q carefully, You would notice that I already tried stat(). Have You compiled and run Your programm ?
0
 
LVL 35

Expert Comment

by:Duncan Roe
ID: 16517538
"man statfs" tells you how to find usage of a *partition*. If you really want to know about a block device, best would be to look at the source of fdisk. "strace fdisk /dev/sda" showed me ioctls BLKSSZGET, HDIO_GETGEO, BLKGETSIZE, & BLKGETSIZE64 on the block device, which is also read from (for the partition table, I imagine
0
 
LVL 43

Author Comment

by:ravenpl
ID: 16517821
statfs is useless - we are talking about devices, not filesystems.
those ioctls are mentioned in ahoffman's 'man sd', but I haven't time o check it yet. But I suppose that's what I need.
0
 
LVL 35

Accepted Solution

by:
Duncan Roe earned 200 total points
ID: 16517895
"strace fdisk /dev/hda" shows the same ioctls. "man ioctl_list" identifies the structures associated with each
0
 
LVL 43

Author Comment

by:ravenpl
ID: 16532638
The asisted should be accepted and vice versa ;)
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 16533337
glad to have helped, even a bit unspecific
Future readers will see how to exchange "acepted" and "assisted"
;-)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month20 days, 14 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question