mirror of
https://github.com/reactos/reactos.git
synced 2024-10-01 23:14:53 +00:00
[CDMAKE]
- Factor out the code that writes data from a file. - Use BOOL type where needed. svn path=/trunk/; revision=69070
This commit is contained in:
parent
d5ee70e4f0
commit
d8b6cfc7f3
|
@ -166,11 +166,11 @@ DWORD unused_bytes_at_ends_of_files;
|
||||||
DWORD number_of_directories;
|
DWORD number_of_directories;
|
||||||
DWORD bytes_in_directories;
|
DWORD bytes_in_directories;
|
||||||
|
|
||||||
char bootimage[512];
|
|
||||||
BOOL eltorito;
|
BOOL eltorito;
|
||||||
DWORD boot_catalog_sector;
|
DWORD boot_catalog_sector;
|
||||||
DWORD boot_image_sector;
|
DWORD boot_image_sector;
|
||||||
WORD boot_image_size; // counted in 512 byte sectors
|
WORD boot_image_size; // counted in 512 byte sectors
|
||||||
|
char bootimage[512];
|
||||||
|
|
||||||
BOOL joliet;
|
BOOL joliet;
|
||||||
DWORD joliet_path_table_size;
|
DWORD joliet_path_table_size;
|
||||||
|
@ -575,7 +575,7 @@ This function checks to see if there's a cdname conflict.
|
||||||
#define strcasecmp stricmp
|
#define strcasecmp stricmp
|
||||||
#endif//_WIN32
|
#endif//_WIN32
|
||||||
|
|
||||||
int cdname_exists(PDIR_RECORD d)
|
BOOL cdname_exists(PDIR_RECORD d)
|
||||||
{
|
{
|
||||||
PDIR_RECORD p = d->parent->first_record;
|
PDIR_RECORD p = d->parent->first_record;
|
||||||
while (p)
|
while (p)
|
||||||
|
@ -583,10 +583,10 @@ int cdname_exists(PDIR_RECORD d)
|
||||||
if ( p != d
|
if ( p != d
|
||||||
&& !strcasecmp(p->name_on_cd, d->name_on_cd)
|
&& !strcasecmp(p->name_on_cd, d->name_on_cd)
|
||||||
&& !strcasecmp(p->extension_on_cd, d->extension_on_cd) )
|
&& !strcasecmp(p->extension_on_cd, d->extension_on_cd) )
|
||||||
return 1;
|
return TRUE;
|
||||||
p = p->next_in_directory;
|
p = p->next_in_directory;
|
||||||
}
|
}
|
||||||
return 0;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void parse_filename_into_dirrecord(const char* filename, PDIR_RECORD d, BOOL dir)
|
void parse_filename_into_dirrecord(const char* filename, PDIR_RECORD d, BOOL dir)
|
||||||
|
@ -809,7 +809,7 @@ make_directory_records(PDIR_RECORD d)
|
||||||
d->first_record = NULL;
|
d->first_record = NULL;
|
||||||
strcpy(end_source, "*.*");
|
strcpy(end_source, "*.*");
|
||||||
|
|
||||||
findhandle =_findfirst(source, &f);
|
findhandle = _findfirst(source, &f);
|
||||||
if (findhandle != 0)
|
if (findhandle != 0)
|
||||||
{
|
{
|
||||||
do
|
do
|
||||||
|
@ -839,7 +839,7 @@ make_directory_records(PDIR_RECORD d)
|
||||||
}
|
}
|
||||||
|
|
||||||
strcpy(end_source, "*.*");
|
strcpy(end_source, "*.*");
|
||||||
findhandle= _findfirst(source, &f);
|
findhandle = _findfirst(source, &f);
|
||||||
if (findhandle)
|
if (findhandle)
|
||||||
{
|
{
|
||||||
do
|
do
|
||||||
|
@ -1121,14 +1121,14 @@ new_empty_dirrecord(PDIR_RECORD d, BOOL directory)
|
||||||
}
|
}
|
||||||
|
|
||||||
#if _WIN32
|
#if _WIN32
|
||||||
static int
|
static BOOL
|
||||||
get_cd_file_time(HANDLE handle, PDATE_AND_TIME cd_time_info)
|
get_cd_file_time(HANDLE handle, PDATE_AND_TIME cd_time_info)
|
||||||
{
|
{
|
||||||
FILETIME file_time;
|
FILETIME file_time;
|
||||||
SYSTEMTIME sys_time;
|
SYSTEMTIME sys_time;
|
||||||
|
|
||||||
if (!GetFileTime(handle, NULL, NULL, &file_time))
|
if (!GetFileTime(handle, NULL, NULL, &file_time))
|
||||||
return -1;
|
return FALSE;
|
||||||
|
|
||||||
FileTimeToSystemTime(&file_time, &sys_time);
|
FileTimeToSystemTime(&file_time, &sys_time);
|
||||||
memset(cd_time_info, 0, sizeof(*cd_time_info));
|
memset(cd_time_info, 0, sizeof(*cd_time_info));
|
||||||
|
@ -1140,7 +1140,7 @@ get_cd_file_time(HANDLE handle, PDATE_AND_TIME cd_time_info)
|
||||||
cd_time_info->minute = sys_time.wMinute;
|
cd_time_info->minute = sys_time.wMinute;
|
||||||
cd_time_info->second = sys_time.wSecond;
|
cd_time_info->second = sys_time.wSecond;
|
||||||
|
|
||||||
return 0;
|
return TRUE;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -1175,7 +1175,7 @@ scan_specified_files(PDIR_RECORD d, struct target_dir_entry *dir)
|
||||||
error_exit("Can't open timestamp file %s\n", file->source_name);
|
error_exit("Can't open timestamp file %s\n", file->source_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (get_cd_file_time(open_file, &d->date_and_time) == -1)
|
if (!get_cd_file_time(open_file, &d->date_and_time))
|
||||||
{
|
{
|
||||||
error_exit("Can't stat timestamp file %s\n", file->source_name);
|
error_exit("Can't stat timestamp file %s\n", file->source_name);
|
||||||
}
|
}
|
||||||
|
@ -1210,7 +1210,7 @@ scan_specified_files(PDIR_RECORD d, struct target_dir_entry *dir)
|
||||||
{
|
{
|
||||||
error_exit("Can't open file %s\n", file->source_name);
|
error_exit("Can't open file %s\n", file->source_name);
|
||||||
}
|
}
|
||||||
if (get_cd_file_time(open_file, &new_d->date_and_time) == -1)
|
if (!get_cd_file_time(open_file, &new_d->date_and_time))
|
||||||
{
|
{
|
||||||
error_exit("Can't stat file %s\n", file->source_name);
|
error_exit("Can't stat file %s\n", file->source_name);
|
||||||
}
|
}
|
||||||
|
@ -1294,6 +1294,31 @@ static void get_time_string(char *str)
|
||||||
root.date_and_time.second);
|
root.date_and_time.second);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static BOOL write_from_file(FILE *file, DWORD size)
|
||||||
|
{
|
||||||
|
int n;
|
||||||
|
|
||||||
|
fseek(file, 0, SEEK_SET);
|
||||||
|
while (size > 0)
|
||||||
|
{
|
||||||
|
n = BUFFER_SIZE - cd.count;
|
||||||
|
if ((DWORD)n > size)
|
||||||
|
n = size;
|
||||||
|
|
||||||
|
if (fread(cd.buffer + cd.count, n, 1, file) < 1)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
cd.count += n;
|
||||||
|
if (cd.count == BUFFER_SIZE)
|
||||||
|
flush_buffer();
|
||||||
|
cd.sector += n / SECTOR_SIZE;
|
||||||
|
cd.offset += n % SECTOR_SIZE;
|
||||||
|
size -= n;
|
||||||
|
}
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
static void pass(void)
|
static void pass(void)
|
||||||
{
|
{
|
||||||
PDIR_RECORD d;
|
PDIR_RECORD d;
|
||||||
|
@ -1303,16 +1328,15 @@ static void pass(void)
|
||||||
DWORD size;
|
DWORD size;
|
||||||
DWORD number_of_sectors;
|
DWORD number_of_sectors;
|
||||||
char *old_end_source;
|
char *old_end_source;
|
||||||
int n;
|
|
||||||
FILE *file;
|
FILE *file;
|
||||||
char timestring[17];
|
char timestring[17];
|
||||||
|
|
||||||
get_time_string(timestring);
|
get_time_string(timestring);
|
||||||
|
|
||||||
// first 16 sectors are zeros
|
// first 16 sectors are zeros
|
||||||
|
|
||||||
write_block(16 * SECTOR_SIZE, 0);
|
write_block(16 * SECTOR_SIZE, 0);
|
||||||
|
|
||||||
|
|
||||||
// Primary Volume Descriptor
|
// Primary Volume Descriptor
|
||||||
|
|
||||||
write_string("\1CD001\1");
|
write_string("\1CD001\1");
|
||||||
|
@ -1356,7 +1380,6 @@ static void pass(void)
|
||||||
|
|
||||||
|
|
||||||
// Boot Volume Descriptor
|
// Boot Volume Descriptor
|
||||||
|
|
||||||
if (eltorito)
|
if (eltorito)
|
||||||
{
|
{
|
||||||
write_byte(0);
|
write_byte(0);
|
||||||
|
@ -1369,7 +1392,6 @@ static void pass(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Supplementary Volume Descriptor
|
// Supplementary Volume Descriptor
|
||||||
|
|
||||||
if (joliet)
|
if (joliet)
|
||||||
{
|
{
|
||||||
write_string("\2CD001\1");
|
write_string("\2CD001\1");
|
||||||
|
@ -1413,7 +1435,6 @@ static void pass(void)
|
||||||
fill_sector();
|
fill_sector();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Volume Descriptor Set Terminator
|
// Volume Descriptor Set Terminator
|
||||||
write_string("\377CD001\1");
|
write_string("\377CD001\1");
|
||||||
fill_sector();
|
fill_sector();
|
||||||
|
@ -1429,7 +1450,7 @@ static void pass(void)
|
||||||
write_little_endian_word(0); // reserved
|
write_little_endian_word(0); // reserved
|
||||||
write_string("ReactOS Foundation");
|
write_string("ReactOS Foundation");
|
||||||
write_block(6, 0); // padding
|
write_block(6, 0); // padding
|
||||||
write_little_endian_word(0x62E); // checksum
|
write_little_endian_word(0x62E); // checksum // FIXME: This is hardcoded!!
|
||||||
write_little_endian_word(0xAA55); // signature
|
write_little_endian_word(0xAA55); // signature
|
||||||
|
|
||||||
// default entry
|
// default entry
|
||||||
|
@ -1454,29 +1475,16 @@ static void pass(void)
|
||||||
error_exit("Can't open %s\n", bootimage);
|
error_exit("Can't open %s\n", bootimage);
|
||||||
fseek(file, 0, SEEK_END);
|
fseek(file, 0, SEEK_END);
|
||||||
size = ftell(file);
|
size = ftell(file);
|
||||||
fseek(file, 0, SEEK_SET);
|
|
||||||
if (size == 0 || (size % 2048))
|
if (size == 0 || (size % 2048))
|
||||||
{
|
{
|
||||||
fclose(file);
|
fclose(file);
|
||||||
error_exit("Invalid boot image size (%lu bytes)\n", size);
|
error_exit("Invalid boot image size (%lu bytes)\n", size);
|
||||||
}
|
}
|
||||||
boot_image_size = size / 512;
|
boot_image_size = size / 512;
|
||||||
while (size > 0)
|
if (!write_from_file(file, size))
|
||||||
{
|
{
|
||||||
n = BUFFER_SIZE - cd.count;
|
fclose(file);
|
||||||
if ((DWORD) n > size)
|
error_exit("Read error in file %s\n", bootimage);
|
||||||
n = size;
|
|
||||||
if (fread(cd.buffer + cd.count, n, 1, file) < 1)
|
|
||||||
{
|
|
||||||
fclose(file);
|
|
||||||
error_exit("Read error in file %s\n", bootimage);
|
|
||||||
}
|
|
||||||
cd.count += n;
|
|
||||||
if (cd.count == BUFFER_SIZE)
|
|
||||||
flush_buffer();
|
|
||||||
cd.sector += n / SECTOR_SIZE;
|
|
||||||
cd.offset += n % SECTOR_SIZE;
|
|
||||||
size -= n;
|
|
||||||
}
|
}
|
||||||
fclose(file);
|
fclose(file);
|
||||||
// fill_sector();
|
// fill_sector();
|
||||||
|
@ -1581,7 +1589,7 @@ static void pass(void)
|
||||||
fill_sector();
|
fill_sector();
|
||||||
}
|
}
|
||||||
|
|
||||||
// directories and files
|
// Directories and files
|
||||||
for (d = &root; d != NULL; d = d->next_in_path_table)
|
for (d = &root; d != NULL; d = d->next_in_path_table)
|
||||||
{
|
{
|
||||||
// write directory
|
// write directory
|
||||||
|
@ -1652,23 +1660,10 @@ static void pass(void)
|
||||||
file = fopen(file_source, "rb");
|
file = fopen(file_source, "rb");
|
||||||
if (file == NULL)
|
if (file == NULL)
|
||||||
error_exit("Can't open %s\n", file_source);
|
error_exit("Can't open %s\n", file_source);
|
||||||
fseek(file, 0, SEEK_SET);
|
if (!write_from_file(file, size))
|
||||||
while (size > 0)
|
|
||||||
{
|
{
|
||||||
n = BUFFER_SIZE - cd.count;
|
fclose(file);
|
||||||
if ((DWORD) n > size)
|
error_exit("Read error in file %s\n", file_source);
|
||||||
n = size;
|
|
||||||
if (fread(cd.buffer + cd.count, n, 1, file) < 1)
|
|
||||||
{
|
|
||||||
fclose(file);
|
|
||||||
error_exit("Read error in file %s\n", file_source);
|
|
||||||
}
|
|
||||||
cd.count += n;
|
|
||||||
if (cd.count == BUFFER_SIZE)
|
|
||||||
flush_buffer();
|
|
||||||
cd.sector += n / SECTOR_SIZE;
|
|
||||||
cd.offset += n % SECTOR_SIZE;
|
|
||||||
size -= n;
|
|
||||||
}
|
}
|
||||||
fclose(file);
|
fclose(file);
|
||||||
end_source = old_end_source;
|
end_source = old_end_source;
|
||||||
|
|
Loading…
Reference in a new issue