X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fmountd.git;a=blobdiff_plain;f=mount.c;h=f995745eb2c07b51de7ebae21812370f67caaeec;hp=a7f1862f2747919090da85c2c4fcc140ae282463;hb=7c8fea849d5a59485daea527106e29e4db0f989b;hpb=dd5799c9f8cc7a01c0572c067bf907b37cdd7d04 diff --git a/mount.c b/mount.c index a7f1862..f995745 100644 --- a/mount.c +++ b/mount.c @@ -139,8 +139,7 @@ static void mount_add_list(char *name, char *dev, char *serial, { struct mount *mount; char tmp[64], tmp2[64]; - if(fs <= MBR || fs > LASTFS) - return; + mount = malloc(sizeof(struct mount)); INIT_LIST_HEAD(&mount->list); strncpy(mount->vendor, vendor, 64); @@ -155,14 +154,14 @@ static void mount_add_list(char *name, char *dev, char *serial, mount->mounted = 0; mount->fs = fs; list_add(&mount->list, &mounts); - if((!mount->ignore) && (mount->fs > MBR) && (mount->fs <= LASTFS)) + if (!mount->ignore) { log_printf("new mount : %s -> %s (%s)\n", name, dev, fs_names[mount->fs]); snprintf(tmp, 64, "%s%s", uci_path, name); snprintf(tmp2, 64, "/tmp/run/mountd/%s", dev); symlink(tmp2, tmp); - mount_new("/tmp/run/mountd/", dev); - system_printf("ACTION=add DEVICE=%s NAME=%s /sbin/hotplug-call mount", dev, name); + if (!mount_new("/tmp/run/mountd/", dev)) + system_printf("ACTION=add DEVICE=%s NAME=%s /sbin/hotplug-call mount", dev, name); } } @@ -174,7 +173,6 @@ static int mount_check_disc(char *disc) if(!fp) { log_printf("error reading /proc/mounts"); - fclose(fp); return avail; } while((fgets(tmp, 256, fp) != NULL) && (avail == -1)) @@ -294,8 +292,10 @@ int mount_new(char *path, char *dev) pid = waitpid(pid, &ret, 0); ret = WEXITSTATUS(ret); log_printf("----------> mount ret = %d\n", ret); - if(ret && (ret != 0xff)) + if (ret && ret != 0xff) { + rmdir(tmp); return -1; + } if(mount_wait_for_disc(mount->dev) == 0) { mount->mounted = 1; @@ -452,6 +452,7 @@ static void mount_dev_add(char *dev) char sector_size[64]; FILE *fp; int offset = 3; + int fs; strcpy(name, dev); if (!strncmp(name, "mmcblk", 6)) @@ -557,7 +558,11 @@ static void mount_dev_add(char *dev) fclose(fp); } snprintf(tmp, 64, "/dev/%s", dev); - mount_add_list(node, dev, s, vendor, model, rev, ignore, size, sector_size, detect_fs(tmp)); + fs = detect_fs(tmp); + if (fs <= MBR || fs > LASTFS) { + ignore = 1; + } + mount_add_list(node, dev, s, vendor, model, rev, ignore, size, sector_size, fs); mount_dump_uci_state(); } } @@ -607,7 +612,7 @@ char* is_mounted(char *block, char *path) return 0; } -static void mount_check_mount_list(void) +static void mount_update_mount_list(void) { FILE *fp = fopen("/proc/mounts", "r"); char tmp[256]; @@ -615,13 +620,18 @@ static void mount_check_mount_list(void) if(!fp) { log_printf("error reading /proc/mounts"); - fclose(fp); return; } mounted_count = 0; while(fgets(tmp, 256, fp) != NULL) { char *t, *t2; + + if (mounted_count + 1 > MAX_MOUNTED) { + log_printf("found more than %d mounts \n", MAX_MOUNTED); + break; + } + t = strstr(tmp, " "); if(t) { @@ -647,10 +657,8 @@ static void mount_check_mount_list(void) mounted[mounted_count][0], mounted[mounted_count][1], mounted[mounted_count][2]);*/ - if(mounted_count < MAX_MOUNTED - 1) - mounted_count++; - else - log_printf("found more than %d mounts \n", MAX_MOUNTED); + + mounted_count++; } fclose(fp); } @@ -745,11 +753,13 @@ static void mount_enum_drives(void) p->next->prev = p->prev; p = p->next; log_printf("removing %s\n", q->dev); - snprintf(tmp, 64, "%s%s", "/tmp/run/mountd/", q->dev); - rmdir(tmp); - snprintf(tmp, 64, "%s%s", uci_path, q->name); - unlink(tmp); - system_printf("ACTION=remove DEVICE=%s NAME=%s /sbin/hotplug-call mount", q->dev, q->name); + if (q->mounted) { + snprintf(tmp, 64, "%s%s", "/tmp/run/mountd/", q->dev); + rmdir(tmp); + snprintf(tmp, 64, "%s%s", uci_path, q->name); + unlink(tmp); + system_printf("ACTION=remove DEVICE=%s NAME=%s /sbin/hotplug-call mount", q->dev, q->name); + } free(q); mount_dump_uci_state(); system_printf("/etc/fonstated/ReloadSamba"); @@ -769,7 +779,7 @@ static void mount_check_enum(void) void mount_init(void) { INIT_LIST_HEAD(&mounts); - timer_add(mount_check_mount_list, 2); + timer_add(mount_update_mount_list, 2); timer_add(mount_check_enum, 1); - mount_check_mount_list(); + mount_update_mount_list(); }