Print this page
libbe
ba_path->module + lost file

@@ -459,15 +459,15 @@
 
         while (fgets(line, BUFSIZ, menu_fp)) {
                 char *tok = NULL;
 
                 (void) strlcpy(temp_line, line, BUFSIZ);
-                tok = strtok(line, BE_WHITE_SPACE);
+                tok = strtok(line, "=\n");
 
                 if (tok == NULL || tok[0] == '#') {
                         continue;
-                } else if (strcmp(tok, "title") == 0) {
+                } 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,11 +478,11 @@
                                         free(tmp_entries[i]);
                                         tmp_entries[i] = NULL;
                                 }
                                 num_tmp_lines = 0;
                         }
-                } else if (strcmp(tok, "bootfs") == 0) {
+                } else if (strcmp(tok, "data_set") == 0) {
                         char *bootfs = strtok(NULL, BE_WHITE_SPACE);
                         found_title = B_FALSE;
                         if (bootfs == NULL)
                                 continue;
 

@@ -498,11 +498,11 @@
                                 found_orig_be = B_TRUE;
                                 num_lines = 0;
                                 /*
                                  * Store the new title line
                                  */
-                                (void) snprintf(str, BUFSIZ, "title %s\n",
+                                (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,15 +512,35 @@
                                 for (i = 0; i < num_tmp_lines; i++) {
                                         entries[num_lines] = tmp_entries[i];
                                         tmp_entries[i] = NULL;
                                         num_lines++;
                                 }
-                                num_tmp_lines = 0;
+
+                                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, "bootfs %s\n",
+                                (void) snprintf(str, BUFSIZ, "data_set=%s\n",
                                     be_root_ds);
                                 entries[num_lines] = strdup(str);
                                 num_lines++;
                                 collect_lines = B_TRUE;
                         }

@@ -534,10 +554,23 @@
                                 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,22 +629,40 @@
                  */
                 if (be_has_grub())
                         (void) fprintf(menu_fp, "%s\n", BE_GRUB_COMMENT);
                 ret = BE_SUCCESS;
         } else {
-                (void) fprintf(menu_fp, "title %s\n",
+                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);
-                (void) fprintf(menu_fp, "bootfs %s\n", be_root_ds);
+                *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$ "
-                            "/platform/i86pc/kernel/$ISADIR/unix -B "
-                            "$ZFS-BOOTFS\n");
-                        (void) fprintf(menu_fp, "module$ "
+                        (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,11 +838,11 @@
                 char *tok = NULL;
 
                 (void) strlcpy(tline, menu_buf, sizeof (tline));
 
                 /* Tokenize line */
-                tok = strtok(tline, BE_WHITE_SPACE);
+                tok = strtok(tline, "=\n");
 
                 if (tok == NULL || tok[0] == '#') {
                         /* Found empty line or comment line */
                         if (do_buffer) {
                                 /* Buffer this line */

@@ -809,11 +860,11 @@
                         } 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) {
+                } 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,11 +872,11 @@
                         if (tok != NULL) {
                                 default_entry = atoi(tok);
                         }
 
                         (void) fputs(menu_buf, tmp_menu_fp);
-                } else if (strcmp(tok, "title") == 0) {
+                } 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,11 +908,11 @@
                         if ((buffer[nlines++] = strdup(menu_buf)) == NULL) {
                                 ret = BE_ERR_NOMEM;
                                 goto cleanup;
                         }
 
-                } else if (strcmp(tok, "bootfs") == 0) {
+                } 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,19 +1069,19 @@
                                 char *tok = NULL;
 
                                 (void) strlcpy(tline, menu_buf, sizeof (tline));
 
                                 /* Tokenize line */
-                                tok = strtok(tline, BE_WHITE_SPACE);
+                                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") == 0) {
+                                } else if (strcmp(tok, "default_entry") == 0) {
                                         /* Found the default line, adjust it */
                                         (void) snprintf(tline, sizeof (tline),
-                                            "default %d\n", default_entry);
+                                            "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,28 +1236,28 @@
 
         free(pool_mntpnt);
         pool_mntpnt = NULL;
 
         while (fgets(line, BUFSIZ, menu_fp)) {
-                char *tok = strtok(line, BE_WHITE_SPACE);
+                char *tok = strtok(line, "=\n");
 
                 if (tok != NULL && tok[0] != '#') {
                         if (!found_default) {
-                                if (strcmp(tok, "default") == 0) {
+                                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, "title") == 0) {
+                        if (strcmp(tok, "entry_name") == 0) {
                                 entries++;
                         } else if (default_entry == entries - 1) {
-                                if (strcmp(tok, "bootfs") == 0) {
+                                if (strcmp(tok, "data_set") == 0) {
                                         tok = strtok(NULL, BE_WHITE_SPACE);
                                         (void) fclose(menu_fp);
 
                                         if (tok == NULL) {
                                                 ret = BE_SUCCESS;

@@ -1385,18 +1436,18 @@
                 ret = errno_to_be_err(err);
                 goto cleanup;
         }
 
         while (fgets(line, BUFSIZ, grub_fp)) {
-                char *tok = strtok(line, BE_WHITE_SPACE);
+                char *tok = strtok(line, "=\n");
 
                 if (tok == NULL || tok[0] == '#') {
                         continue;
-                } else if (strcmp(tok, "title") == 0) {
+                } else if (strcmp(tok, "entry_name") == 0) {
                         entries++;
                         continue;
-                } else if (strcmp(tok, "bootfs") == 0) {
+                } 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,20 +1465,20 @@
                 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, 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);
+                if ((tok = strtok(temp_line, "=\n")) != NULL &&
+                    strcmp(tok, "default_entry") == 0) {
                 } else {
                         (void) fputs(line, temp_fp);
                 }
         }
 

@@ -1518,10 +1569,11 @@
         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,26 +1686,27 @@
                 char *c = NULL;
 
                 (void) strlcpy(tline, line, sizeof (tline));
 
                 /* Tokenize line */
-                c = strtok(tline, BE_WHITE_SPACE);
+                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, "title") == 0) {
+                } 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,27 +1726,28 @@
                                          * 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),
-                                                    "title %s %s\n",
+                                                    "entry_name=%s %s\n",
                                                     be_new_name, desc);
                                         } else {
                                                 (void) snprintf(new_line,
                                                     sizeof (new_line),
-                                                    "title %s\n", be_new_name);
+                                                    "entry_name=%s\n", be_new_name);
                                         }
 
                                         (void) fputs(new_line, new_fp);
                                 } else {
                                         (void) fputs(line, new_fp);
                                 }
                         }
-                } else if (strcmp(c, "bootfs") == 0) {
+                } 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,12 +1762,13 @@
                                 /*
                                  * 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), "bootfs %s\n",
+                                            sizeof (new_line), "data_set=%s\n",
                                             be_new_root_ds);
 
                                         (void) fputs(new_line, new_fp);
                                 } else {
                                         (void) fputs(line, new_fp);

@@ -1851,14 +1906,14 @@
 
         free(rpool_mntpnt);
         rpool_mntpnt = NULL;
 
         while (fgets(line, BUFSIZ, menu_fp)) {
-                char *tok = strtok_r(line, BE_WHITE_SPACE, &last);
+                char *tok = strtok_r(line, "=\n", &last);
 
                 if (tok != NULL && tok[0] != '#') {
-                        if (strcmp(tok, "bootfs") == 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,11 +1926,11 @@
                                          */
                                         *entry = ent_num - 1;
                                         ret = B_TRUE;
                                         goto cleanup;
                                 }
-                        } else if (strcmp(tok, "title") == 0)
+                        } else if (strcmp(tok, "entry_name") == 0)
                                 ent_num++;
                 }
         }
 
 cleanup:

@@ -3637,26 +3692,26 @@
                          * 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);
+                                    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) fprintf(temp_fp, "timeout=30\n");
                 (void) fclose(temp_fp);
 
         } else {
                 /*
                  * The menu file doesn't exist so we need to create a