Contiki-NG
storage.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010, Swedish Institute of Computer Science
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the Institute nor the names of its contributors
14  * may be used to endorse or promote products derived from this software
15  * without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  */
29 
30 /**
31  * \file
32  * The storage interface used by the database.
33  * \author
34  * Nicolas Tsiftes <nvt@sics.se>
35  */
36 
37 #ifndef STORAGE_H
38 #define STORAGE_H
39 
40 #include "index.h"
41 #include "relation.h"
42 
43 #define TABLE_NAME_SUFFIX ".row"
44 #define TABLE_NAME_LENGTH (RELATION_NAME_LENGTH + \
45  sizeof(TABLE_NAME_SUFFIX) - 1)
46 
47 #define INDEX_NAME_SUFFIX ".idx"
48 #define INDEX_NAME_LENGTH (RELATION_NAME_LENGTH + \
49  sizeof(INDEX_NAME_SUFFIX) - 1)
50 
51 typedef unsigned char * storage_row_t;
52 
53 char *storage_generate_file(char *, unsigned long);
54 
55 db_result_t storage_load(relation_t *);
56 void storage_unload(relation_t *);
57 
58 db_result_t storage_get_relation(relation_t *, char *);
59 db_result_t storage_put_relation(relation_t *);
60 db_result_t storage_drop_relation(relation_t *, int);
61 db_result_t storage_rename_relation(char *, char *);
62 
63 db_result_t storage_put_attribute(relation_t *, attribute_t *);
64 db_result_t storage_get_index(index_t *, relation_t *, attribute_t *);
65 db_result_t storage_put_index(index_t *);
66 
67 db_result_t storage_get_row(relation_t *, tuple_id_t *, storage_row_t);
68 db_result_t storage_put_row(relation_t *, storage_row_t);
69 db_result_t storage_get_row_amount(relation_t *, tuple_id_t *);
70 
71 db_storage_id_t storage_open(const char *);
72 void storage_close(db_storage_id_t);
73 db_result_t storage_read(db_storage_id_t, void *, unsigned long, unsigned);
74 db_result_t storage_write(db_storage_id_t, void *, unsigned long, unsigned);
75 
76 #endif /* STORAGE_H */