-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcloopreader.h
More file actions
60 lines (43 loc) · 1.45 KB
/
cloopreader.h
File metadata and controls
60 lines (43 loc) · 1.45 KB
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
#ifndef CLOOPREADER_H
#define CLOOPREADER_H
/* #define DEBUG */
#include "common_header.h"
#include <stdio.h>
/* OPA -- _O_peration with _p_error (with _a_dditional parameter) */
#define OPA(expr,test) ({\
typeof(expr) ret=expr; \
if(test){\
fprintf(stderr,__FILE__":%d: run-time: \""#expr"\": %s\n",\
__LINE__,strerror(errno)); \
bfuncinfo("run-time error in \"%s\": %s",#expr,strerror(errno)); \
}\
ret; \
})
#define NEG ret==-1
#define ZER ret==0
#define NUL ret==NULL
#define OP(expr) OPA(expr, NEG)
#define btc __be64_to_cpu
#define ALLOC(var,size) var=(typeof(var))malloc(size)
#define ulong unsigned long
struct cloop_data{
int fh;
int numblocks;
ulong blocksize;
struct block_info *toc; /* Data index */
size_t tocsize;
unsigned char* cblock; /* Compressed block */
unsigned char* pblock; /* Plain block */
ulong cblocksize; /* Size of compressed block */
ulong cblocksizecur; /* Size of allocated memory */
int curblock; /* Number of current block (which is decompressed to pblock) */
};
/* Initialize cloop reader */
int cloop_init(struct cloop_data *c, int fh);
/* Change cloop "page" */
int cloop_swap(struct cloop_data *c,ulong page);
/* Read data from cloop (may decrease buffer size)*/
int cloop_read(struct cloop_data* c, off_t offset,void* buf,ulong size);
/* Read all requested data from cloop */
int cloop_read_all(struct cloop_data* c, off_t offset,void* buf,ulong size);
#endif