diff options
author | Christophe Grenier <[email protected]> | 2025-04-04 17:57:29 +0200 |
---|---|---|
committer | Christophe Grenier <[email protected]> | 2025-04-04 17:57:29 +0200 |
commit | 5f06fc11ae9fa7f687f25372432f42d68e5414bb (patch) | |
tree | d85a1b6cd46345ba66a2a2d470abfe4252e5a828 | |
parent | 544ecfea8ced026f474bf72c866fedabbd03f65c (diff) |
Improve iconv and ntfs_device_operations_ioctl() compatibility
-rw-r--r-- | configure.ac | 134 | ||||
-rw-r--r-- | src/exfat_dir.c | 2 | ||||
-rw-r--r-- | src/ntfs_dir.c | 14 | ||||
-rw-r--r-- | src/ntfs_io.c | 4 |
4 files changed, 67 insertions, 87 deletions
diff --git a/configure.ac b/configure.ac index 0e4e8851..e72579d9 100644 --- a/configure.ac +++ b/configure.ac @@ -2,11 +2,11 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ([2.59]) -AC_INIT([testdisk],[7.2],[[email protected]]) +AC_INIT([testdisk],[7.3-WIP],[[email protected]]) AC_LANG(C) sinclude(acx_pthread.m4) sinclude(mkdir.m4) -TESTDISKDATE="February 2024" +TESTDISKDATE="April 2025" AC_SUBST(TESTDISKDATE) AC_DEFINE_UNQUOTED([TESTDISKDATE],"$TESTDISKDATE",[Date of release]) AC_CONFIG_AUX_DIR(config) @@ -332,81 +332,11 @@ AC_HEADER_STDC AC_HEADER_SYS_WAIT AC_CHECK_HEADERS([byteswap.h curses.h cygwin/fs.h cygwin/version.h dal/file_dal.h dal/file.h ddk/ntddstor.h dirent.h endian.h errno.h fcntl.h features.h giconv.h glob.h iconv.h io.h libgen.h limits.h linux/fs.h linux/hdreg.h linux/types.h locale.h machine/endian.h malloc.h ncurses.h ncurses/curses.h ncurses/ncurses.h ncursesw/curses.h ncursesw/ncurses.h ntfs/version.h pwd.h scsi/scsi.h scsi/scsi_ioctl.h scsi/sg.h setjmp.h signal.h stdarg.h sys/cygwin.h sys/disk.h sys/disklabel.h sys/dkio.h sys/endian.h sys/ioctl.h sys/sysmacros.h sys/param.h sys/select.h sys/time.h sys/utsname.h sys/vtoc.h time.h utime.h w32api/ddk/ntdddisk.h windef.h windows.h zlib.h]) -#-------------------------------------------------------------------- -# Check for iconv support (for Unicode conversion). -#-------------------------------------------------------------------- -# -# We need to find an iconv library that matches the installed iconv.h header -# (if any). It is important to check header/library compatibility. It's -# fairly common to have iconv support both in libc and from libiconv. In that -# case, a naive check that iconv() is in libc will succeed, but if we use -# libiconv's iconv.h, it will redefine iconv() to functions that exist -# only in libiconv, and we'll get link errors. -# -# First, check if there's a working iconv in libc (ie. if the test program -# compiles and links without any extra flags). -if test "x$with_iconv" != "xno"; then -AC_MSG_CHECKING(iconv support) -AC_LINK_IFELSE([AC_LANG_SOURCE([#include <iconv.h> -int main(int argc,char **argv) { iconv_open("foo","bar"); }])] -, - # libc has a working iconv. - AC_DEFINE(HAVE_ICONV,1, [Define if you have this function]) - AC_MSG_RESULT([[yes, in libc]]) - have_iconv=yes -) - -if test "x$have_iconv" != "xyes" ; then - # libc doesn't have a working iconv. Try adding -liconv and any user - # supplied directory. - - old_LIBS="$LIBS" - if test "${iconv_lib_a}" = ""; then - LIBS="-liconv $LIBS" - else - LIBS="${iconv_lib_a} $LIBS" - fi - AC_LINK_IFELSE([AC_LANG_SOURCE([#include <iconv.h> - int main(int argc,char **argv) { iconv_open("foo","bar"); }])] - , - # -liconv works. - AC_DEFINE(HAVE_ICONV,1, [Define if you have this function]) - AC_MSG_RESULT([[yes, -liconv]]) - have_iconv=yes - , - LIBS="$old_LIBS" - ) -fi - -if test "x$have_iconv" != "xyes" ; then - # -liconv didn't work. Try giconv.h and -lgiconv. - # BSDs install this lib as libgiconv. - old_LIBS="$LIBS" - if test "${giconv_lib_a}" = ""; then - LIBS="-lgiconv $LIBS" - else - LIBS="${giconv_lib_a} $LIBS" - fi - AC_LINK_IFELSE([AC_LANG_SOURCE([#include <giconv.h> - int main(int argc,char **argv) { iconv_open("foo","bar"); }])] - , - AC_DEFINE(HAVE_ICONV,1, [Define if you have this function]) - AC_DEFINE(HAVE_GICONV,1, [Define if you have this function]) - AC_MSG_RESULT([[yes, -lgiconv]]) - , - AC_MSG_RESULT([[no]]) - LIBS="$old_LIBS" - ) -fi -else - AC_MSG_WARN(Use of iconv function disabled) -fi - -if test "x$have_iconv" != "xyes"; then - if test "x$with_iconv" = "xyes"; then - AC_MSG_ERROR([iconv requested but not found]) - fi -fi +dnl Check for ICONV support +AM_ICONV +photorec_LDADD="$LIBICONV $photorec_LDADD" +qphotorec_LDADD="$LIBICONV $qphotorec_LDADD" +testdisk_LDADD="$LIBICONV $testdisk_LDADD" AC_CHECK_HEADERS(sys/mount.h,,, [[ @@ -738,6 +668,56 @@ if test "${ac_cv_c_ntfs_mbstoucs_have_two_arguments}" != "no"; then AC_DEFINE([NTFS_MBSTOUCS_HAVE_TWO_ARGUMENTS], 1, [Define if ntfs_mbstoucs takes two parameters.]) fi +AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ +#ifdef HAVE_LIBNTFS +#include <ntfs/device.h> +#endif +#ifdef HAVE_LIBNTFS3G +#include <ntfs-3g/types.h> +#include <ntfs-3g/device.h> +#endif + +static int ntfs_device_testdisk_io_ioctl(struct ntfs_device *dev, int request, void *argp) +{ + return -1; +} +]], +[[ +struct ntfs_device_operations ntfs_device_testdisk_io_ops = { + .ioctl = &ntfs_device_testdisk_io_ioctl, +}; + ]])], + [ac_cv_c_ntfs_device_operations_ioctl_int=yes], + [ac_cv_c_ntfs_device_operations_ioctl_int=no]) +if test "${ac_cv_c_ntfs_device_operations_ioctl_int}" != "no"; then + AC_DEFINE([NTFS_DEVICE_OPERATIONS_IOCTL_INT], 1, [Define if request is an int.]) +fi + +AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ +#ifdef HAVE_LIBNTFS +#include <ntfs/device.h> +#endif +#ifdef HAVE_LIBNTFS3G +#include <ntfs-3g/types.h> +#include <ntfs-3g/device.h> +#endif + +static int ntfs_device_testdisk_io_ioctl(struct ntfs_device *dev, unsigned long request, void *argp) +{ + return -1; +} +]], +[[ +struct ntfs_device_operations ntfs_device_testdisk_io_ops = { + .ioctl = &ntfs_device_testdisk_io_ioctl, +}; + ]])], + [ac_cv_c_ntfs_device_operations_ioctl_ul=yes], + [ac_cv_c_ntfs_device_operations_ioctl_ul=no]) +if test "${ac_cv_c_ntfs_device_operations_ioctl_ul}" != "no"; then + AC_DEFINE([NTFS_DEVICE_OPERATIONS_IOCTL_UL], 1, [Define if request is an unsigned long.]) +fi + if test "x$use_reiserfs" != "xno"; then if test "x$with_reiserfs" != "xno"; then AC_CHECK_LIB(reiserfs,libreiserfs_get_version,[ diff --git a/src/exfat_dir.c b/src/exfat_dir.c index 7cdfc147..dd7c400b 100644 --- a/src/exfat_dir.c +++ b/src/exfat_dir.c @@ -90,7 +90,7 @@ static int exfat_ucstoutf8(iconv_t cd, const unsigned char *ins, const unsigned inb_left = ins_len; outb_left = outs_len - 1; // reserve 1 byte for NUL - if (iconv(cd, (char **)&inp, &inb_left, &outp, &outb_left) == (size_t)(-1)) + if (iconv(cd, (ICONV_CONST char **)&inp, &inb_left, &outp, &outb_left) == (size_t)(-1)) { // Regardless of the value of errno log_error("exfat_ucstoutf8: iconv failed %s\n", strerror(errno)); diff --git a/src/ntfs_dir.c b/src/ntfs_dir.c index d6fc559f..379e93f5 100644 --- a/src/ntfs_dir.c +++ b/src/ntfs_dir.c @@ -108,7 +108,7 @@ extern struct ntfs_device_operations ntfs_device_testdisk_io_ops; extern int ntfs_readdir(ntfs_inode *dir_ni, s64 *pos, void *dirent, ntfs_filldir_t filldir); -static int ntfs_td_list_entry( struct ntfs_dir_struct *ls, const ntfschar *name, +static int ntfs_td_list_entry( struct ntfs_dir_struct *ls, ntfschar *name, const int name_len, const int name_type, const s64 pos, const MFT_REF mref, const unsigned dt_type); static int ntfs_dir(disk_t *disk_car, const partition_t *partition, dir_data_t *dir_data, const unsigned long int cluster, file_info_t *dir_list); @@ -139,21 +139,21 @@ static int index_get_size(ntfs_inode *inode) } #ifdef HAVE_ICONV -static int ntfs_ucstoutf8(iconv_t cd, const ntfschar *ins, const int ins_len, char **outs, const int outs_len) +static int ntfs_ucstoutf8(iconv_t cd, char *ins, const int ins_len, char **outs, const int outs_len) { - const char *inp; + char *inp; char *outp; size_t inb_left, outb_left; if (cd == (iconv_t)(-1)) return -1; outp = *outs; - inp = (const char *) ins; + inp = (char *) ins; inb_left = ins_len << 1; // ntfschar is 16-bit outb_left = outs_len - 1; // reserve 1 byte for NUL *outp = '\0'; - if (iconv(cd, (char**)&inp, &inb_left, &outp, &outb_left) == (size_t)(-1)) + if (iconv(cd, (ICONV_CONST char**)&inp, &inb_left, &outp, &outb_left) == (size_t)(-1)) { // Regardless of the value of errno log_error("ntfs_ucstoutf8: iconv failed\n"); @@ -168,7 +168,7 @@ static int ntfs_ucstoutf8(iconv_t cd, const ntfschar *ins, const int ins_len, ch * ntfs_td_list_entry * FIXME: Should we print errors as we go along? (AIA) */ -static int ntfs_td_list_entry( struct ntfs_dir_struct *ls, const ntfschar *name, +static int ntfs_td_list_entry( struct ntfs_dir_struct *ls, ntfschar *name, const int name_len, const int name_type, const s64 pos, const MFT_REF mref, const unsigned dt_type) { @@ -189,7 +189,7 @@ static int ntfs_td_list_entry( struct ntfs_dir_struct *ls, const ntfschar *name } #ifdef HAVE_ICONV - if (ntfs_ucstoutf8(ls->cd, name, name_len, &filename, MAX_PATH) < 0 && + if (ntfs_ucstoutf8(ls->cd, (char *)name, name_len, &filename, MAX_PATH) < 0 && ntfs_ucstombs (name, name_len, &filename, MAX_PATH) < 0) { log_error("Cannot represent filename in current locale.\n"); goto freefn; diff --git a/src/ntfs_io.c b/src/ntfs_io.c index 7e60e2c4..09ea38cc 100644 --- a/src/ntfs_io.c +++ b/src/ntfs_io.c @@ -159,7 +159,7 @@ static int ntfs_device_testdisk_io_stat(struct ntfs_device *dev, struct stat *bu return -1; } -#ifdef HAVE_LIBNTFS +#ifdef NTFS_DEVICE_OPERATIONS_IOCTL_INT static int ntfs_device_testdisk_io_ioctl(struct ntfs_device *dev, int request, void *argp) { @@ -169,7 +169,7 @@ static int ntfs_device_testdisk_io_ioctl(struct ntfs_device *dev, int request, #endif return -1; } -#else +#elif defined(NTFS_DEVICE_OPERATIONS_IOCTL_UL) static int ntfs_device_testdisk_io_ioctl(struct ntfs_device *dev, unsigned long request, void *argp) { |