glusterfs
1/*
2FUSE: Filesystem in Userspace
3Copyright (C) 2001-2007 Miklos Szeredi <miklos@szeredi.hu>
4
5This program can be distributed under the terms of the GNU LGPLv2.
6See the file COPYING.LIB.
7*/
8
9#include <dirent.h>10#include <stdio.h>11#include <string.h>12#include <errno.h>13#include <sys/types.h>14#include <sys/stat.h>15
16int fuse_mnt_check_empty(const char *progname, const char *mnt,17mode_t rootmode, off_t rootsize)18{
19int isempty = 1;20
21if (S_ISDIR(rootmode)) {22struct dirent *ent;23DIR *dp = opendir(mnt);24if (dp == NULL) {25fprintf(stderr,26"%s: failed to open mountpoint for reading: %s\n",27progname, strerror(errno));28return -1;29}30while ((ent = readdir(dp)) != NULL) {31if (strcmp(ent->d_name, ".") != 0 &&32strcmp(ent->d_name, "..") != 0) {33isempty = 0;34break;35}36}37closedir(dp);38} else if (rootsize)39isempty = 0;40
41if (!isempty) {42fprintf(stderr, "%s: mountpoint is not empty\n", progname);43fprintf(stderr, "%s: if you are sure this is safe, use the 'nonempty' mount option\n", progname);44return -1;45}46return 0;47}
48
49int fuse_mnt_check_fuseblk(void)50{
51char buf[256];52FILE *f = fopen("/proc/filesystems", "r");53if (!f)54return 1;55
56while (fgets(buf, sizeof(buf), f))57if (strstr(buf, "fuseblk\n")) {58fclose(f);59return 1;60}61
62fclose(f);63return 0;64}
65