OmniSciDB  04ee39c94c
File.h
Go to the documentation of this file.
1 /*
2  * Copyright 2017 MapD Technologies, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
23 #ifndef DATAMGR_FILE_FILE_H
24 #define DATAMGR_FILE_FILE_H
25 
26 #define MAPD_FILE_EXT ".mapd"
27 #define MAX_FILE_N_PAGES 256
28 #define MAX_FILE_N_METADATA_PAGES 4096
29 
30 #include <iostream>
31 #include <string>
32 #include "../../Shared/types.h"
33 
34 namespace File_Namespace {
35 
36 FILE* create(const std::string& basePath,
37  const int fileId,
38  const size_t pageSize,
39  const size_t npages);
40 
41 FILE* create(const std::string& fullPath, const size_t requestedFileSize);
42 
49 FILE* open(int fileId);
50 
51 FILE* open(const std::string& path);
52 
58 void close(FILE* f);
59 
67 bool removeFile(const std::string basePath, const std::string filename);
68 
79 size_t read(FILE* f, const size_t offset, const size_t size, int8_t* buf);
80 
91 size_t write(FILE* f, const size_t offset, const size_t size, int8_t* buf);
92 
102 size_t append(FILE* f, const size_t size, int8_t* buf);
103 
114 size_t readPage(FILE* f, const size_t pageSize, const size_t pageNum, int8_t* buf);
115 
126 size_t writePage(FILE* f, const size_t pageSize, const size_t pageNum, int8_t* buf);
127 
137 size_t appendPage(FILE* f, const size_t pageSize, int8_t* buf);
138 
144 size_t fileSize(FILE* f);
145 
150 void renameForDelete(const std::string directoryName);
151 
152 } // namespace File_Namespace
153 
154 #endif // DATAMGR_FILE_FILE_H
size_t appendPage(FILE *f, const size_t pageSize, int8_t *buf)
Appends a page from buf to the file.
Definition: File.cpp:166
size_t writePage(FILE *f, const size_t pageSize, const size_t pageNum, int8_t *buf)
Writes a page from buf to the file.
Definition: File.cpp:153
FILE * create(const std::string &basePath, const int fileId, const size_t pageSize, const size_t numPages)
Definition: File.cpp:35
size_t read(FILE *f, const size_t offset, const size_t size, int8_t *buf)
Reads the specified number of bytes from the offset position in file f into buf.
Definition: File.cpp:113
size_t append(FILE *f, const size_t size, int8_t *buf)
Appends the specified number of bytes to the end of the file f from buf.
Definition: File.cpp:136
size_t readPage(FILE *f, const size_t pageSize, const size_t pageNum, int8_t *buf)
Reads the specified page from the file f into buf.
Definition: File.cpp:140
size_t fileSize(FILE *f)
Returns the size of the specified file.
Definition: File.cpp:171
FILE * open(int fileId)
Opens/creates the file with the given id; returns NULL on error.
Definition: File.cpp:83
size_t write(FILE *f, const size_t offset, const size_t size, int8_t *buf)
Writes the specified number of bytes to the offset position in file f from buf.
Definition: File.cpp:121
void close(FILE *f)
Closes the file pointed to by the FILE pointer.
Definition: File.cpp:102
bool removeFile(const std::string basePath, const std::string filename)
Deletes the file pointed to by the FILE pointer.
Definition: File.cpp:108
void renameForDelete(const std::string directoryName)
Renames a directory to DELETE_ME_<EPOCH>_<oldname>.
Definition: File.cpp:183