static int storage_info_func (CameraFilesystem *fs, CameraStorageInformation **storageinformations, int *nrofstorageinformations, void *data, GPContext *context) { Camera *camera = data; int r; struct tf_packet reply; CameraStorageInformation *sif; /* List your storages here */ gp_log (GP_LOG_ERROR, "topfield", __func__); r = send_cmd_hdd_size(camera,context); if(r < 0) return r; r = get_tf_packet(camera, &reply, context); if(r < 0) return r; switch (get_u32(&reply.cmd)) { case DATA_HDD_SIZE: { unsigned int totalk = get_u32(&reply.data); unsigned int freek = get_u32(&reply.data[4]); sif = *storageinformations = calloc(sizeof(CameraStorageInformation),1); *nrofstorageinformations = 1; sif->fields |= GP_STORAGEINFO_BASE; strcpy (sif->basedir,"/"); sif->fields |= GP_STORAGEINFO_STORAGETYPE; sif->type = GP_STORAGEINFO_ST_FIXED_RAM; sif->fields |= GP_STORAGEINFO_ACCESS; sif->access = GP_STORAGEINFO_AC_READWRITE; sif->fields |= GP_STORAGEINFO_FILESYSTEMTYPE; sif->fstype = GP_STORAGEINFO_FST_GENERICHIERARCHICAL; sif->fields |= GP_STORAGEINFO_MAXCAPACITY; sif->capacitykbytes = totalk / 1024; sif->fields |= GP_STORAGEINFO_FREESPACEKBYTES; sif->freekbytes = freek / 1024; return GP_OK; break; } case FAIL: gp_log (GP_LOG_ERROR, "topfield", "ERROR: Device reports %s\n", decode_error(&reply)); break; default: gp_log (GP_LOG_ERROR, "topfield", "ERROR: Unhandled packet\n"); break; } return GP_ERROR_IO; }
int do_hdd_size(int fd) { int r; r = send_cmd_hdd_size(fd); if(r < 0) { return -EPROTO; } r = get_tf_packet(fd, &reply); if(r < 0) { return -EPROTO; } switch (get_u32(&reply.cmd)) { case DATA_HDD_SIZE: { __u32 totalk = get_u32(&reply.data); __u32 freek = get_u32(&reply.data[4]); printf("Total %10u kiB %7u MiB %4u GiB\n", totalk, totalk / 1024, totalk / (1024 * 1024)); printf("Free %10u kiB %7u MiB %4u GiB\n", freek, freek / 1024, freek / (1024 * 1024)); return 0; break; } case FAIL: fprintf(stderr, "ERROR: Device reports %s\n", decode_error(&reply)); break; default: fprintf(stderr, "ERROR: Unhandled packet\n"); } return -EPROTO; }