Write out new-style statcache data.
[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 <list>
15 #include <string>
16 #include <sstream>
17
18 #include "store.h"
19 #include "ref.h"
20 #include "util.h"
21
22 /* Metadata for a single inode, ready to be written out. */
23 struct MetadataItem {
24     int offset;
25     std::string text;
26 };
27
28 class MetadataWriter {
29 public:
30     MetadataWriter(TarSegmentStore *store, const char *path,
31                    const char *snapshot_name, const char *snapshot_scheme);
32     void add(const std::string& path, dictionary info);
33     ObjectReference close();
34
35 private:
36     void metadata_flush();
37
38     // Where are objects eventually written to?
39     TarSegmentStore *store;
40
41     // File descriptors for reading/writing local statcache data
42     std::string statcache_path, statcache_tmp_path;
43     FILE *statcache_out;
44
45     // Metadata not yet written out to the segment store
46     size_t chunk_size;
47     std::list<MetadataItem> items;
48     std::ostringstream metadata_root;
49 };
50
51 #endif // _LBS_METADATA_H