plan9.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608
  1. /*
  2. * GRUB -- GRand Unified Bootloader
  3. * Copyright (C) 2010 Free Software Foundation, Inc.
  4. *
  5. * GRUB is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * GRUB is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include <grub/loader.h>
  19. #include <grub/file.h>
  20. #include <grub/err.h>
  21. #include <grub/device.h>
  22. #include <grub/disk.h>
  23. #include <grub/misc.h>
  24. #include <grub/types.h>
  25. #include <grub/partition.h>
  26. #include <grub/msdos_partition.h>
  27. #include <grub/scsi.h>
  28. #include <grub/dl.h>
  29. #include <grub/command.h>
  30. #include <grub/i18n.h>
  31. #include <grub/video.h>
  32. #include <grub/mm.h>
  33. #include <grub/cpu/relocator.h>
  34. #include <grub/extcmd.h>
  35. #include <grub/verify.h>
  36. GRUB_MOD_LICENSE ("GPLv3+");
  37. static grub_dl_t my_mod;
  38. static struct grub_relocator *rel;
  39. static grub_uint32_t eip = 0xffffffff;
  40. #define GRUB_PLAN9_TARGET 0x100000
  41. #define GRUB_PLAN9_ALIGN 4096
  42. #define GRUB_PLAN9_CONFIG_ADDR 0x001200
  43. #define GRUB_PLAN9_CONFIG_PATH_SIZE 0x000040
  44. #define GRUB_PLAN9_CONFIG_MAGIC "ZORT 0\r\n"
  45. static const struct grub_arg_option options[] =
  46. {
  47. {"map", 'm', GRUB_ARG_OPTION_REPEATABLE,
  48. /* TRANSLATORS: it's about guessing which GRUB disk
  49. is which Plan9 disk. If your language has no
  50. word "mapping" you can use another word which
  51. means that the GRUBDEVICE and PLAN9DEVICE are
  52. actually the same device, just named differently
  53. in OS and GRUB. */
  54. N_("Override guessed mapping of Plan9 devices."),
  55. N_("GRUBDEVICE=PLAN9DEVICE"),
  56. ARG_TYPE_STRING},
  57. {0, 0, 0, 0, 0, 0}
  58. };
  59. struct grub_plan9_header
  60. {
  61. grub_uint32_t magic;
  62. #define GRUB_PLAN9_MAGIC 0x1eb
  63. grub_uint32_t text_size;
  64. grub_uint32_t data_size;
  65. grub_uint32_t bss_size;
  66. grub_uint32_t sectiona;
  67. grub_uint32_t entry_addr;
  68. grub_uint32_t zero;
  69. grub_uint32_t sectionb;
  70. };
  71. static grub_err_t
  72. grub_plan9_boot (void)
  73. {
  74. struct grub_relocator32_state state = {
  75. .eax = 0,
  76. .eip = eip,
  77. .ebx = 0,
  78. .ecx = 0,
  79. .edx = 0,
  80. .edi = 0,
  81. .esp = 0,
  82. .ebp = 0,
  83. .esi = 0
  84. };
  85. grub_video_set_mode ("text", 0, 0);
  86. return grub_relocator32_boot (rel, state, 0);
  87. }
  88. static grub_err_t
  89. grub_plan9_unload (void)
  90. {
  91. grub_relocator_unload (rel);
  92. rel = NULL;
  93. grub_dl_unref (my_mod);
  94. return GRUB_ERR_NONE;
  95. }
  96. /* Context for grub_cmd_plan9. */
  97. struct grub_cmd_plan9_ctx
  98. {
  99. grub_extcmd_context_t ctxt;
  100. grub_file_t file;
  101. char *pmap;
  102. grub_size_t pmapalloc;
  103. grub_size_t pmapptr;
  104. int noslash;
  105. int prefixescnt[5];
  106. char *bootdisk, *bootpart;
  107. };
  108. static const char prefixes[5][10] = {
  109. "dos", "plan9", "ntfs", "linux", "linuxswap"
  110. };
  111. #include <grub/err.h>
  112. static inline grub_err_t
  113. grub_extend_alloc (grub_size_t sz, grub_size_t *allocated, char **ptr)
  114. {
  115. void *n;
  116. if (sz < *allocated)
  117. return GRUB_ERR_NONE;
  118. *allocated = 2 * sz;
  119. n = grub_realloc (*ptr, *allocated);
  120. if (!n)
  121. return grub_errno;
  122. *ptr = n;
  123. return GRUB_ERR_NONE;
  124. }
  125. /* Helper for grub_cmd_plan9. */
  126. static int
  127. fill_partition (grub_disk_t disk, const grub_partition_t partition, void *data)
  128. {
  129. struct grub_cmd_plan9_ctx *fill_ctx = data;
  130. int file_disk = 0;
  131. int pstart, pend;
  132. if (!fill_ctx->noslash)
  133. {
  134. if (grub_extend_alloc (fill_ctx->pmapptr + 1, &fill_ctx->pmapalloc,
  135. &fill_ctx->pmap))
  136. return 1;
  137. fill_ctx->pmap[fill_ctx->pmapptr++] = '/';
  138. }
  139. fill_ctx->noslash = 0;
  140. file_disk = fill_ctx->file->device->disk
  141. && disk->id == fill_ctx->file->device->disk->id
  142. && disk->dev->id == fill_ctx->file->device->disk->dev->id;
  143. pstart = fill_ctx->pmapptr;
  144. if (grub_strcmp (partition->partmap->name, "plan") == 0)
  145. {
  146. unsigned ptr = partition->index + sizeof ("part ") - 1;
  147. grub_err_t err;
  148. disk->partition = partition->parent;
  149. do
  150. {
  151. if (grub_extend_alloc (fill_ctx->pmapptr + 1, &fill_ctx->pmapalloc,
  152. &fill_ctx->pmap))
  153. return 1;
  154. err = grub_disk_read (disk, 1, ptr, 1,
  155. fill_ctx->pmap + fill_ctx->pmapptr);
  156. if (err)
  157. {
  158. disk->partition = 0;
  159. return err;
  160. }
  161. ptr++;
  162. fill_ctx->pmapptr++;
  163. }
  164. while (grub_isalpha (fill_ctx->pmap[fill_ctx->pmapptr - 1])
  165. || grub_isdigit (fill_ctx->pmap[fill_ctx->pmapptr - 1]));
  166. fill_ctx->pmapptr--;
  167. }
  168. else
  169. {
  170. char name[50];
  171. int c = 0;
  172. if (grub_strcmp (partition->partmap->name, "msdos") == 0)
  173. {
  174. switch (partition->msdostype)
  175. {
  176. case GRUB_PC_PARTITION_TYPE_PLAN9:
  177. c = 1;
  178. break;
  179. case GRUB_PC_PARTITION_TYPE_NTFS:
  180. c = 2;
  181. break;
  182. case GRUB_PC_PARTITION_TYPE_MINIX:
  183. case GRUB_PC_PARTITION_TYPE_LINUX_MINIX:
  184. case GRUB_PC_PARTITION_TYPE_EXT2FS:
  185. c = 3;
  186. break;
  187. case GRUB_PC_PARTITION_TYPE_LINUX_SWAP:
  188. c = 4;
  189. break;
  190. }
  191. }
  192. if (fill_ctx->prefixescnt[c] == 0)
  193. grub_strcpy (name, prefixes[c]);
  194. else
  195. grub_snprintf (name, sizeof (name), "%s.%d", prefixes[c],
  196. fill_ctx->prefixescnt[c]);
  197. fill_ctx->prefixescnt[c]++;
  198. if (grub_extend_alloc (fill_ctx->pmapptr + grub_strlen (name) + 1,
  199. &fill_ctx->pmapalloc, &fill_ctx->pmap))
  200. return 1;
  201. grub_strcpy (fill_ctx->pmap + fill_ctx->pmapptr, name);
  202. fill_ctx->pmapptr += grub_strlen (name);
  203. }
  204. pend = fill_ctx->pmapptr;
  205. if (grub_extend_alloc (fill_ctx->pmapptr + 2 + 25 + 5 + 25,
  206. &fill_ctx->pmapalloc, &fill_ctx->pmap))
  207. return 1;
  208. fill_ctx->pmap[fill_ctx->pmapptr++] = ' ';
  209. grub_snprintf (fill_ctx->pmap + fill_ctx->pmapptr, 25 + 5 + 25,
  210. "%" PRIuGRUB_UINT64_T " %" PRIuGRUB_UINT64_T,
  211. grub_partition_get_start (partition),
  212. grub_partition_get_start (partition)
  213. + grub_partition_get_len (partition));
  214. if (file_disk && grub_partition_get_start (partition)
  215. == grub_partition_get_start (fill_ctx->file->device->disk->partition)
  216. && grub_partition_get_len (partition)
  217. == grub_partition_get_len (fill_ctx->file->device->disk->partition))
  218. {
  219. grub_free (fill_ctx->bootpart);
  220. fill_ctx->bootpart = grub_strndup (fill_ctx->pmap + pstart,
  221. pend - pstart);
  222. }
  223. fill_ctx->pmapptr += grub_strlen (fill_ctx->pmap + fill_ctx->pmapptr);
  224. return 0;
  225. }
  226. /* Helper for grub_cmd_plan9. */
  227. static int
  228. fill_disk (const char *name, void *data)
  229. {
  230. struct grub_cmd_plan9_ctx *fill_ctx = data;
  231. grub_device_t dev;
  232. char *plan9name = NULL;
  233. unsigned i;
  234. int file_disk = 0;
  235. dev = grub_device_open (name);
  236. if (!dev)
  237. {
  238. grub_print_error ();
  239. return 0;
  240. }
  241. if (!dev->disk)
  242. {
  243. grub_device_close (dev);
  244. return 0;
  245. }
  246. file_disk = fill_ctx->file->device->disk
  247. && dev->disk->id == fill_ctx->file->device->disk->id
  248. && dev->disk->dev->id == fill_ctx->file->device->disk->dev->id;
  249. for (i = 0;
  250. fill_ctx->ctxt->state[0].args && fill_ctx->ctxt->state[0].args[i]; i++)
  251. if (grub_strncmp (name, fill_ctx->ctxt->state[0].args[i],
  252. grub_strlen (name)) == 0
  253. && fill_ctx->ctxt->state[0].args[i][grub_strlen (name)] == '=')
  254. break;
  255. if (fill_ctx->ctxt->state[0].args && fill_ctx->ctxt->state[0].args[i])
  256. plan9name = grub_strdup (fill_ctx->ctxt->state[0].args[i]
  257. + grub_strlen (name) + 1);
  258. else
  259. switch (dev->disk->dev->id)
  260. {
  261. case GRUB_DISK_DEVICE_BIOSDISK_ID:
  262. if (dev->disk->id & 0x80)
  263. plan9name = grub_xasprintf ("sdB%u",
  264. (unsigned) (dev->disk->id & 0x7f));
  265. else
  266. plan9name = grub_xasprintf ("fd%u",
  267. (unsigned) (dev->disk->id & 0x7f));
  268. break;
  269. /* Shouldn't happen as Plan9 doesn't work on these platforms. */
  270. case GRUB_DISK_DEVICE_OFDISK_ID:
  271. case GRUB_DISK_DEVICE_EFIDISK_ID:
  272. /* Plan9 doesn't see those. */
  273. default:
  274. /* Not sure how to handle those. */
  275. case GRUB_DISK_DEVICE_NAND_ID:
  276. if (!file_disk)
  277. {
  278. grub_device_close (dev);
  279. return 0;
  280. }
  281. /* if it's the disk the kernel is loaded from we need to name
  282. it nevertheless. */
  283. plan9name = grub_strdup ("sdZ0");
  284. break;
  285. case GRUB_DISK_DEVICE_ATA_ID:
  286. {
  287. unsigned unit;
  288. if (grub_strlen (dev->disk->name) < sizeof ("ata0") - 1)
  289. unit = 0;
  290. else
  291. unit = grub_strtoul (dev->disk->name + sizeof ("ata0") - 1, 0, 0);
  292. plan9name = grub_xasprintf ("sd%c%d", 'C' + unit / 2, unit % 2);
  293. }
  294. break;
  295. case GRUB_DISK_DEVICE_SCSI_ID:
  296. if (((dev->disk->id >> GRUB_SCSI_ID_SUBSYSTEM_SHIFT) & 0xff)
  297. == GRUB_SCSI_SUBSYSTEM_PATA)
  298. {
  299. unsigned unit;
  300. if (grub_strlen (dev->disk->name) < sizeof ("ata0") - 1)
  301. unit = 0;
  302. else
  303. unit = grub_strtoul (dev->disk->name + sizeof ("ata0") - 1,
  304. 0, 0);
  305. plan9name = grub_xasprintf ("sd%c%d", 'C' + unit / 2, unit % 2);
  306. break;
  307. }
  308. /* FIXME: how does Plan9 number controllers?
  309. We probably need save the SCSI devices and sort them */
  310. plan9name
  311. = grub_xasprintf ("sd0%u", (unsigned)
  312. ((dev->disk->id >> GRUB_SCSI_ID_BUS_SHIFT)
  313. & 0xf));
  314. break;
  315. }
  316. if (!plan9name)
  317. {
  318. grub_print_error ();
  319. grub_device_close (dev);
  320. return 0;
  321. }
  322. if (grub_extend_alloc (fill_ctx->pmapptr + grub_strlen (plan9name)
  323. + sizeof ("part="), &fill_ctx->pmapalloc,
  324. &fill_ctx->pmap))
  325. {
  326. grub_free (plan9name);
  327. grub_device_close (dev);
  328. return 1;
  329. }
  330. grub_strcpy (fill_ctx->pmap + fill_ctx->pmapptr, plan9name);
  331. fill_ctx->pmapptr += grub_strlen (plan9name);
  332. if (!file_disk)
  333. grub_free (plan9name);
  334. else
  335. {
  336. grub_free (fill_ctx->bootdisk);
  337. fill_ctx->bootdisk = plan9name;
  338. }
  339. grub_strcpy (fill_ctx->pmap + fill_ctx->pmapptr, "part=");
  340. fill_ctx->pmapptr += sizeof ("part=") - 1;
  341. fill_ctx->noslash = 1;
  342. grub_memset (fill_ctx->prefixescnt, 0, sizeof (fill_ctx->prefixescnt));
  343. if (grub_partition_iterate (dev->disk, fill_partition, fill_ctx))
  344. {
  345. grub_device_close (dev);
  346. return 1;
  347. }
  348. if (grub_extend_alloc (fill_ctx->pmapptr + 1, &fill_ctx->pmapalloc,
  349. &fill_ctx->pmap))
  350. {
  351. grub_device_close (dev);
  352. return 1;
  353. }
  354. fill_ctx->pmap[fill_ctx->pmapptr++] = '\n';
  355. grub_device_close (dev);
  356. return 0;
  357. }
  358. static grub_err_t
  359. grub_cmd_plan9 (grub_extcmd_context_t ctxt, int argc, char *argv[])
  360. {
  361. struct grub_cmd_plan9_ctx fill_ctx = {
  362. .ctxt = ctxt,
  363. .file = 0,
  364. .pmap = NULL,
  365. .pmapalloc = 256,
  366. .pmapptr = 0,
  367. .noslash = 1,
  368. .bootdisk = NULL,
  369. .bootpart = NULL
  370. };
  371. void *mem;
  372. grub_size_t memsize, padsize;
  373. struct grub_plan9_header hdr;
  374. char *config, *configptr;
  375. grub_size_t configsize;
  376. char *bootpath = NULL;
  377. if (argc == 0)
  378. return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
  379. grub_dl_ref (my_mod);
  380. rel = grub_relocator_new ();
  381. if (!rel)
  382. goto fail;
  383. fill_ctx.file = grub_file_open (argv[0], GRUB_FILE_TYPE_PLAN9_KERNEL);
  384. if (! fill_ctx.file)
  385. goto fail;
  386. fill_ctx.pmap = grub_malloc (fill_ctx.pmapalloc);
  387. if (!fill_ctx.pmap)
  388. goto fail;
  389. if (grub_disk_dev_iterate (fill_disk, &fill_ctx))
  390. goto fail;
  391. if (grub_extend_alloc (fill_ctx.pmapptr + 1, &fill_ctx.pmapalloc,
  392. &fill_ctx.pmap))
  393. goto fail;
  394. fill_ctx.pmap[fill_ctx.pmapptr] = 0;
  395. {
  396. char *file_name = grub_strchr (argv[0], ')');
  397. if (file_name)
  398. file_name++;
  399. else
  400. file_name = argv[0];
  401. if (*file_name)
  402. file_name++;
  403. if (fill_ctx.bootpart)
  404. bootpath = grub_xasprintf ("%s!%s!%s", fill_ctx.bootdisk,
  405. fill_ctx.bootpart, file_name);
  406. else
  407. bootpath = grub_xasprintf ("%s!%s", fill_ctx.bootdisk, file_name);
  408. grub_free (fill_ctx.bootdisk);
  409. grub_free (fill_ctx.bootpart);
  410. }
  411. if (!bootpath)
  412. goto fail;
  413. if (grub_file_read (fill_ctx.file, &hdr,
  414. sizeof (hdr)) != (grub_ssize_t) sizeof (hdr))
  415. {
  416. if (!grub_errno)
  417. grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"),
  418. argv[0]);
  419. goto fail;
  420. }
  421. if (grub_be_to_cpu32 (hdr.magic) != GRUB_PLAN9_MAGIC
  422. || hdr.zero)
  423. {
  424. grub_error (GRUB_ERR_BAD_OS, "unsupported Plan9");
  425. goto fail;
  426. }
  427. memsize = ALIGN_UP (grub_be_to_cpu32 (hdr.text_size) + sizeof (hdr),
  428. GRUB_PLAN9_ALIGN);
  429. memsize += ALIGN_UP (grub_be_to_cpu32 (hdr.data_size), GRUB_PLAN9_ALIGN);
  430. memsize += ALIGN_UP(grub_be_to_cpu32 (hdr.bss_size), GRUB_PLAN9_ALIGN);
  431. eip = grub_be_to_cpu32 (hdr.entry_addr) & 0xfffffff;
  432. /* path */
  433. configsize = GRUB_PLAN9_CONFIG_PATH_SIZE;
  434. /* magic */
  435. configsize += sizeof (GRUB_PLAN9_CONFIG_MAGIC) - 1;
  436. {
  437. int i;
  438. for (i = 1; i < argc; i++)
  439. configsize += grub_strlen (argv[i]) + 1;
  440. }
  441. configsize += (sizeof ("bootfile=") - 1) + grub_strlen (bootpath) + 1;
  442. configsize += fill_ctx.pmapptr;
  443. /* Terminating \0. */
  444. configsize++;
  445. {
  446. grub_relocator_chunk_t ch;
  447. grub_err_t err;
  448. err = grub_relocator_alloc_chunk_addr (rel, &ch, GRUB_PLAN9_CONFIG_ADDR,
  449. configsize);
  450. if (err)
  451. goto fail;
  452. config = get_virtual_current_address (ch);
  453. }
  454. grub_memset (config, 0, GRUB_PLAN9_CONFIG_PATH_SIZE);
  455. grub_strncpy (config, bootpath, GRUB_PLAN9_CONFIG_PATH_SIZE - 1);
  456. configptr = config + GRUB_PLAN9_CONFIG_PATH_SIZE;
  457. grub_memcpy (configptr, GRUB_PLAN9_CONFIG_MAGIC,
  458. sizeof (GRUB_PLAN9_CONFIG_MAGIC) - 1);
  459. configptr += sizeof (GRUB_PLAN9_CONFIG_MAGIC) - 1;
  460. configptr = grub_stpcpy (configptr, "bootfile=");
  461. configptr = grub_stpcpy (configptr, bootpath);
  462. *configptr++ = '\n';
  463. char *cmdline = configptr;
  464. {
  465. int i;
  466. for (i = 1; i < argc; i++)
  467. {
  468. configptr = grub_stpcpy (configptr, argv[i]);
  469. *configptr++ = '\n';
  470. }
  471. }
  472. {
  473. grub_err_t err;
  474. *configptr = '\0';
  475. err = grub_verify_string (cmdline, GRUB_VERIFY_KERNEL_CMDLINE);
  476. if (err)
  477. goto fail;
  478. }
  479. configptr = grub_stpcpy (configptr, fill_ctx.pmap);
  480. {
  481. grub_relocator_chunk_t ch;
  482. grub_err_t err;
  483. err = grub_relocator_alloc_chunk_addr (rel, &ch, GRUB_PLAN9_TARGET,
  484. memsize);
  485. if (err)
  486. goto fail;
  487. mem = get_virtual_current_address (ch);
  488. }
  489. {
  490. grub_uint8_t *ptr;
  491. ptr = mem;
  492. grub_memcpy (ptr, &hdr, sizeof (hdr));
  493. ptr += sizeof (hdr);
  494. if (grub_file_read (fill_ctx.file, ptr, grub_be_to_cpu32 (hdr.text_size))
  495. != (grub_ssize_t) grub_be_to_cpu32 (hdr.text_size))
  496. {
  497. if (!grub_errno)
  498. grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"),
  499. argv[0]);
  500. goto fail;
  501. }
  502. ptr += grub_be_to_cpu32 (hdr.text_size);
  503. padsize = ALIGN_UP (grub_be_to_cpu32 (hdr.text_size) + sizeof (hdr),
  504. GRUB_PLAN9_ALIGN) - grub_be_to_cpu32 (hdr.text_size)
  505. - sizeof (hdr);
  506. grub_memset (ptr, 0, padsize);
  507. ptr += padsize;
  508. if (grub_file_read (fill_ctx.file, ptr, grub_be_to_cpu32 (hdr.data_size))
  509. != (grub_ssize_t) grub_be_to_cpu32 (hdr.data_size))
  510. {
  511. if (!grub_errno)
  512. grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"),
  513. argv[0]);
  514. goto fail;
  515. }
  516. ptr += grub_be_to_cpu32 (hdr.data_size);
  517. padsize = ALIGN_UP (grub_be_to_cpu32 (hdr.data_size), GRUB_PLAN9_ALIGN)
  518. - grub_be_to_cpu32 (hdr.data_size);
  519. grub_memset (ptr, 0, padsize);
  520. ptr += padsize;
  521. grub_memset (ptr, 0, ALIGN_UP(grub_be_to_cpu32 (hdr.bss_size),
  522. GRUB_PLAN9_ALIGN));
  523. }
  524. grub_loader_set (grub_plan9_boot, grub_plan9_unload, 1);
  525. return GRUB_ERR_NONE;
  526. fail:
  527. grub_free (fill_ctx.pmap);
  528. if (fill_ctx.file)
  529. grub_file_close (fill_ctx.file);
  530. grub_plan9_unload ();
  531. return grub_errno;
  532. }
  533. static grub_extcmd_t cmd;
  534. GRUB_MOD_INIT(plan9)
  535. {
  536. cmd = grub_register_extcmd ("plan9", grub_cmd_plan9,
  537. GRUB_COMMAND_OPTIONS_AT_START,
  538. N_("KERNEL ARGS"), N_("Load Plan9 kernel."),
  539. options);
  540. my_mod = mod;
  541. }
  542. GRUB_MOD_FINI(plan9)
  543. {
  544. grub_unregister_extcmd (cmd);
  545. }