📄 iso9660.c
字号:
/*C**************************************************************************
* NAME: iso9660.c
*----------------------------------------------------------------------------
* Copyright (c) 2003 Atmel.
*----------------------------------------------------------------------------
* RELEASE: snd1c-refd-nf-4_0_3
* REVISION: 1.3
*----------------------------------------------------------------------------
* PURPOSE:
* ISO9660 file-system basics functions
*
* NOTES:
* Some variables are shared with fat.c module :
* data Uint32 fat_ptr_data
* data Uint16 fat_fclust_byte_count
* idata Uint16 fat_dclust_byte_count
* idata Uint32 fat_dir_current_sect
* idata Uint16 fat_dir_list_index
* xdata char ext[]
* xdata Byte fat_buf_sector[]
* Global variable :
* pdata Byte gl_buffer[]
*
*****************************************************************************/
/*_____ I N C L U D E S ____________________________________________________*/
#include "config.h" /* system configuration */
#include "..\mem\hard.h" /* low level function definition */
#include "file.h" /* file function definition */
#include "iso9660.h" /* iso9660 file-system definition */
/*_____ M A C R O S ________________________________________________________*/
/*_____ D E F I N I T I O N ________________________________________________*/
/* shared variables with fat.c module */
extern data Uint32 fat_ptr_data;
extern data Uint16 fat_fclust_byte_count;
extern idata Uint16 fat_dclust_byte_count;
extern idata Uint32 fat_dir_current_sect;
extern xdata Uint16 fat_dir_list_index;
extern xdata char ext[];
extern xdata Byte fat_buf_sector[];
extern pdata Byte gl_buffer[];
extern xdata Uint32 fat_dir_start_sect;
extern xdata Uint16 fat_dir_list_last;
extern xdata Byte current_ext;
extern idata Uint16 fat_dchain_index;
extern idata Uint16 fat_fchain_nb_clust;
extern xdata Byte fat_fchain_index_save;
extern xdata Byte fat_fchain_nb_clust_save;
extern xdata Uint16 fat_fclust_byte_count_save;
#define iso_dir_current_sect fat_dir_current_sect
#define iso_dir_byte_count fat_dclust_byte_count
#define iso_f_current_sect fat_ptr_data
#define iso_current_byte_counter fat_fclust_byte_count
#define iso_current_dir_file fat_buf_sector
#define iso_file_index fat_dir_list_index
#define iso_file_max_index fat_dir_list_last
#define iso_dir_start_sect fat_dir_start_sect
#define iso_dir_size fat_dchain_index
#define iso_f_nb_sector_save fat_fclust_byte_count_save
#define iso_f_nb_byte_save fat_fchain_nb_clust
extern char pdata *lfn_name; /* long filename limited to MAX_FILENAME_LEN chars */
extern xdata iso_VolumeDescriptor iso_header; /* iso header informations */
extern xdata iso_cache iso_file_cache; /* cache for the current file */
extern idata Uint16 iso_f_nb_sector;
extern idata Uint16 iso_f_max_sector;
extern bdata bit iso_cd; /* if set to one cd is iso else cd is joliet format */
/*_____ D E C L A R A T I O N ______________________________________________*/
Uint16 iso_dgetw(void);
/*F**************************************************************************
* NAME: fat_install
*----------------------------------------------------------------------------
* PARAMS:
*
* return:
* - OK: intallation succeeded
* - KO: no primary or supplementary volume descriptor found
*
*----------------------------------------------------------------------------
* PURPOSE:
* Install the iso file system
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
*
*----------------------------------------------------------------------------
* REQUIREMENTS:
*****************************************************************************/
bit iso_install(void)
{
iso_f_current_sect = Hard_iso_read_toc() + 1 + 16;
iso_cd = 0;
if (Hard_iso_read_open(iso_f_current_sect) == OK)
{
if ((Hard_iso_read_word() & 0xFF) == 0x01) /* ISO CD */
{
iso_f_current_sect--;
iso_cd = 1;
}
Hard_iso_read_close();
}
if (iso_read_volume_descriptor(iso_f_current_sect) == OK) /* read volume descriptor */
return OK;
else
return KO;
}
/*F**************************************************************************
* NAME: iso_read_volume_descriptor
*----------------------------------------------------------------------------
* PARAMS:
* sector: firt sector of ISO block location
* return:
* - OK: intallation succeeded
* - KO: error
*----------------------------------------------------------------------------
* PURPOSE:
* Read CD volumes descriptors.
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
*
*----------------------------------------------------------------------------
* REQUIREMENTS:
*****************************************************************************/
bit iso_read_volume_descriptor (Uint32 sector)
{
Byte i;
Uint16 tmp_word;
/* settting current offset */
iso_dir_current_sect = sector;
if (Hard_iso_read_open(iso_dir_current_sect) == OK)
{
/* Byte 1 - 2 : Volume descriptor type & Standard identifier */
/* Byte 3 - 4 : Standard identifier */
/* Byte 5 - 6 : Standard identifier */
/* Standard identifier is 'CD001' */
tmp_word = Hard_iso_read_word();
if ( (((Byte*)&tmp_word)[0] != 0x43) || /* check if it is a standard iso cd volume */
(Hard_iso_read_word() != 0x3044) || /* string 0D */
(Hard_iso_read_word() != 0x3130)) /* string 10 */
{
Hard_iso_read_close();
return KO;
}
switch (((Byte*)&tmp_word)[1])
{
case TYPE_BOOT_RECORD: /* Boot record */
{
break;
}
case TYPE_PRIMARY_VD: /* Primary Volume Descriptor or */
case TYPE_SUPPLEMENTARY_VD: /* Supplementary Volume Descriptor */
{
i = 3;
while (i != 40)
{
Hard_iso_read_word(); /* dummy read */
i++;
}
iso_header.volume_size = Hard_iso_read_word(); /* Byte 81 - 82 */
iso_header.volume_size += ((Uint32)(Hard_iso_read_word()) << 16); /* Byte 83 - 84 */
Hard_iso_read_word(); /* Byte 85 - 86 */
Hard_iso_read_word(); /* Byte 87 - 88 */
i = 44;
while (i != 64)
{
Hard_iso_read_word(); /* dummy read */
i++;
}
/* Byte 129 - 132 : Logical Block Size - Both byte order */
iso_header.logical_block_size = Hard_iso_read_word();
Hard_iso_read_word();
while (i != 76)
{
tmp_word = Hard_iso_read_word(); /* dummy read */
i++;
}
/* Byte 157 - 190 : Directory record for root directory */
/* Sbyte 1 : Length of directoy record */
/* Sbyte 2 : Extended attribute record length */
iso_header.root.length = (Hard_iso_read_word() & 0xFF);
/* Sbyte 3 - 10 : Location of extent - Both byte order */
iso_header.root.extend_location = Hard_iso_read_word();
iso_header.root.extend_location += ((Uint32)(Hard_iso_read_word()) << 16);
Hard_iso_read_word();
Hard_iso_read_word();
/* Sbyte 11 - 18 : Data Length - Both Byte order */
iso_header.root.data_length = Hard_iso_read_word();
iso_header.root.data_length += ((Uint32)(Hard_iso_read_word()) << 16);
iso_dir_size = iso_header.root.data_length / iso_header.logical_block_size;
break;
}
case TYPE_PARTITION_VD: /* Partition Volume Descriptor */
{
break;
}
case TYPE_VOLUME_SET_TERMINATOR: /* Volume set terminator */
{
break;
}
default: /* error */
{
return KO;
}
}
Hard_iso_read_close();
return OK;
}
else
return KO;
}
/*F**************************************************************************
* NAME: iso_fseek
*----------------------------------------------------------------------------
* PARAMS:
* offset: relative signed seek offset in file
*
* return:
* seek status: - OK: seek done
* - KO: out of file seek
*----------------------------------------------------------------------------
* PURPOSE:
* Change file pointer of an openned file
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
* Seek is done with byte boundary
*----------------------------------------------------------------------------
* REQUIREMENTS:
*****************************************************************************/
bit iso_fseek(Int16 offset)
{
Uint16 i; /* generic counter */
Uint32 file_pos;
file_pos = ((iso_f_current_sect - iso_file_cache.info.extend_location) * iso_header.logical_block_size)
+ (Uint32)(iso_current_byte_counter);
if ((file_pos + offset) < 0)
return KO;
file_pos += offset;
iso_f_nb_sector = (file_pos / iso_header.logical_block_size);
iso_f_current_sect = (Uint32)(iso_f_nb_sector) + iso_file_cache.info.extend_location;
iso_current_byte_counter = ((Uint16)file_pos % iso_header.logical_block_size);
Hard_iso_read_close();
Hard_iso_read_open(iso_f_current_sect);
for (i = 0; i < iso_current_byte_counter; i++)
{
Hard_iso_read_byte();
}
return OK;
}
/*F**************************************************************************
* NAME: iso_fseek_abs
*----------------------------------------------------------------------------
* PARAMS:
* offset: absolute seek offset in file
*
* return:
*----------------------------------------------------------------------------
* PURPOSE:
* Move ahead file read pointer of an openned file
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
*----------------------------------------------------------------------------
* REQUIREMENTS:
*****************************************************************************/
bit iso_fseek_abs(Uint32 offset)
{
Uint16 i; /* generic counter */
iso_f_nb_sector = (Uint16)(offset / iso_header.logical_block_size);
iso_current_byte_counter = (Uint16)(offset % iso_header.logical_block_size);
iso_f_current_sect = (Uint32)(iso_f_nb_sector) + iso_file_cache.info.extend_location;
Hard_iso_read_close();
Hard_iso_read_open(iso_f_current_sect);
for (i = 0; i < iso_current_byte_counter; i++)
{
Hard_iso_read_byte();
}
return OK;
}
/*F**************************************************************************
* NAME: iso_dseek
*----------------------------------------------------------------------------
* PARAMS:
* offset: offset to current position in signed word value
*
* return:
*----------------------------------------------------------------------------
* PURPOSE:
* Seek from the current position to a new offset computing relative
* poisition +/- scan size limited to a 16 bit offset
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
*
*----------------------------------------------------------------------------
* REQUIREMENTS:
*****************************************************************************/
bit iso_dseek(Int16 offset)
{
Uint16 i; /* generic counter */
Uint32 dir_pos;
dir_pos = ((iso_dir_current_sect - iso_header.root.extend_location) * iso_header.logical_block_size)
+ iso_dir_byte_count;
if ((dir_pos + offset) < 0)
return KO;
dir_pos += offset;
iso_dir_current_sect = (dir_pos / iso_header.logical_block_size)
+ iso_header.root.extend_location;
iso_dir_byte_count = dir_pos % iso_header.logical_block_size;
Hard_iso_read_close();
Hard_iso_read_open(iso_dir_current_sect);
for (i = 0; i < iso_dir_byte_count; i++)
{
Hard_iso_read_byte();
}
return OK;
}
/*F**************************************************************************
* NAME: iso_get_file_dir
*----------------------------------------------------------------------------
* PARAMS:
*
* return:
*----------------------------------------------------------------------------
* PURPOSE:
* Give information about the directory :
* - total number of entries
*----------------------------------------------------------------------------
* EXAMPLE:
*
*----------------------------------------------------------------------------
* NOTE:
*
*----------------------------------------------------------------------------
* REQUIREMENTS:
*
*****************************************************************************/
void iso_get_file_dir(void)
{
Byte attributes;
Byte len;
Byte i;
Byte j;
Byte k;
Byte entry_len;
Byte tmp_byte;
Byte byte_to_read;
Byte padding_byte;
Byte entry_rel;
Uint16 tmp_word;
bit no_more_entry;
bit end_of_name;
no_more_entry = FALSE;
entry_rel = 0;
fat_dir_list_index = 0;
do
{
padding_byte = 0;
do
{
tmp_word = iso_dgetw();
padding_byte++;
if ((iso_dir_current_sect - iso_dir_start_sect) >= iso_dir_size)
{
no_more_entry = TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -