Skip to content

Commit

Permalink
check for subvolume
Browse files Browse the repository at this point in the history
fixed syntax errors
  • Loading branch information
jsuchome committed Sep 9, 2013
1 parent db12973 commit 7073052
Showing 1 changed file with 37 additions and 5 deletions.
42 changes: 37 additions & 5 deletions agent-snapper/src/SnapperAgent.cc
Expand Up @@ -141,7 +141,7 @@ YCPBoolean btrfs_ioctl_call(string path, int request)
memset(&args, 0, sizeof(args));
strncpy(args.name, name.c_str(), sizeof(args.name) - 1);

ret = YCPBoolean (ioctl(dirfd, request, &args) == 0);
YCPBoolean ret = YCPBoolean (ioctl(dirfd, request, &args) == 0);

close(dirfd);

Expand Down Expand Up @@ -218,6 +218,34 @@ YCPValue SnapperAgent::Read(const YCPPath &path, const YCPValue& arg, const YCPV

if (path->length() == 1) {

/**
* Read (.snapper.is_subvolume, "path/to/dir") -> returns true if given directory is a subvolume
*/
if (PC(0) == "is_subvolume") {

string path = "";
if (arg->isString()) {
path = arg->asString()->value();
}

if (path == "") {
y2error ("path attribute missing!");
return YCPBoolean (false);
}

struct stat status;
if (stat(path.c_str(), &status) != 0) {
y2error ("status of '%s' cannot be obtained", path.c_str());
return YCPBoolean (false);
}
if (!S_ISDIR(status.st_mode)) {
y2error ("'%s' is not a directory", path.c_str());
return YCPBoolean (false);
}

// see Btrfs::is_subvolume
return YCPBoolean (status.st_ino == 256);
}
if (PC(0) == "configs") {
YCPList retlist;

Expand Down Expand Up @@ -472,6 +500,9 @@ YCPValue SnapperAgent::Execute(const YCPPath &path, const YCPValue& arg,

return ret;
}
/**
* Execute(.snapper.delete_config, $[ "config_name" : name $] -> deletes given configuration
*/
else if (PC(0) == "delete_config") {

string name = getValue(argmap, YCPString("config_name"), "");
Expand Down Expand Up @@ -620,20 +651,21 @@ YCPValue SnapperAgent::Execute(const YCPPath &path, const YCPValue& arg,
}
else if (path->length() == 2 && PC(0) == "subvolume") {

// create new subvolume, argument 'path' must be provided
// create new subvolume; argument 'path' must be provided
if (PC(1) == "create")
{
return btrfs_ioctl_call(
getValue(argmap, YCPString("path"), "")
getValue(argmap, YCPString("path"), ""),
BTRFS_IOC_SUBVOL_CREATE
);
}
// delete existing subvolume; argument 'path' must be provided
// (delete_config must be called before subvolume.delete)
else if (PC(1) == "delete") {

return btrfs_ioctl_call(
getValue(argmap, YCPString("path"), "")
getValue(argmap, YCPString("path"), ""),
BTRFS_IOC_SNAP_DESTROY
BTRFS_IOC_SUBVOL_CREATE
);
}
}
Expand Down

0 comments on commit 7073052

Please sign in to comment.