Skip to content

Commit

Permalink
utils: add has_fs_type() + is_fs_type()
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
  • Loading branch information
Christian Brauner authored and stgraber committed Aug 15, 2017
1 parent 7b48c59 commit b692229
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/lxc/utils.c
Expand Up @@ -2383,3 +2383,25 @@ void *must_realloc(void *orig, size_t sz)

return ret;
}

bool is_fs_type(const struct statfs *fs, fs_type_magic magic_val)
{
return (fs->f_type == (fs_type_magic)magic_val);
}

bool has_fs_type(const char *path, fs_type_magic magic_val)
{
bool has_type;
int ret;
struct statfs sb;

ret = statfs(path, &sb);
if (ret < 0)
return false;

has_type = is_fs_type(&sb, magic_val);
if (!has_type && magic_val == RAMFS_MAGIC)
WARN("When the ramfs it a tmpfs statfs() might report tmpfs");

return has_type;
}
6 changes: 6 additions & 0 deletions src/lxc/utils.h
Expand Up @@ -36,6 +36,7 @@
#include <linux/loop.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <sys/vfs.h>

#include "initutils.h"

Expand Down Expand Up @@ -386,4 +387,9 @@ char *must_copy_string(const char *entry);
/* Re-alllocate a pointer, do not fail */
void *must_realloc(void *orig, size_t sz);

/* __typeof__ should be safe to use with all compilers. */
typedef __typeof__(((struct statfs *)NULL)->f_type) fs_type_magic;
bool has_fs_type(const char *path, fs_type_magic magic_val);
bool is_fs_type(const struct statfs *fs, fs_type_magic magic_val);

#endif /* __LXC_UTILS_H */

0 comments on commit b692229

Please sign in to comment.