Mar 25, 2014 at 11:16pm UTC
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 Mar 25, 2014 at 11:17pm UTC
Mar 25, 2014 at 11:29pm UTC
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.
Mar 25, 2014 at 11:30pm UTC
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 /
Mar 25, 2014 at 11:34pm UTC
Size of a raw block device. 'parted' can show it, so how does that (open source) program do it?
Mar 25, 2014 at 11:35pm UTC
hmmm that might be a good idea. it might be worth it to see the source