#include "hammer.h"
void
hammer_cmd_get_version(char **av, int ac)
{
struct hammer_ioc_version version;
char wip[16];
int fd;
if (ac != 1) {
errx(1, "hammer version - expected a single <fs> path arg");
}
fd = open(av[0], O_RDONLY);
if (fd < 0) {
err(1, "hammer version: unable to access %s", av[0]);
}
bzero(&version, sizeof(version));
if (ioctl(fd, HAMMERIOC_GET_VERSION, &version) < 0) {
err(1, "hammer version ioctl");
}
HammerVersion = version.cur_version;
snprintf(wip, 16, "%d", version.wip_version);
printf("min=%d wip=%s max=%d current=%d description=\"%s\"\n",
version.min_version,
(version.wip_version > version.max_version) ? "none" : wip,
version.max_version,
version.cur_version,
version.description
);
if (QuietOpt == 0) {
version.cur_version = 1;
printf("available versions:\n");
while (ioctl(fd, HAMMERIOC_GET_VERSION, &version) == 0) {
printf(" %d\t%s\t%s\n",
version.cur_version,
(version.cur_version < version.wip_version ?
"NORM" : "WIP "),
version.description);
++version.cur_version;
}
}
close(fd);
}
void
hammer_cmd_set_version(char **av, int ac)
{
struct hammer_ioc_version version;
int fd;
int overs;
int nvers;
if (ac < 2 || ac > 3 || (ac == 3 && strcmp(av[2], "force") != 0)) {
errx(1, "hammer version-upgrade: expected <fs> vers# [force]");
}
fd = open(av[0], O_RDONLY);
if (fd < 0) {
err(1, "hammer version-upgrade: unable to access %s", av[0]);
}
bzero(&version, sizeof(version));
if (ioctl(fd, HAMMERIOC_GET_VERSION, &version) < 0) {
err(1, "hammer ioctl");
}
HammerVersion = version.cur_version;
overs = version.cur_version;
version.cur_version = strtol(av[1], NULL, 0);
nvers = version.cur_version;
if (ioctl(fd, HAMMERIOC_GET_VERSION, &version) < 0) {
err(1, "hammer ioctl");
}
HammerVersion = version.cur_version;
if (version.cur_version >= version.wip_version && ac != 3) {
errx(1, "The requested version is a work-in-progress"
" and requires the 'force' directive");
}
if (ioctl(fd, HAMMERIOC_SET_VERSION, &version) < 0) {
err(1, "hammer version-upgrade ioctl");
}
if (version.head.error) {
errx(1, "hammer version-upgrade ioctl");
}
printf("hammer version-upgrade: succeeded\n");
if (overs < 3 && nvers >= 3) {
printf("NOTE! Please run 'hammer cleanup' to convert the\n"
"<pfs>/snapshots directories to the new meta-data\n"
"format. Once converted configuration data will\n"
"no longer resides in <pfs>/snapshots and you can\n"
"even rm -rf it entirely if you want.\n");
}
close(fd);
}