Commit 997be073 authored by Andrey Filippov's avatar Andrey Filippov

debugging, tested status files fro raw recording

parent c78bbfc2
......@@ -2454,7 +2454,7 @@ int main(int argc, char *argv[])
strncpy(sstate.rawdev.state_path, (const char *)state_name_str, str_len + 1);
}
ret = get_state_directory(&sstate);
ret = getup_state_files(&sstate);
D2(syslog (LOG_INFO, "%s:line %d : get_state_directory() -> %d @ %07d\n", \
__FILE__, __LINE__, ret, get_fpga_usec(sstate.fd_fparmsall[0], 0)));
......
......@@ -202,7 +202,19 @@ static int find_state(FILE *f, uint64_t *pos, const rawdev_buffer *rawdev)
return -3;
}
int get_state_directory(camogm_state *state) { //rawdev_buffer *rawdev){
int get_dir_path(char* file_path, char* directory){ // directory should be allocated, returns w/o trailing '/'
// int dirlen;
char * cp;
strncpy(directory, file_path, ELPHEL_PATH_MAX); // rawdev->state_path is always absolute
cp=strrchr(directory,'/');
if (!cp) {
return -1; // no '/'
}
*cp=0; // truncate at '_'
return strlen(directory);
}
int getup_state_files(camogm_state *state) { //rawdev_buffer *rawdev){
rawdev_buffer *rawdev = &state->rawdev;
int dirlen, preflen; // length of directory path including trailing '/'
char * cp;
......@@ -213,20 +225,22 @@ int get_state_directory(camogm_state *state) { //rawdev_buffer *rawdev){
struct dirent *dir;
struct stat fstat;
__time_t tsec = 0;
strncpy(state_directory, rawdev->state_path, ELPHEL_PATH_MAX);
#if 0
strncpy(state_directory, rawdev->state_path, ELPHEL_PATH_MAX); // rawdev->state_path is always absolute
cp=strrchr(state_directory,'/');
if (!cp) {
return -1;
}
*cp=0; // truncate
dirlen = strlen(state_directory);
#endif
dirlen = get_dir_path(rawdev->state_path, state_directory);
preflen = dirlen+1; // counts '/'
strcpy(pathname,state_directory);
cp = pathname + dirlen;
*cp = '/';
cp++;
*cp=0;
// return rawdev->state_directory;
// get latest
strcpy(rawdev->state_prefix, state_directory);
......@@ -275,17 +289,37 @@ int get_state_directory(camogm_state *state) { //rawdev_buffer *rawdev){
return 0;
}
// need to modify - if prefix already appeared, and provided index <= old, increment latest old one
int set_state_file_from_prefix(camogm_state *state, const char * prefix){ // prefix is relative to /dev/sda1 (where camogm.disk is)
rawdev_buffer *rawdev = &state->rawdev;
char last_path[ELPHEL_PATH_MAX];
char * cp, *cp1;
int preflen, len, i;
strcpy(last_path,prefix); // may be either relative to camogm.disk directory or absolute
char * cp, *cp1, *local_pref; // pointer to last_path after '/'
int preflen, len, i , new_index, old_index;
DIR *d;
struct dirent *dir;
// char pathname[ELPHEL_PATH_MAX];
char state_directory[ELPHEL_PATH_MAX];
cp = last_path;
if (prefix[0] != '/') { // relative
len = get_dir_path(rawdev->state_path, last_path);
if (len < 0) {
D0(syslog (LOG_ERR,"%s:%d: State file '%s' is not absolute, should start with /dev/sda1", __FILE__, __LINE__, rawdev->state_path));
}
cp = last_path + len;
*cp++ = '/';
strncpy(cp, prefix, ELPHEL_PATH_MAX - len -2);
} else {
strcpy(last_path,prefix); // may be either relative to camogm.disk directory or absolute
}
// now - always absolute
if (!strcmp(last_path + (strlen(last_path)-strlen(STATE_EXT)),STATE_EXT)) { // ends with .disk
last_path[strlen(last_path)-strlen(STATE_EXT)] = '\0'; // truncate at .
}
rawdev->state_index = 0;
// absolute, w/o '.disk.
strcpy(rawdev->state_prefix, last_path); // use anyway, only index may be adjusted
// local_pref = last_path+
new_index = 0;
cp = strrchr(last_path,'_'); // find last '_'
if (!cp || strchr(cp,'/')){ //'_' in the directory name
cp = last_path+strlen(last_path); // full string w/o optional extension
......@@ -298,16 +332,57 @@ int set_state_file_from_prefix(camogm_state *state, const char * prefix){ // pre
break;
}
}
D2(syslog (LOG_INFO,"_s030_ len=%d, cp=0x%08x, cp1=%s", \
D2(syslog (LOG_INFO,"_s030_ len=%d, cp=0x%08x, cp1='%s'", \
len, (int) cp, cp1));
if (cp) {
sscanf(cp+1, "%d",&rawdev->state_index);
sscanf(cp+1, "%d",&new_index);
} else {
cp = last_path+strlen(last_path);
}
}
*cp = '\0';
strcpy(rawdev->state_prefix, last_path);
*cp = '\0'; // instead of the '_' or '.' in '.disk'
// last_path - prefix (absolute), new_index
// get directory from the new potential prefix (last_path)
len = get_dir_path(last_path, state_directory);
if (len < 0) {
D0(syslog (LOG_ERR,"%s:%d: Prefix '%s' should be absolute here", __FILE__, __LINE__, last_path));
return -1;
}
local_pref = last_path + (len+1); // right after '/', ends at former "_" or ".disk"
preflen = strlen(local_pref);
// see if the same prefix already appeared, if yes - find the maximal index
old_index = -1;
//strcpy(rawdev->state_prefix, state_directory)
D3(syslog (LOG_INFO, "_s31_ new prefix='%s' new directory='%s'", \
last_path, state_directory));
d = opendir(state_directory);
if (d) {
while ((dir = readdir(d)) != NULL) {
if (!strcmp(STATE_EXT, dir->d_name +(strlen(dir->d_name) - strlen(STATE_EXT)))) { // same extension
if (!strncmp(local_pref, dir->d_name, preflen)) { // starts same
if ((dir->d_name[preflen] == '_') || (dir->d_name[preflen] == '.')){
i=0; // if not get any - will be 0;
sscanf(dir->d_name+preflen+1, "%d",&i);
D3(syslog (LOG_INFO, "_s32_ matching old file='%s' index=%d", \
dir->d_name, i));
if (i > old_index) {
old_index = i;
}
}
}
}
}
closedir(d);
}
if (old_index >= new_index){
rawdev->state_index = old_index + 1;
D3(syslog (LOG_INFO, "_s33_ using incremented old index=%d (new was %d), prefix = '%s'", \
rawdev->state_index, new_index, rawdev->state_prefix));
} else {
rawdev->state_index = new_index;
D3(syslog (LOG_INFO, "_s33_ using new index index=%d (old was %d), prefix = '%s'", \
rawdev->state_index, old_index, rawdev->state_prefix));
}
preflen = snprintf(state->path, ELPHEL_PATH_MAX, STATE_FMT, rawdev->state_prefix ,rawdev->state_index);
D2(syslog (LOG_INFO,"_s03_ prefix='%s', rawdev->state_prefix='%s', index=%d, preflen=%d, state->path=%s", \
prefix, rawdev->state_prefix, rawdev->state_index, preflen, state->path));
......
......@@ -31,7 +31,10 @@ ssize_t emul_writev (int fd, const struct iovec *iovec, int count);
int get_write_page(struct writer_params *wparams);
int get_num_empty(struct writer_params *wparams);
int get_num_busy(struct writer_params *wparams);
int get_state_directory(camogm_state *state); // rawdev_buffer *rawdev);
int get_dir_path(char* file_path, char* directory); // directory should be allocated, returns w/o trailing '/'
int getup_state_files(camogm_state *state); // rawdev_buffer *rawdev);
int set_state_file_from_prefix(camogm_state *state, const char * prefix);
char * get_state_path(camogm_state *state);
void next_state_path(camogm_state *state);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment