1 --- server/gam_fs.c.orig 2007-07-04 09:36:49.000000000 -0400 2 +++ server/gam_fs.c 2007-08-10 15:05:41.000000000 -0400 3 @@ -7,6 +7,11 @@ 4 #include <string.h> 5 #include <errno.h> 6 #include <glib.h> 7 +#ifdef __FreeBSD__ 8 +#include <sys/param.h> 9 +#include <sys/ucred.h> 10 +#include <sys/mount.h> 11 +#endif 12 #include "gam_error.h" 13 #include "gam_fs.h" 14 15 @@ -21,9 +26,13 @@ typedef struct _gam_fs_properties { 16 typedef struct _gam_fs { 17 char *path; 18 char *fsname; 19 + guint64 flags; 20 } gam_fs; 21 22 static gboolean initialized = FALSE; 23 +#ifdef __FreeBSD__ 24 +static gboolean initializing = FALSE; 25 +#endif 26 static GList *filesystems = NULL; 27 static GList *fs_props = NULL; 28 static struct stat mtab_sbuf; 29 @@ -110,6 +119,7 @@ gam_fs_filesystem_sort_cb (gconstpointer 30 return strlen(fsb->path) - strlen (fsa->path); 31 } 32 33 +#ifdef __linux__ 34 static void 35 gam_fs_scan_mtab (void) 36 { 37 @@ -165,10 +175,41 @@ gam_fs_scan_mtab (void) 38 gam_fs_free_filesystems (); 39 filesystems = g_list_sort (new_filesystems, gam_fs_filesystem_sort_cb); 40 } 41 +#endif 42 + 43 +#ifdef __FreeBSD__ 44 +static void 45 +gam_fs_getmntinfo (void) 46 +{ 47 + struct statfs *stat; 48 + GList *new_filesystems = NULL; 49 + gam_fs *fs = NULL; 50 + int i, n; 51 + 52 + n = getmntinfo(&stat, MNT_NOWAIT); 53 + if (n == -1) 54 + return; 55 + 56 + for (i = 0; i < n; i++) 57 + { 58 + fs = g_new0 (gam_fs, 1); 59 + fs->path = g_strdup (stat[i].f_mntonname); 60 + fs->fsname = g_strdup (stat[i].f_fstypename); 61 + fs->flags = stat[i].f_flags; 62 + 63 + new_filesystems = g_list_prepend (new_filesystems, fs); 64 + } 65 + 66 + /* Replace the old file systems list with the new one */ 67 + gam_fs_free_filesystems (); 68 + filesystems = g_list_sort (new_filesystems, gam_fs_filesystem_sort_cb); 69 +} 70 +#endif 71 72 void 73 gam_fs_init (void) 74 { 75 +#if defined(__linux__) 76 if (initialized == FALSE) 77 { 78 initialized = TRUE; 79 @@ -181,6 +222,7 @@ gam_fs_init (void) 80 if (stat("/etc/mtab", &mtab_sbuf) != 0) 81 { 82 GAM_DEBUG(DEBUG_INFO, "Could not stat /etc/mtab\n"); 83 + return; 84 } 85 gam_fs_scan_mtab (); 86 } else { 87 @@ -189,6 +231,7 @@ gam_fs_init (void) 88 if (stat("/etc/mtab", &sbuf) != 0) 89 { 90 GAM_DEBUG(DEBUG_INFO, "Could not stat /etc/mtab\n"); 91 + return; 92 } 93 94 /* /etc/mtab has changed */ 95 @@ -199,6 +242,54 @@ gam_fs_init (void) 96 97 mtab_sbuf = sbuf; 98 } 99 +#elif defined(__FreeBSD__) 100 + if (initialized == FALSE && initializing == FALSE) 101 + { 102 + GList *iterator = NULL; 103 + GHashTable *fs_hash = NULL; 104 + gam_fs *fs = NULL; 105 + 106 + initialized = TRUE; 107 + initializing = TRUE; 108 + 109 + gam_fs_getmntinfo (); 110 + 111 + iterator = filesystems; 112 + fs_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); 113 + 114 + while (iterator) { 115 + fs = iterator->data; 116 + 117 + if (!g_hash_table_lookup (fs_hash, fs->fsname)) { 118 + if (fs->flags & MNT_LOCAL) 119 + gam_fs_set (fs->fsname, GFS_MT_DEFAULT, 0); 120 + else 121 + gam_fs_set (fs->fsname, GFS_MT_POLL, 5); 122 + 123 + g_hash_table_insert (fs_hash, g_strdup (fs->fsname), GINT_TO_POINTER (1)); 124 + } 125 + 126 + iterator = g_list_next (iterator); 127 + } 128 + 129 + g_hash_table_destroy (fs_hash); 130 + initializing = FALSE; 131 + } else if (initializing == FALSE) { 132 + struct stat sbuf; 133 + 134 + if (stat ("/etc/fstab", &sbuf) != 0) { 135 + GAM_DEBUG(DEBUG_INFO, "Could not stat /etc/fstab\n"); 136 + return; 137 + } 138 + 139 + if (sbuf.st_mtime != mtab_sbuf.st_mtime) { 140 + GAM_DEBUG(DEBUG_INFO, "Updating list of mounted filesystems\n"); 141 + gam_fs_getmntinfo (); 142 + } 143 + 144 + mtab_sbuf = sbuf; 145 + } 146 +#endif 147 } 148 149 gam_fs_mon_type 150 @@ -210,7 +301,11 @@ gam_fs_get_mon_type (const char *path) 151 props = gam_fs_find_fs_props (path); 152 153 if (!props) 154 +#ifdef USE_GAMIN_POLLER 155 + return GFS_MT_POLL; 156 +#else 157 return GFS_MT_DEFAULT; 158 +#endif 159 160 return props->mon_type; 161 } 162