int ReadWriteTest(void) { static int test_data[] = { 3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9, 3, 2, 3, 8, 4, 6, 2, 6, 4, 3, 3, 8, 3, 2, 7, 9, 5, 0, 2, 8, 8, 4, 1, 9, 7, 1, 6, 9, 3, 9, 9, 3, 7, 5, 1, 0, 5, 8, 2, 0, 9, 7, 4, 9, 4, 4, 5, 9, 2, 3, 0, 7, 8, 1, 6, 4, 0, 6, 2, 8, 6, 2, 0, 8, 9, 9, 8, 6, 2, 8, 0, 3, 4, 8, 2, 5, 3, 4, 2, 1, 1, 7, 0, 6, 7, 6 }; struct DynArray da; int i; int nerrors = 0; printf("\nReadWriteTest\n"); DynArrayCtor(&da, 2); for (i = 0; i < NACL_ARRAY_SIZE(test_data); ++i) { if (!DynArraySet(&da, i, (void *) test_data[i])) { printf("insert for position %d failed\n", i); ++nerrors; } } for (i = 0; i < NACL_ARRAY_SIZE(test_data); ++i) { if ((int) DynArrayGet(&da, i) != test_data[i]) { printf("check for value at position %d failed\n", i); ++nerrors; } } DynArrayDtor(&da); DynArrayCtor(&da, 10); for (i = NACL_ARRAY_SIZE(test_data); --i >= 0; ) { if (!DynArraySet(&da, i, (void *) test_data[i])) { printf("insert for position %d failed\n", i); ++nerrors; } } for (i = NACL_ARRAY_SIZE(test_data); --i >= 0; ) { if ((int) DynArrayGet(&da, i) != test_data[i]) { printf("check for value at position %d failed\n", i); ++nerrors; } } DynArrayDtor(&da); printf(0 != nerrors ? "FAIL\n" : "OK\n"); return nerrors; }
struct MountInfo* mm_mountinfo_bypath( struct MountsManager *mounts_manager, const char* path, int *mount_index ){ struct MountInfo *mount_info=NULL; int i; for( i=0; i < mounts_manager->mount_items.num_entries; i++ ){ /*if matched path and mount path*/ struct MountInfo *current_mount_info = (struct MountInfo *)DynArrayGet(&mounts_manager->mount_items, i); if ( current_mount_info == NULL ) continue; const char* mount_path = current_mount_info->mount_path; /*if path is matched, then check mountpoint*/ if ( !strncmp( mount_path, path, strlen(mount_path) ) ){ if ( mount_info == NULL || strlen(mount_path) > strlen(mount_info->mount_path) ){ mount_info = current_mount_info; *mount_index=i; } } } if ( mount_info != NULL ){ ZRT_LOG(L_EXTRA, "located mount by path=%s: mountpoint=%s, mount_index=%d", path, mount_info->mount_path, *mount_index); return mount_info; } else{ ZRT_LOG(L_EXTRA, "didn't locate mount by path=%s", path); return NULL; } }
void Free(struct ChannelsConfigInterface *ch_if){ struct UserChannel *channel = NULL; for( int i=0; i < ch_if->channels->num_entries; i++ ){ channel = DynArrayGet(ch_if->channels, i); assert(channel); free(channel); } DynArrayDtor( ch_if->channels ); }
struct UserChannel *Channel(struct ChannelsConfigInterface *ch_if, int nodetype, int nodeid, int8_t channelmode){ struct UserChannel *ch = NULL; for ( int i=0; i < ch_if->channels->num_entries; i++ ){ ch = DynArrayGet(ch_if->channels, i); if( ch && ch->nodetype == nodetype && ch->nodeid == nodeid && ch->mode == channelmode ){ ch->DebugPrint = DebugPrint; return ch; } } return NULL; }
int GetNodesListByType( const struct ChannelsConfigInterface *ch_if, int nodetype, int **nodes_array ){ int count_rchan = 0; int count_wchan = 0; int i=0; /*calculate nodes count for two groups (read,write) of nodes and select maximum */ for ( i=0; i < ch_if->channels->num_entries; i++ ){ struct UserChannel *channel = DynArrayGet(ch_if->channels, i ); if ( channel->nodetype == nodetype && channel->mode == EChannelModeRead ) count_rchan++; else if ( channel->nodetype == nodetype && channel->mode == EChannelModeWrite ) count_wchan++; } *nodes_array = calloc( count_rchan > count_wchan ? count_rchan : count_wchan, sizeof(int) ); int mode=0; if ( count_rchan > count_wchan ){ /*alloc array of node ids*/ mode=EChannelModeRead; } else{ mode=EChannelModeWrite; } /*sort to get ascending nodeid array*/ qsort( ch_if->channels->ptr_array, ch_if->channels->num_entries,sizeof(struct UserChannel*), cmp_by_node_type_and_id ); count_rchan = 0; for ( i=0; i < ch_if->channels->num_entries; i++ ){ struct UserChannel *channel = DynArrayGet(ch_if->channels, i ); if ( channel->nodetype == nodetype && channel->mode == mode ){ (*nodes_array)[count_rchan++] = channel->nodeid; } } return count_rchan; }
struct async_lock_data * match_mount_data_by_condition_value(int condition_value) { struct async_lock_data *lock_data = NULL; int i; if (s_fuse_mount_data == NULL) return NULL; /*look lock_data matching it by mountpoint*/ for (i=0; i < s_fuse_mount_data->num_entries; i++){ lock_data = DynArrayGet( s_fuse_mount_data, i); if (lock_data!=NULL && lock_data->cond_value == condition_value){ break; } else lock_data=NULL; } return lock_data; }
struct async_lock_data * match_mount_data_by_mountpoint(const char *mountpoint) { struct async_lock_data *lock_data = NULL; int i; if (s_fuse_mount_data == NULL) return NULL; /*look lock_data matching it by mountpoint*/ for (i=0; i < s_fuse_mount_data->num_entries; i++){ lock_data = DynArrayGet( s_fuse_mount_data, i); if (lock_data!=NULL && !strcmp(lock_data->args.mountpoint, mountpoint)){ break; } else lock_data=NULL; } return lock_data; }
void terminate_fuse_mounts(){ int i; struct async_lock_data *lock_data; if (s_fuse_mount_data == NULL) return; for(i=0; i < s_fuse_mount_data->num_entries; i++){ lock_data = DynArrayGet( s_fuse_mount_data, i); /*if exist initialized fs that need to be stopped*/ if (lock_data != NULL){ if (lock_data->cond_value >= EConditionInitialized){ /*release waiting fuse_main, continue exiting*/ update_cond_value(lock_data, EConditionWaitingFinalization); } /*remove mount from mounts list, and free all memories*/ get_system_mounts_manager()->mount_remove( get_system_mounts_manager(), lock_data->args.mountpoint ); /*remove asynch data of fuse mount*/ free_lock_data_remove_from_array(lock_data); } } DynArrayDtor(s_fuse_mount_data); }