source: titan/titan/harddisk.h @ 29563

Last change on this file since 29563 was 29563, checked in by obi, 10 years ago

harddisk formating set ext3 to default.

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