--- /dev/null	2012-08-31 05:08:58.000000000 +0400
+++ new/grub/util/grub-solarislst2cfg.c	2012-08-31 05:08:58.176823035 +0400
@@ -0,0 +1,274 @@
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2012 Daniil Lunev
+ *
+ *  GRUB is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  GRUB is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <grub/types.h>
+#include <grub/emu/misc.h>
+#include <grub/emu/getroot.h>
+#include <grub/fs.h>
+#include <grub/device.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#define BUFFER_SIZE 512
+
+struct commands {
+  const char * lst;
+  const char * cfg;
+};
+
+void
+get_uuid_by_path(char * path, char ** uuid)
+{
+  char ** devices = NULL;
+  char * drive = NULL;
+  grub_device_t dev = NULL;
+  grub_fs_t fs = NULL;
+  char * grub_path = NULL;
+
+  grub_path = canonicalize_file_name(path);
+  if (! grub_path)
+    grub_util_error("Can't canonicalize path");
+  
+  devices = grub_guess_root_devices(grub_path);
+  if (! devices) 
+    grub_util_error("Can't find device");
+  
+  drive = grub_util_get_grub_dev(devices[0]);
+  if (! drive)
+    grub_util_error("Can't get drive");
+    
+  dev = grub_device_open(drive);
+  if (! dev) 
+    grub_util_error("Can't open device");
+
+  fs = grub_fs_probe(dev);
+  if (! fs) 
+    grub_util_error("Probing fs error");
+
+  if (! fs->uuid) 
+    grub_util_error("This fs doesn't support uuid");
+
+  if (fs->uuid(dev, uuid) != GRUB_ERR_NONE) 
+    grub_util_error("%s", grub_errmsg);
+
+  free(grub_path);
+  if (dev) 
+    grub_device_close(dev);
+
+  return;
+}
+
+struct commands com[] = {
+  {"title", "entry_name"},
+  {"findroot", "pool"},
+  {"bootfs", "data_set"},
+  {"kernel$", "kernel_path"},
+  {"module$", "module"},
+  {"default", "default_entry"},
+  {"timeout", "timeout"},
+  {"serial", "serial"},
+  {"terminal", "terminal"},
+  {0, 0},
+};
+
+int
+get_command_id(char * command)
+{
+  int i = 0;
+  for (; com[i].lst; ++i)
+    if (!strcmp(com[i].lst, command))
+      return i;
+  return -1;
+}
+
+char *
+retrive_value(char * val)
+{
+  char * str; 
+  int quote_flag = 0;;
+
+  while ((*val == ' ') || (*val == '\t'))
+    ++val;
+
+  if (*val == '"') {
+    ++val;
+    ++quote_flag;  
+  }
+  
+  str = val;
+  
+  for (;;) {
+    if (quote_flag) {
+      if (*val == '"') 
+        break;
+      if (*val == '\0')
+        return NULL;
+    } else {
+      if ((*val == ' ') || (*val == '\t') || (*val == '\0'))
+        break;
+    }
+    ++val;
+  }
+  *val = '\0';
+
+  return str;
+}
+
+int
+parse_menulst(FILE * in_file, FILE * out_file)
+{
+  char line[BUFFER_SIZE];
+  char * command;
+  char * value;
+  char * label = NULL;
+  char bootfs[BUFFER_SIZE];
+  char pool[BUFFER_SIZE];
+  char * uuid;
+  char * c;
+  int com_id;
+
+  for (;;) {
+    command = fgets(line, BUFFER_SIZE, in_file);
+    if (! command)
+      return 0;
+
+    c = command + strlen(command) - 1;
+    if ((*c != '\n') && (fgets(line, BUFFER_SIZE, in_file)))
+      return 1;
+
+    if ((*command == '#') || (*command == ' ') 
+       || (*command == '\t') || (*command == '\n'))
+      continue;
+
+    if (*c == '\n')
+      *c = '\0';
+    value = strchr(line, ' ');
+    if (! value)
+      continue;
+
+    *value++ = '\0';
+    
+    com_id = get_command_id(command);
+    if (com_id < 0)
+      continue;
+
+    switch (com_id) {
+    case 0:
+      fprintf(out_file,"\n%s=%s\n", com[com_id].cfg, value);
+      break;
+    case 1:
+      label = strdup(strchr(value, '_') + 1);
+      c = strchr(label, ',');
+      if (c)
+        *c = 0;
+      continue;
+    case 2:
+      c = strchr(value, '/');
+      if (c != NULL) {
+        strcpy(bootfs, c);
+        *c = '\0';
+        strcpy(pool + 1, value);
+        *pool = '/';
+        uuid = NULL;
+        get_uuid_by_path(pool, &uuid);
+        if (! uuid)
+          return 1;
+      
+        fprintf(out_file,"pool_uuid=%s\n", uuid);
+        
+      } 
+      *c = '/';
+      fprintf(out_file,"data_set=%s\n", value);
+      if (label) {
+        free(label);
+        label = NULL;
+      }
+      break;
+    case 3:
+    case 4:
+      if (label) {
+        fprintf(out_file,"pool_label=%s\n", label);
+        free(label);
+        label = NULL;
+      }
+      if (com_id == 3)
+        c = strchr (value, ' ');
+        if (c)
+          *c = '\0';
+      if (! value)
+        return 1;
+      
+      fprintf(out_file,"%s=%s\n", com[com_id].cfg, value);
+
+      if ((com_id == 3) && (c)) {
+        char * tmp;
+        value = c + 1;
+        tmp = strstr(value, "ZFS-BOOTFS");
+        if (tmp)
+          *(tmp + 3) = '_';
+        fprintf(out_file,"kernel_options=%s\n", value);
+      }
+
+      break;
+    default:
+      fprintf(out_file,"%s=%s\n", com[com_id].cfg, value);
+      break;
+    }
+  }
+  return 0;
+}
+
+int
+main(int argc, char ** argv)
+{
+  FILE * lst_file;
+  FILE * cfg_file;
+  int err = 0;
+
+  if (argc != 3) {
+    printf("grub-solarislst2cfg lst_file cfg_file\n");
+    return 1;
+  }
+
+  lst_file = fopen(argv[1], "r");
+  if (! lst_file)
+    return 1;
+
+  cfg_file = fopen(argv[2], "w");
+  if (! cfg_file) {
+    fclose(lst_file);
+    return 1;
+  }
+
+  grub_util_init_nls();
+  grub_util_biosdisk_init(DEFAULT_DEVICE_MAP);
+  grub_init_all();
+  
+  err = parse_menulst(lst_file, cfg_file);
+
+  grub_fini_all();
+
+  fclose(lst_file);
+  fclose(cfg_file);
+
+  if (err)
+    remove(argv[2]);
+  return err;
+}
