Re: pread function help needed....?
Re: pread function help needed....?
- Subject: Re: pread function help needed....?
- From: Wenguang Wang <email@hidden>
- Date: Fri, 9 Dec 2011 05:51:08 -0800
On Dec 9, 2011, at 12:05 AM, Waqar Ahmad wrote:
> Hi,
>
> I used pread function to read disk0/disk1 sectors, but each time I change
> the value of reading bytes it returns the same output plz check my program
> below and tel me if there is any mistake....
>
>
> #include <stdio.h>
> #include "stdlib.h"
>
> int main (int argc, const char * argv[]) {
> // insert code here...
> printf("Hello, World!\n");
> int fd = open("/dev/rdisk0");
> unsigned long byts=pread(fd, 1024, 1024, 0);
You used 1024 as buf, which is wrong. Buf should be a pointer to a chunk of memory that can be written, you usually use malloc or new to allocate it.
By the way, this is a very basic question about C programming. There are plenty of sample code on the web that you can learn from before asking in such a mailing list.
-Wenguang
> //unsigned long byts=pread(fd, 0, 512, 0);
> //unsigned long byts=pread(fd, 512, 512, 0);
> //unsigned long byts=pread(fd, 512, 0, 0);
> //nbytes_got = pread(fd, buf, nbytes, off);
>
>
> printf("byts = %lu", byts);
> return 0;
> }
>
> OutPut:
> Hello, World!
> byts = 18446744073709551615
>
>
> Regards,
> Waqar Ahmad
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Filesystem-dev mailing list (email@hidden)
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Filesystem-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden