/* Put the label in *label and uuid in *uuid. * Return 0 if no label/uuid found, NZ if there is a label or uuid. */ int find_label_or_uuid(char *dev_name, char *label, char *uuid) { struct volume_id id; memset(&id, 0x00, sizeof(id)); if (label) *label = 0; if (uuid) *uuid = 0; if ((id.fd = open(dev_name, O_RDONLY)) < 0) return 0; volume_id_get_buffer(&id, 0, SB_BUFFER_SIZE); if (volume_id_probe_linux_swap(&id) == 0 || id.error) goto ret; if (volume_id_probe_vfat(&id) == 0 || id.error) goto ret; if (volume_id_probe_ext(&id) == 0 || id.error) goto ret; if (volume_id_probe_ntfs(&id) == 0 || id.error) goto ret; #if defined(RTCONFIG_HFS) if(volume_id_probe_hfs_hfsplus(&id) == 0 || id.error) goto ret; #endif ret: volume_id_free_buffer(&id); if (label && (*id.label != 0)) strcpy(label, id.label); if (uuid && (*id.uuid != 0)) strcpy(uuid, id.uuid); close(id.fd); return (label && *label != 0) || (uuid && *uuid != 0); }
int find_partition_label(const char *dev_name, char *label, int partition_order) { struct volume_id id; char dev_path[128]; char usb_port[8]; int port_num; char nvram_label[32], nvram_value[512]; if(label) *label = 0; memset(usb_port, 0, 8); if(get_usb_port_by_device(dev_name, usb_port, 8) == NULL) return 0; port_num = get_usb_port_number(usb_port); memset(nvram_label, 0, 32); sprintf(nvram_label, "usb_path%d_label%d", port_num, partition_order); memset(nvram_value, 0, 512); strncpy(nvram_value, nvram_safe_get(nvram_label), 512); if(strlen(nvram_value) > 0) { strcpy(label, nvram_value); return (label && *label != 0); } memset(dev_path, 0, 128); sprintf(dev_path, "/dev/%s", dev_name); memset(&id, 0x00, sizeof(id)); if((id.fd = open(dev_path, O_RDONLY)) < 0) return 0; volume_id_get_buffer(&id, 0, SB_BUFFER_SIZE); if(volume_id_probe_linux_swap(&id) == 0 || id.error) goto ret; if(volume_id_probe_ext(&id) == 0 || id.error) goto ret; if(volume_id_probe_vfat(&id) == 0 || id.error) goto ret; if(volume_id_probe_ntfs(&id) == 0 || id.error) goto ret; if(volume_id_probe_hfs_hfsplus(&id) == 0 || id.error) goto ret; ret: volume_id_free_buffer(&id); if(label && (*id.label != 0)) strcpy(label, id.label); else strcpy(label, " "); nvram_set(nvram_label, label); close(id.fd); return (label && *label != 0); }