image.c revision 10f9c75519671e7c7ab8993b54fe22da7c2d0c38
/*-*- 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 "path-util.h"
#include "image.h"
static const char image_search_path[] =
if (!i)
return NULL;
free(i);
return NULL;
}
static int image_new(
ImageType t,
const char *name,
const char *path,
bool read_only,
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;
path_kill_slashes(i->path);
}
*ret = i;
i = NULL;
return 0;
}
int r;
/* We explicitly *do* follow symlinks here, since we want to
* them normally. */
return -errno;
if (!ret)
return 1;
/* btrfs subvolumes have inode 256 */
if (fd < 0)
return -errno;
return -errno;
/* It's a btrfs subvolume */
if (r < 0)
return r;
r = image_new(IMAGE_SUBVOLUME,
name,
path,
0,
ret);
if (r < 0)
return r;
return 1;
}
}
/* It's just a normal directory. */
r = image_new(IMAGE_DIRECTORY,
name,
path,
false,
0,
0,
ret);
if (r < 0)
return r;
return 1;
const char *truncated;
/* It's a GPT block device */
if (!ret)
return 1;
path,
ret);
if (r < 0)
return r;
return 1;
}
return 0;
}
const char *path;
int r;
/* There are no images with invalid names */
if (!image_name_is_valid(name))
return 0;
if (!d) {
continue;
return -errno;
}
if (r == 0 || r == -ENOENT)
continue;
if (r < 0)
return r;
return 1;
}
return 0;
};
int image_discover(Hashmap *h) {
const char *path;
int r;
assert(h);
if (!d) {
return 0;
return -errno;
}
continue;
continue;
if (r == 0 || r == -ENOENT)
continue;
if (r < 0)
return r;
if (r < 0)
return r;
}
}
return 0;
}
Image *i;
while ((i = hashmap_steal_first(map)))
image_unref(i);
}
static const char* const image_type_table[_IMAGE_TYPE_MAX] = {
[IMAGE_DIRECTORY] = "directory",
[IMAGE_SUBVOLUME] = "subvolume",
[IMAGE_GPT] = "gpt",
};