Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jan 25, 2012, 04:31 AM   #1
musharraf
macrumors newbie
 
Join Date: Jan 2012
Open USB Drive as File using NSWorkplace in Objective-C

I am writing an application in MAC-OS using Objective-C , to read Boot-Sector of USB Drive and just to modify some bytes in it.

I created object of NSWorkspace, but problem is that how can pass USB-Drive Path in openFile methods.



Thanks
musharraf is offline   0 Reply With Quote
Old Jan 25, 2012, 05:41 AM   #2
KnightWRX
macrumors Pentium
 
KnightWRX's Avatar
 
Join Date: Jan 2009
Location: Quebec, Canada
Did you mean NSWorkspace ?

http://developer.apple.com/library/m...Reference.html

What have you tried that hasn't worked ? Are you sure this is the class you want for what you want to do ? What exactly are you trying to achieve where you think you need to modify some bytes in the boot sector of a USB flash drive ?

To modify a device at such a level under Unix, you usually require access to the character device special file which will present you the device in "raw" mode. Under OS X, I believe these files will be /dev/rdisk# where # is replaced by the disk number.

NSWorkspace doesn't sound like what you need at all, except maybe to get a list of mounted media using the - (NSArray *)mountedRemovableMedia method. But frankly, this won't give you the DSF for the USB media. openFile doesn't do what you think it does, it basically acts as if you've double clicked a file.

You probably need to look a bit deeper here, the I/O Kit API is probably more in-tune with what you want to do, along with the I/O Registry :

http://developer.apple.com/library/m...Reference.html

Once you have the info for the USB device, just go for standard ANSI C or POSIX stuff to manipulate the bits in the file (fopen()/open(), fseek(), fprintf()/fputc(), fclose()/close()).
__________________
"What you leave behind is not what is engraved in stone monuments, but what is woven into the lives of others."
-- Pericles
KnightWRX is offline   0 Reply With Quote
Old Jan 25, 2012, 05:54 AM   #3
musharraf
Thread Starter
macrumors newbie
 
Join Date: Jan 2012
Open USB Drive as File using NSWorkplace in Objective-C

Hi,

In Windows I am using "CreateFile" API to get handle USB DRIVE e.g( H:\\ etc.) and using "DeviceIoControl" to mount and Unmount USB Drive to update its Boot Sector.

This same functionality I want to use in MAC-OS. I can open using ANSI-C functions but Mount/Unmount... how can be.


Thanks
musharraf is offline   0 Reply With Quote
Old Jan 25, 2012, 06:05 AM   #4
KnightWRX
macrumors Pentium
 
KnightWRX's Avatar
 
Join Date: Jan 2009
Location: Quebec, Canada
Did you read my second link ? That's a pretty hefty document I pointed to (the I/O kit reference). It should contain everything you need to know. But again I question why you feel the need to even modify the boot sector of a USB drive ?
__________________
"What you leave behind is not what is engraved in stone monuments, but what is woven into the lives of others."
-- Pericles
KnightWRX is offline   0 Reply With Quote
Old Jan 25, 2012, 01:33 PM   #5
kainjow
Moderator emeritus
 
kainjow's Avatar
 
Join Date: Jun 2000
Use DiskArbitration framework to get local drives. Then feed the kDADiskDescriptionMediaBSDNameKey of the disk to opendev().

You can also then use DADiskUnmount(), DADiskMount(), and DADiskEject().
kainjow is offline   1 Reply With Quote
Old Jan 11, 2013, 12:17 AM   #6
numero
macrumors member
 
Join Date: Jul 2002
Location: OR
I did a project like this a few years ago. I ended up reading the /dev/rdisk file. The link below will explain how the data is structured. Open the /dev/rdisk file for reading and march down the bytes.

http://www.microsoft.com/whdc/system...re/fatgen.mspx
numero is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
virtualbox do not see USB drive in my computer Meric Windows, Linux & Others on the Mac 2 Oct 27, 2012 07:10 AM
Formatted USB drive as "Free space" and now isn't found rodnet OS X 1 Jul 1, 2010 12:01 AM
CORRECTLY format usb drive for pc use maclook Mac Basics and Help 2 Sep 19, 2009 06:46 PM
I'm an idiot--how to view USB Drive photo files from PC on new MAC Book? primaamanda MacBook 6 May 1, 2009 10:55 PM
Deleting files off USB drive deletes files - Doesn't free up space jpod89 Mac Basics and Help 6 Jan 17, 2008 10:26 PM


All times are GMT -5. The time now is 02:03 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC