embox

Форк
0
/
mount_point.c 
87 строк · 2.0 Кб
1
/**
2
 * @brief
3
 *
4
 * @date 02.01.24
5
 * @author Aleksey Zhmulin
6
 */
7

8
#include <assert.h>
9
#include <errno.h>
10
#include <stdbool.h>
11
#include <string.h>
12

13
#include <lib/libds/dlist.h>
14
#include <vfs/core.h>
15

16
void vfs_mount_point_get_first_bind(const struct inode *mount_point,
17
    struct inode *lookup) {
18
	memcpy(lookup, mount_point, sizeof(struct inode));
19

20
	while (vfs_mount_point_get_prev_bind(lookup, lookup)) {}
21
}
22

23
void vfs_mount_point_get_first(const struct inode *mount_point,
24
    struct inode *lookup) {
25
	memcpy(lookup, mount_point, sizeof(struct inode));
26

27
	while (vfs_mount_point_get_prev(lookup, lookup)) {}
28
}
29

30
void vfs_mount_point_get_last(const struct inode *mount_point,
31
    struct inode *lookup) {
32
	memcpy(lookup, mount_point, sizeof(struct inode));
33

34
	while (vfs_mount_point_get_next(lookup, lookup)) {}
35
}
36

37
bool vfs_mount_point_get_next(const struct inode *mount_point,
38
    struct inode *lookup) {
39
	struct super_block *sb;
40

41
	assert(!vfs_inode_is_bad(mount_point));
42

43
	dlist_foreach_entry(sb, &mount_point->sb->mount_list, list_item) {
44
		if (mount_point->ino == sb->mount_point.ino) {
45
			lookup->ino = VFS_MPT_INO;
46
			lookup->sb = sb;
47
			return true;
48
		}
49
	}
50

51
	return false;
52
}
53

54
bool vfs_mount_point_get_prev(const struct inode *mount_point,
55
    struct inode *lookup) {
56
	assert(!vfs_inode_is_bad(mount_point));
57

58
	if (!vfs_inode_is_mount_point(mount_point)
59
	    || vfs_inode_is_root(mount_point)) {
60
		return false;
61
	}
62

63
	memcpy(lookup, &mount_point->sb->mount_point, sizeof(struct inode));
64

65
	return true;
66
}
67

68
bool vfs_mount_point_get_prev_bind(const struct inode *mount_point,
69
    struct inode *lookup) {
70
	assert(!vfs_inode_is_bad(mount_point));
71

72
	if (!mount_point->sb->bind_mount) {
73
		return false;
74
	}
75

76
	return vfs_mount_point_get_prev(mount_point, lookup);
77
}
78

79
void vfs_mount_point_add_next(const struct inode *mount_point,
80
    struct super_block *sb) {
81
	struct inode mpt;
82

83
	vfs_mount_point_get_last(mount_point, &mpt);
84

85
	dlist_add_next(&sb->list_item, &mpt.sb->mount_list);
86
	memcpy(&sb->mount_point, &mpt, sizeof(struct inode));
87
}
88

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

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

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

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