forked from yutianzeabc/File-System-Design
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmy_cd.c
More file actions
48 lines (40 loc) · 1.18 KB
/
Copy pathmy_cd.c
File metadata and controls
48 lines (40 loc) · 1.18 KB
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
//
// Created by 孙鹏 on 2021/1/4.
//
#ifndef FILE_SYSTEM_DESIGN_CD
#define FILE_SYSTEM_DESIGN_CD
#include "fs.h"
#include "inode.h"
#include "c_operator.h"
#include <stdio.h>
#include <string.h>
void my_cd(char *dirname)
{
inode *curr_dir_point = NULL;
curr_dir_point = get_inode_point(curr_dir_inode);
int curr_dir_index;
curr_dir_index = curr_dir_point->direction_chart_id;
index_element *curr_dir_index_start = NULL;
curr_dir_index_start = virtualDisk + curr_dir_index*BLOCK_SIZE;
fcb *curr_dir_fcb = NULL;
curr_dir_fcb = virtualDisk + curr_dir_index_start->physical_id*BLOCK_SIZE;
int i;
for (i = 0; i < curr_dir_point->length/ sizeof(fcb); ++i)
{
if(strcmp(dirname, curr_dir_fcb->filename)==0)
{
inode *temp;
temp = get_inode_point(curr_dir_fcb->i_ino);
if(temp->attribute==1)
break;
}
curr_dir_fcb++;
} //遍历当前目录,找到文件名匹配且文件属性为1
if (i==(curr_dir_point->length/ sizeof(fcb)))
{
printf("\n%s Not exist\n",dirname);
return;
}
curr_dir_inode = curr_dir_fcb->i_ino;
}
#endif