1 | #ifndef HARDDISK_H |
---|
2 | #define HARDDISK_H |
---|
3 | |
---|
4 | int checkfilesystemexist(char* filesystem) |
---|
5 | { |
---|
6 | int ret = 0; |
---|
7 | char* tmpstr = NULL, *tmpstr1 = NULL; |
---|
8 | |
---|
9 | tmpstr = readfiletomem("/proc/filesystems", 0); |
---|
10 | |
---|
11 | tmpstr1 = ostrcat("\t", filesystem, 0, 0); |
---|
12 | tmpstr1 = ostrcat(tmpstr1, "\n", 0, 0); |
---|
13 | |
---|
14 | if(ostrstr(tmpstr, tmpstr1) != NULL) |
---|
15 | ret = 1; |
---|
16 | |
---|
17 | free(tmpstr); tmpstr = NULL; |
---|
18 | free(tmpstr1); tmpstr1 = NULL; |
---|
19 | |
---|
20 | return ret; |
---|
21 | } |
---|
22 | |
---|
23 | char* blocktogb(unsigned long long size) |
---|
24 | { |
---|
25 | char* buf = NULL; |
---|
26 | |
---|
27 | buf = malloc(MINMALLOC); |
---|
28 | if(buf == NULL) |
---|
29 | { |
---|
30 | err("no mem"); |
---|
31 | return NULL; |
---|
32 | } |
---|
33 | snprintf(buf, MINMALLOC, "%.2f", (float)size / 2 / 1024 / 1024); //size is in 512KB blocks |
---|
34 | return ostrshrink(buf); |
---|
35 | } |
---|
36 | |
---|
37 | struct hdd* gethdd(char* device) |
---|
38 | { |
---|
39 | struct hdd *node = hdd; |
---|
40 | |
---|
41 | while(node != NULL) |
---|
42 | { |
---|
43 | if(ostrcmp(node->device, device) == 0) |
---|
44 | return node; |
---|
45 | node = node->next; |
---|
46 | } |
---|
47 | debug(100, "hdd not found (device=%s)", device); |
---|
48 | return NULL; |
---|
49 | } |
---|
50 | |
---|
51 | unsigned long long hddgetsize(char* device, char* partition) |
---|
52 | { |
---|
53 | char* file = NULL; |
---|
54 | unsigned long long size = 0; |
---|
55 | |
---|
56 | file = ostrcat(file , "/sys/block/", 1, 0); |
---|
57 | file = ostrcat(file , device, 1, 0); |
---|
58 | if(partition != NULL) |
---|
59 | { |
---|
60 | file = ostrcat(file , "/", 1, 0); |
---|
61 | file = ostrcat(file , partition, 1, 0); |
---|
62 | } |
---|
63 | file = ostrcat(file , "/size", 1, 0); |
---|
64 | size = readsysull(file, 1); |
---|
65 | debug(80, "file: %s, size: %lu", file, size); |
---|
66 | free(file); file = NULL; |
---|
67 | |
---|
68 | return size; |
---|
69 | } |
---|
70 | |
---|
71 | char* hddgetvendor(char* device) |
---|
72 | { |
---|
73 | char* file = NULL, *vendor = NULL; |
---|
74 | |
---|
75 | file = ostrcat(file , "/sys/block/", 1, 0); |
---|
76 | file = ostrcat(file , device, 1, 0); |
---|
77 | file = ostrcat(file , "/device/vendor", 1, 0); |
---|
78 | vendor = strstrip(readsys(file, 1)); |
---|
79 | debug(80, "file: %s, vendor: %s", file, vendor); |
---|
80 | free(file); file = NULL; |
---|
81 | |
---|
82 | return vendor; |
---|
83 | } |
---|
84 | |
---|
85 | char* hddgetmodel(char* device) |
---|
86 | { |
---|
87 | char* file = NULL, *model = NULL; |
---|
88 | |
---|
89 | file = ostrcat(file , "/sys/block/", 1, 0); |
---|
90 | file = ostrcat(file , device, 1, 0); |
---|
91 | file = ostrcat(file , "/device/model", 1, 0); |
---|
92 | model = strstrip(readsys(file, 1)); |
---|
93 | debug(80, "file: %s, model: %s", file, model); |
---|
94 | free(file); file = NULL; |
---|
95 | |
---|
96 | return model; |
---|
97 | } |
---|
98 | |
---|
99 | int hddgetremovable(char* device) |
---|
100 | { |
---|
101 | char* file = NULL; |
---|
102 | int removable = 0; |
---|
103 | |
---|
104 | file = ostrcat(file , "/sys/block/", 1, 0); |
---|
105 | file = ostrcat(file , device, 1, 0); |
---|
106 | file = ostrcat(file , "/removable", 1, 0); |
---|
107 | removable = readsysul(file, 1); |
---|
108 | debug(80, "file: %s, removable: %d", file, removable); |
---|
109 | free(file); file = NULL; |
---|
110 | |
---|
111 | return removable; |
---|
112 | } |
---|
113 | |
---|
114 | void screenfilesystem(char* dev) |
---|
115 | { |
---|
116 | int i, rcret = 0, count = 1; |
---|
117 | struct skin* screen = getscreen("harddisk_main"); |
---|
118 | struct skin* details = getscreennode(screen, "details"); |
---|
119 | struct skin* listbox = getscreennode(screen, "listbox"); |
---|
120 | struct skin* tmp = NULL; |
---|
121 | char* tmpstr = NULL, *tmpstr1 = NULL; |
---|
122 | |
---|
123 | delmarkedscreennodes(screen, 1); |
---|
124 | listbox->aktpage = -1; |
---|
125 | listbox->aktline = 1; |
---|
126 | changetitle(screen, _("Harddisk Format - Filesystem")); |
---|
127 | if(details != status.skinerr) changetext(details, _("select the format filesystem type for your media drive")); |
---|
128 | |
---|
129 | if(status.expertmodus > 9) count = 5; |
---|
130 | |
---|
131 | for(i = 0; i < count; i++) |
---|
132 | { |
---|
133 | if(i == 0 && checkfilesystemexist("ext3") == 0) continue; |
---|
134 | else if(i == 1 && checkfilesystemexist("ext4") == 0) continue; |
---|
135 | else if(i == 2 && checkfilesystemexist("ext2") == 0) continue; |
---|
136 | else if(i == 3 && checkfilesystemexist("jfs") == 0) continue; |
---|
137 | else if(i == 4 && checkfilesystemexist("vfat") == 0) continue; |
---|
138 | |
---|
139 | tmp = addlistbox(screen, listbox, tmp, 1); |
---|
140 | if(tmp != NULL) |
---|
141 | { |
---|
142 | if(i == 0) tmpstr = "ext3"; |
---|
143 | else if(i == 1) tmpstr = "ext4"; |
---|
144 | else if(i == 2) tmpstr = "ext2"; |
---|
145 | else if(i == 3) tmpstr = "jfs"; |
---|
146 | else if(i == 4) tmpstr = "vfat"; |
---|
147 | tmpstr1 = ostrcat(tmpstr1, getconfig("skinpath", NULL), 1, 0); |
---|
148 | tmpstr1 = ostrcat(tmpstr1, "/skin/", 1, 0); |
---|
149 | tmpstr1 = ostrcat(tmpstr1, tmpstr, 1, 0); |
---|
150 | tmpstr1 = ostrcat(tmpstr1, ".png", 1, 0); |
---|
151 | |
---|
152 | if(!file_exist(tmpstr1)) |
---|
153 | { |
---|
154 | free(tmpstr1); tmpstr1 = NULL; |
---|
155 | tmpstr1 = ostrcat(tmpstr1, getconfig("skinpath", NULL), 1, 0); |
---|
156 | tmpstr1 = ostrcat(tmpstr1, "/skin/default.png", 1, 0); |
---|
157 | } |
---|
158 | changepic(tmp, tmpstr1); |
---|
159 | free(tmpstr1); tmpstr1 = NULL; |
---|
160 | |
---|
161 | changename(tmp, tmpstr); |
---|
162 | if(i == 0) |
---|
163 | { |
---|
164 | tmpstr = ostrcat(tmpstr, " (", 0, 0); |
---|
165 | tmpstr = ostrcat(tmpstr, _("default"), 1, 0); |
---|
166 | tmpstr = ostrcat(tmpstr, ")", 1, 0); |
---|
167 | changetext(tmp, tmpstr); |
---|
168 | free(tmpstr); tmpstr = NULL; |
---|
169 | } |
---|
170 | else |
---|
171 | changetext(tmp, tmpstr); |
---|
172 | |
---|
173 | tmp->textposx = 120; |
---|
174 | tmp->height = 50; |
---|
175 | tmp->valign = convertxmlentry("middle", 0); |
---|
176 | tmp->hspace = 5; |
---|
177 | } |
---|
178 | } |
---|
179 | |
---|
180 | drawscreen(screen, 0, 0); |
---|
181 | addscreenrc(screen, listbox); |
---|
182 | |
---|
183 | while (1) |
---|
184 | { |
---|
185 | rcret = waitrc(screen, 0, 0); |
---|
186 | |
---|
187 | if(rcret==getrcconfigint("rcexit", NULL)) break; |
---|
188 | if(listbox->select != NULL && rcret==getrcconfigint("rcok", NULL)) |
---|
189 | { |
---|
190 | hddformat(dev, listbox->select->name); |
---|
191 | break; |
---|
192 | } |
---|
193 | } |
---|
194 | delownerrc(screen); |
---|
195 | delmarkedscreennodes(screen, 1); |
---|
196 | clearscreen(screen); |
---|
197 | } |
---|
198 | |
---|
199 | void screenconfigurehdd(char* dev) |
---|
200 | { |
---|
201 | int i, y = 1, rcret = 0, ret = 0; |
---|
202 | struct skin* screen = getscreen("harddisk_main"); |
---|
203 | struct skin* details = getscreennode(screen, "details"); |
---|
204 | struct skin* listbox = getscreennode(screen, "listbox"); |
---|
205 | |
---|
206 | struct skin* load = getscreen("loading"); |
---|
207 | struct skin* tmp = NULL; |
---|
208 | char* tmpstr = NULL, *tmpstr1 = NULL, *tmpstr2 = NULL, *path = NULL, *mountpath = NULL, *cmd = NULL; |
---|
209 | int record = 0, swapextensions = 0, swapdir = 0, backup = 0; |
---|
210 | delmarkedscreennodes(screen, 1); |
---|
211 | listbox->aktpage = -1; |
---|
212 | listbox->aktline = 1; |
---|
213 | changetitle(screen, _("Harddisk Configure")); |
---|
214 | if(details != status.skinerr) changetext(details, _("select the function for the specified device")); |
---|
215 | |
---|
216 | mountpath = getconfig("mountpath", NULL); |
---|
217 | mountpath = ostrcat(mountpath, "/", 0, 0); |
---|
218 | mountpath = ostrcat(mountpath, dev, 1, 0); |
---|
219 | mountpath = ostrcat(mountpath, "/", 1, 0); |
---|
220 | |
---|
221 | if(status.expertmodus > 9) y = 4; |
---|
222 | for(i = 0; i < y; i++) |
---|
223 | { |
---|
224 | tmp = addlistbox(screen, listbox, tmp, 1); |
---|
225 | if(tmp != NULL) |
---|
226 | { |
---|
227 | tmp->type = CHOICEBOX; |
---|
228 | if(i == 0) |
---|
229 | { |
---|
230 | tmpstr = _("use medium for record"); |
---|
231 | tmpstr1 = "record"; |
---|
232 | path = ostrcat(mountpath, "movie", 0, 0); |
---|
233 | if(file_exist(path)) |
---|
234 | { |
---|
235 | addchoicebox(tmp, "1", _("yes")); |
---|
236 | addchoicebox(tmp, "0", _("no")); |
---|
237 | record = 1; |
---|
238 | } |
---|
239 | else |
---|
240 | { |
---|
241 | addchoicebox(tmp, "0", _("no")); |
---|
242 | addchoicebox(tmp, "1", _("yes")); |
---|
243 | record = 0; |
---|
244 | } |
---|
245 | free(path), path = NULL; |
---|
246 | } |
---|
247 | else if(i == 1) |
---|
248 | { |
---|
249 | tmpstr = _("use medium for extension"); |
---|
250 | tmpstr1 = "swapextensions"; |
---|
251 | path = ostrcat(mountpath, "swapextensions", 0, 0); |
---|
252 | if(file_exist(path)) |
---|
253 | { |
---|
254 | addchoicebox(tmp, "1", _("yes")); |
---|
255 | addchoicebox(tmp, "0", _("no")); |
---|
256 | swapextensions = 1; |
---|
257 | } |
---|
258 | else |
---|
259 | { |
---|
260 | addchoicebox(tmp, "0", _("no")); |
---|
261 | addchoicebox(tmp, "1", _("yes")); |
---|
262 | swapextensions = 0; |
---|
263 | } |
---|
264 | free(path), path = NULL; |
---|
265 | } |
---|
266 | else if(i == 2) |
---|
267 | { |
---|
268 | tmpstr = _("use medium for swap"); |
---|
269 | tmpstr1 = "swapdir"; |
---|
270 | path = ostrcat(mountpath, "swapdir", 0, 0); |
---|
271 | if(file_exist(path)) |
---|
272 | { |
---|
273 | addchoicebox(tmp, "1", _("yes")); |
---|
274 | addchoicebox(tmp, "0", _("no")); |
---|
275 | swapdir = 1; |
---|
276 | } |
---|
277 | else |
---|
278 | { |
---|
279 | addchoicebox(tmp, "0", _("no")); |
---|
280 | addchoicebox(tmp, "1", _("yes")); |
---|
281 | swapdir = 0; |
---|
282 | } |
---|
283 | free(path), path = NULL; |
---|
284 | } |
---|
285 | else if(i == 3) |
---|
286 | { |
---|
287 | tmpstr = _("use medium for backup"); |
---|
288 | tmpstr1 = "backup"; |
---|
289 | path = ostrcat(mountpath, "backup", 0, 0); |
---|
290 | if(file_exist(path)) |
---|
291 | { |
---|
292 | addchoicebox(tmp, "1", _("yes")); |
---|
293 | addchoicebox(tmp, "0", _("no")); |
---|
294 | backup = 1; |
---|
295 | } |
---|
296 | else |
---|
297 | { |
---|
298 | addchoicebox(tmp, "0", _("no")); |
---|
299 | addchoicebox(tmp, "1", _("yes")); |
---|
300 | backup = 0; |
---|
301 | } |
---|
302 | free(path), path = NULL; |
---|
303 | } |
---|
304 | |
---|
305 | tmpstr2 = ostrcat(tmpstr2, getconfig("skinpath", NULL), 1, 0); |
---|
306 | tmpstr2 = ostrcat(tmpstr2, "/skin/", 1, 0); |
---|
307 | tmpstr2 = ostrcat(tmpstr2, tmpstr1, 1, 0); |
---|
308 | tmpstr2 = ostrcat(tmpstr2, ".png", 1, 0); |
---|
309 | |
---|
310 | if(!file_exist(tmpstr2)) |
---|
311 | { |
---|
312 | free(tmpstr2); tmpstr2 = NULL; |
---|
313 | tmpstr2 = ostrcat(tmpstr2, getconfig("skinpath", NULL), 1, 0); |
---|
314 | tmpstr2 = ostrcat(tmpstr2, "/skin/default.png", 1, 0); |
---|
315 | } |
---|
316 | changepic(tmp, tmpstr2); |
---|
317 | free(tmpstr2); tmpstr2 = NULL; |
---|
318 | |
---|
319 | changetext(tmp, tmpstr); |
---|
320 | changename(tmp, tmpstr1); |
---|
321 | tmp->textposx = 120; |
---|
322 | tmp->height = 50; |
---|
323 | tmp->valign = convertxmlentry("middle", 0); |
---|
324 | tmp->hspace = 5; |
---|
325 | } |
---|
326 | } |
---|
327 | |
---|
328 | drawscreen(screen, 0, 0); |
---|
329 | tmp = listbox->select; |
---|
330 | |
---|
331 | while (1) |
---|
332 | { |
---|
333 | addscreenrc(screen, tmp); |
---|
334 | |
---|
335 | rcret = waitrc(screen, 0, 0); |
---|
336 | tmp = listbox->select; |
---|
337 | |
---|
338 | if(ostrcmp(listbox->select->name, "record") == 0) |
---|
339 | record = atoi(listbox->select->ret); |
---|
340 | if(ostrcmp(listbox->select->name, "swapextensions") == 0) |
---|
341 | swapextensions = atoi(listbox->select->ret); |
---|
342 | if(ostrcmp(listbox->select->name, "swapdir") == 0) |
---|
343 | swapdir = atoi(listbox->select->ret); |
---|
344 | if(ostrcmp(listbox->select->name, "backup") == 0) |
---|
345 | backup = atoi(listbox->select->ret); |
---|
346 | |
---|
347 | if(rcret==getrcconfigint("rcexit",NULL)) break; |
---|
348 | if(listbox->select != NULL && rcret == getrcconfigint("rcok", NULL)) |
---|
349 | { |
---|
350 | if(record == 0) |
---|
351 | { |
---|
352 | path = ostrcat(mountpath, "movie", 0, 0); |
---|
353 | if(file_exist(path)) |
---|
354 | { |
---|
355 | if(textbox("Message", _("Are you sure, you want to delete the record directory on this drive?"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 800, 200, 0, 0) == 1) |
---|
356 | { |
---|
357 | drawscreen(load, 0, 0); |
---|
358 | cmd = ostrcat("rm -rf ", path, 0, 0); |
---|
359 | system(cmd); |
---|
360 | free(cmd); cmd = NULL; |
---|
361 | system("hotplug.sh delRecord"); |
---|
362 | clearscreen(load); |
---|
363 | } |
---|
364 | } |
---|
365 | free(path), path = NULL; |
---|
366 | } |
---|
367 | else if(record == 1) |
---|
368 | { |
---|
369 | path = ostrcat(mountpath, "movie", 0, 0); |
---|
370 | if(!file_exist(path)) |
---|
371 | { |
---|
372 | drawscreen(load, 0, 0); |
---|
373 | ret = mkdir(path, 0777); |
---|
374 | system("hotplug.sh first"); |
---|
375 | clearscreen(load); |
---|
376 | } |
---|
377 | free(path), path = NULL; |
---|
378 | } |
---|
379 | |
---|
380 | if(swapextensions == 0) |
---|
381 | { |
---|
382 | path = ostrcat(mountpath, "swapextensions", 0, 0); |
---|
383 | if(file_exist(path)) |
---|
384 | { |
---|
385 | drawscreen(load, 0, 0); |
---|
386 | cmd = ostrcat("rm -rf ", path, 0, 0); |
---|
387 | system(cmd); |
---|
388 | free(cmd); cmd = NULL; |
---|
389 | system("hotplug.sh delSwapextensions"); |
---|
390 | clearscreen(load); |
---|
391 | } |
---|
392 | free(path), path = NULL; |
---|
393 | } |
---|
394 | else if(swapextensions == 1) |
---|
395 | { |
---|
396 | path = ostrcat(mountpath, "swapextensions", 0, 0); |
---|
397 | if(!file_exist(path)) |
---|
398 | { |
---|
399 | drawscreen(load, 0, 0); |
---|
400 | ret = mkdir(path, 0777); |
---|
401 | system("hotplug.sh first"); |
---|
402 | clearscreen(load); |
---|
403 | } |
---|
404 | free(path), path = NULL; |
---|
405 | } |
---|
406 | |
---|
407 | if(swapdir == 0) |
---|
408 | { |
---|
409 | path = ostrcat(mountpath, "swapdir", 0, 0); |
---|
410 | if(file_exist(path)) |
---|
411 | { |
---|
412 | drawscreen(load, 0, 0); |
---|
413 | system("hotplug.sh delSwap"); |
---|
414 | cmd = ostrcat("rm -rf ", path, 0, 0); |
---|
415 | system(cmd); |
---|
416 | free(cmd); cmd = NULL; |
---|
417 | clearscreen(load); |
---|
418 | } |
---|
419 | free(path), path = NULL; |
---|
420 | } |
---|
421 | else if(swapdir == 1) |
---|
422 | { |
---|
423 | path = ostrcat(mountpath, "swapdir", 0, 0); |
---|
424 | if(!file_exist(path)) |
---|
425 | { |
---|
426 | drawscreen(load, 0, 0); |
---|
427 | ret = mkdir(path, 0777); |
---|
428 | system("hotplug.sh first"); |
---|
429 | clearscreen(load); |
---|
430 | } |
---|
431 | free(path), path = NULL; |
---|
432 | } |
---|
433 | |
---|
434 | if(backup == 0) |
---|
435 | { |
---|
436 | path = ostrcat(mountpath, "backup", 0, 0); |
---|
437 | if(file_exist(path)) |
---|
438 | { |
---|
439 | drawscreen(load, 0, 0); |
---|
440 | cmd = ostrcat("rm -rf ", path, 0, 0); |
---|
441 | system(cmd); |
---|
442 | free(cmd); cmd = NULL; |
---|
443 | system("hotplug.sh delBackup"); |
---|
444 | clearscreen(load); |
---|
445 | } |
---|
446 | free(path), path = NULL; |
---|
447 | } |
---|
448 | else if(backup == 1) |
---|
449 | { |
---|
450 | path = ostrcat(mountpath, "backup", 0, 0); |
---|
451 | if(!file_exist(path)) |
---|
452 | { |
---|
453 | drawscreen(load, 0, 0); |
---|
454 | ret = mkdir(path, 0777); |
---|
455 | system("hotplug.sh first"); |
---|
456 | clearscreen(load); |
---|
457 | } |
---|
458 | free(path), path = NULL; |
---|
459 | } |
---|
460 | break; |
---|
461 | } |
---|
462 | } |
---|
463 | |
---|
464 | free(mountpath), mountpath = NULL; |
---|
465 | delownerrc(screen); |
---|
466 | delmarkedscreennodes(screen, 1); |
---|
467 | clearscreen(screen); |
---|
468 | } |
---|
469 | |
---|
470 | void screenharddisk(int mode) |
---|
471 | { |
---|
472 | struct skin* screen = getscreen("harddisk_main"); |
---|
473 | struct skin* listbox = getscreennode(screen, "listbox"); |
---|
474 | struct skin* details = getscreennode(screen, "details"); |
---|
475 | struct skin* tmp = NULL; |
---|
476 | struct hdd* hddnode = NULL; |
---|
477 | int tmphangtime = 999999, rcret = 0; |
---|
478 | char* tmpstr = NULL, *tmpstr1 = NULL, *path = NULL; |
---|
479 | |
---|
480 | addhddall(); |
---|
481 | start: |
---|
482 | tmp = NULL; |
---|
483 | hddnode = hdd; |
---|
484 | |
---|
485 | if(hdd == NULL) |
---|
486 | { |
---|
487 | textbox(_("Harddisk"), _("sorry found no harddisk"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 800, 600, 0, 0); |
---|
488 | return; |
---|
489 | } |
---|
490 | |
---|
491 | status.hangtime = tmphangtime; |
---|
492 | delmarkedscreennodes(screen, 1); |
---|
493 | if(mode == 0) |
---|
494 | { |
---|
495 | changetitle(screen, _("Harddisk Format")); |
---|
496 | if(details != status.skinerr) changetext(details, _("select the media drive from Device List for formating")); |
---|
497 | } |
---|
498 | else if(mode == 1) |
---|
499 | { |
---|
500 | changetitle(screen, _("Harddisk Fsck")); |
---|
501 | if(details != status.skinerr) changetext(details, _("select the media drive from Device List for fsck")); |
---|
502 | } |
---|
503 | else if(mode == 2) |
---|
504 | { |
---|
505 | changetitle(screen, _("Harddisk Configure")); |
---|
506 | if(details != status.skinerr) changetext(details, _("select the media drive from Device List for configuration")); |
---|
507 | } |
---|
508 | |
---|
509 | listbox->aktpage = -1; |
---|
510 | listbox->aktline = 1; |
---|
511 | |
---|
512 | while(hddnode != NULL) |
---|
513 | { |
---|
514 | if(mode == 2 && hddnode->partition == 0) |
---|
515 | { |
---|
516 | hddnode = hddnode->next; |
---|
517 | continue; |
---|
518 | } |
---|
519 | tmp = addlistbox(screen, listbox, tmp, 1); |
---|
520 | if(tmp != NULL) |
---|
521 | { |
---|
522 | if(hddnode->removable == 0) |
---|
523 | { |
---|
524 | tmpstr = ostrcat(tmpstr, _("HDD "), 1, 0); |
---|
525 | tmpstr1 = ostrcat(tmpstr1, getconfig("skinpath", NULL), 1, 0); |
---|
526 | tmpstr1 = ostrcat(tmpstr1, "/skin/hdd.png", 1, 0); |
---|
527 | } |
---|
528 | else |
---|
529 | { |
---|
530 | tmpstr = ostrcat(tmpstr, _("STICK "), 1, 0); |
---|
531 | tmpstr1 = ostrcat(tmpstr1, getconfig("skinpath", NULL), 1, 0); |
---|
532 | tmpstr1 = ostrcat(tmpstr1, "/skin/stick.png", 1, 0); |
---|
533 | } |
---|
534 | if(mode == 2) |
---|
535 | { |
---|
536 | tmpstr = ostrcat(tmpstr, hddnode->label, 1, 0); |
---|
537 | tmpstr = ostrcat(tmpstr, " (", 1, 0); |
---|
538 | tmpstr = ostrcat(tmpstr, hddnode->device, 1, 0); |
---|
539 | tmpstr = ostrcat(tmpstr, ")", 1, 0); |
---|
540 | |
---|
541 | path = getconfig("mountpath", NULL); |
---|
542 | path = ostrcat(path, "/", 0, 0); |
---|
543 | path = ostrcat(path, hddnode->device, 1, 0); |
---|
544 | path = ostrcat(path, "/", 1, 0); |
---|
545 | path = ostrcat(path, "swapextensions", 1, 0); |
---|
546 | if(file_exist(path) == 1) |
---|
547 | { |
---|
548 | tmpstr = ostrcat(tmpstr, " - ", 1, 0); |
---|
549 | tmpstr = ostrcat(tmpstr, _("ext"), 1, 0); |
---|
550 | } |
---|
551 | free(path); path = NULL; |
---|
552 | |
---|
553 | path = getconfig("mountpath", NULL); |
---|
554 | path = ostrcat(path, "/", 0, 0); |
---|
555 | path = ostrcat(path, hddnode->device, 1, 0); |
---|
556 | path = ostrcat(path, "/", 1, 0); |
---|
557 | path = ostrcat(path, "swapdir", 1, 0); |
---|
558 | if(file_exist(path) == 1) |
---|
559 | { |
---|
560 | tmpstr = ostrcat(tmpstr, " - ", 1, 0); |
---|
561 | tmpstr = ostrcat(tmpstr, _("swap"), 1, 0); |
---|
562 | } |
---|
563 | free(path); path = NULL; |
---|
564 | |
---|
565 | path = getconfig("mountpath", NULL); |
---|
566 | path = ostrcat(path, "/", 0, 0); |
---|
567 | path = ostrcat(path, hddnode->device, 1, 0); |
---|
568 | path = ostrcat(path, "/", 1, 0); |
---|
569 | path = ostrcat(path, "backup", 1, 0); |
---|
570 | if(file_exist(path) == 1) |
---|
571 | { |
---|
572 | tmpstr = ostrcat(tmpstr, " - ", 1, 0); |
---|
573 | tmpstr = ostrcat(tmpstr, _("backup"), 1, 0); |
---|
574 | } |
---|
575 | free(path); path = NULL; |
---|
576 | |
---|
577 | path = getconfig("mountpath", NULL); |
---|
578 | path = ostrcat(path, "/", 0, 0); |
---|
579 | path = ostrcat(path, hddnode->device, 1, 0); |
---|
580 | path = ostrcat(path, "/", 1, 0); |
---|
581 | path = ostrcat(path, "movie", 1, 0); |
---|
582 | if(file_exist(path) == 1) |
---|
583 | { |
---|
584 | tmpstr = ostrcat(tmpstr, " - ", 1, 0); |
---|
585 | tmpstr = ostrcat(tmpstr, _("record"), 1, 0); |
---|
586 | } |
---|
587 | free(path); path = NULL; |
---|
588 | } |
---|
589 | else |
---|
590 | { |
---|
591 | tmpstr = ostrcat(tmpstr, "(", 1, 0); |
---|
592 | tmpstr = ostrcat(tmpstr, hddnode->device, 1, 0); |
---|
593 | tmpstr = ostrcat(tmpstr, "-", 1, 0); |
---|
594 | tmpstr = ostrcat(tmpstr, hddnode->label, 1, 0); |
---|
595 | tmpstr = ostrcat(tmpstr, "-", 1, 0); |
---|
596 | tmpstr = ostrcat(tmpstr, hddnode->filesystem, 1, 0); |
---|
597 | tmpstr = ostrcat(tmpstr, ") ", 1, 0); |
---|
598 | tmpstr = ostrcat(tmpstr, hddnode->model, 1, 0); |
---|
599 | tmpstr = ostrcat(tmpstr, " ", 1, 0); |
---|
600 | tmpstr = ostrcat(tmpstr, blocktogb(hddnode->size), 1, 1); |
---|
601 | tmpstr = ostrcat(tmpstr, " GB", 1, 0); |
---|
602 | } |
---|
603 | changetext(tmp, tmpstr); |
---|
604 | free(tmpstr); tmpstr = NULL; |
---|
605 | |
---|
606 | changename(tmp, hddnode->device); |
---|
607 | tmp->textposx = 120; |
---|
608 | tmp->height = 50; |
---|
609 | tmp->valign = convertxmlentry("middle", 0); |
---|
610 | tmp->hspace = 5; |
---|
611 | |
---|
612 | if(!file_exist(tmpstr1)) |
---|
613 | { |
---|
614 | free(tmpstr1); tmpstr1 = NULL; |
---|
615 | tmpstr1 = ostrcat(tmpstr1, getconfig("skinpath", NULL), 1, 0); |
---|
616 | tmpstr1 = ostrcat(tmpstr1, "/skin/default.png", 1, 0); |
---|
617 | } |
---|
618 | changepic(tmp, tmpstr1); |
---|
619 | free(tmpstr1); tmpstr1 = NULL; |
---|
620 | } |
---|
621 | hddnode = hddnode->next; |
---|
622 | } |
---|
623 | |
---|
624 | drawscreen(screen, 0, 0); |
---|
625 | addscreenrc(screen, listbox); |
---|
626 | |
---|
627 | while (1) |
---|
628 | { |
---|
629 | rcret = waitrc(screen, 0, 0); |
---|
630 | |
---|
631 | if(rcret==getrcconfigint("rcexit",NULL)) break; |
---|
632 | if(listbox->select != NULL && rcret==getrcconfigint("rcok",NULL)) |
---|
633 | { |
---|
634 | if(mode == 0) |
---|
635 | { |
---|
636 | tmpstr = ostrcat(listbox->select->name, NULL, 0, 0); |
---|
637 | screenfilesystem(tmpstr); |
---|
638 | free(tmpstr); tmpstr = NULL; |
---|
639 | } |
---|
640 | else if(mode == 1) |
---|
641 | { |
---|
642 | if(hddfsck(listbox->select->name) == 1) |
---|
643 | continue; |
---|
644 | } |
---|
645 | else if(mode == 2) |
---|
646 | { |
---|
647 | tmpstr = ostrcat(listbox->select->name, NULL, 0, 0); |
---|
648 | screenconfigurehdd(tmpstr); |
---|
649 | free(tmpstr); tmpstr = NULL; |
---|
650 | delownerrc(screen); |
---|
651 | goto start; |
---|
652 | } |
---|
653 | break; |
---|
654 | } |
---|
655 | } |
---|
656 | |
---|
657 | delownerrc(screen); |
---|
658 | delmarkedscreennodes(screen, 1); |
---|
659 | clearscreen(screen); |
---|
660 | } |
---|
661 | |
---|
662 | void hddformat(char* dev, char* filesystem) |
---|
663 | { |
---|
664 | int format = 0; |
---|
665 | int large = 0; |
---|
666 | int rc = 0; |
---|
667 | char* cmd = NULL; |
---|
668 | struct hdd* node = NULL; |
---|
669 | resettvpic(); |
---|
670 | |
---|
671 | node = gethdd(dev); |
---|
672 | if(node == NULL) return; |
---|
673 | |
---|
674 | if(node->size > 4294967295UL) |
---|
675 | { |
---|
676 | if(!file_exist("/var/bin/parted") && !file_exist("/var/swap/bin/parted") && !file_exist("/mnt/swapextensions/bin/parted") && !file_exist("/usr/sbin/parted")) |
---|
677 | { |
---|
678 | textbox(_("Message"), _("HDD > 2TB unsupported.\nYou must first install plugin parted, then you can use this panel."), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 800, 200, 0, 0); |
---|
679 | return; |
---|
680 | } |
---|
681 | large = 1; |
---|
682 | } |
---|
683 | |
---|
684 | if(node->partition == 0) |
---|
685 | { |
---|
686 | 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) |
---|
687 | { |
---|
688 | cmd = ostrcat("/sbin/parter.sh /dev/" , dev, 0, 0); |
---|
689 | cmd = ostrcat(cmd , " create 1 ", 1, 0); |
---|
690 | cmd = ostrcat(cmd , filesystem, 1, 0); |
---|
691 | if(large == 1) |
---|
692 | cmd = ostrcat(cmd , " large", 1, 0); |
---|
693 | |
---|
694 | if(file_exist("/var/swap")) |
---|
695 | { |
---|
696 | if(!file_exist("/var/swap/logs")) |
---|
697 | mkdir("/var/swap/logs", 777); |
---|
698 | |
---|
699 | if(file_exist("/etc/.beta") && file_exist("/var/swap/logs")) |
---|
700 | cmd = ostrcat(cmd, " > /var/swap/logs/format_debug.log 2>&1", 1, 0); |
---|
701 | } |
---|
702 | else if(!file_exist("/etc/.smalbox")) |
---|
703 | { |
---|
704 | if(!file_exist("/mnt/logs")) |
---|
705 | mkdir("/mnt/logs", 777); |
---|
706 | |
---|
707 | if(file_exist("/etc/.beta") && file_exist("/mnt/logs")) |
---|
708 | cmd = ostrcat(cmd, " > /mnt/logs/format_debug.log 2>&1", 1, 0); |
---|
709 | } |
---|
710 | |
---|
711 | debug(80, "fdisk create cmd: %s", cmd); |
---|
712 | system(cmd); |
---|
713 | format = 2; |
---|
714 | free(cmd); cmd = NULL; |
---|
715 | } |
---|
716 | |
---|
717 | } |
---|
718 | else |
---|
719 | { |
---|
720 | 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) |
---|
721 | { |
---|
722 | printf("dev: %s\n", dev); |
---|
723 | |
---|
724 | char* part = oregex(".*([0-9]{1,2}).*", dev); |
---|
725 | printf("part: %s\n", part); |
---|
726 | |
---|
727 | char* devname = oregex(".*([a-z]{3}).*", dev); |
---|
728 | printf("devname: %s\n", devname); |
---|
729 | |
---|
730 | cmd = ostrcat("/sbin/parter.sh /dev/" , devname, 0, 0); |
---|
731 | cmd = ostrcat(cmd , " update ", 1, 0); |
---|
732 | cmd = ostrcat(cmd , part, 1, 0); |
---|
733 | cmd = ostrcat(cmd , " ", 1, 0); |
---|
734 | cmd = ostrcat(cmd , filesystem, 1, 0); |
---|
735 | free(part), part = NULL; |
---|
736 | free(devname), devname = NULL; |
---|
737 | |
---|
738 | if(large == 1) |
---|
739 | cmd = ostrcat(cmd , " large", 1, 0); |
---|
740 | |
---|
741 | if(file_exist("/var/swap")) |
---|
742 | { |
---|
743 | if(!file_exist("/var/swap/logs")) |
---|
744 | mkdir("/var/swap/logs", 777); |
---|
745 | |
---|
746 | if(file_exist("/etc/.beta") && file_exist("/var/swap/logs")) |
---|
747 | cmd = ostrcat(cmd, " > /var/swap/logs/format_debug.log 2>&1", 1, 0); |
---|
748 | } |
---|
749 | else if(!file_exist("/etc/.smalbox")) |
---|
750 | { |
---|
751 | if(!file_exist("/mnt/logs")) |
---|
752 | mkdir("/mnt/logs", 777); |
---|
753 | |
---|
754 | if(file_exist("/etc/.beta") && file_exist("/mnt/logs")) |
---|
755 | cmd = ostrcat(cmd, " > /mnt/logs/format_debug.log 2>&1", 1, 0); |
---|
756 | } |
---|
757 | |
---|
758 | debug(80, "fdisk update cmd: %s", cmd); |
---|
759 | system(cmd); |
---|
760 | format = 1; |
---|
761 | free(cmd); cmd = NULL; |
---|
762 | } |
---|
763 | } |
---|
764 | |
---|
765 | if(format > 0) |
---|
766 | { |
---|
767 | int record = 0, ext = 0, swap = 0, backup = 0; |
---|
768 | |
---|
769 | if(textbox(_("Message"), _("use medium for record"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 800, 200, 0, 0) == 1) |
---|
770 | record = 1; |
---|
771 | |
---|
772 | if(status.expertmodus > 9) |
---|
773 | { |
---|
774 | if(textbox(_("Message"), _("use medium for extension"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 800, 200, 0, 0) == 1) |
---|
775 | ext = 1; |
---|
776 | if(textbox(_("Message"), _("use medium for swap"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 800, 200, 0, 0) == 1) |
---|
777 | swap = 1; |
---|
778 | if(textbox(_("Message"), _("use medium for backup"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 800, 200, 0, 0) == 1) |
---|
779 | backup = 1; |
---|
780 | } |
---|
781 | |
---|
782 | |
---|
783 | if(ostrcmp(filesystem, "vfat") == 0) |
---|
784 | cmd = ostrcat("/sbin/cmd.sh \"mkfs.fat.gui -F 32\" /dev/" , dev, 0, 0); |
---|
785 | else if(ostrcmp(filesystem, "jfs") == 0) |
---|
786 | cmd = ostrcat("/sbin/cmd.sh \"mkfs.jfs.gui -q\" /dev/" , dev, 0, 0); |
---|
787 | else if(ostrcmp(filesystem, "ext2") == 0) |
---|
788 | cmd = ostrcat("/sbin/cmd.sh mkfs.ext2.gui /dev/" , dev, 0, 0); |
---|
789 | else if(ostrcmp(filesystem, "ext3") == 0) |
---|
790 | cmd = ostrcat("/sbin/cmd.sh \"mkfs.ext3.gui -T largefile -m0 -O dir_index\" /dev/" , dev, 0, 0); |
---|
791 | else if(ostrcmp(filesystem, "ext4") == 0) |
---|
792 | cmd = ostrcat("/sbin/cmd.sh \"mkfs.ext4.gui -T largefile -m0 -O dir_index\" /dev/" , dev, 0, 0); |
---|
793 | |
---|
794 | if(format == 2) cmd = ostrcat(cmd , "1", 1, 0); |
---|
795 | |
---|
796 | if(record == 1) |
---|
797 | cmd = ostrcat(cmd , " 1", 1, 0); |
---|
798 | else |
---|
799 | cmd = ostrcat(cmd , " 0", 1, 0); |
---|
800 | |
---|
801 | if(ext == 1) |
---|
802 | cmd = ostrcat(cmd , " 1", 1, 0); |
---|
803 | else |
---|
804 | cmd = ostrcat(cmd , " 0", 1, 0); |
---|
805 | |
---|
806 | if(swap == 1) |
---|
807 | cmd = ostrcat(cmd , " 1", 1, 0); |
---|
808 | else |
---|
809 | cmd = ostrcat(cmd , " 0", 1, 0); |
---|
810 | |
---|
811 | if(backup == 1) |
---|
812 | cmd = ostrcat(cmd , " 1", 1, 0); |
---|
813 | else |
---|
814 | cmd = ostrcat(cmd , " 0", 1, 0); |
---|
815 | |
---|
816 | if(file_exist("/var/swap")) |
---|
817 | { |
---|
818 | if(!file_exist("/var/swap/logs")) |
---|
819 | mkdir("/var/swap/logs", 777); |
---|
820 | |
---|
821 | if(file_exist("/etc/.beta") && file_exist("/var/swap/logs")) |
---|
822 | cmd = ostrcat(cmd, " >> /var/swap/logs/format_debug.log 2>&1", 1, 0); |
---|
823 | } |
---|
824 | else if(!file_exist("/etc/.smalbox")) |
---|
825 | { |
---|
826 | if(!file_exist("/mnt/logs")) |
---|
827 | mkdir("/mnt/logs", 777); |
---|
828 | |
---|
829 | if(file_exist("/etc/.beta") && file_exist("/mnt/logs")) |
---|
830 | cmd = ostrcat(cmd, " >> /mnt/logs/format_debug.log 2>&1", 1, 0); |
---|
831 | } |
---|
832 | |
---|
833 | debug(80, "format cmd: %s", cmd); |
---|
834 | rc = system(cmd); |
---|
835 | free(cmd); cmd = NULL; |
---|
836 | if(rc != 0) |
---|
837 | { |
---|
838 | textbox(_("Message"), _("ERROR\npartition could not be created"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 800, 200, 0, 0); |
---|
839 | return; |
---|
840 | } |
---|
841 | } |
---|
842 | } |
---|
843 | |
---|
844 | int hddfsck(char* dev) |
---|
845 | { |
---|
846 | char* cmd = NULL; |
---|
847 | struct hdd* node = NULL; |
---|
848 | |
---|
849 | node = gethdd(dev); |
---|
850 | if(node == NULL) return 1; |
---|
851 | if(node->filesystem == NULL) return 1; |
---|
852 | debug(80, "device=%s filesystem=%s", dev, node->filesystem); |
---|
853 | resettvpic(); |
---|
854 | |
---|
855 | if(node->size > 524288000UL) |
---|
856 | { |
---|
857 | textbox(_("Message"), _("Information: This hard drive size can take a file\nsystem check between 30 minutes and 1.5 hours."), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 800, 200, 0, 0); |
---|
858 | } |
---|
859 | |
---|
860 | 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) |
---|
861 | { |
---|
862 | if(ostrcmp(node->filesystem, "vfat") == 0) |
---|
863 | cmd = ostrcat("/sbin/cmd.sh \"fsck.fat.gui -a -v\" /dev/" , dev, 0, 0); |
---|
864 | else if(ostrcmp(node->filesystem, "jfs") == 0) |
---|
865 | cmd = ostrcat("/sbin/cmd.sh \"fsck.jfs.gui -f -p\" /dev/" , dev, 0, 0); |
---|
866 | else if(ostrcmp(node->filesystem, "ext2") == 0) |
---|
867 | cmd = ostrcat("/sbin/cmd.sh \"fsck.ext2.gui -f -p\" /dev/" , dev, 0, 0); |
---|
868 | else if(ostrcmp(node->filesystem, "ext3") == 0) |
---|
869 | cmd = ostrcat("/sbin/cmd.sh \"fsck.ext3.gui -f -p\" /dev/" , dev, 0, 0); |
---|
870 | else if(ostrcmp(node->filesystem, "ext4") == 0) |
---|
871 | cmd = ostrcat("/sbin/cmd.sh \"fsck.ext4.gui -f -p\" /dev/" , dev, 0, 0); |
---|
872 | |
---|
873 | if(file_exist("/var/swap")) |
---|
874 | { |
---|
875 | if(!file_exist("/var/swap/logs")) |
---|
876 | mkdir("/var/swap/logs", 777); |
---|
877 | |
---|
878 | if(file_exist("/etc/.beta") && file_exist("/var/swap/logs")) |
---|
879 | cmd = ostrcat(cmd, " > /var/swap/logs/fsck_debug.log 2>&1", 1, 0); |
---|
880 | } |
---|
881 | else if(!file_exist("/etc/.smalbox")) |
---|
882 | { |
---|
883 | if(!file_exist("/mnt/logs")) |
---|
884 | mkdir("/mnt/logs", 777); |
---|
885 | |
---|
886 | if(file_exist("/etc/.beta") && file_exist("/mnt/logs")) |
---|
887 | cmd = ostrcat(cmd, " > /mnt/logs/fsck_debug.log 2>&1", 1, 0); |
---|
888 | } |
---|
889 | |
---|
890 | debug(80, "fsck cmd: %s", cmd); |
---|
891 | system(cmd); |
---|
892 | free(cmd); cmd = NULL; |
---|
893 | } |
---|
894 | |
---|
895 | return 0; |
---|
896 | } |
---|
897 | |
---|
898 | void screenharddisksleep() |
---|
899 | { |
---|
900 | char* sleepWert = NULL; |
---|
901 | int rcret = 0; |
---|
902 | struct skin* sleep_config = getscreen("harddisk_main"); |
---|
903 | struct skin* details = getscreennode(sleep_config, "details"); |
---|
904 | struct skin* listbox = getscreennode(sleep_config, "listbox"); |
---|
905 | struct skin* node = NULL; |
---|
906 | struct skin* tmp = NULL; |
---|
907 | |
---|
908 | /*int m_with = sleep_config->width; |
---|
909 | int m_height = sleep_config->height; |
---|
910 | int m_prozwidth = sleep_config->prozwidth; |
---|
911 | int m_prozheight= sleep_config->prozheight; |
---|
912 | |
---|
913 | sleep_config->prozheight = YES; |
---|
914 | sleep_config->prozwidth = YES; |
---|
915 | sleep_config->width = 40; |
---|
916 | sleep_config->height = 30;*/ |
---|
917 | |
---|
918 | delmarkedscreennodes(sleep_config, 1); |
---|
919 | listbox->aktpage = -1; |
---|
920 | listbox->aktline = 1; |
---|
921 | changetitle(sleep_config, _("Harddisk Sleep")); |
---|
922 | if(details != status.skinerr) changetext(details, _("set here the default sleeptime for all your media drives")); |
---|
923 | |
---|
924 | node = addlistbox(sleep_config, listbox, node, 1); |
---|
925 | if(node != NULL) |
---|
926 | { |
---|
927 | node->type = CHOICEBOX; |
---|
928 | changetext(node, _("Time to sleep")); changename(node, "timetosleep"); |
---|
929 | addchoicebox(node, "0", _("off")); |
---|
930 | addchoicebox(node, "300", _("5 min")); addchoicebox(node, "600", _("10 min")); |
---|
931 | addchoicebox(node, "900", _("15 min")); addchoicebox(node, "3600", _("60 min")); |
---|
932 | |
---|
933 | sleepWert = getconfig("timetosleep", NULL); |
---|
934 | if(sleepWert == NULL) |
---|
935 | setchoiceboxselection(node, "0"); |
---|
936 | else |
---|
937 | setchoiceboxselection(node, sleepWert); |
---|
938 | } |
---|
939 | |
---|
940 | drawscreen(sleep_config, 0, 0); |
---|
941 | tmp = listbox->select; |
---|
942 | |
---|
943 | while(1) |
---|
944 | { |
---|
945 | addscreenrc(sleep_config, tmp); |
---|
946 | rcret = waitrc(sleep_config, 0, 0); |
---|
947 | tmp = listbox->select; |
---|
948 | |
---|
949 | if(rcret == getrcconfigint("rcexit", NULL)) break; |
---|
950 | |
---|
951 | if(listbox->select != NULL && listbox->select->ret != NULL && rcret == getrcconfigint("rcok", NULL)) |
---|
952 | { |
---|
953 | addconfig("timetosleep", listbox->select->ret); |
---|
954 | //settimetosleep(atoi(listbox->select->ret)); |
---|
955 | break; |
---|
956 | } |
---|
957 | } |
---|
958 | |
---|
959 | /*sleep_config->width = m_with; |
---|
960 | sleep_config->height = m_height; |
---|
961 | sleep_config->prozheight = m_prozheight; |
---|
962 | sleep_config->prozwidth = m_prozwidth;*/ |
---|
963 | delmarkedscreennodes(sleep_config, 1); |
---|
964 | delownerrc(sleep_config); |
---|
965 | clearscreen(sleep_config); |
---|
966 | } |
---|
967 | |
---|
968 | //flag 0: lock |
---|
969 | //flag 1: no lock |
---|
970 | void delhdd(char* device, int flag) |
---|
971 | { |
---|
972 | if(flag == 0) m_lock(&status.hddmutex, 13); |
---|
973 | struct hdd *node = hdd, *prev = hdd; |
---|
974 | |
---|
975 | while(node != NULL) |
---|
976 | { |
---|
977 | if(ostrcmp(node->device, device) == 0) |
---|
978 | { |
---|
979 | if(node == hdd) |
---|
980 | { |
---|
981 | hdd = node->next; |
---|
982 | if(hdd != NULL) |
---|
983 | hdd->prev = NULL; |
---|
984 | } |
---|
985 | else |
---|
986 | { |
---|
987 | prev->next = node->next; |
---|
988 | if(node->next != NULL) |
---|
989 | node->next->prev = prev; |
---|
990 | } |
---|
991 | |
---|
992 | free(node->device); node->device = NULL; |
---|
993 | free(node->vendor); node->vendor = NULL; |
---|
994 | free(node->model); node->model = NULL; |
---|
995 | free(node->label); node->label = NULL; |
---|
996 | free(node->uuid); node->uuid = NULL; |
---|
997 | free(node->filesystem); node->filesystem = NULL; |
---|
998 | |
---|
999 | free(node); |
---|
1000 | node = NULL; |
---|
1001 | break; |
---|
1002 | } |
---|
1003 | |
---|
1004 | prev = node; |
---|
1005 | node = node->next; |
---|
1006 | } |
---|
1007 | if(flag == 0) m_unlock(&status.hddmutex, 13); |
---|
1008 | } |
---|
1009 | |
---|
1010 | //flag 0: lock |
---|
1011 | //flag 1: no lock |
---|
1012 | struct hdd* addhdd(char* device, int partition, unsigned long long size, int removable, char* vendor, char *model, char* label, char* filesystem, char* uuid, int timetosleep, struct hdd* last, int flag) |
---|
1013 | { |
---|
1014 | if(flag == 0) m_lock(&status.hddmutex, 13); |
---|
1015 | struct hdd *newnode = NULL, *prev = NULL, *node = hdd; |
---|
1016 | |
---|
1017 | newnode = (struct hdd*)malloc(sizeof(struct hdd)); |
---|
1018 | if(newnode == NULL) |
---|
1019 | { |
---|
1020 | err("no memory"); |
---|
1021 | if(flag == 0) m_unlock(&status.hddmutex, 13); |
---|
1022 | return NULL; |
---|
1023 | } |
---|
1024 | memset(newnode, 0, sizeof(struct hdd)); |
---|
1025 | |
---|
1026 | newnode->device = device; |
---|
1027 | newnode->partition = partition; |
---|
1028 | newnode->size = size; |
---|
1029 | newnode->removable = removable; |
---|
1030 | newnode->vendor = vendor; |
---|
1031 | newnode->model = model; |
---|
1032 | newnode->label = label; |
---|
1033 | newnode->uuid = uuid; |
---|
1034 | newnode->filesystem = filesystem; |
---|
1035 | newnode->read = 0; |
---|
1036 | newnode->write = 0; |
---|
1037 | newnode->sleeptime = timetosleep; |
---|
1038 | newnode->notchanged = 0; |
---|
1039 | |
---|
1040 | debug(80, "add hdd %s", device); |
---|
1041 | |
---|
1042 | if(last == NULL) |
---|
1043 | { |
---|
1044 | while(node != NULL && strcoll(newnode->device, node->device) > 0) |
---|
1045 | { |
---|
1046 | prev = node; |
---|
1047 | node = node->next; |
---|
1048 | } |
---|
1049 | } |
---|
1050 | else |
---|
1051 | { |
---|
1052 | prev = last; |
---|
1053 | node = last->next; |
---|
1054 | } |
---|
1055 | |
---|
1056 | if(prev == NULL) |
---|
1057 | { |
---|
1058 | hdd = newnode; |
---|
1059 | } |
---|
1060 | else |
---|
1061 | { |
---|
1062 | prev->next = newnode; |
---|
1063 | newnode->prev = prev; |
---|
1064 | } |
---|
1065 | newnode->next = node; |
---|
1066 | |
---|
1067 | //show message for new, not configured devices |
---|
1068 | //check only partition 1 |
---|
1069 | if(status.standby == 0 && newnode->partition == 1 && ostrstr(newnode->device, "1") != NULL) |
---|
1070 | { |
---|
1071 | char* tmpstr = NULL, *backup = NULL, *movie = NULL, *swapextensions = NULL, *swapfile = NULL, *checkfile = NULL; |
---|
1072 | int newdev = 1, ret = 0; |
---|
1073 | |
---|
1074 | tmpstr = ostrcat("/autofs/", newnode->device, 0, 0); |
---|
1075 | checkfile = ostrcat(tmpstr, "/.titandev", 0, 0); |
---|
1076 | if(file_exist(checkfile) == 0) |
---|
1077 | { |
---|
1078 | backup = ostrcat(tmpstr, "/backup", 0, 0); |
---|
1079 | movie = ostrcat(tmpstr, "/movie", 0, 0); |
---|
1080 | swapextensions = ostrcat(tmpstr, "/swapextensions", 0, 0); |
---|
1081 | swapfile = ostrcat(tmpstr, "/swapfile", 0, 0); |
---|
1082 | |
---|
1083 | if(file_exist(movie) == 1 || file_exist(swapextensions)== 1 || file_exist(backup) == 1 || file_exist(swapfile) == 1) |
---|
1084 | newdev = 0; |
---|
1085 | |
---|
1086 | ret = writesys(checkfile, "titan", 1); |
---|
1087 | if(ret == 0) |
---|
1088 | { |
---|
1089 | sync(); |
---|
1090 | if(newdev == 1) |
---|
1091 | textbox("Message", _("Found new Stick/HDD.\nYou can configure it in Harddisk Menu."), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 800, 200, 15, 0); |
---|
1092 | } |
---|
1093 | } |
---|
1094 | free(tmpstr); tmpstr = NULL; |
---|
1095 | free(backup); backup = NULL; |
---|
1096 | free(movie); movie = NULL; |
---|
1097 | free(swapextensions); swapextensions = NULL; |
---|
1098 | free(swapfile); swapfile = NULL; |
---|
1099 | free(checkfile); checkfile = NULL; |
---|
1100 | } |
---|
1101 | |
---|
1102 | if(flag == 0) m_unlock(&status.hddmutex, 13); |
---|
1103 | return newnode; |
---|
1104 | } |
---|
1105 | |
---|
1106 | //flag = 0: mutex lock |
---|
1107 | //flag = 1: no mutex lock |
---|
1108 | void freehdd(int flag) |
---|
1109 | { |
---|
1110 | if(flag == 0) m_lock(&status.hddmutex, 13); |
---|
1111 | struct hdd *node = hdd, *prev = hdd; |
---|
1112 | |
---|
1113 | while(node != NULL) |
---|
1114 | { |
---|
1115 | prev = node; |
---|
1116 | node = node->next; |
---|
1117 | if(prev != NULL) |
---|
1118 | delhdd(prev->device, 1); |
---|
1119 | } |
---|
1120 | if(flag == 0) m_unlock(&status.hddmutex, 13); |
---|
1121 | } |
---|
1122 | |
---|
1123 | int addhddall() |
---|
1124 | { |
---|
1125 | m_lock(&status.hddmutex, 13); |
---|
1126 | FILE* fd = NULL; |
---|
1127 | FILE* fd2 = NULL; |
---|
1128 | char* fileline = NULL, *dev = NULL, *pos = NULL, *part = NULL; |
---|
1129 | char* tmpstr = NULL; |
---|
1130 | char* tmpstr2 = NULL; |
---|
1131 | int partition = 0; |
---|
1132 | int timetosleep = 0; |
---|
1133 | struct hdd *node = hdd; |
---|
1134 | struct hdd *nodedev = hdd; |
---|
1135 | int w1, w2, w3, w4, w5; |
---|
1136 | |
---|
1137 | fd = fopen("/proc/partitions", "r"); |
---|
1138 | if(fd == NULL) |
---|
1139 | { |
---|
1140 | err("open /proc/partitions"); |
---|
1141 | m_unlock(&status.hddmutex, 13); |
---|
1142 | return 1; |
---|
1143 | } |
---|
1144 | |
---|
1145 | fileline = malloc(MINMALLOC); |
---|
1146 | if(fileline == NULL) |
---|
1147 | { |
---|
1148 | err("no mem"); |
---|
1149 | m_unlock(&status.hddmutex, 13); |
---|
1150 | return 1; |
---|
1151 | } |
---|
1152 | |
---|
1153 | while(fgets(fileline, MINMALLOC, fd) != NULL) |
---|
1154 | { |
---|
1155 | pos = ostrstr(fileline, "sd"); |
---|
1156 | if(pos != NULL) |
---|
1157 | { |
---|
1158 | partition = 0; |
---|
1159 | part = NULL; |
---|
1160 | pos = string_newline(pos); |
---|
1161 | if(strlen(pos) == 3) |
---|
1162 | { |
---|
1163 | free(dev); dev = NULL; |
---|
1164 | dev = ostrcat(pos, NULL, 0, 0); |
---|
1165 | if(getconfig("timetosleep", NULL) == NULL) |
---|
1166 | timetosleep = 0; |
---|
1167 | else |
---|
1168 | timetosleep = atoi(getconfig("timetosleep", NULL)); |
---|
1169 | } |
---|
1170 | if(strlen(pos) == 4) |
---|
1171 | { |
---|
1172 | part = pos; |
---|
1173 | partition = atoi(&pos[3]); |
---|
1174 | } |
---|
1175 | tmpstr = ostrcat(tmpstr, "#", 1, 0); |
---|
1176 | tmpstr = ostrcat(tmpstr, pos, 1, 0); |
---|
1177 | //if(gethdd(pos) == NULL) |
---|
1178 | nodedev = gethdd(pos); |
---|
1179 | if(nodedev == NULL) |
---|
1180 | 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); |
---|
1181 | |
---|
1182 | //HDD SleepTimer start |
---|
1183 | if(nodedev != NULL) { |
---|
1184 | if(nodedev->sleeptime != timetosleep) { |
---|
1185 | nodedev->read = 0; |
---|
1186 | nodedev->write = 0; |
---|
1187 | nodedev->sleeptime = timetosleep; |
---|
1188 | nodedev->notchanged = 0; |
---|
1189 | } |
---|
1190 | if(strlen(pos) == 3 && timetosleep > 0) { |
---|
1191 | free(tmpstr2);tmpstr2=NULL; |
---|
1192 | tmpstr2 = ostrcat(tmpstr2, "/sys/block/", 1, 0); |
---|
1193 | tmpstr2 = ostrcat(tmpstr2, nodedev->device, 1, 0); |
---|
1194 | tmpstr2 = ostrcat(tmpstr2, "/stat", 1, 0); |
---|
1195 | fd2 = fopen(tmpstr2, "r"); |
---|
1196 | if(fd2 != NULL) { |
---|
1197 | fscanf(fd2, "%d%d%d%d%d", &w1,&w2,&w3,&w4,&w5); |
---|
1198 | fclose(fd2); |
---|
1199 | fd2 = NULL; |
---|
1200 | if((nodedev->read != w1) || (nodedev->write != w5)) { |
---|
1201 | nodedev->read = w1; |
---|
1202 | nodedev->write = w5; |
---|
1203 | nodedev->notchanged = 0; |
---|
1204 | } else { |
---|
1205 | if (nodedev->notchanged < nodedev->sleeptime) { |
---|
1206 | nodedev->notchanged = nodedev->notchanged + (status.addhddall->delay / 1000); |
---|
1207 | if (nodedev->notchanged >= nodedev->sleeptime) { |
---|
1208 | free(tmpstr2);tmpstr2=NULL; |
---|
1209 | #ifdef MIPSEL |
---|
1210 | tmpstr2 = ostrcat(tmpstr2, "sdparm -C stop /dev/", 1, 0); |
---|
1211 | #else |
---|
1212 | tmpstr2 = ostrcat(tmpstr2, "hd-idle -t ", 1, 0); |
---|
1213 | #endif |
---|
1214 | tmpstr2 = ostrcat(tmpstr2, nodedev->device, 1, 0); |
---|
1215 | printf("cmd: %s\n", tmpstr2); |
---|
1216 | system(tmpstr2); |
---|
1217 | } |
---|
1218 | } |
---|
1219 | } |
---|
1220 | } |
---|
1221 | } |
---|
1222 | } |
---|
1223 | //HDD SleepTimer end |
---|
1224 | |
---|
1225 | } |
---|
1226 | } |
---|
1227 | |
---|
1228 | //check for removed devs |
---|
1229 | while(node != NULL && tmpstr != NULL) |
---|
1230 | { |
---|
1231 | if(ostrstr(tmpstr, node->device) == NULL) |
---|
1232 | { |
---|
1233 | debug(80, "remove %s", node->device); |
---|
1234 | delhdd(node->device, 1); |
---|
1235 | } |
---|
1236 | node = node->next; |
---|
1237 | } |
---|
1238 | |
---|
1239 | if(node != NULL && tmpstr == NULL) |
---|
1240 | { |
---|
1241 | debug(80, "remove all"); |
---|
1242 | freehdd(1); |
---|
1243 | } |
---|
1244 | |
---|
1245 | free(tmpstr); |
---|
1246 | free(tmpstr2); |
---|
1247 | free(dev); |
---|
1248 | free(fileline); |
---|
1249 | fclose(fd); |
---|
1250 | m_unlock(&status.hddmutex, 13); |
---|
1251 | return 0; |
---|
1252 | } |
---|
1253 | |
---|
1254 | #endif |
---|