The size of my disk?

I'm trying to write a program that without caring about the file system writes bytes to a disk. Here is how I do this:
1
2
3
4
5
6
7
8
9
10
#include <iostream>
#include <unistd.h>
#include <fcntl.h>
using namespace std;
char WriteToDisk[] = "I'm writing plain bytes to a disk!";
int main(){
int Disk=open("/dev/sdb",O_RDWR);
write(Disk,WriteToDisk,34);
close(Disk);
return 0;}

This is nice, but how do I get the size of the disk?
Is there a function that I can call to get the size of the disk?
Last edited on
a quick google search found this: http://en.wikipedia.org/wiki/Stat_%28system_call%29
stat() is for a file. I'm talking about a disk. Do you think the same function that works for a file will work for a disk?
Maybe. Let me try.
give it a try but im not exactly sure.i know that directories are considered files, which is why i think it would work, since it is loaded on a mount point on /
Size of a raw block device. 'parted' can show it, so how does that (open source) program do it?
hmmm that might be a good idea. it might be worth it to see the source
Topic archived. No new replies allowed.