2009-05-08 Pavel Roskin <proski@gnu.org>
[grub2/bean.git] / fs / iso9660.c
blob140d8c2135aa38f312654c0478df7f868c170b78
1 /* iso9660.c - iso9660 implementation with extensions:
2 SUSP, Rock Ridge. */
3 /*
4 * GRUB -- GRand Unified Bootloader
5 * Copyright (C) 2004,2005,2006,2007,2008 Free Software Foundation, Inc.
7 * GRUB is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * GRUB is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
21 #include <grub/err.h>
22 #include <grub/file.h>
23 #include <grub/mm.h>
24 #include <grub/misc.h>
25 #include <grub/disk.h>
26 #include <grub/dl.h>
27 #include <grub/types.h>
28 #include <grub/fshelp.h>
30 #define GRUB_ISO9660_FSTYPE_DIR 0040000
31 #define GRUB_ISO9660_FSTYPE_REG 0100000
32 #define GRUB_ISO9660_FSTYPE_SYMLINK 0120000
33 #define GRUB_ISO9660_FSTYPE_MASK 0170000
35 #define GRUB_ISO9660_LOG2_BLKSZ 2
36 #define GRUB_ISO9660_BLKSZ 2048
38 #define GRUB_ISO9660_RR_DOT 2
39 #define GRUB_ISO9660_RR_DOTDOT 4
41 #define GRUB_ISO9660_VOLDESC_BOOT 0
42 #define GRUB_ISO9660_VOLDESC_PRIMARY 1
43 #define GRUB_ISO9660_VOLDESC_SUPP 2
44 #define GRUB_ISO9660_VOLDESC_PART 3
45 #define GRUB_ISO9660_VOLDESC_END 255
47 /* The head of a volume descriptor. */
48 struct grub_iso9660_voldesc
50 grub_uint8_t type;
51 grub_uint8_t magic[5];
52 grub_uint8_t version;
53 } __attribute__ ((packed));
55 /* A directory entry. */
56 struct grub_iso9660_dir
58 grub_uint8_t len;
59 grub_uint8_t ext_sectors;
60 grub_uint32_t first_sector;
61 grub_uint32_t first_sector_be;
62 grub_uint32_t size;
63 grub_uint32_t size_be;
64 grub_uint8_t unused1[7];
65 grub_uint8_t flags;
66 grub_uint8_t unused2[6];
67 grub_uint8_t namelen;
68 } __attribute__ ((packed));
70 struct grub_iso9660_date
72 grub_uint8_t year[4];
73 grub_uint8_t month[2];
74 grub_uint8_t day[2];
75 grub_uint8_t hour[2];
76 grub_uint8_t minute[2];
77 grub_uint8_t second[2];
78 grub_uint8_t hundredth[2];
79 grub_uint8_t offset;
80 } __attribute__ ((packed));
82 /* The primary volume descriptor. Only little endian is used. */
83 struct grub_iso9660_primary_voldesc
85 struct grub_iso9660_voldesc voldesc;
86 grub_uint8_t unused1[33];
87 grub_uint8_t volname[32];
88 grub_uint8_t unused2[16];
89 grub_uint8_t escape[32];
90 grub_uint8_t unused3[12];
91 grub_uint32_t path_table_size;
92 grub_uint8_t unused4[4];
93 grub_uint32_t path_table;
94 grub_uint8_t unused5[12];
95 struct grub_iso9660_dir rootdir;
96 grub_uint8_t unused6[624];
97 struct grub_iso9660_date created;
98 struct grub_iso9660_date modified;
99 } __attribute__ ((packed));
101 /* A single entry in the path table. */
102 struct grub_iso9660_path
104 grub_uint8_t len;
105 grub_uint8_t sectors;
106 grub_uint32_t first_sector;
107 grub_uint16_t parentdir;
108 grub_uint8_t name[0];
109 } __attribute__ ((packed));
111 /* An entry in the System Usage area of the directory entry. */
112 struct grub_iso9660_susp_entry
114 grub_uint8_t sig[2];
115 grub_uint8_t len;
116 grub_uint8_t version;
117 grub_uint8_t data[0];
118 } __attribute__ ((packed));
120 /* The CE entry. This is used to describe the next block where data
121 can be found. */
122 struct grub_iso9660_susp_ce
124 struct grub_iso9660_susp_entry entry;
125 grub_uint32_t blk;
126 grub_uint32_t blk_be;
127 grub_uint32_t off;
128 grub_uint32_t off_be;
129 grub_uint32_t len;
130 grub_uint32_t len_be;
131 } __attribute__ ((packed));
133 struct grub_iso9660_data
135 struct grub_iso9660_primary_voldesc voldesc;
136 grub_disk_t disk;
137 unsigned int first_sector;
138 unsigned int length;
139 int rockridge;
140 int susp_skip;
141 int joliet;
144 struct grub_fshelp_node
146 struct grub_iso9660_data *data;
147 unsigned int size;
148 unsigned int blk;
149 unsigned int dir_blk;
150 unsigned int dir_off;
153 static grub_dl_t my_mod;
156 /* Iterate over the susp entries, starting with block SUA_BLOCK on the
157 offset SUA_POS with a size of SUA_SIZE bytes. Hook is called for
158 every entry. */
159 static grub_err_t
160 grub_iso9660_susp_iterate (struct grub_iso9660_data *data,
161 int sua_block, int sua_pos, int sua_size,
162 grub_err_t (*hook)
163 (struct grub_iso9660_susp_entry *entry))
165 char *sua;
166 struct grub_iso9660_susp_entry *entry;
168 auto grub_err_t load_sua (void);
170 /* Load a part of the System Usage Area. */
171 grub_err_t load_sua (void)
173 sua = grub_malloc (sua_size);
174 if (!sua)
175 return grub_errno;
177 if (grub_disk_read (data->disk, sua_block, sua_pos,
178 sua_size, sua))
179 return grub_errno;
181 entry = (struct grub_iso9660_susp_entry *) sua;
182 return 0;
185 if (load_sua ())
186 return grub_errno;
188 for (; (char *) entry < (char *) sua + sua_size - 1;
189 entry = (struct grub_iso9660_susp_entry *)
190 ((char *) entry + entry->len))
192 /* The last entry. */
193 if (grub_strncmp ((char *) entry->sig, "ST", 2) == 0)
194 break;
196 /* Additional entries are stored elsewhere. */
197 if (grub_strncmp ((char *) entry->sig, "CE", 2) == 0)
199 struct grub_iso9660_susp_ce *ce;
201 ce = (struct grub_iso9660_susp_ce *) entry;
202 sua_size = grub_le_to_cpu32 (ce->len);
203 sua_pos = grub_le_to_cpu32 (ce->off);
204 sua_block = grub_le_to_cpu32 (ce->blk) << GRUB_ISO9660_LOG2_BLKSZ;
206 grub_free (sua);
207 if (load_sua ())
208 return grub_errno;
211 if (hook (entry))
213 grub_free (sua);
214 return 0;
218 grub_free (sua);
219 return 0;
222 static char *
223 grub_iso9660_convert_string (grub_uint16_t *us, int len)
225 char *p;
226 int i;
228 p = grub_malloc (len * 4 + 1);
229 if (! p)
230 return p;
232 for (i=0; i<len; i++)
233 us[i] = grub_be_to_cpu16 (us[i]);
235 *grub_utf16_to_utf8 ((grub_uint8_t *) p, us, len) = '\0';
237 return p;
240 static struct grub_iso9660_data *
241 grub_iso9660_mount (grub_disk_t disk)
243 struct grub_iso9660_data *data = 0;
244 struct grub_iso9660_dir rootdir;
245 int sua_pos;
246 int sua_size;
247 char *sua;
248 struct grub_iso9660_susp_entry *entry;
249 struct grub_iso9660_primary_voldesc voldesc;
250 int block;
252 auto grub_err_t susp_iterate (struct grub_iso9660_susp_entry *);
254 grub_err_t susp_iterate (struct grub_iso9660_susp_entry *susp_entry)
256 /* The "ER" entry is used to detect extensions. The
257 `IEEE_P1285' extension means Rock ridge. */
258 if (grub_strncmp ((char *) susp_entry->sig, "ER", 2) == 0)
260 data->rockridge = 1;
261 return 1;
263 return 0;
266 data = grub_malloc (sizeof (struct grub_iso9660_data));
267 if (! data)
268 return 0;
270 data->disk = disk;
271 data->rockridge = 0;
272 data->joliet = 0;
274 block = 16;
277 int copy_voldesc = 0;
279 /* Read the superblock. */
280 if (grub_disk_read (disk, block << GRUB_ISO9660_LOG2_BLKSZ, 0,
281 sizeof (struct grub_iso9660_primary_voldesc),
282 (char *) &voldesc))
284 grub_error (GRUB_ERR_BAD_FS, "not a iso9660 filesystem");
285 goto fail;
288 if (grub_strncmp ((char *) voldesc.voldesc.magic, "CD001", 5) != 0)
290 grub_error (GRUB_ERR_BAD_FS, "not a iso9660 filesystem");
291 goto fail;
294 if (voldesc.voldesc.type == GRUB_ISO9660_VOLDESC_PRIMARY)
295 copy_voldesc = 1;
296 else if ((voldesc.voldesc.type == GRUB_ISO9660_VOLDESC_SUPP) &&
297 (voldesc.escape[0] == 0x25) && (voldesc.escape[1] == 0x2f) &&
298 ((voldesc.escape[2] == 0x40) || /* UCS-2 Level 1. */
299 (voldesc.escape[2] == 0x43) || /* UCS-2 Level 2. */
300 (voldesc.escape[2] == 0x45))) /* UCS-2 Level 3. */
302 copy_voldesc = 1;
303 data->joliet = 1;
306 if (copy_voldesc)
307 grub_memcpy((char *) &data->voldesc, (char *) &voldesc,
308 sizeof (struct grub_iso9660_primary_voldesc));
310 block++;
311 } while (voldesc.voldesc.type != GRUB_ISO9660_VOLDESC_END);
313 /* Read the system use area and test it to see if SUSP is
314 supported. */
315 if (grub_disk_read (disk, (grub_le_to_cpu32 (data->voldesc.rootdir.first_sector)
316 << GRUB_ISO9660_LOG2_BLKSZ), 0,
317 sizeof (rootdir), (char *) &rootdir))
319 grub_error (GRUB_ERR_BAD_FS, "not a iso9660 filesystem");
320 goto fail;
323 sua_pos = (sizeof (rootdir) + rootdir.namelen
324 + (rootdir.namelen % 2) - 1);
325 sua_size = rootdir.len - sua_pos;
327 sua = grub_malloc (sua_size);
328 if (! sua)
329 goto fail;
331 if (grub_disk_read (disk, (grub_le_to_cpu32 (data->voldesc.rootdir.first_sector)
332 << GRUB_ISO9660_LOG2_BLKSZ), sua_pos,
333 sua_size, sua))
335 grub_error (GRUB_ERR_BAD_FS, "not a iso9660 filesystem");
336 goto fail;
339 entry = (struct grub_iso9660_susp_entry *) sua;
341 /* Test if the SUSP protocol is used on this filesystem. */
342 if (grub_strncmp ((char *) entry->sig, "SP", 2) == 0)
344 /* The 2nd data byte stored how many bytes are skipped every time
345 to get to the SUA (System Usage Area). */
346 data->susp_skip = entry->data[2];
347 entry = (struct grub_iso9660_susp_entry *) ((char *) entry + entry->len);
349 /* Iterate over the entries in the SUA area to detect
350 extensions. */
351 if (grub_iso9660_susp_iterate (data,
352 (grub_le_to_cpu32 (data->voldesc.rootdir.first_sector)
353 << GRUB_ISO9660_LOG2_BLKSZ),
354 sua_pos, sua_size, susp_iterate))
355 goto fail;
358 return data;
360 fail:
361 grub_free (data);
362 return 0;
366 static char *
367 grub_iso9660_read_symlink (grub_fshelp_node_t node)
369 struct grub_iso9660_dir dirent;
370 int sua_off;
371 int sua_size;
372 char *symlink = 0;
373 int addslash = 0;
375 auto void add_part (const char *part, int len);
376 auto grub_err_t susp_iterate_sl (struct grub_iso9660_susp_entry *);
378 /* Extend the symlink. */
379 void add_part (const char *part, int len)
381 int size = grub_strlen (symlink);
383 symlink = grub_realloc (symlink, size + len + 1);
384 if (! symlink)
385 return;
387 grub_strncat (symlink, part, len);
390 /* Read in a symlink. */
391 grub_err_t susp_iterate_sl (struct grub_iso9660_susp_entry *entry)
393 if (grub_strncmp ("SL", (char *) entry->sig, 2) == 0)
395 unsigned int pos = 1;
397 /* The symlink is not stored as a POSIX symlink, translate it. */
398 while (pos < grub_le_to_cpu32 (entry->len))
400 if (addslash)
402 add_part ("/", 1);
403 addslash = 0;
406 /* The current position is the `Component Flag'. */
407 switch (entry->data[pos] & 30)
409 case 0:
411 /* The data on pos + 2 is the actual data, pos + 1
412 is the length. Both are part of the `Component
413 Record'. */
414 add_part ((char *) &entry->data[pos + 2],
415 entry->data[pos + 1]);
416 if ((entry->data[pos] & 1))
417 addslash = 1;
419 break;
422 case 2:
423 add_part ("./", 2);
424 break;
426 case 4:
427 add_part ("../", 3);
428 break;
430 case 8:
431 add_part ("/", 1);
432 break;
434 /* In pos + 1 the length of the `Component Record' is
435 stored. */
436 pos += entry->data[pos + 1] + 2;
439 /* Check if `grub_realloc' failed. */
440 if (grub_errno)
441 return grub_errno;
444 return 0;
447 if (grub_disk_read (node->data->disk, node->dir_blk, node->dir_off,
448 sizeof (dirent), (char *) &dirent))
449 return 0;
451 sua_off = (sizeof (dirent) + dirent.namelen + 1 - (dirent.namelen % 2)
452 + node->data->susp_skip);
453 sua_size = dirent.len - sua_off;
455 symlink = grub_malloc (1);
456 if (!symlink)
457 return 0;
459 *symlink = '\0';
461 if (grub_iso9660_susp_iterate (node->data, node->dir_blk,
462 node->dir_off + sua_off,
463 sua_size, susp_iterate_sl))
465 grub_free (symlink);
466 return 0;
469 return symlink;
473 static int
474 grub_iso9660_iterate_dir (grub_fshelp_node_t dir,
475 int NESTED_FUNC_ATTR
476 (*hook) (const char *filename,
477 enum grub_fshelp_filetype filetype,
478 grub_fshelp_node_t node))
480 struct grub_iso9660_dir dirent;
481 unsigned int offset = 0;
482 char *filename;
483 int filename_alloc = 0;
484 enum grub_fshelp_filetype type;
486 auto grub_err_t susp_iterate_dir (struct grub_iso9660_susp_entry *);
488 grub_err_t susp_iterate_dir (struct grub_iso9660_susp_entry *entry)
490 /* The filename in the rock ridge entry. */
491 if (grub_strncmp ("NM", (char *) entry->sig, 2) == 0)
493 /* The flags are stored at the data position 0, here the
494 filename type is stored. */
495 if (entry->data[0] & GRUB_ISO9660_RR_DOT)
496 filename = ".";
497 else if (entry->data[0] & GRUB_ISO9660_RR_DOTDOT)
498 filename = "..";
499 else
501 int size = 1;
502 if (filename)
504 size += grub_strlen (filename);
505 grub_realloc (filename,
506 grub_strlen (filename)
507 + entry->len);
509 else
511 size = entry->len - 5;
512 filename = grub_malloc (size + 1);
513 filename[0] = '\0';
515 filename_alloc = 1;
516 grub_strncpy (filename, (char *) &entry->data[1], size);
517 filename[size] = '\0';
520 /* The mode information (st_mode). */
521 else if (grub_strncmp ((char *) entry->sig, "PX", 2) == 0)
523 /* At position 0 of the PX record the st_mode information is
524 stored. */
525 grub_uint32_t mode = ((*(grub_uint32_t *) &entry->data[0])
526 & GRUB_ISO9660_FSTYPE_MASK);
528 switch (mode)
530 case GRUB_ISO9660_FSTYPE_DIR:
531 type = GRUB_FSHELP_DIR;
532 break;
533 case GRUB_ISO9660_FSTYPE_REG:
534 type = GRUB_FSHELP_REG;
535 break;
536 case GRUB_ISO9660_FSTYPE_SYMLINK:
537 type = GRUB_FSHELP_SYMLINK;
538 break;
539 default:
540 type = GRUB_FSHELP_UNKNOWN;
544 return 0;
547 while (offset < dir->size)
549 if (grub_disk_read (dir->data->disk,
550 (dir->blk << GRUB_ISO9660_LOG2_BLKSZ)
551 + offset / GRUB_DISK_SECTOR_SIZE,
552 offset % GRUB_DISK_SECTOR_SIZE,
553 sizeof (dirent), (char *) &dirent))
554 return 0;
556 /* The end of the block, skip to the next one. */
557 if (!dirent.len)
559 offset = (offset / GRUB_ISO9660_BLKSZ + 1) * GRUB_ISO9660_BLKSZ;
560 continue;
564 char name[dirent.namelen + 1];
565 int nameoffset = offset + sizeof (dirent);
566 struct grub_fshelp_node *node;
567 int sua_off = (sizeof (dirent) + dirent.namelen + 1
568 - (dirent.namelen % 2));;
569 int sua_size = dirent.len - sua_off;
571 sua_off += offset + dir->data->susp_skip;
573 filename = 0;
574 filename_alloc = 0;
575 type = GRUB_FSHELP_UNKNOWN;
577 if (dir->data->rockridge
578 && grub_iso9660_susp_iterate (dir->data,
579 (dir->blk << GRUB_ISO9660_LOG2_BLKSZ)
580 + (sua_off
581 / GRUB_DISK_SECTOR_SIZE),
582 sua_off % GRUB_DISK_SECTOR_SIZE,
583 sua_size, susp_iterate_dir))
584 return 0;
586 /* Read the name. */
587 if (grub_disk_read (dir->data->disk,
588 (dir->blk << GRUB_ISO9660_LOG2_BLKSZ)
589 + nameoffset / GRUB_DISK_SECTOR_SIZE,
590 nameoffset % GRUB_DISK_SECTOR_SIZE,
591 dirent.namelen, (char *) name))
592 return 0;
594 node = grub_malloc (sizeof (struct grub_fshelp_node));
595 if (!node)
596 return 0;
598 /* Setup a new node. */
599 node->data = dir->data;
600 node->size = grub_le_to_cpu32 (dirent.size);
601 node->blk = grub_le_to_cpu32 (dirent.first_sector);
602 node->dir_blk = ((dir->blk << GRUB_ISO9660_LOG2_BLKSZ)
603 + offset / GRUB_DISK_SECTOR_SIZE);
604 node->dir_off = offset % GRUB_DISK_SECTOR_SIZE;
606 /* If the filetype was not stored using rockridge, use
607 whatever is stored in the iso9660 filesystem. */
608 if (type == GRUB_FSHELP_UNKNOWN)
610 if ((dirent.flags & 3) == 2)
611 type = GRUB_FSHELP_DIR;
612 else
613 type = GRUB_FSHELP_REG;
616 /* The filename was not stored in a rock ridge entry. Read it
617 from the iso9660 filesystem. */
618 if (!filename)
620 name[dirent.namelen] = '\0';
621 filename = grub_strrchr (name, ';');
622 if (filename)
623 *filename = '\0';
625 if (dirent.namelen == 1 && name[0] == 0)
626 filename = ".";
627 else if (dirent.namelen == 1 && name[0] == 1)
628 filename = "..";
629 else
630 filename = name;
633 if (dir->data->joliet)
635 char *oldname;
637 oldname = filename;
638 filename = grub_iso9660_convert_string
639 ((grub_uint16_t *) oldname, dirent.namelen >> 1);
641 if (filename_alloc)
642 grub_free (oldname);
644 filename_alloc = 1;
647 if (hook (filename, type, node))
649 if (filename_alloc)
650 grub_free (filename);
651 return 1;
653 if (filename_alloc)
654 grub_free (filename);
657 offset += dirent.len;
660 return 0;
665 static grub_err_t
666 grub_iso9660_dir (grub_device_t device, const char *path,
667 int (*hook) (const char *filename,
668 const struct grub_dirhook_info *info))
670 struct grub_iso9660_data *data = 0;
671 struct grub_fshelp_node rootnode;
672 struct grub_fshelp_node *foundnode;
674 auto int NESTED_FUNC_ATTR iterate (const char *filename,
675 enum grub_fshelp_filetype filetype,
676 grub_fshelp_node_t node);
678 int NESTED_FUNC_ATTR iterate (const char *filename,
679 enum grub_fshelp_filetype filetype,
680 grub_fshelp_node_t node)
682 struct grub_dirhook_info info;
683 grub_memset (&info, 0, sizeof (info));
684 info.dir = ((filetype & GRUB_FSHELP_TYPE_MASK) == GRUB_FSHELP_DIR);
685 grub_free (node);
686 return hook (filename, &info);
689 grub_dl_ref (my_mod);
691 data = grub_iso9660_mount (device->disk);
692 if (! data)
693 goto fail;
695 rootnode.data = data;
696 rootnode.blk = grub_le_to_cpu32 (data->voldesc.rootdir.first_sector);
697 rootnode.size = grub_le_to_cpu32 (data->voldesc.rootdir.size);
699 /* Use the fshelp function to traverse the path. */
700 if (grub_fshelp_find_file (path, &rootnode,
701 &foundnode,
702 grub_iso9660_iterate_dir,
703 grub_iso9660_read_symlink,
704 GRUB_FSHELP_DIR))
705 goto fail;
707 /* List the files in the directory. */
708 grub_iso9660_iterate_dir (foundnode, iterate);
710 if (foundnode != &rootnode)
711 grub_free (foundnode);
713 fail:
714 grub_free (data);
716 grub_dl_unref (my_mod);
718 return grub_errno;
722 /* Open a file named NAME and initialize FILE. */
723 static grub_err_t
724 grub_iso9660_open (struct grub_file *file, const char *name)
726 struct grub_iso9660_data *data;
727 struct grub_fshelp_node rootnode;
728 struct grub_fshelp_node *foundnode;
730 grub_dl_ref (my_mod);
732 data = grub_iso9660_mount (file->device->disk);
733 if (!data)
734 goto fail;
736 rootnode.data = data;
737 rootnode.blk = grub_le_to_cpu32 (data->voldesc.rootdir.first_sector);
738 rootnode.size = grub_le_to_cpu32 (data->voldesc.rootdir.size);
740 /* Use the fshelp function to traverse the path. */
741 if (grub_fshelp_find_file (name, &rootnode,
742 &foundnode,
743 grub_iso9660_iterate_dir,
744 grub_iso9660_read_symlink,
745 GRUB_FSHELP_REG))
746 goto fail;
748 data->first_sector = foundnode->blk;
749 data->length = foundnode->size;
751 file->data = data;
752 file->size = foundnode->size;
753 file->offset = 0;
755 return 0;
757 fail:
758 grub_dl_unref (my_mod);
760 grub_free (data);
762 return grub_errno;;
766 static grub_ssize_t
767 grub_iso9660_read (grub_file_t file, char *buf, grub_size_t len)
769 struct grub_iso9660_data *data =
770 (struct grub_iso9660_data *) file->data;
772 /* XXX: The file is stored in as a single extent. */
773 data->disk->read_hook = file->read_hook;
774 grub_disk_read (data->disk,
775 data->first_sector << GRUB_ISO9660_LOG2_BLKSZ,
776 file->offset,
777 len, buf);
778 data->disk->read_hook = 0;
780 return len;
784 static grub_err_t
785 grub_iso9660_close (grub_file_t file)
787 grub_free (file->data);
789 grub_dl_unref (my_mod);
791 return GRUB_ERR_NONE;
795 static grub_err_t
796 grub_iso9660_label (grub_device_t device, char **label)
798 struct grub_iso9660_data *data;
799 data = grub_iso9660_mount (device->disk);
801 if (data)
803 if (data->joliet)
804 *label = grub_iso9660_convert_string
805 ((grub_uint16_t *) &data->voldesc.volname, 16);
806 else
807 *label = grub_strndup ((char *) data->voldesc.volname, 32);
808 grub_free (data);
810 else
811 *label = 0;
813 return grub_errno;
817 static grub_err_t
818 grub_iso9660_uuid (grub_device_t device, char **uuid)
820 struct grub_iso9660_data *data;
821 grub_disk_t disk = device->disk;
823 grub_dl_ref (my_mod);
825 data = grub_iso9660_mount (disk);
826 if (data)
828 if (! data->voldesc.modified.year[0] && ! data->voldesc.modified.year[1]
829 && ! data->voldesc.modified.year[2] && ! data->voldesc.modified.year[3]
830 && ! data->voldesc.modified.month[0] && ! data->voldesc.modified.month[1]
831 && ! data->voldesc.modified.day[0] && ! data->voldesc.modified.day[1]
832 && ! data->voldesc.modified.hour[0] && ! data->voldesc.modified.hour[1]
833 && ! data->voldesc.modified.minute[0] && ! data->voldesc.modified.minute[1]
834 && ! data->voldesc.modified.second[0] && ! data->voldesc.modified.second[1]
835 && ! data->voldesc.modified.hundredth[0] && ! data->voldesc.modified.hundredth[1])
837 grub_error (GRUB_ERR_BAD_NUMBER, "No creation date in filesystem to generate UUID.");
838 *uuid = NULL;
840 else
842 *uuid = grub_malloc (sizeof ("YYYY-MM-DD-HH-mm-ss-hh"));
843 grub_sprintf (*uuid, "%c%c%c%c-%c%c-%c%c-%c%c-%c%c-%c%c-%c%c",
844 data->voldesc.modified.year[0], data->voldesc.modified.year[1],
845 data->voldesc.modified.year[2], data->voldesc.modified.year[3],
846 data->voldesc.modified.month[0], data->voldesc.modified.month[1],
847 data->voldesc.modified.day[0], data->voldesc.modified.day[1],
848 data->voldesc.modified.hour[0], data->voldesc.modified.hour[1],
849 data->voldesc.modified.minute[0], data->voldesc.modified.minute[1],
850 data->voldesc.modified.second[0], data->voldesc.modified.second[1],
851 data->voldesc.modified.hundredth[0], data->voldesc.modified.hundredth[1]);
854 else
855 *uuid = NULL;
857 grub_dl_unref (my_mod);
859 grub_free (data);
861 return grub_errno;
866 static struct grub_fs grub_iso9660_fs =
868 .name = "iso9660",
869 .dir = grub_iso9660_dir,
870 .open = grub_iso9660_open,
871 .read = grub_iso9660_read,
872 .close = grub_iso9660_close,
873 .label = grub_iso9660_label,
874 .uuid = grub_iso9660_uuid,
875 .next = 0
878 GRUB_MOD_INIT(iso9660)
880 grub_fs_register (&grub_iso9660_fs);
881 my_mod = mod;
884 GRUB_MOD_FINI(iso9660)
886 grub_fs_unregister (&grub_iso9660_fs);