image.c revision cd61c3bfd718fb398cc53ced906266a9297782c9
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2013 Lennart Poettering
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include "strv.h"
#include "utf8.h"
#include "btrfs-util.h"
#include "image.h"
#include "bus-label.h"
if (!i)
return NULL;
free(i);
return NULL;
}
static int add_image(
Hashmap *h,
ImageType t,
const char *name,
const char *path,
bool read_only,
int r;
assert(h);
assert(t >= 0);
assert(t < _IMAGE_TYPE_MAX);
if (!i)
return -ENOMEM;
i->type = t;
if (!i->name)
return -ENOMEM;
if (path) {
if (!i->path)
return -ENOMEM;
}
r = hashmap_put(h, i->name, i);
if (r < 0)
return r;
i = NULL;
return 0;
}
int image_discover(Hashmap *h) {
const char *path;
int r;
assert(h);
if (!d) {
return 0;
return -errno;
}
continue;
/* Temporary files for atomically creating new files */
continue;
continue;
continue;
continue;
/* We explicitly *do* follow symlinks here,
* since we want to allow symlinking trees
* normally. */
continue;
return -errno;
}
/* btrfs subvolumes have inode 256 */
if (fd < 0) {
continue;
return -errno;
}
return -errno;
int ro;
/* It's a btrfs subvolume */
if (ro < 0)
return ro;
/* r = btrfs_subvol_get_btime(fd, &btime); */
/* if (r < 0) */
/* return r; */
r = add_image(h,
path,
ro,
0,
btime);
if (r < 0)
return r;
continue;
}
}
/* It's just a normal directory. */
r = add_image(h,
path,
false,
0,
0);
if (r < 0)
return r;
/* It's a GPT block device */
r = add_image(h,
path,
0);
if (r < 0)
return r;
}
}
}
return 0;
}
Image *i;
while ((i = hashmap_steal_first(map)))
image_unref(i);
}
char *image_bus_path(const char *name) {
_cleanup_free_ char *e = NULL;
e = bus_label_escape(name);
if (!e)
return NULL;
return strappend("/org/freedesktop/machine1/image/", e);
}
static const char* const image_type_table[_IMAGE_TYPE_MAX] = {
[IMAGE_DIRECTORY] = "directory",
[IMAGE_SUBVOLUME] = "subvolume",
[IMAGE_GPT] = "gpt",
};