Lines Matching refs:st

30 void nhw_nvm_initialize_data_storage(nvm_storage_state_t *st){  in nhw_nvm_initialize_data_storage()  argument
34 st->fd = -1; in nhw_nvm_initialize_data_storage()
35 st->storage = NULL; in nhw_nvm_initialize_data_storage()
37 if (st->in_ram == true) { in nhw_nvm_initialize_data_storage()
38 st->storage = (uint8_t *)bs_malloc(st->size); in nhw_nvm_initialize_data_storage()
42 bs_create_folders_in_path(st->file_path); in nhw_nvm_initialize_data_storage()
43 st->fd = open(st->file_path, O_RDWR | O_CREAT, (mode_t)0600); in nhw_nvm_initialize_data_storage()
44 if (st->fd == -1) { in nhw_nvm_initialize_data_storage()
46 __func__, st->type_s, st->file_path, strerror(errno)); in nhw_nvm_initialize_data_storage()
49 rc = fstat(st->fd, &f_stat); in nhw_nvm_initialize_data_storage()
52 __func__, st->type_s, st->file_path, strerror(errno)); in nhw_nvm_initialize_data_storage()
55 if (ftruncate(st->fd, st->size) == -1) { in nhw_nvm_initialize_data_storage()
57 __func__, st->type_s, st->file_path, strerror(errno)); in nhw_nvm_initialize_data_storage()
60 st->storage = mmap(NULL, st->size, PROT_WRITE | PROT_READ, MAP_SHARED, st->fd, 0); in nhw_nvm_initialize_data_storage()
61 if (st->storage == MAP_FAILED) { in nhw_nvm_initialize_data_storage()
63 __func__, st->type_s, st->file_path, strerror(errno)); in nhw_nvm_initialize_data_storage()
67 if ((st->erase_at_start == true) || (st->in_ram == true) || (f_stat.st_size == 0)) { in nhw_nvm_initialize_data_storage()
69 (void)memset(st->storage, 0xFF, st->size); in nhw_nvm_initialize_data_storage()
73 void nhw_nvm_init_storage(nvm_storage_state_t *st, struct nhw_nvm_st_args_t *args, in nhw_nvm_init_storage() argument
76 st->file_path = args->file; in nhw_nvm_init_storage()
77 st->erase_at_start = args->erase; in nhw_nvm_init_storage()
78 st->rm_at_exit = args->rm; in nhw_nvm_init_storage()
79 st->in_ram = args->in_ram; in nhw_nvm_init_storage()
80 st->size = size; in nhw_nvm_init_storage()
81 st->type_s = type_s; in nhw_nvm_init_storage()
83 nhw_nvm_initialize_data_storage(st); in nhw_nvm_init_storage()
91 void nhw_nvm_clear_storage(nvm_storage_state_t *st){ in nhw_nvm_clear_storage() argument
93 if (st->in_ram == true) { in nhw_nvm_clear_storage()
94 if (st->storage != NULL) { in nhw_nvm_clear_storage()
95 free(st->storage); in nhw_nvm_clear_storage()
96 st->storage = NULL; in nhw_nvm_clear_storage()
101 if ((st->storage != MAP_FAILED) && (st->storage != NULL)) { in nhw_nvm_clear_storage()
102 munmap(st->storage, st->size); in nhw_nvm_clear_storage()
103 st->storage = NULL; in nhw_nvm_clear_storage()
106 if (st->fd != -1) { in nhw_nvm_clear_storage()
107 close(st->fd); in nhw_nvm_clear_storage()
108 st->fd = -1; in nhw_nvm_clear_storage()
111 if ((st->rm_at_exit == true) && (st->file_path != NULL)) { in nhw_nvm_clear_storage()
113 (void) remove(st->file_path); in nhw_nvm_clear_storage()
114 st->file_path = NULL; in nhw_nvm_clear_storage()