void parselabel(void) { char *partname, *partduid; struct fstab *fsent; int i; i = asprintf(&partname, "/dev/%s%c", dkname, 'a'); if (i == -1) err(4, NULL); i = asprintf(&partduid, "%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx.a", lab.d_uid[0], lab.d_uid[1], lab.d_uid[2], lab.d_uid[3], lab.d_uid[4], lab.d_uid[5], lab.d_uid[6], lab.d_uid[7]); if (i == -1) err(4, NULL); setfsent(); for (i = 0; i < MAXPARTITIONS; i++) { partname[strlen(dkname) + 5] = 'a' + i; partduid[strlen(partduid) - 1] = 'a' + i; fsent = getfsspec(partname); if (fsent == NULL) fsent = getfsspec(partduid); if (fsent) mountpoints[i] = strdup(fsent->fs_file); } endfsent(); free(partduid); free(partname); if (aflag) editor_allocspace(&lab); }
/* * Fetch requested disklabel into 'lab' using ioctl. */ void readlabel(int f) { char *partname, *partduid; struct fstab *fsent; int i; if (cflag && ioctl(f, DIOCRLDINFO) < 0) err(4, "ioctl DIOCRLDINFO"); if ((op == RESTORE) || dflag || aflag) { if (ioctl(f, DIOCGPDINFO, &lab) < 0) err(4, "ioctl DIOCGPDINFO"); } else { if (ioctl(f, DIOCGDINFO, &lab) < 0) err(4, "ioctl DIOCGDINFO"); } asprintf(&partname, "/dev/%s%c", dkname, 'a'); asprintf(&partduid, "%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx.a", lab.d_uid[0], lab.d_uid[1], lab.d_uid[2], lab.d_uid[3], lab.d_uid[4], lab.d_uid[5], lab.d_uid[6], lab.d_uid[7]); setfsent(); for (i = 0; i < MAXPARTITIONS; i++) { partname[strlen(dkname) + 5] = 'a' + i; partduid[strlen(partduid) - 1] = 'a' + i; fsent = getfsspec(partname); if (fsent == NULL) fsent = getfsspec(partduid); if (fsent) mountpoints[i] = strdup(fsent->fs_file); } endfsent(); free(partduid); free(partname); if (aflag) editor_allocspace(&lab); }