int create_control_files(char *mnt) { char *control_dir = eyefi_file_on(RDIR, mnt); int ret = 0; enum eyefi_file file; ret = mkdir(control_dir, 0644); debug_printf(1, "making control directory: '%s', errno: %d\n", control_dir, errno); free(control_dir); if ((ret != 0) && (errno != EEXIST)) { perror("unable to create Eye-Fi control directory"); return errno; } for (file = REQC; file <= RSPM; file++) { ret = zero_file(file, mnt); debug_printf(2, "trying to create control file: '%s', ret: %d\n", eyefi_file_name(file), ret); if (ret) { perror("unable to create control file"); goto out; } } out: return ret; }
int zero_file(enum eyefi_file file, char *mnt) { char *fname; char *zerobuf[EYEFI_BUF_SIZE]; int fd; int ret; memset(&zerobuf[0], 0, EYEFI_BUF_SIZE); fname = eyefi_file_on(file, mnt); debug_printf(1, "creating control file: '%s'\n", fname); fd = open(fname, O_WRONLY|O_CREAT); ret = fd; if (ret < 0) goto out; ret = write(fd, &zerobuf[0], EYEFI_BUF_SIZE); if (ret < 0) goto out; ret = 0; fsync(fd); close(fd); out: free(fname); if (ret) return errno; return 0; }
static char *check_mount_line(int line_nr, char *line) { char dev[LINEBUFSZ]; char mnt[LINEBUFSZ]; char fs[LINEBUFSZ]; char opt[LINEBUFSZ]; int garb1; int garb2; int read; read = sscanf(&line[0], "%s %s %s %s %d %d", &dev[0], &mnt[0], &fs[0], &opt[0], &garb1, &garb2); if (read != 6) { debug_printf(2, "Unable to parse mount line: '%s'\n", line); return NULL; } // only look at fat filesystems: if (!fs_is(fs, "msdos") && !fs_is(fs, "vfat")) { debug_printf(4, "fs[%d] at '%s' is not fat, skipping...\n", line_nr, mnt); return NULL; } // Linux's /proc/mounts has spaces like this \040 replace_escapes(&mnt[0]); char *file = eyefi_file_on(REQM, &mnt[0]); struct stat statbuf; int statret; statret = stat(file, &statbuf); free(file); debug_printf(2, "looking for EyeFi file here: '%s' (statret: %d)\n", file, statret); if ((statret == -1) && (errno == ENOENT) && dev_has_eyefi_vol_id(&dev[0])) { debug_printf(1, "found mount '%s' that looks like Eye-Fi, " "but has no control files\n", mnt); int control_creation = create_control_files(&mnt[0]); if (control_creation != 0) return NULL; statret = stat(file, &statbuf); } if (statret) { debug_printf(3, "fs[%d] at: %s is not an Eye-Fi card, skipping...\n", line_nr, &mnt[0]); debug_printf(4, "statret: %d/%d\n", statret, errno); return NULL; } return strdup(&mnt[0]); }
static char *eyefi_file(enum eyefi_file file) { init_card(); return eyefi_file_on(file, locate_eyefi_mount()); }