2006-09-20 21:47:43 +00:00
|
|
|
static __attribute__((used)) char* rcsid = "$CVSHeader$";
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
* (c) 2004-2006 Laurent Vivier <Laurent@lvivier.info>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
|
|
|
#include "libemile.h"
|
|
|
|
#include "emile.h"
|
|
|
|
|
2006-10-20 17:12:30 +00:00
|
|
|
int emile_first_set_param_scsi_extents( int fd, int drive_num, int second_offset, int size, int blocksize)
|
2006-09-20 21:47:43 +00:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
char first[1024];
|
|
|
|
int current;
|
|
|
|
unsigned short max_blocks;
|
|
|
|
int location;
|
|
|
|
|
|
|
|
location = lseek(fd, 0, SEEK_CUR);
|
|
|
|
if (location == -1)
|
|
|
|
return EEMILE_CANNOT_READ_FIRST;
|
|
|
|
|
|
|
|
ret = read(fd, first, 1024);
|
|
|
|
if (ret == -1)
|
|
|
|
return EEMILE_CANNOT_READ_FIRST;
|
|
|
|
|
|
|
|
max_blocks = read_short((u_int16_t*)&first[1022]) / 6;
|
|
|
|
|
2006-10-20 17:12:30 +00:00
|
|
|
write_short((u_int16_t*)&first[1014], blocksize);
|
2006-09-20 21:47:43 +00:00
|
|
|
write_short((u_int16_t*)&first[1016], drive_num);
|
|
|
|
|
|
|
|
write_long((u_int32_t*)&first[1018], 0);
|
|
|
|
current = 1014;
|
|
|
|
|
|
|
|
current -= 2;
|
2006-10-20 17:12:30 +00:00
|
|
|
write_short((u_int16_t*)&first[current], (size + blocksize - 1) / blocksize);
|
2006-09-20 21:47:43 +00:00
|
|
|
current -= 4;
|
|
|
|
write_long((u_int32_t*)&first[current], second_offset);
|
|
|
|
|
|
|
|
/* mark end of blocks list */
|
|
|
|
current -= 2;
|
|
|
|
write_short((u_int16_t*)(&first[current]), 0);
|
|
|
|
/* set second level size */
|
2006-10-20 17:12:30 +00:00
|
|
|
write_long((u_int32_t*)&first[1018], (size + blocksize - 1) / blocksize * blocksize);
|
2006-09-20 21:47:43 +00:00
|
|
|
|
|
|
|
ret = lseek(fd, location, SEEK_SET);
|
2006-09-20 22:41:42 +00:00
|
|
|
if (ret != location)
|
2006-09-20 21:47:43 +00:00
|
|
|
return EEMILE_CANNOT_WRITE_FIRST;
|
|
|
|
|
|
|
|
ret = write(fd, first, 1024);
|
|
|
|
if (ret == -1)
|
|
|
|
return EEMILE_CANNOT_WRITE_FIRST;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|