2 * ISO 9660 filesystem backend for GRUB (GRand Unified Bootloader)
3 * including Rock Ridge Extensions support
5 * Copyright (C) 1998, 1999 Kousuke Takai <tak@kmc.kyoto-u.ac.jp>
7 * This program 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 2 of the License, or
10 * (at your option) any later version.
12 * This program 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 this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
24 * linux/fs/isofs/rock.[ch]
25 * mkisofs-1.11.1/diag/isoinfo.c
26 * mkisofs-1.11.1/iso9660.h
27 * (all are written by Eric Youngdale)
30 * Leonid Lisovskiy <lly@pisem.net> 2003
34 * Modified to make it work with FILO
35 * 2003-10 by SONE Takeshi
45 #if defined(__sparc__) || defined(__PPC__)
51 struct iso_superblock {
52 unsigned long vol_sector;
54 unsigned long file_start;
57 #define ISO_SUPER ((struct iso_superblock *)(FSYS_BUF))
58 #define PRIMDESC ((struct iso_primary_descriptor *)(FSYS_BUF + 2048))
59 #define DIRREC ((struct iso_directory_record *)(FSYS_BUF + 4096))
60 #define RRCONT_BUF ((unsigned char *)(FSYS_BUF + 6144))
61 #define NAME_BUF ((unsigned char *)(FSYS_BUF + 8192))
64 iso9660_devread (int sector, int byte_offset, int byte_len, char *buf)
66 /* FILO uses 512-byte "soft" sector, and ISO-9660 uses 2048-byte
68 return devread(sector<<2, byte_offset, byte_len, buf);
77 * Because there is no defined slice type ID for ISO-9660 filesystem,
78 * this test will pass only either (1) if entire disk is used, or
79 * (2) if current partition is BSD style sub-partition whose ID is
82 /*if ((current_partition != 0xFFFFFF)
83 && !IS_PC_SLICE_TYPE_BSD_WITH_FS(current_slice, FS_ISO9660))
87 * Currently, only FIRST session of MultiSession disks are supported !!!
89 for (sector = 16 ; sector < 32 ; sector++)
91 if (!iso9660_devread(sector, 0, sizeof(*PRIMDESC), (char *)PRIMDESC))
93 /* check ISO_VD_PRIMARY and ISO_STANDARD_ID */
94 if (CHECK4(&PRIMDESC->type, ISO_VD_PRIMARY, 'C', 'D', '0')
95 && CHECK2(PRIMDESC->id + 3, '0', '1'))
97 ISO_SUPER->vol_sector = sector;
98 ISO_SUPER->file_start = 0;
99 fsmax = PRIMDESC->volume_space_size.ENDIAN;
108 iso9660_dir (char *dirname)
110 struct iso_directory_record *idr;
112 struct rock_ridge *ce_ptr;
113 unsigned int pathlen;
117 unsigned char file_type;
118 unsigned char rr_flag;
120 idr = &PRIMDESC->root_directory_record;
121 ISO_SUPER->file_start = 0;
125 while (*dirname == '/') /* skip leading slashes */
127 /* pathlen = strcspn(dirname, "/\n\t "); */
130 && !isspace(dirname[pathlen]) && dirname[pathlen] != '/' ;
134 size = idr->size.ENDIAN;
135 extent = idr->extent.ENDIAN;
139 if (!iso9660_devread(extent, 0, ISO_SECTOR_SIZE, (char *)DIRREC))
141 errnum = ERR_FSYS_CORRUPT;
146 idr = (struct iso_directory_record *)DIRREC;
147 for (; idr->length.ENDIAN > 0;
148 idr = (struct iso_directory_record *)((char *)idr + idr->length.ENDIAN) )
150 const char *name = (char *)idr->name;
151 unsigned int name_len = idr->name_len.ENDIAN;
153 file_type = (idr->flags.ENDIAN & 2) ? ISO_DIRECTORY : ISO_REGULAR;
156 if ((name[0] == 0) || /* self */
157 (name[0] == 1)) /* parent */
160 if (name_len > 2 && CHECK2(name + name_len - 2, ';', '1'))
162 name_len -= 2; /* truncate trailing file version */
163 if (name_len > 1 && name[name_len - 1] == '.')
164 name_len--; /* truncate trailing dot */
168 * Parse Rock-Ridge extension
170 rr_len = (idr->length.ENDIAN - idr->name_len.ENDIAN
171 - (unsigned char)sizeof(struct iso_directory_record)
172 + (unsigned char)sizeof(idr->name));
173 rr_ptr.ptr = ((char *)idr + idr->name_len.ENDIAN
174 + sizeof(struct iso_directory_record)
175 - sizeof(idr->name));
177 rr_ptr.ptr++, rr_len--;
179 rr_flag = RR_FLAG_NM | RR_FLAG_PX;
183 if (rr_ptr.rr->version != 1)
188 "Non-supported version (%d) RockRidge chunk "
189 "`%c%c'\n", rr_ptr.rr->version,
190 rr_ptr.rr->signature & 0xFF,
191 rr_ptr.rr->signature >> 8);
194 else if (CHECK2(&rr_ptr.rr->signature, 'R', 'R')
195 && rr_ptr.rr->len >= 5)
196 rr_flag &= rr_ptr.rr->u.rr.flags.ENDIAN;
197 else if (CHECK2(&rr_ptr.rr->signature, 'N', 'M'))
199 name = (char *)rr_ptr.rr->u.nm.name;
200 name_len = rr_ptr.rr->len - 5;
201 rr_flag &= ~RR_FLAG_NM;
203 else if (CHECK2(&rr_ptr.rr->signature, 'P', 'X')
204 && rr_ptr.rr->len >= 36)
206 file_type = ((rr_ptr.rr->u.px.mode.ENDIAN & POSIX_S_IFMT)
209 : ((rr_ptr.rr->u.px.mode.ENDIAN & POSIX_S_IFMT)
211 ? ISO_DIRECTORY : ISO_OTHER));
212 rr_flag &= ~RR_FLAG_PX;
214 else if (CHECK2(&rr_ptr.rr->signature, 'C', 'E')
215 && rr_ptr.rr->len >= 28)
219 * There is no more extension we expects...
222 rr_len -= rr_ptr.rr->len;
223 rr_ptr.ptr += rr_ptr.rr->len;
224 if (rr_len < 4 && ce_ptr != NULL)
226 /* preserve name before loading new extent. */
227 if( RRCONT_BUF <= (unsigned char *)name
228 && (unsigned char *)name < RRCONT_BUF + ISO_SECTOR_SIZE )
230 memcpy(NAME_BUF, name, name_len);
231 name = (char *)NAME_BUF;
233 rr_ptr.ptr = (char *)(RRCONT_BUF + ce_ptr->u.ce.offset.ENDIAN);
234 rr_len = ce_ptr->u.ce.size.ENDIAN;
235 if (!iso9660_devread(ce_ptr->u.ce.extent.ENDIAN, 0,
236 ISO_SECTOR_SIZE, (char *)RRCONT_BUF))
238 errnum = 0; /* this is not fatal. */
246 if (name_len >= pathlen
247 && !strnicmp(name, dirname, pathlen))
249 if (dirname[pathlen] == '/' || !print_possibilities)
252 * DIRNAME is directory component of pathname,
253 * or we are to open a file.
255 if (pathlen == name_len)
257 if (dirname[pathlen] == '/')
259 if (file_type != ISO_DIRECTORY)
261 errnum = ERR_BAD_FILETYPE;
266 if (file_type != ISO_REGULAR)
268 errnum = ERR_BAD_FILETYPE;
271 ISO_SUPER->file_start = idr->extent.ENDIAN;
273 filemax = idr->size.ENDIAN;
277 else /* Completion */
280 if (print_possibilities > 0)
281 print_possibilities = -print_possibilities;
282 memcpy(NAME_BUF, name, name_len);
283 NAME_BUF[name_len] = '\0';
284 print_a_completion (NAME_BUF);
290 size -= ISO_SECTOR_SIZE;
293 if (dirname[pathlen] == '/' || print_possibilities >= 0)
295 errnum = ERR_FILE_NOT_FOUND;
302 } while (*dirname == '/');
308 iso9660_read (char *buf, int len)
310 int sector, blkoffset, size, ret;
312 if (ISO_SUPER->file_start == 0)
316 blkoffset = filepos & (ISO_SECTOR_SIZE - 1);
317 sector = filepos >> ISO_SECTOR_BITS;
320 size = ISO_SECTOR_SIZE - blkoffset;
324 disk_read_func = disk_read_hook;
326 if (!iso9660_devread(ISO_SUPER->file_start + sector, blkoffset, size, buf))
329 disk_read_func = NULL;
342 #endif /* FSYS_ISO9660 */