File indexing completed on 2024-05-12 17:22:21

0001 /*
0002     SPDX-FileCopyrightText: 2002 Shie Erlich <erlich@users.sourceforge.net>
0003     SPDX-FileCopyrightText: 2002 Rafi Yanai <yanai@users.sourceforge.net>
0004     SPDX-FileCopyrightText: 2004-2022 Krusader Krew <https://krusader.org>
0005 
0006     From the linux kernel
0007 
0008     SPDX-License-Identifier: GPL-2.0-or-later
0009 */
0010 
0011 #ifndef ISO_FS_H
0012 #define ISO_FS_H
0013 
0014 #include "bswap.h"
0015 
0016 #ifdef Q_OS_WIN
0017 #define DIR_SEPARATOR "/"
0018 #define DIR_SEPARATOR2 "\\"
0019 #define DIR_SEPARATOR_CHAR '/'
0020 #define DIR_SEPARATOR_CHAR2 '\\'
0021 #define REPLACE_DIR_SEP2(x) x = x.replace(DIR_SEPARATOR2, DIR_SEPARATOR);
0022 #else
0023 #define DIR_SEPARATOR "/"
0024 #define DIR_SEPARATOR2 "/"
0025 #define DIR_SEPARATOR_CHAR '/'
0026 #define DIR_SEPARATOR_CHAR2 '/'
0027 #define REPLACE_DIR_SEP2(x)
0028 #endif
0029 
0030 /*
0031  * The isofs filesystem constants/structures
0032  */
0033 
0034 /* This part borrowed from the bsd386 isofs */
0035 #define ISODCL(from, to) (to - from + 1)
0036 
0037 struct iso_volume_descriptor {
0038     char type[ISODCL(1, 1)]; /* 711 */
0039     char id[ISODCL(2, 6)];
0040     char version[ISODCL(7, 7)];
0041     char data[ISODCL(8, 2048)];
0042 };
0043 
0044 /* volume descriptor types */
0045 #define ISO_VD_BOOT 0
0046 #define ISO_VD_PRIMARY 1
0047 #define ISO_VD_SUPPLEMENTARY 2
0048 #define ISO_VD_END 255
0049 
0050 #define ISO_STANDARD_ID "CD001"
0051 
0052 struct iso_primary_descriptor {
0053     char type[ISODCL(1, 1)]; /* 711 */
0054     char id[ISODCL(2, 6)];
0055     char version[ISODCL(7, 7)]; /* 711 */
0056     char unused1[ISODCL(8, 8)];
0057     char system_id[ISODCL(9, 40)]; /* achars */
0058     char volume_id[ISODCL(41, 72)]; /* dchars */
0059     char unused2[ISODCL(73, 80)];
0060     char volume_space_size[ISODCL(81, 88)]; /* 733 */
0061     char unused3[ISODCL(89, 120)];
0062     char volume_set_size[ISODCL(121, 124)]; /* 723 */
0063     char volume_sequence_number[ISODCL(125, 128)]; /* 723 */
0064     char logical_block_size[ISODCL(129, 132)]; /* 723 */
0065     char path_table_size[ISODCL(133, 140)]; /* 733 */
0066     char type_l_path_table[ISODCL(141, 144)]; /* 731 */
0067     char opt_type_l_path_table[ISODCL(145, 148)]; /* 731 */
0068     char type_m_path_table[ISODCL(149, 152)]; /* 732 */
0069     char opt_type_m_path_table[ISODCL(153, 156)]; /* 732 */
0070     char root_directory_record[ISODCL(157, 190)]; /* 9.1 */
0071     char volume_set_id[ISODCL(191, 318)]; /* dchars */
0072     char publisher_id[ISODCL(319, 446)]; /* achars */
0073     char preparer_id[ISODCL(447, 574)]; /* achars */
0074     char application_id[ISODCL(575, 702)]; /* achars */
0075     char copyright_file_id[ISODCL(703, 739)]; /* 7.5 dchars */
0076     char abstract_file_id[ISODCL(740, 776)]; /* 7.5 dchars */
0077     char bibliographic_file_id[ISODCL(777, 813)]; /* 7.5 dchars */
0078     char creation_date[ISODCL(814, 830)]; /* 8.4.26.1 */
0079     char modification_date[ISODCL(831, 847)]; /* 8.4.26.1 */
0080     char expiration_date[ISODCL(848, 864)]; /* 8.4.26.1 */
0081     char effective_date[ISODCL(865, 881)]; /* 8.4.26.1 */
0082     char file_structure_version[ISODCL(882, 882)]; /* 711 */
0083     char unused4[ISODCL(883, 883)];
0084     char application_data[ISODCL(884, 1395)];
0085     char unused5[ISODCL(1396, 2048)];
0086 };
0087 
0088 /* Almost the same as the primary descriptor but two fields are specified */
0089 struct iso_supplementary_descriptor {
0090     char type[ISODCL(1, 1)]; /* 711 */
0091     char id[ISODCL(2, 6)];
0092     char version[ISODCL(7, 7)]; /* 711 */
0093     char flags[ISODCL(8, 8)]; /* 853 */
0094     char system_id[ISODCL(9, 40)]; /* achars */
0095     char volume_id[ISODCL(41, 72)]; /* dchars */
0096     char unused2[ISODCL(73, 80)];
0097     char volume_space_size[ISODCL(81, 88)]; /* 733 */
0098     char escape[ISODCL(89, 120)]; /* 856 */
0099     char volume_set_size[ISODCL(121, 124)]; /* 723 */
0100     char volume_sequence_number[ISODCL(125, 128)]; /* 723 */
0101     char logical_block_size[ISODCL(129, 132)]; /* 723 */
0102     char path_table_size[ISODCL(133, 140)]; /* 733 */
0103     char type_l_path_table[ISODCL(141, 144)]; /* 731 */
0104     char opt_type_l_path_table[ISODCL(145, 148)]; /* 731 */
0105     char type_m_path_table[ISODCL(149, 152)]; /* 732 */
0106     char opt_type_m_path_table[ISODCL(153, 156)]; /* 732 */
0107     char root_directory_record[ISODCL(157, 190)]; /* 9.1 */
0108     char volume_set_id[ISODCL(191, 318)]; /* dchars */
0109     char publisher_id[ISODCL(319, 446)]; /* achars */
0110     char preparer_id[ISODCL(447, 574)]; /* achars */
0111     char application_id[ISODCL(575, 702)]; /* achars */
0112     char copyright_file_id[ISODCL(703, 739)]; /* 7.5 dchars */
0113     char abstract_file_id[ISODCL(740, 776)]; /* 7.5 dchars */
0114     char bibliographic_file_id[ISODCL(777, 813)]; /* 7.5 dchars */
0115     char creation_date[ISODCL(814, 830)]; /* 8.4.26.1 */
0116     char modification_date[ISODCL(831, 847)]; /* 8.4.26.1 */
0117     char expiration_date[ISODCL(848, 864)]; /* 8.4.26.1 */
0118     char effective_date[ISODCL(865, 881)]; /* 8.4.26.1 */
0119     char file_structure_version[ISODCL(882, 882)]; /* 711 */
0120     char unused4[ISODCL(883, 883)];
0121     char application_data[ISODCL(884, 1395)];
0122     char unused5[ISODCL(1396, 2048)];
0123 };
0124 
0125 #define HS_STANDARD_ID "CDROM"
0126 
0127 struct hs_volume_descriptor {
0128     char foo[ISODCL(1, 8)]; /* 733 */
0129     char type[ISODCL(9, 9)]; /* 711 */
0130     char id[ISODCL(10, 14)];
0131     char version[ISODCL(15, 15)]; /* 711 */
0132     char data[ISODCL(16, 2048)];
0133 };
0134 
0135 struct hs_primary_descriptor {
0136     char foo[ISODCL(1, 8)]; /* 733 */
0137     char type[ISODCL(9, 9)]; /* 711 */
0138     char id[ISODCL(10, 14)];
0139     char version[ISODCL(15, 15)]; /* 711 */
0140     char unused1[ISODCL(16, 16)]; /* 711 */
0141     char system_id[ISODCL(17, 48)]; /* achars */
0142     char volume_id[ISODCL(49, 80)]; /* dchars */
0143     char unused2[ISODCL(81, 88)]; /* 733 */
0144     char volume_space_size[ISODCL(89, 96)]; /* 733 */
0145     char unused3[ISODCL(97, 128)]; /* 733 */
0146     char volume_set_size[ISODCL(129, 132)]; /* 723 */
0147     char volume_sequence_number[ISODCL(133, 136)]; /* 723 */
0148     char logical_block_size[ISODCL(137, 140)]; /* 723 */
0149     char path_table_size[ISODCL(141, 148)]; /* 733 */
0150     char type_l_path_table[ISODCL(149, 152)]; /* 731 */
0151     char unused4[ISODCL(153, 180)]; /* 733 */
0152     char root_directory_record[ISODCL(181, 214)]; /* 9.1 */
0153 };
0154 
0155 /* We use this to help us look up the parent inode numbers. */
0156 
0157 struct iso_path_table {
0158     char name_len[1]; /* 711 */
0159     char ext_attr_length[1]; /* 711 */
0160     char extent[4]; /* 731 */
0161     char parent[2]; /* 721 */
0162     char name[1];
0163 };
0164 
0165 /* high sierra is identical to iso, except that the date is only 6 bytes, and
0166    there is an extra reserved byte after the flags */
0167 
0168 struct iso_directory_record {
0169     char length[ISODCL(1, 1)]; /* 711 */
0170     char ext_attr_length[ISODCL(2, 2)]; /* 711 */
0171     char extent[ISODCL(3, 10)]; /* 733 */
0172     char size[ISODCL(11, 18)]; /* 733 */
0173     char date[ISODCL(19, 25)]; /* 7 by 711 */
0174     char flags[ISODCL(26, 26)];
0175     char file_unit_size[ISODCL(27, 27)]; /* 711 */
0176     char interleave[ISODCL(28, 28)]; /* 711 */
0177     char volume_sequence_number[ISODCL(29, 32)]; /* 723 */
0178     char name_len[ISODCL(33, 33)]; /* 711 */
0179     char name[1];
0180 };
0181 
0182 /* 8 bit numbers */
0183 static __inline unsigned char isonum_711(char *p);
0184 static __inline char isonum_712(char *p);
0185 
0186 /* 16 bit numbers */
0187 static __inline unsigned short isonum_721(char *p);
0188 static __inline unsigned short isonum_722(char *p);
0189 static __inline unsigned short isonum_723(char *p);
0190 
0191 /* 32 bit numbers */
0192 static __inline unsigned int isonum_731(char *p);
0193 static __inline unsigned int isonum_732(char *p);
0194 static __inline unsigned int isonum_733(char *p);
0195 
0196 /* 8 bit numbers */
0197 static __inline unsigned char isonum_711(char *p)
0198 {
0199     return *(unsigned char *)p;
0200 }
0201 static __inline char isonum_712(char *p)
0202 {
0203     return *p;
0204 }
0205 
0206 /* 16 bit numbers */
0207 static __inline unsigned short isonum_721(char *p)
0208 {
0209     return le2me_16(*(unsigned short *)p);
0210 }
0211 static __inline unsigned short isonum_722(char *p)
0212 {
0213     return be2me_16(*(unsigned short *)p);
0214 }
0215 static __inline unsigned short isonum_723(char *p)
0216 {
0217     /* Ignore bigendian datum due to broken mastering programs */
0218     return le2me_16(*(unsigned short *)p);
0219 }
0220 
0221 /* 32 bit numbers */
0222 static __inline unsigned int isonum_731(char *p)
0223 {
0224     return le2me_32(*(unsigned int *)p);
0225 }
0226 
0227 static __inline unsigned int isonum_732(char *p)
0228 {
0229     return be2me_32(*(unsigned int *)p);
0230 }
0231 
0232 static __inline unsigned int isonum_733(char *p)
0233 {
0234     /* Ignore bigendian datum due to broken mastering programs */
0235     return le2me_32(*(unsigned int *)p);
0236 }
0237 
0238 #endif /*_ISOFS_H*/