mount: drop duplicated rmdir() call from the mount_enum_drives()
[project/mountd.git] / mount.c
1 #include <stdio.h>
2 #include <string.h>
3 #include <stdlib.h>
4 #include <unistd.h>
5 #include <sys/stat.h>
6 #include <sys/types.h>
7 #include <fcntl.h>
8 #include <sys/ioctl.h>
9 #include <linux/hdreg.h>
10 #include <scsi/sg.h>
11 #include <dirent.h>
12 #include <sys/wait.h>
13 #include <sys/inotify.h>
14 #include <sys/stat.h>
15 #include <sys/types.h>
16 #include <glob.h>
17 #include <libgen.h>
18 #include <poll.h>
19 #include <dirent.h>
20 #include <syslog.h>
21
22 #include "include/log.h"
23 #include "include/list.h"
24 #include "include/sys.h"
25 #include "include/signal.h"
26 #include "include/timer.h"
27 #include "include/autofs.h"
28 #include "include/ucix.h"
29 #include "include/fs.h"
30 #include "include/mount.h"
31
32 int mount_new(char *path, char *dev);
33
34 static struct list_head mounts;
35
36 /**
37 * enum status - status of mount entry
38 *
39 * @STATUS_UNMOUNTED: currently not mounted
40 * @STATUS_MOUNTED: mounted & ready for usage
41 * @STATUS_EXPIRED: mount expired & *temporary* unmounted
42 * @STATUS_IGNORE: entry should be ignored and never mounted
43 */
44 enum status {
45 STATUS_UNMOUNTED = 0,
46 STATUS_MOUNTED,
47 STATUS_EXPIRED,
48 STATUS_IGNORE,
49 };
50
51 struct mount {
52 struct list_head list;
53 char name[64];
54 char dev[64];
55 char serial[64];
56 char vendor[64];
57 char model[64];
58 char rev[64];
59 enum status status;
60 char size[64];
61 char sector_size[64];
62 int fs;
63 };
64
65 static char *fs_names[] = {
66 "",
67 "",
68 "mbr",
69 "ext2",
70 "ext3",
71 "fat",
72 "hfsplus",
73 "",
74 "ntfs",
75 "",
76 "exfat",
77 "ext4",
78 "hfsplusjournal"
79 };
80
81 #define MAX_MOUNTED 32
82 #define MAX_MOUNT_NAME 32
83
84 static char mounted[MAX_MOUNTED][3][MAX_MOUNT_NAME];
85 static int mounted_count = 0;
86 extern char uci_path[32];
87
88 static void mount_dump_uci_state(void)
89 {
90 struct uci_context *ctx;
91 struct list_head *p;
92 char mountd[] = {"mountd"};
93 char type[] = {"mountd_disc"};
94 int mounted = 0;
95 unsigned long long int size = 0;
96 unlink("/var/state/mountd");
97 ctx = ucix_init("mountd");
98 uci_set_savedir(ctx, "/var/state/");
99 ucix_add_option_int(ctx, mountd, mountd, "count", list_count(&mounts));
100 list_for_each(p, &mounts)
101 {
102 struct mount *q = container_of(p, struct mount, list);
103 char t[64];
104 if(q->fs == EXTENDED)
105 continue;
106 ucix_add_section(ctx, mountd, q->serial, type);
107 strcpy(t, q->dev);
108 t[3] = '\0';
109 ucix_add_option(ctx, mountd, q->serial, "disc", t);
110 ucix_add_option(ctx, mountd, q->serial, "sector_size", q->sector_size);
111 snprintf(t, 64, "part%dmounted", atoi(&q->dev[3]));
112 ucix_add_option(ctx, mountd, q->serial, t, q->status == STATUS_MOUNTED ? "1" : "0");
113 ucix_add_option(ctx, mountd, q->serial, "vendor", q->vendor);
114 ucix_add_option(ctx, mountd, q->serial, "model", q->model);
115 ucix_add_option(ctx, mountd, q->serial, "rev", q->rev);
116 snprintf(t, 64, "size%d", atoi(&q->dev[3]));
117 ucix_add_option(ctx, mountd, q->serial, t, q->size);
118 if(q->fs > MBR && q->fs <= LASTFS)
119 {
120 snprintf(t, 64, "fs%d", atoi(&q->dev[3]));
121 ucix_add_option(ctx, mountd, q->serial, t, fs_names[q->fs]);
122 }
123 if (q->status == STATUS_MOUNTED)
124 mounted++;
125 if ((q->status != STATUS_IGNORE) && q->size && q->sector_size)
126 size = size + (((unsigned long long int)atoi(q->size)) * ((unsigned long long int)atoi(q->sector_size)));
127 }
128 ucix_add_option_int(ctx, mountd, mountd, "mounted", mounted);
129 ucix_add_option_int(ctx, mountd, mountd, "total", size);
130 system_printf("echo -n %llu > /tmp/run/mountd_size", size);
131 ucix_save_state(ctx, "mountd");
132 ucix_cleanup(ctx);
133 }
134
135 static struct mount* mount_find(char *name, char *dev)
136 {
137 struct list_head *p;
138 list_for_each(p, &mounts)
139 {
140 struct mount *q = container_of(p, struct mount, list);
141 if(name)
142 if(!strcmp(q->name, name))
143 return q;
144 if(dev)
145 if(!strcmp(q->dev, dev))
146 return q;
147 }
148 return 0;
149 }
150
151 static void mount_add_list(char *name, char *dev, char *serial,
152 char *vendor, char *model, char *rev, int ignore, char *size, char *sector_size, int fs)
153 {
154 struct mount *mount;
155 char tmp[64], tmp2[64];
156
157 mount = malloc(sizeof(struct mount));
158 INIT_LIST_HEAD(&mount->list);
159 strncpy(mount->vendor, vendor, 64);
160 strncpy(mount->model, model, 64);
161 strncpy(mount->rev, rev, 64);
162 strncpy(mount->name, name, 64);
163 strncpy(mount->dev, dev, 64);
164 strncpy(mount->serial, serial, 64);
165 strncpy(mount->size, size, 64);
166 strncpy(mount->sector_size, sector_size, 64);
167 mount->status = STATUS_UNMOUNTED;
168 mount->fs = fs;
169 list_add(&mount->list, &mounts);
170
171 if (ignore) {
172 mount->status = STATUS_IGNORE;
173 } else {
174 log_printf("new mount : %s -> %s (%s)\n", name, dev, fs_names[mount->fs]);
175 snprintf(tmp, 64, "%s%s", uci_path, name);
176 snprintf(tmp2, 64, "/tmp/run/mountd/%s", dev);
177 symlink(tmp2, tmp);
178 if (!mount_new("/tmp/run/mountd/", dev))
179 system_printf("ACTION=add DEVICE=%s NAME=%s /sbin/hotplug-call mount", dev, name);
180 }
181 }
182
183 static int mount_check_disc(char *disc)
184 {
185 FILE *fp = fopen("/proc/mounts", "r");
186 char tmp[256];
187 int avail = -1;
188 if(!fp)
189 {
190 log_printf("error reading /proc/mounts");
191 return avail;
192 }
193 while((fgets(tmp, 256, fp) != NULL) && (avail == -1))
194 {
195 char *t;
196 char tmp2[32];
197 t = strstr(tmp, " ");
198 if(t)
199 {
200 int l;
201 *t = '\0';
202 l = snprintf(tmp2, 31, "/dev/%s", disc);
203
204 if(!strncmp(tmp, tmp2, l))
205 avail = 0;
206 }
207 }
208 fclose(fp);
209 return avail;
210 }
211
212 static int mount_wait_for_disc(char *disc)
213 {
214 int i = 10;
215 while(i--)
216 {
217 int ret = mount_check_disc(disc);
218 if(!ret)
219 return ret;
220 poll(0, 0, 100);
221 }
222 return -1;
223 }
224
225 int mount_new(char *path, char *dev)
226 {
227 struct mount *mount;
228 char tmp[256];
229 int ret = 1;
230 pid_t pid;
231 mount = mount_find(0, dev);
232 if(!mount)
233 {
234 log_printf("request for invalid path %s%s\n", path, dev);
235 return -1;
236 }
237 if (mount->status == STATUS_IGNORE || mount->status == STATUS_MOUNTED || mount->fs == EXTENDED)
238 return -1;
239 snprintf(tmp, 256, "%s%s", path, mount->dev);
240 log_printf("mounting %s\n", tmp);
241 mkdir(tmp, 777);
242
243 pid = autofs_safe_fork();
244 if(!pid)
245 {
246 char *options, *fstype;
247 if(mount->fs == EXFAT)
248 {
249 options = "rw,uid=1000,gid=1000";
250 fstype = "exfat";
251 }
252 if(mount->fs == FAT)
253 {
254 options = "rw,uid=1000,gid=1000";
255 fstype = "vfat";
256 }
257 if(mount->fs == EXT4)
258 {
259 options = "rw,defaults";
260 fstype = "ext4";
261 }
262 if(mount->fs == EXT3)
263 {
264 options = "rw,defaults";
265 fstype = "ext3";
266 }
267 if(mount->fs == EXT2)
268 {
269 options = "rw,defaults";
270 fstype = "ext2";
271 }
272 if(mount->fs == HFSPLUS)
273 {
274 options = "rw,defaults,uid=1000,gid=1000";
275 fstype = "hfsplus";
276 }
277 if(mount->fs == HFSPLUSJOURNAL)
278 {
279 options = "ro,defaults,uid=1000,gid=1000";
280 fstype = "hfsplus";
281 }
282 if(mount->fs == NTFS)
283 {
284 options = "force";
285 fstype = "ntfs-3g";
286 }
287 if(mount->fs > MBR && mount->fs <= LASTFS)
288 {
289 struct uci_context *ctx;
290 char *uci_options, *uci_fstype;
291 ctx = ucix_init("mountd");
292 if(fs_names[mount->fs])
293 {
294 uci_options = ucix_get_option(ctx, "mountd", fs_names[mount->fs], "options");
295 uci_fstype = ucix_get_option(ctx, "mountd", fs_names[mount->fs], "fstype");
296 if(uci_options)
297 options = uci_options;
298 if(uci_fstype)
299 fstype = uci_fstype;
300 log_printf("mount -t %s -o %s /dev/%s %s", fstype, options, mount->dev, tmp);
301 ret = system_printf("mount -t %s -o %s /dev/%s %s", fstype, options, mount->dev, tmp);
302 }
303 ucix_cleanup(ctx);
304 }
305 exit(WEXITSTATUS(ret));
306 }
307 pid = waitpid(pid, &ret, 0);
308 ret = WEXITSTATUS(ret);
309 log_printf("----------> mount ret = %d\n", ret);
310 if (ret && ret != 0xff) {
311 rmdir(tmp);
312 return -1;
313 }
314 if(mount_wait_for_disc(mount->dev) == 0)
315 {
316 mount->status = STATUS_MOUNTED;
317 mount_dump_uci_state();
318 } else return -1;
319 return 0;
320 }
321
322 int mount_remove(char *path, char *dev)
323 {
324 struct mount *mount;
325 char tmp[256];
326 int ret;
327 snprintf(tmp, 256, "%s%s", path, dev);
328 log_printf("device %s has expired... unmounting %s\n", dev, tmp);
329 ret = system_printf("/bin/umount %s", tmp);
330 if(ret != 0)
331 return 0;
332 rmdir(tmp);
333 mount = mount_find(0, dev);
334 if(mount)
335 mount->status = STATUS_EXPIRED;
336 log_printf("finished unmounting\n");
337 mount_dump_uci_state();
338 return 0;
339 }
340
341 static int dir_sort(const struct dirent **a, const struct dirent **b)
342 {
343 return 0;
344 }
345
346 static int dir_filter(const struct dirent *a)
347 {
348 if(strstr(a->d_name, ":"))
349 return 1;
350 return 0;
351 }
352
353 static char* mount_get_serial(char *dev)
354 {
355 static char tmp[64];
356 static char tmp2[64];
357 int disc;
358 static struct hd_driveid hd;
359 int i;
360 static char *serial;
361 static char disc_id[13];
362 snprintf(tmp, 64, "/dev/%s", dev);
363 disc = open(tmp, O_RDONLY);
364 if(!disc)
365 {
366 log_printf("Trying to open unknown disc\n");
367 return 0;
368 }
369 i = ioctl(disc, HDIO_GET_IDENTITY, &hd);
370 close(disc);
371 if(!i)
372 serial = (char*)hd.serial_no;
373 /* if we failed, it probably a usb storage device */
374 /* there must be a better way for this */
375 if(i)
376 {
377 struct dirent **namelist;
378 int n = scandir("/sys/bus/scsi/devices/", &namelist, dir_filter, dir_sort);
379 if(n > 0)
380 {
381 while(n--)
382 {
383 char *t = strstr(namelist[n]->d_name, ":");
384 if(t)
385 {
386 int id;
387 struct stat buf;
388 char tmp3[64];
389 int ret;
390 *t = 0;
391 id = atoi(namelist[n]->d_name);
392 *t = ':';
393 sprintf(tmp3, "/sys/bus/scsi/devices/%s/block:%s/", namelist[n]->d_name, dev);
394 ret = stat(tmp3, &buf);
395 if(ret)
396 {
397 sprintf(tmp3, "/sys/bus/scsi/devices/%s/block/%s/", namelist[n]->d_name, dev);
398 ret = stat(tmp3, &buf);
399 }
400 if(!ret)
401 {
402 FILE *fp;
403 snprintf(tmp2, 64, "/proc/scsi/usb-storage/%d", id);
404 fp = fopen(tmp2, "r");
405 if(fp)
406 {
407 while(fgets(tmp2, 64, fp) != NULL)
408 {
409 serial = strstr(tmp2, "Serial Number:");
410 if(serial)
411 {
412 serial += strlen("Serial Number: ");
413 serial[strlen(serial) - 1] = '\0';
414 i = 0;
415 break;
416 }
417 }
418 fclose(fp);
419 }
420 }
421 }
422 free(namelist[n]);
423 }
424 free(namelist);
425 }
426 }
427 if(i)
428 {
429 log_printf("could not find a serial number for the device %s\n", dev);
430 } else {
431 /* serial string id is cheap, but makes the discs anonymous */
432 unsigned char uniq[6];
433 unsigned int *u = (unsigned int*) uniq;
434 int l = strlen(serial);
435 int i;
436 memset(disc_id, 0, 13);
437 memset(uniq, 0, 6);
438 for(i = 0; i < l; i++)
439 {
440 uniq[i%6] += serial[i];
441 }
442 sprintf(disc_id, "%08X%02X%02X", *u, uniq[4], uniq[5]);
443 //log_printf("Serial number - %s %s\n", serial, disc_id);
444 return disc_id;
445 }
446 sprintf(disc_id, "000000000000");
447 return disc_id;
448 }
449
450 static void mount_dev_add(char *dev)
451 {
452 struct mount *mount = mount_find(0, dev);
453 if(!mount)
454 {
455 char node[64];
456 char name[64];
457 int ignore = 0;
458 char *s;
459 char tmp[64];
460 char tmp2[64];
461 char *p;
462 struct uci_context *ctx;
463 char vendor[64];
464 char model[64];
465 char rev[64];
466 char size[64];
467 char sector_size[64];
468 FILE *fp;
469 int offset = 3;
470 int fs;
471
472 strcpy(name, dev);
473 if (!strncmp(name, "mmcblk", 6))
474 offset = 7;
475 name[offset] = '\0';
476 s = mount_get_serial(name);
477 if(!s) {
478 return;
479 }
480 if (!strncmp(name, "mmcblk", 6)) {
481 snprintf(tmp, 64, "part%s", &dev[8]);
482 snprintf(node, 64, "SD-P%s", &dev[8]);
483
484 } else {
485 snprintf(tmp, 64, "part%s", &dev[3]);
486 snprintf(node, 64, "USB-%s", &dev[2]);
487 }
488 if(node[4] >= 'a' && node[4] <= 'z')
489 {
490 node[4] -= 'a';
491 node[4] += 'A';
492 }
493 ctx = ucix_init("mountd");
494 p = ucix_get_option(ctx, "mountd", s, tmp);
495 ucix_cleanup(ctx);
496 if(p)
497 {
498 if(strlen(p) == 1)
499 {
500 if(*p == '0')
501 ignore = 1;
502 } else {
503 snprintf(node, 64, "%s", p);
504 }
505 }
506 strcpy(name, dev);
507 name[3] = '\0';
508 snprintf(tmp, 64, "/sys/class/block/%s/device/model", name);
509 fp = fopen(tmp, "r");
510 if(!fp)
511 {
512 snprintf(tmp, 64, "/sys/block/%s/device/model", name);
513 fp = fopen(tmp, "r");
514 }
515 if(!fp)
516 snprintf(model, 64, "unknown");
517 else {
518 fgets(model, 64, fp);
519 model[strlen(model) - 1] = '\0';;
520 fclose(fp);
521 }
522 snprintf(tmp, 64, "/sys/class/block/%s/device/vendor", name);
523 fp = fopen(tmp, "r");
524 if(!fp)
525 {
526 snprintf(tmp, 64, "/sys/block/%s/device/vendor", name);
527 fp = fopen(tmp, "r");
528 }
529 if(!fp)
530 snprintf(vendor, 64, "unknown");
531 else {
532 fgets(vendor, 64, fp);
533 vendor[strlen(vendor) - 1] = '\0';
534 fclose(fp);
535 }
536 snprintf(tmp, 64, "/sys/class/block/%s/device/rev", name);
537 fp = fopen(tmp, "r");
538 if(!fp)
539 {
540 snprintf(tmp, 64, "/sys/block/%s/device/rev", name);
541 fp = fopen(tmp, "r");
542 }
543 if(!fp)
544 snprintf(rev, 64, "unknown");
545 else {
546 fgets(rev, 64, fp);
547 rev[strlen(rev) - 1] = '\0';
548 fclose(fp);
549 }
550 snprintf(tmp, 64, "/sys/class/block/%s/size", dev);
551 fp = fopen(tmp, "r");
552 if(!fp)
553 {
554 snprintf(tmp, 64, "/sys/block/%s/%s/size", name, dev);
555 fp = fopen(tmp, "r");
556 }
557 if(!fp)
558 snprintf(size, 64, "unknown");
559 else {
560 fgets(size, 64, fp);
561 size[strlen(size) - 1] = '\0';
562 fclose(fp);
563 }
564 strcpy(tmp2, dev);
565 tmp2[3] = '\0';
566 snprintf(tmp, 64, "/sys/block/%s/queue/hw_sector_size", tmp2);
567 fp = fopen(tmp, "r");
568 if(!fp)
569 snprintf(sector_size, 64, "unknown");
570 else {
571 fgets(sector_size, 64, fp);
572 sector_size[strlen(sector_size) - 1] = '\0';
573 fclose(fp);
574 }
575 snprintf(tmp, 64, "/dev/%s", dev);
576 fs = detect_fs(tmp);
577 if (fs <= MBR || fs > LASTFS) {
578 ignore = 1;
579 }
580 mount_add_list(node, dev, s, vendor, model, rev, ignore, size, sector_size, fs);
581 mount_dump_uci_state();
582 }
583 }
584
585 static void mount_dev_del(struct mount *mount)
586 {
587 char tmp[256];
588
589 if (mount->status == STATUS_MOUNTED) {
590 snprintf(tmp, 256, "%s%s", "/tmp/run/mountd/", mount->dev);
591 log_printf("device %s has disappeared ... unmounting %s\n", mount->dev, tmp);
592 system_printf("/bin/umount %s", tmp);
593 rmdir(tmp);
594 mount_dump_uci_state();
595 }
596 }
597
598 void mount_dump_list(void)
599 {
600 struct list_head *p;
601 list_for_each(p, &mounts)
602 {
603 struct mount *q = container_of(p, struct mount, list);
604 log_printf("* %s %s %d\n", q->name, q->dev, q->status == STATUS_MOUNTED);
605 }
606 }
607
608 char* is_mounted(char *block, char *path)
609 {
610 int i;
611 for(i = 0; i < mounted_count; i++)
612 {
613 if(block)
614 if(!strncmp(&mounted[i][0][0], block, strlen(&mounted[i][0][0])))
615 return &mounted[i][0][0];
616 if(path)
617 if(!strncmp(&mounted[i][1][1], &path[1], strlen(&mounted[i][1][0])))
618 return &mounted[i][0][0];
619 }
620 return 0;
621 }
622
623 static void mount_update_mount_list(void)
624 {
625 FILE *fp = fopen("/proc/mounts", "r");
626 char tmp[256];
627
628 if(!fp)
629 {
630 log_printf("error reading /proc/mounts");
631 return;
632 }
633 mounted_count = 0;
634 while(fgets(tmp, 256, fp) != NULL)
635 {
636 char *t, *t2;
637
638 if (mounted_count + 1 > MAX_MOUNTED) {
639 log_printf("found more than %d mounts \n", MAX_MOUNTED);
640 break;
641 }
642
643 t = strstr(tmp, " ");
644 if(t)
645 {
646 *t = '\0';
647 t++;
648 } else t = tmp;
649 strncpy(&mounted[mounted_count][0][0], tmp, MAX_MOUNT_NAME);
650 t2 = strstr(t, " ");
651 if(t2)
652 {
653 *t2 = '\0';
654 t2++;
655 } else t2 = t;
656 strncpy(&mounted[mounted_count][1][0], t, MAX_MOUNT_NAME);
657 t = strstr(t2, " ");
658 if(t)
659 {
660 *t = '\0';
661 t++;
662 } else t = tmp;
663 strncpy(&mounted[mounted_count][2][0], t2, MAX_MOUNT_NAME);
664 /* printf("%s %s %s\n",
665 mounted[mounted_count][0],
666 mounted[mounted_count][1],
667 mounted[mounted_count][2]);*/
668
669 mounted_count++;
670 }
671 fclose(fp);
672 }
673
674 /* FIXME: we need more intelligence here */
675 static int dir_filter2(const struct dirent *a)
676 {
677 if(!strncmp(a->d_name, "mmcblk", 6) || !strncmp(a->d_name, "sd", 2))
678 return 1;
679 return 0;
680 }
681 #define MAX_BLOCK 64
682 static char block[MAX_BLOCK][MAX_BLOCK];
683 static int blk_cnt = 0;
684
685 static int check_block(char *b)
686 {
687 int i;
688 for(i = 0; i < blk_cnt; i++)
689 {
690 if(!strcmp(block[i], b))
691 return 1;
692 }
693 return 0;
694 }
695
696 static void mount_enum_drives(void)
697 {
698 struct dirent **namelist, **namelist2;
699 int i, n = scandir("/sys/block/", &namelist, dir_filter2, dir_sort);
700 struct list_head *p;
701 blk_cnt = 0;
702 if(n > 0)
703 {
704 while(n--)
705 {
706 if(blk_cnt < MAX_BLOCK)
707 {
708 int m;
709 char tmp[64];
710 snprintf(tmp, 64, "/sys/block/%s/", namelist[n]->d_name);
711 m = scandir(tmp, &namelist2, dir_filter2, dir_sort);
712 if(m > 0)
713 {
714 while(m--)
715 {
716 strncpy(&block[blk_cnt][0], namelist2[m]->d_name, MAX_BLOCK);
717 blk_cnt++;
718 free(namelist2[m]);
719 }
720 free(namelist2);
721 } else {
722 strncpy(&block[blk_cnt][0], namelist[n]->d_name, MAX_BLOCK);
723 blk_cnt++;
724 }
725 }
726 free(namelist[n]);
727 }
728 free(namelist);
729 }
730 p = mounts.next;
731 while(p != &mounts)
732 {
733 struct mount *q = container_of(p, struct mount, list);
734 char tmp[64];
735 struct uci_context *ctx;
736 int del = 0;
737 char *t;
738 snprintf(tmp, 64, "part%s", &q->dev[3]);
739 ctx = ucix_init("mountd");
740 t = ucix_get_option(ctx, "mountd", q->serial, tmp);
741 ucix_cleanup(ctx);
742 if (t && q->status != STATUS_MOUNTED)
743 {
744 if(!strcmp(t, "0"))
745 {
746 if (q->status != STATUS_IGNORE)
747 del = 1;
748 } else if(!strcmp(t, "1"))
749 {
750 if(strncmp(q->name, "Disc-", 5))
751 del = 1;
752 } else if(strcmp(q->name, t))
753 {
754 del = 1;
755 }
756 }
757 if(!check_block(q->dev)||del)
758 {
759 mount_dev_del(q);
760 p->prev->next = p->next;
761 p->next->prev = p->prev;
762 p = p->next;
763 if (q->status == STATUS_MOUNTED || q->status == STATUS_EXPIRED) {
764 snprintf(tmp, 64, "%s%s", uci_path, q->name);
765 log_printf("unlinking %s\n", tmp);
766 unlink(tmp);
767 system_printf("ACTION=remove DEVICE=%s NAME=%s /sbin/hotplug-call mount", q->dev, q->name);
768 }
769 free(q);
770 mount_dump_uci_state();
771 system_printf("/etc/fonstated/ReloadSamba");
772 } else p = p->next;
773 }
774
775 for(i = 0; i < blk_cnt; i++)
776 mount_dev_add(block[i]);
777 }
778
779 static void mount_check_enum(void)
780 {
781 waitpid(-1, 0, WNOHANG);
782 mount_enum_drives();
783 }
784
785 void mount_init(void)
786 {
787 INIT_LIST_HEAD(&mounts);
788 timer_add(mount_update_mount_list, 2);
789 timer_add(mount_check_enum, 1);
790 mount_update_mount_list();
791 }