-
Notifications
You must be signed in to change notification settings - Fork 0
/
NimbleStore.cpp
50 lines (44 loc) · 1.19 KB
/
NimbleStore.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//
// Created by lygn128 on 16-3-17.
//
#include "NimbleStore.h"
#include "utils.h"
#include "Global.h"
#include <cstdio>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <cstring>
#include <unistd.h>
NimbleStore::NimbleStore(char *path) {
bool dirExist;
dirExist = isDirExist(path);
if(!dirExist) {
printf("data dir is not exist\n");
exit(-1);
}
for(int i = 0;i < CHUNKNUM;i++){
char * tempPAth = (char*)malloc(100);
sprintf(tempPAth,"%s/%d",path,i);
// printf("%s\n",tempPAth);
int fd = open(tempPAth,O_CREAT|O_RDWR|O_APPEND,0666);
fdArry[i] = fd;
// printf("fd is %d \n",fdArry[i]);
}
}
size_t NimbleStore::Fwrite(int chunkId, size_t offset, size_t size, void *data, size_t len) {
int fd = fdArry[chunkId];
__glibcxx_assert(fd > 0);
return pwrite(fd,data,len,offset);
}
size_t NimbleStore::Write(int chunkId, void *data, size_t len) {
static int i = 0;
// int fd = fdArry[chunkId];
// __glibcxx_assert(fd > 0);
// return write(fd,data,len);
int fd = fdArry[i++];
i = i%CHUNKNUM;
// __glibcxx_assert(fd > 0);
return write(fd,data,len);
}