Print this page
libbe
ba_path->module + lost file
*** 459,473 ****
while (fgets(line, BUFSIZ, menu_fp)) {
char *tok = NULL;
(void) strlcpy(temp_line, line, BUFSIZ);
! tok = strtok(line, BE_WHITE_SPACE);
if (tok == NULL || tok[0] == '#') {
continue;
! } else if (strcmp(tok, "title") == 0) {
collect_lines = B_FALSE;
if ((tok = strtok(NULL, "\n")) == NULL)
(void) strlcpy(title, "", sizeof (title));
else
(void) strlcpy(title, tok, sizeof (title));
--- 459,473 ----
while (fgets(line, BUFSIZ, menu_fp)) {
char *tok = NULL;
(void) strlcpy(temp_line, line, BUFSIZ);
! tok = strtok(line, "=\n");
if (tok == NULL || tok[0] == '#') {
continue;
! } else if (strcmp(tok, "entry_name") == 0) {
collect_lines = B_FALSE;
if ((tok = strtok(NULL, "\n")) == NULL)
(void) strlcpy(title, "", sizeof (title));
else
(void) strlcpy(title, tok, sizeof (title));
*** 478,488 ****
free(tmp_entries[i]);
tmp_entries[i] = NULL;
}
num_tmp_lines = 0;
}
! } else if (strcmp(tok, "bootfs") == 0) {
char *bootfs = strtok(NULL, BE_WHITE_SPACE);
found_title = B_FALSE;
if (bootfs == NULL)
continue;
--- 478,488 ----
free(tmp_entries[i]);
tmp_entries[i] = NULL;
}
num_tmp_lines = 0;
}
! } else if (strcmp(tok, "data_set") == 0) {
char *bootfs = strtok(NULL, BE_WHITE_SPACE);
found_title = B_FALSE;
if (bootfs == NULL)
continue;
*** 498,508 ****
found_orig_be = B_TRUE;
num_lines = 0;
/*
* Store the new title line
*/
! (void) snprintf(str, BUFSIZ, "title %s\n",
description ? description : be_name);
entries[num_lines] = strdup(str);
num_lines++;
/*
* If there are any lines between the title
--- 498,508 ----
found_orig_be = B_TRUE;
num_lines = 0;
/*
* Store the new title line
*/
! (void) snprintf(str, BUFSIZ, "entry_name=%s\n",
description ? description : be_name);
entries[num_lines] = strdup(str);
num_lines++;
/*
* If there are any lines between the title
*** 512,526 ****
for (i = 0; i < num_tmp_lines; i++) {
entries[num_lines] = tmp_entries[i];
tmp_entries[i] = NULL;
num_lines++;
}
! num_tmp_lines = 0;
/*
* Store the new bootfs line.
*/
! (void) snprintf(str, BUFSIZ, "bootfs %s\n",
be_root_ds);
entries[num_lines] = strdup(str);
num_lines++;
collect_lines = B_TRUE;
}
--- 512,546 ----
for (i = 0; i < num_tmp_lines; i++) {
entries[num_lines] = tmp_entries[i];
tmp_entries[i] = NULL;
num_lines++;
}
!
! zprop_get_cbdata_t cb = { 0 };
! zprop_source_t src;
! char * bc = strchr(be_root_ds, '/');
! char sguid[] = "guid";
!
! *bc = '\0';
! cb.cb_first = B_TRUE;
! cb.cb_sources = ZPROP_SRC_ALL;
! cb.cb_type = ZFS_TYPE_POOL;
! zprop_get_list(g_zfs, sguid, &cb.cb_proplist, ZFS_TYPE_POOL);
! zpool_handle_t * z_hndl = zpool_open(g_zfs, be_root_ds);
! *bc = '/';
! if (z_hndl) {
! uint64_t guid = zpool_get_prop_int(z_hndl, cb.cb_proplist->pl_prop, &src);
! (void) snprintf(str, BUFSIZ, "pool_uuid=%llx\n", guid);
! entries[num_lines] = strdup(str);
! num_lines++;
! zpool_close(z_hndl);
! }
! num_tmp_lines = 0;
/*
* Store the new bootfs line.
*/
! (void) snprintf(str, BUFSIZ, "data_set=%s\n",
be_root_ds);
entries[num_lines] = strdup(str);
num_lines++;
collect_lines = B_TRUE;
}
*** 534,543 ****
--- 554,576 ----
continue;
if (strcmp(tok, "splashimage") == 0) {
entries[num_lines] =
strdup("splashimage "
"/boot/splashimage.xpm\n");
+ } else if ((strcmp(tok, "kernel_path") == 0) ||
+ (strcmp(tok, "module") == 0))
+ {
+ char * path;
+ char * st_path;
+
+ st_path = strtok(NULL, "\n");
+ path = (char *) malloc(512);
+ strcpy(path, tok);
+ strcat(path, "=");
+ strcat(path, st_path);
+ strcat(path, "\n");
+ entries[num_lines] = path;
} else {
entries[num_lines] = strdup(temp_line);
}
num_lines++;
} else if (found_title && !found_orig_be) {
*** 596,617 ****
*/
if (be_has_grub())
(void) fprintf(menu_fp, "%s\n", BE_GRUB_COMMENT);
ret = BE_SUCCESS;
} else {
! (void) fprintf(menu_fp, "title %s\n",
description ? description : be_name);
! (void) fprintf(menu_fp, "bootfs %s\n", be_root_ds);
/*
* Check to see if this system supports grub
*/
if (be_has_grub()) {
! (void) fprintf(menu_fp, "kernel$ "
! "/platform/i86pc/kernel/$ISADIR/unix -B "
! "$ZFS-BOOTFS\n");
! (void) fprintf(menu_fp, "module$ "
"/platform/i86pc/$ISADIR/boot_archive\n");
(void) fprintf(menu_fp, "%s\n", BE_GRUB_COMMENT);
}
ret = BE_SUCCESS;
}
--- 629,668 ----
*/
if (be_has_grub())
(void) fprintf(menu_fp, "%s\n", BE_GRUB_COMMENT);
ret = BE_SUCCESS;
} else {
! zprop_get_cbdata_t cb = { 0 };
! zprop_source_t src;
! char * bc = strchr(be_root_ds, '/');
! char sguid[] = "guid";
!
! (void) fprintf(menu_fp, "entry_name=%s\n",
description ? description : be_name);
! *bc = '\0';
! cb.cb_first = B_TRUE;
! cb.cb_sources = ZPROP_SRC_ALL;
! cb.cb_type = ZFS_TYPE_POOL;
! zprop_get_list(g_zfs, sguid, &cb.cb_proplist, ZFS_TYPE_POOL);
! zpool_handle_t * z_hndl = zpool_open(g_zfs, be_root_ds);
! *bc = '/';
! if (z_hndl) {
! uint64_t guid = zpool_get_prop_int(z_hndl, cb.cb_proplist->pl_prop, &src);
! (void) fprintf(menu_fp, "pool_uuid=%llx\n", guid);
! zpool_close(z_hndl);
! }
! (void) fprintf(menu_fp, "data_set=%s\n", be_root_ds);
/*
* Check to see if this system supports grub
*/
if (be_has_grub()) {
! (void) fprintf(menu_fp, "kernel_path="
! "/platform/i86pc/kernel/$ISADIR/unix\n");
! (void) fprintf(menu_fp, "kernel_options="
! "-B $ZFS_BOOTFS,console=graphic\n");
! (void) fprintf(menu_fp, "module="
"/platform/i86pc/$ISADIR/boot_archive\n");
(void) fprintf(menu_fp, "%s\n", BE_GRUB_COMMENT);
}
ret = BE_SUCCESS;
}
*** 787,797 ****
char *tok = NULL;
(void) strlcpy(tline, menu_buf, sizeof (tline));
/* Tokenize line */
! tok = strtok(tline, BE_WHITE_SPACE);
if (tok == NULL || tok[0] == '#') {
/* Found empty line or comment line */
if (do_buffer) {
/* Buffer this line */
--- 838,848 ----
char *tok = NULL;
(void) strlcpy(tline, menu_buf, sizeof (tline));
/* Tokenize line */
! tok = strtok(tline, "=\n");
if (tok == NULL || tok[0] == '#') {
/* Found empty line or comment line */
if (do_buffer) {
/* Buffer this line */
*** 809,819 ****
} else if (write || strncmp(menu_buf, BE_GRUB_COMMENT,
strlen(BE_GRUB_COMMENT)) != 0) {
/* Write this line out */
(void) fputs(menu_buf, tmp_menu_fp);
}
! } else if (strcmp(tok, "default") == 0) {
/*
* Record what 'default' is set to because we might
* need to adjust this upon deleting an entry.
*/
tok = strtok(NULL, BE_WHITE_SPACE);
--- 860,870 ----
} else if (write || strncmp(menu_buf, BE_GRUB_COMMENT,
strlen(BE_GRUB_COMMENT)) != 0) {
/* Write this line out */
(void) fputs(menu_buf, tmp_menu_fp);
}
! } else if (strcmp(tok, "default_entry") == 0) {
/*
* Record what 'default' is set to because we might
* need to adjust this upon deleting an entry.
*/
tok = strtok(NULL, BE_WHITE_SPACE);
*** 821,831 ****
if (tok != NULL) {
default_entry = atoi(tok);
}
(void) fputs(menu_buf, tmp_menu_fp);
! } else if (strcmp(tok, "title") == 0) {
/*
* If we've reached a 'title' line and do_buffer is
* is true, that means we've just buffered an entire
* entry without finding a 'bootfs' directive. We
* need to write that entry out and keep searching.
--- 872,882 ----
if (tok != NULL) {
default_entry = atoi(tok);
}
(void) fputs(menu_buf, tmp_menu_fp);
! } else if (strcmp(tok, "entry_name") == 0) {
/*
* If we've reached a 'title' line and do_buffer is
* is true, that means we've just buffered an entire
* entry without finding a 'bootfs' directive. We
* need to write that entry out and keep searching.
*** 857,867 ****
if ((buffer[nlines++] = strdup(menu_buf)) == NULL) {
ret = BE_ERR_NOMEM;
goto cleanup;
}
! } else if (strcmp(tok, "bootfs") == 0) {
char *bootfs = NULL;
/*
* Found a 'bootfs' line. See if it matches the
* BE we're looking for.
--- 908,918 ----
if ((buffer[nlines++] = strdup(menu_buf)) == NULL) {
ret = BE_ERR_NOMEM;
goto cleanup;
}
! } else if (strcmp(tok, "data_set") == 0) {
char *bootfs = NULL;
/*
* Found a 'bootfs' line. See if it matches the
* BE we're looking for.
*** 1018,1036 ****
char *tok = NULL;
(void) strlcpy(tline, menu_buf, sizeof (tline));
/* Tokenize line */
! tok = strtok(tline, BE_WHITE_SPACE);
if (tok == NULL) {
/* Found empty line, write it out */
(void) fputs(menu_buf, tmp_menu_fp);
! } else if (strcmp(tok, "default") == 0) {
/* Found the default line, adjust it */
(void) snprintf(tline, sizeof (tline),
! "default %d\n", default_entry);
(void) fputs(tline, tmp_menu_fp);
} else {
/* Pass through all other lines */
(void) fputs(menu_buf, tmp_menu_fp);
--- 1069,1087 ----
char *tok = NULL;
(void) strlcpy(tline, menu_buf, sizeof (tline));
/* Tokenize line */
! tok = strtok(tline, "=\n");
if (tok == NULL) {
/* Found empty line, write it out */
(void) fputs(menu_buf, tmp_menu_fp);
! } else if (strcmp(tok, "default_entry") == 0) {
/* Found the default line, adjust it */
(void) snprintf(tline, sizeof (tline),
! "default_entry=%d\n", default_entry);
(void) fputs(tline, tmp_menu_fp);
} else {
/* Pass through all other lines */
(void) fputs(menu_buf, tmp_menu_fp);
*** 1185,1212 ****
free(pool_mntpnt);
pool_mntpnt = NULL;
while (fgets(line, BUFSIZ, menu_fp)) {
! char *tok = strtok(line, BE_WHITE_SPACE);
if (tok != NULL && tok[0] != '#') {
if (!found_default) {
! if (strcmp(tok, "default") == 0) {
tok = strtok(NULL, BE_WHITE_SPACE);
if (tok != NULL) {
default_entry = atoi(tok);
rewind(menu_fp);
found_default = 1;
}
}
continue;
}
! if (strcmp(tok, "title") == 0) {
entries++;
} else if (default_entry == entries - 1) {
! if (strcmp(tok, "bootfs") == 0) {
tok = strtok(NULL, BE_WHITE_SPACE);
(void) fclose(menu_fp);
if (tok == NULL) {
ret = BE_SUCCESS;
--- 1236,1263 ----
free(pool_mntpnt);
pool_mntpnt = NULL;
while (fgets(line, BUFSIZ, menu_fp)) {
! char *tok = strtok(line, "=\n");
if (tok != NULL && tok[0] != '#') {
if (!found_default) {
! if (strcmp(tok, "default_entry") == 0) {
tok = strtok(NULL, BE_WHITE_SPACE);
if (tok != NULL) {
default_entry = atoi(tok);
rewind(menu_fp);
found_default = 1;
}
}
continue;
}
! if (strcmp(tok, "entry_name") == 0) {
entries++;
} else if (default_entry == entries - 1) {
! if (strcmp(tok, "data_set") == 0) {
tok = strtok(NULL, BE_WHITE_SPACE);
(void) fclose(menu_fp);
if (tok == NULL) {
ret = BE_SUCCESS;
*** 1385,1402 ****
ret = errno_to_be_err(err);
goto cleanup;
}
while (fgets(line, BUFSIZ, grub_fp)) {
! char *tok = strtok(line, BE_WHITE_SPACE);
if (tok == NULL || tok[0] == '#') {
continue;
! } else if (strcmp(tok, "title") == 0) {
entries++;
continue;
! } else if (strcmp(tok, "bootfs") == 0) {
char *bootfs = strtok(NULL, BE_WHITE_SPACE);
if (bootfs == NULL)
continue;
if (strcmp(bootfs, be_root_ds) == 0) {
--- 1436,1453 ----
ret = errno_to_be_err(err);
goto cleanup;
}
while (fgets(line, BUFSIZ, grub_fp)) {
! char *tok = strtok(line, "=\n");
if (tok == NULL || tok[0] == '#') {
continue;
! } else if (strcmp(tok, "entry_name") == 0) {
entries++;
continue;
! } else if (strcmp(tok, "data_set") == 0) {
char *bootfs = strtok(NULL, BE_WHITE_SPACE);
if (bootfs == NULL)
continue;
if (strcmp(bootfs, be_root_ds) == 0) {
*** 1414,1433 ****
goto cleanup;
}
rewind(grub_fp);
while (fgets(line, BUFSIZ, grub_fp)) {
char *tok = NULL;
(void) strncpy(temp_line, line, BUFSIZ);
! if ((tok = strtok(temp_line, BE_WHITE_SPACE)) != NULL &&
! strcmp(tok, "default") == 0) {
! (void) snprintf(temp_line, BUFSIZ, "default %d\n",
! entries - 1 >= 0 ? entries - 1 : 0);
! (void) fputs(temp_line, temp_fp);
} else {
(void) fputs(line, temp_fp);
}
}
--- 1465,1484 ----
goto cleanup;
}
rewind(grub_fp);
+ (void) snprintf(temp_line, BUFSIZ, "default_entry=%d\n",
+ entries - 1 >= 0 ? entries - 1 : 0);
+ (void) fputs(temp_line, temp_fp);
while (fgets(line, BUFSIZ, grub_fp)) {
char *tok = NULL;
(void) strncpy(temp_line, line, BUFSIZ);
! if ((tok = strtok(temp_line, "=\n")) != NULL &&
! strcmp(tok, "default_entry") == 0) {
} else {
(void) fputs(line, temp_fp);
}
}
*** 1518,1527 ****
--- 1569,1579 ----
FILE *new_fp = NULL;
struct stat sb;
int temp_menu_len = 0;
int tmp_fd;
int ret = BE_SUCCESS;
+ int flag = 0;
int err = 0;
boolean_t pool_mounted = B_FALSE;
errno = 0;
*** 1634,1659 ****
char *c = NULL;
(void) strlcpy(tline, line, sizeof (tline));
/* Tokenize line */
! c = strtok(tline, BE_WHITE_SPACE);
if (c == NULL) {
/* Found empty line, write it out. */
(void) fputs(line, new_fp);
} else if (c[0] == '#') {
/* Found a comment line, write it out. */
(void) fputs(line, new_fp);
! } else if (strcmp(c, "title") == 0) {
char *name = NULL;
char *desc = NULL;
/*
* Found a 'title' line, parse out BE name or
* the description.
*/
name = strtok(NULL, BE_WHITE_SPACE);
if (name == NULL) {
/*
* Nothing after 'title', just push
--- 1686,1712 ----
char *c = NULL;
(void) strlcpy(tline, line, sizeof (tline));
/* Tokenize line */
! c = strtok(tline, "=\n");
if (c == NULL) {
/* Found empty line, write it out. */
(void) fputs(line, new_fp);
} else if (c[0] == '#') {
/* Found a comment line, write it out. */
(void) fputs(line, new_fp);
! } else if (strcmp(c, "entry_name") == 0) {
char *name = NULL;
char *desc = NULL;
/*
* Found a 'title' line, parse out BE name or
* the description.
*/
+ flag = 0;
name = strtok(NULL, BE_WHITE_SPACE);
if (name == NULL) {
/*
* Nothing after 'title', just push
*** 1673,1699 ****
* the old BE name, replace it with
* the new one, and write it out
* along with the remainder of
* description if there is one.
*/
if (desc) {
(void) snprintf(new_line,
sizeof (new_line),
! "title %s %s\n",
be_new_name, desc);
} else {
(void) snprintf(new_line,
sizeof (new_line),
! "title %s\n", be_new_name);
}
(void) fputs(new_line, new_fp);
} else {
(void) fputs(line, new_fp);
}
}
! } else if (strcmp(c, "bootfs") == 0) {
/*
* Found a 'bootfs' line, parse out the BE root
* dataset value.
*/
char *root_ds = strtok(NULL, BE_WHITE_SPACE);
--- 1726,1753 ----
* the old BE name, replace it with
* the new one, and write it out
* along with the remainder of
* description if there is one.
*/
+ ++flag;
if (desc) {
(void) snprintf(new_line,
sizeof (new_line),
! "entry_name=%s %s\n",
be_new_name, desc);
} else {
(void) snprintf(new_line,
sizeof (new_line),
! "entry_name=%s\n", be_new_name);
}
(void) fputs(new_line, new_fp);
} else {
(void) fputs(line, new_fp);
}
}
! } else if (strcmp(c, "data_set") == 0) {
/*
* Found a 'bootfs' line, parse out the BE root
* dataset value.
*/
char *root_ds = strtok(NULL, BE_WHITE_SPACE);
*** 1708,1719 ****
/*
* If this bootfs is the one we're renaming,
* write out the new root dataset value
*/
if (strcmp(root_ds, be_root_ds) == 0) {
(void) snprintf(new_line,
! sizeof (new_line), "bootfs %s\n",
be_new_root_ds);
(void) fputs(new_line, new_fp);
} else {
(void) fputs(line, new_fp);
--- 1762,1774 ----
/*
* If this bootfs is the one we're renaming,
* write out the new root dataset value
*/
if (strcmp(root_ds, be_root_ds) == 0) {
+ ++flag;
(void) snprintf(new_line,
! sizeof (new_line), "data_set=%s\n",
be_new_root_ds);
(void) fputs(new_line, new_fp);
} else {
(void) fputs(line, new_fp);
*** 1851,1864 ****
free(rpool_mntpnt);
rpool_mntpnt = NULL;
while (fgets(line, BUFSIZ, menu_fp)) {
! char *tok = strtok_r(line, BE_WHITE_SPACE, &last);
if (tok != NULL && tok[0] != '#') {
! if (strcmp(tok, "bootfs") == 0) {
tok = strtok_r(last, BE_WHITE_SPACE, &last);
if (tok != NULL && strcmp(tok,
be_dataset) == 0) {
(void) fclose(menu_fp);
/*
--- 1906,1919 ----
free(rpool_mntpnt);
rpool_mntpnt = NULL;
while (fgets(line, BUFSIZ, menu_fp)) {
! char *tok = strtok_r(line, "=\n", &last);
if (tok != NULL && tok[0] != '#') {
! if (strcmp(tok, "data_set") == 0) {
tok = strtok_r(last, BE_WHITE_SPACE, &last);
if (tok != NULL && strcmp(tok,
be_dataset) == 0) {
(void) fclose(menu_fp);
/*
*** 1871,1881 ****
*/
*entry = ent_num - 1;
ret = B_TRUE;
goto cleanup;
}
! } else if (strcmp(tok, "title") == 0)
ent_num++;
}
}
cleanup:
--- 1926,1936 ----
*/
*entry = ent_num - 1;
ret = B_TRUE;
goto cleanup;
}
! } else if (strcmp(tok, "entry_name") == 0)
ent_num++;
}
}
cleanup:
*** 3637,3662 ****
* GRUB splash screen will not be enabled.
*/
if (strncmp(console, "text", strlen("text")) == 0 ||
strncmp(console, "graphics",
strlen("graphics")) == 0) {
!
(void) fprintf(temp_fp, "%s\n", BE_GRUB_SPLASH);
(void) fprintf(temp_fp, "%s\n",
BE_GRUB_FOREGROUND);
(void) fprintf(temp_fp, "%s\n",
BE_GRUB_BACKGROUND);
(void) fprintf(temp_fp, "%s\n",
! BE_GRUB_DEFAULT);
} else {
be_print_err(gettext("be_create_menu: "
"console on serial line, "
"GRUB splash image will be disabled\n"));
}
}
! (void) fprintf(temp_fp, "timeout 30\n");
(void) fclose(temp_fp);
} else {
/*
* The menu file doesn't exist so we need to create a
--- 3692,3717 ----
* GRUB splash screen will not be enabled.
*/
if (strncmp(console, "text", strlen("text")) == 0 ||
strncmp(console, "graphics",
strlen("graphics")) == 0) {
! /*
(void) fprintf(temp_fp, "%s\n", BE_GRUB_SPLASH);
(void) fprintf(temp_fp, "%s\n",
BE_GRUB_FOREGROUND);
(void) fprintf(temp_fp, "%s\n",
BE_GRUB_BACKGROUND);
(void) fprintf(temp_fp, "%s\n",
! BE_GRUB_DEFAULT);*/
} else {
be_print_err(gettext("be_create_menu: "
"console on serial line, "
"GRUB splash image will be disabled\n"));
}
}
! (void) fprintf(temp_fp, "timeout=30\n");
(void) fclose(temp_fp);
} else {
/*
* The menu file doesn't exist so we need to create a