deek5
deek5

Reputation: 365

How rename an Volume (partition) with Objective-C?

I create vhd in different formats (NTFS, FAT32, FAT16, HFS +), I do not find the way to get the $ Volume_name offset of an NTFS partition, plus I would like to convert a string to $ Volume_name. By observing the $ Volume_name of an NTFS partition I was able to see that the string is cut (after each character there is a null character example what we read in hexadecimal of the volume_name that would be "WIN10EN" and in hexa "57494e3130454e" if we go to the offset of $ volume_name we will read with a hexadecimal editor 570049004e003100300045004e and its representation ascii "W I N 1 0 E N". Hence my question is there a command to obtain the offset of $ Volume_name (the offset is in byte 15776 or 0x3DA0)? Is there a string conversion to name a Volume?

Upvotes: -1

Views: 304

Answers (2)

deek5
deek5

Reputation: 365

Hello, to rename a Volume with Xcode on Mac, the easiest way is to use The functions of DiskArbitration and more specifically

"void DADiskRename (DADiskRef disk, CFStringRef name, DADiskRenameOptions options, DADiskRenameCallback callback, void * context);
"

With an empty callback. Which can give.

#import <DiskArbitration / DiskArbitration.h>
#import <Cocoa / Cocoa.h>



Void MountCallback (DADiskRef disk, DADitererRef dissenter, void * context);

Void DADiskRename (DADiskRef disk, CFStringRef name, DADiskRenameOptions options, DADiskRenameCallback callback, void * context);
Int rename (char * argv, char * device)
Int renomer ((char * argv, char * device)
{

    Const char * deviceName = device;

    Renom = 1;

    CFStringRef name = CFStringCreateWithCString (NULL, argv, kCFStringEncodingUTF8);



    DASessionRef session = DASessionCreate (kCFAllocatorDefault);

    DADiskRef disk = DADiskCreateFromBSDName (kCFAllocatorDefault, session, deviceName);

    DADiskRename (disk, name, 0x00000000, MountCallback, (void *) deviceName);

    DASessionSetDispatchQueue (session, NULL);

    CFRelease (session);

    Session = NULL;

Return EXIT_SUCCESS;


}



Void MountCallback (DADiskRef disk, DADitererRef dissenter, void * context) {

    Return;
}

Upvotes: 1

deek5
deek5

Reputation: 365

In the creation of a Vhd of course there is the formatting of the partition (my Vhd created have a unique MBR partition) formatting with diskutil according to the chosen system the names of the partitions is limited for NTFS according to diskutil the names are In Capital letter, idem for MSDOS FAT. While long for NTFS or FAT partitions you can use names with small letter. So after formatting for NTFS partitions I use "newfs_ufsd_NTFS -v" to rename with Capital letter, and small letter. For FAT, I changed news_msdos (version 226 https://opensource.apple.com/tarballs/msdosfs/msdosfs-226.tar.gz) the newfs_msdos.c file to line 1320 in "mklabel (u_int8_t** * dest, Const char * src) "where we find" c = * src? Toupper (* src ++): '';" Changed to "c = * src? * Src ++: '';" **which makes it possible to use capital letters or small letters. So for my solution, I do not find an answer to how to get the $Volume_name offset from an NTFS partition.

Upvotes: 0

Related Questions