1 /***************************************************************************
2 * Copyright (c) 2005, 2006 by Dmitry Morozhnikov <dmiceman@mail.ru > *
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. *
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. *
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 ***************************************************************************/
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
{
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)
49 typedef struct _isofs_inode
{
50 struct iso_directory_record
*record
;
53 time_t ctime
; // cached value from record->date
63 size_t zf_header_size
;
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
73 int TF
; // 1 if TF entry found, st in effect
74 int ZF
; // 1 if ZF entry found
77 // borrowed from zisofs-tools
78 typedef struct _zf_file_header
{
80 char uncompressed_len
[4];
81 unsigned char header_size
;
82 unsigned char block_size
;
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. */
101 static inline int isonum_711(unsigned char *p
)
103 return *(unsigned char *)p
;
105 // static inline int isonum_712(char *p)
109 static inline unsigned int isonum_721(char *p
)
111 #if defined(WORDS_BIGENDIAN)
112 return *(unsigned short *)p
;
114 return bswap_16(*(unsigned short *)p
);
117 // static inline unsigned int isonum_722(char *p)
119 // return be16_to_cpu(get_unaligned((__le16 *)p));
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
);
127 return *(unsigned short *)p
;
130 static inline unsigned int isonum_731(char *p
)
132 #if defined(WORDS_BIGENDIAN)
133 return bswap_32(*(unsigned int *)p
);
135 return *(unsigned int *)p
;
138 // static inline unsigned int isonum_732(char *p)
140 // return be32_to_cpu(get_unaligned((__le32 *)p));
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
);
148 return *(unsigned int *)p
;
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
);