embox
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
20extern int fat_alloc_inode_priv(struct inode *inode, struct fat_dirent *de);21extern 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*/
33struct inode *fat_ilookup(struct inode *node, char const *name, struct inode const *dir) {34struct dirinfo *di;35struct fat_dirent de;36uint8_t tmp_ent;37uint8_t tmp_sec;38uint32_t tmp_clus;39char tmppath[128];40int found = 0;41
42assert(name);43assert(S_ISDIR(dir->i_mode));44
45di = inode_priv(dir);46assert(di);47
48tmp_ent = di->currententry;49tmp_sec = di->currentsector;50tmp_clus = di->currentcluster;51fat_reset_dir(di);52
53if (read_dir_buf(di)) {54goto err_out;55}56
57while (!fat_get_next_long(di, &de, tmppath)) {58if (!strncmp(tmppath, name, NAME_MAX - 1)) {59found = 1;60break;61}62}63
64if (!found) {65goto err_out;66}67
68if (fat_alloc_inode_priv(node, &de)) {69goto err_out;70}71
72if (fat_fill_inode(node, &de, di)) {73fat_destroy_inode(node);74goto err_out;75}76
77goto succ_out;78err_out:79node = NULL;80succ_out:81di->currentcluster = tmp_clus;82di->currententry = tmp_ent;83di->currentsector = tmp_sec;84return node;85}
86
87extern struct idesc *dvfs_file_open_idesc(struct lookup *lookup, int __oflag);88extern int fat_destroy_inode(struct inode *inode);89struct super_block_operations fat_sbops = {90.open_idesc = dvfs_file_open_idesc,91.destroy_inode = fat_destroy_inode,92};93