Update copyright dates in source files.
[cumulus.git] / metadata.h
1 /* LBS: An LFS-inspired filesystem backup system
2  * Copyright (C) 2007-2008  Michael Vrable
3  *
4  * Handling of metadata written to backup snapshots.  This manages the writing
5  * of file metadata into new backup snapshots, including breaking the metadata
6  * log apart across separate objects.  Eventually this should include unified
7  * handling of the statcache, and re-use of metadata between snapshots.
8  */
9
10 #ifndef _LBS_METADATA_H
11 #define _LBS_METADATA_H
12
13 #include <stdio.h>
14 #include <sys/types.h>
15 #include <sys/stat.h>
16 #include <list>
17 #include <string>
18 #include <sstream>
19
20 #include "store.h"
21 #include "ref.h"
22 #include "util.h"
23
24 extern bool flag_full_metadata;
25
26 /* Metadata for a single inode, ready to be written out. */
27 struct MetadataItem {
28     int offset;
29     std::string text;
30
31     bool reused;
32     ObjectReference ref;
33 };
34
35 class MetadataWriter {
36 public:
37     MetadataWriter(TarSegmentStore *store, const char *path,
38                    const char *snapshot_name, const char *snapshot_scheme);
39     void add(dictionary info);
40     ObjectReference close();
41
42     bool find(const std::string& path);
43     ObjectReference old_ref() const {
44         return ObjectReference::parse(old_metadata_loc);
45     }
46
47     bool is_unchanged(const struct stat *stat_buf);
48
49     dictionary get_old_metadata() const { return old_metadata; }
50     std::list<ObjectReference> get_blocks();
51     std::string get_checksum() { return old_metadata["checksum"]; }
52
53 private:
54     void metadata_flush();
55     void read_statcache();
56
57     // Where are objects eventually written to?
58     TarSegmentStore *store;
59
60     // File descriptors for reading/writing local statcache data
61     std::string statcache_path, statcache_tmp_path;
62     FILE *statcache_in, *statcache_out;
63
64     // Metadata not yet written out to the segment store
65     size_t chunk_size;
66     std::list<MetadataItem> items;
67     std::ostringstream metadata_root;
68
69     // Statcache information read back in from a previous run
70     bool old_metadata_eof;
71     dictionary old_metadata;
72     std::string old_metadata_loc;   // Reference to where the metadata is found
73 };
74
75 #endif // _LBS_METADATA_H