File: dares.h

package info (click to toggle)
dares 0.6.5%2Brepack-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, forky, sid, trixie
  • size: 700 kB
  • sloc: ansic: 1,169; cpp: 955; makefile: 32
file content (86 lines) | stat: -rw-r--r-- 2,922 bytes parent folder | download | duplicates (5)
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
82
83
84
85
86
/* dares.h */
/* part of DAta REScue dares */

/* DAta REScue (C) 2002 Oliver Diedrich, odi@ct.heise.de */
/* (C) 2005 c't magazine for computer technology, Heise Zeitschriften Verlag */
/* This file may be redistributed under the terms of the */
/* GNU Public License (GPL), see www.gnu.org */

#ifndef __DARES_H__
#define __DARES_H__

#define NAME_FORMAT "%s/%07lu-%s.%s"    // save_path, block #, type, bin|asc
#define BIN 1                           // binary file
#define ASC 2                           // text file
#define END_NULL_BIN 5                  // # zeros at end of binary files
#define END_NULL_ASC 1                  // # zeros at end of text files
#define LOG_FILE "dares.log"            // default name of log file

#define MAXMAGIS 100000                 // different file types in all_type[]
#define MAX_TYPE 80                     // max length of file type string
#define MAGIC_FILE "magic"              // default name of magic file

// define DOS to compile for DOS/Windows environment
#undef DOS
#ifndef DOS
  #define O_BINARY 0
#endif


// daresOpen() return values:
// return values greater than DARES_OPEN_OK contain the number of blocks found
#define DARES_OPEN_OK                 0
#define DARES_OPEN_INVALID_PARAM     -1
#define DARES_OPEN_CANNOT_OPEN_IMAGE -2
#define DARES_OPEN_CANNOT_MALLOC     -3
#define DARES_OPEN_CANNOT_OPEN_MAGIC -4

/* save_file() return values */
#define SAVE_FILE_OK                   1
#define SAVE_FILE_CANNOT_OPEN_IMAGE   -1
#define SAVE_FILE_CANNOT_OPEN_OUTFILE -2
#define SAVE_FILE_SEEK_ERROR          -3
#define SAVE_FILE_READ_ERROR          -4
#define SAVE_FILE_WRITE_ERROR         -5

#undef NDEBUG
#include <assert.h>

struct extent                 // a series of block numbers belonging to a file
{
  unsigned long start;        // block number
  unsigned long end;          // block number
  struct extent *next;        // next extent; NULL: last extent
};


struct one_file               // a recognized file while scanning disk
{
  unsigned long count;        // current number
  struct extent *ext;         // pointer to first extent
  unsigned long size;         // # bytes already written
  int filetype;               // ASC or BIN
  char *trunc;                // "truncated: ..." string, might be missing
  struct one_file *next;      // pointer to next file of same type
};


struct one_type               // one of the found file types
{
  char *name;                 // file type
  unsigned int hash;          // hash value, computed from name; after scan:
                              // # of files of this type
  unsigned int trunc;         // # of truncated files
  struct one_file *first;     // start of the list of files of this type
  struct one_file *last;      // last element in this list
};


int daresOpen(int argc, char *argv[]);

int daresClose( void );

int save_file(struct one_file *f, char *type, char *name);

#endif