4 * ROX-Filer, filer for the ROX desktop project
5 * By Thomas Leonard, <tal197@ecs.soton.ac.uk>.
8 /* mount.c - code for handling mount points */
21 /* Map mount points to mntent structures */
22 GHashTable
*fstab_mounts
= NULL
;
23 GHashTable
*mtab_mounts
= NULL
;
27 /* Static prototypes */
28 static GHashTable
*read_table(GHashTable
*mount_points
, char *path
);
29 static time_t read_time(char *path
);
30 static gboolean
free_mp(gpointer key
, gpointer value
, gpointer data
);
31 static void clear_table(GHashTable
*table
);
32 static time_t read_time(char *path
);
36 fstab_mounts
= g_hash_table_new(g_str_hash
, g_str_equal
);
37 mtab_mounts
= g_hash_table_new(g_str_hash
, g_str_equal
);
39 fstab_time
= read_time("/etc/fstab");
40 read_table(fstab_mounts
, "/etc/fstab");
41 mtab_time
= read_time("/etc/mtab");
42 read_table(mtab_mounts
, "/etc/mtab");
49 /* Ensure everything is uptodate */
51 time
= read_time("/etc/fstab");
52 if (time
!= fstab_time
)
55 read_table(fstab_mounts
, "/etc/fstab");
58 time
= read_time("/etc/mtab");
59 if (time
!= mtab_time
)
62 read_table(mtab_mounts
, "/etc/mtab");
66 static gboolean
free_mp(gpointer key
, gpointer value
, gpointer data
)
68 MountPoint
*mp
= (MountPoint
*) value
;
77 /* Remove all entries from a hash table, freeing them as we go */
78 static void clear_table(GHashTable
*table
)
80 g_hash_table_foreach_remove(table
, free_mp
, NULL
);
83 /* Return the mtime of a file */
84 static time_t read_time(char *path
)
88 g_return_val_if_fail(stat(path
, &info
) == 0, 0);
93 static GHashTable
*read_table(GHashTable
*mount_points
, char *path
)
99 clear_table(mount_points
);
101 tab
= setmntent(path
, "r");
102 g_return_val_if_fail(tab
!= NULL
, NULL
);
104 while ((ent
= getmntent(tab
)))
106 if (strcmp(ent
->mnt_dir
, "swap") == 0)
109 mp
= g_malloc(sizeof(MountPoint
));
110 mp
->name
= g_strdup(ent
->mnt_fsname
);
111 mp
->dir
= g_strdup(ent
->mnt_dir
);
113 g_hash_table_insert(mount_points
, mp
->dir
, mp
);