From: John Crispin Date: Mon, 27 Jul 2015 12:05:13 +0000 (+0200) Subject: import patches/ and cmake support X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=827e9eb7ea68786c1b840402a4b2b64473263ae3;p=project%2Fmountd.git import patches/ and cmake support Signed-off-by: John Crispin --- diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..2e712cd --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 2.6) + +PROJECT(mountd C) +ADD_DEFINITIONS(-Os -ggdb -Wall -Werror --std=gnu99 -Wmissing-declarations) + +SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "") + +ADD_EXECUTABLE(mountd main.c log.c sys.c autofs.c mount.c timer.c signal.c ucix.c led.c fs.c ucix.c) +TARGET_LINK_LIBRARIES(mountd uci ubox) + +INSTALL(TARGETS mountd + RUNTIME DESTINATION sbin +) diff --git a/Makefile b/Makefile deleted file mode 100644 index 38d849e..0000000 --- a/Makefile +++ /dev/null @@ -1,19 +0,0 @@ -PROG=mountd -OBJS=main.o lib/log.o lib/sys.o lib/autofs.o lib/mount.o lib/timer.o lib/signal.o lib/ucix.o lib/led.o lib/fs.o lib/ucix.o - -LDFLAGS?= -LDFLAGS+=-ldl -luci - -CFLAGS?= -CFLAGS+= -Wall - -all: mountd - -mountd: $(OBJS) - $(CC) $(CFLAGS) $(LDFLAGS) $^ -o $@ - -clean: - rm -f lib/*.o *.o $(PROG) - -%.o: %.c - $(CC) $(CFLAGS) -c $^ -o $@ diff --git a/autofs.c b/autofs.c index cbcada3..5f8810e 100644 --- a/autofs.c +++ b/autofs.c @@ -19,7 +19,7 @@ #include #include #include -#include +#include #include #include "include/log.h" @@ -28,6 +28,7 @@ #include "include/mount.h" #include "include/signal.h" #include "include/ucix.h" +#include "include/autofs.h" int fdin = 0; /* data coming out of the kernel */ int fdout = 0;/* data going into the kernel */ @@ -36,7 +37,7 @@ dev_t dev; time_t uci_timeout; char uci_path[32]; -void umount_autofs(void) +static void umount_autofs(void) { system_printf("umount %s 2> /dev/null", "/tmp/run/mountd/"); } @@ -113,7 +114,7 @@ static int autofs_process_request(const struct autofs_v5_packet *pkt) return 0; } -void expire_proc(void) +static void expire_proc(void) { struct autofs_packet_expire pkt; while(ioctl(fdin, AUTOFS_IOC_EXPIRE, &pkt) == 0) @@ -140,6 +141,7 @@ static int fullread(void *ptr, size_t len) static int autofs_in(union autofs_v5_packet_union *pkt) { + int res; struct pollfd fds[1]; fds[0].fd = fdout; @@ -147,15 +149,19 @@ static int autofs_in(union autofs_v5_packet_union *pkt) while(1) { - if(poll(fds, 2, 1000) == -1) + res = poll(fds, 1, -1); + + if (res == -1) { if (errno == EINTR) continue; log_printf("failed while trying to read packet from kernel\n"); return -1; } - if(fds[0].revents & POLLIN) + else if ((res > 0) && (fds[0].revents & POLLIN)) + { return fullread(pkt, sizeof(*pkt)); + } } } @@ -170,14 +176,14 @@ pid_t autofs_safe_fork(void) return pid; } -void autofs_cleanup_handler(void) +static void autofs_cleanup_handler(void) { close(fdin); close(fdout); umount_autofs(); } -void autofs_init(void) +static void autofs_init(void) { int kproto_version; char *p; diff --git a/fs.c b/fs.c index 2d6b5ba..49ad1d5 100644 --- a/fs.c +++ b/fs.c @@ -2,7 +2,6 @@ #include #include #include -#include #include #include #include @@ -11,7 +10,7 @@ typedef int (*dfunc)(int); -unsigned short +static unsigned short get_le_short(void *from) { unsigned char *p = from; @@ -19,7 +18,7 @@ get_le_short(void *from) (unsigned short)p[0]; } -unsigned int get_le_long(void *from) +static unsigned int get_le_long(void *from) { unsigned char *p = from; return ((unsigned int)(p[3]) << 24) + @@ -28,14 +27,14 @@ unsigned int get_le_long(void *from) (unsigned int)p[0]; } -unsigned short get_be_short(void *from) +static unsigned short get_be_short(void *from) { unsigned char *p = from; return ((unsigned short)(p[0]) << 8) + (unsigned short)p[1]; } -unsigned int get_be_long(void *from) +static unsigned int get_be_long(void *from) { unsigned char *p = from; return ((unsigned int)(p[0]) << 24) + @@ -44,7 +43,7 @@ unsigned int get_be_long(void *from) (unsigned int)p[3]; } -int get_buffer(int fd, unsigned char *b, int offset, int len) +static int get_buffer(int fd, unsigned char *b, int offset, int len) { if(lseek(fd, offset, SEEK_SET) != offset) return -1; @@ -54,7 +53,7 @@ int get_buffer(int fd, unsigned char *b, int offset, int len) } #define MBR_BUF_SIZE 512 -int detect_mbr(int fd) +static int detect_mbr(int fd) { int ret = NONE; unsigned char *buffer = (unsigned char*)malloc(MBR_BUF_SIZE); @@ -69,7 +68,7 @@ out: #define EFI_BUF_OFFSET 512 #define EFI_BUF_SIZE 512 -int detect_efi(int fd) +static int detect_efi(int fd) { int ret = NONE; unsigned char *buffer = (unsigned char*)malloc(EFI_BUF_SIZE); @@ -83,7 +82,7 @@ out: } #define EXT2_BUF_SIZE 1024 -int detect_ext23(int fd) +static int detect_ext23(int fd) { int ret = NONE; unsigned char *buffer = (unsigned char*)malloc(EXT2_BUF_SIZE); @@ -91,9 +90,14 @@ int detect_ext23(int fd) goto out; if(get_le_short(buffer + 56) == 0xEF53) { - if((get_le_long(buffer + 96) & 0x0008) - || (get_le_long(buffer + 92) & 0x0004)) - ret = EXT3; + if(get_le_long(buffer + 92) & 0x0004) + { + if ((get_le_long(buffer + 96) < 0x0000040) + && (get_le_long(buffer + 100) < 0x0000008)) + ret = EXT3; + else + ret = EXT4; + } else ret = EXT2; } @@ -103,7 +107,7 @@ out: } #define FAT_BUF_SIZE 512 -int detect_fat(int fd) +static int detect_fat(int fd) { int ret = NONE; unsigned char *buffer = (unsigned char*)malloc(FAT_BUF_SIZE); @@ -121,7 +125,7 @@ out: #define HFSPLUS_VOL_JOURNALED (1 << 13) #define HFSPLUS_BUF_SIZE 512 -int detect_hfsplus(int fd) +static int detect_hfsplus(int fd) { int ret = NONE; unsigned short magic; @@ -144,7 +148,7 @@ out: } #define NTFS_BUF_SIZE 512 -int detect_ntfs(int fd) +static int detect_ntfs(int fd) { int ret = NONE; unsigned char *buffer = (unsigned char*)malloc(NTFS_BUF_SIZE); @@ -158,7 +162,7 @@ out: } #define EXTENDED_BUF_SIZE 512 -int detect_extended(int fd) +static int detect_extended(int fd) { int ret = NONE; unsigned char *buffer = (unsigned char*)malloc(MBR_BUF_SIZE); diff --git a/include/fs.h b/include/fs.h index fbe9ffa..be60f2e 100644 --- a/include/fs.h +++ b/include/fs.h @@ -7,5 +7,6 @@ #define EFI 7 #define NTFS 8 #define EXTENDED 9 +#define EXT4 10 int detect_fs(char *device); diff --git a/led.c b/led.c index 6ff01f7..62554e6 100644 --- a/led.c +++ b/led.c @@ -25,6 +25,7 @@ #include "include/ucix.h" #include "include/log.h" #include "include/timer.h" +#include "include/led.h" char usbled[16]; diff --git a/log.c b/log.c index 263e1d5..ae7a7c9 100644 --- a/log.c +++ b/log.c @@ -2,6 +2,8 @@ #include #include +#include "include/log.h" + extern int daemonize; void log_start(void) diff --git a/main.c b/main.c index 2c08bde..815d58e 100644 --- a/main.c +++ b/main.c @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -13,7 +14,9 @@ int daemonize = 0; int main(int argc, char *argv[]) { - daemon(0,0); + if ((argc < 2) || strcmp(argv[1], "-f")) + daemon(0,0); + daemonize = 1; log_start(); log_printf("Starting OpenWrt (auto)mountd V1\n"); diff --git a/mount.c b/mount.c index 16c3529..1b3e8f4 100644 --- a/mount.c +++ b/mount.c @@ -16,6 +16,7 @@ #include #include #include +#include #include "include/log.h" #include "include/list.h" @@ -25,6 +26,7 @@ #include "include/autofs.h" #include "include/ucix.h" #include "include/fs.h" +#include "include/mount.h" int mount_new(char *path, char *dev); @@ -53,7 +55,10 @@ char *fs_names[] = { "EXT3", "FAT", "HFSPLUS", - "NTFS" + "", + "NTFS", + "", + "EXT4" }; #define MAX_MOUNTED 32 @@ -63,7 +68,7 @@ char mounted[MAX_MOUNTED][3][MAX_MOUNT_NAME]; int mounted_count = 0; extern char uci_path[32]; -void mount_dump_uci_state(void) +static void mount_dump_uci_state(void) { struct uci_context *ctx; struct list_head *p; @@ -93,7 +98,7 @@ 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 <= NTFS) + if(q->fs > MBR && q->fs <= EXT4) { snprintf(t, 64, "fs%d", atoi(&q->dev[3])); ucix_add_option(ctx, mountd, q->serial, t, fs_names[q->fs]); @@ -110,7 +115,7 @@ void mount_dump_uci_state(void) ucix_cleanup(ctx); } -struct mount* mount_find(char *name, char *dev) +static struct mount* mount_find(char *name, char *dev) { struct list_head *p; list_for_each(p, &mounts) @@ -126,12 +131,12 @@ struct mount* mount_find(char *name, char *dev) return 0; } -void mount_add_list(char *name, char *dev, char *serial, +static void mount_add_list(char *name, char *dev, char *serial, char *vendor, char *model, char *rev, int ignore, char *size, char *sector_size, int fs) { struct mount *mount; char tmp[64], tmp2[64]; - if(fs <= MBR || fs > NTFS) + if(fs <= MBR || fs > EXT4) return; mount = malloc(sizeof(struct mount)); INIT_LIST_HEAD(&mount->list); @@ -147,7 +152,7 @@ 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 <= NTFS)) + if((!mount->ignore) && (mount->fs > MBR) && (mount->fs <= EXT4)) { log_printf("new mount : %s -> %s (%s)\n", name, dev, fs_names[mount->fs]); snprintf(tmp, 64, "%s%s", uci_path, name); @@ -157,7 +162,7 @@ void mount_add_list(char *name, char *dev, char *serial, } } -int mount_check_disc(char *disc) +static int mount_check_disc(char *disc) { FILE *fp = fopen("/proc/mounts", "r"); char tmp[256]; @@ -187,7 +192,7 @@ int mount_check_disc(char *disc) return avail; } -int mount_wait_for_disc(char *disc) +static int mount_wait_for_disc(char *disc) { int i = 10; while(i--) @@ -226,6 +231,11 @@ int mount_new(char *path, char *dev) 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); } + 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); + } if(mount->fs == EXT3) { log_printf("mount -t ext3 -o rw,defaults /dev/%s %s", mount->dev, tmp); @@ -280,19 +290,19 @@ int mount_remove(char *path, char *dev) return 0; } -int dir_sort(const void *a, const void *b) +static int dir_sort(const struct dirent **a, const struct dirent **b) { return 0; } -int dir_filter(const struct dirent *a) +static int dir_filter(const struct dirent *a) { if(strstr(a->d_name, ":")) return 1; return 0; } -char* mount_get_serial(char *dev) +static char* mount_get_serial(char *dev) { static char tmp[64]; static char tmp2[64]; @@ -371,6 +381,7 @@ char* mount_get_serial(char *dev) } else { /* serial string id is cheap, but makes the discs anonymous */ unsigned char uniq[6]; + unsigned int *u = (unsigned int*) uniq; int l = strlen(serial); int i; static char disc_id[13]; @@ -380,14 +391,14 @@ char* mount_get_serial(char *dev) { uniq[i%6] += serial[i]; } - sprintf(disc_id, "%08X%02X%02X", *((unsigned int*)&uniq[0]), uniq[4], uniq[5]); + sprintf(disc_id, "%08X%02X%02X", *u, uniq[4], uniq[5]); //log_printf("Serial number - %s %s\n", serial, disc_id); return disc_id; } return 0; } -void mount_dev_add(char *dev) +static void mount_dev_add(char *dev) { struct mount *mount = mount_find(0, dev); if(!mount) @@ -506,7 +517,7 @@ void mount_dev_add(char *dev) } } -void mount_dev_del(char *dev) +static void mount_dev_del(char *dev) { struct mount *mount = mount_find(0, dev); char tmp[256]; @@ -551,7 +562,7 @@ char* is_mounted(char *block, char *path) return 0; } -void mount_check_mount_list(void) +static void mount_check_mount_list(void) { FILE *fp = fopen("/proc/mounts", "r"); char tmp[256]; @@ -599,8 +610,8 @@ void mount_check_mount_list(void) fclose(fp); } -/* FIXME: we need ore intelligence here */ -int dir_filter2(const struct dirent *a) +/* FIXME: we need more intelligence here */ +static int dir_filter2(const struct dirent *a) { if(/*strcmp(a->d_name, "sda") &&*/(!strncmp(a->d_name, "sd", 2))) return 1; @@ -610,7 +621,7 @@ int dir_filter2(const struct dirent *a) char block[MAX_BLOCK][MAX_BLOCK]; int blk_cnt = 0; -int check_block(char *b) +static int check_block(char *b) { int i; for(i = 0; i < blk_cnt; i++) @@ -621,7 +632,7 @@ int check_block(char *b) return 0; } -void mount_enum_drives(void) +static void mount_enum_drives(void) { struct dirent **namelist, **namelist2; int i, n = scandir("/sys/block/", &namelist, dir_filter2, dir_sort); @@ -696,7 +707,7 @@ void mount_enum_drives(void) mount_dev_add(block[i]); } -void mount_check_enum(void) +static void mount_check_enum(void) { waitpid(-1, 0, WNOHANG); mount_enum_drives(); diff --git a/signal.c b/signal.c index 1772fb4..4a4450c 100644 --- a/signal.c +++ b/signal.c @@ -5,10 +5,11 @@ #include "include/log.h" #include "include/list.h" #include "include/led.h" +#include "include/signal.h" void (*crtlc_cb)(void) = 0; -void handlerINT(int s) +static void handlerINT(int s) { log_printf("caught sig int ... cleaning up\n"); if(crtlc_cb) diff --git a/sys.c b/sys.c index 2b81a53..fdb32d9 100644 --- a/sys.c +++ b/sys.c @@ -4,6 +4,7 @@ #include #include "include/log.h" +#include "include/sys.h" int system_printf(char *fmt, ...) { diff --git a/timer.c b/timer.c index f6901f7..b3adff4 100644 --- a/timer.c +++ b/timer.c @@ -34,7 +34,7 @@ void timer_add(timercb_t timercb, int timeout) list_add(&timer->list, &timers); } -void timer_proc(int signo) +static void timer_proc(int signo) { struct list_head *p; list_for_each(p, &timers) diff --git a/uci.c b/uci.c index 4f7adb8..f5aad02 100644 --- a/uci.c +++ b/uci.c @@ -28,7 +28,7 @@ struct uci_package *p = NULL; struct uci_context* uci_init(char *config_file) { struct uci_context *ctx = uci_alloc_context(); - uci_add_history_path(ctx, "/var/state"); + uci_add_delta_path(ctx, "/var/state"); if(uci_load(ctx, config_file, &p) != UCI_OK) { log_printf("/etc/config/%s is missing or corrupt\n", config_file); diff --git a/ucix.c b/ucix.c index 66f8d77..e2a6780 100644 --- a/ucix.c +++ b/ucix.c @@ -18,7 +18,7 @@ static inline int ucix_get_ptr(struct uci_context *ctx, const char *p, const cha struct uci_context* ucix_init(const char *config_file) { struct uci_context *ctx = uci_alloc_context(); - uci_add_history_path(ctx, "/var/state"); + uci_add_delta_path(ctx, "/var/state"); if(uci_load(ctx, config_file, NULL) != UCI_OK) { printf("%s/%s is missing or corrupt\n", ctx->savedir, config_file);