[maemo-commits] [maemo-commits] r17428 - in projects/haf/trunk/ke-recv: debian src

From: subversion at stage.maemo.org subversion at stage.maemo.org
Date: Mon Feb 16 09:38:31 EET 2009
Author: kihamala
Date: 2009-02-16 09:38:30 +0200 (Mon, 16 Feb 2009)
New Revision: 17428

Modified:
   projects/haf/trunk/ke-recv/debian/changelog
   projects/haf/trunk/ke-recv/debian/control
   projects/haf/trunk/ke-recv/src/events.c
   projects/haf/trunk/ke-recv/src/events.h
   projects/haf/trunk/ke-recv/src/ke-recv.c
   projects/haf/trunk/ke-recv/src/mmc-check.c
   projects/haf/trunk/ke-recv/src/osso-mmc-mount.sh
Log:
add time-limited check and interface for full check


Modified: projects/haf/trunk/ke-recv/debian/changelog
===================================================================
--- projects/haf/trunk/ke-recv/debian/changelog	2009-02-14 15:10:50 UTC (rev 17427)
+++ projects/haf/trunk/ke-recv/debian/changelog	2009-02-16 07:38:30 UTC (rev 17428)
@@ -7,6 +7,9 @@
   * Disabled Application Manager auto-start feature.
   * Disabled 'memory card available' banner. Fixes: NB#101300, NB#101094
   * Disabled 'memory card in use' dialog. Fixes: NB#100744
+  * Do a time-limited memory card check before trying to mount it read-write.
+  * Add D-Bus interface for full memory card check.
+  * Disable D-Bus interface for memory card repairing.
 
  -- Kimmo Hämäläinen <kimmo.hamalainen at nokia.com>  Fri, 13 Feb 2009 11:00:18 +0200
 

Modified: projects/haf/trunk/ke-recv/debian/control
===================================================================
--- projects/haf/trunk/ke-recv/debian/control	2009-02-14 15:10:50 UTC (rev 17427)
+++ projects/haf/trunk/ke-recv/debian/control	2009-02-16 07:38:30 UTC (rev 17428)
@@ -7,7 +7,7 @@
 
 Package: ke-recv
 Architecture: any
-Depends: ${shlibs:Depends}, ke-recv-l10n-mr | ke-recv-l10n-mr0, gconf2, osso-af-startup (>= 1.22), hal, dosfstools, mtools
+Depends: ${shlibs:Depends}, ke-recv-l10n-mr | ke-recv-l10n-mr0, gconf2, osso-af-startup (>= 1.22), hal, dosfstools (>> 3.0.1-1maemo1), mtools
 Description: Program for automatical mounting and unmounting of memory cards.
  Program for receiving HW events from the HAL, managing mounting, renaming,
  formatting, and partitioning of memory cards, etc.

Modified: projects/haf/trunk/ke-recv/src/events.c
===================================================================
--- projects/haf/trunk/ke-recv/src/events.c	2009-02-14 15:10:50 UTC (rev 17427)
+++ projects/haf/trunk/ke-recv/src/events.c	2009-02-16 07:38:30 UTC (rev 17428)
@@ -809,7 +809,7 @@
 
         args[1] = part_device;
 
-        /* exec mmc-format */
+        /* exec mmc-check */
         ret = exec_prog(args[0], args);
 
         if (ret > 2) {
@@ -836,6 +836,62 @@
         }
 }
 
+static void handle_e_check(mmc_info_t *mmc)
+{
+        int ret, mounted;
+        char *part_device = NULL, *udi = NULL;
+        volume_list_t *l;
+        const char* args[] = {"/usr/sbin/mmc-check", NULL, NULL};
+
+        l = get_nth_volume(mmc, mmc->preferred_volume);
+
+        if (l && l->dev_name && l->udi) {
+                part_device = l->dev_name;
+                udi = l->udi;
+        } else {
+                ULOG_ERR_F("device name for the partition not found");
+                display_system_note("Partition not found");
+                return;
+        }
+
+        /* check if someone else has already mounted it */
+        mounted = get_prop_bool(udi, "volume.is_mounted");
+        if (mounted) {
+                ULOG_INFO_F("%s is mounted", part_device);
+                return;
+        }
+
+        args[1] = part_device;
+
+        /* exec mmc-check */
+        ret = exec_prog(args[0], args);
+
+        if (ret > 2) {
+                ULOG_ERR_F("dosfsck returned: %d", ret - 2);
+                display_system_note("dosfsck failed");
+                /* TODO: set corrupt flag */
+                return;
+        } else if (ret > 0) {
+                ULOG_ERR_F("mmc-check error code: %d", ret);
+                display_system_note("mmc-check failed");
+                return;
+        } else if (ret < 0) {
+                ULOG_ERR_F("exec_prog error code: %d", ret);
+                display_system_note("exec_prog failed");
+                return;
+        }
+#if 0
+        l->corrupt = 0;
+        set_mmc_corrupted_flag(FALSE, mmc);
+
+        if (mount_volumes(mmc)) {
+                display_system_note(_("card_memory_card_repaired"));
+        } else {
+                display_system_note(MSG_UNABLE_TO_REPAIR);
+        }
+#endif
+}
+
 static int mount_volumes(mmc_info_t *mmc)
 {
         const char *mount_args[] = {MMC_MOUNT_COMMAND, NULL, NULL, NULL};
@@ -1007,6 +1063,7 @@
                         ULOG_WARN_F("improper state");
                         break;
                 case E_REPAIR:
+                case E_CHECK:
                         ULOG_WARN_F("improper state");
                         break;
                 case E_VOLUME_REMOVED:
@@ -1181,6 +1238,9 @@
                 case E_REPAIR:
                         handle_e_repair(mmc);
                         break;
+                case E_CHECK:
+                        handle_e_check(mmc);
+                        break;
                 case E_VOLUME_ADDED:
                         ULOG_DEBUG_F("E_VOLUME_ADDED for %s", mmc->name);
                         if (ignore_cable || !in_mass_storage_mode()) {
@@ -1279,6 +1339,7 @@
                         ULOG_WARN_F("improper state");
                         break;
                 case E_REPAIR:
+                case E_CHECK:
                         ULOG_WARN_F("improper state");
                         break;
                 case E_UNMOUNT_TIMEOUT:

Modified: projects/haf/trunk/ke-recv/src/events.h
===================================================================
--- projects/haf/trunk/ke-recv/src/events.h	2009-02-14 15:10:50 UTC (rev 17427)
+++ projects/haf/trunk/ke-recv/src/events.h	2009-02-16 07:38:30 UTC (rev 17428)
@@ -70,6 +70,7 @@
         E_RENAME,
         E_FORMAT,
         E_REPAIR,
+        E_CHECK,
         E_UNMOUNT_TIMEOUT,
        	E_VOLUME_ADDED,
        	E_VOLUME_REMOVED,

Modified: projects/haf/trunk/ke-recv/src/ke-recv.c
===================================================================
--- projects/haf/trunk/ke-recv/src/ke-recv.c	2009-02-14 15:10:50 UTC (rev 17427)
+++ projects/haf/trunk/ke-recv/src/ke-recv.c	2009-02-16 07:38:30 UTC (rev 17428)
@@ -487,6 +487,40 @@
         return DBUS_HANDLER_RESULT_HANDLED;
 }
 
+static DBusHandlerResult card_check_handler(DBusConnection *c,
+                                             DBusMessage *m,
+                                             void *data)
+{
+        DBusMessageIter iter;
+        char *s = NULL;
+        mmc_info_t *mmc;
+
+        ULOG_DEBUG_F("entered");
+        the_connection = c;
+        the_message = m;
+        if (!dbus_message_iter_init(m, &iter)) {
+                ULOG_ERR_F("no device name argument");
+                send_error("no_argument");
+                goto away;
+        }
+        dbus_message_iter_get_basic(&iter, &s);
+
+        mmc = mmc_from_dev_name(s);
+        if (mmc == NULL) {
+                ULOG_ERR_F("bad device name '%s'", s);
+                send_error("bad_argument");
+        } else {
+                send_reply();
+                handle_event(E_CHECK, mmc, NULL);
+        }
+away:
+        /* invalidate */
+        the_connection = NULL;
+        the_message = NULL;
+        return DBUS_HANDLER_RESULT_HANDLED;
+}
+
+#if 0
 static DBusHandlerResult card_repair_handler(DBusConnection *c,
                                              DBusMessage *m,
                                              void *data)
@@ -519,6 +553,7 @@
         the_message = NULL;
         return DBUS_HANDLER_RESULT_HANDLED;
 }
+#endif
 
 /* This function is for testing only. Allows emulating the USB cable
  * attaching and detaching. */
@@ -3058,11 +3093,18 @@
         register_op(sys_conn, &vtable,
                     "/com/nokia/ke_recv/check_auto_install", NULL);
 
+#if 0
         /* D-Bus interface for repairing memory cards */
         vtable.message_function = card_repair_handler;
         register_op(sys_conn, &vtable,
                     "/com/nokia/ke_recv/repair_card", NULL);
+#endif
 
+        /* D-Bus interface for repairing memory cards */
+        vtable.message_function = card_check_handler;
+        register_op(sys_conn, &vtable,
+                    "/com/nokia/ke_recv/check_card", NULL);
+
         /* D-Bus interface for 'ejecting' USB mass storages */
         vtable.message_function = eject_handler;
         register_op(sys_conn, &vtable,

Modified: projects/haf/trunk/ke-recv/src/mmc-check.c
===================================================================
--- projects/haf/trunk/ke-recv/src/mmc-check.c	2009-02-14 15:10:50 UTC (rev 17427)
+++ projects/haf/trunk/ke-recv/src/mmc-check.c	2009-02-16 07:38:30 UTC (rev 17428)
@@ -41,6 +41,7 @@
 static pid_t child_pid = -1;
 static int pipe_fd = -1;
 static HildonBanner *hildon_banner = NULL;
+static int quick_check = 0;
 
 static void sig_handler(int signo)
 {
@@ -62,7 +63,6 @@
                 } else if (WEXITSTATUS(child_status) == 2) {
                         exit(4);
                 }
-                sync();  /* sync before exit */
                 exit(0);
         } else {
                 ULOG_WARN_F("child terminated abnormally");
@@ -144,25 +144,36 @@
 
 static gboolean start_repair(const char *dev)
 {
-        const char* args[] = {"/sbin/dosfsck", "-a", NULL, NULL};
+        const char* args[] = {"/sbin/dosfsck", NULL, NULL, NULL, NULL, NULL};
 
         ULOG_DEBUG_F("entered");
 
-        args[2] = dev;
+        if (quick_check) {
+                /* time-limited check */
+                args[1] = "-T";
+                args[2] = "10";
+                args[3] = dev;
+        } else {
+                /* full check */
+                args[1] = "-n";
+                args[2] = dev;
+        }
 
         if (no_wait_exec(args[0], args) > 0) {
-                /* set up reading from the pipe */
-                GError* err = NULL;
-                GIOChannel* ch = g_io_channel_unix_new(pipe_fd);
-                if (g_io_channel_set_encoding(ch, NULL, &err) !=
-                                G_IO_STATUS_NORMAL) {
-                        ULOG_ERR_F("failed to set encoding");
+                if (!quick_check) {
+                        /* set up reading from the pipe */
+                        GError* err = NULL;
+                        GIOChannel* ch = g_io_channel_unix_new(pipe_fd);
+                        if (g_io_channel_set_encoding(ch, NULL, &err) !=
+                                        G_IO_STATUS_NORMAL) {
+                                ULOG_ERR_F("failed to set encoding");
+                        }
+                        /*
+                        g_io_channel_set_buffered(ch, FALSE);
+                        */
+                        g_io_add_watch(ch, G_IO_IN | G_IO_ERR | G_IO_HUP,
+                                       gio_func, NULL);
                 }
-                /*
-                g_io_channel_set_buffered(ch, FALSE);
-                */
-                g_io_add_watch(ch, G_IO_IN | G_IO_ERR | G_IO_HUP,
-                               gio_func, NULL);
                 return TRUE;
         } else {
                 return FALSE;
@@ -176,10 +187,13 @@
         ULOG_OPEN("mmc-check");
         ULOG_DEBUG_L("entered");
 
-        if (argc != 2) {
-                ULOG_CRIT_L("Usage: %s <device>", argv[0]);
+        if (argc != 2 && argc != 3) {
+                ULOG_CRIT_L("Usage: %s <device> [-q]", argv[0]);
                 exit(1);
         }
+        if (argc == 3) {
+                quick_check = 1;
+        }
 
         sa.sa_handler = sig_handler;
         sigemptyset(&sa.sa_mask);
@@ -189,35 +203,42 @@
                 exit(1);
         }
 
-        if (setlocale(LC_ALL, "") == NULL) {
-                ULOG_CRIT_L("could not set locale");
-                exit(1);
-        }
-        if (bindtextdomain(PACKAGE, LOCALEDIR) == NULL) {
-                ULOG_ERR_L("bindtextdomain() failed");
-        }
-        if (textdomain(PACKAGE) == NULL) {
-                ULOG_ERR_L("textdomain() failed");
-        }
+        if (!quick_check) {
+                if (setlocale(LC_ALL, "") == NULL) {
+                        ULOG_CRIT_L("could not set locale");
+                        exit(1);
+                }
+                if (bindtextdomain(PACKAGE, LOCALEDIR) == NULL) {
+                        ULOG_ERR_L("bindtextdomain() failed");
+                }
+                if (textdomain(PACKAGE) == NULL) {
+                        ULOG_ERR_L("textdomain() failed");
+                }
 
-        if (!gtk_init_check(&argc, &argv)) {
-                ULOG_CRIT_L("gtk_init failed");
-                exit(1);
-        }
+                if (!gtk_init_check(&argc, &argv)) {
+                        ULOG_CRIT_L("gtk_init failed");
+                        exit(1);
+                }
 
-        hildon_banner = (HildonBanner*)hildon_banner_show_progress(NULL, NULL,
+                hildon_banner =
+                        (HildonBanner*)hildon_banner_show_progress(NULL, NULL,
                                 _("card_repairing_memory_card"));
-        hildon_banner_set_fraction(hildon_banner, 0.0);
-        gtk_widget_show(GTK_WIDGET(hildon_banner));
+                hildon_banner_set_fraction(hildon_banner, 0.0);
+                gtk_widget_show(GTK_WIDGET(hildon_banner));
+        }
 
         if (start_repair(argv[1])) {
-                ULOG_DEBUG_L("going to main loop");
-                gtk_main();
-                ULOG_WARN_L("returned from main loop");
-                sync();  /* sync before exit */
+                if (quick_check) {
+                        ULOG_DEBUG_L("waiting for child");
+                        sleep(20000);  /* FIXME */
+                } else {
+                        ULOG_DEBUG_L("going to main loop");
+                        gtk_main();
+                        ULOG_WARN_L("returned from main loop");
+                }
                 exit(0);
         } else {
-                ULOG_CRIT_L("could not start repairing");
+                ULOG_CRIT_L("could not start repairing/checking");
                 exit(1);
         }
 }

Modified: projects/haf/trunk/ke-recv/src/osso-mmc-mount.sh
===================================================================
--- projects/haf/trunk/ke-recv/src/osso-mmc-mount.sh	2009-02-14 15:10:50 UTC (rev 17427)
+++ projects/haf/trunk/ke-recv/src/osso-mmc-mount.sh	2009-02-16 07:38:30 UTC (rev 17428)
@@ -1,7 +1,7 @@
 #!/bin/sh
 # This file is part of ke-recv
 #
-# Copyright (C) 2005-2007 Nokia Corporation. All rights reserved.
+# Copyright (C) 2005-2009 Nokia Corporation. All rights reserved.
 #
 # Contact: Kimmo Hämäläinen <kimmo.hamalainen at nokia.com>
 #
@@ -45,6 +45,18 @@
   mkdir -p $MP
 fi
 
+/sbin/dosfsck -T 10 $PDEV
+if [ $? != 0 ]; then
+  echo "$0: $PDEV is corrupt, trying to mount it read-only"
+  mount -t vfat -o ro,noauto,nodev,noexec,nosuid,noatime,nodiratime,utf8,uid=29999,shortname=mixed,dmask=000,fmask=0133 $PDEV $MP > /dev/null
+  if [ $? = 0 ]; then
+    echo "$0: $PDEV mounted read-only"
+    exit 0
+  else
+    echo "$0: Couldn't mount $PDEV read-only"
+    exit 1
+  fi
+fi
 
 mmc-mount $PDEV $MP
 RC=$?


More information about the maemo-commits mailing list