use EMILE error codes

This commit is contained in:
Laurent Vivier 2004-12-12 22:59:38 +00:00
parent 6a61e404d1
commit 4dc4058c13
11 changed files with 57 additions and 80 deletions

View File

@ -22,7 +22,7 @@ int emile_first_get_param(int fd, int *drive_num, int *second_offset,
ret = read(fd, &firstBlock, sizeof(firstBlock));
if (ret != sizeof(firstBlock))
return -1;
return EEMILE_CANNOT_READ_FIRST;
if ( strncmp( firstBlock.boot_block_header.SysName+1,
"Mac Bootloader", 14) == 0 )
@ -32,7 +32,7 @@ int emile_first_get_param(int fd, int *drive_num, int *second_offset,
*second_size = read_long(&firstBlock.second_param_block.ioReqCount);
}
else
return -1;
return EEMILE_UNKNOWN_FIRST;
return 0;
}

View File

@ -23,11 +23,11 @@ int emile_first_set_param(int fd, unsigned short tune_mask, int drive_num,
location = lseek(fd, 0, SEEK_CUR);
if (location == -1)
return -1;
return EEMILE_CANNOT_READ_FIRST;
ret = read(fd, &firstBlock, sizeof(firstBlock));
if (ret != sizeof(firstBlock))
return -1;
return EEMILE_CANNOT_READ_FIRST;
if ( strncmp( firstBlock.boot_block_header.SysName+1,
"Mac Bootloader", 14) == 0 )
@ -46,14 +46,14 @@ int emile_first_set_param(int fd, unsigned short tune_mask, int drive_num,
ret = lseek(fd, location, SEEK_SET);
if (ret != 0)
return -1;
return EEMILE_CANNOT_WRITE_FIRST;
ret = write(fd, &firstBlock, sizeof(firstBlock));
if (ret != sizeof(firstBlock))
return -1;
return EEMILE_CANNOT_WRITE_FIRST;
}
else
return -1;
return EEMILE_UNKNOWN_FIRST;
return 0;
}

View File

@ -31,7 +31,7 @@ int emile_first_set_param_scsi(int fd, char *second_name)
ret = read(fd, first, 1024);
if (ret == -1)
return 1;
return EEMILE_CANNOT_READ_FIRST;
max_blocks = *first_max_blocks / 6;
@ -39,16 +39,16 @@ int emile_first_set_param_scsi(int fd, char *second_name)
malloc(sizeof(struct emile_container)
+ max_blocks * sizeof(struct emile_block));
if (container == NULL)
return -1;
return EEMILE_MALLOC_ERROR;
container->max_blocks = max_blocks;
fd_second = open(second_name, O_RDONLY);
if (fd_second == -1)
return -1;
return EEMILE_CANNOT_OPEN_FILE;
ret = emile_scsi_create_container(fd_second, container);
if (ret != 0)
return -1;
return ret;
close(fd_second);
*unit_id = container->unit_id;
@ -77,11 +77,11 @@ int emile_first_set_param_scsi(int fd, char *second_name)
ret = lseek(fd, 0, SEEK_SET);
if (ret != 0)
return -1;
return EEMILE_CANNOT_WRITE_FIRST;
ret = write(fd, first, 1024);
if (ret == -1)
return 1;
return EEMILE_CANNOT_WRITE_FIRST;
return ret;
return 0;
}

View File

@ -24,14 +24,11 @@ static int copy_file(int fd, char* file)
int total;
static char buffer[FLOPPY_SECTOR_SIZE];
if (fd < 0)
return -1;
source = open(file, O_RDONLY);
if (source < 0)
{
close(source);
return -1;
return EEMILE_CANNOT_OPEN_FILE;
}
total = 0;
@ -75,9 +72,6 @@ static int pad_image(int fd, int size)
int size_written;
int total;
if (fd < 0)
return -1;
if (size % FLOPPY_SECTOR_SIZE) {
fprintf(stderr,
"WARNING: pad size is not a multiple of sector size\n");
@ -103,19 +97,19 @@ static int aggregate(int fd, char* first_level, char* second_level, char* kernel
ret = copy_file(fd, first_level);
if (ret < 0)
return 6;
return EEMILE_CANNOT_WRITE_FIRST;
total = ret;
ret = copy_file(fd, second_level);
if (ret < 0)
return 6;
return EEMILE_CANNOT_WRITE_SECOND;
total += ret;
if (kernel_image != NULL)
{
ret = copy_file(fd, kernel_image);
if (ret < 0)
return 6;
return EEMILE_CANNOT_WRITE_KERNEL;
total += ret;
}
@ -123,13 +117,13 @@ static int aggregate(int fd, char* first_level, char* second_level, char* kernel
{
ret = copy_file(fd, ramdisk);
if (ret < 0)
return 6;
return EEMILE_CANNOT_WRITE_RAMDISK;
total += ret;
}
ret = pad_image(fd, 1474560 - total);
if (ret < 0)
return 6;
return EEMILE_CANNOT_WRITE_PAD;
return 0;
}
@ -148,20 +142,20 @@ int emile_floppy_create_image(char* first_level, char* second_level,
fd = open(image, O_RDWR|O_CREAT|O_TRUNC,
S_IRUSR| S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
if (fd == -1)
return -1;
return EEMILE_CANNOT_CREATE_IMAGE;
/* aggregating files: first, second, kernel, ramdisk */
if (first_level == NULL)
{
close(fd);
return -1;
return EEMILE_MISSING_FIRST;
}
if (second_level == NULL)
{
close(fd);
return -1;
return EEMILE_MISSING_SECOND;
}
if (kernel_image == NULL)
@ -171,11 +165,12 @@ int emile_floppy_create_image(char* first_level, char* second_level,
if (ret != 0)
{
close(fd);
return -1;
return ret;
}
/* set first level info */
lseek(fd, 0, SEEK_SET);
ret = emile_first_set_param(fd, EMILE_FIRST_TUNE_DRIVE |
EMILE_FIRST_TUNE_OFFSET|
EMILE_FIRST_TUNE_SIZE,
@ -184,7 +179,7 @@ int emile_floppy_create_image(char* first_level, char* second_level,
if (ret != 0)
{
close(fd);
return -1;
return ret;
}
/* set second level info */
@ -193,13 +188,8 @@ int emile_floppy_create_image(char* first_level, char* second_level,
FIRST_LEVEL_SIZE +
emile_file_get_size(second_level),
buffer_size, ramdisk);
if (ret != 0)
{
close(fd);
return -1;
}
close(fd);
return 0;
return ret;
}

View File

@ -21,12 +21,12 @@ int emile_second_get_cmdline(int fd, char* cmdline)
ret = read(fd, &header, sizeof(header));
if (ret != sizeof(header))
return -1;
return EEMILE_CANNOT_READ_SECOND;
if (!EMILE_COMPAT(EMILE_02_SIGNATURE, read_long(&header.signature)))
{
fprintf(stderr, "Bad Header signature\n");
return -1;
return EEMILE_INVALID_SECOND;
}
strncpy(cmdline, header.command_line, 256);

View File

@ -22,7 +22,7 @@ int emile_second_get_kernel(int fd, u_int32_t *kernel_offset,
ret = read(fd, &header, sizeof(header));
if (ret != sizeof(header))
return -1;
return EEMILE_CANNOT_READ_SECOND;
*kernel_offset = read_long(&header.kernel_image_offset);
*kernel_image_size = read_long(&header.kernel_image_size);

View File

@ -26,13 +26,10 @@ int emile_second_get_output(int fd, unsigned int *console_mask,
ret = read(fd, &header, sizeof(header));
if (ret != sizeof(header))
return -1;
return EEMILE_CANNOT_READ_SECOND;
if (!EMILE_COMPAT(EMILE_03_SIGNATURE, read_long(&header.signature)))
{
fprintf(stderr, "Bad Header signature\n");
return -1;
}
return EEMILE_INVALID_SECOND;
*console_mask = read_long(&header.console_mask);
*bitrate0 = read_long(&header.serial0_bitrate);

View File

@ -22,28 +22,25 @@ int emile_second_set_cmdline(int fd, char* cmdline)
location = lseek(fd, 0, SEEK_CUR);
if (ret == -1)
return -1;
return EEMILE_CANNOT_READ_SECOND;
ret = read(fd, &header, sizeof(header));
if (ret != sizeof(header))
return -1;
return EEMILE_CANNOT_READ_SECOND;
if (!EMILE_COMPAT(EMILE_02_SIGNATURE, read_long(&header.signature)))
{
fprintf(stderr, "Bad Header signature\n");
return -1;
}
return EEMILE_INVALID_SECOND;
strncpy(header.command_line, cmdline, 256);
header.command_line[255] = 0;
ret = lseek(fd, location, SEEK_SET);
if (ret == -1)
return -1;
return EEMILE_CANNOT_WRITE_SECOND;
ret = write(fd, &header, sizeof(header));
if (ret != sizeof(header))
return -1;
return EEMILE_CANNOT_WRITE_SECOND;
return 0;
}

View File

@ -23,11 +23,11 @@ int emile_second_set_kernel(int fd, char *kernel_image,
location = lseek(fd, 0, SEEK_CUR);
if (ret == -1)
return -1;
return EEMILE_CANNOT_READ_SECOND;
ret = read(fd, &header, sizeof(header));
if (ret != sizeof(header))
return -1;
return EEMILE_CANNOT_READ_SECOND;
if (kernel_image != NULL)
{
@ -53,11 +53,11 @@ int emile_second_set_kernel(int fd, char *kernel_image,
ret = lseek(fd, location, SEEK_SET);
if (ret == -1)
return -1;
return EEMILE_CANNOT_WRITE_SECOND;
ret = write(fd, &header, sizeof(header));
if (ret != sizeof(header))
return -1;
return EEMILE_CANNOT_WRITE_SECOND;
return 0;
}

View File

@ -28,10 +28,10 @@ int emile_second_set_kernel_scsi(int fd, char *kernel_name)
ret = read(fd, &header, sizeof(header));
if (ret != sizeof(header))
return -1;
return EEMILE_CANNOT_READ_SECOND;
if (!EMILE_COMPAT(EMILE_04_SIGNATURE, read_long(&header.signature)))
return -1;
return EEMILE_INVALID_SECOND;
container_offset = read_long(&header.kernel_image_offset);
if (container_offset == 0)
@ -39,16 +39,16 @@ int emile_second_set_kernel_scsi(int fd, char *kernel_name)
ret = lseek(fd, container_offset, SEEK_SET);
if (ret != container_offset)
return -1;
return EEMILE_CANNOT_READ_SECOND;
container = (struct emile_container*)
malloc(sizeof(struct emile_container));
if (container == NULL)
return -1;
return EEMILE_MALLOC_ERROR;
ret = read(fd, container, sizeof(struct emile_container));
if (ret != sizeof(struct emile_container))
return -1;
return EEMILE_CANNOT_READ_SECOND;
max_blocks = container->max_blocks;
@ -57,16 +57,16 @@ int emile_second_set_kernel_scsi(int fd, char *kernel_name)
malloc(sizeof(struct emile_container)
+ max_blocks * sizeof(struct emile_block));
if (container == NULL)
return -1;
return EEMILE_MALLOC_ERROR;
container->max_blocks = max_blocks;
fd_kernel = open(kernel_name, O_RDONLY);
if (fd_kernel == -1)
return -1;
return EEMILE_CANNOT_READ_KERNEL;
ret = emile_scsi_create_container(fd_kernel, container);
if (ret != 0)
return 10;
return ret;
close(fd_kernel);
kernel_image_size = 0;
@ -80,13 +80,13 @@ int emile_second_set_kernel_scsi(int fd, char *kernel_name)
ret = lseek(fd, container_offset, SEEK_SET);
if (ret != container_offset)
return -1;
return EEMILE_CANNOT_WRITE_SECOND;
ret = write(fd, container, sizeof(struct emile_container)
+ max_blocks * sizeof(struct emile_block));
if (ret != sizeof(struct emile_container)
+ max_blocks * sizeof(struct emile_block))
return -1;
return EEMILE_CANNOT_WRITE_SECOND;
ret = lseek(fd, 0, SEEK_SET);
if (ret != 0)
@ -96,7 +96,7 @@ int emile_second_set_kernel_scsi(int fd, char *kernel_name)
ret = write(fd, &header, sizeof(header));
if (ret != sizeof(header))
return -2;
return EEMILE_CANNOT_WRITE_SECOND;
return 0;
}

View File

@ -27,17 +27,14 @@ int emile_second_set_output(int fd, unsigned int enable_mask,
location = lseek(fd, 0, SEEK_CUR);
if (location == -1)
return location;
return EEMILE_CANNOT_READ_SECOND;
ret = read(fd, &header, sizeof(header));
if (ret != sizeof(header))
return -1;
return EEMILE_CANNOT_READ_SECOND;
if (!EMILE_COMPAT(EMILE_03_SIGNATURE, read_long(&header.signature)))
{
fprintf(stderr, "Bad Header signature\n");
return -1;
}
return EEMILE_INVALID_SECOND;
header.console_mask |= enable_mask;
header.console_mask &= ~disable_mask;
@ -66,15 +63,11 @@ int emile_second_set_output(int fd, unsigned int enable_mask,
ret = lseek(fd, location, SEEK_SET);
if (ret == -1)
{
perror("Cannot go to buffer offset");
close(fd);
return 8;
}
return EEMILE_CANNOT_WRITE_SECOND;
ret = write(fd, &header, sizeof(header));
if (ret != sizeof(header))
return -1;
return EEMILE_CANNOT_WRITE_SECOND;
return 0;
}