string subvol_option = default_subvolume_name;
if (!subvol_option.empty())
subvol_option += "/";
- subvol_option += ".snapshots";
+ subvol_option += SNAPSHOTS_NAME;
- mkdir((root_prefix + "/.snapshots").c_str(), 0777);
+ mkdir((root_prefix + "/" SNAPSHOTS_NAME).c_str(), 0777);
- SDir s_dir(root_prefix + "/.snapshots");
+ SDir s_dir(root_prefix + "/" SNAPSHOTS_NAME);
if (!s_dir.mount(device, "btrfs", 0, "subvol=" + subvol_option))
{
cerr << "mounting .snapshots failed" << endl;
#include "snapper/File.h"
#include "snapper/Snapper.h"
#include "snapper/SnapperTmpl.h"
+#include "snapper/SnapperDefines.h"
#include "snapper/Acls.h"
#include "snapper/Exception.h"
try
{
- create_subvolume(subvolume_dir.fd(), ".snapshots");
+ create_subvolume(subvolume_dir.fd(), SNAPSHOTS_NAME);
}
catch (const runtime_error_with_errno& e)
{
}
}
- SFile x(subvolume_dir, ".snapshots");
+ SFile x(subvolume_dir, SNAPSHOTS_NAME);
#ifdef ENABLE_SELINUX
try
try
{
- delete_subvolume(subvolume_dir.fd(), ".snapshots");
+ delete_subvolume(subvolume_dir.fd(), SNAPSHOTS_NAME);
}
catch (const runtime_error& e)
{
string
Bcachefs::snapshotDir(unsigned int num) const
{
- return (subvolume == "/" ? "" : subvolume) + "/.snapshots/" + decString(num) +
- "/snapshot";
+ return (subvolume == "/" ? "" : subvolume) + "/" SNAPSHOTS_NAME "/" + decString(num) +
+ "/" SNAPSHOT_NAME;
}
Bcachefs::openInfosDir() const
{
SDir subvolume_dir = openSubvolumeDir();
- SDir infos_dir(subvolume_dir, ".snapshots");
+ SDir infos_dir(subvolume_dir, SNAPSHOTS_NAME);
struct stat stat;
if (infos_dir.stat(&stat) != 0)
Bcachefs::openSnapshotDir(unsigned int num) const
{
SDir info_dir = openInfoDir(num);
- SDir snapshot_dir(info_dir, "snapshot");
+ SDir snapshot_dir(info_dir, SNAPSHOT_NAME);
return snapshot_dir;
}
try
{
if (empty)
- create_subvolume(info_dir.fd(), "snapshot");
+ create_subvolume(info_dir.fd(), SNAPSHOT_NAME);
else
- create_snapshot(subvolume_dir.fd(), subvolume, info_dir.fd(), "snapshot", read_only);
+ create_snapshot(subvolume_dir.fd(), subvolume, info_dir.fd(), SNAPSHOT_NAME, read_only);
}
catch (const runtime_error& e)
{
try
{
- create_snapshot(snapshot_dir.fd(), subvolume, info_dir.fd(), "snapshot", read_only);
+ create_snapshot(snapshot_dir.fd(), subvolume, info_dir.fd(), SNAPSHOT_NAME, read_only);
}
catch (const runtime_error& e)
{
try
{
- delete_subvolume(info_dir.fd(), "snapshot");
+ delete_subvolume(info_dir.fd(), SNAPSHOT_NAME);
}
catch (const runtime_error& e)
{
SDir info_dir = openInfoDir(num);
struct stat stat;
- int r = info_dir.stat("snapshot", &stat, AT_SYMLINK_NOFOLLOW);
+ int r = info_dir.stat(SNAPSHOT_NAME, &stat, AT_SYMLINK_NOFOLLOW);
return r == 0 && is_subvolume(stat);
}
catch (const IOErrorException& e)
try
{
- create_subvolume(subvolume_dir.fd(), ".snapshots");
+ create_subvolume(subvolume_dir.fd(), SNAPSHOTS_NAME);
}
catch (const runtime_error_with_errno& e)
{
}
}
- SFile x(subvolume_dir, ".snapshots");
+ SFile x(subvolume_dir, SNAPSHOTS_NAME);
#ifdef ENABLE_SELINUX
try
{
#ifdef ENABLE_ROLLBACK
if (subvolume == "/")
{
- subvolume_dir.umount(".snapshots");
+ subvolume_dir.umount(SNAPSHOTS_NAME);
removeFromFstab();
}
try
{
- delete_subvolume(subvolume_dir.fd(), ".snapshots");
+ delete_subvolume(subvolume_dir.fd(), SNAPSHOTS_NAME);
}
catch (const runtime_error& e)
{
string
Btrfs::snapshotDir(unsigned int num) const
{
- return (subvolume == "/" ? "" : subvolume) + "/.snapshots/" + decString(num) +
- "/snapshot";
+ return (subvolume == "/" ? "" : subvolume) + "/" SNAPSHOTS_NAME "/" + decString(num) +
+ "/" SNAPSHOT_NAME;
}
Btrfs::openInfosDir() const
{
SDir subvolume_dir = openSubvolumeDir();
- SDir infos_dir(subvolume_dir, ".snapshots");
+ SDir infos_dir(subvolume_dir, SNAPSHOTS_NAME);
struct stat stat;
if (infos_dir.stat(&stat) != 0)
Btrfs::openSnapshotDir(unsigned int num) const
{
SDir info_dir = openInfoDir(num);
- SDir snapshot_dir(info_dir, "snapshot");
+ SDir snapshot_dir(info_dir, SNAPSHOT_NAME);
return snapshot_dir;
}
try
{
if (empty)
- create_subvolume(info_dir.fd(), "snapshot");
+ create_subvolume(info_dir.fd(), SNAPSHOT_NAME);
else
- create_snapshot(subvolume_dir.fd(), info_dir.fd(), "snapshot", read_only,
+ create_snapshot(subvolume_dir.fd(), info_dir.fd(), SNAPSHOT_NAME, read_only,
quota ? qgroup : no_qgroup);
}
catch (const runtime_error& e)
try
{
- create_snapshot(snapshot_dir.fd(), info_dir.fd(), "snapshot", read_only,
+ create_snapshot(snapshot_dir.fd(), info_dir.fd(), SNAPSHOT_NAME, read_only,
quota ? qgroup : no_qgroup);
}
catch (const runtime_error& e)
try
{
- create_snapshot(tmp_mount_dir.fd(), info_dir.fd(), "snapshot", read_only,
+ create_snapshot(tmp_mount_dir.fd(), info_dir.fd(), SNAPSHOT_NAME, read_only,
quota ? qgroup : no_qgroup);
}
catch (const runtime_error& e)
subvolid_t subvolid = get_id(openSnapshotDir(num).fd());
#endif
- delete_subvolume(info_dir.fd(), "snapshot");
+ delete_subvolume(info_dir.fd(), SNAPSHOT_NAME);
#if defined(HAVE_LIBBTRFS) || defined(HAVE_LIBBTRFSUTIL)
deleted_subvolids.push_back(subvolid);
}
catch (const runtime_error& e)
{
- y2err("delete snapshot " << info_dir.fullname() << "/snapshot failed, " << e.what());
+ y2err("delete snapshot " << info_dir.fullname() << "/" SNAPSHOT_NAME " failed, " << e.what());
SN_THROW(DeleteSnapshotFailedException());
}
}
SDir info_dir = openInfoDir(num);
struct stat stat;
- int r = info_dir.stat("snapshot", &stat, AT_SYMLINK_NOFOLLOW);
+ int r = info_dir.stat(SNAPSHOT_NAME, &stat, AT_SYMLINK_NOFOLLOW);
return r == 0 && is_subvolume(stat);
}
catch (const IOErrorException& e)
string subvol_option = default_subvolume_name;
if (!subvol_option.empty())
subvol_option += "/";
- subvol_option += ".snapshots";
+ subvol_option += SNAPSHOTS_NAME;
MntTable mnt_table(root_prefix);
mnt_table.parse_fstab();
if (!snapshots)
throw runtime_error("mnt_copy_fs failed");
- mnt_fs_set_target(snapshots, "/.snapshots");
+ mnt_fs_set_target(snapshots, "/" SNAPSHOTS_NAME);
char* options = mnt_fs_strdup_options(snapshots);
mnt_optstr_remove_option(&options, "defaults");
MntTable mnt_table(root_prefix);
mnt_table.parse_fstab();
- string mountpoint = (subvolume == "/" ? "" : subvolume) + "/.snapshots";
+ string mountpoint = (subvolume == "/" ? "" : subvolume) + "/" SNAPSHOTS_NAME;
libmnt_fs* snapshots = mnt_table.find_target(mountpoint, MNT_ITER_FORWARD);
if (!snapshots)
return;
#include "snapper/Exception.h"
#include "snapper/XAttributes.h"
#include "snapper/Acls.h"
+#include "snapper/SnapperDefines.h"
namespace snapper
bool
filter(const string& name)
{
- if (name == "/.snapshots")
+ if (name == "/" SNAPSHOTS_NAME)
return true;
return false;
void
Ext4::createConfig() const
{
- int r1 = mkdir((subvolume + "/.snapshots").c_str(), 0700);
+ int r1 = mkdir((subvolume + "/" SNAPSHOTS_NAME).c_str(), 0700);
if (r1 == 0)
{
- SystemCmd cmd1({ CHATTRBIN, "+x", subvolume + "/.snapshots" });
+ SystemCmd cmd1({ CHATTRBIN, "+x", subvolume + "/" SNAPSHOTS_NAME });
if (cmd1.retcode() != 0)
throw CreateConfigFailedException("chattr failed");
}
throw CreateConfigFailedException("mkdir failed");
}
- int r2 = mkdir((subvolume + "/.snapshots/.info").c_str(), 0700);
+ int r2 = mkdir((subvolume + "/" SNAPSHOTS_NAME "/.info").c_str(), 0700);
if (r2 == 0)
{
- SystemCmd cmd2({ CHATTRBIN, "-x", subvolume + "/.snapshots/.info" });
+ SystemCmd cmd2({ CHATTRBIN, "-x", subvolume + "/" SNAPSHOTS_NAME "/.info" });
if (cmd2.retcode() != 0)
throw CreateConfigFailedException("chattr failed");
}
void
Ext4::deleteConfig() const
{
- int r1 = rmdir((subvolume + "/.snapshots/.info").c_str());
+ int r1 = rmdir((subvolume + "/" SNAPSHOTS_NAME "/.info").c_str());
if (r1 != 0)
{
y2err("rmdir failed errno:" << errno << " (" << stringerror(errno) << ")");
throw DeleteConfigFailedException("rmdir failed");
}
- int r2 = rmdir((subvolume + "/.snapshots").c_str());
+ int r2 = rmdir((subvolume + "/" SNAPSHOTS_NAME).c_str());
if (r2 != 0)
{
y2err("rmdir failed errno:" << errno << " (" << stringerror(errno) << ")");
string
Ext4::snapshotFile(unsigned int num) const
{
- return (subvolume == "/" ? "" : subvolume) + "/.snapshots/" + decString(num);
+ return (subvolume == "/" ? "" : subvolume) + "/" SNAPSHOTS_NAME "/" + decString(num);
}
void
Lvm::createLvmConfig(const SDir& subvolume_dir, int mode) const
{
- int r1 = subvolume_dir.mkdir(".snapshots", mode);
+ int r1 = subvolume_dir.mkdir(SNAPSHOTS_NAME, mode);
if (r1 != 0 && errno != EEXIST)
{
y2err("mkdir failed errno:" << errno << " (" << strerror(errno) << ")");
try
{
- string path(subvolume_dir.fullname() + "/.snapshots");
+ string path(subvolume_dir.fullname() + "/" SNAPSHOTS_NAME);
con = selabel_handle->selabel_lookup(path, mode);
if (con)
{
SDir subvolume_dir = openSubvolumeDir();
- int r1 = subvolume_dir.unlink(".snapshots", AT_REMOVEDIR);
+ int r1 = subvolume_dir.unlink(SNAPSHOTS_NAME, AT_REMOVEDIR);
if (r1 != 0)
{
y2err("rmdir failed errno:" << errno << " (" << strerror(errno) << ")");
string
Lvm::snapshotDir(unsigned int num) const
{
- return (subvolume == "/" ? "" : subvolume) + "/.snapshots/" + decString(num) +
- "/snapshot";
+ return (subvolume == "/" ? "" : subvolume) + "/" SNAPSHOTS_NAME "/" + decString(num) +
+ "/" SNAPSHOT_NAME;
}
Lvm::openInfosDir() const
{
SDir subvolume_dir = openSubvolumeDir();
- SDir infos_dir(subvolume_dir, ".snapshots");
+ SDir infos_dir(subvolume_dir, SNAPSHOTS_NAME);
struct stat stat;
if (infos_dir.stat(&stat) != 0)
Lvm::openSnapshotDir(unsigned int num) const
{
SDir info_dir = openInfoDir(num);
- SDir snapshot_dir(info_dir, "snapshot");
+ SDir snapshot_dir(info_dir, SNAPSHOT_NAME);
return snapshot_dir;
}
SN_THROW(UnsupportedException());
SDir info_dir = openInfoDir(num);
- int r1 = info_dir.mkdir("snapshot", 0755);
+ int r1 = info_dir.mkdir(SNAPSHOT_NAME, 0755);
if (r1 != 0 && errno != EEXIST)
{
y2err("mkdir failed errno:" << errno << " (" << strerror(errno) << ")");
}
SDir info_dir = openInfoDir(num);
- info_dir.unlink("snapshot", AT_REMOVEDIR);
+ info_dir.unlink(SNAPSHOT_NAME, AT_REMOVEDIR);
SDir infos_dir = openInfosDir();
infos_dir.unlink(decString(num), AT_REMOVEDIR);
{
SDir info_dir = openInfoDir(num);
- if (!umount(info_dir, "snapshot"))
+ if (!umount(info_dir, SNAPSHOT_NAME))
SN_THROW(UmountSnapshotFailedException());
}
try
{
SDir subvol_dir = openSubvolumeDir();
- SDir infos_dir(subvol_dir, ".snapshots");
+ SDir infos_dir(subvol_dir, SNAPSHOTS_NAME);
if (infos_dir.restorecon(selabel_handle))
{
if (!skip_snapshot_dir)
{
- SFile snapshot_dir(info_dir, "snapshot");
+ SFile snapshot_dir(info_dir, SNAPSHOT_NAME);
snapshot_dir.restorecon(selabel_handle);
}
#define DEV_MAPPER_DIR "/dev/mapper"
+// parts of the path of snapshots
+// "/.snapshots/42/snapshot/" = "/SNAPSHOTS_NAME/42/snapshot/"
+
+#define SNAPSHOTS_NAME ".snapshots"
+#define SNAPSHOT_NAME "snapshot"
+
+
// commands
#define SH_BIN "/bin/sh"