int nfs41_session_set_lease( IN nfs41_session *session, IN uint32_t lease_time) { int status = NO_ERROR; uint32_t thread_id; if (valid_handle(session->renew_thread)) { eprintf("nfs41_session_set_lease(): session " "renewal thread already started!\n"); goto out; } if (lease_time == 0) { eprintf("nfs41_session_set_lease(): invalid lease_time=0\n"); status = ERROR_INVALID_PARAMETER; goto out; } session->lease_time = lease_time; session->renew_thread = (HANDLE)_beginthreadex(NULL, 0, renew_session, session, 0, &thread_id); if (!valid_handle(session->renew_thread)) { status = GetLastError(); eprintf("_beginthreadex failed %d\n", status); goto out; } out: return status; }
/** * @brief set watchdog timer timeout period function * @param handle [in] wdt handle * @param period [in] wdt reset period in seconds * @return success: 0, erro: erro_id */ int gp_wdt_set_timeout(int handle,int period) { unsigned long freq; unsigned long count; unsigned long prescale = 1; if(!valid_handle(handle)) return -EINVAL; freq = gpHalWdtGetBaseClk(); count = 0xfffffffful/freq; if((period < 1)||(period > count)) return -EINVAL; gp_wdt_data.period = period; count = period*freq; prescale = (uint16_t)(count>>16); if(prescale){ count = count/(prescale + 1); } gpHalWdtSetPrescale(prescale); gpHalWdtSetLoad(count); return 0; }
/** * @brief wdt enable function * @param handle [in] wdt handles */ int gp_wdt_enable(int handle) { if(!valid_handle(handle)) return -EINVAL; gpHalWdtEnable(1); return 0; }
/** * @brief watchdog force reset * @param handle [in] wdt handle * @return success: 0, erro: erro_id */ int gp_wdt_force_reset(int handle) { if(!valid_handle(handle)) return -EINVAL; gpHalWdtForceReset(); return 0; }
/** * @brief feed watchdog,prevent watchdog reset * @param handle [in] wdt handle * @return success: 0, erro: erro_id */ int gp_wdt_keep_alive(int handle) { if(!valid_handle(handle)) return -EINVAL; gpHalWdtKeepAlive(); return 0; }
/** * @brief get watchdog timer timeout period function * @param handle [in] wdt handle * @param period [out] wdt reset period in seconds * @return success: 0, erro: erro_id */ int gp_wdt_get_timeout(int handle,int *period) { if(!valid_handle(handle)) return -EINVAL; *period = gp_wdt_data.period; return 0; }
/** * @brief wdt release function * @param handle [in] wdt handle * @return success: 0, erro: erro_id */ int gp_wdt_release(int handle) { if(!valid_handle(handle)) return -EINVAL; clear_bit(0,&gp_wdt_data.isOpened); gp_wdt_disable((int)&gp_wdt_data); return 0; }
int syscall_read(int handle, void *buf, size_t nbytes) { // Do some checking if ((handle >= 0 && handle < 20 && fileinf->fhandles[handle] >= 0) && valid_handle(fileinf->fhandles[handle], O_RDONLY | O_RDWR)) { handle=fileinf->fhandles[handle]; return read_file(handle, (char *)buf, nbytes); } else return EINVALID_FILE_HANDLE; }
void nfs41_session_free( IN nfs41_session *session) { AcquireSRWLockExclusive(&session->client->session_lock); if (valid_handle(session->renew_thread)) { dprintf(1, "nfs41_session_free: terminating session renewal thread\n"); if (!TerminateThread(session->renew_thread, NO_ERROR)) eprintf("failed to terminate renewal thread %p\n", session->renew_thread); } if (session->isValidState) { session->client->rpc->is_valid_session = FALSE; nfs41_destroy_session(session); } DeleteCriticalSection(&session->table.lock); ReleaseSRWLockExclusive(&session->client->session_lock); free(session); }
int main(int argc, char * argv[]) { int i; int read_write_error; int input_stat[2] = {0}; int output_stat[2] = {0}; int flags = 0; int count = -1; int skip = 0, seek = 0; int bs = -1, ibs = 4096, obs = 4096; int buffer_size = 0; int count_read, count_write; time_t time_start, time_finish, time_use; const char * input_path = "-"; const char * output_path = "-"; const char * input_device = NULL; const char * output_device = NULL; struct io_base *input_handle, *output_handle; char * buffer_read, * buffer_write, * buffer_alloc; for (i = 1; i < argc; i++) { char * argline = argv[i]; char * optvalue = getoptvalue(argv[i]); ARG_INT(&ibs, 1, "ibs="); ARG_INT(&obs, 2, "obs="); ARG_INT(&bs, (1 | 2), "bs="); ARG_INT(&seek, 4, "seek="); ARG_INT(&skip, 8, "skip="); ARG_INT(&count, 16, "count="); ARG_STRING(&input_path, 32, "if="); ARG_STRING(&output_path, 64, "of="); ARG_STRING(&input_device, 128, "kin="); ARG_STRING(&output_device, 256, "kout="); fprintf(stderr, "unkown operand %s", argline); exit(-1); } if (bs != -1) { ibs = bs; obs = bs; } valid_size("invalid input block size", ibs); valid_size("invalid output block size", obs); input_handle = open_file(input_path, GENERIC_READ); valid_handle("invalid input handle", input_handle); output_handle = open_file(output_path, GENERIC_WRITE); valid_handle("invalid output handle", output_handle); buffer_size = (ibs < obs? obs: ibs) * 2; buffer_alloc = (char *)malloc(buffer_size); valid_buffer("alloc buffer fail", buffer_alloc); if (seek > 0) { off_t posnew = seek * (off_t)(obs); off_t poscur = io_lseek(output_handle, posnew, SEEK_CUR); valid_size("seek output file fail", posnew == poscur); } if (skip > 0) { off_t posnew = skip * (off_t)(ibs); off_t poscur = io_lseek(output_handle, posnew, SEEK_CUR); valid_size("skip input file fail", posnew == poscur); } read_write_error = 0; count_read = count_write = 0; buffer_read = buffer_write = buffer_alloc; time_start = time(NULL); while (read_write_error == 0) { size_t transfer = 0; while (buffer_read < buffer_alloc + obs) { if (!io_read(input_handle, buffer_read, ibs, &transfer)) { read_write_error = 2; break; } if (transfer == 0) { read_write_error = 1; break; } buffer_read += transfer; count_read += transfer; input_stat[transfer == ibs]++; if (input_stat[0] + input_stat[1] == count) { read_write_error = 1; break; } } while (buffer_write + obs <= buffer_read) { if (!io_write(output_handle, buffer_write, obs, &transfer)) { read_write_error = 2; break; } if (transfer == 0) { read_write_error = 2; break; } output_stat[transfer == obs]++; buffer_write += transfer; count_write += transfer; } memmove(buffer_alloc, buffer_write, count_read - count_write); buffer_read = buffer_alloc + (count_read - count_write); buffer_write = buffer_alloc; } while (read_write_error == 1 && count_write < count_read) { size_t transfer = (count_read - count_write); valid_size("internal error", transfer < obs); if (io_write(output_handle, buffer_write, transfer, &transfer)) { output_stat[transfer == obs]++; buffer_write += transfer; count_write += transfer; continue; } if (io_write(output_handle, buffer_write, obs, &transfer)) { output_stat[transfer == obs]++; buffer_write += transfer; count_write += transfer; continue; } read_write_error = 3; break; } time_finish = time(NULL); io_close(output_handle); io_close(input_handle); free(buffer_alloc); time_use = time_finish > time_start? time_finish - time_start: 1; fprintf(stderr, "%d+%d records in\n", input_stat[1], input_stat[0]); fprintf(stderr, "%d+%d records out\n", output_stat[1], output_stat[0]); fprintf(stderr, "%d bytes transferred in %ld secs (%ld bytes/sec)\n", count_read, time_use, count_read / time_use); return 0; }