2009-10-19 22:14:08 +02:00
|
|
|
/*
|
|
|
|
|
|
|
|
File: iso.c
|
|
|
|
|
|
|
|
Copyright (C) 2009 Christophe GRENIER <grenier@cgsecurity.org>
|
|
|
|
|
|
|
|
This software 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 of the License, 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 this program; if not, write the Free Software Foundation, Inc., 51
|
|
|
|
Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
#include <stdio.h>
|
|
|
|
#ifdef HAVE_STDLIB_H
|
|
|
|
#include <stdlib.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
#include <string.h>
|
|
|
|
#endif
|
|
|
|
#include "types.h"
|
|
|
|
#include "common.h"
|
2009-10-25 18:29:16 +01:00
|
|
|
#include "iso9660.h"
|
2009-10-19 22:14:08 +02:00
|
|
|
#include "iso.h"
|
|
|
|
#include "fnctdsk.h"
|
|
|
|
#include "log.h"
|
|
|
|
#include "guid_cpy.h"
|
|
|
|
|
2021-11-20 11:26:50 +01:00
|
|
|
/*@
|
|
|
|
@ requires \valid_read(iso);
|
|
|
|
@ requires \valid(partition);
|
|
|
|
@ requires valid_partition(partition);
|
|
|
|
@ requires \separated(iso, partition);
|
|
|
|
@*/
|
2016-01-23 10:14:22 +01:00
|
|
|
static void set_ISO_info(const struct iso_primary_descriptor *iso, partition_t *partition);
|
2009-10-19 22:14:08 +02:00
|
|
|
|
2021-11-20 11:26:50 +01:00
|
|
|
/*@
|
|
|
|
@ requires \valid_read(iso);
|
|
|
|
@ assigns \nothing;
|
|
|
|
@*/
|
2016-01-23 10:14:22 +01:00
|
|
|
static int test_ISO(const struct iso_primary_descriptor *iso)
|
2009-11-01 11:18:54 +01:00
|
|
|
{
|
|
|
|
static const unsigned char iso_header[6]= { 0x01, 'C', 'D', '0', '0', '1'};
|
|
|
|
if(memcmp(iso, iso_header, sizeof(iso_header))!=0)
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-10-19 22:14:08 +02:00
|
|
|
int check_ISO(disk_t *disk_car, partition_t *partition)
|
|
|
|
{
|
|
|
|
unsigned char *buffer=(unsigned char*)MALLOC(ISO_PD_SIZE);
|
|
|
|
if(disk_car->pread(disk_car, buffer, ISO_PD_SIZE, partition->part_offset + 64 * 512) != ISO_PD_SIZE)
|
|
|
|
{
|
|
|
|
free(buffer);
|
|
|
|
return 1;
|
|
|
|
}
|
2016-01-23 10:14:22 +01:00
|
|
|
if(test_ISO((struct iso_primary_descriptor*)buffer)!=0)
|
2009-10-19 22:14:08 +02:00
|
|
|
{
|
|
|
|
free(buffer);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
set_ISO_info((struct iso_primary_descriptor*)buffer, partition);
|
|
|
|
free(buffer);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-01-23 10:14:22 +01:00
|
|
|
static void set_ISO_info(const struct iso_primary_descriptor *iso, partition_t *partition)
|
2009-10-19 22:14:08 +02:00
|
|
|
{
|
2020-09-14 18:38:12 +02:00
|
|
|
const unsigned int volume_space_size_le=le32(iso->volume_space_size_le);
|
|
|
|
const unsigned int volume_space_size_be=be32(iso->volume_space_size_be);
|
|
|
|
const unsigned int logical_block_size_le=le16(iso->logical_block_size_le);
|
|
|
|
const unsigned int logical_block_size_be=be16(iso->logical_block_size_be);
|
2016-01-23 10:14:22 +01:00
|
|
|
partition->upart_type=UP_ISO;
|
2023-08-25 16:45:59 +02:00
|
|
|
set_part_name_chomp(partition, (const char*)iso->volume_id, 32);
|
2020-09-14 18:38:12 +02:00
|
|
|
if(volume_space_size_le==volume_space_size_be && logical_block_size_le==logical_block_size_be)
|
2012-04-21 14:14:54 +02:00
|
|
|
{
|
2020-09-14 18:38:12 +02:00
|
|
|
partition->blocksize=logical_block_size_le;
|
2012-08-12 20:29:39 +02:00
|
|
|
snprintf(partition->info, sizeof(partition->info),
|
|
|
|
"ISO9660 blocksize=%u", partition->blocksize);
|
2012-04-21 14:14:54 +02:00
|
|
|
}
|
2009-10-19 22:14:08 +02:00
|
|
|
else
|
|
|
|
snprintf(partition->info, sizeof(partition->info), "ISO");
|
|
|
|
}
|
|
|
|
|
2012-04-15 11:23:48 +02:00
|
|
|
int recover_ISO(const struct iso_primary_descriptor *iso, partition_t *partition)
|
2009-10-19 22:14:08 +02:00
|
|
|
{
|
2016-01-23 10:14:22 +01:00
|
|
|
if(test_ISO(iso)!=0)
|
2009-10-19 22:14:08 +02:00
|
|
|
return 1;
|
|
|
|
set_ISO_info(iso, partition);
|
|
|
|
{
|
2020-09-14 18:38:12 +02:00
|
|
|
const unsigned int volume_space_size_le=le32(iso->volume_space_size_le);
|
|
|
|
const unsigned int volume_space_size_be=be32(iso->volume_space_size_be);
|
|
|
|
const unsigned int logical_block_size_le=le16(iso->logical_block_size_le);
|
|
|
|
const unsigned int logical_block_size_be=be16(iso->logical_block_size_be);
|
|
|
|
if(volume_space_size_le==volume_space_size_be && logical_block_size_le==logical_block_size_be)
|
2009-10-19 22:14:08 +02:00
|
|
|
{ /* ISO 9660 */
|
2020-09-14 18:38:12 +02:00
|
|
|
partition->part_size=(uint64_t)volume_space_size_le * logical_block_size_le;
|
2009-10-19 22:14:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|