François Gautrais 9 anos atrás
pai
commit
66bf6010b4
4 arquivos alterados com 22 adições e 3 exclusões
  1. 0 1
      io.h
  2. 4 0
      server/db.h
  3. 18 0
      server/db_access.c
  4. 0 2
      server/db_access.h

+ 0 - 1
io.h

@@ -3,7 +3,6 @@
 
 #ifdef __linux__
 	#include <unistd.h>
-	#include <wiringPi.h>
 	#include <unistd.h>
 	#include <sys/types.h>
 	#include <sys/stat.h>

+ 4 - 0
server/db.h

@@ -7,6 +7,7 @@
 typedef struct 
 {
 	db_index_t index;
+	cache_t* cache;
 } db_t;
 
 
@@ -54,4 +55,7 @@ db_data_set_t* db_get(db_t* db, db_time_t* start, db_time_t* end);
 db_data_interval_t* db_load_fault(db_t* db, db_date_t ds, uint32_t dsm,
 																					 db_date_t de, uint32_t dem);
 
+
+int db_load_page(db_t* db, uint64_t page, db_data_t* buffer);
+
 #endif

+ 18 - 0
server/db_access.c

@@ -131,6 +131,23 @@ uint32_t db_index_get(db_t* db, db_date_t d, uint32_t time, int f)
 }
 
 
+int db_load_page(db_t* db, uint64_t page, db_data_t* buffer)
+{
+	int fd = open("data", O_RDONLY), r;
+	if(fd<0)
+	{
+		fprintf(stderr, "Error unable to load page %ld (%x->%x) (db_load_page())",
+										page, page*db->cache->page_size*sizeof(db_data_t), 
+										(page+1)*db->cache->page_size*sizeof(db_data_t));
+		perror(" ");
+		return -1;
+	}
+	lseek(fd,page*db->cache->page_size*sizeof(db_data_t), SEEK_SET);
+	r=read(fd, buffer,  db->cache->page_size*sizeof(db_data_t));
+	close(fd);
+	return r;
+}
+
 
 void write_data()
 {
@@ -168,6 +185,7 @@ void write_data()
 	close(f);
 }
 
+
 void write_day()
 {
 	int f = open("metadata_days", O_RDWR | O_CREAT, 0777 );

+ 0 - 2
server/db_access.h

@@ -11,7 +11,6 @@
 #include <sys/types.h>
 #include <fcntl.h>
 
-
 typedef struct
 {
 	uint16_t year;
@@ -69,7 +68,6 @@ typedef struct
 
 
 
-
 void db_index_release(db_index_t* in);
 int  db_index_load(db_index_t* out);