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* titletext = getscreennode(screen, "titletext"); |
---|
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(titletext != status.skinerr) changetext(titletext, _("Harddisk Format - Filesystem")); |
---|
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 = 2, rcret = 0, ret = 0, mode = 0; |
---|
202 | struct skin* screen = getscreen("harddisk_main"); |
---|
203 | struct skin* titletext = getscreennode(screen, "titletext"); |
---|
204 | struct skin* listbox = getscreennode(screen, "listbox"); |
---|
205 | struct skin* load = getscreen("loading"); |
---|
206 | struct skin* tmp = NULL; |
---|
207 | char* tmpstr = NULL, *tmpstr1 = NULL, *tmpstr2 = NULL; |
---|
208 | char* path = NULL; |
---|
209 | |
---|
210 | delmarkedscreennodes(screen, 1); |
---|
211 | listbox->aktpage = -1; |
---|
212 | listbox->aktline = 1; |
---|
213 | changetitle(screen, _("Harddisk Configure")); |
---|
214 | if(titletext != status.skinerr) changetext(titletext, _("Harddisk Configure")); |
---|
215 | |
---|
216 | if(status.expertmodus > 9) y = 8; |
---|
217 | |
---|
218 | for(i = 0; i < y; i++) |
---|
219 | { |
---|
220 | tmp = addlistbox(screen, listbox, tmp, 1); |
---|
221 | if(tmp != NULL) |
---|
222 | { |
---|
223 | if(i == 0) |
---|
224 | { |
---|
225 | tmpstr = _("use medium for record"); |
---|
226 | tmpstr1 = "addrecord"; |
---|
227 | } |
---|
228 | else if(i == 1) |
---|
229 | { |
---|
230 | tmpstr = _("del medium for record"); |
---|
231 | tmpstr1 = "delrecord"; |
---|
232 | } |
---|
233 | else if(i == 2) |
---|
234 | { |
---|
235 | tmpstr = _("use medium for extension"); |
---|
236 | tmpstr1 = "addext"; |
---|
237 | } |
---|
238 | else if(i == 3) |
---|
239 | { |
---|
240 | tmpstr = _("del medium for extension"); |
---|
241 | tmpstr1 = "delext"; |
---|
242 | } |
---|
243 | else if(i == 4) |
---|
244 | { |
---|
245 | tmpstr = _("use medium for swap"); |
---|
246 | tmpstr1 = "addswap"; |
---|
247 | } |
---|
248 | else if(i == 5) |
---|
249 | { |
---|
250 | tmpstr = _("del medium for swap"); |
---|
251 | tmpstr1 = "delswap"; |
---|
252 | } |
---|
253 | else if(i == 6) |
---|
254 | { |
---|
255 | tmpstr = _("use medium for backup"); |
---|
256 | tmpstr1 = "addbackup"; |
---|
257 | } |
---|
258 | else if(i == 7) |
---|
259 | { |
---|
260 | tmpstr = _("del medium for backup"); |
---|
261 | tmpstr1 = "delbackup"; |
---|
262 | } |
---|
263 | tmpstr2 = ostrcat(tmpstr2, getconfig("skinpath", NULL), 1, 0); |
---|
264 | tmpstr2 = ostrcat(tmpstr2, "/skin/", 1, 0); |
---|
265 | tmpstr2 = ostrcat(tmpstr2, tmpstr1, 1, 0); |
---|
266 | tmpstr2 = ostrcat(tmpstr2, ".png", 1, 0); |
---|
267 | |
---|
268 | if(!file_exist(tmpstr2)) |
---|
269 | { |
---|
270 | free(tmpstr2); tmpstr2 = NULL; |
---|
271 | tmpstr2 = ostrcat(tmpstr2, getconfig("skinpath", NULL), 1, 0); |
---|
272 | tmpstr2 = ostrcat(tmpstr2, "/skin/default.png", 1, 0); |
---|
273 | } |
---|
274 | changepic(tmp, tmpstr2); |
---|
275 | free(tmpstr2); tmpstr2 = NULL; |
---|
276 | |
---|
277 | changetext(tmp, tmpstr); |
---|
278 | changename(tmp, tmpstr1); |
---|
279 | tmp->textposx = 120; |
---|
280 | tmp->height = 50; |
---|
281 | tmp->valign = convertxmlentry("middle", 0); |
---|
282 | tmp->hspace = 5; |
---|
283 | } |
---|
284 | } |
---|
285 | |
---|
286 | drawscreen(screen, 0, 0); |
---|
287 | addscreenrc(screen, listbox); |
---|
288 | |
---|
289 | while (1) |
---|
290 | { |
---|
291 | rcret = waitrc(screen, 0, 0); |
---|
292 | |
---|
293 | if(rcret==getrcconfigint("rcexit",NULL)) break; |
---|
294 | if(listbox->select != NULL && rcret==getrcconfigint("rcok",NULL)) |
---|
295 | { |
---|
296 | path = getconfig("mountpath", NULL); |
---|
297 | path = ostrcat(path, "/", 0, 0); |
---|
298 | path = ostrcat(path, dev, 1, 0); |
---|
299 | path = ostrcat(path, "/", 1, 0); |
---|
300 | |
---|
301 | if(ostrcmp(listbox->select->name, "addrecord") == 0) |
---|
302 | { |
---|
303 | mode = 0; |
---|
304 | path = ostrcat(path, "movie", 1, 0); |
---|
305 | } |
---|
306 | if(ostrcmp(listbox->select->name, "addswap") == 0) |
---|
307 | { |
---|
308 | mode = 0; |
---|
309 | path = ostrcat(path, "swapdir", 1, 0); |
---|
310 | } |
---|
311 | if(ostrcmp(listbox->select->name, "addext") == 0) |
---|
312 | { |
---|
313 | mode = 0; |
---|
314 | path = ostrcat(path, "swapextensions", 1, 0); |
---|
315 | } |
---|
316 | if(ostrcmp(listbox->select->name, "addbackup") == 0) |
---|
317 | { |
---|
318 | mode = 0; |
---|
319 | path = ostrcat(path, "backup", 1, 0); |
---|
320 | } |
---|
321 | if(ostrcmp(listbox->select->name, "delrecord") == 0) |
---|
322 | { |
---|
323 | mode = 1; |
---|
324 | path = ostrcat(path, "movie", 1, 0); |
---|
325 | } |
---|
326 | if(ostrcmp(listbox->select->name, "delswap") == 0) |
---|
327 | { |
---|
328 | mode = 1; |
---|
329 | path = ostrcat(path, "swapdir", 1, 0); |
---|
330 | } |
---|
331 | if(ostrcmp(listbox->select->name, "delext") == 0) |
---|
332 | { |
---|
333 | mode = 1; |
---|
334 | path = ostrcat(path, "swapextensions", 1, 0); |
---|
335 | } |
---|
336 | if(ostrcmp(listbox->select->name, "delbackup") == 0) |
---|
337 | { |
---|
338 | mode = 1; |
---|
339 | path = ostrcat(path, "backup", 1, 0); |
---|
340 | } |
---|
341 | |
---|
342 | if(mode == 0) ret = mkdir(path, 0777); |
---|
343 | if(mode == 1) |
---|
344 | { |
---|
345 | if(textbox("Message", _("Are you sure you want to delete this directory?"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 800, 200, 0, 0) == 1) |
---|
346 | { |
---|
347 | ret = rmdir(path); |
---|
348 | if(ret < 0) |
---|
349 | { |
---|
350 | if(textbox("Message", _("Directory has content\nReally delete directory and content?"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 800, 200, 0, 0) == 1) |
---|
351 | { |
---|
352 | drawscreen(load, 0, 0); |
---|
353 | ret = -1; |
---|
354 | |
---|
355 | if(ostrcmp(listbox->select->name, "delswap") == 0) |
---|
356 | system("hotplug.sh delSwap"); |
---|
357 | |
---|
358 | char* cmd = NULL; |
---|
359 | cmd = ostrcat("rm -rf ", path, 0, 0); |
---|
360 | system(cmd); |
---|
361 | free(cmd); cmd = NULL; |
---|
362 | if(file_exist(path) == 0) ret = 0; |
---|
363 | clearscreen(load); |
---|
364 | } |
---|
365 | else |
---|
366 | ret = 9999; |
---|
367 | } |
---|
368 | } |
---|
369 | else |
---|
370 | ret = 9999; |
---|
371 | } |
---|
372 | free(path); path = NULL; |
---|
373 | if(ret < 0) |
---|
374 | { |
---|
375 | if(mode == 0) perr("mkdir"); |
---|
376 | if(mode == 1) perr("rmdir"); |
---|
377 | textbox("Message", _("can't create or delete directory"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 800, 200, 5, 0); |
---|
378 | } |
---|
379 | else if(ret != 9999) |
---|
380 | { |
---|
381 | textbox("Message", _("succesfull create or delelete directory"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 800, 200, 5, 0); |
---|
382 | //start hotplug after create/del dir |
---|
383 | if(ostrcmp(listbox->select->name, "addrecord") == 0 || ostrcmp(listbox->select->name, "addswap") == 0 || ostrcmp(listbox->select->name, "addext") == 0 || ostrcmp(listbox->select->name, "addbackup") == 0) |
---|
384 | { |
---|
385 | drawscreen(load, 0, 0); |
---|
386 | system("hotplug.sh first"); |
---|
387 | clearscreen(load); |
---|
388 | } |
---|
389 | if(ostrcmp(listbox->select->name, "delrecord") == 0) |
---|
390 | { |
---|
391 | drawscreen(load, 0, 0); |
---|
392 | system("hotplug.sh delRecord"); |
---|
393 | clearscreen(load); |
---|
394 | } |
---|
395 | if(ostrcmp(listbox->select->name, "delext") == 0) |
---|
396 | { |
---|
397 | drawscreen(load, 0, 0); |
---|
398 | system("hotplug.sh delSwapextensions"); |
---|
399 | clearscreen(load); |
---|
400 | } |
---|
401 | if(ostrcmp(listbox->select->name, "delbackup") == 0) |
---|
402 | { |
---|
403 | drawscreen(load, 0, 0); |
---|
404 | system("hotplug.sh delBackup"); |
---|
405 | clearscreen(load); |
---|
406 | } |
---|
407 | } |
---|
408 | drawscreen(screen, 0, 0); |
---|
409 | } |
---|
410 | } |
---|
411 | delownerrc(screen); |
---|
412 | delmarkedscreennodes(screen, 1); |
---|
413 | clearscreen(screen); |
---|
414 | } |
---|
415 | |
---|
416 | void screenharddisk(int mode) |
---|
417 | { |
---|
418 | struct skin* screen = getscreen("harddisk_main"); |
---|
419 | struct skin* listbox = getscreennode(screen, "listbox"); |
---|
420 | struct skin* titletext = getscreennode(screen, "titletext"); |
---|
421 | struct skin* tmp = NULL; |
---|
422 | struct hdd* hddnode = NULL; |
---|
423 | int tmphangtime = 999999, rcret = 0; |
---|
424 | char* tmpstr = NULL, *tmpstr1 = NULL, *path = NULL; |
---|
425 | |
---|
426 | addhddall(); |
---|
427 | start: |
---|
428 | tmp = NULL; |
---|
429 | hddnode = hdd; |
---|
430 | |
---|
431 | if(hdd == NULL) |
---|
432 | { |
---|
433 | textbox(_("Harddisk"), _("sorry found no harddisk"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 800, 600, 0, 0); |
---|
434 | return; |
---|
435 | } |
---|
436 | |
---|
437 | status.hangtime = tmphangtime; |
---|
438 | delmarkedscreennodes(screen, 1); |
---|
439 | if(mode == 0) |
---|
440 | { |
---|
441 | changetitle(screen, _("Harddisk Format - List Devices")); |
---|
442 | if(titletext != status.skinerr) changetext(titletext, _("Harddisk Format - List Devices")); |
---|
443 | } |
---|
444 | else if(mode == 1) |
---|
445 | { |
---|
446 | changetitle(screen, _("Harddisk Fsck - List Devices")); |
---|
447 | if(titletext != status.skinerr) changetext(titletext, _("Harddisk Fsck - List Devices")); |
---|
448 | } |
---|
449 | else if(mode == 2) |
---|
450 | { |
---|
451 | changetitle(screen, _("Harddisk Configure - List Devices")); |
---|
452 | if(titletext != status.skinerr) changetext(titletext, _("Harddisk Configure - List Devices")); |
---|
453 | } |
---|
454 | |
---|
455 | listbox->aktpage = -1; |
---|
456 | listbox->aktline = 1; |
---|
457 | |
---|
458 | while(hddnode != NULL) |
---|
459 | { |
---|
460 | if(mode == 2 && hddnode->partition == 0) |
---|
461 | { |
---|
462 | hddnode = hddnode->next; |
---|
463 | continue; |
---|
464 | } |
---|
465 | tmp = addlistbox(screen, listbox, tmp, 1); |
---|
466 | if(tmp != NULL) |
---|
467 | { |
---|
468 | if(hddnode->removable == 0) |
---|
469 | { |
---|
470 | tmpstr = ostrcat(tmpstr, _("HDD "), 1, 0); |
---|
471 | tmpstr1 = ostrcat(tmpstr1, getconfig("skinpath", NULL), 1, 0); |
---|
472 | tmpstr1 = ostrcat(tmpstr1, "/skin/hdd.png", 1, 0); |
---|
473 | } |
---|
474 | else |
---|
475 | { |
---|
476 | tmpstr = ostrcat(tmpstr, _("STICK "), 1, 0); |
---|
477 | tmpstr1 = ostrcat(tmpstr1, getconfig("skinpath", NULL), 1, 0); |
---|
478 | tmpstr1 = ostrcat(tmpstr1, "/skin/stick.png", 1, 0); |
---|
479 | } |
---|
480 | if(mode == 2) |
---|
481 | { |
---|
482 | tmpstr = ostrcat(tmpstr, hddnode->label, 1, 0); |
---|
483 | tmpstr = ostrcat(tmpstr, " (", 1, 0); |
---|
484 | tmpstr = ostrcat(tmpstr, hddnode->device, 1, 0); |
---|
485 | tmpstr = ostrcat(tmpstr, ")", 1, 0); |
---|
486 | |
---|
487 | path = getconfig("mountpath", NULL); |
---|
488 | path = ostrcat(path, "/", 0, 0); |
---|
489 | path = ostrcat(path, hddnode->device, 1, 0); |
---|
490 | path = ostrcat(path, "/", 1, 0); |
---|
491 | path = ostrcat(path, "swapextensions", 1, 0); |
---|
492 | if(file_exist(path) == 1) |
---|
493 | { |
---|
494 | tmpstr = ostrcat(tmpstr, " - ", 1, 0); |
---|
495 | tmpstr = ostrcat(tmpstr, _("ext"), 1, 0); |
---|
496 | } |
---|
497 | free(path); path = NULL; |
---|
498 | |
---|
499 | path = getconfig("mountpath", NULL); |
---|
500 | path = ostrcat(path, "/", 0, 0); |
---|
501 | path = ostrcat(path, hddnode->device, 1, 0); |
---|
502 | path = ostrcat(path, "/", 1, 0); |
---|
503 | path = ostrcat(path, "swapdir", 1, 0); |
---|
504 | if(file_exist(path) == 1) |
---|
505 | { |
---|
506 | tmpstr = ostrcat(tmpstr, " - ", 1, 0); |
---|
507 | tmpstr = ostrcat(tmpstr, _("swap"), 1, 0); |
---|
508 | } |
---|
509 | free(path); path = NULL; |
---|
510 | |
---|
511 | path = getconfig("mountpath", NULL); |
---|
512 | path = ostrcat(path, "/", 0, 0); |
---|
513 | path = ostrcat(path, hddnode->device, 1, 0); |
---|
514 | path = ostrcat(path, "/", 1, 0); |
---|
515 | path = ostrcat(path, "backup", 1, 0); |
---|
516 | if(file_exist(path) == 1) |
---|
517 | { |
---|
518 | tmpstr = ostrcat(tmpstr, " - ", 1, 0); |
---|
519 | tmpstr = ostrcat(tmpstr, _("backup"), 1, 0); |
---|
520 | } |
---|
521 | free(path); path = NULL; |
---|
522 | |
---|
523 | path = getconfig("mountpath", NULL); |
---|
524 | path = ostrcat(path, "/", 0, 0); |
---|
525 | path = ostrcat(path, hddnode->device, 1, 0); |
---|
526 | path = ostrcat(path, "/", 1, 0); |
---|
527 | path = ostrcat(path, "movie", 1, 0); |
---|
528 | if(file_exist(path) == 1) |
---|
529 | { |
---|
530 | tmpstr = ostrcat(tmpstr, " - ", 1, 0); |
---|
531 | tmpstr = ostrcat(tmpstr, _("record"), 1, 0); |
---|
532 | } |
---|
533 | free(path); path = NULL; |
---|
534 | } |
---|
535 | else |
---|
536 | { |
---|
537 | tmpstr = ostrcat(tmpstr, "(", 1, 0); |
---|
538 | tmpstr = ostrcat(tmpstr, hddnode->device, 1, 0); |
---|
539 | tmpstr = ostrcat(tmpstr, "-", 1, 0); |
---|
540 | tmpstr = ostrcat(tmpstr, hddnode->label, 1, 0); |
---|
541 | tmpstr = ostrcat(tmpstr, "-", 1, 0); |
---|
542 | tmpstr = ostrcat(tmpstr, hddnode->filesystem, 1, 0); |
---|
543 | tmpstr = ostrcat(tmpstr, ") ", 1, 0); |
---|
544 | tmpstr = ostrcat(tmpstr, hddnode->model, 1, 0); |
---|
545 | tmpstr = ostrcat(tmpstr, " ", 1, 0); |
---|
546 | tmpstr = ostrcat(tmpstr, blocktogb(hddnode->size), 1, 1); |
---|
547 | tmpstr = ostrcat(tmpstr, " GB", 1, 0); |
---|
548 | } |
---|
549 | changetext(tmp, tmpstr); |
---|
550 | free(tmpstr); tmpstr = NULL; |
---|
551 | |
---|
552 | changename(tmp, hddnode->device); |
---|
553 | tmp->textposx = 120; |
---|
554 | tmp->height = 50; |
---|
555 | tmp->valign = convertxmlentry("middle", 0); |
---|
556 | tmp->hspace = 5; |
---|
557 | |
---|
558 | if(!file_exist(tmpstr1)) |
---|
559 | { |
---|
560 | free(tmpstr1); tmpstr1 = NULL; |
---|
561 | tmpstr1 = ostrcat(tmpstr1, getconfig("skinpath", NULL), 1, 0); |
---|
562 | tmpstr1 = ostrcat(tmpstr1, "/skin/default.png", 1, 0); |
---|
563 | } |
---|
564 | changepic(tmp, tmpstr1); |
---|
565 | free(tmpstr1); tmpstr1 = NULL; |
---|
566 | } |
---|
567 | hddnode = hddnode->next; |
---|
568 | } |
---|
569 | |
---|
570 | drawscreen(screen, 0, 0); |
---|
571 | addscreenrc(screen, listbox); |
---|
572 | |
---|
573 | while (1) |
---|
574 | { |
---|
575 | rcret = waitrc(screen, 0, 0); |
---|
576 | |
---|
577 | if(rcret==getrcconfigint("rcexit",NULL)) break; |
---|
578 | if(listbox->select != NULL && rcret==getrcconfigint("rcok",NULL)) |
---|
579 | { |
---|
580 | if(mode == 0) |
---|
581 | { |
---|
582 | tmpstr = ostrcat(listbox->select->name, NULL, 0, 0); |
---|
583 | screenfilesystem(tmpstr); |
---|
584 | free(tmpstr); tmpstr = NULL; |
---|
585 | } |
---|
586 | else if(mode == 1) |
---|
587 | { |
---|
588 | if(hddfsck(listbox->select->name) == 1) |
---|
589 | continue; |
---|
590 | } |
---|
591 | else if(mode == 2) |
---|
592 | { |
---|
593 | tmpstr = ostrcat(listbox->select->name, NULL, 0, 0); |
---|
594 | screenconfigurehdd(tmpstr); |
---|
595 | free(tmpstr); tmpstr = NULL; |
---|
596 | delownerrc(screen); |
---|
597 | goto start; |
---|
598 | } |
---|
599 | break; |
---|
600 | } |
---|
601 | } |
---|
602 | |
---|
603 | delownerrc(screen); |
---|
604 | delmarkedscreennodes(screen, 1); |
---|
605 | clearscreen(screen); |
---|
606 | } |
---|
607 | |
---|
608 | void hddformat(char* dev, char* filesystem) |
---|
609 | { |
---|
610 | int format = 0; |
---|
611 | int large = 0; |
---|
612 | int rc = 0; |
---|
613 | char* cmd = NULL; |
---|
614 | struct hdd* node = NULL; |
---|
615 | |
---|
616 | |
---|
617 | node = gethdd(dev); |
---|
618 | if(node == NULL) return; |
---|
619 | |
---|
620 | if(node->size > 4294967295UL) |
---|
621 | { |
---|
622 | if(!file_exist("/var/bin/parted") && !file_exist("/var/swap/bin/parted") && !file_exist("/mnt/swapextensions/bin/parted")) |
---|
623 | { |
---|
624 | 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); |
---|
625 | return; |
---|
626 | } |
---|
627 | large = 1; |
---|
628 | } |
---|
629 | |
---|
630 | if(node->partition == 0) |
---|
631 | { |
---|
632 | 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) |
---|
633 | { |
---|
634 | cmd = ostrcat("/sbin/parter.sh /dev/" , dev, 0, 0); |
---|
635 | cmd = ostrcat(cmd , " create 1 ", 1, 0); |
---|
636 | cmd = ostrcat(cmd , filesystem, 1, 0); |
---|
637 | if(large == 1) |
---|
638 | cmd = ostrcat(cmd , " large", 1, 0); |
---|
639 | |
---|
640 | if(checkbox("ATEMIO520") == 1 || checkbox("ATEMIO530") == 1 || checkbox("UFS912") == 1 || checkbox("ATEMIO7600") == 1) |
---|
641 | { |
---|
642 | if(!file_exist("/mnt/logs")) |
---|
643 | mkdir("/mnt/logs", 777); |
---|
644 | |
---|
645 | if(file_exist("/etc/.beta") && file_exist("/mnt/logs")) |
---|
646 | cmd = ostrcat(cmd, " > /mnt/logs/format_debug.log 2>&1", 1, 0); |
---|
647 | } |
---|
648 | else if(file_exist("/var/swap")) |
---|
649 | { |
---|
650 | if(!file_exist("/var/swap/logs")) |
---|
651 | mkdir("/var/swap/logs", 777); |
---|
652 | |
---|
653 | if(file_exist("/etc/.beta") && file_exist("/var/swap/logs")) |
---|
654 | cmd = ostrcat(cmd, " > /var/swap/logs/format_debug.log 2>&1", 1, 0); |
---|
655 | } |
---|
656 | |
---|
657 | debug(80, "fdisk create cmd: %s", cmd); |
---|
658 | system(cmd); |
---|
659 | format = 2; |
---|
660 | free(cmd); cmd = NULL; |
---|
661 | } |
---|
662 | |
---|
663 | } |
---|
664 | else |
---|
665 | { |
---|
666 | 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) |
---|
667 | { |
---|
668 | printf("dev: %s\n", dev); |
---|
669 | |
---|
670 | char* part = oregex(".*([0-9]{1,2}).*", dev); |
---|
671 | printf("part: %s\n", part); |
---|
672 | |
---|
673 | char* devname = oregex(".*([a-z]{3}).*", dev); |
---|
674 | printf("devname: %s\n", devname); |
---|
675 | |
---|
676 | cmd = ostrcat("/sbin/parter.sh /dev/" , devname, 0, 0); |
---|
677 | cmd = ostrcat(cmd , " update ", 1, 0); |
---|
678 | cmd = ostrcat(cmd , part, 1, 0); |
---|
679 | cmd = ostrcat(cmd , " ", 1, 0); |
---|
680 | cmd = ostrcat(cmd , filesystem, 1, 0); |
---|
681 | free(part), part = NULL; |
---|
682 | free(devname), devname = NULL; |
---|
683 | |
---|
684 | if(large == 1) |
---|
685 | cmd = ostrcat(cmd , " large", 1, 0); |
---|
686 | |
---|
687 | if(checkbox("ATEMIO520") == 1 || checkbox("ATEMIO530") == 1 || checkbox("UFS912") == 1 || checkbox("ATEMIO7600") == 1) |
---|
688 | { |
---|
689 | if(!file_exist("/mnt/logs")) |
---|
690 | mkdir("/mnt/logs", 777); |
---|
691 | |
---|
692 | if(file_exist("/etc/.beta") && file_exist("/mnt/logs")) |
---|
693 | cmd = ostrcat(cmd, " > /mnt/logs/format_debug.log 2>&1", 1, 0); |
---|
694 | } |
---|
695 | else if(file_exist("/var/swap")) |
---|
696 | { |
---|
697 | if(!file_exist("/var/swap/logs")) |
---|
698 | mkdir("/var/swap/logs", 777); |
---|
699 | |
---|
700 | if(file_exist("/etc/.beta") && file_exist("/var/swap/logs")) |
---|
701 | cmd = ostrcat(cmd, " > /var/swap/logs/format_debug.log 2>&1", 1, 0); |
---|
702 | } |
---|
703 | |
---|
704 | debug(80, "fdisk update cmd: %s", cmd); |
---|
705 | system(cmd); |
---|
706 | format = 1; |
---|
707 | free(cmd); cmd = NULL; |
---|
708 | } |
---|
709 | } |
---|
710 | |
---|
711 | if(format > 0) |
---|
712 | { |
---|
713 | int record = 0, ext = 0, swap = 0, backup = 0; |
---|
714 | |
---|
715 | if(textbox(_("Message"), _("use medium for record"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 800, 200, 0, 0) == 1) |
---|
716 | record = 1; |
---|
717 | |
---|
718 | if(status.expertmodus > 9) |
---|
719 | { |
---|
720 | if(textbox(_("Message"), _("use medium for extension"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 800, 200, 0, 0) == 1) |
---|
721 | ext = 1; |
---|
722 | if(textbox(_("Message"), _("use medium for swap"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 800, 200, 0, 0) == 1) |
---|
723 | swap = 1; |
---|
724 | if(textbox(_("Message"), _("use medium for backup"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 800, 200, 0, 0) == 1) |
---|
725 | backup = 1; |
---|
726 | } |
---|
727 | |
---|
728 | |
---|
729 | if(ostrcmp(filesystem, "vfat") == 0) |
---|
730 | cmd = ostrcat("/sbin/cmd.sh \"mkfs.fat.gui -F 32\" /dev/" , dev, 0, 0); |
---|
731 | else if(ostrcmp(filesystem, "jfs") == 0) |
---|
732 | cmd = ostrcat("/sbin/cmd.sh \"mkfs.jfs.gui -q\" /dev/" , dev, 0, 0); |
---|
733 | else if(ostrcmp(filesystem, "ext2") == 0) |
---|
734 | cmd = ostrcat("/sbin/cmd.sh mkfs.ext2.gui /dev/" , dev, 0, 0); |
---|
735 | else if(ostrcmp(filesystem, "ext3") == 0) |
---|
736 | cmd = ostrcat("/sbin/cmd.sh \"mkfs.ext3.gui -T largefile -m0 -O dir_index\" /dev/" , dev, 0, 0); |
---|
737 | else if(ostrcmp(filesystem, "ext4") == 0) |
---|
738 | cmd = ostrcat("/sbin/cmd.sh \"mkfs.ext4.gui -T largefile -m0 -O dir_index\" /dev/" , dev, 0, 0); |
---|
739 | |
---|
740 | if(format == 2) cmd = ostrcat(cmd , "1", 1, 0); |
---|
741 | |
---|
742 | if(record == 1) |
---|
743 | cmd = ostrcat(cmd , " 1", 1, 0); |
---|
744 | else |
---|
745 | cmd = ostrcat(cmd , " 0", 1, 0); |
---|
746 | |
---|
747 | if(ext == 1) |
---|
748 | cmd = ostrcat(cmd , " 1", 1, 0); |
---|
749 | else |
---|
750 | cmd = ostrcat(cmd , " 0", 1, 0); |
---|
751 | |
---|
752 | if(swap == 1) |
---|
753 | cmd = ostrcat(cmd , " 1", 1, 0); |
---|
754 | else |
---|
755 | cmd = ostrcat(cmd , " 0", 1, 0); |
---|
756 | |
---|
757 | if(backup == 1) |
---|
758 | cmd = ostrcat(cmd , " 1", 1, 0); |
---|
759 | else |
---|
760 | cmd = ostrcat(cmd , " 0", 1, 0); |
---|
761 | |
---|
762 | if(checkbox("ATEMIO520") == 1 || checkbox("ATEMIO530") == 1 || checkbox("UFS912") == 1 || checkbox("ATEMIO7600") == 1) |
---|
763 | { |
---|
764 | if(!file_exist("/mnt/logs")) |
---|
765 | mkdir("/mnt/logs", 777); |
---|
766 | |
---|
767 | if(file_exist("/etc/.beta") && file_exist("/mnt/logs")) |
---|
768 | cmd = ostrcat(cmd, " >> /mnt/logs/format_debug.log 2>&1", 1, 0); |
---|
769 | } |
---|
770 | else if(file_exist("/var/swap")) |
---|
771 | { |
---|
772 | if(!file_exist("/var/swap/logs")) |
---|
773 | mkdir("/var/swap/logs", 777); |
---|
774 | |
---|
775 | if(file_exist("/etc/.beta") && file_exist("/var/swap/logs")) |
---|
776 | cmd = ostrcat(cmd, " >> /var/swap/logs/format_debug.log 2>&1", 1, 0); |
---|
777 | } |
---|
778 | |
---|
779 | debug(80, "format cmd: %s", cmd); |
---|
780 | rc = system(cmd); |
---|
781 | free(cmd); cmd = NULL; |
---|
782 | if(rc != 0) |
---|
783 | { |
---|
784 | textbox(_("Message"), _("ERROR\npartition could not be created"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 800, 200, 0, 0); |
---|
785 | return; |
---|
786 | } |
---|
787 | } |
---|
788 | } |
---|
789 | |
---|
790 | int hddfsck(char* dev) |
---|
791 | { |
---|
792 | char* cmd = NULL; |
---|
793 | struct hdd* node = NULL; |
---|
794 | |
---|
795 | node = gethdd(dev); |
---|
796 | if(node == NULL) return 1; |
---|
797 | if(node->filesystem == NULL) return 1; |
---|
798 | debug(80, "device=%s filesystem=%s", dev, node->filesystem); |
---|
799 | |
---|
800 | if(node->size > 524288000UL) |
---|
801 | { |
---|
802 | 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); |
---|
803 | } |
---|
804 | |
---|
805 | 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) |
---|
806 | { |
---|
807 | if(ostrcmp(node->filesystem, "vfat") == 0) |
---|
808 | cmd = ostrcat("/sbin/cmd.sh \"fsck.fat.gui -a -v\" /dev/" , dev, 0, 0); |
---|
809 | else if(ostrcmp(node->filesystem, "jfs") == 0) |
---|
810 | cmd = ostrcat("/sbin/cmd.sh \"fsck.jfs.gui -f -p\" /dev/" , dev, 0, 0); |
---|
811 | else if(ostrcmp(node->filesystem, "ext2") == 0) |
---|
812 | cmd = ostrcat("/sbin/cmd.sh \"fsck.ext2.gui -f -p\" /dev/" , dev, 0, 0); |
---|
813 | else if(ostrcmp(node->filesystem, "ext3") == 0) |
---|
814 | cmd = ostrcat("/sbin/cmd.sh \"fsck.ext3.gui -f -p\" /dev/" , dev, 0, 0); |
---|
815 | else if(ostrcmp(node->filesystem, "ext4") == 0) |
---|
816 | cmd = ostrcat("/sbin/cmd.sh \"fsck.ext4.gui -f -p\" /dev/" , dev, 0, 0); |
---|
817 | |
---|
818 | if(checkbox("ATEMIO520") == 1 || checkbox("ATEMIO530") == 1 || checkbox("UFS912") == 1 || checkbox("ATEMIO7600") == 1) |
---|
819 | { |
---|
820 | if(!file_exist("/mnt/logs")) |
---|
821 | mkdir("/mnt/logs", 777); |
---|
822 | |
---|
823 | if(file_exist("/etc/.beta") && file_exist("/mnt/logs")) |
---|
824 | cmd = ostrcat(cmd, " > /mnt/logs/fsck_debug.log 2>&1", 1, 0); |
---|
825 | } |
---|
826 | else if(file_exist("/var/swap")) |
---|
827 | { |
---|
828 | if(!file_exist("/var/swap/logs")) |
---|
829 | mkdir("/var/swap/logs", 777); |
---|
830 | |
---|
831 | if(file_exist("/etc/.beta") && file_exist("/var/swap/logs")) |
---|
832 | cmd = ostrcat(cmd, " > /var/swap/logs/fsck_debug.log 2>&1", 1, 0); |
---|
833 | } |
---|
834 | |
---|
835 | debug(80, "fsck cmd: %s", cmd); |
---|
836 | system(cmd); |
---|
837 | free(cmd); cmd = NULL; |
---|
838 | } |
---|
839 | |
---|
840 | return 0; |
---|
841 | } |
---|
842 | |
---|
843 | void screenharddisksleep() |
---|
844 | { |
---|
845 | |
---|
846 | char* sleepWert = NULL; |
---|
847 | int rcret = 0; |
---|
848 | struct skin* sleep_config = getscreen("harddisk_main"); |
---|
849 | struct skin* titletext = getscreennode(sleep_config, "titletext"); |
---|
850 | struct skin* listbox = getscreennode(sleep_config, "listbox"); |
---|
851 | struct skin* node = NULL; |
---|
852 | struct skin* tmp = NULL; |
---|
853 | |
---|
854 | /*int m_with = sleep_config->width; |
---|
855 | int m_height = sleep_config->height; |
---|
856 | int m_prozwidth = sleep_config->prozwidth; |
---|
857 | int m_prozheight= sleep_config->prozheight; |
---|
858 | |
---|
859 | sleep_config->prozheight = YES; |
---|
860 | sleep_config->prozwidth = YES; |
---|
861 | sleep_config->width = 40; |
---|
862 | sleep_config->height = 30;*/ |
---|
863 | |
---|
864 | delmarkedscreennodes(sleep_config, 1); |
---|
865 | listbox->aktpage = -1; |
---|
866 | listbox->aktline = 1; |
---|
867 | changetitle(sleep_config, _("Harddisk Sleep")); |
---|
868 | if(titletext != status.skinerr) changetext(titletext, _("Harddisk Sleep")); |
---|
869 | |
---|
870 | node = addlistbox(sleep_config, listbox, node, 1); |
---|
871 | if(node != NULL) |
---|
872 | { |
---|
873 | node->type = CHOICEBOX; |
---|
874 | changetext(node, _("Time to sleep")); changename(node, "timetosleep"); |
---|
875 | addchoicebox(node, "0", _("off")); |
---|
876 | addchoicebox(node, "300", _("5 min")); addchoicebox(node, "600", _("10 min")); |
---|
877 | addchoicebox(node, "900", _("15 min")); addchoicebox(node, "3600", _("60 min")); |
---|
878 | |
---|
879 | sleepWert = getconfig("timetosleep", NULL); |
---|
880 | if(sleepWert == NULL) |
---|
881 | setchoiceboxselection(node, "0"); |
---|
882 | else |
---|
883 | setchoiceboxselection(node, sleepWert); |
---|
884 | } |
---|
885 | |
---|
886 | drawscreen(sleep_config, 0, 0); |
---|
887 | tmp = listbox->select; |
---|
888 | |
---|
889 | while(1) |
---|
890 | { |
---|
891 | addscreenrc(sleep_config, tmp); |
---|
892 | rcret = waitrc(sleep_config, 0, 0); |
---|
893 | tmp = listbox->select; |
---|
894 | |
---|
895 | if(rcret == getrcconfigint("rcexit", NULL)) break; |
---|
896 | |
---|
897 | if(listbox->select != NULL && listbox->select->ret != NULL && rcret == getrcconfigint("rcok", NULL)) |
---|
898 | { |
---|
899 | addconfig("timetosleep", listbox->select->ret); |
---|
900 | //settimetosleep(atoi(listbox->select->ret)); |
---|
901 | break; |
---|
902 | } |
---|
903 | } |
---|
904 | |
---|
905 | /*sleep_config->width = m_with; |
---|
906 | sleep_config->height = m_height; |
---|
907 | sleep_config->prozheight = m_prozheight; |
---|
908 | sleep_config->prozwidth = m_prozwidth;*/ |
---|
909 | delmarkedscreennodes(sleep_config, 1); |
---|
910 | delownerrc(sleep_config); |
---|
911 | clearscreen(sleep_config); |
---|
912 | } |
---|
913 | |
---|
914 | //flag 0: lock |
---|
915 | //flag 1: no lock |
---|
916 | void delhdd(char* device, int flag) |
---|
917 | { |
---|
918 | if(flag == 0) m_lock(&status.hddmutex, 13); |
---|
919 | struct hdd *node = hdd, *prev = hdd; |
---|
920 | |
---|
921 | while(node != NULL) |
---|
922 | { |
---|
923 | if(ostrcmp(node->device, device) == 0) |
---|
924 | { |
---|
925 | if(node == hdd) |
---|
926 | { |
---|
927 | hdd = node->next; |
---|
928 | if(hdd != NULL) |
---|
929 | hdd->prev = NULL; |
---|
930 | } |
---|
931 | else |
---|
932 | { |
---|
933 | prev->next = node->next; |
---|
934 | if(node->next != NULL) |
---|
935 | node->next->prev = prev; |
---|
936 | } |
---|
937 | |
---|
938 | free(node->device); node->device = NULL; |
---|
939 | free(node->vendor); node->vendor = NULL; |
---|
940 | free(node->model); node->model = NULL; |
---|
941 | free(node->label); node->label = NULL; |
---|
942 | free(node->uuid); node->uuid = NULL; |
---|
943 | free(node->filesystem); node->filesystem = NULL; |
---|
944 | |
---|
945 | free(node); |
---|
946 | node = NULL; |
---|
947 | break; |
---|
948 | } |
---|
949 | |
---|
950 | prev = node; |
---|
951 | node = node->next; |
---|
952 | } |
---|
953 | if(flag == 0) m_unlock(&status.hddmutex, 13); |
---|
954 | } |
---|
955 | |
---|
956 | //flag 0: lock |
---|
957 | //flag 1: no lock |
---|
958 | 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) |
---|
959 | { |
---|
960 | if(flag == 0) m_lock(&status.hddmutex, 13); |
---|
961 | struct hdd *newnode = NULL, *prev = NULL, *node = hdd; |
---|
962 | |
---|
963 | newnode = (struct hdd*)malloc(sizeof(struct hdd)); |
---|
964 | if(newnode == NULL) |
---|
965 | { |
---|
966 | err("no memory"); |
---|
967 | if(flag == 0) m_unlock(&status.hddmutex, 13); |
---|
968 | return NULL; |
---|
969 | } |
---|
970 | memset(newnode, 0, sizeof(struct hdd)); |
---|
971 | |
---|
972 | newnode->device = device; |
---|
973 | newnode->partition = partition; |
---|
974 | newnode->size = size; |
---|
975 | newnode->removable = removable; |
---|
976 | newnode->vendor = vendor; |
---|
977 | newnode->model = model; |
---|
978 | newnode->label = label; |
---|
979 | newnode->uuid = uuid; |
---|
980 | newnode->filesystem = filesystem; |
---|
981 | newnode->read = 0; |
---|
982 | newnode->write = 0; |
---|
983 | newnode->sleeptime = timetosleep; |
---|
984 | newnode->notchanged = 0; |
---|
985 | |
---|
986 | debug(80, "add hdd %s", device); |
---|
987 | |
---|
988 | if(last == NULL) |
---|
989 | { |
---|
990 | while(node != NULL && strcoll(newnode->device, node->device) > 0) |
---|
991 | { |
---|
992 | prev = node; |
---|
993 | node = node->next; |
---|
994 | } |
---|
995 | } |
---|
996 | else |
---|
997 | { |
---|
998 | prev = last; |
---|
999 | node = last->next; |
---|
1000 | } |
---|
1001 | |
---|
1002 | if(prev == NULL) |
---|
1003 | hdd = newnode; |
---|
1004 | else |
---|
1005 | { |
---|
1006 | prev->next = newnode; |
---|
1007 | newnode->prev = prev; |
---|
1008 | } |
---|
1009 | newnode->next = node; |
---|
1010 | |
---|
1011 | //show message for new, not configured devices |
---|
1012 | //check only partition 1 |
---|
1013 | if(status.standby == 0 && newnode->partition == 1 && ostrstr(newnode->device, "1") != NULL) |
---|
1014 | { |
---|
1015 | char* tmpstr = NULL, *backup = NULL, *movie = NULL, *swapextensions = NULL, *swapfile = NULL, *checkfile = NULL; |
---|
1016 | int newdev = 1, ret = 0; |
---|
1017 | |
---|
1018 | tmpstr = ostrcat("/autofs/", newnode->device, 0, 0); |
---|
1019 | checkfile = ostrcat(tmpstr, "/.titandev", 0, 0); |
---|
1020 | if(file_exist(checkfile) == 0) |
---|
1021 | { |
---|
1022 | backup = ostrcat(tmpstr, "/backup", 0, 0); |
---|
1023 | movie = ostrcat(tmpstr, "/movie", 0, 0); |
---|
1024 | swapextensions = ostrcat(tmpstr, "/swapextensions", 0, 0); |
---|
1025 | swapfile = ostrcat(tmpstr, "/swapfile", 0, 0); |
---|
1026 | |
---|
1027 | if(file_exist(movie) == 1 || file_exist(swapextensions)== 1 || file_exist(backup) == 1 || file_exist(swapfile) == 1) |
---|
1028 | newdev = 0; |
---|
1029 | |
---|
1030 | ret = writesys(checkfile, "titan", 1); |
---|
1031 | if(ret == 0) |
---|
1032 | { |
---|
1033 | sync(); |
---|
1034 | if(newdev == 1) |
---|
1035 | 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); |
---|
1036 | } |
---|
1037 | } |
---|
1038 | free(tmpstr); tmpstr = NULL; |
---|
1039 | free(backup); backup = NULL; |
---|
1040 | free(movie); movie = NULL; |
---|
1041 | free(swapextensions); swapextensions = NULL; |
---|
1042 | free(swapfile); swapfile = NULL; |
---|
1043 | free(checkfile); checkfile = NULL; |
---|
1044 | } |
---|
1045 | |
---|
1046 | if(flag == 0) m_unlock(&status.hddmutex, 13); |
---|
1047 | return newnode; |
---|
1048 | } |
---|
1049 | |
---|
1050 | //flag = 0: mutex lock |
---|
1051 | //flag = 1: no mutex lock |
---|
1052 | void freehdd(int flag) |
---|
1053 | { |
---|
1054 | if(flag == 0) m_lock(&status.hddmutex, 13); |
---|
1055 | struct hdd *node = hdd, *prev = hdd; |
---|
1056 | |
---|
1057 | while(node != NULL) |
---|
1058 | { |
---|
1059 | prev = node; |
---|
1060 | node = node->next; |
---|
1061 | if(prev != NULL) |
---|
1062 | delhdd(prev->device, 1); |
---|
1063 | } |
---|
1064 | if(flag == 0) m_unlock(&status.hddmutex, 13); |
---|
1065 | } |
---|
1066 | |
---|
1067 | int addhddall() |
---|
1068 | { |
---|
1069 | m_lock(&status.hddmutex, 13); |
---|
1070 | FILE* fd = NULL; |
---|
1071 | FILE* fd2 = NULL; |
---|
1072 | char* fileline = NULL, *dev = NULL, *pos = NULL, *part = NULL; |
---|
1073 | char* tmpstr = NULL; |
---|
1074 | char* tmpstr2 = NULL; |
---|
1075 | int partition = 0; |
---|
1076 | int timetosleep = 0; |
---|
1077 | struct hdd *node = hdd; |
---|
1078 | struct hdd *nodedev = hdd; |
---|
1079 | int w1, w2, w3, w4, w5; |
---|
1080 | |
---|
1081 | fd = fopen("/proc/partitions", "r"); |
---|
1082 | if(fd == NULL) |
---|
1083 | { |
---|
1084 | err("open /proc/partitions"); |
---|
1085 | m_unlock(&status.hddmutex, 13); |
---|
1086 | return 1; |
---|
1087 | } |
---|
1088 | |
---|
1089 | fileline = malloc(MINMALLOC); |
---|
1090 | if(fileline == NULL) |
---|
1091 | { |
---|
1092 | err("no mem"); |
---|
1093 | m_unlock(&status.hddmutex, 13); |
---|
1094 | return 1; |
---|
1095 | } |
---|
1096 | |
---|
1097 | while(fgets(fileline, MINMALLOC, fd) != NULL) |
---|
1098 | { |
---|
1099 | pos = ostrstr(fileline, "sd"); |
---|
1100 | if(pos != NULL) |
---|
1101 | { |
---|
1102 | partition = 0; |
---|
1103 | part = NULL; |
---|
1104 | pos = string_newline(pos); |
---|
1105 | if(strlen(pos) == 3) |
---|
1106 | { |
---|
1107 | free(dev); dev = NULL; |
---|
1108 | dev = ostrcat(pos, NULL, 0, 0); |
---|
1109 | if(getconfig("timetosleep", NULL) == NULL) |
---|
1110 | timetosleep = 0; |
---|
1111 | else |
---|
1112 | timetosleep = atoi(getconfig("timetosleep", NULL)); |
---|
1113 | } |
---|
1114 | if(strlen(pos) == 4) |
---|
1115 | { |
---|
1116 | part = pos; |
---|
1117 | partition = atoi(&pos[3]); |
---|
1118 | } |
---|
1119 | tmpstr = ostrcat(tmpstr, "#", 1, 0); |
---|
1120 | tmpstr = ostrcat(tmpstr, pos, 1, 0); |
---|
1121 | //if(gethdd(pos) == NULL) |
---|
1122 | nodedev = gethdd(pos); |
---|
1123 | if(nodedev == NULL) |
---|
1124 | 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); |
---|
1125 | |
---|
1126 | //HDD SleepTimer start |
---|
1127 | if(nodedev != NULL) { |
---|
1128 | if(nodedev->sleeptime != timetosleep) { |
---|
1129 | nodedev->read = 0; |
---|
1130 | nodedev->write = 0; |
---|
1131 | nodedev->sleeptime = timetosleep; |
---|
1132 | nodedev->notchanged = 0; |
---|
1133 | } |
---|
1134 | if(strlen(pos) == 3 && timetosleep > 0) { |
---|
1135 | free(tmpstr2);tmpstr2=NULL; |
---|
1136 | tmpstr2 = ostrcat(tmpstr2, "/sys/block/", 1, 0); |
---|
1137 | tmpstr2 = ostrcat(tmpstr2, nodedev->device, 1, 0); |
---|
1138 | tmpstr2 = ostrcat(tmpstr2, "/stat", 1, 0); |
---|
1139 | fd2 = fopen(tmpstr2, "r"); |
---|
1140 | if(fd2 != NULL) { |
---|
1141 | fscanf(fd2, "%d%d%d%d%d", &w1,&w2,&w3,&w4,&w5); |
---|
1142 | fclose(fd2); |
---|
1143 | fd2 = NULL; |
---|
1144 | if((nodedev->read != w1) || (nodedev->write != w5)) { |
---|
1145 | nodedev->read = w1; |
---|
1146 | nodedev->write = w5; |
---|
1147 | nodedev->notchanged = 0; |
---|
1148 | } else { |
---|
1149 | if (nodedev->notchanged < nodedev->sleeptime) { |
---|
1150 | nodedev->notchanged = nodedev->notchanged + (status.addhddall->delay / 1000); |
---|
1151 | if (nodedev->notchanged >= nodedev->sleeptime) { |
---|
1152 | free(tmpstr2);tmpstr2=NULL; |
---|
1153 | // tmpstr2 = ostrcat(tmpstr2, "/sbin/sdparm -C stop /dev/", 1, 0); |
---|
1154 | tmpstr2 = ostrcat(tmpstr2, "/sbin//hd-idle -t ", 1, 0); |
---|
1155 | tmpstr2 = ostrcat(tmpstr2, nodedev->device, 1, 0); |
---|
1156 | system(tmpstr2); |
---|
1157 | } |
---|
1158 | } |
---|
1159 | } |
---|
1160 | } |
---|
1161 | } |
---|
1162 | } |
---|
1163 | //HDD SleepTimer end |
---|
1164 | |
---|
1165 | } |
---|
1166 | } |
---|
1167 | |
---|
1168 | //check for removed devs |
---|
1169 | while(node != NULL && tmpstr != NULL) |
---|
1170 | { |
---|
1171 | if(ostrstr(tmpstr, node->device) == NULL) |
---|
1172 | { |
---|
1173 | debug(80, "remove %s", node->device); |
---|
1174 | delhdd(node->device, 1); |
---|
1175 | } |
---|
1176 | node = node->next; |
---|
1177 | } |
---|
1178 | |
---|
1179 | if(node != NULL && tmpstr == NULL) |
---|
1180 | { |
---|
1181 | debug(80, "remove all"); |
---|
1182 | freehdd(1); |
---|
1183 | } |
---|
1184 | |
---|
1185 | free(tmpstr); |
---|
1186 | free(tmpstr2); |
---|
1187 | free(dev); |
---|
1188 | free(fileline); |
---|
1189 | fclose(fd); |
---|
1190 | m_unlock(&status.hddmutex, 13); |
---|
1191 | return 0; |
---|
1192 | } |
---|
1193 | |
---|
1194 | #endif |
---|