Re: How do I read sectors of disk in objective c cocoa application?
Re: How do I read sectors of disk in objective c cocoa application?
- Subject: Re: How do I read sectors of disk in objective c cocoa application?
- From: Martin mahal Halter <email@hidden>
- Date: Fri, 09 Dec 2011 15:21:40 +0100
hi waqar
in your first mail you wrote that you just want to read values from and to a file, so no need to read the HFS catalog and sectors.
By reading your other mails, I had the impression you probably need some architectural guidance as well. So please don't be offended by my trivial reading tipps. All Apple Developer Documentation is very well written and helped me a lot getting into the Cocoa way of doing things.
Have a look at the File System Programming Guide:
http://developer.apple.com/library/mac/#documentation/FileManagement/Conceptual/FileSystemProgrammingGUide/FileSystemOverview/FileSystemOverview.html
Especially the chapter "Choose the Right Way to Access Files":
http://developer.apple.com/library/mac/#documentation/FileManagement/Conceptual/FileSystemProgrammingGUide/AccessingFilesandDirectories/AccessingFilesandDirectories.html#//apple_ref/doc/uid/TP40010672-CH3-SW5
Here few lines of cocoa pseudo code. I'm not really a c-programmer, but i know all the Cocoa ways to interact with files.
// write
NSData *hexValues = [NSData dataWithBytes:(const void *)bytes length:(NSUInteger)length];
BOOL success = [hexValues writeToFile:[@"~/filename" stringByExpandingTildeInPath] atomically:YES];
// read
NSData *hexValues = [NSData dataWithContentsOfFile:[@"~/filename" stringByExpandingTildeInPath]];
[hexValues getBytes:&pointerToBytes length:(NSUInteger)length];
// alternatively use NSFileManager contentsAtPath:
You could also go the way to Core Foundation (to avoid Objective-C) by using CFData-Functions:
http://developer.apple.com/library/mac/#documentation/CoreFoundation/Reference/CFDataRef/Reference/reference.html
What kind of data-structures are you going to read? Is it some that you create yourself?
What do you mean by "read mounted drives programmatically"?
* To get a list of mounted drives use the NSWorkspace mountedLocalVolumePaths
* To get a list of files at a specific path use NSFileManager contentsOfDirectoryAtPath:error or use the modern NSURL and NSDirectoryEnumerator APIs
And it has been asked before: What is your goal? Are you porting a win32.exe to Mac OS X?
Best regards,
mahal
http://raskinformac.com
Am 07.12.2011 um 15:03 schrieb Waqar Ahmad:
> Hi,
>
> Thanks a lot for your reply, I just want to read mounted drives programmatically and want to write hex values into a file, so kindly guide me through way I can get this...
>
> Regards,
> Waqar Ahmad
Am 09.12.2011 um 09:05 schrieb Waqar Ahmad:
> 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);
> //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