]> CyberLeo.Net >> Repos - SourceForge/eyefi-config.git/blob - eyefi-freebsd.c
Remove unnecessary system()
[SourceForge/eyefi-config.git] / eyefi-freebsd.c
1 #include <sys/param.h>\r
2 #include <sys/ucred.h>\r
3 #include <sys/mount.h>\r
4 \r
5 #include "eyefi-config.h"\r
6 \r
7 #include <unistd.h>\r
8 #include <fcntl.h>\r
9 \r
10 int fd_flush(int fd)\r
11 {\r
12         int ret;\r
13         ret = fsync(fd);\r
14         if (ret)\r
15                 perror("fsync() failed");\r
16         return ret;\r
17 }\r
18 \r
19 \r
20 #define LINEBUFSZ 1024\r
21 char *locate_eyefi_mount(void)\r
22 {\r
23         static char eyefi_mount[PATHNAME_MAX]; // PATH_MAX anyone?\r
24 \r
25         if (strlen(eyefi_mount))\r
26                 return &eyefi_mount[0];\r
27 \r
28         int numfs;\r
29         int bufsize;\r
30         struct statfs * fsbuf;\r
31         int i;\r
32 \r
33         if ((numfs = getfsstat(NULL, 0, MNT_WAIT)) < 0) {\r
34                 debug_printf(2, "unable to obtain the number of file systems\n");\r
35                 return(NULL);\r
36         }\r
37 \r
38         bufsize = (long)numfs *sizeof(struct statfs);\r
39         if ((fsbuf = malloc(bufsize)) == NULL) {\r
40                 debug_printf(2, "unable to allocate space for filesystem list\n");\r
41                 return(NULL);\r
42         }\r
43 \r
44         if (getfsstat(fsbuf, bufsize, MNT_WAIT) < 0) {\r
45                 debug_printf(2, "unable to get the list of filesystems\n");\r
46                 return(NULL);\r
47         }\r
48 \r
49         for(i = 0; i < numfs; i++) {\r
50                 if(fsbuf[i].f_type != 5) continue; // Not MSDOS\r
51 \r
52                 char *file = eyefi_file_on(REQM, fsbuf[i].f_mntonname);\r
53                 debug_printf(2, "looking for EyeFi file here: '%s'\n", file);\r
54 \r
55                 struct stat statbuf;\r
56                 int statret;\r
57                 statret = stat(file, &statbuf);\r
58                 free(file);\r
59                 if (statret) {\r
60                         debug_printf(2, "fs at: %s is not an Eye-Fi card, skipping...\n",\r
61                                         eyefi_mount);\r
62                         continue;\r
63                 }\r
64 \r
65                 strcpy(&eyefi_mount[0], fsbuf[i].f_mntonname);\r
66                 debug_printf(1, "located EyeFi card at: '%s'\n", eyefi_mount);\r
67                 break;\r
68         }\r
69 \r
70         if (strlen(eyefi_mount))\r
71                 return &eyefi_mount[0];\r
72 \r
73         debug_printf(0, "unable to locate Eye-Fi card\n");\r
74         if (eyefi_debug_level < 5) {\r
75                 debug_printf(0, "Please check that your card is inserted and mounted\n");\r
76                 debug_printf(0, "If you still have issues, please re-run with the '-d5' option and report the output\n");\r
77         } else {\r
78                 debug_printf(0, "----------------------------------------------\n");\r
79                 debug_printf(0, "Debug information:\n");\r
80         }\r
81         exit(1);\r
82         return NULL;\r
83 }\r