1 #include "eyefi-config.h"
6 static int atoo(char o)
8 if ((o >= '0') && (o <= '7'))
13 static int octal_esc_to_chr(char *input)
17 int len = strlen(input);
19 //intf("%s('%s')\n", __func__, input);
25 for (i=1; i < len ; i++) {
28 int tmp = atoo(input[i]);
29 //intf("tmp: %d\n", tmp);
38 static char *replace_escapes(char *str)
42 debug_printf(4, "%s(%s)\n", __func__, str);
43 for (i=0; i < strlen(str); i++) {
44 int esc = octal_esc_to_chr(&str[i]);
50 str[output++] = str[i];
53 debug_printf(4, "replaced escapes in: '%s' bytes of output: %d\n", str, output);
60 ret = posix_fadvise(fd, 0, 0, POSIX_FADV_DONTNEED);
62 perror("posix_fadvise() failed");
67 #define LINEBUFSZ 1024
68 char *locate_eyefi_mount(void)
70 static char eyefi_mount[PATHNAME_MAX]; // PATH_MAX anyone?
72 FILE *mounts = fopen("/proc/mounts", "r");
81 if (strlen(eyefi_mount))
82 return &eyefi_mount[0];
84 while (fgets(&line[0], 1023, mounts)) {
86 read = sscanf(&line[0], "%s %s %s %s %d %d",
87 &dev[0], &mnt[0], &fs[0], &opt[0],
89 // only look at fat filesystems:
90 if (strcmp(fs, "msdos") && strcmp(fs, "vfat")) {
91 debug_printf(2, "fs at '%s' is not fat, skipping...\n", mnt);
94 // Linux's /proc/mounts has spaces like this \040
95 replace_escapes(&mnt[0]);
96 char *file = eyefi_file_on(REQM, &mnt[0]);
97 debug_printf(2, "looking for EyeFi file here: '%s'\n", file);
101 statret = stat(file, &statbuf);
104 debug_printf(2, "fs at: %s is not an Eye-Fi card, skipping...\n",
108 strcpy(&eyefi_mount[0], &mnt[0]);
109 debug_printf(1, "located EyeFi card at: '%s'\n", eyefi_mount);
114 if (strlen(eyefi_mount))
115 return &eyefi_mount[0];
117 debug_printf(0, "unable to locate Eye-Fi card\n");
118 if (eyefi_debug_level < 5) {
119 debug_printf(0, "Please check that your card is inserted and mounted\n");
120 debug_printf(0, "If you still have issues, please re-run with the '-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");