Drop the old statcache implementation.
[cumulus.git] / metadata.h
1 /* LBS: An LFS-inspired filesystem backup system
2  * Copyright (C) 2007  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 /* Metadata for a single inode, ready to be written out. */
25 struct MetadataItem {
26     int offset;
27     std::string text;
28
29     bool reused;
30     ObjectReference ref;
31 };
32
33 class MetadataWriter {
34 public:
35     MetadataWriter(TarSegmentStore *store, const char *path,
36                    const char *snapshot_name, const char *snapshot_scheme);
37     void add(dictionary info);
38     ObjectReference close();
39
40     bool find(const std::string& path);
41     ObjectReference *old_ref() const {
42         return ObjectReference::parse(old_metadata_loc);
43     }
44
45     bool matched() const { return found_match; }
46     bool is_unchanged(const struct stat *stat_buf);
47
48     dictionary get_old_metadata() const { return old_metadata; }
49     std::list<ObjectReference> get_blocks();
50     std::string get_checksum() { return old_metadata["checksum"]; }
51
52 private:
53     void metadata_flush();
54     void read_statcache();
55
56     // Where are objects eventually written to?
57     TarSegmentStore *store;
58
59     // File descriptors for reading/writing local statcache data
60     std::string statcache_path, statcache_tmp_path;
61     FILE *statcache_in, *statcache_out;
62
63     // Metadata not yet written out to the segment store
64     size_t chunk_size;
65     std::list<MetadataItem> items;
66     std::ostringstream metadata_root;
67
68     // Statcache information read back in from a previous run
69     bool found_match;               // Result of last call to find
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