18c2aff776a775d34a4c9893a4c72e0434d68e36artem/***************************************************************************
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * CVSID: $Id: hal-storage-mount.c,v 1.7 2006/06/21 00:44:03 david Exp $
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * hal-storage-cleanup-mountpoint.c : Cleanup mount point when hald detects
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * that an unmount not done through Unmount()
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * Copyright (C) 2006 David Zeuthen, <david@fubar.dk>
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * This program is free software; you can redistribute it and/or modify
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * it under the terms of the GNU General Public License as published by
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * the Free Software Foundation; either version 2 of the License, or
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * (at your option) any later version.
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * This program is distributed in the hope that it will be useful,
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * but WITHOUT ANY WARRANTY; without even the implied warranty of
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * GNU General Public License for more details.
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * You should have received a copy of the GNU General Public License
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * along with this program; if not, write to the Free Software
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18c2aff776a775d34a4c9893a4c72e0434d68e36artem **************************************************************************/
18c2aff776a775d34a4c9893a4c72e0434d68e36artem/*#define DEBUG*/
18c2aff776a775d34a4c9893a4c72e0434d68e36artem fprintf (stderr, "This program should only be started by hald.\n");
18c2aff776a775d34a4c9893a4c72e0434d68e36artem unknown_error ("Cannot seek to end of /media/.hal-mtab");
18c2aff776a775d34a4c9893a4c72e0434d68e36artem unknown_error ("Cannot determine size of /media/.hal-mtab");
18c2aff776a775d34a4c9893a4c72e0434d68e36artem num_read = fread (hal_mtab_buf, 1, hal_mtab_orig_len, hal_mtab_orig);
18c2aff776a775d34a4c9893a4c72e0434d68e36artem /* find the entry we're going to unmount */
18c2aff776a775d34a4c9893a4c72e0434d68e36artem unknown_error ("mount point is not /media/.hal-mtab");
18c2aff776a775d34a4c9893a4c72e0434d68e36artem printf ("Found entry for mount point '%s' in /media/.hal-mtab", mount_point);
18c2aff776a775d34a4c9893a4c72e0434d68e36artem /* create new .hal-mtab~ file without the entry we're going to unmount */
18c2aff776a775d34a4c9893a4c72e0434d68e36artem if (i > 0) {
18c2aff776a775d34a4c9893a4c72e0434d68e36artem if (fwrite (lines[i], 1, strlen (lines[i]), hal_mtab_new) != strlen (lines[i])) {
18c2aff776a775d34a4c9893a4c72e0434d68e36artem /* remove directory */
18c2aff776a775d34a4c9893a4c72e0434d68e36artem /* set new .hal-mtab file */
18c2aff776a775d34a4c9893a4c72e0434d68e36artem if (rename ("/media/.hal-mtab~", "/media/.hal-mtab") != 0) {
18c2aff776a775d34a4c9893a4c72e0434d68e36artem unknown_error ("Cannot rename /media/.hal-mtab~ to /media/.hal-mtab");
18c2aff776a775d34a4c9893a4c72e0434d68e36artem unknown_error ("Cannot obtain lock on /media/.hal-mtab");
18c2aff776a775d34a4c9893a4c72e0434d68e36artem printf ("in hal-storage-cleanup-mountpoint for mount point '%s'\n", mount_point);