1 #include "eyefi-config.h"
3 #define O_DIRECT 00040000 /* direct disk access hint */
5 static int atoo(char o)
7 if ((o >= '0') && (o <= '7'))
12 static int octal_esc_to_chr(char *input)
16 int len = strlen(input);
18 //intf("%s('%s')\n", __func__, input);
24 for (i=1; i < len ; i++) {
27 int tmp = atoo(input[i]);
28 //intf("tmp: %d\n", tmp);
37 static char *replace_escapes(char *str)
41 debug_printf(4, "%s(%s)\n", __func__, str);
42 for (i=0; i < strlen(str); i++) {
43 int esc = octal_esc_to_chr(&str[i]);
49 str[output++] = str[i];
52 debug_printf(4, "replaced escapes in: '%s' bytes of output: %d\n", str, output);
56 int fd_dont_cache(int fd)
58 return fcntl(fd, F_SETFL, O_DIRECT);
62 #define LINEBUFSZ 1024
63 char *locate_eyefi_mount(void)
65 static char eyefi_mount[PATHNAME_MAX]; // PATH_MAX anyone?
67 FILE *mounts = fopen("/proc/mounts", "r");
76 if (strlen(eyefi_mount))
77 return &eyefi_mount[0];
79 while (fgets(&line[0], 1023, mounts)) {
81 read = sscanf(&line[0], "%s %s %s %s %d %d",
82 &dev[0], &mnt[0], &fs[0], &opt[0],
84 // only look at fat filesystems:
85 if (strcmp(fs, "msdos") && strcmp(fs, "vfat")) {
86 debug_printf(2, "fs at '%s' is not fat, skipping...\n", mnt);
89 // Linux's /proc/mounts has spaces like this \040
90 replace_escapes(&mnt[0]);
91 char *file = eyefi_file_on(REQM, &mnt[0]);
92 debug_printf(2, "looking for EyeFi file here: '%s'\n", file);
96 statret = stat(file, &statbuf);
99 debug_printf(2, "fs at: %s is not an Eye-Fi card, skipping...\n",
103 strcpy(&eyefi_mount[0], &mnt[0]);
104 debug_printf(1, "located EyeFi card at: '%s'\n", eyefi_mount);
109 if (strlen(eyefi_mount))
110 return &eyefi_mount[0];
112 debug_printf(0, "unable to locate Eye-Fi card\n");
113 if (eyefi_debug_level < 5)
114 debug_printf(0, "please run with '-d5' option and report the output\n");
116 debug_printf(0, "----------------------------------------------\n");
117 debug_printf(0, "Debug information:\n");
118 system("cat /proc/mounts >&2");