-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcd.c
97 lines (87 loc) · 1.88 KB
/
cd.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*Authors: Stephen Brikiatis and Kelly Morrissey
Class: CSI-385-01
Assignment: FAT12
Date Assigned: 08/30/16
Due Date: 11/2/16
Description: This code holds the control of the cd command in relation to the FAT12.
Certification of Authenticity:
We certify that this assignment is entirely our own work.
*/
#include <stdio.h>
int main(int argc, char *argv[])
{
char *fileSystem;
char *currentDir;
int currentSector;
char dirName[8] = " " ;
int position = 0x00;//starting postion of
int fileIndicator; //This holds the check for if the found file is a directory or not
int result; //for the do while loop 1 is found, -1 is error, 2 is doesn't exist
if(argc > 2)
{
printf("Wrong number of arguments.");
}
else if(argc == 1)
{
currentDir = "/";
currentSector = 32;
return 0;
}
int i;
result = 0;
do
{
for(i = 0; i < 8; i++)
{
dirName[i] = currentDir[position+i];
}
fileIndicator = currentDir[position+0x10];
if(dirName == argv[1])
{
if(fileIndicator == 0x10)
{
result = 1;
}
else
{
result = -1;
}
}
else if(dirName[0] == 0x00 | dirName[0] == 0xF6)
{
result = 2;
}
else
{
position = position + 0x20;
}
}while(result == 0);
if(result == 1)
{
int mostSignificantByte = (((int) currentDir[position+0x1B]) << 8);
int leastSignificantByte = ((int) currentDir[position+0x1A]);
currentSector = mostSignificantByte | leastSignificantByte;
if(currentSector == 0)
{
currentSector == 19;
}
else
{
currentSector = currentSector + 19;
}
}
else if(result == 2)
{
printf("There is no directory with that name.");
}
else if(result == -1)
{
printf("No file has this name.");
}
else
{
printf("What is Toronto?????");
}
//mmap stuff needs to go here.
return 0;
}