1 | #ifndef HARDDISK_H |
---|
2 | #define HARDDISK_H |
---|
3 | |
---|
4 | char* blocktogb(unsigned long size) |
---|
5 | { |
---|
6 | char* buf = NULL; |
---|
7 | |
---|
8 | buf = malloc(MINMALLOC); |
---|
9 | if(buf == NULL) |
---|
10 | { |
---|
11 | err("no mem"); |
---|
12 | return NULL; |
---|
13 | } |
---|
14 | snprintf(buf, MINMALLOC, "%.2f", (float)size / 2 / 1024 / 1024); //size is in 512KB blocks |
---|
15 | return buf; |
---|
16 | } |
---|
17 | |
---|
18 | struct hdd* gethdd(char* device) |
---|
19 | { |
---|
20 | debug(1000, "in"); |
---|
21 | struct hdd *node = hdd; |
---|
22 | |
---|
23 | while(node != NULL) |
---|
24 | { |
---|
25 | if(ostrcmp(node->device, device) == 0) |
---|
26 | { |
---|
27 | debug(1000, "out"); |
---|
28 | return node; |
---|
29 | } |
---|
30 | node = node->next; |
---|
31 | } |
---|
32 | debug(100, "hdd not found (device=%s)", device); |
---|
33 | return NULL; |
---|
34 | } |
---|
35 | |
---|
36 | unsigned long hddgetsize(char* device, char* partition) |
---|
37 | { |
---|
38 | char* file = NULL; |
---|
39 | unsigned long size = 0; |
---|
40 | |
---|
41 | file = ostrcat(file , "/sys/block/", 1, 0); |
---|
42 | file = ostrcat(file , device, 1, 0); |
---|
43 | if(partition != NULL) |
---|
44 | { |
---|
45 | file = ostrcat(file , "/", 1, 0); |
---|
46 | file = ostrcat(file , partition, 1, 0); |
---|
47 | } |
---|
48 | file = ostrcat(file , "/size", 1, 0); |
---|
49 | size = readsysul(file, 1); |
---|
50 | debug(80, "file: %s, size: %lu", file, size); |
---|
51 | free(file); file = NULL; |
---|
52 | |
---|
53 | return size; |
---|
54 | } |
---|
55 | |
---|
56 | char* hddgetvendor(char* device) |
---|
57 | { |
---|
58 | char* file = NULL, *vendor = NULL; |
---|
59 | |
---|
60 | file = ostrcat(file , "/sys/block/", 1, 0); |
---|
61 | file = ostrcat(file , device, 1, 0); |
---|
62 | file = ostrcat(file , "/device/vendor", 1, 0); |
---|
63 | vendor = strstrip(readsys(file, 1)); |
---|
64 | debug(80, "file: %s, vendor: %s", file, vendor); |
---|
65 | free(file); file = NULL; |
---|
66 | |
---|
67 | return vendor; |
---|
68 | } |
---|
69 | |
---|
70 | char* hddgetmodel(char* device) |
---|
71 | { |
---|
72 | char* file = NULL, *model = NULL; |
---|
73 | |
---|
74 | file = ostrcat(file , "/sys/block/", 1, 0); |
---|
75 | file = ostrcat(file , device, 1, 0); |
---|
76 | file = ostrcat(file , "/device/model", 1, 0); |
---|
77 | model = strstrip(readsys(file, 1)); |
---|
78 | debug(80, "file: %s, model: %s", file, model); |
---|
79 | free(file); file = NULL; |
---|
80 | |
---|
81 | return model; |
---|
82 | } |
---|
83 | |
---|
84 | int hddgetremovable(char* device) |
---|
85 | { |
---|
86 | char* file = NULL; |
---|
87 | int removable = 0; |
---|
88 | |
---|
89 | file = ostrcat(file , "/sys/block/", 1, 0); |
---|
90 | file = ostrcat(file , device, 1, 0); |
---|
91 | file = ostrcat(file , "/removable", 1, 0); |
---|
92 | removable = readsysul(file, 1); |
---|
93 | debug(80, "file: %s, removable: %d", file, removable); |
---|
94 | free(file); file = NULL; |
---|
95 | |
---|
96 | return removable; |
---|
97 | } |
---|
98 | |
---|
99 | void screenfilesystem(char* dev) |
---|
100 | { |
---|
101 | int i, rcret = 0, count = 3; |
---|
102 | struct skin* screen = getscreen("harddisk_main"); |
---|
103 | struct skin* listbox = getscreennode(screen, "listbox"); |
---|
104 | struct skin* tmp = NULL; |
---|
105 | char* tmpstr = NULL, *tmpstr1 = NULL; |
---|
106 | |
---|
107 | delmarkedscreennodes(screen, 1); |
---|
108 | listbox->aktpage = -1; |
---|
109 | listbox->aktline = 1; |
---|
110 | changetitle(screen, "Harddisk Format - Filesystem"); |
---|
111 | |
---|
112 | if(status.expertmodus > 9) count = 4; |
---|
113 | |
---|
114 | for(i = 0; i < count; i++) |
---|
115 | { |
---|
116 | tmp = addlistbox(screen, listbox, tmp, 1); |
---|
117 | if(tmp != NULL) |
---|
118 | { |
---|
119 | if(i == 0) tmpstr = "ext2"; |
---|
120 | else if(i == 1) tmpstr = "ext3"; |
---|
121 | else if(i == 2) tmpstr = "jfs"; |
---|
122 | else if(i == 3) tmpstr = "vfat"; |
---|
123 | tmpstr1 = ostrcat(tmpstr1, getconfig("skinpath", NULL), 1, 0); |
---|
124 | tmpstr1 = ostrcat(tmpstr1, "/skin/ext2.png", 1, 0); |
---|
125 | tmpstr1 = ostrcat(tmpstr1, "/skin/", 1, 0); |
---|
126 | tmpstr1 = ostrcat(tmpstr1, tmpstr, 1, 0); |
---|
127 | tmpstr1 = ostrcat(tmpstr1, ".png", 1, 0); |
---|
128 | |
---|
129 | if(!file_exist(tmpstr1)) |
---|
130 | { |
---|
131 | free(tmpstr1); tmpstr1 = NULL; |
---|
132 | tmpstr1 = ostrcat(tmpstr1, getconfig("skinpath", NULL), 1, 0); |
---|
133 | tmpstr1 = ostrcat(tmpstr1, "/skin/default.png", 1, 0); |
---|
134 | } |
---|
135 | changepic(tmp, tmpstr1); |
---|
136 | free(tmpstr1); tmpstr1 = NULL; |
---|
137 | |
---|
138 | changetext(tmp, tmpstr); |
---|
139 | changename(tmp, tmpstr); |
---|
140 | tmp->textposx = 120; |
---|
141 | tmp->height = 50; |
---|
142 | tmp->valign = convertxmlentry("middle", 0); |
---|
143 | tmp->hspace = 5; |
---|
144 | } |
---|
145 | } |
---|
146 | |
---|
147 | drawscreen(screen, 0); |
---|
148 | addscreenrc(screen, listbox); |
---|
149 | |
---|
150 | while (1) |
---|
151 | { |
---|
152 | rcret = waitrc(screen, 0, 0); |
---|
153 | |
---|
154 | if(rcret==getrcconfigint("rcexit",NULL)) break; |
---|
155 | if(listbox->select != NULL && rcret==getrcconfigint("rcok",NULL)) |
---|
156 | { |
---|
157 | hddformat(dev, listbox->select->name); |
---|
158 | break; |
---|
159 | } |
---|
160 | } |
---|
161 | delownerrc(screen); |
---|
162 | delmarkedscreennodes(screen, 1); |
---|
163 | clearscreen(screen); |
---|
164 | } |
---|
165 | |
---|
166 | void screenconfigurehdd(char* dev) |
---|
167 | { |
---|
168 | int i, y = 8, rcret = 0, ret = 0, mode = 0; |
---|
169 | struct skin* screen = getscreen("harddisk_main"); |
---|
170 | struct skin* listbox = getscreennode(screen, "listbox"); |
---|
171 | struct skin* tmp = NULL; |
---|
172 | char* tmpstr = NULL, *tmpstr1 = NULL, *tmpstr2 = NULL; |
---|
173 | char* path = NULL; |
---|
174 | |
---|
175 | delmarkedscreennodes(screen, 1); |
---|
176 | listbox->aktpage = -1; |
---|
177 | listbox->aktline = 1; |
---|
178 | changetitle(screen, _("Harddisk Configure")); |
---|
179 | |
---|
180 | if(status.expertmodus < 10) y = 1; |
---|
181 | for(i = 0; i < y; i++) |
---|
182 | { |
---|
183 | tmp = addlistbox(screen, listbox, tmp, 1); |
---|
184 | if(tmp != NULL) |
---|
185 | { |
---|
186 | if(i == 0) |
---|
187 | { |
---|
188 | tmpstr = _("use medium for record"); |
---|
189 | tmpstr1 = "addrecord"; |
---|
190 | } |
---|
191 | else if(i == 1) |
---|
192 | { |
---|
193 | tmpstr = _("use medium for extension"); |
---|
194 | tmpstr1 = "addext"; |
---|
195 | } |
---|
196 | else if(i == 2) |
---|
197 | { |
---|
198 | tmpstr = _("use medium for swap"); |
---|
199 | tmpstr1 = "addswap"; |
---|
200 | } |
---|
201 | else if(i == 3) |
---|
202 | { |
---|
203 | tmpstr = _("use medium for backup"); |
---|
204 | tmpstr1 = "addbackup"; |
---|
205 | } |
---|
206 | else if(i == 4) |
---|
207 | { |
---|
208 | tmpstr = _("del medium for record"); |
---|
209 | tmpstr1 = "delrecord"; |
---|
210 | } |
---|
211 | else if(i == 5) |
---|
212 | { |
---|
213 | tmpstr = _("del medium for extension"); |
---|
214 | tmpstr1 = "delext"; |
---|
215 | } |
---|
216 | else if(i == 6) |
---|
217 | { |
---|
218 | tmpstr = _("del medium for swap"); |
---|
219 | tmpstr1 = "delswap"; |
---|
220 | } |
---|
221 | else if(i == 7) |
---|
222 | { |
---|
223 | tmpstr = _("del medium for backup"); |
---|
224 | tmpstr1 = "delbackup"; |
---|
225 | } |
---|
226 | tmpstr2 = ostrcat(tmpstr2, getconfig("skinpath", NULL), 1, 0); |
---|
227 | tmpstr2 = ostrcat(tmpstr2, "/skin/ext2.png", 1, 0); |
---|
228 | tmpstr2 = ostrcat(tmpstr2, "/skin/", 1, 0); |
---|
229 | tmpstr2 = ostrcat(tmpstr2, tmpstr1, 1, 0); |
---|
230 | tmpstr2 = ostrcat(tmpstr2, ".png", 1, 0); |
---|
231 | |
---|
232 | if(!file_exist(tmpstr2)) |
---|
233 | { |
---|
234 | free(tmpstr2); tmpstr2 = NULL; |
---|
235 | tmpstr2 = ostrcat(tmpstr2, getconfig("skinpath", NULL), 1, 0); |
---|
236 | tmpstr2 = ostrcat(tmpstr2, "/skin/default.png", 1, 0); |
---|
237 | } |
---|
238 | changepic(tmp, tmpstr2); |
---|
239 | free(tmpstr2); tmpstr2 = NULL; |
---|
240 | |
---|
241 | changetext(tmp, tmpstr); |
---|
242 | changename(tmp, tmpstr1); |
---|
243 | tmp->textposx = 120; |
---|
244 | tmp->height = 50; |
---|
245 | tmp->valign = convertxmlentry("middle", 0); |
---|
246 | tmp->hspace = 5; |
---|
247 | } |
---|
248 | } |
---|
249 | |
---|
250 | drawscreen(screen, 0); |
---|
251 | addscreenrc(screen, listbox); |
---|
252 | |
---|
253 | while (1) |
---|
254 | { |
---|
255 | rcret = waitrc(screen, 0, 0); |
---|
256 | |
---|
257 | if(rcret==getrcconfigint("rcexit",NULL)) break; |
---|
258 | if(listbox->select != NULL && rcret==getrcconfigint("rcok",NULL)) |
---|
259 | { |
---|
260 | path = getconfig("mountpath", NULL); |
---|
261 | path = ostrcat(path, "/", 0, 0); |
---|
262 | path = ostrcat(path, dev, 1, 0); |
---|
263 | path = ostrcat(path, "/", 1, 0); |
---|
264 | |
---|
265 | if(ostrcmp(listbox->select->name, "addrecord") == 0) |
---|
266 | { |
---|
267 | mode = 0; |
---|
268 | path = ostrcat(path, "movie", 1, 0); |
---|
269 | } |
---|
270 | if(ostrcmp(listbox->select->name, "addswap") == 0) |
---|
271 | { |
---|
272 | mode = 0; |
---|
273 | path = ostrcat(path, "swapdir", 1, 0); |
---|
274 | } |
---|
275 | if(ostrcmp(listbox->select->name, "addext") == 0) |
---|
276 | { |
---|
277 | mode = 0; |
---|
278 | path = ostrcat(path, "swapextensions", 1, 0); |
---|
279 | } |
---|
280 | if(ostrcmp(listbox->select->name, "addbackup") == 0) |
---|
281 | { |
---|
282 | mode = 0; |
---|
283 | path = ostrcat(path, "backup", 1, 0); |
---|
284 | } |
---|
285 | if(ostrcmp(listbox->select->name, "delrecord") == 0) |
---|
286 | { |
---|
287 | mode = 1; |
---|
288 | path = ostrcat(path, "movie", 1, 0); |
---|
289 | } |
---|
290 | if(ostrcmp(listbox->select->name, "delswap") == 0) |
---|
291 | { |
---|
292 | mode = 1; |
---|
293 | path = ostrcat(path, "swapdir", 1, 0); |
---|
294 | } |
---|
295 | if(ostrcmp(listbox->select->name, "delext") == 0) |
---|
296 | { |
---|
297 | mode = 1; |
---|
298 | path = ostrcat(path, "swapextensions", 1, 0); |
---|
299 | } |
---|
300 | if(ostrcmp(listbox->select->name, "delbackup") == 0) |
---|
301 | { |
---|
302 | mode = 1; |
---|
303 | path = ostrcat(path, "backup", 1, 0); |
---|
304 | } |
---|
305 | |
---|
306 | if(mode == 0) ret = mkdir(path, 777); |
---|
307 | if(mode == 1) |
---|
308 | { |
---|
309 | if(textbox("Message", _("Are you sure you want to delete this directory?"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 0, 0) == 1) |
---|
310 | ret = rmdir(path); |
---|
311 | else |
---|
312 | ret = 9999; |
---|
313 | } |
---|
314 | free(path); path = NULL; |
---|
315 | if(ret < 0) |
---|
316 | { |
---|
317 | if(mode == 0) perr("mkdir"); |
---|
318 | if(mode == 1) perr("rmdir"); |
---|
319 | textbox("Message", _("can't create or delete directory"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 5, 0); |
---|
320 | } |
---|
321 | else if(ret != 9999) |
---|
322 | { |
---|
323 | textbox("Message", _("succesfull create or delelete directory"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 5, 0); |
---|
324 | //mount hdd after create dir movie |
---|
325 | if(ostrcmp(listbox->select->name, "addrecord") == 0) |
---|
326 | system("hotplug.sh first"); |
---|
327 | } |
---|
328 | drawscreen(screen, 0); |
---|
329 | } |
---|
330 | } |
---|
331 | delownerrc(screen); |
---|
332 | delmarkedscreennodes(screen, 1); |
---|
333 | clearscreen(screen); |
---|
334 | } |
---|
335 | |
---|
336 | void screenharddisk(int mode) |
---|
337 | { |
---|
338 | struct skin* screen = getscreen("harddisk_main"); |
---|
339 | struct skin* listbox = getscreennode(screen, "listbox"); |
---|
340 | struct skin* tmp = NULL; |
---|
341 | struct hdd* hddnode = NULL; |
---|
342 | int tmphangtime = 999999, rcret = 0; |
---|
343 | char* tmpstr = NULL, *tmpstr1 = NULL, *path = NULL; |
---|
344 | |
---|
345 | addhddall(); |
---|
346 | start: |
---|
347 | tmp = NULL; |
---|
348 | hddnode = hdd; |
---|
349 | |
---|
350 | if(hdd == NULL) |
---|
351 | { |
---|
352 | textbox(_("Harddisk"), _("sorry found no harddisk"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 800, 600, 0, 0); |
---|
353 | return; |
---|
354 | } |
---|
355 | |
---|
356 | status.hangtime = tmphangtime; |
---|
357 | delmarkedscreennodes(screen, 1); |
---|
358 | if(mode == 0) |
---|
359 | changetitle(screen, _("Harddisk Format - List Devices")); |
---|
360 | else if(mode == 1) |
---|
361 | changetitle(screen, _("Harddisk Fsck - List Devices")); |
---|
362 | else if(mode == 2) |
---|
363 | changetitle(screen, _("Harddisk Configure - List Devices")); |
---|
364 | |
---|
365 | listbox->aktpage = -1; |
---|
366 | listbox->aktline = 1; |
---|
367 | |
---|
368 | while(hddnode != NULL) |
---|
369 | { |
---|
370 | if(mode == 2 && hddnode->partition == 0) |
---|
371 | { |
---|
372 | hddnode = hddnode->next; |
---|
373 | continue; |
---|
374 | } |
---|
375 | tmp = addlistbox(screen, listbox, tmp, 1); |
---|
376 | if(tmp != NULL) |
---|
377 | { |
---|
378 | if(hddnode->removable == 0) |
---|
379 | { |
---|
380 | tmpstr = ostrcat(tmpstr, _("HDD "), 1, 0); |
---|
381 | tmpstr1 = ostrcat(tmpstr1, getconfig("skinpath", NULL), 1, 0); |
---|
382 | tmpstr1 = ostrcat(tmpstr1, "/skin/hdd.png", 1, 0); |
---|
383 | } |
---|
384 | else |
---|
385 | { |
---|
386 | tmpstr = ostrcat(tmpstr, _("STICK "), 1, 0); |
---|
387 | tmpstr1 = ostrcat(tmpstr1, getconfig("skinpath", NULL), 1, 0); |
---|
388 | tmpstr1 = ostrcat(tmpstr1, "/skin/stick.png", 1, 0); |
---|
389 | } |
---|
390 | if(mode == 2) |
---|
391 | { |
---|
392 | tmpstr = ostrcat(tmpstr, hddnode->label, 1, 0); |
---|
393 | tmpstr = ostrcat(tmpstr, " (", 1, 0); |
---|
394 | tmpstr = ostrcat(tmpstr, hddnode->device, 1, 0); |
---|
395 | tmpstr = ostrcat(tmpstr, ")", 1, 0); |
---|
396 | |
---|
397 | path = getconfig("mountpath", NULL); |
---|
398 | path = ostrcat(path, "/", 0, 0); |
---|
399 | path = ostrcat(path, hddnode->device, 1, 0); |
---|
400 | path = ostrcat(path, "/", 1, 0); |
---|
401 | path = ostrcat(path, "swapextensions", 1, 0); |
---|
402 | if(file_exist(path) == 1) |
---|
403 | { |
---|
404 | tmpstr = ostrcat(tmpstr, " - ", 1, 0); |
---|
405 | tmpstr = ostrcat(tmpstr, _("ext"), 1, 0); |
---|
406 | } |
---|
407 | free(path); path = NULL; |
---|
408 | |
---|
409 | path = getconfig("mountpath", NULL); |
---|
410 | path = ostrcat(path, "/", 0, 0); |
---|
411 | path = ostrcat(path, hddnode->device, 1, 0); |
---|
412 | path = ostrcat(path, "/", 1, 0); |
---|
413 | path = ostrcat(path, "swapdir", 1, 0); |
---|
414 | if(file_exist(path) == 1) |
---|
415 | { |
---|
416 | tmpstr = ostrcat(tmpstr, " - ", 1, 0); |
---|
417 | tmpstr = ostrcat(tmpstr, _("swap"), 1, 0); |
---|
418 | } |
---|
419 | free(path); path = NULL; |
---|
420 | |
---|
421 | path = getconfig("mountpath", NULL); |
---|
422 | path = ostrcat(path, "/", 0, 0); |
---|
423 | path = ostrcat(path, hddnode->device, 1, 0); |
---|
424 | path = ostrcat(path, "/", 1, 0); |
---|
425 | path = ostrcat(path, "backup", 1, 0); |
---|
426 | if(file_exist(path) == 1) |
---|
427 | { |
---|
428 | tmpstr = ostrcat(tmpstr, " - ", 1, 0); |
---|
429 | tmpstr = ostrcat(tmpstr, _("backup"), 1, 0); |
---|
430 | } |
---|
431 | free(path); path = NULL; |
---|
432 | |
---|
433 | path = getconfig("mountpath", NULL); |
---|
434 | path = ostrcat(path, "/", 0, 0); |
---|
435 | path = ostrcat(path, hddnode->device, 1, 0); |
---|
436 | path = ostrcat(path, "/", 1, 0); |
---|
437 | path = ostrcat(path, "movie", 1, 0); |
---|
438 | if(file_exist(path) == 1) |
---|
439 | { |
---|
440 | tmpstr = ostrcat(tmpstr, " - ", 1, 0); |
---|
441 | tmpstr = ostrcat(tmpstr, _("record"), 1, 0); |
---|
442 | } |
---|
443 | free(path); path = NULL; |
---|
444 | } |
---|
445 | else |
---|
446 | { |
---|
447 | tmpstr = ostrcat(tmpstr, "(", 1, 0); |
---|
448 | tmpstr = ostrcat(tmpstr, hddnode->device, 1, 0); |
---|
449 | tmpstr = ostrcat(tmpstr, "-", 1, 0); |
---|
450 | tmpstr = ostrcat(tmpstr, hddnode->label, 1, 0); |
---|
451 | tmpstr = ostrcat(tmpstr, "-", 1, 0); |
---|
452 | tmpstr = ostrcat(tmpstr, hddnode->filesystem, 1, 0); |
---|
453 | tmpstr = ostrcat(tmpstr, ") ", 1, 0); |
---|
454 | tmpstr = ostrcat(tmpstr, hddnode->model, 1, 0); |
---|
455 | tmpstr = ostrcat(tmpstr, " ", 1, 0); |
---|
456 | tmpstr = ostrcat(tmpstr, blocktogb(hddnode->size), 1, 1); |
---|
457 | tmpstr = ostrcat(tmpstr, " GB", 1, 0); |
---|
458 | } |
---|
459 | changetext(tmp, tmpstr); |
---|
460 | free(tmpstr); tmpstr = NULL; |
---|
461 | |
---|
462 | changename(tmp, hddnode->device); |
---|
463 | tmp->textposx = 120; |
---|
464 | tmp->height = 50; |
---|
465 | tmp->valign = convertxmlentry("middle", 0); |
---|
466 | tmp->hspace = 5; |
---|
467 | |
---|
468 | if(!file_exist(tmpstr1)) |
---|
469 | { |
---|
470 | free(tmpstr1); tmpstr1 = NULL; |
---|
471 | tmpstr1 = ostrcat(tmpstr1, getconfig("skinpath", NULL), 1, 0); |
---|
472 | tmpstr1 = ostrcat(tmpstr1, "/skin/default.png", 1, 0); |
---|
473 | } |
---|
474 | changepic(tmp, tmpstr1); |
---|
475 | free(tmpstr1); tmpstr1 = NULL; |
---|
476 | } |
---|
477 | hddnode = hddnode->next; |
---|
478 | } |
---|
479 | |
---|
480 | drawscreen(screen, 0); |
---|
481 | addscreenrc(screen, listbox); |
---|
482 | |
---|
483 | while (1) |
---|
484 | { |
---|
485 | rcret = waitrc(screen, 0, 0); |
---|
486 | |
---|
487 | if(rcret==getrcconfigint("rcexit",NULL)) break; |
---|
488 | if(listbox->select != NULL && rcret==getrcconfigint("rcok",NULL)) |
---|
489 | { |
---|
490 | if(mode == 0) |
---|
491 | { |
---|
492 | tmpstr = ostrcat(listbox->select->name, NULL, 0, 0); |
---|
493 | screenfilesystem(tmpstr); |
---|
494 | free(tmpstr); tmpstr = NULL; |
---|
495 | } |
---|
496 | else if(mode == 1) |
---|
497 | hddfsck(listbox->select->name); |
---|
498 | else if(mode == 2) |
---|
499 | { |
---|
500 | tmpstr = ostrcat(listbox->select->name, NULL, 0, 0); |
---|
501 | screenconfigurehdd(tmpstr); |
---|
502 | free(tmpstr); tmpstr = NULL; |
---|
503 | delownerrc(screen); |
---|
504 | goto start; |
---|
505 | } |
---|
506 | break; |
---|
507 | } |
---|
508 | } |
---|
509 | |
---|
510 | delownerrc(screen); |
---|
511 | delmarkedscreennodes(screen, 1); |
---|
512 | clearscreen(screen); |
---|
513 | } |
---|
514 | |
---|
515 | void hddformat(char* dev, char* filesystem) |
---|
516 | { |
---|
517 | int format = 0; |
---|
518 | char* cmd = NULL; |
---|
519 | struct hdd* node = NULL; |
---|
520 | |
---|
521 | node = gethdd(dev); |
---|
522 | if(node == NULL) return; |
---|
523 | |
---|
524 | if(node->partition == 0) |
---|
525 | { |
---|
526 | if(textbox(_("Message"), _("Are you sure you want to remove all Partitions\non this device and create a new Partition 1?\nBox reboots after format"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 800, 200, 0, 0) == 1) |
---|
527 | { |
---|
528 | cmd = ostrcat("/sbin/parter.sh /dev/" , dev, 0, 0); |
---|
529 | cmd = ostrcat(cmd , " create 1", 1, 0); |
---|
530 | |
---|
531 | debug(80, "fdisk create cmd: %s", cmd); |
---|
532 | system(cmd); |
---|
533 | format = 2; |
---|
534 | free(cmd); cmd = NULL; |
---|
535 | } |
---|
536 | |
---|
537 | } |
---|
538 | else |
---|
539 | { |
---|
540 | if(textbox(_("Message"), _("Are you sure you want to format this Partition?\nBox reboots after format"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 800, 200, 0, 0) == 1) |
---|
541 | format = 1; |
---|
542 | } |
---|
543 | |
---|
544 | if(format > 0) |
---|
545 | { |
---|
546 | if(ostrcmp(filesystem, "vfat") == 0) |
---|
547 | cmd = ostrcat("/sbin/cmd.sh mkfs.fat -F 32 /dev/" , dev, 0, 0); |
---|
548 | else if(ostrcmp(filesystem, "jfs") == 0) |
---|
549 | cmd = ostrcat("/sbin/cmd.sh mkfs.jfs -q /dev/" , dev, 0, 0); |
---|
550 | else if(ostrcmp(filesystem, "ext2") == 0) |
---|
551 | cmd = ostrcat("/sbin/cmd.sh mkfs.ext2 /dev/" , dev, 0, 0); |
---|
552 | else if(ostrcmp(filesystem, "ext3") == 0) |
---|
553 | cmd = ostrcat("/sbin/cmd.sh mkfs.ext3 -T largefile -m0 -O dir_index /dev/" , dev, 0, 0); |
---|
554 | |
---|
555 | if(format == 2) cmd = ostrcat(cmd , "1", 1, 0); |
---|
556 | |
---|
557 | debug(80, "format cmd: %s", cmd); |
---|
558 | system(cmd); |
---|
559 | free(cmd); cmd = NULL; |
---|
560 | } |
---|
561 | } |
---|
562 | |
---|
563 | void hddfsck(char* dev) |
---|
564 | { |
---|
565 | char* cmd = NULL; |
---|
566 | struct hdd* node = NULL; |
---|
567 | |
---|
568 | if(textbox(_("Message"), _("Are you sure you want to check this Partition?\nBox reboots after check"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 800, 200, 0, 0) == 1) |
---|
569 | { |
---|
570 | node = gethdd(dev); |
---|
571 | if(node == NULL) return; |
---|
572 | debug(80, "device=%s filesystem=%s", dev, node->filesystem); |
---|
573 | |
---|
574 | if(ostrcmp(node->filesystem, "vfat") == 0) |
---|
575 | cmd = ostrcat("/sbin/cmd.sh fsck.fat -a -v /dev/" , dev, 0, 0); |
---|
576 | else if(ostrcmp(node->filesystem, "jfs") == 0) |
---|
577 | cmd = ostrcat("/sbin/cmd.sh fsck.jfs -f -p /dev/" , dev, 0, 0); |
---|
578 | else if(ostrcmp(node->filesystem, "ext2") == 0) |
---|
579 | cmd = ostrcat("/sbin/cmd.sh fsck.ext2 -f -p /dev/" , dev, 0, 0); |
---|
580 | else if(ostrcmp(node->filesystem, "ext3") == 0) |
---|
581 | cmd = ostrcat("/sbin/cmd.sh fsck.ext3 -f -p /dev/" , dev, 0, 0); |
---|
582 | |
---|
583 | debug(80, "fsck cmd: %s", cmd); |
---|
584 | system(cmd); |
---|
585 | free(cmd); cmd = NULL; |
---|
586 | } |
---|
587 | |
---|
588 | } |
---|
589 | |
---|
590 | void screenharddisksleep() |
---|
591 | { |
---|
592 | |
---|
593 | char* sleepWert = NULL; |
---|
594 | int rcret = 0; |
---|
595 | struct skin* sleep_config = getscreen("harddisk_main"); |
---|
596 | struct skin* listbox = getscreennode(sleep_config, "listbox"); |
---|
597 | struct skin* node = NULL; |
---|
598 | struct skin* tmp = NULL; |
---|
599 | |
---|
600 | /*int m_with = sleep_config->width; |
---|
601 | int m_height = sleep_config->height; |
---|
602 | int m_prozwidth = sleep_config->prozwidth; |
---|
603 | int m_prozheight= sleep_config->prozheight; |
---|
604 | |
---|
605 | sleep_config->prozheight = YES; |
---|
606 | sleep_config->prozwidth = YES; |
---|
607 | sleep_config->width = 40; |
---|
608 | sleep_config->height = 30;*/ |
---|
609 | |
---|
610 | node = addlistbox(sleep_config, listbox, node, 1); |
---|
611 | if(node != NULL) |
---|
612 | { |
---|
613 | node->type = CHOICEBOX; |
---|
614 | changetext(node, _("Time to sleep")); changename(node, "timetosleep"); |
---|
615 | addchoicebox(node, "0", _("off")); |
---|
616 | addchoicebox(node, "300", _("5 min")); addchoicebox(node, "600", _("10 min")); |
---|
617 | addchoicebox(node, "900", _("15 min")); addchoicebox(node, "3600", _("60 min")); |
---|
618 | |
---|
619 | sleepWert = getconfig("timetosleep", NULL); |
---|
620 | if(sleepWert == NULL) |
---|
621 | setchoiceboxselection(node, "0"); |
---|
622 | else |
---|
623 | setchoiceboxselection(node, sleepWert); |
---|
624 | } |
---|
625 | |
---|
626 | drawscreen(sleep_config, 0); |
---|
627 | tmp = listbox->select; |
---|
628 | |
---|
629 | while(1) |
---|
630 | { |
---|
631 | addscreenrc(sleep_config, tmp); |
---|
632 | rcret = waitrc(sleep_config, 0, 0); |
---|
633 | tmp = listbox->select; |
---|
634 | |
---|
635 | if(rcret == getrcconfigint("rcexit", NULL)) break; |
---|
636 | |
---|
637 | if(listbox->select != NULL && listbox->select->ret != NULL && rcret == getrcconfigint("rcok", NULL)) |
---|
638 | { |
---|
639 | addconfig("timetosleep", listbox->select->ret); |
---|
640 | //settimetosleep(atoi(listbox->select->ret)); |
---|
641 | break; |
---|
642 | } |
---|
643 | } |
---|
644 | |
---|
645 | /*sleep_config->width = m_with; |
---|
646 | sleep_config->height = m_height; |
---|
647 | sleep_config->prozheight = m_prozheight; |
---|
648 | sleep_config->prozwidth = m_prozwidth;*/ |
---|
649 | delmarkedscreennodes(sleep_config, 1); |
---|
650 | delownerrc(sleep_config); |
---|
651 | clearscreen(sleep_config); |
---|
652 | } |
---|
653 | |
---|
654 | //flag 0: lock |
---|
655 | //flag 1: no lock |
---|
656 | void delhdd(char* device, int flag) |
---|
657 | { |
---|
658 | debug(1000, "in"); |
---|
659 | if(flag == 0) m_lock(&status.hddmutex, 13); |
---|
660 | struct hdd *node = hdd, *prev = hdd; |
---|
661 | |
---|
662 | while(node != NULL) |
---|
663 | { |
---|
664 | if(ostrcmp(node->device, device) == 0) |
---|
665 | { |
---|
666 | if(node == hdd) |
---|
667 | { |
---|
668 | hdd = node->next; |
---|
669 | if(hdd != NULL) |
---|
670 | hdd->prev = NULL; |
---|
671 | } |
---|
672 | else |
---|
673 | { |
---|
674 | prev->next = node->next; |
---|
675 | if(node->next != NULL) |
---|
676 | node->next->prev = prev; |
---|
677 | } |
---|
678 | |
---|
679 | free(node->device); node->device = NULL; |
---|
680 | free(node->vendor); node->vendor = NULL; |
---|
681 | free(node->model); node->model = NULL; |
---|
682 | free(node->label); node->label = NULL; |
---|
683 | free(node->uuid); node->uuid = NULL; |
---|
684 | free(node->filesystem); node->filesystem = NULL; |
---|
685 | |
---|
686 | free(node); |
---|
687 | node = NULL; |
---|
688 | break; |
---|
689 | } |
---|
690 | |
---|
691 | prev = node; |
---|
692 | node = node->next; |
---|
693 | } |
---|
694 | if(flag == 0) m_unlock(&status.hddmutex, 13); |
---|
695 | debug(1000, "out"); |
---|
696 | } |
---|
697 | |
---|
698 | //flag 0: lock |
---|
699 | //flag 1: no lock |
---|
700 | struct hdd* addhdd(char* device, int partition, unsigned long size, int removable, char* vendor, char *model, char* label, char* filesystem, char* uuid, int timetosleep, struct hdd* last, int flag) |
---|
701 | { |
---|
702 | debug(1000, "in"); |
---|
703 | if(flag == 0) m_lock(&status.hddmutex, 13); |
---|
704 | struct hdd *newnode = NULL, *prev = NULL, *node = hdd; |
---|
705 | |
---|
706 | newnode = (struct hdd*)malloc(sizeof(struct hdd)); |
---|
707 | if(newnode == NULL) |
---|
708 | { |
---|
709 | err("no memory"); |
---|
710 | if(flag == 0) m_unlock(&status.hddmutex, 13); |
---|
711 | return NULL; |
---|
712 | } |
---|
713 | memset(newnode, 0, sizeof(struct hdd)); |
---|
714 | |
---|
715 | newnode->device = device; |
---|
716 | newnode->partition = partition; |
---|
717 | newnode->size = size; |
---|
718 | newnode->removable = removable; |
---|
719 | newnode->vendor = vendor; |
---|
720 | newnode->model = model; |
---|
721 | newnode->label = label; |
---|
722 | newnode->uuid = uuid; |
---|
723 | newnode->filesystem = filesystem; |
---|
724 | newnode->read = 0; |
---|
725 | newnode->write = 0; |
---|
726 | newnode->sleeptime = timetosleep; |
---|
727 | newnode->notchanged = 0; |
---|
728 | |
---|
729 | debug(80, "add hdd %s", device); |
---|
730 | |
---|
731 | if(last == NULL) |
---|
732 | { |
---|
733 | while(node != NULL && strcoll(newnode->device, node->device) > 0) |
---|
734 | { |
---|
735 | prev = node; |
---|
736 | node = node->next; |
---|
737 | } |
---|
738 | } |
---|
739 | else |
---|
740 | { |
---|
741 | prev = last; |
---|
742 | node = last->next; |
---|
743 | } |
---|
744 | |
---|
745 | if(prev == NULL) |
---|
746 | hdd = newnode; |
---|
747 | else |
---|
748 | { |
---|
749 | prev->next = newnode; |
---|
750 | newnode->prev = prev; |
---|
751 | } |
---|
752 | newnode->next = node; |
---|
753 | |
---|
754 | if(flag == 0) m_unlock(&status.hddmutex, 13); |
---|
755 | debug(1000, "out"); |
---|
756 | return newnode; |
---|
757 | } |
---|
758 | |
---|
759 | //flag = 0: mutex lock |
---|
760 | //flag = 1: no mutex lock |
---|
761 | void freehdd(int flag) |
---|
762 | { |
---|
763 | debug(1000, "in"); |
---|
764 | if(flag == 0) m_lock(&status.hddmutex, 13); |
---|
765 | struct hdd *node = hdd, *prev = hdd; |
---|
766 | |
---|
767 | while(node != NULL) |
---|
768 | { |
---|
769 | prev = node; |
---|
770 | node = node->next; |
---|
771 | if(prev != NULL) |
---|
772 | delhdd(prev->device, 1); |
---|
773 | } |
---|
774 | debug(1000, "out"); |
---|
775 | if(flag == 0) m_unlock(&status.hddmutex, 13); |
---|
776 | } |
---|
777 | |
---|
778 | int addhddall() |
---|
779 | { |
---|
780 | m_lock(&status.hddmutex, 13); |
---|
781 | FILE* fd = NULL; |
---|
782 | FILE* fd2 = NULL; |
---|
783 | char* fileline = NULL, *dev = NULL, *pos = NULL, *part = NULL; |
---|
784 | char* tmpstr = NULL; |
---|
785 | char* tmpstr2 = NULL; |
---|
786 | int partition = 0; |
---|
787 | int timetosleep = 0; |
---|
788 | struct hdd *node = hdd; |
---|
789 | struct hdd *nodedev = hdd; |
---|
790 | int w1, w2, w3, w4, w5; |
---|
791 | |
---|
792 | fd = fopen("/proc/partitions", "r"); |
---|
793 | if(fd == NULL) |
---|
794 | { |
---|
795 | err("open /proc/partitions"); |
---|
796 | m_unlock(&status.hddmutex, 13); |
---|
797 | return 1; |
---|
798 | } |
---|
799 | |
---|
800 | fileline = malloc(MINMALLOC); |
---|
801 | if(fileline == NULL) |
---|
802 | { |
---|
803 | err("no mem"); |
---|
804 | m_unlock(&status.hddmutex, 13); |
---|
805 | return 1; |
---|
806 | } |
---|
807 | |
---|
808 | while(fgets(fileline, MINMALLOC, fd) != NULL) |
---|
809 | { |
---|
810 | pos = strstr(fileline, "sd"); |
---|
811 | if(pos != NULL) |
---|
812 | { |
---|
813 | partition = 0; |
---|
814 | part = NULL; |
---|
815 | pos = string_newline(pos); |
---|
816 | if(strlen(pos) == 3) |
---|
817 | { |
---|
818 | free(dev); dev = NULL; |
---|
819 | dev = ostrcat(pos, NULL, 0, 0); |
---|
820 | if(getconfig("timetosleep", NULL) == NULL) |
---|
821 | timetosleep = 0; |
---|
822 | else |
---|
823 | timetosleep = atoi(getconfig("timetosleep", NULL)); |
---|
824 | } |
---|
825 | if(strlen(pos) == 4) |
---|
826 | { |
---|
827 | part = pos; |
---|
828 | partition = atoi(&pos[3]); |
---|
829 | } |
---|
830 | tmpstr = ostrcat(tmpstr, "#", 1, 0); |
---|
831 | tmpstr = ostrcat(tmpstr, pos, 1, 0); |
---|
832 | //if(gethdd(pos) == NULL) |
---|
833 | nodedev = gethdd(pos); |
---|
834 | if(nodedev == NULL) |
---|
835 | nodedev = addhdd(ostrcat(pos, NULL, 0, 0), partition, hddgetsize(dev, part), hddgetremovable(dev), hddgetvendor(dev), hddgetmodel(dev), get_label(part), get_filesystem(part), get_uuid(part), timetosleep, NULL, 1); |
---|
836 | |
---|
837 | //HDD SleepTimer start |
---|
838 | if(nodedev != NULL) { |
---|
839 | if(nodedev->sleeptime != timetosleep) { |
---|
840 | nodedev->read = 0; |
---|
841 | nodedev->write = 0; |
---|
842 | nodedev->sleeptime = timetosleep; |
---|
843 | nodedev->notchanged = 0; |
---|
844 | } |
---|
845 | if(strlen(pos) == 3) { |
---|
846 | free(tmpstr2);tmpstr2=NULL; |
---|
847 | tmpstr2 = ostrcat(tmpstr2, "/sys/block/", 1, 0); |
---|
848 | tmpstr2 = ostrcat(tmpstr2, nodedev->device, 1, 0); |
---|
849 | tmpstr2 = ostrcat(tmpstr2, "/stat", 1, 0); |
---|
850 | fd2 = fopen(tmpstr2, "r"); |
---|
851 | if(fd2 != NULL) { |
---|
852 | fscanf(fd2, "%d%d%d%d%d", &w1,&w2,&w3,&w4,&w5); |
---|
853 | fclose(fd2); |
---|
854 | fd2 = NULL; |
---|
855 | if((nodedev->read != w1) || (nodedev->write != w5)) { |
---|
856 | nodedev->read = w1; |
---|
857 | nodedev->write = w5; |
---|
858 | nodedev->notchanged = 0; |
---|
859 | } else { |
---|
860 | if (nodedev->notchanged < nodedev->sleeptime) { |
---|
861 | nodedev->notchanged = nodedev->notchanged + (status.addhddall->delay / 1000); |
---|
862 | if (nodedev->notchanged >= nodedev->sleeptime) { |
---|
863 | free(tmpstr2);tmpstr2=NULL; |
---|
864 | tmpstr2 = ostrcat(tmpstr2, "/sbin/sdparm -C stop /dev/", 1, 0); |
---|
865 | tmpstr2 = ostrcat(tmpstr2, nodedev->device, 1, 0); |
---|
866 | system(tmpstr2); |
---|
867 | } |
---|
868 | } |
---|
869 | } |
---|
870 | } |
---|
871 | } |
---|
872 | } |
---|
873 | //HDD SleepTimer end |
---|
874 | |
---|
875 | } |
---|
876 | } |
---|
877 | |
---|
878 | //check for removed devs |
---|
879 | while(node != NULL && tmpstr != NULL) |
---|
880 | { |
---|
881 | if(strstr(tmpstr, node->device) == 0) |
---|
882 | { |
---|
883 | debug(80, "remove %s", node->device); |
---|
884 | delhdd(node->device, 1); |
---|
885 | } |
---|
886 | node = node->next; |
---|
887 | } |
---|
888 | |
---|
889 | if(node != NULL && tmpstr == NULL) |
---|
890 | { |
---|
891 | debug(80, "remove all"); |
---|
892 | freehdd(1); |
---|
893 | } |
---|
894 | |
---|
895 | free(tmpstr); |
---|
896 | free(tmpstr2); |
---|
897 | free(dev); |
---|
898 | free(fileline); |
---|
899 | fclose(fd); |
---|
900 | m_unlock(&status.hddmutex, 13); |
---|
901 | return 0; |
---|
902 | } |
---|
903 | |
---|
904 | #endif |
---|