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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
#ifndef BTFILES_H
#define BTFILES_H
#include "./def.h"
#include <inttypes.h>
#include <sys/types.h>
#include <stdio.h>
#include <time.h>
#include "bitfield.h"
#include "btconfig.h"
typedef struct _btfile{
char *bf_filename; // full path of file.
uint64_t bf_length;
FILE *bf_fp;
char *bf_buffer;
time_t bf_last_timestamp; // last io timestamp.
size_t bf_npieces; //number of pieces
unsigned char bf_flag_opened:1;
unsigned char bf_flag_readonly:1;
unsigned char bf_reserved:6;
struct _btfile *bf_next;
}BTFILE;
class btFiles
{
private:
BTFILE *m_btfhead;
char *m_directory;
uint64_t m_total_files_length;
size_t m_total_opened; // already opened
size_t m_nfiles;
BTFILE **m_file;
uint8_t m_flag_automanage:1;
uint8_t m_flag_reserved:7; // current version not implement
BTFILE* _new_bfnode();
int _btf_close_oldest();
int _btf_close(BTFILE *pbf);
int _btf_open(BTFILE *pbf, const int iotype);
int _btf_ftruncate(int fd, int64_t length);
int _btf_creat_by_path(const char *pathname, int64_t file_length);
int _btf_destroy();
int _btf_recurses_directory(const char *cur_path, BTFILE **plastnode);
int ConvertFilename(char *dst, const char *src, int size);
public:
int CreateFiles();
void CloseFile(size_t nfile);
btFiles();
~btFiles();
int BuildFromFS(const char *pathname);
int BuildFromMI(const char *metabuf, const size_t metabuf_len,
const char *saveas, bool exam_only);
char *GetDataName() const;
uint64_t GetTotalLength() const { return m_total_files_length; }
ssize_t IO(char *buf, uint64_t off, size_t len, const int iotype);
size_t FillMetaInfo(FILE* fp);
void SetFilter(int nfile, BitField *pFilter, size_t pieceLength);
size_t GetNFiles() const { return m_nfiles; }
char *GetFileName(size_t nfile) const;
uint64_t GetFileSize(size_t nfile) const;
size_t GetFilePieces(size_t nfile) const;
void PrintOut();
};
#endif
|