source: titan/titan/harddisk.h @ 24223

Last change on this file since 24223 was 23942, checked in by obi, 11 years ago

fix textbox size

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