Skip to content

Instantly share code, notes, and snippets.

@tomac
Created June 30, 2014 14:11
Show Gist options
  • Select an option

  • Save tomac/332b80c1fea81684753f to your computer and use it in GitHub Desktop.

Select an option

Save tomac/332b80c1fea81684753f to your computer and use it in GitHub Desktop.
Desmontar
bsdName = (CFStringRef) IORegistryEntrySearchCFProperty(device
, kIOServicePlane
, CFSTR( kIOBSDNameKey )
, NULL
, kIORegistryIterateRecursively);
/* Ahora ya podemos ver si está latch activado o no para desmontar el disco */
char* bsdNameChar = malloc(CFStringGetLength(bsdName) * sizeof(char));
if (bsdNameChar) {
if (CFStringGetCString(bsdName, bsdNameChar, CFStringGetLength(bsdName) +1, kCFStringEncodingASCII)) {
/* Hacemos la petición a latch usando el SDK para C */
buffer = operationStatus(pAccountId, operationId);
if(buffer == NULL || strcmp(buffer,"") == 0) {
fprintf(stderr, "Error contacting latch servers");
return 1;
}
/* Si el estado es off, entonces desmontamos el disco */
if (strstr(buffer, "\"status\":\"off\"") != NULL) {
fprintf (stdout, "Status: latch locked\n");
fprintf(stderr, "Ejecting %s...\n", bsdNameChar);
int size = strlen("/usr/sbin/diskutil") + strlen(" eject") + strlen(bsdNameChar) + 2;
char *command = (char *) malloc(size);
snprintf(command, size, "/usr/sbin/diskutil eject %s", bsdNameChar);
system(command);
free(command);
/* Si está a on, lo dejamos conectarse sin problemas */
} else if (strstr(buffer, "\"status\":\"on\"") != NULL){
fprintf (stdout, "Status: latch not locked\n");
} else {
fprintf(stderr, "Ouch. Something went wrong, are you really paired?\n");
return 1;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment