embox

Форк
0
/
fat_dvfs.c 
92 строки · 1.9 Кб
1
/**
2
 * @file
3
 * @brief Implementation of FAT driver for DVFS
4
 *
5
 * @date   11 Apr 2015
6
 * @author Denis Deryugin <deryugin.denis@gmail.com>
7
 */
8

9
#include <limits.h>
10
#include <stddef.h>
11
#include <assert.h>
12
#include <sys/stat.h>
13
#include <string.h>
14

15
#include <fs/inode.h>
16
#include <fs/super_block.h>
17

18
#include "fat.h"
19

20
extern int fat_alloc_inode_priv(struct inode *inode, struct fat_dirent *de);
21
extern int fat_destroy_inode(struct inode *inode);
22

23
/* @brief Figure out if node at specific path exists or not
24
 * @note  Assume dir is root
25
 * @note IMPORTANT: this functions should not be calls in the middle of iterate,
26
 * as it wipes dirinfo content
27
 *
28
 * @param name Full path to the extected node
29
 * @param dir  Inode of corresponding parent directory
30
 *
31
 * @return Pointer of inode or NULL if not found
32
 */
33
struct inode *fat_ilookup(struct inode *node, char const *name, struct inode const *dir) {
34
	struct dirinfo *di;
35
	struct fat_dirent de;
36
	uint8_t tmp_ent;
37
	uint8_t tmp_sec;
38
	uint32_t tmp_clus;
39
	char tmppath[128];
40
	int found = 0;
41

42
	assert(name);
43
	assert(S_ISDIR(dir->i_mode));
44

45
	di = inode_priv(dir);
46
	assert(di);
47

48
	tmp_ent = di->currententry;
49
	tmp_sec = di->currentsector;
50
	tmp_clus = di->currentcluster;
51
	fat_reset_dir(di);
52

53
	if (read_dir_buf(di)) {
54
		goto err_out;
55
	}
56

57
	while (!fat_get_next_long(di, &de, tmppath)) {
58
		if (!strncmp(tmppath, name, NAME_MAX - 1)) {
59
			found = 1;
60
			break;
61
		}
62
	}
63

64
	if (!found) {
65
		goto err_out;
66
	}
67

68
	if (fat_alloc_inode_priv(node, &de)) {
69
		goto err_out;
70
	}
71

72
	if (fat_fill_inode(node, &de, di)) {
73
		fat_destroy_inode(node);
74
		goto err_out;
75
	}
76

77
	goto succ_out;
78
err_out:
79
	node = NULL;
80
succ_out:
81
	di->currentcluster = tmp_clus;
82
	di->currententry = tmp_ent;
83
	di->currentsector = tmp_sec;
84
	return node;
85
}
86

87
extern struct idesc *dvfs_file_open_idesc(struct lookup *lookup, int __oflag);
88
extern int fat_destroy_inode(struct inode *inode);
89
struct super_block_operations fat_sbops = {
90
	.open_idesc    = dvfs_file_open_idesc,
91
	.destroy_inode = fat_destroy_inode,
92
};
93

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

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

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

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