glusterfs

Форк
0
/
mount_util.c 
64 строки · 1.3 Кб
1
/*
2
  FUSE: Filesystem in Userspace
3
  Copyright (C) 2001-2007  Miklos Szeredi <miklos@szeredi.hu>
4

5
  This program can be distributed under the terms of the GNU LGPLv2.
6
  See 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

16
int fuse_mnt_check_empty(const char *progname, const char *mnt,
17
			 mode_t rootmode, off_t rootsize)
18
{
19
	int isempty = 1;
20

21
	if (S_ISDIR(rootmode)) {
22
		struct dirent *ent;
23
		DIR *dp = opendir(mnt);
24
		if (dp == NULL) {
25
			fprintf(stderr,
26
				"%s: failed to open mountpoint for reading: %s\n",
27
				progname, strerror(errno));
28
			return -1;
29
		}
30
		while ((ent = readdir(dp)) != NULL) {
31
			if (strcmp(ent->d_name, ".") != 0 &&
32
			    strcmp(ent->d_name, "..") != 0) {
33
				isempty = 0;
34
				break;
35
			}
36
		}
37
		closedir(dp);
38
	} else if (rootsize)
39
		isempty = 0;
40

41
	if (!isempty) {
42
		fprintf(stderr, "%s: mountpoint is not empty\n", progname);
43
		fprintf(stderr, "%s: if you are sure this is safe, use the 'nonempty' mount option\n", progname);
44
		return -1;
45
	}
46
	return 0;
47
}
48

49
int fuse_mnt_check_fuseblk(void)
50
{
51
	char buf[256];
52
	FILE *f = fopen("/proc/filesystems", "r");
53
	if (!f)
54
		return 1;
55

56
	while (fgets(buf, sizeof(buf), f))
57
		if (strstr(buf, "fuseblk\n")) {
58
			fclose(f);
59
			return 1;
60
		}
61

62
	fclose(f);
63
	return 0;
64
}
65

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.