mf_handle_t mf_open(const char *pathname){ LOG(INFO, "mf_open called\n"); assert(pathname); int fd = open(pathname, O_RDWR | O_CREAT, 0755); if (fd == -1) return NULL; long int size = fsize(pathname); if (size == -1) return NULL; struct _mf *mf = (struct _mf *) malloc(sizeof(struct _mf)); mf -> fd = fd; mf -> size = size; mf -> prev_ch = NULL; chunk_manager_init(&mf -> cm, fd, O_RDWR | O_CREAT); struct sysinfo info; //I know :) if (sysinfo(&info) == 0) { int tmp; struct chunk *ch = NULL; chunk_manager_offset2chunk(&mf -> cm, 0, info.freeram / 2, &ch, &tmp, 0); mf -> prev_ch = ch; } return (mf_handle_t) mf; }
int local_chunk_manager_init (struct local_chunk_manager *lcm, int fd, int mode){ int thr; int index; for (thr = 0; thr < MAX_NUM_THREADS; thr++){ for (index = 0; index < LOCAL_POOL_SIZE; index++){ lcm -> lchunk_pool[thr][index].chunk = NULL; lcm -> lchunk_pool[thr][index].local_ref_cnt = 0; } lcm -> cur_lchunk_index_free[thr] = 0; lcm -> cur_lchunk_index_prev[thr] = 0; } return chunk_manager_init(&lcm -> cm, fd, mode); }