Imported Upstream version 0.1.2
[platform/upstream/snapper.git] / snapper / Filesystem.h
1 /*
2  * Copyright (c) [2011-2013] Novell, Inc.
3  *
4  * All Rights Reserved.
5  *
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms of version 2 of the GNU General Public License as published
8  * by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, contact Novell, Inc.
17  *
18  * To contact Novell about this file by physical or electronic mail, you may
19  * find current contact information at www.novell.com.
20  */
21
22
23 #ifndef SNAPPER_FILESYSTEM_H
24 #define SNAPPER_FILESYSTEM_H
25
26
27 #include <string>
28 #include <vector>
29
30 #include "snapper/FileUtils.h"
31 #include "snapper/Compare.h"
32
33
34 namespace snapper
35 {
36     using std::string;
37     using std::vector;
38
39
40     class MtabData;
41
42
43     class Filesystem
44     {
45     public:
46
47         Filesystem(const string& subvolume) : subvolume(subvolume) {}
48         virtual ~Filesystem() {}
49
50         static Filesystem* create(const string& fstype, const string& subvolume);
51
52         virtual string fstype() const = 0;
53
54         virtual void createConfig() const = 0;
55         virtual void deleteConfig() const = 0;
56
57         virtual string snapshotDir(unsigned int num) const = 0;
58
59         virtual SDir openSubvolumeDir() const;
60         virtual SDir openInfosDir() const = 0;
61         virtual SDir openInfoDir(unsigned int num) const;
62         virtual SDir openSnapshotDir(unsigned int num) const = 0;
63
64         virtual void createSnapshot(unsigned int num) const = 0;
65         virtual void deleteSnapshot(unsigned int num) const = 0;
66
67         virtual bool isSnapshotMounted(unsigned int num) const = 0;
68         virtual void mountSnapshot(unsigned int num) const = 0;
69         virtual void umountSnapshot(unsigned int num) const = 0;
70
71         virtual bool checkSnapshot(unsigned int num) const = 0;
72
73         virtual void cmpDirs(const SDir& dir1, const SDir& dir2, cmpdirs_cb_t cb) const;
74
75     protected:
76
77         const string subvolume;
78
79         static vector<string> filter_mount_options(const vector<string>& options);
80
81         static bool mount(const string& device, int fd, const string& mount_type,
82                           const vector<string>& options);
83         static bool umount(int fd, const string& mount_point);
84
85     };
86
87 }
88
89
90 #endif