Commit fcfd70dd authored by lw's avatar lw

Copy .dbs files to /tmp and map copied file.

parent 5847ffa0
...@@ -409,15 +409,18 @@ dbs_Map(pwr_tStatus *sts, const char *filename) ...@@ -409,15 +409,18 @@ dbs_Map(pwr_tStatus *sts, const char *filename)
struct stat sb; struct stat sb;
int ret; int ret;
int fd; int fd;
int tfd;
int i; int i;
dbs_sSect *sect; dbs_sSect *sect;
dbs_sFile file; //dbs_sFile file;
void *base = 0; void *base = 0;
int nVolRef; int nVolRef;
dbs_sVolRef *vrp; dbs_sVolRef *vrp;
dbs_sMenv *mep = 0; dbs_sMenv *mep = 0;
dbs_sVenv *vep = 0; dbs_sVenv *vep = 0;
char buf[512];
char tfname[] = "/tmp/loadfile.dbs_XXXXXX";
*sts = DBS__SUCCESS; *sts = DBS__SUCCESS;
if ((ret = stat(filename, &sb)) != 0) { if ((ret = stat(filename, &sb)) != 0) {
...@@ -427,21 +430,35 @@ dbs_Map(pwr_tStatus *sts, const char *filename) ...@@ -427,21 +430,35 @@ dbs_Map(pwr_tStatus *sts, const char *filename)
} }
fd = open(filename, O_RDWR); fd = open(filename, O_RDWR);
tfd = mkstemp(tfname);
printf("dbs_Map:: %s -> %s\n", filename, tfname);
while (1) {
int count;
count = read(fd, buf, sizeof(buf));
if (count <= 0)
break;
write(tfd, buf, count);
}
ret = close(fd);
errno = 0; errno = 0;
ret = read(fd, &file, sizeof(file)); //ret = read(fd, &file, sizeof(file));
// printf("st_size...: %ld\n", sb.st_size); // printf("st_size...: %ld\n", sb.st_size);
// printf("size......: %d\n", file.size); // printf("size......: %d\n", file.size);
base = mmap(NULL, sb.st_size, PROT_READ, MAP_SHARED, fd, 0); base = mmap(NULL, sb.st_size, PROT_READ, MAP_SHARED, tfd, 0);
if (base == NULL) { if (base == NULL) {
*sts = errno_GetStatus(); *sts = errno_GetStatus();
perror("mmap"); perror("mmap");
ret = close(fd); ret = close(tfd);
return NULL; return NULL;
} }
ret = close(fd); ret = close(tfd);
unlink(tfname);
sect = (dbs_sSect*)(base + dbs_dAlign(sizeof(dbs_sFile))); sect = (dbs_sSect*)(base + dbs_dAlign(sizeof(dbs_sFile)));
vrp = (dbs_sVolRef*)(base + sect[dbs_eSect_volref].offset); vrp = (dbs_sVolRef*)(base + sect[dbs_eSect_volref].offset);
...@@ -568,6 +585,8 @@ dbs_Unmap(pwr_tStatus *sts, dbs_sMenv *mep) ...@@ -568,6 +585,8 @@ dbs_Unmap(pwr_tStatus *sts, dbs_sMenv *mep)
{ {
*sts = DBS__SUCCESS; *sts = DBS__SUCCESS;
if (mep->flags.b.isMapped) { if (mep->flags.b.isMapped) {
munmap(mep->base, mep->size);
mep->flags.b.isMapped = 0;
return TRUE; return TRUE;
} else if (mep->f != NULL) { } else if (mep->f != NULL) {
printf("ERROR, dbs_Unmap, trying to unmap a non mapped file\n"); printf("ERROR, dbs_Unmap, trying to unmap a non mapped file\n");
......
...@@ -7,8 +7,15 @@ ...@@ -7,8 +7,15 @@
void wb_vrepdbs::unref() void wb_vrepdbs::unref()
{ {
if (--m_nRef == 0) printf("wb_vrepdbs::unref\n");
if (--m_nRef == 0) {
pwr_tStatus sts;
printf("wb_vrepdbs::unref::dbs_Unmap\n");
dbs_Unmap(&sts, m_dbsmep);
delete this; delete this;
}
} }
wb_vrep *wb_vrepdbs::ref() wb_vrep *wb_vrepdbs::ref()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment