1 |
/* device.c - device manager */ |
/* device.c - device manager */ |
2 |
/* |
/* |
3 |
* GRUB -- GRand Unified Bootloader |
* GRUB -- GRand Unified Bootloader |
4 |
* Copyright (C) 2002 Free Software Foundation, Inc. |
* Copyright (C) 2002,2005 Free Software Foundation, Inc. |
5 |
* |
* |
6 |
* GRUB is free software; you can redistribute it and/or modify |
* GRUB is free software; you can redistribute it and/or modify |
7 |
* it under the terms of the GNU General Public License as published by |
* it under the terms of the GNU General Public License as published by |
24 |
#include <grub/fs.h> |
#include <grub/fs.h> |
25 |
#include <grub/mm.h> |
#include <grub/mm.h> |
26 |
#include <grub/misc.h> |
#include <grub/misc.h> |
27 |
|
#include <grub/env.h> |
|
static char *grub_device_root; |
|
|
|
|
|
grub_err_t |
|
|
grub_device_set_root (const char *name) |
|
|
{ |
|
|
grub_free (grub_device_root); |
|
|
grub_device_root = grub_strdup (name); |
|
|
return grub_errno; |
|
|
} |
|
|
|
|
|
const char * |
|
|
grub_device_get_root (void) |
|
|
{ |
|
|
if (! grub_device_root) |
|
|
grub_error (GRUB_ERR_BAD_DEVICE, "no root device"); |
|
|
|
|
|
return grub_device_root; |
|
|
} |
|
28 |
|
|
29 |
grub_device_t |
grub_device_t |
30 |
grub_device_open (const char *name) |
grub_device_open (const char *name) |
34 |
|
|
35 |
if (! name) |
if (! name) |
36 |
{ |
{ |
37 |
if (! grub_device_root) |
name = grub_env_get ("root"); |
38 |
|
if (*name == '\0') |
39 |
{ |
{ |
40 |
grub_error (GRUB_ERR_BAD_DEVICE, "no device is set"); |
grub_error (GRUB_ERR_BAD_DEVICE, "no device is set"); |
41 |
goto fail; |
goto fail; |
42 |
} |
} |
|
|
|
|
name = grub_device_root; |
|
43 |
} |
} |
44 |
|
|
45 |
dev = grub_malloc (sizeof (*dev)); |
dev = grub_malloc (sizeof (*dev)); |