1 /* iso9660.c - iso9660 implementation with extensions:
4 * GRUB -- GRand Unified Bootloader
5 * Copyright (C) 2004,2005,2006,2007,2008,2009,2010 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/>.
22 #include <grub/file.h>
24 #include <grub/misc.h>
25 #include <grub/disk.h>
27 #include <grub/types.h>
28 #include <grub/fshelp.h>
29 #include <grub/charset.h>
30 #include <grub/datetime.h>
32 GRUB_MOD_LICENSE ("GPLv3+");
34 #define GRUB_ISO9660_FSTYPE_DIR 0040000
35 #define GRUB_ISO9660_FSTYPE_REG 0100000
36 #define GRUB_ISO9660_FSTYPE_SYMLINK 0120000
37 #define GRUB_ISO9660_FSTYPE_MASK 0170000
39 #define GRUB_ISO9660_LOG2_BLKSZ 2
40 #define GRUB_ISO9660_BLKSZ 2048
42 #define GRUB_ISO9660_RR_DOT 2
43 #define GRUB_ISO9660_RR_DOTDOT 4
45 #define GRUB_ISO9660_VOLDESC_BOOT 0
46 #define GRUB_ISO9660_VOLDESC_PRIMARY 1
47 #define GRUB_ISO9660_VOLDESC_SUPP 2
48 #define GRUB_ISO9660_VOLDESC_PART 3
49 #define GRUB_ISO9660_VOLDESC_END 255
51 /* The head of a volume descriptor. */
52 struct grub_iso9660_voldesc
55 grub_uint8_t magic
[5];
57 } __attribute__ ((packed
));
59 struct grub_iso9660_date2
68 } __attribute__ ((packed
));
70 /* A directory entry. */
71 struct grub_iso9660_dir
74 grub_uint8_t ext_sectors
;
75 grub_uint32_t first_sector
;
76 grub_uint32_t first_sector_be
;
78 grub_uint32_t size_be
;
79 struct grub_iso9660_date2 mtime
;
81 grub_uint8_t unused2
[6];
83 } __attribute__ ((packed
));
85 struct grub_iso9660_date
88 grub_uint8_t month
[2];
91 grub_uint8_t minute
[2];
92 grub_uint8_t second
[2];
93 grub_uint8_t hundredth
[2];
95 } __attribute__ ((packed
));
97 /* The primary volume descriptor. Only little endian is used. */
98 struct grub_iso9660_primary_voldesc
100 struct grub_iso9660_voldesc voldesc
;
101 grub_uint8_t unused1
[33];
102 grub_uint8_t volname
[32];
103 grub_uint8_t unused2
[16];
104 grub_uint8_t escape
[32];
105 grub_uint8_t unused3
[12];
106 grub_uint32_t path_table_size
;
107 grub_uint8_t unused4
[4];
108 grub_uint32_t path_table
;
109 grub_uint8_t unused5
[12];
110 struct grub_iso9660_dir rootdir
;
111 grub_uint8_t unused6
[624];
112 struct grub_iso9660_date created
;
113 struct grub_iso9660_date modified
;
114 } __attribute__ ((packed
));
116 /* A single entry in the path table. */
117 struct grub_iso9660_path
120 grub_uint8_t sectors
;
121 grub_uint32_t first_sector
;
122 grub_uint16_t parentdir
;
123 grub_uint8_t name
[0];
124 } __attribute__ ((packed
));
126 /* An entry in the System Usage area of the directory entry. */
127 struct grub_iso9660_susp_entry
131 grub_uint8_t version
;
132 grub_uint8_t data
[0];
133 } __attribute__ ((packed
));
135 /* The CE entry. This is used to describe the next block where data
137 struct grub_iso9660_susp_ce
139 struct grub_iso9660_susp_entry entry
;
141 grub_uint32_t blk_be
;
143 grub_uint32_t off_be
;
145 grub_uint32_t len_be
;
146 } __attribute__ ((packed
));
148 struct grub_iso9660_data
150 struct grub_iso9660_primary_voldesc voldesc
;
155 struct grub_fshelp_node
*node
;
158 struct grub_fshelp_node
160 struct grub_iso9660_data
*data
;
161 grub_size_t have_dirents
, alloc_dirents
;
163 struct grub_iso9660_dir dirents
[8];
172 FLAG_MORE_EXTENTS
= 0x80
175 static grub_dl_t my_mod
;
179 iso9660_to_unixtime (const struct grub_iso9660_date
*i
, grub_int32_t
*nix
)
181 struct grub_datetime datetime
;
183 if (! i
->year
[0] && ! i
->year
[1]
184 && ! i
->year
[2] && ! i
->year
[3]
185 && ! i
->month
[0] && ! i
->month
[1]
186 && ! i
->day
[0] && ! i
->day
[1]
187 && ! i
->hour
[0] && ! i
->hour
[1]
188 && ! i
->minute
[0] && ! i
->minute
[1]
189 && ! i
->second
[0] && ! i
->second
[1]
190 && ! i
->hundredth
[0] && ! i
->hundredth
[1])
191 return grub_error (GRUB_ERR_BAD_NUMBER
, "empty date");
192 datetime
.year
= (i
->year
[0] - '0') * 1000 + (i
->year
[1] - '0') * 100
193 + (i
->year
[2] - '0') * 10 + (i
->year
[3] - '0');
194 datetime
.month
= (i
->month
[0] - '0') * 10 + (i
->month
[1] - '0');
195 datetime
.day
= (i
->day
[0] - '0') * 10 + (i
->day
[1] - '0');
196 datetime
.hour
= (i
->hour
[0] - '0') * 10 + (i
->hour
[1] - '0');
197 datetime
.minute
= (i
->minute
[0] - '0') * 10 + (i
->minute
[1] - '0');
198 datetime
.second
= (i
->second
[0] - '0') * 10 + (i
->second
[1] - '0');
200 if (!grub_datetime2unixtime (&datetime
, nix
))
201 return grub_error (GRUB_ERR_BAD_NUMBER
, "incorrect date");
202 *nix
-= i
->offset
* 60 * 15;
203 return GRUB_ERR_NONE
;
207 iso9660_to_unixtime2 (const struct grub_iso9660_date2
*i
, grub_int32_t
*nix
)
209 struct grub_datetime datetime
;
211 datetime
.year
= i
->year
+ 1900;
212 datetime
.month
= i
->month
;
213 datetime
.day
= i
->day
;
214 datetime
.hour
= i
->hour
;
215 datetime
.minute
= i
->minute
;
216 datetime
.second
= i
->second
;
218 if (!grub_datetime2unixtime (&datetime
, nix
))
220 *nix
-= i
->offset
* 60 * 15;
225 read_node (grub_fshelp_node_t node
, grub_off_t off
, grub_size_t len
, char *buf
)
233 while (i
< node
->have_dirents
234 && off
>= grub_le_to_cpu32 (node
->dirents
[i
].size
))
236 off
-= grub_le_to_cpu32 (node
->dirents
[i
].size
);
239 if (i
== node
->have_dirents
)
240 return grub_error (GRUB_ERR_OUT_OF_RANGE
, "read out of range");
241 toread
= grub_le_to_cpu32 (node
->dirents
[i
].size
);
244 err
= grub_disk_read (node
->data
->disk
,
245 ((grub_disk_addr_t
) grub_le_to_cpu32 (node
->dirents
[i
].first_sector
)) << GRUB_ISO9660_LOG2_BLKSZ
,
253 return GRUB_ERR_NONE
;
256 /* Iterate over the susp entries, starting with block SUA_BLOCK on the
257 offset SUA_POS with a size of SUA_SIZE bytes. Hook is called for
260 grub_iso9660_susp_iterate (grub_fshelp_node_t node
, grub_off_t off
,
261 grub_ssize_t sua_size
,
263 (struct grub_iso9660_susp_entry
*entry
))
266 struct grub_iso9660_susp_entry
*entry
;
267 grub_disk_addr_t ce_block
;
270 auto grub_err_t
load_sua (void);
272 /* Load a part of the System Usage Area. */
273 grub_err_t
load_sua (void)
276 sua
= grub_malloc (sua_size
);
281 err
= grub_disk_read (node
->data
->disk
, ce_block
, off
,
284 err
= read_node (node
, off
, sua_size
, sua
);
288 entry
= (struct grub_iso9660_susp_entry
*) sua
;
293 return GRUB_ERR_NONE
;
298 for (; (char *) entry
< (char *) sua
+ sua_size
- 1;
299 entry
= (struct grub_iso9660_susp_entry
*)
300 ((char *) entry
+ entry
->len
))
302 /* The last entry. */
303 if (grub_strncmp ((char *) entry
->sig
, "ST", 2) == 0)
306 /* Additional entries are stored elsewhere. */
307 if (grub_strncmp ((char *) entry
->sig
, "CE", 2) == 0)
309 struct grub_iso9660_susp_ce
*ce
;
312 ce
= (struct grub_iso9660_susp_ce
*) entry
;
313 sua_size
= grub_le_to_cpu32 (ce
->len
);
314 off
= grub_le_to_cpu32 (ce
->off
);
315 ce_block
= grub_le_to_cpu32 (ce
->blk
) << GRUB_ISO9660_LOG2_BLKSZ
;
334 grub_iso9660_convert_string (grub_uint8_t
*us
, int len
)
338 grub_uint16_t t
[len
];
340 p
= grub_malloc (len
* GRUB_MAX_UTF8_PER_UTF16
+ 1);
344 for (i
=0; i
<len
; i
++)
345 t
[i
] = grub_be_to_cpu16 (grub_get_unaligned16 (us
+ 2 * i
));
347 *grub_utf16_to_utf8 ((grub_uint8_t
*) p
, t
, len
) = '\0';
353 set_rockridge (struct grub_iso9660_data
*data
)
358 struct grub_iso9660_dir rootdir
;
359 struct grub_iso9660_susp_entry
*entry
;
361 auto grub_err_t
susp_iterate (struct grub_iso9660_susp_entry
*);
363 grub_err_t
susp_iterate (struct grub_iso9660_susp_entry
*susp_entry
)
365 /* The "ER" entry is used to detect extensions. The
366 `IEEE_P1285' extension means Rock ridge. */
367 if (grub_strncmp ((char *) susp_entry
->sig
, "ER", 2) == 0)
377 /* Read the system use area and test it to see if SUSP is
379 if (grub_disk_read (data
->disk
,
380 (grub_le_to_cpu32 (data
->voldesc
.rootdir
.first_sector
)
381 << GRUB_ISO9660_LOG2_BLKSZ
), 0,
382 sizeof (rootdir
), (char *) &rootdir
))
383 return grub_error (GRUB_ERR_BAD_FS
, "not a ISO9660 filesystem");
385 sua_pos
= (sizeof (rootdir
) + rootdir
.namelen
386 + (rootdir
.namelen
% 2) - 1);
387 sua_size
= rootdir
.len
- sua_pos
;
390 return GRUB_ERR_NONE
;
392 sua
= grub_malloc (sua_size
);
396 if (grub_disk_read (data
->disk
,
397 (grub_le_to_cpu32 (data
->voldesc
.rootdir
.first_sector
)
398 << GRUB_ISO9660_LOG2_BLKSZ
), sua_pos
,
402 return grub_error (GRUB_ERR_BAD_FS
, "not a ISO9660 filesystem");
405 entry
= (struct grub_iso9660_susp_entry
*) sua
;
407 /* Test if the SUSP protocol is used on this filesystem. */
408 if (grub_strncmp ((char *) entry
->sig
, "SP", 2) == 0)
410 struct grub_fshelp_node rootnode
;
412 rootnode
.data
= data
;
413 rootnode
.alloc_dirents
= ARRAY_SIZE (rootnode
.dirents
);
414 rootnode
.have_dirents
= 1;
415 rootnode
.have_symlink
= 0;
416 rootnode
.dirents
[0] = data
->voldesc
.rootdir
;
418 /* The 2nd data byte stored how many bytes are skipped every time
419 to get to the SUA (System Usage Area). */
420 data
->susp_skip
= entry
->data
[2];
421 entry
= (struct grub_iso9660_susp_entry
*) ((char *) entry
+ entry
->len
);
423 /* Iterate over the entries in the SUA area to detect
425 if (grub_iso9660_susp_iterate (&rootnode
,
426 sua_pos
, sua_size
, susp_iterate
))
433 return GRUB_ERR_NONE
;
436 static struct grub_iso9660_data
*
437 grub_iso9660_mount (grub_disk_t disk
)
439 struct grub_iso9660_data
*data
= 0;
440 struct grub_iso9660_primary_voldesc voldesc
;
443 data
= grub_zalloc (sizeof (struct grub_iso9660_data
));
452 int copy_voldesc
= 0;
454 /* Read the superblock. */
455 if (grub_disk_read (disk
, block
<< GRUB_ISO9660_LOG2_BLKSZ
, 0,
456 sizeof (struct grub_iso9660_primary_voldesc
),
459 grub_error (GRUB_ERR_BAD_FS
, "not a ISO9660 filesystem");
463 if (grub_strncmp ((char *) voldesc
.voldesc
.magic
, "CD001", 5) != 0)
465 grub_error (GRUB_ERR_BAD_FS
, "not a ISO9660 filesystem");
469 if (voldesc
.voldesc
.type
== GRUB_ISO9660_VOLDESC_PRIMARY
)
471 else if (!data
->rockridge
472 && (voldesc
.voldesc
.type
== GRUB_ISO9660_VOLDESC_SUPP
)
473 && (voldesc
.escape
[0] == 0x25) && (voldesc
.escape
[1] == 0x2f)
475 ((voldesc
.escape
[2] == 0x40) || /* UCS-2 Level 1. */
476 (voldesc
.escape
[2] == 0x43) || /* UCS-2 Level 2. */
477 (voldesc
.escape
[2] == 0x45))) /* UCS-2 Level 3. */
485 grub_memcpy((char *) &data
->voldesc
, (char *) &voldesc
,
486 sizeof (struct grub_iso9660_primary_voldesc
));
487 if (set_rockridge (data
))
492 } while (voldesc
.voldesc
.type
!= GRUB_ISO9660_VOLDESC_END
);
503 grub_iso9660_read_symlink (grub_fshelp_node_t node
)
505 return node
->have_symlink
506 ? grub_strdup (node
->symlink
507 + (node
->have_dirents
) * sizeof (node
->dirents
[0])
508 - sizeof (node
->dirents
)) : grub_strdup ("");
512 get_node_size (grub_fshelp_node_t node
)
517 for (i
= 0; i
< node
->have_dirents
; i
++)
518 ret
+= grub_le_to_cpu32 (node
->dirents
[i
].size
);
523 grub_iso9660_iterate_dir (grub_fshelp_node_t dir
,
525 (*hook
) (const char *filename
,
526 enum grub_fshelp_filetype filetype
,
527 grub_fshelp_node_t node
))
529 struct grub_iso9660_dir dirent
;
530 grub_off_t offset
= 0;
532 int filename_alloc
= 0;
533 enum grub_fshelp_filetype type
;
536 int was_continue
= 0;
538 /* Extend the symlink. */
539 auto inline void __attribute__ ((always_inline
)) add_part (const char *part
,
542 auto inline void __attribute__ ((always_inline
)) add_part (const char *part
,
545 int size
= symlink
? grub_strlen (symlink
) : 0;
547 symlink
= grub_realloc (symlink
, size
+ len2
+ 1);
552 grub_strncat (symlink
, part
, len2
);
555 auto grub_err_t
susp_iterate_dir (struct grub_iso9660_susp_entry
*);
557 grub_err_t
susp_iterate_dir (struct grub_iso9660_susp_entry
*entry
)
559 /* The filename in the rock ridge entry. */
560 if (grub_strncmp ("NM", (char *) entry
->sig
, 2) == 0)
562 /* The flags are stored at the data position 0, here the
563 filename type is stored. */
564 /* FIXME: Fix this slightly improper cast. */
565 if (entry
->data
[0] & GRUB_ISO9660_RR_DOT
)
566 filename
= (char *) ".";
567 else if (entry
->data
[0] & GRUB_ISO9660_RR_DOTDOT
)
568 filename
= (char *) "..";
569 else if (entry
->len
>= 5)
571 grub_size_t size
= 1, csize
= 1;
573 csize
= size
= entry
->len
- 5;
577 size
+= grub_strlen (filename
);
578 filename
= grub_realloc (filename
, size
+ 1);
583 filename
= grub_zalloc (size
+ 1);
592 grub_strncat (filename
, (char *) &entry
->data
[1], csize
);
593 filename
[size
] = '\0';
596 /* The mode information (st_mode). */
597 else if (grub_strncmp ((char *) entry
->sig
, "PX", 2) == 0)
599 /* At position 0 of the PX record the st_mode information is
600 stored (little-endian). */
601 grub_uint32_t mode
= ((entry
->data
[0] + (entry
->data
[1] << 8))
602 & GRUB_ISO9660_FSTYPE_MASK
);
606 case GRUB_ISO9660_FSTYPE_DIR
:
607 type
= GRUB_FSHELP_DIR
;
609 case GRUB_ISO9660_FSTYPE_REG
:
610 type
= GRUB_FSHELP_REG
;
612 case GRUB_ISO9660_FSTYPE_SYMLINK
:
613 type
= GRUB_FSHELP_SYMLINK
;
616 type
= GRUB_FSHELP_UNKNOWN
;
619 else if (grub_strncmp ("SL", (char *) entry
->sig
, 2) == 0)
621 unsigned int pos
= 1;
623 /* The symlink is not stored as a POSIX symlink, translate it. */
624 while (pos
+ sizeof (*entry
) < entry
->len
)
626 /* The current position is the `Component Flag'. */
627 switch (entry
->data
[pos
] & 30)
631 /* The data on pos + 2 is the actual data, pos + 1
632 is the length. Both are part of the `Component
634 if (symlink
&& !was_continue
)
636 add_part ((char *) &entry
->data
[pos
+ 2],
637 entry
->data
[pos
+ 1]);
638 was_continue
= (entry
->data
[pos
] & 1);
654 /* In pos + 1 the length of the `Component Record' is
656 pos
+= entry
->data
[pos
+ 1] + 2;
659 /* Check if `grub_realloc' failed. */
667 len
= get_node_size (dir
);
669 for (; offset
< len
; offset
+= dirent
.len
)
674 if (read_node (dir
, offset
, sizeof (dirent
), (char *) &dirent
))
677 /* The end of the block, skip to the next one. */
680 offset
= (offset
/ GRUB_ISO9660_BLKSZ
+ 1) * GRUB_ISO9660_BLKSZ
;
685 char name
[dirent
.namelen
+ 1];
686 int nameoffset
= offset
+ sizeof (dirent
);
687 struct grub_fshelp_node
*node
;
688 int sua_off
= (sizeof (dirent
) + dirent
.namelen
+ 1
689 - (dirent
.namelen
% 2));
690 int sua_size
= dirent
.len
- sua_off
;
692 sua_off
+= offset
+ dir
->data
->susp_skip
;
696 type
= GRUB_FSHELP_UNKNOWN
;
698 if (dir
->data
->rockridge
699 && grub_iso9660_susp_iterate (dir
, sua_off
, sua_size
,
704 if (read_node (dir
, nameoffset
, dirent
.namelen
, (char *) name
))
707 node
= grub_malloc (sizeof (struct grub_fshelp_node
));
711 node
->alloc_dirents
= ARRAY_SIZE (node
->dirents
);
712 node
->have_dirents
= 1;
714 /* Setup a new node. */
715 node
->data
= dir
->data
;
716 node
->have_symlink
= 0;
718 /* If the filetype was not stored using rockridge, use
719 whatever is stored in the iso9660 filesystem. */
720 if (type
== GRUB_FSHELP_UNKNOWN
)
722 if ((dirent
.flags
& FLAG_TYPE
) == FLAG_TYPE_DIR
)
723 type
= GRUB_FSHELP_DIR
;
725 type
= GRUB_FSHELP_REG
;
729 if (!filename
&& dirent
.namelen
== 1 && name
[0] == 0)
730 filename
= (char *) ".";
732 if (!filename
&& dirent
.namelen
== 1 && name
[0] == 1)
733 filename
= (char *) "..";
735 /* The filename was not stored in a rock ridge entry. Read it
736 from the iso9660 filesystem. */
737 if (!dir
->data
->joliet
&& !filename
)
740 name
[dirent
.namelen
] = '\0';
741 filename
= grub_strrchr (name
, ';');
744 /* ISO9660 names are not case-preserving. */
745 type
|= GRUB_FSHELP_CASE_INSENSITIVE
;
746 for (ptr
= name
; *ptr
; ptr
++)
747 *ptr
= grub_tolower (*ptr
);
748 if (ptr
!= name
&& *(ptr
- 1) == '.')
753 if (dir
->data
->joliet
&& !filename
)
755 char *oldname
, *semicolon
;
758 filename
= grub_iso9660_convert_string
759 ((grub_uint8_t
*) oldname
, dirent
.namelen
>> 1);
761 semicolon
= grub_strrchr (filename
, ';');
771 node
->dirents
[0] = dirent
;
772 while (dirent
.flags
& FLAG_MORE_EXTENTS
)
774 offset
+= dirent
.len
;
775 if (read_node (dir
, offset
, sizeof (dirent
), (char *) &dirent
))
778 grub_free (filename
);
782 if (node
->have_dirents
>= node
->alloc_dirents
)
784 struct grub_fshelp_node
*new_node
;
785 node
->alloc_dirents
*= 2;
786 new_node
= grub_realloc (node
,
787 sizeof (struct grub_fshelp_node
)
788 + ((node
->alloc_dirents
789 - ARRAY_SIZE (node
->dirents
))
790 * sizeof (node
->dirents
[0])));
794 grub_free (filename
);
800 node
->dirents
[node
->have_dirents
++] = dirent
;
804 if ((node
->alloc_dirents
- node
->have_dirents
)
805 * sizeof (node
->dirents
[0]) < grub_strlen (symlink
) + 1)
807 struct grub_fshelp_node
*new_node
;
808 new_node
= grub_realloc (node
,
809 sizeof (struct grub_fshelp_node
)
810 + ((node
->alloc_dirents
811 - ARRAY_SIZE (node
->dirents
))
812 * sizeof (node
->dirents
[0]))
813 + grub_strlen (symlink
) + 1);
817 grub_free (filename
);
823 node
->have_symlink
= 1;
824 grub_strcpy (node
->symlink
825 + node
->have_dirents
* sizeof (node
->dirents
[0])
826 - sizeof (node
->dirents
), symlink
);
831 if (hook (filename
, type
, node
))
834 grub_free (filename
);
838 grub_free (filename
);
848 grub_iso9660_dir (grub_device_t device
, const char *path
,
849 int (*hook
) (const char *filename
,
850 const struct grub_dirhook_info
*info
))
852 struct grub_iso9660_data
*data
= 0;
853 struct grub_fshelp_node rootnode
;
854 struct grub_fshelp_node
*foundnode
;
856 auto int NESTED_FUNC_ATTR
iterate (const char *filename
,
857 enum grub_fshelp_filetype filetype
,
858 grub_fshelp_node_t node
);
860 int NESTED_FUNC_ATTR
iterate (const char *filename
,
861 enum grub_fshelp_filetype filetype
,
862 grub_fshelp_node_t node
)
864 struct grub_dirhook_info info
;
865 grub_memset (&info
, 0, sizeof (info
));
866 info
.dir
= ((filetype
& GRUB_FSHELP_TYPE_MASK
) == GRUB_FSHELP_DIR
);
867 info
.mtimeset
= !!iso9660_to_unixtime2 (&node
->dirents
[0].mtime
, &info
.mtime
);
870 return hook (filename
, &info
);
873 grub_dl_ref (my_mod
);
875 data
= grub_iso9660_mount (device
->disk
);
879 rootnode
.data
= data
;
880 rootnode
.alloc_dirents
= 0;
881 rootnode
.have_dirents
= 1;
882 rootnode
.have_symlink
= 0;
883 rootnode
.dirents
[0] = data
->voldesc
.rootdir
;
885 /* Use the fshelp function to traverse the path. */
886 if (grub_fshelp_find_file (path
, &rootnode
,
888 grub_iso9660_iterate_dir
,
889 grub_iso9660_read_symlink
,
893 /* List the files in the directory. */
894 grub_iso9660_iterate_dir (foundnode
, iterate
);
896 if (foundnode
!= &rootnode
)
897 grub_free (foundnode
);
902 grub_dl_unref (my_mod
);
908 /* Open a file named NAME and initialize FILE. */
910 grub_iso9660_open (struct grub_file
*file
, const char *name
)
912 struct grub_iso9660_data
*data
;
913 struct grub_fshelp_node rootnode
;
914 struct grub_fshelp_node
*foundnode
;
916 grub_dl_ref (my_mod
);
918 data
= grub_iso9660_mount (file
->device
->disk
);
922 rootnode
.data
= data
;
923 rootnode
.alloc_dirents
= 0;
924 rootnode
.have_dirents
= 1;
925 rootnode
.have_symlink
= 0;
926 rootnode
.dirents
[0] = data
->voldesc
.rootdir
;
928 /* Use the fshelp function to traverse the path. */
929 if (grub_fshelp_find_file (name
, &rootnode
,
931 grub_iso9660_iterate_dir
,
932 grub_iso9660_read_symlink
,
936 data
->node
= foundnode
;
938 file
->size
= get_node_size (foundnode
);
944 grub_dl_unref (my_mod
);
953 grub_iso9660_read (grub_file_t file
, char *buf
, grub_size_t len
)
955 struct grub_iso9660_data
*data
=
956 (struct grub_iso9660_data
*) file
->data
;
958 /* XXX: The file is stored in as a single extent. */
959 data
->disk
->read_hook
= file
->read_hook
;
960 read_node (data
->node
, file
->offset
, len
, buf
);
961 data
->disk
->read_hook
= NULL
;
971 grub_iso9660_close (grub_file_t file
)
973 struct grub_iso9660_data
*data
=
974 (struct grub_iso9660_data
*) file
->data
;
975 grub_free (data
->node
);
978 grub_dl_unref (my_mod
);
980 return GRUB_ERR_NONE
;
985 grub_iso9660_label (grub_device_t device
, char **label
)
987 struct grub_iso9660_data
*data
;
988 data
= grub_iso9660_mount (device
->disk
);
993 *label
= grub_iso9660_convert_string (data
->voldesc
.volname
, 16);
995 *label
= grub_strndup ((char *) data
->voldesc
.volname
, 32);
999 for (ptr
= *label
; *ptr
;ptr
++);
1001 while (ptr
>= *label
&& *ptr
== ' ')
1015 grub_iso9660_uuid (grub_device_t device
, char **uuid
)
1017 struct grub_iso9660_data
*data
;
1018 grub_disk_t disk
= device
->disk
;
1020 grub_dl_ref (my_mod
);
1022 data
= grub_iso9660_mount (disk
);
1025 if (! data
->voldesc
.modified
.year
[0] && ! data
->voldesc
.modified
.year
[1]
1026 && ! data
->voldesc
.modified
.year
[2] && ! data
->voldesc
.modified
.year
[3]
1027 && ! data
->voldesc
.modified
.month
[0] && ! data
->voldesc
.modified
.month
[1]
1028 && ! data
->voldesc
.modified
.day
[0] && ! data
->voldesc
.modified
.day
[1]
1029 && ! data
->voldesc
.modified
.hour
[0] && ! data
->voldesc
.modified
.hour
[1]
1030 && ! data
->voldesc
.modified
.minute
[0] && ! data
->voldesc
.modified
.minute
[1]
1031 && ! data
->voldesc
.modified
.second
[0] && ! data
->voldesc
.modified
.second
[1]
1032 && ! data
->voldesc
.modified
.hundredth
[0] && ! data
->voldesc
.modified
.hundredth
[1])
1034 grub_error (GRUB_ERR_BAD_NUMBER
, "no creation date in filesystem to generate UUID");
1039 *uuid
= grub_xasprintf ("%c%c%c%c-%c%c-%c%c-%c%c-%c%c-%c%c-%c%c",
1040 data
->voldesc
.modified
.year
[0],
1041 data
->voldesc
.modified
.year
[1],
1042 data
->voldesc
.modified
.year
[2],
1043 data
->voldesc
.modified
.year
[3],
1044 data
->voldesc
.modified
.month
[0],
1045 data
->voldesc
.modified
.month
[1],
1046 data
->voldesc
.modified
.day
[0],
1047 data
->voldesc
.modified
.day
[1],
1048 data
->voldesc
.modified
.hour
[0],
1049 data
->voldesc
.modified
.hour
[1],
1050 data
->voldesc
.modified
.minute
[0],
1051 data
->voldesc
.modified
.minute
[1],
1052 data
->voldesc
.modified
.second
[0],
1053 data
->voldesc
.modified
.second
[1],
1054 data
->voldesc
.modified
.hundredth
[0],
1055 data
->voldesc
.modified
.hundredth
[1]);
1061 grub_dl_unref (my_mod
);
1068 /* Get writing time of filesystem. */
1070 grub_iso9660_mtime (grub_device_t device
, grub_int32_t
*timebuf
)
1072 struct grub_iso9660_data
*data
;
1073 grub_disk_t disk
= device
->disk
;
1076 grub_dl_ref (my_mod
);
1078 data
= grub_iso9660_mount (disk
);
1081 grub_dl_unref (my_mod
);
1084 err
= iso9660_to_unixtime (&data
->voldesc
.modified
, timebuf
);
1086 grub_dl_unref (my_mod
);
1096 static struct grub_fs grub_iso9660_fs
=
1099 .dir
= grub_iso9660_dir
,
1100 .open
= grub_iso9660_open
,
1101 .read
= grub_iso9660_read
,
1102 .close
= grub_iso9660_close
,
1103 .label
= grub_iso9660_label
,
1104 .uuid
= grub_iso9660_uuid
,
1105 .mtime
= grub_iso9660_mtime
,
1107 .reserved_first_sector
= 1,
1108 .blocklist_install
= 1,
1113 GRUB_MOD_INIT(iso9660
)
1115 grub_fs_register (&grub_iso9660_fs
);
1119 GRUB_MOD_FINI(iso9660
)
1121 grub_fs_unregister (&grub_iso9660_fs
);