Update README.md
[appimagekit/gsi.git] / isofs.h
blobc9a6072be9c2b0dfe9b7b030a85ca657052e9ede
1 /***************************************************************************
2 * Copyright (c) 2005, 2006 by Dmitry Morozhnikov <dmiceman@mail.ru > *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
18 ***************************************************************************/
20 #ifndef _ISOFS_H
21 #define _ISOFS_H
23 #include <sys/stat.h>
24 #include <linux/iso_fs.h>
25 #include <linux/rock.h>
27 typedef int (*isofs_dir_fill_t) (void *buf, const char *name,
28 const struct stat *stat, off_t off);
30 typedef struct _isofs_context {
31 char *imagefile;
32 int fd;
33 int pd_have_rr; // 1 if primary descriptor have hierarchy with rrip extension
34 struct iso_primary_descriptor pd;
35 int supplementary; // 1 if supplementary descriptor found and in effect
36 struct iso_supplementary_descriptor sd;
37 struct iso_directory_record *root;
38 int file_offset; // offset to begin of useful data (for .nrg files)
39 int id_offset; // offset to CD001 inside file
40 size_t block_size; // raw block size
41 size_t block_offset; // offset from block start to data
42 size_t data_size; // data size inside block
43 int susp; // parse susp entries
44 int susp_skip; // skip bytes from susp SP entry
45 int joliet_level; // joliet extension level (1, 2 or 3)
46 ino_t last_ino;
47 } isofs_context;
49 typedef struct _isofs_inode {
50 struct iso_directory_record *record;
51 struct stat st;
52 ino_t st_ino;
53 time_t ctime; // cached value from record->date
54 char *sl;
55 size_t sl_len;
56 char *nm;
57 size_t nm_len;
58 int cl_block;
59 int pl_block;
60 size_t zf_size;
61 size_t real_size;
62 char zf_algorithm[2];
63 size_t zf_header_size;
64 int zf_block_shift;
65 int zf_nblocks;
66 int *zf_blockptr;
67 int PX; // 1 if PX entry found, st in effect
68 int SL; // 1 if SL entry found, sl in effect
69 int NM; // 1 if NM entry found, nm in effect
70 int CL; // 1 if CL found, cl_block in effect
71 int PL; // 1 if PL found, pl_block in effect
72 int RE;
73 int TF; // 1 if TF entry found, st in effect
74 int ZF; // 1 if ZF entry found
75 } isofs_inode;
77 // borrowed from zisofs-tools
78 typedef struct _zf_file_header {
79 char magic[8];
80 char uncompressed_len[4];
81 unsigned char header_size;
82 unsigned char block_size;
83 char reserved[2];
84 } zf_file_header;
86 // macros for iso_directory_record->flags
87 #define ISO_FLAGS_HIDDEN(x) (*((unsigned char *) x) & 1)
88 #define ISO_FLAGS_DIR(x) (*((unsigned char *) x) & (1 << 1))
90 // borrowed from linux kernel rock ridge code
92 #define SIG(A,B) ((A) | ((B) << 8)) /* isonum_721() */
94 // borrowed from linux kernel isofs code
96 /* Number conversion inlines, named after the section in ISO 9660
97 they correspond to. */
99 #include <byteswap.h>
101 static inline int isonum_711(unsigned char *p)
103 return *(unsigned char *)p;
105 // static inline int isonum_712(char *p)
106 // {
107 // return *(s8 *)p;
108 // }
109 static inline unsigned int isonum_721(char *p)
111 #if defined(WORDS_BIGENDIAN)
112 return *(unsigned short *)p;
113 #else
114 return bswap_16(*(unsigned short *)p);
115 #endif
117 // static inline unsigned int isonum_722(char *p)
118 // {
119 // return be16_to_cpu(get_unaligned((__le16 *)p));
120 // }
121 static inline unsigned int isonum_723(char *p)
123 /* Ignore bigendian datum due to broken mastering programs */
124 #if defined(WORDS_BIGENDIAN)
125 return bswap_16(*(unsigned short *)p);
126 #else
127 return *(unsigned short *)p;
128 #endif
130 static inline unsigned int isonum_731(char *p)
132 #if defined(WORDS_BIGENDIAN)
133 return bswap_32(*(unsigned int *)p);
134 #else
135 return *(unsigned int *)p;
136 #endif
138 // static inline unsigned int isonum_732(char *p)
139 // {
140 // return be32_to_cpu(get_unaligned((__le32 *)p));
141 // }
142 static inline unsigned int isonum_733(char *p)
144 /* Ignore bigendian datum due to broken mastering programs */
145 #if defined(WORDS_BIGENDIAN)
146 return bswap_32(*(unsigned int *)p);
147 #else
148 return *(unsigned int *)p;
149 #endif
152 int isofs_real_preinit(char* imagefile, int fd);
153 void* isofs_real_init();
155 int isofs_real_opendir(const char *path);
156 int isofs_real_readdir(const char *path, void *filler_buf, isofs_dir_fill_t filler);
157 int isofs_real_getattr(const char *path, struct stat *stbuf);
158 int isofs_real_readlink(const char *path, char *target, size_t size);
159 int isofs_real_open(const char *path);
160 int isofs_real_read(const char *path, char *out_buf, size_t size, off_t offset);
161 int isofs_real_statfs(struct statfs *stbuf);
163 #endif // _ISOFS_H