From 46f43282c9be97e1efe73f52fddad9528a48488e Mon Sep 17 00:00:00 2001 From: Dave Hansen Date: Wed, 15 Sep 2010 10:16:43 -0700 Subject: [PATCH] FreeBSD support From: Wesha the Leopard To: dave@sr71.net Subject: FreeBSD patches Date: 09/13/2010 08:47:28 AM (Mon, 13 Sep 2010 10:47:28 -0500 (CDT)) 10:21 http://pastebin.com/jaa44JsG 10:22 http://pastebin.com/FtSVCbPV 10:24 http://pastebin.com/wS5D9Huw --Wesha. --- Makefile | 3 ++ eyefi-freebsd.c | 84 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 eyefi-freebsd.c diff --git a/Makefile b/Makefile index a5d1fa4..18e0c14 100644 --- a/Makefile +++ b/Makefile @@ -13,6 +13,9 @@ endif ifeq ($(PLATFORM),Darwin) OBJS += eyefi-osx.o endif +ifeq ($(PLATFORM),FreeBSD) + OBJS += eyefi-freebsd.o +endif eyefi-config: $(OBJS) $(CC) $(CFLAGS) $(OBJS) -static -o $@ diff --git a/eyefi-freebsd.c b/eyefi-freebsd.c new file mode 100644 index 0000000..0826cd9 --- /dev/null +++ b/eyefi-freebsd.c @@ -0,0 +1,84 @@ +#include +#include +#include + +#include "eyefi-config.h" + +#include +#include + +int fd_flush(int fd) +{ + int ret; + ret = fsync(fd); + if (ret) + perror("fsync() failed"); + return ret; +} + + +#define LINEBUFSZ 1024 +char *locate_eyefi_mount(void) +{ + static char eyefi_mount[PATHNAME_MAX]; // PATH_MAX anyone? + + if (strlen(eyefi_mount)) + return &eyefi_mount[0]; + + int numfs; + int bufsize; + struct statfs * fsbuf; + int i; + + if ((numfs = getfsstat(NULL, 0, MNT_WAIT)) < 0) { + debug_printf(2, "unable to obtain the number of file systems\n"); + return(NULL); + } + + bufsize = (long)numfs *sizeof(struct statfs); + if ((fsbuf = malloc(bufsize)) == NULL) { + debug_printf(2, "unable to allocate space for filesystem list\n"); + return(NULL); + } + + if (getfsstat(fsbuf, bufsize, MNT_WAIT) < 0) { + debug_printf(2, "unable to get the list of filesystems\n"); + return(NULL); + } + + for(i = 0; i < numfs; i++) { + if(fsbuf[i].f_type != 5) continue; // Not MSDOS + + char *file = eyefi_file_on(REQM, fsbuf[i].f_mntonname); + debug_printf(2, "looking for EyeFi file here: '%s'\n", file); + + struct stat statbuf; + int statret; + statret = stat(file, &statbuf); + free(file); + if (statret) { + debug_printf(2, "fs at: %s is not an Eye-Fi card, skipping...\n", + eyefi_mount); + continue; + } + + strcpy(&eyefi_mount[0], fsbuf[i].f_mntonname); + debug_printf(1, "located EyeFi card at: '%s'\n", eyefi_mount); + break; + } + + if (strlen(eyefi_mount)) + return &eyefi_mount[0]; + + debug_printf(0, "unable to locate Eye-Fi card\n"); + if (eyefi_debug_level < 5) { + debug_printf(0, "Please check that your card is inserted and mounted\n"); + debug_printf(0, "If you still have issues, please re-run with the '-d5' option and report the output\n"); + } else { + debug_printf(0, "----------------------------------------------\n"); + debug_printf(0, "Debug information:\n"); + system("cat /proc/mounts >&2"); + } + exit(1); + return NULL; +} \ No newline at end of file -- 2.42.0