X-Git-Url: http://git.openwrt.org/?a=blobdiff_plain;f=mount.c;h=a7f1862f2747919090da85c2c4fcc140ae282463;hb=dd5799c9f8cc7a01c0572c067bf907b37cdd7d04;hp=0133f172007f629791c77a578cca6d3048b64cc4;hpb=efa99c9051c6e50eca10653c85246f473fc71851;p=project%2Fmountd.git diff --git a/mount.c b/mount.c index 0133f17..a7f1862 100644 --- a/mount.c +++ b/mount.c @@ -31,7 +31,7 @@ int mount_new(char *path, char *dev); -struct list_head mounts; +static struct list_head mounts; struct mount { struct list_head list; @@ -48,26 +48,27 @@ struct mount { int fs; }; -char *fs_names[] = { +static char *fs_names[] = { "", "", - "MBR", - "EXT2", - "EXT3", - "FAT", - "HFSPLUS", + "mbr", + "ext2", + "ext3", + "fat", + "hfsplus", "", - "NTFS", + "ntfs", "", - "EXFAT", - "EXT4" + "exfat", + "ext4", + "hfsplusjournal" }; #define MAX_MOUNTED 32 #define MAX_MOUNT_NAME 32 -char mounted[MAX_MOUNTED][3][MAX_MOUNT_NAME]; -int mounted_count = 0; +static char mounted[MAX_MOUNTED][3][MAX_MOUNT_NAME]; +static int mounted_count = 0; extern char uci_path[32]; static void mount_dump_uci_state(void) @@ -100,7 +101,7 @@ static void mount_dump_uci_state(void) ucix_add_option(ctx, mountd, q->serial, "rev", q->rev); snprintf(t, 64, "size%d", atoi(&q->dev[3])); ucix_add_option(ctx, mountd, q->serial, t, q->size); - if(q->fs > MBR && q->fs <= EXT4) + if(q->fs > MBR && q->fs <= LASTFS) { snprintf(t, 64, "fs%d", atoi(&q->dev[3])); ucix_add_option(ctx, mountd, q->serial, t, fs_names[q->fs]); @@ -138,7 +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 > EXT4) + if(fs <= MBR || fs > LASTFS) return; mount = malloc(sizeof(struct mount)); INIT_LIST_HEAD(&mount->list); @@ -154,7 +155,7 @@ 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 <= EXT4)) + if((!mount->ignore) && (mount->fs > MBR) && (mount->fs <= LASTFS)) { log_printf("new mount : %s -> %s (%s)\n", name, dev, fs_names[mount->fs]); snprintf(tmp, 64, "%s%s", uci_path, name); @@ -176,7 +177,7 @@ static int mount_check_disc(char *disc) fclose(fp); return avail; } - while((fgets(tmp, 256, fp) > 0) && (avail == -1)) + while((fgets(tmp, 256, fp) != NULL) && (avail == -1)) { char *t; char tmp2[32]; @@ -229,40 +230,64 @@ int mount_new(char *path, char *dev) pid = autofs_safe_fork(); if(!pid) { + char *options, *fstype; if(mount->fs == EXFAT) { - log_printf("mount -t exfat -o rw,uid=1000,gid=1000 /dev/%s %s", mount->dev, tmp); - ret = system_printf("mount -t exfat -o rw,uid=1000,gid=1000 /dev/%s %s", mount->dev, tmp); + options = "rw,uid=1000,gid=1000"; + fstype = "exfat"; } if(mount->fs == FAT) { - log_printf("mount -t vfat -o rw,uid=1000,gid=1000 /dev/%s %s", mount->dev, tmp); - ret = system_printf("mount -t vfat -o rw,uid=1000,gid=1000 /dev/%s %s", mount->dev, tmp); + options = "rw,uid=1000,gid=1000"; + fstype = "vfat"; } if(mount->fs == EXT4) { - log_printf("mount -t ext4 -o rw,defaults /dev/%s %s", mount->dev, tmp); - ret = system_printf("mount -t ext4 -o rw,defaults /dev/%s %s", mount->dev, tmp); + options = "rw,defaults"; + fstype = "ext4"; } if(mount->fs == EXT3) { - log_printf("mount -t ext3 -o rw,defaults /dev/%s %s", mount->dev, tmp); - ret = system_printf("mount -t ext3 -o rw,defaults /dev/%s %s", mount->dev, tmp); + options = "rw,defaults"; + fstype = "ext3"; } if(mount->fs == EXT2) { - log_printf("mount -t ext2 -o rw,defaults /dev/%s %s", mount->dev, tmp); - ret = system_printf("mount -t ext2 -o rw,defaults /dev/%s %s", mount->dev, tmp); + options = "rw,defaults"; + fstype = "ext2"; } if(mount->fs == HFSPLUS) { - log_printf("mount -t hfsplus -o rw,defaults,uid=1000,gid=1000 /dev/%s %s", mount->dev, tmp); - ret = system_printf("mount -t hfsplus -o rw,defaults,uid=1000,gid=1000 /dev/%s %s", mount->dev, tmp); + options = "rw,defaults,uid=1000,gid=1000"; + fstype = "hfsplus"; + } + if(mount->fs == HFSPLUSJOURNAL) + { + options = "ro,defaults,uid=1000,gid=1000"; + fstype = "hfsplus"; } if(mount->fs == NTFS) { - log_printf("ntfs-3g /dev/%s %s -o force", mount->dev, tmp); - ret = system_printf("ntfs-3g /dev/%s %s -o force", mount->dev, tmp); + options = "force"; + fstype = "ntfs-3g"; + } + if(mount->fs > MBR && mount->fs <= LASTFS) + { + struct uci_context *ctx; + char *uci_options, *uci_fstype; + ctx = ucix_init("mountd"); + if(fs_names[mount->fs]) + { + uci_options = ucix_get_option(ctx, "mountd", fs_names[mount->fs], "options"); + uci_fstype = ucix_get_option(ctx, "mountd", fs_names[mount->fs], "fstype"); + if(uci_options) + options = uci_options; + if(uci_fstype) + fstype = uci_fstype; + log_printf("mount -t %s -o %s /dev/%s %s", fstype, options, mount->dev, tmp); + ret = system_printf("mount -t %s -o %s /dev/%s %s", fstype, options, mount->dev, tmp); + } + ucix_cleanup(ctx); } exit(WEXITSTATUS(ret)); } @@ -364,7 +389,7 @@ static char* mount_get_serial(char *dev) fp = fopen(tmp2, "r"); if(fp) { - while(fgets(tmp2, 64, fp) > 0) + while(fgets(tmp2, 64, fp) != NULL) { serial = strstr(tmp2, "Serial Number:"); if(serial) @@ -594,7 +619,7 @@ static void mount_check_mount_list(void) return; } mounted_count = 0; - while(fgets(tmp, 256, fp) > 0) + while(fgets(tmp, 256, fp) != NULL) { char *t, *t2; t = strstr(tmp, " "); @@ -638,8 +663,8 @@ static int dir_filter2(const struct dirent *a) return 0; } #define MAX_BLOCK 64 -char block[MAX_BLOCK][MAX_BLOCK]; -int blk_cnt = 0; +static char block[MAX_BLOCK][MAX_BLOCK]; +static int blk_cnt = 0; static int check_block(char *b) { @@ -668,13 +693,19 @@ static void mount_enum_drives(void) char tmp[64]; snprintf(tmp, 64, "/sys/block/%s/", namelist[n]->d_name); m = scandir(tmp, &namelist2, dir_filter2, dir_sort); - while(m--) + if(m > 0) { - strncpy(&block[blk_cnt][0], namelist2[m]->d_name, MAX_BLOCK); + while(m--) + { + strncpy(&block[blk_cnt][0], namelist2[m]->d_name, MAX_BLOCK); + blk_cnt++; + free(namelist2[m]); + } + free(namelist2); + } else { + strncpy(&block[blk_cnt][0], namelist[n]->d_name, MAX_BLOCK); blk_cnt++; - free(namelist2[m]); } - free(namelist2); } free(namelist[n]); } @@ -714,6 +745,8 @@ 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);