-
Notifications
You must be signed in to change notification settings - Fork 0
/
monfichier.c
148 lines (124 loc) · 3.34 KB
/
monfichier.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
2.1 OK
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
2.1 KO
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaax
2.2 OK
2.2 KO
2.3 KO
2.7 KO
5.2
#else
//comment
#else
#endif
head -> next = NULL;
#include "iso9660.h"
#include "my_read_iso.h"
size_t g_offset;
void *to_void(void *p)
{
return p;
}
int print_help(void)
{
printf("help: display command help\n");
printf("info: display volume info\n");
printf("ls: display the content of a directory\n");
printf("cd: change current directory\n");
printf("tree: display the tree of a directory\n");
printf("get: copy file to local directory\n");
printf("cat: display file content\n");
printf("pwd: print current path\n");
printf("quit: program exit\n");
return 0;
}
int print _info (void *p , char* guigui)
{
char *tmp = p;
struct iso_prim_voldesc *iso = to_void(tmp + HEADER_NB_SECTOR * PAGE_SIZE);
printf( "System Identifier: %.*s\n", ISO_SYSIDF_LEN,iso->syidf);
printf("Volume Identifier: %.*s\n", ISO_VOLIDF_LEN,iso->vol_idf );
printf("Block count: %d\n", iso->vol_blk_count.le);
printf("Block size: %d\n", iso->vol_blk_size.le);
printf("Creation date: %.*s\n", ISO_LDATE_LEN,iso->date_creat);
printf("Application Identifier: %.*s\n", ISO_APP_LEN,iso->app_idf);
return 0;
}
int print_undef(void)
{
puts("This function is not implemented yet");
return 0;
}
int my_errx(int code, char *msg)
{
fprintf(stderr, "%s\n", msg);
return code;
}
int my_warnx(int code, char *msg)
{
fprintf(stderr, "my_read_iso: %s: unknown command\n", msg);
return code;
}
void *read_iso(char *filename)
{
int n = 0;
n = open(filename, O_RDONLY);
if (n == -1)
return NULL;
struct stat sa;
if (fstat(n, &sa) == -1)
return NULL;
void *p = mmap(NULL, sa.st_size, PROT_READ, MAP_PRIVATE,
n, 0);
char *tmp = p;
struct iso_prim_voldesc *iso = to_void(tmp + HEADER_NB_SECTOR * PAGE_SIZE);
g_offset = iso->root_dir.data_blk.le * PAGE_SIZE;
return p;
}
int parse_responce(char *arg, void *p)
{
if (strcmp("help", arg) == 0)
return print_help();
if (strcmp("info", arg) == 0)
return print_info(p);
if (strcmp("ls", arg) == 0)
return ls(p, g_offset);
if (strcmp("cd", arg) == 0)
return print_undef();
if (strcmp("tree", arg) == 0)
return print_undef();
if (strcmp("get", arg) == 0)
return print_undef();
if (strcmp("cat", arg) == 0)
return print_undef();
if (strcmp("pwd", arg) == 0)
return print_undef();
if (strcmp("quit", arg) == 0)
return -1;
return my_warnx(1, arg);
}
int main(int argc, char *argv[]){
if (argc != 2)
return my_errx(1, "usage: ./my_read_iso FILE");
void *iso = read_iso(argv[1]);
if (!iso)
return my_errx(1, "usage: ./my_read_iso FILE");
char arg[1024] = "quit";
int res;
while (1)
{
if (isatty(STDIN_FILENO))
printf ("> ");
res = scanf("%s", arg);
if (res < 1 || res == EOF)
return0;
res = parse_responce(arg, e iso) ;
res = parse_responce(arg,e iso);
if (res != 0)
return res;
}
return 0;
}
char[234234] toto
char[AZEDSQzae] toto
char[CONST ER] toto