Changeset View
Changeset View
Standalone View
Standalone View
usr.sbin/bsdinstall/partedit/partedit.c
Show First 20 Lines • Show All 318 Lines • ▼ Show 20 Lines | if (root->newfs == NULL && !sade_mode) { | ||||
if (cancel) | if (cancel) | ||||
return (FALSE); | return (FALSE); | ||||
} | } | ||||
return (TRUE); | return (TRUE); | ||||
} | } | ||||
static int | static int | ||||
mountpoint_sorter(const void *xa, const void *xb) | |||||
{ | |||||
struct partition_metadata *a = *(struct partition_metadata **)xa; | |||||
struct partition_metadata *b = *(struct partition_metadata **)xb; | |||||
if (a->fstab == NULL && b->fstab == NULL) | |||||
return 0; | |||||
if (a->fstab == NULL) | |||||
return 1; | |||||
if (b->fstab == NULL) | |||||
return -1; | |||||
return strcmp(a->fstab->fs_file, b->fstab->fs_file); | |||||
} | |||||
static int | |||||
apply_changes(struct gmesh *mesh) | apply_changes(struct gmesh *mesh) | ||||
{ | { | ||||
struct partition_metadata *md; | struct partition_metadata *md; | ||||
char message[512]; | char message[512]; | ||||
int i, nitems, error; | int i, nitems, error; | ||||
const char **items; | const char **items; | ||||
const char *fstab_path; | const char *fstab_path; | ||||
FILE *fstab; | FILE *fstab; | ||||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | apply_changes(struct gmesh *mesh) | ||||
} | } | ||||
dialog_mixedgauge("Initializing", | dialog_mixedgauge("Initializing", | ||||
"Initializing file systems. Please wait.", 0, 0, | "Initializing file systems. Please wait.", 0, 0, | ||||
i*100/nitems, nitems, __DECONST(char **, items)); | i*100/nitems, nitems, __DECONST(char **, items)); | ||||
for (i = 1; i < nitems; i++) | for (i = 1; i < nitems; i++) | ||||
free(__DECONST(char *, items[i*2])); | free(__DECONST(char *, items[i*2])); | ||||
free(items); | free(items); | ||||
/* Sort filesystems for fstab so that mountpoints are ordered */ | |||||
{ | |||||
struct partition_metadata **tobesorted; | |||||
struct partition_metadata *tmp; | |||||
int nparts = 0; | |||||
TAILQ_FOREACH(md, &part_metadata, metadata) | |||||
nparts++; | |||||
tobesorted = malloc(sizeof(struct partition_metadata *)*nparts); | |||||
nparts = 0; | |||||
TAILQ_FOREACH_SAFE(md, &part_metadata, metadata, tmp) { | |||||
tobesorted[nparts++] = md; | |||||
TAILQ_REMOVE(&part_metadata, md, metadata); | |||||
} | |||||
qsort(tobesorted, nparts, sizeof(tobesorted[0]), | |||||
mountpoint_sorter); | |||||
/* Now re-add everything */ | |||||
while (nparts-- > 0) | |||||
TAILQ_INSERT_HEAD(&part_metadata, | |||||
tobesorted[nparts], metadata); | |||||
free(tobesorted); | |||||
} | |||||
if (getenv("PATH_FSTAB") != NULL) | if (getenv("PATH_FSTAB") != NULL) | ||||
fstab_path = getenv("PATH_FSTAB"); | fstab_path = getenv("PATH_FSTAB"); | ||||
else | else | ||||
fstab_path = "/etc/fstab"; | fstab_path = "/etc/fstab"; | ||||
fstab = fopen(fstab_path, "w+"); | fstab = fopen(fstab_path, "w+"); | ||||
if (fstab == NULL) { | if (fstab == NULL) { | ||||
sprintf(message, "Cannot open fstab file %s for writing (%s)\n", | sprintf(message, "Cannot open fstab file %s for writing (%s)\n", | ||||
▲ Show 20 Lines • Show All 184 Lines • Show Last 20 Lines |