-
Notifications
You must be signed in to change notification settings - Fork 0
/
fs_dentry.c
75 lines (61 loc) · 1.15 KB
/
fs_dentry.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "oscafs.h"
//Error value
#define NO_DENTRY -1
str_t dentry[NUM_DENTRY];
void clear_entry(int i)
{
dentry[i].str[0] = '\0';
dentry[i].num = 0;
}
void init_dentry(void)
{
// Write "" in each dentry row
for (int i = 0; i < NUM_DENTRY; i++)
{
//snprintf(dentry[i].str, STR_LEN, "");
clear_entry(i);
}
}
str_t *get_dentry()
{
return dentry;
}
char *return_entry(int i)
{
return dentry[i].str;
}
int check_entry(int i)
{
return dentry[i].str[0] == '\0';
}
int return_first_entry()
{
for (int i = 0; i < NUM_DENTRY; i++)
if (check_entry(i))
return i;
return NO_DENTRY;
}
/* copy string str into entry i
return length of copied string
*/
int write_entry(int i, char *str)
{
char *dest = strncpy(dentry[i].str, str, NAME_LEN);
//dentry[i].str[NAME_LEN - 1] = '\0';
return strlen(dest);
}
int write_first_free(char *str)
{
int i = return_first_entry();
if (i >= 0)
write_entry(i, str);
return i;
}
int write_firstblock_num(int i)
{
dentry[i].num = alloc_block();
return dentry[i].num;
}