summaryrefslogtreecommitdiffstats
path: root/tools/hal-callout.c
diff options
context:
space:
mode:
authorChristophe Fergeau <teuf@gnome.org>2007-11-06 19:44:12 +0000
committerChristophe Fergeau <teuf@gnome.org>2007-11-06 19:44:12 +0000
commitff2ab777950a4b2bc8ce1719c0a73114a5445ceb (patch)
tree29077505b80812cf51abbed540c28c55e788825f /tools/hal-callout.c
parentecae67fbdfacd08e474298447ce978f4318c5e0d (diff)
downloadlibgpod-ff2ab777950a4b2bc8ce1719c0a73114a5445ceb.tar.gz
libgpod-ff2ab777950a4b2bc8ce1719c0a73114a5445ceb.tar.xz
libgpod-ff2ab777950a4b2bc8ce1719c0a73114a5445ceb.zip
* configure.ac:
* tools/20-libgpod-sysinfo-extended.fdi: * tools/Makefile.am: * tools/hal-callout.c: * tools/ipod-scsi-inquiry.c: * tools/read-sysinfoextended-sgutils.c: add hal callout which automatically write SysinfoExtended to iPods when they are plugged if it's properly installed git-svn-id: https://gtkpod.svn.sf.net/svnroot/gtkpod/libgpod/trunk@1760 f01d2545-417e-4e96-918e-98f8d0dbbcb6
Diffstat (limited to 'tools/hal-callout.c')
-rw-r--r--tools/hal-callout.c90
1 files changed, 90 insertions, 0 deletions
diff --git a/tools/hal-callout.c b/tools/hal-callout.c
new file mode 100644
index 0000000..5a89a57
--- /dev/null
+++ b/tools/hal-callout.c
@@ -0,0 +1,90 @@
+#include <errno.h>
+#include <glib.h>
+#include <glib/gstdio.h>
+#define __USE_BSD /* for mkdtemp */
+#include <stdlib.h>
+#include <string.h>
+#include <sys/mount.h>
+#include <itdb.h>
+#include <itdb_device.h>
+
+extern char *read_sysinfo_extended (const char *device);
+
+static char *mount_ipod (const char *dev_path)
+{
+ char *filename;
+ char *tmpname;
+ const char *fstype;
+ int result;
+
+ fstype = g_getenv ("HAL_PROP_VOLUME_FSTYPE");
+ if (fstype == NULL) {
+ return NULL;
+ }
+ filename = g_build_filename (G_DIR_SEPARATOR_S, "tmp", "ipodXXXXXX",
+ NULL);
+ if (filename == NULL) {
+ return NULL;
+ }
+ tmpname = mkdtemp (filename);
+ if (tmpname == NULL) {
+ g_free (filename);
+ return NULL;
+ }
+ g_assert (tmpname == filename);
+ result = mount (dev_path, tmpname, fstype, 0, NULL);
+ if (result != 0) {
+ g_rmdir (filename);
+ g_free (filename);
+ return NULL;
+ }
+
+ return tmpname;
+}
+
+static gboolean write_sysinfo_extended (const char *mountpoint,
+ const char *data)
+{
+ char *filename;
+ char *devdirpath;
+ gboolean result;
+
+ devdirpath = itdb_get_device_dir (mountpoint);
+ if (devdirpath == NULL) {
+ return FALSE;
+ }
+ filename = itdb_get_path (devdirpath, "SysInfoExtended");
+ g_free (devdirpath);
+ if (filename == NULL) {
+ return FALSE;
+ }
+
+ result = g_file_set_contents (filename, data, -1, NULL);
+ g_free (filename);
+
+ return result;
+}
+
+int main (int argc, char **argv)
+{
+ char *ipod_mountpoint;
+ char *xml;
+
+ xml = read_sysinfo_extended (g_getenv ("HAL_PROP_BLOCK_DEVICE"));
+ if (xml == NULL) {
+ return -1;
+ }
+ ipod_mountpoint = mount_ipod (g_getenv ("HAL_PROP_BLOCK_DEVICE"));
+ if (ipod_mountpoint == NULL) {
+ g_free (xml);
+ return -1;
+ }
+ write_sysinfo_extended (ipod_mountpoint, xml);
+
+ umount (ipod_mountpoint);
+ g_rmdir (ipod_mountpoint);
+ g_free (ipod_mountpoint);
+ g_free (xml);
+
+ return 0;
+}