diff --git a/include/ntfs-3g/volume.h b/include/ntfs-3g/volume.h index f8cab845..4f6f004b 100644 --- a/include/ntfs-3g/volume.h +++ b/include/ntfs-3g/volume.h @@ -219,6 +219,8 @@ struct _ntfs_volume { s64 free_mft_records; /* Same for free mft records (see above) */ }; +extern const char *ntfs_home; + extern ntfs_volume *ntfs_volume_alloc(void); extern ntfs_volume *ntfs_volume_startup(struct ntfs_device *dev, @@ -237,6 +239,9 @@ extern int ntfs_logfile_reset(ntfs_volume *vol); extern int ntfs_volume_write_flags(ntfs_volume *vol, const u16 flags); extern int ntfs_volume_error(int err); +extern void ntfs_mount_error(const char *vol, const char *mntpoint, int err); + +extern int ntfs_set_locale(void); #endif /* defined _NTFS_VOLUME_H */ diff --git a/libntfs-3g/volume.c b/libntfs-3g/volume.c index 4849db9f..e4ba6b56 100644 --- a/libntfs-3g/volume.c +++ b/libntfs-3g/volume.c @@ -49,6 +49,9 @@ #ifdef HAVE_LIMITS_H #include #endif +#ifdef HAVE_LOCALE_H +#include +#endif #include "volume.h" #include "attrib.h" @@ -67,6 +70,66 @@ #define PATH_MAX 4096 #endif +const char *ntfs_home = +"Ntfs-3g news, support and information: http://ntfs-3g.org\n"; + +static const char *invalid_ntfs_msg = +"The device '%s' doesn't seem to have a valid NTFS.\n" +"Maybe the wrong device is used? Or the whole disk instead of a\n" +"partition (e.g. /dev/sda, not /dev/sda1)? Or the other way around?\n"; + +static const char *corrupt_volume_msg = +"NTFS is either inconsistent, or there is a hardware fault, or it's a\n" +"SoftRAID/FakeRAID hardware. In the first case run chkdsk /f on Windows\n" +"then reboot into Windows twice. The usage of the /f parameter is very\n" +"important! If the device is a SoftRAID/FakeRAID then first activate\n" +"it and mount a different device under the /dev/mapper/ directory, (e.g.\n" +"/dev/mapper/nvidia_eahaabcc1). Please see the 'dmraid' documentation\n" +"for more details.\n"; + +static const char *hibernated_volume_msg = +"The NTFS partition is hibernated. Please resume and shutdown Windows\n" +"properly, or mount the volume read-only with the 'ro' mount option, or\n" +"mount the volume read-write with the 'remove_hiberfile' mount option.\n" +"For example type on the command line:\n" +"\n" +" mount -t ntfs-3g -o remove_hiberfile %s %s\n" +"\n"; + +static const char *unclean_journal_msg = +"Mount is denied because NTFS is marked to be in use. Choose one action:\n" +"\n" +"Choice 1: If you have Windows then disconnect the external devices by\n" +" clicking on the 'Safely Remove Hardware' icon in the Windows\n" +" taskbar then shutdown Windows cleanly.\n" +"\n" +"Choice 2: If you don't have Windows then you can use the 'force' option for\n" +" your own responsibility. For example type on the command line:\n"; + +static const char *opened_volume_msg = +"Mount is denied because the NTFS volume is already exclusively opened.\n" +"The volume may be already mounted, or another software may use it which\n" +"could be identified for example by the help of the 'fuser' command.\n"; + +static const char *fakeraid_msg = +"Either the device is missing or it's powered down, or you have\n" +"SoftRAID hardware and must use an activated, different device under\n" +"/dev/mapper/, (e.g. /dev/mapper/nvidia_eahaabcc1) to mount NTFS.\n" +"Please see the 'dmraid' documentation for help.\n"; + +static const char *access_denied_msg = +"Please check '%s' and the ntfs-3g binary permissions,\n" +"and the mounting user ID. More explanation is provided at\n" +"http://ntfs-3g.org/support.html#unprivileged\n"; + +static const char *forced_mount_msg = +"\n" +" mount -t ntfs-3g -o force %s %s\n" +"\n" +" Or add the option to the relevant row in the /etc/fstab file:\n" +"\n" +" %s %s ntfs-3g force 0 0\n"; + /** * ntfs_volume_alloc - Create an NTFS volume object and initialise it * @@ -1473,3 +1536,47 @@ int ntfs_volume_error(int err) return ret; } + +void ntfs_mount_error(const char *volume, const char *mntpoint, int err) +{ + switch (err) { + case NTFS_VOLUME_NOT_NTFS: + ntfs_log_error(invalid_ntfs_msg, volume); + break; + case NTFS_VOLUME_CORRUPT: + ntfs_log_error("%s", corrupt_volume_msg); + break; + case NTFS_VOLUME_HIBERNATED: + ntfs_log_error(hibernated_volume_msg, volume, mntpoint); + break; + case NTFS_VOLUME_UNCLEAN_UNMOUNT: + ntfs_log_error("%s", unclean_journal_msg); + ntfs_log_error(forced_mount_msg, volume, mntpoint, + volume, mntpoint); + break; + case NTFS_VOLUME_LOCKED: + ntfs_log_error("%s", opened_volume_msg); + break; + case NTFS_VOLUME_RAID: + ntfs_log_error("%s", fakeraid_msg); + break; + case NTFS_VOLUME_NO_PRIVILEGE: + ntfs_log_error(access_denied_msg, volume); + break; + } +} + +int ntfs_set_locale(void) +{ + const char *locale; + + locale = setlocale(LC_ALL, ""); + if (!locale) { + locale = setlocale(LC_ALL, NULL); + ntfs_log_error("Couldn't set local environment, using default " + "'%s'.\n", locale); + return 1; + } + return 0; +} + diff --git a/src/Makefile.am b/src/Makefile.am index e04776c8..22d70254 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -23,14 +23,14 @@ ntfs_3g_CFLAGS = \ -DFUSE_USE_VERSION=26 \ $(FUSE_CFLAGS) \ -I$(top_srcdir)/include/ntfs-3g -ntfs_3g_SOURCES = ntfs-3g.c utils.c utils.h +ntfs_3g_SOURCES = ntfs-3g.c ntfs_3g_probe_LDADD = $(top_builddir)/libntfs-3g/libntfs-3g.la if REALLYSTATIC ntfs_3g_probe_LDFLAGS = $(AM_LDFLAGS) -all-static endif ntfs_3g_probe_CFLAGS = $(AM_CFLAGS) -I$(top_srcdir)/include/ntfs-3g -ntfs_3g_probe_SOURCES = ntfs-3g.probe.c utils.c utils.h +ntfs_3g_probe_SOURCES = ntfs-3g.probe.c if RUN_LDCONFIG install-exec-hook: diff --git a/src/ntfs-3g.c b/src/ntfs-3g.c index 679a8a53..83fe3f94 100644 --- a/src/ntfs-3g.c +++ b/src/ntfs-3g.c @@ -89,7 +89,6 @@ #include "unistr.h" #include "layout.h" #include "index.h" -#include "utils.h" #include "ntfstime.h" #include "misc.h" @@ -2219,7 +2218,7 @@ int main(int argc, char *argv[]) if (drop_privs()) return NTFS_VOLUME_NO_PRIVILEGE; - utils_set_locale(); + ntfs_set_locale(); ntfs_log_set_handler(ntfs_log_handler_stderr); if (parse_options(argc, argv)) { @@ -2301,7 +2300,7 @@ int main(int argc, char *argv[]) fuse_unmount(opts.mnt_point, ctx->fc); fuse_destroy(fh); err_out: - utils_mount_error(opts.device, opts.mnt_point, err); + ntfs_mount_error(opts.device, opts.mnt_point, err); err2: ntfs_close(); free(ctx); diff --git a/src/ntfs-3g.probe.c b/src/ntfs-3g.probe.c index 8981c064..be265dd7 100644 --- a/src/ntfs-3g.probe.c +++ b/src/ntfs-3g.probe.c @@ -33,7 +33,6 @@ #include #include "volume.h" -#include "utils.h" #include "misc.h" #ifndef PATH_MAX diff --git a/src/utils.c b/src/utils.c deleted file mode 100644 index 8914eb25..00000000 --- a/src/utils.c +++ /dev/null @@ -1,151 +0,0 @@ -/** - * utils.c - Originated from the Linux-NTFS project. - * - * Copyright (c) 2002-2005 Richard Russon - * Copyright (c) 2003-2006 Anton Altaparmakov - * Copyright (c) 2003 Lode Leroy - * Copyright (c) 2005-2008 Szabolcs Szakacsits - * - * A set of shared functions for ntfs utilities - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program (in the main directory of the NTFS-3G - * distribution in the file COPYING); if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#ifdef HAVE_LOCALE_H -#include -#endif -#ifdef HAVE_ERRNO_H -#include -#endif - -#include "utils.h" - -const char *ntfs_home = - "Ntfs-3g news, support and information: http://ntfs-3g.org\n"; -const char *ntfs_gpl = "This program is free software, released under the GNU " - "General Public License\nand you are welcome to redistribute it under " - "certain conditions. It comes with\nABSOLUTELY NO WARRANTY; for " - "details read the GNU General Public License to be\nfound in the file " - "\"COPYING\" distributed with this program, or online at:\n" - "http://www.gnu.org/copyleft/gpl.html\n"; - -static const char *invalid_ntfs_msg = -"The device '%s' doesn't have a valid NTFS.\n" -"Maybe you selected the wrong device? Or the whole disk instead of a\n" -"partition (e.g. /dev/hda, not /dev/hda1)? Or the other way around?\n"; - -static const char *corrupt_volume_msg = -"NTFS is either inconsistent, or you have hardware faults, or you have a\n" -"SoftRAID/FakeRAID hardware. In the first case run chkdsk /f on Windows\n" -"then reboot into Windows TWICE. The usage of the /f parameter is very\n" -"important! If you have SoftRAID/FakeRAID then first you must activate\n" -"it and mount a different device under the /dev/mapper/ directory, (e.g.\n" -"/dev/mapper/nvidia_eahaabcc1). Please see the 'dmraid' documentation\n" -"for the details.\n"; - -static const char *hibernated_volume_msg = -"The NTFS partition is hibernated. Please resume and shutdown Windows\n" -"properly, or mount the volume read-only with the 'ro' mount option, or\n" -"mount the volume read-write with the 'remove_hiberfile' mount option.\n" -"For example type on the command line:\n" -"\n" -" mount -t ntfs-3g -o remove_hiberfile %s %s\n" -"\n"; - -static const char *unclean_journal_msg = -"Mount is denied because NTFS is marked to be in use. Choose one action:\n" -"\n" -"Choice 1: If you have Windows then disconnect the external devices by\n" -" clicking on the 'Safely Remove Hardware' icon in the Windows\n" -" taskbar then shutdown Windows cleanly.\n" -"\n" -"Choice 2: If you don't have Windows then you can use the 'force' option for\n" -" your own responsibility. For example type on the command line:\n"; - -static const char *opened_volume_msg = -"Mount is denied because the NTFS volume is already exclusively opened.\n" -"The volume may be already mounted, or another software may use it which\n" -"could be identified for example by the help of the 'fuser' command.\n"; - -static const char *fakeraid_msg = -"Either the device is missing or it's powered down, or you have\n" -"SoftRAID hardware and must use an activated, different device under\n" -"/dev/mapper/, (e.g. /dev/mapper/nvidia_eahaabcc1) to mount NTFS.\n" -"Please see the 'dmraid' documentation for help.\n"; - -static const char *access_denied_msg = -"Please check '%s' and the ntfs-3g binary permissions,\n" -"and the mounting user ID. More explanation is provided at\n" -"http://ntfs-3g.org/support.html#unprivileged\n"; - -static const char *forced_mount_msg = -"\n" -" mount -t ntfs-3g -o force %s %s\n" -"\n" -" Or add the option to the relevant row in the /etc/fstab file:\n" -"\n" -" %s %s ntfs-3g force 0 0\n"; - -/** - * utils_set_locale - */ -int utils_set_locale(void) -{ - const char *locale; - - locale = setlocale(LC_ALL, ""); - if (!locale) { - locale = setlocale(LC_ALL, NULL); - ntfs_log_error("Couldn't set local environment, using default " - "'%s'.\n", locale); - return 1; - } - return 0; -} - -void utils_mount_error(const char *volume, const char *mntpoint, int err) -{ - switch (err) { - case NTFS_VOLUME_NOT_NTFS: - ntfs_log_error(invalid_ntfs_msg, volume); - break; - case NTFS_VOLUME_CORRUPT: - ntfs_log_error("%s", corrupt_volume_msg); - break; - case NTFS_VOLUME_HIBERNATED: - ntfs_log_error(hibernated_volume_msg, volume, mntpoint); - break; - case NTFS_VOLUME_UNCLEAN_UNMOUNT: - ntfs_log_error("%s", unclean_journal_msg); - ntfs_log_error(forced_mount_msg, volume, mntpoint, - volume, mntpoint); - break; - case NTFS_VOLUME_LOCKED: - ntfs_log_error("%s", opened_volume_msg); - break; - case NTFS_VOLUME_RAID: - ntfs_log_error("%s", fakeraid_msg); - break; - case NTFS_VOLUME_NO_PRIVILEGE: - ntfs_log_error(access_denied_msg, volume); - break; - } -} - diff --git a/src/utils.h b/src/utils.h deleted file mode 100644 index 2d47ca4b..00000000 --- a/src/utils.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * utils.h - Originated from the Linux-NTFS project. - * - * Copyright (c) 2002-2005 Richard Russon - * Copyright (c) 2004 Anton Altaparmakov - * Copyright (c) 2005-2007 Szabolcs Szakacsits - * - * A set of shared functions for ntfs utilities - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program (in the main directory of the NTFS-3G - * distribution in the file COPYING); if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef _NTFS_UTILS_H_ -#define _NTFS_UTILS_H_ - -#include "volume.h" - -extern const char *ntfs_home; -extern const char *ntfs_gpl; - -int utils_set_locale(void); -void utils_mount_error(const char *vol, const char *mntpoint, int err); - -#endif /* _NTFS_UTILS_H_ */