Home | History | Annotate | Download | only in stage2
      1 /*
      2  *  ISO 9660 filesystem backend for GRUB (GRand Unified Bootloader)
      3  *  including Rock Ridge Extensions support
      4  *
      5  *  Copyright (C) 1998, 1999  Kousuke Takai  <tak (at) kmc.kyoto-u.ac.jp>
      6  *
      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.
     11  *
     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.
     16  *
     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., 675 Mass Ave, Cambridge, MA 02139, USA.
     20  */
     21 /*
     22  *  References:
     23  *	linux/fs/isofs/rock.[ch]
     24  *	mkisofs-1.11.1/diag/isoinfo.c
     25  *	mkisofs-1.11.1/iso9660.h
     26  *		(all are written by Eric Youngdale)
     27  */
     28 
     29 #ifndef _ISO9660_H_
     30 #define _ISO9660_H_
     31 
     32 #define ISO_SECTOR_BITS              (11)
     33 #define ISO_SECTOR_SIZE              (1<<ISO_SECTOR_BITS)
     34 
     35 #define	ISO_REGULAR	1	/* regular file	*/
     36 #define	ISO_DIRECTORY	2	/* directory	*/
     37 #define	ISO_OTHER	0	/* other file (with Rock Ridge) */
     38 
     39 #define	RR_FLAG_PX	0x01	/* have POSIX file attributes */
     40 #define RR_FLAG_PN	0x02	/* POSIX devices */
     41 #define RR_FLAG_SL	0x04	/* Symbolic link */
     42 #define	RR_FLAG_NM	0x08	/* have alternate file name   */
     43 #define RR_FLAG_CL	0x10	/* Child link */
     44 #define RR_FLAG_PL	0x20	/* Parent link */
     45 #define RR_FLAG_RE	0x40	/* Relocation directory */
     46 #define RR_FLAG_TF	0x80	/* Timestamps */
     47 
     48 /* POSIX file attributes for Rock Ridge extensions */
     49 #define	POSIX_S_IFMT	0xF000
     50 #define	POSIX_S_IFREG	0x8000
     51 #define	POSIX_S_IFDIR	0x4000
     52 
     53 /* volume descriptor types */
     54 #define ISO_VD_PRIMARY 1
     55 #define ISO_VD_END 255
     56 
     57 #define ISO_STANDARD_ID "CD001"
     58 
     59 #ifndef ASM_FILE
     60 
     61 #ifndef	__BIT_TYPES_DEFINED__
     62 typedef		 int	 int8_t	__attribute__((mode(QI)));
     63 typedef unsigned int   u_int8_t	__attribute__((mode(QI)));
     64 typedef		 int	int16_t	__attribute__((mode(HI)));
     65 typedef unsigned int  u_int16_t	__attribute__((mode(HI)));
     66 typedef		 int	int32_t	__attribute__((mode(SI)));
     67 typedef unsigned int  u_int32_t	__attribute__((mode(SI)));
     68 #endif
     69 
     70 typedef	union {
     71   u_int8_t l,b;
     72 }	iso_8bit_t;
     73 
     74 typedef	struct __iso_16bit {
     75   u_int16_t l, b;
     76 } iso_16bit_t __attribute__ ((packed));
     77 
     78 typedef	struct __iso_32bit {
     79   u_int32_t l, b;
     80 } iso_32bit_t __attribute__ ((packed));
     81 
     82 typedef u_int8_t		iso_date_t[7];
     83 
     84 struct iso_directory_record {
     85   iso_8bit_t	length;
     86   iso_8bit_t	ext_attr_length;
     87   iso_32bit_t	extent;
     88   iso_32bit_t	size;
     89   iso_date_t	date;
     90   iso_8bit_t	flags;
     91   iso_8bit_t	file_unit_size;
     92   iso_8bit_t	interleave;
     93   iso_16bit_t	volume_seq_number;
     94   iso_8bit_t	name_len;
     95   u_int8_t	name[1];
     96 } __attribute__ ((packed));
     97 
     98 struct iso_primary_descriptor {
     99   iso_8bit_t	type;
    100   u_int8_t	id[5];
    101   iso_8bit_t	version;
    102   u_int8_t	_unused1[1];
    103   u_int8_t	system_id[32];
    104   u_int8_t	volume_id[32];
    105   u_int8_t	_unused2[8];
    106   iso_32bit_t	volume_space_size;
    107   u_int8_t	_unused3[32];
    108   iso_16bit_t	volume_set_size;
    109   iso_16bit_t	volume_seq_number;
    110   iso_16bit_t	logical_block_size;
    111   iso_32bit_t	path_table_size;
    112   u_int8_t	type_l_path_table[4];
    113   u_int8_t	opt_type_l_path_table[4];
    114   u_int8_t	type_m_path_table[4];
    115   u_int8_t	opt_type_m_path_table[4];
    116   struct iso_directory_record root_directory_record;
    117   u_int8_t	volume_set_id[128];
    118   u_int8_t	publisher_id[128];
    119   u_int8_t	preparer_id[128];
    120   u_int8_t	application_id[128];
    121   u_int8_t	copyright_file_id[37];
    122   u_int8_t	abstract_file_id[37];
    123   u_int8_t	bibliographic_file_id[37];
    124   u_int8_t	creation_date[17];
    125   u_int8_t	modification_date[17];
    126   u_int8_t	expiration_date[17];
    127   u_int8_t	effective_date[17];
    128   iso_8bit_t	file_structure_version;
    129   u_int8_t	_unused4[1];
    130   u_int8_t	application_data[512];
    131   u_int8_t	_unused5[653];
    132 } __attribute__ ((packed));
    133 
    134 struct rock_ridge {
    135   u_int16_t	signature;
    136   u_int8_t	len;
    137   u_int8_t	version;
    138   union {
    139     struct SP {
    140       u_int16_t	magic;
    141       u_int8_t	skip;
    142     } sp;
    143     struct CE {
    144       iso_32bit_t	extent;
    145       iso_32bit_t	offset;
    146       iso_32bit_t	size;
    147     } ce;
    148     struct ER {
    149       u_int8_t	len_id;
    150       u_int8_t	len_des;
    151       u_int8_t	len_src;
    152       u_int8_t	ext_ver;
    153       u_int8_t	data[0];
    154     } er;
    155     struct RR {
    156       iso_8bit_t	flags;
    157     } rr;
    158     struct PX {
    159       iso_32bit_t	mode;
    160       iso_32bit_t	nlink;
    161       iso_32bit_t	uid;
    162       iso_32bit_t	gid;
    163     } px;
    164     struct PN {
    165       iso_32bit_t	dev_high;
    166       iso_32bit_t	dev_low;
    167     } pn;
    168     struct SL {
    169       iso_8bit_t flags;
    170       struct SL_component {
    171 	iso_8bit_t	flags;
    172 	u_int8_t		len;
    173 	u_int8_t		text[0];
    174       } link;
    175     } sl;
    176     struct NM {
    177       iso_8bit_t	flags;
    178       u_int8_t	name[0];
    179     } nm;
    180     struct CL {
    181       iso_32bit_t	location;
    182     } cl;
    183     struct PL {
    184       iso_32bit_t	location;
    185     } pl;
    186     struct TF {
    187       iso_8bit_t	flags;
    188       iso_date_t	times[0];
    189     } tf;
    190   } u;
    191 } __attribute__ ((packed));
    192 
    193 typedef	union RR_ptr {
    194   struct rock_ridge *rr;
    195   char		  *ptr;
    196   int		   i;
    197 } RR_ptr_t;
    198 
    199 #define	RRMAGIC(c1, c2)	((c1)|(c2) << 8)
    200 
    201 #define	CHECK2(ptr, c1, c2) \
    202 	(*(unsigned short *)(ptr) == (((c1) | (c2) << 8) & 0xFFFF))
    203 
    204 #endif /* !ASM_FILE */
    205 
    206 #endif /* _ISO9660_H_ */
    207