Updated PCI IDs to latest snapshot.
[tangerine.git] / arch / common / boot / grub2 / disk / fs_uuid.c
blob27dffc2f6fb32a2779b571501d19b7b4bcd56594
1 /* fs_uuid.c - Access disks by their filesystem UUID. */
2 /*
3 * GRUB -- GRand Unified Bootloader
4 * Copyright (C) 2007,2008 Free Software Foundation, Inc.
6 * 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
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * GRUB is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
20 #include <grub/disk.h>
21 #include <grub/dl.h>
22 #include <grub/kernel.h>
23 #include <grub/misc.h>
24 #include <grub/mm.h>
25 #include <grub/types.h>
27 #include <grub/fs.h>
29 static grub_device_t
30 search_fs_uuid (const char *key, unsigned long *count)
32 *count = 0;
33 grub_device_t ret = NULL;
35 auto int iterate_device (const char *name);
36 int iterate_device (const char *name)
38 grub_device_t dev;
40 dev = grub_device_open (name);
41 if (dev)
43 grub_fs_t fs;
45 fs = grub_fs_probe (dev);
46 if (fs && fs->uuid)
48 char *uuid;
50 (fs->uuid) (dev, &uuid);
51 if (grub_errno == GRUB_ERR_NONE && uuid)
53 (*count)++;
55 if (grub_strcmp (uuid, key) == 0)
57 ret = dev;
58 grub_free (uuid);
59 return 1;
61 grub_free (uuid);
65 grub_device_close (dev);
68 grub_errno = GRUB_ERR_NONE;
69 return 0;
72 grub_device_iterate (iterate_device);
74 return ret;
77 static grub_err_t
78 grub_fs_uuid_open (const char *name, grub_disk_t disk)
80 grub_device_t dev;
82 if (grub_strncmp (name, "UUID=", sizeof ("UUID=")-1))
83 return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "not a UUID virtual volume");
85 dev = search_fs_uuid (name + sizeof ("UUID=") - 1, &disk->id);
86 if (! dev)
87 return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "no matching UUID found");
89 disk->total_sectors = dev->disk->total_sectors;
90 disk->has_partitions = 0;
91 disk->partition = dev->disk->partition;
92 disk->data = dev->disk;
94 return GRUB_ERR_NONE;
97 static void
98 grub_fs_uuid_close (grub_disk_t disk __attribute((unused)))
102 static grub_err_t
103 grub_fs_uuid_read (grub_disk_t disk, grub_disk_addr_t sector,
104 grub_size_t size, char *buf)
106 grub_disk_t parent = disk->data;
107 return parent->dev->read (parent, sector, size, buf);
110 static grub_err_t
111 grub_fs_uuid_write (grub_disk_t disk, grub_disk_addr_t sector,
112 grub_size_t size, const char *buf)
114 grub_disk_t parent = disk->data;
115 return parent->dev->write (parent, sector, size, buf);
118 static struct grub_disk_dev grub_fs_uuid_dev =
120 .name = "fs_uuid",
121 .id = GRUB_DISK_DEVICE_UUID_ID,
122 .open = grub_fs_uuid_open,
123 .close = grub_fs_uuid_close,
124 .read = grub_fs_uuid_read,
125 .write = grub_fs_uuid_write,
126 .next = 0
129 GRUB_MOD_INIT(fs_uuid)
131 grub_disk_dev_register (&grub_fs_uuid_dev);
134 GRUB_MOD_FINI(fs_uuid)
136 grub_disk_dev_unregister (&grub_fs_uuid_dev);