1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
|
/*
* Copyright (C) 2003 by The Joker / Avalaunch team
* Copyright (C) 2003-2013 Team XBMC
* http://xbmc.org
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XBMC; see the file COPYING. If not, see
* <http://www.gnu.org/licenses/>.
*
*/
#ifndef ISO9660_H
#define ISO9660_H
#pragma once
#include <vector>
#include <string>
#include "system.h" // for win32 types
#ifdef TARGET_WINDOWS
// Ideally we should just be including iso9660.h, but it's not win32-ified at this point,
// and these are all we need
typedef uint32_t iso723_t;
typedef uint64_t iso733_t;
#else
#include <cdio/iso9660.h>
#endif
#pragma pack(1)
struct iso9660_VolumeDescriptor
{
unsigned char byOne; //0
char szSignature[6]; //1-6
unsigned char byZero; //7
char szSystemIdentifier[32]; //8-39
char szVolumeIdentifier[32]; //40-71
unsigned char byZero2[8]; //72-79
DWORD dwTotalSectorsLE; //80-83
DWORD dwTotalSectorsBE; //84-87
unsigned char byZero3[32]; //88-119
WORD wVolumeSetSizeLE; //120-121
WORD wVolumeSetSizeBE; //122-123
WORD wVolumeSequenceNumberLE; //124-125
WORD wVolumeSequenceNumberBE; //126-127
iso723_t logical_block_size; // sector size, e.g. 2048 (128-129 LE - 130-131 BE)
DWORD dwPathTableLengthLE; //132-135
DWORD dwPathTableLengthBE; //136-139
DWORD wFirstPathTableStartSectorLE; //140-143
DWORD wSecondPathTableStartSectorLE; //144-147
DWORD wFirstPathTableStartSectorBE; //148-151
DWORD wSecondPathTableStartSectorBE; //152-155
unsigned char szRootDir[34];
unsigned char szVolumeSetIdentifier[128];
unsigned char szPublisherIdentifier[128];
unsigned char szDataPreparerIdentifier[128];
unsigned char szApplicationIdentifier[128];
unsigned char szCopyRightFileIdentifier[37];
unsigned char szAbstractFileIdentifier[37];
unsigned char szBibliographicalFileIdentifier[37];
unsigned char tDateTimeVolumeCreation[17];
unsigned char tDateTimeVolumeModification[17];
unsigned char tDateTimeVolumeExpiration[17];
unsigned char tDateTimeVolumeEffective[17];
unsigned char byOne2;
unsigned char byZero4;
unsigned char byZero5[512];
unsigned char byZero6[653];
} ;
struct iso9660_Datetime {
BYTE year; /* Number of years since 1900 */
BYTE month; /* Has value in range 1..12. Note starts
at 1, not 0 like a tm struct. */
BYTE day; /* Day of the month from 1 to 31 */
BYTE hour; /* Hour of the day from 0 to 23 */
BYTE minute; /* Minute of the hour from 0 to 59 */
BYTE second; /* Second of the minute from 0 to 59 */
char gmtoff; /* GMT values -48 .. + 52 in 15 minute intervals */
};
struct iso9660_Directory
{
#define Flag_NotExist 0x01 /* 1-file not exists */
#define Flag_Directory 0x02 /* 0-normal file, 1-directory */
#define Flag_Associated 0x03 /* 0-not associated file */
#define Flag_Protection 0x04 /* 0-normal acces */
#define Flag_Multi 0x07 /* 0-final Directory Record for the file */
BYTE ucRecordLength; //0 the number of bytes in the record (which must be even)
BYTE ucExtendAttributeSectors; //1 [number of sectors in extended attribute record]
iso733_t extent; // LBA of first local block allocated to the extent (2..5 LE - 6..9 BE)
iso733_t size; // data length of File Section. This does not include the length of any XA Records. (10..13 LE - 14..17 BE)
iso9660_Datetime DateTime; //18..24 date
BYTE byFlags; //25 flags
BYTE UnitSize; //26 file unit size for an interleaved file
BYTE InterleaveGapSize; //27 interleave gap size for an interleaved file
WORD VolSequenceLE; //28..29 volume sequence number
WORD VolSequenceBE; //30..31
BYTE Len_Fi; //32 N, the identifier length
BYTE FileName[512]; //33 identifier
};
#pragma pack()
struct iso9660info
{
char iso9660; // found iso9660 format ?
char joliet; // found joliet format ?
DWORD mp3; // found mp3s ?
DWORD HeaderPos; // joliet header position if found, regular if not
DWORD DirSize; // size of current dir, will be dividable by 2048
DWORD CurrDirPos; // position of current selected dir
char *Curr_dir_cache; // current dir in raw format
char *Curr_dir; // name of current directory
DWORD Curr_dir_sectorsize; // dirs are sometimes bigger than a sector - then we need this info.
HANDLE ISO_HANDLE;
DWORD iso9660searchpointer; // for search use
DWORD curr_filesize; // for use when openfile'd a file.
DWORD curr_filepos; // for use when openfile'd a file.
struct iso9660_VolumeDescriptor iso; // best fitted header
struct iso9660_Directory isodir;
struct iso9660_Directory isofileinfo;
};
struct iso_dirtree
{
char *path;
char *name; // name of the directory/file
char type; // bit 0 = no entry, bit 1 = file, bit 2 = dir
DWORD Location; // number of the first sector of file data or directory
DWORD Length; // number of bytes of file data or length of directory
FILETIME filetime; // date time of the directory/file
struct iso_dirtree *dirpointer; // if type is a dir, this will point to the list in that dir
struct iso_dirtree *next; // pointer to next file/dir in this directory
};
struct iso_directories
{
char* path;
struct iso_dirtree* dir;
struct iso_directories* next;
};
#define MAX_ISO_FILES 30
class iso9660
{
public:
class isofile
{
public:
bool m_bUseMode2;
DWORD m_dwCircBuffBegin;
DWORD m_dwCircBuffEnd;
DWORD m_dwCircBuffSectorStart;
DWORD m_dwStartBlock;
DWORD m_dwCurrentBlock; // Current being read Block
int64_t m_dwFilePos;
BYTE* m_pBuffer;
int64_t m_dwFileSize;
};
iso9660( );
virtual ~iso9660( );
HANDLE FindFirstFile( char *szLocalFolder, WIN32_FIND_DATA *wfdFile );
int FindNextFile( HANDLE szLocalFolder, WIN32_FIND_DATA *wfdFile );
bool FindClose( HANDLE szLocalFolder );
DWORD SetFilePointer(HANDLE hFile, LONG lDistanceToMove, PLONG lpDistanceToMoveHigh, DWORD dwMoveMethod );
int64_t GetFileSize(HANDLE hFile);
int64_t GetFilePosition(HANDLE hFile);
int64_t Seek(HANDLE hFile, int64_t lOffset, int whence);
HANDLE OpenFile( const char* filename );
long ReadFile(HANDLE fd, uint8_t *pBuffer, long lSize);
void CloseFile(HANDLE hFile);
void Reset();
void Scan();
bool IsScanned();
protected:
void IsoDateTimeToFileTime(iso9660_Datetime* isoDateTime, FILETIME* filetime);
struct iso_dirtree* ReadRecursiveDirFromSector( DWORD sector, const char * );
struct iso_dirtree* FindFolder( char *Folder );
std::string GetThinText(BYTE* strTxt, int iLen );
bool ReadSectorFromCache(iso9660::isofile* pContext, DWORD sector, uint8_t** ppBuffer);
void ReleaseSectorFromCache(iso9660::isofile* pContext, DWORD sector);
const std::string ParseName(struct iso9660_Directory& isodir);
HANDLE AllocFileContext();
void FreeFileContext(HANDLE hFile);
isofile* GetFileContext(HANDLE hFile);
bool IsRockRidge(struct iso9660_Directory& isodir);
struct iso9660info m_info;
std::string m_strReturn;
struct iso9660_Directory m_openfileinfo;
struct iso_dirtree* m_searchpointer;
struct iso_directories* m_paths;
struct iso_directories* m_lastpath;
std::vector<struct iso_dirtree*> m_vecDirsAndFiles;
HANDLE m_hCDROM;
isofile* m_isoFiles[MAX_ISO_FILES];
#define CIRC_BUFFER_SIZE 10
/*
bool m_bUseMode2;
DWORD m_dwCircBuffBegin;
DWORD m_dwCircBuffEnd;
DWORD m_dwCircBuffSectorStart;
DWORD m_dwStartBlock;
DWORD m_dwCurrentBlock; // Current being read Block
int64_t m_dwFilePos;
BYTE* m_pBuffer;
int64_t m_dwFileSize;
*/
};
extern class iso9660 m_isoReader;
#endif
|