The particular need for my want to learn how to use mount(), opposed to just setting up a system() call, is quite odd and has to do with encryption algorithms temporarily writing to a disk... I won't get into that, but I will show you how to force an update on a volume that has already been mounted in single user mode as read only, in this case it will be "/"
#import //For mount()
#import //for hfs_mount_args
#import // for #define'd constants
// Outline of an hfs specific struct
/*
struct hfs_mount_args {
char *fspec; ****name of the device e.g:"/dev/disk0s2"
uid_t hfs_uid;
gid_t hfs_gid;
mode_t hfs_mask;
u_int32_t hfs_encoding;
struct timezone hfs_timezone;
int flags;
int journal_tbuffer_size;
int journal_flags;
int journal_disable;
};
*/
int main (int argc, const char * argv[]) {
struct hfs_mount_args some_data; //Declare your struct
int options = 0; //Declare your options variable
int result = 0 //Declare a return variable
some_data.fspec = strdup("/dev/disk0s2"); //Specify a device to be mounted
options = MNT_UPDATE | MNT_NOEXEC; //Forces the volume to not allow executables to run
result = mount("hfs", "/", options ,&some_data);//Mount it
NSLog(@"%d",result);//should return 0 on a successful mount
/* add some more code here*/
return 0;//exit
}
No comments:
Post a Comment