1 #include "eyefi-config.h"
3 // Geez there has to be a better way to do this
6 #define O_DIRECT 00040000 /* direct disk access hint */
8 #define O_DIRECT 0200000 /* direct disk access hint - currently ignored */
11 static int atoo(char o)
13 if ((o >= '0') && (o <= '7'))
18 static int octal_esc_to_chr(char *input)
22 int len = strlen(input);
24 //intf("%s('%s')\n", __func__, input);
30 for (i=1; i < len ; i++) {
33 int tmp = atoo(input[i]);
34 //intf("tmp: %d\n", tmp);
43 static char *replace_escapes(char *str)
47 debug_printf(4, "%s(%s)\n", __func__, str);
48 for (i=0; i < strlen(str); i++) {
49 int esc = octal_esc_to_chr(&str[i]);
55 str[output++] = str[i];
58 debug_printf(4, "replaced escapes in: '%s' bytes of output: %d\n", str, output);
62 int fd_dont_cache(int fd)
64 return fcntl(fd, F_SETFL, O_DIRECT);
68 #define LINEBUFSZ 1024
69 char *locate_eyefi_mount(void)
71 static char eyefi_mount[PATHNAME_MAX]; // PATH_MAX anyone?
73 FILE *mounts = fopen("/proc/mounts", "r");
82 if (strlen(eyefi_mount))
83 return &eyefi_mount[0];
85 while (fgets(&line[0], 1023, mounts)) {
87 read = sscanf(&line[0], "%s %s %s %s %d %d",
88 &dev[0], &mnt[0], &fs[0], &opt[0],
90 // only look at fat filesystems:
91 if (strcmp(fs, "msdos") && strcmp(fs, "vfat")) {
92 debug_printf(2, "fs at '%s' is not fat, skipping...\n", mnt);
95 // Linux's /proc/mounts has spaces like this \040
96 replace_escapes(&mnt[0]);
97 char *file = eyefi_file_on(REQM, &mnt[0]);
98 debug_printf(2, "looking for EyeFi file here: '%s'\n", file);
102 statret = stat(file, &statbuf);
105 debug_printf(2, "fs at: %s is not an Eye-Fi card, skipping...\n",
109 strcpy(&eyefi_mount[0], &mnt[0]);
110 debug_printf(1, "located EyeFi card at: '%s'\n", eyefi_mount);
115 if (strlen(eyefi_mount))
116 return &eyefi_mount[0];
118 debug_printf(0, "unable to locate Eye-Fi card\n");
119 if (eyefi_debug_level < 5)
120 debug_printf(0, "please run with '-d5' option and report the output\n");
122 debug_printf(0, "----------------------------------------------\n");
123 debug_printf(0, "Debug information:\n");
124 system("cat /proc/mounts >&2");