ntfs-3g-2026.2.25/0000775000175000017500000000000015152260235007057 5ntfs-3g-2026.2.25/config.sub0000755000175000017500000011544115152260212010761 #! /bin/sh # Configuration validation subroutine script. # Copyright 1992-2024 Free Software Foundation, Inc. # shellcheck disable=SC2006,SC2268,SC2162 # see below for rationale timestamp='2024-05-27' # This file 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 3 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; if not, see . # # As a special exception to the GNU General Public License, if you # distribute this file as part of a program that contains a # configuration script generated by Autoconf, you may include it under # the same distribution terms that you use for the rest of that # program. This Exception is an additional permission under section 7 # of the GNU General Public License, version 3 ("GPLv3"). # Please send patches to . # # Configuration subroutine to validate and canonicalize a configuration type. # Supply the specified configuration type as an argument. # If it is invalid, we print an error message on stderr and exit with code 1. # Otherwise, we print the canonical config type on stdout and succeed. # You can get the latest version of this script from: # https://git.savannah.gnu.org/cgit/config.git/plain/config.sub # This file is supposed to be the same for all GNU packages # and recognize all the CPU types, system types and aliases # that are meaningful with *any* GNU software. # Each package is responsible for reporting which valid configurations # it does not support. The user should be able to distinguish # a failure to support a valid configuration from a meaningless # configuration. # The goal of this file is to map all the various variations of a given # machine specification into a single specification in the form: # CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM # or in some cases, the newer four-part form: # CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM # It is wrong to echo any other type of specification. # The "shellcheck disable" line above the timestamp inhibits complaints # about features and limitations of the classic Bourne shell that were # superseded or lifted in POSIX. However, this script identifies a wide # variety of pre-POSIX systems that do not have POSIX shells at all, and # even some reasonably current systems (Solaris 10 as case-in-point) still # have a pre-POSIX /bin/sh. me=`echo "$0" | sed -e 's,.*/,,'` usage="\ Usage: $0 [OPTION] CPU-MFR-OPSYS or ALIAS Canonicalize a configuration name. Options: -h, --help print this help, then exit -t, --time-stamp print date of last modification, then exit -v, --version print version number, then exit Report bugs and patches to ." version="\ GNU config.sub ($timestamp) Copyright 1992-2024 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." help=" Try '$me --help' for more information." # Parse command line while test $# -gt 0 ; do case $1 in --time-stamp | --time* | -t ) echo "$timestamp" ; exit ;; --version | -v ) echo "$version" ; exit ;; --help | --h* | -h ) echo "$usage"; exit ;; -- ) # Stop option processing shift; break ;; - ) # Use stdin as input. break ;; -* ) echo "$me: invalid option $1$help" >&2 exit 1 ;; *local*) # First pass through any local machine types. echo "$1" exit ;; * ) break ;; esac done case $# in 0) echo "$me: missing argument$help" >&2 exit 1;; 1) ;; *) echo "$me: too many arguments$help" >&2 exit 1;; esac # Split fields of configuration type saved_IFS=$IFS IFS="-" read field1 field2 field3 field4 <&2 exit 1 ;; *-*-*-*) basic_machine=$field1-$field2 basic_os=$field3-$field4 ;; *-*-*) # Ambiguous whether COMPANY is present, or skipped and KERNEL-OS is two # parts maybe_os=$field2-$field3 case $maybe_os in cloudabi*-eabi* \ | kfreebsd*-gnu* \ | knetbsd*-gnu* \ | kopensolaris*-gnu* \ | linux-* \ | managarm-* \ | netbsd*-eabi* \ | netbsd*-gnu* \ | nto-qnx* \ | os2-emx* \ | rtmk-nova* \ | storm-chaos* \ | uclinux-gnu* \ | uclinux-uclibc* \ | windows-* ) basic_machine=$field1 basic_os=$maybe_os ;; android-linux) basic_machine=$field1-unknown basic_os=linux-android ;; *) basic_machine=$field1-$field2 basic_os=$field3 ;; esac ;; *-*) case $field1-$field2 in # Shorthands that happen to contain a single dash convex-c[12] | convex-c3[248]) basic_machine=$field2-convex basic_os= ;; decstation-3100) basic_machine=mips-dec basic_os= ;; *-*) # Second component is usually, but not always the OS case $field2 in # Do not treat sunos as a manufacturer sun*os*) basic_machine=$field1 basic_os=$field2 ;; # Manufacturers 3100* \ | 32* \ | 3300* \ | 3600* \ | 7300* \ | acorn \ | altos* \ | apollo \ | apple \ | atari \ | att* \ | axis \ | be \ | bull \ | cbm \ | ccur \ | cisco \ | commodore \ | convergent* \ | convex* \ | cray \ | crds \ | dec* \ | delta* \ | dg \ | digital \ | dolphin \ | encore* \ | gould \ | harris \ | highlevel \ | hitachi* \ | hp \ | ibm* \ | intergraph \ | isi* \ | knuth \ | masscomp \ | microblaze* \ | mips* \ | motorola* \ | ncr* \ | news \ | next \ | ns \ | oki \ | omron* \ | pc533* \ | rebel \ | rom68k \ | rombug \ | semi \ | sequent* \ | siemens \ | sgi* \ | siemens \ | sim \ | sni \ | sony* \ | stratus \ | sun \ | sun[234]* \ | tektronix \ | tti* \ | ultra \ | unicom* \ | wec \ | winbond \ | wrs) basic_machine=$field1-$field2 basic_os= ;; zephyr*) basic_machine=$field1-unknown basic_os=$field2 ;; *) basic_machine=$field1 basic_os=$field2 ;; esac ;; esac ;; *) # Convert single-component short-hands not valid as part of # multi-component configurations. case $field1 in 386bsd) basic_machine=i386-pc basic_os=bsd ;; a29khif) basic_machine=a29k-amd basic_os=udi ;; adobe68k) basic_machine=m68010-adobe basic_os=scout ;; alliant) basic_machine=fx80-alliant basic_os= ;; altos | altos3068) basic_machine=m68k-altos basic_os= ;; am29k) basic_machine=a29k-none basic_os=bsd ;; amdahl) basic_machine=580-amdahl basic_os=sysv ;; amiga) basic_machine=m68k-unknown basic_os= ;; amigaos | amigados) basic_machine=m68k-unknown basic_os=amigaos ;; amigaunix | amix) basic_machine=m68k-unknown basic_os=sysv4 ;; apollo68) basic_machine=m68k-apollo basic_os=sysv ;; apollo68bsd) basic_machine=m68k-apollo basic_os=bsd ;; aros) basic_machine=i386-pc basic_os=aros ;; aux) basic_machine=m68k-apple basic_os=aux ;; balance) basic_machine=ns32k-sequent basic_os=dynix ;; blackfin) basic_machine=bfin-unknown basic_os=linux ;; cegcc) basic_machine=arm-unknown basic_os=cegcc ;; cray) basic_machine=j90-cray basic_os=unicos ;; crds | unos) basic_machine=m68k-crds basic_os= ;; da30) basic_machine=m68k-da30 basic_os= ;; decstation | pmax | pmin | dec3100 | decstatn) basic_machine=mips-dec basic_os= ;; delta88) basic_machine=m88k-motorola basic_os=sysv3 ;; dicos) basic_machine=i686-pc basic_os=dicos ;; djgpp) basic_machine=i586-pc basic_os=msdosdjgpp ;; ebmon29k) basic_machine=a29k-amd basic_os=ebmon ;; es1800 | OSE68k | ose68k | ose | OSE) basic_machine=m68k-ericsson basic_os=ose ;; gmicro) basic_machine=tron-gmicro basic_os=sysv ;; go32) basic_machine=i386-pc basic_os=go32 ;; h8300hms) basic_machine=h8300-hitachi basic_os=hms ;; h8300xray) basic_machine=h8300-hitachi basic_os=xray ;; h8500hms) basic_machine=h8500-hitachi basic_os=hms ;; harris) basic_machine=m88k-harris basic_os=sysv3 ;; hp300 | hp300hpux) basic_machine=m68k-hp basic_os=hpux ;; hp300bsd) basic_machine=m68k-hp basic_os=bsd ;; hppaosf) basic_machine=hppa1.1-hp basic_os=osf ;; hppro) basic_machine=hppa1.1-hp basic_os=proelf ;; i386mach) basic_machine=i386-mach basic_os=mach ;; isi68 | isi) basic_machine=m68k-isi basic_os=sysv ;; m68knommu) basic_machine=m68k-unknown basic_os=linux ;; magnum | m3230) basic_machine=mips-mips basic_os=sysv ;; merlin) basic_machine=ns32k-utek basic_os=sysv ;; mingw64) basic_machine=x86_64-pc basic_os=mingw64 ;; mingw32) basic_machine=i686-pc basic_os=mingw32 ;; mingw32ce) basic_machine=arm-unknown basic_os=mingw32ce ;; monitor) basic_machine=m68k-rom68k basic_os=coff ;; morphos) basic_machine=powerpc-unknown basic_os=morphos ;; moxiebox) basic_machine=moxie-unknown basic_os=moxiebox ;; msdos) basic_machine=i386-pc basic_os=msdos ;; msys) basic_machine=i686-pc basic_os=msys ;; mvs) basic_machine=i370-ibm basic_os=mvs ;; nacl) basic_machine=le32-unknown basic_os=nacl ;; ncr3000) basic_machine=i486-ncr basic_os=sysv4 ;; netbsd386) basic_machine=i386-pc basic_os=netbsd ;; netwinder) basic_machine=armv4l-rebel basic_os=linux ;; news | news700 | news800 | news900) basic_machine=m68k-sony basic_os=newsos ;; news1000) basic_machine=m68030-sony basic_os=newsos ;; necv70) basic_machine=v70-nec basic_os=sysv ;; nh3000) basic_machine=m68k-harris basic_os=cxux ;; nh[45]000) basic_machine=m88k-harris basic_os=cxux ;; nindy960) basic_machine=i960-intel basic_os=nindy ;; mon960) basic_machine=i960-intel basic_os=mon960 ;; nonstopux) basic_machine=mips-compaq basic_os=nonstopux ;; os400) basic_machine=powerpc-ibm basic_os=os400 ;; OSE68000 | ose68000) basic_machine=m68000-ericsson basic_os=ose ;; os68k) basic_machine=m68k-none basic_os=os68k ;; paragon) basic_machine=i860-intel basic_os=osf ;; parisc) basic_machine=hppa-unknown basic_os=linux ;; psp) basic_machine=mipsallegrexel-sony basic_os=psp ;; pw32) basic_machine=i586-unknown basic_os=pw32 ;; rdos | rdos64) basic_machine=x86_64-pc basic_os=rdos ;; rdos32) basic_machine=i386-pc basic_os=rdos ;; rom68k) basic_machine=m68k-rom68k basic_os=coff ;; sa29200) basic_machine=a29k-amd basic_os=udi ;; sei) basic_machine=mips-sei basic_os=seiux ;; sequent) basic_machine=i386-sequent basic_os= ;; sps7) basic_machine=m68k-bull basic_os=sysv2 ;; st2000) basic_machine=m68k-tandem basic_os= ;; stratus) basic_machine=i860-stratus basic_os=sysv4 ;; sun2) basic_machine=m68000-sun basic_os= ;; sun2os3) basic_machine=m68000-sun basic_os=sunos3 ;; sun2os4) basic_machine=m68000-sun basic_os=sunos4 ;; sun3) basic_machine=m68k-sun basic_os= ;; sun3os3) basic_machine=m68k-sun basic_os=sunos3 ;; sun3os4) basic_machine=m68k-sun basic_os=sunos4 ;; sun4) basic_machine=sparc-sun basic_os= ;; sun4os3) basic_machine=sparc-sun basic_os=sunos3 ;; sun4os4) basic_machine=sparc-sun basic_os=sunos4 ;; sun4sol2) basic_machine=sparc-sun basic_os=solaris2 ;; sun386 | sun386i | roadrunner) basic_machine=i386-sun basic_os= ;; sv1) basic_machine=sv1-cray basic_os=unicos ;; symmetry) basic_machine=i386-sequent basic_os=dynix ;; t3e) basic_machine=alphaev5-cray basic_os=unicos ;; t90) basic_machine=t90-cray basic_os=unicos ;; toad1) basic_machine=pdp10-xkl basic_os=tops20 ;; tpf) basic_machine=s390x-ibm basic_os=tpf ;; udi29k) basic_machine=a29k-amd basic_os=udi ;; ultra3) basic_machine=a29k-nyu basic_os=sym1 ;; v810 | necv810) basic_machine=v810-nec basic_os=none ;; vaxv) basic_machine=vax-dec basic_os=sysv ;; vms) basic_machine=vax-dec basic_os=vms ;; vsta) basic_machine=i386-pc basic_os=vsta ;; vxworks960) basic_machine=i960-wrs basic_os=vxworks ;; vxworks68) basic_machine=m68k-wrs basic_os=vxworks ;; vxworks29k) basic_machine=a29k-wrs basic_os=vxworks ;; xbox) basic_machine=i686-pc basic_os=mingw32 ;; ymp) basic_machine=ymp-cray basic_os=unicos ;; *) basic_machine=$1 basic_os= ;; esac ;; esac # Decode 1-component or ad-hoc basic machines case $basic_machine in # Here we handle the default manufacturer of certain CPU types. It is in # some cases the only manufacturer, in others, it is the most popular. w89k) cpu=hppa1.1 vendor=winbond ;; op50n) cpu=hppa1.1 vendor=oki ;; op60c) cpu=hppa1.1 vendor=oki ;; ibm*) cpu=i370 vendor=ibm ;; orion105) cpu=clipper vendor=highlevel ;; mac | mpw | mac-mpw) cpu=m68k vendor=apple ;; pmac | pmac-mpw) cpu=powerpc vendor=apple ;; # Recognize the various machine names and aliases which stand # for a CPU type and a company and sometimes even an OS. 3b1 | 7300 | 7300-att | att-7300 | pc7300 | safari | unixpc) cpu=m68000 vendor=att ;; 3b*) cpu=we32k vendor=att ;; bluegene*) cpu=powerpc vendor=ibm basic_os=cnk ;; decsystem10* | dec10*) cpu=pdp10 vendor=dec basic_os=tops10 ;; decsystem20* | dec20*) cpu=pdp10 vendor=dec basic_os=tops20 ;; delta | 3300 | delta-motorola | 3300-motorola | motorola-delta | motorola-3300) cpu=m68k vendor=motorola ;; # This used to be dpx2*, but that gets the RS6000-based # DPX/20 and the x86-based DPX/2-100 wrong. See # https://oldskool.silicium.org/stations/bull_dpx20.htm # https://www.feb-patrimoine.com/english/bull_dpx2.htm # https://www.feb-patrimoine.com/english/unix_and_bull.htm dpx2 | dpx2[23]00 | dpx2[23]xx) cpu=m68k vendor=bull ;; dpx2100 | dpx21xx) cpu=i386 vendor=bull ;; dpx20) cpu=rs6000 vendor=bull ;; encore | umax | mmax) cpu=ns32k vendor=encore ;; elxsi) cpu=elxsi vendor=elxsi basic_os=${basic_os:-bsd} ;; fx2800) cpu=i860 vendor=alliant ;; genix) cpu=ns32k vendor=ns ;; h3050r* | hiux*) cpu=hppa1.1 vendor=hitachi basic_os=hiuxwe2 ;; hp3k9[0-9][0-9] | hp9[0-9][0-9]) cpu=hppa1.0 vendor=hp ;; hp9k2[0-9][0-9] | hp9k31[0-9]) cpu=m68000 vendor=hp ;; hp9k3[2-9][0-9]) cpu=m68k vendor=hp ;; hp9k6[0-9][0-9] | hp6[0-9][0-9]) cpu=hppa1.0 vendor=hp ;; hp9k7[0-79][0-9] | hp7[0-79][0-9]) cpu=hppa1.1 vendor=hp ;; hp9k78[0-9] | hp78[0-9]) # FIXME: really hppa2.0-hp cpu=hppa1.1 vendor=hp ;; hp9k8[67]1 | hp8[67]1 | hp9k80[24] | hp80[24] | hp9k8[78]9 | hp8[78]9 | hp9k893 | hp893) # FIXME: really hppa2.0-hp cpu=hppa1.1 vendor=hp ;; hp9k8[0-9][13679] | hp8[0-9][13679]) cpu=hppa1.1 vendor=hp ;; hp9k8[0-9][0-9] | hp8[0-9][0-9]) cpu=hppa1.0 vendor=hp ;; i*86v32) cpu=`echo "$1" | sed -e 's/86.*/86/'` vendor=pc basic_os=sysv32 ;; i*86v4*) cpu=`echo "$1" | sed -e 's/86.*/86/'` vendor=pc basic_os=sysv4 ;; i*86v) cpu=`echo "$1" | sed -e 's/86.*/86/'` vendor=pc basic_os=sysv ;; i*86sol2) cpu=`echo "$1" | sed -e 's/86.*/86/'` vendor=pc basic_os=solaris2 ;; j90 | j90-cray) cpu=j90 vendor=cray basic_os=${basic_os:-unicos} ;; iris | iris4d) cpu=mips vendor=sgi case $basic_os in irix*) ;; *) basic_os=irix4 ;; esac ;; miniframe) cpu=m68000 vendor=convergent ;; *mint | mint[0-9]* | *MiNT | *MiNT[0-9]*) cpu=m68k vendor=atari basic_os=mint ;; news-3600 | risc-news) cpu=mips vendor=sony basic_os=newsos ;; next | m*-next) cpu=m68k vendor=next ;; np1) cpu=np1 vendor=gould ;; op50n-* | op60c-*) cpu=hppa1.1 vendor=oki basic_os=proelf ;; pa-hitachi) cpu=hppa1.1 vendor=hitachi basic_os=hiuxwe2 ;; pbd) cpu=sparc vendor=tti ;; pbb) cpu=m68k vendor=tti ;; pc532) cpu=ns32k vendor=pc532 ;; pn) cpu=pn vendor=gould ;; power) cpu=power vendor=ibm ;; ps2) cpu=i386 vendor=ibm ;; rm[46]00) cpu=mips vendor=siemens ;; rtpc | rtpc-*) cpu=romp vendor=ibm ;; sde) cpu=mipsisa32 vendor=sde basic_os=${basic_os:-elf} ;; simso-wrs) cpu=sparclite vendor=wrs basic_os=vxworks ;; tower | tower-32) cpu=m68k vendor=ncr ;; vpp*|vx|vx-*) cpu=f301 vendor=fujitsu ;; w65) cpu=w65 vendor=wdc ;; w89k-*) cpu=hppa1.1 vendor=winbond basic_os=proelf ;; none) cpu=none vendor=none ;; leon|leon[3-9]) cpu=sparc vendor=$basic_machine ;; leon-*|leon[3-9]-*) cpu=sparc vendor=`echo "$basic_machine" | sed 's/-.*//'` ;; *-*) saved_IFS=$IFS IFS="-" read cpu vendor <&2 exit 1 ;; esac ;; esac # Here we canonicalize certain aliases for manufacturers. case $vendor in digital*) vendor=dec ;; commodore*) vendor=cbm ;; *) ;; esac # Decode manufacturer-specific aliases for certain operating systems. if test x"$basic_os" != x then # First recognize some ad-hoc cases, or perhaps split kernel-os, or else just # set os. obj= case $basic_os in gnu/linux*) kernel=linux os=`echo "$basic_os" | sed -e 's|gnu/linux|gnu|'` ;; os2-emx) kernel=os2 os=`echo "$basic_os" | sed -e 's|os2-emx|emx|'` ;; nto-qnx*) kernel=nto os=`echo "$basic_os" | sed -e 's|nto-qnx|qnx|'` ;; *-*) saved_IFS=$IFS IFS="-" read kernel os <&2 fi ;; *) echo "Invalid configuration '$1': OS '$os' not recognized" 1>&2 exit 1 ;; esac case $obj in aout* | coff* | elf* | pe*) ;; '') # empty is fine ;; *) echo "Invalid configuration '$1': Machine code format '$obj' not recognized" 1>&2 exit 1 ;; esac # Here we handle the constraint that a (synthetic) cpu and os are # valid only in combination with each other and nowhere else. case $cpu-$os in # The "javascript-unknown-ghcjs" triple is used by GHC; we # accept it here in order to tolerate that, but reject any # variations. javascript-ghcjs) ;; javascript-* | *-ghcjs) echo "Invalid configuration '$1': cpu '$cpu' is not valid with os '$os$obj'" 1>&2 exit 1 ;; esac # As a final step for OS-related things, validate the OS-kernel combination # (given a valid OS), if there is a kernel. case $kernel-$os-$obj in linux-gnu*- | linux-android*- | linux-dietlibc*- | linux-llvm*- \ | linux-mlibc*- | linux-musl*- | linux-newlib*- \ | linux-relibc*- | linux-uclibc*- | linux-ohos*- ) ;; uclinux-uclibc*- | uclinux-gnu*- ) ;; managarm-mlibc*- | managarm-kernel*- ) ;; windows*-msvc*-) ;; -dietlibc*- | -llvm*- | -mlibc*- | -musl*- | -newlib*- | -relibc*- \ | -uclibc*- ) # These are just libc implementations, not actual OSes, and thus # require a kernel. echo "Invalid configuration '$1': libc '$os' needs explicit kernel." 1>&2 exit 1 ;; -kernel*- ) echo "Invalid configuration '$1': '$os' needs explicit kernel." 1>&2 exit 1 ;; *-kernel*- ) echo "Invalid configuration '$1': '$kernel' does not support '$os'." 1>&2 exit 1 ;; *-msvc*- ) echo "Invalid configuration '$1': '$os' needs 'windows'." 1>&2 exit 1 ;; kfreebsd*-gnu*- | knetbsd*-gnu*- | netbsd*-gnu*- | kopensolaris*-gnu*-) ;; vxworks-simlinux- | vxworks-simwindows- | vxworks-spe-) ;; nto-qnx*-) ;; os2-emx-) ;; rtmk-nova-) ;; *-eabi*- | *-gnueabi*-) ;; none--*) # None (no kernel, i.e. freestanding / bare metal), # can be paired with an machine code file format ;; -*-) # Blank kernel with real OS is always fine. ;; --*) # Blank kernel and OS with real machine code file format is always fine. ;; *-*-*) echo "Invalid configuration '$1': Kernel '$kernel' not known to work with OS '$os'." 1>&2 exit 1 ;; esac # Here we handle the case where we know the os, and the CPU type, but not the # manufacturer. We pick the logical manufacturer. case $vendor in unknown) case $cpu-$os in *-riscix*) vendor=acorn ;; *-sunos* | *-solaris*) vendor=sun ;; *-cnk* | *-aix*) vendor=ibm ;; *-beos*) vendor=be ;; *-hpux*) vendor=hp ;; *-mpeix*) vendor=hp ;; *-hiux*) vendor=hitachi ;; *-unos*) vendor=crds ;; *-dgux*) vendor=dg ;; *-luna*) vendor=omron ;; *-genix*) vendor=ns ;; *-clix*) vendor=intergraph ;; *-mvs* | *-opened*) vendor=ibm ;; *-os400*) vendor=ibm ;; s390-* | s390x-*) vendor=ibm ;; *-ptx*) vendor=sequent ;; *-tpf*) vendor=ibm ;; *-vxsim* | *-vxworks* | *-windiss*) vendor=wrs ;; *-aux*) vendor=apple ;; *-hms*) vendor=hitachi ;; *-mpw* | *-macos*) vendor=apple ;; *-*mint | *-mint[0-9]* | *-*MiNT | *-MiNT[0-9]*) vendor=atari ;; *-vos*) vendor=stratus ;; esac ;; esac echo "$cpu-$vendor${kernel:+-$kernel}${os:+-$os}${obj:+-$obj}" exit # Local variables: # eval: (add-hook 'before-save-hook 'time-stamp) # time-stamp-start: "timestamp='" # time-stamp-format: "%:y-%02m-%02d" # time-stamp-end: "'" # End: ntfs-3g-2026.2.25/configure.ac0000664000175000017500000005024515152260173011274 # # configure.ac - Source file to generate "./configure" to prepare package for # compilation. # # Copyright (c) 2000-2013 Anton Altaparmakov # Copyright (c) 2003 Jan Kratochvil # Copyright (c) 2005-2009 Szabolcs Szakacsits # Copyright (C) 2007-2008 Alon Bar-Lev # # This program/include file 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/include file 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 # Autoconf AC_PREREQ(2.59) AC_INIT([ntfs-3g],[2026.2.25],[ntfs-3g-devel@lists.sf.net]) LIBNTFS_3G_VERSION="89" AC_CONFIG_SRCDIR([src/ntfs-3g.c]) # Environment AC_CANONICAL_HOST AC_CANONICAL_TARGET # Automake AM_INIT_AUTOMAKE([]) AC_CONFIG_HEADERS([config.h]) AC_CONFIG_MACRO_DIR([m4]) AM_MAINTAINER_MODE # Options AC_ARG_ENABLE( [debug], [AS_HELP_STRING([--enable-debug],[enable debugging code and output])], , [enable_debug="no"] ) AC_ARG_ENABLE( [warnings], [AS_HELP_STRING([--enable-warnings],[enable lots of compiler warnings])], , [enable_warnings="no"] ) AC_ARG_ENABLE( [pedantic], [AS_HELP_STRING([--enable-pedantic],[enable compile pedantic mode])], , [enable_pedantic="no"] ) AC_ARG_ENABLE( [really-static], [AS_HELP_STRING([--enable-really-static],[create fully static binaries])], , [enable_really_static="no"] ) AC_ARG_ENABLE( [mount-helper], [AS_HELP_STRING([--enable-mount-helper],[install mount helper @<:@default=enabled for linux@:>@])], , [ case "${target_os}" in linux*) enable_mount_helper="yes" ;; *) enable_mount_helper="no" ;; esac ] ) AC_ARG_ENABLE( [ldscript], [AS_HELP_STRING([--enable-ldscript],[use ldscript instead of .so symlink])], , [enable_ldscript="no"] ) AC_ARG_ENABLE( [ldconfig], [AS_HELP_STRING([--disable-ldconfig],[do not update dynamic linker cache using ldconfig])], , [enable_ldconfig="yes"] ) AC_ARG_ENABLE( [library], [AS_HELP_STRING([--disable-library],[do not install libntfs-3g but link it into ntfs-3g])], , [enable_library="yes"] ) AC_ARG_ENABLE( [mtab], [AS_HELP_STRING([--disable-mtab],[disable and ignore usage of /etc/mtab])], , [enable_mtab="yes"] ) AC_ARG_ENABLE( [posix-acls], [AS_HELP_STRING([--enable-posix-acls],[enable POSIX ACL support])], , [enable_posix_acls="no"] ) AC_ARG_ENABLE( [xattr-mappings], [AS_HELP_STRING([--enable-xattr-mappings],[enable system extended attributes mappings])], , [enable_xattr_mappings="no"] ) AC_ARG_ENABLE( [plugins], [AS_HELP_STRING([--disable-plugins], [Disable external reparse point plugins for the ntfs-3g FUSE driver])], [if test x${enableval} = "xyes"; then disable_plugins="no"; fi], [disable_plugins="no"] ) AC_ARG_ENABLE( [device-default-io-ops], [AS_HELP_STRING([--disable-device-default-io-ops],[install default IO ops])], , [enable_device_default_io_ops="yes"] ) AC_ARG_ENABLE( [ntfs-3g], [AS_HELP_STRING([--disable-ntfs-3g],[disable the ntfs-3g FUSE driver])], , [enable_ntfs_3g="yes"] ) AC_ARG_ENABLE( [ntfsprogs], [AS_HELP_STRING([--disable-ntfsprogs],[disable ntfsprogs utilities (default=no)])], , [enable_ntfsprogs="yes"] ) AC_ARG_ENABLE(crypto, AS_HELP_STRING(--enable-crypto,enable crypto related code and utilities (default=no)), , enable_crypto=no ) AC_ARG_ENABLE( [extras], [AS_HELP_STRING([--enable-extras],[enable extra ntfsprogs utilities (default=no)])], , [enable_extras="no"] ) AC_ARG_ENABLE( [quarantined], [AS_HELP_STRING([--enable-quarantined],[enable quarantined ntfsprogs utilities (default=no)])], , [enable_quarantined="no"] ) AC_ARG_ENABLE( [nfconv], [AS_HELP_STRING([--disable-nfconv],[disable the 'nfconv' patch, which adds support for Unicode normalization form conversion when built on Mac OS X @<:@default=enabled for Mac OS X@:>@])], [enable_nfconv="no"], [ case "${target_os}" in darwin*) enable_nfconv="yes" ;; *) enable_nfconv="no" ;; esac ] ) # pthread_rwlock_t requires _GNU_SOURCE AC_GNU_SOURCE # Programs AC_PROG_CC(gcc cc) AC_PROG_LN_S AM_PROG_CC_C_O ifdef( [LT_INIT], [LT_INIT], [AC_PROG_LIBTOOL] ) AC_PROG_INSTALL PKG_PROG_PKG_CONFIG AC_PATH_PROG([MV], [mv]) AC_PATH_PROG([RM], [rm]) AC_PATH_PROG([SED], [sed]) AC_ARG_VAR([LDCONFIG], [ldconfig utility]) AC_PATH_PROG([LDCONFIG], [ldconfig], [true], [/sbin /usr/sbin $PATH]) # Environment AC_MSG_CHECKING([Windows OS]) case "${target}" in *-mingw32*|*-winnt*|*-cygwin*) AC_MSG_RESULT([yes]) WINDOWS="yes" AC_DEFINE( [WINDOWS], [1], [Define to 1 if this is a Windows OS] ) ;; *) AC_MSG_RESULT([no]) WINDOWS="no" ;; esac if test "x${enable_ntfs_3g}" != "xyes"; then with_fuse="none" elif test "x${with_fuse}" = "x"; then AC_MSG_CHECKING([fuse compatibility]) case "${target_os}" in linux*|solaris*) AC_ARG_WITH( [fuse], [AS_HELP_STRING([--with-fuse=],[Select FUSE library: internal or external @<:@default=internal@:>@])], , [with_fuse="internal"] ) ;; darwin*|netbsd*|kfreebsd*-gnu) with_fuse="external" ;; freebsd*) AC_MSG_ERROR([Please see FreeBSD support at http://www.freshports.org/sysutils/fusefs-ntfs]) ;; *) AC_MSG_ERROR([ntfs-3g can be built for Linux, FreeBSD, Mac OS X, NetBSD, and Solaris only.]) ;; esac AC_MSG_RESULT([${with_fuse}]) fi case "${target_os}" in solaris*) if test "x$GCC" != "xyes" ; then AC_MSG_ERROR([ntfs-3g can be built only with gcc on Solaris. Install it by 'pkg install gcc-dev' and retry.)]) fi ;; esac if test "${enable_ldscript}" = "yes"; then AC_MSG_CHECKING([Output format]) OUTPUT_FORMAT="$(${CC} ${CFLAGS} ${LDFLAGS} -Wl,--verbose 2>&1 | ${SED} -n 's/^OUTPUT_FORMAT("\([[^"]]*\)",.*/\1/p')" if test -z "${OUTPUT_FORMAT}"; then AC_MSG_RESULT([None]) else AC_MSG_RESULT([${OUTPUT_FORMAT}]) OUTPUT_FORMAT="OUTPUT_FORMAT ( ${OUTPUT_FORMAT} )" fi fi # Libraries if test "${with_fuse}" = "internal"; then AC_CHECK_LIB( [pthread], [pthread_create], [LIBFUSE_LITE_LIBS="${LIBFUSE_LITE_LIBS} -lpthread"], [AC_MSG_ERROR([Cannot find pthread library])] ) AC_DEFINE( [_REENTRANT], [1], [Required define if using POSIX threads] ) # required so that we re-compile anything AC_DEFINE( [FUSE_INTERNAL], [1], [Define to 1 if using internal fuse] ) AC_MSG_CHECKING([Solaris OS]) AC_LANG_PUSH([C]) AC_COMPILE_IFELSE( [ AC_LANG_SOURCE( [[#if !((defined(sun) || defined(__sun)) && (defined(__SVR4) || defined(__svr4__)))]] [[#error "Not a Solaris system."]] [[#endif]] ) ], [ AC_MSG_RESULT([yes]) LIBFUSE_LITE_CFLAGS="${LIBFUSE_LITE_CFLAGS} -std=c99 -D__SOLARIS__ -D_XOPEN_SOURCE=600 -D__EXTENSIONS__" LIBFUSE_LITE_LIBS="${LIBFUSE_LITE_LIBS} -lxnet" ], [ AC_MSG_RESULT([no]) ] ) AC_LANG_POP([C]) elif test "${with_fuse}" = "external"; then if test -z "$PKG_CONFIG"; then AC_PATH_PROG(PKG_CONFIG, pkg-config, no) fi test "x${PKG_CONFIG}" = "xno" && AC_MSG_ERROR([pkg-config wasn't found! Please install from your vendor, or see http://pkg-config.freedesktop.org/wiki/]) # Libraries often install their metadata .pc files in directories # not searched by pkg-config. Let's workaround this. export PKG_CONFIG_PATH=${PKG_CONFIG_PATH}:/lib/pkgconfig:/usr/lib/pkgconfig:/opt/gnome/lib/pkgconfig:/usr/share/pkgconfig:/usr/local/lib/pkgconfig:$prefix/lib/pkgconfig:/opt/gnome/share/pkgconfig:/usr/local/share/pkgconfig PKG_CHECK_MODULES( [FUSE_MODULE], [fuse >= 2.6.0], , [ AC_MSG_ERROR([FUSE >= 2.6.0 was not found. Either older FUSE is still present, or FUSE is not fully installed (e.g. fuse, libfuse, libfuse2, libfuse-dev, etc packages). Source code: http://fuse.sf.net]) ] ) FUSE_LIB_PATH=`$PKG_CONFIG --libs-only-L fuse | sed -e 's,/[/]*,/,g' -e 's,[ ]*$,,'` fi # Autodetect whether we can build crypto stuff or not. compile_crypto=false if test "$enable_crypto" != "no"; then have_libgcrypt=false AM_PATH_LIBGCRYPT(1.2.2, [ have_libgcrypt=true ], [ if test "$enable_crypto" = "yes"; then AC_MSG_ERROR([ntfsprogs crypto code requires the gcrypt library.]) else AC_MSG_WARN([ntfsprogs crypto code requires the gcrypt library.]) fi ]) have_libgnutls=false PKG_CHECK_MODULES(GNUTLS, gnutls >= 1.4.4, [ have_libgnutls=true ], if test "$enable_crypto" = "yes"; then AC_MSG_ERROR([ntfsprogs crypto code requires the gnutls library.]) else AC_MSG_WARN([ntfsprogs crypto code requires the gnutls library.]) fi ) if test "$have_libgcrypt" = "true"; then if test "$have_libgnutls" = "true"; then compile_crypto=true AC_DEFINE([ENABLE_CRYPTO], 1, [Define this to 1 if you want to enable support of encrypted files in libntfs and utilities.]) fi fi fi AM_CONDITIONAL(ENABLE_CRYPTO, $compile_crypto) # add --with-extra-includes and --with-extra-libs switch to ./configure all_libraries="$all_libraries $USER_LDFLAGS" all_includes="$all_includes $USER_INCLUDES" AC_SUBST(all_includes) AC_SUBST(all_libraries) # Specify support for generating DCE compliant UUIDs (aka GUIDs). We check if # uuid/uuid.h header is present and the uuid library is present that goes with # it and then check if uuid_generate() is present and usable. # # DCE UUIDs are enabled by default and can be disabled with the --disable-uuid # option to the configure script. AC_ARG_WITH(uuid, [ --with-uuid@<:@=PFX@:>@ generate DCE compliant UUIDs, with optional prefix to uuid library and headers @<:@default=detect@:>@ --without-uuid do not generate DCE compliant UUIDs], if test "$with_uuid" = "yes"; then extrapath=default elif test "$with_uuid" = "no"; then extrapath= else extrapath=$with_uuid fi, extrapath=default ) if test "x$extrapath" != "x"; then if test "x$extrapath" != "xdefault"; then MKNTFS_CPPFLAGS="$MKNTFS_CPPFLAGS -I$extrapath/include" MKNTFS_LIBS="$MKNTFS_LIBS -L$extrapath/lib" fi search_for_luuid="yes" AC_CHECK_HEADER([uuid/uuid.h], [], [ AC_MSG_WARN([ntfsprogs DCE compliant UUID generation code requires the uuid library.]) search_for_luuid="no" ], ) if test "x$search_for_luuid" != "xno"; then # Look for uuid_generate in the standard C library. AC_CHECK_FUNC([uuid_generate], [ AC_DEFINE([ENABLE_UUID], 1, [Define this to 1 if you want to enable generation of DCE compliant UUIDs.]) search_for_luuid="no" ], [], ) fi if test "x$search_for_luuid" != "xno"; then # Look for uuid_generate in the 'uuid' library. AC_CHECK_LIB([uuid], [uuid_generate], [ AC_DEFINE([ENABLE_UUID], 1, [Define this to 1 if you want to enable generation of DCE compliant UUIDs.]) MKNTFS_LIBS="$MKNTFS_LIBS -luuid" search_for_luuid="no" ], [], ) fi if test "x$search_for_luuid" != "xno"; then AC_MSG_WARN([ntfsprogs DCE compliant UUID generation code requires the uuid library.]) fi fi # Specify support for obtaining the correct BIOS legacy geometry needed for # Windows to boot in CHS mode. We check if hd.h header is present and the hd # library is present that goes with it and then check if the hd_list() function # is present and usable. # # Using the hd library is enabled by default and can be disabled with the # --disable-hd option to the configure script. AC_ARG_WITH(hd, [ --with-hd@<:@=PFX@:>@ use Windows compliant disk geometry, with optional prefix to hd library and headers @<:@default=detect@:>@ --without-hd do not use Windows compliant disk geometry], if test "$with_hd" = "yes"; then extrapath2=default elif test "$with_hd" = "no"; then extrapath2= else extrapath2=$with_hd fi, extrapath2=default ) if test "x$extrapath2" != "x"; then if test "x$extrapath2" != "xdefault"; then LIBNTFS_CPPFLAGS="$LIBNTFS_CPPFLAGS -I$extrapath2/include" LIBNTFS_LIBS="$LIBNTFS_LIBS -L$extrapath2/lib" fi AC_CHECK_HEADER([hd.h], AC_CHECK_LIB([hd], [hd_list], AC_DEFINE([ENABLE_HD], 1, [Define this to 1 if you want to enable use of Windows compliant disk geometry.]) LIBNTFS_LIBS="$LIBNTFS_LIBS -lhd" NTFSPROGS_STATIC_LIBS="$NTFSPROGS_STATIC_LIBS -lhd", AC_MSG_WARN([ntfsprogs Windows compliant geometry code requires the hd library.]), ), AC_MSG_WARN([ntfsprogs Windows compliant geometry code requires the hd library.]), ) fi # Checks for header files. AC_HEADER_STDC AC_HEADER_MAJOR AC_CHECK_HEADERS([ctype.h fcntl.h libgen.h libintl.h limits.h locale.h \ mntent.h stddef.h stdint.h stdlib.h stdio.h stdarg.h string.h \ strings.h errno.h time.h unistd.h utime.h wchar.h getopt.h features.h \ regex.h endian.h byteswap.h sys/byteorder.h sys/disk.h sys/endian.h \ sys/param.h sys/ioctl.h sys/mount.h sys/stat.h sys/types.h \ sys/vfs.h sys/statvfs.h linux/major.h linux/fd.h \ linux/fs.h inttypes.h linux/hdreg.h \ machine/endian.h windows.h syslog.h pwd.h malloc.h]) # Checks for typedefs, structures, and compiler characteristics. AC_HEADER_STDBOOL AC_C_BIGENDIAN( , [ AC_DEFINE( [WORDS_LITTLEENDIAN], [1], [Define to 1 if your processor stores words with the least significant byte first (like Intel and VAX, unlike Motorola and SPARC).] ) ] , ) AC_C_CONST AC_C_INLINE AC_TYPE_OFF_T AC_TYPE_SIZE_T AC_STRUCT_ST_BLOCKS AC_CHECK_MEMBERS([struct stat.st_rdev]) AC_CHECK_MEMBERS([struct stat.st_atim]) AC_CHECK_MEMBERS([struct stat.st_atimespec]) AC_CHECK_MEMBERS([struct stat.st_atimensec]) # For the 'nfconv' patch (Mac OS X only): case "${target_os}" in darwin*) if test "${enable_nfconv}" = "yes"; then AC_CHECK_HEADER( [CoreFoundation/CoreFoundation.h], [ LDFLAGS="${LDFLAGS} -framework CoreFoundation" AC_DEFINE( [ENABLE_NFCONV], [1], [Define to 1 if the nfconv patch should be enabled] ) ], AC_MSG_ERROR([[Cannot find CoreFoundation required for 'nfconv' functionality Mac OS X. You may use the --disable-nfconv 'configure' option to avoid this error.]]) ) fi ;; esac # Checks for library functions. AC_FUNC_GETMNTENT AC_FUNC_MBRTOWC AC_FUNC_MEMCMP AC_FUNC_STAT AC_FUNC_STRFTIME AC_FUNC_UTIME_NULL AC_FUNC_VPRINTF AC_CHECK_FUNCS([ \ atexit basename daemon dup2 fdatasync ffs getopt_long hasmntopt \ mbsinit memmove memset realpath regcomp setlocale setxattr \ strcasecmp strchr strdup strerror strnlen strsep strtol strtoul \ sysconf utime utimensat gettimeofday clock_gettime fork memcpy random snprintf \ ]) AC_SYS_LARGEFILE # The dlopen API might be in libc or in libdl. Check libc first, then # fall back to libdl. LIBDL="" if test "x${disable_external_plugins}" = "xno"; then AC_CHECK_LIB(c, dlopen, , [AC_CHECK_LIB(dl, dlopen, [LIBDL="-ldl"], [AC_MSG_ERROR(["Unable to find libdl (required for external plugin support)"])])]) fi AC_SUBST([LIBDL]) if test "$GCC" = "yes" ; then # We add -Wall to enable some compiler warnings. CFLAGS="${CFLAGS} -Wall" fi if test "${enable_pedantic}" = "yes"; then enable_warnings="yes" CFLAGS="${CFLAGS} -pedantic" fi if test "${enable_warnings}" = "yes"; then CFLAGS="${CFLAGS} -W -Wall -Waggregate-return -Wbad-function-cast -Wcast-align -Wcast-qual -Wdisabled-optimization -Wdiv-by-zero -Wfloat-equal -Winline -Wmissing-declarations -Wmissing-format-attribute -Wmissing-noreturn -Wmissing-prototypes -Wmultichar -Wnested-externs -Wpointer-arith -Wredundant-decls -Wshadow -Wsign-compare -Wstrict-prototypes -Wundef -Wwrite-strings -Wformat -Wformat-security -Wuninitialized" fi if test "${enable_debug}" = "yes"; then CFLAGS="${CFLAGS} -ggdb3 -DDEBUG" AC_DEFINE( [ENABLE_DEBUG], [1], [Define to 1 if debug should be enabled] ) fi test "${enable_device_default_io_ops}" = "no" && AC_DEFINE( [NO_NTFS_DEVICE_DEFAULT_IO_OPS], [1], [Don't use default IO ops] ) test "${enable_mtab}" = "no" && AC_DEFINE([IGNORE_MTAB], [1], [Don't update /etc/mtab]) test "${enable_posix_acls}" != "no" && AC_DEFINE([POSIXACLS], [1], [POSIX ACL support]) test "${enable_xattr_mappings}" != "no" && AC_DEFINE([XATTR_MAPPINGS], [1], [system extended attributes mappings]) test "${disable_plugins}" != "no" && AC_DEFINE([DISABLE_PLUGINS], [1], [Define to 1 for disabling reparse plugins]) test "${enable_really_static}" = "yes" && enable_library="no" test "${enable_library}" = "no" && enable_ldconfig="no" if test "x${DISTCHECK_HACK}" != "x"; then enable_mount_helper="no" enable_ldconfig="no" fi # Settings pkgconfigdir="\$(libdir)/pkgconfig" ntfs3gincludedir="\$(includedir)/ntfs-3g" # Executables should be installed to the root filesystem, otherwise # automounting NTFS volumes can fail during boot if the driver binaries # and their dependencies are on an unmounted partition. Use --exec-prefix # to override this. if test "x${exec_prefix}" = "xNONE"; then rootbindir="/bin" rootsbindir="/sbin" rootlibdir="/lib${libdir##*/lib}" else rootbindir="\$(bindir)" rootsbindir="\$(sbindir)" rootlibdir="\$(libdir)" fi AC_SUBST([pkgconfigdir]) AC_SUBST([ntfs3gincludedir]) AC_SUBST([rootbindir]) AC_SUBST([rootsbindir]) AC_SUBST([rootlibdir]) AC_SUBST([LIBNTFS_3G_VERSION]) AC_SUBST([LIBFUSE_LITE_CFLAGS]) AC_SUBST([LIBFUSE_LITE_LIBS]) AC_SUBST([MKNTFS_CPPFLAGS]) AC_SUBST([MKNTFS_LIBS]) AC_SUBST([LIBNTFS_CPPFLAGS]) AC_SUBST([LIBNTFS_LIBS]) AC_SUBST([NTFSPROGS_STATIC_LIBS]) AC_SUBST([OUTPUT_FORMAT]) AM_CONDITIONAL([FUSE_INTERNAL], [test "${with_fuse}" = "internal"]) AM_CONDITIONAL([GENERATE_LDSCRIPT], [test "${enable_ldscript}" = "yes"]) AM_CONDITIONAL([WINDOWS], [test "${WINDOWS}" = "yes"]) AM_CONDITIONAL([NTFS_DEVICE_DEFAULT_IO_OPS], [test "${enable_device_default_io_ops}" = "yes"]) AM_CONDITIONAL([RUN_LDCONFIG], [test "${enable_ldconfig}" = "yes"]) AM_CONDITIONAL([REALLYSTATIC], [test "${enable_really_static}" = "yes"]) AM_CONDITIONAL([INSTALL_LIBRARY], [test "${enable_library}" = "yes"]) AM_CONDITIONAL([ENABLE_MOUNT_HELPER], [test "${enable_mount_helper}" = "yes"]) AM_CONDITIONAL([ENABLE_NTFS_3G], [test "${enable_ntfs_3g}" = "yes"]) AM_CONDITIONAL([ENABLE_NTFSPROGS], [test "${enable_ntfsprogs}" = "yes"]) AM_CONDITIONAL([ENABLE_EXTRAS], [test "${enable_extras}" = "yes"]) AM_CONDITIONAL([ENABLE_QUARANTINED], [test "${enable_quarantined}" = "yes"]) AM_CONDITIONAL([DISABLE_PLUGINS], [test "${disable_plugins}" != "no"]) # workaround for /dev/null; then cat < Copyright (C) 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; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License. ntfs-3g-2026.2.25/README0000664000175000017500000001340715152260173007665 INTRODUCTION ============ The NTFS-3G driver is an open source, freely available read/write NTFS driver for Linux, FreeBSD, macOS, NetBSD, OpenIndiana, QNX and Haiku. It provides safe and fast handling of the Windows XP, Windows Server 2003, Windows 2000, Windows Vista, Windows Server 2008, Windows 7, Windows 8, Windows Server 2012, Windows Server 2016, Windows 10 and Windows Server 2019 NTFS file systems. The purpose of the project is to develop, quality assurance and support a trustable, featureful and high performance solution for hardware platforms and operating systems whose users need to reliably interoperate with NTFS. Besides this practical goal, the project also aims to explore the limits of the hybrid, kernel/user space filesystem driver approach, performance, reliability and feature richness per invested effort wise. Besides the common file system features, NTFS-3G has support for file ownership and permissions, POSIX ACLs, junction points, extended attributes and creating internally compressed files (parameter files in the directory .NTFS-3G may be required to enable them). The new compressed file formats available in Windows 10 can also be read through a plugin. News, support answers, problem submission instructions, support and discussion forums, and other information are available on the project web site at https://github.com/tuxera/ntfs-3g/wiki The project has been funded, supported and maintained since 2008 by Tuxera: https://tuxera.com LICENSES ======== All the NTFS related components: the file system drivers, the ntfsprogs utilities and the shared library libntfs-3g are distributed 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. See the included file COPYING. The fuse-lite library is distributed under the terms of the GNU LGPLv2. See the included file COPYING.LIB. QUICK INSTALLATION ================== Most distributions have an up-to-date NTFS-3G package ready for use, and the recommended way is to install it. If you need some specific customization, you can compile and install from the released source code. Make sure you have the basic development tools and the kernel includes the FUSE kernel module. Then unpack the source tarball and type: ./configure make make install # or 'sudo make install' if you aren't root. Please note that NTFS-3G doesn't require the FUSE user space package any more. The list of options for building specific configurations is displayed by typing : ./configure --help Below are a few specific options to ./configure : --disable-ntfsprogs : do not build the ntfsprogs tools, --enable-extras : build more ntfsprogs tools, --disable-plugins : disable support for plugins --enable-posix-acls : enable support for Posix ACLs --enable-xattr-mappings : enable system extended attributes mappings --with-fuse=external : use external fuse (overriding Linux default) There are also a few make targets for building parts : make libntfs : only build the libntfs-3g library make libs : only build libntfs-3g (and libfuse-lite, if relevant) make drivers : only build drivers and libraries, without ntfsprogs make ntfsprogs : only build ntfsprogs and libntfs-3g, without drivers USAGE ===== If there was no error during installation then the NTFS volume can be read-write mounted for everybody the following way as the root user (unmount the volume if it was already mounted, and replace /dev/sda1 and /mnt/windows, if needed): mount -t ntfs-3g /dev/sda1 /mnt/windows or ntfs-3g /dev/sda1 /mnt/windows Please see the ntfs-3g manual page for more options and examples. You can also make NTFS to be mounted during boot by putting the below line at the END(!) of the /etc/fstab file: /dev/sda1 /mnt/windows ntfs-3g defaults 0 0 TESTING WITHOUT INSTALLING ========================= Newer versions of ntfs-3g can be tested without installing anything and without disturbing an existing installation. Just configure and make as shown previously. This will create the scripts ntfs-3g and lowntfs-3g in the src directory, which you may activate for testing: ./configure make then, as root: src/ntfs-3g [-o mount-options] /dev/sda1 /mnt/windows And, to end the test, unmount the usual way: umount /dev/sda1 NTFS UTILITIES ============== The ntfsprogs directory includes utilities for doing all required tasks to NTFS partitions. In general, just run a utility without any command line options to display the version number and usage syntax. The following utilities are so far implemented: ntfsfix - Attempt to fix an NTFS partition and force Windows to check NTFS. mkntfs - Format a partition with the NTFS filesystem. See man 8 mkntfs for command line options. ntfslabel - Display/change the label of an NTFS partition. See man 8 ntfslabel for details. ntfsundelete - Recover deleted files from an NTFS volume. See man 8 ntfsundelete for more details. ntfsresize - Resize NTFS volumes. See man 8 ntfsresize for details. ntfsclone - Efficiently create/restore an image of an NTFS partition. See man 8 ntfsclone for details. ntfscluster - Locate the owner of any given sector or cluster on an NTFS partition. See man 8 ntfscluster for details. ntfsinfo - Show some information about an NTFS partition or one of the files or directories within it. See man 8 ntfsinfo for details. ntfsrecover - Recover updates committed by Windows but interrupted before being synced. ntfsls - List information about files in a directory residing on an NTFS partition. See man 8 ntfsls for details. ntfscat - Concatenate files and print their contents on the standard output. ntfscp - Overwrite files on an NTFS partition. ntfssecaudit - Audit the security metadata. ntfsusermap - Assistance for building a user mapping file. ntfs-3g-2026.2.25/AUTHORS0000664000175000017500000000050715152260173010052 Present authors of ntfs-3g in alphabetical order: Jean-Pierre Andre Alon Bar-Lev Martin Bene Dominique L Bouix Csaba Henk Bernhard Kaindl Erik Larsson Alejandro Pulver Szabolcs Szakacsits Miklos Szeredi Past authors in alphabetical order: Anton Altaparmakov Mario Emmenlauer Yuval Fledel Yura Pakhuchiy Richard Russon ntfs-3g-2026.2.25/COPYING.LIB0000664000175000017500000006130315152260173010443 GNU LIBRARY GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1991 Free Software Foundation, Inc. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. [This is the first released version of the library GPL. It is numbered 2 because it goes with version 2 of the ordinary GPL.] Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This license, the Library General Public License, applies to some specially designated Free Software Foundation software, and to any other libraries whose authors decide to use it. You can use it for your libraries, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library, or if you modify it. For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link a program with the library, you must provide complete object files to the recipients so that they can relink them with the library, after making changes to the library and recompiling it. And you must show them these terms so they know their rights. Our method of protecting your rights has two steps: (1) copyright the library, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the library. Also, for each distributor's protection, we want to make certain that everyone understands that there is no warranty for this free library. If the library is modified by someone else and passed on, we want its recipients to know that what they have is not the original version, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that companies distributing free software will individually obtain patent licenses, thus in effect transforming the program into proprietary software. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. Most GNU software, including some libraries, is covered by the ordinary GNU General Public License, which was designed for utility programs. This license, the GNU Library General Public License, applies to certain designated libraries. This license is quite different from the ordinary one; be sure to read it in full, and don't assume that anything in it is the same as in the ordinary license. The reason we have a separate public license for some libraries is that they blur the distinction we usually make between modifying or adding to a program and simply using it. Linking a program with a library, without changing the library, is in some sense simply using the library, and is analogous to running a utility program or application program. However, in a textual and legal sense, the linked executable is a combined work, a derivative of the original library, and the ordinary General Public License treats it as such. Because of this blurred distinction, using the ordinary General Public License for libraries did not effectively promote software sharing, because most developers did not use the libraries. We concluded that weaker conditions might promote sharing better. However, unrestricted linking of non-free programs would deprive the users of those programs of all benefit from the free status of the libraries themselves. This Library General Public License is intended to permit developers of non-free programs to use free libraries, while preserving your freedom as a user of such programs to change the free libraries that are incorporated in them. (We have not seen how to achieve this as regards changes in header files, but we have achieved it as regards changes in the actual functions of the Library.) The hope is that this will lead to faster development of free libraries. The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, while the latter only works together with the library. Note that it is possible for a library to be covered by the ordinary General Public License rather than by this special one. GNU LIBRARY GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any software library which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Library General Public License (also called "this License"). Each licensee is addressed as "you". A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables. The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".) "Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library. Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does. 1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) The modified work must itself be a software library. b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change. c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License. d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful. (For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library. In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices. Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy. This option is useful when you wish to copy part of the code of the Library into a program that is not a library. 4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange. If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code. 5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License. However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables. When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law. If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.) Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself. 6. As an exception to the Sections above, you may also compile or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications. You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things: a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.) b) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution. c) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place. d) Verify that the user has already received a copy of these materials or that you have already sent this user a copy. For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute. 7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above. b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 9. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it. 10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 11. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 13. The Free Software Foundation may publish revised and/or new versions of the Library General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation. 14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Libraries If you develop a new library, and you want it to be of the greatest possible use to the public, we recommend making it free software that everyone can redistribute and change. You can do so by permitting redistribution under these terms (or, alternatively, under the terms of the ordinary General Public License). To apply these terms, attach the following notices to the library. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA Also add information on how to contact you by electronic and paper mail. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the library, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the library `Frob' (a library for tweaking knobs) written by James Random Hacker. , 1 April 1990 Ty Coon, President of Vice That's all there is to it! ntfs-3g-2026.2.25/install-sh0000755000175000017500000003611515152260212011002 #!/bin/sh # install - install a program, script, or datafile scriptversion=2024-06-19.01; # UTC # This originates from X11R5 (mit/util/scripts/install.sh), which was # later released in X11R6 (xc/config/util/install.sh) with the # following copyright and license. # # Copyright (C) 1994 X Consortium # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to # deal in the Software without restriction, including without limitation the # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or # sell copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN # AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- # TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # # Except as contained in this notice, the name of the X Consortium shall not # be used in advertising or otherwise to promote the sale, use or other deal- # ings in this Software without prior written authorization from the X Consor- # tium. # # # FSF changes to this file are in the public domain. # # Calling this script install-sh is preferred over install.sh, to prevent # 'make' implicit rules from creating a file called install from it # when there is no Makefile. # # This script is compatible with the BSD install script, but was written # from scratch. tab=' ' nl=' ' IFS=" $tab$nl" # Set DOITPROG to "echo" to test this script. doit=${DOITPROG-} doit_exec=${doit:-exec} # Put in absolute file names if you don't have them in your path; # or use environment vars. chgrpprog=${CHGRPPROG-chgrp} chmodprog=${CHMODPROG-chmod} chownprog=${CHOWNPROG-chown} cmpprog=${CMPPROG-cmp} cpprog=${CPPROG-cp} mkdirprog=${MKDIRPROG-mkdir} mvprog=${MVPROG-mv} rmprog=${RMPROG-rm} stripprog=${STRIPPROG-strip} posix_mkdir= # Desired mode of installed file. mode=0755 # Create dirs (including intermediate dirs) using mode 755. # This is like GNU 'install' as of coreutils 8.32 (2020). mkdir_umask=22 backupsuffix= chgrpcmd= chmodcmd=$chmodprog chowncmd= mvcmd=$mvprog rmcmd="$rmprog -f" stripcmd= src= dst= dir_arg= dst_arg= copy_on_change=false is_target_a_directory=possibly usage="\ Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE or: $0 [OPTION]... SRCFILES... DIRECTORY or: $0 [OPTION]... -t DIRECTORY SRCFILES... or: $0 [OPTION]... -d DIRECTORIES... In the 1st form, copy SRCFILE to DSTFILE. In the 2nd and 3rd, copy all SRCFILES to DIRECTORY. In the 4th, create DIRECTORIES. Options: --help display this help and exit. --version display version info and exit. -c (ignored) -C install only if different (preserve data modification time) -d create directories instead of installing files. -g GROUP $chgrpprog installed files to GROUP. -m MODE $chmodprog installed files to MODE. -o USER $chownprog installed files to USER. -p pass -p to $cpprog. -s $stripprog installed files. -S SUFFIX attempt to back up existing files, with suffix SUFFIX. -t DIRECTORY install into DIRECTORY. -T report an error if DSTFILE is a directory. Environment variables override the default commands: CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG RMPROG STRIPPROG By default, rm is invoked with -f; when overridden with RMPROG, it's up to you to specify -f if you want it. If -S is not specified, no backups are attempted. Report bugs to . GNU Automake home page: . General help using GNU software: ." while test $# -ne 0; do case $1 in -c) ;; -C) copy_on_change=true;; -d) dir_arg=true;; -g) chgrpcmd="$chgrpprog $2" shift;; --help) echo "$usage"; exit $?;; -m) mode=$2 case $mode in *' '* | *"$tab"* | *"$nl"* | *'*'* | *'?'* | *'['*) echo "$0: invalid mode: $mode" >&2 exit 1;; esac shift;; -o) chowncmd="$chownprog $2" shift;; -p) cpprog="$cpprog -p";; -s) stripcmd=$stripprog;; -S) backupsuffix="$2" shift;; -t) is_target_a_directory=always dst_arg=$2 # Protect names problematic for 'test' and other utilities. case $dst_arg in -* | [=\(\)!]) dst_arg=./$dst_arg;; esac shift;; -T) is_target_a_directory=never;; --version) echo "$0 (GNU Automake) $scriptversion"; exit $?;; --) shift break;; -*) echo "$0: invalid option: $1" >&2 exit 1;; *) break;; esac shift done # We allow the use of options -d and -T together, by making -d # take the precedence; this is for compatibility with GNU install. if test -n "$dir_arg"; then if test -n "$dst_arg"; then echo "$0: target directory not allowed when installing a directory." >&2 exit 1 fi fi if test $# -ne 0 && test -z "$dir_arg$dst_arg"; then # When -d is used, all remaining arguments are directories to create. # When -t is used, the destination is already specified. # Otherwise, the last argument is the destination. Remove it from $@. for arg do if test -n "$dst_arg"; then # $@ is not empty: it contains at least $arg. set fnord "$@" "$dst_arg" shift # fnord fi shift # arg dst_arg=$arg # Protect names problematic for 'test' and other utilities. case $dst_arg in -* | [=\(\)!]) dst_arg=./$dst_arg;; esac done fi if test $# -eq 0; then if test -z "$dir_arg"; then echo "$0: no input file specified." >&2 exit 1 fi # It's OK to call 'install-sh -d' without argument. # This can happen when creating conditional directories. exit 0 fi if test -z "$dir_arg"; then if test $# -gt 1 || test "$is_target_a_directory" = always; then if test ! -d "$dst_arg"; then echo "$0: $dst_arg: Is not a directory." >&2 exit 1 fi fi fi if test -z "$dir_arg"; then do_exit='(exit $ret); exit $ret' trap "ret=129; $do_exit" 1 trap "ret=130; $do_exit" 2 trap "ret=141; $do_exit" 13 trap "ret=143; $do_exit" 15 # Set umask so as not to create temps with too-generous modes. # However, 'strip' requires both read and write access to temps. case $mode in # Optimize common cases. *644) cp_umask=133;; *755) cp_umask=22;; *[0-7]) if test -z "$stripcmd"; then u_plus_rw= else u_plus_rw='% 200' fi cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; *) if test -z "$stripcmd"; then u_plus_rw= else u_plus_rw=,u+rw fi cp_umask=$mode$u_plus_rw;; esac fi for src do # Protect names problematic for 'test' and other utilities. case $src in -* | [=\(\)!]) src=./$src;; esac if test -n "$dir_arg"; then dst=$src dstdir=$dst test -d "$dstdir" dstdir_status=$? # Don't chown directories that already exist. if test $dstdir_status = 0; then chowncmd="" fi else # Waiting for this to be detected by the "$cpprog $src $dsttmp" command # might cause directories to be created, which would be especially bad # if $src (and thus $dsttmp) contains '*'. if test ! -f "$src" && test ! -d "$src"; then echo "$0: $src does not exist." >&2 exit 1 fi if test -z "$dst_arg"; then echo "$0: no destination specified." >&2 exit 1 fi dst=$dst_arg # If destination is a directory, append the input filename. if test -d "$dst"; then if test "$is_target_a_directory" = never; then echo "$0: $dst_arg: Is a directory" >&2 exit 1 fi dstdir=$dst dstbase=`basename "$src"` case $dst in */) dst=$dst$dstbase;; *) dst=$dst/$dstbase;; esac dstdir_status=0 else dstdir=`dirname "$dst"` test -d "$dstdir" dstdir_status=$? fi fi case $dstdir in */) dstdirslash=$dstdir;; *) dstdirslash=$dstdir/;; esac obsolete_mkdir_used=false if test $dstdir_status != 0; then case $posix_mkdir in '') # With -d, create the new directory with the user-specified mode. # Otherwise, rely on $mkdir_umask. if test -n "$dir_arg"; then mkdir_mode=-m$mode else mkdir_mode= fi posix_mkdir=false # The $RANDOM variable is not portable (e.g., dash). Use it # here however when possible just to lower collision chance. tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ trap ' ret=$? rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir" 2>/dev/null exit $ret ' 0 # Because "mkdir -p" follows existing symlinks and we likely work # directly in world-writable /tmp, make sure that the '$tmpdir' # directory is successfully created first before we actually test # 'mkdir -p'. if (umask $mkdir_umask && $mkdirprog $mkdir_mode "$tmpdir" && exec $mkdirprog $mkdir_mode -p -- "$tmpdir/a/b") >/dev/null 2>&1 then if test -z "$dir_arg" || { # Check for POSIX incompatibility with -m. # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or # other-writable bit of parent directory when it shouldn't. # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. test_tmpdir="$tmpdir/a" ls_ld_tmpdir=`ls -ld "$test_tmpdir"` case $ls_ld_tmpdir in d????-?r-*) different_mode=700;; d????-?--*) different_mode=755;; *) false;; esac && $mkdirprog -m$different_mode -p -- "$test_tmpdir" && { ls_ld_tmpdir_1=`ls -ld "$test_tmpdir"` test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" } } then posix_mkdir=: fi rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir" else # Remove any dirs left behind by ancient mkdir implementations. rmdir ./$mkdir_mode ./-p ./-- "$tmpdir" 2>/dev/null fi trap '' 0;; esac if $posix_mkdir && ( umask $mkdir_umask && $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" ) then : else # mkdir does not conform to POSIX, # or it failed possibly due to a race condition. Create the # directory the slow way, step by step, checking for races as we go. case $dstdir in /*) prefix='/';; [-=\(\)!]*) prefix='./';; *) prefix='';; esac oIFS=$IFS IFS=/ set -f set fnord $dstdir shift set +f IFS=$oIFS prefixes= for d do test X"$d" = X && continue prefix=$prefix$d if test -d "$prefix"; then prefixes= else if $posix_mkdir; then (umask $mkdir_umask && $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break # Don't fail if two instances are running concurrently. test -d "$prefix" || exit 1 else case $prefix in *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; *) qprefix=$prefix;; esac prefixes="$prefixes '$qprefix'" fi fi prefix=$prefix/ done if test -n "$prefixes"; then # Don't fail if two instances are running concurrently. (umask $mkdir_umask && eval "\$doit_exec \$mkdirprog $prefixes") || test -d "$dstdir" || exit 1 obsolete_mkdir_used=true fi fi fi if test -n "$dir_arg"; then { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 else # Make a couple of temp file names in the proper directory. dsttmp=${dstdirslash}_inst.$$_ rmtmp=${dstdirslash}_rm.$$_ # Trap to clean up those temp files at exit. trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 # Copy the file name to the temp name. (umask $cp_umask && { test -z "$stripcmd" || { # Create $dsttmp read-write so that cp doesn't create it read-only, # which would cause strip to fail. if test -z "$doit"; then : >"$dsttmp" # No need to fork-exec 'touch'. else $doit touch "$dsttmp" fi } } && $doit_exec $cpprog "$src" "$dsttmp") && # and set any options; do chmod last to preserve setuid bits. # # If any of these fail, we abort the whole thing. If we want to # ignore errors from any of these, just make sure not to ignore # errors from the above "$doit $cpprog $src $dsttmp" command. # { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } && { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } && { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && # If -C, don't bother to copy if it wouldn't change the file. if $copy_on_change && old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && set -f && set X $old && old=:$2:$4:$5:$6 && set X $new && new=:$2:$4:$5:$6 && set +f && test "$old" = "$new" && $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 then rm -f "$dsttmp" else # If $backupsuffix is set, and the file being installed # already exists, attempt a backup. Don't worry if it fails, # e.g., if mv doesn't support -f. if test -n "$backupsuffix" && test -f "$dst"; then $doit $mvcmd -f "$dst" "$dst$backupsuffix" 2>/dev/null fi # Rename the file to the real destination. $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || # The rename failed, perhaps because mv can't rename something else # to itself, or perhaps because mv is so ancient that it does not # support -f. { # Now remove or move aside any old file at destination location. # We try this two ways since rm can't unlink itself on some # systems and the destination file might be busy for other # reasons. In this case, the final cleanup might fail but the new # file should still install successfully. { test ! -f "$dst" || $doit $rmcmd "$dst" 2>/dev/null || { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && { $doit $rmcmd "$rmtmp" 2>/dev/null; :; } } || { echo "$0: cannot unlink or rename $dst" >&2 (exit 1); exit 1 } } && # Now rename the file to the real destination. $doit $mvcmd "$dsttmp" "$dst" } fi || exit 1 trap '' 0 fi done # Local variables: # eval: (add-hook 'before-save-hook 'time-stamp) # time-stamp-start: "scriptversion=" # time-stamp-format: "%:y-%02m-%02d.%02H" # time-stamp-time-zone: "UTC0" # time-stamp-end: "; # UTC" # End: ntfs-3g-2026.2.25/src/0000775000175000017500000000000015152260235007646 5ntfs-3g-2026.2.25/src/ntfs-3g.probe.8.in0000664000175000017500000000416315152260174012661 .\" Copyright (c) 2008 Szabolcs Szakacsits. .\" This file may be copied under the terms of the GNU Public License. .\" .TH NTFS-3G.PROBE 8 "January 2008" "ntfs-3g.probe @VERSION@" .SH NAME ntfs-3g.probe \- Probe an NTFS volume mountability .SH SYNOPSIS .B ntfs-3g.probe .I <\-\-readonly|\-\-readwrite> .I volume .br .SH DESCRIPTION The \fBntfs-3g.probe\fR utility tests a volume if it's NTFS mountable read-only or read-write, and exits with a status value accordingly. The \fIvolume\fR can be a block device or image file. .SH OPTIONS Below is a summary of the options that \fBntfs-3g.probe\fR accepts. .TP .B \-r, \-\-readonly Test if the volume can be mounted read-only. .TP .B \-w, \-\-readwrite Test if the volume can be mounted read-write. .TP .B \-h, \-\-help Display help and exit. .SH EXAMPLE Test if /dev/sda1 can be mounted read-write: .RS .sp .B ntfs-3g.probe --readwrite /dev/sda1 .sp .RE .SH EXIT CODES The exit codes are as follows: .IP 0 Volume is mountable. .IP 11 Syntax error, command line parsing failed. .IP 12 The volume doesn't have a valid NTFS. .IP 13 Inconsistent NTFS, hardware or device driver fault, or unsetup SoftRAID/FakeRAID hardware. .IP 14 The NTFS partition is hibernated. .IP 15 The volume was not cleanly unmounted. .IP 16 The volume is already exclusively opened and in use by a kernel driver or software. .IP 17 Unsetup SoftRAID/FakeRAID hardware. .IP 18 Unknown reason. .IP 19 Not enough privilege to mount. .IP 20 Out of memory. .IP 21 Unclassified FUSE error. .SH KNOWN ISSUES Please see .RS .sp https://github.com/tuxera/ntfs-3g/wiki/NTFS-3G-FAQ .sp .RE for common questions and known issues. If you think you have found an undocumented problem in the latest release of the software then please post an ntfs-3g issue describing it in detail so that the development team can be aware of the issue and take care of it: .RS .sp https://github.com/tuxera/ntfs-3g/issues .sp .RE .SH AUTHORS .B ntfs-3g.probe was written by Szabolcs Szakacsits. .SH THANKS Alon Bar-Lev has integrated the utility into the NTFS-3G build process and tested it with Erik Larsson before the public release. .SH SEE ALSO .BR ntfs-3g (8) ntfs-3g-2026.2.25/src/Makefile.am0000664000175000017500000000427015152260174011627 EXTRA_DIST = ntfs-3g_common.h MAINTAINERCLEANFILES = $(srcdir)/Makefile.in if FUSE_INTERNAL FUSE_CFLAGS = -I$(top_srcdir)/include/fuse-lite FUSE_LIBS = $(top_builddir)/libfuse-lite/libfuse-lite.la else FUSE_CFLAGS = $(FUSE_MODULE_CFLAGS) FUSE_LIBS = $(FUSE_MODULE_LIBS) endif if !DISABLE_PLUGINS plugindir = $(libdir)/ntfs-3g PLUGIN_CFLAGS = -DPLUGIN_DIR=\"$(plugindir)\" endif if ENABLE_NTFS_3G bin_PROGRAMS = ntfs-3g.probe rootbin_PROGRAMS = ntfs-3g lowntfs-3g rootsbin_DATA = #Create directory man_MANS = ntfs-3g.8 ntfs-3g.probe.8 ntfs_3g_LDADD = $(LIBDL) $(FUSE_LIBS) $(top_builddir)/libntfs-3g/libntfs-3g.la if REALLYSTATIC ntfs_3g_LDFLAGS = $(AM_LDFLAGS) -all-static endif ntfs_3g_CFLAGS = \ $(AM_CFLAGS) \ -DFUSE_USE_VERSION=26 \ $(FUSE_CFLAGS) \ -I$(top_srcdir)/include/ntfs-3g \ $(PLUGIN_CFLAGS) ntfs_3g_SOURCES = ntfs-3g.c ntfs-3g_common.c lowntfs_3g_LDADD = $(LIBDL) $(FUSE_LIBS) $(top_builddir)/libntfs-3g/libntfs-3g.la if REALLYSTATIC lowntfs_3g_LDFLAGS = $(AM_LDFLAGS) -all-static endif lowntfs_3g_CFLAGS = \ $(AM_CFLAGS) \ -DFUSE_USE_VERSION=26 \ $(FUSE_CFLAGS) \ -I$(top_srcdir)/include/ntfs-3g \ $(PLUGIN_CFLAGS) lowntfs_3g_SOURCES = lowntfs-3g.c ntfs-3g_common.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 drivers : $(FUSE_LIBS) ntfs-3g lowntfs-3g install-exec-hook: if RUN_LDCONFIG $(LDCONFIG) endif if !DISABLE_PLUGINS $(MKDIR_P) $(DESTDIR)/$(plugindir) endif if ENABLE_MOUNT_HELPER install-exec-local: install-rootbinPROGRAMS $(MKDIR_P) "$(DESTDIR)/sbin" $(LN_S) -f "$(rootbindir)/ntfs-3g" "$(DESTDIR)/sbin/mount.ntfs-3g" $(LN_S) -f "$(rootbindir)/lowntfs-3g" "$(DESTDIR)/sbin/mount.lowntfs-3g" install-data-local: install-man8 $(LN_S) -f ntfs-3g.8 "$(DESTDIR)$(man8dir)/mount.ntfs-3g.8" $(LN_S) -f ntfs-3g.8 "$(DESTDIR)$(man8dir)/mount.lowntfs-3g.8" uninstall-local: $(RM) -f "$(DESTDIR)$(man8dir)/mount.ntfs-3g.8" $(RM) -f "$(DESTDIR)/sbin/mount.ntfs-3g" "$(DESTDIR)/sbin/mount.lowntfs-3g" endif endif # ENABLE_NTFS_3G ntfs-3g-2026.2.25/src/lowntfs-3g.c0000664000175000017500000036341415152260174011752 /** * ntfs-3g - Third Generation NTFS Driver * * Copyright (c) 2005-2007 Yura Pakhuchiy * Copyright (c) 2005 Yuval Fledel * Copyright (c) 2006-2009 Szabolcs Szakacsits * Copyright (c) 2007-2021 Jean-Pierre Andre * Copyright (c) 2009 Erik Larsson * * This file is originated from the Linux-NTFS project. * * 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 */ #include "config.h" #include #include #if !defined(FUSE_VERSION) || (FUSE_VERSION < 26) #error "***********************************************************" #error "* *" #error "* Compilation requires at least FUSE version 2.6.0! *" #error "* *" #error "***********************************************************" #endif #ifdef HAVE_STDIO_H #include #endif #ifdef HAVE_STRING_H #include #endif #ifdef HAVE_ERRNO_H #include #endif #ifdef HAVE_FCNTL_H #include #endif #ifdef HAVE_UNISTD_H #include #endif #ifdef HAVE_STDLIB_H #include #endif #ifdef HAVE_LOCALE_H #include #endif #include #ifdef HAVE_LIMITS_H #include #endif #include #include #ifdef HAVE_SETXATTR #include #endif #ifdef HAVE_SYS_TYPES_H #include #endif #ifdef MAJOR_IN_MKDEV #include #endif #ifdef MAJOR_IN_SYSMACROS #include #endif #if defined(__APPLE__) || defined(__DARWIN__) #include #elif defined(__sun) && defined (__SVR4) #include #endif /* defined(__APPLE__) || defined(__DARWIN__), ... */ #ifndef FUSE_CAP_POSIX_ACL /* until defined in */ #define FUSE_CAP_POSIX_ACL (1 << 18) #endif /* FUSE_CAP_POSIX_ACL */ #include "compat.h" #include "bitmap.h" #include "attrib.h" #include "inode.h" #include "volume.h" #include "dir.h" #include "unistr.h" #include "layout.h" #include "index.h" #include "ntfstime.h" #include "security.h" #include "reparse.h" #include "ea.h" #include "object_id.h" #include "efs.h" #include "logging.h" #include "xattrs.h" #include "misc.h" #include "ioctl.h" #include "plugin.h" #include "ntfs-3g_common.h" /* * The following permission checking modes are governed by * the LPERMSCONFIG value in param.h */ /* ACLS may be checked by kernel (requires a fuse patch) or here */ #define KERNELACLS ((LPERMSCONFIG > 6) & (LPERMSCONFIG < 10)) /* basic permissions may be checked by kernel or here */ #define KERNELPERMS (((LPERMSCONFIG - 1) % 6) < 3) /* may want to use fuse/kernel cacheing */ #define CACHEING (!(LPERMSCONFIG % 3)) #if KERNELACLS & !KERNELPERMS #error "Incompatible options KERNELACLS and KERNELPERMS" #endif #if !CACHEING #define ATTR_TIMEOUT (ctx->ro ? TIMEOUT_RO : 0.0) #define ENTRY_TIMEOUT (ctx->ro ? TIMEOUT_RO : 0.0) #else #if defined(__sun) && defined (__SVR4) #define ATTR_TIMEOUT (ctx->ro ? TIMEOUT_RO : 10.0) #define ENTRY_TIMEOUT (ctx->ro ? TIMEOUT_RO : 10.0) #else /* defined(__sun) && defined (__SVR4) */ /* * FUSE cacheing is only usable with basic permissions * checked by the kernel with external fuse >= 2.8 */ #if !KERNELPERMS #warning "Fuse cacheing is only usable with basic permissions checked by kernel" #endif #if KERNELACLS #define ATTR_TIMEOUT (ctx->ro ? TIMEOUT_RO : 10.0) #define ENTRY_TIMEOUT (ctx->ro ? TIMEOUT_RO : 10.0) #else /* KERNELACLS */ #define ATTR_TIMEOUT (ctx->ro ? TIMEOUT_RO : \ (ctx->vol->secure_flags & (1 << SECURITY_DEFAULT) ? 10.0 : 0.0)) #define ENTRY_TIMEOUT (ctx->ro ? TIMEOUT_RO : \ (ctx->vol->secure_flags & (1 << SECURITY_DEFAULT) ? 10.0 : 0.0)) #endif /* KERNELACLS */ #endif /* defined(__sun) && defined (__SVR4) */ #endif /* !CACHEING */ #define GHOSTLTH 40 /* max length of a ghost file name - see ghostformat */ /* sometimes the kernel cannot check access */ #define ntfs_real_allowed_access(scx, ni, type) ntfs_allowed_access(scx, ni, type) #if POSIXACLS & KERNELPERMS & !KERNELACLS /* short-circuit if PERMS checked by kernel and ACLs by fs */ #define ntfs_allowed_access(scx, ni, type) \ ((scx)->vol->secure_flags & (1 << SECURITY_DEFAULT) \ ? 1 : ntfs_allowed_access(scx, ni, type)) #endif #define set_archive(ni) (ni)->flags |= FILE_ATTR_ARCHIVE #define INODE(ino) ((ino) == 1 ? (MFT_REF)FILE_root : (MFT_REF)(ino)) /* * Call a function from a reparse plugin (variable arguments) * Requires "reparse" and "ops" to have been defined * * Returns a non-negative value if successful, * and a negative error code if something fails. */ #define CALL_REPARSE_PLUGIN(ni, op_name, ...) \ (reparse = (REPARSE_POINT*)NULL, \ ops = select_reparse_plugin(ctx, ni, &reparse), \ (!ops ? -errno \ : (ops->op_name ? \ ops->op_name(ni, reparse, __VA_ARGS__) \ : -EOPNOTSUPP))), \ free(reparse) typedef enum { FSTYPE_NONE, FSTYPE_UNKNOWN, FSTYPE_FUSE, FSTYPE_FUSEBLK } fuse_fstype; typedef struct fill_item { struct fill_item *next; size_t bufsize; size_t off; char buf[0]; } ntfs_fuse_fill_item_t; typedef struct fill_context { struct fill_item *first; struct fill_item *last; #ifndef DISABLE_PLUGINS u64 fh; #endif /* DISABLE_PLUGINS */ off_t off; fuse_req_t req; fuse_ino_t ino; BOOL filled; } ntfs_fuse_fill_context_t; struct open_file { struct open_file *next; struct open_file *previous; long long ghost; fuse_ino_t ino; fuse_ino_t parent; int state; #ifndef DISABLE_PLUGINS struct fuse_file_info fi; #endif /* DISABLE_PLUGINS */ } ; enum { CLOSE_GHOST = 1, CLOSE_COMPRESSED = 2, CLOSE_ENCRYPTED = 4, CLOSE_DMTIME = 8, CLOSE_REPARSE = 16 }; enum RM_TYPES { RM_LINK, RM_DIR, RM_ANY, } ; static struct ntfs_options opts; const char *EXEC_NAME = "lowntfs-3g"; static ntfs_fuse_context_t *ctx; static u32 ntfs_sequence; static const char ghostformat[] = ".ghost-ntfs-3g-%020llu"; static const char *usage_msg = "\n" "%s %s %s %d - Third Generation NTFS Driver\n" "\t\tConfiguration type %d, " #ifdef HAVE_SETXATTR "XATTRS are on, " #else "XATTRS are off, " #endif #if POSIXACLS "POSIX ACLS are on\n" #else "POSIX ACLS are off\n" #endif "\n" "Copyright (C) 2005-2007 Yura Pakhuchiy\n" "Copyright (C) 2006-2009 Szabolcs Szakacsits\n" "Copyright (C) 2007-2022 Jean-Pierre Andre\n" "Copyright (C) 2009-2020 Erik Larsson\n" "\n" "Usage: %s [-o option[,...]] \n" "\n" "Options: ro (read-only mount), windows_names, uid=, gid=,\n" " umask=, fmask=, dmask=, streams_interface=.\n" " Please see the details in the manual (type: man ntfs-3g).\n" "\n" "Example: lowntfs-3g /dev/sda1 /mnt/windows\n" "\n" #ifdef PLUGIN_DIR "Plugin path: " PLUGIN_DIR "\n\n" #endif /* PLUGIN_DIR */ "%s"; static const char ntfs_bad_reparse[] = "unsupported reparse tag 0x%08lx"; /* exact length of target text, without the terminator */ #define ntfs_bad_reparse_lth (sizeof(ntfs_bad_reparse) + 2) #ifdef FUSE_INTERNAL int drop_privs(void); int restore_privs(void); #else /* * setuid and setgid root ntfs-3g denies to start with external FUSE, * therefore the below functions are no-op in such case. */ static int drop_privs(void) { return 0; } #if defined(linux) || defined(__uClinux__) static int restore_privs(void) { return 0; } #endif static const char *setuid_msg = "Mount is denied because setuid and setgid root ntfs-3g is insecure with the\n" "external FUSE library. Either remove the setuid/setgid bit from the binary\n" "or rebuild NTFS-3G with integrated FUSE support and make it setuid root.\n" "Please see more information at\n" "https://github.com/tuxera/ntfs-3g/wiki/NTFS-3G-FAQ\n"; static const char *unpriv_fuseblk_msg = "Unprivileged user can not mount NTFS block devices using the external FUSE\n" "library. Either mount the volume as root, or rebuild NTFS-3G with integrated\n" "FUSE support and make it setuid root. Please see more information at\n" "https://github.com/tuxera/ntfs-3g/wiki/NTFS-3G-FAQ\n"; #endif static void ntfs_fuse_update_times(ntfs_inode *ni, ntfs_time_update_flags mask) { if (ctx->atime == ATIME_DISABLED) mask &= ~NTFS_UPDATE_ATIME; else if (ctx->atime == ATIME_RELATIVE && mask == NTFS_UPDATE_ATIME && (sle64_to_cpu(ni->last_access_time) >= sle64_to_cpu(ni->last_data_change_time)) && (sle64_to_cpu(ni->last_access_time) >= sle64_to_cpu(ni->last_mft_change_time))) return; ntfs_inode_update_times(ni, mask); } static s64 ntfs_get_nr_free_mft_records(ntfs_volume *vol) { ntfs_attr *na = vol->mftbmp_na; s64 nr_free = ntfs_attr_get_free_bits(na); if (nr_free >= 0) nr_free += (na->allocated_size - na->data_size) << 3; return nr_free; } /* * Fill a security context as needed by security functions * returns TRUE if there is a user mapping, * FALSE if there is none * This is not an error and the context is filled anyway, * it is used for implicit Windows-like inheritance */ static BOOL ntfs_fuse_fill_security_context(fuse_req_t req, struct SECURITY_CONTEXT *scx) { const struct fuse_ctx *fusecontext; scx->vol = ctx->vol; scx->mapping[MAPUSERS] = ctx->security.mapping[MAPUSERS]; scx->mapping[MAPGROUPS] = ctx->security.mapping[MAPGROUPS]; scx->pseccache = &ctx->seccache; if (req) { fusecontext = fuse_req_ctx(req); scx->uid = fusecontext->uid; scx->gid = fusecontext->gid; scx->tid = fusecontext->pid; #ifdef FUSE_CAP_DONT_MASK /* the umask can be processed by the file system */ scx->umask = fusecontext->umask; #else /* the umask if forced by fuse on creation */ scx->umask = 0; #endif } else { scx->uid = 0; scx->gid = 0; scx->tid = 0; scx->umask = 0; } return (ctx->security.mapping[MAPUSERS] != (struct MAPPING*)NULL); } static u64 ntfs_fuse_inode_lookup(fuse_ino_t parent, const char *name) { u64 ino = (u64)-1; u64 inum; ntfs_inode *dir_ni; /* Open target directory. */ dir_ni = ntfs_inode_open(ctx->vol, INODE(parent)); if (dir_ni) { /* Lookup file */ inum = ntfs_inode_lookup_by_mbsname(dir_ni, name); /* never return inodes 0 and 1 */ if (MREF(inum) <= 1) { inum = (u64)-1; errno = ENOENT; } if (ntfs_inode_close(dir_ni) || (inum == (u64)-1)) ino = (u64)-1; else ino = MREF(inum); } return (ino); } #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) /* * Check access to parent directory * * file inode is only opened when not fed in and S_ISVTX is requested, * when already open and S_ISVTX, it *HAS TO* be fed in. * * returns 1 if allowed, * 0 if not allowed or some error occurred (errno tells why) */ static int ntfs_allowed_dir_access(struct SECURITY_CONTEXT *scx, ntfs_inode *dir_ni, fuse_ino_t ino, ntfs_inode *ni, mode_t accesstype) { int allowed; ntfs_inode *ni2; struct stat stbuf; allowed = ntfs_allowed_access(scx, dir_ni, accesstype); /* * for an not-owned sticky directory, have to * check whether file itself is owned */ if ((accesstype == (S_IWRITE + S_IEXEC + S_ISVTX)) && (allowed == 2)) { if (ni) ni2 = ni; else ni2 = ntfs_inode_open(ctx->vol, INODE(ino)); allowed = 0; if (ni2) { allowed = (ntfs_get_owner_mode(scx,ni2,&stbuf) >= 0) && (stbuf.st_uid == scx->uid); if (!ni) ntfs_inode_close(ni2); } } return (allowed); } #endif /* !KERNELPERMS | (POSIXACLS & !KERNELACLS) */ /** * ntfs_fuse_statfs - return information about mounted NTFS volume * @path: ignored (but fuse requires it) * @sfs: statfs structure in which to return the information * * Return information about the mounted NTFS volume @sb in the statfs structure * pointed to by @sfs (this is initialized with zeros before ntfs_statfs is * called). We interpret the values to be correct of the moment in time at * which we are called. Most values are variable otherwise and this isn't just * the free values but the totals as well. For example we can increase the * total number of file nodes if we run out and we can keep doing this until * there is no more space on the volume left at all. * * This code based on ntfs_statfs from ntfs kernel driver. * * Returns 0 on success or -errno on error. */ static void ntfs_fuse_statfs(fuse_req_t req, fuse_ino_t ino __attribute__((unused))) { struct statvfs sfs; s64 size; int delta_bits; ntfs_volume *vol; vol = ctx->vol; if (vol) { /* * File system block size. Used to calculate used/free space by df. * Incorrectly documented as "optimal transfer block size". */ sfs.f_bsize = vol->cluster_size; /* Fundamental file system block size, used as the unit. */ sfs.f_frsize = vol->cluster_size; /* * Total number of blocks on file system in units of f_frsize. * Since inodes are also stored in blocks ($MFT is a file) hence * this is the number of clusters on the volume. */ sfs.f_blocks = vol->nr_clusters; /* Free blocks available for all and for non-privileged processes. */ size = vol->free_clusters; if (size < 0) size = 0; sfs.f_bavail = sfs.f_bfree = size; /* Free inodes on the free space */ delta_bits = vol->cluster_size_bits - vol->mft_record_size_bits; if (delta_bits >= 0) size <<= delta_bits; else size >>= -delta_bits; /* Number of inodes at this point in time. */ sfs.f_files = (vol->mftbmp_na->allocated_size << 3) + size; /* Free inodes available for all and for non-privileged processes. */ size += vol->free_mft_records; if (size < 0) size = 0; sfs.f_ffree = sfs.f_favail = size; /* Maximum length of filenames. */ sfs.f_namemax = NTFS_MAX_NAME_LEN; fuse_reply_statfs(req, &sfs); } else fuse_reply_err(req, ENODEV); } static void set_fuse_error(int *err) { if (!*err) *err = -errno; } #if 0 && (defined(__APPLE__) || defined(__DARWIN__)) /* Unfinished. */ static int ntfs_macfuse_getxtimes(const char *org_path, struct timespec *bkuptime, struct timespec *crtime) { int res = 0; ntfs_inode *ni; char *path = NULL; ntfschar *stream_name; int stream_name_len; stream_name_len = ntfs_fuse_parse_path(org_path, &path, &stream_name); if (stream_name_len < 0) return stream_name_len; memset(bkuptime, 0, sizeof(struct timespec)); memset(crtime, 0, sizeof(struct timespec)); ni = ntfs_pathname_to_inode(ctx->vol, NULL, path); if (!ni) { res = -errno; goto exit; } /* We have no backup timestamp in NTFS. */ crtime->tv_sec = ni->creation_time; exit: if (ntfs_inode_close(ni)) set_fuse_error(&res); free(path); if (stream_name_len) free(stream_name); return res; } int ntfs_macfuse_setcrtime(const char *path, const struct timespec *tv) { ntfs_inode *ni; int res = 0; if (ntfs_fuse_is_named_data_stream(path)) return -EINVAL; /* n/a for named data streams. */ ni = ntfs_pathname_to_inode(ctx->vol, NULL, path); if (!ni) return -errno; if (tv) { ni->creation_time = tv->tv_sec; ntfs_fuse_update_times(ni, NTFS_UPDATE_CTIME); } if (ntfs_inode_close(ni)) set_fuse_error(&res); return res; } int ntfs_macfuse_setbkuptime(const char *path, const struct timespec *tv) { ntfs_inode *ni; int res = 0; if (ntfs_fuse_is_named_data_stream(path)) return -EINVAL; /* n/a for named data streams. */ ni = ntfs_pathname_to_inode(ctx->vol, NULL, path); if (!ni) return -errno; /* * Only pretending to set backup time successfully to please the APIs of * Mac OS X. In reality, NTFS has no backup time. */ if (ntfs_inode_close(ni)) set_fuse_error(&res); return res; } int ntfs_macfuse_setchgtime(const char *path, const struct timespec *tv) { ntfs_inode *ni; int res = 0; if (ntfs_fuse_is_named_data_stream(path)) return -EINVAL; /* n/a for named data streams. */ ni = ntfs_pathname_to_inode(ctx->vol, NULL, path); if (!ni) return -errno; if (tv) { ni->last_mft_change_time = tv->tv_sec; ntfs_fuse_update_times(ni, 0); } if (ntfs_inode_close(ni)) set_fuse_error(&res); return res; } #endif /* defined(__APPLE__) || defined(__DARWIN__) */ static void ntfs_init(void *userdata __attribute__((unused)), struct fuse_conn_info *conn) { #if defined(__APPLE__) || defined(__DARWIN__) FUSE_ENABLE_XTIMES(conn); #endif #ifdef FUSE_CAP_DONT_MASK /* request umask not to be enforced by fuse */ conn->want |= FUSE_CAP_DONT_MASK; #endif /* defined FUSE_CAP_DONT_MASK */ #if POSIXACLS & KERNELACLS /* request ACLs to be checked by kernel */ conn->want |= FUSE_CAP_POSIX_ACL; #endif /* POSIXACLS & KERNELACLS */ #ifdef FUSE_CAP_BIG_WRITES if (ctx->big_writes && ((ctx->vol->nr_clusters << ctx->vol->cluster_size_bits) >= SAFE_CAPACITY_FOR_BIG_WRITES)) conn->want |= FUSE_CAP_BIG_WRITES; #endif #ifdef FUSE_CAP_IOCTL_DIR conn->want |= FUSE_CAP_IOCTL_DIR; #endif /* defined(FUSE_CAP_IOCTL_DIR) */ } #ifndef DISABLE_PLUGINS /* * Define attributes for a junction or symlink * (internal plugin) */ static int junction_getstat(ntfs_inode *ni, const REPARSE_POINT *reparse __attribute__((unused)), struct stat *stbuf) { char *target; int res; errno = 0; target = ntfs_make_symlink(ni, ctx->abs_mnt_point); /* * If the reparse point is not a valid * directory junction, and there is no error * we still display as a symlink */ if (target || (errno == EOPNOTSUPP)) { if (target) stbuf->st_size = strlen(target); else stbuf->st_size = ntfs_bad_reparse_lth; stbuf->st_blocks = (ni->allocated_size + 511) >> 9; stbuf->st_mode = S_IFLNK; free(target); res = 0; } else { res = -errno; } return (res); } static int wsl_getstat(ntfs_inode *ni, const REPARSE_POINT *reparse, struct stat *stbuf) { dev_t rdev; int res; res = ntfs_reparse_check_wsl(ni, reparse); if (!res) { switch (reparse->reparse_tag) { case IO_REPARSE_TAG_AF_UNIX : stbuf->st_mode = S_IFSOCK; break; case IO_REPARSE_TAG_LX_FIFO : stbuf->st_mode = S_IFIFO; break; case IO_REPARSE_TAG_LX_CHR : stbuf->st_mode = S_IFCHR; res = ntfs_ea_check_wsldev(ni, &rdev); stbuf->st_rdev = rdev; break; case IO_REPARSE_TAG_LX_BLK : stbuf->st_mode = S_IFBLK; res = ntfs_ea_check_wsldev(ni, &rdev); stbuf->st_rdev = rdev; break; default : stbuf->st_size = ntfs_bad_reparse_lth; stbuf->st_mode = S_IFLNK; break; } } /* * If the reparse point is not a valid wsl special file * we display as a symlink */ if (res) { stbuf->st_size = ntfs_bad_reparse_lth; stbuf->st_mode = S_IFLNK; res = 0; } return (res); } /* * Apply permission masks to st_mode returned by reparse handler */ static void apply_umask(struct stat *stbuf) { switch (stbuf->st_mode & S_IFMT) { case S_IFREG : stbuf->st_mode &= ~ctx->fmask; break; case S_IFDIR : stbuf->st_mode &= ~ctx->dmask; break; case S_IFLNK : stbuf->st_mode = (stbuf->st_mode & S_IFMT) | 0777; break; default : break; } } #endif /* DISABLE_PLUGINS */ static int ntfs_fuse_getstat(struct SECURITY_CONTEXT *scx, ntfs_inode *ni, struct stat *stbuf) { int res = 0; ntfs_attr *na; BOOL withusermapping; memset(stbuf, 0, sizeof(struct stat)); withusermapping = (scx->mapping[MAPUSERS] != (struct MAPPING*)NULL); stbuf->st_nlink = le16_to_cpu(ni->mrec->link_count); if (ctx->posix_nlink && !(ni->flags & FILE_ATTR_REPARSE_POINT)) stbuf->st_nlink = ntfs_dir_link_cnt(ni); if ((ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) || (ni->flags & FILE_ATTR_REPARSE_POINT)) { if (ni->flags & FILE_ATTR_REPARSE_POINT) { #ifndef DISABLE_PLUGINS const plugin_operations_t *ops; REPARSE_POINT *reparse; res = CALL_REPARSE_PLUGIN(ni, getattr, stbuf); if (!res) { apply_umask(stbuf); } else { stbuf->st_size = ntfs_bad_reparse_lth; stbuf->st_blocks = (ni->allocated_size + 511) >> 9; stbuf->st_mode = S_IFLNK; res = 0; } goto ok; #else /* DISABLE_PLUGINS */ char *target; errno = 0; target = ntfs_make_symlink(ni, ctx->abs_mnt_point); /* * If the reparse point is not a valid * directory junction, and there is no error * we still display as a symlink */ if (target || (errno == EOPNOTSUPP)) { if (target) stbuf->st_size = strlen(target); else stbuf->st_size = ntfs_bad_reparse_lth; stbuf->st_blocks = (ni->allocated_size + 511) >> 9; stbuf->st_nlink = le16_to_cpu(ni->mrec->link_count); stbuf->st_mode = S_IFLNK; free(target); } else { res = -errno; goto exit; } #endif /* DISABLE_PLUGINS */ } else { /* Directory. */ stbuf->st_mode = S_IFDIR | (0777 & ~ctx->dmask); /* get index size, if not known */ if (!test_nino_flag(ni, KnownSize)) { na = ntfs_attr_open(ni, AT_INDEX_ALLOCATION, NTFS_INDEX_I30, 4); if (na) { ni->data_size = na->data_size; ni->allocated_size = na->allocated_size; set_nino_flag(ni, KnownSize); ntfs_attr_close(na); } } stbuf->st_size = ni->data_size; stbuf->st_blocks = ni->allocated_size >> 9; if (!ctx->posix_nlink) stbuf->st_nlink = 1; /* Make find(1) work */ } } else { /* Regular or Interix (INTX) file. */ stbuf->st_mode = S_IFREG; stbuf->st_size = ni->data_size; #ifdef HAVE_SETXATTR /* extended attributes interface required */ /* * return data size rounded to next 512 byte boundary for * encrypted files to include padding required for decryption * also include 2 bytes for padding info */ if (ctx->efs_raw && (ni->flags & FILE_ATTR_ENCRYPTED) && ni->data_size) stbuf->st_size = ((ni->data_size + 511) & ~511) + 2; #endif /* HAVE_SETXATTR */ /* * Temporary fix to make ActiveSync work via Samba 3.0. * See more on the ntfs-3g-devel list. */ stbuf->st_blocks = (ni->allocated_size + 511) >> 9; if (ni->flags & FILE_ATTR_SYSTEM) { na = ntfs_attr_open(ni, AT_DATA, AT_UNNAMED, 0); if (!na) { stbuf->st_ino = ni->mft_no; goto nodata; } /* Check whether it's Interix FIFO or socket. */ if (!(ni->flags & FILE_ATTR_HIDDEN)) { /* FIFO. */ if (na->data_size == 0) stbuf->st_mode = S_IFIFO; /* Socket link. */ if (na->data_size == 1) stbuf->st_mode = S_IFSOCK; } /* * Check whether it's Interix symbolic link, block or * character device. */ if ((u64)na->data_size <= sizeof(INTX_FILE_TYPES) + sizeof(ntfschar) * PATH_MAX && (u64)na->data_size > sizeof(INTX_FILE_TYPES)) { INTX_FILE *intx_file; intx_file = (INTX_FILE*)ntfs_malloc(na->data_size); if (!intx_file) { res = -errno; ntfs_attr_close(na); goto exit; } if (ntfs_attr_pread(na, 0, na->data_size, intx_file) != na->data_size) { res = -errno; free(intx_file); ntfs_attr_close(na); goto exit; } if (intx_file->magic == INTX_BLOCK_DEVICE && na->data_size == (s64)offsetof( INTX_FILE, device_end)) { stbuf->st_mode = S_IFBLK; stbuf->st_rdev = makedev(le64_to_cpu( intx_file->major), le64_to_cpu( intx_file->minor)); } if (intx_file->magic == INTX_CHARACTER_DEVICE && na->data_size == (s64)offsetof( INTX_FILE, device_end)) { stbuf->st_mode = S_IFCHR; stbuf->st_rdev = makedev(le64_to_cpu( intx_file->major), le64_to_cpu( intx_file->minor)); } if (intx_file->magic == INTX_SYMBOLIC_LINK) { char *target = NULL; int len; /* st_size should be set to length of * symlink target as multibyte string */ len = ntfs_ucstombs( intx_file->target, (na->data_size - offsetof(INTX_FILE, target)) / sizeof(ntfschar), &target, 0); if (len < 0) { res = -errno; free(intx_file); ntfs_attr_close(na); goto exit; } free(target); stbuf->st_mode = S_IFLNK; stbuf->st_size = len; } free(intx_file); } ntfs_attr_close(na); } stbuf->st_mode |= (0777 & ~ctx->fmask); } #ifndef DISABLE_PLUGINS ok: #endif /* DISABLE_PLUGINS */ if (withusermapping) { if (ntfs_get_owner_mode(scx,ni,stbuf) < 0) set_fuse_error(&res); } else { stbuf->st_uid = ctx->uid; stbuf->st_gid = ctx->gid; } if (S_ISLNK(stbuf->st_mode)) stbuf->st_mode |= 0777; nodata : stbuf->st_ino = ni->mft_no; #ifdef HAVE_STRUCT_STAT_ST_ATIMESPEC stbuf->st_atimespec = ntfs2timespec(ni->last_access_time); stbuf->st_ctimespec = ntfs2timespec(ni->last_mft_change_time); stbuf->st_mtimespec = ntfs2timespec(ni->last_data_change_time); #elif defined(HAVE_STRUCT_STAT_ST_ATIM) stbuf->st_atim = ntfs2timespec(ni->last_access_time); stbuf->st_ctim = ntfs2timespec(ni->last_mft_change_time); stbuf->st_mtim = ntfs2timespec(ni->last_data_change_time); #elif defined(HAVE_STRUCT_STAT_ST_ATIMENSEC) { struct timespec ts; ts = ntfs2timespec(ni->last_access_time); stbuf->st_atime = ts.tv_sec; stbuf->st_atimensec = ts.tv_nsec; ts = ntfs2timespec(ni->last_mft_change_time); stbuf->st_ctime = ts.tv_sec; stbuf->st_ctimensec = ts.tv_nsec; ts = ntfs2timespec(ni->last_data_change_time); stbuf->st_mtime = ts.tv_sec; stbuf->st_mtimensec = ts.tv_nsec; } #else #warning "No known way to set nanoseconds in struct stat !" { struct timespec ts; ts = ntfs2timespec(ni->last_access_time); stbuf->st_atime = ts.tv_sec; ts = ntfs2timespec(ni->last_mft_change_time); stbuf->st_ctime = ts.tv_sec; ts = ntfs2timespec(ni->last_data_change_time); stbuf->st_mtime = ts.tv_sec; } #endif exit: return (res); } static void ntfs_fuse_getattr(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi __attribute__((unused))) { int res; ntfs_inode *ni; struct stat stbuf; struct SECURITY_CONTEXT security; ni = ntfs_inode_open(ctx->vol, INODE(ino)); if (!ni) res = -errno; else { ntfs_fuse_fill_security_context(req, &security); res = ntfs_fuse_getstat(&security, ni, &stbuf); if (ntfs_inode_close(ni)) set_fuse_error(&res); } if (!res) fuse_reply_attr(req, &stbuf, ATTR_TIMEOUT); else fuse_reply_err(req, -res); } static __inline__ BOOL ntfs_fuse_fillstat(struct SECURITY_CONTEXT *scx, struct fuse_entry_param *pentry, u64 iref) { ntfs_inode *ni; BOOL ok = FALSE; pentry->ino = MREF(iref); ni = ntfs_inode_open(ctx->vol, pentry->ino); if (ni) { if (!ntfs_fuse_getstat(scx, ni, &pentry->attr)) { pentry->generation = 1; pentry->attr_timeout = ATTR_TIMEOUT; pentry->entry_timeout = ENTRY_TIMEOUT; ok = TRUE; } if (ntfs_inode_close(ni)) ok = FALSE; } return (ok); } static void ntfs_fuse_lookup(fuse_req_t req, fuse_ino_t parent, const char *name) { struct SECURITY_CONTEXT security; struct fuse_entry_param entry; ntfs_inode *dir_ni; u64 iref; BOOL ok = FALSE; if (strlen(name) < 256) { dir_ni = ntfs_inode_open(ctx->vol, INODE(parent)); if (dir_ni) { #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) /* * make sure the parent directory is searchable */ if (ntfs_fuse_fill_security_context(req, &security) && !ntfs_allowed_access(&security,dir_ni,S_IEXEC)) { ntfs_inode_close(dir_ni); errno = EACCES; } else { #else ntfs_fuse_fill_security_context(req, &security); #endif iref = ntfs_inode_lookup_by_mbsname(dir_ni, name); /* never return inodes 0 and 1 */ if (MREF(iref) <= 1) { iref = (u64)-1; errno = ENOENT; } ok = !ntfs_inode_close(dir_ni) && (iref != (u64)-1) && ntfs_fuse_fillstat( &security,&entry,iref); #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) } #endif } } else errno = ENAMETOOLONG; if (!ok) fuse_reply_err(req, errno); else fuse_reply_entry(req, &entry); } #ifndef DISABLE_PLUGINS /* * Get the link defined by a junction or symlink * (internal plugin) */ static int junction_readlink(ntfs_inode *ni, const REPARSE_POINT *reparse, char **pbuf) { int res; le32 tag; int lth; errno = 0; res = 0; *pbuf = ntfs_make_symlink(ni, ctx->abs_mnt_point); if (!*pbuf) { if (errno == EOPNOTSUPP) { *pbuf = (char*)ntfs_malloc(ntfs_bad_reparse_lth + 1); if (*pbuf) { if (reparse) tag = reparse->reparse_tag; else tag = const_cpu_to_le32(0); lth = snprintf(*pbuf, ntfs_bad_reparse_lth + 1, ntfs_bad_reparse, (long)le32_to_cpu(tag)); if (lth != ntfs_bad_reparse_lth) { free(*pbuf); *pbuf = (char*)NULL; res = -errno; } } else res = -ENOMEM; } else res = -errno; } return (res); } #endif /* DISABLE_PLUGINS */ static void ntfs_fuse_readlink(fuse_req_t req, fuse_ino_t ino) { ntfs_inode *ni = NULL; ntfs_attr *na = NULL; INTX_FILE *intx_file = NULL; char *buf = (char*)NULL; int res = 0; /* Get inode. */ ni = ntfs_inode_open(ctx->vol, INODE(ino)); if (!ni) { res = -errno; goto exit; } /* * Reparse point : analyze as a junction point */ if (ni->flags & FILE_ATTR_REPARSE_POINT) { REPARSE_POINT *reparse; le32 tag; int lth; #ifndef DISABLE_PLUGINS const plugin_operations_t *ops; res = CALL_REPARSE_PLUGIN(ni, readlink, &buf); /* plugin missing or reparse tag failing the check */ if (res && ((errno == ELIBACC) || (errno == EINVAL))) errno = EOPNOTSUPP; #else /* DISABLE_PLUGINS */ errno = 0; res = 0; buf = ntfs_make_symlink(ni, ctx->abs_mnt_point); #endif /* DISABLE_PLUGINS */ if (!buf && (errno == EOPNOTSUPP)) { buf = (char*)malloc(ntfs_bad_reparse_lth + 1); if (buf) { reparse = ntfs_get_reparse_point(ni); if (reparse) { tag = reparse->reparse_tag; free(reparse); } else tag = const_cpu_to_le32(0); lth = snprintf(buf, ntfs_bad_reparse_lth + 1, ntfs_bad_reparse, (long)le32_to_cpu(tag)); res = 0; if (lth != ntfs_bad_reparse_lth) { free(buf); buf = (char*)NULL; } } } if (!buf) res = -errno; goto exit; } /* Sanity checks. */ if (!(ni->flags & FILE_ATTR_SYSTEM)) { res = -EINVAL; goto exit; } na = ntfs_attr_open(ni, AT_DATA, AT_UNNAMED, 0); if (!na) { res = -errno; goto exit; } if ((size_t)na->data_size <= sizeof(INTX_FILE_TYPES)) { res = -EINVAL; goto exit; } if ((size_t)na->data_size > sizeof(INTX_FILE_TYPES) + sizeof(ntfschar) * PATH_MAX) { res = -ENAMETOOLONG; goto exit; } /* Receive file content. */ intx_file = (INTX_FILE*)ntfs_malloc(na->data_size); if (!intx_file) { res = -errno; goto exit; } if (ntfs_attr_pread(na, 0, na->data_size, intx_file) != na->data_size) { res = -errno; goto exit; } /* Sanity check. */ if (intx_file->magic != INTX_SYMBOLIC_LINK) { res = -EINVAL; goto exit; } /* Convert link from unicode to local encoding. */ if (ntfs_ucstombs(intx_file->target, (na->data_size - offsetof(INTX_FILE, target)) / sizeof(ntfschar), &buf, 0) < 0) { res = -errno; goto exit; } exit: if (intx_file) free(intx_file); if (na) ntfs_attr_close(na); if (ntfs_inode_close(ni)) set_fuse_error(&res); if (res < 0) fuse_reply_err(req, -res); else fuse_reply_readlink(req, buf); free(buf); } static int ntfs_fuse_filler(ntfs_fuse_fill_context_t *fill_ctx, const ntfschar *name, const int name_len, const int name_type, const s64 pos __attribute__((unused)), const MFT_REF mref, const unsigned dt_type __attribute__((unused))) { char *filename = NULL; int ret = 0; int filenamelen = -1; size_t sz; ntfs_fuse_fill_item_t *current; ntfs_fuse_fill_item_t *newone; if (name_type == FILE_NAME_DOS) return 0; if ((filenamelen = ntfs_ucstombs(name, name_len, &filename, 0)) < 0) { ntfs_log_perror("Filename decoding failed (inode %llu)", (unsigned long long)MREF(mref)); return -1; } /* never return inodes 0 and 1 */ if (MREF(mref) > 1) { struct stat st = { .st_ino = MREF(mref) }; #ifndef DISABLE_PLUGINS ntfs_inode *ni; #endif /* DISABLE_PLUGINS */ switch (dt_type) { case NTFS_DT_DIR : st.st_mode = S_IFDIR | (0777 & ~ctx->dmask); break; case NTFS_DT_LNK : st.st_mode = S_IFLNK | 0777; break; case NTFS_DT_FIFO : st.st_mode = S_IFIFO; break; case NTFS_DT_SOCK : st.st_mode = S_IFSOCK; break; case NTFS_DT_BLK : st.st_mode = S_IFBLK; break; case NTFS_DT_CHR : st.st_mode = S_IFCHR; break; case NTFS_DT_REPARSE : st.st_mode = S_IFLNK | 0777; /* default */ #ifndef DISABLE_PLUGINS /* get emulated type from plugin if available */ ni = ntfs_inode_open(ctx->vol, mref); if (ni && (ni->flags & FILE_ATTR_REPARSE_POINT)) { const plugin_operations_t *ops; REPARSE_POINT *reparse; int res; res = CALL_REPARSE_PLUGIN(ni, getattr, &st); if (!res) apply_umask(&st); else st.st_mode = S_IFLNK; } if (ni) ntfs_inode_close(ni); #endif /* DISABLE_PLUGINS */ break; default : /* unexpected types shown as plain files */ case NTFS_DT_REG : st.st_mode = S_IFREG | (0777 & ~ctx->fmask); break; } #if defined(__APPLE__) || defined(__DARWIN__) /* * Returning file names larger than MAXNAMLEN (255) bytes * causes Darwin/Mac OS X to bug out and skip the entry. */ if (filenamelen > MAXNAMLEN) { ntfs_log_debug("Truncating %d byte filename to " "%d bytes.\n", filenamelen, MAXNAMLEN); ntfs_log_debug(" before: '%s'\n", filename); memset(filename + MAXNAMLEN, 0, filenamelen - MAXNAMLEN); ntfs_log_debug(" after: '%s'\n", filename); } #elif defined(__sun) && defined (__SVR4) /* * Returning file names larger than MAXNAMELEN (256) bytes * causes Solaris/Illumos to return an I/O error from the system * call. * However we also need space for a terminating NULL, or user * space tools will bug out since they expect a NULL terminator. * Effectively the maximum length of a file name is MAXNAMELEN - * 1 (255). */ if (filenamelen > (MAXNAMELEN - 1)) { ntfs_log_debug("Truncating %d byte filename to %d " "bytes.\n", filenamelen, MAXNAMELEN - 1); ntfs_log_debug(" before: '%s'\n", filename); memset(&filename[MAXNAMELEN - 1], 0, filenamelen - (MAXNAMELEN - 1)); ntfs_log_debug(" after: '%s'\n", filename); } #endif /* defined(__APPLE__) || defined(__DARWIN__), ... */ current = fill_ctx->last; sz = fuse_add_direntry(fill_ctx->req, ¤t->buf[current->off], current->bufsize - current->off, filename, &st, current->off + fill_ctx->off); if (!sz || ((current->off + sz) > current->bufsize)) { newone = (ntfs_fuse_fill_item_t*)ntfs_malloc (sizeof(ntfs_fuse_fill_item_t) + current->bufsize); if (newone) { newone->off = 0; newone->bufsize = current->bufsize; newone->next = (ntfs_fuse_fill_item_t*)NULL; current->next = newone; fill_ctx->last = newone; fill_ctx->off += current->off; current = newone; sz = fuse_add_direntry(fill_ctx->req, current->buf, current->bufsize - current->off, filename, &st, fill_ctx->off); if (!sz) { errno = EIO; ntfs_log_error("Could not add a" " directory entry (inode %lld)\n", (unsigned long long)MREF(mref)); } } else { sz = 0; errno = ENOMEM; } } if (sz) { current->off += sz; } else { ret = -1; } } free(filename); return ret; } static void ntfs_fuse_opendir(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi) { int res = 0; ntfs_inode *ni; int accesstype; ntfs_fuse_fill_context_t *fill; struct SECURITY_CONTEXT security; ni = ntfs_inode_open(ctx->vol, INODE(ino)); if (ni) { if (ntfs_fuse_fill_security_context(req, &security)) { if (fi->flags & O_WRONLY) accesstype = S_IWRITE; else if (fi->flags & O_RDWR) accesstype = S_IWRITE | S_IREAD; else accesstype = S_IREAD; if (!ntfs_allowed_access(&security,ni,accesstype)) res = -EACCES; } if (ni->flags & FILE_ATTR_REPARSE_POINT) { #ifndef DISABLE_PLUGINS const plugin_operations_t *ops; REPARSE_POINT *reparse; fi->fh = 0; res = CALL_REPARSE_PLUGIN(ni, opendir, fi); #else /* DISABLE_PLUGINS */ res = -EOPNOTSUPP; #endif /* DISABLE_PLUGINS */ } if (ntfs_inode_close(ni)) set_fuse_error(&res); if (!res) { fill = (ntfs_fuse_fill_context_t*) ntfs_malloc(sizeof(ntfs_fuse_fill_context_t)); if (!fill) res = -errno; else { fill->first = fill->last = (ntfs_fuse_fill_item_t*)NULL; fill->filled = FALSE; fill->ino = ino; fill->off = 0; #ifndef DISABLE_PLUGINS fill->fh = fi->fh; #endif /* DISABLE_PLUGINS */ } fi->fh = (long)fill; } } else res = -errno; if (!res) fuse_reply_open(req, fi); else fuse_reply_err(req, -res); } static void ntfs_fuse_releasedir(fuse_req_t req, fuse_ino_t ino __attribute__((unused)), struct fuse_file_info *fi) { #ifndef DISABLE_PLUGINS struct fuse_file_info ufi; ntfs_inode *ni; #endif /* DISABLE_PLUGINS */ ntfs_fuse_fill_context_t *fill; ntfs_fuse_fill_item_t *current; int res; res = 0; fill = (ntfs_fuse_fill_context_t*)(long)fi->fh; if (fill && (fill->ino == ino)) { /* make sure to clear results */ current = fill->first; while (current) { current = current->next; free(fill->first); fill->first = current; } #ifndef DISABLE_PLUGINS if (fill->fh) { const plugin_operations_t *ops; REPARSE_POINT *reparse; ni = ntfs_inode_open(ctx->vol, INODE(ino)); if (ni) { if (ni->flags & FILE_ATTR_REPARSE_POINT) { memcpy(&ufi, fi, sizeof(ufi)); ufi.fh = fill->fh; res = CALL_REPARSE_PLUGIN(ni, release, &ufi); } if (ntfs_inode_close(ni) && !res) res = -errno; } else res = -errno; } #endif /* DISABLE_PLUGINS */ fill->ino = 0; free(fill); } fuse_reply_err(req, -res); } static void ntfs_fuse_readdir(fuse_req_t req, fuse_ino_t ino, size_t size, off_t off __attribute__((unused)), struct fuse_file_info *fi __attribute__((unused))) { #ifndef DISABLE_PLUGINS struct fuse_file_info ufi; #endif /* DISABLE_PLUGINS */ ntfs_fuse_fill_item_t *first; ntfs_fuse_fill_item_t *current; ntfs_fuse_fill_context_t *fill; ntfs_inode *ni; s64 pos = 0; int err = 0; fill = (ntfs_fuse_fill_context_t*)(long)fi->fh; if (fill && (fill->ino == ino)) { if (fill->filled && !off) { /* Rewinding : make sure to clear existing results */ current = fill->first; while (current) { current = current->next; free(fill->first); fill->first = current; } fill->filled = FALSE; } if (!fill->filled) { /* initial call : build the full list */ current = (ntfs_fuse_fill_item_t*)NULL; first = (ntfs_fuse_fill_item_t*)ntfs_malloc (sizeof(ntfs_fuse_fill_item_t) + size); if (first) { first->bufsize = size; first->off = 0; first->next = (ntfs_fuse_fill_item_t*)NULL; fill->req = req; fill->first = first; fill->last = first; fill->off = 0; ni = ntfs_inode_open(ctx->vol,INODE(ino)); if (!ni) err = -errno; else { if (ni->flags & FILE_ATTR_REPARSE_POINT) { #ifndef DISABLE_PLUGINS const plugin_operations_t *ops; REPARSE_POINT *reparse; memcpy(&ufi, fi, sizeof(ufi)); ufi.fh = fill->fh; err = CALL_REPARSE_PLUGIN(ni, readdir, &pos, fill, (ntfs_filldir_t) ntfs_fuse_filler, &ufi); #else /* DISABLE_PLUGINS */ err = -EOPNOTSUPP; #endif /* DISABLE_PLUGINS */ } else { if (ntfs_readdir(ni, &pos, fill, (ntfs_filldir_t) ntfs_fuse_filler)) err = -errno; } fill->filled = TRUE; ntfs_fuse_update_times(ni, NTFS_UPDATE_ATIME); if (ntfs_inode_close(ni)) set_fuse_error(&err); } if (!err) { off_t loc = 0; /* * In some circumstances, the queue gets * reinitialized by releasedir() + opendir(), * apparently always on end of partial buffer. * Files may be missing or duplicated. */ while (first && ((loc < off) || !first->off)) { loc += first->off; fill->first = first->next; free(first); first = fill->first; } current = first; } } else err = -errno; } else { /* subsequent call : return next non-empty buffer */ current = fill->first; while (current && !current->off) { current = current->next; free(fill->first); fill->first = current; } } if (!err) { if (current) { fuse_reply_buf(req, current->buf, current->off); fill->first = current->next; free(current); } else { fuse_reply_buf(req, (char*)NULL, 0); /* reply sent, now must exit with no error */ } } } else { errno = EIO; err = -errno; ntfs_log_error("Uninitialized fuse_readdir()\n"); } if (err) fuse_reply_err(req, -err); } static void ntfs_fuse_open(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi) { ntfs_inode *ni; ntfs_attr *na = NULL; struct open_file *of; int state = 0; int res = 0; #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) int accesstype; struct SECURITY_CONTEXT security; #endif ni = ntfs_inode_open(ctx->vol, INODE(ino)); if (ni) { if (!(ni->flags & FILE_ATTR_REPARSE_POINT)) { na = ntfs_attr_open(ni, AT_DATA, AT_UNNAMED, 0); if (!na) { res = -errno; goto close; } } #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) if (ntfs_fuse_fill_security_context(req, &security)) { if (fi->flags & O_WRONLY) accesstype = S_IWRITE; else if (fi->flags & O_RDWR) accesstype = S_IWRITE | S_IREAD; else accesstype = S_IREAD; /* check whether requested access is allowed */ if (!ntfs_allowed_access(&security, ni,accesstype)) res = -EACCES; } #endif if (ni->flags & FILE_ATTR_REPARSE_POINT) { #ifndef DISABLE_PLUGINS const plugin_operations_t *ops; REPARSE_POINT *reparse; fi->fh = 0; res = CALL_REPARSE_PLUGIN(ni, open, fi); if (!res && fi->fh) { state = CLOSE_REPARSE; } #else /* DISABLE_PLUGINS */ res = -EOPNOTSUPP; #endif /* DISABLE_PLUGINS */ goto close; } if ((res >= 0) && (fi->flags & (O_WRONLY | O_RDWR))) { /* mark a future need to compress the last chunk */ if (na->data_flags & ATTR_COMPRESSION_MASK) state |= CLOSE_COMPRESSED; #ifdef HAVE_SETXATTR /* extended attributes interface required */ /* mark a future need to fixup encrypted inode */ if (ctx->efs_raw && !(na->data_flags & ATTR_IS_ENCRYPTED) && (ni->flags & FILE_ATTR_ENCRYPTED)) state |= CLOSE_ENCRYPTED; #endif /* HAVE_SETXATTR */ /* mark a future need to update the mtime */ if (ctx->dmtime) state |= CLOSE_DMTIME; /* deny opening metadata files for writing */ if (ino < FILE_first_user) res = -EPERM; } ntfs_attr_close(na); close: if (ntfs_inode_close(ni)) set_fuse_error(&res); } else res = -errno; if (res >= 0) { of = (struct open_file*)malloc(sizeof(struct open_file)); if (of) { of->parent = 0; of->ino = ino; of->state = state; #ifndef DISABLE_PLUGINS memcpy(&of->fi, fi, sizeof(struct fuse_file_info)); #endif /* DISABLE_PLUGINS */ of->next = ctx->open_files; of->previous = (struct open_file*)NULL; if (ctx->open_files) ctx->open_files->previous = of; ctx->open_files = of; fi->fh = (long)of; } } if (res) fuse_reply_err(req, -res); else fuse_reply_open(req, fi); } static void ntfs_fuse_read(fuse_req_t req, fuse_ino_t ino, size_t size, off_t offset, struct fuse_file_info *fi __attribute__((unused))) { ntfs_inode *ni = NULL; ntfs_attr *na = NULL; int res; char *buf = (char*)NULL; s64 total = 0; s64 max_read; if (!size) { res = 0; goto exit; } buf = (char*)ntfs_malloc(size); if (!buf) { res = -errno; goto exit; } ni = ntfs_inode_open(ctx->vol, INODE(ino)); if (!ni) { res = -errno; goto exit; } if (ni->flags & FILE_ATTR_REPARSE_POINT) { #ifndef DISABLE_PLUGINS const plugin_operations_t *ops; REPARSE_POINT *reparse; struct open_file *of; of = (struct open_file*)(long)fi->fh; res = CALL_REPARSE_PLUGIN(ni, read, buf, size, offset, &of->fi); if (res >= 0) { goto stamps; } #else /* DISABLE_PLUGINS */ res = -EOPNOTSUPP; #endif /* DISABLE_PLUGINS */ goto exit; } na = ntfs_attr_open(ni, AT_DATA, AT_UNNAMED, 0); if (!na) { res = -errno; goto exit; } max_read = na->data_size; #ifdef HAVE_SETXATTR /* extended attributes interface required */ /* limit reads at next 512 byte boundary for encrypted attributes */ if (ctx->efs_raw && max_read && (na->data_flags & ATTR_IS_ENCRYPTED) && NAttrNonResident(na)) { max_read = ((na->data_size+511) & ~511) + 2; } #endif /* HAVE_SETXATTR */ if (offset + (off_t)size > max_read) { if (max_read < offset) goto ok; size = max_read - offset; } while (size > 0) { s64 ret = ntfs_attr_pread(na, offset, size, buf + total); if (ret != (s64)size) ntfs_log_perror("ntfs_attr_pread error reading inode %lld at " "offset %lld: %lld <> %lld", (long long)ni->mft_no, (long long)offset, (long long)size, (long long)ret); if (ret <= 0 || ret > (s64)size) { res = (ret < 0) ? -errno : -EIO; goto exit; } size -= ret; offset += ret; total += ret; } ok: res = total; #ifndef DISABLE_PLUGINS stamps : #endif /* DISABLE_PLUGINS */ ntfs_fuse_update_times(ni, NTFS_UPDATE_ATIME); exit: if (na) ntfs_attr_close(na); if (ntfs_inode_close(ni)) set_fuse_error(&res); if (res < 0) fuse_reply_err(req, -res); else fuse_reply_buf(req, buf, res); free(buf); } static void ntfs_fuse_write(fuse_req_t req, fuse_ino_t ino, const char *buf, size_t size, off_t offset, struct fuse_file_info *fi __attribute__((unused))) { ntfs_inode *ni = NULL; ntfs_attr *na = NULL; int res, total = 0; ni = ntfs_inode_open(ctx->vol, INODE(ino)); if (!ni) { res = -errno; goto exit; } if (ni->flags & FILE_ATTR_REPARSE_POINT) { #ifndef DISABLE_PLUGINS const plugin_operations_t *ops; REPARSE_POINT *reparse; struct open_file *of; of = (struct open_file*)(long)fi->fh; res = CALL_REPARSE_PLUGIN(ni, write, buf, size, offset, &of->fi); if (res >= 0) { goto stamps; } #else /* DISABLE_PLUGINS */ res = -EOPNOTSUPP; #endif /* DISABLE_PLUGINS */ goto exit; } na = ntfs_attr_open(ni, AT_DATA, AT_UNNAMED, 0); if (!na) { res = -errno; goto exit; } while (size) { s64 ret = ntfs_attr_pwrite(na, offset, size, buf + total); if (ret <= 0) { res = -errno; goto exit; } size -= ret; offset += ret; total += ret; } res = total; #ifndef DISABLE_PLUGINS stamps : #endif /* DISABLE_PLUGINS */ if ((res > 0) && (!ctx->dmtime || (sle64_to_cpu(ntfs_current_time()) - sle64_to_cpu(ni->last_data_change_time)) > ctx->dmtime)) ntfs_fuse_update_times(ni, NTFS_UPDATE_MCTIME); exit: if (na) ntfs_attr_close(na); if (res > 0) set_archive(ni); if (ntfs_inode_close(ni)) set_fuse_error(&res); if (res < 0) fuse_reply_err(req, -res); else fuse_reply_write(req, res); } static int ntfs_fuse_chmod(struct SECURITY_CONTEXT *scx, fuse_ino_t ino, mode_t mode, struct stat *stbuf) { int res = 0; ntfs_inode *ni; /* Unsupported if inherit or no user mapping has been defined */ if ((!scx->mapping[MAPUSERS] || ctx->inherit) && !ctx->silent) { res = -EOPNOTSUPP; } else { ni = ntfs_inode_open(ctx->vol, INODE(ino)); if (!ni) res = -errno; else { /* ignore if Windows inheritance is forced */ if (scx->mapping[MAPUSERS] && !ctx->inherit) { if (ntfs_set_mode(scx, ni, mode)) res = -errno; else { ntfs_fuse_update_times(ni, NTFS_UPDATE_CTIME); /* * Must return updated times, and * inode has been updated, so hope * we get no further errors */ res = ntfs_fuse_getstat(scx, ni, stbuf); } NInoSetDirty(ni); } else res = ntfs_fuse_getstat(scx, ni, stbuf); if (ntfs_inode_close(ni)) set_fuse_error(&res); } } return res; } static int ntfs_fuse_chown(struct SECURITY_CONTEXT *scx, fuse_ino_t ino, uid_t uid, gid_t gid, struct stat *stbuf) { ntfs_inode *ni; int res; /* Unsupported if inherit or no user mapping has been defined */ if ((!scx->mapping[MAPUSERS] || ctx->inherit) && !ctx->silent && ((uid != ctx->uid) || (gid != ctx->gid))) res = -EOPNOTSUPP; else { res = 0; ni = ntfs_inode_open(ctx->vol, INODE(ino)); if (!ni) res = -errno; else { /* ignore if Windows inheritance is forced */ if (scx->mapping[MAPUSERS] && !ctx->inherit && (((int)uid != -1) || ((int)gid != -1))) { if (ntfs_set_owner(scx, ni, uid, gid)) res = -errno; else { ntfs_fuse_update_times(ni, NTFS_UPDATE_CTIME); /* * Must return updated times, and * inode has been updated, so hope * we get no further errors */ res = ntfs_fuse_getstat(scx, ni, stbuf); } } else res = ntfs_fuse_getstat(scx, ni, stbuf); if (ntfs_inode_close(ni)) set_fuse_error(&res); } } return (res); } static int ntfs_fuse_chownmod(struct SECURITY_CONTEXT *scx, fuse_ino_t ino, uid_t uid, gid_t gid, mode_t mode, struct stat *stbuf) { ntfs_inode *ni; int res; /* Unsupported if inherit or no user mapping has been defined */ if ((!scx->mapping[MAPUSERS] || ctx->inherit) && !ctx->silent && ((uid != ctx->uid) || (gid != ctx->gid))) res = -EOPNOTSUPP; else { res = 0; ni = ntfs_inode_open(ctx->vol, INODE(ino)); if (!ni) res = -errno; else { /* ignore if Windows inheritance is forced */ if (scx->mapping[MAPUSERS] && !ctx->inherit) { if (ntfs_set_ownmod(scx, ni, uid, gid, mode)) res = -errno; else { ntfs_fuse_update_times(ni, NTFS_UPDATE_CTIME); /* * Must return updated times, and * inode has been updated, so hope * we get no further errors */ res = ntfs_fuse_getstat(scx, ni, stbuf); } } else res = ntfs_fuse_getstat(scx, ni, stbuf); if (ntfs_inode_close(ni)) set_fuse_error(&res); } } return (res); } static int ntfs_fuse_trunc(struct SECURITY_CONTEXT *scx, fuse_ino_t ino, #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) off_t size, BOOL chkwrite, struct stat *stbuf) #else off_t size, BOOL chkwrite __attribute__((unused)), struct stat *stbuf) #endif { ntfs_inode *ni = NULL; ntfs_attr *na = NULL; int res; s64 oldsize; ni = ntfs_inode_open(ctx->vol, INODE(ino)); if (!ni) goto exit; /* deny truncating metadata files */ if (ino < FILE_first_user) { errno = EPERM; goto exit; } if (!(ni->flags & FILE_ATTR_REPARSE_POINT)) { na = ntfs_attr_open(ni, AT_DATA, AT_UNNAMED, 0); if (!na) goto exit; } #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) /* * deny truncation if cannot write to file * (already checked for ftruncate()) */ if (scx->mapping[MAPUSERS] && chkwrite && !ntfs_allowed_access(scx, ni, S_IWRITE)) { errno = EACCES; goto exit; } #endif if (ni->flags & FILE_ATTR_REPARSE_POINT) { #ifndef DISABLE_PLUGINS const plugin_operations_t *ops; REPARSE_POINT *reparse; res = CALL_REPARSE_PLUGIN(ni, truncate, size); if (!res) { set_archive(ni); goto stamps; } #else /* DISABLE_PLUGINS */ res = -EOPNOTSUPP; #endif /* DISABLE_PLUGINS */ goto exit; } /* * for compressed files, upsizing is done by inserting a final * zero, which is optimized as creating a hole when possible. */ oldsize = na->data_size; if ((na->data_flags & ATTR_COMPRESSION_MASK) && (size > na->initialized_size)) { char zero = 0; if (ntfs_attr_pwrite(na, size - 1, 1, &zero) <= 0) goto exit; } else if (ntfs_attr_truncate(na, size)) goto exit; if (oldsize != size) set_archive(ni); #ifndef DISABLE_PLUGINS stamps : #endif /* DISABLE_PLUGINS */ ntfs_fuse_update_times(ni, NTFS_UPDATE_MCTIME); res = ntfs_fuse_getstat(scx, ni, stbuf); errno = (res ? -res : 0); exit: res = -errno; ntfs_attr_close(na); if (ntfs_inode_close(ni)) set_fuse_error(&res); return res; } #if defined(HAVE_UTIMENSAT) & defined(FUSE_SET_ATTR_ATIME_NOW) static int ntfs_fuse_utimens(struct SECURITY_CONTEXT *scx, fuse_ino_t ino, struct stat *stin, struct stat *stbuf, int to_set) { ntfs_inode *ni; int res = 0; ni = ntfs_inode_open(ctx->vol, INODE(ino)); if (!ni) return -errno; /* no check or update if both UTIME_OMIT */ if (to_set & (FUSE_SET_ATTR_ATIME + FUSE_SET_ATTR_MTIME)) { #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) if (ntfs_allowed_as_owner(scx, ni) || ((to_set & FUSE_SET_ATTR_ATIME_NOW) && (to_set & FUSE_SET_ATTR_MTIME_NOW) && ntfs_allowed_access(scx, ni, S_IWRITE))) { #endif ntfs_time_update_flags mask = NTFS_UPDATE_CTIME; if (to_set & FUSE_SET_ATTR_ATIME_NOW) mask |= NTFS_UPDATE_ATIME; else if (to_set & FUSE_SET_ATTR_ATIME) { #ifdef HAVE_STRUCT_STAT_ST_ATIMESPEC ni->last_access_time = timespec2ntfs(stin->st_atimespec); #elif defined(HAVE_STRUCT_STAT_ST_ATIM) ni->last_access_time = timespec2ntfs(stin->st_atim); #else ni->last_access_time.tv_sec = stin->st_atime; #ifdef HAVE_STRUCT_STAT_ST_ATIMENSEC ni->last_access_time.tv_nsec = stin->st_atimensec; #endif #endif } if (to_set & FUSE_SET_ATTR_MTIME_NOW) mask |= NTFS_UPDATE_MTIME; else if (to_set & FUSE_SET_ATTR_MTIME) { #ifdef HAVE_STRUCT_STAT_ST_ATIMESPEC ni->last_data_change_time = timespec2ntfs(stin->st_mtimespec); #elif defined(HAVE_STRUCT_STAT_ST_ATIM) ni->last_data_change_time = timespec2ntfs(stin->st_mtim); #else ni->last_data_change_time.tv_sec = stin->st_mtime; #ifdef HAVE_STRUCT_STAT_ST_ATIMENSEC ni->last_data_change_time.tv_nsec = stin->st_mtimensec; #endif #endif } ntfs_inode_update_times(ni, mask); #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) } else res = -errno; #endif } if (!res) res = ntfs_fuse_getstat(scx, ni, stbuf); if (ntfs_inode_close(ni)) set_fuse_error(&res); return res; } #else /* defined(HAVE_UTIMENSAT) & defined(FUSE_SET_ATTR_ATIME_NOW) */ static int ntfs_fuse_utime(struct SECURITY_CONTEXT *scx, fuse_ino_t ino, struct stat *stin, struct stat *stbuf) { ntfs_inode *ni; int res = 0; struct timespec actime; struct timespec modtime; #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) BOOL ownerok; BOOL writeok; #endif ni = ntfs_inode_open(ctx->vol, INODE(ino)); if (!ni) return -errno; #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) ownerok = ntfs_allowed_as_owner(scx, ni); if (stin) { /* * fuse never calls with a NULL buf and we do not * know whether the specific condition can be applied * So we have to accept updating by a non-owner having * write access. */ writeok = !ownerok && (stin->st_atime == stin->st_mtime) && ntfs_allowed_access(scx, ni, S_IWRITE); /* Must be owner */ if (!ownerok && !writeok) res = (stin->st_atime == stin->st_mtime ? -EACCES : -EPERM); else { actime.tv_sec = stin->st_atime; actime.tv_nsec = 0; modtime.tv_sec = stin->st_mtime; modtime.tv_nsec = 0; ni->last_access_time = timespec2ntfs(actime); ni->last_data_change_time = timespec2ntfs(modtime); ntfs_fuse_update_times(ni, NTFS_UPDATE_CTIME); } } else { /* Must be owner or have write access */ writeok = !ownerok && ntfs_allowed_access(scx, ni, S_IWRITE); if (!ownerok && !writeok) res = -EACCES; else ntfs_inode_update_times(ni, NTFS_UPDATE_AMCTIME); } #else if (stin) { actime.tv_sec = stin->st_atime; actime.tv_nsec = 0; modtime.tv_sec = stin->st_mtime; modtime.tv_nsec = 0; ni->last_access_time = timespec2ntfs(actime); ni->last_data_change_time = timespec2ntfs(modtime); ntfs_fuse_update_times(ni, NTFS_UPDATE_CTIME); } else ntfs_inode_update_times(ni, NTFS_UPDATE_AMCTIME); #endif res = ntfs_fuse_getstat(scx, ni, stbuf); if (ntfs_inode_close(ni)) set_fuse_error(&res); return res; } #endif /* defined(HAVE_UTIMENSAT) & defined(FUSE_SET_ATTR_ATIME_NOW) */ static void ntfs_fuse_setattr(fuse_req_t req, fuse_ino_t ino, struct stat *attr, int to_set, struct fuse_file_info *fi __attribute__((unused))) { struct stat stbuf; ntfs_inode *ni; int res; struct SECURITY_CONTEXT security; res = 0; ntfs_fuse_fill_security_context(req, &security); /* no flags */ if (!(to_set & (FUSE_SET_ATTR_MODE | FUSE_SET_ATTR_UID | FUSE_SET_ATTR_GID | FUSE_SET_ATTR_SIZE | FUSE_SET_ATTR_ATIME | FUSE_SET_ATTR_MTIME))) { ni = ntfs_inode_open(ctx->vol, INODE(ino)); if (!ni) res = -errno; else { res = ntfs_fuse_getstat(&security, ni, &stbuf); if (ntfs_inode_close(ni)) set_fuse_error(&res); } } /* some set of uid/gid/mode */ if (to_set & (FUSE_SET_ATTR_MODE | FUSE_SET_ATTR_UID | FUSE_SET_ATTR_GID)) { switch (to_set & (FUSE_SET_ATTR_MODE | FUSE_SET_ATTR_UID | FUSE_SET_ATTR_GID)) { case FUSE_SET_ATTR_MODE : res = ntfs_fuse_chmod(&security, ino, attr->st_mode & 07777, &stbuf); break; case FUSE_SET_ATTR_UID : res = ntfs_fuse_chown(&security, ino, attr->st_uid, (gid_t)-1, &stbuf); break; case FUSE_SET_ATTR_GID : res = ntfs_fuse_chown(&security, ino, (uid_t)-1, attr->st_gid, &stbuf); break; case FUSE_SET_ATTR_UID + FUSE_SET_ATTR_GID : res = ntfs_fuse_chown(&security, ino, attr->st_uid, attr->st_gid, &stbuf); break; case FUSE_SET_ATTR_UID + FUSE_SET_ATTR_MODE: res = ntfs_fuse_chownmod(&security, ino, attr->st_uid, (gid_t)-1,attr->st_mode, &stbuf); break; case FUSE_SET_ATTR_GID + FUSE_SET_ATTR_MODE: res = ntfs_fuse_chownmod(&security, ino, (uid_t)-1, attr->st_gid,attr->st_mode, &stbuf); break; case FUSE_SET_ATTR_UID + FUSE_SET_ATTR_GID + FUSE_SET_ATTR_MODE: res = ntfs_fuse_chownmod(&security, ino, attr->st_uid, attr->st_gid,attr->st_mode, &stbuf); break; default : break; } } /* size */ if (!res && (to_set & FUSE_SET_ATTR_SIZE)) { res = ntfs_fuse_trunc(&security, ino, attr->st_size, !fi, &stbuf); } /* some set of atime/mtime */ if (!res && (to_set & (FUSE_SET_ATTR_ATIME + FUSE_SET_ATTR_MTIME))) { #if defined(HAVE_UTIMENSAT) & defined(FUSE_SET_ATTR_ATIME_NOW) res = ntfs_fuse_utimens(&security, ino, attr, &stbuf, to_set); #else /* defined(HAVE_UTIMENSAT) & defined(FUSE_SET_ATTR_ATIME_NOW) */ res = ntfs_fuse_utime(&security, ino, attr, &stbuf); #endif /* defined(HAVE_UTIMENSAT) & defined(FUSE_SET_ATTR_ATIME_NOW) */ } if (res) fuse_reply_err(req, -res); else fuse_reply_attr(req, &stbuf, ATTR_TIMEOUT); } #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) static void ntfs_fuse_access(fuse_req_t req, fuse_ino_t ino, int mask) { int res = 0; int mode; ntfs_inode *ni; struct SECURITY_CONTEXT security; /* JPA return unsupported if no user mapping has been defined */ if (!ntfs_fuse_fill_security_context(req, &security)) { if (ctx->silent) res = 0; else res = -EOPNOTSUPP; } else { ni = ntfs_inode_open(ctx->vol, INODE(ino)); if (!ni) { res = -errno; } else { mode = 0; if (mask & (X_OK | W_OK | R_OK)) { if (mask & X_OK) mode += S_IEXEC; if (mask & W_OK) mode += S_IWRITE; if (mask & R_OK) mode += S_IREAD; if (!ntfs_allowed_access(&security, ni, mode)) res = -errno; } if (ntfs_inode_close(ni)) set_fuse_error(&res); } } if (res < 0) fuse_reply_err(req, -res); else fuse_reply_err(req, 0); } #endif /* !KERNELPERMS | (POSIXACLS & !KERNELACLS) */ static int ntfs_fuse_create(fuse_req_t req, fuse_ino_t parent, const char *name, mode_t typemode, dev_t dev, struct fuse_entry_param *e, const char *target, struct fuse_file_info *fi) { ntfschar *uname = NULL, *utarget = NULL; ntfs_inode *dir_ni = NULL, *ni; struct open_file *of; int state = 0; le32 securid; gid_t gid; mode_t dsetgid; mode_t type = typemode & ~07777; mode_t perm; struct SECURITY_CONTEXT security; int res = 0, uname_len, utarget_len; /* Generate unicode filename. */ uname_len = ntfs_mbstoucs(name, &uname); if ((uname_len < 0) || (ctx->windows_names && ntfs_forbidden_names(ctx->vol,uname,uname_len,TRUE))) { res = -errno; goto exit; } /* Deny creating into $Extend */ if (parent == FILE_Extend) { res = -EPERM; goto exit; } /* Open parent directory. */ dir_ni = ntfs_inode_open(ctx->vol, INODE(parent)); if (!dir_ni) { res = -errno; goto exit; } #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) /* make sure parent directory is writeable and executable */ if (!ntfs_fuse_fill_security_context(req, &security) || ntfs_allowed_create(&security, dir_ni, &gid, &dsetgid)) { #else ntfs_fuse_fill_security_context(req, &security); ntfs_allowed_create(&security, dir_ni, &gid, &dsetgid); #endif if (S_ISDIR(type)) perm = (typemode & ~ctx->dmask & 0777) | (dsetgid & S_ISGID); else if ((ctx->special_files == NTFS_FILES_WSL) && S_ISLNK(type)) perm = typemode | 0777; else perm = typemode & ~ctx->fmask & 0777; /* * Try to get a security id available for * file creation (from inheritance or argument). * This is not possible for NTFS 1.x, and we will * have to build a security attribute later. */ if (!ctx->security.mapping[MAPUSERS]) securid = const_cpu_to_le32(0); else if (ctx->inherit) securid = ntfs_inherited_id(&security, dir_ni, S_ISDIR(type)); else #if POSIXACLS securid = ntfs_alloc_securid(&security, security.uid, gid, dir_ni, perm, S_ISDIR(type)); #else securid = ntfs_alloc_securid(&security, security.uid, gid, perm & ~security.umask, S_ISDIR(type)); #endif /* Create object specified in @type. */ if (dir_ni->flags & FILE_ATTR_REPARSE_POINT) { #ifndef DISABLE_PLUGINS const plugin_operations_t *ops; REPARSE_POINT *reparse; reparse = (REPARSE_POINT*)NULL; ops = select_reparse_plugin(ctx, dir_ni, &reparse); if (ops && ops->create) { ni = (*ops->create)(dir_ni, reparse, securid, uname, uname_len, type); } else { ni = (ntfs_inode*)NULL; errno = EOPNOTSUPP; } free(reparse); #else /* DISABLE_PLUGINS */ ni = (ntfs_inode*)NULL; errno = EOPNOTSUPP; #endif /* DISABLE_PLUGINS */ } else { switch (type) { case S_IFCHR: case S_IFBLK: ni = ntfs_create_device(dir_ni, securid, uname, uname_len, type, dev); break; case S_IFLNK: utarget_len = ntfs_mbstoucs(target, &utarget); if (utarget_len < 0) { res = -errno; goto exit; } ni = ntfs_create_symlink(dir_ni, securid, uname, uname_len, utarget, utarget_len); break; default: ni = ntfs_create(dir_ni, securid, uname, uname_len, type); break; } } if (ni) { /* * set the security attribute if a security id * could not be allocated (eg NTFS 1.x) */ if (ctx->security.mapping[MAPUSERS]) { #if POSIXACLS if (!securid && ntfs_set_inherited_posix(&security, ni, security.uid, gid, dir_ni, perm) < 0) set_fuse_error(&res); #else if (!securid && ntfs_set_owner_mode(&security, ni, security.uid, gid, perm & ~security.umask) < 0) set_fuse_error(&res); #endif } set_archive(ni); /* mark a need to compress the end of file */ if (fi && (ni->flags & FILE_ATTR_COMPRESSED)) { state |= CLOSE_COMPRESSED; } #ifdef HAVE_SETXATTR /* extended attributes interface required */ /* mark a future need to fixup encrypted inode */ if (fi && ctx->efs_raw && (ni->flags & FILE_ATTR_ENCRYPTED)) state |= CLOSE_ENCRYPTED; #endif /* HAVE_SETXATTR */ if (fi && ctx->dmtime) state |= CLOSE_DMTIME; ntfs_inode_update_mbsname(dir_ni, name, ni->mft_no); NInoSetDirty(ni); e->ino = ni->mft_no; e->generation = 1; e->attr_timeout = ATTR_TIMEOUT; e->entry_timeout = ENTRY_TIMEOUT; res = ntfs_fuse_getstat(&security, ni, &e->attr); /* * closing ni requires access to dir_ni to * synchronize the index, avoid double opening. */ if (ntfs_inode_close_in_dir(ni, dir_ni)) set_fuse_error(&res); ntfs_fuse_update_times(dir_ni, NTFS_UPDATE_MCTIME); } else res = -errno; #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) } else res = -errno; #endif exit: free(uname); if (ntfs_inode_close(dir_ni)) set_fuse_error(&res); if (utarget) free(utarget); if ((res >= 0) && fi) { of = (struct open_file*)malloc(sizeof(struct open_file)); if (of) { of->parent = 0; of->ino = e->ino; of->state = state; of->next = ctx->open_files; of->previous = (struct open_file*)NULL; if (ctx->open_files) ctx->open_files->previous = of; ctx->open_files = of; fi->fh = (long)of; } } return res; } static void ntfs_fuse_create_file(fuse_req_t req, fuse_ino_t parent, const char *name, mode_t mode, struct fuse_file_info *fi) { int res; struct fuse_entry_param entry; res = ntfs_fuse_create(req, parent, name, mode & (S_IFMT | 07777), 0, &entry, NULL, fi); if (res < 0) fuse_reply_err(req, -res); else fuse_reply_create(req, &entry, fi); } static void ntfs_fuse_mknod(fuse_req_t req, fuse_ino_t parent, const char *name, mode_t mode, dev_t rdev) { int res; struct fuse_entry_param e; res = ntfs_fuse_create(req, parent, name, mode & (S_IFMT | 07777), rdev, &e,NULL,(struct fuse_file_info*)NULL); if (res < 0) fuse_reply_err(req, -res); else fuse_reply_entry(req, &e); } static void ntfs_fuse_symlink(fuse_req_t req, const char *target, fuse_ino_t parent, const char *name) { int res; struct fuse_entry_param entry; res = ntfs_fuse_create(req, parent, name, S_IFLNK, 0, &entry, target, (struct fuse_file_info*)NULL); if (res < 0) fuse_reply_err(req, -res); else fuse_reply_entry(req, &entry); } static int ntfs_fuse_newlink(fuse_req_t req __attribute__((unused)), fuse_ino_t ino, fuse_ino_t newparent, const char *newname, struct fuse_entry_param *e) { ntfschar *uname = NULL; ntfs_inode *dir_ni = NULL, *ni; int res = 0, uname_len; struct SECURITY_CONTEXT security; /* Open file for which create hard link. */ ni = ntfs_inode_open(ctx->vol, INODE(ino)); if (!ni) { res = -errno; goto exit; } /* Do not accept linking to a directory (except for renaming) */ if (e && (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY)) { errno = EPERM; res = -errno; goto exit; } /* Generate unicode filename. */ uname_len = ntfs_mbstoucs(newname, &uname); if ((uname_len < 0) || (ctx->windows_names && ntfs_forbidden_names(ctx->vol,uname,uname_len,TRUE))) { res = -errno; goto exit; } /* Open parent directory. */ dir_ni = ntfs_inode_open(ctx->vol, INODE(newparent)); if (!dir_ni) { res = -errno; goto exit; } #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) /* make sure the target parent directory is writeable */ if (ntfs_fuse_fill_security_context(req, &security) && !ntfs_allowed_access(&security,dir_ni,S_IWRITE + S_IEXEC)) res = -EACCES; else #else ntfs_fuse_fill_security_context(req, &security); #endif { if (dir_ni->flags & FILE_ATTR_REPARSE_POINT) { #ifndef DISABLE_PLUGINS const plugin_operations_t *ops; REPARSE_POINT *reparse; res = CALL_REPARSE_PLUGIN(dir_ni, link, ni, uname, uname_len); if (res < 0) goto exit; #else /* DISABLE_PLUGINS */ res = -EOPNOTSUPP; goto exit; #endif /* DISABLE_PLUGINS */ } else { if (ntfs_link(ni, dir_ni, uname, uname_len)) { res = -errno; goto exit; } } ntfs_inode_update_mbsname(dir_ni, newname, ni->mft_no); if (e) { e->ino = ni->mft_no; e->generation = 1; e->attr_timeout = ATTR_TIMEOUT; e->entry_timeout = ENTRY_TIMEOUT; res = ntfs_fuse_getstat(&security, ni, &e->attr); } set_archive(ni); ntfs_fuse_update_times(ni, NTFS_UPDATE_CTIME); ntfs_fuse_update_times(dir_ni, NTFS_UPDATE_MCTIME); } exit: /* * Must close dir_ni first otherwise ntfs_inode_sync_file_name(ni) * may fail because ni may not be in parent's index on the disk yet. */ if (ntfs_inode_close(dir_ni)) set_fuse_error(&res); if (ntfs_inode_close(ni)) set_fuse_error(&res); free(uname); return (res); } static void ntfs_fuse_link(fuse_req_t req, fuse_ino_t ino, fuse_ino_t newparent, const char *newname) { struct fuse_entry_param entry; int res; res = ntfs_fuse_newlink(req, ino, newparent, newname, &entry); if (res) fuse_reply_err(req, -res); else fuse_reply_entry(req, &entry); } static int ntfs_fuse_rm(fuse_req_t req, fuse_ino_t parent, const char *name, enum RM_TYPES rm_type __attribute__((unused))) { ntfschar *uname = NULL; ntfschar *ugname; ntfs_inode *dir_ni = NULL, *ni = NULL; int res = 0, uname_len; int ugname_len; u64 iref; fuse_ino_t ino; struct open_file *of; char ghostname[GHOSTLTH]; #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) struct SECURITY_CONTEXT security; #endif #if defined(__sun) && defined (__SVR4) int isdir; #endif /* defined(__sun) && defined (__SVR4) */ /* Deny removing from $Extend */ if (parent == FILE_Extend) { res = -EPERM; goto exit; } /* Open parent directory. */ dir_ni = ntfs_inode_open(ctx->vol, INODE(parent)); if (!dir_ni) { res = -errno; goto exit; } /* Generate unicode filename. */ uname_len = ntfs_mbstoucs(name, &uname); if (uname_len < 0) { res = -errno; goto exit; } /* Open object for delete. */ iref = ntfs_inode_lookup_by_mbsname(dir_ni, name); if (iref == (u64)-1) { res = -errno; goto exit; } ino = (fuse_ino_t)MREF(iref); /* deny unlinking metadata files */ if (ino < FILE_first_user) { res = -EPERM; goto exit; } ni = ntfs_inode_open(ctx->vol, ino); if (!ni) { res = -errno; goto exit; } #if defined(__sun) && defined (__SVR4) /* on Solaris : deny unlinking directories */ isdir = ni->mrec->flags & MFT_RECORD_IS_DIRECTORY; #ifndef DISABLE_PLUGINS /* get emulated type from plugin if available */ if (ni->flags & FILE_ATTR_REPARSE_POINT) { struct stat st; const plugin_operations_t *ops; REPARSE_POINT *reparse; /* Avoid double opening of parent directory */ res = ntfs_inode_close(dir_ni); if (res) goto exit; dir_ni = (ntfs_inode*)NULL; res = CALL_REPARSE_PLUGIN(ni, getattr, &st); if (res) goto exit; isdir = S_ISDIR(st.st_mode); dir_ni = ntfs_inode_open(ctx->vol, INODE(parent)); if (!dir_ni) { res = -errno; goto exit; } } #endif /* DISABLE_PLUGINS */ if (rm_type == (isdir ? RM_LINK : RM_DIR)) { errno = (isdir ? EISDIR : ENOTDIR); res = -errno; goto exit; } #endif /* defined(__sun) && defined (__SVR4) */ #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) /* JPA deny unlinking if directory is not writable and executable */ if (ntfs_fuse_fill_security_context(req, &security) && !ntfs_allowed_dir_access(&security, dir_ni, ino, ni, S_IEXEC + S_IWRITE + S_ISVTX)) { errno = EACCES; res = -errno; goto exit; } #endif /* * We keep one open_file record per opening, to avoid * having to check the list of open files when opening * and closing (which are more frequent than unlinking). * As a consequence, we may have to create several * ghosts names for the same file. * The file may have been opened with a different name * in a different parent directory. The ghost is * nevertheless created in the parent directory of the * name being unlinked, and permissions to do so are the * same as required for unlinking. */ for (of=ctx->open_files; of; of = of->next) { if ((of->ino == ino) && !(of->state & CLOSE_GHOST)) { /* file was open, create a ghost in unlink parent */ ntfs_inode *gni; u64 gref; /* ni has to be closed for linking ghost */ if (ni) { if (ntfs_inode_close(ni)) { res = -errno; goto exit; } ni = (ntfs_inode*)NULL; } of->state |= CLOSE_GHOST; of->parent = parent; of->ghost = ++ctx->latest_ghost; sprintf(ghostname,ghostformat,of->ghost); /* Generate unicode filename. */ ugname = (ntfschar*)NULL; ugname_len = ntfs_mbstoucs(ghostname, &ugname); if (ugname_len < 0) { res = -errno; goto exit; } /* sweep existing ghost if any, ignoring errors */ gref = ntfs_inode_lookup_by_mbsname(dir_ni, ghostname); if (gref != (u64)-1) { gni = ntfs_inode_open(ctx->vol, MREF(gref)); ntfs_delete(ctx->vol, (char*)NULL, gni, dir_ni, ugname, ugname_len); /* ntfs_delete() always closes gni and dir_ni */ dir_ni = (ntfs_inode*)NULL; } else { if (ntfs_inode_close(dir_ni)) { res = -errno; goto out; } dir_ni = (ntfs_inode*)NULL; } free(ugname); res = ntfs_fuse_newlink(req, of->ino, parent, ghostname, (struct fuse_entry_param*)NULL); if (res) goto out; /* now reopen then parent directory */ dir_ni = ntfs_inode_open(ctx->vol, INODE(parent)); if (!dir_ni) { res = -errno; goto exit; } } } if (!ni) { ni = ntfs_inode_open(ctx->vol, ino); if (!ni) { res = -errno; goto exit; } } if (dir_ni->flags & FILE_ATTR_REPARSE_POINT) { #ifndef DISABLE_PLUGINS const plugin_operations_t *ops; REPARSE_POINT *reparse; res = CALL_REPARSE_PLUGIN(dir_ni, unlink, (char*)NULL, ni, uname, uname_len); #else /* DISABLE_PLUGINS */ res = -EOPNOTSUPP; #endif /* DISABLE_PLUGINS */ } else if (ntfs_delete(ctx->vol, (char*)NULL, ni, dir_ni, uname, uname_len)) res = -errno; /* ntfs_delete() always closes ni and dir_ni */ ni = dir_ni = NULL; exit: if (ntfs_inode_close(ni) && !res) res = -errno; if (ntfs_inode_close(dir_ni) && !res) res = -errno; out : free(uname); return res; } static void ntfs_fuse_unlink(fuse_req_t req, fuse_ino_t parent, const char *name) { int res; res = ntfs_fuse_rm(req, parent, name, RM_LINK); if (res) fuse_reply_err(req, -res); else fuse_reply_err(req, 0); } static int ntfs_fuse_safe_rename(fuse_req_t req, fuse_ino_t ino, fuse_ino_t parent, const char *name, fuse_ino_t xino, fuse_ino_t newparent, const char *newname, const char *tmp) { int ret; ntfs_log_trace("Entering\n"); ret = ntfs_fuse_newlink(req, xino, newparent, tmp, (struct fuse_entry_param*)NULL); if (ret) return ret; ret = ntfs_fuse_rm(req, newparent, newname, RM_ANY); if (!ret) { ret = ntfs_fuse_newlink(req, ino, newparent, newname, (struct fuse_entry_param*)NULL); if (ret) goto restore; ret = ntfs_fuse_rm(req, parent, name, RM_ANY); if (ret) { if (ntfs_fuse_rm(req, newparent, newname, RM_ANY)) goto err; goto restore; } } goto cleanup; restore: if (ntfs_fuse_newlink(req, xino, newparent, newname, (struct fuse_entry_param*)NULL)) { err: ntfs_log_perror("Rename failed. Existing file '%s' was renamed " "to '%s'", newname, tmp); } else { cleanup: /* * Condition for this unlink has already been checked in * "ntfs_fuse_rename_existing_dest()", so it should never * fail (unless concurrent access to directories when fuse * is multithreaded) */ if (ntfs_fuse_rm(req, newparent, tmp, RM_ANY) < 0) ntfs_log_perror("Rename failed. Existing file '%s' still present " "as '%s'", newname, tmp); } return ret; } static int ntfs_fuse_rename_existing_dest(fuse_req_t req, fuse_ino_t ino, fuse_ino_t parent, const char *name, fuse_ino_t xino, fuse_ino_t newparent, const char *newname) { int ret, len; char *tmp; const char *ext = ".ntfs-3g-"; #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) ntfs_inode *newdir_ni; struct SECURITY_CONTEXT security; #endif ntfs_log_trace("Entering\n"); len = strlen(newname) + strlen(ext) + 10 + 1; /* wc(str(2^32)) + \0 */ tmp = (char*)ntfs_malloc(len); if (!tmp) return -errno; ret = snprintf(tmp, len, "%s%s%010d", newname, ext, ++ntfs_sequence); if (ret != len - 1) { ntfs_log_error("snprintf failed: %d != %d\n", ret, len - 1); ret = -EOVERFLOW; } else { #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) /* * Make sure existing dest can be removed. * This is only needed if parent directory is * sticky, because in this situation condition * for unlinking is different from condition for * linking */ newdir_ni = ntfs_inode_open(ctx->vol, INODE(newparent)); if (newdir_ni) { if (!ntfs_fuse_fill_security_context(req,&security) || ntfs_allowed_dir_access(&security, newdir_ni, xino, (ntfs_inode*)NULL, S_IEXEC + S_IWRITE + S_ISVTX)) { if (ntfs_inode_close(newdir_ni)) ret = -errno; else ret = ntfs_fuse_safe_rename(req, ino, parent, name, xino, newparent, newname, tmp); } else { ntfs_inode_close(newdir_ni); ret = -EACCES; } } else ret = -errno; #else ret = ntfs_fuse_safe_rename(req, ino, parent, name, xino, newparent, newname, tmp); #endif } free(tmp); return ret; } static void ntfs_fuse_rename(fuse_req_t req, fuse_ino_t parent, const char *name, fuse_ino_t newparent, const char *newname) { int ret; fuse_ino_t ino; fuse_ino_t xino; ntfs_inode *ni; ntfs_log_debug("rename: old: '%s' new: '%s'\n", name, newname); /* * FIXME: Rename should be atomic. */ ino = ntfs_fuse_inode_lookup(parent, name); if (ino == (fuse_ino_t)-1) { ret = -errno; goto out; } /* Check whether target is present */ xino = ntfs_fuse_inode_lookup(newparent, newname); if (xino != (fuse_ino_t)-1) { /* * Target exists : no need to check whether it * designates the same inode, this has already * been checked (by fuse ?) */ ni = ntfs_inode_open(ctx->vol, INODE(xino)); if (!ni) ret = -errno; else { ret = ntfs_check_empty_dir(ni); if (ret < 0) { ret = -errno; ntfs_inode_close(ni); goto out; } if (ntfs_inode_close(ni)) { set_fuse_error(&ret); goto out; } ret = ntfs_fuse_rename_existing_dest(req, ino, parent, name, xino, newparent, newname); } } else { /* target does not exist */ ret = ntfs_fuse_newlink(req, ino, newparent, newname, (struct fuse_entry_param*)NULL); if (ret) goto out; ret = ntfs_fuse_rm(req, parent, name, RM_ANY); if (ret) ntfs_fuse_rm(req, newparent, newname, RM_ANY); } out: if (ret) fuse_reply_err(req, -ret); else fuse_reply_err(req, 0); } static void ntfs_fuse_release(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi) { ntfs_inode *ni = NULL; ntfs_attr *na = NULL; struct open_file *of; char ghostname[GHOSTLTH]; int res; of = (struct open_file*)(long)fi->fh; /* Only for marked descriptors there is something to do */ if (!of || !(of->state & (CLOSE_COMPRESSED | CLOSE_ENCRYPTED | CLOSE_DMTIME | CLOSE_REPARSE))) { res = 0; goto out; } ni = ntfs_inode_open(ctx->vol, INODE(ino)); if (!ni) { res = -errno; goto exit; } if (ni->flags & FILE_ATTR_REPARSE_POINT) { #ifndef DISABLE_PLUGINS const plugin_operations_t *ops; REPARSE_POINT *reparse; res = CALL_REPARSE_PLUGIN(ni, release, &of->fi); if (!res) { goto stamps; } #else /* DISABLE_PLUGINS */ /* Assume release() was not needed */ res = 0; #endif /* DISABLE_PLUGINS */ goto exit; } na = ntfs_attr_open(ni, AT_DATA, AT_UNNAMED, 0); if (!na) { res = -errno; goto exit; } res = 0; if (of->state & CLOSE_COMPRESSED) res = ntfs_attr_pclose(na); #ifdef HAVE_SETXATTR /* extended attributes interface required */ if (of->state & CLOSE_ENCRYPTED) res = ntfs_efs_fixup_attribute(NULL, na); #endif /* HAVE_SETXATTR */ #ifndef DISABLE_PLUGINS stamps : #endif /* DISABLE_PLUGINS */ if (of->state & CLOSE_DMTIME) ntfs_inode_update_times(ni,NTFS_UPDATE_MCTIME); exit: if (na) ntfs_attr_close(na); if (ntfs_inode_close(ni)) set_fuse_error(&res); out: /* remove the associate ghost file (even if release failed) */ if (of) { if (of->state & CLOSE_GHOST) { sprintf(ghostname,ghostformat,of->ghost); ntfs_fuse_rm(req, of->parent, ghostname, RM_ANY); } /* remove from open files list */ if (of->next) of->next->previous = of->previous; if (of->previous) of->previous->next = of->next; else ctx->open_files = of->next; free(of); } if (res) fuse_reply_err(req, -res); else fuse_reply_err(req, 0); } static void ntfs_fuse_mkdir(fuse_req_t req, fuse_ino_t parent, const char *name, mode_t mode) { int res; struct fuse_entry_param entry; res = ntfs_fuse_create(req, parent, name, S_IFDIR | (mode & 07777), 0, &entry, (char*)NULL, (struct fuse_file_info*)NULL); if (res < 0) fuse_reply_err(req, -res); else fuse_reply_entry(req, &entry); } static void ntfs_fuse_rmdir(fuse_req_t req, fuse_ino_t parent, const char *name) { int res; res = ntfs_fuse_rm(req, parent, name, RM_DIR); if (res) fuse_reply_err(req, -res); else fuse_reply_err(req, 0); } static void ntfs_fuse_fsync(fuse_req_t req, fuse_ino_t ino __attribute__((unused)), int type __attribute__((unused)), struct fuse_file_info *fi __attribute__((unused))) { /* sync the full device */ if (ntfs_device_sync(ctx->vol->dev)) fuse_reply_err(req, errno); else fuse_reply_err(req, 0); } #if defined(FUSE_INTERNAL) || (FUSE_VERSION >= 28) static void ntfs_fuse_ioctl(fuse_req_t req __attribute__((unused)), fuse_ino_t ino __attribute__((unused)), int cmd, void *arg, struct fuse_file_info *fi __attribute__((unused)), unsigned flags, const void *data, size_t in_bufsz, size_t out_bufsz) { ntfs_inode *ni; char *buf = (char*)NULL; int bufsz; int ret = 0; if (flags & FUSE_IOCTL_COMPAT) { ret = -ENOSYS; } else { ni = ntfs_inode_open(ctx->vol, INODE(ino)); if (!ni) { ret = -errno; goto fail; } bufsz = (in_bufsz > out_bufsz ? in_bufsz : out_bufsz); if (bufsz) { buf = ntfs_malloc(bufsz); if (!buf) { ret = ENOMEM; goto fail; } memcpy(buf, data, in_bufsz); } /* * Linux defines the request argument of ioctl() to be an * unsigned long, which fuse 2.x forwards as a signed int * into which the request sometimes does not fit. * So we must expand the value and make sure it is not * sign-extended. */ ret = ntfs_ioctl(ni, (unsigned int)cmd, arg, flags, buf); if (ntfs_inode_close (ni)) set_fuse_error(&ret); } if (ret) fail : fuse_reply_err(req, -ret); else fuse_reply_ioctl(req, 0, buf, out_bufsz); if (buf) free(buf); } #endif /* defined(FUSE_INTERNAL) || (FUSE_VERSION >= 28) */ static void ntfs_fuse_bmap(fuse_req_t req, fuse_ino_t ino, size_t blocksize, uint64_t vidx) { ntfs_inode *ni; ntfs_attr *na; LCN lcn; uint64_t lidx = 0; int ret = 0; int cl_per_bl = ctx->vol->cluster_size / blocksize; if (blocksize > ctx->vol->cluster_size) { ret = -EINVAL; goto done; } ni = ntfs_inode_open(ctx->vol, INODE(ino)); if (!ni) { ret = -errno; goto done; } na = ntfs_attr_open(ni, AT_DATA, AT_UNNAMED, 0); if (!na) { ret = -errno; goto close_inode; } if ((na->data_flags & (ATTR_COMPRESSION_MASK | ATTR_IS_ENCRYPTED)) || !NAttrNonResident(na)) { ret = -EINVAL; goto close_attr; } if (ntfs_attr_map_whole_runlist(na)) { ret = -errno; goto close_attr; } lcn = ntfs_rl_vcn_to_lcn(na->rl, vidx / cl_per_bl); lidx = (lcn > 0) ? lcn * cl_per_bl + vidx % cl_per_bl : 0; close_attr: ntfs_attr_close(na); close_inode: if (ntfs_inode_close(ni)) set_fuse_error(&ret); done : if (ret < 0) fuse_reply_err(req, -ret); else fuse_reply_bmap(req, lidx); } #ifdef HAVE_SETXATTR /* * Name space identifications and prefixes */ enum { XATTRNS_NONE, XATTRNS_USER, XATTRNS_SYSTEM, XATTRNS_SECURITY, XATTRNS_TRUSTED, XATTRNS_OPEN } ; /* * Check whether access to internal data as an extended * attribute in system name space is allowed * * Returns pointer to inode if allowed, * NULL and errno set if not allowed */ static ntfs_inode *ntfs_check_access_xattr(fuse_req_t req, struct SECURITY_CONTEXT *security, fuse_ino_t ino, int attr, BOOL setting) { ntfs_inode *dir_ni; ntfs_inode *ni; BOOL foracl; BOOL bad; mode_t acctype; ni = (ntfs_inode*)NULL; foracl = (attr == XATTR_POSIX_ACC) || (attr == XATTR_POSIX_DEF); /* * When accessing Posix ACL, return unsupported if ACL * were disabled or no user mapping has been defined, * or trying to change a Windows-inherited ACL. * However no error will be returned to getfacl */ if (((!ntfs_fuse_fill_security_context(req, security) || (ctx->secure_flags & ((1 << SECURITY_DEFAULT) | (1 << SECURITY_RAW)))) || !(ctx->secure_flags & (1 << SECURITY_ACL)) || (setting && ctx->inherit)) && foracl) { if (ctx->silent && !ctx->security.mapping[MAPUSERS]) errno = 0; else errno = EOPNOTSUPP; } else { /* * parent directory must be executable, and * for setting a DOS name it must be writeable */ if (setting && (attr == XATTR_NTFS_DOS_NAME)) acctype = S_IEXEC | S_IWRITE; else acctype = S_IEXEC; ni = ntfs_inode_open(ctx->vol, INODE(ino)); /* basic access was checked previously in a lookup */ if (ni && (acctype != S_IEXEC)) { bad = FALSE; /* do not reopen root */ if (ni->mft_no == FILE_root) { /* forbid getting/setting names on root */ if ((attr == XATTR_NTFS_DOS_NAME) || !ntfs_real_allowed_access(security, ni, acctype)) bad = TRUE; } else { dir_ni = ntfs_dir_parent_inode(ni); if (dir_ni) { if (!ntfs_real_allowed_access(security, dir_ni, acctype)) bad = TRUE; if (ntfs_inode_close(dir_ni)) bad = TRUE; } else bad = TRUE; } if (bad) { ntfs_inode_close(ni); ni = (ntfs_inode*)NULL; } } } return (ni); } /* * Determine the name space of an extended attribute */ static int xattr_namespace(const char *name) { int namespace; if (ctx->streams == NF_STREAMS_INTERFACE_XATTR) { namespace = XATTRNS_NONE; if (!strncmp(name, nf_ns_user_prefix, nf_ns_user_prefix_len) && (strlen(name) != (size_t)nf_ns_user_prefix_len)) namespace = XATTRNS_USER; else if (!strncmp(name, nf_ns_system_prefix, nf_ns_system_prefix_len) && (strlen(name) != (size_t)nf_ns_system_prefix_len)) namespace = XATTRNS_SYSTEM; else if (!strncmp(name, nf_ns_security_prefix, nf_ns_security_prefix_len) && (strlen(name) != (size_t)nf_ns_security_prefix_len)) namespace = XATTRNS_SECURITY; else if (!strncmp(name, nf_ns_trusted_prefix, nf_ns_trusted_prefix_len) && (strlen(name) != (size_t)nf_ns_trusted_prefix_len)) namespace = XATTRNS_TRUSTED; } else namespace = XATTRNS_OPEN; return (namespace); } /* * Fix the prefix of an extended attribute */ static int fix_xattr_prefix(const char *name, int namespace, ntfschar **lename) { int len; char *prefixed; *lename = (ntfschar*)NULL; switch (namespace) { case XATTRNS_USER : /* * user name space : remove user prefix */ len = ntfs_mbstoucs(name + nf_ns_user_prefix_len, lename); break; case XATTRNS_SYSTEM : case XATTRNS_SECURITY : case XATTRNS_TRUSTED : /* * security, trusted and unmapped system name spaces : * insert ntfs-3g prefix */ prefixed = (char*)ntfs_malloc(strlen(xattr_ntfs_3g) + strlen(name) + 1); if (prefixed) { strcpy(prefixed,xattr_ntfs_3g); strcat(prefixed,name); len = ntfs_mbstoucs(prefixed, lename); free(prefixed); } else len = -1; break; case XATTRNS_OPEN : /* * in open name space mode : do no fix prefix */ len = ntfs_mbstoucs(name, lename); break; default : len = -1; } return (len); } static void ntfs_fuse_listxattr(fuse_req_t req, fuse_ino_t ino, size_t size) { ntfs_attr_search_ctx *actx = NULL; ntfs_inode *ni; char *list = (char*)NULL; int ret = 0; #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) struct SECURITY_CONTEXT security; #endif #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) ntfs_fuse_fill_security_context(req, &security); #endif ni = ntfs_inode_open(ctx->vol, INODE(ino)); if (!ni) { ret = -errno; goto out; } /* Return with no result for symlinks, fifo, etc. */ if (!user_xattrs_allowed(ctx, ni)) goto exit; /* otherwise file must be readable */ #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) if (!ntfs_allowed_access(&security,ni,S_IREAD)) { ret = -EACCES; goto exit; } #endif actx = ntfs_attr_get_search_ctx(ni, NULL); if (!actx) { ret = -errno; goto exit; } if (size) { list = (char*)malloc(size); if (!list) { ret = -errno; goto exit; } } if ((ctx->streams == NF_STREAMS_INTERFACE_XATTR) || (ctx->streams == NF_STREAMS_INTERFACE_OPENXATTR)) { ret = ntfs_fuse_listxattr_common(ni, actx, list, size, ctx->streams == NF_STREAMS_INTERFACE_XATTR); if (ret < 0) goto exit; } if (errno != ENOENT) ret = -errno; exit: if (actx) ntfs_attr_put_search_ctx(actx); if (ntfs_inode_close(ni)) set_fuse_error(&ret); out : if (ret < 0) fuse_reply_err(req, -ret); else if (size) fuse_reply_buf(req, list, ret); else fuse_reply_xattr(req, ret); free(list); } #if defined(__APPLE__) || defined(__DARWIN__) static void ntfs_fuse_getxattr(fuse_req_t req, fuse_ino_t ino, const char *name, size_t size, uint32_t position) #else static void ntfs_fuse_getxattr(fuse_req_t req, fuse_ino_t ino, const char *name, size_t size) #endif { #if !(defined(__APPLE__) || defined(__DARWIN__)) static const unsigned int position = 0U; #endif ntfs_inode *ni; ntfs_inode *dir_ni; ntfs_attr *na = NULL; char *value = (char*)NULL; ntfschar *lename = (ntfschar*)NULL; int lename_len; int res; s64 rsize; enum SYSTEMXATTRS attr; int namespace; struct SECURITY_CONTEXT security; #if defined(__APPLE__) || defined(__DARWIN__) /* If the attribute is not a resource fork attribute and the position * parameter is non-zero, we return with EINVAL as requesting position * is not permitted for non-resource fork attributes. */ if (position && strcmp(name, XATTR_RESOURCEFORK_NAME)) { fuse_reply_err(req, EINVAL); return; } #endif attr = ntfs_xattr_system_type(name,ctx->vol); if (attr != XATTR_UNMAPPED) { /* * hijack internal data and ACL retrieval, whatever * mode was selected for xattr (from the user's * point of view, ACLs are not xattr) */ if (size) value = (char*)ntfs_malloc(size); #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) if (!size || value) { ni = ntfs_check_access_xattr(req, &security, ino, attr, FALSE); if (ni) { if (ntfs_allowed_access(&security,ni,S_IREAD)) { if (attr == XATTR_NTFS_DOS_NAME) dir_ni = ntfs_dir_parent_inode(ni); else dir_ni = (ntfs_inode*)NULL; res = ntfs_xattr_system_getxattr(&security, attr, ni, dir_ni, value, size); if (dir_ni && ntfs_inode_close(dir_ni)) set_fuse_error(&res); } else res = -errno; if (ntfs_inode_close(ni)) set_fuse_error(&res); } else res = -errno; #else /* * Standard access control has been done by fuse/kernel */ if (!size || value) { ni = ntfs_inode_open(ctx->vol, INODE(ino)); if (ni) { /* user mapping not mandatory */ ntfs_fuse_fill_security_context(req, &security); if (attr == XATTR_NTFS_DOS_NAME) dir_ni = ntfs_dir_parent_inode(ni); else dir_ni = (ntfs_inode*)NULL; res = ntfs_xattr_system_getxattr(&security, attr, ni, dir_ni, value, size); if (dir_ni && ntfs_inode_close(dir_ni)) set_fuse_error(&res); if (ntfs_inode_close(ni)) set_fuse_error(&res); } else res = -errno; #endif } else res = -errno; if (res < 0) fuse_reply_err(req, -res); else if (size) fuse_reply_buf(req, value, res); else fuse_reply_xattr(req, res); free(value); return; } if (ctx->streams == NF_STREAMS_INTERFACE_NONE) { res = -EOPNOTSUPP; goto out; } namespace = xattr_namespace(name); if (namespace == XATTRNS_NONE) { res = -EOPNOTSUPP; goto out; } #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) ntfs_fuse_fill_security_context(req,&security); /* trusted only readable by root */ if ((namespace == XATTRNS_TRUSTED) && security.uid) { res = -NTFS_NOXATTR_ERRNO; goto out; } #endif ni = ntfs_inode_open(ctx->vol, INODE(ino)); if (!ni) { res = -errno; goto out; } /* Return with no result for symlinks, fifo, etc. */ if (!user_xattrs_allowed(ctx, ni)) { res = -NTFS_NOXATTR_ERRNO; goto exit; } /* otherwise file must be readable */ #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) if (!ntfs_allowed_access(&security, ni, S_IREAD)) { res = -errno; goto exit; } #endif lename_len = fix_xattr_prefix(name, namespace, &lename); if (lename_len == -1) { res = -errno; goto exit; } na = ntfs_attr_open(ni, AT_DATA, lename, lename_len); if (!na) { res = -NTFS_NOXATTR_ERRNO; goto exit; } rsize = na->data_size; if (ctx->efs_raw && rsize && (na->data_flags & ATTR_IS_ENCRYPTED) && NAttrNonResident(na)) rsize = ((na->data_size + 511) & ~511) + 2; rsize -= position; if (size) { if (size >= (size_t)rsize) { value = (char*)ntfs_malloc(rsize); if (value) res = ntfs_attr_pread(na, position, rsize, value); if (!value || (res != rsize)) res = -errno; } else res = -ERANGE; } else res = rsize; exit: if (na) ntfs_attr_close(na); free(lename); if (ntfs_inode_close(ni)) set_fuse_error(&res); out : if (res < 0) fuse_reply_err(req, -res); else if (size) fuse_reply_buf(req, value, res); else fuse_reply_xattr(req, res); free(value); } #if defined(__APPLE__) || defined(__DARWIN__) static void ntfs_fuse_setxattr(fuse_req_t req, fuse_ino_t ino, const char *name, const char *value, size_t size, int flags, uint32_t position) #else static void ntfs_fuse_setxattr(fuse_req_t req, fuse_ino_t ino, const char *name, const char *value, size_t size, int flags) #endif { #if !(defined(__APPLE__) || defined(__DARWIN__)) static const unsigned int position = 0U; #else BOOL is_resource_fork; #endif ntfs_inode *ni; ntfs_inode *dir_ni; ntfs_attr *na = NULL; ntfschar *lename = NULL; int res, lename_len; size_t total; s64 part; enum SYSTEMXATTRS attr; int namespace; struct SECURITY_CONTEXT security; #if defined(__APPLE__) || defined(__DARWIN__) /* If the attribute is not a resource fork attribute and the position * parameter is non-zero, we return with EINVAL as requesting position * is not permitted for non-resource fork attributes. */ is_resource_fork = strcmp(name, XATTR_RESOURCEFORK_NAME) ? FALSE : TRUE; if (position && !is_resource_fork) { fuse_reply_err(req, EINVAL); return; } #endif attr = ntfs_xattr_system_type(name,ctx->vol); if (attr != XATTR_UNMAPPED) { /* * hijack internal data and ACL setting, whatever * mode was selected for xattr (from the user's * point of view, ACLs are not xattr) * Note : ctime updated on successful settings */ #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) ni = ntfs_check_access_xattr(req,&security,ino,attr,TRUE); if (ni) { if (ntfs_allowed_as_owner(&security, ni)) { if (attr == XATTR_NTFS_DOS_NAME) dir_ni = ntfs_dir_parent_inode(ni); else dir_ni = (ntfs_inode*)NULL; res = ntfs_xattr_system_setxattr(&security, attr, ni, dir_ni, value, size, flags); /* never have to close dir_ni */ if (res) res = -errno; } else res = -errno; if (attr != XATTR_NTFS_DOS_NAME) { if (!res) ntfs_fuse_update_times(ni, NTFS_UPDATE_CTIME); if (ntfs_inode_close(ni)) set_fuse_error(&res); } } else res = -errno; #else /* creation of a new name is not controlled by fuse */ if (attr == XATTR_NTFS_DOS_NAME) ni = ntfs_check_access_xattr(req, &security, ino, attr, TRUE); else ni = ntfs_inode_open(ctx->vol, INODE(ino)); if (ni) { /* * user mapping is not mandatory * if defined, only owner is allowed */ if (!ntfs_fuse_fill_security_context(req, &security) || ntfs_allowed_as_owner(&security, ni)) { if (attr == XATTR_NTFS_DOS_NAME) dir_ni = ntfs_dir_parent_inode(ni); else dir_ni = (ntfs_inode*)NULL; res = ntfs_xattr_system_setxattr(&security, attr, ni, dir_ni, value, size, flags); /* never have to close dir_ni */ if (res) res = -errno; } else res = -errno; if (attr != XATTR_NTFS_DOS_NAME) { if (!res) ntfs_fuse_update_times(ni, NTFS_UPDATE_CTIME); if (ntfs_inode_close(ni)) set_fuse_error(&res); } } else res = -errno; #endif #if CACHEING && !defined(FUSE_INTERNAL) && FUSE_VERSION >= 28 /* * Most of system xattr settings cause changes to some * file attribute (st_mode, st_nlink, st_mtime, etc.), * so we must invalidate cached data when cacheing is * in use (not possible with internal fuse or external * fuse before 2.8) */ if ((res >= 0) && fuse_lowlevel_notify_inval_inode(ctx->fc, ino, -1, 0)) res = -errno; #endif if (res < 0) fuse_reply_err(req, -res); else fuse_reply_err(req, 0); return; } if ((ctx->streams != NF_STREAMS_INTERFACE_XATTR) && (ctx->streams != NF_STREAMS_INTERFACE_OPENXATTR)) { res = -EOPNOTSUPP; goto out; } namespace = xattr_namespace(name); if (namespace == XATTRNS_NONE) { res = -EOPNOTSUPP; goto out; } #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) ntfs_fuse_fill_security_context(req,&security); /* security and trusted only settable by root */ if (((namespace == XATTRNS_SECURITY) || (namespace == XATTRNS_TRUSTED)) && security.uid) { res = -EPERM; goto out; } #endif ni = ntfs_inode_open(ctx->vol, INODE(ino)); if (!ni) { res = -errno; goto out; } #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) switch (namespace) { case XATTRNS_SECURITY : case XATTRNS_TRUSTED : if (security.uid) { res = -EPERM; goto exit; } break; case XATTRNS_SYSTEM : if (!ntfs_allowed_as_owner(&security, ni)) { res = -EACCES; goto exit; } break; default : /* User xattr not allowed for symlinks, fifo, etc. */ if (!user_xattrs_allowed(ctx, ni)) { res = -EPERM; goto exit; } if (!ntfs_allowed_access(&security,ni,S_IWRITE)) { res = -EACCES; goto exit; } break; } #else /* User xattr not allowed for symlinks, fifo, etc. */ if ((namespace == XATTRNS_USER) && !user_xattrs_allowed(ctx, ni)) { res = -EPERM; goto exit; } #endif lename_len = fix_xattr_prefix(name, namespace, &lename); if ((lename_len == -1) || (ctx->windows_names && ntfs_forbidden_chars(lename,lename_len,TRUE))) { res = -errno; goto exit; } na = ntfs_attr_open(ni, AT_DATA, lename, lename_len); if (na && flags == XATTR_CREATE) { res = -EEXIST; goto exit; } if (!na) { if (flags == XATTR_REPLACE) { res = -NTFS_NOXATTR_ERRNO; goto exit; } if (ntfs_attr_add(ni, AT_DATA, lename, lename_len, NULL, 0)) { res = -errno; goto exit; } if (!(ni->flags & FILE_ATTR_ARCHIVE)) { set_archive(ni); NInoFileNameSetDirty(ni); } na = ntfs_attr_open(ni, AT_DATA, lename, lename_len); if (!na) { res = -errno; goto exit; } #if defined(__APPLE__) || defined(__DARWIN__) } else if (is_resource_fork) { /* In macOS, the resource fork is a special case. It doesn't * ever shrink (it would have to be removed and re-added). */ #endif } else { /* currently compressed streams can only be wiped out */ if (ntfs_attr_truncate(na, (s64)0 /* size */)) { res = -errno; goto exit; } } total = 0; res = 0; if (size) { do { part = ntfs_attr_pwrite(na, position + total, size - total, &value[total]); if (part > 0) total += part; } while ((part > 0) && (total < size)); } if ((total != size) || ntfs_attr_pclose(na)) res = -errno; else { if (ctx->efs_raw && (ni->flags & FILE_ATTR_ENCRYPTED)) { if (ntfs_efs_fixup_attribute(NULL,na)) res = -errno; } } if (!res) { ntfs_fuse_update_times(ni, NTFS_UPDATE_CTIME); if (!(ni->flags & FILE_ATTR_ARCHIVE)) { set_archive(ni); NInoFileNameSetDirty(ni); } } exit: if (na) ntfs_attr_close(na); free(lename); if (ntfs_inode_close(ni)) set_fuse_error(&res); out : if (res < 0) fuse_reply_err(req, -res); else fuse_reply_err(req, 0); } static void ntfs_fuse_removexattr(fuse_req_t req, fuse_ino_t ino, const char *name) { ntfs_inode *ni; ntfs_inode *dir_ni; ntfschar *lename = NULL; int res = 0, lename_len; enum SYSTEMXATTRS attr; int namespace; struct SECURITY_CONTEXT security; attr = ntfs_xattr_system_type(name,ctx->vol); if (attr != XATTR_UNMAPPED) { switch (attr) { /* * Removal of NTFS ACL, ATTRIB, EFSINFO or TIMES * is never allowed */ case XATTR_NTFS_ACL : case XATTR_NTFS_ATTRIB : case XATTR_NTFS_ATTRIB_BE : case XATTR_NTFS_EFSINFO : case XATTR_NTFS_TIMES : case XATTR_NTFS_TIMES_BE : case XATTR_NTFS_CRTIME : case XATTR_NTFS_CRTIME_BE : res = -EPERM; break; default : #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) ni = ntfs_check_access_xattr(req, &security, ino, attr,TRUE); if (ni) { if (ntfs_allowed_as_owner(&security, ni)) { if (attr == XATTR_NTFS_DOS_NAME) dir_ni = ntfs_dir_parent_inode(ni); else dir_ni = (ntfs_inode*)NULL; res = ntfs_xattr_system_removexattr(&security, attr, ni, dir_ni); if (res) res = -errno; /* never have to close dir_ni */ } else res = -errno; if (attr != XATTR_NTFS_DOS_NAME) { if (!res) ntfs_fuse_update_times(ni, NTFS_UPDATE_CTIME); if (ntfs_inode_close(ni)) set_fuse_error(&res); } } else res = -errno; #else /* creation of a new name is not controlled by fuse */ if (attr == XATTR_NTFS_DOS_NAME) ni = ntfs_check_access_xattr(req, &security, ino, attr, TRUE); else ni = ntfs_inode_open(ctx->vol, INODE(ino)); if (ni) { /* * user mapping is not mandatory * if defined, only owner is allowed */ if (!ntfs_fuse_fill_security_context(req, &security) || ntfs_allowed_as_owner(&security, ni)) { if (attr == XATTR_NTFS_DOS_NAME) dir_ni = ntfs_dir_parent_inode(ni); else dir_ni = (ntfs_inode*)NULL; res = ntfs_xattr_system_removexattr(&security, attr, ni, dir_ni); /* never have to close dir_ni */ if (res) res = -errno; } else res = -errno; if (attr != XATTR_NTFS_DOS_NAME) { if (!res) ntfs_fuse_update_times(ni, NTFS_UPDATE_CTIME); if (ntfs_inode_close(ni)) set_fuse_error(&res); } } else res = -errno; #endif #if CACHEING && !defined(FUSE_INTERNAL) && FUSE_VERSION >= 28 /* * Some allowed system xattr removals cause changes to * some file attribute (st_mode, st_nlink, etc.), * so we must invalidate cached data when cacheing is * in use (not possible with internal fuse or external * fuse before 2.8) */ if ((res >= 0) && fuse_lowlevel_notify_inval_inode(ctx->fc, ino, -1, 0)) res = -errno; #endif break; } if (res < 0) fuse_reply_err(req, -res); else fuse_reply_err(req, 0); return; } if ((ctx->streams != NF_STREAMS_INTERFACE_XATTR) && (ctx->streams != NF_STREAMS_INTERFACE_OPENXATTR)) { res = -EOPNOTSUPP; goto out; } namespace = xattr_namespace(name); if (namespace == XATTRNS_NONE) { res = -EOPNOTSUPP; goto out; } #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) ntfs_fuse_fill_security_context(req,&security); /* security and trusted only settable by root */ if (((namespace == XATTRNS_SECURITY) || (namespace == XATTRNS_TRUSTED)) && security.uid) { res = -EACCES; goto out; } #endif ni = ntfs_inode_open(ctx->vol, INODE(ino)); if (!ni) { res = -errno; goto out; } #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) switch (namespace) { case XATTRNS_SECURITY : case XATTRNS_TRUSTED : if (security.uid) { res = -EPERM; goto exit; } break; case XATTRNS_SYSTEM : if (!ntfs_allowed_as_owner(&security, ni)) { res = -EACCES; goto exit; } break; default : /* User xattr not allowed for symlinks, fifo, etc. */ if (!user_xattrs_allowed(ctx, ni)) { res = -EPERM; goto exit; } if (!ntfs_allowed_access(&security,ni,S_IWRITE)) { res = -EACCES; goto exit; } break; } #else /* User xattr not allowed for symlinks, fifo, etc. */ if ((namespace == XATTRNS_USER) && !user_xattrs_allowed(ctx, ni)) { res = -EPERM; goto exit; } #endif lename_len = fix_xattr_prefix(name, namespace, &lename); if (lename_len == -1) { res = -errno; goto exit; } if (ntfs_attr_remove(ni, AT_DATA, lename, lename_len)) { if (errno == ENOENT) errno = NTFS_NOXATTR_ERRNO; res = -errno; } if (!res) { ntfs_fuse_update_times(ni, NTFS_UPDATE_CTIME); if (!(ni->flags & FILE_ATTR_ARCHIVE)) { set_archive(ni); NInoFileNameSetDirty(ni); } } exit: free(lename); if (ntfs_inode_close(ni)) set_fuse_error(&res); out : if (res < 0) fuse_reply_err(req, -res); else fuse_reply_err(req, 0); return; } #else #if POSIXACLS #error "Option inconsistency : POSIXACLS requires SETXATTR" #endif #endif /* HAVE_SETXATTR */ #ifndef DISABLE_PLUGINS static void register_internal_reparse_plugins(void) { static const plugin_operations_t ops = { .getattr = junction_getstat, .readlink = junction_readlink, } ; static const plugin_operations_t wsl_ops = { .getattr = wsl_getstat, } ; register_reparse_plugin(ctx, IO_REPARSE_TAG_MOUNT_POINT, &ops, (void*)NULL); register_reparse_plugin(ctx, IO_REPARSE_TAG_SYMLINK, &ops, (void*)NULL); register_reparse_plugin(ctx, IO_REPARSE_TAG_LX_SYMLINK, &ops, (void*)NULL); register_reparse_plugin(ctx, IO_REPARSE_TAG_AF_UNIX, &wsl_ops, (void*)NULL); register_reparse_plugin(ctx, IO_REPARSE_TAG_LX_FIFO, &wsl_ops, (void*)NULL); register_reparse_plugin(ctx, IO_REPARSE_TAG_LX_CHR, &wsl_ops, (void*)NULL); register_reparse_plugin(ctx, IO_REPARSE_TAG_LX_BLK, &wsl_ops, (void*)NULL); } #endif /* DISABLE_PLUGINS */ static void ntfs_close(void) { struct SECURITY_CONTEXT security; if (!ctx) return; if (!ctx->vol) return; if (ctx->mounted) { ntfs_log_info("Unmounting %s (%s)\n", opts.device, ctx->vol->vol_name); if (ntfs_fuse_fill_security_context((fuse_req_t)NULL, &security)) { if (ctx->seccache && ctx->seccache->head.p_reads) { ntfs_log_info("Permissions cache : %lu writes, " "%lu reads, %lu.%1lu%% hits\n", ctx->seccache->head.p_writes, ctx->seccache->head.p_reads, 100 * ctx->seccache->head.p_hits / ctx->seccache->head.p_reads, 1000 * ctx->seccache->head.p_hits / ctx->seccache->head.p_reads % 10); } } ntfs_destroy_security_context(&security); } if (ntfs_umount(ctx->vol, FALSE)) ntfs_log_perror("Failed to close volume %s", opts.device); ctx->vol = NULL; } static void ntfs_fuse_destroy2(void *notused __attribute__((unused))) { ntfs_close(); } static struct fuse_lowlevel_ops ntfs_3g_ops = { .lookup = ntfs_fuse_lookup, .getattr = ntfs_fuse_getattr, .readlink = ntfs_fuse_readlink, .opendir = ntfs_fuse_opendir, .readdir = ntfs_fuse_readdir, .releasedir = ntfs_fuse_releasedir, .open = ntfs_fuse_open, .release = ntfs_fuse_release, .read = ntfs_fuse_read, .write = ntfs_fuse_write, .setattr = ntfs_fuse_setattr, .statfs = ntfs_fuse_statfs, .create = ntfs_fuse_create_file, .mknod = ntfs_fuse_mknod, .symlink = ntfs_fuse_symlink, .link = ntfs_fuse_link, .unlink = ntfs_fuse_unlink, .rename = ntfs_fuse_rename, .mkdir = ntfs_fuse_mkdir, .rmdir = ntfs_fuse_rmdir, .fsync = ntfs_fuse_fsync, .fsyncdir = ntfs_fuse_fsync, .bmap = ntfs_fuse_bmap, .destroy = ntfs_fuse_destroy2, #if defined(FUSE_INTERNAL) || (FUSE_VERSION >= 28) .ioctl = ntfs_fuse_ioctl, #endif /* defined(FUSE_INTERNAL) || (FUSE_VERSION >= 28) */ #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) .access = ntfs_fuse_access, #endif #ifdef HAVE_SETXATTR .getxattr = ntfs_fuse_getxattr, .setxattr = ntfs_fuse_setxattr, .removexattr = ntfs_fuse_removexattr, .listxattr = ntfs_fuse_listxattr, #endif /* HAVE_SETXATTR */ #if 0 && (defined(__APPLE__) || defined(__DARWIN__)) /* Unfinished. */ /* MacFUSE extensions. */ .getxtimes = ntfs_macfuse_getxtimes, .setcrtime = ntfs_macfuse_setcrtime, .setbkuptime = ntfs_macfuse_setbkuptime, .setchgtime = ntfs_macfuse_setchgtime, #endif /* defined(__APPLE__) || defined(__DARWIN__) */ .init = ntfs_init }; static int ntfs_fuse_init(void) { ctx = (ntfs_fuse_context_t*)ntfs_calloc(sizeof(ntfs_fuse_context_t)); if (!ctx) return -1; *ctx = (ntfs_fuse_context_t) { .uid = getuid(), .gid = getgid(), #if defined(linux) .streams = NF_STREAMS_INTERFACE_XATTR, #else .streams = NF_STREAMS_INTERFACE_NONE, #endif .atime = ATIME_RELATIVE, .silent = TRUE, .recover = TRUE }; return 0; } static int ntfs_open(const char *device) { unsigned long flags = 0; ntfs_volume *vol; if (!ctx->blkdev) flags |= NTFS_MNT_EXCLUSIVE; if (ctx->ro) flags |= NTFS_MNT_RDONLY; else if (!ctx->hiberfile) flags |= NTFS_MNT_MAY_RDONLY; if (ctx->recover) flags |= NTFS_MNT_RECOVER; if (ctx->hiberfile) flags |= NTFS_MNT_IGNORE_HIBERFILE; ctx->vol = vol = ntfs_mount(device, flags); if (!vol) { ntfs_log_perror("Failed to mount '%s'", device); goto err_out; } if (ctx->sync && ctx->vol->dev) NDevSetSync(ctx->vol->dev); if (ctx->compression) NVolSetCompression(ctx->vol); else NVolClearCompression(ctx->vol); #ifdef HAVE_SETXATTR /* archivers must see hidden files */ if (ctx->efs_raw) ctx->hide_hid_files = FALSE; #endif if (ntfs_set_shown_files(ctx->vol, ctx->show_sys_files, !ctx->hide_hid_files, ctx->hide_dot_files)) goto err_out; if (ctx->ignore_case && ntfs_set_ignore_case(vol)) goto err_out; if (ntfs_volume_get_free_space(ctx->vol)) { ntfs_log_perror("Failed to read NTFS $Bitmap"); goto err_out; } vol->free_mft_records = ntfs_get_nr_free_mft_records(vol); if (vol->free_mft_records < 0) { ntfs_log_perror("Failed to calculate free MFT records"); goto err_out; } if (ctx->hiberfile && ntfs_volume_check_hiberfile(vol, 0)) { if (errno != EPERM) goto err_out; if (ntfs_fuse_rm((fuse_req_t)NULL,FILE_root,"hiberfil.sys", RM_LINK)) goto err_out; } errno = 0; goto out; err_out: if (!errno) /* Make sure to return an error */ errno = EIO; out : return ntfs_volume_error(errno); } static void usage(void) { ntfs_log_info(usage_msg, EXEC_NAME, VERSION, FUSE_TYPE, fuse_version(), 5 + POSIXACLS*6 - KERNELPERMS*3 + CACHEING, EXEC_NAME, ntfs_home); } #if defined(linux) || defined(__uClinux__) static const char *dev_fuse_msg = "HINT: You should be root, or make ntfs-3g setuid root, or load the FUSE\n" " kernel module as root ('modprobe fuse' or 'insmod /fuse.ko'" " or insmod /fuse.o'). Make also sure that the fuse device" " exists. It's usually either /dev/fuse or /dev/misc/fuse."; static const char *fuse26_kmod_msg = "WARNING: Deficient Linux kernel detected. Some driver features are\n" " not available (swap file on NTFS, boot from NTFS by LILO), and\n" " unmount is not safe unless it's made sure the ntfs-3g process\n" " naturally terminates after calling 'umount'. If you wish this\n" " message to disappear then you should upgrade to at least kernel\n" " version 2.6.20, or request help from your distribution to fix\n" " the kernel problem. The below web page has more information:\n" " https://github.com/tuxera/ntfs-3g/wiki/NTFS-3G-FAQ\n" "\n"; static void mknod_dev_fuse(const char *dev) { struct stat st; if (stat(dev, &st) && (errno == ENOENT)) { mode_t mask = umask(0); if (mknod(dev, S_IFCHR | 0666, makedev(10, 229))) { ntfs_log_perror("Failed to create '%s'", dev); if (errno == EPERM) ntfs_log_error("%s", dev_fuse_msg); } umask(mask); } } static void create_dev_fuse(void) { mknod_dev_fuse("/dev/fuse"); #ifdef __UCLIBC__ { struct stat st; /* The fuse device is under /dev/misc using devfs. */ if (stat("/dev/misc", &st) && (errno == ENOENT)) { mode_t mask = umask(0); mkdir("/dev/misc", 0775); umask(mask); } mknod_dev_fuse("/dev/misc/fuse"); } #endif } static fuse_fstype get_fuse_fstype(void) { char buf[256]; fuse_fstype fstype = FSTYPE_NONE; FILE *f = fopen("/proc/filesystems", "r"); if (!f) { ntfs_log_perror("Failed to open /proc/filesystems"); return FSTYPE_UNKNOWN; } while (fgets(buf, sizeof(buf), f)) { if (strstr(buf, "fuseblk\n")) { fstype = FSTYPE_FUSEBLK; break; } if (strstr(buf, "fuse\n")) fstype = FSTYPE_FUSE; } fclose(f); return fstype; } static fuse_fstype load_fuse_module(void) { int i; struct stat st; pid_t pid; const char *cmd = "/sbin/modprobe"; char *env = (char*)NULL; struct timespec req = { 0, 100000000 }; /* 100 msec */ fuse_fstype fstype; if (!stat(cmd, &st) && !geteuid()) { pid = fork(); if (!pid) { execle(cmd, cmd, "fuse", (char*)NULL, &env); _exit(1); } else if (pid != -1) waitpid(pid, NULL, 0); } for (i = 0; i < 10; i++) { /* * We sleep first because despite the detection of the loaded * FUSE kernel module, fuse_mount() can still fail if it's not * fully functional/initialized. Note, of course this is still * unreliable but usually helps. */ nanosleep(&req, NULL); fstype = get_fuse_fstype(); if (fstype != FSTYPE_NONE) break; } return fstype; } #endif static struct fuse_chan *try_fuse_mount(char *parsed_options) { struct fuse_chan *fc = NULL; struct fuse_args margs = FUSE_ARGS_INIT(0, NULL); /* The fuse_mount() options get modified, so we always rebuild it */ if ((fuse_opt_add_arg(&margs, EXEC_NAME) == -1 || fuse_opt_add_arg(&margs, "-o") == -1 || fuse_opt_add_arg(&margs, parsed_options) == -1)) { ntfs_log_error("Failed to set FUSE options.\n"); goto free_args; } fc = fuse_mount(opts.mnt_point, &margs); free_args: fuse_opt_free_args(&margs); return fc; } static int set_fuseblk_options(char **parsed_options) { char options[64]; long pagesize; u32 blksize = ctx->vol->cluster_size; pagesize = sysconf(_SC_PAGESIZE); if (pagesize < 1) pagesize = 4096; if (blksize > (u32)pagesize) blksize = pagesize; snprintf(options, sizeof(options), ",blkdev,blksize=%u", blksize); if (ntfs_strappend(parsed_options, options)) return -1; return 0; } static struct fuse_session *mount_fuse(char *parsed_options) { struct fuse_session *se = NULL; struct fuse_args args = FUSE_ARGS_INIT(0, NULL); ctx->fc = try_fuse_mount(parsed_options); if (!ctx->fc) return NULL; if (fuse_opt_add_arg(&args, "") == -1) goto err; if (ctx->debug) if (fuse_opt_add_arg(&args, "-odebug") == -1) goto err; se = fuse_lowlevel_new(&args , &ntfs_3g_ops, sizeof(ntfs_3g_ops), NULL); if (!se) goto err; if (fuse_set_signal_handlers(se)) goto err_destroy; fuse_session_add_chan(se, ctx->fc); out: fuse_opt_free_args(&args); return se; err_destroy: fuse_session_destroy(se); se = NULL; err: fuse_unmount(opts.mnt_point, ctx->fc); goto out; } static void setup_logging(char *parsed_options) { if (!ctx->no_detach) { if (daemon(0, ctx->debug)) ntfs_log_error("Failed to daemonize.\n"); else if (!ctx->debug) { #ifndef DEBUG ntfs_log_set_handler(ntfs_log_handler_syslog); /* Override default libntfs identify. */ openlog(EXEC_NAME, LOG_PID, LOG_DAEMON); #endif } } ctx->seccache = (struct PERMISSIONS_CACHE*)NULL; ntfs_log_info("Version %s %s %d\n", VERSION, FUSE_TYPE, fuse_version()); if (strcmp(opts.arg_device,opts.device)) ntfs_log_info("Requested device %s canonicalized as %s\n", opts.arg_device,opts.device); ntfs_log_info("Mounted %s (%s, label \"%s\", NTFS %d.%d)\n", opts.device, (ctx->ro) ? "Read-Only" : "Read-Write", ctx->vol->vol_name, ctx->vol->major_ver, ctx->vol->minor_ver); ntfs_log_info("Cmdline options: %s\n", opts.options ? opts.options : ""); ntfs_log_info("Mount options: %s\n", parsed_options); } int main(int argc, char *argv[]) { char *parsed_options = NULL; struct fuse_session *se; #if !(defined(__sun) && defined (__SVR4)) fuse_fstype fstype = FSTYPE_UNKNOWN; #endif const char *permissions_mode = (const char*)NULL; const char *failed_secure = (const char*)NULL; #if defined(HAVE_SETXATTR) && defined(XATTR_MAPPINGS) struct XATTRMAPPING *xattr_mapping = (struct XATTRMAPPING*)NULL; #endif /* defined(HAVE_SETXATTR) && defined(XATTR_MAPPINGS) */ struct stat sbuf; unsigned long existing_mount; int err, fd; /* * Make sure file descriptors 0, 1 and 2 are open, * otherwise chaos would ensue. */ do { fd = open("/dev/null", O_RDWR); if (fd > 2) close(fd); } while (fd >= 0 && fd <= 2); #ifndef FUSE_INTERNAL if ((getuid() != geteuid()) || (getgid() != getegid())) { fprintf(stderr, "%s", setuid_msg); return NTFS_VOLUME_INSECURE; } #endif if (drop_privs()) return NTFS_VOLUME_NO_PRIVILEGE; ntfs_set_locale(); ntfs_log_set_handler(ntfs_log_handler_stderr); if (ntfs_parse_options(&opts, usage, argc, argv)) { usage(); return NTFS_VOLUME_SYNTAX_ERROR; } if (ntfs_fuse_init()) { err = NTFS_VOLUME_OUT_OF_MEMORY; goto err2; } parsed_options = parse_mount_options(ctx, &opts, TRUE); if (!parsed_options) { err = NTFS_VOLUME_SYNTAX_ERROR; goto err_out; } if (!ntfs_check_if_mounted(opts.device,&existing_mount) && (existing_mount & NTFS_MF_MOUNTED) /* accept multiple read-only mounts */ && (!(existing_mount & NTFS_MF_READONLY) || !ctx->ro)) { err = NTFS_VOLUME_LOCKED; goto err_out; } /* need absolute mount point for junctions */ if (opts.mnt_point[0] == '/') ctx->abs_mnt_point = strdup(opts.mnt_point); else { ctx->abs_mnt_point = (char*)ntfs_malloc(PATH_MAX); if (ctx->abs_mnt_point) { if ((strlen(opts.mnt_point) < PATH_MAX) && getcwd(ctx->abs_mnt_point, PATH_MAX - strlen(opts.mnt_point) - 1)) { strcat(ctx->abs_mnt_point, "/"); strcat(ctx->abs_mnt_point, opts.mnt_point); #if defined(__sun) && defined (__SVR4) /* Solaris also wants the absolute mount point */ opts.mnt_point = ctx->abs_mnt_point; #endif /* defined(__sun) && defined (__SVR4) */ } else { free(ctx->abs_mnt_point); ctx->abs_mnt_point = (char*)NULL; } } } if (!ctx->abs_mnt_point) { err = NTFS_VOLUME_OUT_OF_MEMORY; goto err_out; } ctx->security.uid = 0; ctx->security.gid = 0; if ((opts.mnt_point[0] == '/') && !stat(opts.mnt_point,&sbuf)) { /* collect owner of mount point, useful for default mapping */ ctx->security.uid = sbuf.st_uid; ctx->security.gid = sbuf.st_gid; } #if defined(linux) || defined(__uClinux__) fstype = get_fuse_fstype(); err = NTFS_VOLUME_NO_PRIVILEGE; if (restore_privs()) goto err_out; if (fstype == FSTYPE_NONE || fstype == FSTYPE_UNKNOWN) fstype = load_fuse_module(); create_dev_fuse(); if (drop_privs()) goto err_out; #endif if (stat(opts.device, &sbuf)) { ntfs_log_perror("Failed to access '%s'", opts.device); err = NTFS_VOLUME_NO_PRIVILEGE; goto err_out; } #if !(defined(__sun) && defined (__SVR4)) /* Always use fuseblk for block devices unless it's surely missing. */ if (S_ISBLK(sbuf.st_mode) && (fstype != FSTYPE_FUSE)) ctx->blkdev = TRUE; #endif #ifndef FUSE_INTERNAL if (getuid() && ctx->blkdev) { ntfs_log_error("%s", unpriv_fuseblk_msg); err = NTFS_VOLUME_NO_PRIVILEGE; goto err2; } #endif err = ntfs_open(opts.device); if (err) goto err_out; /* Force read-only mount if the device was found read-only */ if (!ctx->ro && NVolReadOnly(ctx->vol)) { ctx->rw = FALSE; ctx->ro = TRUE; if (ntfs_strinsert(&parsed_options, ",ro")) goto err_out; ntfs_log_info("Could not mount read-write, trying read-only\n"); } else if (ctx->rw && ntfs_strinsert(&parsed_options, ",rw")) goto err_out; /* We must do this after ntfs_open() to be able to set the blksize */ if (ctx->blkdev && set_fuseblk_options(&parsed_options)) goto err_out; ctx->vol->abs_mnt_point = ctx->abs_mnt_point; ctx->vol->special_files = ctx->special_files; ctx->security.vol = ctx->vol; ctx->vol->secure_flags = ctx->secure_flags; #ifdef HAVE_SETXATTR /* extended attributes interface required */ ctx->vol->efs_raw = ctx->efs_raw; #endif /* HAVE_SETXATTR */ if (!ntfs_build_mapping(&ctx->security,ctx->usermap_path, (ctx->vol->secure_flags & ((1 << SECURITY_DEFAULT) | (1 << SECURITY_ACL))) && !ctx->inherit && !(ctx->vol->secure_flags & (1 << SECURITY_WANTED)))) { #if POSIXACLS /* use basic permissions if requested */ if (ctx->vol->secure_flags & (1 << SECURITY_DEFAULT)) permissions_mode = "User mapping built, Posix ACLs not used"; else { permissions_mode = "User mapping built, Posix ACLs in use"; #if KERNELACLS if (ntfs_strinsert(&parsed_options, ",default_permissions,acl")) { err = NTFS_VOLUME_SYNTAX_ERROR; goto err_out; } #endif /* KERNELACLS */ } #else /* POSIXACLS */ if (!(ctx->vol->secure_flags & ((1 << SECURITY_DEFAULT) | (1 << SECURITY_ACL)))) { /* * No explicit option but user mapping found * force default security */ #if KERNELPERMS ctx->vol->secure_flags |= (1 << SECURITY_DEFAULT); if (ntfs_strinsert(&parsed_options, ",default_permissions")) { err = NTFS_VOLUME_SYNTAX_ERROR; goto err_out; } #endif /* KERNELPERMS */ } permissions_mode = "User mapping built"; #endif /* POSIXACLS */ ctx->dmask = ctx->fmask = 0; } else { ctx->security.uid = ctx->uid; ctx->security.gid = ctx->gid; /* same ownership/permissions for all files */ ctx->security.mapping[MAPUSERS] = (struct MAPPING*)NULL; ctx->security.mapping[MAPGROUPS] = (struct MAPPING*)NULL; if ((ctx->vol->secure_flags & (1 << SECURITY_WANTED)) && !(ctx->vol->secure_flags & (1 << SECURITY_DEFAULT))) { ctx->vol->secure_flags |= (1 << SECURITY_DEFAULT); if (ntfs_strinsert(&parsed_options, ",default_permissions")) { err = NTFS_VOLUME_SYNTAX_ERROR; goto err_out; } } if (ctx->vol->secure_flags & (1 << SECURITY_DEFAULT)) { ctx->vol->secure_flags |= (1 << SECURITY_RAW); permissions_mode = "Global ownership and permissions enforced"; } else { ctx->vol->secure_flags &= ~(1 << SECURITY_RAW); permissions_mode = "Ownership and permissions disabled"; } } if (ctx->usermap_path) free (ctx->usermap_path); #if defined(HAVE_SETXATTR) && defined(XATTR_MAPPINGS) xattr_mapping = ntfs_xattr_build_mapping(ctx->vol, ctx->xattrmap_path); ctx->vol->xattr_mapping = xattr_mapping; /* * Errors are logged, do not refuse mounting, it would be * too difficult to fix the unmountable mapping file. */ if (ctx->xattrmap_path) free(ctx->xattrmap_path); #endif /* defined(HAVE_SETXATTR) && defined(XATTR_MAPPINGS) */ #ifndef DISABLE_PLUGINS register_internal_reparse_plugins(); #endif /* DISABLE_PLUGINS */ se = mount_fuse(parsed_options); if (!se) { err = NTFS_VOLUME_FUSE_ERROR; goto err_out; } ctx->mounted = TRUE; #if defined(linux) || defined(__uClinux__) if (S_ISBLK(sbuf.st_mode) && (fstype == FSTYPE_FUSE)) ntfs_log_info("%s", fuse26_kmod_msg); #endif setup_logging(parsed_options); if (failed_secure) ntfs_log_info("%s\n",failed_secure); if (permissions_mode) ntfs_log_info("%s, configuration type %d\n",permissions_mode, 5 + POSIXACLS*6 - KERNELPERMS*3 + CACHEING); fuse_session_loop(se); fuse_remove_signal_handlers(se); err = 0; fuse_unmount(opts.mnt_point, ctx->fc); fuse_session_destroy(se); err_out: ntfs_mount_error(opts.device, opts.mnt_point, err); if (ctx->abs_mnt_point) free(ctx->abs_mnt_point); #if defined(HAVE_SETXATTR) && defined(XATTR_MAPPINGS) ntfs_xattr_free_mapping(xattr_mapping); #endif /* defined(HAVE_SETXATTR) && defined(XATTR_MAPPINGS) */ err2: ntfs_close(); #ifndef DISABLE_PLUGINS close_reparse_plugins(ctx); #endif /* DISABLE_PLUGINS */ free(ctx); free(parsed_options); free(opts.options); free(opts.device); return err; } ntfs-3g-2026.2.25/src/ntfs-3g_common.h0000664000175000017500000001263115152260174012575 /* * ntfs-3g_common.h - Common declarations for ntfs-3g and lowntfs-3g. * * Copyright (c) 2010-2011 Jean-Pierre Andre * Copyright (c) 2010 Erik Larsson * * This program/include file 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/include file 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_3G_COMMON_H #define _NTFS_3G_COMMON_H #include "inode.h" struct ntfs_options { char *mnt_point; /* Mount point */ char *options; /* Mount options */ char *device; /* Device to mount */ char *arg_device; /* Device requested in argv */ } ; typedef enum { NF_STREAMS_INTERFACE_NONE, /* No access to named data streams. */ NF_STREAMS_INTERFACE_XATTR, /* Map named data streams to xattrs. */ NF_STREAMS_INTERFACE_OPENXATTR, /* Same, not limited to "user." */ NF_STREAMS_INTERFACE_WINDOWS, /* "file:stream" interface. */ } ntfs_fuse_streams_interface; struct DEFOPTION { const char *name; int type; int flags; } ; /* Options, order not significant */ enum { OPT_RO, OPT_NOATIME, OPT_ATIME, OPT_RELATIME, OPT_DMTIME, OPT_RW, OPT_FAKE_RW, OPT_FSNAME, OPT_NO_DEF_OPTS, OPT_DEFAULT_PERMISSIONS, OPT_PERMISSIONS, OPT_ACL, OPT_UMASK, OPT_FMASK, OPT_DMASK, OPT_UID, OPT_GID, OPT_SHOW_SYS_FILES, OPT_HIDE_HID_FILES, OPT_HIDE_DOT_FILES, OPT_IGNORE_CASE, OPT_WINDOWS_NAMES, OPT_COMPRESSION, OPT_NOCOMPRESSION, OPT_SILENT, OPT_RECOVER, OPT_NORECOVER, OPT_REMOVE_HIBERFILE, OPT_SYNC, OPT_BIG_WRITES, OPT_LOCALE, OPT_NFCONV, OPT_NONFCONV, OPT_STREAMS_INTERFACE, OPT_USER_XATTR, OPT_NOAUTO, OPT_DEBUG, OPT_NO_DETACH, OPT_REMOUNT, OPT_BLKSIZE, OPT_INHERIT, OPT_ADDSECURIDS, OPT_STATICGRPS, OPT_USERMAPPING, OPT_XATTRMAPPING, OPT_EFS_RAW, OPT_POSIX_NLINK, OPT_SPECIAL_FILES, OPT_HELP, OPT_VERSION, } ; /* Option flags */ enum { FLGOPT_BOGUS = 1, FLGOPT_STRING = 2, FLGOPT_OCTAL = 4, FLGOPT_DECIMAL = 8, FLGOPT_APPEND = 16, FLGOPT_NOSUPPORT = 32, FLGOPT_OPTIONAL = 64 } ; typedef enum { ATIME_ENABLED, ATIME_DISABLED, ATIME_RELATIVE } ntfs_atime_t; typedef enum { ERR_PLUGIN = 1 } single_log_t; #ifndef DISABLE_PLUGINS typedef struct plugin_list { struct plugin_list *next; void *handle; const plugin_operations_t *ops; le32 tag; } plugin_list_t; #endif /* DISABLE_PLUGINS */ typedef struct { ntfs_volume *vol; unsigned int uid; unsigned int gid; unsigned int fmask; unsigned int dmask; ntfs_fuse_streams_interface streams; ntfs_atime_t atime; s64 dmtime; BOOL ro; BOOL rw; BOOL show_sys_files; BOOL hide_hid_files; BOOL hide_dot_files; BOOL windows_names; BOOL ignore_case; BOOL compression; BOOL acl; BOOL silent; BOOL recover; BOOL hiberfile; BOOL sync; BOOL big_writes; BOOL debug; BOOL no_detach; BOOL blkdev; BOOL mounted; BOOL posix_nlink; ntfs_volume_special_files special_files; #ifdef HAVE_SETXATTR /* extended attributes interface required */ BOOL efs_raw; #ifdef XATTR_MAPPINGS char *xattrmap_path; #endif /* XATTR_MAPPINGS */ #endif /* HAVE_SETXATTR */ struct fuse_chan *fc; BOOL inherit; unsigned int secure_flags; single_log_t errors_logged; char *usermap_path; char *abs_mnt_point; #ifndef DISABLE_PLUGINS plugin_list_t *plugins; #endif /* DISABLE_PLUGINS */ struct PERMISSIONS_CACHE *seccache; struct SECURITY_CONTEXT security; struct open_file *open_files; /* only defined in lowntfs-3g */ u64 latest_ghost; } ntfs_fuse_context_t; extern const char *EXEC_NAME; #ifdef FUSE_INTERNAL #define FUSE_TYPE "integrated FUSE" #else #define FUSE_TYPE "external FUSE" #endif extern const char xattr_ntfs_3g[]; extern const char nf_ns_user_prefix[]; extern const int nf_ns_user_prefix_len; extern const char nf_ns_system_prefix[]; extern const int nf_ns_system_prefix_len; extern const char nf_ns_security_prefix[]; extern const int nf_ns_security_prefix_len; extern const char nf_ns_trusted_prefix[]; extern const int nf_ns_trusted_prefix_len; int ntfs_strappend(char **dest, const char *append); int ntfs_strinsert(char **dest, const char *append); char *parse_mount_options(ntfs_fuse_context_t *ctx, const struct ntfs_options *popts, BOOL low_fuse); int ntfs_parse_options(struct ntfs_options *popts, void (*usage)(void), int argc, char *argv[]); int ntfs_fuse_listxattr_common(ntfs_inode *ni, ntfs_attr_search_ctx *actx, char *list, size_t size, BOOL prefixing); BOOL user_xattrs_allowed(ntfs_fuse_context_t *ctx, ntfs_inode *ni); #ifndef DISABLE_PLUGINS void close_reparse_plugins(ntfs_fuse_context_t *ctx); const struct plugin_operations *select_reparse_plugin(ntfs_fuse_context_t *ctx, ntfs_inode *ni, REPARSE_POINT **reparse); int register_reparse_plugin(ntfs_fuse_context_t *ctx, le32 tag, const plugin_operations_t *ops, void *handle); #endif /* DISABLE_PLUGINS */ #endif /* _NTFS_3G_COMMON_H */ ntfs-3g-2026.2.25/src/ntfs-3g.8.in0000664000175000017500000004474015152260174011560 .\" Copyright (c) 2005-2006 Yura Pakhuchiy. .\" Copyright (c) 2005 Richard Russon. .\" Copyright (c) 2006-2009 Szabolcs Szakacsits. .\" Copyright (c) 2009-2014 Jean-Pierre Andre .\" This file may be copied under the terms of the GNU Public License. .\" .TH NTFS-3G 8 "Aug 2021" "ntfs-3g @VERSION@" .SH NAME ntfs-3g \- Third Generation Read/Write NTFS Driver .SH SYNOPSIS .B ntfs-3g \fB[-o \fIoption\fP\fB[,...]]\fR .I volume mount_point .br .B mount \-t ntfs-3g \fB[-o \fIoption\fP\fB[,...]]\fR .I volume mount_point .br .B lowntfs-3g \fB[-o \fIoption\fP\fB[,...]]\fR .I volume mount_point .br .B mount \-t lowntfs-3g \fB[-o \fIoption\fP\fB[,...]]\fR .I volume mount_point .SH DESCRIPTION \fBntfs-3g\fR is an NTFS driver, which can create, remove, rename, move files, directories, hard links, and streams; it can read and write files, including streams, sparse files and transparently compressed files; it can handle special files like symbolic links, devices, and FIFOs; moreover it provides standard management of file ownership and permissions, including POSIX ACLs. .PP It comes in two variants \fBntfs-3g\fR and \fBlowntfs-3g\fR with a few differences mentioned below in relevant options descriptions. .PP The \fIvolume\fR to be mounted can be either a block device or an image file, either by using the mount command or starting the drive. .SS Windows hibernation and fast restarting On computers which can be dual-booted into Windows or Linux, Windows has to be fully shut down before booting into Linux, otherwise the NTFS file systems on internal disks may be left in an inconsistent state and changes made by Linux may be ignored by Windows. .P So, Windows may not be left in hibernation when starting Linux, in order to avoid inconsistencies. Moreover, the fast restart feature available on recent Windows systems has to be disabled. This can be achieved by issuing as an Administrator the Windows command which disables both hibernation and fast restarting : .RS .sp powercfg /h off .sp .RE If either Windows is hibernated or its fast restart is enabled, partitions on internal disks are forced to be mounted in read-only mode. .SS Access Handling and Security By default, files and directories are owned by the effective user and group of the mounting process, and everybody has full read, write, execution and directory browsing permissions. You can also assign permissions to a single user by using the .B uid and/or the .B gid options together with the .B umask, or .B fmask and .B dmask options. .PP Doing so, all Windows users have full access to the files created by .B ntfs-3g. .PP But, by setting the \fBpermissions\fR option, you can benefit from the full ownership and permissions features as defined by POSIX. Moreover, by defining a Windows-to-Linux user mapping, the ownerships and permissions are even applied to Windows users and conversely. .PP If .B ntfs-3g is set setuid-root then non-root users will be also able to mount volumes. .SS Windows Filename Compatibility NTFS supports several filename namespaces: DOS, Win32 and POSIX. While the \fBntfs-3g\fR driver handles all of them, it always creates new files in the POSIX namespace for maximum portability and interoperability reasons. This means that filenames are case sensitive and all characters are allowed except '/' and '\\0'. This is perfectly legal on Windows, though some application may get confused. The option \fBwindows_names\fP may be used to apply Windows restrictions to new file names. .SS Alternate Data Streams (ADS) NTFS stores all data in streams. Every file has exactly one unnamed data stream and can have many named data streams. The size of a file is the size of its unnamed data stream. By default, \fBntfs-3g\fR will only read the unnamed data stream. .PP By using the option \fBstreams_interface=windows\fP, with the ntfs-3g driver (not possible with lowntfs-3g), you will be able to read any named data streams, simply by specifying the stream name after a colon. For example: .RS .sp cat some.mp3:artist .sp .RE Named data streams act like normal files, so you can read from them, write to them and even delete them (using rm). You can list all the named data streams a file has by getting the \fBntfs.streams.list\fP extended attribute. .SH OPTIONS Below is a summary of the options that \fBntfs-3g\fR accepts. .TP .B acl Enable setting Posix ACLs on created files and use them for access control. This option is only available on specific builds. It is set by default when a user mapping file is present and the .B permissions mount option is not set. .TP .B allow_other This option overrides the security measure restricting file access to the user mounting the filesystem. This option is only allowed to root, but this restriction can be overridden by the \fBuser_allow_other\fP option in the /etc/fuse.conf file. .TP .B atime, noatime, relatime The .B atime option updates inode access time for each access. The .B noatime option disables inode access time updates, which can speed up file operations and prevent sleeping (notebook) disks spinning up too often thus saving energy and disk lifetime. The .B relatime option is very similar to .B noatime. It updates inode access times relative to modify or change time. The access time is only updated if the previous access time was earlier than the current modify or change time. Unlike .B noatime this option doesn't break applications that need to know if a file has been read since the last time it was modified. This is the default behaviour. .TP .B big_writes This option prevents fuse from splitting write buffers into 4K chunks, enabling big write buffers to be transferred from the application in a single step (up to some system limit, generally 128K bytes). .TP .B compression This option enables creating new transparently compressed files in directories marked for compression. A directory is marked for compression by setting the bit 11 (value 0x00000800) in its Windows attribute. In such a directory, new files are created compressed and new subdirectories are themselves marked for compression. The option and the flag have no effect on existing files. Currently this is the default option. .TP .B debug Makes ntfs-3g (or lowntfs-3g) to print a lot of debug output from libntfs-3g and FUSE. .TP .B delay_mtime[= value] Only update the file modification time and the file change time of a file when it is closed or when the indicated delay since the previous update has elapsed. The argument is a number of seconds, with a default value of 60. This is mainly useful for big files which are kept open for a long time and written to without changing their size, such as databases or file system images mounted as loop. .TP .BI dmask= value Set the bitmask of the directory permissions that are not present. The value is given in octal. The default value is 0 which means full access to everybody. .TP .B efs_raw This option should only be used in backup or restore situation. It changes the apparent size of files and the behavior of read and write operation so that encrypted files can be saved and restored without being decrypted. The \fBuser.ntfs.efsinfo\fP extended attribute has also to be saved and restored for the file to be decrypted. .TP .BI fmask= value Set the bitmask of the file permissions that are not present. The value is given in octal. The default value is 0 which means full access to everybody. .TP .B force This option is obsolete. It has been superseded by the \fBrecover\fR and \fBnorecover\fR options. .TP .B hide_dot_files Set the hidden flag in the NTFS attribute for created files and directories whose first character of the name is a dot. Such files and directories normally do not appear in directory listings, and when the flag is set they do not appear in Windows directory displays either. When a file is renamed or linked with a new name, the hidden flag is adjusted to the latest name. .TP .B hide_hid_files Hide the hidden files and directories in directory listings, the hidden files and directories being the ones whose NTFS attribute have the hidden flag set. The hidden files will not be selected when using wildcards in commands, but all files and directories remain accessible by full name, for example you can always display the Windows trash bin directory by : "ls \-ld '$RECYCLE.BIN'". .TP .B ignore_case \fP(only with lowntfs-3g) Ignore character case when accessing a file (\fBFOO\fR, \fBFoo\fR, \fBfoo\fR, etc. designate the same file). All files are displayed with lower case in directory listings. .TP .B inherit When creating a new file, set its initial protections according to inheritance rules defined in parent directory. These rules deviate from Posix specifications, but yield a better Windows compatibility. The \fBpermissions\fR (or **acl**) option or a valid user mapping file is required for this option to be effective. .TP .BI locale= value This option can be useful when wanting a language specific locale environment. It is however discouraged as it leads to files with untranslatable characters to not be visible. .TP .BI max_read= value With this option the maximum size of read operations can be set. The default is infinite. Note that the size of read requests is limited anyway by the system (usually to 128kbyte). .TP .B no_def_opts By default ntfs-3g acts as if \fBsilent\fP (ignore permission errors when permissions are not enabled), \fBallow_other\fP (allow any user to access files) and \fBnonempty\fP (allow mounting on non-empty directories) were set, and \fBno_def_opts\fP cancels these default options. .TP .B no_detach Makes ntfs-3g to not detach from terminal and print some debug output. .TP .B nocompression This option disables creating new transparently compressed files in directories marked for compression. Existing compressed files can still be read and updated. .TP .B norecover Do not try to mount a partition which was not unmounted properly by Windows. .TP .B permissions Set standard permissions on created files and use standard access control. This option is set by default when a user mapping file is present. .TP .B posix_nlink Compute the count of hard links of a file or directory according to the POSIX specifications. When this option is not set, a count of 1 is set for directories, and the short name of files is accounted for. Using the option entails some penalty as the count is not stored and has to be computed. .TP .B recover Recover and try to mount a partition which was not unmounted properly by Windows. The Windows logfile is cleared, which may cause inconsistencies. Currently this is the default option. .TP .B remove_hiberfile When the NTFS volume is hibernated, a read-write mount is denied and a read-only mount is forced. One needs either to resume Windows and shutdown it properly, or use this option which will remove the Windows hibernation file. Please note, this means that the saved Windows session will be completely lost. Use this option under your own responsibility. .TP .B ro Mount the filesystem read\-only. Useful if Windows is hibernated or the NTFS journal file is unclean. .TP .B show_sys_files Show the metafiles in directory listings. Otherwise the default behaviour is to hide the metafiles, which are special files used to store the NTFS structure. Please note that even when this option is specified, "$MFT" may not be visible due to a glibc bug. Furthermore, irrespectively of \fBshow_sys_files\fP, all files are accessible by name, for example you can always do "ls \-l '$UpCase'". .TP .B silent Do nothing, without returning any error, on chmod and chown operations and on permission checking errors, when the \fBpermissions\fR option is not set and no user mapping file is defined. This option is on by default, and when set off (through option \fBno_def_opts\fR) ownership and permissions parameters have to be set. .TP .BI special_files= mode This option selects a mode for representing a special file to be created (symbolic link, socket, fifo, character or block device). The \fImode\fP can be \fBinterix\fR or \fBwsl\fR, and existing files in either mode are recognized irrespective of the selected mode. Interix is the traditional mode, used by default, and wsl is interoperable with Windows WSL, but it is not compatible with Windows versions earlier than Windows 10. Neither mode are interoperable with Windows. .TP .BI streams_interface= mode This option controls how the user can access Alternate Data Streams (ADS) or in other words, named data streams. The \fImode\fP can be set to one of \fBnone\fR, \fBwindows\fR or \fBxattr\fR. If the option is set to \fBnone\fR, the user will have no access to the named data streams. If it is set to \fBwindows\fR (not possible with lowntfs-3g), then the user can access them just like in Windows (eg. cat file:stream). If it's set to \fBxattr\fR, then the named data streams are mapped to extended attributes and a user can manipulate them using \fB{get,set}fattr\fR utilities. The default is \fBxattr\fR. .TP \fBuid=\fP\fIvalue\fP and \fBgid=\fP\fIvalue\fP Set the owner and the group of files and directories. The values are numerical. The defaults are the uid and gid of the current process. .TP .BI umask= value Set the bitmask of the file and directory permissions that are not present. The value is given in octal. The default value is 0 which means full access to everybody. .TP .BI usermapping= file-name Use file \fIfile-name\fP as the user mapping file instead of the default \fB.NTFS-3G/UserMapping\fP. If \fIfile-name\fP defines a full path, the file must be located on a partition previously mounted. If it defines a relative path, it is interpreted relative to the root of NTFS partition being mounted. .P .RS When a user mapping file is defined, the options \fBuid=\fP, \fBgid=\fP, \fBumask=\fP, \fBfmask=\fP, \fBdmask=\fP and \fBsilent\fP are ignored. .RE .TP .B user_xattr Same as \fBstreams_interface=\fP\fIxattr\fP. .TP .B windows_names This option prevents files, directories and extended attributes to be created with a name not allowed by windows, because .RS .RS .sp - it contains some not allowed character, .br - or the last character is a space or a dot, .br - or the name is reserved. .sp .RE The forbidden characters are the nine characters " * / : < > ? \\ | and those whose code is less than 0x20, and the reserved names are CON, PRN, AUX, NUL, COM1..COM9, LPT1..LPT9, with no suffix or followed by a dot. .sp Existing such files can still be read (and renamed). .RE .SH USER MAPPING NTFS uses specific ids to record the ownership of files instead of the \fBuid\fP (user id) and \fBgid\fP (group id) used by Linux. As a consequence a mapping between the ids has to be defined for ownerships to be recorded into NTFS files and recognized. .P By default, this mapping is fetched from the file \fB.NTFS-3G/UserMapping\fP located in the NTFS partition. The option \fBusermapping=\fP may be used to define another location. When the option **permissions** is set and no mapping file is found, a default mapping is used. .P Each line in the user mapping file defines a mapping. It is organized in three fields separated by colons. The first field identifies a \fBuid\fP, the second field identifies a \fBgid\fP and the third one identifies the corresponding NTFS id, known as a \fBSID\fP. The \fBuid\fP and the \fBgid\fP are optional and defining both of them for the same \fBSID\fP is not recommended. .P If no interoperation with Windows is needed, you can use the option \fBpermissions\fP to define a standard mapping. Alternately, you may define your own mapping by setting a single default mapping with no uid and gid. In both cases, files created on Linux will appear to Windows as owned by a foreign user, and files created on Windows will appear to Linux as owned by root. Just copy the example below and replace the 9 and 10-digit numbers by any number not greater than 4294967295. The resulting behavior is the same as the one with the option \fBpermission\fP set with no ownership option and no user mapping file available. .RS .sp .B ::S-1-5-21-3141592653-589793238-462643383-10000 .sp .RE If a strong interoperation with Windows is needed, the mapping has to be defined for each user and group known to both system, and the \fBSID\fPs used by Windows has to be collected. This will lead to a user mapping file like : .RS .sp .B john::S-1-5-21-3141592653-589793238-462643383-1008 .B mary::S-1-5-21-3141592653-589793238-462643383-1009 .B :smith:S-1-5-21-3141592653-589793238-462643383-513 .B ::S-1-5-21-3141592653-589793238-462643383-10000 .sp .RE .P The utility \fBntfsusermap\fP may be used to create such a user mapping file. .SH EXAMPLES Mount /dev/sda1 to /mnt/windows: .RS .sp .B ntfs-3g /dev/sda1 /mnt/windows .RE or .RS .B mount -t ntfs-3g /dev/sda1 /mnt/windows .sp .RE Mount the ntfs data partition /dev/sda3 to /mnt/data with standard Linux permissions applied : .RS .sp .B ntfs-3g -o permissions /dev/sda3 /mnt/data .RE or .RS .B mount -t ntfs-3g -o permissions /dev/sda3 /mnt/data .sp .RE Read\-only mount /dev/sda5 to /home/user/mnt and make user with uid 1000 to be the owner of all files: .RS .sp .B ntfs-3g /dev/sda5 /home/user/mnt \-o ro,uid=1000 .sp .RE /etc/fstab entry for the above (the sixth and last field has to be zero to avoid a file system check at boot time) : .RS .sp .B /dev/sda5 /home/user/mnt ntfs\-3g ro,uid=1000 0 0 .sp .RE Unmount /mnt/windows: .RS .sp .B umount /mnt/windows .sp .RE .SH EXIT CODES To facilitate the use of the .B ntfs-3g driver in scripts, an exit code is returned to give an indication of the mountability status of a volume. Value 0 means success, and all other ones mean an error. The unique error codes are documented in the .BR ntfs-3g.probe (8) manual page. .SH KNOWN ISSUES Please see .RS .sp https://github.com/tuxera/ntfs-3g/wiki/NTFS-3G-FAQ .sp .RE for common questions and known issues. If you would find a new one in the latest release of the software then please post an ntfs-3g issue describing it in detail so that the development team can be aware of the issue and take care of it: .RS .sp https://github.com/tuxera/ntfs-3g/issues .sp .RE .SH AUTHORS .B ntfs-3g was based on and a major improvement to ntfsmount and libntfs which were written by Yura Pakhuchiy and the Linux-NTFS team. The improvements were made, the ntfs-3g project was initiated and currently led by long time Linux-NTFS team developer Szabolcs Szakacsits (szaka@tuxera.com). .SH THANKS Several people made heroic efforts, often over five or more years which resulted the ntfs-3g driver. Most importantly they are Anton Altaparmakov, Jean-Pierre André, Erik Larsson, Richard Russon, Szabolcs Szakacsits, Yura Pakhuchiy, Yuval Fledel, and the author of the groundbreaking FUSE filesystem development framework, Miklos Szeredi. .SH SEE ALSO .BR ntfs-3g.probe (8), .BR ntfsprogs (8), .BR attr (5), .BR getfattr (1) ntfs-3g-2026.2.25/src/Makefile.in0000664000175000017500000012617015152260212011635 # Makefile.in generated by automake 1.17 from Makefile.am. # @configure_input@ # Copyright (C) 1994-2024 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY, to the extent permitted by law; without # even the implied warranty of MERCHANTABILITY or FITNESS FOR A # PARTICULAR PURPOSE. @SET_MAKE@ VPATH = @srcdir@ am__is_gnu_make = { \ if test -z '$(MAKELEVEL)'; then \ false; \ elif test -n '$(MAKE_HOST)'; then \ true; \ elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \ true; \ else \ false; \ fi; \ } am__make_running_with_option = \ case $${target_option-} in \ ?) ;; \ *) echo "am__make_running_with_option: internal error: invalid" \ "target option '$${target_option-}' specified" >&2; \ exit 1;; \ esac; \ has_opt=no; \ sane_makeflags=$$MAKEFLAGS; \ if $(am__is_gnu_make); then \ sane_makeflags=$$MFLAGS; \ else \ case $$MAKEFLAGS in \ *\\[\ \ ]*) \ bs=\\; \ sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \ | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \ esac; \ fi; \ skip_next=no; \ strip_trailopt () \ { \ flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \ }; \ for flg in $$sane_makeflags; do \ test $$skip_next = yes && { skip_next=no; continue; }; \ case $$flg in \ *=*|--*) continue;; \ -*I) strip_trailopt 'I'; skip_next=yes;; \ -*I?*) strip_trailopt 'I';; \ -*O) strip_trailopt 'O'; skip_next=yes;; \ -*O?*) strip_trailopt 'O';; \ -*l) strip_trailopt 'l'; skip_next=yes;; \ -*l?*) strip_trailopt 'l';; \ -[dEDm]) skip_next=yes;; \ -[JT]) skip_next=yes;; \ esac; \ case $$flg in \ *$$target_option*) has_opt=yes; break;; \ esac; \ done; \ test $$has_opt = yes am__make_dryrun = (target_option=n; $(am__make_running_with_option)) am__make_keepgoing = (target_option=k; $(am__make_running_with_option)) am__rm_f = rm -f $(am__rm_f_notfound) am__rm_rf = rm -rf $(am__rm_f_notfound) pkgdatadir = $(datadir)/@PACKAGE@ pkgincludedir = $(includedir)/@PACKAGE@ pkglibdir = $(libdir)/@PACKAGE@ pkglibexecdir = $(libexecdir)/@PACKAGE@ am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd install_sh_DATA = $(install_sh) -c -m 644 install_sh_PROGRAM = $(install_sh) -c install_sh_SCRIPT = $(install_sh) -c INSTALL_HEADER = $(INSTALL_DATA) transform = $(program_transform_name) NORMAL_INSTALL = : PRE_INSTALL = : POST_INSTALL = : NORMAL_UNINSTALL = : PRE_UNINSTALL = : POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ target_triplet = @target@ @ENABLE_NTFS_3G_TRUE@bin_PROGRAMS = ntfs-3g.probe$(EXEEXT) @ENABLE_NTFS_3G_TRUE@rootbin_PROGRAMS = ntfs-3g$(EXEEXT) \ @ENABLE_NTFS_3G_TRUE@ lowntfs-3g$(EXEEXT) subdir = src ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \ $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \ $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \ $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) DIST_COMMON = $(srcdir)/Makefile.am $(am__DIST_COMMON) mkinstalldirs = $(install_sh) -d CONFIG_HEADER = $(top_builddir)/config.h CONFIG_CLEAN_FILES = ntfs-3g.8 ntfs-3g.probe.8 CONFIG_CLEAN_VPATH_FILES = am__installdirs = "$(DESTDIR)$(bindir)" "$(DESTDIR)$(rootbindir)" \ "$(DESTDIR)$(man8dir)" "$(DESTDIR)$(rootsbindir)" PROGRAMS = $(bin_PROGRAMS) $(rootbin_PROGRAMS) am__lowntfs_3g_SOURCES_DIST = lowntfs-3g.c ntfs-3g_common.c @ENABLE_NTFS_3G_TRUE@am_lowntfs_3g_OBJECTS = \ @ENABLE_NTFS_3G_TRUE@ lowntfs_3g-lowntfs-3g.$(OBJEXT) \ @ENABLE_NTFS_3G_TRUE@ lowntfs_3g-ntfs-3g_common.$(OBJEXT) lowntfs_3g_OBJECTS = $(am_lowntfs_3g_OBJECTS) am__DEPENDENCIES_1 = @FUSE_INTERNAL_FALSE@am__DEPENDENCIES_2 = $(am__DEPENDENCIES_1) @FUSE_INTERNAL_TRUE@am__DEPENDENCIES_2 = $(top_builddir)/libfuse-lite/libfuse-lite.la @ENABLE_NTFS_3G_TRUE@lowntfs_3g_DEPENDENCIES = $(am__DEPENDENCIES_1) \ @ENABLE_NTFS_3G_TRUE@ $(am__DEPENDENCIES_2) \ @ENABLE_NTFS_3G_TRUE@ $(top_builddir)/libntfs-3g/libntfs-3g.la AM_V_lt = $(am__v_lt_@AM_V@) am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) am__v_lt_0 = --silent am__v_lt_1 = lowntfs_3g_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(lowntfs_3g_CFLAGS) \ $(CFLAGS) $(lowntfs_3g_LDFLAGS) $(LDFLAGS) -o $@ am__ntfs_3g_SOURCES_DIST = ntfs-3g.c ntfs-3g_common.c @ENABLE_NTFS_3G_TRUE@am_ntfs_3g_OBJECTS = ntfs_3g-ntfs-3g.$(OBJEXT) \ @ENABLE_NTFS_3G_TRUE@ ntfs_3g-ntfs-3g_common.$(OBJEXT) ntfs_3g_OBJECTS = $(am_ntfs_3g_OBJECTS) @ENABLE_NTFS_3G_TRUE@ntfs_3g_DEPENDENCIES = $(am__DEPENDENCIES_1) \ @ENABLE_NTFS_3G_TRUE@ $(am__DEPENDENCIES_2) \ @ENABLE_NTFS_3G_TRUE@ $(top_builddir)/libntfs-3g/libntfs-3g.la ntfs_3g_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(ntfs_3g_CFLAGS) \ $(CFLAGS) $(ntfs_3g_LDFLAGS) $(LDFLAGS) -o $@ am__ntfs_3g_probe_SOURCES_DIST = ntfs-3g.probe.c @ENABLE_NTFS_3G_TRUE@am_ntfs_3g_probe_OBJECTS = \ @ENABLE_NTFS_3G_TRUE@ ntfs_3g_probe-ntfs-3g.probe.$(OBJEXT) ntfs_3g_probe_OBJECTS = $(am_ntfs_3g_probe_OBJECTS) @ENABLE_NTFS_3G_TRUE@ntfs_3g_probe_DEPENDENCIES = \ @ENABLE_NTFS_3G_TRUE@ $(top_builddir)/libntfs-3g/libntfs-3g.la ntfs_3g_probe_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(ntfs_3g_probe_CFLAGS) \ $(CFLAGS) $(ntfs_3g_probe_LDFLAGS) $(LDFLAGS) -o $@ AM_V_P = $(am__v_P_@AM_V@) am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) am__v_P_0 = false am__v_P_1 = : AM_V_GEN = $(am__v_GEN_@AM_V@) am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@) am__v_GEN_0 = @echo " GEN " $@; am__v_GEN_1 = AM_V_at = $(am__v_at_@AM_V@) am__v_at_ = $(am__v_at_@AM_DEFAULT_V@) am__v_at_0 = @ am__v_at_1 = DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) depcomp = $(SHELL) $(top_srcdir)/depcomp am__maybe_remake_depfiles = depfiles am__depfiles_remade = ./$(DEPDIR)/lowntfs_3g-lowntfs-3g.Po \ ./$(DEPDIR)/lowntfs_3g-ntfs-3g_common.Po \ ./$(DEPDIR)/ntfs_3g-ntfs-3g.Po \ ./$(DEPDIR)/ntfs_3g-ntfs-3g_common.Po \ ./$(DEPDIR)/ntfs_3g_probe-ntfs-3g.probe.Po am__mv = mv -f COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \ $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \ $(AM_CFLAGS) $(CFLAGS) AM_V_CC = $(am__v_CC_@AM_V@) am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@) am__v_CC_0 = @echo " CC " $@; am__v_CC_1 = CCLD = $(CC) LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ $(AM_LDFLAGS) $(LDFLAGS) -o $@ AM_V_CCLD = $(am__v_CCLD_@AM_V@) am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@) am__v_CCLD_0 = @echo " CCLD " $@; am__v_CCLD_1 = SOURCES = $(lowntfs_3g_SOURCES) $(ntfs_3g_SOURCES) \ $(ntfs_3g_probe_SOURCES) DIST_SOURCES = $(am__lowntfs_3g_SOURCES_DIST) \ $(am__ntfs_3g_SOURCES_DIST) $(am__ntfs_3g_probe_SOURCES_DIST) am__can_run_installinfo = \ case $$AM_UPDATE_INFO_DIR in \ n|no|NO) false;; \ *) (install-info --version) >/dev/null 2>&1;; \ esac am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; am__vpath_adj = case $$p in \ $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ *) f=$$p;; \ esac; am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`; am__install_max = 40 am__nobase_strip_setup = \ srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'` am__nobase_strip = \ for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||" am__nobase_list = $(am__nobase_strip_setup); \ for p in $$list; do echo "$$p $$p"; done | \ sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \ $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \ if (++n[$$2] == $(am__install_max)) \ { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \ END { for (dir in files) print dir, files[dir] }' am__base_list = \ sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' am__uninstall_files_from_dir = { \ { test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; } \ || { echo " ( cd '$$dir' && rm -f" $$files ")"; \ $(am__cd) "$$dir" && echo $$files | $(am__xargs_n) 40 $(am__rm_f); }; \ } man8dir = $(mandir)/man8 NROFF = nroff MANS = $(man_MANS) DATA = $(rootsbin_DATA) am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) # Read a list of newline-separated strings from the standard input, # and print each of them once, without duplicates. Input order is # *not* preserved. am__uniquify_input = $(AWK) '\ BEGIN { nonempty = 0; } \ { items[$$0] = 1; nonempty = 1; } \ END { if (nonempty) { for (i in items) print i; }; } \ ' # Make sure the list of sources is unique. This is necessary because, # e.g., the same source file might be shared among _SOURCES variables # for different programs/libraries. am__define_uniq_tagged_files = \ list='$(am__tagged_files)'; \ unique=`for i in $$list; do \ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ done | $(am__uniquify_input)` am__DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/ntfs-3g.8.in \ $(srcdir)/ntfs-3g.probe.8.in $(top_srcdir)/depcomp DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) ACLOCAL = @ACLOCAL@ AMTAR = @AMTAR@ AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ AR = @AR@ AUTOCONF = @AUTOCONF@ AUTOHEADER = @AUTOHEADER@ AUTOMAKE = @AUTOMAKE@ AWK = @AWK@ CC = @CC@ CCDEPMODE = @CCDEPMODE@ CFLAGS = @CFLAGS@ CPPFLAGS = @CPPFLAGS@ CSCOPE = @CSCOPE@ CTAGS = @CTAGS@ CYGPATH_W = @CYGPATH_W@ DEFS = @DEFS@ DEPDIR = @DEPDIR@ DLLTOOL = @DLLTOOL@ DSYMUTIL = @DSYMUTIL@ DUMPBIN = @DUMPBIN@ ECHO_C = @ECHO_C@ ECHO_N = @ECHO_N@ ECHO_T = @ECHO_T@ EGREP = @EGREP@ ETAGS = @ETAGS@ EXEEXT = @EXEEXT@ FGREP = @FGREP@ FILECMD = @FILECMD@ FUSE_MODULE_CFLAGS = @FUSE_MODULE_CFLAGS@ FUSE_MODULE_LIBS = @FUSE_MODULE_LIBS@ GNUTLS_CFLAGS = @GNUTLS_CFLAGS@ GNUTLS_LIBS = @GNUTLS_LIBS@ GPGRT_CONFIG = @GPGRT_CONFIG@ GREP = @GREP@ INSTALL = @INSTALL@ INSTALL_DATA = @INSTALL_DATA@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ INSTALL_SCRIPT = @INSTALL_SCRIPT@ INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ LD = @LD@ LDCONFIG = @LDCONFIG@ LDFLAGS = @LDFLAGS@ LIBDL = @LIBDL@ LIBFUSE_LITE_CFLAGS = @LIBFUSE_LITE_CFLAGS@ LIBFUSE_LITE_LIBS = @LIBFUSE_LITE_LIBS@ LIBGCRYPT_CFLAGS = @LIBGCRYPT_CFLAGS@ LIBGCRYPT_CONFIG = @LIBGCRYPT_CONFIG@ LIBGCRYPT_LIBS = @LIBGCRYPT_LIBS@ LIBNTFS_3G_VERSION = @LIBNTFS_3G_VERSION@ LIBNTFS_CPPFLAGS = @LIBNTFS_CPPFLAGS@ LIBNTFS_LIBS = @LIBNTFS_LIBS@ LIBOBJS = @LIBOBJS@ LIBS = @LIBS@ LIBTOOL = @LIBTOOL@ LIPO = @LIPO@ LN_S = @LN_S@ LTLIBOBJS = @LTLIBOBJS@ LT_SYS_LIBRARY_PATH = @LT_SYS_LIBRARY_PATH@ MAINT = @MAINT@ MAKEINFO = @MAKEINFO@ MANIFEST_TOOL = @MANIFEST_TOOL@ MKDIR_P = @MKDIR_P@ MKNTFS_CPPFLAGS = @MKNTFS_CPPFLAGS@ MKNTFS_LIBS = @MKNTFS_LIBS@ MV = @MV@ NM = @NM@ NMEDIT = @NMEDIT@ NTFSPROGS_STATIC_LIBS = @NTFSPROGS_STATIC_LIBS@ OBJDUMP = @OBJDUMP@ OBJEXT = @OBJEXT@ OTOOL = @OTOOL@ OTOOL64 = @OTOOL64@ OUTPUT_FORMAT = @OUTPUT_FORMAT@ PACKAGE = @PACKAGE@ PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ PACKAGE_NAME = @PACKAGE_NAME@ PACKAGE_STRING = @PACKAGE_STRING@ PACKAGE_TARNAME = @PACKAGE_TARNAME@ PACKAGE_URL = @PACKAGE_URL@ PACKAGE_VERSION = @PACKAGE_VERSION@ PATH_SEPARATOR = @PATH_SEPARATOR@ PKG_CONFIG = @PKG_CONFIG@ PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ RANLIB = @RANLIB@ RM = @RM@ SED = @SED@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ STRIP = @STRIP@ VERSION = @VERSION@ abs_builddir = @abs_builddir@ abs_srcdir = @abs_srcdir@ abs_top_builddir = @abs_top_builddir@ abs_top_srcdir = @abs_top_srcdir@ ac_ct_AR = @ac_ct_AR@ ac_ct_CC = @ac_ct_CC@ ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ all_includes = @all_includes@ all_libraries = @all_libraries@ am__include = @am__include@ am__leading_dot = @am__leading_dot@ am__quote = @am__quote@ am__rm_f_notfound = @am__rm_f_notfound@ am__tar = @am__tar@ am__untar = @am__untar@ am__xargs_n = @am__xargs_n@ bindir = @bindir@ build = @build@ build_alias = @build_alias@ build_cpu = @build_cpu@ build_os = @build_os@ build_vendor = @build_vendor@ builddir = @builddir@ datadir = @datadir@ datarootdir = @datarootdir@ docdir = @docdir@ dvidir = @dvidir@ exec_prefix = @exec_prefix@ host = @host@ host_alias = @host_alias@ host_cpu = @host_cpu@ host_os = @host_os@ host_vendor = @host_vendor@ htmldir = @htmldir@ includedir = @includedir@ infodir = @infodir@ install_sh = @install_sh@ libdir = @libdir@ libexecdir = @libexecdir@ localedir = @localedir@ localstatedir = @localstatedir@ mandir = @mandir@ mkdir_p = @mkdir_p@ ntfs3gincludedir = @ntfs3gincludedir@ oldincludedir = @oldincludedir@ pdfdir = @pdfdir@ pkgconfigdir = @pkgconfigdir@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ rootbindir = @rootbindir@ rootlibdir = @rootlibdir@ rootsbindir = @rootsbindir@ runstatedir = @runstatedir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ sysconfdir = @sysconfdir@ target = @target@ target_alias = @target_alias@ target_cpu = @target_cpu@ target_os = @target_os@ target_vendor = @target_vendor@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ EXTRA_DIST = ntfs-3g_common.h MAINTAINERCLEANFILES = $(srcdir)/Makefile.in @FUSE_INTERNAL_FALSE@FUSE_CFLAGS = $(FUSE_MODULE_CFLAGS) @FUSE_INTERNAL_TRUE@FUSE_CFLAGS = -I$(top_srcdir)/include/fuse-lite @FUSE_INTERNAL_FALSE@FUSE_LIBS = $(FUSE_MODULE_LIBS) @FUSE_INTERNAL_TRUE@FUSE_LIBS = $(top_builddir)/libfuse-lite/libfuse-lite.la @DISABLE_PLUGINS_FALSE@plugindir = $(libdir)/ntfs-3g @DISABLE_PLUGINS_FALSE@PLUGIN_CFLAGS = -DPLUGIN_DIR=\"$(plugindir)\" @ENABLE_NTFS_3G_TRUE@rootsbin_DATA = #Create directory @ENABLE_NTFS_3G_TRUE@man_MANS = ntfs-3g.8 ntfs-3g.probe.8 @ENABLE_NTFS_3G_TRUE@ntfs_3g_LDADD = $(LIBDL) $(FUSE_LIBS) $(top_builddir)/libntfs-3g/libntfs-3g.la @ENABLE_NTFS_3G_TRUE@@REALLYSTATIC_TRUE@ntfs_3g_LDFLAGS = $(AM_LDFLAGS) -all-static @ENABLE_NTFS_3G_TRUE@ntfs_3g_CFLAGS = \ @ENABLE_NTFS_3G_TRUE@ $(AM_CFLAGS) \ @ENABLE_NTFS_3G_TRUE@ -DFUSE_USE_VERSION=26 \ @ENABLE_NTFS_3G_TRUE@ $(FUSE_CFLAGS) \ @ENABLE_NTFS_3G_TRUE@ -I$(top_srcdir)/include/ntfs-3g \ @ENABLE_NTFS_3G_TRUE@ $(PLUGIN_CFLAGS) @ENABLE_NTFS_3G_TRUE@ntfs_3g_SOURCES = ntfs-3g.c ntfs-3g_common.c @ENABLE_NTFS_3G_TRUE@lowntfs_3g_LDADD = $(LIBDL) $(FUSE_LIBS) $(top_builddir)/libntfs-3g/libntfs-3g.la @ENABLE_NTFS_3G_TRUE@@REALLYSTATIC_TRUE@lowntfs_3g_LDFLAGS = $(AM_LDFLAGS) -all-static @ENABLE_NTFS_3G_TRUE@lowntfs_3g_CFLAGS = \ @ENABLE_NTFS_3G_TRUE@ $(AM_CFLAGS) \ @ENABLE_NTFS_3G_TRUE@ -DFUSE_USE_VERSION=26 \ @ENABLE_NTFS_3G_TRUE@ $(FUSE_CFLAGS) \ @ENABLE_NTFS_3G_TRUE@ -I$(top_srcdir)/include/ntfs-3g \ @ENABLE_NTFS_3G_TRUE@ $(PLUGIN_CFLAGS) @ENABLE_NTFS_3G_TRUE@lowntfs_3g_SOURCES = lowntfs-3g.c ntfs-3g_common.c @ENABLE_NTFS_3G_TRUE@ntfs_3g_probe_LDADD = $(top_builddir)/libntfs-3g/libntfs-3g.la @ENABLE_NTFS_3G_TRUE@@REALLYSTATIC_TRUE@ntfs_3g_probe_LDFLAGS = $(AM_LDFLAGS) -all-static @ENABLE_NTFS_3G_TRUE@ntfs_3g_probe_CFLAGS = $(AM_CFLAGS) -I$(top_srcdir)/include/ntfs-3g @ENABLE_NTFS_3G_TRUE@ntfs_3g_probe_SOURCES = ntfs-3g.probe.c all: all-am .SUFFIXES: .SUFFIXES: .c .lo .o .obj $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) @for dep in $?; do \ case '$(am__configure_deps)' in \ *$$dep*) \ ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ && { if test -f $@; then exit 0; else break; fi; }; \ exit 1;; \ esac; \ done; \ echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu src/Makefile'; \ $(am__cd) $(top_srcdir) && \ $(AUTOMAKE) --gnu src/Makefile Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status @case '$?' in \ *config.status*) \ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ *) \ echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles)'; \ cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles);; \ esac; $(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh $(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh $(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh $(am__aclocal_m4_deps): ntfs-3g.8: $(top_builddir)/config.status $(srcdir)/ntfs-3g.8.in cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ ntfs-3g.probe.8: $(top_builddir)/config.status $(srcdir)/ntfs-3g.probe.8.in cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ install-binPROGRAMS: $(bin_PROGRAMS) @$(NORMAL_INSTALL) @list='$(bin_PROGRAMS)'; test -n "$(bindir)" || list=; \ if test -n "$$list"; then \ echo " $(MKDIR_P) '$(DESTDIR)$(bindir)'"; \ $(MKDIR_P) "$(DESTDIR)$(bindir)" || exit 1; \ fi; \ for p in $$list; do echo "$$p $$p"; done | \ sed 's/$(EXEEXT)$$//' | \ while read p p1; do if test -f $$p \ || test -f $$p1 \ ; then echo "$$p"; echo "$$p"; else :; fi; \ done | \ sed -e 'p;s,.*/,,;n;h' \ -e 's|.*|.|' \ -e 'p;x;s,.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/' | \ sed 'N;N;N;s,\n, ,g' | \ $(AWK) 'BEGIN { files["."] = ""; dirs["."] = 1 } \ { d=$$3; if (dirs[d] != 1) { print "d", d; dirs[d] = 1 } \ if ($$2 == $$4) files[d] = files[d] " " $$1; \ else { print "f", $$3 "/" $$4, $$1; } } \ END { for (d in files) print "f", d, files[d] }' | \ while read type dir files; do \ if test "$$dir" = .; then dir=; else dir=/$$dir; fi; \ test -z "$$files" || { \ echo " $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files '$(DESTDIR)$(bindir)$$dir'"; \ $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files "$(DESTDIR)$(bindir)$$dir" || exit $$?; \ } \ ; done uninstall-binPROGRAMS: @$(NORMAL_UNINSTALL) @list='$(bin_PROGRAMS)'; test -n "$(bindir)" || list=; \ files=`for p in $$list; do echo "$$p"; done | \ sed -e 'h;s,^.*/,,;s/$(EXEEXT)$$//;$(transform)' \ -e 's/$$/$(EXEEXT)/' \ `; \ test -n "$$list" || exit 0; \ echo " ( cd '$(DESTDIR)$(bindir)' && rm -f" $$files ")"; \ cd "$(DESTDIR)$(bindir)" && $(am__rm_f) $$files clean-binPROGRAMS: $(am__rm_f) $(bin_PROGRAMS) test -z "$(EXEEXT)" || $(am__rm_f) $(bin_PROGRAMS:$(EXEEXT)=) install-rootbinPROGRAMS: $(rootbin_PROGRAMS) @$(NORMAL_INSTALL) @list='$(rootbin_PROGRAMS)'; test -n "$(rootbindir)" || list=; \ if test -n "$$list"; then \ echo " $(MKDIR_P) '$(DESTDIR)$(rootbindir)'"; \ $(MKDIR_P) "$(DESTDIR)$(rootbindir)" || exit 1; \ fi; \ for p in $$list; do echo "$$p $$p"; done | \ sed 's/$(EXEEXT)$$//' | \ while read p p1; do if test -f $$p \ || test -f $$p1 \ ; then echo "$$p"; echo "$$p"; else :; fi; \ done | \ sed -e 'p;s,.*/,,;n;h' \ -e 's|.*|.|' \ -e 'p;x;s,.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/' | \ sed 'N;N;N;s,\n, ,g' | \ $(AWK) 'BEGIN { files["."] = ""; dirs["."] = 1 } \ { d=$$3; if (dirs[d] != 1) { print "d", d; dirs[d] = 1 } \ if ($$2 == $$4) files[d] = files[d] " " $$1; \ else { print "f", $$3 "/" $$4, $$1; } } \ END { for (d in files) print "f", d, files[d] }' | \ while read type dir files; do \ if test "$$dir" = .; then dir=; else dir=/$$dir; fi; \ test -z "$$files" || { \ echo " $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files '$(DESTDIR)$(rootbindir)$$dir'"; \ $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files "$(DESTDIR)$(rootbindir)$$dir" || exit $$?; \ } \ ; done uninstall-rootbinPROGRAMS: @$(NORMAL_UNINSTALL) @list='$(rootbin_PROGRAMS)'; test -n "$(rootbindir)" || list=; \ files=`for p in $$list; do echo "$$p"; done | \ sed -e 'h;s,^.*/,,;s/$(EXEEXT)$$//;$(transform)' \ -e 's/$$/$(EXEEXT)/' \ `; \ test -n "$$list" || exit 0; \ echo " ( cd '$(DESTDIR)$(rootbindir)' && rm -f" $$files ")"; \ cd "$(DESTDIR)$(rootbindir)" && $(am__rm_f) $$files clean-rootbinPROGRAMS: $(am__rm_f) $(rootbin_PROGRAMS) test -z "$(EXEEXT)" || $(am__rm_f) $(rootbin_PROGRAMS:$(EXEEXT)=) lowntfs-3g$(EXEEXT): $(lowntfs_3g_OBJECTS) $(lowntfs_3g_DEPENDENCIES) $(EXTRA_lowntfs_3g_DEPENDENCIES) @rm -f lowntfs-3g$(EXEEXT) $(AM_V_CCLD)$(lowntfs_3g_LINK) $(lowntfs_3g_OBJECTS) $(lowntfs_3g_LDADD) $(LIBS) ntfs-3g$(EXEEXT): $(ntfs_3g_OBJECTS) $(ntfs_3g_DEPENDENCIES) $(EXTRA_ntfs_3g_DEPENDENCIES) @rm -f ntfs-3g$(EXEEXT) $(AM_V_CCLD)$(ntfs_3g_LINK) $(ntfs_3g_OBJECTS) $(ntfs_3g_LDADD) $(LIBS) ntfs-3g.probe$(EXEEXT): $(ntfs_3g_probe_OBJECTS) $(ntfs_3g_probe_DEPENDENCIES) $(EXTRA_ntfs_3g_probe_DEPENDENCIES) @rm -f ntfs-3g.probe$(EXEEXT) $(AM_V_CCLD)$(ntfs_3g_probe_LINK) $(ntfs_3g_probe_OBJECTS) $(ntfs_3g_probe_LDADD) $(LIBS) mostlyclean-compile: -rm -f *.$(OBJEXT) distclean-compile: -rm -f *.tab.c @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lowntfs_3g-lowntfs-3g.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lowntfs_3g-ntfs-3g_common.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ntfs_3g-ntfs-3g.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ntfs_3g-ntfs-3g_common.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ntfs_3g_probe-ntfs-3g.probe.Po@am__quote@ # am--include-marker $(am__depfiles_remade): @$(MKDIR_P) $(@D) @: >>$@ am--depfiles: $(am__depfiles_remade) .c.o: @am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ $< .c.obj: @am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'` .c.lo: @am__fastdepCC_TRUE@ $(AM_V_CC)$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $< lowntfs_3g-lowntfs-3g.o: lowntfs-3g.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lowntfs_3g_CFLAGS) $(CFLAGS) -MT lowntfs_3g-lowntfs-3g.o -MD -MP -MF $(DEPDIR)/lowntfs_3g-lowntfs-3g.Tpo -c -o lowntfs_3g-lowntfs-3g.o `test -f 'lowntfs-3g.c' || echo '$(srcdir)/'`lowntfs-3g.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/lowntfs_3g-lowntfs-3g.Tpo $(DEPDIR)/lowntfs_3g-lowntfs-3g.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='lowntfs-3g.c' object='lowntfs_3g-lowntfs-3g.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lowntfs_3g_CFLAGS) $(CFLAGS) -c -o lowntfs_3g-lowntfs-3g.o `test -f 'lowntfs-3g.c' || echo '$(srcdir)/'`lowntfs-3g.c lowntfs_3g-lowntfs-3g.obj: lowntfs-3g.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lowntfs_3g_CFLAGS) $(CFLAGS) -MT lowntfs_3g-lowntfs-3g.obj -MD -MP -MF $(DEPDIR)/lowntfs_3g-lowntfs-3g.Tpo -c -o lowntfs_3g-lowntfs-3g.obj `if test -f 'lowntfs-3g.c'; then $(CYGPATH_W) 'lowntfs-3g.c'; else $(CYGPATH_W) '$(srcdir)/lowntfs-3g.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/lowntfs_3g-lowntfs-3g.Tpo $(DEPDIR)/lowntfs_3g-lowntfs-3g.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='lowntfs-3g.c' object='lowntfs_3g-lowntfs-3g.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lowntfs_3g_CFLAGS) $(CFLAGS) -c -o lowntfs_3g-lowntfs-3g.obj `if test -f 'lowntfs-3g.c'; then $(CYGPATH_W) 'lowntfs-3g.c'; else $(CYGPATH_W) '$(srcdir)/lowntfs-3g.c'; fi` lowntfs_3g-ntfs-3g_common.o: ntfs-3g_common.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lowntfs_3g_CFLAGS) $(CFLAGS) -MT lowntfs_3g-ntfs-3g_common.o -MD -MP -MF $(DEPDIR)/lowntfs_3g-ntfs-3g_common.Tpo -c -o lowntfs_3g-ntfs-3g_common.o `test -f 'ntfs-3g_common.c' || echo '$(srcdir)/'`ntfs-3g_common.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/lowntfs_3g-ntfs-3g_common.Tpo $(DEPDIR)/lowntfs_3g-ntfs-3g_common.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='ntfs-3g_common.c' object='lowntfs_3g-ntfs-3g_common.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lowntfs_3g_CFLAGS) $(CFLAGS) -c -o lowntfs_3g-ntfs-3g_common.o `test -f 'ntfs-3g_common.c' || echo '$(srcdir)/'`ntfs-3g_common.c lowntfs_3g-ntfs-3g_common.obj: ntfs-3g_common.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lowntfs_3g_CFLAGS) $(CFLAGS) -MT lowntfs_3g-ntfs-3g_common.obj -MD -MP -MF $(DEPDIR)/lowntfs_3g-ntfs-3g_common.Tpo -c -o lowntfs_3g-ntfs-3g_common.obj `if test -f 'ntfs-3g_common.c'; then $(CYGPATH_W) 'ntfs-3g_common.c'; else $(CYGPATH_W) '$(srcdir)/ntfs-3g_common.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/lowntfs_3g-ntfs-3g_common.Tpo $(DEPDIR)/lowntfs_3g-ntfs-3g_common.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='ntfs-3g_common.c' object='lowntfs_3g-ntfs-3g_common.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lowntfs_3g_CFLAGS) $(CFLAGS) -c -o lowntfs_3g-ntfs-3g_common.obj `if test -f 'ntfs-3g_common.c'; then $(CYGPATH_W) 'ntfs-3g_common.c'; else $(CYGPATH_W) '$(srcdir)/ntfs-3g_common.c'; fi` ntfs_3g-ntfs-3g.o: ntfs-3g.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(ntfs_3g_CFLAGS) $(CFLAGS) -MT ntfs_3g-ntfs-3g.o -MD -MP -MF $(DEPDIR)/ntfs_3g-ntfs-3g.Tpo -c -o ntfs_3g-ntfs-3g.o `test -f 'ntfs-3g.c' || echo '$(srcdir)/'`ntfs-3g.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/ntfs_3g-ntfs-3g.Tpo $(DEPDIR)/ntfs_3g-ntfs-3g.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='ntfs-3g.c' object='ntfs_3g-ntfs-3g.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(ntfs_3g_CFLAGS) $(CFLAGS) -c -o ntfs_3g-ntfs-3g.o `test -f 'ntfs-3g.c' || echo '$(srcdir)/'`ntfs-3g.c ntfs_3g-ntfs-3g.obj: ntfs-3g.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(ntfs_3g_CFLAGS) $(CFLAGS) -MT ntfs_3g-ntfs-3g.obj -MD -MP -MF $(DEPDIR)/ntfs_3g-ntfs-3g.Tpo -c -o ntfs_3g-ntfs-3g.obj `if test -f 'ntfs-3g.c'; then $(CYGPATH_W) 'ntfs-3g.c'; else $(CYGPATH_W) '$(srcdir)/ntfs-3g.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/ntfs_3g-ntfs-3g.Tpo $(DEPDIR)/ntfs_3g-ntfs-3g.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='ntfs-3g.c' object='ntfs_3g-ntfs-3g.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(ntfs_3g_CFLAGS) $(CFLAGS) -c -o ntfs_3g-ntfs-3g.obj `if test -f 'ntfs-3g.c'; then $(CYGPATH_W) 'ntfs-3g.c'; else $(CYGPATH_W) '$(srcdir)/ntfs-3g.c'; fi` ntfs_3g-ntfs-3g_common.o: ntfs-3g_common.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(ntfs_3g_CFLAGS) $(CFLAGS) -MT ntfs_3g-ntfs-3g_common.o -MD -MP -MF $(DEPDIR)/ntfs_3g-ntfs-3g_common.Tpo -c -o ntfs_3g-ntfs-3g_common.o `test -f 'ntfs-3g_common.c' || echo '$(srcdir)/'`ntfs-3g_common.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/ntfs_3g-ntfs-3g_common.Tpo $(DEPDIR)/ntfs_3g-ntfs-3g_common.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='ntfs-3g_common.c' object='ntfs_3g-ntfs-3g_common.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(ntfs_3g_CFLAGS) $(CFLAGS) -c -o ntfs_3g-ntfs-3g_common.o `test -f 'ntfs-3g_common.c' || echo '$(srcdir)/'`ntfs-3g_common.c ntfs_3g-ntfs-3g_common.obj: ntfs-3g_common.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(ntfs_3g_CFLAGS) $(CFLAGS) -MT ntfs_3g-ntfs-3g_common.obj -MD -MP -MF $(DEPDIR)/ntfs_3g-ntfs-3g_common.Tpo -c -o ntfs_3g-ntfs-3g_common.obj `if test -f 'ntfs-3g_common.c'; then $(CYGPATH_W) 'ntfs-3g_common.c'; else $(CYGPATH_W) '$(srcdir)/ntfs-3g_common.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/ntfs_3g-ntfs-3g_common.Tpo $(DEPDIR)/ntfs_3g-ntfs-3g_common.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='ntfs-3g_common.c' object='ntfs_3g-ntfs-3g_common.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(ntfs_3g_CFLAGS) $(CFLAGS) -c -o ntfs_3g-ntfs-3g_common.obj `if test -f 'ntfs-3g_common.c'; then $(CYGPATH_W) 'ntfs-3g_common.c'; else $(CYGPATH_W) '$(srcdir)/ntfs-3g_common.c'; fi` ntfs_3g_probe-ntfs-3g.probe.o: ntfs-3g.probe.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(ntfs_3g_probe_CFLAGS) $(CFLAGS) -MT ntfs_3g_probe-ntfs-3g.probe.o -MD -MP -MF $(DEPDIR)/ntfs_3g_probe-ntfs-3g.probe.Tpo -c -o ntfs_3g_probe-ntfs-3g.probe.o `test -f 'ntfs-3g.probe.c' || echo '$(srcdir)/'`ntfs-3g.probe.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/ntfs_3g_probe-ntfs-3g.probe.Tpo $(DEPDIR)/ntfs_3g_probe-ntfs-3g.probe.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='ntfs-3g.probe.c' object='ntfs_3g_probe-ntfs-3g.probe.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(ntfs_3g_probe_CFLAGS) $(CFLAGS) -c -o ntfs_3g_probe-ntfs-3g.probe.o `test -f 'ntfs-3g.probe.c' || echo '$(srcdir)/'`ntfs-3g.probe.c ntfs_3g_probe-ntfs-3g.probe.obj: ntfs-3g.probe.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(ntfs_3g_probe_CFLAGS) $(CFLAGS) -MT ntfs_3g_probe-ntfs-3g.probe.obj -MD -MP -MF $(DEPDIR)/ntfs_3g_probe-ntfs-3g.probe.Tpo -c -o ntfs_3g_probe-ntfs-3g.probe.obj `if test -f 'ntfs-3g.probe.c'; then $(CYGPATH_W) 'ntfs-3g.probe.c'; else $(CYGPATH_W) '$(srcdir)/ntfs-3g.probe.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/ntfs_3g_probe-ntfs-3g.probe.Tpo $(DEPDIR)/ntfs_3g_probe-ntfs-3g.probe.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='ntfs-3g.probe.c' object='ntfs_3g_probe-ntfs-3g.probe.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(ntfs_3g_probe_CFLAGS) $(CFLAGS) -c -o ntfs_3g_probe-ntfs-3g.probe.obj `if test -f 'ntfs-3g.probe.c'; then $(CYGPATH_W) 'ntfs-3g.probe.c'; else $(CYGPATH_W) '$(srcdir)/ntfs-3g.probe.c'; fi` mostlyclean-libtool: -rm -f *.lo clean-libtool: -rm -rf .libs _libs install-man8: $(man_MANS) @$(NORMAL_INSTALL) @list1=''; \ list2='$(man_MANS)'; \ test -n "$(man8dir)" \ && test -n "`echo $$list1$$list2`" \ || exit 0; \ echo " $(MKDIR_P) '$(DESTDIR)$(man8dir)'"; \ $(MKDIR_P) "$(DESTDIR)$(man8dir)" || exit 1; \ { for i in $$list1; do echo "$$i"; done; \ if test -n "$$list2"; then \ for i in $$list2; do echo "$$i"; done \ | sed -n '/\.8[a-z]*$$/p'; \ fi; \ } | while read p; do \ if test -f $$p; then d=; else d="$(srcdir)/"; fi; \ echo "$$d$$p"; echo "$$p"; \ done | \ sed -e 'n;s,.*/,,;p;h;s,.*\.,,;s,^[^8][0-9a-z]*$$,8,;x' \ -e 's,\.[0-9a-z]*$$,,;$(transform);G;s,\n,.,' | \ sed 'N;N;s,\n, ,g' | { \ list=; while read file base inst; do \ if test "$$base" = "$$inst"; then list="$$list $$file"; else \ echo " $(INSTALL_DATA) '$$file' '$(DESTDIR)$(man8dir)/$$inst'"; \ $(INSTALL_DATA) "$$file" "$(DESTDIR)$(man8dir)/$$inst" || exit $$?; \ fi; \ done; \ for i in $$list; do echo "$$i"; done | $(am__base_list) | \ while read files; do \ test -z "$$files" || { \ echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(man8dir)'"; \ $(INSTALL_DATA) $$files "$(DESTDIR)$(man8dir)" || exit $$?; }; \ done; } uninstall-man8: @$(NORMAL_UNINSTALL) @list=''; test -n "$(man8dir)" || exit 0; \ files=`{ for i in $$list; do echo "$$i"; done; \ l2='$(man_MANS)'; for i in $$l2; do echo "$$i"; done | \ sed -n '/\.8[a-z]*$$/p'; \ } | sed -e 's,.*/,,;h;s,.*\.,,;s,^[^8][0-9a-z]*$$,8,;x' \ -e 's,\.[0-9a-z]*$$,,;$(transform);G;s,\n,.,'`; \ dir='$(DESTDIR)$(man8dir)'; $(am__uninstall_files_from_dir) install-rootsbinDATA: $(rootsbin_DATA) @$(NORMAL_INSTALL) @list='$(rootsbin_DATA)'; test -n "$(rootsbindir)" || list=; \ if test -n "$$list"; then \ echo " $(MKDIR_P) '$(DESTDIR)$(rootsbindir)'"; \ $(MKDIR_P) "$(DESTDIR)$(rootsbindir)" || exit 1; \ fi; \ for p in $$list; do \ if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ echo "$$d$$p"; \ done | $(am__base_list) | \ while read files; do \ echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(rootsbindir)'"; \ $(INSTALL_DATA) $$files "$(DESTDIR)$(rootsbindir)" || exit $$?; \ done uninstall-rootsbinDATA: @$(NORMAL_UNINSTALL) @list='$(rootsbin_DATA)'; test -n "$(rootsbindir)" || list=; \ files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \ dir='$(DESTDIR)$(rootsbindir)'; $(am__uninstall_files_from_dir) ID: $(am__tagged_files) $(am__define_uniq_tagged_files); mkid -fID $$unique tags: tags-am TAGS: tags tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) set x; \ here=`pwd`; \ $(am__define_uniq_tagged_files); \ shift; \ if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ test -n "$$unique" || unique=$$empty_fix; \ if test $$# -gt 0; then \ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ "$$@" $$unique; \ else \ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ $$unique; \ fi; \ fi ctags: ctags-am CTAGS: ctags ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) $(am__define_uniq_tagged_files); \ test -z "$(CTAGS_ARGS)$$unique" \ || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ $$unique GTAGS: here=`$(am__cd) $(top_builddir) && pwd` \ && $(am__cd) $(top_srcdir) \ && gtags -i $(GTAGS_ARGS) "$$here" cscopelist: cscopelist-am cscopelist-am: $(am__tagged_files) list='$(am__tagged_files)'; \ case "$(srcdir)" in \ [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \ *) sdir=$(subdir)/$(srcdir) ;; \ esac; \ for i in $$list; do \ if test -f "$$i"; then \ echo "$(subdir)/$$i"; \ else \ echo "$$sdir/$$i"; \ fi; \ done >> $(top_builddir)/cscope.files distclean-tags: -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags distdir: $(BUILT_SOURCES) $(MAKE) $(AM_MAKEFLAGS) distdir-am distdir-am: $(DISTFILES) @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ list='$(DISTFILES)'; \ dist_files=`for file in $$list; do echo $$file; done | \ sed -e "s|^$$srcdirstrip/||;t" \ -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ case $$dist_files in \ */*) $(MKDIR_P) `echo "$$dist_files" | \ sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ sort -u` ;; \ esac; \ for file in $$dist_files; do \ if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ if test -d $$d/$$file; then \ dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ if test -d "$(distdir)/$$file"; then \ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ fi; \ if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ fi; \ cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ else \ test -f "$(distdir)/$$file" \ || cp -p $$d/$$file "$(distdir)/$$file" \ || exit 1; \ fi; \ done check-am: all-am check: check-am all-am: Makefile $(PROGRAMS) $(MANS) $(DATA) installdirs: for dir in "$(DESTDIR)$(bindir)" "$(DESTDIR)$(rootbindir)" "$(DESTDIR)$(man8dir)" "$(DESTDIR)$(rootsbindir)"; do \ test -z "$$dir" || $(MKDIR_P) "$$dir"; \ done install: install-am install-exec: install-exec-am install-data: install-data-am uninstall: uninstall-am install-am: all-am @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am installcheck: installcheck-am install-strip: if test -z '$(STRIP)'; then \ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ install; \ else \ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ fi mostlyclean-generic: clean-generic: distclean-generic: -$(am__rm_f) $(CONFIG_CLEAN_FILES) -test . = "$(srcdir)" || $(am__rm_f) $(CONFIG_CLEAN_VPATH_FILES) maintainer-clean-generic: @echo "This command is intended for maintainers to use" @echo "it deletes files that may require special tools to rebuild." -$(am__rm_f) $(MAINTAINERCLEANFILES) @ENABLE_MOUNT_HELPER_FALSE@install-data-local: @ENABLE_NTFS_3G_FALSE@install-data-local: @ENABLE_MOUNT_HELPER_FALSE@install-exec-local: @ENABLE_NTFS_3G_FALSE@install-exec-local: @ENABLE_MOUNT_HELPER_FALSE@uninstall-local: @ENABLE_NTFS_3G_FALSE@uninstall-local: @ENABLE_NTFS_3G_FALSE@install-exec-hook: clean: clean-am clean-am: clean-binPROGRAMS clean-generic clean-libtool \ clean-rootbinPROGRAMS mostlyclean-am distclean: distclean-am -rm -f ./$(DEPDIR)/lowntfs_3g-lowntfs-3g.Po -rm -f ./$(DEPDIR)/lowntfs_3g-ntfs-3g_common.Po -rm -f ./$(DEPDIR)/ntfs_3g-ntfs-3g.Po -rm -f ./$(DEPDIR)/ntfs_3g-ntfs-3g_common.Po -rm -f ./$(DEPDIR)/ntfs_3g_probe-ntfs-3g.probe.Po -rm -f Makefile distclean-am: clean-am distclean-compile distclean-generic \ distclean-tags dvi: dvi-am dvi-am: html: html-am html-am: info: info-am info-am: install-data-am: install-data-local install-man \ install-rootbinPROGRAMS install-rootsbinDATA install-dvi: install-dvi-am install-dvi-am: install-exec-am: install-binPROGRAMS install-exec-local @$(NORMAL_INSTALL) $(MAKE) $(AM_MAKEFLAGS) install-exec-hook install-html: install-html-am install-html-am: install-info: install-info-am install-info-am: install-man: install-man8 install-pdf: install-pdf-am install-pdf-am: install-ps: install-ps-am install-ps-am: installcheck-am: maintainer-clean: maintainer-clean-am -rm -f ./$(DEPDIR)/lowntfs_3g-lowntfs-3g.Po -rm -f ./$(DEPDIR)/lowntfs_3g-ntfs-3g_common.Po -rm -f ./$(DEPDIR)/ntfs_3g-ntfs-3g.Po -rm -f ./$(DEPDIR)/ntfs_3g-ntfs-3g_common.Po -rm -f ./$(DEPDIR)/ntfs_3g_probe-ntfs-3g.probe.Po -rm -f Makefile maintainer-clean-am: distclean-am maintainer-clean-generic mostlyclean: mostlyclean-am mostlyclean-am: mostlyclean-compile mostlyclean-generic \ mostlyclean-libtool pdf: pdf-am pdf-am: ps: ps-am ps-am: uninstall-am: uninstall-binPROGRAMS uninstall-local uninstall-man \ uninstall-rootbinPROGRAMS uninstall-rootsbinDATA uninstall-man: uninstall-man8 .MAKE: install-am install-exec-am install-strip .PHONY: CTAGS GTAGS TAGS all all-am am--depfiles check check-am clean \ clean-binPROGRAMS clean-generic clean-libtool \ clean-rootbinPROGRAMS cscopelist-am ctags ctags-am distclean \ distclean-compile distclean-generic distclean-libtool \ distclean-tags distdir dvi dvi-am html html-am info info-am \ install install-am install-binPROGRAMS install-data \ install-data-am install-data-local install-dvi install-dvi-am \ install-exec install-exec-am install-exec-hook \ install-exec-local install-html install-html-am install-info \ install-info-am install-man install-man8 install-pdf \ install-pdf-am install-ps install-ps-am \ install-rootbinPROGRAMS install-rootsbinDATA install-strip \ installcheck installcheck-am installdirs maintainer-clean \ maintainer-clean-generic mostlyclean mostlyclean-compile \ mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ tags tags-am uninstall uninstall-am uninstall-binPROGRAMS \ uninstall-local uninstall-man uninstall-man8 \ uninstall-rootbinPROGRAMS uninstall-rootsbinDATA .PRECIOUS: Makefile @ENABLE_NTFS_3G_TRUE@drivers : $(FUSE_LIBS) ntfs-3g lowntfs-3g @ENABLE_NTFS_3G_TRUE@install-exec-hook: @ENABLE_NTFS_3G_TRUE@@RUN_LDCONFIG_TRUE@ $(LDCONFIG) @DISABLE_PLUGINS_FALSE@@ENABLE_NTFS_3G_TRUE@ $(MKDIR_P) $(DESTDIR)/$(plugindir) @ENABLE_MOUNT_HELPER_TRUE@@ENABLE_NTFS_3G_TRUE@install-exec-local: install-rootbinPROGRAMS @ENABLE_MOUNT_HELPER_TRUE@@ENABLE_NTFS_3G_TRUE@ $(MKDIR_P) "$(DESTDIR)/sbin" @ENABLE_MOUNT_HELPER_TRUE@@ENABLE_NTFS_3G_TRUE@ $(LN_S) -f "$(rootbindir)/ntfs-3g" "$(DESTDIR)/sbin/mount.ntfs-3g" @ENABLE_MOUNT_HELPER_TRUE@@ENABLE_NTFS_3G_TRUE@ $(LN_S) -f "$(rootbindir)/lowntfs-3g" "$(DESTDIR)/sbin/mount.lowntfs-3g" @ENABLE_MOUNT_HELPER_TRUE@@ENABLE_NTFS_3G_TRUE@install-data-local: install-man8 @ENABLE_MOUNT_HELPER_TRUE@@ENABLE_NTFS_3G_TRUE@ $(LN_S) -f ntfs-3g.8 "$(DESTDIR)$(man8dir)/mount.ntfs-3g.8" @ENABLE_MOUNT_HELPER_TRUE@@ENABLE_NTFS_3G_TRUE@ $(LN_S) -f ntfs-3g.8 "$(DESTDIR)$(man8dir)/mount.lowntfs-3g.8" @ENABLE_MOUNT_HELPER_TRUE@@ENABLE_NTFS_3G_TRUE@uninstall-local: @ENABLE_MOUNT_HELPER_TRUE@@ENABLE_NTFS_3G_TRUE@ $(RM) -f "$(DESTDIR)$(man8dir)/mount.ntfs-3g.8" @ENABLE_MOUNT_HELPER_TRUE@@ENABLE_NTFS_3G_TRUE@ $(RM) -f "$(DESTDIR)/sbin/mount.ntfs-3g" "$(DESTDIR)/sbin/mount.lowntfs-3g" # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. .NOEXPORT: # Tell GNU make to disable its built-in pattern rules. %:: %,v %:: RCS/%,v %:: RCS/% %:: s.% %:: SCCS/s.% ntfs-3g-2026.2.25/src/ntfs-3g.probe.c0000664000175000017500000000706515152260174012333 /** * ntfs-3g.probe - Probe NTFS volume mountability * * Copyright (c) 2007-2009 Szabolcs Szakacsits * * 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 */ #include "config.h" #ifdef HAVE_STDLIB_H #include #endif #ifdef HAVE_STRING_H #include #endif #ifdef HAVE_ERRNO_H #include #endif #include #include "compat.h" #include "volume.h" #include "misc.h" typedef enum { PROBE_UNSET, PROBE_READONLY, PROBE_READWRITE } probe_t; static struct options { probe_t probetype; char *device; } opts; static const char *EXEC_NAME = "ntfs-3g.probe"; static const char *usage_msg = "\n" "%s %s - Probe NTFS volume mountability\n" "\n" "Copyright (C) 2007 Szabolcs Szakacsits\n" "\n" "Usage: %s <--readonly|--readwrite> \n" "\n" "Example: ntfs-3g.probe --readwrite /dev/sda1\n" "\n" "%s"; static int ntfs_open(const char *device) { ntfs_volume *vol; unsigned long flags = 0; int ret = NTFS_VOLUME_OK; if (opts.probetype == PROBE_READONLY) flags |= NTFS_MNT_RDONLY; vol = ntfs_mount(device, flags); if (!vol) ret = ntfs_volume_error(errno); if (ret == 0 && ntfs_umount(vol, FALSE) == -1) ret = ntfs_volume_error(errno); return ret; } static void usage(void) { ntfs_log_info(usage_msg, EXEC_NAME, VERSION, EXEC_NAME, ntfs_home); } static int parse_options(int argc, char *argv[]) { int c; static const char *sopt = "-hrw"; static const struct option lopt[] = { { "readonly", no_argument, NULL, 'r' }, { "readwrite", no_argument, NULL, 'w' }, { "help", no_argument, NULL, 'h' }, { NULL, 0, NULL, 0 } }; opterr = 0; /* We handle errors. */ opts.probetype = PROBE_UNSET; while ((c = getopt_long(argc, argv, sopt, lopt, NULL)) != -1) { switch (c) { case 1: /* A non-option argument */ if (!opts.device) { opts.device = ntfs_malloc(PATH_MAX + 1); if (!opts.device) return -1; strncpy(opts.device, optarg, PATH_MAX); opts.device[PATH_MAX] = 0; } else { ntfs_log_error("%s: You must specify exactly " "one device\n", EXEC_NAME); return -1; } break; case 'h': usage(); exit(0); case 'r': opts.probetype = PROBE_READONLY; break; case 'w': opts.probetype = PROBE_READWRITE; break; default: ntfs_log_error("%s: Unknown option '%s'.\n", EXEC_NAME, argv[optind - 1]); return -1; } } if (!opts.device) { ntfs_log_error("ERROR: %s: Device is missing\n", EXEC_NAME); return -1; } if (opts.probetype == PROBE_UNSET) { ntfs_log_error("ERROR: %s: Probe type is missing\n", EXEC_NAME); return -1; } return 0; } int main(int argc, char *argv[]) { int err; ntfs_log_set_handler(ntfs_log_handler_stderr); if (parse_options(argc, argv)) { usage(); exit(NTFS_VOLUME_SYNTAX_ERROR); } err = ntfs_open(opts.device); free(opts.device); if (err) exit(err); return (0); } ntfs-3g-2026.2.25/src/ntfs-3g_common.c0000664000175000017500000006307215152260174012575 /** * ntfs-3g_common.c - Common definitions for ntfs-3g and lowntfs-3g. * * Copyright (c) 2010-2021 Jean-Pierre Andre * Copyright (c) 2010 Erik Larsson * * This program/include file 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/include file 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_STDLIB_H #include #endif #ifdef HAVE_DLFCN_H #include #endif #ifdef HAVE_STRING_H #include #endif #ifdef HAVE_LIMITS_H #include #endif #ifdef HAVE_ERRNO_H #include #endif #include #include #include "compat.h" #include "inode.h" #include "dir.h" #include "security.h" #include "xattrs.h" #include "reparse.h" #include "plugin.h" #include "ntfs-3g_common.h" #include "realpath.h" #include "misc.h" const char xattr_ntfs_3g[] = "ntfs-3g."; const char nf_ns_user_prefix[] = "user."; const int nf_ns_user_prefix_len = sizeof(nf_ns_user_prefix) - 1; const char nf_ns_system_prefix[] = "system."; const int nf_ns_system_prefix_len = sizeof(nf_ns_system_prefix) - 1; const char nf_ns_security_prefix[] = "security."; const int nf_ns_security_prefix_len = sizeof(nf_ns_security_prefix) - 1; const char nf_ns_trusted_prefix[] = "trusted."; const int nf_ns_trusted_prefix_len = sizeof(nf_ns_trusted_prefix) - 1; static const char nf_ns_alt_xattr_efsinfo[] = "user.ntfs.efsinfo"; static const char def_opts[] = "allow_other,nonempty,"; /* * Table of recognized options * Their order may be significant * The options invalid in some configuration should still * be present, so that an error can be returned */ const struct DEFOPTION optionlist[] = { { "ro", OPT_RO, FLGOPT_APPEND | FLGOPT_BOGUS }, { "noatime", OPT_NOATIME, FLGOPT_BOGUS }, { "atime", OPT_ATIME, FLGOPT_BOGUS }, { "relatime", OPT_RELATIME, FLGOPT_BOGUS }, { "delay_mtime", OPT_DMTIME, FLGOPT_DECIMAL | FLGOPT_OPTIONAL }, { "rw", OPT_RW, FLGOPT_BOGUS }, { "fake_rw", OPT_FAKE_RW, FLGOPT_BOGUS }, { "fsname", OPT_FSNAME, FLGOPT_NOSUPPORT }, { "no_def_opts", OPT_NO_DEF_OPTS, FLGOPT_BOGUS }, { "default_permissions", OPT_DEFAULT_PERMISSIONS, FLGOPT_BOGUS }, { "permissions", OPT_PERMISSIONS, FLGOPT_BOGUS }, { "acl", OPT_ACL, FLGOPT_BOGUS }, { "umask", OPT_UMASK, FLGOPT_OCTAL }, { "fmask", OPT_FMASK, FLGOPT_OCTAL }, { "dmask", OPT_DMASK, FLGOPT_OCTAL }, { "uid", OPT_UID, FLGOPT_DECIMAL }, { "gid", OPT_GID, FLGOPT_DECIMAL }, { "show_sys_files", OPT_SHOW_SYS_FILES, FLGOPT_BOGUS }, { "hide_hid_files", OPT_HIDE_HID_FILES, FLGOPT_BOGUS }, { "hide_dot_files", OPT_HIDE_DOT_FILES, FLGOPT_BOGUS }, { "ignore_case", OPT_IGNORE_CASE, FLGOPT_BOGUS }, { "windows_names", OPT_WINDOWS_NAMES, FLGOPT_BOGUS }, { "compression", OPT_COMPRESSION, FLGOPT_BOGUS }, { "nocompression", OPT_NOCOMPRESSION, FLGOPT_BOGUS }, { "silent", OPT_SILENT, FLGOPT_BOGUS }, { "recover", OPT_RECOVER, FLGOPT_BOGUS }, { "norecover", OPT_NORECOVER, FLGOPT_BOGUS }, { "remove_hiberfile", OPT_REMOVE_HIBERFILE, FLGOPT_BOGUS }, { "sync", OPT_SYNC, FLGOPT_BOGUS | FLGOPT_APPEND }, { "big_writes", OPT_BIG_WRITES, FLGOPT_BOGUS }, { "locale", OPT_LOCALE, FLGOPT_STRING }, { "nfconv", OPT_NFCONV, FLGOPT_BOGUS }, { "nonfconv", OPT_NONFCONV, FLGOPT_BOGUS }, { "streams_interface", OPT_STREAMS_INTERFACE, FLGOPT_STRING }, { "user_xattr", OPT_USER_XATTR, FLGOPT_BOGUS }, { "noauto", OPT_NOAUTO, FLGOPT_BOGUS }, { "debug", OPT_DEBUG, FLGOPT_BOGUS }, { "no_detach", OPT_NO_DETACH, FLGOPT_BOGUS }, { "remount", OPT_REMOUNT, FLGOPT_BOGUS }, { "blksize", OPT_BLKSIZE, FLGOPT_STRING }, { "inherit", OPT_INHERIT, FLGOPT_BOGUS }, { "addsecurids", OPT_ADDSECURIDS, FLGOPT_BOGUS }, { "staticgrps", OPT_STATICGRPS, FLGOPT_BOGUS }, { "usermapping", OPT_USERMAPPING, FLGOPT_STRING }, { "xattrmapping", OPT_XATTRMAPPING, FLGOPT_STRING }, { "efs_raw", OPT_EFS_RAW, FLGOPT_BOGUS }, { "posix_nlink", OPT_POSIX_NLINK, FLGOPT_BOGUS }, { "special_files", OPT_SPECIAL_FILES, FLGOPT_STRING }, { "--help", OPT_HELP, FLGOPT_BOGUS }, { "-h", OPT_HELP, FLGOPT_BOGUS }, { "--version", OPT_VERSION, FLGOPT_BOGUS }, { "-V", OPT_VERSION, FLGOPT_BOGUS }, { (const char*)NULL, 0, 0 } /* end marker */ } ; #define STRAPPEND_MAX_INSIZE 8192 #define strappend_is_large(x) ((x) > STRAPPEND_MAX_INSIZE) int ntfs_strappend(char **dest, const char *append) { char *p; size_t size_append, size_dest = 0; if (!dest) return -1; if (!append) return 0; size_append = strlen(append); if (*dest) size_dest = strlen(*dest); if (strappend_is_large(size_dest) || strappend_is_large(size_append)) { errno = EOVERFLOW; ntfs_log_perror("%s: Too large input buffer", EXEC_NAME); return -1; } p = (char*)realloc(*dest, size_dest + size_append + 1); if (!p) { ntfs_log_perror("%s: Memory realloction failed", EXEC_NAME); return -1; } *dest = p; strcpy(*dest + size_dest, append); return 0; } int ntfs_strappend_escaped(char **dest, const char *append) { int ret = -1; char *escaped_string = NULL; #if FUSE_VERSION >= 27 if (fuse_version() >= 28) { const char *ptr = append; char *dest_ptr = NULL; size_t append_length = 0; size_t escaped_length = 0; while (*ptr) { if (*ptr == '\\' || *ptr == ',') { escaped_length++; } escaped_length++; append_length++; ptr++; } if (escaped_length != append_length) { ptr = append; escaped_string = malloc(escaped_length + 1); if (!escaped_string) { goto out; } dest_ptr = escaped_string; while (*ptr) { if (*ptr == '\\' || *ptr == ',') { *(dest_ptr++) = '\\'; } *(dest_ptr++) = *(ptr++); } *dest_ptr = '\0'; ntfs_log_debug("Generated escaped string: %s\n", escaped_string); } } #endif /* FUSE_VERSION >= 27 */ ret = ntfs_strappend(dest, escaped_string ? escaped_string : append); out: if (escaped_string) { free(escaped_string); } return ret; } /* * Insert an option before ",fsname=" * This is for keeping "fsname" as the last option, because on * Solaris device names may contain commas. */ int ntfs_strinsert(char **dest, const char *append) { char *p, *q; size_t size_append, size_dest = 0; if (!dest) return -1; if (!append) return 0; size_append = strlen(append); if (*dest) size_dest = strlen(*dest); if (strappend_is_large(size_dest) || strappend_is_large(size_append)) { errno = EOVERFLOW; ntfs_log_perror("%s: Too large input buffer", EXEC_NAME); return -1; } p = (char*)malloc(size_dest + size_append + 1); if (!p) { ntfs_log_perror("%s: Memory reallocation failed", EXEC_NAME); return -1; } strcpy(p, *dest); q = strstr(p, ",fsname="); if (q) { strcpy(q, append); q = strstr(*dest, ",fsname="); if (q) strcat(p, q); free(*dest); *dest = p; } else { free(*dest); *dest = p; strcpy(*dest + size_dest, append); } return 0; } static int bogus_option_value(char *val, const char *s) { if (val) { ntfs_log_error("'%s' option shouldn't have value.\n", s); return -1; } return 0; } static int missing_option_value(char *val, const char *s) { if (!val) { ntfs_log_error("'%s' option should have a value.\n", s); return -1; } return 0; } char *parse_mount_options(ntfs_fuse_context_t *ctx, const struct ntfs_options *popts, BOOL low_fuse) { char *options, *s, *opt, *val, *ret = NULL; const char *orig_opts = popts->options; BOOL no_def_opts = FALSE; int default_permissions = 0; int permissions = 0; int acl = 0; int want_permissions = 0; int intarg; const struct DEFOPTION *poptl; ctx->secure_flags = 0; #ifdef HAVE_SETXATTR /* extended attributes interface required */ ctx->efs_raw = FALSE; #endif /* HAVE_SETXATTR */ ctx->compression = DEFAULT_COMPRESSION; options = strdup(orig_opts ? orig_opts : ""); if (!options) { ntfs_log_perror("%s: strdup failed", EXEC_NAME); return NULL; } s = options; while (s && *s && (val = strsep(&s, ","))) { opt = strsep(&val, "="); poptl = optionlist; while (poptl->name && strcmp(poptl->name,opt)) poptl++; if (poptl->name) { if ((poptl->flags & FLGOPT_BOGUS) && bogus_option_value(val, opt)) goto err_exit; if ((poptl->flags & FLGOPT_OCTAL) && (!val || sscanf(val, "%o", &intarg) != 1)) { ntfs_log_error("'%s' option needs an octal value\n", opt); goto err_exit; } if (poptl->flags & FLGOPT_DECIMAL) { if ((poptl->flags & FLGOPT_OPTIONAL) && !val) intarg = 0; else if (!val || sscanf(val, "%i", &intarg) != 1) { ntfs_log_error("'%s' option " "needs a decimal value\n", opt); goto err_exit; } } if ((poptl->flags & FLGOPT_STRING) && missing_option_value(val, opt)) goto err_exit; switch (poptl->type) { case OPT_RO : case OPT_FAKE_RW : ctx->ro = TRUE; break; case OPT_RW : ctx->rw = TRUE; break; case OPT_NOATIME : ctx->atime = ATIME_DISABLED; break; case OPT_ATIME : ctx->atime = ATIME_ENABLED; break; case OPT_RELATIME : ctx->atime = ATIME_RELATIVE; break; case OPT_DMTIME : if (!intarg) intarg = DEFAULT_DMTIME; ctx->dmtime = intarg*10000000LL; break; case OPT_NO_DEF_OPTS : no_def_opts = TRUE; /* Don't add default options. */ ctx->silent = FALSE; /* cancel default silent */ break; case OPT_DEFAULT_PERMISSIONS : default_permissions = 1; break; case OPT_PERMISSIONS : permissions = 1; break; #if POSIXACLS case OPT_ACL : acl = 1; break; #endif case OPT_UMASK : ctx->dmask = ctx->fmask = intarg; want_permissions = 1; break; case OPT_FMASK : ctx->fmask = intarg; want_permissions = 1; break; case OPT_DMASK : ctx->dmask = intarg; want_permissions = 1; break; case OPT_UID : ctx->uid = intarg; want_permissions = 1; break; case OPT_GID : ctx->gid = intarg; want_permissions = 1; break; case OPT_SHOW_SYS_FILES : ctx->show_sys_files = TRUE; break; case OPT_HIDE_HID_FILES : ctx->hide_hid_files = TRUE; break; case OPT_HIDE_DOT_FILES : ctx->hide_dot_files = TRUE; break; case OPT_WINDOWS_NAMES : ctx->windows_names = TRUE; break; case OPT_IGNORE_CASE : if (low_fuse) ctx->ignore_case = TRUE; else { ntfs_log_error("'%s' is an unsupported option.\n", poptl->name); goto err_exit; } break; case OPT_COMPRESSION : ctx->compression = TRUE; break; case OPT_NOCOMPRESSION : ctx->compression = FALSE; break; case OPT_SILENT : ctx->silent = TRUE; break; case OPT_RECOVER : ctx->recover = TRUE; break; case OPT_NORECOVER : ctx->recover = FALSE; break; case OPT_REMOVE_HIBERFILE : ctx->hiberfile = TRUE; break; case OPT_SYNC : ctx->sync = TRUE; break; #ifdef FUSE_CAP_BIG_WRITES case OPT_BIG_WRITES : ctx->big_writes = TRUE; break; #endif case OPT_LOCALE : ntfs_set_char_encoding(val); break; #if defined(__APPLE__) || defined(__DARWIN__) #ifdef ENABLE_NFCONV case OPT_NFCONV : if (ntfs_macosx_normalize_filenames(1)) { ntfs_log_error("ntfs_macosx_normalize_filenames(1) failed!\n"); goto err_exit; } break; case OPT_NONFCONV : if (ntfs_macosx_normalize_filenames(0)) { ntfs_log_error("ntfs_macosx_normalize_filenames(0) failed!\n"); goto err_exit; } break; #endif /* ENABLE_NFCONV */ #endif /* defined(__APPLE__) || defined(__DARWIN__) */ case OPT_STREAMS_INTERFACE : if (!strcmp(val, "none")) ctx->streams = NF_STREAMS_INTERFACE_NONE; else if (!strcmp(val, "xattr")) ctx->streams = NF_STREAMS_INTERFACE_XATTR; else if (!strcmp(val, "openxattr")) ctx->streams = NF_STREAMS_INTERFACE_OPENXATTR; else if (!low_fuse && !strcmp(val, "windows")) ctx->streams = NF_STREAMS_INTERFACE_WINDOWS; else { ntfs_log_error("Invalid named data streams " "access interface.\n"); goto err_exit; } break; case OPT_USER_XATTR : #if defined(__APPLE__) || defined(__DARWIN__) /* macOS builds use non-namespaced extended * attributes by default since it matches the * standard behaviour of macOS filesystems. */ ctx->streams = NF_STREAMS_INTERFACE_OPENXATTR; #else ctx->streams = NF_STREAMS_INTERFACE_XATTR; #endif break; case OPT_NOAUTO : /* Don't pass noauto option to fuse. */ break; case OPT_DEBUG : ctx->debug = TRUE; ntfs_log_set_levels(NTFS_LOG_LEVEL_DEBUG); ntfs_log_set_levels(NTFS_LOG_LEVEL_TRACE); break; case OPT_NO_DETACH : ctx->no_detach = TRUE; break; case OPT_REMOUNT : ntfs_log_error("Remounting is not supported at present." " You have to umount volume and then " "mount it once again.\n"); goto err_exit; case OPT_BLKSIZE : ntfs_log_info("WARNING: blksize option is ignored " "because ntfs-3g must calculate it.\n"); break; case OPT_INHERIT : /* * do not overwrite inherited permissions * in create() */ ctx->inherit = TRUE; break; case OPT_ADDSECURIDS : /* * create security ids for files being read * with an individual security attribute */ ctx->secure_flags |= (1 << SECURITY_ADDSECURIDS); break; case OPT_STATICGRPS : /* * use static definition of groups * for file access control */ ctx->secure_flags |= (1 << SECURITY_STATICGRPS); break; case OPT_USERMAPPING : ctx->usermap_path = strdup(val); if (!ctx->usermap_path) { ntfs_log_error("no more memory to store " "'usermapping' option.\n"); goto err_exit; } break; #ifdef HAVE_SETXATTR /* extended attributes interface required */ #ifdef XATTR_MAPPINGS case OPT_XATTRMAPPING : ctx->xattrmap_path = strdup(val); if (!ctx->xattrmap_path) { ntfs_log_error("no more memory to store " "'xattrmapping' option.\n"); goto err_exit; } break; #endif /* XATTR_MAPPINGS */ case OPT_EFS_RAW : ctx->efs_raw = TRUE; break; #endif /* HAVE_SETXATTR */ case OPT_POSIX_NLINK : ctx->posix_nlink = TRUE; break; case OPT_SPECIAL_FILES : if (!strcmp(val, "interix")) ctx->special_files = NTFS_FILES_INTERIX; else if (!strcmp(val, "wsl")) ctx->special_files = NTFS_FILES_WSL; else { ntfs_log_error("Invalid special_files" " mode.\n"); goto err_exit; } break; case OPT_FSNAME : /* Filesystem name. */ /* * We need this to be able to check whether filesystem * mounted or not. * (falling through to default) */ case OPT_HELP : /* Could lead to unclean condition */ case OPT_VERSION : /* Could lead to unclean condition */ default : ntfs_log_error("'%s' is an unsupported option.\n", poptl->name); goto err_exit; } if ((poptl->flags & FLGOPT_APPEND) && (ntfs_strappend(&ret, poptl->name) || ntfs_strappend(&ret, ","))) goto err_exit; } else { /* Probably FUSE option. */ if (ntfs_strappend(&ret, opt)) goto err_exit; if (val) { if (ntfs_strappend(&ret, "=")) goto err_exit; if (ntfs_strappend(&ret, val)) goto err_exit; } if (ntfs_strappend(&ret, ",")) goto err_exit; } } if (!no_def_opts && ntfs_strappend(&ret, def_opts)) goto err_exit; if ((default_permissions || (permissions && !acl)) && ntfs_strappend(&ret, "default_permissions,")) goto err_exit; /* The atime options exclude each other */ if (ctx->atime == ATIME_RELATIVE && ntfs_strappend(&ret, "relatime,")) goto err_exit; else if (ctx->atime == ATIME_ENABLED && ntfs_strappend(&ret, "atime,")) goto err_exit; else if (ctx->atime == ATIME_DISABLED && ntfs_strappend(&ret, "noatime,")) goto err_exit; if (ntfs_strappend(&ret, "fsname=")) goto err_exit; if (ntfs_strappend_escaped(&ret, popts->device)) { goto err_exit; } if (permissions && !acl) ctx->secure_flags |= (1 << SECURITY_DEFAULT); if (acl) ctx->secure_flags |= (1 << SECURITY_ACL); if (want_permissions) ctx->secure_flags |= (1 << SECURITY_WANTED); if (ctx->ro) { ctx->secure_flags &= ~(1 << SECURITY_ADDSECURIDS); ctx->hiberfile = FALSE; ctx->rw = FALSE; } exit: free(options); return ret; err_exit: free(ret); ret = NULL; goto exit; } /** * parse_options - Read and validate the programs command line * Read the command line, verify the syntax and parse the options. * * Return: 0 success, -1 error. */ int ntfs_parse_options(struct ntfs_options *popts, void (*usage)(void), int argc, char *argv[]) { int c; static const char *sopt = "-o:hnsvV"; static const struct option lopt[] = { { "options", required_argument, NULL, 'o' }, { "help", no_argument, NULL, 'h' }, { "no-mtab", no_argument, NULL, 'n' }, { "verbose", no_argument, NULL, 'v' }, { "version", no_argument, NULL, 'V' }, { NULL, 0, NULL, 0 } }; opterr = 0; /* We'll handle the errors, thank you. */ while ((c = getopt_long(argc, argv, sopt, lopt, NULL)) != -1) { switch (c) { case 1: /* A non-option argument */ if (!popts->device) { popts->device = ntfs_malloc(PATH_MAX + 1); if (!popts->device) return -1; /* Canonicalize device name (mtab, etc) */ popts->arg_device = optarg; if (!ntfs_realpath_canonicalize(optarg, popts->device)) { ntfs_log_perror("%s: Failed to access " "volume '%s'", EXEC_NAME, optarg); free(popts->device); popts->device = NULL; return -1; } } else if (!popts->mnt_point) { popts->mnt_point = optarg; } else { ntfs_log_error("%s: You must specify exactly one " "device and exactly one mount " "point.\n", EXEC_NAME); return -1; } break; case 'o': if (popts->options) if (ntfs_strappend(&popts->options, ",")) return -1; if (ntfs_strappend(&popts->options, optarg)) return -1; break; case 'h': usage(); exit(9); case 'n': /* * no effect - automount passes it, meaning 'no-mtab' */ break; case 's': /* * no effect - automount passes it, meaning sloppy */ break; case 'v': /* * We must handle the 'verbose' option even if * we don't use it because mount(8) passes it. */ break; case 'V': ntfs_log_info("%s %s %s %d\n", EXEC_NAME, VERSION, FUSE_TYPE, fuse_version()); exit(0); default: ntfs_log_error("%s: Unknown option '%s'.\n", EXEC_NAME, argv[optind - 1]); return -1; } } if (!popts->device) { ntfs_log_error("%s: No device is specified.\n", EXEC_NAME); return -1; } if (!popts->mnt_point) { ntfs_log_error("%s: No mountpoint is specified.\n", EXEC_NAME); return -1; } return 0; } #ifdef HAVE_SETXATTR int ntfs_fuse_listxattr_common(ntfs_inode *ni, ntfs_attr_search_ctx *actx, char *list, size_t size, BOOL prefixing) { int ret = 0; char *to = list; #ifdef XATTR_MAPPINGS BOOL accepted; const struct XATTRMAPPING *item; #endif /* XATTR_MAPPINGS */ /* first list the regular user attributes (ADS) */ while (!ntfs_attr_lookup(AT_DATA, NULL, 0, CASE_SENSITIVE, 0, NULL, 0, actx)) { char *tmp_name = NULL; int tmp_name_len; if (!actx->attr->name_length) continue; tmp_name_len = ntfs_ucstombs( (ntfschar *)((u8*)actx->attr + le16_to_cpu(actx->attr->name_offset)), actx->attr->name_length, &tmp_name, 0); if (tmp_name_len < 0) { ret = -errno; goto exit; } /* * When using name spaces, do not return * security, trusted or system attributes * (filtered elsewhere anyway) * otherwise insert "user." prefix */ if (prefixing) { if ((strlen(tmp_name) > sizeof(xattr_ntfs_3g)) && !strncmp(tmp_name,xattr_ntfs_3g, sizeof(xattr_ntfs_3g)-1)) tmp_name_len = 0; else ret += tmp_name_len + nf_ns_user_prefix_len + 1; } else ret += tmp_name_len + 1; if (size && tmp_name_len) { if ((size_t)ret <= size) { if (prefixing) { strcpy(to, nf_ns_user_prefix); to += nf_ns_user_prefix_len; } strncpy(to, tmp_name, tmp_name_len); to += tmp_name_len; *to = 0; to++; } else { free(tmp_name); ret = -ERANGE; goto exit; } } free(tmp_name); } #ifdef XATTR_MAPPINGS /* now append the system attributes mapped to user space */ for (item=ni->vol->xattr_mapping; item; item=item->next) { switch (item->xattr) { case XATTR_NTFS_EFSINFO : accepted = ni->vol->efs_raw && (ni->flags & FILE_ATTR_ENCRYPTED); break; case XATTR_NTFS_REPARSE_DATA : accepted = (ni->flags & FILE_ATTR_REPARSE_POINT) != const_cpu_to_le32(0); break; // TODO : we are supposed to only return xattrs which are set // this is more complex for OBJECT_ID and DOS_NAME default : accepted = TRUE; break; } if (accepted) { ret += strlen(item->name) + 1; if (size) { if ((size_t)ret <= size) { strcpy(to, item->name); to += strlen(item->name); *to++ = 0; } else { ret = -ERANGE; goto exit; } } #else /* XATTR_MAPPINGS */ /* List efs info xattr for encrypted files */ if (ni->vol->efs_raw && (ni->flags & FILE_ATTR_ENCRYPTED)) { ret += sizeof(nf_ns_alt_xattr_efsinfo); if ((size_t)ret <= size) { memcpy(to, nf_ns_alt_xattr_efsinfo, sizeof(nf_ns_alt_xattr_efsinfo)); to += sizeof(nf_ns_alt_xattr_efsinfo); #endif /* XATTR_MAPPINGS */ } } exit : return (ret); } #endif /* HAVE_SETXATTR */ #ifndef DISABLE_PLUGINS int register_reparse_plugin(ntfs_fuse_context_t *ctx, le32 tag, const plugin_operations_t *ops, void *handle) { plugin_list_t *plugin; int res; res = -1; plugin = (plugin_list_t*)ntfs_malloc(sizeof(plugin_list_t)); if (plugin) { plugin->tag = tag; plugin->ops = ops; plugin->handle = handle; plugin->next = ctx->plugins; ctx->plugins = plugin; res = 0; } return (res); } /* * Get the reparse operations associated to an inode * * The plugin able to process the reparse point is dynamically loaded * * When successful, returns the operations vector and the reparse * data if requested, * Otherwise returns NULL, with errno set. */ const struct plugin_operations *select_reparse_plugin(ntfs_fuse_context_t *ctx, ntfs_inode *ni, REPARSE_POINT **reparse_wanted) { const struct plugin_operations *ops; void *handle; REPARSE_POINT *reparse; le32 tag, seltag; plugin_list_t *plugin; plugin_init_t pinit; ops = (struct plugin_operations*)NULL; reparse = ntfs_get_reparse_point(ni); if (reparse) { tag = reparse->reparse_tag; seltag = tag & IO_REPARSE_PLUGIN_SELECT; for (plugin=ctx->plugins; plugin && (plugin->tag != seltag); plugin = plugin->next) { } if (plugin) { ops = plugin->ops; } else { #ifdef PLUGIN_DIR char name[sizeof(PLUGIN_DIR) + 64]; snprintf(name,sizeof(name), PLUGIN_DIR "/ntfs-plugin-%08lx.so", (long)le32_to_cpu(seltag)); #else char name[64]; snprintf(name,sizeof(name), "ntfs-plugin-%08lx.so", (long)le32_to_cpu(seltag)); #endif handle = dlopen(name, RTLD_LAZY); if (handle) { pinit = (plugin_init_t)dlsym(handle, "init"); if (pinit) { /* pinit() should set errno if it fails */ ops = (*pinit)(tag); if (ops && register_reparse_plugin(ctx, seltag, ops, handle)) ops = (struct plugin_operations*)NULL; } else errno = ELIBBAD; if (!ops) dlclose(handle); } else { errno = ELIBACC; if (!(ctx->errors_logged & ERR_PLUGIN)) { ntfs_log_perror( "Could not load plugin %s", name); ntfs_log_error("Hint %s\n",dlerror()); } ctx->errors_logged |= ERR_PLUGIN; } } if (ops && reparse_wanted) *reparse_wanted = reparse; else free(reparse); } return (ops); } void close_reparse_plugins(ntfs_fuse_context_t *ctx) { while (ctx->plugins) { plugin_list_t *next; next = ctx->plugins->next; if (ctx->plugins->handle) dlclose(ctx->plugins->handle); free(ctx->plugins); ctx->plugins = next; } } #endif /* DISABLE_PLUGINS */ #ifdef HAVE_SETXATTR /* * Check whether a user xattr is allowed * * The inode must be a plain file or a directory. The only allowed * metadata file is the root directory (useful for MacOSX and hopefully * does not harm Windows). */ BOOL user_xattrs_allowed(ntfs_fuse_context_t *ctx __attribute__((unused)), ntfs_inode *ni) { u32 dt_type; BOOL res; /* Quick return for common cases and root */ if (!(ni->flags & (FILE_ATTR_SYSTEM | FILE_ATTR_REPARSE_POINT)) || (ni->mft_no == FILE_root)) res = TRUE; else { /* Reparse point depends on kind, see plugin */ if (ni->flags & FILE_ATTR_REPARSE_POINT) { #ifndef DISABLE_PLUGINS struct stat stbuf; REPARSE_POINT *reparse; const plugin_operations_t *ops; res = FALSE; /* default for error cases */ ops = select_reparse_plugin(ctx, ni, &reparse); if (ops) { if (ops->getattr && !ops->getattr(ni,reparse,&stbuf)) { res = S_ISREG(stbuf.st_mode) || S_ISDIR(stbuf.st_mode); } free(reparse); } #else /* DISABLE_PLUGINS */ res = FALSE; /* mountpoints, symlinks, ... */ #endif /* DISABLE_PLUGINS */ } else { /* Metadata */ if (ni->mft_no < FILE_first_user) res = FALSE; else { /* Interix types */ dt_type = ntfs_interix_types(ni); res = (dt_type == NTFS_DT_REG) || (dt_type == NTFS_DT_DIR); } } } return (res); } #endif /* HAVE_SETXATTR */ ntfs-3g-2026.2.25/src/ntfs-3g.c0000664000175000017500000034550415152260174011230 /** * ntfs-3g - Third Generation NTFS Driver * * Copyright (c) 2005-2007 Yura Pakhuchiy * Copyright (c) 2005 Yuval Fledel * Copyright (c) 2006-2009 Szabolcs Szakacsits * Copyright (c) 2007-2021 Jean-Pierre Andre * Copyright (c) 2009 Erik Larsson * * This file is originated from the Linux-NTFS project. * * 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 */ #include "config.h" #include #if !defined(FUSE_VERSION) || (FUSE_VERSION < 26) #error "***********************************************************" #error "* *" #error "* Compilation requires at least FUSE version 2.6.0! *" #error "* *" #error "***********************************************************" #endif #ifdef HAVE_STDIO_H #include #endif #ifdef HAVE_STRING_H #include #endif #ifdef HAVE_ERRNO_H #include #endif #ifdef HAVE_FCNTL_H #include #endif #ifdef HAVE_UNISTD_H #include #endif #ifdef HAVE_STDLIB_H #include #endif #ifdef HAVE_LOCALE_H #include #endif #include #ifdef HAVE_LIMITS_H #include #endif #include #include #ifdef HAVE_SETXATTR #include #endif #ifdef HAVE_SYS_TYPES_H #include #endif #ifdef MAJOR_IN_MKDEV #include #endif #ifdef MAJOR_IN_SYSMACROS #include #endif #if defined(__APPLE__) || defined(__DARWIN__) #include #elif defined(__sun) && defined (__SVR4) #include #endif /* defined(__APPLE__) || defined(__DARWIN__), ... */ #ifndef FUSE_CAP_POSIX_ACL /* until defined in */ #define FUSE_CAP_POSIX_ACL (1 << 18) #endif /* FUSE_CAP_POSIX_ACL */ #include "compat.h" #include "attrib.h" #include "inode.h" #include "volume.h" #include "dir.h" #include "unistr.h" #include "layout.h" #include "index.h" #include "ntfstime.h" #include "security.h" #include "reparse.h" #include "ea.h" #include "object_id.h" #include "efs.h" #include "logging.h" #include "xattrs.h" #include "misc.h" #include "ioctl.h" #include "plugin.h" #include "ntfs-3g_common.h" /* * The following permission checking modes are governed by * the HPERMSCONFIG value in param.h */ /* ACLS may be checked by kernel (requires a fuse patch) or here */ #define KERNELACLS ((HPERMSCONFIG > 6) & (HPERMSCONFIG < 10)) /* basic permissions may be checked by kernel or here */ #define KERNELPERMS (((HPERMSCONFIG - 1) % 6) < 3) /* may want to use fuse/kernel cacheing */ #define CACHEING (!(HPERMSCONFIG % 3)) #if KERNELACLS & !KERNELPERMS #error Incompatible options KERNELACLS and KERNELPERMS #endif /* sometimes the kernel cannot check access */ #define ntfs_real_allowed_access(scx, ni, type) ntfs_allowed_access(scx, ni, type) #if POSIXACLS & KERNELPERMS & !KERNELACLS /* short-circuit if PERMS checked by kernel and ACLs by fs */ #define ntfs_allowed_access(scx, ni, type) \ ((scx)->vol->secure_flags & (1 << SECURITY_DEFAULT) \ ? 1 : ntfs_allowed_access(scx, ni, type)) #endif #define set_archive(ni) (ni)->flags |= FILE_ATTR_ARCHIVE /* * Call a function from a reparse plugin (variable arguments) * Requires "reparse" and "ops" to have been defined * * Returns a non-negative value if successful, * and a negative error code if something fails. */ #define CALL_REPARSE_PLUGIN(ni, op_name, ...) \ (reparse = (REPARSE_POINT*)NULL, \ ops = select_reparse_plugin(ctx, ni, &reparse), \ (!ops ? -errno \ : (ops->op_name ? \ ops->op_name(ni, reparse, __VA_ARGS__) \ : -EOPNOTSUPP))), \ free(reparse) typedef enum { FSTYPE_NONE, FSTYPE_UNKNOWN, FSTYPE_FUSE, FSTYPE_FUSEBLK } fuse_fstype; typedef struct { fuse_fill_dir_t filler; void *buf; } ntfs_fuse_fill_context_t; enum { CLOSE_COMPRESSED = 1, CLOSE_ENCRYPTED = 2, CLOSE_DMTIME = 4, CLOSE_REPARSE = 8 }; static struct ntfs_options opts; const char *EXEC_NAME = "ntfs-3g"; static ntfs_fuse_context_t *ctx; static u32 ntfs_sequence; static const char *usage_msg = "\n" "%s %s %s %d - Third Generation NTFS Driver\n" "\t\tConfiguration type %d, " #ifdef HAVE_SETXATTR "XATTRS are on, " #else "XATTRS are off, " #endif #if POSIXACLS "POSIX ACLS are on\n" #else "POSIX ACLS are off\n" #endif "\n" "Copyright (C) 2005-2007 Yura Pakhuchiy\n" "Copyright (C) 2006-2009 Szabolcs Szakacsits\n" "Copyright (C) 2007-2022 Jean-Pierre Andre\n" "Copyright (C) 2009-2020 Erik Larsson\n" "\n" "Usage: %s [-o option[,...]] \n" "\n" "Options: ro (read-only mount), windows_names, uid=, gid=,\n" " umask=, fmask=, dmask=, streams_interface=.\n" " Please see the details in the manual (type: man ntfs-3g).\n" "\n" "Example: ntfs-3g /dev/sda1 /mnt/windows\n" "\n" #ifdef PLUGIN_DIR "Plugin path: " PLUGIN_DIR "\n\n" #endif /* PLUGIN_DIR */ "%s"; static const char ntfs_bad_reparse[] = "unsupported reparse tag 0x%08lx"; /* exact length of target text, without the terminator */ #define ntfs_bad_reparse_lth (sizeof(ntfs_bad_reparse) + 2) #ifdef FUSE_INTERNAL int drop_privs(void); int restore_privs(void); #else /* * setuid and setgid root ntfs-3g denies to start with external FUSE, * therefore the below functions are no-op in such case. */ static int drop_privs(void) { return 0; } #if defined(linux) || defined(__uClinux__) static int restore_privs(void) { return 0; } #endif static const char *setuid_msg = "Mount is denied because setuid and setgid root ntfs-3g is insecure with the\n" "external FUSE library. Either remove the setuid/setgid bit from the binary\n" "or rebuild NTFS-3G with integrated FUSE support and make it setuid root.\n" "Please see more information at\n" "https://github.com/tuxera/ntfs-3g/wiki/NTFS-3G-FAQ\n"; static const char *unpriv_fuseblk_msg = "Unprivileged user can not mount NTFS block devices using the external FUSE\n" "library. Either mount the volume as root, or rebuild NTFS-3G with integrated\n" "FUSE support and make it setuid root. Please see more information at\n" "https://github.com/tuxera/ntfs-3g/wiki/NTFS-3G-FAQ\n"; #endif /** * ntfs_fuse_is_named_data_stream - check path to be to named data stream * @path: path to check * * Returns 1 if path is to named data stream or 0 otherwise. */ static int ntfs_fuse_is_named_data_stream(const char *path) { if (strchr(path, ':') && ctx->streams == NF_STREAMS_INTERFACE_WINDOWS) return 1; return 0; } static void ntfs_fuse_update_times(ntfs_inode *ni, ntfs_time_update_flags mask) { if (ctx->atime == ATIME_DISABLED) mask &= ~NTFS_UPDATE_ATIME; else if (ctx->atime == ATIME_RELATIVE && mask == NTFS_UPDATE_ATIME && (sle64_to_cpu(ni->last_access_time) >= sle64_to_cpu(ni->last_data_change_time)) && (sle64_to_cpu(ni->last_access_time) >= sle64_to_cpu(ni->last_mft_change_time))) return; ntfs_inode_update_times(ni, mask); } static s64 ntfs_get_nr_free_mft_records(ntfs_volume *vol) { ntfs_attr *na = vol->mftbmp_na; s64 nr_free = ntfs_attr_get_free_bits(na); if (nr_free >= 0) nr_free += (na->allocated_size - na->data_size) << 3; return nr_free; } /* * Fill a security context as needed by security functions * returns TRUE if there is a user mapping, * FALSE if there is none * This is not an error and the context is filled anyway, * it is used for implicit Windows-like inheritance */ static BOOL ntfs_fuse_fill_security_context(struct SECURITY_CONTEXT *scx) { struct fuse_context *fusecontext; scx->vol = ctx->vol; scx->mapping[MAPUSERS] = ctx->security.mapping[MAPUSERS]; scx->mapping[MAPGROUPS] = ctx->security.mapping[MAPGROUPS]; scx->pseccache = &ctx->seccache; fusecontext = fuse_get_context(); scx->uid = fusecontext->uid; scx->gid = fusecontext->gid; scx->tid = fusecontext->pid; #ifdef FUSE_CAP_DONT_MASK /* the umask can be processed by the file system */ scx->umask = fusecontext->umask; #else /* the umask if forced by fuse on creation */ scx->umask = 0; #endif return (ctx->security.mapping[MAPUSERS] != (struct MAPPING*)NULL); } #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) /* * Check access to parent directory * * directory and file inodes are only opened when not fed in, * they *HAVE TO* be fed in when already open, however * file inode is only useful when S_ISVTX is requested * * returns 1 if allowed, * 0 if not allowed or some error occurred (errno tells why) */ static int ntfs_allowed_dir_access(struct SECURITY_CONTEXT *scx, const char *path, ntfs_inode *dir_ni, ntfs_inode *ni, mode_t accesstype) { int allowed; ntfs_inode *ni2; ntfs_inode *dir_ni2; char *dirpath; char *name; struct stat stbuf; #if POSIXACLS & KERNELPERMS & !KERNELACLS /* short-circuit if PERMS checked by kernel and ACLs by fs */ if (scx->vol->secure_flags & (1 << SECURITY_DEFAULT)) allowed = 1; else #endif { if (dir_ni) allowed = ntfs_real_allowed_access(scx, dir_ni, accesstype); else { allowed = 0; dirpath = strdup(path); if (dirpath) { /* the root of file system is seen as a parent of itself */ /* is that correct ? */ name = strrchr(dirpath, '/'); *name = 0; dir_ni2 = ntfs_pathname_to_inode(scx->vol, NULL, dirpath); if (dir_ni2) { allowed = ntfs_real_allowed_access(scx, dir_ni2, accesstype); if (ntfs_inode_close(dir_ni2)) allowed = 0; } free(dirpath); } } /* * for a not-owned sticky directory, have to * check whether file itself is owned */ if ((accesstype == (S_IWRITE + S_IEXEC + S_ISVTX)) && (allowed == 2)) { if (ni) ni2 = ni; else ni2 = ntfs_pathname_to_inode(scx->vol, NULL, path); allowed = 0; if (ni2) { allowed = (ntfs_get_owner_mode(scx,ni2,&stbuf) >= 0) && (stbuf.st_uid == scx->uid); if (!ni) ntfs_inode_close(ni2); } } } return (allowed); } #endif #ifdef HAVE_SETXATTR /* extended attributes interface required */ /* * Check access to parent directory * * for non-standard cases where access control cannot be checked by kernel * * no known situations where S_ISVTX is requested * * returns 1 if allowed, * 0 if not allowed or some error occurred (errno tells why) */ static int ntfs_allowed_real_dir_access(struct SECURITY_CONTEXT *scx, const char *path, ntfs_inode *dir_ni, mode_t accesstype) { int allowed; ntfs_inode *dir_ni2; char *dirpath; char *name; if (dir_ni) allowed = ntfs_real_allowed_access(scx, dir_ni, accesstype); else { allowed = 0; dirpath = strdup(path); if (dirpath) { /* the root of file system is seen as a parent of itself */ /* is that correct ? */ name = strrchr(dirpath, '/'); *name = 0; dir_ni2 = ntfs_pathname_to_inode(scx->vol, NULL, dirpath); if (dir_ni2) { allowed = ntfs_real_allowed_access(scx, dir_ni2, accesstype); if (ntfs_inode_close(dir_ni2)) allowed = 0; } free(dirpath); } } return (allowed); } static ntfs_inode *get_parent_dir(const char *path) { ntfs_inode *dir_ni; char *dirpath; char *p; dirpath = strdup(path); dir_ni = (ntfs_inode*)NULL; if (dirpath) { p = strrchr(dirpath,'/'); if (p) { /* always present, be safe */ *p = 0; dir_ni = ntfs_pathname_to_inode(ctx->vol, NULL, dirpath); } free(dirpath); } else errno = ENOMEM; return (dir_ni); } #endif /* HAVE_SETXATTR */ /** * ntfs_fuse_statfs - return information about mounted NTFS volume * @path: ignored (but fuse requires it) * @sfs: statfs structure in which to return the information * * Return information about the mounted NTFS volume @sb in the statfs structure * pointed to by @sfs (this is initialized with zeros before ntfs_statfs is * called). We interpret the values to be correct of the moment in time at * which we are called. Most values are variable otherwise and this isn't just * the free values but the totals as well. For example we can increase the * total number of file nodes if we run out and we can keep doing this until * there is no more space on the volume left at all. * * This code based on ntfs_statfs from ntfs kernel driver. * * Returns 0 on success or -errno on error. */ static int ntfs_fuse_statfs(const char *path __attribute__((unused)), struct statvfs *sfs) { s64 size; int delta_bits; ntfs_volume *vol; vol = ctx->vol; if (!vol) return -ENODEV; /* * File system block size. Used to calculate used/free space by df. * Incorrectly documented as "optimal transfer block size". */ sfs->f_bsize = vol->cluster_size; /* Fundamental file system block size, used as the unit. */ sfs->f_frsize = vol->cluster_size; /* * Total number of blocks on file system in units of f_frsize. * Since inodes are also stored in blocks ($MFT is a file) hence * this is the number of clusters on the volume. */ sfs->f_blocks = vol->nr_clusters; /* Free blocks available for all and for non-privileged processes. */ size = vol->free_clusters; if (size < 0) size = 0; sfs->f_bavail = sfs->f_bfree = size; /* Free inodes on the free space */ delta_bits = vol->cluster_size_bits - vol->mft_record_size_bits; if (delta_bits >= 0) size <<= delta_bits; else size >>= -delta_bits; /* Number of inodes at this point in time. */ sfs->f_files = (vol->mftbmp_na->allocated_size << 3) + size; /* Free inodes available for all and for non-privileged processes. */ size += vol->free_mft_records; if (size < 0) size = 0; sfs->f_ffree = sfs->f_favail = size; /* Maximum length of filenames. */ sfs->f_namemax = NTFS_MAX_NAME_LEN; return 0; } /** * ntfs_fuse_parse_path - split path to path and stream name. * @org_path: path to split * @path: pointer to buffer in which parsed path saved * @stream_name: pointer to buffer where stream name in unicode saved * * This function allocates buffers for @*path and @*stream, user must free them * after use. * * Return values: * <0 Error occurred, return -errno; * 0 No stream name, @*stream is not allocated and set to AT_UNNAMED. * >0 Stream name length in unicode characters. */ static int ntfs_fuse_parse_path(const char *org_path, char **path, ntfschar **stream_name) { char *stream_name_mbs; int res; stream_name_mbs = strdup(org_path); if (!stream_name_mbs) return -errno; if (ctx->streams == NF_STREAMS_INTERFACE_WINDOWS) { *path = strsep(&stream_name_mbs, ":"); if (stream_name_mbs) { *stream_name = NULL; res = ntfs_mbstoucs(stream_name_mbs, stream_name); if (res < 0) { free(*path); *path = NULL; return -errno; } return res; } } else *path = stream_name_mbs; *stream_name = AT_UNNAMED; return 0; } static void set_fuse_error(int *err) { if (!*err) *err = -errno; } #if defined(__APPLE__) || defined(__DARWIN__) static int ntfs_macfuse_getxtimes(const char *org_path, struct timespec *bkuptime, struct timespec *crtime) { int res = 0; ntfs_inode *ni; char *path = NULL; ntfschar *stream_name; int stream_name_len; stream_name_len = ntfs_fuse_parse_path(org_path, &path, &stream_name); if (stream_name_len < 0) return stream_name_len; memset(bkuptime, 0, sizeof(struct timespec)); memset(crtime, 0, sizeof(struct timespec)); ni = ntfs_pathname_to_inode(ctx->vol, NULL, path); if (!ni) { res = -errno; goto exit; } /* We have no backup timestamp in NTFS. */ crtime->tv_sec = sle64_to_cpu(ni->creation_time); exit: if (ntfs_inode_close(ni)) set_fuse_error(&res); free(path); if (stream_name_len) free(stream_name); return res; } int ntfs_macfuse_setcrtime(const char *path, const struct timespec *tv) { ntfs_inode *ni; int res = 0; if (ntfs_fuse_is_named_data_stream(path)) return -EINVAL; /* n/a for named data streams. */ ni = ntfs_pathname_to_inode(ctx->vol, NULL, path); if (!ni) return -errno; if (tv) { ni->creation_time = cpu_to_sle64(tv->tv_sec); ntfs_fuse_update_times(ni, NTFS_UPDATE_CTIME); } if (ntfs_inode_close(ni)) set_fuse_error(&res); return res; } int ntfs_macfuse_setbkuptime(const char *path, const struct timespec *tv) { ntfs_inode *ni; int res = 0; if (ntfs_fuse_is_named_data_stream(path)) return -EINVAL; /* n/a for named data streams. */ ni = ntfs_pathname_to_inode(ctx->vol, NULL, path); if (!ni) return -errno; /* * Only pretending to set backup time successfully to please the APIs of * Mac OS X. In reality, NTFS has no backup time. */ if (ntfs_inode_close(ni)) set_fuse_error(&res); return res; } int ntfs_macfuse_setchgtime(const char *path, const struct timespec *tv) { ntfs_inode *ni; int res = 0; if (ntfs_fuse_is_named_data_stream(path)) return -EINVAL; /* n/a for named data streams. */ ni = ntfs_pathname_to_inode(ctx->vol, NULL, path); if (!ni) return -errno; if (tv) { ni->last_mft_change_time = cpu_to_sle64(tv->tv_sec); ntfs_fuse_update_times(ni, 0); } if (ntfs_inode_close(ni)) set_fuse_error(&res); return res; } #endif /* defined(__APPLE__) || defined(__DARWIN__) */ static void *ntfs_init(struct fuse_conn_info *conn) { #if defined(__APPLE__) || defined(__DARWIN__) FUSE_ENABLE_XTIMES(conn); #endif #ifdef FUSE_CAP_DONT_MASK /* request umask not to be enforced by fuse */ conn->want |= FUSE_CAP_DONT_MASK; #endif /* defined FUSE_CAP_DONT_MASK */ #if POSIXACLS & KERNELACLS /* request ACLs to be checked by kernel */ conn->want |= FUSE_CAP_POSIX_ACL; #endif /* POSIXACLS & KERNELACLS */ #ifdef FUSE_CAP_BIG_WRITES if (ctx->big_writes && ((ctx->vol->nr_clusters << ctx->vol->cluster_size_bits) >= SAFE_CAPACITY_FOR_BIG_WRITES)) conn->want |= FUSE_CAP_BIG_WRITES; #endif #ifdef FUSE_CAP_IOCTL_DIR conn->want |= FUSE_CAP_IOCTL_DIR; #endif /* defined(FUSE_CAP_IOCTL_DIR) */ return NULL; } #ifndef DISABLE_PLUGINS /* * Define attributes for a junction or symlink * (internal plugin) */ static int junction_getattr(ntfs_inode *ni, const REPARSE_POINT *reparse __attribute__((unused)), struct stat *stbuf) { char *target; int res; errno = 0; target = ntfs_make_symlink(ni, ctx->abs_mnt_point); /* * If the reparse point is not a valid * directory junction, and there is no error * we still display as a symlink */ if (target || (errno == EOPNOTSUPP)) { if (target) stbuf->st_size = strlen(target); else stbuf->st_size = ntfs_bad_reparse_lth; stbuf->st_blocks = (ni->allocated_size + 511) >> 9; stbuf->st_mode = S_IFLNK; free(target); res = 0; } else { res = -errno; } return (res); } static int wsl_getattr(ntfs_inode *ni, const REPARSE_POINT *reparse, struct stat *stbuf) { dev_t rdev; int res; res = ntfs_reparse_check_wsl(ni, reparse); if (!res) { switch (reparse->reparse_tag) { case IO_REPARSE_TAG_AF_UNIX : stbuf->st_mode = S_IFSOCK; break; case IO_REPARSE_TAG_LX_FIFO : stbuf->st_mode = S_IFIFO; break; case IO_REPARSE_TAG_LX_CHR : stbuf->st_mode = S_IFCHR; res = ntfs_ea_check_wsldev(ni, &rdev); stbuf->st_rdev = rdev; break; case IO_REPARSE_TAG_LX_BLK : stbuf->st_mode = S_IFBLK; res = ntfs_ea_check_wsldev(ni, &rdev); stbuf->st_rdev = rdev; break; default : stbuf->st_size = ntfs_bad_reparse_lth; stbuf->st_mode = S_IFLNK; break; } } /* * If the reparse point is not a valid wsl special file * we display as a symlink */ if (res) { stbuf->st_size = ntfs_bad_reparse_lth; stbuf->st_mode = S_IFLNK; res = 0; } return (res); } /* * Apply permission masks to st_mode returned by a reparse handler */ static void apply_umask(struct stat *stbuf) { switch (stbuf->st_mode & S_IFMT) { case S_IFREG : stbuf->st_mode &= ~ctx->fmask; break; case S_IFDIR : stbuf->st_mode &= ~ctx->dmask; break; case S_IFLNK : stbuf->st_mode = (stbuf->st_mode & S_IFMT) | 0777; break; default : break; } } #endif /* DISABLE_PLUGINS */ static int ntfs_fuse_getattr(const char *org_path, struct stat *stbuf) { int res = 0; ntfs_inode *ni; ntfs_attr *na; char *path = NULL; ntfschar *stream_name; int stream_name_len; BOOL withusermapping; struct SECURITY_CONTEXT security; stream_name_len = ntfs_fuse_parse_path(org_path, &path, &stream_name); if (stream_name_len < 0) return stream_name_len; memset(stbuf, 0, sizeof(struct stat)); ni = ntfs_pathname_to_inode(ctx->vol, NULL, path); if (!ni) { res = -errno; goto exit; } withusermapping = ntfs_fuse_fill_security_context(&security); #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) /* * make sure the parent directory is searchable */ if (withusermapping && !ntfs_allowed_dir_access(&security,path, (!strcmp(org_path,"/") ? ni : (ntfs_inode*)NULL), ni, S_IEXEC)) { res = -EACCES; goto exit; } #endif stbuf->st_nlink = le16_to_cpu(ni->mrec->link_count); if (ctx->posix_nlink && !(ni->flags & FILE_ATTR_REPARSE_POINT)) stbuf->st_nlink = ntfs_dir_link_cnt(ni); if (((ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) || (ni->flags & FILE_ATTR_REPARSE_POINT)) && !stream_name_len) { if (ni->flags & FILE_ATTR_REPARSE_POINT) { #ifndef DISABLE_PLUGINS const plugin_operations_t *ops; REPARSE_POINT *reparse; res = CALL_REPARSE_PLUGIN(ni, getattr, stbuf); if (!res) { apply_umask(stbuf); goto ok; } else { stbuf->st_size = ntfs_bad_reparse_lth; stbuf->st_blocks = (ni->allocated_size + 511) >> 9; stbuf->st_mode = S_IFLNK; res = 0; goto ok; } goto exit; #else /* DISABLE_PLUGINS */ char *target; errno = 0; target = ntfs_make_symlink(ni, ctx->abs_mnt_point); /* * If the reparse point is not a valid * directory junction, and there is no error * we still display as a symlink */ if (target || (errno == EOPNOTSUPP)) { if (target) stbuf->st_size = strlen(target); else stbuf->st_size = ntfs_bad_reparse_lth; stbuf->st_blocks = (ni->allocated_size + 511) >> 9; stbuf->st_nlink = le16_to_cpu(ni->mrec->link_count); stbuf->st_mode = S_IFLNK; free(target); } else { res = -errno; goto exit; } #endif /* DISABLE_PLUGINS */ } else { /* Directory. */ stbuf->st_mode = S_IFDIR | (0777 & ~ctx->dmask); /* get index size, if not known */ if (!test_nino_flag(ni, KnownSize)) { na = ntfs_attr_open(ni, AT_INDEX_ALLOCATION, NTFS_INDEX_I30, 4); if (na) { ni->data_size = na->data_size; ni->allocated_size = na->allocated_size; set_nino_flag(ni, KnownSize); ntfs_attr_close(na); } } stbuf->st_size = ni->data_size; stbuf->st_blocks = ni->allocated_size >> 9; if (!ctx->posix_nlink) stbuf->st_nlink = 1; /* Make find(1) work */ } } else { /* Regular or Interix (INTX) file. */ stbuf->st_mode = S_IFREG; stbuf->st_size = ni->data_size; #ifdef HAVE_SETXATTR /* extended attributes interface required */ /* * return data size rounded to next 512 byte boundary for * encrypted files to include padding required for decryption * also include 2 bytes for padding info */ if (ctx->efs_raw && (ni->flags & FILE_ATTR_ENCRYPTED) && ni->data_size) stbuf->st_size = ((ni->data_size + 511) & ~511) + 2; #endif /* HAVE_SETXATTR */ /* * Temporary fix to make ActiveSync work via Samba 3.0. * See more on the ntfs-3g-devel list. */ stbuf->st_blocks = (ni->allocated_size + 511) >> 9; if (ni->flags & FILE_ATTR_SYSTEM || stream_name_len) { na = ntfs_attr_open(ni, AT_DATA, stream_name, stream_name_len); if (!na) { if (stream_name_len) { res = -ENOENT; goto exit; } else goto nodata; } if (stream_name_len) { stbuf->st_size = na->data_size; stbuf->st_blocks = na->allocated_size >> 9; } /* Check whether it's Interix FIFO or socket. */ if (!(ni->flags & FILE_ATTR_HIDDEN) && !stream_name_len) { /* FIFO. */ if (na->data_size == 0) stbuf->st_mode = S_IFIFO; /* Socket link. */ if (na->data_size == 1) stbuf->st_mode = S_IFSOCK; } #ifdef HAVE_SETXATTR /* extended attributes interface required */ /* encrypted named stream */ /* round size up to next 512 byte boundary */ if (ctx->efs_raw && stream_name_len && (na->data_flags & ATTR_IS_ENCRYPTED) && NAttrNonResident(na)) stbuf->st_size = ((na->data_size+511) & ~511)+2; #endif /* HAVE_SETXATTR */ /* * Check whether it's Interix symbolic link, block or * character device. */ if ((u64)na->data_size <= sizeof(INTX_FILE_TYPES) + sizeof(ntfschar) * PATH_MAX && (u64)na->data_size > sizeof(INTX_FILE_TYPES) && !stream_name_len) { INTX_FILE *intx_file; intx_file = ntfs_malloc(na->data_size); if (!intx_file) { res = -errno; ntfs_attr_close(na); goto exit; } if (ntfs_attr_pread(na, 0, na->data_size, intx_file) != na->data_size) { res = -errno; free(intx_file); ntfs_attr_close(na); goto exit; } if (intx_file->magic == INTX_BLOCK_DEVICE && na->data_size == offsetof( INTX_FILE, device_end)) { stbuf->st_mode = S_IFBLK; stbuf->st_rdev = makedev(le64_to_cpu( intx_file->major), le64_to_cpu( intx_file->minor)); } if (intx_file->magic == INTX_CHARACTER_DEVICE && na->data_size == offsetof( INTX_FILE, device_end)) { stbuf->st_mode = S_IFCHR; stbuf->st_rdev = makedev(le64_to_cpu( intx_file->major), le64_to_cpu( intx_file->minor)); } if (intx_file->magic == INTX_SYMBOLIC_LINK) { char *target = NULL; int len; /* st_size should be set to length of * symlink target as multibyte string */ len = ntfs_ucstombs( intx_file->target, (na->data_size - offsetof(INTX_FILE, target)) / sizeof(ntfschar), &target, 0); if (len < 0) { res = -errno; free(intx_file); ntfs_attr_close(na); goto exit; } free(target); stbuf->st_mode = S_IFLNK; stbuf->st_size = len; } free(intx_file); } ntfs_attr_close(na); } stbuf->st_mode |= (0777 & ~ctx->fmask); } #ifndef DISABLE_PLUGINS ok: #endif /* DISABLE_PLUGINS */ if (withusermapping) { if (ntfs_get_owner_mode(&security,ni,stbuf) < 0) set_fuse_error(&res); } else { stbuf->st_uid = ctx->uid; stbuf->st_gid = ctx->gid; } if (S_ISLNK(stbuf->st_mode)) stbuf->st_mode |= 0777; nodata : stbuf->st_ino = ni->mft_no; #ifdef HAVE_STRUCT_STAT_ST_ATIMESPEC stbuf->st_atimespec = ntfs2timespec(ni->last_access_time); stbuf->st_ctimespec = ntfs2timespec(ni->last_mft_change_time); stbuf->st_mtimespec = ntfs2timespec(ni->last_data_change_time); #elif defined(HAVE_STRUCT_STAT_ST_ATIM) stbuf->st_atim = ntfs2timespec(ni->last_access_time); stbuf->st_ctim = ntfs2timespec(ni->last_mft_change_time); stbuf->st_mtim = ntfs2timespec(ni->last_data_change_time); #elif defined(HAVE_STRUCT_STAT_ST_ATIMENSEC) { struct timespec ts; ts = ntfs2timespec(ni->last_access_time); stbuf->st_atime = ts.tv_sec; stbuf->st_atimensec = ts.tv_nsec; ts = ntfs2timespec(ni->last_mft_change_time); stbuf->st_ctime = ts.tv_sec; stbuf->st_ctimensec = ts.tv_nsec; ts = ntfs2timespec(ni->last_data_change_time); stbuf->st_mtime = ts.tv_sec; stbuf->st_mtimensec = ts.tv_nsec; } #else #warning "No known way to set nanoseconds in struct stat !" { struct timespec ts; ts = ntfs2timespec(ni->last_access_time); stbuf->st_atime = ts.tv_sec; ts = ntfs2timespec(ni->last_mft_change_time); stbuf->st_ctime = ts.tv_sec; ts = ntfs2timespec(ni->last_data_change_time); stbuf->st_mtime = ts.tv_sec; } #endif exit: if (ntfs_inode_close(ni)) set_fuse_error(&res); free(path); if (stream_name_len) free(stream_name); return res; } #ifndef DISABLE_PLUGINS /* * Get the link defined by a junction or symlink * (internal plugin) */ static int junction_readlink(ntfs_inode *ni, const REPARSE_POINT *reparse __attribute__((unused)), char **pbuf) { int res; le32 tag; int lth; errno = 0; res = 0; *pbuf = ntfs_make_symlink(ni, ctx->abs_mnt_point); if (!*pbuf) { if (errno == EOPNOTSUPP) { *pbuf = (char*)ntfs_malloc(ntfs_bad_reparse_lth + 1); if (*pbuf) { if (reparse) tag = reparse->reparse_tag; else tag = const_cpu_to_le32(0); lth = snprintf(*pbuf, ntfs_bad_reparse_lth + 1, ntfs_bad_reparse, (long)le32_to_cpu(tag)); if (lth != ntfs_bad_reparse_lth) { free(*pbuf); *pbuf = (char*)NULL; res = -errno; } } else res = -ENOMEM; } else res = -errno; } return (res); } #endif /* DISABLE_PLUGINS */ static int ntfs_fuse_readlink(const char *org_path, char *buf, size_t buf_size) { char *path = NULL; ntfschar *stream_name; ntfs_inode *ni = NULL; ntfs_attr *na = NULL; INTX_FILE *intx_file = NULL; int stream_name_len, res = 0; REPARSE_POINT *reparse; le32 tag; int lth; /* Get inode. */ stream_name_len = ntfs_fuse_parse_path(org_path, &path, &stream_name); if (stream_name_len < 0) return stream_name_len; if (stream_name_len > 0) { res = -EINVAL; goto exit; } ni = ntfs_pathname_to_inode(ctx->vol, NULL, path); if (!ni) { res = -errno; goto exit; } /* * Reparse point : analyze as a junction point */ if (ni->flags & FILE_ATTR_REPARSE_POINT) { #ifndef DISABLE_PLUGINS char *gotlink; const plugin_operations_t *ops; gotlink = (char*)NULL; res = CALL_REPARSE_PLUGIN(ni, readlink, &gotlink); if (gotlink) { strncpy(buf, gotlink, buf_size); free(gotlink); res = 0; } else { errno = EOPNOTSUPP; res = -EOPNOTSUPP; } #else /* DISABLE_PLUGINS */ char *target; errno = 0; res = 0; target = ntfs_make_symlink(ni, ctx->abs_mnt_point); if (target) { strncpy(buf,target,buf_size); free(target); } else res = -errno; #endif /* DISABLE_PLUGINS */ if (res == -EOPNOTSUPP) { reparse = ntfs_get_reparse_point(ni); if (reparse) { tag = reparse->reparse_tag; free(reparse); } else tag = const_cpu_to_le32(0); lth = snprintf(buf, ntfs_bad_reparse_lth + 1, ntfs_bad_reparse, (long)le32_to_cpu(tag)); res = 0; if (lth != ntfs_bad_reparse_lth) res = -errno; } goto exit; } /* Sanity checks. */ if (!(ni->flags & FILE_ATTR_SYSTEM)) { res = -EINVAL; goto exit; } na = ntfs_attr_open(ni, AT_DATA, AT_UNNAMED, 0); if (!na) { res = -errno; goto exit; } if ((size_t)na->data_size <= sizeof(INTX_FILE_TYPES)) { res = -EINVAL; goto exit; } if ((size_t)na->data_size > sizeof(INTX_FILE_TYPES) + sizeof(ntfschar) * PATH_MAX) { res = -ENAMETOOLONG; goto exit; } /* Receive file content. */ intx_file = ntfs_malloc(na->data_size); if (!intx_file) { res = -errno; goto exit; } if (ntfs_attr_pread(na, 0, na->data_size, intx_file) != na->data_size) { res = -errno; goto exit; } /* Sanity check. */ if (intx_file->magic != INTX_SYMBOLIC_LINK) { res = -EINVAL; goto exit; } /* Convert link from unicode to local encoding. */ if (ntfs_ucstombs(intx_file->target, (na->data_size - offsetof(INTX_FILE, target)) / sizeof(ntfschar), &buf, buf_size) < 0) { res = -errno; goto exit; } exit: if (intx_file) free(intx_file); if (na) ntfs_attr_close(na); if (ntfs_inode_close(ni)) set_fuse_error(&res); free(path); if (stream_name_len) free(stream_name); return res; } static int ntfs_fuse_filler(ntfs_fuse_fill_context_t *fill_ctx, const ntfschar *name, const int name_len, const int name_type, const s64 pos __attribute__((unused)), const MFT_REF mref, const unsigned dt_type __attribute__((unused))) { char *filename = NULL; int ret = 0; int filenamelen = -1; if (name_type == FILE_NAME_DOS) return 0; if ((filenamelen = ntfs_ucstombs(name, name_len, &filename, 0)) < 0) { ntfs_log_perror("Filename decoding failed (inode %llu)", (unsigned long long)MREF(mref)); return -1; } if (ntfs_fuse_is_named_data_stream(filename)) { ntfs_log_error("Unable to access '%s' (inode %llu) with " "current named streams access interface.\n", filename, (unsigned long long)MREF(mref)); free(filename); return 0; } else { struct stat st = { .st_ino = MREF(mref) }; #ifndef DISABLE_PLUGINS ntfs_inode *ni; #endif /* DISABLE_PLUGINS */ switch (dt_type) { case NTFS_DT_DIR : st.st_mode = S_IFDIR | (0777 & ~ctx->dmask); break; case NTFS_DT_LNK : st.st_mode = S_IFLNK | 0777; break; case NTFS_DT_FIFO : st.st_mode = S_IFIFO; break; case NTFS_DT_SOCK : st.st_mode = S_IFSOCK; break; case NTFS_DT_BLK : st.st_mode = S_IFBLK; break; case NTFS_DT_CHR : st.st_mode = S_IFCHR; break; case NTFS_DT_REPARSE : st.st_mode = S_IFLNK | 0777; /* default */ #ifndef DISABLE_PLUGINS /* get emulated type from plugin if available */ ni = ntfs_inode_open(ctx->vol, mref); if (ni && (ni->flags & FILE_ATTR_REPARSE_POINT)) { const plugin_operations_t *ops; REPARSE_POINT *reparse; int res; res = CALL_REPARSE_PLUGIN(ni, getattr, &st); if (!res) apply_umask(&st); else st.st_mode = S_IFLNK; } if (ni) ntfs_inode_close(ni); #endif /* DISABLE_PLUGINS */ break; default : /* unexpected types shown as plain files */ case NTFS_DT_REG : st.st_mode = S_IFREG | (0777 & ~ctx->fmask); break; } #if defined(__APPLE__) || defined(__DARWIN__) /* * Returning file names larger than MAXNAMLEN (255) bytes * causes Darwin/Mac OS X to bug out and skip the entry. */ if (filenamelen > MAXNAMLEN) { ntfs_log_debug("Truncating %d byte filename to " "%d bytes.\n", filenamelen, MAXNAMLEN); ntfs_log_debug(" before: '%s'\n", filename); memset(filename + MAXNAMLEN, 0, filenamelen - MAXNAMLEN); ntfs_log_debug(" after: '%s'\n", filename); } #elif defined(__sun) && defined (__SVR4) /* * Returning file names larger than MAXNAMELEN (256) bytes * causes Solaris/Illumos to return an I/O error from the system * call. * However we also need space for a terminating NULL, or user * space tools will bug out since they expect a NULL terminator. * Effectively the maximum length of a file name is MAXNAMELEN - * 1 (255). */ if (filenamelen > (MAXNAMELEN - 1)) { ntfs_log_debug("Truncating %d byte filename to %d " "bytes.\n", filenamelen, MAXNAMELEN - 1); ntfs_log_debug(" before: '%s'\n", filename); memset(&filename[MAXNAMELEN - 1], 0, filenamelen - (MAXNAMELEN - 1)); ntfs_log_debug(" after: '%s'\n", filename); } #endif /* defined(__APPLE__) || defined(__DARWIN__), ... */ ret = fill_ctx->filler(fill_ctx->buf, filename, &st, 0); } free(filename); return ret; } #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) static int ntfs_fuse_opendir(const char *path, struct fuse_file_info *fi) { int res = 0; ntfs_inode *ni; int accesstype; struct SECURITY_CONTEXT security; if (ntfs_fuse_is_named_data_stream(path)) return -EINVAL; /* n/a for named data streams. */ ni = ntfs_pathname_to_inode(ctx->vol, NULL, path); if (ni) { if (ntfs_fuse_fill_security_context(&security)) { if (fi->flags & O_WRONLY) accesstype = S_IWRITE; else if (fi->flags & O_RDWR) accesstype = S_IWRITE | S_IREAD; else accesstype = S_IREAD; /* * directory must be searchable * and requested access be allowed */ if (!strcmp(path,"/") ? !ntfs_allowed_dir_access(&security, path, ni, ni, accesstype | S_IEXEC) : !ntfs_allowed_dir_access(&security, path, (ntfs_inode*)NULL, ni, S_IEXEC) || !ntfs_allowed_access(&security, ni,accesstype)) res = -EACCES; } if (ni->flags & FILE_ATTR_REPARSE_POINT) { #ifndef DISABLE_PLUGINS const plugin_operations_t *ops; REPARSE_POINT *reparse; fi->fh = 0; res = CALL_REPARSE_PLUGIN(ni, opendir, fi); #else /* DISABLE_PLUGINS */ res = -EOPNOTSUPP; #endif /* DISABLE_PLUGINS */ } if (ntfs_inode_close(ni)) set_fuse_error(&res); } else res = -errno; return res; } #endif static int ntfs_fuse_readdir(const char *path, void *buf, fuse_fill_dir_t filler, off_t offset __attribute__((unused)), struct fuse_file_info *fi __attribute__((unused))) { ntfs_fuse_fill_context_t fill_ctx; ntfs_inode *ni; s64 pos = 0; int err = 0; fill_ctx.filler = filler; fill_ctx.buf = buf; ni = ntfs_pathname_to_inode(ctx->vol, NULL, path); if (!ni) return -errno; if (ni->flags & FILE_ATTR_REPARSE_POINT) { #ifndef DISABLE_PLUGINS const plugin_operations_t *ops; REPARSE_POINT *reparse; err = CALL_REPARSE_PLUGIN(ni, readdir, &pos, &fill_ctx, (ntfs_filldir_t)ntfs_fuse_filler, fi); #else /* DISABLE_PLUGINS */ err = -EOPNOTSUPP; #endif /* DISABLE_PLUGINS */ } else { if (ntfs_readdir(ni, &pos, &fill_ctx, (ntfs_filldir_t)ntfs_fuse_filler)) err = -errno; } ntfs_fuse_update_times(ni, NTFS_UPDATE_ATIME); if (ntfs_inode_close(ni)) set_fuse_error(&err); return err; } static int ntfs_fuse_open(const char *org_path, #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) struct fuse_file_info *fi) #else struct fuse_file_info *fi __attribute__((unused))) #endif { ntfs_inode *ni; ntfs_attr *na = NULL; int res = 0; char *path = NULL; ntfschar *stream_name; int stream_name_len; #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) int accesstype; struct SECURITY_CONTEXT security; #endif stream_name_len = ntfs_fuse_parse_path(org_path, &path, &stream_name); if (stream_name_len < 0) return stream_name_len; ni = ntfs_pathname_to_inode(ctx->vol, NULL, path); if (ni) { if (!(ni->flags & FILE_ATTR_REPARSE_POINT)) { na = ntfs_attr_open(ni, AT_DATA, stream_name, stream_name_len); if (!na) { res = -errno; goto close; } } #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) if (ntfs_fuse_fill_security_context(&security)) { if (fi->flags & O_WRONLY) accesstype = S_IWRITE; else if (fi->flags & O_RDWR) accesstype = S_IWRITE | S_IREAD; else accesstype = S_IREAD; /* * directory must be searchable * and requested access allowed */ if (!ntfs_allowed_dir_access(&security, path,(ntfs_inode*)NULL,ni,S_IEXEC) || !ntfs_allowed_access(&security, ni,accesstype)) res = -EACCES; } #endif if (ni->flags & FILE_ATTR_REPARSE_POINT) { #ifndef DISABLE_PLUGINS const plugin_operations_t *ops; REPARSE_POINT *reparse; fi->fh = 0; res = CALL_REPARSE_PLUGIN(ni, open, fi); #else /* DISABLE_PLUGINS */ res = -EOPNOTSUPP; #endif /* DISABLE_PLUGINS */ goto close; } if ((res >= 0) && (fi->flags & (O_WRONLY | O_RDWR))) { /* mark a future need to compress the last chunk */ if (na->data_flags & ATTR_COMPRESSION_MASK) fi->fh |= CLOSE_COMPRESSED; #ifdef HAVE_SETXATTR /* extended attributes interface required */ /* mark a future need to fixup encrypted inode */ if (ctx->efs_raw && !(na->data_flags & ATTR_IS_ENCRYPTED) && (ni->flags & FILE_ATTR_ENCRYPTED)) fi->fh |= CLOSE_ENCRYPTED; #endif /* HAVE_SETXATTR */ /* mark a future need to update the mtime */ if (ctx->dmtime) fi->fh |= CLOSE_DMTIME; /* deny opening metadata files for writing */ if (ni->mft_no < FILE_first_user) res = -EPERM; } ntfs_attr_close(na); close: if (ntfs_inode_close(ni)) set_fuse_error(&res); } else res = -errno; free(path); if (stream_name_len) free(stream_name); return res; } static int ntfs_fuse_read(const char *org_path, char *buf, size_t size, off_t offset, struct fuse_file_info *fi __attribute__((unused))) { ntfs_inode *ni = NULL; ntfs_attr *na = NULL; char *path = NULL; ntfschar *stream_name; int stream_name_len, res; s64 total = 0; s64 max_read; if (!size) return 0; stream_name_len = ntfs_fuse_parse_path(org_path, &path, &stream_name); if (stream_name_len < 0) return stream_name_len; ni = ntfs_pathname_to_inode(ctx->vol, NULL, path); if (!ni) { res = -errno; goto exit; } if (ni->flags & FILE_ATTR_REPARSE_POINT) { #ifndef DISABLE_PLUGINS const plugin_operations_t *ops; REPARSE_POINT *reparse; if (stream_name_len || !fi) { res = -EINVAL; goto exit; } res = CALL_REPARSE_PLUGIN(ni, read, buf, size, offset, fi); if (res >= 0) { goto stamps; } #else /* DISABLE_PLUGINS */ res = -EOPNOTSUPP; #endif /* DISABLE_PLUGINS */ goto exit; } na = ntfs_attr_open(ni, AT_DATA, stream_name, stream_name_len); if (!na) { res = -errno; goto exit; } max_read = na->data_size; #ifdef HAVE_SETXATTR /* extended attributes interface required */ /* limit reads at next 512 byte boundary for encrypted attributes */ if (ctx->efs_raw && max_read && (na->data_flags & ATTR_IS_ENCRYPTED) && NAttrNonResident(na)) { max_read = ((na->data_size+511) & ~511) + 2; } #endif /* HAVE_SETXATTR */ if (offset + (off_t)size > max_read) { if (max_read < offset) goto ok; size = max_read - offset; } while (size > 0) { s64 ret = ntfs_attr_pread(na, offset, size, buf + total); if (ret != (s64)size) ntfs_log_perror("ntfs_attr_pread error reading '%s' at " "offset %lld: %lld <> %lld", org_path, (long long)offset, (long long)size, (long long)ret); if (ret <= 0 || ret > (s64)size) { res = (ret < 0) ? -errno : -EIO; goto exit; } size -= ret; offset += ret; total += ret; } ok: res = total; #ifndef DISABLE_PLUGINS stamps: #endif /* DISABLE_PLUGINS */ ntfs_fuse_update_times(ni, NTFS_UPDATE_ATIME); exit: if (na) ntfs_attr_close(na); if (ntfs_inode_close(ni)) set_fuse_error(&res); free(path); if (stream_name_len) free(stream_name); return res; } static int ntfs_fuse_write(const char *org_path, const char *buf, size_t size, off_t offset, struct fuse_file_info *fi __attribute__((unused))) { ntfs_inode *ni = NULL; ntfs_attr *na = NULL; char *path = NULL; ntfschar *stream_name; int stream_name_len, res, total = 0; stream_name_len = ntfs_fuse_parse_path(org_path, &path, &stream_name); if (stream_name_len < 0) { res = stream_name_len; goto out; } ni = ntfs_pathname_to_inode(ctx->vol, NULL, path); if (!ni) { res = -errno; goto exit; } if (ni->flags & FILE_ATTR_REPARSE_POINT) { #ifndef DISABLE_PLUGINS const plugin_operations_t *ops; REPARSE_POINT *reparse; if (stream_name_len || !fi) { res = -EINVAL; goto exit; } res = CALL_REPARSE_PLUGIN(ni, write, buf, size, offset, fi); if (res >= 0) { goto stamps; } #else /* DISABLE_PLUGINS */ res = -EOPNOTSUPP; #endif /* DISABLE_PLUGINS */ goto exit; } na = ntfs_attr_open(ni, AT_DATA, stream_name, stream_name_len); if (!na) { res = -errno; goto exit; } while (size) { s64 ret = ntfs_attr_pwrite(na, offset, size, buf + total); if (ret <= 0) { res = -errno; goto exit; } size -= ret; offset += ret; total += ret; } res = total; #ifndef DISABLE_PLUGINS stamps: #endif /* DISABLE_PLUGINS */ if ((res > 0) && (!ctx->dmtime || (sle64_to_cpu(ntfs_current_time()) - sle64_to_cpu(ni->last_data_change_time)) > ctx->dmtime)) ntfs_fuse_update_times(ni, NTFS_UPDATE_MCTIME); exit: if (na) ntfs_attr_close(na); if (res > 0) set_archive(ni); if (ntfs_inode_close(ni)) set_fuse_error(&res); free(path); if (stream_name_len) free(stream_name); out: return res; } static int ntfs_fuse_release(const char *org_path, struct fuse_file_info *fi) { ntfs_inode *ni = NULL; ntfs_attr *na = NULL; char *path = NULL; ntfschar *stream_name; int stream_name_len, res; if (!fi) { res = -EINVAL; goto out; } /* Only for marked descriptors there is something to do */ if (!fi->fh) { res = 0; goto out; } stream_name_len = ntfs_fuse_parse_path(org_path, &path, &stream_name); if (stream_name_len < 0) { res = stream_name_len; goto out; } ni = ntfs_pathname_to_inode(ctx->vol, NULL, path); if (!ni) { res = -errno; goto exit; } if (ni->flags & FILE_ATTR_REPARSE_POINT) { #ifndef DISABLE_PLUGINS const plugin_operations_t *ops; REPARSE_POINT *reparse; if (stream_name_len) { res = -EINVAL; goto exit; } res = CALL_REPARSE_PLUGIN(ni, release, fi); if (!res) { goto stamps; } #else /* DISABLE_PLUGINS */ /* Assume release() was not needed */ res = 0; #endif /* DISABLE_PLUGINS */ goto exit; } na = ntfs_attr_open(ni, AT_DATA, stream_name, stream_name_len); if (!na) { res = -errno; goto exit; } res = 0; if (fi->fh & CLOSE_COMPRESSED) res = ntfs_attr_pclose(na); #ifdef HAVE_SETXATTR /* extended attributes interface required */ if (fi->fh & CLOSE_ENCRYPTED) res = ntfs_efs_fixup_attribute(NULL, na); #endif /* HAVE_SETXATTR */ #ifndef DISABLE_PLUGINS stamps: #endif /* DISABLE_PLUGINS */ if (fi->fh & CLOSE_DMTIME) ntfs_inode_update_times(ni,NTFS_UPDATE_MCTIME); exit: if (na) ntfs_attr_close(na); if (ntfs_inode_close(ni)) set_fuse_error(&res); free(path); if (stream_name_len) free(stream_name); out: return res; } /* * Common part for truncate() and ftruncate() */ static int ntfs_fuse_trunc(const char *org_path, off_t size, #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) BOOL chkwrite) #else BOOL chkwrite __attribute__((unused))) #endif { ntfs_inode *ni = NULL; ntfs_attr *na = NULL; int res; char *path = NULL; ntfschar *stream_name; int stream_name_len; s64 oldsize; #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) struct SECURITY_CONTEXT security; #endif stream_name_len = ntfs_fuse_parse_path(org_path, &path, &stream_name); if (stream_name_len < 0) return stream_name_len; ni = ntfs_pathname_to_inode(ctx->vol, NULL, path); if (!ni) goto exit; /* deny truncating metadata files */ if (ni->mft_no < FILE_first_user) { errno = EPERM; goto exit; } if (ni->flags & FILE_ATTR_REPARSE_POINT) { #ifndef DISABLE_PLUGINS const plugin_operations_t *ops; REPARSE_POINT *reparse; if (stream_name_len) { res = -EINVAL; goto exit; } res = CALL_REPARSE_PLUGIN(ni, truncate, size); if (!res) { set_archive(ni); goto stamps; } #else /* DISABLE_PLUGINS */ res = -EOPNOTSUPP; #endif /* DISABLE_PLUGINS */ goto exit; } na = ntfs_attr_open(ni, AT_DATA, stream_name, stream_name_len); if (!na) goto exit; #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) /* * JPA deny truncation if cannot search in parent directory * or cannot write to file (already checked for ftruncate()) */ if (ntfs_fuse_fill_security_context(&security) && (!ntfs_allowed_dir_access(&security, path, (ntfs_inode*)NULL, ni, S_IEXEC) || (chkwrite && !ntfs_allowed_access(&security, ni, S_IWRITE)))) { errno = EACCES; goto exit; } #endif /* * For compressed files, upsizing is done by inserting a final * zero, which is optimized as creating a hole when possible. */ oldsize = na->data_size; if ((na->data_flags & ATTR_COMPRESSION_MASK) && (size > na->initialized_size)) { char zero = 0; if (ntfs_attr_pwrite(na, size - 1, 1, &zero) <= 0) goto exit; } else if (ntfs_attr_truncate(na, size)) goto exit; if (oldsize != size) set_archive(ni); #ifndef DISABLE_PLUGINS stamps: #endif /* DISABLE_PLUGINS */ ntfs_fuse_update_times(ni, NTFS_UPDATE_MCTIME); errno = 0; exit: res = -errno; ntfs_attr_close(na); if (ntfs_inode_close(ni)) set_fuse_error(&res); free(path); if (stream_name_len) free(stream_name); return res; } static int ntfs_fuse_truncate(const char *org_path, off_t size) { return ntfs_fuse_trunc(org_path, size, TRUE); } static int ntfs_fuse_ftruncate(const char *org_path, off_t size, struct fuse_file_info *fi __attribute__((unused))) { /* * in ->ftruncate() the file handle is guaranteed * to have been opened for write. */ return (ntfs_fuse_trunc(org_path, size, FALSE)); } static int ntfs_fuse_chmod(const char *path, mode_t mode) { int res = 0; ntfs_inode *ni; struct SECURITY_CONTEXT security; if (ntfs_fuse_is_named_data_stream(path)) return -EINVAL; /* n/a for named data streams. */ /* * Return unsupported if no user mapping has been defined * or enforcing Windows-type inheritance */ if (ctx->inherit || !ntfs_fuse_fill_security_context(&security)) { if (ctx->silent) res = 0; else res = -EOPNOTSUPP; } else { #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) /* parent directory must be executable */ if (ntfs_allowed_dir_access(&security,path, (ntfs_inode*)NULL,(ntfs_inode*)NULL,S_IEXEC)) { #endif ni = ntfs_pathname_to_inode(ctx->vol, NULL, path); if (!ni) res = -errno; else { if (ntfs_set_mode(&security,ni,mode)) res = -errno; else ntfs_fuse_update_times(ni, NTFS_UPDATE_CTIME); NInoSetDirty(ni); if (ntfs_inode_close(ni)) set_fuse_error(&res); } #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) } else res = -errno; #endif } return res; } static int ntfs_fuse_chown(const char *path, uid_t uid, gid_t gid) { ntfs_inode *ni; int res; struct SECURITY_CONTEXT security; if (ntfs_fuse_is_named_data_stream(path)) return -EINVAL; /* n/a for named data streams. */ /* * Return unsupported if no user mapping has been defined * or enforcing Windows-type inheritance */ if (ctx->inherit || !ntfs_fuse_fill_security_context(&security)) { if (ctx->silent) return 0; if (uid == ctx->uid && gid == ctx->gid) return 0; return -EOPNOTSUPP; } else { res = 0; if (((int)uid != -1) || ((int)gid != -1)) { #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) /* parent directory must be executable */ if (ntfs_allowed_dir_access(&security,path, (ntfs_inode*)NULL,(ntfs_inode*)NULL,S_IEXEC)) { #endif ni = ntfs_pathname_to_inode(ctx->vol, NULL, path); if (!ni) res = -errno; else { if (ntfs_set_owner(&security, ni,uid,gid)) res = -errno; else ntfs_fuse_update_times(ni, NTFS_UPDATE_CTIME); if (ntfs_inode_close(ni)) set_fuse_error(&res); } #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) } else res = -errno; #endif } } return (res); } #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) static int ntfs_fuse_access(const char *path, int type) { int res = 0; int mode; ntfs_inode *ni; struct SECURITY_CONTEXT security; if (ntfs_fuse_is_named_data_stream(path)) return -EINVAL; /* n/a for named data streams. */ /* JPA return unsupported if no user mapping has been defined */ if (!ntfs_fuse_fill_security_context(&security)) { if (ctx->silent) res = 0; else res = -EOPNOTSUPP; } else { /* parent directory must be seachable */ if (ntfs_allowed_dir_access(&security,path,(ntfs_inode*)NULL, (ntfs_inode*)NULL,S_IEXEC)) { ni = ntfs_pathname_to_inode(ctx->vol, NULL, path); if (!ni) { res = -errno; } else { mode = 0; if (type & (X_OK | W_OK | R_OK)) { if (type & X_OK) mode += S_IEXEC; if (type & W_OK) mode += S_IWRITE; if (type & R_OK) mode += S_IREAD; if (!ntfs_allowed_access(&security, ni, mode)) res = -errno; } if (ntfs_inode_close(ni)) set_fuse_error(&res); } } else res = -errno; } return (res); } #endif static int ntfs_fuse_create(const char *org_path, mode_t typemode, dev_t dev, const char *target, struct fuse_file_info *fi) { char *name; ntfschar *uname = NULL, *utarget = NULL; ntfs_inode *dir_ni = NULL, *ni; char *dir_path; le32 securid; char *path = NULL; gid_t gid; mode_t dsetgid; ntfschar *stream_name; int stream_name_len; mode_t type = typemode & ~07777; mode_t perm; struct SECURITY_CONTEXT security; int res = 0, uname_len, utarget_len; dir_path = strdup(org_path); if (!dir_path) return -errno; /* Generate unicode filename. */ name = strrchr(dir_path, '/'); name++; uname_len = ntfs_mbstoucs(name, &uname); if ((uname_len < 0) || (ctx->windows_names && ntfs_forbidden_names(ctx->vol,uname,uname_len,TRUE))) { res = -errno; goto exit; } stream_name_len = ntfs_fuse_parse_path(org_path, &path, &stream_name); /* stream name validity has been checked previously */ if (stream_name_len < 0) { res = stream_name_len; goto exit; } /* Open parent directory. */ *--name = 0; dir_ni = ntfs_pathname_to_inode(ctx->vol, NULL, dir_path); /* Deny creating files in $Extend */ if (!dir_ni || (dir_ni->mft_no == FILE_Extend)) { free(path); res = -errno; if (dir_ni) res = -EPERM; goto exit; } #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) /* make sure parent directory is writeable and executable */ if (!ntfs_fuse_fill_security_context(&security) || ntfs_allowed_create(&security, dir_ni, &gid, &dsetgid)) { #else ntfs_fuse_fill_security_context(&security); ntfs_allowed_create(&security, dir_ni, &gid, &dsetgid); #endif if (S_ISDIR(type)) perm = (typemode & ~ctx->dmask & 0777) | (dsetgid & S_ISGID); else if ((ctx->special_files == NTFS_FILES_WSL) && S_ISLNK(type)) perm = typemode | 0777; else perm = typemode & ~ctx->fmask & 0777; /* * Try to get a security id available for * file creation (from inheritance or argument). * This is not possible for NTFS 1.x, and we will * have to build a security attribute later. */ if (!ctx->security.mapping[MAPUSERS]) securid = const_cpu_to_le32(0); else if (ctx->inherit) securid = ntfs_inherited_id(&security, dir_ni, S_ISDIR(type)); else #if POSIXACLS securid = ntfs_alloc_securid(&security, security.uid, gid, dir_ni, perm, S_ISDIR(type)); #else securid = ntfs_alloc_securid(&security, security.uid, gid, perm & ~security.umask, S_ISDIR(type)); #endif /* Create object specified in @type. */ if (dir_ni->flags & FILE_ATTR_REPARSE_POINT) { #ifndef DISABLE_PLUGINS const plugin_operations_t *ops; REPARSE_POINT *reparse; reparse = (REPARSE_POINT*)NULL; ops = select_reparse_plugin(ctx, dir_ni, &reparse); if (ops && ops->create) { ni = (*ops->create)(dir_ni, reparse, securid, uname, uname_len, type); } else { ni = (ntfs_inode*)NULL; errno = EOPNOTSUPP; } free(reparse); #else /* DISABLE_PLUGINS */ errno = EOPNOTSUPP; #endif /* DISABLE_PLUGINS */ } else { switch (type) { case S_IFCHR: case S_IFBLK: ni = ntfs_create_device(dir_ni, securid, uname, uname_len, type, dev); break; case S_IFLNK: utarget_len = ntfs_mbstoucs(target, &utarget); if (utarget_len < 0) { res = -errno; goto exit; } ni = ntfs_create_symlink(dir_ni, securid, uname, uname_len, utarget, utarget_len); break; default: ni = ntfs_create(dir_ni, securid, uname, uname_len, type); break; } } if (ni) { /* * set the security attribute if a security id * could not be allocated (eg NTFS 1.x) */ if (ctx->security.mapping[MAPUSERS]) { #if POSIXACLS if (!securid && ntfs_set_inherited_posix(&security, ni, security.uid, gid, dir_ni, perm) < 0) set_fuse_error(&res); #else if (!securid && ntfs_set_owner_mode(&security, ni, security.uid, gid, perm & ~security.umask) < 0) set_fuse_error(&res); #endif } set_archive(ni); /* mark a need to compress the end of file */ if (fi && (ni->flags & FILE_ATTR_COMPRESSED)) { fi->fh |= CLOSE_COMPRESSED; } #ifdef HAVE_SETXATTR /* extended attributes interface required */ /* mark a future need to fixup encrypted inode */ if (fi && ctx->efs_raw && (ni->flags & FILE_ATTR_ENCRYPTED)) fi->fh |= CLOSE_ENCRYPTED; #endif /* HAVE_SETXATTR */ /* mark a need to update the mtime */ if (fi && ctx->dmtime) fi->fh |= CLOSE_DMTIME; NInoSetDirty(ni); /* * closing ni requires access to dir_ni to * synchronize the index, avoid double opening. */ if (ntfs_inode_close_in_dir(ni, dir_ni)) set_fuse_error(&res); ntfs_fuse_update_times(dir_ni, NTFS_UPDATE_MCTIME); } else res = -errno; #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) } else res = -errno; #endif free(path); exit: free(uname); if (ntfs_inode_close(dir_ni)) set_fuse_error(&res); if (utarget) free(utarget); free(dir_path); return res; } static int ntfs_fuse_create_stream(const char *path, ntfschar *stream_name, const int stream_name_len, struct fuse_file_info *fi) { ntfs_inode *ni; int res = 0; ni = ntfs_pathname_to_inode(ctx->vol, NULL, path); if (!ni) { res = -errno; if (res == -ENOENT) { /* * If such file does not exist, create it and try once * again to add stream to it. * Note : no fuse_file_info for creation of main file */ res = ntfs_fuse_create(path, S_IFREG, 0, NULL, (struct fuse_file_info*)NULL); if (!res) return ntfs_fuse_create_stream(path, stream_name, stream_name_len,fi); else res = -errno; } return res; } if (ntfs_attr_add(ni, AT_DATA, stream_name, stream_name_len, NULL, 0)) res = -errno; else set_archive(ni); if ((res >= 0) && fi && (fi->flags & (O_WRONLY | O_RDWR))) { /* mark a future need to compress the last block */ if (ni->flags & FILE_ATTR_COMPRESSED) fi->fh |= CLOSE_COMPRESSED; #ifdef HAVE_SETXATTR /* extended attributes interface required */ /* mark a future need to fixup encrypted inode */ if (ctx->efs_raw && (ni->flags & FILE_ATTR_ENCRYPTED)) fi->fh |= CLOSE_ENCRYPTED; #endif /* HAVE_SETXATTR */ if (ctx->dmtime) fi->fh |= CLOSE_DMTIME; } if (ntfs_inode_close(ni)) set_fuse_error(&res); return res; } static int ntfs_fuse_mknod_common(const char *org_path, mode_t mode, dev_t dev, struct fuse_file_info *fi) { char *path = NULL; ntfschar *stream_name; int stream_name_len; int res = 0; stream_name_len = ntfs_fuse_parse_path(org_path, &path, &stream_name); if (stream_name_len < 0) return stream_name_len; if (stream_name_len && (!S_ISREG(mode) || (ctx->windows_names && ntfs_forbidden_names(ctx->vol,stream_name, stream_name_len, TRUE)))) { res = -EINVAL; goto exit; } if (!stream_name_len) res = ntfs_fuse_create(path, mode & (S_IFMT | 07777), dev, NULL,fi); else res = ntfs_fuse_create_stream(path, stream_name, stream_name_len,fi); exit: free(path); if (stream_name_len) free(stream_name); return res; } static int ntfs_fuse_mknod(const char *path, mode_t mode, dev_t dev) { return ntfs_fuse_mknod_common(path, mode, dev, (struct fuse_file_info*)NULL); } static int ntfs_fuse_create_file(const char *path, mode_t mode, struct fuse_file_info *fi) { return ntfs_fuse_mknod_common(path, mode, 0, fi); } static int ntfs_fuse_symlink(const char *to, const char *from) { if (ntfs_fuse_is_named_data_stream(from)) return -EINVAL; /* n/a for named data streams. */ return ntfs_fuse_create(from, S_IFLNK, 0, to, (struct fuse_file_info*)NULL); } static int ntfs_fuse_link(const char *old_path, const char *new_path) { char *name; ntfschar *uname = NULL; ntfs_inode *dir_ni = NULL, *ni; char *path; int res = 0, uname_len; #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) BOOL samedir; struct SECURITY_CONTEXT security; #endif if (ntfs_fuse_is_named_data_stream(old_path)) return -EINVAL; /* n/a for named data streams. */ if (ntfs_fuse_is_named_data_stream(new_path)) return -EINVAL; /* n/a for named data streams. */ path = strdup(new_path); if (!path) return -errno; /* Open file for which create hard link. */ ni = ntfs_pathname_to_inode(ctx->vol, NULL, old_path); if (!ni) { res = -errno; goto exit; } /* Generate unicode filename. */ name = strrchr(path, '/'); name++; uname_len = ntfs_mbstoucs(name, &uname); if ((uname_len < 0) || (ctx->windows_names && ntfs_forbidden_names(ctx->vol,uname,uname_len,TRUE))) { res = -errno; goto exit; } /* Open parent directory. */ *--name = 0; dir_ni = ntfs_pathname_to_inode(ctx->vol, NULL, path); if (!dir_ni) { res = -errno; goto exit; } #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) samedir = !strncmp(old_path, path, strlen(path)) && (old_path[strlen(path)] == '/'); /* JPA make sure the parent directories are writeable */ if (ntfs_fuse_fill_security_context(&security) && ((!samedir && !ntfs_allowed_dir_access(&security,old_path, (ntfs_inode*)NULL,ni,S_IWRITE + S_IEXEC)) || !ntfs_allowed_access(&security,dir_ni,S_IWRITE + S_IEXEC))) res = -EACCES; else #endif { if (dir_ni->flags & FILE_ATTR_REPARSE_POINT) { #ifndef DISABLE_PLUGINS const plugin_operations_t *ops; REPARSE_POINT *reparse; res = CALL_REPARSE_PLUGIN(dir_ni, link, ni, uname, uname_len); #else /* DISABLE_PLUGINS */ errno = EOPNOTSUPP; res = -errno; #endif /* DISABLE_PLUGINS */ if (res) goto exit; } else if (ntfs_link(ni, dir_ni, uname, uname_len)) { res = -errno; goto exit; } set_archive(ni); ntfs_fuse_update_times(ni, NTFS_UPDATE_CTIME); ntfs_fuse_update_times(dir_ni, NTFS_UPDATE_MCTIME); } exit: /* * Must close dir_ni first otherwise ntfs_inode_sync_file_name(ni) * may fail because ni may not be in parent's index on the disk yet. */ if (ntfs_inode_close(dir_ni)) set_fuse_error(&res); if (ntfs_inode_close(ni)) set_fuse_error(&res); free(uname); free(path); return res; } static int ntfs_fuse_rm(const char *org_path) { char *name; ntfschar *uname = NULL; ntfs_inode *dir_ni = NULL, *ni; char *path; int res = 0, uname_len; #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) struct SECURITY_CONTEXT security; #endif path = strdup(org_path); if (!path) return -errno; /* Open object for delete. */ ni = ntfs_pathname_to_inode(ctx->vol, NULL, path); if (!ni) { res = -errno; goto exit; } /* deny unlinking metadata files */ if (ni->mft_no < FILE_first_user) { errno = EPERM; res = -errno; goto exit; } /* Generate unicode filename. */ name = strrchr(path, '/'); name++; uname_len = ntfs_mbstoucs(name, &uname); if (uname_len < 0) { res = -errno; goto exit; } /* Open parent directory. */ *--name = 0; dir_ni = ntfs_pathname_to_inode(ctx->vol, NULL, path); /* deny unlinking metadata files from $Extend */ if (!dir_ni || (dir_ni->mft_no == FILE_Extend)) { res = -errno; if (dir_ni) res = -EPERM; goto exit; } #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) /* JPA deny unlinking if directory is not writable and executable */ if (!ntfs_fuse_fill_security_context(&security) || ntfs_allowed_dir_access(&security, org_path, dir_ni, ni, S_IEXEC + S_IWRITE + S_ISVTX)) { #endif if (dir_ni->flags & FILE_ATTR_REPARSE_POINT) { #ifndef DISABLE_PLUGINS const plugin_operations_t *ops; REPARSE_POINT *reparse; res = CALL_REPARSE_PLUGIN(dir_ni, unlink, org_path, ni, uname, uname_len); #else /* DISABLE_PLUGINS */ res = -EOPNOTSUPP; #endif /* DISABLE_PLUGINS */ } else if (ntfs_delete(ctx->vol, org_path, ni, dir_ni, uname, uname_len)) res = -errno; /* ntfs_delete() always closes ni and dir_ni */ ni = dir_ni = NULL; #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) } else res = -EACCES; #endif exit: if (ntfs_inode_close(dir_ni)) set_fuse_error(&res); if (ntfs_inode_close(ni)) set_fuse_error(&res); free(uname); free(path); return res; } static int ntfs_fuse_rm_stream(const char *path, ntfschar *stream_name, const int stream_name_len) { ntfs_inode *ni; int res = 0; ni = ntfs_pathname_to_inode(ctx->vol, NULL, path); if (!ni) return -errno; if (ntfs_attr_remove(ni, AT_DATA, stream_name, stream_name_len)) res = -errno; if (ntfs_inode_close(ni)) set_fuse_error(&res); return res; } static int ntfs_fuse_unlink(const char *org_path) { char *path = NULL; ntfschar *stream_name; int stream_name_len; int res = 0; #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) struct SECURITY_CONTEXT security; #endif stream_name_len = ntfs_fuse_parse_path(org_path, &path, &stream_name); if (stream_name_len < 0) return stream_name_len; if (!stream_name_len) res = ntfs_fuse_rm(path); else { #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) /* * JPA deny unlinking stream if directory is not * writable and executable (debatable) */ if (!ntfs_fuse_fill_security_context(&security) || ntfs_allowed_dir_access(&security, path, (ntfs_inode*)NULL, (ntfs_inode*)NULL, S_IEXEC + S_IWRITE + S_ISVTX)) res = ntfs_fuse_rm_stream(path, stream_name, stream_name_len); else res = -errno; #else res = ntfs_fuse_rm_stream(path, stream_name, stream_name_len); #endif } free(path); if (stream_name_len) free(stream_name); return res; } static int ntfs_fuse_safe_rename(const char *old_path, const char *new_path, const char *tmp) { int ret; ntfs_log_trace("Entering\n"); ret = ntfs_fuse_link(new_path, tmp); if (ret) return ret; ret = ntfs_fuse_unlink(new_path); if (!ret) { ret = ntfs_fuse_link(old_path, new_path); if (ret) goto restore; ret = ntfs_fuse_unlink(old_path); if (ret) { if (ntfs_fuse_unlink(new_path)) goto err; goto restore; } } goto cleanup; restore: if (ntfs_fuse_link(tmp, new_path)) { err: ntfs_log_perror("Rename failed. Existing file '%s' was renamed " "to '%s'", new_path, tmp); } else { cleanup: /* * Condition for this unlink has already been checked in * "ntfs_fuse_rename_existing_dest()", so it should never * fail (unless concurrent access to directories when fuse * is multithreaded) */ if (ntfs_fuse_unlink(tmp) < 0) ntfs_log_perror("Rename failed. Existing file '%s' still present " "as '%s'", new_path, tmp); } return ret; } static int ntfs_fuse_rename_existing_dest(const char *old_path, const char *new_path) { int ret, len; char *tmp; const char *ext = ".ntfs-3g-"; #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) struct SECURITY_CONTEXT security; #endif ntfs_log_trace("Entering\n"); len = strlen(new_path) + strlen(ext) + 10 + 1; /* wc(str(2^32)) + \0 */ tmp = ntfs_malloc(len); if (!tmp) return -errno; ret = snprintf(tmp, len, "%s%s%010d", new_path, ext, ++ntfs_sequence); if (ret != len - 1) { ntfs_log_error("snprintf failed: %d != %d\n", ret, len - 1); ret = -EOVERFLOW; } else { #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) /* * Make sure existing dest can be removed. * This is only needed if parent directory is * sticky, because in this situation condition * for unlinking is different from condition for * linking */ if (!ntfs_fuse_fill_security_context(&security) || ntfs_allowed_dir_access(&security, new_path, (ntfs_inode*)NULL, (ntfs_inode*)NULL, S_IEXEC + S_IWRITE + S_ISVTX)) ret = ntfs_fuse_safe_rename(old_path, new_path, tmp); else ret = -EACCES; #else ret = ntfs_fuse_safe_rename(old_path, new_path, tmp); #endif } free(tmp); return ret; } static int ntfs_fuse_rename(const char *old_path, const char *new_path) { int ret, stream_name_len; char *path = NULL; ntfschar *stream_name; ntfs_inode *ni; u64 inum; BOOL same; ntfs_log_debug("rename: old: '%s' new: '%s'\n", old_path, new_path); /* * FIXME: Rename should be atomic. */ stream_name_len = ntfs_fuse_parse_path(new_path, &path, &stream_name); if (stream_name_len < 0) return stream_name_len; ni = ntfs_pathname_to_inode(ctx->vol, NULL, path); if (ni) { ret = ntfs_check_empty_dir(ni); if (ret < 0) { ret = -errno; ntfs_inode_close(ni); goto out; } inum = ni->mft_no; if (ntfs_inode_close(ni)) { set_fuse_error(&ret); goto out; } free(path); path = (char*)NULL; if (stream_name_len) free(stream_name); /* silently ignore a rename to same inode */ stream_name_len = ntfs_fuse_parse_path(old_path, &path, &stream_name); if (stream_name_len < 0) return stream_name_len; ni = ntfs_pathname_to_inode(ctx->vol, NULL, path); if (ni) { same = ni->mft_no == inum; if (ntfs_inode_close(ni)) ret = -errno; else if (!same) ret = ntfs_fuse_rename_existing_dest( old_path, new_path); } else ret = -errno; goto out; } ret = ntfs_fuse_link(old_path, new_path); if (ret) goto out; ret = ntfs_fuse_unlink(old_path); if (ret) ntfs_fuse_unlink(new_path); out: free(path); if (stream_name_len) free(stream_name); return ret; } static int ntfs_fuse_mkdir(const char *path, mode_t mode) { if (ntfs_fuse_is_named_data_stream(path)) return -EINVAL; /* n/a for named data streams. */ return ntfs_fuse_create(path, S_IFDIR | (mode & 07777), 0, NULL, (struct fuse_file_info*)NULL); } static int ntfs_fuse_rmdir(const char *path) { if (ntfs_fuse_is_named_data_stream(path)) return -EINVAL; /* n/a for named data streams. */ return ntfs_fuse_rm(path); } #ifdef HAVE_UTIMENSAT static int ntfs_fuse_utimens(const char *path, const struct timespec tv[2]) { ntfs_inode *ni; int res = 0; #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) struct SECURITY_CONTEXT security; #endif if (ntfs_fuse_is_named_data_stream(path)) return -EINVAL; /* n/a for named data streams. */ #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) /* parent directory must be executable */ if (ntfs_fuse_fill_security_context(&security) && !ntfs_allowed_dir_access(&security,path, (ntfs_inode*)NULL,(ntfs_inode*)NULL,S_IEXEC)) { return (-errno); } #endif ni = ntfs_pathname_to_inode(ctx->vol, NULL, path); if (!ni) return -errno; /* no check or update if both UTIME_OMIT */ if ((tv[0].tv_nsec != UTIME_OMIT) || (tv[1].tv_nsec != UTIME_OMIT)) { #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) if (ntfs_allowed_as_owner(&security, ni) || ((tv[0].tv_nsec == UTIME_NOW) && (tv[1].tv_nsec == UTIME_NOW) && ntfs_allowed_access(&security, ni, S_IWRITE))) { #endif ntfs_time_update_flags mask = NTFS_UPDATE_CTIME; if (tv[0].tv_nsec == UTIME_NOW) mask |= NTFS_UPDATE_ATIME; else if (tv[0].tv_nsec != UTIME_OMIT) ni->last_access_time = timespec2ntfs(tv[0]); if (tv[1].tv_nsec == UTIME_NOW) mask |= NTFS_UPDATE_MTIME; else if (tv[1].tv_nsec != UTIME_OMIT) ni->last_data_change_time = timespec2ntfs(tv[1]); ntfs_inode_update_times(ni, mask); #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) } else res = -errno; #endif } if (ntfs_inode_close(ni)) set_fuse_error(&res); return res; } #else /* HAVE_UTIMENSAT */ static int ntfs_fuse_utime(const char *path, struct utimbuf *buf) { ntfs_inode *ni; int res = 0; struct timespec actime; struct timespec modtime; #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) BOOL ownerok; BOOL writeok; struct SECURITY_CONTEXT security; #endif if (ntfs_fuse_is_named_data_stream(path)) return -EINVAL; /* n/a for named data streams. */ #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) /* parent directory must be executable */ if (ntfs_fuse_fill_security_context(&security) && !ntfs_allowed_dir_access(&security,path, (ntfs_inode*)NULL,(ntfs_inode*)NULL,S_IEXEC)) { return (-errno); } #endif ni = ntfs_pathname_to_inode(ctx->vol, NULL, path); if (!ni) return -errno; #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) ownerok = ntfs_allowed_as_owner(&security, ni); if (buf) { /* * fuse never calls with a NULL buf and we do not * know whether the specific condition can be applied * So we have to accept updating by a non-owner having * write access. */ writeok = !ownerok && (buf->actime == buf->modtime) && ntfs_allowed_access(&security, ni, S_IWRITE); /* Must be owner */ if (!ownerok && !writeok) res = (buf->actime == buf->modtime ? -EACCES : -EPERM); else { actime.tv_sec = buf->actime; actime.tv_nsec = 0; modtime.tv_sec = buf->modtime; modtime.tv_nsec = 0; ni->last_access_time = timespec2ntfs(actime); ni->last_data_change_time = timespec2ntfs(modtime); ntfs_fuse_update_times(ni, NTFS_UPDATE_CTIME); } } else { /* Must be owner or have write access */ writeok = !ownerok && ntfs_allowed_access(&security, ni, S_IWRITE); if (!ownerok && !writeok) res = -EACCES; else ntfs_inode_update_times(ni, NTFS_UPDATE_AMCTIME); } #else if (buf) { actime.tv_sec = buf->actime; actime.tv_nsec = 0; modtime.tv_sec = buf->modtime; modtime.tv_nsec = 0; ni->last_access_time = timespec2ntfs(actime); ni->last_data_change_time = timespec2ntfs(modtime); ntfs_fuse_update_times(ni, NTFS_UPDATE_CTIME); } else ntfs_inode_update_times(ni, NTFS_UPDATE_AMCTIME); #endif if (ntfs_inode_close(ni)) set_fuse_error(&res); return res; } #endif /* HAVE_UTIMENSAT */ static int ntfs_fuse_fsync(const char *path __attribute__((unused)), int type __attribute__((unused)), struct fuse_file_info *fi __attribute__((unused))) { int ret; /* sync the full device */ ret = ntfs_device_sync(ctx->vol->dev); if (ret) ret = -errno; return (ret); } #if defined(FUSE_INTERNAL) || (FUSE_VERSION >= 28) static int ntfs_fuse_ioctl(const char *path, int cmd, void *arg, struct fuse_file_info *fi __attribute__((unused)), unsigned int flags, void *data) { ntfs_inode *ni; int ret; if (flags & FUSE_IOCTL_COMPAT) return -ENOSYS; ni = ntfs_pathname_to_inode(ctx->vol, NULL, path); if (!ni) return -errno; /* * Linux defines the request argument of ioctl() to be an * unsigned long, which fuse 2.x forwards as a signed int into * which the request sometimes does not fit. * So we must expand the value and make sure it is not sign-extended. */ ret = ntfs_ioctl(ni, (unsigned int)cmd, arg, flags, data); if (ntfs_inode_close (ni)) set_fuse_error(&ret); return ret; } #endif /* defined(FUSE_INTERNAL) || (FUSE_VERSION >= 28) */ static int ntfs_fuse_bmap(const char *path, size_t blocksize, uint64_t *idx) { ntfs_inode *ni; ntfs_attr *na; LCN lcn; int ret = 0; int cl_per_bl = ctx->vol->cluster_size / blocksize; if (blocksize > ctx->vol->cluster_size) return -EINVAL; if (ntfs_fuse_is_named_data_stream(path)) return -EINVAL; ni = ntfs_pathname_to_inode(ctx->vol, NULL, path); if (!ni) return -errno; na = ntfs_attr_open(ni, AT_DATA, AT_UNNAMED, 0); if (!na) { ret = -errno; goto close_inode; } if ((na->data_flags & (ATTR_COMPRESSION_MASK | ATTR_IS_ENCRYPTED)) || !NAttrNonResident(na)) { ret = -EINVAL; goto close_attr; } if (ntfs_attr_map_whole_runlist(na)) { ret = -errno; goto close_attr; } lcn = ntfs_rl_vcn_to_lcn(na->rl, *idx / cl_per_bl); *idx = (lcn > 0) ? lcn * cl_per_bl + *idx % cl_per_bl : 0; close_attr: ntfs_attr_close(na); close_inode: if (ntfs_inode_close(ni)) set_fuse_error(&ret); return ret; } #ifdef HAVE_SETXATTR /* * Name space identifications and prefixes */ enum { XATTRNS_NONE, XATTRNS_USER, XATTRNS_SYSTEM, XATTRNS_SECURITY, XATTRNS_TRUSTED, XATTRNS_OPEN } ; /* * Check whether access to internal data as an extended * attribute in system name space is allowed * * Returns pointer to inode if allowed, * NULL and errno set if not allowed */ static ntfs_inode *ntfs_check_access_xattr(struct SECURITY_CONTEXT *security, const char *path, int attr, BOOL setting) { ntfs_inode *ni; BOOL foracl; mode_t acctype; ni = (ntfs_inode*)NULL; if (ntfs_fuse_is_named_data_stream(path)) errno = EINVAL; /* n/a for named data streams. */ else { foracl = (attr == XATTR_POSIX_ACC) || (attr == XATTR_POSIX_DEF); /* * When accessing Posix ACL, return unsupported if ACL * were disabled or no user mapping has been defined, * or trying to change a Windows-inherited ACL. * However no error will be returned to getfacl */ if (((!ntfs_fuse_fill_security_context(security) || (ctx->secure_flags & ((1 << SECURITY_DEFAULT) | (1 << SECURITY_RAW)))) || !(ctx->secure_flags & (1 << SECURITY_ACL)) || (setting && ctx->inherit)) && foracl) { if (ctx->silent && !ctx->security.mapping[MAPUSERS]) errno = 0; else errno = EOPNOTSUPP; } else { /* * parent directory must be executable, and * for setting a DOS name it must be writeable */ if (setting && (attr == XATTR_NTFS_DOS_NAME)) acctype = S_IEXEC | S_IWRITE; else acctype = S_IEXEC; if ((attr == XATTR_NTFS_DOS_NAME) && !strcmp(path,"/")) /* forbid getting/setting names on root */ errno = EPERM; else if (ntfs_allowed_real_dir_access(security, path, (ntfs_inode*)NULL ,acctype)) { ni = ntfs_pathname_to_inode(ctx->vol, NULL, path); } } } return (ni); } /* * Determine the name space of an extended attribute */ static int xattr_namespace(const char *name) { int namespace; if (ctx->streams == NF_STREAMS_INTERFACE_XATTR) { namespace = XATTRNS_NONE; if (!strncmp(name, nf_ns_user_prefix, nf_ns_user_prefix_len) && (strlen(name) != (size_t)nf_ns_user_prefix_len)) namespace = XATTRNS_USER; else if (!strncmp(name, nf_ns_system_prefix, nf_ns_system_prefix_len) && (strlen(name) != (size_t)nf_ns_system_prefix_len)) namespace = XATTRNS_SYSTEM; else if (!strncmp(name, nf_ns_security_prefix, nf_ns_security_prefix_len) && (strlen(name) != (size_t)nf_ns_security_prefix_len)) namespace = XATTRNS_SECURITY; else if (!strncmp(name, nf_ns_trusted_prefix, nf_ns_trusted_prefix_len) && (strlen(name) != (size_t)nf_ns_trusted_prefix_len)) namespace = XATTRNS_TRUSTED; } else namespace = XATTRNS_OPEN; return (namespace); } /* * Fix the prefix of an extended attribute */ static int fix_xattr_prefix(const char *name, int namespace, ntfschar **lename) { int len; char *prefixed; *lename = (ntfschar*)NULL; switch (namespace) { case XATTRNS_USER : /* * user name space : remove user prefix */ len = ntfs_mbstoucs(name + nf_ns_user_prefix_len, lename); break; case XATTRNS_SYSTEM : case XATTRNS_SECURITY : case XATTRNS_TRUSTED : /* * security, trusted and unmapped system name spaces : * insert ntfs-3g prefix */ prefixed = ntfs_malloc(strlen(xattr_ntfs_3g) + strlen(name) + 1); if (prefixed) { strcpy(prefixed,xattr_ntfs_3g); strcat(prefixed,name); len = ntfs_mbstoucs(prefixed, lename); free(prefixed); } else len = -1; break; case XATTRNS_OPEN : /* * in open name space mode : do no fix prefix */ len = ntfs_mbstoucs(name, lename); break; default : len = -1; } return (len); } static int ntfs_fuse_listxattr(const char *path, char *list, size_t size) { ntfs_attr_search_ctx *actx = NULL; ntfs_inode *ni; int ret = 0; #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) struct SECURITY_CONTEXT security; #endif #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) /* parent directory must be executable */ if (ntfs_fuse_fill_security_context(&security) && !ntfs_allowed_dir_access(&security,path,(ntfs_inode*)NULL, (ntfs_inode*)NULL,S_IEXEC)) { return (-errno); } #endif ni = ntfs_pathname_to_inode(ctx->vol, NULL, path); if (!ni) return -errno; /* Return with no result for symlinks, fifo, etc. */ if (!user_xattrs_allowed(ctx, ni)) goto exit; /* otherwise file must be readable */ #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) if (!ntfs_allowed_access(&security,ni,S_IREAD)) { ret = -EACCES; goto exit; } #endif actx = ntfs_attr_get_search_ctx(ni, NULL); if (!actx) { ret = -errno; goto exit; } if ((ctx->streams == NF_STREAMS_INTERFACE_XATTR) || (ctx->streams == NF_STREAMS_INTERFACE_OPENXATTR)) { ret = ntfs_fuse_listxattr_common(ni, actx, list, size, ctx->streams == NF_STREAMS_INTERFACE_XATTR); if (ret < 0) goto exit; } if (errno != ENOENT) ret = -errno; exit: if (actx) ntfs_attr_put_search_ctx(actx); if (ntfs_inode_close(ni)) set_fuse_error(&ret); return ret; } static int ntfs_fuse_getxattr_windows(const char *path, const char *name, char *value, size_t size) { ntfs_attr_search_ctx *actx = NULL; ntfs_inode *ni; char *to = value; int ret = 0; #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) struct SECURITY_CONTEXT security; #endif if (strcmp(name, "ntfs.streams.list")) return -EOPNOTSUPP; #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) /* parent directory must be executable */ if (ntfs_fuse_fill_security_context(&security) && !ntfs_allowed_dir_access(&security,path,(ntfs_inode*)NULL, (ntfs_inode*)NULL,S_IEXEC)) { return (-errno); } #endif ni = ntfs_pathname_to_inode(ctx->vol, NULL, path); if (!ni) return -errno; #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) if (!ntfs_allowed_access(&security,ni,S_IREAD)) { ret = -errno; goto exit; } #endif actx = ntfs_attr_get_search_ctx(ni, NULL); if (!actx) { ret = -errno; goto exit; } while (!ntfs_attr_lookup(AT_DATA, NULL, 0, CASE_SENSITIVE, 0, NULL, 0, actx)) { char *tmp_name = NULL; int tmp_name_len; if (!actx->attr->name_length) continue; tmp_name_len = ntfs_ucstombs((ntfschar *)((u8*)actx->attr + le16_to_cpu(actx->attr->name_offset)), actx->attr->name_length, &tmp_name, 0); if (tmp_name_len < 0) { ret = -errno; goto exit; } if (ret) ret++; /* For space delimiter. */ ret += tmp_name_len; if (size) { if ((size_t)ret <= size) { /* Don't add space to the beginning of line. */ if (to != value) { *to = '\0'; to++; } strncpy(to, tmp_name, tmp_name_len); to += tmp_name_len; } else { free(tmp_name); ret = -ERANGE; goto exit; } } free(tmp_name); } if (errno != ENOENT) ret = -errno; exit: if (actx) ntfs_attr_put_search_ctx(actx); if (ntfs_inode_close(ni)) set_fuse_error(&ret); return ret; } #if defined(__APPLE__) || defined(__DARWIN__) static int ntfs_fuse_getxattr(const char *path, const char *name, char *value, size_t size, uint32_t position) #else static int ntfs_fuse_getxattr(const char *path, const char *name, char *value, size_t size) #endif { #if !(defined(__APPLE__) || defined(__DARWIN__)) static const unsigned int position = 0U; #endif ntfs_inode *ni; ntfs_inode *dir_ni; ntfs_attr *na = NULL; ntfschar *lename = NULL; int res, lename_len; s64 rsize; enum SYSTEMXATTRS attr; int namespace; struct SECURITY_CONTEXT security; #if defined(__APPLE__) || defined(__DARWIN__) /* If the attribute is not a resource fork attribute and the position * parameter is non-zero, we return with EINVAL as requesting position * is not permitted for non-resource fork attributes. */ if (position && strcmp(name, XATTR_RESOURCEFORK_NAME)) { return -EINVAL; } #endif attr = ntfs_xattr_system_type(name,ctx->vol); if (attr != XATTR_UNMAPPED) { #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) /* * hijack internal data and ACL retrieval, whatever * mode was selected for xattr (from the user's * point of view, ACLs are not xattr) */ ni = ntfs_check_access_xattr(&security, path, attr, FALSE); if (ni) { if (ntfs_allowed_access(&security,ni,S_IREAD)) { if (attr == XATTR_NTFS_DOS_NAME) dir_ni = get_parent_dir(path); else dir_ni = (ntfs_inode*)NULL; res = ntfs_xattr_system_getxattr(&security, attr, ni, dir_ni, value, size); if (dir_ni && ntfs_inode_close(dir_ni)) set_fuse_error(&res); } else { res = -errno; } if (ntfs_inode_close(ni)) set_fuse_error(&res); } else res = -errno; #else /* * Only hijack NTFS ACL retrieval if POSIX ACLS * option is not selected * Access control is done by fuse */ if (ntfs_fuse_is_named_data_stream(path)) res = -EINVAL; /* n/a for named data streams. */ else { ni = ntfs_pathname_to_inode(ctx->vol, NULL, path); if (ni) { /* user mapping not mandatory */ ntfs_fuse_fill_security_context(&security); if (attr == XATTR_NTFS_DOS_NAME) dir_ni = get_parent_dir(path); else dir_ni = (ntfs_inode*)NULL; res = ntfs_xattr_system_getxattr(&security, attr, ni, dir_ni, value, size); if (dir_ni && ntfs_inode_close(dir_ni)) set_fuse_error(&res); if (ntfs_inode_close(ni)) set_fuse_error(&res); } else res = -errno; } #endif return (res); } if (ctx->streams == NF_STREAMS_INTERFACE_WINDOWS) return ntfs_fuse_getxattr_windows(path, name, value, size); if (ctx->streams == NF_STREAMS_INTERFACE_NONE) return -EOPNOTSUPP; namespace = xattr_namespace(name); if (namespace == XATTRNS_NONE) return -EOPNOTSUPP; #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) /* parent directory must be executable */ if (ntfs_fuse_fill_security_context(&security) && !ntfs_allowed_dir_access(&security,path,(ntfs_inode*)NULL, (ntfs_inode*)NULL,S_IEXEC)) { return (-errno); } /* trusted only readable by root */ if ((namespace == XATTRNS_TRUSTED) && security.uid) return -NTFS_NOXATTR_ERRNO; #endif ni = ntfs_pathname_to_inode(ctx->vol, NULL, path); if (!ni) return -errno; /* Return with no result for symlinks, fifo, etc. */ if (!user_xattrs_allowed(ctx, ni)) { res = -NTFS_NOXATTR_ERRNO; goto exit; } /* otherwise file must be readable */ #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) if (!ntfs_allowed_access(&security, ni, S_IREAD)) { res = -errno; goto exit; } #endif lename_len = fix_xattr_prefix(name, namespace, &lename); if (lename_len == -1) { res = -errno; goto exit; } na = ntfs_attr_open(ni, AT_DATA, lename, lename_len); if (!na) { res = -NTFS_NOXATTR_ERRNO; goto exit; } rsize = na->data_size; if (ctx->efs_raw && rsize && (na->data_flags & ATTR_IS_ENCRYPTED) && NAttrNonResident(na)) rsize = ((na->data_size + 511) & ~511) + 2; rsize -= position; if (size) { if (size >= (size_t)rsize) { res = ntfs_attr_pread(na, position, rsize, value); if (res != rsize) res = -errno; } else res = -ERANGE; } else res = rsize; exit: if (na) ntfs_attr_close(na); free(lename); if (ntfs_inode_close(ni)) set_fuse_error(&res); return res; } #if defined(__APPLE__) || defined(__DARWIN__) static int ntfs_fuse_setxattr(const char *path, const char *name, const char *value, size_t size, int flags, uint32_t position) #else static int ntfs_fuse_setxattr(const char *path, const char *name, const char *value, size_t size, int flags) #endif { #if !(defined(__APPLE__) || defined(__DARWIN__)) static const unsigned int position = 0U; #else BOOL is_resource_fork; #endif ntfs_inode *ni; ntfs_inode *dir_ni; ntfs_attr *na = NULL; ntfschar *lename = NULL; int res, lename_len; size_t total; s64 part; enum SYSTEMXATTRS attr; int namespace; struct SECURITY_CONTEXT security; #if defined(__APPLE__) || defined(__DARWIN__) /* If the attribute is not a resource fork attribute and the position * parameter is non-zero, we return with EINVAL as requesting position * is not permitted for non-resource fork attributes. */ is_resource_fork = strcmp(name, XATTR_RESOURCEFORK_NAME) ? FALSE : TRUE; if (position && !is_resource_fork) { return -EINVAL; } #endif attr = ntfs_xattr_system_type(name,ctx->vol); if (attr != XATTR_UNMAPPED) { #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) /* * hijack internal data and ACL setting, whatever * mode was selected for xattr (from the user's * point of view, ACLs are not xattr) * Note : ctime updated on successful settings */ ni = ntfs_check_access_xattr(&security,path,attr,TRUE); if (ni) { if (ntfs_allowed_as_owner(&security,ni)) { if (attr == XATTR_NTFS_DOS_NAME) dir_ni = get_parent_dir(path); else dir_ni = (ntfs_inode*)NULL; res = ntfs_xattr_system_setxattr(&security, attr, ni, dir_ni, value, size, flags); /* never have to close dir_ni */ if (res) res = -errno; } else res = -errno; if (attr != XATTR_NTFS_DOS_NAME) { if (!res) ntfs_fuse_update_times(ni, NTFS_UPDATE_CTIME); if (ntfs_inode_close(ni)) set_fuse_error(&res); } } else res = -errno; #else /* * Only hijack NTFS ACL setting if POSIX ACLS * option is not selected * Access control is partially done by fuse */ if (ntfs_fuse_is_named_data_stream(path)) res = -EINVAL; /* n/a for named data streams. */ else { /* creation of a new name is not controlled by fuse */ if (attr == XATTR_NTFS_DOS_NAME) ni = ntfs_check_access_xattr(&security,path,attr,TRUE); else ni = ntfs_pathname_to_inode(ctx->vol, NULL, path); if (ni) { /* * user mapping is not mandatory * if defined, only owner is allowed */ if (!ntfs_fuse_fill_security_context(&security) || ntfs_allowed_as_owner(&security,ni)) { if (attr == XATTR_NTFS_DOS_NAME) dir_ni = get_parent_dir(path); else dir_ni = (ntfs_inode*)NULL; res = ntfs_xattr_system_setxattr(&security, attr, ni, dir_ni, value, size, flags); /* never have to close dir_ni */ if (res) res = -errno; } else res = -errno; if (attr != XATTR_NTFS_DOS_NAME) { if (!res) ntfs_fuse_update_times(ni, NTFS_UPDATE_CTIME); if (ntfs_inode_close(ni)) set_fuse_error(&res); } } else res = -errno; } #endif return (res); } if ((ctx->streams != NF_STREAMS_INTERFACE_XATTR) && (ctx->streams != NF_STREAMS_INTERFACE_OPENXATTR)) return -EOPNOTSUPP; namespace = xattr_namespace(name); if (namespace == XATTRNS_NONE) return -EOPNOTSUPP; #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) /* parent directory must be executable */ if (ntfs_fuse_fill_security_context(&security) && !ntfs_allowed_dir_access(&security,path,(ntfs_inode*)NULL, (ntfs_inode*)NULL,S_IEXEC)) { return (-errno); } /* security and trusted only settable by root */ if (((namespace == XATTRNS_SECURITY) || (namespace == XATTRNS_TRUSTED)) && security.uid) return -EPERM; #endif ni = ntfs_pathname_to_inode(ctx->vol, NULL, path); if (!ni) return -errno; #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) switch (namespace) { case XATTRNS_SECURITY : case XATTRNS_TRUSTED : if (security.uid) { res = -EPERM; goto exit; } break; case XATTRNS_SYSTEM : if (!ntfs_allowed_as_owner(&security,ni)) { res = -EACCES; goto exit; } break; default : /* User xattr not allowed for symlinks, fifo, etc. */ if (!user_xattrs_allowed(ctx, ni)) { res = -EPERM; goto exit; } if (!ntfs_allowed_access(&security,ni,S_IWRITE)) { res = -EACCES; goto exit; } break; } #else /* User xattr not allowed for symlinks, fifo, etc. */ if ((namespace == XATTRNS_USER) && !user_xattrs_allowed(ctx, ni)) { res = -EPERM; goto exit; } #endif lename_len = fix_xattr_prefix(name, namespace, &lename); if ((lename_len == -1) || (ctx->windows_names && ntfs_forbidden_chars(lename,lename_len,TRUE))) { res = -errno; goto exit; } na = ntfs_attr_open(ni, AT_DATA, lename, lename_len); if (na && flags == XATTR_CREATE) { res = -EEXIST; goto exit; } if (!na) { if (flags == XATTR_REPLACE) { res = -NTFS_NOXATTR_ERRNO; goto exit; } if (ntfs_attr_add(ni, AT_DATA, lename, lename_len, NULL, 0)) { res = -errno; goto exit; } if (!(ni->flags & FILE_ATTR_ARCHIVE)) { set_archive(ni); NInoFileNameSetDirty(ni); } na = ntfs_attr_open(ni, AT_DATA, lename, lename_len); if (!na) { res = -errno; goto exit; } #if defined(__APPLE__) || defined(__DARWIN__) } else if (is_resource_fork) { /* In macOS, the resource fork is a special case. It doesn't * ever shrink (it would have to be removed and re-added). */ #endif } else { /* currently compressed streams can only be wiped out */ if (ntfs_attr_truncate(na, (s64)0 /* size */)) { res = -errno; goto exit; } } total = 0; res = 0; if (size) { do { part = ntfs_attr_pwrite(na, position + total, size - total, &value[total]); if (part > 0) total += part; } while ((part > 0) && (total < size)); } if ((total != size) || ntfs_attr_pclose(na)) res = -errno; else { if (ctx->efs_raw && (ni->flags & FILE_ATTR_ENCRYPTED)) { if (ntfs_efs_fixup_attribute(NULL,na)) res = -errno; } } if (!res) { ntfs_fuse_update_times(ni, NTFS_UPDATE_CTIME); if (!(ni->flags & FILE_ATTR_ARCHIVE)) { set_archive(ni); NInoFileNameSetDirty(ni); } } exit: if (na) ntfs_attr_close(na); free(lename); if (ntfs_inode_close(ni)) set_fuse_error(&res); return res; } static int ntfs_fuse_removexattr(const char *path, const char *name) { ntfs_inode *ni; ntfs_inode *dir_ni; ntfschar *lename = NULL; int res = 0, lename_len; enum SYSTEMXATTRS attr; int namespace; struct SECURITY_CONTEXT security; attr = ntfs_xattr_system_type(name,ctx->vol); if (attr != XATTR_UNMAPPED) { switch (attr) { /* * Removal of NTFS ACL, ATTRIB, EFSINFO or TIMES * is never allowed */ case XATTR_NTFS_ACL : case XATTR_NTFS_ATTRIB : case XATTR_NTFS_ATTRIB_BE : case XATTR_NTFS_EFSINFO : case XATTR_NTFS_TIMES : case XATTR_NTFS_TIMES_BE : case XATTR_NTFS_CRTIME : case XATTR_NTFS_CRTIME_BE : res = -EPERM; break; default : #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) /* * hijack internal data and ACL removal, whatever * mode was selected for xattr (from the user's * point of view, ACLs are not xattr) * Note : ctime updated on successful settings */ ni = ntfs_check_access_xattr(&security,path,attr,TRUE); if (ni) { if (ntfs_allowed_as_owner(&security,ni)) { if (attr == XATTR_NTFS_DOS_NAME) dir_ni = get_parent_dir(path); else dir_ni = (ntfs_inode*)NULL; res = ntfs_xattr_system_removexattr(&security, attr, ni, dir_ni); /* never have to close dir_ni */ if (res) res = -errno; } else res = -errno; if (attr != XATTR_NTFS_DOS_NAME) { if (!res) ntfs_fuse_update_times(ni, NTFS_UPDATE_CTIME); if (ntfs_inode_close(ni)) set_fuse_error(&res); } } else res = -errno; #else /* * Only hijack NTFS ACL setting if POSIX ACLS * option is not selected * Access control is partially done by fuse */ /* creation of a new name is not controlled by fuse */ if (attr == XATTR_NTFS_DOS_NAME) ni = ntfs_check_access_xattr(&security, path, attr, TRUE); else { if (ntfs_fuse_is_named_data_stream(path)) { ni = (ntfs_inode*)NULL; errno = EINVAL; /* n/a for named data streams. */ } else ni = ntfs_pathname_to_inode(ctx->vol, NULL, path); } if (ni) { /* * user mapping is not mandatory * if defined, only owner is allowed */ if (!ntfs_fuse_fill_security_context(&security) || ntfs_allowed_as_owner(&security,ni)) { if (attr == XATTR_NTFS_DOS_NAME) dir_ni = get_parent_dir(path); else dir_ni = (ntfs_inode*)NULL; res = ntfs_xattr_system_removexattr(&security, attr, ni, dir_ni); /* never have to close dir_ni */ if (res) res = -errno; } else res = -errno; if (attr != XATTR_NTFS_DOS_NAME) { if (!res) ntfs_fuse_update_times(ni, NTFS_UPDATE_CTIME); if (ntfs_inode_close(ni)) set_fuse_error(&res); } } else res = -errno; #endif break; } return (res); } if ((ctx->streams != NF_STREAMS_INTERFACE_XATTR) && (ctx->streams != NF_STREAMS_INTERFACE_OPENXATTR)) return -EOPNOTSUPP; namespace = xattr_namespace(name); if (namespace == XATTRNS_NONE) return -EOPNOTSUPP; #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) /* parent directory must be executable */ if (ntfs_fuse_fill_security_context(&security) && !ntfs_allowed_dir_access(&security,path,(ntfs_inode*)NULL, (ntfs_inode*)NULL,S_IEXEC)) { return (-errno); } /* security and trusted only settable by root */ if (((namespace == XATTRNS_SECURITY) || (namespace == XATTRNS_TRUSTED)) && security.uid) return -EACCES; #endif ni = ntfs_pathname_to_inode(ctx->vol, NULL, path); if (!ni) return -errno; #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) switch (namespace) { case XATTRNS_SECURITY : case XATTRNS_TRUSTED : if (security.uid) { res = -EPERM; goto exit; } break; case XATTRNS_SYSTEM : if (!ntfs_allowed_as_owner(&security,ni)) { res = -EACCES; goto exit; } break; default : /* User xattr not allowed for symlinks, fifo, etc. */ if (!user_xattrs_allowed(ctx, ni)) { res = -EPERM; goto exit; } if (!ntfs_allowed_access(&security,ni,S_IWRITE)) { res = -EACCES; goto exit; } break; } #else /* User xattr not allowed for symlinks, fifo, etc. */ if ((namespace == XATTRNS_USER) && !user_xattrs_allowed(ctx, ni)) { res = -EPERM; goto exit; } #endif lename_len = fix_xattr_prefix(name, namespace, &lename); if (lename_len == -1) { res = -errno; goto exit; } if (ntfs_attr_remove(ni, AT_DATA, lename, lename_len)) { if (errno == ENOENT) errno = NTFS_NOXATTR_ERRNO; res = -errno; } if (!res) { ntfs_fuse_update_times(ni, NTFS_UPDATE_CTIME); if (!(ni->flags & FILE_ATTR_ARCHIVE)) { set_archive(ni); NInoFileNameSetDirty(ni); } } exit: free(lename); if (ntfs_inode_close(ni)) set_fuse_error(&res); return res; } #else #if POSIXACLS #error "Option inconsistency : POSIXACLS requires SETXATTR" #endif #endif /* HAVE_SETXATTR */ #ifndef DISABLE_PLUGINS static void register_internal_reparse_plugins(void) { static const plugin_operations_t ops = { .getattr = junction_getattr, .readlink = junction_readlink, } ; static const plugin_operations_t wsl_ops = { .getattr = wsl_getattr, } ; register_reparse_plugin(ctx, IO_REPARSE_TAG_MOUNT_POINT, &ops, (void*)NULL); register_reparse_plugin(ctx, IO_REPARSE_TAG_SYMLINK, &ops, (void*)NULL); register_reparse_plugin(ctx, IO_REPARSE_TAG_LX_SYMLINK, &ops, (void*)NULL); register_reparse_plugin(ctx, IO_REPARSE_TAG_LX_SYMLINK, &ops, (void*)NULL); register_reparse_plugin(ctx, IO_REPARSE_TAG_AF_UNIX, &wsl_ops, (void*)NULL); register_reparse_plugin(ctx, IO_REPARSE_TAG_LX_FIFO, &wsl_ops, (void*)NULL); register_reparse_plugin(ctx, IO_REPARSE_TAG_LX_CHR, &wsl_ops, (void*)NULL); register_reparse_plugin(ctx, IO_REPARSE_TAG_LX_BLK, &wsl_ops, (void*)NULL); } #endif /* DISABLE_PLUGINS */ static void ntfs_close(void) { struct SECURITY_CONTEXT security; if (!ctx) return; if (!ctx->vol) return; if (ctx->mounted) { ntfs_log_info("Unmounting %s (%s)\n", opts.device, ctx->vol->vol_name); if (ntfs_fuse_fill_security_context(&security)) { if (ctx->seccache && ctx->seccache->head.p_reads) { ntfs_log_info("Permissions cache : %lu writes, " "%lu reads, %lu.%1lu%% hits\n", ctx->seccache->head.p_writes, ctx->seccache->head.p_reads, 100 * ctx->seccache->head.p_hits / ctx->seccache->head.p_reads, 1000 * ctx->seccache->head.p_hits / ctx->seccache->head.p_reads % 10); } } ntfs_destroy_security_context(&security); } if (ntfs_umount(ctx->vol, FALSE)) ntfs_log_perror("Failed to close volume %s", opts.device); ctx->vol = NULL; } static void ntfs_fuse_destroy2(void *unused __attribute__((unused))) { ntfs_close(); } static struct fuse_operations ntfs_3g_ops = { .getattr = ntfs_fuse_getattr, .readlink = ntfs_fuse_readlink, .readdir = ntfs_fuse_readdir, .open = ntfs_fuse_open, .release = ntfs_fuse_release, .read = ntfs_fuse_read, .write = ntfs_fuse_write, .truncate = ntfs_fuse_truncate, .ftruncate = ntfs_fuse_ftruncate, .statfs = ntfs_fuse_statfs, .chmod = ntfs_fuse_chmod, .chown = ntfs_fuse_chown, .create = ntfs_fuse_create_file, .mknod = ntfs_fuse_mknod, .symlink = ntfs_fuse_symlink, .link = ntfs_fuse_link, .unlink = ntfs_fuse_unlink, .rename = ntfs_fuse_rename, .mkdir = ntfs_fuse_mkdir, .rmdir = ntfs_fuse_rmdir, #ifdef HAVE_UTIMENSAT .utimens = ntfs_fuse_utimens, #if defined(linux) & !defined(FUSE_INTERNAL) & (FUSE_VERSION < 30) .flag_utime_omit_ok = 1, #endif /* defined(linux) & !defined(FUSE_INTERNAL) */ #else .utime = ntfs_fuse_utime, #endif .fsync = ntfs_fuse_fsync, .fsyncdir = ntfs_fuse_fsync, .bmap = ntfs_fuse_bmap, .destroy = ntfs_fuse_destroy2, #if defined(FUSE_INTERNAL) || (FUSE_VERSION >= 28) .ioctl = ntfs_fuse_ioctl, #endif /* defined(FUSE_INTERNAL) || (FUSE_VERSION >= 28) */ #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) .access = ntfs_fuse_access, .opendir = ntfs_fuse_opendir, .releasedir = ntfs_fuse_release, #endif #ifdef HAVE_SETXATTR .getxattr = ntfs_fuse_getxattr, .setxattr = ntfs_fuse_setxattr, .removexattr = ntfs_fuse_removexattr, .listxattr = ntfs_fuse_listxattr, #endif /* HAVE_SETXATTR */ #if defined(__APPLE__) || defined(__DARWIN__) /* MacFUSE extensions. */ .getxtimes = ntfs_macfuse_getxtimes, .setcrtime = ntfs_macfuse_setcrtime, .setbkuptime = ntfs_macfuse_setbkuptime, .setchgtime = ntfs_macfuse_setchgtime, #endif /* defined(__APPLE__) || defined(__DARWIN__) */ .init = ntfs_init }; static int ntfs_fuse_init(void) { ctx = ntfs_calloc(sizeof(ntfs_fuse_context_t)); if (!ctx) return -1; *ctx = (ntfs_fuse_context_t) { .uid = getuid(), .gid = getgid(), #if defined(linux) .streams = NF_STREAMS_INTERFACE_XATTR, #else .streams = NF_STREAMS_INTERFACE_NONE, #endif .atime = ATIME_RELATIVE, .silent = TRUE, .recover = TRUE }; return 0; } static int ntfs_open(const char *device) { unsigned long flags = 0; if (!ctx->blkdev) flags |= NTFS_MNT_EXCLUSIVE; if (ctx->ro) flags |= NTFS_MNT_RDONLY; else if (!ctx->hiberfile) flags |= NTFS_MNT_MAY_RDONLY; if (ctx->recover) flags |= NTFS_MNT_RECOVER; if (ctx->hiberfile) flags |= NTFS_MNT_IGNORE_HIBERFILE; ctx->vol = ntfs_mount(device, flags); if (!ctx->vol) { ntfs_log_perror("Failed to mount '%s'", device); goto err_out; } if (ctx->sync && ctx->vol->dev) NDevSetSync(ctx->vol->dev); if (ctx->compression) NVolSetCompression(ctx->vol); else NVolClearCompression(ctx->vol); #ifdef HAVE_SETXATTR /* archivers must see hidden files */ if (ctx->efs_raw) ctx->hide_hid_files = FALSE; #endif if (ntfs_set_shown_files(ctx->vol, ctx->show_sys_files, !ctx->hide_hid_files, ctx->hide_dot_files)) goto err_out; if (ntfs_volume_get_free_space(ctx->vol)) { ntfs_log_perror("Failed to read NTFS $Bitmap"); goto err_out; } ctx->vol->free_mft_records = ntfs_get_nr_free_mft_records(ctx->vol); if (ctx->vol->free_mft_records < 0) { ntfs_log_perror("Failed to calculate free MFT records"); goto err_out; } if (ctx->hiberfile && ntfs_volume_check_hiberfile(ctx->vol, 0)) { if (errno != EPERM) goto err_out; if (ntfs_fuse_rm("/hiberfil.sys")) goto err_out; } errno = 0; goto out; err_out: if (!errno) errno = EIO; out : return ntfs_volume_error(errno); } static void usage(void) { ntfs_log_info(usage_msg, EXEC_NAME, VERSION, FUSE_TYPE, fuse_version(), 4 + POSIXACLS*6 - KERNELPERMS*3 + CACHEING, EXEC_NAME, ntfs_home); } #if defined(linux) || defined(__uClinux__) static const char *dev_fuse_msg = "HINT: You should be root, or make ntfs-3g setuid root, or load the FUSE\n" " kernel module as root ('modprobe fuse' or 'insmod /fuse.ko'" " or insmod /fuse.o'). Make also sure that the fuse device" " exists. It's usually either /dev/fuse or /dev/misc/fuse."; static const char *fuse26_kmod_msg = "WARNING: Deficient Linux kernel detected. Some driver features are\n" " not available (swap file on NTFS, boot from NTFS by LILO), and\n" " unmount is not safe unless it's made sure the ntfs-3g process\n" " naturally terminates after calling 'umount'. If you wish this\n" " message to disappear then you should upgrade to at least kernel\n" " version 2.6.20, or request help from your distribution to fix\n" " the kernel problem. The below web page has more information:\n" " https://github.com/tuxera/ntfs-3g/wiki/NTFS-3G-FAQ\n" "\n"; static void mknod_dev_fuse(const char *dev) { struct stat st; if (stat(dev, &st) && (errno == ENOENT)) { mode_t mask = umask(0); if (mknod(dev, S_IFCHR | 0666, makedev(10, 229))) { ntfs_log_perror("Failed to create '%s'", dev); if (errno == EPERM) ntfs_log_error("%s", dev_fuse_msg); } umask(mask); } } static void create_dev_fuse(void) { mknod_dev_fuse("/dev/fuse"); #ifdef __UCLIBC__ { struct stat st; /* The fuse device is under /dev/misc using devfs. */ if (stat("/dev/misc", &st) && (errno == ENOENT)) { mode_t mask = umask(0); mkdir("/dev/misc", 0775); umask(mask); } mknod_dev_fuse("/dev/misc/fuse"); } #endif } static fuse_fstype get_fuse_fstype(void) { char buf[256]; fuse_fstype fstype = FSTYPE_NONE; FILE *f = fopen("/proc/filesystems", "r"); if (!f) { ntfs_log_perror("Failed to open /proc/filesystems"); return FSTYPE_UNKNOWN; } while (fgets(buf, sizeof(buf), f)) { if (strstr(buf, "fuseblk\n")) { fstype = FSTYPE_FUSEBLK; break; } if (strstr(buf, "fuse\n")) fstype = FSTYPE_FUSE; } fclose(f); return fstype; } static fuse_fstype load_fuse_module(void) { int i; struct stat st; pid_t pid; const char *cmd = "/sbin/modprobe"; char *env = (char*)NULL; struct timespec req = { 0, 100000000 }; /* 100 msec */ fuse_fstype fstype; if (!stat(cmd, &st) && !geteuid()) { pid = fork(); if (!pid) { execle(cmd, cmd, "fuse", (char*)NULL, &env); _exit(1); } else if (pid != -1) waitpid(pid, NULL, 0); } for (i = 0; i < 10; i++) { /* * We sleep first because despite the detection of the loaded * FUSE kernel module, fuse_mount() can still fail if it's not * fully functional/initialized. Note, of course this is still * unreliable but usually helps. */ nanosleep(&req, NULL); fstype = get_fuse_fstype(); if (fstype != FSTYPE_NONE) break; } return fstype; } #endif static struct fuse_chan *try_fuse_mount(char *parsed_options) { struct fuse_chan *fc = NULL; struct fuse_args margs = FUSE_ARGS_INIT(0, NULL); /* The fuse_mount() options get modified, so we always rebuild it */ if ((fuse_opt_add_arg(&margs, EXEC_NAME) == -1 || fuse_opt_add_arg(&margs, "-o") == -1 || fuse_opt_add_arg(&margs, parsed_options) == -1)) { ntfs_log_error("Failed to set FUSE options.\n"); goto free_args; } fc = fuse_mount(opts.mnt_point, &margs); free_args: fuse_opt_free_args(&margs); return fc; } static int set_fuseblk_options(char **parsed_options) { char options[64]; long pagesize; u32 blksize = ctx->vol->cluster_size; pagesize = sysconf(_SC_PAGESIZE); if (pagesize < 1) pagesize = 4096; if (blksize > (u32)pagesize) blksize = pagesize; snprintf(options, sizeof(options), ",blkdev,blksize=%u", blksize); if (ntfs_strappend(parsed_options, options)) return -1; return 0; } static struct fuse *mount_fuse(char *parsed_options) { struct fuse *fh = NULL; struct fuse_args args = FUSE_ARGS_INIT(0, NULL); ctx->fc = try_fuse_mount(parsed_options); if (!ctx->fc) return NULL; if (fuse_opt_add_arg(&args, "") == -1) goto err; if (ctx->ro) { char buf[128]; int len; len = snprintf(buf, sizeof(buf), "-ouse_ino,kernel_cache" ",attr_timeout=%d,entry_timeout=%d", (int)TIMEOUT_RO, (int)TIMEOUT_RO); if ((len < 0) || (len >= (int)sizeof(buf)) || (fuse_opt_add_arg(&args, buf) == -1)) goto err; } else { #if !CACHEING if (fuse_opt_add_arg(&args, "-ouse_ino,kernel_cache" ",attr_timeout=0") == -1) goto err; #else if (fuse_opt_add_arg(&args, "-ouse_ino,kernel_cache" ",attr_timeout=1") == -1) goto err; #endif } if (ctx->debug) if (fuse_opt_add_arg(&args, "-odebug") == -1) goto err; fh = fuse_new(ctx->fc, &args , &ntfs_3g_ops, sizeof(ntfs_3g_ops), NULL); if (!fh) goto err; if (fuse_set_signal_handlers(fuse_get_session(fh))) goto err_destory; out: fuse_opt_free_args(&args); return fh; err_destory: fuse_destroy(fh); fh = NULL; err: fuse_unmount(opts.mnt_point, ctx->fc); goto out; } static void setup_logging(char *parsed_options) { if (!ctx->no_detach) { if (daemon(0, ctx->debug)) ntfs_log_error("Failed to daemonize.\n"); else if (!ctx->debug) { #ifndef DEBUG ntfs_log_set_handler(ntfs_log_handler_syslog); /* Override default libntfs identify. */ openlog(EXEC_NAME, LOG_PID, LOG_DAEMON); #endif } } ctx->seccache = (struct PERMISSIONS_CACHE*)NULL; ntfs_log_info("Version %s %s %d\n", VERSION, FUSE_TYPE, fuse_version()); if (strcmp(opts.arg_device,opts.device)) ntfs_log_info("Requested device %s canonicalized as %s\n", opts.arg_device,opts.device); ntfs_log_info("Mounted %s (%s, label \"%s\", NTFS %d.%d)\n", opts.device, (ctx->ro) ? "Read-Only" : "Read-Write", ctx->vol->vol_name, ctx->vol->major_ver, ctx->vol->minor_ver); ntfs_log_info("Cmdline options: %s\n", opts.options ? opts.options : ""); ntfs_log_info("Mount options: %s\n", parsed_options); } int main(int argc, char *argv[]) { char *parsed_options = NULL; struct fuse *fh; #if !(defined(__sun) && defined (__SVR4)) fuse_fstype fstype = FSTYPE_UNKNOWN; #endif const char *permissions_mode = (const char*)NULL; const char *failed_secure = (const char*)NULL; #if defined(HAVE_SETXATTR) && defined(XATTR_MAPPINGS) struct XATTRMAPPING *xattr_mapping = (struct XATTRMAPPING*)NULL; #endif /* defined(HAVE_SETXATTR) && defined(XATTR_MAPPINGS) */ struct stat sbuf; unsigned long existing_mount; int err, fd; /* * Make sure file descriptors 0, 1 and 2 are open, * otherwise chaos would ensue. */ do { fd = open("/dev/null", O_RDWR); if (fd > 2) close(fd); } while (fd >= 0 && fd <= 2); #ifndef FUSE_INTERNAL if ((getuid() != geteuid()) || (getgid() != getegid())) { fprintf(stderr, "%s", setuid_msg); return NTFS_VOLUME_INSECURE; } #endif if (drop_privs()) return NTFS_VOLUME_NO_PRIVILEGE; ntfs_set_locale(); ntfs_log_set_handler(ntfs_log_handler_stderr); if (ntfs_parse_options(&opts, usage, argc, argv)) { usage(); return NTFS_VOLUME_SYNTAX_ERROR; } if (ntfs_fuse_init()) { err = NTFS_VOLUME_OUT_OF_MEMORY; goto err2; } parsed_options = parse_mount_options(ctx, &opts, FALSE); if (!parsed_options) { err = NTFS_VOLUME_SYNTAX_ERROR; goto err_out; } if (!ntfs_check_if_mounted(opts.device,&existing_mount) && (existing_mount & NTFS_MF_MOUNTED) /* accept multiple read-only mounts */ && (!(existing_mount & NTFS_MF_READONLY) || !ctx->ro)) { err = NTFS_VOLUME_LOCKED; goto err_out; } /* need absolute mount point for junctions */ if (opts.mnt_point[0] == '/') ctx->abs_mnt_point = strdup(opts.mnt_point); else { ctx->abs_mnt_point = (char*)ntfs_malloc(PATH_MAX); if (ctx->abs_mnt_point) { if ((strlen(opts.mnt_point) < PATH_MAX) && getcwd(ctx->abs_mnt_point, PATH_MAX - strlen(opts.mnt_point) - 1)) { strcat(ctx->abs_mnt_point, "/"); strcat(ctx->abs_mnt_point, opts.mnt_point); #if defined(__sun) && defined (__SVR4) /* Solaris also wants the absolute mount point */ opts.mnt_point = ctx->abs_mnt_point; #endif /* defined(__sun) && defined (__SVR4) */ } else { free(ctx->abs_mnt_point); ctx->abs_mnt_point = (char*)NULL; } } } if (!ctx->abs_mnt_point) { err = NTFS_VOLUME_OUT_OF_MEMORY; goto err_out; } ctx->security.uid = 0; ctx->security.gid = 0; if ((opts.mnt_point[0] == '/') && !stat(opts.mnt_point,&sbuf)) { /* collect owner of mount point, useful for default mapping */ ctx->security.uid = sbuf.st_uid; ctx->security.gid = sbuf.st_gid; } #if defined(linux) || defined(__uClinux__) fstype = get_fuse_fstype(); err = NTFS_VOLUME_NO_PRIVILEGE; if (restore_privs()) goto err_out; if (fstype == FSTYPE_NONE || fstype == FSTYPE_UNKNOWN) fstype = load_fuse_module(); create_dev_fuse(); if (drop_privs()) goto err_out; #endif if (stat(opts.device, &sbuf)) { ntfs_log_perror("Failed to access '%s'", opts.device); err = NTFS_VOLUME_NO_PRIVILEGE; goto err_out; } #if !(defined(__sun) && defined (__SVR4)) /* Always use fuseblk for block devices unless it's surely missing. */ if (S_ISBLK(sbuf.st_mode) && (fstype != FSTYPE_FUSE)) ctx->blkdev = TRUE; #endif #ifndef FUSE_INTERNAL if (getuid() && ctx->blkdev) { ntfs_log_error("%s", unpriv_fuseblk_msg); err = NTFS_VOLUME_NO_PRIVILEGE; goto err2; } #endif err = ntfs_open(opts.device); if (err) goto err_out; /* Force read-only mount if the device was found read-only */ if (!ctx->ro && NVolReadOnly(ctx->vol)) { ctx->rw = FALSE; ctx->ro = TRUE; if (ntfs_strinsert(&parsed_options, ",ro")) goto err_out; ntfs_log_info("Could not mount read-write, trying read-only\n"); } else if (ctx->rw && ntfs_strinsert(&parsed_options, ",rw")) goto err_out; /* We must do this after ntfs_open() to be able to set the blksize */ if (ctx->blkdev && set_fuseblk_options(&parsed_options)) goto err_out; ctx->vol->abs_mnt_point = ctx->abs_mnt_point; ctx->security.vol = ctx->vol; ctx->vol->secure_flags = ctx->secure_flags; ctx->vol->special_files = ctx->special_files; #ifdef HAVE_SETXATTR /* extended attributes interface required */ ctx->vol->efs_raw = ctx->efs_raw; #endif /* HAVE_SETXATTR */ if (!ntfs_build_mapping(&ctx->security,ctx->usermap_path, (ctx->vol->secure_flags & ((1 << SECURITY_DEFAULT) | (1 << SECURITY_ACL))) && !ctx->inherit && !(ctx->vol->secure_flags & (1 << SECURITY_WANTED)))) { #if POSIXACLS /* use basic permissions if requested */ if (ctx->vol->secure_flags & (1 << SECURITY_DEFAULT)) permissions_mode = "User mapping built, Posix ACLs not used"; else { permissions_mode = "User mapping built, Posix ACLs in use"; #if KERNELACLS if (ntfs_strinsert(&parsed_options, ",default_permissions,acl")) { err = NTFS_VOLUME_SYNTAX_ERROR; goto err_out; } #endif /* KERNELACLS */ } #else /* POSIXACLS */ #if KERNELPERMS if (!(ctx->vol->secure_flags & ((1 << SECURITY_DEFAULT) | (1 << SECURITY_ACL)))) { /* * No explicit option but user mapping found * force default security */ ctx->vol->secure_flags |= (1 << SECURITY_DEFAULT); if (ntfs_strinsert(&parsed_options, ",default_permissions")) { err = NTFS_VOLUME_SYNTAX_ERROR; goto err_out; } } #endif /* KERNELPERMS */ permissions_mode = "User mapping built"; #endif /* POSIXACLS */ ctx->dmask = ctx->fmask = 0; } else { ctx->security.uid = ctx->uid; ctx->security.gid = ctx->gid; /* same ownership/permissions for all files */ ctx->security.mapping[MAPUSERS] = (struct MAPPING*)NULL; ctx->security.mapping[MAPGROUPS] = (struct MAPPING*)NULL; if ((ctx->vol->secure_flags & (1 << SECURITY_WANTED)) && !(ctx->vol->secure_flags & (1 << SECURITY_DEFAULT))) { ctx->vol->secure_flags |= (1 << SECURITY_DEFAULT); if (ntfs_strinsert(&parsed_options, ",default_permissions")) { err = NTFS_VOLUME_SYNTAX_ERROR; goto err_out; } } if (ctx->vol->secure_flags & (1 << SECURITY_DEFAULT)) { ctx->vol->secure_flags |= (1 << SECURITY_RAW); permissions_mode = "Global ownership and permissions enforced"; } else { ctx->vol->secure_flags &= ~(1 << SECURITY_RAW); permissions_mode = "Ownership and permissions disabled"; } } if (ctx->usermap_path) free (ctx->usermap_path); #if defined(HAVE_SETXATTR) && defined(XATTR_MAPPINGS) xattr_mapping = ntfs_xattr_build_mapping(ctx->vol, ctx->xattrmap_path); ctx->vol->xattr_mapping = xattr_mapping; /* * Errors are logged, do not refuse mounting, it would be * too difficult to fix the unmountable mapping file. */ if (ctx->xattrmap_path) free(ctx->xattrmap_path); #endif /* defined(HAVE_SETXATTR) && defined(XATTR_MAPPINGS) */ #ifndef DISABLE_PLUGINS register_internal_reparse_plugins(); #endif /* DISABLE_PLUGINS */ fh = mount_fuse(parsed_options); if (!fh) { err = NTFS_VOLUME_FUSE_ERROR; goto err_out; } ctx->mounted = TRUE; #if defined(linux) || defined(__uClinux__) if (S_ISBLK(sbuf.st_mode) && (fstype == FSTYPE_FUSE)) ntfs_log_info("%s", fuse26_kmod_msg); #endif setup_logging(parsed_options); if (failed_secure) ntfs_log_info("%s\n",failed_secure); if (permissions_mode) ntfs_log_info("%s, configuration type %d\n",permissions_mode, 4 + POSIXACLS*6 - KERNELPERMS*3 + CACHEING); if ((ctx->vol->secure_flags & (1 << SECURITY_RAW)) && !ctx->uid && ctx->gid) ntfs_log_error("Warning : using problematic uid==0 and gid!=0\n"); fuse_loop(fh); err = 0; fuse_unmount(opts.mnt_point, ctx->fc); fuse_destroy(fh); err_out: ntfs_mount_error(opts.device, opts.mnt_point, err); if (ctx->abs_mnt_point) free(ctx->abs_mnt_point); #if defined(HAVE_SETXATTR) && defined(XATTR_MAPPINGS) ntfs_xattr_free_mapping(xattr_mapping); #endif /* defined(HAVE_SETXATTR) && defined(XATTR_MAPPINGS) */ err2: ntfs_close(); #ifndef DISABLE_PLUGINS close_reparse_plugins(ctx); #endif /* DISABLE_PLUGINS */ free(ctx); free(parsed_options); free(opts.options); free(opts.device); return err; } ntfs-3g-2026.2.25/libntfs-3g/0000775000175000017500000000000015152260235011027 5ntfs-3g-2026.2.25/libntfs-3g/inode.c0000664000175000017500000012642415152260173012223 /** * inode.c - Inode handling code. Originated from the Linux-NTFS project. * * Copyright (c) 2002-2005 Anton Altaparmakov * Copyright (c) 2002-2008 Szabolcs Szakacsits * Copyright (c) 2004-2007 Yura Pakhuchiy * Copyright (c) 2004-2005 Richard Russon * Copyright (c) 2009-2010 Jean-Pierre Andre * * This program/include file 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/include file 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_STDLIB_H #include #endif #ifdef HAVE_STRING_H #include #endif #ifdef HAVE_ERRNO_H #include #endif #include "param.h" #include "compat.h" #include "types.h" #include "volume.h" #include "cache.h" #include "inode.h" #include "attrib.h" #include "debug.h" #include "mft.h" #include "attrlist.h" #include "runlist.h" #include "lcnalloc.h" #include "index.h" #include "dir.h" #include "ntfstime.h" #include "logging.h" #include "misc.h" #include "xattrs.h" ntfs_inode *ntfs_inode_base(ntfs_inode *ni) { if (ni->nr_extents == -1) return ni->base_ni; return ni; } /** * ntfs_inode_mark_dirty - set the inode (and its base inode if it exists) dirty * @ni: ntfs inode to set dirty * * Set the inode @ni dirty so it is written out later (at the latest at * ntfs_inode_close() time). If @ni is an extent inode, set the base inode * dirty, too. * * This function cannot fail. */ void ntfs_inode_mark_dirty(ntfs_inode *ni) { NInoSetDirty(ni); if (ni->nr_extents == -1) NInoSetDirty(ni->base_ni); } /** * __ntfs_inode_allocate - Create and initialise an NTFS inode object * @vol: * * Description... * * Returns: */ static ntfs_inode *__ntfs_inode_allocate(ntfs_volume *vol) { ntfs_inode *ni; ni = (ntfs_inode*)ntfs_calloc(sizeof(ntfs_inode)); if (ni) ni->vol = vol; return ni; } /** * ntfs_inode_allocate - Create an NTFS inode object * @vol: * * Description... * * Returns: */ ntfs_inode *ntfs_inode_allocate(ntfs_volume *vol) { return __ntfs_inode_allocate(vol); } /** * __ntfs_inode_release - Destroy an NTFS inode object * @ni: * * Description... * * Returns: */ static void __ntfs_inode_release(ntfs_inode *ni) { if (NInoDirty(ni)) ntfs_log_error("Releasing dirty inode %lld!\n", (long long)ni->mft_no); if (NInoAttrList(ni) && ni->attr_list) free(ni->attr_list); free(ni->mrec); free(ni); return; } /** * ntfs_inode_open - open an inode ready for access * @vol: volume to get the inode from * @mref: inode number / mft record number to open * * Allocate an ntfs_inode structure and initialize it for the given inode * specified by @mref. @mref specifies the inode number / mft record to read, * including the sequence number, which can be 0 if no sequence number checking * is to be performed. * * Then, allocate a buffer for the mft record, read the mft record from the * volume @vol, and attach it to the ntfs_inode structure (->mrec). The * mft record is mst deprotected and sanity checked for validity and we abort * if deprotection or checks fail. * * Finally, search for an attribute list attribute in the mft record and if one * is found, load the attribute list attribute value and attach it to the * ntfs_inode structure (->attr_list). Also set the NI_AttrList bit to indicate * this. * * Return a pointer to the ntfs_inode structure on success or NULL on error, * with errno set to the error code. */ static ntfs_inode *ntfs_inode_real_open(ntfs_volume *vol, const MFT_REF mref) { s64 l; ntfs_inode *ni = NULL; ntfs_attr_search_ctx *ctx; STANDARD_INFORMATION *std_info; le32 lthle; int olderrno; ntfs_log_enter("Entering for inode %lld\n", (long long)MREF(mref)); if (!vol) { errno = EINVAL; goto out; } ni = __ntfs_inode_allocate(vol); if (!ni) goto out; if (ntfs_file_record_read(vol, mref, &ni->mrec, NULL)) goto err_out; if (!(ni->mrec->flags & MFT_RECORD_IN_USE)) { errno = ENOENT; goto err_out; } ni->mft_no = MREF(mref); ctx = ntfs_attr_get_search_ctx(ni, NULL); if (!ctx) goto err_out; /* Receive some basic information about inode. */ if (ntfs_attr_lookup(AT_STANDARD_INFORMATION, AT_UNNAMED, 0, CASE_SENSITIVE, 0, NULL, 0, ctx)) { if (!ni->mrec->base_mft_record) ntfs_log_perror("No STANDARD_INFORMATION in base record" " %lld", (long long)MREF(mref)); goto put_err_out; } lthle = ctx->attr->value_length; if (le32_to_cpu(lthle) < offsetof(STANDARD_INFORMATION, owner_id)) { ntfs_log_error("Corrupt STANDARD_INFORMATION in base" " record %lld\n", (long long)MREF(mref)); goto put_err_out; } std_info = (STANDARD_INFORMATION *)((u8 *)ctx->attr + le16_to_cpu(ctx->attr->value_offset)); ni->flags = std_info->file_attributes; ni->creation_time = std_info->creation_time; ni->last_data_change_time = std_info->last_data_change_time; ni->last_mft_change_time = std_info->last_mft_change_time; ni->last_access_time = std_info->last_access_time; /* Insert v3 extensions if present */ /* length may be seen as 48 (v1.x) or 72 (v3.x) */ if (le32_to_cpu(lthle) >= offsetof(STANDARD_INFORMATION, v3_end)) { set_nino_flag(ni, v3_Extensions); ni->owner_id = std_info->owner_id; ni->security_id = std_info->security_id; ni->quota_charged = std_info->quota_charged; ni->usn = std_info->usn; } else { clear_nino_flag(ni, v3_Extensions); ni->owner_id = const_cpu_to_le32(0); ni->security_id = const_cpu_to_le32(0); } /* Set attribute list information. */ olderrno = errno; if (ntfs_attr_lookup(AT_ATTRIBUTE_LIST, AT_UNNAMED, 0, CASE_SENSITIVE, 0, NULL, 0, ctx)) { if (errno != ENOENT) goto put_err_out; /* Attribute list attribute does not present. */ /* restore previous errno to avoid misinterpretation */ errno = olderrno; goto get_size; } NInoSetAttrList(ni); l = ntfs_get_attribute_value_length(ctx->attr); if (!l) goto put_err_out; if ((u64)l > 0x40000) { errno = EIO; ntfs_log_perror("Too large attrlist attribute (%llu), inode " "%lld", (long long)l, (long long)MREF(mref)); goto put_err_out; } ni->attr_list_size = l; ni->attr_list = ntfs_malloc(ni->attr_list_size); if (!ni->attr_list) goto put_err_out; l = ntfs_get_attribute_value(vol, ctx->attr, ni->attr_list); if (!l) goto put_err_out; if (l != ni->attr_list_size) { errno = EIO; ntfs_log_perror("Unexpected attrlist size (%lld <> %u), inode " "%lld", (long long)l, ni->attr_list_size, (long long)MREF(mref)); goto put_err_out; } get_size: olderrno = errno; if (ntfs_attr_lookup(AT_DATA, AT_UNNAMED, 0, 0, 0, NULL, 0, ctx)) { if (errno != ENOENT) goto put_err_out; /* Directory or special file. */ /* restore previous errno to avoid misinterpretation */ errno = olderrno; ni->data_size = ni->allocated_size = 0; } else { if (ctx->attr->non_resident) { ni->data_size = sle64_to_cpu(ctx->attr->data_size); if (ctx->attr->flags & (ATTR_IS_COMPRESSED | ATTR_IS_SPARSE)) ni->allocated_size = sle64_to_cpu( ctx->attr->compressed_size); else ni->allocated_size = sle64_to_cpu( ctx->attr->allocated_size); } else { ni->data_size = le32_to_cpu(ctx->attr->value_length); ni->allocated_size = (ni->data_size + 7) & ~7; } set_nino_flag(ni,KnownSize); } ntfs_attr_put_search_ctx(ctx); out: ntfs_log_leave("\n"); return ni; put_err_out: ntfs_attr_put_search_ctx(ctx); err_out: __ntfs_inode_release(ni); ni = NULL; goto out; } /** * ntfs_inode_close - close an ntfs inode and free all associated memory * @ni: ntfs inode to close * * Make sure the ntfs inode @ni is clean. * * If the ntfs inode @ni is a base inode, close all associated extent inodes, * then deallocate all memory attached to it, and finally free the ntfs inode * structure itself. * * If it is an extent inode, we disconnect it from its base inode before we * destroy it. * * It is OK to pass NULL to this function, it is just noop in this case. * * Return 0 on success or -1 on error with errno set to the error code. On * error, @ni has not been freed. The user should attempt to handle the error * and call ntfs_inode_close() again. The following error codes are defined: * * EBUSY @ni and/or its attribute list runlist is/are dirty and the * attempt to write it/them to disk failed. * EINVAL @ni is invalid (probably it is an extent inode). * EIO I/O error while trying to write inode to disk. */ int ntfs_inode_real_close(ntfs_inode *ni) { int ret = -1; if (!ni) return 0; ntfs_log_enter("Entering for inode %lld\n", (long long)ni->mft_no); /* If we have dirty metadata, write it out. */ if (NInoDirty(ni) || NInoAttrListDirty(ni)) { if (ntfs_inode_sync(ni)) { if (errno != EIO) errno = EBUSY; goto err; } } /* Is this a base inode with mapped extent inodes? */ if (ni->nr_extents > 0) { while (ni->nr_extents > 0) { if (ntfs_inode_real_close(ni->extent_nis[0])) { if (errno != EIO) errno = EBUSY; goto err; } } } else if (ni->nr_extents == -1) { ntfs_inode **tmp_nis; ntfs_inode *base_ni; s32 i; /* * If the inode is an extent inode, disconnect it from the * base inode before destroying it. */ base_ni = ni->base_ni; for (i = 0; i < base_ni->nr_extents; ++i) { tmp_nis = base_ni->extent_nis; if (tmp_nis[i] != ni) continue; /* Found it. Disconnect. */ memmove(tmp_nis + i, tmp_nis + i + 1, (base_ni->nr_extents - i - 1) * sizeof(ntfs_inode *)); /* Buffer should be for multiple of four extents. */ if ((--base_ni->nr_extents) & 3) { i = -1; break; } /* * ElectricFence is unhappy with realloc(x,0) as free(x) * thus we explicitly separate these two cases. */ if (base_ni->nr_extents) { /* Resize the memory buffer. */ tmp_nis = realloc(tmp_nis, base_ni->nr_extents * sizeof(ntfs_inode *)); /* Ignore errors, they don't really matter. */ if (tmp_nis) base_ni->extent_nis = tmp_nis; } else if (tmp_nis) { free(tmp_nis); base_ni->extent_nis = (ntfs_inode**)NULL; } /* Allow for error checking. */ i = -1; break; } /* * We could successfully sync, so only log this error * and try to sync other inode extents too. */ if (i != -1) ntfs_log_error("Extent inode %lld was not found\n", (long long)ni->mft_no); } __ntfs_inode_release(ni); ret = 0; err: ntfs_log_leave("\n"); return ret; } #if CACHE_NIDATA_SIZE /* * Free an inode structure when there is not more space * in the cache */ void ntfs_inode_nidata_free(const struct CACHED_GENERIC *cached) { ntfs_inode_real_close(((const struct CACHED_NIDATA*)cached)->ni); } /* * Compute a hash value for an inode entry */ int ntfs_inode_nidata_hash(const struct CACHED_GENERIC *item) { return (((const struct CACHED_NIDATA*)item)->inum % (2*CACHE_NIDATA_SIZE)); } /* * inum comparing for entering/fetching from cache */ static int idata_cache_compare(const struct CACHED_GENERIC *cached, const struct CACHED_GENERIC *wanted) { return (((const struct CACHED_NIDATA*)cached)->inum != ((const struct CACHED_NIDATA*)wanted)->inum); } /* * Invalidate an inode entry when not needed anymore. * The entry should have been synced, it may be reused later, * if it is requested before it is dropped from cache. */ void ntfs_inode_invalidate(ntfs_volume *vol, const MFT_REF mref) { struct CACHED_NIDATA item; item.inum = MREF(mref); item.ni = (ntfs_inode*)NULL; item.pathname = (const char*)NULL; item.varsize = 0; ntfs_invalidate_cache(vol->nidata_cache, GENERIC(&item),idata_cache_compare,CACHE_FREE); } #endif /* * Open an inode * * When possible, an entry recorded in the cache is reused * * **NEVER REOPEN** an inode, this can lead to a duplicated * cache entry (hard to detect), and to an obsolete one being * reused. System files are however protected from being cached. */ ntfs_inode *ntfs_inode_open(ntfs_volume *vol, const MFT_REF mref) { ntfs_inode *ni; #if CACHE_NIDATA_SIZE struct CACHED_NIDATA item; struct CACHED_NIDATA *cached; /* fetch idata from cache */ item.inum = MREF(mref); debug_double_inode(item.inum,1); item.pathname = (const char*)NULL; item.varsize = 0; cached = (struct CACHED_NIDATA*)ntfs_fetch_cache(vol->nidata_cache, GENERIC(&item),idata_cache_compare); if (cached) { ni = cached->ni; /* do not keep open entries in cache */ ntfs_remove_cache(vol->nidata_cache, (struct CACHED_GENERIC*)cached,0); } else { ni = ntfs_inode_real_open(vol, mref); } if (!ni) { debug_double_inode(item.inum, 0); } #else ni = ntfs_inode_real_open(vol, mref); #endif return (ni); } /* * Close an inode entry * * If cacheing is in use, the entry is synced and kept available * in cache for further use. * * System files (inode < 16 or having the IS_4 flag) are protected * against being cached. */ int ntfs_inode_close(ntfs_inode *ni) { int res; #if CACHE_NIDATA_SIZE BOOL dirty; struct CACHED_NIDATA item; if (ni) { debug_double_inode(ni->mft_no,0); /* do not cache system files : could lead to double entries */ if (ni->vol && ni->vol->nidata_cache && ((ni->mft_no == FILE_root) || ((ni->mft_no >= FILE_first_user) && !(ni->mrec->flags & MFT_RECORD_IS_4)))) { /* If we have dirty metadata, write it out. */ dirty = NInoDirty(ni) || NInoAttrListDirty(ni); if (dirty) { res = ntfs_inode_sync(ni); /* do a real close if sync failed */ if (res) ntfs_inode_real_close(ni); } else res = 0; if (!res) { /* feed idata into cache */ item.inum = ni->mft_no; item.ni = ni; item.pathname = (const char*)NULL; item.varsize = 0; debug_cached_inode(ni); ntfs_enter_cache(ni->vol->nidata_cache, GENERIC(&item), idata_cache_compare); } } else { /* cache not ready or system file, really close */ res = ntfs_inode_real_close(ni); } } else res = 0; #else res = ntfs_inode_real_close(ni); #endif return (res); } /** * ntfs_extent_inode_open - load an extent inode and attach it to its base * @base_ni: base ntfs inode * @mref: mft reference of the extent inode to load (in little endian) * * First check if the extent inode @mref is already attached to the base ntfs * inode @base_ni, and if so, return a pointer to the attached extent inode. * * If the extent inode is not already attached to the base inode, allocate an * ntfs_inode structure and initialize it for the given inode @mref. @mref * specifies the inode number / mft record to read, including the sequence * number, which can be 0 if no sequence number checking is to be performed. * * Then, allocate a buffer for the mft record, read the mft record from the * volume @base_ni->vol, and attach it to the ntfs_inode structure (->mrec). * The mft record is mst deprotected and sanity checked for validity and we * abort if deprotection or checks fail. * * Finally attach the ntfs inode to its base inode @base_ni and return a * pointer to the ntfs_inode structure on success or NULL on error, with errno * set to the error code. * * Note, extent inodes are never closed directly. They are automatically * disposed off by the closing of the base inode. */ ntfs_inode *ntfs_extent_inode_open(ntfs_inode *base_ni, const leMFT_REF mref) { u64 mft_no = MREF_LE(mref); VCN extent_vcn; runlist_element *rl; ntfs_volume *vol; ntfs_inode *ni = NULL; ntfs_inode **extent_nis; int i; if (!base_ni) { errno = EINVAL; ntfs_log_perror("%s", __FUNCTION__); return NULL; } ntfs_log_enter("Opening extent inode %lld (base mft record %lld).\n", (unsigned long long)mft_no, (unsigned long long)base_ni->mft_no); if (!base_ni->mft_no) { /* * When getting extents of MFT, we must be sure * they are in the MFT part which has already * been mapped, otherwise we fall into an endless * recursion. * Situations have been met where extents locations * are described in themselves. * This is a severe error which chkdsk cannot fix. */ vol = base_ni->vol; extent_vcn = mft_no << vol->mft_record_size_bits >> vol->cluster_size_bits; rl = vol->mft_na->rl; if (rl) { while (rl->length && ((rl->vcn + rl->length) <= extent_vcn)) rl++; } if (!rl || (rl->lcn < 0)) { ntfs_log_error("MFT is corrupt, cannot read" " its unmapped extent record %lld\n", (long long)mft_no); ntfs_log_error("Note : chkdsk cannot fix this," " try ntfsfix\n"); errno = EIO; ni = (ntfs_inode*)NULL; goto out; } } /* Is the extent inode already open and attached to the base inode? */ if (base_ni->nr_extents > 0) { extent_nis = base_ni->extent_nis; for (i = 0; i < base_ni->nr_extents; i++) { u16 seq_no; ni = extent_nis[i]; if (mft_no != ni->mft_no) continue; /* Verify the sequence number if given. */ seq_no = MSEQNO_LE(mref); if (seq_no && seq_no != le16_to_cpu( ni->mrec->sequence_number)) { errno = EIO; ntfs_log_perror("Found stale extent mft " "reference mft=%lld", (long long)ni->mft_no); goto out; } goto out; } } /* Wasn't there, we need to load the extent inode. */ ni = __ntfs_inode_allocate(base_ni->vol); if (!ni) goto out; if (ntfs_file_record_read(base_ni->vol, le64_to_cpu(mref), &ni->mrec, NULL)) goto err_out; ni->mft_no = mft_no; ni->nr_extents = -1; ni->base_ni = base_ni; /* Attach extent inode to base inode, reallocating memory if needed. */ if (!(base_ni->nr_extents & 3)) { i = (base_ni->nr_extents + 4) * sizeof(ntfs_inode *); extent_nis = ntfs_malloc(i); if (!extent_nis) goto err_out; if (base_ni->nr_extents) { memcpy(extent_nis, base_ni->extent_nis, i - 4 * sizeof(ntfs_inode *)); free(base_ni->extent_nis); } base_ni->extent_nis = extent_nis; } base_ni->extent_nis[base_ni->nr_extents++] = ni; out: ntfs_log_leave("\n"); return ni; err_out: __ntfs_inode_release(ni); ni = NULL; goto out; } /** * ntfs_inode_attach_all_extents - attach all extents for target inode * @ni: opened ntfs inode for which perform attach * * Return 0 on success and -1 on error with errno set to the error code. */ int ntfs_inode_attach_all_extents(ntfs_inode *ni) { ATTR_LIST_ENTRY *ale; u64 prev_attached = 0; if (!ni) { ntfs_log_trace("Invalid arguments.\n"); errno = EINVAL; return -1; } if (ni->nr_extents == -1) ni = ni->base_ni; ntfs_log_trace("Entering for inode 0x%llx.\n", (long long) ni->mft_no); /* Inode haven't got attribute list, thus nothing to attach. */ if (!NInoAttrList(ni)) return 0; if (!ni->attr_list) { ntfs_log_trace("Corrupt in-memory struct.\n"); errno = EINVAL; return -1; } /* Walk through attribute list and attach all extents. */ errno = 0; ale = (ATTR_LIST_ENTRY *)ni->attr_list; while ((u8*)ale < ni->attr_list + ni->attr_list_size) { if (ni->mft_no != MREF_LE(ale->mft_reference) && prev_attached != MREF_LE(ale->mft_reference)) { if (!ntfs_extent_inode_open(ni, ale->mft_reference)) { ntfs_log_trace("Couldn't attach extent inode.\n"); return -1; } prev_attached = MREF_LE(ale->mft_reference); } ale = (ATTR_LIST_ENTRY *)((u8*)ale + le16_to_cpu(ale->length)); } return 0; } /** * ntfs_inode_sync_standard_information - update standard information attribute * @ni: ntfs inode to update standard information * * Return 0 on success or -1 on error with errno set to the error code. */ static int ntfs_inode_sync_standard_information(ntfs_inode *ni) { ntfs_attr_search_ctx *ctx; STANDARD_INFORMATION *std_info; u32 lth; le32 lthle; ntfs_log_trace("Entering for inode %lld\n", (long long)ni->mft_no); ctx = ntfs_attr_get_search_ctx(ni, NULL); if (!ctx) return -1; if (ntfs_attr_lookup(AT_STANDARD_INFORMATION, AT_UNNAMED, 0, CASE_SENSITIVE, 0, NULL, 0, ctx)) { ntfs_log_perror("Failed to sync standard info (inode %lld)", (long long)ni->mft_no); ntfs_attr_put_search_ctx(ctx); return -1; } std_info = (STANDARD_INFORMATION *)((u8 *)ctx->attr + le16_to_cpu(ctx->attr->value_offset)); std_info->file_attributes = ni->flags; if (!test_nino_flag(ni, TimesSet)) { std_info->creation_time = ni->creation_time; std_info->last_data_change_time = ni->last_data_change_time; std_info->last_mft_change_time = ni->last_mft_change_time; std_info->last_access_time = ni->last_access_time; } /* JPA update v3.x extensions, ensuring consistency */ lthle = ctx->attr->value_length; lth = le32_to_cpu(lthle); if (test_nino_flag(ni, v3_Extensions) && (lth < offsetof(STANDARD_INFORMATION, v3_end))) ntfs_log_error("bad sync of standard information\n"); if (lth >= offsetof(STANDARD_INFORMATION, v3_end)) { std_info->owner_id = ni->owner_id; std_info->security_id = ni->security_id; std_info->quota_charged = ni->quota_charged; std_info->usn = ni->usn; } ntfs_inode_mark_dirty(ctx->ntfs_ino); ntfs_attr_put_search_ctx(ctx); return 0; } /** * ntfs_inode_sync_file_name - update FILE_NAME attributes * @ni: ntfs inode to update FILE_NAME attributes * * Update all FILE_NAME attributes for inode @ni in the index. * * Return 0 on success or -1 on error with errno set to the error code. */ static int ntfs_inode_sync_file_name(ntfs_inode *ni, ntfs_inode *dir_ni) { ntfs_attr_search_ctx *ctx = NULL; ntfs_index_context *ictx; ntfs_inode *index_ni; FILE_NAME_ATTR *fn; FILE_NAME_ATTR *fnx; REPARSE_POINT *rpp; le32 reparse_tag; int err = 0; ntfs_log_trace("Entering for inode %lld\n", (long long)ni->mft_no); ctx = ntfs_attr_get_search_ctx(ni, NULL); if (!ctx) { err = errno; goto err_out; } /* Collect the reparse tag, if any */ reparse_tag = const_cpu_to_le32(0); if (ni->flags & FILE_ATTR_REPARSE_POINT) { if (!ntfs_attr_lookup(AT_REPARSE_POINT, NULL, 0, CASE_SENSITIVE, 0, NULL, 0, ctx)) { rpp = (REPARSE_POINT*)((u8 *)ctx->attr + le16_to_cpu(ctx->attr->value_offset)); reparse_tag = rpp->reparse_tag; } ntfs_attr_reinit_search_ctx(ctx); } /* Walk through all FILE_NAME attributes and update them. */ while (!ntfs_attr_lookup(AT_FILE_NAME, NULL, 0, 0, 0, NULL, 0, ctx)) { fn = (FILE_NAME_ATTR *)((u8 *)ctx->attr + le16_to_cpu(ctx->attr->value_offset)); if (MREF_LE(fn->parent_directory) == ni->mft_no) { /* * WARNING: We cheat here and obtain 2 attribute * search contexts for one inode (first we obtained * above, second will be obtained inside * ntfs_index_lookup), it's acceptable for library, * but will deadlock in the kernel. */ index_ni = ni; } else if (dir_ni) index_ni = dir_ni; else index_ni = ntfs_inode_open(ni->vol, le64_to_cpu(fn->parent_directory)); if (!index_ni) { if (!err) err = errno; ntfs_log_perror("Failed to open inode %lld with index", (long long)MREF_LE(fn->parent_directory)); continue; } ictx = ntfs_index_ctx_get(index_ni, NTFS_INDEX_I30, 4); if (!ictx) { if (!err) err = errno; ntfs_log_perror("Failed to get index ctx, inode %lld", (long long)index_ni->mft_no); if ((ni != index_ni) && !dir_ni && ntfs_inode_close(index_ni) && !err) err = errno; continue; } if (ntfs_index_lookup(fn, sizeof(FILE_NAME_ATTR), ictx)) { if (!err) { if (errno == ENOENT) err = EIO; else err = errno; } ntfs_log_perror("Index lookup failed, inode %lld", (long long)index_ni->mft_no); ntfs_index_ctx_put(ictx); if (ni != index_ni && ntfs_inode_close(index_ni) && !err) err = errno; continue; } /* Update flags and file size. */ fnx = (FILE_NAME_ATTR *)ictx->data; fnx->file_attributes = (fnx->file_attributes & ~FILE_ATTR_VALID_FLAGS) | (ni->flags & FILE_ATTR_VALID_FLAGS); if (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) fnx->data_size = fnx->allocated_size = const_cpu_to_sle64(0); else { fnx->allocated_size = cpu_to_sle64(ni->allocated_size); fnx->data_size = cpu_to_sle64(ni->data_size); /* * The file name record has also to be fixed if some * attribute update implied the unnamed data to be * made non-resident */ fn->allocated_size = fnx->allocated_size; } /* update or clear the reparse tag in the index */ fnx->reparse_point_tag = reparse_tag; if (!test_nino_flag(ni, TimesSet)) { fnx->creation_time = ni->creation_time; fnx->last_data_change_time = ni->last_data_change_time; fnx->last_mft_change_time = ni->last_mft_change_time; fnx->last_access_time = ni->last_access_time; } else { fnx->creation_time = fn->creation_time; fnx->last_data_change_time = fn->last_data_change_time; fnx->last_mft_change_time = fn->last_mft_change_time; fnx->last_access_time = fn->last_access_time; } ntfs_index_entry_mark_dirty(ictx); ntfs_index_ctx_put(ictx); if ((ni != index_ni) && !dir_ni && ntfs_inode_close(index_ni) && !err) err = errno; } /* Check for real error occurred. */ if (errno != ENOENT) { err = errno; ntfs_log_perror("Attribute lookup failed, inode %lld", (long long)ni->mft_no); goto err_out; } ntfs_attr_put_search_ctx(ctx); if (err) { errno = err; return -1; } return 0; err_out: if (ctx) ntfs_attr_put_search_ctx(ctx); errno = err; return -1; } /** * ntfs_inode_sync - write the inode (and its dirty extents) to disk * @ni: ntfs inode to write * * Write the inode @ni to disk as well as its dirty extent inodes if such * exist and @ni is a base inode. If @ni is an extent inode, only @ni is * written completely disregarding its base inode and any other extent inodes. * * For a base inode with dirty extent inodes if any writes fail for whatever * reason, the failing inode is skipped and the sync process is continued. At * the end the error condition that brought about the failure is returned. Thus * the smallest amount of data loss possible occurs. * * Return 0 on success or -1 on error with errno set to the error code. * The following error codes are defined: * EINVAL - Invalid arguments were passed to the function. * EBUSY - Inode and/or one of its extents is busy, try again later. * EIO - I/O error while writing the inode (or one of its extents). */ static int ntfs_inode_sync_in_dir(ntfs_inode *ni, ntfs_inode *dir_ni) { int ret = 0; int err = 0; if (!ni) { errno = EINVAL; ntfs_log_error("Failed to sync NULL inode\n"); return -1; } ntfs_log_enter("Entering for inode %lld\n", (long long)ni->mft_no); /* Update STANDARD_INFORMATION. */ if ((ni->mrec->flags & MFT_RECORD_IN_USE) && ni->nr_extents != -1 && ntfs_inode_sync_standard_information(ni)) { if (!err || errno == EIO) { err = errno; if (err != EIO) err = EBUSY; } } /* Update FILE_NAME's in the index. */ if ((ni->mrec->flags & MFT_RECORD_IN_USE) && ni->nr_extents != -1 && NInoFileNameTestAndClearDirty(ni) && ntfs_inode_sync_file_name(ni, dir_ni)) { if (!err || errno == EIO) { err = errno; if (err != EIO) err = EBUSY; } ntfs_log_perror("Failed to sync FILE_NAME (inode %lld)", (long long)ni->mft_no); NInoFileNameSetDirty(ni); } /* Write out attribute list from cache to disk. */ if ((ni->mrec->flags & MFT_RECORD_IN_USE) && ni->nr_extents != -1 && NInoAttrList(ni) && NInoAttrListTestAndClearDirty(ni)) { ntfs_attr *na; na = ntfs_attr_open(ni, AT_ATTRIBUTE_LIST, AT_UNNAMED, 0); if (!na) { if (!err || errno == EIO) { err = errno; if (err != EIO) err = EBUSY; ntfs_log_perror("Attribute list sync failed " "(open, inode %lld)", (long long)ni->mft_no); } NInoAttrListSetDirty(ni); goto sync_inode; } if (na->data_size == ni->attr_list_size) { if (ntfs_attr_pwrite(na, 0, ni->attr_list_size, ni->attr_list) != ni->attr_list_size) { if (!err || errno == EIO) { err = errno; if (err != EIO) err = EBUSY; ntfs_log_perror("Attribute list sync " "failed (write, inode %lld)", (long long)ni->mft_no); } NInoAttrListSetDirty(ni); } } else { err = EIO; ntfs_log_error("Attribute list sync failed (bad size, " "inode %lld)\n", (long long)ni->mft_no); NInoAttrListSetDirty(ni); } ntfs_attr_close(na); } sync_inode: /* Write this inode out to the $MFT (and $MFTMirr if applicable). */ if (NInoTestAndClearDirty(ni)) { if (ntfs_mft_record_write(ni->vol, ni->mft_no, ni->mrec)) { if (!err || errno == EIO) { err = errno; if (err != EIO) err = EBUSY; } NInoSetDirty(ni); ntfs_log_perror("MFT record sync failed, inode %lld", (long long)ni->mft_no); } } /* If this is a base inode with extents write all dirty extents, too. */ if (ni->nr_extents > 0) { s32 i; for (i = 0; i < ni->nr_extents; ++i) { ntfs_inode *eni; eni = ni->extent_nis[i]; if (!NInoTestAndClearDirty(eni)) continue; if (ntfs_mft_record_write(eni->vol, eni->mft_no, eni->mrec)) { if (!err || errno == EIO) { err = errno; if (err != EIO) err = EBUSY; } NInoSetDirty(eni); ntfs_log_perror("Extent MFT record sync failed," " inode %lld/%lld", (long long)ni->mft_no, (long long)eni->mft_no); } } } if (err) { errno = err; ret = -1; } ntfs_log_leave("\n"); return ret; } int ntfs_inode_sync(ntfs_inode *ni) { return (ntfs_inode_sync_in_dir(ni, (ntfs_inode*)NULL)); } /* * Close an inode with an open parent inode */ int ntfs_inode_close_in_dir(ntfs_inode *ni, ntfs_inode *dir_ni) { int res; res = ntfs_inode_sync_in_dir(ni, dir_ni); if (res) { if (errno != EIO) errno = EBUSY; } else res = ntfs_inode_close(ni); return (res); } /** * ntfs_inode_add_attrlist - add attribute list to inode and fill it * @ni: opened ntfs inode to which add attribute list * * Return 0 on success or -1 on error with errno set to the error code. * The following error codes are defined: * EINVAL - Invalid arguments were passed to the function. * EEXIST - Attribute list already exist. * EIO - Input/Ouput error occurred. * ENOMEM - Not enough memory to perform add. */ int ntfs_inode_add_attrlist(ntfs_inode *ni) { int err; ntfs_attr_search_ctx *ctx; u8 *al = NULL, *aln; int al_len = 0; ATTR_LIST_ENTRY *ale = NULL; ntfs_attr *na; if (!ni) { errno = EINVAL; ntfs_log_perror("%s", __FUNCTION__); return -1; } ntfs_log_trace("inode %llu\n", (unsigned long long) ni->mft_no); if (NInoAttrList(ni) || ni->nr_extents) { errno = EEXIST; ntfs_log_perror("Inode already has attribute list"); return -1; } /* Form attribute list. */ ctx = ntfs_attr_get_search_ctx(ni, NULL); if (!ctx) { err = errno; goto err_out; } /* Walk through all attributes. */ while (!ntfs_attr_lookup(AT_UNUSED, NULL, 0, 0, 0, NULL, 0, ctx)) { int ale_size; if (ctx->attr->type == AT_ATTRIBUTE_LIST) { err = EIO; ntfs_log_perror("Attribute list already present"); goto put_err_out; } ale_size = (sizeof(ATTR_LIST_ENTRY) + sizeof(ntfschar) * ctx->attr->name_length + 7) & ~7; al_len += ale_size; aln = realloc(al, al_len); if (!aln) { err = errno; ntfs_log_perror("Failed to realloc %d bytes", al_len); goto put_err_out; } ale = (ATTR_LIST_ENTRY *)(aln + ((u8 *)ale - al)); al = aln; memset(ale, 0, ale_size); /* Add attribute to attribute list. */ ale->type = ctx->attr->type; ale->length = cpu_to_le16((sizeof(ATTR_LIST_ENTRY) + sizeof(ntfschar) * ctx->attr->name_length + 7) & ~7); ale->name_length = ctx->attr->name_length; ale->name_offset = (u8 *)ale->name - (u8 *)ale; if (ctx->attr->non_resident) ale->lowest_vcn = ctx->attr->lowest_vcn; else ale->lowest_vcn = const_cpu_to_sle64(0); ale->mft_reference = MK_LE_MREF(ni->mft_no, le16_to_cpu(ni->mrec->sequence_number)); ale->instance = ctx->attr->instance; memcpy(ale->name, (u8 *)ctx->attr + le16_to_cpu(ctx->attr->name_offset), ctx->attr->name_length * sizeof(ntfschar)); ale = (ATTR_LIST_ENTRY *)(al + al_len); } /* Check for real error occurred. */ if (errno != ENOENT) { err = errno; ntfs_log_perror("%s: Attribute lookup failed, inode %lld", __FUNCTION__, (long long)ni->mft_no); goto put_err_out; } /* Set in-memory attribute list. */ ni->attr_list = al; ni->attr_list_size = al_len; NInoSetAttrList(ni); NInoAttrListSetDirty(ni); /* Free space if there is not enough it for $ATTRIBUTE_LIST. */ if (le32_to_cpu(ni->mrec->bytes_allocated) - le32_to_cpu(ni->mrec->bytes_in_use) < offsetof(ATTR_RECORD, resident_end)) { if (ntfs_inode_free_space(ni, offsetof(ATTR_RECORD, resident_end))) { /* Failed to free space. */ err = errno; ntfs_log_perror("Failed to free space for attrlist"); goto rollback; } } /* Add $ATTRIBUTE_LIST to mft record. */ if (ntfs_resident_attr_record_add(ni, AT_ATTRIBUTE_LIST, NULL, 0, NULL, 0, const_cpu_to_le16(0)) < 0) { err = errno; ntfs_log_perror("Couldn't add $ATTRIBUTE_LIST to MFT"); goto rollback; } /* Resize it. */ na = ntfs_attr_open(ni, AT_ATTRIBUTE_LIST, AT_UNNAMED, 0); if (!na) { err = errno; ntfs_log_perror("Failed to open just added $ATTRIBUTE_LIST"); goto remove_attrlist_record; } if (ntfs_attr_truncate(na, al_len)) { err = errno; ntfs_log_perror("Failed to resize just added $ATTRIBUTE_LIST"); ntfs_attr_close(na); goto remove_attrlist_record;; } ntfs_attr_put_search_ctx(ctx); ntfs_attr_close(na); return 0; remove_attrlist_record: /* Prevent ntfs_attr_recorm_rm from freeing attribute list. */ ni->attr_list = NULL; NInoClearAttrList(ni); /* Remove $ATTRIBUTE_LIST record. */ ntfs_attr_reinit_search_ctx(ctx); if (!ntfs_attr_lookup(AT_ATTRIBUTE_LIST, NULL, 0, CASE_SENSITIVE, 0, NULL, 0, ctx)) { if (ntfs_attr_record_rm(ctx)) ntfs_log_perror("Rollback failed to remove attrlist"); } else ntfs_log_perror("Rollback failed to find attrlist"); /* Setup back in-memory runlist. */ ni->attr_list = al; ni->attr_list_size = al_len; NInoSetAttrList(ni); rollback: /* * Scan attribute list for attributes that placed not in the base MFT * record and move them to it. */ ntfs_attr_reinit_search_ctx(ctx); ale = (ATTR_LIST_ENTRY*)al; while ((u8*)ale < al + al_len) { if (MREF_LE(ale->mft_reference) != ni->mft_no) { if (!ntfs_attr_lookup(ale->type, ale->name, ale->name_length, CASE_SENSITIVE, sle64_to_cpu(ale->lowest_vcn), NULL, 0, ctx)) { if (ntfs_attr_record_move_to(ctx, ni)) ntfs_log_perror("Rollback failed to " "move attribute"); } else ntfs_log_perror("Rollback failed to find attr"); ntfs_attr_reinit_search_ctx(ctx); } ale = (ATTR_LIST_ENTRY*)((u8*)ale + le16_to_cpu(ale->length)); } /* Remove in-memory attribute list. */ ni->attr_list = NULL; ni->attr_list_size = 0; NInoClearAttrList(ni); NInoAttrListClearDirty(ni); put_err_out: ntfs_attr_put_search_ctx(ctx); err_out: free(al); errno = err; return -1; } /** * ntfs_inode_free_space - free space in the MFT record of an inode * @ni: ntfs inode in which MFT record needs more free space * @size: amount of space needed to free * * Return 0 on success or -1 on error with errno set to the error code. */ int ntfs_inode_free_space(ntfs_inode *ni, int size) { ntfs_attr_search_ctx *ctx; int freed; if (!ni || size < 0) { errno = EINVAL; ntfs_log_perror("%s: ni=%p size=%d", __FUNCTION__, ni, size); return -1; } ntfs_log_trace("Entering for inode %lld, size %d\n", (unsigned long long)ni->mft_no, size); freed = (le32_to_cpu(ni->mrec->bytes_allocated) - le32_to_cpu(ni->mrec->bytes_in_use)); if (size <= freed) return 0; ctx = ntfs_attr_get_search_ctx(ni, NULL); if (!ctx) return -1; /* * $STANDARD_INFORMATION and $ATTRIBUTE_LIST must stay in the base MFT * record, so position search context on the first attribute after them. */ if (ntfs_attr_position(AT_FILE_NAME, ctx)) goto put_err_out; while (1) { int record_size; /* * Check whether attribute is from different MFT record. If so, * find next, because we don't need such. */ while (ctx->ntfs_ino->mft_no != ni->mft_no) { retry: if (ntfs_attr_position(AT_UNUSED, ctx)) goto put_err_out; } if (ntfs_inode_base(ctx->ntfs_ino)->mft_no == FILE_MFT && ctx->attr->type == AT_DATA) goto retry; if (ctx->attr->type == AT_INDEX_ROOT) goto retry; record_size = le32_to_cpu(ctx->attr->length); if (ntfs_attr_record_move_away(ctx, 0)) { ntfs_log_perror("Failed to move out attribute #2"); break; } freed += record_size; /* Check whether we are done. */ if (size <= freed) { ntfs_attr_put_search_ctx(ctx); return 0; } /* * Reposition to first attribute after $STANDARD_INFORMATION * and $ATTRIBUTE_LIST instead of simply skipping this attribute * because in the case when we have got only in-memory attribute * list then ntfs_attr_lookup will fail when it tries to find * $ATTRIBUTE_LIST. */ ntfs_attr_reinit_search_ctx(ctx); if (ntfs_attr_position(AT_FILE_NAME, ctx)) break; } put_err_out: ntfs_attr_put_search_ctx(ctx); if (errno == ENOSPC) ntfs_log_trace("No attributes left that could be moved out.\n"); return -1; } /** * ntfs_inode_update_times - update selected time fields for ntfs inode * @ni: ntfs inode for which update time fields * @mask: select which time fields should be updated * * This function updates time fields to current time. Fields to update are * selected using @mask (see enum @ntfs_time_update_flags for posssible values). */ void ntfs_inode_update_times(ntfs_inode *ni, ntfs_time_update_flags mask) { ntfs_time now; if (!ni) { ntfs_log_error("%s(): Invalid arguments.\n", __FUNCTION__); return; } if ((ni->mft_no < FILE_first_user && ni->mft_no != FILE_root) || NVolReadOnly(ni->vol) || !mask) return; now = ntfs_current_time(); if (mask & NTFS_UPDATE_ATIME) ni->last_access_time = now; if (mask & NTFS_UPDATE_MTIME) ni->last_data_change_time = now; if (mask & NTFS_UPDATE_CTIME) ni->last_mft_change_time = now; NInoFileNameSetDirty(ni); NInoSetDirty(ni); } /** * ntfs_inode_badclus_bad - check for $Badclus:$Bad data attribute * @mft_no: mft record number where @attr is present * @attr: attribute record used to check for the $Bad attribute * * Check if the mft record given by @mft_no and @attr contains the bad sector * list. Please note that mft record numbers describing $Badclus extent inodes * will not match the current $Badclus:$Bad check. * * On success return 1 if the file is $Badclus:$Bad, otherwise return 0. * On error return -1 with errno set to the error code. */ int ntfs_inode_badclus_bad(u64 mft_no, ATTR_RECORD *attr) { int len, ret = 0; ntfschar *ustr; if (!attr) { ntfs_log_error("Invalid argument.\n"); errno = EINVAL; return -1; } if (mft_no != FILE_BadClus) return 0; if (attr->type != AT_DATA) return 0; if ((ustr = ntfs_str2ucs("$Bad", &len)) == NULL) { ntfs_log_perror("Couldn't convert '$Bad' to Unicode"); return -1; } if (ustr && ntfs_names_are_equal(ustr, len, (ntfschar *)((u8 *)attr + le16_to_cpu(attr->name_offset)), attr->name_length, 0, NULL, 0)) ret = 1; ntfs_ucsfree(ustr); return ret; } /* * Get high precision NTFS times * * They are returned in following order : create, update, access, change * provided they fit in requested size. * * Returns the modified size if successfull (or 32 if buffer size is null) * -errno if failed */ int ntfs_inode_get_times(ntfs_inode *ni, char *value, size_t size) { ntfs_attr_search_ctx *ctx; STANDARD_INFORMATION *std_info; u64 *times; int ret; ret = 0; ctx = ntfs_attr_get_search_ctx(ni, NULL); if (ctx) { if (ntfs_attr_lookup(AT_STANDARD_INFORMATION, AT_UNNAMED, 0, CASE_SENSITIVE, 0, NULL, 0, ctx)) { ntfs_log_perror("Failed to get standard info (inode %lld)", (long long)ni->mft_no); } else { std_info = (STANDARD_INFORMATION *)((u8 *)ctx->attr + le16_to_cpu(ctx->attr->value_offset)); if (value && (size >= 8)) { times = (u64*)value; times[0] = sle64_to_cpu(std_info->creation_time); ret = 8; if (size >= 16) { times[1] = sle64_to_cpu(std_info->last_data_change_time); ret = 16; } if (size >= 24) { times[2] = sle64_to_cpu(std_info->last_access_time); ret = 24; } if (size >= 32) { times[3] = sle64_to_cpu(std_info->last_mft_change_time); ret = 32; } } else if (!size) ret = 32; else ret = -ERANGE; } ntfs_attr_put_search_ctx(ctx); } return (ret ? ret : -errno); } /* * Set high precision NTFS times * * They are expected in this order : create, update, access * provided they are present in input. The change time is set to * current time. * * The times are inserted directly in the standard_information and * file names attributes to avoid manipulating low precision times * * Returns 0 if success * -1 if there were an error (described by errno) */ int ntfs_inode_set_times(ntfs_inode *ni, const char *value, size_t size, int flags) { ntfs_attr_search_ctx *ctx; STANDARD_INFORMATION *std_info; FILE_NAME_ATTR *fn; u64 times[4]; ntfs_time now; int cnt; int ret; ret = -1; if ((size >= 8) && !(flags & XATTR_CREATE)) { /* Copy, to avoid alignment issue encountered on ARM */ memcpy(times, value, (size < sizeof(times) ? size : sizeof(times))); now = ntfs_current_time(); /* update the standard information attribute */ ctx = ntfs_attr_get_search_ctx(ni, NULL); if (ctx) { if (ntfs_attr_lookup(AT_STANDARD_INFORMATION, AT_UNNAMED, 0, CASE_SENSITIVE, 0, NULL, 0, ctx)) { ntfs_log_perror("Failed to get standard info (inode %lld)", (long long)ni->mft_no); } else { std_info = (STANDARD_INFORMATION *)((u8 *)ctx->attr + le16_to_cpu(ctx->attr->value_offset)); /* * Mark times set to avoid overwriting * them when the inode is closed. * The inode structure must also be updated * (with loss of precision) because of cacheing. * TODO : use NTFS precision in inode, and * return sub-second times in getattr() */ set_nino_flag(ni, TimesSet); std_info->creation_time = cpu_to_sle64(times[0]); ni->creation_time = std_info->creation_time; if (size >= 16) { std_info->last_data_change_time = cpu_to_sle64(times[1]); ni->last_data_change_time = std_info->last_data_change_time; } if (size >= 24) { std_info->last_access_time = cpu_to_sle64(times[2]); ni->last_access_time = std_info->last_access_time; } std_info->last_mft_change_time = now; ni->last_mft_change_time = now; ntfs_inode_mark_dirty(ctx->ntfs_ino); NInoFileNameSetDirty(ni); /* update the file names attributes */ ntfs_attr_reinit_search_ctx(ctx); cnt = 0; while (!ntfs_attr_lookup(AT_FILE_NAME, AT_UNNAMED, 0, CASE_SENSITIVE, 0, NULL, 0, ctx)) { fn = (FILE_NAME_ATTR*)((u8 *)ctx->attr + le16_to_cpu(ctx->attr->value_offset)); fn->creation_time = cpu_to_sle64(times[0]); if (size >= 16) fn->last_data_change_time = cpu_to_sle64(times[1]); if (size >= 24) fn->last_access_time = cpu_to_sle64(times[2]); fn->last_mft_change_time = now; cnt++; } if (cnt) ret = 0; else { ntfs_log_perror("Failed to get file names (inode %lld)", (long long)ni->mft_no); } } ntfs_attr_put_search_ctx(ctx); } } else if (size < 8) errno = ERANGE; else errno = EEXIST; return (ret); } ntfs-3g-2026.2.25/libntfs-3g/compress.c0000664000175000017500000015407315152260173012761 /** * compress.c - Compressed attribute handling code. Originated from the Linux-NTFS * project. * * Copyright (c) 2004-2005 Anton Altaparmakov * Copyright (c) 2004-2006 Szabolcs Szakacsits * Copyright (c) 2005 Yura Pakhuchiy * Copyright (c) 2009-2014 Jean-Pierre Andre * Copyright (c) 2014 Eric Biggers * * This program/include file 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/include file 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_STDIO_H #include #endif #ifdef HAVE_STRING_H #include #endif #ifdef HAVE_STDLIB_H #include #endif #ifdef HAVE_ERRNO_H #include #endif #include "attrib.h" #include "debug.h" #include "volume.h" #include "types.h" #include "layout.h" #include "runlist.h" #include "compress.h" #include "lcnalloc.h" #include "logging.h" #include "misc.h" #undef le16_to_cpup /* the standard le16_to_cpup() crashes for unaligned data on some processors */ #define le16_to_cpup(p) (*(u8*)(p) + (((u8*)(p))[1] << 8)) /** * enum ntfs_compression_constants - constants used in the compression code */ typedef enum { /* Token types and access mask. */ NTFS_SYMBOL_TOKEN = 0, NTFS_PHRASE_TOKEN = 1, NTFS_TOKEN_MASK = 1, /* Compression sub-block constants. */ NTFS_SB_SIZE_MASK = 0x0fff, NTFS_SB_SIZE = 0x1000, NTFS_SB_IS_COMPRESSED = 0x8000, } ntfs_compression_constants; /* Match length at or above which ntfs_best_match() will stop searching for * longer matches. */ #define NICE_MATCH_LEN 18 /* Maximum number of potential matches that ntfs_best_match() will consider at * each position. */ #define MAX_SEARCH_DEPTH 24 /* log base 2 of the number of entries in the hash table for match-finding. */ #define HASH_SHIFT 14 /* Constant for the multiplicative hash function. */ #define HASH_MULTIPLIER 0x1E35A7BD struct COMPRESS_CONTEXT { const unsigned char *inbuf; int bufsize; int size; int rel; int mxsz; s16 head[1 << HASH_SHIFT]; s16 prev[NTFS_SB_SIZE]; } ; /* * Hash the next 3-byte sequence in the input buffer */ static inline unsigned int ntfs_hash(const u8 *p) { u32 str; u32 hash; #if defined(__i386__) || defined(__x86_64__) /* Unaligned access allowed, and little endian CPU. * Callers ensure that at least 4 (not 3) bytes are remaining. */ str = *(const u32 *)p & 0xFFFFFF; #else str = ((u32)p[0] << 0) | ((u32)p[1] << 8) | ((u32)p[2] << 16); #endif hash = str * HASH_MULTIPLIER; /* High bits are more random than the low bits. */ return hash >> (32 - HASH_SHIFT); } /* * Search for the longest sequence matching current position * * A hash table, each entry of which points to a chain of sequence * positions sharing the corresponding hash code, is maintained to speed up * searching for matches. To maintain the hash table, either * ntfs_best_match() or ntfs_skip_position() has to be called for each * consecutive position. * * This function is heavily used; it has to be optimized carefully. * * This function sets pctx->size and pctx->rel to the length and offset, * respectively, of the longest match found. * * The minimum match length is assumed to be 3, and the maximum match * length is assumed to be pctx->mxsz. If this function produces * pctx->size < 3, then no match was found. * * Note: for the following reasons, this function is not guaranteed to find * *the* longest match up to pctx->mxsz: * * (1) If this function finds a match of NICE_MATCH_LEN bytes or greater, * it ends early because a match this long is good enough and it's not * worth spending more time searching. * * (2) If this function considers MAX_SEARCH_DEPTH matches with a single * position, it ends early and returns the longest match found so far. * This saves a lot of time on degenerate inputs. */ static void ntfs_best_match(struct COMPRESS_CONTEXT *pctx, const int i, int best_len) { const u8 * const inbuf = pctx->inbuf; const u8 * const strptr = &inbuf[i]; /* String we're matching against */ s16 * const prev = pctx->prev; const int max_len = min(pctx->bufsize - i, pctx->mxsz); const int nice_len = min(NICE_MATCH_LEN, max_len); int depth_remaining = MAX_SEARCH_DEPTH; const u8 *best_matchptr = strptr; unsigned int hash; s16 cur_match; const u8 *matchptr; int len; if (max_len < 4) goto out; /* Insert the current sequence into the appropriate hash chain. */ hash = ntfs_hash(strptr); cur_match = pctx->head[hash]; prev[i] = cur_match; pctx->head[hash] = i; if (best_len >= max_len) { /* Lazy match is being attempted, but there aren't enough length * bits remaining to code a longer match. */ goto out; } /* Search the appropriate hash chain for matches. */ for (; cur_match >= 0 && depth_remaining--; cur_match = prev[cur_match]) { matchptr = &inbuf[cur_match]; /* Considering the potential match at 'matchptr': is it longer * than 'best_len'? * * The bytes at index 'best_len' are the most likely to differ, * so check them first. * * The bytes at indices 'best_len - 1' and '0' are less * important to check separately. But doing so still gives a * slight performance improvement, at least on x86_64, probably * because they create separate branches for the CPU to predict * independently of the branches in the main comparison loops. */ if (matchptr[best_len] != strptr[best_len] || matchptr[best_len - 1] != strptr[best_len - 1] || matchptr[0] != strptr[0]) goto next_match; for (len = 1; len < best_len - 1; len++) if (matchptr[len] != strptr[len]) goto next_match; /* The match is the longest found so far --- * at least 'best_len' + 1 bytes. Continue extending it. */ best_matchptr = matchptr; do { if (++best_len >= nice_len) { /* 'nice_len' reached; don't waste time * searching for longer matches. Extend the * match as far as possible and terminate the * search. */ while (best_len < max_len && (best_matchptr[best_len] == strptr[best_len])) { best_len++; } goto out; } } while (best_matchptr[best_len] == strptr[best_len]); /* Found a longer match, but 'nice_len' not yet reached. */ next_match: /* Continue to next match in the chain. */ ; } /* Reached end of chain, or ended early due to reaching the maximum * search depth. */ out: /* Return the longest match we were able to find. */ pctx->size = best_len; pctx->rel = best_matchptr - strptr; /* given as a negative number! */ } /* * Advance the match-finder, but don't search for matches. */ static void ntfs_skip_position(struct COMPRESS_CONTEXT *pctx, const int i) { unsigned int hash; if (pctx->bufsize - i < 4) return; /* Insert the current sequence into the appropriate hash chain. */ hash = ntfs_hash(pctx->inbuf + i); pctx->prev[i] = pctx->head[hash]; pctx->head[hash] = i; } /* * Compress a 4096-byte block * * Returns a header of two bytes followed by the compressed data. * If compression is not effective, the header and an uncompressed * block is returned. * * Note : two bytes may be output before output buffer overflow * is detected, so a 4100-bytes output buffer must be reserved. * * Returns the size of the compressed block, including the * header (minimal size is 2, maximum size is 4098) * 0 if an error has been met. */ static unsigned int ntfs_compress_block(const char *inbuf, const int bufsize, char *outbuf) { struct COMPRESS_CONTEXT *pctx; int i; /* current position */ int j; /* end of best match from current position */ int k; /* end of best match from next position */ int offs; /* offset to best match */ int bp; /* bits to store offset */ int bp_cur; /* saved bits to store offset at current position */ int mxoff; /* max match offset : 1 << bp */ unsigned int xout; unsigned int q; /* aggregated offset and size */ int have_match; /* do we have a match at the current position? */ char *ptag; /* location reserved for a tag */ int tag; /* current value of tag */ int ntag; /* count of bits still undefined in tag */ pctx = ntfs_malloc(sizeof(struct COMPRESS_CONTEXT)); if (!pctx) { errno = ENOMEM; return 0; } /* All hash chains start as empty. The special value '-1' indicates the * end of each hash chain. */ memset(pctx->head, 0xFF, sizeof(pctx->head)); pctx->inbuf = (const unsigned char*)inbuf; pctx->bufsize = bufsize; xout = 2; i = 0; bp = 4; mxoff = 1 << bp; pctx->mxsz = (1 << (16 - bp)) + 2; have_match = 0; tag = 0; ntag = 8; ptag = &outbuf[xout++]; while ((i < bufsize) && (xout < (NTFS_SB_SIZE + 2))) { /* This implementation uses "lazy" parsing: it always chooses * the longest match, unless the match at the next position is * longer. This is the same strategy used by the high * compression modes of zlib. */ if (!have_match) { /* Find the longest match at the current position. But * first adjust the maximum match length if needed. * (This loop might need to run more than one time in * the case that we just output a long match.) */ while (mxoff < i) { bp++; mxoff <<= 1; pctx->mxsz = (pctx->mxsz + 2) >> 1; } ntfs_best_match(pctx, i, 2); } if (pctx->size >= 3) { /* Found a match at the current position. */ j = i + pctx->size; bp_cur = bp; offs = pctx->rel; if (pctx->size >= NICE_MATCH_LEN) { /* Choose long matches immediately. */ q = (~offs << (16 - bp_cur)) + (j - i - 3); outbuf[xout++] = q & 255; outbuf[xout++] = (q >> 8) & 255; tag |= (1 << (8 - ntag)); if (j == bufsize) { /* Shortcut if the match extends to the * end of the buffer. */ i = j; --ntag; break; } i += 1; do { ntfs_skip_position(pctx, i); } while (++i != j); have_match = 0; } else { /* Check for a longer match at the next * position. */ /* Doesn't need to be while() since we just * adjusted the maximum match length at the * previous position. */ if (mxoff < i + 1) { bp++; mxoff <<= 1; pctx->mxsz = (pctx->mxsz + 2) >> 1; } ntfs_best_match(pctx, i + 1, pctx->size); k = i + 1 + pctx->size; if (k > (j + 1)) { /* Next match is longer. * Output a literal. */ outbuf[xout++] = inbuf[i++]; have_match = 1; } else { /* Next match isn't longer. * Output the current match. */ q = (~offs << (16 - bp_cur)) + (j - i - 3); outbuf[xout++] = q & 255; outbuf[xout++] = (q >> 8) & 255; tag |= (1 << (8 - ntag)); /* The minimum match length is 3, and * we've run two bytes through the * matchfinder already. So the minimum * number of positions we need to skip * is 1. */ i += 2; do { ntfs_skip_position(pctx, i); } while (++i != j); have_match = 0; } } } else { /* No match at current position. Output a literal. */ outbuf[xout++] = inbuf[i++]; have_match = 0; } /* Store the tag if fully used. */ if (!--ntag) { *ptag = tag; ntag = 8; ptag = &outbuf[xout++]; tag = 0; } } /* Store the last tag if partially used. */ if (ntag == 8) xout--; else *ptag = tag; /* Determine whether to store the data compressed or uncompressed. */ if ((i >= bufsize) && (xout < (NTFS_SB_SIZE + 2))) { /* Compressed. */ outbuf[0] = (xout - 3) & 255; outbuf[1] = 0xb0 + (((xout - 3) >> 8) & 15); } else { /* Uncompressed. */ memcpy(&outbuf[2], inbuf, bufsize); if (bufsize < NTFS_SB_SIZE) memset(&outbuf[bufsize + 2], 0, NTFS_SB_SIZE - bufsize); outbuf[0] = 0xff; outbuf[1] = 0x3f; xout = NTFS_SB_SIZE + 2; } /* Free the compression context and return the total number of bytes * written to 'outbuf'. */ free(pctx); return (xout); } /** * ntfs_decompress - decompress a compression block into an array of pages * @dest: buffer to which to write the decompressed data * @dest_size: size of buffer @dest in bytes * @cb_start: compression block to decompress * @cb_size: size of compression block @cb_start in bytes * * This decompresses the compression block @cb_start into the destination * buffer @dest. * * @cb_start is a pointer to the compression block which needs decompressing * and @cb_size is the size of @cb_start in bytes (8-64kiB). * * Return 0 if success or -EOVERFLOW on error in the compressed stream. */ static int ntfs_decompress(u8 *dest, const u32 dest_size, u8 *const cb_start, const u32 cb_size) { /* * Pointers into the compressed data, i.e. the compression block (cb), * and the therein contained sub-blocks (sb). */ u8 *cb_end = cb_start + cb_size; /* End of cb. */ u8 *cb = cb_start; /* Current position in cb. */ u8 *cb_sb_start = cb; /* Beginning of the current sb in the cb. */ u8 *cb_sb_end; /* End of current sb / beginning of next sb. */ /* Variables for uncompressed data / destination. */ u8 *dest_end = dest + dest_size; /* End of dest buffer. */ u8 *dest_sb_start; /* Start of current sub-block in dest. */ u8 *dest_sb_end; /* End of current sb in dest. */ /* Variables for tag and token parsing. */ u8 tag; /* Current tag. */ int token; /* Loop counter for the eight tokens in tag. */ ntfs_log_trace("Entering, cb_size = 0x%x.\n", (unsigned)cb_size); do_next_sb: ntfs_log_debug("Beginning sub-block at offset = %d in the cb.\n", (int)(cb - cb_start)); /* * Have we reached the end of the compression block or the end of the * decompressed data? The latter can happen for example if the current * position in the compression block is one byte before its end so the * first two checks do not detect it. */ if (cb == cb_end || !le16_to_cpup((le16*)cb) || dest == dest_end) { if (dest_end > dest) memset(dest, 0, dest_end - dest); ntfs_log_debug("Completed. Returning success (0).\n"); return 0; } /* Setup offset for the current sub-block destination. */ dest_sb_start = dest; dest_sb_end = dest + NTFS_SB_SIZE; /* Check that we are still within allowed boundaries. */ if (dest_sb_end > dest_end) goto return_overflow; /* Does the minimum size of a compressed sb overflow valid range? */ if (cb + 6 > cb_end) goto return_overflow; /* Setup the current sub-block source pointers and validate range. */ cb_sb_start = cb; cb_sb_end = cb_sb_start + (le16_to_cpup((le16*)cb) & NTFS_SB_SIZE_MASK) + 3; if (cb_sb_end > cb_end) goto return_overflow; /* Now, we are ready to process the current sub-block (sb). */ if (!(le16_to_cpup((le16*)cb) & NTFS_SB_IS_COMPRESSED)) { ntfs_log_debug("Found uncompressed sub-block.\n"); /* This sb is not compressed, just copy it into destination. */ /* Advance source position to first data byte. */ cb += 2; /* An uncompressed sb must be full size. */ if (cb_sb_end - cb != NTFS_SB_SIZE) goto return_overflow; /* Copy the block and advance the source position. */ memcpy(dest, cb, NTFS_SB_SIZE); cb += NTFS_SB_SIZE; /* Advance destination position to next sub-block. */ dest += NTFS_SB_SIZE; goto do_next_sb; } ntfs_log_debug("Found compressed sub-block.\n"); /* This sb is compressed, decompress it into destination. */ /* Forward to the first tag in the sub-block. */ cb += 2; do_next_tag: if (cb == cb_sb_end) { /* Check if the decompressed sub-block was not full-length. */ if (dest < dest_sb_end) { int nr_bytes = dest_sb_end - dest; ntfs_log_debug("Filling incomplete sub-block with zeroes.\n"); /* Zero remainder and update destination position. */ memset(dest, 0, nr_bytes); dest += nr_bytes; } /* We have finished the current sub-block. */ goto do_next_sb; } /* Check we are still in range. */ if (cb > cb_sb_end || dest > dest_sb_end) goto return_overflow; /* Get the next tag and advance to first token. */ tag = *cb++; /* Parse the eight tokens described by the tag. */ for (token = 0; token < 8; token++, tag >>= 1) { u16 lg, pt, length, max_non_overlap; register u16 i; u8 *dest_back_addr; /* Check if we are done / still in range. */ if (cb >= cb_sb_end || dest > dest_sb_end) break; /* Determine token type and parse appropriately.*/ if ((tag & NTFS_TOKEN_MASK) == NTFS_SYMBOL_TOKEN) { /* * We have a symbol token, copy the symbol across, and * advance the source and destination positions. */ *dest++ = *cb++; /* Continue with the next token. */ continue; } /* * We have a phrase token. Make sure it is not the first tag in * the sb as this is illegal and would confuse the code below. */ if (dest == dest_sb_start) goto return_overflow; /* * Determine the number of bytes to go back (p) and the number * of bytes to copy (l). We use an optimized algorithm in which * we first calculate log2(current destination position in sb), * which allows determination of l and p in O(1) rather than * O(n). We just need an arch-optimized log2() function now. */ lg = 0; for (i = dest - dest_sb_start - 1; i >= 0x10; i >>= 1) lg++; /* Get the phrase token into i. */ pt = le16_to_cpup((le16*)cb); /* * Calculate starting position of the byte sequence in * the destination using the fact that p = (pt >> (12 - lg)) + 1 * and make sure we don't go too far back. */ dest_back_addr = dest - (pt >> (12 - lg)) - 1; if (dest_back_addr < dest_sb_start) goto return_overflow; /* Now calculate the length of the byte sequence. */ length = (pt & (0xfff >> lg)) + 3; /* Verify destination is in range. */ if (dest + length > dest_sb_end) goto return_overflow; /* The number of non-overlapping bytes. */ max_non_overlap = dest - dest_back_addr; if (length <= max_non_overlap) { /* The byte sequence doesn't overlap, just copy it. */ memcpy(dest, dest_back_addr, length); /* Advance destination pointer. */ dest += length; } else { /* * The byte sequence does overlap, copy non-overlapping * part and then do a slow byte by byte copy for the * overlapping part. Also, advance the destination * pointer. */ memcpy(dest, dest_back_addr, max_non_overlap); dest += max_non_overlap; dest_back_addr += max_non_overlap; length -= max_non_overlap; while (length--) *dest++ = *dest_back_addr++; } /* Advance source position and continue with the next token. */ cb += 2; } /* No tokens left in the current tag. Continue with the next tag. */ goto do_next_tag; return_overflow: errno = EOVERFLOW; ntfs_log_perror("Failed to decompress file"); return -1; } /** * ntfs_is_cb_compressed - internal function, do not use * * This is a very specialised function determining if a cb is compressed or * uncompressed. It is assumed that checking for a sparse cb has already been * performed and that the cb is not sparse. It makes all sorts of other * assumptions as well and hence it is not useful anywhere other than where it * is used at the moment. Please, do not make this function available for use * outside of compress.c as it is bound to confuse people and not do what they * want. * * Return TRUE on errors so that the error will be detected later on in the * code. Might be a bit confusing to debug but there really should never be * errors coming from here. */ static BOOL ntfs_is_cb_compressed(ntfs_attr *na, runlist_element *rl, VCN cb_start_vcn, int cb_clusters) { /* * The simplest case: the run starting at @cb_start_vcn contains * @cb_clusters clusters which are all not sparse, thus the cb is not * compressed. */ restart: cb_clusters -= rl->length - (cb_start_vcn - rl->vcn); while (cb_clusters > 0) { /* Go to the next run. */ rl++; /* Map the next runlist fragment if it is not mapped. */ if (rl->lcn < LCN_HOLE || !rl->length) { cb_start_vcn = rl->vcn; rl = ntfs_attr_find_vcn(na, rl->vcn); if (!rl || rl->lcn < LCN_HOLE || !rl->length) return TRUE; /* * If the runs were merged need to deal with the * resulting partial run so simply restart. */ if (rl->vcn < cb_start_vcn) goto restart; } /* If the current run is sparse, the cb is compressed. */ if (rl->lcn == LCN_HOLE) return TRUE; /* If the whole cb is not sparse, it is not compressed. */ if (rl->length >= cb_clusters) return FALSE; cb_clusters -= rl->length; }; /* All cb_clusters were not sparse thus the cb is not compressed. */ return FALSE; } /** * ntfs_compressed_attr_pread - read from a compressed attribute * @na: ntfs attribute to read from * @pos: byte position in the attribute to begin reading from * @count: number of bytes to read * @b: output data buffer * * NOTE: You probably want to be using attrib.c::ntfs_attr_pread() instead. * * This function will read @count bytes starting at offset @pos from the * compressed ntfs attribute @na into the data buffer @b. * * On success, return the number of successfully read bytes. If this number * is lower than @count this means that the read reached end of file or that * an error was encountered during the read so that the read is partial. * 0 means end of file or nothing was read (also return 0 when @count is 0). * * On error and nothing has been read, return -1 with errno set appropriately * to the return code of ntfs_pread(), or to EINVAL in case of invalid * arguments. */ s64 ntfs_compressed_attr_pread(ntfs_attr *na, s64 pos, s64 count, void *b) { s64 br, to_read, ofs, total, total2; u64 cb_size_mask; VCN start_vcn, vcn, end_vcn; ntfs_volume *vol; runlist_element *rl; u8 *dest, *cb, *cb_pos, *cb_end; u32 cb_size; int err; ATTR_FLAGS data_flags; FILE_ATTR_FLAGS compression; unsigned int nr_cbs, cb_clusters; ntfs_log_trace("Entering for inode 0x%llx, attr 0x%x, pos 0x%llx, count 0x%llx.\n", (unsigned long long)na->ni->mft_no, le32_to_cpu(na->type), (long long)pos, (long long)count); data_flags = na->data_flags; compression = na->ni->flags & FILE_ATTR_COMPRESSED; if (!na || !na->ni || !na->ni->vol || !b || ((data_flags & ATTR_COMPRESSION_MASK) != ATTR_IS_COMPRESSED) || pos < 0 || count < 0) { errno = EINVAL; return -1; } /* * Encrypted attributes are not supported. We return access denied, * which is what Windows NT4 does, too. */ if (NAttrEncrypted(na)) { errno = EACCES; return -1; } if (!count) return 0; /* Truncate reads beyond end of attribute. */ if (pos + count > na->data_size) { if (pos >= na->data_size) { return 0; } count = na->data_size - pos; } /* If it is a resident attribute, simply use ntfs_attr_pread(). */ if (!NAttrNonResident(na)) return ntfs_attr_pread(na, pos, count, b); if (na->compression_block_size < NTFS_SB_SIZE) { ntfs_log_error("Unsupported compression block size %ld\n", (long)na->compression_block_size); errno = EOVERFLOW; return (-1); } total = total2 = 0; /* Zero out reads beyond initialized size. */ if (pos + count > na->initialized_size) { if (pos >= na->initialized_size) { memset(b, 0, count); return count; } total2 = pos + count - na->initialized_size; count -= total2; memset((u8*)b + count, 0, total2); } vol = na->ni->vol; cb_size = na->compression_block_size; cb_size_mask = cb_size - 1UL; cb_clusters = na->compression_block_clusters; /* Need a temporary buffer for each loaded compression block. */ cb = (u8*)ntfs_malloc(cb_size); if (!cb) return -1; /* Need a temporary buffer for each uncompressed block. */ dest = (u8*)ntfs_malloc(cb_size); if (!dest) { free(cb); return -1; } /* * The first vcn in the first compression block (cb) which we need to * decompress. */ start_vcn = (pos & ~cb_size_mask) >> vol->cluster_size_bits; /* Offset in the uncompressed cb at which to start reading data. */ ofs = pos & cb_size_mask; /* * The first vcn in the cb after the last cb which we need to * decompress. */ end_vcn = ((pos + count + cb_size - 1) & ~cb_size_mask) >> vol->cluster_size_bits; /* Number of compression blocks (cbs) in the wanted vcn range. */ nr_cbs = (end_vcn - start_vcn) << vol->cluster_size_bits >> na->compression_block_size_bits; cb_end = cb + cb_size; do_next_cb: nr_cbs--; cb_pos = cb; vcn = start_vcn; start_vcn += cb_clusters; /* Check whether the compression block is sparse. */ rl = ntfs_attr_find_vcn(na, vcn); if (!rl || rl->lcn < LCN_HOLE) { free(cb); free(dest); if (total) return total; /* FIXME: Do we want EIO or the error code? (AIA) */ errno = EIO; return -1; } if (rl->lcn == LCN_HOLE) { /* Sparse cb, zero out destination range overlapping the cb. */ ntfs_log_debug("Found sparse compression block.\n"); to_read = min(count, cb_size - ofs); memset(b, 0, to_read); ofs = 0; total += to_read; count -= to_read; b = (u8*)b + to_read; } else if (!ntfs_is_cb_compressed(na, rl, vcn, cb_clusters)) { s64 tdata_size, tinitialized_size; /* * Uncompressed cb, read it straight into the destination range * overlapping the cb. */ ntfs_log_debug("Found uncompressed compression block.\n"); /* * Read the uncompressed data into the destination buffer. * NOTE: We cheat a little bit here by marking the attribute as * not compressed in the ntfs_attr structure so that we can * read the data by simply using ntfs_attr_pread(). (-8 * NOTE: we have to modify data_size and initialized_size * temporarily as well... */ to_read = min(count, cb_size - ofs); ofs += vcn << vol->cluster_size_bits; NAttrClearCompressed(na); na->data_flags &= ~ATTR_COMPRESSION_MASK; tdata_size = na->data_size; tinitialized_size = na->initialized_size; na->data_size = na->initialized_size = na->allocated_size; do { br = ntfs_attr_pread(na, ofs, to_read, b); if (br <= 0) { if (!br) { ntfs_log_error("Failed to read an" " uncompressed cluster," " inode %lld offs 0x%llx\n", (long long)na->ni->mft_no, (long long)ofs); errno = EIO; } err = errno; na->data_size = tdata_size; na->initialized_size = tinitialized_size; na->ni->flags |= compression; na->data_flags = data_flags; free(cb); free(dest); if (total) return total; errno = err; return br; } total += br; count -= br; b = (u8*)b + br; to_read -= br; ofs += br; } while (to_read > 0); na->data_size = tdata_size; na->initialized_size = tinitialized_size; na->ni->flags |= compression; na->data_flags = data_flags; ofs = 0; } else { s64 tdata_size, tinitialized_size; u32 decompsz; /* * Compressed cb, decompress it into the temporary buffer, then * copy the data to the destination range overlapping the cb. */ ntfs_log_debug("Found compressed compression block.\n"); /* * Read the compressed data into the temporary buffer. * NOTE: We cheat a little bit here by marking the attribute as * not compressed in the ntfs_attr structure so that we can * read the raw, compressed data by simply using * ntfs_attr_pread(). (-8 * NOTE: We have to modify data_size and initialized_size * temporarily as well... */ to_read = cb_size; NAttrClearCompressed(na); na->data_flags &= ~ATTR_COMPRESSION_MASK; tdata_size = na->data_size; tinitialized_size = na->initialized_size; na->data_size = na->initialized_size = na->allocated_size; do { br = ntfs_attr_pread(na, (vcn << vol->cluster_size_bits) + (cb_pos - cb), to_read, cb_pos); if (br <= 0) { if (!br) { ntfs_log_error("Failed to read a" " compressed cluster, " " inode %lld offs 0x%llx\n", (long long)na->ni->mft_no, (long long)(vcn << vol->cluster_size_bits)); errno = EIO; } err = errno; na->data_size = tdata_size; na->initialized_size = tinitialized_size; na->ni->flags |= compression; na->data_flags = data_flags; free(cb); free(dest); if (total) return total; errno = err; return br; } cb_pos += br; to_read -= br; } while (to_read > 0); na->data_size = tdata_size; na->initialized_size = tinitialized_size; na->ni->flags |= compression; na->data_flags = data_flags; /* Just a precaution. */ if (cb_pos + 2 <= cb_end) *(u16*)cb_pos = 0; ntfs_log_debug("Successfully read the compression block.\n"); /* Do not decompress beyond the requested block */ to_read = min(count, cb_size - ofs); decompsz = ((ofs + to_read - 1) | (NTFS_SB_SIZE - 1)) + 1; if (ntfs_decompress(dest, decompsz, cb, cb_size) < 0) { err = errno; free(cb); free(dest); if (total) return total; errno = err; return -1; } memcpy(b, dest + ofs, to_read); total += to_read; count -= to_read; b = (u8*)b + to_read; ofs = 0; } /* Do we have more work to do? */ if (nr_cbs) goto do_next_cb; /* We no longer need the buffers. */ free(cb); free(dest); /* Return number of bytes read. */ return total + total2; } /* * Read data from a set of clusters * * Returns the amount of data read */ static u32 read_clusters(ntfs_volume *vol, const runlist_element *rl, s64 offs, u32 to_read, char *inbuf) { u32 count; int xgot; u32 got; s64 xpos; BOOL first; char *xinbuf; const runlist_element *xrl; got = 0; xrl = rl; xinbuf = inbuf; first = TRUE; do { count = xrl->length << vol->cluster_size_bits; xpos = xrl->lcn << vol->cluster_size_bits; if (first) { count -= offs; xpos += offs; } if ((to_read - got) < count) count = to_read - got; xgot = ntfs_pread(vol->dev, xpos, count, xinbuf); if (xgot == (int)count) { got += count; xpos += count; xinbuf += count; xrl++; } first = FALSE; } while ((xgot == (int)count) && (got < to_read)); return (got); } /* * Write data to a set of clusters * * Returns the amount of data written */ static s32 write_clusters(ntfs_volume *vol, const runlist_element *rl, s64 offs, s32 to_write, const char *outbuf) { s32 count; s32 put, xput; s64 xpos; BOOL first; const char *xoutbuf; const runlist_element *xrl; put = 0; xrl = rl; xoutbuf = outbuf; first = TRUE; do { count = xrl->length << vol->cluster_size_bits; xpos = xrl->lcn << vol->cluster_size_bits; if (first) { count -= offs; xpos += offs; } if ((to_write - put) < count) count = to_write - put; xput = ntfs_pwrite(vol->dev, xpos, count, xoutbuf); if (xput == count) { put += count; xpos += count; xoutbuf += count; xrl++; } first = FALSE; } while ((xput == count) && (put < to_write)); return (put); } /* * Compress and write a set of blocks * * returns the size actually written (rounded to a full cluster) * or 0 if all zeroes (nothing is written) * or -1 if could not compress (nothing is written) * or -2 if there were an irrecoverable error (errno set) */ static s32 ntfs_comp_set(ntfs_attr *na, runlist_element *rl, s64 offs, u32 insz, const char *inbuf) { ntfs_volume *vol; char *outbuf; char *pbuf; u32 compsz; s32 written; s32 rounded; unsigned int clsz; u32 p; unsigned int sz; unsigned int bsz; BOOL fail; BOOL allzeroes; /* a single compressed zero */ static char onezero[] = { 0x01, 0xb0, 0x00, 0x00 } ; /* a couple of compressed zeroes */ static char twozeroes[] = { 0x02, 0xb0, 0x00, 0x00, 0x00 } ; /* more compressed zeroes, to be followed by some count */ static char morezeroes[] = { 0x03, 0xb0, 0x02, 0x00 } ; vol = na->ni->vol; written = -1; /* default return */ clsz = 1 << vol->cluster_size_bits; /* may need 2 extra bytes per block and 2 more bytes */ outbuf = (char*)ntfs_malloc(na->compression_block_size + 2*(na->compression_block_size/NTFS_SB_SIZE) + 2); if (outbuf) { fail = FALSE; compsz = 0; allzeroes = TRUE; for (p=0; (p na->compression_block_size)) fail = TRUE; else { if (allzeroes) { /* check whether this is all zeroes */ switch (sz) { case 4 : allzeroes = !memcmp( pbuf,onezero,4); break; case 5 : allzeroes = !memcmp( pbuf,twozeroes,5); break; case 6 : allzeroes = !memcmp( pbuf,morezeroes,4); break; default : allzeroes = FALSE; break; } } compsz += sz; } } if (!fail && !allzeroes) { /* add a couple of null bytes, space has been checked */ outbuf[compsz++] = 0; outbuf[compsz++] = 0; /* write a full cluster, to avoid partial reading */ rounded = ((compsz - 1) | (clsz - 1)) + 1; memset(&outbuf[compsz], 0, rounded - compsz); written = write_clusters(vol, rl, offs, rounded, outbuf); if (written != rounded) { /* * TODO : previously written text has been * spoilt, should return a specific error */ ntfs_log_error("error writing compressed data\n"); errno = EIO; written = -2; } } else if (!fail) written = 0; free(outbuf); } return (written); } /* * Check the validity of a compressed runlist * The check starts at the beginning of current run and ends * at the end of runlist * errno is set if the runlist is not valid */ static BOOL valid_compressed_run(ntfs_attr *na, runlist_element *rl, BOOL fullcheck, const char *text) { runlist_element *xrl; const char *err; BOOL ok = TRUE; xrl = rl; while (xrl->vcn & (na->compression_block_clusters - 1)) xrl--; err = (const char*)NULL; while (xrl->length) { if ((xrl->vcn + xrl->length) != xrl[1].vcn) err = "Runs not adjacent"; if (xrl->lcn == LCN_HOLE) { if ((xrl->vcn + xrl->length) & (na->compression_block_clusters - 1)) { err = "Invalid hole"; } if (fullcheck && (xrl[1].lcn == LCN_HOLE)) { err = "Adjacent holes"; } } if (err) { ntfs_log_error("%s at %s index %ld inode %lld\n", err, text, (long)(xrl - na->rl), (long long)na->ni->mft_no); errno = EIO; ok = FALSE; err = (const char*)NULL; } xrl++; } return (ok); } /* * Free unneeded clusters after overwriting compressed data * * This generally requires one or two empty slots at the end of runlist, * but we do not want to reallocate the runlist here because * there are many pointers to it. * So the empty slots have to be reserved beforehand * * Returns zero unless some error occurred (described by errno) * * +======= start of block =====+ * 0 |A chunk may overflow | <-- rl usedcnt : A + B * |A on previous block | then B * |A | * +-- end of allocated chunk --+ freelength : C * |B | (incl overflow) * +== end of compressed data ==+ * |C | <-- freerl freecnt : C + D * |C chunk may overflow | * |C on next block | * +-- end of allocated chunk --+ * |D | * |D chunk may overflow | * 15 |D on next block | * +======== end of block ======+ * */ static int ntfs_compress_overwr_free(ntfs_attr *na, runlist_element *rl, s32 usedcnt, s32 freecnt, VCN *update_from) { BOOL beginhole; BOOL mergeholes; s32 oldlength; s32 freelength; s64 freelcn; s64 freevcn; runlist_element *freerl; ntfs_volume *vol; s32 carry; int res; vol = na->ni->vol; res = 0; freelcn = rl->lcn + usedcnt; freevcn = rl->vcn + usedcnt; freelength = rl->length - usedcnt; beginhole = !usedcnt && !rl->vcn; /* can merge with hole before ? */ mergeholes = !usedcnt && rl[0].vcn && (rl[-1].lcn == LCN_HOLE); /* truncate current run, carry to subsequent hole */ carry = freelength; oldlength = rl->length; if (mergeholes) { /* merging with a hole before */ freerl = rl; } else { rl->length -= freelength; /* warning : can be zero */ freerl = ++rl; } if (!mergeholes && (usedcnt || beginhole)) { s32 freed; runlist_element *frl; runlist_element *erl; int holes = 0; BOOL threeparts; /* free the unneeded clusters from initial run, then freerl */ threeparts = (freelength > freecnt); freed = 0; frl = freerl; if (freelength) { res = ntfs_cluster_free_basic(vol,freelcn, (threeparts ? freecnt : freelength)); if (!res) freed += (threeparts ? freecnt : freelength); if (!usedcnt) { holes++; freerl--; freerl->length += (threeparts ? freecnt : freelength); if (freerl->vcn < *update_from) *update_from = freerl->vcn; } } while (!res && frl->length && (freed < freecnt)) { if (frl->length <= (freecnt - freed)) { res = ntfs_cluster_free_basic(vol, frl->lcn, frl->length); if (!res) { freed += frl->length; frl->lcn = LCN_HOLE; frl->length += carry; carry = 0; holes++; } } else { res = ntfs_cluster_free_basic(vol, frl->lcn, freecnt - freed); if (!res) { frl->lcn += freecnt - freed; frl->vcn += freecnt - freed; frl->length -= freecnt - freed; freed = freecnt; } } frl++; } na->compressed_size -= freed << vol->cluster_size_bits; switch (holes) { case 0 : /* there are no hole, must insert one */ /* space for hole has been prereserved */ if (freerl->lcn == LCN_HOLE) { if (threeparts) { erl = freerl; while (erl->length) erl++; do { erl[2] = *erl; } while (erl-- != freerl); freerl[1].length = freelength - freecnt; freerl->length = freecnt; freerl[1].lcn = freelcn + freecnt; freerl[1].vcn = freevcn + freecnt; freerl[2].lcn = LCN_HOLE; freerl[2].vcn = freerl[1].vcn + freerl[1].length; freerl->vcn = freevcn; } else { freerl->vcn = freevcn; freerl->length += freelength; } } else { erl = freerl; while (erl->length) erl++; if (threeparts) { do { erl[2] = *erl; } while (erl-- != freerl); freerl[1].lcn = freelcn + freecnt; freerl[1].vcn = freevcn + freecnt; freerl[1].length = oldlength - usedcnt - freecnt; } else { do { erl[1] = *erl; } while (erl-- != freerl); } freerl->lcn = LCN_HOLE; freerl->vcn = freevcn; freerl->length = freecnt; } break; case 1 : /* there is a single hole, may have to merge */ freerl->vcn = freevcn; freerl->length = freecnt; if (freerl[1].lcn == LCN_HOLE) { freerl->length += freerl[1].length; erl = freerl; do { erl++; *erl = erl[1]; } while (erl->length); } break; default : /* there were several holes, must merge them */ freerl->lcn = LCN_HOLE; freerl->vcn = freevcn; freerl->length = freecnt; if (freerl[holes].lcn == LCN_HOLE) { freerl->length += freerl[holes].length; holes++; } erl = freerl; do { erl++; *erl = erl[holes - 1]; } while (erl->length); break; } } else { s32 freed; runlist_element *frl; runlist_element *xrl; freed = 0; frl = freerl--; if (freerl->vcn < *update_from) *update_from = freerl->vcn; while (!res && frl->length && (freed < freecnt)) { if (frl->length <= (freecnt - freed)) { freerl->length += frl->length; freed += frl->length; res = ntfs_cluster_free_basic(vol, frl->lcn, frl->length); frl++; } else { freerl->length += freecnt - freed; res = ntfs_cluster_free_basic(vol, frl->lcn, freecnt - freed); frl->lcn += freecnt - freed; frl->vcn += freecnt - freed; frl->length -= freecnt - freed; freed = freecnt; } } /* remove unneded runlist entries */ xrl = freerl; /* group with next run if also a hole */ if (frl->length && (frl->lcn == LCN_HOLE)) { xrl->length += frl->length; frl++; } while (frl->length) { *++xrl = *frl++; } *++xrl = *frl; /* terminator */ na->compressed_size -= freed << vol->cluster_size_bits; } return (res); } /* * Free unneeded clusters after compression * * This generally requires one or two empty slots at the end of runlist, * but we do not want to reallocate the runlist here because * there are many pointers to it. * So the empty slots have to be reserved beforehand * * Returns zero unless some error occurred (described by errno) */ static int ntfs_compress_free(ntfs_attr *na, runlist_element *rl, s64 used, s64 reserved, BOOL appending, VCN *update_from) { s32 freecnt; s32 usedcnt; int res; s64 freelcn; s64 freevcn; s32 freelength; BOOL mergeholes; BOOL beginhole; ntfs_volume *vol; runlist_element *freerl; res = -1; /* default return */ vol = na->ni->vol; freecnt = (reserved - used) >> vol->cluster_size_bits; usedcnt = (reserved >> vol->cluster_size_bits) - freecnt; if (rl->vcn < *update_from) *update_from = rl->vcn; /* skip entries fully used, if any */ while (rl->length && (rl->length < usedcnt)) { usedcnt -= rl->length; /* must be > 0 */ rl++; } if (rl->length) { /* * Splitting the current allocation block requires * an extra runlist element to create the hole. * The required entry has been prereserved when * mapping the runlist. */ /* get the free part in initial run */ freelcn = rl->lcn + usedcnt; freevcn = rl->vcn + usedcnt; /* new count of allocated clusters */ if (!((freevcn + freecnt) & (na->compression_block_clusters - 1))) { if (!appending) res = ntfs_compress_overwr_free(na,rl, usedcnt,freecnt,update_from); else { freelength = rl->length - usedcnt; beginhole = !usedcnt && !rl->vcn; mergeholes = !usedcnt && rl[0].vcn && (rl[-1].lcn == LCN_HOLE); if (mergeholes) { s32 carry; /* shorten the runs which have free space */ carry = freecnt; freerl = rl; while (freerl->length < carry) { carry -= freerl->length; freerl++; } freerl->length = carry; freerl = rl; } else { rl->length = usedcnt; /* can be zero ? */ freerl = ++rl; } if ((freelength > 0) && !mergeholes && (usedcnt || beginhole)) { /* * move the unused part to the end. Doing so, * the vcn will be out of order. This does * not harm, the vcn are meaningless now, and * only the lcn are meaningful for freeing. */ /* locate current end */ while (rl->length) rl++; /* new terminator relocated */ rl[1].vcn = rl->vcn; rl[1].lcn = LCN_ENOENT; rl[1].length = 0; /* hole, currently allocated */ rl->vcn = freevcn; rl->lcn = freelcn; rl->length = freelength; } else { /* why is this different from the begin hole case ? */ if ((freelength > 0) && !mergeholes && !usedcnt) { freerl--; freerl->length = freelength; if (freerl->vcn < *update_from) *update_from = freerl->vcn; } } /* free the hole */ res = ntfs_cluster_free_from_rl(vol,freerl); if (!res) { na->compressed_size -= freecnt << vol->cluster_size_bits; if (mergeholes) { /* merge with adjacent hole */ freerl--; freerl->length += freecnt; } else { if (beginhole) freerl--; /* mark hole as free */ freerl->lcn = LCN_HOLE; freerl->vcn = freevcn; freerl->length = freecnt; } if (freerl->vcn < *update_from) *update_from = freerl->vcn; /* and set up the new end */ freerl[1].lcn = LCN_ENOENT; freerl[1].vcn = freevcn + freecnt; freerl[1].length = 0; } } } else { ntfs_log_error("Bad end of a compression block set\n"); errno = EIO; } } else { ntfs_log_error("No cluster to free after compression\n"); errno = EIO; } NAttrSetRunlistDirty(na); return (res); } /* * Read existing data, decompress and append buffer * Do nothing if something fails */ static int ntfs_read_append(ntfs_attr *na, const runlist_element *rl, s64 offs, u32 compsz, s32 pos, BOOL appending, char *outbuf, s64 to_write, const void *b) { int fail = 1; char *compbuf; u32 decompsz; u32 got; if (compsz == na->compression_block_size) { /* if the full block was requested, it was a hole */ memset(outbuf,0,compsz); memcpy(&outbuf[pos],b,to_write); fail = 0; } else { compbuf = (char*)ntfs_malloc(compsz); if (compbuf) { /* must align to full block for decompression */ if (appending) decompsz = ((pos - 1) | (NTFS_SB_SIZE - 1)) + 1; else decompsz = na->compression_block_size; got = read_clusters(na->ni->vol, rl, offs, compsz, compbuf); if ((got == compsz) && !ntfs_decompress((u8*)outbuf,decompsz, (u8*)compbuf,compsz)) { memcpy(&outbuf[pos],b,to_write); fail = 0; } free(compbuf); } } return (fail); } /* * Flush a full compression block * * returns the size actually written (rounded to a full cluster) * or 0 if could not compress (and written uncompressed) * or -1 if there were an irrecoverable error (errno set) */ static s32 ntfs_flush(ntfs_attr *na, runlist_element *rl, s64 offs, char *outbuf, s32 count, BOOL compress, BOOL appending, VCN *update_from) { s32 rounded; s32 written; int clsz; if (compress) { written = ntfs_comp_set(na, rl, offs, count, outbuf); if (written == -1) compress = FALSE; if ((written >= 0) && ntfs_compress_free(na,rl,offs + written, offs + na->compression_block_size, appending, update_from)) written = -1; } else written = 0; if (!compress) { clsz = 1 << na->ni->vol->cluster_size_bits; rounded = ((count - 1) | (clsz - 1)) + 1; if (rounded > count) memset(&outbuf[count], 0, rounded - count); written = write_clusters(na->ni->vol, rl, offs, rounded, outbuf); if (written != rounded) written = -1; } return (written); } /* * Write some data to be compressed. * Compression only occurs when a few clusters (usually 16) are * full. When this occurs an extra runlist slot may be needed, so * it has to be reserved beforehand. * * Returns the size of uncompressed data written, * or negative if an error occurred. * When the returned size is less than requested, new clusters have * to be allocated before the function is called again. */ s64 ntfs_compressed_pwrite(ntfs_attr *na, runlist_element *wrl, s64 wpos, s64 offs, s64 to_write, s64 rounded, const void *b, int compressed_part, VCN *update_from) { ntfs_volume *vol; runlist_element *brl; /* entry containing the beginning of block */ int compression_length; s64 written; s64 to_read; s64 to_flush; s64 roffs; s64 got; s64 start_vcn; s64 nextblock; s64 endwrite; u32 compsz; char *inbuf; char *outbuf; BOOL fail; BOOL done; BOOL compress; BOOL appending; if (!valid_compressed_run(na,wrl,FALSE,"begin compressed write")) { return (-1); } if ((*update_from < 0) || (compressed_part < 0) || (compressed_part > (int)na->compression_block_clusters)) { ntfs_log_error("Bad update vcn or compressed_part %d for compressed write\n", compressed_part); errno = EIO; return (-1); } /* make sure there are two unused entries in runlist */ if (na->unused_runs < 2) { ntfs_log_error("No unused runs for compressed write\n"); errno = EIO; return (-1); } if (na->compression_block_size < NTFS_SB_SIZE) { ntfs_log_error("Unsupported compression block size %ld\n", (long)na->compression_block_size); errno = EOVERFLOW; return (-1); } if (wrl->vcn < *update_from) *update_from = wrl->vcn; written = -1; /* default return */ vol = na->ni->vol; compression_length = na->compression_block_clusters; compress = FALSE; done = FALSE; /* * Cannot accept writing beyond the current compression set * because when compression occurs, clusters are freed * and have to be reallocated. * (cannot happen with standard fuse 4K buffers) * Caller has to avoid this situation, or face consequences. */ nextblock = ((offs + (wrl->vcn << vol->cluster_size_bits)) | (na->compression_block_size - 1)) + 1; /* determine whether we are appending to file */ endwrite = offs + to_write + (wrl->vcn << vol->cluster_size_bits); appending = endwrite >= na->initialized_size; if (endwrite >= nextblock) { /* it is time to compress */ compress = TRUE; /* only process what we can */ to_write = rounded = nextblock - (offs + (wrl->vcn << vol->cluster_size_bits)); } start_vcn = 0; fail = FALSE; brl = wrl; roffs = 0; /* * If we are about to compress or we need to decompress * existing data, we have to process a full set of blocks. * So relocate the parameters to the beginning of allocation * containing the first byte of the set of blocks. */ if (compress || compressed_part) { /* find the beginning of block */ start_vcn = (wrl->vcn + (offs >> vol->cluster_size_bits)) & -compression_length; if (start_vcn < *update_from) *update_from = start_vcn; while (brl->vcn && (brl->vcn > start_vcn)) { /* jumping back a hole means big trouble */ if (brl->lcn == (LCN)LCN_HOLE) { ntfs_log_error("jump back over a hole when appending\n"); fail = TRUE; errno = EIO; } brl--; offs += brl->length << vol->cluster_size_bits; } roffs = (start_vcn - brl->vcn) << vol->cluster_size_bits; } if (compressed_part && !fail) { /* * The set of compression blocks contains compressed data * (we are reopening an existing file to append to it) * Decompress the data and append */ compsz = (s32)compressed_part << vol->cluster_size_bits; outbuf = (char*)ntfs_malloc(na->compression_block_size); if (outbuf) { if (appending) { to_read = offs - roffs; to_flush = to_read + to_write; } else { to_read = na->data_size - (brl->vcn << vol->cluster_size_bits); if (to_read > na->compression_block_size) to_read = na->compression_block_size; to_flush = to_read; } if (!ntfs_read_append(na, brl, roffs, compsz, (s32)(offs - roffs), appending, outbuf, to_write, b)) { written = ntfs_flush(na, brl, roffs, outbuf, to_flush, compress, appending, update_from); if (written >= 0) { written = to_write; done = TRUE; } } free(outbuf); } } else { if (compress && !fail) { /* * we are filling up a block, read the full set * of blocks and compress it */ inbuf = (char*)ntfs_malloc(na->compression_block_size); if (inbuf) { to_read = offs - roffs; if (to_read) got = read_clusters(vol, brl, roffs, to_read, inbuf); else got = 0; if (got == to_read) { memcpy(&inbuf[to_read],b,to_write); written = ntfs_comp_set(na, brl, roffs, to_read + to_write, inbuf); /* * if compression was not successful, * only write the part which was requested */ if ((written >= 0) /* free the unused clusters */ && !ntfs_compress_free(na,brl, written + roffs, na->compression_block_size + roffs, appending, update_from)) { done = TRUE; written = to_write; } } free(inbuf); } } if (!done) { /* * if the compression block is not full, or * if compression failed for whatever reason, * write uncompressed */ /* check we are not overflowing current allocation */ if ((wpos + rounded) > ((wrl->lcn + wrl->length) << vol->cluster_size_bits)) { ntfs_log_error("writing on unallocated clusters\n"); errno = EIO; } else { written = ntfs_pwrite(vol->dev, wpos, rounded, b); if (written == rounded) written = to_write; } } } if ((written >= 0) && !valid_compressed_run(na,wrl,TRUE,"end compressed write")) written = -1; return (written); } /* * Close a file written compressed. * This compresses the last partial compression block of the file. * Two empty runlist slots have to be reserved beforehand. * * Returns zero if closing is successful. */ int ntfs_compressed_close(ntfs_attr *na, runlist_element *wrl, s64 offs, VCN *update_from) { ntfs_volume *vol; runlist_element *brl; /* entry containing the beginning of block */ int compression_length; s64 written; s64 to_read; s64 roffs; s64 got; s64 start_vcn; char *inbuf; BOOL fail; BOOL done; if (na->unused_runs < 2) { ntfs_log_error("No unused runs for compressed close\n"); errno = EIO; return (-1); } if (*update_from < 0) { ntfs_log_error("Bad update vcn for compressed close\n"); errno = EIO; return (-1); } if (na->compression_block_size < NTFS_SB_SIZE) { ntfs_log_error("Unsupported compression block size %ld\n", (long)na->compression_block_size); errno = EOVERFLOW; return (-1); } if (wrl->vcn < *update_from) *update_from = wrl->vcn; vol = na->ni->vol; compression_length = na->compression_block_clusters; done = FALSE; /* * There generally is an uncompressed block at end of file, * read the full block and compress it */ inbuf = (char*)ntfs_malloc(na->compression_block_size); if (inbuf) { start_vcn = (wrl->vcn + (offs >> vol->cluster_size_bits)) & -compression_length; if (start_vcn < *update_from) *update_from = start_vcn; to_read = offs + ((wrl->vcn - start_vcn) << vol->cluster_size_bits); brl = wrl; fail = FALSE; while (brl->vcn && (brl->vcn > start_vcn)) { if (brl->lcn == (LCN)LCN_HOLE) { ntfs_log_error("jump back over a hole when closing\n"); fail = TRUE; errno = EIO; } brl--; } if (!fail) { /* roffs can be an offset from another uncomp block */ roffs = (start_vcn - brl->vcn) << vol->cluster_size_bits; if (to_read) { got = read_clusters(vol, brl, roffs, to_read, inbuf); if (got == to_read) { written = ntfs_comp_set(na, brl, roffs, to_read, inbuf); if ((written >= 0) /* free the unused clusters */ && !ntfs_compress_free(na,brl, written + roffs, na->compression_block_size + roffs, TRUE, update_from)) { done = TRUE; } else /* if compression failed, leave uncompressed */ if (written == -1) done = TRUE; } } else done = TRUE; free(inbuf); } } if (done && !valid_compressed_run(na,wrl,TRUE,"end compressed close")) done = FALSE; return (!done); } ntfs-3g-2026.2.25/libntfs-3g/unix_io.c0000664000175000017500000002077215152260173012576 /** * unix_io.c - Unix style disk io functions. Originated from the Linux-NTFS project. * * Copyright (c) 2000-2006 Anton Altaparmakov * * This program/include file 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/include file 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_UNISTD_H #include #endif #ifdef HAVE_STDLIB_H #include #endif #ifdef HAVE_STRING_H #include #endif #ifdef HAVE_ERRNO_H #include #endif #ifdef HAVE_STDIO_H #include #endif #ifdef HAVE_SYS_TYPES_H #include #endif #ifdef HAVE_SYS_STAT_H #include #endif #ifdef HAVE_FCNTL_H #include #endif #ifdef HAVE_SYS_IOCTL_H #include #endif #ifdef HAVE_LINUX_FD_H #include #endif #ifdef HAVE_LINUX_FS_H #include #endif #include "types.h" #include "mst.h" #include "debug.h" #include "device.h" #include "logging.h" #include "misc.h" #define DEV_FD(dev) (*(int *)dev->d_private) /* Define to nothing if not present on this system. */ #ifndef O_EXCL # define O_EXCL 0 #endif /** * fsync replacement which makes every effort to try to get the data down to * disk, using different means for different operating systems. Specifically, * it issues the proper fcntl for Mac OS X or does fsync where it is available * or as a last resort calls the fsync function. Information on this problem * was retrieved from: * http://mirror.linux.org.au/pub/linux.conf.au/2007/video/talks/278.pdf */ static int ntfs_fsync(int fildes) { int ret = -1; #if defined(__APPLE__) || defined(__DARWIN__) # ifndef F_FULLFSYNC # error "Mac OS X: F_FULLFSYNC is not defined. Either you didn't include fcntl.h or you're using an older, unsupported version of Mac OS X (pre-10.3)." # endif /* * Apple has disabled fsync() for internal disk drives in OS X. * To force a synchronization of disk contents, we use a Mac OS X * specific fcntl, F_FULLFSYNC. */ ret = fcntl(fildes, F_FULLFSYNC, NULL); if (ret) { /* * If we are not on a file system that supports this, * then fall back to a plain fsync. */ ret = fsync(fildes); } #else ret = fsync(fildes); #endif return ret; } /** * ntfs_device_unix_io_open - Open a device and lock it exclusively * @dev: * @flags: * * Description... * * Returns: */ static int ntfs_device_unix_io_open(struct ntfs_device *dev, int flags) { struct flock flk; struct stat sbuf; int err; if (NDevOpen(dev)) { errno = EBUSY; return -1; } if (stat(dev->d_name, &sbuf)) { ntfs_log_perror("Failed to access '%s'", dev->d_name); return -1; } if (S_ISBLK(sbuf.st_mode)) NDevSetBlock(dev); dev->d_private = ntfs_malloc(sizeof(int)); if (!dev->d_private) return -1; /* * Open file for exclusive access if mounting r/w. * Fuseblk takes care about block devices. */ if (!NDevBlock(dev) && (flags & O_RDWR) == O_RDWR) flags |= O_EXCL; *(int*)dev->d_private = open(dev->d_name, flags); if (*(int*)dev->d_private == -1) { err = errno; /* if permission error and rw, retry read-only */ if ((err == EACCES) && ((flags & O_RDWR) == O_RDWR)) err = EROFS; goto err_out; } #ifdef HAVE_LINUX_FS_H /* Check whether the device was forced read-only */ if (NDevBlock(dev) && ((flags & O_RDWR) == O_RDWR)) { int r; int state; r = ioctl(DEV_FD(dev), BLKROGET, &state); if (!r && state) { err = EROFS; if (close(DEV_FD(dev))) err = errno; goto err_out; } } #endif if ((flags & O_RDWR) != O_RDWR) NDevSetReadOnly(dev); memset(&flk, 0, sizeof(flk)); if (NDevReadOnly(dev)) flk.l_type = F_RDLCK; else flk.l_type = F_WRLCK; flk.l_whence = SEEK_SET; flk.l_start = flk.l_len = 0LL; if (fcntl(DEV_FD(dev), F_SETLK, &flk)) { err = errno; ntfs_log_perror("Failed to %s lock '%s'", NDevReadOnly(dev) ? "read" : "write", dev->d_name); if (close(DEV_FD(dev))) ntfs_log_perror("Failed to close '%s'", dev->d_name); goto err_out; } NDevSetOpen(dev); return 0; err_out: free(dev->d_private); dev->d_private = NULL; errno = err; return -1; } /** * ntfs_device_unix_io_close - Close the device, releasing the lock * @dev: * * Description... * * Returns: */ static int ntfs_device_unix_io_close(struct ntfs_device *dev) { struct flock flk; if (!NDevOpen(dev)) { errno = EBADF; ntfs_log_perror("Device %s is not open", dev->d_name); return -1; } if (NDevDirty(dev)) if (ntfs_fsync(DEV_FD(dev))) { ntfs_log_perror("Failed to fsync device %s", dev->d_name); return -1; } memset(&flk, 0, sizeof(flk)); flk.l_type = F_UNLCK; flk.l_whence = SEEK_SET; flk.l_start = flk.l_len = 0LL; if (fcntl(DEV_FD(dev), F_SETLK, &flk)) ntfs_log_perror("Could not unlock %s", dev->d_name); if (close(DEV_FD(dev))) { ntfs_log_perror("Failed to close device %s", dev->d_name); return -1; } NDevClearOpen(dev); free(dev->d_private); dev->d_private = NULL; return 0; } /** * ntfs_device_unix_io_seek - Seek to a place on the device * @dev: * @offset: * @whence: * * Description... * * Returns: */ static s64 ntfs_device_unix_io_seek(struct ntfs_device *dev, s64 offset, int whence) { return lseek(DEV_FD(dev), offset, whence); } /** * ntfs_device_unix_io_read - Read from the device, from the current location * @dev: * @buf: * @count: * * Description... * * Returns: */ static s64 ntfs_device_unix_io_read(struct ntfs_device *dev, void *buf, s64 count) { return read(DEV_FD(dev), buf, count); } /** * ntfs_device_unix_io_write - Write to the device, at the current location * @dev: * @buf: * @count: * * Description... * * Returns: */ static s64 ntfs_device_unix_io_write(struct ntfs_device *dev, const void *buf, s64 count) { if (NDevReadOnly(dev)) { errno = EROFS; return -1; } NDevSetDirty(dev); return write(DEV_FD(dev), buf, count); } /** * ntfs_device_unix_io_pread - Perform a positioned read from the device * @dev: * @buf: * @count: * @offset: * * Description... * * Returns: */ static s64 ntfs_device_unix_io_pread(struct ntfs_device *dev, void *buf, s64 count, s64 offset) { return pread(DEV_FD(dev), buf, count, offset); } /** * ntfs_device_unix_io_pwrite - Perform a positioned write to the device * @dev: * @buf: * @count: * @offset: * * Description... * * Returns: */ static s64 ntfs_device_unix_io_pwrite(struct ntfs_device *dev, const void *buf, s64 count, s64 offset) { if (NDevReadOnly(dev)) { errno = EROFS; return -1; } NDevSetDirty(dev); return pwrite(DEV_FD(dev), buf, count, offset); } /** * ntfs_device_unix_io_sync - Flush any buffered changes to the device * @dev: * * Description... * * Returns: */ static int ntfs_device_unix_io_sync(struct ntfs_device *dev) { int res = 0; if (!NDevReadOnly(dev)) { res = ntfs_fsync(DEV_FD(dev)); if (res) ntfs_log_perror("Failed to sync device %s", dev->d_name); else NDevClearDirty(dev); } return res; } /** * ntfs_device_unix_io_stat - Get information about the device * @dev: * @buf: * * Description... * * Returns: */ static int ntfs_device_unix_io_stat(struct ntfs_device *dev, struct stat *buf) { return fstat(DEV_FD(dev), buf); } /** * ntfs_device_unix_io_ioctl - Perform an ioctl on the device * @dev: * @request: * @argp: * * Description... * * Returns: */ static int ntfs_device_unix_io_ioctl(struct ntfs_device *dev, unsigned long request, void *argp) { return ioctl(DEV_FD(dev), request, argp); } /** * Device operations for working with unix style devices and files. */ struct ntfs_device_operations ntfs_device_unix_io_ops = { .open = ntfs_device_unix_io_open, .close = ntfs_device_unix_io_close, .seek = ntfs_device_unix_io_seek, .read = ntfs_device_unix_io_read, .write = ntfs_device_unix_io_write, .pread = ntfs_device_unix_io_pread, .pwrite = ntfs_device_unix_io_pwrite, .sync = ntfs_device_unix_io_sync, .stat = ntfs_device_unix_io_stat, .ioctl = ntfs_device_unix_io_ioctl, }; ntfs-3g-2026.2.25/libntfs-3g/runlist.c0000664000175000017500000017371715152260173012634 /** * runlist.c - Run list handling code. Originated from the Linux-NTFS project. * * Copyright (c) 2002-2005 Anton Altaparmakov * Copyright (c) 2002-2005 Richard Russon * Copyright (c) 2002-2008 Szabolcs Szakacsits * Copyright (c) 2004 Yura Pakhuchiy * Copyright (c) 2007-2022 Jean-Pierre Andre * * This program/include file 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/include file 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_STDIO_H #include #endif #ifdef HAVE_STRING_H #include #endif #ifdef HAVE_STDLIB_H #include #endif #ifdef HAVE_ERRNO_H #include #endif #include "compat.h" #include "types.h" #include "volume.h" #include "layout.h" #include "debug.h" #include "device.h" #include "logging.h" #include "misc.h" /** * ntfs_rl_mm - runlist memmove * @base: * @dst: * @src: * @size: * * Description... * * Returns: */ static void ntfs_rl_mm(runlist_element *base, int dst, int src, int size) { if ((dst != src) && (size > 0)) memmove(base + dst, base + src, size * sizeof(*base)); } /** * ntfs_rl_mc - runlist memory copy * @dstbase: * @dst: * @srcbase: * @src: * @size: * * Description... * * Returns: */ static void ntfs_rl_mc(runlist_element *dstbase, int dst, runlist_element *srcbase, int src, int size) { if (size > 0) memcpy(dstbase + dst, srcbase + src, size * sizeof(*dstbase)); } /** * ntfs_rl_realloc - Reallocate memory for runlists * @rl: original runlist * @old_size: number of runlist elements in the original runlist @rl * @new_size: number of runlist elements we need space for * * As the runlists grow, more memory will be required. To prevent large * numbers of small reallocations of memory, this function returns a 4kiB block * of memory. * * N.B. If the new allocation doesn't require a different number of 4kiB * blocks in memory, the function will return the original pointer. * * On success, return a pointer to the newly allocated, or recycled, memory. * On error, return NULL with errno set to the error code. */ static runlist_element *ntfs_rl_realloc(runlist_element *rl, int old_size, int new_size) { old_size = (old_size * sizeof(runlist_element) + 0xfff) & ~0xfff; new_size = (new_size * sizeof(runlist_element) + 0xfff) & ~0xfff; if (old_size == new_size) return rl; return realloc(rl, new_size); } /* * Extend a runlist by some entry count * The runlist may have to be reallocated * * Returns the reallocated runlist * or NULL if reallocation was not possible (with errno set) * the runlist is left unchanged if the reallocation fails */ runlist_element *ntfs_rl_extend(ntfs_attr *na, runlist_element *rl, int more_entries) { runlist_element *newrl; int last; int irl; if (na->rl && rl) { irl = (int)(rl - na->rl); last = irl; while (na->rl[last].length) last++; newrl = ntfs_rl_realloc(na->rl,last+1,last+more_entries+1); if (!newrl) { errno = ENOMEM; rl = (runlist_element*)NULL; } else { na->rl = newrl; rl = &newrl[irl]; } } else { ntfs_log_error("Cannot extend unmapped runlist"); errno = EIO; rl = (runlist_element*)NULL; } return (rl); } /** * ntfs_rl_are_mergeable - test if two runlists can be joined together * @dst: original runlist * @src: new runlist to test for mergeability with @dst * * Test if two runlists can be joined together. For this, their VCNs and LCNs * must be adjacent. * * Return: TRUE Success, the runlists can be merged. * FALSE Failure, the runlists cannot be merged. */ static BOOL ntfs_rl_are_mergeable(runlist_element *dst, runlist_element *src) { if (!dst || !src) { ntfs_log_debug("Eeek. ntfs_rl_are_mergeable() invoked with NULL " "pointer!\n"); return FALSE; } /* We can merge unmapped regions even if they are misaligned. */ if ((dst->lcn == LCN_RL_NOT_MAPPED) && (src->lcn == LCN_RL_NOT_MAPPED)) return TRUE; /* If the runs are misaligned, we cannot merge them. */ if ((dst->vcn + dst->length) != src->vcn) return FALSE; /* If both runs are non-sparse and contiguous, we can merge them. */ if ((dst->lcn >= 0) && (src->lcn >= 0) && ((dst->lcn + dst->length) == src->lcn)) return TRUE; /* If we are merging two holes, we can merge them. */ if ((dst->lcn == LCN_HOLE) && (src->lcn == LCN_HOLE)) return TRUE; /* Cannot merge. */ return FALSE; } /** * __ntfs_rl_merge - merge two runlists without testing if they can be merged * @dst: original, destination runlist * @src: new runlist to merge with @dst * * Merge the two runlists, writing into the destination runlist @dst. The * caller must make sure the runlists can be merged or this will corrupt the * destination runlist. */ static void __ntfs_rl_merge(runlist_element *dst, runlist_element *src) { dst->length += src->length; } /** * ntfs_rl_append - append a runlist after a given element * @dst: original runlist to be worked on * @dsize: number of elements in @dst (including end marker) * @src: runlist to be inserted into @dst * @ssize: number of elements in @src (excluding end marker) * @loc: append the new runlist @src after this element in @dst * * Append the runlist @src after element @loc in @dst. Merge the right end of * the new runlist, if necessary. Adjust the size of the hole before the * appended runlist. * * On success, return a pointer to the new, combined, runlist. Note, both * runlists @dst and @src are deallocated before returning so you cannot use * the pointers for anything any more. (Strictly speaking the returned runlist * may be the same as @dst but this is irrelevant.) * * On error, return NULL, with errno set to the error code. Both runlists are * left unmodified. */ static runlist_element *ntfs_rl_append(runlist_element *dst, int dsize, runlist_element *src, int ssize, int loc) { BOOL right = FALSE; /* Right end of @src needs merging */ int marker; /* End of the inserted runs */ if (!dst || !src) { ntfs_log_debug("Eeek. ntfs_rl_append() invoked with NULL " "pointer!\n"); errno = EINVAL; return NULL; } /* First, check if the right hand end needs merging. */ if ((loc + 1) < dsize) right = ntfs_rl_are_mergeable(src + ssize - 1, dst + loc + 1); /* Space required: @dst size + @src size, less one if we merged. */ dst = ntfs_rl_realloc(dst, dsize, dsize + ssize - right); if (!dst) return NULL; /* * We are guaranteed to succeed from here so can start modifying the * original runlists. */ /* First, merge the right hand end, if necessary. */ if (right) __ntfs_rl_merge(src + ssize - 1, dst + loc + 1); /* marker - First run after the @src runs that have been inserted */ marker = loc + ssize + 1; /* Move the tail of @dst out of the way, then copy in @src. */ ntfs_rl_mm(dst, marker, loc + 1 + right, dsize - loc - 1 - right); ntfs_rl_mc(dst, loc + 1, src, 0, ssize); /* Adjust the size of the preceding hole. */ dst[loc].length = dst[loc + 1].vcn - dst[loc].vcn; /* We may have changed the length of the file, so fix the end marker */ if (dst[marker].lcn == LCN_ENOENT) dst[marker].vcn = dst[marker-1].vcn + dst[marker-1].length; return dst; } /** * ntfs_rl_insert - insert a runlist into another * @dst: original runlist to be worked on * @dsize: number of elements in @dst (including end marker) * @src: new runlist to be inserted * @ssize: number of elements in @src (excluding end marker) * @loc: insert the new runlist @src before this element in @dst * * Insert the runlist @src before element @loc in the runlist @dst. Merge the * left end of the new runlist, if necessary. Adjust the size of the hole * after the inserted runlist. * * On success, return a pointer to the new, combined, runlist. Note, both * runlists @dst and @src are deallocated before returning so you cannot use * the pointers for anything any more. (Strictly speaking the returned runlist * may be the same as @dst but this is irrelevant.) * * On error, return NULL, with errno set to the error code. Both runlists are * left unmodified. */ static runlist_element *ntfs_rl_insert(runlist_element *dst, int dsize, runlist_element *src, int ssize, int loc) { BOOL left = FALSE; /* Left end of @src needs merging */ BOOL disc = FALSE; /* Discontinuity between @dst and @src */ int marker; /* End of the inserted runs */ if (!dst || !src) { ntfs_log_debug("Eeek. ntfs_rl_insert() invoked with NULL " "pointer!\n"); errno = EINVAL; return NULL; } /* disc => Discontinuity between the end of @dst and the start of @src. * This means we might need to insert a "notmapped" run. */ if (loc == 0) disc = (src[0].vcn > 0); else { s64 merged_length; left = ntfs_rl_are_mergeable(dst + loc - 1, src); merged_length = dst[loc - 1].length; if (left) merged_length += src->length; disc = (src[0].vcn > dst[loc - 1].vcn + merged_length); } /* Space required: @dst size + @src size, less one if we merged, plus * one if there was a discontinuity. */ dst = ntfs_rl_realloc(dst, dsize, dsize + ssize - left + disc); if (!dst) return NULL; /* * We are guaranteed to succeed from here so can start modifying the * original runlist. */ if (left) __ntfs_rl_merge(dst + loc - 1, src); /* * marker - First run after the @src runs that have been inserted * Nominally: marker = @loc + @ssize (location + number of runs in @src) * If "left", then the first run in @src has been merged with one in @dst. * If "disc", then @dst and @src don't meet and we need an extra run to fill the gap. */ marker = loc + ssize - left + disc; /* Move the tail of @dst out of the way, then copy in @src. */ ntfs_rl_mm(dst, marker, loc, dsize - loc); ntfs_rl_mc(dst, loc + disc, src, left, ssize - left); /* Adjust the VCN of the first run after the insertion ... */ dst[marker].vcn = dst[marker - 1].vcn + dst[marker - 1].length; /* ... and the length. */ if (dst[marker].lcn == LCN_HOLE || dst[marker].lcn == LCN_RL_NOT_MAPPED) dst[marker].length = dst[marker + 1].vcn - dst[marker].vcn; /* Writing beyond the end of the file and there's a discontinuity. */ if (disc) { if (loc > 0) { dst[loc].vcn = dst[loc - 1].vcn + dst[loc - 1].length; dst[loc].length = dst[loc + 1].vcn - dst[loc].vcn; } else { dst[loc].vcn = 0; dst[loc].length = dst[loc + 1].vcn; } dst[loc].lcn = LCN_RL_NOT_MAPPED; } return dst; } /** * ntfs_rl_replace - overwrite a runlist element with another runlist * @dst: original runlist to be worked on * @dsize: number of elements in @dst (including end marker) * @src: new runlist to be inserted * @ssize: number of elements in @src (excluding end marker) * @loc: index in runlist @dst to overwrite with @src * * Replace the runlist element @dst at @loc with @src. Merge the left and * right ends of the inserted runlist, if necessary. * * On success, return a pointer to the new, combined, runlist. Note, both * runlists @dst and @src are deallocated before returning so you cannot use * the pointers for anything any more. (Strictly speaking the returned runlist * may be the same as @dst but this is irrelevant.) * * On error, return NULL, with errno set to the error code. Both runlists are * left unmodified. */ static runlist_element *ntfs_rl_replace(runlist_element *dst, int dsize, runlist_element *src, int ssize, int loc) { signed delta; BOOL left = FALSE; /* Left end of @src needs merging */ BOOL right = FALSE; /* Right end of @src needs merging */ int tail; /* Start of tail of @dst */ int marker; /* End of the inserted runs */ if (!dst || !src) { ntfs_log_debug("Eeek. ntfs_rl_replace() invoked with NULL " "pointer!\n"); errno = EINVAL; return NULL; } /* First, see if the left and right ends need merging. */ if ((loc + 1) < dsize) right = ntfs_rl_are_mergeable(src + ssize - 1, dst + loc + 1); if (loc > 0) left = ntfs_rl_are_mergeable(dst + loc - 1, src); /* Allocate some space. We'll need less if the left, right, or both * ends get merged. The -1 accounts for the run being replaced. */ delta = ssize - 1 - left - right; if (delta > 0) { dst = ntfs_rl_realloc(dst, dsize, dsize + delta); if (!dst) return NULL; } /* * We are guaranteed to succeed from here so can start modifying the * original runlists. */ /* First, merge the left and right ends, if necessary. */ if (right) __ntfs_rl_merge(src + ssize - 1, dst + loc + 1); if (left) __ntfs_rl_merge(dst + loc - 1, src); /* * tail - Offset of the tail of @dst * Nominally: @tail = @loc + 1 (location, skipping the replaced run) * If "right", then one of @dst's runs is already merged into @src. */ tail = loc + right + 1; /* * marker - First run after the @src runs that have been inserted * Nominally: @marker = @loc + @ssize (location + number of runs in @src) * If "left", then the first run in @src has been merged with one in @dst. */ marker = loc + ssize - left; /* Move the tail of @dst out of the way, then copy in @src. */ ntfs_rl_mm(dst, marker, tail, dsize - tail); ntfs_rl_mc(dst, loc, src, left, ssize - left); /* We may have changed the length of the file, so fix the end marker */ if (((dsize - tail) > 0) && (dst[marker].lcn == LCN_ENOENT)) dst[marker].vcn = dst[marker - 1].vcn + dst[marker - 1].length; return dst; } /** * ntfs_rl_split - insert a runlist into the centre of a hole * @dst: original runlist to be worked on * @dsize: number of elements in @dst (including end marker) * @src: new runlist to be inserted * @ssize: number of elements in @src (excluding end marker) * @loc: index in runlist @dst at which to split and insert @src * * Split the runlist @dst at @loc into two and insert @new in between the two * fragments. No merging of runlists is necessary. Adjust the size of the * holes either side. * * On success, return a pointer to the new, combined, runlist. Note, both * runlists @dst and @src are deallocated before returning so you cannot use * the pointers for anything any more. (Strictly speaking the returned runlist * may be the same as @dst but this is irrelevant.) * * On error, return NULL, with errno set to the error code. Both runlists are * left unmodified. */ static runlist_element *ntfs_rl_split(runlist_element *dst, int dsize, runlist_element *src, int ssize, int loc) { if (!dst || !src) { ntfs_log_debug("Eeek. ntfs_rl_split() invoked with NULL pointer!\n"); errno = EINVAL; return NULL; } /* Space required: @dst size + @src size + one new hole. */ dst = ntfs_rl_realloc(dst, dsize, dsize + ssize + 1); if (!dst) return dst; /* * We are guaranteed to succeed from here so can start modifying the * original runlists. */ /* Move the tail of @dst out of the way, then copy in @src. */ ntfs_rl_mm(dst, loc + 1 + ssize, loc, dsize - loc); ntfs_rl_mc(dst, loc + 1, src, 0, ssize); /* Adjust the size of the holes either size of @src. */ dst[loc].length = dst[loc+1].vcn - dst[loc].vcn; dst[loc+ssize+1].vcn = dst[loc+ssize].vcn + dst[loc+ssize].length; dst[loc+ssize+1].length = dst[loc+ssize+2].vcn - dst[loc+ssize+1].vcn; return dst; } /** * ntfs_runlists_merge_i - see ntfs_runlists_merge */ static runlist_element *ntfs_runlists_merge_i(runlist_element *drl, runlist_element *srl) { int di, si; /* Current index into @[ds]rl. */ int sstart; /* First index with lcn > LCN_RL_NOT_MAPPED. */ int dins; /* Index into @drl at which to insert @srl. */ int dend, send; /* Last index into @[ds]rl. */ int dfinal, sfinal; /* The last index into @[ds]rl with lcn >= LCN_HOLE. */ int marker = 0; VCN marker_vcn = 0; ntfs_log_debug("dst:\n"); ntfs_debug_runlist_dump(drl); ntfs_log_debug("src:\n"); ntfs_debug_runlist_dump(srl); /* Check for silly calling... */ if (!srl) return drl; /* Check for the case where the first mapping is being done now. */ if (!drl) { drl = srl; /* Complete the source runlist if necessary. */ if (drl[0].vcn) { /* Scan to the end of the source runlist. */ for (dend = 0; drl[dend].length; dend++) ; dend++; drl = ntfs_rl_realloc(drl, dend, dend + 1); if (!drl) return drl; /* Insert start element at the front of the runlist. */ ntfs_rl_mm(drl, 1, 0, dend); drl[0].vcn = 0; drl[0].lcn = LCN_RL_NOT_MAPPED; drl[0].length = drl[1].vcn; } goto finished; } si = di = 0; /* Skip any unmapped start element(s) in the source runlist. */ while (srl[si].length && srl[si].lcn < (LCN)LCN_HOLE) si++; /* Can't have an entirely unmapped source runlist. */ if (!srl[si].length) { errno = EINVAL; ntfs_log_perror("%s: unmapped source runlist", __FUNCTION__); return NULL; } /* Record the starting points. */ sstart = si; /* * Skip forward in @drl until we reach the position where @srl needs to * be inserted. If we reach the end of @drl, @srl just needs to be * appended to @drl. */ for (; drl[di].length; di++) { if (drl[di].vcn + drl[di].length > srl[sstart].vcn) break; } dins = di; /* Sanity check for illegal overlaps. */ if ((drl[di].vcn == srl[si].vcn) && (drl[di].lcn >= 0) && (srl[si].lcn >= 0)) { errno = ERANGE; ntfs_log_perror("Run lists overlap. Cannot merge"); return NULL; } /* Scan to the end of both runlists in order to know their sizes. */ for (send = si; srl[send].length; send++) ; for (dend = di; drl[dend].length; dend++) ; if (srl[send].lcn == (LCN)LCN_ENOENT) marker_vcn = srl[marker = send].vcn; /* Scan to the last element with lcn >= LCN_HOLE. */ for (sfinal = send; sfinal >= 0 && srl[sfinal].lcn < LCN_HOLE; sfinal--) ; for (dfinal = dend; dfinal >= 0 && drl[dfinal].lcn < LCN_HOLE; dfinal--) ; { BOOL start; BOOL finish; int ds = dend + 1; /* Number of elements in drl & srl */ int ss = sfinal - sstart + 1; start = ((drl[dins].lcn < LCN_RL_NOT_MAPPED) || /* End of file */ (drl[dins].vcn == srl[sstart].vcn)); /* Start of hole */ finish = ((drl[dins].lcn >= LCN_RL_NOT_MAPPED) && /* End of file */ ((drl[dins].vcn + drl[dins].length) <= /* End of hole */ (srl[send - 1].vcn + srl[send - 1].length))); /* Or we'll lose an end marker */ if (finish && !drl[dins].length) ss++; if (marker && (drl[dins].vcn + drl[dins].length > srl[send - 1].vcn)) finish = FALSE; ntfs_log_debug("dfinal = %i, dend = %i\n", dfinal, dend); ntfs_log_debug("sstart = %i, sfinal = %i, send = %i\n", sstart, sfinal, send); ntfs_log_debug("start = %i, finish = %i\n", start, finish); ntfs_log_debug("ds = %i, ss = %i, dins = %i\n", ds, ss, dins); if (start) { if (finish) drl = ntfs_rl_replace(drl, ds, srl + sstart, ss, dins); else drl = ntfs_rl_insert(drl, ds, srl + sstart, ss, dins); } else { if (finish) drl = ntfs_rl_append(drl, ds, srl + sstart, ss, dins); else drl = ntfs_rl_split(drl, ds, srl + sstart, ss, dins); } if (!drl) { ntfs_log_perror("Merge failed"); return drl; } free(srl); if (marker) { ntfs_log_debug("Triggering marker code.\n"); for (ds = dend; drl[ds].length; ds++) ; /* We only need to care if @srl ended after @drl. */ if (drl[ds].vcn <= marker_vcn) { int slots = 0; if (drl[ds].vcn == marker_vcn) { ntfs_log_debug("Old marker = %lli, replacing with " "LCN_ENOENT.\n", (long long)drl[ds].lcn); drl[ds].lcn = (LCN)LCN_ENOENT; goto finished; } /* * We need to create an unmapped runlist element in * @drl or extend an existing one before adding the * ENOENT terminator. */ if (drl[ds].lcn == (LCN)LCN_ENOENT) { ds--; slots = 1; } if (drl[ds].lcn != (LCN)LCN_RL_NOT_MAPPED) { /* Add an unmapped runlist element. */ if (!slots) { /* FIXME/TODO: We need to have the * extra memory already! (AIA) */ drl = ntfs_rl_realloc(drl, ds, ds + 2); if (!drl) goto critical_error; slots = 2; } ds++; /* Need to set vcn if it isn't set already. */ if (slots != 1) drl[ds].vcn = drl[ds - 1].vcn + drl[ds - 1].length; drl[ds].lcn = (LCN)LCN_RL_NOT_MAPPED; /* We now used up a slot. */ slots--; } drl[ds].length = marker_vcn - drl[ds].vcn; /* Finally add the ENOENT terminator. */ ds++; if (!slots) { /* FIXME/TODO: We need to have the extra * memory already! (AIA) */ drl = ntfs_rl_realloc(drl, ds, ds + 1); if (!drl) goto critical_error; } drl[ds].vcn = marker_vcn; drl[ds].lcn = (LCN)LCN_ENOENT; drl[ds].length = (s64)0; } } } finished: /* The merge was completed successfully. */ ntfs_log_debug("Merged runlist:\n"); ntfs_debug_runlist_dump(drl); return drl; critical_error: /* Critical error! We cannot afford to fail here. */ ntfs_log_perror("libntfs: Critical error"); ntfs_log_debug("Forcing segmentation fault!\n"); marker_vcn = ((runlist*)NULL)->lcn; return drl; } /** * ntfs_runlists_merge - merge two runlists into one * @drl: original runlist to be worked on * @srl: new runlist to be merged into @drl * * First we sanity check the two runlists @srl and @drl to make sure that they * are sensible and can be merged. The runlist @srl must be either after the * runlist @drl or completely within a hole (or unmapped region) in @drl. * * Merging of runlists is necessary in two cases: * 1. When attribute lists are used and a further extent is being mapped. * 2. When new clusters are allocated to fill a hole or extend a file. * * There are four possible ways @srl can be merged. It can: * - be inserted at the beginning of a hole, * - split the hole in two and be inserted between the two fragments, * - be appended at the end of a hole, or it can * - replace the whole hole. * It can also be appended to the end of the runlist, which is just a variant * of the insert case. * * On success, return a pointer to the new, combined, runlist. Note, both * runlists @drl and @srl are deallocated before returning so you cannot use * the pointers for anything any more. (Strictly speaking the returned runlist * may be the same as @dst but this is irrelevant.) * * On error, return NULL, with errno set to the error code. Both runlists are * left unmodified. The following error codes are defined: * ENOMEM Not enough memory to allocate runlist array. * EINVAL Invalid parameters were passed in. * ERANGE The runlists overlap and cannot be merged. */ runlist_element *ntfs_runlists_merge(runlist_element *drl, runlist_element *srl) { runlist_element *rl; ntfs_log_enter("Entering\n"); rl = ntfs_runlists_merge_i(drl, srl); ntfs_log_leave("\n"); return rl; } /** * ntfs_mapping_pairs_decompress - convert mapping pairs array to runlist * @vol: ntfs volume on which the attribute resides * @attr: attribute record whose mapping pairs array to decompress * @old_rl: optional runlist in which to insert @attr's runlist * * Decompress the attribute @attr's mapping pairs array into a runlist. On * success, return the decompressed runlist. * * If @old_rl is not NULL, decompressed runlist is inserted into the * appropriate place in @old_rl and the resultant, combined runlist is * returned. The original @old_rl is deallocated. * * On error, return NULL with errno set to the error code. @old_rl is left * unmodified in that case. * * The following error codes are defined: * ENOMEM Not enough memory to allocate runlist array. * EIO Corrupt runlist. * EINVAL Invalid parameters were passed in. * ERANGE The two runlists overlap. * * FIXME: For now we take the conceptionally simplest approach of creating the * new runlist disregarding the already existing one and then splicing the * two into one, if that is possible (we check for overlap and discard the new * runlist if overlap present before returning NULL, with errno = ERANGE). */ static runlist_element *ntfs_mapping_pairs_decompress_i(const ntfs_volume *vol, const ATTR_RECORD *attr, runlist_element *old_rl) { VCN vcn; /* Current vcn. */ LCN lcn; /* Current lcn. */ s64 deltaxcn; /* Change in [vl]cn. */ runlist_element *rl; /* The output runlist. */ const u8 *buf; /* Current position in mapping pairs array. */ const u8 *attr_end; /* End of attribute. */ int err, rlsize; /* Size of runlist buffer. */ u16 rlpos; /* Current runlist position in units of runlist_elements. */ u8 b; /* Current byte offset in buf. */ ntfs_log_trace("Entering for attr 0x%x.\n", (unsigned)le32_to_cpu(attr->type)); /* Make sure attr exists and is non-resident. */ if (!attr || !attr->non_resident || sle64_to_cpu(attr->lowest_vcn) < (VCN)0) { errno = EINVAL; return NULL; } /* Start at vcn = lowest_vcn and lcn 0. */ vcn = sle64_to_cpu(attr->lowest_vcn); lcn = 0; /* Get start of the mapping pairs array. */ buf = (const u8*)attr + le16_to_cpu(attr->mapping_pairs_offset); attr_end = (const u8*)attr + le32_to_cpu(attr->length); if (buf < (const u8*)attr || buf > attr_end) { ntfs_log_debug("Corrupt attribute.\n"); errno = EIO; return NULL; } /* Current position in runlist array. */ rlpos = 0; /* Allocate first 4kiB block and set current runlist size to 4kiB. */ rlsize = 0x1000; rl = ntfs_malloc(rlsize); if (!rl) return NULL; /* Insert unmapped starting element if necessary. */ if (vcn) { rl->vcn = (VCN)0; rl->lcn = (LCN)LCN_RL_NOT_MAPPED; rl->length = vcn; rlpos++; } while (buf < attr_end && *buf) { /* * Allocate more memory if needed, including space for the * not-mapped and terminator elements. */ if ((int)((rlpos + 3) * sizeof(*old_rl)) > rlsize) { runlist_element *rl2; rlsize += 0x1000; rl2 = realloc(rl, rlsize); if (!rl2) { int eo = errno; free(rl); errno = eo; return NULL; } rl = rl2; } /* Enter the current vcn into the current runlist element. */ rl[rlpos].vcn = vcn; /* * Get the change in vcn, i.e. the run length in clusters. * Doing it this way ensures that we signextend negative values. * A negative run length doesn't make any sense, but hey, I * didn't make up the NTFS specs and Windows NT4 treats the run * length as a signed value so that's how it is... */ b = *buf & 0xf; if (b) { if (buf + b > attr_end) goto io_error; for (deltaxcn = (s8)buf[b--]; b; b--) deltaxcn = (deltaxcn << 8) + buf[b]; } else { /* The length entry is compulsory. */ ntfs_log_debug("Missing length entry in mapping pairs " "array.\n"); deltaxcn = (s64)-1; } /* * Assume a negative length to indicate data corruption and * hence clean-up and return NULL. */ if (deltaxcn < 0) { ntfs_log_debug("Invalid length in mapping pairs array.\n"); goto err_out; } /* * Enter the current run length into the current runlist * element. */ rl[rlpos].length = deltaxcn; /* Increment the current vcn by the current run length. */ vcn += deltaxcn; /* * There might be no lcn change at all, as is the case for * sparse clusters on NTFS 3.0+, in which case we set the lcn * to LCN_HOLE. */ if (!(*buf & 0xf0)) rl[rlpos].lcn = (LCN)LCN_HOLE; else { /* Get the lcn change which really can be negative. */ u8 b2 = *buf & 0xf; b = b2 + ((*buf >> 4) & 0xf); if (buf + b > attr_end) goto io_error; for (deltaxcn = (s8)buf[b--]; b > b2; b--) deltaxcn = (deltaxcn << 8) + buf[b]; /* Change the current lcn to it's new value. */ lcn += deltaxcn; #ifdef DEBUG /* * On NTFS 1.2-, apparently can have lcn == -1 to * indicate a hole. But we haven't verified ourselves * whether it is really the lcn or the deltaxcn that is * -1. So if either is found give us a message so we * can investigate it further! */ if (vol->major_ver < 3) { if (deltaxcn == (LCN)-1) ntfs_log_debug("lcn delta == -1\n"); if (lcn == (LCN)-1) ntfs_log_debug("lcn == -1\n"); } #endif /* Check lcn is not below -1. */ if (lcn < (LCN)-1) { ntfs_log_debug("Invalid LCN < -1 in mapping pairs " "array.\n"); goto err_out; } /* chkdsk accepts zero-sized runs only for holes */ if ((lcn != (LCN)-1) && !rl[rlpos].length) { ntfs_log_debug( "Invalid zero-sized data run.\n"); goto err_out; } /* Enter the current lcn into the runlist element. */ rl[rlpos].lcn = lcn; } /* Get to the next runlist element, skipping zero-sized holes */ if (rl[rlpos].length) rlpos++; /* Increment the buffer position to the next mapping pair. */ buf += (*buf & 0xf) + ((*buf >> 4) & 0xf) + 1; } if (buf >= attr_end) goto io_error; /* * If there is a highest_vcn specified, it must be equal to the final * vcn in the runlist - 1, or something has gone badly wrong. */ deltaxcn = sle64_to_cpu(attr->highest_vcn); if (deltaxcn && vcn - 1 != deltaxcn) { mpa_err: ntfs_log_debug("Corrupt mapping pairs array in non-resident " "attribute.\n"); goto err_out; } /* * If this is the base of runlist (if 'lowest_vcn' is 0), then * 'allocated_size' is valid, and we can use it to compute the total * number of clusters across all extents. If the runlist covers all * clusters, then it fits into a single extent and we can terminate * the runlist with LCN_NOENT. Otherwise, we must terminate the runlist * with LCN_RL_NOT_MAPPED and let the caller look for more extents. */ if (!attr->lowest_vcn) { VCN num_clusters; num_clusters = ((sle64_to_cpu(attr->allocated_size) + vol->cluster_size - 1) >> vol->cluster_size_bits); if (num_clusters > vcn) { /* * The runlist doesn't cover all the clusters, so there * must be more extents. */ ntfs_log_debug("More extents to follow; vcn = 0x%llx, " "num_clusters = 0x%llx\n", (long long)vcn, (long long)num_clusters); rl[rlpos].vcn = vcn; vcn += rl[rlpos].length = num_clusters - vcn; rl[rlpos].lcn = (LCN)LCN_RL_NOT_MAPPED; rlpos++; } else if (vcn > num_clusters) { /* * There are more VCNs in the runlist than expected, so * the runlist is corrupt. */ ntfs_log_error("Corrupt attribute. vcn = 0x%llx, " "num_clusters = 0x%llx\n", (long long)vcn, (long long)num_clusters); goto mpa_err; } rl[rlpos].lcn = (LCN)LCN_ENOENT; } else /* Not the base extent. There may be more extents to follow. */ rl[rlpos].lcn = (LCN)LCN_RL_NOT_MAPPED; /* Setup terminating runlist element. */ rl[rlpos].vcn = vcn; rl[rlpos].length = (s64)0; /* If no existing runlist was specified, we are done. */ if (!old_rl || !old_rl[0].length) { ntfs_log_debug("Mapping pairs array successfully decompressed:\n"); ntfs_debug_runlist_dump(rl); if (old_rl) free(old_rl); return rl; } /* Now combine the new and old runlists checking for overlaps. */ if (rl[0].length) old_rl = ntfs_runlists_merge(old_rl, rl); else free(rl); if (old_rl) return old_rl; err = errno; free(rl); ntfs_log_debug("Failed to merge runlists.\n"); errno = err; return NULL; io_error: ntfs_log_debug("Corrupt attribute.\n"); err_out: free(rl); errno = EIO; return NULL; } runlist_element *ntfs_mapping_pairs_decompress(const ntfs_volume *vol, const ATTR_RECORD *attr, runlist_element *old_rl) { runlist_element *rle; ntfs_log_enter("Entering\n"); rle = ntfs_mapping_pairs_decompress_i(vol, attr, old_rl); ntfs_log_leave("\n"); return rle; } /** * ntfs_rl_vcn_to_lcn - convert a vcn into a lcn given a runlist * @rl: runlist to use for conversion * @vcn: vcn to convert * * Convert the virtual cluster number @vcn of an attribute into a logical * cluster number (lcn) of a device using the runlist @rl to map vcns to their * corresponding lcns. * * Since lcns must be >= 0, we use negative return values with special meaning: * * Return value Meaning / Description * ================================================== * -1 = LCN_HOLE Hole / not allocated on disk. * -2 = LCN_RL_NOT_MAPPED This is part of the runlist which has not been * inserted into the runlist yet. * -3 = LCN_ENOENT There is no such vcn in the attribute. * -4 = LCN_EINVAL Input parameter error. */ LCN ntfs_rl_vcn_to_lcn(const runlist_element *rl, const VCN vcn) { int i; if (vcn < (VCN)0) return (LCN)LCN_EINVAL; /* * If rl is NULL, assume that we have found an unmapped runlist. The * caller can then attempt to map it and fail appropriately if * necessary. */ if (!rl) return (LCN)LCN_RL_NOT_MAPPED; /* Catch out of lower bounds vcn. */ if (vcn < rl[0].vcn) return (LCN)LCN_ENOENT; for (i = 0; rl[i].length; i++) { if (vcn < rl[i+1].vcn) { if (rl[i].lcn >= (LCN)0) return rl[i].lcn + (vcn - rl[i].vcn); return rl[i].lcn; } } /* * The terminator element is setup to the correct value, i.e. one of * LCN_HOLE, LCN_RL_NOT_MAPPED, or LCN_ENOENT. */ if (rl[i].lcn < (LCN)0) return rl[i].lcn; /* Just in case... We could replace this with BUG() some day. */ return (LCN)LCN_ENOENT; } /** * ntfs_rl_pread - gather read from disk * @vol: ntfs volume to read from * @rl: runlist specifying where to read the data from * @pos: byte position within runlist @rl at which to begin the read * @count: number of bytes to read * @b: data buffer into which to read from disk * * This function will read @count bytes from the volume @vol to the data buffer * @b gathering the data as specified by the runlist @rl. The read begins at * offset @pos into the runlist @rl. * * On success, return the number of successfully read bytes. If this number is * lower than @count this means that the read reached end of file or that an * error was encountered during the read so that the read is partial. 0 means * nothing was read (also return 0 when @count is 0). * * On error and nothing has been read, return -1 with errno set appropriately * to the return code of ntfs_pread(), or to EINVAL in case of invalid * arguments. * * NOTE: If we encounter EOF while reading we return EIO because we assume that * the run list must point to valid locations within the ntfs volume. */ s64 ntfs_rl_pread(const ntfs_volume *vol, const runlist_element *rl, const s64 pos, s64 count, void *b) { s64 bytes_read, to_read, ofs, total; int err = EIO; if (!vol || !rl || pos < 0 || count < 0) { errno = EINVAL; ntfs_log_perror("Failed to read runlist [vol: %p rl: %p " "pos: %lld count: %lld]", vol, rl, (long long)pos, (long long)count); return -1; } if (!count) return count; /* Seek in @rl to the run containing @pos. */ for (ofs = 0; rl->length && (ofs + (rl->length << vol->cluster_size_bits) <= pos); rl++) ofs += (rl->length << vol->cluster_size_bits); /* Offset in the run at which to begin reading. */ ofs = pos - ofs; for (total = 0LL; count; rl++, ofs = 0) { if (!rl->length) goto rl_err_out; if (rl->lcn < (LCN)0) { if (rl->lcn != (LCN)LCN_HOLE) goto rl_err_out; /* It is a hole. Just fill buffer @b with zeroes. */ to_read = min(count, (rl->length << vol->cluster_size_bits) - ofs); memset(b, 0, to_read); /* Update counters and proceed with next run. */ total += to_read; count -= to_read; b = (u8*)b + to_read; continue; } /* It is a real lcn, read it from the volume. */ to_read = min(count, (rl->length << vol->cluster_size_bits) - ofs); retry: bytes_read = ntfs_pread(vol->dev, (rl->lcn << vol->cluster_size_bits) + ofs, to_read, b); /* If everything ok, update progress counters and continue. */ if (bytes_read > 0) { total += bytes_read; count -= bytes_read; b = (u8*)b + bytes_read; continue; } /* If the syscall was interrupted, try again. */ if (bytes_read == (s64)-1 && errno == EINTR) goto retry; if (bytes_read == (s64)-1) err = errno; goto rl_err_out; } /* Finally, return the number of bytes read. */ return total; rl_err_out: if (total) return total; errno = err; return -1; } /** * ntfs_rl_pwrite - scatter write to disk * @vol: ntfs volume to write to * @rl: runlist entry specifying where to write the data to * @ofs: offset in file for runlist element indicated in @rl * @pos: byte position from runlist beginning at which to begin the write * @count: number of bytes to write * @b: data buffer to write to disk * * This function will write @count bytes from data buffer @b to the volume @vol * scattering the data as specified by the runlist @rl. The write begins at * offset @pos into the runlist @rl. If a run is sparse then the related buffer * data is ignored which means that the caller must ensure they are consistent. * * On success, return the number of successfully written bytes. If this number * is lower than @count this means that the write has been interrupted in * flight or that an error was encountered during the write so that the write * is partial. 0 means nothing was written (also return 0 when @count is 0). * * On error and nothing has been written, return -1 with errno set * appropriately to the return code of ntfs_pwrite(), or to to EINVAL in case * of invalid arguments. */ s64 ntfs_rl_pwrite(const ntfs_volume *vol, const runlist_element *rl, s64 ofs, const s64 pos, s64 count, void *b) { s64 written, to_write, total = 0; int err = EIO; if (!vol || !rl || pos < 0 || count < 0) { errno = EINVAL; ntfs_log_perror("Failed to write runlist [vol: %p rl: %p " "pos: %lld count: %lld]", vol, rl, (long long)pos, (long long)count); goto errno_set; } if (!count) goto out; /* Seek in @rl to the run containing @pos. */ while (rl->length && (ofs + (rl->length << vol->cluster_size_bits) <= pos)) { ofs += (rl->length << vol->cluster_size_bits); rl++; } /* Offset in the run at which to begin writing. */ ofs = pos - ofs; for (total = 0LL; count; rl++, ofs = 0) { if (!rl->length) goto rl_err_out; if (rl->lcn < (LCN)0) { if (rl->lcn != (LCN)LCN_HOLE) goto rl_err_out; to_write = min(count, (rl->length << vol->cluster_size_bits) - ofs); total += to_write; count -= to_write; b = (u8*)b + to_write; continue; } /* It is a real lcn, write it to the volume. */ to_write = min(count, (rl->length << vol->cluster_size_bits) - ofs); retry: if (!NVolReadOnly(vol)) written = ntfs_pwrite(vol->dev, (rl->lcn << vol->cluster_size_bits) + ofs, to_write, b); else written = to_write; /* If everything ok, update progress counters and continue. */ if (written > 0) { total += written; count -= written; b = (u8*)b + written; continue; } /* If the syscall was interrupted, try again. */ if (written == (s64)-1 && errno == EINTR) goto retry; if (written == (s64)-1) err = errno; goto rl_err_out; } out: return total; rl_err_out: if (total) goto out; errno = err; errno_set: total = -1; goto out; } /** * ntfs_get_nr_significant_bytes - get number of bytes needed to store a number * @n: number for which to get the number of bytes for * * Return the number of bytes required to store @n unambiguously as * a signed number. * * This is used in the context of the mapping pairs array to determine how * many bytes will be needed in the array to store a given logical cluster * number (lcn) or a specific run length. * * Return the number of bytes written. This function cannot fail. */ int ntfs_get_nr_significant_bytes(const s64 n) { u64 l; int i; l = (n < 0 ? ~n : n); i = 1; if (l >= 128) { l >>= 7; do { i++; l >>= 8; } while (l); } return i; } /** * ntfs_get_size_for_mapping_pairs - get bytes needed for mapping pairs array * @vol: ntfs volume (needed for the ntfs version) * @rl: runlist for which to determine the size of the mapping pairs * @start_vcn: vcn at which to start the mapping pairs array * * Walk the runlist @rl and calculate the size in bytes of the mapping pairs * array corresponding to the runlist @rl, starting at vcn @start_vcn. This * for example allows us to allocate a buffer of the right size when building * the mapping pairs array. * * If @rl is NULL, just return 1 (for the single terminator byte). * * Return the calculated size in bytes on success. On error, return -1 with * errno set to the error code. The following error codes are defined: * EINVAL - Run list contains unmapped elements. Make sure to only pass * fully mapped runlists to this function. * - @start_vcn is invalid. * EIO - The runlist is corrupt. */ int ntfs_get_size_for_mapping_pairs(const ntfs_volume *vol, const runlist_element *rl, const VCN start_vcn, int max_size) { LCN prev_lcn; int rls; if (start_vcn < 0) { ntfs_log_trace("start_vcn %lld (should be >= 0)\n", (long long) start_vcn); errno = EINVAL; goto errno_set; } if (!rl) { if (start_vcn) { ntfs_log_trace("rl NULL, start_vcn %lld (should be > 0)\n", (long long) start_vcn); errno = EINVAL; goto errno_set; } rls = 1; goto out; } /* Skip to runlist element containing @start_vcn. */ while (rl->length && start_vcn >= rl[1].vcn) rl++; if ((!rl->length && start_vcn > rl->vcn) || start_vcn < rl->vcn) { errno = EINVAL; goto errno_set; } prev_lcn = 0; /* Always need the terminating zero byte. */ rls = 1; /* Do the first partial run if present. */ if (start_vcn > rl->vcn) { s64 delta; /* We know rl->length != 0 already. */ if (rl->length < 0 || rl->lcn < LCN_HOLE) goto err_out; delta = start_vcn - rl->vcn; /* Header byte + length. */ rls += 1 + ntfs_get_nr_significant_bytes(rl->length - delta); /* * If the logical cluster number (lcn) denotes a hole and we * are on NTFS 3.0+, we don't store it at all, i.e. we need * zero space. On earlier NTFS versions we just store the lcn. * Note: this assumes that on NTFS 1.2-, holes are stored with * an lcn of -1 and not a delta_lcn of -1 (unless both are -1). */ if (rl->lcn >= 0 || vol->major_ver < 3) { prev_lcn = rl->lcn; if (rl->lcn >= 0) prev_lcn += delta; /* Change in lcn. */ rls += ntfs_get_nr_significant_bytes(prev_lcn); } /* Go to next runlist element. */ rl++; } /* Do the full runs. */ for (; rl->length && (rls <= max_size); rl++) { if (rl->length < 0 || rl->lcn < LCN_HOLE) goto err_out; /* Header byte + length. */ rls += 1 + ntfs_get_nr_significant_bytes(rl->length); /* * If the logical cluster number (lcn) denotes a hole and we * are on NTFS 3.0+, we don't store it at all, i.e. we need * zero space. On earlier NTFS versions we just store the lcn. * Note: this assumes that on NTFS 1.2-, holes are stored with * an lcn of -1 and not a delta_lcn of -1 (unless both are -1). */ if (rl->lcn >= 0 || vol->major_ver < 3) { /* Change in lcn. */ rls += ntfs_get_nr_significant_bytes(rl->lcn - prev_lcn); prev_lcn = rl->lcn; } } out: return rls; err_out: if (rl->lcn == LCN_RL_NOT_MAPPED) errno = EINVAL; else errno = EIO; errno_set: rls = -1; goto out; } /** * ntfs_write_significant_bytes - write the significant bytes of a number * @dst: destination buffer to write to * @dst_max: pointer to last byte of destination buffer for bounds checking * @n: number whose significant bytes to write * * Store in @dst, the minimum bytes of the number @n which are required to * identify @n unambiguously as a signed number, taking care not to exceed * @dest_max, the maximum position within @dst to which we are allowed to * write. * * This is used when building the mapping pairs array of a runlist to compress * a given logical cluster number (lcn) or a specific run length to the minimum * size possible. * * Return the number of bytes written on success. On error, i.e. the * destination buffer @dst is too small, return -1 with errno set ENOSPC. */ int ntfs_write_significant_bytes(u8 *dst, const u8 *dst_max, const s64 n) { s64 l = n; int i; i = 0; if (dst > dst_max) goto err_out; *dst++ = l; i++; while ((l > 0x7f) || (l < -0x80)) { if (dst > dst_max) goto err_out; l >>= 8; *dst++ = l; i++; } return i; err_out: errno = ENOSPC; return -1; } /** * ntfs_mapping_pairs_build - build the mapping pairs array from a runlist * @vol: ntfs volume (needed for the ntfs version) * @dst: destination buffer to which to write the mapping pairs array * @dst_len: size of destination buffer @dst in bytes * @rl: runlist for which to build the mapping pairs array * @start_vcn: vcn at which to start the mapping pairs array * @stop_vcn: first vcn outside destination buffer on success or ENOSPC error * * Create the mapping pairs array from the runlist @rl, starting at vcn * @start_vcn and save the array in @dst. @dst_len is the size of @dst in * bytes and it should be at least equal to the value obtained by calling * ntfs_get_size_for_mapping_pairs(). * * If @rl is NULL, just write a single terminator byte to @dst. * * On success or ENOSPC error, if @stop_vcn is not NULL, *@stop_vcn is set to * the first vcn outside the destination buffer. Note that on error @dst has * been filled with all the mapping pairs that will fit, thus it can be treated * as partial success, in that a new attribute extent needs to be created or the * next extent has to be used and the mapping pairs build has to be continued * with @start_vcn set to *@stop_vcn. * * Return 0 on success. On error, return -1 with errno set to the error code. * The following error codes are defined: * EINVAL - Run list contains unmapped elements. Make sure to only pass * fully mapped runlists to this function. * - @start_vcn is invalid. * EIO - The runlist is corrupt. * ENOSPC - The destination buffer is too small. */ int ntfs_mapping_pairs_build(const ntfs_volume *vol, u8 *dst, const int dst_len, const runlist_element *rl, const VCN start_vcn, runlist_element const **stop_rl) { LCN prev_lcn; u8 *dst_max, *dst_next; s8 len_len, lcn_len; int ret = 0; if (start_vcn < 0) goto val_err; if (!rl) { if (start_vcn) goto val_err; if (stop_rl) *stop_rl = rl; if (dst_len < 1) goto nospc_err; goto ok; } /* Skip to runlist element containing @start_vcn. */ while (rl->length && start_vcn >= rl[1].vcn) rl++; if ((!rl->length && start_vcn > rl->vcn) || start_vcn < rl->vcn) goto val_err; /* * @dst_max is used for bounds checking in * ntfs_write_significant_bytes(). */ dst_max = dst + dst_len - 1; prev_lcn = 0; /* Do the first partial run if present. */ if (start_vcn > rl->vcn) { s64 delta; /* We know rl->length != 0 already. */ if (rl->length < 0 || rl->lcn < LCN_HOLE) goto err_out; delta = start_vcn - rl->vcn; /* Write length. */ len_len = ntfs_write_significant_bytes(dst + 1, dst_max, rl->length - delta); if (len_len < 0) goto size_err; /* * If the logical cluster number (lcn) denotes a hole and we * are on NTFS 3.0+, we don't store it at all, i.e. we need * zero space. On earlier NTFS versions we just write the lcn * change. FIXME: Do we need to write the lcn change or just * the lcn in that case? Not sure as I have never seen this * case on NT4. - We assume that we just need to write the lcn * change until someone tells us otherwise... (AIA) */ if (rl->lcn >= 0 || vol->major_ver < 3) { prev_lcn = rl->lcn; if (rl->lcn >= 0) prev_lcn += delta; /* Write change in lcn. */ lcn_len = ntfs_write_significant_bytes(dst + 1 + len_len, dst_max, prev_lcn); if (lcn_len < 0) goto size_err; } else lcn_len = 0; dst_next = dst + len_len + lcn_len + 1; if (dst_next > dst_max) goto size_err; /* Update header byte. */ *dst = lcn_len << 4 | len_len; /* Position at next mapping pairs array element. */ dst = dst_next; /* Go to next runlist element. */ rl++; } /* Do the full runs. */ for (; rl->length; rl++) { if (rl->length < 0 || rl->lcn < LCN_HOLE) goto err_out; /* Write length. */ len_len = ntfs_write_significant_bytes(dst + 1, dst_max, rl->length); if (len_len < 0) goto size_err; /* * If the logical cluster number (lcn) denotes a hole and we * are on NTFS 3.0+, we don't store it at all, i.e. we need * zero space. On earlier NTFS versions we just write the lcn * change. FIXME: Do we need to write the lcn change or just * the lcn in that case? Not sure as I have never seen this * case on NT4. - We assume that we just need to write the lcn * change until someone tells us otherwise... (AIA) */ if (rl->lcn >= 0 || vol->major_ver < 3) { /* Write change in lcn. */ lcn_len = ntfs_write_significant_bytes(dst + 1 + len_len, dst_max, rl->lcn - prev_lcn); if (lcn_len < 0) goto size_err; prev_lcn = rl->lcn; } else lcn_len = 0; dst_next = dst + len_len + lcn_len + 1; if (dst_next > dst_max) goto size_err; /* Update header byte. */ *dst = lcn_len << 4 | len_len; /* Position at next mapping pairs array element. */ dst += 1 + len_len + lcn_len; } /* Set stop vcn. */ if (stop_rl) *stop_rl = rl; ok: /* Add terminator byte. */ *dst = 0; out: return ret; size_err: /* Set stop vcn. */ if (stop_rl) *stop_rl = rl; /* Add terminator byte. */ *dst = 0; nospc_err: errno = ENOSPC; goto errno_set; val_err: errno = EINVAL; goto errno_set; err_out: if (rl->lcn == LCN_RL_NOT_MAPPED) errno = EINVAL; else errno = EIO; errno_set: ret = -1; goto out; } /** * ntfs_rl_truncate - truncate a runlist starting at a specified vcn * @arl: address of runlist to truncate * @start_vcn: first vcn which should be cut off * * Truncate the runlist *@arl starting at vcn @start_vcn as well as the memory * buffer holding the runlist. * * Return 0 on success and -1 on error with errno set to the error code. * * NOTE: @arl is the address of the runlist. We need the address so we can * modify the pointer to the runlist with the new, reallocated memory buffer. */ int ntfs_rl_truncate(runlist **arl, const VCN start_vcn) { runlist *rl; /* BOOL is_end = FALSE; */ if (!arl || !*arl) { errno = EINVAL; if (!arl) ntfs_log_perror("rl_truncate error: arl: %p", arl); else ntfs_log_perror("rl_truncate error:" " arl: %p *arl: %p", arl, *arl); return -1; } rl = *arl; if (start_vcn < rl->vcn) { errno = EINVAL; ntfs_log_perror("Start_vcn lies outside front of runlist"); return -1; } /* Find the starting vcn in the run list. */ while (rl->length) { if (start_vcn < rl[1].vcn) break; rl++; } if (!rl->length) { errno = EIO; ntfs_log_trace("Truncating already truncated runlist?\n"); return -1; } /* Truncate the run. */ rl->length = start_vcn - rl->vcn; /* * If a run was partially truncated, make the following runlist * element a terminator instead of the truncated runlist * element itself. */ if (rl->length) { ++rl; /* if (!rl->length) is_end = TRUE; */ rl->vcn = start_vcn; rl->length = 0; } rl->lcn = (LCN)LCN_ENOENT; /** * Reallocate memory if necessary. * FIXME: Below code is broken, because runlist allocations must be * a multiple of 4096. The code caused crashes and corruptions. */ /* if (!is_end) { size_t new_size = (rl - *arl + 1) * sizeof(runlist_element); rl = realloc(*arl, new_size); if (rl) *arl = rl; } */ return 0; } /** * ntfs_rl_sparse - check whether runlist have sparse regions or not. * @rl: runlist to check * * Return 1 if have, 0 if not, -1 on error with errno set to the error code. */ int ntfs_rl_sparse(runlist *rl) { runlist *rlc; if (!rl) { errno = EINVAL; ntfs_log_perror("%s: ", __FUNCTION__); return -1; } for (rlc = rl; rlc->length; rlc++) if (rlc->lcn < 0) { if (rlc->lcn != LCN_HOLE) { errno = EINVAL; ntfs_log_perror("%s: bad runlist", __FUNCTION__); return -1; } return 1; } return 0; } /** * ntfs_rl_get_compressed_size - calculate length of non sparse regions * @vol: ntfs volume (need for cluster size) * @rl: runlist to calculate for * * Return compressed size or -1 on error with errno set to the error code. */ s64 ntfs_rl_get_compressed_size(ntfs_volume *vol, runlist *rl) { runlist *rlc; s64 ret = 0; if (!rl) { errno = EINVAL; ntfs_log_perror("%s: ", __FUNCTION__); return -1; } for (rlc = rl; rlc->length; rlc++) { if (rlc->lcn < 0) { if (rlc->lcn != LCN_HOLE) { errno = EINVAL; ntfs_log_perror("%s: bad runlist", __FUNCTION__); return -1; } } else ret += rlc->length; } return ret << vol->cluster_size_bits; } #ifdef NTFS_TEST /** * test_rl_helper */ #define MKRL(R,V,L,S) \ (R)->vcn = V; \ (R)->lcn = L; \ (R)->length = S; /* } */ /** * test_rl_dump_runlist - Runlist test: Display the contents of a runlist * @rl: * * Description... * * Returns: */ static void test_rl_dump_runlist(const runlist_element *rl) { int abbr = 0; /* abbreviate long lists */ int len = 0; int i; const char *lcn_str[5] = { "HOLE", "NOTMAP", "ENOENT", "XXXX" }; if (!rl) { printf(" Run list not present.\n"); return; } if (abbr) for (len = 0; rl[len].length; len++) ; printf(" VCN LCN len\n"); for (i = 0; ; i++, rl++) { LCN lcn = rl->lcn; if ((abbr) && (len > 20)) { if (i == 4) printf(" ...\n"); if ((i > 3) && (i < (len - 3))) continue; } if (lcn < (LCN)0) { int ind = -lcn - 1; if (ind > -LCN_ENOENT - 1) ind = 3; printf("%8lld %8s %8lld\n", rl->vcn, lcn_str[ind], rl->length); } else printf("%8lld %8lld %8lld\n", rl->vcn, rl->lcn, rl->length); if (!rl->length) break; } if ((abbr) && (len > 20)) printf(" (%d entries)\n", len+1); printf("\n"); } /** * test_rl_runlists_merge - Runlist test: Merge two runlists * @drl: * @srl: * * Description... * * Returns: */ static runlist_element * test_rl_runlists_merge(runlist_element *drl, runlist_element *srl) { runlist_element *res = NULL; printf("dst:\n"); test_rl_dump_runlist(drl); printf("src:\n"); test_rl_dump_runlist(srl); res = ntfs_runlists_merge(drl, srl); printf("res:\n"); test_rl_dump_runlist(res); return res; } /** * test_rl_read_buffer - Runlist test: Read a file containing a runlist * @file: * @buf: * @bufsize: * * Description... * * Returns: */ static int test_rl_read_buffer(const char *file, u8 *buf, int bufsize) { FILE *fptr; fptr = fopen(file, "r"); if (!fptr) { printf("open %s\n", file); return 0; } if (fread(buf, bufsize, 1, fptr) == 99) { printf("read %s\n", file); return 0; } fclose(fptr); return 1; } /** * test_rl_pure_src - Runlist test: Complicate the simple tests a little * @contig: * @multi: * @vcn: * @len: * * Description... * * Returns: */ static runlist_element * test_rl_pure_src(BOOL contig, BOOL multi, int vcn, int len) { runlist_element *result; int fudge; if (contig) fudge = 0; else fudge = 999; result = ntfs_malloc(4096); if (!result) return NULL; if (multi) { MKRL(result+0, vcn + (0*len/4), fudge + vcn + 1000 + (0*len/4), len / 4) MKRL(result+1, vcn + (1*len/4), fudge + vcn + 1000 + (1*len/4), len / 4) MKRL(result+2, vcn + (2*len/4), fudge + vcn + 1000 + (2*len/4), len / 4) MKRL(result+3, vcn + (3*len/4), fudge + vcn + 1000 + (3*len/4), len / 4) MKRL(result+4, vcn + (4*len/4), LCN_RL_NOT_MAPPED, 0) } else { MKRL(result+0, vcn, fudge + vcn + 1000, len) MKRL(result+1, vcn + len, LCN_RL_NOT_MAPPED, 0) } return result; } /** * test_rl_pure_test - Runlist test: Perform tests using simple runlists * @test: * @contig: * @multi: * @vcn: * @len: * @file: * @size: * * Description... * * Returns: */ static void test_rl_pure_test(int test, BOOL contig, BOOL multi, int vcn, int len, runlist_element *file, int size) { runlist_element *src; runlist_element *dst; runlist_element *res; src = test_rl_pure_src(contig, multi, vcn, len); dst = ntfs_malloc(4096); if (!src || !dst) { printf("Test %2d ---------- FAILED! (no free memory?)\n", test); return; } memcpy(dst, file, size); printf("Test %2d ----------\n", test); res = test_rl_runlists_merge(dst, src); free(res); } /** * test_rl_pure - Runlist test: Create tests using simple runlists * @contig: * @multi: * * Description... * * Returns: */ static void test_rl_pure(char *contig, char *multi) { /* VCN, LCN, len */ static runlist_element file1[] = { { 0, -1, 100 }, /* HOLE */ { 100, 1100, 100 }, /* DATA */ { 200, -1, 100 }, /* HOLE */ { 300, 1300, 100 }, /* DATA */ { 400, -1, 100 }, /* HOLE */ { 500, -3, 0 } /* NOENT */ }; static runlist_element file2[] = { { 0, 1000, 100 }, /* DATA */ { 100, -1, 100 }, /* HOLE */ { 200, -3, 0 } /* NOENT */ }; static runlist_element file3[] = { { 0, 1000, 100 }, /* DATA */ { 100, -3, 0 } /* NOENT */ }; static runlist_element file4[] = { { 0, -3, 0 } /* NOENT */ }; static runlist_element file5[] = { { 0, -2, 100 }, /* NOTMAP */ { 100, 1100, 100 }, /* DATA */ { 200, -2, 100 }, /* NOTMAP */ { 300, 1300, 100 }, /* DATA */ { 400, -2, 100 }, /* NOTMAP */ { 500, -3, 0 } /* NOENT */ }; static runlist_element file6[] = { { 0, 1000, 100 }, /* DATA */ { 100, -2, 100 }, /* NOTMAP */ { 200, -3, 0 } /* NOENT */ }; BOOL c, m; if (strcmp(contig, "contig") == 0) c = TRUE; else if (strcmp(contig, "noncontig") == 0) c = FALSE; else { printf("rl pure [contig|noncontig] [single|multi]\n"); return; } if (strcmp(multi, "multi") == 0) m = TRUE; else if (strcmp(multi, "single") == 0) m = FALSE; else { printf("rl pure [contig|noncontig] [single|multi]\n"); return; } test_rl_pure_test(1, c, m, 0, 40, file1, sizeof(file1)); test_rl_pure_test(2, c, m, 40, 40, file1, sizeof(file1)); test_rl_pure_test(3, c, m, 60, 40, file1, sizeof(file1)); test_rl_pure_test(4, c, m, 0, 100, file1, sizeof(file1)); test_rl_pure_test(5, c, m, 200, 40, file1, sizeof(file1)); test_rl_pure_test(6, c, m, 240, 40, file1, sizeof(file1)); test_rl_pure_test(7, c, m, 260, 40, file1, sizeof(file1)); test_rl_pure_test(8, c, m, 200, 100, file1, sizeof(file1)); test_rl_pure_test(9, c, m, 400, 40, file1, sizeof(file1)); test_rl_pure_test(10, c, m, 440, 40, file1, sizeof(file1)); test_rl_pure_test(11, c, m, 460, 40, file1, sizeof(file1)); test_rl_pure_test(12, c, m, 400, 100, file1, sizeof(file1)); test_rl_pure_test(13, c, m, 160, 100, file2, sizeof(file2)); test_rl_pure_test(14, c, m, 100, 140, file2, sizeof(file2)); test_rl_pure_test(15, c, m, 200, 40, file2, sizeof(file2)); test_rl_pure_test(16, c, m, 240, 40, file2, sizeof(file2)); test_rl_pure_test(17, c, m, 100, 40, file3, sizeof(file3)); test_rl_pure_test(18, c, m, 140, 40, file3, sizeof(file3)); test_rl_pure_test(19, c, m, 0, 40, file4, sizeof(file4)); test_rl_pure_test(20, c, m, 40, 40, file4, sizeof(file4)); test_rl_pure_test(21, c, m, 0, 40, file5, sizeof(file5)); test_rl_pure_test(22, c, m, 40, 40, file5, sizeof(file5)); test_rl_pure_test(23, c, m, 60, 40, file5, sizeof(file5)); test_rl_pure_test(24, c, m, 0, 100, file5, sizeof(file5)); test_rl_pure_test(25, c, m, 200, 40, file5, sizeof(file5)); test_rl_pure_test(26, c, m, 240, 40, file5, sizeof(file5)); test_rl_pure_test(27, c, m, 260, 40, file5, sizeof(file5)); test_rl_pure_test(28, c, m, 200, 100, file5, sizeof(file5)); test_rl_pure_test(29, c, m, 400, 40, file5, sizeof(file5)); test_rl_pure_test(30, c, m, 440, 40, file5, sizeof(file5)); test_rl_pure_test(31, c, m, 460, 40, file5, sizeof(file5)); test_rl_pure_test(32, c, m, 400, 100, file5, sizeof(file5)); test_rl_pure_test(33, c, m, 160, 100, file6, sizeof(file6)); test_rl_pure_test(34, c, m, 100, 140, file6, sizeof(file6)); } /** * test_rl_zero - Runlist test: Merge a zero-length runlist * * Description... * * Returns: */ static void test_rl_zero(void) { runlist_element *jim = NULL; runlist_element *bob = NULL; bob = calloc(3, sizeof(runlist_element)); if (!bob) return; MKRL(bob+0, 10, 99, 5) MKRL(bob+1, 15, LCN_RL_NOT_MAPPED, 0) jim = test_rl_runlists_merge(jim, bob); if (!jim) return; free(jim); } /** * test_rl_frag_combine - Runlist test: Perform tests using fragmented files * @vol: * @attr1: * @attr2: * @attr3: * * Description... * * Returns: */ static void test_rl_frag_combine(ntfs_volume *vol, ATTR_RECORD *attr1, ATTR_RECORD *attr2, ATTR_RECORD *attr3) { runlist_element *run1; runlist_element *run2; runlist_element *run3; run1 = ntfs_mapping_pairs_decompress(vol, attr1, NULL); if (!run1) return; run2 = ntfs_mapping_pairs_decompress(vol, attr2, NULL); if (!run2) return; run1 = test_rl_runlists_merge(run1, run2); run3 = ntfs_mapping_pairs_decompress(vol, attr3, NULL); if (!run3) return; run1 = test_rl_runlists_merge(run1, run3); free(run1); } /** * test_rl_frag - Runlist test: Create tests using very fragmented files * @test: * * Description... * * Returns: */ static void test_rl_frag(char *test) { ntfs_volume vol; ATTR_RECORD *attr1 = ntfs_malloc(1024); ATTR_RECORD *attr2 = ntfs_malloc(1024); ATTR_RECORD *attr3 = ntfs_malloc(1024); if (!attr1 || !attr2 || !attr3) goto out; vol.sb = NULL; vol.sector_size_bits = 9; vol.cluster_size = 2048; vol.cluster_size_bits = 11; vol.major_ver = 3; if (!test_rl_read_buffer("runlist-data/attr1.bin", (u8*) attr1, 1024)) goto out; if (!test_rl_read_buffer("runlist-data/attr2.bin", (u8*) attr2, 1024)) goto out; if (!test_rl_read_buffer("runlist-data/attr3.bin", (u8*) attr3, 1024)) goto out; if (strcmp(test, "123") == 0) test_rl_frag_combine(&vol, attr1, attr2, attr3); else if (strcmp(test, "132") == 0) test_rl_frag_combine(&vol, attr1, attr3, attr2); else if (strcmp(test, "213") == 0) test_rl_frag_combine(&vol, attr2, attr1, attr3); else if (strcmp(test, "231") == 0) test_rl_frag_combine(&vol, attr2, attr3, attr1); else if (strcmp(test, "312") == 0) test_rl_frag_combine(&vol, attr3, attr1, attr2); else if (strcmp(test, "321") == 0) test_rl_frag_combine(&vol, attr3, attr2, attr1); else printf("Frag: No such test '%s'\n", test); out: free(attr1); free(attr2); free(attr3); } /** * test_rl_main - Runlist test: Program start (main) * @argc: * @argv: * * Description... * * Returns: */ int test_rl_main(int argc, char *argv[]) { if ((argc == 2) && (strcmp(argv[1], "zero") == 0)) test_rl_zero(); else if ((argc == 3) && (strcmp(argv[1], "frag") == 0)) test_rl_frag(argv[2]); else if ((argc == 4) && (strcmp(argv[1], "pure") == 0)) test_rl_pure(argv[2], argv[3]); else printf("rl [zero|frag|pure] {args}\n"); return 0; } #endif ntfs-3g-2026.2.25/libntfs-3g/acls.c0000664000175000017500000035140215152260173012043 /** * acls.c - General function to process NTFS ACLs * * This module is part of ntfs-3g library, but may also be * integrated in tools running over Linux or Windows * * Copyright (c) 2007-2017 Jean-Pierre Andre * * This program/include file 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/include file 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 */ #include "config.h" #ifdef HAVE_STDIO_H #include #endif #ifdef HAVE_STDLIB_H #include #endif #ifdef HAVE_STRING_H #include #endif #ifdef HAVE_ERRNO_H #include #endif #ifdef HAVE_SYS_STAT_H #include #endif #ifdef HAVE_FCNTL_H #include #endif #ifdef HAVE_SYSLOG_H #include #endif #include #include #include #include "types.h" #include "layout.h" #include "security.h" #include "acls.h" #include "misc.h" /* * A few useful constants */ /* * null SID (S-1-0-0) */ static const char nullsidbytes[] = { 1, /* revision */ 1, /* auth count */ 0, 0, 0, 0, 0, 0, /* base */ 0, 0, 0, 0 /* 1st level */ }; static const SID *nullsid = (const SID*)nullsidbytes; /* * SID for world (S-1-1-0) */ static const char worldsidbytes[] = { 1, /* revision */ 1, /* auth count */ 0, 0, 0, 0, 0, 1, /* base */ 0, 0, 0, 0 /* 1st level */ } ; const SID *worldsid = (const SID*)worldsidbytes; /* * SID for authenticated user (S-1-5-11) */ static const char authsidbytes[] = { 1, /* revision */ 1, /* auth count */ 0, 0, 0, 0, 0, 5, /* base */ 11, 0, 0, 0 /* 1st level */ }; static const SID *authsid = (const SID*)authsidbytes; /* * SID for administrator */ static const char adminsidbytes[] = { 1, /* revision */ 2, /* auth count */ 0, 0, 0, 0, 0, 5, /* base */ 32, 0, 0, 0, /* 1st level */ 32, 2, 0, 0 /* 2nd level */ }; const SID *adminsid = (const SID*)adminsidbytes; /* * SID for system */ static const char systemsidbytes[] = { 1, /* revision */ 1, /* auth count */ 0, 0, 0, 0, 0, 5, /* base */ 18, 0, 0, 0 /* 1st level */ }; static const SID *systemsid = (const SID*)systemsidbytes; /* * SID for generic creator-owner * S-1-3-0 */ static const char ownersidbytes[] = { 1, /* revision */ 1, /* auth count */ 0, 0, 0, 0, 0, 3, /* base */ 0, 0, 0, 0 /* 1st level */ } ; static const SID *ownersid = (const SID*)ownersidbytes; /* * SID for generic creator-group * S-1-3-1 */ static const char groupsidbytes[] = { 1, /* revision */ 1, /* auth count */ 0, 0, 0, 0, 0, 3, /* base */ 1, 0, 0, 0 /* 1st level */ } ; static const SID *groupsid = (const SID*)groupsidbytes; /* * Determine the size of a SID */ int ntfs_sid_size(const SID * sid) { return (sid->sub_authority_count * 4 + 8); } /* * Test whether two SID are equal */ BOOL ntfs_same_sid(const SID *first, const SID *second) { int size; size = ntfs_sid_size(first); return ((ntfs_sid_size(second) == size) && !memcmp(first, second, size)); } /* * Test whether a SID means "world user" * Local users group recognized as world * Also interactive users so that /Users/Public is world accessible, * but only if Posix ACLs are not enabled (if Posix ACLs are enabled, * access to /Users/Public should be done by defining interactive users * as a mapped group.) */ static int is_world_sid(const SID * usid) { return ( /* check whether S-1-1-0 : world */ ((usid->sub_authority_count == 1) && (usid->identifier_authority.high_part == const_cpu_to_be16(0)) && (usid->identifier_authority.low_part == const_cpu_to_be32(1)) && (usid->sub_authority[0] == const_cpu_to_le32(0))) /* check whether S-1-5-32-545 : local user */ || ((usid->sub_authority_count == 2) && (usid->identifier_authority.high_part == const_cpu_to_be16(0)) && (usid->identifier_authority.low_part == const_cpu_to_be32(5)) && (usid->sub_authority[0] == const_cpu_to_le32(32)) && (usid->sub_authority[1] == const_cpu_to_le32(545))) /* check whether S-1-5-11 : authenticated user */ || ((usid->sub_authority_count == 1) && (usid->identifier_authority.high_part == const_cpu_to_be16(0)) && (usid->identifier_authority.low_part == const_cpu_to_be32(5)) && (usid->sub_authority[0] == const_cpu_to_le32(11))) #if !POSIXACLS /* check whether S-1-5-4 : interactive user */ || ((usid->sub_authority_count == 1) && (usid->identifier_authority.high_part == const_cpu_to_be16(0)) && (usid->identifier_authority.low_part == const_cpu_to_be32(5)) && (usid->sub_authority[0] == const_cpu_to_le32(4))) #endif /* !POSIXACLS */ ); } /* * Test whether a SID means "some user (or group)" * Currently we only check for S-1-5-21... but we should * probably test for other configurations */ BOOL ntfs_is_user_sid(const SID *usid) { return ((usid->sub_authority_count == 5) && (usid->identifier_authority.high_part == const_cpu_to_be16(0)) && (usid->identifier_authority.low_part == const_cpu_to_be32(5)) && (usid->sub_authority[0] == const_cpu_to_le32(21))); } /* * Test whether a SID means "some special group" * Currently we only check for a few S-1-5-n but we should * probably test for other configurations. * * This is useful for granting access to /Users/Public for * specific users when the Posix ACLs are enabled. */ static BOOL ntfs_known_group_sid(const SID *usid) { /* count == 1 excludes S-1-5-5-X-Y (logon) */ return ((usid->sub_authority_count == 1) && (usid->identifier_authority.high_part == const_cpu_to_be16(0)) && (usid->identifier_authority.low_part == const_cpu_to_be32(5)) && (le32_to_cpu(usid->sub_authority[0]) >= 1) && (le32_to_cpu(usid->sub_authority[0]) <= 6)); } /* * Determine the size of a security attribute * whatever the order of fields */ unsigned int ntfs_attr_size(const char *attr) { const SECURITY_DESCRIPTOR_RELATIVE *phead; const ACL *pdacl; const ACL *psacl; const SID *psid; unsigned int offdacl; unsigned int offsacl; unsigned int offowner; unsigned int offgroup; unsigned int endsid; unsigned int endacl; unsigned int attrsz; phead = (const SECURITY_DESCRIPTOR_RELATIVE*)attr; /* * First check group, which is the last field in all descriptors * we build, and in most descriptors built by Windows */ attrsz = sizeof(SECURITY_DESCRIPTOR_RELATIVE); offgroup = le32_to_cpu(phead->group); if (offgroup >= attrsz) { /* find end of GSID */ psid = (const SID*)&attr[offgroup]; endsid = offgroup + ntfs_sid_size(psid); if (endsid > attrsz) attrsz = endsid; } offowner = le32_to_cpu(phead->owner); if (offowner >= attrsz) { /* find end of USID */ psid = (const SID*)&attr[offowner]; endsid = offowner + ntfs_sid_size(psid); attrsz = endsid; } offsacl = le32_to_cpu(phead->sacl); if (offsacl >= attrsz) { /* find end of SACL */ psacl = (const ACL*)&attr[offsacl]; endacl = offsacl + le16_to_cpu(psacl->size); if (endacl > attrsz) attrsz = endacl; } /* find end of DACL */ offdacl = le32_to_cpu(phead->dacl); if (offdacl >= attrsz) { pdacl = (const ACL*)&attr[offdacl]; endacl = offdacl + le16_to_cpu(pdacl->size); if (endacl > attrsz) attrsz = endacl; } return (attrsz); } /** * ntfs_valid_sid - determine if a SID is valid * @sid: SID for which to determine if it is valid * * Determine if the SID pointed to by @sid is valid. * * Return TRUE if it is valid and FALSE otherwise. */ BOOL ntfs_valid_sid(const SID *sid) { return sid && sid->revision == SID_REVISION && sid->sub_authority_count <= SID_MAX_SUB_AUTHORITIES; } /* * Check whether a SID is acceptable for an implicit * mapping pattern. * It should have been already checked it is a valid user SID. * * The last authority reference has to be >= 1000 (Windows usage) * and <= 0x7fffffff, so that 30 bits from a uid and 30 more bits * from a gid an be inserted with no overflow. */ BOOL ntfs_valid_pattern(const SID *sid) { int cnt; u32 auth; le32 leauth; cnt = sid->sub_authority_count; leauth = sid->sub_authority[cnt-1]; auth = le32_to_cpu(leauth); return ((auth >= 1000) && (auth <= 0x7fffffff)); } /* * Compute the uid or gid associated to a SID * through an implicit mapping * * Returns 0 (root) if it does not match pattern */ static u32 findimplicit(const SID *xsid, const SID *pattern, int parity) { BIGSID defsid; SID *psid; u32 xid; /* uid or gid */ int cnt; u32 carry; le32 leauth; u32 uauth; u32 xlast; u32 rlast; memcpy(&defsid,pattern,ntfs_sid_size(pattern)); psid = (SID*)&defsid; cnt = psid->sub_authority_count; xid = 0; if (xsid->sub_authority_count == cnt) { psid->sub_authority[cnt-1] = xsid->sub_authority[cnt-1]; leauth = xsid->sub_authority[cnt-1]; xlast = le32_to_cpu(leauth); leauth = pattern->sub_authority[cnt-1]; rlast = le32_to_cpu(leauth); if ((xlast > rlast) && !((xlast ^ rlast ^ parity) & 1)) { /* direct check for basic situation */ if (ntfs_same_sid(psid,xsid)) xid = ((xlast - rlast) >> 1) & 0x3fffffff; else { /* * check whether part of mapping had to be * recorded in a higher level authority */ carry = 1; do { leauth = psid->sub_authority[cnt-2]; uauth = le32_to_cpu(leauth) + 1; psid->sub_authority[cnt-2] = cpu_to_le32(uauth); } while (!ntfs_same_sid(psid,xsid) && (++carry < 4)); if (carry < 4) xid = (((xlast - rlast) >> 1) & 0x3fffffff) | (carry << 30); } } } return (xid); } /* * Find usid mapped to a Linux user * Returns NULL if not found */ const SID *ntfs_find_usid(const struct MAPPING* usermapping, uid_t uid, SID *defusid) { const struct MAPPING *p; const SID *sid; le32 leauth; u32 uauth; int cnt; if (!uid) sid = adminsid; else { p = usermapping; while (p && p->xid && ((uid_t)p->xid != uid)) p = p->next; if (p && !p->xid) { /* * default pattern has been reached : * build an implicit SID according to pattern * (the pattern format was checked while reading * the mapping file) */ memcpy(defusid, p->sid, ntfs_sid_size(p->sid)); cnt = defusid->sub_authority_count; leauth = defusid->sub_authority[cnt-1]; uauth = le32_to_cpu(leauth) + 2*(uid & 0x3fffffff); defusid->sub_authority[cnt-1] = cpu_to_le32(uauth); if (uid & 0xc0000000) { leauth = defusid->sub_authority[cnt-2]; uauth = le32_to_cpu(leauth) + ((uid >> 30) & 3); defusid->sub_authority[cnt-2] = cpu_to_le32(uauth); } sid = defusid; } else sid = (p ? p->sid : (const SID*)NULL); } return (sid); } /* * Find Linux group mapped to a gsid * Returns 0 (root) if not found */ const SID *ntfs_find_gsid(const struct MAPPING* groupmapping, gid_t gid, SID *defgsid) { const struct MAPPING *p; const SID *sid; le32 leauth; u32 uauth; int cnt; if (!gid) sid = adminsid; else { p = groupmapping; while (p && p->xid && ((gid_t)p->xid != gid)) p = p->next; if (p && !p->xid) { /* * default pattern has been reached : * build an implicit SID according to pattern * (the pattern format was checked while reading * the mapping file) */ memcpy(defgsid, p->sid, ntfs_sid_size(p->sid)); cnt = defgsid->sub_authority_count; leauth = defgsid->sub_authority[cnt-1]; uauth = le32_to_cpu(leauth) + 2*(gid & 0x3fffffff) + 1; defgsid->sub_authority[cnt-1] = cpu_to_le32(uauth); if (gid & 0xc0000000) { leauth = defgsid->sub_authority[cnt-2]; uauth = le32_to_cpu(leauth) + ((gid >> 30) & 3); defgsid->sub_authority[cnt-2] = cpu_to_le32(uauth); } sid = defgsid; } else sid = (p ? p->sid : (const SID*)NULL); } return (sid); } /* * Find Linux owner mapped to a usid * Returns 0 (root) if not found */ uid_t ntfs_find_user(const struct MAPPING* usermapping, const SID *usid) { uid_t uid; const struct MAPPING *p; p = usermapping; while (p && p->xid && !ntfs_same_sid(usid, p->sid)) p = p->next; if (p && !p->xid) /* * No explicit mapping found, try implicit mapping */ uid = findimplicit(usid,p->sid,0); else uid = (p ? p->xid : 0); return (uid); } /* * Find Linux group mapped to a gsid * Returns 0 (root) if not found */ gid_t ntfs_find_group(const struct MAPPING* groupmapping, const SID * gsid) { gid_t gid; const struct MAPPING *p; p = groupmapping; while (p && p->xid && !ntfs_same_sid(gsid, p->sid)) p = p->next; if (p && !p->xid) /* * No explicit mapping found, try implicit mapping */ gid = findimplicit(gsid,p->sid,1); else gid = (p ? p->xid : 0); return (gid); } /* * Check the validity of the ACEs in a DACL or SACL */ static BOOL valid_acl(const ACL *pacl, unsigned int end) { const ACCESS_ALLOWED_ACE *pace; unsigned int offace; unsigned int acecnt; unsigned int acesz; unsigned int nace; unsigned int wantsz; BOOL ok; ok = TRUE; acecnt = le16_to_cpu(pacl->ace_count); offace = sizeof(ACL); for (nace = 0; (nace < acecnt) && ok; nace++) { /* be sure the beginning is within range */ if ((offace + sizeof(ACCESS_ALLOWED_ACE)) > end) ok = FALSE; else { pace = (const ACCESS_ALLOWED_ACE*) &((const char*)pacl)[offace]; acesz = le16_to_cpu(pace->size); switch (pace->type) { case ACCESS_ALLOWED_ACE_TYPE : case ACCESS_DENIED_ACE_TYPE : wantsz = ntfs_sid_size(&pace->sid) + 8; if (((offace + acesz) > end) || !ntfs_valid_sid(&pace->sid) || (wantsz != acesz)) ok = FALSE; break; case SYSTEM_AUDIT_ACE_TYPE : case ACCESS_ALLOWED_CALLBACK_ACE_TYPE : case ACCESS_DENIED_CALLBACK_ACE_TYPE : case SYSTEM_AUDIT_CALLBACK_ACE_TYPE : case SYSTEM_MANDATORY_LABEL_ACE_TYPE : case SYSTEM_RESOURCE_ATTRIBUTE_ACE_TYPE : case SYSTEM_SCOPED_POLICY_ID_ACE_TYPE : /* Extra data after the SID */ wantsz = ntfs_sid_size(&pace->sid) + 8; if (((offace + acesz) > end) || !ntfs_valid_sid(&pace->sid) || (wantsz > acesz)) ok = FALSE; break; default : /* SID at a different location */ if ((offace + acesz) > end) ok = FALSE; break; } offace += acesz; } } return (ok); } /* * Do sanity checks on security descriptors read from storage * basically, we make sure that every field holds within * allocated storage * Should not be called with a NULL argument * returns TRUE if considered safe * if not, error should be logged by caller */ BOOL ntfs_valid_descr(const char *securattr, unsigned int attrsz) { const SECURITY_DESCRIPTOR_RELATIVE *phead; const ACL *pdacl; const ACL *psacl; unsigned int offdacl; unsigned int offsacl; unsigned int offowner; unsigned int offgroup; BOOL ok; ok = TRUE; /* * first check overall size if within allocation range * and a DACL is present * and owner and group SID are valid */ phead = (const SECURITY_DESCRIPTOR_RELATIVE*)securattr; offdacl = le32_to_cpu(phead->dacl); offsacl = le32_to_cpu(phead->sacl); offowner = le32_to_cpu(phead->owner); offgroup = le32_to_cpu(phead->group); pdacl = (const ACL*)&securattr[offdacl]; psacl = (const ACL*)&securattr[offsacl]; /* * size check occurs before the above pointers are used * * "DR Watson" standard directory on WinXP has an * old revision and no DACL though SE_DACL_PRESENT is set */ if ((attrsz >= sizeof(SECURITY_DESCRIPTOR_RELATIVE)) && (phead->revision == SECURITY_DESCRIPTOR_REVISION) && (offowner >= sizeof(SECURITY_DESCRIPTOR_RELATIVE)) && ((offowner + 2) < attrsz) && (offgroup >= sizeof(SECURITY_DESCRIPTOR_RELATIVE)) && ((offgroup + 2) < attrsz) && (!offdacl || ((offdacl >= sizeof(SECURITY_DESCRIPTOR_RELATIVE)) && (offdacl+sizeof(ACL) <= attrsz))) && (!offsacl || ((offsacl >= sizeof(SECURITY_DESCRIPTOR_RELATIVE)) && (offsacl+sizeof(ACL) <= attrsz))) && !(phead->owner & const_cpu_to_le32(3)) && !(phead->group & const_cpu_to_le32(3)) && !(phead->dacl & const_cpu_to_le32(3)) && !(phead->sacl & const_cpu_to_le32(3)) && (ntfs_attr_size(securattr) <= attrsz) && ntfs_valid_sid((const SID*)&securattr[offowner]) && ntfs_valid_sid((const SID*)&securattr[offgroup]) /* * if there is an ACL, as indicated by offdacl, * require SE_DACL_PRESENT * but "Dr Watson" has SE_DACL_PRESENT though no DACL */ && (!offdacl || ((phead->control & SE_DACL_PRESENT) && ((pdacl->revision == ACL_REVISION) || (pdacl->revision == ACL_REVISION_DS)))) /* same for SACL */ && (!offsacl || ((phead->control & SE_SACL_PRESENT) && ((psacl->revision == ACL_REVISION) || (psacl->revision == ACL_REVISION_DS))))) { /* * Check the DACL and SACL if present */ if ((offdacl && !valid_acl(pdacl,attrsz - offdacl)) || (offsacl && !valid_acl(psacl,attrsz - offsacl))) ok = FALSE; } else ok = FALSE; return (ok); } /* * Copy the inheritable parts of an ACL * * Returns the size of the new ACL * or zero if nothing is inheritable */ int ntfs_inherit_acl(const ACL *oldacl, ACL *newacl, const SID *usid, const SID *gsid, BOOL fordir, le16 inherited) { unsigned int src; unsigned int dst; int oldcnt; int newcnt; unsigned int selection; int nace; int acesz; int usidsz; int gsidsz; BOOL acceptable; const ACCESS_ALLOWED_ACE *poldace; ACCESS_ALLOWED_ACE *pnewace; ACCESS_ALLOWED_ACE *pauthace; ACCESS_ALLOWED_ACE *pownerace; pauthace = (ACCESS_ALLOWED_ACE*)NULL; pownerace = (ACCESS_ALLOWED_ACE*)NULL; usidsz = ntfs_sid_size(usid); gsidsz = ntfs_sid_size(gsid); /* ACL header */ newacl->revision = ACL_REVISION; newacl->alignment1 = 0; newacl->alignment2 = const_cpu_to_le16(0); src = dst = sizeof(ACL); selection = (fordir ? CONTAINER_INHERIT_ACE : OBJECT_INHERIT_ACE); newcnt = 0; oldcnt = le16_to_cpu(oldacl->ace_count); for (nace = 0; nace < oldcnt; nace++) { poldace = (const ACCESS_ALLOWED_ACE*)((const char*)oldacl + src); acesz = le16_to_cpu(poldace->size); src += acesz; /* * Currently only ACE for file or directory access are * processed. More information needed about what to do * for other types (whose SID may be at a different location) */ switch (poldace->type) { case ACCESS_ALLOWED_ACE_TYPE : case ACCESS_DENIED_ACE_TYPE : acceptable = TRUE; break; default : acceptable = FALSE; break; } /* * Extract inheritance for access, including inheritance for * access from an ACE with is both applied and inheritable. * * must not output OBJECT_INHERIT_ACE or CONTAINER_INHERIT_ACE * * According to MSDN : * "For a case in which a container object inherits an ACE * "that is both effective on the container and inheritable * "by its descendants, the container may inherit two ACEs. * "This occurs if the inheritable ACE contains generic * "information." */ if ((poldace->flags & selection) && acceptable && (!fordir || (poldace->flags & NO_PROPAGATE_INHERIT_ACE) || (poldace->mask & (GENERIC_ALL | GENERIC_READ | GENERIC_WRITE | GENERIC_EXECUTE))) && !ntfs_same_sid(&poldace->sid, ownersid) && !ntfs_same_sid(&poldace->sid, groupsid)) { pnewace = (ACCESS_ALLOWED_ACE*) ((char*)newacl + dst); memcpy(pnewace,poldace,acesz); /* reencode GENERIC_ALL */ if (pnewace->mask & GENERIC_ALL) { pnewace->mask &= ~GENERIC_ALL; if (fordir) pnewace->mask |= OWNER_RIGHTS | DIR_READ | DIR_WRITE | DIR_EXEC; else /* * The last flag is not defined for a file, * however Windows sets it, so do the same */ pnewace->mask |= OWNER_RIGHTS | FILE_READ | FILE_WRITE | FILE_EXEC | const_cpu_to_le32(0x40); } /* reencode GENERIC_READ (+ EXECUTE) */ if (pnewace->mask & GENERIC_READ) { if (fordir) pnewace->mask |= OWNER_RIGHTS | DIR_READ | DIR_EXEC; else pnewace->mask |= OWNER_RIGHTS | FILE_READ | FILE_EXEC; pnewace->mask &= ~(GENERIC_READ | GENERIC_EXECUTE | WRITE_DAC | WRITE_OWNER | DELETE | FILE_WRITE_EA | FILE_WRITE_ATTRIBUTES); } /* reencode GENERIC_WRITE */ if (pnewace->mask & GENERIC_WRITE) { if (fordir) pnewace->mask |= OWNER_RIGHTS | DIR_WRITE; else pnewace->mask |= OWNER_RIGHTS | FILE_WRITE; pnewace->mask &= ~(GENERIC_WRITE | WRITE_DAC | WRITE_OWNER | FILE_DELETE_CHILD); } /* remove inheritance flags */ pnewace->flags &= ~(OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE | INHERIT_ONLY_ACE); /* * Group similar ACE for authenticated users * (should probably be done for other SIDs) */ if ((poldace->type == ACCESS_ALLOWED_ACE_TYPE) && ntfs_same_sid(&poldace->sid, authsid)) { if (pauthace) { pauthace->flags |= pnewace->flags; pauthace->mask |= pnewace->mask; } else { pauthace = pnewace; if (inherited) pnewace->flags |= INHERITED_ACE; dst += acesz; newcnt++; } } else { if (inherited) pnewace->flags |= INHERITED_ACE; dst += acesz; newcnt++; } } /* * Inheritance for access, specific to * creator-owner (and creator-group) */ if ((fordir || !inherited || (poldace->flags & (CONTAINER_INHERIT_ACE | OBJECT_INHERIT_ACE))) && acceptable) { pnewace = (ACCESS_ALLOWED_ACE*) ((char*)newacl + dst); memcpy(pnewace,poldace,acesz); /* * Replace generic creator-owner and * creator-group by owner and group * (but keep for further inheritance) */ if (ntfs_same_sid(&pnewace->sid, ownersid)) { memcpy(&pnewace->sid, usid, usidsz); pnewace->size = cpu_to_le16(usidsz + 8); /* remove inheritance flags */ pnewace->flags &= ~(OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE | INHERIT_ONLY_ACE); if (inherited) pnewace->flags |= INHERITED_ACE; if ((pnewace->type == ACCESS_ALLOWED_ACE_TYPE) && pownerace && !(pnewace->flags & ~pownerace->flags)) { pownerace->mask |= pnewace->mask; } else { dst += usidsz + 8; newcnt++; } } if (ntfs_same_sid(&pnewace->sid, groupsid)) { memcpy(&pnewace->sid, gsid, gsidsz); pnewace->size = cpu_to_le16(gsidsz + 8); /* remove inheritance flags */ pnewace->flags &= ~(OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE | INHERIT_ONLY_ACE); if (inherited) pnewace->flags |= INHERITED_ACE; dst += gsidsz + 8; newcnt++; } } /* * inheritance for further inheritance * * Situations leading to output CONTAINER_INHERIT_ACE * or OBJECT_INHERIT_ACE */ if (fordir && (poldace->flags & (CONTAINER_INHERIT_ACE | OBJECT_INHERIT_ACE))) { pnewace = (ACCESS_ALLOWED_ACE*) ((char*)newacl + dst); memcpy(pnewace,poldace,acesz); if ((poldace->flags & OBJECT_INHERIT_ACE) && !(poldace->flags & (CONTAINER_INHERIT_ACE | NO_PROPAGATE_INHERIT_ACE))) pnewace->flags |= INHERIT_ONLY_ACE; if (acceptable && (poldace->flags & CONTAINER_INHERIT_ACE) && !(poldace->flags & NO_PROPAGATE_INHERIT_ACE) && !ntfs_same_sid(&poldace->sid, ownersid) && !ntfs_same_sid(&poldace->sid, groupsid)) { if ((poldace->mask & (GENERIC_ALL | GENERIC_READ | GENERIC_WRITE | GENERIC_EXECUTE))) pnewace->flags |= INHERIT_ONLY_ACE; else pnewace->flags &= ~INHERIT_ONLY_ACE; } if (inherited) pnewace->flags |= INHERITED_ACE; /* * Prepare grouping similar ACE for authenticated users */ if ((poldace->type == ACCESS_ALLOWED_ACE_TYPE) && !pauthace && !(pnewace->flags & INHERIT_ONLY_ACE) && ntfs_same_sid(&poldace->sid, authsid)) { pauthace = pnewace; } /* * Prepare grouping similar ACE for owner */ if ((poldace->type == ACCESS_ALLOWED_ACE_TYPE) && !pownerace && !(pnewace->flags & INHERIT_ONLY_ACE) && ntfs_same_sid(&poldace->sid, usid)) { pownerace = pnewace; } dst += acesz; newcnt++; } } /* * Adjust header if something was inherited */ if (dst > sizeof(ACL)) { newacl->ace_count = cpu_to_le16(newcnt); newacl->size = cpu_to_le16(dst); } else dst = 0; return (dst); } #if POSIXACLS /* * Do sanity checks on a Posix descriptor * Should not be called with a NULL argument * returns TRUE if considered safe * if not, error should be logged by caller */ BOOL ntfs_valid_posix(const struct POSIX_SECURITY *pxdesc) { const struct POSIX_ACL *pacl; int i; BOOL ok; u16 tag; u32 id; int perms; struct { u16 previous; u32 previousid; u16 tagsset; mode_t mode; int owners; int groups; int others; } checks[2], *pchk; for (i=0; i<2; i++) { checks[i].mode = 0; checks[i].tagsset = 0; checks[i].owners = 0; checks[i].groups = 0; checks[i].others = 0; checks[i].previous = 0; checks[i].previousid = 0; } ok = TRUE; pacl = &pxdesc->acl; /* * header (strict for now) */ if ((pacl->version != POSIX_VERSION) || (pacl->flags != 0) || (pacl->filler != 0)) ok = FALSE; /* * Reject multiple owner, group or other * but do not require them to be present * Also check the ACEs are in correct order * which implies there is no duplicates */ for (i=0; iacccnt + pxdesc->defcnt; i++) { if (i >= pxdesc->firstdef) pchk = &checks[1]; else pchk = &checks[0]; perms = pacl->ace[i].perms; tag = pacl->ace[i].tag; pchk->tagsset |= tag; id = pacl->ace[i].id; if (perms & ~7) ok = FALSE; if ((tag < pchk->previous) || ((tag == pchk->previous) && (id <= pchk->previousid))) ok = FALSE; pchk->previous = tag; pchk->previousid = id; switch (tag) { case POSIX_ACL_USER_OBJ : if (pchk->owners++) ok = FALSE; if (id != (u32)-1) ok = FALSE; pchk->mode |= perms << 6; break; case POSIX_ACL_GROUP_OBJ : if (pchk->groups++) ok = FALSE; if (id != (u32)-1) ok = FALSE; pchk->mode = (pchk->mode & 07707) | (perms << 3); break; case POSIX_ACL_OTHER : if (pchk->others++) ok = FALSE; if (id != (u32)-1) ok = FALSE; pchk->mode |= perms; break; case POSIX_ACL_USER : case POSIX_ACL_GROUP : if (id == (u32)-1) ok = FALSE; break; case POSIX_ACL_MASK : if (id != (u32)-1) ok = FALSE; pchk->mode = (pchk->mode & 07707) | (perms << 3); break; default : ok = FALSE; break; } } if ((pxdesc->acccnt > 0) && ((checks[0].owners != 1) || (checks[0].groups != 1) || (checks[0].others != 1))) ok = FALSE; /* do not check owner, group or other are present in */ /* the default ACL, Windows does not necessarily set them */ /* descriptor */ if (pxdesc->defcnt && (pxdesc->acccnt > pxdesc->firstdef)) ok = FALSE; if ((pxdesc->acccnt < 0) || (pxdesc->defcnt < 0)) ok = FALSE; /* check mode, unless null or no tag set */ if (pxdesc->mode && checks[0].tagsset && (checks[0].mode != (pxdesc->mode & 0777))) ok = FALSE; /* check tagsset */ if (pxdesc->tagsset != checks[0].tagsset) ok = FALSE; return (ok); } /* * Set standard header data into a Posix ACL * The mode argument should provide the 3 upper bits of target mode */ static mode_t posix_header(struct POSIX_SECURITY *pxdesc, mode_t basemode) { mode_t mode; u16 tagsset; struct POSIX_ACE *pace; int i; mode = basemode & 07000; tagsset = 0; for (i=0; iacccnt; i++) { pace = &pxdesc->acl.ace[i]; tagsset |= pace->tag; switch(pace->tag) { case POSIX_ACL_USER_OBJ : mode |= (pace->perms & 7) << 6; break; case POSIX_ACL_GROUP_OBJ : case POSIX_ACL_MASK : mode = (mode & 07707) | ((pace->perms & 7) << 3); break; case POSIX_ACL_OTHER : mode |= pace->perms & 7; break; default : break; } } pxdesc->tagsset = tagsset; pxdesc->mode = mode; pxdesc->acl.version = POSIX_VERSION; pxdesc->acl.flags = 0; pxdesc->acl.filler = 0; return (mode); } /* * Sort ACEs in a Posix ACL * This is useful for always getting reusable converted ACLs, * it also helps in merging ACEs. * Repeated tag+id are allowed and not merged here. * * Tags should be in ascending sequence and for a repeatable tag * ids should be in ascending sequence. */ void ntfs_sort_posix(struct POSIX_SECURITY *pxdesc) { struct POSIX_ACL *pacl; struct POSIX_ACE ace; int i; int offs; BOOL done; u16 tag; u16 previous; u32 id; u32 previousid; /* * Check sequencing of tag+id in access ACE's */ pacl = &pxdesc->acl; do { done = TRUE; previous = pacl->ace[0].tag; previousid = pacl->ace[0].id; for (i=1; iacccnt; i++) { tag = pacl->ace[i].tag; id = pacl->ace[i].id; if ((tag < previous) || ((tag == previous) && (id < previousid))) { done = FALSE; memcpy(&ace,&pacl->ace[i-1],sizeof(struct POSIX_ACE)); memcpy(&pacl->ace[i-1],&pacl->ace[i],sizeof(struct POSIX_ACE)); memcpy(&pacl->ace[i],&ace,sizeof(struct POSIX_ACE)); } else { previous = tag; previousid = id; } } } while (!done); /* * Same for default ACEs */ do { done = TRUE; if ((pxdesc->defcnt) > 1) { offs = pxdesc->firstdef; previous = pacl->ace[offs].tag; previousid = pacl->ace[offs].id; for (i=offs+1; idefcnt; i++) { tag = pacl->ace[i].tag; id = pacl->ace[i].id; if ((tag < previous) || ((tag == previous) && (id < previousid))) { done = FALSE; memcpy(&ace,&pacl->ace[i-1],sizeof(struct POSIX_ACE)); memcpy(&pacl->ace[i-1],&pacl->ace[i],sizeof(struct POSIX_ACE)); memcpy(&pacl->ace[i],&ace,sizeof(struct POSIX_ACE)); } else { previous = tag; previousid = id; } } } } while (!done); } /* * Merge a new mode into a Posix descriptor * The Posix descriptor is not reallocated, its size is unchanged * * returns 0 if ok */ int ntfs_merge_mode_posix(struct POSIX_SECURITY *pxdesc, mode_t mode) { int i; BOOL maskfound; struct POSIX_ACE *pace; int todo; maskfound = FALSE; todo = POSIX_ACL_USER_OBJ | POSIX_ACL_GROUP_OBJ | POSIX_ACL_OTHER; for (i=pxdesc->acccnt-1; i>=0; i--) { pace = &pxdesc->acl.ace[i]; switch(pace->tag) { case POSIX_ACL_USER_OBJ : pace->perms = (mode >> 6) & 7; todo &= ~POSIX_ACL_USER_OBJ; break; case POSIX_ACL_GROUP_OBJ : if (!maskfound) pace->perms = (mode >> 3) & 7; todo &= ~POSIX_ACL_GROUP_OBJ; break; case POSIX_ACL_MASK : pace->perms = (mode >> 3) & 7; maskfound = TRUE; break; case POSIX_ACL_OTHER : pace->perms = mode & 7; todo &= ~POSIX_ACL_OTHER; break; default : break; } } pxdesc->mode = mode; return (todo ? -1 : 0); } /* * Replace an access or default Posix ACL * The resulting ACL is checked for validity * * Returns a new ACL or NULL if there is a problem */ struct POSIX_SECURITY *ntfs_replace_acl(const struct POSIX_SECURITY *oldpxdesc, const struct POSIX_ACL *newacl, int count, BOOL deflt) { struct POSIX_SECURITY *newpxdesc; size_t newsize; int offset; int oldoffset; int i; if (deflt) newsize = sizeof(struct POSIX_SECURITY) + (oldpxdesc->acccnt + count)*sizeof(struct POSIX_ACE); else newsize = sizeof(struct POSIX_SECURITY) + (oldpxdesc->defcnt + count)*sizeof(struct POSIX_ACE); newpxdesc = (struct POSIX_SECURITY*)malloc(newsize); if (newpxdesc) { if (deflt) { offset = oldpxdesc->acccnt; newpxdesc->acccnt = oldpxdesc->acccnt; newpxdesc->defcnt = count; newpxdesc->firstdef = offset; /* copy access ACEs */ for (i=0; iacccnt; i++) newpxdesc->acl.ace[i] = oldpxdesc->acl.ace[i]; /* copy default ACEs */ for (i=0; iacl.ace[i + offset] = newacl->ace[i]; } else { offset = count; newpxdesc->acccnt = count; newpxdesc->defcnt = oldpxdesc->defcnt; newpxdesc->firstdef = count; /* copy access ACEs */ for (i=0; iacl.ace[i] = newacl->ace[i]; /* copy default ACEs */ oldoffset = oldpxdesc->firstdef; for (i=0; idefcnt; i++) newpxdesc->acl.ace[i + offset] = oldpxdesc->acl.ace[i + oldoffset]; } /* assume special flags unchanged */ posix_header(newpxdesc, oldpxdesc->mode); if (!ntfs_valid_posix(newpxdesc)) { /* do not log, this is an application error */ free(newpxdesc); newpxdesc = (struct POSIX_SECURITY*)NULL; errno = EINVAL; } } else errno = ENOMEM; return (newpxdesc); } /* * Build a basic Posix ACL from a mode and umask, * ignoring inheritance from the parent directory */ struct POSIX_SECURITY *ntfs_build_basic_posix( const struct POSIX_SECURITY *pxdesc __attribute__((unused)), mode_t mode, mode_t mask, BOOL isdir __attribute__((unused))) { struct POSIX_SECURITY *pydesc; struct POSIX_ACE *pyace; pydesc = (struct POSIX_SECURITY*)malloc( sizeof(struct POSIX_SECURITY) + 3*sizeof(struct POSIX_ACE)); if (pydesc) { pyace = &pydesc->acl.ace[0]; pyace->tag = POSIX_ACL_USER_OBJ; pyace->perms = ((mode & ~mask) >> 6) & 7; pyace->id = -1; pyace = &pydesc->acl.ace[1]; pyace->tag = POSIX_ACL_GROUP_OBJ; pyace->perms = ((mode & ~mask) >> 3) & 7; pyace->id = -1; pyace = &pydesc->acl.ace[2]; pyace->tag = POSIX_ACL_OTHER; pyace->perms = (mode & ~mask) & 7; pyace->id = -1; pydesc->mode = mode; pydesc->tagsset = POSIX_ACL_USER_OBJ | POSIX_ACL_GROUP_OBJ | POSIX_ACL_OTHER; pydesc->acccnt = 3; pydesc->defcnt = 0; pydesc->firstdef = 6; pydesc->filler = 0; pydesc->acl.version = POSIX_VERSION; pydesc->acl.flags = 0; pydesc->acl.filler = 0; } else errno = ENOMEM; return (pydesc); } /* * Build an inherited Posix descriptor from parent * descriptor (if any) restricted to creation mode * * Returns the inherited descriptor or NULL if there is a problem */ struct POSIX_SECURITY *ntfs_build_inherited_posix( const struct POSIX_SECURITY *pxdesc, mode_t mode, mode_t mask, BOOL isdir) { struct POSIX_SECURITY *pydesc; struct POSIX_ACE *pyace; int count; int defcnt; int size; int i; s16 tagsset; if (pxdesc && pxdesc->defcnt) { if (isdir) count = 2*pxdesc->defcnt + 3; else count = pxdesc->defcnt + 3; } else count = 3; pydesc = (struct POSIX_SECURITY*)malloc( sizeof(struct POSIX_SECURITY) + count*sizeof(struct POSIX_ACE)); if (pydesc) { /* * Copy inherited tags and adapt perms * Use requested mode, ignoring umask * (not possible with older versions of fuse) */ tagsset = 0; defcnt = (pxdesc ? pxdesc->defcnt : 0); for (i=defcnt-1; i>=0; i--) { pyace = &pydesc->acl.ace[i]; *pyace = pxdesc->acl.ace[pxdesc->firstdef + i]; switch (pyace->tag) { case POSIX_ACL_USER_OBJ : pyace->perms &= (mode >> 6) & 7; break; case POSIX_ACL_GROUP_OBJ : if (!(tagsset & POSIX_ACL_MASK)) pyace->perms &= (mode >> 3) & 7; break; case POSIX_ACL_OTHER : pyace->perms &= mode & 7; break; case POSIX_ACL_MASK : pyace->perms &= (mode >> 3) & 7; break; default : break; } tagsset |= pyace->tag; } pydesc->acccnt = defcnt; /* * If some standard tags were missing, append them from mode * and sort the list * Here we have to use the umask'ed mode */ if (~tagsset & (POSIX_ACL_USER_OBJ | POSIX_ACL_GROUP_OBJ | POSIX_ACL_OTHER)) { i = defcnt; /* owner was missing */ if (!(tagsset & POSIX_ACL_USER_OBJ)) { pyace = &pydesc->acl.ace[i]; pyace->tag = POSIX_ACL_USER_OBJ; pyace->id = -1; pyace->perms = ((mode & ~mask) >> 6) & 7; tagsset |= POSIX_ACL_USER_OBJ; i++; } /* owning group was missing */ if (!(tagsset & POSIX_ACL_GROUP_OBJ)) { pyace = &pydesc->acl.ace[i]; pyace->tag = POSIX_ACL_GROUP_OBJ; pyace->id = -1; pyace->perms = ((mode & ~mask) >> 3) & 7; tagsset |= POSIX_ACL_GROUP_OBJ; i++; } /* other was missing */ if (!(tagsset & POSIX_ACL_OTHER)) { pyace = &pydesc->acl.ace[i]; pyace->tag = POSIX_ACL_OTHER; pyace->id = -1; pyace->perms = mode & ~mask & 7; tagsset |= POSIX_ACL_OTHER; i++; } pydesc->acccnt = i; pydesc->firstdef = i; pydesc->defcnt = 0; ntfs_sort_posix(pydesc); } /* * append as a default ACL if a directory */ pydesc->firstdef = pydesc->acccnt; if (defcnt && isdir) { size = sizeof(struct POSIX_ACE)*defcnt; memcpy(&pydesc->acl.ace[pydesc->firstdef], &pxdesc->acl.ace[pxdesc->firstdef],size); pydesc->defcnt = defcnt; } else { pydesc->defcnt = 0; } /* assume special bits are not inherited */ posix_header(pydesc, mode & 07000); if (!ntfs_valid_posix(pydesc)) { ntfs_log_error("Error building an inherited Posix desc\n"); errno = EIO; free(pydesc); pydesc = (struct POSIX_SECURITY*)NULL; } } else errno = ENOMEM; return (pydesc); } static int merge_lists_posix(struct POSIX_ACE *targetace, const struct POSIX_ACE *firstace, const struct POSIX_ACE *secondace, int firstcnt, int secondcnt) { int k; k = 0; /* * No list is exhausted : * if same tag+id in both list : * ignore ACE from second list * else take the one with smaller tag+id */ while ((firstcnt > 0) && (secondcnt > 0)) if ((firstace->tag == secondace->tag) && (firstace->id == secondace->id)) { secondace++; secondcnt--; } else if ((firstace->tag < secondace->tag) || ((firstace->tag == secondace->tag) && (firstace->id < secondace->id))) { targetace->tag = firstace->tag; targetace->id = firstace->id; targetace->perms = firstace->perms; firstace++; targetace++; firstcnt--; k++; } else { targetace->tag = secondace->tag; targetace->id = secondace->id; targetace->perms = secondace->perms; secondace++; targetace++; secondcnt--; k++; } /* * One list is exhausted, copy the other one */ while (firstcnt > 0) { targetace->tag = firstace->tag; targetace->id = firstace->id; targetace->perms = firstace->perms; firstace++; targetace++; firstcnt--; k++; } while (secondcnt > 0) { targetace->tag = secondace->tag; targetace->id = secondace->id; targetace->perms = secondace->perms; secondace++; targetace++; secondcnt--; k++; } return (k); } /* * Merge two Posix ACLs * The input ACLs have to be adequately sorted * * Returns the merged ACL, which is allocated and has to be freed by caller, * or NULL if failed */ struct POSIX_SECURITY *ntfs_merge_descr_posix(const struct POSIX_SECURITY *first, const struct POSIX_SECURITY *second) { struct POSIX_SECURITY *pxdesc; struct POSIX_ACE *targetace; const struct POSIX_ACE *firstace; const struct POSIX_ACE *secondace; size_t size; int k; size = sizeof(struct POSIX_SECURITY) + (first->acccnt + first->defcnt + second->acccnt + second->defcnt)*sizeof(struct POSIX_ACE); pxdesc = (struct POSIX_SECURITY*)malloc(size); if (pxdesc) { /* * merge access ACEs */ firstace = first->acl.ace; secondace = second->acl.ace; targetace = pxdesc->acl.ace; k = merge_lists_posix(targetace,firstace,secondace, first->acccnt,second->acccnt); pxdesc->acccnt = k; /* * merge default ACEs */ pxdesc->firstdef = k; firstace = &first->acl.ace[first->firstdef]; secondace = &second->acl.ace[second->firstdef]; targetace = &pxdesc->acl.ace[k]; k = merge_lists_posix(targetace,firstace,secondace, first->defcnt,second->defcnt); pxdesc->defcnt = k; /* * build header */ pxdesc->acl.version = POSIX_VERSION; pxdesc->acl.flags = 0; pxdesc->acl.filler = 0; pxdesc->mode = 0; pxdesc->tagsset = 0; } else errno = ENOMEM; return (pxdesc); } struct BUILD_CONTEXT { BOOL isdir; BOOL adminowns; BOOL groupowns; u16 selfuserperms; u16 selfgrpperms; u16 grpperms; u16 othperms; u16 mask; u16 designates; u16 withmask; u16 rootspecial; } ; static BOOL build_user_denials(ACL *pacl, const SID *usid, struct MAPPING* const mapping[], ACE_FLAGS flags, const struct POSIX_ACE *pxace, struct BUILD_CONTEXT *pset) { BIGSID defsid; ACCESS_ALLOWED_ACE *pdace; const SID *sid; int sidsz; int pos; int acecnt; le32 grants; le32 denials; u16 perms; u16 mixperms; u16 tag; BOOL rejected; BOOL rootuser; BOOL avoidmask; rejected = FALSE; tag = pxace->tag; perms = pxace->perms; rootuser = FALSE; pos = le16_to_cpu(pacl->size); acecnt = le16_to_cpu(pacl->ace_count); avoidmask = (pset->mask == (POSIX_PERM_R | POSIX_PERM_W | POSIX_PERM_X)) && ((pset->designates && pset->withmask) || (!pset->designates && !pset->withmask)); if (tag == POSIX_ACL_USER_OBJ) { sid = usid; sidsz = ntfs_sid_size(sid); grants = OWNER_RIGHTS; } else { if (pxace->id) { sid = ntfs_find_usid(mapping[MAPUSERS], pxace->id, (SID*)&defsid); grants = WORLD_RIGHTS; } else { sid = adminsid; rootuser = TRUE; grants = WORLD_RIGHTS & ~ROOT_OWNER_UNMARK; } if (sid) { sidsz = ntfs_sid_size(sid); /* * Insert denial of complement of mask for * each designated user (except root) * WRITE_OWNER is inserted so that * the mask can be identified */ if (!avoidmask && !rootuser) { denials = WRITE_OWNER; pdace = (ACCESS_DENIED_ACE*)&((char*)pacl)[pos]; if (pset->isdir) { if (!(pset->mask & POSIX_PERM_X)) denials |= DIR_EXEC; if (!(pset->mask & POSIX_PERM_W)) denials |= DIR_WRITE; if (!(pset->mask & POSIX_PERM_R)) denials |= DIR_READ; } else { if (!(pset->mask & POSIX_PERM_X)) denials |= FILE_EXEC; if (!(pset->mask & POSIX_PERM_W)) denials |= FILE_WRITE; if (!(pset->mask & POSIX_PERM_R)) denials |= FILE_READ; } if (rootuser) grants &= ~ROOT_OWNER_UNMARK; pdace->type = ACCESS_DENIED_ACE_TYPE; pdace->flags = flags; pdace->size = cpu_to_le16(sidsz + 8); pdace->mask = denials; memcpy((char*)&pdace->sid, sid, sidsz); pos += sidsz + 8; acecnt++; } } else rejected = TRUE; } if (!rejected) { if (pset->isdir) { if (perms & POSIX_PERM_X) grants |= DIR_EXEC; if (perms & POSIX_PERM_W) grants |= DIR_WRITE; if (perms & POSIX_PERM_R) grants |= DIR_READ; } else { if (perms & POSIX_PERM_X) grants |= FILE_EXEC; if (perms & POSIX_PERM_W) grants |= FILE_WRITE; if (perms & POSIX_PERM_R) grants |= FILE_READ; } /* a possible ACE to deny owner what he/she would */ /* induely get from administrator, group or world */ /* unless owner is administrator or group */ denials = const_cpu_to_le32(0); pdace = (ACCESS_DENIED_ACE*)&((char*)pacl)[pos]; if (!pset->adminowns && !rootuser) { if (!pset->groupowns) { mixperms = pset->grpperms | pset->othperms; if (tag == POSIX_ACL_USER_OBJ) mixperms |= pset->selfuserperms; if (pset->isdir) { if (mixperms & POSIX_PERM_X) denials |= DIR_EXEC; if (mixperms & POSIX_PERM_W) denials |= DIR_WRITE; if (mixperms & POSIX_PERM_R) denials |= DIR_READ; } else { if (mixperms & POSIX_PERM_X) denials |= FILE_EXEC; if (mixperms & POSIX_PERM_W) denials |= FILE_WRITE; if (mixperms & POSIX_PERM_R) denials |= FILE_READ; } } else { mixperms = ~pset->grpperms & pset->othperms; if (tag == POSIX_ACL_USER_OBJ) mixperms |= pset->selfuserperms; if (pset->isdir) { if (mixperms & POSIX_PERM_X) denials |= DIR_EXEC; if (mixperms & POSIX_PERM_W) denials |= DIR_WRITE; if (mixperms & POSIX_PERM_R) denials |= DIR_READ; } else { if (mixperms & POSIX_PERM_X) denials |= FILE_EXEC; if (mixperms & POSIX_PERM_W) denials |= FILE_WRITE; if (mixperms & POSIX_PERM_R) denials |= FILE_READ; } } denials &= ~grants; if (denials) { pdace->type = ACCESS_DENIED_ACE_TYPE; pdace->flags = flags; pdace->size = cpu_to_le16(sidsz + 8); pdace->mask = denials; memcpy((char*)&pdace->sid, sid, sidsz); pos += sidsz + 8; acecnt++; } } } pacl->size = cpu_to_le16(pos); pacl->ace_count = cpu_to_le16(acecnt); return (!rejected); } static BOOL build_user_grants(ACL *pacl, const SID *usid, struct MAPPING* const mapping[], ACE_FLAGS flags, const struct POSIX_ACE *pxace, struct BUILD_CONTEXT *pset) { BIGSID defsid; ACCESS_ALLOWED_ACE *pgace; const SID *sid; int sidsz; int pos; int acecnt; le32 grants; u16 perms; u16 tag; BOOL rejected; BOOL rootuser; rejected = FALSE; tag = pxace->tag; perms = pxace->perms; rootuser = FALSE; pos = le16_to_cpu(pacl->size); acecnt = le16_to_cpu(pacl->ace_count); if (tag == POSIX_ACL_USER_OBJ) { sid = usid; sidsz = ntfs_sid_size(sid); grants = OWNER_RIGHTS; } else { if (pxace->id) { sid = ntfs_find_usid(mapping[MAPUSERS], pxace->id, (SID*)&defsid); if (sid) sidsz = ntfs_sid_size(sid); else rejected = TRUE; grants = WORLD_RIGHTS; } else { sid = adminsid; sidsz = ntfs_sid_size(sid); rootuser = TRUE; grants = WORLD_RIGHTS & ~ROOT_OWNER_UNMARK; } } if (!rejected) { if (pset->isdir) { if (perms & POSIX_PERM_X) grants |= DIR_EXEC; if (perms & POSIX_PERM_W) grants |= DIR_WRITE; if (perms & POSIX_PERM_R) grants |= DIR_READ; } else { if (perms & POSIX_PERM_X) grants |= FILE_EXEC; if (perms & POSIX_PERM_W) grants |= FILE_WRITE; if (perms & POSIX_PERM_R) grants |= FILE_READ; } if (rootuser) grants &= ~ROOT_OWNER_UNMARK; pgace = (ACCESS_DENIED_ACE*)&((char*)pacl)[pos]; pgace->type = ACCESS_ALLOWED_ACE_TYPE; pgace->size = cpu_to_le16(sidsz + 8); pgace->flags = flags; pgace->mask = grants; memcpy((char*)&pgace->sid, sid, sidsz); pos += sidsz + 8; acecnt = le16_to_cpu(pacl->ace_count) + 1; pacl->ace_count = cpu_to_le16(acecnt); pacl->size = cpu_to_le16(pos); } return (!rejected); } /* a grant ACE for group */ /* unless group-obj has the same rights as world */ /* but present if group is owner or owner is administrator */ /* this ACE will be inserted after denials for group */ static BOOL build_group_denials_grant(ACL *pacl, const SID *gsid, struct MAPPING* const mapping[], ACE_FLAGS flags, const struct POSIX_ACE *pxace, struct BUILD_CONTEXT *pset) { BIGSID defsid; ACCESS_ALLOWED_ACE *pdace; ACCESS_ALLOWED_ACE *pgace; const SID *sid; int sidsz; int pos; int acecnt; le32 grants; le32 denials; u16 perms; u16 mixperms; u16 tag; BOOL avoidmask; BOOL rootgroup; BOOL rejected; rejected = FALSE; tag = pxace->tag; perms = pxace->perms; pos = le16_to_cpu(pacl->size); acecnt = le16_to_cpu(pacl->ace_count); rootgroup = FALSE; avoidmask = (pset->mask == (POSIX_PERM_R | POSIX_PERM_W | POSIX_PERM_X)) && ((pset->designates && pset->withmask) || (!pset->designates && !pset->withmask)); if (tag == POSIX_ACL_GROUP_OBJ) sid = gsid; else if (pxace->id) sid = ntfs_find_gsid(mapping[MAPGROUPS], pxace->id, (SID*)&defsid); else { sid = adminsid; rootgroup = TRUE; } if (sid) { sidsz = ntfs_sid_size(sid); /* * Insert denial of complement of mask for * each group * WRITE_OWNER is inserted so that * the mask can be identified * Note : this mask may lead on Windows to * deny rights to administrators belonging * to some user group */ if ((!avoidmask && !rootgroup) || (pset->rootspecial && (tag == POSIX_ACL_GROUP_OBJ))) { denials = WRITE_OWNER; pdace = (ACCESS_DENIED_ACE*)&((char*)pacl)[pos]; if (pset->isdir) { if (!(pset->mask & POSIX_PERM_X)) denials |= DIR_EXEC; if (!(pset->mask & POSIX_PERM_W)) denials |= DIR_WRITE; if (!(pset->mask & POSIX_PERM_R)) denials |= DIR_READ; } else { if (!(pset->mask & POSIX_PERM_X)) denials |= FILE_EXEC; if (!(pset->mask & POSIX_PERM_W)) denials |= FILE_WRITE; if (!(pset->mask & POSIX_PERM_R)) denials |= FILE_READ; } pdace->type = ACCESS_DENIED_ACE_TYPE; pdace->flags = flags; pdace->size = cpu_to_le16(sidsz + 8); pdace->mask = denials; memcpy((char*)&pdace->sid, sid, sidsz); pos += sidsz + 8; acecnt++; } } else rejected = TRUE; if (!rejected && (pset->adminowns || pset->groupowns || avoidmask || rootgroup || (perms != pset->othperms))) { grants = WORLD_RIGHTS; if (rootgroup) grants &= ~ROOT_GROUP_UNMARK; if (pset->isdir) { if (perms & POSIX_PERM_X) grants |= DIR_EXEC; if (perms & POSIX_PERM_W) grants |= DIR_WRITE; if (perms & POSIX_PERM_R) grants |= DIR_READ; } else { if (perms & POSIX_PERM_X) grants |= FILE_EXEC; if (perms & POSIX_PERM_W) grants |= FILE_WRITE; if (perms & POSIX_PERM_R) grants |= FILE_READ; } /* a possible ACE to deny group what it would get from world */ /* or administrator, unless owner is administrator or group */ denials = const_cpu_to_le32(0); pdace = (ACCESS_DENIED_ACE*)&((char*)pacl)[pos]; if (!pset->adminowns && !pset->groupowns && !rootgroup) { mixperms = pset->othperms; if (tag == POSIX_ACL_GROUP_OBJ) mixperms |= pset->selfgrpperms; if (pset->isdir) { if (mixperms & POSIX_PERM_X) denials |= DIR_EXEC; if (mixperms & POSIX_PERM_W) denials |= DIR_WRITE; if (mixperms & POSIX_PERM_R) denials |= DIR_READ; } else { if (mixperms & POSIX_PERM_X) denials |= FILE_EXEC; if (mixperms & POSIX_PERM_W) denials |= FILE_WRITE; if (mixperms & POSIX_PERM_R) denials |= FILE_READ; } denials &= ~(grants | OWNER_RIGHTS); if (denials) { pdace->type = ACCESS_DENIED_ACE_TYPE; pdace->flags = flags; pdace->size = cpu_to_le16(sidsz + 8); pdace->mask = denials; memcpy((char*)&pdace->sid, sid, sidsz); pos += sidsz + 8; acecnt++; } } /* now insert grants to group if more than world */ if (pset->adminowns || pset->groupowns || (avoidmask && (pset->designates || pset->withmask)) || (perms & ~pset->othperms) || (pset->rootspecial && (tag == POSIX_ACL_GROUP_OBJ)) || (tag == POSIX_ACL_GROUP)) { if (rootgroup) grants &= ~ROOT_GROUP_UNMARK; pgace = (ACCESS_DENIED_ACE*)&((char*)pacl)[pos]; pgace->type = ACCESS_ALLOWED_ACE_TYPE; pgace->flags = flags; pgace->size = cpu_to_le16(sidsz + 8); pgace->mask = grants; memcpy((char*)&pgace->sid, sid, sidsz); pos += sidsz + 8; acecnt++; } } pacl->size = cpu_to_le16(pos); pacl->ace_count = cpu_to_le16(acecnt); return (!rejected); } /* * Build an ACL composed of several ACE's * returns size of ACL or zero if failed * * Three schemes are defined : * * 1) if root is neither owner nor group up to 7 ACE's are set up : * - denials to owner (preventing grants to world or group to apply) * + mask denials to designated user (unless mask allows all) * + denials to designated user * - grants to owner (always present - first grant) * + grants to designated user * + mask denial to group (unless mask allows all) * - denials to group (preventing grants to world to apply) * - grants to group (unless group has no more than world rights) * + mask denials to designated group (unless mask allows all) * + grants to designated group * + denials to designated group * - grants to world (unless none) * - full privileges to administrator, always present * - full privileges to system, always present * * The same scheme is applied for Posix ACLs, with the mask represented * as denials prepended to grants for designated users and groups * * This is inspired by an Internet Draft from Marius Aamodt Eriksen * for mapping NFSv4 ACLs to Posix ACLs (draft-ietf-nfsv4-acl-mapping-00.txt) * More recent versions of the draft (draft-ietf-nfsv4-acl-mapping-05.txt) * are not followed, as they ignore the Posix mask and lead to * loss of compatibility with Linux implementations on other fs. * * Note that denials to group are located after grants to owner. * This only occurs in the unfrequent situation where world * has more rights than group and cannot be avoided if owner and other * have some common right which is denied to group (eg for mode 745 * executing has to be denied to group, but not to owner or world). * This rare situation is processed by Windows correctly, but * Windows utilities may want to change the order, with a * consequence of applying the group denials to the Windows owner. * The interpretation on Linux is not affected by the order change. * * 2) if root is either owner or group, two problems arise : * - granting full rights to administrator (as needed to transpose * to Windows rights bypassing granting to root) would imply * Linux permissions to always be seen as rwx, no matter the chmod * - there is no different SID to separate an administrator owner * from an administrator group. Hence Linux permissions for owner * would always be similar to permissions to group. * * as a work-around, up to 5 ACE's are set up if owner or group : * - grants to owner, always present at first position * - grants to group, always present * - grants to world, unless none * - full privileges to administrator, always present * - full privileges to system, always present * * On Windows, these ACE's are processed normally, though they * are redundant (owner, group and administrator are the same, * as a consequence any denials would damage administrator rights) * but on Linux, privileges to administrator are ignored (they * are not needed as root has always full privileges), and * neither grants to group are applied to owner, nor grants to * world are applied to owner or group. * * 3) finally a similar situation arises when group is owner (they * have the same SID), but is not root. * In this situation up to 6 ACE's are set up : * * - denials to owner (preventing grants to world to apply) * - grants to owner (always present) * - grants to group (unless groups has same rights as world) * - grants to world (unless none) * - full privileges to administrator, always present * - full privileges to system, always present * * On Windows, these ACE's are processed normally, though they * are redundant (as owner and group are the same), but this has * no impact on administrator rights * * Special flags (S_ISVTX, S_ISGID, S_ISUID) : * an extra null ACE is inserted to hold these flags, using * the same conventions as cygwin. * */ static int buildacls_posix(struct MAPPING* const mapping[], char *secattr, int offs, const struct POSIX_SECURITY *pxdesc, int isdir, const SID *usid, const SID *gsid) { struct BUILD_CONTEXT aceset[2], *pset; BOOL adminowns; BOOL groupowns; ACL *pacl; ACCESS_ALLOWED_ACE *pgace; ACCESS_ALLOWED_ACE *pdace; const struct POSIX_ACE *pxace; BOOL ok; mode_t mode; u16 tag; u16 perms; ACE_FLAGS flags; int pos; int i; int k; BIGSID defsid; const SID *sid; int acecnt; int usidsz; int wsidsz; int asidsz; int ssidsz; int nsidsz; le32 grants; usidsz = ntfs_sid_size(usid); wsidsz = ntfs_sid_size(worldsid); asidsz = ntfs_sid_size(adminsid); ssidsz = ntfs_sid_size(systemsid); mode = pxdesc->mode; /* adminowns and groupowns are used for both lists */ adminowns = ntfs_same_sid(usid, adminsid) || ntfs_same_sid(gsid, adminsid); groupowns = !adminowns && ntfs_same_sid(usid, gsid); ok = TRUE; /* ACL header */ pacl = (ACL*)&secattr[offs]; pacl->revision = ACL_REVISION; pacl->alignment1 = 0; pacl->size = cpu_to_le16(sizeof(ACL) + usidsz + 8); pacl->ace_count = const_cpu_to_le16(0); pacl->alignment2 = const_cpu_to_le16(0); /* * Determine what is allowed to some group or world * to prevent designated users or other groups to get * rights from groups or world * Do the same if owner and group appear as designated * user or group * Also get global mask */ for (k=0; k<2; k++) { pset = &aceset[k]; pset->selfuserperms = 0; pset->selfgrpperms = 0; pset->grpperms = 0; pset->othperms = 0; pset->mask = (POSIX_PERM_R | POSIX_PERM_W | POSIX_PERM_X); pset->designates = 0; pset->withmask = 0; pset->rootspecial = 0; pset->adminowns = adminowns; pset->groupowns = groupowns; pset->isdir = isdir; } for (i=pxdesc->acccnt+pxdesc->defcnt-1; i>=0; i--) { if (i >= pxdesc->acccnt) { pset = &aceset[1]; pxace = &pxdesc->acl.ace[i + pxdesc->firstdef - pxdesc->acccnt]; } else { pset = &aceset[0]; pxace = &pxdesc->acl.ace[i]; } switch (pxace->tag) { case POSIX_ACL_USER : pset->designates++; if (pxace->id) { sid = ntfs_find_usid(mapping[MAPUSERS], pxace->id, (SID*)&defsid); if (sid && ntfs_same_sid(sid,usid)) pset->selfuserperms |= pxace->perms; } else /* root as designated user is processed apart */ pset->rootspecial = TRUE; break; case POSIX_ACL_GROUP : pset->designates++; if (pxace->id) { sid = ntfs_find_gsid(mapping[MAPUSERS], pxace->id, (SID*)&defsid); if (sid && ntfs_same_sid(sid,gsid)) pset->selfgrpperms |= pxace->perms; } else /* root as designated group is processed apart */ pset->rootspecial = TRUE; /* fall through */ case POSIX_ACL_GROUP_OBJ : pset->grpperms |= pxace->perms; break; case POSIX_ACL_OTHER : pset->othperms = pxace->perms; break; case POSIX_ACL_MASK : pset->withmask++; pset->mask = pxace->perms; default : break; } } if (pxdesc->defcnt && (pxdesc->firstdef != pxdesc->acccnt)) { ntfs_log_error("** error : access and default not consecutive\n"); return (0); } /* * First insert all denials for owner and each * designated user (with mask if needed) */ pacl->ace_count = const_cpu_to_le16(0); pacl->size = const_cpu_to_le16(sizeof(ACL)); for (i=0; (i<(pxdesc->acccnt + pxdesc->defcnt)) && ok; i++) { if (i >= pxdesc->acccnt) { flags = INHERIT_ONLY_ACE | OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE; pset = &aceset[1]; pxace = &pxdesc->acl.ace[i + pxdesc->firstdef - pxdesc->acccnt]; } else { if (pxdesc->defcnt) flags = NO_PROPAGATE_INHERIT_ACE; else flags = (isdir ? DIR_INHERITANCE : FILE_INHERITANCE); pset = &aceset[0]; pxace = &pxdesc->acl.ace[i]; } tag = pxace->tag; perms = pxace->perms; switch (tag) { /* insert denial ACEs for each owner or allowed user */ case POSIX_ACL_USER : case POSIX_ACL_USER_OBJ : ok = build_user_denials(pacl, usid, mapping, flags, pxace, pset); break; default : break; } } /* * for directories, insert a world execution denial * inherited to plain files. * This is to prevent Windows from granting execution * of files through inheritance from parent directory */ if (isdir && ok) { pos = le16_to_cpu(pacl->size); pdace = (ACCESS_DENIED_ACE*) &secattr[offs + pos]; pdace->type = ACCESS_DENIED_ACE_TYPE; pdace->flags = INHERIT_ONLY_ACE | OBJECT_INHERIT_ACE; pdace->size = cpu_to_le16(wsidsz + 8); pdace->mask = FILE_EXEC; memcpy((char*)&pdace->sid, worldsid, wsidsz); pos += wsidsz + 8; acecnt = le16_to_cpu(pacl->ace_count) + 1; pacl->ace_count = cpu_to_le16(acecnt); pacl->size = cpu_to_le16(pos); } /* * now insert (if needed) * - grants to owner and designated users * - mask and denials for all groups * - grants to other */ for (i=0; (i<(pxdesc->acccnt + pxdesc->defcnt)) && ok; i++) { if (i >= pxdesc->acccnt) { flags = INHERIT_ONLY_ACE | OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE; pset = &aceset[1]; pxace = &pxdesc->acl.ace[i + pxdesc->firstdef - pxdesc->acccnt]; } else { if (pxdesc->defcnt) flags = NO_PROPAGATE_INHERIT_ACE; else flags = (isdir ? DIR_INHERITANCE : FILE_INHERITANCE); pset = &aceset[0]; pxace = &pxdesc->acl.ace[i]; } tag = pxace->tag; perms = pxace->perms; switch (tag) { /* ACE for each owner or allowed user */ case POSIX_ACL_USER : case POSIX_ACL_USER_OBJ : ok = build_user_grants(pacl,usid, mapping,flags,pxace,pset); break; case POSIX_ACL_GROUP_OBJ : /* denials and grants for group when needed */ if (pset->groupowns && !pset->adminowns && (pset->grpperms == pset->othperms) && !pset->designates && !pset->withmask) { ok = TRUE; } else { ok = build_group_denials_grant(pacl,gsid, mapping,flags,pxace,pset); } break; case POSIX_ACL_GROUP : /* denials and grants for designated groups */ ok = build_group_denials_grant(pacl,gsid, mapping,flags,pxace,pset); break; case POSIX_ACL_OTHER : /* grants for other users */ pos = le16_to_cpu(pacl->size); pgace = (ACCESS_ALLOWED_ACE*)&secattr[offs + pos]; grants = WORLD_RIGHTS; if (isdir) { if (perms & POSIX_PERM_X) grants |= DIR_EXEC; if (perms & POSIX_PERM_W) grants |= DIR_WRITE; if (perms & POSIX_PERM_R) grants |= DIR_READ; } else { if (perms & POSIX_PERM_X) grants |= FILE_EXEC; if (perms & POSIX_PERM_W) grants |= FILE_WRITE; if (perms & POSIX_PERM_R) grants |= FILE_READ; } pgace->type = ACCESS_ALLOWED_ACE_TYPE; pgace->flags = flags; pgace->size = cpu_to_le16(wsidsz + 8); pgace->mask = grants; memcpy((char*)&pgace->sid, worldsid, wsidsz); pos += wsidsz + 8; acecnt = le16_to_cpu(pacl->ace_count) + 1; pacl->ace_count = cpu_to_le16(acecnt); pacl->size = cpu_to_le16(pos); break; } } if (!ok) { errno = EINVAL; pos = 0; } else { /* an ACE for administrators */ /* always full access */ pos = le16_to_cpu(pacl->size); acecnt = le16_to_cpu(pacl->ace_count); if (isdir) flags = OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE; else flags = NO_PROPAGATE_INHERIT_ACE; pgace = (ACCESS_ALLOWED_ACE*)&secattr[offs + pos]; pgace->type = ACCESS_ALLOWED_ACE_TYPE; pgace->flags = flags; pgace->size = cpu_to_le16(asidsz + 8); grants = OWNER_RIGHTS | FILE_READ | FILE_WRITE | FILE_EXEC; pgace->mask = grants; memcpy((char*)&pgace->sid, adminsid, asidsz); pos += asidsz + 8; acecnt++; /* an ACE for system (needed ?) */ /* always full access */ pgace = (ACCESS_ALLOWED_ACE*)&secattr[offs + pos]; pgace->type = ACCESS_ALLOWED_ACE_TYPE; pgace->flags = flags; pgace->size = cpu_to_le16(ssidsz + 8); grants = OWNER_RIGHTS | FILE_READ | FILE_WRITE | FILE_EXEC; pgace->mask = grants; memcpy((char*)&pgace->sid, systemsid, ssidsz); pos += ssidsz + 8; acecnt++; /* a null ACE to hold special flags */ /* using the same representation as cygwin */ if (mode & (S_ISVTX | S_ISGID | S_ISUID)) { nsidsz = ntfs_sid_size(nullsid); pgace = (ACCESS_ALLOWED_ACE*)&secattr[offs + pos]; pgace->type = ACCESS_ALLOWED_ACE_TYPE; pgace->flags = NO_PROPAGATE_INHERIT_ACE; pgace->size = cpu_to_le16(nsidsz + 8); grants = const_cpu_to_le32(0); if (mode & S_ISUID) grants |= FILE_APPEND_DATA; if (mode & S_ISGID) grants |= FILE_WRITE_DATA; if (mode & S_ISVTX) grants |= FILE_READ_DATA; pgace->mask = grants; memcpy((char*)&pgace->sid, nullsid, nsidsz); pos += nsidsz + 8; acecnt++; } /* fix ACL header */ pacl->size = cpu_to_le16(pos); pacl->ace_count = cpu_to_le16(acecnt); } return (ok ? pos : 0); } #endif /* POSIXACLS */ static int buildacls(char *secattr, int offs, mode_t mode, int isdir, const SID * usid, const SID * gsid) { ACL *pacl; ACCESS_ALLOWED_ACE *pgace; ACCESS_ALLOWED_ACE *pdace; BOOL adminowns; BOOL groupowns; ACE_FLAGS gflags; int pos; int acecnt; int usidsz; int gsidsz; int wsidsz; int asidsz; int ssidsz; int nsidsz; le32 grants; le32 denials; usidsz = ntfs_sid_size(usid); gsidsz = ntfs_sid_size(gsid); wsidsz = ntfs_sid_size(worldsid); asidsz = ntfs_sid_size(adminsid); ssidsz = ntfs_sid_size(systemsid); adminowns = ntfs_same_sid(usid, adminsid) || ntfs_same_sid(gsid, adminsid); groupowns = !adminowns && ntfs_same_sid(usid, gsid); /* ACL header */ pacl = (ACL*)&secattr[offs]; pacl->revision = ACL_REVISION; pacl->alignment1 = 0; pacl->size = cpu_to_le16(sizeof(ACL) + usidsz + 8); pacl->ace_count = const_cpu_to_le16(1); pacl->alignment2 = const_cpu_to_le16(0); pos = sizeof(ACL); acecnt = 0; /* compute a grant ACE for owner */ /* this ACE will be inserted after denial for owner */ grants = OWNER_RIGHTS; if (isdir) { gflags = DIR_INHERITANCE; if (mode & S_IXUSR) grants |= DIR_EXEC; if (mode & S_IWUSR) grants |= DIR_WRITE; if (mode & S_IRUSR) grants |= DIR_READ; } else { gflags = FILE_INHERITANCE; if (mode & S_IXUSR) grants |= FILE_EXEC; if (mode & S_IWUSR) grants |= FILE_WRITE; if (mode & S_IRUSR) grants |= FILE_READ; } /* a possible ACE to deny owner what he/she would */ /* induely get from administrator, group or world */ /* unless owner is administrator or group */ denials = const_cpu_to_le32(0); pdace = (ACCESS_DENIED_ACE*) &secattr[offs + pos]; if (!adminowns) { if (!groupowns) { if (isdir) { pdace->flags = DIR_INHERITANCE; if (mode & (S_IXGRP | S_IXOTH)) denials |= DIR_EXEC; if (mode & (S_IWGRP | S_IWOTH)) denials |= DIR_WRITE; if (mode & (S_IRGRP | S_IROTH)) denials |= DIR_READ; } else { pdace->flags = FILE_INHERITANCE; if (mode & (S_IXGRP | S_IXOTH)) denials |= FILE_EXEC; if (mode & (S_IWGRP | S_IWOTH)) denials |= FILE_WRITE; if (mode & (S_IRGRP | S_IROTH)) denials |= FILE_READ; } } else { if (isdir) { pdace->flags = DIR_INHERITANCE; if ((mode & S_IXOTH) && !(mode & S_IXGRP)) denials |= DIR_EXEC; if ((mode & S_IWOTH) && !(mode & S_IWGRP)) denials |= DIR_WRITE; if ((mode & S_IROTH) && !(mode & S_IRGRP)) denials |= DIR_READ; } else { pdace->flags = FILE_INHERITANCE; if ((mode & S_IXOTH) && !(mode & S_IXGRP)) denials |= FILE_EXEC; if ((mode & S_IWOTH) && !(mode & S_IWGRP)) denials |= FILE_WRITE; if ((mode & S_IROTH) && !(mode & S_IRGRP)) denials |= FILE_READ; } } denials &= ~grants; if (denials) { pdace->type = ACCESS_DENIED_ACE_TYPE; pdace->size = cpu_to_le16(usidsz + 8); pdace->mask = denials; memcpy((char*)&pdace->sid, usid, usidsz); pos += usidsz + 8; acecnt++; } } /* * for directories, a world execution denial * inherited to plain files */ if (isdir) { pdace = (ACCESS_DENIED_ACE*) &secattr[offs + pos]; pdace->type = ACCESS_DENIED_ACE_TYPE; pdace->flags = INHERIT_ONLY_ACE | OBJECT_INHERIT_ACE; pdace->size = cpu_to_le16(wsidsz + 8); pdace->mask = FILE_EXEC; memcpy((char*)&pdace->sid, worldsid, wsidsz); pos += wsidsz + 8; acecnt++; } /* now insert grants to owner */ pgace = (ACCESS_ALLOWED_ACE*) &secattr[offs + pos]; pgace->type = ACCESS_ALLOWED_ACE_TYPE; pgace->size = cpu_to_le16(usidsz + 8); pgace->flags = gflags; pgace->mask = grants; memcpy((char*)&pgace->sid, usid, usidsz); pos += usidsz + 8; acecnt++; /* a grant ACE for group */ /* unless group has the same rights as world */ /* but present if group is owner or owner is administrator */ /* this ACE will be inserted after denials for group */ if (adminowns || (((mode >> 3) ^ mode) & 7)) { grants = WORLD_RIGHTS; if (isdir) { gflags = DIR_INHERITANCE; if (mode & S_IXGRP) grants |= DIR_EXEC; if (mode & S_IWGRP) grants |= DIR_WRITE; if (mode & S_IRGRP) grants |= DIR_READ; } else { gflags = FILE_INHERITANCE; if (mode & S_IXGRP) grants |= FILE_EXEC; if (mode & S_IWGRP) grants |= FILE_WRITE; if (mode & S_IRGRP) grants |= FILE_READ; } /* a possible ACE to deny group what it would get from world */ /* or administrator, unless owner is administrator or group */ denials = const_cpu_to_le32(0); pdace = (ACCESS_ALLOWED_ACE*)&secattr[offs + pos]; if (!adminowns && !groupowns) { if (isdir) { pdace->flags = DIR_INHERITANCE; if (mode & S_IXOTH) denials |= DIR_EXEC; if (mode & S_IWOTH) denials |= DIR_WRITE; if (mode & S_IROTH) denials |= DIR_READ; } else { pdace->flags = FILE_INHERITANCE; if (mode & S_IXOTH) denials |= FILE_EXEC; if (mode & S_IWOTH) denials |= FILE_WRITE; if (mode & S_IROTH) denials |= FILE_READ; } denials &= ~(grants | OWNER_RIGHTS); if (denials) { pdace->type = ACCESS_DENIED_ACE_TYPE; pdace->size = cpu_to_le16(gsidsz + 8); pdace->mask = denials; memcpy((char*)&pdace->sid, gsid, gsidsz); pos += gsidsz + 8; acecnt++; } } if (adminowns || groupowns || ((mode >> 3) & ~mode & 7)) { /* now insert grants to group */ /* if more rights than other */ pgace = (ACCESS_ALLOWED_ACE*)&secattr[offs + pos]; pgace->type = ACCESS_ALLOWED_ACE_TYPE; pgace->flags = gflags; pgace->size = cpu_to_le16(gsidsz + 8); pgace->mask = grants; memcpy((char*)&pgace->sid, gsid, gsidsz); pos += gsidsz + 8; acecnt++; } } /* an ACE for world users */ pgace = (ACCESS_ALLOWED_ACE*)&secattr[offs + pos]; pgace->type = ACCESS_ALLOWED_ACE_TYPE; grants = WORLD_RIGHTS; if (isdir) { pgace->flags = DIR_INHERITANCE; if (mode & S_IXOTH) grants |= DIR_EXEC; if (mode & S_IWOTH) grants |= DIR_WRITE; if (mode & S_IROTH) grants |= DIR_READ; } else { pgace->flags = FILE_INHERITANCE; if (mode & S_IXOTH) grants |= FILE_EXEC; if (mode & S_IWOTH) grants |= FILE_WRITE; if (mode & S_IROTH) grants |= FILE_READ; } pgace->size = cpu_to_le16(wsidsz + 8); pgace->mask = grants; memcpy((char*)&pgace->sid, worldsid, wsidsz); pos += wsidsz + 8; acecnt++; /* an ACE for administrators */ /* always full access */ pgace = (ACCESS_ALLOWED_ACE*)&secattr[offs + pos]; pgace->type = ACCESS_ALLOWED_ACE_TYPE; if (isdir) pgace->flags = DIR_INHERITANCE; else pgace->flags = FILE_INHERITANCE; pgace->size = cpu_to_le16(asidsz + 8); grants = OWNER_RIGHTS | FILE_READ | FILE_WRITE | FILE_EXEC; pgace->mask = grants; memcpy((char*)&pgace->sid, adminsid, asidsz); pos += asidsz + 8; acecnt++; /* an ACE for system (needed ?) */ /* always full access */ pgace = (ACCESS_ALLOWED_ACE*)&secattr[offs + pos]; pgace->type = ACCESS_ALLOWED_ACE_TYPE; if (isdir) pgace->flags = DIR_INHERITANCE; else pgace->flags = FILE_INHERITANCE; pgace->size = cpu_to_le16(ssidsz + 8); grants = OWNER_RIGHTS | FILE_READ | FILE_WRITE | FILE_EXEC; pgace->mask = grants; memcpy((char*)&pgace->sid, systemsid, ssidsz); pos += ssidsz + 8; acecnt++; /* a null ACE to hold special flags */ /* using the same representation as cygwin */ if (mode & (S_ISVTX | S_ISGID | S_ISUID)) { nsidsz = ntfs_sid_size(nullsid); pgace = (ACCESS_ALLOWED_ACE*)&secattr[offs + pos]; pgace->type = ACCESS_ALLOWED_ACE_TYPE; pgace->flags = NO_PROPAGATE_INHERIT_ACE; pgace->size = cpu_to_le16(nsidsz + 8); grants = const_cpu_to_le32(0); if (mode & S_ISUID) grants |= FILE_APPEND_DATA; if (mode & S_ISGID) grants |= FILE_WRITE_DATA; if (mode & S_ISVTX) grants |= FILE_READ_DATA; pgace->mask = grants; memcpy((char*)&pgace->sid, nullsid, nsidsz); pos += nsidsz + 8; acecnt++; } /* fix ACL header */ pacl->size = cpu_to_le16(pos); pacl->ace_count = cpu_to_le16(acecnt); return (pos); } #if POSIXACLS /* * Build a full security descriptor from a Posix ACL * returns descriptor in allocated memory, must free() after use */ char *ntfs_build_descr_posix(struct MAPPING* const mapping[], struct POSIX_SECURITY *pxdesc, int isdir, const SID *usid, const SID *gsid) { int newattrsz; SECURITY_DESCRIPTOR_RELATIVE *pnhead; char *newattr; int aclsz; int usidsz; int gsidsz; int wsidsz; int asidsz; int ssidsz; int k; usidsz = ntfs_sid_size(usid); gsidsz = ntfs_sid_size(gsid); wsidsz = ntfs_sid_size(worldsid); asidsz = ntfs_sid_size(adminsid); ssidsz = ntfs_sid_size(systemsid); /* allocate enough space for the new security attribute */ newattrsz = sizeof(SECURITY_DESCRIPTOR_RELATIVE) /* header */ + usidsz + gsidsz /* usid and gsid */ + sizeof(ACL) /* acl header */ + 2*(8 + usidsz) /* two possible ACE for user */ + 3*(8 + gsidsz) /* three possible ACE for group and mask */ + 8 + wsidsz /* one ACE for world */ + 8 + asidsz /* one ACE for admin */ + 8 + ssidsz; /* one ACE for system */ if (isdir) /* a world denial for directories */ newattrsz += 8 + wsidsz; if (pxdesc->mode & 07000) /* a NULL ACE for special modes */ newattrsz += 8 + ntfs_sid_size(nullsid); /* account for non-owning users and groups */ for (k=0; kacccnt; k++) { if ((pxdesc->acl.ace[k].tag == POSIX_ACL_USER) || (pxdesc->acl.ace[k].tag == POSIX_ACL_GROUP)) newattrsz += 3*MAX_SID_SIZE; } /* account for default ACE's */ newattrsz += 2*MAX_SID_SIZE*pxdesc->defcnt; newattr = (char*)ntfs_malloc(newattrsz); if (newattr) { /* build the main header part */ pnhead = (SECURITY_DESCRIPTOR_RELATIVE*)newattr; pnhead->revision = SECURITY_DESCRIPTOR_REVISION; pnhead->alignment = 0; /* * The flag SE_DACL_PROTECTED prevents the ACL * to be changed in an inheritance after creation */ pnhead->control = SE_DACL_PRESENT | SE_DACL_PROTECTED | SE_SELF_RELATIVE; /* * Windows prefers ACL first, do the same to * get the same hash value and avoid duplication */ /* build permissions */ aclsz = buildacls_posix(mapping,newattr, sizeof(SECURITY_DESCRIPTOR_RELATIVE), pxdesc, isdir, usid, gsid); if (aclsz && ((int)(sizeof(SECURITY_DESCRIPTOR_RELATIVE) + aclsz + usidsz + gsidsz) <= newattrsz)) { /* append usid and gsid */ memcpy(&newattr[sizeof(SECURITY_DESCRIPTOR_RELATIVE) + aclsz], usid, usidsz); memcpy(&newattr[sizeof(SECURITY_DESCRIPTOR_RELATIVE) + aclsz + usidsz], gsid, gsidsz); /* positions of ACL, USID and GSID into header */ pnhead->owner = cpu_to_le32(sizeof(SECURITY_DESCRIPTOR_RELATIVE) + aclsz); pnhead->group = cpu_to_le32(sizeof(SECURITY_DESCRIPTOR_RELATIVE) + aclsz + usidsz); pnhead->sacl = const_cpu_to_le32(0); pnhead->dacl = const_cpu_to_le32(sizeof(SECURITY_DESCRIPTOR_RELATIVE)); } else { /* ACL failure (errno set) or overflow */ free(newattr); newattr = (char*)NULL; if (aclsz) { /* hope error was detected before overflowing */ ntfs_log_error("Security descriptor is longer than expected\n"); errno = EIO; } } } else errno = ENOMEM; return (newattr); } #endif /* POSIXACLS */ /* * Build a full security descriptor * returns descriptor in allocated memory, must free() after use */ char *ntfs_build_descr(mode_t mode, int isdir, const SID * usid, const SID * gsid) { int newattrsz; SECURITY_DESCRIPTOR_RELATIVE *pnhead; char *newattr; int aclsz; int usidsz; int gsidsz; int wsidsz; int asidsz; int ssidsz; usidsz = ntfs_sid_size(usid); gsidsz = ntfs_sid_size(gsid); wsidsz = ntfs_sid_size(worldsid); asidsz = ntfs_sid_size(adminsid); ssidsz = ntfs_sid_size(systemsid); /* allocate enough space for the new security attribute */ newattrsz = sizeof(SECURITY_DESCRIPTOR_RELATIVE) /* header */ + usidsz + gsidsz /* usid and gsid */ + sizeof(ACL) /* acl header */ + 2*(8 + usidsz) /* two possible ACE for user */ + 2*(8 + gsidsz) /* two possible ACE for group */ + 8 + wsidsz /* one ACE for world */ + 8 + asidsz /* one ACE for admin */ + 8 + ssidsz; /* one ACE for system */ if (isdir) /* a world denial for directories */ newattrsz += 8 + wsidsz; if (mode & 07000) /* a NULL ACE for special modes */ newattrsz += 8 + ntfs_sid_size(nullsid); newattr = (char*)ntfs_malloc(newattrsz); if (newattr) { /* build the main header part */ pnhead = (SECURITY_DESCRIPTOR_RELATIVE*) newattr; pnhead->revision = SECURITY_DESCRIPTOR_REVISION; pnhead->alignment = 0; /* * The flag SE_DACL_PROTECTED prevents the ACL * to be changed in an inheritance after creation */ pnhead->control = SE_DACL_PRESENT | SE_DACL_PROTECTED | SE_SELF_RELATIVE; /* * Windows prefers ACL first, do the same to * get the same hash value and avoid duplication */ /* build permissions */ aclsz = buildacls(newattr, sizeof(SECURITY_DESCRIPTOR_RELATIVE), mode, isdir, usid, gsid); if (((int)sizeof(SECURITY_DESCRIPTOR_RELATIVE) + aclsz + usidsz + gsidsz) <= newattrsz) { /* append usid and gsid */ memcpy(&newattr[sizeof(SECURITY_DESCRIPTOR_RELATIVE) + aclsz], usid, usidsz); memcpy(&newattr[sizeof(SECURITY_DESCRIPTOR_RELATIVE) + aclsz + usidsz], gsid, gsidsz); /* positions of ACL, USID and GSID into header */ pnhead->owner = cpu_to_le32(sizeof(SECURITY_DESCRIPTOR_RELATIVE) + aclsz); pnhead->group = cpu_to_le32(sizeof(SECURITY_DESCRIPTOR_RELATIVE) + aclsz + usidsz); pnhead->sacl = const_cpu_to_le32(0); pnhead->dacl = const_cpu_to_le32(sizeof(SECURITY_DESCRIPTOR_RELATIVE)); } else { /* hope error was detected before overflowing */ free(newattr); newattr = (char*)NULL; ntfs_log_error("Security descriptor is longer than expected\n"); errno = EIO; } } else errno = ENOMEM; return (newattr); } /* * Create a mode_t permission set * from owner, group and world grants as represented in ACEs */ static int merge_permissions(BOOL isdir, le32 owner, le32 group, le32 world, le32 special) { int perm; perm = 0; /* build owner permission */ if (owner) { if (isdir) { /* exec if any of list, traverse */ if (owner & DIR_GEXEC) perm |= S_IXUSR; /* write if any of addfile, adddir, delchild */ if (owner & DIR_GWRITE) perm |= S_IWUSR; /* read if any of list */ if (owner & DIR_GREAD) perm |= S_IRUSR; } else { /* exec if execute or generic execute */ if (owner & FILE_GEXEC) perm |= S_IXUSR; /* write if any of writedata or generic write */ if (owner & FILE_GWRITE) perm |= S_IWUSR; /* read if any of readdata or generic read */ if (owner & FILE_GREAD) perm |= S_IRUSR; } } /* build group permission */ if (group) { if (isdir) { /* exec if any of list, traverse */ if (group & DIR_GEXEC) perm |= S_IXGRP; /* write if any of addfile, adddir, delchild */ if (group & DIR_GWRITE) perm |= S_IWGRP; /* read if any of list */ if (group & DIR_GREAD) perm |= S_IRGRP; } else { /* exec if execute */ if (group & FILE_GEXEC) perm |= S_IXGRP; /* write if any of writedata, appenddata */ if (group & FILE_GWRITE) perm |= S_IWGRP; /* read if any of readdata */ if (group & FILE_GREAD) perm |= S_IRGRP; } } /* build world permission */ if (world) { if (isdir) { /* exec if any of list, traverse */ if (world & DIR_GEXEC) perm |= S_IXOTH; /* write if any of addfile, adddir, delchild */ if (world & DIR_GWRITE) perm |= S_IWOTH; /* read if any of list */ if (world & DIR_GREAD) perm |= S_IROTH; } else { /* exec if execute */ if (world & FILE_GEXEC) perm |= S_IXOTH; /* write if any of writedata, appenddata */ if (world & FILE_GWRITE) perm |= S_IWOTH; /* read if any of readdata */ if (world & FILE_GREAD) perm |= S_IROTH; } } /* build special permission flags */ if (special) { if (special & FILE_APPEND_DATA) perm |= S_ISUID; if (special & FILE_WRITE_DATA) perm |= S_ISGID; if (special & FILE_READ_DATA) perm |= S_ISVTX; } return (perm); } #if POSIXACLS /* * Normalize a Posix ACL either from a sorted raw set of * access ACEs or default ACEs * (standard case : different owner, group and administrator) */ static int norm_std_permissions_posix(struct POSIX_SECURITY *posix_desc, BOOL groupowns, int start, int count, int target) { int j,k; s32 id; u16 tag; u16 tagsset; struct POSIX_ACE *pxace; mode_t grantgrps; mode_t grantwrld; mode_t denywrld; mode_t allow; mode_t deny; mode_t perms; mode_t mode; mode = 0; tagsset = 0; /* * Determine what is granted to some group or world * Also get denials to world which are meant to prevent * execution flags to be inherited by plain files */ pxace = posix_desc->acl.ace; grantgrps = 0; grantwrld = 0; denywrld = 0; for (j=start; j<(start + count); j++) { if (pxace[j].perms & POSIX_PERM_DENIAL) { /* deny world exec unless for default */ if ((pxace[j].tag == POSIX_ACL_OTHER) && !start) denywrld = pxace[j].perms; } else { switch (pxace[j].tag) { case POSIX_ACL_GROUP_OBJ : grantgrps |= pxace[j].perms; break; case POSIX_ACL_GROUP : if (pxace[j].id) grantgrps |= pxace[j].perms; break; case POSIX_ACL_OTHER : grantwrld = pxace[j].perms; break; default : break; } } } /* * Collect groups of ACEs related to the same id * and determine what is granted and what is denied. * It is important the ACEs have been sorted */ j = start; k = target; while (j < (start + count)) { tag = pxace[j].tag; id = pxace[j].id; if (pxace[j].perms & POSIX_PERM_DENIAL) { deny = pxace[j].perms | denywrld; allow = 0; } else { deny = denywrld; allow = pxace[j].perms; } j++; while ((j < (start + count)) && (pxace[j].tag == tag) && (pxace[j].id == id)) { if (pxace[j].perms & POSIX_PERM_DENIAL) deny |= pxace[j].perms; else allow |= pxace[j].perms; j++; } /* * Build the permissions equivalent to grants and denials */ if (groupowns) { if (tag == POSIX_ACL_MASK) perms = ~deny; else perms = allow & ~deny; } else switch (tag) { case POSIX_ACL_USER_OBJ : perms = (allow | grantgrps | grantwrld) & ~deny; break; case POSIX_ACL_USER : if (id) perms = (allow | grantgrps | grantwrld) & ~deny; else perms = allow; break; case POSIX_ACL_GROUP_OBJ : perms = (allow | grantwrld) & ~deny; break; case POSIX_ACL_GROUP : if (id) perms = (allow | grantwrld) & ~deny; else perms = allow; break; case POSIX_ACL_MASK : perms = ~deny; break; default : perms = allow & ~deny; break; } /* * Store into a Posix ACE */ if (tag != POSIX_ACL_SPECIAL) { pxace[k].tag = tag; pxace[k].id = id; pxace[k].perms = perms & (POSIX_PERM_R | POSIX_PERM_W | POSIX_PERM_X); tagsset |= tag; k++; } switch (tag) { case POSIX_ACL_USER_OBJ : mode |= ((perms & 7) << 6); break; case POSIX_ACL_GROUP_OBJ : case POSIX_ACL_MASK : mode = (mode & 07707) | ((perms & 7) << 3); break; case POSIX_ACL_OTHER : mode |= perms & 7; break; case POSIX_ACL_SPECIAL : mode |= (perms & (S_ISVTX | S_ISUID | S_ISGID)); break; default : break; } } if (!start) { /* not satisfactory */ posix_desc->mode = mode; posix_desc->tagsset = tagsset; } return (k - target); } #endif /* POSIXACLS */ /* * Interpret an ACL and extract meaningful grants * (standard case : different owner, group and administrator) */ static int build_std_permissions(const char *securattr, const SID *usid, const SID *gsid, BOOL isdir) { const SECURITY_DESCRIPTOR_RELATIVE *phead; const ACL *pacl; const ACCESS_ALLOWED_ACE *pace; int offdacl; int offace; int acecnt; int nace; BOOL noown; le32 special; le32 allowown, allowgrp, allowall; le32 denyown, denygrp, denyall; phead = (const SECURITY_DESCRIPTOR_RELATIVE*)securattr; offdacl = le32_to_cpu(phead->dacl); pacl = (const ACL*)&securattr[offdacl]; special = const_cpu_to_le32(0); allowown = allowgrp = allowall = const_cpu_to_le32(0); denyown = denygrp = denyall = const_cpu_to_le32(0); noown = TRUE; if (offdacl) { acecnt = le16_to_cpu(pacl->ace_count); offace = offdacl + sizeof(ACL); } else { acecnt = 0; offace = 0; } for (nace = 0; nace < acecnt; nace++) { pace = (const ACCESS_ALLOWED_ACE*)&securattr[offace]; if (!(pace->flags & INHERIT_ONLY_ACE)) { if (ntfs_same_sid(usid, &pace->sid) || ntfs_same_sid(ownersid, &pace->sid)) { noown = FALSE; if (pace->type == ACCESS_ALLOWED_ACE_TYPE) allowown |= pace->mask; else if (pace->type == ACCESS_DENIED_ACE_TYPE) denyown |= pace->mask; } else if (ntfs_same_sid(gsid, &pace->sid) && !(pace->mask & WRITE_OWNER)) { if (pace->type == ACCESS_ALLOWED_ACE_TYPE) allowgrp |= pace->mask; else if (pace->type == ACCESS_DENIED_ACE_TYPE) denygrp |= pace->mask; } else if (is_world_sid((const SID*)&pace->sid)) { if (pace->type == ACCESS_ALLOWED_ACE_TYPE) allowall |= pace->mask; else if (pace->type == ACCESS_DENIED_ACE_TYPE) denyall |= pace->mask; } else if ((ntfs_same_sid((const SID*)&pace->sid,nullsid)) && (pace->type == ACCESS_ALLOWED_ACE_TYPE)) special |= pace->mask; } offace += le16_to_cpu(pace->size); } /* * No indication about owner's rights : grant basic rights * This happens for files created by Windows in directories * created by Linux and owned by root, because Windows * merges the admin ACEs */ if (noown) allowown = (FILE_READ_DATA | FILE_WRITE_DATA | FILE_EXECUTE); /* * Add to owner rights granted to group or world * unless denied personaly, and add to group rights * granted to world unless denied specifically */ allowown |= (allowgrp | allowall); allowgrp |= allowall; return (merge_permissions(isdir, allowown & ~(denyown | denyall), allowgrp & ~(denygrp | denyall), allowall & ~denyall, special)); } /* * Interpret an ACL and extract meaningful grants * (special case : owner and group are the same, * and not administrator) */ static int build_owngrp_permissions(const char *securattr, const SID *usid, BOOL isdir) { const SECURITY_DESCRIPTOR_RELATIVE *phead; const ACL *pacl; const ACCESS_ALLOWED_ACE *pace; int offdacl; int offace; int acecnt; int nace; le32 special; BOOL grppresent; BOOL ownpresent; le32 allowown, allowgrp, allowall; le32 denyown, denygrp, denyall; phead = (const SECURITY_DESCRIPTOR_RELATIVE*)securattr; offdacl = le32_to_cpu(phead->dacl); pacl = (const ACL*)&securattr[offdacl]; special = const_cpu_to_le32(0); allowown = allowgrp = allowall = const_cpu_to_le32(0); denyown = denygrp = denyall = const_cpu_to_le32(0); ownpresent = FALSE; grppresent = FALSE; if (offdacl) { acecnt = le16_to_cpu(pacl->ace_count); offace = offdacl + sizeof(ACL); } else { acecnt = 0; offace = 0; } for (nace = 0; nace < acecnt; nace++) { pace = (const ACCESS_ALLOWED_ACE*)&securattr[offace]; if (!(pace->flags & INHERIT_ONLY_ACE)) { if ((ntfs_same_sid(usid, &pace->sid) || ntfs_same_sid(ownersid, &pace->sid)) && (pace->mask & WRITE_OWNER)) { if (pace->type == ACCESS_ALLOWED_ACE_TYPE) { allowown |= pace->mask; ownpresent = TRUE; } } else if (ntfs_same_sid(usid, &pace->sid) && (!(pace->mask & WRITE_OWNER))) { if (pace->type == ACCESS_ALLOWED_ACE_TYPE) { allowgrp |= pace->mask; grppresent = TRUE; } } else if (is_world_sid((const SID*)&pace->sid)) { if (pace->type == ACCESS_ALLOWED_ACE_TYPE) allowall |= pace->mask; else if (pace->type == ACCESS_DENIED_ACE_TYPE) denyall |= pace->mask; } else if ((ntfs_same_sid((const SID*)&pace->sid,nullsid)) && (pace->type == ACCESS_ALLOWED_ACE_TYPE)) special |= pace->mask; } offace += le16_to_cpu(pace->size); } if (!ownpresent) allowown = allowall; if (!grppresent) allowgrp = allowall; return (merge_permissions(isdir, allowown & ~(denyown | denyall), allowgrp & ~(denygrp | denyall), allowall & ~denyall, special)); } #if POSIXACLS /* * Normalize a Posix ACL either from a sorted raw set of * access ACEs or default ACEs * (special case : owner or/and group is administrator) */ static int norm_ownadmin_permissions_posix(struct POSIX_SECURITY *posix_desc, int start, int count, int target) { int j,k; s32 id; u16 tag; u16 tagsset; struct POSIX_ACE *pxace; mode_t denywrld; mode_t allow; mode_t deny; mode_t perms; mode_t mode; mode = 0; pxace = posix_desc->acl.ace; tagsset = 0; denywrld = 0; /* * Get denials to world which are meant to prevent * execution flags to be inherited by plain files */ for (j=start; j<(start + count); j++) { if (pxace[j].perms & POSIX_PERM_DENIAL) { /* deny world exec not for default */ if ((pxace[j].tag == POSIX_ACL_OTHER) && !start) denywrld = pxace[j].perms; } } /* * Collect groups of ACEs related to the same id * and determine what is granted (denials are ignored) * It is important the ACEs have been sorted */ j = start; k = target; deny = 0; while (j < (start + count)) { allow = 0; tag = pxace[j].tag; id = pxace[j].id; if (tag == POSIX_ACL_MASK) { deny = pxace[j].perms; j++; while ((j < (start + count)) && (pxace[j].tag == POSIX_ACL_MASK)) j++; } else { if (!(pxace[j].perms & POSIX_PERM_DENIAL)) allow = pxace[j].perms; j++; while ((j < (start + count)) && (pxace[j].tag == tag) && (pxace[j].id == id)) { if (!(pxace[j].perms & POSIX_PERM_DENIAL)) allow |= pxace[j].perms; j++; } } /* * Store the grants into a Posix ACE */ if (tag == POSIX_ACL_MASK) perms = ~deny; else perms = allow & ~denywrld; if (tag != POSIX_ACL_SPECIAL) { pxace[k].tag = tag; pxace[k].id = id; pxace[k].perms = perms & (POSIX_PERM_R | POSIX_PERM_W | POSIX_PERM_X); tagsset |= tag; k++; } switch (tag) { case POSIX_ACL_USER_OBJ : mode |= ((perms & 7) << 6); break; case POSIX_ACL_GROUP_OBJ : case POSIX_ACL_MASK : mode = (mode & 07707) | ((perms & 7) << 3); break; case POSIX_ACL_OTHER : mode |= perms & 7; break; case POSIX_ACL_SPECIAL : mode |= perms & (S_ISVTX | S_ISUID | S_ISGID); break; default : break; } } if (!start) { /* not satisfactory */ posix_desc->mode = mode; posix_desc->tagsset = tagsset; } return (k - target); } #endif /* POSIXACLS */ /* * Interpret an ACL and extract meaningful grants * (special case : owner or/and group is administrator) */ static int build_ownadmin_permissions(const char *securattr, const SID *usid, const SID *gsid, BOOL isdir) { const SECURITY_DESCRIPTOR_RELATIVE *phead; const ACL *pacl; const ACCESS_ALLOWED_ACE *pace; int offdacl; int offace; int acecnt; int nace; BOOL firstapply; int isforeign; le32 special; le32 allowown, allowgrp, allowall; le32 denyown, denygrp, denyall; phead = (const SECURITY_DESCRIPTOR_RELATIVE*)securattr; offdacl = le32_to_cpu(phead->dacl); pacl = (const ACL*)&securattr[offdacl]; special = const_cpu_to_le32(0); allowown = allowgrp = allowall = const_cpu_to_le32(0); denyown = denygrp = denyall = const_cpu_to_le32(0); if (offdacl) { acecnt = le16_to_cpu(pacl->ace_count); offace = offdacl + sizeof(ACL); } else { acecnt = 0; offace = 0; } firstapply = TRUE; isforeign = 3; for (nace = 0; nace < acecnt; nace++) { pace = (const ACCESS_ALLOWED_ACE*)&securattr[offace]; if (!(pace->flags & INHERIT_ONLY_ACE) && !(~pace->mask & (ROOT_OWNER_UNMARK | ROOT_GROUP_UNMARK))) { if ((ntfs_same_sid(usid, &pace->sid) || ntfs_same_sid(ownersid, &pace->sid)) && (((pace->mask & WRITE_OWNER) && firstapply))) { if (pace->type == ACCESS_ALLOWED_ACE_TYPE) { allowown |= pace->mask; isforeign &= ~1; } else if (pace->type == ACCESS_DENIED_ACE_TYPE) denyown |= pace->mask; } else if (ntfs_same_sid(gsid, &pace->sid) && (!(pace->mask & WRITE_OWNER))) { if (pace->type == ACCESS_ALLOWED_ACE_TYPE) { allowgrp |= pace->mask; isforeign &= ~2; } else if (pace->type == ACCESS_DENIED_ACE_TYPE) denygrp |= pace->mask; } else if (is_world_sid((const SID*)&pace->sid)) { if (pace->type == ACCESS_ALLOWED_ACE_TYPE) allowall |= pace->mask; else if (pace->type == ACCESS_DENIED_ACE_TYPE) denyall |= pace->mask; } firstapply = FALSE; } else if (!(pace->flags & INHERIT_ONLY_ACE)) if ((ntfs_same_sid((const SID*)&pace->sid,nullsid)) && (pace->type == ACCESS_ALLOWED_ACE_TYPE)) special |= pace->mask; offace += le16_to_cpu(pace->size); } if (isforeign) { allowown |= (allowgrp | allowall); allowgrp |= allowall; } return (merge_permissions(isdir, allowown & ~(denyown | denyall), allowgrp & ~(denygrp | denyall), allowall & ~denyall, special)); } #if OWNERFROMACL /* * Define the owner of a file as the first user allowed * to change the owner, instead of the user defined as owner. * * This produces better approximations for files written by a * Windows user in an inheritable directory owned by another user, * as the access rights are inheritable but the ownership is not. * * An important case is the directories "Documents and Settings/user" * which the users must have access to, though Windows considers them * as owned by administrator. */ const SID *ntfs_acl_owner(const char *securattr) { const SECURITY_DESCRIPTOR_RELATIVE *phead; const SID *usid; const ACL *pacl; const ACCESS_ALLOWED_ACE *pace; int offdacl; int offace; int acecnt; int nace; BOOL found; found = FALSE; phead = (const SECURITY_DESCRIPTOR_RELATIVE*)securattr; offdacl = le32_to_cpu(phead->dacl); if (offdacl) { pacl = (const ACL*)&securattr[offdacl]; acecnt = le16_to_cpu(pacl->ace_count); offace = offdacl + sizeof(ACL); nace = 0; do { pace = (const ACCESS_ALLOWED_ACE*)&securattr[offace]; if ((pace->mask & WRITE_OWNER) && (pace->type == ACCESS_ALLOWED_ACE_TYPE) && ntfs_is_user_sid(&pace->sid)) found = TRUE; offace += le16_to_cpu(pace->size); } while (!found && (++nace < acecnt)); } if (found) usid = &pace->sid; else usid = (const SID*)&securattr[le32_to_cpu(phead->owner)]; return (usid); } #else /* * Special case for files owned by administrator with full * access granted to a mapped user : consider this user as the tenant * of the file. * * This situation cannot be represented with Linux concepts and can * only be found for files or directories created by Windows. * Typical situation : directory "Documents and Settings/user" which * is on the path to user's files and must be given access to user * only. * * Check file is owned by administrator and no user has rights before * calling. * Returns the uid of tenant or zero if none */ static uid_t find_tenant(struct MAPPING *const mapping[], const char *securattr) { const SECURITY_DESCRIPTOR_RELATIVE *phead; const ACL *pacl; const ACCESS_ALLOWED_ACE *pace; int offdacl; int offace; int acecnt; int nace; uid_t tid; uid_t xid; phead = (const SECURITY_DESCRIPTOR_RELATIVE*)securattr; offdacl = le32_to_cpu(phead->dacl); pacl = (const ACL*)&securattr[offdacl]; tid = 0; if (offdacl) { acecnt = le16_to_cpu(pacl->ace_count); offace = offdacl + sizeof(ACL); } else acecnt = 0; for (nace = 0; nace < acecnt; nace++) { pace = (const ACCESS_ALLOWED_ACE*)&securattr[offace]; if ((pace->type == ACCESS_ALLOWED_ACE_TYPE) && (pace->mask & DIR_WRITE)) { xid = ntfs_find_user(mapping[MAPUSERS], &pace->sid); if (xid) tid = xid; } offace += le16_to_cpu(pace->size); } return (tid); } #endif /* OWNERFROMACL */ #if POSIXACLS /* * Build Posix permissions from an ACL * returns a pointer to the requested permissions * or a null pointer (with errno set) if there is a problem * * If the NTFS ACL was created according to our rules, the retrieved * Posix ACL should be the exact ACL which was set. However if * the NTFS ACL was built by a different tool, the result could * be a a poor approximation of what was expected */ struct POSIX_SECURITY *ntfs_build_permissions_posix( struct MAPPING *const mapping[], const char *securattr, const SID *usid, const SID *gsid, BOOL isdir) { const SECURITY_DESCRIPTOR_RELATIVE *phead; struct POSIX_SECURITY *pxdesc; const ACL *pacl; const ACCESS_ALLOWED_ACE *pace; struct POSIX_ACE *pxace; struct { uid_t prevuid; gid_t prevgid; int groupmasks; s16 tagsset; BOOL gotowner; BOOL gotownermask; BOOL gotgroup; mode_t permswrld; } ctx[2], *pctx; int offdacl; int offace; int alloccnt; int acecnt; uid_t uid; gid_t gid; int i,j; int k,l; BOOL ignore; BOOL adminowns; BOOL groupowns; BOOL firstinh; BOOL genericinh; phead = (const SECURITY_DESCRIPTOR_RELATIVE*)securattr; offdacl = le32_to_cpu(phead->dacl); if (offdacl) { pacl = (const ACL*)&securattr[offdacl]; acecnt = le16_to_cpu(pacl->ace_count); offace = offdacl + sizeof(ACL); } else { acecnt = 0; offace = 0; } adminowns = FALSE; groupowns = ntfs_same_sid(gsid,usid); firstinh = FALSE; genericinh = FALSE; /* * Build a raw posix security descriptor * by just translating permissions and ids * * The worst case number of ACE entries consists of: * - 'acecount' ACE entries from the main loop (see below) * iterating over the 'securattr' array. * - 1 ACE entry which may be added when creating world * permissions if none exist. * - 1 ACE entry which may be added when setting basic owner * permissions if none exist (both lists). * - 1 ACE entry which may be added when duplicating world * permissions as group_obj permissions if none exist. * - 'acecount + 2' ACE entries which may be added when * duplicating world permissions as group permissions if they * were converted to masks and the masks are not followed by a * group entry. * - 1 ACE entry which may be added when inserting a default * mask if none is present and there are designated users or * groups. * * This amounts to 2*acecnt + 6 ACE entries in the worst case. */ alloccnt = 2*acecnt + 6; pxdesc = (struct POSIX_SECURITY*)malloc( sizeof(struct POSIX_SECURITY) + alloccnt*sizeof(struct POSIX_ACE)); if (!pxdesc) { ntfs_log_perror("Unable to allocate %zu bytes for " "POSIX_SECURITY structure", (size_t)(sizeof(struct POSIX_SECURITY) + alloccnt*sizeof(struct POSIX_ACE))); errno = ENOMEM; return NULL; } k = 0; l = alloccnt; for (i=0; i<2; i++) { pctx = &ctx[i]; pctx->permswrld = 0; pctx->prevuid = -1; pctx->prevgid = -1; pctx->groupmasks = 0; pctx->tagsset = 0; pctx->gotowner = FALSE; pctx->gotgroup = FALSE; pctx->gotownermask = FALSE; } for (j=0; jflags & INHERIT_ONLY_ACE) { pxace = &pxdesc->acl.ace[l - 1]; pctx = &ctx[1]; } else { pxace = &pxdesc->acl.ace[k]; pctx = &ctx[0]; } ignore = FALSE; /* * grants for root as a designated user or group */ if ((~pace->mask & (ROOT_OWNER_UNMARK | ROOT_GROUP_UNMARK)) && (pace->type == ACCESS_ALLOWED_ACE_TYPE) && ntfs_same_sid(&pace->sid, adminsid)) { pxace->tag = (pace->mask & ROOT_OWNER_UNMARK ? POSIX_ACL_GROUP : POSIX_ACL_USER); pxace->id = 0; if ((pace->mask & (GENERIC_ALL | WRITE_OWNER)) && (pace->flags & INHERIT_ONLY_ACE)) ignore = genericinh = TRUE; } else if (ntfs_same_sid(usid, &pace->sid)) { pxace->id = -1; /* * Owner has no write-owner right : * a group was defined same as owner * or admin was owner or group : * denials are meant to owner * and grants are meant to group */ if (!(pace->mask & (WRITE_OWNER | GENERIC_ALL)) && (pace->type == ACCESS_ALLOWED_ACE_TYPE)) { if (ntfs_same_sid(gsid,usid)) { pxace->tag = POSIX_ACL_GROUP_OBJ; pxace->id = -1; } else { if (ntfs_same_sid(&pace->sid,usid)) groupowns = TRUE; gid = ntfs_find_group(mapping[MAPGROUPS],&pace->sid); if (gid) { pxace->tag = POSIX_ACL_GROUP; pxace->id = gid; pctx->prevgid = gid; } else { uid = ntfs_find_user(mapping[MAPUSERS],&pace->sid); if (uid) { pxace->tag = POSIX_ACL_USER; pxace->id = uid; } else ignore = TRUE; } } } else { /* * when group owns, late denials for owner * mean group mask */ if ((pace->type == ACCESS_DENIED_ACE_TYPE) && (pace->mask & WRITE_OWNER)) { pxace->tag = POSIX_ACL_MASK; pctx->gotownermask = TRUE; if (pctx->gotowner) pctx->groupmasks++; } else { if (pace->type == ACCESS_ALLOWED_ACE_TYPE) pctx->gotowner = TRUE; if (pctx->gotownermask && !pctx->gotowner) { uid = ntfs_find_user(mapping[MAPUSERS],&pace->sid); pxace->id = uid; pxace->tag = POSIX_ACL_USER; } else pxace->tag = POSIX_ACL_USER_OBJ; /* system ignored, and admin */ /* ignored at first position */ if (pace->flags & INHERIT_ONLY_ACE) { if ((firstinh && ntfs_same_sid(&pace->sid,adminsid)) || ntfs_same_sid(&pace->sid,systemsid)) ignore = TRUE; if (!firstinh) { firstinh = TRUE; } } else { if ((adminowns && ntfs_same_sid(&pace->sid,adminsid)) || ntfs_same_sid(&pace->sid,systemsid)) ignore = TRUE; if (ntfs_same_sid(usid,adminsid)) adminowns = TRUE; } } } } else if (ntfs_same_sid(gsid, &pace->sid)) { if ((pace->type == ACCESS_DENIED_ACE_TYPE) && (pace->mask & WRITE_OWNER)) { pxace->tag = POSIX_ACL_MASK; pxace->id = -1; if (pctx->gotowner) pctx->groupmasks++; } else { if (pctx->gotgroup || (pctx->groupmasks > 1)) { gid = ntfs_find_group(mapping[MAPGROUPS],&pace->sid); if (gid) { pxace->id = gid; pxace->tag = POSIX_ACL_GROUP; pctx->prevgid = gid; } else ignore = TRUE; } else { pxace->id = -1; pxace->tag = POSIX_ACL_GROUP_OBJ; if (pace->type == ACCESS_ALLOWED_ACE_TYPE) pctx->gotgroup = TRUE; } if (ntfs_same_sid(gsid,adminsid) || ntfs_same_sid(gsid,systemsid)) { if (pace->mask & (WRITE_OWNER | GENERIC_ALL)) ignore = TRUE; if (ntfs_same_sid(gsid,adminsid)) adminowns = TRUE; else genericinh = ignore; } } } else if (is_world_sid((const SID*)&pace->sid)) { pxace->id = -1; pxace->tag = POSIX_ACL_OTHER; if ((pace->type == ACCESS_DENIED_ACE_TYPE) && (pace->flags & INHERIT_ONLY_ACE)) ignore = TRUE; } else if (ntfs_same_sid((const SID*)&pace->sid,nullsid)) { pxace->id = -1; pxace->tag = POSIX_ACL_SPECIAL; } else { uid = ntfs_find_user(mapping[MAPUSERS],&pace->sid); if (uid) { if ((pace->type == ACCESS_DENIED_ACE_TYPE) && (pace->mask & WRITE_OWNER) && (pctx->prevuid != uid)) { pxace->id = -1; pxace->tag = POSIX_ACL_MASK; } else { pxace->id = uid; pxace->tag = POSIX_ACL_USER; } pctx->prevuid = uid; } else { gid = ntfs_find_group(mapping[MAPGROUPS],&pace->sid); if (gid) { if ((pace->type == ACCESS_DENIED_ACE_TYPE) && (pace->mask & WRITE_OWNER) && (pctx->prevgid != gid)) { pxace->tag = POSIX_ACL_MASK; pctx->groupmasks++; } else { pxace->tag = POSIX_ACL_GROUP; } pxace->id = gid; pctx->prevgid = gid; } else { /* * do not grant rights to unknown * people and do not define root as a * designated user or group */ ignore = TRUE; } } } if (((pace->type == ACCESS_ALLOWED_ACE_TYPE) || (pace->type == ACCESS_DENIED_ACE_TYPE)) && !ignore) { pxace->perms = 0; /* specific decoding for vtx/uid/gid */ if (pxace->tag == POSIX_ACL_SPECIAL) { if (pace->mask & FILE_APPEND_DATA) pxace->perms |= S_ISUID; if (pace->mask & FILE_WRITE_DATA) pxace->perms |= S_ISGID; if (pace->mask & FILE_READ_DATA) pxace->perms |= S_ISVTX; } else if (isdir) { if (pace->mask & DIR_GEXEC) pxace->perms |= POSIX_PERM_X; if (pace->mask & DIR_GWRITE) pxace->perms |= POSIX_PERM_W; if (pace->mask & DIR_GREAD) pxace->perms |= POSIX_PERM_R; if ((pace->mask & GENERIC_ALL) && (pace->flags & INHERIT_ONLY_ACE)) pxace->perms |= POSIX_PERM_X | POSIX_PERM_W | POSIX_PERM_R; } else { if (pace->mask & FILE_GEXEC) pxace->perms |= POSIX_PERM_X; if (pace->mask & FILE_GWRITE) pxace->perms |= POSIX_PERM_W; if (pace->mask & FILE_GREAD) pxace->perms |= POSIX_PERM_R; } if (pace->type != ACCESS_ALLOWED_ACE_TYPE) pxace->perms |= POSIX_PERM_DENIAL; else if (pxace->tag == POSIX_ACL_OTHER) pctx->permswrld |= pxace->perms; pctx->tagsset |= pxace->tag; if (pace->flags & INHERIT_ONLY_ACE) { l--; } else { k++; } } offace += le16_to_cpu(pace->size); } /* * Create world perms if none (both lists) */ for (i=0; i<2; i++) if ((genericinh || !i) && !(ctx[i].tagsset & POSIX_ACL_OTHER)) { if (i) pxace = &pxdesc->acl.ace[--l]; else pxace = &pxdesc->acl.ace[k++]; pxace->tag = POSIX_ACL_OTHER; pxace->id = -1; pxace->perms = 0; ctx[i].tagsset |= POSIX_ACL_OTHER; ctx[i].permswrld = 0; } /* * Set basic owner perms if none (both lists) * This happens for files created by Windows in directories * created by Linux and owned by root, because Windows * merges the admin ACEs */ for (i=0; i<2; i++) if (!(ctx[i].tagsset & POSIX_ACL_USER_OBJ) && (ctx[i].tagsset & POSIX_ACL_OTHER)) { if (i) pxace = &pxdesc->acl.ace[--l]; else pxace = &pxdesc->acl.ace[k++]; pxace->tag = POSIX_ACL_USER_OBJ; pxace->id = -1; pxace->perms = POSIX_PERM_R | POSIX_PERM_W | POSIX_PERM_X; ctx[i].tagsset |= POSIX_ACL_USER_OBJ; } /* * Duplicate world perms as group_obj perms if none */ for (i=0; i<2; i++) if ((ctx[i].tagsset & POSIX_ACL_OTHER) && !(ctx[i].tagsset & POSIX_ACL_GROUP_OBJ)) { if (i) pxace = &pxdesc->acl.ace[--l]; else pxace = &pxdesc->acl.ace[k++]; pxace->tag = POSIX_ACL_GROUP_OBJ; pxace->id = -1; pxace->perms = ctx[i].permswrld; ctx[i].tagsset |= POSIX_ACL_GROUP_OBJ; } /* * Also duplicate world perms as group perms if they * were converted to mask and not followed by a group entry */ if (ctx[0].groupmasks) { for (j=k-2; j>=0; j--) { if ((pxdesc->acl.ace[j].tag == POSIX_ACL_MASK) && (pxdesc->acl.ace[j].id != -1) && ((pxdesc->acl.ace[j+1].tag != POSIX_ACL_GROUP) || (pxdesc->acl.ace[j+1].id != pxdesc->acl.ace[j].id))) { pxace = &pxdesc->acl.ace[k]; pxace->tag = POSIX_ACL_GROUP; pxace->id = pxdesc->acl.ace[j].id; pxace->perms = ctx[0].permswrld; ctx[0].tagsset |= POSIX_ACL_GROUP; k++; } if (pxdesc->acl.ace[j].tag == POSIX_ACL_MASK) pxdesc->acl.ace[j].id = -1; } } if (ctx[1].groupmasks) { for (j=l; j<(alloccnt-1); j++) { if ((pxdesc->acl.ace[j].tag == POSIX_ACL_MASK) && (pxdesc->acl.ace[j].id != -1) && ((pxdesc->acl.ace[j+1].tag != POSIX_ACL_GROUP) || (pxdesc->acl.ace[j+1].id != pxdesc->acl.ace[j].id))) { pxace = &pxdesc->acl.ace[l - 1]; pxace->tag = POSIX_ACL_GROUP; pxace->id = pxdesc->acl.ace[j].id; pxace->perms = ctx[1].permswrld; ctx[1].tagsset |= POSIX_ACL_GROUP; l--; } if (pxdesc->acl.ace[j].tag == POSIX_ACL_MASK) pxdesc->acl.ace[j].id = -1; } } /* * Insert default mask if none present and * there are designated users or groups * (the space for it has not beed used) */ for (i=0; i<2; i++) if ((ctx[i].tagsset & (POSIX_ACL_USER | POSIX_ACL_GROUP)) && !(ctx[i].tagsset & POSIX_ACL_MASK)) { if (i) pxace = &pxdesc->acl.ace[--l]; else pxace = &pxdesc->acl.ace[k++]; pxace->tag = POSIX_ACL_MASK; pxace->id = -1; pxace->perms = POSIX_PERM_DENIAL; ctx[i].tagsset |= POSIX_ACL_MASK; } if (k > l) { ntfs_log_error("Posix descriptor is longer than expected\n"); errno = EIO; free(pxdesc); pxdesc = (struct POSIX_SECURITY*)NULL; } else { pxdesc->acccnt = k; pxdesc->defcnt = alloccnt - l; pxdesc->firstdef = l; pxdesc->tagsset = ctx[0].tagsset; pxdesc->acl.version = POSIX_VERSION; pxdesc->acl.flags = 0; pxdesc->acl.filler = 0; ntfs_sort_posix(pxdesc); if (adminowns) { k = norm_ownadmin_permissions_posix(pxdesc, 0, pxdesc->acccnt, 0); pxdesc->acccnt = k; l = norm_ownadmin_permissions_posix(pxdesc, pxdesc->firstdef, pxdesc->defcnt, k); pxdesc->firstdef = k; pxdesc->defcnt = l; } else { k = norm_std_permissions_posix(pxdesc,groupowns, 0, pxdesc->acccnt, 0); pxdesc->acccnt = k; l = norm_std_permissions_posix(pxdesc,groupowns, pxdesc->firstdef, pxdesc->defcnt, k); pxdesc->firstdef = k; pxdesc->defcnt = l; } } if (pxdesc && !ntfs_valid_posix(pxdesc)) { ntfs_log_error("Invalid Posix descriptor built\n"); errno = EIO; free(pxdesc); pxdesc = (struct POSIX_SECURITY*)NULL; } return (pxdesc); } #endif /* POSIXACLS */ /* * Build unix-style (mode_t) permissions from an ACL * returns the requested permissions * or a negative result (with errno set) if there is a problem */ int ntfs_build_permissions(const char *securattr, const SID *usid, const SID *gsid, BOOL isdir) { int perm; BOOL adminowns; BOOL groupowns; adminowns = ntfs_same_sid(usid,adminsid) || ntfs_same_sid(gsid,adminsid); groupowns = !adminowns && ntfs_same_sid(gsid,usid); if (adminowns) perm = build_ownadmin_permissions(securattr, usid, gsid, isdir); else if (groupowns) perm = build_owngrp_permissions(securattr, usid, isdir); else perm = build_std_permissions(securattr, usid, gsid, isdir); return (perm); } /* * The following must be in some library... */ static unsigned long atoul(const char *p) { /* must be somewhere ! */ unsigned long v; v = 0; while ((*p >= '0') && (*p <= '9')) v = v * 10 + (*p++) - '0'; return (v); } /* * Build an internal representation of a SID * Returns a copy in allocated memory if it succeeds * The SID is checked to be a valid user one. */ static SID *encodesid(const char *sidstr) { SID *sid; int cnt; BIGSID bigsid; SID *bsid; u32 auth; const char *p; sid = (SID*) NULL; if (!strncmp(sidstr, "S-1-", 4)) { bsid = (SID*)&bigsid; bsid->revision = SID_REVISION; p = &sidstr[4]; auth = atoul(p); bsid->identifier_authority.high_part = const_cpu_to_be16(0); bsid->identifier_authority.low_part = cpu_to_be32(auth); cnt = 0; p = strchr(p, '-'); while (p && (cnt < 8)) { p++; auth = atoul(p); bsid->sub_authority[cnt] = cpu_to_le32(auth); p = strchr(p, '-'); cnt++; } bsid->sub_authority_count = cnt; if ((cnt > 0) && ntfs_valid_sid(bsid) && (ntfs_is_user_sid(bsid) || ntfs_known_group_sid(bsid))) { sid = (SID*) ntfs_malloc(4 * cnt + 8); if (sid) memcpy(sid, bsid, 4 * cnt + 8); } } return (sid); } /* * Get a single mapping item from buffer * * Always reads a full line, truncating long lines * Refills buffer when exhausted * Returns pointer to item, or NULL when there is no more */ static struct MAPLIST *getmappingitem(FILEREADER reader, void *fileid, off_t *poffs, char *buf, int *psrc, s64 *psize) { int src; int dst; char *q; char *pu; char *pg; int gotend; struct MAPLIST *item; src = *psrc; dst = 0; /* allocate and get a full line */ item = (struct MAPLIST*)ntfs_malloc(sizeof(struct MAPLIST)); if (item) { do { gotend = 0; while ((src < *psize) && (buf[src] != '\n')) { if (dst < LINESZ) item->maptext[dst++] = buf[src]; src++; } if (src >= *psize) { *poffs += *psize; *psize = reader(fileid, buf, (size_t)BUFSZ, *poffs); src = 0; } else { gotend = 1; src++; item->maptext[dst] = '\0'; dst = 0; } } while (*psize && ((item->maptext[0] == '#') || !gotend)); if (gotend) { pu = pg = (char*)NULL; /* decompose into uid, gid and sid */ item->uidstr = item->maptext; item->gidstr = strchr(item->uidstr, ':'); if (item->gidstr) { pu = item->gidstr++; item->sidstr = strchr(item->gidstr, ':'); if (item->sidstr) { pg = item->sidstr++; q = strchr(item->sidstr, ':'); if (q) *q = 0; } } if (pu && pg) *pu = *pg = '\0'; else { ntfs_log_early_error("Bad mapping item \"%s\"\n", item->maptext); free(item); item = (struct MAPLIST*)NULL; } } else { free(item); /* free unused item */ item = (struct MAPLIST*)NULL; } } *psrc = src; return (item); } /* * Read user mapping file and split into their attribute. * Parameters are kept as text in a chained list until logins * are converted to uid. * Returns the head of list, if any * * If an absolute path is provided, the mapping file is assumed * to be located in another mounted file system, and plain read() * are used to get its contents. * If a relative path is provided, the mapping file is assumed * to be located on the current file system, and internal IO * have to be used since we are still mounting and we have not * entered the fuse loop yet. */ struct MAPLIST *ntfs_read_mapping(FILEREADER reader, void *fileid) { char buf[BUFSZ]; struct MAPLIST *item; struct MAPLIST *firstitem; struct MAPLIST *lastitem; int src; off_t offs; s64 size; firstitem = (struct MAPLIST*)NULL; lastitem = (struct MAPLIST*)NULL; offs = 0; size = reader(fileid, buf, (size_t)BUFSZ, (off_t)0); if (size > 0) { src = 0; do { item = getmappingitem(reader, fileid, &offs, buf, &src, &size); if (item) { item->next = (struct MAPLIST*)NULL; if (lastitem) lastitem->next = item; else firstitem = item; lastitem = item; } } while (item); } return (firstitem); } /* * Free memory used to store the user mapping * The only purpose is to facilitate the detection of memory leaks */ void ntfs_free_mapping(struct MAPPING *mapping[]) { struct MAPPING *user; struct MAPPING *group; /* free user mappings */ while (mapping[MAPUSERS]) { user = mapping[MAPUSERS]; /* do not free SIDs used for group mappings */ group = mapping[MAPGROUPS]; while (group && (group->sid != user->sid)) group = group->next; if (!group) free(user->sid); /* free group list if any */ if (user->grcnt) free(user->groups); /* unchain item and free */ mapping[MAPUSERS] = user->next; free(user); } /* free group mappings */ while (mapping[MAPGROUPS]) { group = mapping[MAPGROUPS]; free(group->sid); /* unchain item and free */ mapping[MAPGROUPS] = group->next; free(group); } } /* * Build the user mapping list * user identification may be given in symbolic or numeric format * * ! Note ! : does getpwnam() read /etc/passwd or some other file ? * if so there is a possible recursion into fuse if this * file is on NTFS, and fuse is not recursion safe. */ struct MAPPING *ntfs_do_user_mapping(struct MAPLIST *firstitem) { struct MAPLIST *item; struct MAPPING *firstmapping; struct MAPPING *lastmapping; struct MAPPING *mapping; struct passwd *pwd; SID *sid; int uid; firstmapping = (struct MAPPING*)NULL; lastmapping = (struct MAPPING*)NULL; for (item = firstitem; item; item = item->next) { if ((item->uidstr[0] >= '0') && (item->uidstr[0] <= '9')) uid = atoi(item->uidstr); else { uid = 0; if (item->uidstr[0]) { pwd = getpwnam(item->uidstr); if (pwd) uid = pwd->pw_uid; else ntfs_log_early_error("Invalid user \"%s\"\n", item->uidstr); } } /* * Records with no uid and no gid are inserted * to define the implicit mapping pattern */ if (uid || (!item->uidstr[0] && !item->gidstr[0])) { sid = encodesid(item->sidstr); if (sid && ntfs_known_group_sid(sid)) { ntfs_log_error("Bad user SID %s\n", item->sidstr); free(sid); sid = (SID*)NULL; } if (sid && !item->uidstr[0] && !item->gidstr[0] && !ntfs_valid_pattern(sid)) { ntfs_log_error("Bad implicit SID pattern %s\n", item->sidstr); sid = (SID*)NULL; } if (sid) { mapping = (struct MAPPING*) ntfs_malloc(sizeof(struct MAPPING)); if (mapping) { mapping->sid = sid; mapping->xid = uid; mapping->grcnt = 0; mapping->next = (struct MAPPING*)NULL; if (lastmapping) lastmapping->next = mapping; else firstmapping = mapping; lastmapping = mapping; } } } } return (firstmapping); } /* * Build the group mapping list * group identification may be given in symbolic or numeric format * * gid not associated to a uid are processed first in order * to favour real groups * * ! Note ! : does getgrnam() read /etc/group or some other file ? * if so there is a possible recursion into fuse if this * file is on NTFS, and fuse is not recursion safe. */ struct MAPPING *ntfs_do_group_mapping(struct MAPLIST *firstitem) { struct MAPLIST *item; struct MAPPING *firstmapping; struct MAPPING *lastmapping; struct MAPPING *mapping; struct group *grp; BOOL secondstep; BOOL ok; int step; SID *sid; int gid; firstmapping = (struct MAPPING*)NULL; lastmapping = (struct MAPPING*)NULL; for (step=1; step<=2; step++) { for (item = firstitem; item; item = item->next) { secondstep = (item->uidstr[0] != '\0') || !item->gidstr[0]; ok = (step == 1 ? !secondstep : secondstep); if ((item->gidstr[0] >= '0') && (item->gidstr[0] <= '9')) gid = atoi(item->gidstr); else { gid = 0; if (item->gidstr[0]) { grp = getgrnam(item->gidstr); if (grp) gid = grp->gr_gid; else ntfs_log_early_error("Invalid group \"%s\"\n", item->gidstr); } } /* * Records with no uid and no gid are inserted in the * second step to define the implicit mapping pattern */ if (ok && (gid || (!item->uidstr[0] && !item->gidstr[0]))) { sid = encodesid(item->sidstr); if (sid && !item->uidstr[0] && !item->gidstr[0] && !ntfs_valid_pattern(sid)) { /* error already logged */ sid = (SID*)NULL; } if (sid) { mapping = (struct MAPPING*) ntfs_malloc(sizeof(struct MAPPING)); if (mapping) { mapping->sid = sid; mapping->xid = gid; /* special groups point to themselves */ if (ntfs_known_group_sid(sid)) { mapping->groups = (gid_t*)&mapping->xid; mapping->grcnt = 1; } else mapping->grcnt = 0; mapping->next = (struct MAPPING*)NULL; if (lastmapping) lastmapping->next = mapping; else firstmapping = mapping; lastmapping = mapping; } } } } } return (firstmapping); } ntfs-3g-2026.2.25/libntfs-3g/logging.c0000664000175000017500000004150215152260173012544 /** * logging.c - Centralised logging. Originated from the Linux-NTFS project. * * Copyright (c) 2005 Richard Russon * Copyright (c) 2005-2008 Szabolcs Szakacsits * Copyright (c) 2010 Jean-Pierre Andre * * This program/include file 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/include file 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_STDIO_H #include #endif #ifdef HAVE_ERRNO_H #include #endif #ifdef HAVE_STDARG_H #include #endif #ifdef HAVE_STRING_H #include #endif #ifdef HAVE_STDLIB_H #include #endif #ifdef HAVE_SYSLOG_H #include #endif #include "logging.h" #include "misc.h" #ifndef PATH_SEP #define PATH_SEP '/' #endif #ifdef DEBUG static int tab; #endif /* Some gcc 3.x, 4.[01].X crash with internal compiler error. */ #if __GNUC__ <= 3 || (__GNUC__ == 4 && __GNUC_MINOR__ <= 1) # define BROKEN_GCC_FORMAT_ATTRIBUTE #else # define BROKEN_GCC_FORMAT_ATTRIBUTE __attribute__((format(printf, 6, 0))) #endif /** * struct ntfs_logging - Control info for the logging system * @levels: Bitfield of logging levels * @flags: Flags which affect the output style * @handler: Function to perform the actual logging */ struct ntfs_logging { u32 levels; u32 flags; ntfs_log_handler *handler BROKEN_GCC_FORMAT_ATTRIBUTE; }; /** * ntfs_log * This struct controls all the logging within the library and tools. */ static struct ntfs_logging ntfs_log = { #ifdef DEBUG NTFS_LOG_LEVEL_DEBUG | NTFS_LOG_LEVEL_TRACE | NTFS_LOG_LEVEL_ENTER | NTFS_LOG_LEVEL_LEAVE | #endif NTFS_LOG_LEVEL_INFO | NTFS_LOG_LEVEL_QUIET | NTFS_LOG_LEVEL_WARNING | NTFS_LOG_LEVEL_ERROR | NTFS_LOG_LEVEL_PERROR | NTFS_LOG_LEVEL_CRITICAL | NTFS_LOG_LEVEL_PROGRESS, NTFS_LOG_FLAG_ONLYNAME, #ifdef DEBUG ntfs_log_handler_outerr #else ntfs_log_handler_null #endif }; /** * ntfs_log_get_levels - Get a list of the current logging levels * * Find out which logging levels are enabled. * * Returns: Log levels in a 32-bit field */ u32 ntfs_log_get_levels(void) { return ntfs_log.levels; } /** * ntfs_log_set_levels - Enable extra logging levels * @levels: 32-bit field of log levels to set * * Enable one or more logging levels. * The logging levels are named: NTFS_LOG_LEVEL_*. * * Returns: Log levels that were enabled before the call */ u32 ntfs_log_set_levels(u32 levels) { u32 old; old = ntfs_log.levels; ntfs_log.levels |= levels; return old; } /** * ntfs_log_clear_levels - Disable some logging levels * @levels: 32-bit field of log levels to clear * * Disable one or more logging levels. * The logging levels are named: NTFS_LOG_LEVEL_*. * * Returns: Log levels that were enabled before the call */ u32 ntfs_log_clear_levels(u32 levels) { u32 old; old = ntfs_log.levels; ntfs_log.levels &= (~levels); return old; } /** * ntfs_log_get_flags - Get a list of logging style flags * * Find out which logging flags are enabled. * * Returns: Logging flags in a 32-bit field */ u32 ntfs_log_get_flags(void) { return ntfs_log.flags; } /** * ntfs_log_set_flags - Enable extra logging style flags * @flags: 32-bit field of logging flags to set * * Enable one or more logging flags. * The log flags are named: NTFS_LOG_LEVEL_*. * * Returns: Logging flags that were enabled before the call */ u32 ntfs_log_set_flags(u32 flags) { u32 old; old = ntfs_log.flags; ntfs_log.flags |= flags; return old; } /** * ntfs_log_clear_flags - Disable some logging styles * @flags: 32-bit field of logging flags to clear * * Disable one or more logging flags. * The log flags are named: NTFS_LOG_LEVEL_*. * * Returns: Logging flags that were enabled before the call */ u32 ntfs_log_clear_flags(u32 flags) { u32 old; old = ntfs_log.flags; ntfs_log.flags &= (~flags); return old; } /** * ntfs_log_get_stream - Default output streams for logging levels * @level: Log level * * By default, urgent messages are sent to "stderr". * Other messages are sent to "stdout". * * Returns: "string" Prefix to be used */ static FILE * ntfs_log_get_stream(u32 level) { FILE *stream; switch (level) { case NTFS_LOG_LEVEL_INFO: case NTFS_LOG_LEVEL_QUIET: case NTFS_LOG_LEVEL_PROGRESS: case NTFS_LOG_LEVEL_VERBOSE: stream = stdout; break; case NTFS_LOG_LEVEL_DEBUG: case NTFS_LOG_LEVEL_TRACE: case NTFS_LOG_LEVEL_ENTER: case NTFS_LOG_LEVEL_LEAVE: case NTFS_LOG_LEVEL_WARNING: case NTFS_LOG_LEVEL_ERROR: case NTFS_LOG_LEVEL_CRITICAL: case NTFS_LOG_LEVEL_PERROR: default: stream = stderr; break; } return stream; } /** * ntfs_log_get_prefix - Default prefixes for logging levels * @level: Log level to be prefixed * * Prefixing the logging output can make it easier to parse. * * Returns: "string" Prefix to be used */ static const char * ntfs_log_get_prefix(u32 level) { const char *prefix; switch (level) { case NTFS_LOG_LEVEL_DEBUG: prefix = "DEBUG: "; break; case NTFS_LOG_LEVEL_TRACE: prefix = "TRACE: "; break; case NTFS_LOG_LEVEL_QUIET: prefix = "QUIET: "; break; case NTFS_LOG_LEVEL_INFO: prefix = "INFO: "; break; case NTFS_LOG_LEVEL_VERBOSE: prefix = "VERBOSE: "; break; case NTFS_LOG_LEVEL_PROGRESS: prefix = "PROGRESS: "; break; case NTFS_LOG_LEVEL_WARNING: prefix = "WARNING: "; break; case NTFS_LOG_LEVEL_ERROR: prefix = "ERROR: "; break; case NTFS_LOG_LEVEL_PERROR: prefix = "ERROR: "; break; case NTFS_LOG_LEVEL_CRITICAL: prefix = "CRITICAL: "; break; default: prefix = ""; break; } return prefix; } /** * ntfs_log_set_handler - Provide an alternate logging handler * @handler: function to perform the logging * * This alternate handler will be called for all future logging requests. * If no @handler is specified, logging will revert to the default handler. */ void ntfs_log_set_handler(ntfs_log_handler *handler) { if (handler) { ntfs_log.handler = handler; #ifdef HAVE_SYSLOG_H if (handler == ntfs_log_handler_syslog) openlog("ntfs-3g", LOG_PID, LOG_USER); #endif } else ntfs_log.handler = ntfs_log_handler_null; } /** * ntfs_log_redirect - Pass on the request to the real handler * @function: Function in which the log line occurred * @file: File in which the log line occurred * @line: Line number on which the log line occurred * @level: Level at which the line is logged * @data: User specified data, possibly specific to a handler * @format: printf-style formatting string * @...: Arguments to be formatted * * This is just a redirector function. The arguments are simply passed to the * main logging handler (as defined in the global logging struct @ntfs_log). * * Returns: -1 Error occurred * 0 Message wasn't logged * num Number of output characters */ int ntfs_log_redirect(const char *function, const char *file, int line, u32 level, void *data, const char *format, ...) { int olderr = errno; int ret; va_list args; if (!(ntfs_log.levels & level)) /* Don't log this message */ return 0; va_start(args, format); errno = olderr; ret = ntfs_log.handler(function, file, line, level, data, format, args); va_end(args); errno = olderr; return ret; } /** * ntfs_log_handler_syslog - syslog logging handler * @function: Function in which the log line occurred * @file: File in which the log line occurred * @line: Line number on which the log line occurred * @level: Level at which the line is logged * @data: User specified data, possibly specific to a handler * @format: printf-style formatting string * @args: Arguments to be formatted * * A simple syslog logging handler. Ignores colors. * * Returns: -1 Error occurred * 0 Message wasn't logged * num Number of output characters */ #ifdef HAVE_SYSLOG_H #define LOG_LINE_LEN 512 int ntfs_log_handler_syslog(const char *function __attribute__((unused)), const char *file __attribute__((unused)), int line __attribute__((unused)), u32 level, void *data __attribute__((unused)), const char *format, va_list args) { char logbuf[LOG_LINE_LEN]; int ret, olderr = errno; #ifndef DEBUG if ((level & NTFS_LOG_LEVEL_PERROR) && errno == ENOSPC) return 1; #endif ret = vsnprintf(logbuf, LOG_LINE_LEN, format, args); if (ret < 0) { vsyslog(LOG_NOTICE, format, args); ret = 1; goto out; } if ((LOG_LINE_LEN > ret + 3) && (level & NTFS_LOG_LEVEL_PERROR)) { strncat(logbuf, ": ", LOG_LINE_LEN - ret - 1); strncat(logbuf, strerror(olderr), LOG_LINE_LEN - (ret + 3)); ret = strlen(logbuf); } syslog(LOG_NOTICE, "%s", logbuf); out: errno = olderr; return ret; } #endif /* * Early logging before the logs are redirected * * (not quite satisfactory : this appears before the ntfs-g banner, * and with a different pid) */ void ntfs_log_early_error(const char *format, ...) { va_list args; va_start(args, format); #ifdef HAVE_SYSLOG_H openlog("ntfs-3g", LOG_PID, LOG_USER); ntfs_log_handler_syslog(NULL, NULL, 0, NTFS_LOG_LEVEL_ERROR, NULL, format, args); #else vfprintf(stderr,format,args); #endif va_end(args); } /** * ntfs_log_handler_fprintf - Basic logging handler * @function: Function in which the log line occurred * @file: File in which the log line occurred * @line: Line number on which the log line occurred * @level: Level at which the line is logged * @data: User specified data, possibly specific to a handler * @format: printf-style formatting string * @args: Arguments to be formatted * * A simple logging handler. This is where the log line is finally displayed. * It is more likely that you will want to set the handler to either * ntfs_log_handler_outerr or ntfs_log_handler_stderr. * * Note: For this handler, @data is a pointer to a FILE output stream. * If @data is NULL, nothing will be displayed. * * Returns: -1 Error occurred * 0 Message wasn't logged * num Number of output characters */ int ntfs_log_handler_fprintf(const char *function, const char *file, int line, u32 level, void *data, const char *format, va_list args) { #ifdef DEBUG int i; #endif int ret = 0; int olderr = errno; FILE *stream; if (!data) /* Interpret data as a FILE stream. */ return 0; /* If it's NULL, we can't do anything. */ stream = (FILE*)data; #ifdef DEBUG if (level == NTFS_LOG_LEVEL_LEAVE) { if (tab) tab--; return 0; } for (i = 0; i < tab; i++) ret += fprintf(stream, " "); #endif if ((ntfs_log.flags & NTFS_LOG_FLAG_ONLYNAME) && (strchr(file, PATH_SEP))) /* Abbreviate the filename */ file = strrchr(file, PATH_SEP) + 1; if (ntfs_log.flags & NTFS_LOG_FLAG_PREFIX) /* Prefix the output */ ret += fprintf(stream, "%s", ntfs_log_get_prefix(level)); if (ntfs_log.flags & NTFS_LOG_FLAG_FILENAME) /* Source filename */ ret += fprintf(stream, "%s ", file); if (ntfs_log.flags & NTFS_LOG_FLAG_LINE) /* Source line number */ ret += fprintf(stream, "(%d) ", line); if ((ntfs_log.flags & NTFS_LOG_FLAG_FUNCTION) || /* Source function */ (level & NTFS_LOG_LEVEL_TRACE) || (level & NTFS_LOG_LEVEL_ENTER)) ret += fprintf(stream, "%s(): ", function); ret += vfprintf(stream, format, args); if (level & NTFS_LOG_LEVEL_PERROR) ret += fprintf(stream, ": %s\n", strerror(olderr)); #ifdef DEBUG if (level == NTFS_LOG_LEVEL_ENTER) tab++; #endif fflush(stream); errno = olderr; return ret; } /** * ntfs_log_handler_null - Null logging handler (no output) * @function: Function in which the log line occurred * @file: File in which the log line occurred * @line: Line number on which the log line occurred * @level: Level at which the line is logged * @data: User specified data, possibly specific to a handler * @format: printf-style formatting string * @args: Arguments to be formatted * * This handler produces no output. It provides a way to temporarily disable * logging, without having to change the levels and flags. * * Returns: 0 Message wasn't logged */ int ntfs_log_handler_null(const char *function __attribute__((unused)), const char *file __attribute__((unused)), int line __attribute__((unused)), u32 level __attribute__((unused)), void *data __attribute__((unused)), const char *format __attribute__((unused)), va_list args __attribute__((unused))) { return 0; } /** * ntfs_log_handler_stdout - All logs go to stdout * @function: Function in which the log line occurred * @file: File in which the log line occurred * @line: Line number on which the log line occurred * @level: Level at which the line is logged * @data: User specified data, possibly specific to a handler * @format: printf-style formatting string * @args: Arguments to be formatted * * Display a log message to stdout. * * Note: For this handler, @data is a pointer to a FILE output stream. * If @data is NULL, then stdout will be used. * * Note: This function calls ntfs_log_handler_fprintf to do the main work. * * Returns: -1 Error occurred * 0 Message wasn't logged * num Number of output characters */ int ntfs_log_handler_stdout(const char *function, const char *file, int line, u32 level, void *data, const char *format, va_list args) { if (!data) data = stdout; return ntfs_log_handler_fprintf(function, file, line, level, data, format, args); } /** * ntfs_log_handler_outerr - Logs go to stdout/stderr depending on level * @function: Function in which the log line occurred * @file: File in which the log line occurred * @line: Line number on which the log line occurred * @level: Level at which the line is logged * @data: User specified data, possibly specific to a handler * @format: printf-style formatting string * @args: Arguments to be formatted * * Display a log message. The output stream will be determined by the log * level. * * Note: For this handler, @data is a pointer to a FILE output stream. * If @data is NULL, the function ntfs_log_get_stream will be called * * Note: This function calls ntfs_log_handler_fprintf to do the main work. * * Returns: -1 Error occurred * 0 Message wasn't logged * num Number of output characters */ int ntfs_log_handler_outerr(const char *function, const char *file, int line, u32 level, void *data, const char *format, va_list args) { if (!data) data = ntfs_log_get_stream(level); return ntfs_log_handler_fprintf(function, file, line, level, data, format, args); } /** * ntfs_log_handler_stderr - All logs go to stderr * @function: Function in which the log line occurred * @file: File in which the log line occurred * @line: Line number on which the log line occurred * @level: Level at which the line is logged * @data: User specified data, possibly specific to a handler * @format: printf-style formatting string * @args: Arguments to be formatted * * Display a log message to stderr. * * Note: For this handler, @data is a pointer to a FILE output stream. * If @data is NULL, then stdout will be used. * * Note: This function calls ntfs_log_handler_fprintf to do the main work. * * Returns: -1 Error occurred * 0 Message wasn't logged * num Number of output characters */ int ntfs_log_handler_stderr(const char *function, const char *file, int line, u32 level, void *data, const char *format, va_list args) { if (!data) data = stderr; return ntfs_log_handler_fprintf(function, file, line, level, data, format, args); } /** * ntfs_log_parse_option - Act upon command line options * @option: Option flag * * Delegate some of the work of parsing the command line. All the options begin * with "--log-". Options cause log levels to be enabled in @ntfs_log (the * global logging structure). * * Note: The "colour" option changes the logging handler. * * Returns: TRUE Option understood * FALSE Invalid log option */ BOOL ntfs_log_parse_option(const char *option) { if (strcmp(option, "--log-debug") == 0) { ntfs_log_set_levels(NTFS_LOG_LEVEL_DEBUG); return TRUE; } else if (strcmp(option, "--log-verbose") == 0) { ntfs_log_set_levels(NTFS_LOG_LEVEL_VERBOSE); return TRUE; } else if (strcmp(option, "--log-quiet") == 0) { ntfs_log_clear_levels(NTFS_LOG_LEVEL_QUIET); return TRUE; } else if (strcmp(option, "--log-trace") == 0) { ntfs_log_set_levels(NTFS_LOG_LEVEL_TRACE); return TRUE; } ntfs_log_debug("Unknown logging option '%s'\n", option); return FALSE; } ntfs-3g-2026.2.25/libntfs-3g/object_id.c0000664000175000017500000004041715152260173013044 /** * object_id.c - Processing of object ids * * This module is part of ntfs-3g library * * Copyright (c) 2009-2019 Jean-Pierre Andre * * This program/include file 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/include file 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_STDLIB_H #include #endif #ifdef HAVE_ERRNO_H #include #endif #ifdef HAVE_STRING_H #include #endif #ifdef HAVE_SYS_STAT_H #include #endif #ifdef HAVE_SYS_SYSMACROS_H #include #endif #include "compat.h" #include "types.h" #include "debug.h" #include "attrib.h" #include "inode.h" #include "dir.h" #include "volume.h" #include "mft.h" #include "index.h" #include "lcnalloc.h" #include "object_id.h" #include "logging.h" #include "misc.h" #include "xattrs.h" /* * Endianness considerations * * According to RFC 4122, GUIDs should be printed with the most * significant byte first, and the six fields be compared individually * for ordering. RFC 4122 does not define the internal representation. * * Windows apparently stores the first three fields in little endian * order, and the last two fields in big endian order. * * Here we always copy disk images with no endianness change, * and, for indexing, GUIDs are compared as if they were a sequence * of four little-endian unsigned 32 bit integers (as Windows * does it that way.) * * --------------------- begin from RFC 4122 ---------------------- * Consider each field of the UUID to be an unsigned integer as shown * in the table in section Section 4.1.2. Then, to compare a pair of * UUIDs, arithmetically compare the corresponding fields from each * UUID in order of significance and according to their data type. * Two UUIDs are equal if and only if all the corresponding fields * are equal. * * UUIDs, as defined in this document, can also be ordered * lexicographically. For a pair of UUIDs, the first one follows the * second if the most significant field in which the UUIDs differ is * greater for the first UUID. The second precedes the first if the * most significant field in which the UUIDs differ is greater for * the second UUID. * * The fields are encoded as 16 octets, with the sizes and order of the * fields defined above, and with each field encoded with the Most * Significant Byte first (known as network byte order). Note that the * field names, particularly for multiplexed fields, follow historical * practice. * * 0 1 2 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | time_low | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | time_mid | time_hi_and_version | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * |clk_seq_hi_res | clk_seq_low | node (0-1) | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | node (2-5) | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * * ---------------------- end from RFC 4122 ----------------------- */ typedef struct { union { /* alignment may be needed to evaluate collations */ u32 alignment; GUID guid; } object_id; } OBJECT_ID_INDEX_KEY; typedef struct { le64 file_id; GUID birth_volume_id; GUID birth_object_id; GUID domain_id; } OBJECT_ID_INDEX_DATA; // known as OBJ_ID_INDEX_DATA struct OBJECT_ID_INDEX { /* index entry in $Extend/$ObjId */ INDEX_ENTRY_HEADER header; OBJECT_ID_INDEX_KEY key; OBJECT_ID_INDEX_DATA data; } ; static ntfschar objid_index_name[] = { const_cpu_to_le16('$'), const_cpu_to_le16('O') }; /* * Set the index for a new object id * * Returns 0 if success * -1 if failure, explained by errno */ static int set_object_id_index(ntfs_inode *ni, ntfs_index_context *xo, const OBJECT_ID_ATTR *object_id) { struct OBJECT_ID_INDEX indx; u64 file_id_cpu; le64 file_id; le16 seqn; seqn = ni->mrec->sequence_number; file_id_cpu = MK_MREF(ni->mft_no,le16_to_cpu(seqn)); file_id = cpu_to_le64(file_id_cpu); indx.header.data_offset = const_cpu_to_le16( sizeof(INDEX_ENTRY_HEADER) + sizeof(OBJECT_ID_INDEX_KEY)); indx.header.data_length = const_cpu_to_le16( sizeof(OBJECT_ID_INDEX_DATA)); indx.header.reservedV = const_cpu_to_le32(0); indx.header.length = const_cpu_to_le16( sizeof(struct OBJECT_ID_INDEX)); indx.header.key_length = const_cpu_to_le16( sizeof(OBJECT_ID_INDEX_KEY)); indx.header.flags = const_cpu_to_le16(0); indx.header.reserved = const_cpu_to_le16(0); memcpy(&indx.key.object_id,object_id,sizeof(GUID)); indx.data.file_id = file_id; memcpy(&indx.data.birth_volume_id, &object_id->birth_volume_id,sizeof(GUID)); memcpy(&indx.data.birth_object_id, &object_id->birth_object_id,sizeof(GUID)); memcpy(&indx.data.domain_id, &object_id->domain_id,sizeof(GUID)); ntfs_index_ctx_reinit(xo); return (ntfs_ie_add(xo,(INDEX_ENTRY*)&indx)); } /* * Open the $Extend/$ObjId file and its index * * Return the index context if opened * or NULL if an error occurred (errno tells why) * * The index has to be freed and inode closed when not needed any more. */ static ntfs_index_context *open_object_id_index(ntfs_volume *vol) { u64 inum; ntfs_inode *ni; ntfs_inode *dir_ni; ntfs_index_context *xo; /* do not use path_name_to inode - could reopen root */ dir_ni = ntfs_inode_open(vol, FILE_Extend); ni = (ntfs_inode*)NULL; if (dir_ni) { inum = ntfs_inode_lookup_by_mbsname(dir_ni,"$ObjId"); if (inum != (u64)-1) ni = ntfs_inode_open(vol, inum); ntfs_inode_close(dir_ni); } if (ni) { xo = ntfs_index_ctx_get(ni, objid_index_name, 2); if (!xo) { ntfs_inode_close(ni); } } else xo = (ntfs_index_context*)NULL; return (xo); } /* * Merge object_id data stored in the index into * a full object_id struct. * * returns 0 if merging successful * -1 if no data could be merged. This is generally not an error */ static int merge_index_data(ntfs_inode *ni, const OBJECT_ID_ATTR *objectid_attr, OBJECT_ID_ATTR *full_objectid) { OBJECT_ID_INDEX_KEY key; struct OBJECT_ID_INDEX *entry; ntfs_index_context *xo; ntfs_inode *xoni; int res; res = -1; xo = open_object_id_index(ni->vol); if (xo) { memcpy(&key.object_id,objectid_attr,sizeof(GUID)); if (!ntfs_index_lookup(&key, sizeof(OBJECT_ID_INDEX_KEY), xo)) { entry = (struct OBJECT_ID_INDEX*)xo->entry; /* make sure inode numbers match */ if (entry && (MREF(le64_to_cpu(entry->data.file_id)) == ni->mft_no)) { memcpy(&full_objectid->birth_volume_id, &entry->data.birth_volume_id, sizeof(GUID)); memcpy(&full_objectid->birth_object_id, &entry->data.birth_object_id, sizeof(GUID)); memcpy(&full_objectid->domain_id, &entry->data.domain_id, sizeof(GUID)); res = 0; } } xoni = xo->ni; ntfs_index_ctx_put(xo); ntfs_inode_close(xoni); } return (res); } /* * Remove an object id index entry if attribute present * * Returns the size of existing object id * (the existing object_d is returned) * -1 if failure, explained by errno */ static int remove_object_id_index(ntfs_attr *na, ntfs_index_context *xo, OBJECT_ID_ATTR *old_attr) { OBJECT_ID_INDEX_KEY key; struct OBJECT_ID_INDEX *entry; s64 size; int ret; ret = na->data_size; if (ret) { /* read the existing object id attribute */ size = ntfs_attr_pread(na, 0, sizeof(GUID), old_attr); if (size >= (s64)sizeof(GUID)) { memcpy(&key.object_id, &old_attr->object_id,sizeof(GUID)); if (!ntfs_index_lookup(&key, sizeof(OBJECT_ID_INDEX_KEY), xo)) { entry = (struct OBJECT_ID_INDEX*)xo->entry; memcpy(&old_attr->birth_volume_id, &entry->data.birth_volume_id, sizeof(GUID)); memcpy(&old_attr->birth_object_id, &entry->data.birth_object_id, sizeof(GUID)); memcpy(&old_attr->domain_id, &entry->data.domain_id, sizeof(GUID)); if (ntfs_index_rm(xo)) ret = -1; } } else { ret = -1; errno = ENODATA; } } return (ret); } /* * Update the object id and index * * The object_id attribute should have been created and the * non-duplication of the GUID should have been checked before. * * Returns 0 if success * -1 if failure, explained by errno * If could not remove the existing index, nothing is done, * If could not write the new data, no index entry is inserted * If failed to insert the index, data is removed */ static int update_object_id(ntfs_inode *ni, ntfs_index_context *xo, const OBJECT_ID_ATTR *value, size_t size) { OBJECT_ID_ATTR old_attr; ntfs_attr *na; int oldsize; int written; int res; res = 0; na = ntfs_attr_open(ni, AT_OBJECT_ID, AT_UNNAMED, 0); if (na) { memset(&old_attr, 0, sizeof(OBJECT_ID_ATTR)); /* remove the existing index entry */ oldsize = remove_object_id_index(na,xo,&old_attr); if (oldsize < 0) res = -1; else { /* resize attribute */ res = ntfs_attr_truncate(na, (s64)sizeof(GUID)); /* write the object_id in attribute */ if (!res && value) { written = (int)ntfs_attr_pwrite(na, (s64)0, (s64)sizeof(GUID), &value->object_id); if (written != (s64)sizeof(GUID)) { ntfs_log_error("Failed to update " "object id\n"); errno = EIO; res = -1; } } /* overwrite index data with new value */ memcpy(&old_attr, value, (size < sizeof(OBJECT_ID_ATTR) ? size : sizeof(OBJECT_ID_ATTR))); if (!res && set_object_id_index(ni,xo,&old_attr)) { /* * If cannot index, try to remove the object * id and log the error. There will be an * inconsistency if removal fails. */ ntfs_attr_rm(na); ntfs_log_error("Failed to index object id." " Possible corruption.\n"); } } ntfs_attr_close(na); NInoSetDirty(ni); } else res = -1; return (res); } /* * Add a (dummy) object id to an inode if it does not exist * * returns 0 if attribute was inserted (or already present) * -1 if adding failed (explained by errno) */ static int add_object_id(ntfs_inode *ni, int flags) { int res; u8 dummy; res = -1; /* default return */ if (!ntfs_attr_exist(ni,AT_OBJECT_ID, AT_UNNAMED,0)) { if (!(flags & XATTR_REPLACE)) { /* * no object id attribute : add one, * apparently, this does not feed the new value in * Note : NTFS version must be >= 3 */ if (ni->vol->major_ver >= 3) { res = ntfs_attr_add(ni, AT_OBJECT_ID, AT_UNNAMED, 0, &dummy, (s64)0); NInoSetDirty(ni); } else errno = EOPNOTSUPP; } else errno = ENODATA; } else { if (flags & XATTR_CREATE) errno = EEXIST; else res = 0; } return (res); } /* * Delete an object_id index entry * * Returns 0 if success * -1 if failure, explained by errno */ int ntfs_delete_object_id_index(ntfs_inode *ni) { ntfs_index_context *xo; ntfs_inode *xoni; ntfs_attr *na; OBJECT_ID_ATTR old_attr; int res; res = 0; na = ntfs_attr_open(ni, AT_OBJECT_ID, AT_UNNAMED, 0); if (na) { /* * read the existing object id * and un-index it */ xo = open_object_id_index(ni->vol); if (xo) { if (remove_object_id_index(na,xo,&old_attr) < 0) res = -1; xoni = xo->ni; ntfs_index_entry_mark_dirty(xo); NInoSetDirty(xoni); ntfs_index_ctx_put(xo); ntfs_inode_close(xoni); } ntfs_attr_close(na); } return (res); } /* * Get the ntfs object id into an extended attribute * * If present, the object_id from the attribute and the GUIDs * from the index are returned (formatted as OBJECT_ID_ATTR) * * Returns the global size (can be 0, 16 or 64) * and the buffer is updated if it is long enough */ int ntfs_get_ntfs_object_id(ntfs_inode *ni, char *value, size_t size) { OBJECT_ID_ATTR full_objectid; OBJECT_ID_ATTR *objectid_attr; s64 attr_size; int full_size; full_size = 0; /* default to no data and some error to be defined */ if (ni) { objectid_attr = (OBJECT_ID_ATTR*)ntfs_attr_readall(ni, AT_OBJECT_ID,(ntfschar*)NULL, 0, &attr_size); if (objectid_attr) { /* restrict to only GUID present in attr */ if (attr_size == sizeof(GUID)) { memcpy(&full_objectid.object_id, objectid_attr,sizeof(GUID)); full_size = sizeof(GUID); /* get data from index, if any */ if (!merge_index_data(ni, objectid_attr, &full_objectid)) { full_size = sizeof(OBJECT_ID_ATTR); } if (full_size <= (s64)size) { if (value) memcpy(value,&full_objectid, full_size); else errno = EINVAL; } } else { /* unexpected size, better return unsupported */ errno = EOPNOTSUPP; full_size = 0; } free(objectid_attr); } else errno = ENODATA; } return (full_size ? (int)full_size : -errno); } /* * Set the object id from an extended attribute * * The first 16 bytes are the new object id, they can be followed * by the birth volume id, the birth object id and the domain id. * If they are not present, their previous value is kept. * Only the object id is stored into the attribute, all the fields * are stored into the index. * * Returns 0, or -1 if there is a problem */ int ntfs_set_ntfs_object_id(ntfs_inode *ni, const char *value, size_t size, int flags) { OBJECT_ID_INDEX_KEY key; ntfs_inode *xoni; ntfs_index_context *xo; int res; res = 0; if (ni && value && (size >= sizeof(GUID))) { xo = open_object_id_index(ni->vol); if (xo) { /* make sure the GUID was not used elsewhere */ memcpy(&key.object_id, value, sizeof(GUID)); if ((ntfs_index_lookup(&key, sizeof(OBJECT_ID_INDEX_KEY), xo)) || (MREF_LE(((struct OBJECT_ID_INDEX*)xo->entry) ->data.file_id) == ni->mft_no)) { ntfs_index_ctx_reinit(xo); res = add_object_id(ni, flags); if (!res) { /* update value and index */ res = update_object_id(ni,xo, (const OBJECT_ID_ATTR*)value, size); } } else { /* GUID is present elsewhere */ res = -1; errno = EEXIST; } xoni = xo->ni; ntfs_index_entry_mark_dirty(xo); NInoSetDirty(xoni); ntfs_index_ctx_put(xo); ntfs_inode_close(xoni); } else { res = -1; } } else { errno = EINVAL; res = -1; } return (res ? -1 : 0); } /* * Remove the object id * * Returns 0, or -1 if there is a problem */ int ntfs_remove_ntfs_object_id(ntfs_inode *ni) { int res; int olderrno; ntfs_attr *na; ntfs_inode *xoni; ntfs_index_context *xo; int oldsize; OBJECT_ID_ATTR old_attr; res = 0; if (ni) { /* * open and delete the object id */ na = ntfs_attr_open(ni, AT_OBJECT_ID, AT_UNNAMED,0); if (na) { /* first remove index (old object id needed) */ xo = open_object_id_index(ni->vol); if (xo) { oldsize = remove_object_id_index(na,xo, &old_attr); if (oldsize < 0) { res = -1; } else { /* now remove attribute */ res = ntfs_attr_rm(na); if (res && (oldsize > (int)sizeof(GUID))) { /* * If we could not remove the * attribute, try to restore the * index and log the error. There * will be an inconsistency if * the reindexing fails. */ set_object_id_index(ni, xo, &old_attr); ntfs_log_error( "Failed to remove object id." " Possible corruption.\n"); } } xoni = xo->ni; ntfs_index_entry_mark_dirty(xo); NInoSetDirty(xoni); ntfs_index_ctx_put(xo); ntfs_inode_close(xoni); } olderrno = errno; ntfs_attr_close(na); /* avoid errno pollution */ if (errno == ENOENT) errno = olderrno; } else { errno = ENODATA; res = -1; } NInoSetDirty(ni); } else { errno = EINVAL; res = -1; } return (res ? -1 : 0); } ntfs-3g-2026.2.25/libntfs-3g/lcnalloc.c0000664000175000017500000005000115152260173012677 /** * lcnalloc.c - Cluster (de)allocation code. Originated from the Linux-NTFS project. * * Copyright (c) 2002-2004 Anton Altaparmakov * Copyright (c) 2004 Yura Pakhuchiy * Copyright (c) 2004-2008 Szabolcs Szakacsits * Copyright (c) 2008-2009 Jean-Pierre Andre * * This program/include file 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/include file 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_STDLIB_H #include #endif #ifdef HAVE_STDIO_H #include #endif #ifdef HAVE_ERRNO_H #include #endif #include "types.h" #include "attrib.h" #include "bitmap.h" #include "debug.h" #include "runlist.h" #include "volume.h" #include "lcnalloc.h" #include "logging.h" #include "misc.h" /* * Plenty possibilities for big optimizations all over in the cluster * allocation, however at the moment the dominant bottleneck (~ 90%) is * the update of the mapping pairs which converges to the cubic Faulhaber's * formula as the function of the number of extents (fragments, runs). */ #define NTFS_LCNALLOC_BSIZE 4096 #define NTFS_LCNALLOC_SKIP NTFS_LCNALLOC_BSIZE enum { ZONE_MFT = 1, ZONE_DATA1 = 2, ZONE_DATA2 = 4 } ; static void ntfs_cluster_set_zone_pos(LCN start, LCN end, LCN *pos, LCN tc) { ntfs_log_trace("pos: %lld tc: %lld\n", (long long)*pos, (long long)tc); if (tc >= end) *pos = start; else if (tc >= start) *pos = tc; } static void ntfs_cluster_update_zone_pos(ntfs_volume *vol, u8 zone, LCN tc) { ntfs_log_trace("tc = %lld, zone = %d\n", (long long)tc, zone); if (zone == ZONE_MFT) ntfs_cluster_set_zone_pos(vol->mft_lcn, vol->mft_zone_end, &vol->mft_zone_pos, tc); else if (zone == ZONE_DATA1) ntfs_cluster_set_zone_pos(vol->mft_zone_end, vol->nr_clusters, &vol->data1_zone_pos, tc); else /* zone == ZONE_DATA2 */ ntfs_cluster_set_zone_pos(0, vol->mft_zone_start, &vol->data2_zone_pos, tc); } /* * Unmark full zones when a cluster has been freed in a full zone * * Next allocation will reuse the freed cluster */ static void update_full_status(ntfs_volume *vol, LCN lcn) { if (lcn >= vol->mft_zone_end) { if (vol->full_zones & ZONE_DATA1) { ntfs_cluster_update_zone_pos(vol, ZONE_DATA1, lcn); vol->full_zones &= ~ZONE_DATA1; } } else if (lcn < vol->mft_zone_start) { if (vol->full_zones & ZONE_DATA2) { ntfs_cluster_update_zone_pos(vol, ZONE_DATA2, lcn); vol->full_zones &= ~ZONE_DATA2; } } else { if (vol->full_zones & ZONE_MFT) { ntfs_cluster_update_zone_pos(vol, ZONE_MFT, lcn); vol->full_zones &= ~ZONE_MFT; } } } static s64 max_empty_bit_range(unsigned char *buf, int size) { int i, j, run = 0; int max_range = 0; s64 start_pos = -1; ntfs_log_trace("Entering\n"); i = 0; while (i < size) { switch (*buf) { case 0 : do { buf++; run += 8; i++; } while ((i < size) && !*buf); break; case 255 : if (run > max_range) { max_range = run; start_pos = (s64)i * 8 - run; } run = 0; do { buf++; i++; } while ((i < size) && (*buf == 255)); break; default : for (j = 0; j < 8; j++) { int bit = *buf & (1 << j); if (bit) { if (run > max_range) { max_range = run; start_pos = (s64)i * 8 + (j - run); } run = 0; } else run++; } i++; buf++; } } if (run > max_range) start_pos = (s64)i * 8 - run; return start_pos; } static int bitmap_writeback(ntfs_volume *vol, s64 pos, s64 size, void *b, u8 *writeback) { s64 written; ntfs_log_trace("Entering\n"); if (!*writeback) return 0; *writeback = 0; written = ntfs_attr_pwrite(vol->lcnbmp_na, pos, size, b); if (written != size) { if (!written) errno = EIO; ntfs_log_perror("Bitmap write error (%lld, %lld)", (long long)pos, (long long)size); return -1; } return 0; } /** * ntfs_cluster_alloc - allocate clusters on an ntfs volume * @vol: mounted ntfs volume on which to allocate the clusters * @start_vcn: vcn to use for the first allocated cluster * @count: number of clusters to allocate * @start_lcn: starting lcn at which to allocate the clusters (or -1 if none) * @zone: zone from which to allocate the clusters * * Allocate @count clusters preferably starting at cluster @start_lcn or at the * current allocator position if @start_lcn is -1, on the mounted ntfs volume * @vol. @zone is either DATA_ZONE for allocation of normal clusters and * MFT_ZONE for allocation of clusters for the master file table, i.e. the * $MFT/$DATA attribute. * * On success return a runlist describing the allocated cluster(s). * * On error return NULL with errno set to the error code. * * Notes on the allocation algorithm * ================================= * * There are two data zones. First is the area between the end of the mft zone * and the end of the volume, and second is the area between the start of the * volume and the start of the mft zone. On unmodified/standard NTFS 1.x * volumes, the second data zone doesn't exist due to the mft zone being * expanded to cover the start of the volume in order to reserve space for the * mft bitmap attribute. * * The complexity stems from the need of implementing the mft vs data zoned * approach and from the fact that we have access to the lcn bitmap via up to * NTFS_LCNALLOC_BSIZE bytes at a time, so we need to cope with crossing over * boundaries of two buffers. Further, the fact that the allocator allows for * caller supplied hints as to the location of where allocation should begin * and the fact that the allocator keeps track of where in the data zones the * next natural allocation should occur, contribute to the complexity of the * function. But it should all be worthwhile, because this allocator: * 1) implements MFT zone reservation * 2) causes reduction in fragmentation. * The code is not optimized for speed. */ runlist *ntfs_cluster_alloc(ntfs_volume *vol, VCN start_vcn, s64 count, LCN start_lcn, const NTFS_CLUSTER_ALLOCATION_ZONES zone) { LCN zone_start, zone_end; /* current search range */ LCN last_read_pos, lcn; LCN bmp_pos; /* current bit position inside the bitmap */ LCN prev_lcn = 0, prev_run_len = 0; s64 clusters, br; runlist *rl = NULL, *trl; u8 *buf, *byte, bit, writeback; u8 pass = 1; /* 1: inside zone; 2: start of zone */ u8 search_zone; /* 4: data2 (start) 1: mft (middle) 2: data1 (end) */ u8 done_zones = 0; u8 has_guess, used_zone_pos; int err = 0, rlpos, rlsize, buf_size; ntfs_log_enter("Entering with count = 0x%llx, start_lcn = 0x%llx, " "zone = %s_ZONE.\n", (long long)count, (long long) start_lcn, zone == MFT_ZONE ? "MFT" : "DATA"); if (!vol || count < 0 || start_lcn < -1 || !vol->lcnbmp_na || (s8)zone < FIRST_ZONE || zone > LAST_ZONE) { errno = EINVAL; ntfs_log_perror("%s: vcn: %lld, count: %lld, lcn: %lld", __FUNCTION__, (long long)start_vcn, (long long)count, (long long)start_lcn); goto out; } /* Return empty runlist if @count == 0 */ if (!count) { rl = ntfs_malloc(0x1000); if (rl) { rl[0].vcn = start_vcn; rl[0].lcn = LCN_RL_NOT_MAPPED; rl[0].length = 0; } goto out; } buf = ntfs_malloc(NTFS_LCNALLOC_BSIZE); if (!buf) goto out; /* * If no @start_lcn was requested, use the current zone * position otherwise use the requested @start_lcn. */ has_guess = 1; zone_start = start_lcn; if (zone_start < 0) { if (zone == DATA_ZONE) zone_start = vol->data1_zone_pos; else zone_start = vol->mft_zone_pos; has_guess = 0; } used_zone_pos = has_guess ? 0 : 1; if (!zone_start || zone_start == vol->mft_zone_start || zone_start == vol->mft_zone_end) pass = 2; if (zone_start < vol->mft_zone_start) { zone_end = vol->mft_zone_start; search_zone = ZONE_DATA2; } else if (zone_start < vol->mft_zone_end) { zone_end = vol->mft_zone_end; search_zone = ZONE_MFT; } else { zone_end = vol->nr_clusters; search_zone = ZONE_DATA1; } bmp_pos = zone_start; /* Loop until all clusters are allocated. */ clusters = count; rlpos = rlsize = 0; while (1) { /* check whether we have exhausted the current zone */ if (search_zone & vol->full_zones) goto zone_pass_done; last_read_pos = bmp_pos >> 3; br = ntfs_attr_pread(vol->lcnbmp_na, last_read_pos, NTFS_LCNALLOC_BSIZE, buf); if (br <= 0) { if (!br) goto zone_pass_done; err = errno; ntfs_log_perror("Reading $BITMAP failed"); goto err_ret; } /* * We might have read less than NTFS_LCNALLOC_BSIZE bytes * if we are close to the end of the attribute. */ buf_size = (int)br << 3; lcn = bmp_pos & 7; bmp_pos &= ~7; writeback = 0; while (lcn < buf_size) { byte = buf + (lcn >> 3); bit = 1 << (lcn & 7); if (has_guess) { if (*byte & bit) { has_guess = 0; break; } } else { lcn = max_empty_bit_range(buf, br); if (lcn < 0) break; has_guess = 1; continue; } /* First free bit is at lcn + bmp_pos. */ /* Reallocate memory if necessary. */ if ((rlpos + 2) * (int)sizeof(runlist) >= rlsize) { rlsize += 4096; trl = realloc(rl, rlsize); if (!trl) { err = ENOMEM; ntfs_log_perror("realloc() failed"); goto wb_err_ret; } rl = trl; } /* Allocate the bitmap bit. */ *byte |= bit; writeback = 1; if (NVolFreeSpaceKnown(vol)) { if (vol->free_clusters <= 0) ntfs_log_error("Non-positive free" " clusters (%lld)!\n", (long long)vol->free_clusters); else vol->free_clusters--; } /* * Coalesce with previous run if adjacent LCNs. * Otherwise, append a new run. */ if (prev_lcn == lcn + bmp_pos - prev_run_len && rlpos) { ntfs_log_debug("Cluster coalesce: prev_lcn: " "%lld lcn: %lld bmp_pos: %lld " "prev_run_len: %lld\n", (long long)prev_lcn, (long long)lcn, (long long)bmp_pos, (long long)prev_run_len); rl[rlpos - 1].length = ++prev_run_len; } else { if (rlpos) rl[rlpos].vcn = rl[rlpos - 1].vcn + prev_run_len; else { rl[rlpos].vcn = start_vcn; ntfs_log_debug("Start_vcn: %lld\n", (long long)start_vcn); } rl[rlpos].lcn = prev_lcn = lcn + bmp_pos; rl[rlpos].length = prev_run_len = 1; rlpos++; } ntfs_log_debug("RUN: %-16lld %-16lld %-16lld\n", (long long)rl[rlpos - 1].vcn, (long long)rl[rlpos - 1].lcn, (long long)rl[rlpos - 1].length); /* Done? */ if (!--clusters) { if (used_zone_pos) ntfs_cluster_update_zone_pos(vol, search_zone, lcn + bmp_pos + 1 + NTFS_LCNALLOC_SKIP); goto done_ret; } lcn++; } if (bitmap_writeback(vol, last_read_pos, br, buf, &writeback)) { err = errno; goto err_ret; } if (!used_zone_pos) { used_zone_pos = 1; if (search_zone == ZONE_MFT) zone_start = vol->mft_zone_pos; else if (search_zone == ZONE_DATA1) zone_start = vol->data1_zone_pos; else zone_start = vol->data2_zone_pos; if (!zone_start || zone_start == vol->mft_zone_start || zone_start == vol->mft_zone_end) pass = 2; bmp_pos = zone_start; } else bmp_pos += buf_size; if (bmp_pos < zone_end) continue; zone_pass_done: ntfs_log_trace("Finished current zone pass(%i).\n", pass); if (pass == 1) { pass = 2; zone_end = zone_start; if (search_zone == ZONE_MFT) zone_start = vol->mft_zone_start; else if (search_zone == ZONE_DATA1) zone_start = vol->mft_zone_end; else zone_start = 0; /* Sanity check. */ if (zone_end < zone_start) zone_end = zone_start; bmp_pos = zone_start; continue; } /* pass == 2 */ done_zones_check: done_zones |= search_zone; vol->full_zones |= search_zone; if (done_zones < (ZONE_MFT + ZONE_DATA1 + ZONE_DATA2)) { ntfs_log_trace("Switching zone.\n"); pass = 1; if (rlpos) { LCN tc = rl[rlpos - 1].lcn + rl[rlpos - 1].length + NTFS_LCNALLOC_SKIP; if (used_zone_pos) ntfs_cluster_update_zone_pos(vol, search_zone, tc); } switch (search_zone) { case ZONE_MFT: ntfs_log_trace("Zone switch: mft -> data1\n"); switch_to_data1_zone: search_zone = ZONE_DATA1; zone_start = vol->data1_zone_pos; zone_end = vol->nr_clusters; if (zone_start == vol->mft_zone_end) pass = 2; break; case ZONE_DATA1: ntfs_log_trace("Zone switch: data1 -> data2\n"); search_zone = ZONE_DATA2; zone_start = vol->data2_zone_pos; zone_end = vol->mft_zone_start; if (!zone_start) pass = 2; break; case ZONE_DATA2: if (!(done_zones & ZONE_DATA1)) { ntfs_log_trace("data2 -> data1\n"); goto switch_to_data1_zone; } ntfs_log_trace("Zone switch: data2 -> mft\n"); search_zone = ZONE_MFT; zone_start = vol->mft_zone_pos; zone_end = vol->mft_zone_end; if (zone_start == vol->mft_zone_start) pass = 2; break; } bmp_pos = zone_start; if (zone_start == zone_end) { ntfs_log_trace("Empty zone, skipped.\n"); goto done_zones_check; } continue; } ntfs_log_trace("All zones are finished, no space on device.\n"); err = ENOSPC; goto err_ret; } done_ret: ntfs_log_debug("At done_ret.\n"); /* Add runlist terminator element. */ rl[rlpos].vcn = rl[rlpos - 1].vcn + rl[rlpos - 1].length; rl[rlpos].lcn = LCN_RL_NOT_MAPPED; rl[rlpos].length = 0; if (bitmap_writeback(vol, last_read_pos, br, buf, &writeback)) { err = errno; goto err_ret; } done_err_ret: free(buf); if (err) { errno = err; ntfs_log_perror("Failed to allocate clusters"); rl = NULL; } out: ntfs_log_leave("\n"); return rl; wb_err_ret: ntfs_log_trace("At wb_err_ret.\n"); if (bitmap_writeback(vol, last_read_pos, br, buf, &writeback)) err = errno; err_ret: ntfs_log_trace("At err_ret.\n"); if (rl) { /* Add runlist terminator element. */ rl[rlpos].vcn = rl[rlpos - 1].vcn + rl[rlpos - 1].length; rl[rlpos].lcn = LCN_RL_NOT_MAPPED; rl[rlpos].length = 0; ntfs_debug_runlist_dump(rl); ntfs_cluster_free_from_rl(vol, rl); free(rl); rl = NULL; } goto done_err_ret; } /** * ntfs_cluster_free_from_rl - free clusters from runlist * @vol: mounted ntfs volume on which to free the clusters * @rl: runlist from which deallocate clusters * * On success return 0 and on error return -1 with errno set to the error code. */ int ntfs_cluster_free_from_rl(ntfs_volume *vol, runlist *rl) { s64 nr_freed = 0; int ret = -1; ntfs_log_trace("Entering.\n"); for (; rl->length; rl++) { ntfs_log_trace("Dealloc lcn 0x%llx, len 0x%llx.\n", (long long)rl->lcn, (long long)rl->length); if (rl->lcn >= 0) { update_full_status(vol,rl->lcn); if (ntfs_bitmap_clear_run(vol->lcnbmp_na, rl->lcn, rl->length)) { ntfs_log_perror("Cluster deallocation failed " "(%lld, %lld)", (long long)rl->lcn, (long long)rl->length); goto out; } nr_freed += rl->length ; } } ret = 0; out: vol->free_clusters += nr_freed; if (NVolFreeSpaceKnown(vol) && (vol->free_clusters > vol->nr_clusters)) ntfs_log_error("Too many free clusters (%lld > %lld)!", (long long)vol->free_clusters, (long long)vol->nr_clusters); return ret; } /* * Basic cluster run free * Returns 0 if successful */ int ntfs_cluster_free_basic(ntfs_volume *vol, s64 lcn, s64 count) { s64 nr_freed = 0; int ret = -1; ntfs_log_trace("Entering.\n"); ntfs_log_trace("Dealloc lcn 0x%llx, len 0x%llx.\n", (long long)lcn, (long long)count); if (lcn >= 0) { update_full_status(vol,lcn); if (ntfs_bitmap_clear_run(vol->lcnbmp_na, lcn, count)) { ntfs_log_perror("Cluster deallocation failed " "(%lld, %lld)", (long long)lcn, (long long)count); goto out; } nr_freed += count; } ret = 0; out: vol->free_clusters += nr_freed; if (vol->free_clusters > vol->nr_clusters) ntfs_log_error("Too many free clusters (%lld > %lld)!", (long long)vol->free_clusters, (long long)vol->nr_clusters); return ret; } /** * ntfs_cluster_free - free clusters on an ntfs volume * @vol: mounted ntfs volume on which to free the clusters * @na: attribute whose runlist describes the clusters to free * @start_vcn: vcn in @rl at which to start freeing clusters * @count: number of clusters to free or -1 for all clusters * * Free @count clusters starting at the cluster @start_vcn in the runlist * described by the attribute @na from the mounted ntfs volume @vol. * * If @count is -1, all clusters from @start_vcn to the end of the runlist * are deallocated. * * On success return the number of deallocated clusters (not counting sparse * clusters) and on error return -1 with errno set to the error code. */ int ntfs_cluster_free(ntfs_volume *vol, ntfs_attr *na, VCN start_vcn, s64 count) { runlist *rl; s64 delta, to_free, nr_freed = 0; int ret = -1; if (!vol || !vol->lcnbmp_na || !na || start_vcn < 0 || (count < 0 && count != -1)) { ntfs_log_trace("Invalid arguments!\n"); errno = EINVAL; return -1; } ntfs_log_enter("Entering for inode 0x%llx, attr 0x%x, count 0x%llx, " "vcn 0x%llx.\n", (unsigned long long)na->ni->mft_no, le32_to_cpu(na->type), (long long)count, (long long)start_vcn); rl = ntfs_attr_find_vcn(na, start_vcn); if (!rl) { if (errno == ENOENT) ret = 0; goto leave; } if (rl->lcn < 0 && rl->lcn != LCN_HOLE) { errno = EIO; ntfs_log_perror("%s: Unexpected lcn (%lld)", __FUNCTION__, (long long)rl->lcn); goto leave; } /* Find the starting cluster inside the run that needs freeing. */ delta = start_vcn - rl->vcn; /* The number of clusters in this run that need freeing. */ to_free = rl->length - delta; if (count >= 0 && to_free > count) to_free = count; if (rl->lcn != LCN_HOLE) { /* Do the actual freeing of the clusters in this run. */ update_full_status(vol,rl->lcn + delta); if (ntfs_bitmap_clear_run(vol->lcnbmp_na, rl->lcn + delta, to_free)) goto leave; nr_freed = to_free; } /* Go to the next run and adjust the number of clusters left to free. */ ++rl; if (count >= 0) count -= to_free; /* * Loop over the remaining runs, using @count as a capping value, and * free them. */ for (; rl->length && count != 0; ++rl) { // FIXME: Need to try ntfs_attr_map_runlist() for attribute // list support! (AIA) if (rl->lcn < 0 && rl->lcn != LCN_HOLE) { // FIXME: Eeek! We need rollback! (AIA) errno = EIO; ntfs_log_perror("%s: Invalid lcn (%lli)", __FUNCTION__, (long long)rl->lcn); goto out; } /* The number of clusters in this run that need freeing. */ to_free = rl->length; if (count >= 0 && to_free > count) to_free = count; if (rl->lcn != LCN_HOLE) { update_full_status(vol,rl->lcn); if (ntfs_bitmap_clear_run(vol->lcnbmp_na, rl->lcn, to_free)) { // FIXME: Eeek! We need rollback! (AIA) ntfs_log_perror("%s: Clearing bitmap run failed", __FUNCTION__); goto out; } nr_freed += to_free; } if (count >= 0) count -= to_free; } if (count != -1 && count != 0) { // FIXME: Eeek! BUG() errno = EIO; ntfs_log_perror("%s: count still not zero (%lld)", __FUNCTION__, (long long)count); goto out; } ret = nr_freed; out: vol->free_clusters += nr_freed ; if (vol->free_clusters > vol->nr_clusters) ntfs_log_error("Too many free clusters (%lld > %lld)!", (long long)vol->free_clusters, (long long)vol->nr_clusters); leave: ntfs_log_leave("\n"); return ret; } ntfs-3g-2026.2.25/libntfs-3g/collate.c0000664000175000017500000001417215152260173012544 /** * collate.c - NTFS collation handling. Originated from the Linux-NTFS project. * * Copyright (c) 2004 Anton Altaparmakov * Copyright (c) 2005 Yura Pakhuchiy * * This program/include file 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/include file 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_STDLIB_H #include #endif #ifdef HAVE_STRING_H #include #endif #ifdef HAVE_ERRNO_H #include #endif #include "attrib.h" #include "index.h" #include "collate.h" #include "debug.h" #include "unistr.h" #include "logging.h" /** * ntfs_collate_binary - Which of two binary objects should be listed first * @vol: unused * @data1: * @data1_len: * @data2: * @data2_len: * * Description... * * Returns: */ static int ntfs_collate_binary(ntfs_volume *vol __attribute__((unused)), const void *data1, const int data1_len, const void *data2, const int data2_len) { int rc; ntfs_log_trace("Entering.\n"); rc = memcmp(data1, data2, min(data1_len, data2_len)); if (!rc && (data1_len != data2_len)) { if (data1_len < data2_len) rc = -1; else rc = 1; } ntfs_log_trace("Done, returning %i.\n", rc); return rc; } /** * ntfs_collate_ntofs_ulong - Which of two long ints should be listed first * @vol: unused * @data1: * @data1_len: * @data2: * @data2_len: * * Description... * * Returns: */ static int ntfs_collate_ntofs_ulong(ntfs_volume *vol __attribute__((unused)), const void *data1, const int data1_len, const void *data2, const int data2_len) { int rc; u32 d1, d2; ntfs_log_trace("Entering.\n"); if (data1_len != data2_len || data1_len != 4) { ntfs_log_error("data1_len or/and data2_len not equal to 4.\n"); return NTFS_COLLATION_ERROR; } d1 = le32_to_cpup(data1); d2 = le32_to_cpup(data2); if (d1 < d2) rc = -1; else { if (d1 == d2) rc = 0; else rc = 1; } ntfs_log_trace("Done, returning %i.\n", rc); return rc; } /** * ntfs_collate_ntofs_ulongs - Which of two le32 arrays should be listed first * * Returns: -1, 0 or 1 depending of how the arrays compare */ static int ntfs_collate_ntofs_ulongs(ntfs_volume *vol __attribute__((unused)), const void *data1, const int data1_len, const void *data2, const int data2_len) { int rc; int len; const le32 *p1, *p2; u32 d1, d2; ntfs_log_trace("Entering.\n"); if ((data1_len != data2_len) || (data1_len <= 0) || (data1_len & 3)) { ntfs_log_error("data1_len or data2_len not valid\n"); return NTFS_COLLATION_ERROR; } p1 = (const le32*)data1; p2 = (const le32*)data2; len = data1_len; do { d1 = le32_to_cpup(p1); p1++; d2 = le32_to_cpup(p2); p2++; } while ((d1 == d2) && ((len -= 4) > 0)); if (d1 < d2) rc = -1; else { if (d1 == d2) rc = 0; else rc = 1; } ntfs_log_trace("Done, returning %i.\n", rc); return rc; } /** * ntfs_collate_ntofs_security_hash - Which of two security descriptors * should be listed first * @vol: unused * @data1: * @data1_len: * @data2: * @data2_len: * * JPA compare two security hash keys made of two unsigned le32 * * Returns: -1, 0 or 1 depending of how the keys compare */ static int ntfs_collate_ntofs_security_hash(ntfs_volume *vol __attribute__((unused)), const void *data1, const int data1_len, const void *data2, const int data2_len) { int rc; u32 d1, d2; const le32 *p1, *p2; ntfs_log_trace("Entering.\n"); if (data1_len != data2_len || data1_len != 8) { ntfs_log_error("data1_len or/and data2_len not equal to 8.\n"); return NTFS_COLLATION_ERROR; } p1 = (const le32*)data1; p2 = (const le32*)data2; d1 = le32_to_cpup(p1); d2 = le32_to_cpup(p2); if (d1 < d2) rc = -1; else { if (d1 > d2) rc = 1; else { p1++; p2++; d1 = le32_to_cpup(p1); d2 = le32_to_cpup(p2); if (d1 < d2) rc = -1; else { if (d1 > d2) rc = 1; else rc = 0; } } } ntfs_log_trace("Done, returning %i.\n", rc); return rc; } /** * ntfs_collate_file_name - Which of two filenames should be listed first * @vol: * @data1: * @data1_len: unused * @data2: * @data2_len: unused * * Description... * * Returns: */ static int ntfs_collate_file_name(ntfs_volume *vol, const void *data1, const int data1_len __attribute__((unused)), const void *data2, const int data2_len __attribute__((unused))) { const FILE_NAME_ATTR *file_name_attr1; const FILE_NAME_ATTR *file_name_attr2; int rc; ntfs_log_trace("Entering.\n"); file_name_attr1 = (const FILE_NAME_ATTR*)data1; file_name_attr2 = (const FILE_NAME_ATTR*)data2; rc = ntfs_names_full_collate( (ntfschar*)&file_name_attr1->file_name, file_name_attr1->file_name_length, (ntfschar*)&file_name_attr2->file_name, file_name_attr2->file_name_length, CASE_SENSITIVE, vol->upcase, vol->upcase_len); ntfs_log_trace("Done, returning %i.\n", rc); return rc; } /* * Get a pointer to appropriate collation function. * * Returns NULL if the needed function is not implemented */ COLLATE ntfs_get_collate_function(COLLATION_RULES cr) { COLLATE collate; switch (cr) { case COLLATION_BINARY : collate = ntfs_collate_binary; break; case COLLATION_FILE_NAME : collate = ntfs_collate_file_name; break; case COLLATION_NTOFS_SECURITY_HASH : collate = ntfs_collate_ntofs_security_hash; break; case COLLATION_NTOFS_ULONG : collate = ntfs_collate_ntofs_ulong; break; case COLLATION_NTOFS_ULONGS : collate = ntfs_collate_ntofs_ulongs; break; default : errno = EOPNOTSUPP; collate = (COLLATE)NULL; break; } return (collate); } ntfs-3g-2026.2.25/libntfs-3g/compat.c0000664000175000017500000001710115152260173012377 /** * compat.c - Tweaks for Windows compatibility * * Copyright (c) 2002 Richard Russon * Copyright (c) 2002-2004 Anton Altaparmakov * * This program/include file 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/include file 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 #include "compat.h" #ifndef HAVE_FFS /** * ffs - Find the first set bit in an int * @x: * * Description... * * Returns: */ int ffs(int x) { int r = 1; if (!x) return 0; if (!(x & 0xffff)) { x >>= 16; r += 16; } if (!(x & 0xff)) { x >>= 8; r += 8; } if (!(x & 0xf)) { x >>= 4; r += 4; } if (!(x & 3)) { x >>= 2; r += 2; } if (!(x & 1)) { x >>= 1; r += 1; } return r; } #endif /* HAVE_FFS */ #ifndef HAVE_DAEMON /* ************************************************************ * From: src.opensolaris.org * src/lib/libresolv2/common/bsd/daemon.c */ /* * Copyright (c) 1997-2000 by Sun Microsystems, Inc. * All rights reserved. */ #if defined(LIBC_SCCS) && !defined(lint) static const char sccsid[] = "@(#)daemon.c 8.1 (Berkeley) 6/4/93"; static const char rcsid[] = "$Id: compat.c,v 1.1.1.1.2.1 2008-08-16 15:17:44 jpandre Exp $"; #endif /* LIBC_SCCS and not lint */ /* * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #ifdef HAVE_FCNTL_H #include #endif #ifdef HAVE_UNISTD_H #include #endif int daemon(int nochdir, int noclose) { int fd; switch (fork()) { case -1: return (-1); case 0: break; default: _exit(0); } if (setsid() == -1) return (-1); if (!nochdir) (void)chdir("/"); if (!noclose && (fd = open("/dev/null", O_RDWR, 0)) != -1) { (void)dup2(fd, 0); (void)dup2(fd, 1); (void)dup2(fd, 2); if (fd > 2) (void)close (fd); } return (0); } /* * End: src/lib/libresolv2/common/bsd/daemon.c *************************************************************/ #endif /* HAVE_DAEMON */ #ifndef HAVE_STRSEP /* ************************************************************ * From: src.opensolaris.org * src/lib/libresolv2/common/bsd/strsep.c */ /* * Copyright (c) 1997, by Sun Microsystems, Inc. * All rights reserved. */ #if defined(LIBC_SCCS) && !defined(lint) static const char sccsid[] = "strsep.c 8.1 (Berkeley) 6/4/93"; static const char rcsid[] = "$Id: compat.c,v 1.1.1.1.2.1 2008-08-16 15:17:44 jpandre Exp $"; #endif /* LIBC_SCCS and not lint */ /* * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #ifdef HAVE_STRING_H #include #endif #ifdef HAVE_STDIO_H #include #endif /* * Get next token from string *stringp, where tokens are possibly-empty * strings separated by characters from delim. * * Writes NULs into the string at *stringp to end tokens. * delim need not remain constant from call to call. * On return, *stringp points past the last NUL written (if there might * be further tokens), or is NULL (if there are definitely no more tokens). * * If *stringp is NULL, strsep returns NULL. */ char *strsep(char **stringp, const char *delim) { char *s; const char *spanp; int c, sc; char *tok; if ((s = *stringp) == NULL) return (NULL); for (tok = s;;) { c = *s++; spanp = delim; do { if ((sc = *spanp++) == c) { if (c == 0) s = NULL; else s[-1] = 0; *stringp = s; return (tok); } } while (sc != 0); } /* NOTREACHED */ } /* * End: src/lib/libresolv2/common/bsd/strsep.c *************************************************************/ #endif /* HAVE_STRSEP */ ntfs-3g-2026.2.25/libntfs-3g/realpath.c0000664000175000017500000000451515152260173012721 /* * realpath.c - realpath() aware of device mapper * Originated from the util-linux project. */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include #include #ifdef HAVE_LIMITS_H #include #endif #ifdef HAVE_CTYPE_H #include #endif #include "param.h" #include "realpath.h" /* If there is no realpath() on the system, provide a dummy one. */ #ifndef HAVE_REALPATH char *ntfs_realpath(const char *path, char *resolved_path) { strncpy(resolved_path, path, PATH_MAX); resolved_path[PATH_MAX] = '\0'; return resolved_path; } #endif #ifdef linux /* * Converts private "dm-N" names to "/dev/mapper/" * * Since 2.6.29 (patch 784aae735d9b0bba3f8b9faef4c8b30df3bf0128) kernel sysfs * provides the real DM device names in /sys/block//dm/name */ static char * canonicalize_dm_name(const char *ptname, char *canonical) { FILE *f; size_t sz; char name[MAPPERNAMELTH + 16]; char path[sizeof(name) + 16]; char *res = NULL; snprintf(path, sizeof(path), "/sys/block/%s/dm/name", ptname); if (!(f = fopen(path, "r"))) return NULL; /* read "\n" from sysfs */ if (fgets(name, sizeof(name), f) && (sz = strlen(name)) > 1) { name[sz - 1] = '\0'; snprintf(path, sizeof(path), "/dev/mapper/%s", name); res = strcpy(canonical, path); } fclose(f); return res; } /* * Canonicalize a device path * * Workaround from "basinilya" for fixing device mapper paths. * * Background (Phillip Susi, 2011-04-09) * - ntfs-3g canonicalizes the device name so that if you mount with * /dev/mapper/foo, the device name listed in mtab is /dev/dm-n, * so you can not umount /dev/mapper/foo * - umount won't even recognize and translate /dev/dm-n to the mount * point, apparently because of the '-' involved. Editing mtab and * removing the '-' allows you to umount /dev/dmn successfully. * * This code restores the devmapper name after canonicalization, * until a proper fix is implemented. */ char *ntfs_realpath_canonicalize(const char *path, char *canonical) { char *p; if (path == NULL) return NULL; if (!ntfs_realpath(path, canonical)) return NULL; p = strrchr(canonical, '/'); if (p && strncmp(p, "/dm-", 4) == 0 && isdigit(*(p + 4))) { p = canonicalize_dm_name(p+1, canonical); if (p) return p; } return canonical; } #endif ntfs-3g-2026.2.25/libntfs-3g/xattrs.c0000664000175000017500000004645115152260173012453 /** * xattrs.c : common functions to deal with system extended attributes * * Copyright (c) 2010-2014 Jean-Pierre Andre * * This program/include file 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/include file 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_STDIO_H #include #endif #ifdef HAVE_STDLIB_H #include #endif #ifdef HAVE_STRING_H #include #endif #ifdef HAVE_FCNTL_H #include #endif #ifdef HAVE_UNISTD_H #include #endif #ifdef HAVE_ERRNO_H #include #endif #include "types.h" #include "param.h" #include "layout.h" #include "attrib.h" #include "index.h" #include "dir.h" #include "security.h" #include "acls.h" #include "efs.h" #include "reparse.h" #include "object_id.h" #include "ea.h" #include "misc.h" #include "logging.h" #include "xattrs.h" #if POSIXACLS #if __BYTE_ORDER == __BIG_ENDIAN /* * Posix ACL structures */ struct LE_POSIX_ACE { le16 tag; le16 perms; le32 id; } __attribute__((__packed__)); struct LE_POSIX_ACL { u8 version; u8 flags; le16 filler; struct LE_POSIX_ACE ace[0]; } __attribute__((__packed__)); #endif #endif static const char nf_ns_xattr_ntfs_acl[] = "system.ntfs_acl"; static const char nf_ns_xattr_attrib[] = "system.ntfs_attrib"; static const char nf_ns_xattr_attrib_be[] = "system.ntfs_attrib_be"; static const char nf_ns_xattr_efsinfo[] = "system.ntfs_efsinfo"; static const char nf_ns_xattr_reparse[] = "system.ntfs_reparse_data"; static const char nf_ns_xattr_object_id[] = "system.ntfs_object_id"; static const char nf_ns_xattr_dos_name[] = "system.ntfs_dos_name"; static const char nf_ns_xattr_times[] = "system.ntfs_times"; static const char nf_ns_xattr_times_be[] = "system.ntfs_times_be"; static const char nf_ns_xattr_crtime[] = "system.ntfs_crtime"; static const char nf_ns_xattr_crtime_be[] = "system.ntfs_crtime_be"; static const char nf_ns_xattr_ea[] = "system.ntfs_ea"; static const char nf_ns_xattr_posix_access[] = "system.posix_acl_access"; static const char nf_ns_xattr_posix_default[] = "system.posix_acl_default"; static const char nf_ns_alt_xattr_efsinfo[] = "user.ntfs.efsinfo"; struct XATTRNAME { enum SYSTEMXATTRS xattr; const char *name; } ; static struct XATTRNAME nf_ns_xattr_names[] = { { XATTR_NTFS_ACL, nf_ns_xattr_ntfs_acl }, { XATTR_NTFS_ATTRIB, nf_ns_xattr_attrib }, { XATTR_NTFS_ATTRIB_BE, nf_ns_xattr_attrib_be }, { XATTR_NTFS_EFSINFO, nf_ns_xattr_efsinfo }, { XATTR_NTFS_REPARSE_DATA, nf_ns_xattr_reparse }, { XATTR_NTFS_OBJECT_ID, nf_ns_xattr_object_id }, { XATTR_NTFS_DOS_NAME, nf_ns_xattr_dos_name }, { XATTR_NTFS_TIMES, nf_ns_xattr_times }, { XATTR_NTFS_TIMES_BE, nf_ns_xattr_times_be }, { XATTR_NTFS_CRTIME, nf_ns_xattr_crtime }, { XATTR_NTFS_CRTIME_BE, nf_ns_xattr_crtime_be }, { XATTR_NTFS_EA, nf_ns_xattr_ea }, { XATTR_POSIX_ACC, nf_ns_xattr_posix_access }, { XATTR_POSIX_DEF, nf_ns_xattr_posix_default }, { XATTR_UNMAPPED, (char*)NULL } /* terminator */ }; /* * Make an integer big-endian * * Swap bytes on a small-endian computer and does nothing on a * big-endian computer. */ static void fix_big_endian(char *p, int size) { #if __BYTE_ORDER == __LITTLE_ENDIAN int i,j; int c; i = 0; j = size - 1; while (i < j) { c = p[i]; p[i++] = p[j]; p[j--] = c; } #endif } #if POSIXACLS #if __BYTE_ORDER == __BIG_ENDIAN /* * Make a Posix ACL CPU endian */ static int le_acl_to_cpu(const struct LE_POSIX_ACL *le_acl, size_t size, struct POSIX_ACL *acl) { int i; int cnt; acl->version = le_acl->version; acl->flags = le_acl->flags; acl->filler = 0; cnt = (size - sizeof(struct LE_POSIX_ACL)) / sizeof(struct LE_POSIX_ACE); for (i=0; iace[i].tag = le16_to_cpu(le_acl->ace[i].tag); acl->ace[i].perms = le16_to_cpu(le_acl->ace[i].perms); acl->ace[i].id = le32_to_cpu(le_acl->ace[i].id); } return (0); } /* * Make a Posix ACL little endian */ int cpu_to_le_acl(const struct POSIX_ACL *acl, size_t size, struct LE_POSIX_ACL *le_acl) { int i; int cnt; le_acl->version = acl->version; le_acl->flags = acl->flags; le_acl->filler = const_cpu_to_le16(0); cnt = (size - sizeof(struct POSIX_ACL)) / sizeof(struct POSIX_ACE); for (i=0; iace[i].tag = cpu_to_le16(acl->ace[i].tag); le_acl->ace[i].perms = cpu_to_le16(acl->ace[i].perms); le_acl->ace[i].id = cpu_to_le32(acl->ace[i].id); } return (0); } #endif #endif /* * Determine whether an extended attribute is mapped to * internal data (original name in system namespace, or renamed) */ enum SYSTEMXATTRS ntfs_xattr_system_type(const char *name, ntfs_volume *vol) { struct XATTRNAME *p; enum SYSTEMXATTRS ret; #ifdef XATTR_MAPPINGS const struct XATTRMAPPING *q; #endif /* XATTR_MAPPINGS */ p = nf_ns_xattr_names; while (p->name && strcmp(p->name,name)) p++; ret = p->xattr; #ifdef XATTR_MAPPINGS if (!p->name && vol && vol->xattr_mapping) { q = vol->xattr_mapping; while (q && strcmp(q->name,name)) q = q->next; if (q) ret = q->xattr; } #else /* XATTR_MAPPINGS */ if (!p->name && vol && vol->efs_raw && !strcmp(nf_ns_alt_xattr_efsinfo,name)) ret = XATTR_NTFS_EFSINFO; #endif /* XATTR_MAPPINGS */ return (ret); } #ifdef XATTR_MAPPINGS /* * Basic read from a user mapping file on another volume */ static int basicread(void *fileid, char *buf, size_t size, off_t offs __attribute__((unused))) { return (read(*(int*)fileid, buf, size)); } /* * Read from a user mapping file on current NTFS partition */ static int localread(void *fileid, char *buf, size_t size, off_t offs) { return (ntfs_attr_data_read((ntfs_inode*)fileid, AT_UNNAMED, 0, buf, size, offs)); } /* * Get a single mapping item from buffer * * Always reads a full line, truncating long lines * Refills buffer when exhausted * Returns pointer to item, or NULL when there is no more * Note : errors are logged, but not returned // TODO partially share with acls.c */ static struct XATTRMAPPING *getmappingitem(FILEREADER reader, void *fileid, off_t *poffs, char *buf, int *psrc, s64 *psize) { int src; int dst; char *pe; char *ps; char *pu; enum SYSTEMXATTRS xattr; int gotend; char maptext[LINESZ]; struct XATTRMAPPING *item; src = *psrc; dst = 0; do { gotend = 0; while ((src < *psize) && (buf[src] != '\n')) { /* ignore spaces */ if ((dst < LINESZ) && (buf[src] != '\r') && (buf[src] != '\t') && (buf[src] != ' ')) maptext[dst++] = buf[src]; src++; } if (src >= *psize) { *poffs += *psize; *psize = reader(fileid, buf, (size_t)BUFSZ, *poffs); src = 0; } else { gotend = 1; src++; maptext[dst] = '\0'; dst = 0; } } while (*psize && ((maptext[0] == '#') || !gotend)); item = (struct XATTRMAPPING*)NULL; if (gotend) { /* decompose into system name and user name */ ps = maptext; pu = strchr(maptext,':'); if (pu) { *pu++ = 0; pe = strchr(pu,':'); if (pe) *pe = 0; /* check name validity */ if ((strlen(pu) < 6) || strncmp(pu,"user.",5)) pu = (char*)NULL; xattr = ntfs_xattr_system_type(ps, (ntfs_volume*)NULL); if (xattr == XATTR_UNMAPPED) pu = (char*)NULL; } if (pu) { item = (struct XATTRMAPPING*)ntfs_malloc( sizeof(struct XATTRMAPPING) + strlen(pu)); if (item) { item->xattr = xattr; strcpy(item->name,pu); item->next = (struct XATTRMAPPING*)NULL; } } else { ntfs_log_early_error("Bad xattr mapping item, aborting\n"); } } *psrc = src; return (item); } /* * Read xattr mapping file and split into their attribute. * Parameters are kept in a chained list. * Returns the head of list, if any * Errors are logged, but not returned * * If an absolute path is provided, the mapping file is assumed * to be located in another mounted file system, and plain read() * are used to get its contents. * If a relative path is provided, the mapping file is assumed * to be located on the current file system, and internal IO * have to be used since we are still mounting and we have not * entered the fuse loop yet. */ static struct XATTRMAPPING *ntfs_read_xattr_mapping(FILEREADER reader, void *fileid) { char buf[BUFSZ]; struct XATTRMAPPING *item; struct XATTRMAPPING *current; struct XATTRMAPPING *firstitem; struct XATTRMAPPING *lastitem; BOOL duplicated; int src; off_t offs; s64 size; firstitem = (struct XATTRMAPPING*)NULL; lastitem = (struct XATTRMAPPING*)NULL; offs = 0; size = reader(fileid, buf, (size_t)BUFSZ, (off_t)0); if (size > 0) { src = 0; do { item = getmappingitem(reader, fileid, &offs, buf, &src, &size); if (item) { /* check no double mapping */ duplicated = FALSE; for (current=firstitem; current; current=current->next) if ((current->xattr == item->xattr) || !strcmp(current->name,item->name)) duplicated = TRUE; if (duplicated) { free(item); ntfs_log_early_error("Conflicting xattr mapping ignored\n"); } else { item->next = (struct XATTRMAPPING*)NULL; if (lastitem) lastitem->next = item; else firstitem = item; lastitem = item; } } } while (item); } return (firstitem); } /* * Build the extended attribute mappings to user namespace * * Note : no error is returned. If we refused mounting when there * is an error it would be too difficult to fix the offending file */ struct XATTRMAPPING *ntfs_xattr_build_mapping(ntfs_volume *vol, const char *xattrmap_path) { struct XATTRMAPPING *firstmapping; struct XATTRMAPPING *mapping; BOOL user_efs; BOOL notfound; ntfs_inode *ni; int fd; firstmapping = (struct XATTRMAPPING*)NULL; notfound = FALSE; if (!xattrmap_path) xattrmap_path = XATTRMAPPINGFILE; if (xattrmap_path[0] == '/') { fd = open(xattrmap_path,O_RDONLY); if (fd > 0) { firstmapping = ntfs_read_xattr_mapping(basicread, (void*)&fd); close(fd); } else notfound = TRUE; } else { ni = ntfs_pathname_to_inode(vol, NULL, xattrmap_path); if (ni) { firstmapping = ntfs_read_xattr_mapping(localread, ni); ntfs_inode_close(ni); } else notfound = TRUE; } if (notfound && strcmp(xattrmap_path, XATTRMAPPINGFILE)) { ntfs_log_early_error("Could not open \"%s\"\n",xattrmap_path); } if (vol->efs_raw) { user_efs = TRUE; for (mapping=firstmapping; mapping; mapping=mapping->next) if (mapping->xattr == XATTR_NTFS_EFSINFO) user_efs = FALSE; } else user_efs = FALSE; if (user_efs) { mapping = (struct XATTRMAPPING*)ntfs_malloc( sizeof(struct XATTRMAPPING) + strlen(nf_ns_alt_xattr_efsinfo)); if (mapping) { mapping->next = firstmapping; mapping->xattr = XATTR_NTFS_EFSINFO; strcpy(mapping->name,nf_ns_alt_xattr_efsinfo); firstmapping = mapping; } } return (firstmapping); } void ntfs_xattr_free_mapping(struct XATTRMAPPING *mapping) { struct XATTRMAPPING *p, *q; p = mapping; while (p) { q = p->next; free(p); p = q; } } #endif /* XATTR_MAPPINGS */ /* * Get an NTFS attribute into an extended attribute * * Returns the non-negative size of attribute if successful, * or negative, with errno set, when fails * Note : the size is returned even if no buffer is provided * for returning the attribute, or if it is zero-sized. */ int ntfs_xattr_system_getxattr(struct SECURITY_CONTEXT *scx, enum SYSTEMXATTRS attr, ntfs_inode *ni, ntfs_inode *dir_ni, char *value, size_t size) { int res; int i; #if POSIXACLS #if __BYTE_ORDER == __BIG_ENDIAN struct POSIX_ACL *acl; #endif #endif switch (attr) { case XATTR_NTFS_ACL : res = ntfs_get_ntfs_acl(scx, ni, value, size); break; #if POSIXACLS #if __BYTE_ORDER == __BIG_ENDIAN case XATTR_POSIX_ACC : acl = (struct POSIX_ACL*)ntfs_malloc(size); if (acl) { res = ntfs_get_posix_acl(scx, ni, nf_ns_xattr_posix_access, (char*)acl, size); if (res > 0) { if (cpu_to_le_acl(acl,res, (struct LE_POSIX_ACL*)value)) res = -errno; } free(acl); } else res = -errno; break; case XATTR_POSIX_DEF : acl = (struct POSIX_ACL*)ntfs_malloc(size); if (acl) { res = ntfs_get_posix_acl(scx, ni, nf_ns_xattr_posix_default, (char*)acl, size); if (res > 0) { if (cpu_to_le_acl(acl,res, (struct LE_POSIX_ACL*)value)) res = -errno; } free(acl); } else res = -errno; break; #else case XATTR_POSIX_ACC : res = ntfs_get_posix_acl(scx, ni, nf_ns_xattr_posix_access, value, size); break; case XATTR_POSIX_DEF : res = ntfs_get_posix_acl(scx, ni, nf_ns_xattr_posix_default, value, size); break; #endif #endif case XATTR_NTFS_ATTRIB : res = ntfs_get_ntfs_attrib(ni, value, size); break; case XATTR_NTFS_ATTRIB_BE : res = ntfs_get_ntfs_attrib(ni, value, size); if ((res == 4) && value) { if (size >= 4) fix_big_endian(value,4); else res = -EINVAL; } break; case XATTR_NTFS_EFSINFO : if (ni->vol->efs_raw) res = ntfs_get_efs_info(ni, value, size); else res = -EPERM; break; case XATTR_NTFS_REPARSE_DATA : res = ntfs_get_ntfs_reparse_data(ni, value, size); break; case XATTR_NTFS_OBJECT_ID : res = ntfs_get_ntfs_object_id(ni, value, size); break; case XATTR_NTFS_DOS_NAME: if (dir_ni) res = ntfs_get_ntfs_dos_name(ni, dir_ni, value, size); else res = -errno; break; case XATTR_NTFS_TIMES: res = ntfs_inode_get_times(ni, value, size); break; case XATTR_NTFS_TIMES_BE: res = ntfs_inode_get_times(ni, value, size); if ((res > 0) && value) { for (i=0; (i+1)*sizeof(u64)<=(unsigned int)res; i++) fix_big_endian(&value[i*sizeof(u64)], sizeof(u64)); } break; case XATTR_NTFS_CRTIME: res = ntfs_inode_get_times(ni, value, (size >= sizeof(u64) ? sizeof(u64) : size)); break; case XATTR_NTFS_CRTIME_BE: res = ntfs_inode_get_times(ni, value, (size >= sizeof(u64) ? sizeof(u64) : size)); if ((res >= (int)sizeof(u64)) && value) fix_big_endian(value,sizeof(u64)); break; case XATTR_NTFS_EA : res = ntfs_get_ntfs_ea(ni, value, size); break; default : errno = EOPNOTSUPP; res = -errno; break; } return (res); } /* * Set an NTFS attribute from an extended attribute * * Returns 0 if successful, * non-zero, with errno set, when fails */ int ntfs_xattr_system_setxattr(struct SECURITY_CONTEXT *scx, enum SYSTEMXATTRS attr, ntfs_inode *ni, ntfs_inode *dir_ni, const char *value, size_t size, int flags) { int res; int i; char buf[4*sizeof(u64)]; #if POSIXACLS #if __BYTE_ORDER == __BIG_ENDIAN struct POSIX_ACL *acl; #endif #endif switch (attr) { case XATTR_NTFS_ACL : res = ntfs_set_ntfs_acl(scx, ni, value, size, flags); break; #if POSIXACLS #if __BYTE_ORDER == __BIG_ENDIAN case XATTR_POSIX_ACC : acl = (struct POSIX_ACL*)ntfs_malloc(size); if (acl) { if (!le_acl_to_cpu((const struct LE_POSIX_ACL*)value, size, acl)) { res = ntfs_set_posix_acl(scx ,ni , nf_ns_xattr_posix_access, (char*)acl, size, flags); } else res = -errno; free(acl); } else res = -errno; break; case XATTR_POSIX_DEF : acl = (struct POSIX_ACL*)ntfs_malloc(size); if (acl) { if (!le_acl_to_cpu((const struct LE_POSIX_ACL*)value, size, acl)) { res = ntfs_set_posix_acl(scx ,ni , nf_ns_xattr_posix_default, (char*)acl, size, flags); } else res = -errno; free(acl); } else res = -errno; break; #else case XATTR_POSIX_ACC : res = ntfs_set_posix_acl(scx ,ni , nf_ns_xattr_posix_access, value, size, flags); break; case XATTR_POSIX_DEF : res = ntfs_set_posix_acl(scx, ni, nf_ns_xattr_posix_default, value, size, flags); break; #endif #endif case XATTR_NTFS_ATTRIB : res = ntfs_set_ntfs_attrib(ni, value, size, flags); break; case XATTR_NTFS_ATTRIB_BE : if (value && (size >= 4)) { memcpy(buf,value,4); fix_big_endian(buf,4); res = ntfs_set_ntfs_attrib(ni, buf, 4, flags); } else res = ntfs_set_ntfs_attrib(ni, value, size, flags); break; case XATTR_NTFS_EFSINFO : if (ni->vol->efs_raw) res = ntfs_set_efs_info(ni, value, size, flags); else { errno = EPERM; res = -EPERM; } break; case XATTR_NTFS_REPARSE_DATA : res = ntfs_set_ntfs_reparse_data(ni, value, size, flags); break; case XATTR_NTFS_OBJECT_ID : res = ntfs_set_ntfs_object_id(ni, value, size, flags); break; case XATTR_NTFS_DOS_NAME: if (dir_ni) /* warning : this closes both inodes */ res = ntfs_set_ntfs_dos_name(ni, dir_ni, value, size, flags); else { errno = EINVAL; res = -errno; } break; case XATTR_NTFS_TIMES: res = ntfs_inode_set_times(ni, value, size, flags); break; case XATTR_NTFS_TIMES_BE: if (value && (size > 0) && (size <= 4*sizeof(u64))) { memcpy(buf,value,size); for (i=0; (i+1)*sizeof(u64)<=size; i++) fix_big_endian(&buf[i*sizeof(u64)], sizeof(u64)); res = ntfs_inode_set_times(ni, buf, size, flags); } else res = ntfs_inode_set_times(ni, value, size, flags); break; case XATTR_NTFS_CRTIME: res = ntfs_inode_set_times(ni, value, (size >= sizeof(u64) ? sizeof(u64) : size), flags); break; case XATTR_NTFS_CRTIME_BE: if (value && (size >= sizeof(u64))) { memcpy(buf,value,sizeof(u64)); fix_big_endian(buf,sizeof(u64)); res = ntfs_inode_set_times(ni, buf, sizeof(u64), flags); } else res = ntfs_inode_set_times(ni, value, size, flags); break; case XATTR_NTFS_EA : res = ntfs_set_ntfs_ea(ni, value, size, flags); break; default : errno = EOPNOTSUPP; res = -errno; break; } return (res); } int ntfs_xattr_system_removexattr(struct SECURITY_CONTEXT *scx, enum SYSTEMXATTRS attr, ntfs_inode *ni, ntfs_inode *dir_ni) { int res; res = 0; switch (attr) { /* * Removal of NTFS ACL, ATTRIB, EFSINFO or TIMES * is never allowed */ case XATTR_NTFS_ACL : case XATTR_NTFS_ATTRIB : case XATTR_NTFS_ATTRIB_BE : case XATTR_NTFS_EFSINFO : case XATTR_NTFS_TIMES : case XATTR_NTFS_TIMES_BE : case XATTR_NTFS_CRTIME : case XATTR_NTFS_CRTIME_BE : res = -EPERM; break; #if POSIXACLS case XATTR_POSIX_ACC : case XATTR_POSIX_DEF : if (ni) { if (!ntfs_allowed_as_owner(scx, ni) || ntfs_remove_posix_acl(scx, ni, (attr == XATTR_POSIX_ACC ? nf_ns_xattr_posix_access : nf_ns_xattr_posix_default))) res = -errno; } else res = -errno; break; #endif case XATTR_NTFS_REPARSE_DATA : if (ni) { if (!ntfs_allowed_as_owner(scx, ni) || ntfs_remove_ntfs_reparse_data(ni)) res = -errno; } else res = -errno; break; case XATTR_NTFS_OBJECT_ID : if (ni) { if (!ntfs_allowed_as_owner(scx, ni) || ntfs_remove_ntfs_object_id(ni)) res = -errno; } else res = -errno; break; case XATTR_NTFS_DOS_NAME: if (ni && dir_ni) { if (ntfs_remove_ntfs_dos_name(ni,dir_ni)) res = -errno; /* ni and dir_ni have been closed */ } else res = -errno; break; case XATTR_NTFS_EA : res = ntfs_remove_ntfs_ea(ni); break; default : errno = EOPNOTSUPP; res = -errno; break; } return (res); } ntfs-3g-2026.2.25/libntfs-3g/security.c0000664000175000017500000042436215152260173012776 /** * security.c - Handling security/ACLs in NTFS. Originated from the Linux-NTFS project. * * Copyright (c) 2004 Anton Altaparmakov * Copyright (c) 2005-2006 Szabolcs Szakacsits * Copyright (c) 2006 Yura Pakhuchiy * Copyright (c) 2007-2015 Jean-Pierre Andre * * This program/include file 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/include file 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_STDIO_H #include #endif #ifdef HAVE_STDLIB_H #include #endif #ifdef HAVE_STRING_H #include #endif #ifdef HAVE_ERRNO_H #include #endif #ifdef HAVE_FCNTL_H #include #endif #ifdef HAVE_SYS_STAT_H #include #endif #include #include #include #include "compat.h" #include "param.h" #include "types.h" #include "layout.h" #include "attrib.h" #include "index.h" #include "dir.h" #include "bitmap.h" #include "security.h" #include "acls.h" #include "cache.h" #include "misc.h" #include "xattrs.h" /* * JPA NTFS constants or structs * should be moved to layout.h */ #define ALIGN_SDS_BLOCK 0x40000 /* Alignment for a $SDS block */ #define ALIGN_SDS_ENTRY 16 /* Alignment for a $SDS entry */ #define STUFFSZ 0x4000 /* unitary stuffing size for $SDS */ #define FIRST_SECURITY_ID 0x100 /* Lowest security id */ /* Mask for attributes which can be forced */ #define FILE_ATTR_SETTABLE ( FILE_ATTR_READONLY \ | FILE_ATTR_HIDDEN \ | FILE_ATTR_SYSTEM \ | FILE_ATTR_ARCHIVE \ | FILE_ATTR_TEMPORARY \ | FILE_ATTR_OFFLINE \ | FILE_ATTR_NOT_CONTENT_INDEXED ) struct SII { /* this is an image of an $SII index entry */ le16 offs; le16 size; le32 fill1; le16 indexsz; le16 indexksz; le16 flags; le16 fill2; le32 keysecurid; /* did not find official description for the following */ le32 hash; le32 securid; le32 dataoffsl; /* documented as badly aligned */ le32 dataoffsh; le32 datasize; } ; struct SDH { /* this is an image of an $SDH index entry */ le16 offs; le16 size; le32 fill1; le16 indexsz; le16 indexksz; le16 flags; le16 fill2; le32 keyhash; le32 keysecurid; /* did not find official description for the following */ le32 hash; le32 securid; le32 dataoffsl; le32 dataoffsh; le32 datasize; le32 fill3; } ; /* * A few useful constants */ static ntfschar sii_stream[] = { const_cpu_to_le16('$'), const_cpu_to_le16('S'), const_cpu_to_le16('I'), const_cpu_to_le16('I'), const_cpu_to_le16(0) }; static ntfschar sdh_stream[] = { const_cpu_to_le16('$'), const_cpu_to_le16('S'), const_cpu_to_le16('D'), const_cpu_to_le16('H'), const_cpu_to_le16(0) }; /* * null SID (S-1-0-0) */ extern const SID *nullsid; /* * The zero GUID. */ static const GUID __zero_guid = { const_cpu_to_le32(0), const_cpu_to_le16(0), const_cpu_to_le16(0), { 0, 0, 0, 0, 0, 0, 0, 0 } }; static const GUID *const zero_guid = &__zero_guid; /** * ntfs_guid_is_zero - check if a GUID is zero * @guid: [IN] guid to check * * Return TRUE if @guid is a valid pointer to a GUID and it is the zero GUID * and FALSE otherwise. */ BOOL ntfs_guid_is_zero(const GUID *guid) { return (memcmp(guid, zero_guid, sizeof(*zero_guid))); } /** * ntfs_guid_to_mbs - convert a GUID to a multi byte string * @guid: [IN] guid to convert * @guid_str: [OUT] string in which to return the GUID (optional) * * Convert the GUID pointed to by @guid to a multi byte string of the form * "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX". Therefore, @guid_str (if not NULL) * needs to be able to store at least 37 bytes. * * If @guid_str is not NULL it will contain the converted GUID on return. If * it is NULL a string will be allocated and this will be returned. The caller * is responsible for free()ing the string in that case. * * On success return the converted string and on failure return NULL with errno * set to the error code. */ char *ntfs_guid_to_mbs(const GUID *guid, char *guid_str) { char *_guid_str; int res; if (!guid) { errno = EINVAL; return NULL; } _guid_str = guid_str; if (!_guid_str) { _guid_str = (char*)ntfs_malloc(37); if (!_guid_str) return _guid_str; } res = snprintf(_guid_str, 37, "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x", (unsigned int)le32_to_cpu(guid->data1), le16_to_cpu(guid->data2), le16_to_cpu(guid->data3), guid->data4[0], guid->data4[1], guid->data4[2], guid->data4[3], guid->data4[4], guid->data4[5], guid->data4[6], guid->data4[7]); if (res == 36) return _guid_str; if (!guid_str) free(_guid_str); errno = EINVAL; return NULL; } /** * ntfs_sid_to_mbs_size - determine maximum size for the string of a SID * @sid: [IN] SID for which to determine the maximum string size * * Determine the maximum multi byte string size in bytes which is needed to * store the standard textual representation of the SID pointed to by @sid. * See ntfs_sid_to_mbs(), below. * * On success return the maximum number of bytes needed to store the multi byte * string and on failure return -1 with errno set to the error code. */ int ntfs_sid_to_mbs_size(const SID *sid) { int size, i; if (!ntfs_valid_sid(sid)) { errno = EINVAL; return -1; } /* Start with "S-". */ size = 2; /* * Add the SID_REVISION. Hopefully the compiler will optimize this * away as SID_REVISION is a constant. */ for (i = SID_REVISION; i > 0; i /= 10) size++; /* Add the "-". */ size++; /* * Add the identifier authority. If it needs to be in decimal, the * maximum is 2^32-1 = 4294967295 = 10 characters. If it needs to be * in hexadecimal, then maximum is 0x665544332211 = 14 characters. */ if (!sid->identifier_authority.high_part) size += 10; else size += 14; /* * Finally, add the sub authorities. For each we have a "-" followed * by a decimal which can be up to 2^32-1 = 4294967295 = 10 characters. */ size += (1 + 10) * sid->sub_authority_count; /* We need the zero byte at the end, too. */ size++; return size * sizeof(char); } /** * ntfs_sid_to_mbs - convert a SID to a multi byte string * @sid: [IN] SID to convert * @sid_str: [OUT] string in which to return the SID (optional) * @sid_str_size: [IN] size in bytes of @sid_str * * Convert the SID pointed to by @sid to its standard textual representation. * @sid_str (if not NULL) needs to be able to store at least * ntfs_sid_to_mbs_size() bytes. @sid_str_size is the size in bytes of * @sid_str if @sid_str is not NULL. * * The standard textual representation of the SID is of the form: * S-R-I-S-S... * Where: * - The first "S" is the literal character 'S' identifying the following * digits as a SID. * - R is the revision level of the SID expressed as a sequence of digits * in decimal. * - I is the 48-bit identifier_authority, expressed as digits in decimal, * if I < 2^32, or hexadecimal prefixed by "0x", if I >= 2^32. * - S... is one or more sub_authority values, expressed as digits in * decimal. * * If @sid_str is not NULL it will contain the converted SUID on return. If it * is NULL a string will be allocated and this will be returned. The caller is * responsible for free()ing the string in that case. * * On success return the converted string and on failure return NULL with errno * set to the error code. */ char *ntfs_sid_to_mbs(const SID *sid, char *sid_str, size_t sid_str_size) { u64 u; le32 leauth; char *s; int i, j, cnt; /* * No need to check @sid if !@sid_str since ntfs_sid_to_mbs_size() will * check @sid, too. 8 is the minimum SID string size. */ if (sid_str && (sid_str_size < 8 || !ntfs_valid_sid(sid))) { errno = EINVAL; return NULL; } /* Allocate string if not provided. */ if (!sid_str) { cnt = ntfs_sid_to_mbs_size(sid); if (cnt < 0) return NULL; s = (char*)ntfs_malloc(cnt); if (!s) return s; sid_str = s; /* So we know we allocated it. */ sid_str_size = 0; } else { s = sid_str; cnt = sid_str_size; } /* Start with "S-R-". */ i = snprintf(s, cnt, "S-%hhu-", (unsigned char)sid->revision); if (i < 0 || i >= cnt) goto err_out; s += i; cnt -= i; /* Add the identifier authority. */ for (u = i = 0, j = 40; i < 6; i++, j -= 8) u += (u64)sid->identifier_authority.value[i] << j; if (!sid->identifier_authority.high_part) i = snprintf(s, cnt, "%lu", (unsigned long)u); else i = snprintf(s, cnt, "0x%llx", (unsigned long long)u); if (i < 0 || i >= cnt) goto err_out; s += i; cnt -= i; /* Finally, add the sub authorities. */ for (j = 0; j < sid->sub_authority_count; j++) { leauth = sid->sub_authority[j]; i = snprintf(s, cnt, "-%u", (unsigned int) le32_to_cpu(leauth)); if (i < 0 || i >= cnt) goto err_out; s += i; cnt -= i; } return sid_str; err_out: if (i >= cnt) i = EMSGSIZE; else i = errno; if (!sid_str_size) free(sid_str); errno = i; return NULL; } /** * ntfs_generate_guid - generatates a random current guid. * @guid: [OUT] pointer to a GUID struct to hold the generated guid. * * perhaps not a very good random number generator though... */ void ntfs_generate_guid(GUID *guid) { unsigned int i; u8 *p = (u8 *)guid; /* this is called at most once from mkntfs */ srandom(time((time_t*)NULL) ^ (getpid() << 16)); for (i = 0; i < sizeof(GUID); i++) { p[i] = (u8)(random() & 0xFF); if (i == 7) p[7] = (p[7] & 0x0F) | 0x40; if (i == 8) p[8] = (p[8] & 0x3F) | 0x80; } } /** * ntfs_security_hash - calculate the hash of a security descriptor * @sd: self-relative security descriptor whose hash to calculate * @length: size in bytes of the security descritor @sd * * Calculate the hash of the self-relative security descriptor @sd of length * @length bytes. * * This hash is used in the $Secure system file as the primary key for the $SDH * index and is also stored in the header of each security descriptor in the * $SDS data stream as well as in the index data of both the $SII and $SDH * indexes. In all three cases it forms part of the SDS_ENTRY_HEADER * structure. * * Return the calculated security hash in little endian. */ le32 ntfs_security_hash(const SECURITY_DESCRIPTOR_RELATIVE *sd, const u32 len) { const le32 *pos = (const le32*)sd; const le32 *end = pos + (len >> 2); u32 hash = 0; while (pos < end) { hash = le32_to_cpup(pos) + ntfs_rol32(hash, 3); pos++; } return cpu_to_le32(hash); } /* * Get the first entry of current index block * cut and pasted form ntfs_ie_get_first() in index.c */ static INDEX_ENTRY *ntfs_ie_get_first(INDEX_HEADER *ih) { return (INDEX_ENTRY*)((u8*)ih + le32_to_cpu(ih->entries_offset)); } /* * Stuff a 256KB block into $SDS before writing descriptors * into the block. * * This prevents $SDS from being automatically declared as sparse * when the second copy of the first security descriptor is written * 256KB further ahead. * * Having $SDS declared as a sparse file is not wrong by itself * and chkdsk leaves it as a sparse file. It does however complain * and add a sparse flag (0x0200) into field file_attributes of * STANDARD_INFORMATION of $Secure. This probably means that a * sparse attribute (ATTR_IS_SPARSE) is only allowed in sparse * files (FILE_ATTR_SPARSE_FILE). * * Windows normally does not convert to sparse attribute or sparse * file. Stuffing is just a way to get to the same result. */ static int entersecurity_stuff(ntfs_volume *vol, off_t offs) { int res; int written; unsigned long total; char *stuff; res = 0; total = 0; stuff = (char*)ntfs_malloc(STUFFSZ); if (stuff) { memset(stuff, 0, STUFFSZ); do { written = ntfs_attr_data_write(vol->secure_ni, STREAM_SDS, 4, stuff, STUFFSZ, offs); if (written == STUFFSZ) { total += STUFFSZ; offs += STUFFSZ; } else { errno = ENOSPC; res = -1; } } while (!res && (total < ALIGN_SDS_BLOCK)); free(stuff); } else { errno = ENOMEM; res = -1; } return (res); } /* * Enter a new security descriptor into $Secure (data only) * it has to be written twice with an offset of 256KB * * Should only be called by entersecurityattr() to ensure consistency * * Returns zero if sucessful */ static int entersecurity_data(ntfs_volume *vol, const SECURITY_DESCRIPTOR_RELATIVE *attr, s64 attrsz, le32 hash, le32 keyid, off_t offs, int gap) { int res; int written1; int written2; char *fullattr; int fullsz; SECURITY_DESCRIPTOR_HEADER *phsds; res = -1; fullsz = attrsz + gap + sizeof(SECURITY_DESCRIPTOR_HEADER); fullattr = (char*)ntfs_malloc(fullsz); if (fullattr) { /* * Clear the gap from previous descriptor * this could be useful for appending the second * copy to the end of file. When creating a new * 256K block, the gap is cleared while writing * the first copy */ if (gap) memset(fullattr,0,gap); memcpy(&fullattr[gap + sizeof(SECURITY_DESCRIPTOR_HEADER)], attr,attrsz); phsds = (SECURITY_DESCRIPTOR_HEADER*)&fullattr[gap]; phsds->hash = hash; phsds->security_id = keyid; phsds->offset = cpu_to_le64(offs); phsds->length = cpu_to_le32(fullsz - gap); written1 = ntfs_attr_data_write(vol->secure_ni, STREAM_SDS, 4, fullattr, fullsz, offs - gap); written2 = ntfs_attr_data_write(vol->secure_ni, STREAM_SDS, 4, fullattr, fullsz, offs - gap + ALIGN_SDS_BLOCK); if ((written1 == fullsz) && (written2 == written1)) { /* * Make sure the data size for $SDS marks the end * of the last security attribute. Windows uses * this to determine where the next attribute will * be written, which causes issues if chkdsk had * previously deleted the last entries without * adjusting the size. */ res = ntfs_attr_shrink_size(vol->secure_ni,STREAM_SDS, 4, offs - gap + ALIGN_SDS_BLOCK + fullsz); } else errno = ENOSPC; free(fullattr); } else errno = ENOMEM; return (res); } /* * Enter a new security descriptor in $Secure (indexes only) * * Should only be called by entersecurityattr() to ensure consistency * * Returns zero if sucessful */ static int entersecurity_indexes(ntfs_volume *vol, s64 attrsz, le32 hash, le32 keyid, off_t offs) { union { struct { le32 dataoffsl; le32 dataoffsh; } parts; le64 all; } realign; int res; ntfs_index_context *xsii; ntfs_index_context *xsdh; struct SII newsii; struct SDH newsdh; res = -1; /* enter a new $SII record */ xsii = vol->secure_xsii; ntfs_index_ctx_reinit(xsii); newsii.offs = const_cpu_to_le16(20); newsii.size = const_cpu_to_le16(sizeof(struct SII) - 20); newsii.fill1 = const_cpu_to_le32(0); newsii.indexsz = const_cpu_to_le16(sizeof(struct SII)); newsii.indexksz = const_cpu_to_le16(sizeof(SII_INDEX_KEY)); newsii.flags = const_cpu_to_le16(0); newsii.fill2 = const_cpu_to_le16(0); newsii.keysecurid = keyid; newsii.hash = hash; newsii.securid = keyid; realign.all = cpu_to_le64(offs); newsii.dataoffsh = realign.parts.dataoffsh; newsii.dataoffsl = realign.parts.dataoffsl; newsii.datasize = cpu_to_le32(attrsz + sizeof(SECURITY_DESCRIPTOR_HEADER)); if (!ntfs_ie_add(xsii,(INDEX_ENTRY*)&newsii)) { /* enter a new $SDH record */ xsdh = vol->secure_xsdh; ntfs_index_ctx_reinit(xsdh); newsdh.offs = const_cpu_to_le16(24); newsdh.size = const_cpu_to_le16( sizeof(SECURITY_DESCRIPTOR_HEADER)); newsdh.fill1 = const_cpu_to_le32(0); newsdh.indexsz = const_cpu_to_le16( sizeof(struct SDH)); newsdh.indexksz = const_cpu_to_le16( sizeof(SDH_INDEX_KEY)); newsdh.flags = const_cpu_to_le16(0); newsdh.fill2 = const_cpu_to_le16(0); newsdh.keyhash = hash; newsdh.keysecurid = keyid; newsdh.hash = hash; newsdh.securid = keyid; newsdh.dataoffsh = realign.parts.dataoffsh; newsdh.dataoffsl = realign.parts.dataoffsl; newsdh.datasize = cpu_to_le32(attrsz + sizeof(SECURITY_DESCRIPTOR_HEADER)); /* special filler value, Windows generally */ /* fills with 0x00490049, sometimes with zero */ newsdh.fill3 = const_cpu_to_le32(0x00490049); if (!ntfs_ie_add(xsdh,(INDEX_ENTRY*)&newsdh)) res = 0; } return (res); } /* * Enter a new security descriptor in $Secure (data and indexes) * Returns id of entry, or zero if there is a problem. * (should not be called for NTFS version < 3.0) * * important : calls have to be serialized, however no locking is * needed while fuse is not multithreaded */ static le32 entersecurityattr(ntfs_volume *vol, const SECURITY_DESCRIPTOR_RELATIVE *attr, s64 attrsz, le32 hash) { union { struct { le32 dataoffsl; le32 dataoffsh; } parts; le64 all; } realign; le32 securid; le32 keyid; u32 newkey; off_t offs; int gap; int size; BOOL found; struct SII *psii; INDEX_ENTRY *entry; INDEX_ENTRY *next; ntfs_index_context *xsii; int retries; ntfs_attr *na; int olderrno; /* find the first available securid beyond the last key */ /* in $Secure:$SII. This also determines the first */ /* available location in $Secure:$SDS, as this stream */ /* is always appended to and the id's are allocated */ /* in sequence */ securid = const_cpu_to_le32(0); xsii = vol->secure_xsii; ntfs_index_ctx_reinit(xsii); offs = size = 0; keyid = const_cpu_to_le32(-1); olderrno = errno; found = !ntfs_index_lookup((char*)&keyid, sizeof(SII_INDEX_KEY), xsii); if (!found && (errno != ENOENT)) { ntfs_log_perror("Inconsistency in index $SII"); psii = (struct SII*)NULL; } else { /* restore errno to avoid misinterpretation */ errno = olderrno; entry = xsii->entry; psii = (struct SII*)xsii->entry; } if (psii) { /* * Get last entry in block, but must get first one * one first, as we should already be beyond the * last one. For some reason the search for the last * entry sometimes does not return the last block... * we assume this can only happen in root block */ if (xsii->is_in_root) entry = ntfs_ie_get_first ((INDEX_HEADER*)&xsii->ir->index); else entry = ntfs_ie_get_first ((INDEX_HEADER*)&xsii->ib->index); /* * All index blocks should be at least half full * so there always is a last entry but one, * except when creating the first entry in index root. * This was however found not to be true : chkdsk * sometimes deletes all the (unused) keys in the last * index block without rebalancing the tree. * When this happens, a new search is restarted from * the smallest key. */ keyid = const_cpu_to_le32(0); retries = 0; while (entry) { next = ntfs_index_next(entry,xsii); if (next) { psii = (struct SII*)next; /* save last key and */ /* available position */ keyid = psii->keysecurid; realign.parts.dataoffsh = psii->dataoffsh; realign.parts.dataoffsl = psii->dataoffsl; offs = le64_to_cpu(realign.all); size = le32_to_cpu(psii->datasize); } entry = next; if (!entry && !keyid && !retries) { /* search failed, retry from smallest key */ ntfs_index_ctx_reinit(xsii); found = !ntfs_index_lookup((char*)&keyid, sizeof(SII_INDEX_KEY), xsii); if (!found && (errno != ENOENT)) { ntfs_log_perror("Index $SII is broken"); psii = (struct SII*)NULL; } else { /* restore errno */ errno = olderrno; entry = xsii->entry; psii = (struct SII*)entry; } if (psii && !(psii->flags & INDEX_ENTRY_END)) { /* save first key and */ /* available position */ keyid = psii->keysecurid; realign.parts.dataoffsh = psii->dataoffsh; realign.parts.dataoffsl = psii->dataoffsl; offs = le64_to_cpu(realign.all); size = le32_to_cpu(psii->datasize); } retries++; } } } if (!keyid) { /* * could not find any entry, before creating the first * entry, make a double check by making sure size of $SII * is less than needed for one entry */ securid = const_cpu_to_le32(0); na = ntfs_attr_open(vol->secure_ni,AT_INDEX_ROOT,sii_stream,4); if (na) { if ((size_t)na->data_size < (sizeof(struct SII) + sizeof(INDEX_ENTRY_HEADER))) { ntfs_log_error("Creating the first security_id\n"); securid = const_cpu_to_le32(FIRST_SECURITY_ID); } ntfs_attr_close(na); } if (!securid) { ntfs_log_error("Error creating a security_id\n"); errno = EIO; } } else { newkey = le32_to_cpu(keyid) + 1; securid = cpu_to_le32(newkey); } /* * The security attr has to be written twice 256KB * apart. This implies that offsets like * 0x40000*odd_integer must be left available for * the second copy. So align to next block when * the last byte overflows on a wrong block. */ if (securid) { gap = (-size) & (ALIGN_SDS_ENTRY - 1); offs += gap + size; if ((offs + attrsz + sizeof(SECURITY_DESCRIPTOR_HEADER) - 1) & ALIGN_SDS_BLOCK) { offs = ((offs + attrsz + sizeof(SECURITY_DESCRIPTOR_HEADER) - 1) | (ALIGN_SDS_BLOCK - 1)) + 1; } if (!(offs & (ALIGN_SDS_BLOCK - 1))) entersecurity_stuff(vol, offs); /* * now write the security attr to storage : * first data, then SII, then SDH * If failure occurs while writing SDS, data will never * be accessed through indexes, and will be overwritten * by the next allocated descriptor * If failure occurs while writing SII, the id has not * recorded and will be reallocated later * If failure occurs while writing SDH, the space allocated * in SDS or SII will not be reused, an inconsistency * will persist with no significant consequence */ if (entersecurity_data(vol, attr, attrsz, hash, securid, offs, gap) || entersecurity_indexes(vol, attrsz, hash, securid, offs)) securid = const_cpu_to_le32(0); } /* inode now is dirty, synchronize it all */ ntfs_index_entry_mark_dirty(vol->secure_xsii); ntfs_index_ctx_reinit(vol->secure_xsii); ntfs_index_entry_mark_dirty(vol->secure_xsdh); ntfs_index_ctx_reinit(vol->secure_xsdh); NInoSetDirty(vol->secure_ni); if (ntfs_inode_sync(vol->secure_ni)) ntfs_log_perror("Could not sync $Secure\n"); return (securid); } /* * Find a matching security descriptor in $Secure, * if none, allocate a new id and write the descriptor to storage * Returns id of entry, or zero if there is a problem. * * important : calls have to be serialized, however no locking is * needed while fuse is not multithreaded */ static le32 setsecurityattr(ntfs_volume *vol, const SECURITY_DESCRIPTOR_RELATIVE *attr, s64 attrsz) { struct SDH *psdh; /* this is an image of index (le) */ union { struct { le32 dataoffsl; le32 dataoffsh; } parts; le64 all; } realign; BOOL found; BOOL collision; size_t size; size_t rdsize; s64 offs; int res; ntfs_index_context *xsdh; char *oldattr; SDH_INDEX_KEY key; INDEX_ENTRY *entry; le32 securid; le32 hash; int olderrno; hash = ntfs_security_hash(attr,attrsz); oldattr = (char*)NULL; securid = const_cpu_to_le32(0); res = 0; xsdh = vol->secure_xsdh; if (vol->secure_ni && xsdh && !vol->secure_reentry++) { ntfs_index_ctx_reinit(xsdh); /* * find the nearest key as (hash,0) * (do not search for partial key : in case of collision, * it could return a key which is not the first one which * collides) */ key.hash = hash; key.security_id = const_cpu_to_le32(0); olderrno = errno; found = !ntfs_index_lookup((char*)&key, sizeof(SDH_INDEX_KEY), xsdh); if (!found && (errno != ENOENT)) ntfs_log_perror("Inconsistency in index $SDH"); else { /* restore errno to avoid misinterpretation */ errno = olderrno; entry = xsdh->entry; found = FALSE; /* * lookup() may return a node with no data, * if so get next */ if (entry->ie_flags & INDEX_ENTRY_END) entry = ntfs_index_next(entry,xsdh); do { collision = FALSE; psdh = (struct SDH*)entry; if (psdh) size = (size_t) le32_to_cpu(psdh->datasize) - sizeof(SECURITY_DESCRIPTOR_HEADER); else size = 0; /* if hash is not the same, the key is not present */ if (psdh && (size > 0) && (psdh->keyhash == hash)) { /* if hash is the same */ /* check the whole record */ realign.parts.dataoffsh = psdh->dataoffsh; realign.parts.dataoffsl = psdh->dataoffsl; offs = le64_to_cpu(realign.all) + sizeof(SECURITY_DESCRIPTOR_HEADER); oldattr = (char*)ntfs_malloc(size); if (oldattr) { rdsize = ntfs_attr_data_read( vol->secure_ni, STREAM_SDS, 4, oldattr, size, offs); found = (rdsize == size) && !memcmp(oldattr,attr,size); free(oldattr); /* if the records do not compare */ /* (hash collision), try next one */ if (!found) { entry = ntfs_index_next( entry,xsdh); collision = TRUE; } } else res = ENOMEM; } } while (collision && entry); if (found) securid = psdh->keysecurid; else { if (res) { errno = res; securid = const_cpu_to_le32(0); } else { /* * no matching key : * have to build a new one */ securid = entersecurityattr(vol, attr, attrsz, hash); } } } } if (--vol->secure_reentry) ntfs_log_perror("Reentry error, check no multithreading\n"); return (securid); } /* * Update the security descriptor of a file * Either as an attribute (complying with pre v3.x NTFS version) * or, when possible, as an entry in $Secure (for NTFS v3.x) * * returns 0 if success */ static int update_secur_descr(ntfs_volume *vol, char *newattr, ntfs_inode *ni) { int newattrsz; int written; int res; ntfs_attr *na; newattrsz = ntfs_attr_size(newattr); #if !FORCE_FORMAT_v1x if ((vol->major_ver < 3) || !vol->secure_ni) { #endif /* update for NTFS format v1.x */ /* update the old security attribute */ na = ntfs_attr_open(ni, AT_SECURITY_DESCRIPTOR, AT_UNNAMED, 0); if (na) { /* resize attribute */ res = ntfs_attr_truncate(na, (s64) newattrsz); /* overwrite value */ if (!res) { written = (int)ntfs_attr_pwrite(na, (s64) 0, (s64) newattrsz, newattr); if (written != newattrsz) { ntfs_log_error("Failed to update " "a v1.x security descriptor\n"); errno = EIO; res = -1; } } ntfs_attr_close(na); /* if old security attribute was found, also */ /* truncate standard information attribute to v1.x */ /* this is needed when security data is wanted */ /* as v1.x though volume is formatted for v3.x */ na = ntfs_attr_open(ni, AT_STANDARD_INFORMATION, AT_UNNAMED, 0); if (na) { clear_nino_flag(ni, v3_Extensions); /* * Truncating the record does not sweep extensions * from copy in memory. Clear security_id to be safe */ ni->security_id = const_cpu_to_le32(0); res = ntfs_attr_truncate(na, (s64)48); ntfs_attr_close(na); clear_nino_flag(ni, v3_Extensions); } } else { /* * insert the new security attribute if there * were none */ res = ntfs_attr_add(ni, AT_SECURITY_DESCRIPTOR, AT_UNNAMED, 0, (u8*)newattr, (s64) newattrsz); } #if !FORCE_FORMAT_v1x } else { /* update for NTFS format v3.x */ le32 securid; securid = setsecurityattr(vol, (const SECURITY_DESCRIPTOR_RELATIVE*)newattr, (s64)newattrsz); if (securid) { na = ntfs_attr_open(ni, AT_STANDARD_INFORMATION, AT_UNNAMED, 0); if (na) { res = 0; if (!test_nino_flag(ni, v3_Extensions)) { /* expand standard information attribute to v3.x */ res = ntfs_attr_truncate(na, (s64)sizeof(STANDARD_INFORMATION)); ni->owner_id = const_cpu_to_le32(0); ni->quota_charged = const_cpu_to_le64(0); ni->usn = const_cpu_to_le64(0); ntfs_attr_remove(ni, AT_SECURITY_DESCRIPTOR, AT_UNNAMED, 0); } set_nino_flag(ni, v3_Extensions); ni->security_id = securid; ntfs_attr_close(na); } else { ntfs_log_error("Failed to update " "standard informations\n"); errno = EIO; res = -1; } } else res = -1; } #endif /* mark node as dirty */ NInoSetDirty(ni); return (res); } /* * Upgrade the security descriptor of a file * This is intended to allow graceful upgrades for files which * were created in previous versions, with a security attributes * and no security id. * * It will allocate a security id and replace the individual * security attribute by a reference to the global one * * Special files are not upgraded (currently / and files in * directories /$*) * * Though most code is similar to update_secur_desc() it has * been kept apart to facilitate the further processing of * special cases or even to remove it if found dangerous. * * returns 0 if success, * 1 if not upgradable. This is not an error. * -1 if there is a problem */ static int upgrade_secur_desc(ntfs_volume *vol, const char *attr, ntfs_inode *ni) { int attrsz; int res; le32 securid; ntfs_attr *na; /* * upgrade requires NTFS format v3.x * also refuse upgrading for special files * whose number is less than FILE_first_user */ if ((vol->major_ver >= 3) && (ni->mft_no >= FILE_first_user)) { attrsz = ntfs_attr_size(attr); securid = setsecurityattr(vol, (const SECURITY_DESCRIPTOR_RELATIVE*)attr, (s64)attrsz); if (securid) { na = ntfs_attr_open(ni, AT_STANDARD_INFORMATION, AT_UNNAMED, 0); if (na) { /* expand standard information attribute to v3.x */ res = ntfs_attr_truncate(na, (s64)sizeof(STANDARD_INFORMATION)); ni->owner_id = const_cpu_to_le32(0); ni->quota_charged = const_cpu_to_le64(0); ni->usn = const_cpu_to_le64(0); ntfs_attr_remove(ni, AT_SECURITY_DESCRIPTOR, AT_UNNAMED, 0); set_nino_flag(ni, v3_Extensions); ni->security_id = securid; ntfs_attr_close(na); } else { ntfs_log_error("Failed to upgrade " "standard informations\n"); errno = EIO; res = -1; } } else res = -1; /* mark node as dirty */ NInoSetDirty(ni); } else res = 1; return (res); } /* * Optional simplified checking of group membership * * This only takes into account the groups defined in * /etc/group at initialization time. * It does not take into account the groups dynamically set by * setgroups() nor the changes in /etc/group since initialization * * This optional method could be useful if standard checking * leads to a performance concern. * * Should not be called for user root, however the group may be root * */ static BOOL staticgroupmember(struct SECURITY_CONTEXT *scx, uid_t uid, gid_t gid) { BOOL ingroup; int grcnt; gid_t *groups; struct MAPPING *user; ingroup = FALSE; if (uid) { user = scx->mapping[MAPUSERS]; while (user && ((uid_t)user->xid != uid)) user = user->next; if (user) { groups = user->groups; grcnt = user->grcnt; while ((--grcnt >= 0) && (groups[grcnt] != gid)) { } ingroup = (grcnt >= 0); } } return (ingroup); } #if defined(__sun) && defined (__SVR4) /* * Check whether current thread owner is member of file group * Solaris/OpenIndiana version * Should not be called for user root, however the group may be root * * The group list is available in "/proc/$PID/cred" * */ static BOOL groupmember(struct SECURITY_CONTEXT *scx, uid_t uid, gid_t gid) { typedef struct prcred { uid_t pr_euid; /* effective user id */ uid_t pr_ruid; /* real user id */ uid_t pr_suid; /* saved user id (from exec) */ gid_t pr_egid; /* effective group id */ gid_t pr_rgid; /* real group id */ gid_t pr_sgid; /* saved group id (from exec) */ int pr_ngroups; /* number of supplementary groups */ gid_t pr_groups[1]; /* array of supplementary groups */ } prcred_t; enum { readset = 16 }; prcred_t basecreds; gid_t groups[readset]; char filename[64]; int fd; int k; int cnt; gid_t *p; BOOL ismember; int got; pid_t tid; if (scx->vol->secure_flags & (1 << SECURITY_STATICGRPS)) ismember = staticgroupmember(scx, uid, gid); else { ismember = FALSE; /* default return */ tid = scx->tid; sprintf(filename,"/proc/%u/cred",tid); fd = open(filename,O_RDONLY); if (fd >= 0) { got = read(fd, &basecreds, sizeof(prcred_t)); if (got == sizeof(prcred_t)) { if (basecreds.pr_egid == gid) ismember = TRUE; p = basecreds.pr_groups; cnt = 1; k = 0; while (!ismember && (k < basecreds.pr_ngroups) && (cnt > 0) && (*p != gid)) { k++; cnt--; p++; if (cnt <= 0) { got = read(fd, groups, readset*sizeof(gid_t)); cnt = got/sizeof(gid_t); p = groups; } } if ((cnt > 0) && (k < basecreds.pr_ngroups)) ismember = TRUE; } close(fd); } } return (ismember); } #else /* defined(__sun) && defined (__SVR4) */ /* * Check whether current thread owner is member of file group * Linux version * Should not be called for user root, however the group may be root * * As indicated by Miklos Szeredi : * * The group list is available in * * /proc/$PID/task/$TID/status * * and fuse supplies TID in get_fuse_context()->pid. The only problem is * finding out PID, for which I have no good solution, except to iterate * through all processes. This is rather slow, but may be speeded up * with caching and heuristics (for single threaded programs PID = TID). * * The following implementation gets the group list from * /proc/$TID/task/$TID/status which apparently exists and * contains the same data. */ static BOOL groupmember(struct SECURITY_CONTEXT *scx, uid_t uid, gid_t gid) { static char key[] = "\nGroups:"; char buf[BUFSZ+1]; char filename[64]; enum { INKEY, INSEP, INNUM, INEND } state; int fd; char c; int matched; BOOL ismember; int got; char *p; gid_t grp; pid_t tid; if (scx->vol->secure_flags & (1 << SECURITY_STATICGRPS)) ismember = staticgroupmember(scx, uid, gid); else { ismember = FALSE; /* default return */ tid = scx->tid; sprintf(filename,"/proc/%u/task/%u/status",tid,tid); fd = open(filename,O_RDONLY); if (fd >= 0) { got = read(fd, buf, BUFSZ); buf[got] = 0; state = INKEY; matched = 0; p = buf; grp = 0; /* * A simple automaton to process lines like * Groups: 14 500 513 */ do { c = *p++; if (!c) { /* refill buffer */ got = read(fd, buf, BUFSZ); buf[got] = 0; p = buf; c = *p++; /* 0 at end of file */ } switch (state) { case INKEY : if (key[matched] == c) { if (!key[++matched]) state = INSEP; } else if (key[0] == c) matched = 1; else matched = 0; break; case INSEP : if ((c >= '0') && (c <= '9')) { grp = c - '0'; state = INNUM; } else if ((c != ' ') && (c != '\t')) state = INEND; break; case INNUM : if ((c >= '0') && (c <= '9')) grp = grp*10 + c - '0'; else { ismember = (grp == gid); if ((c != ' ') && (c != '\t')) state = INEND; else state = INSEP; } default : break; } } while (!ismember && c && (state != INEND)); close(fd); if (!c) ntfs_log_error("No group record found in %s\n",filename); } else ntfs_log_error("Could not open %s\n",filename); } return (ismember); } #endif /* defined(__sun) && defined (__SVR4) */ #if POSIXACLS /* * Extract the basic permissions from a Posix ACL * * This is only to be used when Posix ACLs are compiled in, * but not enabled in the mount options. * * it replaces the permission mask by the group permissions. * If special groups are mapped, they are also considered as world. */ static int ntfs_basic_perms(const struct SECURITY_CONTEXT *scx, const struct POSIX_SECURITY *pxdesc) { int k; int perms; const struct POSIX_ACE *pace; const struct MAPPING* group; k = 0; perms = pxdesc->mode; for (k=0; k < pxdesc->acccnt; k++) { pace = &pxdesc->acl.ace[k]; if (pace->tag == POSIX_ACL_GROUP_OBJ) perms = (perms & 07707) | ((pace->perms & 7) << 3); else if (pace->tag == POSIX_ACL_GROUP) { group = scx->mapping[MAPGROUPS]; while (group && (group->xid != pace->id)) group = group->next; if (group && group->grcnt && (*(group->groups) == (gid_t)pace->id)) perms |= pace->perms & 7; } } return (perms); } #endif /* POSIXACLS */ /* * Cacheing is done two-way : * - from uid, gid and perm to securid (CACHED_SECURID) * - from a securid to uid, gid and perm (CACHED_PERMISSIONS) * * CACHED_SECURID data is kept in a most-recent-first list * which should not be too long to be efficient. Its optimal * size is depends on usage and is hard to determine. * * CACHED_PERMISSIONS data is kept in a two-level indexed array. It * is optimal at the expense of storage. Use of a most-recent-first * list would save memory and provide similar performances for * standard usage, but not for file servers with too many file * owners * * CACHED_PERMISSIONS_LEGACY is a special case for CACHED_PERMISSIONS * for legacy directories which were not allocated a security_id * it is organized in a most-recent-first list. * * In main caches, data is never invalidated, as the meaning of * a security_id only changes when user mapping is changed, which * current implies remounting. However returned entries may be * overwritten at next update, so data has to be copied elsewhere * before another cache update is made. * In legacy cache, data has to be invalidated when protection is * changed. * * Though the same data may be found in both list, they * must be kept separately : the interpretation of ACL * in both direction are approximations which could be non * reciprocal for some configuration of the user mapping data * * During the process of recompiling ntfs-3g from a tgz archive, * security processing added 7.6% to the cpu time used by ntfs-3g * and 30% if the cache is disabled. */ static struct PERMISSIONS_CACHE *create_caches(struct SECURITY_CONTEXT *scx, u32 securindex) { struct PERMISSIONS_CACHE *cache; unsigned int index1; unsigned int i; cache = (struct PERMISSIONS_CACHE*)NULL; /* create the first permissions blocks */ index1 = securindex >> CACHE_PERMISSIONS_BITS; cache = (struct PERMISSIONS_CACHE*) ntfs_malloc(sizeof(struct PERMISSIONS_CACHE) + index1*sizeof(struct CACHED_PERMISSIONS*)); if (cache) { cache->head.last = index1; cache->head.p_reads = 0; cache->head.p_hits = 0; cache->head.p_writes = 0; *scx->pseccache = cache; for (i=0; i<=index1; i++) cache->cachetable[i] = (struct CACHED_PERMISSIONS*)NULL; } return (cache); } /* * Free memory used by caches * The only purpose is to facilitate the detection of memory leaks */ static void free_caches(struct SECURITY_CONTEXT *scx) { unsigned int index1; struct PERMISSIONS_CACHE *pseccache; pseccache = *scx->pseccache; if (pseccache) { for (index1=0; index1<=pseccache->head.last; index1++) if (pseccache->cachetable[index1]) { #if POSIXACLS struct CACHED_PERMISSIONS *cacheentry; unsigned int index2; for (index2=0; index2<(1<< CACHE_PERMISSIONS_BITS); index2++) { cacheentry = &pseccache->cachetable[index1][index2]; if (cacheentry->valid && cacheentry->pxdesc) free(cacheentry->pxdesc); } #endif free(pseccache->cachetable[index1]); } free(pseccache); } } static int compare(const struct CACHED_SECURID *cached, const struct CACHED_SECURID *item) { #if POSIXACLS size_t csize; size_t isize; /* only compare data and sizes */ csize = (cached->variable ? sizeof(struct POSIX_ACL) + (((struct POSIX_SECURITY*)cached->variable)->acccnt + ((struct POSIX_SECURITY*)cached->variable)->defcnt) *sizeof(struct POSIX_ACE) : 0); isize = (item->variable ? sizeof(struct POSIX_ACL) + (((struct POSIX_SECURITY*)item->variable)->acccnt + ((struct POSIX_SECURITY*)item->variable)->defcnt) *sizeof(struct POSIX_ACE) : 0); return ((cached->uid != item->uid) || (cached->gid != item->gid) || (cached->dmode != item->dmode) || (csize != isize) || (csize && isize && memcmp(&((struct POSIX_SECURITY*)cached->variable)->acl, &((struct POSIX_SECURITY*)item->variable)->acl, csize))); #else return ((cached->uid != item->uid) || (cached->gid != item->gid) || (cached->dmode != item->dmode)); #endif } static int leg_compare(const struct CACHED_PERMISSIONS_LEGACY *cached, const struct CACHED_PERMISSIONS_LEGACY *item) { return (cached->mft_no != item->mft_no); } /* * Resize permission cache table * do not call unless resizing is needed * * If allocation fails, the cache size is not updated * Lack of memory is not considered as an error, the cache is left * consistent and errno is not set. */ static void resize_cache(struct SECURITY_CONTEXT *scx, u32 securindex) { struct PERMISSIONS_CACHE *oldcache; struct PERMISSIONS_CACHE *newcache; int newcnt; int oldcnt; unsigned int index1; unsigned int i; oldcache = *scx->pseccache; index1 = securindex >> CACHE_PERMISSIONS_BITS; newcnt = index1 + 1; if (newcnt <= ((CACHE_PERMISSIONS_SIZE + (1 << CACHE_PERMISSIONS_BITS) - 1) >> CACHE_PERMISSIONS_BITS)) { /* expand cache beyond current end, do not use realloc() */ /* to avoid losing data when there is no more memory */ oldcnt = oldcache->head.last + 1; newcache = (struct PERMISSIONS_CACHE*) ntfs_malloc( sizeof(struct PERMISSIONS_CACHE) + (newcnt - 1)*sizeof(struct CACHED_PERMISSIONS*)); if (newcache) { memcpy(newcache,oldcache, sizeof(struct PERMISSIONS_CACHE) + (oldcnt - 1)*sizeof(struct CACHED_PERMISSIONS*)); free(oldcache); /* mark new entries as not valid */ for (i=newcache->head.last+1; i<=index1; i++) newcache->cachetable[i] = (struct CACHED_PERMISSIONS*)NULL; newcache->head.last = index1; *scx->pseccache = newcache; } } } /* * Enter uid, gid and mode into cache, if possible * * returns the updated or created cache entry, * or NULL if not possible (typically if there is no * security id associated) */ #if POSIXACLS static struct CACHED_PERMISSIONS *enter_cache(struct SECURITY_CONTEXT *scx, ntfs_inode *ni, uid_t uid, gid_t gid, struct POSIX_SECURITY *pxdesc) #else static struct CACHED_PERMISSIONS *enter_cache(struct SECURITY_CONTEXT *scx, ntfs_inode *ni, uid_t uid, gid_t gid, mode_t mode) #endif { struct CACHED_PERMISSIONS *cacheentry; struct CACHED_PERMISSIONS *cacheblock; struct PERMISSIONS_CACHE *pcache; u32 securindex; #if POSIXACLS int pxsize; struct POSIX_SECURITY *pxcached; #endif unsigned int index1; unsigned int index2; int i; /* cacheing is only possible if a security_id has been defined */ if (test_nino_flag(ni, v3_Extensions) && ni->security_id) { /* * Immediately test the most frequent situation * where the entry exists */ securindex = le32_to_cpu(ni->security_id); index1 = securindex >> CACHE_PERMISSIONS_BITS; index2 = securindex & ((1 << CACHE_PERMISSIONS_BITS) - 1); pcache = *scx->pseccache; if (pcache && (pcache->head.last >= index1) && pcache->cachetable[index1]) { cacheentry = &pcache->cachetable[index1][index2]; cacheentry->uid = uid; cacheentry->gid = gid; #if POSIXACLS if (cacheentry->valid && cacheentry->pxdesc) free(cacheentry->pxdesc); if (pxdesc) { pxsize = sizeof(struct POSIX_SECURITY) + (pxdesc->acccnt + pxdesc->defcnt)*sizeof(struct POSIX_ACE); pxcached = (struct POSIX_SECURITY*)malloc(pxsize); if (pxcached) { memcpy(pxcached, pxdesc, pxsize); cacheentry->pxdesc = pxcached; } else { cacheentry->valid = 0; cacheentry = (struct CACHED_PERMISSIONS*)NULL; } cacheentry->mode = pxdesc->mode & 07777; } else cacheentry->pxdesc = (struct POSIX_SECURITY*)NULL; #else cacheentry->mode = mode & 07777; #endif cacheentry->inh_fileid = const_cpu_to_le32(0); cacheentry->inh_dirid = const_cpu_to_le32(0); cacheentry->valid = 1; pcache->head.p_writes++; } else { if (!pcache) { /* create the first cache block */ pcache = create_caches(scx, securindex); } else { if (index1 > pcache->head.last) { resize_cache(scx, securindex); pcache = *scx->pseccache; } } /* allocate block, if cache table was allocated */ if (pcache && (index1 <= pcache->head.last)) { cacheblock = (struct CACHED_PERMISSIONS*) malloc(sizeof(struct CACHED_PERMISSIONS) << CACHE_PERMISSIONS_BITS); pcache->cachetable[index1] = cacheblock; for (i=0; i<(1 << CACHE_PERMISSIONS_BITS); i++) cacheblock[i].valid = 0; cacheentry = &cacheblock[index2]; if (cacheentry) { cacheentry->uid = uid; cacheentry->gid = gid; #if POSIXACLS if (pxdesc) { pxsize = sizeof(struct POSIX_SECURITY) + (pxdesc->acccnt + pxdesc->defcnt)*sizeof(struct POSIX_ACE); pxcached = (struct POSIX_SECURITY*)malloc(pxsize); if (pxcached) { memcpy(pxcached, pxdesc, pxsize); cacheentry->pxdesc = pxcached; } else { cacheentry->valid = 0; cacheentry = (struct CACHED_PERMISSIONS*)NULL; } cacheentry->mode = pxdesc->mode & 07777; } else cacheentry->pxdesc = (struct POSIX_SECURITY*)NULL; #else cacheentry->mode = mode & 07777; #endif cacheentry->inh_fileid = const_cpu_to_le32(0); cacheentry->inh_dirid = const_cpu_to_le32(0); cacheentry->valid = 1; pcache->head.p_writes++; } } else cacheentry = (struct CACHED_PERMISSIONS*)NULL; } } else { cacheentry = (struct CACHED_PERMISSIONS*)NULL; #if CACHE_LEGACY_SIZE if (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) { struct CACHED_PERMISSIONS_LEGACY wanted; struct CACHED_PERMISSIONS_LEGACY *legacy; wanted.perm.uid = uid; wanted.perm.gid = gid; #if POSIXACLS wanted.perm.mode = pxdesc->mode & 07777; wanted.perm.inh_fileid = const_cpu_to_le32(0); wanted.perm.inh_dirid = const_cpu_to_le32(0); wanted.mft_no = ni->mft_no; wanted.variable = (void*)pxdesc; wanted.varsize = sizeof(struct POSIX_SECURITY) + (pxdesc->acccnt + pxdesc->defcnt)*sizeof(struct POSIX_ACE); #else wanted.perm.mode = mode & 07777; wanted.perm.inh_fileid = const_cpu_to_le32(0); wanted.perm.inh_dirid = const_cpu_to_le32(0); wanted.mft_no = ni->mft_no; wanted.variable = (void*)NULL; wanted.varsize = 0; #endif legacy = (struct CACHED_PERMISSIONS_LEGACY*)ntfs_enter_cache( scx->vol->legacy_cache, GENERIC(&wanted), (cache_compare)leg_compare); if (legacy) { cacheentry = &legacy->perm; #if POSIXACLS /* * give direct access to the cached pxdesc * in the permissions structure */ cacheentry->pxdesc = legacy->variable; #endif } } #endif } return (cacheentry); } /* * Fetch owner, group and permission of a file, if cached * * Beware : do not use the returned entry after a cache update : * the cache may be relocated making the returned entry meaningless * * returns the cache entry, or NULL if not available */ static struct CACHED_PERMISSIONS *fetch_cache(struct SECURITY_CONTEXT *scx, ntfs_inode *ni) { struct CACHED_PERMISSIONS *cacheentry; struct PERMISSIONS_CACHE *pcache; u32 securindex; unsigned int index1; unsigned int index2; /* cacheing is only possible if a security_id has been defined */ cacheentry = (struct CACHED_PERMISSIONS*)NULL; if (test_nino_flag(ni, v3_Extensions) && (ni->security_id)) { securindex = le32_to_cpu(ni->security_id); index1 = securindex >> CACHE_PERMISSIONS_BITS; index2 = securindex & ((1 << CACHE_PERMISSIONS_BITS) - 1); pcache = *scx->pseccache; if (pcache && (pcache->head.last >= index1) && pcache->cachetable[index1]) { cacheentry = &pcache->cachetable[index1][index2]; /* reject if entry is not valid */ if (!cacheentry->valid) cacheentry = (struct CACHED_PERMISSIONS*)NULL; else pcache->head.p_hits++; if (pcache) pcache->head.p_reads++; } } #if CACHE_LEGACY_SIZE else { cacheentry = (struct CACHED_PERMISSIONS*)NULL; if (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) { struct CACHED_PERMISSIONS_LEGACY wanted; struct CACHED_PERMISSIONS_LEGACY *legacy; wanted.mft_no = ni->mft_no; wanted.variable = (void*)NULL; wanted.varsize = 0; legacy = (struct CACHED_PERMISSIONS_LEGACY*)ntfs_fetch_cache( scx->vol->legacy_cache, GENERIC(&wanted), (cache_compare)leg_compare); if (legacy) cacheentry = &legacy->perm; } } #endif #if POSIXACLS if (cacheentry && !cacheentry->pxdesc) { ntfs_log_error("No Posix descriptor in cache\n"); cacheentry = (struct CACHED_PERMISSIONS*)NULL; } #endif return (cacheentry); } /* * Retrieve a security attribute from $Secure */ static char *retrievesecurityattr(ntfs_volume *vol, SII_INDEX_KEY id) { struct SII *psii; union { struct { le32 dataoffsl; le32 dataoffsh; } parts; le64 all; } realign; int found; size_t size; size_t rdsize; s64 offs; ntfs_inode *ni; ntfs_index_context *xsii; char *securattr; securattr = (char*)NULL; ni = vol->secure_ni; xsii = vol->secure_xsii; if (ni && xsii) { ntfs_index_ctx_reinit(xsii); found = !ntfs_index_lookup((char*)&id, sizeof(SII_INDEX_KEY), xsii); if (found) { psii = (struct SII*)xsii->entry; size = (size_t) le32_to_cpu(psii->datasize) - sizeof(SECURITY_DESCRIPTOR_HEADER); /* work around bad alignment problem */ realign.parts.dataoffsh = psii->dataoffsh; realign.parts.dataoffsl = psii->dataoffsl; offs = le64_to_cpu(realign.all) + sizeof(SECURITY_DESCRIPTOR_HEADER); securattr = (char*)ntfs_malloc(size); if (securattr) { rdsize = ntfs_attr_data_read( ni, STREAM_SDS, 4, securattr, size, offs); if ((rdsize != size) || !ntfs_valid_descr(securattr, rdsize)) { /* error to be logged by caller */ free(securattr); securattr = (char*)NULL; } } } else if (errno != ENOENT) ntfs_log_perror("Inconsistency in index $SII"); } if (!securattr) { ntfs_log_error("Failed to retrieve a security descriptor\n"); errno = EIO; } return (securattr); } /* * Get the security descriptor associated to a file * * Either : * - read the security descriptor attribute (v1.x format) * - or find the descriptor in $Secure:$SDS (v3.x format) * * in both case, sanity checks are done on the attribute and * the descriptor can be assumed safe * * The returned descriptor is dynamically allocated and has to be freed */ static char *getsecurityattr(ntfs_volume *vol, ntfs_inode *ni) { SII_INDEX_KEY securid; char *securattr; s64 readallsz; /* * Warning : in some situations, after fixing by chkdsk, * v3_Extensions are marked present (long standard informations) * with a default security descriptor inserted in an * attribute */ if (test_nino_flag(ni, v3_Extensions) && vol->secure_ni && ni->security_id) { /* get v3.x descriptor in $Secure */ securid.security_id = ni->security_id; securattr = retrievesecurityattr(vol,securid); if (!securattr) ntfs_log_error("Bad security descriptor for 0x%lx\n", (long)le32_to_cpu(ni->security_id)); } else { /* get v1.x security attribute */ readallsz = 0; securattr = ntfs_attr_readall(ni, AT_SECURITY_DESCRIPTOR, AT_UNNAMED, 0, &readallsz); if (securattr && !ntfs_valid_descr(securattr, readallsz)) { ntfs_log_error("Bad security descriptor for inode %lld\n", (long long)ni->mft_no); free(securattr); securattr = (char*)NULL; } } if (!securattr) { /* * in some situations, there is no security * descriptor, and chkdsk does not detect or fix * anything. This could be a normal situation. * When this happens, simulate a descriptor with * minimum rights, so that a real descriptor can * be created by chown or chmod */ ntfs_log_error("No security descriptor found for inode %lld\n", (long long)ni->mft_no); securattr = ntfs_build_descr(0, 0, adminsid, adminsid); } return (securattr); } #if POSIXACLS /* * Determine which access types to a file are allowed * according to the relation of current process to the file * * When Posix ACLs are compiled in but not enabled in the mount * options POSIX_ACL_USER, POSIX_ACL_GROUP and POSIX_ACL_MASK * are ignored. */ static int access_check_posix(struct SECURITY_CONTEXT *scx, struct POSIX_SECURITY *pxdesc, mode_t request, uid_t uid, gid_t gid) { struct POSIX_ACE *pxace; int userperms; int groupperms; int mask; BOOL somegroup; BOOL needgroups; BOOL noacl; mode_t perms; int i; noacl = !(scx->vol->secure_flags & (1 << SECURITY_ACL)); if (noacl) perms = ntfs_basic_perms(scx, pxdesc); else perms = pxdesc->mode; /* owner and root access */ if (!scx->uid || (uid == scx->uid)) { if (!scx->uid) { /* root access if owner or other execution */ if (perms & 0101) perms |= 01777; else { /* root access if some group execution */ groupperms = 0; mask = 7; for (i=pxdesc->acccnt-1; i>=0 ; i--) { pxace = &pxdesc->acl.ace[i]; switch (pxace->tag) { case POSIX_ACL_USER_OBJ : case POSIX_ACL_GROUP_OBJ : groupperms |= pxace->perms; break; case POSIX_ACL_GROUP : if (!noacl) groupperms |= pxace->perms; break; case POSIX_ACL_MASK : if (!noacl) mask = pxace->perms & 7; break; default : break; } } perms = (groupperms & mask & 1) | 6; } } else perms &= 07700; } else { /* * analyze designated users, get mask * and identify whether we need to check * the group memberships. The groups are * not needed when all groups have the * same permissions as other for the * requested modes. */ userperms = -1; groupperms = -1; needgroups = FALSE; mask = 7; for (i=pxdesc->acccnt-1; i>=0 ; i--) { pxace = &pxdesc->acl.ace[i]; switch (pxace->tag) { case POSIX_ACL_USER : if (!noacl && ((uid_t)pxace->id == scx->uid)) userperms = pxace->perms; break; case POSIX_ACL_MASK : if (!noacl) mask = pxace->perms & 7; break; case POSIX_ACL_GROUP_OBJ : if (((pxace->perms & mask) ^ perms) & (request >> 6) & 7) needgroups = TRUE; break; case POSIX_ACL_GROUP : if (!noacl && (((pxace->perms & mask) ^ perms) & (request >> 6) & 7)) needgroups = TRUE; break; default : break; } } /* designated users */ if (userperms >= 0) perms = (perms & 07000) + (userperms & mask); else if (!needgroups) perms &= 07007; else { /* owning group */ if (!(~(perms >> 3) & request & mask) && ((gid == scx->gid) || groupmember(scx, scx->uid, gid))) perms &= 07070; else if (!noacl) { /* other groups */ groupperms = -1; somegroup = FALSE; for (i=pxdesc->acccnt-1; i>=0 ; i--) { pxace = &pxdesc->acl.ace[i]; if ((pxace->tag == POSIX_ACL_GROUP) && groupmember(scx, scx->uid, pxace->id)) { if (!(~pxace->perms & request & mask)) groupperms = pxace->perms; somegroup = TRUE; } } if (groupperms >= 0) perms = (perms & 07000) + (groupperms & mask); else if (somegroup) perms = 0; else perms &= 07007; } else perms &= 07007; } } return (perms); } /* * Get permissions to access a file * Takes into account the relation of user to file (owner, group, ...) * Do no use as mode of the file * Do no call if default_permissions is set * * returns -1 if there is a problem */ static int ntfs_get_perm(struct SECURITY_CONTEXT *scx, ntfs_inode * ni, mode_t request) { const SECURITY_DESCRIPTOR_RELATIVE *phead; const struct CACHED_PERMISSIONS *cached; char *securattr; const SID *usid; /* owner of file/directory */ const SID *gsid; /* group of file/directory */ uid_t uid; gid_t gid; int perm; BOOL isdir; struct POSIX_SECURITY *pxdesc; if (!scx->mapping[MAPUSERS]) perm = 07777; else { /* check whether available in cache */ cached = fetch_cache(scx,ni); if (cached) { uid = cached->uid; gid = cached->gid; perm = access_check_posix(scx,cached->pxdesc,request,uid,gid); } else { perm = 0; /* default to no permission */ isdir = (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) != const_cpu_to_le16(0); securattr = getsecurityattr(scx->vol, ni); if (securattr) { phead = (const SECURITY_DESCRIPTOR_RELATIVE*) securattr; gsid = (const SID*)& securattr[le32_to_cpu(phead->group)]; gid = ntfs_find_group(scx->mapping[MAPGROUPS],gsid); #if OWNERFROMACL usid = ntfs_acl_owner(securattr); pxdesc = ntfs_build_permissions_posix(scx->mapping,securattr, usid, gsid, isdir); if (pxdesc) perm = pxdesc->mode & 07777; else perm = -1; uid = ntfs_find_user(scx->mapping[MAPUSERS],usid); #else usid = (const SID*)& securattr[le32_to_cpu(phead->owner)]; pxdesc = ntfs_build_permissions_posix(scx,securattr, usid, gsid, isdir); if (pxdesc) perm = pxdesc->mode & 07777; else perm = -1; if (!perm && ntfs_same_sid(usid, adminsid)) { uid = find_tenant(scx, securattr); if (uid) perm = 0700; } else uid = ntfs_find_user(scx->mapping[MAPUSERS],usid); #endif /* * Create a security id if there were none * and upgrade option is selected */ if (!test_nino_flag(ni, v3_Extensions) && (perm >= 0) && (scx->vol->secure_flags & (1 << SECURITY_ADDSECURIDS))) { upgrade_secur_desc(scx->vol, securattr, ni); /* * fetch owner and group for cacheing * if there is a securid */ } if (test_nino_flag(ni, v3_Extensions) && (perm >= 0)) { enter_cache(scx, ni, uid, gid, pxdesc); } if (pxdesc) { perm = access_check_posix(scx,pxdesc,request,uid,gid); free(pxdesc); } free(securattr); } else { perm = -1; uid = gid = 0; } } } return (perm); } /* * Get a Posix ACL * * returns size or -errno if there is a problem * if size was too small, no copy is done and errno is not set, * the caller is expected to issue a new call */ int ntfs_get_posix_acl(struct SECURITY_CONTEXT *scx, ntfs_inode *ni, const char *name, char *value, size_t size) { const SECURITY_DESCRIPTOR_RELATIVE *phead; struct POSIX_SECURITY *pxdesc; const struct CACHED_PERMISSIONS *cached; char *securattr; const SID *usid; /* owner of file/directory */ const SID *gsid; /* group of file/directory */ uid_t uid; gid_t gid; BOOL isdir; size_t outsize; outsize = 0; /* default to error */ if (!scx->mapping[MAPUSERS]) errno = ENOTSUP; else { /* check whether available in cache */ cached = fetch_cache(scx,ni); if (cached) pxdesc = cached->pxdesc; else { securattr = getsecurityattr(scx->vol, ni); isdir = (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) != const_cpu_to_le16(0); if (securattr) { phead = (const SECURITY_DESCRIPTOR_RELATIVE*) securattr; gsid = (const SID*)& securattr[le32_to_cpu(phead->group)]; #if OWNERFROMACL usid = ntfs_acl_owner(securattr); #else usid = (const SID*)& securattr[le32_to_cpu(phead->owner)]; #endif pxdesc = ntfs_build_permissions_posix(scx->mapping,securattr, usid, gsid, isdir); /* * fetch owner and group for cacheing */ if (pxdesc) { /* * Create a security id if there were none * and upgrade option is selected */ if (!test_nino_flag(ni, v3_Extensions) && (scx->vol->secure_flags & (1 << SECURITY_ADDSECURIDS))) { upgrade_secur_desc(scx->vol, securattr, ni); } #if OWNERFROMACL uid = ntfs_find_user(scx->mapping[MAPUSERS],usid); #else if (!(pxdesc->mode & 07777) && ntfs_same_sid(usid, adminsid)) { uid = find_tenant(scx, securattr); } else uid = ntfs_find_user(scx->mapping[MAPUSERS],usid); #endif gid = ntfs_find_group(scx->mapping[MAPGROUPS],gsid); if (pxdesc->tagsset & POSIX_ACL_EXTENSIONS) enter_cache(scx, ni, uid, gid, pxdesc); } free(securattr); } else pxdesc = (struct POSIX_SECURITY*)NULL; } if (pxdesc) { if (ntfs_valid_posix(pxdesc)) { if (!strcmp(name,"system.posix_acl_default")) { if (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) outsize = sizeof(struct POSIX_ACL) + pxdesc->defcnt*sizeof(struct POSIX_ACE); else { /* * getting default ACL from plain file : * return EACCES if size > 0 as * indicated in the man, but return ok * if size == 0, so that ls does not * display an error */ if (size > 0) { outsize = 0; errno = EACCES; } else outsize = sizeof(struct POSIX_ACL); } if (outsize && (outsize <= size)) { memcpy(value,&pxdesc->acl,sizeof(struct POSIX_ACL)); memcpy(&value[sizeof(struct POSIX_ACL)], &pxdesc->acl.ace[pxdesc->firstdef], outsize-sizeof(struct POSIX_ACL)); } } else { outsize = sizeof(struct POSIX_ACL) + pxdesc->acccnt*sizeof(struct POSIX_ACE); if (outsize <= size) memcpy(value,&pxdesc->acl,outsize); } } else { outsize = 0; errno = EIO; ntfs_log_error("Invalid Posix ACL built\n"); } if (!cached) free(pxdesc); } else outsize = 0; } return (outsize ? (int)outsize : -errno); } #else /* POSIXACLS */ /* * Get permissions to access a file * Takes into account the relation of user to file (owner, group, ...) * Do no use as mode of the file * * returns -1 if there is a problem */ static int ntfs_get_perm(struct SECURITY_CONTEXT *scx, ntfs_inode *ni, mode_t request) { const SECURITY_DESCRIPTOR_RELATIVE *phead; const struct CACHED_PERMISSIONS *cached; char *securattr; const SID *usid; /* owner of file/directory */ const SID *gsid; /* group of file/directory */ BOOL isdir; uid_t uid; gid_t gid; int perm; if (!scx->mapping[MAPUSERS] || (!scx->uid && !(request & S_IEXEC))) perm = 07777; else { /* check whether available in cache */ cached = fetch_cache(scx,ni); if (cached) { perm = cached->mode; uid = cached->uid; gid = cached->gid; } else { perm = 0; /* default to no permission */ isdir = (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) != const_cpu_to_le16(0); securattr = getsecurityattr(scx->vol, ni); if (securattr) { phead = (const SECURITY_DESCRIPTOR_RELATIVE*) securattr; gsid = (const SID*)& securattr[le32_to_cpu(phead->group)]; gid = ntfs_find_group(scx->mapping[MAPGROUPS],gsid); #if OWNERFROMACL usid = ntfs_acl_owner(securattr); perm = ntfs_build_permissions(securattr, usid, gsid, isdir); uid = ntfs_find_user(scx->mapping[MAPUSERS],usid); #else usid = (const SID*)& securattr[le32_to_cpu(phead->owner)]; perm = ntfs_build_permissions(securattr, usid, gsid, isdir); if (!perm && ntfs_same_sid(usid, adminsid)) { uid = find_tenant(scx, securattr); if (uid) perm = 0700; } else uid = ntfs_find_user(scx->mapping[MAPUSERS],usid); #endif /* * Create a security id if there were none * and upgrade option is selected */ if (!test_nino_flag(ni, v3_Extensions) && (perm >= 0) && (scx->vol->secure_flags & (1 << SECURITY_ADDSECURIDS))) { upgrade_secur_desc(scx->vol, securattr, ni); /* * fetch owner and group for cacheing * if there is a securid */ } if (test_nino_flag(ni, v3_Extensions) && (perm >= 0)) { enter_cache(scx, ni, uid, gid, perm); } free(securattr); } else { perm = -1; uid = gid = 0; } } if (perm >= 0) { if (!scx->uid) { /* root access and execution */ if (perm & 0111) perm |= 01777; else perm = 0; } else if (uid == scx->uid) perm &= 07700; else /* * avoid checking group membership * when the requested perms for group * are the same as perms for other */ if ((gid == scx->gid) || ((((perm >> 3) ^ perm) & (request >> 6) & 7) && groupmember(scx, scx->uid, gid))) perm &= 07070; else perm &= 07007; } } return (perm); } #endif /* POSIXACLS */ /* * Get an NTFS ACL * * Returns size or -errno if there is a problem * if size was too small, no copy is done and errno is not set, * the caller is expected to issue a new call */ int ntfs_get_ntfs_acl(struct SECURITY_CONTEXT *scx, ntfs_inode *ni, char *value, size_t size) { char *securattr; size_t outsize; outsize = 0; /* default to no data and no error */ securattr = getsecurityattr(scx->vol, ni); if (securattr) { outsize = ntfs_attr_size(securattr); if (outsize <= size) { memcpy(value,securattr,outsize); } free(securattr); } return (outsize ? (int)outsize : -errno); } /* * Get owner, group and permissions in an stat structure * returns permissions, or -1 if there is a problem */ int ntfs_get_owner_mode(struct SECURITY_CONTEXT *scx, ntfs_inode * ni, struct stat *stbuf) { const SECURITY_DESCRIPTOR_RELATIVE *phead; char *securattr; const SID *usid; /* owner of file/directory */ const SID *gsid; /* group of file/directory */ const struct CACHED_PERMISSIONS *cached; int perm; BOOL isdir; #if POSIXACLS struct POSIX_SECURITY *pxdesc; #endif if (!scx->mapping[MAPUSERS]) perm = 07777; else { /* check whether available in cache */ cached = fetch_cache(scx,ni); if (cached) { #if POSIXACLS if (!(scx->vol->secure_flags & (1 << SECURITY_ACL)) && cached->pxdesc) perm = ntfs_basic_perms(scx,cached->pxdesc); else #endif perm = cached->mode; stbuf->st_uid = cached->uid; stbuf->st_gid = cached->gid; stbuf->st_mode = (stbuf->st_mode & ~07777) + perm; } else { perm = -1; /* default to error */ isdir = (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) != const_cpu_to_le16(0); securattr = getsecurityattr(scx->vol, ni); if (securattr) { phead = (const SECURITY_DESCRIPTOR_RELATIVE*) securattr; gsid = (const SID*)& securattr[le32_to_cpu(phead->group)]; #if OWNERFROMACL usid = ntfs_acl_owner(securattr); #else usid = (const SID*)& securattr[le32_to_cpu(phead->owner)]; #endif #if POSIXACLS pxdesc = ntfs_build_permissions_posix( scx->mapping, securattr, usid, gsid, isdir); if (pxdesc) { if (!(scx->vol->secure_flags & (1 << SECURITY_ACL))) perm = ntfs_basic_perms(scx, pxdesc); else perm = pxdesc->mode & 07777; } else perm = -1; #else perm = ntfs_build_permissions(securattr, usid, gsid, isdir); #endif /* * fetch owner and group for cacheing */ if (perm >= 0) { /* * Create a security id if there were none * and upgrade option is selected */ if (!test_nino_flag(ni, v3_Extensions) && (scx->vol->secure_flags & (1 << SECURITY_ADDSECURIDS))) { upgrade_secur_desc(scx->vol, securattr, ni); } #if OWNERFROMACL stbuf->st_uid = ntfs_find_user(scx->mapping[MAPUSERS],usid); #else if (!perm && ntfs_same_sid(usid, adminsid)) { stbuf->st_uid = find_tenant(scx, securattr); if (stbuf->st_uid) perm = 0700; } else stbuf->st_uid = ntfs_find_user(scx->mapping[MAPUSERS],usid); #endif stbuf->st_gid = ntfs_find_group(scx->mapping[MAPGROUPS],gsid); stbuf->st_mode = (stbuf->st_mode & ~07777) + perm; #if POSIXACLS enter_cache(scx, ni, stbuf->st_uid, stbuf->st_gid, pxdesc); free(pxdesc); #else enter_cache(scx, ni, stbuf->st_uid, stbuf->st_gid, perm); #endif } free(securattr); } } } return (perm); } #if POSIXACLS /* * Get the base for a Posix inheritance and * build an inherited Posix descriptor */ static struct POSIX_SECURITY *inherit_posix(struct SECURITY_CONTEXT *scx, ntfs_inode *dir_ni, mode_t mode, BOOL isdir) { const struct CACHED_PERMISSIONS *cached; const SECURITY_DESCRIPTOR_RELATIVE *phead; struct POSIX_SECURITY *pxdesc; struct POSIX_SECURITY *pydesc; char *securattr; const SID *usid; const SID *gsid; uid_t uid; gid_t gid; pydesc = (struct POSIX_SECURITY*)NULL; /* check whether parent directory is available in cache */ cached = fetch_cache(scx,dir_ni); if (cached) { uid = cached->uid; gid = cached->gid; pxdesc = cached->pxdesc; if (pxdesc) { if (scx->vol->secure_flags & (1 << SECURITY_ACL)) pydesc = ntfs_build_inherited_posix(pxdesc, mode, scx->umask, isdir); else pydesc = ntfs_build_basic_posix(pxdesc, mode, scx->umask, isdir); } } else { securattr = getsecurityattr(scx->vol, dir_ni); if (securattr) { phead = (const SECURITY_DESCRIPTOR_RELATIVE*) securattr; gsid = (const SID*)& securattr[le32_to_cpu(phead->group)]; gid = ntfs_find_group(scx->mapping[MAPGROUPS],gsid); #if OWNERFROMACL usid = ntfs_acl_owner(securattr); pxdesc = ntfs_build_permissions_posix(scx->mapping,securattr, usid, gsid, TRUE); uid = ntfs_find_user(scx->mapping[MAPUSERS],usid); #else usid = (const SID*)& securattr[le32_to_cpu(phead->owner)]; pxdesc = ntfs_build_permissions_posix(scx->mapping,securattr, usid, gsid, TRUE); if (pxdesc && ntfs_same_sid(usid, adminsid)) { uid = find_tenant(scx, securattr); } else uid = ntfs_find_user(scx->mapping[MAPUSERS],usid); #endif if (pxdesc) { /* * Create a security id if there were none * and upgrade option is selected */ if (!test_nino_flag(dir_ni, v3_Extensions) && (scx->vol->secure_flags & (1 << SECURITY_ADDSECURIDS))) { upgrade_secur_desc(scx->vol, securattr, dir_ni); /* * fetch owner and group for cacheing * if there is a securid */ } if (test_nino_flag(dir_ni, v3_Extensions)) { enter_cache(scx, dir_ni, uid, gid, pxdesc); } if (scx->vol->secure_flags & (1 << SECURITY_ACL)) pydesc = ntfs_build_inherited_posix( pxdesc, mode, scx->umask, isdir); else pydesc = ntfs_build_basic_posix( pxdesc, mode, scx->umask, isdir); free(pxdesc); } free(securattr); } } return (pydesc); } /* * Allocate a security_id for a file being created * * Returns zero if not possible (NTFS v3.x required) */ le32 ntfs_alloc_securid(struct SECURITY_CONTEXT *scx, uid_t uid, gid_t gid, ntfs_inode *dir_ni, mode_t mode, BOOL isdir) { #if !FORCE_FORMAT_v1x const struct CACHED_SECURID *cached; struct CACHED_SECURID wanted; struct POSIX_SECURITY *pxdesc; char *newattr; int newattrsz; const SID *usid; const SID *gsid; BIGSID defusid; BIGSID defgsid; le32 securid; #endif securid = const_cpu_to_le32(0); #if !FORCE_FORMAT_v1x pxdesc = inherit_posix(scx, dir_ni, mode, isdir); if (pxdesc) { /* check whether target securid is known in cache */ wanted.uid = uid; wanted.gid = gid; wanted.dmode = pxdesc->mode & mode & 07777; if (isdir) wanted.dmode |= 0x10000; wanted.variable = (void*)pxdesc; wanted.varsize = sizeof(struct POSIX_SECURITY) + (pxdesc->acccnt + pxdesc->defcnt)*sizeof(struct POSIX_ACE); cached = (const struct CACHED_SECURID*)ntfs_fetch_cache( scx->vol->securid_cache, GENERIC(&wanted), (cache_compare)compare); /* quite simple, if we are lucky */ if (cached) securid = cached->securid; /* not in cache : make sure we can create ids */ if (!cached && (scx->vol->major_ver >= 3)) { usid = ntfs_find_usid(scx->mapping[MAPUSERS],uid,(SID*)&defusid); gsid = ntfs_find_gsid(scx->mapping[MAPGROUPS],gid,(SID*)&defgsid); if (!usid || !gsid) { ntfs_log_error("File created by an unmapped user/group %d/%d\n", (int)uid, (int)gid); usid = gsid = adminsid; } newattr = ntfs_build_descr_posix(scx->mapping, pxdesc, isdir, usid, gsid); if (newattr) { newattrsz = ntfs_attr_size(newattr); securid = setsecurityattr(scx->vol, (const SECURITY_DESCRIPTOR_RELATIVE*)newattr, newattrsz); if (securid) { /* update cache, for subsequent use */ wanted.securid = securid; ntfs_enter_cache(scx->vol->securid_cache, GENERIC(&wanted), (cache_compare)compare); } free(newattr); } else { /* * could not build new security attribute * errno set by ntfs_build_descr() */ } } free(pxdesc); } #endif return (securid); } /* * Apply Posix inheritance to a newly created file * (for NTFS 1.x only : no securid) */ int ntfs_set_inherited_posix(struct SECURITY_CONTEXT *scx, ntfs_inode *ni, uid_t uid, gid_t gid, ntfs_inode *dir_ni, mode_t mode) { struct POSIX_SECURITY *pxdesc; char *newattr; const SID *usid; const SID *gsid; BIGSID defusid; BIGSID defgsid; BOOL isdir; int res; res = -1; isdir = (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) != const_cpu_to_le16(0); pxdesc = inherit_posix(scx, dir_ni, mode, isdir); if (pxdesc) { usid = ntfs_find_usid(scx->mapping[MAPUSERS],uid,(SID*)&defusid); gsid = ntfs_find_gsid(scx->mapping[MAPGROUPS],gid,(SID*)&defgsid); if (!usid || !gsid) { ntfs_log_error("File created by an unmapped user/group %d/%d\n", (int)uid, (int)gid); usid = gsid = adminsid; } newattr = ntfs_build_descr_posix(scx->mapping, pxdesc, isdir, usid, gsid); if (newattr) { /* Adjust Windows read-only flag */ res = update_secur_descr(scx->vol, newattr, ni); if (!res && !isdir) { if (mode & S_IWUSR) ni->flags &= ~FILE_ATTR_READONLY; else ni->flags |= FILE_ATTR_READONLY; } #if CACHE_LEGACY_SIZE /* also invalidate legacy cache */ if (isdir && !ni->security_id) { struct CACHED_PERMISSIONS_LEGACY legacy; legacy.mft_no = ni->mft_no; legacy.variable = pxdesc; legacy.varsize = sizeof(struct POSIX_SECURITY) + (pxdesc->acccnt + pxdesc->defcnt)*sizeof(struct POSIX_ACE); ntfs_invalidate_cache(scx->vol->legacy_cache, GENERIC(&legacy), (cache_compare)leg_compare,0); } #endif free(newattr); } else { /* * could not build new security attribute * errno set by ntfs_build_descr() */ } } return (res); } #else le32 ntfs_alloc_securid(struct SECURITY_CONTEXT *scx, uid_t uid, gid_t gid, mode_t mode, BOOL isdir) { #if !FORCE_FORMAT_v1x const struct CACHED_SECURID *cached; struct CACHED_SECURID wanted; char *newattr; int newattrsz; const SID *usid; const SID *gsid; BIGSID defusid; BIGSID defgsid; le32 securid; #endif securid = const_cpu_to_le32(0); #if !FORCE_FORMAT_v1x /* check whether target securid is known in cache */ wanted.uid = uid; wanted.gid = gid; wanted.dmode = mode & 07777; if (isdir) wanted.dmode |= 0x10000; wanted.variable = (void*)NULL; wanted.varsize = 0; cached = (const struct CACHED_SECURID*)ntfs_fetch_cache( scx->vol->securid_cache, GENERIC(&wanted), (cache_compare)compare); /* quite simple, if we are lucky */ if (cached) securid = cached->securid; /* not in cache : make sure we can create ids */ if (!cached && (scx->vol->major_ver >= 3)) { usid = ntfs_find_usid(scx->mapping[MAPUSERS],uid,(SID*)&defusid); gsid = ntfs_find_gsid(scx->mapping[MAPGROUPS],gid,(SID*)&defgsid); if (!usid || !gsid) { ntfs_log_error("File created by an unmapped user/group %d/%d\n", (int)uid, (int)gid); usid = gsid = adminsid; } newattr = ntfs_build_descr(mode, isdir, usid, gsid); if (newattr) { newattrsz = ntfs_attr_size(newattr); securid = setsecurityattr(scx->vol, (const SECURITY_DESCRIPTOR_RELATIVE*)newattr, newattrsz); if (securid) { /* update cache, for subsequent use */ wanted.securid = securid; ntfs_enter_cache(scx->vol->securid_cache, GENERIC(&wanted), (cache_compare)compare); } free(newattr); } else { /* * could not build new security attribute * errno set by ntfs_build_descr() */ } } #endif return (securid); } #endif /* * Update ownership and mode of a file, reusing an existing * security descriptor when possible * * Returns zero if successful */ #if POSIXACLS int ntfs_set_owner_mode(struct SECURITY_CONTEXT *scx, ntfs_inode *ni, uid_t uid, gid_t gid, mode_t mode, struct POSIX_SECURITY *pxdesc) #else int ntfs_set_owner_mode(struct SECURITY_CONTEXT *scx, ntfs_inode *ni, uid_t uid, gid_t gid, mode_t mode) #endif { int res; const struct CACHED_SECURID *cached; struct CACHED_SECURID wanted; char *newattr; const SID *usid; const SID *gsid; BIGSID defusid; BIGSID defgsid; BOOL isdir; res = 0; /* check whether target securid is known in cache */ isdir = (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) != const_cpu_to_le16(0); wanted.uid = uid; wanted.gid = gid; wanted.dmode = mode & 07777; if (isdir) wanted.dmode |= 0x10000; #if POSIXACLS wanted.variable = (void*)pxdesc; if (pxdesc) wanted.varsize = sizeof(struct POSIX_SECURITY) + (pxdesc->acccnt + pxdesc->defcnt)*sizeof(struct POSIX_ACE); else wanted.varsize = 0; #else wanted.variable = (void*)NULL; wanted.varsize = 0; #endif if (test_nino_flag(ni, v3_Extensions)) { cached = (const struct CACHED_SECURID*)ntfs_fetch_cache( scx->vol->securid_cache, GENERIC(&wanted), (cache_compare)compare); /* quite simple, if we are lucky */ if (cached) { ni->security_id = cached->securid; NInoSetDirty(ni); /* adjust Windows read-only flag */ if (!isdir) { if (mode & S_IWUSR) ni->flags &= ~FILE_ATTR_READONLY; else ni->flags |= FILE_ATTR_READONLY; NInoFileNameSetDirty(ni); } } } else cached = (struct CACHED_SECURID*)NULL; if (!cached) { /* * Do not use usid and gsid from former attributes, * but recompute them to get repeatable results * which can be kept in cache. */ usid = ntfs_find_usid(scx->mapping[MAPUSERS],uid,(SID*)&defusid); gsid = ntfs_find_gsid(scx->mapping[MAPGROUPS],gid,(SID*)&defgsid); if (!usid || !gsid) { ntfs_log_error("File made owned by an unmapped user/group %d/%d\n", uid, gid); usid = gsid = adminsid; } #if POSIXACLS if (pxdesc) newattr = ntfs_build_descr_posix(scx->mapping, pxdesc, isdir, usid, gsid); else newattr = ntfs_build_descr(mode, isdir, usid, gsid); #else newattr = ntfs_build_descr(mode, isdir, usid, gsid); #endif if (newattr) { res = update_secur_descr(scx->vol, newattr, ni); if (!res) { /* adjust Windows read-only flag */ if (!isdir) { if (mode & S_IWUSR) ni->flags &= ~FILE_ATTR_READONLY; else ni->flags |= FILE_ATTR_READONLY; NInoFileNameSetDirty(ni); } /* update cache, for subsequent use */ if (test_nino_flag(ni, v3_Extensions)) { wanted.securid = ni->security_id; ntfs_enter_cache(scx->vol->securid_cache, GENERIC(&wanted), (cache_compare)compare); } #if CACHE_LEGACY_SIZE /* also invalidate legacy cache */ if (isdir && !ni->security_id) { struct CACHED_PERMISSIONS_LEGACY legacy; legacy.mft_no = ni->mft_no; #if POSIXACLS legacy.variable = wanted.variable; legacy.varsize = wanted.varsize; #else legacy.variable = (void*)NULL; legacy.varsize = 0; #endif ntfs_invalidate_cache(scx->vol->legacy_cache, GENERIC(&legacy), (cache_compare)leg_compare,0); } #endif } free(newattr); } else { /* * could not build new security attribute * errno set by ntfs_build_descr() */ res = -1; } } return (res); } /* * Check whether user has ownership rights on a file * * Returns TRUE if allowed * if not, errno tells why */ BOOL ntfs_allowed_as_owner(struct SECURITY_CONTEXT *scx, ntfs_inode *ni) { const struct CACHED_PERMISSIONS *cached; char *oldattr; const SID *usid; uid_t processuid; uid_t uid; BOOL gotowner; int allowed; processuid = scx->uid; /* TODO : use CAP_FOWNER process capability */ /* * Always allow for root * Also always allow if no mapping has been defined */ if (!scx->mapping[MAPUSERS] || !processuid) allowed = TRUE; else { gotowner = FALSE; /* default */ /* get the owner, either from cache or from old attribute */ cached = fetch_cache(scx, ni); if (cached) { uid = cached->uid; gotowner = TRUE; } else { oldattr = getsecurityattr(scx->vol, ni); if (oldattr) { #if OWNERFROMACL usid = ntfs_acl_owner(oldattr); #else const SECURITY_DESCRIPTOR_RELATIVE *phead; phead = (const SECURITY_DESCRIPTOR_RELATIVE*) oldattr; usid = (const SID*)&oldattr [le32_to_cpu(phead->owner)]; #endif uid = ntfs_find_user(scx->mapping[MAPUSERS], usid); gotowner = TRUE; free(oldattr); } } /* TODO : use CAP_FOWNER process capability */ if (gotowner && (!processuid || (processuid == uid))) allowed = TRUE; else { allowed = FALSE; errno = EPERM; } } return (allowed); } #if POSIXACLS /* * Set a new access or default Posix ACL to a file * (or remove ACL if no input data) * Validity of input data is checked after merging * * Returns 0, or -1 if there is a problem which errno describes */ int ntfs_set_posix_acl(struct SECURITY_CONTEXT *scx, ntfs_inode *ni, const char *name, const char *value, size_t size, int flags) { const SECURITY_DESCRIPTOR_RELATIVE *phead; const struct CACHED_PERMISSIONS *cached; char *oldattr; uid_t processuid; const SID *usid; const SID *gsid; uid_t uid; uid_t gid; int res; BOOL isdir; BOOL deflt; BOOL exist; int count; struct POSIX_SECURITY *oldpxdesc; struct POSIX_SECURITY *newpxdesc; /* get the current pxsec, either from cache or from old attribute */ res = -1; deflt = !strcmp(name,"system.posix_acl_default"); if (size) count = (size - sizeof(struct POSIX_ACL)) / sizeof(struct POSIX_ACE); else count = 0; isdir = (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) != const_cpu_to_le16(0); newpxdesc = (struct POSIX_SECURITY*)NULL; if ((!value || (((const struct POSIX_ACL*)value)->version == POSIX_VERSION)) && (!deflt || isdir || (!size && !value))) { cached = fetch_cache(scx, ni); if (cached) { uid = cached->uid; gid = cached->gid; oldpxdesc = cached->pxdesc; if (oldpxdesc) { newpxdesc = ntfs_replace_acl(oldpxdesc, (const struct POSIX_ACL*)value,count,deflt); } } else { oldattr = getsecurityattr(scx->vol, ni); if (oldattr) { phead = (const SECURITY_DESCRIPTOR_RELATIVE*)oldattr; #if OWNERFROMACL usid = ntfs_acl_owner(oldattr); #else usid = (const SID*)&oldattr[le32_to_cpu(phead->owner)]; #endif gsid = (const SID*)&oldattr[le32_to_cpu(phead->group)]; uid = ntfs_find_user(scx->mapping[MAPUSERS],usid); gid = ntfs_find_group(scx->mapping[MAPGROUPS],gsid); oldpxdesc = ntfs_build_permissions_posix(scx->mapping, oldattr, usid, gsid, isdir); if (oldpxdesc) { if (deflt) exist = oldpxdesc->defcnt > 0; else exist = oldpxdesc->acccnt > 3; if ((exist && (flags & XATTR_CREATE)) || (!exist && (flags & XATTR_REPLACE))) { errno = (exist ? EEXIST : ENODATA); } else { newpxdesc = ntfs_replace_acl(oldpxdesc, (const struct POSIX_ACL*)value,count,deflt); } free(oldpxdesc); } free(oldattr); } } } else errno = EINVAL; if (newpxdesc) { processuid = scx->uid; /* TODO : use CAP_FOWNER process capability */ if (!processuid || (uid == processuid)) { /* * clear setgid if file group does * not match process group */ if (processuid && (gid != scx->gid) && !groupmember(scx, scx->uid, gid)) { newpxdesc->mode &= ~S_ISGID; } res = ntfs_set_owner_mode(scx, ni, uid, gid, newpxdesc->mode, newpxdesc); } else errno = EPERM; free(newpxdesc); } return (res ? -1 : 0); } /* * Remove a default Posix ACL from a file * * Returns 0, or -1 if there is a problem which errno describes */ int ntfs_remove_posix_acl(struct SECURITY_CONTEXT *scx, ntfs_inode *ni, const char *name) { return (ntfs_set_posix_acl(scx, ni, name, (const char*)NULL, 0, 0)); } #endif /* * Set a new NTFS ACL to a file * * Returns 0, or -1 if there is a problem */ int ntfs_set_ntfs_acl(struct SECURITY_CONTEXT *scx, ntfs_inode *ni, const char *value, size_t size, int flags) { char *attr; int res; res = -1; if ((size > 0) && !(flags & XATTR_CREATE) && ntfs_valid_descr(value,size) && (ntfs_attr_size(value) == size)) { /* need copying in order to write */ attr = (char*)ntfs_malloc(size); if (attr) { memcpy(attr,value,size); res = update_secur_descr(scx->vol, attr, ni); /* * No need to invalidate standard caches : * the relation between a securid and * the associated protection is unchanged, * only the relation between a file and * its securid and protection is changed. */ #if CACHE_LEGACY_SIZE /* * we must however invalidate the legacy * cache, which is based on inode numbers. * For safety, invalidate even if updating * failed. */ if ((ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) && !ni->security_id) { struct CACHED_PERMISSIONS_LEGACY legacy; legacy.mft_no = ni->mft_no; legacy.variable = (char*)NULL; legacy.varsize = 0; ntfs_invalidate_cache(scx->vol->legacy_cache, GENERIC(&legacy), (cache_compare)leg_compare,0); } #endif free(attr); } else errno = ENOMEM; } else errno = EINVAL; return (res ? -1 : 0); } /* * Set new permissions to a file * Checks user mapping has been defined before request for setting * * rejected if request is not originated by owner or root * * returns 0 on success * -1 on failure, with errno = EIO */ int ntfs_set_mode(struct SECURITY_CONTEXT *scx, ntfs_inode *ni, mode_t mode) { const SECURITY_DESCRIPTOR_RELATIVE *phead; const struct CACHED_PERMISSIONS *cached; char *oldattr; const SID *usid; const SID *gsid; uid_t processuid; uid_t uid; uid_t gid; int res; #if POSIXACLS BOOL isdir; int pxsize; const struct POSIX_SECURITY *oldpxdesc; struct POSIX_SECURITY *newpxdesc = (struct POSIX_SECURITY*)NULL; #endif /* get the current owner, either from cache or from old attribute */ res = 0; cached = fetch_cache(scx, ni); if (cached) { uid = cached->uid; gid = cached->gid; #if POSIXACLS oldpxdesc = cached->pxdesc; if (oldpxdesc) { /* must copy before merging */ pxsize = sizeof(struct POSIX_SECURITY) + (oldpxdesc->acccnt + oldpxdesc->defcnt)*sizeof(struct POSIX_ACE); newpxdesc = (struct POSIX_SECURITY*)malloc(pxsize); if (newpxdesc) { memcpy(newpxdesc, oldpxdesc, pxsize); if (ntfs_merge_mode_posix(newpxdesc, mode)) res = -1; } else res = -1; } else newpxdesc = (struct POSIX_SECURITY*)NULL; #endif } else { oldattr = getsecurityattr(scx->vol, ni); if (oldattr) { phead = (const SECURITY_DESCRIPTOR_RELATIVE*)oldattr; #if OWNERFROMACL usid = ntfs_acl_owner(oldattr); #else usid = (const SID*)&oldattr[le32_to_cpu(phead->owner)]; #endif gsid = (const SID*)&oldattr[le32_to_cpu(phead->group)]; uid = ntfs_find_user(scx->mapping[MAPUSERS],usid); gid = ntfs_find_group(scx->mapping[MAPGROUPS],gsid); #if POSIXACLS isdir = (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) != const_cpu_to_le16(0); newpxdesc = ntfs_build_permissions_posix(scx->mapping, oldattr, usid, gsid, isdir); if (!newpxdesc || ntfs_merge_mode_posix(newpxdesc, mode)) res = -1; #endif free(oldattr); } else res = -1; } if (!res) { processuid = scx->uid; /* TODO : use CAP_FOWNER process capability */ if (!processuid || (uid == processuid)) { /* * clear setgid if file group does * not match process group */ if (processuid && (gid != scx->gid) && !groupmember(scx, scx->uid, gid)) mode &= ~S_ISGID; #if POSIXACLS if (newpxdesc) { newpxdesc->mode = mode; res = ntfs_set_owner_mode(scx, ni, uid, gid, mode, newpxdesc); } else res = ntfs_set_owner_mode(scx, ni, uid, gid, mode, newpxdesc); #else res = ntfs_set_owner_mode(scx, ni, uid, gid, mode); #endif } else { errno = EPERM; res = -1; /* neither owner nor root */ } } else { /* * Should not happen : a default descriptor is generated * by getsecurityattr() when there are none */ ntfs_log_error("File has no security descriptor\n"); res = -1; errno = EIO; } #if POSIXACLS if (newpxdesc) free(newpxdesc); #endif return (res ? -1 : 0); } /* * Create a default security descriptor for files whose descriptor * cannot be inherited */ int ntfs_sd_add_everyone(ntfs_inode *ni) { /* JPA SECURITY_DESCRIPTOR_ATTR *sd; */ SECURITY_DESCRIPTOR_RELATIVE *sd; ACL *acl; ACCESS_ALLOWED_ACE *ace; SID *sid; int ret, sd_len; /* Create SECURITY_DESCRIPTOR attribute (everyone has full access). */ /* * Calculate security descriptor length. We have 2 sub-authorities in * owner and group SIDs, but structure SID contain only one, so add * 4 bytes to every SID. */ sd_len = sizeof(SECURITY_DESCRIPTOR_ATTR) + 2 * (sizeof(SID) + 4) + sizeof(ACL) + sizeof(ACCESS_ALLOWED_ACE); sd = (SECURITY_DESCRIPTOR_RELATIVE*)ntfs_calloc(sd_len); if (!sd) return -1; sd->revision = SECURITY_DESCRIPTOR_REVISION; sd->control = SE_DACL_PRESENT | SE_SELF_RELATIVE; sid = (SID*)((u8*)sd + sizeof(SECURITY_DESCRIPTOR_ATTR)); sid->revision = SID_REVISION; sid->sub_authority_count = 2; sid->sub_authority[0] = const_cpu_to_le32(SECURITY_BUILTIN_DOMAIN_RID); sid->sub_authority[1] = const_cpu_to_le32(DOMAIN_ALIAS_RID_ADMINS); sid->identifier_authority.value[5] = 5; sd->owner = cpu_to_le32((u8*)sid - (u8*)sd); sid = (SID*)((u8*)sid + sizeof(SID) + 4); sid->revision = SID_REVISION; sid->sub_authority_count = 2; sid->sub_authority[0] = const_cpu_to_le32(SECURITY_BUILTIN_DOMAIN_RID); sid->sub_authority[1] = const_cpu_to_le32(DOMAIN_ALIAS_RID_ADMINS); sid->identifier_authority.value[5] = 5; sd->group = cpu_to_le32((u8*)sid - (u8*)sd); acl = (ACL*)((u8*)sid + sizeof(SID) + 4); acl->revision = ACL_REVISION; acl->size = const_cpu_to_le16(sizeof(ACL) + sizeof(ACCESS_ALLOWED_ACE)); acl->ace_count = const_cpu_to_le16(1); sd->dacl = cpu_to_le32((u8*)acl - (u8*)sd); ace = (ACCESS_ALLOWED_ACE*)((u8*)acl + sizeof(ACL)); ace->type = ACCESS_ALLOWED_ACE_TYPE; ace->flags = OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE; ace->size = const_cpu_to_le16(sizeof(ACCESS_ALLOWED_ACE)); ace->mask = const_cpu_to_le32(0x1f01ff); /* FIXME */ ace->sid.revision = SID_REVISION; ace->sid.sub_authority_count = 1; ace->sid.sub_authority[0] = const_cpu_to_le32(0); ace->sid.identifier_authority.value[5] = 1; ret = ntfs_attr_add(ni, AT_SECURITY_DESCRIPTOR, AT_UNNAMED, 0, (u8*)sd, sd_len); if (ret) ntfs_log_perror("Failed to add initial SECURITY_DESCRIPTOR"); free(sd); return ret; } /* * Check whether user can access a file in a specific way * * Returns 1 if access is allowed, including user is root or no * user mapping defined * 2 if sticky and accesstype is S_IWRITE + S_IEXEC + S_ISVTX * 0 and sets errno if there is a problem or if access * is not allowed * * This is used for Posix ACL and checking creation of DOS file names */ int ntfs_allowed_access(struct SECURITY_CONTEXT *scx, ntfs_inode *ni, int accesstype) /* access type required (S_Ixxx values) */ { int perm; int res; int allow; struct stat stbuf; /* * Always allow for root unless execution is requested. * (was checked by fuse until kernel 2.6.29) * Also always allow if no mapping has been defined */ if (!scx->mapping[MAPUSERS] || (!scx->uid && (!(accesstype & S_IEXEC) || (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY)))) allow = 1; else { perm = ntfs_get_perm(scx, ni, accesstype); if (perm >= 0) { res = EACCES; switch (accesstype) { case S_IEXEC: allow = (perm & (S_IXUSR | S_IXGRP | S_IXOTH)) != 0; break; case S_IWRITE: allow = (perm & (S_IWUSR | S_IWGRP | S_IWOTH)) != 0; break; case S_IWRITE + S_IEXEC: allow = ((perm & (S_IWUSR | S_IWGRP | S_IWOTH)) != 0) && ((perm & (S_IXUSR | S_IXGRP | S_IXOTH)) != 0); break; case S_IREAD: allow = (perm & (S_IRUSR | S_IRGRP | S_IROTH)) != 0; break; case S_IREAD + S_IEXEC: allow = ((perm & (S_IRUSR | S_IRGRP | S_IROTH)) != 0) && ((perm & (S_IXUSR | S_IXGRP | S_IXOTH)) != 0); break; case S_IREAD + S_IWRITE: allow = ((perm & (S_IRUSR | S_IRGRP | S_IROTH)) != 0) && ((perm & (S_IWUSR | S_IWGRP | S_IWOTH)) != 0); break; case S_IWRITE + S_IEXEC + S_ISVTX: if (perm & S_ISVTX) { if ((ntfs_get_owner_mode(scx,ni,&stbuf) >= 0) && (stbuf.st_uid == scx->uid)) allow = 1; else allow = 2; } else allow = ((perm & (S_IWUSR | S_IWGRP | S_IWOTH)) != 0) && ((perm & (S_IXUSR | S_IXGRP | S_IXOTH)) != 0); break; case S_IREAD + S_IWRITE + S_IEXEC: allow = ((perm & (S_IRUSR | S_IRGRP | S_IROTH)) != 0) && ((perm & (S_IWUSR | S_IWGRP | S_IWOTH)) != 0) && ((perm & (S_IXUSR | S_IXGRP | S_IXOTH)) != 0); break; default : res = EINVAL; allow = 0; break; } if (!allow) errno = res; } else allow = 0; } return (allow); } /* * Check whether user can create a file (or directory) * * Returns TRUE if access is allowed, * Also returns the gid and dsetgid applicable to the created file */ int ntfs_allowed_create(struct SECURITY_CONTEXT *scx, ntfs_inode *dir_ni, gid_t *pgid, mode_t *pdsetgid) { int perm; int res; int allow; struct stat stbuf; /* * Always allow for root. * Also always allow if no mapping has been defined */ if (!scx->mapping[MAPUSERS]) perm = 0777; else perm = ntfs_get_perm(scx, dir_ni, S_IWRITE + S_IEXEC); if (!scx->mapping[MAPUSERS] || !scx->uid) { allow = 1; } else { perm = ntfs_get_perm(scx, dir_ni, S_IWRITE + S_IEXEC); if (perm >= 0) { res = EACCES; allow = ((perm & (S_IWUSR | S_IWGRP | S_IWOTH)) != 0) && ((perm & (S_IXUSR | S_IXGRP | S_IXOTH)) != 0); if (!allow) errno = res; } else allow = 0; } *pgid = scx->gid; *pdsetgid = 0; /* return directory group if S_ISGID is set */ if (allow && (perm & S_ISGID)) { if (ntfs_get_owner_mode(scx, dir_ni, &stbuf) >= 0) { *pdsetgid = stbuf.st_mode & S_ISGID; if (perm & S_ISGID) *pgid = stbuf.st_gid; } } return (allow); } #if 0 /* not needed any more */ /* * Check whether user can access the parent directory * of a file in a specific way * * Returns true if access is allowed, including user is root and * no user mapping defined * * Sets errno if there is a problem or if not allowed * * This is used for Posix ACL and checking creation of DOS file names */ BOOL old_ntfs_allowed_dir_access(struct SECURITY_CONTEXT *scx, const char *path, int accesstype) { int allow; char *dirpath; char *name; ntfs_inode *ni; ntfs_inode *dir_ni; struct stat stbuf; allow = 0; dirpath = strdup(path); if (dirpath) { /* the root of file system is seen as a parent of itself */ /* is that correct ? */ name = strrchr(dirpath, '/'); *name = 0; dir_ni = ntfs_pathname_to_inode(scx->vol, NULL, dirpath); if (dir_ni) { allow = ntfs_allowed_access(scx, dir_ni, accesstype); ntfs_inode_close(dir_ni); /* * for an not-owned sticky directory, have to * check whether file itself is owned */ if ((accesstype == (S_IWRITE + S_IEXEC + S_ISVTX)) && (allow == 2)) { ni = ntfs_pathname_to_inode(scx->vol, NULL, path); allow = FALSE; if (ni) { allow = (ntfs_get_owner_mode(scx,ni,&stbuf) >= 0) && (stbuf.st_uid == scx->uid); ntfs_inode_close(ni); } } } free(dirpath); } return (allow); /* errno is set if not allowed */ } #endif /* * Define a new owner/group to a file * * returns zero if successful */ int ntfs_set_owner(struct SECURITY_CONTEXT *scx, ntfs_inode *ni, uid_t uid, gid_t gid) { const SECURITY_DESCRIPTOR_RELATIVE *phead; const struct CACHED_PERMISSIONS *cached; char *oldattr; const SID *usid; const SID *gsid; uid_t fileuid; uid_t filegid; mode_t mode; int perm; BOOL isdir; int res; #if POSIXACLS struct POSIX_SECURITY *pxdesc; BOOL pxdescbuilt = FALSE; #endif res = 0; /* get the current owner and mode from cache or security attributes */ oldattr = (char*)NULL; cached = fetch_cache(scx,ni); if (cached) { fileuid = cached->uid; filegid = cached->gid; mode = cached->mode; #if POSIXACLS pxdesc = cached->pxdesc; if (!pxdesc) res = -1; #endif } else { fileuid = 0; filegid = 0; mode = 0; oldattr = getsecurityattr(scx->vol, ni); if (oldattr) { isdir = (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) != const_cpu_to_le16(0); phead = (const SECURITY_DESCRIPTOR_RELATIVE*) oldattr; gsid = (const SID*) &oldattr[le32_to_cpu(phead->group)]; #if OWNERFROMACL usid = ntfs_acl_owner(oldattr); #else usid = (const SID*) &oldattr[le32_to_cpu(phead->owner)]; #endif #if POSIXACLS pxdesc = ntfs_build_permissions_posix(scx->mapping, oldattr, usid, gsid, isdir); if (pxdesc) { pxdescbuilt = TRUE; fileuid = ntfs_find_user(scx->mapping[MAPUSERS],usid); filegid = ntfs_find_group(scx->mapping[MAPGROUPS],gsid); mode = perm = pxdesc->mode; } else res = -1; #else mode = perm = ntfs_build_permissions(oldattr, usid, gsid, isdir); if (perm >= 0) { fileuid = ntfs_find_user(scx->mapping[MAPUSERS],usid); filegid = ntfs_find_group(scx->mapping[MAPGROUPS],gsid); } else res = -1; #endif free(oldattr); } else res = -1; } if (!res) { /* check requested by root */ /* or chgrp requested by owner to an owned group */ if (!scx->uid || ((((int)uid < 0) || (uid == fileuid)) && ((gid == scx->gid) || groupmember(scx, scx->uid, gid)) && (fileuid == scx->uid))) { /* replace by the new usid and gsid */ /* or reuse old gid and sid for cacheing */ if ((int)uid < 0) uid = fileuid; if ((int)gid < 0) gid = filegid; #if !defined(__sun) || !defined (__SVR4) /* clear setuid and setgid if owner has changed */ /* unless request originated by root */ if (uid && (fileuid != uid)) mode &= 01777; #endif #if POSIXACLS res = ntfs_set_owner_mode(scx, ni, uid, gid, mode, pxdesc); #else res = ntfs_set_owner_mode(scx, ni, uid, gid, mode); #endif } else { res = -1; /* neither owner nor root */ errno = EPERM; } #if POSIXACLS if (pxdescbuilt) free(pxdesc); #endif } else { /* * Should not happen : a default descriptor is generated * by getsecurityattr() when there are none */ ntfs_log_error("File has no security descriptor\n"); res = -1; errno = EIO; } return (res ? -1 : 0); } /* * Define new owner/group and mode to a file * * returns zero if successful */ int ntfs_set_ownmod(struct SECURITY_CONTEXT *scx, ntfs_inode *ni, uid_t uid, gid_t gid, const mode_t mode) { const struct CACHED_PERMISSIONS *cached; char *oldattr; uid_t fileuid; uid_t filegid; int res; #if POSIXACLS const SECURITY_DESCRIPTOR_RELATIVE *phead; const SID *usid; const SID *gsid; BOOL isdir; const struct POSIX_SECURITY *oldpxdesc; struct POSIX_SECURITY *newpxdesc = (struct POSIX_SECURITY*)NULL; int pxsize; #endif res = 0; /* get the current owner and mode from cache or security attributes */ oldattr = (char*)NULL; cached = fetch_cache(scx,ni); if (cached) { fileuid = cached->uid; filegid = cached->gid; #if POSIXACLS oldpxdesc = cached->pxdesc; if (oldpxdesc) { /* must copy before merging */ pxsize = sizeof(struct POSIX_SECURITY) + (oldpxdesc->acccnt + oldpxdesc->defcnt)*sizeof(struct POSIX_ACE); newpxdesc = (struct POSIX_SECURITY*)malloc(pxsize); if (newpxdesc) { memcpy(newpxdesc, oldpxdesc, pxsize); if (ntfs_merge_mode_posix(newpxdesc, mode)) res = -1; } else res = -1; } #endif } else { fileuid = 0; filegid = 0; oldattr = getsecurityattr(scx->vol, ni); if (oldattr) { #if POSIXACLS isdir = (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) != const_cpu_to_le16(0); phead = (const SECURITY_DESCRIPTOR_RELATIVE*) oldattr; gsid = (const SID*) &oldattr[le32_to_cpu(phead->group)]; #if OWNERFROMACL usid = ntfs_acl_owner(oldattr); #else usid = (const SID*) &oldattr[le32_to_cpu(phead->owner)]; #endif newpxdesc = ntfs_build_permissions_posix(scx->mapping, oldattr, usid, gsid, isdir); if (!newpxdesc || ntfs_merge_mode_posix(newpxdesc, mode)) res = -1; else { fileuid = ntfs_find_user(scx->mapping[MAPUSERS],usid); filegid = ntfs_find_group(scx->mapping[MAPGROUPS],gsid); } #endif free(oldattr); } else res = -1; } if (!res) { /* check requested by root */ /* or chgrp requested by owner to an owned group */ if (!scx->uid || ((((int)uid < 0) || (uid == fileuid)) && ((gid == scx->gid) || groupmember(scx, scx->uid, gid)) && (fileuid == scx->uid))) { /* replace by the new usid and gsid */ /* or reuse old gid and sid for cacheing */ if ((int)uid < 0) uid = fileuid; if ((int)gid < 0) gid = filegid; #if POSIXACLS res = ntfs_set_owner_mode(scx, ni, uid, gid, mode, newpxdesc); #else res = ntfs_set_owner_mode(scx, ni, uid, gid, mode); #endif } else { res = -1; /* neither owner nor root */ errno = EPERM; } } else { /* * Should not happen : a default descriptor is generated * by getsecurityattr() when there are none */ ntfs_log_error("File has no security descriptor\n"); res = -1; errno = EIO; } #if POSIXACLS free(newpxdesc); #endif return (res ? -1 : 0); } /* * Build a security id for a descriptor inherited from * parent directory the Windows way */ static le32 build_inherited_id(struct SECURITY_CONTEXT *scx, const char *parentattr, BOOL fordir) { const SECURITY_DESCRIPTOR_RELATIVE *pphead; const ACL *ppacl; const SID *usid; const SID *gsid; BIGSID defusid; BIGSID defgsid; int offpacl; int offgroup; SECURITY_DESCRIPTOR_RELATIVE *pnhead; ACL *pnacl; int parentattrsz; char *newattr; int newattrsz; int aclsz; int usidsz; int gsidsz; int pos; le32 securid; parentattrsz = ntfs_attr_size(parentattr); pphead = (const SECURITY_DESCRIPTOR_RELATIVE*)parentattr; if (scx->mapping[MAPUSERS]) { usid = ntfs_find_usid(scx->mapping[MAPUSERS], scx->uid, (SID*)&defusid); gsid = ntfs_find_gsid(scx->mapping[MAPGROUPS], scx->gid, (SID*)&defgsid); #if OWNERFROMACL /* Get approximation of parent owner when cannot map */ if (!gsid) gsid = adminsid; if (!usid) { usid = ntfs_acl_owner(parentattr); if (!ntfs_is_user_sid(gsid)) gsid = usid; } #else /* Define owner as root when cannot map */ if (!usid) usid = adminsid; if (!gsid) gsid = adminsid; #endif } else { /* * If there is no user mapping and this is not a root * user, we have to get owner and group from somewhere, * and the parent directory has to contribute. * Windows never has to do that, because it can always * rely on a user mapping */ if (!scx->uid) usid = adminsid; else { #if OWNERFROMACL usid = ntfs_acl_owner(parentattr); #else int offowner; offowner = le32_to_cpu(pphead->owner); usid = (const SID*)&parentattr[offowner]; #endif } if (!scx->gid) gsid = adminsid; else { offgroup = le32_to_cpu(pphead->group); gsid = (const SID*)&parentattr[offgroup]; } } /* * new attribute is smaller than parent's * except for differences in SIDs which appear in * owner, group and possible grants and denials in * generic creator-owner and creator-group ACEs. * For directories, an ACE may be duplicated for * access and inheritance, so we double the count. */ usidsz = ntfs_sid_size(usid); gsidsz = ntfs_sid_size(gsid); newattrsz = parentattrsz + 3*usidsz + 3*gsidsz; if (fordir) newattrsz *= 2; newattr = (char*)ntfs_malloc(newattrsz); if (newattr) { pnhead = (SECURITY_DESCRIPTOR_RELATIVE*)newattr; pnhead->revision = SECURITY_DESCRIPTOR_REVISION; pnhead->alignment = 0; pnhead->control = (pphead->control & (SE_DACL_AUTO_INHERITED | SE_SACL_AUTO_INHERITED)) | SE_SELF_RELATIVE; pos = sizeof(SECURITY_DESCRIPTOR_RELATIVE); /* * locate and inherit DACL * do not test SE_DACL_PRESENT (wrong for "DR Watson") */ pnhead->dacl = const_cpu_to_le32(0); if (pphead->dacl) { offpacl = le32_to_cpu(pphead->dacl); ppacl = (const ACL*)&parentattr[offpacl]; pnacl = (ACL*)&newattr[pos]; aclsz = ntfs_inherit_acl(ppacl, pnacl, usid, gsid, fordir, pphead->control & SE_DACL_AUTO_INHERITED); if (aclsz) { pnhead->dacl = cpu_to_le32(pos); pos += aclsz; pnhead->control |= SE_DACL_PRESENT; } } /* * locate and inherit SACL */ pnhead->sacl = const_cpu_to_le32(0); if (pphead->sacl) { offpacl = le32_to_cpu(pphead->sacl); ppacl = (const ACL*)&parentattr[offpacl]; pnacl = (ACL*)&newattr[pos]; aclsz = ntfs_inherit_acl(ppacl, pnacl, usid, gsid, fordir, pphead->control & SE_SACL_AUTO_INHERITED); if (aclsz) { pnhead->sacl = cpu_to_le32(pos); pos += aclsz; pnhead->control |= SE_SACL_PRESENT; } } /* * inherit or redefine owner */ memcpy(&newattr[pos],usid,usidsz); pnhead->owner = cpu_to_le32(pos); pos += usidsz; /* * inherit or redefine group */ memcpy(&newattr[pos],gsid,gsidsz); pnhead->group = cpu_to_le32(pos); pos += gsidsz; securid = setsecurityattr(scx->vol, (SECURITY_DESCRIPTOR_RELATIVE*)newattr, pos); free(newattr); } else securid = const_cpu_to_le32(0); return (securid); } /* * Get an inherited security id * * For Windows compatibility, the normal initial permission setting * may be inherited from the parent directory instead of being * defined by the creation arguments. * * The following creates an inherited id for that purpose. * * Note : the owner and group of parent directory are also * inherited (which is not the case on Windows) if no user mapping * is defined. * * Returns the inherited id, or zero if not possible (eg on NTFS 1.x) */ le32 ntfs_inherited_id(struct SECURITY_CONTEXT *scx, ntfs_inode *dir_ni, BOOL fordir) { struct CACHED_PERMISSIONS *cached; char *parentattr; le32 securid; securid = const_cpu_to_le32(0); cached = (struct CACHED_PERMISSIONS*)NULL; /* * Try to get inherited id from cache, possible when * the current process owns the parent directory */ if (test_nino_flag(dir_ni, v3_Extensions) && dir_ni->security_id) { cached = fetch_cache(scx, dir_ni); if (cached && (cached->uid == scx->uid) && (cached->gid == scx->gid)) securid = (fordir ? cached->inh_dirid : cached->inh_fileid); } /* * Not cached or not available in cache, compute it all * Note : if parent directory has no id, it is not cacheable */ if (!securid) { parentattr = getsecurityattr(scx->vol, dir_ni); if (parentattr) { securid = build_inherited_id(scx, parentattr, fordir); free(parentattr); /* * Store the result into cache for further use * if the current process owns the parent directory */ if (securid) { cached = fetch_cache(scx, dir_ni); if (cached && (cached->uid == scx->uid) && (cached->gid == scx->gid)) { if (fordir) cached->inh_dirid = securid; else cached->inh_fileid = securid; } } } } return (securid); } /* * Link a group to a member of group * * Returns 0 if OK, -1 (and errno set) if error */ static int link_single_group(struct MAPPING *usermapping, struct passwd *user, gid_t gid) { struct group *group; char **grmem; int grcnt; gid_t *groups; int res; res = 0; group = getgrgid(gid); if (group && group->gr_mem) { grcnt = usermapping->grcnt; groups = usermapping->groups; grmem = group->gr_mem; while (*grmem && strcmp(user->pw_name, *grmem)) grmem++; if (*grmem) { if (!grcnt) groups = (gid_t*)malloc(sizeof(gid_t)); else groups = (gid_t*)realloc(groups, (grcnt+1)*sizeof(gid_t)); if (groups) groups[grcnt++] = gid; else { res = -1; errno = ENOMEM; } } usermapping->grcnt = grcnt; usermapping->groups = groups; } return (res); } /* * Statically link group to users * This is based on groups defined in /etc/group and does not take * the groups dynamically set by setgroups() nor any changes in * /etc/group into account * * Only mapped groups and root group are linked to mapped users * * Returns 0 if OK, -1 (and errno set) if error * */ static int link_group_members(struct SECURITY_CONTEXT *scx) { struct MAPPING *usermapping; struct MAPPING *groupmapping; struct passwd *user; int res; res = 0; for (usermapping=scx->mapping[MAPUSERS]; usermapping && !res; usermapping=usermapping->next) { usermapping->grcnt = 0; usermapping->groups = (gid_t*)NULL; user = getpwuid(usermapping->xid); if (user && user->pw_name) { for (groupmapping=scx->mapping[MAPGROUPS]; groupmapping && !res; groupmapping=groupmapping->next) { if (link_single_group(usermapping, user, groupmapping->xid)) res = -1; } if (!res && link_single_group(usermapping, user, (gid_t)0)) res = -1; } } return (res); } /* * Apply default single user mapping * returns zero if successful */ static int ntfs_do_default_mapping(struct SECURITY_CONTEXT *scx, uid_t uid, gid_t gid, const SID *usid) { struct MAPPING *usermapping; struct MAPPING *groupmapping; SID *sid; int sidsz; int res; res = -1; sidsz = ntfs_sid_size(usid); sid = (SID*)ntfs_malloc(sidsz); if (sid) { memcpy(sid,usid,sidsz); usermapping = (struct MAPPING*)ntfs_malloc(sizeof(struct MAPPING)); if (usermapping) { groupmapping = (struct MAPPING*)ntfs_malloc(sizeof(struct MAPPING)); if (groupmapping) { usermapping->sid = sid; usermapping->xid = uid; usermapping->next = (struct MAPPING*)NULL; groupmapping->sid = sid; groupmapping->xid = gid; groupmapping->next = (struct MAPPING*)NULL; scx->mapping[MAPUSERS] = usermapping; scx->mapping[MAPGROUPS] = groupmapping; res = 0; } } } return (res); } /* * Make sure there are no ambiguous mapping * Ambiguous mapping may lead to undesired configurations and * we had rather be safe until the consequences are understood */ #if 0 /* not activated for now */ static BOOL check_mapping(const struct MAPPING *usermapping, const struct MAPPING *groupmapping) { const struct MAPPING *mapping1; const struct MAPPING *mapping2; BOOL ambiguous; ambiguous = FALSE; for (mapping1=usermapping; mapping1; mapping1=mapping1->next) for (mapping2=mapping1->next; mapping2; mapping1=mapping2->next) if (ntfs_same_sid(mapping1->sid,mapping2->sid)) { if (mapping1->xid != mapping2->xid) ambiguous = TRUE; } else { if (mapping1->xid == mapping2->xid) ambiguous = TRUE; } for (mapping1=groupmapping; mapping1; mapping1=mapping1->next) for (mapping2=mapping1->next; mapping2; mapping1=mapping2->next) if (ntfs_same_sid(mapping1->sid,mapping2->sid)) { if (mapping1->xid != mapping2->xid) ambiguous = TRUE; } else { if (mapping1->xid == mapping2->xid) ambiguous = TRUE; } return (ambiguous); } #endif #if 0 /* not used any more */ /* * Try and apply default single user mapping * returns zero if successful */ static int ntfs_default_mapping(struct SECURITY_CONTEXT *scx) { const SECURITY_DESCRIPTOR_RELATIVE *phead; ntfs_inode *ni; char *securattr; const SID *usid; int res; res = -1; ni = ntfs_pathname_to_inode(scx->vol, NULL, "/."); if (ni) { securattr = getsecurityattr(scx->vol, ni); if (securattr) { phead = (const SECURITY_DESCRIPTOR_RELATIVE*)securattr; usid = (SID*)&securattr[le32_to_cpu(phead->owner)]; if (ntfs_is_user_sid(usid)) res = ntfs_do_default_mapping(scx, scx->uid, scx->gid, usid); free(securattr); } ntfs_inode_close(ni); } return (res); } #endif /* * Basic read from a user mapping file on another volume */ static int basicread(void *fileid, char *buf, size_t size, off_t offs __attribute__((unused))) { return (read(*(int*)fileid, buf, size)); } /* * Read from a user mapping file on current NTFS partition */ static int localread(void *fileid, char *buf, size_t size, off_t offs) { return (ntfs_attr_data_read((ntfs_inode*)fileid, AT_UNNAMED, 0, buf, size, offs)); } /* * Build the user mapping * - according to a mapping file if defined (or default present), * - or try default single user mapping if possible * * The mapping is specific to a mounted device * No locking done, mounting assumed non multithreaded * * returns zero if mapping is successful * (failure should not be interpreted as an error) */ int ntfs_build_mapping(struct SECURITY_CONTEXT *scx, const char *usermap_path, BOOL allowdef) { struct MAPLIST *item; struct MAPLIST *firstitem; struct MAPPING *usermapping; struct MAPPING *groupmapping; ntfs_inode *ni; int fd; static struct { u8 revision; u8 levels; be16 highbase; be32 lowbase; le32 level1; le32 level2; le32 level3; le32 level4; le32 level5; } defmap = { 1, 5, const_cpu_to_be16(0), const_cpu_to_be32(5), const_cpu_to_le32(21), const_cpu_to_le32(DEFSECAUTH1), const_cpu_to_le32(DEFSECAUTH2), const_cpu_to_le32(DEFSECAUTH3), const_cpu_to_le32(DEFSECBASE) } ; /* be sure not to map anything until done */ scx->mapping[MAPUSERS] = (struct MAPPING*)NULL; scx->mapping[MAPGROUPS] = (struct MAPPING*)NULL; if (!usermap_path) usermap_path = MAPPINGFILE; if (usermap_path[0] == '/') { fd = open(usermap_path,O_RDONLY); if (fd > 0) { firstitem = ntfs_read_mapping(basicread, (void*)&fd); close(fd); } else firstitem = (struct MAPLIST*)NULL; } else { ni = ntfs_pathname_to_inode(scx->vol, NULL, usermap_path); if (ni) { firstitem = ntfs_read_mapping(localread, ni); ntfs_inode_close(ni); } else firstitem = (struct MAPLIST*)NULL; } if (firstitem) { usermapping = ntfs_do_user_mapping(firstitem); groupmapping = ntfs_do_group_mapping(firstitem); if (usermapping && groupmapping) { scx->mapping[MAPUSERS] = usermapping; scx->mapping[MAPGROUPS] = groupmapping; } else ntfs_log_error("There were no valid user or no valid group\n"); /* now we can free the memory copy of input text */ /* and rely on internal representation */ while (firstitem) { item = firstitem->next; free(firstitem); firstitem = item; } } else { /* no mapping file, try a default mapping */ if (allowdef) { if (!ntfs_do_default_mapping(scx, 0, 0, (const SID*)&defmap)) ntfs_log_info("Using default user mapping\n"); } } return (!scx->mapping[MAPUSERS] || link_group_members(scx)); } /* * Get the ntfs attribute into an extended attribute * The attribute is returned according to cpu endianness */ int ntfs_get_ntfs_attrib(ntfs_inode *ni, char *value, size_t size) { u32 attrib; size_t outsize; outsize = 0; /* default to no data and no error */ if (ni) { attrib = le32_to_cpu(ni->flags); if (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) attrib |= const_le32_to_cpu(FILE_ATTR_DIRECTORY); else attrib &= ~const_le32_to_cpu(FILE_ATTR_DIRECTORY); if (!attrib) attrib |= const_le32_to_cpu(FILE_ATTR_NORMAL); outsize = sizeof(FILE_ATTR_FLAGS); if (size >= outsize) { if (value) memcpy(value,&attrib,outsize); else errno = EINVAL; } } return (outsize ? (int)outsize : -errno); } /* * Return the ntfs attribute into an extended attribute * The attribute is expected according to cpu endianness * * Returns 0, or -1 if there is a problem */ int ntfs_set_ntfs_attrib(ntfs_inode *ni, const char *value, size_t size, int flags) { u32 attrib; le32 settable; ATTR_FLAGS dirflags; int res; res = -1; if (ni && value && (size >= sizeof(FILE_ATTR_FLAGS))) { if (!(flags & XATTR_CREATE)) { /* copy to avoid alignment problems */ memcpy(&attrib,value,sizeof(FILE_ATTR_FLAGS)); settable = FILE_ATTR_SETTABLE; res = 0; if (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) { /* * Accept changing compression for a directory * and set index root accordingly */ settable |= FILE_ATTR_COMPRESSED; if ((ni->flags ^ cpu_to_le32(attrib)) & FILE_ATTR_COMPRESSED) { if (ni->flags & FILE_ATTR_COMPRESSED) dirflags = const_cpu_to_le16(0); else dirflags = ATTR_IS_COMPRESSED; res = ntfs_attr_set_flags(ni, AT_INDEX_ROOT, NTFS_INDEX_I30, 4, dirflags, ATTR_COMPRESSION_MASK); } } if (!res) { ni->flags = (ni->flags & ~settable) | (cpu_to_le32(attrib) & settable); NInoFileNameSetDirty(ni); NInoSetDirty(ni); } } else errno = EEXIST; } else errno = EINVAL; return (res ? -1 : 0); } /* * Open the volume's security descriptor index ($Secure) * * returns 0 if it succeeds * -1 with errno set if it fails and the volume is NTFS v3.0+ */ int ntfs_open_secure(ntfs_volume *vol) { ntfs_inode *ni; ntfs_index_context *sii; ntfs_index_context *sdh; if (vol->secure_ni) /* Already open? */ return 0; ni = ntfs_pathname_to_inode(vol, NULL, "$Secure"); if (!ni) goto err; if (ni->mft_no != FILE_Secure) { ntfs_log_error("$Secure does not have expected inode number!"); errno = EINVAL; goto err_close_ni; } /* Allocate the needed index contexts. */ sii = ntfs_index_ctx_get(ni, sii_stream, 4); if (!sii) goto err_close_ni; sdh = ntfs_index_ctx_get(ni, sdh_stream, 4); if (!sdh) goto err_close_sii; vol->secure_xsdh = sdh; vol->secure_xsii = sii; vol->secure_ni = ni; return 0; err_close_sii: ntfs_index_ctx_put(sii); err_close_ni: ntfs_inode_close(ni); err: /* Failing on NTFS pre-v3.0 is expected. */ if (vol->major_ver < 3) return 0; ntfs_log_perror("Failed to open $Secure"); return -1; } /* * Close the volume's security descriptor index ($Secure) * * returns 0 if it succeeds * -1 with errno set if it fails */ int ntfs_close_secure(ntfs_volume *vol) { int res = 0; if (vol->secure_ni) { ntfs_index_ctx_put(vol->secure_xsdh); ntfs_index_ctx_put(vol->secure_xsii); res = ntfs_inode_close(vol->secure_ni); vol->secure_ni = NULL; } return res; } /* * Destroy a security context * Allocated memory is freed to facilitate the detection of memory leaks */ void ntfs_destroy_security_context(struct SECURITY_CONTEXT *scx) { ntfs_free_mapping(scx->mapping); free_caches(scx); } /* * API for direct access to security descriptors * based on Win32 API */ /* * Selective feeding of a security descriptor into user buffer * * Returns TRUE if successful */ static BOOL feedsecurityattr(const char *attr, u32 selection, char *buf, u32 buflen, u32 *psize) { const SECURITY_DESCRIPTOR_RELATIVE *phead; SECURITY_DESCRIPTOR_RELATIVE *pnhead; const ACL *pdacl; const ACL *psacl; const SID *pusid; const SID *pgsid; unsigned int offdacl; unsigned int offsacl; unsigned int offowner; unsigned int offgroup; unsigned int daclsz; unsigned int saclsz; unsigned int usidsz; unsigned int gsidsz; unsigned int size; /* size of requested attributes */ BOOL ok; unsigned int pos; unsigned int avail; le16 control; avail = 0; control = SE_SELF_RELATIVE; phead = (const SECURITY_DESCRIPTOR_RELATIVE*)attr; size = sizeof(SECURITY_DESCRIPTOR_RELATIVE); /* locate DACL if requested and available */ if (phead->dacl && (selection & DACL_SECURITY_INFORMATION)) { offdacl = le32_to_cpu(phead->dacl); pdacl = (const ACL*)&attr[offdacl]; daclsz = le16_to_cpu(pdacl->size); size += daclsz; avail |= DACL_SECURITY_INFORMATION; } else offdacl = daclsz = 0; /* locate owner if requested and available */ offowner = le32_to_cpu(phead->owner); if (offowner && (selection & OWNER_SECURITY_INFORMATION)) { /* find end of USID */ pusid = (const SID*)&attr[offowner]; usidsz = ntfs_sid_size(pusid); size += usidsz; avail |= OWNER_SECURITY_INFORMATION; } else offowner = usidsz = 0; /* locate group if requested and available */ offgroup = le32_to_cpu(phead->group); if (offgroup && (selection & GROUP_SECURITY_INFORMATION)) { /* find end of GSID */ pgsid = (const SID*)&attr[offgroup]; gsidsz = ntfs_sid_size(pgsid); size += gsidsz; avail |= GROUP_SECURITY_INFORMATION; } else offgroup = gsidsz = 0; /* locate SACL if requested and available */ if (phead->sacl && (selection & SACL_SECURITY_INFORMATION)) { /* find end of SACL */ offsacl = le32_to_cpu(phead->sacl); psacl = (const ACL*)&attr[offsacl]; saclsz = le16_to_cpu(psacl->size); size += saclsz; avail |= SACL_SECURITY_INFORMATION; } else offsacl = saclsz = 0; /* * Check having enough size in destination buffer * (required size is returned nevertheless so that * the request can be reissued with adequate size) */ if (size > buflen) { *psize = size; errno = EINVAL; ok = FALSE; } else { if (selection & OWNER_SECURITY_INFORMATION) control |= phead->control & SE_OWNER_DEFAULTED; if (selection & GROUP_SECURITY_INFORMATION) control |= phead->control & SE_GROUP_DEFAULTED; if (selection & DACL_SECURITY_INFORMATION) control |= phead->control & (SE_DACL_PRESENT | SE_DACL_DEFAULTED | SE_DACL_AUTO_INHERITED | SE_DACL_PROTECTED); if (selection & SACL_SECURITY_INFORMATION) control |= phead->control & (SE_SACL_PRESENT | SE_SACL_DEFAULTED | SE_SACL_AUTO_INHERITED | SE_SACL_PROTECTED); /* * copy header and feed new flags, even if no detailed data */ memcpy(buf,attr,sizeof(SECURITY_DESCRIPTOR_RELATIVE)); pnhead = (SECURITY_DESCRIPTOR_RELATIVE*)buf; pnhead->control = control; pos = sizeof(SECURITY_DESCRIPTOR_RELATIVE); /* copy DACL if requested and available */ if (selection & avail & DACL_SECURITY_INFORMATION) { pnhead->dacl = cpu_to_le32(pos); memcpy(&buf[pos],&attr[offdacl],daclsz); pos += daclsz; } else pnhead->dacl = const_cpu_to_le32(0); /* copy SACL if requested and available */ if (selection & avail & SACL_SECURITY_INFORMATION) { pnhead->sacl = cpu_to_le32(pos); memcpy(&buf[pos],&attr[offsacl],saclsz); pos += saclsz; } else pnhead->sacl = const_cpu_to_le32(0); /* copy owner if requested and available */ if (selection & avail & OWNER_SECURITY_INFORMATION) { pnhead->owner = cpu_to_le32(pos); memcpy(&buf[pos],&attr[offowner],usidsz); pos += usidsz; } else pnhead->owner = const_cpu_to_le32(0); /* copy group if requested and available */ if (selection & avail & GROUP_SECURITY_INFORMATION) { pnhead->group = cpu_to_le32(pos); memcpy(&buf[pos],&attr[offgroup],gsidsz); pos += gsidsz; } else pnhead->group = const_cpu_to_le32(0); if (pos != size) ntfs_log_error("Error in security descriptor size\n"); *psize = size; ok = TRUE; } return (ok); } /* * Merge a new security descriptor into the old one * and assign to designated file * * Returns TRUE if successful */ static BOOL mergesecurityattr(ntfs_volume *vol, const char *oldattr, const char *newattr, u32 selection, ntfs_inode *ni) { const SECURITY_DESCRIPTOR_RELATIVE *oldhead; const SECURITY_DESCRIPTOR_RELATIVE *newhead; SECURITY_DESCRIPTOR_RELATIVE *targhead; const ACL *pdacl; const ACL *psacl; const SID *powner; const SID *pgroup; int offdacl; int offsacl; int offowner; int offgroup; unsigned int size; le16 control; char *target; int pos; int oldattrsz; int newattrsz; BOOL ok; ok = FALSE; /* default return */ oldhead = (const SECURITY_DESCRIPTOR_RELATIVE*)oldattr; newhead = (const SECURITY_DESCRIPTOR_RELATIVE*)newattr; oldattrsz = ntfs_attr_size(oldattr); newattrsz = ntfs_attr_size(newattr); target = (char*)ntfs_malloc(oldattrsz + newattrsz); if (target) { targhead = (SECURITY_DESCRIPTOR_RELATIVE*)target; pos = sizeof(SECURITY_DESCRIPTOR_RELATIVE); control = SE_SELF_RELATIVE; /* * copy new DACL if selected * or keep old DACL if any */ if ((selection & DACL_SECURITY_INFORMATION) ? newhead->dacl : oldhead->dacl) { if (selection & DACL_SECURITY_INFORMATION) { offdacl = le32_to_cpu(newhead->dacl); pdacl = (const ACL*)&newattr[offdacl]; } else { offdacl = le32_to_cpu(oldhead->dacl); pdacl = (const ACL*)&oldattr[offdacl]; } size = le16_to_cpu(pdacl->size); memcpy(&target[pos], pdacl, size); targhead->dacl = cpu_to_le32(pos); pos += size; } else targhead->dacl = const_cpu_to_le32(0); if (selection & DACL_SECURITY_INFORMATION) { control |= newhead->control & (SE_DACL_PRESENT | SE_DACL_DEFAULTED | SE_DACL_PROTECTED); if (newhead->control & SE_DACL_AUTO_INHERIT_REQ) control |= SE_DACL_AUTO_INHERITED; } else control |= oldhead->control & (SE_DACL_PRESENT | SE_DACL_DEFAULTED | SE_DACL_AUTO_INHERITED | SE_DACL_PROTECTED); /* * copy new SACL if selected * or keep old SACL if any */ if ((selection & SACL_SECURITY_INFORMATION) ? newhead->sacl : oldhead->sacl) { if (selection & SACL_SECURITY_INFORMATION) { offsacl = le32_to_cpu(newhead->sacl); psacl = (const ACL*)&newattr[offsacl]; } else { offsacl = le32_to_cpu(oldhead->sacl); psacl = (const ACL*)&oldattr[offsacl]; } size = le16_to_cpu(psacl->size); memcpy(&target[pos], psacl, size); targhead->sacl = cpu_to_le32(pos); pos += size; } else targhead->sacl = const_cpu_to_le32(0); if (selection & SACL_SECURITY_INFORMATION) { control |= newhead->control & (SE_SACL_PRESENT | SE_SACL_DEFAULTED | SE_SACL_PROTECTED); if (newhead->control & SE_SACL_AUTO_INHERIT_REQ) control |= SE_SACL_AUTO_INHERITED; } else control |= oldhead->control & (SE_SACL_PRESENT | SE_SACL_DEFAULTED | SE_SACL_AUTO_INHERITED | SE_SACL_PROTECTED); /* * copy new OWNER if selected * or keep old OWNER if any */ if ((selection & OWNER_SECURITY_INFORMATION) ? newhead->owner : oldhead->owner) { if (selection & OWNER_SECURITY_INFORMATION) { offowner = le32_to_cpu(newhead->owner); powner = (const SID*)&newattr[offowner]; } else { offowner = le32_to_cpu(oldhead->owner); powner = (const SID*)&oldattr[offowner]; } size = ntfs_sid_size(powner); memcpy(&target[pos], powner, size); targhead->owner = cpu_to_le32(pos); pos += size; } else targhead->owner = const_cpu_to_le32(0); if (selection & OWNER_SECURITY_INFORMATION) control |= newhead->control & SE_OWNER_DEFAULTED; else control |= oldhead->control & SE_OWNER_DEFAULTED; /* * copy new GROUP if selected * or keep old GROUP if any */ if ((selection & GROUP_SECURITY_INFORMATION) ? newhead->group : oldhead->group) { if (selection & GROUP_SECURITY_INFORMATION) { offgroup = le32_to_cpu(newhead->group); pgroup = (const SID*)&newattr[offgroup]; control |= newhead->control & SE_GROUP_DEFAULTED; } else { offgroup = le32_to_cpu(oldhead->group); pgroup = (const SID*)&oldattr[offgroup]; control |= oldhead->control & SE_GROUP_DEFAULTED; } size = ntfs_sid_size(pgroup); memcpy(&target[pos], pgroup, size); targhead->group = cpu_to_le32(pos); pos += size; } else targhead->group = const_cpu_to_le32(0); if (selection & GROUP_SECURITY_INFORMATION) control |= newhead->control & SE_GROUP_DEFAULTED; else control |= oldhead->control & SE_GROUP_DEFAULTED; targhead->revision = SECURITY_DESCRIPTOR_REVISION; targhead->alignment = 0; targhead->control = control; ok = !update_secur_descr(vol, target, ni); free(target); } return (ok); } /* * Return the security descriptor of a file * This is intended to be similar to GetFileSecurity() from Win32 * in order to facilitate the development of portable tools * * returns zero if unsuccessful (following Win32 conventions) * -1 if no securid * the securid if any * * The Win32 API is : * * BOOL WINAPI GetFileSecurity( * __in LPCTSTR lpFileName, * __in SECURITY_INFORMATION RequestedInformation, * __out_opt PSECURITY_DESCRIPTOR pSecurityDescriptor, * __in DWORD nLength, * __out LPDWORD lpnLengthNeeded * ); * */ int ntfs_get_file_security(struct SECURITY_API *scapi, const char *path, u32 selection, char *buf, u32 buflen, u32 *psize) { ntfs_inode *ni; char *attr; int res; res = 0; /* default return */ if (scapi && (scapi->magic == MAGIC_API)) { ni = ntfs_pathname_to_inode(scapi->security.vol, NULL, path); if (ni) { attr = getsecurityattr(scapi->security.vol, ni); if (attr) { if (feedsecurityattr(attr,selection, buf,buflen,psize)) { if (test_nino_flag(ni, v3_Extensions) && ni->security_id) res = le32_to_cpu( ni->security_id); else res = -1; } free(attr); } ntfs_inode_close(ni); } else errno = ENOENT; if (!res) *psize = 0; } else errno = EINVAL; /* do not clear *psize */ return (res); } /* * Set the security descriptor of a file or directory * This is intended to be similar to SetFileSecurity() from Win32 * in order to facilitate the development of portable tools * * returns zero if unsuccessful (following Win32 conventions) * -1 if no securid * the securid if any * * The Win32 API is : * * BOOL WINAPI SetFileSecurity( * __in LPCTSTR lpFileName, * __in SECURITY_INFORMATION SecurityInformation, * __in PSECURITY_DESCRIPTOR pSecurityDescriptor * ); */ int ntfs_set_file_security(struct SECURITY_API *scapi, const char *path, u32 selection, const char *attr) { const SECURITY_DESCRIPTOR_RELATIVE *phead; ntfs_inode *ni; int attrsz; BOOL missing; char *oldattr; int res; res = 0; /* default return */ if (scapi && (scapi->magic == MAGIC_API) && attr) { phead = (const SECURITY_DESCRIPTOR_RELATIVE*)attr; attrsz = ntfs_attr_size(attr); /* if selected, owner and group must be present or defaulted */ missing = ((selection & OWNER_SECURITY_INFORMATION) && !phead->owner && !(phead->control & SE_OWNER_DEFAULTED)) || ((selection & GROUP_SECURITY_INFORMATION) && !phead->group && !(phead->control & SE_GROUP_DEFAULTED)); if (!missing && (phead->control & SE_SELF_RELATIVE) && ntfs_valid_descr(attr, attrsz)) { ni = ntfs_pathname_to_inode(scapi->security.vol, NULL, path); if (ni) { oldattr = getsecurityattr(scapi->security.vol, ni); if (oldattr) { if (mergesecurityattr( scapi->security.vol, oldattr, attr, selection, ni)) { if (test_nino_flag(ni, v3_Extensions)) res = le32_to_cpu( ni->security_id); else res = -1; } free(oldattr); } ntfs_inode_close(ni); } } else errno = EINVAL; } else errno = EINVAL; return (res); } /* * Return the attributes of a file * This is intended to be similar to GetFileAttributes() from Win32 * in order to facilitate the development of portable tools * * returns -1 if unsuccessful (Win32 : INVALID_FILE_ATTRIBUTES) * * The Win32 API is : * * DWORD WINAPI GetFileAttributes( * __in LPCTSTR lpFileName * ); */ int ntfs_get_file_attributes(struct SECURITY_API *scapi, const char *path) { ntfs_inode *ni; s32 attrib; attrib = -1; /* default return */ if (scapi && (scapi->magic == MAGIC_API) && path) { ni = ntfs_pathname_to_inode(scapi->security.vol, NULL, path); if (ni) { attrib = le32_to_cpu(ni->flags); if (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) attrib |= const_le32_to_cpu(FILE_ATTR_DIRECTORY); else attrib &= ~const_le32_to_cpu(FILE_ATTR_DIRECTORY); if (!attrib) attrib |= const_le32_to_cpu(FILE_ATTR_NORMAL); ntfs_inode_close(ni); } else errno = ENOENT; } else errno = EINVAL; /* do not clear *psize */ return (attrib); } /* * Set attributes to a file or directory * This is intended to be similar to SetFileAttributes() from Win32 * in order to facilitate the development of portable tools * * Only a few flags can be set (same list as Win32) * * returns zero if unsuccessful (following Win32 conventions) * nonzero if successful * * The Win32 API is : * * BOOL WINAPI SetFileAttributes( * __in LPCTSTR lpFileName, * __in DWORD dwFileAttributes * ); */ BOOL ntfs_set_file_attributes(struct SECURITY_API *scapi, const char *path, s32 attrib) { ntfs_inode *ni; le32 settable; ATTR_FLAGS dirflags; int res; res = 0; /* default return */ if (scapi && (scapi->magic == MAGIC_API) && path) { ni = ntfs_pathname_to_inode(scapi->security.vol, NULL, path); if (ni) { settable = FILE_ATTR_SETTABLE; if (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) { /* * Accept changing compression for a directory * and set index root accordingly */ settable |= FILE_ATTR_COMPRESSED; if ((ni->flags ^ cpu_to_le32(attrib)) & FILE_ATTR_COMPRESSED) { if (ni->flags & FILE_ATTR_COMPRESSED) dirflags = const_cpu_to_le16(0); else dirflags = ATTR_IS_COMPRESSED; res = ntfs_attr_set_flags(ni, AT_INDEX_ROOT, NTFS_INDEX_I30, 4, dirflags, ATTR_COMPRESSION_MASK); } } if (!res) { ni->flags = (ni->flags & ~settable) | (cpu_to_le32(attrib) & settable); NInoSetDirty(ni); NInoFileNameSetDirty(ni); } if (!ntfs_inode_close(ni)) res = -1; } else errno = ENOENT; } return (res); } BOOL ntfs_read_directory(struct SECURITY_API *scapi, const char *path, ntfs_filldir_t callback, void *context) { ntfs_inode *ni; BOOL ok; s64 pos; ok = FALSE; /* default return */ if (scapi && (scapi->magic == MAGIC_API) && callback) { ni = ntfs_pathname_to_inode(scapi->security.vol, NULL, path); if (ni) { if (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) { pos = 0; ntfs_readdir(ni,&pos,context,callback); ok = !ntfs_inode_close(ni); } else { ntfs_inode_close(ni); errno = ENOTDIR; } } else errno = ENOENT; } else errno = EINVAL; /* do not clear *psize */ return (ok); } /* * read $SDS (for auditing security data) * * Returns the number or read bytes, or -1 if there is an error */ int ntfs_read_sds(struct SECURITY_API *scapi, char *buf, u32 size, u32 offset) { int got; got = -1; /* default return */ if (scapi && (scapi->magic == MAGIC_API)) { if (scapi->security.vol->secure_ni) got = ntfs_attr_data_read(scapi->security.vol->secure_ni, STREAM_SDS, 4, buf, size, offset); else errno = EOPNOTSUPP; } else errno = EINVAL; return (got); } /* * read $SII (for auditing security data) * * Returns next entry, or NULL if there is an error */ INDEX_ENTRY *ntfs_read_sii(struct SECURITY_API *scapi, INDEX_ENTRY *entry) { SII_INDEX_KEY key; INDEX_ENTRY *ret; BOOL found; ntfs_index_context *xsii; ret = (INDEX_ENTRY*)NULL; /* default return */ if (scapi && (scapi->magic == MAGIC_API)) { xsii = scapi->security.vol->secure_xsii; if (xsii) { if (!entry) { key.security_id = const_cpu_to_le32(0); found = !ntfs_index_lookup((char*)&key, sizeof(SII_INDEX_KEY), xsii); /* not supposed to find */ if (!found && (errno == ENOENT)) ret = xsii->entry; } else ret = ntfs_index_next(entry,xsii); if (!ret) errno = ENODATA; } else errno = EOPNOTSUPP; } else errno = EINVAL; return (ret); } /* * read $SDH (for auditing security data) * * Returns next entry, or NULL if there is an error */ INDEX_ENTRY *ntfs_read_sdh(struct SECURITY_API *scapi, INDEX_ENTRY *entry) { SDH_INDEX_KEY key; INDEX_ENTRY *ret; BOOL found; ntfs_index_context *xsdh; ret = (INDEX_ENTRY*)NULL; /* default return */ if (scapi && (scapi->magic == MAGIC_API)) { xsdh = scapi->security.vol->secure_xsdh; if (xsdh) { if (!entry) { key.hash = const_cpu_to_le32(0); key.security_id = const_cpu_to_le32(0); found = !ntfs_index_lookup((char*)&key, sizeof(SDH_INDEX_KEY), xsdh); /* not supposed to find */ if (!found && (errno == ENOENT)) ret = xsdh->entry; } else ret = ntfs_index_next(entry,xsdh); if (!ret) errno = ENODATA; } else errno = ENOTSUP; } else errno = EINVAL; return (ret); } /* * Get the mapped user SID * A buffer of 40 bytes has to be supplied * * returns the size of the SID, or zero and errno set if not found */ int ntfs_get_usid(struct SECURITY_API *scapi, uid_t uid, char *buf) { const SID *usid; BIGSID defusid; int size; size = 0; if (scapi && (scapi->magic == MAGIC_API)) { usid = ntfs_find_usid(scapi->security.mapping[MAPUSERS], uid, (SID*)&defusid); if (usid) { size = ntfs_sid_size(usid); memcpy(buf,usid,size); } else errno = ENODATA; } else errno = EINVAL; return (size); } /* * Get the mapped group SID * A buffer of 40 bytes has to be supplied * * returns the size of the SID, or zero and errno set if not found */ int ntfs_get_gsid(struct SECURITY_API *scapi, gid_t gid, char *buf) { const SID *gsid; BIGSID defgsid; int size; size = 0; if (scapi && (scapi->magic == MAGIC_API)) { gsid = ntfs_find_gsid(scapi->security.mapping[MAPGROUPS], gid, (SID*)&defgsid); if (gsid) { size = ntfs_sid_size(gsid); memcpy(buf,gsid,size); } else errno = ENODATA; } else errno = EINVAL; return (size); } /* * Get the user mapped to a SID * * returns the uid, or -1 if not found */ int ntfs_get_user(struct SECURITY_API *scapi, const SID *usid) { int uid; uid = -1; if (scapi && (scapi->magic == MAGIC_API) && ntfs_valid_sid(usid)) { if (ntfs_same_sid(usid,adminsid)) uid = 0; else { uid = ntfs_find_user(scapi->security.mapping[MAPUSERS], usid); if (!uid) { uid = -1; errno = ENODATA; } } } else errno = EINVAL; return (uid); } /* * Get the group mapped to a SID * * returns the uid, or -1 if not found */ int ntfs_get_group(struct SECURITY_API *scapi, const SID *gsid) { int gid; gid = -1; if (scapi && (scapi->magic == MAGIC_API) && ntfs_valid_sid(gsid)) { if (ntfs_same_sid(gsid,adminsid)) gid = 0; else { gid = ntfs_find_group(scapi->security.mapping[MAPGROUPS], gsid); if (!gid) { gid = -1; errno = ENODATA; } } } else errno = EINVAL; return (gid); } /* * Initializations before calling ntfs_get_file_security() * ntfs_set_file_security() and ntfs_read_directory() * * Only allowed for root * * Returns an (obscured) struct SECURITY_API* needed for further calls * NULL if not root (EPERM) or device is mounted (EBUSY) */ struct SECURITY_API *ntfs_initialize_file_security(const char *device, unsigned long flags) { ntfs_volume *vol; unsigned long mntflag; int mnt; struct SECURITY_API *scapi; struct SECURITY_CONTEXT *scx; scapi = (struct SECURITY_API*)NULL; mnt = ntfs_check_if_mounted(device, &mntflag); if (!mnt && !(mntflag & NTFS_MF_MOUNTED) && !getuid()) { vol = ntfs_mount(device, flags); if (vol) { scapi = (struct SECURITY_API*) ntfs_malloc(sizeof(struct SECURITY_API)); if (!ntfs_volume_get_free_space(vol) && scapi) { scapi->magic = MAGIC_API; scapi->seccache = (struct PERMISSIONS_CACHE*)NULL; scx = &scapi->security; scx->vol = vol; scx->uid = getuid(); scx->gid = getgid(); scx->pseccache = &scapi->seccache; scx->vol->secure_flags = 0; /* accept no mapping and no $Secure */ ntfs_build_mapping(scx,(const char*)NULL,TRUE); } else { if (scapi) free(scapi); else errno = ENOMEM; mnt = ntfs_umount(vol,FALSE); scapi = (struct SECURITY_API*)NULL; } } } else if (getuid()) errno = EPERM; else errno = EBUSY; return (scapi); } /* * Leaving after ntfs_initialize_file_security() * * Returns FALSE if FAILED */ BOOL ntfs_leave_file_security(struct SECURITY_API *scapi) { int ok; ntfs_volume *vol; ok = FALSE; if (scapi && (scapi->magic == MAGIC_API) && scapi->security.vol) { vol = scapi->security.vol; ntfs_destroy_security_context(&scapi->security); free(scapi); if (!ntfs_umount(vol, 0)) ok = TRUE; } return (ok); } ntfs-3g-2026.2.25/libntfs-3g/bitmap.c0000664000175000017500000001755715152260173012407 /** * bitmap.c - Bitmap handling code. Originated from the Linux-NTFS project. * * Copyright (c) 2002-2006 Anton Altaparmakov * Copyright (c) 2004-2005 Richard Russon * Copyright (c) 2004-2008 Szabolcs Szakacsits * * This program/include file 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/include file 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_STDLIB_H #include #endif #ifdef HAVE_STDIO_H #include #endif #ifdef HAVE_STRING_H #include #endif #ifdef HAVE_ERRNO_H #include #endif #include "types.h" #include "attrib.h" #include "bitmap.h" #include "debug.h" #include "logging.h" #include "misc.h" /** * ntfs_bit_set - set a bit in a field of bits * @bitmap: field of bits * @bit: bit to set * @new_value: value to set bit to (0 or 1) * * Set the bit @bit in the @bitmap to @new_value. Ignore all errors. */ void ntfs_bit_set(u8 *bitmap, const u64 bit, const u8 new_value) { if (!bitmap || new_value > 1) return; if (!new_value) bitmap[bit >> 3] &= ~(1 << (bit & 7)); else bitmap[bit >> 3] |= (1 << (bit & 7)); } /** * ntfs_bit_get - get value of a bit in a field of bits * @bitmap: field of bits * @bit: bit to get * * Get and return the value of the bit @bit in @bitmap (0 or 1). * Return -1 on error. */ char ntfs_bit_get(const u8 *bitmap, const u64 bit) { if (!bitmap) return -1; return (bitmap[bit >> 3] >> (bit & 7)) & 1; } /** * ntfs_bit_get_and_set - get value of a bit in a field of bits and set it * @bitmap: field of bits * @bit: bit to get/set * @new_value: value to set bit to (0 or 1) * * Return the value of the bit @bit and set it to @new_value (0 or 1). * Return -1 on error. */ char ntfs_bit_get_and_set(u8 *bitmap, const u64 bit, const u8 new_value) { register u8 old_bit, shift; if (!bitmap || new_value > 1) return -1; shift = bit & 7; old_bit = (bitmap[bit >> 3] >> shift) & 1; if (new_value != old_bit) bitmap[bit >> 3] ^= 1 << shift; return old_bit; } /** * ntfs_bitmap_set_bits_in_run - set a run of bits in a bitmap to a value * @na: attribute containing the bitmap * @start_bit: first bit to set * @count: number of bits to set * @value: value to set the bits to (i.e. 0 or 1) * * Set @count bits starting at bit @start_bit in the bitmap described by the * attribute @na to @value, where @value is either 0 or 1. * * On success return 0 and on error return -1 with errno set to the error code. */ static int ntfs_bitmap_set_bits_in_run(ntfs_attr *na, s64 start_bit, s64 count, int value) { s64 bufsize, br; u8 *buf, *lastbyte_buf; int bit, firstbyte, lastbyte, lastbyte_pos, tmp, ret = -1; if (!na || start_bit < 0 || count < 0) { errno = EINVAL; ntfs_log_perror("%s: Invalid argument (%p, %lld, %lld)", __FUNCTION__, na, (long long)start_bit, (long long)count); return -1; } bit = start_bit & 7; if (bit) firstbyte = 1; else firstbyte = 0; /* Calculate the required buffer size in bytes, capping it at 8kiB. */ bufsize = ((count - (bit ? 8 - bit : 0) + 7) >> 3) + firstbyte; if (bufsize > 8192) bufsize = 8192; buf = ntfs_malloc(bufsize); if (!buf) return -1; /* Depending on @value, zero or set all bits in the allocated buffer. */ memset(buf, value ? 0xff : 0, bufsize); /* If there is a first partial byte... */ if (bit) { /* read it in... */ br = ntfs_attr_pread(na, start_bit >> 3, 1, buf); if (br != 1) { if (br >= 0) errno = EIO; goto free_err_out; } /* and set or clear the appropriate bits in it. */ while ((bit & 7) && count--) { if (value) *buf |= 1 << bit++; else *buf &= ~(1 << bit++); } /* Update @start_bit to the new position. */ start_bit = (start_bit + 7) & ~7; } /* Loop until @count reaches zero. */ lastbyte = 0; lastbyte_buf = NULL; bit = count & 7; do { /* If there is a last partial byte... */ if (count > 0 && bit) { lastbyte_pos = ((count + 7) >> 3) + firstbyte; if (!lastbyte_pos) { // FIXME: Eeek! BUG! ntfs_log_error("Lastbyte is zero. Leaving " "inconsistent metadata.\n"); errno = EIO; goto free_err_out; } /* and it is in the currently loaded bitmap window... */ if (lastbyte_pos <= bufsize) { lastbyte_buf = buf + lastbyte_pos - 1; /* read the byte in... */ br = ntfs_attr_pread(na, (start_bit + count) >> 3, 1, lastbyte_buf); if (br != 1) { // FIXME: Eeek! We need rollback! (AIA) if (br >= 0) errno = EIO; ntfs_log_perror("Reading of last byte " "failed (%lld). Leaving inconsistent " "metadata", (long long)br); goto free_err_out; } /* and set/clear the appropriate bits in it. */ while (bit && count--) { if (value) *lastbyte_buf |= 1 << --bit; else *lastbyte_buf &= ~(1 << --bit); } /* We don't want to come back here... */ bit = 0; /* We have a last byte that we have handled. */ lastbyte = 1; } } /* Write the prepared buffer to disk. */ tmp = (start_bit >> 3) - firstbyte; br = ntfs_attr_pwrite(na, tmp, bufsize, buf); if (br != bufsize) { // FIXME: Eeek! We need rollback! (AIA) if (br >= 0) errno = EIO; ntfs_log_perror("Failed to write buffer to bitmap " "(%lld != %lld). Leaving inconsistent metadata", (long long)br, (long long)bufsize); goto free_err_out; } /* Update counters. */ tmp = (bufsize - firstbyte - lastbyte) << 3; if (firstbyte) { firstbyte = 0; /* * Re-set the partial first byte so a subsequent write * of the buffer does not have stale, incorrect bits. */ *buf = value ? 0xff : 0; } start_bit += tmp; count -= tmp; if (bufsize > (tmp = (count + 7) >> 3)) bufsize = tmp; if (lastbyte && count != 0) { // FIXME: Eeek! BUG! ntfs_log_error("Last buffer but count is not zero " "(%lld). Leaving inconsistent metadata.\n", (long long)count); errno = EIO; goto free_err_out; } } while (count > 0); ret = 0; free_err_out: free(buf); return ret; } /** * ntfs_bitmap_set_run - set a run of bits in a bitmap * @na: attribute containing the bitmap * @start_bit: first bit to set * @count: number of bits to set * * Set @count bits starting at bit @start_bit in the bitmap described by the * attribute @na. * * On success return 0 and on error return -1 with errno set to the error code. */ int ntfs_bitmap_set_run(ntfs_attr *na, s64 start_bit, s64 count) { int ret; ntfs_log_enter("Set from bit %lld, count %lld\n", (long long)start_bit, (long long)count); ret = ntfs_bitmap_set_bits_in_run(na, start_bit, count, 1); ntfs_log_leave("\n"); return ret; } /** * ntfs_bitmap_clear_run - clear a run of bits in a bitmap * @na: attribute containing the bitmap * @start_bit: first bit to clear * @count: number of bits to clear * * Clear @count bits starting at bit @start_bit in the bitmap described by the * attribute @na. * * On success return 0 and on error return -1 with errno set to the error code. */ int ntfs_bitmap_clear_run(ntfs_attr *na, s64 start_bit, s64 count) { int ret; ntfs_log_enter("Clear from bit %lld, count %lld\n", (long long)start_bit, (long long)count); ret = ntfs_bitmap_set_bits_in_run(na, start_bit, count, 0); ntfs_log_leave("\n"); return ret; } ntfs-3g-2026.2.25/libntfs-3g/Makefile.am0000664000175000017500000000335215152260173013007 MAINTAINERCLEANFILES = $(srcdir)/Makefile.in if INSTALL_LIBRARY rootlib_LTLIBRARIES=#Create directory lib_LTLIBRARIES = libntfs-3g.la pkgconfig_DATA = libntfs-3g.pc else noinst_LTLIBRARIES = libntfs-3g.la endif libntfs_3g_la_CFLAGS = $(AM_CFLAGS) libntfs_3g_la_CPPFLAGS= $(AM_CPPFLAGS) $(LIBNTFS_CPPFLAGS) -I$(top_srcdir)/include/ntfs-3g libntfs_3g_la_LIBADD = $(LIBNTFS_LIBS) libntfs_3g_la_LDFLAGS = -version-info $(LIBNTFS_3G_VERSION) -no-undefined libntfs_3g_la_SOURCES = \ acls.c \ attrib.c \ attrlist.c \ bitmap.c \ bootsect.c \ cache.c \ collate.c \ compat.c \ compress.c \ debug.c \ device.c \ dir.c \ ea.c \ efs.c \ index.c \ inode.c \ ioctl.c \ lcnalloc.c \ logfile.c \ logging.c \ mft.c \ misc.c \ mst.c \ object_id.c \ realpath.c \ reparse.c \ runlist.c \ security.c \ unistr.c \ volume.c \ xattrs.c if NTFS_DEVICE_DEFAULT_IO_OPS if WINDOWS libntfs_3g_la_SOURCES += win32_io.c else libntfs_3g_la_SOURCES += unix_io.c endif endif # We may need to move .so files to root # And create ldscript or symbolic link from /usr install-exec-hook: install-rootlibLTLIBRARIES if INSTALL_LIBRARY if [ ! "$(rootlibdir)" -ef "$(libdir)" ]; then \ $(MV) -f "$(DESTDIR)/$(libdir)"/libntfs-3g.so* "$(DESTDIR)/$(rootlibdir)"; \ fi if GENERATE_LDSCRIPT if [ ! "$(rootlibdir)" -ef "$(libdir)" ]; then \ $(install_sh_PROGRAM) "libntfs-3g.script.so" "$(DESTDIR)/$(libdir)/libntfs-3g.so"; \ fi else if [ ! "$(rootlibdir)" -ef "$(libdir)" ]; then \ $(LN_S) "$(rootlibdir)/libntfs-3g.so" "$(DESTDIR)/$(libdir)/libntfs-3g.so"; \ fi endif endif uninstall-local: if INSTALL_LIBRARY $(RM) -f "$(DESTDIR)/$(rootlibdir)"/libntfs-3g.so* endif if ENABLE_NTFSPROGS libs: $(lib_LTLIBRARIES) endif ntfs-3g-2026.2.25/libntfs-3g/attrlist.c0000664000175000017500000002144215152260173012765 /** * attrlist.c - Attribute list attribute handling code. Originated from the Linux-NTFS * project. * * Copyright (c) 2004-2005 Anton Altaparmakov * Copyright (c) 2004-2005 Yura Pakhuchiy * Copyright (c) 2006 Szabolcs Szakacsits * * This program/include file 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/include file 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_STRING_H #include #endif #ifdef HAVE_STDLIB_H #include #endif #ifdef HAVE_ERRNO_H #include #endif #include "types.h" #include "layout.h" #include "attrib.h" #include "attrlist.h" #include "debug.h" #include "unistr.h" #include "logging.h" #include "misc.h" /** * ntfs_attrlist_need - check whether inode need attribute list * @ni: opened ntfs inode for which perform check * * Check whether all are attributes belong to one MFT record, in that case * attribute list is not needed. * * Return 1 if inode need attribute list, 0 if not, -1 on error with errno set * to the error code. If function succeed errno set to 0. The following error * codes are defined: * EINVAL - Invalid arguments passed to function or attribute haven't got * attribute list. */ int ntfs_attrlist_need(ntfs_inode *ni) { ATTR_LIST_ENTRY *ale; if (!ni) { ntfs_log_trace("Invalid arguments.\n"); errno = EINVAL; return -1; } ntfs_log_trace("Entering for inode 0x%llx.\n", (long long) ni->mft_no); if (!NInoAttrList(ni)) { ntfs_log_trace("Inode haven't got attribute list.\n"); errno = EINVAL; return -1; } if (!ni->attr_list) { ntfs_log_trace("Corrupt in-memory struct.\n"); errno = EINVAL; return -1; } errno = 0; ale = (ATTR_LIST_ENTRY *)ni->attr_list; while ((u8*)ale < ni->attr_list + ni->attr_list_size) { if (MREF_LE(ale->mft_reference) != ni->mft_no) return 1; ale = (ATTR_LIST_ENTRY *)((u8*)ale + le16_to_cpu(ale->length)); } return 0; } /** * ntfs_attrlist_entry_add - add an attribute list attribute entry * @ni: opened ntfs inode, which contains that attribute * @attr: attribute record to add to attribute list * * Return 0 on success and -1 on error with errno set to the error code. The * following error codes are defined: * EINVAL - Invalid arguments passed to function. * ENOMEM - Not enough memory to allocate necessary buffers. * EIO - I/O error occurred or damaged filesystem. * EEXIST - Such attribute already present in attribute list. */ int ntfs_attrlist_entry_add(ntfs_inode *ni, ATTR_RECORD *attr) { ATTR_LIST_ENTRY *ale; leMFT_REF mref; ntfs_attr *na = NULL; ntfs_attr_search_ctx *ctx; u8 *new_al; int entry_len, entry_offset, err; ntfs_log_trace("Entering for inode 0x%llx, attr 0x%x.\n", (long long) ni->mft_no, (unsigned) le32_to_cpu(attr->type)); if (!ni || !attr) { ntfs_log_trace("Invalid arguments.\n"); errno = EINVAL; return -1; } mref = MK_LE_MREF(ni->mft_no, le16_to_cpu(ni->mrec->sequence_number)); if (ni->nr_extents == -1) ni = ni->base_ni; if (!NInoAttrList(ni)) { ntfs_log_trace("Attribute list isn't present.\n"); errno = ENOENT; return -1; } /* Determine size and allocate memory for new attribute list. */ entry_len = (sizeof(ATTR_LIST_ENTRY) + sizeof(ntfschar) * attr->name_length + 7) & ~7; new_al = ntfs_calloc(ni->attr_list_size + entry_len); if (!new_al) return -1; /* Find place for the new entry. */ ctx = ntfs_attr_get_search_ctx(ni, NULL); if (!ctx) { err = errno; goto err_out; } if (!ntfs_attr_lookup(attr->type, (attr->name_length) ? (ntfschar*) ((u8*)attr + le16_to_cpu(attr->name_offset)) : AT_UNNAMED, attr->name_length, CASE_SENSITIVE, (attr->non_resident) ? sle64_to_cpu(attr->lowest_vcn) : 0, (attr->non_resident) ? NULL : ((u8*)attr + le16_to_cpu(attr->value_offset)), (attr->non_resident) ? 0 : le32_to_cpu(attr->value_length), ctx)) { /* Found some extent, check it to be before new extent. */ if (ctx->al_entry->lowest_vcn == attr->lowest_vcn) { err = EEXIST; ntfs_log_trace("Such attribute already present in the " "attribute list.\n"); ntfs_attr_put_search_ctx(ctx); goto err_out; } /* Add new entry after this extent. */ ale = (ATTR_LIST_ENTRY*)((u8*)ctx->al_entry + le16_to_cpu(ctx->al_entry->length)); } else { /* Check for real errors. */ if (errno != ENOENT) { err = errno; ntfs_log_trace("Attribute lookup failed.\n"); ntfs_attr_put_search_ctx(ctx); goto err_out; } /* No previous extents found. */ ale = ctx->al_entry; } /* Don't need it anymore, @ctx->al_entry points to @ni->attr_list. */ ntfs_attr_put_search_ctx(ctx); /* Determine new entry offset. */ entry_offset = ((u8 *)ale - ni->attr_list); /* Set pointer to new entry. */ ale = (ATTR_LIST_ENTRY *)(new_al + entry_offset); /* Zero it to fix valgrind warning. */ memset(ale, 0, entry_len); /* Form new entry. */ ale->type = attr->type; ale->length = cpu_to_le16(entry_len); ale->name_length = attr->name_length; ale->name_offset = offsetof(ATTR_LIST_ENTRY, name); if (attr->non_resident) ale->lowest_vcn = attr->lowest_vcn; else ale->lowest_vcn = const_cpu_to_sle64(0); ale->mft_reference = mref; ale->instance = attr->instance; memcpy(ale->name, (u8 *)attr + le16_to_cpu(attr->name_offset), attr->name_length * sizeof(ntfschar)); /* Resize $ATTRIBUTE_LIST to new length. */ na = ntfs_attr_open(ni, AT_ATTRIBUTE_LIST, AT_UNNAMED, 0); if (!na) { err = errno; ntfs_log_trace("Failed to open $ATTRIBUTE_LIST attribute.\n"); goto err_out; } if (ntfs_attr_truncate(na, ni->attr_list_size + entry_len)) { err = errno; ntfs_log_trace("$ATTRIBUTE_LIST resize failed.\n"); goto err_out; } /* Copy entries from old attribute list to new. */ memcpy(new_al, ni->attr_list, entry_offset); memcpy(new_al + entry_offset + entry_len, ni->attr_list + entry_offset, ni->attr_list_size - entry_offset); /* Set new runlist. */ free(ni->attr_list); ni->attr_list = new_al; ni->attr_list_size = ni->attr_list_size + entry_len; NInoAttrListSetDirty(ni); /* Done! */ ntfs_attr_close(na); return 0; err_out: if (na) ntfs_attr_close(na); free(new_al); errno = err; return -1; } /** * ntfs_attrlist_entry_rm - remove an attribute list attribute entry * @ctx: attribute search context describing the attribute list entry * * Remove the attribute list entry @ctx->al_entry from the attribute list. * * Return 0 on success and -1 on error with errno set to the error code. */ int ntfs_attrlist_entry_rm(ntfs_attr_search_ctx *ctx) { u8 *new_al; int new_al_len; ntfs_inode *base_ni; ntfs_attr *na; ATTR_LIST_ENTRY *ale; int err; if (!ctx || !ctx->ntfs_ino || !ctx->al_entry) { ntfs_log_trace("Invalid arguments.\n"); errno = EINVAL; return -1; } if (ctx->base_ntfs_ino) base_ni = ctx->base_ntfs_ino; else base_ni = ctx->ntfs_ino; ale = ctx->al_entry; ntfs_log_trace("Entering for inode 0x%llx, attr 0x%x, lowest_vcn %lld.\n", (long long) ctx->ntfs_ino->mft_no, (unsigned) le32_to_cpu(ctx->al_entry->type), (long long) sle64_to_cpu(ctx->al_entry->lowest_vcn)); if (!NInoAttrList(base_ni)) { ntfs_log_trace("Attribute list isn't present.\n"); errno = ENOENT; return -1; } /* Allocate memory for new attribute list. */ new_al_len = base_ni->attr_list_size - le16_to_cpu(ale->length); new_al = ntfs_calloc(new_al_len); if (!new_al) return -1; /* Reisze $ATTRIBUTE_LIST to new length. */ na = ntfs_attr_open(base_ni, AT_ATTRIBUTE_LIST, AT_UNNAMED, 0); if (!na) { err = errno; ntfs_log_trace("Failed to open $ATTRIBUTE_LIST attribute.\n"); goto err_out; } if (ntfs_attr_truncate(na, new_al_len)) { err = errno; ntfs_log_trace("$ATTRIBUTE_LIST resize failed.\n"); goto err_out; } /* Copy entries from old attribute list to new. */ memcpy(new_al, base_ni->attr_list, (u8*)ale - base_ni->attr_list); memcpy(new_al + ((u8*)ale - base_ni->attr_list), (u8*)ale + le16_to_cpu( ale->length), new_al_len - ((u8*)ale - base_ni->attr_list)); /* Set new runlist. */ free(base_ni->attr_list); base_ni->attr_list = new_al; base_ni->attr_list_size = new_al_len; NInoAttrListSetDirty(base_ni); /* Done! */ ntfs_attr_close(na); return 0; err_out: if (na) ntfs_attr_close(na); free(new_al); errno = err; return -1; } ntfs-3g-2026.2.25/libntfs-3g/debug.c0000664000175000017500000000432515152260173012206 /** * debug.c - Debugging output functions. Originated from the Linux-NTFS project. * * Copyright (c) 2002-2004 Anton Altaparmakov * Copyright (c) 2004-2006 Szabolcs Szakacsits * * This program/include file 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/include file 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_ERRNO_H #include #endif #include "types.h" #include "runlist.h" #include "debug.h" #include "logging.h" #ifdef DEBUG /** * ntfs_debug_runlist_dump - Dump a runlist. * @rl: * * Description... * * Returns: */ void ntfs_debug_runlist_dump(const runlist_element *rl) { int i = 0; const char *lcn_str[5] = { "LCN_HOLE ", "LCN_RL_NOT_MAPPED", "LCN_ENOENT ", "LCN_EINVAL ", "LCN_unknown " }; ntfs_log_debug("NTFS-fs DEBUG: Dumping runlist (values in hex):\n"); if (!rl) { ntfs_log_debug("Run list not present.\n"); return; } ntfs_log_debug("VCN LCN Run length\n"); do { LCN lcn = (rl + i)->lcn; if (lcn < (LCN)0) { int idx = -lcn - 1; if (idx > -LCN_EINVAL - 1) idx = 4; ntfs_log_debug("%-16lld %s %-16lld%s\n", (long long)rl[i].vcn, lcn_str[idx], (long long)rl[i].length, rl[i].length ? "" : " (runlist end)"); } else ntfs_log_debug("%-16lld %-16lld %-16lld%s\n", (long long)rl[i].vcn, (long long)rl[i].lcn, (long long)rl[i].length, rl[i].length ? "" : " (runlist end)"); } while (rl[i++].length); } #endif ntfs-3g-2026.2.25/libntfs-3g/reparse.c0000664000175000017500000011034415152260173012560 /** * reparse.c - Processing of reparse points * * This module is part of ntfs-3g library * * Copyright (c) 2008-2021 Jean-Pierre Andre * * This program/include file 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/include file 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_STDLIB_H #include #endif #ifdef HAVE_ERRNO_H #include #endif #ifdef HAVE_STRING_H #include #endif #ifdef HAVE_SYS_STAT_H #include #endif #ifdef MAJOR_IN_MKDEV #include #endif #ifdef MAJOR_IN_SYSMACROS #include #endif #include "compat.h" #include "types.h" #include "debug.h" #include "layout.h" #include "attrib.h" #include "inode.h" #include "dir.h" #include "volume.h" #include "mft.h" #include "index.h" #include "lcnalloc.h" #include "logging.h" #include "misc.h" #include "reparse.h" #include "xattrs.h" #include "ea.h" struct MOUNT_POINT_REPARSE_DATA { /* reparse data for junctions */ le16 subst_name_offset; le16 subst_name_length; le16 print_name_offset; le16 print_name_length; char path_buffer[0]; /* above data assume this is char array */ } ; struct SYMLINK_REPARSE_DATA { /* reparse data for symlinks */ le16 subst_name_offset; le16 subst_name_length; le16 print_name_offset; le16 print_name_length; le32 flags; /* 1 for full target, otherwise 0 */ char path_buffer[0]; /* above data assume this is char array */ } ; struct WSL_LINK_REPARSE_DATA { le32 type; char link[0]; } ; struct REPARSE_INDEX { /* index entry in $Extend/$Reparse */ INDEX_ENTRY_HEADER header; REPARSE_INDEX_KEY key; le32 filling; } ; static const ntfschar dir_junction_head[] = { const_cpu_to_le16('\\'), const_cpu_to_le16('?'), const_cpu_to_le16('?'), const_cpu_to_le16('\\') } ; static const ntfschar vol_junction_head[] = { const_cpu_to_le16('\\'), const_cpu_to_le16('?'), const_cpu_to_le16('?'), const_cpu_to_le16('\\'), const_cpu_to_le16('V'), const_cpu_to_le16('o'), const_cpu_to_le16('l'), const_cpu_to_le16('u'), const_cpu_to_le16('m'), const_cpu_to_le16('e'), const_cpu_to_le16('{'), } ; static ntfschar reparse_index_name[] = { const_cpu_to_le16('$'), const_cpu_to_le16('R') }; static const char mappingdir[] = ".NTFS-3G/"; /* * Fix a file name with doubtful case in some directory index * and return the name with the casing used in directory. * * Should only be used to translate paths stored with case insensitivity * (such as directory junctions) when no case conflict is expected. * If there some ambiguity, the name which collates first is returned. * * The name is converted to upper case and searched the usual way. * The collation rules for file names are such that we should get the * first candidate if any. */ static u64 ntfs_fix_file_name(ntfs_inode *dir_ni, ntfschar *uname, int uname_len) { ntfs_volume *vol = dir_ni->vol; ntfs_index_context *icx; u64 mref; le64 lemref; int lkup; int olderrno; int i; u32 cpuchar; INDEX_ENTRY *entry; FILE_NAME_ATTR *found; struct { FILE_NAME_ATTR attr; ntfschar file_name[NTFS_MAX_NAME_LEN + 1]; } find; mref = (u64)-1; /* default return (not found) */ icx = ntfs_index_ctx_get(dir_ni, NTFS_INDEX_I30, 4); if (icx) { if (uname_len > NTFS_MAX_NAME_LEN) uname_len = NTFS_MAX_NAME_LEN; find.attr.file_name_length = uname_len; for (i=0; iupcase_len) && (le16_to_cpu(vol->upcase[cpuchar]) < cpuchar)) find.attr.file_name[i] = vol->upcase[cpuchar]; else find.attr.file_name[i] = uname[i]; } olderrno = errno; lkup = ntfs_index_lookup((char*)&find, uname_len, icx); if (errno == ENOENT) errno = olderrno; /* * We generally only get the first matching candidate, * so we still have to check whether this is a real match */ if (icx->entry && (icx->entry->ie_flags & INDEX_ENTRY_END)) /* get next entry if reaching end of block */ entry = ntfs_index_next(icx->entry, icx); else entry = icx->entry; if (entry) { found = &entry->key.file_name; if (lkup && ntfs_names_are_equal(find.attr.file_name, find.attr.file_name_length, found->file_name, found->file_name_length, IGNORE_CASE, vol->upcase, vol->upcase_len)) lkup = 0; if (!lkup) { /* * name found : * fix original name and return inode */ lemref = entry->indexed_file; mref = le64_to_cpu(lemref); if (NVolCaseSensitive(vol) || !vol->locase) { for (i=0; ifile_name_length; i++) uname[i] = found->file_name[i]; } else { for (i=0; ifile_name_length; i++) uname[i] = vol->locase[le16_to_cpu(found->file_name[i])]; } } } ntfs_index_ctx_put(icx); } return (mref); } /* * Search for a directory junction or a symbolic link * along the target path, with target defined as a full absolute path * * Returns the path translated to a Linux path * or NULL if the path is not valid */ static char *search_absolute(ntfs_volume *vol, ntfschar *path, int count, BOOL isdir) { ntfs_inode *ni; u64 inum; char *target; int start; int len; target = (char*)NULL; /* default return */ ni = ntfs_inode_open(vol, (MFT_REF)FILE_root); if (ni) { start = 0; /* * Examine and translate the path, until we reach either * - the end, * - an unknown item * - a non-directory * - another reparse point, * A reparse point is not dereferenced, it will be * examined later when the translated path is dereferenced, * however the final part of the path will not be adjusted * to correct case. */ do { len = 0; while (((start + len) < count) && (path[start + len] != const_cpu_to_le16('\\'))) len++; inum = ntfs_fix_file_name(ni, &path[start], len); ntfs_inode_close(ni); ni = (ntfs_inode*)NULL; if (inum != (u64)-1) { inum = MREF(inum); ni = ntfs_inode_open(vol, inum); start += len; if (start < count) path[start++] = const_cpu_to_le16('/'); } } while (ni && (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) && !(ni->flags & FILE_ATTR_REPARSE_POINT) && (start < count)); if (ni && ((ni->mrec->flags & MFT_RECORD_IS_DIRECTORY ? isdir : !isdir) || (ni->flags & FILE_ATTR_REPARSE_POINT))) if (ntfs_ucstombs(path, count, &target, 0) < 0) { if (target) { free(target); target = (char*)NULL; } } if (ni) ntfs_inode_close(ni); } return (target); } /* * Search for a symbolic link along the target path, * with the target defined as a relative path * * Note : the path used to access the current inode, may be * different from the one implied in the target definition, * when an inode has names in several directories. * * Returns the path translated to a Linux path * or NULL if the path is not valid */ static char *search_relative(ntfs_inode *ni, ntfschar *path, int count) { char *target = (char*)NULL; ntfs_inode *curni; ntfs_inode *newni; u64 inum; int pos; int lth; BOOL ok; BOOL morelinks; int max = 32; /* safety */ pos = 0; ok = TRUE; morelinks = FALSE; curni = ntfs_dir_parent_inode(ni); /* * Examine and translate the path, until we reach either * - the end, * - an unknown item * - a non-directory * - another reparse point, * A reparse point is not dereferenced, it will be * examined later when the translated path is dereferenced, * however the final part of the path will not be adjusted * to correct case. */ while (curni && ok && !morelinks && (pos < (count - 1)) && --max) { if ((count >= (pos + 2)) && (path[pos] == const_cpu_to_le16('.')) && (path[pos+1] == const_cpu_to_le16('\\'))) { path[pos+1] = const_cpu_to_le16('/'); pos += 2; } else { if ((count >= (pos + 3)) && (path[pos] == const_cpu_to_le16('.')) &&(path[pos+1] == const_cpu_to_le16('.')) && (path[pos+2] == const_cpu_to_le16('\\'))) { path[pos+2] = const_cpu_to_le16('/'); pos += 3; newni = ntfs_dir_parent_inode(curni); if (curni != ni) ntfs_inode_close(curni); curni = newni; if (!curni) ok = FALSE; } else { lth = 0; while (((pos + lth) < count) && (path[pos + lth] != const_cpu_to_le16('\\'))) lth++; if (lth > 0) inum = ntfs_fix_file_name(curni,&path[pos],lth); else inum = (u64)-1; if (!lth || ((curni != ni) && ntfs_inode_close(curni)) || (inum == (u64)-1)) ok = FALSE; else { curni = ntfs_inode_open(ni->vol, MREF(inum)); if (!curni) ok = FALSE; else { if (curni->flags & FILE_ATTR_REPARSE_POINT) morelinks = TRUE; if (ok && ((pos + lth) < count)) { path[pos + lth] = const_cpu_to_le16('/'); pos += lth + 1; if (morelinks && ntfs_inode_close(curni)) ok = FALSE; } else { pos += lth; if (!morelinks && (ni->mrec->flags ^ curni->mrec->flags) & MFT_RECORD_IS_DIRECTORY) ok = FALSE; if (ntfs_inode_close(curni)) ok = FALSE; } } } } } } if (ok && (ntfs_ucstombs(path, count, &target, 0) < 0)) { free(target); // needed ? target = (char*)NULL; } return (target); } /* * Check whether a drive letter has been defined in .NTFS-3G * * Returns 1 if found, * 0 if not found, * -1 if there was an error (described by errno) */ static int ntfs_drive_letter(ntfs_volume *vol, ntfschar letter) { char defines[NTFS_MAX_NAME_LEN + 5]; char *drive; int ret; int sz; int olderrno; ntfs_inode *ni; ret = -1; drive = (char*)NULL; sz = ntfs_ucstombs(&letter, 1, &drive, 0); if (sz > 0) { strcpy(defines,mappingdir); if ((*drive >= 'a') && (*drive <= 'z')) *drive += 'A' - 'a'; strcat(defines,drive); strcat(defines,":"); olderrno = errno; ni = ntfs_pathname_to_inode(vol, NULL, defines); if (ni && !ntfs_inode_close(ni)) ret = 1; else if (errno == ENOENT) { ret = 0; /* avoid errno pollution */ errno = olderrno; } } if (drive) free(drive); return (ret); } /* * Check whether reparse data describes a valid wsl special file * which is either a socket, a fifo, or a character or block device * * Return zero if valid, otherwise returns a negative error code */ int ntfs_reparse_check_wsl(ntfs_inode *ni, const REPARSE_POINT *reparse) { int res; res = -EOPNOTSUPP; switch (reparse->reparse_tag) { case IO_REPARSE_TAG_AF_UNIX : case IO_REPARSE_TAG_LX_FIFO : case IO_REPARSE_TAG_LX_CHR : case IO_REPARSE_TAG_LX_BLK : if (!reparse->reparse_data_length && (ni->flags & FILE_ATTRIBUTE_RECALL_ON_OPEN)) res = 0; break; default : break; } if (res) errno = EOPNOTSUPP; return (res); } /* * Do some sanity checks on reparse data * * Microsoft reparse points have an 8-byte header whereas * non-Microsoft reparse points have a 24-byte header. In each case, * 'reparse_data_length' must equal the number of non-header bytes. * * If the reparse data looks like a junction point or symbolic * link, more checks can be done. * */ static BOOL valid_reparse_data(ntfs_inode *ni, const REPARSE_POINT *reparse_attr, size_t size) { BOOL ok; unsigned int offs; unsigned int lth; const struct MOUNT_POINT_REPARSE_DATA *mount_point_data; const struct SYMLINK_REPARSE_DATA *symlink_data; const struct WSL_LINK_REPARSE_DATA *wsl_reparse_data; ok = ni && reparse_attr && (size >= sizeof(REPARSE_POINT)) && (reparse_attr->reparse_tag != IO_REPARSE_TAG_RESERVED_ZERO) && (((size_t)le16_to_cpu(reparse_attr->reparse_data_length) + sizeof(REPARSE_POINT) + ((reparse_attr->reparse_tag & IO_REPARSE_TAG_IS_MICROSOFT) ? 0 : sizeof(GUID))) == size); if (ok) { switch (reparse_attr->reparse_tag) { case IO_REPARSE_TAG_MOUNT_POINT : if (size < sizeof(REPARSE_POINT) + sizeof(struct MOUNT_POINT_REPARSE_DATA)) { ok = FALSE; break; } mount_point_data = (const struct MOUNT_POINT_REPARSE_DATA*) reparse_attr->reparse_data; offs = le16_to_cpu(mount_point_data->subst_name_offset); lth = le16_to_cpu(mount_point_data->subst_name_length); /* consistency checks */ if (!(ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) || ((size_t)((sizeof(REPARSE_POINT) + sizeof(struct MOUNT_POINT_REPARSE_DATA) + offs + lth)) > size)) ok = FALSE; break; case IO_REPARSE_TAG_SYMLINK : if (size < sizeof(REPARSE_POINT) + sizeof(struct SYMLINK_REPARSE_DATA)) { ok = FALSE; break; } symlink_data = (const struct SYMLINK_REPARSE_DATA*) reparse_attr->reparse_data; offs = le16_to_cpu(symlink_data->subst_name_offset); lth = le16_to_cpu(symlink_data->subst_name_length); if ((size_t)((sizeof(REPARSE_POINT) + sizeof(struct SYMLINK_REPARSE_DATA) + offs + lth)) > size) ok = FALSE; break; case IO_REPARSE_TAG_LX_SYMLINK : wsl_reparse_data = (const struct WSL_LINK_REPARSE_DATA*) reparse_attr->reparse_data; if ((le16_to_cpu(reparse_attr->reparse_data_length) <= sizeof(wsl_reparse_data->type)) || (wsl_reparse_data->type != const_cpu_to_le32(2))) ok = FALSE; break; case IO_REPARSE_TAG_AF_UNIX : case IO_REPARSE_TAG_LX_FIFO : case IO_REPARSE_TAG_LX_CHR : case IO_REPARSE_TAG_LX_BLK : if (reparse_attr->reparse_data_length || !(ni->flags & FILE_ATTRIBUTE_RECALL_ON_OPEN)) ok = FALSE; break; default : break; } } if (!ok) errno = EINVAL; return (ok); } /* * Check and translate the target of a junction point or * a full absolute symbolic link. * * A full target definition begins with "\??\" or "\\?\" * * The fully defined target is redefined as a relative link, * - either to the target if found on the same device. * - or into the /.NTFS-3G directory for the user to define * In the first situation, the target is translated to case-sensitive path. * * returns the target converted to a relative symlink * or NULL if there were some problem, as described by errno */ static char *ntfs_get_fulllink(ntfs_volume *vol, ntfschar *junction, int count, const char *mnt_point, BOOL isdir) { char *target; char *fulltarget; int sz; char *q; enum { DIR_JUNCTION, VOL_JUNCTION, NO_JUNCTION } kind; target = (char*)NULL; fulltarget = (char*)NULL; /* * For a valid directory junction we want \??\x:\ * where \ is an individual char and x a non-null char */ if ((count >= 7) && !memcmp(junction,dir_junction_head,8) && junction[4] && (junction[5] == const_cpu_to_le16(':')) && (junction[6] == const_cpu_to_le16('\\'))) kind = DIR_JUNCTION; else /* * For a valid volume junction we want \\?\Volume{ * and a final \ (where \ is an individual char) */ if ((count >= 12) && !memcmp(junction,vol_junction_head,22) && (junction[count-1] == const_cpu_to_le16('\\'))) kind = VOL_JUNCTION; else kind = NO_JUNCTION; /* * Directory junction with an explicit path and * no specific definition for the drive letter : * try to interpret as a target on the same volume */ if ((kind == DIR_JUNCTION) && (count >= 7) && junction[7] && !ntfs_drive_letter(vol, junction[4])) { target = search_absolute(vol,&junction[7],count - 7, isdir); if (target) { fulltarget = (char*)ntfs_malloc(strlen(mnt_point) + strlen(target) + 2); if (fulltarget) { strcpy(fulltarget,mnt_point); strcat(fulltarget,"/"); strcat(fulltarget,target); } free(target); } } /* * Volume junctions or directory junctions with * target not found on current volume : * link to /.NTFS-3G/target which the user can * define as a symbolic link to the real target */ if (((kind == DIR_JUNCTION) && !fulltarget) || (kind == VOL_JUNCTION)) { sz = ntfs_ucstombs(&junction[4], (kind == VOL_JUNCTION ? count - 5 : count - 4), &target, 0); if ((sz > 0) && target) { /* reverse slashes */ for (q=target; *q; q++) if (*q == '\\') *q = '/'; /* force uppercase drive letter */ if ((target[1] == ':') && (target[0] >= 'a') && (target[0] <= 'z')) target[0] += 'A' - 'a'; fulltarget = (char*)ntfs_malloc(strlen(mnt_point) + sizeof(mappingdir) + strlen(target) + 1); if (fulltarget) { strcpy(fulltarget,mnt_point); strcat(fulltarget,"/"); strcat(fulltarget,mappingdir); strcat(fulltarget,target); } } if (target) free(target); } return (fulltarget); } /* * Check and translate the target of an absolute symbolic link. * * An absolute target definition begins with "\" or "x:\" * * The absolute target is redefined as a relative link, * - either to the target if found on the same device. * - or into the /.NTFS-3G directory for the user to define * In the first situation, the target is translated to case-sensitive path. * * returns the target converted to a relative symlink * or NULL if there were some problem, as described by errno */ char *ntfs_get_abslink(ntfs_volume *vol, ntfschar *junction, int count, const char *mnt_point __attribute__((unused)), BOOL isdir) { char *target; char *fulltarget; int sz; char *q; enum { FULL_PATH, ABS_PATH, REJECTED_PATH } kind; target = (char*)NULL; fulltarget = (char*)NULL; /* * For a full valid path we want x:\ * where \ is an individual char and x a non-null char */ if ((count >= 3) && junction[0] && (junction[1] == const_cpu_to_le16(':')) && (junction[2] == const_cpu_to_le16('\\'))) kind = FULL_PATH; else /* * For an absolute path we want an initial \ */ if ((count >= 0) && (junction[0] == const_cpu_to_le16('\\'))) kind = ABS_PATH; else kind = REJECTED_PATH; /* * Full path, with a drive letter and * no specific definition for the drive letter : * try to interpret as a target on the same volume. * Do the same for an abs path with no drive letter. */ if (((kind == FULL_PATH) && (count >= 3) && junction[3] && !ntfs_drive_letter(vol, junction[0])) || (kind == ABS_PATH)) { if (kind == ABS_PATH) target = search_absolute(vol, &junction[1], count - 1, isdir); else target = search_absolute(vol, &junction[3], count - 3, isdir); if (target) { fulltarget = (char*)ntfs_malloc( strlen(vol->abs_mnt_point) + strlen(target) + 2); if (fulltarget) { strcpy(fulltarget,vol->abs_mnt_point); strcat(fulltarget,"/"); strcat(fulltarget,target); } free(target); } } /* * full path with target not found on current volume : * link to /.NTFS-3G/target which the user can * define as a symbolic link to the real target */ if ((kind == FULL_PATH) && !fulltarget) { sz = ntfs_ucstombs(&junction[0], count,&target, 0); if ((sz > 0) && target) { /* reverse slashes */ for (q=target; *q; q++) if (*q == '\\') *q = '/'; /* force uppercase drive letter */ if ((target[1] == ':') && (target[0] >= 'a') && (target[0] <= 'z')) target[0] += 'A' - 'a'; fulltarget = (char*)ntfs_malloc( strlen(vol->abs_mnt_point) + sizeof(mappingdir) + strlen(target) + 1); if (fulltarget) { strcpy(fulltarget,vol->abs_mnt_point); strcat(fulltarget,"/"); strcat(fulltarget,mappingdir); strcat(fulltarget,target); } } if (target) free(target); } return (fulltarget); } /* * Check and translate the target of a relative symbolic link. * * A relative target definition does not begin with "\" * * The original definition of relative target is kept, it is just * translated to a case-sensitive path. * * returns the target converted to a relative symlink * or NULL if there were some problem, as described by errno */ static char *ntfs_get_rellink(ntfs_inode *ni, ntfschar *junction, int count) { char *target; target = search_relative(ni,junction,count); return (target); } /* * Get the target for a junction point or symbolic link * Should only be called for files or directories with reparse data * * returns the target converted to a relative path, or NULL * if some error occurred, as described by errno * errno is EOPNOTSUPP if the reparse point is not a valid * symbolic link or directory junction */ char *ntfs_make_symlink(ntfs_inode *ni, const char *mnt_point) { s64 attr_size = 0; char *target; unsigned int offs; unsigned int lth; ntfs_volume *vol; REPARSE_POINT *reparse_attr; struct MOUNT_POINT_REPARSE_DATA *mount_point_data; struct SYMLINK_REPARSE_DATA *symlink_data; struct WSL_LINK_REPARSE_DATA *wsl_link_data; enum { FULL_TARGET, ABS_TARGET, REL_TARGET } kind; ntfschar *p; BOOL bad; BOOL isdir; target = (char*)NULL; bad = TRUE; isdir = (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) != const_cpu_to_le16(0); vol = ni->vol; reparse_attr = (REPARSE_POINT*)ntfs_attr_readall(ni, AT_REPARSE_POINT,(ntfschar*)NULL, 0, &attr_size); if (reparse_attr && attr_size && valid_reparse_data(ni, reparse_attr, attr_size)) { switch (reparse_attr->reparse_tag) { case IO_REPARSE_TAG_MOUNT_POINT : mount_point_data = (struct MOUNT_POINT_REPARSE_DATA*) reparse_attr->reparse_data; offs = le16_to_cpu(mount_point_data->subst_name_offset); lth = le16_to_cpu(mount_point_data->subst_name_length); /* reparse data consistency has been checked */ target = ntfs_get_fulllink(vol, (ntfschar*)&mount_point_data->path_buffer[offs], lth/2, mnt_point, isdir); if (target) bad = FALSE; break; case IO_REPARSE_TAG_SYMLINK : symlink_data = (struct SYMLINK_REPARSE_DATA*) reparse_attr->reparse_data; offs = le16_to_cpu(symlink_data->subst_name_offset); lth = le16_to_cpu(symlink_data->subst_name_length); p = (ntfschar*)&symlink_data->path_buffer[offs]; /* * Predetermine the kind of target, * the called function has to make a full check */ if (*p++ == const_cpu_to_le16('\\')) { if ((*p == const_cpu_to_le16('?')) || (*p == const_cpu_to_le16('\\'))) kind = FULL_TARGET; else kind = ABS_TARGET; } else if (*p == const_cpu_to_le16(':')) kind = ABS_TARGET; else kind = REL_TARGET; p--; /* reparse data consistency has been checked */ switch (kind) { case FULL_TARGET : if (!(symlink_data->flags & const_cpu_to_le32(1))) { target = ntfs_get_fulllink(vol, p, lth/2, mnt_point, isdir); if (target) bad = FALSE; } break; case ABS_TARGET : if (symlink_data->flags & const_cpu_to_le32(1)) { target = ntfs_get_abslink(vol, p, lth/2, mnt_point, isdir); if (target) bad = FALSE; } break; case REL_TARGET : if (symlink_data->flags & const_cpu_to_le32(1)) { target = ntfs_get_rellink(ni, p, lth/2); if (target) bad = FALSE; } break; } break; case IO_REPARSE_TAG_LX_SYMLINK : wsl_link_data = (struct WSL_LINK_REPARSE_DATA*) reparse_attr->reparse_data; if (wsl_link_data->type == const_cpu_to_le32(2)) { lth = le16_to_cpu( reparse_attr->reparse_data_length) - sizeof(wsl_link_data->type); target = (char*)ntfs_malloc(lth + 1); if (target) { memcpy(target, wsl_link_data->link, lth); target[lth] = 0; bad = FALSE; } } break; } free(reparse_attr); } if (bad) errno = EOPNOTSUPP; return (target); } /* * Check whether a reparse point looks like a junction point * or a symbolic link. * Should only be called for files or directories with reparse data * * The validity of the target is not checked. */ BOOL ntfs_possible_symlink(ntfs_inode *ni) { s64 attr_size = 0; REPARSE_POINT *reparse_attr; BOOL possible; possible = FALSE; reparse_attr = (REPARSE_POINT*)ntfs_attr_readall(ni, AT_REPARSE_POINT,(ntfschar*)NULL, 0, &attr_size); if (reparse_attr && attr_size) { switch (reparse_attr->reparse_tag) { case IO_REPARSE_TAG_MOUNT_POINT : case IO_REPARSE_TAG_SYMLINK : case IO_REPARSE_TAG_LX_SYMLINK : possible = TRUE; default : ; } free(reparse_attr); } return (possible); } /* * Set the index for new reparse data * * Returns 0 if success * -1 if failure, explained by errno */ static int set_reparse_index(ntfs_inode *ni, ntfs_index_context *xr, le32 reparse_tag) { struct REPARSE_INDEX indx; u64 file_id_cpu; le64 file_id; le16 seqn; seqn = ni->mrec->sequence_number; file_id_cpu = MK_MREF(ni->mft_no,le16_to_cpu(seqn)); file_id = cpu_to_le64(file_id_cpu); indx.header.data_offset = const_cpu_to_le16( sizeof(INDEX_ENTRY_HEADER) + sizeof(REPARSE_INDEX_KEY)); indx.header.data_length = const_cpu_to_le16(0); indx.header.reservedV = const_cpu_to_le32(0); indx.header.length = const_cpu_to_le16( sizeof(struct REPARSE_INDEX)); indx.header.key_length = const_cpu_to_le16( sizeof(REPARSE_INDEX_KEY)); indx.header.flags = const_cpu_to_le16(0); indx.header.reserved = const_cpu_to_le16(0); indx.key.reparse_tag = reparse_tag; /* danger on processors which require proper alignment ! */ memcpy(&indx.key.file_id, &file_id, 8); indx.filling = const_cpu_to_le32(0); ntfs_index_ctx_reinit(xr); return (ntfs_ie_add(xr,(INDEX_ENTRY*)&indx)); } /* * Remove a reparse data index entry if attribute present * * Returns the size of existing reparse data * (the existing reparse tag is returned) * -1 if failure, explained by errno */ static int remove_reparse_index(ntfs_attr *na, ntfs_index_context *xr, le32 *preparse_tag) { REPARSE_INDEX_KEY key; u64 file_id_cpu; le64 file_id; s64 size; le16 seqn; int ret; ret = na->data_size; if (ret) { /* read the existing reparse_tag */ size = ntfs_attr_pread(na, 0, 4, preparse_tag); if (size == 4) { seqn = na->ni->mrec->sequence_number; file_id_cpu = MK_MREF(na->ni->mft_no,le16_to_cpu(seqn)); file_id = cpu_to_le64(file_id_cpu); key.reparse_tag = *preparse_tag; /* danger on processors which require proper alignment ! */ memcpy(&key.file_id, &file_id, 8); if (!ntfs_index_lookup(&key, sizeof(REPARSE_INDEX_KEY), xr) && ntfs_index_rm(xr)) ret = -1; } else { ret = -1; errno = ENODATA; } } return (ret); } /* * Open the $Extend/$Reparse file and its index * * Return the index context if opened * or NULL if an error occurred (errno tells why) * * The index has to be freed and inode closed when not needed any more. */ static ntfs_index_context *open_reparse_index(ntfs_volume *vol) { u64 inum; ntfs_inode *ni; ntfs_inode *dir_ni; ntfs_index_context *xr; /* do not use path_name_to inode - could reopen root */ dir_ni = ntfs_inode_open(vol, FILE_Extend); ni = (ntfs_inode*)NULL; if (dir_ni) { inum = ntfs_inode_lookup_by_mbsname(dir_ni,"$Reparse"); if (inum != (u64)-1) ni = ntfs_inode_open(vol, inum); ntfs_inode_close(dir_ni); } if (ni) { xr = ntfs_index_ctx_get(ni, reparse_index_name, 2); if (!xr) { ntfs_inode_close(ni); } } else xr = (ntfs_index_context*)NULL; return (xr); } /* * Update the reparse data and index * * The reparse data attribute should have been created, and * an existing index is expected if there is an existing value. * * Returns 0 if success * -1 if failure, explained by errno * If could not remove the existing index, nothing is done, * If could not write the new data, no index entry is inserted * If failed to insert the index, data is removed */ static int update_reparse_data(ntfs_inode *ni, ntfs_index_context *xr, const char *value, size_t size) { int res; int written; int oldsize; ntfs_attr *na; le32 reparse_tag; res = 0; na = ntfs_attr_open(ni, AT_REPARSE_POINT, AT_UNNAMED, 0); if (na) { /* remove the existing reparse data */ oldsize = remove_reparse_index(na,xr,&reparse_tag); if (oldsize < 0) res = -1; else { /* resize attribute */ res = ntfs_attr_truncate(na, (s64)size); /* overwrite value if any */ if (!res && value) { written = (int)ntfs_attr_pwrite(na, (s64)0, (s64)size, value); if (written != (s64)size) { ntfs_log_error("Failed to update " "reparse data\n"); errno = EIO; res = -1; } } if (!res && set_reparse_index(ni,xr, ((const REPARSE_POINT*)value)->reparse_tag) && (oldsize > 0)) { /* * If cannot index, try to remove the reparse * data and log the error. There will be an * inconsistency if removal fails. */ ntfs_attr_rm(na); ntfs_log_error("Failed to index reparse data." " Possible corruption.\n"); } } ntfs_attr_close(na); NInoSetDirty(ni); } else res = -1; return (res); } /* * Delete a reparse index entry * * Returns 0 if success * -1 if failure, explained by errno */ int ntfs_delete_reparse_index(ntfs_inode *ni) { ntfs_index_context *xr; ntfs_inode *xrni; ntfs_attr *na; le32 reparse_tag; int res; res = 0; na = ntfs_attr_open(ni, AT_REPARSE_POINT, AT_UNNAMED, 0); if (na) { /* * read the existing reparse data (the tag is enough) * and un-index it */ xr = open_reparse_index(ni->vol); if (xr) { if (remove_reparse_index(na,xr,&reparse_tag) < 0) res = -1; xrni = xr->ni; ntfs_index_entry_mark_dirty(xr); NInoSetDirty(xrni); ntfs_index_ctx_put(xr); ntfs_inode_close(xrni); } ntfs_attr_close(na); } return (res); } /* * Get the ntfs reparse data into an extended attribute * * Returns the reparse data size * and the buffer is updated if it is long enough */ int ntfs_get_ntfs_reparse_data(ntfs_inode *ni, char *value, size_t size) { REPARSE_POINT *reparse_attr; s64 attr_size; attr_size = 0; /* default to no data and no error */ if (ni) { if (ni->flags & FILE_ATTR_REPARSE_POINT) { reparse_attr = (REPARSE_POINT*)ntfs_attr_readall(ni, AT_REPARSE_POINT,(ntfschar*)NULL, 0, &attr_size); if (reparse_attr) { if (attr_size <= (s64)size) { if (value) memcpy(value,reparse_attr, attr_size); else errno = EINVAL; } free(reparse_attr); } } else errno = ENODATA; } return (attr_size ? (int)attr_size : -errno); } /* * Set the reparse data from an extended attribute * * Warning : the new data is not checked * * Returns 0, or -1 if there is a problem */ int ntfs_set_ntfs_reparse_data(ntfs_inode *ni, const char *value, size_t size, int flags) { int res; u8 dummy; ntfs_inode *xrni; ntfs_index_context *xr; res = 0; /* * reparse data compatibily with EA is not checked * any more, it is required by Windows 10, but may * lead to problems with earlier versions. */ if (ni && valid_reparse_data(ni, (const REPARSE_POINT*)value, size)) { xr = open_reparse_index(ni->vol); if (xr) { if (!ntfs_attr_exist(ni,AT_REPARSE_POINT, AT_UNNAMED,0)) { if (!(flags & XATTR_REPLACE)) { /* * no reparse data attribute : add one, * apparently, this does not feed the new value in * Note : NTFS version must be >= 3 */ if (ni->vol->major_ver >= 3) { res = ntfs_attr_add(ni, AT_REPARSE_POINT, AT_UNNAMED,0,&dummy, (s64)0); if (!res) { ni->flags |= FILE_ATTR_REPARSE_POINT; NInoFileNameSetDirty(ni); } NInoSetDirty(ni); } else { errno = EOPNOTSUPP; res = -1; } } else { errno = ENODATA; res = -1; } } else { if (flags & XATTR_CREATE) { errno = EEXIST; res = -1; } } if (!res) { /* update value and index */ res = update_reparse_data(ni,xr,value,size); } xrni = xr->ni; ntfs_index_entry_mark_dirty(xr); NInoSetDirty(xrni); ntfs_index_ctx_put(xr); ntfs_inode_close(xrni); } else { res = -1; } } else { errno = EINVAL; res = -1; } return (res ? -1 : 0); } /* * Remove the reparse data * * Returns 0, or -1 if there is a problem */ int ntfs_remove_ntfs_reparse_data(ntfs_inode *ni) { int res; int olderrno; ntfs_attr *na; ntfs_inode *xrni; ntfs_index_context *xr; le32 reparse_tag; res = 0; if (ni) { /* * open and delete the reparse data */ na = ntfs_attr_open(ni, AT_REPARSE_POINT, AT_UNNAMED,0); if (na) { /* first remove index (reparse data needed) */ xr = open_reparse_index(ni->vol); if (xr) { if (remove_reparse_index(na,xr, &reparse_tag) < 0) { res = -1; } else { /* now remove attribute */ res = ntfs_attr_rm(na); if (!res) { ni->flags &= ~FILE_ATTR_REPARSE_POINT; NInoFileNameSetDirty(ni); } else { /* * If we could not remove the * attribute, try to restore the * index and log the error. There * will be an inconsistency if * the reindexing fails. */ set_reparse_index(ni, xr, reparse_tag); ntfs_log_error( "Failed to remove reparse data." " Possible corruption.\n"); } } xrni = xr->ni; ntfs_index_entry_mark_dirty(xr); NInoSetDirty(xrni); ntfs_index_ctx_put(xr); ntfs_inode_close(xrni); } olderrno = errno; ntfs_attr_close(na); /* avoid errno pollution */ if (errno == ENOENT) errno = olderrno; } else { errno = ENODATA; res = -1; } NInoSetDirty(ni); } else { errno = EINVAL; res = -1; } return (res ? -1 : 0); } /* * Set reparse data for a WSL type symlink */ int ntfs_reparse_set_wsl_symlink(ntfs_inode *ni, const ntfschar *target, int target_len) { int res; int len; int reparse_len; char *utarget; REPARSE_POINT *reparse; struct WSL_LINK_REPARSE_DATA *data; res = -1; utarget = (char*)NULL; len = ntfs_ucstombs(target, target_len, &utarget, 0); if (len > 0) { reparse_len = sizeof(REPARSE_POINT) + sizeof(data->type) + len; reparse = (REPARSE_POINT*)malloc(reparse_len); if (reparse) { data = (struct WSL_LINK_REPARSE_DATA*) reparse->reparse_data; reparse->reparse_tag = IO_REPARSE_TAG_LX_SYMLINK; reparse->reparse_data_length = cpu_to_le16(sizeof(data->type) + len); reparse->reserved = const_cpu_to_le16(0); data->type = const_cpu_to_le32(2); memcpy(data->link, utarget, len); res = ntfs_set_ntfs_reparse_data(ni, (char*)reparse, reparse_len, 0); free(reparse); } } free(utarget); return (res); } /* * Set reparse data for a WSL special file other than a symlink * (socket, fifo, character or block device) */ int ntfs_reparse_set_wsl_not_symlink(ntfs_inode *ni, mode_t mode) { int res; int len; int reparse_len; le32 reparse_tag; REPARSE_POINT *reparse; res = -1; len = 0; switch (mode) { case S_IFSOCK : reparse_tag = IO_REPARSE_TAG_AF_UNIX; break; case S_IFIFO : reparse_tag = IO_REPARSE_TAG_LX_FIFO; break; case S_IFCHR : reparse_tag = IO_REPARSE_TAG_LX_CHR; break; case S_IFBLK : reparse_tag = IO_REPARSE_TAG_LX_BLK; break; default : len = -1; errno = EOPNOTSUPP; break; } if (len >= 0) { reparse_len = sizeof(REPARSE_POINT) + len; reparse = (REPARSE_POINT*)malloc(reparse_len); if (reparse) { reparse->reparse_tag = reparse_tag; reparse->reparse_data_length = cpu_to_le16(len); reparse->reserved = const_cpu_to_le16(0); res = ntfs_set_ntfs_reparse_data(ni, (char*)reparse, reparse_len, 0); free(reparse); } } return (res); } /* * Get the reparse data into a buffer * * Returns the buffer if the reparse data exists and is valid * NULL otherwise (with errno set according to the cause). * When a buffer is returned, it has to be freed by caller. */ REPARSE_POINT *ntfs_get_reparse_point(ntfs_inode *ni) { s64 attr_size = 0; REPARSE_POINT *reparse_attr; reparse_attr = (REPARSE_POINT*)NULL; if (ni) { reparse_attr = (REPARSE_POINT*)ntfs_attr_readall(ni, AT_REPARSE_POINT,(ntfschar*)NULL, 0, &attr_size); if (reparse_attr && !valid_reparse_data(ni, reparse_attr, attr_size)) { free(reparse_attr); reparse_attr = (REPARSE_POINT*)NULL; errno = EINVAL; } } else errno = EINVAL; return (reparse_attr); } ntfs-3g-2026.2.25/libntfs-3g/volume.c0000664000175000017500000015130215152260173012425 /** * volume.c - NTFS volume handling code. Originated from the Linux-NTFS project. * * Copyright (c) 2000-2006 Anton Altaparmakov * Copyright (c) 2002-2009 Szabolcs Szakacsits * Copyright (c) 2004-2005 Richard Russon * Copyright (c) 2010 Jean-Pierre Andre * * This program/include file 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/include file 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_STDLIB_H #include #endif #ifdef HAVE_STDIO_H #include #endif #ifdef HAVE_STRING_H #include #endif #ifdef HAVE_FCNTL_H #include #endif #ifdef HAVE_UNISTD_H #include #endif #ifdef HAVE_ERRNO_H #include #endif #ifdef HAVE_SYS_STAT_H #include #endif #ifdef HAVE_LIMITS_H #include #endif #ifdef HAVE_LOCALE_H #include #endif #if defined(__sun) && defined (__SVR4) #include #endif #include "param.h" #include "compat.h" #include "volume.h" #include "attrib.h" #include "mft.h" #include "bootsect.h" #include "device.h" #include "debug.h" #include "inode.h" #include "runlist.h" #include "logfile.h" #include "dir.h" #include "logging.h" #include "cache.h" #include "realpath.h" #include "misc.h" #include "security.h" const char *ntfs_home = "News, support and information: https://github.com/tuxera/ntfs-3g/\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 in an unsafe state. Please resume and shutdown\n" "Windows fully (no hibernation or fast restarting), or mount the volume\n" "read-only with the 'ro' mount option.\n"; static const char *fallback_readonly_msg = "Falling back to read-only mount because the NTFS partition is in an\n" "unsafe state. Please resume and shutdown Windows fully (no hibernation\n" "or fast restarting.)\n"; static const char *unclean_journal_msg = "Write access is denied because the disk wasn't safely powered\n" "off and the 'norecover' mount option was specified.\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" "https://github.com/tuxera/ntfs-3g/wiki/NTFS-3G-FAQ\n"; /** * ntfs_volume_alloc - Create an NTFS volume object and initialise it * * Description... * * Returns: */ ntfs_volume *ntfs_volume_alloc(void) { return ntfs_calloc(sizeof(ntfs_volume)); } static void ntfs_attr_free(ntfs_attr **na) { if (na && *na) { ntfs_attr_close(*na); *na = NULL; } } static int ntfs_inode_free(ntfs_inode **ni) { int ret = -1; if (ni && *ni) { ret = ntfs_inode_close(*ni); *ni = NULL; } return ret; } static void ntfs_error_set(int *err) { if (!*err) *err = errno; } /** * __ntfs_volume_release - Destroy an NTFS volume object * @v: * * Description... * * Returns: */ static int __ntfs_volume_release(ntfs_volume *v) { int err = 0; if (ntfs_close_secure(v)) ntfs_error_set(&err); if (ntfs_inode_free(&v->vol_ni)) ntfs_error_set(&err); /* * FIXME: Inodes must be synced before closing * attributes, otherwise unmount could fail. */ if (v->lcnbmp_ni && NInoDirty(v->lcnbmp_ni)) ntfs_inode_sync(v->lcnbmp_ni); ntfs_attr_free(&v->lcnbmp_na); if (ntfs_inode_free(&v->lcnbmp_ni)) ntfs_error_set(&err); if (v->mft_ni && NInoDirty(v->mft_ni)) ntfs_inode_sync(v->mft_ni); ntfs_attr_free(&v->mftbmp_na); ntfs_attr_free(&v->mft_na); if (ntfs_inode_free(&v->mft_ni)) ntfs_error_set(&err); if (v->mftmirr_ni && NInoDirty(v->mftmirr_ni)) ntfs_inode_sync(v->mftmirr_ni); ntfs_attr_free(&v->mftmirr_na); if (ntfs_inode_free(&v->mftmirr_ni)) ntfs_error_set(&err); if (v->dev) { struct ntfs_device *dev = v->dev; if (dev->d_ops->sync(dev)) ntfs_error_set(&err); if (dev->d_ops->close(dev)) ntfs_error_set(&err); } ntfs_free_lru_caches(v); free(v->vol_name); free(v->upcase); if (v->locase) free(v->locase); free(v->attrdef); free(v); errno = err; return errno ? -1 : 0; } static int ntfs_attr_setup_flag(ntfs_inode *ni) { STANDARD_INFORMATION *si; s64 lth; int r; si = (STANDARD_INFORMATION*)ntfs_attr_readall(ni, AT_STANDARD_INFORMATION, AT_UNNAMED, 0, <h); if (si) { if ((u64)lth >= offsetof(STANDARD_INFORMATION, owner_id)) ni->flags = si->file_attributes; free(si); r = 0; } else { ntfs_log_error("Failed to get standard information of $MFT\n"); r = -1; } return (r); } /** * ntfs_mft_load - load the $MFT and setup the ntfs volume with it * @vol: ntfs volume whose $MFT to load * * Load $MFT from @vol and setup @vol with it. After calling this function the * volume @vol is ready for use by all read access functions provided by the * ntfs library. * * Return 0 on success and -1 on error with errno set to the error code. */ static int ntfs_mft_load(ntfs_volume *vol) { VCN next_vcn, last_vcn, highest_vcn; s64 l; MFT_RECORD *mb = NULL; ntfs_attr_search_ctx *ctx = NULL; ATTR_RECORD *a; int eo; /* Manually setup an ntfs_inode. */ vol->mft_ni = ntfs_inode_allocate(vol); mb = ntfs_malloc(vol->mft_record_size); if (!vol->mft_ni || !mb) { ntfs_log_perror("Error allocating memory for $MFT"); goto error_exit; } vol->mft_ni->mft_no = 0; vol->mft_ni->mrec = mb; /* Can't use any of the higher level functions yet! */ l = ntfs_mst_pread(vol->dev, vol->mft_lcn << vol->cluster_size_bits, 1, vol->mft_record_size, mb); if (l != 1) { if (l != -1) errno = EIO; ntfs_log_perror("Error reading $MFT"); goto error_exit; } if (ntfs_mft_record_check(vol, 0, mb)) goto error_exit; ctx = ntfs_attr_get_search_ctx(vol->mft_ni, NULL); if (!ctx) goto error_exit; /* Find the $ATTRIBUTE_LIST attribute in $MFT if present. */ if (ntfs_attr_lookup(AT_ATTRIBUTE_LIST, AT_UNNAMED, 0, 0, 0, NULL, 0, ctx)) { if (errno != ENOENT) { ntfs_log_error("$MFT has corrupt attribute list.\n"); goto io_error_exit; } goto mft_has_no_attr_list; } NInoSetAttrList(vol->mft_ni); l = ntfs_get_attribute_value_length(ctx->attr); if (l <= 0 || l > 0x40000) { ntfs_log_error("$MFT/$ATTR_LIST invalid length (%lld).\n", (long long)l); goto io_error_exit; } vol->mft_ni->attr_list_size = l; vol->mft_ni->attr_list = ntfs_malloc(l); if (!vol->mft_ni->attr_list) goto error_exit; l = ntfs_get_attribute_value(vol, ctx->attr, vol->mft_ni->attr_list); if (!l) { ntfs_log_error("Failed to get value of $MFT/$ATTR_LIST.\n"); goto io_error_exit; } if ((l != vol->mft_ni->attr_list_size) || (l < (s64)offsetof(ATTR_LIST_ENTRY, name))) { ntfs_log_error("Partial read of $MFT/$ATTR_LIST (%lld != " "%u or < %d).\n", (long long)l, vol->mft_ni->attr_list_size, (int)offsetof(ATTR_LIST_ENTRY, name)); goto io_error_exit; } mft_has_no_attr_list: if (ntfs_attr_setup_flag(vol->mft_ni)) goto error_exit; /* We now have a fully setup ntfs inode for $MFT in vol->mft_ni. */ /* Get an ntfs attribute for $MFT/$DATA and set it up, too. */ vol->mft_na = ntfs_attr_open(vol->mft_ni, AT_DATA, AT_UNNAMED, 0); if (!vol->mft_na) { ntfs_log_perror("Failed to open ntfs attribute"); goto error_exit; } /* Read all extents from the $DATA attribute in $MFT. */ ntfs_attr_reinit_search_ctx(ctx); last_vcn = vol->mft_na->allocated_size >> vol->cluster_size_bits; highest_vcn = next_vcn = 0; a = NULL; while (!ntfs_attr_lookup(AT_DATA, AT_UNNAMED, 0, 0, next_vcn, NULL, 0, ctx)) { runlist_element *nrl; a = ctx->attr; /* $MFT must be non-resident. */ if (!a->non_resident) { ntfs_log_error("$MFT must be non-resident.\n"); goto io_error_exit; } /* $MFT must be uncompressed and unencrypted. */ if (a->flags & ATTR_COMPRESSION_MASK || a->flags & ATTR_IS_ENCRYPTED) { ntfs_log_error("$MFT must be uncompressed and " "unencrypted.\n"); goto io_error_exit; } /* * Decompress the mapping pairs array of this extent and merge * the result into the existing runlist. No need for locking * as we have exclusive access to the inode at this time and we * are a mount in progress task, too. */ nrl = ntfs_mapping_pairs_decompress(vol, a, vol->mft_na->rl); if (!nrl) { ntfs_log_perror("ntfs_mapping_pairs_decompress() failed"); goto error_exit; } /* Make sure $DATA is the MFT itself */ if (nrl->lcn != vol->mft_lcn) { ntfs_log_perror("The MFT is not self-contained"); goto error_exit; } vol->mft_na->rl = nrl; /* Get the lowest vcn for the next extent. */ highest_vcn = sle64_to_cpu(a->highest_vcn); next_vcn = highest_vcn + 1; /* Only one extent or error, which we catch below. */ if (next_vcn <= 0) break; /* Avoid endless loops due to corruption. */ if (next_vcn < sle64_to_cpu(a->lowest_vcn)) { ntfs_log_error("$MFT has corrupt attribute list.\n"); goto io_error_exit; } } if (!a) { ntfs_log_error("$MFT/$DATA attribute not found.\n"); goto io_error_exit; } if (highest_vcn && highest_vcn != last_vcn - 1) { ntfs_log_error("Failed to load runlist for $MFT/$DATA.\n"); ntfs_log_error("highest_vcn = 0x%llx, last_vcn - 1 = 0x%llx\n", (long long)highest_vcn, (long long)last_vcn - 1); goto io_error_exit; } /* Done with the $Mft mft record. */ ntfs_attr_put_search_ctx(ctx); ctx = NULL; /* Update the size fields in the inode. */ vol->mft_ni->data_size = vol->mft_na->data_size; vol->mft_ni->allocated_size = vol->mft_na->allocated_size; set_nino_flag(vol->mft_ni, KnownSize); /* * The volume is now setup so we can use all read access functions. */ vol->mftbmp_na = ntfs_attr_open(vol->mft_ni, AT_BITMAP, AT_UNNAMED, 0); if (!vol->mftbmp_na) { ntfs_log_perror("Failed to open $MFT/$BITMAP"); goto error_exit; } return 0; io_error_exit: errno = EIO; error_exit: eo = errno; if (ctx) ntfs_attr_put_search_ctx(ctx); if (vol->mft_na) { ntfs_attr_close(vol->mft_na); vol->mft_na = NULL; } if (vol->mft_ni) { ntfs_inode_close(vol->mft_ni); vol->mft_ni = NULL; } errno = eo; return -1; } /** * ntfs_mftmirr_load - load the $MFTMirr and setup the ntfs volume with it * @vol: ntfs volume whose $MFTMirr to load * * Load $MFTMirr from @vol and setup @vol with it. After calling this function * the volume @vol is ready for use by all write access functions provided by * the ntfs library (assuming ntfs_mft_load() has been called successfully * beforehand). * * Return 0 on success and -1 on error with errno set to the error code. */ static int ntfs_mftmirr_load(ntfs_volume *vol) { int err; vol->mftmirr_ni = ntfs_inode_open(vol, FILE_MFTMirr); if (!vol->mftmirr_ni) { ntfs_log_perror("Failed to open inode $MFTMirr"); return -1; } vol->mftmirr_na = ntfs_attr_open(vol->mftmirr_ni, AT_DATA, AT_UNNAMED, 0); if (!vol->mftmirr_na) { ntfs_log_perror("Failed to open $MFTMirr/$DATA"); goto error_exit; } if (ntfs_attr_map_runlist(vol->mftmirr_na, 0) < 0) { ntfs_log_perror("Failed to map runlist of $MFTMirr/$DATA"); goto error_exit; } if (vol->mftmirr_na->rl->lcn != vol->mftmirr_lcn) { ntfs_log_error("Bad $MFTMirr lcn 0x%llx, want 0x%llx\n", (long long)vol->mftmirr_na->rl->lcn, (long long)vol->mftmirr_lcn); goto error_exit; } return 0; error_exit: err = errno; if (vol->mftmirr_na) { ntfs_attr_close(vol->mftmirr_na); vol->mftmirr_na = NULL; } ntfs_inode_close(vol->mftmirr_ni); vol->mftmirr_ni = NULL; errno = err; return -1; } /** * ntfs_volume_startup - allocate and setup an ntfs volume * @dev: device to open * @flags: optional mount flags * * Load, verify, and parse bootsector; load and setup $MFT and $MFTMirr. After * calling this function, the volume is setup sufficiently to call all read * and write access functions provided by the library. * * Return the allocated volume structure on success and NULL on error with * errno set to the error code. */ ntfs_volume *ntfs_volume_startup(struct ntfs_device *dev, ntfs_mount_flags flags) { LCN mft_zone_size, mft_lcn; s64 br; ntfs_volume *vol; NTFS_BOOT_SECTOR *bs; int eo; if (!dev || !dev->d_ops || !dev->d_name) { errno = EINVAL; ntfs_log_perror("%s: dev = %p", __FUNCTION__, dev); return NULL; } bs = ntfs_malloc(sizeof(NTFS_BOOT_SECTOR)); if (!bs) return NULL; /* Allocate the volume structure. */ vol = ntfs_volume_alloc(); if (!vol) goto error_exit; /* Create the default upcase table. */ vol->upcase_len = ntfs_upcase_build_default(&vol->upcase); if (!vol->upcase_len || !vol->upcase) goto error_exit; /* Default with no locase table and case sensitive file names */ vol->locase = (ntfschar*)NULL; NVolSetCaseSensitive(vol); /* by default, all files are shown and not marked hidden */ NVolSetShowSysFiles(vol); NVolSetShowHidFiles(vol); NVolClearHideDotFiles(vol); /* set default compression */ #if DEFAULT_COMPRESSION NVolSetCompression(vol); #else NVolClearCompression(vol); #endif if (flags & NTFS_MNT_RDONLY) NVolSetReadOnly(vol); /* ...->open needs bracketing to compile with glibc 2.7 */ if ((dev->d_ops->open)(dev, NVolReadOnly(vol) ? O_RDONLY: O_RDWR)) { if (!NVolReadOnly(vol) && (errno == EROFS)) { if ((dev->d_ops->open)(dev, O_RDONLY)) { ntfs_log_perror("Error opening read-only '%s'", dev->d_name); goto error_exit; } else { ntfs_log_info("Error opening '%s' read-write\n", dev->d_name); NVolSetReadOnly(vol); } } else { ntfs_log_perror("Error opening '%s'", dev->d_name); goto error_exit; } } /* Attach the device to the volume. */ vol->dev = dev; /* Now read the bootsector. */ br = ntfs_pread(dev, 0, sizeof(NTFS_BOOT_SECTOR), bs); if (br != sizeof(NTFS_BOOT_SECTOR)) { if (br != -1) errno = EINVAL; if (!br) ntfs_log_error("Failed to read bootsector (size=0)\n"); else ntfs_log_perror("Error reading bootsector"); goto error_exit; } if (!ntfs_boot_sector_is_ntfs(bs)) { errno = EINVAL; goto error_exit; } if (ntfs_boot_sector_parse(vol, bs) < 0) goto error_exit; free(bs); bs = NULL; /* Now set the device block size to the sector size. */ if (ntfs_device_block_size_set(vol->dev, vol->sector_size)) ntfs_log_debug("Failed to set the device block size to the " "sector size. This may affect performance " "but should be harmless otherwise. Error: " "%s\n", strerror(errno)); /* We now initialize the cluster allocator. */ vol->full_zones = 0; mft_zone_size = vol->nr_clusters >> 3; /* 12.5% */ /* Setup the mft zone. */ vol->mft_zone_start = vol->mft_zone_pos = vol->mft_lcn; ntfs_log_debug("mft_zone_pos = 0x%llx\n", (long long)vol->mft_zone_pos); /* * Calculate the mft_lcn for an unmodified NTFS volume (see mkntfs * source) and if the actual mft_lcn is in the expected place or even * further to the front of the volume, extend the mft_zone to cover the * beginning of the volume as well. This is in order to protect the * area reserved for the mft bitmap as well within the mft_zone itself. * On non-standard volumes we don't protect it as the overhead would be * higher than the speed increase we would get by doing it. */ mft_lcn = (8192 + 2 * vol->cluster_size - 1) / vol->cluster_size; if (mft_lcn * vol->cluster_size < 16 * 1024) mft_lcn = (16 * 1024 + vol->cluster_size - 1) / vol->cluster_size; if (vol->mft_zone_start <= mft_lcn) vol->mft_zone_start = 0; ntfs_log_debug("mft_zone_start = 0x%llx\n", (long long)vol->mft_zone_start); /* * Need to cap the mft zone on non-standard volumes so that it does * not point outside the boundaries of the volume. We do this by * halving the zone size until we are inside the volume. */ vol->mft_zone_end = vol->mft_lcn + mft_zone_size; while (vol->mft_zone_end >= vol->nr_clusters) { mft_zone_size >>= 1; if (!mft_zone_size) { errno = EINVAL; goto error_exit; } vol->mft_zone_end = vol->mft_lcn + mft_zone_size; } ntfs_log_debug("mft_zone_end = 0x%llx\n", (long long)vol->mft_zone_end); /* * Set the current position within each data zone to the start of the * respective zone. */ vol->data1_zone_pos = vol->mft_zone_end; ntfs_log_debug("data1_zone_pos = %lld\n", (long long)vol->data1_zone_pos); vol->data2_zone_pos = 0; ntfs_log_debug("data2_zone_pos = %lld\n", (long long)vol->data2_zone_pos); /* Set the mft data allocation position to mft record 24. */ vol->mft_data_pos = 24; /* * The cluster allocator is now fully operational. */ /* Need to setup $MFT so we can use the library read functions. */ if (ntfs_mft_load(vol) < 0) { ntfs_log_perror("Failed to load $MFT"); goto error_exit; } /* Need to setup $MFTMirr so we can use the write functions, too. */ if (ntfs_mftmirr_load(vol) < 0) { ntfs_log_perror("Failed to load $MFTMirr"); goto error_exit; } return vol; error_exit: eo = errno; free(bs); if (vol) __ntfs_volume_release(vol); errno = eo; return NULL; } /** * ntfs_volume_check_logfile - check logfile on target volume * @vol: volume on which to check logfile * * Return 0 on success and -1 on error with errno set error code. */ static int ntfs_volume_check_logfile(ntfs_volume *vol) { ntfs_inode *ni; ntfs_attr *na = NULL; RESTART_PAGE_HEADER *rp = NULL; int err = 0; ni = ntfs_inode_open(vol, FILE_LogFile); if (!ni) { ntfs_log_perror("Failed to open inode FILE_LogFile"); errno = EIO; return -1; } na = ntfs_attr_open(ni, AT_DATA, AT_UNNAMED, 0); if (!na) { ntfs_log_perror("Failed to open $FILE_LogFile/$DATA"); err = EIO; goto out; } if (!ntfs_check_logfile(na, &rp) || !ntfs_is_logfile_clean(na, rp)) err = EOPNOTSUPP; /* * If the latest restart page was identified as version * 2.0, then Windows may have kept a cached copy of * metadata for fast restarting, and we should not mount. * Hibernation will be seen the same way on a non * Windows-system partition, so we have to use the same * error code (EPERM). * The restart page may also be identified as version 2.0 * when access to the file system is terminated abruptly * by unplugging or power cut, so mounting is also rejected * after such an event. */ if (rp && (rp->major_ver == const_cpu_to_le16(2)) && (rp->minor_ver == const_cpu_to_le16(0))) { ntfs_log_error("Metadata kept in Windows cache, refused to mount.\n"); err = EPERM; } free(rp); ntfs_attr_close(na); out: if (ntfs_inode_close(ni)) ntfs_error_set(&err); if (err) { errno = err; return -1; } return 0; } /** * ntfs_hiberfile_open - Find and open '/hiberfil.sys' * @vol: An ntfs volume obtained from ntfs_mount * * Return: inode Success, hiberfil.sys is valid * NULL hiberfil.sys doesn't exist or some other error occurred */ static ntfs_inode *ntfs_hiberfile_open(ntfs_volume *vol) { u64 inode; ntfs_inode *ni_root; ntfs_inode *ni_hibr = NULL; ntfschar *unicode = NULL; int unicode_len; const char *hiberfile = "hiberfil.sys"; if (!vol) { errno = EINVAL; return NULL; } ni_root = ntfs_inode_open(vol, FILE_root); if (!ni_root) { ntfs_log_debug("Couldn't open the root directory.\n"); return NULL; } unicode_len = ntfs_mbstoucs(hiberfile, &unicode); if (unicode_len < 0) { ntfs_log_perror("Couldn't convert 'hiberfil.sys' to Unicode"); goto out; } inode = ntfs_inode_lookup_by_name(ni_root, unicode, unicode_len); if (inode == (u64)-1) { ntfs_log_debug("Couldn't find file '%s'.\n", hiberfile); goto out; } inode = MREF(inode); ni_hibr = ntfs_inode_open(vol, inode); if (!ni_hibr) { ntfs_log_debug("Couldn't open inode %lld.\n", (long long)inode); goto out; } out: if (ntfs_inode_close(ni_root)) { ntfs_inode_close(ni_hibr); ni_hibr = NULL; } free(unicode); return ni_hibr; } #define NTFS_HIBERFILE_HEADER_SIZE 4096 /** * ntfs_volume_check_hiberfile - check hiberfil.sys whether Windows is * hibernated on the target volume * @vol: volume on which to check hiberfil.sys * * Return: 0 if Windows isn't hibernated for sure * -1 otherwise and errno is set to the appropriate value */ int ntfs_volume_check_hiberfile(ntfs_volume *vol, int verbose) { ntfs_inode *ni; ntfs_attr *na = NULL; int bytes_read, err; char *buf = NULL; ni = ntfs_hiberfile_open(vol); if (!ni) { if (errno == ENOENT) return 0; return -1; } buf = ntfs_malloc(NTFS_HIBERFILE_HEADER_SIZE); if (!buf) goto out; na = ntfs_attr_open(ni, AT_DATA, AT_UNNAMED, 0); if (!na) { ntfs_log_perror("Failed to open hiberfil.sys data attribute"); goto out; } bytes_read = ntfs_attr_pread(na, 0, NTFS_HIBERFILE_HEADER_SIZE, buf); if (bytes_read == -1) { ntfs_log_perror("Failed to read hiberfil.sys"); goto out; } if (bytes_read < NTFS_HIBERFILE_HEADER_SIZE) { if (verbose) ntfs_log_error("Hibernated non-system partition, " "refused to mount.\n"); errno = EPERM; goto out; } if ((memcmp(buf, "hibr", 4) == 0) || (memcmp(buf, "HIBR", 4) == 0)) { if (verbose) ntfs_log_error("Windows is hibernated, refused to mount.\n"); errno = EPERM; goto out; } /* All right, all header bytes are zero */ errno = 0; out: if (na) ntfs_attr_close(na); free(buf); err = errno; if (ntfs_inode_close(ni)) ntfs_error_set(&err); errno = err; return errno ? -1 : 0; } /* * Make sure a LOGGED_UTILITY_STREAM attribute named "$TXF_DATA" * on the root directory is resident. * When it is non-resident, the partition cannot be mounted on Vista * (see http://support.microsoft.com/kb/974729) * * We take care to avoid this situation, however this can be a * consequence of having used an older version (including older * Windows version), so we had better fix it. * * Returns 0 if unneeded or successful * -1 if there was an error, explained by errno */ static int fix_txf_data(ntfs_volume *vol) { void *txf_data; s64 txf_data_size; ntfs_inode *ni; ntfs_attr *na; int res; res = 0; ntfs_log_debug("Loading root directory\n"); ni = ntfs_inode_open(vol, FILE_root); if (!ni) { ntfs_log_perror("Failed to open root directory"); res = -1; } else { /* Get the $TXF_DATA attribute */ na = ntfs_attr_open(ni, AT_LOGGED_UTILITY_STREAM, TXF_DATA, 9); if (na) { if (NAttrNonResident(na)) { /* * Fix the attribute by truncating, then * rewriting it. */ ntfs_log_debug("Making $TXF_DATA resident\n"); txf_data = ntfs_attr_readall(ni, AT_LOGGED_UTILITY_STREAM, TXF_DATA, 9, &txf_data_size); if (txf_data) { if (ntfs_attr_truncate(na, 0) || (ntfs_attr_pwrite(na, 0, txf_data_size, txf_data) != txf_data_size)) res = -1; free(txf_data); } if (res) ntfs_log_error("Failed to make $TXF_DATA resident\n"); else ntfs_log_error("$TXF_DATA made resident\n"); } ntfs_attr_close(na); } if (ntfs_inode_close(ni)) { ntfs_log_perror("Failed to close root"); res = -1; } } return (res); } /** * ntfs_device_mount - open ntfs volume * @dev: device to open * @flags: optional mount flags * * This function mounts an ntfs volume. @dev should describe the device which * to mount as the ntfs volume. * * @flags is an optional second parameter. The same flags are used as for * the mount system call (man 2 mount). Currently only the following flag * is implemented: * NTFS_MNT_RDONLY - mount volume read-only * * The function opens the device @dev and verifies that it contains a valid * bootsector. Then, it allocates an ntfs_volume structure and initializes * some of the values inside the structure from the information stored in the * bootsector. It proceeds to load the necessary system files and completes * setting up the structure. * * Return the allocated volume structure on success and NULL on error with * errno set to the error code. */ ntfs_volume *ntfs_device_mount(struct ntfs_device *dev, ntfs_mount_flags flags) { s64 l; ntfs_volume *vol; u8 *m = NULL, *m2 = NULL; ntfs_attr_search_ctx *ctx = NULL; ntfs_inode *ni; ntfs_attr *na; ATTR_RECORD *a; VOLUME_INFORMATION *vinf; ntfschar *vname; u32 record_size; int i, j, eo; unsigned int k; u32 u; BOOL need_fallback_ro; need_fallback_ro = FALSE; vol = ntfs_volume_startup(dev, flags); if (!vol) return NULL; /* Load data from $MFT and $MFTMirr and compare the contents. */ m = ntfs_malloc(vol->mftmirr_size << vol->mft_record_size_bits); m2 = ntfs_malloc(vol->mftmirr_size << vol->mft_record_size_bits); if (!m || !m2) goto error_exit; l = ntfs_attr_mst_pread(vol->mft_na, 0, vol->mftmirr_size, vol->mft_record_size, m); if (l != vol->mftmirr_size) { if (l == -1) ntfs_log_perror("Failed to read $MFT"); else { ntfs_log_error("Failed to read $MFT, unexpected length " "(%lld != %d).\n", (long long)l, vol->mftmirr_size); errno = EIO; } goto error_exit; } for (i = 0; (i < l) && (i < FILE_first_user); ++i) if (ntfs_mft_record_check(vol, FILE_MFT + i, (MFT_RECORD*)(m + i*vol->mft_record_size))) goto error_exit; l = ntfs_attr_mst_pread(vol->mftmirr_na, 0, vol->mftmirr_size, vol->mft_record_size, m2); if (l != vol->mftmirr_size) { if (l == -1) { ntfs_log_perror("Failed to read $MFTMirr"); goto error_exit; } vol->mftmirr_size = l; } for (i = 0; (i < l) && (i < FILE_first_user); ++i) if (ntfs_mft_record_check(vol, FILE_MFT + i, (MFT_RECORD*)(m2 + i*vol->mft_record_size))) goto error_exit; ntfs_log_debug("Comparing $MFTMirr to $MFT...\n"); /* Windows 10 does not update the full $MFTMirr any more */ for (i = 0; (i < vol->mftmirr_size) && (i < FILE_first_user); ++i) { MFT_RECORD *mrec, *mrec2; const char *ESTR[12] = { "$MFT", "$MFTMirr", "$LogFile", "$Volume", "$AttrDef", "root directory", "$Bitmap", "$Boot", "$BadClus", "$Secure", "$UpCase", "$Extend" }; const char *s; if (i < 12) s = ESTR[i]; else if (i < 16) s = "system file"; else s = "mft record"; mrec = (MFT_RECORD*)(m + i * vol->mft_record_size); if (mrec->flags & MFT_RECORD_IN_USE) { if (ntfs_is_baad_record(mrec->magic)) { ntfs_log_error("$MFT error: Incomplete multi " "sector transfer detected in " "'%s'.\n", s); goto io_error_exit; } if (!ntfs_is_mft_record(mrec->magic)) { ntfs_log_error("$MFT error: Invalid mft " "record for '%s'.\n", s); goto io_error_exit; } } mrec2 = (MFT_RECORD*)(m2 + i * vol->mft_record_size); if (mrec2->flags & MFT_RECORD_IN_USE) { if (ntfs_is_baad_record(mrec2->magic)) { ntfs_log_error("$MFTMirr error: Incomplete " "multi sector transfer " "detected in '%s'.\n", s); goto io_error_exit; } if (!ntfs_is_mft_record(mrec2->magic)) { ntfs_log_error("$MFTMirr error: Invalid mft " "record for '%s'.\n", s); goto io_error_exit; } } record_size = ntfs_mft_record_get_data_size(mrec); if ((record_size <= sizeof(MFT_RECORD)) || (record_size > vol->mft_record_size) || memcmp(mrec, mrec2, record_size)) { ntfs_log_error("$MFTMirr does not match $MFT (record " "%d).\n", i); goto io_error_exit; } } free(m2); free(m); m = m2 = NULL; /* Now load the bitmap from $Bitmap. */ ntfs_log_debug("Loading $Bitmap...\n"); vol->lcnbmp_ni = ntfs_inode_open(vol, FILE_Bitmap); if (!vol->lcnbmp_ni) { ntfs_log_perror("Failed to open inode FILE_Bitmap"); goto error_exit; } vol->lcnbmp_na = ntfs_attr_open(vol->lcnbmp_ni, AT_DATA, AT_UNNAMED, 0); if (!vol->lcnbmp_na) { ntfs_log_perror("Failed to open ntfs attribute"); goto error_exit; } if (vol->lcnbmp_na->data_size > vol->lcnbmp_na->allocated_size) { ntfs_log_error("Corrupt cluster map size (%lld > %lld)\n", (long long)vol->lcnbmp_na->data_size, (long long)vol->lcnbmp_na->allocated_size); goto io_error_exit; } /* Now load the upcase table from $UpCase. */ ntfs_log_debug("Loading $UpCase...\n"); ni = ntfs_inode_open(vol, FILE_UpCase); if (!ni) { ntfs_log_perror("Failed to open inode FILE_UpCase"); goto error_exit; } /* Get an ntfs attribute for $UpCase/$DATA. */ na = ntfs_attr_open(ni, AT_DATA, AT_UNNAMED, 0); if (!na) { ntfs_log_perror("Failed to open ntfs attribute"); ntfs_inode_close(ni); goto error_exit; } /* * Note: Normally, the upcase table has a length equal to 65536 * 2-byte Unicode characters. Anyway we currently can only process * such characters. */ if ((na->data_size - 2) & ~0x1fffeULL) { ntfs_log_error("Error: Upcase table is invalid (want size even " "<= 131072).\n"); errno = EINVAL; goto bad_upcase; } if (vol->upcase_len != na->data_size >> 1) { vol->upcase_len = na->data_size >> 1; /* Throw away default table. */ free(vol->upcase); vol->upcase = ntfs_malloc(na->data_size); if (!vol->upcase) goto bad_upcase; } /* Read in the $DATA attribute value into the buffer. */ l = ntfs_attr_pread(na, 0, na->data_size, vol->upcase); if (l != na->data_size) { ntfs_log_error("Failed to read $UpCase, unexpected length " "(%lld != %lld).\n", (long long)l, (long long)na->data_size); errno = EIO; goto bad_upcase; } /* Done with the $UpCase mft record. */ ntfs_attr_close(na); if (ntfs_inode_close(ni)) { ntfs_log_perror("Failed to close $UpCase"); goto error_exit; } /* Consistency check of $UpCase, restricted to plain ASCII chars */ k = 0x20; while ((k < vol->upcase_len) && (k < 0x7f) && (le16_to_cpu(vol->upcase[k]) == ((k < 'a') || (k > 'z') ? k : k + 'A' - 'a'))) k++; if (k < 0x7f) { ntfs_log_error("Corrupted file $UpCase\n"); goto io_error_exit; } /* * Now load $Volume and set the version information and flags in the * vol structure accordingly. */ ntfs_log_debug("Loading $Volume...\n"); vol->vol_ni = ntfs_inode_open(vol, FILE_Volume); if (!vol->vol_ni) { ntfs_log_perror("Failed to open inode FILE_Volume"); goto error_exit; } /* Get a search context for the $Volume/$VOLUME_INFORMATION lookup. */ ctx = ntfs_attr_get_search_ctx(vol->vol_ni, NULL); if (!ctx) goto error_exit; /* Find the $VOLUME_INFORMATION attribute. */ if (ntfs_attr_lookup(AT_VOLUME_INFORMATION, AT_UNNAMED, 0, 0, 0, NULL, 0, ctx)) { ntfs_log_perror("$VOLUME_INFORMATION attribute not found in " "$Volume"); goto error_exit; } a = ctx->attr; /* Has to be resident. */ if (a->non_resident) { ntfs_log_error("Attribute $VOLUME_INFORMATION must be " "resident but it isn't.\n"); errno = EIO; goto error_exit; } /* Get a pointer to the value of the attribute. */ vinf = (VOLUME_INFORMATION*)(le16_to_cpu(a->value_offset) + (char*)a); /* Sanity checks. */ if ((char*)vinf + le32_to_cpu(a->value_length) > (char*)ctx->mrec + le32_to_cpu(ctx->mrec->bytes_in_use) || le16_to_cpu(a->value_offset) + le32_to_cpu( a->value_length) > le32_to_cpu(a->length)) { ntfs_log_error("$VOLUME_INFORMATION in $Volume is corrupt.\n"); errno = EIO; goto error_exit; } /* Setup vol from the volume information attribute value. */ vol->major_ver = vinf->major_ver; vol->minor_ver = vinf->minor_ver; /* Do not use le16_to_cpu() macro here as our VOLUME_FLAGS are defined using cpu_to_le16() macro and hence are consistent. */ vol->flags = vinf->flags; /* * Reinitialize the search context for the $Volume/$VOLUME_NAME lookup. */ ntfs_attr_reinit_search_ctx(ctx); if (ntfs_attr_lookup(AT_VOLUME_NAME, AT_UNNAMED, 0, 0, 0, NULL, 0, ctx)) { if (errno != ENOENT) { ntfs_log_perror("Failed to lookup of $VOLUME_NAME in " "$Volume failed"); goto error_exit; } /* * Attribute not present. This has been seen in the field. * Treat this the same way as if the attribute was present but * had zero length. */ vol->vol_name = ntfs_malloc(1); if (!vol->vol_name) goto error_exit; vol->vol_name[0] = '\0'; } else { a = ctx->attr; /* Has to be resident. */ if (a->non_resident) { ntfs_log_error("$VOLUME_NAME must be resident.\n"); errno = EIO; goto error_exit; } /* Get a pointer to the value of the attribute. */ vname = (ntfschar*)(le16_to_cpu(a->value_offset) + (char*)a); u = le32_to_cpu(a->value_length) / 2; /* * Convert Unicode volume name to current locale multibyte * format. */ vol->vol_name = NULL; if (ntfs_ucstombs(vname, u, &vol->vol_name, 0) == -1) { ntfs_log_perror("Volume name could not be converted " "to current locale"); ntfs_log_debug("Forcing name into ASCII by replacing " "non-ASCII characters with underscores.\n"); vol->vol_name = ntfs_malloc(u + 1); if (!vol->vol_name) goto error_exit; for (j = 0; j < (s32)u; j++) { u16 uc = le16_to_cpu(vname[j]); if (uc > 0xff) uc = (u16)'_'; vol->vol_name[j] = (char)uc; } vol->vol_name[u] = '\0'; } } ntfs_attr_put_search_ctx(ctx); ctx = NULL; /* Now load the attribute definitions from $AttrDef. */ ntfs_log_debug("Loading $AttrDef...\n"); ni = ntfs_inode_open(vol, FILE_AttrDef); if (!ni) { ntfs_log_perror("Failed to open $AttrDef"); goto error_exit; } /* Get an ntfs attribute for $AttrDef/$DATA. */ na = ntfs_attr_open(ni, AT_DATA, AT_UNNAMED, 0); if (!na) { ntfs_log_perror("Failed to open ntfs attribute"); goto error_exit; } /* Check we don't overflow 24-bits. */ if ((u64)na->data_size > 0xffffffLL) { ntfs_log_error("Attribute definition table is too big (max " "24-bit allowed).\n"); errno = EINVAL; goto error_exit; } vol->attrdef_len = na->data_size; vol->attrdef = ntfs_malloc(na->data_size); if (!vol->attrdef) goto error_exit; /* Read in the $DATA attribute value into the buffer. */ l = ntfs_attr_pread(na, 0, na->data_size, vol->attrdef); if (l != na->data_size) { ntfs_log_error("Failed to read $AttrDef, unexpected length " "(%lld != %lld).\n", (long long)l, (long long)na->data_size); errno = EIO; goto error_exit; } /* Done with the $AttrDef mft record. */ ntfs_attr_close(na); if (ntfs_inode_close(ni)) { ntfs_log_perror("Failed to close $AttrDef"); goto error_exit; } /* Open $Secure. */ if (ntfs_open_secure(vol)) goto error_exit; /* * Check for dirty logfile and hibernated Windows. * We care only about read-write mounts. */ if (!(flags & (NTFS_MNT_RDONLY | NTFS_MNT_FORENSIC))) { if (!(flags & NTFS_MNT_IGNORE_HIBERFILE) && ntfs_volume_check_hiberfile(vol, 1) < 0) { if (flags & NTFS_MNT_MAY_RDONLY) need_fallback_ro = TRUE; else goto error_exit; } if (ntfs_volume_check_logfile(vol) < 0) { /* Always reject cached metadata for now */ if (!(flags & NTFS_MNT_RECOVER) || (errno == EPERM)) { if (flags & NTFS_MNT_MAY_RDONLY) need_fallback_ro = TRUE; else goto error_exit; } else { ntfs_log_info("The file system wasn't safely " "closed on Windows. Fixing.\n"); if (ntfs_logfile_reset(vol)) goto error_exit; } } /* make $TXF_DATA resident if present on the root directory */ if (!(flags & NTFS_MNT_RDONLY) && !need_fallback_ro) { if (fix_txf_data(vol)) goto error_exit; } } if (need_fallback_ro) { NVolSetReadOnly(vol); ntfs_log_error("%s", fallback_readonly_msg); } return vol; bad_upcase : ntfs_attr_close(na); ntfs_inode_close(ni); goto error_exit; io_error_exit: errno = EIO; error_exit: eo = errno; if (ctx) ntfs_attr_put_search_ctx(ctx); free(m); free(m2); __ntfs_volume_release(vol); errno = eo; return NULL; } /* * Set appropriate flags for showing NTFS metafiles * or files marked as hidden. * Not set in ntfs_mount() to avoid breaking existing tools. */ int ntfs_set_shown_files(ntfs_volume *vol, BOOL show_sys_files, BOOL show_hid_files, BOOL hide_dot_files) { int res; res = -1; if (vol) { NVolClearShowSysFiles(vol); NVolClearShowHidFiles(vol); NVolClearHideDotFiles(vol); if (show_sys_files) NVolSetShowSysFiles(vol); if (show_hid_files) NVolSetShowHidFiles(vol); if (hide_dot_files) NVolSetHideDotFiles(vol); res = 0; } if (res) ntfs_log_error("Failed to set file visibility\n"); return (res); } /* * Set ignore case mode */ int ntfs_set_ignore_case(ntfs_volume *vol) { int res; res = -1; if (vol && vol->upcase) { vol->locase = ntfs_locase_table_build(vol->upcase, vol->upcase_len); if (vol->locase) { NVolClearCaseSensitive(vol); res = 0; } } if (res) ntfs_log_error("Failed to set ignore_case mode\n"); return (res); } /** * ntfs_mount - open ntfs volume * @name: name of device/file to open * @flags: optional mount flags * * This function mounts an ntfs volume. @name should contain the name of the * device/file to mount as the ntfs volume. * * @flags is an optional second parameter. The same flags are used as for * the mount system call (man 2 mount). Currently only the following flags * is implemented: * NTFS_MNT_RDONLY - mount volume read-only * * The function opens the device or file @name and verifies that it contains a * valid bootsector. Then, it allocates an ntfs_volume structure and initializes * some of the values inside the structure from the information stored in the * bootsector. It proceeds to load the necessary system files and completes * setting up the structure. * * Return the allocated volume structure on success and NULL on error with * errno set to the error code. * * Note, that a copy is made of @name, and hence it can be discarded as * soon as the function returns. */ ntfs_volume *ntfs_mount(const char *name __attribute__((unused)), ntfs_mount_flags flags __attribute__((unused))) { #ifndef NO_NTFS_DEVICE_DEFAULT_IO_OPS struct ntfs_device *dev; ntfs_volume *vol; /* Allocate an ntfs_device structure. */ dev = ntfs_device_alloc(name, 0, &ntfs_device_default_io_ops, NULL); if (!dev) return NULL; /* Call ntfs_device_mount() to do the actual mount. */ vol = ntfs_device_mount(dev, flags); if (!vol) { int eo = errno; ntfs_device_free(dev); errno = eo; } else ntfs_create_lru_caches(vol); return vol; #else /* * ntfs_mount() makes no sense if NO_NTFS_DEVICE_DEFAULT_IO_OPS is * defined as there are no device operations available in libntfs in * this case. */ errno = EOPNOTSUPP; return NULL; #endif } /** * ntfs_umount - close ntfs volume * @vol: address of ntfs_volume structure of volume to close * @force: if true force close the volume even if it is busy * * Deallocate all structures (including @vol itself) associated with the ntfs * volume @vol. * * Return 0 on success. On error return -1 with errno set appropriately * (most likely to one of EAGAIN, EBUSY or EINVAL). The EAGAIN error means that * an operation is in progress and if you try the close later the operation * might be completed and the close succeed. * * If @force is true (i.e. not zero) this function will close the volume even * if this means that data might be lost. * * @vol must have previously been returned by a call to ntfs_mount(). * * @vol itself is deallocated and should no longer be dereferenced after this * function returns success. If it returns an error then nothing has been done * so it is safe to continue using @vol. */ int ntfs_umount(ntfs_volume *vol, const BOOL force __attribute__((unused))) { struct ntfs_device *dev; int ret; if (!vol) { errno = EINVAL; return -1; } dev = vol->dev; ret = __ntfs_volume_release(vol); ntfs_device_free(dev); return ret; } #ifdef HAVE_MNTENT_H /** * ntfs_mntent_check - desc * * If you are wanting to use this, you actually wanted to use * ntfs_check_if_mounted(), you just didn't realize. (-: * * See description of ntfs_check_if_mounted(), below. */ static int ntfs_mntent_check(const char *file, unsigned long *mnt_flags) { struct mntent *mnt; char *real_file = NULL, *real_fsname = NULL; FILE *f; int err = 0; real_file = ntfs_malloc(PATH_MAX + 1); if (!real_file) return -1; real_fsname = ntfs_malloc(PATH_MAX + 1); if (!real_fsname) { err = errno; goto exit; } if (!ntfs_realpath_canonicalize(file, real_file)) { err = errno; goto exit; } f = setmntent("/proc/mounts", "r"); if (!f && !(f = setmntent(MOUNTED, "r"))) { err = errno; goto exit; } while ((mnt = getmntent(f))) { if (!ntfs_realpath_canonicalize(mnt->mnt_fsname, real_fsname)) continue; if (!strcmp(real_file, real_fsname)) break; } endmntent(f); if (!mnt) goto exit; *mnt_flags = NTFS_MF_MOUNTED; if (!strcmp(mnt->mnt_dir, "/")) *mnt_flags |= NTFS_MF_ISROOT; #ifdef HAVE_HASMNTOPT if (hasmntopt(mnt, "ro") && !hasmntopt(mnt, "rw")) *mnt_flags |= NTFS_MF_READONLY; #endif exit: free(real_file); free(real_fsname); if (err) { errno = err; return -1; } return 0; } #else /* HAVE_MNTENT_H */ #if defined(__sun) && defined (__SVR4) static int ntfs_mntent_check(const char *file, unsigned long *mnt_flags) { struct mnttab *mnt = NULL; char *real_file = NULL, *real_fsname = NULL; FILE *f; int err = 0; real_file = (char*)ntfs_malloc(PATH_MAX + 1); if (!real_file) return -1; real_fsname = (char*)ntfs_malloc(PATH_MAX + 1); mnt = (struct mnttab*)ntfs_malloc(MNT_LINE_MAX + 1); if (!real_fsname || !mnt) { err = errno; goto exit; } if (!ntfs_realpath_canonicalize(file, real_file)) { err = errno; goto exit; } if (!(f = fopen(MNTTAB, "r"))) { err = errno; goto exit; } while (!getmntent(f, mnt)) { if (!ntfs_realpath_canonicalize(mnt->mnt_special, real_fsname)) continue; if (!strcmp(real_file, real_fsname)) { *mnt_flags = NTFS_MF_MOUNTED; if (!strcmp(mnt->mnt_mountp, "/")) *mnt_flags |= NTFS_MF_ISROOT; if (hasmntopt(mnt, "ro") && !hasmntopt(mnt, "rw")) *mnt_flags |= NTFS_MF_READONLY; break; } } fclose(f); exit: free(mnt); free(real_file); free(real_fsname); if (err) { errno = err; return -1; } return 0; } #endif /* defined(__sun) && defined (__SVR4) */ #endif /* HAVE_MNTENT_H */ /** * ntfs_check_if_mounted - check if an ntfs volume is currently mounted * @file: device file to check * @mnt_flags: pointer into which to return the ntfs mount flags (see volume.h) * * If the running system does not support the {set,get,end}mntent() calls, * just return 0 and set *@mnt_flags to zero. * * When the system does support the calls, ntfs_check_if_mounted() first tries * to find the device @file in /etc/mtab (or wherever this is kept on the * running system). If it is not found, assume the device is not mounted and * return 0 and set *@mnt_flags to zero. * * If the device @file is found, set the NTFS_MF_MOUNTED flags in *@mnt_flags. * * Further if @file is mounted as the file system root ("/"), set the flag * NTFS_MF_ISROOT in *@mnt_flags. * * Finally, check if the file system is mounted read-only, and if so set the * NTFS_MF_READONLY flag in *@mnt_flags. * * On success return 0 with *@mnt_flags set to the ntfs mount flags. * * On error return -1 with errno set to the error code. */ int ntfs_check_if_mounted(const char *file __attribute__((unused)), unsigned long *mnt_flags) { *mnt_flags = 0; #if defined(HAVE_MNTENT_H) || (defined(__sun) && defined (__SVR4)) return ntfs_mntent_check(file, mnt_flags); #else return 0; #endif } /** * ntfs_version_is_supported - check if NTFS version is supported. * @vol: ntfs volume whose version we're interested in. * * The function checks if the NTFS volume version is known or not. * Version 1.1 and 1.2 are used by Windows NT3.x and NT4. * Version 2.x is used by Windows 2000 Betas. * Version 3.0 is used by Windows 2000. * Version 3.1 is used by Windows XP, Windows Server 2003 and Longhorn. * * Return 0 if NTFS version is supported otherwise -1 with errno set. * * The following error codes are defined: * EOPNOTSUPP - Unknown NTFS version * EINVAL - Invalid argument */ int ntfs_version_is_supported(ntfs_volume *vol) { u8 major, minor; if (!vol) { errno = EINVAL; return -1; } major = vol->major_ver; minor = vol->minor_ver; if (NTFS_V1_1(major, minor) || NTFS_V1_2(major, minor)) return 0; if (NTFS_V2_X(major, minor)) return 0; if (NTFS_V3_0(major, minor) || NTFS_V3_1(major, minor)) return 0; errno = EOPNOTSUPP; return -1; } /** * ntfs_logfile_reset - "empty" $LogFile data attribute value * @vol: ntfs volume whose $LogFile we intend to reset. * * Fill the value of the $LogFile data attribute, i.e. the contents of * the file, with 0xff's, thus marking the journal as empty. * * FIXME(?): We might need to zero the LSN field of every single mft * record as well. (But, first try without doing that and see what * happens, since chkdsk might pickup the pieces and do it for us...) * * On success return 0. * * On error return -1 with errno set to the error code. */ int ntfs_logfile_reset(ntfs_volume *vol) { ntfs_inode *ni; ntfs_attr *na; int eo; if (!vol) { errno = EINVAL; return -1; } ni = ntfs_inode_open(vol, FILE_LogFile); if (!ni) { ntfs_log_perror("Failed to open inode FILE_LogFile"); return -1; } na = ntfs_attr_open(ni, AT_DATA, AT_UNNAMED, 0); if (!na) { eo = errno; ntfs_log_perror("Failed to open $FILE_LogFile/$DATA"); goto error_exit; } if (ntfs_empty_logfile(na)) { eo = errno; ntfs_attr_close(na); goto error_exit; } ntfs_attr_close(na); return ntfs_inode_close(ni); error_exit: ntfs_inode_close(ni); errno = eo; return -1; } /** * ntfs_volume_write_flags - set the flags of an ntfs volume * @vol: ntfs volume where we set the volume flags * @flags: new flags * * Set the on-disk volume flags in the mft record of $Volume and * on volume @vol to @flags. * * Return 0 if successful and -1 if not with errno set to the error code. */ int ntfs_volume_write_flags(ntfs_volume *vol, const le16 flags) { ATTR_RECORD *a; VOLUME_INFORMATION *c; ntfs_attr_search_ctx *ctx; int ret = -1; /* failure */ if (!vol || !vol->vol_ni) { errno = EINVAL; return -1; } /* Get a pointer to the volume information attribute. */ ctx = ntfs_attr_get_search_ctx(vol->vol_ni, NULL); if (!ctx) return -1; if (ntfs_attr_lookup(AT_VOLUME_INFORMATION, AT_UNNAMED, 0, 0, 0, NULL, 0, ctx)) { ntfs_log_error("Attribute $VOLUME_INFORMATION was not found " "in $Volume!\n"); goto err_out; } a = ctx->attr; /* Sanity check. */ if (a->non_resident) { ntfs_log_error("Attribute $VOLUME_INFORMATION must be resident " "but it isn't.\n"); errno = EIO; goto err_out; } /* Get a pointer to the value of the attribute. */ c = (VOLUME_INFORMATION*)(le16_to_cpu(a->value_offset) + (char*)a); /* Sanity checks. */ if ((char*)c + le32_to_cpu(a->value_length) > (char*)ctx->mrec + le32_to_cpu(ctx->mrec->bytes_in_use) || le16_to_cpu(a->value_offset) + le32_to_cpu(a->value_length) > le32_to_cpu(a->length)) { ntfs_log_error("Attribute $VOLUME_INFORMATION in $Volume is " "corrupt!\n"); errno = EIO; goto err_out; } /* Set the volume flags. */ vol->flags = c->flags = flags & VOLUME_FLAGS_MASK; /* Write them to disk. */ ntfs_inode_mark_dirty(vol->vol_ni); if (ntfs_inode_sync(vol->vol_ni)) goto err_out; ret = 0; /* success */ err_out: ntfs_attr_put_search_ctx(ctx); return ret; } int ntfs_volume_error(int err) { int ret; switch (err) { case 0: ret = NTFS_VOLUME_OK; break; case EINVAL: ret = NTFS_VOLUME_NOT_NTFS; break; case EIO: ret = NTFS_VOLUME_CORRUPT; break; case EPERM: /* * Hibernation and fast restarting are seen the * same way on a non Windows-system partition. */ ret = NTFS_VOLUME_HIBERNATED; break; case EOPNOTSUPP: ret = NTFS_VOLUME_UNCLEAN_UNMOUNT; break; case EBUSY: ret = NTFS_VOLUME_LOCKED; break; case ENXIO: ret = NTFS_VOLUME_RAID; break; case EACCES: ret = NTFS_VOLUME_NO_PRIVILEGE; break; default: ret = NTFS_VOLUME_UNKNOWN_REASON; break; } 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); 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; } /* * Feed the counts of free clusters and free mft records */ int ntfs_volume_get_free_space(ntfs_volume *vol) { ntfs_attr *na; int ret; ret = -1; /* default return */ vol->free_clusters = ntfs_attr_get_free_bits(vol->lcnbmp_na); if (vol->free_clusters < 0) { ntfs_log_perror("Failed to read NTFS $Bitmap"); } else { na = vol->mftbmp_na; vol->free_mft_records = ntfs_attr_get_free_bits(na); if (vol->free_mft_records >= 0) vol->free_mft_records += (na->allocated_size - na->data_size) << 3; if (vol->free_mft_records < 0) ntfs_log_perror("Failed to calculate free MFT records"); else { NVolSetFreeSpaceKnown(vol); ret = 0; } } return (ret); } /** * ntfs_volume_rename - change the current label on a volume * @vol: volume to change the label on * @label: the new label * @label_len: the length of @label in ntfschars including the terminating NULL * character, which is mandatory (the value can not exceed 128) * * Change the label on the volume @vol to @label. */ int ntfs_volume_rename(ntfs_volume *vol, const ntfschar *label, int label_len) { ntfs_attr *na; char *old_vol_name; char *new_vol_name = NULL; int new_vol_name_len; int err; if (NVolReadOnly(vol)) { ntfs_log_error("Refusing to change label on read-only mounted " "volume.\n"); errno = EROFS; return -1; } label_len *= sizeof(ntfschar); if (label_len > 0x100) { ntfs_log_error("New label is too long. Maximum %u characters " "allowed.\n", (unsigned)(0x100 / sizeof(ntfschar))); errno = ERANGE; return -1; } na = ntfs_attr_open(vol->vol_ni, AT_VOLUME_NAME, AT_UNNAMED, 0); if (!na) { if (errno != ENOENT) { err = errno; ntfs_log_perror("Lookup of $VOLUME_NAME attribute " "failed"); goto err_out; } /* The volume name attribute does not exist. Need to add it. */ if (ntfs_attr_add(vol->vol_ni, AT_VOLUME_NAME, AT_UNNAMED, 0, (const u8*) label, label_len)) { err = errno; ntfs_log_perror("Encountered error while adding " "$VOLUME_NAME attribute"); goto err_out; } } else { s64 written; if (NAttrNonResident(na)) { err = errno; ntfs_log_error("Error: Attribute $VOLUME_NAME must be " "resident.\n"); goto err_out; } if (na->data_size != label_len) { if (ntfs_attr_truncate(na, label_len)) { err = errno; ntfs_log_perror("Error resizing resident " "attribute"); goto err_out; } } if (label_len) { written = ntfs_attr_pwrite(na, 0, label_len, label); if (written == -1) { err = errno; ntfs_log_perror("Error when writing " "$VOLUME_NAME data"); goto err_out; } else if (written != label_len) { err = EIO; ntfs_log_error("Partial write when writing " "$VOLUME_NAME data."); goto err_out; } } } new_vol_name_len = ntfs_ucstombs(label, label_len, &new_vol_name, 0); if (new_vol_name_len == -1) { err = errno; ntfs_log_perror("Error while decoding new volume name"); goto err_out; } old_vol_name = vol->vol_name; vol->vol_name = new_vol_name; free(old_vol_name); err = 0; err_out: if (na) ntfs_attr_close(na); if (err) errno = err; return err ? -1 : 0; } ntfs-3g-2026.2.25/libntfs-3g/cache.c0000664000175000017500000003626115152260173012167 /** * cache.c : deal with LRU caches * * Copyright (c) 2008-2010 Jean-Pierre Andre * * This program/include file 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/include file 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_STDLIB_H #include #endif #ifdef HAVE_STRING_H #include #endif #include "types.h" #include "security.h" #include "cache.h" #include "misc.h" #include "logging.h" /* * General functions to deal with LRU caches * * The cached data have to be organized in a structure in which * the first fields must follow a mandatory pattern and further * fields may contain any fixed size data. They are stored in an * LRU list. * * A compare function must be provided for finding a wanted entry * in the cache. Another function may be provided for invalidating * an entry to facilitate multiple invalidation. * * These functions never return error codes. When there is a * shortage of memory, data is simply not cached. * When there is a hashing bug, hashing is dropped, and sequential * searches are used. */ /* * Enter a new hash index, after a new record has been inserted * * Do not call when a record has been modified (with no key change) */ static void inserthashindex(struct CACHE_HEADER *cache, struct CACHED_GENERIC *current) { int h; struct HASH_ENTRY *link; struct HASH_ENTRY *first; if (cache->dohash) { h = cache->dohash(current); if ((h >= 0) && (h < cache->max_hash)) { /* get a free link and insert at top of hash list */ link = cache->free_hash; if (link) { cache->free_hash = link->next; first = cache->first_hash[h]; if (first) link->next = first; else link->next = NULL; link->entry = current; cache->first_hash[h] = link; } else { ntfs_log_error("No more hash entries," " cache %s hashing dropped\n", cache->name); cache->dohash = (cache_hash)NULL; } } else { ntfs_log_error("Illegal hash value," " cache %s hashing dropped\n", cache->name); cache->dohash = (cache_hash)NULL; } } } /* * Drop a hash index when a record is about to be deleted */ static void drophashindex(struct CACHE_HEADER *cache, const struct CACHED_GENERIC *current, int hash) { struct HASH_ENTRY *link; struct HASH_ENTRY *previous; if (cache->dohash) { if ((hash >= 0) && (hash < cache->max_hash)) { /* find the link and unlink */ link = cache->first_hash[hash]; previous = (struct HASH_ENTRY*)NULL; while (link && (link->entry != current)) { previous = link; link = link->next; } if (link) { if (previous) previous->next = link->next; else cache->first_hash[hash] = link->next; link->next = cache->free_hash; cache->free_hash = link; } else { ntfs_log_error("Bad hash list," " cache %s hashing dropped\n", cache->name); cache->dohash = (cache_hash)NULL; } } else { ntfs_log_error("Illegal hash value," " cache %s hashing dropped\n", cache->name); cache->dohash = (cache_hash)NULL; } } } /* * Fetch an entry from cache * * returns the cache entry, or NULL if not available * The returned entry may be modified, but not freed */ struct CACHED_GENERIC *ntfs_fetch_cache(struct CACHE_HEADER *cache, const struct CACHED_GENERIC *wanted, cache_compare compare) { struct CACHED_GENERIC *current; struct CACHED_GENERIC *previous; struct HASH_ENTRY *link; int h; current = (struct CACHED_GENERIC*)NULL; if (cache) { if (cache->dohash) { /* * When possible, use the hash table to * locate the entry if present */ h = cache->dohash(wanted); link = cache->first_hash[h]; while (link && compare(link->entry, wanted)) link = link->next; if (link) current = link->entry; } if (!cache->dohash) { /* * Search sequentially in LRU list if no hash table * or if hashing has just failed */ current = cache->most_recent_entry; while (current && compare(current, wanted)) { current = current->next; } } if (current) { previous = current->previous; cache->hits++; if (previous) { /* * found and not at head of list, unlink from current * position and relink as head of list */ previous->next = current->next; if (current->next) current->next->previous = current->previous; else cache->oldest_entry = current->previous; current->next = cache->most_recent_entry; current->previous = (struct CACHED_GENERIC*)NULL; cache->most_recent_entry->previous = current; cache->most_recent_entry = current; } } cache->reads++; } return (current); } /* * Enter an inode number into cache * returns the cache entry or NULL if not possible */ struct CACHED_GENERIC *ntfs_enter_cache(struct CACHE_HEADER *cache, const struct CACHED_GENERIC *item, cache_compare compare) { struct CACHED_GENERIC *current; struct CACHED_GENERIC *before; struct HASH_ENTRY *link; int h; current = (struct CACHED_GENERIC*)NULL; if (cache) { if (cache->dohash) { /* * When possible, use the hash table to * find out whether the entry if present */ h = cache->dohash(item); link = cache->first_hash[h]; while (link && compare(link->entry, item)) link = link->next; if (link) { current = link->entry; } } if (!cache->dohash) { /* * Search sequentially in LRU list to locate the end, * and find out whether the entry is already in list * As we normally go to the end, no statistics is * kept. */ current = cache->most_recent_entry; while (current && compare(current, item)) { current = current->next; } } if (!current) { /* * Not in list, get a free entry or reuse the * last entry, and relink as head of list * Note : we assume at least three entries, so * before, previous and first are different when * an entry is reused. */ if (cache->free_entry) { current = cache->free_entry; cache->free_entry = cache->free_entry->next; if (item->varsize) { current->variable = ntfs_malloc( item->varsize); } else current->variable = (void*)NULL; current->varsize = item->varsize; if (!cache->oldest_entry) cache->oldest_entry = current; } else { /* reusing the oldest entry */ current = cache->oldest_entry; before = current->previous; before->next = (struct CACHED_GENERIC*)NULL; if (cache->dohash) drophashindex(cache,current, cache->dohash(current)); if (cache->dofree) cache->dofree(current); cache->oldest_entry = current->previous; if (item->varsize) { if (current->varsize) current->variable = realloc( current->variable, item->varsize); else current->variable = ntfs_malloc( item->varsize); } else { if (current->varsize) free(current->variable); current->variable = (void*)NULL; } current->varsize = item->varsize; } current->next = cache->most_recent_entry; current->previous = (struct CACHED_GENERIC*)NULL; if (cache->most_recent_entry) cache->most_recent_entry->previous = current; cache->most_recent_entry = current; memcpy(current->payload, item->payload, cache->fixed_size); if (item->varsize) { if (current->variable) { memcpy(current->variable, item->variable, item->varsize); } else { /* * no more memory for variable part * recycle entry in free list * not an error, just uncacheable */ cache->most_recent_entry = current->next; current->next = cache->free_entry; cache->free_entry = current; current = (struct CACHED_GENERIC*)NULL; } } else { current->variable = (void*)NULL; current->varsize = 0; } if (cache->dohash && current) inserthashindex(cache,current); } cache->writes++; } return (current); } /* * Invalidate a cache entry * The entry is moved to the free entry list * A specific function may be called for entry deletion */ static void do_invalidate(struct CACHE_HEADER *cache, struct CACHED_GENERIC *current, int flags) { struct CACHED_GENERIC *previous; previous = current->previous; if ((flags & CACHE_FREE) && cache->dofree) cache->dofree(current); /* * Relink into free list */ if (current->next) current->next->previous = current->previous; else cache->oldest_entry = current->previous; if (previous) previous->next = current->next; else cache->most_recent_entry = current->next; current->next = cache->free_entry; cache->free_entry = current; if (current->variable) free(current->variable); current->varsize = 0; } /* * Invalidate entries in cache * * Several entries may have to be invalidated (at least for inodes * associated to directories which have been renamed), a different * compare function may be provided to select entries to invalidate * * Returns the number of deleted entries, this can be used by * the caller to signal a cache corruption if the entry was * supposed to be found. */ int ntfs_invalidate_cache(struct CACHE_HEADER *cache, const struct CACHED_GENERIC *item, cache_compare compare, int flags) { struct CACHED_GENERIC *current; struct CACHED_GENERIC *next; struct HASH_ENTRY *link; int count; int h; current = (struct CACHED_GENERIC*)NULL; count = 0; if (cache) { if (!(flags & CACHE_NOHASH) && cache->dohash) { /* * When possible, use the hash table to * find out whether the entry if present */ h = cache->dohash(item); link = cache->first_hash[h]; while (link) { if (compare(link->entry, item)) link = link->next; else { current = link->entry; link = link->next; if (current) { drophashindex(cache,current,h); do_invalidate(cache, current,flags); count++; } } } } if ((flags & CACHE_NOHASH) || !cache->dohash) { /* * Search sequentially in LRU list */ current = cache->most_recent_entry; while (current) { if (!compare(current, item)) { next = current->next; if (cache->dohash) drophashindex(cache,current, cache->dohash(current)); do_invalidate(cache,current,flags); current = next; count++; } else { current = current->next; } } } } return (count); } int ntfs_remove_cache(struct CACHE_HEADER *cache, struct CACHED_GENERIC *item, int flags) { int count; count = 0; if (cache) { if (cache->dohash) drophashindex(cache,item,cache->dohash(item)); do_invalidate(cache,item,flags); count++; } return (count); } /* * Free memory allocated to a cache */ static void ntfs_free_cache(struct CACHE_HEADER *cache) { struct CACHED_GENERIC *entry; if (cache) { for (entry=cache->most_recent_entry; entry; entry=entry->next) { if (cache->dofree) cache->dofree(entry); if (entry->variable) free(entry->variable); } free(cache); } } /* * Create a cache * * Returns the cache header, or NULL if the cache could not be created */ static struct CACHE_HEADER *ntfs_create_cache(const char *name, cache_free dofree, cache_hash dohash, int full_item_size, int item_count, int max_hash) { struct CACHE_HEADER *cache; struct CACHED_GENERIC *pc; struct CACHED_GENERIC *qc; struct HASH_ENTRY *ph; struct HASH_ENTRY *qh; struct HASH_ENTRY **px; size_t size; int i; size = sizeof(struct CACHE_HEADER) + item_count*full_item_size; if (max_hash) size += item_count*sizeof(struct HASH_ENTRY) + max_hash*sizeof(struct HASH_ENTRY*); cache = (struct CACHE_HEADER*)ntfs_malloc(size); if (cache) { /* header */ cache->name = name; cache->dofree = dofree; if (dohash && max_hash) { cache->dohash = dohash; cache->max_hash = max_hash; } else { cache->dohash = (cache_hash)NULL; cache->max_hash = 0; } cache->fixed_size = full_item_size - sizeof(struct CACHED_GENERIC); cache->reads = 0; cache->writes = 0; cache->hits = 0; /* chain the data entries, and mark an invalid entry */ cache->most_recent_entry = (struct CACHED_GENERIC*)NULL; cache->oldest_entry = (struct CACHED_GENERIC*)NULL; cache->free_entry = &cache->entry[0]; pc = &cache->entry[0]; for (i=0; i<(item_count - 1); i++) { qc = (struct CACHED_GENERIC*)((char*)pc + full_item_size); pc->next = qc; pc->variable = (void*)NULL; pc->varsize = 0; pc = qc; } /* special for the last entry */ pc->next = (struct CACHED_GENERIC*)NULL; pc->variable = (void*)NULL; pc->varsize = 0; if (max_hash) { /* chain the hash entries */ ph = (struct HASH_ENTRY*)(((char*)pc) + full_item_size); cache->free_hash = ph; for (i=0; i<(item_count - 1); i++) { qh = &ph[1]; ph->next = qh; ph = qh; } /* special for the last entry */ if (item_count) { ph->next = (struct HASH_ENTRY*)NULL; } /* create and initialize the hash indexes */ px = (struct HASH_ENTRY**)&ph[1]; cache->first_hash = px; for (i=0; ifree_hash = (struct HASH_ENTRY*)NULL; cache->first_hash = (struct HASH_ENTRY**)NULL; } } return (cache); } /* * Create all LRU caches * * No error return, if creation is not possible, cacheing will * just be not available */ void ntfs_create_lru_caches(ntfs_volume *vol) { #if CACHE_INODE_SIZE /* inode cache */ vol->xinode_cache = ntfs_create_cache("inode",(cache_free)NULL, ntfs_dir_inode_hash, sizeof(struct CACHED_INODE), CACHE_INODE_SIZE, 2*CACHE_INODE_SIZE); #endif #if CACHE_NIDATA_SIZE /* idata cache */ vol->nidata_cache = ntfs_create_cache("nidata", ntfs_inode_nidata_free, ntfs_inode_nidata_hash, sizeof(struct CACHED_NIDATA), CACHE_NIDATA_SIZE, 2*CACHE_NIDATA_SIZE); #endif #if CACHE_LOOKUP_SIZE /* lookup cache */ vol->lookup_cache = ntfs_create_cache("lookup", (cache_free)NULL, ntfs_dir_lookup_hash, sizeof(struct CACHED_LOOKUP), CACHE_LOOKUP_SIZE, 2*CACHE_LOOKUP_SIZE); #endif vol->securid_cache = ntfs_create_cache("securid",(cache_free)NULL, (cache_hash)NULL,sizeof(struct CACHED_SECURID), CACHE_SECURID_SIZE, 0); #if CACHE_LEGACY_SIZE vol->legacy_cache = ntfs_create_cache("legacy",(cache_free)NULL, (cache_hash)NULL, sizeof(struct CACHED_PERMISSIONS_LEGACY), CACHE_LEGACY_SIZE, 0); #endif } /* * Free all LRU caches */ void ntfs_free_lru_caches(ntfs_volume *vol) { #if CACHE_INODE_SIZE ntfs_free_cache(vol->xinode_cache); #endif #if CACHE_NIDATA_SIZE ntfs_free_cache(vol->nidata_cache); #endif #if CACHE_LOOKUP_SIZE ntfs_free_cache(vol->lookup_cache); #endif ntfs_free_cache(vol->securid_cache); #if CACHE_LEGACY_SIZE ntfs_free_cache(vol->legacy_cache); #endif } ntfs-3g-2026.2.25/libntfs-3g/logfile.c0000664000175000017500000006137515152260173012551 /** * logfile.c - NTFS journal handling. Originated from the Linux-NTFS project. * * Copyright (c) 2002-2005 Anton Altaparmakov * Copyright (c) 2005 Yura Pakhuchiy * Copyright (c) 2005-2009 Szabolcs Szakacsits * * This program/include file 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/include file 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_STDLIB_H #include #endif #ifdef HAVE_STRING_H #include #endif #ifdef HAVE_ERRNO_H #include #endif #include "attrib.h" #include "debug.h" #include "logfile.h" #include "volume.h" #include "mst.h" #include "logging.h" #include "misc.h" /** * ntfs_check_restart_page_header - check the page header for consistency * @rp: restart page header to check * @pos: position in logfile at which the restart page header resides * * Check the restart page header @rp for consistency and return TRUE if it is * consistent and FALSE otherwise. * * This function only needs NTFS_BLOCK_SIZE bytes in @rp, i.e. it does not * require the full restart page. */ static BOOL ntfs_check_restart_page_header(RESTART_PAGE_HEADER *rp, s64 pos) { u32 logfile_system_page_size, logfile_log_page_size; u16 ra_ofs, usa_count, usa_ofs, usa_end = 0; BOOL have_usa = TRUE; ntfs_log_trace("Entering.\n"); /* * If the system or log page sizes are smaller than the ntfs block size * or either is not a power of 2 we cannot handle this log file. */ logfile_system_page_size = le32_to_cpu(rp->system_page_size); logfile_log_page_size = le32_to_cpu(rp->log_page_size); if (logfile_system_page_size < NTFS_BLOCK_SIZE || logfile_log_page_size < NTFS_BLOCK_SIZE || logfile_system_page_size & (logfile_system_page_size - 1) || logfile_log_page_size & (logfile_log_page_size - 1)) { ntfs_log_error("$LogFile uses unsupported page size.\n"); return FALSE; } /* * We must be either at !pos (1st restart page) or at pos = system page * size (2nd restart page). */ if (pos && pos != logfile_system_page_size) { ntfs_log_error("Found restart area in incorrect " "position in $LogFile.\n"); return FALSE; } /* * We only know how to handle version 1.1 and 2.0, though * version 2.0 is probably related to cached metadata in * Windows 8, and we will refuse to mount. * Nevertheless, do all the relevant checks before rejecting. */ if (((rp->major_ver != const_cpu_to_sle16(1)) || (rp->minor_ver != const_cpu_to_sle16(1))) && ((rp->major_ver != const_cpu_to_sle16(2)) || (rp->minor_ver != const_cpu_to_sle16(0)))) { ntfs_log_error("$LogFile version %i.%i is not " "supported.\n (This driver supports version " "1.1 and 2.0 only.)\n", (int)sle16_to_cpu(rp->major_ver), (int)sle16_to_cpu(rp->minor_ver)); return FALSE; } /* * If chkdsk has been run the restart page may not be protected by an * update sequence array. */ if (ntfs_is_chkd_record(rp->magic) && !le16_to_cpu(rp->usa_count)) { have_usa = FALSE; goto skip_usa_checks; } /* Verify the size of the update sequence array. */ usa_count = 1 + (logfile_system_page_size >> NTFS_BLOCK_SIZE_BITS); if (usa_count != le16_to_cpu(rp->usa_count)) { ntfs_log_error("$LogFile restart page specifies " "inconsistent update sequence array count.\n"); return FALSE; } /* Verify the position of the update sequence array. */ usa_ofs = le16_to_cpu(rp->usa_ofs); usa_end = usa_ofs + usa_count * sizeof(u16); if (usa_ofs < offsetof(RESTART_PAGE_HEADER, usn) || usa_end > NTFS_BLOCK_SIZE - sizeof(u16)) { ntfs_log_error("$LogFile restart page specifies " "inconsistent update sequence array offset.\n"); return FALSE; } skip_usa_checks: /* * Verify the position of the restart area. It must be: * - aligned to 8-byte boundary, * - after the update sequence array, and * - within the system page size. */ ra_ofs = le16_to_cpu(rp->restart_area_offset); if (ra_ofs & 7 || (have_usa ? ra_ofs < usa_end : ra_ofs < offsetof(RESTART_PAGE_HEADER, usn)) || ra_ofs > logfile_system_page_size) { ntfs_log_error("$LogFile restart page specifies " "inconsistent restart area offset.\n"); return FALSE; } /* * Only restart pages modified by chkdsk are allowed to have chkdsk_lsn * set. */ if (!ntfs_is_chkd_record(rp->magic) && sle64_to_cpu(rp->chkdsk_lsn)) { ntfs_log_error("$LogFile restart page is not modified " "by chkdsk but a chkdsk LSN is specified.\n"); return FALSE; } ntfs_log_trace("Done.\n"); return TRUE; } /** * ntfs_check_restart_area - check the restart area for consistency * @rp: restart page whose restart area to check * * Check the restart area of the restart page @rp for consistency and return * TRUE if it is consistent and FALSE otherwise. * * This function assumes that the restart page header has already been * consistency checked. * * This function only needs NTFS_BLOCK_SIZE bytes in @rp, i.e. it does not * require the full restart page. */ static BOOL ntfs_check_restart_area(RESTART_PAGE_HEADER *rp) { u64 file_size; RESTART_AREA *ra; u16 ra_ofs, ra_len, ca_ofs; u8 fs_bits; ntfs_log_trace("Entering.\n"); ra_ofs = le16_to_cpu(rp->restart_area_offset); ra = (RESTART_AREA*)((u8*)rp + ra_ofs); /* * Everything before ra->file_size must be before the first word * protected by an update sequence number. This ensures that it is * safe to access ra->client_array_offset. */ if (ra_ofs + offsetof(RESTART_AREA, file_size) > NTFS_BLOCK_SIZE - sizeof(u16)) { ntfs_log_error("$LogFile restart area specifies " "inconsistent file offset.\n"); return FALSE; } /* * Now that we can access ra->client_array_offset, make sure everything * up to the log client array is before the first word protected by an * update sequence number. This ensures we can access all of the * restart area elements safely. Also, the client array offset must be * aligned to an 8-byte boundary. */ ca_ofs = le16_to_cpu(ra->client_array_offset); if (((ca_ofs + 7) & ~7) != ca_ofs || ra_ofs + ca_ofs > (u16)(NTFS_BLOCK_SIZE - sizeof(u16))) { ntfs_log_error("$LogFile restart area specifies " "inconsistent client array offset.\n"); return FALSE; } /* * The restart area must end within the system page size both when * calculated manually and as specified by ra->restart_area_length. * Also, the calculated length must not exceed the specified length. */ ra_len = ca_ofs + le16_to_cpu(ra->log_clients) * sizeof(LOG_CLIENT_RECORD); if ((u32)(ra_ofs + ra_len) > le32_to_cpu(rp->system_page_size) || (u32)(ra_ofs + le16_to_cpu(ra->restart_area_length)) > le32_to_cpu(rp->system_page_size) || ra_len > le16_to_cpu(ra->restart_area_length)) { ntfs_log_error("$LogFile restart area is out of bounds " "of the system page size specified by the " "restart page header and/or the specified " "restart area length is inconsistent.\n"); return FALSE; } /* * The ra->client_free_list and ra->client_in_use_list must be either * LOGFILE_NO_CLIENT or less than ra->log_clients or they are * overflowing the client array. */ if ((ra->client_free_list != LOGFILE_NO_CLIENT && le16_to_cpu(ra->client_free_list) >= le16_to_cpu(ra->log_clients)) || (ra->client_in_use_list != LOGFILE_NO_CLIENT && le16_to_cpu(ra->client_in_use_list) >= le16_to_cpu(ra->log_clients))) { ntfs_log_error("$LogFile restart area specifies " "overflowing client free and/or in use lists.\n"); return FALSE; } /* * Check ra->seq_number_bits against ra->file_size for consistency. * We cannot just use ffs() because the file size is not a power of 2. */ file_size = (u64)sle64_to_cpu(ra->file_size); fs_bits = 0; while (file_size) { file_size >>= 1; fs_bits++; } if (le32_to_cpu(ra->seq_number_bits) != (u32)(67 - fs_bits)) { ntfs_log_error("$LogFile restart area specifies " "inconsistent sequence number bits.\n"); return FALSE; } /* The log record header length must be a multiple of 8. */ if (((le16_to_cpu(ra->log_record_header_length) + 7) & ~7) != le16_to_cpu(ra->log_record_header_length)) { ntfs_log_error("$LogFile restart area specifies " "inconsistent log record header length.\n"); return FALSE; } /* Ditto for the log page data offset. */ if (((le16_to_cpu(ra->log_page_data_offset) + 7) & ~7) != le16_to_cpu(ra->log_page_data_offset)) { ntfs_log_error("$LogFile restart area specifies " "inconsistent log page data offset.\n"); return FALSE; } ntfs_log_trace("Done.\n"); return TRUE; } /** * ntfs_check_log_client_array - check the log client array for consistency * @rp: restart page whose log client array to check * * Check the log client array of the restart page @rp for consistency and * return TRUE if it is consistent and FALSE otherwise. * * This function assumes that the restart page header and the restart area have * already been consistency checked. * * Unlike ntfs_check_restart_page_header() and ntfs_check_restart_area(), this * function needs @rp->system_page_size bytes in @rp, i.e. it requires the full * restart page and the page must be multi sector transfer deprotected. */ static BOOL ntfs_check_log_client_array(RESTART_PAGE_HEADER *rp) { RESTART_AREA *ra; LOG_CLIENT_RECORD *ca, *cr; u16 nr_clients, idx; BOOL in_free_list, idx_is_first; u32 offset_clients; ntfs_log_trace("Entering.\n"); /* The restart area must be fully within page */ if ((le16_to_cpu(rp->restart_area_offset) + sizeof(RESTART_AREA)) > le32_to_cpu(rp->system_page_size)) goto err_out; ra = (RESTART_AREA*)((u8*)rp + le16_to_cpu(rp->restart_area_offset)); offset_clients = le16_to_cpu(rp->restart_area_offset) + le16_to_cpu(ra->client_array_offset); /* The clients' records must begin within page */ if (offset_clients >= le32_to_cpu(rp->system_page_size)) goto err_out; ca = (LOG_CLIENT_RECORD*)((u8*)ra + le16_to_cpu(ra->client_array_offset)); /* * Check the ra->client_free_list first and then check the * ra->client_in_use_list. Check each of the log client records in * each of the lists and check that the array does not overflow the * ra->log_clients value. Also keep track of the number of records * visited as there cannot be more than ra->log_clients records and * that way we detect eventual loops in within a list. */ nr_clients = le16_to_cpu(ra->log_clients); idx = le16_to_cpu(ra->client_free_list); in_free_list = TRUE; check_list: for (idx_is_first = TRUE; idx != LOGFILE_NO_CLIENT_CPU; nr_clients--, idx = le16_to_cpu(cr->next_client)) { if (!nr_clients || idx >= le16_to_cpu(ra->log_clients)) goto err_out; /* The client record must be fully within page */ if ((offset_clients + (idx + 1)*sizeof(LOG_CLIENT_RECORD)) > le32_to_cpu(rp->system_page_size)) goto err_out; /* Set @cr to the current log client record. */ cr = ca + idx; /* The first log client record must not have a prev_client. */ if (idx_is_first) { if (cr->prev_client != LOGFILE_NO_CLIENT) goto err_out; idx_is_first = FALSE; } } /* Switch to and check the in use list if we just did the free list. */ if (in_free_list) { in_free_list = FALSE; idx = le16_to_cpu(ra->client_in_use_list); goto check_list; } ntfs_log_trace("Done.\n"); return TRUE; err_out: ntfs_log_error("$LogFile log client array is corrupt.\n"); return FALSE; } /** * ntfs_check_and_load_restart_page - check the restart page for consistency * @log_na: opened ntfs attribute for journal $LogFile * @rp: restart page to check * @pos: position in @log_na at which the restart page resides * @wrp: [OUT] copy of the multi sector transfer deprotected restart page * @lsn: [OUT] set to the current logfile lsn on success * * Check the restart page @rp for consistency and return 0 if it is consistent * and errno otherwise. The restart page may have been modified by chkdsk in * which case its magic is CHKD instead of RSTR. * * This function only needs NTFS_BLOCK_SIZE bytes in @rp, i.e. it does not * require the full restart page. * * If @wrp is not NULL, on success, *@wrp will point to a buffer containing a * copy of the complete multi sector transfer deprotected page. On failure, * *@wrp is undefined. * * Similarly, if @lsn is not NULL, on success *@lsn will be set to the current * logfile lsn according to this restart page. On failure, *@lsn is undefined. * * The following error codes are defined: * EINVAL - The restart page is inconsistent. * ENOMEM - Not enough memory to load the restart page. * EIO - Failed to reading from $LogFile. */ static int ntfs_check_and_load_restart_page(ntfs_attr *log_na, RESTART_PAGE_HEADER *rp, s64 pos, RESTART_PAGE_HEADER **wrp, LSN *lsn) { RESTART_AREA *ra; RESTART_PAGE_HEADER *trp; int err; ntfs_log_trace("Entering.\n"); /* Check the restart page header for consistency. */ if (!ntfs_check_restart_page_header(rp, pos)) { /* Error output already done inside the function. */ return EINVAL; } /* Check the restart area for consistency. */ if (!ntfs_check_restart_area(rp)) { /* Error output already done inside the function. */ return EINVAL; } ra = (RESTART_AREA*)((u8*)rp + le16_to_cpu(rp->restart_area_offset)); /* * Allocate a buffer to store the whole restart page so we can multi * sector transfer deprotect it. * For safety, make sure this is consistent with the usa_count * and shorter than the full log size */ if ((le32_to_cpu(rp->system_page_size) > (u32)(le16_to_cpu(rp->usa_count) - 1)*NTFS_BLOCK_SIZE) || (le32_to_cpu(rp->system_page_size) > le64_to_cpu(log_na->data_size))) return (EINVAL); trp = ntfs_malloc(le32_to_cpu(rp->system_page_size)); if (!trp) return errno; /* * Read the whole of the restart page into the buffer. If it fits * completely inside @rp, just copy it from there. Otherwise read it * from disk. */ if (le32_to_cpu(rp->system_page_size) <= NTFS_BLOCK_SIZE) memcpy(trp, rp, le32_to_cpu(rp->system_page_size)); else if (ntfs_attr_pread(log_na, pos, le32_to_cpu(rp->system_page_size), trp) != le32_to_cpu(rp->system_page_size)) { err = errno; ntfs_log_error("Failed to read whole restart page into the " "buffer.\n"); if (err != ENOMEM) err = EIO; goto err_out; } /* * Perform the multi sector transfer deprotection on the buffer if the * restart page is protected. */ if ((!ntfs_is_chkd_record(trp->magic) || le16_to_cpu(trp->usa_count)) && ntfs_mst_post_read_fixup((NTFS_RECORD*)trp, le32_to_cpu(rp->system_page_size))) { /* * A multi sector tranfer error was detected. We only need to * abort if the restart page contents exceed the multi sector * transfer fixup of the first sector. */ if (le16_to_cpu(rp->restart_area_offset) + le16_to_cpu(ra->restart_area_length) > NTFS_BLOCK_SIZE - (int)sizeof(u16)) { ntfs_log_error("Multi sector transfer error " "detected in $LogFile restart page.\n"); err = EINVAL; goto err_out; } } /* * If the restart page is modified by chkdsk or there are no active * logfile clients, the logfile is consistent. Otherwise, need to * check the log client records for consistency, too. */ err = 0; if (ntfs_is_rstr_record(rp->magic) && ra->client_in_use_list != LOGFILE_NO_CLIENT) { if (!ntfs_check_log_client_array(trp)) { err = EINVAL; goto err_out; } } if (lsn) { if (ntfs_is_rstr_record(rp->magic)) *lsn = sle64_to_cpu(ra->current_lsn); else /* if (ntfs_is_chkd_record(rp->magic)) */ *lsn = sle64_to_cpu(rp->chkdsk_lsn); } ntfs_log_trace("Done.\n"); if (wrp) *wrp = trp; else { err_out: free(trp); } return err; } /** * ntfs_check_logfile - check in the journal if the volume is consistent * @log_na: ntfs attribute of loaded journal $LogFile to check * @rp: [OUT] on success this is a copy of the current restart page * * Check the $LogFile journal for consistency and return TRUE if it is * consistent and FALSE if not. On success, the current restart page is * returned in *@rp. Caller must call ntfs_free(*@rp) when finished with it. * * At present we only check the two restart pages and ignore the log record * pages. * * Note that the MstProtected flag is not set on the $LogFile inode and hence * when reading pages they are not deprotected. This is because we do not know * if the $LogFile was created on a system with a different page size to ours * yet and mst deprotection would fail if our page size is smaller. */ BOOL ntfs_check_logfile(ntfs_attr *log_na, RESTART_PAGE_HEADER **rp) { s64 size, pos; LSN rstr1_lsn, rstr2_lsn; ntfs_volume *vol = log_na->ni->vol; u8 *kaddr = NULL; RESTART_PAGE_HEADER *rstr1_ph = NULL; RESTART_PAGE_HEADER *rstr2_ph = NULL; int log_page_size, err; BOOL logfile_is_empty = TRUE; u8 log_page_bits; ntfs_log_trace("Entering.\n"); /* An empty $LogFile must have been clean before it got emptied. */ if (NVolLogFileEmpty(vol)) goto is_empty; size = log_na->data_size; /* Make sure the file doesn't exceed the maximum allowed size. */ if (size > (s64)MaxLogFileSize) size = MaxLogFileSize; log_page_size = DefaultLogPageSize; /* * Use generic_ffs() instead of ffs() to enable the compiler to * optimize log_page_size and log_page_bits into constants. */ log_page_bits = ffs(log_page_size) - 1; size &= ~(log_page_size - 1); /* * Ensure the log file is big enough to store at least the two restart * pages and the minimum number of log record pages. */ if (size < log_page_size * 2 || (size - log_page_size * 2) >> log_page_bits < MinLogRecordPages) { ntfs_log_error("$LogFile is too small.\n"); return FALSE; } /* Allocate memory for restart page. */ kaddr = ntfs_malloc(NTFS_BLOCK_SIZE); if (!kaddr) return FALSE; /* * Read through the file looking for a restart page. Since the restart * page header is at the beginning of a page we only need to search at * what could be the beginning of a page (for each page size) rather * than scanning the whole file byte by byte. If all potential places * contain empty and uninitialized records, the log file can be assumed * to be empty. */ for (pos = 0; pos < size; pos <<= 1) { /* * Read first NTFS_BLOCK_SIZE bytes of potential restart page. */ if (ntfs_attr_pread(log_na, pos, NTFS_BLOCK_SIZE, kaddr) != NTFS_BLOCK_SIZE) { ntfs_log_error("Failed to read first NTFS_BLOCK_SIZE " "bytes of potential restart page.\n"); goto err_out; } /* * A non-empty block means the logfile is not empty while an * empty block after a non-empty block has been encountered * means we are done. */ if (!ntfs_is_empty_recordp((le32*)kaddr)) logfile_is_empty = FALSE; else if (!logfile_is_empty) break; /* * A log record page means there cannot be a restart page after * this so no need to continue searching. */ if (ntfs_is_rcrd_recordp((le32*)kaddr)) break; /* If not a (modified by chkdsk) restart page, continue. */ if (!ntfs_is_rstr_recordp((le32*)kaddr) && !ntfs_is_chkd_recordp((le32*)kaddr)) { if (!pos) pos = NTFS_BLOCK_SIZE >> 1; continue; } /* * Check the (modified by chkdsk) restart page for consistency * and get a copy of the complete multi sector transfer * deprotected restart page. */ err = ntfs_check_and_load_restart_page(log_na, (RESTART_PAGE_HEADER*)kaddr, pos, !rstr1_ph ? &rstr1_ph : &rstr2_ph, !rstr1_ph ? &rstr1_lsn : &rstr2_lsn); if (!err) { /* * If we have now found the first (modified by chkdsk) * restart page, continue looking for the second one. */ if (!pos) { pos = NTFS_BLOCK_SIZE >> 1; continue; } /* * We have now found the second (modified by chkdsk) * restart page, so we can stop looking. */ break; } /* * Error output already done inside the function. Note, we do * not abort if the restart page was invalid as we might still * find a valid one further in the file. */ if (err != EINVAL) goto err_out; /* Continue looking. */ if (!pos) pos = NTFS_BLOCK_SIZE >> 1; } if (kaddr) { free(kaddr); kaddr = NULL; } if (logfile_is_empty) { NVolSetLogFileEmpty(vol); is_empty: ntfs_log_trace("Done. ($LogFile is empty.)\n"); return TRUE; } if (!rstr1_ph) { if (rstr2_ph) ntfs_log_error("BUG: rstr2_ph isn't NULL!\n"); ntfs_log_error("Did not find any restart pages in " "$LogFile and it was not empty.\n"); return FALSE; } /* If both restart pages were found, use the more recent one. */ if (rstr2_ph) { /* * If the second restart area is more recent, switch to it. * Otherwise just throw it away. */ if (rstr2_lsn > rstr1_lsn) { ntfs_log_debug("Using second restart page as it is more " "recent.\n"); free(rstr1_ph); rstr1_ph = rstr2_ph; /* rstr1_lsn = rstr2_lsn; */ } else { ntfs_log_debug("Using first restart page as it is more " "recent.\n"); free(rstr2_ph); } rstr2_ph = NULL; } /* All consistency checks passed. */ if (rp) *rp = rstr1_ph; else free(rstr1_ph); ntfs_log_trace("Done.\n"); return TRUE; err_out: free(kaddr); free(rstr1_ph); free(rstr2_ph); return FALSE; } /** * ntfs_is_logfile_clean - check in the journal if the volume is clean * @log_na: ntfs attribute of loaded journal $LogFile to check * @rp: copy of the current restart page * * Analyze the $LogFile journal and return TRUE if it indicates the volume was * shutdown cleanly and FALSE if not. * * At present we only look at the two restart pages and ignore the log record * pages. This is a little bit crude in that there will be a very small number * of cases where we think that a volume is dirty when in fact it is clean. * This should only affect volumes that have not been shutdown cleanly but did * not have any pending, non-check-pointed i/o, i.e. they were completely idle * at least for the five seconds preceding the unclean shutdown. * * This function assumes that the $LogFile journal has already been consistency * checked by a call to ntfs_check_logfile() and in particular if the $LogFile * is empty this function requires that NVolLogFileEmpty() is true otherwise an * empty volume will be reported as dirty. */ BOOL ntfs_is_logfile_clean(ntfs_attr *log_na, RESTART_PAGE_HEADER *rp) { RESTART_AREA *ra; ntfs_log_trace("Entering.\n"); /* An empty $LogFile must have been clean before it got emptied. */ if (NVolLogFileEmpty(log_na->ni->vol)) { ntfs_log_trace("$LogFile is empty\n"); return TRUE; } if (!rp) { ntfs_log_error("Restart page header is NULL\n"); return FALSE; } if (!ntfs_is_rstr_record(rp->magic) && !ntfs_is_chkd_record(rp->magic)) { ntfs_log_error("Restart page buffer is invalid\n"); return FALSE; } ra = (RESTART_AREA*)((u8*)rp + le16_to_cpu(rp->restart_area_offset)); /* * If the $LogFile has active clients, i.e. it is open, and we do not * have the RESTART_VOLUME_IS_CLEAN bit set in the restart area flags, * we assume there was an unclean shutdown. */ if (ra->client_in_use_list != LOGFILE_NO_CLIENT && !(ra->flags & RESTART_VOLUME_IS_CLEAN)) { ntfs_log_error("The disk contains an unclean file system (%d, " "%d).\n", le16_to_cpu(ra->client_in_use_list), le16_to_cpu(ra->flags)); return FALSE; } /* $LogFile indicates a clean shutdown. */ ntfs_log_trace("$LogFile indicates a clean shutdown\n"); return TRUE; } /** * ntfs_empty_logfile - empty the contents of the $LogFile journal * @na: ntfs attribute of journal $LogFile to empty * * Empty the contents of the $LogFile journal @na and return 0 on success and * -1 on error. * * This function assumes that the $LogFile journal has already been consistency * checked by a call to ntfs_check_logfile() and that ntfs_is_logfile_clean() * has been used to ensure that the $LogFile is clean. */ int ntfs_empty_logfile(ntfs_attr *na) { s64 pos, count; char buf[NTFS_BUF_SIZE]; ntfs_log_trace("Entering.\n"); if (NVolLogFileEmpty(na->ni->vol)) return 0; if (!NAttrNonResident(na)) { errno = EIO; ntfs_log_perror("Resident $LogFile $DATA attribute"); return -1; } memset(buf, -1, NTFS_BUF_SIZE); pos = 0; while ((count = na->data_size - pos) > 0) { if (count > NTFS_BUF_SIZE) count = NTFS_BUF_SIZE; count = ntfs_attr_pwrite(na, pos, count, buf); if (count <= 0) { ntfs_log_perror("Failed to reset $LogFile"); if (count != -1) errno = EIO; return -1; } pos += count; } NVolSetLogFileEmpty(na->ni->vol); return 0; } ntfs-3g-2026.2.25/libntfs-3g/mst.c0000664000175000017500000001776215152260173011734 /** * mst.c - Multi sector fixup handling code. Originated from the Linux-NTFS project. * * Copyright (c) 2000-2004 Anton Altaparmakov * Copyright (c) 2006-2009 Szabolcs Szakacsits * * This program/include file 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/include file 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_ERRNO_H #include #endif #include "mst.h" #include "logging.h" /* * Basic validation of a NTFS multi-sector record. The record size must be a * multiple of the logical sector size; and the update sequence array must be * properly aligned, of the expected length, and must end before the last le16 * in the first logical sector. */ static BOOL is_valid_record(u32 size, u16 usa_ofs, u16 usa_count) { return size % NTFS_BLOCK_SIZE == 0 && usa_ofs % 2 == 0 && usa_count == 1 + (size / NTFS_BLOCK_SIZE) && usa_ofs + ((u32)usa_count * 2) <= NTFS_BLOCK_SIZE - 2; } /** * ntfs_mst_post_read_fixup - deprotect multi sector transfer protected data * @b: pointer to the data to deprotect * @size: size in bytes of @b * * Perform the necessary post read multi sector transfer fixups and detect the * presence of incomplete multi sector transfers. - In that case, overwrite the * magic of the ntfs record header being processed with "BAAD" (in memory only!) * and abort processing. * * Return 0 on success and -1 on error, with errno set to the error code. The * following error codes are defined: * EINVAL Invalid arguments or invalid NTFS record in buffer @b. * EIO Multi sector transfer error was detected. Magic of the NTFS * record in @b will have been set to "BAAD". */ int ntfs_mst_post_read_fixup_warn(NTFS_RECORD *b, const u32 size, BOOL warn) { u16 usa_ofs, usa_count, usn; u16 *usa_pos, *data_pos; ntfs_log_trace("Entering\n"); /* Setup the variables. */ usa_ofs = le16_to_cpu(b->usa_ofs); usa_count = le16_to_cpu(b->usa_count); if (!is_valid_record(size, usa_ofs, usa_count)) { errno = EINVAL; if (warn) { ntfs_log_perror("%s: magic: 0x%08lx size: %ld " " usa_ofs: %d usa_count: %u", __FUNCTION__, (long)le32_to_cpu(*(le32 *)b), (long)size, (int)usa_ofs, (unsigned int)usa_count); } return -1; } /* Position of usn in update sequence array. */ usa_pos = (u16*)b + usa_ofs/sizeof(u16); /* * The update sequence number which has to be equal to each of the * u16 values before they are fixed up. Note no need to care for * endianness since we are comparing and moving data for on disk * structures which means the data is consistent. - If it is * consistency the wrong endianness it doesn't make any difference. */ usn = *usa_pos; /* * Position in protected data of first u16 that needs fixing up. */ data_pos = (u16*)b + NTFS_BLOCK_SIZE/sizeof(u16) - 1; /* * Check for incomplete multi sector transfer(s). */ while (--usa_count) { if (*data_pos != usn) { /* * Incomplete multi sector transfer detected! )-: * Set the magic to "BAAD" and return failure. * Note that magic_BAAD is already converted to le32. */ errno = EIO; ntfs_log_perror("Incomplete multi-sector transfer: " "magic: 0x%08x size: %d usa_ofs: %d usa_count:" " %d data: %d usn: %d", le32_to_cpu(*(le32 *)b), size, usa_ofs, usa_count, *data_pos, usn); b->magic = magic_BAAD; return -1; } data_pos += NTFS_BLOCK_SIZE/sizeof(u16); } /* Re-setup the variables. */ usa_count = le16_to_cpu(b->usa_count); data_pos = (u16*)b + NTFS_BLOCK_SIZE/sizeof(u16) - 1; /* Fixup all sectors. */ while (--usa_count) { /* * Increment position in usa and restore original data from * the usa into the data buffer. */ *data_pos = *(++usa_pos); /* Increment position in data as well. */ data_pos += NTFS_BLOCK_SIZE/sizeof(u16); } return 0; } /* * Deprotect multi sector transfer protected data * with a warning if an error is found. */ int ntfs_mst_post_read_fixup(NTFS_RECORD *b, const u32 size) { return (ntfs_mst_post_read_fixup_warn(b,size,TRUE)); } /** * ntfs_mst_pre_write_fixup - apply multi sector transfer protection * @b: pointer to the data to protect * @size: size in bytes of @b * * Perform the necessary pre write multi sector transfer fixup on the data * pointer to by @b of @size. * * Return 0 if fixups applied successfully or -1 if no fixups were performed * due to errors. In that case errno i set to the error code (EINVAL). * * NOTE: We consider the absence / invalidity of an update sequence array to * mean error. This means that you have to create a valid update sequence * array header in the ntfs record before calling this function, otherwise it * will fail (the header needs to contain the position of the update sequence * array together with the number of elements in the array). You also need to * initialise the update sequence number before calling this function * otherwise a random word will be used (whatever was in the record at that * position at that time). */ int ntfs_mst_pre_write_fixup(NTFS_RECORD *b, const u32 size) { u16 usa_ofs, usa_count, usn; le16 le_usn; le16 *usa_pos, *data_pos; ntfs_log_trace("Entering\n"); /* Sanity check + only fixup if it makes sense. */ if (!b || ntfs_is_baad_record(b->magic) || ntfs_is_hole_record(b->magic)) { errno = EINVAL; ntfs_log_perror("%s: bad argument", __FUNCTION__); return -1; } /* Setup the variables. */ usa_ofs = le16_to_cpu(b->usa_ofs); usa_count = le16_to_cpu(b->usa_count); if (!is_valid_record(size, usa_ofs, usa_count)) { errno = EINVAL; ntfs_log_perror("%s", __FUNCTION__); return -1; } /* Position of usn in update sequence array. */ usa_pos = (le16*)((u8*)b + usa_ofs); /* * Cyclically increment the update sequence number * (skipping 0 and -1, i.e. 0xffff). */ usn = le16_to_cpup(usa_pos) + 1; if (usn == 0xffff || !usn) usn = 1; le_usn = cpu_to_le16(usn); *usa_pos = le_usn; /* Position in data of first le16 that needs fixing up. */ data_pos = (le16*)b + NTFS_BLOCK_SIZE/sizeof(le16) - 1; /* Fixup all sectors. */ while (--usa_count) { /* * Increment the position in the usa and save the * original data from the data buffer into the usa. */ *(++usa_pos) = *data_pos; /* Apply fixup to data. */ *data_pos = le_usn; /* Increment position in data as well. */ data_pos += NTFS_BLOCK_SIZE/sizeof(le16); } return 0; } /** * ntfs_mst_post_write_fixup - deprotect multi sector transfer protected data * @b: pointer to the data to deprotect * * Perform the necessary post write multi sector transfer fixup, not checking * for any errors, because we assume we have just used * ntfs_mst_pre_write_fixup(), thus the data will be fine or we would never * have gotten here. */ void ntfs_mst_post_write_fixup(NTFS_RECORD *b) { u16 *usa_pos, *data_pos; u16 usa_ofs = le16_to_cpu(b->usa_ofs); u16 usa_count = le16_to_cpu(b->usa_count); ntfs_log_trace("Entering\n"); /* Position of usn in update sequence array. */ usa_pos = (u16*)b + usa_ofs/sizeof(u16); /* Position in protected data of first u16 that needs fixing up. */ data_pos = (u16*)b + NTFS_BLOCK_SIZE/sizeof(u16) - 1; /* Fixup all sectors. */ while (--usa_count) { /* * Increment position in usa and restore original data from * the usa into the data buffer. */ *data_pos = *(++usa_pos); /* Increment position in data as well. */ data_pos += NTFS_BLOCK_SIZE/sizeof(u16); } } ntfs-3g-2026.2.25/libntfs-3g/ioctl.c0000664000175000017500000002411215152260173012226 /** * ioctl.c - Processing of ioctls * * This module is part of ntfs-3g library * * Copyright (c) 2014-2019 Jean-Pierre Andre * Copyright (c) 2014 Red Hat, Inc. * * This program/include file 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/include file 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 */ #include "config.h" #ifdef HAVE_STDIO_H #include #endif #ifdef HAVE_INTTYPES_H #include #endif #ifdef HAVE_STRING_H #include #endif #ifdef HAVE_ERRNO_H #include #endif #ifdef HAVE_FCNTL_H #include #endif #ifdef HAVE_UNISTD_H #include #endif #ifdef HAVE_STDLIB_H #include #endif #ifdef HAVE_LIMITS_H #include #endif #include #ifdef HAVE_SYS_TYPES_H #include #endif #ifdef MAJOR_IN_MKDEV #include #endif #ifdef MAJOR_IN_SYSMACROS #include #endif #ifdef HAVE_SYS_STAT_H #include #endif #ifdef HAVE_LINUX_FS_H #include #endif #include "compat.h" #include "debug.h" #include "bitmap.h" #include "attrib.h" #include "inode.h" #include "layout.h" #include "volume.h" #include "index.h" #include "logging.h" #include "ntfstime.h" #include "unistr.h" #include "dir.h" #include "security.h" #include "ioctl.h" #include "misc.h" #if defined(FITRIM) && defined(BLKDISCARD) /* Issue a TRIM request to the underlying device for the given clusters. */ static int fstrim_clusters(ntfs_volume *vol, LCN lcn, s64 length) { struct ntfs_device *dev = vol->dev; uint64_t range[2]; ntfs_log_debug("fstrim_clusters: %lld length %lld\n", (long long) lcn, (long long) length); range[0] = lcn << vol->cluster_size_bits; range[1] = length << vol->cluster_size_bits; if (dev->d_ops->ioctl(dev, BLKDISCARD, range) == -1) { ntfs_log_debug("fstrim_one_cluster: ioctl failed: %m\n"); return -errno; } return 0; } static int read_line(const char *path, char *line, size_t max_bytes) { FILE *fp; fp = fopen(path, "r"); if (fp == NULL) return -errno; if (fgets(line, max_bytes, fp) == NULL) { int ret = -EIO; /* fgets doesn't set errno */ fclose(fp); return ret; } fclose (fp); return 0; } static int read_u64(const char *path, u64 *n) { char line[64]; int ret; ret = read_line(path, line, sizeof line); if (ret) return ret; if (sscanf(line, "%" SCNu64, n) != 1) return -EINVAL; return 0; } /* Find discard limits for current backing device. */ static int fstrim_limits(ntfs_volume *vol, u64 *discard_alignment, u64 *discard_granularity, u64 *discard_max_bytes) { struct stat statbuf; char path1[40]; /* holds "/sys/dev/block/%d:%d" */ char path2[40 + sizeof(path1)]; /* less than 40 bytes more than path1 */ int ret; /* Stat the backing device. Caller has ensured it is a block device. */ if (stat(vol->dev->d_name, &statbuf) == -1) { ntfs_log_debug("fstrim_limits: could not stat %s\n", vol->dev->d_name); return -errno; } /* For whole devices, * /sys/dev/block/MAJOR:MINOR/discard_alignment * /sys/dev/block/MAJOR:MINOR/queue/discard_granularity * /sys/dev/block/MAJOR:MINOR/queue/discard_max_bytes * will exist. * For partitions, we also need to check the parent device: * /sys/dev/block/MAJOR:MINOR/../queue/discard_granularity * /sys/dev/block/MAJOR:MINOR/../queue/discard_max_bytes */ snprintf(path1, sizeof path1, "/sys/dev/block/%d:%d", major(statbuf.st_rdev), minor(statbuf.st_rdev)); snprintf(path2, sizeof path2, "%s/discard_alignment", path1); ret = read_u64(path2, discard_alignment); if (ret) { if (ret != -ENOENT) return ret; else /* We would expect this file to exist on all * modern kernels. But for the sake of very * old kernels: */ goto not_found; } snprintf(path2, sizeof path2, "%s/queue/discard_granularity", path1); ret = read_u64(path2, discard_granularity); if (ret) { if (ret != -ENOENT) return ret; else { snprintf(path2, sizeof path2, "%s/../queue/discard_granularity", path1); ret = read_u64(path2, discard_granularity); if (ret) { if (ret != -ENOENT) return ret; else goto not_found; } } } snprintf(path2, sizeof path2, "%s/queue/discard_max_bytes", path1); ret = read_u64(path2, discard_max_bytes); if (ret) { if (ret != -ENOENT) return ret; else { snprintf(path2, sizeof path2, "%s/../queue/discard_max_bytes", path1); ret = read_u64(path2, discard_max_bytes); if (ret) { if (ret != -ENOENT) return ret; else goto not_found; } } } return 0; not_found: /* If we reach here then we didn't find the device. This is * not an error, but set discard_max_bytes = 0 to indicate * that discard is not available. */ *discard_alignment = 0; *discard_granularity = 0; *discard_max_bytes = 0; return 0; } static inline LCN align_up(ntfs_volume *vol, LCN lcn, u64 granularity) { u64 aligned; aligned = (lcn << vol->cluster_size_bits) + granularity - 1; aligned -= aligned % granularity; return (aligned >> vol->cluster_size_bits); } static inline u64 align_down(ntfs_volume *vol, u64 count, u64 granularity) { u64 aligned; aligned = count << vol->cluster_size_bits; aligned -= aligned % granularity; return (aligned >> vol->cluster_size_bits); } #define FSTRIM_BUFSIZ 4096 /* Trim the filesystem. * * Free blocks between 'start' and 'start+len-1' (both byte offsets) * are found and TRIM requests are sent to the block device. 'minlen' * is the minimum continguous free range to discard. */ static int fstrim(ntfs_volume *vol, void *data, u64 *trimmed) { struct fstrim_range *range = data; u64 start = range->start; u64 len = range->len; u64 minlen = range->minlen; u64 discard_alignment, discard_granularity, discard_max_bytes; u8 *buf = NULL; LCN start_buf; int ret; ntfs_log_debug("fstrim: start=%llu len=%llu minlen=%llu\n", (unsigned long long) start, (unsigned long long) len, (unsigned long long) minlen); *trimmed = 0; /* Fail if user tries to use the fstrim -o/-l/-m options. * XXX We could fix these limitations in future. */ if (start != 0 || len != (uint64_t)-1) { ntfs_log_error("fstrim: setting start or length is not supported\n"); return -EINVAL; } if (minlen > vol->cluster_size) { ntfs_log_error("fstrim: minlen > cluster size is not supported\n"); return -EINVAL; } /* Only block devices are supported. It would be possible to * support backing files (ie. without using loop) but the * ioctls used to punch holes in files are completely * different. */ if (!NDevBlock(vol->dev)) { ntfs_log_error("fstrim: not supported for non-block-device\n"); return -EOPNOTSUPP; } ret = fstrim_limits(vol, &discard_alignment, &discard_granularity, &discard_max_bytes); if (ret) return ret; if (discard_alignment != 0) { ntfs_log_error("fstrim: backing device is not aligned for discards\n"); return -EOPNOTSUPP; } if (discard_max_bytes == 0) { ntfs_log_error("fstrim: backing device does not support discard (discard_max_bytes == 0)\n"); return -EOPNOTSUPP; } /* Sync the device before doing anything. */ ret = ntfs_device_sync(vol->dev); if (ret) return ret; /* Read through the bitmap. */ buf = ntfs_malloc(FSTRIM_BUFSIZ); if (buf == NULL) return -errno; for (start_buf = 0; start_buf < vol->nr_clusters; start_buf += FSTRIM_BUFSIZ * 8) { s64 count; s64 br; LCN end_buf, start_lcn; /* start_buf is LCN of first cluster in the current buffer. * end_buf is LCN of last cluster + 1 in the current buffer. */ end_buf = start_buf + FSTRIM_BUFSIZ*8; if (end_buf > vol->nr_clusters) end_buf = vol->nr_clusters; count = (end_buf - start_buf) / 8; br = ntfs_attr_pread(vol->lcnbmp_na, start_buf/8, count, buf); if (br != count) { if (br >= 0) ret = -EIO; else ret = -errno; goto free_out; } /* Trim the clusters in large as possible blocks, but * not larger than discard_max_bytes, and compatible * with the supported trim granularity. */ for (start_lcn = start_buf; start_lcn < end_buf; ++start_lcn) { if (!ntfs_bit_get(buf, start_lcn-start_buf)) { LCN end_lcn; LCN aligned_lcn; u64 aligned_count; /* Cluster 'start_lcn' is not in use, * find end of this run. */ end_lcn = start_lcn+1; while (end_lcn < end_buf && (u64) (end_lcn-start_lcn) << vol->cluster_size_bits < discard_max_bytes && !ntfs_bit_get(buf, end_lcn-start_buf)) end_lcn++; aligned_lcn = align_up(vol, start_lcn, discard_granularity); if (aligned_lcn >= end_lcn) aligned_count = 0; else { aligned_count = align_down(vol, end_lcn - aligned_lcn, discard_granularity); } if (aligned_count) { ret = fstrim_clusters(vol, aligned_lcn, aligned_count); if (ret) goto free_out; *trimmed += aligned_count << vol->cluster_size_bits; } start_lcn = end_lcn-1; } } } ret = 0; free_out: free(buf); return ret; } #endif /* FITRIM && BLKDISCARD */ int ntfs_ioctl(ntfs_inode *ni, unsigned long cmd, void *arg __attribute__((unused)), unsigned int flags __attribute__((unused)), void *data) { int ret = 0; switch (cmd) { #if defined(FITRIM) && defined(BLKDISCARD) case FITRIM: if (!ni || !data) ret = -EINVAL; else { u64 trimmed; struct fstrim_range *range = (struct fstrim_range*)data; ret = fstrim(ni->vol, data, &trimmed); range->len = trimmed; } break; #else #warning Trimming not supported : FITRIM or BLKDISCARD not defined #endif default : ret = -EINVAL; break; } return (ret); } ntfs-3g-2026.2.25/libntfs-3g/libntfs-3g.pc.in0000664000175000017500000000036615152260173013656 prefix=@prefix@ exec_prefix=@exec_prefix@ libdir=@libdir@ includedir=@includedir@ Name: libntfs-3g Description: NTFS-3G Read/Write Driver Library Version: @PACKAGE_VERSION@ Cflags: -I${includedir} Libs: @LIBFUSE_LITE_LIBS@ -L${libdir} -lntfs-3g ntfs-3g-2026.2.25/libntfs-3g/bootsect.c0000664000175000017500000002520015152260173012735 /** * bootsect.c - Boot sector handling code. Originated from the Linux-NTFS project. * * Copyright (c) 2000-2006 Anton Altaparmakov * Copyright (c) 2003-2008 Szabolcs Szakacsits * Copyright (c) 2005 Yura Pakhuchiy * * This program/include file 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/include file 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_STDIO_H #include #endif #ifdef HAVE_STDLIB_H #include #endif #ifdef HAVE_STRING_H #include #endif #ifdef HAVE_ERRNO_H #include #endif #include "param.h" #include "compat.h" #include "bootsect.h" #include "debug.h" #include "logging.h" /** * ntfs_boot_sector_is_ntfs - check if buffer contains a valid ntfs boot sector * @b: buffer containing putative boot sector to analyze * @silent: if zero, output progress messages to stderr * * Check if the buffer @b contains a valid ntfs boot sector. The buffer @b * must be at least 512 bytes in size. * * If @silent is zero, output progress messages to stderr. Otherwise, do not * output any messages (except when configured with --enable-debug in which * case warning/debug messages may be displayed). * * Return TRUE if @b contains a valid ntfs boot sector and FALSE if not. */ BOOL ntfs_boot_sector_is_ntfs(NTFS_BOOT_SECTOR *b) { u32 i; BOOL ret = FALSE; u16 sectors_per_cluster; ntfs_log_debug("Beginning bootsector check.\n"); ntfs_log_debug("Checking OEMid, NTFS signature.\n"); if (b->oem_id != const_cpu_to_le64(0x202020205346544eULL)) { /* "NTFS " */ ntfs_log_error("NTFS signature is missing.\n"); goto not_ntfs; } ntfs_log_debug("Checking bytes per sector.\n"); if (le16_to_cpu(b->bpb.bytes_per_sector) < 256 || le16_to_cpu(b->bpb.bytes_per_sector) > 4096) { ntfs_log_error("Unexpected bytes per sector value (%d).\n", le16_to_cpu(b->bpb.bytes_per_sector)); goto not_ntfs; } ntfs_log_debug("Checking sectors per cluster.\n"); switch (b->bpb.sectors_per_cluster) { case 1: case 2: case 4: case 8: case 16: case 32: case 64: case 128: break; default: if ((b->bpb.sectors_per_cluster < 240) || (b->bpb.sectors_per_cluster > 253)) { if (b->bpb.sectors_per_cluster > 128) ntfs_log_error("Unexpected sectors" " per cluster value (code 0x%x)\n", b->bpb.sectors_per_cluster); else ntfs_log_error("Unexpected sectors" " per cluster value (%d).\n", b->bpb.sectors_per_cluster); goto not_ntfs; } } ntfs_log_debug("Checking cluster size.\n"); if (b->bpb.sectors_per_cluster > 128) sectors_per_cluster = 1 << (256 - b->bpb.sectors_per_cluster); else sectors_per_cluster = b->bpb.sectors_per_cluster; i = (u32)le16_to_cpu(b->bpb.bytes_per_sector) * sectors_per_cluster; if (i > NTFS_MAX_CLUSTER_SIZE) { ntfs_log_error("Unexpected cluster size (%d).\n", i); goto not_ntfs; } ntfs_log_debug("Checking reserved fields are zero.\n"); if (le16_to_cpu(b->bpb.reserved_sectors) || le16_to_cpu(b->bpb.root_entries) || le16_to_cpu(b->bpb.sectors) || le16_to_cpu(b->bpb.sectors_per_fat) || le32_to_cpu(b->bpb.large_sectors) || b->bpb.fats) { ntfs_log_error("Reserved fields aren't zero " "(%d, %d, %d, %d, %d, %d).\n", le16_to_cpu(b->bpb.reserved_sectors), le16_to_cpu(b->bpb.root_entries), le16_to_cpu(b->bpb.sectors), le16_to_cpu(b->bpb.sectors_per_fat), le32_to_cpu(b->bpb.large_sectors), b->bpb.fats); goto not_ntfs; } ntfs_log_debug("Checking clusters per mft record.\n"); if ((u8)b->clusters_per_mft_record < 0xe1 || (u8)b->clusters_per_mft_record > 0xf7) { switch (b->clusters_per_mft_record) { case 1: case 2: case 4: case 8: case 0x10: case 0x20: case 0x40: break; default: ntfs_log_error("Unexpected clusters per mft record " "(%d).\n", b->clusters_per_mft_record); goto not_ntfs; } } ntfs_log_debug("Checking clusters per index block.\n"); if ((u8)b->clusters_per_index_record < 0xe1 || (u8)b->clusters_per_index_record > 0xf7) { switch (b->clusters_per_index_record) { case 1: case 2: case 4: case 8: case 0x10: case 0x20: case 0x40: break; default: ntfs_log_error("Unexpected clusters per index record " "(%d).\n", b->clusters_per_index_record); goto not_ntfs; } } /* MFT and MFTMirr may not overlap the boot sector or be the same */ if (((s64)sle64_to_cpu(b->mft_lcn) <= 0) || ((s64)sle64_to_cpu(b->mftmirr_lcn) <= 0) || (b->mft_lcn == b->mftmirr_lcn)) { ntfs_log_error("Invalid location of MFT or MFTMirr.\n"); goto not_ntfs; } if (b->end_of_sector_marker != const_cpu_to_le16(0xaa55)) ntfs_log_debug("Warning: Bootsector has invalid end of sector " "marker.\n"); ntfs_log_debug("Bootsector check completed successfully.\n"); ret = TRUE; not_ntfs: return ret; } static const char *last_sector_error = "HINTS: Either the volume is a RAID/LDM but it wasn't setup yet,\n" " or it was not setup correctly (e.g. by not using mdadm --build ...),\n" " or a wrong device is tried to be mounted,\n" " or the partition table is corrupt (partition is smaller than NTFS),\n" " or the NTFS boot sector is corrupt (NTFS size is not valid).\n"; /** * ntfs_boot_sector_parse - setup an ntfs volume from an ntfs boot sector * @vol: ntfs_volume to setup * @bs: buffer containing ntfs boot sector to parse * * Parse the ntfs bootsector @bs and setup the ntfs volume @vol with the * obtained values. * * Return 0 on success or -1 on error with errno set to the error code EINVAL. */ int ntfs_boot_sector_parse(ntfs_volume *vol, const NTFS_BOOT_SECTOR *bs) { s64 sectors; u16 sectors_per_cluster; s8 c; /* We return -1 with errno = EINVAL on error. */ errno = EINVAL; vol->sector_size = le16_to_cpu(bs->bpb.bytes_per_sector); vol->sector_size_bits = ffs(vol->sector_size) - 1; ntfs_log_debug("SectorSize = 0x%x\n", vol->sector_size); ntfs_log_debug("SectorSizeBits = %u\n", vol->sector_size_bits); /* * The bounds checks on mft_lcn and mft_mirr_lcn (i.e. them being * below or equal the number_of_clusters) really belong in the * ntfs_boot_sector_is_ntfs but in this way we can just do this once. */ if (bs->bpb.sectors_per_cluster > 128) sectors_per_cluster = 1 << (256 - bs->bpb.sectors_per_cluster); else sectors_per_cluster = bs->bpb.sectors_per_cluster; ntfs_log_debug("SectorsPerCluster = 0x%x\n", sectors_per_cluster); if (sectors_per_cluster & (sectors_per_cluster - 1)) { ntfs_log_error("sectors_per_cluster (%d) is not a power of 2." "\n", sectors_per_cluster); return -1; } sectors = sle64_to_cpu(bs->number_of_sectors); ntfs_log_debug("NumberOfSectors = %lld\n", (long long)sectors); if (!sectors) { ntfs_log_error("Volume size is set to zero.\n"); return -1; } if (vol->dev->d_ops->seek(vol->dev, (sectors - 1) << vol->sector_size_bits, SEEK_SET) == -1) { ntfs_log_perror("Failed to read last sector (%lld)", (long long)(sectors - 1)); ntfs_log_error("%s", last_sector_error); return -1; } vol->nr_clusters = sectors >> (ffs(sectors_per_cluster) - 1); vol->mft_lcn = sle64_to_cpu(bs->mft_lcn); vol->mftmirr_lcn = sle64_to_cpu(bs->mftmirr_lcn); ntfs_log_debug("MFT LCN = %lld\n", (long long)vol->mft_lcn); ntfs_log_debug("MFTMirr LCN = %lld\n", (long long)vol->mftmirr_lcn); if ((vol->mft_lcn < 0 || vol->mft_lcn > vol->nr_clusters) || (vol->mftmirr_lcn < 0 || vol->mftmirr_lcn > vol->nr_clusters)) { ntfs_log_error("$MFT LCN (%lld) or $MFTMirr LCN (%lld) is " "greater than the number of clusters (%lld).\n", (long long)vol->mft_lcn, (long long)vol->mftmirr_lcn, (long long)vol->nr_clusters); return -1; } vol->cluster_size = sectors_per_cluster * vol->sector_size; if (vol->cluster_size & (vol->cluster_size - 1)) { ntfs_log_error("cluster_size (%d) is not a power of 2.\n", vol->cluster_size); return -1; } vol->cluster_size_bits = ffs(vol->cluster_size) - 1; /* * Need to get the clusters per mft record and handle it if it is * negative. Then calculate the mft_record_size. A value of 0x80 is * illegal, thus signed char is actually ok! */ c = bs->clusters_per_mft_record; ntfs_log_debug("ClusterSize = 0x%x\n", (unsigned)vol->cluster_size); ntfs_log_debug("ClusterSizeBits = %u\n", vol->cluster_size_bits); ntfs_log_debug("ClustersPerMftRecord = 0x%x\n", c); /* * When clusters_per_mft_record is negative, it means that it is to * be taken to be the negative base 2 logarithm of the mft_record_size * min bytes. Then: * mft_record_size = 2^(-clusters_per_mft_record) bytes. */ if (c < 0) vol->mft_record_size = 1 << -c; else vol->mft_record_size = c << vol->cluster_size_bits; if (vol->mft_record_size & (vol->mft_record_size - 1)) { ntfs_log_error("mft_record_size (%d) is not a power of 2.\n", vol->mft_record_size); return -1; } vol->mft_record_size_bits = ffs(vol->mft_record_size) - 1; ntfs_log_debug("MftRecordSize = 0x%x\n", (unsigned)vol->mft_record_size); ntfs_log_debug("MftRecordSizeBits = %u\n", vol->mft_record_size_bits); /* Same as above for INDX record. */ c = bs->clusters_per_index_record; ntfs_log_debug("ClustersPerINDXRecord = 0x%x\n", c); if (c < 0) vol->indx_record_size = 1 << -c; else vol->indx_record_size = c << vol->cluster_size_bits; vol->indx_record_size_bits = ffs(vol->indx_record_size) - 1; ntfs_log_debug("INDXRecordSize = 0x%x\n", (unsigned)vol->indx_record_size); ntfs_log_debug("INDXRecordSizeBits = %u\n", vol->indx_record_size_bits); /* * Work out the size of the MFT mirror in number of mft records. If the * cluster size is less than or equal to the size taken by four mft * records, the mft mirror stores the first four mft records. If the * cluster size is bigger than the size taken by four mft records, the * mft mirror contains as many mft records as will fit into one * cluster. */ if (vol->cluster_size <= 4 * vol->mft_record_size) vol->mftmirr_size = 4; else vol->mftmirr_size = vol->cluster_size / vol->mft_record_size; return 0; } ntfs-3g-2026.2.25/libntfs-3g/efs.c0000664000175000017500000002552015152260173011675 /** * efs.c - Limited processing of encrypted files * * This module is part of ntfs-3g library * * Copyright (c) 2009 Martin Bene * Copyright (c) 2009-2010 Jean-Pierre Andre * * This program/include file 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/include file 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_STDLIB_H #include #endif #ifdef HAVE_ERRNO_H #include #endif #ifdef HAVE_STRING_H #include #endif #ifdef HAVE_SYS_STAT_H #include #endif #ifdef HAVE_SYS_SYSMACROS_H #include #endif #include "types.h" #include "debug.h" #include "attrib.h" #include "inode.h" #include "dir.h" #include "efs.h" #include "index.h" #include "logging.h" #include "misc.h" #include "efs.h" #include "xattrs.h" static ntfschar logged_utility_stream_name[] = { const_cpu_to_le16('$'), const_cpu_to_le16('E'), const_cpu_to_le16('F'), const_cpu_to_le16('S'), const_cpu_to_le16(0) } ; /* * Get the ntfs EFS info into an extended attribute */ int ntfs_get_efs_info(ntfs_inode *ni, char *value, size_t size) { EFS_ATTR_HEADER *efs_info; s64 attr_size = 0; if (ni) { if (ni->flags & FILE_ATTR_ENCRYPTED) { efs_info = (EFS_ATTR_HEADER*)ntfs_attr_readall(ni, AT_LOGGED_UTILITY_STREAM,(ntfschar*)NULL, 0, &attr_size); if (efs_info && (le32_to_cpu(efs_info->length) == attr_size)) { if (attr_size <= (s64)size) { if (value) memcpy(value,efs_info,attr_size); else { errno = EFAULT; attr_size = 0; } } else if (size) { errno = ERANGE; attr_size = 0; } free (efs_info); } else { if (efs_info) { free(efs_info); ntfs_log_error("Bad efs_info for inode %lld\n", (long long)ni->mft_no); } else { ntfs_log_error("Could not get efsinfo" " for inode %lld\n", (long long)ni->mft_no); } errno = EIO; attr_size = 0; } } else { errno = ENODATA; ntfs_log_trace("Inode %lld is not encrypted\n", (long long)ni->mft_no); } } return (attr_size ? (int)attr_size : -errno); } /* * Fix all encrypted AT_DATA attributes of an inode * * The fix may require making an attribute non resident, which * requires more space in the MFT record, and may cause some * attribute to be expelled and the full record to be reorganized. * When this happens, the search for data attributes has to be * reinitialized. * * Returns zero if successful. * -1 if there is a problem. */ static int fixup_loop(ntfs_inode *ni) { ntfs_attr_search_ctx *ctx; ntfs_attr *na; ATTR_RECORD *a; BOOL restart; int cnt; int maxcnt; int res = 0; maxcnt = 0; do { restart = FALSE; ctx = ntfs_attr_get_search_ctx(ni, NULL); if (!ctx) { ntfs_log_error("Failed to get ctx for efs\n"); res = -1; } cnt = 0; while (!restart && !res && !ntfs_attr_lookup(AT_DATA, NULL, 0, CASE_SENSITIVE, 0, NULL, 0, ctx)) { cnt++; a = ctx->attr; na = ntfs_attr_open(ctx->ntfs_ino, AT_DATA, (ntfschar*)((u8*)a + le16_to_cpu(a->name_offset)), a->name_length); if (!na) { ntfs_log_error("can't open DATA Attribute\n"); res = -1; } if (na && !(ctx->attr->flags & ATTR_IS_ENCRYPTED)) { if (!NAttrNonResident(na) && ntfs_attr_make_non_resident(na, ctx)) { /* * ntfs_attr_make_non_resident fails if there * is not enough space in the MFT record. * When this happens, force making non-resident * so that some other attribute is expelled. */ if (ntfs_attr_force_non_resident(na)) { res = -1; } else { /* make sure there is some progress */ if (cnt <= maxcnt) { errno = EIO; ntfs_log_error("Multiple failure" " making non resident\n"); res = -1; } else { ntfs_attr_put_search_ctx(ctx); ctx = (ntfs_attr_search_ctx*)NULL; restart = TRUE; maxcnt = cnt; } } } if (!restart && !res && ntfs_efs_fixup_attribute(ctx, na)) { ntfs_log_error("Error in efs fixup of AT_DATA Attribute\n"); res = -1; } } if (na) ntfs_attr_close(na); } } while (restart && !res); if (ctx) ntfs_attr_put_search_ctx(ctx); return (res); } /* * Set the efs data from an extended attribute * Warning : the new data is not checked * Returns 0, or -1 if there is a problem */ int ntfs_set_efs_info(ntfs_inode *ni, const char *value, size_t size, int flags) { int res; int written; ntfs_attr *na; const EFS_ATTR_HEADER *info_header; res = 0; if (ni && value && size) { if (ni->flags & (FILE_ATTR_ENCRYPTED | FILE_ATTR_COMPRESSED)) { if (ni->flags & FILE_ATTR_ENCRYPTED) { ntfs_log_trace("Inode %lld already encrypted\n", (long long)ni->mft_no); errno = EEXIST; } else { /* * Possible problem : if encrypted file was * restored in a compressed directory, it was * restored as compressed. * TODO : decompress first. */ ntfs_log_error("Inode %lld cannot be encrypted and compressed\n", (long long)ni->mft_no); errno = EIO; } return -1; } info_header = (const EFS_ATTR_HEADER*)value; /* make sure we get a likely efsinfo */ if (le32_to_cpu(info_header->length) != size) { errno = EINVAL; return (-1); } if (!ntfs_attr_exist(ni,AT_LOGGED_UTILITY_STREAM, (ntfschar*)NULL,0)) { if (!(flags & XATTR_REPLACE)) { /* * no logged_utility_stream attribute : add one, * apparently, this does not feed the new value in */ res = ntfs_attr_add(ni,AT_LOGGED_UTILITY_STREAM, logged_utility_stream_name,4, (u8*)NULL,(s64)size); } else { errno = ENODATA; res = -1; } } else { errno = EEXIST; res = -1; } if (!res) { /* * open and update the existing efs data */ na = ntfs_attr_open(ni, AT_LOGGED_UTILITY_STREAM, logged_utility_stream_name, 4); if (na) { /* resize attribute */ res = ntfs_attr_truncate(na, (s64)size); /* overwrite value if any */ if (!res && value) { written = (int)ntfs_attr_pwrite(na, (s64)0, (s64)size, value); if (written != (s64)size) { ntfs_log_error("Failed to " "update efs data\n"); errno = EIO; res = -1; } } ntfs_attr_close(na); } else res = -1; } if (!res) { /* Don't handle AT_DATA Attribute(s) if inode is a directory */ if (!(ni->mrec->flags & MFT_RECORD_IS_DIRECTORY)) { /* iterate over AT_DATA attributes */ /* set encrypted flag, truncate attribute to match padding bytes */ if (fixup_loop(ni)) return -1; } ni->flags |= FILE_ATTR_ENCRYPTED; NInoSetDirty(ni); NInoFileNameSetDirty(ni); } } else { errno = EINVAL; res = -1; } return (res ? -1 : 0); } /* * Fixup raw encrypted AT_DATA Attribute * read padding length from last two bytes * truncate attribute, make non-resident, * set data size to match padding length * set ATTR_IS_ENCRYPTED flag on attribute * * Return 0 if successful * -1 if failed (errno tells why) */ int ntfs_efs_fixup_attribute(ntfs_attr_search_ctx *ctx, ntfs_attr *na) { s64 newsize; s64 oldsize; le16 appended_bytes; u16 padding_length; ntfs_inode *ni; BOOL close_ctx = FALSE; if (!na) { ntfs_log_error("no na specified for efs_fixup_attribute\n"); goto err_out; } if (!ctx) { ctx = ntfs_attr_get_search_ctx(na->ni, NULL); if (!ctx) { ntfs_log_error("Failed to get ctx for efs\n"); goto err_out; } close_ctx = TRUE; if (ntfs_attr_lookup(AT_DATA, na->name, na->name_len, CASE_SENSITIVE, 0, NULL, 0, ctx)) { ntfs_log_error("attr lookup for AT_DATA attribute failed in efs fixup\n"); goto err_out; } } else { if (!NAttrNonResident(na)) { ntfs_log_error("Cannot make non resident" " when a context has been allocated\n"); goto err_out; } } /* no extra bytes are added to void attributes */ oldsize = na->data_size; if (oldsize) { /* make sure size is valid for a raw encrypted stream */ if ((oldsize & 511) != 2) { ntfs_log_error("Bad raw encrypted stream\n"); goto err_out; } /* read padding length from last two bytes of attribute */ if (ntfs_attr_pread(na, oldsize - 2, 2, &appended_bytes) != 2) { ntfs_log_error("Error reading padding length\n"); goto err_out; } padding_length = le16_to_cpu(appended_bytes); if (padding_length > 511 || padding_length > na->data_size-2) { errno = EINVAL; ntfs_log_error("invalid padding length %d for data_size %lld\n", padding_length, (long long)oldsize); goto err_out; } newsize = oldsize - padding_length - 2; /* * truncate attribute to possibly free clusters allocated * for the last two bytes, but do not truncate to new size * to avoid losing useful data */ if (ntfs_attr_truncate(na, oldsize - 2)) { ntfs_log_error("Error truncating attribute\n"); goto err_out; } } else newsize = 0; /* * Encrypted AT_DATA Attributes MUST be non-resident * This has to be done after the attribute is resized, as * resizing down to zero may cause the attribute to be made * resident. */ if (!NAttrNonResident(na) && ntfs_attr_make_non_resident(na, ctx)) { if (!close_ctx || ntfs_attr_force_non_resident(na)) { ntfs_log_error("Error making DATA attribute non-resident\n"); goto err_out; } else { /* * must reinitialize context after forcing * non-resident. We need a context for updating * the state, and at this point, we are sure * the context is not used elsewhere. */ ntfs_attr_reinit_search_ctx(ctx); if (ntfs_attr_lookup(AT_DATA, na->name, na->name_len, CASE_SENSITIVE, 0, NULL, 0, ctx)) { ntfs_log_error("attr lookup for AT_DATA attribute failed in efs fixup\n"); goto err_out; } } } ni = na->ni; if (!na->name_len) { ni->data_size = newsize; ni->allocated_size = na->allocated_size; } NInoSetDirty(ni); NInoFileNameSetDirty(ni); ctx->attr->data_size = cpu_to_sle64(newsize); if (sle64_to_cpu(ctx->attr->initialized_size) > newsize) ctx->attr->initialized_size = ctx->attr->data_size; ctx->attr->flags |= ATTR_IS_ENCRYPTED; if (close_ctx) ntfs_attr_put_search_ctx(ctx); return (0); err_out: if (close_ctx && ctx) ntfs_attr_put_search_ctx(ctx); return (-1); } ntfs-3g-2026.2.25/libntfs-3g/mft.c0000664000175000017500000017511215152260173011711 /** * mft.c - Mft record handling code. Originated from the Linux-NTFS project. * * Copyright (c) 2000-2004 Anton Altaparmakov * Copyright (c) 2004-2005 Richard Russon * Copyright (c) 2004-2008 Szabolcs Szakacsits * Copyright (c) 2005 Yura Pakhuchiy * Copyright (c) 2014-2021 Jean-Pierre Andre * * This program/include file 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/include file 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_STDLIB_H #include #endif #ifdef HAVE_STDIO_H #include #endif #ifdef HAVE_ERRNO_H #include #endif #ifdef HAVE_STRING_H #include #endif #ifdef HAVE_LIMITS_H #include #endif #include #include "compat.h" #include "types.h" #include "device.h" #include "debug.h" #include "bitmap.h" #include "attrib.h" #include "inode.h" #include "volume.h" #include "layout.h" #include "lcnalloc.h" #include "mft.h" #include "logging.h" #include "misc.h" /** * ntfs_mft_records_read - read records from the mft from disk * @vol: volume to read from * @mref: starting mft record number to read * @count: number of mft records to read * @b: output data buffer * * Read @count mft records starting at @mref from volume @vol into buffer * @b. Return 0 on success or -1 on error, with errno set to the error * code. * * If any of the records exceed the initialized size of the $MFT/$DATA * attribute, i.e. they cannot possibly be allocated mft records, assume this * is a bug and return error code ESPIPE. * * The read mft records are mst deprotected and are hence ready to use. The * caller should check each record with is_baad_record() in case mst * deprotection failed. * * NOTE: @b has to be at least of size @count * vol->mft_record_size. */ int ntfs_mft_records_read(const ntfs_volume *vol, const MFT_REF mref, const s64 count, MFT_RECORD *b) { s64 br; VCN m; ntfs_log_trace("inode %llu\n", (unsigned long long)MREF(mref)); if (!vol || !vol->mft_na || !b || count < 0) { errno = EINVAL; ntfs_log_perror("%s: b=%p count=%lld mft=%llu", __FUNCTION__, b, (long long)count, (unsigned long long)MREF(mref)); return -1; } m = MREF(mref); /* Refuse to read non-allocated mft records. */ if (m + count > vol->mft_na->initialized_size >> vol->mft_record_size_bits) { errno = ESPIPE; ntfs_log_perror("Trying to read non-allocated mft records " "(%lld > %lld)", (long long)m + count, (long long)vol->mft_na->initialized_size >> vol->mft_record_size_bits); return -1; } br = ntfs_attr_mst_pread(vol->mft_na, m << vol->mft_record_size_bits, count, vol->mft_record_size, b); if (br != count) { if (br != -1) errno = EIO; ntfs_log_perror("Failed to read of MFT, mft=%llu count=%lld " "br=%lld", (long long)m, (long long)count, (long long)br); return -1; } return 0; } /** * ntfs_mft_records_write - write mft records to disk * @vol: volume to write to * @mref: starting mft record number to write * @count: number of mft records to write * @b: data buffer containing the mft records to write * * Write @count mft records starting at @mref from data buffer @b to volume * @vol. Return 0 on success or -1 on error, with errno set to the error code. * * If any of the records exceed the initialized size of the $MFT/$DATA * attribute, i.e. they cannot possibly be allocated mft records, assume this * is a bug and return error code ESPIPE. * * Before the mft records are written, they are mst protected. After the write, * they are deprotected again, thus resulting in an increase in the update * sequence number inside the data buffer @b. * * If any mft records are written which are also represented in the mft mirror * $MFTMirr, we make a copy of the relevant parts of the data buffer @b into a * temporary buffer before we do the actual write. Then if at least one mft * record was successfully written, we write the appropriate mft records from * the copied buffer to the mft mirror, too. */ int ntfs_mft_records_write(const ntfs_volume *vol, const MFT_REF mref, const s64 count, MFT_RECORD *b) { s64 bw; VCN m; void *bmirr = NULL; int cnt = 0, res = 0; if (!vol || !vol->mft_na || vol->mftmirr_size <= 0 || !b || count < 0) { errno = EINVAL; return -1; } m = MREF(mref); /* Refuse to write non-allocated mft records. */ if (m + count > vol->mft_na->initialized_size >> vol->mft_record_size_bits) { errno = ESPIPE; ntfs_log_perror("Trying to write non-allocated mft records " "(%lld > %lld)", (long long)m + count, (long long)vol->mft_na->initialized_size >> vol->mft_record_size_bits); return -1; } if (m < vol->mftmirr_size) { if (!vol->mftmirr_na) { errno = EINVAL; return -1; } cnt = vol->mftmirr_size - m; if (cnt > count) cnt = count; if ((m + cnt) > vol->mftmirr_na->initialized_size >> vol->mft_record_size_bits) { errno = ESPIPE; ntfs_log_perror("Trying to write non-allocated mftmirr" " records (%lld > %lld)", (long long)m + cnt, (long long)vol->mftmirr_na->initialized_size >> vol->mft_record_size_bits); return -1; } bmirr = ntfs_malloc(cnt * vol->mft_record_size); if (!bmirr) return -1; memcpy(bmirr, b, cnt * vol->mft_record_size); } bw = ntfs_attr_mst_pwrite(vol->mft_na, m << vol->mft_record_size_bits, count, vol->mft_record_size, b); if (bw != count) { if (bw != -1) errno = EIO; if (bw >= 0) ntfs_log_debug("Error: partial write while writing $Mft " "record(s)!\n"); else ntfs_log_perror("Error writing $Mft record(s)"); res = errno; } if (bmirr && bw > 0) { if (bw < cnt) cnt = bw; bw = ntfs_attr_mst_pwrite(vol->mftmirr_na, m << vol->mft_record_size_bits, cnt, vol->mft_record_size, bmirr); if (bw != cnt) { if (bw != -1) errno = EIO; ntfs_log_debug("Error: failed to sync $MFTMirr! Run " "chkdsk.\n"); res = errno; } } free(bmirr); if (!res) return res; errno = res; return -1; } /* * Check the consistency of an MFT record * * Make sure its general fields are safe, then examine all its * attributes and apply generic checks to them. * The attribute checks are skipped when a record is being read in * order to collect its sequence number for creating a new record. * * Returns 0 if the checks are successful * -1 with errno = EIO otherwise */ int ntfs_mft_record_check(const ntfs_volume *vol, const MFT_REF mref, MFT_RECORD *m) { ATTR_RECORD *a; ATTR_TYPES previous_type; int ret = -1; u32 offset; s32 space; if (!ntfs_is_file_record(m->magic)) { if (!NVolNoFixupWarn(vol)) ntfs_log_error("Record %llu has no FILE magic (0x%x)\n", (unsigned long long)MREF(mref), (int)le32_to_cpu(*(le32*)m)); goto err_out; } if (le32_to_cpu(m->bytes_allocated) != vol->mft_record_size) { ntfs_log_error("Record %llu has corrupt allocation size " "(%u <> %u)\n", (unsigned long long)MREF(mref), vol->mft_record_size, le32_to_cpu(m->bytes_allocated)); goto err_out; } if (!NVolNoFixupWarn(vol) && (le32_to_cpu(m->bytes_in_use) > vol->mft_record_size)) { ntfs_log_error("Record %llu has corrupt in-use size " "(%u > %u)\n", (unsigned long long)MREF(mref), (int)le32_to_cpu(m->bytes_in_use), (int)vol->mft_record_size); goto err_out; } if (le16_to_cpu(m->attrs_offset) & 7) { ntfs_log_error("Attributes badly aligned in record %llu\n", (unsigned long long)MREF(mref)); goto err_out; } a = (ATTR_RECORD *)((char *)m + le16_to_cpu(m->attrs_offset)); if (p2n(a) < p2n(m) || (char *)a > (char *)m + vol->mft_record_size) { ntfs_log_error("Record %llu is corrupt\n", (unsigned long long)MREF(mref)); goto err_out; } if (!NVolNoFixupWarn(vol)) { offset = le16_to_cpu(m->attrs_offset); space = le32_to_cpu(m->bytes_in_use) - offset; a = (ATTR_RECORD*)((char*)m + offset); previous_type = AT_STANDARD_INFORMATION; while ((space >= (s32)offsetof(ATTR_RECORD, resident_end)) && (a->type != AT_END) && (le32_to_cpu(a->type) >= le32_to_cpu(previous_type))) { if ((le32_to_cpu(a->length) <= (u32)space) && !(le32_to_cpu(a->length) & 7)) { if (!ntfs_attr_inconsistent(a, mref)) { previous_type = a->type; offset += le32_to_cpu(a->length); space -= le32_to_cpu(a->length); a = (ATTR_RECORD*)((char*)m + offset); } else goto err_out; } else { ntfs_log_error("Corrupted MFT record %llu\n", (unsigned long long)MREF(mref)); goto err_out; } } /* We are supposed to reach an AT_END */ if ((space < 4) || (a->type != AT_END)) { ntfs_log_error("Bad end of MFT record %llu\n", (unsigned long long)MREF(mref)); goto err_out; } } ret = 0; err_out: if (ret) errno = EIO; return ret; } /** * ntfs_file_record_read - read a FILE record from the mft from disk * @vol: volume to read from * @mref: mft reference specifying mft record to read * @mrec: address of pointer in which to return the mft record * @attr: address of pointer in which to return the first attribute * * Read a FILE record from the mft of @vol from the storage medium. @mref * specifies the mft record to read, including the sequence number, which can * be 0 if no sequence number checking is to be performed. * * The function allocates a buffer large enough to hold the mft record and * reads the record into the buffer (mst deprotecting it in the process). * *@mrec is then set to point to the buffer. * * If @attr is not NULL, *@attr is set to point to the first attribute in the * mft record, i.e. *@attr is a pointer into *@mrec. * * Return 0 on success, or -1 on error, with errno set to the error code. * * The read mft record is checked for having the magic FILE, * and for having a matching sequence number (if MSEQNO(*@mref) != 0). * If either of these fails, -1 is returned and errno is set to EIO. If you get * this, but you still want to read the mft record (e.g. in order to correct * it), use ntfs_mft_record_read() directly. * * Note: Caller has to free *@mrec when finished. * * Note: We do not check if the mft record is flagged in use. The caller can * check if desired. */ int ntfs_file_record_read(const ntfs_volume *vol, const MFT_REF mref, MFT_RECORD **mrec, ATTR_RECORD **attr) { MFT_RECORD *m; if (!vol || !mrec) { errno = EINVAL; ntfs_log_perror("%s: mrec=%p", __FUNCTION__, mrec); return -1; } m = *mrec; if (!m) { m = ntfs_malloc(vol->mft_record_size); if (!m) return -1; } if (ntfs_mft_record_read(vol, mref, m)) goto err_out; if (ntfs_mft_record_check(vol, mref, m)) goto err_out; if (MSEQNO(mref) && MSEQNO(mref) != le16_to_cpu(m->sequence_number)) { ntfs_log_error("Record %llu has wrong SeqNo (%d <> %d)\n", (unsigned long long)MREF(mref), MSEQNO(mref), le16_to_cpu(m->sequence_number)); errno = EIO; goto err_out; } *mrec = m; if (attr) *attr = (ATTR_RECORD*)((char*)m + le16_to_cpu(m->attrs_offset)); return 0; err_out: if (m != *mrec) free(m); return -1; } /** * ntfs_mft_record_layout - layout an mft record into a memory buffer * @vol: volume to which the mft record will belong * @mref: mft reference specifying the mft record number * @mrec: destination buffer of size >= @vol->mft_record_size bytes * * Layout an empty, unused mft record with the mft reference @mref into the * buffer @m. The volume @vol is needed because the mft record structure was * modified in NTFS 3.1 so we need to know which volume version this mft record * will be used on. * * On success return 0 and on error return -1 with errno set to the error code. */ int ntfs_mft_record_layout(const ntfs_volume *vol, const MFT_REF mref, MFT_RECORD *mrec) { ATTR_RECORD *a; if (!vol || !mrec) { errno = EINVAL; ntfs_log_perror("%s: mrec=%p", __FUNCTION__, mrec); return -1; } /* Aligned to 2-byte boundary. */ if (vol->major_ver < 3 || (vol->major_ver == 3 && !vol->minor_ver)) mrec->usa_ofs = cpu_to_le16((sizeof(MFT_RECORD_OLD) + 1) & ~1); else { /* Abort if mref is > 32 bits. */ if (MREF(mref) & 0x0000ffff00000000ull) { errno = ERANGE; ntfs_log_perror("Mft reference exceeds 32 bits"); return -1; } mrec->usa_ofs = cpu_to_le16((sizeof(MFT_RECORD) + 1) & ~1); /* * Set the NTFS 3.1+ specific fields while we know that the * volume version is 3.1+. */ mrec->reserved = const_cpu_to_le16(0); mrec->mft_record_number = cpu_to_le32(MREF(mref)); } mrec->magic = magic_FILE; if (vol->mft_record_size >= NTFS_BLOCK_SIZE) mrec->usa_count = cpu_to_le16(vol->mft_record_size / NTFS_BLOCK_SIZE + 1); else { mrec->usa_count = const_cpu_to_le16(1); ntfs_log_error("Sector size is bigger than MFT record size. " "Setting usa_count to 1. If Windows chkdsk " "reports this as corruption, please email %s " "stating that you saw this message and that " "the file system created was corrupt. " "Thank you.\n", NTFS_DEV_LIST); } /* Set the update sequence number to 1. */ *(le16*)((u8*)mrec + le16_to_cpu(mrec->usa_ofs)) = const_cpu_to_le16(1); mrec->lsn = const_cpu_to_sle64(0ll); mrec->sequence_number = const_cpu_to_le16(1); mrec->link_count = const_cpu_to_le16(0); /* Aligned to 8-byte boundary. */ mrec->attrs_offset = cpu_to_le16((le16_to_cpu(mrec->usa_ofs) + (le16_to_cpu(mrec->usa_count) << 1) + 7) & ~7); mrec->flags = const_cpu_to_le16(0); /* * Using attrs_offset plus eight bytes (for the termination attribute), * aligned to 8-byte boundary. */ mrec->bytes_in_use = cpu_to_le32((le16_to_cpu(mrec->attrs_offset) + 8 + 7) & ~7); mrec->bytes_allocated = cpu_to_le32(vol->mft_record_size); mrec->base_mft_record = const_cpu_to_le64((MFT_REF)0); mrec->next_attr_instance = const_cpu_to_le16(0); a = (ATTR_RECORD*)((u8*)mrec + le16_to_cpu(mrec->attrs_offset)); a->type = AT_END; a->length = const_cpu_to_le32(0); /* Finally, clear the unused part of the mft record. */ memset((u8*)a + 8, 0, vol->mft_record_size - ((u8*)a + 8 - (u8*)mrec)); return 0; } /** * ntfs_mft_record_format - format an mft record on an ntfs volume * @vol: volume on which to format the mft record * @mref: mft reference specifying mft record to format * * Format the mft record with the mft reference @mref in $MFT/$DATA, i.e. lay * out an empty, unused mft record in memory and write it to the volume @vol. * * On success return 0 and on error return -1 with errno set to the error code. */ int ntfs_mft_record_format(const ntfs_volume *vol, const MFT_REF mref) { MFT_RECORD *m; int ret = -1; ntfs_log_enter("Entering\n"); m = ntfs_calloc(vol->mft_record_size); if (!m) goto out; if (ntfs_mft_record_layout(vol, mref, m)) goto free_m; if (ntfs_mft_record_write(vol, mref, m)) goto free_m; ret = 0; free_m: free(m); out: ntfs_log_leave("\n"); return ret; } static const char *es = " Leaving inconsistent metadata. Run chkdsk."; /** * ntfs_ffz - Find the first unset (zero) bit in a word * @word: * * Description... * * Returns: */ static inline unsigned int ntfs_ffz(unsigned int word) { return ffs(~word) - 1; } static int ntfs_is_mft(ntfs_inode *ni) { if (ni && ni->mft_no == FILE_MFT) return 1; return 0; } #ifndef PAGE_SIZE #define PAGE_SIZE 4096 #endif #define RESERVED_MFT_RECORDS 64 /** * ntfs_mft_bitmap_find_free_rec - find a free mft record in the mft bitmap * @vol: volume on which to search for a free mft record * @base_ni: open base inode if allocating an extent mft record or NULL * * Search for a free mft record in the mft bitmap attribute on the ntfs volume * @vol. * * If @base_ni is NULL start the search at the default allocator position. * * If @base_ni is not NULL start the search at the mft record after the base * mft record @base_ni. * * Return the free mft record on success and -1 on error with errno set to the * error code. An error code of ENOSPC means that there are no free mft * records in the currently initialized mft bitmap. */ static int ntfs_mft_bitmap_find_free_rec(ntfs_volume *vol, ntfs_inode *base_ni) { s64 pass_end, ll, data_pos, pass_start, ofs, bit; ntfs_attr *mftbmp_na; u8 *buf, *byte; unsigned int size; u8 pass, b; int ret = -1; ntfs_log_enter("Entering\n"); mftbmp_na = vol->mftbmp_na; /* * Set the end of the pass making sure we do not overflow the mft * bitmap. */ size = PAGE_SIZE; pass_end = vol->mft_na->allocated_size >> vol->mft_record_size_bits; ll = mftbmp_na->initialized_size << 3; if (pass_end > ll) pass_end = ll; pass = 1; if (!base_ni) data_pos = vol->mft_data_pos; else data_pos = base_ni->mft_no + 1; if (data_pos < RESERVED_MFT_RECORDS) data_pos = RESERVED_MFT_RECORDS; if (data_pos >= pass_end) { data_pos = RESERVED_MFT_RECORDS; pass = 2; /* This happens on a freshly formatted volume. */ if (data_pos >= pass_end) { errno = ENOSPC; goto leave; } } if (ntfs_is_mft(base_ni)) { data_pos = 0; pass = 2; } pass_start = data_pos; buf = ntfs_malloc(PAGE_SIZE); if (!buf) goto leave; ntfs_log_debug("Starting bitmap search: pass %u, pass_start 0x%llx, " "pass_end 0x%llx, data_pos 0x%llx.\n", pass, (long long)pass_start, (long long)pass_end, (long long)data_pos); #ifdef DEBUG byte = NULL; b = 0; #endif /* Loop until a free mft record is found. */ for (; pass <= 2; size = PAGE_SIZE) { /* Cap size to pass_end. */ ofs = data_pos >> 3; ll = ((pass_end + 7) >> 3) - ofs; if (size > ll) size = ll; ll = ntfs_attr_pread(mftbmp_na, ofs, size, buf); if (ll < 0) { ntfs_log_perror("Failed to read $MFT bitmap"); free(buf); goto leave; } ntfs_log_debug("Read 0x%llx bytes.\n", (long long)ll); /* If we read at least one byte, search @buf for a zero bit. */ if (ll) { size = ll << 3; bit = data_pos & 7; data_pos &= ~7ull; ntfs_log_debug("Before inner for loop: size 0x%x, " "data_pos 0x%llx, bit 0x%llx, " "*byte 0x%hhx, b %u.\n", size, (long long)data_pos, (long long)bit, (u8) (byte ? *byte : -1), b); for (; bit < size && data_pos + bit < pass_end; bit &= ~7ull, bit += 8) { /* * If we're extending $MFT and running out of the first * mft record (base record) then give up searching since * no guarantee that the found record will be accessible. */ if (ntfs_is_mft(base_ni) && bit > 400) goto out; byte = buf + (bit >> 3); if (*byte == 0xff) continue; /* Note: ffz() result must be zero based. */ b = ntfs_ffz((unsigned long)*byte); if (b < 8 && b >= (bit & 7)) { free(buf); ret = data_pos + (bit & ~7ull) + b; goto leave; } } ntfs_log_debug("After inner for loop: size 0x%x, " "data_pos 0x%llx, bit 0x%llx, " "*byte 0x%hhx, b %u.\n", size, (long long)data_pos, (long long)bit, (u8) (byte ? *byte : -1), b); data_pos += size; /* * If the end of the pass has not been reached yet, * continue searching the mft bitmap for a zero bit. */ if (data_pos < pass_end) continue; } /* Do the next pass. */ pass++; if (pass == 2) { /* * Starting the second pass, in which we scan the first * part of the zone which we omitted earlier. */ pass_end = pass_start; data_pos = pass_start = RESERVED_MFT_RECORDS; ntfs_log_debug("pass %i, pass_start 0x%llx, pass_end " "0x%llx.\n", pass, (long long)pass_start, (long long)pass_end); if (data_pos >= pass_end) break; } } /* No free mft records in currently initialized mft bitmap. */ out: free(buf); errno = ENOSPC; leave: ntfs_log_leave("\n"); return ret; } static int ntfs_mft_attr_extend(ntfs_attr *na) { int ret = STATUS_ERROR; ntfs_log_enter("Entering\n"); if (!NInoAttrList(na->ni)) { if (ntfs_inode_add_attrlist(na->ni)) { ntfs_log_perror("%s: Can not add attrlist #3", __FUNCTION__); goto out; } /* We can't sync the $MFT inode since its runlist is bogus. */ ret = STATUS_KEEP_SEARCHING; goto out; } if (ntfs_attr_update_mapping_pairs(na, 0)) { ntfs_log_perror("%s: MP update failed", __FUNCTION__); goto out; } ret = STATUS_OK; out: ntfs_log_leave("\n"); return ret; } /** * ntfs_mft_bitmap_extend_allocation_i - see ntfs_mft_bitmap_extend_allocation */ static int ntfs_mft_bitmap_extend_allocation_i(ntfs_volume *vol) { LCN lcn; s64 ll = 0; /* silence compiler warning */ ntfs_attr *mftbmp_na; runlist_element *rl, *rl2 = NULL; /* silence compiler warning */ ntfs_attr_search_ctx *ctx; MFT_RECORD *m = NULL; /* silence compiler warning */ ATTR_RECORD *a = NULL; /* silence compiler warning */ int err, mp_size; int ret = STATUS_ERROR; u32 old_alen = 0; /* silence compiler warning */ BOOL mp_rebuilt = FALSE; BOOL update_mp = FALSE; mftbmp_na = vol->mftbmp_na; /* * Determine the last lcn of the mft bitmap. The allocated size of the * mft bitmap cannot be zero so we are ok to do this. */ rl = ntfs_attr_find_vcn(mftbmp_na, (mftbmp_na->allocated_size - 1) >> vol->cluster_size_bits); if (!rl || !rl->length || rl->lcn < 0) { ntfs_log_error("Failed to determine last allocated " "cluster of mft bitmap attribute.\n"); if (rl) errno = EIO; return STATUS_ERROR; } lcn = rl->lcn + rl->length; rl2 = ntfs_cluster_alloc(vol, rl[1].vcn, 1, lcn, DATA_ZONE); if (!rl2) { ntfs_log_error("Failed to allocate a cluster for " "the mft bitmap.\n"); return STATUS_ERROR; } rl = ntfs_runlists_merge(mftbmp_na->rl, rl2); if (!rl) { err = errno; ntfs_log_error("Failed to merge runlists for mft " "bitmap.\n"); if (ntfs_cluster_free_from_rl(vol, rl2)) ntfs_log_error("Failed to deallocate " "cluster.%s\n", es); free(rl2); errno = err; return STATUS_ERROR; } mftbmp_na->rl = rl; ntfs_log_debug("Adding one run to mft bitmap.\n"); /* Find the last run in the new runlist. */ for (; rl[1].length; rl++) ; /* * Update the attribute record as well. Note: @rl is the last * (non-terminator) runlist element of mft bitmap. */ ctx = ntfs_attr_get_search_ctx(mftbmp_na->ni, NULL); if (!ctx) goto undo_alloc; if (ntfs_attr_lookup(mftbmp_na->type, mftbmp_na->name, mftbmp_na->name_len, 0, rl[1].vcn, NULL, 0, ctx)) { ntfs_log_error("Failed to find last attribute extent of " "mft bitmap attribute.\n"); goto undo_alloc; } m = ctx->mrec; a = ctx->attr; ll = sle64_to_cpu(a->lowest_vcn); rl2 = ntfs_attr_find_vcn(mftbmp_na, ll); if (!rl2 || !rl2->length) { ntfs_log_error("Failed to determine previous last " "allocated cluster of mft bitmap attribute.\n"); if (rl2) errno = EIO; goto undo_alloc; } /* Get the size for the new mapping pairs array for this extent. */ mp_size = ntfs_get_size_for_mapping_pairs(vol, rl2, ll, INT_MAX); if (mp_size <= 0) { ntfs_log_error("Get size for mapping pairs failed for " "mft bitmap attribute extent.\n"); goto undo_alloc; } /* Expand the attribute record if necessary. */ old_alen = le32_to_cpu(a->length); if (ntfs_attr_record_resize(m, a, mp_size + le16_to_cpu(a->mapping_pairs_offset))) { ntfs_log_info("extending $MFT bitmap\n"); ret = ntfs_mft_attr_extend(vol->mftbmp_na); if (ret == STATUS_OK) goto ok; if (ret == STATUS_ERROR) { ntfs_log_perror("%s: ntfs_mft_attr_extend failed", __FUNCTION__); update_mp = TRUE; } goto undo_alloc; } mp_rebuilt = TRUE; /* Generate the mapping pairs array directly into the attr record. */ if (ntfs_mapping_pairs_build(vol, (u8*)a + le16_to_cpu(a->mapping_pairs_offset), mp_size, rl2, ll, NULL)) { ntfs_log_error("Failed to build mapping pairs array for " "mft bitmap attribute.\n"); errno = EIO; goto undo_alloc; } /* Update the highest_vcn. */ a->highest_vcn = cpu_to_sle64(rl[1].vcn - 1); /* * We now have extended the mft bitmap allocated_size by one cluster. * Reflect this in the ntfs_attr structure and the attribute record. */ if (a->lowest_vcn) { /* * We are not in the first attribute extent, switch to it, but * first ensure the changes will make it to disk later. */ ntfs_inode_mark_dirty(ctx->ntfs_ino); ntfs_attr_reinit_search_ctx(ctx); if (ntfs_attr_lookup(mftbmp_na->type, mftbmp_na->name, mftbmp_na->name_len, 0, 0, NULL, 0, ctx)) { ntfs_log_error("Failed to find first attribute " "extent of mft bitmap attribute.\n"); goto restore_undo_alloc; } a = ctx->attr; } ok: mftbmp_na->allocated_size += vol->cluster_size; a->allocated_size = cpu_to_sle64(mftbmp_na->allocated_size); /* Ensure the changes make it to disk. */ ntfs_inode_mark_dirty(ctx->ntfs_ino); ntfs_attr_put_search_ctx(ctx); return STATUS_OK; restore_undo_alloc: err = errno; ntfs_attr_reinit_search_ctx(ctx); if (ntfs_attr_lookup(mftbmp_na->type, mftbmp_na->name, mftbmp_na->name_len, 0, rl[1].vcn, NULL, 0, ctx)) { ntfs_log_error("Failed to find last attribute extent of " "mft bitmap attribute.%s\n", es); ntfs_attr_put_search_ctx(ctx); mftbmp_na->allocated_size += vol->cluster_size; /* * The only thing that is now wrong is ->allocated_size of the * base attribute extent which chkdsk should be able to fix. */ errno = err; return STATUS_ERROR; } m = ctx->mrec; a = ctx->attr; a->highest_vcn = cpu_to_sle64(rl[1].vcn - 2); errno = err; undo_alloc: err = errno; /* Remove the last run from the runlist. */ lcn = rl->lcn; rl->lcn = rl[1].lcn; rl->length = 0; /* FIXME: use an ntfs_cluster_free_* function */ if (ntfs_bitmap_clear_bit(vol->lcnbmp_na, lcn)) ntfs_log_error("Failed to free cluster.%s\n", es); else vol->free_clusters++; if (mp_rebuilt) { if (ntfs_mapping_pairs_build(vol, (u8*)a + le16_to_cpu(a->mapping_pairs_offset), old_alen - le16_to_cpu(a->mapping_pairs_offset), rl2, ll, NULL)) ntfs_log_error("Failed to restore mapping " "pairs array.%s\n", es); if (ntfs_attr_record_resize(m, a, old_alen)) ntfs_log_error("Failed to restore attribute " "record.%s\n", es); ntfs_inode_mark_dirty(ctx->ntfs_ino); } if (update_mp) { if (ntfs_attr_update_mapping_pairs(vol->mftbmp_na, 0)) ntfs_log_perror("%s: MP update failed", __FUNCTION__); } if (ctx) ntfs_attr_put_search_ctx(ctx); errno = err; return ret; } /** * ntfs_mft_bitmap_extend_allocation - extend mft bitmap attribute by a cluster * @vol: volume on which to extend the mft bitmap attribute * * Extend the mft bitmap attribute on the ntfs volume @vol by one cluster. * * Note: Only changes allocated_size, i.e. does not touch initialized_size or * data_size. * * Return 0 on success and -1 on error with errno set to the error code. */ static int ntfs_mft_bitmap_extend_allocation(ntfs_volume *vol) { int ret; ntfs_log_enter("Entering\n"); ret = ntfs_mft_bitmap_extend_allocation_i(vol); ntfs_log_leave("\n"); return ret; } /** * ntfs_mft_bitmap_extend_initialized - extend mft bitmap initialized data * @vol: volume on which to extend the mft bitmap attribute * * Extend the initialized portion of the mft bitmap attribute on the ntfs * volume @vol by 8 bytes. * * Note: Only changes initialized_size and data_size, i.e. requires that * allocated_size is big enough to fit the new initialized_size. * * Return 0 on success and -1 on error with errno set to the error code. */ static int ntfs_mft_bitmap_extend_initialized(ntfs_volume *vol) { s64 old_data_size, old_initialized_size, ll; ntfs_attr *mftbmp_na; ntfs_attr_search_ctx *ctx; ATTR_RECORD *a; int err; int ret = -1; ntfs_log_enter("Entering\n"); mftbmp_na = vol->mftbmp_na; ctx = ntfs_attr_get_search_ctx(mftbmp_na->ni, NULL); if (!ctx) goto out; if (ntfs_attr_lookup(mftbmp_na->type, mftbmp_na->name, mftbmp_na->name_len, 0, 0, NULL, 0, ctx)) { ntfs_log_error("Failed to find first attribute extent of " "mft bitmap attribute.\n"); err = errno; goto put_err_out; } a = ctx->attr; old_data_size = mftbmp_na->data_size; old_initialized_size = mftbmp_na->initialized_size; mftbmp_na->initialized_size += 8; a->initialized_size = cpu_to_sle64(mftbmp_na->initialized_size); if (mftbmp_na->initialized_size > mftbmp_na->data_size) { mftbmp_na->data_size = mftbmp_na->initialized_size; a->data_size = cpu_to_sle64(mftbmp_na->data_size); } /* Ensure the changes make it to disk. */ ntfs_inode_mark_dirty(ctx->ntfs_ino); ntfs_attr_put_search_ctx(ctx); /* Initialize the mft bitmap attribute value with zeroes. */ ll = 0; ll = ntfs_attr_pwrite(mftbmp_na, old_initialized_size, 8, &ll); if (ll == 8) { ntfs_log_debug("Wrote eight initialized bytes to mft bitmap.\n"); ret = 0; goto out; } ntfs_log_error("Failed to write to mft bitmap.\n"); err = errno; if (ll >= 0) err = EIO; /* Try to recover from the error. */ ctx = ntfs_attr_get_search_ctx(mftbmp_na->ni, NULL); if (!ctx) goto err_out; if (ntfs_attr_lookup(mftbmp_na->type, mftbmp_na->name, mftbmp_na->name_len, 0, 0, NULL, 0, ctx)) { ntfs_log_error("Failed to find first attribute extent of " "mft bitmap attribute.%s\n", es); put_err_out: ntfs_attr_put_search_ctx(ctx); goto err_out; } a = ctx->attr; mftbmp_na->initialized_size = old_initialized_size; a->initialized_size = cpu_to_sle64(old_initialized_size); if (mftbmp_na->data_size != old_data_size) { mftbmp_na->data_size = old_data_size; a->data_size = cpu_to_sle64(old_data_size); } ntfs_inode_mark_dirty(ctx->ntfs_ino); ntfs_attr_put_search_ctx(ctx); ntfs_log_debug("Restored status of mftbmp: allocated_size 0x%llx, " "data_size 0x%llx, initialized_size 0x%llx.\n", (long long)mftbmp_na->allocated_size, (long long)mftbmp_na->data_size, (long long)mftbmp_na->initialized_size); err_out: errno = err; out: ntfs_log_leave("\n"); return ret; } /** * ntfs_mft_data_extend_allocation - extend mft data attribute * @vol: volume on which to extend the mft data attribute * * Extend the mft data attribute on the ntfs volume @vol by 16 mft records * worth of clusters or if not enough space for this by one mft record worth * of clusters. * * Note: Only changes allocated_size, i.e. does not touch initialized_size or * data_size. * * Return 0 on success and -1 on error with errno set to the error code. */ static int ntfs_mft_data_extend_allocation(ntfs_volume *vol) { LCN lcn; VCN old_last_vcn; s64 min_nr, nr, ll = 0; /* silence compiler warning */ ntfs_attr *mft_na; runlist_element *rl, *rl2; ntfs_attr_search_ctx *ctx; MFT_RECORD *m = NULL; /* silence compiler warning */ ATTR_RECORD *a = NULL; /* silence compiler warning */ int err, mp_size; int ret = STATUS_ERROR; u32 old_alen = 0; /* silence compiler warning */ BOOL mp_rebuilt = FALSE; BOOL update_mp = FALSE; ntfs_log_enter("Extending mft data allocation.\n"); mft_na = vol->mft_na; /* * Determine the preferred allocation location, i.e. the last lcn of * the mft data attribute. The allocated size of the mft data * attribute cannot be zero so we are ok to do this. */ rl = ntfs_attr_find_vcn(mft_na, (mft_na->allocated_size - 1) >> vol->cluster_size_bits); if (!rl || !rl->length || rl->lcn < 0) { ntfs_log_error("Failed to determine last allocated " "cluster of mft data attribute.\n"); if (rl) errno = EIO; goto out; } lcn = rl->lcn + rl->length; ntfs_log_debug("Last lcn of mft data attribute is 0x%llx.\n", (long long)lcn); /* Minimum allocation is one mft record worth of clusters. */ min_nr = vol->mft_record_size >> vol->cluster_size_bits; if (!min_nr) min_nr = 1; /* Want to allocate 16 mft records worth of clusters. */ nr = vol->mft_record_size << 4 >> vol->cluster_size_bits; if (!nr) nr = min_nr; old_last_vcn = rl[1].vcn; do { rl2 = ntfs_cluster_alloc(vol, old_last_vcn, nr, lcn, MFT_ZONE); if (rl2) break; if (errno != ENOSPC || nr == min_nr) { ntfs_log_perror("Failed to allocate (%lld) clusters " "for $MFT", (long long)nr); goto out; } /* * There is not enough space to do the allocation, but there * might be enough space to do a minimal allocation so try that * before failing. */ nr = min_nr; ntfs_log_debug("Retrying mft data allocation with minimal cluster " "count %lli.\n", (long long)nr); } while (1); ntfs_log_debug("Allocated %lld clusters.\n", (long long)nr); rl = ntfs_runlists_merge(mft_na->rl, rl2); if (!rl) { err = errno; ntfs_log_error("Failed to merge runlists for mft data " "attribute.\n"); if (ntfs_cluster_free_from_rl(vol, rl2)) ntfs_log_error("Failed to deallocate clusters " "from the mft data attribute.%s\n", es); free(rl2); errno = err; goto out; } mft_na->rl = rl; /* Find the last run in the new runlist. */ for (; rl[1].length; rl++) ; /* Update the attribute record as well. */ ctx = ntfs_attr_get_search_ctx(mft_na->ni, NULL); if (!ctx) goto undo_alloc; if (ntfs_attr_lookup(mft_na->type, mft_na->name, mft_na->name_len, 0, rl[1].vcn, NULL, 0, ctx)) { ntfs_log_error("Failed to find last attribute extent of " "mft data attribute.\n"); goto undo_alloc; } m = ctx->mrec; a = ctx->attr; ll = sle64_to_cpu(a->lowest_vcn); rl2 = ntfs_attr_find_vcn(mft_na, ll); if (!rl2 || !rl2->length) { ntfs_log_error("Failed to determine previous last " "allocated cluster of mft data attribute.\n"); if (rl2) errno = EIO; goto undo_alloc; } /* Get the size for the new mapping pairs array for this extent. */ mp_size = ntfs_get_size_for_mapping_pairs(vol, rl2, ll, INT_MAX); if (mp_size <= 0) { ntfs_log_error("Get size for mapping pairs failed for " "mft data attribute extent.\n"); goto undo_alloc; } /* Expand the attribute record if necessary. */ old_alen = le32_to_cpu(a->length); if (ntfs_attr_record_resize(m, a, mp_size + le16_to_cpu(a->mapping_pairs_offset))) { ret = ntfs_mft_attr_extend(vol->mft_na); if (ret == STATUS_OK) goto ok; if (ret == STATUS_ERROR) { ntfs_log_perror("%s: ntfs_mft_attr_extend failed", __FUNCTION__); update_mp = TRUE; } goto undo_alloc; } mp_rebuilt = TRUE; /* * Generate the mapping pairs array directly into the attribute record. */ if (ntfs_mapping_pairs_build(vol, (u8*)a + le16_to_cpu(a->mapping_pairs_offset), mp_size, rl2, ll, NULL)) { ntfs_log_error("Failed to build mapping pairs array of " "mft data attribute.\n"); errno = EIO; goto undo_alloc; } /* Update the highest_vcn. */ a->highest_vcn = cpu_to_sle64(rl[1].vcn - 1); /* * We now have extended the mft data allocated_size by nr clusters. * Reflect this in the ntfs_attr structure and the attribute record. * @rl is the last (non-terminator) runlist element of mft data * attribute. */ if (a->lowest_vcn) { /* * We are not in the first attribute extent, switch to it, but * first ensure the changes will make it to disk later. */ ntfs_inode_mark_dirty(ctx->ntfs_ino); ntfs_attr_reinit_search_ctx(ctx); if (ntfs_attr_lookup(mft_na->type, mft_na->name, mft_na->name_len, 0, 0, NULL, 0, ctx)) { ntfs_log_error("Failed to find first attribute " "extent of mft data attribute.\n"); goto restore_undo_alloc; } a = ctx->attr; } ok: mft_na->allocated_size += nr << vol->cluster_size_bits; a->allocated_size = cpu_to_sle64(mft_na->allocated_size); /* Ensure the changes make it to disk. */ ntfs_inode_mark_dirty(ctx->ntfs_ino); ntfs_attr_put_search_ctx(ctx); ret = STATUS_OK; out: ntfs_log_leave("\n"); return ret; restore_undo_alloc: err = errno; ntfs_attr_reinit_search_ctx(ctx); if (ntfs_attr_lookup(mft_na->type, mft_na->name, mft_na->name_len, 0, rl[1].vcn, NULL, 0, ctx)) { ntfs_log_error("Failed to find last attribute extent of " "mft data attribute.%s\n", es); ntfs_attr_put_search_ctx(ctx); mft_na->allocated_size += nr << vol->cluster_size_bits; /* * The only thing that is now wrong is ->allocated_size of the * base attribute extent which chkdsk should be able to fix. */ errno = err; ret = STATUS_ERROR; goto out; } m = ctx->mrec; a = ctx->attr; a->highest_vcn = cpu_to_sle64(old_last_vcn - 1); errno = err; undo_alloc: err = errno; if (ntfs_cluster_free(vol, mft_na, old_last_vcn, -1) < 0) ntfs_log_error("Failed to free clusters from mft data " "attribute.%s\n", es); if (ntfs_rl_truncate(&mft_na->rl, old_last_vcn)) ntfs_log_error("Failed to truncate mft data attribute " "runlist.%s\n", es); if (mp_rebuilt) { if (ntfs_mapping_pairs_build(vol, (u8*)a + le16_to_cpu(a->mapping_pairs_offset), old_alen - le16_to_cpu(a->mapping_pairs_offset), rl2, ll, NULL)) ntfs_log_error("Failed to restore mapping pairs " "array.%s\n", es); if (ntfs_attr_record_resize(m, a, old_alen)) ntfs_log_error("Failed to restore attribute " "record.%s\n", es); ntfs_inode_mark_dirty(ctx->ntfs_ino); } if (update_mp) { if (ntfs_attr_update_mapping_pairs(vol->mft_na, 0)) ntfs_log_perror("%s: MP update failed", __FUNCTION__); } if (ctx) ntfs_attr_put_search_ctx(ctx); errno = err; goto out; } static int ntfs_mft_record_init(ntfs_volume *vol, s64 size) { int ret = -1; ntfs_attr *mft_na; s64 old_data_initialized, old_data_size; ntfs_attr_search_ctx *ctx; ntfs_log_enter("Entering\n"); /* NOTE: Caller must sanity check vol, vol->mft_na and vol->mftbmp_na */ mft_na = vol->mft_na; /* * The mft record is outside the initialized data. Extend the mft data * attribute until it covers the allocated record. The loop is only * actually traversed more than once when a freshly formatted volume * is first written to so it optimizes away nicely in the common case. */ ntfs_log_debug("Status of mft data before extension: " "allocated_size 0x%llx, data_size 0x%llx, " "initialized_size 0x%llx.\n", (long long)mft_na->allocated_size, (long long)mft_na->data_size, (long long)mft_na->initialized_size); while (size > mft_na->allocated_size) { if (ntfs_mft_data_extend_allocation(vol) == STATUS_ERROR) goto out; ntfs_log_debug("Status of mft data after allocation extension: " "allocated_size 0x%llx, data_size 0x%llx, " "initialized_size 0x%llx.\n", (long long)mft_na->allocated_size, (long long)mft_na->data_size, (long long)mft_na->initialized_size); } old_data_initialized = mft_na->initialized_size; old_data_size = mft_na->data_size; /* * Extend mft data initialized size (and data size of course) to reach * the allocated mft record, formatting the mft records along the way. * Note: We only modify the ntfs_attr structure as that is all that is * needed by ntfs_mft_record_format(). We will update the attribute * record itself in one fell swoop later on. */ while (size > mft_na->initialized_size) { s64 ll2 = mft_na->initialized_size >> vol->mft_record_size_bits; mft_na->initialized_size += vol->mft_record_size; if (mft_na->initialized_size > mft_na->data_size) mft_na->data_size = mft_na->initialized_size; ntfs_log_debug("Initializing mft record 0x%llx.\n", (long long)ll2); if (ntfs_mft_record_format(vol, ll2) < 0) { ntfs_log_perror("Failed to format mft record"); goto undo_data_init; } } /* Update the mft data attribute record to reflect the new sizes. */ ctx = ntfs_attr_get_search_ctx(mft_na->ni, NULL); if (!ctx) goto undo_data_init; if (ntfs_attr_lookup(mft_na->type, mft_na->name, mft_na->name_len, 0, 0, NULL, 0, ctx)) { ntfs_log_error("Failed to find first attribute extent of " "mft data attribute.\n"); ntfs_attr_put_search_ctx(ctx); goto undo_data_init; } ctx->attr->initialized_size = cpu_to_sle64(mft_na->initialized_size); ctx->attr->data_size = cpu_to_sle64(mft_na->data_size); ctx->attr->allocated_size = cpu_to_sle64(mft_na->allocated_size); /* Ensure the changes make it to disk. */ ntfs_inode_mark_dirty(ctx->ntfs_ino); ntfs_attr_put_search_ctx(ctx); ntfs_log_debug("Status of mft data after mft record initialization: " "allocated_size 0x%llx, data_size 0x%llx, " "initialized_size 0x%llx.\n", (long long)mft_na->allocated_size, (long long)mft_na->data_size, (long long)mft_na->initialized_size); /* Sanity checks. */ if (mft_na->data_size > mft_na->allocated_size || mft_na->initialized_size > mft_na->data_size) NTFS_BUG("mft_na sanity checks failed"); /* Sync MFT to minimize data loss if there won't be clean unmount. */ if (ntfs_inode_sync(mft_na->ni)) goto undo_data_init; ret = 0; out: ntfs_log_leave("\n"); return ret; undo_data_init: mft_na->initialized_size = old_data_initialized; mft_na->data_size = old_data_size; goto out; } static int ntfs_mft_rec_init(ntfs_volume *vol, s64 size) { int ret = -1; ntfs_attr *mft_na; s64 old_data_initialized, old_data_size; ntfs_attr_search_ctx *ctx; ntfs_log_enter("Entering\n"); mft_na = vol->mft_na; if (size > mft_na->allocated_size || size > mft_na->initialized_size) { errno = EIO; ntfs_log_perror("%s: unexpected $MFT sizes, see below", __FUNCTION__); ntfs_log_error("$MFT: size=%lld allocated_size=%lld " "data_size=%lld initialized_size=%lld\n", (long long)size, (long long)mft_na->allocated_size, (long long)mft_na->data_size, (long long)mft_na->initialized_size); goto out; } old_data_initialized = mft_na->initialized_size; old_data_size = mft_na->data_size; /* Update the mft data attribute record to reflect the new sizes. */ ctx = ntfs_attr_get_search_ctx(mft_na->ni, NULL); if (!ctx) goto undo_data_init; if (ntfs_attr_lookup(mft_na->type, mft_na->name, mft_na->name_len, 0, 0, NULL, 0, ctx)) { ntfs_log_error("Failed to find first attribute extent of " "mft data attribute.\n"); ntfs_attr_put_search_ctx(ctx); goto undo_data_init; } ctx->attr->initialized_size = cpu_to_sle64(mft_na->initialized_size); ctx->attr->data_size = cpu_to_sle64(mft_na->data_size); /* CHECKME: ctx->attr->allocation_size is already ok? */ /* Ensure the changes make it to disk. */ ntfs_inode_mark_dirty(ctx->ntfs_ino); ntfs_attr_put_search_ctx(ctx); /* Sanity checks. */ if (mft_na->data_size > mft_na->allocated_size || mft_na->initialized_size > mft_na->data_size) NTFS_BUG("mft_na sanity checks failed"); out: ntfs_log_leave("\n"); return ret; undo_data_init: mft_na->initialized_size = old_data_initialized; mft_na->data_size = old_data_size; goto out; } ntfs_inode *ntfs_mft_rec_alloc(ntfs_volume *vol, BOOL mft_data) { s64 ll, bit; ntfs_attr *mft_na, *mftbmp_na; MFT_RECORD *m; ntfs_inode *ni = NULL; ntfs_inode *base_ni; int err; le16 seq_no, usn; BOOL forced_mft_data; ntfs_log_enter("Entering\n"); mft_na = vol->mft_na; mftbmp_na = vol->mftbmp_na; base_ni = mft_na->ni; /* * The first extent containing $MFT:$AT_DATA is better located * in record 15 to make sure it can be read at mount time. * The record 15 is prereserved as a base inode with no * extents and no name, and it is marked in use. */ forced_mft_data = FALSE; if (mft_data) { ntfs_inode *ext_ni = ntfs_inode_open(vol, FILE_mft_data); /* * If record 15 cannot be opened, it is probably in * use as an extent. Apply standard procedure for * further extents. */ if (ext_ni) { /* * Make sure record 15 is a base extent and it has * no name. A base inode with no name cannot be in use. * The test based on base_mft_record fails for * extents of MFT, so we need a special check. * If already used, apply standard procedure. */ if (!ext_ni->mrec->base_mft_record && !ext_ni->mrec->link_count) forced_mft_data = TRUE; ntfs_inode_close(ext_ni); /* Double-check, in case it is used for MFT */ if (forced_mft_data && base_ni->nr_extents) { int i; for (i=0; inr_extents; i++) { if (base_ni->extent_nis[i] && (base_ni->extent_nis[i]->mft_no == FILE_mft_data)) forced_mft_data = FALSE; } } } } if (forced_mft_data) bit = FILE_mft_data; else bit = ntfs_mft_bitmap_find_free_rec(vol, base_ni); if (bit >= 0) goto found_free_rec; if (errno != ENOSPC) goto out; errno = ENOSPC; /* strerror() is intentionally used below, we want to log this error. */ ntfs_log_error("No free mft record for $MFT: %s\n", strerror(errno)); goto err_out; found_free_rec: if (ntfs_bitmap_set_bit(mftbmp_na, bit)) { ntfs_log_error("Failed to allocate bit in mft bitmap #2\n"); goto err_out; } ll = (bit + 1) << vol->mft_record_size_bits; if (ll > mft_na->initialized_size) if (ntfs_mft_rec_init(vol, ll) < 0) goto undo_mftbmp_alloc; /* * We now have allocated and initialized the mft record. Need to read * it from disk and re-format it, preserving the sequence number if it * is not zero as well as the update sequence number if it is not zero * or -1 (0xffff). */ m = ntfs_malloc(vol->mft_record_size); if (!m) goto undo_mftbmp_alloc; if (ntfs_mft_record_read(vol, bit, m)) { free(m); goto undo_mftbmp_alloc; } /* Sanity check that the mft record is really not in use. */ if (!forced_mft_data && (ntfs_is_file_record(m->magic) && (m->flags & MFT_RECORD_IN_USE))) { ntfs_log_error("Inode %lld is used but it wasn't marked in " "$MFT bitmap. Fixed.\n", (long long)bit); free(m); goto undo_mftbmp_alloc; } /* * Retrieve the former seq_no and usn so that the new record * cannot be mistaken for the former one. * However the original record may just be garbage, so * use some sensible value when they cannot be retrieved. */ seq_no = m->sequence_number; if (le16_to_cpu(m->usa_ofs) <= (NTFS_BLOCK_SIZE - 2)) usn = *(le16*)((u8*)m + (le16_to_cpu(m->usa_ofs) & -2)); else usn = const_cpu_to_le16(1); if (ntfs_mft_record_layout(vol, bit, m)) { ntfs_log_error("Failed to re-format mft record.\n"); free(m); goto undo_mftbmp_alloc; } if (seq_no) m->sequence_number = seq_no; seq_no = usn; if (seq_no && seq_no != const_cpu_to_le16(0xffff)) *(le16*)((u8*)m + le16_to_cpu(m->usa_ofs)) = usn; /* Set the mft record itself in use. */ m->flags |= MFT_RECORD_IN_USE; /* Now need to open an ntfs inode for the mft record. */ ni = ntfs_inode_allocate(vol); if (!ni) { ntfs_log_error("Failed to allocate buffer for inode.\n"); free(m); goto undo_mftbmp_alloc; } ni->mft_no = bit; ni->mrec = m; /* * If we are allocating an extent mft record, make the opened inode an * extent inode and attach it to the base inode. Also, set the base * mft record reference in the extent inode. */ ni->nr_extents = -1; ni->base_ni = base_ni; m->base_mft_record = MK_LE_MREF(base_ni->mft_no, le16_to_cpu(base_ni->mrec->sequence_number)); /* * Attach the extent inode to the base inode, reallocating * memory if needed. */ if (!(base_ni->nr_extents & 3)) { ntfs_inode **extent_nis; int i; i = (base_ni->nr_extents + 4) * sizeof(ntfs_inode *); extent_nis = ntfs_malloc(i); if (!extent_nis) { free(m); free(ni); goto undo_mftbmp_alloc; } if (base_ni->nr_extents) { memcpy(extent_nis, base_ni->extent_nis, i - 4 * sizeof(ntfs_inode *)); free(base_ni->extent_nis); } base_ni->extent_nis = extent_nis; } base_ni->extent_nis[base_ni->nr_extents++] = ni; /* Make sure the allocated inode is written out to disk later. */ ntfs_inode_mark_dirty(ni); /* Initialize time, allocated and data size in ntfs_inode struct. */ ni->data_size = ni->allocated_size = 0; ni->flags = const_cpu_to_le32(0); ni->creation_time = ni->last_data_change_time = ni->last_mft_change_time = ni->last_access_time = ntfs_current_time(); /* Update the default mft allocation position if it was used. */ if (!base_ni) vol->mft_data_pos = bit + 1; /* Return the opened, allocated inode of the allocated mft record. */ ntfs_log_error("allocated %sinode %lld\n", base_ni ? "extent " : "", (long long)bit); out: ntfs_log_leave("\n"); return ni; undo_mftbmp_alloc: err = errno; if (ntfs_bitmap_clear_bit(mftbmp_na, bit)) ntfs_log_error("Failed to clear bit in mft bitmap.%s\n", es); errno = err; err_out: if (!errno) errno = EIO; ni = NULL; goto out; } /** * ntfs_mft_record_alloc - allocate an mft record on an ntfs volume * @vol: volume on which to allocate the mft record * @base_ni: open base inode if allocating an extent mft record or NULL * * Allocate an mft record in $MFT/$DATA of an open ntfs volume @vol. * * If @base_ni is NULL make the mft record a base mft record and allocate it at * the default allocator position. * * If @base_ni is not NULL make the allocated mft record an extent record, * allocate it starting at the mft record after the base mft record and attach * the allocated and opened ntfs inode to the base inode @base_ni. * * On success return the now opened ntfs (extent) inode of the mft record. * * On error return NULL with errno set to the error code. * * To find a free mft record, we scan the mft bitmap for a zero bit. To * optimize this we start scanning at the place specified by @base_ni or if * @base_ni is NULL we start where we last stopped and we perform wrap around * when we reach the end. Note, we do not try to allocate mft records below * number 24 because numbers 0 to 15 are the defined system files anyway and 16 * to 24 are used for storing extension mft records or used by chkdsk to store * its log. However the record number 15 is dedicated to the first extent to * the $DATA attribute of $MFT. This is required to avoid the possibility * of creating a run list with a circular dependence which once written to disk * can never be read in again. Windows will only use records 16 to 24 for * normal files if the volume is completely out of space. We never use them * which means that when the volume is really out of space we cannot create any * more files while Windows can still create up to 8 small files. We can start * doing this at some later time, it does not matter much for now. * * When scanning the mft bitmap, we only search up to the last allocated mft * record. If there are no free records left in the range 24 to number of * allocated mft records, then we extend the $MFT/$DATA attribute in order to * create free mft records. We extend the allocated size of $MFT/$DATA by 16 * records at a time or one cluster, if cluster size is above 16kiB. If there * is not sufficient space to do this, we try to extend by a single mft record * or one cluster, if cluster size is above the mft record size, but we only do * this if there is enough free space, which we know from the values returned * by the failed cluster allocation function when we tried to do the first * allocation. * * No matter how many mft records we allocate, we initialize only the first * allocated mft record, incrementing mft data size and initialized size * accordingly, open an ntfs_inode for it and return it to the caller, unless * there are less than 24 mft records, in which case we allocate and initialize * mft records until we reach record 24 which we consider as the first free mft * record for use by normal files. * * If during any stage we overflow the initialized data in the mft bitmap, we * extend the initialized size (and data size) by 8 bytes, allocating another * cluster if required. The bitmap data size has to be at least equal to the * number of mft records in the mft, but it can be bigger, in which case the * superfluous bits are padded with zeroes. * * Thus, when we return successfully (return value non-zero), we will have: * - initialized / extended the mft bitmap if necessary, * - initialized / extended the mft data if necessary, * - set the bit corresponding to the mft record being allocated in the * mft bitmap, * - open an ntfs_inode for the allocated mft record, and we will * - return the ntfs_inode. * * On error (return value zero), nothing will have changed. If we had changed * anything before the error occurred, we will have reverted back to the * starting state before returning to the caller. Thus, except for bugs, we * should always leave the volume in a consistent state when returning from * this function. * * Note, this function cannot make use of most of the normal functions, like * for example for attribute resizing, etc, because when the run list overflows * the base mft record and an attribute list is used, it is very important that * the extension mft records used to store the $DATA attribute of $MFT can be * reached without having to read the information contained inside them, as * this would make it impossible to find them in the first place after the * volume is dismounted. $MFT/$BITMAP probably does not need to follow this * rule because the bitmap is not essential for finding the mft records, but on * the other hand, handling the bitmap in this special way would make life * easier because otherwise there might be circular invocations of functions * when reading the bitmap but if we are careful, we should be able to avoid * all problems. */ ntfs_inode *ntfs_mft_record_alloc(ntfs_volume *vol, ntfs_inode *base_ni) { s64 ll, bit; ntfs_attr *mft_na, *mftbmp_na; MFT_RECORD *m; ntfs_inode *ni = NULL; int err; u32 usa_ofs; le16 seq_no, usn; BOOL oldwarn; if (base_ni) ntfs_log_enter("Entering (allocating an extent mft record for " "base mft record %lld).\n", (long long)base_ni->mft_no); else ntfs_log_enter("Entering (allocating a base mft record)\n"); if (!vol || !vol->mft_na || !vol->mftbmp_na) { errno = EINVAL; goto out; } if (ntfs_is_mft(base_ni)) { ni = ntfs_mft_rec_alloc(vol, FALSE); goto out; } mft_na = vol->mft_na; mftbmp_na = vol->mftbmp_na; retry: bit = ntfs_mft_bitmap_find_free_rec(vol, base_ni); if (bit >= 0) { ntfs_log_debug("found free record (#1) at %lld\n", (long long)bit); goto found_free_rec; } if (errno != ENOSPC) goto out; /* * No free mft records left. If the mft bitmap already covers more * than the currently used mft records, the next records are all free, * so we can simply allocate the first unused mft record. * Note: We also have to make sure that the mft bitmap at least covers * the first 24 mft records as they are special and whilst they may not * be in use, we do not allocate from them. */ ll = mft_na->initialized_size >> vol->mft_record_size_bits; if (mftbmp_na->initialized_size << 3 > ll && mftbmp_na->initialized_size > RESERVED_MFT_RECORDS / 8) { bit = ll; if (bit < RESERVED_MFT_RECORDS) bit = RESERVED_MFT_RECORDS; ntfs_log_debug("found free record (#2) at %lld\n", (long long)bit); goto found_free_rec; } /* * The mft bitmap needs to be expanded until it covers the first unused * mft record that we can allocate. * Note: The smallest mft record we allocate is mft record 24. */ ntfs_log_debug("Status of mftbmp before extension: allocated_size 0x%llx, " "data_size 0x%llx, initialized_size 0x%llx.\n", (long long)mftbmp_na->allocated_size, (long long)mftbmp_na->data_size, (long long)mftbmp_na->initialized_size); if (mftbmp_na->initialized_size + 8 > mftbmp_na->allocated_size) { const s64 old_allocated_size = mftbmp_na->allocated_size; int ret = ntfs_mft_bitmap_extend_allocation(vol); if (ret == STATUS_ERROR) goto err_out; if (ret == STATUS_KEEP_SEARCHING) { ret = ntfs_mft_bitmap_extend_allocation(vol); if (ret != STATUS_OK) goto err_out; } ntfs_log_debug("Status of mftbmp after allocation extension: " "allocated_size 0x%llx, data_size 0x%llx, " "initialized_size 0x%llx.\n", (long long)mftbmp_na->allocated_size, (long long)mftbmp_na->data_size, (long long)mftbmp_na->initialized_size); vol->free_mft_records += (mftbmp_na->allocated_size - old_allocated_size) << 3; } /* * We now have sufficient allocated space, extend the initialized_size * as well as the data_size if necessary and fill the new space with * zeroes. */ bit = mftbmp_na->initialized_size << 3; if (ntfs_mft_bitmap_extend_initialized(vol)) goto err_out; ntfs_log_debug("Status of mftbmp after initialized extension: " "allocated_size 0x%llx, data_size 0x%llx, " "initialized_size 0x%llx.\n", (long long)mftbmp_na->allocated_size, (long long)mftbmp_na->data_size, (long long)mftbmp_na->initialized_size); ntfs_log_debug("found free record (#3) at %lld\n", (long long)bit); found_free_rec: /* @bit is the found free mft record, allocate it in the mft bitmap. */ if (ntfs_bitmap_set_bit(mftbmp_na, bit)) { ntfs_log_error("Failed to allocate bit in mft bitmap.\n"); goto err_out; } /* The mft bitmap is now uptodate. Deal with mft data attribute now. */ ll = (bit + 1) << vol->mft_record_size_bits; if (ll > mft_na->initialized_size) if (ntfs_mft_record_init(vol, ll) < 0) goto undo_mftbmp_alloc; /* * We now have allocated and initialized the mft record. Need to read * it from disk and re-format it, preserving the sequence number if it * is not zero as well as the update sequence number if it is not zero * or -1 (0xffff). */ m = ntfs_malloc(vol->mft_record_size); if (!m) goto undo_mftbmp_alloc; /* * As this is allocating a new record, do not expect it to have * been initialized previously, so do not warn over bad fixups * (hence avoid warn flooding when an NTFS partition has been wiped). */ oldwarn = !NVolNoFixupWarn(vol); NVolSetNoFixupWarn(vol); if (ntfs_mft_record_read(vol, bit, m)) { if (oldwarn) NVolClearNoFixupWarn(vol); free(m); goto undo_mftbmp_alloc; } if (oldwarn) NVolClearNoFixupWarn(vol); /* Sanity check that the mft record is really not in use. */ if (ntfs_is_file_record(m->magic) && (m->flags & MFT_RECORD_IN_USE)) { ntfs_log_error("Inode %lld is used but it wasn't marked in " "$MFT bitmap. Fixed.\n", (long long)bit); free(m); goto retry; } seq_no = m->sequence_number; /* * As ntfs_mft_record_read() returns what has been read * even when the fixups have been found bad, we have to * check where we fetch the initial usn from. */ usa_ofs = le16_to_cpu(m->usa_ofs); if (!(usa_ofs & 1) && (usa_ofs < NTFS_BLOCK_SIZE)) { usn = *(le16*)((u8*)m + usa_ofs); } else usn = const_cpu_to_le16(1); if (ntfs_mft_record_layout(vol, bit, m)) { ntfs_log_error("Failed to re-format mft record.\n"); free(m); goto undo_mftbmp_alloc; } if (seq_no) m->sequence_number = seq_no; seq_no = usn; if (seq_no && seq_no != const_cpu_to_le16(0xffff)) *(le16*)((u8*)m + le16_to_cpu(m->usa_ofs)) = usn; /* Set the mft record itself in use. */ m->flags |= MFT_RECORD_IN_USE; /* Now need to open an ntfs inode for the mft record. */ ni = ntfs_inode_allocate(vol); if (!ni) { ntfs_log_error("Failed to allocate buffer for inode.\n"); free(m); goto undo_mftbmp_alloc; } ni->mft_no = bit; ni->mrec = m; /* * If we are allocating an extent mft record, make the opened inode an * extent inode and attach it to the base inode. Also, set the base * mft record reference in the extent inode. */ if (base_ni) { ni->nr_extents = -1; ni->base_ni = base_ni; m->base_mft_record = MK_LE_MREF(base_ni->mft_no, le16_to_cpu(base_ni->mrec->sequence_number)); /* * Attach the extent inode to the base inode, reallocating * memory if needed. */ if (!(base_ni->nr_extents & 3)) { ntfs_inode **extent_nis; int i; i = (base_ni->nr_extents + 4) * sizeof(ntfs_inode *); extent_nis = ntfs_malloc(i); if (!extent_nis) { free(m); free(ni); goto undo_mftbmp_alloc; } if (base_ni->nr_extents) { memcpy(extent_nis, base_ni->extent_nis, i - 4 * sizeof(ntfs_inode *)); free(base_ni->extent_nis); } base_ni->extent_nis = extent_nis; } base_ni->extent_nis[base_ni->nr_extents++] = ni; } /* Make sure the allocated inode is written out to disk later. */ ntfs_inode_mark_dirty(ni); /* Initialize time, allocated and data size in ntfs_inode struct. */ ni->data_size = ni->allocated_size = 0; ni->flags = const_cpu_to_le32(0); ni->creation_time = ni->last_data_change_time = ni->last_mft_change_time = ni->last_access_time = ntfs_current_time(); /* Update the default mft allocation position if it was used. */ if (!base_ni) vol->mft_data_pos = bit + 1; /* Return the opened, allocated inode of the allocated mft record. */ ntfs_log_debug("allocated %sinode 0x%llx.\n", base_ni ? "extent " : "", (long long)bit); vol->free_mft_records--; out: ntfs_log_leave("\n"); return ni; undo_mftbmp_alloc: err = errno; if (ntfs_bitmap_clear_bit(mftbmp_na, bit)) ntfs_log_error("Failed to clear bit in mft bitmap.%s\n", es); errno = err; err_out: if (!errno) errno = EIO; ni = NULL; goto out; } /** * ntfs_mft_record_free - free an mft record on an ntfs volume * @vol: volume on which to free the mft record * @ni: open ntfs inode of the mft record to free * * Free the mft record of the open inode @ni on the mounted ntfs volume @vol. * Note that this function calls ntfs_inode_close() internally and hence you * cannot use the pointer @ni any more after this function returns success. * * On success return 0 and on error return -1 with errno set to the error code. */ int ntfs_mft_record_free(ntfs_volume *vol, ntfs_inode *ni) { u64 mft_no; int err; u16 seq_no; le16 old_seq_no; ntfs_log_trace("Entering for inode 0x%llx.\n", (long long) ni->mft_no); if (!vol || !vol->mftbmp_na || !ni) { errno = EINVAL; return -1; } /* Cache the mft reference for later. */ mft_no = ni->mft_no; /* Mark the mft record as not in use. */ ni->mrec->flags &= ~MFT_RECORD_IN_USE; /* Increment the sequence number, skipping zero, if it is not zero. */ old_seq_no = ni->mrec->sequence_number; seq_no = le16_to_cpu(old_seq_no); if (seq_no == 0xffff) seq_no = 1; else if (seq_no) seq_no++; ni->mrec->sequence_number = cpu_to_le16(seq_no); /* Set the inode dirty and write it out. */ ntfs_inode_mark_dirty(ni); if (ntfs_inode_sync(ni)) { err = errno; goto sync_rollback; } /* Clear the bit in the $MFT/$BITMAP corresponding to this record. */ if (ntfs_bitmap_clear_bit(vol->mftbmp_na, mft_no)) { err = errno; // FIXME: If ntfs_bitmap_clear_run() guarantees rollback on // error, this could be changed to goto sync_rollback; goto bitmap_rollback; } /* Throw away the now freed inode. */ #if CACHE_NIDATA_SIZE if (!ntfs_inode_real_close(ni)) { #else if (!ntfs_inode_close(ni)) { #endif vol->free_mft_records++; return 0; } err = errno; /* Rollback what we did... */ bitmap_rollback: if (ntfs_bitmap_set_bit(vol->mftbmp_na, mft_no)) ntfs_log_debug("Eeek! Rollback failed in ntfs_mft_record_free(). " "Leaving inconsistent metadata!\n"); sync_rollback: ni->mrec->flags |= MFT_RECORD_IN_USE; ni->mrec->sequence_number = old_seq_no; ntfs_inode_mark_dirty(ni); errno = err; return -1; } /** * ntfs_mft_usn_dec - Decrement USN by one * @mrec: pointer to an mft record * * On success return 0 and on error return -1 with errno set. */ int ntfs_mft_usn_dec(MFT_RECORD *mrec) { u16 usn; le16 *usnp; if (!mrec) { errno = EINVAL; return -1; } usnp = (le16*)((char*)mrec + le16_to_cpu(mrec->usa_ofs)); usn = le16_to_cpup(usnp); if (usn-- <= 1) usn = 0xfffe; *usnp = cpu_to_le16(usn); return 0; } ntfs-3g-2026.2.25/libntfs-3g/attrib.c0000664000175000017500000064721415152260173012417 /** * attrib.c - Attribute handling code. Originated from the Linux-NTFS project. * * Copyright (c) 2000-2010 Anton Altaparmakov * Copyright (c) 2002-2005 Richard Russon * Copyright (c) 2002-2008 Szabolcs Szakacsits * Copyright (c) 2004-2007 Yura Pakhuchiy * Copyright (c) 2007-2021 Jean-Pierre Andre * Copyright (c) 2010 Erik Larsson * * This program/include file 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/include file 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_STDIO_H #include #endif #ifdef HAVE_STRING_H #include #endif #ifdef HAVE_STDLIB_H #include #endif #ifdef HAVE_ERRNO_H #include #endif #ifdef HAVE_LIMITS_H #include #endif #include "param.h" #include "compat.h" #include "attrib.h" #include "attrlist.h" #include "device.h" #include "mft.h" #include "debug.h" #include "mst.h" #include "volume.h" #include "types.h" #include "layout.h" #include "inode.h" #include "runlist.h" #include "lcnalloc.h" #include "dir.h" #include "compress.h" #include "bitmap.h" #include "logging.h" #include "misc.h" #include "efs.h" ntfschar AT_UNNAMED[] = { const_cpu_to_le16('\0') }; ntfschar STREAM_SDS[] = { const_cpu_to_le16('$'), const_cpu_to_le16('S'), const_cpu_to_le16('D'), const_cpu_to_le16('S'), const_cpu_to_le16('\0') }; ntfschar TXF_DATA[] = { const_cpu_to_le16('$'), const_cpu_to_le16('T'), const_cpu_to_le16('X'), const_cpu_to_le16('F'), const_cpu_to_le16('_'), const_cpu_to_le16('D'), const_cpu_to_le16('A'), const_cpu_to_le16('T'), const_cpu_to_le16('A'), const_cpu_to_le16('\0') }; static int NAttrFlag(ntfs_attr *na, FILE_ATTR_FLAGS flag) { if (na->type == AT_DATA && na->name == AT_UNNAMED) return (na->ni->flags & flag); return 0; } static void NAttrSetFlag(ntfs_attr *na, FILE_ATTR_FLAGS flag) { if (na->type == AT_DATA && na->name == AT_UNNAMED) na->ni->flags |= flag; else ntfs_log_trace("Denied setting flag %d for not unnamed data " "attribute\n", le32_to_cpu(flag)); } static void NAttrClearFlag(ntfs_attr *na, FILE_ATTR_FLAGS flag) { if (na->type == AT_DATA && na->name == AT_UNNAMED) na->ni->flags &= ~flag; } #define GenNAttrIno(func_name, flag) \ int NAttr##func_name(ntfs_attr *na) { return NAttrFlag (na, flag); } \ void NAttrSet##func_name(ntfs_attr *na) { NAttrSetFlag (na, flag); } \ void NAttrClear##func_name(ntfs_attr *na){ NAttrClearFlag(na, flag); } GenNAttrIno(Compressed, FILE_ATTR_COMPRESSED) GenNAttrIno(Encrypted, FILE_ATTR_ENCRYPTED) GenNAttrIno(Sparse, FILE_ATTR_SPARSE_FILE) /** * ntfs_get_attribute_value_length - Find the length of an attribute * @a: * * Description... * * Returns: */ s64 ntfs_get_attribute_value_length(const ATTR_RECORD *a) { if (!a) { errno = EINVAL; return 0; } errno = 0; if (a->non_resident) return sle64_to_cpu(a->data_size); return (s64)le32_to_cpu(a->value_length); } /** * ntfs_get_attribute_value - Get a copy of an attribute * @vol: * @a: * @b: * * Description... * * Returns: */ s64 ntfs_get_attribute_value(const ntfs_volume *vol, const ATTR_RECORD *a, u8 *b) { runlist *rl; s64 total, r; int i; /* Sanity checks. */ if (!vol || !a || !b) { errno = EINVAL; return 0; } /* Complex attribute? */ /* * Ignore the flags in case they are not zero for an attribute list * attribute. Windows does not complain about invalid flags and chkdsk * does not detect or fix them so we need to cope with it, too. */ if (a->type != AT_ATTRIBUTE_LIST && a->flags) { ntfs_log_error("Non-zero (%04x) attribute flags. Cannot handle " "this yet.\n", le16_to_cpu(a->flags)); errno = EOPNOTSUPP; return 0; } if (!a->non_resident) { /* Attribute is resident. */ /* Sanity check. */ if (le32_to_cpu(a->value_length) + le16_to_cpu(a->value_offset) > le32_to_cpu(a->length)) { return 0; } memcpy(b, (const char*)a + le16_to_cpu(a->value_offset), le32_to_cpu(a->value_length)); errno = 0; return (s64)le32_to_cpu(a->value_length); } /* Attribute is not resident. */ /* If no data, return 0. */ if (!(a->data_size)) { errno = 0; return 0; } /* * FIXME: What about attribute lists?!? (AIA) */ /* Decompress the mapping pairs array into a runlist. */ rl = ntfs_mapping_pairs_decompress(vol, a, NULL); if (!rl) { errno = EINVAL; return 0; } /* * FIXED: We were overflowing here in a nasty fashion when we * reach the last cluster in the runlist as the buffer will * only be big enough to hold data_size bytes while we are * reading in allocated_size bytes which is usually larger * than data_size, since the actual data is unlikely to have a * size equal to a multiple of the cluster size! * FIXED2: We were also overflowing here in the same fashion * when the data_size was more than one run smaller than the * allocated size which happens with Windows XP sometimes. */ /* Now load all clusters in the runlist into b. */ for (i = 0, total = 0; rl[i].length; i++) { if (total + (rl[i].length << vol->cluster_size_bits) >= sle64_to_cpu(a->data_size)) { unsigned char *intbuf = NULL; s64 intlth; /* * We have reached the last run so we were going to * overflow when executing the ntfs_pread() which is * BAAAAAAAD! * Temporary fix: * Allocate a new buffer with size: * rl[i].length << vol->cluster_size_bits, do the * read into our buffer, then memcpy the correct * amount of data into the caller supplied buffer, * free our buffer, and continue. * We have reached the end of data size so we were * going to overflow in the same fashion. * Temporary fix: same as above. * * For safety, limit the amount to read to the * needed size, knowing that the whole attribute * size has been checked to be <= 0x40000. */ intlth = (sle64_to_cpu(a->data_size) - total + vol->cluster_size - 1) >> vol->cluster_size_bits; if (rl[i].length < intlth) intlth = rl[i].length; intbuf = (u8*)ntfs_malloc(intlth << vol->cluster_size_bits); if (!intbuf) { free(rl); return 0; } /* * FIXME: If compressed file: Only read if lcn != -1. * Otherwise, we are dealing with a sparse run and we * just memset the user buffer to 0 for the length of * the run, which should be 16 (= compression unit * size). * FIXME: Really only when file is compressed, or can * we have sparse runs in uncompressed files as well? * - Yes we can, in sparse files! But not necessarily * size of 16, just run length. */ r = ntfs_pread(vol->dev, rl[i].lcn << vol->cluster_size_bits, intlth << vol->cluster_size_bits, intbuf); if (r != intlth << vol->cluster_size_bits) { #define ESTR "Error reading attribute value" if (r == -1) ntfs_log_perror(ESTR); else if (r < intlth << vol->cluster_size_bits) { ntfs_log_debug(ESTR ": Ran out of input data.\n"); errno = EIO; } else { ntfs_log_debug(ESTR ": unknown error\n"); errno = EIO; } #undef ESTR free(rl); free(intbuf); return 0; } memcpy(b + total, intbuf, sle64_to_cpu(a->data_size) - total); free(intbuf); total = sle64_to_cpu(a->data_size); break; } /* * FIXME: If compressed file: Only read if lcn != -1. * Otherwise, we are dealing with a sparse run and we just * memset the user buffer to 0 for the length of the run, which * should be 16 (= compression unit size). * FIXME: Really only when file is compressed, or can * we have sparse runs in uncompressed files as well? * - Yes we can, in sparse files! But not necessarily size of * 16, just run length. */ r = ntfs_pread(vol->dev, rl[i].lcn << vol->cluster_size_bits, rl[i].length << vol->cluster_size_bits, b + total); if (r != rl[i].length << vol->cluster_size_bits) { #define ESTR "Error reading attribute value" if (r == -1) ntfs_log_perror(ESTR); else if (r < rl[i].length << vol->cluster_size_bits) { ntfs_log_debug(ESTR ": Ran out of input data.\n"); errno = EIO; } else { ntfs_log_debug(ESTR ": unknown error\n"); errno = EIO; } #undef ESTR free(rl); return 0; } total += r; } free(rl); return total; } /* Already cleaned up code below, but still look for FIXME:... */ /** * __ntfs_attr_init - primary initialization of an ntfs attribute structure * @na: ntfs attribute to initialize * @ni: ntfs inode with which to initialize the ntfs attribute * @type: attribute type * @name: attribute name in little endian Unicode or NULL * @name_len: length of attribute @name in Unicode characters (if @name given) * * Initialize the ntfs attribute @na with @ni, @type, @name, and @name_len. */ static void __ntfs_attr_init(ntfs_attr *na, ntfs_inode *ni, const ATTR_TYPES type, ntfschar *name, const u32 name_len) { na->rl = NULL; na->ni = ni; na->type = type; na->name = name; if (name) na->name_len = name_len; else na->name_len = 0; } /** * ntfs_attr_init - initialize an ntfs_attr with data sizes and status * @na: * @non_resident: * @compressed: * @encrypted: * @sparse: * @allocated_size: * @data_size: * @initialized_size: * @compressed_size: * @compression_unit: * * Final initialization for an ntfs attribute. */ void ntfs_attr_init(ntfs_attr *na, const BOOL non_resident, const ATTR_FLAGS data_flags, const BOOL encrypted, const BOOL sparse, const s64 allocated_size, const s64 data_size, const s64 initialized_size, const s64 compressed_size, const u8 compression_unit) { if (!NAttrInitialized(na)) { na->data_flags = data_flags; if (non_resident) NAttrSetNonResident(na); if (data_flags & ATTR_COMPRESSION_MASK) NAttrSetCompressed(na); if (encrypted) NAttrSetEncrypted(na); if (sparse) NAttrSetSparse(na); na->allocated_size = allocated_size; na->data_size = data_size; na->initialized_size = initialized_size; if ((data_flags & ATTR_COMPRESSION_MASK) || sparse) { ntfs_volume *vol = na->ni->vol; na->compressed_size = compressed_size; na->compression_block_clusters = 1 << compression_unit; na->compression_block_size = 1 << (compression_unit + vol->cluster_size_bits); na->compression_block_size_bits = ffs( na->compression_block_size) - 1; } NAttrSetInitialized(na); } } /** * ntfs_attr_open - open an ntfs attribute for access * @ni: open ntfs inode in which the ntfs attribute resides * @type: attribute type * @name: attribute name in little endian Unicode or AT_UNNAMED or NULL * @name_len: length of attribute @name in Unicode characters (if @name given) * * Allocate a new ntfs attribute structure, initialize it with @ni, @type, * @name, and @name_len, then return it. Return NULL on error with * errno set to the error code. * * If @name is AT_UNNAMED look specifically for an unnamed attribute. If you * do not care whether the attribute is named or not set @name to NULL. In * both those cases @name_len is not used at all. */ ntfs_attr *ntfs_attr_open(ntfs_inode *ni, const ATTR_TYPES type, ntfschar *name, u32 name_len) { ntfs_attr_search_ctx *ctx; ntfs_attr *na = NULL; ntfschar *newname = NULL; ATTR_RECORD *a; le16 cs; ntfs_log_enter("Entering for inode %lld, attr 0x%x.\n", (unsigned long long)ni->mft_no, le32_to_cpu(type)); if (!ni || !ni->vol || !ni->mrec) { errno = EINVAL; goto out; } na = ntfs_calloc(sizeof(ntfs_attr)); if (!na) goto out; if (!name_len) name = (ntfschar*)NULL; if (name && name != AT_UNNAMED && name != NTFS_INDEX_I30) { /* A null char leads to a short name and unallocated bytes */ if (ntfs_ucsnlen(name, name_len) != name_len) { ntfs_log_error("Null character in attribute name" " of inode %lld\n",(long long)ni->mft_no); errno = EIO; goto err_out; } name = ntfs_ucsndup(name, name_len); if (!name) goto err_out; newname = name; } ctx = ntfs_attr_get_search_ctx(ni, NULL); if (!ctx) goto err_out; if (ntfs_attr_lookup(type, name, name_len, 0, 0, NULL, 0, ctx)) goto put_err_out; a = ctx->attr; if (!name) { if (a->name_length) { ntfschar *attr_name; attr_name = (ntfschar*)((u8*)a + le16_to_cpu(a->name_offset)); /* A null character leads to illegal memory access */ if (ntfs_ucsnlen(attr_name, a->name_length) != a->name_length) { ntfs_log_error("Null character in attribute" " name in inode %lld\n", (long long)ni->mft_no); errno = EIO; goto put_err_out; } name = ntfs_ucsndup(attr_name, a->name_length); if (!name) goto put_err_out; newname = name; name_len = a->name_length; } else { name = AT_UNNAMED; name_len = 0; } } __ntfs_attr_init(na, ni, type, name, name_len); /* * Wipe the flags in case they are not zero for an attribute list * attribute. Windows does not complain about invalid flags and chkdsk * does not detect or fix them so we need to cope with it, too. */ if (type == AT_ATTRIBUTE_LIST) a->flags = const_cpu_to_le16(0); if ((type == AT_DATA) && (a->non_resident ? !a->initialized_size : !a->value_length)) { /* * Define/redefine the compression state if stream is * empty, based on the compression mark on parent * directory (for unnamed data streams) or on current * inode (for named data streams). The compression mark * may change any time, the compression state can only * change when stream is wiped out. * * Also prevent compression on NTFS version < 3.0 * or cluster size > 4K or compression is disabled */ a->flags &= ~ATTR_COMPRESSION_MASK; if ((ni->flags & FILE_ATTR_COMPRESSED) && (ni->vol->major_ver >= 3) && NVolCompression(ni->vol) && (ni->vol->cluster_size <= MAX_COMPRESSION_CLUSTER_SIZE)) a->flags |= ATTR_IS_COMPRESSED; } cs = a->flags & (ATTR_IS_COMPRESSED | ATTR_IS_SPARSE); /* a file may be sparse though its unnamed data is not (cf $UsnJrnl) */ if (na->type == AT_DATA && na->name == AT_UNNAMED && (((a->flags & ATTR_IS_SPARSE) && !NAttrSparse(na)) || (!(a->flags & ATTR_IS_ENCRYPTED) != !NAttrEncrypted(na)))) { errno = EIO; ntfs_log_perror("Inode %lld has corrupt attribute flags " "(0x%x <> 0x%x)",(unsigned long long)ni->mft_no, le16_to_cpu(a->flags), le32_to_cpu(na->ni->flags)); goto put_err_out; } if (a->non_resident) { if (((a->flags & ATTR_COMPRESSION_MASK) || a->compression_unit) && (ni->vol->major_ver < 3)) { errno = EIO; ntfs_log_perror("Compressed inode %lld not allowed" " on NTFS %d.%d", (unsigned long long)ni->mft_no, ni->vol->major_ver, ni->vol->major_ver); goto put_err_out; } if ((a->flags & ATTR_COMPRESSION_MASK) && !a->compression_unit) { errno = EIO; ntfs_log_perror("Compressed inode %lld attr 0x%x has " "no compression unit", (unsigned long long)ni->mft_no, le32_to_cpu(type)); goto put_err_out; } if ((a->flags & ATTR_COMPRESSION_MASK) && (a->compression_unit != STANDARD_COMPRESSION_UNIT)) { errno = EIO; ntfs_log_perror("Compressed inode %lld attr 0x%lx has " "an unsupported compression unit %d", (unsigned long long)ni->mft_no, (long)le32_to_cpu(type), (int)a->compression_unit); goto put_err_out; } ntfs_attr_init(na, TRUE, a->flags, a->flags & ATTR_IS_ENCRYPTED, a->flags & ATTR_IS_SPARSE, sle64_to_cpu(a->allocated_size), sle64_to_cpu(a->data_size), sle64_to_cpu(a->initialized_size), cs ? sle64_to_cpu(a->compressed_size) : 0, cs ? a->compression_unit : 0); } else { s64 l = le32_to_cpu(a->value_length); ntfs_attr_init(na, FALSE, a->flags, a->flags & ATTR_IS_ENCRYPTED, a->flags & ATTR_IS_SPARSE, (l + 7) & ~7, l, l, cs ? (l + 7) & ~7 : 0, 0); } ntfs_attr_put_search_ctx(ctx); out: ntfs_log_leave("\n"); return na; put_err_out: ntfs_attr_put_search_ctx(ctx); err_out: free(newname); free(na); na = NULL; goto out; } /** * ntfs_attr_close - free an ntfs attribute structure * @na: ntfs attribute structure to free * * Release all memory associated with the ntfs attribute @na and then release * @na itself. */ void ntfs_attr_close(ntfs_attr *na) { if (!na) return; if (NAttrNonResident(na) && na->rl) free(na->rl); /* Don't release if using an internal constant. */ if (na->name != AT_UNNAMED && na->name != NTFS_INDEX_I30 && na->name != STREAM_SDS) free(na->name); free(na); } /** * ntfs_attr_map_runlist - map (a part of) a runlist of an ntfs attribute * @na: ntfs attribute for which to map (part of) a runlist * @vcn: map runlist part containing this vcn * * Map the part of a runlist containing the @vcn of the ntfs attribute @na. * * Return 0 on success and -1 on error with errno set to the error code. */ int ntfs_attr_map_runlist(ntfs_attr *na, VCN vcn) { LCN lcn; ntfs_attr_search_ctx *ctx; ntfs_log_trace("Entering for inode 0x%llx, attr 0x%x, vcn 0x%llx.\n", (unsigned long long)na->ni->mft_no, le32_to_cpu(na->type), (long long)vcn); lcn = ntfs_rl_vcn_to_lcn(na->rl, vcn); if (lcn >= 0 || lcn == LCN_HOLE || lcn == LCN_ENOENT) return 0; ctx = ntfs_attr_get_search_ctx(na->ni, NULL); if (!ctx) return -1; /* Find the attribute in the mft record. */ if (!ntfs_attr_lookup(na->type, na->name, na->name_len, CASE_SENSITIVE, vcn, NULL, 0, ctx)) { runlist_element *rl; /* Decode the runlist. */ rl = ntfs_mapping_pairs_decompress(na->ni->vol, ctx->attr, na->rl); if (rl) { na->rl = rl; ntfs_attr_put_search_ctx(ctx); return 0; } } ntfs_attr_put_search_ctx(ctx); return -1; } #if PARTIAL_RUNLIST_UPDATING /* * Map the runlist of an attribute from some point to the end * * Returns 0 if success, * -1 if it failed (errno telling why) */ static int ntfs_attr_map_partial_runlist(ntfs_attr *na, VCN vcn) { VCN last_vcn; VCN highest_vcn; VCN needed; runlist_element *rl; ATTR_RECORD *a; BOOL startseen; ntfs_attr_search_ctx *ctx; BOOL done; BOOL newrunlist; if (NAttrFullyMapped(na)) return 0; ctx = ntfs_attr_get_search_ctx(na->ni, NULL); if (!ctx) return -1; /* Get the last vcn in the attribute. */ last_vcn = na->allocated_size >> na->ni->vol->cluster_size_bits; needed = vcn; highest_vcn = 0; startseen = FALSE; done = FALSE; rl = (runlist_element*)NULL; do { newrunlist = FALSE; /* Find the attribute in the mft record. */ if (!ntfs_attr_lookup(na->type, na->name, na->name_len, CASE_SENSITIVE, needed, NULL, 0, ctx)) { a = ctx->attr; /* Decode and merge the runlist. */ if (ntfs_rl_vcn_to_lcn(na->rl, needed) == LCN_RL_NOT_MAPPED) { rl = ntfs_mapping_pairs_decompress(na->ni->vol, a, na->rl); newrunlist = TRUE; } else rl = na->rl; if (rl) { na->rl = rl; highest_vcn = sle64_to_cpu(a->highest_vcn); if (highest_vcn < needed) { /* corruption detection on unchanged runlists */ if (newrunlist && ((highest_vcn + 1) < last_vcn)) { ntfs_log_error("Corrupt attribute list\n"); rl = (runlist_element*)NULL; errno = EIO; } done = TRUE; } needed = highest_vcn + 1; if (!a->lowest_vcn) startseen = TRUE; } } else { done = TRUE; } } while (rl && !done && (needed < last_vcn)); ntfs_attr_put_search_ctx(ctx); /* * Make sure we reached the end, unless the last * runlist was modified earlier (using HOLES_DELAY * leads to have a visibility over attributes which * have not yet been fully updated) */ if (done && newrunlist && (needed < last_vcn)) { ntfs_log_error("End of runlist not reached\n"); rl = (runlist_element*)NULL; errno = EIO; } /* mark fully mapped if we did so */ if (rl && startseen) NAttrSetFullyMapped(na); return (rl ? 0 : -1); } #endif /** * ntfs_attr_map_whole_runlist - map the whole runlist of an ntfs attribute * @na: ntfs attribute for which to map the runlist * * Map the whole runlist of the ntfs attribute @na. For an attribute made up * of only one attribute extent this is the same as calling * ntfs_attr_map_runlist(na, 0) but for an attribute with multiple extents this * will map the runlist fragments from each of the extents thus giving access * to the entirety of the disk allocation of an attribute. * * Return 0 on success and -1 on error with errno set to the error code. */ int ntfs_attr_map_whole_runlist(ntfs_attr *na) { VCN next_vcn, last_vcn, highest_vcn; ntfs_attr_search_ctx *ctx; ntfs_volume *vol = na->ni->vol; ATTR_RECORD *a; int ret = -1; int not_mapped; ntfs_log_enter("Entering for inode %llu, attr 0x%x.\n", (unsigned long long)na->ni->mft_no, le32_to_cpu(na->type)); /* avoid multiple full runlist mappings */ if (NAttrFullyMapped(na)) { ret = 0; goto out; } ctx = ntfs_attr_get_search_ctx(na->ni, NULL); if (!ctx) goto out; /* Map all attribute extents one by one. */ next_vcn = last_vcn = highest_vcn = 0; a = NULL; while (1) { runlist_element *rl; not_mapped = 0; if (ntfs_rl_vcn_to_lcn(na->rl, next_vcn) == LCN_RL_NOT_MAPPED) not_mapped = 1; if (ntfs_attr_lookup(na->type, na->name, na->name_len, CASE_SENSITIVE, next_vcn, NULL, 0, ctx)) break; a = ctx->attr; if (not_mapped) { /* Decode the runlist. */ rl = ntfs_mapping_pairs_decompress(na->ni->vol, a, na->rl); if (!rl) goto err_out; na->rl = rl; } /* Are we in the first extent? */ if (!next_vcn) { if (a->lowest_vcn) { errno = EIO; ntfs_log_perror("First extent of inode %llu " "attribute has non-zero lowest_vcn", (unsigned long long)na->ni->mft_no); goto err_out; } /* Get the last vcn in the attribute. */ last_vcn = sle64_to_cpu(a->allocated_size) >> vol->cluster_size_bits; } /* Get the lowest vcn for the next extent. */ highest_vcn = sle64_to_cpu(a->highest_vcn); next_vcn = highest_vcn + 1; /* Only one extent or error, which we catch below. */ if (next_vcn <= 0) { errno = ENOENT; break; } /* Avoid endless loops due to corruption. */ if (next_vcn < sle64_to_cpu(a->lowest_vcn)) { errno = EIO; ntfs_log_perror("Inode %llu has corrupt attribute list", (unsigned long long)na->ni->mft_no); goto err_out; } } if (!a) { ntfs_log_perror("Couldn't find attribute for runlist mapping"); goto err_out; } /* * Cannot check highest_vcn when the last runlist has * been modified earlier, as runlists and sizes may be * updated without highest_vcn being in sync, when * HOLES_DELAY is used */ if (not_mapped && highest_vcn && highest_vcn != last_vcn - 1) { errno = EIO; ntfs_log_perror("Failed to load full runlist: inode: %llu " "highest_vcn: 0x%llx last_vcn: 0x%llx", (unsigned long long)na->ni->mft_no, (long long)highest_vcn, (long long)last_vcn); goto err_out; } if (errno == ENOENT) { NAttrSetFullyMapped(na); ret = 0; } err_out: ntfs_attr_put_search_ctx(ctx); out: ntfs_log_leave("\n"); return ret; } /** * ntfs_attr_vcn_to_lcn - convert a vcn into a lcn given an ntfs attribute * @na: ntfs attribute whose runlist to use for conversion * @vcn: vcn to convert * * Convert the virtual cluster number @vcn of an attribute into a logical * cluster number (lcn) of a device using the runlist @na->rl to map vcns to * their corresponding lcns. * * If the @vcn is not mapped yet, attempt to map the attribute extent * containing the @vcn and retry the vcn to lcn conversion. * * Since lcns must be >= 0, we use negative return values with special meaning: * * Return value Meaning / Description * ========================================== * -1 = LCN_HOLE Hole / not allocated on disk. * -3 = LCN_ENOENT There is no such vcn in the attribute. * -4 = LCN_EINVAL Input parameter error. * -5 = LCN_EIO Corrupt fs, disk i/o error, or not enough memory. */ LCN ntfs_attr_vcn_to_lcn(ntfs_attr *na, const VCN vcn) { LCN lcn; BOOL is_retry = FALSE; if (!na || !NAttrNonResident(na) || vcn < 0) return (LCN)LCN_EINVAL; ntfs_log_trace("Entering for inode 0x%llx, attr 0x%x.\n", (unsigned long long)na->ni->mft_no, le32_to_cpu(na->type)); retry: /* Convert vcn to lcn. If that fails map the runlist and retry once. */ lcn = ntfs_rl_vcn_to_lcn(na->rl, vcn); if (lcn >= 0) return lcn; if (!is_retry && !ntfs_attr_map_runlist(na, vcn)) { is_retry = TRUE; goto retry; } /* * If the attempt to map the runlist failed, or we are getting * LCN_RL_NOT_MAPPED despite having mapped the attribute extent * successfully, something is really badly wrong... */ if (!is_retry || lcn == (LCN)LCN_RL_NOT_MAPPED) return (LCN)LCN_EIO; /* lcn contains the appropriate error code. */ return lcn; } /** * ntfs_attr_find_vcn - find a vcn in the runlist of an ntfs attribute * @na: ntfs attribute whose runlist to search * @vcn: vcn to find * * Find the virtual cluster number @vcn in the runlist of the ntfs attribute * @na and return the the address of the runlist element containing the @vcn. * * Note you need to distinguish between the lcn of the returned runlist * element being >= 0 and LCN_HOLE. In the later case you have to return zeroes * on read and allocate clusters on write. You need to update the runlist, the * attribute itself as well as write the modified mft record to disk. * * If there is an error return NULL with errno set to the error code. The * following error codes are defined: * EINVAL Input parameter error. * ENOENT There is no such vcn in the runlist. * ENOMEM Not enough memory. * EIO I/O error or corrupt metadata. */ runlist_element *ntfs_attr_find_vcn(ntfs_attr *na, const VCN vcn) { runlist_element *rl; BOOL is_retry = FALSE; if (!na || !NAttrNonResident(na) || vcn < 0) { errno = EINVAL; return NULL; } ntfs_log_trace("Entering for inode 0x%llx, attr 0x%x, vcn %llx\n", (unsigned long long)na->ni->mft_no, le32_to_cpu(na->type), (long long)vcn); retry: rl = na->rl; if (!rl) goto map_rl; if (vcn < rl[0].vcn) goto map_rl; while (rl->length) { if (vcn < rl[1].vcn) { if (rl->lcn >= (LCN)LCN_HOLE) return rl; break; } rl++; } switch (rl->lcn) { case (LCN)LCN_RL_NOT_MAPPED: goto map_rl; case (LCN)LCN_ENOENT: errno = ENOENT; break; case (LCN)LCN_EINVAL: errno = EINVAL; break; default: errno = EIO; break; } return NULL; map_rl: /* The @vcn is in an unmapped region, map the runlist and retry. */ if (!is_retry && !ntfs_attr_map_runlist(na, vcn)) { is_retry = TRUE; goto retry; } /* * If we already retried or the mapping attempt failed something has * gone badly wrong. EINVAL and ENOENT coming from a failed mapping * attempt are equivalent to errors for us as they should not happen * in our code paths. */ if (is_retry || errno == EINVAL || errno == ENOENT) errno = EIO; return NULL; } /** * ntfs_attr_pread_i - see description at ntfs_attr_pread() */ static s64 ntfs_attr_pread_i(ntfs_attr *na, const s64 pos, s64 count, void *b) { s64 br, to_read, ofs, total, total2, max_read, max_init; ntfs_volume *vol; runlist_element *rl; u16 efs_padding_length; /* Sanity checking arguments is done in ntfs_attr_pread(). */ if ((na->data_flags & ATTR_COMPRESSION_MASK) && NAttrNonResident(na)) { if ((na->data_flags & ATTR_COMPRESSION_MASK) == ATTR_IS_COMPRESSED) return ntfs_compressed_attr_pread(na, pos, count, b); else { /* compression mode not supported */ errno = EOPNOTSUPP; return -1; } } /* * Encrypted non-resident attributes are not supported. We return * access denied, which is what Windows NT4 does, too. * However, allow if mounted with efs_raw option */ vol = na->ni->vol; if (!vol->efs_raw && NAttrEncrypted(na) && NAttrNonResident(na)) { errno = EACCES; return -1; } if (!count) return 0; /* * Truncate reads beyond end of attribute, * but round to next 512 byte boundary for encrypted * attributes with efs_raw mount option */ max_read = na->data_size; max_init = na->initialized_size; if (na->ni->vol->efs_raw && (na->data_flags & ATTR_IS_ENCRYPTED) && NAttrNonResident(na)) { if (na->data_size != na->initialized_size) { ntfs_log_error("uninitialized encrypted file not supported\n"); errno = EINVAL; return -1; } max_init = max_read = ((na->data_size + 511) & ~511) + 2; } if (pos + count > max_read) { if (pos >= max_read) return 0; count = max_read - pos; } /* If it is a resident attribute, get the value from the mft record. */ if (!NAttrNonResident(na)) { ntfs_attr_search_ctx *ctx; char *val; ctx = ntfs_attr_get_search_ctx(na->ni, NULL); if (!ctx) return -1; if (ntfs_attr_lookup(na->type, na->name, na->name_len, 0, 0, NULL, 0, ctx)) { res_err_out: ntfs_attr_put_search_ctx(ctx); return -1; } val = (char*)ctx->attr + le16_to_cpu(ctx->attr->value_offset); if (val < (char*)ctx->attr || val + le32_to_cpu(ctx->attr->value_length) > (char*)ctx->mrec + vol->mft_record_size) { errno = EIO; ntfs_log_perror("%s: Sanity check failed", __FUNCTION__); goto res_err_out; } memcpy(b, val + pos, count); ntfs_attr_put_search_ctx(ctx); return count; } total = total2 = 0; /* Zero out reads beyond initialized size. */ if (pos + count > max_init) { if (pos >= max_init) { memset(b, 0, count); return count; } total2 = pos + count - max_init; count -= total2; memset((u8*)b + count, 0, total2); } /* * for encrypted non-resident attributes with efs_raw set * the last two bytes aren't read from disk but contain * the number of padding bytes so original size can be * restored */ if (na->ni->vol->efs_raw && (na->data_flags & ATTR_IS_ENCRYPTED) && ((pos + count) > max_init-2)) { efs_padding_length = 511 - ((na->data_size - 1) & 511); if (pos+count == max_init) { if (count == 1) { *((u8*)b+count-1) = (u8)(efs_padding_length >> 8); count--; total2++; } else { *(le16*)((u8*)b+count-2) = cpu_to_le16(efs_padding_length); count -= 2; total2 +=2; } } else { *((u8*)b+count-1) = (u8)(efs_padding_length & 0xff); count--; total2++; } } /* Find the runlist element containing the vcn. */ rl = ntfs_attr_find_vcn(na, pos >> vol->cluster_size_bits); if (!rl) { /* * If the vcn is not present it is an out of bounds read. * However, we already truncated the read to the data_size, * so getting this here is an error. */ if (errno == ENOENT) { errno = EIO; ntfs_log_perror("%s: Failed to find VCN #1", __FUNCTION__); } return -1; } /* * Gather the requested data into the linear destination buffer. Note, * a partial final vcn is taken care of by the @count capping of read * length. */ ofs = pos - (rl->vcn << vol->cluster_size_bits); for (; count; rl++, ofs = 0) { if (rl->lcn == LCN_RL_NOT_MAPPED) { rl = ntfs_attr_find_vcn(na, rl->vcn); if (!rl) { if (errno == ENOENT) { errno = EIO; ntfs_log_perror("%s: Failed to find VCN #2", __FUNCTION__); } goto rl_err_out; } /* Needed for case when runs merged. */ ofs = pos + total - (rl->vcn << vol->cluster_size_bits); } if (!rl->length) { errno = EIO; ntfs_log_perror("%s: Zero run length", __FUNCTION__); goto rl_err_out; } if (rl->lcn < (LCN)0) { if (rl->lcn != (LCN)LCN_HOLE) { ntfs_log_perror("%s: Bad run (%lld)", __FUNCTION__, (long long)rl->lcn); goto rl_err_out; } /* It is a hole, just zero the matching @b range. */ to_read = min(count, (rl->length << vol->cluster_size_bits) - ofs); memset(b, 0, to_read); /* Update progress counters. */ total += to_read; count -= to_read; b = (u8*)b + to_read; continue; } /* It is a real lcn, read it into @dst. */ to_read = min(count, (rl->length << vol->cluster_size_bits) - ofs); retry: ntfs_log_trace("Reading %lld bytes from vcn %lld, lcn %lld, ofs" " %lld.\n", (long long)to_read, (long long)rl->vcn, (long long )rl->lcn, (long long)ofs); br = ntfs_pread(vol->dev, (rl->lcn << vol->cluster_size_bits) + ofs, to_read, b); /* If everything ok, update progress counters and continue. */ if (br > 0) { total += br; count -= br; b = (u8*)b + br; } if (br == to_read) continue; /* If the syscall was interrupted, try again. */ if (br == (s64)-1 && errno == EINTR) goto retry; if (total) return total; if (!br) errno = EIO; ntfs_log_perror("%s: ntfs_pread failed", __FUNCTION__); return -1; } /* Finally, return the number of bytes read. */ return total + total2; rl_err_out: if (total) return total; errno = EIO; return -1; } /** * ntfs_attr_pread - read from an attribute specified by an ntfs_attr structure * @na: ntfs attribute to read from * @pos: byte position in the attribute to begin reading from * @count: number of bytes to read * @b: output data buffer * * This function will read @count bytes starting at offset @pos from the ntfs * attribute @na into the data buffer @b. * * On success, return the number of successfully read bytes. If this number is * lower than @count this means that the read reached end of file or that an * error was encountered during the read so that the read is partial. 0 means * end of file or nothing was read (also return 0 when @count is 0). * * On error and nothing has been read, return -1 with errno set appropriately * to the return code of ntfs_pread(), or to EINVAL in case of invalid * arguments. */ s64 ntfs_attr_pread(ntfs_attr *na, const s64 pos, s64 count, void *b) { s64 ret; if (!na || !na->ni || !na->ni->vol || !b || pos < 0 || count < 0) { errno = EINVAL; ntfs_log_perror("%s: na=%p b=%p pos=%lld count=%lld", __FUNCTION__, na, b, (long long)pos, (long long)count); return -1; } ntfs_log_enter("Entering for inode %lld attr 0x%x pos %lld count " "%lld\n", (unsigned long long)na->ni->mft_no, le32_to_cpu(na->type), (long long)pos, (long long)count); ret = ntfs_attr_pread_i(na, pos, count, b); ntfs_log_leave("\n"); return ret; } static int ntfs_attr_fill_zero(ntfs_attr *na, s64 pos, s64 count) { char *buf; s64 written, size, end = pos + count; s64 ofsi; const runlist_element *rli; ntfs_volume *vol; int ret = -1; ntfs_log_trace("pos %lld, count %lld\n", (long long)pos, (long long)count); if (!na || pos < 0 || count < 0) { errno = EINVAL; goto err_out; } buf = ntfs_calloc(NTFS_BUF_SIZE); if (!buf) goto err_out; rli = na->rl; ofsi = 0; vol = na->ni->vol; while (pos < end) { while (rli->length && (ofsi + (rli->length << vol->cluster_size_bits) <= pos)) { ofsi += (rli->length << vol->cluster_size_bits); rli++; } size = min(end - pos, NTFS_BUF_SIZE); /* * If the zeroed block is fully within a hole, * we need not write anything, so advance as far * as possible within the hole. */ if ((rli->lcn == (LCN)LCN_HOLE) && (ofsi <= pos) && (ofsi + (rli->length << vol->cluster_size_bits) >= (pos + size))) { size = min(end - pos, ofsi - pos + (rli->length << vol->cluster_size_bits)); pos += size; } else { written = ntfs_rl_pwrite(vol, rli, ofsi, pos, size, buf); if (written <= 0) { ntfs_log_perror("Failed to zero space"); goto err_free; } pos += written; } } ret = 0; err_free: free(buf); err_out: return ret; } static int ntfs_attr_fill_hole(ntfs_attr *na, s64 count, s64 *ofs, runlist_element **rl, VCN *update_from) { s64 to_write; s64 need; ntfs_volume *vol = na->ni->vol; int eo, ret = -1; runlist *rlc; LCN lcn_seek_from = -1; VCN cur_vcn, from_vcn; if (na->ni->mft_no == FILE_Bitmap) { /* * Filling a hole in the main bitmap implies allocating * clusters, which is likely to imply updating the * bitmap in a cluster being allocated. * Not supported now, could lead to endless recursions. */ ntfs_log_error("Corrupt $BitMap not fully allocated\n"); errno = EIO; goto err_out; } to_write = min(count, ((*rl)->length << vol->cluster_size_bits) - *ofs); cur_vcn = (*rl)->vcn; from_vcn = (*rl)->vcn + (*ofs >> vol->cluster_size_bits); ntfs_log_trace("count: %lld, cur_vcn: %lld, from: %lld, to: %lld, ofs: " "%lld\n", (long long)count, (long long)cur_vcn, (long long)from_vcn, (long long)to_write, (long long)*ofs); /* Map the runlist to be able to update mapping pairs later. */ #if PARTIAL_RUNLIST_UPDATING if (!na->rl) { if (ntfs_attr_map_whole_runlist(na)) goto err_out; } else { /* make sure the run ahead of hole is mapped */ if ((*rl)->lcn == LCN_HOLE) { if (ntfs_attr_map_partial_runlist(na, (cur_vcn ? cur_vcn - 1 : cur_vcn))) goto err_out; } } #else if (ntfs_attr_map_whole_runlist(na)) goto err_out; #endif /* Restore @*rl, it probably get lost during runlist mapping. */ *rl = ntfs_attr_find_vcn(na, cur_vcn); if (!*rl) { ntfs_log_error("Failed to find run after mapping runlist. " "Please report to %s.\n", NTFS_DEV_LIST); errno = EIO; goto err_out; } /* Search backwards to find the best lcn to start seek from. */ rlc = *rl; while (rlc->vcn) { rlc--; if (rlc->lcn >= 0) { /* * avoid fragmenting a compressed file * Windows does not do that, and that may * not be desirable for files which can * be updated */ if (na->data_flags & ATTR_COMPRESSION_MASK) lcn_seek_from = rlc->lcn + rlc->length; else lcn_seek_from = rlc->lcn + (from_vcn - rlc->vcn); break; } } if (lcn_seek_from == -1) { /* Backwards search failed, search forwards. */ rlc = *rl; while (rlc->length) { rlc++; if (rlc->lcn >= 0) { lcn_seek_from = rlc->lcn - (rlc->vcn - from_vcn); if (lcn_seek_from < -1) lcn_seek_from = -1; break; } } } need = ((*ofs + to_write - 1) >> vol->cluster_size_bits) + 1 + (*rl)->vcn - from_vcn; if ((na->data_flags & ATTR_COMPRESSION_MASK) && (need < na->compression_block_clusters)) { /* * for a compressed file, be sure to allocate the full * compression block, as we may need space to decompress * existing compressed data. * So allocate the space common to compression block * and existing hole. */ VCN alloc_vcn; if ((from_vcn & -na->compression_block_clusters) <= (*rl)->vcn) alloc_vcn = (*rl)->vcn; else alloc_vcn = from_vcn & -na->compression_block_clusters; need = (alloc_vcn | (na->compression_block_clusters - 1)) + 1 - alloc_vcn; if (need > (*rl)->length) { ntfs_log_error("Cannot allocate %lld clusters" " within a hole of %lld\n", (long long)need, (long long)(*rl)->length); errno = EIO; goto err_out; } rlc = ntfs_cluster_alloc(vol, alloc_vcn, need, lcn_seek_from, DATA_ZONE); } else rlc = ntfs_cluster_alloc(vol, from_vcn, need, lcn_seek_from, DATA_ZONE); if (!rlc) goto err_out; if (na->data_flags & (ATTR_COMPRESSION_MASK | ATTR_IS_SPARSE)) na->compressed_size += need << vol->cluster_size_bits; *rl = ntfs_runlists_merge(na->rl, rlc); NAttrSetRunlistDirty(na); /* * For a compressed attribute, we must be sure there are two * available entries, so reserve them before it gets too late. */ if (*rl && (na->data_flags & ATTR_COMPRESSION_MASK)) { runlist_element *oldrl = na->rl; na->rl = *rl; *rl = ntfs_rl_extend(na,*rl,2); if (!*rl) na->rl = oldrl; /* restore to original if failed */ } if (!*rl) { eo = errno; ntfs_log_perror("Failed to merge runlists"); if (ntfs_cluster_free_from_rl(vol, rlc)) { ntfs_log_perror("Failed to free hot clusters. " "Please run chkdsk /f"); } errno = eo; goto err_out; } na->unused_runs = 2; na->rl = *rl; if ((*update_from == -1) || (from_vcn < *update_from)) *update_from = from_vcn; *rl = ntfs_attr_find_vcn(na, cur_vcn); if (!*rl) { /* * It's definitely a BUG, if we failed to find @cur_vcn, because * we missed it during instantiating of the hole. */ ntfs_log_error("Failed to find run after hole instantiation. " "Please report to %s.\n", NTFS_DEV_LIST); errno = EIO; goto err_out; } /* If leaved part of the hole go to the next run. */ if ((*rl)->lcn < 0) (*rl)++; /* Now LCN shoudn't be less than 0. */ if ((*rl)->lcn < 0) { ntfs_log_error("BUG! LCN is lesser than 0. " "Please report to the %s.\n", NTFS_DEV_LIST); errno = EIO; goto err_out; } if (*ofs) { /* Clear non-sparse region from @cur_vcn to @*ofs. */ if (ntfs_attr_fill_zero(na, cur_vcn << vol->cluster_size_bits, *ofs)) goto err_out; } if ((*rl)->vcn < cur_vcn) { /* * Clusters that replaced hole are merged with * previous run, so we need to update offset. */ *ofs += (cur_vcn - (*rl)->vcn) << vol->cluster_size_bits; } if ((*rl)->vcn > cur_vcn) { /* * We left part of the hole, so we need to update offset */ *ofs -= ((*rl)->vcn - cur_vcn) << vol->cluster_size_bits; } ret = 0; err_out: return ret; } static int stuff_hole(ntfs_attr *na, const s64 pos); /* * Split an existing hole for overwriting with data * The hole may have to be split into two or three parts, so * that the overwritten part fits within a single compression block * * No cluster allocation is needed, this will be done later in * standard hole filling, hence no need to reserve runs for * future needs. * * Returns the number of clusters with existing compressed data * in the compression block to be written to * (or the full block, if it was a full hole) * -1 if there were an error */ static int split_compressed_hole(ntfs_attr *na, runlist_element **prl, s64 pos, s64 count, VCN *update_from) { int compressed_part; int cluster_size_bits = na->ni->vol->cluster_size_bits; runlist_element *rl = *prl; compressed_part = na->compression_block_clusters; /* reserve entries in runlist if we have to split */ if (rl->length > na->compression_block_clusters) { *prl = ntfs_rl_extend(na,*prl,2); if (!*prl) { compressed_part = -1; } else { rl = *prl; na->unused_runs = 2; } } if (*prl && (rl->length > na->compression_block_clusters)) { /* * Locate the update part relative to beginning of * current run */ int beginwrite = (pos >> cluster_size_bits) - rl->vcn; s32 endblock = (((pos + count - 1) >> cluster_size_bits) | (na->compression_block_clusters - 1)) + 1 - rl->vcn; compressed_part = na->compression_block_clusters - (rl->length & (na->compression_block_clusters - 1)); if ((beginwrite + compressed_part) >= na->compression_block_clusters) compressed_part = na->compression_block_clusters; /* * if the run ends beyond end of needed block * we have to split the run */ if (endblock < rl[0].length) { runlist_element *xrl; int n; /* * we have to split into three parts if the run * does not end within the first compression block. * This means the hole begins before the * compression block. */ if (endblock > na->compression_block_clusters) { if (na->unused_runs < 2) { ntfs_log_error("No free run, case 1\n"); } na->unused_runs -= 2; xrl = rl; n = 0; while (xrl->length) { xrl++; n++; } do { xrl[2] = *xrl; xrl--; } while (xrl != rl); rl[1].length = na->compression_block_clusters; rl[2].length = rl[0].length - endblock; rl[0].length = endblock - na->compression_block_clusters; rl[1].lcn = LCN_HOLE; rl[2].lcn = LCN_HOLE; rl[1].vcn = rl[0].vcn + rl[0].length; rl[2].vcn = rl[1].vcn + na->compression_block_clusters; rl = ++(*prl); } else { /* * split into two parts and use the * first one */ if (!na->unused_runs) { ntfs_log_error("No free run, case 2\n"); } na->unused_runs--; xrl = rl; n = 0; while (xrl->length) { xrl++; n++; } do { xrl[1] = *xrl; xrl--; } while (xrl != rl); if (beginwrite < endblock) { /* we will write into the first part of hole */ rl[1].length = rl[0].length - endblock; rl[0].length = endblock; rl[1].vcn = rl[0].vcn + rl[0].length; rl[1].lcn = LCN_HOLE; } else { /* we will write into the second part of hole */ // impossible ? rl[1].length = rl[0].length - endblock; rl[0].length = endblock; rl[1].vcn = rl[0].vcn + rl[0].length; rl[1].lcn = LCN_HOLE; rl = ++(*prl); } } } else { if (rl[1].length) { runlist_element *xrl; int n; /* * split into two parts and use the * last one */ if (!na->unused_runs) { ntfs_log_error("No free run, case 4\n"); } na->unused_runs--; xrl = rl; n = 0; while (xrl->length) { xrl++; n++; } do { xrl[1] = *xrl; xrl--; } while (xrl != rl); } else { rl[2].lcn = rl[1].lcn; rl[2].vcn = rl[1].vcn; rl[2].length = rl[1].length; } rl[1].vcn -= na->compression_block_clusters; rl[1].lcn = LCN_HOLE; rl[1].length = na->compression_block_clusters; rl[0].length -= na->compression_block_clusters; if (pos >= (rl[1].vcn << cluster_size_bits)) { rl = ++(*prl); } } NAttrSetRunlistDirty(na); if ((*update_from == -1) || ((*prl)->vcn < *update_from)) *update_from = (*prl)->vcn; } return (compressed_part); } /* * Borrow space from adjacent hole for appending data * The hole may have to be split so that the end of hole is not * affected by cluster allocation and overwriting * Cluster allocation is needed for the overwritten compression block * * Must always leave two unused entries in the runlist * * Returns the number of clusters with existing compressed data * in the compression block to be written to * -1 if there were an error */ static int borrow_from_hole(ntfs_attr *na, runlist_element **prl, s64 pos, s64 count, VCN *update_from, BOOL wasnonresident) { int compressed_part = 0; int cluster_size_bits = na->ni->vol->cluster_size_bits; runlist_element *rl = *prl; s32 endblock; long long allocated; runlist_element *zrl; int irl; BOOL undecided; BOOL nothole; /* check whether the compression block is fully allocated */ endblock = (((pos + count - 1) >> cluster_size_bits) | (na->compression_block_clusters - 1)) + 1 - rl->vcn; allocated = 0; zrl = rl; irl = 0; while (zrl->length && (zrl->lcn >= 0) && (allocated < endblock)) { allocated += zrl->length; zrl++; irl++; } undecided = (allocated < endblock) && (zrl->lcn == LCN_RL_NOT_MAPPED); nothole = (allocated >= endblock) || (zrl->lcn != LCN_HOLE); if (undecided || nothole) { runlist_element *orl = na->rl; s64 olcn = (*prl)->lcn; #if PARTIAL_RUNLIST_UPDATING VCN prevblock; #endif /* * Map the runlist, unless it has not been created. * If appending data, a partial mapping from the * end of previous block will do. */ irl = *prl - na->rl; #if PARTIAL_RUNLIST_UPDATING prevblock = pos >> cluster_size_bits; if (prevblock) prevblock--; if (!NAttrBeingNonResident(na) && (NAttrDataAppending(na) ? ntfs_attr_map_partial_runlist(na,prevblock) : ntfs_attr_map_whole_runlist(na))) { #else if (!NAttrBeingNonResident(na) && ntfs_attr_map_whole_runlist(na)) { #endif rl = (runlist_element*)NULL; } else { /* * Mapping the runlist may cause its relocation, * and relocation may be at the same place with * relocated contents. * Have to find the current run again when this * happens. */ if ((na->rl != orl) || ((*prl)->lcn != olcn)) { zrl = &na->rl[irl]; while (zrl->length && (zrl->lcn != olcn)) zrl++; *prl = zrl; } if (!(*prl)->length) { ntfs_log_error("Mapped run not found," " inode %lld lcn 0x%llx\n", (long long)na->ni->mft_no, (long long)olcn); rl = (runlist_element*)NULL; } else { rl = ntfs_rl_extend(na,*prl,2); na->unused_runs = 2; } } *prl = rl; if (rl && undecided) { allocated = 0; zrl = rl; irl = 0; while (zrl->length && (zrl->lcn >= 0) && (allocated < endblock)) { allocated += zrl->length; zrl++; irl++; } } } /* * compression block not fully allocated and followed * by a hole : we must allocate in the hole. */ if (rl && (allocated < endblock) && (zrl->lcn == LCN_HOLE)) { s64 xofs; /* * split the hole if not fully needed */ if ((allocated + zrl->length) > endblock) { runlist_element *xrl; *prl = ntfs_rl_extend(na,*prl,1); if (*prl) { /* beware : rl was reallocated */ rl = *prl; zrl = &rl[irl]; na->unused_runs = 0; xrl = zrl; while (xrl->length) xrl++; do { xrl[1] = *xrl; } while (xrl-- != zrl); zrl->length = endblock - allocated; zrl[1].length -= zrl->length; zrl[1].vcn = zrl->vcn + zrl->length; NAttrSetRunlistDirty(na); } } if (*prl) { if (wasnonresident) compressed_part = na->compression_block_clusters - zrl->length; xofs = 0; if (ntfs_attr_fill_hole(na, zrl->length << cluster_size_bits, &xofs, &zrl, update_from)) compressed_part = -1; else { /* go back to initial cluster, now reallocated */ while (zrl->vcn > (pos >> cluster_size_bits)) zrl--; *prl = zrl; } } } if (!*prl) { ntfs_log_error("No elements to borrow from a hole\n"); compressed_part = -1; } else if ((*update_from == -1) || ((*prl)->vcn < *update_from)) *update_from = (*prl)->vcn; return (compressed_part); } static int ntfs_attr_truncate_i(ntfs_attr *na, const s64 newsize, hole_type holes); /** * ntfs_attr_pwrite - positioned write to an ntfs attribute * @na: ntfs attribute to write to * @pos: position in the attribute to write to * @count: number of bytes to write * @b: data buffer to write to disk * * This function will write @count bytes from data buffer @b to ntfs attribute * @na at position @pos. * * On success, return the number of successfully written bytes. If this number * is lower than @count this means that an error was encountered during the * write so that the write is partial. 0 means nothing was written (also return * 0 when @count is 0). * * On error and nothing has been written, return -1 with errno set * appropriately to the return code of ntfs_pwrite(), or to EINVAL in case of * invalid arguments. */ static s64 ntfs_attr_pwrite_i(ntfs_attr *na, const s64 pos, s64 count, const void *b) { s64 written, to_write, ofs, old_initialized_size, old_data_size; s64 total = 0; VCN update_from = -1; ntfs_volume *vol; s64 fullcount; ntfs_attr_search_ctx *ctx = NULL; runlist_element *rl; s64 hole_end; int eo; int compressed_part; struct { unsigned int undo_initialized_size : 1; unsigned int undo_data_size : 1; } need_to = { 0, 0 }; BOOL wasnonresident = FALSE; BOOL compressed; vol = na->ni->vol; compressed = (na->data_flags & ATTR_COMPRESSION_MASK) != const_cpu_to_le16(0); na->unused_runs = 0; /* prepare overflow checks */ /* * Encrypted attributes are only supported in raw mode. We return * access denied, which is what Windows NT4 does, too. * Moreover a file cannot be both encrypted and compressed. */ if ((na->data_flags & ATTR_IS_ENCRYPTED) && (compressed || !vol->efs_raw)) { errno = EACCES; goto errno_set; } /* * Fill the gap, when writing beyond the end of a compressed * file. This will make recursive calls */ if (compressed && (na->type == AT_DATA) && (pos > na->initialized_size) && stuff_hole(na,pos)) goto errno_set; /* If this is a compressed attribute it needs special treatment. */ wasnonresident = NAttrNonResident(na) != 0; /* * Compression is restricted to data streams and * only ATTR_IS_COMPRESSED compression mode is supported. */ if (compressed && ((na->type != AT_DATA) || ((na->data_flags & ATTR_COMPRESSION_MASK) != ATTR_IS_COMPRESSED))) { errno = EOPNOTSUPP; goto errno_set; } if (!count) goto out; /* for a compressed file, get prepared to reserve a full block */ fullcount = count; /* If the write reaches beyond the end, extend the attribute. */ old_data_size = na->data_size; /* identify whether this is appending to a non resident data attribute */ if ((na->type == AT_DATA) && (pos >= old_data_size) && NAttrNonResident(na)) NAttrSetDataAppending(na); if (pos + count > na->data_size) { #if PARTIAL_RUNLIST_UPDATING /* * When appending data, the attribute is first extended * before being filled with data. This may cause the * attribute to be made temporarily sparse, which * implies reformating the inode and reorganizing the * full runlist. To avoid unnecessary reorganization, * we avoid sparse testing until the data is filled in. */ if (ntfs_attr_truncate_i(na, pos + count, (NAttrDataAppending(na) ? HOLES_DELAY : HOLES_OK))) { ntfs_log_perror("Failed to enlarge attribute"); goto errno_set; } /* * If we avoided updating the runlist, we must be sure * to cancel the enlargement and put back the runlist to * a clean state if we get into some error. */ if (NAttrDataAppending(na)) need_to.undo_data_size = 1; #else if (ntfs_attr_truncate_i(na, pos + count, HOLES_OK)) { ntfs_log_perror("Failed to enlarge attribute"); goto errno_set; } #endif /* resizing may change the compression mode */ compressed = (na->data_flags & ATTR_COMPRESSION_MASK) != const_cpu_to_le16(0); need_to.undo_data_size = 1; } /* * For compressed data, a single full block was allocated * to deal with compression, possibly in a previous call. * We are not able to process several blocks because * some clusters are freed after compression and * new allocations have to be done before proceeding, * so truncate the requested count if needed (big buffers). */ if (compressed) { fullcount = (pos | (na->compression_block_size - 1)) + 1 - pos; if (count > fullcount) count = fullcount; } old_initialized_size = na->initialized_size; /* If it is a resident attribute, write the data to the mft record. */ if (!NAttrNonResident(na)) { char *val; ctx = ntfs_attr_get_search_ctx(na->ni, NULL); if (!ctx) goto err_out; if (ntfs_attr_lookup(na->type, na->name, na->name_len, 0, 0, NULL, 0, ctx)) { ntfs_log_perror("%s: lookup failed", __FUNCTION__); goto err_out; } val = (char*)ctx->attr + le16_to_cpu(ctx->attr->value_offset); if (val < (char*)ctx->attr || val + le32_to_cpu(ctx->attr->value_length) > (char*)ctx->mrec + vol->mft_record_size) { errno = EIO; ntfs_log_perror("%s: Sanity check failed", __FUNCTION__); goto err_out; } memcpy(val + pos, b, count); if (ntfs_mft_record_write(vol, ctx->ntfs_ino->mft_no, ctx->mrec)) { /* * NOTE: We are in a bad state at this moment. We have * dirtied the mft record but we failed to commit it to * disk. Since we have read the mft record ok before, * it is unlikely to fail writing it, so is ok to just * return error here... (AIA) */ ntfs_log_perror("%s: failed to write mft record", __FUNCTION__); goto err_out; } ntfs_attr_put_search_ctx(ctx); total = count; goto out; } /* Handle writes beyond initialized_size. */ if (pos + count > na->initialized_size) { #if PARTIAL_RUNLIST_UPDATING /* * When appending, we only need to map the end of the runlist, * starting at the last previously allocated run, so that * we are able a new one to it. * However, for compressed file, we need the full compression * block, which may be split in several extents. */ if (compressed && !NAttrDataAppending(na)) { if (ntfs_attr_map_whole_runlist(na)) goto err_out; } else { VCN block_begin; if (NAttrDataAppending(na) || (pos < na->initialized_size)) block_begin = pos >> vol->cluster_size_bits; else block_begin = na->initialized_size >> vol->cluster_size_bits; if (compressed) block_begin &= -na->compression_block_clusters; if (block_begin) block_begin--; if (ntfs_attr_map_partial_runlist(na, block_begin)) goto err_out; if ((update_from == -1) || (block_begin < update_from)) update_from = block_begin; } #else if (ntfs_attr_map_whole_runlist(na)) goto err_out; #endif /* * For a compressed attribute, we must be sure there is an * available entry, and, when reopening a compressed file, * we may need to split a hole. So reserve the entries * before it gets too late. */ if (compressed) { na->rl = ntfs_rl_extend(na,na->rl,2); if (!na->rl) goto err_out; na->unused_runs = 2; } /* Set initialized_size to @pos + @count. */ ctx = ntfs_attr_get_search_ctx(na->ni, NULL); if (!ctx) goto err_out; if (ntfs_attr_lookup(na->type, na->name, na->name_len, 0, 0, NULL, 0, ctx)) goto err_out; /* If write starts beyond initialized_size, zero the gap. */ if (pos > na->initialized_size) if (ntfs_attr_fill_zero(na, na->initialized_size, pos - na->initialized_size)) goto err_out; ctx->attr->initialized_size = cpu_to_sle64(pos + count); /* fix data_size for compressed files */ if (compressed) { na->data_size = pos + count; ctx->attr->data_size = ctx->attr->initialized_size; } if (ntfs_mft_record_write(vol, ctx->ntfs_ino->mft_no, ctx->mrec)) { /* * Undo the change in the in-memory copy and send it * back for writing. */ ctx->attr->initialized_size = cpu_to_sle64(old_initialized_size); ntfs_mft_record_write(vol, ctx->ntfs_ino->mft_no, ctx->mrec); goto err_out; } na->initialized_size = pos + count; #if CACHE_NIDATA_SIZE if (na->ni->mrec->flags & MFT_RECORD_IS_DIRECTORY ? na->type == AT_INDEX_ROOT && na->name == NTFS_INDEX_I30 : na->type == AT_DATA && na->name == AT_UNNAMED) { na->ni->data_size = na->data_size; if ((compressed || NAttrSparse(na)) && NAttrNonResident(na)) na->ni->allocated_size = na->compressed_size; else na->ni->allocated_size = na->allocated_size; set_nino_flag(na->ni,KnownSize); } #endif ntfs_attr_put_search_ctx(ctx); ctx = NULL; /* * NOTE: At this point the initialized_size in the mft record * has been updated BUT there is random data on disk thus if * we decide to abort, we MUST change the initialized_size * again. */ need_to.undo_initialized_size = 1; } /* Find the runlist element containing the vcn. */ rl = ntfs_attr_find_vcn(na, pos >> vol->cluster_size_bits); if (!rl) { /* * If the vcn is not present it is an out of bounds write. * However, we already extended the size of the attribute, * so getting this here must be an error of some kind. */ if (errno == ENOENT) { errno = EIO; ntfs_log_perror("%s: Failed to find VCN #3", __FUNCTION__); } goto err_out; } /* * Determine if there is compressed data in the current * compression block (when appending to an existing file). * If so, decompression will be needed, and the full block * must be allocated to be identified as uncompressed. * This comes in two variants, depending on whether * compression has saved at least one cluster. * The compressed size can never be over full size by * more than 485 (maximum for 15 compression blocks * compressed to 4098 and the last 3640 bytes compressed * to 3640 + 3640/8 = 4095, with 15*2 + 4095 - 3640 = 485) * This is less than the smallest cluster, so the hole is * is never beyond the cluster next to the position of * the first uncompressed byte to write. */ compressed_part = 0; if (compressed) { if ((rl->lcn == (LCN)LCN_HOLE) && wasnonresident) { if (rl->length < na->compression_block_clusters) /* * the needed block is in a hole smaller * than the compression block : we can use * it fully */ compressed_part = na->compression_block_clusters - rl->length; else { /* * the needed block is in a hole bigger * than the compression block : we must * split the hole and use it partially */ compressed_part = split_compressed_hole(na, &rl, pos, count, &update_from); } } else { if (rl->lcn >= 0) { /* * the needed block contains data, make * sure the full compression block is * allocated. Borrow from hole if needed */ compressed_part = borrow_from_hole(na, &rl, pos, count, &update_from, wasnonresident); } } if (compressed_part < 0) goto err_out; /* just making non-resident, so not yet compressed */ if (NAttrBeingNonResident(na) && (compressed_part < na->compression_block_clusters)) compressed_part = 0; } ofs = pos - (rl->vcn << vol->cluster_size_bits); /* * Scatter the data from the linear data buffer to the volume. Note, a * partial final vcn is taken care of by the @count capping of write * length. */ for (hole_end = 0; count; rl++, ofs = 0) { if (rl->lcn == LCN_RL_NOT_MAPPED) { rl = ntfs_attr_find_vcn(na, rl->vcn); if (!rl) { if (errno == ENOENT) { errno = EIO; ntfs_log_perror("%s: Failed to find VCN" " #4", __FUNCTION__); } goto rl_err_out; } /* Needed for case when runs merged. */ ofs = pos + total - (rl->vcn << vol->cluster_size_bits); } if (!rl->length) { errno = EIO; ntfs_log_perror("%s: Zero run length", __FUNCTION__); goto rl_err_out; } if (rl->lcn < (LCN)0) { hole_end = rl->vcn + rl->length; if (rl->lcn != (LCN)LCN_HOLE) { errno = EIO; ntfs_log_perror("%s: Unexpected LCN (%lld)", __FUNCTION__, (long long)rl->lcn); goto rl_err_out; } if (ntfs_attr_fill_hole(na, fullcount, &ofs, &rl, &update_from)) goto err_out; } if (compressed) { while (rl->length && (ofs >= (rl->length << vol->cluster_size_bits))) { ofs -= rl->length << vol->cluster_size_bits; rl++; } } /* It is a real lcn, write it to the volume. */ to_write = min(count, (rl->length << vol->cluster_size_bits) - ofs); retry: ntfs_log_trace("Writing %lld bytes to vcn %lld, lcn %lld, ofs " "%lld.\n", (long long)to_write, (long long)rl->vcn, (long long)rl->lcn, (long long)ofs); if (!NVolReadOnly(vol)) { s64 wpos = (rl->lcn << vol->cluster_size_bits) + ofs; s64 wend = (rl->vcn << vol->cluster_size_bits) + ofs + to_write; u32 bsize = vol->cluster_size; /* Byte size needed to zero fill a cluster */ s64 rounding = ((wend + bsize - 1) & ~(s64)(bsize - 1)) - wend; /** * Zero fill to cluster boundary if we're writing at the * end of the attribute or into an ex-sparse cluster. * This will cause the kernel not to seek and read disk * blocks during write(2) to fill the end of the buffer * which increases write speed by 2-10 fold typically. * * This is done even for compressed files, because * data is generally first written uncompressed. */ if (rounding && ((wend == na->initialized_size) || (wend < (hole_end << vol->cluster_size_bits)))){ char *cb; rounding += to_write; cb = ntfs_malloc(rounding); if (!cb) goto err_out; memcpy(cb, b, to_write); memset(cb + to_write, 0, rounding - to_write); if (compressed) { written = ntfs_compressed_pwrite(na, rl, wpos, ofs, to_write, rounding, cb, compressed_part, &update_from); } else { written = ntfs_pwrite(vol->dev, wpos, rounding, cb); if (written == rounding) written = to_write; } free(cb); } else { if (compressed) { written = ntfs_compressed_pwrite(na, rl, wpos, ofs, to_write, to_write, b, compressed_part, &update_from); } else written = ntfs_pwrite(vol->dev, wpos, to_write, b); } } else written = to_write; /* If everything ok, update progress counters and continue. */ if (written > 0) { total += written; count -= written; fullcount -= written; b = (const u8*)b + written; } if (written != to_write) { /* Partial write cannot be dealt with, stop there */ /* If the syscall was interrupted, try again. */ if (written == (s64)-1 && errno == EINTR) goto retry; if (!written) errno = EIO; goto rl_err_out; } compressed_part = 0; } done: if (ctx) ntfs_attr_put_search_ctx(ctx); /* * Update mapping pairs if needed. * For a compressed file, we try to make a partial update * of the mapping list. This makes a difference only if * inode extents were needed. */ if (NAttrRunlistDirty(na)) { if (ntfs_attr_update_mapping_pairs(na, (update_from < 0 ? 0 : update_from))) { /* * FIXME: trying to recover by goto rl_err_out; * could cause driver hang by infinite looping. */ total = -1; goto out; } if (!wasnonresident) NAttrClearBeingNonResident(na); NAttrClearDataAppending(na); } out: return total; rl_err_out: eo = errno; if (total) { if (need_to.undo_initialized_size) { if (pos + total > na->initialized_size) goto done; /* * TODO: Need to try to change initialized_size. If it * succeeds goto done, otherwise goto err_out. (AIA) */ goto err_out; } goto done; } errno = eo; err_out: eo = errno; if (need_to.undo_initialized_size) { int err; err = 0; if (!ctx) { ctx = ntfs_attr_get_search_ctx(na->ni, NULL); if (!ctx) err = 1; } else ntfs_attr_reinit_search_ctx(ctx); if (!err) { err = ntfs_attr_lookup(na->type, na->name, na->name_len, 0, 0, NULL, 0, ctx); if (!err) { na->initialized_size = old_initialized_size; ctx->attr->initialized_size = cpu_to_sle64( old_initialized_size); err = ntfs_mft_record_write(vol, ctx->ntfs_ino->mft_no, ctx->mrec); } } if (err) { /* * FIXME: At this stage could try to recover by filling * old_initialized_size -> new_initialized_size with * data or at least zeroes. (AIA) */ ntfs_log_error("Eeek! Failed to recover from error. " "Leaving metadata in inconsistent " "state! Run chkdsk!\n"); } } if (ctx) ntfs_attr_put_search_ctx(ctx); /* Update mapping pairs if needed. */ if (NAttrRunlistDirty(na)) ntfs_attr_update_mapping_pairs(na, 0); /* Restore original data_size if needed. */ if (need_to.undo_data_size && ntfs_attr_truncate_i(na, old_data_size, HOLES_OK)) ntfs_log_perror("Failed to restore data_size"); errno = eo; errno_set: total = -1; goto out; } s64 ntfs_attr_pwrite(ntfs_attr *na, const s64 pos, s64 count, const void *b) { s64 total; s64 written; ntfs_log_enter("Entering for inode %lld, attr 0x%x, pos 0x%llx, count " "0x%llx.\n", (long long)na->ni->mft_no, le32_to_cpu(na->type), (long long)pos, (long long)count); total = 0; if (!na || !na->ni || !na->ni->vol || !b || pos < 0 || count < 0) { errno = EINVAL; written = -1; ntfs_log_perror("%s", __FUNCTION__); goto out; } /* * Compressed attributes may be written partially, so * we may have to iterate. */ do { written = ntfs_attr_pwrite_i(na, pos + total, count - total, (const u8*)b + total); if (written > 0) total += written; } while ((written > 0) && (total < count)); out : ntfs_log_leave("\n"); return (total > 0 ? total : written); } int ntfs_attr_pclose(ntfs_attr *na) { s64 ofs; int failed; BOOL ok = TRUE; VCN update_from = -1; ntfs_volume *vol; ntfs_attr_search_ctx *ctx = NULL; runlist_element *rl; int eo; int compressed_part; BOOL compressed; ntfs_log_enter("Entering for inode 0x%llx, attr 0x%x.\n", (unsigned long long)na->ni->mft_no, le32_to_cpu(na->type)); if (!na || !na->ni || !na->ni->vol) { errno = EINVAL; ntfs_log_perror("%s", __FUNCTION__); goto errno_set; } vol = na->ni->vol; na->unused_runs = 0; compressed = (na->data_flags & ATTR_COMPRESSION_MASK) != const_cpu_to_le16(0); /* * Encrypted non-resident attributes are not supported. We return * access denied, which is what Windows NT4 does, too. */ if (NAttrEncrypted(na) && NAttrNonResident(na)) { errno = EACCES; goto errno_set; } /* If this is not a compressed attribute get out */ /* same if it is resident */ if (!compressed || !NAttrNonResident(na)) goto out; /* safety check : no recursion on close */ if (NAttrComprClosing(na)) { errno = EIO; ntfs_log_error("Bad ntfs_attr_pclose" " recursion on inode %lld\n", (long long)na->ni->mft_no); goto out; } NAttrSetComprClosing(na); /* * For a compressed attribute, we must be sure there are two * available entries, so reserve them before it gets too late. */ if (ntfs_attr_map_whole_runlist(na)) goto err_out; na->rl = ntfs_rl_extend(na,na->rl,2); if (!na->rl) goto err_out; na->unused_runs = 2; /* Find the runlist element containing the terminal vcn. */ rl = ntfs_attr_find_vcn(na, (na->initialized_size - 1) >> vol->cluster_size_bits); if (!rl) { /* * If the vcn is not present it is an out of bounds write. * However, we have already written the last byte uncompressed, * so getting this here must be an error of some kind. */ if (errno == ENOENT) { errno = EIO; ntfs_log_perror("%s: Failed to find VCN #5", __FUNCTION__); } goto err_out; } /* * Scatter the data from the linear data buffer to the volume. Note, a * partial final vcn is taken care of by the @count capping of write * length. */ compressed_part = 0; if (rl->lcn >= 0) { runlist_element *xrl; xrl = rl; do { xrl++; } while (xrl->lcn >= 0); compressed_part = (-xrl->length) & (na->compression_block_clusters - 1); } else if (rl->lcn == (LCN)LCN_HOLE) { if (rl->length < na->compression_block_clusters) compressed_part = na->compression_block_clusters - rl->length; else compressed_part = na->compression_block_clusters; } /* done, if the last block set was compressed */ if (compressed_part) goto out; ofs = na->initialized_size - (rl->vcn << vol->cluster_size_bits); if (rl->lcn == LCN_RL_NOT_MAPPED) { rl = ntfs_attr_find_vcn(na, rl->vcn); if (!rl) { if (errno == ENOENT) { errno = EIO; ntfs_log_perror("%s: Failed to find VCN" " #6", __FUNCTION__); } goto rl_err_out; } /* Needed for case when runs merged. */ ofs = na->initialized_size - (rl->vcn << vol->cluster_size_bits); } if (!rl->length) { errno = EIO; ntfs_log_perror("%s: Zero run length", __FUNCTION__); goto rl_err_out; } if (rl->lcn < (LCN)0) { if (rl->lcn != (LCN)LCN_HOLE) { errno = EIO; ntfs_log_perror("%s: Unexpected LCN (%lld)", __FUNCTION__, (long long)rl->lcn); goto rl_err_out; } if (ntfs_attr_fill_hole(na, (s64)0, &ofs, &rl, &update_from)) goto err_out; } while (rl->length && (ofs >= (rl->length << vol->cluster_size_bits))) { ofs -= rl->length << vol->cluster_size_bits; rl++; } retry: failed = 0; if (update_from < 0) update_from = 0; if (!NVolReadOnly(vol)) { failed = ntfs_compressed_close(na, rl, ofs, &update_from); #if CACHE_NIDATA_SIZE if (na->ni->mrec->flags & MFT_RECORD_IS_DIRECTORY ? na->type == AT_INDEX_ROOT && na->name == NTFS_INDEX_I30 : na->type == AT_DATA && na->name == AT_UNNAMED) { na->ni->data_size = na->data_size; na->ni->allocated_size = na->compressed_size; set_nino_flag(na->ni,KnownSize); } #endif } if (failed) { /* If the syscall was interrupted, try again. */ if (errno == EINTR) goto retry; else goto rl_err_out; } if (ctx) ntfs_attr_put_search_ctx(ctx); /* Update mapping pairs if needed. */ if (NAttrFullyMapped(na)) if (ntfs_attr_update_mapping_pairs(na, update_from)) { /* * FIXME: trying to recover by goto rl_err_out; * could cause driver hang by infinite looping. */ ok = FALSE; goto out; } out: NAttrClearComprClosing(na); ntfs_log_leave("\n"); return (!ok); rl_err_out: /* * need not restore old sizes, only compressed_size * can have changed. It has been set according to * the current runlist while updating the mapping pairs, * and must be kept consistent with the runlists. */ err_out: eo = errno; if (ctx) ntfs_attr_put_search_ctx(ctx); /* Update mapping pairs if needed. */ if (NAttrFullyMapped(na)) ntfs_attr_update_mapping_pairs(na, 0); errno = eo; errno_set: ok = FALSE; goto out; } /** * ntfs_attr_mst_pread - multi sector transfer protected ntfs attribute read * @na: multi sector transfer protected ntfs attribute to read from * @pos: byte position in the attribute to begin reading from * @bk_cnt: number of mst protected blocks to read * @bk_size: size of each mst protected block in bytes * @dst: output data buffer * * This function will read @bk_cnt blocks of size @bk_size bytes each starting * at offset @pos from the ntfs attribute @na into the data buffer @b. * * On success, the multi sector transfer fixups are applied and the number of * read blocks is returned. If this number is lower than @bk_cnt this means * that the read has either reached end of attribute or that an error was * encountered during the read so that the read is partial. 0 means end of * attribute or nothing to read (also return 0 when @bk_cnt or @bk_size are 0). * * On error and nothing has been read, return -1 with errno set appropriately * to the return code of ntfs_attr_pread() or to EINVAL in case of invalid * arguments. * * NOTE: If an incomplete multi sector transfer is detected the magic is * changed to BAAD but no error is returned, i.e. it is possible that any of * the returned blocks have multi sector transfer errors. This should be * detected by the caller by checking each block with is_baad_recordp(&block). * The reasoning is that we want to fixup as many blocks as possible and we * want to return even bad ones to the caller so, e.g. in case of ntfsck, the * errors can be repaired. */ s64 ntfs_attr_mst_pread(ntfs_attr *na, const s64 pos, const s64 bk_cnt, const u32 bk_size, void *dst) { s64 br; u8 *end; BOOL warn; ntfs_log_trace("Entering for inode 0x%llx, attr type 0x%x, pos 0x%llx.\n", (unsigned long long)na->ni->mft_no, le32_to_cpu(na->type), (long long)pos); if (bk_cnt < 0 || bk_size % NTFS_BLOCK_SIZE) { errno = EINVAL; ntfs_log_perror("%s", __FUNCTION__); return -1; } br = ntfs_attr_pread(na, pos, bk_cnt * bk_size, dst); if (br <= 0) return br; br /= bk_size; /* log errors unless silenced */ warn = !na->ni || !na->ni->vol || !NVolNoFixupWarn(na->ni->vol); for (end = (u8*)dst + br * bk_size; (u8*)dst < end; dst = (u8*)dst + bk_size) ntfs_mst_post_read_fixup_warn((NTFS_RECORD*)dst, bk_size, warn); /* Finally, return the number of blocks read. */ return br; } /** * ntfs_attr_mst_pwrite - multi sector transfer protected ntfs attribute write * @na: multi sector transfer protected ntfs attribute to write to * @pos: position in the attribute to write to * @bk_cnt: number of mst protected blocks to write * @bk_size: size of each mst protected block in bytes * @src: data buffer to write to disk * * This function will write @bk_cnt blocks of size @bk_size bytes each from * data buffer @b to multi sector transfer (mst) protected ntfs attribute @na * at position @pos. * * On success, return the number of successfully written blocks. If this number * is lower than @bk_cnt this means that an error was encountered during the * write so that the write is partial. 0 means nothing was written (also * return 0 when @bk_cnt or @bk_size are 0). * * On error and nothing has been written, return -1 with errno set * appropriately to the return code of ntfs_attr_pwrite(), or to EINVAL in case * of invalid arguments. * * NOTE: We mst protect the data, write it, then mst deprotect it using a quick * deprotect algorithm (no checking). This saves us from making a copy before * the write and at the same time causes the usn to be incremented in the * buffer. This conceptually fits in better with the idea that cached data is * always deprotected and protection is performed when the data is actually * going to hit the disk and the cache is immediately deprotected again * simulating an mst read on the written data. This way cache coherency is * achieved. */ s64 ntfs_attr_mst_pwrite(ntfs_attr *na, const s64 pos, s64 bk_cnt, const u32 bk_size, void *src) { s64 written, i; ntfs_log_trace("Entering for inode 0x%llx, attr type 0x%x, pos 0x%llx.\n", (unsigned long long)na->ni->mft_no, le32_to_cpu(na->type), (long long)pos); if (bk_cnt < 0 || bk_size % NTFS_BLOCK_SIZE) { errno = EINVAL; return -1; } if (!bk_cnt) return 0; /* Prepare data for writing. */ for (i = 0; i < bk_cnt; ++i) { int err; err = ntfs_mst_pre_write_fixup((NTFS_RECORD*) ((u8*)src + i * bk_size), bk_size); if (err < 0) { /* Abort write at this position. */ ntfs_log_perror("%s #1", __FUNCTION__); if (!i) return err; bk_cnt = i; break; } } /* Write the prepared data. */ written = ntfs_attr_pwrite(na, pos, bk_cnt * bk_size, src); if (written <= 0) { ntfs_log_perror("%s: written=%lld", __FUNCTION__, (long long)written); } /* Quickly deprotect the data again. */ for (i = 0; i < bk_cnt; ++i) ntfs_mst_post_write_fixup((NTFS_RECORD*)((u8*)src + i * bk_size)); if (written <= 0) return written; /* Finally, return the number of complete blocks written. */ return written / bk_size; } /** * ntfs_attr_find - find (next) attribute in mft record * @type: attribute type to find * @name: attribute name to find (optional, i.e. NULL means don't care) * @name_len: attribute name length (only needed if @name present) * @ic: IGNORE_CASE or CASE_SENSITIVE (ignored if @name not present) * @val: attribute value to find (optional, resident attributes only) * @val_len: attribute value length * @ctx: search context with mft record and attribute to search from * * You shouldn't need to call this function directly. Use lookup_attr() instead. * * ntfs_attr_find() takes a search context @ctx as parameter and searches the * mft record specified by @ctx->mrec, beginning at @ctx->attr, for an * attribute of @type, optionally @name and @val. If found, ntfs_attr_find() * returns 0 and @ctx->attr will point to the found attribute. * * If not found, ntfs_attr_find() returns -1, with errno set to ENOENT and * @ctx->attr will point to the attribute before which the attribute being * searched for would need to be inserted if such an action were to be desired. * * On actual error, ntfs_attr_find() returns -1 with errno set to the error * code but not to ENOENT. In this case @ctx->attr is undefined and in * particular do not rely on it not changing. * * If @ctx->is_first is TRUE, the search begins with @ctx->attr itself. If it * is FALSE, the search begins after @ctx->attr. * * If @type is AT_UNUSED, return the first found attribute, i.e. one can * enumerate all attributes by setting @type to AT_UNUSED and then calling * ntfs_attr_find() repeatedly until it returns -1 with errno set to ENOENT to * indicate that there are no more entries. During the enumeration, each * successful call of ntfs_attr_find() will return the next attribute in the * mft record @ctx->mrec. * * If @type is AT_END, seek to the end and return -1 with errno set to ENOENT. * AT_END is not a valid attribute, its length is zero for example, thus it is * safer to return error instead of success in this case. This also allows us * to interoperate cleanly with ntfs_external_attr_find(). * * If @name is AT_UNNAMED search for an unnamed attribute. If @name is present * but not AT_UNNAMED search for a named attribute matching @name. Otherwise, * match both named and unnamed attributes. * * If @ic is IGNORE_CASE, the @name comparison is not case sensitive and * @ctx->ntfs_ino must be set to the ntfs inode to which the mft record * @ctx->mrec belongs. This is so we can get at the ntfs volume and hence at * the upcase table. If @ic is CASE_SENSITIVE, the comparison is case * sensitive. When @name is present, @name_len is the @name length in Unicode * characters. * * If @name is not present (NULL), we assume that the unnamed attribute is * being searched for. * * Finally, the resident attribute value @val is looked for, if present. * If @val is not present (NULL), @val_len is ignored. * * ntfs_attr_find() only searches the specified mft record and it ignores the * presence of an attribute list attribute (unless it is the one being searched * for, obviously). If you need to take attribute lists into consideration, use * ntfs_attr_lookup() instead (see below). This also means that you cannot use * ntfs_attr_find() to search for extent records of non-resident attributes, as * extents with lowest_vcn != 0 are usually described by the attribute list * attribute only. - Note that it is possible that the first extent is only in * the attribute list while the last extent is in the base mft record, so don't * rely on being able to find the first extent in the base mft record. * * Warning: Never use @val when looking for attribute types which can be * non-resident as this most likely will result in a crash! */ static int ntfs_attr_find(const ATTR_TYPES type, const ntfschar *name, const u32 name_len, const IGNORE_CASE_BOOL ic, const u8 *val, const u32 val_len, ntfs_attr_search_ctx *ctx) { ATTR_RECORD *a; ntfs_volume *vol; ntfschar *upcase; ptrdiff_t offs; ptrdiff_t space; u32 upcase_len; ntfs_log_trace("attribute type 0x%x.\n", le32_to_cpu(type)); if (ctx->ntfs_ino) { vol = ctx->ntfs_ino->vol; upcase = vol->upcase; upcase_len = vol->upcase_len; } else { if (name && name != AT_UNNAMED) { errno = EINVAL; ntfs_log_perror("%s", __FUNCTION__); return -1; } vol = NULL; upcase = NULL; upcase_len = 0; } /* * Iterate over attributes in mft record starting at @ctx->attr, or the * attribute following that, if @ctx->is_first is TRUE. */ if (ctx->is_first) { a = ctx->attr; ctx->is_first = FALSE; } else a = (ATTR_RECORD*)((char*)ctx->attr + le32_to_cpu(ctx->attr->length)); for (;; a = (ATTR_RECORD*)((char*)a + le32_to_cpu(a->length))) { /* * Make sure the attribute fully lies within the MFT record * and we can safely access its minimal fields. */ offs = p2n(a) - p2n(ctx->mrec); space = le32_to_cpu(ctx->mrec->bytes_in_use) - offs; if ((offs < 0) || (((space < (ptrdiff_t)offsetof(ATTR_RECORD, resident_end)) || (space < (ptrdiff_t)le32_to_cpu(a->length))) && ((space < 4) || (a->type != AT_END)))) break; ctx->attr = a; if (((type != AT_UNUSED) && (le32_to_cpu(a->type) > le32_to_cpu(type))) || (a->type == AT_END)) { errno = ENOENT; return -1; } if (!a->length) break; /* If this is an enumeration return this attribute. */ if (type == AT_UNUSED) return 0; if (a->type != type) continue; /* * If @name is AT_UNNAMED we want an unnamed attribute. * If @name is present, compare the two names. * Otherwise, match any attribute. */ if (name == AT_UNNAMED) { /* The search failed if the found attribute is named. */ if (a->name_length) { errno = ENOENT; return -1; } } else { register int rc; if (a->name_length && ((le16_to_cpu(a->name_offset) + a->name_length * sizeof(ntfschar)) > le32_to_cpu(a->length))) { ntfs_log_error("Corrupt attribute name" " in MFT record %lld\n", (long long)ctx->ntfs_ino->mft_no); break; } if (name && ((rc = ntfs_names_full_collate(name, name_len, (ntfschar*)((char*)a + le16_to_cpu(a->name_offset)), a->name_length, ic, upcase, upcase_len)))) { /* * If @name collates before a->name, * there is no matching attribute. */ if (rc < 0) { errno = ENOENT; return -1; } /* If the strings are not equal, continue search. */ continue; } } /* * The names match or @name not present and attribute is * unnamed. If no @val specified, we have found the attribute * and are done. */ if (!val) return 0; /* @val is present; compare values. */ else { register int rc; rc = memcmp(val, (char*)a +le16_to_cpu(a->value_offset), min(val_len, le32_to_cpu(a->value_length))); /* * If @val collates before the current attribute's * value, there is no matching attribute. */ if (!rc) { register u32 avl; avl = le32_to_cpu(a->value_length); if (val_len == avl) return 0; if (val_len < avl) { errno = ENOENT; return -1; } } else if (rc < 0) { errno = ENOENT; return -1; } } } errno = EIO; ntfs_log_perror("%s: Corrupt inode (%lld)", __FUNCTION__, ctx->ntfs_ino ? (long long)ctx->ntfs_ino->mft_no : -1); return -1; } void ntfs_attr_name_free(char **name) { if (*name) { free(*name); *name = NULL; } } char *ntfs_attr_name_get(const ntfschar *uname, const int uname_len) { char *name = NULL; int name_len; name_len = ntfs_ucstombs(uname, uname_len, &name, 0); if (name_len < 0) { ntfs_log_perror("ntfs_ucstombs"); return NULL; } else if (name_len > 0) return name; ntfs_attr_name_free(&name); return NULL; } /** * ntfs_external_attr_find - find an attribute in the attribute list of an inode * @type: attribute type to find * @name: attribute name to find (optional, i.e. NULL means don't care) * @name_len: attribute name length (only needed if @name present) * @ic: IGNORE_CASE or CASE_SENSITIVE (ignored if @name not present) * @lowest_vcn: lowest vcn to find (optional, non-resident attributes only) * @val: attribute value to find (optional, resident attributes only) * @val_len: attribute value length * @ctx: search context with mft record and attribute to search from * * You shouldn't need to call this function directly. Use ntfs_attr_lookup() * instead. * * Find an attribute by searching the attribute list for the corresponding * attribute list entry. Having found the entry, map the mft record for read * if the attribute is in a different mft record/inode, find the attribute in * there and return it. * * If @type is AT_UNUSED, return the first found attribute, i.e. one can * enumerate all attributes by setting @type to AT_UNUSED and then calling * ntfs_external_attr_find() repeatedly until it returns -1 with errno set to * ENOENT to indicate that there are no more entries. During the enumeration, * each successful call of ntfs_external_attr_find() will return the next * attribute described by the attribute list of the base mft record described * by the search context @ctx. * * If @type is AT_END, seek to the end of the base mft record ignoring the * attribute list completely and return -1 with errno set to ENOENT. AT_END is * not a valid attribute, its length is zero for example, thus it is safer to * return error instead of success in this case. * * If @name is AT_UNNAMED search for an unnamed attribute. If @name is present * but not AT_UNNAMED search for a named attribute matching @name. Otherwise, * match both named and unnamed attributes. * * On first search @ctx->ntfs_ino must be the inode of the base mft record and * @ctx must have been obtained from a call to ntfs_attr_get_search_ctx(). * On subsequent calls, @ctx->ntfs_ino can be any extent inode, too * (@ctx->base_ntfs_ino is then the base inode). * * After finishing with the attribute/mft record you need to call * ntfs_attr_put_search_ctx() to cleanup the search context (unmapping any * mapped extent inodes, etc). * * Return 0 if the search was successful and -1 if not, with errno set to the * error code. * * On success, @ctx->attr is the found attribute, it is in mft record * @ctx->mrec, and @ctx->al_entry is the attribute list entry for this * attribute with @ctx->base_* being the base mft record to which @ctx->attr * belongs. * * On error ENOENT, i.e. attribute not found, @ctx->attr is set to the * attribute which collates just after the attribute being searched for in the * base ntfs inode, i.e. if one wants to add the attribute to the mft record * this is the correct place to insert it into, and if there is not enough * space, the attribute should be placed in an extent mft record. * @ctx->al_entry points to the position within @ctx->base_ntfs_ino->attr_list * at which the new attribute's attribute list entry should be inserted. The * other @ctx fields, base_ntfs_ino, base_mrec, and base_attr are set to NULL. * The only exception to this is when @type is AT_END, in which case * @ctx->al_entry is set to NULL also (see above). * * The following error codes are defined: * ENOENT Attribute not found, not an error as such. * EINVAL Invalid arguments. * EIO I/O error or corrupt data structures found. * ENOMEM Not enough memory to allocate necessary buffers. */ static int ntfs_external_attr_find(ATTR_TYPES type, const ntfschar *name, const u32 name_len, const IGNORE_CASE_BOOL ic, const VCN lowest_vcn, const u8 *val, const u32 val_len, ntfs_attr_search_ctx *ctx) { ntfs_inode *base_ni, *ni; ntfs_volume *vol; ATTR_LIST_ENTRY *al_entry, *next_al_entry; u8 *al_start, *al_end; ATTR_RECORD *a; ntfschar *al_name; ptrdiff_t offs; ptrdiff_t space; u32 al_name_len; BOOL is_first_search = FALSE; ni = ctx->ntfs_ino; base_ni = ctx->base_ntfs_ino; ntfs_log_trace("Entering for inode %lld, attribute type 0x%x.\n", (unsigned long long)ni->mft_no, le32_to_cpu(type)); if (!base_ni) { /* First call happens with the base mft record. */ base_ni = ctx->base_ntfs_ino = ctx->ntfs_ino; ctx->base_mrec = ctx->mrec; } if (ni == base_ni) ctx->base_attr = ctx->attr; if (type == AT_END) goto not_found; vol = base_ni->vol; al_start = base_ni->attr_list; al_end = al_start + base_ni->attr_list_size; if (!ctx->al_entry) { ctx->al_entry = (ATTR_LIST_ENTRY*)al_start; is_first_search = TRUE; } /* * Iterate over entries in attribute list starting at @ctx->al_entry, * or the entry following that, if @ctx->is_first is TRUE. */ if (ctx->is_first) { al_entry = ctx->al_entry; ctx->is_first = FALSE; /* * If an enumeration and the first attribute is higher than * the attribute list itself, need to return the attribute list * attribute. */ if ((type == AT_UNUSED) && is_first_search && le32_to_cpu(al_entry->type) > le32_to_cpu(AT_ATTRIBUTE_LIST)) goto find_attr_list_attr; } else { /* Check for small entry */ if (((p2n(al_end) - p2n(ctx->al_entry)) < (long)offsetof(ATTR_LIST_ENTRY, name)) || (le16_to_cpu(ctx->al_entry->length) & 7) || (le16_to_cpu(ctx->al_entry->length) < offsetof(ATTR_LIST_ENTRY, name))) goto corrupt; al_entry = (ATTR_LIST_ENTRY*)((char*)ctx->al_entry + le16_to_cpu(ctx->al_entry->length)); if ((u8*)al_entry == al_end) goto not_found; /* Preliminary check for small entry */ if ((p2n(al_end) - p2n(al_entry)) < (long)offsetof(ATTR_LIST_ENTRY, name)) goto corrupt; /* * If this is an enumeration and the attribute list attribute * is the next one in the enumeration sequence, just return the * attribute list attribute from the base mft record as it is * not listed in the attribute list itself. */ if ((type == AT_UNUSED) && le32_to_cpu(ctx->al_entry->type) < le32_to_cpu(AT_ATTRIBUTE_LIST) && le32_to_cpu(al_entry->type) > le32_to_cpu(AT_ATTRIBUTE_LIST)) { int rc; find_attr_list_attr: /* Check for bogus calls. */ if (name || name_len || val || val_len || lowest_vcn) { errno = EINVAL; ntfs_log_perror("%s", __FUNCTION__); return -1; } /* We want the base record. */ ctx->ntfs_ino = base_ni; ctx->mrec = ctx->base_mrec; ctx->is_first = TRUE; /* Sanity checks are performed elsewhere. */ ctx->attr = (ATTR_RECORD*)((u8*)ctx->mrec + le16_to_cpu(ctx->mrec->attrs_offset)); /* Find the attribute list attribute. */ rc = ntfs_attr_find(AT_ATTRIBUTE_LIST, NULL, 0, IGNORE_CASE, NULL, 0, ctx); /* * Setup the search context so the correct * attribute is returned next time round. */ ctx->al_entry = al_entry; ctx->is_first = TRUE; /* Got it. Done. */ if (!rc) return 0; /* Error! If other than not found return it. */ if (errno != ENOENT) return rc; /* Not found?!? Absurd! */ errno = EIO; ntfs_log_error("Attribute list wasn't found"); return -1; } } for (;; al_entry = next_al_entry) { /* Out of bounds check. */ if ((u8*)al_entry < base_ni->attr_list || (u8*)al_entry > al_end) break; /* Inode is corrupt. */ ctx->al_entry = al_entry; /* Catch the end of the attribute list. */ if ((u8*)al_entry == al_end) goto not_found; if ((((u8*)al_entry + offsetof(ATTR_LIST_ENTRY, name)) > al_end) || ((u8*)al_entry + le16_to_cpu(al_entry->length) > al_end) || (le16_to_cpu(al_entry->length) & 7) || (le16_to_cpu(al_entry->length) < offsetof(ATTR_LIST_ENTRY, name_length)) || (al_entry->name_length && ((u8*)al_entry + al_entry->name_offset + al_entry->name_length * sizeof(ntfschar)) > al_end)) break; /* corrupt */ next_al_entry = (ATTR_LIST_ENTRY*)((u8*)al_entry + le16_to_cpu(al_entry->length)); if (type != AT_UNUSED) { if (le32_to_cpu(al_entry->type) > le32_to_cpu(type)) goto not_found; if (type != al_entry->type) continue; } al_name_len = al_entry->name_length; al_name = (ntfschar*)((u8*)al_entry + al_entry->name_offset); /* * If !@type we want the attribute represented by this * attribute list entry. */ if (type == AT_UNUSED) goto is_enumeration; /* * If @name is AT_UNNAMED we want an unnamed attribute. * If @name is present, compare the two names. * Otherwise, match any attribute. */ if (name == AT_UNNAMED) { if (al_name_len) goto not_found; } else { int rc; if (name && ((rc = ntfs_names_full_collate(name, name_len, al_name, al_name_len, ic, vol->upcase, vol->upcase_len)))) { /* * If @name collates before al_name, * there is no matching attribute. */ if (rc < 0) goto not_found; /* If the strings are not equal, continue search. */ continue; } } /* * The names match or @name not present and attribute is * unnamed. Now check @lowest_vcn. Continue search if the * next attribute list entry still fits @lowest_vcn. Otherwise * we have reached the right one or the search has failed. */ if (lowest_vcn && (u8*)next_al_entry >= al_start && (u8*)next_al_entry + 6 < al_end && (u8*)next_al_entry + le16_to_cpu( next_al_entry->length) <= al_end && sle64_to_cpu(next_al_entry->lowest_vcn) <= lowest_vcn && next_al_entry->type == al_entry->type && next_al_entry->name_length == al_name_len && ntfs_names_are_equal((ntfschar*)((char*) next_al_entry + next_al_entry->name_offset), next_al_entry->name_length, al_name, al_name_len, CASE_SENSITIVE, vol->upcase, vol->upcase_len)) continue; is_enumeration: if (MREF_LE(al_entry->mft_reference) == ni->mft_no) { if (MSEQNO_LE(al_entry->mft_reference) != le16_to_cpu( ni->mrec->sequence_number)) { ntfs_log_error("Found stale mft reference in " "attribute list!\n"); break; } } else { /* Mft references do not match. */ /* Do we want the base record back? */ if (MREF_LE(al_entry->mft_reference) == base_ni->mft_no) { ni = ctx->ntfs_ino = base_ni; ctx->mrec = ctx->base_mrec; } else { /* We want an extent record. */ if (!vol->mft_na) { ntfs_log_perror("$MFT not ready for " "opening an extent to inode %lld\n", (long long)base_ni->mft_no); break; } ni = ntfs_extent_inode_open(base_ni, al_entry->mft_reference); if (!ni) break; ctx->ntfs_ino = ni; ctx->mrec = ni->mrec; } } a = ctx->attr = (ATTR_RECORD*)((char*)ctx->mrec + le16_to_cpu(ctx->mrec->attrs_offset)); /* * ctx->ntfs_ino, ctx->mrec, and ctx->attr now point to the * mft record containing the attribute represented by the * current al_entry. * * We could call into ntfs_attr_find() to find the right * attribute in this mft record but this would be less * efficient and not quite accurate as ntfs_attr_find() ignores * the attribute instance numbers for example which become * important when one plays with attribute lists. Also, because * a proper match has been found in the attribute list entry * above, the comparison can now be optimized. So it is worth * re-implementing a simplified ntfs_attr_find() here. * * Use a manual loop so we can still use break and continue * with the same meanings as above. */ do_next_attr_loop: /* * Make sure the attribute fully lies within the MFT record * and we can safely access its minimal fields. */ offs = p2n(a) - p2n(ctx->mrec); space = le32_to_cpu(ctx->mrec->bytes_in_use) - offs; if (offs < 0) break; if ((space >= 4) && (a->type == AT_END)) continue; if ((space < (ptrdiff_t)offsetof(ATTR_RECORD, resident_end)) || (space < (ptrdiff_t)le32_to_cpu(a->length))) break; if (al_entry->instance != a->instance) goto do_next_attr; /* * If the type and/or the name are/is mismatched between the * attribute list entry and the attribute record, there is * corruption so we break and return error EIO. */ if (al_entry->type != a->type) break; if (!ntfs_names_are_equal((ntfschar*)((char*)a + le16_to_cpu(a->name_offset)), a->name_length, al_name, al_name_len, CASE_SENSITIVE, vol->upcase, vol->upcase_len)) break; ctx->attr = a; /* * If no @val specified or @val specified and it matches, we * have found it! Also, if !@type, it is an enumeration, so we * want the current attribute. */ if ((type == AT_UNUSED) || !val || (!a->non_resident && le32_to_cpu(a->value_length) == val_len && !memcmp((char*)a + le16_to_cpu(a->value_offset), val, val_len))) { return 0; } do_next_attr: /* Proceed to the next attribute in the current mft record. */ a = (ATTR_RECORD*)((char*)a + le32_to_cpu(a->length)); goto do_next_attr_loop; } corrupt : if (ni != base_ni) { ctx->ntfs_ino = base_ni; ctx->mrec = ctx->base_mrec; ctx->attr = ctx->base_attr; } errno = EIO; ntfs_log_error("Corrupt attribute list entry in MFT record %lld\n", (long long)base_ni->mft_no); return -1; not_found: /* * If we were looking for AT_END or we were enumerating and reached the * end, we reset the search context @ctx and use ntfs_attr_find() to * seek to the end of the base mft record. */ if (type == AT_UNUSED || type == AT_END) { ntfs_attr_reinit_search_ctx(ctx); return ntfs_attr_find(AT_END, name, name_len, ic, val, val_len, ctx); } /* * The attribute wasn't found. Before we return, we want to ensure * @ctx->mrec and @ctx->attr indicate the position at which the * attribute should be inserted in the base mft record. Since we also * want to preserve @ctx->al_entry we cannot reinitialize the search * context using ntfs_attr_reinit_search_ctx() as this would set * @ctx->al_entry to NULL. Thus we do the necessary bits manually (see * ntfs_attr_init_search_ctx() below). Note, we _only_ preserve * @ctx->al_entry as the remaining fields (base_*) are identical to * their non base_ counterparts and we cannot set @ctx->base_attr * correctly yet as we do not know what @ctx->attr will be set to by * the call to ntfs_attr_find() below. */ ctx->mrec = ctx->base_mrec; ctx->attr = (ATTR_RECORD*)((u8*)ctx->mrec + le16_to_cpu(ctx->mrec->attrs_offset)); ctx->is_first = TRUE; ctx->ntfs_ino = ctx->base_ntfs_ino; ctx->base_ntfs_ino = NULL; ctx->base_mrec = NULL; ctx->base_attr = NULL; /* * In case there are multiple matches in the base mft record, need to * keep enumerating until we get an attribute not found response (or * another error), otherwise we would keep returning the same attribute * over and over again and all programs using us for enumeration would * lock up in a tight loop. */ { int ret; do { ret = ntfs_attr_find(type, name, name_len, ic, val, val_len, ctx); } while (!ret); return ret; } } /* * Check the consistency of an attribute * * Do the general consistency checks of the selected attribute : * - the required fields can be accessed * - the variable fields do not overflow * - the attribute is [non-]resident if it must be * - miscelleaneous checks * * Returns 0 if the checks pass * -1 with errno = EIO otherwise */ int ntfs_attr_inconsistent(const ATTR_RECORD *a, const MFT_REF mref) { const FILE_NAME_ATTR *fn; const INDEX_ROOT *ir; u64 inum; int ret; /* * The attribute was found to fully lie within the MFT * record, now make sure its relevant parts (name, runlist, * value) also lie within. The first step is to make sure * the attribute has the minimum length so that accesses to * the lengths and offsets of these parts are safe. */ ret = 0; inum = MREF(mref); if (a->non_resident) { if ((a->non_resident != 1) || (le32_to_cpu(a->length) < offsetof(ATTR_RECORD, non_resident_end)) || (le16_to_cpu(a->mapping_pairs_offset) >= le32_to_cpu(a->length)) || (a->name_length && (((u32)le16_to_cpu(a->name_offset) + a->name_length * sizeof(ntfschar)) > le32_to_cpu(a->length))) || (le64_to_cpu(a->highest_vcn) < le64_to_cpu(a->lowest_vcn))) { ntfs_log_error("Corrupt non resident attribute" " 0x%x in MFT record %lld\n", (int)le32_to_cpu(a->type), (long long)inum); errno = EIO; ret = -1; } } else { if ((le32_to_cpu(a->length) < offsetof(ATTR_RECORD, resident_end)) || (le32_to_cpu(a->value_length) & 0xff000000) || (a->value_length && ((le16_to_cpu(a->value_offset) + le32_to_cpu(a->value_length)) > le32_to_cpu(a->length))) || (a->name_length && (((u32)le16_to_cpu(a->name_offset) + a->name_length * sizeof(ntfschar)) > le32_to_cpu(a->length)))) { ntfs_log_error("Corrupt resident attribute" " 0x%x in MFT record %lld\n", (int)le32_to_cpu(a->type), (long long)inum); errno = EIO; ret = -1; } } if (!ret) { /* * Checking whether an attribute must be [non-]resident * is hard-coded for well-known ones. This should be * done through ntfs_attr_can_be_non_resident(), based on * $AttrDef, but this would give an easy way to bypass * the checks. * Attributes which are not well-known are not checked. * * Note : at this stage we know that a->length and * a->value_length cannot look like being negative. */ switch(a->type) { case AT_FILE_NAME : /* Check file names are resident and do not overflow */ fn = (const FILE_NAME_ATTR*)((const u8*)a + le16_to_cpu(a->value_offset)); if (a->non_resident || (le32_to_cpu(a->value_length) < offsetof(FILE_NAME_ATTR, file_name)) || !fn->file_name_length || ((fn->file_name_length * sizeof(ntfschar) + offsetof(FILE_NAME_ATTR, file_name)) > le32_to_cpu(a->value_length))) { ntfs_log_error("Corrupt file name" " attribute in MFT record %lld.\n", (long long)inum); errno = EIO; ret = -1; } break; case AT_INDEX_ROOT : /* Check root index is resident and does not overflow */ ir = (const INDEX_ROOT*)((const u8*)a + le16_to_cpu(a->value_offset)); /* index.allocated_size may overflow while resizing */ if (a->non_resident || (le32_to_cpu(a->value_length) < offsetof(INDEX_ROOT, index.reserved)) || (le32_to_cpu(ir->index.entries_offset) < sizeof(INDEX_HEADER)) || (le32_to_cpu(ir->index.index_length) < le32_to_cpu(ir->index.entries_offset)) || (le32_to_cpu(ir->index.allocated_size) < le32_to_cpu(ir->index.index_length)) || (le32_to_cpu(a->value_length) < (le32_to_cpu(ir->index.allocated_size) + offsetof(INDEX_ROOT, reserved)))) { ntfs_log_error("Corrupt index root" " in MFT record %lld.\n", (long long)inum); errno = EIO; ret = -1; } break; case AT_STANDARD_INFORMATION : if (a->non_resident || (le32_to_cpu(a->value_length) < offsetof(STANDARD_INFORMATION, v1_end))) { ntfs_log_error("Corrupt standard information" " in MFT record %lld\n", (long long)inum); errno = EIO; ret = -1; } break; case AT_OBJECT_ID : if (a->non_resident || (le32_to_cpu(a->value_length) < sizeof(GUID))) { ntfs_log_error("Corrupt object id" " in MFT record %lld\n", (long long)inum); errno = EIO; ret = -1; } break; case AT_VOLUME_NAME : case AT_EA_INFORMATION : if (a->non_resident) { ntfs_log_error("Attribute 0x%x in MFT record" " %lld should be resident.\n", (int)le32_to_cpu(a->type), (long long)inum); errno = EIO; ret = -1; } break; case AT_VOLUME_INFORMATION : if (a->non_resident || (le32_to_cpu(a->value_length) < sizeof(VOLUME_INFORMATION))) { ntfs_log_error("Corrupt volume information" " in MFT record %lld\n", (long long)inum); errno = EIO; ret = -1; } break; case AT_INDEX_ALLOCATION : if (!a->non_resident) { ntfs_log_error("Corrupt index allocation" " in MFT record %lld", (long long)inum); errno = EIO; ret = -1; } break; default : break; } } return (ret); } /** * ntfs_attr_lookup - find an attribute in an ntfs inode * @type: attribute type to find * @name: attribute name to find (optional, i.e. NULL means don't care) * @name_len: attribute name length (only needed if @name present) * @ic: IGNORE_CASE or CASE_SENSITIVE (ignored if @name not present) * @lowest_vcn: lowest vcn to find (optional, non-resident attributes only) * @val: attribute value to find (optional, resident attributes only) * @val_len: attribute value length * @ctx: search context with mft record and attribute to search from * * Find an attribute in an ntfs inode. On first search @ctx->ntfs_ino must * be the base mft record and @ctx must have been obtained from a call to * ntfs_attr_get_search_ctx(). * * This function transparently handles attribute lists and @ctx is used to * continue searches where they were left off at. * * If @type is AT_UNUSED, return the first found attribute, i.e. one can * enumerate all attributes by setting @type to AT_UNUSED and then calling * ntfs_attr_lookup() repeatedly until it returns -1 with errno set to ENOENT * to indicate that there are no more entries. During the enumeration, each * successful call of ntfs_attr_lookup() will return the next attribute, with * the current attribute being described by the search context @ctx. * * If @type is AT_END, seek to the end of the base mft record ignoring the * attribute list completely and return -1 with errno set to ENOENT. AT_END is * not a valid attribute, its length is zero for example, thus it is safer to * return error instead of success in this case. It should never be needed to * do this, but we implement the functionality because it allows for simpler * code inside ntfs_external_attr_find(). * * If @name is AT_UNNAMED search for an unnamed attribute. If @name is present * but not AT_UNNAMED search for a named attribute matching @name. Otherwise, * match both named and unnamed attributes. * * After finishing with the attribute/mft record you need to call * ntfs_attr_put_search_ctx() to cleanup the search context (unmapping any * mapped extent inodes, etc). * * Return 0 if the search was successful and -1 if not, with errno set to the * error code. * * On success, @ctx->attr is the found attribute, it is in mft record * @ctx->mrec, and @ctx->al_entry is the attribute list entry for this * attribute with @ctx->base_* being the base mft record to which @ctx->attr * belongs. If no attribute list attribute is present @ctx->al_entry and * @ctx->base_* are NULL. * * On error ENOENT, i.e. attribute not found, @ctx->attr is set to the * attribute which collates just after the attribute being searched for in the * base ntfs inode, i.e. if one wants to add the attribute to the mft record * this is the correct place to insert it into, and if there is not enough * space, the attribute should be placed in an extent mft record. * @ctx->al_entry points to the position within @ctx->base_ntfs_ino->attr_list * at which the new attribute's attribute list entry should be inserted. The * other @ctx fields, base_ntfs_ino, base_mrec, and base_attr are set to NULL. * The only exception to this is when @type is AT_END, in which case * @ctx->al_entry is set to NULL also (see above). * * * The following error codes are defined: * ENOENT Attribute not found, not an error as such. * EINVAL Invalid arguments. * EIO I/O error or corrupt data structures found. * ENOMEM Not enough memory to allocate necessary buffers. */ int ntfs_attr_lookup(const ATTR_TYPES type, const ntfschar *name, const u32 name_len, const IGNORE_CASE_BOOL ic, const VCN lowest_vcn, const u8 *val, const u32 val_len, ntfs_attr_search_ctx *ctx) { ntfs_volume *vol; ntfs_inode *base_ni; int ret = -1; ntfs_log_enter("Entering for attribute type 0x%x\n", le32_to_cpu(type)); if (!ctx || !ctx->mrec || !ctx->attr || (name && name != AT_UNNAMED && (!ctx->ntfs_ino || !(vol = ctx->ntfs_ino->vol) || !vol->upcase || !vol->upcase_len))) { errno = EINVAL; ntfs_log_perror("%s", __FUNCTION__); goto out; } if (ctx->base_ntfs_ino) base_ni = ctx->base_ntfs_ino; else base_ni = ctx->ntfs_ino; if (!base_ni || !NInoAttrList(base_ni) || type == AT_ATTRIBUTE_LIST) ret = ntfs_attr_find(type, name, name_len, ic, val, val_len, ctx); else ret = ntfs_external_attr_find(type, name, name_len, ic, lowest_vcn, val, val_len, ctx); out: ntfs_log_leave("\n"); return ret; } /** * ntfs_attr_position - find given or next attribute type in an ntfs inode * @type: attribute type to start lookup * @ctx: search context with mft record and attribute to search from * * Find an attribute type in an ntfs inode or the next attribute which is not * the AT_END attribute. Please see more details at ntfs_attr_lookup. * * Return 0 if the search was successful and -1 if not, with errno set to the * error code. * * The following error codes are defined: * EINVAL Invalid arguments. * EIO I/O error or corrupt data structures found. * ENOMEM Not enough memory to allocate necessary buffers. * ENOSPC No attribute was found after 'type', only AT_END. */ int ntfs_attr_position(const ATTR_TYPES type, ntfs_attr_search_ctx *ctx) { if (ntfs_attr_lookup(type, NULL, 0, CASE_SENSITIVE, 0, NULL, 0, ctx)) { if (errno != ENOENT) return -1; if (ctx->attr->type == AT_END) { errno = ENOSPC; return -1; } } return 0; } /** * ntfs_attr_init_search_ctx - initialize an attribute search context * @ctx: attribute search context to initialize * @ni: ntfs inode with which to initialize the search context * @mrec: mft record with which to initialize the search context * * Initialize the attribute search context @ctx with @ni and @mrec. */ static void ntfs_attr_init_search_ctx(ntfs_attr_search_ctx *ctx, ntfs_inode *ni, MFT_RECORD *mrec) { if (!mrec) mrec = ni->mrec; ctx->mrec = mrec; /* Sanity checks are performed elsewhere. */ ctx->attr = (ATTR_RECORD*)((u8*)mrec + le16_to_cpu(mrec->attrs_offset)); ctx->is_first = TRUE; ctx->ntfs_ino = ni; ctx->al_entry = NULL; ctx->base_ntfs_ino = NULL; ctx->base_mrec = NULL; ctx->base_attr = NULL; } /** * ntfs_attr_reinit_search_ctx - reinitialize an attribute search context * @ctx: attribute search context to reinitialize * * Reinitialize the attribute search context @ctx. * * This is used when a search for a new attribute is being started to reset * the search context to the beginning. */ void ntfs_attr_reinit_search_ctx(ntfs_attr_search_ctx *ctx) { if (!ctx->base_ntfs_ino) { /* No attribute list. */ ctx->is_first = TRUE; /* Sanity checks are performed elsewhere. */ ctx->attr = (ATTR_RECORD*)((u8*)ctx->mrec + le16_to_cpu(ctx->mrec->attrs_offset)); /* * This needs resetting due to ntfs_external_attr_find() which * can leave it set despite having zeroed ctx->base_ntfs_ino. */ ctx->al_entry = NULL; return; } /* Attribute list. */ ntfs_attr_init_search_ctx(ctx, ctx->base_ntfs_ino, ctx->base_mrec); return; } /** * ntfs_attr_get_search_ctx - allocate/initialize a new attribute search context * @ni: ntfs inode with which to initialize the search context * @mrec: mft record with which to initialize the search context * * Allocate a new attribute search context, initialize it with @ni and @mrec, * and return it. Return NULL on error with errno set. * * @mrec can be NULL, in which case the mft record is taken from @ni. * * Note: For low level utilities which know what they are doing we allow @ni to * be NULL and @mrec to be set. Do NOT do this unless you understand the * implications!!! For example it is no longer safe to call ntfs_attr_lookup(). */ ntfs_attr_search_ctx *ntfs_attr_get_search_ctx(ntfs_inode *ni, MFT_RECORD *mrec) { ntfs_attr_search_ctx *ctx; if (!ni && !mrec) { errno = EINVAL; ntfs_log_perror("NULL arguments"); return NULL; } ctx = ntfs_malloc(sizeof(ntfs_attr_search_ctx)); if (ctx) ntfs_attr_init_search_ctx(ctx, ni, mrec); return ctx; } /** * ntfs_attr_put_search_ctx - release an attribute search context * @ctx: attribute search context to free * * Release the attribute search context @ctx. */ void ntfs_attr_put_search_ctx(ntfs_attr_search_ctx *ctx) { // NOTE: save errno if it could change and function stays void! free(ctx); } /** * ntfs_attr_find_in_attrdef - find an attribute in the $AttrDef system file * @vol: ntfs volume to which the attribute belongs * @type: attribute type which to find * * Search for the attribute definition record corresponding to the attribute * @type in the $AttrDef system file. * * Return the attribute type definition record if found and NULL if not found * or an error occurred. On error the error code is stored in errno. The * following error codes are defined: * ENOENT - The attribute @type is not specified in $AttrDef. * EINVAL - Invalid parameters (e.g. @vol is not valid). */ ATTR_DEF *ntfs_attr_find_in_attrdef(const ntfs_volume *vol, const ATTR_TYPES type) { ATTR_DEF *ad; if (!vol || !vol->attrdef || !type) { errno = EINVAL; ntfs_log_perror("%s: type=%d", __FUNCTION__, le32_to_cpu(type)); return NULL; } for (ad = vol->attrdef; ((ptrdiff_t)((u8*)ad - (u8*)vol->attrdef + sizeof(ATTR_DEF)) <= vol->attrdef_len) && ad->type; ++ad) { /* We haven't found it yet, carry on searching. */ if (le32_to_cpu(ad->type) < le32_to_cpu(type)) continue; /* We found the attribute; return it. */ if (ad->type == type) return ad; /* We have gone too far already. No point in continuing. */ break; } errno = ENOENT; ntfs_log_perror("%s: type=%d", __FUNCTION__, le32_to_cpu(type)); return NULL; } /** * ntfs_attr_size_bounds_check - check a size of an attribute type for validity * @vol: ntfs volume to which the attribute belongs * @type: attribute type which to check * @size: size which to check * * Check whether the @size in bytes is valid for an attribute of @type on the * ntfs volume @vol. This information is obtained from $AttrDef system file. * * Return 0 if valid and -1 if not valid or an error occurred. On error the * error code is stored in errno. The following error codes are defined: * ERANGE - @size is not valid for the attribute @type. * ENOENT - The attribute @type is not specified in $AttrDef. * EINVAL - Invalid parameters (e.g. @size is < 0 or @vol is not valid). */ int ntfs_attr_size_bounds_check(const ntfs_volume *vol, const ATTR_TYPES type, const s64 size) { ATTR_DEF *ad; s64 min_size, max_size; if (size < 0) { errno = EINVAL; ntfs_log_perror("%s: size=%lld", __FUNCTION__, (long long)size); return -1; } /* * $ATTRIBUTE_LIST shouldn't be greater than 0x40000, otherwise * Windows would crash. This is not listed in the AttrDef. */ if (type == AT_ATTRIBUTE_LIST && size > 0x40000) { errno = ERANGE; ntfs_log_perror("Too large attrlist (%lld)", (long long)size); return -1; } ad = ntfs_attr_find_in_attrdef(vol, type); if (!ad) return -1; min_size = sle64_to_cpu(ad->min_size); max_size = sle64_to_cpu(ad->max_size); /* The $AttrDef generated by Windows specifies 2 as min_size for the * volume name attribute, but in reality Windows sets it to 0 when * clearing the volume name. If we want to be able to clear the volume * name we must also accept 0 as min_size, despite the $AttrDef * definition. */ if(type == AT_VOLUME_NAME) min_size = 0; if ((min_size && (size < min_size)) || ((max_size > 0) && (size > max_size))) { errno = ERANGE; ntfs_log_perror("Attr type %d size check failed (min,size,max=" "%lld,%lld,%lld)", le32_to_cpu(type), (long long)min_size, (long long)size, (long long)max_size); return -1; } return 0; } /** * ntfs_attr_can_be_non_resident - check if an attribute can be non-resident * @vol: ntfs volume to which the attribute belongs * @type: attribute type to check * @name: attribute name to check * @name_len: attribute name length * * Check whether the attribute of @type and @name with name length @name_len on * the ntfs volume @vol is allowed to be non-resident. This information is * obtained from $AttrDef system file and is augmented by rules imposed by * Microsoft (e.g. see http://support.microsoft.com/kb/974729/). * * Return 0 if the attribute is allowed to be non-resident and -1 if not or an * error occurred. On error the error code is stored in errno. The following * error codes are defined: * EPERM - The attribute is not allowed to be non-resident. * ENOENT - The attribute @type is not specified in $AttrDef. * EINVAL - Invalid parameters (e.g. @vol is not valid). */ static int ntfs_attr_can_be_non_resident(const ntfs_volume *vol, const ATTR_TYPES type, const ntfschar *name, int name_len) { ATTR_DEF *ad; BOOL allowed; /* * Microsoft has decreed that $LOGGED_UTILITY_STREAM attributes with a * name of $TXF_DATA must be resident despite the entry for * $LOGGED_UTILITY_STREAM in $AttrDef allowing them to be non-resident. * Failure to obey this on the root directory mft record of a volume * causes Windows Vista and later to see the volume as a RAW volume and * thus cannot mount it at all. */ if ((type == AT_LOGGED_UTILITY_STREAM) && name && ntfs_names_are_equal(TXF_DATA, 9, name, name_len, CASE_SENSITIVE, vol->upcase, vol->upcase_len)) allowed = FALSE; else { /* Find the attribute definition record in $AttrDef. */ ad = ntfs_attr_find_in_attrdef(vol, type); if (!ad) return -1; /* Check the flags and return the result. */ allowed = !(ad->flags & ATTR_DEF_RESIDENT); } if (!allowed) { errno = EPERM; ntfs_log_trace("Attribute can't be non-resident\n"); return -1; } return 0; } /** * ntfs_attr_can_be_resident - check if an attribute can be resident * @vol: ntfs volume to which the attribute belongs * @type: attribute type which to check * * Check whether the attribute of @type on the ntfs volume @vol is allowed to * be resident. This information is derived from our ntfs knowledge and may * not be completely accurate, especially when user defined attributes are * present. Basically we allow everything to be resident except for index * allocation and extended attribute attributes. * * Return 0 if the attribute is allowed to be resident and -1 if not or an * error occurred. On error the error code is stored in errno. The following * error codes are defined: * EPERM - The attribute is not allowed to be resident. * EINVAL - Invalid parameters (e.g. @vol is not valid). * * Warning: In the system file $MFT the attribute $Bitmap must be non-resident * otherwise windows will not boot (blue screen of death)! We cannot * check for this here as we don't know which inode's $Bitmap is being * asked about so the caller needs to special case this. */ int ntfs_attr_can_be_resident(const ntfs_volume *vol, const ATTR_TYPES type) { if (!vol || !vol->attrdef || !type) { errno = EINVAL; return -1; } if (type != AT_INDEX_ALLOCATION) return 0; ntfs_log_trace("Attribute can't be resident\n"); errno = EPERM; return -1; } /** * ntfs_make_room_for_attr - make room for an attribute inside an mft record * @m: mft record * @pos: position at which to make space * @size: byte size to make available at this position * * @pos points to the attribute in front of which we want to make space. * * Return 0 on success or -1 on error. On error the error code is stored in * errno. Possible error codes are: * ENOSPC - There is not enough space available to complete operation. The * caller has to make space before calling this. * EINVAL - Input parameters were faulty. */ int ntfs_make_room_for_attr(MFT_RECORD *m, u8 *pos, u32 size) { u32 biu; ntfs_log_trace("Entering for pos 0x%d, size %u.\n", (int)(pos - (u8*)m), (unsigned) size); /* Make size 8-byte alignment. */ size = (size + 7) & ~7; /* Rigorous consistency checks. */ if (!m || !pos || pos < (u8*)m) { errno = EINVAL; ntfs_log_perror("%s: pos=%p m=%p", __FUNCTION__, pos, m); return -1; } /* The -8 is for the attribute terminator. */ if (pos - (u8*)m > (int)le32_to_cpu(m->bytes_in_use) - 8) { errno = EINVAL; return -1; } /* Nothing to do. */ if (!size) return 0; biu = le32_to_cpu(m->bytes_in_use); /* Do we have enough space? */ if (biu + size > le32_to_cpu(m->bytes_allocated) || pos + size > (u8*)m + le32_to_cpu(m->bytes_allocated)) { errno = ENOSPC; ntfs_log_trace("No enough space in the MFT record\n"); return -1; } /* Move everything after pos to pos + size. */ memmove(pos + size, pos, biu - (pos - (u8*)m)); /* Update mft record. */ m->bytes_in_use = cpu_to_le32(biu + size); return 0; } /** * ntfs_resident_attr_record_add - add resident attribute to inode * @ni: opened ntfs inode to which MFT record add attribute * @type: type of the new attribute * @name: name of the new attribute * @name_len: name length of the new attribute * @val: value of the new attribute * @size: size of new attribute (length of @val, if @val != NULL) * @flags: flags of the new attribute * * Return offset to attribute from the beginning of the mft record on success * and -1 on error. On error the error code is stored in errno. * Possible error codes are: * EINVAL - Invalid arguments passed to function. * EEXIST - Attribute of such type and with same name already exists. * EIO - I/O error occurred or damaged filesystem. */ int ntfs_resident_attr_record_add(ntfs_inode *ni, ATTR_TYPES type, const ntfschar *name, u8 name_len, const u8 *val, u32 size, ATTR_FLAGS data_flags) { ntfs_attr_search_ctx *ctx; u32 length; ATTR_RECORD *a; MFT_RECORD *m; int err, offset; ntfs_inode *base_ni; ntfs_log_trace("Entering for inode 0x%llx, attr 0x%x, flags 0x%x.\n", (long long) ni->mft_no, (unsigned) le32_to_cpu(type), (unsigned) le16_to_cpu(data_flags)); if (!ni || (!name && name_len)) { errno = EINVAL; return -1; } if (ntfs_attr_can_be_resident(ni->vol, type)) { if (errno == EPERM) ntfs_log_trace("Attribute can't be resident.\n"); else ntfs_log_trace("ntfs_attr_can_be_resident failed.\n"); return -1; } /* Locate place where record should be. */ ctx = ntfs_attr_get_search_ctx(ni, NULL); if (!ctx) return -1; /* * Use ntfs_attr_find instead of ntfs_attr_lookup to find place for * attribute in @ni->mrec, not any extent inode in case if @ni is base * file record. */ if (!ntfs_attr_find(type, name, name_len, CASE_SENSITIVE, val, size, ctx)) { err = EEXIST; ntfs_log_trace("Attribute already present.\n"); goto put_err_out; } if (errno != ENOENT) { err = EIO; goto put_err_out; } a = ctx->attr; m = ctx->mrec; /* Make room for attribute. */ length = offsetof(ATTR_RECORD, resident_end) + ((name_len * sizeof(ntfschar) + 7) & ~7) + ((size + 7) & ~7); if (ntfs_make_room_for_attr(ctx->mrec, (u8*) ctx->attr, length)) { err = errno; ntfs_log_trace("Failed to make room for attribute.\n"); goto put_err_out; } /* Setup record fields. */ offset = ((u8*)a - (u8*)m); a->type = type; a->length = cpu_to_le32(length); a->non_resident = 0; a->name_length = name_len; a->name_offset = (name_len ? const_cpu_to_le16(offsetof(ATTR_RECORD, resident_end)) : const_cpu_to_le16(0)); a->flags = data_flags; a->instance = m->next_attr_instance; a->value_length = cpu_to_le32(size); a->value_offset = cpu_to_le16(length - ((size + 7) & ~7)); if (val) memcpy((u8*)a + le16_to_cpu(a->value_offset), val, size); else memset((u8*)a + le16_to_cpu(a->value_offset), 0, size); if (type == AT_FILE_NAME) a->resident_flags = RESIDENT_ATTR_IS_INDEXED; else a->resident_flags = 0; if (name_len) memcpy((u8*)a + le16_to_cpu(a->name_offset), name, sizeof(ntfschar) * name_len); m->next_attr_instance = cpu_to_le16((le16_to_cpu(m->next_attr_instance) + 1) & 0xffff); if (ni->nr_extents == -1) base_ni = ni->base_ni; else base_ni = ni; if (type != AT_ATTRIBUTE_LIST && NInoAttrList(base_ni)) { if (ntfs_attrlist_entry_add(ni, a)) { err = errno; ntfs_attr_record_resize(m, a, 0); ntfs_log_trace("Failed add attribute entry to " "ATTRIBUTE_LIST.\n"); goto put_err_out; } } if (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY ? type == AT_INDEX_ROOT && name == NTFS_INDEX_I30 : type == AT_DATA && name == AT_UNNAMED) { ni->data_size = size; ni->allocated_size = (size + 7) & ~7; set_nino_flag(ni,KnownSize); } ntfs_inode_mark_dirty(ni); ntfs_attr_put_search_ctx(ctx); return offset; put_err_out: ntfs_attr_put_search_ctx(ctx); errno = err; return -1; } /** * ntfs_non_resident_attr_record_add - add extent of non-resident attribute * @ni: opened ntfs inode to which MFT record add attribute * @type: type of the new attribute extent * @name: name of the new attribute extent * @name_len: name length of the new attribute extent * @lowest_vcn: lowest vcn of the new attribute extent * @dataruns_size: dataruns size of the new attribute extent * @flags: flags of the new attribute extent * * Return offset to attribute from the beginning of the mft record on success * and -1 on error. On error the error code is stored in errno. * Possible error codes are: * EINVAL - Invalid arguments passed to function. * EEXIST - Attribute of such type, with same lowest vcn and with same * name already exists. * EIO - I/O error occurred or damaged filesystem. */ int ntfs_non_resident_attr_record_add(ntfs_inode *ni, ATTR_TYPES type, const ntfschar *name, u8 name_len, VCN lowest_vcn, int dataruns_size, ATTR_FLAGS flags) { ntfs_attr_search_ctx *ctx; u32 length; ATTR_RECORD *a; MFT_RECORD *m; ntfs_inode *base_ni; int err, offset; ntfs_log_trace("Entering for inode 0x%llx, attr 0x%x, lowest_vcn %lld, " "dataruns_size %d, flags 0x%x.\n", (long long) ni->mft_no, (unsigned) le32_to_cpu(type), (long long) lowest_vcn, dataruns_size, (unsigned) le16_to_cpu(flags)); if (!ni || dataruns_size <= 0 || (!name && name_len)) { errno = EINVAL; return -1; } if (ntfs_attr_can_be_non_resident(ni->vol, type, name, name_len)) { if (errno == EPERM) ntfs_log_perror("Attribute can't be non resident"); else ntfs_log_perror("ntfs_attr_can_be_non_resident failed"); return -1; } /* Locate place where record should be. */ ctx = ntfs_attr_get_search_ctx(ni, NULL); if (!ctx) return -1; /* * Use ntfs_attr_find instead of ntfs_attr_lookup to find place for * attribute in @ni->mrec, not any extent inode in case if @ni is base * file record. */ if (!ntfs_attr_find(type, name, name_len, CASE_SENSITIVE, NULL, 0, ctx)) { err = EEXIST; ntfs_log_perror("Attribute 0x%x already present", le32_to_cpu(type)); goto put_err_out; } if (errno != ENOENT) { ntfs_log_perror("ntfs_attr_find failed"); err = EIO; goto put_err_out; } a = ctx->attr; m = ctx->mrec; /* Make room for attribute. */ dataruns_size = (dataruns_size + 7) & ~7; length = offsetof(ATTR_RECORD, compressed_size) + ((sizeof(ntfschar) * name_len + 7) & ~7) + dataruns_size + ((flags & (ATTR_IS_COMPRESSED | ATTR_IS_SPARSE)) ? sizeof(a->compressed_size) : 0); if (ntfs_make_room_for_attr(ctx->mrec, (u8*) ctx->attr, length)) { err = errno; ntfs_log_perror("Failed to make room for attribute"); goto put_err_out; } /* Setup record fields. */ a->type = type; a->length = cpu_to_le32(length); a->non_resident = 1; a->name_length = name_len; a->name_offset = cpu_to_le16(offsetof(ATTR_RECORD, compressed_size) + ((flags & (ATTR_IS_COMPRESSED | ATTR_IS_SPARSE)) ? sizeof(a->compressed_size) : 0)); a->flags = flags; a->instance = m->next_attr_instance; a->lowest_vcn = cpu_to_sle64(lowest_vcn); a->mapping_pairs_offset = cpu_to_le16(length - dataruns_size); a->compression_unit = (flags & ATTR_IS_COMPRESSED) ? STANDARD_COMPRESSION_UNIT : 0; /* If @lowest_vcn == 0, than setup empty attribute. */ if (!lowest_vcn) { a->highest_vcn = const_cpu_to_sle64(-1); a->allocated_size = const_cpu_to_sle64(0); a->data_size = const_cpu_to_sle64(0); a->initialized_size = const_cpu_to_sle64(0); /* Set empty mapping pairs. */ *((u8*)a + le16_to_cpu(a->mapping_pairs_offset)) = 0; } if (name_len) memcpy((u8*)a + le16_to_cpu(a->name_offset), name, sizeof(ntfschar) * name_len); m->next_attr_instance = cpu_to_le16((le16_to_cpu(m->next_attr_instance) + 1) & 0xffff); if (ni->nr_extents == -1) base_ni = ni->base_ni; else base_ni = ni; if (type != AT_ATTRIBUTE_LIST && NInoAttrList(base_ni)) { if (ntfs_attrlist_entry_add(ni, a)) { err = errno; ntfs_log_perror("Failed add attr entry to attrlist"); ntfs_attr_record_resize(m, a, 0); goto put_err_out; } } ntfs_inode_mark_dirty(ni); /* * Locate offset from start of the MFT record where new attribute is * placed. We need relookup it, because record maybe moved during * update of attribute list. */ ntfs_attr_reinit_search_ctx(ctx); if (ntfs_attr_lookup(type, name, name_len, CASE_SENSITIVE, lowest_vcn, NULL, 0, ctx)) { ntfs_log_perror("%s: attribute lookup failed", __FUNCTION__); ntfs_attr_put_search_ctx(ctx); return -1; } offset = (u8*)ctx->attr - (u8*)ctx->mrec; ntfs_attr_put_search_ctx(ctx); return offset; put_err_out: ntfs_attr_put_search_ctx(ctx); errno = err; return -1; } /** * ntfs_attr_record_rm - remove attribute extent * @ctx: search context describing the attribute which should be removed * * If this function succeed, user should reinit search context if he/she wants * use it anymore. * * Return 0 on success and -1 on error. On error the error code is stored in * errno. Possible error codes are: * EINVAL - Invalid arguments passed to function. * EIO - I/O error occurred or damaged filesystem. */ int ntfs_attr_record_rm(ntfs_attr_search_ctx *ctx) { ntfs_inode *base_ni, *ni; ATTR_TYPES type; if (!ctx || !ctx->ntfs_ino || !ctx->mrec || !ctx->attr) { errno = EINVAL; return -1; } ntfs_log_trace("Entering for inode 0x%llx, attr 0x%x.\n", (long long) ctx->ntfs_ino->mft_no, (unsigned) le32_to_cpu(ctx->attr->type)); type = ctx->attr->type; ni = ctx->ntfs_ino; if (ctx->base_ntfs_ino) base_ni = ctx->base_ntfs_ino; else base_ni = ctx->ntfs_ino; /* Remove attribute itself. */ if (ntfs_attr_record_resize(ctx->mrec, ctx->attr, 0)) { ntfs_log_trace("Couldn't remove attribute record. Bug or damaged MFT " "record.\n"); if (NInoAttrList(base_ni) && type != AT_ATTRIBUTE_LIST) if (ntfs_attrlist_entry_add(ni, ctx->attr)) ntfs_log_trace("Rollback failed. Leaving inconstant " "metadata.\n"); errno = EIO; return -1; } ntfs_inode_mark_dirty(ni); /* * Remove record from $ATTRIBUTE_LIST if present and we don't want * delete $ATTRIBUTE_LIST itself. */ if (NInoAttrList(base_ni) && type != AT_ATTRIBUTE_LIST) { if (ntfs_attrlist_entry_rm(ctx)) { ntfs_log_trace("Couldn't delete record from " "$ATTRIBUTE_LIST.\n"); return -1; } } /* Post $ATTRIBUTE_LIST delete setup. */ if (type == AT_ATTRIBUTE_LIST) { if (NInoAttrList(base_ni) && base_ni->attr_list) free(base_ni->attr_list); base_ni->attr_list = NULL; NInoClearAttrList(base_ni); NInoAttrListClearDirty(base_ni); } /* Free MFT record, if it doesn't contain attributes. */ if (le32_to_cpu(ctx->mrec->bytes_in_use) - le16_to_cpu(ctx->mrec->attrs_offset) == 8) { if (ntfs_mft_record_free(ni->vol, ni)) { // FIXME: We need rollback here. ntfs_log_trace("Couldn't free MFT record.\n"); errno = EIO; return -1; } /* Remove done if we freed base inode. */ if (ni == base_ni) return 0; } if (type == AT_ATTRIBUTE_LIST || !NInoAttrList(base_ni)) return 0; /* Remove attribute list if we don't need it any more. */ if (!ntfs_attrlist_need(base_ni)) { ntfs_attr_reinit_search_ctx(ctx); if (ntfs_attr_lookup(AT_ATTRIBUTE_LIST, NULL, 0, CASE_SENSITIVE, 0, NULL, 0, ctx)) { /* * FIXME: Should we succeed here? Definitely something * goes wrong because NInoAttrList(base_ni) returned * that we have got attribute list. */ ntfs_log_trace("Couldn't find attribute list. Succeed " "anyway.\n"); return 0; } /* Deallocate clusters. */ if (ctx->attr->non_resident) { runlist *al_rl; al_rl = ntfs_mapping_pairs_decompress(base_ni->vol, ctx->attr, NULL); if (!al_rl) { ntfs_log_trace("Couldn't decompress attribute list " "runlist. Succeed anyway.\n"); return 0; } if (ntfs_cluster_free_from_rl(base_ni->vol, al_rl)) { ntfs_log_trace("Leaking clusters! Run chkdsk. " "Couldn't free clusters from " "attribute list runlist.\n"); } free(al_rl); } /* Remove attribute record itself. */ if (ntfs_attr_record_rm(ctx)) { /* * FIXME: Should we succeed here? BTW, chkdsk doesn't * complain if it find MFT record with attribute list, * but without extents. */ ntfs_log_trace("Couldn't remove attribute list. Succeed " "anyway.\n"); return 0; } } return 0; } /** * ntfs_attr_add - add attribute to inode * @ni: opened ntfs inode to which add attribute * @type: type of the new attribute * @name: name in unicode of the new attribute * @name_len: name length in unicode characters of the new attribute * @val: value of new attribute * @size: size of the new attribute / length of @val (if specified) * * @val should always be specified for always resident attributes (eg. FILE_NAME * attribute), for attributes that can become non-resident @val can be NULL * (eg. DATA attribute). @size can be specified even if @val is NULL, in this * case data size will be equal to @size and initialized size will be equal * to 0. * * If inode haven't got enough space to add attribute, add attribute to one of * it extents, if no extents present or no one of them have enough space, than * allocate new extent and add attribute to it. * * If on one of this steps attribute list is needed but not present, than it is * added transparently to caller. So, this function should not be called with * @type == AT_ATTRIBUTE_LIST, if you really need to add attribute list call * ntfs_inode_add_attrlist instead. * * On success return 0. On error return -1 with errno set to the error code. */ int ntfs_attr_add(ntfs_inode *ni, ATTR_TYPES type, ntfschar *name, u8 name_len, const u8 *val, s64 size) { u32 attr_rec_size; int err, i, offset; BOOL is_resident; BOOL can_be_non_resident = FALSE; ntfs_inode *attr_ni; ntfs_attr *na; ATTR_FLAGS data_flags; if (!ni || size < 0 || type == AT_ATTRIBUTE_LIST) { errno = EINVAL; ntfs_log_perror("%s: ni=%p size=%lld", __FUNCTION__, ni, (long long)size); return -1; } ntfs_log_trace("Entering for inode %lld, attr %x, size %lld.\n", (long long)ni->mft_no, le32_to_cpu(type), (long long)size); if (ni->nr_extents == -1) ni = ni->base_ni; /* Check the attribute type and the size. */ if (ntfs_attr_size_bounds_check(ni->vol, type, size)) { if (errno == ENOENT) errno = EIO; return -1; } /* Sanity checks for always resident attributes. */ if (ntfs_attr_can_be_non_resident(ni->vol, type, name, name_len)) { if (errno != EPERM) { err = errno; ntfs_log_perror("ntfs_attr_can_be_non_resident failed"); goto err_out; } /* @val is mandatory. */ if (!val) { errno = EINVAL; ntfs_log_perror("val is mandatory for always resident " "attributes"); return -1; } if (size > ni->vol->mft_record_size) { errno = ERANGE; ntfs_log_perror("Attribute is too big"); return -1; } } else can_be_non_resident = TRUE; /* * Determine resident or not will be new attribute. We add 8 to size in * non resident case for mapping pairs. */ if (!ntfs_attr_can_be_resident(ni->vol, type)) { is_resident = TRUE; } else { if (errno != EPERM) { err = errno; ntfs_log_perror("ntfs_attr_can_be_resident failed"); goto err_out; } is_resident = FALSE; } /* Calculate attribute record size. */ if (is_resident) attr_rec_size = offsetof(ATTR_RECORD, resident_end) + ((name_len * sizeof(ntfschar) + 7) & ~7) + ((size + 7) & ~7); else attr_rec_size = offsetof(ATTR_RECORD, non_resident_end) + ((name_len * sizeof(ntfschar) + 7) & ~7) + 8; /* * If we have enough free space for the new attribute in the base MFT * record, then add attribute to it. */ if (le32_to_cpu(ni->mrec->bytes_allocated) - le32_to_cpu(ni->mrec->bytes_in_use) >= attr_rec_size) { attr_ni = ni; goto add_attr_record; } /* Try to add to extent inodes. */ if (ntfs_inode_attach_all_extents(ni)) { err = errno; ntfs_log_perror("Failed to attach all extents to inode"); goto err_out; } for (i = 0; i < ni->nr_extents; i++) { attr_ni = ni->extent_nis[i]; if (le32_to_cpu(attr_ni->mrec->bytes_allocated) - le32_to_cpu(attr_ni->mrec->bytes_in_use) >= attr_rec_size) goto add_attr_record; } /* There is no extent that contain enough space for new attribute. */ if (!NInoAttrList(ni)) { /* Add attribute list not present, add it and retry. */ if (ntfs_inode_add_attrlist(ni)) { err = errno; ntfs_log_perror("Failed to add attribute list"); goto err_out; } return ntfs_attr_add(ni, type, name, name_len, val, size); } /* Allocate new extent. */ attr_ni = ntfs_mft_record_alloc(ni->vol, ni); if (!attr_ni) { err = errno; ntfs_log_perror("Failed to allocate extent record"); goto err_out; } add_attr_record: if ((ni->flags & FILE_ATTR_COMPRESSED) && (ni->vol->major_ver >= 3) && NVolCompression(ni->vol) && (ni->vol->cluster_size <= MAX_COMPRESSION_CLUSTER_SIZE) && ((type == AT_DATA) || ((type == AT_INDEX_ROOT) && (name == NTFS_INDEX_I30)))) data_flags = ATTR_IS_COMPRESSED; else data_flags = const_cpu_to_le16(0); if (is_resident) { /* Add resident attribute. */ offset = ntfs_resident_attr_record_add(attr_ni, type, name, name_len, val, size, data_flags); if (offset < 0) { if (errno == ENOSPC && can_be_non_resident) goto add_non_resident; err = errno; ntfs_log_perror("Failed to add resident attribute"); goto free_err_out; } return 0; } add_non_resident: /* Add non resident attribute. */ offset = ntfs_non_resident_attr_record_add(attr_ni, type, name, name_len, 0, 8, data_flags); if (offset < 0) { err = errno; ntfs_log_perror("Failed to add non resident attribute"); goto free_err_out; } /* If @size == 0, we are done. */ if (!size) return 0; /* Open new attribute and resize it. */ na = ntfs_attr_open(ni, type, name, name_len); if (!na) { err = errno; ntfs_log_perror("Failed to open just added attribute"); goto rm_attr_err_out; } /* Resize and set attribute value. */ if (ntfs_attr_truncate_i(na, size, HOLES_OK) || (val && (ntfs_attr_pwrite(na, 0, size, val) != size))) { err = errno; ntfs_log_perror("Failed to initialize just added attribute"); if (ntfs_attr_rm(na)) ntfs_log_perror("Failed to remove just added attribute"); ntfs_attr_close(na); goto err_out; } ntfs_attr_close(na); return 0; rm_attr_err_out: /* Remove just added attribute. */ if (ntfs_attr_record_resize(attr_ni->mrec, (ATTR_RECORD*)((u8*)attr_ni->mrec + offset), 0)) ntfs_log_perror("Failed to remove just added attribute #2"); free_err_out: /* Free MFT record, if it doesn't contain attributes. */ if (le32_to_cpu(attr_ni->mrec->bytes_in_use) - le16_to_cpu(attr_ni->mrec->attrs_offset) == 8) if (ntfs_mft_record_free(attr_ni->vol, attr_ni)) ntfs_log_perror("Failed to free MFT record"); err_out: errno = err; return -1; } /* * Change an attribute flag */ int ntfs_attr_set_flags(ntfs_inode *ni, ATTR_TYPES type, const ntfschar *name, u8 name_len, ATTR_FLAGS flags, ATTR_FLAGS mask) { ntfs_attr_search_ctx *ctx; int res; res = -1; /* Search for designated attribute */ ctx = ntfs_attr_get_search_ctx(ni, NULL); if (ctx) { if (!ntfs_attr_lookup(type, name, name_len, CASE_SENSITIVE, 0, NULL, 0, ctx)) { /* do the requested change (all small endian le16) */ ctx->attr->flags = (ctx->attr->flags & ~mask) | (flags & mask); NInoSetDirty(ni); res = 0; } ntfs_attr_put_search_ctx(ctx); } return (res); } /** * ntfs_attr_rm - remove attribute from ntfs inode * @na: opened ntfs attribute to delete * * Remove attribute and all it's extents from ntfs inode. If attribute was non * resident also free all clusters allocated by attribute. * * Return 0 on success or -1 on error with errno set to the error code. */ int ntfs_attr_rm(ntfs_attr *na) { ntfs_attr_search_ctx *ctx; int ret = 0; if (!na) { ntfs_log_trace("Invalid arguments passed.\n"); errno = EINVAL; return -1; } ntfs_log_trace("Entering for inode 0x%llx, attr 0x%x.\n", (long long) na->ni->mft_no, le32_to_cpu(na->type)); /* Free cluster allocation. */ if (NAttrNonResident(na)) { if (ntfs_attr_map_whole_runlist(na)) return -1; if (ntfs_cluster_free(na->ni->vol, na, 0, -1) < 0) { ntfs_log_trace("Failed to free cluster allocation. Leaving " "inconstant metadata.\n"); ret = -1; } } /* Search for attribute extents and remove them all. */ ctx = ntfs_attr_get_search_ctx(na->ni, NULL); if (!ctx) return -1; while (!ntfs_attr_lookup(na->type, na->name, na->name_len, CASE_SENSITIVE, 0, NULL, 0, ctx)) { if (ntfs_attr_record_rm(ctx)) { ntfs_log_trace("Failed to remove attribute extent. Leaving " "inconstant metadata.\n"); ret = -1; } ntfs_attr_reinit_search_ctx(ctx); } ntfs_attr_put_search_ctx(ctx); if (errno != ENOENT) { ntfs_log_trace("Attribute lookup failed. Probably leaving inconstant " "metadata.\n"); ret = -1; } return ret; } /** * ntfs_attr_record_resize - resize an attribute record * @m: mft record containing attribute record * @a: attribute record to resize * @new_size: new size in bytes to which to resize the attribute record @a * * Resize the attribute record @a, i.e. the resident part of the attribute, in * the mft record @m to @new_size bytes. * * Return 0 on success and -1 on error with errno set to the error code. * The following error codes are defined: * ENOSPC - Not enough space in the mft record @m to perform the resize. * Note that on error no modifications have been performed whatsoever. * * Warning: If you make a record smaller without having copied all the data you * are interested in the data may be overwritten! */ int ntfs_attr_record_resize(MFT_RECORD *m, ATTR_RECORD *a, u32 new_size) { u32 old_size, alloc_size, attr_size; old_size = le32_to_cpu(m->bytes_in_use); alloc_size = le32_to_cpu(m->bytes_allocated); attr_size = le32_to_cpu(a->length); ntfs_log_trace("Sizes: old=%u alloc=%u attr=%u new=%u\n", (unsigned)old_size, (unsigned)alloc_size, (unsigned)attr_size, (unsigned)new_size); /* Align to 8 bytes, just in case the caller hasn't. */ new_size = (new_size + 7) & ~7; /* If the actual attribute length has changed, move things around. */ if (new_size != attr_size) { u32 new_muse = old_size - attr_size + new_size; /* Not enough space in this mft record. */ if (new_muse > alloc_size) { errno = ENOSPC; ntfs_log_trace("Not enough space in the MFT record " "(%u > %u)\n", new_muse, alloc_size); return -1; } if (a->type == AT_INDEX_ROOT && new_size > attr_size && new_muse + 120 > alloc_size && old_size + 120 <= alloc_size) { errno = ENOSPC; ntfs_log_trace("Too big INDEX_ROOT (%u > %u)\n", new_muse, alloc_size); return STATUS_RESIDENT_ATTRIBUTE_FILLED_MFT; } /* Move attributes following @a to their new location. */ if (((u8 *)m + old_size) < ((u8 *)a + attr_size)) { ntfs_log_error("Attribute 0x%x overflows" " from MFT record\n", (int)le32_to_cpu(a->type)); errno = EIO; return (-1); } memmove((u8 *)a + new_size, (u8 *)a + attr_size, old_size - ((u8 *)a - (u8 *)m) - attr_size); /* Adjust @m to reflect the change in used space. */ m->bytes_in_use = cpu_to_le32(new_muse); /* Adjust @a to reflect the new size. */ if (new_size >= offsetof(ATTR_REC, length) + sizeof(a->length)) a->length = cpu_to_le32(new_size); } return 0; } /** * ntfs_resident_attr_value_resize - resize the value of a resident attribute * @m: mft record containing attribute record * @a: attribute record whose value to resize * @new_size: new size in bytes to which to resize the attribute value of @a * * Resize the value of the attribute @a in the mft record @m to @new_size bytes. * If the value is made bigger, the newly "allocated" space is cleared. * * Return 0 on success and -1 on error with errno set to the error code. * The following error codes are defined: * ENOSPC - Not enough space in the mft record @m to perform the resize. * Note that on error no modifications have been performed whatsoever. */ int ntfs_resident_attr_value_resize(MFT_RECORD *m, ATTR_RECORD *a, const u32 new_size) { int ret; ntfs_log_trace("Entering for new size %u.\n", (unsigned)new_size); if (!a->value_length) { /* Offset is unsafe when no value */ int offset = ((offsetof(ATTR_RECORD, resident_end) + a->name_length*sizeof(ntfschar) - 1) | 7) + 1; a->value_offset = cpu_to_le16(offset); } /* Resize the resident part of the attribute record. */ if ((ret = ntfs_attr_record_resize(m, a, (le16_to_cpu(a->value_offset) + new_size + 7) & ~7)) < 0) return ret; /* * If we made the attribute value bigger, clear the area between the * old size and @new_size. */ if (new_size > le32_to_cpu(a->value_length)) memset((u8*)a + le16_to_cpu(a->value_offset) + le32_to_cpu(a->value_length), 0, new_size - le32_to_cpu(a->value_length)); /* Finally update the length of the attribute value. */ a->value_length = cpu_to_le32(new_size); return 0; } /** * ntfs_attr_record_move_to - move attribute record to target inode * @ctx: attribute search context describing the attribute record * @ni: opened ntfs inode to which move attribute record * * If this function succeed, user should reinit search context if he/she wants * use it anymore. * * Return 0 on success and -1 on error with errno set to the error code. */ int ntfs_attr_record_move_to(ntfs_attr_search_ctx *ctx, ntfs_inode *ni) { ntfs_attr_search_ctx *nctx; ATTR_RECORD *a; int err; if (!ctx || !ctx->attr || !ctx->ntfs_ino || !ni) { ntfs_log_trace("Invalid arguments passed.\n"); errno = EINVAL; return -1; } ntfs_log_trace("Entering for ctx->attr->type 0x%x, ctx->ntfs_ino->mft_no " "0x%llx, ni->mft_no 0x%llx.\n", (unsigned) le32_to_cpu(ctx->attr->type), (long long) ctx->ntfs_ino->mft_no, (long long) ni->mft_no); if (ctx->ntfs_ino == ni) return 0; if (!ctx->al_entry) { ntfs_log_trace("Inode should contain attribute list to use this " "function.\n"); errno = EINVAL; return -1; } /* Find place in MFT record where attribute will be moved. */ a = ctx->attr; nctx = ntfs_attr_get_search_ctx(ni, NULL); if (!nctx) return -1; /* * Use ntfs_attr_find instead of ntfs_attr_lookup to find place for * attribute in @ni->mrec, not any extent inode in case if @ni is base * file record. */ if (!ntfs_attr_find(a->type, (ntfschar*)((u8*)a + le16_to_cpu( a->name_offset)), a->name_length, CASE_SENSITIVE, NULL, 0, nctx)) { ntfs_log_trace("Attribute of such type, with same name already " "present in this MFT record.\n"); err = EEXIST; goto put_err_out; } if (errno != ENOENT) { err = errno; ntfs_log_debug("Attribute lookup failed.\n"); goto put_err_out; } /* Make space and move attribute. */ if (ntfs_make_room_for_attr(ni->mrec, (u8*) nctx->attr, le32_to_cpu(a->length))) { err = errno; ntfs_log_trace("Couldn't make space for attribute.\n"); goto put_err_out; } memcpy(nctx->attr, a, le32_to_cpu(a->length)); nctx->attr->instance = nctx->mrec->next_attr_instance; nctx->mrec->next_attr_instance = cpu_to_le16( (le16_to_cpu(nctx->mrec->next_attr_instance) + 1) & 0xffff); ntfs_attr_record_resize(ctx->mrec, a, 0); ntfs_inode_mark_dirty(ctx->ntfs_ino); ntfs_inode_mark_dirty(ni); /* Update attribute list. */ ctx->al_entry->mft_reference = MK_LE_MREF(ni->mft_no, le16_to_cpu(ni->mrec->sequence_number)); ctx->al_entry->instance = nctx->attr->instance; ntfs_attrlist_mark_dirty(ni); ntfs_attr_put_search_ctx(nctx); return 0; put_err_out: ntfs_attr_put_search_ctx(nctx); errno = err; return -1; } /** * ntfs_attr_record_move_away - move away attribute record from it's mft record * @ctx: attribute search context describing the attribute record * @extra: minimum amount of free space in the new holder of record * * New attribute record holder must have free @extra bytes after moving * attribute record to it. * * If this function succeed, user should reinit search context if he/she wants * use it anymore. * * Return 0 on success and -1 on error with errno set to the error code. */ int ntfs_attr_record_move_away(ntfs_attr_search_ctx *ctx, int extra) { ntfs_inode *base_ni, *ni; MFT_RECORD *m; int i; if (!ctx || !ctx->attr || !ctx->ntfs_ino || extra < 0) { errno = EINVAL; ntfs_log_perror("%s: ctx=%p ctx->attr=%p extra=%d", __FUNCTION__, ctx, ctx ? ctx->attr : NULL, extra); return -1; } ntfs_log_trace("Entering for attr 0x%x, inode %llu\n", (unsigned) le32_to_cpu(ctx->attr->type), (unsigned long long)ctx->ntfs_ino->mft_no); if (ctx->ntfs_ino->nr_extents == -1) base_ni = ctx->base_ntfs_ino; else base_ni = ctx->ntfs_ino; if (!NInoAttrList(base_ni)) { errno = EINVAL; ntfs_log_perror("Inode %llu has no attrlist", (unsigned long long)base_ni->mft_no); return -1; } if (ntfs_inode_attach_all_extents(ctx->ntfs_ino)) { ntfs_log_perror("Couldn't attach extents, inode=%llu", (unsigned long long)base_ni->mft_no); return -1; } /* Walk through all extents and try to move attribute to them. */ for (i = 0; i < base_ni->nr_extents; i++) { ni = base_ni->extent_nis[i]; m = ni->mrec; if (ctx->ntfs_ino->mft_no == ni->mft_no) continue; if (le32_to_cpu(m->bytes_allocated) - le32_to_cpu(m->bytes_in_use) < le32_to_cpu(ctx->attr->length) + extra) continue; /* * ntfs_attr_record_move_to can fail if extent with other lowest * VCN already present in inode we trying move record to. So, * do not return error. */ if (!ntfs_attr_record_move_to(ctx, ni)) return 0; } /* * Failed to move attribute to one of the current extents, so allocate * new extent and move attribute to it. */ ni = ntfs_mft_record_alloc(base_ni->vol, base_ni); if (!ni) { ntfs_log_perror("Couldn't allocate MFT record"); return -1; } if (ntfs_attr_record_move_to(ctx, ni)) { ntfs_log_perror("Couldn't move attribute to MFT record"); return -1; } return 0; } /** * ntfs_attr_make_non_resident - convert a resident to a non-resident attribute * @na: open ntfs attribute to make non-resident * @ctx: ntfs search context describing the attribute * * Convert a resident ntfs attribute to a non-resident one. * * Return 0 on success and -1 on error with errno set to the error code. The * following error codes are defined: * EPERM - The attribute is not allowed to be non-resident. * TODO: others... * * NOTE to self: No changes in the attribute list are required to move from * a resident to a non-resident attribute. * * Warning: We do not set the inode dirty and we do not write out anything! * We expect the caller to do this as this is a fairly low level * function and it is likely there will be further changes made. */ int ntfs_attr_make_non_resident(ntfs_attr *na, ntfs_attr_search_ctx *ctx) { s64 new_allocated_size, bw; ntfs_volume *vol = na->ni->vol; ATTR_REC *a = ctx->attr; runlist *rl; int mp_size, mp_ofs, name_ofs, arec_size, err; ntfs_log_trace("Entering for inode 0x%llx, attr 0x%x.\n", (unsigned long long)na->ni->mft_no, le32_to_cpu(na->type)); /* Some preliminary sanity checking. */ if (NAttrNonResident(na)) { ntfs_log_trace("Eeek! Trying to make non-resident attribute " "non-resident. Aborting...\n"); errno = EINVAL; return -1; } /* Check that the attribute is allowed to be non-resident. */ if (ntfs_attr_can_be_non_resident(vol, na->type, na->name, na->name_len)) return -1; new_allocated_size = (le32_to_cpu(a->value_length) + vol->cluster_size - 1) & ~(vol->cluster_size - 1); if (new_allocated_size > 0) { if ((a->flags & ATTR_COMPRESSION_MASK) == ATTR_IS_COMPRESSED) { /* must allocate full compression blocks */ new_allocated_size = ((new_allocated_size - 1) | ((1L << (STANDARD_COMPRESSION_UNIT + vol->cluster_size_bits)) - 1)) + 1; } /* Start by allocating clusters to hold the attribute value. */ rl = ntfs_cluster_alloc(vol, 0, new_allocated_size >> vol->cluster_size_bits, -1, DATA_ZONE); if (!rl) return -1; } else rl = NULL; /* * Setup the in-memory attribute structure to be non-resident so that * we can use ntfs_attr_pwrite(). */ NAttrSetNonResident(na); NAttrSetBeingNonResident(na); na->rl = rl; na->allocated_size = new_allocated_size; na->data_size = na->initialized_size = le32_to_cpu(a->value_length); /* * FIXME: For now just clear all of these as we don't support them when * writing. */ NAttrClearSparse(na); NAttrClearEncrypted(na); if ((a->flags & ATTR_COMPRESSION_MASK) == ATTR_IS_COMPRESSED) { /* set compression writing parameters */ na->compression_block_size = 1 << (STANDARD_COMPRESSION_UNIT + vol->cluster_size_bits); na->compression_block_clusters = 1 << STANDARD_COMPRESSION_UNIT; } if (rl) { /* Now copy the attribute value to the allocated cluster(s). */ bw = ntfs_attr_pwrite(na, 0, le32_to_cpu(a->value_length), (u8*)a + le16_to_cpu(a->value_offset)); if (bw != le32_to_cpu(a->value_length)) { err = errno; ntfs_log_debug("Eeek! Failed to write out attribute value " "(bw = %lli, errno = %i). " "Aborting...\n", (long long)bw, err); if (bw >= 0) err = EIO; goto cluster_free_err_out; } } /* Determine the size of the mapping pairs array. */ mp_size = ntfs_get_size_for_mapping_pairs(vol, rl, 0, INT_MAX); if (mp_size < 0) { err = errno; ntfs_log_debug("Eeek! Failed to get size for mapping pairs array. " "Aborting...\n"); goto cluster_free_err_out; } /* Calculate new offsets for the name and the mapping pairs array. */ if (na->ni->flags & FILE_ATTR_COMPRESSED) name_ofs = (sizeof(ATTR_REC) + 7) & ~7; else name_ofs = (sizeof(ATTR_REC) - sizeof(a->compressed_size) + 7) & ~7; mp_ofs = (name_ofs + a->name_length * sizeof(ntfschar) + 7) & ~7; /* * Determine the size of the resident part of the non-resident * attribute record. (Not compressed thus no compressed_size element * present.) */ arec_size = (mp_ofs + mp_size + 7) & ~7; /* Resize the resident part of the attribute record. */ if (ntfs_attr_record_resize(ctx->mrec, a, arec_size) < 0) { err = errno; goto cluster_free_err_out; } /* * Convert the resident part of the attribute record to describe a * non-resident attribute. */ a->non_resident = 1; /* Move the attribute name if it exists and update the offset. */ if (a->name_length) memmove((u8*)a + name_ofs, (u8*)a + le16_to_cpu(a->name_offset), a->name_length * sizeof(ntfschar)); a->name_offset = cpu_to_le16(name_ofs); /* Setup the fields specific to non-resident attributes. */ a->lowest_vcn = const_cpu_to_sle64(0); a->highest_vcn = cpu_to_sle64((new_allocated_size - 1) >> vol->cluster_size_bits); a->mapping_pairs_offset = cpu_to_le16(mp_ofs); /* * Update the flags to match the in-memory ones. * However cannot change the compression state if we had * a fuse_file_info open with a mark for release. * The decisions about compression can only be made when * creating/recreating the stream, not when making non resident. */ a->flags &= ~(ATTR_IS_SPARSE | ATTR_IS_ENCRYPTED); if ((a->flags & ATTR_COMPRESSION_MASK) == ATTR_IS_COMPRESSED) { /* support only ATTR_IS_COMPRESSED compression mode */ a->compression_unit = STANDARD_COMPRESSION_UNIT; a->compressed_size = const_cpu_to_sle64(0); } else { a->compression_unit = 0; a->flags &= ~ATTR_COMPRESSION_MASK; na->data_flags = a->flags; } memset(&a->reserved1, 0, sizeof(a->reserved1)); a->allocated_size = cpu_to_sle64(new_allocated_size); a->data_size = a->initialized_size = cpu_to_sle64(na->data_size); /* Generate the mapping pairs array in the attribute record. */ if (ntfs_mapping_pairs_build(vol, (u8*)a + mp_ofs, arec_size - mp_ofs, rl, 0, NULL) < 0) { // FIXME: Eeek! We need rollback! (AIA) ntfs_log_trace("Eeek! Failed to build mapping pairs. Leaving " "corrupt attribute record on disk. In memory " "runlist is still intact! Error code is %i. " "FIXME: Need to rollback instead!\n", errno); return -1; } /* Done! */ return 0; cluster_free_err_out: if (rl && ntfs_cluster_free(vol, na, 0, -1) < 0) ntfs_log_trace("Eeek! Failed to release allocated clusters in error " "code path. Leaving inconsistent metadata...\n"); NAttrClearNonResident(na); NAttrClearFullyMapped(na); na->allocated_size = na->data_size; na->rl = NULL; free(rl); errno = err; return -1; } static int ntfs_resident_attr_resize(ntfs_attr *na, const s64 newsize); /** * ntfs_resident_attr_resize - resize a resident, open ntfs attribute * @na: resident ntfs attribute to resize * @newsize: new size (in bytes) to which to resize the attribute * * Change the size of a resident, open ntfs attribute @na to @newsize bytes. * Can also be used to force an attribute non-resident. In this case, the * size cannot be changed. * * On success return 0 * On error return values are: * STATUS_RESIDENT_ATTRIBUTE_FILLED_MFT * STATUS_ERROR - otherwise * The following error codes are defined: * ENOMEM - Not enough memory to complete operation. * ERANGE - @newsize is not valid for the attribute type of @na. * ENOSPC - There is no enough space in base mft to resize $ATTRIBUTE_LIST. */ static int ntfs_resident_attr_resize_i(ntfs_attr *na, const s64 newsize, hole_type holes) { ntfs_attr_search_ctx *ctx; ntfs_volume *vol; ntfs_inode *ni; int err, ret = STATUS_ERROR; ntfs_log_trace("Inode 0x%llx attr 0x%x new size %lld\n", (unsigned long long)na->ni->mft_no, le32_to_cpu(na->type), (long long)newsize); /* Get the attribute record that needs modification. */ ctx = ntfs_attr_get_search_ctx(na->ni, NULL); if (!ctx) return -1; if (ntfs_attr_lookup(na->type, na->name, na->name_len, 0, 0, NULL, 0, ctx)) { err = errno; ntfs_log_perror("ntfs_attr_lookup failed"); goto put_err_out; } vol = na->ni->vol; /* * Check the attribute type and the corresponding minimum and maximum * sizes against @newsize and fail if @newsize is out of bounds. */ if (ntfs_attr_size_bounds_check(vol, na->type, newsize) < 0) { err = errno; if (err == ENOENT) err = EIO; ntfs_log_perror("%s: bounds check failed", __FUNCTION__); goto put_err_out; } /* * If @newsize is bigger than the mft record we need to make the * attribute non-resident if the attribute type supports it. If it is * smaller we can go ahead and attempt the resize. */ if ((newsize < vol->mft_record_size) && (holes != HOLES_NONRES)) { /* Perform the resize of the attribute record. */ if (!(ret = ntfs_resident_attr_value_resize(ctx->mrec, ctx->attr, newsize))) { /* Update attribute size everywhere. */ na->data_size = na->initialized_size = newsize; na->allocated_size = (newsize + 7) & ~7; if ((na->data_flags & ATTR_COMPRESSION_MASK) || NAttrSparse(na)) na->compressed_size = na->allocated_size; if (na->ni->mrec->flags & MFT_RECORD_IS_DIRECTORY ? na->type == AT_INDEX_ROOT && na->name == NTFS_INDEX_I30 : na->type == AT_DATA && na->name == AT_UNNAMED) { na->ni->data_size = na->data_size; if (((na->data_flags & ATTR_COMPRESSION_MASK) || NAttrSparse(na)) && NAttrNonResident(na)) na->ni->allocated_size = na->compressed_size; else na->ni->allocated_size = na->allocated_size; set_nino_flag(na->ni,KnownSize); if (na->type == AT_DATA) NInoFileNameSetDirty(na->ni); } goto resize_done; } /* Prefer AT_INDEX_ALLOCATION instead of AT_ATTRIBUTE_LIST */ if (ret == STATUS_RESIDENT_ATTRIBUTE_FILLED_MFT) { err = errno; goto put_err_out; } } /* There is not enough space in the mft record to perform the resize. */ /* Make the attribute non-resident if possible. */ if (!ntfs_attr_make_non_resident(na, ctx)) { ntfs_inode_mark_dirty(ctx->ntfs_ino); ntfs_attr_put_search_ctx(ctx); /* * do not truncate when forcing non-resident, this * could cause the attribute to be made resident again, * so size changes are not allowed. */ if (holes == HOLES_NONRES) { ret = 0; if (newsize != na->data_size) { ntfs_log_error("Cannot change size when" " forcing non-resident\n"); errno = EIO; ret = STATUS_ERROR; } return (ret); } /* Resize non-resident attribute */ return ntfs_attr_truncate_i(na, newsize, holes); } else if (errno != ENOSPC && errno != EPERM) { err = errno; ntfs_log_perror("Failed to make attribute non-resident"); goto put_err_out; } /* Try to make other attributes non-resident and retry each time. */ ntfs_attr_init_search_ctx(ctx, NULL, na->ni->mrec); while (!ntfs_attr_lookup(AT_UNUSED, NULL, 0, 0, 0, NULL, 0, ctx)) { ntfs_attr *tna; ATTR_RECORD *a; a = ctx->attr; if (a->non_resident) continue; /* * Check out whether convert is reasonable. Assume that mapping * pairs will take 8 bytes. */ if (le32_to_cpu(a->length) <= offsetof(ATTR_RECORD, compressed_size) + ((a->name_length * sizeof(ntfschar) + 7) & ~7) + 8) continue; tna = ntfs_attr_open(na->ni, a->type, (ntfschar*)((u8*)a + le16_to_cpu(a->name_offset)), a->name_length); if (!tna) { err = errno; ntfs_log_perror("Couldn't open attribute"); goto put_err_out; } if (ntfs_attr_make_non_resident(tna, ctx)) { ntfs_attr_close(tna); continue; } if ((tna->type == AT_DATA) && !tna->name_len) { /* * If we had to make the unnamed data attribute * non-resident, propagate its new allocated size * to all name attributes and directory indexes */ tna->ni->allocated_size = tna->allocated_size; NInoFileNameSetDirty(tna->ni); } if (((tna->data_flags & ATTR_COMPRESSION_MASK) == ATTR_IS_COMPRESSED) && ntfs_attr_pclose(tna)) { err = errno; ntfs_attr_close(tna); goto put_err_out; } ntfs_inode_mark_dirty(tna->ni); ntfs_attr_close(tna); ntfs_attr_put_search_ctx(ctx); return ntfs_resident_attr_resize_i(na, newsize, holes); } /* Check whether error occurred. */ if (errno != ENOENT) { err = errno; ntfs_log_perror("%s: Attribute lookup failed 1", __FUNCTION__); goto put_err_out; } /* * The standard information and attribute list attributes can't be * moved out from the base MFT record, so try to move out others. */ if (na->type==AT_STANDARD_INFORMATION || na->type==AT_ATTRIBUTE_LIST) { ntfs_attr_put_search_ctx(ctx); if (!NInoAttrList(na->ni) && ntfs_inode_add_attrlist(na->ni)) { ntfs_log_perror("Could not add attribute list"); return -1; } if (ntfs_inode_free_space(na->ni, offsetof(ATTR_RECORD, non_resident_end) + 8)) { ntfs_log_perror("Could not free space in MFT record"); return -1; } return ntfs_resident_attr_resize_i(na, newsize, holes); } /* * Move the attribute to a new mft record, creating an attribute list * attribute or modifying it if it is already present. */ /* Point search context back to attribute which we need resize. */ ntfs_attr_init_search_ctx(ctx, na->ni, NULL); if (ntfs_attr_lookup(na->type, na->name, na->name_len, CASE_SENSITIVE, 0, NULL, 0, ctx)) { ntfs_log_perror("%s: Attribute lookup failed 2", __FUNCTION__); err = errno; goto put_err_out; } /* * Check whether attribute is already single in this MFT record. * 8 added for the attribute terminator. */ if (le32_to_cpu(ctx->mrec->bytes_in_use) == le16_to_cpu(ctx->mrec->attrs_offset) + le32_to_cpu(ctx->attr->length) + 8) { err = ENOSPC; ntfs_log_trace("MFT record is filled with one attribute\n"); ret = STATUS_RESIDENT_ATTRIBUTE_FILLED_MFT; goto put_err_out; } /* Add attribute list if not present. */ if (na->ni->nr_extents == -1) ni = na->ni->base_ni; else ni = na->ni; if (!NInoAttrList(ni)) { ntfs_attr_put_search_ctx(ctx); if (ntfs_inode_add_attrlist(ni)) return -1; return ntfs_resident_attr_resize_i(na, newsize, holes); } /* Allocate new mft record. */ ni = ntfs_mft_record_alloc(vol, ni); if (!ni) { err = errno; ntfs_log_perror("Couldn't allocate new MFT record"); goto put_err_out; } /* Move attribute to it. */ if (ntfs_attr_record_move_to(ctx, ni)) { err = errno; ntfs_log_perror("Couldn't move attribute to new MFT record"); goto put_err_out; } /* Update ntfs attribute. */ if (na->ni->nr_extents == -1) na->ni = ni; ntfs_attr_put_search_ctx(ctx); /* Try to perform resize once again. */ return ntfs_resident_attr_resize_i(na, newsize, holes); resize_done: /* * Set the inode (and its base inode if it exists) dirty so it is * written out later. */ ntfs_inode_mark_dirty(ctx->ntfs_ino); ntfs_attr_put_search_ctx(ctx); return 0; put_err_out: ntfs_attr_put_search_ctx(ctx); errno = err; return ret; } static int ntfs_resident_attr_resize(ntfs_attr *na, const s64 newsize) { int ret; ntfs_log_enter("Entering\n"); ret = ntfs_resident_attr_resize_i(na, newsize, HOLES_OK); ntfs_log_leave("\n"); return ret; } /* * Force an attribute to be made non-resident without * changing its size. * * This is particularly needed when the attribute has no data, * as the non-resident variant requires more space in the MFT * record, and may imply expelling some other attribute. * * As a consequence the existing ntfs_attr_search_ctx's have to * be closed or reinitialized. * * returns 0 if successful, * < 0 if failed, with errno telling why */ int ntfs_attr_force_non_resident(ntfs_attr *na) { int res; res = ntfs_resident_attr_resize_i(na, na->data_size, HOLES_NONRES); if (!res && !NAttrNonResident(na)) { res = -1; errno = EIO; ntfs_log_error("Failed to force non-resident\n"); } return (res); } /** * ntfs_attr_make_resident - convert a non-resident to a resident attribute * @na: open ntfs attribute to make resident * @ctx: ntfs search context describing the attribute * * Convert a non-resident ntfs attribute to a resident one. * * Return 0 on success and -1 on error with errno set to the error code. The * following error codes are defined: * EINVAL - Invalid arguments passed. * EPERM - The attribute is not allowed to be resident. * EIO - I/O error, damaged inode or bug. * ENOSPC - There is no enough space to perform conversion. * EOPNOTSUPP - Requested conversion is not supported yet. * * Warning: We do not set the inode dirty and we do not write out anything! * We expect the caller to do this as this is a fairly low level * function and it is likely there will be further changes made. */ static int ntfs_attr_make_resident(ntfs_attr *na, ntfs_attr_search_ctx *ctx) { ntfs_volume *vol = na->ni->vol; ATTR_REC *a = ctx->attr; int name_ofs, val_ofs, err = EIO; s64 arec_size, bytes_read; ntfs_log_trace("Entering for inode 0x%llx, attr 0x%x.\n", (unsigned long long)na->ni->mft_no, le32_to_cpu(na->type)); /* Should be called for the first extent of the attribute. */ if (sle64_to_cpu(a->lowest_vcn)) { ntfs_log_trace("Eeek! Should be called for the first extent of the " "attribute. Aborting...\n"); errno = EINVAL; return -1; } /* Some preliminary sanity checking. */ if (!NAttrNonResident(na)) { ntfs_log_trace("Eeek! Trying to make resident attribute resident. " "Aborting...\n"); errno = EINVAL; return -1; } /* Make sure this is not $MFT/$BITMAP or Windows will not boot! */ if (na->type == AT_BITMAP && na->ni->mft_no == FILE_MFT) { errno = EPERM; return -1; } /* Check that the attribute is allowed to be resident. */ if (ntfs_attr_can_be_resident(vol, na->type)) return -1; if (na->data_flags & ATTR_IS_ENCRYPTED) { ntfs_log_trace("Making encrypted streams resident is not " "implemented yet.\n"); errno = EOPNOTSUPP; return -1; } /* Work out offsets into and size of the resident attribute. */ name_ofs = 24; /* = sizeof(resident_ATTR_REC); */ val_ofs = (name_ofs + a->name_length * sizeof(ntfschar) + 7) & ~7; arec_size = (val_ofs + na->data_size + 7) & ~7; /* Sanity check the size before we start modifying the attribute. */ if (le32_to_cpu(ctx->mrec->bytes_in_use) - le32_to_cpu(a->length) + arec_size > le32_to_cpu(ctx->mrec->bytes_allocated)) { errno = ENOSPC; ntfs_log_trace("Not enough space to make attribute resident\n"); return -1; } /* Read and cache the whole runlist if not already done. */ if (ntfs_attr_map_whole_runlist(na)) return -1; /* Move the attribute name if it exists and update the offset. */ if (a->name_length) { memmove((u8*)a + name_ofs, (u8*)a + le16_to_cpu(a->name_offset), a->name_length * sizeof(ntfschar)); } a->name_offset = cpu_to_le16(name_ofs); /* Resize the resident part of the attribute record. */ if (ntfs_attr_record_resize(ctx->mrec, a, arec_size) < 0) { /* * Bug, because ntfs_attr_record_resize should not fail (we * already checked that attribute fits MFT record). */ ntfs_log_error("BUG! Failed to resize attribute record. " "Please report to the %s. Aborting...\n", NTFS_DEV_LIST); errno = EIO; return -1; } /* Convert the attribute record to describe a resident attribute. */ a->non_resident = 0; a->flags = const_cpu_to_le16(0); a->value_length = cpu_to_le32(na->data_size); a->value_offset = cpu_to_le16(val_ofs); /* * If a data stream was wiped out, adjust the compression mode * to current state of compression flag */ if (!na->data_size && (na->type == AT_DATA) && (na->ni->vol->major_ver >= 3) && NVolCompression(na->ni->vol) && (na->ni->vol->cluster_size <= MAX_COMPRESSION_CLUSTER_SIZE) && (na->ni->flags & FILE_ATTR_COMPRESSED)) { a->flags |= ATTR_IS_COMPRESSED; na->data_flags = a->flags; } /* * File names cannot be non-resident so we would never see this here * but at least it serves as a reminder that there may be attributes * for which we do need to set this flag. (AIA) */ if (a->type == AT_FILE_NAME) a->resident_flags = RESIDENT_ATTR_IS_INDEXED; else a->resident_flags = 0; a->reservedR = 0; /* Sanity fixup... Shouldn't really happen. (AIA) */ if (na->initialized_size > na->data_size) na->initialized_size = na->data_size; /* Copy data from run list to resident attribute value. */ bytes_read = ntfs_rl_pread(vol, na->rl, 0, na->initialized_size, (u8*)a + val_ofs); if (bytes_read != na->initialized_size) { if (bytes_read < 0) err = errno; ntfs_log_trace("Eeek! Failed to read attribute data. Leaving " "inconstant metadata. Run chkdsk. " "Aborting...\n"); errno = err; return -1; } /* Clear memory in gap between initialized_size and data_size. */ if (na->initialized_size < na->data_size) memset((u8*)a + val_ofs + na->initialized_size, 0, na->data_size - na->initialized_size); /* * Deallocate clusters from the runlist. * * NOTE: We can use ntfs_cluster_free() because we have already mapped * the whole run list and thus it doesn't matter that the attribute * record is in a transiently corrupted state at this moment in time. */ if (ntfs_cluster_free(vol, na, 0, -1) < 0) { ntfs_log_perror("Eeek! Failed to release allocated clusters"); ntfs_log_trace("Ignoring error and leaving behind wasted " "clusters.\n"); } /* Throw away the now unused runlist. */ free(na->rl); na->rl = NULL; /* Update in-memory struct ntfs_attr. */ NAttrClearNonResident(na); NAttrClearFullyMapped(na); NAttrClearSparse(na); NAttrClearEncrypted(na); na->initialized_size = na->data_size; na->allocated_size = na->compressed_size = (na->data_size + 7) & ~7; na->compression_block_size = 0; na->compression_block_size_bits = na->compression_block_clusters = 0; return 0; } /* * If we are in the first extent, then set/clean sparse bit, * update allocated and compressed size. */ static int ntfs_attr_update_meta(ATTR_RECORD *a, ntfs_attr *na, MFT_RECORD *m, hole_type holes, ntfs_attr_search_ctx *ctx) { int sparse, ret = 0; ntfs_log_trace("Entering for inode 0x%llx, attr 0x%x\n", (unsigned long long)na->ni->mft_no, le32_to_cpu(na->type)); if (a->lowest_vcn) goto out; a->allocated_size = cpu_to_sle64(na->allocated_size); /* Update sparse bit, unless this is an intermediate state */ if (holes == HOLES_DELAY) sparse = (a->flags & ATTR_IS_SPARSE) != const_cpu_to_le16(0); else { sparse = ntfs_rl_sparse(na->rl); if (sparse == -1) { errno = EIO; goto error; } } /* Check whether attribute becomes sparse, unless check is delayed. */ if ((holes != HOLES_DELAY) && sparse && !(a->flags & (ATTR_IS_SPARSE | ATTR_IS_COMPRESSED))) { /* * Move attribute to another mft record, if attribute is too * small to add compressed_size field to it and we have no * free space in the current mft record. */ if ((le32_to_cpu(a->length) - le16_to_cpu(a->mapping_pairs_offset) == 8) && !(le32_to_cpu(m->bytes_allocated) - le32_to_cpu(m->bytes_in_use))) { if (!NInoAttrList(na->ni)) { ntfs_attr_put_search_ctx(ctx); if (ntfs_inode_add_attrlist(na->ni)) goto leave; goto retry; } if (ntfs_attr_record_move_away(ctx, 8)) { ntfs_log_perror("Failed to move attribute"); goto error; } ntfs_attr_put_search_ctx(ctx); goto retry; } if (!(le32_to_cpu(a->length) - le16_to_cpu( a->mapping_pairs_offset))) { errno = EIO; ntfs_log_perror("Mapping pairs space is 0"); goto error; } NAttrSetSparse(na); a->flags |= ATTR_IS_SPARSE; na->data_flags = a->flags; a->compression_unit = STANDARD_COMPRESSION_UNIT; /* Windows set it so, even if attribute is not actually compressed. */ memmove((u8*)a + le16_to_cpu(a->name_offset) + 8, (u8*)a + le16_to_cpu(a->name_offset), a->name_length * sizeof(ntfschar)); a->name_offset = cpu_to_le16(le16_to_cpu(a->name_offset) + 8); a->mapping_pairs_offset = cpu_to_le16(le16_to_cpu(a->mapping_pairs_offset) + 8); } /* Attribute no longer sparse. */ if (!sparse && (a->flags & ATTR_IS_SPARSE) && !(a->flags & ATTR_IS_COMPRESSED)) { NAttrClearSparse(na); a->flags &= ~ATTR_IS_SPARSE; na->data_flags = a->flags; a->compression_unit = 0; memmove((u8*)a + le16_to_cpu(a->name_offset) - 8, (u8*)a + le16_to_cpu(a->name_offset), a->name_length * sizeof(ntfschar)); if (le16_to_cpu(a->name_offset) >= 8) a->name_offset = cpu_to_le16(le16_to_cpu(a->name_offset) - 8); a->mapping_pairs_offset = cpu_to_le16(le16_to_cpu(a->mapping_pairs_offset) - 8); } /* Update compressed size if required. */ if (NAttrFullyMapped(na) && (sparse || (na->data_flags & ATTR_COMPRESSION_MASK))) { s64 new_compr_size; new_compr_size = ntfs_rl_get_compressed_size(na->ni->vol, na->rl); if (new_compr_size == -1) goto error; na->compressed_size = new_compr_size; a->compressed_size = cpu_to_sle64(new_compr_size); } /* * Set FILE_NAME dirty flag, to update sparse bit and * allocated size in the index. */ if (na->type == AT_DATA && na->name == AT_UNNAMED) { if (sparse || (na->data_flags & ATTR_COMPRESSION_MASK)) na->ni->allocated_size = na->compressed_size; else na->ni->allocated_size = na->allocated_size; NInoFileNameSetDirty(na->ni); } out: return ret; leave: ret = -1; goto out; /* return -1 */ retry: ret = -2; goto out; error: ret = -3; goto out; } #define NTFS_VCN_DELETE_MARK -2 /** * ntfs_attr_update_mapping_pairs_i - see ntfs_attr_update_mapping_pairs */ static int ntfs_attr_update_mapping_pairs_i(ntfs_attr *na, VCN from_vcn, hole_type holes) { ntfs_attr_search_ctx *ctx; ntfs_inode *ni, *base_ni; MFT_RECORD *m; ATTR_RECORD *a; VCN stop_vcn; const runlist_element *stop_rl; int err, mp_size, cur_max_mp_size, exp_max_mp_size, ret = -1; BOOL finished_build; BOOL first_updated = FALSE; retry: if (!na || !na->rl) { errno = EINVAL; ntfs_log_perror("%s: na=%p", __FUNCTION__, na); return -1; } ntfs_log_trace("Entering for inode %llu, attr 0x%x\n", (unsigned long long)na->ni->mft_no, le32_to_cpu(na->type)); if (!NAttrNonResident(na)) { errno = EINVAL; ntfs_log_perror("%s: resident attribute", __FUNCTION__); return -1; } #if PARTIAL_RUNLIST_UPDATING /* * For a file just been made sparse, we will have * to reformat the first extent, so be sure the * runlist is fully mapped and fully processed. * Same if the file was sparse and is not any more. * Note : not needed if the full runlist is to be processed */ if ((holes != HOLES_DELAY) && (!NAttrFullyMapped(na) || from_vcn) && !(na->data_flags & ATTR_IS_COMPRESSED)) { BOOL changed; if (!(na->data_flags & ATTR_IS_SPARSE)) { int sparse = 0; runlist_element *xrl; /* * If attribute was not sparse, we only * have to check whether there is a hole * in the updated region. */ for (xrl = na->rl; xrl->length; xrl++) { if (xrl->lcn < 0) { if (xrl->lcn == LCN_HOLE) { sparse = 1; break; } if (xrl->lcn != LCN_RL_NOT_MAPPED) { sparse = -1; break; } } } if (sparse < 0) { ntfs_log_error("Could not check whether sparse\n"); errno = EIO; return (-1); } changed = sparse > 0; } else { /* * If attribute was sparse, the compressed * size has been maintained, and it gives * and easy way to check whether the * attribute is still sparse. */ changed = (((na->data_size - 1) | (na->ni->vol->cluster_size - 1)) + 1) == na->compressed_size; } if (changed) { if (ntfs_attr_map_whole_runlist(na)) { ntfs_log_error("Could not map whole for sparse change\n"); errno = EIO; return (-1); } from_vcn = 0; } } #endif if (na->ni->nr_extents == -1) base_ni = na->ni->base_ni; else base_ni = na->ni; ctx = ntfs_attr_get_search_ctx(base_ni, NULL); if (!ctx) return -1; /* Fill attribute records with new mapping pairs. */ stop_vcn = 0; stop_rl = na->rl; finished_build = FALSE; while (!ntfs_attr_lookup(na->type, na->name, na->name_len, CASE_SENSITIVE, from_vcn, NULL, 0, ctx)) { a = ctx->attr; m = ctx->mrec; if (!a->lowest_vcn) first_updated = TRUE; /* * If runlist is updating not from the beginning, then set * @stop_vcn properly, i.e. to the lowest vcn of record that * contain @from_vcn. Also we do not need @from_vcn anymore, * set it to 0 to make ntfs_attr_lookup enumerate attributes. */ if (from_vcn) { LCN first_lcn; stop_vcn = sle64_to_cpu(a->lowest_vcn); from_vcn = 0; /* * Check whether the first run we need to update is * the last run in runlist, if so, then deallocate * all attrubute extents starting this one. */ first_lcn = ntfs_rl_vcn_to_lcn(na->rl, stop_vcn); if (first_lcn == LCN_EINVAL) { errno = EIO; ntfs_log_perror("Bad runlist"); goto put_err_out; } if (first_lcn == LCN_ENOENT || first_lcn == LCN_RL_NOT_MAPPED) finished_build = TRUE; } /* * Check whether we finished mapping pairs build, if so mark * extent as need to delete (by setting highest vcn to * NTFS_VCN_DELETE_MARK (-2), we shall check it later and * delete extent) and continue search. */ if (finished_build) { ntfs_log_trace("Mark attr 0x%x for delete in inode " "%lld.\n", (unsigned)le32_to_cpu(a->type), (long long)ctx->ntfs_ino->mft_no); a->highest_vcn = cpu_to_sle64(NTFS_VCN_DELETE_MARK); ntfs_inode_mark_dirty(ctx->ntfs_ino); continue; } switch (ntfs_attr_update_meta(a, na, m, holes, ctx)) { case -1: return -1; case -2: goto retry; case -3: goto put_err_out; } /* * Determine maximum possible length of mapping pairs, * if we shall *not* expand space for mapping pairs. */ cur_max_mp_size = le32_to_cpu(a->length) - le16_to_cpu(a->mapping_pairs_offset); /* * Determine maximum possible length of mapping pairs in the * current mft record, if we shall expand space for mapping * pairs. */ exp_max_mp_size = le32_to_cpu(m->bytes_allocated) - le32_to_cpu(m->bytes_in_use) + cur_max_mp_size; /* Get the size for the rest of mapping pairs array. */ mp_size = ntfs_get_size_for_mapping_pairs(na->ni->vol, stop_rl, stop_vcn, exp_max_mp_size); if (mp_size <= 0) { ntfs_log_perror("%s: get MP size failed", __FUNCTION__); goto put_err_out; } /* Test mapping pairs for fitting in the current mft record. */ if (mp_size > exp_max_mp_size) { /* * Mapping pairs of $ATTRIBUTE_LIST attribute must fit * in the base mft record. Try to move out other * attributes and try again. */ if (na->type == AT_ATTRIBUTE_LIST) { ntfs_attr_put_search_ctx(ctx); if (ntfs_inode_free_space(na->ni, mp_size - cur_max_mp_size)) { ntfs_log_perror("Attribute list is too " "big. Defragment the " "volume\n"); return -1; } goto retry; } /* Add attribute list if it isn't present, and retry. */ if (!NInoAttrList(base_ni)) { ntfs_attr_put_search_ctx(ctx); if (ntfs_inode_add_attrlist(base_ni)) { ntfs_log_perror("Can not add attrlist"); return -1; } goto retry; } /* * Set mapping pairs size to maximum possible for this * mft record. We shall write the rest of mapping pairs * to another MFT records. */ mp_size = exp_max_mp_size; } /* Change space for mapping pairs if we need it. */ if (((mp_size + 7) & ~7) != cur_max_mp_size) { if (ntfs_attr_record_resize(m, a, le16_to_cpu(a->mapping_pairs_offset) + mp_size)) { errno = EIO; ntfs_log_perror("Failed to resize attribute"); goto put_err_out; } } /* Update lowest vcn. */ a->lowest_vcn = cpu_to_sle64(stop_vcn); ntfs_inode_mark_dirty(ctx->ntfs_ino); if ((ctx->ntfs_ino->nr_extents == -1 || NInoAttrList(ctx->ntfs_ino)) && ctx->attr->type != AT_ATTRIBUTE_LIST) { ctx->al_entry->lowest_vcn = cpu_to_sle64(stop_vcn); ntfs_attrlist_mark_dirty(ctx->ntfs_ino); } /* * Generate the new mapping pairs array directly into the * correct destination, i.e. the attribute record itself. */ if (!ntfs_mapping_pairs_build(na->ni->vol, (u8*)a + le16_to_cpu( a->mapping_pairs_offset), mp_size, na->rl, stop_vcn, &stop_rl)) finished_build = TRUE; if (stop_rl) stop_vcn = stop_rl->vcn; else stop_vcn = 0; if (!finished_build && errno != ENOSPC) { ntfs_log_perror("Failed to build mapping pairs"); goto put_err_out; } a->highest_vcn = cpu_to_sle64(stop_vcn - 1); } /* Check whether error occurred. */ if (errno != ENOENT) { ntfs_log_perror("%s: Attribute lookup failed", __FUNCTION__); goto put_err_out; } /* * If the base extent was skipped in the above process, * we still may have to update the sizes. */ if (!first_updated) { le16 spcomp; ntfs_attr_reinit_search_ctx(ctx); if (!ntfs_attr_lookup(na->type, na->name, na->name_len, CASE_SENSITIVE, 0, NULL, 0, ctx)) { a = ctx->attr; a->allocated_size = cpu_to_sle64(na->allocated_size); spcomp = na->data_flags & (ATTR_IS_COMPRESSED | ATTR_IS_SPARSE); if (spcomp) a->compressed_size = cpu_to_sle64(na->compressed_size); /* Updating sizes taints the extent holding the attr */ if (ctx->ntfs_ino) NInoSetDirty(ctx->ntfs_ino); if ((na->type == AT_DATA) && (na->name == AT_UNNAMED)) { na->ni->allocated_size = (spcomp ? na->compressed_size : na->allocated_size); NInoFileNameSetDirty(na->ni); } } else { ntfs_log_error("Failed to update sizes in base extent\n"); goto put_err_out; } } /* Deallocate not used attribute extents and return with success. */ if (finished_build) { ntfs_attr_reinit_search_ctx(ctx); ntfs_log_trace("Deallocate marked extents.\n"); while (!ntfs_attr_lookup(na->type, na->name, na->name_len, CASE_SENSITIVE, 0, NULL, 0, ctx)) { if (sle64_to_cpu(ctx->attr->highest_vcn) != NTFS_VCN_DELETE_MARK) continue; /* Remove unused attribute record. */ if (ntfs_attr_record_rm(ctx)) { ntfs_log_perror("Could not remove unused attr"); goto put_err_out; } ntfs_attr_reinit_search_ctx(ctx); } if (errno != ENOENT) { ntfs_log_perror("%s: Attr lookup failed", __FUNCTION__); goto put_err_out; } ntfs_log_trace("Deallocate done.\n"); ntfs_attr_put_search_ctx(ctx); goto ok; } ntfs_attr_put_search_ctx(ctx); ctx = NULL; /* Allocate new MFT records for the rest of mapping pairs. */ while (1) { /* Calculate size of rest mapping pairs. */ mp_size = ntfs_get_size_for_mapping_pairs(na->ni->vol, na->rl, stop_vcn, INT_MAX); if (mp_size <= 0) { ntfs_log_perror("%s: get mp size failed", __FUNCTION__); goto put_err_out; } /* Allocate new mft record, with special case for mft itself */ if (!na->ni->mft_no) ni = ntfs_mft_rec_alloc(na->ni->vol, na->type == AT_DATA); else ni = ntfs_mft_record_alloc(na->ni->vol, base_ni); if (!ni) { ntfs_log_perror("Could not allocate new MFT record"); goto put_err_out; } m = ni->mrec; /* * If mapping size exceed available space, set them to * possible maximum. */ cur_max_mp_size = le32_to_cpu(m->bytes_allocated) - le32_to_cpu(m->bytes_in_use) - (offsetof(ATTR_RECORD, compressed_size) + (((na->data_flags & ATTR_COMPRESSION_MASK) || NAttrSparse(na)) ? sizeof(a->compressed_size) : 0)) - ((sizeof(ntfschar) * na->name_len + 7) & ~7); if (mp_size > cur_max_mp_size) mp_size = cur_max_mp_size; /* Add attribute extent to new record. */ err = ntfs_non_resident_attr_record_add(ni, na->type, na->name, na->name_len, stop_vcn, mp_size, na->data_flags); if (err == -1) { err = errno; ntfs_log_perror("Could not add attribute extent"); if (ntfs_mft_record_free(na->ni->vol, ni)) ntfs_log_perror("Could not free MFT record"); errno = err; goto put_err_out; } a = (ATTR_RECORD*)((u8*)m + err); err = ntfs_mapping_pairs_build(na->ni->vol, (u8*)a + le16_to_cpu(a->mapping_pairs_offset), mp_size, na->rl, stop_vcn, &stop_rl); if (stop_rl) stop_vcn = stop_rl->vcn; else stop_vcn = 0; if (err < 0 && errno != ENOSPC) { err = errno; ntfs_log_perror("Failed to build MP"); if (ntfs_mft_record_free(na->ni->vol, ni)) ntfs_log_perror("Couldn't free MFT record"); errno = err; goto put_err_out; } a->highest_vcn = cpu_to_sle64(stop_vcn - 1); ntfs_inode_mark_dirty(ni); /* All mapping pairs has been written. */ if (!err) break; } ok: NAttrClearRunlistDirty(na); ret = 0; out: return ret; put_err_out: if (ctx) ntfs_attr_put_search_ctx(ctx); goto out; } #undef NTFS_VCN_DELETE_MARK /** * ntfs_attr_update_mapping_pairs - update mapping pairs for ntfs attribute * @na: non-resident ntfs open attribute for which we need update * @from_vcn: update runlist starting this VCN * * Build mapping pairs from @na->rl and write them to the disk. Also, this * function updates sparse bit, allocated and compressed size (allocates/frees * space for this field if required). * * @na->allocated_size should be set to correct value for the new runlist before * call to this function. Vice-versa @na->compressed_size will be calculated and * set to correct value during this function. * * FIXME: This function does not update sparse bit and compressed size correctly * if called with @from_vcn != 0. * * FIXME: Rewrite without using NTFS_VCN_DELETE_MARK define. * * On success return 0 and on error return -1 with errno set to the error code. * The following error codes are defined: * EINVAL - Invalid arguments passed. * ENOMEM - Not enough memory to complete operation. * ENOSPC - There is no enough space in base mft to resize $ATTRIBUTE_LIST * or there is no free MFT records left to allocate. */ int ntfs_attr_update_mapping_pairs(ntfs_attr *na, VCN from_vcn) { int ret; ntfs_log_enter("Entering\n"); ret = ntfs_attr_update_mapping_pairs_i(na, from_vcn, HOLES_OK); ntfs_log_leave("\n"); return ret; } /** * ntfs_non_resident_attr_shrink - shrink a non-resident, open ntfs attribute * @na: non-resident ntfs attribute to shrink * @newsize: new size (in bytes) to which to shrink the attribute * * Reduce the size of a non-resident, open ntfs attribute @na to @newsize bytes. * * On success return 0 and on error return -1 with errno set to the error code. * The following error codes are defined: * ENOMEM - Not enough memory to complete operation. * ERANGE - @newsize is not valid for the attribute type of @na. */ static int ntfs_non_resident_attr_shrink(ntfs_attr *na, const s64 newsize) { ntfs_volume *vol; ntfs_attr_search_ctx *ctx; VCN first_free_vcn; s64 nr_freed_clusters; int err; ntfs_log_trace("Inode 0x%llx attr 0x%x new size %lld\n", (unsigned long long) na->ni->mft_no, le32_to_cpu(na->type), (long long)newsize); vol = na->ni->vol; /* * Check the attribute type and the corresponding minimum size * against @newsize and fail if @newsize is too small. */ if (ntfs_attr_size_bounds_check(vol, na->type, newsize) < 0) { if (errno == ERANGE) { ntfs_log_trace("Eeek! Size bounds check failed. " "Aborting...\n"); } else if (errno == ENOENT) errno = EIO; return -1; } /* The first cluster outside the new allocation. */ if (na->data_flags & ATTR_COMPRESSION_MASK) /* * For compressed files we must keep full compressions blocks, * but currently we do not decompress/recompress the last * block to truncate the data, so we may leave more allocated * clusters than really needed. */ first_free_vcn = (((newsize - 1) | (na->compression_block_size - 1)) + 1) >> vol->cluster_size_bits; else first_free_vcn = (newsize + vol->cluster_size - 1) >> vol->cluster_size_bits; /* * Compare the new allocation with the old one and only deallocate * clusters if there is a change. */ if ((na->allocated_size >> vol->cluster_size_bits) != first_free_vcn) { if (ntfs_attr_map_whole_runlist(na)) { ntfs_log_trace("Eeek! ntfs_attr_map_whole_runlist " "failed.\n"); return -1; } /* Deallocate all clusters starting with the first free one. */ nr_freed_clusters = ntfs_cluster_free(vol, na, first_free_vcn, -1); if (nr_freed_clusters < 0) { ntfs_log_trace("Eeek! Freeing of clusters failed. " "Aborting...\n"); return -1; } /* Truncate the runlist itself. */ if (ntfs_rl_truncate(&na->rl, first_free_vcn)) { /* * Failed to truncate the runlist, so just throw it * away, it will be mapped afresh on next use. */ free(na->rl); na->rl = NULL; ntfs_log_trace("Eeek! Run list truncation failed.\n"); return -1; } NAttrSetRunlistDirty(na); /* Prepare to mapping pairs update. */ na->allocated_size = first_free_vcn << vol->cluster_size_bits; /* Write mapping pairs for new runlist. */ if (ntfs_attr_update_mapping_pairs(na, 0 /*first_free_vcn*/)) { ntfs_log_trace("Eeek! Mapping pairs update failed. " "Leaving inconstant metadata. " "Run chkdsk.\n"); return -1; } } /* Get the first attribute record. */ ctx = ntfs_attr_get_search_ctx(na->ni, NULL); if (!ctx) return -1; if (ntfs_attr_lookup(na->type, na->name, na->name_len, CASE_SENSITIVE, 0, NULL, 0, ctx)) { err = errno; if (err == ENOENT) err = EIO; ntfs_log_trace("Eeek! Lookup of first attribute extent failed. " "Leaving inconstant metadata.\n"); goto put_err_out; } /* Update data and initialized size. */ na->data_size = newsize; ctx->attr->data_size = cpu_to_sle64(newsize); if (newsize < na->initialized_size) { na->initialized_size = newsize; ctx->attr->initialized_size = cpu_to_sle64(newsize); } /* Update data size in the index. */ if (na->ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) { if (na->type == AT_INDEX_ROOT && na->name == NTFS_INDEX_I30) { na->ni->data_size = na->data_size; na->ni->allocated_size = na->allocated_size; set_nino_flag(na->ni,KnownSize); } } else { if (na->type == AT_DATA && na->name == AT_UNNAMED) { na->ni->data_size = na->data_size; NInoFileNameSetDirty(na->ni); } } /* If the attribute now has zero size, make it resident. */ if (!newsize) { if (!(na->data_flags & ATTR_IS_ENCRYPTED) && ntfs_attr_make_resident(na, ctx)) { /* If couldn't make resident, just continue. */ if (errno != EPERM) ntfs_log_error("Failed to make attribute " "resident. Leaving as is...\n"); } } /* Set the inode dirty so it is written out later. */ ntfs_inode_mark_dirty(ctx->ntfs_ino); /* Done! */ ntfs_attr_put_search_ctx(ctx); return 0; put_err_out: ntfs_attr_put_search_ctx(ctx); errno = err; return -1; } /** * ntfs_non_resident_attr_expand - expand a non-resident, open ntfs attribute * @na: non-resident ntfs attribute to expand * @newsize: new size (in bytes) to which to expand the attribute * * Expand the size of a non-resident, open ntfs attribute @na to @newsize bytes, * by allocating new clusters. * * On success return 0 and on error return -1 with errno set to the error code. * The following error codes are defined: * ENOMEM - Not enough memory to complete operation. * ERANGE - @newsize is not valid for the attribute type of @na. * ENOSPC - There is no enough space in base mft to resize $ATTRIBUTE_LIST. */ static int ntfs_non_resident_attr_expand_i(ntfs_attr *na, const s64 newsize, hole_type holes) { LCN lcn_seek_from; VCN first_free_vcn; ntfs_volume *vol; ntfs_attr_search_ctx *ctx; runlist *rl, *rln; s64 org_alloc_size; int err; ntfs_log_trace("Inode %lld, attr 0x%x, new size %lld old size %lld\n", (unsigned long long)na->ni->mft_no, le32_to_cpu(na->type), (long long)newsize, (long long)na->data_size); vol = na->ni->vol; /* * Check the attribute type and the corresponding maximum size * against @newsize and fail if @newsize is too big. */ if (ntfs_attr_size_bounds_check(vol, na->type, newsize) < 0) { if (errno == ENOENT) errno = EIO; ntfs_log_perror("%s: bounds check failed", __FUNCTION__); return -1; } if (na->type == AT_DATA) NAttrSetDataAppending(na); /* Save for future use. */ org_alloc_size = na->allocated_size; /* The first cluster outside the new allocation. */ first_free_vcn = (newsize + vol->cluster_size - 1) >> vol->cluster_size_bits; /* * Compare the new allocation with the old one and only allocate * clusters if there is a change. */ if ((na->allocated_size >> vol->cluster_size_bits) < first_free_vcn) { #if PARTIAL_RUNLIST_UPDATING s64 start_update; /* * Update from the last previously allocated run, * as we may have to expand an existing hole. */ start_update = na->allocated_size >> vol->cluster_size_bits; if (start_update) start_update--; if (ntfs_attr_map_partial_runlist(na, start_update)) { ntfs_log_perror("failed to map partial runlist"); return -1; } #else if (ntfs_attr_map_whole_runlist(na)) { ntfs_log_perror("ntfs_attr_map_whole_runlist failed"); return -1; } #endif /* * If we extend $DATA attribute on NTFS 3+ volume, we can add * sparse runs instead of real allocation of clusters. */ if ((na->type == AT_DATA) && (vol->major_ver >= 3) && (holes != HOLES_NO)) { rl = ntfs_malloc(0x1000); if (!rl) return -1; rl[0].vcn = (na->allocated_size >> vol->cluster_size_bits); rl[0].lcn = LCN_HOLE; rl[0].length = first_free_vcn - (na->allocated_size >> vol->cluster_size_bits); rl[1].vcn = first_free_vcn; rl[1].lcn = LCN_ENOENT; rl[1].length = 0; } else { /* * Determine first after last LCN of attribute. * We will start seek clusters from this LCN to avoid * fragmentation. If there are no valid LCNs in the * attribute let the cluster allocator choose the * starting LCN. */ lcn_seek_from = -1; if (na->rl->length) { /* Seek to the last run list element. */ for (rl = na->rl; (rl + 1)->length; rl++) ; /* * If the last LCN is a hole or similar seek * back to last valid LCN. */ while (rl->lcn < 0 && rl != na->rl) rl--; /* * Only set lcn_seek_from it the LCN is valid. */ if (rl->lcn >= 0) lcn_seek_from = rl->lcn + rl->length; } rl = ntfs_cluster_alloc(vol, na->allocated_size >> vol->cluster_size_bits, first_free_vcn - (na->allocated_size >> vol->cluster_size_bits), lcn_seek_from, DATA_ZONE); if (!rl) { ntfs_log_perror("Cluster allocation failed " "(%lld)", (long long)first_free_vcn - ((long long)na->allocated_size >> vol->cluster_size_bits)); return -1; } } /* Append new clusters to attribute runlist. */ rln = ntfs_runlists_merge(na->rl, rl); if (!rln) { /* Failed, free just allocated clusters. */ err = errno; ntfs_log_perror("Run list merge failed"); ntfs_cluster_free_from_rl(vol, rl); free(rl); errno = err; return -1; } na->rl = rln; NAttrSetRunlistDirty(na); /* Prepare to mapping pairs update. */ na->allocated_size = first_free_vcn << vol->cluster_size_bits; #if PARTIAL_RUNLIST_UPDATING /* * Write mapping pairs for new runlist, unless this is * a temporary state before appending data. * If the update is not done, we must be sure to do * it later, and to get to a clean state even on errors. */ if ((holes != HOLES_DELAY) && ntfs_attr_update_mapping_pairs_i(na, start_update, holes)) { #else /* Write mapping pairs for new runlist. */ if (ntfs_attr_update_mapping_pairs(na, 0)) { #endif err = errno; ntfs_log_perror("Mapping pairs update failed"); goto rollback; } } ctx = ntfs_attr_get_search_ctx(na->ni, NULL); if (!ctx) { err = errno; if (na->allocated_size == org_alloc_size) { errno = err; return -1; } else goto rollback; } if (ntfs_attr_lookup(na->type, na->name, na->name_len, CASE_SENSITIVE, 0, NULL, 0, ctx)) { err = errno; ntfs_log_perror("Lookup of first attribute extent failed"); if (err == ENOENT) err = EIO; if (na->allocated_size != org_alloc_size) { ntfs_attr_put_search_ctx(ctx); goto rollback; } else goto put_err_out; } /* Update data size. */ na->data_size = newsize; ctx->attr->data_size = cpu_to_sle64(newsize); /* Update data size in the index. */ if (na->ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) { if (na->type == AT_INDEX_ROOT && na->name == NTFS_INDEX_I30) { na->ni->data_size = na->data_size; na->ni->allocated_size = na->allocated_size; set_nino_flag(na->ni,KnownSize); } } else { if (na->type == AT_DATA && na->name == AT_UNNAMED) { na->ni->data_size = na->data_size; NInoFileNameSetDirty(na->ni); } } /* Set the inode dirty so it is written out later. */ ntfs_inode_mark_dirty(ctx->ntfs_ino); /* Done! */ ntfs_attr_put_search_ctx(ctx); return 0; rollback: /* Free allocated clusters. */ if (ntfs_cluster_free(vol, na, org_alloc_size >> vol->cluster_size_bits, -1) < 0) { err = EIO; ntfs_log_perror("Leaking clusters"); } /* Now, truncate the runlist itself. */ if (ntfs_rl_truncate(&na->rl, org_alloc_size >> vol->cluster_size_bits)) { /* * Failed to truncate the runlist, so just throw it away, it * will be mapped afresh on next use. */ free(na->rl); na->rl = NULL; ntfs_log_perror("Couldn't truncate runlist. Rollback failed"); } else { NAttrSetRunlistDirty(na); /* Prepare to mapping pairs update. */ na->allocated_size = org_alloc_size; /* Restore mapping pairs. */ if (ntfs_attr_update_mapping_pairs(na, 0 /*na->allocated_size >> vol->cluster_size_bits*/)) { ntfs_log_perror("Failed to restore old mapping pairs"); } } errno = err; return -1; put_err_out: ntfs_attr_put_search_ctx(ctx); errno = err; return -1; } static int ntfs_non_resident_attr_expand(ntfs_attr *na, const s64 newsize, hole_type holes) { int ret; ntfs_log_enter("Entering\n"); ret = ntfs_non_resident_attr_expand_i(na, newsize, holes); ntfs_log_leave("\n"); return ret; } /** * ntfs_attr_truncate - resize an ntfs attribute * @na: open ntfs attribute to resize * @newsize: new size (in bytes) to which to resize the attribute * @holes: how to create a hole if expanding * * Change the size of an open ntfs attribute @na to @newsize bytes. If the * attribute is made bigger and the attribute is resident the newly * "allocated" space is cleared and if the attribute is non-resident the * newly allocated space is marked as not initialised and no real allocation * on disk is performed. * * On success return 0. * On error return values are: * STATUS_RESIDENT_ATTRIBUTE_FILLED_MFT * STATUS_ERROR - otherwise * The following error codes are defined: * EINVAL - Invalid arguments were passed to the function. * EOPNOTSUPP - The desired resize is not implemented yet. * EACCES - Encrypted attribute. */ static int ntfs_attr_truncate_i(ntfs_attr *na, const s64 newsize, hole_type holes) { int ret = STATUS_ERROR; s64 fullsize; BOOL compressed; if (!na || newsize < 0 || (na->ni->mft_no == FILE_MFT && na->type == AT_DATA)) { ntfs_log_trace("Invalid arguments passed.\n"); errno = EINVAL; return STATUS_ERROR; } ntfs_log_enter("Entering for inode %lld, attr 0x%x, size %lld\n", (unsigned long long)na->ni->mft_no, le32_to_cpu(na->type), (long long)newsize); if (na->data_size == newsize) { ntfs_log_trace("Size is already ok\n"); ret = STATUS_OK; goto out; } /* * Encrypted attributes are not supported. We return access denied, * which is what Windows NT4 does, too. */ if ((na->data_flags & ATTR_IS_ENCRYPTED) && !na->ni->vol->efs_raw) { errno = EACCES; ntfs_log_trace("Cannot truncate encrypted attribute\n"); goto out; } /* * TODO: Implement making handling of compressed attributes. * Currently we can only expand the attribute or delete it, * and only for ATTR_IS_COMPRESSED. This is however possible * for resident attributes when there is no open fuse context * (important case : $INDEX_ROOT:$I30) */ compressed = (na->data_flags & ATTR_COMPRESSION_MASK) != const_cpu_to_le16(0); if (compressed && NAttrNonResident(na) && ((na->data_flags & ATTR_COMPRESSION_MASK) != ATTR_IS_COMPRESSED)) { errno = EOPNOTSUPP; ntfs_log_perror("Failed to truncate compressed attribute"); goto out; } if (NAttrNonResident(na)) { /* * For compressed data, the last block must be fully * allocated, and we do not know the size of compression * block until the attribute has been made non-resident. * Moreover we can only process a single compression * block at a time (from where we are about to write), * so we silently do not allocate more. * * Note : do not request upsizing of compressed files * unless being able to face the consequences ! */ if (compressed && newsize && (newsize > na->data_size)) fullsize = (na->initialized_size | (na->compression_block_size - 1)) + 1; else fullsize = newsize; if (fullsize > na->data_size) ret = ntfs_non_resident_attr_expand(na, fullsize, holes); else ret = ntfs_non_resident_attr_shrink(na, fullsize); } else ret = ntfs_resident_attr_resize_i(na, newsize, holes); out: ntfs_log_leave("Return status %d\n", ret); return ret; } /* * Resize an attribute, creating a hole if relevant */ int ntfs_attr_truncate(ntfs_attr *na, const s64 newsize) { int r; r = ntfs_attr_truncate_i(na, newsize, HOLES_OK); NAttrClearDataAppending(na); NAttrClearBeingNonResident(na); return (r); } /* * Resize an attribute, avoiding hole creation */ int ntfs_attr_truncate_solid(ntfs_attr *na, const s64 newsize) { return (ntfs_attr_truncate_i(na, newsize, HOLES_NO)); } /* * Stuff a hole in a compressed file * * An unallocated hole must be aligned on compression block size. * If needed current block and target block are stuffed with zeroes. * * Returns 0 if succeeded, * -1 if it failed (as explained in errno) */ static int stuff_hole(ntfs_attr *na, const s64 pos) { s64 size; s64 begin_size; s64 end_size; char *buf; int ret; ret = 0; /* * If the attribute is resident, the compression block size * is not defined yet and we can make no decision. * So we first try resizing to the target and if the * attribute is still resident, we're done */ if (!NAttrNonResident(na)) { ret = ntfs_resident_attr_resize(na, pos); if (!ret && !NAttrNonResident(na)) na->initialized_size = na->data_size = pos; } if (!ret && NAttrNonResident(na)) { /* does the hole span over several compression block ? */ if ((pos ^ na->initialized_size) & ~(na->compression_block_size - 1)) { begin_size = ((na->initialized_size - 1) | (na->compression_block_size - 1)) + 1 - na->initialized_size; end_size = pos & (na->compression_block_size - 1); size = (begin_size > end_size ? begin_size : end_size); } else { /* short stuffing in a single compression block */ begin_size = size = pos - na->initialized_size; end_size = 0; } if (size) buf = (char*)ntfs_malloc(size); else buf = (char*)NULL; if (buf || !size) { memset(buf,0,size); /* stuff into current block */ if (begin_size && (ntfs_attr_pwrite(na, na->initialized_size, begin_size, buf) != begin_size)) ret = -1; /* create an unstuffed hole */ if (!ret && ((na->initialized_size + end_size) < pos) && ntfs_non_resident_attr_expand(na, pos - end_size, HOLES_OK)) ret = -1; else na->initialized_size = na->data_size = pos - end_size; /* stuff into the target block */ if (!ret && end_size && (ntfs_attr_pwrite(na, na->initialized_size, end_size, buf) != end_size)) ret = -1; if (buf) free(buf); } else ret = -1; } /* make absolutely sure we have reached the target */ if (!ret && (na->initialized_size != pos)) { ntfs_log_error("Failed to stuff a compressed file" "target %lld reached %lld\n", (long long)pos, (long long)na->initialized_size); errno = EIO; ret = -1; } return (ret); } /** * ntfs_attr_readall - read the entire data from an ntfs attribute * @ni: open ntfs inode in which the ntfs attribute resides * @type: attribute type * @name: attribute name in little endian Unicode or AT_UNNAMED or NULL * @name_len: length of attribute @name in Unicode characters (if @name given) * @data_size: if non-NULL then store here the data size * * This function will read the entire content of an ntfs attribute. * If @name is AT_UNNAMED then look specifically for an unnamed attribute. * If @name is NULL then the attribute could be either named or not. * In both those cases @name_len is not used at all. * * On success a buffer is allocated with the content of the attribute * and which needs to be freed when it's not needed anymore. If the * @data_size parameter is non-NULL then the data size is set there. * * On error NULL is returned with errno set to the error code. */ void *ntfs_attr_readall(ntfs_inode *ni, const ATTR_TYPES type, ntfschar *name, u32 name_len, s64 *data_size) { ntfs_attr *na; void *data, *ret = NULL; s64 size; ntfs_log_enter("Entering\n"); na = ntfs_attr_open(ni, type, name, name_len); if (!na) { ntfs_log_perror("ntfs_attr_open failed, inode %lld attr 0x%lx", (long long)ni->mft_no,(long)le32_to_cpu(type)); goto err_exit; } /* * Consistency check : restrict to 65536 bytes. * index bitmaps may need more, but still limited by * the number of clusters. */ if (((u64)na->data_size > 65536) && ((type != AT_BITMAP) || ((u64)na->data_size > (u64)((ni->vol->nr_clusters + 7) >> 3)))) { ntfs_log_error("Corrupt attribute 0x%lx in inode %lld\n", (long)le32_to_cpu(type),(long long)ni->mft_no); errno = EOVERFLOW; goto out; } data = ntfs_malloc(na->data_size); if (!data) goto out; size = ntfs_attr_pread(na, 0, na->data_size, data); if (size != na->data_size) { ntfs_log_perror("ntfs_attr_pread failed"); free(data); goto out; } ret = data; if (data_size) *data_size = size; out: ntfs_attr_close(na); err_exit: ntfs_log_leave("\n"); return ret; } /* * Read some data from a data attribute * * Returns the amount of data read, negative if there was an error */ int ntfs_attr_data_read(ntfs_inode *ni, ntfschar *stream_name, int stream_name_len, char *buf, size_t size, off_t offset) { ntfs_attr *na = NULL; int res, total = 0; na = ntfs_attr_open(ni, AT_DATA, stream_name, stream_name_len); if (!na) { res = -errno; goto exit; } if ((size_t)offset < (size_t)na->data_size) { if (offset + size > (size_t)na->data_size) size = na->data_size - offset; while (size) { res = ntfs_attr_pread(na, offset, size, buf + total); if ((off_t)res < (off_t)size) ntfs_log_perror("ntfs_attr_pread partial read " "(%lld : %lld <> %d)", (long long)offset, (long long)size, res); if (res <= 0) { res = -errno; goto exit; } size -= res; offset += res; total += res; } } res = total; exit: if (na) ntfs_attr_close(na); return res; } /* * Write some data into a data attribute * * Returns the amount of data written, negative if there was an error */ int ntfs_attr_data_write(ntfs_inode *ni, ntfschar *stream_name, int stream_name_len, const char *buf, size_t size, off_t offset) { ntfs_attr *na = NULL; int res, total = 0; na = ntfs_attr_open(ni, AT_DATA, stream_name, stream_name_len); if (!na) { res = -errno; goto exit; } while (size) { res = ntfs_attr_pwrite(na, offset, size, buf + total); if (res < (s64)size) ntfs_log_perror("ntfs_attr_pwrite partial write (%lld: " "%lld <> %d)", (long long)offset, (long long)size, res); if (res <= 0) { res = -errno; goto exit; } size -= res; offset += res; total += res; } res = total; exit: if (na) ntfs_attr_close(na); return res; } /* * Shrink the size of a data attribute if needed * * For non-resident attributes only. * The space remains allocated. * * Returns 0 if successful * -1 if failed, with errno telling why */ int ntfs_attr_shrink_size(ntfs_inode *ni, ntfschar *stream_name, int stream_name_len, off_t offset) { ntfs_attr_search_ctx *ctx; ATTR_RECORD *a; int res; res = -1; ctx = ntfs_attr_get_search_ctx(ni, NULL); if (ctx) { if (!ntfs_attr_lookup(AT_DATA, stream_name, stream_name_len, CASE_SENSITIVE, 0, NULL, 0, ctx)) { a = ctx->attr; if (a->non_resident && (sle64_to_cpu(a->initialized_size) > offset)) { a->initialized_size = cpu_to_sle64(offset); a->data_size = a->initialized_size; } res = 0; } ntfs_attr_put_search_ctx(ctx); } return (res); } int ntfs_attr_exist(ntfs_inode *ni, const ATTR_TYPES type, const ntfschar *name, u32 name_len) { ntfs_attr_search_ctx *ctx; int ret; ntfs_log_trace("Entering\n"); ctx = ntfs_attr_get_search_ctx(ni, NULL); if (!ctx) return 0; ret = ntfs_attr_lookup(type, name, name_len, CASE_SENSITIVE, 0, NULL, 0, ctx); ntfs_attr_put_search_ctx(ctx); return !ret; } int ntfs_attr_remove(ntfs_inode *ni, const ATTR_TYPES type, ntfschar *name, u32 name_len) { ntfs_attr *na; int ret; ntfs_log_trace("Entering\n"); if (!ni) { ntfs_log_error("%s: NULL inode pointer", __FUNCTION__); errno = EINVAL; return -1; } na = ntfs_attr_open(ni, type, name, name_len); if (!na) { /* do not log removal of non-existent stream */ if (type != AT_DATA) { ntfs_log_perror("Failed to open attribute 0x%02x of inode " "0x%llx", le32_to_cpu(type), (unsigned long long)ni->mft_no); } return -1; } ret = ntfs_attr_rm(na); if (ret) ntfs_log_perror("Failed to remove attribute 0x%02x of inode " "0x%llx", le32_to_cpu(type), (unsigned long long)ni->mft_no); ntfs_attr_close(na); return ret; } /* Below macros are 32-bit ready. */ #define BCX(x) ((x) - (((x) >> 1) & 0x77777777) - \ (((x) >> 2) & 0x33333333) - \ (((x) >> 3) & 0x11111111)) #define BITCOUNT(x) (((BCX(x) + (BCX(x) >> 4)) & 0x0F0F0F0F) % 255) static u8 *ntfs_init_lut256(void) { int i; u8 *lut; lut = ntfs_malloc(256); if (lut) for(i = 0; i < 256; i++) *(lut + i) = 8 - BITCOUNT(i); return lut; } s64 ntfs_attr_get_free_bits(ntfs_attr *na) { u8 *buf, *lut; s64 br = 0; s64 total = 0; s64 nr_free = 0; lut = ntfs_init_lut256(); if (!lut) return -1; buf = ntfs_malloc(65536); if (!buf) goto out; while (1) { u32 *p; br = ntfs_attr_pread(na, total, 65536, buf); if (br <= 0) break; total += br; p = (u32 *)buf + br / 4 - 1; for (; (u8 *)p >= buf; p--) { nr_free += lut[ *p & 255] + lut[(*p >> 8) & 255] + lut[(*p >> 16) & 255] + lut[(*p >> 24) ]; } switch (br % 4) { case 3: nr_free += lut[*(buf + br - 3)]; /* FALLTHRU */ case 2: nr_free += lut[*(buf + br - 2)]; /* FALLTHRU */ case 1: nr_free += lut[*(buf + br - 1)]; } } free(buf); out: free(lut); if (!total || br < 0) return -1; return nr_free; } ntfs-3g-2026.2.25/libntfs-3g/Makefile.in0000664000175000017500000021356015152260212013016 # Makefile.in generated by automake 1.17 from Makefile.am. # @configure_input@ # Copyright (C) 1994-2024 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY, to the extent permitted by law; without # even the implied warranty of MERCHANTABILITY or FITNESS FOR A # PARTICULAR PURPOSE. @SET_MAKE@ VPATH = @srcdir@ am__is_gnu_make = { \ if test -z '$(MAKELEVEL)'; then \ false; \ elif test -n '$(MAKE_HOST)'; then \ true; \ elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \ true; \ else \ false; \ fi; \ } am__make_running_with_option = \ case $${target_option-} in \ ?) ;; \ *) echo "am__make_running_with_option: internal error: invalid" \ "target option '$${target_option-}' specified" >&2; \ exit 1;; \ esac; \ has_opt=no; \ sane_makeflags=$$MAKEFLAGS; \ if $(am__is_gnu_make); then \ sane_makeflags=$$MFLAGS; \ else \ case $$MAKEFLAGS in \ *\\[\ \ ]*) \ bs=\\; \ sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \ | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \ esac; \ fi; \ skip_next=no; \ strip_trailopt () \ { \ flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \ }; \ for flg in $$sane_makeflags; do \ test $$skip_next = yes && { skip_next=no; continue; }; \ case $$flg in \ *=*|--*) continue;; \ -*I) strip_trailopt 'I'; skip_next=yes;; \ -*I?*) strip_trailopt 'I';; \ -*O) strip_trailopt 'O'; skip_next=yes;; \ -*O?*) strip_trailopt 'O';; \ -*l) strip_trailopt 'l'; skip_next=yes;; \ -*l?*) strip_trailopt 'l';; \ -[dEDm]) skip_next=yes;; \ -[JT]) skip_next=yes;; \ esac; \ case $$flg in \ *$$target_option*) has_opt=yes; break;; \ esac; \ done; \ test $$has_opt = yes am__make_dryrun = (target_option=n; $(am__make_running_with_option)) am__make_keepgoing = (target_option=k; $(am__make_running_with_option)) am__rm_f = rm -f $(am__rm_f_notfound) am__rm_rf = rm -rf $(am__rm_f_notfound) pkgdatadir = $(datadir)/@PACKAGE@ pkgincludedir = $(includedir)/@PACKAGE@ pkglibdir = $(libdir)/@PACKAGE@ pkglibexecdir = $(libexecdir)/@PACKAGE@ am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd install_sh_DATA = $(install_sh) -c -m 644 install_sh_PROGRAM = $(install_sh) -c install_sh_SCRIPT = $(install_sh) -c INSTALL_HEADER = $(INSTALL_DATA) transform = $(program_transform_name) NORMAL_INSTALL = : PRE_INSTALL = : POST_INSTALL = : NORMAL_UNINSTALL = : PRE_UNINSTALL = : POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ target_triplet = @target@ @NTFS_DEVICE_DEFAULT_IO_OPS_TRUE@@WINDOWS_TRUE@am__append_1 = win32_io.c @NTFS_DEVICE_DEFAULT_IO_OPS_TRUE@@WINDOWS_FALSE@am__append_2 = unix_io.c subdir = libntfs-3g ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \ $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \ $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \ $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) DIST_COMMON = $(srcdir)/Makefile.am $(am__DIST_COMMON) mkinstalldirs = $(install_sh) -d CONFIG_HEADER = $(top_builddir)/config.h CONFIG_CLEAN_FILES = libntfs-3g.pc libntfs-3g.script.so CONFIG_CLEAN_VPATH_FILES = am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; am__vpath_adj = case $$p in \ $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ *) f=$$p;; \ esac; am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`; am__install_max = 40 am__nobase_strip_setup = \ srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'` am__nobase_strip = \ for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||" am__nobase_list = $(am__nobase_strip_setup); \ for p in $$list; do echo "$$p $$p"; done | \ sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \ $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \ if (++n[$$2] == $(am__install_max)) \ { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \ END { for (dir in files) print dir, files[dir] }' am__base_list = \ sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' am__uninstall_files_from_dir = { \ { test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; } \ || { echo " ( cd '$$dir' && rm -f" $$files ")"; \ $(am__cd) "$$dir" && echo $$files | $(am__xargs_n) 40 $(am__rm_f); }; \ } am__installdirs = "$(DESTDIR)$(libdir)" "$(DESTDIR)$(rootlibdir)" \ "$(DESTDIR)$(pkgconfigdir)" LTLIBRARIES = $(lib_LTLIBRARIES) $(noinst_LTLIBRARIES) \ $(rootlib_LTLIBRARIES) am__DEPENDENCIES_1 = libntfs_3g_la_DEPENDENCIES = $(am__DEPENDENCIES_1) am__libntfs_3g_la_SOURCES_DIST = acls.c attrib.c attrlist.c bitmap.c \ bootsect.c cache.c collate.c compat.c compress.c debug.c \ device.c dir.c ea.c efs.c index.c inode.c ioctl.c lcnalloc.c \ logfile.c logging.c mft.c misc.c mst.c object_id.c realpath.c \ reparse.c runlist.c security.c unistr.c volume.c xattrs.c \ win32_io.c unix_io.c @NTFS_DEVICE_DEFAULT_IO_OPS_TRUE@@WINDOWS_TRUE@am__objects_1 = libntfs_3g_la-win32_io.lo @NTFS_DEVICE_DEFAULT_IO_OPS_TRUE@@WINDOWS_FALSE@am__objects_2 = libntfs_3g_la-unix_io.lo am_libntfs_3g_la_OBJECTS = libntfs_3g_la-acls.lo \ libntfs_3g_la-attrib.lo libntfs_3g_la-attrlist.lo \ libntfs_3g_la-bitmap.lo libntfs_3g_la-bootsect.lo \ libntfs_3g_la-cache.lo libntfs_3g_la-collate.lo \ libntfs_3g_la-compat.lo libntfs_3g_la-compress.lo \ libntfs_3g_la-debug.lo libntfs_3g_la-device.lo \ libntfs_3g_la-dir.lo libntfs_3g_la-ea.lo libntfs_3g_la-efs.lo \ libntfs_3g_la-index.lo libntfs_3g_la-inode.lo \ libntfs_3g_la-ioctl.lo libntfs_3g_la-lcnalloc.lo \ libntfs_3g_la-logfile.lo libntfs_3g_la-logging.lo \ libntfs_3g_la-mft.lo libntfs_3g_la-misc.lo \ libntfs_3g_la-mst.lo libntfs_3g_la-object_id.lo \ libntfs_3g_la-realpath.lo libntfs_3g_la-reparse.lo \ libntfs_3g_la-runlist.lo libntfs_3g_la-security.lo \ libntfs_3g_la-unistr.lo libntfs_3g_la-volume.lo \ libntfs_3g_la-xattrs.lo $(am__objects_1) $(am__objects_2) libntfs_3g_la_OBJECTS = $(am_libntfs_3g_la_OBJECTS) AM_V_lt = $(am__v_lt_@AM_V@) am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) am__v_lt_0 = --silent am__v_lt_1 = libntfs_3g_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(libntfs_3g_la_CFLAGS) \ $(CFLAGS) $(libntfs_3g_la_LDFLAGS) $(LDFLAGS) -o $@ @INSTALL_LIBRARY_FALSE@am_libntfs_3g_la_rpath = @INSTALL_LIBRARY_TRUE@am_libntfs_3g_la_rpath = -rpath $(libdir) AM_V_P = $(am__v_P_@AM_V@) am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) am__v_P_0 = false am__v_P_1 = : AM_V_GEN = $(am__v_GEN_@AM_V@) am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@) am__v_GEN_0 = @echo " GEN " $@; am__v_GEN_1 = AM_V_at = $(am__v_at_@AM_V@) am__v_at_ = $(am__v_at_@AM_DEFAULT_V@) am__v_at_0 = @ am__v_at_1 = DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) depcomp = $(SHELL) $(top_srcdir)/depcomp am__maybe_remake_depfiles = depfiles am__depfiles_remade = ./$(DEPDIR)/libntfs_3g_la-acls.Plo \ ./$(DEPDIR)/libntfs_3g_la-attrib.Plo \ ./$(DEPDIR)/libntfs_3g_la-attrlist.Plo \ ./$(DEPDIR)/libntfs_3g_la-bitmap.Plo \ ./$(DEPDIR)/libntfs_3g_la-bootsect.Plo \ ./$(DEPDIR)/libntfs_3g_la-cache.Plo \ ./$(DEPDIR)/libntfs_3g_la-collate.Plo \ ./$(DEPDIR)/libntfs_3g_la-compat.Plo \ ./$(DEPDIR)/libntfs_3g_la-compress.Plo \ ./$(DEPDIR)/libntfs_3g_la-debug.Plo \ ./$(DEPDIR)/libntfs_3g_la-device.Plo \ ./$(DEPDIR)/libntfs_3g_la-dir.Plo \ ./$(DEPDIR)/libntfs_3g_la-ea.Plo \ ./$(DEPDIR)/libntfs_3g_la-efs.Plo \ ./$(DEPDIR)/libntfs_3g_la-index.Plo \ ./$(DEPDIR)/libntfs_3g_la-inode.Plo \ ./$(DEPDIR)/libntfs_3g_la-ioctl.Plo \ ./$(DEPDIR)/libntfs_3g_la-lcnalloc.Plo \ ./$(DEPDIR)/libntfs_3g_la-logfile.Plo \ ./$(DEPDIR)/libntfs_3g_la-logging.Plo \ ./$(DEPDIR)/libntfs_3g_la-mft.Plo \ ./$(DEPDIR)/libntfs_3g_la-misc.Plo \ ./$(DEPDIR)/libntfs_3g_la-mst.Plo \ ./$(DEPDIR)/libntfs_3g_la-object_id.Plo \ ./$(DEPDIR)/libntfs_3g_la-realpath.Plo \ ./$(DEPDIR)/libntfs_3g_la-reparse.Plo \ ./$(DEPDIR)/libntfs_3g_la-runlist.Plo \ ./$(DEPDIR)/libntfs_3g_la-security.Plo \ ./$(DEPDIR)/libntfs_3g_la-unistr.Plo \ ./$(DEPDIR)/libntfs_3g_la-unix_io.Plo \ ./$(DEPDIR)/libntfs_3g_la-volume.Plo \ ./$(DEPDIR)/libntfs_3g_la-win32_io.Plo \ ./$(DEPDIR)/libntfs_3g_la-xattrs.Plo am__mv = mv -f COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \ $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \ $(AM_CFLAGS) $(CFLAGS) AM_V_CC = $(am__v_CC_@AM_V@) am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@) am__v_CC_0 = @echo " CC " $@; am__v_CC_1 = CCLD = $(CC) LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ $(AM_LDFLAGS) $(LDFLAGS) -o $@ AM_V_CCLD = $(am__v_CCLD_@AM_V@) am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@) am__v_CCLD_0 = @echo " CCLD " $@; am__v_CCLD_1 = SOURCES = $(libntfs_3g_la_SOURCES) DIST_SOURCES = $(am__libntfs_3g_la_SOURCES_DIST) am__can_run_installinfo = \ case $$AM_UPDATE_INFO_DIR in \ n|no|NO) false;; \ *) (install-info --version) >/dev/null 2>&1;; \ esac DATA = $(pkgconfig_DATA) am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) # Read a list of newline-separated strings from the standard input, # and print each of them once, without duplicates. Input order is # *not* preserved. am__uniquify_input = $(AWK) '\ BEGIN { nonempty = 0; } \ { items[$$0] = 1; nonempty = 1; } \ END { if (nonempty) { for (i in items) print i; }; } \ ' # Make sure the list of sources is unique. This is necessary because, # e.g., the same source file might be shared among _SOURCES variables # for different programs/libraries. am__define_uniq_tagged_files = \ list='$(am__tagged_files)'; \ unique=`for i in $$list; do \ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ done | $(am__uniquify_input)` am__DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/libntfs-3g.pc.in \ $(srcdir)/libntfs-3g.script.so.in $(top_srcdir)/depcomp DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) ACLOCAL = @ACLOCAL@ AMTAR = @AMTAR@ AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ AR = @AR@ AUTOCONF = @AUTOCONF@ AUTOHEADER = @AUTOHEADER@ AUTOMAKE = @AUTOMAKE@ AWK = @AWK@ CC = @CC@ CCDEPMODE = @CCDEPMODE@ CFLAGS = @CFLAGS@ CPPFLAGS = @CPPFLAGS@ CSCOPE = @CSCOPE@ CTAGS = @CTAGS@ CYGPATH_W = @CYGPATH_W@ DEFS = @DEFS@ DEPDIR = @DEPDIR@ DLLTOOL = @DLLTOOL@ DSYMUTIL = @DSYMUTIL@ DUMPBIN = @DUMPBIN@ ECHO_C = @ECHO_C@ ECHO_N = @ECHO_N@ ECHO_T = @ECHO_T@ EGREP = @EGREP@ ETAGS = @ETAGS@ EXEEXT = @EXEEXT@ FGREP = @FGREP@ FILECMD = @FILECMD@ FUSE_MODULE_CFLAGS = @FUSE_MODULE_CFLAGS@ FUSE_MODULE_LIBS = @FUSE_MODULE_LIBS@ GNUTLS_CFLAGS = @GNUTLS_CFLAGS@ GNUTLS_LIBS = @GNUTLS_LIBS@ GPGRT_CONFIG = @GPGRT_CONFIG@ GREP = @GREP@ INSTALL = @INSTALL@ INSTALL_DATA = @INSTALL_DATA@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ INSTALL_SCRIPT = @INSTALL_SCRIPT@ INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ LD = @LD@ LDCONFIG = @LDCONFIG@ LDFLAGS = @LDFLAGS@ LIBDL = @LIBDL@ LIBFUSE_LITE_CFLAGS = @LIBFUSE_LITE_CFLAGS@ LIBFUSE_LITE_LIBS = @LIBFUSE_LITE_LIBS@ LIBGCRYPT_CFLAGS = @LIBGCRYPT_CFLAGS@ LIBGCRYPT_CONFIG = @LIBGCRYPT_CONFIG@ LIBGCRYPT_LIBS = @LIBGCRYPT_LIBS@ LIBNTFS_3G_VERSION = @LIBNTFS_3G_VERSION@ LIBNTFS_CPPFLAGS = @LIBNTFS_CPPFLAGS@ LIBNTFS_LIBS = @LIBNTFS_LIBS@ LIBOBJS = @LIBOBJS@ LIBS = @LIBS@ LIBTOOL = @LIBTOOL@ LIPO = @LIPO@ LN_S = @LN_S@ LTLIBOBJS = @LTLIBOBJS@ LT_SYS_LIBRARY_PATH = @LT_SYS_LIBRARY_PATH@ MAINT = @MAINT@ MAKEINFO = @MAKEINFO@ MANIFEST_TOOL = @MANIFEST_TOOL@ MKDIR_P = @MKDIR_P@ MKNTFS_CPPFLAGS = @MKNTFS_CPPFLAGS@ MKNTFS_LIBS = @MKNTFS_LIBS@ MV = @MV@ NM = @NM@ NMEDIT = @NMEDIT@ NTFSPROGS_STATIC_LIBS = @NTFSPROGS_STATIC_LIBS@ OBJDUMP = @OBJDUMP@ OBJEXT = @OBJEXT@ OTOOL = @OTOOL@ OTOOL64 = @OTOOL64@ OUTPUT_FORMAT = @OUTPUT_FORMAT@ PACKAGE = @PACKAGE@ PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ PACKAGE_NAME = @PACKAGE_NAME@ PACKAGE_STRING = @PACKAGE_STRING@ PACKAGE_TARNAME = @PACKAGE_TARNAME@ PACKAGE_URL = @PACKAGE_URL@ PACKAGE_VERSION = @PACKAGE_VERSION@ PATH_SEPARATOR = @PATH_SEPARATOR@ PKG_CONFIG = @PKG_CONFIG@ PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ RANLIB = @RANLIB@ RM = @RM@ SED = @SED@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ STRIP = @STRIP@ VERSION = @VERSION@ abs_builddir = @abs_builddir@ abs_srcdir = @abs_srcdir@ abs_top_builddir = @abs_top_builddir@ abs_top_srcdir = @abs_top_srcdir@ ac_ct_AR = @ac_ct_AR@ ac_ct_CC = @ac_ct_CC@ ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ all_includes = @all_includes@ all_libraries = @all_libraries@ am__include = @am__include@ am__leading_dot = @am__leading_dot@ am__quote = @am__quote@ am__rm_f_notfound = @am__rm_f_notfound@ am__tar = @am__tar@ am__untar = @am__untar@ am__xargs_n = @am__xargs_n@ bindir = @bindir@ build = @build@ build_alias = @build_alias@ build_cpu = @build_cpu@ build_os = @build_os@ build_vendor = @build_vendor@ builddir = @builddir@ datadir = @datadir@ datarootdir = @datarootdir@ docdir = @docdir@ dvidir = @dvidir@ exec_prefix = @exec_prefix@ host = @host@ host_alias = @host_alias@ host_cpu = @host_cpu@ host_os = @host_os@ host_vendor = @host_vendor@ htmldir = @htmldir@ includedir = @includedir@ infodir = @infodir@ install_sh = @install_sh@ libdir = @libdir@ libexecdir = @libexecdir@ localedir = @localedir@ localstatedir = @localstatedir@ mandir = @mandir@ mkdir_p = @mkdir_p@ ntfs3gincludedir = @ntfs3gincludedir@ oldincludedir = @oldincludedir@ pdfdir = @pdfdir@ pkgconfigdir = @pkgconfigdir@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ rootbindir = @rootbindir@ rootlibdir = @rootlibdir@ rootsbindir = @rootsbindir@ runstatedir = @runstatedir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ sysconfdir = @sysconfdir@ target = @target@ target_alias = @target_alias@ target_cpu = @target_cpu@ target_os = @target_os@ target_vendor = @target_vendor@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ MAINTAINERCLEANFILES = $(srcdir)/Makefile.in @INSTALL_LIBRARY_TRUE@rootlib_LTLIBRARIES = #Create directory @INSTALL_LIBRARY_TRUE@lib_LTLIBRARIES = libntfs-3g.la @INSTALL_LIBRARY_TRUE@pkgconfig_DATA = libntfs-3g.pc @INSTALL_LIBRARY_FALSE@noinst_LTLIBRARIES = libntfs-3g.la libntfs_3g_la_CFLAGS = $(AM_CFLAGS) libntfs_3g_la_CPPFLAGS = $(AM_CPPFLAGS) $(LIBNTFS_CPPFLAGS) -I$(top_srcdir)/include/ntfs-3g libntfs_3g_la_LIBADD = $(LIBNTFS_LIBS) libntfs_3g_la_LDFLAGS = -version-info $(LIBNTFS_3G_VERSION) -no-undefined libntfs_3g_la_SOURCES = acls.c attrib.c attrlist.c bitmap.c bootsect.c \ cache.c collate.c compat.c compress.c debug.c device.c dir.c \ ea.c efs.c index.c inode.c ioctl.c lcnalloc.c logfile.c \ logging.c mft.c misc.c mst.c object_id.c realpath.c reparse.c \ runlist.c security.c unistr.c volume.c xattrs.c \ $(am__append_1) $(am__append_2) all: all-am .SUFFIXES: .SUFFIXES: .c .lo .o .obj $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) @for dep in $?; do \ case '$(am__configure_deps)' in \ *$$dep*) \ ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ && { if test -f $@; then exit 0; else break; fi; }; \ exit 1;; \ esac; \ done; \ echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu libntfs-3g/Makefile'; \ $(am__cd) $(top_srcdir) && \ $(AUTOMAKE) --gnu libntfs-3g/Makefile Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status @case '$?' in \ *config.status*) \ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ *) \ echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles)'; \ cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles);; \ esac; $(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh $(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh $(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh $(am__aclocal_m4_deps): libntfs-3g.pc: $(top_builddir)/config.status $(srcdir)/libntfs-3g.pc.in cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ libntfs-3g.script.so: $(top_builddir)/config.status $(srcdir)/libntfs-3g.script.so.in cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ install-libLTLIBRARIES: $(lib_LTLIBRARIES) @$(NORMAL_INSTALL) @list='$(lib_LTLIBRARIES)'; test -n "$(libdir)" || list=; \ list2=; for p in $$list; do \ if test -f $$p; then \ list2="$$list2 $$p"; \ else :; fi; \ done; \ test -z "$$list2" || { \ echo " $(MKDIR_P) '$(DESTDIR)$(libdir)'"; \ $(MKDIR_P) "$(DESTDIR)$(libdir)" || exit 1; \ echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 '$(DESTDIR)$(libdir)'"; \ $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(libdir)"; \ } uninstall-libLTLIBRARIES: @$(NORMAL_UNINSTALL) @list='$(lib_LTLIBRARIES)'; test -n "$(libdir)" || list=; \ for p in $$list; do \ $(am__strip_dir) \ echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f '$(DESTDIR)$(libdir)/$$f'"; \ $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f "$(DESTDIR)$(libdir)/$$f"; \ done clean-libLTLIBRARIES: -$(am__rm_f) $(lib_LTLIBRARIES) @list='$(lib_LTLIBRARIES)'; \ locs=`for p in $$list; do echo $$p; done | \ sed 's|^[^/]*$$|.|; s|/[^/]*$$||; s|$$|/so_locations|' | \ sort -u`; \ echo rm -f $${locs}; \ $(am__rm_f) $${locs} clean-noinstLTLIBRARIES: -$(am__rm_f) $(noinst_LTLIBRARIES) @list='$(noinst_LTLIBRARIES)'; \ locs=`for p in $$list; do echo $$p; done | \ sed 's|^[^/]*$$|.|; s|/[^/]*$$||; s|$$|/so_locations|' | \ sort -u`; \ echo rm -f $${locs}; \ $(am__rm_f) $${locs} install-rootlibLTLIBRARIES: $(rootlib_LTLIBRARIES) @$(NORMAL_INSTALL) @list='$(rootlib_LTLIBRARIES)'; test -n "$(rootlibdir)" || list=; \ list2=; for p in $$list; do \ if test -f $$p; then \ list2="$$list2 $$p"; \ else :; fi; \ done; \ test -z "$$list2" || { \ echo " $(MKDIR_P) '$(DESTDIR)$(rootlibdir)'"; \ $(MKDIR_P) "$(DESTDIR)$(rootlibdir)" || exit 1; \ echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 '$(DESTDIR)$(rootlibdir)'"; \ $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(rootlibdir)"; \ } uninstall-rootlibLTLIBRARIES: @$(NORMAL_UNINSTALL) @list='$(rootlib_LTLIBRARIES)'; test -n "$(rootlibdir)" || list=; \ for p in $$list; do \ $(am__strip_dir) \ echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f '$(DESTDIR)$(rootlibdir)/$$f'"; \ $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f "$(DESTDIR)$(rootlibdir)/$$f"; \ done clean-rootlibLTLIBRARIES: -$(am__rm_f) $(rootlib_LTLIBRARIES) @list='$(rootlib_LTLIBRARIES)'; \ locs=`for p in $$list; do echo $$p; done | \ sed 's|^[^/]*$$|.|; s|/[^/]*$$||; s|$$|/so_locations|' | \ sort -u`; \ echo rm -f $${locs}; \ $(am__rm_f) $${locs} libntfs-3g.la: $(libntfs_3g_la_OBJECTS) $(libntfs_3g_la_DEPENDENCIES) $(EXTRA_libntfs_3g_la_DEPENDENCIES) $(AM_V_CCLD)$(libntfs_3g_la_LINK) $(am_libntfs_3g_la_rpath) $(libntfs_3g_la_OBJECTS) $(libntfs_3g_la_LIBADD) $(LIBS) mostlyclean-compile: -rm -f *.$(OBJEXT) distclean-compile: -rm -f *.tab.c @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libntfs_3g_la-acls.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libntfs_3g_la-attrib.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libntfs_3g_la-attrlist.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libntfs_3g_la-bitmap.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libntfs_3g_la-bootsect.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libntfs_3g_la-cache.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libntfs_3g_la-collate.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libntfs_3g_la-compat.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libntfs_3g_la-compress.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libntfs_3g_la-debug.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libntfs_3g_la-device.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libntfs_3g_la-dir.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libntfs_3g_la-ea.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libntfs_3g_la-efs.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libntfs_3g_la-index.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libntfs_3g_la-inode.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libntfs_3g_la-ioctl.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libntfs_3g_la-lcnalloc.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libntfs_3g_la-logfile.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libntfs_3g_la-logging.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libntfs_3g_la-mft.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libntfs_3g_la-misc.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libntfs_3g_la-mst.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libntfs_3g_la-object_id.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libntfs_3g_la-realpath.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libntfs_3g_la-reparse.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libntfs_3g_la-runlist.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libntfs_3g_la-security.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libntfs_3g_la-unistr.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libntfs_3g_la-unix_io.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libntfs_3g_la-volume.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libntfs_3g_la-win32_io.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libntfs_3g_la-xattrs.Plo@am__quote@ # am--include-marker $(am__depfiles_remade): @$(MKDIR_P) $(@D) @: >>$@ am--depfiles: $(am__depfiles_remade) .c.o: @am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ $< .c.obj: @am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'` .c.lo: @am__fastdepCC_TRUE@ $(AM_V_CC)$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $< libntfs_3g_la-acls.lo: acls.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libntfs_3g_la_CPPFLAGS) $(CPPFLAGS) $(libntfs_3g_la_CFLAGS) $(CFLAGS) -MT libntfs_3g_la-acls.lo -MD -MP -MF $(DEPDIR)/libntfs_3g_la-acls.Tpo -c -o libntfs_3g_la-acls.lo `test -f 'acls.c' || echo '$(srcdir)/'`acls.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libntfs_3g_la-acls.Tpo $(DEPDIR)/libntfs_3g_la-acls.Plo @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='acls.c' object='libntfs_3g_la-acls.lo' libtool=yes @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libntfs_3g_la_CPPFLAGS) $(CPPFLAGS) $(libntfs_3g_la_CFLAGS) $(CFLAGS) -c -o libntfs_3g_la-acls.lo `test -f 'acls.c' || echo '$(srcdir)/'`acls.c libntfs_3g_la-attrib.lo: attrib.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libntfs_3g_la_CPPFLAGS) $(CPPFLAGS) $(libntfs_3g_la_CFLAGS) $(CFLAGS) -MT libntfs_3g_la-attrib.lo -MD -MP -MF $(DEPDIR)/libntfs_3g_la-attrib.Tpo -c -o libntfs_3g_la-attrib.lo `test -f 'attrib.c' || echo '$(srcdir)/'`attrib.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libntfs_3g_la-attrib.Tpo $(DEPDIR)/libntfs_3g_la-attrib.Plo @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='attrib.c' object='libntfs_3g_la-attrib.lo' libtool=yes @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libntfs_3g_la_CPPFLAGS) $(CPPFLAGS) $(libntfs_3g_la_CFLAGS) $(CFLAGS) -c -o libntfs_3g_la-attrib.lo `test -f 'attrib.c' || echo '$(srcdir)/'`attrib.c libntfs_3g_la-attrlist.lo: attrlist.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libntfs_3g_la_CPPFLAGS) $(CPPFLAGS) $(libntfs_3g_la_CFLAGS) $(CFLAGS) -MT libntfs_3g_la-attrlist.lo -MD -MP -MF $(DEPDIR)/libntfs_3g_la-attrlist.Tpo -c -o libntfs_3g_la-attrlist.lo `test -f 'attrlist.c' || echo '$(srcdir)/'`attrlist.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libntfs_3g_la-attrlist.Tpo $(DEPDIR)/libntfs_3g_la-attrlist.Plo @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='attrlist.c' object='libntfs_3g_la-attrlist.lo' libtool=yes @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libntfs_3g_la_CPPFLAGS) $(CPPFLAGS) $(libntfs_3g_la_CFLAGS) $(CFLAGS) -c -o libntfs_3g_la-attrlist.lo `test -f 'attrlist.c' || echo '$(srcdir)/'`attrlist.c libntfs_3g_la-bitmap.lo: bitmap.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libntfs_3g_la_CPPFLAGS) $(CPPFLAGS) $(libntfs_3g_la_CFLAGS) $(CFLAGS) -MT libntfs_3g_la-bitmap.lo -MD -MP -MF $(DEPDIR)/libntfs_3g_la-bitmap.Tpo -c -o libntfs_3g_la-bitmap.lo `test -f 'bitmap.c' || echo '$(srcdir)/'`bitmap.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libntfs_3g_la-bitmap.Tpo $(DEPDIR)/libntfs_3g_la-bitmap.Plo @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='bitmap.c' object='libntfs_3g_la-bitmap.lo' libtool=yes @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libntfs_3g_la_CPPFLAGS) $(CPPFLAGS) $(libntfs_3g_la_CFLAGS) $(CFLAGS) -c -o libntfs_3g_la-bitmap.lo `test -f 'bitmap.c' || echo '$(srcdir)/'`bitmap.c libntfs_3g_la-bootsect.lo: bootsect.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libntfs_3g_la_CPPFLAGS) $(CPPFLAGS) $(libntfs_3g_la_CFLAGS) $(CFLAGS) -MT libntfs_3g_la-bootsect.lo -MD -MP -MF $(DEPDIR)/libntfs_3g_la-bootsect.Tpo -c -o libntfs_3g_la-bootsect.lo `test -f 'bootsect.c' || echo '$(srcdir)/'`bootsect.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libntfs_3g_la-bootsect.Tpo $(DEPDIR)/libntfs_3g_la-bootsect.Plo @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='bootsect.c' object='libntfs_3g_la-bootsect.lo' libtool=yes @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libntfs_3g_la_CPPFLAGS) $(CPPFLAGS) $(libntfs_3g_la_CFLAGS) $(CFLAGS) -c -o libntfs_3g_la-bootsect.lo `test -f 'bootsect.c' || echo '$(srcdir)/'`bootsect.c libntfs_3g_la-cache.lo: cache.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libntfs_3g_la_CPPFLAGS) $(CPPFLAGS) $(libntfs_3g_la_CFLAGS) $(CFLAGS) -MT libntfs_3g_la-cache.lo -MD -MP -MF $(DEPDIR)/libntfs_3g_la-cache.Tpo -c -o libntfs_3g_la-cache.lo `test -f 'cache.c' || echo '$(srcdir)/'`cache.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libntfs_3g_la-cache.Tpo $(DEPDIR)/libntfs_3g_la-cache.Plo @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='cache.c' object='libntfs_3g_la-cache.lo' libtool=yes @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libntfs_3g_la_CPPFLAGS) $(CPPFLAGS) $(libntfs_3g_la_CFLAGS) $(CFLAGS) -c -o libntfs_3g_la-cache.lo `test -f 'cache.c' || echo '$(srcdir)/'`cache.c libntfs_3g_la-collate.lo: collate.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libntfs_3g_la_CPPFLAGS) $(CPPFLAGS) $(libntfs_3g_la_CFLAGS) $(CFLAGS) -MT libntfs_3g_la-collate.lo -MD -MP -MF $(DEPDIR)/libntfs_3g_la-collate.Tpo -c -o libntfs_3g_la-collate.lo `test -f 'collate.c' || echo '$(srcdir)/'`collate.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libntfs_3g_la-collate.Tpo $(DEPDIR)/libntfs_3g_la-collate.Plo @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='collate.c' object='libntfs_3g_la-collate.lo' libtool=yes @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libntfs_3g_la_CPPFLAGS) $(CPPFLAGS) $(libntfs_3g_la_CFLAGS) $(CFLAGS) -c -o libntfs_3g_la-collate.lo `test -f 'collate.c' || echo '$(srcdir)/'`collate.c libntfs_3g_la-compat.lo: compat.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libntfs_3g_la_CPPFLAGS) $(CPPFLAGS) $(libntfs_3g_la_CFLAGS) $(CFLAGS) -MT libntfs_3g_la-compat.lo -MD -MP -MF $(DEPDIR)/libntfs_3g_la-compat.Tpo -c -o libntfs_3g_la-compat.lo `test -f 'compat.c' || echo '$(srcdir)/'`compat.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libntfs_3g_la-compat.Tpo $(DEPDIR)/libntfs_3g_la-compat.Plo @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='compat.c' object='libntfs_3g_la-compat.lo' libtool=yes @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libntfs_3g_la_CPPFLAGS) $(CPPFLAGS) $(libntfs_3g_la_CFLAGS) $(CFLAGS) -c -o libntfs_3g_la-compat.lo `test -f 'compat.c' || echo '$(srcdir)/'`compat.c libntfs_3g_la-compress.lo: compress.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libntfs_3g_la_CPPFLAGS) $(CPPFLAGS) $(libntfs_3g_la_CFLAGS) $(CFLAGS) -MT libntfs_3g_la-compress.lo -MD -MP -MF $(DEPDIR)/libntfs_3g_la-compress.Tpo -c -o libntfs_3g_la-compress.lo `test -f 'compress.c' || echo '$(srcdir)/'`compress.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libntfs_3g_la-compress.Tpo $(DEPDIR)/libntfs_3g_la-compress.Plo @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='compress.c' object='libntfs_3g_la-compress.lo' libtool=yes @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libntfs_3g_la_CPPFLAGS) $(CPPFLAGS) $(libntfs_3g_la_CFLAGS) $(CFLAGS) -c -o libntfs_3g_la-compress.lo `test -f 'compress.c' || echo '$(srcdir)/'`compress.c libntfs_3g_la-debug.lo: debug.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libntfs_3g_la_CPPFLAGS) $(CPPFLAGS) $(libntfs_3g_la_CFLAGS) $(CFLAGS) -MT libntfs_3g_la-debug.lo -MD -MP -MF $(DEPDIR)/libntfs_3g_la-debug.Tpo -c -o libntfs_3g_la-debug.lo `test -f 'debug.c' || echo '$(srcdir)/'`debug.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libntfs_3g_la-debug.Tpo $(DEPDIR)/libntfs_3g_la-debug.Plo @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='debug.c' object='libntfs_3g_la-debug.lo' libtool=yes @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libntfs_3g_la_CPPFLAGS) $(CPPFLAGS) $(libntfs_3g_la_CFLAGS) $(CFLAGS) -c -o libntfs_3g_la-debug.lo `test -f 'debug.c' || echo '$(srcdir)/'`debug.c libntfs_3g_la-device.lo: device.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libntfs_3g_la_CPPFLAGS) $(CPPFLAGS) $(libntfs_3g_la_CFLAGS) $(CFLAGS) -MT libntfs_3g_la-device.lo -MD -MP -MF $(DEPDIR)/libntfs_3g_la-device.Tpo -c -o libntfs_3g_la-device.lo `test -f 'device.c' || echo '$(srcdir)/'`device.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libntfs_3g_la-device.Tpo $(DEPDIR)/libntfs_3g_la-device.Plo @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='device.c' object='libntfs_3g_la-device.lo' libtool=yes @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libntfs_3g_la_CPPFLAGS) $(CPPFLAGS) $(libntfs_3g_la_CFLAGS) $(CFLAGS) -c -o libntfs_3g_la-device.lo `test -f 'device.c' || echo '$(srcdir)/'`device.c libntfs_3g_la-dir.lo: dir.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libntfs_3g_la_CPPFLAGS) $(CPPFLAGS) $(libntfs_3g_la_CFLAGS) $(CFLAGS) -MT libntfs_3g_la-dir.lo -MD -MP -MF $(DEPDIR)/libntfs_3g_la-dir.Tpo -c -o libntfs_3g_la-dir.lo `test -f 'dir.c' || echo '$(srcdir)/'`dir.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libntfs_3g_la-dir.Tpo $(DEPDIR)/libntfs_3g_la-dir.Plo @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='dir.c' object='libntfs_3g_la-dir.lo' libtool=yes @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libntfs_3g_la_CPPFLAGS) $(CPPFLAGS) $(libntfs_3g_la_CFLAGS) $(CFLAGS) -c -o libntfs_3g_la-dir.lo `test -f 'dir.c' || echo '$(srcdir)/'`dir.c libntfs_3g_la-ea.lo: ea.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libntfs_3g_la_CPPFLAGS) $(CPPFLAGS) $(libntfs_3g_la_CFLAGS) $(CFLAGS) -MT libntfs_3g_la-ea.lo -MD -MP -MF $(DEPDIR)/libntfs_3g_la-ea.Tpo -c -o libntfs_3g_la-ea.lo `test -f 'ea.c' || echo '$(srcdir)/'`ea.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libntfs_3g_la-ea.Tpo $(DEPDIR)/libntfs_3g_la-ea.Plo @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='ea.c' object='libntfs_3g_la-ea.lo' libtool=yes @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libntfs_3g_la_CPPFLAGS) $(CPPFLAGS) $(libntfs_3g_la_CFLAGS) $(CFLAGS) -c -o libntfs_3g_la-ea.lo `test -f 'ea.c' || echo '$(srcdir)/'`ea.c libntfs_3g_la-efs.lo: efs.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libntfs_3g_la_CPPFLAGS) $(CPPFLAGS) $(libntfs_3g_la_CFLAGS) $(CFLAGS) -MT libntfs_3g_la-efs.lo -MD -MP -MF $(DEPDIR)/libntfs_3g_la-efs.Tpo -c -o libntfs_3g_la-efs.lo `test -f 'efs.c' || echo '$(srcdir)/'`efs.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libntfs_3g_la-efs.Tpo $(DEPDIR)/libntfs_3g_la-efs.Plo @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='efs.c' object='libntfs_3g_la-efs.lo' libtool=yes @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libntfs_3g_la_CPPFLAGS) $(CPPFLAGS) $(libntfs_3g_la_CFLAGS) $(CFLAGS) -c -o libntfs_3g_la-efs.lo `test -f 'efs.c' || echo '$(srcdir)/'`efs.c libntfs_3g_la-index.lo: index.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libntfs_3g_la_CPPFLAGS) $(CPPFLAGS) $(libntfs_3g_la_CFLAGS) $(CFLAGS) -MT libntfs_3g_la-index.lo -MD -MP -MF $(DEPDIR)/libntfs_3g_la-index.Tpo -c -o libntfs_3g_la-index.lo `test -f 'index.c' || echo '$(srcdir)/'`index.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libntfs_3g_la-index.Tpo $(DEPDIR)/libntfs_3g_la-index.Plo @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='index.c' object='libntfs_3g_la-index.lo' libtool=yes @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libntfs_3g_la_CPPFLAGS) $(CPPFLAGS) $(libntfs_3g_la_CFLAGS) $(CFLAGS) -c -o libntfs_3g_la-index.lo `test -f 'index.c' || echo '$(srcdir)/'`index.c libntfs_3g_la-inode.lo: inode.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libntfs_3g_la_CPPFLAGS) $(CPPFLAGS) $(libntfs_3g_la_CFLAGS) $(CFLAGS) -MT libntfs_3g_la-inode.lo -MD -MP -MF $(DEPDIR)/libntfs_3g_la-inode.Tpo -c -o libntfs_3g_la-inode.lo `test -f 'inode.c' || echo '$(srcdir)/'`inode.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libntfs_3g_la-inode.Tpo $(DEPDIR)/libntfs_3g_la-inode.Plo @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='inode.c' object='libntfs_3g_la-inode.lo' libtool=yes @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libntfs_3g_la_CPPFLAGS) $(CPPFLAGS) $(libntfs_3g_la_CFLAGS) $(CFLAGS) -c -o libntfs_3g_la-inode.lo `test -f 'inode.c' || echo '$(srcdir)/'`inode.c libntfs_3g_la-ioctl.lo: ioctl.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libntfs_3g_la_CPPFLAGS) $(CPPFLAGS) $(libntfs_3g_la_CFLAGS) $(CFLAGS) -MT libntfs_3g_la-ioctl.lo -MD -MP -MF $(DEPDIR)/libntfs_3g_la-ioctl.Tpo -c -o libntfs_3g_la-ioctl.lo `test -f 'ioctl.c' || echo '$(srcdir)/'`ioctl.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libntfs_3g_la-ioctl.Tpo $(DEPDIR)/libntfs_3g_la-ioctl.Plo @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='ioctl.c' object='libntfs_3g_la-ioctl.lo' libtool=yes @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libntfs_3g_la_CPPFLAGS) $(CPPFLAGS) $(libntfs_3g_la_CFLAGS) $(CFLAGS) -c -o libntfs_3g_la-ioctl.lo `test -f 'ioctl.c' || echo '$(srcdir)/'`ioctl.c libntfs_3g_la-lcnalloc.lo: lcnalloc.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libntfs_3g_la_CPPFLAGS) $(CPPFLAGS) $(libntfs_3g_la_CFLAGS) $(CFLAGS) -MT libntfs_3g_la-lcnalloc.lo -MD -MP -MF $(DEPDIR)/libntfs_3g_la-lcnalloc.Tpo -c -o libntfs_3g_la-lcnalloc.lo `test -f 'lcnalloc.c' || echo '$(srcdir)/'`lcnalloc.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libntfs_3g_la-lcnalloc.Tpo $(DEPDIR)/libntfs_3g_la-lcnalloc.Plo @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='lcnalloc.c' object='libntfs_3g_la-lcnalloc.lo' libtool=yes @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libntfs_3g_la_CPPFLAGS) $(CPPFLAGS) $(libntfs_3g_la_CFLAGS) $(CFLAGS) -c -o libntfs_3g_la-lcnalloc.lo `test -f 'lcnalloc.c' || echo '$(srcdir)/'`lcnalloc.c libntfs_3g_la-logfile.lo: logfile.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libntfs_3g_la_CPPFLAGS) $(CPPFLAGS) $(libntfs_3g_la_CFLAGS) $(CFLAGS) -MT libntfs_3g_la-logfile.lo -MD -MP -MF $(DEPDIR)/libntfs_3g_la-logfile.Tpo -c -o libntfs_3g_la-logfile.lo `test -f 'logfile.c' || echo '$(srcdir)/'`logfile.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libntfs_3g_la-logfile.Tpo $(DEPDIR)/libntfs_3g_la-logfile.Plo @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='logfile.c' object='libntfs_3g_la-logfile.lo' libtool=yes @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libntfs_3g_la_CPPFLAGS) $(CPPFLAGS) $(libntfs_3g_la_CFLAGS) $(CFLAGS) -c -o libntfs_3g_la-logfile.lo `test -f 'logfile.c' || echo '$(srcdir)/'`logfile.c libntfs_3g_la-logging.lo: logging.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libntfs_3g_la_CPPFLAGS) $(CPPFLAGS) $(libntfs_3g_la_CFLAGS) $(CFLAGS) -MT libntfs_3g_la-logging.lo -MD -MP -MF $(DEPDIR)/libntfs_3g_la-logging.Tpo -c -o libntfs_3g_la-logging.lo `test -f 'logging.c' || echo '$(srcdir)/'`logging.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libntfs_3g_la-logging.Tpo $(DEPDIR)/libntfs_3g_la-logging.Plo @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='logging.c' object='libntfs_3g_la-logging.lo' libtool=yes @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libntfs_3g_la_CPPFLAGS) $(CPPFLAGS) $(libntfs_3g_la_CFLAGS) $(CFLAGS) -c -o libntfs_3g_la-logging.lo `test -f 'logging.c' || echo '$(srcdir)/'`logging.c libntfs_3g_la-mft.lo: mft.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libntfs_3g_la_CPPFLAGS) $(CPPFLAGS) $(libntfs_3g_la_CFLAGS) $(CFLAGS) -MT libntfs_3g_la-mft.lo -MD -MP -MF $(DEPDIR)/libntfs_3g_la-mft.Tpo -c -o libntfs_3g_la-mft.lo `test -f 'mft.c' || echo '$(srcdir)/'`mft.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libntfs_3g_la-mft.Tpo $(DEPDIR)/libntfs_3g_la-mft.Plo @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='mft.c' object='libntfs_3g_la-mft.lo' libtool=yes @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libntfs_3g_la_CPPFLAGS) $(CPPFLAGS) $(libntfs_3g_la_CFLAGS) $(CFLAGS) -c -o libntfs_3g_la-mft.lo `test -f 'mft.c' || echo '$(srcdir)/'`mft.c libntfs_3g_la-misc.lo: misc.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libntfs_3g_la_CPPFLAGS) $(CPPFLAGS) $(libntfs_3g_la_CFLAGS) $(CFLAGS) -MT libntfs_3g_la-misc.lo -MD -MP -MF $(DEPDIR)/libntfs_3g_la-misc.Tpo -c -o libntfs_3g_la-misc.lo `test -f 'misc.c' || echo '$(srcdir)/'`misc.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libntfs_3g_la-misc.Tpo $(DEPDIR)/libntfs_3g_la-misc.Plo @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='misc.c' object='libntfs_3g_la-misc.lo' libtool=yes @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libntfs_3g_la_CPPFLAGS) $(CPPFLAGS) $(libntfs_3g_la_CFLAGS) $(CFLAGS) -c -o libntfs_3g_la-misc.lo `test -f 'misc.c' || echo '$(srcdir)/'`misc.c libntfs_3g_la-mst.lo: mst.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libntfs_3g_la_CPPFLAGS) $(CPPFLAGS) $(libntfs_3g_la_CFLAGS) $(CFLAGS) -MT libntfs_3g_la-mst.lo -MD -MP -MF $(DEPDIR)/libntfs_3g_la-mst.Tpo -c -o libntfs_3g_la-mst.lo `test -f 'mst.c' || echo '$(srcdir)/'`mst.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libntfs_3g_la-mst.Tpo $(DEPDIR)/libntfs_3g_la-mst.Plo @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='mst.c' object='libntfs_3g_la-mst.lo' libtool=yes @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libntfs_3g_la_CPPFLAGS) $(CPPFLAGS) $(libntfs_3g_la_CFLAGS) $(CFLAGS) -c -o libntfs_3g_la-mst.lo `test -f 'mst.c' || echo '$(srcdir)/'`mst.c libntfs_3g_la-object_id.lo: object_id.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libntfs_3g_la_CPPFLAGS) $(CPPFLAGS) $(libntfs_3g_la_CFLAGS) $(CFLAGS) -MT libntfs_3g_la-object_id.lo -MD -MP -MF $(DEPDIR)/libntfs_3g_la-object_id.Tpo -c -o libntfs_3g_la-object_id.lo `test -f 'object_id.c' || echo '$(srcdir)/'`object_id.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libntfs_3g_la-object_id.Tpo $(DEPDIR)/libntfs_3g_la-object_id.Plo @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='object_id.c' object='libntfs_3g_la-object_id.lo' libtool=yes @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libntfs_3g_la_CPPFLAGS) $(CPPFLAGS) $(libntfs_3g_la_CFLAGS) $(CFLAGS) -c -o libntfs_3g_la-object_id.lo `test -f 'object_id.c' || echo '$(srcdir)/'`object_id.c libntfs_3g_la-realpath.lo: realpath.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libntfs_3g_la_CPPFLAGS) $(CPPFLAGS) $(libntfs_3g_la_CFLAGS) $(CFLAGS) -MT libntfs_3g_la-realpath.lo -MD -MP -MF $(DEPDIR)/libntfs_3g_la-realpath.Tpo -c -o libntfs_3g_la-realpath.lo `test -f 'realpath.c' || echo '$(srcdir)/'`realpath.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libntfs_3g_la-realpath.Tpo $(DEPDIR)/libntfs_3g_la-realpath.Plo @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='realpath.c' object='libntfs_3g_la-realpath.lo' libtool=yes @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libntfs_3g_la_CPPFLAGS) $(CPPFLAGS) $(libntfs_3g_la_CFLAGS) $(CFLAGS) -c -o libntfs_3g_la-realpath.lo `test -f 'realpath.c' || echo '$(srcdir)/'`realpath.c libntfs_3g_la-reparse.lo: reparse.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libntfs_3g_la_CPPFLAGS) $(CPPFLAGS) $(libntfs_3g_la_CFLAGS) $(CFLAGS) -MT libntfs_3g_la-reparse.lo -MD -MP -MF $(DEPDIR)/libntfs_3g_la-reparse.Tpo -c -o libntfs_3g_la-reparse.lo `test -f 'reparse.c' || echo '$(srcdir)/'`reparse.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libntfs_3g_la-reparse.Tpo $(DEPDIR)/libntfs_3g_la-reparse.Plo @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='reparse.c' object='libntfs_3g_la-reparse.lo' libtool=yes @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libntfs_3g_la_CPPFLAGS) $(CPPFLAGS) $(libntfs_3g_la_CFLAGS) $(CFLAGS) -c -o libntfs_3g_la-reparse.lo `test -f 'reparse.c' || echo '$(srcdir)/'`reparse.c libntfs_3g_la-runlist.lo: runlist.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libntfs_3g_la_CPPFLAGS) $(CPPFLAGS) $(libntfs_3g_la_CFLAGS) $(CFLAGS) -MT libntfs_3g_la-runlist.lo -MD -MP -MF $(DEPDIR)/libntfs_3g_la-runlist.Tpo -c -o libntfs_3g_la-runlist.lo `test -f 'runlist.c' || echo '$(srcdir)/'`runlist.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libntfs_3g_la-runlist.Tpo $(DEPDIR)/libntfs_3g_la-runlist.Plo @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='runlist.c' object='libntfs_3g_la-runlist.lo' libtool=yes @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libntfs_3g_la_CPPFLAGS) $(CPPFLAGS) $(libntfs_3g_la_CFLAGS) $(CFLAGS) -c -o libntfs_3g_la-runlist.lo `test -f 'runlist.c' || echo '$(srcdir)/'`runlist.c libntfs_3g_la-security.lo: security.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libntfs_3g_la_CPPFLAGS) $(CPPFLAGS) $(libntfs_3g_la_CFLAGS) $(CFLAGS) -MT libntfs_3g_la-security.lo -MD -MP -MF $(DEPDIR)/libntfs_3g_la-security.Tpo -c -o libntfs_3g_la-security.lo `test -f 'security.c' || echo '$(srcdir)/'`security.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libntfs_3g_la-security.Tpo $(DEPDIR)/libntfs_3g_la-security.Plo @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='security.c' object='libntfs_3g_la-security.lo' libtool=yes @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libntfs_3g_la_CPPFLAGS) $(CPPFLAGS) $(libntfs_3g_la_CFLAGS) $(CFLAGS) -c -o libntfs_3g_la-security.lo `test -f 'security.c' || echo '$(srcdir)/'`security.c libntfs_3g_la-unistr.lo: unistr.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libntfs_3g_la_CPPFLAGS) $(CPPFLAGS) $(libntfs_3g_la_CFLAGS) $(CFLAGS) -MT libntfs_3g_la-unistr.lo -MD -MP -MF $(DEPDIR)/libntfs_3g_la-unistr.Tpo -c -o libntfs_3g_la-unistr.lo `test -f 'unistr.c' || echo '$(srcdir)/'`unistr.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libntfs_3g_la-unistr.Tpo $(DEPDIR)/libntfs_3g_la-unistr.Plo @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='unistr.c' object='libntfs_3g_la-unistr.lo' libtool=yes @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libntfs_3g_la_CPPFLAGS) $(CPPFLAGS) $(libntfs_3g_la_CFLAGS) $(CFLAGS) -c -o libntfs_3g_la-unistr.lo `test -f 'unistr.c' || echo '$(srcdir)/'`unistr.c libntfs_3g_la-volume.lo: volume.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libntfs_3g_la_CPPFLAGS) $(CPPFLAGS) $(libntfs_3g_la_CFLAGS) $(CFLAGS) -MT libntfs_3g_la-volume.lo -MD -MP -MF $(DEPDIR)/libntfs_3g_la-volume.Tpo -c -o libntfs_3g_la-volume.lo `test -f 'volume.c' || echo '$(srcdir)/'`volume.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libntfs_3g_la-volume.Tpo $(DEPDIR)/libntfs_3g_la-volume.Plo @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='volume.c' object='libntfs_3g_la-volume.lo' libtool=yes @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libntfs_3g_la_CPPFLAGS) $(CPPFLAGS) $(libntfs_3g_la_CFLAGS) $(CFLAGS) -c -o libntfs_3g_la-volume.lo `test -f 'volume.c' || echo '$(srcdir)/'`volume.c libntfs_3g_la-xattrs.lo: xattrs.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libntfs_3g_la_CPPFLAGS) $(CPPFLAGS) $(libntfs_3g_la_CFLAGS) $(CFLAGS) -MT libntfs_3g_la-xattrs.lo -MD -MP -MF $(DEPDIR)/libntfs_3g_la-xattrs.Tpo -c -o libntfs_3g_la-xattrs.lo `test -f 'xattrs.c' || echo '$(srcdir)/'`xattrs.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libntfs_3g_la-xattrs.Tpo $(DEPDIR)/libntfs_3g_la-xattrs.Plo @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='xattrs.c' object='libntfs_3g_la-xattrs.lo' libtool=yes @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libntfs_3g_la_CPPFLAGS) $(CPPFLAGS) $(libntfs_3g_la_CFLAGS) $(CFLAGS) -c -o libntfs_3g_la-xattrs.lo `test -f 'xattrs.c' || echo '$(srcdir)/'`xattrs.c libntfs_3g_la-win32_io.lo: win32_io.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libntfs_3g_la_CPPFLAGS) $(CPPFLAGS) $(libntfs_3g_la_CFLAGS) $(CFLAGS) -MT libntfs_3g_la-win32_io.lo -MD -MP -MF $(DEPDIR)/libntfs_3g_la-win32_io.Tpo -c -o libntfs_3g_la-win32_io.lo `test -f 'win32_io.c' || echo '$(srcdir)/'`win32_io.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libntfs_3g_la-win32_io.Tpo $(DEPDIR)/libntfs_3g_la-win32_io.Plo @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='win32_io.c' object='libntfs_3g_la-win32_io.lo' libtool=yes @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libntfs_3g_la_CPPFLAGS) $(CPPFLAGS) $(libntfs_3g_la_CFLAGS) $(CFLAGS) -c -o libntfs_3g_la-win32_io.lo `test -f 'win32_io.c' || echo '$(srcdir)/'`win32_io.c libntfs_3g_la-unix_io.lo: unix_io.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libntfs_3g_la_CPPFLAGS) $(CPPFLAGS) $(libntfs_3g_la_CFLAGS) $(CFLAGS) -MT libntfs_3g_la-unix_io.lo -MD -MP -MF $(DEPDIR)/libntfs_3g_la-unix_io.Tpo -c -o libntfs_3g_la-unix_io.lo `test -f 'unix_io.c' || echo '$(srcdir)/'`unix_io.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libntfs_3g_la-unix_io.Tpo $(DEPDIR)/libntfs_3g_la-unix_io.Plo @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='unix_io.c' object='libntfs_3g_la-unix_io.lo' libtool=yes @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libntfs_3g_la_CPPFLAGS) $(CPPFLAGS) $(libntfs_3g_la_CFLAGS) $(CFLAGS) -c -o libntfs_3g_la-unix_io.lo `test -f 'unix_io.c' || echo '$(srcdir)/'`unix_io.c mostlyclean-libtool: -rm -f *.lo clean-libtool: -rm -rf .libs _libs install-pkgconfigDATA: $(pkgconfig_DATA) @$(NORMAL_INSTALL) @list='$(pkgconfig_DATA)'; test -n "$(pkgconfigdir)" || list=; \ if test -n "$$list"; then \ echo " $(MKDIR_P) '$(DESTDIR)$(pkgconfigdir)'"; \ $(MKDIR_P) "$(DESTDIR)$(pkgconfigdir)" || exit 1; \ fi; \ for p in $$list; do \ if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ echo "$$d$$p"; \ done | $(am__base_list) | \ while read files; do \ echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(pkgconfigdir)'"; \ $(INSTALL_DATA) $$files "$(DESTDIR)$(pkgconfigdir)" || exit $$?; \ done uninstall-pkgconfigDATA: @$(NORMAL_UNINSTALL) @list='$(pkgconfig_DATA)'; test -n "$(pkgconfigdir)" || list=; \ files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \ dir='$(DESTDIR)$(pkgconfigdir)'; $(am__uninstall_files_from_dir) ID: $(am__tagged_files) $(am__define_uniq_tagged_files); mkid -fID $$unique tags: tags-am TAGS: tags tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) set x; \ here=`pwd`; \ $(am__define_uniq_tagged_files); \ shift; \ if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ test -n "$$unique" || unique=$$empty_fix; \ if test $$# -gt 0; then \ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ "$$@" $$unique; \ else \ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ $$unique; \ fi; \ fi ctags: ctags-am CTAGS: ctags ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) $(am__define_uniq_tagged_files); \ test -z "$(CTAGS_ARGS)$$unique" \ || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ $$unique GTAGS: here=`$(am__cd) $(top_builddir) && pwd` \ && $(am__cd) $(top_srcdir) \ && gtags -i $(GTAGS_ARGS) "$$here" cscopelist: cscopelist-am cscopelist-am: $(am__tagged_files) list='$(am__tagged_files)'; \ case "$(srcdir)" in \ [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \ *) sdir=$(subdir)/$(srcdir) ;; \ esac; \ for i in $$list; do \ if test -f "$$i"; then \ echo "$(subdir)/$$i"; \ else \ echo "$$sdir/$$i"; \ fi; \ done >> $(top_builddir)/cscope.files distclean-tags: -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags distdir: $(BUILT_SOURCES) $(MAKE) $(AM_MAKEFLAGS) distdir-am distdir-am: $(DISTFILES) @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ list='$(DISTFILES)'; \ dist_files=`for file in $$list; do echo $$file; done | \ sed -e "s|^$$srcdirstrip/||;t" \ -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ case $$dist_files in \ */*) $(MKDIR_P) `echo "$$dist_files" | \ sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ sort -u` ;; \ esac; \ for file in $$dist_files; do \ if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ if test -d $$d/$$file; then \ dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ if test -d "$(distdir)/$$file"; then \ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ fi; \ if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ fi; \ cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ else \ test -f "$(distdir)/$$file" \ || cp -p $$d/$$file "$(distdir)/$$file" \ || exit 1; \ fi; \ done check-am: all-am check: check-am all-am: Makefile $(LTLIBRARIES) $(DATA) install-rootlibLTLIBRARIES: install-libLTLIBRARIES installdirs: for dir in "$(DESTDIR)$(libdir)" "$(DESTDIR)$(rootlibdir)" "$(DESTDIR)$(pkgconfigdir)"; do \ test -z "$$dir" || $(MKDIR_P) "$$dir"; \ done install: install-am install-exec: install-exec-am install-data: install-data-am uninstall: uninstall-am install-am: all-am @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am installcheck: installcheck-am install-strip: if test -z '$(STRIP)'; then \ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ install; \ else \ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ fi mostlyclean-generic: clean-generic: distclean-generic: -$(am__rm_f) $(CONFIG_CLEAN_FILES) -test . = "$(srcdir)" || $(am__rm_f) $(CONFIG_CLEAN_VPATH_FILES) maintainer-clean-generic: @echo "This command is intended for maintainers to use" @echo "it deletes files that may require special tools to rebuild." -$(am__rm_f) $(MAINTAINERCLEANFILES) clean: clean-am clean-am: clean-generic clean-libLTLIBRARIES clean-libtool \ clean-noinstLTLIBRARIES clean-rootlibLTLIBRARIES \ mostlyclean-am distclean: distclean-am -rm -f ./$(DEPDIR)/libntfs_3g_la-acls.Plo -rm -f ./$(DEPDIR)/libntfs_3g_la-attrib.Plo -rm -f ./$(DEPDIR)/libntfs_3g_la-attrlist.Plo -rm -f ./$(DEPDIR)/libntfs_3g_la-bitmap.Plo -rm -f ./$(DEPDIR)/libntfs_3g_la-bootsect.Plo -rm -f ./$(DEPDIR)/libntfs_3g_la-cache.Plo -rm -f ./$(DEPDIR)/libntfs_3g_la-collate.Plo -rm -f ./$(DEPDIR)/libntfs_3g_la-compat.Plo -rm -f ./$(DEPDIR)/libntfs_3g_la-compress.Plo -rm -f ./$(DEPDIR)/libntfs_3g_la-debug.Plo -rm -f ./$(DEPDIR)/libntfs_3g_la-device.Plo -rm -f ./$(DEPDIR)/libntfs_3g_la-dir.Plo -rm -f ./$(DEPDIR)/libntfs_3g_la-ea.Plo -rm -f ./$(DEPDIR)/libntfs_3g_la-efs.Plo -rm -f ./$(DEPDIR)/libntfs_3g_la-index.Plo -rm -f ./$(DEPDIR)/libntfs_3g_la-inode.Plo -rm -f ./$(DEPDIR)/libntfs_3g_la-ioctl.Plo -rm -f ./$(DEPDIR)/libntfs_3g_la-lcnalloc.Plo -rm -f ./$(DEPDIR)/libntfs_3g_la-logfile.Plo -rm -f ./$(DEPDIR)/libntfs_3g_la-logging.Plo -rm -f ./$(DEPDIR)/libntfs_3g_la-mft.Plo -rm -f ./$(DEPDIR)/libntfs_3g_la-misc.Plo -rm -f ./$(DEPDIR)/libntfs_3g_la-mst.Plo -rm -f ./$(DEPDIR)/libntfs_3g_la-object_id.Plo -rm -f ./$(DEPDIR)/libntfs_3g_la-realpath.Plo -rm -f ./$(DEPDIR)/libntfs_3g_la-reparse.Plo -rm -f ./$(DEPDIR)/libntfs_3g_la-runlist.Plo -rm -f ./$(DEPDIR)/libntfs_3g_la-security.Plo -rm -f ./$(DEPDIR)/libntfs_3g_la-unistr.Plo -rm -f ./$(DEPDIR)/libntfs_3g_la-unix_io.Plo -rm -f ./$(DEPDIR)/libntfs_3g_la-volume.Plo -rm -f ./$(DEPDIR)/libntfs_3g_la-win32_io.Plo -rm -f ./$(DEPDIR)/libntfs_3g_la-xattrs.Plo -rm -f Makefile distclean-am: clean-am distclean-compile distclean-generic \ distclean-tags dvi: dvi-am dvi-am: html: html-am html-am: info: info-am info-am: install-data-am: install-pkgconfigDATA install-rootlibLTLIBRARIES install-dvi: install-dvi-am install-dvi-am: install-exec-am: install-libLTLIBRARIES @$(NORMAL_INSTALL) $(MAKE) $(AM_MAKEFLAGS) install-exec-hook install-html: install-html-am install-html-am: install-info: install-info-am install-info-am: install-man: install-pdf: install-pdf-am install-pdf-am: install-ps: install-ps-am install-ps-am: installcheck-am: maintainer-clean: maintainer-clean-am -rm -f ./$(DEPDIR)/libntfs_3g_la-acls.Plo -rm -f ./$(DEPDIR)/libntfs_3g_la-attrib.Plo -rm -f ./$(DEPDIR)/libntfs_3g_la-attrlist.Plo -rm -f ./$(DEPDIR)/libntfs_3g_la-bitmap.Plo -rm -f ./$(DEPDIR)/libntfs_3g_la-bootsect.Plo -rm -f ./$(DEPDIR)/libntfs_3g_la-cache.Plo -rm -f ./$(DEPDIR)/libntfs_3g_la-collate.Plo -rm -f ./$(DEPDIR)/libntfs_3g_la-compat.Plo -rm -f ./$(DEPDIR)/libntfs_3g_la-compress.Plo -rm -f ./$(DEPDIR)/libntfs_3g_la-debug.Plo -rm -f ./$(DEPDIR)/libntfs_3g_la-device.Plo -rm -f ./$(DEPDIR)/libntfs_3g_la-dir.Plo -rm -f ./$(DEPDIR)/libntfs_3g_la-ea.Plo -rm -f ./$(DEPDIR)/libntfs_3g_la-efs.Plo -rm -f ./$(DEPDIR)/libntfs_3g_la-index.Plo -rm -f ./$(DEPDIR)/libntfs_3g_la-inode.Plo -rm -f ./$(DEPDIR)/libntfs_3g_la-ioctl.Plo -rm -f ./$(DEPDIR)/libntfs_3g_la-lcnalloc.Plo -rm -f ./$(DEPDIR)/libntfs_3g_la-logfile.Plo -rm -f ./$(DEPDIR)/libntfs_3g_la-logging.Plo -rm -f ./$(DEPDIR)/libntfs_3g_la-mft.Plo -rm -f ./$(DEPDIR)/libntfs_3g_la-misc.Plo -rm -f ./$(DEPDIR)/libntfs_3g_la-mst.Plo -rm -f ./$(DEPDIR)/libntfs_3g_la-object_id.Plo -rm -f ./$(DEPDIR)/libntfs_3g_la-realpath.Plo -rm -f ./$(DEPDIR)/libntfs_3g_la-reparse.Plo -rm -f ./$(DEPDIR)/libntfs_3g_la-runlist.Plo -rm -f ./$(DEPDIR)/libntfs_3g_la-security.Plo -rm -f ./$(DEPDIR)/libntfs_3g_la-unistr.Plo -rm -f ./$(DEPDIR)/libntfs_3g_la-unix_io.Plo -rm -f ./$(DEPDIR)/libntfs_3g_la-volume.Plo -rm -f ./$(DEPDIR)/libntfs_3g_la-win32_io.Plo -rm -f ./$(DEPDIR)/libntfs_3g_la-xattrs.Plo -rm -f Makefile maintainer-clean-am: distclean-am maintainer-clean-generic mostlyclean: mostlyclean-am mostlyclean-am: mostlyclean-compile mostlyclean-generic \ mostlyclean-libtool pdf: pdf-am pdf-am: ps: ps-am ps-am: uninstall-am: uninstall-libLTLIBRARIES uninstall-local \ uninstall-pkgconfigDATA uninstall-rootlibLTLIBRARIES .MAKE: install-am install-exec-am install-strip .PHONY: CTAGS GTAGS TAGS all all-am am--depfiles check check-am clean \ clean-generic clean-libLTLIBRARIES clean-libtool \ clean-noinstLTLIBRARIES clean-rootlibLTLIBRARIES cscopelist-am \ ctags ctags-am distclean distclean-compile distclean-generic \ distclean-libtool distclean-tags distdir dvi dvi-am html \ html-am info info-am install install-am install-data \ install-data-am install-dvi install-dvi-am install-exec \ install-exec-am install-exec-hook install-html install-html-am \ install-info install-info-am install-libLTLIBRARIES \ install-man install-pdf install-pdf-am install-pkgconfigDATA \ install-ps install-ps-am install-rootlibLTLIBRARIES \ install-strip installcheck installcheck-am installdirs \ maintainer-clean maintainer-clean-generic mostlyclean \ mostlyclean-compile mostlyclean-generic mostlyclean-libtool \ pdf pdf-am ps ps-am tags tags-am uninstall uninstall-am \ uninstall-libLTLIBRARIES uninstall-local \ uninstall-pkgconfigDATA uninstall-rootlibLTLIBRARIES .PRECIOUS: Makefile # We may need to move .so files to root # And create ldscript or symbolic link from /usr install-exec-hook: install-rootlibLTLIBRARIES @INSTALL_LIBRARY_TRUE@ if [ ! "$(rootlibdir)" -ef "$(libdir)" ]; then \ @INSTALL_LIBRARY_TRUE@ $(MV) -f "$(DESTDIR)/$(libdir)"/libntfs-3g.so* "$(DESTDIR)/$(rootlibdir)"; \ @INSTALL_LIBRARY_TRUE@ fi @GENERATE_LDSCRIPT_TRUE@@INSTALL_LIBRARY_TRUE@ if [ ! "$(rootlibdir)" -ef "$(libdir)" ]; then \ @GENERATE_LDSCRIPT_TRUE@@INSTALL_LIBRARY_TRUE@ $(install_sh_PROGRAM) "libntfs-3g.script.so" "$(DESTDIR)/$(libdir)/libntfs-3g.so"; \ @GENERATE_LDSCRIPT_TRUE@@INSTALL_LIBRARY_TRUE@ fi @GENERATE_LDSCRIPT_FALSE@@INSTALL_LIBRARY_TRUE@ if [ ! "$(rootlibdir)" -ef "$(libdir)" ]; then \ @GENERATE_LDSCRIPT_FALSE@@INSTALL_LIBRARY_TRUE@ $(LN_S) "$(rootlibdir)/libntfs-3g.so" "$(DESTDIR)/$(libdir)/libntfs-3g.so"; \ @GENERATE_LDSCRIPT_FALSE@@INSTALL_LIBRARY_TRUE@ fi uninstall-local: @INSTALL_LIBRARY_TRUE@ $(RM) -f "$(DESTDIR)/$(rootlibdir)"/libntfs-3g.so* @ENABLE_NTFSPROGS_TRUE@libs: $(lib_LTLIBRARIES) # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. .NOEXPORT: # Tell GNU make to disable its built-in pattern rules. %:: %,v %:: RCS/%,v %:: RCS/% %:: s.% %:: SCCS/s.% ntfs-3g-2026.2.25/libntfs-3g/win32_io.c0000664000175000017500000015541515152260173012560 /* * win32_io.c - A stdio-like disk I/O implementation for low-level disk access * on Win32. Can access an NTFS volume while it is mounted. * Originated from the Linux-NTFS project. * * Copyright (c) 2003-2004 Lode Leroy * Copyright (c) 2003-2006 Anton Altaparmakov * Copyright (c) 2004-2005 Yuval Fledel * Copyright (c) 2012-2014 Jean-Pierre Andre * * This program/include file 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/include file 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 */ #include "config.h" #ifdef HAVE_WINDOWS_H #define BOOL WINBOOL /* avoid conflicting definitions of BOOL */ #include #undef BOOL #endif #ifdef HAVE_STDLIB_H #include #endif /* * Definitions needed for */ #ifndef _ANONYMOUS_UNION #define _ANONYMOUS_UNION #define _ANONYMOUS_STRUCT typedef unsigned long long DWORD64; #endif typedef struct { DWORD data1; /* The first eight hexadecimal digits of the GUID. */ WORD data2; /* The first group of four hexadecimal digits. */ WORD data3; /* The second group of four hexadecimal digits. */ char data4[8]; /* The first two bytes are the third group of four hexadecimal digits. The remaining six bytes are the final 12 hexadecimal digits. */ } GUID; #include #ifdef HAVE_STDIO_H #include #endif #ifdef HAVE_CTYPE_H #include #endif #ifdef HAVE_ERRNO_H #include #endif #ifdef HAVE_FCNTL_H #include #endif #ifdef HAVE_SYS_STAT_H #include #define stat stat64 #define st_blocks st_rdev /* emulate st_blocks, missing in Windows */ #endif /* Prevent volume.h from being be loaded, as it conflicts with winnt.h. */ #define _NTFS_VOLUME_H struct ntfs_volume; typedef struct ntfs_volume ntfs_volume; #include "debug.h" #include "types.h" #include "device.h" #include "misc.h" #define cpu_to_le16(x) (x) #define const_cpu_to_le16(x) (x) #ifndef MAX_PATH #define MAX_PATH 1024 #endif #ifndef NTFS_BLOCK_SIZE #define NTFS_BLOCK_SIZE 512 #define NTFS_BLOCK_SIZE_BITS 9 #endif #ifndef INVALID_SET_FILE_POINTER #define INVALID_SET_FILE_POINTER ((DWORD)-1) #endif #ifndef IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS #define IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS 5636096 #endif #ifndef IOCTL_DISK_GET_DRIVE_GEOMETRY #define IOCTL_DISK_GET_DRIVE_GEOMETRY 0x70000 #endif #ifndef IOCTL_GET_DISK_LENGTH_INFO #define IOCTL_GET_DISK_LENGTH_INFO 0x7405c #endif #ifndef FSCTL_ALLOW_EXTENDED_DASD_IO #define FSCTL_ALLOW_EXTENDED_DASD_IO 0x90083 #endif /* Windows 2k+ imports. */ typedef HANDLE (WINAPI *LPFN_FINDFIRSTVOLUME)(LPTSTR, DWORD); typedef BOOL (WINAPI *LPFN_FINDNEXTVOLUME)(HANDLE, LPTSTR, DWORD); typedef BOOL (WINAPI *LPFN_FINDVOLUMECLOSE)(HANDLE); typedef BOOL (WINAPI *LPFN_SETFILEPOINTEREX)(HANDLE, LARGE_INTEGER, PLARGE_INTEGER, DWORD); static LPFN_FINDFIRSTVOLUME fnFindFirstVolume = NULL; static LPFN_FINDNEXTVOLUME fnFindNextVolume = NULL; static LPFN_FINDVOLUMECLOSE fnFindVolumeClose = NULL; static LPFN_SETFILEPOINTEREX fnSetFilePointerEx = NULL; #ifdef UNICODE #define FNPOSTFIX "W" #else #define FNPOSTFIX "A" #endif enum { /* see http://msdn.microsoft.com/en-us/library/cc704588(v=prot.10).aspx */ STATUS_UNKNOWN = -1, STATUS_SUCCESS = 0x00000000, STATUS_BUFFER_OVERFLOW = 0x80000005, STATUS_INVALID_HANDLE = 0xC0000008, STATUS_INVALID_PARAMETER = 0xC000000D, STATUS_INVALID_DEVICE_REQUEST = 0xC0000010, STATUS_END_OF_FILE = 0xC0000011, STATUS_CONFLICTING_ADDRESSES = 0xC0000018, STATUS_NO_MATCH = 0xC000001E, STATUS_ACCESS_DENIED = 0xC0000022, STATUS_BUFFER_TOO_SMALL = 0xC0000023, STATUS_OBJECT_TYPE_MISMATCH = 0xC0000024, STATUS_FILE_NOT_FOUND = 0xC0000028, STATUS_OBJECT_NAME_INVALID = 0xC0000033, STATUS_OBJECT_NAME_NOT_FOUND = 0xC0000034, STATUS_SHARING_VIOLATION = 0xC0000043, STATUS_INVALID_PARAMETER_1 = 0xC00000EF, STATUS_IO_DEVICE_ERROR = 0xC0000185, STATUS_GUARD_PAGE_VIOLATION = 0x80000001 } ; typedef u32 NTSTATUS; /* do not let the compiler choose the size */ #ifdef __x86_64__ typedef unsigned long long ULONG_PTR; /* an integer the same size as a pointer */ #else typedef unsigned long ULONG_PTR; /* an integer the same size as a pointer */ #endif HANDLE get_osfhandle(int); /* from msvcrt.dll */ /* * A few needed definitions not included in */ typedef struct _IO_STATUS_BLOCK { union { NTSTATUS Status; PVOID Pointer; }; ULONG_PTR Information; } IO_STATUS_BLOCK, *PIO_STATUS_BLOCK; typedef struct _UNICODE_STRING { USHORT Length; USHORT MaximumLength; #ifdef __x86_64__ u32 padding; #endif PWSTR Buffer; } UNICODE_STRING, *PUNICODE_STRING; typedef struct _OBJECT_ATTRIBUTES { ULONG Length; #ifdef __x86_64__ u32 padding1; HANDLE RootDirectory; PUNICODE_STRING ObjectName; ULONG Attributes; u32 padding2; #else HANDLE RootDirectory; PUNICODE_STRING ObjectName; ULONG Attributes; #endif PVOID SecurityDescriptor; PVOID SecurityQualityOfService; } OBJECT_ATTRIBUTES, *POBJECT_ATTRIBUTES; #define FILE_OPEN 1 #define FILE_CREATE 2 #define FILE_OVERWRITE 4 #define FILE_SYNCHRONOUS_IO_ALERT 0x10 #define FILE_SYNCHRONOUS_IO_NONALERT 0x20 #define OBJ_CASE_INSENSITIVE 0x40 typedef void (WINAPI *PIO_APC_ROUTINE)(void*, PIO_STATUS_BLOCK, ULONG); extern WINAPI NTSTATUS NtOpenFile( PHANDLE FileHandle, ACCESS_MASK DesiredAccess, POBJECT_ATTRIBUTES ObjectAttributes, PIO_STATUS_BLOCK IoStatusBlock, ULONG ShareAccess, ULONG OpenOptions ); extern WINAPI NTSTATUS NtReadFile( HANDLE FileHandle, HANDLE Event, PIO_APC_ROUTINE ApcRoutine, PVOID ApcContext, PIO_STATUS_BLOCK IoStatusBlock, PVOID Buffer, ULONG Length, PLARGE_INTEGER ByteOffset, PULONG Key ); extern WINAPI NTSTATUS NtWriteFile( HANDLE FileHandle, HANDLE Event, PIO_APC_ROUTINE ApcRoutine, PVOID ApcContext, PIO_STATUS_BLOCK IoStatusBlock, LPCVOID Buffer, ULONG Length, PLARGE_INTEGER ByteOffset, PULONG Key ); extern NTSTATUS WINAPI NtClose( HANDLE Handle ); extern NTSTATUS WINAPI NtDeviceIoControlFile( HANDLE FileHandle, HANDLE Event, PIO_APC_ROUTINE ApcRoutine, PVOID ApcContext, PIO_STATUS_BLOCK IoStatusBlock, ULONG IoControlCode, PVOID InputBuffer, ULONG InputBufferLength, PVOID OutputBuffer, ULONG OutputBufferLength ); extern NTSTATUS WINAPI NtFsControlFile( HANDLE FileHandle, HANDLE Event, PIO_APC_ROUTINE ApcRoutine, PVOID ApcContext, PIO_STATUS_BLOCK IoStatusBlock, ULONG FsControlCode, PVOID InputBuffer, ULONG InputBufferLength, PVOID OutputBuffer, ULONG OutputBufferLength ); /** * struct win32_fd - */ typedef struct { HANDLE handle; s64 pos; /* Logical current position on the volume. */ s64 part_start; s64 part_length; int part_hidden_sectors; s64 geo_size, geo_cylinders; s32 geo_sector_size; s64 volume_size; DWORD geo_sectors, geo_heads; HANDLE vol_handle; BOOL ntdll; } win32_fd; /** * ntfs_w32error_to_errno - convert a win32 error code to the unix one * @w32error: the win32 error code * * Limited to a relatively small but useful number of codes. */ static int ntfs_w32error_to_errno(unsigned int w32error) { ntfs_log_trace("Converting w32error 0x%x.\n",w32error); switch (w32error) { case ERROR_INVALID_FUNCTION: return EBADRQC; case ERROR_FILE_NOT_FOUND: case ERROR_PATH_NOT_FOUND: case ERROR_INVALID_NAME: return ENOENT; case ERROR_TOO_MANY_OPEN_FILES: return EMFILE; case ERROR_ACCESS_DENIED: return EACCES; case ERROR_INVALID_HANDLE: return EBADF; case ERROR_NOT_ENOUGH_MEMORY: return ENOMEM; case ERROR_OUTOFMEMORY: return ENOSPC; case ERROR_INVALID_DRIVE: case ERROR_BAD_UNIT: return ENODEV; case ERROR_WRITE_PROTECT: return EROFS; case ERROR_NOT_READY: case ERROR_SHARING_VIOLATION: return EBUSY; case ERROR_BAD_COMMAND: return EINVAL; case ERROR_SEEK: case ERROR_NEGATIVE_SEEK: return ESPIPE; case ERROR_NOT_SUPPORTED: return EOPNOTSUPP; case ERROR_BAD_NETPATH: return ENOSHARE; default: /* generic message */ return ENOMSG; } } static int ntfs_ntstatus_to_errno(NTSTATUS status) { ntfs_log_trace("Converting w32error 0x%x.\n",w32error); switch (status) { case STATUS_INVALID_HANDLE : case STATUS_INVALID_PARAMETER : case STATUS_OBJECT_NAME_INVALID : case STATUS_INVALID_DEVICE_REQUEST : return (EINVAL); case STATUS_ACCESS_DENIED : return (EACCES); case STATUS_IO_DEVICE_ERROR : case STATUS_END_OF_FILE : return (EIO); case STATUS_SHARING_VIOLATION : return (EBUSY); default: /* generic message */ return ENOMSG; } } /** * libntfs_SetFilePointerEx - emulation for SetFilePointerEx() * * We use this to emulate SetFilePointerEx() when it is not present. This can * happen since SetFilePointerEx() only exists in Win2k+. */ static BOOL WINAPI libntfs_SetFilePointerEx(HANDLE hFile, LARGE_INTEGER liDistanceToMove, PLARGE_INTEGER lpNewFilePointer, DWORD dwMoveMethod) { liDistanceToMove.u.LowPart = SetFilePointer(hFile, liDistanceToMove.u.LowPart, &liDistanceToMove.u.HighPart, dwMoveMethod); SetLastError(NO_ERROR); if (liDistanceToMove.u.LowPart == INVALID_SET_FILE_POINTER && GetLastError() != NO_ERROR) { if (lpNewFilePointer) lpNewFilePointer->QuadPart = -1; return FALSE; } if (lpNewFilePointer) lpNewFilePointer->QuadPart = liDistanceToMove.QuadPart; return TRUE; } /** * ntfs_device_win32_init_imports - initialize the function pointers * * The Find*Volume and SetFilePointerEx functions exist only on win2k+, as such * we cannot just staticly import them. * * This function initializes the imports if the functions do exist and in the * SetFilePointerEx case, we emulate the function ourselves if it is not * present. * * Note: The values are cached, do be afraid to run it more than once. */ static void ntfs_device_win32_init_imports(void) { HMODULE kernel32 = GetModuleHandle("kernel32"); if (!kernel32) { errno = ntfs_w32error_to_errno(GetLastError()); ntfs_log_trace("kernel32.dll could not be imported.\n"); } if (!fnSetFilePointerEx) { if (kernel32) fnSetFilePointerEx = (LPFN_SETFILEPOINTEREX) GetProcAddress(kernel32, "SetFilePointerEx"); /* * If we did not get kernel32.dll or it is not Win2k+, emulate * SetFilePointerEx(). */ if (!fnSetFilePointerEx) { ntfs_log_debug("SetFilePointerEx() not found in " "kernel32.dll: Enabling emulation.\n"); fnSetFilePointerEx = libntfs_SetFilePointerEx; } } /* Cannot do lookups if we could not get kernel32.dll... */ if (!kernel32) return; if (!fnFindFirstVolume) fnFindFirstVolume = (LPFN_FINDFIRSTVOLUME) GetProcAddress(kernel32, "FindFirstVolume" FNPOSTFIX); if (!fnFindNextVolume) fnFindNextVolume = (LPFN_FINDNEXTVOLUME) GetProcAddress(kernel32, "FindNextVolume" FNPOSTFIX); if (!fnFindVolumeClose) fnFindVolumeClose = (LPFN_FINDVOLUMECLOSE) GetProcAddress(kernel32, "FindVolumeClose"); } /** * ntfs_device_unix_status_flags_to_win32 - convert unix->win32 open flags * @flags: unix open status flags * * Supported flags are O_RDONLY, O_WRONLY and O_RDWR. */ static __inline__ int ntfs_device_unix_status_flags_to_win32(int flags) { int win_mode; switch (flags & O_ACCMODE) { case O_RDONLY: win_mode = GENERIC_READ; break; case O_WRONLY: win_mode = GENERIC_WRITE; break; case O_RDWR: win_mode = GENERIC_READ | GENERIC_WRITE; break; default: /* error */ ntfs_log_trace("Unknown status flags.\n"); win_mode = 0; } return win_mode; } /** * ntfs_device_win32_simple_open_file - just open a file via win32 API * @filename: name of the file to open * @handle: pointer the a HANDLE in which to put the result * @flags: unix open status flags * @locking: will the function gain an exclusive lock on the file? * * Supported flags are O_RDONLY, O_WRONLY and O_RDWR. * * Return 0 if o.k. * -1 if not, and errno set. In this case handle is trashed. */ static int ntfs_device_win32_simple_open_file(const char *filename, HANDLE *handle, int flags, BOOL locking) { *handle = CreateFile(filename, ntfs_device_unix_status_flags_to_win32(flags), locking ? 0 : (FILE_SHARE_WRITE | FILE_SHARE_READ), NULL, (flags & O_CREAT ? OPEN_ALWAYS : OPEN_EXISTING), 0, NULL); if (*handle == INVALID_HANDLE_VALUE) { errno = ntfs_w32error_to_errno(GetLastError()); ntfs_log_trace("CreateFile(%s) failed.\n", filename); return -1; } return 0; } /** * ntfs_device_win32_lock - lock the volume * @handle: a win32 HANDLE for a volume to lock * * Locking a volume means no one can access its contents. * Exiting the process automatically unlocks the volume, except in old NT4s. * * Return 0 if o.k. * -1 if not, and errno set. */ static int ntfs_device_win32_lock(HANDLE handle) { DWORD i; if (!DeviceIoControl(handle, FSCTL_LOCK_VOLUME, NULL, 0, NULL, 0, &i, NULL)) { errno = ntfs_w32error_to_errno(GetLastError()); ntfs_log_trace("Couldn't lock volume.\n"); return -1; } ntfs_log_debug("Volume locked.\n"); return 0; } /** * ntfs_device_win32_unlock - unlock the volume * @handle: the win32 HANDLE which the volume was locked with * * Return 0 if o.k. * -1 if not, and errno set. */ static int ntfs_device_win32_unlock(HANDLE handle) { DWORD i; if (!DeviceIoControl(handle, FSCTL_UNLOCK_VOLUME, NULL, 0, NULL, 0, &i, NULL)) { errno = ntfs_w32error_to_errno(GetLastError()); ntfs_log_trace("Couldn't unlock volume.\n"); return -1; } ntfs_log_debug("Volume unlocked.\n"); return 0; } static int ntfs_device_win32_setlock(HANDLE handle, ULONG code) { IO_STATUS_BLOCK io_status; NTSTATUS res; io_status.Status = STATUS_SUCCESS; io_status.Information = 0; res = NtFsControlFile(handle,(HANDLE)NULL, (PIO_APC_ROUTINE)NULL,(void*)NULL, &io_status, code, (char*)NULL,0,(char*)NULL,0); if (res != STATUS_SUCCESS) errno = ntfs_ntstatus_to_errno(res); return (res == STATUS_SUCCESS ? 0 : -1); } /** * ntfs_device_win32_dismount - dismount a volume * @handle: a win32 HANDLE for a volume to dismount * * Dismounting means the system will refresh the volume in the first change it * gets. Usefull after altering the file structures. * The volume must be locked by the current process while dismounting. * A side effect is that the volume is also unlocked, but you must not rely om * this. * * Return 0 if o.k. * -1 if not, and errno set. */ static int ntfs_device_win32_dismount(HANDLE handle) { DWORD i; if (!DeviceIoControl(handle, FSCTL_DISMOUNT_VOLUME, NULL, 0, NULL, 0, &i, NULL)) { errno = ntfs_w32error_to_errno(GetLastError()); ntfs_log_trace("Couldn't dismount volume.\n"); return -1; } ntfs_log_debug("Volume dismounted.\n"); return 0; } /** * ntfs_device_win32_getsize - get file size via win32 API * @handle: pointer the file HANDLE obtained via open * * Only works on ordinary files. * * Return The file size if o.k. * -1 if not, and errno set. */ static s64 ntfs_device_win32_getsize(HANDLE handle) { LONG loword, hiword; SetLastError(NO_ERROR); hiword = 0; loword = SetFilePointer(handle, 0, &hiword, 2); if ((loword == INVALID_SET_FILE_POINTER) && (GetLastError() != NO_ERROR)) { errno = ntfs_w32error_to_errno(GetLastError()); ntfs_log_trace("Couldn't get file size.\n"); return -1; } return ((s64)hiword << 32) + (ULONG)loword; } /** * ntfs_device_win32_getdisklength - get disk size via win32 API * @handle: pointer the file HANDLE obtained via open * @argp: pointer to result buffer * * Only works on PhysicalDriveX type handles. * * Return The disk size if o.k. * -1 if not, and errno set. */ static s64 ntfs_device_win32_getdisklength(HANDLE handle) { GET_LENGTH_INFORMATION buf; DWORD i; if (!DeviceIoControl(handle, IOCTL_DISK_GET_LENGTH_INFO, NULL, 0, &buf, sizeof(buf), &i, NULL)) { errno = ntfs_w32error_to_errno(GetLastError()); ntfs_log_trace("Couldn't get disk length.\n"); return -1; } ntfs_log_debug("Disk length: %lld.\n", buf.Length.QuadPart); return buf.Length.QuadPart; } /** * ntfs_device_win32_getntfssize - get NTFS volume size via win32 API * @handle: pointer the file HANDLE obtained via open * @argp: pointer to result buffer * * Only works on NTFS volume handles. * An annoying bug in windows is that an NTFS volume does not occupy the entire * partition, namely not the last sector (which holds the backup boot sector, * and normally not interesting). * Use this function to get the length of the accessible space through a given * volume handle. * * Return The volume size if o.k. * -1 if not, and errno set. */ static s64 ntfs_device_win32_getntfssize(HANDLE handle) { s64 rvl; #ifdef FSCTL_GET_NTFS_VOLUME_DATA DWORD i; NTFS_VOLUME_DATA_BUFFER buf; if (!DeviceIoControl(handle, FSCTL_GET_NTFS_VOLUME_DATA, NULL, 0, &buf, sizeof(buf), &i, NULL)) { errno = ntfs_w32error_to_errno(GetLastError()); ntfs_log_trace("Couldn't get NTFS volume length.\n"); return -1; } rvl = buf.NumberSectors.QuadPart * buf.BytesPerSector; ntfs_log_debug("NTFS volume length: 0x%llx.\n", (long long)rvl); #else errno = EINVAL; rvl = -1; #endif return rvl; } /** * ntfs_device_win32_getgeo - get CHS information of a drive * @handle: an open handle to the PhysicalDevice * @fd: a win_fd structure that will be filled * * Return 0 if o.k. * -1 if not, and errno set. * * In Windows NT+: fills size, sectors, and cylinders and sets heads to -1. * In Windows XP+: fills size, sectors, cylinders, and heads. * * Note: In pre XP, this requires write permission, even though nothing is * actually written. * * If fails, sets sectors, cylinders, heads, and size to -1. */ static int ntfs_device_win32_getgeo(HANDLE handle, win32_fd *fd) { DWORD i; BOOL rvl; BYTE b[sizeof(DISK_GEOMETRY) + sizeof(DISK_PARTITION_INFO) + sizeof(DISK_DETECTION_INFO) + 512]; rvl = DeviceIoControl(handle, IOCTL_DISK_GET_DRIVE_GEOMETRY_EX, NULL, 0, &b, sizeof(b), &i, NULL); if (rvl) { ntfs_log_debug("GET_DRIVE_GEOMETRY_EX detected.\n"); DISK_DETECTION_INFO *ddi = (PDISK_DETECTION_INFO) (((PBYTE)(&((PDISK_GEOMETRY_EX)b)->Data)) + (((PDISK_PARTITION_INFO) (&((PDISK_GEOMETRY_EX)b)->Data))-> SizeOfPartitionInfo)); fd->geo_cylinders = ((DISK_GEOMETRY*)&b)->Cylinders.QuadPart; fd->geo_sectors = ((DISK_GEOMETRY*)&b)->SectorsPerTrack; fd->geo_size = ((DISK_GEOMETRY_EX*)&b)->DiskSize.QuadPart; fd->geo_sector_size = NTFS_BLOCK_SIZE; switch (ddi->DetectionType) { case DetectInt13: fd->geo_cylinders = ddi->Int13.MaxCylinders; fd->geo_sectors = ddi->Int13.SectorsPerTrack; fd->geo_heads = ddi->Int13.MaxHeads; return 0; case DetectExInt13: fd->geo_cylinders = ddi->ExInt13.ExCylinders; fd->geo_sectors = ddi->ExInt13.ExSectorsPerTrack; fd->geo_heads = ddi->ExInt13.ExHeads; return 0; case DetectNone: default: break; } } else fd->geo_heads = -1; rvl = DeviceIoControl(handle, IOCTL_DISK_GET_DRIVE_GEOMETRY, NULL, 0, &b, sizeof(b), &i, NULL); if (rvl) { ntfs_log_debug("GET_DRIVE_GEOMETRY detected.\n"); fd->geo_cylinders = ((DISK_GEOMETRY*)&b)->Cylinders.QuadPart; fd->geo_sectors = ((DISK_GEOMETRY*)&b)->SectorsPerTrack; fd->geo_size = fd->geo_cylinders * fd->geo_sectors * ((DISK_GEOMETRY*)&b)->TracksPerCylinder * ((DISK_GEOMETRY*)&b)->BytesPerSector; fd->geo_sector_size = ((DISK_GEOMETRY*)&b)->BytesPerSector; return 0; } errno = ntfs_w32error_to_errno(GetLastError()); ntfs_log_trace("Couldn't retrieve disk geometry.\n"); fd->geo_cylinders = -1; fd->geo_sectors = -1; fd->geo_size = -1; fd->geo_sector_size = NTFS_BLOCK_SIZE; return -1; } static int ntfs_device_win32_getntgeo(HANDLE handle, win32_fd *fd) { DISK_GEOMETRY geo; NTSTATUS st; IO_STATUS_BLOCK status; u64 bytes; int res; res = -1; fd->geo_cylinders = 0; fd->geo_sectors = 0; fd->geo_size = 1073741824; fd->geo_sectors = fd->geo_size >> 9; fd->geo_sector_size = NTFS_BLOCK_SIZE; st = NtDeviceIoControlFile(handle, (HANDLE)NULL, (PIO_APC_ROUTINE)NULL, (void*)NULL, &status, IOCTL_DISK_GET_DRIVE_GEOMETRY, (void*)NULL, 0, (void*)&geo, sizeof(geo)); if (st == STATUS_SUCCESS) { /* over-estimate the (rounded) number of cylinders */ fd->geo_cylinders = geo.Cylinders.QuadPart + 1; fd->geo_sectors = fd->geo_cylinders *geo.TracksPerCylinder*geo.SectorsPerTrack; fd->geo_size = fd->geo_sectors*geo.BytesPerSector; fd->geo_sector_size = geo.BytesPerSector; res = 0; /* try to get the exact sector count */ st = NtDeviceIoControlFile(handle, (HANDLE)NULL, (PIO_APC_ROUTINE)NULL, (void*)NULL, &status, IOCTL_GET_DISK_LENGTH_INFO, (void*)NULL, 0, (void*)&bytes, sizeof(bytes)); if (st == STATUS_SUCCESS) { fd->geo_size = bytes; fd->geo_sectors = bytes/geo.BytesPerSector; } } return (res); } /** * ntfs_device_win32_open_file - open a file via win32 API * @filename: name of the file to open * @fd: pointer to win32 file device in which to put the result * @flags: unix open status flags * * Return 0 if o.k. * -1 if not, and errno set. */ static __inline__ int ntfs_device_win32_open_file(char *filename, win32_fd *fd, int flags) { HANDLE handle; int mode; if (ntfs_device_win32_simple_open_file(filename, &handle, flags, FALSE)) { /* open error */ return -1; } mode = flags & O_ACCMODE; if ((mode == O_RDWR) || (mode == O_WRONLY)) { DWORD bytes; /* try making sparse (but ignore errors) */ DeviceIoControl(handle, FSCTL_SET_SPARSE, (void*)NULL, 0, (void*)NULL, 0, &bytes, (LPOVERLAPPED)NULL); } /* fill fd */ fd->handle = handle; fd->part_start = 0; fd->part_length = ntfs_device_win32_getsize(handle); fd->pos = 0; fd->part_hidden_sectors = -1; fd->geo_size = -1; /* used as a marker that this is a file */ fd->vol_handle = INVALID_HANDLE_VALUE; fd->geo_sector_size = 512; /* will be adjusted from the boot sector */ fd->ntdll = FALSE; return 0; } /** * ntfs_device_win32_open_drive - open a drive via win32 API * @drive_id: drive to open * @fd: pointer to win32 file device in which to put the result * @flags: unix open status flags * * return 0 if o.k. * -1 if not, and errno set. */ static __inline__ int ntfs_device_win32_open_drive(int drive_id, win32_fd *fd, int flags) { HANDLE handle; int err; char filename[MAX_PATH]; sprintf(filename, "\\\\.\\PhysicalDrive%d", drive_id); if ((err = ntfs_device_win32_simple_open_file(filename, &handle, flags, TRUE))) { /* open error */ return err; } /* store the drive geometry */ ntfs_device_win32_getgeo(handle, fd); /* Just to be sure */ if (fd->geo_size == -1) fd->geo_size = ntfs_device_win32_getdisklength(handle); /* fill fd */ fd->ntdll = FALSE; fd->handle = handle; fd->part_start = 0; fd->part_length = fd->geo_size; fd->pos = 0; fd->part_hidden_sectors = -1; fd->vol_handle = INVALID_HANDLE_VALUE; return 0; } /** * ntfs_device_win32_open_lowlevel - open a drive via low level win32 API * @drive_id: drive to open * @fd: pointer to win32 file device in which to put the result * @flags: unix open status flags * * return 0 if o.k. * -1 if not, and errno set. */ static __inline__ int ntfs_device_win32_open_lowlevel(int drive_id, win32_fd *fd, int flags) { HANDLE handle; NTSTATUS st; ACCESS_MASK access; ULONG share; OBJECT_ATTRIBUTES attr; IO_STATUS_BLOCK io_status; UNICODE_STRING unicode_name; ntfschar unicode_buffer[7]; int mode; static const ntfschar unicode_init[] = { const_cpu_to_le16('\\'), const_cpu_to_le16('?'), const_cpu_to_le16('?'), const_cpu_to_le16('\\'), const_cpu_to_le16(' '), const_cpu_to_le16(':'), const_cpu_to_le16(0) }; memcpy(unicode_buffer, unicode_init, sizeof(unicode_buffer)); unicode_buffer[4] = cpu_to_le16(drive_id + 'A'); unicode_name.Buffer = unicode_buffer; unicode_name.Length = 6*sizeof(ntfschar); unicode_name.MaximumLength = 6*sizeof(ntfschar); attr.Length = sizeof(OBJECT_ATTRIBUTES); attr.RootDirectory = (HANDLE*)NULL; attr.ObjectName = &unicode_name; attr.Attributes = OBJ_CASE_INSENSITIVE; attr.SecurityDescriptor = (void*)NULL; attr.SecurityQualityOfService = (void*)NULL; io_status.Status = 0; io_status.Information = 0; mode = flags & O_ACCMODE; share = (mode == O_RDWR ? 0 : FILE_SHARE_READ | FILE_SHARE_WRITE); access = (mode == O_RDWR ? FILE_READ_DATA | FILE_WRITE_DATA | SYNCHRONIZE : FILE_READ_DATA | SYNCHRONIZE); st = NtOpenFile(&handle, access, &attr, &io_status, share, FILE_SYNCHRONOUS_IO_ALERT); if (st != STATUS_SUCCESS) { errno = ntfs_ntstatus_to_errno(st); return (-1); } ntfs_device_win32_setlock(handle,FSCTL_LOCK_VOLUME); /* store the drive geometry */ ntfs_device_win32_getntgeo(handle, fd); fd->ntdll = TRUE; /* allow accessing the full partition */ st = NtFsControlFile(handle, (HANDLE)NULL, (PIO_APC_ROUTINE)NULL, (PVOID)NULL, &io_status, FSCTL_ALLOW_EXTENDED_DASD_IO, NULL, 0, NULL, 0); if (st != STATUS_SUCCESS) { errno = ntfs_ntstatus_to_errno(st); NtClose(handle); return (-1); } /* fill fd */ fd->handle = handle; fd->part_start = 0; fd->part_length = fd->geo_size; fd->pos = 0; fd->part_hidden_sectors = -1; fd->vol_handle = INVALID_HANDLE_VALUE; return 0; } /** * ntfs_device_win32_open_volume_for_partition - find and open a volume * * Windows NT/2k/XP handles volumes instead of partitions. * This function gets the partition details and return an open volume handle. * That volume is the one whose only physical location on disk is the described * partition. * * The function required Windows 2k/XP, otherwise it fails (gracefully). * * Return success: a valid open volume handle. * fail : INVALID_HANDLE_VALUE */ static HANDLE ntfs_device_win32_open_volume_for_partition(unsigned int drive_id, s64 part_offset, s64 part_length, int flags) { HANDLE vol_find_handle; TCHAR vol_name[MAX_PATH]; /* Make sure all the required imports exist. */ if (!fnFindFirstVolume || !fnFindNextVolume || !fnFindVolumeClose) { ntfs_log_trace("Required dll imports not found.\n"); return INVALID_HANDLE_VALUE; } /* Start iterating through volumes. */ ntfs_log_trace("Entering with drive_id=%d, part_offset=%lld, " "path_length=%lld, flags=%d.\n", drive_id, (unsigned long long)part_offset, (unsigned long long)part_length, flags); vol_find_handle = fnFindFirstVolume(vol_name, MAX_PATH); /* If a valid handle could not be aquired, reply with "don't know". */ if (vol_find_handle == INVALID_HANDLE_VALUE) { ntfs_log_trace("FindFirstVolume failed.\n"); return INVALID_HANDLE_VALUE; } do { int vol_name_length; HANDLE handle; /* remove trailing '/' from vol_name */ #ifdef UNICODE vol_name_length = wcslen(vol_name); #else vol_name_length = strlen(vol_name); #endif if (vol_name_length>0) vol_name[vol_name_length-1]=0; ntfs_log_debug("Processing %s.\n", vol_name); /* open the file */ handle = CreateFile(vol_name, ntfs_device_unix_status_flags_to_win32(flags), FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); if (handle != INVALID_HANDLE_VALUE) { DWORD bytesReturned; #define EXTENTS_SIZE sizeof(VOLUME_DISK_EXTENTS) + 9 * sizeof(DISK_EXTENT) char extents[EXTENTS_SIZE]; /* Check physical locations. */ if (DeviceIoControl(handle, IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS, NULL, 0, extents, EXTENTS_SIZE, &bytesReturned, NULL)) { if (((VOLUME_DISK_EXTENTS *)extents)-> NumberOfDiskExtents == 1) { DISK_EXTENT *extent = &(( VOLUME_DISK_EXTENTS *) extents)->Extents[0]; if ((extent->DiskNumber==drive_id) && (extent->StartingOffset. QuadPart==part_offset) && (extent-> ExtentLength.QuadPart == part_length)) { /* * Eureka! (Archimedes, 287 BC, * "I have found it!") */ fnFindVolumeClose( vol_find_handle); return handle; } } } } else ntfs_log_trace("getExtents() Failed.\n"); } while (fnFindNextVolume(vol_find_handle, vol_name, MAX_PATH)); /* End of iteration through volumes. */ ntfs_log_trace("Closing, volume was not found.\n"); fnFindVolumeClose(vol_find_handle); return INVALID_HANDLE_VALUE; } /** * ntfs_device_win32_find_partition - locates partition details by id. * @handle: HANDLE to the PhysicalDrive * @partition_id: the partition number to locate * @part_offset: pointer to where to put the offset to the partition * @part_length: pointer to where to put the length of the partition * @hidden_sectors: pointer to where to put the hidden sectors * * This function requires an open PhysicalDrive handle and a partition_id. * If a partition with the required id is found on the supplied device, * the partition attributes are returned back. * * Returns: TRUE if found, and sets the output parameters. * FALSE if not and errno is set to the error code. */ static BOOL ntfs_device_win32_find_partition(HANDLE handle, DWORD partition_id, s64 *part_offset, s64 *part_length, int *hidden_sectors) { DRIVE_LAYOUT_INFORMATION *drive_layout; unsigned int err, buf_size, part_count; DWORD i; /* * There is no way to know the required buffer, so if the ioctl fails, * try doubling the buffer size each time until the ioctl succeeds. */ part_count = 8; do { buf_size = sizeof(DRIVE_LAYOUT_INFORMATION) + part_count * sizeof(PARTITION_INFORMATION); drive_layout = (DRIVE_LAYOUT_INFORMATION*)ntfs_malloc(buf_size); if (!drive_layout) { errno = ENOMEM; return FALSE; } if (DeviceIoControl(handle, IOCTL_DISK_GET_DRIVE_LAYOUT, NULL, 0, (BYTE*)drive_layout, buf_size, &i, NULL)) break; err = GetLastError(); free(drive_layout); if (err != ERROR_INSUFFICIENT_BUFFER) { ntfs_log_trace("GetDriveLayout failed.\n"); errno = ntfs_w32error_to_errno(err); return FALSE; } ntfs_log_debug("More than %u partitions.\n", part_count); part_count <<= 1; if (part_count > 512) { ntfs_log_trace("GetDriveLayout failed: More than 512 " "partitions?\n"); errno = ENOBUFS; return FALSE; } } while (1); for (i = 0; i < drive_layout->PartitionCount; i++) { if (drive_layout->PartitionEntry[i].PartitionNumber == partition_id) { *part_offset = drive_layout->PartitionEntry[i]. StartingOffset.QuadPart; *part_length = drive_layout->PartitionEntry[i]. PartitionLength.QuadPart; *hidden_sectors = drive_layout->PartitionEntry[i]. HiddenSectors; free(drive_layout); return TRUE; } } free(drive_layout); errno = ENOENT; return FALSE; } /** * ntfs_device_win32_open_partition - open a partition via win32 API * @drive_id: drive to open * @partition_id: partition to open * @fd: win32 file device to return * @flags: unix open status flags * * Return 0 if o.k. * -1 if not, and errno set. * * When fails, fd contents may have not been preserved. */ static int ntfs_device_win32_open_partition(int drive_id, unsigned int partition_id, win32_fd *fd, int flags) { s64 part_start, part_length; HANDLE handle; int err, hidden_sectors; char drive_name[MAX_PATH]; sprintf(drive_name, "\\\\.\\PhysicalDrive%d", drive_id); /* Open the entire device without locking, ask questions later */ if ((err = ntfs_device_win32_simple_open_file(drive_name, &handle, flags, FALSE))) { /* error */ return err; } if (ntfs_device_win32_find_partition(handle, partition_id, &part_start, &part_length, &hidden_sectors)) { s64 tmp; HANDLE vol_handle = ntfs_device_win32_open_volume_for_partition( drive_id, part_start, part_length, flags); /* Store the drive geometry. */ ntfs_device_win32_getgeo(handle, fd); fd->handle = handle; fd->pos = 0; fd->part_start = part_start; fd->part_length = part_length; fd->part_hidden_sectors = hidden_sectors; fd->geo_sector_size = 512; fd->ntdll = FALSE; tmp = ntfs_device_win32_getntfssize(vol_handle); if (tmp > 0) fd->geo_size = tmp; else fd->geo_size = fd->part_length; if (vol_handle != INVALID_HANDLE_VALUE) { if (((flags & O_RDWR) == O_RDWR) && ntfs_device_win32_lock(vol_handle)) { CloseHandle(vol_handle); CloseHandle(handle); return -1; } fd->vol_handle = vol_handle; } else { if ((flags & O_RDWR) == O_RDWR) { /* Access if read-write, no volume found. */ ntfs_log_trace("Partitions containing Spanned/" "Mirrored volumes are not " "supported in R/W status " "yet.\n"); CloseHandle(handle); errno = EOPNOTSUPP; return -1; } fd->vol_handle = INVALID_HANDLE_VALUE; } return 0; } else { ntfs_log_debug("Partition %u not found on drive %d.\n", partition_id, drive_id); CloseHandle(handle); errno = ENODEV; return -1; } } /** * ntfs_device_win32_open - open a device * @dev: a pointer to the NTFS_DEVICE to open * @flags: unix open status flags * * @dev->d_name must hold the device name, the rest is ignored. * Supported flags are O_RDONLY, O_WRONLY and O_RDWR. * * If name is in format "(hd[0-9],[0-9])" then open a partition. * If name is in format "(hd[0-9])" then open a volume. * Otherwise open a file. */ static int ntfs_device_win32_open(struct ntfs_device *dev, int flags) { int drive_id = 0, numparams; unsigned int part = 0; char drive_char; win32_fd fd; int err; if (NDevOpen(dev)) { errno = EBUSY; return -1; } ntfs_device_win32_init_imports(); numparams = sscanf(dev->d_name, "/dev/hd%c%u", &drive_char, &part); if (!numparams && (dev->d_name[1] == ':') && (dev->d_name[2] == '\0')) { drive_char = dev->d_name[0]; numparams = 3; drive_id = toupper(drive_char) - 'A'; } switch (numparams) { case 0: ntfs_log_debug("win32_open(%s) -> file.\n", dev->d_name); err = ntfs_device_win32_open_file(dev->d_name, &fd, flags); break; case 1: ntfs_log_debug("win32_open(%s) -> drive %d.\n", dev->d_name, drive_id); err = ntfs_device_win32_open_drive(drive_id, &fd, flags); break; case 2: ntfs_log_debug("win32_open(%s) -> drive %d, part %u.\n", dev->d_name, drive_id, part); err = ntfs_device_win32_open_partition(drive_id, part, &fd, flags); break; case 3: ntfs_log_debug("win32_open(%s) -> drive %c:\n", dev->d_name, drive_char); err = ntfs_device_win32_open_lowlevel(drive_id, &fd, flags); break; default: ntfs_log_debug("win32_open(%s) -> unknwon file format.\n", dev->d_name); err = -1; } if (err) return err; ntfs_log_debug("win32_open(%s) -> %p, offset 0x%llx.\n", dev->d_name, dev, fd.part_start); /* Setup our read-only flag. */ if ((flags & O_RDWR) != O_RDWR) NDevSetReadOnly(dev); dev->d_private = (win32_fd*)ntfs_malloc(sizeof(win32_fd)); memcpy(dev->d_private, &fd, sizeof(win32_fd)); NDevSetOpen(dev); NDevClearDirty(dev); return 0; } /** * ntfs_device_win32_seek - change current logical file position * @dev: ntfs device obtained via ->open * @offset: required offset from the whence anchor * @whence: whence anchor specifying what @offset is relative to * * Return the new position on the volume on success and -1 on error with errno * set to the error code. * * @whence may be one of the following: * SEEK_SET - Offset is relative to file start. * SEEK_CUR - Offset is relative to current position. * SEEK_END - Offset is relative to end of file. */ static s64 ntfs_device_win32_seek(struct ntfs_device *dev, s64 offset, int whence) { s64 abs_ofs; win32_fd *fd = (win32_fd *)dev->d_private; ntfs_log_trace("seek offset = 0x%llx, whence = %d.\n", offset, whence); switch (whence) { case SEEK_SET: abs_ofs = offset; break; case SEEK_CUR: abs_ofs = fd->pos + offset; break; case SEEK_END: /* End of partition != end of disk. */ if (fd->part_length == -1) { ntfs_log_trace("Position relative to end of disk not " "implemented.\n"); errno = EOPNOTSUPP; return -1; } abs_ofs = fd->part_length + offset; break; default: ntfs_log_trace("Wrong mode %d.\n", whence); errno = EINVAL; return -1; } if ((abs_ofs < 0) || (fd->ntdll && (abs_ofs > fd->part_length))) { ntfs_log_trace("Seeking outsize seekable area.\n"); errno = EINVAL; return -1; } fd->pos = abs_ofs; return abs_ofs; } /** * ntfs_device_win32_pio - positioned low level i/o * @fd: win32 device descriptor obtained via ->open * @pos: at which position to do i/o from/to * @count: how many bytes should be transfered * @b: source/destination buffer * @write: TRUE if write transfer and FALSE if read transfer * * On success returns the number of bytes transfered (can be < @count) and on * error returns -1 and errno set. Transfer starts from position @pos on @fd. * * Notes: * - @pos, @buf, and @count must be aligned to geo_sector_size * - When dealing with volumes, a single call must not span both volume * and disk extents. * - Does not use/set @fd->pos. */ static s64 ntfs_device_win32_pio(win32_fd *fd, const s64 pos, const s64 count, void *rbuf, const void *wbuf) { LARGE_INTEGER li; HANDLE handle; DWORD bt; BOOL res; s64 bytes; ntfs_log_trace("pos = 0x%llx, count = 0x%llx, direction = %s.\n", (long long)pos, (long long)count, write ? "write" : "read"); li.QuadPart = pos; if (fd->vol_handle != INVALID_HANDLE_VALUE && pos < fd->geo_size) { ntfs_log_debug("Transfering via vol_handle.\n"); handle = fd->vol_handle; } else { ntfs_log_debug("Transfering via handle.\n"); handle = fd->handle; li.QuadPart += fd->part_start; } if (fd->ntdll) { IO_STATUS_BLOCK io_status; NTSTATUS res; LARGE_INTEGER offset; io_status.Status = STATUS_SUCCESS; io_status.Information = 0; offset.QuadPart = pos; if (wbuf) { res = NtWriteFile(fd->handle,(HANDLE)NULL, (PIO_APC_ROUTINE)NULL,(void*)NULL, &io_status, wbuf, count, &offset, (PULONG)NULL); } else { res = NtReadFile(fd->handle,(HANDLE)NULL, (PIO_APC_ROUTINE)NULL,(void*)NULL, &io_status, rbuf, count, &offset, (PULONG)NULL); } if (res == STATUS_SUCCESS) { bytes = io_status.Information; } else { bytes = -1; errno = ntfs_ntstatus_to_errno(res); } } else { if (!fnSetFilePointerEx(handle, li, NULL, FILE_BEGIN)) { errno = ntfs_w32error_to_errno(GetLastError()); ntfs_log_trace("SetFilePointer failed.\n"); return -1; } if (wbuf) res = WriteFile(handle, wbuf, count, &bt, NULL); else res = ReadFile(handle, rbuf, count, &bt, NULL); bytes = bt; if (!res) { errno = ntfs_w32error_to_errno(GetLastError()); ntfs_log_trace("%sFile() failed.\n", write ? "Write" : "Read"); return -1; } if (rbuf && !pos) { /* get the sector size from the boot sector */ char *boot = (char*)rbuf; fd->geo_sector_size = (boot[11] & 255) + ((boot[12] & 255) << 8); } } return bytes; } /** * ntfs_device_win32_pread_simple - positioned simple read * @fd: win32 device descriptor obtained via ->open * @pos: at which position to read from * @count: how many bytes should be read * @b: a pointer to where to put the contents * * On success returns the number of bytes read (can be < @count) and on error * returns -1 and errno set. Read starts from position @pos. * * Notes: * - @pos, @buf, and @count must be aligned to geo_sector_size. * - When dealing with volumes, a single call must not span both volume * and disk extents. * - Does not use/set @fd->pos. */ static inline s64 ntfs_device_win32_pread_simple(win32_fd *fd, const s64 pos, const s64 count, void *b) { return ntfs_device_win32_pio(fd, pos, count, b, (void*)NULL); } /** * ntfs_device_win32_read - read bytes from an ntfs device * @dev: ntfs device obtained via ->open * @b: pointer to where to put the contents * @count: how many bytes should be read * * On success returns the number of bytes actually read (can be < @count). * On error returns -1 with errno set. */ static s64 ntfs_device_win32_read(struct ntfs_device *dev, void *b, s64 count) { s64 old_pos, to_read, i, br = 0; win32_fd *fd = (win32_fd *)dev->d_private; BYTE *alignedbuffer; int old_ofs, ofs; old_pos = fd->pos; old_ofs = ofs = old_pos & (fd->geo_sector_size - 1); to_read = (ofs + count + fd->geo_sector_size - 1) & ~(s64)(fd->geo_sector_size - 1); /* Impose maximum of 2GB to be on the safe side. */ if (to_read > 0x80000000) { int delta = to_read - count; to_read = 0x80000000; count = to_read - delta; } ntfs_log_trace("fd = %p, b = %p, count = 0x%llx, pos = 0x%llx, " "ofs = %i, to_read = 0x%llx.\n", fd, b, (long long)count, (long long)old_pos, ofs, (long long)to_read); if (!((unsigned long)b & (fd->geo_sector_size - 1)) && !old_ofs && !(count & (fd->geo_sector_size - 1))) alignedbuffer = b; else { alignedbuffer = (BYTE *)VirtualAlloc(NULL, to_read, MEM_COMMIT, PAGE_READWRITE); if (!alignedbuffer) { errno = ntfs_w32error_to_errno(GetLastError()); ntfs_log_trace("VirtualAlloc failed for read.\n"); return -1; } } if (fd->vol_handle != INVALID_HANDLE_VALUE && old_pos < fd->geo_size) { s64 vol_to_read = fd->geo_size - old_pos; if (count > vol_to_read) { br = ntfs_device_win32_pread_simple(fd, old_pos & ~(s64)(fd->geo_sector_size - 1), ofs + vol_to_read, alignedbuffer); if (br == -1) goto read_error; to_read -= br; if (br < ofs) { br = 0; goto read_partial; } br -= ofs; fd->pos += br; ofs = fd->pos & (fd->geo_sector_size - 1); if (br != vol_to_read) goto read_partial; } } i = ntfs_device_win32_pread_simple(fd, fd->pos & ~(s64)(fd->geo_sector_size - 1), to_read, alignedbuffer + br); if (i == -1) { if (br) goto read_partial; goto read_error; } if (i < ofs) goto read_partial; i -= ofs; br += i; if (br > count) br = count; fd->pos = old_pos + br; read_partial: if (alignedbuffer != b) { memcpy((void*)b, alignedbuffer + old_ofs, br); VirtualFree(alignedbuffer, 0, MEM_RELEASE); } return br; read_error: if (alignedbuffer != b) VirtualFree(alignedbuffer, 0, MEM_RELEASE); return -1; } /** * ntfs_device_win32_close - close an open ntfs deivce * @dev: ntfs device obtained via ->open * * Return 0 if o.k. * -1 if not, and errno set. Note if error fd->vol_handle is trashed. */ static int ntfs_device_win32_close(struct ntfs_device *dev) { win32_fd *fd = (win32_fd *)dev->d_private; BOOL rvl; ntfs_log_trace("Closing device %p.\n", dev); if (!NDevOpen(dev)) { errno = EBADF; return -1; } if (fd->vol_handle != INVALID_HANDLE_VALUE) { if (!NDevReadOnly(dev)) { ntfs_device_win32_dismount(fd->vol_handle); ntfs_device_win32_unlock(fd->vol_handle); } if (!CloseHandle(fd->vol_handle)) ntfs_log_trace("CloseHandle() failed for volume.\n"); } if (fd->ntdll) { ntfs_device_win32_setlock(fd->handle,FSCTL_UNLOCK_VOLUME); rvl = NtClose(fd->handle) == STATUS_SUCCESS; } else rvl = CloseHandle(fd->handle); NDevClearOpen(dev); free(fd); if (!rvl) { errno = ntfs_w32error_to_errno(GetLastError()); if (fd->ntdll) ntfs_log_trace("NtClose() failed.\n"); else ntfs_log_trace("CloseHandle() failed.\n"); return -1; } return 0; } /** * ntfs_device_win32_sync - flush write buffers to disk * @dev: ntfs device obtained via ->open * * Return 0 if o.k. * -1 if not, and errno set. * * Note: Volume syncing works differently in windows. * Disk cannot be synced in windows. */ static int ntfs_device_win32_sync(struct ntfs_device *dev) { int err = 0; BOOL to_clear = TRUE; if (!NDevReadOnly(dev) && NDevDirty(dev)) { win32_fd *fd = (win32_fd *)dev->d_private; if ((fd->vol_handle != INVALID_HANDLE_VALUE) && !FlushFileBuffers(fd->vol_handle)) { to_clear = FALSE; err = ntfs_w32error_to_errno(GetLastError()); } if (!FlushFileBuffers(fd->handle)) { to_clear = FALSE; if (!err) err = ntfs_w32error_to_errno(GetLastError()); } if (!to_clear) { ntfs_log_trace("Could not sync.\n"); errno = err; return -1; } NDevClearDirty(dev); } return 0; } /** * ntfs_device_win32_pwrite_simple - positioned simple write * @fd: win32 device descriptor obtained via ->open * @pos: at which position to write to * @count: how many bytes should be written * @b: a pointer to the data to write * * On success returns the number of bytes written and on error returns -1 and * errno set. Write starts from position @pos. * * Notes: * - @pos, @buf, and @count must be aligned to geo_sector_size. * - When dealing with volumes, a single call must not span both volume * and disk extents. * - Does not use/set @fd->pos. */ static inline s64 ntfs_device_win32_pwrite_simple(win32_fd *fd, const s64 pos, const s64 count, const void *b) { return ntfs_device_win32_pio(fd, pos, count, (void*)NULL, b); } /** * ntfs_device_win32_write - write bytes to an ntfs device * @dev: ntfs device obtained via ->open * @b: pointer to the data to write * @count: how many bytes should be written * * On success returns the number of bytes actually written. * On error returns -1 with errno set. */ static s64 ntfs_device_win32_write(struct ntfs_device *dev, const void *b, s64 count) { s64 old_pos, to_write, i, bw = 0; win32_fd *fd = (win32_fd *)dev->d_private; const BYTE *alignedbuffer; BYTE *readbuffer; int old_ofs, ofs; old_pos = fd->pos; old_ofs = ofs = old_pos & (fd->geo_sector_size - 1); to_write = (ofs + count + fd->geo_sector_size - 1) & ~(s64)(fd->geo_sector_size - 1); /* Impose maximum of 2GB to be on the safe side. */ if (to_write > 0x80000000) { int delta = to_write - count; to_write = 0x80000000; count = to_write - delta; } ntfs_log_trace("fd = %p, b = %p, count = 0x%llx, pos = 0x%llx, " "ofs = %i, to_write = 0x%llx.\n", fd, b, (long long)count, (long long)old_pos, ofs, (long long)to_write); if (NDevReadOnly(dev)) { ntfs_log_trace("Can't write on a R/O device.\n"); errno = EROFS; return -1; } if (!count) return 0; NDevSetDirty(dev); readbuffer = (BYTE*)NULL; if (!((unsigned long)b & (fd->geo_sector_size - 1)) && !old_ofs && !(count & (fd->geo_sector_size - 1))) alignedbuffer = (const BYTE *)b; else { s64 end; readbuffer = (BYTE *)VirtualAlloc(NULL, to_write, MEM_COMMIT, PAGE_READWRITE); if (!readbuffer) { errno = ntfs_w32error_to_errno(GetLastError()); ntfs_log_trace("VirtualAlloc failed for write.\n"); return -1; } /* Read first sector if start of write not sector aligned. */ if (ofs) { i = ntfs_device_win32_pread_simple(fd, old_pos & ~(s64)(fd->geo_sector_size - 1), fd->geo_sector_size, readbuffer); if (i != fd->geo_sector_size) { if (i >= 0) errno = EIO; goto write_error; } } /* * Read last sector if end of write not sector aligned and last * sector is either not the same as the first sector or it is * the same as the first sector but this has not been read in * yet, i.e. the start of the write is sector aligned. */ end = old_pos + count; if ((end & (fd->geo_sector_size - 1)) && ((to_write > fd->geo_sector_size) || !ofs)) { i = ntfs_device_win32_pread_simple(fd, end & ~(s64)(fd->geo_sector_size - 1), fd->geo_sector_size, readbuffer + to_write - fd->geo_sector_size); if (i != fd->geo_sector_size) { if (i >= 0) errno = EIO; goto write_error; } } /* Copy the data to be written into @readbuffer. */ memcpy(readbuffer + ofs, b, count); alignedbuffer = readbuffer; } if (fd->vol_handle != INVALID_HANDLE_VALUE && old_pos < fd->geo_size) { s64 vol_to_write = fd->geo_size - old_pos; if (count > vol_to_write) { bw = ntfs_device_win32_pwrite_simple(fd, old_pos & ~(s64)(fd->geo_sector_size - 1), ofs + vol_to_write, alignedbuffer); if (bw == -1) goto write_error; to_write -= bw; if (bw < ofs) { bw = 0; goto write_partial; } bw -= ofs; fd->pos += bw; ofs = fd->pos & (fd->geo_sector_size - 1); if (bw != vol_to_write) goto write_partial; } } i = ntfs_device_win32_pwrite_simple(fd, fd->pos & ~(s64)(fd->geo_sector_size - 1), to_write, alignedbuffer + bw); if (i == -1) { if (bw) goto write_partial; goto write_error; } if (i < ofs) goto write_partial; i -= ofs; bw += i; if (bw > count) bw = count; fd->pos = old_pos + bw; write_partial: if (readbuffer) VirtualFree(readbuffer, 0, MEM_RELEASE); return bw; write_error: bw = -1; goto write_partial; } /** * ntfs_device_win32_stat - get a unix-like stat structure for an ntfs device * @dev: ntfs device obtained via ->open * @buf: pointer to the stat structure to fill * * Note: Only st_mode, st_size, and st_blocks are filled. * * Return 0 if o.k. * -1 if not and errno set. in this case handle is trashed. */ static int ntfs_device_win32_stat(struct ntfs_device *dev, struct stat *buf) { win32_fd *fd = (win32_fd *)dev->d_private; mode_t st_mode; if ((dev->d_name[1] == ':') && (dev->d_name[2] == '\0')) st_mode = S_IFBLK; else switch (GetFileType(fd->handle)) { case FILE_TYPE_CHAR: st_mode = S_IFCHR; break; case FILE_TYPE_DISK: st_mode = S_IFREG; break; case FILE_TYPE_PIPE: st_mode = S_IFIFO; break; default: st_mode = 0; } memset(buf, 0, sizeof(struct stat)); buf->st_mode = st_mode; buf->st_size = fd->part_length; if (buf->st_size != -1) buf->st_blocks = buf->st_size >> 9; else buf->st_size = 0; return 0; } #ifdef HDIO_GETGEO /** * ntfs_win32_hdio_getgeo - get drive geometry * @dev: ntfs device obtained via ->open * @argp: pointer to where to put the output * * Note: Works on windows NT/2k/XP only. * * Return 0 if o.k. * -1 if not, and errno set. Note if error fd->handle is trashed. */ static __inline__ int ntfs_win32_hdio_getgeo(struct ntfs_device *dev, struct hd_geometry *argp) { win32_fd *fd = (win32_fd *)dev->d_private; argp->heads = fd->geo_heads; argp->sectors = fd->geo_sectors; argp->cylinders = fd->geo_cylinders; argp->start = fd->part_hidden_sectors; return 0; } #endif /** * ntfs_win32_blksszget - get block device sector size * @dev: ntfs device obtained via ->open * @argp: pointer to where to put the output * * Note: Works on windows NT/2k/XP only. * * Return 0 if o.k. * -1 if not, and errno set. Note if error fd->handle is trashed. */ static __inline__ int ntfs_win32_blksszget(struct ntfs_device *dev,int *argp) { win32_fd *fd = (win32_fd *)dev->d_private; DWORD bytesReturned; DISK_GEOMETRY dg; if (DeviceIoControl(fd->handle, IOCTL_DISK_GET_DRIVE_GEOMETRY, NULL, 0, &dg, sizeof(DISK_GEOMETRY), &bytesReturned, NULL)) { /* success */ *argp = dg.BytesPerSector; return 0; } errno = ntfs_w32error_to_errno(GetLastError()); ntfs_log_trace("GET_DRIVE_GEOMETRY failed.\n"); return -1; } static int ntfs_device_win32_ioctl(struct ntfs_device *dev, unsigned long request, void *argp) { #if defined(BLKGETSIZE) | defined(BLKGETSIZE64) win32_fd *fd = (win32_fd *)dev->d_private; #endif ntfs_log_trace("win32_ioctl(0x%lx) called.\n", request); switch (request) { #if defined(BLKGETSIZE) case BLKGETSIZE: ntfs_log_debug("BLKGETSIZE detected.\n"); if (fd->part_length >= 0) { *(int *)argp = (int)(fd->part_length / 512); return 0; } errno = EOPNOTSUPP; return -1; #endif #if defined(BLKGETSIZE64) case BLKGETSIZE64: ntfs_log_debug("BLKGETSIZE64 detected.\n"); if (fd->part_length >= 0) { *(s64 *)argp = fd->part_length; return 0; } errno = EOPNOTSUPP; return -1; #endif #ifdef HDIO_GETGEO case HDIO_GETGEO: ntfs_log_debug("HDIO_GETGEO detected.\n"); return ntfs_win32_hdio_getgeo(dev, (struct hd_geometry *)argp); #endif #ifdef BLKSSZGET case BLKSSZGET: ntfs_log_debug("BLKSSZGET detected.\n"); if (fd && !fd->ntdll) { *(int*)argp = fd->geo_sector_size; return (0); } else return ntfs_win32_blksszget(dev, (int *)argp); #endif #ifdef BLKBSZSET case BLKBSZSET: ntfs_log_debug("BLKBSZSET detected.\n"); /* Nothing to do on Windows. */ return 0; #endif default: ntfs_log_debug("unimplemented ioctl 0x%lx.\n", request); errno = EOPNOTSUPP; return -1; } } static s64 ntfs_device_win32_pread(struct ntfs_device *dev, void *b, s64 count, s64 offset) { s64 got; win32_fd *fd; /* read the fast way if sector aligned */ fd = (win32_fd*)dev->d_private; if (!((count | offset) & (fd->geo_sector_size - 1))) { got = ntfs_device_win32_pio(fd, offset, count, b, (void*)NULL); } else { if (ntfs_device_win32_seek(dev, offset, 0) == -1) got = 0; else got = ntfs_device_win32_read(dev, b, count); } return (got); } static s64 ntfs_device_win32_pwrite(struct ntfs_device *dev, const void *b, s64 count, s64 offset) { s64 put; win32_fd *fd; /* write the fast way if sector aligned */ fd = (win32_fd*)dev->d_private; if (!((count | offset) & (fd->geo_sector_size - 1))) { put = ntfs_device_win32_pio(fd, offset, count, (void*)NULL, b); } else { if (ntfs_device_win32_seek(dev, offset, 0) == -1) put = 0; else put = ntfs_device_win32_write(dev, b, count); } return (put); } struct ntfs_device_operations ntfs_device_win32_io_ops = { .open = ntfs_device_win32_open, .close = ntfs_device_win32_close, .seek = ntfs_device_win32_seek, .read = ntfs_device_win32_read, .write = ntfs_device_win32_write, .pread = ntfs_device_win32_pread, .pwrite = ntfs_device_win32_pwrite, .sync = ntfs_device_win32_sync, .stat = ntfs_device_win32_stat, .ioctl = ntfs_device_win32_ioctl }; /* * Mark an open file as sparse * * This is only called by ntfsclone when cloning a volume to a file. * The argument is the target file, not a volume. * * Returns 0 if successful. */ int ntfs_win32_set_sparse(int fd) { BOOL ok; HANDLE handle; DWORD bytes; handle = get_osfhandle(fd); if (handle == INVALID_HANDLE_VALUE) ok = FALSE; else ok = DeviceIoControl(handle, FSCTL_SET_SPARSE, (void*)NULL, 0, (void*)NULL, 0, &bytes, (LPOVERLAPPED)NULL); return (!ok); } /* * Resize an open file * * This is only called by ntfsclone when cloning a volume to a file. * The argument must designate a file, not a volume. * * Returns 0 if successful. */ static int win32_ftruncate(HANDLE handle, s64 size) { BOOL ok; LONG hsize, lsize; LONG ohsize, olsize; if (handle == INVALID_HANDLE_VALUE) ok = FALSE; else { SetLastError(NO_ERROR); /* save original position */ ohsize = 0; olsize = SetFilePointer(handle, 0, &ohsize, 1); hsize = size >> 32; lsize = size & 0xffffffff; ok = (SetFilePointer(handle, lsize, &hsize, 0) == (DWORD)lsize) && (GetLastError() == NO_ERROR) && SetEndOfFile(handle); /* restore original position, even if above failed */ SetFilePointer(handle, olsize, &ohsize, 0); if (GetLastError() != NO_ERROR) ok = FALSE; } if (!ok) errno = EINVAL; return (ok ? 0 : -1); } int ntfs_device_win32_ftruncate(struct ntfs_device *dev, s64 size) { win32_fd *fd; int ret; ret = -1; fd = (win32_fd*)dev->d_private; if (fd && !fd->ntdll) ret = win32_ftruncate(fd->handle, size); return (ret); } int ntfs_win32_ftruncate(int fd, s64 size) { int ret; HANDLE handle; handle = get_osfhandle(fd); ret = win32_ftruncate(handle, size); return (ret); } ntfs-3g-2026.2.25/libntfs-3g/ea.c0000664000175000017500000003056615152260173011513 /** * ea.c - Processing of EA's * * This module is part of ntfs-3g library * * Copyright (c) 2014-2021 Jean-Pierre Andre * * This program/include file 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/include file 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_STDIO_H #include #endif #ifdef HAVE_STDLIB_H #include #endif #ifdef HAVE_STRING_H #include #endif #ifdef HAVE_FCNTL_H #include #endif #ifdef HAVE_UNISTD_H #include #endif #ifdef HAVE_ERRNO_H #include #endif #ifdef MAJOR_IN_MKDEV #include #endif #ifdef MAJOR_IN_SYSMACROS #include #endif #include "types.h" #include "param.h" #include "layout.h" #include "attrib.h" #include "index.h" #include "dir.h" #include "ea.h" #include "misc.h" #include "logging.h" #include "xattrs.h" static const char lxdev[] = "$LXDEV"; static const char lxmod[] = "$LXMOD"; /* * Create a needed attribute (EA or EA_INFORMATION) * * Returns 0 if successful, * -1 otherwise, with errno indicating why it failed. */ static int ntfs_need_ea(ntfs_inode *ni, ATTR_TYPES type, int size, int flags) { u8 dummy; int res; res = 0; if (!ntfs_attr_exist(ni,type, AT_UNNAMED,0)) { if (!(flags & XATTR_REPLACE)) { /* * no needed attribute : add one, * apparently, this does not feed the new value in * Note : NTFS version must be >= 3 */ if (ni->vol->major_ver >= 3) { res = ntfs_attr_add(ni, type, AT_UNNAMED,0,&dummy,(s64)size); if (!res) { NInoFileNameSetDirty(ni); } NInoSetDirty(ni); } else { errno = EOPNOTSUPP; res = -1; } } else { errno = ENODATA; res = -1; } } return (res); } /* * Restore the old EA_INFORMATION or delete the current one, * when EA cannot be updated. * * As this is used in the context of some other error, the caller * is responsible for returning the proper error, and errno is * left unchanged. * Only double errors are logged here. */ static void restore_ea_info(ntfs_attr *nai, const EA_INFORMATION *old_ea_info) { s64 written; int olderrno; olderrno = errno; if (old_ea_info) { written = ntfs_attr_pwrite(nai, 0, sizeof(EA_INFORMATION), old_ea_info); if ((size_t)written != sizeof(EA_INFORMATION)) { ntfs_log_error("Could not restore the EA_INFORMATION," " possible inconsistency in inode %lld\n", (long long)nai->ni->mft_no); } } else { if (ntfs_attr_rm(nai)) { ntfs_log_error("Could not delete the EA_INFORMATION," " possible inconsistency in inode %lld\n", (long long)nai->ni->mft_no); } } errno = olderrno; } /* * Update both EA and EA_INFORMATION */ static int ntfs_update_ea(ntfs_inode *ni, const char *value, size_t size, const EA_INFORMATION *ea_info, const EA_INFORMATION *old_ea_info) { ntfs_attr *na; ntfs_attr *nai; int res; res = 0; nai = ntfs_attr_open(ni, AT_EA_INFORMATION, AT_UNNAMED, 0); if (nai) { na = ntfs_attr_open(ni, AT_EA, AT_UNNAMED, 0); if (na) { /* * Set EA_INFORMATION first, it is easier to * restore the old value, if setting EA fails. */ if (ntfs_attr_pwrite(nai, 0, sizeof(EA_INFORMATION), ea_info) != (s64)sizeof(EA_INFORMATION)) { res = -errno; } else { if (((na->data_size > (s64)size) && ntfs_attr_truncate(na, size)) || (ntfs_attr_pwrite(na, 0, size, value) != (s64)size)) { res = -errno; if (old_ea_info) restore_ea_info(nai, old_ea_info); } } ntfs_attr_close(na); } ntfs_attr_close(nai); } else { res = -errno; } return (res); } /* * Return the existing EA * * The EA_INFORMATION is not examined and the consistency of the * existing EA is not checked. * * If successful, the full attribute is returned unchanged * and its size is returned. * If the designated buffer is too small, the needed size is * returned, and the buffer is left unchanged. * If there is an error, a negative value is returned and errno * is set according to the error. */ int ntfs_get_ntfs_ea(ntfs_inode *ni, char *value, size_t size) { s64 ea_size; void *ea_buf; int res = 0; if (ntfs_attr_exist(ni, AT_EA, AT_UNNAMED, 0)) { ea_buf = ntfs_attr_readall(ni, AT_EA, (ntfschar*)NULL, 0, &ea_size); if (ea_buf) { if (value && (ea_size <= (s64)size)) memcpy(value, ea_buf, ea_size); free(ea_buf); res = ea_size; } else { ntfs_log_error("Failed to read EA from inode %lld\n", (long long)ni->mft_no); errno = ENODATA; res = -errno; } } else { errno = ENODATA; res = -errno; } return (res); } /* * Set a new EA, and set EA_INFORMATION accordingly * * This is roughly the same as ZwSetEaFile() on Windows, however * the "offset to next" of the last EA should not be cleared. * * Consistency of the new EA is first checked. * * EA_INFORMATION is set first, and it is restored to its former * state if setting EA fails. * * Returns 0 if successful * a negative value if an error occurred. */ int ntfs_set_ntfs_ea(ntfs_inode *ni, const char *value, size_t size, int flags) { EA_INFORMATION ea_info; EA_INFORMATION *old_ea_info; s64 old_ea_size; int res; size_t offs; size_t nextoffs; BOOL ok; int ea_count; int ea_packed; const EA_ATTR *p_ea; res = -1; if (value && (size > 0)) { /* do consistency checks */ offs = 0; ok = TRUE; ea_count = 0; ea_packed = 0; nextoffs = 0; while (ok && (offs < size)) { p_ea = (const EA_ATTR*)&value[offs]; nextoffs = offs + le32_to_cpu(p_ea->next_entry_offset); /* null offset to next not allowed */ ok = (nextoffs > offs) && (nextoffs <= size) && !(nextoffs & 3) && p_ea->name_length /* zero sized value are allowed */ && ((offs + offsetof(EA_ATTR,name) + p_ea->name_length + 1 + le16_to_cpu(p_ea->value_length)) <= nextoffs) && ((offs + offsetof(EA_ATTR,name) + p_ea->name_length + 1 + le16_to_cpu(p_ea->value_length)) >= (nextoffs - 3)) && !p_ea->name[p_ea->name_length]; /* name not checked, as chkdsk accepts any chars */ if (ok) { if (p_ea->flags & NEED_EA) ea_count++; /* * Assume ea_packed includes : * 4 bytes for header (flags and lengths) * + name length + 1 * + value length */ ea_packed += 5 + p_ea->name_length + le16_to_cpu(p_ea->value_length); offs = nextoffs; } } /* * EA and REPARSE_POINT compatibility not checked any more, * required by Windows 10, but having both may lead to * problems with earlier versions. */ if (ok) { ea_info.ea_length = cpu_to_le16(ea_packed); ea_info.need_ea_count = cpu_to_le16(ea_count); ea_info.ea_query_length = cpu_to_le32(nextoffs); old_ea_size = 0; old_ea_info = NULL; /* Try to save the old EA_INFORMATION */ if (ntfs_attr_exist(ni, AT_EA_INFORMATION, AT_UNNAMED, 0)) { old_ea_info = ntfs_attr_readall(ni, AT_EA_INFORMATION, (ntfschar*)NULL, 0, &old_ea_size); } /* * no EA or EA_INFORMATION : add them */ if (!ntfs_need_ea(ni, AT_EA_INFORMATION, sizeof(EA_INFORMATION), flags) && !ntfs_need_ea(ni, AT_EA, 0, flags)) { res = ntfs_update_ea(ni, value, size, &ea_info, old_ea_info); } else { res = -errno; } if (old_ea_info) free(old_ea_info); } else { errno = EINVAL; res = -errno; } } else { errno = EINVAL; res = -errno; } return (res); } /* * Remove the EA (including EA_INFORMATION) * * EA_INFORMATION is removed first, and it is restored to its former * state if removing EA fails. * * Returns 0, or -1 if there is a problem */ int ntfs_remove_ntfs_ea(ntfs_inode *ni) { EA_INFORMATION *old_ea_info; s64 old_ea_size; int res; ntfs_attr *na; ntfs_attr *nai; res = 0; if (ni) { /* * open and delete the EA_INFORMATION and the EA */ nai = ntfs_attr_open(ni, AT_EA_INFORMATION, AT_UNNAMED, 0); if (nai) { na = ntfs_attr_open(ni, AT_EA, AT_UNNAMED, 0); if (na) { /* Try to save the old EA_INFORMATION */ old_ea_info = ntfs_attr_readall(ni, AT_EA_INFORMATION, (ntfschar*)NULL, 0, &old_ea_size); res = ntfs_attr_rm(na); NInoFileNameSetDirty(ni); if (!res) { res = ntfs_attr_rm(nai); if (res && old_ea_info) { /* * Failed to remove the EA, try to * restore the EA_INFORMATION */ restore_ea_info(nai, old_ea_info); } } else { ntfs_log_error("Failed to remove the" " EA_INFORMATION from inode %lld\n", (long long)ni->mft_no); } free(old_ea_info); ntfs_attr_close(na); } else { /* EA_INFORMATION present, but no EA */ res = ntfs_attr_rm(nai); NInoFileNameSetDirty(ni); } ntfs_attr_close(nai); } else { errno = ENODATA; res = -1; } NInoSetDirty(ni); } else { errno = EINVAL; res = -1; } return (res ? -1 : 0); } /* * Check for the presence of an EA "$LXDEV" (used by WSL) * and return its value as a device address * * Returns zero if successful * -1 if failed, with errno set */ int ntfs_ea_check_wsldev(ntfs_inode *ni, dev_t *rdevp) { const EA_ATTR *p_ea; int bufsize; char *buf; int lth; int res; int offset; int next; BOOL found; struct { le32 major; le32 minor; } device; res = -EOPNOTSUPP; bufsize = 256; /* expected to be enough */ buf = (char*)malloc(bufsize); if (buf) { lth = ntfs_get_ntfs_ea(ni, buf, bufsize); /* retry if short buf */ if (lth > bufsize) { free(buf); bufsize = lth; buf = (char*)malloc(bufsize); if (buf) lth = ntfs_get_ntfs_ea(ni, buf, bufsize); } } if (buf && (lth > 0) && (lth <= bufsize)) { offset = 0; found = FALSE; do { p_ea = (const EA_ATTR*)&buf[offset]; next = le32_to_cpu(p_ea->next_entry_offset); found = ((next > (int)(sizeof(lxdev) + sizeof(device))) && (p_ea->name_length == (sizeof(lxdev) - 1)) && (p_ea->value_length == const_cpu_to_le16(sizeof(device))) && !memcmp(p_ea->name, lxdev, sizeof(lxdev))); if (!found) offset += next; } while (!found && (next > 0) && (offset < lth)); if (found) { /* beware of alignment */ memcpy(&device, &p_ea->name[p_ea->name_length + 1], sizeof(device)); *rdevp = makedev(le32_to_cpu(device.major), le32_to_cpu(device.minor)); res = 0; } } free(buf); return (res); } int ntfs_ea_set_wsl_not_symlink(ntfs_inode *ni, mode_t type, dev_t dev) { le32 mode; struct { le32 major; le32 minor; } device; struct EA_WSL { struct EA_LXMOD { /* always inserted */ EA_ATTR base; char name[sizeof(lxmod)]; char value[sizeof(mode)]; char stuff[3 & -(sizeof(lxmod) + sizeof(mode))]; } mod; struct EA_LXDEV { /* char or block devices only */ EA_ATTR base; char name[sizeof(lxdev)]; char value[sizeof(device)]; char stuff[3 & -(sizeof(lxdev) + sizeof(device))]; } dev; } attr; int len; int res; memset(&attr, 0, sizeof(attr)); mode = cpu_to_le32((u32)(type | 0644)); attr.mod.base.next_entry_offset = const_cpu_to_le32(sizeof(attr.mod)); attr.mod.base.flags = 0; attr.mod.base.name_length = sizeof(lxmod) - 1; attr.mod.base.value_length = const_cpu_to_le16(sizeof(mode)); memcpy(attr.mod.name, lxmod, sizeof(lxmod)); memcpy(attr.mod.value, &mode, sizeof(mode)); len = sizeof(attr.mod); if (S_ISCHR(type) || S_ISBLK(type)) { device.major = cpu_to_le32(major(dev)); device.minor = cpu_to_le32(minor(dev)); attr.dev.base.next_entry_offset = const_cpu_to_le32(sizeof(attr.dev)); attr.dev.base.flags = 0; attr.dev.base.name_length = sizeof(lxdev) - 1; attr.dev.base.value_length = const_cpu_to_le16(sizeof(device)); memcpy(attr.dev.name, lxdev, sizeof(lxdev)); memcpy(attr.dev.value, &device, sizeof(device)); len += sizeof(attr.dev); } res = ntfs_set_ntfs_ea(ni, (char*)&attr, len, 0); return (res); } ntfs-3g-2026.2.25/libntfs-3g/index.c0000664000175000017500000015001015152260173012220 /** * index.c - NTFS index handling. Originated from the Linux-NTFS project. * * Copyright (c) 2004-2005 Anton Altaparmakov * Copyright (c) 2004-2005 Richard Russon * Copyright (c) 2005-2006 Yura Pakhuchiy * Copyright (c) 2005-2008 Szabolcs Szakacsits * Copyright (c) 2007-2021 Jean-Pierre Andre * * This program/include file 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/include file 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_STDLIB_H #include #endif #ifdef HAVE_STRING_H #include #endif #ifdef HAVE_ERRNO_H #include #endif #include "attrib.h" #include "debug.h" #include "index.h" #include "collate.h" #include "mst.h" #include "dir.h" #include "logging.h" #include "bitmap.h" #include "reparse.h" #include "misc.h" /** * ntfs_index_entry_mark_dirty - mark an index entry dirty * @ictx: ntfs index context describing the index entry * * Mark the index entry described by the index entry context @ictx dirty. * * If the index entry is in the index root attribute, simply mark the inode * containing the index root attribute dirty. This ensures the mftrecord, and * hence the index root attribute, will be written out to disk later. * * If the index entry is in an index block belonging to the index allocation * attribute, set ib_dirty to TRUE, thus index block will be updated during * ntfs_index_ctx_put. */ void ntfs_index_entry_mark_dirty(ntfs_index_context *ictx) { if (ictx->is_in_root) ntfs_inode_mark_dirty(ictx->actx->ntfs_ino); else if (ictx->ib != NULL) { ictx->ib_dirty = TRUE; } } static s64 ntfs_ib_vcn_to_pos(ntfs_index_context *icx, VCN vcn) { return vcn << icx->vcn_size_bits; } static VCN ntfs_ib_pos_to_vcn(ntfs_index_context *icx, s64 pos) { return pos >> icx->vcn_size_bits; } static int ntfs_ib_write(ntfs_index_context *icx, INDEX_BLOCK *ib) { s64 ret, vcn = sle64_to_cpu(ib->index_block_vcn); ntfs_log_trace("vcn: %lld\n", (long long)vcn); ret = ntfs_attr_mst_pwrite(icx->ia_na, ntfs_ib_vcn_to_pos(icx, vcn), 1, icx->block_size, ib); if (ret != 1) { ntfs_log_perror("Failed to write index block %lld, inode %llu", (long long)vcn, (unsigned long long)icx->ni->mft_no); return STATUS_ERROR; } return STATUS_OK; } static int ntfs_icx_ib_write(ntfs_index_context *icx) { if (ntfs_ib_write(icx, icx->ib)) return STATUS_ERROR; icx->ib_dirty = FALSE; return STATUS_OK; } /** * ntfs_index_ctx_get - allocate and initialize a new index context * @ni: ntfs inode with which to initialize the context * @name: name of the which context describes * @name_len: length of the index name * * Allocate a new index context, initialize it with @ni and return it. * Return NULL if allocation failed. */ ntfs_index_context *ntfs_index_ctx_get(ntfs_inode *ni, ntfschar *name, u32 name_len) { ntfs_index_context *icx; ntfs_log_trace("Entering\n"); if (!ni) { errno = EINVAL; return NULL; } if (ni->nr_extents == -1) ni = ni->base_ni; icx = ntfs_calloc(sizeof(ntfs_index_context)); if (icx) *icx = (ntfs_index_context) { .ni = ni, .name = name, .name_len = name_len, }; return icx; } static void ntfs_index_ctx_free(ntfs_index_context *icx) { ntfs_log_trace("Entering\n"); if (!icx->bad_index && !icx->entry) return; if (icx->actx) ntfs_attr_put_search_ctx(icx->actx); if (!icx->is_in_root) { if (icx->ib_dirty) { /* FIXME: Error handling!!! */ ntfs_ib_write(icx, icx->ib); } free(icx->ib); } ntfs_attr_close(icx->ia_na); } /** * ntfs_index_ctx_put - release an index context * @icx: index context to free * * Release the index context @icx, releasing all associated resources. */ void ntfs_index_ctx_put(ntfs_index_context *icx) { ntfs_index_ctx_free(icx); free(icx); } /** * ntfs_index_ctx_reinit - reinitialize an index context * @icx: index context to reinitialize * * Reinitialize the index context @icx so it can be used for ntfs_index_lookup. */ void ntfs_index_ctx_reinit(ntfs_index_context *icx) { ntfs_log_trace("Entering\n"); ntfs_index_ctx_free(icx); *icx = (ntfs_index_context) { .ni = icx->ni, .name = icx->name, .name_len = icx->name_len, }; } static leVCN *ntfs_ie_get_vcn_addr(INDEX_ENTRY *ie) { return (leVCN *)((u8 *)ie + le16_to_cpu(ie->length) - sizeof(leVCN)); } /** * Get the subnode vcn to which the index entry refers. */ VCN ntfs_ie_get_vcn(INDEX_ENTRY *ie) { return sle64_to_cpup(ntfs_ie_get_vcn_addr(ie)); } static INDEX_ENTRY *ntfs_ie_get_first(INDEX_HEADER *ih) { return (INDEX_ENTRY *)((u8 *)ih + le32_to_cpu(ih->entries_offset)); } static INDEX_ENTRY *ntfs_ie_get_next(INDEX_ENTRY *ie) { return (INDEX_ENTRY *)((char *)ie + le16_to_cpu(ie->length)); } static u8 *ntfs_ie_get_end(INDEX_HEADER *ih) { /* FIXME: check if it isn't overflowing the index block size */ return (u8 *)ih + le32_to_cpu(ih->index_length); } static int ntfs_ie_end(INDEX_ENTRY *ie) { return ie->ie_flags & INDEX_ENTRY_END || !ie->length; } /** * Find the last entry in the index block */ static INDEX_ENTRY *ntfs_ie_get_last(INDEX_ENTRY *ie, char *ies_end) { ntfs_log_trace("Entering\n"); while ((char *)ie < ies_end && !ntfs_ie_end(ie)) ie = ntfs_ie_get_next(ie); return ie; } static INDEX_ENTRY *ntfs_ie_get_by_pos(INDEX_HEADER *ih, int pos) { INDEX_ENTRY *ie; ntfs_log_trace("pos: %d\n", pos); ie = ntfs_ie_get_first(ih); while (pos-- > 0) ie = ntfs_ie_get_next(ie); return ie; } static INDEX_ENTRY *ntfs_ie_prev(INDEX_HEADER *ih, INDEX_ENTRY *ie) { INDEX_ENTRY *ie_prev = NULL; INDEX_ENTRY *tmp; ntfs_log_trace("Entering\n"); tmp = ntfs_ie_get_first(ih); while (tmp != ie) { ie_prev = tmp; tmp = ntfs_ie_get_next(tmp); } return ie_prev; } char *ntfs_ie_filename_get(INDEX_ENTRY *ie) { FILE_NAME_ATTR *fn; fn = (FILE_NAME_ATTR *)&ie->key; return ntfs_attr_name_get(fn->file_name, fn->file_name_length); } void ntfs_ie_filename_dump(INDEX_ENTRY *ie) { char *s; s = ntfs_ie_filename_get(ie); ntfs_log_debug("'%s' ", s); ntfs_attr_name_free(&s); } void ntfs_ih_filename_dump(INDEX_HEADER *ih) { INDEX_ENTRY *ie; ntfs_log_trace("Entering\n"); ie = ntfs_ie_get_first(ih); while (!ntfs_ie_end(ie)) { ntfs_ie_filename_dump(ie); ie = ntfs_ie_get_next(ie); } } static int ntfs_ih_numof_entries(INDEX_HEADER *ih) { int n; INDEX_ENTRY *ie; u8 *end; ntfs_log_trace("Entering\n"); end = ntfs_ie_get_end(ih); ie = ntfs_ie_get_first(ih); for (n = 0; !ntfs_ie_end(ie) && (u8 *)ie < end; n++) ie = ntfs_ie_get_next(ie); return n; } static int ntfs_ih_one_entry(INDEX_HEADER *ih) { return (ntfs_ih_numof_entries(ih) == 1); } static int ntfs_ih_zero_entry(INDEX_HEADER *ih) { return (ntfs_ih_numof_entries(ih) == 0); } static void ntfs_ie_delete(INDEX_HEADER *ih, INDEX_ENTRY *ie) { u32 new_size; ntfs_log_trace("Entering\n"); new_size = le32_to_cpu(ih->index_length) - le16_to_cpu(ie->length); ih->index_length = cpu_to_le32(new_size); memmove(ie, (u8 *)ie + le16_to_cpu(ie->length), new_size - ((u8 *)ie - (u8 *)ih)); } static void ntfs_ie_set_vcn(INDEX_ENTRY *ie, VCN vcn) { *ntfs_ie_get_vcn_addr(ie) = cpu_to_sle64(vcn); } /** * Insert @ie index entry at @pos entry. Used @ih values should be ok already. */ static void ntfs_ie_insert(INDEX_HEADER *ih, INDEX_ENTRY *ie, INDEX_ENTRY *pos) { int ie_size = le16_to_cpu(ie->length); ntfs_log_trace("Entering\n"); ih->index_length = cpu_to_le32(le32_to_cpu(ih->index_length) + ie_size); memmove((u8 *)pos + ie_size, pos, le32_to_cpu(ih->index_length) - ((u8 *)pos - (u8 *)ih) - ie_size); memcpy(pos, ie, ie_size); } static INDEX_ENTRY *ntfs_ie_dup(INDEX_ENTRY *ie) { INDEX_ENTRY *dup; ntfs_log_trace("Entering\n"); dup = ntfs_malloc(le16_to_cpu(ie->length)); if (dup) memcpy(dup, ie, le16_to_cpu(ie->length)); return dup; } static INDEX_ENTRY *ntfs_ie_dup_novcn(INDEX_ENTRY *ie) { INDEX_ENTRY *dup; int size = le16_to_cpu(ie->length); ntfs_log_trace("Entering\n"); if (ie->ie_flags & INDEX_ENTRY_NODE) size -= sizeof(VCN); dup = ntfs_malloc(size); if (dup) { memcpy(dup, ie, size); dup->ie_flags &= ~INDEX_ENTRY_NODE; dup->length = cpu_to_le16(size); } return dup; } static INDEX_ROOT *ntfs_ir_lookup(ntfs_inode *ni, ntfschar *name, u32 name_len, ntfs_attr_search_ctx **ctx) { ATTR_RECORD *a; INDEX_ROOT *ir = NULL; ntfs_log_trace("Entering\n"); *ctx = ntfs_attr_get_search_ctx(ni, NULL); if (!*ctx) return NULL; if (ntfs_attr_lookup(AT_INDEX_ROOT, name, name_len, CASE_SENSITIVE, 0, NULL, 0, *ctx)) { ntfs_log_perror("Failed to lookup $INDEX_ROOT"); goto err_out; } a = (*ctx)->attr; if (a->non_resident) { errno = EINVAL; ntfs_log_perror("Non-resident $INDEX_ROOT detected"); goto err_out; } ir = (INDEX_ROOT *)((char *)a + le16_to_cpu(a->value_offset)); err_out: if (!ir) { ntfs_attr_put_search_ctx(*ctx); *ctx = NULL; } return ir; } static INDEX_ROOT *ntfs_ir_lookup2(ntfs_inode *ni, ntfschar *name, u32 len) { ntfs_attr_search_ctx *ctx; INDEX_ROOT *ir; ir = ntfs_ir_lookup(ni, name, len, &ctx); if (ir) ntfs_attr_put_search_ctx(ctx); return ir; } /* * Check the consistency of an index block * * Make sure the index block does not overflow from the index record. * The size of block is assumed to have been checked to be what is * defined in the index root. * * Returns 0 if no error was found * -1 otherwise (with errno unchanged) * * |<--->| offsetof(INDEX_BLOCK, index) * | |<--->| sizeof(INDEX_HEADER) * | | | * | | | seq index entries unused * |=====|=====|=====|===========================|==============| * | | | | | * | |<--------->| entries_offset | | * | |<---------------- index_length ------->| | * | |<--------------------- allocated_size --------------->| * |<--------------------------- block_size ------------------->| * * size(INDEX_HEADER) <= ent_offset < ind_length <= alloc_size < bk_size */ int ntfs_index_block_inconsistent(const INDEX_BLOCK *ib, u32 block_size, u64 inum, VCN vcn) { u32 ib_size = (unsigned)le32_to_cpu(ib->index.allocated_size) + offsetof(INDEX_BLOCK, index); if (!ntfs_is_indx_record(ib->magic)) { ntfs_log_error("Corrupt index block signature: vcn %lld inode " "%llu\n", (long long)vcn, (unsigned long long)inum); return -1; } if (sle64_to_cpu(ib->index_block_vcn) != vcn) { ntfs_log_error("Corrupt index block: VCN (%lld) is different " "from expected VCN (%lld) in inode %llu\n", (long long)sle64_to_cpu(ib->index_block_vcn), (long long)vcn, (unsigned long long)inum); return -1; } if (ib_size != block_size) { ntfs_log_error("Corrupt index block : VCN (%lld) of inode %llu " "has a size (%u) differing from the index " "specified size (%u)\n", (long long)vcn, (unsigned long long)inum, ib_size, (unsigned int)block_size); return -1; } if (le32_to_cpu(ib->index.entries_offset) < sizeof(INDEX_HEADER)) { ntfs_log_error("Invalid index entry offset in inode %lld\n", (unsigned long long)inum); return -1; } if (le32_to_cpu(ib->index.index_length) <= le32_to_cpu(ib->index.entries_offset)) { ntfs_log_error("No space for index entries in inode %lld\n", (unsigned long long)inum); return -1; } if (le32_to_cpu(ib->index.allocated_size) < le32_to_cpu(ib->index.index_length)) { ntfs_log_error("Index entries overflow in inode %lld\n", (unsigned long long)inum); return -1; } return (0); } /* * Check the consistency of an index entry * * Make sure data and key do not overflow from entry. * As a side effect, an entry with zero length is rejected. * This entry must be a full one (no INDEX_ENTRY_END flag), and its * length must have been checked beforehand to not overflow from the * index record. * * Returns 0 if no error was found * -1 otherwise (with errno unchanged) */ int ntfs_index_entry_inconsistent(const INDEX_ENTRY *ie, COLLATION_RULES collation_rule, u64 inum) { int ret; ret = 0; if (ie->key_length && ((le16_to_cpu(ie->key_length) + offsetof(INDEX_ENTRY, key)) > le16_to_cpu(ie->length))) { ntfs_log_error("Overflow from index entry in inode %lld\n", (long long)inum); ret = -1; } else if (collation_rule == COLLATION_FILE_NAME) { if ((offsetof(INDEX_ENTRY, key.file_name.file_name) + ie->key.file_name.file_name_length * sizeof(ntfschar)) > le16_to_cpu(ie->length)) { ntfs_log_error("File name overflow from index" " entry in inode %lld\n", (long long)inum); ret = -1; } } else { if (ie->data_length && ((le16_to_cpu(ie->data_offset) + le16_to_cpu(ie->data_length)) > le16_to_cpu(ie->length))) { ntfs_log_error("Data overflow from index" " entry in inode %lld\n", (long long)inum); ret = -1; } } return (ret); } /** * Find a key in the index block. * * Return values: * STATUS_OK with errno set to ESUCCESS if we know for sure that the * entry exists and @ie_out points to this entry. * STATUS_NOT_FOUND with errno set to ENOENT if we know for sure the * entry doesn't exist and @ie_out is the insertion point. * STATUS_KEEP_SEARCHING if we can't answer the above question and * @vcn will contain the node index block. * STATUS_ERROR with errno set if on unexpected error during lookup. */ static int ntfs_ie_lookup(const void *key, const int key_len, ntfs_index_context *icx, INDEX_HEADER *ih, VCN *vcn, INDEX_ENTRY **ie_out) { INDEX_ENTRY *ie; u8 *index_end; int rc, item = 0; ntfs_log_trace("Entering\n"); index_end = ntfs_ie_get_end(ih); /* * Loop until we exceed valid memory (corruption case) or until we * reach the last entry. */ for (ie = ntfs_ie_get_first(ih); ; ie = ntfs_ie_get_next(ie)) { /* Bounds checks. */ if ((u8 *)ie + sizeof(INDEX_ENTRY_HEADER) > index_end || (u8 *)ie + le16_to_cpu(ie->length) > index_end) { errno = ERANGE; ntfs_log_error("Index entry out of bounds in inode " "%llu.\n", (unsigned long long)icx->ni->mft_no); return STATUS_ERROR; } /* * The last entry cannot contain a key. It can however contain * a pointer to a child node in the B+tree so we just break out. */ if (ntfs_ie_end(ie)) break; /* * Not a perfect match, need to do full blown collation so we * know which way in the B+tree we have to go. */ if (!icx->collate) { ntfs_log_error("Collation function not defined\n"); errno = EOPNOTSUPP; return STATUS_ERROR; } /* Make sure key and data do not overflow from entry */ if (ntfs_index_entry_inconsistent(ie, icx->ir->collation_rule, icx->ni->mft_no)) { errno = EIO; return STATUS_ERROR; } rc = icx->collate(icx->ni->vol, key, key_len, &ie->key, le16_to_cpu(ie->key_length)); if (rc == NTFS_COLLATION_ERROR) { ntfs_log_error("Collation error. Perhaps a filename " "contains invalid characters?\n"); errno = ERANGE; return STATUS_ERROR; } /* * If @key collates before the key of the current entry, there * is definitely no such key in this index but we might need to * descend into the B+tree so we just break out of the loop. */ if (rc == -1) break; if (!rc) { *ie_out = ie; errno = 0; icx->parent_pos[icx->pindex] = item; return STATUS_OK; } item++; } /* * We have finished with this index block without success. Check for the * presence of a child node and if not present return with errno ENOENT, * otherwise we will keep searching in another index block. */ if (!(ie->ie_flags & INDEX_ENTRY_NODE)) { ntfs_log_debug("Index entry wasn't found.\n"); *ie_out = ie; errno = ENOENT; return STATUS_NOT_FOUND; } /* Get the starting vcn of the index_block holding the child node. */ *vcn = ntfs_ie_get_vcn(ie); if (*vcn < 0) { errno = EINVAL; ntfs_log_perror("Negative vcn in inode %llu", (unsigned long long)icx->ni->mft_no); return STATUS_ERROR; } ntfs_log_trace("Parent entry number %d\n", item); icx->parent_pos[icx->pindex] = item; return STATUS_KEEP_SEARCHING; } static ntfs_attr *ntfs_ia_open(ntfs_index_context *icx, ntfs_inode *ni) { ntfs_attr *na; na = ntfs_attr_open(ni, AT_INDEX_ALLOCATION, icx->name, icx->name_len); if (!na) { ntfs_log_perror("Failed to open index allocation of inode " "%llu", (unsigned long long)ni->mft_no); return NULL; } return na; } static int ntfs_ib_read(ntfs_index_context *icx, VCN vcn, INDEX_BLOCK *dst) { s64 pos, ret; ntfs_log_trace("vcn: %lld\n", (long long)vcn); pos = ntfs_ib_vcn_to_pos(icx, vcn); ret = ntfs_attr_mst_pread(icx->ia_na, pos, 1, icx->block_size, (u8 *)dst); if (ret != 1) { if (ret == -1) ntfs_log_perror("Failed to read index block"); else ntfs_log_error("Failed to read full index block at " "%lld\n", (long long)pos); return -1; } if (ntfs_index_block_inconsistent((INDEX_BLOCK*)dst, icx->block_size, icx->ia_na->ni->mft_no, vcn)) { errno = EIO; return -1; } return 0; } static int ntfs_icx_parent_inc(ntfs_index_context *icx) { icx->pindex++; if (icx->pindex >= MAX_PARENT_VCN) { errno = EOPNOTSUPP; ntfs_log_perror("Index is over %d level deep", MAX_PARENT_VCN); return STATUS_ERROR; } return STATUS_OK; } static int ntfs_icx_parent_dec(ntfs_index_context *icx) { icx->pindex--; if (icx->pindex < 0) { errno = EINVAL; ntfs_log_perror("Corrupt index pointer (%d)", icx->pindex); return STATUS_ERROR; } return STATUS_OK; } /** * ntfs_index_lookup - find a key in an index and return its index entry * @key: [IN] key for which to search in the index * @key_len: [IN] length of @key in bytes * @icx: [IN/OUT] context describing the index and the returned entry * * Before calling ntfs_index_lookup(), @icx must have been obtained from a * call to ntfs_index_ctx_get(). * * Look for the @key in the index specified by the index lookup context @icx. * ntfs_index_lookup() walks the contents of the index looking for the @key. * * If the @key is found in the index, 0 is returned and @icx is setup to * describe the index entry containing the matching @key. @icx->entry is the * index entry and @icx->data and @icx->data_len are the index entry data and * its length in bytes, respectively. * * If the @key is not found in the index, -1 is returned, errno = ENOENT and * @icx is setup to describe the index entry whose key collates immediately * after the search @key, i.e. this is the position in the index at which * an index entry with a key of @key would need to be inserted. * * If an error occurs return -1, set errno to error code and @icx is left * untouched. * * When finished with the entry and its data, call ntfs_index_ctx_put() to free * the context and other associated resources. * * If the index entry was modified, call ntfs_index_entry_mark_dirty() before * the call to ntfs_index_ctx_put() to ensure that the changes are written * to disk. */ int ntfs_index_lookup(const void *key, const int key_len, ntfs_index_context *icx) { VCN old_vcn, vcn; ntfs_inode *ni = icx->ni; INDEX_ROOT *ir; INDEX_ENTRY *ie; INDEX_BLOCK *ib = NULL; int ret, err = 0; ntfs_log_trace("Entering\n"); if (!key || key_len <= 0) { errno = EINVAL; ntfs_log_perror("key: %p key_len: %d", key, key_len); return -1; } ir = ntfs_ir_lookup(ni, icx->name, icx->name_len, &icx->actx); if (!ir) { if (errno == ENOENT) errno = EIO; return -1; } icx->block_size = le32_to_cpu(ir->index_block_size); if (icx->block_size < NTFS_BLOCK_SIZE) { errno = EINVAL; ntfs_log_perror("Index block size (%d) is smaller than the " "sector size (%d)", icx->block_size, NTFS_BLOCK_SIZE); goto err_out; } if (ni->vol->cluster_size <= icx->block_size) icx->vcn_size_bits = ni->vol->cluster_size_bits; else icx->vcn_size_bits = NTFS_BLOCK_SIZE_BITS; /* get the appropriate collation function */ icx->ir = ir; icx->collate = ntfs_get_collate_function(ir->collation_rule); if (!icx->collate) { err = errno = EOPNOTSUPP; ntfs_log_perror("Unknown collation rule 0x%x", (unsigned)le32_to_cpu(ir->collation_rule)); goto err_out; } old_vcn = VCN_INDEX_ROOT_PARENT; ret = ntfs_ie_lookup(key, key_len, icx, &ir->index, &vcn, &ie); if (ret == STATUS_ERROR) { err = errno; goto err_lookup; } icx->ir = ir; if (ret != STATUS_KEEP_SEARCHING) { /* STATUS_OK or STATUS_NOT_FOUND */ err = errno; icx->is_in_root = TRUE; icx->parent_vcn[icx->pindex] = old_vcn; goto done; } /* Child node present, descend into it. */ icx->ia_na = ntfs_ia_open(icx, ni); if (!icx->ia_na) goto err_out; ib = ntfs_malloc(icx->block_size); if (!ib) { err = errno; goto err_out; } descend_into_child_node: icx->parent_vcn[icx->pindex] = old_vcn; if (ntfs_icx_parent_inc(icx)) { err = errno; goto err_out; } old_vcn = vcn; ntfs_log_debug("Descend into node with VCN %lld\n", (long long)vcn); if (ntfs_ib_read(icx, vcn, ib)) goto err_out; ret = ntfs_ie_lookup(key, key_len, icx, &ib->index, &vcn, &ie); if (ret != STATUS_KEEP_SEARCHING) { err = errno; if (ret == STATUS_ERROR) goto err_out; /* STATUS_OK or STATUS_NOT_FOUND */ icx->is_in_root = FALSE; icx->ib = ib; icx->parent_vcn[icx->pindex] = vcn; goto done; } if ((ib->index.ih_flags & NODE_MASK) == LEAF_NODE) { ntfs_log_error("Index entry with child node found in a leaf " "node in inode 0x%llx.\n", (unsigned long long)ni->mft_no); goto err_out; } goto descend_into_child_node; err_out: icx->bad_index = TRUE; /* Force icx->* to be freed */ err_lookup: if (icx->actx) { ntfs_attr_put_search_ctx(icx->actx); icx->actx = NULL; } free(ib); if (!err) err = EIO; errno = err; return -1; done: icx->entry = ie; icx->data = (u8 *)ie + offsetof(INDEX_ENTRY, key); icx->data_len = le16_to_cpu(ie->key_length); ntfs_log_trace("Done.\n"); if (err) { errno = err; return -1; } return 0; } static INDEX_BLOCK *ntfs_ib_alloc(VCN ib_vcn, u32 ib_size, INDEX_HEADER_FLAGS node_type) { INDEX_BLOCK *ib; int ih_size = sizeof(INDEX_HEADER); ntfs_log_trace("ib_vcn: %lld ib_size: %u\n", (long long)ib_vcn, ib_size); ib = ntfs_calloc(ib_size); if (!ib) return NULL; ib->magic = magic_INDX; ib->usa_ofs = const_cpu_to_le16(sizeof(INDEX_BLOCK)); ib->usa_count = cpu_to_le16(ib_size / NTFS_BLOCK_SIZE + 1); /* Set USN to 1 */ *(le16 *)((char *)ib + le16_to_cpu(ib->usa_ofs)) = const_cpu_to_le16(1); ib->lsn = const_cpu_to_sle64(0); ib->index_block_vcn = cpu_to_sle64(ib_vcn); ib->index.entries_offset = cpu_to_le32((ih_size + le16_to_cpu(ib->usa_count) * 2 + 7) & ~7); ib->index.index_length = const_cpu_to_le32(0); ib->index.allocated_size = cpu_to_le32(ib_size - (sizeof(INDEX_BLOCK) - ih_size)); ib->index.ih_flags = node_type; return ib; } /** * Find the median by going through all the entries */ static INDEX_ENTRY *ntfs_ie_get_median(INDEX_HEADER *ih) { INDEX_ENTRY *ie, *ie_start; u8 *ie_end; int i = 0, median; ntfs_log_trace("Entering\n"); ie = ie_start = ntfs_ie_get_first(ih); ie_end = (u8 *)ntfs_ie_get_end(ih); while ((u8 *)ie < ie_end && !ntfs_ie_end(ie)) { ie = ntfs_ie_get_next(ie); i++; } /* * NOTE: this could be also the entry at the half of the index block. */ median = i / 2 - 1; ntfs_log_trace("Entries: %d median: %d\n", i, median); for (i = 0, ie = ie_start; i <= median; i++) ie = ntfs_ie_get_next(ie); return ie; } static s64 ntfs_ibm_vcn_to_pos(ntfs_index_context *icx, VCN vcn) { return ntfs_ib_vcn_to_pos(icx, vcn) / icx->block_size; } static s64 ntfs_ibm_pos_to_vcn(ntfs_index_context *icx, s64 pos) { return ntfs_ib_pos_to_vcn(icx, pos * icx->block_size); } static int ntfs_ibm_add(ntfs_index_context *icx) { u8 bmp[8]; ntfs_log_trace("Entering\n"); if (ntfs_attr_exist(icx->ni, AT_BITMAP, icx->name, icx->name_len)) return STATUS_OK; /* * AT_BITMAP must be at least 8 bytes. */ memset(bmp, 0, sizeof(bmp)); if (ntfs_attr_add(icx->ni, AT_BITMAP, icx->name, icx->name_len, bmp, sizeof(bmp))) { ntfs_log_perror("Failed to add AT_BITMAP"); return STATUS_ERROR; } return STATUS_OK; } static int ntfs_ibm_modify(ntfs_index_context *icx, VCN vcn, int set) { u8 byte; s64 pos = ntfs_ibm_vcn_to_pos(icx, vcn); u32 bpos = pos / 8; u32 bit = 1 << (pos % 8); ntfs_attr *na; int ret = STATUS_ERROR; ntfs_log_trace("%s vcn: %lld\n", set ? "set" : "clear", (long long)vcn); na = ntfs_attr_open(icx->ni, AT_BITMAP, icx->name, icx->name_len); if (!na) { ntfs_log_perror("Failed to open $BITMAP attribute"); return -1; } if (set) { if (na->data_size < bpos + 1) { if (ntfs_attr_truncate(na, (na->data_size + 8) & ~7)) { ntfs_log_perror("Failed to truncate AT_BITMAP"); goto err_na; } } } if (ntfs_attr_pread(na, bpos, 1, &byte) != 1) { ntfs_log_perror("Failed to read $BITMAP"); goto err_na; } if (set) byte |= bit; else byte &= ~bit; if (ntfs_attr_pwrite(na, bpos, 1, &byte) != 1) { ntfs_log_perror("Failed to write $Bitmap"); goto err_na; } ret = STATUS_OK; err_na: ntfs_attr_close(na); return ret; } static int ntfs_ibm_set(ntfs_index_context *icx, VCN vcn) { return ntfs_ibm_modify(icx, vcn, 1); } static int ntfs_ibm_clear(ntfs_index_context *icx, VCN vcn) { return ntfs_ibm_modify(icx, vcn, 0); } static VCN ntfs_ibm_get_free(ntfs_index_context *icx) { u8 *bm; int bit; s64 vcn, byte, size; ntfs_log_trace("Entering\n"); bm = ntfs_attr_readall(icx->ni, AT_BITMAP, icx->name, icx->name_len, &size); if (!bm) return (VCN)-1; for (byte = 0; byte < size; byte++) { if (bm[byte] == 255) continue; for (bit = 0; bit < 8; bit++) { if (!(bm[byte] & (1 << bit))) { vcn = ntfs_ibm_pos_to_vcn(icx, byte * 8 + bit); goto out; } } } vcn = ntfs_ibm_pos_to_vcn(icx, size * 8); out: ntfs_log_trace("allocated vcn: %lld\n", (long long)vcn); if (ntfs_ibm_set(icx, vcn)) vcn = (VCN)-1; free(bm); return vcn; } static INDEX_BLOCK *ntfs_ir_to_ib(INDEX_ROOT *ir, VCN ib_vcn) { INDEX_BLOCK *ib; INDEX_ENTRY *ie_last; char *ies_start, *ies_end; int i; ntfs_log_trace("Entering\n"); ib = ntfs_ib_alloc(ib_vcn, le32_to_cpu(ir->index_block_size), LEAF_NODE); if (!ib) return NULL; ies_start = (char *)ntfs_ie_get_first(&ir->index); ies_end = (char *)ntfs_ie_get_end(&ir->index); ie_last = ntfs_ie_get_last((INDEX_ENTRY *)ies_start, ies_end); /* * Copy all entries, including the termination entry * as well, which can never have any data. */ i = (char *)ie_last - ies_start + le16_to_cpu(ie_last->length); memcpy(ntfs_ie_get_first(&ib->index), ies_start, i); ib->index.ih_flags = ir->index.ih_flags; ib->index.index_length = cpu_to_le32(i + le32_to_cpu(ib->index.entries_offset)); return ib; } static void ntfs_ir_nill(INDEX_ROOT *ir) { INDEX_ENTRY *ie_last; char *ies_start, *ies_end; ntfs_log_trace("Entering\n"); /* * TODO: This function could be much simpler. */ ies_start = (char *)ntfs_ie_get_first(&ir->index); ies_end = (char *)ntfs_ie_get_end(&ir->index); ie_last = ntfs_ie_get_last((INDEX_ENTRY *)ies_start, ies_end); /* * Move the index root termination entry forward */ if ((char *)ie_last > ies_start) { memmove(ies_start, (char *)ie_last, le16_to_cpu(ie_last->length)); ie_last = (INDEX_ENTRY *)ies_start; } } static int ntfs_ib_copy_tail(ntfs_index_context *icx, INDEX_BLOCK *src, INDEX_ENTRY *median, VCN new_vcn) { u8 *ies_end; INDEX_ENTRY *ie_head; /* first entry after the median */ int tail_size, ret; INDEX_BLOCK *dst; ntfs_log_trace("Entering\n"); dst = ntfs_ib_alloc(new_vcn, icx->block_size, src->index.ih_flags & NODE_MASK); if (!dst) return STATUS_ERROR; ie_head = ntfs_ie_get_next(median); ies_end = (u8 *)ntfs_ie_get_end(&src->index); tail_size = ies_end - (u8 *)ie_head; memcpy(ntfs_ie_get_first(&dst->index), ie_head, tail_size); dst->index.index_length = cpu_to_le32(tail_size + le32_to_cpu(dst->index.entries_offset)); ret = ntfs_ib_write(icx, dst); free(dst); return ret; } static int ntfs_ib_cut_tail(ntfs_index_context *icx, INDEX_BLOCK *ib, INDEX_ENTRY *ie) { char *ies_start, *ies_end; INDEX_ENTRY *ie_last; ntfs_log_trace("Entering\n"); ies_start = (char *)ntfs_ie_get_first(&ib->index); ies_end = (char *)ntfs_ie_get_end(&ib->index); ie_last = ntfs_ie_get_last((INDEX_ENTRY *)ies_start, ies_end); if (ie_last->ie_flags & INDEX_ENTRY_NODE) ntfs_ie_set_vcn(ie_last, ntfs_ie_get_vcn(ie)); memcpy(ie, ie_last, le16_to_cpu(ie_last->length)); ib->index.index_length = cpu_to_le32(((char *)ie - ies_start) + le16_to_cpu(ie->length) + le32_to_cpu(ib->index.entries_offset)); if (ntfs_ib_write(icx, ib)) return STATUS_ERROR; return STATUS_OK; } static int ntfs_ia_add(ntfs_index_context *icx) { ntfs_log_trace("Entering\n"); if (ntfs_ibm_add(icx)) return -1; if (!ntfs_attr_exist(icx->ni, AT_INDEX_ALLOCATION, icx->name, icx->name_len)) { if (ntfs_attr_add(icx->ni, AT_INDEX_ALLOCATION, icx->name, icx->name_len, NULL, 0)) { ntfs_log_perror("Failed to add AT_INDEX_ALLOCATION"); return -1; } } icx->ia_na = ntfs_ia_open(icx, icx->ni); if (!icx->ia_na) return -1; return 0; } static int ntfs_ir_reparent(ntfs_index_context *icx) { ntfs_attr_search_ctx *ctx = NULL; INDEX_ROOT *ir; INDEX_ENTRY *ie; INDEX_BLOCK *ib = NULL; VCN new_ib_vcn; int ix_root_size; int ret = STATUS_ERROR; ntfs_log_trace("Entering\n"); ir = ntfs_ir_lookup2(icx->ni, icx->name, icx->name_len); if (!ir) goto out; if ((ir->index.ih_flags & NODE_MASK) == SMALL_INDEX) if (ntfs_ia_add(icx)) goto out; new_ib_vcn = ntfs_ibm_get_free(icx); if (new_ib_vcn == -1) goto out; ir = ntfs_ir_lookup2(icx->ni, icx->name, icx->name_len); if (!ir) goto clear_bmp; ib = ntfs_ir_to_ib(ir, new_ib_vcn); if (ib == NULL) { ntfs_log_perror("Failed to move index root to index block"); goto clear_bmp; } if (ntfs_ib_write(icx, ib)) goto clear_bmp; retry : ir = ntfs_ir_lookup(icx->ni, icx->name, icx->name_len, &ctx); if (!ir) goto clear_bmp; ntfs_ir_nill(ir); ie = ntfs_ie_get_first(&ir->index); ie->ie_flags |= INDEX_ENTRY_NODE; ie->length = const_cpu_to_le16(sizeof(INDEX_ENTRY_HEADER) + sizeof(VCN)); ir->index.ih_flags = LARGE_INDEX; ir->index.index_length = cpu_to_le32(le32_to_cpu(ir->index.entries_offset) + le16_to_cpu(ie->length)); ir->index.allocated_size = ir->index.index_length; ix_root_size = sizeof(INDEX_ROOT) - sizeof(INDEX_HEADER) + le32_to_cpu(ir->index.allocated_size); if (ntfs_resident_attr_value_resize(ctx->mrec, ctx->attr, ix_root_size)) { /* * When there is no space to build a non-resident * index, we may have to move the root to an extent */ if ((errno == ENOSPC) && (ctx->al_entry || !ntfs_inode_add_attrlist(icx->ni))) { ntfs_attr_put_search_ctx(ctx); ctx = (ntfs_attr_search_ctx*)NULL; ir = ntfs_ir_lookup(icx->ni, icx->name, icx->name_len, &ctx); if (ir && !ntfs_attr_record_move_away(ctx, ix_root_size - le32_to_cpu(ctx->attr->value_length))) { ntfs_attr_put_search_ctx(ctx); ctx = (ntfs_attr_search_ctx*)NULL; goto retry; } } /* FIXME: revert index root */ goto clear_bmp; } /* * FIXME: do it earlier if we have enough space in IR (should always), * so in error case we wouldn't lose the IB. */ ntfs_ie_set_vcn(ie, new_ib_vcn); ret = STATUS_OK; err_out: free(ib); ntfs_attr_put_search_ctx(ctx); out: return ret; clear_bmp: ntfs_ibm_clear(icx, new_ib_vcn); goto err_out; } /** * ntfs_ir_truncate - Truncate index root attribute * * Returns STATUS_OK, STATUS_RESIDENT_ATTRIBUTE_FILLED_MFT or STATUS_ERROR. */ static int ntfs_ir_truncate(ntfs_index_context *icx, int data_size) { ntfs_attr *na; int ret; ntfs_log_trace("Entering\n"); na = ntfs_attr_open(icx->ni, AT_INDEX_ROOT, icx->name, icx->name_len); if (!na) { ntfs_log_perror("Failed to open INDEX_ROOT"); return STATUS_ERROR; } /* * INDEX_ROOT must be resident and its entries can be moved to * INDEX_BLOCK, so ENOSPC isn't a real error. */ ret = ntfs_attr_truncate(na, data_size + offsetof(INDEX_ROOT, index)); if (ret == STATUS_OK) { icx->ir = ntfs_ir_lookup2(icx->ni, icx->name, icx->name_len); if (!icx->ir) return STATUS_ERROR; icx->ir->index.allocated_size = cpu_to_le32(data_size); } else if (ret == STATUS_ERROR) ntfs_log_perror("Failed to truncate INDEX_ROOT"); ntfs_attr_close(na); return ret; } /** * ntfs_ir_make_space - Make more space for the index root attribute * * On success return STATUS_OK or STATUS_KEEP_SEARCHING. * On error return STATUS_ERROR. */ static int ntfs_ir_make_space(ntfs_index_context *icx, int data_size) { int ret; ntfs_log_trace("Entering\n"); ret = ntfs_ir_truncate(icx, data_size); if (ret == STATUS_RESIDENT_ATTRIBUTE_FILLED_MFT) { ret = ntfs_ir_reparent(icx); if (ret == STATUS_OK) ret = STATUS_KEEP_SEARCHING; else ntfs_log_perror("Failed to nodify INDEX_ROOT"); } return ret; } /* * NOTE: 'ie' must be a copy of a real index entry. */ static int ntfs_ie_add_vcn(INDEX_ENTRY **ie) { INDEX_ENTRY *p, *old = *ie; old->length = cpu_to_le16(le16_to_cpu(old->length) + sizeof(VCN)); p = realloc(old, le16_to_cpu(old->length)); if (!p) return STATUS_ERROR; p->ie_flags |= INDEX_ENTRY_NODE; *ie = p; return STATUS_OK; } static int ntfs_ih_insert(INDEX_HEADER *ih, INDEX_ENTRY *orig_ie, VCN new_vcn, int pos) { INDEX_ENTRY *ie_node, *ie; int ret = STATUS_ERROR; VCN old_vcn; ntfs_log_trace("Entering\n"); ie = ntfs_ie_dup(orig_ie); if (!ie) return STATUS_ERROR; if (!(ie->ie_flags & INDEX_ENTRY_NODE)) if (ntfs_ie_add_vcn(&ie)) goto out; ie_node = ntfs_ie_get_by_pos(ih, pos); old_vcn = ntfs_ie_get_vcn(ie_node); ntfs_ie_set_vcn(ie_node, new_vcn); ntfs_ie_insert(ih, ie, ie_node); ntfs_ie_set_vcn(ie_node, old_vcn); ret = STATUS_OK; out: free(ie); return ret; } static VCN ntfs_icx_parent_vcn(ntfs_index_context *icx) { return icx->parent_vcn[icx->pindex]; } static VCN ntfs_icx_parent_pos(ntfs_index_context *icx) { return icx->parent_pos[icx->pindex]; } static int ntfs_ir_insert_median(ntfs_index_context *icx, INDEX_ENTRY *median, VCN new_vcn) { u32 new_size; int ret; ntfs_log_trace("Entering\n"); icx->ir = ntfs_ir_lookup2(icx->ni, icx->name, icx->name_len); if (!icx->ir) return STATUS_ERROR; new_size = le32_to_cpu(icx->ir->index.index_length) + le16_to_cpu(median->length); if (!(median->ie_flags & INDEX_ENTRY_NODE)) new_size += sizeof(VCN); ret = ntfs_ir_make_space(icx, new_size); if (ret != STATUS_OK) return ret; icx->ir = ntfs_ir_lookup2(icx->ni, icx->name, icx->name_len); if (!icx->ir) return STATUS_ERROR; return ntfs_ih_insert(&icx->ir->index, median, new_vcn, ntfs_icx_parent_pos(icx)); } static int ntfs_ib_split(ntfs_index_context *icx, INDEX_BLOCK *ib); /** * On success return STATUS_OK or STATUS_KEEP_SEARCHING. * On error return STATUS_ERROR. */ static int ntfs_ib_insert(ntfs_index_context *icx, INDEX_ENTRY *ie, VCN new_vcn) { INDEX_BLOCK *ib; u32 idx_size, allocated_size; int err = STATUS_ERROR; VCN old_vcn; ntfs_log_trace("Entering\n"); ib = ntfs_malloc(icx->block_size); if (!ib) return -1; old_vcn = ntfs_icx_parent_vcn(icx); if (ntfs_ib_read(icx, old_vcn, ib)) goto err_out; idx_size = le32_to_cpu(ib->index.index_length); allocated_size = le32_to_cpu(ib->index.allocated_size); /* FIXME: sizeof(VCN) should be included only if ie has no VCN */ if (idx_size + le16_to_cpu(ie->length) + sizeof(VCN) > allocated_size) { err = ntfs_ib_split(icx, ib); if (err == STATUS_OK) err = STATUS_KEEP_SEARCHING; goto err_out; } if (ntfs_ih_insert(&ib->index, ie, new_vcn, ntfs_icx_parent_pos(icx))) goto err_out; if (ntfs_ib_write(icx, ib)) goto err_out; err = STATUS_OK; err_out: free(ib); return err; } /** * ntfs_ib_split - Split an index block * * On success return STATUS_OK or STATUS_KEEP_SEARCHING. * On error return is STATUS_ERROR. */ static int ntfs_ib_split(ntfs_index_context *icx, INDEX_BLOCK *ib) { INDEX_ENTRY *median; VCN new_vcn; int ret; ntfs_log_trace("Entering\n"); if (ntfs_icx_parent_dec(icx)) return STATUS_ERROR; median = ntfs_ie_get_median(&ib->index); new_vcn = ntfs_ibm_get_free(icx); if (new_vcn == -1) return STATUS_ERROR; if (ntfs_ib_copy_tail(icx, ib, median, new_vcn)) { ntfs_ibm_clear(icx, new_vcn); return STATUS_ERROR; } if (ntfs_icx_parent_vcn(icx) == VCN_INDEX_ROOT_PARENT) ret = ntfs_ir_insert_median(icx, median, new_vcn); else ret = ntfs_ib_insert(icx, median, new_vcn); if (ret != STATUS_OK) { ntfs_ibm_clear(icx, new_vcn); return ret; } ret = ntfs_ib_cut_tail(icx, ib, median); return ret; } /* JPA static */ int ntfs_ie_add(ntfs_index_context *icx, INDEX_ENTRY *ie) { INDEX_HEADER *ih; int allocated_size, new_size; int ret = STATUS_ERROR; #ifdef DEBUG /* removed by JPA to make function usable for security indexes char *fn; fn = ntfs_ie_filename_get(ie); ntfs_log_trace("file: '%s'\n", fn); ntfs_attr_name_free(&fn); */ #endif while (1) { if (!ntfs_index_lookup(&ie->key, le16_to_cpu(ie->key_length), icx)) { errno = EEXIST; ntfs_log_perror("Index already have such entry"); goto err_out; } if (errno != ENOENT) { ntfs_log_perror("Failed to find place for new entry"); goto err_out; } if (icx->is_in_root) ih = &icx->ir->index; else ih = &icx->ib->index; allocated_size = le32_to_cpu(ih->allocated_size); new_size = le32_to_cpu(ih->index_length) + le16_to_cpu(ie->length); if (new_size <= allocated_size) break; ntfs_log_trace("index block sizes: allocated: %d needed: %d\n", allocated_size, new_size); if (icx->is_in_root) { if (ntfs_ir_make_space(icx, new_size) == STATUS_ERROR) goto err_out; } else { if (ntfs_ib_split(icx, icx->ib) == STATUS_ERROR) goto err_out; } ntfs_inode_mark_dirty(icx->actx->ntfs_ino); ntfs_index_ctx_reinit(icx); } ntfs_ie_insert(ih, ie, icx->entry); ntfs_index_entry_mark_dirty(icx); ret = STATUS_OK; err_out: ntfs_log_trace("%s\n", ret ? "Failed" : "Done"); return ret; } /** * ntfs_index_add_filename - add filename to directory index * @ni: ntfs inode describing directory to which index add filename * @fn: FILE_NAME attribute to add * @mref: reference of the inode which @fn describes * * Return 0 on success or -1 on error with errno set to the error code. */ int ntfs_index_add_filename(ntfs_inode *ni, FILE_NAME_ATTR *fn, MFT_REF mref) { INDEX_ENTRY *ie; ntfs_index_context *icx; int fn_size, ie_size, err, ret = -1; ntfs_log_trace("Entering\n"); if (!ni || !fn) { ntfs_log_error("Invalid arguments.\n"); errno = EINVAL; return -1; } fn_size = (fn->file_name_length * sizeof(ntfschar)) + sizeof(FILE_NAME_ATTR); ie_size = (sizeof(INDEX_ENTRY_HEADER) + fn_size + 7) & ~7; ie = ntfs_calloc(ie_size); if (!ie) return -1; ie->indexed_file = cpu_to_le64(mref); ie->length = cpu_to_le16(ie_size); ie->key_length = cpu_to_le16(fn_size); memcpy(&ie->key, fn, fn_size); icx = ntfs_index_ctx_get(ni, NTFS_INDEX_I30, 4); if (!icx) goto out; ret = ntfs_ie_add(icx, ie); err = errno; ntfs_index_ctx_put(icx); errno = err; out: free(ie); return ret; } static int ntfs_ih_takeout(ntfs_index_context *icx, INDEX_HEADER *ih, INDEX_ENTRY *ie, INDEX_BLOCK *ib) { INDEX_ENTRY *ie_roam; int freed_space; BOOL full; int ret = STATUS_ERROR; ntfs_log_trace("Entering\n"); full = ih->index_length == ih->allocated_size; ie_roam = ntfs_ie_dup_novcn(ie); if (!ie_roam) return STATUS_ERROR; ntfs_ie_delete(ih, ie); if (ntfs_icx_parent_vcn(icx) == VCN_INDEX_ROOT_PARENT) { /* * Recover the space which may have been freed * while deleting an entry from root index */ freed_space = le32_to_cpu(ih->allocated_size) - le32_to_cpu(ih->index_length); if (full && (freed_space > 0) && !(freed_space & 7)) { ntfs_ir_truncate(icx, le32_to_cpu(ih->index_length)); /* do nothing if truncation fails */ } ntfs_inode_mark_dirty(icx->actx->ntfs_ino); } else if (ntfs_ib_write(icx, ib)) goto out; ntfs_index_ctx_reinit(icx); ret = ntfs_ie_add(icx, ie_roam); out: free(ie_roam); return ret; } /** * Used if an empty index block to be deleted has END entry as the parent * in the INDEX_ROOT which is the only one there. */ static void ntfs_ir_leafify(ntfs_index_context *icx, INDEX_HEADER *ih) { INDEX_ENTRY *ie; ntfs_log_trace("Entering\n"); ie = ntfs_ie_get_first(ih); ie->ie_flags &= ~INDEX_ENTRY_NODE; ie->length = cpu_to_le16(le16_to_cpu(ie->length) - sizeof(VCN)); ih->index_length = cpu_to_le32(le32_to_cpu(ih->index_length) - sizeof(VCN)); ih->ih_flags &= ~LARGE_INDEX; /* Not fatal error */ ntfs_ir_truncate(icx, le32_to_cpu(ih->index_length)); } /** * Used if an empty index block to be deleted has END entry as the parent * in the INDEX_ROOT which is not the only one there. */ static int ntfs_ih_reparent_end(ntfs_index_context *icx, INDEX_HEADER *ih, INDEX_BLOCK *ib) { INDEX_ENTRY *ie, *ie_prev; ntfs_log_trace("Entering\n"); ie = ntfs_ie_get_by_pos(ih, ntfs_icx_parent_pos(icx)); ie_prev = ntfs_ie_prev(ih, ie); ntfs_ie_set_vcn(ie, ntfs_ie_get_vcn(ie_prev)); return ntfs_ih_takeout(icx, ih, ie_prev, ib); } static int ntfs_index_rm_leaf(ntfs_index_context *icx) { INDEX_BLOCK *ib = NULL; INDEX_HEADER *parent_ih; INDEX_ENTRY *ie; int ret = STATUS_ERROR; ntfs_log_trace("pindex: %d\n", icx->pindex); if (ntfs_icx_parent_dec(icx)) return STATUS_ERROR; if (ntfs_ibm_clear(icx, icx->parent_vcn[icx->pindex + 1])) return STATUS_ERROR; if (ntfs_icx_parent_vcn(icx) == VCN_INDEX_ROOT_PARENT) parent_ih = &icx->ir->index; else { ib = ntfs_malloc(icx->block_size); if (!ib) return STATUS_ERROR; if (ntfs_ib_read(icx, ntfs_icx_parent_vcn(icx), ib)) goto out; parent_ih = &ib->index; } ie = ntfs_ie_get_by_pos(parent_ih, ntfs_icx_parent_pos(icx)); if (!ntfs_ie_end(ie)) { ret = ntfs_ih_takeout(icx, parent_ih, ie, ib); goto out; } if (ntfs_ih_zero_entry(parent_ih)) { if (ntfs_icx_parent_vcn(icx) == VCN_INDEX_ROOT_PARENT) { ntfs_ir_leafify(icx, parent_ih); goto ok; } ret = ntfs_index_rm_leaf(icx); goto out; } if (ntfs_ih_reparent_end(icx, parent_ih, ib)) goto out; ok: ret = STATUS_OK; out: free(ib); return ret; } static int ntfs_index_rm_node(ntfs_index_context *icx) { int entry_pos, pindex; VCN vcn; INDEX_BLOCK *ib = NULL; INDEX_ENTRY *ie_succ, *ie, *entry = icx->entry; INDEX_HEADER *ih; u32 new_size; int delta, ret = STATUS_ERROR; ntfs_log_trace("Entering\n"); if (!icx->ia_na) { icx->ia_na = ntfs_ia_open(icx, icx->ni); if (!icx->ia_na) return STATUS_ERROR; } ib = ntfs_malloc(icx->block_size); if (!ib) return STATUS_ERROR; ie_succ = ntfs_ie_get_next(icx->entry); entry_pos = icx->parent_pos[icx->pindex]++; pindex = icx->pindex; descend: vcn = ntfs_ie_get_vcn(ie_succ); if (ntfs_ib_read(icx, vcn, ib)) goto out; ie_succ = ntfs_ie_get_first(&ib->index); if (ntfs_icx_parent_inc(icx)) goto out; icx->parent_vcn[icx->pindex] = vcn; icx->parent_pos[icx->pindex] = 0; if ((ib->index.ih_flags & NODE_MASK) == INDEX_NODE) goto descend; if (ntfs_ih_zero_entry(&ib->index)) { errno = EIO; ntfs_log_perror("Empty index block"); goto out; } ie = ntfs_ie_dup(ie_succ); if (!ie) goto out; if (ntfs_ie_add_vcn(&ie)) goto out2; ntfs_ie_set_vcn(ie, ntfs_ie_get_vcn(icx->entry)); if (icx->is_in_root) ih = &icx->ir->index; else ih = &icx->ib->index; delta = le16_to_cpu(ie->length) - le16_to_cpu(icx->entry->length); new_size = le32_to_cpu(ih->index_length) + delta; if (delta > 0) { if (icx->is_in_root) { ret = ntfs_ir_make_space(icx, new_size); if (ret != STATUS_OK) goto out2; ih = &icx->ir->index; entry = ntfs_ie_get_by_pos(ih, entry_pos); } else if (new_size > le32_to_cpu(ih->allocated_size)) { icx->pindex = pindex; ret = ntfs_ib_split(icx, icx->ib); if (ret == STATUS_OK) ret = STATUS_KEEP_SEARCHING; goto out2; } } ntfs_ie_delete(ih, entry); ntfs_ie_insert(ih, ie, entry); if (icx->is_in_root) { if (ntfs_ir_truncate(icx, new_size)) goto out2; } else if (ntfs_icx_ib_write(icx)) goto out2; ntfs_ie_delete(&ib->index, ie_succ); if (ntfs_ih_zero_entry(&ib->index)) { if (ntfs_index_rm_leaf(icx)) goto out2; } else if (ntfs_ib_write(icx, ib)) goto out2; ret = STATUS_OK; out2: free(ie); out: free(ib); return ret; } /** * ntfs_index_rm - remove entry from the index * @icx: index context describing entry to delete * * Delete entry described by @icx from the index. Index context is always * reinitialized after use of this function, so it can be used for index * lookup once again. * * Return 0 on success or -1 on error with errno set to the error code. */ /*static JPA*/ int ntfs_index_rm(ntfs_index_context *icx) { INDEX_HEADER *ih; int err, ret = STATUS_OK; ntfs_log_trace("Entering\n"); if (!icx || (!icx->ib && !icx->ir) || ntfs_ie_end(icx->entry)) { ntfs_log_error("Invalid arguments.\n"); errno = EINVAL; goto err_out; } if (icx->is_in_root) ih = &icx->ir->index; else ih = &icx->ib->index; if (icx->entry->ie_flags & INDEX_ENTRY_NODE) { ret = ntfs_index_rm_node(icx); } else if (icx->is_in_root || !ntfs_ih_one_entry(ih)) { ntfs_ie_delete(ih, icx->entry); if (icx->is_in_root) { err = ntfs_ir_truncate(icx, le32_to_cpu(ih->index_length)); if (err != STATUS_OK) goto err_out; } else if (ntfs_icx_ib_write(icx)) goto err_out; } else { if (ntfs_index_rm_leaf(icx)) goto err_out; } out: return ret; err_out: ret = STATUS_ERROR; goto out; } int ntfs_index_remove(ntfs_inode *dir_ni, ntfs_inode *ni __attribute__((unused)), const void *key, const int keylen) { int ret = STATUS_ERROR; ntfs_index_context *icx; icx = ntfs_index_ctx_get(dir_ni, NTFS_INDEX_I30, 4); if (!icx) return -1; while (1) { if (ntfs_index_lookup(key, keylen, icx)) goto err_out; ret = ntfs_index_rm(icx); if (ret == STATUS_ERROR) goto err_out; else if (ret == STATUS_OK) break; ntfs_inode_mark_dirty(icx->actx->ntfs_ino); ntfs_index_ctx_reinit(icx); } ntfs_inode_mark_dirty(icx->actx->ntfs_ino); out: ntfs_index_ctx_put(icx); return ret; err_out: ret = STATUS_ERROR; ntfs_log_perror("Delete failed"); goto out; } /** * ntfs_index_root_get - read the index root of an attribute * @ni: open ntfs inode in which the ntfs attribute resides * @attr: attribute for which we want its index root * * This function will read the related index root an ntfs attribute. * * On success a buffer is allocated with the content of the index root * and which needs to be freed when it's not needed anymore. * * On error NULL is returned with errno set to the error code. */ INDEX_ROOT *ntfs_index_root_get(ntfs_inode *ni, ATTR_RECORD *attr) { ntfs_attr_search_ctx *ctx; ntfschar *name; INDEX_ROOT *root = NULL; name = (ntfschar *)((u8 *)attr + le16_to_cpu(attr->name_offset)); if (!ntfs_ir_lookup(ni, name, attr->name_length, &ctx)) return NULL; root = ntfs_malloc(sizeof(INDEX_ROOT)); if (!root) goto out; *root = *((INDEX_ROOT *)((u8 *)ctx->attr + le16_to_cpu(ctx->attr->value_offset))); out: ntfs_attr_put_search_ctx(ctx); return root; } /* * Walk down the index tree (leaf bound) * until there are no subnode in the first index entry * returns the entry at the bottom left in subnode */ static INDEX_ENTRY *ntfs_index_walk_down(INDEX_ENTRY *ie, ntfs_index_context *ictx) { INDEX_ENTRY *entry; s64 vcn; entry = ie; do { vcn = ntfs_ie_get_vcn(entry); if (ictx->is_in_root) { /* down from level zero */ ictx->ir = (INDEX_ROOT*)NULL; ictx->ib = (INDEX_BLOCK*)ntfs_malloc(ictx->block_size); ictx->pindex = 1; ictx->is_in_root = FALSE; } else { /* down from non-zero level */ ictx->pindex++; } ictx->parent_pos[ictx->pindex] = 0; ictx->parent_vcn[ictx->pindex] = vcn; if (!ntfs_ib_read(ictx,vcn,ictx->ib)) { ictx->entry = ntfs_ie_get_first(&ictx->ib->index); entry = ictx->entry; } else entry = (INDEX_ENTRY*)NULL; } while (entry && (entry->ie_flags & INDEX_ENTRY_NODE)); return (entry); } /* * Walk up the index tree (root bound) * until there is a valid data entry in parent * returns the parent entry or NULL if no more parent */ static INDEX_ENTRY *ntfs_index_walk_up(INDEX_ENTRY *ie, ntfs_index_context *ictx) { INDEX_ENTRY *entry; s64 vcn; entry = ie; if (ictx->pindex > 0) { do { ictx->pindex--; if (!ictx->pindex) { /* we have reached the root */ free(ictx->ib); ictx->ib = (INDEX_BLOCK*)NULL; ictx->is_in_root = TRUE; /* a new search context is to be allocated */ if (ictx->actx) free(ictx->actx); ictx->ir = ntfs_ir_lookup(ictx->ni, ictx->name, ictx->name_len, &ictx->actx); if (ictx->ir) entry = ntfs_ie_get_by_pos( &ictx->ir->index, ictx->parent_pos[ictx->pindex]); else entry = (INDEX_ENTRY*)NULL; } else { /* up into non-root node */ vcn = ictx->parent_vcn[ictx->pindex]; if (!ntfs_ib_read(ictx,vcn,ictx->ib)) { entry = ntfs_ie_get_by_pos( &ictx->ib->index, ictx->parent_pos[ictx->pindex]); } else entry = (INDEX_ENTRY*)NULL; } ictx->entry = entry; } while (entry && (ictx->pindex > 0) && (entry->ie_flags & INDEX_ENTRY_END)); } else entry = (INDEX_ENTRY*)NULL; return (entry); } /* * Get next entry in an index according to collating sequence. * Must be initialized through a ntfs_index_lookup() * * Returns next entry or NULL if none * * Sample layout : * * +---+---+---+---+---+---+---+---+ n ptrs to subnodes * | | | 10| 25| 33| | | | n-1 keys in between * +---+---+---+---+---+---+---+---+ no key in last entry * | A | A * | | | +-------------------------------+ * +--------------------------+ | +-----+ | * | +--+ | | * V | V | * +---+---+---+---+---+---+---+---+ | +---+---+---+---+---+---+---+---+ * | 11| 12| 13| 14| 15| 16| 17| | | | 26| 27| 28| 29| 30| 31| 32| | * +---+---+---+---+---+---+---+---+ | +---+---+---+---+---+---+---+---+ * | | * +-----------------------+ | * | | * +---+---+---+---+---+---+---+---+ * | 18| 19| 20| 21| 22| 23| 24| | * +---+---+---+---+---+---+---+---+ */ INDEX_ENTRY *ntfs_index_next(INDEX_ENTRY *ie, ntfs_index_context *ictx) { INDEX_ENTRY *next; le16 flags; /* * lookup() may have returned an invalid node * when searching for a partial key * if this happens, walk up */ if (ie->ie_flags & INDEX_ENTRY_END) next = ntfs_index_walk_up(ie, ictx); else { /* * get next entry in same node * there is always one after any entry with data */ next = (INDEX_ENTRY*)((char*)ie + le16_to_cpu(ie->length)); ++ictx->parent_pos[ictx->pindex]; flags = next->ie_flags; /* walk down if it has a subnode */ if (flags & INDEX_ENTRY_NODE) { next = ntfs_index_walk_down(next,ictx); } else { /* walk up it has no subnode, nor data */ if (flags & INDEX_ENTRY_END) { next = ntfs_index_walk_up(next, ictx); } } } /* return NULL if stuck at end of a block */ if (next && (next->ie_flags & INDEX_ENTRY_END)) next = (INDEX_ENTRY*)NULL; return (next); } ntfs-3g-2026.2.25/libntfs-3g/misc.c0000664000175000017500000000335615152260173012056 /** * misc.c : miscellaneous : * - dealing with errors in memory allocation * * Copyright (c) 2008 Jean-Pierre Andre * * This program/include file 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/include file 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_STDLIB_H #include #endif #ifdef HAVE_STRING_H #include #endif #include "types.h" #include "misc.h" #include "logging.h" /** * ntfs_calloc * * Return a pointer to the allocated memory or NULL if the request fails. */ void *ntfs_calloc(size_t size) { void *p; p = calloc(1, size); if (!p) ntfs_log_perror("Failed to calloc %lld bytes", (long long)size); return p; } void *ntfs_malloc(size_t size) { void *p; p = malloc(size); if (!p) ntfs_log_perror("Failed to malloc %lld bytes", (long long)size); return p; } void *ntfs_realloc(void *ptr, size_t size) { void *p; p = realloc(ptr, size); if (!p) ntfs_log_perror("Failed to realloc %lld bytes", (long long)size); return p; } void ntfs_free(void *p) { free(p); } ntfs-3g-2026.2.25/libntfs-3g/dir.c0000664000175000017500000023470115152260173011701 /** * dir.c - Directory handling code. Originated from the Linux-NTFS project. * * Copyright (c) 2002-2005 Anton Altaparmakov * Copyright (c) 2004-2005 Richard Russon * Copyright (c) 2004-2008 Szabolcs Szakacsits * Copyright (c) 2005-2007 Yura Pakhuchiy * Copyright (c) 2008-2021 Jean-Pierre Andre * * This program/include file 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/include file 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_STDLIB_H #include #endif #ifdef HAVE_ERRNO_H #include #endif #ifdef HAVE_STRING_H #include #endif #ifdef HAVE_SYS_STAT_H #include #endif #ifdef HAVE_SYS_TYPES_H #include #endif #ifdef MAJOR_IN_MKDEV #include #endif #ifdef MAJOR_IN_SYSMACROS #include #endif #include "param.h" #include "types.h" #include "debug.h" #include "attrib.h" #include "inode.h" #include "dir.h" #include "volume.h" #include "mft.h" #include "index.h" #include "ntfstime.h" #include "lcnalloc.h" #include "logging.h" #include "cache.h" #include "misc.h" #include "security.h" #include "reparse.h" #include "object_id.h" #include "xattrs.h" #include "ea.h" /* * The little endian Unicode strings "$I30", "$SII", "$SDH", "$O" * and "$Q" as global constants. */ ntfschar NTFS_INDEX_I30[5] = { const_cpu_to_le16('$'), const_cpu_to_le16('I'), const_cpu_to_le16('3'), const_cpu_to_le16('0'), const_cpu_to_le16('\0') }; ntfschar NTFS_INDEX_SII[5] = { const_cpu_to_le16('$'), const_cpu_to_le16('S'), const_cpu_to_le16('I'), const_cpu_to_le16('I'), const_cpu_to_le16('\0') }; ntfschar NTFS_INDEX_SDH[5] = { const_cpu_to_le16('$'), const_cpu_to_le16('S'), const_cpu_to_le16('D'), const_cpu_to_le16('H'), const_cpu_to_le16('\0') }; ntfschar NTFS_INDEX_O[3] = { const_cpu_to_le16('$'), const_cpu_to_le16('O'), const_cpu_to_le16('\0') }; ntfschar NTFS_INDEX_Q[3] = { const_cpu_to_le16('$'), const_cpu_to_le16('Q'), const_cpu_to_le16('\0') }; ntfschar NTFS_INDEX_R[3] = { const_cpu_to_le16('$'), const_cpu_to_le16('R'), const_cpu_to_le16('\0') }; #if CACHE_INODE_SIZE /* * Pathname hashing * * Based on first char and second char (which may be '\0') */ int ntfs_dir_inode_hash(const struct CACHED_GENERIC *cached) { const char *path; const unsigned char *name; path = (const char*)cached->variable; if (!path) { ntfs_log_error("Bad inode cache entry\n"); return (-1); } name = (const unsigned char*)strrchr(path,'/'); if (!name) name = (const unsigned char*)path; return (((name[0] << 1) + name[1] + strlen((const char*)name)) % (2*CACHE_INODE_SIZE)); } /* * Pathname comparing for entering/fetching from cache */ static int inode_cache_compare(const struct CACHED_GENERIC *cached, const struct CACHED_GENERIC *wanted) { return (!cached->variable || strcmp(cached->variable, wanted->variable)); } /* * Pathname comparing for invalidating entries in cache * * A partial path is compared in order to invalidate all paths * related to a renamed directory * inode numbers are also checked, as deleting a long name may * imply deleting a short name and conversely * * Only use associated with a CACHE_NOHASH flag */ static int inode_cache_inv_compare(const struct CACHED_GENERIC *cached, const struct CACHED_GENERIC *wanted) { int len; BOOL different; const struct CACHED_INODE *w; const struct CACHED_INODE *c; w = (const struct CACHED_INODE*)wanted; c = (const struct CACHED_INODE*)cached; if (w->pathname) { len = strlen(w->pathname); different = !cached->variable || ((w->inum != MREF(c->inum)) && (strncmp(c->pathname, w->pathname, len) || ((c->pathname[len] != '\0') && (c->pathname[len] != '/')))); } else different = !c->pathname || (w->inum != MREF(c->inum)); return (different); } #endif #if CACHE_LOOKUP_SIZE /* * File name comparing for entering/fetching from lookup cache */ static int lookup_cache_compare(const struct CACHED_GENERIC *cached, const struct CACHED_GENERIC *wanted) { const struct CACHED_LOOKUP *c = (const struct CACHED_LOOKUP*) cached; const struct CACHED_LOOKUP *w = (const struct CACHED_LOOKUP*) wanted; return (!c->name || (c->parent != w->parent) || (c->namesize != w->namesize) || memcmp(c->name, w->name, c->namesize)); } /* * Inode number comparing for invalidating lookup cache * * All entries with designated inode number are invalidated * * Only use associated with a CACHE_NOHASH flag */ static int lookup_cache_inv_compare(const struct CACHED_GENERIC *cached, const struct CACHED_GENERIC *wanted) { const struct CACHED_LOOKUP *c = (const struct CACHED_LOOKUP*) cached; const struct CACHED_LOOKUP *w = (const struct CACHED_LOOKUP*) wanted; return (!c->name || (c->parent != w->parent) || (MREF(c->inum) != MREF(w->inum))); } /* * Lookup hashing * * Based on first, second and and last char */ int ntfs_dir_lookup_hash(const struct CACHED_GENERIC *cached) { const unsigned char *name; int count; unsigned int val; name = (const unsigned char*)cached->variable; count = cached->varsize; if (!name || !count) { ntfs_log_error("Bad lookup cache entry\n"); return (-1); } val = (name[0] << 2) + (name[1] << 1) + name[count - 1] + count; return (val % (2*CACHE_LOOKUP_SIZE)); } #endif /** * ntfs_inode_lookup_by_name - find an inode in a directory given its name * @dir_ni: ntfs inode of the directory in which to search for the name * @uname: Unicode name for which to search in the directory * @uname_len: length of the name @uname in Unicode characters * * Look for an inode with name @uname in the directory with inode @dir_ni. * ntfs_inode_lookup_by_name() walks the contents of the directory looking for * the Unicode name. If the name is found in the directory, the corresponding * inode number (>= 0) is returned as a mft reference in cpu format, i.e. it * is a 64-bit number containing the sequence number. * * On error, return -1 with errno set to the error code. If the inode is is not * found errno is ENOENT. * * Note, @uname_len does not include the (optional) terminating NULL character. * * Note, we look for a case sensitive match first but we also look for a case * insensitive match at the same time. If we find a case insensitive match, we * save that for the case that we don't find an exact match, where we return * the mft reference of the case insensitive match. * * If the volume is mounted with the case sensitive flag set, then we only * allow exact matches. */ u64 ntfs_inode_lookup_by_name(ntfs_inode *dir_ni, const ntfschar *uname, const int uname_len) { VCN vcn; u64 mref = 0; s64 br; ntfs_volume *vol = dir_ni->vol; ntfs_attr_search_ctx *ctx; INDEX_ROOT *ir; INDEX_ENTRY *ie; INDEX_ALLOCATION *ia; IGNORE_CASE_BOOL case_sensitivity; u8 *index_end; ntfs_attr *ia_na; int eo, rc; u32 index_block_size; u8 index_vcn_size_bits; ntfs_log_trace("Entering\n"); if (!dir_ni || !dir_ni->mrec || !uname || uname_len <= 0) { errno = EINVAL; return -1; } ctx = ntfs_attr_get_search_ctx(dir_ni, NULL); if (!ctx) return -1; /* Find the index root attribute in the mft record. */ if (ntfs_attr_lookup(AT_INDEX_ROOT, NTFS_INDEX_I30, 4, CASE_SENSITIVE, 0, NULL, 0, ctx)) { ntfs_log_perror("Index root attribute missing in directory inode " "%lld", (unsigned long long)dir_ni->mft_no); goto put_err_out; } case_sensitivity = (NVolCaseSensitive(vol) ? CASE_SENSITIVE : IGNORE_CASE); /* Get to the index root value. */ ir = (INDEX_ROOT*)((u8*)ctx->attr + le16_to_cpu(ctx->attr->value_offset)); index_block_size = le32_to_cpu(ir->index_block_size); if (index_block_size < NTFS_BLOCK_SIZE || index_block_size & (index_block_size - 1)) { ntfs_log_error("Index block size %u is invalid.\n", (unsigned)index_block_size); goto put_err_out; } /* Consistency check of ir done while fetching attribute */ index_end = (u8*)&ir->index + le32_to_cpu(ir->index.index_length); /* The first index entry. */ ie = (INDEX_ENTRY*)((u8*)&ir->index + le32_to_cpu(ir->index.entries_offset)); /* * Loop until we exceed valid memory (corruption case) or until we * reach the last entry. */ for (;; ie = (INDEX_ENTRY*)((u8*)ie + le16_to_cpu(ie->length))) { /* Bounds checks. */ if ((u8*)ie < (u8*)ctx->mrec || (u8*)ie + sizeof(INDEX_ENTRY_HEADER) > index_end || (u8*)ie + le16_to_cpu(ie->length) > index_end) { ntfs_log_error("Index root entry out of bounds in" " inode %lld\n", (unsigned long long)dir_ni->mft_no); goto put_err_out; } /* * The last entry cannot contain a name. It can however contain * a pointer to a child node in the B+tree so we just break out. */ if (ie->ie_flags & INDEX_ENTRY_END) break; /* The file name must not overflow from the entry */ if (ntfs_index_entry_inconsistent(ie, COLLATION_FILE_NAME, dir_ni->mft_no)) { errno = EIO; goto put_err_out; } /* * Not a perfect match, need to do full blown collation so we * know which way in the B+tree we have to go. */ rc = ntfs_names_full_collate(uname, uname_len, (ntfschar*)&ie->key.file_name.file_name, ie->key.file_name.file_name_length, case_sensitivity, vol->upcase, vol->upcase_len); /* * If uname collates before the name of the current entry, there * is definitely no such name in this index but we might need to * descend into the B+tree so we just break out of the loop. */ if (rc == -1) break; /* The names are not equal, continue the search. */ if (rc) continue; /* * Perfect match, this will never happen as the * ntfs_are_names_equal() call will have gotten a match but we * still treat it correctly. */ mref = le64_to_cpu(ie->indexed_file); ntfs_attr_put_search_ctx(ctx); return mref; } /* * We have finished with this index without success. Check for the * presence of a child node and if not present return error code * ENOENT, unless we have got the mft reference of a matching name * cached in mref in which case return mref. */ if (!(ie->ie_flags & INDEX_ENTRY_NODE)) { ntfs_attr_put_search_ctx(ctx); if (mref) return mref; ntfs_log_debug("Entry not found - between root entries.\n"); errno = ENOENT; return -1; } /* Child node present, descend into it. */ /* Open the index allocation attribute. */ ia_na = ntfs_attr_open(dir_ni, AT_INDEX_ALLOCATION, NTFS_INDEX_I30, 4); if (!ia_na) { ntfs_log_perror("Failed to open index allocation (inode %lld)", (unsigned long long)dir_ni->mft_no); goto put_err_out; } /* Allocate a buffer for the current index block. */ ia = ntfs_malloc(index_block_size); if (!ia) { ntfs_attr_close(ia_na); goto put_err_out; } /* Determine the size of a vcn in the directory index. */ if (vol->cluster_size <= index_block_size) { index_vcn_size_bits = vol->cluster_size_bits; } else { index_vcn_size_bits = NTFS_BLOCK_SIZE_BITS; } /* Get the starting vcn of the index_block holding the child node. */ vcn = sle64_to_cpup((sle64*)((u8*)ie + le16_to_cpu(ie->length) - 8)); descend_into_child_node: /* Read the index block starting at vcn. */ br = ntfs_attr_mst_pread(ia_na, vcn << index_vcn_size_bits, 1, index_block_size, ia); if (br != 1) { if (br != -1) errno = EIO; ntfs_log_perror("Failed to read vcn 0x%llx from inode %lld", (unsigned long long)vcn, (unsigned long long)ia_na->ni->mft_no); goto close_err_out; } if (ntfs_index_block_inconsistent((INDEX_BLOCK*)ia, index_block_size, ia_na->ni->mft_no, vcn)) { errno = EIO; goto close_err_out; } index_end = (u8*)&ia->index + le32_to_cpu(ia->index.index_length); /* The first index entry. */ ie = (INDEX_ENTRY*)((u8*)&ia->index + le32_to_cpu(ia->index.entries_offset)); /* * Iterate similar to above big loop but applied to index buffer, thus * loop until we exceed valid memory (corruption case) or until we * reach the last entry. */ for (;; ie = (INDEX_ENTRY*)((u8*)ie + le16_to_cpu(ie->length))) { /* Bounds check. */ if ((u8*)ie < (u8*)ia || (u8*)ie + sizeof(INDEX_ENTRY_HEADER) > index_end || (u8*)ie + le16_to_cpu(ie->length) > index_end) { ntfs_log_error("Index entry out of bounds in directory " "inode %lld.\n", (unsigned long long)dir_ni->mft_no); errno = EIO; goto close_err_out; } /* * The last entry cannot contain a name. It can however contain * a pointer to a child node in the B+tree so we just break out. */ if (ie->ie_flags & INDEX_ENTRY_END) break; /* The file name must not overflow from the entry */ if (ntfs_index_entry_inconsistent(ie, COLLATION_FILE_NAME, dir_ni->mft_no)) { errno = EIO; goto close_err_out; } /* * Not a perfect match, need to do full blown collation so we * know which way in the B+tree we have to go. */ rc = ntfs_names_full_collate(uname, uname_len, (ntfschar*)&ie->key.file_name.file_name, ie->key.file_name.file_name_length, case_sensitivity, vol->upcase, vol->upcase_len); /* * If uname collates before the name of the current entry, there * is definitely no such name in this index but we might need to * descend into the B+tree so we just break out of the loop. */ if (rc == -1) break; /* The names are not equal, continue the search. */ if (rc) continue; mref = le64_to_cpu(ie->indexed_file); free(ia); ntfs_attr_close(ia_na); ntfs_attr_put_search_ctx(ctx); return mref; } /* * We have finished with this index buffer without success. Check for * the presence of a child node. */ if (ie->ie_flags & INDEX_ENTRY_NODE) { if ((ia->index.ih_flags & NODE_MASK) == LEAF_NODE) { ntfs_log_error("Index entry with child node found in a leaf " "node in directory inode %lld.\n", (unsigned long long)dir_ni->mft_no); errno = EIO; goto close_err_out; } /* Child node present, descend into it. */ vcn = sle64_to_cpup((sle64*)((u8*)ie + le16_to_cpu(ie->length) - 8)); if (vcn >= 0) goto descend_into_child_node; ntfs_log_error("Negative child node vcn in directory inode " "0x%llx.\n", (unsigned long long)dir_ni->mft_no); errno = EIO; goto close_err_out; } free(ia); ntfs_attr_close(ia_na); ntfs_attr_put_search_ctx(ctx); /* * No child node present, return error code ENOENT, unless we have got * the mft reference of a matching name cached in mref in which case * return mref. */ if (mref) return mref; ntfs_log_debug("Entry not found.\n"); errno = ENOENT; return -1; put_err_out: eo = EIO; ntfs_log_debug("Corrupt directory. Aborting lookup.\n"); eo_put_err_out: ntfs_attr_put_search_ctx(ctx); errno = eo; return -1; close_err_out: eo = errno; free(ia); ntfs_attr_close(ia_na); goto eo_put_err_out; } /* * Lookup a file in a directory from its UTF-8 name * * The name is first fetched from cache if one is defined * * Returns the inode number * or -1 if not possible (errno tells why) */ u64 ntfs_inode_lookup_by_mbsname(ntfs_inode *dir_ni, const char *name) { int uname_len; ntfschar *uname = (ntfschar*)NULL; u64 inum; char *cached_name; const char *const_name; if (!NVolCaseSensitive(dir_ni->vol)) { cached_name = ntfs_uppercase_mbs(name, dir_ni->vol->upcase, dir_ni->vol->upcase_len); const_name = cached_name; } else { cached_name = (char*)NULL; const_name = name; } if (const_name) { #if CACHE_LOOKUP_SIZE /* * fetch inode from cache */ if (dir_ni->vol->lookup_cache) { struct CACHED_LOOKUP item; struct CACHED_LOOKUP *cached; item.name = const_name; item.namesize = strlen(const_name) + 1; item.parent = dir_ni->mft_no; cached = (struct CACHED_LOOKUP*)ntfs_fetch_cache( dir_ni->vol->lookup_cache, GENERIC(&item), lookup_cache_compare); if (cached) { inum = cached->inum; if (inum == (u64)-1) errno = ENOENT; } else { /* Generate unicode name. */ uname_len = ntfs_mbstoucs(name, &uname); if (uname_len >= 0) { inum = ntfs_inode_lookup_by_name(dir_ni, uname, uname_len); item.inum = inum; /* enter into cache, even if not found */ ntfs_enter_cache(dir_ni->vol->lookup_cache, GENERIC(&item), lookup_cache_compare); free(uname); } else inum = (s64)-1; } } else #endif { /* Generate unicode name. */ uname_len = ntfs_mbstoucs(cached_name, &uname); if (uname_len >= 0) inum = ntfs_inode_lookup_by_name(dir_ni, uname, uname_len); else inum = (s64)-1; } if (cached_name) free(cached_name); } else inum = (s64)-1; return (inum); } /* * Update a cache lookup record when a name has been defined * * The UTF-8 name is required */ void ntfs_inode_update_mbsname(ntfs_inode *dir_ni, const char *name, u64 inum) { #if CACHE_LOOKUP_SIZE struct CACHED_LOOKUP item; struct CACHED_LOOKUP *cached; char *cached_name; if (dir_ni->vol->lookup_cache) { if (!NVolCaseSensitive(dir_ni->vol)) { cached_name = ntfs_uppercase_mbs(name, dir_ni->vol->upcase, dir_ni->vol->upcase_len); item.name = cached_name; } else { cached_name = (char*)NULL; item.name = name; } if (item.name) { item.namesize = strlen(item.name) + 1; item.parent = dir_ni->mft_no; item.inum = inum; cached = (struct CACHED_LOOKUP*)ntfs_enter_cache( dir_ni->vol->lookup_cache, GENERIC(&item), lookup_cache_compare); if (cached) cached->inum = inum; if (cached_name) free(cached_name); } } #endif } /** * ntfs_pathname_to_inode - Find the inode which represents the given pathname * @vol: An ntfs volume obtained from ntfs_mount * @parent: A directory inode to begin the search (may be NULL) * @pathname: Pathname to be located * * Take an ASCII pathname and find the inode that represents it. The function * splits the path and then descends the directory tree. If @parent is NULL, * then the root directory '.' will be used as the base for the search. * * Return: inode Success, the pathname was valid * NULL Error, the pathname was invalid, or some other error occurred */ ntfs_inode *ntfs_pathname_to_inode(ntfs_volume *vol, ntfs_inode *parent, const char *pathname) { u64 inum; int len, err = 0; char *p, *q; ntfs_inode *ni; ntfs_inode *result = NULL; ntfschar *unicode = NULL; char *ascii = NULL; #if CACHE_INODE_SIZE struct CACHED_INODE item; struct CACHED_INODE *cached; char *fullname; #endif if (!vol || !pathname) { errno = EINVAL; return NULL; } ntfs_log_trace("path: '%s'\n", pathname); ascii = strdup(pathname); if (!ascii) { ntfs_log_error("Out of memory.\n"); err = ENOMEM; goto out; } p = ascii; /* Remove leading /'s. */ while (p && *p && *p == PATH_SEP) p++; #if CACHE_INODE_SIZE fullname = p; if (p[0] && (p[strlen(p)-1] == PATH_SEP)) ntfs_log_error("Unnormalized path %s\n",ascii); #endif if (parent) { ni = parent; } else { #if CACHE_INODE_SIZE /* * fetch inode for full path from cache */ if (*fullname) { item.pathname = fullname; item.varsize = strlen(fullname) + 1; cached = (struct CACHED_INODE*)ntfs_fetch_cache( vol->xinode_cache, GENERIC(&item), inode_cache_compare); } else cached = (struct CACHED_INODE*)NULL; if (cached) { /* * return opened inode if found in cache */ inum = MREF(cached->inum); ni = ntfs_inode_open(vol, inum); if (!ni) { ntfs_log_debug("Cannot open inode %llu: %s.\n", (unsigned long long)inum, p); err = EIO; } result = ni; goto out; } #endif ni = ntfs_inode_open(vol, FILE_root); if (!ni) { ntfs_log_debug("Couldn't open the inode of the root " "directory.\n"); err = EIO; result = (ntfs_inode*)NULL; goto out; } } while (p && *p) { /* Find the end of the first token. */ q = strchr(p, PATH_SEP); if (q != NULL) { *q = '\0'; } #if CACHE_INODE_SIZE /* * fetch inode for partial path from cache */ cached = (struct CACHED_INODE*)NULL; if (!parent) { item.pathname = fullname; item.varsize = strlen(fullname) + 1; cached = (struct CACHED_INODE*)ntfs_fetch_cache( vol->xinode_cache, GENERIC(&item), inode_cache_compare); if (cached) { inum = cached->inum; } } /* * if not in cache, translate, search, then * insert into cache if found */ if (!cached) { len = ntfs_mbstoucs(p, &unicode); if (len < 0) { ntfs_log_perror("Could not convert filename to Unicode:" " '%s'", p); err = errno; goto close; } else if (len > NTFS_MAX_NAME_LEN) { err = ENAMETOOLONG; goto close; } inum = ntfs_inode_lookup_by_name(ni, unicode, len); if (!parent && (inum != (u64) -1)) { item.inum = inum; ntfs_enter_cache(vol->xinode_cache, GENERIC(&item), inode_cache_compare); } } #else len = ntfs_mbstoucs(p, &unicode); if (len < 0) { ntfs_log_perror("Could not convert filename to Unicode:" " '%s'", p); err = errno; goto close; } else if (len > NTFS_MAX_NAME_LEN) { err = ENAMETOOLONG; goto close; } inum = ntfs_inode_lookup_by_name(ni, unicode, len); #endif if (inum == (u64) -1) { ntfs_log_debug("Couldn't find name '%s' in pathname " "'%s'.\n", p, pathname); err = ENOENT; goto close; } if (ni != parent) if (ntfs_inode_close(ni)) { err = errno; goto out; } inum = MREF(inum); ni = ntfs_inode_open(vol, inum); if (!ni) { ntfs_log_debug("Cannot open inode %llu: %s.\n", (unsigned long long)inum, p); err = EIO; goto close; } free(unicode); unicode = NULL; if (q) *q++ = PATH_SEP; /* JPA */ p = q; while (p && *p && *p == PATH_SEP) p++; } result = ni; ni = NULL; close: if (ni && (ni != parent)) if (ntfs_inode_close(ni) && !err) err = errno; out: free(ascii); free(unicode); if (err) errno = err; return result; } /* * The little endian Unicode string ".." for ntfs_readdir(). */ static const ntfschar dotdot[3] = { const_cpu_to_le16('.'), const_cpu_to_le16('.'), const_cpu_to_le16('\0') }; /* * union index_union - * More helpers for ntfs_readdir(). */ typedef union { INDEX_ROOT *ir; INDEX_ALLOCATION *ia; } index_union __attribute__((__transparent_union__)); /** * enum INDEX_TYPE - * More helpers for ntfs_readdir(). */ typedef enum { INDEX_TYPE_ROOT, /* index root */ INDEX_TYPE_ALLOCATION, /* index allocation */ } INDEX_TYPE; /* * Decode Interix file types * * Non-Interix types are returned as plain files, because a * Windows user may force patterns very similar to Interix, * and most metadata files have such similar patters. */ u32 ntfs_interix_types(ntfs_inode *ni) { ntfs_attr *na; u32 dt_type; le64 magic; dt_type = NTFS_DT_UNKNOWN; na = ntfs_attr_open(ni, AT_DATA, NULL, 0); if (na) { /* * Unrecognized patterns (eg HID + SYST for metadata) * are plain files or directories */ if (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) dt_type = NTFS_DT_DIR; else dt_type = NTFS_DT_REG; if (na->data_size <= 1) { if (!(ni->flags & FILE_ATTR_HIDDEN)) dt_type = (na->data_size ? NTFS_DT_SOCK : NTFS_DT_FIFO); } else { if ((na->data_size >= (s64)sizeof(magic)) && (ntfs_attr_pread(na, 0, sizeof(magic), &magic) == sizeof(magic))) { if (magic == INTX_SYMBOLIC_LINK) dt_type = NTFS_DT_LNK; else if (magic == INTX_BLOCK_DEVICE) dt_type = NTFS_DT_BLK; else if (magic == INTX_CHARACTER_DEVICE) dt_type = NTFS_DT_CHR; } } ntfs_attr_close(na); } return (dt_type); } /* * Decode file types * * Better only use for Interix types and junctions, * unneeded complexity when used for plain files or directories * * Error cases are logged and returned as unknown. */ static u32 ntfs_dir_entry_type(ntfs_inode *dir_ni, MFT_REF mref, FILE_ATTR_FLAGS attributes) { ntfs_inode *ni; u32 dt_type; dt_type = NTFS_DT_UNKNOWN; ni = ntfs_inode_open(dir_ni->vol, mref); if (ni) { if (attributes & FILE_ATTR_REPARSE_POINT) dt_type = (ntfs_possible_symlink(ni) ? NTFS_DT_LNK : NTFS_DT_REPARSE); else if ((attributes & FILE_ATTR_SYSTEM) && !(attributes & FILE_ATTR_I30_INDEX_PRESENT)) dt_type = ntfs_interix_types(ni); else dt_type = (attributes & FILE_ATTR_I30_INDEX_PRESENT ? NTFS_DT_DIR : NTFS_DT_REG); if (ntfs_inode_close(ni)) { /* anything special worth doing ? */ ntfs_log_error("Failed to close inode %lld\n", (long long)MREF(mref)); } } if (dt_type == NTFS_DT_UNKNOWN) ntfs_log_error("Could not decode the type of inode %lld\n", (long long)MREF(mref)); return (dt_type); } /** * ntfs_filldir - ntfs specific filldir method * @dir_ni: ntfs inode of current directory * @pos: current position in directory * @ivcn_bits: log(2) of index vcn size * @index_type: specifies whether @iu is an index root or an index allocation * @iu: index root or index block to which @ie belongs * @ie: current index entry * @dirent: context for filldir callback supplied by the caller * @filldir: filldir callback supplied by the caller * * Pass information specifying the current directory entry @ie to the @filldir * callback. */ static int ntfs_filldir(ntfs_inode *dir_ni, s64 *pos, u8 ivcn_bits, const INDEX_TYPE index_type, index_union iu, INDEX_ENTRY *ie, void *dirent, ntfs_filldir_t filldir) { FILE_NAME_ATTR *fn = &ie->key.file_name; unsigned dt_type; BOOL metadata; ntfschar *loname; int res; MFT_REF mref; ntfs_log_trace("Entering.\n"); /* Advance the position even if going to skip the entry. */ if (index_type == INDEX_TYPE_ALLOCATION) *pos = (u8*)ie - (u8*)iu.ia + (sle64_to_cpu( iu.ia->index_block_vcn) << ivcn_bits) + dir_ni->vol->mft_record_size; else /* if (index_type == INDEX_TYPE_ROOT) */ *pos = (u8*)ie - (u8*)iu.ir; mref = le64_to_cpu(ie->indexed_file); metadata = (MREF(mref) != FILE_root) && (MREF(mref) < FILE_first_user); /* Skip root directory self reference entry. */ if (MREF_LE(ie->indexed_file) == FILE_root) return 0; if ((ie->key.file_name.file_attributes & (FILE_ATTR_REPARSE_POINT | FILE_ATTR_SYSTEM)) && !metadata) dt_type = ntfs_dir_entry_type(dir_ni, mref, ie->key.file_name.file_attributes); else if (ie->key.file_name.file_attributes & FILE_ATTR_I30_INDEX_PRESENT) dt_type = NTFS_DT_DIR; else dt_type = NTFS_DT_REG; /* return metadata files and hidden files if requested */ if ((!metadata && (NVolShowHidFiles(dir_ni->vol) || !(fn->file_attributes & FILE_ATTR_HIDDEN))) || (NVolShowSysFiles(dir_ni->vol) && (NVolShowHidFiles(dir_ni->vol) || metadata))) { if (NVolCaseSensitive(dir_ni->vol)) { res = filldir(dirent, fn->file_name, fn->file_name_length, fn->file_name_type, *pos, mref, dt_type); } else { loname = (ntfschar*)ntfs_malloc(2*fn->file_name_length); if (loname) { memcpy(loname, fn->file_name, 2*fn->file_name_length); ntfs_name_locase(loname, fn->file_name_length, dir_ni->vol->locase, dir_ni->vol->upcase_len); res = filldir(dirent, loname, fn->file_name_length, fn->file_name_type, *pos, mref, dt_type); free(loname); } else res = -1; } } else res = 0; return (res); } /** * ntfs_mft_get_parent_ref - find mft reference of parent directory of an inode * @ni: ntfs inode whose parent directory to find * * Find the parent directory of the ntfs inode @ni. To do this, find the first * file name attribute in the mft record of @ni and return the parent mft * reference from that. * * Note this only makes sense for directories, since files can be hard linked * from multiple directories and there is no way for us to tell which one is * being looked for. * * Technically directories can have hard links, too, but we consider that as * illegal as Linux/UNIX do not support directory hard links. * * Return the mft reference of the parent directory on success or -1 on error * with errno set to the error code. */ static MFT_REF ntfs_mft_get_parent_ref(ntfs_inode *ni) { MFT_REF mref; ntfs_attr_search_ctx *ctx; FILE_NAME_ATTR *fn; int eo; ntfs_log_trace("Entering.\n"); if (!ni) { errno = EINVAL; return ERR_MREF(-1); } ctx = ntfs_attr_get_search_ctx(ni, NULL); if (!ctx) return ERR_MREF(-1); if (ntfs_attr_lookup(AT_FILE_NAME, AT_UNNAMED, 0, 0, 0, NULL, 0, ctx)) { ntfs_log_error("No file name found in inode %lld\n", (unsigned long long)ni->mft_no); goto err_out; } if (ctx->attr->non_resident) { ntfs_log_error("File name attribute must be resident (inode " "%lld)\n", (unsigned long long)ni->mft_no); goto io_err_out; } fn = (FILE_NAME_ATTR*)((u8*)ctx->attr + le16_to_cpu(ctx->attr->value_offset)); mref = le64_to_cpu(fn->parent_directory); ntfs_attr_put_search_ctx(ctx); return mref; io_err_out: errno = EIO; err_out: eo = errno; ntfs_attr_put_search_ctx(ctx); errno = eo; return ERR_MREF(-1); } /** * ntfs_readdir - read the contents of an ntfs directory * @dir_ni: ntfs inode of current directory * @pos: current position in directory * @dirent: context for filldir callback supplied by the caller * @filldir: filldir callback supplied by the caller * * Parse the index root and the index blocks that are marked in use in the * index bitmap and hand each found directory entry to the @filldir callback * supplied by the caller. * * Return 0 on success or -1 on error with errno set to the error code. * * Note: Index blocks are parsed in ascending vcn order, from which follows * that the directory entries are not returned sorted. */ int ntfs_readdir(ntfs_inode *dir_ni, s64 *pos, void *dirent, ntfs_filldir_t filldir) { s64 i_size, br, ia_pos, bmp_pos, ia_start; ntfs_volume *vol; ntfs_attr *ia_na, *bmp_na = NULL; ntfs_attr_search_ctx *ctx = NULL; u8 *index_end, *bmp = NULL; INDEX_ROOT *ir; INDEX_ENTRY *ie; INDEX_ALLOCATION *ia = NULL; int rc, ir_pos, bmp_buf_size, bmp_buf_pos, eo; u32 index_block_size; u8 index_block_size_bits, index_vcn_size_bits; ntfs_log_trace("Entering.\n"); if (!dir_ni || !pos || !filldir) { errno = EINVAL; return -1; } if (!(dir_ni->mrec->flags & MFT_RECORD_IS_DIRECTORY)) { errno = ENOTDIR; return -1; } vol = dir_ni->vol; ntfs_log_trace("Entering for inode %lld, *pos 0x%llx.\n", (unsigned long long)dir_ni->mft_no, (long long)*pos); /* Open the index allocation attribute. */ ia_na = ntfs_attr_open(dir_ni, AT_INDEX_ALLOCATION, NTFS_INDEX_I30, 4); if (!ia_na) { if (errno != ENOENT) { ntfs_log_perror("Failed to open index allocation attribute. " "Directory inode %lld is corrupt or bug", (unsigned long long)dir_ni->mft_no); return -1; } i_size = 0; } else i_size = ia_na->data_size; rc = 0; /* Are we at end of dir yet? */ if (*pos >= i_size + vol->mft_record_size) goto done; /* Emulate . and .. for all directories. */ if (!*pos) { rc = filldir(dirent, dotdot, 1, FILE_NAME_POSIX, *pos, MK_MREF(dir_ni->mft_no, le16_to_cpu(dir_ni->mrec->sequence_number)), NTFS_DT_DIR); if (rc) goto err_out; ++*pos; } if (*pos == 1) { MFT_REF parent_mref; parent_mref = ntfs_mft_get_parent_ref(dir_ni); if (parent_mref == ERR_MREF(-1)) { ntfs_log_perror("Parent directory not found"); goto dir_err_out; } rc = filldir(dirent, dotdot, 2, FILE_NAME_POSIX, *pos, parent_mref, NTFS_DT_DIR); if (rc) goto err_out; ++*pos; } ctx = ntfs_attr_get_search_ctx(dir_ni, NULL); if (!ctx) goto err_out; /* Get the offset into the index root attribute. */ ir_pos = (int)*pos; /* Find the index root attribute in the mft record. */ if (ntfs_attr_lookup(AT_INDEX_ROOT, NTFS_INDEX_I30, 4, CASE_SENSITIVE, 0, NULL, 0, ctx)) { ntfs_log_perror("Index root attribute missing in directory inode " "%lld", (unsigned long long)dir_ni->mft_no); goto dir_err_out; } /* Get to the index root value. */ ir = (INDEX_ROOT*)((u8*)ctx->attr + le16_to_cpu(ctx->attr->value_offset)); /* Determine the size of a vcn in the directory index. */ index_block_size = le32_to_cpu(ir->index_block_size); if (index_block_size < NTFS_BLOCK_SIZE || index_block_size & (index_block_size - 1)) { ntfs_log_error("Index block size %u is invalid.\n", (unsigned)index_block_size); goto dir_err_out; } index_block_size_bits = ffs(index_block_size) - 1; if (vol->cluster_size <= index_block_size) { index_vcn_size_bits = vol->cluster_size_bits; } else { index_vcn_size_bits = NTFS_BLOCK_SIZE_BITS; } /* Are we jumping straight into the index allocation attribute? */ if (*pos >= vol->mft_record_size) { ntfs_attr_put_search_ctx(ctx); ctx = NULL; goto skip_index_root; } index_end = (u8*)&ir->index + le32_to_cpu(ir->index.index_length); /* The first index entry. */ ie = (INDEX_ENTRY*)((u8*)&ir->index + le32_to_cpu(ir->index.entries_offset)); /* * Loop until we exceed valid memory (corruption case) or until we * reach the last entry or until filldir tells us it has had enough * or signals an error (both covered by the rc test). */ for (;; ie = (INDEX_ENTRY*)((u8*)ie + le16_to_cpu(ie->length))) { ntfs_log_debug("In index root, offset %d.\n", (int)((u8*)ie - (u8*)ir)); /* Bounds checks. */ if ((u8*)ie < (u8*)ctx->mrec || (u8*)ie + sizeof(INDEX_ENTRY_HEADER) > index_end || (u8*)ie + le16_to_cpu(ie->length) > index_end) { ntfs_log_error("Index root entry out of bounds in" " inode %lld\n", (unsigned long long)dir_ni->mft_no); goto dir_err_out; } /* The last entry cannot contain a name. */ if (ie->ie_flags & INDEX_ENTRY_END) break; if (!le16_to_cpu(ie->length)) goto dir_err_out; /* Skip index root entry if continuing previous readdir. */ if (ir_pos > (u8*)ie - (u8*)ir) continue; /* The file name must not overflow from the entry */ if (ntfs_index_entry_inconsistent(ie, COLLATION_FILE_NAME, dir_ni->mft_no)) { errno = EIO; goto dir_err_out; } /* * Submit the directory entry to ntfs_filldir(), which will * invoke the filldir() callback as appropriate. */ rc = ntfs_filldir(dir_ni, pos, index_vcn_size_bits, INDEX_TYPE_ROOT, ir, ie, dirent, filldir); if (rc) { ntfs_attr_put_search_ctx(ctx); ctx = NULL; goto err_out; } } ntfs_attr_put_search_ctx(ctx); ctx = NULL; /* If there is no index allocation attribute we are finished. */ if (!ia_na) goto EOD; /* Advance *pos to the beginning of the index allocation. */ *pos = vol->mft_record_size; skip_index_root: if (!ia_na) goto done; /* Allocate a buffer for the current index block. */ ia = ntfs_malloc(index_block_size); if (!ia) goto err_out; bmp_na = ntfs_attr_open(dir_ni, AT_BITMAP, NTFS_INDEX_I30, 4); if (!bmp_na) { ntfs_log_perror("Failed to open index bitmap attribute"); goto dir_err_out; } /* Get the offset into the index allocation attribute. */ ia_pos = *pos - vol->mft_record_size; bmp_pos = ia_pos >> index_block_size_bits; if (bmp_pos >> 3 >= bmp_na->data_size) { ntfs_log_error("Current index position exceeds index bitmap " "size.\n"); goto dir_err_out; } bmp_buf_size = min(bmp_na->data_size - (bmp_pos >> 3), 4096); bmp = ntfs_malloc(bmp_buf_size); if (!bmp) goto err_out; br = ntfs_attr_pread(bmp_na, bmp_pos >> 3, bmp_buf_size, bmp); if (br != bmp_buf_size) { if (br != -1) errno = EIO; ntfs_log_perror("Failed to read from index bitmap attribute"); goto err_out; } bmp_buf_pos = 0; /* If the index block is not in use find the next one that is. */ while (!(bmp[bmp_buf_pos >> 3] & (1 << (bmp_buf_pos & 7)))) { find_next_index_buffer: bmp_pos++; bmp_buf_pos++; /* If we have reached the end of the bitmap, we are done. */ if (bmp_pos >> 3 >= bmp_na->data_size) goto EOD; ia_pos = bmp_pos << index_block_size_bits; if (bmp_buf_pos >> 3 < bmp_buf_size) continue; /* Read next chunk from the index bitmap. */ bmp_buf_pos = 0; if ((bmp_pos >> 3) + bmp_buf_size > bmp_na->data_size) bmp_buf_size = bmp_na->data_size - (bmp_pos >> 3); br = ntfs_attr_pread(bmp_na, bmp_pos >> 3, bmp_buf_size, bmp); if (br != bmp_buf_size) { if (br != -1) errno = EIO; ntfs_log_perror("Failed to read from index bitmap attribute"); goto err_out; } } ntfs_log_debug("Handling index block 0x%llx.\n", (long long)bmp_pos); /* Read the index block starting at bmp_pos. */ br = ntfs_attr_mst_pread(ia_na, bmp_pos << index_block_size_bits, 1, index_block_size, ia); if (br != 1) { if (br != -1) errno = EIO; ntfs_log_perror("Failed to read index block"); goto err_out; } ia_start = ia_pos & ~(s64)(index_block_size - 1); if (ntfs_index_block_inconsistent((INDEX_BLOCK*)ia, index_block_size, ia_na->ni->mft_no, ia_start >> index_vcn_size_bits)) { goto dir_err_out; } index_end = (u8*)&ia->index + le32_to_cpu(ia->index.index_length); /* The first index entry. */ ie = (INDEX_ENTRY*)((u8*)&ia->index + le32_to_cpu(ia->index.entries_offset)); /* * Loop until we exceed valid memory (corruption case) or until we * reach the last entry or until ntfs_filldir tells us it has had * enough or signals an error (both covered by the rc test). */ for (;; ie = (INDEX_ENTRY*)((u8*)ie + le16_to_cpu(ie->length))) { ntfs_log_debug("In index allocation, offset 0x%llx.\n", (long long)ia_start + ((u8*)ie - (u8*)ia)); /* Bounds checks. */ if ((u8*)ie < (u8*)ia || (u8*)ie + sizeof(INDEX_ENTRY_HEADER) > index_end || (u8*)ie + le16_to_cpu(ie->length) > index_end) { ntfs_log_error("Index entry out of bounds in directory inode " "%lld.\n", (unsigned long long)dir_ni->mft_no); goto dir_err_out; } /* The last entry cannot contain a name. */ if (ie->ie_flags & INDEX_ENTRY_END) break; if (!le16_to_cpu(ie->length)) goto dir_err_out; /* Skip index entry if continuing previous readdir. */ if (ia_pos - ia_start > (u8*)ie - (u8*)ia) continue; /* The file name must not overflow from the entry */ if (ntfs_index_entry_inconsistent(ie, COLLATION_FILE_NAME, dir_ni->mft_no)) { errno = EIO; goto dir_err_out; } /* * Submit the directory entry to ntfs_filldir(), which will * invoke the filldir() callback as appropriate. */ rc = ntfs_filldir(dir_ni, pos, index_vcn_size_bits, INDEX_TYPE_ALLOCATION, ia, ie, dirent, filldir); if (rc) goto err_out; } goto find_next_index_buffer; EOD: /* We are finished, set *pos to EOD. */ *pos = i_size + vol->mft_record_size; done: free(ia); free(bmp); if (bmp_na) ntfs_attr_close(bmp_na); if (ia_na) ntfs_attr_close(ia_na); ntfs_log_debug("EOD, *pos 0x%llx, returning 0.\n", (long long)*pos); return 0; dir_err_out: errno = EIO; err_out: eo = errno; ntfs_log_trace("failed.\n"); if (ctx) ntfs_attr_put_search_ctx(ctx); free(ia); free(bmp); if (bmp_na) ntfs_attr_close(bmp_na); if (ia_na) ntfs_attr_close(ia_na); errno = eo; return -1; } /** * __ntfs_create - create object on ntfs volume * @dir_ni: ntfs inode for directory in which create new object * @securid: id of inheritable security descriptor, 0 if none * @name: unicode name of new object * @name_len: length of the name in unicode characters * @type: type of the object to create * @dev: major and minor device numbers (obtained from makedev()) * @target: target in unicode (only for symlinks) * @target_len: length of target in unicode characters * * Internal, use ntfs_create{,_device,_symlink} wrappers instead. * * @type can be: * S_IFREG to create regular file * S_IFDIR to create directory * S_IFBLK to create block device * S_IFCHR to create character device * S_IFLNK to create symbolic link * S_IFIFO to create FIFO * S_IFSOCK to create socket * other values are invalid. * * @dev is used only if @type is S_IFBLK or S_IFCHR, in other cases its value * ignored. * * @target and @target_len are used only if @type is S_IFLNK, in other cases * their value ignored. * * Return opened ntfs inode that describes created object on success or NULL * on error with errno set to the error code. */ static ntfs_inode *__ntfs_create(ntfs_inode *dir_ni, le32 securid, const ntfschar *name, u8 name_len, mode_t type, dev_t dev, const ntfschar *target, int target_len) { ntfs_inode *ni; int rollback_data = 0, rollback_sd = 0; int rollback_dir = 0; FILE_NAME_ATTR *fn = NULL; STANDARD_INFORMATION *si = NULL; int err, fn_len, si_len; ntfs_volume_special_files special_files; ntfs_log_trace("Entering.\n"); /* Sanity checks. */ if (!dir_ni || !name || !name_len) { ntfs_log_error("Invalid arguments.\n"); errno = EINVAL; return NULL; } ni = ntfs_mft_record_alloc(dir_ni->vol, NULL); if (!ni) return NULL; #if CACHE_NIDATA_SIZE ntfs_inode_invalidate(dir_ni->vol, ni->mft_no); #endif special_files = dir_ni->vol->special_files; /* * Create STANDARD_INFORMATION attribute. * JPA Depending on available inherited security descriptor, * Write STANDARD_INFORMATION v1.2 (no inheritance) or v3 */ if (securid) si_len = sizeof(STANDARD_INFORMATION); else si_len = offsetof(STANDARD_INFORMATION, v1_end); si = ntfs_calloc(si_len); if (!si) { err = errno; goto err_out; } si->creation_time = ni->creation_time; si->last_data_change_time = ni->last_data_change_time; si->last_mft_change_time = ni->last_mft_change_time; si->last_access_time = ni->last_access_time; if (securid) { set_nino_flag(ni, v3_Extensions); ni->owner_id = si->owner_id = const_cpu_to_le32(0); ni->security_id = si->security_id = securid; ni->quota_charged = si->quota_charged = const_cpu_to_le64(0); ni->usn = si->usn = const_cpu_to_le64(0); } else clear_nino_flag(ni, v3_Extensions); if (!S_ISREG(type) && !S_ISDIR(type)) { switch (special_files) { case NTFS_FILES_WSL : if (!S_ISLNK(type)) { si->file_attributes = FILE_ATTRIBUTE_RECALL_ON_OPEN; ni->flags = FILE_ATTRIBUTE_RECALL_ON_OPEN; } break; default : si->file_attributes = FILE_ATTR_SYSTEM; ni->flags = FILE_ATTR_SYSTEM; break; } } ni->flags |= FILE_ATTR_ARCHIVE; if (NVolHideDotFiles(dir_ni->vol) && (name_len > 1) && (name[0] == const_cpu_to_le16('.')) && (name[1] != const_cpu_to_le16('.'))) ni->flags |= FILE_ATTR_HIDDEN; /* * Set compression flag according to parent directory * unless NTFS version < 3.0 or cluster size > 4K * or compression has been disabled */ if ((dir_ni->flags & FILE_ATTR_COMPRESSED) && (dir_ni->vol->major_ver >= 3) && NVolCompression(dir_ni->vol) && (dir_ni->vol->cluster_size <= MAX_COMPRESSION_CLUSTER_SIZE) && (S_ISREG(type) || S_ISDIR(type))) ni->flags |= FILE_ATTR_COMPRESSED; /* Add STANDARD_INFORMATION to inode. */ if (ntfs_attr_add(ni, AT_STANDARD_INFORMATION, AT_UNNAMED, 0, (u8*)si, si_len)) { err = errno; ntfs_log_error("Failed to add STANDARD_INFORMATION " "attribute.\n"); goto err_out; } if (!securid) { if (ntfs_sd_add_everyone(ni)) { err = errno; goto err_out; } rollback_sd = 1; } if (S_ISDIR(type)) { INDEX_ROOT *ir = NULL; INDEX_ENTRY *ie; int ir_len, index_len; /* Create INDEX_ROOT attribute. */ index_len = sizeof(INDEX_HEADER) + sizeof(INDEX_ENTRY_HEADER); ir_len = offsetof(INDEX_ROOT, index) + index_len; ir = ntfs_calloc(ir_len); if (!ir) { err = errno; goto err_out; } ir->type = AT_FILE_NAME; ir->collation_rule = COLLATION_FILE_NAME; ir->index_block_size = cpu_to_le32(ni->vol->indx_record_size); if (ni->vol->cluster_size <= ni->vol->indx_record_size) ir->clusters_per_index_block = ni->vol->indx_record_size >> ni->vol->cluster_size_bits; else ir->clusters_per_index_block = ni->vol->indx_record_size >> NTFS_BLOCK_SIZE_BITS; ir->index.entries_offset = const_cpu_to_le32(sizeof(INDEX_HEADER)); ir->index.index_length = cpu_to_le32(index_len); ir->index.allocated_size = cpu_to_le32(index_len); ie = (INDEX_ENTRY*)((u8*)ir + sizeof(INDEX_ROOT)); ie->length = const_cpu_to_le16(sizeof(INDEX_ENTRY_HEADER)); ie->key_length = const_cpu_to_le16(0); ie->ie_flags = INDEX_ENTRY_END; /* Add INDEX_ROOT attribute to inode. */ if (ntfs_attr_add(ni, AT_INDEX_ROOT, NTFS_INDEX_I30, 4, (u8*)ir, ir_len)) { err = errno; free(ir); ntfs_log_error("Failed to add INDEX_ROOT attribute.\n"); goto err_out; } free(ir); } else { INTX_FILE *data; int data_len; switch (type) { case S_IFBLK: case S_IFCHR: switch (special_files) { case NTFS_FILES_WSL : data_len = 0; data = (INTX_FILE*)NULL; break; default : data_len = offsetof(INTX_FILE, device_end); data = (INTX_FILE*)ntfs_malloc( data_len); if (!data) { err = errno; goto err_out; } data->major = cpu_to_le64(major(dev)); data->minor = cpu_to_le64(minor(dev)); if (type == S_IFBLK) data->magic = INTX_BLOCK_DEVICE; if (type == S_IFCHR) data->magic = INTX_CHARACTER_DEVICE; break; } break; case S_IFLNK: switch (special_files) { case NTFS_FILES_WSL : data_len = 0; data = (INTX_FILE*)NULL; break; default : data_len = sizeof(INTX_FILE_TYPES) + target_len * sizeof(ntfschar); data = (INTX_FILE*)ntfs_malloc( data_len); if (!data) { err = errno; goto err_out; } data->magic = INTX_SYMBOLIC_LINK; memcpy(data->target, target, target_len * sizeof(ntfschar)); break; } break; case S_IFSOCK: data = NULL; if (special_files == NTFS_FILES_WSL) data_len = 0; else data_len = 1; break; default: /* FIFO or regular file. */ data = NULL; data_len = 0; break; } /* Add DATA attribute to inode. */ if (ntfs_attr_add(ni, AT_DATA, AT_UNNAMED, 0, (u8*)data, data_len)) { err = errno; ntfs_log_error("Failed to add DATA attribute.\n"); free(data); goto err_out; } rollback_data = 1; free(data); } /* Create FILE_NAME attribute. */ fn_len = sizeof(FILE_NAME_ATTR) + name_len * sizeof(ntfschar); fn = ntfs_calloc(fn_len); if (!fn) { err = errno; goto err_out; } fn->parent_directory = MK_LE_MREF(dir_ni->mft_no, le16_to_cpu(dir_ni->mrec->sequence_number)); fn->file_name_length = name_len; fn->file_name_type = FILE_NAME_POSIX; if (S_ISDIR(type)) fn->file_attributes = FILE_ATTR_I30_INDEX_PRESENT; if (!S_ISREG(type) && !S_ISDIR(type)) { if (special_files == NTFS_FILES_INTERIX) fn->file_attributes = FILE_ATTR_SYSTEM; } else fn->file_attributes |= ni->flags & FILE_ATTR_COMPRESSED; fn->file_attributes |= FILE_ATTR_ARCHIVE; fn->file_attributes |= ni->flags & FILE_ATTR_HIDDEN; fn->creation_time = ni->creation_time; fn->last_data_change_time = ni->last_data_change_time; fn->last_mft_change_time = ni->last_mft_change_time; fn->last_access_time = ni->last_access_time; if (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) fn->data_size = fn->allocated_size = const_cpu_to_sle64(0); else { fn->data_size = cpu_to_sle64(ni->data_size); fn->allocated_size = cpu_to_sle64(ni->allocated_size); } memcpy(fn->file_name, name, name_len * sizeof(ntfschar)); /* Add FILE_NAME attribute to inode. */ if (ntfs_attr_add(ni, AT_FILE_NAME, AT_UNNAMED, 0, (u8*)fn, fn_len)) { err = errno; ntfs_log_error("Failed to add FILE_NAME attribute.\n"); goto err_out; } /* Add FILE_NAME attribute to index. */ if (ntfs_index_add_filename(dir_ni, fn, MK_MREF(ni->mft_no, le16_to_cpu(ni->mrec->sequence_number)))) { err = errno; ntfs_log_perror("Failed to add entry to the index"); goto err_out; } rollback_dir = 1; /* Set hard links count and directory flag. */ ni->mrec->link_count = const_cpu_to_le16(1); if (S_ISDIR(type)) ni->mrec->flags |= MFT_RECORD_IS_DIRECTORY; /* Add reparse data */ if (special_files == NTFS_FILES_WSL) { switch (type) { case S_IFLNK : err = ntfs_reparse_set_wsl_symlink(ni, target, target_len); break; case S_IFIFO : case S_IFSOCK : case S_IFCHR : case S_IFBLK : err = ntfs_reparse_set_wsl_not_symlink(ni, type); if (!err) { err = ntfs_ea_set_wsl_not_symlink(ni, type, dev); if (err) ntfs_remove_ntfs_reparse_data(ni); } break; default : err = 0; break; } if (err) { err = errno; goto err_out; } } ntfs_inode_mark_dirty(ni); /* Done! */ free(fn); free(si); ntfs_log_trace("Done.\n"); return ni; err_out: ntfs_log_trace("Failed.\n"); if (rollback_dir) ntfs_index_remove(dir_ni, ni, fn, fn_len); if (rollback_sd) ntfs_attr_remove(ni, AT_SECURITY_DESCRIPTOR, AT_UNNAMED, 0); if (rollback_data) ntfs_attr_remove(ni, AT_DATA, AT_UNNAMED, 0); /* * Free extent MFT records (should not exist any with current * ntfs_create implementation, but for any case if something will be * changed in the future). */ while (ni->nr_extents) if (ntfs_mft_record_free(ni->vol, *(ni->extent_nis))) { err = errno; ntfs_log_error("Failed to free extent MFT record. " "Leaving inconsistent metadata.\n"); } if (ntfs_mft_record_free(ni->vol, ni)) ntfs_log_error("Failed to free MFT record. " "Leaving inconsistent metadata. Run chkdsk.\n"); free(fn); free(si); errno = err; return NULL; } /** * Some wrappers around __ntfs_create() ... */ ntfs_inode *ntfs_create(ntfs_inode *dir_ni, le32 securid, const ntfschar *name, u8 name_len, mode_t type) { if (type != S_IFREG && type != S_IFDIR && type != S_IFIFO && type != S_IFSOCK) { ntfs_log_error("Invalid arguments.\n"); return NULL; } return __ntfs_create(dir_ni, securid, name, name_len, type, 0, NULL, 0); } ntfs_inode *ntfs_create_device(ntfs_inode *dir_ni, le32 securid, const ntfschar *name, u8 name_len, mode_t type, dev_t dev) { if (type != S_IFCHR && type != S_IFBLK) { ntfs_log_error("Invalid arguments.\n"); return NULL; } return __ntfs_create(dir_ni, securid, name, name_len, type, dev, NULL, 0); } ntfs_inode *ntfs_create_symlink(ntfs_inode *dir_ni, le32 securid, const ntfschar *name, u8 name_len, const ntfschar *target, int target_len) { if (!target || !target_len) { ntfs_log_error("%s: Invalid argument (%p, %d)\n", __FUNCTION__, target, target_len); return NULL; } return __ntfs_create(dir_ni, securid, name, name_len, S_IFLNK, 0, target, target_len); } int ntfs_check_empty_dir(ntfs_inode *ni) { ntfs_attr *na; int ret = 0; if (!(ni->mrec->flags & MFT_RECORD_IS_DIRECTORY)) return 0; na = ntfs_attr_open(ni, AT_INDEX_ROOT, NTFS_INDEX_I30, 4); if (!na) { errno = EIO; ntfs_log_perror("Failed to open directory"); return -1; } /* Non-empty directory? */ if ((na->data_size != sizeof(INDEX_ROOT) + sizeof(INDEX_ENTRY_HEADER))){ /* Both ENOTEMPTY and EEXIST are ok. We use the more common. */ errno = ENOTEMPTY; ntfs_log_debug("Directory is not empty\n"); ret = -1; } ntfs_attr_close(na); return ret; } static int ntfs_check_unlinkable_dir(ntfs_inode *ni, FILE_NAME_ATTR *fn) { int link_count = le16_to_cpu(ni->mrec->link_count); int ret; ret = ntfs_check_empty_dir(ni); if (!ret || errno != ENOTEMPTY) return ret; /* * Directory is non-empty, so we can unlink only if there is more than * one "real" hard link, i.e. links aren't different DOS and WIN32 names */ if ((link_count == 1) || (link_count == 2 && fn->file_name_type == FILE_NAME_DOS)) { errno = ENOTEMPTY; ntfs_log_debug("Non-empty directory without hard links\n"); goto no_hardlink; } ret = 0; no_hardlink: return ret; } /** * ntfs_delete - delete file or directory from ntfs volume * @ni: ntfs inode for object to delte * @dir_ni: ntfs inode for directory in which delete object * @name: unicode name of the object to delete * @name_len: length of the name in unicode characters * * @ni is always closed after the call to this function (even if it failed), * user does not need to call ntfs_inode_close himself. * * Return 0 on success or -1 on error with errno set to the error code. */ int ntfs_delete(ntfs_volume *vol, const char *pathname, ntfs_inode *ni, ntfs_inode *dir_ni, const ntfschar *name, u8 name_len) { ntfs_attr_search_ctx *actx = NULL; FILE_NAME_ATTR *fn = NULL; BOOL looking_for_dos_name = FALSE, looking_for_win32_name = FALSE; BOOL case_sensitive_match = TRUE; int err = 0; #if CACHE_NIDATA_SIZE int i; #endif #if CACHE_INODE_SIZE struct CACHED_INODE item; const char *p; u64 inum = (u64)-1; int count; #endif #if CACHE_LOOKUP_SIZE struct CACHED_LOOKUP lkitem; #endif ntfs_log_trace("Entering.\n"); if (!ni || !dir_ni || !name || !name_len) { ntfs_log_error("Invalid arguments.\n"); errno = EINVAL; goto err_out; } if (ni->nr_extents == -1) ni = ni->base_ni; if (dir_ni->nr_extents == -1) dir_ni = dir_ni->base_ni; /* * Search for FILE_NAME attribute with such name. If it's in POSIX or * WIN32_AND_DOS namespace, then simply remove it from index and inode. * If filename in DOS or in WIN32 namespace, then remove DOS name first, * only then remove WIN32 name. */ actx = ntfs_attr_get_search_ctx(ni, NULL); if (!actx) goto err_out; search: while (!(err = ntfs_attr_lookup(AT_FILE_NAME, AT_UNNAMED, 0, CASE_SENSITIVE, 0, NULL, 0, actx))) { #ifdef DEBUG char *s; #endif IGNORE_CASE_BOOL case_sensitive = IGNORE_CASE; fn = (FILE_NAME_ATTR*)((u8*)actx->attr + le16_to_cpu(actx->attr->value_offset)); #ifdef DEBUG s = ntfs_attr_name_get(fn->file_name, fn->file_name_length); ntfs_log_trace("name: '%s' type: %d dos: %d win32: %d " "case: %d\n", s, fn->file_name_type, looking_for_dos_name, looking_for_win32_name, case_sensitive_match); ntfs_attr_name_free(&s); #endif if (looking_for_dos_name) { if (fn->file_name_type == FILE_NAME_DOS) break; else continue; } if (looking_for_win32_name) { if (fn->file_name_type == FILE_NAME_WIN32) break; else continue; } /* Ignore hard links from other directories */ if (dir_ni->mft_no != MREF_LE(fn->parent_directory)) { ntfs_log_debug("MFT record numbers don't match " "(%llu != %llu)\n", (long long unsigned)dir_ni->mft_no, (long long unsigned)MREF_LE(fn->parent_directory)); continue; } if (case_sensitive_match || ((fn->file_name_type == FILE_NAME_POSIX) && NVolCaseSensitive(ni->vol))) case_sensitive = CASE_SENSITIVE; if (ntfs_names_are_equal(fn->file_name, fn->file_name_length, name, name_len, case_sensitive, ni->vol->upcase, ni->vol->upcase_len)){ if (fn->file_name_type == FILE_NAME_WIN32) { looking_for_dos_name = TRUE; ntfs_attr_reinit_search_ctx(actx); continue; } if (fn->file_name_type == FILE_NAME_DOS) looking_for_dos_name = TRUE; break; } } if (err) { /* * If case sensitive search failed, then try once again * ignoring case. */ if (errno == ENOENT && case_sensitive_match) { case_sensitive_match = FALSE; ntfs_attr_reinit_search_ctx(actx); goto search; } goto err_out; } if (ntfs_check_unlinkable_dir(ni, fn) < 0) goto err_out; if (ntfs_index_remove(dir_ni, ni, fn, le32_to_cpu(actx->attr->value_length))) goto err_out; /* * Keep the last name in place, this is useful for undeletion * (Windows also does so), however delete the name if it were * in an extent, to avoid leaving an attribute list. */ if ((ni->mrec->link_count == const_cpu_to_le16(1)) && !actx->base_ntfs_ino) { /* make sure to not loop to another search */ looking_for_dos_name = FALSE; } else { if (ntfs_attr_record_rm(actx)) goto err_out; } ni->mrec->link_count = cpu_to_le16(le16_to_cpu( ni->mrec->link_count) - 1); ntfs_inode_mark_dirty(ni); if (looking_for_dos_name) { looking_for_dos_name = FALSE; looking_for_win32_name = TRUE; ntfs_attr_reinit_search_ctx(actx); goto search; } /* TODO: Update object id, quota and securiry indexes if required. */ /* * If hard link count is not equal to zero then we are done. In other * case there are no reference to this inode left, so we should free all * non-resident attributes and mark all MFT record as not in use. */ #if CACHE_LOOKUP_SIZE /* invalidate entry in lookup cache */ lkitem.name = (const char*)NULL; lkitem.namesize = 0; lkitem.inum = ni->mft_no; lkitem.parent = dir_ni->mft_no; ntfs_invalidate_cache(vol->lookup_cache, GENERIC(&lkitem), lookup_cache_inv_compare, CACHE_NOHASH); #endif #if CACHE_INODE_SIZE inum = ni->mft_no; if (pathname) { /* invalide cache entry, even if there was an error */ /* Remove leading /'s. */ p = pathname; while (*p == PATH_SEP) p++; if (p[0] && (p[strlen(p)-1] == PATH_SEP)) ntfs_log_error("Unnormalized path %s\n",pathname); item.pathname = p; item.varsize = strlen(p); } else { item.pathname = (const char*)NULL; item.varsize = 0; } item.inum = inum; count = ntfs_invalidate_cache(vol->xinode_cache, GENERIC(&item), inode_cache_inv_compare, CACHE_NOHASH); if (pathname && !count) ntfs_log_error("Could not delete inode cache entry for %s\n", pathname); #endif if (ni->mrec->link_count) { ntfs_inode_update_times(ni, NTFS_UPDATE_CTIME); goto ok; } if (ntfs_delete_reparse_index(ni)) { /* * Failed to remove the reparse index : proceed anyway * This is not a critical error, the entry is useless * because of sequence_number, and stopping file deletion * would be much worse as the file is not referenced now. */ err = errno; } if (ntfs_delete_object_id_index(ni)) { /* * Failed to remove the object id index : proceed anyway * This is not a critical error. */ err = errno; } ntfs_attr_reinit_search_ctx(actx); while (!ntfs_attrs_walk(actx)) { if (actx->attr->non_resident) { runlist *rl; rl = ntfs_mapping_pairs_decompress(ni->vol, actx->attr, NULL); if (!rl) { err = errno; ntfs_log_error("Failed to decompress runlist. " "Leaving inconsistent metadata.\n"); continue; } if (ntfs_cluster_free_from_rl(ni->vol, rl)) { err = errno; ntfs_log_error("Failed to free clusters. " "Leaving inconsistent metadata.\n"); continue; } free(rl); } } if (errno != ENOENT) { err = errno; ntfs_log_error("Attribute enumeration failed. " "Probably leaving inconsistent metadata.\n"); } /* All extents should be attached after attribute walk. */ #if CACHE_NIDATA_SIZE /* * Disconnect extents before deleting them, so they are * not wrongly moved to cache through the chainings */ for (i=ni->nr_extents-1; i>=0; i--) { ni->extent_nis[i]->base_ni = (ntfs_inode*)NULL; ni->extent_nis[i]->nr_extents = 0; if (ntfs_mft_record_free(ni->vol, ni->extent_nis[i])) { err = errno; ntfs_log_error("Failed to free extent MFT record. " "Leaving inconsistent metadata.\n"); } } free(ni->extent_nis); ni->nr_extents = 0; ni->extent_nis = (ntfs_inode**)NULL; #else while (ni->nr_extents) if (ntfs_mft_record_free(ni->vol, *(ni->extent_nis))) { err = errno; ntfs_log_error("Failed to free extent MFT record. " "Leaving inconsistent metadata.\n"); } #endif debug_double_inode(ni->mft_no,0); if (ntfs_mft_record_free(ni->vol, ni)) { err = errno; ntfs_log_error("Failed to free base MFT record. " "Leaving inconsistent metadata.\n"); } ni = NULL; ok: ntfs_inode_update_times(dir_ni, NTFS_UPDATE_MCTIME); out: if (actx) ntfs_attr_put_search_ctx(actx); if (ntfs_inode_close(dir_ni) && !err) err = errno; if (ntfs_inode_close(ni) && !err) err = errno; if (err) { errno = err; ntfs_log_debug("Could not delete file: %s\n", strerror(errno)); return -1; } ntfs_log_trace("Done.\n"); return 0; err_out: err = errno; goto out; } /** * ntfs_link - create hard link for file or directory * @ni: ntfs inode for object to create hard link * @dir_ni: ntfs inode for directory in which new link should be placed * @name: unicode name of the new link * @name_len: length of the name in unicode characters * * NOTE: At present we allow creating hardlinks to directories, we use them * in a temporary state during rename. But it's defenitely bad idea to have * hard links to directories as a result of operation. * FIXME: Create internal __ntfs_link that allows hard links to a directories * and external ntfs_link that do not. Write ntfs_rename that uses __ntfs_link. * * Return 0 on success or -1 on error with errno set to the error code. */ static int ntfs_link_i(ntfs_inode *ni, ntfs_inode *dir_ni, const ntfschar *name, u8 name_len, FILE_NAME_TYPE_FLAGS nametype) { FILE_NAME_ATTR *fn = NULL; int fn_len, err; ntfs_log_trace("Entering.\n"); if (!ni || !dir_ni || !name || !name_len || ni->mft_no == dir_ni->mft_no) { err = EINVAL; ntfs_log_perror("ntfs_link wrong arguments"); goto err_out; } if (NVolHideDotFiles(dir_ni->vol)) { /* Set hidden flag according to the latest name */ if ((name_len > 1) && (name[0] == const_cpu_to_le16('.')) && (name[1] != const_cpu_to_le16('.'))) ni->flags |= FILE_ATTR_HIDDEN; else ni->flags &= ~FILE_ATTR_HIDDEN; } /* Create FILE_NAME attribute. */ fn_len = sizeof(FILE_NAME_ATTR) + name_len * sizeof(ntfschar); fn = ntfs_calloc(fn_len); if (!fn) { err = errno; goto err_out; } fn->parent_directory = MK_LE_MREF(dir_ni->mft_no, le16_to_cpu(dir_ni->mrec->sequence_number)); fn->file_name_length = name_len; fn->file_name_type = nametype; fn->file_attributes = ni->flags; if (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) { fn->file_attributes |= FILE_ATTR_I30_INDEX_PRESENT; fn->data_size = fn->allocated_size = const_cpu_to_sle64(0); } else { fn->allocated_size = cpu_to_sle64(ni->allocated_size); fn->data_size = cpu_to_sle64(ni->data_size); } fn->creation_time = ni->creation_time; fn->last_data_change_time = ni->last_data_change_time; fn->last_mft_change_time = ni->last_mft_change_time; fn->last_access_time = ni->last_access_time; memcpy(fn->file_name, name, name_len * sizeof(ntfschar)); /* Add FILE_NAME attribute to index. */ if (ntfs_index_add_filename(dir_ni, fn, MK_MREF(ni->mft_no, le16_to_cpu(ni->mrec->sequence_number)))) { err = errno; ntfs_log_perror("Failed to add filename to the index"); goto err_out; } /* Add FILE_NAME attribute to inode. */ if (ntfs_attr_add(ni, AT_FILE_NAME, AT_UNNAMED, 0, (u8*)fn, fn_len)) { ntfs_log_error("Failed to add FILE_NAME attribute.\n"); err = errno; /* Try to remove just added attribute from index. */ if (ntfs_index_remove(dir_ni, ni, fn, fn_len)) goto rollback_failed; goto err_out; } /* Increment hard links count. */ ni->mrec->link_count = cpu_to_le16(le16_to_cpu( ni->mrec->link_count) + 1); /* Done! */ ntfs_inode_mark_dirty(ni); free(fn); ntfs_log_trace("Done.\n"); return 0; rollback_failed: ntfs_log_error("Rollback failed. Leaving inconsistent metadata.\n"); err_out: free(fn); errno = err; return -1; } int ntfs_link(ntfs_inode *ni, ntfs_inode *dir_ni, const ntfschar *name, u8 name_len) { return (ntfs_link_i(ni, dir_ni, name, name_len, FILE_NAME_POSIX)); } /* * Get a parent directory from an inode entry * * This is only used in situations where the path used to access * the current file is not known for sure. The result may be different * from the path when the file is linked in several parent directories. * * Currently this is only used for translating ".." in the target * of a Vista relative symbolic link */ ntfs_inode *ntfs_dir_parent_inode(ntfs_inode *ni) { ntfs_inode *dir_ni = (ntfs_inode*)NULL; u64 inum; FILE_NAME_ATTR *fn; ntfs_attr_search_ctx *ctx; if (ni->mft_no != FILE_root) { /* find the name in the attributes */ ctx = ntfs_attr_get_search_ctx(ni, NULL); if (!ctx) return ((ntfs_inode*)NULL); if (!ntfs_attr_lookup(AT_FILE_NAME, AT_UNNAMED, 0, CASE_SENSITIVE, 0, NULL, 0, ctx)) { /* We know this will always be resident. */ fn = (FILE_NAME_ATTR*)((u8*)ctx->attr + le16_to_cpu(ctx->attr->value_offset)); inum = le64_to_cpu(fn->parent_directory); if (inum != (u64)-1) { dir_ni = ntfs_inode_open(ni->vol, MREF(inum)); } } ntfs_attr_put_search_ctx(ctx); } return (dir_ni); } #define MAX_DOS_NAME_LENGTH 12 /* * Get a DOS name for a file in designated directory * * Not allowed if there are several non-dos names (EMLINK) * * Returns size if found * 0 if not found * -1 if there was an error (described by errno) */ static int get_dos_name(ntfs_inode *ni, u64 dnum, ntfschar *dosname) { size_t outsize = 0; int namecount = 0; FILE_NAME_ATTR *fn; ntfs_attr_search_ctx *ctx; /* find the name in the attributes */ ctx = ntfs_attr_get_search_ctx(ni, NULL); if (!ctx) return -1; while (!ntfs_attr_lookup(AT_FILE_NAME, AT_UNNAMED, 0, CASE_SENSITIVE, 0, NULL, 0, ctx)) { /* We know this will always be resident. */ fn = (FILE_NAME_ATTR*)((u8*)ctx->attr + le16_to_cpu(ctx->attr->value_offset)); if (fn->file_name_type != FILE_NAME_DOS) namecount++; if ((fn->file_name_type & FILE_NAME_DOS) && (MREF_LE(fn->parent_directory) == dnum)) { /* * Found a DOS or WIN32+DOS name for the entry * copy name, after truncation for safety */ outsize = fn->file_name_length; /* TODO : reject if name is too long ? */ if (outsize > MAX_DOS_NAME_LENGTH) outsize = MAX_DOS_NAME_LENGTH; memcpy(dosname,fn->file_name,outsize*sizeof(ntfschar)); } } ntfs_attr_put_search_ctx(ctx); if ((outsize > 0) && (namecount > 1)) { outsize = -1; errno = EMLINK; /* this error implies there is a dos name */ } return (outsize); } /* * Get a long name for a file in designated directory * * Not allowed if there are several non-dos names (EMLINK) * * Returns size if found * 0 if not found * -1 if there was an error (described by errno) */ static int get_long_name(ntfs_inode *ni, u64 dnum, ntfschar *longname) { size_t outsize = 0; int namecount = 0; FILE_NAME_ATTR *fn; ntfs_attr_search_ctx *ctx; /* find the name in the attributes */ ctx = ntfs_attr_get_search_ctx(ni, NULL); if (!ctx) return -1; /* first search for WIN32 or DOS+WIN32 names */ while (!ntfs_attr_lookup(AT_FILE_NAME, AT_UNNAMED, 0, CASE_SENSITIVE, 0, NULL, 0, ctx)) { /* We know this will always be resident. */ fn = (FILE_NAME_ATTR*)((u8*)ctx->attr + le16_to_cpu(ctx->attr->value_offset)); if (fn->file_name_type != FILE_NAME_DOS) namecount++; if ((fn->file_name_type & FILE_NAME_WIN32) && (MREF_LE(fn->parent_directory) == dnum)) { /* * Found a WIN32 or WIN32+DOS name for the entry * copy name */ outsize = fn->file_name_length; memcpy(longname,fn->file_name,outsize*sizeof(ntfschar)); } } if (namecount > 1) { ntfs_attr_put_search_ctx(ctx); errno = EMLINK; return -1; } /* if not found search for POSIX names */ if (!outsize) { ntfs_attr_reinit_search_ctx(ctx); while (!ntfs_attr_lookup(AT_FILE_NAME, AT_UNNAMED, 0, CASE_SENSITIVE, 0, NULL, 0, ctx)) { /* We know this will always be resident. */ fn = (FILE_NAME_ATTR*)((u8*)ctx->attr + le16_to_cpu(ctx->attr->value_offset)); if ((fn->file_name_type == FILE_NAME_POSIX) && (MREF_LE(fn->parent_directory) == dnum)) { /* * Found a POSIX name for the entry * copy name */ outsize = fn->file_name_length; memcpy(longname,fn->file_name,outsize*sizeof(ntfschar)); } } } ntfs_attr_put_search_ctx(ctx); return (outsize); } /* * Get the ntfs DOS name into an extended attribute */ int ntfs_get_ntfs_dos_name(ntfs_inode *ni, ntfs_inode *dir_ni, char *value, size_t size) { int outsize = 0; char *outname = (char*)NULL; u64 dnum; int doslen; ntfschar dosname[MAX_DOS_NAME_LENGTH]; dnum = dir_ni->mft_no; doslen = get_dos_name(ni, dnum, dosname); if (doslen > 0) { /* * Found a DOS name for the entry, make * uppercase and encode into the buffer * if there is enough space */ ntfs_name_upcase(dosname, doslen, ni->vol->upcase, ni->vol->upcase_len); outsize = ntfs_ucstombs(dosname, doslen, &outname, 0); if (outsize < 0) { ntfs_log_error("Cannot represent dosname in current locale.\n"); outsize = -errno; } else { if (value && (outsize <= (int)size)) memcpy(value, outname, outsize); else if (size && (outsize > (int)size)) outsize = -ERANGE; free(outname); } } else { if (doslen == 0) errno = ENODATA; outsize = -errno; } return (outsize); } /* * Change the name space of an existing file or directory * * Returns the old namespace if successful * -1 if an error occurred (described by errno) */ static int set_namespace(ntfs_inode *ni, ntfs_inode *dir_ni, const ntfschar *name, int len, FILE_NAME_TYPE_FLAGS nametype) { ntfs_attr_search_ctx *actx; ntfs_index_context *icx; FILE_NAME_ATTR *fnx; FILE_NAME_ATTR *fn = NULL; BOOL found; int lkup; int ret; ret = -1; actx = ntfs_attr_get_search_ctx(ni, NULL); if (actx) { found = FALSE; do { lkup = ntfs_attr_lookup(AT_FILE_NAME, AT_UNNAMED, 0, CASE_SENSITIVE, 0, NULL, 0, actx); if (!lkup) { fn = (FILE_NAME_ATTR*)((u8*)actx->attr + le16_to_cpu(actx->attr->value_offset)); found = (MREF_LE(fn->parent_directory) == dir_ni->mft_no) && !memcmp(fn->file_name, name, len*sizeof(ntfschar)); } } while (!lkup && !found); if (found) { icx = ntfs_index_ctx_get(dir_ni, NTFS_INDEX_I30, 4); if (icx) { lkup = ntfs_index_lookup((char*)fn, len, icx); if (!lkup && icx->data && icx->data_len) { fnx = (FILE_NAME_ATTR*)icx->data; ret = fn->file_name_type; fn->file_name_type = nametype; fnx->file_name_type = nametype; ntfs_inode_mark_dirty(ni); ntfs_index_entry_mark_dirty(icx); } ntfs_index_ctx_put(icx); } } ntfs_attr_put_search_ctx(actx); } return (ret); } /* * Set a DOS name to a file and adjust name spaces * * If the new names are collapsible (same uppercased chars) : * * - the existing DOS name or DOS+Win32 name is made Posix * - if it was a real DOS name, the existing long name is made DOS+Win32 * and the existing DOS name is deleted * - finally the existing long name is made DOS+Win32 unless already done * * If the new names are not collapsible : * * - insert the short name as a DOS name * - delete the old long name or existing short name * - insert the new long name (as a Win32 or DOS+Win32 name) * * Deleting the old long name will not delete the file * provided the old name was in the Posix name space, * because the alternate name has been set before. * * The inodes of file and parent directory are always closed * * Returns 0 if successful * -1 if failed */ static int set_dos_name(ntfs_inode *ni, ntfs_inode *dir_ni, const ntfschar *shortname, int shortlen, const ntfschar *longname, int longlen, const ntfschar *deletename, int deletelen, BOOL existed) { unsigned int linkcount; ntfs_volume *vol; BOOL collapsible; BOOL deleted; BOOL done; FILE_NAME_TYPE_FLAGS oldnametype; u64 dnum; u64 fnum; int res; res = -1; vol = ni->vol; dnum = dir_ni->mft_no; fnum = ni->mft_no; /* save initial link count */ linkcount = le16_to_cpu(ni->mrec->link_count); /* check whether the same name may be used as DOS and WIN32 */ collapsible = ntfs_collapsible_chars(ni->vol, shortname, shortlen, longname, longlen); if (collapsible) { deleted = FALSE; done = FALSE; if (existed) { oldnametype = set_namespace(ni, dir_ni, deletename, deletelen, FILE_NAME_POSIX); if (oldnametype == FILE_NAME_DOS) { if (set_namespace(ni, dir_ni, longname, longlen, FILE_NAME_WIN32_AND_DOS) >= 0) { if (!ntfs_delete(vol, (const char*)NULL, ni, dir_ni, deletename, deletelen)) res = 0; deleted = TRUE; } else done = TRUE; } } if (!deleted) { if (!done && (set_namespace(ni, dir_ni, longname, longlen, FILE_NAME_WIN32_AND_DOS) >= 0)) res = 0; ntfs_inode_update_times(ni, NTFS_UPDATE_CTIME); ntfs_inode_update_times(dir_ni, NTFS_UPDATE_MCTIME); if (ntfs_inode_close_in_dir(ni,dir_ni) && !res) res = -1; if (ntfs_inode_close(dir_ni) && !res) res = -1; } } else { if (!ntfs_link_i(ni, dir_ni, shortname, shortlen, FILE_NAME_DOS) /* make sure a new link was recorded */ && (le16_to_cpu(ni->mrec->link_count) > linkcount)) { /* delete the existing long name or short name */ // is it ok to not provide the path ? if (!ntfs_delete(vol, (char*)NULL, ni, dir_ni, deletename, deletelen)) { /* delete closes the inodes, so have to open again */ dir_ni = ntfs_inode_open(vol, dnum); if (dir_ni) { ni = ntfs_inode_open(vol, fnum); if (ni) { if (!ntfs_link_i(ni, dir_ni, longname, longlen, FILE_NAME_WIN32)) res = 0; if (ntfs_inode_close_in_dir(ni, dir_ni) && !res) res = -1; } if (ntfs_inode_close(dir_ni) && !res) res = -1; } } } else { ntfs_inode_close_in_dir(ni,dir_ni); ntfs_inode_close(dir_ni); } } return (res); } /* * Set the ntfs DOS name into an extended attribute * * The DOS name will be added as another file name attribute * using the existing file name information from the original * name or overwriting the DOS Name if one exists. * * The inode of the file is always closed */ int ntfs_set_ntfs_dos_name(ntfs_inode *ni, ntfs_inode *dir_ni, const char *value, size_t size, int flags) { int res = 0; int longlen = 0; int shortlen = 0; char newname[3*MAX_DOS_NAME_LENGTH + 1]; ntfschar oldname[MAX_DOS_NAME_LENGTH]; int oldlen; u64 dnum; BOOL closed = FALSE; ntfschar *shortname = NULL; ntfschar longname[NTFS_MAX_NAME_LEN]; /* copy the string to insert a null char, and truncate */ if (size > 3*MAX_DOS_NAME_LENGTH) size = 3*MAX_DOS_NAME_LENGTH; strncpy(newname, value, size); /* a long name may be truncated badly and be untranslatable */ newname[size] = 0; /* convert the string to the NTFS wide chars, and truncate */ shortlen = ntfs_mbstoucs(newname, &shortname); if (shortlen > MAX_DOS_NAME_LENGTH) shortlen = MAX_DOS_NAME_LENGTH; /* Make sure the short name has valid chars. * Note: the short name cannot end with dot or space, but the * corresponding long name can. */ if ((shortlen < 0) || ntfs_forbidden_names(ni->vol,shortname,shortlen,TRUE)) { ntfs_inode_close_in_dir(ni,dir_ni); ntfs_inode_close(dir_ni); res = -errno; return res; } dnum = dir_ni->mft_no; longlen = get_long_name(ni, dnum, longname); if (longlen > 0) { oldlen = get_dos_name(ni, dnum, oldname); if ((oldlen >= 0) && !ntfs_forbidden_names(ni->vol, longname, longlen, FALSE)) { if (oldlen > 0) { if (flags & XATTR_CREATE) { res = -1; errno = EEXIST; } else if ((shortlen == oldlen) && !memcmp(shortname,oldname, oldlen*sizeof(ntfschar))) /* already set, done */ res = 0; else { res = set_dos_name(ni, dir_ni, shortname, shortlen, longname, longlen, oldname, oldlen, TRUE); closed = TRUE; } } else { if (flags & XATTR_REPLACE) { res = -1; errno = ENODATA; } else { res = set_dos_name(ni, dir_ni, shortname, shortlen, longname, longlen, longname, longlen, FALSE); closed = TRUE; } } } else res = -1; } else { res = -1; if (!longlen) errno = ENOENT; } free(shortname); if (!closed) { ntfs_inode_close_in_dir(ni,dir_ni); ntfs_inode_close(dir_ni); } return (res ? -1 : 0); } /* * Delete the ntfs DOS name */ int ntfs_remove_ntfs_dos_name(ntfs_inode *ni, ntfs_inode *dir_ni) { int res; int oldnametype; int longlen = 0; int shortlen; u64 dnum; ntfs_volume *vol; BOOL deleted = FALSE; ntfschar shortname[MAX_DOS_NAME_LENGTH]; ntfschar longname[NTFS_MAX_NAME_LEN]; res = -1; vol = ni->vol; dnum = dir_ni->mft_no; longlen = get_long_name(ni, dnum, longname); if (longlen > 0) { shortlen = get_dos_name(ni, dnum, shortname); if (shortlen >= 0) { /* migrate the long name as Posix */ oldnametype = set_namespace(ni,dir_ni,longname,longlen, FILE_NAME_POSIX); switch (oldnametype) { case FILE_NAME_WIN32_AND_DOS : /* name was Win32+DOS : done */ res = 0; break; case FILE_NAME_DOS : /* name was DOS, make it back to DOS */ set_namespace(ni,dir_ni,longname,longlen, FILE_NAME_DOS); errno = ENOENT; break; case FILE_NAME_WIN32 : /* name was Win32, make it Posix and delete */ if (set_namespace(ni,dir_ni,shortname,shortlen, FILE_NAME_POSIX) >= 0) { if (!ntfs_delete(vol, (const char*)NULL, ni, dir_ni, shortname, shortlen)) res = 0; deleted = TRUE; } else { /* * DOS name has been found, but cannot * migrate to Posix : something bad * has happened */ errno = EIO; ntfs_log_error("Could not change" " DOS name of inode %lld to Posix\n", (long long)ni->mft_no); } break; default : /* name was Posix or not found : error */ errno = ENOENT; break; } } } else { if (!longlen) errno = ENOENT; res = -1; } if (!deleted) { ntfs_inode_close_in_dir(ni,dir_ni); ntfs_inode_close(dir_ni); } return (res); } /* * Increment the count of subdirectories * (excluding entries with a short name) */ static int nlink_increment(void *nlink_ptr, const ntfschar *name __attribute__((unused)), const int len __attribute__((unused)), const int type, const s64 pos __attribute__((unused)), const MFT_REF mref __attribute__((unused)), const unsigned int dt_type) { if ((dt_type == NTFS_DT_DIR) && (type != FILE_NAME_DOS)) (*((int*)nlink_ptr))++; return (0); } /* * Compute the number of hard links according to Posix * For a directory count the subdirectories whose name is not * a short one, but count "." and ".." * Otherwise count the names, excluding the short ones. * * if there is an error, a null count is returned. */ int ntfs_dir_link_cnt(ntfs_inode *ni) { ntfs_attr_search_ctx *actx; FILE_NAME_ATTR *fn; s64 pos; int err = 0; int nlink = 0; if (!ni) { ntfs_log_error("Invalid argument.\n"); errno = EINVAL; goto err_out; } if (ni->nr_extents == -1) ni = ni->base_ni; if (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) { /* * Directory : scan the directory and count * subdirectories whose name is not DOS-only. * The directory names are ignored, but "." and ".." * are taken into account. */ pos = 0; err = ntfs_readdir(ni, &pos, &nlink, nlink_increment); if (err) nlink = 0; } else { /* * Non-directory : search for FILE_NAME attributes, * and count those which are not DOS-only ones. */ actx = ntfs_attr_get_search_ctx(ni, NULL); if (!actx) goto err_out; while (!(err = ntfs_attr_lookup(AT_FILE_NAME, AT_UNNAMED, 0, CASE_SENSITIVE, 0, NULL, 0, actx))) { fn = (FILE_NAME_ATTR*)((u8*)actx->attr + le16_to_cpu(actx->attr->value_offset)); if (fn->file_name_type != FILE_NAME_DOS) nlink++; } if (err && (errno != ENOENT)) nlink = 0; ntfs_attr_put_search_ctx(actx); } if (!nlink) ntfs_log_perror("Failed to compute nlink of inode %lld", (long long)ni->mft_no); err_out : return (nlink); } ntfs-3g-2026.2.25/libntfs-3g/unistr.c0000664000175000017500000013722515152260173012452 /** * unistr.c - Unicode string handling. Originated from the Linux-NTFS project. * * Copyright (c) 2000-2004 Anton Altaparmakov * Copyright (c) 2002-2009 Szabolcs Szakacsits * Copyright (c) 2008-2015 Jean-Pierre Andre * Copyright (c) 2008 Bernhard Kaindl * * This program/include file 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/include file 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_STDIO_H #include #endif #ifdef HAVE_STDLIB_H #include #endif #ifdef HAVE_WCHAR_H #include #endif #ifdef HAVE_STRING_H #include #endif #ifdef HAVE_ERRNO_H #include #endif #ifdef HAVE_LOCALE_H #include #endif #if defined(__APPLE__) || defined(__DARWIN__) #ifdef ENABLE_NFCONV #include #endif /* ENABLE_NFCONV */ #endif /* defined(__APPLE__) || defined(__DARWIN__) */ #include "compat.h" #include "attrib.h" #include "types.h" #include "unistr.h" #include "debug.h" #include "logging.h" #include "misc.h" #ifndef ALLOW_BROKEN_UNICODE /* Erik allowing broken UTF-16 surrogate pairs and U+FFFE and U+FFFF by default, * open to debate. */ #define ALLOW_BROKEN_UNICODE 1 #endif /* !defined(ALLOW_BROKEN_UNICODE) */ /* * IMPORTANT * ========= * * All these routines assume that the Unicode characters are in little endian * encoding inside the strings!!! */ static int use_utf8 = 1; /* use UTF-8 encoding for file names */ #if defined(__APPLE__) || defined(__DARWIN__) #ifdef ENABLE_NFCONV /** * This variable controls whether or not automatic normalization form conversion * should be performed when translating NTFS unicode file names to UTF-8. * Defaults to on, but can be controlled from the outside using the function * int ntfs_macosx_normalize_filenames(int normalize); */ static int nfconvert_utf8 = 1; #endif /* ENABLE_NFCONV */ #endif /* defined(__APPLE__) || defined(__DARWIN__) */ /* * This is used by the name collation functions to quickly determine what * characters are (in)valid. */ #if 0 static const u8 legal_ansi_char_array[0x40] = { 0x00, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x17, 0x07, 0x18, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x18, 0x16, 0x16, 0x17, 0x07, 0x00, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x04, 0x16, 0x18, 0x16, 0x18, 0x18, }; #endif /** * ntfs_names_are_equal - compare two Unicode names for equality * @s1: name to compare to @s2 * @s1_len: length in Unicode characters of @s1 * @s2: name to compare to @s1 * @s2_len: length in Unicode characters of @s2 * @ic: ignore case bool * @upcase: upcase table (only if @ic == IGNORE_CASE) * @upcase_size: length in Unicode characters of @upcase (if present) * * Compare the names @s1 and @s2 and return TRUE (1) if the names are * identical, or FALSE (0) if they are not identical. If @ic is IGNORE_CASE, * the @upcase table is used to perform a case insensitive comparison. */ BOOL ntfs_names_are_equal(const ntfschar *s1, size_t s1_len, const ntfschar *s2, size_t s2_len, const IGNORE_CASE_BOOL ic, const ntfschar *upcase, const u32 upcase_size) { if (s1_len != s2_len) return FALSE; if (!s1_len) return TRUE; if (ic == CASE_SENSITIVE) return ntfs_ucsncmp(s1, s2, s1_len) ? FALSE: TRUE; return ntfs_ucsncasecmp(s1, s2, s1_len, upcase, upcase_size) ? FALSE: TRUE; } /* * ntfs_names_full_collate() fully collate two Unicode names * * @name1: first Unicode name to compare * @name1_len: length of first Unicode name to compare * @name2: second Unicode name to compare * @name2_len: length of second Unicode name to compare * @ic: either CASE_SENSITIVE or IGNORE_CASE (see below) * @upcase: upcase table * @upcase_len: upcase table size * * If @ic is CASE_SENSITIVE, then the names are compared primarily ignoring * case, but if the names are equal ignoring case, then they are compared * case-sensitively. As an example, "abc" would collate before "BCD" (since * "abc" and "BCD" differ ignoring case and 'A' < 'B') but after "ABC" (since * "ABC" and "abc" are equal ignoring case and 'A' < 'a'). This matches the * collation order of filenames as indexed in NTFS directories. * * If @ic is IGNORE_CASE, then the names are only compared case-insensitively * and are considered to match if and only if they are equal ignoring case. * * Returns: * -1 if the first name collates before the second one, * 0 if the names match, or * 1 if the second name collates before the first one */ int ntfs_names_full_collate(const ntfschar *name1, const u32 name1_len, const ntfschar *name2, const u32 name2_len, const IGNORE_CASE_BOOL ic, const ntfschar *upcase, const u32 upcase_len) { u32 cnt; u16 c1, c2; u16 u1, u2; #ifdef DEBUG if (!name1 || !name2 || !upcase || !upcase_len) { ntfs_log_debug("ntfs_names_collate received NULL pointer!\n"); exit(1); } #endif cnt = min(name1_len, name2_len); if (cnt > 0) { if (ic == CASE_SENSITIVE) { while (--cnt && (*name1 == *name2)) { name1++; name2++; } u1 = c1 = le16_to_cpu(*name1); u2 = c2 = le16_to_cpu(*name2); if (u1 < upcase_len) u1 = le16_to_cpu(upcase[u1]); if (u2 < upcase_len) u2 = le16_to_cpu(upcase[u2]); if ((u1 == u2) && cnt) do { name1++; u1 = le16_to_cpu(*name1); name2++; u2 = le16_to_cpu(*name2); if (u1 < upcase_len) u1 = le16_to_cpu(upcase[u1]); if (u2 < upcase_len) u2 = le16_to_cpu(upcase[u2]); } while ((u1 == u2) && --cnt); if (u1 < u2) return -1; if (u1 > u2) return 1; if (name1_len < name2_len) return -1; if (name1_len > name2_len) return 1; if (c1 < c2) return -1; if (c1 > c2) return 1; } else { do { u1 = le16_to_cpu(*name1); name1++; u2 = le16_to_cpu(*name2); name2++; if (u1 < upcase_len) u1 = le16_to_cpu(upcase[u1]); if (u2 < upcase_len) u2 = le16_to_cpu(upcase[u2]); } while ((u1 == u2) && --cnt); if (u1 < u2) return -1; if (u1 > u2) return 1; if (name1_len < name2_len) return -1; if (name1_len > name2_len) return 1; } } else { if (name1_len < name2_len) return -1; if (name1_len > name2_len) return 1; } return 0; } /** * ntfs_ucsncmp - compare two little endian Unicode strings * @s1: first string * @s2: second string * @n: maximum unicode characters to compare * * Compare the first @n characters of the Unicode strings @s1 and @s2, * The strings in little endian format and appropriate le16_to_cpu() * conversion is performed on non-little endian machines. * * The function returns an integer less than, equal to, or greater than zero * if @s1 (or the first @n Unicode characters thereof) is found, respectively, * to be less than, to match, or be greater than @s2. */ int ntfs_ucsncmp(const ntfschar *s1, const ntfschar *s2, size_t n) { u16 c1, c2; size_t i; #ifdef DEBUG if (!s1 || !s2) { ntfs_log_debug("ntfs_wcsncmp() received NULL pointer!\n"); exit(1); } #endif for (i = 0; i < n; ++i) { c1 = le16_to_cpu(s1[i]); c2 = le16_to_cpu(s2[i]); if (c1 < c2) return -1; if (c1 > c2) return 1; if (!c1) break; } return 0; } /** * ntfs_ucsncasecmp - compare two little endian Unicode strings, ignoring case * @s1: first string * @s2: second string * @n: maximum unicode characters to compare * @upcase: upcase table * @upcase_size: upcase table size in Unicode characters * * Compare the first @n characters of the Unicode strings @s1 and @s2, * ignoring case. The strings in little endian format and appropriate * le16_to_cpu() conversion is performed on non-little endian machines. * * Each character is uppercased using the @upcase table before the comparison. * * The function returns an integer less than, equal to, or greater than zero * if @s1 (or the first @n Unicode characters thereof) is found, respectively, * to be less than, to match, or be greater than @s2. */ int ntfs_ucsncasecmp(const ntfschar *s1, const ntfschar *s2, size_t n, const ntfschar *upcase, const u32 upcase_size) { u16 c1, c2; size_t i; #ifdef DEBUG if (!s1 || !s2 || !upcase) { ntfs_log_debug("ntfs_wcsncasecmp() received NULL pointer!\n"); exit(1); } #endif for (i = 0; i < n; ++i) { if ((c1 = le16_to_cpu(s1[i])) < upcase_size) c1 = le16_to_cpu(upcase[c1]); if ((c2 = le16_to_cpu(s2[i])) < upcase_size) c2 = le16_to_cpu(upcase[c2]); if (c1 < c2) return -1; if (c1 > c2) return 1; if (!c1) break; } return 0; } /** * ntfs_ucsnlen - determine the length of a little endian Unicode string * @s: pointer to Unicode string * @maxlen: maximum length of string @s * * Return the number of Unicode characters in the little endian Unicode * string @s up to a maximum of maxlen Unicode characters, not including * the terminating (ntfschar)'\0'. If there is no (ntfschar)'\0' between @s * and @s + @maxlen, @maxlen is returned. * * This function never looks beyond @s + @maxlen. */ u32 ntfs_ucsnlen(const ntfschar *s, u32 maxlen) { u32 i; for (i = 0; i < maxlen; i++) { if (!le16_to_cpu(s[i])) break; } return i; } /** * ntfs_ucsndup - duplicate little endian Unicode string * @s: pointer to Unicode string * @maxlen: maximum length of string @s * * Return a pointer to a new little endian Unicode string which is a duplicate * of the string s. Memory for the new string is obtained with ntfs_malloc(3), * and can be freed with free(3). * * A maximum of @maxlen Unicode characters are copied and a terminating * (ntfschar)'\0' little endian Unicode character is added. * * This function never looks beyond @s + @maxlen. * * Return a pointer to the new little endian Unicode string on success and NULL * on failure with errno set to the error code. */ ntfschar *ntfs_ucsndup(const ntfschar *s, u32 maxlen) { ntfschar *dst; u32 len; len = ntfs_ucsnlen(s, maxlen); dst = ntfs_malloc((len + 1) * sizeof(ntfschar)); if (dst) { memcpy(dst, s, len * sizeof(ntfschar)); dst[len] = const_cpu_to_le16(L'\0'); } return dst; } /** * ntfs_name_upcase - Map an Unicode name to its uppercase equivalent * @name: * @name_len: * @upcase: * @upcase_len: * * Description... * * Returns: */ void ntfs_name_upcase(ntfschar *name, u32 name_len, const ntfschar *upcase, const u32 upcase_len) { u32 i; u16 u; for (i = 0; i < name_len; i++) if ((u = le16_to_cpu(name[i])) < upcase_len) name[i] = upcase[u]; } /** * ntfs_name_locase - Map a Unicode name to its lowercase equivalent */ void ntfs_name_locase(ntfschar *name, u32 name_len, const ntfschar *locase, const u32 locase_len) { u32 i; u16 u; if (locase) for (i = 0; i < name_len; i++) if ((u = le16_to_cpu(name[i])) < locase_len) name[i] = locase[u]; } /** * ntfs_file_value_upcase - Convert a filename to upper case * @file_name_attr: * @upcase: * @upcase_len: * * Description... * * Returns: */ void ntfs_file_value_upcase(FILE_NAME_ATTR *file_name_attr, const ntfschar *upcase, const u32 upcase_len) { ntfs_name_upcase((ntfschar*)&file_name_attr->file_name, file_name_attr->file_name_length, upcase, upcase_len); } /* NTFS uses Unicode (UTF-16LE [NTFS-3G uses UCS-2LE, which is enough for now]) for path names, but the Unicode code points need to be converted before a path can be accessed under NTFS. For 7 bit ASCII/ANSI, glibc does this even without a locale in a hard-coded fashion as that appears to be is easy because the low 7-bit ASCII range appears to be available in all charsets but it does not convert anything if there was some error with the locale setup or none set up like when mount is called during early boot where he (by policy) do not use locales (and may be not available if /usr is not yet mounted), so this patch fixes the resulting issues for systems which use UTF-8 and for others, specifying the locale in fstab brings them the encoding which they want. If no locale is defined or there was a problem with setting one up and whenever nl_langinfo(CODESET) returns a sting starting with "ANSI", use an internal UCS-2LE <-> UTF-8 codeset converter to fix the bug where NTFS-3G does not show any path names which include international characters!!! (and also fails on creating them) as result. Author: Bernhard Kaindl Jean-Pierre Andre made it compliant with RFC3629/RFC2781. */ /* * Return the number of bytes in UTF-8 needed (without the terminating null) to * store the given UTF-16LE string. * * On error, -1 is returned, and errno is set to the error code. The following * error codes can be expected: * EILSEQ The input string is not valid UTF-16LE (only possible * if compiled without ALLOW_BROKEN_UNICODE). * ENAMETOOLONG The length of the UTF-8 string in bytes (without the * terminating null) would exceed @outs_len. */ static int utf16_to_utf8_size(const ntfschar *ins, const int ins_len, int outs_len) { int i, ret = -1; int count = 0; BOOL surrog; surrog = FALSE; for (i = 0; i < ins_len && ins[i] && count <= outs_len; i++) { unsigned short c = le16_to_cpu(ins[i]); if (surrog) { if ((c >= 0xdc00) && (c < 0xe000)) { surrog = FALSE; count += 4; } else { #if ALLOW_BROKEN_UNICODE /* The first UTF-16 unit of a surrogate pair has * a value between 0xd800 and 0xdc00. It can be * encoded as an individual UTF-8 sequence if we * cannot combine it with the next UTF-16 unit * unit as a surrogate pair. */ surrog = FALSE; count += 3; --i; continue; #else goto fail; #endif /* ALLOW_BROKEN_UNICODE */ } } else if (c < 0x80) count++; else if (c < 0x800) count += 2; else if (c < 0xd800) count += 3; else if (c < 0xdc00) surrog = TRUE; #if ALLOW_BROKEN_UNICODE else if (c < 0xe000) count += 3; else if (c >= 0xe000) #else else if ((c >= 0xe000) && (c < 0xfffe)) #endif /* ALLOW_BROKEN_UNICODE */ count += 3; else goto fail; } if (surrog && count <= outs_len) { #if ALLOW_BROKEN_UNICODE count += 3; /* ending with a single surrogate */ #else goto fail; #endif /* ALLOW_BROKEN_UNICODE */ } if (count > outs_len) { errno = ENAMETOOLONG; goto out; } ret = count; out: return ret; fail: errno = EILSEQ; goto out; } /* * ntfs_utf16_to_utf8 - convert a little endian UTF16LE string to an UTF-8 string * @ins: input utf16 string buffer * @ins_len: length of input string in utf16 characters * @outs: on return contains the (allocated) output multibyte string * @outs_len: length of output buffer in bytes (ignored if *@outs is NULL) * * Return -1 with errno set if string has invalid byte sequence or too long. */ static int ntfs_utf16_to_utf8(const ntfschar *ins, const int ins_len, char **outs, int outs_len) { #if defined(__APPLE__) || defined(__DARWIN__) #ifdef ENABLE_NFCONV char *original_outs_value = *outs; int original_outs_len = outs_len; #endif /* ENABLE_NFCONV */ #endif /* defined(__APPLE__) || defined(__DARWIN__) */ char *t; int i, size, ret = -1; int halfpair; halfpair = 0; if (!*outs) { /* If no output buffer was provided, we will allocate one and * limit its length to PATH_MAX. Note: we follow the standard * convention of PATH_MAX including the terminating null. */ outs_len = PATH_MAX; } /* The size *with* the terminating null is limited to @outs_len, * so the size *without* the terminating null is limited to one less. */ size = utf16_to_utf8_size(ins, ins_len, outs_len - 1); if (size < 0) goto out; if (!*outs) { outs_len = size + 1; *outs = ntfs_malloc(outs_len); if (!*outs) goto out; } t = *outs; for (i = 0; i < ins_len && ins[i]; i++) { unsigned short c = le16_to_cpu(ins[i]); /* size not double-checked */ if (halfpair) { if ((c >= 0xdc00) && (c < 0xe000)) { *t++ = 0xf0 + (((halfpair + 64) >> 8) & 7); *t++ = 0x80 + (((halfpair + 64) >> 2) & 63); *t++ = 0x80 + ((c >> 6) & 15) + ((halfpair & 3) << 4); *t++ = 0x80 + (c & 63); halfpair = 0; } else { #if ALLOW_BROKEN_UNICODE /* The first UTF-16 unit of a surrogate pair has * a value between 0xd800 and 0xdc00. It can be * encoded as an individual UTF-8 sequence if we * cannot combine it with the next UTF-16 unit * unit as a surrogate pair. */ *t++ = 0xe0 | (halfpair >> 12); *t++ = 0x80 | ((halfpair >> 6) & 0x3f); *t++ = 0x80 | (halfpair & 0x3f); halfpair = 0; --i; continue; #else goto fail; #endif /* ALLOW_BROKEN_UNICODE */ } } else if (c < 0x80) { *t++ = c; } else { if (c < 0x800) { *t++ = (0xc0 | ((c >> 6) & 0x3f)); *t++ = 0x80 | (c & 0x3f); } else if (c < 0xd800) { *t++ = 0xe0 | (c >> 12); *t++ = 0x80 | ((c >> 6) & 0x3f); *t++ = 0x80 | (c & 0x3f); } else if (c < 0xdc00) halfpair = c; #if ALLOW_BROKEN_UNICODE else if (c < 0xe000) { *t++ = 0xe0 | (c >> 12); *t++ = 0x80 | ((c >> 6) & 0x3f); *t++ = 0x80 | (c & 0x3f); } #endif /* ALLOW_BROKEN_UNICODE */ else if (c >= 0xe000) { *t++ = 0xe0 | (c >> 12); *t++ = 0x80 | ((c >> 6) & 0x3f); *t++ = 0x80 | (c & 0x3f); } else goto fail; } } #if ALLOW_BROKEN_UNICODE if (halfpair) { /* ending with a single surrogate */ *t++ = 0xe0 | (halfpair >> 12); *t++ = 0x80 | ((halfpair >> 6) & 0x3f); *t++ = 0x80 | (halfpair & 0x3f); } #endif /* ALLOW_BROKEN_UNICODE */ *t = '\0'; #if defined(__APPLE__) || defined(__DARWIN__) #ifdef ENABLE_NFCONV if(nfconvert_utf8 && (t - *outs) > 0) { char *new_outs = NULL; int new_outs_len = ntfs_macosx_normalize_utf8(*outs, &new_outs, 0); // Normalize to decomposed form if(new_outs_len >= 0 && new_outs != NULL) { if(original_outs_value != *outs) { // We have allocated outs ourselves. free(*outs); *outs = new_outs; t = *outs + new_outs_len; } else { // We need to copy new_outs into the fixed outs buffer. memset(*outs, 0, original_outs_len); strncpy(*outs, new_outs, original_outs_len-1); t = *outs + original_outs_len; free(new_outs); } } else { ntfs_log_error("Failed to normalize NTFS string to UTF-8 NFD: %s\n", *outs); ntfs_log_error(" new_outs=0x%p\n", new_outs); ntfs_log_error(" new_outs_len=%d\n", new_outs_len); } } #endif /* ENABLE_NFCONV */ #endif /* defined(__APPLE__) || defined(__DARWIN__) */ ret = t - *outs; out: return ret; fail: errno = EILSEQ; goto out; } /* * Return the amount of 16-bit elements in UTF-16LE needed * (without the terminating null) to store given UTF-8 string. * * Return -1 with errno set if it's longer than PATH_MAX or string is invalid. * * Note: This does not check whether the input sequence is a valid utf8 string, * and should be used only in context where such check is made! */ static int utf8_to_utf16_size(const char *s) { int ret = -1; unsigned int byte; size_t count = 0; while ((byte = *((const unsigned char *)s++))) { if (++count >= PATH_MAX) goto fail; if (byte >= 0xc0) { if (byte >= 0xF5) { errno = EILSEQ; goto out; } if (!*s) break; if (byte >= 0xC0) s++; if (!*s) break; if (byte >= 0xE0) s++; if (!*s) break; if (byte >= 0xF0) { s++; if (++count >= PATH_MAX) goto fail; } } } ret = count; out: return ret; fail: errno = ENAMETOOLONG; goto out; } /* * This converts one UTF-8 sequence to cpu-endian Unicode value * within range U+0 .. U+10ffff and excluding U+D800 .. U+DFFF * * Return the number of used utf8 bytes or -1 with errno set * if sequence is invalid. */ static int utf8_to_unicode(u32 *wc, const char *s) { unsigned int byte = *((const unsigned char *)s); /* single byte */ if (byte == 0) { *wc = (u32) 0; return 0; } else if (byte < 0x80) { *wc = (u32) byte; return 1; /* double byte */ } else if (byte < 0xc2) { goto fail; } else if (byte < 0xE0) { if ((s[1] & 0xC0) == 0x80) { *wc = ((u32)(byte & 0x1F) << 6) | ((u32)(s[1] & 0x3F)); return 2; } else goto fail; /* three-byte */ } else if (byte < 0xF0) { if (((s[1] & 0xC0) == 0x80) && ((s[2] & 0xC0) == 0x80)) { *wc = ((u32)(byte & 0x0F) << 12) | ((u32)(s[1] & 0x3F) << 6) | ((u32)(s[2] & 0x3F)); /* Check valid ranges */ #if ALLOW_BROKEN_UNICODE if (((*wc >= 0x800) && (*wc <= 0xD7FF)) || ((*wc >= 0xD800) && (*wc <= 0xDFFF)) || ((*wc >= 0xe000) && (*wc <= 0xFFFF))) return 3; #else if (((*wc >= 0x800) && (*wc <= 0xD7FF)) || ((*wc >= 0xe000) && (*wc <= 0xFFFD))) return 3; #endif /* ALLOW_BROKEN_UNICODE */ } goto fail; /* four-byte */ } else if (byte < 0xF5) { if (((s[1] & 0xC0) == 0x80) && ((s[2] & 0xC0) == 0x80) && ((s[3] & 0xC0) == 0x80)) { *wc = ((u32)(byte & 0x07) << 18) | ((u32)(s[1] & 0x3F) << 12) | ((u32)(s[2] & 0x3F) << 6) | ((u32)(s[3] & 0x3F)); /* Check valid ranges */ if ((*wc <= 0x10ffff) && (*wc >= 0x10000)) return 4; } goto fail; } fail: errno = EILSEQ; return -1; } /** * ntfs_utf8_to_utf16 - convert a UTF-8 string to a UTF-16LE string * @ins: input multibyte string buffer * @outs: on return contains the (allocated) output utf16 string * @outs_len: length of output buffer in utf16 characters * * Return -1 with errno set. */ static int ntfs_utf8_to_utf16(const char *ins, ntfschar **outs) { #if defined(__APPLE__) || defined(__DARWIN__) #ifdef ENABLE_NFCONV char *new_ins = NULL; if(nfconvert_utf8) { int new_ins_len; new_ins_len = ntfs_macosx_normalize_utf8(ins, &new_ins, 1); // Normalize to composed form if(new_ins_len >= 0) ins = new_ins; else ntfs_log_error("Failed to normalize NTFS string to UTF-8 NFC: %s\n", ins); } #endif /* ENABLE_NFCONV */ #endif /* defined(__APPLE__) || defined(__DARWIN__) */ const char *t = ins; u32 wc; BOOL allocated; ntfschar *outpos; int shorts, ret = -1; shorts = utf8_to_utf16_size(ins); if (shorts < 0) goto fail; allocated = FALSE; if (!*outs) { *outs = ntfs_malloc((shorts + 1) * sizeof(ntfschar)); if (!*outs) goto fail; allocated = TRUE; } outpos = *outs; while(1) { int m = utf8_to_unicode(&wc, t); if (m <= 0) { if (m < 0) { /* do not leave space allocated if failed */ if (allocated) { free(*outs); *outs = (ntfschar*)NULL; } goto fail; } *outpos++ = const_cpu_to_le16(0); break; } if (wc < 0x10000) *outpos++ = cpu_to_le16(wc); else { wc -= 0x10000; *outpos++ = cpu_to_le16((wc >> 10) + 0xd800); *outpos++ = cpu_to_le16((wc & 0x3ff) + 0xdc00); } t += m; } ret = --outpos - *outs; fail: #if defined(__APPLE__) || defined(__DARWIN__) #ifdef ENABLE_NFCONV if(new_ins != NULL) free(new_ins); #endif /* ENABLE_NFCONV */ #endif /* defined(__APPLE__) || defined(__DARWIN__) */ return ret; } /** * ntfs_ucstombs - convert a little endian Unicode string to a multibyte string * @ins: input Unicode string buffer * @ins_len: length of input string in Unicode characters * @outs: on return contains the (allocated) output multibyte string * @outs_len: length of output buffer in bytes (ignored if *@outs is NULL) * * Convert the input little endian, 2-byte Unicode string @ins, of length * @ins_len into the multibyte string format dictated by the current locale. * * If *@outs is NULL, the function allocates the string and the caller is * responsible for calling free(*@outs); when finished with it. * * On success the function returns the number of bytes written to the output * string *@outs (>= 0), not counting the terminating NULL byte. If the output * string buffer was allocated, *@outs is set to it. * * On error, -1 is returned, and errno is set to the error code. The following * error codes can be expected: * EINVAL Invalid arguments (e.g. @ins or @outs is NULL). * EILSEQ The input string cannot be represented as a multibyte * sequence according to the current locale. * ENAMETOOLONG Destination buffer is too small for input string. * ENOMEM Not enough memory to allocate destination buffer. */ int ntfs_ucstombs(const ntfschar *ins, const int ins_len, char **outs, int outs_len) { char *mbs; int mbs_len; #ifdef MB_CUR_MAX wchar_t wc; int i, o; int cnt = 0; #ifdef HAVE_MBSINIT mbstate_t mbstate; #endif #endif /* MB_CUR_MAX */ if (!ins || !outs) { errno = EINVAL; return -1; } mbs = *outs; mbs_len = outs_len; if (mbs && !mbs_len) { errno = ENAMETOOLONG; return -1; } if (use_utf8) return ntfs_utf16_to_utf8(ins, ins_len, outs, outs_len); #ifdef MB_CUR_MAX if (!mbs) { mbs_len = (ins_len + 1) * MB_CUR_MAX; mbs = ntfs_malloc(mbs_len); if (!mbs) return -1; } #ifdef HAVE_MBSINIT memset(&mbstate, 0, sizeof(mbstate)); #else wctomb(NULL, 0); #endif for (i = o = 0; i < ins_len; i++) { /* Reallocate memory if necessary or abort. */ if ((int)(o + MB_CUR_MAX) > mbs_len) { char *tc; if (mbs == *outs) { errno = ENAMETOOLONG; return -1; } tc = ntfs_malloc((mbs_len + 64) & ~63); if (!tc) goto err_out; memcpy(tc, mbs, mbs_len); mbs_len = (mbs_len + 64) & ~63; free(mbs); mbs = tc; } /* Convert the LE Unicode character to a CPU wide character. */ wc = (wchar_t)le16_to_cpu(ins[i]); if (!wc) break; /* Convert the CPU endian wide character to multibyte. */ #ifdef HAVE_MBSINIT cnt = wcrtomb(mbs + o, wc, &mbstate); #else cnt = wctomb(mbs + o, wc); #endif if (cnt == -1) goto err_out; if (cnt <= 0) { ntfs_log_debug("Eeek. cnt <= 0, cnt = %i\n", cnt); errno = EINVAL; goto err_out; } o += cnt; } #ifdef HAVE_MBSINIT /* Make sure we are back in the initial state. */ if (!mbsinit(&mbstate)) { ntfs_log_debug("Eeek. mbstate not in initial state!\n"); errno = EILSEQ; goto err_out; } #endif /* Now write the NULL character. */ mbs[o] = '\0'; if (*outs != mbs) *outs = mbs; return o; err_out: if (mbs != *outs) { int eo = errno; free(mbs); errno = eo; } #else /* MB_CUR_MAX */ errno = EILSEQ; #endif /* MB_CUR_MAX */ return -1; } /** * ntfs_mbstoucs - convert a multibyte string to a little endian Unicode string * @ins: input multibyte string buffer * @outs: on return contains the (allocated) output Unicode string * * Convert the input multibyte string @ins, from the current locale into the * corresponding little endian, 2-byte Unicode string. * * The function allocates the string and the caller is responsible for calling * free(*@outs); when finished with it. * * On success the function returns the number of Unicode characters written to * the output string *@outs (>= 0), not counting the terminating Unicode NULL * character. * * On error, -1 is returned, and errno is set to the error code. The following * error codes can be expected: * EINVAL Invalid arguments (e.g. @ins or @outs is NULL). * EILSEQ The input string cannot be represented as a Unicode * string according to the current locale. * ENAMETOOLONG Destination buffer is too small for input string. * ENOMEM Not enough memory to allocate destination buffer. */ int ntfs_mbstoucs(const char *ins, ntfschar **outs) { #ifdef MB_CUR_MAX ntfschar *ucs; const char *s; wchar_t wc; int i, o, cnt, ins_len, ucs_len, ins_size; #ifdef HAVE_MBSINIT mbstate_t mbstate; #endif #endif /* MB_CUR_MAX */ if (!ins || !outs) { errno = EINVAL; return -1; } if (use_utf8) return ntfs_utf8_to_utf16(ins, outs); #ifdef MB_CUR_MAX /* Determine the size of the multi-byte string in bytes. */ ins_size = strlen(ins); /* Determine the length of the multi-byte string. */ s = ins; #if defined(HAVE_MBSINIT) memset(&mbstate, 0, sizeof(mbstate)); ins_len = mbsrtowcs(NULL, (const char **)&s, 0, &mbstate); #ifdef __CYGWIN32__ if (!ins_len && *ins) { /* Older Cygwin had broken mbsrtowcs() implementation. */ ins_len = strlen(ins); } #endif #elif !defined(DJGPP) ins_len = mbstowcs(NULL, s, 0); #else /* Eeek!!! DJGPP has broken mbstowcs() implementation!!! */ ins_len = strlen(ins); #endif if (ins_len == -1) return ins_len; #ifdef HAVE_MBSINIT if ((s != ins) || !mbsinit(&mbstate)) { #else if (s != ins) { #endif errno = EILSEQ; return -1; } /* Add the NULL terminator. */ ins_len++; ucs_len = ins_len; ucs = ntfs_malloc(ucs_len * sizeof(ntfschar)); if (!ucs) return -1; #ifdef HAVE_MBSINIT memset(&mbstate, 0, sizeof(mbstate)); #else mbtowc(NULL, NULL, 0); #endif for (i = o = cnt = 0; i < ins_size; i += cnt, o++) { /* Reallocate memory if necessary. */ if (o >= ucs_len) { ntfschar *tc; ucs_len = (ucs_len * sizeof(ntfschar) + 64) & ~63; tc = realloc(ucs, ucs_len); if (!tc) goto err_out; ucs = tc; ucs_len /= sizeof(ntfschar); } /* Convert the multibyte character to a wide character. */ #ifdef HAVE_MBSINIT cnt = mbrtowc(&wc, ins + i, ins_size - i, &mbstate); #else cnt = mbtowc(&wc, ins + i, ins_size - i); #endif if (!cnt) break; if (cnt == -1) goto err_out; if (cnt < -1) { ntfs_log_trace("Eeek. cnt = %i\n", cnt); errno = EINVAL; goto err_out; } /* Make sure we are not overflowing the NTFS Unicode set. */ if ((unsigned long)wc >= (unsigned long)(1 << (8 * sizeof(ntfschar)))) { errno = EILSEQ; goto err_out; } /* Convert the CPU wide character to a LE Unicode character. */ ucs[o] = cpu_to_le16(wc); } #ifdef HAVE_MBSINIT /* Make sure we are back in the initial state. */ if (!mbsinit(&mbstate)) { ntfs_log_trace("Eeek. mbstate not in initial state!\n"); errno = EILSEQ; goto err_out; } #endif /* Now write the NULL character. */ ucs[o] = const_cpu_to_le16(L'\0'); *outs = ucs; return o; err_out: free(ucs); #else /* MB_CUR_MAX */ errno = EILSEQ; #endif /* MB_CUR_MAX */ return -1; } /* * Turn a UTF8 name uppercase * * Returns an allocated uppercase name which has to be freed by caller * or NULL if there is an error (described by errno) */ char *ntfs_uppercase_mbs(const char *low, const ntfschar *upcase, u32 upcase_size) { int size; char *upp; u32 wc; int n; const char *s; char *t; size = strlen(low); upp = (char*)ntfs_malloc(3*size + 1); if (upp) { s = low; t = upp; do { n = utf8_to_unicode(&wc, s); if (n > 0) { if (wc < upcase_size) wc = le16_to_cpu(upcase[wc]); if (wc < 0x80) *t++ = wc; else if (wc < 0x800) { *t++ = (0xc0 | ((wc >> 6) & 0x3f)); *t++ = 0x80 | (wc & 0x3f); } else if (wc < 0x10000) { *t++ = 0xe0 | (wc >> 12); *t++ = 0x80 | ((wc >> 6) & 0x3f); *t++ = 0x80 | (wc & 0x3f); } else { *t++ = 0xf0 | ((wc >> 18) & 7); *t++ = 0x80 | ((wc >> 12) & 63); *t++ = 0x80 | ((wc >> 6) & 0x3f); *t++ = 0x80 | (wc & 0x3f); } s += n; } } while (n > 0); if (n < 0) { free(upp); upp = (char*)NULL; errno = EILSEQ; } else { *t = 0; } } return (upp); } /** * ntfs_upcase_table_build - build the default upcase table for NTFS * @uc: destination buffer where to store the built table * @uc_len: size of destination buffer in bytes * * ntfs_upcase_table_build() builds the default upcase table for NTFS and * stores it in the caller supplied buffer @uc of size @uc_len. * * Note, @uc_len must be at least 128kiB in size or bad things will happen! */ void ntfs_upcase_table_build(ntfschar *uc, u32 uc_len) { struct NEWUPPERCASE { unsigned short first; unsigned short last; short diff; unsigned char step; unsigned char osmajor; unsigned char osminor; } ; /* * This is the table as defined by Windows XP */ static int uc_run_table[][3] = { /* Start, End, Add */ {0x0061, 0x007B, -32}, {0x0451, 0x045D, -80}, {0x1F70, 0x1F72, 74}, {0x00E0, 0x00F7, -32}, {0x045E, 0x0460, -80}, {0x1F72, 0x1F76, 86}, {0x00F8, 0x00FF, -32}, {0x0561, 0x0587, -48}, {0x1F76, 0x1F78, 100}, {0x0256, 0x0258, -205}, {0x1F00, 0x1F08, 8}, {0x1F78, 0x1F7A, 128}, {0x028A, 0x028C, -217}, {0x1F10, 0x1F16, 8}, {0x1F7A, 0x1F7C, 112}, {0x03AC, 0x03AD, -38}, {0x1F20, 0x1F28, 8}, {0x1F7C, 0x1F7E, 126}, {0x03AD, 0x03B0, -37}, {0x1F30, 0x1F38, 8}, {0x1FB0, 0x1FB2, 8}, {0x03B1, 0x03C2, -32}, {0x1F40, 0x1F46, 8}, {0x1FD0, 0x1FD2, 8}, {0x03C2, 0x03C3, -31}, {0x1F51, 0x1F52, 8}, {0x1FE0, 0x1FE2, 8}, {0x03C3, 0x03CC, -32}, {0x1F53, 0x1F54, 8}, {0x1FE5, 0x1FE6, 7}, {0x03CC, 0x03CD, -64}, {0x1F55, 0x1F56, 8}, {0x2170, 0x2180, -16}, {0x03CD, 0x03CF, -63}, {0x1F57, 0x1F58, 8}, {0x24D0, 0x24EA, -26}, {0x0430, 0x0450, -32}, {0x1F60, 0x1F68, 8}, {0xFF41, 0xFF5B, -32}, {0} }; static int uc_dup_table[][2] = { /* Start, End */ {0x0100, 0x012F}, {0x01A0, 0x01A6}, {0x03E2, 0x03EF}, {0x04CB, 0x04CC}, {0x0132, 0x0137}, {0x01B3, 0x01B7}, {0x0460, 0x0481}, {0x04D0, 0x04EB}, {0x0139, 0x0149}, {0x01CD, 0x01DD}, {0x0490, 0x04BF}, {0x04EE, 0x04F5}, {0x014A, 0x0178}, {0x01DE, 0x01EF}, {0x04BF, 0x04BF}, {0x04F8, 0x04F9}, {0x0179, 0x017E}, {0x01F4, 0x01F5}, {0x04C1, 0x04C4}, {0x1E00, 0x1E95}, {0x018B, 0x018B}, {0x01FA, 0x0218}, {0x04C7, 0x04C8}, {0x1EA0, 0x1EF9}, {0} }; static int uc_byte_table[][2] = { /* Offset, Value */ {0x00FF, 0x0178}, {0x01AD, 0x01AC}, {0x01F3, 0x01F1}, {0x0269, 0x0196}, {0x0183, 0x0182}, {0x01B0, 0x01AF}, {0x0253, 0x0181}, {0x026F, 0x019C}, {0x0185, 0x0184}, {0x01B9, 0x01B8}, {0x0254, 0x0186}, {0x0272, 0x019D}, {0x0188, 0x0187}, {0x01BD, 0x01BC}, {0x0259, 0x018F}, {0x0275, 0x019F}, {0x018C, 0x018B}, {0x01C6, 0x01C4}, {0x025B, 0x0190}, {0x0283, 0x01A9}, {0x0192, 0x0191}, {0x01C9, 0x01C7}, {0x0260, 0x0193}, {0x0288, 0x01AE}, {0x0199, 0x0198}, {0x01CC, 0x01CA}, {0x0263, 0x0194}, {0x0292, 0x01B7}, {0x01A8, 0x01A7}, {0x01DD, 0x018E}, {0x0268, 0x0197}, {0} }; /* * Changes which were applied to later Windows versions * * md5 for $UpCase from Winxp : 6fa3db2468275286210751e869d36373 * Vista : 2f03b5a69d486ff3864cecbd07f24440 * Win8 : 7ff498a44e45e77374cc7c962b1b92f2 */ static const struct NEWUPPERCASE newuppercase[] = { /* from Windows 6.0 (Vista) */ { 0x37b, 0x37d, 0x82, 1, 6, 0 }, { 0x1f80, 0x1f87, 0x8, 1, 6, 0 }, { 0x1f90, 0x1f97, 0x8, 1, 6, 0 }, { 0x1fa0, 0x1fa7, 0x8, 1, 6, 0 }, { 0x2c30, 0x2c5e, -0x30, 1, 6, 0 }, { 0x2d00, 0x2d25, -0x1c60, 1, 6, 0 }, { 0x2c68, 0x2c6c, -0x1, 2, 6, 0 }, { 0x219, 0x21f, -0x1, 2, 6, 0 }, { 0x223, 0x233, -0x1, 2, 6, 0 }, { 0x247, 0x24f, -0x1, 2, 6, 0 }, { 0x3d9, 0x3e1, -0x1, 2, 6, 0 }, { 0x48b, 0x48f, -0x1, 2, 6, 0 }, { 0x4fb, 0x513, -0x1, 2, 6, 0 }, { 0x2c81, 0x2ce3, -0x1, 2, 6, 0 }, { 0x3f8, 0x3fb, -0x1, 3, 6, 0 }, { 0x4c6, 0x4ce, -0x1, 4, 6, 0 }, { 0x23c, 0x242, -0x1, 6, 6, 0 }, { 0x4ed, 0x4f7, -0x1, 10, 6, 0 }, { 0x450, 0x45d, -0x50, 13, 6, 0 }, { 0x2c61, 0x2c76, -0x1, 21, 6, 0 }, { 0x1fcc, 0x1ffc, -0x9, 48, 6, 0 }, { 0x180, 0x180, 0xc3, 1, 6, 0 }, { 0x195, 0x195, 0x61, 1, 6, 0 }, { 0x19a, 0x19a, 0xa3, 1, 6, 0 }, { 0x19e, 0x19e, 0x82, 1, 6, 0 }, { 0x1bf, 0x1bf, 0x38, 1, 6, 0 }, { 0x1f9, 0x1f9, -0x1, 1, 6, 0 }, { 0x23a, 0x23a, 0x2a2b, 1, 6, 0 }, { 0x23e, 0x23e, 0x2a28, 1, 6, 0 }, { 0x26b, 0x26b, 0x29f7, 1, 6, 0 }, { 0x27d, 0x27d, 0x29e7, 1, 6, 0 }, { 0x280, 0x280, -0xda, 1, 6, 0 }, { 0x289, 0x289, -0x45, 1, 6, 0 }, { 0x28c, 0x28c, -0x47, 1, 6, 0 }, { 0x3f2, 0x3f2, 0x7, 1, 6, 0 }, { 0x4cf, 0x4cf, -0xf, 1, 6, 0 }, { 0x1d7d, 0x1d7d, 0xee6, 1, 6, 0 }, { 0x1fb3, 0x1fb3, 0x9, 1, 6, 0 }, { 0x214e, 0x214e, -0x1c, 1, 6, 0 }, { 0x2184, 0x2184, -0x1, 1, 6, 0 }, /* from Windows 6.1 (Win7) */ { 0x23a, 0x23e, 0x0, 4, 6, 1 }, { 0x250, 0x250, 0x2a1f, 2, 6, 1 }, { 0x251, 0x251, 0x2a1c, 2, 6, 1 }, { 0x271, 0x271, 0x29fd, 2, 6, 1 }, { 0x371, 0x373, -0x1, 2, 6, 1 }, { 0x377, 0x377, -0x1, 2, 6, 1 }, { 0x3c2, 0x3c2, 0x0, 2, 6, 1 }, { 0x3d7, 0x3d7, -0x8, 2, 6, 1 }, { 0x515, 0x523, -0x1, 2, 6, 1 }, /* below, -0x75fc stands for 0x8a04 and truncation */ { 0x1d79, 0x1d79, -0x75fc, 2, 6, 1 }, { 0x1efb, 0x1eff, -0x1, 2, 6, 1 }, { 0x1fc3, 0x1ff3, 0x9, 48, 6, 1 }, { 0x1fcc, 0x1ffc, 0x0, 48, 6, 1 }, { 0x2c65, 0x2c65, -0x2a2b, 2, 6, 1 }, { 0x2c66, 0x2c66, -0x2a28, 2, 6, 1 }, { 0x2c73, 0x2c73, -0x1, 2, 6, 1 }, { 0xa641, 0xa65f, -0x1, 2, 6, 1 }, { 0xa663, 0xa66d, -0x1, 2, 6, 1 }, { 0xa681, 0xa697, -0x1, 2, 6, 1 }, { 0xa723, 0xa72f, -0x1, 2, 6, 1 }, { 0xa733, 0xa76f, -0x1, 2, 6, 1 }, { 0xa77a, 0xa77c, -0x1, 2, 6, 1 }, { 0xa77f, 0xa787, -0x1, 2, 6, 1 }, { 0xa78c, 0xa78c, -0x1, 2, 6, 1 }, /* end mark */ { 0 } } ; int i, r; int k, off; const struct NEWUPPERCASE *puc; memset((char*)uc, 0, uc_len); uc_len >>= 1; if (uc_len > 65536) uc_len = 65536; for (i = 0; (u32)i < uc_len; i++) uc[i] = cpu_to_le16(i); for (r = 0; uc_run_table[r][0]; r++) { off = uc_run_table[r][2]; for (i = uc_run_table[r][0]; i < uc_run_table[r][1]; i++) uc[i] = cpu_to_le16(i + off); } for (r = 0; uc_dup_table[r][0]; r++) for (i = uc_dup_table[r][0]; i < uc_dup_table[r][1]; i += 2) uc[i + 1] = cpu_to_le16(i); for (r = 0; uc_byte_table[r][0]; r++) { k = uc_byte_table[r][1]; uc[uc_byte_table[r][0]] = cpu_to_le16(k); } for (r=0; newuppercase[r].first; r++) { puc = &newuppercase[r]; if ((puc->osmajor < UPCASE_MAJOR) || ((puc->osmajor == UPCASE_MAJOR) && (puc->osminor <= UPCASE_MINOR))) { off = puc->diff; for (i = puc->first; i <= puc->last; i += puc->step) uc[i] = cpu_to_le16(i + off); } } } /* * Allocate and build the default upcase table * * Returns the number of entries * 0 if failed */ #define UPCASE_LEN 65536 /* default number of entries in upcase */ u32 ntfs_upcase_build_default(ntfschar **upcase) { u32 upcase_len = 0; *upcase = (ntfschar*)ntfs_malloc(UPCASE_LEN*2); if (*upcase) { ntfs_upcase_table_build(*upcase, UPCASE_LEN*2); upcase_len = UPCASE_LEN; } return (upcase_len); } /* * Build a table for converting to lower case * * This is only meaningful when there is a single lower case * character leading to an upper case one, and currently the * only exception is the greek letter sigma which has a single * upper case glyph (code U+03A3), but two lower case glyphs * (code U+03C3 and U+03C2, the latter to be used at the end * of a word). In the following implementation the upper case * sigma will be lowercased as U+03C3. */ ntfschar *ntfs_locase_table_build(const ntfschar *uc, u32 uc_cnt) { ntfschar *lc; u32 upp; u32 i; lc = (ntfschar*)ntfs_malloc(uc_cnt*sizeof(ntfschar)); if (lc) { for (i=0; i NTFS_MAX_NAME_LEN) { free(ucs); errno = ENAMETOOLONG; return NULL; } if (!ucs || !*len) { ucs = AT_UNNAMED; *len = 0; } return ucs; } /** * ntfs_ucsfree - free memory allocated by ntfs_str2ucs() * @ucs input string to be freed * * Free memory at @ucs and which was allocated by ntfs_str2ucs. * * Return value: none. */ void ntfs_ucsfree(ntfschar *ucs) { if (ucs && (ucs != AT_UNNAMED)) free(ucs); } /* * Check whether a name contains no chars forbidden * for DOS or Win32 use * * If @strict is TRUE, then trailing dots and spaces are forbidden. * These names are technically allowed in the Win32 namespace, but * they can be problematic. See comment for FILE_NAME_WIN32. * * If there is a bad char, errno is set to EINVAL */ BOOL ntfs_forbidden_chars(const ntfschar *name, int len, BOOL strict) { BOOL forbidden; int ch; int i; static const u32 mainset = (1L << ('\"' - 0x20)) | (1L << ('*' - 0x20)) | (1L << ('/' - 0x20)) | (1L << (':' - 0x20)) | (1L << ('<' - 0x20)) | (1L << ('>' - 0x20)) | (1L << ('?' - 0x20)); forbidden = (len == 0) || (strict && (name[len-1] == const_cpu_to_le16(' ') || name[len-1] == const_cpu_to_le16('.'))); for (i=0; i= 3)) { /* * Rough hash check to tell whether the first couple of chars * may be one of CO PR AU NU LP or lowercase variants. */ h = ((le16_to_cpu(name[0]) & 31)*48) ^ ((le16_to_cpu(name[1]) & 31)*165); if ((h % 23) == 17) { /* do a full check, depending on the third char */ switch (le16_to_cpu(name[2]) & ~0x20) { case 'N' : if (((len == 3) || (name[3] == dot)) && (!ntfs_ucsncasecmp(name, con, 3, vol->upcase, vol->upcase_len) || !ntfs_ucsncasecmp(name, prn, 3, vol->upcase, vol->upcase_len))) forbidden = TRUE; break; case 'X' : if (((len == 3) || (name[3] == dot)) && !ntfs_ucsncasecmp(name, aux, 3, vol->upcase, vol->upcase_len)) forbidden = TRUE; break; case 'L' : if (((len == 3) || (name[3] == dot)) && !ntfs_ucsncasecmp(name, nul, 3, vol->upcase, vol->upcase_len)) forbidden = TRUE; break; case 'M' : if ((len > 3) && (le16_to_cpu(name[3]) >= '1') && (le16_to_cpu(name[3]) <= '9') && ((len == 4) || (name[4] == dot)) && !ntfs_ucsncasecmp(name, com, 3, vol->upcase, vol->upcase_len)) forbidden = TRUE; break; case 'T' : if ((len > 3) && (le16_to_cpu(name[3]) >= '1') && (le16_to_cpu(name[3]) <= '9') && ((len == 4) || (name[4] == dot)) && !ntfs_ucsncasecmp(name, lpt, 3, vol->upcase, vol->upcase_len)) forbidden = TRUE; break; } } } if (forbidden) errno = EINVAL; return (forbidden); } /* * Check whether the same name can be used as a DOS and * a Win32 name * * The names must be the same, or the short name the uppercase * variant of the long name */ BOOL ntfs_collapsible_chars(ntfs_volume *vol, const ntfschar *shortname, int shortlen, const ntfschar *longname, int longlen) { BOOL collapsible; unsigned int ch; unsigned int cs; int i; collapsible = shortlen == longlen; for (i=0; collapsible && (i= vol->upcase_len) || (cs >= vol->upcase_len) || (vol->upcase[cs] != vol->upcase[ch]))) collapsible = FALSE; } return (collapsible); } /* * Define the character encoding to be used. * Use UTF-8 unless specified otherwise. */ int ntfs_set_char_encoding(const char *locale) { use_utf8 = 0; if (!locale || strstr(locale,"utf8") || strstr(locale,"UTF8") || strstr(locale,"utf-8") || strstr(locale,"UTF-8")) use_utf8 = 1; else if (setlocale(LC_ALL, locale)) use_utf8 = 0; else { ntfs_log_error("Invalid locale, encoding to UTF-8\n"); use_utf8 = 1; } return 0; /* always successful */ } #if defined(__APPLE__) || defined(__DARWIN__) int ntfs_macosx_normalize_filenames(int normalize) { #ifdef ENABLE_NFCONV if (normalize == 0 || normalize == 1) { nfconvert_utf8 = normalize; return 0; } else { return -1; } #else return -1; #endif /* ENABLE_NFCONV */ } int ntfs_macosx_normalize_utf8(const char *utf8_string, char **target, int composed) { #ifdef ENABLE_NFCONV /* For this code to compile, the CoreFoundation framework must be fed to * the linker. */ CFStringRef cfSourceString; CFMutableStringRef cfMutableString; CFRange rangeToProcess; CFIndex requiredBufferLength; char *result = NULL; int resultLength = -1; /* Convert the UTF-8 string to a CFString. */ cfSourceString = CFStringCreateWithCString(kCFAllocatorDefault, utf8_string, kCFStringEncodingUTF8); if (cfSourceString == NULL) { ntfs_log_error("CFStringCreateWithCString failed!\n"); return -2; } /* Create a mutable string from cfSourceString that we are free to * modify. */ cfMutableString = CFStringCreateMutableCopy(kCFAllocatorDefault, 0, cfSourceString); CFRelease(cfSourceString); /* End-of-life. */ if (cfMutableString == NULL) { ntfs_log_error("CFStringCreateMutableCopy failed!\n"); return -3; } /* Normalize the mutable string to the desired normalization form. */ CFStringNormalize(cfMutableString, (composed != 0 ? kCFStringNormalizationFormC : kCFStringNormalizationFormD)); /* Store the resulting string in a '\0'-terminated UTF-8 encoded char* * buffer. */ rangeToProcess = CFRangeMake(0, CFStringGetLength(cfMutableString)); if (CFStringGetBytes(cfMutableString, rangeToProcess, kCFStringEncodingUTF8, 0, false, NULL, 0, &requiredBufferLength) > 0) { resultLength = sizeof(char) * (requiredBufferLength + 1); result = ntfs_calloc(resultLength); if (result != NULL) { if (CFStringGetBytes(cfMutableString, rangeToProcess, kCFStringEncodingUTF8, 0, false, (UInt8*) result, resultLength - 1, &requiredBufferLength) <= 0) { ntfs_log_error("Could not perform UTF-8 " "conversion of normalized " "CFMutableString.\n"); free(result); result = NULL; } } else { ntfs_log_error("Could not perform a ntfs_calloc of %d " "bytes for char *result.\n", resultLength); } } else { ntfs_log_error("Could not perform check for required length of " "UTF-8 conversion of normalized CFMutableString.\n"); } CFRelease(cfMutableString); if (result != NULL) { *target = result; return resultLength - 1; } else { return -1; } #else return -1; #endif /* ENABLE_NFCONV */ } #endif /* defined(__APPLE__) || defined(__DARWIN__) */ ntfs-3g-2026.2.25/libntfs-3g/libntfs-3g.script.so.in0000664000175000017500000000006615152260173015175 @OUTPUT_FORMAT@ GROUP ( @rootlibdir@/libntfs-3g.so ) ntfs-3g-2026.2.25/libntfs-3g/device.c0000664000175000017500000006175215152260173012366 /** * device.c - Low level device io functions. Originated from the Linux-NTFS project. * * Copyright (c) 2004-2013 Anton Altaparmakov * Copyright (c) 2004-2006 Szabolcs Szakacsits * Copyright (c) 2010 Jean-Pierre Andre * Copyright (c) 2008-2013 Tuxera Inc. * * This program/include file 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/include file 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_UNISTD_H #include #endif #ifdef HAVE_STDLIB_H #include #endif #ifdef HAVE_STRING_H #include #endif #ifdef HAVE_ERRNO_H #include #endif #ifdef HAVE_STDIO_H #include #endif #ifdef HAVE_SYS_TYPES_H #include #endif #ifdef HAVE_SYS_STAT_H #include #endif #ifdef HAVE_FCNTL_H #include #endif #ifdef HAVE_SYS_IOCTL_H #include #endif #ifdef HAVE_SYS_PARAM_H #include #endif #ifdef HAVE_SYS_MOUNT_H #include #endif #ifdef HAVE_SYS_DISK_H #include #endif #ifdef HAVE_LINUX_FD_H #include #endif #ifdef HAVE_LINUX_HDREG_H #include #endif #ifdef ENABLE_HD #include #endif #include "types.h" #include "mst.h" #include "debug.h" #include "device.h" #include "logging.h" #include "misc.h" #if defined(linux) && defined(_IO) && !defined(BLKGETSIZE) #define BLKGETSIZE _IO(0x12,96) /* Get device size in 512-byte blocks. */ #endif #if defined(linux) && defined(_IOR) && !defined(BLKGETSIZE64) #define BLKGETSIZE64 _IOR(0x12,114,size_t) /* Get device size in bytes. */ #endif #if defined(linux) && !defined(HDIO_GETGEO) #define HDIO_GETGEO 0x0301 /* Get device geometry. */ #endif #if defined(linux) && defined(_IO) && !defined(BLKSSZGET) # define BLKSSZGET _IO(0x12,104) /* Get device sector size in bytes. */ #endif #if defined(linux) && defined(_IO) && !defined(BLKBSZSET) # define BLKBSZSET _IOW(0x12,113,size_t) /* Set device block size in bytes. */ #endif /** * ntfs_device_alloc - allocate an ntfs device structure and pre-initialize it * @name: name of the device (must be present) * @state: initial device state (usually zero) * @dops: ntfs device operations to use with the device (must be present) * @priv_data: pointer to private data (optional) * * Allocate an ntfs device structure and pre-initialize it with the user- * specified device operations @dops, device state @state, device name @name, * and optional private data @priv_data. * * Note, @name is copied and can hence be freed after this functions returns. * * On success return a pointer to the allocated ntfs device structure and on * error return NULL with errno set to the error code returned by ntfs_malloc(). */ struct ntfs_device *ntfs_device_alloc(const char *name, const long state, struct ntfs_device_operations *dops, void *priv_data) { struct ntfs_device *dev; if (!name) { errno = EINVAL; return NULL; } dev = ntfs_malloc(sizeof(struct ntfs_device)); if (dev) { if (!(dev->d_name = strdup(name))) { int eo = errno; free(dev); errno = eo; return NULL; } dev->d_ops = dops; dev->d_state = state; dev->d_private = priv_data; dev->d_heads = -1; dev->d_sectors_per_track = -1; } return dev; } /** * ntfs_device_free - free an ntfs device structure * @dev: ntfs device structure to free * * Free the ntfs device structure @dev. * * Return 0 on success or -1 on error with errno set to the error code. The * following error codes are defined: * EINVAL Invalid pointer @dev. * EBUSY Device is still open. Close it before freeing it! */ int ntfs_device_free(struct ntfs_device *dev) { if (!dev) { errno = EINVAL; return -1; } if (NDevOpen(dev)) { errno = EBUSY; return -1; } free(dev->d_name); free(dev); return 0; } /* * Sync the device * * returns zero if successful. */ int ntfs_device_sync(struct ntfs_device *dev) { int ret; struct ntfs_device_operations *dops; if (NDevDirty(dev)) { dops = dev->d_ops; ret = dops->sync(dev); } else ret = 0; return ret; } /** * ntfs_pread - positioned read from disk * @dev: device to read from * @pos: position in device to read from * @count: number of bytes to read * @b: output data buffer * * This function will read @count bytes from device @dev at position @pos into * the data buffer @b. * * On success, return the number of successfully read bytes. If this number is * lower than @count this means that we have either reached end of file or * encountered an error during the read so that the read is partial. 0 means * end of file or nothing to read (@count is 0). * * On error and nothing has been read, return -1 with errno set appropriately * to the return code of either seek, read, or set to EINVAL in case of * invalid arguments. */ s64 ntfs_pread(struct ntfs_device *dev, const s64 pos, s64 count, void *b) { s64 br, total; struct ntfs_device_operations *dops; ntfs_log_trace("pos %lld, count %lld\n",(long long)pos,(long long)count); if (!b || count < 0 || pos < 0) { errno = EINVAL; return -1; } if (!count) return 0; dops = dev->d_ops; for (total = 0; count; count -= br, total += br) { br = dops->pread(dev, (char*)b + total, count, pos + total); /* If everything ok, continue. */ if (br > 0) continue; /* If EOF or error return number of bytes read. */ if (!br || total) return total; /* Nothing read and error, return error status. */ return br; } /* Finally, return the number of bytes read. */ return total; } /** * ntfs_pwrite - positioned write to disk * @dev: device to write to * @pos: position in file descriptor to write to * @count: number of bytes to write * @b: data buffer to write to disk * * This function will write @count bytes from data buffer @b to the device @dev * at position @pos. * * On success, return the number of successfully written bytes. If this number * is lower than @count this means that the write has been interrupted in * flight or that an error was encountered during the write so that the write * is partial. 0 means nothing was written (also return 0 when @count is 0). * * On error and nothing has been written, return -1 with errno set * appropriately to the return code of either seek, write, or set * to EINVAL in case of invalid arguments. */ s64 ntfs_pwrite(struct ntfs_device *dev, const s64 pos, s64 count, const void *b) { s64 written, total, ret = -1; struct ntfs_device_operations *dops; ntfs_log_trace("pos %lld, count %lld\n",(long long)pos,(long long)count); if (!b || count < 0 || pos < 0) { errno = EINVAL; goto out; } if (!count) return 0; if (NDevReadOnly(dev)) { errno = EROFS; goto out; } dops = dev->d_ops; NDevSetDirty(dev); for (total = 0; count; count -= written, total += written) { written = dops->pwrite(dev, (const char*)b + total, count, pos + total); /* If everything ok, continue. */ if (written > 0) continue; /* * If nothing written or error return number of bytes written. */ if (!written || total) break; /* Nothing written and error, return error status. */ total = written; break; } if (NDevSync(dev) && total && dops->sync(dev)) { total--; /* on sync error, return partially written */ } ret = total; out: return ret; } /** * ntfs_mst_pread - multi sector transfer (mst) positioned read * @dev: device to read from * @pos: position in file descriptor to read from * @count: number of blocks to read * @bksize: size of each block that needs mst deprotecting * @b: output data buffer * * Multi sector transfer (mst) positioned read. This function will read @count * blocks of size @bksize bytes each from device @dev at position @pos into the * the data buffer @b. * * On success, return the number of successfully read blocks. If this number is * lower than @count this means that we have reached end of file, that the read * was interrupted, or that an error was encountered during the read so that * the read is partial. 0 means end of file or nothing was read (also return 0 * when @count or @bksize are 0). * * On error and nothing was read, return -1 with errno set appropriately to the * return code of either seek, read, or set to EINVAL in case of invalid * arguments. * * NOTE: If an incomplete multi sector transfer has been detected the magic * will have been changed to magic_BAAD but no error will be returned. Thus it * is possible that we return count blocks as being read but that any number * (between zero and count!) of these blocks is actually subject to a multi * sector transfer error. This should be detected by the caller by checking for * the magic being "BAAD". */ s64 ntfs_mst_pread(struct ntfs_device *dev, const s64 pos, s64 count, const u32 bksize, void *b) { s64 br, i; if (bksize & (bksize - 1) || bksize % NTFS_BLOCK_SIZE) { errno = EINVAL; return -1; } /* Do the read. */ br = ntfs_pread(dev, pos, count * bksize, b); if (br < 0) return br; /* * Apply fixups to successfully read data, disregarding any errors * returned from the MST fixup function. This is because we want to * fixup everything possible and we rely on the fact that the "BAAD" * magic will be detected later on. */ count = br / bksize; for (i = 0; i < count; ++i) ntfs_mst_post_read_fixup((NTFS_RECORD*) ((u8*)b + i * bksize), bksize); /* Finally, return the number of complete blocks read. */ return count; } /** * ntfs_mst_pwrite - multi sector transfer (mst) positioned write * @dev: device to write to * @pos: position in file descriptor to write to * @count: number of blocks to write * @bksize: size of each block that needs mst protecting * @b: data buffer to write to disk * * Multi sector transfer (mst) positioned write. This function will write * @count blocks of size @bksize bytes each from data buffer @b to the device * @dev at position @pos. * * On success, return the number of successfully written blocks. If this number * is lower than @count this means that the write has been interrupted or that * an error was encountered during the write so that the write is partial. 0 * means nothing was written (also return 0 when @count or @bksize are 0). * * On error and nothing has been written, return -1 with errno set * appropriately to the return code of either seek, write, or set * to EINVAL in case of invalid arguments. * * NOTE: We mst protect the data, write it, then mst deprotect it using a quick * deprotect algorithm (no checking). This saves us from making a copy before * the write and at the same time causes the usn to be incremented in the * buffer. This conceptually fits in better with the idea that cached data is * always deprotected and protection is performed when the data is actually * going to hit the disk and the cache is immediately deprotected again * simulating an mst read on the written data. This way cache coherency is * achieved. */ s64 ntfs_mst_pwrite(struct ntfs_device *dev, const s64 pos, s64 count, const u32 bksize, void *b) { s64 written, i; if (count < 0 || bksize % NTFS_BLOCK_SIZE) { errno = EINVAL; return -1; } if (!count) return 0; /* Prepare data for writing. */ for (i = 0; i < count; ++i) { int err; err = ntfs_mst_pre_write_fixup((NTFS_RECORD*) ((u8*)b + i * bksize), bksize); if (err < 0) { /* Abort write at this position. */ if (!i) return err; count = i; break; } } /* Write the prepared data. */ written = ntfs_pwrite(dev, pos, count * bksize, b); /* Quickly deprotect the data again. */ for (i = 0; i < count; ++i) ntfs_mst_post_write_fixup((NTFS_RECORD*)((u8*)b + i * bksize)); if (written <= 0) return written; /* Finally, return the number of complete blocks written. */ return written / bksize; } /** * ntfs_cluster_read - read ntfs clusters * @vol: volume to read from * @lcn: starting logical cluster number * @count: number of clusters to read * @b: output data buffer * * Read @count ntfs clusters starting at logical cluster number @lcn from * volume @vol into buffer @b. Return number of clusters read or -1 on error, * with errno set to the error code. */ s64 ntfs_cluster_read(const ntfs_volume *vol, const s64 lcn, const s64 count, void *b) { s64 br; if (!vol || lcn < 0 || count < 0) { errno = EINVAL; return -1; } if (vol->nr_clusters < lcn + count) { errno = ESPIPE; ntfs_log_perror("Trying to read outside of volume " "(%lld < %lld)", (long long)vol->nr_clusters, (long long)lcn + count); return -1; } br = ntfs_pread(vol->dev, lcn << vol->cluster_size_bits, count << vol->cluster_size_bits, b); if (br < 0) { ntfs_log_perror("Error reading cluster(s)"); return br; } return br >> vol->cluster_size_bits; } /** * ntfs_cluster_write - write ntfs clusters * @vol: volume to write to * @lcn: starting logical cluster number * @count: number of clusters to write * @b: data buffer to write to disk * * Write @count ntfs clusters starting at logical cluster number @lcn from * buffer @b to volume @vol. Return the number of clusters written or -1 on * error, with errno set to the error code. */ s64 ntfs_cluster_write(const ntfs_volume *vol, const s64 lcn, const s64 count, const void *b) { s64 bw; if (!vol || lcn < 0 || count < 0) { errno = EINVAL; return -1; } if (vol->nr_clusters < lcn + count) { errno = ESPIPE; ntfs_log_perror("Trying to write outside of volume " "(%lld < %lld)", (long long)vol->nr_clusters, (long long)lcn + count); return -1; } if (!NVolReadOnly(vol)) bw = ntfs_pwrite(vol->dev, lcn << vol->cluster_size_bits, count << vol->cluster_size_bits, b); else bw = count << vol->cluster_size_bits; if (bw < 0) { ntfs_log_perror("Error writing cluster(s)"); return bw; } return bw >> vol->cluster_size_bits; } /** * ntfs_device_offset_valid - test if a device offset is valid * @dev: open device * @ofs: offset to test for validity * * Test if the offset @ofs is an existing location on the device described * by the open device structure @dev. * * Return 0 if it is valid and -1 if it is not valid. */ static int ntfs_device_offset_valid(struct ntfs_device *dev, s64 ofs) { char ch; if (dev->d_ops->seek(dev, ofs, SEEK_SET) >= 0 && dev->d_ops->read(dev, &ch, 1) == 1) return 0; return -1; } /** * ntfs_device_size_get - return the size of a device in blocks * @dev: open device * @block_size: block size in bytes in which to return the result * * Return the number of @block_size sized blocks in the device described by the * open device @dev. * * Adapted from e2fsutils-1.19, Copyright (C) 1995 Theodore Ts'o. * * On error return -1 with errno set to the error code. */ s64 ntfs_device_size_get(struct ntfs_device *dev, int block_size) { s64 high, low; if (!dev || block_size <= 0 || (block_size - 1) & block_size) { errno = EINVAL; return -1; } #ifdef BLKGETSIZE64 { u64 size; if (dev->d_ops->ioctl(dev, BLKGETSIZE64, &size) >= 0) { ntfs_log_debug("BLKGETSIZE64 nr bytes = %llu (0x%llx)\n", (unsigned long long)size, (unsigned long long)size); return (s64)size / block_size; } } #endif #ifdef BLKGETSIZE { unsigned long size; if (dev->d_ops->ioctl(dev, BLKGETSIZE, &size) >= 0) { ntfs_log_debug("BLKGETSIZE nr 512 byte blocks = %lu (0x%lx)\n", size, size); return (s64)size * 512 / block_size; } } #endif #ifdef FDGETPRM { struct floppy_struct this_floppy; if (dev->d_ops->ioctl(dev, FDGETPRM, &this_floppy) >= 0) { ntfs_log_debug("FDGETPRM nr 512 byte blocks = %lu (0x%lx)\n", (unsigned long)this_floppy.size, (unsigned long)this_floppy.size); return (s64)this_floppy.size * 512 / block_size; } } #endif #ifdef DIOCGMEDIASIZE { /* FreeBSD */ off_t size; if (dev->d_ops->ioctl(dev, DIOCGMEDIASIZE, &size) >= 0) { ntfs_log_debug("DIOCGMEDIASIZE nr bytes = %llu (0x%llx)\n", (unsigned long long)size, (unsigned long long)size); return (s64)size / block_size; } } #endif #ifdef DKIOCGETBLOCKCOUNT { /* Mac OS X */ uint64_t blocks; int sector_size; sector_size = ntfs_device_sector_size_get(dev); if (sector_size >= 0 && dev->d_ops->ioctl(dev, DKIOCGETBLOCKCOUNT, &blocks) >= 0) { ntfs_log_debug("DKIOCGETBLOCKCOUNT nr blocks = %llu (0x%llx)\n", (unsigned long long) blocks, (unsigned long long) blocks); return blocks * sector_size / block_size; } } #endif /* * We couldn't figure it out by using a specialized ioctl, * so do binary search to find the size of the device. */ low = 0LL; for (high = 1024LL; !ntfs_device_offset_valid(dev, high); high <<= 1) low = high; while (low < high - 1LL) { const s64 mid = (low + high) / 2; if (!ntfs_device_offset_valid(dev, mid)) low = mid; else high = mid; } dev->d_ops->seek(dev, 0LL, SEEK_SET); return (low + 1LL) / block_size; } /** * ntfs_device_partition_start_sector_get - get starting sector of a partition * @dev: open device * * On success, return the starting sector of the partition @dev in the parent * block device of @dev. On error return -1 with errno set to the error code. * * The following error codes are defined: * EINVAL Input parameter error * EOPNOTSUPP System does not support HDIO_GETGEO ioctl * ENOTTY @dev is a file or a device not supporting HDIO_GETGEO */ s64 ntfs_device_partition_start_sector_get(struct ntfs_device *dev) { if (!dev) { errno = EINVAL; return -1; } #ifdef HDIO_GETGEO { struct hd_geometry geo; if (!dev->d_ops->ioctl(dev, HDIO_GETGEO, &geo)) { ntfs_log_debug("HDIO_GETGEO start_sect = %lu (0x%lx)\n", geo.start, geo.start); return geo.start; } } #else errno = EOPNOTSUPP; #endif return -1; } static int ntfs_device_get_geo(struct ntfs_device *dev) { int err; if (!dev) { errno = EINVAL; return -1; } err = EOPNOTSUPP; #ifdef ENABLE_HD { hd_data_t *hddata; hd_t *hd, *devlist, *partlist = NULL; str_list_t *names; hd_res_t *res; const int d_name_len = strlen(dev->d_name) + 1; int done = 0; hddata = calloc(1, sizeof(*hddata)); if (!hddata) { err = ENOMEM; goto skip_hd; } /* List all "disk" class devices on the system. */ devlist = hd_list(hddata, hw_disk, 1, NULL); if (!devlist) { free(hddata); err = ENOMEM; goto skip_hd; } /* * Loop over each disk device looking for the device with the * same unix name as @dev. */ for (hd = devlist; hd; hd = hd->next) { if (hd->unix_dev_name && !strncmp(dev->d_name, hd->unix_dev_name, d_name_len)) goto got_hd; if (hd->unix_dev_name2 && !strncmp(dev->d_name, hd->unix_dev_name2, d_name_len)) goto got_hd; for (names = hd->unix_dev_names; names; names = names->next) { if (names->str && !strncmp(dev->d_name, names->str, d_name_len)) goto got_hd; } } /* * Device was not a whole disk device. Unless it is a file it * is likely to be a partition device. List all "partition" * class devices on the system. */ partlist = hd_list(hddata, hw_partition, 1, NULL); for (hd = partlist; hd; hd = hd->next) { if (hd->unix_dev_name && !strncmp(dev->d_name, hd->unix_dev_name, d_name_len)) goto got_part_hd; if (hd->unix_dev_name2 && !strncmp(dev->d_name, hd->unix_dev_name2, d_name_len)) goto got_part_hd; for (names = hd->unix_dev_names; names; names = names->next) { if (names->str && !strncmp(dev->d_name, names->str, d_name_len)) goto got_part_hd; } } /* Failed to find the device. Stop trying and clean up. */ goto end_hd; got_part_hd: /* Get the whole block device the partition device is on. */ hd = hd_get_device_by_idx(hddata, hd->attached_to); if (!hd) goto end_hd; got_hd: /* * @hd is now the whole block device either being formatted or * that the partition being formatted is on. * * Loop over each resource of the disk device looking for the * BIOS legacy geometry obtained from EDD which is what Windows * needs to boot. */ for (res = hd->res; res; res = res->next) { /* geotype 3 is BIOS legacy. */ if (res->any.type != res_disk_geo || res->disk_geo.geotype != 3) continue; dev->d_heads = res->disk_geo.heads; dev->d_sectors_per_track = res->disk_geo.sectors; done = 1; } end_hd: if (partlist) hd_free_hd_list(partlist); hd_free_hd_list(devlist); hd_free_hd_data(hddata); free(hddata); if (done) { ntfs_log_debug("EDD/BIOD legacy heads = %u, sectors " "per track = %u\n", dev->d_heads, dev->d_sectors_per_track); return 0; } } skip_hd: #endif #ifdef HDIO_GETGEO { struct hd_geometry geo; if (!dev->d_ops->ioctl(dev, HDIO_GETGEO, &geo)) { dev->d_heads = geo.heads; dev->d_sectors_per_track = geo.sectors; ntfs_log_debug("HDIO_GETGEO heads = %u, sectors per " "track = %u\n", dev->d_heads, dev->d_sectors_per_track); return 0; } err = errno; } #endif errno = err; return -1; } /** * ntfs_device_heads_get - get number of heads of device * @dev: open device * * On success, return the number of heads on the device @dev. On error return * -1 with errno set to the error code. * * The following error codes are defined: * EINVAL Input parameter error * EOPNOTSUPP System does not support HDIO_GETGEO ioctl * ENOTTY @dev is a file or a device not supporting HDIO_GETGEO * ENOMEM Not enough memory to complete the request */ int ntfs_device_heads_get(struct ntfs_device *dev) { if (!dev) { errno = EINVAL; return -1; } if (dev->d_heads == -1) { if (ntfs_device_get_geo(dev) == -1) return -1; if (dev->d_heads == -1) { errno = EINVAL; return -1; } } return dev->d_heads; } /** * ntfs_device_sectors_per_track_get - get number of sectors per track of device * @dev: open device * * On success, return the number of sectors per track on the device @dev. On * error return -1 with errno set to the error code. * * The following error codes are defined: * EINVAL Input parameter error * EOPNOTSUPP System does not support HDIO_GETGEO ioctl * ENOTTY @dev is a file or a device not supporting HDIO_GETGEO * ENOMEM Not enough memory to complete the request */ int ntfs_device_sectors_per_track_get(struct ntfs_device *dev) { if (!dev) { errno = EINVAL; return -1; } if (dev->d_sectors_per_track == -1) { if (ntfs_device_get_geo(dev) == -1) return -1; if (dev->d_sectors_per_track == -1) { errno = EINVAL; return -1; } } return dev->d_sectors_per_track; } /** * ntfs_device_sector_size_get - get sector size of a device * @dev: open device * * On success, return the sector size in bytes of the device @dev. * On error return -1 with errno set to the error code. * * The following error codes are defined: * EINVAL Input parameter error * EOPNOTSUPP System does not support BLKSSZGET ioctl * ENOTTY @dev is a file or a device not supporting BLKSSZGET */ int ntfs_device_sector_size_get(struct ntfs_device *dev) { if (!dev) { errno = EINVAL; return -1; } #ifdef BLKSSZGET { int sect_size = 0; if (!dev->d_ops->ioctl(dev, BLKSSZGET, §_size)) { ntfs_log_debug("BLKSSZGET sector size = %d bytes\n", sect_size); return sect_size; } } #elif defined(DIOCGSECTORSIZE) { /* FreeBSD */ size_t sect_size = 0; if (!dev->d_ops->ioctl(dev, DIOCGSECTORSIZE, §_size)) { ntfs_log_debug("DIOCGSECTORSIZE sector size = %d bytes\n", (int) sect_size); return sect_size; } } #elif defined(DKIOCGETBLOCKSIZE) { /* Mac OS X */ uint32_t sect_size = 0; if (!dev->d_ops->ioctl(dev, DKIOCGETBLOCKSIZE, §_size)) { ntfs_log_debug("DKIOCGETBLOCKSIZE sector size = %d bytes\n", (int) sect_size); return sect_size; } } #else errno = EOPNOTSUPP; #endif return -1; } /** * ntfs_device_block_size_set - set block size of a device * @dev: open device * @block_size: block size to set @dev to * * On success, return 0. * On error return -1 with errno set to the error code. * * The following error codes are defined: * EINVAL Input parameter error * EOPNOTSUPP System does not support BLKBSZSET ioctl * ENOTTY @dev is a file or a device not supporting BLKBSZSET */ int ntfs_device_block_size_set(struct ntfs_device *dev, int block_size __attribute__((unused))) { if (!dev) { errno = EINVAL; return -1; } #ifdef BLKBSZSET { size_t s_block_size = block_size; if (!dev->d_ops->ioctl(dev, BLKBSZSET, &s_block_size)) { ntfs_log_debug("Used BLKBSZSET to set block size to " "%d bytes.\n", block_size); return 0; } /* If not a block device, pretend it was successful. */ if (!NDevBlock(dev)) return 0; } #else /* If not a block device, pretend it was successful. */ if (!NDevBlock(dev)) return 0; errno = EOPNOTSUPP; #endif return -1; } ntfs-3g-2026.2.25/autogen.sh0000775000175000017500000000154215152260173011003 #!/bin/sh # Run this to generate configure, Makefile.in's, etc (autoreconf --version) < /dev/null > /dev/null 2>&1 || { (autoconf --version) < /dev/null > /dev/null 2>&1 || { echo echo "**Error**: You must have the GNU Build System (autoconf, automake, " echo "libtool, etc) to update the ntfs-3g build system. Download the " echo "appropriate packages for your distribution, or get the source " echo "tar balls from ftp://ftp.gnu.org/pub/gnu/." exit 1 } echo echo "**Error**: Your version of autoconf is too old (you need at least 2.57)" echo "to update the ntfs-3g build system. Download the appropriate " echo "updated package for your distribution, or get the source tar ball " echo "from ftp://ftp.gnu.org/pub/gnu/." exit 1 } echo Running autoreconf --verbose --install --force autoreconf --verbose --install --force ntfs-3g-2026.2.25/aclocal.m40000664000175000017500000021614615152260211010643 # generated automatically by aclocal 1.17 -*- Autoconf -*- # Copyright (C) 1996-2024 Free Software Foundation, Inc. # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY, to the extent permitted by law; without # even the implied warranty of MERCHANTABILITY or FITNESS FOR A # PARTICULAR PURPOSE. m4_ifndef([AC_CONFIG_MACRO_DIRS], [m4_defun([_AM_CONFIG_MACRO_DIRS], [])m4_defun([AC_CONFIG_MACRO_DIRS], [_AM_CONFIG_MACRO_DIRS($@)])]) m4_ifndef([AC_AUTOCONF_VERSION], [m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl m4_if(m4_defn([AC_AUTOCONF_VERSION]), [2.72],, [m4_warning([this file was generated for autoconf 2.72. You have another version of autoconf. It may work, but is not guaranteed to. If you have problems, you may need to regenerate the build system entirely. To do so, use the procedure documented by the package, typically 'autoreconf'.])]) # libgcrypt.m4 - Autoconf macros to detect libgcrypt # Copyright (C) 2002, 2003, 2004, 2011, 2014, 2018, 2020, # 2024 g10 Code GmbH # # This file is free software; as a special exception the author gives # unlimited permission to copy and/or distribute it, with or without # modifications, as long as this notice is preserved. # # This file is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY, to the extent permitted by law; without even the # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # # Last-changed: 2024-06-13 dnl dnl Find gpgrt-config, which uses .pc file dnl (minimum pkg-config functionality, supporting cross build) dnl dnl _AM_PATH_GPGRT_CONFIG AC_DEFUN([_AM_PATH_GPGRT_CONFIG],[dnl AC_PATH_PROG(GPGRT_CONFIG, gpgrt-config, no, [$prefix/bin:$PATH]) if test "$GPGRT_CONFIG" != "no"; then # Determine gpgrt_libdir # # Get the prefix of gpgrt-config assuming it's something like: # /bin/gpgrt-config gpgrt_prefix=${GPGRT_CONFIG%/*/*} possible_libdir1=${gpgrt_prefix}/lib # Determine by using system libdir-format with CC, it's like: # Normal style: /usr/lib # GNU cross style: /usr//lib # Debian style: /usr/lib/ # Fedora/openSUSE style: /usr/lib, /usr/lib32 or /usr/lib64 # It is assumed that CC is specified to the one of host on cross build. if libdir_candidates=$(${CC:-cc} -print-search-dirs | \ sed -n -e "/^libraries/{s/libraries: =//;s/:/\\ /g;p;}"); then # From the output of -print-search-dirs, select valid pkgconfig dirs. libdir_candidates=$(for dir in $libdir_candidates; do if p=$(cd $dir 2>/dev/null && pwd); then test -d "$p/pkgconfig" && echo $p; fi done) for possible_libdir0 in $libdir_candidates; do # possible_libdir0: # Fallback candidate, the one of system-installed (by $CC) # (/usr//lib, /usr/lib/ or /usr/lib32) # possible_libdir1: # Another candidate, user-locally-installed # (/lib) # possible_libdir2 # Most preferred # (//lib, # /lib/ or /lib32) if test "${possible_libdir0##*/}" = "lib"; then possible_prefix0=${possible_libdir0%/lib} possible_prefix0_triplet=${possible_prefix0##*/} if test -z "$possible_prefix0_triplet"; then continue fi possible_libdir2=${gpgrt_prefix}/$possible_prefix0_triplet/lib else possible_prefix0=${possible_libdir0%%/lib*} possible_libdir2=${gpgrt_prefix}${possible_libdir0#$possible_prefix0} fi if test -f ${possible_libdir2}/pkgconfig/gpg-error.pc; then gpgrt_libdir=${possible_libdir2} elif test -f ${possible_libdir1}/pkgconfig/gpg-error.pc; then gpgrt_libdir=${possible_libdir1} elif test -f ${possible_libdir0}/pkgconfig/gpg-error.pc; then gpgrt_libdir=${possible_libdir0} fi if test -n "$gpgrt_libdir"; then break; fi done fi if test -z "$gpgrt_libdir"; then # No valid pkgconfig dir in any of the system directories, fallback gpgrt_libdir=${possible_libdir1} fi else unset GPGRT_CONFIG fi if test -n "$gpgrt_libdir"; then # Add the --libdir option to GPGRT_CONFIG GPGRT_CONFIG="$GPGRT_CONFIG --libdir=$gpgrt_libdir" # Make sure if gpgrt-config really works, by testing config gpg-error if ! $GPGRT_CONFIG gpg-error --exists; then # If it doesn't work, clear the GPGRT_CONFIG variable. unset GPGRT_CONFIG fi else # GPGRT_CONFIG found but no suitable dir for --libdir found. # This is a failure. Clear the GPGRT_CONFIG variable. unset GPGRT_CONFIG fi ]) dnl AM_PATH_LIBGCRYPT([MINIMUM-VERSION, dnl [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND ]]]) dnl Test for libgcrypt and define LIBGCRYPT_CFLAGS and LIBGCRYPT_LIBS. dnl MINIMUM-VERSION is a string with the version number optionally prefixed dnl with the API version to also check the API compatibility. Example: dnl a MINIMUM-VERSION of 1:1.2.5 won't pass the test unless the installed dnl version of libgcrypt is at least 1.2.5 *and* the API number is 1. Using dnl this features allows to prevent build against newer versions of libgcrypt dnl with a changed API. dnl dnl If a prefix option is not used, the config script is first dnl searched in $SYSROOT/bin and then along $PATH. If the used dnl config script does not match the host specification the script dnl is added to the gpg_config_script_warn variable. dnl AC_DEFUN([AM_PATH_LIBGCRYPT], [ AC_REQUIRE([AC_CANONICAL_HOST])dnl AC_REQUIRE([_AM_PATH_GPGRT_CONFIG])dnl AC_ARG_WITH(libgcrypt-prefix, AS_HELP_STRING([--with-libgcrypt-prefix=PFX], [prefix where LIBGCRYPT is installed (optional)]), libgcrypt_config_prefix="$withval", libgcrypt_config_prefix="") if test x"${LIBGCRYPT_CONFIG}" = x ; then if test x"${libgcrypt_config_prefix}" != x ; then LIBGCRYPT_CONFIG="${libgcrypt_config_prefix}/bin/libgcrypt-config" fi fi use_gpgrt_config="" if test x"$GPGRT_CONFIG" != x -a "$GPGRT_CONFIG" != "no"; then if $GPGRT_CONFIG libgcrypt --exists; then LIBGCRYPT_CONFIG="$GPGRT_CONFIG libgcrypt" AC_MSG_NOTICE([Use gpgrt-config as libgcrypt-config]) use_gpgrt_config=yes fi fi if test -z "$use_gpgrt_config"; then if test x"${LIBGCRYPT_CONFIG}" = x ; then case "${SYSROOT}" in /*) if test -x "${SYSROOT}/bin/libgcrypt-config" ; then LIBGCRYPT_CONFIG="${SYSROOT}/bin/libgcrypt-config" fi ;; '') ;; *) AC_MSG_WARN([Ignoring \$SYSROOT as it is not an absolute path.]) ;; esac fi AC_PATH_PROG(LIBGCRYPT_CONFIG, libgcrypt-config, no) fi tmp=ifelse([$1], ,1:1.2.0,$1) if echo "$tmp" | grep ':' >/dev/null 2>/dev/null ; then req_libgcrypt_api=`echo "$tmp" | sed 's/\(.*\):\(.*\)/\1/'` min_libgcrypt_version=`echo "$tmp" | sed 's/\(.*\):\(.*\)/\2/'` else req_libgcrypt_api=0 min_libgcrypt_version="$tmp" fi AC_MSG_CHECKING(for LIBGCRYPT - version >= $min_libgcrypt_version) ok=no if test "$LIBGCRYPT_CONFIG" != "no" ; then req_major=`echo $min_libgcrypt_version | \ sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\1/'` req_minor=`echo $min_libgcrypt_version | \ sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\2/'` req_micro=`echo $min_libgcrypt_version | \ sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\3/'` if test -z "$use_gpgrt_config"; then libgcrypt_config_version=`$LIBGCRYPT_CONFIG --version` else libgcrypt_config_version=`$LIBGCRYPT_CONFIG --modversion` fi major=`echo $libgcrypt_config_version | \ sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\1/'` minor=`echo $libgcrypt_config_version | \ sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\2/'` micro=`echo $libgcrypt_config_version | \ sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\3/'` if test "$major" -gt "$req_major"; then ok=yes else if test "$major" -eq "$req_major"; then if test "$minor" -gt "$req_minor"; then ok=yes else if test "$minor" -eq "$req_minor"; then if test "$micro" -ge "$req_micro"; then ok=yes fi fi fi fi fi fi if test $ok = yes; then AC_MSG_RESULT([yes ($libgcrypt_config_version)]) else AC_MSG_RESULT(no) fi if test $ok = yes; then # If we have a recent libgcrypt, we should also check that the # API is compatible if test "$req_libgcrypt_api" -gt 0 ; then if test -z "$use_gpgrt_config"; then tmp=`$LIBGCRYPT_CONFIG --api-version 2>/dev/null || echo 0` else tmp=`$LIBGCRYPT_CONFIG --variable=api_version 2>/dev/null || echo 0` fi if test "$tmp" -gt 0 ; then AC_MSG_CHECKING([LIBGCRYPT API version]) if test "$req_libgcrypt_api" -eq "$tmp" ; then AC_MSG_RESULT([okay]) else ok=no AC_MSG_RESULT([does not match. want=$req_libgcrypt_api got=$tmp]) fi fi fi fi if test $ok = yes; then LIBGCRYPT_CFLAGS=`$LIBGCRYPT_CONFIG --cflags` LIBGCRYPT_LIBS=`$LIBGCRYPT_CONFIG --libs` ifelse([$2], , :, [$2]) if test -z "$use_gpgrt_config"; then libgcrypt_config_host=`$LIBGCRYPT_CONFIG --host 2>/dev/null || echo none` else libgcrypt_config_host=`$LIBGCRYPT_CONFIG --variable=host 2>/dev/null || echo none` fi if test x"$libgcrypt_config_host" != xnone ; then if test x"$libgcrypt_config_host" != x"$host" ; then AC_MSG_WARN([[ *** *** The config script "$LIBGCRYPT_CONFIG" was *** built for $libgcrypt_config_host and thus may not match the *** used host $host. *** You may want to use the configure option --with-libgcrypt-prefix *** to specify a matching config script or use \$SYSROOT. ***]]) gpg_config_script_warn="$gpg_config_script_warn libgcrypt" fi fi else LIBGCRYPT_CFLAGS="" LIBGCRYPT_LIBS="" ifelse([$3], , :, [$3]) fi AC_SUBST(LIBGCRYPT_CFLAGS) AC_SUBST(LIBGCRYPT_LIBS) ]) # pkg.m4 - Macros to locate and use pkg-config. -*- Autoconf -*- # serial 12 (pkg-config-0.29.2) dnl Copyright © 2004 Scott James Remnant . dnl Copyright © 2012-2015 Dan Nicholson dnl dnl This program is free software; you can redistribute it and/or modify dnl it under the terms of the GNU General Public License as published by dnl the Free Software Foundation; either version 2 of the License, or dnl (at your option) any later version. dnl dnl This program is distributed in the hope that it will be useful, but dnl WITHOUT ANY WARRANTY; without even the implied warranty of dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU dnl General Public License for more details. dnl dnl You should have received a copy of the GNU General Public License dnl along with this program; if not, write to the Free Software dnl Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA dnl 02111-1307, USA. dnl dnl As a special exception to the GNU General Public License, if you dnl distribute this file as part of a program that contains a dnl configuration script generated by Autoconf, you may include it under dnl the same distribution terms that you use for the rest of that dnl program. dnl PKG_PREREQ(MIN-VERSION) dnl ----------------------- dnl Since: 0.29 dnl dnl Verify that the version of the pkg-config macros are at least dnl MIN-VERSION. Unlike PKG_PROG_PKG_CONFIG, which checks the user's dnl installed version of pkg-config, this checks the developer's version dnl of pkg.m4 when generating configure. dnl dnl To ensure that this macro is defined, also add: dnl m4_ifndef([PKG_PREREQ], dnl [m4_fatal([must install pkg-config 0.29 or later before running autoconf/autogen])]) dnl dnl See the "Since" comment for each macro you use to see what version dnl of the macros you require. m4_defun([PKG_PREREQ], [m4_define([PKG_MACROS_VERSION], [0.29.2]) m4_if(m4_version_compare(PKG_MACROS_VERSION, [$1]), -1, [m4_fatal([pkg.m4 version $1 or higher is required but ]PKG_MACROS_VERSION[ found])]) ])dnl PKG_PREREQ dnl PKG_PROG_PKG_CONFIG([MIN-VERSION]) dnl ---------------------------------- dnl Since: 0.16 dnl dnl Search for the pkg-config tool and set the PKG_CONFIG variable to dnl first found in the path. Checks that the version of pkg-config found dnl is at least MIN-VERSION. If MIN-VERSION is not specified, 0.9.0 is dnl used since that's the first version where most current features of dnl pkg-config existed. AC_DEFUN([PKG_PROG_PKG_CONFIG], [m4_pattern_forbid([^_?PKG_[A-Z_]+$]) m4_pattern_allow([^PKG_CONFIG(_(PATH|LIBDIR|SYSROOT_DIR|ALLOW_SYSTEM_(CFLAGS|LIBS)))?$]) m4_pattern_allow([^PKG_CONFIG_(DISABLE_UNINSTALLED|TOP_BUILD_DIR|DEBUG_SPEW)$]) AC_ARG_VAR([PKG_CONFIG], [path to pkg-config utility]) AC_ARG_VAR([PKG_CONFIG_PATH], [directories to add to pkg-config's search path]) AC_ARG_VAR([PKG_CONFIG_LIBDIR], [path overriding pkg-config's built-in search path]) if test "x$ac_cv_env_PKG_CONFIG_set" != "xset"; then AC_PATH_TOOL([PKG_CONFIG], [pkg-config]) fi if test -n "$PKG_CONFIG"; then _pkg_min_version=m4_default([$1], [0.9.0]) AC_MSG_CHECKING([pkg-config is at least version $_pkg_min_version]) if $PKG_CONFIG --atleast-pkgconfig-version $_pkg_min_version; then AC_MSG_RESULT([yes]) else AC_MSG_RESULT([no]) PKG_CONFIG="" fi fi[]dnl ])dnl PKG_PROG_PKG_CONFIG dnl PKG_CHECK_EXISTS(MODULES, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND]) dnl ------------------------------------------------------------------- dnl Since: 0.18 dnl dnl Check to see whether a particular set of modules exists. Similar to dnl PKG_CHECK_MODULES(), but does not set variables or print errors. dnl dnl Please remember that m4 expands AC_REQUIRE([PKG_PROG_PKG_CONFIG]) dnl only at the first occurrence in configure.ac, so if the first place dnl it's called might be skipped (such as if it is within an "if", you dnl have to call PKG_CHECK_EXISTS manually AC_DEFUN([PKG_CHECK_EXISTS], [AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl if test -n "$PKG_CONFIG" && \ AC_RUN_LOG([$PKG_CONFIG --exists --print-errors "$1"]); then m4_default([$2], [:]) m4_ifvaln([$3], [else $3])dnl fi]) dnl _PKG_CONFIG([VARIABLE], [COMMAND], [MODULES]) dnl --------------------------------------------- dnl Internal wrapper calling pkg-config via PKG_CONFIG and setting dnl pkg_failed based on the result. m4_define([_PKG_CONFIG], [if test -n "$$1"; then pkg_cv_[]$1="$$1" elif test -n "$PKG_CONFIG"; then PKG_CHECK_EXISTS([$3], [pkg_cv_[]$1=`$PKG_CONFIG --[]$2 "$3" 2>/dev/null` test "x$?" != "x0" && pkg_failed=yes ], [pkg_failed=yes]) else pkg_failed=untried fi[]dnl ])dnl _PKG_CONFIG dnl _PKG_SHORT_ERRORS_SUPPORTED dnl --------------------------- dnl Internal check to see if pkg-config supports short errors. AC_DEFUN([_PKG_SHORT_ERRORS_SUPPORTED], [AC_REQUIRE([PKG_PROG_PKG_CONFIG]) if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then _pkg_short_errors_supported=yes else _pkg_short_errors_supported=no fi[]dnl ])dnl _PKG_SHORT_ERRORS_SUPPORTED dnl PKG_CHECK_MODULES(VARIABLE-PREFIX, MODULES, [ACTION-IF-FOUND], dnl [ACTION-IF-NOT-FOUND]) dnl -------------------------------------------------------------- dnl Since: 0.4.0 dnl dnl Note that if there is a possibility the first call to dnl PKG_CHECK_MODULES might not happen, you should be sure to include an dnl explicit call to PKG_PROG_PKG_CONFIG in your configure.ac AC_DEFUN([PKG_CHECK_MODULES], [AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl AC_ARG_VAR([$1][_CFLAGS], [C compiler flags for $1, overriding pkg-config])dnl AC_ARG_VAR([$1][_LIBS], [linker flags for $1, overriding pkg-config])dnl pkg_failed=no AC_MSG_CHECKING([for $2]) _PKG_CONFIG([$1][_CFLAGS], [cflags], [$2]) _PKG_CONFIG([$1][_LIBS], [libs], [$2]) m4_define([_PKG_TEXT], [Alternatively, you may set the environment variables $1[]_CFLAGS and $1[]_LIBS to avoid the need to call pkg-config. See the pkg-config man page for more details.]) if test $pkg_failed = yes; then AC_MSG_RESULT([no]) _PKG_SHORT_ERRORS_SUPPORTED if test $_pkg_short_errors_supported = yes; then $1[]_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "$2" 2>&1` else $1[]_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "$2" 2>&1` fi # Put the nasty error message in config.log where it belongs echo "$$1[]_PKG_ERRORS" >&AS_MESSAGE_LOG_FD m4_default([$4], [AC_MSG_ERROR( [Package requirements ($2) were not met: $$1_PKG_ERRORS Consider adjusting the PKG_CONFIG_PATH environment variable if you installed software in a non-standard prefix. _PKG_TEXT])[]dnl ]) elif test $pkg_failed = untried; then AC_MSG_RESULT([no]) m4_default([$4], [AC_MSG_FAILURE( [The pkg-config script could not be found or is too old. Make sure it is in your PATH or set the PKG_CONFIG environment variable to the full path to pkg-config. _PKG_TEXT To get pkg-config, see .])[]dnl ]) else $1[]_CFLAGS=$pkg_cv_[]$1[]_CFLAGS $1[]_LIBS=$pkg_cv_[]$1[]_LIBS AC_MSG_RESULT([yes]) $3 fi[]dnl ])dnl PKG_CHECK_MODULES dnl PKG_CHECK_MODULES_STATIC(VARIABLE-PREFIX, MODULES, [ACTION-IF-FOUND], dnl [ACTION-IF-NOT-FOUND]) dnl --------------------------------------------------------------------- dnl Since: 0.29 dnl dnl Checks for existence of MODULES and gathers its build flags with dnl static libraries enabled. Sets VARIABLE-PREFIX_CFLAGS from --cflags dnl and VARIABLE-PREFIX_LIBS from --libs. dnl dnl Note that if there is a possibility the first call to dnl PKG_CHECK_MODULES_STATIC might not happen, you should be sure to dnl include an explicit call to PKG_PROG_PKG_CONFIG in your dnl configure.ac. AC_DEFUN([PKG_CHECK_MODULES_STATIC], [AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl _save_PKG_CONFIG=$PKG_CONFIG PKG_CONFIG="$PKG_CONFIG --static" PKG_CHECK_MODULES($@) PKG_CONFIG=$_save_PKG_CONFIG[]dnl ])dnl PKG_CHECK_MODULES_STATIC dnl PKG_INSTALLDIR([DIRECTORY]) dnl ------------------------- dnl Since: 0.27 dnl dnl Substitutes the variable pkgconfigdir as the location where a module dnl should install pkg-config .pc files. By default the directory is dnl $libdir/pkgconfig, but the default can be changed by passing dnl DIRECTORY. The user can override through the --with-pkgconfigdir dnl parameter. AC_DEFUN([PKG_INSTALLDIR], [m4_pushdef([pkg_default], [m4_default([$1], ['${libdir}/pkgconfig'])]) m4_pushdef([pkg_description], [pkg-config installation directory @<:@]pkg_default[@:>@]) AC_ARG_WITH([pkgconfigdir], [AS_HELP_STRING([--with-pkgconfigdir], pkg_description)],, [with_pkgconfigdir=]pkg_default) AC_SUBST([pkgconfigdir], [$with_pkgconfigdir]) m4_popdef([pkg_default]) m4_popdef([pkg_description]) ])dnl PKG_INSTALLDIR dnl PKG_NOARCH_INSTALLDIR([DIRECTORY]) dnl -------------------------------- dnl Since: 0.27 dnl dnl Substitutes the variable noarch_pkgconfigdir as the location where a dnl module should install arch-independent pkg-config .pc files. By dnl default the directory is $datadir/pkgconfig, but the default can be dnl changed by passing DIRECTORY. The user can override through the dnl --with-noarch-pkgconfigdir parameter. AC_DEFUN([PKG_NOARCH_INSTALLDIR], [m4_pushdef([pkg_default], [m4_default([$1], ['${datadir}/pkgconfig'])]) m4_pushdef([pkg_description], [pkg-config arch-independent installation directory @<:@]pkg_default[@:>@]) AC_ARG_WITH([noarch-pkgconfigdir], [AS_HELP_STRING([--with-noarch-pkgconfigdir], pkg_description)],, [with_noarch_pkgconfigdir=]pkg_default) AC_SUBST([noarch_pkgconfigdir], [$with_noarch_pkgconfigdir]) m4_popdef([pkg_default]) m4_popdef([pkg_description]) ])dnl PKG_NOARCH_INSTALLDIR dnl PKG_CHECK_VAR(VARIABLE, MODULE, CONFIG-VARIABLE, dnl [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND]) dnl ------------------------------------------- dnl Since: 0.28 dnl dnl Retrieves the value of the pkg-config variable for the given module. AC_DEFUN([PKG_CHECK_VAR], [AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl AC_ARG_VAR([$1], [value of $3 for $2, overriding pkg-config])dnl _PKG_CONFIG([$1], [variable="][$3]["], [$2]) AS_VAR_COPY([$1], [pkg_cv_][$1]) AS_VAR_IF([$1], [""], [$5], [$4])dnl ])dnl PKG_CHECK_VAR dnl PKG_WITH_MODULES(VARIABLE-PREFIX, MODULES, dnl [ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND], dnl [DESCRIPTION], [DEFAULT]) dnl ------------------------------------------ dnl dnl Prepare a "--with-" configure option using the lowercase dnl [VARIABLE-PREFIX] name, merging the behaviour of AC_ARG_WITH and dnl PKG_CHECK_MODULES in a single macro. AC_DEFUN([PKG_WITH_MODULES], [ m4_pushdef([with_arg], m4_tolower([$1])) m4_pushdef([description], [m4_default([$5], [build with ]with_arg[ support])]) m4_pushdef([def_arg], [m4_default([$6], [auto])]) m4_pushdef([def_action_if_found], [AS_TR_SH([with_]with_arg)=yes]) m4_pushdef([def_action_if_not_found], [AS_TR_SH([with_]with_arg)=no]) m4_case(def_arg, [yes],[m4_pushdef([with_without], [--without-]with_arg)], [m4_pushdef([with_without],[--with-]with_arg)]) AC_ARG_WITH(with_arg, AS_HELP_STRING(with_without, description[ @<:@default=]def_arg[@:>@]),, [AS_TR_SH([with_]with_arg)=def_arg]) AS_CASE([$AS_TR_SH([with_]with_arg)], [yes],[PKG_CHECK_MODULES([$1],[$2],$3,$4)], [auto],[PKG_CHECK_MODULES([$1],[$2], [m4_n([def_action_if_found]) $3], [m4_n([def_action_if_not_found]) $4])]) m4_popdef([with_arg]) m4_popdef([description]) m4_popdef([def_arg]) ])dnl PKG_WITH_MODULES dnl PKG_HAVE_WITH_MODULES(VARIABLE-PREFIX, MODULES, dnl [DESCRIPTION], [DEFAULT]) dnl ----------------------------------------------- dnl dnl Convenience macro to trigger AM_CONDITIONAL after PKG_WITH_MODULES dnl check._[VARIABLE-PREFIX] is exported as make variable. AC_DEFUN([PKG_HAVE_WITH_MODULES], [ PKG_WITH_MODULES([$1],[$2],,,[$3],[$4]) AM_CONDITIONAL([HAVE_][$1], [test "$AS_TR_SH([with_]m4_tolower([$1]))" = "yes"]) ])dnl PKG_HAVE_WITH_MODULES dnl PKG_HAVE_DEFINE_WITH_MODULES(VARIABLE-PREFIX, MODULES, dnl [DESCRIPTION], [DEFAULT]) dnl ------------------------------------------------------ dnl dnl Convenience macro to run AM_CONDITIONAL and AC_DEFINE after dnl PKG_WITH_MODULES check. HAVE_[VARIABLE-PREFIX] is exported as make dnl and preprocessor variable. AC_DEFUN([PKG_HAVE_DEFINE_WITH_MODULES], [ PKG_HAVE_WITH_MODULES([$1],[$2],[$3],[$4]) AS_IF([test "$AS_TR_SH([with_]m4_tolower([$1]))" = "yes"], [AC_DEFINE([HAVE_][$1], 1, [Enable ]m4_tolower([$1])[ support])]) ])dnl PKG_HAVE_DEFINE_WITH_MODULES # Copyright (C) 2002-2024 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # AM_AUTOMAKE_VERSION(VERSION) # ---------------------------- # Automake X.Y traces this macro to ensure aclocal.m4 has been # generated from the m4 files accompanying Automake X.Y. # (This private macro should not be called outside this file.) AC_DEFUN([AM_AUTOMAKE_VERSION], [am__api_version='1.17' dnl Some users find AM_AUTOMAKE_VERSION and mistake it for a way to dnl require some minimum version. Point them to the right macro. m4_if([$1], [1.17], [], [AC_FATAL([Do not call $0, use AM_INIT_AUTOMAKE([$1]).])])dnl ]) # _AM_AUTOCONF_VERSION(VERSION) # ----------------------------- # aclocal traces this macro to find the Autoconf version. # This is a private macro too. Using m4_define simplifies # the logic in aclocal, which can simply ignore this definition. m4_define([_AM_AUTOCONF_VERSION], []) # AM_SET_CURRENT_AUTOMAKE_VERSION # ------------------------------- # Call AM_AUTOMAKE_VERSION and AM_AUTOMAKE_VERSION so they can be traced. # This function is AC_REQUIREd by AM_INIT_AUTOMAKE. AC_DEFUN([AM_SET_CURRENT_AUTOMAKE_VERSION], [AM_AUTOMAKE_VERSION([1.17])dnl m4_ifndef([AC_AUTOCONF_VERSION], [m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl _AM_AUTOCONF_VERSION(m4_defn([AC_AUTOCONF_VERSION]))]) # AM_AUX_DIR_EXPAND -*- Autoconf -*- # Copyright (C) 2001-2024 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # For projects using AC_CONFIG_AUX_DIR([foo]), Autoconf sets # $ac_aux_dir to '$srcdir/foo'. In other projects, it is set to # '$srcdir', '$srcdir/..', or '$srcdir/../..'. # # Of course, Automake must honor this variable whenever it calls a # tool from the auxiliary directory. The problem is that $srcdir (and # therefore $ac_aux_dir as well) can be either absolute or relative, # depending on how configure is run. This is pretty annoying, since # it makes $ac_aux_dir quite unusable in subdirectories: in the top # source directory, any form will work fine, but in subdirectories a # relative path needs to be adjusted first. # # $ac_aux_dir/missing # fails when called from a subdirectory if $ac_aux_dir is relative # $top_srcdir/$ac_aux_dir/missing # fails if $ac_aux_dir is absolute, # fails when called from a subdirectory in a VPATH build with # a relative $ac_aux_dir # # The reason of the latter failure is that $top_srcdir and $ac_aux_dir # are both prefixed by $srcdir. In an in-source build this is usually # harmless because $srcdir is '.', but things will broke when you # start a VPATH build or use an absolute $srcdir. # # So we could use something similar to $top_srcdir/$ac_aux_dir/missing, # iff we strip the leading $srcdir from $ac_aux_dir. That would be: # am_aux_dir='\$(top_srcdir)/'`expr "$ac_aux_dir" : "$srcdir//*\(.*\)"` # and then we would define $MISSING as # MISSING="\${SHELL} $am_aux_dir/missing" # This will work as long as MISSING is not called from configure, because # unfortunately $(top_srcdir) has no meaning in configure. # However there are other variables, like CC, which are often used in # configure, and could therefore not use this "fixed" $ac_aux_dir. # # Another solution, used here, is to always expand $ac_aux_dir to an # absolute PATH. The drawback is that using absolute paths prevent a # configured tree to be moved without reconfiguration. AC_DEFUN([AM_AUX_DIR_EXPAND], [AC_REQUIRE([AC_CONFIG_AUX_DIR_DEFAULT])dnl # Expand $ac_aux_dir to an absolute path. am_aux_dir=`cd "$ac_aux_dir" && pwd` ]) # AM_CONDITIONAL -*- Autoconf -*- # Copyright (C) 1997-2024 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # AM_CONDITIONAL(NAME, SHELL-CONDITION) # ------------------------------------- # Define a conditional. AC_DEFUN([AM_CONDITIONAL], [AC_PREREQ([2.52])dnl m4_if([$1], [TRUE], [AC_FATAL([$0: invalid condition: $1])], [$1], [FALSE], [AC_FATAL([$0: invalid condition: $1])])dnl AC_SUBST([$1_TRUE])dnl AC_SUBST([$1_FALSE])dnl _AM_SUBST_NOTMAKE([$1_TRUE])dnl _AM_SUBST_NOTMAKE([$1_FALSE])dnl m4_define([_AM_COND_VALUE_$1], [$2])dnl if $2; then $1_TRUE= $1_FALSE='#' else $1_TRUE='#' $1_FALSE= fi AC_CONFIG_COMMANDS_PRE( [if test -z "${$1_TRUE}" && test -z "${$1_FALSE}"; then AC_MSG_ERROR([[conditional "$1" was never defined. Usually this means the macro was only invoked conditionally.]]) fi])]) # Copyright (C) 1999-2024 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # There are a few dirty hacks below to avoid letting 'AC_PROG_CC' be # written in clear, in which case automake, when reading aclocal.m4, # will think it sees a *use*, and therefore will trigger all it's # C support machinery. Also note that it means that autoscan, seeing # CC etc. in the Makefile, will ask for an AC_PROG_CC use... # _AM_DEPENDENCIES(NAME) # ---------------------- # See how the compiler implements dependency checking. # NAME is "CC", "CXX", "OBJC", "OBJCXX", "UPC", or "GJC". # We try a few techniques and use that to set a single cache variable. # # We don't AC_REQUIRE the corresponding AC_PROG_CC since the latter was # modified to invoke _AM_DEPENDENCIES(CC); we would have a circular # dependency, and given that the user is not expected to run this macro, # just rely on AC_PROG_CC. AC_DEFUN([_AM_DEPENDENCIES], [AC_REQUIRE([AM_SET_DEPDIR])dnl AC_REQUIRE([AM_OUTPUT_DEPENDENCY_COMMANDS])dnl AC_REQUIRE([AM_MAKE_INCLUDE])dnl AC_REQUIRE([AM_DEP_TRACK])dnl m4_if([$1], [CC], [depcc="$CC" am_compiler_list=], [$1], [CXX], [depcc="$CXX" am_compiler_list=], [$1], [OBJC], [depcc="$OBJC" am_compiler_list='gcc3 gcc'], [$1], [OBJCXX], [depcc="$OBJCXX" am_compiler_list='gcc3 gcc'], [$1], [UPC], [depcc="$UPC" am_compiler_list=], [$1], [GCJ], [depcc="$GCJ" am_compiler_list='gcc3 gcc'], [depcc="$$1" am_compiler_list=]) AC_CACHE_CHECK([dependency style of $depcc], [am_cv_$1_dependencies_compiler_type], [if test -z "$AMDEP_TRUE" && test -f "$am_depcomp"; then # We make a subdir and do the tests there. Otherwise we can end up # making bogus files that we don't know about and never remove. For # instance it was reported that on HP-UX the gcc test will end up # making a dummy file named 'D' -- because '-MD' means "put the output # in D". rm -rf conftest.dir mkdir conftest.dir # Copy depcomp to subdir because otherwise we won't find it if we're # using a relative directory. cp "$am_depcomp" conftest.dir cd conftest.dir # We will build objects and dependencies in a subdirectory because # it helps to detect inapplicable dependency modes. For instance # both Tru64's cc and ICC support -MD to output dependencies as a # side effect of compilation, but ICC will put the dependencies in # the current directory while Tru64 will put them in the object # directory. mkdir sub am_cv_$1_dependencies_compiler_type=none if test "$am_compiler_list" = ""; then am_compiler_list=`sed -n ['s/^#*\([a-zA-Z0-9]*\))$/\1/p'] < ./depcomp` fi am__universal=false m4_case([$1], [CC], [case " $depcc " in #( *\ -arch\ *\ -arch\ *) am__universal=true ;; esac], [CXX], [case " $depcc " in #( *\ -arch\ *\ -arch\ *) am__universal=true ;; esac]) for depmode in $am_compiler_list; do # Setup a source with many dependencies, because some compilers # like to wrap large dependency lists on column 80 (with \), and # we should not choose a depcomp mode which is confused by this. # # We need to recreate these files for each test, as the compiler may # overwrite some of them when testing with obscure command lines. # This happens at least with the AIX C compiler. : > sub/conftest.c for i in 1 2 3 4 5 6; do echo '#include "conftst'$i'.h"' >> sub/conftest.c # Using ": > sub/conftst$i.h" creates only sub/conftst1.h with # Solaris 10 /bin/sh. echo '/* dummy */' > sub/conftst$i.h done echo "${am__include} ${am__quote}sub/conftest.Po${am__quote}" > confmf # We check with '-c' and '-o' for the sake of the "dashmstdout" # mode. It turns out that the SunPro C++ compiler does not properly # handle '-M -o', and we need to detect this. Also, some Intel # versions had trouble with output in subdirs. am__obj=sub/conftest.${OBJEXT-o} am__minus_obj="-o $am__obj" case $depmode in gcc) # This depmode causes a compiler race in universal mode. test "$am__universal" = false || continue ;; nosideeffect) # After this tag, mechanisms are not by side-effect, so they'll # only be used when explicitly requested. if test "x$enable_dependency_tracking" = xyes; then continue else break fi ;; msvc7 | msvc7msys | msvisualcpp | msvcmsys) # This compiler won't grok '-c -o', but also, the minuso test has # not run yet. These depmodes are late enough in the game, and # so weak that their functioning should not be impacted. am__obj=conftest.${OBJEXT-o} am__minus_obj= ;; none) break ;; esac if depmode=$depmode \ source=sub/conftest.c object=$am__obj \ depfile=sub/conftest.Po tmpdepfile=sub/conftest.TPo \ $SHELL ./depcomp $depcc -c $am__minus_obj sub/conftest.c \ >/dev/null 2>conftest.err && grep sub/conftst1.h sub/conftest.Po > /dev/null 2>&1 && grep sub/conftst6.h sub/conftest.Po > /dev/null 2>&1 && grep $am__obj sub/conftest.Po > /dev/null 2>&1 && ${MAKE-make} -s -f confmf > /dev/null 2>&1; then # icc doesn't choke on unknown options, it will just issue warnings # or remarks (even with -Werror). So we grep stderr for any message # that says an option was ignored or not supported. # When given -MP, icc 7.0 and 7.1 complain thus: # icc: Command line warning: ignoring option '-M'; no argument required # The diagnosis changed in icc 8.0: # icc: Command line remark: option '-MP' not supported if (grep 'ignoring option' conftest.err || grep 'not supported' conftest.err) >/dev/null 2>&1; then :; else am_cv_$1_dependencies_compiler_type=$depmode break fi fi done cd .. rm -rf conftest.dir else am_cv_$1_dependencies_compiler_type=none fi ]) AC_SUBST([$1DEPMODE], [depmode=$am_cv_$1_dependencies_compiler_type]) AM_CONDITIONAL([am__fastdep$1], [ test "x$enable_dependency_tracking" != xno \ && test "$am_cv_$1_dependencies_compiler_type" = gcc3]) ]) # AM_SET_DEPDIR # ------------- # Choose a directory name for dependency files. # This macro is AC_REQUIREd in _AM_DEPENDENCIES. AC_DEFUN([AM_SET_DEPDIR], [AC_REQUIRE([AM_SET_LEADING_DOT])dnl AC_SUBST([DEPDIR], ["${am__leading_dot}deps"])dnl ]) # AM_DEP_TRACK # ------------ AC_DEFUN([AM_DEP_TRACK], [AC_ARG_ENABLE([dependency-tracking], [dnl AS_HELP_STRING( [--enable-dependency-tracking], [do not reject slow dependency extractors]) AS_HELP_STRING( [--disable-dependency-tracking], [speeds up one-time build])]) if test "x$enable_dependency_tracking" != xno; then am_depcomp="$ac_aux_dir/depcomp" AMDEPBACKSLASH='\' am__nodep='_no' fi AM_CONDITIONAL([AMDEP], [test "x$enable_dependency_tracking" != xno]) AC_SUBST([AMDEPBACKSLASH])dnl _AM_SUBST_NOTMAKE([AMDEPBACKSLASH])dnl AC_SUBST([am__nodep])dnl _AM_SUBST_NOTMAKE([am__nodep])dnl ]) # Generate code to set up dependency tracking. -*- Autoconf -*- # Copyright (C) 1999-2024 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # _AM_OUTPUT_DEPENDENCY_COMMANDS # ------------------------------ AC_DEFUN([_AM_OUTPUT_DEPENDENCY_COMMANDS], [{ # Older Autoconf quotes --file arguments for eval, but not when files # are listed without --file. Let's play safe and only enable the eval # if we detect the quoting. # TODO: see whether this extra hack can be removed once we start # requiring Autoconf 2.70 or later. AS_CASE([$CONFIG_FILES], [*\'*], [eval set x "$CONFIG_FILES"], [*], [set x $CONFIG_FILES]) shift # Used to flag and report bootstrapping failures. am_rc=0 for am_mf do # Strip MF so we end up with the name of the file. am_mf=`AS_ECHO(["$am_mf"]) | sed -e 's/:.*$//'` # Check whether this is an Automake generated Makefile which includes # dependency-tracking related rules and includes. # Grep'ing the whole file directly is not great: AIX grep has a line # limit of 2048, but all sed's we know have understand at least 4000. sed -n 's,^am--depfiles:.*,X,p' "$am_mf" | grep X >/dev/null 2>&1 \ || continue am_dirpart=`AS_DIRNAME(["$am_mf"])` am_filepart=`AS_BASENAME(["$am_mf"])` AM_RUN_LOG([cd "$am_dirpart" \ && sed -e '/# am--include-marker/d' "$am_filepart" \ | $MAKE -f - am--depfiles]) || am_rc=$? done if test $am_rc -ne 0; then AC_MSG_FAILURE([Something went wrong bootstrapping makefile fragments for automatic dependency tracking. If GNU make was not used, consider re-running the configure script with MAKE="gmake" (or whatever is necessary). You can also try re-running configure with the '--disable-dependency-tracking' option to at least be able to build the package (albeit without support for automatic dependency tracking).]) fi AS_UNSET([am_dirpart]) AS_UNSET([am_filepart]) AS_UNSET([am_mf]) AS_UNSET([am_rc]) rm -f conftest-deps.mk } ])# _AM_OUTPUT_DEPENDENCY_COMMANDS # AM_OUTPUT_DEPENDENCY_COMMANDS # ----------------------------- # This macro should only be invoked once -- use via AC_REQUIRE. # # This code is only required when automatic dependency tracking is enabled. # This creates each '.Po' and '.Plo' makefile fragment that we'll need in # order to bootstrap the dependency handling code. AC_DEFUN([AM_OUTPUT_DEPENDENCY_COMMANDS], [AC_CONFIG_COMMANDS([depfiles], [test x"$AMDEP_TRUE" != x"" || _AM_OUTPUT_DEPENDENCY_COMMANDS], [AMDEP_TRUE="$AMDEP_TRUE" MAKE="${MAKE-make}"])]) # Do all the work for Automake. -*- Autoconf -*- # Copyright (C) 1996-2024 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # This macro actually does too much. Some checks are only needed if # your package does certain things. But this isn't really a big deal. dnl Redefine AC_PROG_CC to automatically invoke _AM_PROG_CC_C_O. m4_define([AC_PROG_CC], m4_defn([AC_PROG_CC]) [_AM_PROG_CC_C_O ]) # AM_INIT_AUTOMAKE(PACKAGE, VERSION, [NO-DEFINE]) # AM_INIT_AUTOMAKE([OPTIONS]) # ----------------------------------------------- # The call with PACKAGE and VERSION arguments is the old style # call (pre autoconf-2.50), which is being phased out. PACKAGE # and VERSION should now be passed to AC_INIT and removed from # the call to AM_INIT_AUTOMAKE. # We support both call styles for the transition. After # the next Automake release, Autoconf can make the AC_INIT # arguments mandatory, and then we can depend on a new Autoconf # release and drop the old call support. AC_DEFUN([AM_INIT_AUTOMAKE], [AC_PREREQ([2.65])dnl m4_ifdef([_$0_ALREADY_INIT], [m4_fatal([$0 expanded multiple times ]m4_defn([_$0_ALREADY_INIT]))], [m4_define([_$0_ALREADY_INIT], m4_expansion_stack)])dnl dnl Autoconf wants to disallow AM_ names. We explicitly allow dnl the ones we care about. m4_pattern_allow([^AM_[A-Z]+FLAGS$])dnl AC_REQUIRE([AM_SET_CURRENT_AUTOMAKE_VERSION])dnl AC_REQUIRE([AC_PROG_INSTALL])dnl if test "`cd $srcdir && pwd`" != "`pwd`"; then # Use -I$(srcdir) only when $(srcdir) != ., so that make's output # is not polluted with repeated "-I." AC_SUBST([am__isrc], [' -I$(srcdir)'])_AM_SUBST_NOTMAKE([am__isrc])dnl # test to see if srcdir already configured if test -f $srcdir/config.status; then AC_MSG_ERROR([source directory already configured; run "make distclean" there first]) fi fi # test whether we have cygpath if test -z "$CYGPATH_W"; then if (cygpath --version) >/dev/null 2>/dev/null; then CYGPATH_W='cygpath -w' else CYGPATH_W=echo fi fi AC_SUBST([CYGPATH_W]) # Define the identity of the package. dnl Distinguish between old-style and new-style calls. m4_ifval([$2], [AC_DIAGNOSE([obsolete], [$0: two- and three-arguments forms are deprecated.]) m4_ifval([$3], [_AM_SET_OPTION([no-define])])dnl AC_SUBST([PACKAGE], [$1])dnl AC_SUBST([VERSION], [$2])], [_AM_SET_OPTIONS([$1])dnl dnl Diagnose old-style AC_INIT with new-style AM_AUTOMAKE_INIT. m4_if( m4_ifset([AC_PACKAGE_NAME], [ok]):m4_ifset([AC_PACKAGE_VERSION], [ok]), [ok:ok],, [m4_fatal([AC_INIT should be called with package and version arguments])])dnl AC_SUBST([PACKAGE], ['AC_PACKAGE_TARNAME'])dnl AC_SUBST([VERSION], ['AC_PACKAGE_VERSION'])])dnl _AM_IF_OPTION([no-define],, [AC_DEFINE_UNQUOTED([PACKAGE], ["$PACKAGE"], [Name of package]) AC_DEFINE_UNQUOTED([VERSION], ["$VERSION"], [Version number of package])])dnl # Some tools Automake needs. AC_REQUIRE([AM_SANITY_CHECK])dnl AC_REQUIRE([AC_ARG_PROGRAM])dnl AM_MISSING_PROG([ACLOCAL], [aclocal-${am__api_version}]) AM_MISSING_PROG([AUTOCONF], [autoconf]) AM_MISSING_PROG([AUTOMAKE], [automake-${am__api_version}]) AM_MISSING_PROG([AUTOHEADER], [autoheader]) AM_MISSING_PROG([MAKEINFO], [makeinfo]) AC_REQUIRE([AM_PROG_INSTALL_SH])dnl AC_REQUIRE([AM_PROG_INSTALL_STRIP])dnl AC_REQUIRE([AC_PROG_MKDIR_P])dnl # For better backward compatibility. To be removed once Automake 1.9.x # dies out for good. For more background, see: # # AC_SUBST([mkdir_p], ['$(MKDIR_P)']) # We need awk for the "check" target (and possibly the TAP driver). The # system "awk" is bad on some platforms. AC_REQUIRE([AC_PROG_AWK])dnl AC_REQUIRE([AC_PROG_MAKE_SET])dnl AC_REQUIRE([AM_SET_LEADING_DOT])dnl _AM_IF_OPTION([tar-ustar], [_AM_PROG_TAR([ustar])], [_AM_IF_OPTION([tar-pax], [_AM_PROG_TAR([pax])], [_AM_PROG_TAR([v7])])]) _AM_IF_OPTION([no-dependencies],, [AC_PROVIDE_IFELSE([AC_PROG_CC], [_AM_DEPENDENCIES([CC])], [m4_define([AC_PROG_CC], m4_defn([AC_PROG_CC])[_AM_DEPENDENCIES([CC])])])dnl AC_PROVIDE_IFELSE([AC_PROG_CXX], [_AM_DEPENDENCIES([CXX])], [m4_define([AC_PROG_CXX], m4_defn([AC_PROG_CXX])[_AM_DEPENDENCIES([CXX])])])dnl AC_PROVIDE_IFELSE([AC_PROG_OBJC], [_AM_DEPENDENCIES([OBJC])], [m4_define([AC_PROG_OBJC], m4_defn([AC_PROG_OBJC])[_AM_DEPENDENCIES([OBJC])])])dnl AC_PROVIDE_IFELSE([AC_PROG_OBJCXX], [_AM_DEPENDENCIES([OBJCXX])], [m4_define([AC_PROG_OBJCXX], m4_defn([AC_PROG_OBJCXX])[_AM_DEPENDENCIES([OBJCXX])])])dnl ]) # Variables for tags utilities; see am/tags.am if test -z "$CTAGS"; then CTAGS=ctags fi AC_SUBST([CTAGS]) if test -z "$ETAGS"; then ETAGS=etags fi AC_SUBST([ETAGS]) if test -z "$CSCOPE"; then CSCOPE=cscope fi AC_SUBST([CSCOPE]) AC_REQUIRE([_AM_SILENT_RULES])dnl dnl The testsuite driver may need to know about EXEEXT, so add the dnl 'am__EXEEXT' conditional if _AM_COMPILER_EXEEXT was seen. This dnl macro is hooked onto _AC_COMPILER_EXEEXT early, see below. AC_CONFIG_COMMANDS_PRE(dnl [m4_provide_if([_AM_COMPILER_EXEEXT], [AM_CONDITIONAL([am__EXEEXT], [test -n "$EXEEXT"])])])dnl AC_REQUIRE([_AM_PROG_RM_F]) AC_REQUIRE([_AM_PROG_XARGS_N]) dnl The trailing newline in this macro's definition is deliberate, for dnl backward compatibility and to allow trailing 'dnl'-style comments dnl after the AM_INIT_AUTOMAKE invocation. See automake bug#16841. ]) dnl Hook into '_AC_COMPILER_EXEEXT' early to learn its expansion. Do not dnl add the conditional right here, as _AC_COMPILER_EXEEXT may be further dnl mangled by Autoconf and run in a shell conditional statement. m4_define([_AC_COMPILER_EXEEXT], m4_defn([_AC_COMPILER_EXEEXT])[m4_provide([_AM_COMPILER_EXEEXT])]) # When config.status generates a header, we must update the stamp-h file. # This file resides in the same directory as the config header # that is generated. The stamp files are numbered to have different names. # Autoconf calls _AC_AM_CONFIG_HEADER_HOOK (when defined) in the # loop where config.status creates the headers, so we can generate # our stamp files there. AC_DEFUN([_AC_AM_CONFIG_HEADER_HOOK], [# Compute $1's index in $config_headers. _am_arg=$1 _am_stamp_count=1 for _am_header in $config_headers :; do case $_am_header in $_am_arg | $_am_arg:* ) break ;; * ) _am_stamp_count=`expr $_am_stamp_count + 1` ;; esac done echo "timestamp for $_am_arg" >`AS_DIRNAME(["$_am_arg"])`/stamp-h[]$_am_stamp_count]) # Copyright (C) 2001-2024 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # AM_PROG_INSTALL_SH # ------------------ # Define $install_sh. AC_DEFUN([AM_PROG_INSTALL_SH], [AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl if test x"${install_sh+set}" != xset; then case $am_aux_dir in *\ * | *\ *) install_sh="\${SHELL} '$am_aux_dir/install-sh'" ;; *) install_sh="\${SHELL} $am_aux_dir/install-sh" esac fi AC_SUBST([install_sh])]) # Copyright (C) 2003-2024 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # Check whether the underlying file-system supports filenames # with a leading dot. For instance MS-DOS doesn't. AC_DEFUN([AM_SET_LEADING_DOT], [rm -rf .tst 2>/dev/null mkdir .tst 2>/dev/null if test -d .tst; then am__leading_dot=. else am__leading_dot=_ fi rmdir .tst 2>/dev/null AC_SUBST([am__leading_dot])]) # Add --enable-maintainer-mode option to configure. -*- Autoconf -*- # From Jim Meyering # Copyright (C) 1996-2024 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # AM_MAINTAINER_MODE([DEFAULT-MODE]) # ---------------------------------- # Control maintainer-specific portions of Makefiles. # Default is to disable them, unless 'enable' is passed literally. # For symmetry, 'disable' may be passed as well. Anyway, the user # can override the default with the --enable/--disable switch. AC_DEFUN([AM_MAINTAINER_MODE], [m4_case(m4_default([$1], [disable]), [enable], [m4_define([am_maintainer_other], [disable])], [disable], [m4_define([am_maintainer_other], [enable])], [m4_define([am_maintainer_other], [enable]) m4_warn([syntax], [unexpected argument to AM@&t@_MAINTAINER_MODE: $1])]) AC_MSG_CHECKING([whether to enable maintainer-specific portions of Makefiles]) dnl maintainer-mode's default is 'disable' unless 'enable' is passed AC_ARG_ENABLE([maintainer-mode], [AS_HELP_STRING([--]am_maintainer_other[-maintainer-mode], am_maintainer_other[ make rules and dependencies not useful (and sometimes confusing) to the casual installer])], [USE_MAINTAINER_MODE=$enableval], [USE_MAINTAINER_MODE=]m4_if(am_maintainer_other, [enable], [no], [yes])) AC_MSG_RESULT([$USE_MAINTAINER_MODE]) AM_CONDITIONAL([MAINTAINER_MODE], [test $USE_MAINTAINER_MODE = yes]) MAINT=$MAINTAINER_MODE_TRUE AC_SUBST([MAINT])dnl ] ) # Check to see how 'make' treats includes. -*- Autoconf -*- # Copyright (C) 2001-2024 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # AM_MAKE_INCLUDE() # ----------------- # Check whether make has an 'include' directive that can support all # the idioms we need for our automatic dependency tracking code. AC_DEFUN([AM_MAKE_INCLUDE], [AC_MSG_CHECKING([whether ${MAKE-make} supports the include directive]) cat > confinc.mk << 'END' am__doit: @echo this is the am__doit target >confinc.out .PHONY: am__doit END am__include="#" am__quote= # BSD make does it like this. echo '.include "confinc.mk" # ignored' > confmf.BSD # Other make implementations (GNU, Solaris 10, AIX) do it like this. echo 'include confinc.mk # ignored' > confmf.GNU _am_result=no for s in GNU BSD; do AM_RUN_LOG([${MAKE-make} -f confmf.$s && cat confinc.out]) AS_CASE([$?:`cat confinc.out 2>/dev/null`], ['0:this is the am__doit target'], [AS_CASE([$s], [BSD], [am__include='.include' am__quote='"'], [am__include='include' am__quote=''])]) if test "$am__include" != "#"; then _am_result="yes ($s style)" break fi done rm -f confinc.* confmf.* AC_MSG_RESULT([${_am_result}]) AC_SUBST([am__include])]) AC_SUBST([am__quote])]) # Fake the existence of programs that GNU maintainers use. -*- Autoconf -*- # Copyright (C) 1997-2024 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # AM_MISSING_PROG(NAME, PROGRAM) # ------------------------------ AC_DEFUN([AM_MISSING_PROG], [AC_REQUIRE([AM_MISSING_HAS_RUN]) $1=${$1-"${am_missing_run}$2"} AC_SUBST($1)]) # AM_MISSING_HAS_RUN # ------------------ # Define MISSING if not defined so far and test if it is modern enough. # If it is, set am_missing_run to use it, otherwise, to nothing. AC_DEFUN([AM_MISSING_HAS_RUN], [AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl AC_REQUIRE_AUX_FILE([missing])dnl if test x"${MISSING+set}" != xset; then MISSING="\${SHELL} '$am_aux_dir/missing'" fi # Use eval to expand $SHELL if eval "$MISSING --is-lightweight"; then am_missing_run="$MISSING " else am_missing_run= AC_MSG_WARN(['missing' script is too old or missing]) fi ]) # Helper functions for option handling. -*- Autoconf -*- # Copyright (C) 2001-2024 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # _AM_MANGLE_OPTION(NAME) # ----------------------- AC_DEFUN([_AM_MANGLE_OPTION], [[_AM_OPTION_]m4_bpatsubst($1, [[^a-zA-Z0-9_]], [_])]) # _AM_SET_OPTION(NAME) # -------------------- # Set option NAME. Presently that only means defining a flag for this option. AC_DEFUN([_AM_SET_OPTION], [m4_define(_AM_MANGLE_OPTION([$1]), [1])]) # _AM_SET_OPTIONS(OPTIONS) # ------------------------ # OPTIONS is a space-separated list of Automake options. AC_DEFUN([_AM_SET_OPTIONS], [m4_foreach_w([_AM_Option], [$1], [_AM_SET_OPTION(_AM_Option)])]) # _AM_IF_OPTION(OPTION, IF-SET, [IF-NOT-SET]) # ------------------------------------------- # Execute IF-SET if OPTION is set, IF-NOT-SET otherwise. AC_DEFUN([_AM_IF_OPTION], [m4_ifset(_AM_MANGLE_OPTION([$1]), [$2], [$3])]) # Copyright (C) 1999-2024 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # _AM_PROG_CC_C_O # --------------- # Like AC_PROG_CC_C_O, but changed for automake. We rewrite AC_PROG_CC # to automatically call this. AC_DEFUN([_AM_PROG_CC_C_O], [AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl AC_REQUIRE_AUX_FILE([compile])dnl AC_LANG_PUSH([C])dnl AC_CACHE_CHECK( [whether $CC understands -c and -o together], [am_cv_prog_cc_c_o], [AC_LANG_CONFTEST([AC_LANG_PROGRAM([])]) # Make sure it works both with $CC and with simple cc. # Following AC_PROG_CC_C_O, we do the test twice because some # compilers refuse to overwrite an existing .o file with -o, # though they will create one. am_cv_prog_cc_c_o=yes for am_i in 1 2; do if AM_RUN_LOG([$CC -c conftest.$ac_ext -o conftest2.$ac_objext]) \ && test -f conftest2.$ac_objext; then : OK else am_cv_prog_cc_c_o=no break fi done rm -f core conftest* unset am_i]) if test "$am_cv_prog_cc_c_o" != yes; then # Losing compiler, so override with the script. # FIXME: It is wrong to rewrite CC. # But if we don't then we get into trouble of one sort or another. # A longer-term fix would be to have automake use am__CC in this case, # and then we could set am__CC="\$(top_srcdir)/compile \$(CC)" CC="$am_aux_dir/compile $CC" fi AC_LANG_POP([C])]) # For backward compatibility. AC_DEFUN_ONCE([AM_PROG_CC_C_O], [AC_REQUIRE([AC_PROG_CC])]) # Copyright (C) 2022-2024 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # _AM_PROG_RM_F # --------------- # Check whether 'rm -f' without any arguments works. # https://bugs.gnu.org/10828 AC_DEFUN([_AM_PROG_RM_F], [am__rm_f_notfound= AS_IF([(rm -f && rm -fr && rm -rf) 2>/dev/null], [], [am__rm_f_notfound='""']) AC_SUBST(am__rm_f_notfound) ]) # Copyright (C) 2001-2024 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # AM_RUN_LOG(COMMAND) # ------------------- # Run COMMAND, save the exit status in ac_status, and log it. # (This has been adapted from Autoconf's _AC_RUN_LOG macro.) AC_DEFUN([AM_RUN_LOG], [{ echo "$as_me:$LINENO: $1" >&AS_MESSAGE_LOG_FD ($1) >&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD ac_status=$? echo "$as_me:$LINENO: \$? = $ac_status" >&AS_MESSAGE_LOG_FD (exit $ac_status); }]) # Check to make sure that the build environment is sane. -*- Autoconf -*- # Copyright (C) 1996-2024 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # _AM_SLEEP_FRACTIONAL_SECONDS # ---------------------------- AC_DEFUN([_AM_SLEEP_FRACTIONAL_SECONDS], [dnl AC_CACHE_CHECK([whether sleep supports fractional seconds], am_cv_sleep_fractional_seconds, [dnl AS_IF([sleep 0.001 2>/dev/null], [am_cv_sleep_fractional_seconds=yes], [am_cv_sleep_fractional_seconds=no]) ])]) # _AM_FILESYSTEM_TIMESTAMP_RESOLUTION # ----------------------------------- # Determine the filesystem's resolution for file modification # timestamps. The coarsest we know of is FAT, with a resolution # of only two seconds, even with the most recent "exFAT" extensions. # The finest (e.g. ext4 with large inodes, XFS, ZFS) is one # nanosecond, matching clock_gettime. However, it is probably not # possible to delay execution of a shell script for less than one # millisecond, due to process creation overhead and scheduling # granularity, so we don't check for anything finer than that. (See below.) AC_DEFUN([_AM_FILESYSTEM_TIMESTAMP_RESOLUTION], [dnl AC_REQUIRE([_AM_SLEEP_FRACTIONAL_SECONDS]) AC_CACHE_CHECK([filesystem timestamp resolution], am_cv_filesystem_timestamp_resolution, [dnl # Default to the worst case. am_cv_filesystem_timestamp_resolution=2 # Only try to go finer than 1 sec if sleep can do it. # Don't try 1 sec, because if 0.01 sec and 0.1 sec don't work, # - 1 sec is not much of a win compared to 2 sec, and # - it takes 2 seconds to perform the test whether 1 sec works. # # Instead, just use the default 2s on platforms that have 1s resolution, # accept the extra 1s delay when using $sleep in the Automake tests, in # exchange for not incurring the 2s delay for running the test for all # packages. # am_try_resolutions= if test "$am_cv_sleep_fractional_seconds" = yes; then # Even a millisecond often causes a bunch of false positives, # so just try a hundredth of a second. The time saved between .001 and # .01 is not terribly consequential. am_try_resolutions="0.01 0.1 $am_try_resolutions" fi # In order to catch current-generation FAT out, we must *modify* files # that already exist; the *creation* timestamp is finer. Use names # that make ls -t sort them differently when they have equal # timestamps than when they have distinct timestamps, keeping # in mind that ls -t prints the *newest* file first. rm -f conftest.ts? : > conftest.ts1 : > conftest.ts2 : > conftest.ts3 # Make sure ls -t actually works. Do 'set' in a subshell so we don't # clobber the current shell's arguments. (Outer-level square brackets # are removed by m4; they're present so that m4 does not expand # ; be careful, easy to get confused.) if ( set X `[ls -t conftest.ts[12]]` && { test "$[]*" != "X conftest.ts1 conftest.ts2" || test "$[]*" != "X conftest.ts2 conftest.ts1"; } ); then :; else # If neither matched, then we have a broken ls. This can happen # if, for instance, CONFIG_SHELL is bash and it inherits a # broken ls alias from the environment. This has actually # happened. Such a system could not be considered "sane". _AS_ECHO_UNQUOTED( ["Bad output from ls -t: \"`[ls -t conftest.ts[12]]`\""], [AS_MESSAGE_LOG_FD]) AC_MSG_FAILURE([ls -t produces unexpected output. Make sure there is not a broken ls alias in your environment.]) fi for am_try_res in $am_try_resolutions; do # Any one fine-grained sleep might happen to cross the boundary # between two values of a coarser actual resolution, but if we do # two fine-grained sleeps in a row, at least one of them will fall # entirely within a coarse interval. echo alpha > conftest.ts1 sleep $am_try_res echo beta > conftest.ts2 sleep $am_try_res echo gamma > conftest.ts3 # We assume that 'ls -t' will make use of high-resolution # timestamps if the operating system supports them at all. if (set X `ls -t conftest.ts?` && test "$[]2" = conftest.ts3 && test "$[]3" = conftest.ts2 && test "$[]4" = conftest.ts1); then # # Ok, ls -t worked. If we're at a resolution of 1 second, we're done, # because we don't need to test make. make_ok=true if test $am_try_res != 1; then # But if we've succeeded so far with a subsecond resolution, we # have one more thing to check: make. It can happen that # everything else supports the subsecond mtimes, but make doesn't; # notably on macOS, which ships make 3.81 from 2006 (the last one # released under GPLv2). https://bugs.gnu.org/68808 # # We test $MAKE if it is defined in the environment, else "make". # It might get overridden later, but our hope is that in practice # it does not matter: it is the system "make" which is (by far) # the most likely to be broken, whereas if the user overrides it, # probably they did so with a better, or at least not worse, make. # https://lists.gnu.org/archive/html/automake/2024-06/msg00051.html # # Create a Makefile (real tab character here): rm -f conftest.mk echo 'conftest.ts1: conftest.ts2' >conftest.mk echo ' touch conftest.ts2' >>conftest.mk # # Now, running # touch conftest.ts1; touch conftest.ts2; make # should touch ts1 because ts2 is newer. This could happen by luck, # but most often, it will fail if make's support is insufficient. So # test for several consecutive successes. # # (We reuse conftest.ts[12] because we still want to modify existing # files, not create new ones, per above.) n=0 make=${MAKE-make} until test $n -eq 3; do echo one > conftest.ts1 sleep $am_try_res echo two > conftest.ts2 # ts2 should now be newer than ts1 if $make -f conftest.mk | grep 'up to date' >/dev/null; then make_ok=false break # out of $n loop fi n=`expr $n + 1` done fi # if $make_ok; then # Everything we know to check worked out, so call this resolution good. am_cv_filesystem_timestamp_resolution=$am_try_res break # out of $am_try_res loop fi # Otherwise, we'll go on to check the next resolution. fi done rm -f conftest.ts? # (end _am_filesystem_timestamp_resolution) ])]) # AM_SANITY_CHECK # --------------- AC_DEFUN([AM_SANITY_CHECK], [AC_REQUIRE([_AM_FILESYSTEM_TIMESTAMP_RESOLUTION]) # This check should not be cached, as it may vary across builds of # different projects. AC_MSG_CHECKING([whether build environment is sane]) # Reject unsafe characters in $srcdir or the absolute working directory # name. Accept space and tab only in the latter. am_lf=' ' case `pwd` in *[[\\\"\#\$\&\'\`$am_lf]]*) AC_MSG_ERROR([unsafe absolute working directory name]);; esac case $srcdir in *[[\\\"\#\$\&\'\`$am_lf\ \ ]]*) AC_MSG_ERROR([unsafe srcdir value: '$srcdir']);; esac # Do 'set' in a subshell so we don't clobber the current shell's # arguments. Must try -L first in case configure is actually a # symlink; some systems play weird games with the mod time of symlinks # (eg FreeBSD returns the mod time of the symlink's containing # directory). am_build_env_is_sane=no am_has_slept=no rm -f conftest.file for am_try in 1 2; do echo "timestamp, slept: $am_has_slept" > conftest.file if ( set X `ls -Lt "$srcdir/configure" conftest.file 2> /dev/null` if test "$[]*" = "X"; then # -L didn't work. set X `ls -t "$srcdir/configure" conftest.file` fi test "$[]2" = conftest.file ); then am_build_env_is_sane=yes break fi # Just in case. sleep "$am_cv_filesystem_timestamp_resolution" am_has_slept=yes done AC_MSG_RESULT([$am_build_env_is_sane]) if test "$am_build_env_is_sane" = no; then AC_MSG_ERROR([newly created file is older than distributed files! Check your system clock]) fi # If we didn't sleep, we still need to ensure time stamps of config.status and # generated files are strictly newer. am_sleep_pid= AS_IF([test -e conftest.file || grep 'slept: no' conftest.file >/dev/null 2>&1],, [dnl ( sleep "$am_cv_filesystem_timestamp_resolution" ) & am_sleep_pid=$! ]) AC_CONFIG_COMMANDS_PRE( [AC_MSG_CHECKING([that generated files are newer than configure]) if test -n "$am_sleep_pid"; then # Hide warnings about reused PIDs. wait $am_sleep_pid 2>/dev/null fi AC_MSG_RESULT([done])]) rm -f conftest.file ]) # Copyright (C) 2009-2024 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # _AM_SILENT_RULES # ---------------- # Enable less verbose build rules support. AC_DEFUN([_AM_SILENT_RULES], [AM_DEFAULT_VERBOSITY=1 AC_ARG_ENABLE([silent-rules], [dnl AS_HELP_STRING( [--enable-silent-rules], [less verbose build output (undo: "make V=1")]) AS_HELP_STRING( [--disable-silent-rules], [verbose build output (undo: "make V=0")])dnl ]) dnl dnl A few 'make' implementations (e.g., NonStop OS and NextStep) dnl do not support nested variable expansions. dnl See automake bug#9928 and bug#10237. am_make=${MAKE-make} AC_CACHE_CHECK([whether $am_make supports nested variables], [am_cv_make_support_nested_variables], [if AS_ECHO([['TRUE=$(BAR$(V)) BAR0=false BAR1=true V=1 am__doit: @$(TRUE) .PHONY: am__doit']]) | $am_make -f - >/dev/null 2>&1; then am_cv_make_support_nested_variables=yes else am_cv_make_support_nested_variables=no fi]) AC_SUBST([AM_V])dnl AM_SUBST_NOTMAKE([AM_V])dnl AC_SUBST([AM_DEFAULT_V])dnl AM_SUBST_NOTMAKE([AM_DEFAULT_V])dnl AC_SUBST([AM_DEFAULT_VERBOSITY])dnl AM_BACKSLASH='\' AC_SUBST([AM_BACKSLASH])dnl _AM_SUBST_NOTMAKE([AM_BACKSLASH])dnl dnl Delay evaluation of AM_DEFAULT_VERBOSITY to the end to allow multiple calls dnl to AM_SILENT_RULES to change the default value. AC_CONFIG_COMMANDS_PRE([dnl case $enable_silent_rules in @%:@ ((( yes) AM_DEFAULT_VERBOSITY=0;; no) AM_DEFAULT_VERBOSITY=1;; esac if test $am_cv_make_support_nested_variables = yes; then dnl Using '$V' instead of '$(V)' breaks IRIX make. AM_V='$(V)' AM_DEFAULT_V='$(AM_DEFAULT_VERBOSITY)' else AM_V=$AM_DEFAULT_VERBOSITY AM_DEFAULT_V=$AM_DEFAULT_VERBOSITY fi ])dnl ]) # AM_SILENT_RULES([DEFAULT]) # -------------------------- # Set the default verbosity level to DEFAULT ("yes" being less verbose, "no" or # empty being verbose). AC_DEFUN([AM_SILENT_RULES], [AC_REQUIRE([_AM_SILENT_RULES]) AM_DEFAULT_VERBOSITY=m4_if([$1], [yes], [0], [1])]) # Copyright (C) 2001-2024 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # AM_PROG_INSTALL_STRIP # --------------------- # One issue with vendor 'install' (even GNU) is that you can't # specify the program used to strip binaries. This is especially # annoying in cross-compiling environments, where the build's strip # is unlikely to handle the host's binaries. # Fortunately install-sh will honor a STRIPPROG variable, so we # always use install-sh in "make install-strip", and initialize # STRIPPROG with the value of the STRIP variable (set by the user). AC_DEFUN([AM_PROG_INSTALL_STRIP], [AC_REQUIRE([AM_PROG_INSTALL_SH])dnl # Installed binaries are usually stripped using 'strip' when the user # run "make install-strip". However 'strip' might not be the right # tool to use in cross-compilation environments, therefore Automake # will honor the 'STRIP' environment variable to overrule this program. dnl Don't test for $cross_compiling = yes, because it might be 'maybe'. if test "$cross_compiling" != no; then AC_CHECK_TOOL([STRIP], [strip], :) fi INSTALL_STRIP_PROGRAM="\$(install_sh) -c -s" AC_SUBST([INSTALL_STRIP_PROGRAM])]) # Copyright (C) 2006-2024 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # _AM_SUBST_NOTMAKE(VARIABLE) # --------------------------- # Prevent Automake from outputting VARIABLE = @VARIABLE@ in Makefile.in. # This macro is traced by Automake. AC_DEFUN([_AM_SUBST_NOTMAKE]) # AM_SUBST_NOTMAKE(VARIABLE) # -------------------------- # Public sister of _AM_SUBST_NOTMAKE. AC_DEFUN([AM_SUBST_NOTMAKE], [_AM_SUBST_NOTMAKE($@)]) # Check how to create a tarball. -*- Autoconf -*- # Copyright (C) 2004-2024 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # _AM_PROG_TAR(FORMAT) # -------------------- # Check how to create a tarball in format FORMAT. # FORMAT should be one of 'v7', 'ustar', or 'pax'. # # Substitute a variable $(am__tar) that is a command # writing to stdout a FORMAT-tarball containing the directory # $tardir. # tardir=directory && $(am__tar) > result.tar # # Substitute a variable $(am__untar) that extract such # a tarball read from stdin. # $(am__untar) < result.tar # AC_DEFUN([_AM_PROG_TAR], [# Always define AMTAR for backward compatibility. Yes, it's still used # in the wild :-( We should find a proper way to deprecate it ... AC_SUBST([AMTAR], ['$${TAR-tar}']) # We'll loop over all known methods to create a tar archive until one works. _am_tools='gnutar m4_if([$1], [ustar], [plaintar]) pax cpio none' m4_if([$1], [v7], [am__tar='$${TAR-tar} chof - "$$tardir"' am__untar='$${TAR-tar} xf -'], [m4_case([$1], [ustar], [# The POSIX 1988 'ustar' format is defined with fixed-size fields. # There is notably a 21 bits limit for the UID and the GID. In fact, # the 'pax' utility can hang on bigger UID/GID (see automake bug#8343 # and bug#13588). am_max_uid=2097151 # 2^21 - 1 am_max_gid=$am_max_uid # The $UID and $GID variables are not portable, so we need to resort # to the POSIX-mandated id(1) utility. Errors in the 'id' calls # below are definitely unexpected, so allow the users to see them # (that is, avoid stderr redirection). am_uid=`id -u || echo unknown` am_gid=`id -g || echo unknown` AC_MSG_CHECKING([whether UID '$am_uid' is supported by ustar format]) if test x$am_uid = xunknown; then AC_MSG_WARN([ancient id detected; assuming current UID is ok, but dist-ustar might not work]) elif test $am_uid -le $am_max_uid; then AC_MSG_RESULT([yes]) else AC_MSG_RESULT([no]) _am_tools=none fi AC_MSG_CHECKING([whether GID '$am_gid' is supported by ustar format]) if test x$gm_gid = xunknown; then AC_MSG_WARN([ancient id detected; assuming current GID is ok, but dist-ustar might not work]) elif test $am_gid -le $am_max_gid; then AC_MSG_RESULT([yes]) else AC_MSG_RESULT([no]) _am_tools=none fi], [pax], [], [m4_fatal([Unknown tar format])]) AC_MSG_CHECKING([how to create a $1 tar archive]) # Go ahead even if we have the value already cached. We do so because we # need to set the values for the 'am__tar' and 'am__untar' variables. _am_tools=${am_cv_prog_tar_$1-$_am_tools} for _am_tool in $_am_tools; do case $_am_tool in gnutar) for _am_tar in tar gnutar gtar; do AM_RUN_LOG([$_am_tar --version]) && break done am__tar="$_am_tar --format=m4_if([$1], [pax], [posix], [$1]) -chf - "'"$$tardir"' am__tar_="$_am_tar --format=m4_if([$1], [pax], [posix], [$1]) -chf - "'"$tardir"' am__untar="$_am_tar -xf -" ;; plaintar) # Must skip GNU tar: if it does not support --format= it doesn't create # ustar tarball either. (tar --version) >/dev/null 2>&1 && continue am__tar='tar chf - "$$tardir"' am__tar_='tar chf - "$tardir"' am__untar='tar xf -' ;; pax) am__tar='pax -L -x $1 -w "$$tardir"' am__tar_='pax -L -x $1 -w "$tardir"' am__untar='pax -r' ;; cpio) am__tar='find "$$tardir" -print | cpio -o -H $1 -L' am__tar_='find "$tardir" -print | cpio -o -H $1 -L' am__untar='cpio -i -H $1 -d' ;; none) am__tar=false am__tar_=false am__untar=false ;; esac # If the value was cached, stop now. We just wanted to have am__tar # and am__untar set. test -n "${am_cv_prog_tar_$1}" && break # tar/untar a dummy directory, and stop if the command works. rm -rf conftest.dir mkdir conftest.dir echo GrepMe > conftest.dir/file AM_RUN_LOG([tardir=conftest.dir && eval $am__tar_ >conftest.tar]) rm -rf conftest.dir if test -s conftest.tar; then AM_RUN_LOG([$am__untar /dev/null 2>&1 && break fi done rm -rf conftest.dir AC_CACHE_VAL([am_cv_prog_tar_$1], [am_cv_prog_tar_$1=$_am_tool]) AC_MSG_RESULT([$am_cv_prog_tar_$1])]) AC_SUBST([am__tar]) AC_SUBST([am__untar]) ]) # _AM_PROG_TAR # Copyright (C) 2022-2024 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # _AM_PROG_XARGS_N # ---------------- # Check whether 'xargs -n' works. It should work everywhere, so the fallback # is not optimized at all as we never expect to use it. AC_DEFUN([_AM_PROG_XARGS_N], [AC_CACHE_CHECK([xargs -n works], am_cv_xargs_n_works, [dnl AS_IF([test "`echo 1 2 3 | xargs -n2 echo`" = "1 2 3"], [am_cv_xargs_n_works=yes], [am_cv_xargs_n_works=no])]) AS_IF([test "$am_cv_xargs_n_works" = yes], [am__xargs_n='xargs -n'], [dnl am__xargs_n='am__xargs_n () { shift; sed "s/ /\\n/g" | while read am__xargs_n_arg; do "$@" "$am__xargs_n_arg"; done; }' ])dnl AC_SUBST(am__xargs_n) ]) m4_include([m4/libtool.m4]) m4_include([m4/ltoptions.m4]) m4_include([m4/ltsugar.m4]) m4_include([m4/ltversion.m4]) m4_include([m4/lt~obsolete.m4]) ntfs-3g-2026.2.25/m4/0000775000175000017500000000000015152260234007376 5ntfs-3g-2026.2.25/m4/ltoptions.m40000644000175000017500000003612115152260210011606 # Helper functions for option handling. -*- Autoconf -*- # # Copyright (C) 2004-2005, 2007-2009, 2011-2019, 2021-2024 Free # Software Foundation, Inc. # Written by Gary V. Vaughan, 2004 # # This file is free software; the Free Software Foundation gives # unlimited permission to copy and/or distribute it, with or without # modifications, as long as this notice is preserved. # serial 10 ltoptions.m4 # This is to help aclocal find these macros, as it can't see m4_define. AC_DEFUN([LTOPTIONS_VERSION], [m4_if([1])]) # _LT_MANGLE_OPTION(MACRO-NAME, OPTION-NAME) # ------------------------------------------ m4_define([_LT_MANGLE_OPTION], [[_LT_OPTION_]m4_bpatsubst($1__$2, [[^a-zA-Z0-9_]], [_])]) # _LT_SET_OPTION(MACRO-NAME, OPTION-NAME) # --------------------------------------- # Set option OPTION-NAME for macro MACRO-NAME, and if there is a # matching handler defined, dispatch to it. Other OPTION-NAMEs are # saved as a flag. m4_define([_LT_SET_OPTION], [m4_define(_LT_MANGLE_OPTION([$1], [$2]))dnl m4_ifdef(_LT_MANGLE_DEFUN([$1], [$2]), _LT_MANGLE_DEFUN([$1], [$2]), [m4_warning([Unknown $1 option '$2'])])[]dnl ]) # _LT_IF_OPTION(MACRO-NAME, OPTION-NAME, IF-SET, [IF-NOT-SET]) # ------------------------------------------------------------ # Execute IF-SET if OPTION is set, IF-NOT-SET otherwise. m4_define([_LT_IF_OPTION], [m4_ifdef(_LT_MANGLE_OPTION([$1], [$2]), [$3], [$4])]) # _LT_UNLESS_OPTIONS(MACRO-NAME, OPTION-LIST, IF-NOT-SET) # ------------------------------------------------------- # Execute IF-NOT-SET unless all options in OPTION-LIST for MACRO-NAME # are set. m4_define([_LT_UNLESS_OPTIONS], [m4_foreach([_LT_Option], m4_split(m4_normalize([$2])), [m4_ifdef(_LT_MANGLE_OPTION([$1], _LT_Option), [m4_define([$0_found])])])[]dnl m4_ifdef([$0_found], [m4_undefine([$0_found])], [$3 ])[]dnl ]) # _LT_SET_OPTIONS(MACRO-NAME, OPTION-LIST) # ---------------------------------------- # OPTION-LIST is a space-separated list of Libtool options associated # with MACRO-NAME. If any OPTION has a matching handler declared with # LT_OPTION_DEFINE, dispatch to that macro; otherwise complain about # the unknown option and exit. m4_defun([_LT_SET_OPTIONS], [# Set options m4_foreach([_LT_Option], m4_split(m4_normalize([$2])), [_LT_SET_OPTION([$1], _LT_Option)]) m4_if([$1],[LT_INIT],[ dnl dnl Simply set some default values (i.e off) if boolean options were not dnl specified: _LT_UNLESS_OPTIONS([LT_INIT], [dlopen], [enable_dlopen=no ]) _LT_UNLESS_OPTIONS([LT_INIT], [win32-dll], [enable_win32_dll=no ]) dnl dnl If no reference was made to various pairs of opposing options, then dnl we run the default mode handler for the pair. For example, if neither dnl 'shared' nor 'disable-shared' was passed, we enable building of shared dnl archives by default: _LT_UNLESS_OPTIONS([LT_INIT], [shared disable-shared], [_LT_ENABLE_SHARED]) _LT_UNLESS_OPTIONS([LT_INIT], [static disable-static], [_LT_ENABLE_STATIC]) _LT_UNLESS_OPTIONS([LT_INIT], [pic-only no-pic], [_LT_WITH_PIC]) _LT_UNLESS_OPTIONS([LT_INIT], [fast-install disable-fast-install], [_LT_ENABLE_FAST_INSTALL]) _LT_UNLESS_OPTIONS([LT_INIT], [aix-soname=aix aix-soname=both aix-soname=svr4], [_LT_WITH_AIX_SONAME([aix])]) ]) ])# _LT_SET_OPTIONS ## --------------------------------- ## ## Macros to handle LT_INIT options. ## ## --------------------------------- ## # _LT_MANGLE_DEFUN(MACRO-NAME, OPTION-NAME) # ----------------------------------------- m4_define([_LT_MANGLE_DEFUN], [[_LT_OPTION_DEFUN_]m4_bpatsubst(m4_toupper([$1__$2]), [[^A-Z0-9_]], [_])]) # LT_OPTION_DEFINE(MACRO-NAME, OPTION-NAME, CODE) # ----------------------------------------------- m4_define([LT_OPTION_DEFINE], [m4_define(_LT_MANGLE_DEFUN([$1], [$2]), [$3])[]dnl ])# LT_OPTION_DEFINE # dlopen # ------ LT_OPTION_DEFINE([LT_INIT], [dlopen], [enable_dlopen=yes ]) AU_DEFUN([AC_LIBTOOL_DLOPEN], [_LT_SET_OPTION([LT_INIT], [dlopen]) AC_DIAGNOSE([obsolete], [$0: Remove this warning and the call to _LT_SET_OPTION when you put the 'dlopen' option into LT_INIT's first parameter.]) ]) dnl aclocal-1.4 backwards compatibility: dnl AC_DEFUN([AC_LIBTOOL_DLOPEN], []) # win32-dll # --------- # Declare package support for building win32 dll's. LT_OPTION_DEFINE([LT_INIT], [win32-dll], [enable_win32_dll=yes case $host in *-*-cygwin* | *-*-mingw* | *-*-windows* | *-*-pw32* | *-*-cegcc*) AC_CHECK_TOOL(AS, as, false) AC_CHECK_TOOL(DLLTOOL, dlltool, false) AC_CHECK_TOOL(OBJDUMP, objdump, false) ;; esac test -z "$AS" && AS=as _LT_DECL([], [AS], [1], [Assembler program])dnl test -z "$DLLTOOL" && DLLTOOL=dlltool _LT_DECL([], [DLLTOOL], [1], [DLL creation program])dnl test -z "$OBJDUMP" && OBJDUMP=objdump _LT_DECL([], [OBJDUMP], [1], [Object dumper program])dnl ])# win32-dll AU_DEFUN([AC_LIBTOOL_WIN32_DLL], [AC_REQUIRE([AC_CANONICAL_HOST])dnl _LT_SET_OPTION([LT_INIT], [win32-dll]) AC_DIAGNOSE([obsolete], [$0: Remove this warning and the call to _LT_SET_OPTION when you put the 'win32-dll' option into LT_INIT's first parameter.]) ]) dnl aclocal-1.4 backwards compatibility: dnl AC_DEFUN([AC_LIBTOOL_WIN32_DLL], []) # _LT_ENABLE_SHARED([DEFAULT]) # ---------------------------- # implement the --enable-shared flag, and supports the 'shared' and # 'disable-shared' LT_INIT options. # DEFAULT is either 'yes' or 'no'. If omitted, it defaults to 'yes'. m4_define([_LT_ENABLE_SHARED], [m4_define([_LT_ENABLE_SHARED_DEFAULT], [m4_if($1, no, no, yes)])dnl AC_ARG_ENABLE([shared], [AS_HELP_STRING([--enable-shared@<:@=PKGS@:>@], [build shared libraries @<:@default=]_LT_ENABLE_SHARED_DEFAULT[@:>@])], [p=${PACKAGE-default} case $enableval in yes) enable_shared=yes ;; no) enable_shared=no ;; *) enable_shared=no # Look at the argument we got. We use all the common list separators. lt_save_ifs=$IFS; IFS=$IFS$PATH_SEPARATOR, for pkg in $enableval; do IFS=$lt_save_ifs if test "X$pkg" = "X$p"; then enable_shared=yes fi done IFS=$lt_save_ifs ;; esac], [enable_shared=]_LT_ENABLE_SHARED_DEFAULT) _LT_DECL([build_libtool_libs], [enable_shared], [0], [Whether or not to build shared libraries]) ])# _LT_ENABLE_SHARED LT_OPTION_DEFINE([LT_INIT], [shared], [_LT_ENABLE_SHARED([yes])]) LT_OPTION_DEFINE([LT_INIT], [disable-shared], [_LT_ENABLE_SHARED([no])]) # Old names: AC_DEFUN([AC_ENABLE_SHARED], [_LT_SET_OPTION([LT_INIT], m4_if([$1], [no], [disable-])[shared]) ]) AC_DEFUN([AC_DISABLE_SHARED], [_LT_SET_OPTION([LT_INIT], [disable-shared]) ]) AU_DEFUN([AM_ENABLE_SHARED], [AC_ENABLE_SHARED($@)]) AU_DEFUN([AM_DISABLE_SHARED], [AC_DISABLE_SHARED($@)]) dnl aclocal-1.4 backwards compatibility: dnl AC_DEFUN([AM_ENABLE_SHARED], []) dnl AC_DEFUN([AM_DISABLE_SHARED], []) # _LT_ENABLE_STATIC([DEFAULT]) # ---------------------------- # implement the --enable-static flag, and support the 'static' and # 'disable-static' LT_INIT options. # DEFAULT is either 'yes' or 'no'. If omitted, it defaults to 'yes'. m4_define([_LT_ENABLE_STATIC], [m4_define([_LT_ENABLE_STATIC_DEFAULT], [m4_if($1, no, no, yes)])dnl AC_ARG_ENABLE([static], [AS_HELP_STRING([--enable-static@<:@=PKGS@:>@], [build static libraries @<:@default=]_LT_ENABLE_STATIC_DEFAULT[@:>@])], [p=${PACKAGE-default} case $enableval in yes) enable_static=yes ;; no) enable_static=no ;; *) enable_static=no # Look at the argument we got. We use all the common list separators. lt_save_ifs=$IFS; IFS=$IFS$PATH_SEPARATOR, for pkg in $enableval; do IFS=$lt_save_ifs if test "X$pkg" = "X$p"; then enable_static=yes fi done IFS=$lt_save_ifs ;; esac], [enable_static=]_LT_ENABLE_STATIC_DEFAULT) _LT_DECL([build_old_libs], [enable_static], [0], [Whether or not to build static libraries]) ])# _LT_ENABLE_STATIC LT_OPTION_DEFINE([LT_INIT], [static], [_LT_ENABLE_STATIC([yes])]) LT_OPTION_DEFINE([LT_INIT], [disable-static], [_LT_ENABLE_STATIC([no])]) # Old names: AC_DEFUN([AC_ENABLE_STATIC], [_LT_SET_OPTION([LT_INIT], m4_if([$1], [no], [disable-])[static]) ]) AC_DEFUN([AC_DISABLE_STATIC], [_LT_SET_OPTION([LT_INIT], [disable-static]) ]) AU_DEFUN([AM_ENABLE_STATIC], [AC_ENABLE_STATIC($@)]) AU_DEFUN([AM_DISABLE_STATIC], [AC_DISABLE_STATIC($@)]) dnl aclocal-1.4 backwards compatibility: dnl AC_DEFUN([AM_ENABLE_STATIC], []) dnl AC_DEFUN([AM_DISABLE_STATIC], []) # _LT_ENABLE_FAST_INSTALL([DEFAULT]) # ---------------------------------- # implement the --enable-fast-install flag, and support the 'fast-install' # and 'disable-fast-install' LT_INIT options. # DEFAULT is either 'yes' or 'no'. If omitted, it defaults to 'yes'. m4_define([_LT_ENABLE_FAST_INSTALL], [m4_define([_LT_ENABLE_FAST_INSTALL_DEFAULT], [m4_if($1, no, no, yes)])dnl AC_ARG_ENABLE([fast-install], [AS_HELP_STRING([--enable-fast-install@<:@=PKGS@:>@], [optimize for fast installation @<:@default=]_LT_ENABLE_FAST_INSTALL_DEFAULT[@:>@])], [p=${PACKAGE-default} case $enableval in yes) enable_fast_install=yes ;; no) enable_fast_install=no ;; *) enable_fast_install=no # Look at the argument we got. We use all the common list separators. lt_save_ifs=$IFS; IFS=$IFS$PATH_SEPARATOR, for pkg in $enableval; do IFS=$lt_save_ifs if test "X$pkg" = "X$p"; then enable_fast_install=yes fi done IFS=$lt_save_ifs ;; esac], [enable_fast_install=]_LT_ENABLE_FAST_INSTALL_DEFAULT) _LT_DECL([fast_install], [enable_fast_install], [0], [Whether or not to optimize for fast installation])dnl ])# _LT_ENABLE_FAST_INSTALL LT_OPTION_DEFINE([LT_INIT], [fast-install], [_LT_ENABLE_FAST_INSTALL([yes])]) LT_OPTION_DEFINE([LT_INIT], [disable-fast-install], [_LT_ENABLE_FAST_INSTALL([no])]) # Old names: AU_DEFUN([AC_ENABLE_FAST_INSTALL], [_LT_SET_OPTION([LT_INIT], m4_if([$1], [no], [disable-])[fast-install]) AC_DIAGNOSE([obsolete], [$0: Remove this warning and the call to _LT_SET_OPTION when you put the 'fast-install' option into LT_INIT's first parameter.]) ]) AU_DEFUN([AC_DISABLE_FAST_INSTALL], [_LT_SET_OPTION([LT_INIT], [disable-fast-install]) AC_DIAGNOSE([obsolete], [$0: Remove this warning and the call to _LT_SET_OPTION when you put the 'disable-fast-install' option into LT_INIT's first parameter.]) ]) dnl aclocal-1.4 backwards compatibility: dnl AC_DEFUN([AC_ENABLE_FAST_INSTALL], []) dnl AC_DEFUN([AM_DISABLE_FAST_INSTALL], []) # _LT_WITH_AIX_SONAME([DEFAULT]) # ---------------------------------- # implement the --enable-aix-soname configure option, and support the # `aix-soname=aix' and `aix-soname=both' and `aix-soname=svr4' LT_INIT options. # DEFAULT is either `aix', `both', or `svr4'. If omitted, it defaults to `aix'. m4_define([_LT_WITH_AIX_SONAME], [m4_define([_LT_WITH_AIX_SONAME_DEFAULT], [m4_if($1, svr4, svr4, m4_if($1, both, both, aix))])dnl shared_archive_member_spec= case $host,$enable_shared in power*-*-aix[[5-9]]*,yes) AC_MSG_CHECKING([which variant of shared library versioning to provide]) AC_ARG_ENABLE([aix-soname], [AS_HELP_STRING([--enable-aix-soname=aix|svr4|both], [shared library versioning (aka "SONAME") variant to provide on AIX, @<:@default=]_LT_WITH_AIX_SONAME_DEFAULT[@:>@.])], [case $enableval in aix|svr4|both) ;; *) AC_MSG_ERROR([Unknown argument to --enable-aix-soname]) ;; esac lt_cv_with_aix_soname=$enable_aix_soname], [_AC_ENABLE_IF([with], [aix-soname], [case $withval in aix|svr4|both) ;; *) AC_MSG_ERROR([Unknown argument to --with-aix-soname]) ;; esac lt_cv_with_aix_soname=$with_aix_soname], [AC_CACHE_VAL([lt_cv_with_aix_soname], [lt_cv_with_aix_soname=]_LT_WITH_AIX_SONAME_DEFAULT)]) enable_aix_soname=$lt_cv_with_aix_soname]) with_aix_soname=$enable_aix_soname AC_MSG_RESULT([$with_aix_soname]) if test aix != "$with_aix_soname"; then # For the AIX way of multilib, we name the shared archive member # based on the bitwidth used, traditionally 'shr.o' or 'shr_64.o', # and 'shr.imp' or 'shr_64.imp', respectively, for the Import File. # Even when GNU compilers ignore OBJECT_MODE but need '-maix64' flag, # the AIX toolchain works better with OBJECT_MODE set (default 32). if test 64 = "${OBJECT_MODE-32}"; then shared_archive_member_spec=shr_64 else shared_archive_member_spec=shr fi fi ;; *) with_aix_soname=aix ;; esac _LT_DECL([], [shared_archive_member_spec], [0], [Shared archive member basename, for filename based shared library versioning on AIX])dnl ])# _LT_WITH_AIX_SONAME LT_OPTION_DEFINE([LT_INIT], [aix-soname=aix], [_LT_WITH_AIX_SONAME([aix])]) LT_OPTION_DEFINE([LT_INIT], [aix-soname=both], [_LT_WITH_AIX_SONAME([both])]) LT_OPTION_DEFINE([LT_INIT], [aix-soname=svr4], [_LT_WITH_AIX_SONAME([svr4])]) # _LT_WITH_PIC([MODE]) # -------------------- # implement the --enable-pic flag, and support the 'pic-only' and 'no-pic' # LT_INIT options. # MODE is either 'yes' or 'no'. If omitted, it defaults to 'both'. m4_define([_LT_WITH_PIC], [AC_ARG_ENABLE([pic], [AS_HELP_STRING([--enable-pic@<:@=PKGS@:>@], [try to use only PIC/non-PIC objects @<:@default=use both@:>@])], [lt_p=${PACKAGE-default} case $enableval in yes|no) pic_mode=$enableval ;; *) pic_mode=default # Look at the argument we got. We use all the common list separators. lt_save_ifs=$IFS; IFS=$IFS$PATH_SEPARATOR, for lt_pkg in $enableval; do IFS=$lt_save_ifs if test "X$lt_pkg" = "X$lt_p"; then pic_mode=yes fi done IFS=$lt_save_ifs ;; esac], [dnl Continue to support --with-pic and --without-pic, for backward dnl compatibility. _AC_ENABLE_IF([with], [pic], [lt_p=${PACKAGE-default} case $withval in yes|no) pic_mode=$withval ;; *) pic_mode=default # Look at the argument we got. We use all the common list separators. lt_save_ifs=$IFS; IFS=$IFS$PATH_SEPARATOR, for lt_pkg in $withval; do IFS=$lt_save_ifs if test "X$lt_pkg" = "X$lt_p"; then pic_mode=yes fi done IFS=$lt_save_ifs ;; esac], [pic_mode=m4_default([$1], [default])])] ) _LT_DECL([], [pic_mode], [0], [What type of objects to build])dnl ])# _LT_WITH_PIC LT_OPTION_DEFINE([LT_INIT], [pic-only], [_LT_WITH_PIC([yes])]) LT_OPTION_DEFINE([LT_INIT], [no-pic], [_LT_WITH_PIC([no])]) # Old name: AU_DEFUN([AC_LIBTOOL_PICMODE], [_LT_SET_OPTION([LT_INIT], [pic-only]) AC_DIAGNOSE([obsolete], [$0: Remove this warning and the call to _LT_SET_OPTION when you put the 'pic-only' option into LT_INIT's first parameter.]) ]) dnl aclocal-1.4 backwards compatibility: dnl AC_DEFUN([AC_LIBTOOL_PICMODE], []) ## ----------------- ## ## LTDL_INIT Options ## ## ----------------- ## m4_define([_LTDL_MODE], []) LT_OPTION_DEFINE([LTDL_INIT], [nonrecursive], [m4_define([_LTDL_MODE], [nonrecursive])]) LT_OPTION_DEFINE([LTDL_INIT], [recursive], [m4_define([_LTDL_MODE], [recursive])]) LT_OPTION_DEFINE([LTDL_INIT], [subproject], [m4_define([_LTDL_MODE], [subproject])]) m4_define([_LTDL_TYPE], []) LT_OPTION_DEFINE([LTDL_INIT], [installable], [m4_define([_LTDL_TYPE], [installable])]) LT_OPTION_DEFINE([LTDL_INIT], [convenience], [m4_define([_LTDL_TYPE], [convenience])]) ntfs-3g-2026.2.25/m4/ltversion.m40000644000175000017500000000131215152260210011572 # ltversion.m4 -- version numbers -*- Autoconf -*- # # Copyright (C) 2004, 2011-2019, 2021-2024 Free Software Foundation, # Inc. # Written by Scott James Remnant, 2004 # # This file is free software; the Free Software Foundation gives # unlimited permission to copy and/or distribute it, with or without # modifications, as long as this notice is preserved. # @configure_input@ # serial 4441 ltversion.m4 # This file is part of GNU Libtool m4_define([LT_PACKAGE_VERSION], [2.5.4]) m4_define([LT_PACKAGE_REVISION], [2.5.4]) AC_DEFUN([LTVERSION_VERSION], [macro_version='2.5.4' macro_revision='2.5.4' _LT_DECL(, macro_version, 0, [Which release of libtool.m4 was used?]) _LT_DECL(, macro_revision, 0) ]) ntfs-3g-2026.2.25/m4/ltsugar.m40000644000175000017500000001045315152260210011234 # ltsugar.m4 -- libtool m4 base layer. -*-Autoconf-*- # # Copyright (C) 2004-2005, 2007-2008, 2011-2019, 2021-2024 Free Software # Foundation, Inc. # Written by Gary V. Vaughan, 2004 # # This file is free software; the Free Software Foundation gives # unlimited permission to copy and/or distribute it, with or without # modifications, as long as this notice is preserved. # serial 6 ltsugar.m4 # This is to help aclocal find these macros, as it can't see m4_define. AC_DEFUN([LTSUGAR_VERSION], [m4_if([0.1])]) # lt_join(SEP, ARG1, [ARG2...]) # ----------------------------- # Produce ARG1SEPARG2...SEPARGn, omitting [] arguments and their # associated separator. # Needed until we can rely on m4_join from Autoconf 2.62, since all earlier # versions in m4sugar had bugs. m4_define([lt_join], [m4_if([$#], [1], [], [$#], [2], [[$2]], [m4_if([$2], [], [], [[$2]_])$0([$1], m4_shift(m4_shift($@)))])]) m4_define([_lt_join], [m4_if([$#$2], [2], [], [m4_if([$2], [], [], [[$1$2]])$0([$1], m4_shift(m4_shift($@)))])]) # lt_car(LIST) # lt_cdr(LIST) # ------------ # Manipulate m4 lists. # These macros are necessary as long as will still need to support # Autoconf-2.59, which quotes differently. m4_define([lt_car], [[$1]]) m4_define([lt_cdr], [m4_if([$#], 0, [m4_fatal([$0: cannot be called without arguments])], [$#], 1, [], [m4_dquote(m4_shift($@))])]) m4_define([lt_unquote], $1) # lt_append(MACRO-NAME, STRING, [SEPARATOR]) # ------------------------------------------ # Redefine MACRO-NAME to hold its former content plus 'SEPARATOR''STRING'. # Note that neither SEPARATOR nor STRING are expanded; they are appended # to MACRO-NAME as is (leaving the expansion for when MACRO-NAME is invoked). # No SEPARATOR is output if MACRO-NAME was previously undefined (different # than defined and empty). # # This macro is needed until we can rely on Autoconf 2.62, since earlier # versions of m4sugar mistakenly expanded SEPARATOR but not STRING. m4_define([lt_append], [m4_define([$1], m4_ifdef([$1], [m4_defn([$1])[$3]])[$2])]) # lt_combine(SEP, PREFIX-LIST, INFIX, SUFFIX1, [SUFFIX2...]) # ---------------------------------------------------------- # Produce a SEP delimited list of all paired combinations of elements of # PREFIX-LIST with SUFFIX1 through SUFFIXn. Each element of the list # has the form PREFIXmINFIXSUFFIXn. # Needed until we can rely on m4_combine added in Autoconf 2.62. m4_define([lt_combine], [m4_if(m4_eval([$# > 3]), [1], [m4_pushdef([_Lt_sep], [m4_define([_Lt_sep], m4_defn([lt_car]))])]]dnl [[m4_foreach([_Lt_prefix], [$2], [m4_foreach([_Lt_suffix], ]m4_dquote(m4_dquote(m4_shift(m4_shift(m4_shift($@)))))[, [_Lt_sep([$1])[]m4_defn([_Lt_prefix])[$3]m4_defn([_Lt_suffix])])])])]) # lt_if_append_uniq(MACRO-NAME, VARNAME, [SEPARATOR], [UNIQ], [NOT-UNIQ]) # ----------------------------------------------------------------------- # Iff MACRO-NAME does not yet contain VARNAME, then append it (delimited # by SEPARATOR if supplied) and expand UNIQ, else NOT-UNIQ. m4_define([lt_if_append_uniq], [m4_ifdef([$1], [m4_if(m4_index([$3]m4_defn([$1])[$3], [$3$2$3]), [-1], [lt_append([$1], [$2], [$3])$4], [$5])], [lt_append([$1], [$2], [$3])$4])]) # lt_dict_add(DICT, KEY, VALUE) # ----------------------------- m4_define([lt_dict_add], [m4_define([$1($2)], [$3])]) # lt_dict_add_subkey(DICT, KEY, SUBKEY, VALUE) # -------------------------------------------- m4_define([lt_dict_add_subkey], [m4_define([$1($2:$3)], [$4])]) # lt_dict_fetch(DICT, KEY, [SUBKEY]) # ---------------------------------- m4_define([lt_dict_fetch], [m4_ifval([$3], m4_ifdef([$1($2:$3)], [m4_defn([$1($2:$3)])]), m4_ifdef([$1($2)], [m4_defn([$1($2)])]))]) # lt_if_dict_fetch(DICT, KEY, [SUBKEY], VALUE, IF-TRUE, [IF-FALSE]) # ----------------------------------------------------------------- m4_define([lt_if_dict_fetch], [m4_if(lt_dict_fetch([$1], [$2], [$3]), [$4], [$5], [$6])]) # lt_dict_filter(DICT, [SUBKEY], VALUE, [SEPARATOR], KEY, [...]) # -------------------------------------------------------------- m4_define([lt_dict_filter], [m4_if([$5], [], [], [lt_join(m4_quote(m4_default([$4], [[, ]])), lt_unquote(m4_split(m4_normalize(m4_foreach(_Lt_key, lt_car([m4_shiftn(4, $@)]), [lt_if_dict_fetch([$1], _Lt_key, [$2], [$3], [_Lt_key ])])))))])[]dnl ]) ntfs-3g-2026.2.25/m4/libtool.m40000644000175000017500000114100515152260210011216 # libtool.m4 - Configure libtool for the host system. -*-Autoconf-*- # # Copyright (C) 1996-2001, 2003-2019, 2021-2024 Free Software # Foundation, Inc. # Written by Gordon Matzigkeit, 1996 # # This file is free software; the Free Software Foundation gives # unlimited permission to copy and/or distribute it, with or without # modifications, as long as this notice is preserved. m4_define([_LT_COPYING], [dnl # Copyright (C) 2024 Free Software Foundation, Inc. # This is free software; see the source for copying conditions. There is NO # warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # GNU Libtool 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. # # As a special exception to the GNU General Public License, if you # distribute this file as part of a program or library that is built # using GNU Libtool, you may include this file under the same # distribution terms that you use for the rest of that program. # # GNU Libtool 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. If not, see . ]) # serial 63 LT_INIT # LT_PREREQ(VERSION) # ------------------ # Complain and exit if this libtool version is less that VERSION. m4_defun([LT_PREREQ], [m4_if(m4_version_compare(m4_defn([LT_PACKAGE_VERSION]), [$1]), -1, [m4_default([$3], [m4_fatal([Libtool version $1 or higher is required], 63)])], [$2])]) # _LT_CHECK_BUILDDIR # ------------------ # Complain if the absolute build directory name contains unusual characters m4_defun([_LT_CHECK_BUILDDIR], [case `pwd` in *\ * | *\ *) AC_MSG_WARN([Libtool does not cope well with whitespace in `pwd`]) ;; esac ]) # LT_INIT([OPTIONS]) # ------------------ AC_DEFUN([LT_INIT], [AC_PREREQ([2.64])dnl We use AC_PATH_PROGS_FEATURE_CHECK AC_REQUIRE([AC_CONFIG_AUX_DIR_DEFAULT])dnl AC_BEFORE([$0], [LT_LANG])dnl AC_BEFORE([$0], [LT_OUTPUT])dnl AC_BEFORE([$0], [LTDL_INIT])dnl m4_require([_LT_CHECK_BUILDDIR])dnl dnl Autoconf doesn't catch unexpanded LT_ macros by default: m4_pattern_forbid([^_?LT_[A-Z_]+$])dnl m4_pattern_allow([^(_LT_EOF|LT_DLGLOBAL|LT_DLLAZY_OR_NOW|LT_MULTI_MODULE)$])dnl dnl aclocal doesn't pull ltoptions.m4, ltsugar.m4, or ltversion.m4 dnl unless we require an AC_DEFUNed macro: AC_REQUIRE([LTOPTIONS_VERSION])dnl AC_REQUIRE([LTSUGAR_VERSION])dnl AC_REQUIRE([LTVERSION_VERSION])dnl AC_REQUIRE([LTOBSOLETE_VERSION])dnl m4_require([_LT_PROG_LTMAIN])dnl _LT_SHELL_INIT([SHELL=${CONFIG_SHELL-/bin/sh}]) dnl Parse OPTIONS _LT_SET_OPTIONS([$0], [$1]) # This can be used to rebuild libtool when needed LIBTOOL_DEPS=$ltmain # Always use our own libtool. LIBTOOL='$(SHELL) $(top_builddir)/libtool' AC_SUBST(LIBTOOL)dnl _LT_SETUP # Only expand once: m4_define([LT_INIT]) ])# LT_INIT # Old names: AU_ALIAS([AC_PROG_LIBTOOL], [LT_INIT]) AU_ALIAS([AM_PROG_LIBTOOL], [LT_INIT]) dnl aclocal-1.4 backwards compatibility: dnl AC_DEFUN([AC_PROG_LIBTOOL], []) dnl AC_DEFUN([AM_PROG_LIBTOOL], []) # _LT_PREPARE_CC_BASENAME # ----------------------- m4_defun([_LT_PREPARE_CC_BASENAME], [ # Calculate cc_basename. Skip known compiler wrappers and cross-prefix. func_cc_basename () { for cc_temp in @S|@*""; do case $cc_temp in compile | *[[\\/]]compile | ccache | *[[\\/]]ccache ) ;; distcc | *[[\\/]]distcc | purify | *[[\\/]]purify ) ;; \-*) ;; *) break;; esac done func_cc_basename_result=`$ECHO "$cc_temp" | $SED "s%.*/%%; s%^$host_alias-%%"` } ])# _LT_PREPARE_CC_BASENAME # _LT_CC_BASENAME(CC) # ------------------- # It would be clearer to call AC_REQUIREs from _LT_PREPARE_CC_BASENAME, # but that macro is also expanded into generated libtool script, which # arranges for $SED and $ECHO to be set by different means. m4_defun([_LT_CC_BASENAME], [m4_require([_LT_PREPARE_CC_BASENAME])dnl AC_REQUIRE([_LT_DECL_SED])dnl AC_REQUIRE([_LT_PROG_ECHO_BACKSLASH])dnl func_cc_basename $1 cc_basename=$func_cc_basename_result ]) # _LT_FILEUTILS_DEFAULTS # ---------------------- # It is okay to use these file commands and assume they have been set # sensibly after 'm4_require([_LT_FILEUTILS_DEFAULTS])'. m4_defun([_LT_FILEUTILS_DEFAULTS], [: ${CP="cp -f"} : ${MV="mv -f"} : ${RM="rm -f"} ])# _LT_FILEUTILS_DEFAULTS # _LT_SETUP # --------- m4_defun([_LT_SETUP], [AC_REQUIRE([AC_CANONICAL_HOST])dnl AC_REQUIRE([AC_CANONICAL_BUILD])dnl AC_REQUIRE([_LT_PREPARE_SED_QUOTE_VARS])dnl AC_REQUIRE([_LT_PROG_ECHO_BACKSLASH])dnl _LT_DECL([], [PATH_SEPARATOR], [1], [The PATH separator for the build system])dnl dnl _LT_DECL([], [host_alias], [0], [The host system])dnl _LT_DECL([], [host], [0])dnl _LT_DECL([], [host_os], [0])dnl dnl _LT_DECL([], [build_alias], [0], [The build system])dnl _LT_DECL([], [build], [0])dnl _LT_DECL([], [build_os], [0])dnl dnl AC_REQUIRE([AC_PROG_CC])dnl AC_REQUIRE([LT_PATH_LD])dnl AC_REQUIRE([LT_PATH_NM])dnl dnl AC_REQUIRE([AC_PROG_LN_S])dnl test -z "$LN_S" && LN_S="ln -s" _LT_DECL([], [LN_S], [1], [Whether we need soft or hard links])dnl dnl AC_REQUIRE([LT_CMD_MAX_LEN])dnl _LT_DECL([objext], [ac_objext], [0], [Object file suffix (normally "o")])dnl _LT_DECL([], [exeext], [0], [Executable file suffix (normally "")])dnl dnl m4_require([_LT_FILEUTILS_DEFAULTS])dnl m4_require([_LT_CHECK_SHELL_FEATURES])dnl m4_require([_LT_PATH_CONVERSION_FUNCTIONS])dnl m4_require([_LT_CMD_RELOAD])dnl m4_require([_LT_DECL_FILECMD])dnl m4_require([_LT_CHECK_MAGIC_METHOD])dnl m4_require([_LT_CHECK_SHAREDLIB_FROM_LINKLIB])dnl m4_require([_LT_CMD_OLD_ARCHIVE])dnl m4_require([_LT_CMD_GLOBAL_SYMBOLS])dnl m4_require([_LT_WITH_SYSROOT])dnl m4_require([_LT_CMD_TRUNCATE])dnl _LT_CONFIG_LIBTOOL_INIT([ # See if we are running on zsh, and set the options that allow our # commands through without removal of \ escapes INIT. if test -n "\${ZSH_VERSION+set}"; then setopt NO_GLOB_SUBST fi ]) if test -n "${ZSH_VERSION+set}"; then setopt NO_GLOB_SUBST fi _LT_CHECK_OBJDIR m4_require([_LT_TAG_COMPILER])dnl case $host_os in aix3*) # AIX sometimes has problems with the GCC collect2 program. For some # reason, if we set the COLLECT_NAMES environment variable, the problems # vanish in a puff of smoke. if test set != "${COLLECT_NAMES+set}"; then COLLECT_NAMES= export COLLECT_NAMES fi ;; esac # Global variables: ofile=libtool can_build_shared=yes # All known linkers require a '.a' archive for static linking (except MSVC and # ICC, which need '.lib'). libext=a with_gnu_ld=$lt_cv_prog_gnu_ld old_CC=$CC old_CFLAGS=$CFLAGS # Set sane defaults for various variables test -z "$CC" && CC=cc test -z "$LTCC" && LTCC=$CC test -z "$LTCFLAGS" && LTCFLAGS=$CFLAGS test -z "$LD" && LD=ld test -z "$ac_objext" && ac_objext=o _LT_CC_BASENAME([$compiler]) # Only perform the check for file, if the check method requires it test -z "$MAGIC_CMD" && MAGIC_CMD=file case $deplibs_check_method in file_magic*) if test "$file_magic_cmd" = '$MAGIC_CMD'; then _LT_PATH_MAGIC fi ;; esac # Use C for the default configuration in the libtool script LT_SUPPORTED_TAG([CC]) _LT_LANG_C_CONFIG _LT_LANG_DEFAULT_CONFIG _LT_CONFIG_COMMANDS ])# _LT_SETUP # _LT_PREPARE_SED_QUOTE_VARS # -------------------------- # Define a few sed substitution that help us do robust quoting. m4_defun([_LT_PREPARE_SED_QUOTE_VARS], [# Backslashify metacharacters that are still active within # double-quoted strings. sed_quote_subst='s/\([["`$\\]]\)/\\\1/g' # Same as above, but do not quote variable references. double_quote_subst='s/\([["`\\]]\)/\\\1/g' # Sed substitution to delay expansion of an escaped shell variable in a # double_quote_subst'ed string. delay_variable_subst='s/\\\\\\\\\\\$/\\\\\\$/g' # Sed substitution to delay expansion of an escaped single quote. delay_single_quote_subst='s/'\''/'\'\\\\\\\'\''/g' # Sed substitution to avoid accidental globbing in evaled expressions no_glob_subst='s/\*/\\\*/g' ]) # _LT_PROG_LTMAIN # --------------- # Note that this code is called both from 'configure', and 'config.status' # now that we use AC_CONFIG_COMMANDS to generate libtool. Notably, # 'config.status' has no value for ac_aux_dir unless we are using Automake, # so we pass a copy along to make sure it has a sensible value anyway. m4_defun([_LT_PROG_LTMAIN], [m4_ifdef([AC_REQUIRE_AUX_FILE], [AC_REQUIRE_AUX_FILE([ltmain.sh])])dnl _LT_CONFIG_LIBTOOL_INIT([ac_aux_dir='$ac_aux_dir']) ltmain=$ac_aux_dir/ltmain.sh ])# _LT_PROG_LTMAIN ## ------------------------------------- ## ## Accumulate code for creating libtool. ## ## ------------------------------------- ## # So that we can recreate a full libtool script including additional # tags, we accumulate the chunks of code to send to AC_CONFIG_COMMANDS # in macros and then make a single call at the end using the 'libtool' # label. # _LT_CONFIG_LIBTOOL_INIT([INIT-COMMANDS]) # ---------------------------------------- # Register INIT-COMMANDS to be passed to AC_CONFIG_COMMANDS later. m4_define([_LT_CONFIG_LIBTOOL_INIT], [m4_ifval([$1], [m4_append([_LT_OUTPUT_LIBTOOL_INIT], [$1 ])])]) # Initialize. m4_define([_LT_OUTPUT_LIBTOOL_INIT]) # _LT_CONFIG_LIBTOOL([COMMANDS]) # ------------------------------ # Register COMMANDS to be passed to AC_CONFIG_COMMANDS later. m4_define([_LT_CONFIG_LIBTOOL], [m4_ifval([$1], [m4_append([_LT_OUTPUT_LIBTOOL_COMMANDS], [$1 ])])]) # Initialize. m4_define([_LT_OUTPUT_LIBTOOL_COMMANDS]) # _LT_CONFIG_SAVE_COMMANDS([COMMANDS], [INIT_COMMANDS]) # ----------------------------------------------------- m4_defun([_LT_CONFIG_SAVE_COMMANDS], [_LT_CONFIG_LIBTOOL([$1]) _LT_CONFIG_LIBTOOL_INIT([$2]) ]) # _LT_FORMAT_COMMENT([COMMENT]) # ----------------------------- # Add leading comment marks to the start of each line, and a trailing # full-stop to the whole comment if one is not present already. m4_define([_LT_FORMAT_COMMENT], [m4_ifval([$1], [ m4_bpatsubst([m4_bpatsubst([$1], [^ *], [# ])], [['`$\]], [\\\&])]m4_bmatch([$1], [[!?.]$], [], [.]) )]) ## ------------------------ ## ## FIXME: Eliminate VARNAME ## ## ------------------------ ## # _LT_DECL([CONFIGNAME], VARNAME, VALUE, [DESCRIPTION], [IS-TAGGED?]) # ------------------------------------------------------------------- # CONFIGNAME is the name given to the value in the libtool script. # VARNAME is the (base) name used in the configure script. # VALUE may be 0, 1 or 2 for a computed quote escaped value based on # VARNAME. Any other value will be used directly. m4_define([_LT_DECL], [lt_if_append_uniq([lt_decl_varnames], [$2], [, ], [lt_dict_add_subkey([lt_decl_dict], [$2], [libtool_name], [m4_ifval([$1], [$1], [$2])]) lt_dict_add_subkey([lt_decl_dict], [$2], [value], [$3]) m4_ifval([$4], [lt_dict_add_subkey([lt_decl_dict], [$2], [description], [$4])]) lt_dict_add_subkey([lt_decl_dict], [$2], [tagged?], [m4_ifval([$5], [yes], [no])])]) ]) # _LT_TAGDECL([CONFIGNAME], VARNAME, VALUE, [DESCRIPTION]) # -------------------------------------------------------- m4_define([_LT_TAGDECL], [_LT_DECL([$1], [$2], [$3], [$4], [yes])]) # lt_decl_tag_varnames([SEPARATOR], [VARNAME1...]) # ------------------------------------------------ m4_define([lt_decl_tag_varnames], [_lt_decl_filter([tagged?], [yes], $@)]) # _lt_decl_filter(SUBKEY, VALUE, [SEPARATOR], [VARNAME1..]) # --------------------------------------------------------- m4_define([_lt_decl_filter], [m4_case([$#], [0], [m4_fatal([$0: too few arguments: $#])], [1], [m4_fatal([$0: too few arguments: $#: $1])], [2], [lt_dict_filter([lt_decl_dict], [$1], [$2], [], lt_decl_varnames)], [3], [lt_dict_filter([lt_decl_dict], [$1], [$2], [$3], lt_decl_varnames)], [lt_dict_filter([lt_decl_dict], $@)])[]dnl ]) # lt_decl_quote_varnames([SEPARATOR], [VARNAME1...]) # -------------------------------------------------- m4_define([lt_decl_quote_varnames], [_lt_decl_filter([value], [1], $@)]) # lt_decl_dquote_varnames([SEPARATOR], [VARNAME1...]) # --------------------------------------------------- m4_define([lt_decl_dquote_varnames], [_lt_decl_filter([value], [2], $@)]) # lt_decl_varnames_tagged([SEPARATOR], [VARNAME1...]) # --------------------------------------------------- m4_define([lt_decl_varnames_tagged], [m4_assert([$# <= 2])dnl _$0(m4_quote(m4_default([$1], [[, ]])), m4_ifval([$2], [[$2]], [m4_dquote(lt_decl_tag_varnames)]), m4_split(m4_normalize(m4_quote(_LT_TAGS)), [ ]))]) m4_define([_lt_decl_varnames_tagged], [m4_ifval([$3], [lt_combine([$1], [$2], [_], $3)])]) # lt_decl_all_varnames([SEPARATOR], [VARNAME1...]) # ------------------------------------------------ m4_define([lt_decl_all_varnames], [_$0(m4_quote(m4_default([$1], [[, ]])), m4_if([$2], [], m4_quote(lt_decl_varnames), m4_quote(m4_shift($@))))[]dnl ]) m4_define([_lt_decl_all_varnames], [lt_join($@, lt_decl_varnames_tagged([$1], lt_decl_tag_varnames([[, ]], m4_shift($@))))dnl ]) # _LT_CONFIG_STATUS_DECLARE([VARNAME]) # ------------------------------------ # Quote a variable value, and forward it to 'config.status' so that its # declaration there will have the same value as in 'configure'. VARNAME # must have a single quote delimited value for this to work. m4_define([_LT_CONFIG_STATUS_DECLARE], [$1='`$ECHO "$][$1" | $SED "$delay_single_quote_subst"`']) # _LT_CONFIG_STATUS_DECLARATIONS # ------------------------------ # We delimit libtool config variables with single quotes, so when # we write them to config.status, we have to be sure to quote all # embedded single quotes properly. In configure, this macro expands # each variable declared with _LT_DECL (and _LT_TAGDECL) into: # # ='`$ECHO "$" | $SED "$delay_single_quote_subst"`' m4_defun([_LT_CONFIG_STATUS_DECLARATIONS], [m4_foreach([_lt_var], m4_quote(lt_decl_all_varnames), [m4_n([_LT_CONFIG_STATUS_DECLARE(_lt_var)])])]) # _LT_LIBTOOL_TAGS # ---------------- # Output comment and list of tags supported by the script m4_defun([_LT_LIBTOOL_TAGS], [_LT_FORMAT_COMMENT([The names of the tagged configurations supported by this script])dnl available_tags='_LT_TAGS'dnl ]) # _LT_LIBTOOL_DECLARE(VARNAME, [TAG]) # ----------------------------------- # Extract the dictionary values for VARNAME (optionally with TAG) and # expand to a commented shell variable setting: # # # Some comment about what VAR is for. # visible_name=$lt_internal_name m4_define([_LT_LIBTOOL_DECLARE], [_LT_FORMAT_COMMENT(m4_quote(lt_dict_fetch([lt_decl_dict], [$1], [description])))[]dnl m4_pushdef([_libtool_name], m4_quote(lt_dict_fetch([lt_decl_dict], [$1], [libtool_name])))[]dnl m4_case(m4_quote(lt_dict_fetch([lt_decl_dict], [$1], [value])), [0], [_libtool_name=[$]$1], [1], [_libtool_name=$lt_[]$1], [2], [_libtool_name=$lt_[]$1], [_libtool_name=lt_dict_fetch([lt_decl_dict], [$1], [value])])[]dnl m4_ifval([$2], [_$2])[]m4_popdef([_libtool_name])[]dnl ]) # _LT_LIBTOOL_CONFIG_VARS # ----------------------- # Produce commented declarations of non-tagged libtool config variables # suitable for insertion in the LIBTOOL CONFIG section of the 'libtool' # script. Tagged libtool config variables (even for the LIBTOOL CONFIG # section) are produced by _LT_LIBTOOL_TAG_VARS. m4_defun([_LT_LIBTOOL_CONFIG_VARS], [m4_foreach([_lt_var], m4_quote(_lt_decl_filter([tagged?], [no], [], lt_decl_varnames)), [m4_n([_LT_LIBTOOL_DECLARE(_lt_var)])])]) # _LT_LIBTOOL_TAG_VARS(TAG) # ------------------------- m4_define([_LT_LIBTOOL_TAG_VARS], [m4_foreach([_lt_var], m4_quote(lt_decl_tag_varnames), [m4_n([_LT_LIBTOOL_DECLARE(_lt_var, [$1])])])]) # _LT_TAGVAR(VARNAME, [TAGNAME]) # ------------------------------ m4_define([_LT_TAGVAR], [m4_ifval([$2], [$1_$2], [$1])]) # _LT_CONFIG_COMMANDS # ------------------- # Send accumulated output to $CONFIG_STATUS. Thanks to the lists of # variables for single and double quote escaping we saved from calls # to _LT_DECL, we can put quote escaped variables declarations # into 'config.status', and then the shell code to quote escape them in # for loops in 'config.status'. Finally, any additional code accumulated # from calls to _LT_CONFIG_LIBTOOL_INIT is expanded. m4_defun([_LT_CONFIG_COMMANDS], [AC_PROVIDE_IFELSE([LT_OUTPUT], dnl If the libtool generation code has been placed in $CONFIG_LT, dnl instead of duplicating it all over again into config.status, dnl then we will have config.status run $CONFIG_LT later, so it dnl needs to know what name is stored there: [AC_CONFIG_COMMANDS([libtool], [$SHELL $CONFIG_LT || AS_EXIT(1)], [CONFIG_LT='$CONFIG_LT'])], dnl If the libtool generation code is destined for config.status, dnl expand the accumulated commands and init code now: [AC_CONFIG_COMMANDS([libtool], [_LT_OUTPUT_LIBTOOL_COMMANDS], [_LT_OUTPUT_LIBTOOL_COMMANDS_INIT])]) ])#_LT_CONFIG_COMMANDS # Initialize. m4_define([_LT_OUTPUT_LIBTOOL_COMMANDS_INIT], [ # The HP-UX ksh and POSIX shell print the target directory to stdout # if CDPATH is set. (unset CDPATH) >/dev/null 2>&1 && unset CDPATH sed_quote_subst='$sed_quote_subst' double_quote_subst='$double_quote_subst' delay_variable_subst='$delay_variable_subst' _LT_CONFIG_STATUS_DECLARATIONS LTCC='$LTCC' LTCFLAGS='$LTCFLAGS' compiler='$compiler_DEFAULT' # A function that is used when there is no print builtin or printf. func_fallback_echo () { eval 'cat <<_LTECHO_EOF \$[]1 _LTECHO_EOF' } # Quote evaled strings. for var in lt_decl_all_varnames([[ \ ]], lt_decl_quote_varnames); do case \`eval \\\\\$ECHO \\\\""\\\\\$\$var"\\\\"\` in *[[\\\\\\\`\\"\\\$]]*) eval "lt_\$var=\\\\\\"\\\`\\\$ECHO \\"\\\$\$var\\" | \\\$SED \\"\\\$sed_quote_subst\\"\\\`\\\\\\"" ## exclude from sc_prohibit_nested_quotes ;; *) eval "lt_\$var=\\\\\\"\\\$\$var\\\\\\"" ;; esac done # Double-quote double-evaled strings. for var in lt_decl_all_varnames([[ \ ]], lt_decl_dquote_varnames); do case \`eval \\\\\$ECHO \\\\""\\\\\$\$var"\\\\"\` in *[[\\\\\\\`\\"\\\$]]*) eval "lt_\$var=\\\\\\"\\\`\\\$ECHO \\"\\\$\$var\\" | \\\$SED -e \\"\\\$double_quote_subst\\" -e \\"\\\$sed_quote_subst\\" -e \\"\\\$delay_variable_subst\\"\\\`\\\\\\"" ## exclude from sc_prohibit_nested_quotes ;; *) eval "lt_\$var=\\\\\\"\\\$\$var\\\\\\"" ;; esac done _LT_OUTPUT_LIBTOOL_INIT ]) # _LT_GENERATED_FILE_INIT(FILE, [COMMENT]) # ------------------------------------ # Generate a child script FILE with all initialization necessary to # reuse the environment learned by the parent script, and make the # file executable. If COMMENT is supplied, it is inserted after the # '#!' sequence but before initialization text begins. After this # macro, additional text can be appended to FILE to form the body of # the child script. The macro ends with non-zero status if the # file could not be fully written (such as if the disk is full). m4_ifdef([AS_INIT_GENERATED], [m4_defun([_LT_GENERATED_FILE_INIT],[AS_INIT_GENERATED($@)])], [m4_defun([_LT_GENERATED_FILE_INIT], [m4_require([AS_PREPARE])]dnl [m4_pushdef([AS_MESSAGE_LOG_FD])]dnl [lt_write_fail=0 cat >$1 <<_ASEOF || lt_write_fail=1 #! $SHELL # Generated by $as_me. $2 SHELL=\${CONFIG_SHELL-$SHELL} export SHELL _ASEOF cat >>$1 <<\_ASEOF || lt_write_fail=1 AS_SHELL_SANITIZE _AS_PREPARE exec AS_MESSAGE_FD>&1 _ASEOF test 0 = "$lt_write_fail" && chmod +x $1[]dnl m4_popdef([AS_MESSAGE_LOG_FD])])])# _LT_GENERATED_FILE_INIT # LT_OUTPUT # --------- # This macro allows early generation of the libtool script (before # AC_OUTPUT is called), in case it is used in configure for compilation # tests. AC_DEFUN([LT_OUTPUT], [: ${CONFIG_LT=./config.lt} AC_MSG_NOTICE([creating $CONFIG_LT]) _LT_GENERATED_FILE_INIT(["$CONFIG_LT"], [# Run this file to recreate a libtool stub with the current configuration.]) cat >>"$CONFIG_LT" <<\_LTEOF lt_cl_silent=false exec AS_MESSAGE_LOG_FD>>config.log { echo AS_BOX([Running $as_me.]) } >&AS_MESSAGE_LOG_FD lt_cl_help="\ '$as_me' creates a local libtool stub from the current configuration, for use in further configure time tests before the real libtool is generated. Usage: $[0] [[OPTIONS]] -h, --help print this help, then exit -V, --version print version number, then exit -q, --quiet do not print progress messages -d, --debug don't remove temporary files Report bugs to ." lt_cl_version="\ m4_ifset([AC_PACKAGE_NAME], [AC_PACKAGE_NAME ])config.lt[]dnl m4_ifset([AC_PACKAGE_VERSION], [ AC_PACKAGE_VERSION]) configured by $[0], generated by m4_PACKAGE_STRING. Copyright (C) 2024 Free Software Foundation, Inc. This config.lt script is free software; the Free Software Foundation gives unlimited permission to copy, distribute and modify it." while test 0 != $[#] do case $[1] in --version | --v* | -V ) echo "$lt_cl_version"; exit 0 ;; --help | --h* | -h ) echo "$lt_cl_help"; exit 0 ;; --debug | --d* | -d ) debug=: ;; --quiet | --q* | --silent | --s* | -q ) lt_cl_silent=: ;; -*) AC_MSG_ERROR([unrecognized option: $[1] Try '$[0] --help' for more information.]) ;; *) AC_MSG_ERROR([unrecognized argument: $[1] Try '$[0] --help' for more information.]) ;; esac shift done if $lt_cl_silent; then exec AS_MESSAGE_FD>/dev/null fi _LTEOF cat >>"$CONFIG_LT" <<_LTEOF _LT_OUTPUT_LIBTOOL_COMMANDS_INIT _LTEOF cat >>"$CONFIG_LT" <<\_LTEOF AC_MSG_NOTICE([creating $ofile]) _LT_OUTPUT_LIBTOOL_COMMANDS AS_EXIT(0) _LTEOF chmod +x "$CONFIG_LT" # configure is writing to config.log, but config.lt does its own redirection, # appending to config.log, which fails on DOS, as config.log is still kept # open by configure. Here we exec the FD to /dev/null, effectively closing # config.log, so it can be properly (re)opened and appended to by config.lt. lt_cl_success=: test yes = "$silent" && lt_config_lt_args="$lt_config_lt_args --quiet" exec AS_MESSAGE_LOG_FD>/dev/null $SHELL "$CONFIG_LT" $lt_config_lt_args || lt_cl_success=false exec AS_MESSAGE_LOG_FD>>config.log $lt_cl_success || AS_EXIT(1) ])# LT_OUTPUT # _LT_CONFIG(TAG) # --------------- # If TAG is the built-in tag, create an initial libtool script with a # default configuration from the untagged config vars. Otherwise add code # to config.status for appending the configuration named by TAG from the # matching tagged config vars. m4_defun([_LT_CONFIG], [m4_require([_LT_FILEUTILS_DEFAULTS])dnl _LT_CONFIG_SAVE_COMMANDS([ m4_define([_LT_TAG], m4_if([$1], [], [C], [$1]))dnl m4_if(_LT_TAG, [C], [ # See if we are running on zsh, and set the options that allow our # commands through without removal of \ escapes. if test -n "${ZSH_VERSION+set}"; then setopt NO_GLOB_SUBST fi cfgfile=${ofile}T trap "$RM \"$cfgfile\"; exit 1" 1 2 15 $RM "$cfgfile" cat <<_LT_EOF >> "$cfgfile" #! $SHELL # Generated automatically by $as_me ($PACKAGE) $VERSION # NOTE: Changes made to this file will be lost: look at ltmain.sh. # Provide generalized library-building support services. # Written by Gordon Matzigkeit, 1996 _LT_COPYING _LT_LIBTOOL_TAGS # Configured defaults for sys_lib_dlsearch_path munging. : \${LT_SYS_LIBRARY_PATH="$configure_time_lt_sys_library_path"} # ### BEGIN LIBTOOL CONFIG _LT_LIBTOOL_CONFIG_VARS _LT_LIBTOOL_TAG_VARS # ### END LIBTOOL CONFIG _LT_EOF cat <<'_LT_EOF' >> "$cfgfile" # ### BEGIN FUNCTIONS SHARED WITH CONFIGURE _LT_PREPARE_MUNGE_PATH_LIST _LT_PREPARE_CC_BASENAME # ### END FUNCTIONS SHARED WITH CONFIGURE _LT_EOF case $host_os in aix3*) cat <<\_LT_EOF >> "$cfgfile" # AIX sometimes has problems with the GCC collect2 program. For some # reason, if we set the COLLECT_NAMES environment variable, the problems # vanish in a puff of smoke. if test set != "${COLLECT_NAMES+set}"; then COLLECT_NAMES= export COLLECT_NAMES fi _LT_EOF ;; esac _LT_PROG_LTMAIN # We use sed instead of cat because bash on DJGPP gets confused if # if finds mixed CR/LF and LF-only lines. Since sed operates in # text mode, it properly converts lines to CR/LF. This bash problem # is reportedly fixed, but why not run on old versions too? $SED '$q' "$ltmain" >> "$cfgfile" \ || (rm -f "$cfgfile"; exit 1) mv -f "$cfgfile" "$ofile" || (rm -f "$ofile" && cp "$cfgfile" "$ofile" && rm -f "$cfgfile") chmod +x "$ofile" ], [cat <<_LT_EOF >> "$ofile" dnl Unfortunately we have to use $1 here, since _LT_TAG is not expanded dnl in a comment (ie after a #). # ### BEGIN LIBTOOL TAG CONFIG: $1 _LT_LIBTOOL_TAG_VARS(_LT_TAG) # ### END LIBTOOL TAG CONFIG: $1 _LT_EOF ])dnl /m4_if ], [m4_if([$1], [], [ PACKAGE='$PACKAGE' VERSION='$VERSION' RM='$RM' ofile='$ofile'], []) ])dnl /_LT_CONFIG_SAVE_COMMANDS ])# _LT_CONFIG # LT_SUPPORTED_TAG(TAG) # --------------------- # Trace this macro to discover what tags are supported by the libtool # --tag option, using: # autoconf --trace 'LT_SUPPORTED_TAG:$1' AC_DEFUN([LT_SUPPORTED_TAG], []) # C support is built-in for now m4_define([_LT_LANG_C_enabled], []) m4_define([_LT_TAGS], []) # LT_LANG(LANG) # ------------- # Enable libtool support for the given language if not already enabled. AC_DEFUN([LT_LANG], [AC_BEFORE([$0], [LT_OUTPUT])dnl m4_case([$1], [C], [_LT_LANG(C)], [C++], [_LT_LANG(CXX)], [Go], [_LT_LANG(GO)], [Java], [_LT_LANG(GCJ)], [Fortran 77], [_LT_LANG(F77)], [Fortran], [_LT_LANG(FC)], [Windows Resource], [_LT_LANG(RC)], [m4_ifdef([_LT_LANG_]$1[_CONFIG], [_LT_LANG($1)], [m4_fatal([$0: unsupported language: "$1"])])])dnl ])# LT_LANG # _LT_LANG(LANGNAME) # ------------------ m4_defun([_LT_LANG], [m4_ifdef([_LT_LANG_]$1[_enabled], [], [LT_SUPPORTED_TAG([$1])dnl m4_append([_LT_TAGS], [$1 ])dnl m4_define([_LT_LANG_]$1[_enabled], [])dnl _LT_LANG_$1_CONFIG($1)])dnl ])# _LT_LANG m4_ifndef([AC_PROG_GO], [ ############################################################ # NOTE: This macro has been submitted for inclusion into # # GNU Autoconf as AC_PROG_GO. When it is available in # # a released version of Autoconf we should remove this # # macro and use it instead. # ############################################################ m4_defun([AC_PROG_GO], [AC_LANG_PUSH(Go)dnl AC_ARG_VAR([GOC], [Go compiler command])dnl AC_ARG_VAR([GOFLAGS], [Go compiler flags])dnl _AC_ARG_VAR_LDFLAGS()dnl AC_CHECK_TOOL(GOC, gccgo) if test -z "$GOC"; then if test -n "$ac_tool_prefix"; then AC_CHECK_PROG(GOC, [${ac_tool_prefix}gccgo], [${ac_tool_prefix}gccgo]) fi fi if test -z "$GOC"; then AC_CHECK_PROG(GOC, gccgo, gccgo, false) fi ])#m4_defun ])#m4_ifndef # _LT_LANG_DEFAULT_CONFIG # ----------------------- m4_defun([_LT_LANG_DEFAULT_CONFIG], [AC_PROVIDE_IFELSE([AC_PROG_CXX], [LT_LANG(CXX)], [m4_define([AC_PROG_CXX], defn([AC_PROG_CXX])[LT_LANG(CXX)])]) AC_PROVIDE_IFELSE([AC_PROG_F77], [LT_LANG(F77)], [m4_define([AC_PROG_F77], defn([AC_PROG_F77])[LT_LANG(F77)])]) AC_PROVIDE_IFELSE([AC_PROG_FC], [LT_LANG(FC)], [m4_define([AC_PROG_FC], defn([AC_PROG_FC])[LT_LANG(FC)])]) dnl The call to [A][M_PROG_GCJ] is quoted like that to stop aclocal dnl pulling things in needlessly. AC_PROVIDE_IFELSE([AC_PROG_GCJ], [LT_LANG(GCJ)], [AC_PROVIDE_IFELSE([A][M_PROG_GCJ], [LT_LANG(GCJ)], [AC_PROVIDE_IFELSE([LT_PROG_GCJ], [LT_LANG(GCJ)], [m4_ifdef([AC_PROG_GCJ], [m4_define([AC_PROG_GCJ], defn([AC_PROG_GCJ])[LT_LANG(GCJ)])]) m4_ifdef([A][M_PROG_GCJ], [m4_define([A][M_PROG_GCJ], defn([A][M_PROG_GCJ])[LT_LANG(GCJ)])]) m4_ifdef([LT_PROG_GCJ], [m4_define([LT_PROG_GCJ], defn([LT_PROG_GCJ])[LT_LANG(GCJ)])])])])]) AC_PROVIDE_IFELSE([AC_PROG_GO], [LT_LANG(GO)], [m4_define([AC_PROG_GO], defn([AC_PROG_GO])[LT_LANG(GO)])]) AC_PROVIDE_IFELSE([LT_PROG_RC], [LT_LANG(RC)], [m4_define([LT_PROG_RC], defn([LT_PROG_RC])[LT_LANG(RC)])]) ])# _LT_LANG_DEFAULT_CONFIG # Obsolete macros: AU_DEFUN([AC_LIBTOOL_CXX], [LT_LANG(C++)]) AU_DEFUN([AC_LIBTOOL_F77], [LT_LANG(Fortran 77)]) AU_DEFUN([AC_LIBTOOL_FC], [LT_LANG(Fortran)]) AU_DEFUN([AC_LIBTOOL_GCJ], [LT_LANG(Java)]) AU_DEFUN([AC_LIBTOOL_RC], [LT_LANG(Windows Resource)]) dnl aclocal-1.4 backwards compatibility: dnl AC_DEFUN([AC_LIBTOOL_CXX], []) dnl AC_DEFUN([AC_LIBTOOL_F77], []) dnl AC_DEFUN([AC_LIBTOOL_FC], []) dnl AC_DEFUN([AC_LIBTOOL_GCJ], []) dnl AC_DEFUN([AC_LIBTOOL_RC], []) # _LT_TAG_COMPILER # ---------------- m4_defun([_LT_TAG_COMPILER], [AC_REQUIRE([AC_PROG_CC])dnl _LT_DECL([LTCC], [CC], [1], [A C compiler])dnl _LT_DECL([LTCFLAGS], [CFLAGS], [1], [LTCC compiler flags])dnl _LT_TAGDECL([CC], [compiler], [1], [A language specific compiler])dnl _LT_TAGDECL([with_gcc], [GCC], [0], [Is the compiler the GNU compiler?])dnl # If no C compiler was specified, use CC. LTCC=${LTCC-"$CC"} # If no C compiler flags were specified, use CFLAGS. LTCFLAGS=${LTCFLAGS-"$CFLAGS"} # Allow CC to be a program name with arguments. compiler=$CC ])# _LT_TAG_COMPILER # _LT_COMPILER_BOILERPLATE # ------------------------ # Check for compiler boilerplate output or warnings with # the simple compiler test code. m4_defun([_LT_COMPILER_BOILERPLATE], [m4_require([_LT_DECL_SED])dnl ac_outfile=conftest.$ac_objext echo "$lt_simple_compile_test_code" >conftest.$ac_ext eval "$ac_compile" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err _lt_compiler_boilerplate=`cat conftest.err` $RM conftest* ])# _LT_COMPILER_BOILERPLATE # _LT_LINKER_BOILERPLATE # ---------------------- # Check for linker boilerplate output or warnings with # the simple link test code. m4_defun([_LT_LINKER_BOILERPLATE], [m4_require([_LT_DECL_SED])dnl ac_outfile=conftest.$ac_objext echo "$lt_simple_link_test_code" >conftest.$ac_ext eval "$ac_link" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err _lt_linker_boilerplate=`cat conftest.err` $RM -r conftest* ])# _LT_LINKER_BOILERPLATE # _LT_REQUIRED_DARWIN_CHECKS # ------------------------- m4_defun_once([_LT_REQUIRED_DARWIN_CHECKS],[ case $host_os in rhapsody* | darwin*) AC_CHECK_TOOL([DSYMUTIL], [dsymutil], [:]) AC_CHECK_TOOL([NMEDIT], [nmedit], [:]) AC_CHECK_TOOL([LIPO], [lipo], [:]) AC_CHECK_TOOL([OTOOL], [otool], [:]) AC_CHECK_TOOL([OTOOL64], [otool64], [:]) _LT_DECL([], [DSYMUTIL], [1], [Tool to manipulate archived DWARF debug symbol files on Mac OS X]) _LT_DECL([], [NMEDIT], [1], [Tool to change global to local symbols on Mac OS X]) _LT_DECL([], [LIPO], [1], [Tool to manipulate fat objects and archives on Mac OS X]) _LT_DECL([], [OTOOL], [1], [ldd/readelf like tool for Mach-O binaries on Mac OS X]) _LT_DECL([], [OTOOL64], [1], [ldd/readelf like tool for 64 bit Mach-O binaries on Mac OS X 10.4]) AC_CACHE_CHECK([for -single_module linker flag],[lt_cv_apple_cc_single_mod], [lt_cv_apple_cc_single_mod=no if test -z "$LT_MULTI_MODULE"; then # By default we will add the -single_module flag. You can override # by either setting the environment variable LT_MULTI_MODULE # non-empty at configure time, or by adding -multi_module to the # link flags. rm -rf libconftest.dylib* echo "int foo(void){return 1;}" > conftest.c echo "$LTCC $LTCFLAGS $LDFLAGS -o libconftest.dylib \ -dynamiclib -Wl,-single_module conftest.c" >&AS_MESSAGE_LOG_FD $LTCC $LTCFLAGS $LDFLAGS -o libconftest.dylib \ -dynamiclib -Wl,-single_module conftest.c 2>conftest.err _lt_result=$? # If there is a non-empty error log, and "single_module" # appears in it, assume the flag caused a linker warning if test -s conftest.err && $GREP single_module conftest.err; then cat conftest.err >&AS_MESSAGE_LOG_FD # Otherwise, if the output was created with a 0 exit code from # the compiler, it worked. elif test -f libconftest.dylib && test 0 = "$_lt_result"; then lt_cv_apple_cc_single_mod=yes else cat conftest.err >&AS_MESSAGE_LOG_FD fi rm -rf libconftest.dylib* rm -f conftest.* fi]) # Feature test to disable chained fixups since it is not # compatible with '-undefined dynamic_lookup' AC_CACHE_CHECK([for -no_fixup_chains linker flag], [lt_cv_support_no_fixup_chains], [ save_LDFLAGS=$LDFLAGS LDFLAGS="$LDFLAGS -Wl,-no_fixup_chains" AC_LINK_IFELSE( [AC_LANG_PROGRAM([],[])], lt_cv_support_no_fixup_chains=yes, lt_cv_support_no_fixup_chains=no ) LDFLAGS=$save_LDFLAGS ] ) AC_CACHE_CHECK([for -exported_symbols_list linker flag], [lt_cv_ld_exported_symbols_list], [lt_cv_ld_exported_symbols_list=no save_LDFLAGS=$LDFLAGS echo "_main" > conftest.sym LDFLAGS="$LDFLAGS -Wl,-exported_symbols_list,conftest.sym" AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])], [lt_cv_ld_exported_symbols_list=yes], [lt_cv_ld_exported_symbols_list=no]) LDFLAGS=$save_LDFLAGS ]) AC_CACHE_CHECK([for -force_load linker flag],[lt_cv_ld_force_load], [lt_cv_ld_force_load=no cat > conftest.c << _LT_EOF int forced_loaded() { return 2;} _LT_EOF echo "$LTCC $LTCFLAGS -c -o conftest.o conftest.c" >&AS_MESSAGE_LOG_FD $LTCC $LTCFLAGS -c -o conftest.o conftest.c 2>&AS_MESSAGE_LOG_FD echo "$AR $AR_FLAGS libconftest.a conftest.o" >&AS_MESSAGE_LOG_FD $AR $AR_FLAGS libconftest.a conftest.o 2>&AS_MESSAGE_LOG_FD echo "$RANLIB libconftest.a" >&AS_MESSAGE_LOG_FD $RANLIB libconftest.a 2>&AS_MESSAGE_LOG_FD cat > conftest.c << _LT_EOF int main(void) { return 0;} _LT_EOF echo "$LTCC $LTCFLAGS $LDFLAGS -o conftest conftest.c -Wl,-force_load,./libconftest.a" >&AS_MESSAGE_LOG_FD $LTCC $LTCFLAGS $LDFLAGS -o conftest conftest.c -Wl,-force_load,./libconftest.a 2>conftest.err _lt_result=$? if test -s conftest.err && $GREP force_load conftest.err; then cat conftest.err >&AS_MESSAGE_LOG_FD elif test -f conftest && test 0 = "$_lt_result" && $GREP forced_load conftest >/dev/null 2>&1; then lt_cv_ld_force_load=yes else cat conftest.err >&AS_MESSAGE_LOG_FD fi rm -f conftest.err libconftest.a conftest conftest.c rm -rf conftest.dSYM ]) case $host_os in rhapsody* | darwin1.[[012]]) _lt_dar_allow_undefined='$wl-undefined ${wl}suppress' ;; darwin1.*) _lt_dar_allow_undefined='$wl-flat_namespace $wl-undefined ${wl}suppress' ;; darwin*) case $MACOSX_DEPLOYMENT_TARGET,$host in 10.[[012]],*|,*powerpc*-darwin[[5-8]]*) _lt_dar_allow_undefined='$wl-flat_namespace $wl-undefined ${wl}suppress' ;; *) _lt_dar_allow_undefined='$wl-undefined ${wl}dynamic_lookup' if test yes = "$lt_cv_support_no_fixup_chains"; then AS_VAR_APPEND([_lt_dar_allow_undefined], [' $wl-no_fixup_chains']) fi ;; esac ;; esac if test yes = "$lt_cv_apple_cc_single_mod"; then _lt_dar_single_mod='$single_module' fi _lt_dar_needs_single_mod=no case $host_os in rhapsody* | darwin1.*) _lt_dar_needs_single_mod=yes ;; darwin*) # When targeting Mac OS X 10.4 (darwin 8) or later, # -single_module is the default and -multi_module is unsupported. # The toolchain on macOS 10.14 (darwin 18) and later cannot # target any OS version that needs -single_module. case ${MACOSX_DEPLOYMENT_TARGET-10.0},$host in 10.0,*-darwin[[567]].*|10.[[0-3]],*-darwin[[5-9]].*|10.[[0-3]],*-darwin1[[0-7]].*) _lt_dar_needs_single_mod=yes ;; esac ;; esac if test yes = "$lt_cv_ld_exported_symbols_list"; then _lt_dar_export_syms=' $wl-exported_symbols_list,$output_objdir/$libname-symbols.expsym' else _lt_dar_export_syms='~$NMEDIT -s $output_objdir/$libname-symbols.expsym $lib' fi if test : != "$DSYMUTIL" && test no = "$lt_cv_ld_force_load"; then _lt_dsymutil='~$DSYMUTIL $lib || :' else _lt_dsymutil= fi ;; esac ]) # _LT_DARWIN_LINKER_FEATURES([TAG]) # --------------------------------- # Checks for linker and compiler features on darwin m4_defun([_LT_DARWIN_LINKER_FEATURES], [ m4_require([_LT_REQUIRED_DARWIN_CHECKS]) _LT_TAGVAR(archive_cmds_need_lc, $1)=no _LT_TAGVAR(hardcode_direct, $1)=no _LT_TAGVAR(hardcode_automatic, $1)=yes _LT_TAGVAR(hardcode_shlibpath_var, $1)=unsupported if test yes = "$lt_cv_ld_force_load"; then _LT_TAGVAR(whole_archive_flag_spec, $1)='`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience $wl-force_load,$conv\"; done; func_echo_all \"$new_convenience\"`' m4_case([$1], [F77], [_LT_TAGVAR(compiler_needs_object, $1)=yes], [FC], [_LT_TAGVAR(compiler_needs_object, $1)=yes]) else _LT_TAGVAR(whole_archive_flag_spec, $1)='' fi _LT_TAGVAR(link_all_deplibs, $1)=yes _LT_TAGVAR(allow_undefined_flag, $1)=$_lt_dar_allow_undefined case $cc_basename in ifort*|nagfor*) _lt_dar_can_shared=yes ;; *) _lt_dar_can_shared=$GCC ;; esac if test yes = "$_lt_dar_can_shared"; then output_verbose_link_cmd=func_echo_all _LT_TAGVAR(archive_cmds, $1)="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod$_lt_dsymutil" _LT_TAGVAR(module_cmds, $1)="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags$_lt_dsymutil" _LT_TAGVAR(archive_expsym_cmds, $1)="$SED 's|^|_|' < \$export_symbols > \$output_objdir/\$libname-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod$_lt_dar_export_syms$_lt_dsymutil" _LT_TAGVAR(module_expsym_cmds, $1)="$SED -e 's|^|_|' < \$export_symbols > \$output_objdir/\$libname-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags$_lt_dar_export_syms$_lt_dsymutil" m4_if([$1], [CXX], [ if test yes = "$_lt_dar_needs_single_mod" -a yes != "$lt_cv_apple_cc_single_mod"; then _LT_TAGVAR(archive_cmds, $1)="\$CC -r -keep_private_externs -nostdlib -o \$lib-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$lib-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring$_lt_dsymutil" _LT_TAGVAR(archive_expsym_cmds, $1)="$SED 's|^|_|' < \$export_symbols > \$output_objdir/\$libname-symbols.expsym~\$CC -r -keep_private_externs -nostdlib -o \$lib-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$lib-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring$_lt_dar_export_syms$_lt_dsymutil" fi ],[]) else _LT_TAGVAR(ld_shlibs, $1)=no fi ]) # _LT_SYS_MODULE_PATH_AIX([TAGNAME]) # ---------------------------------- # Links a minimal program and checks the executable # for the system default hardcoded library path. In most cases, # this is /usr/lib:/lib, but when the MPI compilers are used # the location of the communication and MPI libs are included too. # If we don't find anything, use the default library path according # to the aix ld manual. # Store the results from the different compilers for each TAGNAME. # Allow to override them for all tags through lt_cv_aix_libpath. m4_defun([_LT_SYS_MODULE_PATH_AIX], [m4_require([_LT_DECL_SED])dnl if test set = "${lt_cv_aix_libpath+set}"; then aix_libpath=$lt_cv_aix_libpath else AC_CACHE_VAL([_LT_TAGVAR([lt_cv_aix_libpath_], [$1])], [AC_LINK_IFELSE([AC_LANG_PROGRAM],[ lt_aix_libpath_sed='[ /Import File Strings/,/^$/ { /^0/ { s/^0 *\([^ ]*\) *$/\1/ p } }]' _LT_TAGVAR([lt_cv_aix_libpath_], [$1])=`dump -H conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"` # Check for a 64-bit object if we didn't find anything. if test -z "$_LT_TAGVAR([lt_cv_aix_libpath_], [$1])"; then _LT_TAGVAR([lt_cv_aix_libpath_], [$1])=`dump -HX64 conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"` fi],[]) if test -z "$_LT_TAGVAR([lt_cv_aix_libpath_], [$1])"; then _LT_TAGVAR([lt_cv_aix_libpath_], [$1])=/usr/lib:/lib fi ]) aix_libpath=$_LT_TAGVAR([lt_cv_aix_libpath_], [$1]) fi ])# _LT_SYS_MODULE_PATH_AIX # _LT_SHELL_INIT(ARG) # ------------------- m4_define([_LT_SHELL_INIT], [m4_divert_text([M4SH-INIT], [$1 ])])# _LT_SHELL_INIT # _LT_PROG_ECHO_BACKSLASH # ----------------------- # Find how we can fake an echo command that does not interpret backslash. # In particular, with Autoconf 2.60 or later we add some code to the start # of the generated configure script that will find a shell with a builtin # printf (that we can use as an echo command). m4_defun([_LT_PROG_ECHO_BACKSLASH], [ECHO='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\' ECHO=$ECHO$ECHO$ECHO$ECHO$ECHO ECHO=$ECHO$ECHO$ECHO$ECHO$ECHO$ECHO AC_MSG_CHECKING([how to print strings]) # Test print first, because it will be a builtin if present. if test "X`( print -r -- -n ) 2>/dev/null`" = X-n && \ test "X`print -r -- $ECHO 2>/dev/null`" = "X$ECHO"; then ECHO='print -r --' elif test "X`printf %s $ECHO 2>/dev/null`" = "X$ECHO"; then ECHO='printf %s\n' else # Use this function as a fallback that always works. func_fallback_echo () { eval 'cat <<_LTECHO_EOF $[]1 _LTECHO_EOF' } ECHO='func_fallback_echo' fi # func_echo_all arg... # Invoke $ECHO with all args, space-separated. func_echo_all () { $ECHO "$*" } case $ECHO in printf*) AC_MSG_RESULT([printf]) ;; print*) AC_MSG_RESULT([print -r]) ;; *) AC_MSG_RESULT([cat]) ;; esac m4_ifdef([_AS_DETECT_SUGGESTED], [_AS_DETECT_SUGGESTED([ test -n "${ZSH_VERSION+set}${BASH_VERSION+set}" || ( ECHO='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\' ECHO=$ECHO$ECHO$ECHO$ECHO$ECHO ECHO=$ECHO$ECHO$ECHO$ECHO$ECHO$ECHO PATH=/empty FPATH=/empty; export PATH FPATH test "X`printf %s $ECHO`" = "X$ECHO" \ || test "X`print -r -- $ECHO`" = "X$ECHO" )])]) _LT_DECL([], [SHELL], [1], [Shell to use when invoking shell scripts]) _LT_DECL([], [ECHO], [1], [An echo program that protects backslashes]) ])# _LT_PROG_ECHO_BACKSLASH # _LT_WITH_SYSROOT # ---------------- AC_DEFUN([_LT_WITH_SYSROOT], [m4_require([_LT_DECL_SED])dnl AC_MSG_CHECKING([for sysroot]) AC_ARG_WITH([sysroot], [AS_HELP_STRING([--with-sysroot@<:@=DIR@:>@], [Search for dependent libraries within DIR (or the compiler's sysroot if not specified).])], [], [with_sysroot=no]) dnl lt_sysroot will always be passed unquoted. We quote it here dnl in case the user passed a directory name. lt_sysroot= case $with_sysroot in #( yes) if test yes = "$GCC"; then # Trim trailing / since we'll always append absolute paths and we want # to avoid //, if only for less confusing output for the user. lt_sysroot=`$CC --print-sysroot 2>/dev/null | $SED 's:/\+$::'` fi ;; #( /*) lt_sysroot=`echo "$with_sysroot" | $SED -e "$sed_quote_subst"` ;; #( no|'') ;; #( *) AC_MSG_RESULT([$with_sysroot]) AC_MSG_ERROR([The sysroot must be an absolute path.]) ;; esac AC_MSG_RESULT([${lt_sysroot:-no}]) _LT_DECL([], [lt_sysroot], [0], [The root where to search for ]dnl [dependent libraries, and where our libraries should be installed.])]) # _LT_ENABLE_LOCK # --------------- m4_defun([_LT_ENABLE_LOCK], [AC_ARG_ENABLE([libtool-lock], [AS_HELP_STRING([--disable-libtool-lock], [avoid locking (might break parallel builds)])]) test no = "$enable_libtool_lock" || enable_libtool_lock=yes # Some flags need to be propagated to the compiler or linker for good # libtool support. case $host in ia64-*-hpux*) # Find out what ABI is being produced by ac_compile, and set mode # options accordingly. echo 'int i;' > conftest.$ac_ext if AC_TRY_EVAL(ac_compile); then case `$FILECMD conftest.$ac_objext` in *ELF-32*) HPUX_IA64_MODE=32 ;; *ELF-64*) HPUX_IA64_MODE=64 ;; esac fi rm -rf conftest* ;; *-*-irix6*) # Find out what ABI is being produced by ac_compile, and set linker # options accordingly. echo '[#]line '$LINENO' "configure"' > conftest.$ac_ext if AC_TRY_EVAL(ac_compile); then if test yes = "$lt_cv_prog_gnu_ld"; then case `$FILECMD conftest.$ac_objext` in *32-bit*) LD="${LD-ld} -melf32bsmip" ;; *N32*) LD="${LD-ld} -melf32bmipn32" ;; *64-bit*) LD="${LD-ld} -melf64bmip" ;; esac else case `$FILECMD conftest.$ac_objext` in *32-bit*) LD="${LD-ld} -32" ;; *N32*) LD="${LD-ld} -n32" ;; *64-bit*) LD="${LD-ld} -64" ;; esac fi fi rm -rf conftest* ;; mips64*-*linux*) # Find out what ABI is being produced by ac_compile, and set linker # options accordingly. echo '[#]line '$LINENO' "configure"' > conftest.$ac_ext if AC_TRY_EVAL(ac_compile); then emul=elf case `$FILECMD conftest.$ac_objext` in *32-bit*) emul="${emul}32" ;; *64-bit*) emul="${emul}64" ;; esac case `$FILECMD conftest.$ac_objext` in *MSB*) emul="${emul}btsmip" ;; *LSB*) emul="${emul}ltsmip" ;; esac case `$FILECMD conftest.$ac_objext` in *N32*) emul="${emul}n32" ;; esac LD="${LD-ld} -m $emul" fi rm -rf conftest* ;; x86_64-*kfreebsd*-gnu|x86_64-*linux*|powerpc*-*linux*| \ s390*-*linux*|s390*-*tpf*|sparc*-*linux*|x86_64-gnu*) # Find out what ABI is being produced by ac_compile, and set linker # options accordingly. Note that the listed cases only cover the # situations where additional linker options are needed (such as when # doing 32-bit compilation for a host where ld defaults to 64-bit, or # vice versa); the common cases where no linker options are needed do # not appear in the list. echo 'int i;' > conftest.$ac_ext if AC_TRY_EVAL(ac_compile); then case `$FILECMD conftest.o` in *32-bit*) case $host in x86_64-*kfreebsd*-gnu) LD="${LD-ld} -m elf_i386_fbsd" ;; x86_64-*linux*|x86_64-gnu*) case `$FILECMD conftest.o` in *x86-64*) LD="${LD-ld} -m elf32_x86_64" ;; *) LD="${LD-ld} -m elf_i386" ;; esac ;; powerpc64le-*linux*) LD="${LD-ld} -m elf32lppclinux" ;; powerpc64-*linux*) LD="${LD-ld} -m elf32ppclinux" ;; s390x-*linux*) LD="${LD-ld} -m elf_s390" ;; sparc64-*linux*) LD="${LD-ld} -m elf32_sparc" ;; esac ;; *64-bit*) case $host in x86_64-*kfreebsd*-gnu) LD="${LD-ld} -m elf_x86_64_fbsd" ;; x86_64-*linux*|x86_64-gnu*) LD="${LD-ld} -m elf_x86_64" ;; powerpcle-*linux*) LD="${LD-ld} -m elf64lppc" ;; powerpc-*linux*) LD="${LD-ld} -m elf64ppc" ;; s390*-*linux*|s390*-*tpf*) LD="${LD-ld} -m elf64_s390" ;; sparc*-*linux*) LD="${LD-ld} -m elf64_sparc" ;; esac ;; esac fi rm -rf conftest* ;; *-*-sco3.2v5*) # On SCO OpenServer 5, we need -belf to get full-featured binaries. SAVE_CFLAGS=$CFLAGS CFLAGS="$CFLAGS -belf" AC_CACHE_CHECK([whether the C compiler needs -belf], lt_cv_cc_needs_belf, [AC_LANG_PUSH(C) AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],[[]])],[lt_cv_cc_needs_belf=yes],[lt_cv_cc_needs_belf=no]) AC_LANG_POP]) if test yes != "$lt_cv_cc_needs_belf"; then # this is probably gcc 2.8.0, egcs 1.0 or newer; no need for -belf CFLAGS=$SAVE_CFLAGS fi ;; *-*solaris*) # Find out what ABI is being produced by ac_compile, and set linker # options accordingly. echo 'int i;' > conftest.$ac_ext if AC_TRY_EVAL(ac_compile); then case `$FILECMD conftest.o` in *64-bit*) case $lt_cv_prog_gnu_ld in yes*) case $host in i?86-*-solaris*|x86_64-*-solaris*) LD="${LD-ld} -m elf_x86_64" ;; sparc*-*-solaris*) LD="${LD-ld} -m elf64_sparc" ;; esac # GNU ld 2.21 introduced _sol2 emulations. Use them if available. if ${LD-ld} -V | grep _sol2 >/dev/null 2>&1; then LD=${LD-ld}_sol2 fi ;; *) if ${LD-ld} -64 -r -o conftest2.o conftest.o >/dev/null 2>&1; then LD="${LD-ld} -64" fi ;; esac ;; esac fi rm -rf conftest* ;; esac need_locks=$enable_libtool_lock ])# _LT_ENABLE_LOCK # _LT_PROG_AR # ----------- m4_defun([_LT_PROG_AR], [AC_CHECK_TOOLS(AR, [ar], false) : ${AR=ar} _LT_DECL([], [AR], [1], [The archiver]) # Use ARFLAGS variable as AR's operation code to sync the variable naming with # Automake. If both AR_FLAGS and ARFLAGS are specified, AR_FLAGS should have # higher priority because that's what people were doing historically (setting # ARFLAGS for automake and AR_FLAGS for libtool). FIXME: Make the AR_FLAGS # variable obsoleted/removed. test ${AR_FLAGS+y} || AR_FLAGS=${ARFLAGS-cr} lt_ar_flags=$AR_FLAGS _LT_DECL([], [lt_ar_flags], [0], [Flags to create an archive (by configure)]) # Make AR_FLAGS overridable by 'make ARFLAGS='. Don't try to run-time override # by AR_FLAGS because that was never working and AR_FLAGS is about to die. _LT_DECL([], [AR_FLAGS], [\@S|@{ARFLAGS-"\@S|@lt_ar_flags"}], [Flags to create an archive]) AC_CACHE_CHECK([for archiver @FILE support], [lt_cv_ar_at_file], [lt_cv_ar_at_file=no AC_COMPILE_IFELSE([AC_LANG_PROGRAM], [echo conftest.$ac_objext > conftest.lst lt_ar_try='$AR $AR_FLAGS libconftest.a @conftest.lst >&AS_MESSAGE_LOG_FD' AC_TRY_EVAL([lt_ar_try]) if test 0 -eq "$ac_status"; then # Ensure the archiver fails upon bogus file names. rm -f conftest.$ac_objext libconftest.a AC_TRY_EVAL([lt_ar_try]) if test 0 -ne "$ac_status"; then lt_cv_ar_at_file=@ fi fi rm -f conftest.* libconftest.a ]) ]) if test no = "$lt_cv_ar_at_file"; then archiver_list_spec= else archiver_list_spec=$lt_cv_ar_at_file fi _LT_DECL([], [archiver_list_spec], [1], [How to feed a file listing to the archiver]) ])# _LT_PROG_AR # _LT_CMD_OLD_ARCHIVE # ------------------- m4_defun([_LT_CMD_OLD_ARCHIVE], [_LT_PROG_AR AC_CHECK_TOOL(STRIP, strip, :) test -z "$STRIP" && STRIP=: _LT_DECL([], [STRIP], [1], [A symbol stripping program]) AC_REQUIRE([AC_PROG_RANLIB]) test -z "$RANLIB" && RANLIB=: _LT_DECL([], [RANLIB], [1], [Commands used to install an old-style archive]) # Determine commands to create old-style static archives. old_archive_cmds='$AR $AR_FLAGS $oldlib$oldobjs' old_postinstall_cmds='chmod 644 $oldlib' old_postuninstall_cmds= if test -n "$RANLIB"; then old_archive_cmds="$old_archive_cmds~\$RANLIB \$tool_oldlib" old_postinstall_cmds="$old_postinstall_cmds~\$RANLIB \$tool_oldlib" fi case $host_os in darwin*) lock_old_archive_extraction=yes ;; *) lock_old_archive_extraction=no ;; esac _LT_DECL([], [old_postinstall_cmds], [2]) _LT_DECL([], [old_postuninstall_cmds], [2]) _LT_TAGDECL([], [old_archive_cmds], [2], [Commands used to build an old-style archive]) _LT_DECL([], [lock_old_archive_extraction], [0], [Whether to use a lock for old archive extraction]) ])# _LT_CMD_OLD_ARCHIVE # _LT_COMPILER_OPTION(MESSAGE, VARIABLE-NAME, FLAGS, # [OUTPUT-FILE], [ACTION-SUCCESS], [ACTION-FAILURE]) # ---------------------------------------------------------------- # Check whether the given compiler option works AC_DEFUN([_LT_COMPILER_OPTION], [m4_require([_LT_FILEUTILS_DEFAULTS])dnl m4_require([_LT_DECL_SED])dnl AC_CACHE_CHECK([$1], [$2], [$2=no m4_if([$4], , [ac_outfile=conftest.$ac_objext], [ac_outfile=$4]) echo "$lt_simple_compile_test_code" > conftest.$ac_ext lt_compiler_flag="$3" ## exclude from sc_useless_quotes_in_assignment # Insert the option either (1) after the last *FLAGS variable, or # (2) before a word containing "conftest.", or (3) at the end. # Note that $ac_compile itself does not contain backslashes and begins # with a dollar sign (not a hyphen), so the echo should work correctly. # The option is referenced via a variable to avoid confusing sed. lt_compile=`echo "$ac_compile" | $SED \ -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ -e 's: [[^ ]]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` (eval echo "\"\$as_me:$LINENO: $lt_compile\"" >&AS_MESSAGE_LOG_FD) (eval "$lt_compile" 2>conftest.err) ac_status=$? cat conftest.err >&AS_MESSAGE_LOG_FD echo "$as_me:$LINENO: \$? = $ac_status" >&AS_MESSAGE_LOG_FD if (exit $ac_status) && test -s "$ac_outfile"; then # The compiler can only warn and ignore the option if not recognized # So say no if there are warnings other than the usual output. $ECHO "$_lt_compiler_boilerplate" | $SED '/^$/d' >conftest.exp $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2 if test ! -s conftest.er2 || diff conftest.exp conftest.er2 >/dev/null; then $2=yes fi fi $RM conftest* ]) if test yes = "[$]$2"; then m4_if([$5], , :, [$5]) else m4_if([$6], , :, [$6]) fi ])# _LT_COMPILER_OPTION # Old name: AU_ALIAS([AC_LIBTOOL_COMPILER_OPTION], [_LT_COMPILER_OPTION]) dnl aclocal-1.4 backwards compatibility: dnl AC_DEFUN([AC_LIBTOOL_COMPILER_OPTION], []) # _LT_LINKER_OPTION(MESSAGE, VARIABLE-NAME, FLAGS, # [ACTION-SUCCESS], [ACTION-FAILURE]) # ---------------------------------------------------- # Check whether the given linker option works AC_DEFUN([_LT_LINKER_OPTION], [m4_require([_LT_FILEUTILS_DEFAULTS])dnl m4_require([_LT_DECL_SED])dnl AC_CACHE_CHECK([$1], [$2], [$2=no save_LDFLAGS=$LDFLAGS LDFLAGS="$LDFLAGS $3" echo "$lt_simple_link_test_code" > conftest.$ac_ext if (eval $ac_link 2>conftest.err) && test -s conftest$ac_exeext; then # The linker can only warn and ignore the option if not recognized # So say no if there are warnings if test -s conftest.err; then # Append any errors to the config.log. cat conftest.err 1>&AS_MESSAGE_LOG_FD $ECHO "$_lt_linker_boilerplate" | $SED '/^$/d' > conftest.exp $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2 if diff conftest.exp conftest.er2 >/dev/null; then $2=yes fi else $2=yes fi fi $RM -r conftest* LDFLAGS=$save_LDFLAGS ]) if test yes = "[$]$2"; then m4_if([$4], , :, [$4]) else m4_if([$5], , :, [$5]) fi ])# _LT_LINKER_OPTION # Old name: AU_ALIAS([AC_LIBTOOL_LINKER_OPTION], [_LT_LINKER_OPTION]) dnl aclocal-1.4 backwards compatibility: dnl AC_DEFUN([AC_LIBTOOL_LINKER_OPTION], []) # LT_CMD_MAX_LEN #--------------- AC_DEFUN([LT_CMD_MAX_LEN], [AC_REQUIRE([AC_CANONICAL_HOST])dnl # find the maximum length of command line arguments AC_MSG_CHECKING([the maximum length of command line arguments]) AC_CACHE_VAL([lt_cv_sys_max_cmd_len], [dnl i=0 teststring=ABCD case $build_os in msdosdjgpp*) # On DJGPP, this test can blow up pretty badly due to problems in libc # (any single argument exceeding 2000 bytes causes a buffer overrun # during glob expansion). Even if it were fixed, the result of this # check would be larger than it should be. lt_cv_sys_max_cmd_len=12288; # 12K is about right ;; gnu* | ironclad*) # Under GNU Hurd and Ironclad, this test is not required because there # is no limit to the length of command line arguments. # Libtool will interpret -1 as no limit whatsoever lt_cv_sys_max_cmd_len=-1; ;; cygwin* | mingw* | windows* | cegcc*) # On Win9x/ME, this test blows up -- it succeeds, but takes # about 5 minutes as the teststring grows exponentially. # Worse, since 9x/ME are not pre-emptively multitasking, # you end up with a "frozen" computer, even though with patience # the test eventually succeeds (with a max line length of 256k). # Instead, let's just punt: use the minimum linelength reported by # all of the supported platforms: 8192 (on NT/2K/XP). lt_cv_sys_max_cmd_len=8192; ;; mint*) # On MiNT this can take a long time and run out of memory. lt_cv_sys_max_cmd_len=8192; ;; amigaos*) # On AmigaOS with pdksh, this test takes hours, literally. # So we just punt and use a minimum line length of 8192. lt_cv_sys_max_cmd_len=8192; ;; darwin* | dragonfly* | freebsd* | midnightbsd* | netbsd* | openbsd*) # This has been around since 386BSD, at least. Likely further. if test -x /sbin/sysctl; then lt_cv_sys_max_cmd_len=`/sbin/sysctl -n kern.argmax` elif test -x /usr/sbin/sysctl; then lt_cv_sys_max_cmd_len=`/usr/sbin/sysctl -n kern.argmax` else lt_cv_sys_max_cmd_len=65536 # usable default for all BSDs fi # And add a safety zone lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 4` lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \* 3` ;; interix*) # We know the value 262144 and hardcode it with a safety zone (like BSD) lt_cv_sys_max_cmd_len=196608 ;; os2*) # The test takes a long time on OS/2. lt_cv_sys_max_cmd_len=8192 ;; osf*) # Dr. Hans Ekkehard Plesser reports seeing a kernel panic running configure # due to this test when exec_disable_arg_limit is 1 on Tru64. It is not # nice to cause kernel panics so lets avoid the loop below. # First set a reasonable default. lt_cv_sys_max_cmd_len=16384 # if test -x /sbin/sysconfig; then case `/sbin/sysconfig -q proc exec_disable_arg_limit` in *1*) lt_cv_sys_max_cmd_len=-1 ;; esac fi ;; sco3.2v5*) lt_cv_sys_max_cmd_len=102400 ;; sysv5* | sco5v6* | sysv4.2uw2*) kargmax=`grep ARG_MAX /etc/conf/cf.d/stune 2>/dev/null` if test -n "$kargmax"; then lt_cv_sys_max_cmd_len=`echo $kargmax | $SED 's/.*[[ ]]//'` else lt_cv_sys_max_cmd_len=32768 fi ;; *) lt_cv_sys_max_cmd_len=`(getconf ARG_MAX) 2> /dev/null` if test -n "$lt_cv_sys_max_cmd_len" && \ test undefined != "$lt_cv_sys_max_cmd_len"; then lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 4` lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \* 3` else # Make teststring a little bigger before we do anything with it. # a 1K string should be a reasonable start. for i in 1 2 3 4 5 6 7 8; do teststring=$teststring$teststring done SHELL=${SHELL-${CONFIG_SHELL-/bin/sh}} # If test is not a shell built-in, we'll probably end up computing a # maximum length that is only half of the actual maximum length, but # we can't tell. while { test X`env echo "$teststring$teststring" 2>/dev/null` \ = "X$teststring$teststring"; } >/dev/null 2>&1 && test 17 != "$i" # 1/2 MB should be enough do i=`expr $i + 1` teststring=$teststring$teststring done # Only check the string length outside the loop. lt_cv_sys_max_cmd_len=`expr "X$teststring" : ".*" 2>&1` teststring= # Add a significant safety factor because C++ compilers can tack on # massive amounts of additional arguments before passing them to the # linker. It appears as though 1/2 is a usable value. lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 2` fi ;; esac ]) if test -n "$lt_cv_sys_max_cmd_len"; then AC_MSG_RESULT($lt_cv_sys_max_cmd_len) else AC_MSG_RESULT(none) fi max_cmd_len=$lt_cv_sys_max_cmd_len _LT_DECL([], [max_cmd_len], [0], [What is the maximum length of a command?]) ])# LT_CMD_MAX_LEN # Old name: AU_ALIAS([AC_LIBTOOL_SYS_MAX_CMD_LEN], [LT_CMD_MAX_LEN]) dnl aclocal-1.4 backwards compatibility: dnl AC_DEFUN([AC_LIBTOOL_SYS_MAX_CMD_LEN], []) # _LT_HEADER_DLFCN # ---------------- m4_defun([_LT_HEADER_DLFCN], [AC_CHECK_HEADERS([dlfcn.h], [], [], [AC_INCLUDES_DEFAULT])dnl ])# _LT_HEADER_DLFCN # _LT_TRY_DLOPEN_SELF (ACTION-IF-TRUE, ACTION-IF-TRUE-W-USCORE, # ACTION-IF-FALSE, ACTION-IF-CROSS-COMPILING) # ---------------------------------------------------------------- m4_defun([_LT_TRY_DLOPEN_SELF], [m4_require([_LT_HEADER_DLFCN])dnl if test yes = "$cross_compiling"; then : [$4] else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF [#line $LINENO "configure" #include "confdefs.h" #if HAVE_DLFCN_H #include #endif #include #ifdef RTLD_GLOBAL # define LT_DLGLOBAL RTLD_GLOBAL #else # ifdef DL_GLOBAL # define LT_DLGLOBAL DL_GLOBAL # else # define LT_DLGLOBAL 0 # endif #endif /* We may have to define LT_DLLAZY_OR_NOW in the command line if we find out it does not work in some platform. */ #ifndef LT_DLLAZY_OR_NOW # ifdef RTLD_LAZY # define LT_DLLAZY_OR_NOW RTLD_LAZY # else # ifdef DL_LAZY # define LT_DLLAZY_OR_NOW DL_LAZY # else # ifdef RTLD_NOW # define LT_DLLAZY_OR_NOW RTLD_NOW # else # ifdef DL_NOW # define LT_DLLAZY_OR_NOW DL_NOW # else # define LT_DLLAZY_OR_NOW 0 # endif # endif # endif # endif #endif /* When -fvisibility=hidden is used, assume the code has been annotated correspondingly for the symbols needed. */ #if defined __GNUC__ && (((__GNUC__ == 3) && (__GNUC_MINOR__ >= 3)) || (__GNUC__ > 3)) int fnord (void) __attribute__((visibility("default"))); #endif int fnord (void) { return 42; } int main (void) { void *self = dlopen (0, LT_DLGLOBAL|LT_DLLAZY_OR_NOW); int status = $lt_dlunknown; if (self) { if (dlsym (self,"fnord")) status = $lt_dlno_uscore; else { if (dlsym( self,"_fnord")) status = $lt_dlneed_uscore; else puts (dlerror ()); } /* dlclose (self); */ } else puts (dlerror ()); return status; }] _LT_EOF if AC_TRY_EVAL(ac_link) && test -s "conftest$ac_exeext" 2>/dev/null; then (./conftest; exit; ) >&AS_MESSAGE_LOG_FD 2>/dev/null lt_status=$? case x$lt_status in x$lt_dlno_uscore) $1 ;; x$lt_dlneed_uscore) $2 ;; x$lt_dlunknown|x*) $3 ;; esac else : # compilation failed $3 fi fi rm -fr conftest* ])# _LT_TRY_DLOPEN_SELF # LT_SYS_DLOPEN_SELF # ------------------ AC_DEFUN([LT_SYS_DLOPEN_SELF], [m4_require([_LT_HEADER_DLFCN])dnl if test yes != "$enable_dlopen"; then enable_dlopen=unknown enable_dlopen_self=unknown enable_dlopen_self_static=unknown else lt_cv_dlopen=no lt_cv_dlopen_libs= case $host_os in beos*) lt_cv_dlopen=load_add_on lt_cv_dlopen_libs= lt_cv_dlopen_self=yes ;; mingw* | windows* | pw32* | cegcc*) lt_cv_dlopen=LoadLibrary lt_cv_dlopen_libs= ;; cygwin*) lt_cv_dlopen=dlopen lt_cv_dlopen_libs= ;; darwin*) # if libdl is installed we need to link against it AC_CHECK_LIB([dl], [dlopen], [lt_cv_dlopen=dlopen lt_cv_dlopen_libs=-ldl],[ lt_cv_dlopen=dyld lt_cv_dlopen_libs= lt_cv_dlopen_self=yes ]) ;; tpf*) # Don't try to run any link tests for TPF. We know it's impossible # because TPF is a cross-compiler, and we know how we open DSOs. lt_cv_dlopen=dlopen lt_cv_dlopen_libs= lt_cv_dlopen_self=no ;; *) AC_CHECK_FUNC([shl_load], [lt_cv_dlopen=shl_load], [AC_CHECK_LIB([dld], [shl_load], [lt_cv_dlopen=shl_load lt_cv_dlopen_libs=-ldld], [AC_CHECK_FUNC([dlopen], [lt_cv_dlopen=dlopen], [AC_CHECK_LIB([dl], [dlopen], [lt_cv_dlopen=dlopen lt_cv_dlopen_libs=-ldl], [AC_CHECK_LIB([svld], [dlopen], [lt_cv_dlopen=dlopen lt_cv_dlopen_libs=-lsvld], [AC_CHECK_LIB([dld], [dld_link], [lt_cv_dlopen=dld_link lt_cv_dlopen_libs=-ldld]) ]) ]) ]) ]) ]) ;; esac if test no = "$lt_cv_dlopen"; then enable_dlopen=no else enable_dlopen=yes fi case $lt_cv_dlopen in dlopen) save_CPPFLAGS=$CPPFLAGS test yes = "$ac_cv_header_dlfcn_h" && CPPFLAGS="$CPPFLAGS -DHAVE_DLFCN_H" save_LDFLAGS=$LDFLAGS wl=$lt_prog_compiler_wl eval LDFLAGS=\"\$LDFLAGS $export_dynamic_flag_spec\" save_LIBS=$LIBS LIBS="$lt_cv_dlopen_libs $LIBS" AC_CACHE_CHECK([whether a program can dlopen itself], lt_cv_dlopen_self, [dnl _LT_TRY_DLOPEN_SELF( lt_cv_dlopen_self=yes, lt_cv_dlopen_self=yes, lt_cv_dlopen_self=no, lt_cv_dlopen_self=cross) ]) if test yes = "$lt_cv_dlopen_self"; then wl=$lt_prog_compiler_wl eval LDFLAGS=\"\$LDFLAGS $lt_prog_compiler_static\" AC_CACHE_CHECK([whether a statically linked program can dlopen itself], lt_cv_dlopen_self_static, [dnl _LT_TRY_DLOPEN_SELF( lt_cv_dlopen_self_static=yes, lt_cv_dlopen_self_static=yes, lt_cv_dlopen_self_static=no, lt_cv_dlopen_self_static=cross) ]) fi CPPFLAGS=$save_CPPFLAGS LDFLAGS=$save_LDFLAGS LIBS=$save_LIBS ;; esac case $lt_cv_dlopen_self in yes|no) enable_dlopen_self=$lt_cv_dlopen_self ;; *) enable_dlopen_self=unknown ;; esac case $lt_cv_dlopen_self_static in yes|no) enable_dlopen_self_static=$lt_cv_dlopen_self_static ;; *) enable_dlopen_self_static=unknown ;; esac fi _LT_DECL([dlopen_support], [enable_dlopen], [0], [Whether dlopen is supported]) _LT_DECL([dlopen_self], [enable_dlopen_self], [0], [Whether dlopen of programs is supported]) _LT_DECL([dlopen_self_static], [enable_dlopen_self_static], [0], [Whether dlopen of statically linked programs is supported]) ])# LT_SYS_DLOPEN_SELF # Old name: AU_ALIAS([AC_LIBTOOL_DLOPEN_SELF], [LT_SYS_DLOPEN_SELF]) dnl aclocal-1.4 backwards compatibility: dnl AC_DEFUN([AC_LIBTOOL_DLOPEN_SELF], []) # _LT_COMPILER_C_O([TAGNAME]) # --------------------------- # Check to see if options -c and -o are simultaneously supported by compiler. # This macro does not hard code the compiler like AC_PROG_CC_C_O. m4_defun([_LT_COMPILER_C_O], [m4_require([_LT_DECL_SED])dnl m4_require([_LT_FILEUTILS_DEFAULTS])dnl m4_require([_LT_TAG_COMPILER])dnl AC_CACHE_CHECK([if $compiler supports -c -o file.$ac_objext], [_LT_TAGVAR(lt_cv_prog_compiler_c_o, $1)], [_LT_TAGVAR(lt_cv_prog_compiler_c_o, $1)=no $RM -r conftest 2>/dev/null mkdir conftest cd conftest mkdir out echo "$lt_simple_compile_test_code" > conftest.$ac_ext lt_compiler_flag="-o out/conftest2.$ac_objext" # Insert the option either (1) after the last *FLAGS variable, or # (2) before a word containing "conftest.", or (3) at the end. # Note that $ac_compile itself does not contain backslashes and begins # with a dollar sign (not a hyphen), so the echo should work correctly. lt_compile=`echo "$ac_compile" | $SED \ -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ -e 's: [[^ ]]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` (eval echo "\"\$as_me:$LINENO: $lt_compile\"" >&AS_MESSAGE_LOG_FD) (eval "$lt_compile" 2>out/conftest.err) ac_status=$? cat out/conftest.err >&AS_MESSAGE_LOG_FD echo "$as_me:$LINENO: \$? = $ac_status" >&AS_MESSAGE_LOG_FD if (exit $ac_status) && test -s out/conftest2.$ac_objext then # The compiler can only warn and ignore the option if not recognized # So say no if there are warnings $ECHO "$_lt_compiler_boilerplate" | $SED '/^$/d' > out/conftest.exp $SED '/^$/d; /^ *+/d' out/conftest.err >out/conftest.er2 if test ! -s out/conftest.er2 || diff out/conftest.exp out/conftest.er2 >/dev/null; then _LT_TAGVAR(lt_cv_prog_compiler_c_o, $1)=yes fi fi chmod u+w . 2>&AS_MESSAGE_LOG_FD $RM conftest* # SGI C++ compiler will create directory out/ii_files/ for # template instantiation test -d out/ii_files && $RM out/ii_files/* && rmdir out/ii_files $RM out/* && rmdir out cd .. $RM -r conftest $RM conftest* ]) _LT_TAGDECL([compiler_c_o], [lt_cv_prog_compiler_c_o], [1], [Does compiler simultaneously support -c and -o options?]) ])# _LT_COMPILER_C_O # _LT_COMPILER_FILE_LOCKS([TAGNAME]) # ---------------------------------- # Check to see if we can do hard links to lock some files if needed m4_defun([_LT_COMPILER_FILE_LOCKS], [m4_require([_LT_ENABLE_LOCK])dnl m4_require([_LT_FILEUTILS_DEFAULTS])dnl _LT_COMPILER_C_O([$1]) hard_links=nottested if test no = "$_LT_TAGVAR(lt_cv_prog_compiler_c_o, $1)" && test no != "$need_locks"; then # do not overwrite the value of need_locks provided by the user AC_MSG_CHECKING([if we can lock with hard links]) hard_links=yes $RM conftest* ln conftest.a conftest.b 2>/dev/null && hard_links=no touch conftest.a ln conftest.a conftest.b 2>&5 || hard_links=no ln conftest.a conftest.b 2>/dev/null && hard_links=no AC_MSG_RESULT([$hard_links]) if test no = "$hard_links"; then AC_MSG_WARN(['$CC' does not support '-c -o', so 'make -j' may be unsafe]) need_locks=warn fi else need_locks=no fi _LT_DECL([], [need_locks], [1], [Must we lock files when doing compilation?]) ])# _LT_COMPILER_FILE_LOCKS # _LT_CHECK_OBJDIR # ---------------- m4_defun([_LT_CHECK_OBJDIR], [AC_CACHE_CHECK([for objdir], [lt_cv_objdir], [rm -f .libs 2>/dev/null mkdir .libs 2>/dev/null if test -d .libs; then lt_cv_objdir=.libs else # MS-DOS does not allow filenames that begin with a dot. lt_cv_objdir=_libs fi rmdir .libs 2>/dev/null]) objdir=$lt_cv_objdir _LT_DECL([], [objdir], [0], [The name of the directory that contains temporary libtool files])dnl m4_pattern_allow([LT_OBJDIR])dnl AC_DEFINE_UNQUOTED([LT_OBJDIR], "$lt_cv_objdir/", [Define to the sub-directory where libtool stores uninstalled libraries.]) ])# _LT_CHECK_OBJDIR # _LT_LINKER_HARDCODE_LIBPATH([TAGNAME]) # -------------------------------------- # Check hardcoding attributes. m4_defun([_LT_LINKER_HARDCODE_LIBPATH], [AC_MSG_CHECKING([how to hardcode library paths into programs]) _LT_TAGVAR(hardcode_action, $1)= if test -n "$_LT_TAGVAR(hardcode_libdir_flag_spec, $1)" || test -n "$_LT_TAGVAR(runpath_var, $1)" || test yes = "$_LT_TAGVAR(hardcode_automatic, $1)"; then # We can hardcode non-existent directories. if test no != "$_LT_TAGVAR(hardcode_direct, $1)" && # If the only mechanism to avoid hardcoding is shlibpath_var, we # have to relink, otherwise we might link with an installed library # when we should be linking with a yet-to-be-installed one ## test no != "$_LT_TAGVAR(hardcode_shlibpath_var, $1)" && test no != "$_LT_TAGVAR(hardcode_minus_L, $1)"; then # Linking always hardcodes the temporary library directory. _LT_TAGVAR(hardcode_action, $1)=relink else # We can link without hardcoding, and we can hardcode nonexisting dirs. _LT_TAGVAR(hardcode_action, $1)=immediate fi else # We cannot hardcode anything, or else we can only hardcode existing # directories. _LT_TAGVAR(hardcode_action, $1)=unsupported fi AC_MSG_RESULT([$_LT_TAGVAR(hardcode_action, $1)]) if test relink = "$_LT_TAGVAR(hardcode_action, $1)" || test yes = "$_LT_TAGVAR(inherit_rpath, $1)"; then # Fast installation is not supported enable_fast_install=no elif test yes = "$shlibpath_overrides_runpath" || test no = "$enable_shared"; then # Fast installation is not necessary enable_fast_install=needless fi _LT_TAGDECL([], [hardcode_action], [0], [How to hardcode a shared library path into an executable]) ])# _LT_LINKER_HARDCODE_LIBPATH # _LT_CMD_STRIPLIB # ---------------- m4_defun([_LT_CMD_STRIPLIB], [m4_require([_LT_DECL_EGREP]) striplib= old_striplib= AC_MSG_CHECKING([whether stripping libraries is possible]) if test -z "$STRIP"; then AC_MSG_RESULT([no]) else if $STRIP -V 2>&1 | $GREP "GNU strip" >/dev/null; then old_striplib="$STRIP --strip-debug" striplib="$STRIP --strip-unneeded" AC_MSG_RESULT([yes]) else case $host_os in darwin*) # FIXME - insert some real tests, host_os isn't really good enough striplib="$STRIP -x" old_striplib="$STRIP -S" AC_MSG_RESULT([yes]) ;; freebsd*) if $STRIP -V 2>&1 | $GREP "elftoolchain" >/dev/null; then old_striplib="$STRIP --strip-debug" striplib="$STRIP --strip-unneeded" AC_MSG_RESULT([yes]) else AC_MSG_RESULT([no]) fi ;; *) AC_MSG_RESULT([no]) ;; esac fi fi _LT_DECL([], [old_striplib], [1], [Commands to strip libraries]) _LT_DECL([], [striplib], [1]) ])# _LT_CMD_STRIPLIB # _LT_PREPARE_MUNGE_PATH_LIST # --------------------------- # Make sure func_munge_path_list() is defined correctly. m4_defun([_LT_PREPARE_MUNGE_PATH_LIST], [[# func_munge_path_list VARIABLE PATH # ----------------------------------- # VARIABLE is name of variable containing _space_ separated list of # directories to be munged by the contents of PATH, which is string # having a format: # "DIR[:DIR]:" # string "DIR[ DIR]" will be prepended to VARIABLE # ":DIR[:DIR]" # string "DIR[ DIR]" will be appended to VARIABLE # "DIRP[:DIRP]::[DIRA:]DIRA" # string "DIRP[ DIRP]" will be prepended to VARIABLE and string # "DIRA[ DIRA]" will be appended to VARIABLE # "DIR[:DIR]" # VARIABLE will be replaced by "DIR[ DIR]" func_munge_path_list () { case x@S|@2 in x) ;; *:) eval @S|@1=\"`$ECHO @S|@2 | $SED 's/:/ /g'` \@S|@@S|@1\" ;; x:*) eval @S|@1=\"\@S|@@S|@1 `$ECHO @S|@2 | $SED 's/:/ /g'`\" ;; *::*) eval @S|@1=\"\@S|@@S|@1\ `$ECHO @S|@2 | $SED -e 's/.*:://' -e 's/:/ /g'`\" eval @S|@1=\"`$ECHO @S|@2 | $SED -e 's/::.*//' -e 's/:/ /g'`\ \@S|@@S|@1\" ;; *) eval @S|@1=\"`$ECHO @S|@2 | $SED 's/:/ /g'`\" ;; esac } ]])# _LT_PREPARE_PATH_LIST # _LT_SYS_DYNAMIC_LINKER([TAG]) # ----------------------------- # PORTME Fill in your ld.so characteristics m4_defun([_LT_SYS_DYNAMIC_LINKER], [AC_REQUIRE([AC_CANONICAL_HOST])dnl m4_require([_LT_DECL_EGREP])dnl m4_require([_LT_FILEUTILS_DEFAULTS])dnl m4_require([_LT_DECL_OBJDUMP])dnl m4_require([_LT_DECL_SED])dnl m4_require([_LT_CHECK_SHELL_FEATURES])dnl m4_require([_LT_PREPARE_MUNGE_PATH_LIST])dnl AC_MSG_CHECKING([dynamic linker characteristics]) m4_if([$1], [], [ if test yes = "$GCC"; then case $host_os in darwin*) lt_awk_arg='/^libraries:/,/LR/' ;; *) lt_awk_arg='/^libraries:/' ;; esac case $host_os in mingw* | windows* | cegcc*) lt_sed_strip_eq='s|=\([[A-Za-z]]:\)|\1|g' ;; *) lt_sed_strip_eq='s|=/|/|g' ;; esac lt_search_path_spec=`$CC -print-search-dirs | awk $lt_awk_arg | $SED -e "s/^libraries://" -e $lt_sed_strip_eq` case $lt_search_path_spec in *\;*) # if the path contains ";" then we assume it to be the separator # otherwise default to the standard path separator (i.e. ":") - it is # assumed that no part of a normal pathname contains ";" but that should # okay in the real world where ";" in dirpaths is itself problematic. lt_search_path_spec=`$ECHO "$lt_search_path_spec" | $SED 's/;/ /g'` ;; *) lt_search_path_spec=`$ECHO "$lt_search_path_spec" | $SED "s/$PATH_SEPARATOR/ /g"` ;; esac # Ok, now we have the path, separated by spaces, we can step through it # and add multilib dir if necessary... lt_tmp_lt_search_path_spec= lt_multi_os_dir=/`$CC $CPPFLAGS $CFLAGS $LDFLAGS -print-multi-os-directory 2>/dev/null` # ...but if some path component already ends with the multilib dir we assume # that all is fine and trust -print-search-dirs as is (GCC 4.2? or newer). case "$lt_multi_os_dir; $lt_search_path_spec " in "/; "* | "/.; "* | "/./; "* | *"$lt_multi_os_dir "* | *"$lt_multi_os_dir/ "*) lt_multi_os_dir= ;; esac for lt_sys_path in $lt_search_path_spec; do if test -d "$lt_sys_path$lt_multi_os_dir"; then lt_tmp_lt_search_path_spec="$lt_tmp_lt_search_path_spec $lt_sys_path$lt_multi_os_dir" elif test -n "$lt_multi_os_dir"; then test -d "$lt_sys_path" && \ lt_tmp_lt_search_path_spec="$lt_tmp_lt_search_path_spec $lt_sys_path" fi done lt_search_path_spec=`$ECHO "$lt_tmp_lt_search_path_spec" | awk ' BEGIN {RS = " "; FS = "/|\n";} { lt_foo = ""; lt_count = 0; for (lt_i = NF; lt_i > 0; lt_i--) { if ($lt_i != "" && $lt_i != ".") { if ($lt_i == "..") { lt_count++; } else { if (lt_count == 0) { lt_foo = "/" $lt_i lt_foo; } else { lt_count--; } } } } if (lt_foo != "") { lt_freq[[lt_foo]]++; } if (lt_freq[[lt_foo]] == 1) { print lt_foo; } }'` # AWK program above erroneously prepends '/' to C:/dos/paths # for these hosts. case $host_os in mingw* | windows* | cegcc*) lt_search_path_spec=`$ECHO "$lt_search_path_spec" |\ $SED 's|/\([[A-Za-z]]:\)|\1|g'` ;; esac sys_lib_search_path_spec=`$ECHO "$lt_search_path_spec" | $lt_NL2SP` else sys_lib_search_path_spec="/lib /usr/lib /usr/local/lib" fi]) library_names_spec= libname_spec='lib$name' soname_spec= shrext_cmds=.so postinstall_cmds= postuninstall_cmds= finish_cmds= finish_eval= shlibpath_var= shlibpath_overrides_runpath=unknown version_type=none dynamic_linker="$host_os ld.so" sys_lib_dlsearch_path_spec="/lib /usr/lib" need_lib_prefix=unknown hardcode_into_libs=no # when you set need_version to no, make sure it does not cause -set_version # flags to be left without arguments need_version=unknown AC_ARG_VAR([LT_SYS_LIBRARY_PATH], [User-defined run-time library search path.]) case $host_os in aix3*) version_type=linux # correct to gnu/linux during the next big refactor library_names_spec='$libname$release$shared_ext$versuffix $libname.a' shlibpath_var=LIBPATH # AIX 3 has no versioning support, so we append a major version to the name. soname_spec='$libname$release$shared_ext$major' ;; aix[[4-9]]*) version_type=linux # correct to gnu/linux during the next big refactor need_lib_prefix=no need_version=no hardcode_into_libs=yes if test ia64 = "$host_cpu"; then # AIX 5 supports IA64 library_names_spec='$libname$release$shared_ext$major $libname$release$shared_ext$versuffix $libname$shared_ext' shlibpath_var=LD_LIBRARY_PATH else # With GCC up to 2.95.x, collect2 would create an import file # for dependence libraries. The import file would start with # the line '#! .'. This would cause the generated library to # depend on '.', always an invalid library. This was fixed in # development snapshots of GCC prior to 3.0. case $host_os in aix4 | aix4.[[01]] | aix4.[[01]].*) if { echo '#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 97)' echo ' yes ' echo '#endif'; } | $CC -E - | $GREP yes > /dev/null; then : else can_build_shared=no fi ;; esac # Using Import Files as archive members, it is possible to support # filename-based versioning of shared library archives on AIX. While # this would work for both with and without runtime linking, it will # prevent static linking of such archives. So we do filename-based # shared library versioning with .so extension only, which is used # when both runtime linking and shared linking is enabled. # Unfortunately, runtime linking may impact performance, so we do # not want this to be the default eventually. Also, we use the # versioned .so libs for executables only if there is the -brtl # linker flag in LDFLAGS as well, or --enable-aix-soname=svr4 only. # To allow for filename-based versioning support, we need to create # libNAME.so.V as an archive file, containing: # *) an Import File, referring to the versioned filename of the # archive as well as the shared archive member, telling the # bitwidth (32 or 64) of that shared object, and providing the # list of exported symbols of that shared object, eventually # decorated with the 'weak' keyword # *) the shared object with the F_LOADONLY flag set, to really avoid # it being seen by the linker. # At run time we better use the real file rather than another symlink, # but for link time we create the symlink libNAME.so -> libNAME.so.V case $with_aix_soname,$aix_use_runtimelinking in # AIX (on Power*) has no versioning support, so currently we cannot hardcode correct # soname into executable. Probably we can add versioning support to # collect2, so additional links can be useful in future. aix,yes) # traditional libtool dynamic_linker='AIX unversionable lib.so' # If using run time linking (on AIX 4.2 or later) use lib.so # instead of lib.a to let people know that these are not # typical AIX shared libraries. library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' ;; aix,no) # traditional AIX only dynamic_linker='AIX lib.a[(]lib.so.V[)]' # We preserve .a as extension for shared libraries through AIX4.2 # and later when we are not doing run time linking. library_names_spec='$libname$release.a $libname.a' soname_spec='$libname$release$shared_ext$major' ;; svr4,*) # full svr4 only dynamic_linker="AIX lib.so.V[(]$shared_archive_member_spec.o[)]" library_names_spec='$libname$release$shared_ext$major $libname$shared_ext' # We do not specify a path in Import Files, so LIBPATH fires. shlibpath_overrides_runpath=yes ;; *,yes) # both, prefer svr4 dynamic_linker="AIX lib.so.V[(]$shared_archive_member_spec.o[)], lib.a[(]lib.so.V[)]" library_names_spec='$libname$release$shared_ext$major $libname$shared_ext' # unpreferred sharedlib libNAME.a needs extra handling postinstall_cmds='test -n "$linkname" || linkname="$realname"~func_stripname "" ".so" "$linkname"~$install_shared_prog "$dir/$func_stripname_result.$libext" "$destdir/$func_stripname_result.$libext"~test -z "$tstripme" || test -z "$striplib" || $striplib "$destdir/$func_stripname_result.$libext"' postuninstall_cmds='for n in $library_names $old_library; do :; done~func_stripname "" ".so" "$n"~test "$func_stripname_result" = "$n" || func_append rmfiles " $odir/$func_stripname_result.$libext"' # We do not specify a path in Import Files, so LIBPATH fires. shlibpath_overrides_runpath=yes ;; *,no) # both, prefer aix dynamic_linker="AIX lib.a[(]lib.so.V[)], lib.so.V[(]$shared_archive_member_spec.o[)]" library_names_spec='$libname$release.a $libname.a' soname_spec='$libname$release$shared_ext$major' # unpreferred sharedlib libNAME.so.V and symlink libNAME.so need extra handling postinstall_cmds='test -z "$dlname" || $install_shared_prog $dir/$dlname $destdir/$dlname~test -z "$tstripme" || test -z "$striplib" || $striplib $destdir/$dlname~test -n "$linkname" || linkname=$realname~func_stripname "" ".a" "$linkname"~(cd "$destdir" && $LN_S -f $dlname $func_stripname_result.so)' postuninstall_cmds='test -z "$dlname" || func_append rmfiles " $odir/$dlname"~for n in $old_library $library_names; do :; done~func_stripname "" ".a" "$n"~func_append rmfiles " $odir/$func_stripname_result.so"' ;; esac shlibpath_var=LIBPATH fi ;; amigaos*) case $host_cpu in powerpc) # Since July 2007 AmigaOS4 officially supports .so libraries. # When compiling the executable, add -use-dynld -Lsobjs: to the compileline. library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' ;; m68k) library_names_spec='$libname.ixlibrary $libname.a' # Create ${libname}_ixlibrary.a entries in /sys/libs. finish_eval='for lib in `ls $libdir/*.ixlibrary 2>/dev/null`; do libname=`func_echo_all "$lib" | $SED '\''s%^.*/\([[^/]]*\)\.ixlibrary$%\1%'\''`; $RM /sys/libs/${libname}_ixlibrary.a; $show "cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a"; cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a || exit 1; done' ;; esac ;; beos*) library_names_spec='$libname$shared_ext' dynamic_linker="$host_os ld.so" shlibpath_var=LIBRARY_PATH ;; bsdi[[45]]*) version_type=linux # correct to gnu/linux during the next big refactor need_version=no library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' soname_spec='$libname$release$shared_ext$major' finish_cmds='PATH="\$PATH:/sbin" ldconfig $libdir' shlibpath_var=LD_LIBRARY_PATH sys_lib_search_path_spec="/shlib /usr/lib /usr/X11/lib /usr/contrib/lib /lib /usr/local/lib" sys_lib_dlsearch_path_spec="/shlib /usr/lib /usr/local/lib" # the default ld.so.conf also contains /usr/contrib/lib and # /usr/X11R6/lib (/usr/X11 is a link to /usr/X11R6), but let us allow # libtool to hard-code these into programs ;; cygwin* | mingw* | windows* | pw32* | cegcc*) version_type=windows shrext_cmds=.dll need_version=no need_lib_prefix=no case $GCC,$cc_basename in yes,*) # gcc library_names_spec='$libname.dll.a' # DLL is installed to $(libdir)/../bin by postinstall_cmds # If user builds GCC with multilib enabled, # it should just install on $(libdir) # not on $(libdir)/../bin or 32 bits dlls would override 64 bit ones. if test xyes = x"$multilib"; then postinstall_cmds='base_file=`basename \$file`~ dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\$base_file'\''i; echo \$dlname'\''`~ dldir=$destdir/`dirname \$dlpath`~ $install_prog $dir/$dlname $destdir/$dlname~ chmod a+x $destdir/$dlname~ if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then eval '\''$striplib $destdir/$dlname'\'' || exit \$?; fi' else postinstall_cmds='base_file=`basename \$file`~ dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\$base_file'\''i; echo \$dlname'\''`~ dldir=$destdir/`dirname \$dlpath`~ test -d \$dldir || mkdir -p \$dldir~ $install_prog $dir/$dlname \$dldir/$dlname~ chmod a+x \$dldir/$dlname~ if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then eval '\''$striplib \$dldir/$dlname'\'' || exit \$?; fi' fi postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~ dlpath=$dir/\$dldll~ $RM \$dlpath' shlibpath_overrides_runpath=yes case $host_os in cygwin*) # Cygwin DLLs use 'cyg' prefix rather than 'lib' soname_spec='`echo $libname | $SED -e 's/^lib/cyg/'``echo $release | $SED -e 's/[[.]]/-/g'`$versuffix$shared_ext' m4_if([$1], [],[ sys_lib_search_path_spec="$sys_lib_search_path_spec /usr/lib/w32api"]) ;; mingw* | windows* | cegcc*) # MinGW DLLs use traditional 'lib' prefix soname_spec='$libname`echo $release | $SED -e 's/[[.]]/-/g'`$versuffix$shared_ext' ;; pw32*) # pw32 DLLs use 'pw' prefix rather than 'lib' library_names_spec='`echo $libname | $SED -e 's/^lib/pw/'``echo $release | $SED -e 's/[[.]]/-/g'`$versuffix$shared_ext' ;; esac dynamic_linker='Win32 ld.exe' ;; *,cl* | *,icl*) # Native MSVC or ICC libname_spec='$name' soname_spec='$libname`echo $release | $SED -e 's/[[.]]/-/g'`$versuffix$shared_ext' library_names_spec='$libname.dll.lib' case $build_os in mingw* | windows*) sys_lib_search_path_spec= lt_save_ifs=$IFS IFS=';' for lt_path in $LIB do IFS=$lt_save_ifs # Let DOS variable expansion print the short 8.3 style file name. lt_path=`cd "$lt_path" 2>/dev/null && cmd //C "for %i in (".") do @echo %~si"` sys_lib_search_path_spec="$sys_lib_search_path_spec $lt_path" done IFS=$lt_save_ifs # Convert to MSYS style. sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | $SED -e 's|\\\\|/|g' -e 's| \\([[a-zA-Z]]\\):| /\\1|g' -e 's|^ ||'` ;; cygwin*) # Convert to unix form, then to dos form, then back to unix form # but this time dos style (no spaces!) so that the unix form looks # like /cygdrive/c/PROGRA~1:/cygdr... sys_lib_search_path_spec=`cygpath --path --unix "$LIB"` sys_lib_search_path_spec=`cygpath --path --dos "$sys_lib_search_path_spec" 2>/dev/null` sys_lib_search_path_spec=`cygpath --path --unix "$sys_lib_search_path_spec" | $SED -e "s/$PATH_SEPARATOR/ /g"` ;; *) sys_lib_search_path_spec=$LIB if $ECHO "$sys_lib_search_path_spec" | [$GREP ';[c-zC-Z]:/' >/dev/null]; then # It is most probably a Windows format PATH. sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | $SED -e 's/;/ /g'` else sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | $SED -e "s/$PATH_SEPARATOR/ /g"` fi # FIXME: find the short name or the path components, as spaces are # common. (e.g. "Program Files" -> "PROGRA~1") ;; esac # DLL is installed to $(libdir)/../bin by postinstall_cmds postinstall_cmds='base_file=`basename \$file`~ dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\$base_file'\''i; echo \$dlname'\''`~ dldir=$destdir/`dirname \$dlpath`~ test -d \$dldir || mkdir -p \$dldir~ $install_prog $dir/$dlname \$dldir/$dlname' postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~ dlpath=$dir/\$dldll~ $RM \$dlpath' shlibpath_overrides_runpath=yes dynamic_linker='Win32 link.exe' ;; *) # Assume MSVC and ICC wrapper library_names_spec='$libname`echo $release | $SED -e 's/[[.]]/-/g'`$versuffix$shared_ext $libname.lib' dynamic_linker='Win32 ld.exe' ;; esac # FIXME: first we should search . and the directory the executable is in shlibpath_var=PATH ;; darwin* | rhapsody*) dynamic_linker="$host_os dyld" version_type=darwin need_lib_prefix=no need_version=no library_names_spec='$libname$release$major$shared_ext $libname$shared_ext' soname_spec='$libname$release$major$shared_ext' shlibpath_overrides_runpath=yes shlibpath_var=DYLD_LIBRARY_PATH shrext_cmds='`test .$module = .yes && echo .so || echo .dylib`' m4_if([$1], [],[ sys_lib_search_path_spec="$sys_lib_search_path_spec /usr/local/lib"]) sys_lib_dlsearch_path_spec='/usr/local/lib /lib /usr/lib' ;; dgux*) version_type=linux # correct to gnu/linux during the next big refactor need_lib_prefix=no need_version=no library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' soname_spec='$libname$release$shared_ext$major' shlibpath_var=LD_LIBRARY_PATH ;; freebsd* | dragonfly* | midnightbsd*) # DragonFly does not have aout. When/if they implement a new # versioning mechanism, adjust this. if test -x /usr/bin/objformat; then objformat=`/usr/bin/objformat` else case $host_os in freebsd[[23]].*) objformat=aout ;; *) objformat=elf ;; esac fi version_type=freebsd-$objformat case $version_type in freebsd-elf*) library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' soname_spec='$libname$release$shared_ext$major' need_version=no need_lib_prefix=no ;; freebsd-*) library_names_spec='$libname$release$shared_ext$versuffix $libname$shared_ext$versuffix' need_version=yes ;; esac case $host_cpu in powerpc64) # On FreeBSD bi-arch platforms, a different variable is used for 32-bit # binaries. See . AC_COMPILE_IFELSE( [AC_LANG_SOURCE( [[int test_pointer_size[sizeof (void *) - 5]; ]])], [shlibpath_var=LD_LIBRARY_PATH], [shlibpath_var=LD_32_LIBRARY_PATH]) ;; *) shlibpath_var=LD_LIBRARY_PATH ;; esac case $host_os in freebsd2.*) shlibpath_overrides_runpath=yes ;; freebsd3.[[01]]* | freebsdelf3.[[01]]*) shlibpath_overrides_runpath=yes hardcode_into_libs=yes ;; freebsd3.[[2-9]]* | freebsdelf3.[[2-9]]* | \ freebsd4.[[0-5]] | freebsdelf4.[[0-5]] | freebsd4.1.1 | freebsdelf4.1.1) shlibpath_overrides_runpath=no hardcode_into_libs=yes ;; *) # from 4.6 on, and DragonFly shlibpath_overrides_runpath=yes hardcode_into_libs=yes ;; esac ;; haiku*) version_type=linux # correct to gnu/linux during the next big refactor need_lib_prefix=no need_version=no dynamic_linker="$host_os runtime_loader" library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' soname_spec='$libname$release$shared_ext$major' shlibpath_var=LIBRARY_PATH shlibpath_overrides_runpath=no sys_lib_search_path_spec='/boot/system/non-packaged/develop/lib /boot/system/develop/lib' sys_lib_dlsearch_path_spec='/boot/home/config/non-packaged/lib /boot/home/config/lib /boot/system/non-packaged/lib /boot/system/lib' hardcode_into_libs=no ;; hpux9* | hpux10* | hpux11*) # Give a soname corresponding to the major version so that dld.sl refuses to # link against other versions. version_type=sunos need_lib_prefix=no need_version=no case $host_cpu in ia64*) shrext_cmds='.so' hardcode_into_libs=yes dynamic_linker="$host_os dld.so" shlibpath_var=LD_LIBRARY_PATH shlibpath_overrides_runpath=yes # Unless +noenvvar is specified. library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' soname_spec='$libname$release$shared_ext$major' if test 32 = "$HPUX_IA64_MODE"; then sys_lib_search_path_spec="/usr/lib/hpux32 /usr/local/lib/hpux32 /usr/local/lib" sys_lib_dlsearch_path_spec=/usr/lib/hpux32 else sys_lib_search_path_spec="/usr/lib/hpux64 /usr/local/lib/hpux64" sys_lib_dlsearch_path_spec=/usr/lib/hpux64 fi ;; hppa*64*) shrext_cmds='.sl' hardcode_into_libs=yes dynamic_linker="$host_os dld.sl" shlibpath_var=LD_LIBRARY_PATH # How should we handle SHLIB_PATH shlibpath_overrides_runpath=yes # Unless +noenvvar is specified. library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' soname_spec='$libname$release$shared_ext$major' sys_lib_search_path_spec="/usr/lib/pa20_64 /usr/ccs/lib/pa20_64" sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec ;; *) shrext_cmds='.sl' dynamic_linker="$host_os dld.sl" shlibpath_var=SHLIB_PATH shlibpath_overrides_runpath=no # +s is required to enable SHLIB_PATH library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' soname_spec='$libname$release$shared_ext$major' ;; esac # HP-UX runs *really* slowly unless shared libraries are mode 555, ... postinstall_cmds='chmod 555 $lib' # or fails outright, so override atomically: install_override_mode=555 ;; interix[[3-9]]*) version_type=linux # correct to gnu/linux during the next big refactor need_lib_prefix=no need_version=no library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' soname_spec='$libname$release$shared_ext$major' dynamic_linker='Interix 3.x ld.so.1 (PE, like ELF)' shlibpath_var=LD_LIBRARY_PATH shlibpath_overrides_runpath=no hardcode_into_libs=yes ;; irix5* | irix6* | nonstopux*) case $host_os in nonstopux*) version_type=nonstopux ;; *) if test yes = "$lt_cv_prog_gnu_ld"; then version_type=linux # correct to gnu/linux during the next big refactor else version_type=irix fi ;; esac need_lib_prefix=no need_version=no soname_spec='$libname$release$shared_ext$major' library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$release$shared_ext $libname$shared_ext' case $host_os in irix5* | nonstopux*) libsuff= shlibsuff= ;; *) case $LD in # libtool.m4 will add one of these switches to LD *-32|*"-32 "|*-melf32bsmip|*"-melf32bsmip ") libsuff= shlibsuff= libmagic=32-bit;; *-n32|*"-n32 "|*-melf32bmipn32|*"-melf32bmipn32 ") libsuff=32 shlibsuff=N32 libmagic=N32;; *-64|*"-64 "|*-melf64bmip|*"-melf64bmip ") libsuff=64 shlibsuff=64 libmagic=64-bit;; *) libsuff= shlibsuff= libmagic=never-match;; esac ;; esac shlibpath_var=LD_LIBRARY${shlibsuff}_PATH shlibpath_overrides_runpath=no sys_lib_search_path_spec="/usr/lib$libsuff /lib$libsuff /usr/local/lib$libsuff" sys_lib_dlsearch_path_spec="/usr/lib$libsuff /lib$libsuff" hardcode_into_libs=yes ;; # No shared lib support for Linux oldld, aout, or coff. linux*oldld* | linux*aout* | linux*coff*) dynamic_linker=no ;; linux*android*) version_type=none # Android doesn't support versioned libraries. need_lib_prefix=no need_version=no library_names_spec='$libname$release$shared_ext $libname$shared_ext' soname_spec='$libname$release$shared_ext' finish_cmds= shlibpath_var=LD_LIBRARY_PATH shlibpath_overrides_runpath=yes # This implies no fast_install, which is unacceptable. # Some rework will be needed to allow for fast_install # before this can be enabled. hardcode_into_libs=yes dynamic_linker='Android linker' # -rpath works at least for libraries that are not overridden by # libraries installed in system locations. _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath $wl$libdir' ;; # This must be glibc/ELF. linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*) version_type=linux # correct to gnu/linux during the next big refactor need_lib_prefix=no need_version=no library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' soname_spec='$libname$release$shared_ext$major' finish_cmds='PATH="\$PATH:/sbin" ldconfig -n $libdir' shlibpath_var=LD_LIBRARY_PATH shlibpath_overrides_runpath=no # Some binutils ld are patched to set DT_RUNPATH AC_CACHE_VAL([lt_cv_shlibpath_overrides_runpath], [lt_cv_shlibpath_overrides_runpath=no save_LDFLAGS=$LDFLAGS save_libdir=$libdir eval "libdir=/foo; wl=\"$_LT_TAGVAR(lt_prog_compiler_wl, $1)\"; \ LDFLAGS=\"\$LDFLAGS $_LT_TAGVAR(hardcode_libdir_flag_spec, $1)\"" AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])], [AS_IF([ ($OBJDUMP -p conftest$ac_exeext) 2>/dev/null | grep "RUNPATH.*$libdir" >/dev/null], [lt_cv_shlibpath_overrides_runpath=yes])]) LDFLAGS=$save_LDFLAGS libdir=$save_libdir ]) shlibpath_overrides_runpath=$lt_cv_shlibpath_overrides_runpath # This implies no fast_install, which is unacceptable. # Some rework will be needed to allow for fast_install # before this can be enabled. hardcode_into_libs=yes # Ideally, we could use ldconfig to report *all* directories which are # searched for libraries, however this is still not possible. Aside from not # being certain /sbin/ldconfig is available, command # 'ldconfig -N -X -v | grep ^/' on 64bit Fedora does not report /usr/lib64, # even though it is searched at run-time. Try to do the best guess by # appending ld.so.conf contents (and includes) to the search path. if test -f /etc/ld.so.conf; then lt_ld_extra=`awk '/^include / { system(sprintf("cd /etc; cat %s 2>/dev/null", \[$]2)); skip = 1; } { if (!skip) print \[$]0; skip = 0; }' < /etc/ld.so.conf | $SED -e 's/#.*//;/^[ ]*hwcap[ ]/d;s/[:, ]/ /g;s/=[^=]*$//;s/=[^= ]* / /g;s/"//g;/^$/d' | tr '\n' ' '` sys_lib_dlsearch_path_spec="/lib /usr/lib $lt_ld_extra" fi # We used to test for /lib/ld.so.1 and disable shared libraries on # powerpc, because MkLinux only supported shared libraries with the # GNU dynamic linker. Since this was broken with cross compilers, # most powerpc-linux boxes support dynamic linking these days and # people can always --disable-shared, the test was removed, and we # assume the GNU/Linux dynamic linker is in use. dynamic_linker='GNU/Linux ld.so' ;; netbsdelf*-gnu) version_type=linux need_lib_prefix=no need_version=no library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' soname_spec='$libname$release$shared_ext$major' shlibpath_var=LD_LIBRARY_PATH shlibpath_overrides_runpath=no hardcode_into_libs=yes dynamic_linker='NetBSD ld.elf_so' ;; netbsdelf*-gnu) version_type=linux need_lib_prefix=no need_version=no library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}' soname_spec='${libname}${release}${shared_ext}$major' shlibpath_var=LD_LIBRARY_PATH shlibpath_overrides_runpath=no hardcode_into_libs=yes dynamic_linker='NetBSD ld.elf_so' ;; netbsd*) version_type=sunos need_lib_prefix=no need_version=no if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then library_names_spec='$libname$release$shared_ext$versuffix $libname$shared_ext$versuffix' finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir' dynamic_linker='NetBSD (a.out) ld.so' else library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' soname_spec='$libname$release$shared_ext$major' dynamic_linker='NetBSD ld.elf_so' fi shlibpath_var=LD_LIBRARY_PATH shlibpath_overrides_runpath=yes hardcode_into_libs=yes ;; *-mlibc) version_type=linux # correct to gnu/linux during the next big refactor need_lib_prefix=no need_version=no library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' soname_spec='$libname$release$shared_ext$major' dynamic_linker='mlibc ld.so' shlibpath_var=LD_LIBRARY_PATH shlibpath_overrides_runpath=no hardcode_into_libs=yes ;; newsos6) version_type=linux # correct to gnu/linux during the next big refactor library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' shlibpath_var=LD_LIBRARY_PATH shlibpath_overrides_runpath=yes ;; *nto* | *qnx*) version_type=qnx need_lib_prefix=no need_version=no library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' soname_spec='$libname$release$shared_ext$major' shlibpath_var=LD_LIBRARY_PATH shlibpath_overrides_runpath=no hardcode_into_libs=yes dynamic_linker='ldqnx.so' ;; openbsd*) version_type=sunos sys_lib_dlsearch_path_spec=/usr/lib need_lib_prefix=no if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`"; then need_version=no else need_version=yes fi library_names_spec='$libname$release$shared_ext$versuffix $libname$shared_ext$versuffix' finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir' shlibpath_var=LD_LIBRARY_PATH shlibpath_overrides_runpath=yes ;; os2*) libname_spec='$name' version_type=windows shrext_cmds=.dll need_version=no need_lib_prefix=no # OS/2 can only load a DLL with a base name of 8 characters or less. soname_spec='`test -n "$os2dllname" && libname="$os2dllname"; v=$($ECHO $release$versuffix | tr -d .-); n=$($ECHO $libname | cut -b -$((8 - ${#v})) | tr . _); $ECHO $n$v`$shared_ext' library_names_spec='${libname}_dll.$libext' dynamic_linker='OS/2 ld.exe' shlibpath_var=BEGINLIBPATH sys_lib_search_path_spec="/lib /usr/lib /usr/local/lib" sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec postinstall_cmds='base_file=`basename \$file`~ dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\$base_file'\''i; $ECHO \$dlname'\''`~ dldir=$destdir/`dirname \$dlpath`~ test -d \$dldir || mkdir -p \$dldir~ $install_prog $dir/$dlname \$dldir/$dlname~ chmod a+x \$dldir/$dlname~ if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then eval '\''$striplib \$dldir/$dlname'\'' || exit \$?; fi' postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; $ECHO \$dlname'\''`~ dlpath=$dir/\$dldll~ $RM \$dlpath' ;; osf3* | osf4* | osf5*) version_type=osf need_lib_prefix=no need_version=no soname_spec='$libname$release$shared_ext$major' library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' shlibpath_var=LD_LIBRARY_PATH sys_lib_search_path_spec="/usr/shlib /usr/ccs/lib /usr/lib/cmplrs/cc /usr/lib /usr/local/lib /var/shlib" sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec ;; rdos*) dynamic_linker=no ;; serenity*) version_type=linux # correct to gnu/linux during the next big refactor need_lib_prefix=no need_version=no library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' soname_spec='$libname$release$shared_ext$major' shlibpath_var=LD_LIBRARY_PATH shlibpath_overrides_runpath=no dynamic_linker='SerenityOS LibELF' ;; solaris*) version_type=linux # correct to gnu/linux during the next big refactor need_lib_prefix=no need_version=no library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' soname_spec='$libname$release$shared_ext$major' shlibpath_var=LD_LIBRARY_PATH shlibpath_overrides_runpath=yes hardcode_into_libs=yes # ldd complains unless libraries are executable postinstall_cmds='chmod +x $lib' ;; sunos4*) version_type=sunos library_names_spec='$libname$release$shared_ext$versuffix $libname$shared_ext$versuffix' finish_cmds='PATH="\$PATH:/usr/etc" ldconfig $libdir' shlibpath_var=LD_LIBRARY_PATH shlibpath_overrides_runpath=yes if test yes = "$with_gnu_ld"; then need_lib_prefix=no fi need_version=yes ;; sysv4 | sysv4.3*) version_type=linux # correct to gnu/linux during the next big refactor library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' soname_spec='$libname$release$shared_ext$major' shlibpath_var=LD_LIBRARY_PATH case $host_vendor in sni) shlibpath_overrides_runpath=no need_lib_prefix=no runpath_var=LD_RUN_PATH ;; siemens) need_lib_prefix=no ;; motorola) need_lib_prefix=no need_version=no shlibpath_overrides_runpath=no sys_lib_search_path_spec='/lib /usr/lib /usr/ccs/lib' ;; esac ;; sysv4*MP*) if test -d /usr/nec; then version_type=linux # correct to gnu/linux during the next big refactor library_names_spec='$libname$shared_ext.$versuffix $libname$shared_ext.$major $libname$shared_ext' soname_spec='$libname$shared_ext.$major' shlibpath_var=LD_LIBRARY_PATH fi ;; sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*) version_type=sco need_lib_prefix=no need_version=no library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext $libname$shared_ext' soname_spec='$libname$release$shared_ext$major' shlibpath_var=LD_LIBRARY_PATH shlibpath_overrides_runpath=yes hardcode_into_libs=yes if test yes = "$with_gnu_ld"; then sys_lib_search_path_spec='/usr/local/lib /usr/gnu/lib /usr/ccs/lib /usr/lib /lib' else sys_lib_search_path_spec='/usr/ccs/lib /usr/lib' case $host_os in sco3.2v5*) sys_lib_search_path_spec="$sys_lib_search_path_spec /lib" ;; esac fi sys_lib_dlsearch_path_spec='/usr/lib' ;; tpf*) # TPF is a cross-target only. Preferred cross-host = GNU/Linux. version_type=linux # correct to gnu/linux during the next big refactor need_lib_prefix=no need_version=no library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' shlibpath_var=LD_LIBRARY_PATH shlibpath_overrides_runpath=no hardcode_into_libs=yes ;; uts4*) version_type=linux # correct to gnu/linux during the next big refactor library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' soname_spec='$libname$release$shared_ext$major' shlibpath_var=LD_LIBRARY_PATH ;; emscripten*) version_type=none need_lib_prefix=no need_version=no library_names_spec='$libname$release$shared_ext' soname_spec='$libname$release$shared_ext' finish_cmds= dynamic_linker="Emscripten linker" _LT_COMPILER_PIC($1)='-fPIC' _LT_TAGVAR(archive_cmds, $1)='$CC -sSIDE_MODULE=2 -shared $libobjs $deplibs $compiler_flags -o $lib' _LT_TAGVAR(archive_expsym_cmds, $1)='$SED "s|^|_|" $export_symbols >$output_objdir/$soname.expsym~$CC -sSIDE_MODULE=2 -shared $libobjs $deplibs $compiler_flags -o $lib -s EXPORTED_FUNCTIONS=@$output_objdir/$soname.expsym' _LT_TAGVAR(archive_cmds_need_lc, $1)=no _LT_TAGVAR(no_undefined_flag, $1)= ;; *) dynamic_linker=no ;; esac AC_MSG_RESULT([$dynamic_linker]) test no = "$dynamic_linker" && can_build_shared=no variables_saved_for_relink="PATH $shlibpath_var $runpath_var" if test yes = "$GCC"; then variables_saved_for_relink="$variables_saved_for_relink GCC_EXEC_PREFIX COMPILER_PATH LIBRARY_PATH" fi if test set = "${lt_cv_sys_lib_search_path_spec+set}"; then sys_lib_search_path_spec=$lt_cv_sys_lib_search_path_spec fi if test set = "${lt_cv_sys_lib_dlsearch_path_spec+set}"; then sys_lib_dlsearch_path_spec=$lt_cv_sys_lib_dlsearch_path_spec fi # remember unaugmented sys_lib_dlsearch_path content for libtool script decls... configure_time_dlsearch_path=$sys_lib_dlsearch_path_spec # ... but it needs LT_SYS_LIBRARY_PATH munging for other configure-time code func_munge_path_list sys_lib_dlsearch_path_spec "$LT_SYS_LIBRARY_PATH" # to be used as default LT_SYS_LIBRARY_PATH value in generated libtool configure_time_lt_sys_library_path=$LT_SYS_LIBRARY_PATH _LT_DECL([], [variables_saved_for_relink], [1], [Variables whose values should be saved in libtool wrapper scripts and restored at link time]) _LT_DECL([], [need_lib_prefix], [0], [Do we need the "lib" prefix for modules?]) _LT_DECL([], [need_version], [0], [Do we need a version for libraries?]) _LT_DECL([], [version_type], [0], [Library versioning type]) _LT_DECL([], [runpath_var], [0], [Shared library runtime path variable]) _LT_DECL([], [shlibpath_var], [0],[Shared library path variable]) _LT_DECL([], [shlibpath_overrides_runpath], [0], [Is shlibpath searched before the hard-coded library search path?]) _LT_DECL([], [libname_spec], [1], [Format of library name prefix]) _LT_DECL([], [library_names_spec], [1], [[List of archive names. First name is the real one, the rest are links. The last name is the one that the linker finds with -lNAME]]) _LT_DECL([], [soname_spec], [1], [[The coded name of the library, if different from the real name]]) _LT_DECL([], [install_override_mode], [1], [Permission mode override for installation of shared libraries]) _LT_DECL([], [postinstall_cmds], [2], [Command to use after installation of a shared archive]) _LT_DECL([], [postuninstall_cmds], [2], [Command to use after uninstallation of a shared archive]) _LT_DECL([], [finish_cmds], [2], [Commands used to finish a libtool library installation in a directory]) _LT_DECL([], [finish_eval], [1], [[As "finish_cmds", except a single script fragment to be evaled but not shown]]) _LT_DECL([], [hardcode_into_libs], [0], [Whether we should hardcode library paths into libraries]) _LT_DECL([], [sys_lib_search_path_spec], [2], [Compile-time system search path for libraries]) _LT_DECL([sys_lib_dlsearch_path_spec], [configure_time_dlsearch_path], [2], [Detected run-time system search path for libraries]) _LT_DECL([], [configure_time_lt_sys_library_path], [2], [Explicit LT_SYS_LIBRARY_PATH set during ./configure time]) ])# _LT_SYS_DYNAMIC_LINKER # _LT_PATH_TOOL_PREFIX(TOOL) # -------------------------- # find a file program that can recognize shared library AC_DEFUN([_LT_PATH_TOOL_PREFIX], [m4_require([_LT_DECL_EGREP])dnl AC_MSG_CHECKING([for $1]) AC_CACHE_VAL(lt_cv_path_MAGIC_CMD, [case $MAGIC_CMD in [[\\/*] | ?:[\\/]*]) lt_cv_path_MAGIC_CMD=$MAGIC_CMD # Let the user override the test with a path. ;; *) lt_save_MAGIC_CMD=$MAGIC_CMD lt_save_ifs=$IFS; IFS=$PATH_SEPARATOR dnl $ac_dummy forces splitting on constant user-supplied paths. dnl POSIX.2 word splitting is done only on the output of word expansions, dnl not every word. This closes a longstanding sh security hole. ac_dummy="m4_if([$2], , $PATH, [$2])" for ac_dir in $ac_dummy; do IFS=$lt_save_ifs test -z "$ac_dir" && ac_dir=. if test -f "$ac_dir/$1"; then lt_cv_path_MAGIC_CMD=$ac_dir/"$1" if test -n "$file_magic_test_file"; then case $deplibs_check_method in "file_magic "*) file_magic_regex=`expr "$deplibs_check_method" : "file_magic \(.*\)"` MAGIC_CMD=$lt_cv_path_MAGIC_CMD if eval $file_magic_cmd \$file_magic_test_file 2> /dev/null | $EGREP "$file_magic_regex" > /dev/null; then : else cat <<_LT_EOF 1>&2 *** Warning: the command libtool uses to detect shared libraries, *** $file_magic_cmd, produces output that libtool cannot recognize. *** The result is that libtool may fail to recognize shared libraries *** as such. This will affect the creation of libtool libraries that *** depend on shared libraries, but programs linked with such libtool *** libraries will work regardless of this problem. Nevertheless, you *** may want to report the problem to your system manager and/or to *** bug-libtool@gnu.org _LT_EOF fi ;; esac fi break fi done IFS=$lt_save_ifs MAGIC_CMD=$lt_save_MAGIC_CMD ;; esac]) MAGIC_CMD=$lt_cv_path_MAGIC_CMD if test -n "$MAGIC_CMD"; then AC_MSG_RESULT($MAGIC_CMD) else AC_MSG_RESULT(no) fi _LT_DECL([], [MAGIC_CMD], [0], [Used to examine libraries when file_magic_cmd begins with "file"])dnl ])# _LT_PATH_TOOL_PREFIX # Old name: AU_ALIAS([AC_PATH_TOOL_PREFIX], [_LT_PATH_TOOL_PREFIX]) dnl aclocal-1.4 backwards compatibility: dnl AC_DEFUN([AC_PATH_TOOL_PREFIX], []) # _LT_PATH_MAGIC # -------------- # find a file program that can recognize a shared library m4_defun([_LT_PATH_MAGIC], [_LT_PATH_TOOL_PREFIX(${ac_tool_prefix}file, /usr/bin$PATH_SEPARATOR$PATH) if test -z "$lt_cv_path_MAGIC_CMD"; then if test -n "$ac_tool_prefix"; then _LT_PATH_TOOL_PREFIX(file, /usr/bin$PATH_SEPARATOR$PATH) else MAGIC_CMD=: fi fi ])# _LT_PATH_MAGIC # LT_PATH_LD # ---------- # find the pathname to the GNU or non-GNU linker AC_DEFUN([LT_PATH_LD], [AC_REQUIRE([AC_PROG_CC])dnl AC_REQUIRE([AC_CANONICAL_HOST])dnl AC_REQUIRE([AC_CANONICAL_BUILD])dnl m4_require([_LT_DECL_SED])dnl m4_require([_LT_DECL_EGREP])dnl m4_require([_LT_PROG_ECHO_BACKSLASH])dnl AC_ARG_WITH([gnu-ld], [AS_HELP_STRING([--with-gnu-ld], [assume the C compiler uses GNU ld @<:@default=no@:>@])], [test no = "$withval" || with_gnu_ld=yes], [with_gnu_ld=no])dnl ac_prog=ld if test yes = "$GCC"; then # Check if gcc -print-prog-name=ld gives a path. AC_MSG_CHECKING([for ld used by $CC]) case $host in *-*-mingw* | *-*-windows*) # gcc leaves a trailing carriage return, which upsets mingw ac_prog=`($CC -print-prog-name=ld) 2>&5 | tr -d '\015'` ;; *) ac_prog=`($CC -print-prog-name=ld) 2>&5` ;; esac case $ac_prog in # Accept absolute paths. [[\\/]]* | ?:[[\\/]]*) re_direlt='/[[^/]][[^/]]*/\.\./' # Canonicalize the pathname of ld ac_prog=`$ECHO "$ac_prog"| $SED 's%\\\\%/%g'` while $ECHO "$ac_prog" | $GREP "$re_direlt" > /dev/null 2>&1; do ac_prog=`$ECHO $ac_prog| $SED "s%$re_direlt%/%"` done test -z "$LD" && LD=$ac_prog ;; "") # If it fails, then pretend we aren't using GCC. ac_prog=ld ;; *) # If it is relative, then search for the first ld in PATH. with_gnu_ld=unknown ;; esac elif test yes = "$with_gnu_ld"; then AC_MSG_CHECKING([for GNU ld]) else AC_MSG_CHECKING([for non-GNU ld]) fi AC_CACHE_VAL(lt_cv_path_LD, [if test -z "$LD"; then lt_save_ifs=$IFS; IFS=$PATH_SEPARATOR for ac_dir in $PATH; do IFS=$lt_save_ifs test -z "$ac_dir" && ac_dir=. if test -f "$ac_dir/$ac_prog" || test -f "$ac_dir/$ac_prog$ac_exeext"; then lt_cv_path_LD=$ac_dir/$ac_prog # Check to see if the program is GNU ld. I'd rather use --version, # but apparently some variants of GNU ld only accept -v. # Break only if it was the GNU/non-GNU ld that we prefer. case `"$lt_cv_path_LD" -v 2>&1 &1 conftest.i cat conftest.i conftest.i >conftest2.i : ${lt_DD:=$DD} AC_PATH_PROGS_FEATURE_CHECK([lt_DD], [dd], [if "$ac_path_lt_DD" bs=32 count=1 conftest.out 2>/dev/null; then cmp -s conftest.i conftest.out \ && ac_cv_path_lt_DD="$ac_path_lt_DD" ac_path_lt_DD_found=: fi]) rm -f conftest.i conftest2.i conftest.out]) ])# _LT_PATH_DD # _LT_CMD_TRUNCATE # ---------------- # find command to truncate a binary pipe m4_defun([_LT_CMD_TRUNCATE], [m4_require([_LT_PATH_DD]) AC_CACHE_CHECK([how to truncate binary pipes], [lt_cv_truncate_bin], [printf 0123456789abcdef0123456789abcdef >conftest.i cat conftest.i conftest.i >conftest2.i lt_cv_truncate_bin= if "$ac_cv_path_lt_DD" bs=32 count=1 conftest.out 2>/dev/null; then cmp -s conftest.i conftest.out \ && lt_cv_truncate_bin="$ac_cv_path_lt_DD bs=4096 count=1" fi rm -f conftest.i conftest2.i conftest.out test -z "$lt_cv_truncate_bin" && lt_cv_truncate_bin="$SED -e 4q"]) _LT_DECL([lt_truncate_bin], [lt_cv_truncate_bin], [1], [Command to truncate a binary pipe]) ])# _LT_CMD_TRUNCATE # _LT_CHECK_MAGIC_METHOD # ---------------------- # how to check for library dependencies # -- PORTME fill in with the dynamic library characteristics m4_defun([_LT_CHECK_MAGIC_METHOD], [m4_require([_LT_DECL_EGREP]) m4_require([_LT_DECL_OBJDUMP]) AC_CACHE_CHECK([how to recognize dependent libraries], lt_cv_deplibs_check_method, [lt_cv_file_magic_cmd='$MAGIC_CMD' lt_cv_file_magic_test_file= lt_cv_deplibs_check_method='unknown' # Need to set the preceding variable on all platforms that support # interlibrary dependencies. # 'none' -- dependencies not supported. # 'unknown' -- same as none, but documents that we really don't know. # 'pass_all' -- all dependencies passed with no checks. # 'file_magic [[regex]]' -- check by looking for files in library path # that responds to the $file_magic_cmd with a given extended regex. # If you have 'file' or equivalent on your system and you're not sure # whether 'pass_all' will *always* work, you probably want this one. case $host_os in aix[[4-9]]*) lt_cv_deplibs_check_method=pass_all ;; beos*) lt_cv_deplibs_check_method=pass_all ;; bsdi[[45]]*) lt_cv_deplibs_check_method='file_magic ELF [[0-9]][[0-9]]*-bit [[ML]]SB (shared object|dynamic lib)' lt_cv_file_magic_cmd='$FILECMD -L' lt_cv_file_magic_test_file=/shlib/libc.so ;; cygwin*) # func_win32_libid is a shell function defined in ltmain.sh lt_cv_deplibs_check_method='file_magic ^x86 archive import|^x86 DLL' lt_cv_file_magic_cmd='func_win32_libid' ;; mingw* | windows* | pw32*) # Base MSYS/MinGW do not provide the 'file' command needed by # func_win32_libid shell function, so use a weaker test based on 'objdump', # unless we find 'file', for example because we are cross-compiling. if ( file / ) >/dev/null 2>&1; then lt_cv_deplibs_check_method='file_magic ^x86 archive import|^x86 DLL' lt_cv_file_magic_cmd='func_win32_libid' else # Keep this pattern in sync with the one in func_win32_libid. lt_cv_deplibs_check_method='file_magic file format (pei*-i386(.*architecture: i386)?|pe-arm-wince|pe-x86-64|pe-aarch64)' lt_cv_file_magic_cmd='$OBJDUMP -f' fi ;; cegcc*) # use the weaker test based on 'objdump'. See mingw*. lt_cv_deplibs_check_method='file_magic file format pe-arm-.*little(.*architecture: arm)?' lt_cv_file_magic_cmd='$OBJDUMP -f' ;; darwin* | rhapsody*) lt_cv_deplibs_check_method=pass_all ;; freebsd* | dragonfly* | midnightbsd*) if echo __ELF__ | $CC -E - | $GREP __ELF__ > /dev/null; then case $host_cpu in i*86 ) # Not sure whether the presence of OpenBSD here was a mistake. # Let's accept both of them until this is cleared up. lt_cv_deplibs_check_method='file_magic (FreeBSD|OpenBSD|DragonFly)/i[[3-9]]86 (compact )?demand paged shared library' lt_cv_file_magic_cmd=$FILECMD lt_cv_file_magic_test_file=`echo /usr/lib/libc.so.*` ;; esac else lt_cv_deplibs_check_method=pass_all fi ;; haiku*) lt_cv_deplibs_check_method=pass_all ;; hpux10.20* | hpux11*) lt_cv_file_magic_cmd=$FILECMD case $host_cpu in ia64*) lt_cv_deplibs_check_method='file_magic (s[[0-9]][[0-9]][[0-9]]|ELF-[[0-9]][[0-9]]) shared object file - IA64' lt_cv_file_magic_test_file=/usr/lib/hpux32/libc.so ;; hppa*64*) [lt_cv_deplibs_check_method='file_magic (s[0-9][0-9][0-9]|ELF[ -][0-9][0-9])(-bit)?( [LM]SB)? shared object( file)?[, -]* PA-RISC [0-9]\.[0-9]'] lt_cv_file_magic_test_file=/usr/lib/pa20_64/libc.sl ;; *) lt_cv_deplibs_check_method='file_magic (s[[0-9]][[0-9]][[0-9]]|PA-RISC[[0-9]]\.[[0-9]]) shared library' lt_cv_file_magic_test_file=/usr/lib/libc.sl ;; esac ;; interix[[3-9]]*) # PIC code is broken on Interix 3.x, that's why |\.a not |_pic\.a here lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so|\.a)$' ;; irix5* | irix6* | nonstopux*) case $LD in *-32|*"-32 ") libmagic=32-bit;; *-n32|*"-n32 ") libmagic=N32;; *-64|*"-64 ") libmagic=64-bit;; *) libmagic=never-match;; esac lt_cv_deplibs_check_method=pass_all ;; # This must be glibc/ELF. linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*) lt_cv_deplibs_check_method=pass_all ;; *-mlibc) lt_cv_deplibs_check_method=pass_all ;; netbsd* | netbsdelf*-gnu) if echo __ELF__ | $CC -E - | $GREP __ELF__ > /dev/null; then lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so\.[[0-9]]+\.[[0-9]]+|_pic\.a)$' else lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so|_pic\.a)$' fi ;; newos6*) lt_cv_deplibs_check_method='file_magic ELF [[0-9]][[0-9]]*-bit [[ML]]SB (executable|dynamic lib)' lt_cv_file_magic_cmd=$FILECMD lt_cv_file_magic_test_file=/usr/lib/libnls.so ;; *nto* | *qnx*) lt_cv_deplibs_check_method=pass_all ;; openbsd*) if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`"; then lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so\.[[0-9]]+\.[[0-9]]+|\.so|_pic\.a)$' else lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so\.[[0-9]]+\.[[0-9]]+|_pic\.a)$' fi ;; osf3* | osf4* | osf5*) lt_cv_deplibs_check_method=pass_all ;; rdos*) lt_cv_deplibs_check_method=pass_all ;; serenity*) lt_cv_deplibs_check_method=pass_all ;; solaris*) lt_cv_deplibs_check_method=pass_all ;; sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*) lt_cv_deplibs_check_method=pass_all ;; sysv4 | sysv4.3*) case $host_vendor in motorola) lt_cv_deplibs_check_method='file_magic ELF [[0-9]][[0-9]]*-bit [[ML]]SB (shared object|dynamic lib) M[[0-9]][[0-9]]* Version [[0-9]]' lt_cv_file_magic_test_file=`echo /usr/lib/libc.so*` ;; ncr) lt_cv_deplibs_check_method=pass_all ;; sequent) lt_cv_file_magic_cmd='/bin/file' lt_cv_deplibs_check_method='file_magic ELF [[0-9]][[0-9]]*-bit [[LM]]SB (shared object|dynamic lib )' ;; sni) lt_cv_file_magic_cmd='/bin/file' lt_cv_deplibs_check_method="file_magic ELF [[0-9]][[0-9]]*-bit [[LM]]SB dynamic lib" lt_cv_file_magic_test_file=/lib/libc.so ;; siemens) lt_cv_deplibs_check_method=pass_all ;; pc) lt_cv_deplibs_check_method=pass_all ;; esac ;; tpf*) lt_cv_deplibs_check_method=pass_all ;; os2*) lt_cv_deplibs_check_method=pass_all ;; esac ]) file_magic_glob= want_nocaseglob=no if test "$build" = "$host"; then case $host_os in mingw* | windows* | pw32*) if ( shopt | grep nocaseglob ) >/dev/null 2>&1; then want_nocaseglob=yes else file_magic_glob=`echo aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ | $SED -e "s/\(..\)/s\/[[\1]]\/[[\1]]\/g;/g"` fi ;; esac fi file_magic_cmd=$lt_cv_file_magic_cmd deplibs_check_method=$lt_cv_deplibs_check_method test -z "$deplibs_check_method" && deplibs_check_method=unknown _LT_DECL([], [deplibs_check_method], [1], [Method to check whether dependent libraries are shared objects]) _LT_DECL([], [file_magic_cmd], [1], [Command to use when deplibs_check_method = "file_magic"]) _LT_DECL([], [file_magic_glob], [1], [How to find potential files when deplibs_check_method = "file_magic"]) _LT_DECL([], [want_nocaseglob], [1], [Find potential files using nocaseglob when deplibs_check_method = "file_magic"]) ])# _LT_CHECK_MAGIC_METHOD # LT_PATH_NM # ---------- # find the pathname to a BSD- or MS-compatible name lister AC_DEFUN([LT_PATH_NM], [AC_REQUIRE([AC_PROG_CC])dnl AC_CACHE_CHECK([for BSD- or MS-compatible name lister (nm)], lt_cv_path_NM, [if test -n "$NM"; then # Let the user override the test. lt_cv_path_NM=$NM else lt_nm_to_check=${ac_tool_prefix}nm if test -n "$ac_tool_prefix" && test "$build" = "$host"; then lt_nm_to_check="$lt_nm_to_check nm" fi for lt_tmp_nm in $lt_nm_to_check; do lt_save_ifs=$IFS; IFS=$PATH_SEPARATOR for ac_dir in $PATH /usr/ccs/bin/elf /usr/ccs/bin /usr/ucb /bin; do IFS=$lt_save_ifs test -z "$ac_dir" && ac_dir=. tmp_nm=$ac_dir/$lt_tmp_nm if test -f "$tmp_nm" || test -f "$tmp_nm$ac_exeext"; then # Check to see if the nm accepts a BSD-compat flag. # Adding the 'sed 1q' prevents false positives on HP-UX, which says: # nm: unknown option "B" ignored # Tru64's nm complains that /dev/null is an invalid object file # MSYS converts /dev/null to NUL, MinGW nm treats NUL as empty case $build_os in mingw* | windows*) lt_bad_file=conftest.nm/nofile ;; *) lt_bad_file=/dev/null ;; esac case `"$tmp_nm" -B $lt_bad_file 2>&1 | $SED '1q'` in *$lt_bad_file* | *'Invalid file or object type'*) lt_cv_path_NM="$tmp_nm -B" break 2 ;; *) case `"$tmp_nm" -p /dev/null 2>&1 | $SED '1q'` in */dev/null*) lt_cv_path_NM="$tmp_nm -p" break 2 ;; *) lt_cv_path_NM=${lt_cv_path_NM="$tmp_nm"} # keep the first match, but continue # so that we can try to find one that supports BSD flags ;; esac ;; esac fi done IFS=$lt_save_ifs done : ${lt_cv_path_NM=no} fi]) if test no != "$lt_cv_path_NM"; then NM=$lt_cv_path_NM else # Didn't find any BSD compatible name lister, look for dumpbin. if test -n "$DUMPBIN"; then : # Let the user override the test. else AC_CHECK_TOOLS(DUMPBIN, [dumpbin "link -dump"], :) case `$DUMPBIN -symbols -headers /dev/null 2>&1 | $SED '1q'` in *COFF*) DUMPBIN="$DUMPBIN -symbols -headers" ;; *) DUMPBIN=: ;; esac fi AC_SUBST([DUMPBIN]) if test : != "$DUMPBIN"; then NM=$DUMPBIN fi fi test -z "$NM" && NM=nm AC_SUBST([NM]) _LT_DECL([], [NM], [1], [A BSD- or MS-compatible name lister])dnl AC_CACHE_CHECK([the name lister ($NM) interface], [lt_cv_nm_interface], [lt_cv_nm_interface="BSD nm" echo "int some_variable = 0;" > conftest.$ac_ext (eval echo "\"\$as_me:$LINENO: $ac_compile\"" >&AS_MESSAGE_LOG_FD) (eval "$ac_compile" 2>conftest.err) cat conftest.err >&AS_MESSAGE_LOG_FD (eval echo "\"\$as_me:$LINENO: $NM \\\"conftest.$ac_objext\\\"\"" >&AS_MESSAGE_LOG_FD) (eval "$NM \"conftest.$ac_objext\"" 2>conftest.err > conftest.out) cat conftest.err >&AS_MESSAGE_LOG_FD (eval echo "\"\$as_me:$LINENO: output\"" >&AS_MESSAGE_LOG_FD) cat conftest.out >&AS_MESSAGE_LOG_FD if $GREP 'External.*some_variable' conftest.out > /dev/null; then lt_cv_nm_interface="MS dumpbin" fi rm -f conftest*]) ])# LT_PATH_NM # Old names: AU_ALIAS([AM_PROG_NM], [LT_PATH_NM]) AU_ALIAS([AC_PROG_NM], [LT_PATH_NM]) dnl aclocal-1.4 backwards compatibility: dnl AC_DEFUN([AM_PROG_NM], []) dnl AC_DEFUN([AC_PROG_NM], []) # _LT_CHECK_SHAREDLIB_FROM_LINKLIB # -------------------------------- # how to determine the name of the shared library # associated with a specific link library. # -- PORTME fill in with the dynamic library characteristics m4_defun([_LT_CHECK_SHAREDLIB_FROM_LINKLIB], [m4_require([_LT_DECL_EGREP]) m4_require([_LT_DECL_OBJDUMP]) m4_require([_LT_DECL_DLLTOOL]) AC_CACHE_CHECK([how to associate runtime and link libraries], lt_cv_sharedlib_from_linklib_cmd, [lt_cv_sharedlib_from_linklib_cmd='unknown' case $host_os in cygwin* | mingw* | windows* | pw32* | cegcc*) # two different shell functions defined in ltmain.sh; # decide which one to use based on capabilities of $DLLTOOL case `$DLLTOOL --help 2>&1` in *--identify-strict*) lt_cv_sharedlib_from_linklib_cmd=func_cygming_dll_for_implib ;; *) lt_cv_sharedlib_from_linklib_cmd=func_cygming_dll_for_implib_fallback ;; esac ;; *) # fallback: assume linklib IS sharedlib lt_cv_sharedlib_from_linklib_cmd=$ECHO ;; esac ]) sharedlib_from_linklib_cmd=$lt_cv_sharedlib_from_linklib_cmd test -z "$sharedlib_from_linklib_cmd" && sharedlib_from_linklib_cmd=$ECHO _LT_DECL([], [sharedlib_from_linklib_cmd], [1], [Command to associate shared and link libraries]) ])# _LT_CHECK_SHAREDLIB_FROM_LINKLIB # _LT_PATH_MANIFEST_TOOL # ---------------------- # locate the manifest tool m4_defun([_LT_PATH_MANIFEST_TOOL], [AC_CHECK_TOOL(MANIFEST_TOOL, mt, :) test -z "$MANIFEST_TOOL" && MANIFEST_TOOL=mt AC_CACHE_CHECK([if $MANIFEST_TOOL is a manifest tool], [lt_cv_path_manifest_tool], [lt_cv_path_manifest_tool=no echo "$as_me:$LINENO: $MANIFEST_TOOL '-?'" >&AS_MESSAGE_LOG_FD $MANIFEST_TOOL '-?' 2>conftest.err > conftest.out cat conftest.err >&AS_MESSAGE_LOG_FD if $GREP 'Manifest Tool' conftest.out > /dev/null; then lt_cv_path_manifest_tool=yes fi rm -f conftest*]) if test yes != "$lt_cv_path_manifest_tool"; then MANIFEST_TOOL=: fi _LT_DECL([], [MANIFEST_TOOL], [1], [Manifest tool])dnl ])# _LT_PATH_MANIFEST_TOOL # _LT_DLL_DEF_P([FILE]) # --------------------- # True iff FILE is a Windows DLL '.def' file. # Keep in sync with func_dll_def_p in the libtool script AC_DEFUN([_LT_DLL_DEF_P], [dnl test DEF = "`$SED -n dnl -e '\''s/^[[ ]]*//'\'' dnl Strip leading whitespace -e '\''/^\(;.*\)*$/d'\'' dnl Delete empty lines and comments -e '\''s/^\(EXPORTS\|LIBRARY\)\([[ ]].*\)*$/DEF/p'\'' dnl -e q dnl Only consider the first "real" line $1`" dnl ])# _LT_DLL_DEF_P # LT_LIB_M # -------- # check for math library AC_DEFUN([LT_LIB_M], [AC_REQUIRE([AC_CANONICAL_HOST])dnl LIBM= case $host in *-*-beos* | *-*-cegcc* | *-*-cygwin* | *-*-haiku* | *-*-mingw* | *-*-pw32* | *-*-darwin*) # These system don't have libm, or don't need it ;; *-ncr-sysv4.3*) AC_CHECK_LIB(mw, _mwvalidcheckl, LIBM=-lmw) AC_CHECK_LIB(m, cos, LIBM="$LIBM -lm") ;; *) AC_CHECK_LIB(m, cos, LIBM=-lm) ;; esac AC_SUBST([LIBM]) ])# LT_LIB_M # Old name: AU_ALIAS([AC_CHECK_LIBM], [LT_LIB_M]) dnl aclocal-1.4 backwards compatibility: dnl AC_DEFUN([AC_CHECK_LIBM], []) # _LT_COMPILER_NO_RTTI([TAGNAME]) # ------------------------------- m4_defun([_LT_COMPILER_NO_RTTI], [m4_require([_LT_TAG_COMPILER])dnl _LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)= if test yes = "$GCC"; then case $cc_basename in nvcc*) _LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)=' -Xcompiler -fno-builtin' ;; *) _LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)=' -fno-builtin' ;; esac _LT_COMPILER_OPTION([if $compiler supports -fno-rtti -fno-exceptions], lt_cv_prog_compiler_rtti_exceptions, [-fno-rtti -fno-exceptions], [], [_LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)="$_LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1) -fno-rtti -fno-exceptions"]) fi _LT_TAGDECL([no_builtin_flag], [lt_prog_compiler_no_builtin_flag], [1], [Compiler flag to turn off builtin functions]) ])# _LT_COMPILER_NO_RTTI # _LT_CMD_GLOBAL_SYMBOLS # ---------------------- m4_defun([_LT_CMD_GLOBAL_SYMBOLS], [AC_REQUIRE([AC_CANONICAL_HOST])dnl AC_REQUIRE([AC_PROG_CC])dnl AC_REQUIRE([AC_PROG_AWK])dnl AC_REQUIRE([LT_PATH_NM])dnl AC_REQUIRE([LT_PATH_LD])dnl m4_require([_LT_DECL_SED])dnl m4_require([_LT_DECL_EGREP])dnl m4_require([_LT_TAG_COMPILER])dnl # Check for command to grab the raw symbol name followed by C symbol from nm. AC_MSG_CHECKING([command to parse $NM output from $compiler object]) AC_CACHE_VAL([lt_cv_sys_global_symbol_pipe], [ # These are sane defaults that work on at least a few old systems. # [They come from Ultrix. What could be older than Ultrix?!! ;)] # Character class describing NM global symbol codes. symcode='[[BCDEGRST]]' # Regexp to match symbols that can be accessed directly from C. sympat='\([[_A-Za-z]][[_A-Za-z0-9]]*\)' # Define system-specific variables. case $host_os in aix*) symcode='[[BCDT]]' ;; cygwin* | mingw* | windows* | pw32* | cegcc*) symcode='[[ABCDGISTW]]' ;; hpux*) if test ia64 = "$host_cpu"; then symcode='[[ABCDEGRST]]' fi ;; irix* | nonstopux*) symcode='[[BCDEGRST]]' ;; osf*) symcode='[[BCDEGQRST]]' ;; solaris*) symcode='[[BCDRT]]' ;; sco3.2v5*) symcode='[[DT]]' ;; sysv4.2uw2*) symcode='[[DT]]' ;; sysv5* | sco5v6* | unixware* | OpenUNIX*) symcode='[[ABDT]]' ;; sysv4) symcode='[[DFNSTU]]' ;; esac # If we're using GNU nm, then use its standard symbol codes. case `$NM -V 2>&1` in *GNU* | *'with BFD'*) symcode='[[ABCDGIRSTW]]' ;; esac if test "$lt_cv_nm_interface" = "MS dumpbin"; then # Gets list of data symbols to import. lt_cv_sys_global_symbol_to_import="$SED -n -e 's/^I .* \(.*\)$/\1/p'" # Adjust the below global symbol transforms to fixup imported variables. lt_cdecl_hook=" -e 's/^I .* \(.*\)$/extern __declspec(dllimport) char \1;/p'" lt_c_name_hook=" -e 's/^I .* \(.*\)$/ {\"\1\", (void *) 0},/p'" lt_c_name_lib_hook="\ -e 's/^I .* \(lib.*\)$/ {\"\1\", (void *) 0},/p'\ -e 's/^I .* \(.*\)$/ {\"lib\1\", (void *) 0},/p'" else # Disable hooks by default. lt_cv_sys_global_symbol_to_import= lt_cdecl_hook= lt_c_name_hook= lt_c_name_lib_hook= fi # Transform an extracted symbol line into a proper C declaration. # Some systems (esp. on ia64) link data and code symbols differently, # so use this general approach. lt_cv_sys_global_symbol_to_cdecl="$SED -n"\ $lt_cdecl_hook\ " -e 's/^T .* \(.*\)$/extern int \1();/p'"\ " -e 's/^$symcode$symcode* .* \(.*\)$/extern char \1;/p'" # Transform an extracted symbol line into symbol name and symbol address lt_cv_sys_global_symbol_to_c_name_address="$SED -n"\ $lt_c_name_hook\ " -e 's/^: \(.*\) .*$/ {\"\1\", (void *) 0},/p'"\ " -e 's/^$symcode$symcode* .* \(.*\)$/ {\"\1\", (void *) \&\1},/p'" # Transform an extracted symbol line into symbol name with lib prefix and # symbol address. lt_cv_sys_global_symbol_to_c_name_address_lib_prefix="$SED -n"\ $lt_c_name_lib_hook\ " -e 's/^: \(.*\) .*$/ {\"\1\", (void *) 0},/p'"\ " -e 's/^$symcode$symcode* .* \(lib.*\)$/ {\"\1\", (void *) \&\1},/p'"\ " -e 's/^$symcode$symcode* .* \(.*\)$/ {\"lib\1\", (void *) \&\1},/p'" # Handle CRLF in mingw tool chain opt_cr= case $build_os in mingw* | windows*) opt_cr=`$ECHO 'x\{0,1\}' | tr x '\015'` # option cr in regexp ;; esac # Try without a prefix underscore, then with it. for ac_symprfx in "" "_"; do # Transform symcode, sympat, and symprfx into a raw symbol and a C symbol. symxfrm="\\1 $ac_symprfx\\2 \\2" # Write the raw and C identifiers. if test "$lt_cv_nm_interface" = "MS dumpbin"; then # Fake it for dumpbin and say T for any non-static function, # D for any global variable and I for any imported variable. # Also find C++ and __fastcall symbols from MSVC++ or ICC, # which start with @ or ?. lt_cv_sys_global_symbol_pipe="$AWK ['"\ " {last_section=section; section=\$ 3};"\ " /^COFF SYMBOL TABLE/{for(i in hide) delete hide[i]};"\ " /Section length .*#relocs.*(pick any)/{hide[last_section]=1};"\ " /^ *Symbol name *: /{split(\$ 0,sn,\":\"); si=substr(sn[2],2)};"\ " /^ *Type *: code/{print \"T\",si,substr(si,length(prfx))};"\ " /^ *Type *: data/{print \"I\",si,substr(si,length(prfx))};"\ " \$ 0!~/External *\|/{next};"\ " / 0+ UNDEF /{next}; / UNDEF \([^|]\)*()/{next};"\ " {if(hide[section]) next};"\ " {f=\"D\"}; \$ 0~/\(\).*\|/{f=\"T\"};"\ " {split(\$ 0,a,/\||\r/); split(a[2],s)};"\ " s[1]~/^[@?]/{print f,s[1],s[1]; next};"\ " s[1]~prfx {split(s[1],t,\"@\"); print f,t[1],substr(t[1],length(prfx))}"\ " ' prfx=^$ac_symprfx]" else lt_cv_sys_global_symbol_pipe="$SED -n -e 's/^.*[[ ]]\($symcode$symcode*\)[[ ]][[ ]]*$ac_symprfx$sympat$opt_cr$/$symxfrm/p'" fi lt_cv_sys_global_symbol_pipe="$lt_cv_sys_global_symbol_pipe | $SED '/ __gnu_lto/d'" # Check to see that the pipe works correctly. pipe_works=no rm -f conftest* cat > conftest.$ac_ext <<_LT_EOF #ifdef __cplusplus extern "C" { #endif char nm_test_var; void nm_test_func(void); void nm_test_func(void){} #ifdef __cplusplus } #endif int main(void){nm_test_var='a';nm_test_func();return(0);} _LT_EOF if AC_TRY_EVAL(ac_compile); then # Now try to grab the symbols. nlist=conftest.nm $ECHO "$as_me:$LINENO: $NM conftest.$ac_objext | $lt_cv_sys_global_symbol_pipe > $nlist" >&AS_MESSAGE_LOG_FD if eval "$NM" conftest.$ac_objext \| "$lt_cv_sys_global_symbol_pipe" \> $nlist 2>&AS_MESSAGE_LOG_FD && test -s "$nlist"; then # Try sorting and uniquifying the output. if sort "$nlist" | uniq > "$nlist"T; then mv -f "$nlist"T "$nlist" else rm -f "$nlist"T fi # Make sure that we snagged all the symbols we need. if $GREP ' nm_test_var$' "$nlist" >/dev/null; then if $GREP ' nm_test_func$' "$nlist" >/dev/null; then cat <<_LT_EOF > conftest.$ac_ext /* Keep this code in sync between libtool.m4, ltmain, lt_system.h, and tests. */ #if defined _WIN32 || defined __CYGWIN__ || defined _WIN32_WCE /* DATA imports from DLLs on WIN32 can't be const, because runtime relocations are performed -- see ld's documentation on pseudo-relocs. */ # define LT@&t@_DLSYM_CONST #elif defined __osf__ /* This system does not cope well with relocations in const data. */ # define LT@&t@_DLSYM_CONST #else # define LT@&t@_DLSYM_CONST const #endif #ifdef __cplusplus extern "C" { #endif _LT_EOF # Now generate the symbol file. eval "$lt_cv_sys_global_symbol_to_cdecl"' < "$nlist" | $GREP -v main >> conftest.$ac_ext' cat <<_LT_EOF >> conftest.$ac_ext /* The mapping between symbol names and symbols. */ LT@&t@_DLSYM_CONST struct { const char *name; void *address; } lt__PROGRAM__LTX_preloaded_symbols[[]] = { { "@PROGRAM@", (void *) 0 }, _LT_EOF $SED "s/^$symcode$symcode* .* \(.*\)$/ {\"\1\", (void *) \&\1},/" < "$nlist" | $GREP -v main >> conftest.$ac_ext cat <<\_LT_EOF >> conftest.$ac_ext {0, (void *) 0} }; /* This works around a problem in FreeBSD linker */ #ifdef FREEBSD_WORKAROUND static const void *lt_preloaded_setup() { return lt__PROGRAM__LTX_preloaded_symbols; } #endif #ifdef __cplusplus } #endif _LT_EOF # Now try linking the two files. mv conftest.$ac_objext conftstm.$ac_objext lt_globsym_save_LIBS=$LIBS lt_globsym_save_CFLAGS=$CFLAGS LIBS=conftstm.$ac_objext CFLAGS="$CFLAGS$_LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)" if AC_TRY_EVAL(ac_link) && test -s conftest$ac_exeext; then pipe_works=yes fi LIBS=$lt_globsym_save_LIBS CFLAGS=$lt_globsym_save_CFLAGS else echo "cannot find nm_test_func in $nlist" >&AS_MESSAGE_LOG_FD fi else echo "cannot find nm_test_var in $nlist" >&AS_MESSAGE_LOG_FD fi else echo "cannot run $lt_cv_sys_global_symbol_pipe" >&AS_MESSAGE_LOG_FD fi else echo "$progname: failed program was:" >&AS_MESSAGE_LOG_FD cat conftest.$ac_ext >&5 fi rm -rf conftest* conftst* # Do not use the global_symbol_pipe unless it works. if test yes = "$pipe_works"; then break else lt_cv_sys_global_symbol_pipe= fi done ]) if test -z "$lt_cv_sys_global_symbol_pipe"; then lt_cv_sys_global_symbol_to_cdecl= fi if test -z "$lt_cv_sys_global_symbol_pipe$lt_cv_sys_global_symbol_to_cdecl"; then AC_MSG_RESULT(failed) else AC_MSG_RESULT(ok) fi # Response file support. if test "$lt_cv_nm_interface" = "MS dumpbin"; then nm_file_list_spec='@' elif $NM --help 2>/dev/null | grep '[[@]]FILE' >/dev/null; then nm_file_list_spec='@' fi _LT_DECL([global_symbol_pipe], [lt_cv_sys_global_symbol_pipe], [1], [Take the output of nm and produce a listing of raw symbols and C names]) _LT_DECL([global_symbol_to_cdecl], [lt_cv_sys_global_symbol_to_cdecl], [1], [Transform the output of nm in a proper C declaration]) _LT_DECL([global_symbol_to_import], [lt_cv_sys_global_symbol_to_import], [1], [Transform the output of nm into a list of symbols to manually relocate]) _LT_DECL([global_symbol_to_c_name_address], [lt_cv_sys_global_symbol_to_c_name_address], [1], [Transform the output of nm in a C name address pair]) _LT_DECL([global_symbol_to_c_name_address_lib_prefix], [lt_cv_sys_global_symbol_to_c_name_address_lib_prefix], [1], [Transform the output of nm in a C name address pair when lib prefix is needed]) _LT_DECL([nm_interface], [lt_cv_nm_interface], [1], [The name lister interface]) _LT_DECL([], [nm_file_list_spec], [1], [Specify filename containing input files for $NM]) ]) # _LT_CMD_GLOBAL_SYMBOLS # _LT_COMPILER_PIC([TAGNAME]) # --------------------------- m4_defun([_LT_COMPILER_PIC], [m4_require([_LT_TAG_COMPILER])dnl _LT_TAGVAR(lt_prog_compiler_wl, $1)= _LT_TAGVAR(lt_prog_compiler_pic, $1)= _LT_TAGVAR(lt_prog_compiler_static, $1)= m4_if([$1], [CXX], [ # C++ specific cases for pic, static, wl, etc. if test yes = "$GXX"; then _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' _LT_TAGVAR(lt_prog_compiler_static, $1)='-static' case $host_os in aix*) # All AIX code is PIC. if test ia64 = "$host_cpu"; then # AIX 5 now supports IA64 processor _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' fi _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' ;; amigaos*) case $host_cpu in powerpc) # see comment about AmigaOS4 .so support _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' ;; m68k) # FIXME: we need at least 68020 code to build shared libraries, but # adding the '-m68020' flag to GCC prevents building anything better, # like '-m68040'. _LT_TAGVAR(lt_prog_compiler_pic, $1)='-m68020 -resident32 -malways-restore-a4' ;; esac ;; beos* | irix5* | irix6* | nonstopux* | osf3* | osf4* | osf5*) # PIC is the default for these OSes. ;; mingw* | windows* | cygwin* | os2* | pw32* | cegcc*) # This hack is so that the source file can tell whether it is being # built for inclusion in a dll (and should export symbols for example). # Although the cygwin gcc ignores -fPIC, still need this for old-style # (--disable-auto-import) libraries m4_if([$1], [GCJ], [], [_LT_TAGVAR(lt_prog_compiler_pic, $1)='-DDLL_EXPORT']) case $host_os in os2*) _LT_TAGVAR(lt_prog_compiler_static, $1)='$wl-static' ;; esac ;; darwin* | rhapsody*) # PIC is the default on this platform # Common symbols not allowed in MH_DYLIB files _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fno-common' ;; *djgpp*) # DJGPP does not support shared libraries at all _LT_TAGVAR(lt_prog_compiler_pic, $1)= ;; haiku*) # PIC is the default for Haiku. # The "-static" flag exists, but is broken. _LT_TAGVAR(lt_prog_compiler_static, $1)= ;; interix[[3-9]]*) # Interix 3.x gcc -fpic/-fPIC options generate broken code. # Instead, we relocate shared libraries at runtime. ;; sysv4*MP*) if test -d /usr/nec; then _LT_TAGVAR(lt_prog_compiler_pic, $1)=-Kconform_pic fi ;; hpux*) # PIC is the default for 64-bit PA HP-UX, but not for 32-bit # PA HP-UX. On IA64 HP-UX, PIC is the default but the pic flag # sets the default TLS model and affects inlining. case $host_cpu in hppa*64*) ;; *) _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' ;; esac ;; *qnx* | *nto*) # QNX uses GNU C++, but need to define -shared option too, otherwise # it will coredump. _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC -shared' ;; *) _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' ;; esac else case $host_os in aix[[4-9]]*) # All AIX code is PIC. if test ia64 = "$host_cpu"; then # AIX 5 now supports IA64 processor _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' else _LT_TAGVAR(lt_prog_compiler_static, $1)='-bnso -bI:/lib/syscalls.exp' fi ;; chorus*) case $cc_basename in cxch68*) # Green Hills C++ Compiler # _LT_TAGVAR(lt_prog_compiler_static, $1)="--no_auto_instantiation -u __main -u __premain -u _abort -r $COOL_DIR/lib/libOrb.a $MVME_DIR/lib/CC/libC.a $MVME_DIR/lib/classix/libcx.s.a" ;; esac ;; mingw* | windows* | cygwin* | os2* | pw32* | cegcc*) # This hack is so that the source file can tell whether it is being # built for inclusion in a dll (and should export symbols for example). m4_if([$1], [GCJ], [], [_LT_TAGVAR(lt_prog_compiler_pic, $1)='-DDLL_EXPORT']) ;; dgux*) case $cc_basename in ec++*) _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' ;; ghcx*) # Green Hills C++ Compiler _LT_TAGVAR(lt_prog_compiler_pic, $1)='-pic' ;; *) ;; esac ;; freebsd* | dragonfly* | midnightbsd*) # FreeBSD uses GNU C++ ;; hpux9* | hpux10* | hpux11*) case $cc_basename in CC*) _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' _LT_TAGVAR(lt_prog_compiler_static, $1)='$wl-a ${wl}archive' if test ia64 != "$host_cpu"; then _LT_TAGVAR(lt_prog_compiler_pic, $1)='+Z' fi ;; aCC*) _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' _LT_TAGVAR(lt_prog_compiler_static, $1)='$wl-a ${wl}archive' case $host_cpu in hppa*64*|ia64*) # +Z the default ;; *) _LT_TAGVAR(lt_prog_compiler_pic, $1)='+Z' ;; esac ;; *) ;; esac ;; interix*) # This is c89, which is MS Visual C++ (no shared libs) # Anyone wants to do a port? ;; irix5* | irix6* | nonstopux*) case $cc_basename in CC*) _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared' # CC pic flag -KPIC is the default. ;; *) ;; esac ;; linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*) case $cc_basename in KCC*) # KAI C++ Compiler _LT_TAGVAR(lt_prog_compiler_wl, $1)='--backend -Wl,' _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' ;; ecpc* ) # old Intel C++ for x86_64, which still supported -KPIC. _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' _LT_TAGVAR(lt_prog_compiler_static, $1)='-static' ;; icpc* ) # Intel C++, used to be incompatible with GCC. # ICC 10 doesn't accept -KPIC any more. _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' _LT_TAGVAR(lt_prog_compiler_static, $1)='-static' ;; pgCC* | pgcpp*) # Portland Group C++ compiler _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fpic' _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' ;; cxx*) # Compaq C++ # Make sure the PIC flag is empty. It appears that all Alpha # Linux and Compaq Tru64 Unix objects are PIC. _LT_TAGVAR(lt_prog_compiler_pic, $1)= _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared' ;; xlc* | xlC* | bgxl[[cC]]* | mpixl[[cC]]*) # IBM XL 8.0, 9.0 on PPC and BlueGene _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' _LT_TAGVAR(lt_prog_compiler_pic, $1)='-qpic' _LT_TAGVAR(lt_prog_compiler_static, $1)='-qstaticlink' ;; *) case `$CC -V 2>&1 | $SED 5q` in *Sun\ C*) # Sun C++ 5.9 _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld ' ;; esac ;; esac ;; lynxos*) ;; m88k*) ;; mvs*) case $cc_basename in cxx*) _LT_TAGVAR(lt_prog_compiler_pic, $1)='-W c,exportall' ;; *) ;; esac ;; netbsd* | netbsdelf*-gnu) ;; *-mlibc) ;; *qnx* | *nto*) # QNX uses GNU C++, but need to define -shared option too, otherwise # it will coredump. _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC -shared' ;; osf3* | osf4* | osf5*) case $cc_basename in KCC*) _LT_TAGVAR(lt_prog_compiler_wl, $1)='--backend -Wl,' ;; RCC*) # Rational C++ 2.4.1 _LT_TAGVAR(lt_prog_compiler_pic, $1)='-pic' ;; cxx*) # Digital/Compaq C++ _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' # Make sure the PIC flag is empty. It appears that all Alpha # Linux and Compaq Tru64 Unix objects are PIC. _LT_TAGVAR(lt_prog_compiler_pic, $1)= _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared' ;; *) ;; esac ;; psos*) ;; serenity*) ;; solaris*) case $cc_basename in CC* | sunCC*) # Sun C++ 4.2, 5.x and Centerline C++ _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld ' ;; gcx*) # Green Hills C++ Compiler _LT_TAGVAR(lt_prog_compiler_pic, $1)='-PIC' ;; *) ;; esac ;; sunos4*) case $cc_basename in CC*) # Sun C++ 4.x _LT_TAGVAR(lt_prog_compiler_pic, $1)='-pic' _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' ;; lcc*) # Lucid _LT_TAGVAR(lt_prog_compiler_pic, $1)='-pic' ;; *) ;; esac ;; sysv5* | unixware* | sco3.2v5* | sco5v6* | OpenUNIX*) case $cc_basename in CC*) _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' ;; esac ;; tandem*) case $cc_basename in NCC*) # NonStop-UX NCC 3.20 _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' ;; *) ;; esac ;; vxworks*) ;; *) _LT_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no ;; esac fi ], [ if test yes = "$GCC"; then _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' _LT_TAGVAR(lt_prog_compiler_static, $1)='-static' case $host_os in aix*) # All AIX code is PIC. if test ia64 = "$host_cpu"; then # AIX 5 now supports IA64 processor _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' fi _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' ;; amigaos*) case $host_cpu in powerpc) # see comment about AmigaOS4 .so support _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' ;; m68k) # FIXME: we need at least 68020 code to build shared libraries, but # adding the '-m68020' flag to GCC prevents building anything better, # like '-m68040'. _LT_TAGVAR(lt_prog_compiler_pic, $1)='-m68020 -resident32 -malways-restore-a4' ;; esac ;; beos* | irix5* | irix6* | nonstopux* | osf3* | osf4* | osf5*) # PIC is the default for these OSes. ;; mingw* | windows* | cygwin* | pw32* | os2* | cegcc*) # This hack is so that the source file can tell whether it is being # built for inclusion in a dll (and should export symbols for example). # Although the cygwin gcc ignores -fPIC, still need this for old-style # (--disable-auto-import) libraries m4_if([$1], [GCJ], [], [_LT_TAGVAR(lt_prog_compiler_pic, $1)='-DDLL_EXPORT']) case $host_os in os2*) _LT_TAGVAR(lt_prog_compiler_static, $1)='$wl-static' ;; esac ;; darwin* | rhapsody*) # PIC is the default on this platform # Common symbols not allowed in MH_DYLIB files _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fno-common' ;; haiku*) # PIC is the default for Haiku. # The "-static" flag exists, but is broken. _LT_TAGVAR(lt_prog_compiler_static, $1)= ;; hpux*) # PIC is the default for 64-bit PA HP-UX, but not for 32-bit # PA HP-UX. On IA64 HP-UX, PIC is the default but the pic flag # sets the default TLS model and affects inlining. case $host_cpu in hppa*64*) # +Z the default ;; *) _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' ;; esac ;; interix[[3-9]]*) # Interix 3.x gcc -fpic/-fPIC options generate broken code. # Instead, we relocate shared libraries at runtime. ;; msdosdjgpp*) # Just because we use GCC doesn't mean we suddenly get shared libraries # on systems that don't support them. _LT_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no enable_shared=no ;; *nto* | *qnx*) # QNX uses GNU C++, but need to define -shared option too, otherwise # it will coredump. _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC -shared' ;; sysv4*MP*) if test -d /usr/nec; then _LT_TAGVAR(lt_prog_compiler_pic, $1)=-Kconform_pic fi ;; *) _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' ;; esac case $cc_basename in nvcc*) # Cuda Compiler Driver 2.2 _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Xlinker ' if test -n "$_LT_TAGVAR(lt_prog_compiler_pic, $1)"; then _LT_TAGVAR(lt_prog_compiler_pic, $1)="-Xcompiler $_LT_TAGVAR(lt_prog_compiler_pic, $1)" fi ;; esac else # PORTME Check for flag to pass linker flags through the system compiler. case $host_os in aix*) _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' if test ia64 = "$host_cpu"; then # AIX 5 now supports IA64 processor _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' else _LT_TAGVAR(lt_prog_compiler_static, $1)='-bnso -bI:/lib/syscalls.exp' fi ;; darwin* | rhapsody*) # PIC is the default on this platform # Common symbols not allowed in MH_DYLIB files _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fno-common' case $cc_basename in nagfor*) # NAG Fortran compiler _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,-Wl,,' _LT_TAGVAR(lt_prog_compiler_pic, $1)='-PIC' _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' ;; esac ;; mingw* | windows* | cygwin* | pw32* | os2* | cegcc*) # This hack is so that the source file can tell whether it is being # built for inclusion in a dll (and should export symbols for example). m4_if([$1], [GCJ], [], [_LT_TAGVAR(lt_prog_compiler_pic, $1)='-DDLL_EXPORT']) case $host_os in os2*) _LT_TAGVAR(lt_prog_compiler_static, $1)='$wl-static' ;; esac ;; hpux9* | hpux10* | hpux11*) _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' # PIC is the default for IA64 HP-UX and 64-bit HP-UX, but # not for PA HP-UX. case $host_cpu in hppa*64*|ia64*) # +Z the default ;; *) _LT_TAGVAR(lt_prog_compiler_pic, $1)='+Z' ;; esac # Is there a better lt_prog_compiler_static that works with the bundled CC? _LT_TAGVAR(lt_prog_compiler_static, $1)='$wl-a ${wl}archive' ;; irix5* | irix6* | nonstopux*) _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' # PIC (with -KPIC) is the default. _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared' ;; linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*) case $cc_basename in # old Intel for x86_64, which still supported -KPIC. ecc*) _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' _LT_TAGVAR(lt_prog_compiler_static, $1)='-static' ;; *flang* | ftn | f18* | f95*) # Flang compiler. _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' _LT_TAGVAR(lt_prog_compiler_static, $1)='-static' ;; # flang / f18. f95 an alias for gfortran or flang on Debian flang* | f18* | f95*) _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' _LT_TAGVAR(lt_prog_compiler_static, $1)='-static' ;; # icc used to be incompatible with GCC. # ICC 10 doesn't accept -KPIC any more. icc* | ifort*) _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' _LT_TAGVAR(lt_prog_compiler_static, $1)='-static' ;; # Lahey Fortran 8.1. lf95*) _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' _LT_TAGVAR(lt_prog_compiler_pic, $1)='--shared' _LT_TAGVAR(lt_prog_compiler_static, $1)='--static' ;; nagfor*) # NAG Fortran compiler _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,-Wl,,' _LT_TAGVAR(lt_prog_compiler_pic, $1)='-PIC' _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' ;; tcc*) # Fabrice Bellard et al's Tiny C Compiler _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' _LT_TAGVAR(lt_prog_compiler_static, $1)='-static' ;; pgcc* | pgf77* | pgf90* | pgf95* | pgfortran*) # Portland Group compilers (*not* the Pentium gcc compiler, # which looks to be a dead project) _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fpic' _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' ;; ccc*) _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' # All Alpha code is PIC. _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared' ;; xl* | bgxl* | bgf* | mpixl*) # IBM XL C 8.0/Fortran 10.1, 11.1 on PPC and BlueGene _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' _LT_TAGVAR(lt_prog_compiler_pic, $1)='-qpic' _LT_TAGVAR(lt_prog_compiler_static, $1)='-qstaticlink' ;; *) case `$CC -V 2>&1 | $SED 5q` in *Sun\ Ceres\ Fortran* | *Sun*Fortran*\ [[1-7]].* | *Sun*Fortran*\ 8.[[0-3]]*) # Sun Fortran 8.3 passes all unrecognized flags to the linker _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' _LT_TAGVAR(lt_prog_compiler_wl, $1)='' ;; *Sun\ F* | *Sun*Fortran*) _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld ' ;; *Sun\ C*) # Sun C 5.9 _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' ;; *Intel*\ [[CF]]*Compiler*) _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' _LT_TAGVAR(lt_prog_compiler_static, $1)='-static' ;; *Portland\ Group*) _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fpic' _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' ;; esac ;; esac ;; newsos6) _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' ;; *-mlibc) _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' _LT_TAGVAR(lt_prog_compiler_static, $1)='-static' ;; *nto* | *qnx*) # QNX uses GNU C++, but need to define -shared option too, otherwise # it will coredump. _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC -shared' ;; osf3* | osf4* | osf5*) _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' # All OSF/1 code is PIC. _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared' ;; rdos*) _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared' ;; serenity*) ;; solaris*) _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' case $cc_basename in f77* | f90* | f95* | sunf77* | sunf90* | sunf95*) _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld ';; *) _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,';; esac ;; sunos4*) _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld ' _LT_TAGVAR(lt_prog_compiler_pic, $1)='-PIC' _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' ;; sysv4 | sysv4.2uw2* | sysv4.3*) _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' ;; sysv4*MP*) if test -d /usr/nec; then _LT_TAGVAR(lt_prog_compiler_pic, $1)='-Kconform_pic' _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' fi ;; sysv5* | unixware* | sco3.2v5* | sco5v6* | OpenUNIX*) _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' ;; unicos*) _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' _LT_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no ;; uts4*) _LT_TAGVAR(lt_prog_compiler_pic, $1)='-pic' _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' ;; *) _LT_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no ;; esac fi ]) case $host_os in # For platforms that do not support PIC, -DPIC is meaningless: *djgpp*) _LT_TAGVAR(lt_prog_compiler_pic, $1)= ;; *) _LT_TAGVAR(lt_prog_compiler_pic, $1)="$_LT_TAGVAR(lt_prog_compiler_pic, $1)@&t@m4_if([$1],[],[ -DPIC],[m4_if([$1],[CXX],[ -DPIC],[])])" ;; esac AC_CACHE_CHECK([for $compiler option to produce PIC], [_LT_TAGVAR(lt_cv_prog_compiler_pic, $1)], [_LT_TAGVAR(lt_cv_prog_compiler_pic, $1)=$_LT_TAGVAR(lt_prog_compiler_pic, $1)]) _LT_TAGVAR(lt_prog_compiler_pic, $1)=$_LT_TAGVAR(lt_cv_prog_compiler_pic, $1) # # Check to make sure the PIC flag actually works. # if test -n "$_LT_TAGVAR(lt_prog_compiler_pic, $1)"; then _LT_COMPILER_OPTION([if $compiler PIC flag $_LT_TAGVAR(lt_prog_compiler_pic, $1) works], [_LT_TAGVAR(lt_cv_prog_compiler_pic_works, $1)], [$_LT_TAGVAR(lt_prog_compiler_pic, $1)@&t@m4_if([$1],[],[ -DPIC],[m4_if([$1],[CXX],[ -DPIC],[])])], [], [case $_LT_TAGVAR(lt_prog_compiler_pic, $1) in "" | " "*) ;; *) _LT_TAGVAR(lt_prog_compiler_pic, $1)=" $_LT_TAGVAR(lt_prog_compiler_pic, $1)" ;; esac], [_LT_TAGVAR(lt_prog_compiler_pic, $1)= _LT_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no]) fi _LT_TAGDECL([pic_flag], [lt_prog_compiler_pic], [1], [Additional compiler flags for building library objects]) _LT_TAGDECL([wl], [lt_prog_compiler_wl], [1], [How to pass a linker flag through the compiler]) # # Check to make sure the static flag actually works. # wl=$_LT_TAGVAR(lt_prog_compiler_wl, $1) eval lt_tmp_static_flag=\"$_LT_TAGVAR(lt_prog_compiler_static, $1)\" _LT_LINKER_OPTION([if $compiler static flag $lt_tmp_static_flag works], _LT_TAGVAR(lt_cv_prog_compiler_static_works, $1), $lt_tmp_static_flag, [], [_LT_TAGVAR(lt_prog_compiler_static, $1)=]) _LT_TAGDECL([link_static_flag], [lt_prog_compiler_static], [1], [Compiler flag to prevent dynamic linking]) ])# _LT_COMPILER_PIC # _LT_LINKER_SHLIBS([TAGNAME]) # ---------------------------- # See if the linker supports building shared libraries. m4_defun([_LT_LINKER_SHLIBS], [AC_REQUIRE([LT_PATH_LD])dnl AC_REQUIRE([LT_PATH_NM])dnl m4_require([_LT_PATH_MANIFEST_TOOL])dnl m4_require([_LT_FILEUTILS_DEFAULTS])dnl m4_require([_LT_DECL_EGREP])dnl m4_require([_LT_DECL_SED])dnl m4_require([_LT_CMD_GLOBAL_SYMBOLS])dnl m4_require([_LT_TAG_COMPILER])dnl AC_MSG_CHECKING([whether the $compiler linker ($LD) supports shared libraries]) m4_if([$1], [CXX], [ _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols' _LT_TAGVAR(exclude_expsyms, $1)=['_GLOBAL_OFFSET_TABLE_|_GLOBAL__F[ID]_.*'] case $host_os in aix[[4-9]]*) # If we're using GNU nm, then we don't want the "-C" option. # -C means demangle to GNU nm, but means don't demangle to AIX nm. # Without the "-l" option, or with the "-B" option, AIX nm treats # weak defined symbols like other global defined symbols, whereas # GNU nm marks them as "W". # While the 'weak' keyword is ignored in the Export File, we need # it in the Import File for the 'aix-soname' feature, so we have # to replace the "-B" option with "-P" for AIX nm. if $NM -V 2>&1 | $GREP 'GNU' > /dev/null; then _LT_TAGVAR(export_symbols_cmds, $1)='$NM -Bpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B") || (\$ 2 == "W")) && ([substr](\$ 3,1,1) != ".")) { if (\$ 2 == "W") { print \$ 3 " weak" } else { print \$ 3 } } }'\'' | sort -u > $export_symbols' else _LT_TAGVAR(export_symbols_cmds, $1)='`func_echo_all $NM | $SED -e '\''s/B\([[^B]]*\)$/P\1/'\''` -PCpgl $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B") || (\$ 2 == "L") || (\$ 2 == "W") || (\$ 2 == "V") || (\$ 2 == "Z")) && ([substr](\$ 1,1,1) != ".")) { if ((\$ 2 == "W") || (\$ 2 == "V") || (\$ 2 == "Z")) { print \$ 1 " weak" } else { print \$ 1 } } }'\'' | sort -u > $export_symbols' fi ;; pw32*) _LT_TAGVAR(export_symbols_cmds, $1)=$ltdll_cmds ;; cygwin* | mingw* | windows* | cegcc*) case $cc_basename in cl* | icl*) _LT_TAGVAR(exclude_expsyms, $1)='_NULL_IMPORT_DESCRIPTOR|_IMPORT_DESCRIPTOR_.*' ;; *) _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[[BCDGRS]][[ ]]/s/.*[[ ]]\([[^ ]]*\)/\1 DATA/;s/^.*[[ ]]__nm__\([[^ ]]*\)[[ ]][[^ ]]*/\1 DATA/;/^I[[ ]]/d;/^[[AITW]][[ ]]/s/.* //'\'' | sort | uniq > $export_symbols' _LT_TAGVAR(exclude_expsyms, $1)=['[_]+GLOBAL_OFFSET_TABLE_|[_]+GLOBAL__[FID]_.*|[_]+head_[A-Za-z0-9_]+_dll|[A-Za-z0-9_]+_dll_iname'] ;; esac ;; linux* | k*bsd*-gnu | gnu*) _LT_TAGVAR(link_all_deplibs, $1)=no ;; *) _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols' ;; esac ], [ runpath_var= _LT_TAGVAR(allow_undefined_flag, $1)= _LT_TAGVAR(always_export_symbols, $1)=no _LT_TAGVAR(archive_cmds, $1)= _LT_TAGVAR(archive_expsym_cmds, $1)= _LT_TAGVAR(compiler_needs_object, $1)=no _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=no _LT_TAGVAR(export_dynamic_flag_spec, $1)= _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols' _LT_TAGVAR(hardcode_automatic, $1)=no _LT_TAGVAR(hardcode_direct, $1)=no _LT_TAGVAR(hardcode_direct_absolute, $1)=no _LT_TAGVAR(hardcode_libdir_flag_spec, $1)= _LT_TAGVAR(hardcode_libdir_separator, $1)= _LT_TAGVAR(hardcode_minus_L, $1)=no _LT_TAGVAR(hardcode_shlibpath_var, $1)=unsupported _LT_TAGVAR(inherit_rpath, $1)=no _LT_TAGVAR(link_all_deplibs, $1)=unknown _LT_TAGVAR(module_cmds, $1)= _LT_TAGVAR(module_expsym_cmds, $1)= _LT_TAGVAR(old_archive_from_new_cmds, $1)= _LT_TAGVAR(old_archive_from_expsyms_cmds, $1)= _LT_TAGVAR(thread_safe_flag_spec, $1)= _LT_TAGVAR(whole_archive_flag_spec, $1)= # include_expsyms should be a list of space-separated symbols to be *always* # included in the symbol list _LT_TAGVAR(include_expsyms, $1)= # exclude_expsyms can be an extended regexp of symbols to exclude # it will be wrapped by ' (' and ')$', so one must not match beginning or # end of line. Example: 'a|bc|.*d.*' will exclude the symbols 'a' and 'bc', # as well as any symbol that contains 'd'. _LT_TAGVAR(exclude_expsyms, $1)=['_GLOBAL_OFFSET_TABLE_|_GLOBAL__F[ID]_.*'] # Although _GLOBAL_OFFSET_TABLE_ is a valid symbol C name, most a.out # platforms (ab)use it in PIC code, but their linkers get confused if # the symbol is explicitly referenced. Since portable code cannot # rely on this symbol name, it's probably fine to never include it in # preloaded symbol tables. # Exclude shared library initialization/finalization symbols. dnl Note also adjust exclude_expsyms for C++ above. extract_expsyms_cmds= case $host_os in cygwin* | mingw* | windows* | pw32* | cegcc*) # FIXME: the MSVC++ and ICC port hasn't been tested in a loooong time # When not using gcc, we currently assume that we are using # Microsoft Visual C++ or Intel C++ Compiler. if test yes != "$GCC"; then with_gnu_ld=no fi ;; interix*) # we just hope/assume this is gcc and not c89 (= MSVC++ or ICC) with_gnu_ld=yes ;; linux* | k*bsd*-gnu | gnu*) _LT_TAGVAR(link_all_deplibs, $1)=no ;; esac _LT_TAGVAR(ld_shlibs, $1)=yes # On some targets, GNU ld is compatible enough with the native linker # that we're better off using the native interface for both. lt_use_gnu_ld_interface=no if test yes = "$with_gnu_ld"; then case $host_os in aix*) # The AIX port of GNU ld has always aspired to compatibility # with the native linker. However, as the warning in the GNU ld # block says, versions before 2.19.5* couldn't really create working # shared libraries, regardless of the interface used. case `$LD -v 2>&1` in *\ \(GNU\ Binutils\)\ 2.19.5*) ;; *\ \(GNU\ Binutils\)\ 2.[[2-9]]*) ;; *\ \(GNU\ Binutils\)\ [[3-9]]*) ;; *) lt_use_gnu_ld_interface=yes ;; esac ;; *) lt_use_gnu_ld_interface=yes ;; esac fi if test yes = "$lt_use_gnu_ld_interface"; then # If archive_cmds runs LD, not CC, wlarc should be empty wlarc='$wl' # Set some defaults for GNU ld with shared library support. These # are reset later if shared libraries are not supported. Putting them # here allows them to be overridden if necessary. runpath_var=LD_RUN_PATH _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath $wl$libdir' _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl--export-dynamic' # ancient GNU ld didn't support --whole-archive et. al. if $LD --help 2>&1 | $GREP 'no-whole-archive' > /dev/null; then _LT_TAGVAR(whole_archive_flag_spec, $1)=$wlarc'--whole-archive$convenience '$wlarc'--no-whole-archive' else _LT_TAGVAR(whole_archive_flag_spec, $1)= fi supports_anon_versioning=no case `$LD -v | $SED -e 's/([[^)]]\+)\s\+//' 2>&1` in *GNU\ gold*) supports_anon_versioning=yes ;; *\ [[01]].* | *\ 2.[[0-9]].* | *\ 2.10.*) ;; # catch versions < 2.11 *\ 2.11.93.0.2\ *) supports_anon_versioning=yes ;; # RH7.3 ... *\ 2.11.92.0.12\ *) supports_anon_versioning=yes ;; # Mandrake 8.2 ... *\ 2.11.*) ;; # other 2.11 versions *) supports_anon_versioning=yes ;; esac # See if GNU ld supports shared libraries. case $host_os in aix[[3-9]]*) # On AIX/PPC, the GNU linker is very broken if test ia64 != "$host_cpu"; then _LT_TAGVAR(ld_shlibs, $1)=no cat <<_LT_EOF 1>&2 *** Warning: the GNU linker, at least up to release 2.19, is reported *** to be unable to reliably create shared libraries on AIX. *** Therefore, libtool is disabling shared libraries support. If you *** really care for shared libraries, you may want to install binutils *** 2.20 or above, or modify your PATH so that a non-GNU linker is found. *** You will then need to restart the configuration process. _LT_EOF fi ;; amigaos*) case $host_cpu in powerpc) # see comment about AmigaOS4 .so support _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' _LT_TAGVAR(archive_expsym_cmds, $1)='' ;; m68k) _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/a2ixlibrary.data~$ECHO "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$ECHO "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$ECHO "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$ECHO "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)' _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' _LT_TAGVAR(hardcode_minus_L, $1)=yes ;; esac ;; beos*) if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then _LT_TAGVAR(allow_undefined_flag, $1)=unsupported # Joseph Beckenbach says some releases of gcc # support --undefined. This deserves some investigation. FIXME _LT_TAGVAR(archive_cmds, $1)='$CC -nostart $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' else _LT_TAGVAR(ld_shlibs, $1)=no fi ;; cygwin* | mingw* | windows* | pw32* | cegcc*) # _LT_TAGVAR(hardcode_libdir_flag_spec, $1) is actually meaningless, # as there is no search path for DLLs. _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl--export-all-symbols' _LT_TAGVAR(allow_undefined_flag, $1)=unsupported _LT_TAGVAR(always_export_symbols, $1)=no _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[[BCDGRS]][[ ]]/s/.*[[ ]]\([[^ ]]*\)/\1 DATA/;s/^.*[[ ]]__nm__\([[^ ]]*\)[[ ]][[^ ]]*/\1 DATA/;/^I[[ ]]/d;/^[[AITW]][[ ]]/s/.* //'\'' | sort | uniq > $export_symbols' _LT_TAGVAR(exclude_expsyms, $1)=['[_]+GLOBAL_OFFSET_TABLE_|[_]+GLOBAL__[FID]_.*|[_]+head_[A-Za-z0-9_]+_dll|[A-Za-z0-9_]+_dll_iname'] _LT_TAGVAR(file_list_spec, $1)='@' if $LD --help 2>&1 | $GREP 'auto-import' > /dev/null; then _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags -o $output_objdir/$soname $wl--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib' # If the export-symbols file already is a .def file, use it as # is; otherwise, prepend EXPORTS... _LT_TAGVAR(archive_expsym_cmds, $1)='if _LT_DLL_DEF_P([$export_symbols]); then cp $export_symbols $output_objdir/$soname.def; else echo EXPORTS > $output_objdir/$soname.def; cat $export_symbols >> $output_objdir/$soname.def; fi~ $CC -shared $output_objdir/$soname.def $libobjs $deplibs $compiler_flags -o $output_objdir/$soname $wl--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib' else _LT_TAGVAR(ld_shlibs, $1)=no fi ;; haiku*) _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' _LT_TAGVAR(link_all_deplibs, $1)=no ;; os2*) _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' _LT_TAGVAR(hardcode_minus_L, $1)=yes _LT_TAGVAR(allow_undefined_flag, $1)=unsupported shrext_cmds=.dll _LT_TAGVAR(archive_cmds, $1)='$ECHO "LIBRARY ${soname%$shared_ext} INITINSTANCE TERMINSTANCE" > $output_objdir/$libname.def~ $ECHO "DESCRIPTION \"$libname\"" >> $output_objdir/$libname.def~ $ECHO "DATA MULTIPLE NONSHARED" >> $output_objdir/$libname.def~ $ECHO EXPORTS >> $output_objdir/$libname.def~ emxexp $libobjs | $SED /"_DLL_InitTerm"/d >> $output_objdir/$libname.def~ $CC -Zdll -Zcrtdll -o $output_objdir/$soname $libobjs $deplibs $compiler_flags $output_objdir/$libname.def~ emximp -o $lib $output_objdir/$libname.def' _LT_TAGVAR(archive_expsym_cmds, $1)='$ECHO "LIBRARY ${soname%$shared_ext} INITINSTANCE TERMINSTANCE" > $output_objdir/$libname.def~ $ECHO "DESCRIPTION \"$libname\"" >> $output_objdir/$libname.def~ $ECHO "DATA MULTIPLE NONSHARED" >> $output_objdir/$libname.def~ $ECHO EXPORTS >> $output_objdir/$libname.def~ prefix_cmds="$SED"~ if test EXPORTS = "`$SED 1q $export_symbols`"; then prefix_cmds="$prefix_cmds -e 1d"; fi~ prefix_cmds="$prefix_cmds -e \"s/^\(.*\)$/_\1/g\""~ cat $export_symbols | $prefix_cmds >> $output_objdir/$libname.def~ $CC -Zdll -Zcrtdll -o $output_objdir/$soname $libobjs $deplibs $compiler_flags $output_objdir/$libname.def~ emximp -o $lib $output_objdir/$libname.def' _LT_TAGVAR(old_archive_from_new_cmds, $1)='emximp -o $output_objdir/${libname}_dll.a $output_objdir/$libname.def' _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes _LT_TAGVAR(file_list_spec, $1)='@' ;; interix[[3-9]]*) _LT_TAGVAR(hardcode_direct, $1)=no _LT_TAGVAR(hardcode_shlibpath_var, $1)=no _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath,$libdir' _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl-E' # Hack: On Interix 3.x, we cannot compile PIC because of a broken gcc. # Instead, shared libraries are loaded at an image base (0x10000000 by # default) and relocated if they conflict, which is a slow very memory # consuming and fragmenting process. To avoid this, we pick a random, # 256 KiB-aligned image base between 0x50000000 and 0x6FFC0000 at link # time. Moving up from 0x10000000 also allows more sbrk(2) space. _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-h,$soname $wl--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' _LT_TAGVAR(archive_expsym_cmds, $1)='$SED "s|^|_|" $export_symbols >$output_objdir/$soname.expsym~$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-h,$soname $wl--retain-symbols-file,$output_objdir/$soname.expsym $wl--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' ;; gnu* | linux* | tpf* | k*bsd*-gnu | kopensolaris*-gnu) tmp_diet=no if test linux-dietlibc = "$host_os"; then case $cc_basename in diet\ *) tmp_diet=yes;; # linux-dietlibc with static linking (!diet-dyn) esac fi if $LD --help 2>&1 | $EGREP ': supported targets:.* elf' > /dev/null \ && test no = "$tmp_diet" then tmp_addflag=' $pic_flag' tmp_sharedflag='-shared' case $cc_basename,$host_cpu in pgcc*) # Portland Group C compiler _LT_TAGVAR(whole_archive_flag_spec, $1)='$wl--whole-archive`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; func_echo_all \"$new_convenience\"` $wl--no-whole-archive' tmp_addflag=' $pic_flag' ;; pgf77* | pgf90* | pgf95* | pgfortran*) # Portland Group f77 and f90 compilers _LT_TAGVAR(whole_archive_flag_spec, $1)='$wl--whole-archive`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; func_echo_all \"$new_convenience\"` $wl--no-whole-archive' tmp_addflag=' $pic_flag -Mnomain' ;; ecc*,ia64* | icc*,ia64*) # Intel C compiler on ia64 tmp_addflag=' -i_dynamic' ;; efc*,ia64* | ifort*,ia64*) # Intel Fortran compiler on ia64 tmp_addflag=' -i_dynamic -nofor_main' ;; ifc* | ifort*) # Intel Fortran compiler tmp_addflag=' -nofor_main' ;; lf95*) # Lahey Fortran 8.1 _LT_TAGVAR(whole_archive_flag_spec, $1)= tmp_sharedflag='--shared' ;; nagfor*) # NAGFOR 5.3 tmp_sharedflag='-Wl,-shared' ;; xl[[cC]]* | bgxl[[cC]]* | mpixl[[cC]]*) # IBM XL C 8.0 on PPC (deal with xlf below) tmp_sharedflag='-qmkshrobj' tmp_addflag= ;; nvcc*) # Cuda Compiler Driver 2.2 _LT_TAGVAR(whole_archive_flag_spec, $1)='$wl--whole-archive`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; func_echo_all \"$new_convenience\"` $wl--no-whole-archive' _LT_TAGVAR(compiler_needs_object, $1)=yes ;; esac case `$CC -V 2>&1 | $SED 5q` in *Sun\ C*) # Sun C 5.9 _LT_TAGVAR(whole_archive_flag_spec, $1)='$wl--whole-archive`new_convenience=; for conv in $convenience\"\"; do test -z \"$conv\" || new_convenience=\"$new_convenience,$conv\"; done; func_echo_all \"$new_convenience\"` $wl--no-whole-archive' _LT_TAGVAR(compiler_needs_object, $1)=yes tmp_sharedflag='-G' ;; *Sun\ F*) # Sun Fortran 8.3 tmp_sharedflag='-G' ;; esac _LT_TAGVAR(archive_cmds, $1)='$CC '"$tmp_sharedflag""$tmp_addflag"' $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' if test yes = "$supports_anon_versioning"; then _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $output_objdir/$libname.ver~ cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~ echo "local: *; };" >> $output_objdir/$libname.ver~ $CC '"$tmp_sharedflag""$tmp_addflag"' $libobjs $deplibs $compiler_flags $wl-soname $wl$soname $wl-version-script $wl$output_objdir/$libname.ver -o $lib' fi case $cc_basename in tcc*) _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath $wl$libdir' _LT_TAGVAR(export_dynamic_flag_spec, $1)='-rdynamic' ;; xlf* | bgf* | bgxlf* | mpixlf*) # IBM XL Fortran 10.1 on PPC cannot create shared libs itself _LT_TAGVAR(whole_archive_flag_spec, $1)='--whole-archive$convenience --no-whole-archive' _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath $wl$libdir' _LT_TAGVAR(archive_cmds, $1)='$LD -shared $libobjs $deplibs $linker_flags -soname $soname -o $lib' if test yes = "$supports_anon_versioning"; then _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $output_objdir/$libname.ver~ cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~ echo "local: *; };" >> $output_objdir/$libname.ver~ $LD -shared $libobjs $deplibs $linker_flags -soname $soname -version-script $output_objdir/$libname.ver -o $lib' fi ;; esac else _LT_TAGVAR(ld_shlibs, $1)=no fi ;; *-mlibc) _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname $wl-retain-symbols-file $wl$export_symbols -o $lib' ;; netbsd* | netbsdelf*-gnu) if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable $libobjs $deplibs $linker_flags -o $lib' wlarc= else _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname $wl-retain-symbols-file $wl$export_symbols -o $lib' fi ;; solaris*) if $LD -v 2>&1 | $GREP 'BFD 2\.8' > /dev/null; then _LT_TAGVAR(ld_shlibs, $1)=no cat <<_LT_EOF 1>&2 *** Warning: The releases 2.8.* of the GNU linker cannot reliably *** create shared libraries on Solaris systems. Therefore, libtool *** is disabling shared libraries support. We urge you to upgrade GNU *** binutils to release 2.9.1 or newer. Another option is to modify *** your PATH or compiler configuration so that the native linker is *** used, and then restart. _LT_EOF elif $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname $wl-retain-symbols-file $wl$export_symbols -o $lib' else _LT_TAGVAR(ld_shlibs, $1)=no fi ;; sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX*) case `$LD -v 2>&1` in *\ [[01]].* | *\ 2.[[0-9]].* | *\ 2.1[[0-5]].*) _LT_TAGVAR(ld_shlibs, $1)=no cat <<_LT_EOF 1>&2 *** Warning: Releases of the GNU linker prior to 2.16.91.0.3 cannot *** reliably create shared libraries on SCO systems. Therefore, libtool *** is disabling shared libraries support. We urge you to upgrade GNU *** binutils to release 2.16.91.0.3 or newer. Another option is to modify *** your PATH or compiler configuration so that the native linker is *** used, and then restart. _LT_EOF ;; *) # For security reasons, it is highly recommended that you always # use absolute paths for naming shared libraries, and exclude the # DT_RUNPATH tag from executables and libraries. But doing so # requires that you compile everything twice, which is a pain. if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath $wl$libdir' _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags $wl-soname $wl$soname $wl-retain-symbols-file $wl$export_symbols -o $lib' else _LT_TAGVAR(ld_shlibs, $1)=no fi ;; esac ;; sunos4*) _LT_TAGVAR(archive_cmds, $1)='$LD -assert pure-text -Bshareable -o $lib $libobjs $deplibs $linker_flags' wlarc= _LT_TAGVAR(hardcode_direct, $1)=yes _LT_TAGVAR(hardcode_shlibpath_var, $1)=no ;; *) if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname $wl-retain-symbols-file $wl$export_symbols -o $lib' else _LT_TAGVAR(ld_shlibs, $1)=no fi ;; esac if test no = "$_LT_TAGVAR(ld_shlibs, $1)"; then runpath_var= _LT_TAGVAR(hardcode_libdir_flag_spec, $1)= _LT_TAGVAR(export_dynamic_flag_spec, $1)= _LT_TAGVAR(whole_archive_flag_spec, $1)= fi else # PORTME fill in a description of your system's linker (not GNU ld) case $host_os in aix3*) _LT_TAGVAR(allow_undefined_flag, $1)=unsupported _LT_TAGVAR(always_export_symbols, $1)=yes _LT_TAGVAR(archive_expsym_cmds, $1)='$LD -o $output_objdir/$soname $libobjs $deplibs $linker_flags -bE:$export_symbols -T512 -H512 -bM:SRE~$AR $AR_FLAGS $lib $output_objdir/$soname' # Note: this linker hardcodes the directories in LIBPATH if there # are no directories specified by -L. _LT_TAGVAR(hardcode_minus_L, $1)=yes if test yes = "$GCC" && test -z "$lt_prog_compiler_static"; then # Neither direct hardcoding nor static linking is supported with a # broken collect2. _LT_TAGVAR(hardcode_direct, $1)=unsupported fi ;; aix[[4-9]]*) if test ia64 = "$host_cpu"; then # On IA64, the linker does run time linking by default, so we don't # have to do anything special. aix_use_runtimelinking=no exp_sym_flag='-Bexport' no_entry_flag= else # If we're using GNU nm, then we don't want the "-C" option. # -C means demangle to GNU nm, but means don't demangle to AIX nm. # Without the "-l" option, or with the "-B" option, AIX nm treats # weak defined symbols like other global defined symbols, whereas # GNU nm marks them as "W". # While the 'weak' keyword is ignored in the Export File, we need # it in the Import File for the 'aix-soname' feature, so we have # to replace the "-B" option with "-P" for AIX nm. if $NM -V 2>&1 | $GREP 'GNU' > /dev/null; then _LT_TAGVAR(export_symbols_cmds, $1)='$NM -Bpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B") || (\$ 2 == "W")) && ([substr](\$ 3,1,1) != ".")) { if (\$ 2 == "W") { print \$ 3 " weak" } else { print \$ 3 } } }'\'' | sort -u > $export_symbols' else _LT_TAGVAR(export_symbols_cmds, $1)='`func_echo_all $NM | $SED -e '\''s/B\([[^B]]*\)$/P\1/'\''` -PCpgl $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B") || (\$ 2 == "L") || (\$ 2 == "W") || (\$ 2 == "V") || (\$ 2 == "Z")) && ([substr](\$ 1,1,1) != ".")) { if ((\$ 2 == "W") || (\$ 2 == "V") || (\$ 2 == "Z")) { print \$ 1 " weak" } else { print \$ 1 } } }'\'' | sort -u > $export_symbols' fi aix_use_runtimelinking=no # Test if we are trying to use run time linking or normal # AIX style linking. If -brtl is somewhere in LDFLAGS, we # have runtime linking enabled, and use it for executables. # For shared libraries, we enable/disable runtime linking # depending on the kind of the shared library created - # when "with_aix_soname,aix_use_runtimelinking" is: # "aix,no" lib.a(lib.so.V) shared, rtl:no, for executables # "aix,yes" lib.so shared, rtl:yes, for executables # lib.a static archive # "both,no" lib.so.V(shr.o) shared, rtl:yes # lib.a(lib.so.V) shared, rtl:no, for executables # "both,yes" lib.so.V(shr.o) shared, rtl:yes, for executables # lib.a(lib.so.V) shared, rtl:no # "svr4,*" lib.so.V(shr.o) shared, rtl:yes, for executables # lib.a static archive case $host_os in aix4.[[23]]|aix4.[[23]].*|aix[[5-9]]*) for ld_flag in $LDFLAGS; do if (test x-brtl = "x$ld_flag" || test x-Wl,-brtl = "x$ld_flag"); then aix_use_runtimelinking=yes break fi done if test svr4,no = "$with_aix_soname,$aix_use_runtimelinking"; then # With aix-soname=svr4, we create the lib.so.V shared archives only, # so we don't have lib.a shared libs to link our executables. # We have to force runtime linking in this case. aix_use_runtimelinking=yes LDFLAGS="$LDFLAGS -Wl,-brtl" fi ;; esac exp_sym_flag='-bexport' no_entry_flag='-bnoentry' fi # When large executables or shared objects are built, AIX ld can # have problems creating the table of contents. If linking a library # or program results in "error TOC overflow" add -mminimal-toc to # CXXFLAGS/CFLAGS for g++/gcc. In the cases where that is not # enough to fix the problem, add -Wl,-bbigtoc to LDFLAGS. _LT_TAGVAR(archive_cmds, $1)='' _LT_TAGVAR(hardcode_direct, $1)=yes _LT_TAGVAR(hardcode_direct_absolute, $1)=yes _LT_TAGVAR(hardcode_libdir_separator, $1)=':' _LT_TAGVAR(link_all_deplibs, $1)=yes _LT_TAGVAR(file_list_spec, $1)='$wl-f,' case $with_aix_soname,$aix_use_runtimelinking in aix,*) ;; # traditional, no import file svr4,* | *,yes) # use import file # The Import File defines what to hardcode. _LT_TAGVAR(hardcode_direct, $1)=no _LT_TAGVAR(hardcode_direct_absolute, $1)=no ;; esac if test yes = "$GCC"; then case $host_os in aix4.[[012]]|aix4.[[012]].*) # We only want to do this on AIX 4.2 and lower, the check # below for broken collect2 doesn't work under 4.3+ collect2name=`$CC -print-prog-name=collect2` if test -f "$collect2name" && strings "$collect2name" | $GREP resolve_lib_name >/dev/null then # We have reworked collect2 : else # We have old collect2 _LT_TAGVAR(hardcode_direct, $1)=unsupported # It fails to find uninstalled libraries when the uninstalled # path is not listed in the libpath. Setting hardcode_minus_L # to unsupported forces relinking _LT_TAGVAR(hardcode_minus_L, $1)=yes _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' _LT_TAGVAR(hardcode_libdir_separator, $1)= fi ;; esac shared_flag='-shared' if test yes = "$aix_use_runtimelinking"; then shared_flag="$shared_flag "'$wl-G' fi # Need to ensure runtime linking is disabled for the traditional # shared library, or the linker may eventually find shared libraries # /with/ Import File - we do not want to mix them. shared_flag_aix='-shared' shared_flag_svr4='-shared $wl-G' else # not using gcc if test ia64 = "$host_cpu"; then # VisualAge C++, Version 5.5 for AIX 5L for IA-64, Beta 3 Release # chokes on -Wl,-G. The following line is correct: shared_flag='-G' else if test yes = "$aix_use_runtimelinking"; then shared_flag='$wl-G' else shared_flag='$wl-bM:SRE' fi shared_flag_aix='$wl-bM:SRE' shared_flag_svr4='$wl-G' fi fi _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl-bexpall' # It seems that -bexpall does not export symbols beginning with # underscore (_), so it is better to generate a list of symbols to export. _LT_TAGVAR(always_export_symbols, $1)=yes if test aix,yes = "$with_aix_soname,$aix_use_runtimelinking"; then # Warning - without using the other runtime loading flags (-brtl), # -berok will link without error, but may produce a broken library. _LT_TAGVAR(allow_undefined_flag, $1)='-berok' # Determine the default libpath from the value encoded in an # empty executable. _LT_SYS_MODULE_PATH_AIX([$1]) _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-blibpath:$libdir:'"$aix_libpath" _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -o $output_objdir/$soname $libobjs $deplibs $wl'$no_entry_flag' $compiler_flags `if test -n "$allow_undefined_flag"; then func_echo_all "$wl$allow_undefined_flag"; else :; fi` $wl'$exp_sym_flag:\$export_symbols' '$shared_flag else if test ia64 = "$host_cpu"; then _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-R $libdir:/usr/lib:/lib' _LT_TAGVAR(allow_undefined_flag, $1)="-z nodefs" _LT_TAGVAR(archive_expsym_cmds, $1)="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs '"\$wl$no_entry_flag"' $compiler_flags $wl$allow_undefined_flag '"\$wl$exp_sym_flag:\$export_symbols" else # Determine the default libpath from the value encoded in an # empty executable. _LT_SYS_MODULE_PATH_AIX([$1]) _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-blibpath:$libdir:'"$aix_libpath" # Warning - without using the other run time loading flags, # -berok will link without error, but may produce a broken library. _LT_TAGVAR(no_undefined_flag, $1)=' $wl-bernotok' _LT_TAGVAR(allow_undefined_flag, $1)=' $wl-berok' if test yes = "$with_gnu_ld"; then # We only use this code for GNU lds that support --whole-archive. _LT_TAGVAR(whole_archive_flag_spec, $1)='$wl--whole-archive$convenience $wl--no-whole-archive' else # Exported symbols can be pulled into shared objects from archives _LT_TAGVAR(whole_archive_flag_spec, $1)='$convenience' fi _LT_TAGVAR(archive_cmds_need_lc, $1)=yes _LT_TAGVAR(archive_expsym_cmds, $1)='$RM -r $output_objdir/$realname.d~$MKDIR $output_objdir/$realname.d' # -brtl affects multiple linker settings, -berok does not and is overridden later compiler_flags_filtered='`func_echo_all "$compiler_flags " | $SED -e "s%-brtl\\([[, ]]\\)%-berok\\1%g"`' if test svr4 != "$with_aix_soname"; then # This is similar to how AIX traditionally builds its shared libraries. _LT_TAGVAR(archive_expsym_cmds, $1)="$_LT_TAGVAR(archive_expsym_cmds, $1)"'~$CC '$shared_flag_aix' -o $output_objdir/$realname.d/$soname $libobjs $deplibs $wl-bnoentry '$compiler_flags_filtered'$wl-bE:$export_symbols$allow_undefined_flag~$AR $AR_FLAGS $output_objdir/$libname$release.a $output_objdir/$realname.d/$soname' fi if test aix != "$with_aix_soname"; then _LT_TAGVAR(archive_expsym_cmds, $1)="$_LT_TAGVAR(archive_expsym_cmds, $1)"'~$CC '$shared_flag_svr4' -o $output_objdir/$realname.d/$shared_archive_member_spec.o $libobjs $deplibs $wl-bnoentry '$compiler_flags_filtered'$wl-bE:$export_symbols$allow_undefined_flag~$STRIP -e $output_objdir/$realname.d/$shared_archive_member_spec.o~( func_echo_all "#! $soname($shared_archive_member_spec.o)"; if test shr_64 = "$shared_archive_member_spec"; then func_echo_all "# 64"; else func_echo_all "# 32"; fi; cat $export_symbols ) > $output_objdir/$realname.d/$shared_archive_member_spec.imp~$AR $AR_FLAGS $output_objdir/$soname $output_objdir/$realname.d/$shared_archive_member_spec.o $output_objdir/$realname.d/$shared_archive_member_spec.imp' else # used by -dlpreopen to get the symbols _LT_TAGVAR(archive_expsym_cmds, $1)="$_LT_TAGVAR(archive_expsym_cmds, $1)"'~$MV $output_objdir/$realname.d/$soname $output_objdir' fi _LT_TAGVAR(archive_expsym_cmds, $1)="$_LT_TAGVAR(archive_expsym_cmds, $1)"'~$RM -r $output_objdir/$realname.d' fi fi ;; amigaos*) case $host_cpu in powerpc) # see comment about AmigaOS4 .so support _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' _LT_TAGVAR(archive_expsym_cmds, $1)='' ;; m68k) _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/a2ixlibrary.data~$ECHO "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$ECHO "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$ECHO "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$ECHO "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)' _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' _LT_TAGVAR(hardcode_minus_L, $1)=yes ;; esac ;; bsdi[[45]]*) _LT_TAGVAR(export_dynamic_flag_spec, $1)=-rdynamic ;; cygwin* | mingw* | windows* | pw32* | cegcc*) # When not using gcc, we currently assume that we are using # Microsoft Visual C++ or Intel C++ Compiler. # hardcode_libdir_flag_spec is actually meaningless, as there is # no search path for DLLs. case $cc_basename in cl* | icl*) # Native MSVC or ICC _LT_TAGVAR(hardcode_libdir_flag_spec, $1)=' ' _LT_TAGVAR(allow_undefined_flag, $1)=unsupported _LT_TAGVAR(always_export_symbols, $1)=yes _LT_TAGVAR(file_list_spec, $1)='@' # Tell ltmain to make .lib files, not .a files. libext=lib # Tell ltmain to make .dll files, not .so files. shrext_cmds=.dll # FIXME: Setting linknames here is a bad hack. _LT_TAGVAR(archive_cmds, $1)='$CC -Fe$output_objdir/$soname $libobjs $compiler_flags $deplibs -Wl,-DLL,-IMPLIB:"$tool_output_objdir$libname.dll.lib"~linknames=' _LT_TAGVAR(archive_expsym_cmds, $1)='if _LT_DLL_DEF_P([$export_symbols]); then cp "$export_symbols" "$output_objdir/$soname.def"; echo "$tool_output_objdir$soname.def" > "$output_objdir/$soname.exp"; else $SED -e '\''s/^/-link -EXPORT:/'\'' < $export_symbols > $output_objdir/$soname.exp; fi~ $CC -Fe$tool_output_objdir$soname $libobjs $compiler_flags $deplibs "@$tool_output_objdir$soname.exp" -Wl,-DLL,-IMPLIB:"$tool_output_objdir$libname.dll.lib"~ linknames=' # The linker will not automatically build a static lib if we build a DLL. # _LT_TAGVAR(old_archive_from_new_cmds, $1)='true' _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes _LT_TAGVAR(exclude_expsyms, $1)='_NULL_IMPORT_DESCRIPTOR|_IMPORT_DESCRIPTOR_.*' _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[[BCDGRS]][[ ]]/s/.*[[ ]]\([[^ ]]*\)/\1,DATA/'\'' | $SED -e '\''/^[[AITW]][[ ]]/s/.*[[ ]]//'\'' | sort | uniq > $export_symbols' # Don't use ranlib _LT_TAGVAR(old_postinstall_cmds, $1)='chmod 644 $oldlib' _LT_TAGVAR(postlink_cmds, $1)='lt_outputfile="@OUTPUT@"~ lt_tool_outputfile="@TOOL_OUTPUT@"~ case $lt_outputfile in *.exe|*.EXE) ;; *) lt_outputfile=$lt_outputfile.exe lt_tool_outputfile=$lt_tool_outputfile.exe ;; esac~ if test : != "$MANIFEST_TOOL" && test -f "$lt_outputfile.manifest"; then $MANIFEST_TOOL -manifest "$lt_tool_outputfile.manifest" -outputresource:"$lt_tool_outputfile" || exit 1; $RM "$lt_outputfile.manifest"; fi' ;; *) # Assume MSVC and ICC wrapper _LT_TAGVAR(hardcode_libdir_flag_spec, $1)=' ' _LT_TAGVAR(allow_undefined_flag, $1)=unsupported # Tell ltmain to make .lib files, not .a files. libext=lib # Tell ltmain to make .dll files, not .so files. shrext_cmds=.dll # FIXME: Setting linknames here is a bad hack. _LT_TAGVAR(archive_cmds, $1)='$CC -o $lib $libobjs $compiler_flags `func_echo_all "$deplibs" | $SED '\''s/ -lc$//'\''` -link -dll~linknames=' # The linker will automatically build a .lib file if we build a DLL. _LT_TAGVAR(old_archive_from_new_cmds, $1)='true' # FIXME: Should let the user specify the lib program. _LT_TAGVAR(old_archive_cmds, $1)='lib -OUT:$oldlib$oldobjs$old_deplibs' _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes ;; esac ;; darwin* | rhapsody*) _LT_DARWIN_LINKER_FEATURES($1) ;; dgux*) _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' _LT_TAGVAR(hardcode_shlibpath_var, $1)=no ;; # FreeBSD 2.2.[012] allows us to include c++rt0.o to get C++ constructor # support. Future versions do this automatically, but an explicit c++rt0.o # does not break anything, and helps significantly (at the cost of a little # extra space). freebsd2.2*) _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags /usr/lib/c++rt0.o' _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' _LT_TAGVAR(hardcode_direct, $1)=yes _LT_TAGVAR(hardcode_shlibpath_var, $1)=no ;; # Unfortunately, older versions of FreeBSD 2 do not have this feature. freebsd2.*) _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags' _LT_TAGVAR(hardcode_direct, $1)=yes _LT_TAGVAR(hardcode_minus_L, $1)=yes _LT_TAGVAR(hardcode_shlibpath_var, $1)=no ;; # FreeBSD 3 and greater uses gcc -shared to do shared libraries. freebsd* | dragonfly* | midnightbsd*) _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags' _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' _LT_TAGVAR(hardcode_direct, $1)=yes _LT_TAGVAR(hardcode_shlibpath_var, $1)=no ;; hpux9*) if test yes = "$GCC"; then _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/$soname~$CC -shared $pic_flag $wl+b $wl$install_libdir -o $output_objdir/$soname $libobjs $deplibs $compiler_flags~test "x$output_objdir/$soname" = "x$lib" || mv $output_objdir/$soname $lib' else _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/$soname~$LD -b +b $install_libdir -o $output_objdir/$soname $libobjs $deplibs $linker_flags~test "x$output_objdir/$soname" = "x$lib" || mv $output_objdir/$soname $lib' fi _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl+b $wl$libdir' _LT_TAGVAR(hardcode_libdir_separator, $1)=: _LT_TAGVAR(hardcode_direct, $1)=yes # hardcode_minus_L: Not really in the search PATH, # but as the default location of the library. _LT_TAGVAR(hardcode_minus_L, $1)=yes _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl-E' ;; hpux10*) if test yes,no = "$GCC,$with_gnu_ld"; then _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $wl+h $wl$soname $wl+b $wl$install_libdir -o $lib $libobjs $deplibs $compiler_flags' else _LT_TAGVAR(archive_cmds, $1)='$LD -b +h $soname +b $install_libdir -o $lib $libobjs $deplibs $linker_flags' fi if test no = "$with_gnu_ld"; then _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl+b $wl$libdir' _LT_TAGVAR(hardcode_libdir_separator, $1)=: _LT_TAGVAR(hardcode_direct, $1)=yes _LT_TAGVAR(hardcode_direct_absolute, $1)=yes _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl-E' # hardcode_minus_L: Not really in the search PATH, # but as the default location of the library. _LT_TAGVAR(hardcode_minus_L, $1)=yes fi ;; hpux11*) if test yes,no = "$GCC,$with_gnu_ld"; then case $host_cpu in hppa*64*) _LT_TAGVAR(archive_cmds, $1)='$CC -shared $wl+h $wl$soname -o $lib $libobjs $deplibs $compiler_flags' ;; ia64*) _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $wl+h $wl$soname $wl+nodefaultrpath -o $lib $libobjs $deplibs $compiler_flags' ;; *) _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $wl+h $wl$soname $wl+b $wl$install_libdir -o $lib $libobjs $deplibs $compiler_flags' ;; esac else case $host_cpu in hppa*64*) _LT_TAGVAR(archive_cmds, $1)='$CC -b $wl+h $wl$soname -o $lib $libobjs $deplibs $compiler_flags' ;; ia64*) _LT_TAGVAR(archive_cmds, $1)='$CC -b $wl+h $wl$soname $wl+nodefaultrpath -o $lib $libobjs $deplibs $compiler_flags' ;; *) m4_if($1, [], [ # Older versions of the 11.00 compiler do not understand -b yet # (HP92453-01 A.11.01.20 doesn't, HP92453-01 B.11.X.35175-35176.GP does) _LT_LINKER_OPTION([if $CC understands -b], _LT_TAGVAR(lt_cv_prog_compiler__b, $1), [-b], [_LT_TAGVAR(archive_cmds, $1)='$CC -b $wl+h $wl$soname $wl+b $wl$install_libdir -o $lib $libobjs $deplibs $compiler_flags'], [_LT_TAGVAR(archive_cmds, $1)='$LD -b +h $soname +b $install_libdir -o $lib $libobjs $deplibs $linker_flags'])], [_LT_TAGVAR(archive_cmds, $1)='$CC -b $wl+h $wl$soname $wl+b $wl$install_libdir -o $lib $libobjs $deplibs $compiler_flags']) ;; esac fi if test no = "$with_gnu_ld"; then _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl+b $wl$libdir' _LT_TAGVAR(hardcode_libdir_separator, $1)=: case $host_cpu in hppa*64*|ia64*) _LT_TAGVAR(hardcode_direct, $1)=no _LT_TAGVAR(hardcode_shlibpath_var, $1)=no ;; *) _LT_TAGVAR(hardcode_direct, $1)=yes _LT_TAGVAR(hardcode_direct_absolute, $1)=yes _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl-E' # hardcode_minus_L: Not really in the search PATH, # but as the default location of the library. _LT_TAGVAR(hardcode_minus_L, $1)=yes ;; esac fi ;; irix5* | irix6* | nonstopux*) if test yes = "$GCC"; then _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname `test -n "$verstring" && func_echo_all "$wl-set_version $wl$verstring"` $wl-update_registry $wl$output_objdir/so_locations -o $lib' # Try to use the -exported_symbol ld option, if it does not # work, assume that -exports_file does not work either and # implicitly export all symbols. # This should be the same for all languages, so no per-tag cache variable. AC_CACHE_CHECK([whether the $host_os linker accepts -exported_symbol], [lt_cv_irix_exported_symbol], [save_LDFLAGS=$LDFLAGS LDFLAGS="$LDFLAGS -shared $wl-exported_symbol ${wl}foo $wl-update_registry $wl/dev/null" AC_LINK_IFELSE( [AC_LANG_SOURCE( [AC_LANG_CASE([C], [[int foo (void) { return 0; }]], [C++], [[int foo (void) { return 0; }]], [Fortran 77], [[ subroutine foo end]], [Fortran], [[ subroutine foo end]])])], [lt_cv_irix_exported_symbol=yes], [lt_cv_irix_exported_symbol=no]) LDFLAGS=$save_LDFLAGS]) if test yes = "$lt_cv_irix_exported_symbol"; then _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname `test -n "$verstring" && func_echo_all "$wl-set_version $wl$verstring"` $wl-update_registry $wl$output_objdir/so_locations $wl-exports_file $wl$export_symbols -o $lib' fi _LT_TAGVAR(link_all_deplibs, $1)=no else _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry $output_objdir/so_locations -o $lib' _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry $output_objdir/so_locations -exports_file $export_symbols -o $lib' fi _LT_TAGVAR(archive_cmds_need_lc, $1)='no' _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath $wl$libdir' _LT_TAGVAR(hardcode_libdir_separator, $1)=: _LT_TAGVAR(inherit_rpath, $1)=yes _LT_TAGVAR(link_all_deplibs, $1)=yes ;; linux*) case $cc_basename in tcc*) # Fabrice Bellard et al's Tiny C Compiler _LT_TAGVAR(ld_shlibs, $1)=yes _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags' _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath $wl$libdir' ;; esac ;; *-mlibc) ;; netbsd* | netbsdelf*-gnu) if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags' # a.out else _LT_TAGVAR(archive_cmds, $1)='$LD -shared -o $lib $libobjs $deplibs $linker_flags' # ELF fi _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' _LT_TAGVAR(hardcode_direct, $1)=yes _LT_TAGVAR(hardcode_shlibpath_var, $1)=no ;; newsos6) _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' _LT_TAGVAR(hardcode_direct, $1)=yes _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath $wl$libdir' _LT_TAGVAR(hardcode_libdir_separator, $1)=: _LT_TAGVAR(hardcode_shlibpath_var, $1)=no ;; *nto* | *qnx*) ;; openbsd*) if test -f /usr/libexec/ld.so; then _LT_TAGVAR(hardcode_direct, $1)=yes _LT_TAGVAR(hardcode_shlibpath_var, $1)=no _LT_TAGVAR(hardcode_direct_absolute, $1)=yes if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`"; then _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags' _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags $wl-retain-symbols-file,$export_symbols' _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath,$libdir' _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl-E' else _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags' _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath,$libdir' fi else _LT_TAGVAR(ld_shlibs, $1)=no fi ;; os2*) _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' _LT_TAGVAR(hardcode_minus_L, $1)=yes _LT_TAGVAR(allow_undefined_flag, $1)=unsupported shrext_cmds=.dll _LT_TAGVAR(archive_cmds, $1)='$ECHO "LIBRARY ${soname%$shared_ext} INITINSTANCE TERMINSTANCE" > $output_objdir/$libname.def~ $ECHO "DESCRIPTION \"$libname\"" >> $output_objdir/$libname.def~ $ECHO "DATA MULTIPLE NONSHARED" >> $output_objdir/$libname.def~ $ECHO EXPORTS >> $output_objdir/$libname.def~ emxexp $libobjs | $SED /"_DLL_InitTerm"/d >> $output_objdir/$libname.def~ $CC -Zdll -Zcrtdll -o $output_objdir/$soname $libobjs $deplibs $compiler_flags $output_objdir/$libname.def~ emximp -o $lib $output_objdir/$libname.def' _LT_TAGVAR(archive_expsym_cmds, $1)='$ECHO "LIBRARY ${soname%$shared_ext} INITINSTANCE TERMINSTANCE" > $output_objdir/$libname.def~ $ECHO "DESCRIPTION \"$libname\"" >> $output_objdir/$libname.def~ $ECHO "DATA MULTIPLE NONSHARED" >> $output_objdir/$libname.def~ $ECHO EXPORTS >> $output_objdir/$libname.def~ prefix_cmds="$SED"~ if test EXPORTS = "`$SED 1q $export_symbols`"; then prefix_cmds="$prefix_cmds -e 1d"; fi~ prefix_cmds="$prefix_cmds -e \"s/^\(.*\)$/_\1/g\""~ cat $export_symbols | $prefix_cmds >> $output_objdir/$libname.def~ $CC -Zdll -Zcrtdll -o $output_objdir/$soname $libobjs $deplibs $compiler_flags $output_objdir/$libname.def~ emximp -o $lib $output_objdir/$libname.def' _LT_TAGVAR(old_archive_from_new_cmds, $1)='emximp -o $output_objdir/${libname}_dll.a $output_objdir/$libname.def' _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes _LT_TAGVAR(file_list_spec, $1)='@' ;; osf3*) if test yes = "$GCC"; then _LT_TAGVAR(allow_undefined_flag, $1)=' $wl-expect_unresolved $wl\*' _LT_TAGVAR(archive_cmds, $1)='$CC -shared$allow_undefined_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname `test -n "$verstring" && func_echo_all "$wl-set_version $wl$verstring"` $wl-update_registry $wl$output_objdir/so_locations -o $lib' else _LT_TAGVAR(allow_undefined_flag, $1)=' -expect_unresolved \*' _LT_TAGVAR(archive_cmds, $1)='$CC -shared$allow_undefined_flag $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry $output_objdir/so_locations -o $lib' fi _LT_TAGVAR(archive_cmds_need_lc, $1)='no' _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath $wl$libdir' _LT_TAGVAR(hardcode_libdir_separator, $1)=: ;; osf4* | osf5*) # as osf3* with the addition of -msym flag if test yes = "$GCC"; then _LT_TAGVAR(allow_undefined_flag, $1)=' $wl-expect_unresolved $wl\*' _LT_TAGVAR(archive_cmds, $1)='$CC -shared$allow_undefined_flag $pic_flag $libobjs $deplibs $compiler_flags $wl-msym $wl-soname $wl$soname `test -n "$verstring" && func_echo_all "$wl-set_version $wl$verstring"` $wl-update_registry $wl$output_objdir/so_locations -o $lib' _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath $wl$libdir' else _LT_TAGVAR(allow_undefined_flag, $1)=' -expect_unresolved \*' _LT_TAGVAR(archive_cmds, $1)='$CC -shared$allow_undefined_flag $libobjs $deplibs $compiler_flags -msym -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry $output_objdir/so_locations -o $lib' _LT_TAGVAR(archive_expsym_cmds, $1)='for i in `cat $export_symbols`; do printf "%s %s\\n" -exported_symbol "\$i" >> $lib.exp; done; printf "%s\\n" "-hidden">> $lib.exp~ $CC -shared$allow_undefined_flag $wl-input $wl$lib.exp $compiler_flags $libobjs $deplibs -soname $soname `test -n "$verstring" && $ECHO "-set_version $verstring"` -update_registry $output_objdir/so_locations -o $lib~$RM $lib.exp' # Both c and cxx compiler support -rpath directly _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-rpath $libdir' fi _LT_TAGVAR(archive_cmds_need_lc, $1)='no' _LT_TAGVAR(hardcode_libdir_separator, $1)=: ;; serenity*) ;; solaris*) _LT_TAGVAR(no_undefined_flag, $1)=' -z defs' if test yes = "$GCC"; then wlarc='$wl' _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $wl-z ${wl}text $wl-h $wl$soname -o $lib $libobjs $deplibs $compiler_flags' _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ $CC -shared $pic_flag $wl-z ${wl}text $wl-M $wl$lib.exp $wl-h $wl$soname -o $lib $libobjs $deplibs $compiler_flags~$RM $lib.exp' else case `$CC -V 2>&1` in *"Compilers 5.0"*) wlarc='' _LT_TAGVAR(archive_cmds, $1)='$LD -G$allow_undefined_flag -h $soname -o $lib $libobjs $deplibs $linker_flags' _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ $LD -G$allow_undefined_flag -M $lib.exp -h $soname -o $lib $libobjs $deplibs $linker_flags~$RM $lib.exp' ;; *) wlarc='$wl' _LT_TAGVAR(archive_cmds, $1)='$CC -G$allow_undefined_flag -h $soname -o $lib $libobjs $deplibs $compiler_flags' _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ $CC -G$allow_undefined_flag -M $lib.exp -h $soname -o $lib $libobjs $deplibs $compiler_flags~$RM $lib.exp' ;; esac fi _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' _LT_TAGVAR(hardcode_shlibpath_var, $1)=no case $host_os in solaris2.[[0-5]] | solaris2.[[0-5]].*) ;; *) # The compiler driver will combine and reorder linker options, # but understands '-z linker_flag'. GCC discards it without '$wl', # but is careful enough not to reorder. # Supported since Solaris 2.6 (maybe 2.5.1?) if test yes = "$GCC"; then _LT_TAGVAR(whole_archive_flag_spec, $1)='$wl-z ${wl}allextract$convenience $wl-z ${wl}defaultextract' else _LT_TAGVAR(whole_archive_flag_spec, $1)='-z allextract$convenience -z defaultextract' fi ;; esac _LT_TAGVAR(link_all_deplibs, $1)=yes ;; sunos4*) if test sequent = "$host_vendor"; then # Use $CC to link under sequent, because it throws in some extra .o # files that make .init and .fini sections work. _LT_TAGVAR(archive_cmds, $1)='$CC -G $wl-h $soname -o $lib $libobjs $deplibs $compiler_flags' else _LT_TAGVAR(archive_cmds, $1)='$LD -assert pure-text -Bstatic -o $lib $libobjs $deplibs $linker_flags' fi _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' _LT_TAGVAR(hardcode_direct, $1)=yes _LT_TAGVAR(hardcode_minus_L, $1)=yes _LT_TAGVAR(hardcode_shlibpath_var, $1)=no ;; sysv4) case $host_vendor in sni) _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' _LT_TAGVAR(hardcode_direct, $1)=yes # is this really true??? ;; siemens) ## LD is ld it makes a PLAMLIB ## CC just makes a GrossModule. _LT_TAGVAR(archive_cmds, $1)='$LD -G -o $lib $libobjs $deplibs $linker_flags' _LT_TAGVAR(reload_cmds, $1)='$CC -r -o $output$reload_objs' _LT_TAGVAR(hardcode_direct, $1)=no ;; motorola) _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' _LT_TAGVAR(hardcode_direct, $1)=no #Motorola manual says yes, but my tests say they lie ;; esac runpath_var='LD_RUN_PATH' _LT_TAGVAR(hardcode_shlibpath_var, $1)=no ;; sysv4.3*) _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' _LT_TAGVAR(hardcode_shlibpath_var, $1)=no _LT_TAGVAR(export_dynamic_flag_spec, $1)='-Bexport' ;; sysv4*MP*) if test -d /usr/nec; then _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' _LT_TAGVAR(hardcode_shlibpath_var, $1)=no runpath_var=LD_RUN_PATH hardcode_runpath_var=yes _LT_TAGVAR(ld_shlibs, $1)=yes fi ;; sysv4*uw2* | sysv5OpenUNIX* | sysv5UnixWare7.[[01]].[[10]]* | unixware7* | sco3.2v5.0.[[024]]*) _LT_TAGVAR(no_undefined_flag, $1)='$wl-z,text' _LT_TAGVAR(archive_cmds_need_lc, $1)=no _LT_TAGVAR(hardcode_shlibpath_var, $1)=no runpath_var='LD_RUN_PATH' if test yes = "$GCC"; then _LT_TAGVAR(archive_cmds, $1)='$CC -shared $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $wl-Bexport:$export_symbols $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' else _LT_TAGVAR(archive_cmds, $1)='$CC -G $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -G $wl-Bexport:$export_symbols $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' fi ;; sysv5* | sco3.2v5* | sco5v6*) # Note: We CANNOT use -z defs as we might desire, because we do not # link with -lc, and that would cause any symbols used from libc to # always be unresolved, which means just about no library would # ever link correctly. If we're not using GNU ld we use -z text # though, which does catch some bad symbols but isn't as heavy-handed # as -z defs. _LT_TAGVAR(no_undefined_flag, $1)='$wl-z,text' _LT_TAGVAR(allow_undefined_flag, $1)='$wl-z,nodefs' _LT_TAGVAR(archive_cmds_need_lc, $1)=no _LT_TAGVAR(hardcode_shlibpath_var, $1)=no _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-R,$libdir' _LT_TAGVAR(hardcode_libdir_separator, $1)=':' _LT_TAGVAR(link_all_deplibs, $1)=yes _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl-Bexport' runpath_var='LD_RUN_PATH' if test yes = "$GCC"; then _LT_TAGVAR(archive_cmds, $1)='$CC -shared $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $wl-Bexport:$export_symbols $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' else _LT_TAGVAR(archive_cmds, $1)='$CC -G $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -G $wl-Bexport:$export_symbols $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' fi ;; uts4*) _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' _LT_TAGVAR(hardcode_shlibpath_var, $1)=no ;; *) _LT_TAGVAR(ld_shlibs, $1)=no ;; esac if test sni = "$host_vendor"; then case $host in sysv4 | sysv4.2uw2* | sysv4.3* | sysv5*) _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl-Blargedynsym' ;; esac fi fi ]) AC_MSG_RESULT([$_LT_TAGVAR(ld_shlibs, $1)]) test no = "$_LT_TAGVAR(ld_shlibs, $1)" && can_build_shared=no _LT_TAGVAR(with_gnu_ld, $1)=$with_gnu_ld _LT_DECL([], [libext], [0], [Old archive suffix (normally "a")])dnl _LT_DECL([], [shrext_cmds], [1], [Shared library suffix (normally ".so")])dnl _LT_DECL([], [extract_expsyms_cmds], [2], [The commands to extract the exported symbol list from a shared archive]) # # Do we need to explicitly link libc? # case "x$_LT_TAGVAR(archive_cmds_need_lc, $1)" in x|xyes) # Assume -lc should be added _LT_TAGVAR(archive_cmds_need_lc, $1)=yes if test yes,yes = "$GCC,$enable_shared"; then case $_LT_TAGVAR(archive_cmds, $1) in *'~'*) # FIXME: we may have to deal with multi-command sequences. ;; '$CC '*) # Test whether the compiler implicitly links with -lc since on some # systems, -lgcc has to come before -lc. If gcc already passes -lc # to ld, don't add -lc before -lgcc. AC_CACHE_CHECK([whether -lc should be explicitly linked in], [lt_cv_]_LT_TAGVAR(archive_cmds_need_lc, $1), [$RM conftest* echo "$lt_simple_compile_test_code" > conftest.$ac_ext if AC_TRY_EVAL(ac_compile) 2>conftest.err; then soname=conftest lib=conftest libobjs=conftest.$ac_objext deplibs= wl=$_LT_TAGVAR(lt_prog_compiler_wl, $1) pic_flag=$_LT_TAGVAR(lt_prog_compiler_pic, $1) compiler_flags=-v linker_flags=-v verstring= output_objdir=. libname=conftest lt_save_allow_undefined_flag=$_LT_TAGVAR(allow_undefined_flag, $1) _LT_TAGVAR(allow_undefined_flag, $1)= if AC_TRY_EVAL(_LT_TAGVAR(archive_cmds, $1) 2\>\&1 \| $GREP \" -lc \" \>/dev/null 2\>\&1) then lt_cv_[]_LT_TAGVAR(archive_cmds_need_lc, $1)=no else lt_cv_[]_LT_TAGVAR(archive_cmds_need_lc, $1)=yes fi _LT_TAGVAR(allow_undefined_flag, $1)=$lt_save_allow_undefined_flag else cat conftest.err 1>&5 fi $RM conftest* ]) _LT_TAGVAR(archive_cmds_need_lc, $1)=$lt_cv_[]_LT_TAGVAR(archive_cmds_need_lc, $1) ;; esac fi ;; esac _LT_TAGDECL([build_libtool_need_lc], [archive_cmds_need_lc], [0], [Whether or not to add -lc for building shared libraries]) _LT_TAGDECL([allow_libtool_libs_with_static_runtimes], [enable_shared_with_static_runtimes], [0], [Whether or not to disallow shared libs when runtime libs are static]) _LT_TAGDECL([], [export_dynamic_flag_spec], [1], [Compiler flag to allow reflexive dlopens]) _LT_TAGDECL([], [whole_archive_flag_spec], [1], [Compiler flag to generate shared objects directly from archives]) _LT_TAGDECL([], [compiler_needs_object], [1], [Whether the compiler copes with passing no objects directly]) _LT_TAGDECL([], [old_archive_from_new_cmds], [2], [Create an old-style archive from a shared archive]) _LT_TAGDECL([], [old_archive_from_expsyms_cmds], [2], [Create a temporary old-style archive to link instead of a shared archive]) _LT_TAGDECL([], [archive_cmds], [2], [Commands used to build a shared archive]) _LT_TAGDECL([], [archive_expsym_cmds], [2]) _LT_TAGDECL([], [module_cmds], [2], [Commands used to build a loadable module if different from building a shared archive.]) _LT_TAGDECL([], [module_expsym_cmds], [2]) _LT_TAGDECL([], [with_gnu_ld], [1], [Whether we are building with GNU ld or not]) _LT_TAGDECL([], [allow_undefined_flag], [1], [Flag that allows shared libraries with undefined symbols to be built]) _LT_TAGDECL([], [no_undefined_flag], [1], [Flag that enforces no undefined symbols]) _LT_TAGDECL([], [hardcode_libdir_flag_spec], [1], [Flag to hardcode $libdir into a binary during linking. This must work even if $libdir does not exist]) _LT_TAGDECL([], [hardcode_libdir_separator], [1], [Whether we need a single "-rpath" flag with a separated argument]) _LT_TAGDECL([], [hardcode_direct], [0], [Set to "yes" if using DIR/libNAME$shared_ext during linking hardcodes DIR into the resulting binary]) _LT_TAGDECL([], [hardcode_direct_absolute], [0], [Set to "yes" if using DIR/libNAME$shared_ext during linking hardcodes DIR into the resulting binary and the resulting library dependency is "absolute", i.e. impossible to change by setting $shlibpath_var if the library is relocated]) _LT_TAGDECL([], [hardcode_minus_L], [0], [Set to "yes" if using the -LDIR flag during linking hardcodes DIR into the resulting binary]) _LT_TAGDECL([], [hardcode_shlibpath_var], [0], [Set to "yes" if using SHLIBPATH_VAR=DIR during linking hardcodes DIR into the resulting binary]) _LT_TAGDECL([], [hardcode_automatic], [0], [Set to "yes" if building a shared library automatically hardcodes DIR into the library and all subsequent libraries and executables linked against it]) _LT_TAGDECL([], [inherit_rpath], [0], [Set to yes if linker adds runtime paths of dependent libraries to runtime path list]) _LT_TAGDECL([], [link_all_deplibs], [0], [Whether libtool must link a program against all its dependency libraries]) _LT_TAGDECL([], [always_export_symbols], [0], [Set to "yes" if exported symbols are required]) _LT_TAGDECL([], [export_symbols_cmds], [2], [The commands to list exported symbols]) _LT_TAGDECL([], [exclude_expsyms], [1], [Symbols that should not be listed in the preloaded symbols]) _LT_TAGDECL([], [include_expsyms], [1], [Symbols that must always be exported]) _LT_TAGDECL([], [prelink_cmds], [2], [Commands necessary for linking programs (against libraries) with templates]) _LT_TAGDECL([], [postlink_cmds], [2], [Commands necessary for finishing linking programs]) _LT_TAGDECL([], [file_list_spec], [1], [Specify filename containing input files]) dnl FIXME: Not yet implemented dnl _LT_TAGDECL([], [thread_safe_flag_spec], [1], dnl [Compiler flag to generate thread safe objects]) ])# _LT_LINKER_SHLIBS # _LT_LANG_C_CONFIG([TAG]) # ------------------------ # Ensure that the configuration variables for a C compiler are suitably # defined. These variables are subsequently used by _LT_CONFIG to write # the compiler configuration to 'libtool'. m4_defun([_LT_LANG_C_CONFIG], [m4_require([_LT_DECL_EGREP])dnl lt_save_CC=$CC AC_LANG_PUSH(C) # Source file extension for C test sources. ac_ext=c # Object file extension for compiled C test sources. objext=o _LT_TAGVAR(objext, $1)=$objext # Code to be used in simple compile tests lt_simple_compile_test_code="int some_variable = 0;" # Code to be used in simple link tests lt_simple_link_test_code='int main(void){return(0);}' _LT_TAG_COMPILER # Save the default compiler, since it gets overwritten when the other # tags are being tested, and _LT_TAGVAR(compiler, []) is a NOP. compiler_DEFAULT=$CC # save warnings/boilerplate of simple test code _LT_COMPILER_BOILERPLATE _LT_LINKER_BOILERPLATE ## CAVEAT EMPTOR: ## There is no encapsulation within the following macros, do not change ## the running order or otherwise move them around unless you know exactly ## what you are doing... if test -n "$compiler"; then _LT_COMPILER_NO_RTTI($1) _LT_COMPILER_PIC($1) _LT_COMPILER_C_O($1) _LT_COMPILER_FILE_LOCKS($1) _LT_LINKER_SHLIBS($1) _LT_SYS_DYNAMIC_LINKER($1) _LT_LINKER_HARDCODE_LIBPATH($1) LT_SYS_DLOPEN_SELF _LT_CMD_STRIPLIB # Report what library types will actually be built AC_MSG_CHECKING([if libtool supports shared libraries]) AC_MSG_RESULT([$can_build_shared]) AC_MSG_CHECKING([whether to build shared libraries]) test no = "$can_build_shared" && enable_shared=no # On AIX, shared libraries and static libraries use the same namespace, and # are all built from PIC. case $host_os in aix3*) test yes = "$enable_shared" && enable_static=no if test -n "$RANLIB"; then archive_cmds="$archive_cmds~\$RANLIB \$lib" postinstall_cmds='$RANLIB $lib' fi ;; aix[[4-9]]*) if test ia64 != "$host_cpu"; then case $enable_shared,$with_aix_soname,$aix_use_runtimelinking in yes,aix,yes) ;; # shared object as lib.so file only yes,svr4,*) ;; # shared object as lib.so archive member only yes,*) enable_static=no ;; # shared object in lib.a archive as well esac fi ;; esac AC_MSG_RESULT([$enable_shared]) AC_MSG_CHECKING([whether to build static libraries]) # Make sure either enable_shared or enable_static is yes. test yes = "$enable_shared" || enable_static=yes AC_MSG_RESULT([$enable_static]) _LT_CONFIG($1) fi AC_LANG_POP CC=$lt_save_CC ])# _LT_LANG_C_CONFIG # _LT_LANG_CXX_CONFIG([TAG]) # -------------------------- # Ensure that the configuration variables for a C++ compiler are suitably # defined. These variables are subsequently used by _LT_CONFIG to write # the compiler configuration to 'libtool'. m4_defun([_LT_LANG_CXX_CONFIG], [m4_require([_LT_FILEUTILS_DEFAULTS])dnl m4_require([_LT_DECL_EGREP])dnl m4_require([_LT_PATH_MANIFEST_TOOL])dnl if test -n "$CXX" && ( test no != "$CXX" && ( (test g++ = "$CXX" && `g++ -v >/dev/null 2>&1` ) || (test g++ != "$CXX"))); then AC_PROG_CXXCPP else _lt_caught_CXX_error=yes fi AC_LANG_PUSH(C++) _LT_TAGVAR(archive_cmds_need_lc, $1)=no _LT_TAGVAR(allow_undefined_flag, $1)= _LT_TAGVAR(always_export_symbols, $1)=no _LT_TAGVAR(archive_expsym_cmds, $1)= _LT_TAGVAR(compiler_needs_object, $1)=no _LT_TAGVAR(export_dynamic_flag_spec, $1)= _LT_TAGVAR(hardcode_direct, $1)=no _LT_TAGVAR(hardcode_direct_absolute, $1)=no _LT_TAGVAR(hardcode_libdir_flag_spec, $1)= _LT_TAGVAR(hardcode_libdir_separator, $1)= _LT_TAGVAR(hardcode_minus_L, $1)=no _LT_TAGVAR(hardcode_shlibpath_var, $1)=unsupported _LT_TAGVAR(hardcode_automatic, $1)=no _LT_TAGVAR(inherit_rpath, $1)=no _LT_TAGVAR(module_cmds, $1)= _LT_TAGVAR(module_expsym_cmds, $1)= _LT_TAGVAR(link_all_deplibs, $1)=unknown _LT_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds _LT_TAGVAR(reload_flag, $1)=$reload_flag _LT_TAGVAR(reload_cmds, $1)=$reload_cmds _LT_TAGVAR(no_undefined_flag, $1)= _LT_TAGVAR(whole_archive_flag_spec, $1)= _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=no # Source file extension for C++ test sources. ac_ext=cpp # Object file extension for compiled C++ test sources. objext=o _LT_TAGVAR(objext, $1)=$objext # No sense in running all these tests if we already determined that # the CXX compiler isn't working. Some variables (like enable_shared) # are currently assumed to apply to all compilers on this platform, # and will be corrupted by setting them based on a non-working compiler. if test yes != "$_lt_caught_CXX_error"; then # Code to be used in simple compile tests lt_simple_compile_test_code="int some_variable = 0;" # Code to be used in simple link tests lt_simple_link_test_code='int main(int, char *[[]]) { return(0); }' # ltmain only uses $CC for tagged configurations so make sure $CC is set. _LT_TAG_COMPILER # save warnings/boilerplate of simple test code _LT_COMPILER_BOILERPLATE _LT_LINKER_BOILERPLATE # Allow CC to be a program name with arguments. lt_save_CC=$CC lt_save_CFLAGS=$CFLAGS lt_save_LD=$LD lt_save_GCC=$GCC GCC=$GXX lt_save_with_gnu_ld=$with_gnu_ld lt_save_path_LD=$lt_cv_path_LD if test -n "${lt_cv_prog_gnu_ldcxx+set}"; then lt_cv_prog_gnu_ld=$lt_cv_prog_gnu_ldcxx else $as_unset lt_cv_prog_gnu_ld fi if test -n "${lt_cv_path_LDCXX+set}"; then lt_cv_path_LD=$lt_cv_path_LDCXX else $as_unset lt_cv_path_LD fi test -z "${LDCXX+set}" || LD=$LDCXX CC=${CXX-"c++"} CFLAGS=$CXXFLAGS compiler=$CC _LT_TAGVAR(compiler, $1)=$CC _LT_CC_BASENAME([$compiler]) if test -n "$compiler"; then # We don't want -fno-exception when compiling C++ code, so set the # no_builtin_flag separately if test yes = "$GXX"; then _LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)=' -fno-builtin' else _LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)= fi if test yes = "$GXX"; then # Set up default GNU C++ configuration LT_PATH_LD # Check if GNU C++ uses GNU ld as the underlying linker, since the # archiving commands below assume that GNU ld is being used. if test yes = "$with_gnu_ld"; then _LT_TAGVAR(archive_cmds, $1)='$CC $pic_flag -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $wl$soname -o $lib' _LT_TAGVAR(archive_expsym_cmds, $1)='$CC $pic_flag -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $wl$soname $wl-retain-symbols-file $wl$export_symbols -o $lib' _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath $wl$libdir' _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl--export-dynamic' # If archive_cmds runs LD, not CC, wlarc should be empty # XXX I think wlarc can be eliminated in ltcf-cxx, but I need to # investigate it a little bit more. (MM) wlarc='$wl' # ancient GNU ld didn't support --whole-archive et. al. if $LD --help 2>&1 | $GREP 'no-whole-archive' > /dev/null; then _LT_TAGVAR(whole_archive_flag_spec, $1)=$wlarc'--whole-archive$convenience '$wlarc'--no-whole-archive' else _LT_TAGVAR(whole_archive_flag_spec, $1)= fi else with_gnu_ld=no wlarc= # A generic and very simple default shared library creation # command for GNU C++ for the case where it uses the native # linker, instead of GNU ld. If possible, this setting should # overridden to take advantage of the native linker features on # the platform it is being used on. _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $lib' fi # Commands to make compiler produce verbose output that lists # what "hidden" libraries, object files and flags are used when # linking a shared library. output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP " [[-]]L"' else GXX=no with_gnu_ld=no wlarc= fi # PORTME: fill in a description of your system's C++ link characteristics AC_MSG_CHECKING([whether the $compiler linker ($LD) supports shared libraries]) _LT_TAGVAR(ld_shlibs, $1)=yes case $host_os in aix3*) # FIXME: insert proper C++ library support _LT_TAGVAR(ld_shlibs, $1)=no ;; aix[[4-9]]*) if test ia64 = "$host_cpu"; then # On IA64, the linker does run time linking by default, so we don't # have to do anything special. aix_use_runtimelinking=no exp_sym_flag='-Bexport' no_entry_flag= else aix_use_runtimelinking=no # Test if we are trying to use run time linking or normal # AIX style linking. If -brtl is somewhere in LDFLAGS, we # have runtime linking enabled, and use it for executables. # For shared libraries, we enable/disable runtime linking # depending on the kind of the shared library created - # when "with_aix_soname,aix_use_runtimelinking" is: # "aix,no" lib.a(lib.so.V) shared, rtl:no, for executables # "aix,yes" lib.so shared, rtl:yes, for executables # lib.a static archive # "both,no" lib.so.V(shr.o) shared, rtl:yes # lib.a(lib.so.V) shared, rtl:no, for executables # "both,yes" lib.so.V(shr.o) shared, rtl:yes, for executables # lib.a(lib.so.V) shared, rtl:no # "svr4,*" lib.so.V(shr.o) shared, rtl:yes, for executables # lib.a static archive case $host_os in aix4.[[23]]|aix4.[[23]].*|aix[[5-9]]*) for ld_flag in $LDFLAGS; do case $ld_flag in *-brtl*) aix_use_runtimelinking=yes break ;; esac done if test svr4,no = "$with_aix_soname,$aix_use_runtimelinking"; then # With aix-soname=svr4, we create the lib.so.V shared archives only, # so we don't have lib.a shared libs to link our executables. # We have to force runtime linking in this case. aix_use_runtimelinking=yes LDFLAGS="$LDFLAGS -Wl,-brtl" fi ;; esac exp_sym_flag='-bexport' no_entry_flag='-bnoentry' fi # When large executables or shared objects are built, AIX ld can # have problems creating the table of contents. If linking a library # or program results in "error TOC overflow" add -mminimal-toc to # CXXFLAGS/CFLAGS for g++/gcc. In the cases where that is not # enough to fix the problem, add -Wl,-bbigtoc to LDFLAGS. _LT_TAGVAR(archive_cmds, $1)='' _LT_TAGVAR(hardcode_direct, $1)=yes _LT_TAGVAR(hardcode_direct_absolute, $1)=yes _LT_TAGVAR(hardcode_libdir_separator, $1)=':' _LT_TAGVAR(link_all_deplibs, $1)=yes _LT_TAGVAR(file_list_spec, $1)='$wl-f,' case $with_aix_soname,$aix_use_runtimelinking in aix,*) ;; # no import file svr4,* | *,yes) # use import file # The Import File defines what to hardcode. _LT_TAGVAR(hardcode_direct, $1)=no _LT_TAGVAR(hardcode_direct_absolute, $1)=no ;; esac if test yes = "$GXX"; then case $host_os in aix4.[[012]]|aix4.[[012]].*) # We only want to do this on AIX 4.2 and lower, the check # below for broken collect2 doesn't work under 4.3+ collect2name=`$CC -print-prog-name=collect2` if test -f "$collect2name" && strings "$collect2name" | $GREP resolve_lib_name >/dev/null then # We have reworked collect2 : else # We have old collect2 _LT_TAGVAR(hardcode_direct, $1)=unsupported # It fails to find uninstalled libraries when the uninstalled # path is not listed in the libpath. Setting hardcode_minus_L # to unsupported forces relinking _LT_TAGVAR(hardcode_minus_L, $1)=yes _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' _LT_TAGVAR(hardcode_libdir_separator, $1)= fi esac shared_flag='-shared' if test yes = "$aix_use_runtimelinking"; then shared_flag=$shared_flag' $wl-G' fi # Need to ensure runtime linking is disabled for the traditional # shared library, or the linker may eventually find shared libraries # /with/ Import File - we do not want to mix them. shared_flag_aix='-shared' shared_flag_svr4='-shared $wl-G' else # not using gcc if test ia64 = "$host_cpu"; then # VisualAge C++, Version 5.5 for AIX 5L for IA-64, Beta 3 Release # chokes on -Wl,-G. The following line is correct: shared_flag='-G' else if test yes = "$aix_use_runtimelinking"; then shared_flag='$wl-G' else shared_flag='$wl-bM:SRE' fi shared_flag_aix='$wl-bM:SRE' shared_flag_svr4='$wl-G' fi fi _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl-bexpall' # It seems that -bexpall does not export symbols beginning with # underscore (_), so it is better to generate a list of symbols to # export. _LT_TAGVAR(always_export_symbols, $1)=yes if test aix,yes = "$with_aix_soname,$aix_use_runtimelinking"; then # Warning - without using the other runtime loading flags (-brtl), # -berok will link without error, but may produce a broken library. # The "-G" linker flag allows undefined symbols. _LT_TAGVAR(no_undefined_flag, $1)='-bernotok' # Determine the default libpath from the value encoded in an empty # executable. _LT_SYS_MODULE_PATH_AIX([$1]) _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-blibpath:$libdir:'"$aix_libpath" _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -o $output_objdir/$soname $libobjs $deplibs $wl'$no_entry_flag' $compiler_flags `if test -n "$allow_undefined_flag"; then func_echo_all "$wl$allow_undefined_flag"; else :; fi` $wl'$exp_sym_flag:\$export_symbols' '$shared_flag else if test ia64 = "$host_cpu"; then _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-R $libdir:/usr/lib:/lib' _LT_TAGVAR(allow_undefined_flag, $1)="-z nodefs" _LT_TAGVAR(archive_expsym_cmds, $1)="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs '"\$wl$no_entry_flag"' $compiler_flags $wl$allow_undefined_flag '"\$wl$exp_sym_flag:\$export_symbols" else # Determine the default libpath from the value encoded in an # empty executable. _LT_SYS_MODULE_PATH_AIX([$1]) _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-blibpath:$libdir:'"$aix_libpath" # Warning - without using the other run time loading flags, # -berok will link without error, but may produce a broken library. _LT_TAGVAR(no_undefined_flag, $1)=' $wl-bernotok' _LT_TAGVAR(allow_undefined_flag, $1)=' $wl-berok' if test yes = "$with_gnu_ld"; then # We only use this code for GNU lds that support --whole-archive. _LT_TAGVAR(whole_archive_flag_spec, $1)='$wl--whole-archive$convenience $wl--no-whole-archive' else # Exported symbols can be pulled into shared objects from archives _LT_TAGVAR(whole_archive_flag_spec, $1)='$convenience' fi _LT_TAGVAR(archive_cmds_need_lc, $1)=yes _LT_TAGVAR(archive_expsym_cmds, $1)='$RM -r $output_objdir/$realname.d~$MKDIR $output_objdir/$realname.d' # -brtl affects multiple linker settings, -berok does not and is overridden later compiler_flags_filtered='`func_echo_all "$compiler_flags " | $SED -e "s%-brtl\\([[, ]]\\)%-berok\\1%g"`' if test svr4 != "$with_aix_soname"; then # This is similar to how AIX traditionally builds its shared # libraries. Need -bnortl late, we may have -brtl in LDFLAGS. _LT_TAGVAR(archive_expsym_cmds, $1)="$_LT_TAGVAR(archive_expsym_cmds, $1)"'~$CC '$shared_flag_aix' -o $output_objdir/$realname.d/$soname $libobjs $deplibs $wl-bnoentry '$compiler_flags_filtered'$wl-bE:$export_symbols$allow_undefined_flag~$AR $AR_FLAGS $output_objdir/$libname$release.a $output_objdir/$realname.d/$soname' fi if test aix != "$with_aix_soname"; then _LT_TAGVAR(archive_expsym_cmds, $1)="$_LT_TAGVAR(archive_expsym_cmds, $1)"'~$CC '$shared_flag_svr4' -o $output_objdir/$realname.d/$shared_archive_member_spec.o $libobjs $deplibs $wl-bnoentry '$compiler_flags_filtered'$wl-bE:$export_symbols$allow_undefined_flag~$STRIP -e $output_objdir/$realname.d/$shared_archive_member_spec.o~( func_echo_all "#! $soname($shared_archive_member_spec.o)"; if test shr_64 = "$shared_archive_member_spec"; then func_echo_all "# 64"; else func_echo_all "# 32"; fi; cat $export_symbols ) > $output_objdir/$realname.d/$shared_archive_member_spec.imp~$AR $AR_FLAGS $output_objdir/$soname $output_objdir/$realname.d/$shared_archive_member_spec.o $output_objdir/$realname.d/$shared_archive_member_spec.imp' else # used by -dlpreopen to get the symbols _LT_TAGVAR(archive_expsym_cmds, $1)="$_LT_TAGVAR(archive_expsym_cmds, $1)"'~$MV $output_objdir/$realname.d/$soname $output_objdir' fi _LT_TAGVAR(archive_expsym_cmds, $1)="$_LT_TAGVAR(archive_expsym_cmds, $1)"'~$RM -r $output_objdir/$realname.d' fi fi ;; beos*) if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then _LT_TAGVAR(allow_undefined_flag, $1)=unsupported # Joseph Beckenbach says some releases of gcc # support --undefined. This deserves some investigation. FIXME _LT_TAGVAR(archive_cmds, $1)='$CC -nostart $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' else _LT_TAGVAR(ld_shlibs, $1)=no fi ;; chorus*) case $cc_basename in *) # FIXME: insert proper C++ library support _LT_TAGVAR(ld_shlibs, $1)=no ;; esac ;; cygwin* | mingw* | windows* | pw32* | cegcc*) case $GXX,$cc_basename in ,cl* | no,cl* | ,icl* | no,icl*) # Native MSVC or ICC # hardcode_libdir_flag_spec is actually meaningless, as there is # no search path for DLLs. _LT_TAGVAR(hardcode_libdir_flag_spec, $1)=' ' _LT_TAGVAR(allow_undefined_flag, $1)=unsupported _LT_TAGVAR(always_export_symbols, $1)=yes _LT_TAGVAR(file_list_spec, $1)='@' # Tell ltmain to make .lib files, not .a files. libext=lib # Tell ltmain to make .dll files, not .so files. shrext_cmds=.dll # FIXME: Setting linknames here is a bad hack. _LT_TAGVAR(archive_cmds, $1)='$CC -o $output_objdir/$soname $libobjs $compiler_flags $deplibs -Wl,-DLL,-IMPLIB:"$tool_output_objdir$libname.dll.lib"~linknames=' _LT_TAGVAR(archive_expsym_cmds, $1)='if _LT_DLL_DEF_P([$export_symbols]); then cp "$export_symbols" "$output_objdir/$soname.def"; echo "$tool_output_objdir$soname.def" > "$output_objdir/$soname.exp"; else $SED -e '\''s/^/-link -EXPORT:/'\'' < $export_symbols > $output_objdir/$soname.exp; fi~ $CC -o $tool_output_objdir$soname $libobjs $compiler_flags $deplibs "@$tool_output_objdir$soname.exp" -Wl,-DLL,-IMPLIB:"$tool_output_objdir$libname.dll.lib"~ linknames=' # The linker will not automatically build a static lib if we build a DLL. # _LT_TAGVAR(old_archive_from_new_cmds, $1)='true' _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes # Don't use ranlib _LT_TAGVAR(old_postinstall_cmds, $1)='chmod 644 $oldlib' _LT_TAGVAR(postlink_cmds, $1)='lt_outputfile="@OUTPUT@"~ lt_tool_outputfile="@TOOL_OUTPUT@"~ case $lt_outputfile in *.exe|*.EXE) ;; *) lt_outputfile=$lt_outputfile.exe lt_tool_outputfile=$lt_tool_outputfile.exe ;; esac~ func_to_tool_file "$lt_outputfile"~ if test : != "$MANIFEST_TOOL" && test -f "$lt_outputfile.manifest"; then $MANIFEST_TOOL -manifest "$lt_tool_outputfile.manifest" -outputresource:"$lt_tool_outputfile" || exit 1; $RM "$lt_outputfile.manifest"; fi' ;; *) # g++ # _LT_TAGVAR(hardcode_libdir_flag_spec, $1) is actually meaningless, # as there is no search path for DLLs. _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl--export-all-symbols' _LT_TAGVAR(allow_undefined_flag, $1)=unsupported _LT_TAGVAR(always_export_symbols, $1)=no _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes _LT_TAGVAR(file_list_spec, $1)='@' if $LD --help 2>&1 | $GREP 'auto-import' > /dev/null; then _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $output_objdir/$soname $wl--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib' # If the export-symbols file already is a .def file, use it as # is; otherwise, prepend EXPORTS... _LT_TAGVAR(archive_expsym_cmds, $1)='if _LT_DLL_DEF_P([$export_symbols]); then cp $export_symbols $output_objdir/$soname.def; else echo EXPORTS > $output_objdir/$soname.def; cat $export_symbols >> $output_objdir/$soname.def; fi~ $CC -shared -nostdlib $output_objdir/$soname.def $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $output_objdir/$soname $wl--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib' else _LT_TAGVAR(ld_shlibs, $1)=no fi ;; esac ;; darwin* | rhapsody*) _LT_DARWIN_LINKER_FEATURES($1) ;; os2*) _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' _LT_TAGVAR(hardcode_minus_L, $1)=yes _LT_TAGVAR(allow_undefined_flag, $1)=unsupported shrext_cmds=.dll _LT_TAGVAR(archive_cmds, $1)='$ECHO "LIBRARY ${soname%$shared_ext} INITINSTANCE TERMINSTANCE" > $output_objdir/$libname.def~ $ECHO "DESCRIPTION \"$libname\"" >> $output_objdir/$libname.def~ $ECHO "DATA MULTIPLE NONSHARED" >> $output_objdir/$libname.def~ $ECHO EXPORTS >> $output_objdir/$libname.def~ emxexp $libobjs | $SED /"_DLL_InitTerm"/d >> $output_objdir/$libname.def~ $CC -Zdll -Zcrtdll -o $output_objdir/$soname $libobjs $deplibs $compiler_flags $output_objdir/$libname.def~ emximp -o $lib $output_objdir/$libname.def' _LT_TAGVAR(archive_expsym_cmds, $1)='$ECHO "LIBRARY ${soname%$shared_ext} INITINSTANCE TERMINSTANCE" > $output_objdir/$libname.def~ $ECHO "DESCRIPTION \"$libname\"" >> $output_objdir/$libname.def~ $ECHO "DATA MULTIPLE NONSHARED" >> $output_objdir/$libname.def~ $ECHO EXPORTS >> $output_objdir/$libname.def~ prefix_cmds="$SED"~ if test EXPORTS = "`$SED 1q $export_symbols`"; then prefix_cmds="$prefix_cmds -e 1d"; fi~ prefix_cmds="$prefix_cmds -e \"s/^\(.*\)$/_\1/g\""~ cat $export_symbols | $prefix_cmds >> $output_objdir/$libname.def~ $CC -Zdll -Zcrtdll -o $output_objdir/$soname $libobjs $deplibs $compiler_flags $output_objdir/$libname.def~ emximp -o $lib $output_objdir/$libname.def' _LT_TAGVAR(old_archive_from_new_cmds, $1)='emximp -o $output_objdir/${libname}_dll.a $output_objdir/$libname.def' _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes _LT_TAGVAR(file_list_spec, $1)='@' ;; dgux*) case $cc_basename in ec++*) # FIXME: insert proper C++ library support _LT_TAGVAR(ld_shlibs, $1)=no ;; ghcx*) # Green Hills C++ Compiler # FIXME: insert proper C++ library support _LT_TAGVAR(ld_shlibs, $1)=no ;; *) # FIXME: insert proper C++ library support _LT_TAGVAR(ld_shlibs, $1)=no ;; esac ;; freebsd2.*) # C++ shared libraries reported to be fairly broken before # switch to ELF _LT_TAGVAR(ld_shlibs, $1)=no ;; freebsd-elf*) _LT_TAGVAR(archive_cmds_need_lc, $1)=no ;; freebsd* | dragonfly* | midnightbsd*) # FreeBSD 3 and later use GNU C++ and GNU ld with standard ELF # conventions _LT_TAGVAR(ld_shlibs, $1)=yes ;; haiku*) _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' _LT_TAGVAR(link_all_deplibs, $1)=no ;; hpux9*) _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl+b $wl$libdir' _LT_TAGVAR(hardcode_libdir_separator, $1)=: _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl-E' _LT_TAGVAR(hardcode_direct, $1)=yes _LT_TAGVAR(hardcode_minus_L, $1)=yes # Not in the search PATH, # but as the default # location of the library. case $cc_basename in CC*) # FIXME: insert proper C++ library support _LT_TAGVAR(ld_shlibs, $1)=no ;; aCC*) _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/$soname~$CC -b $wl+b $wl$install_libdir -o $output_objdir/$soname $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~test "x$output_objdir/$soname" = "x$lib" || mv $output_objdir/$soname $lib' # Commands to make compiler produce verbose output that lists # what "hidden" libraries, object files and flags are used when # linking a shared library. # # There doesn't appear to be a way to prevent this compiler from # explicitly linking system object files so we need to strip them # from the output so that they don't get included in the library # dependencies. output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | $EGREP "[[-]]L"`; list= ; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "$list"' ;; *) if test yes = "$GXX"; then _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/$soname~$CC -shared -nostdlib $pic_flag $wl+b $wl$install_libdir -o $output_objdir/$soname $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~test "x$output_objdir/$soname" = "x$lib" || mv $output_objdir/$soname $lib' else # FIXME: insert proper C++ library support _LT_TAGVAR(ld_shlibs, $1)=no fi ;; esac ;; hpux10*|hpux11*) if test no = "$with_gnu_ld"; then _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl+b $wl$libdir' _LT_TAGVAR(hardcode_libdir_separator, $1)=: case $host_cpu in hppa*64*|ia64*) ;; *) _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl-E' ;; esac fi case $host_cpu in hppa*64*|ia64*) _LT_TAGVAR(hardcode_direct, $1)=no _LT_TAGVAR(hardcode_shlibpath_var, $1)=no ;; *) _LT_TAGVAR(hardcode_direct, $1)=yes _LT_TAGVAR(hardcode_direct_absolute, $1)=yes _LT_TAGVAR(hardcode_minus_L, $1)=yes # Not in the search PATH, # but as the default # location of the library. ;; esac case $cc_basename in CC*) # FIXME: insert proper C++ library support _LT_TAGVAR(ld_shlibs, $1)=no ;; aCC*) case $host_cpu in hppa*64*) _LT_TAGVAR(archive_cmds, $1)='$CC -b $wl+h $wl$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' ;; ia64*) _LT_TAGVAR(archive_cmds, $1)='$CC -b $wl+h $wl$soname $wl+nodefaultrpath -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' ;; *) _LT_TAGVAR(archive_cmds, $1)='$CC -b $wl+h $wl$soname $wl+b $wl$install_libdir -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' ;; esac # Commands to make compiler produce verbose output that lists # what "hidden" libraries, object files and flags are used when # linking a shared library. # # There doesn't appear to be a way to prevent this compiler from # explicitly linking system object files so we need to strip them # from the output so that they don't get included in the library # dependencies. output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | $GREP " [[-]]L"`; list= ; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "$list"' ;; *) if test yes = "$GXX"; then if test no = "$with_gnu_ld"; then case $host_cpu in hppa*64*) _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib -fPIC $wl+h $wl$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' ;; ia64*) _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $pic_flag $wl+h $wl$soname $wl+nodefaultrpath -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' ;; *) _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $pic_flag $wl+h $wl$soname $wl+b $wl$install_libdir -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' ;; esac fi else # FIXME: insert proper C++ library support _LT_TAGVAR(ld_shlibs, $1)=no fi ;; esac ;; interix[[3-9]]*) _LT_TAGVAR(hardcode_direct, $1)=no _LT_TAGVAR(hardcode_shlibpath_var, $1)=no _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath,$libdir' _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl-E' # Hack: On Interix 3.x, we cannot compile PIC because of a broken gcc. # Instead, shared libraries are loaded at an image base (0x10000000 by # default) and relocated if they conflict, which is a slow very memory # consuming and fragmenting process. To avoid this, we pick a random, # 256 KiB-aligned image base between 0x50000000 and 0x6FFC0000 at link # time. Moving up from 0x10000000 also allows more sbrk(2) space. _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-h,$soname $wl--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' _LT_TAGVAR(archive_expsym_cmds, $1)='$SED "s|^|_|" $export_symbols >$output_objdir/$soname.expsym~$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-h,$soname $wl--retain-symbols-file,$output_objdir/$soname.expsym $wl--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' ;; irix5* | irix6*) case $cc_basename in CC*) # SGI C++ _LT_TAGVAR(archive_cmds, $1)='$CC -shared -all -multigot $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry $output_objdir/so_locations -o $lib' # Archives containing C++ object files must be created using # "CC -ar", where "CC" is the IRIX C++ compiler. This is # necessary to make sure instantiated templates are included # in the archive. _LT_TAGVAR(old_archive_cmds, $1)='$CC -ar -WR,-u -o $oldlib $oldobjs' ;; *) if test yes = "$GXX"; then if test no = "$with_gnu_ld"; then _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $wl$soname `test -n "$verstring" && func_echo_all "$wl-set_version $wl$verstring"` $wl-update_registry $wl$output_objdir/so_locations -o $lib' else _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $wl$soname `test -n "$verstring" && func_echo_all "$wl-set_version $wl$verstring"` -o $lib' fi fi _LT_TAGVAR(link_all_deplibs, $1)=yes ;; esac _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath $wl$libdir' _LT_TAGVAR(hardcode_libdir_separator, $1)=: _LT_TAGVAR(inherit_rpath, $1)=yes ;; linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*) case $cc_basename in KCC*) # Kuck and Associates, Inc. (KAI) C++ Compiler # KCC will only create a shared library if the output file # ends with ".so" (or ".sl" for HP-UX), so rename the library # to its proper name (with version) after linking. _LT_TAGVAR(archive_cmds, $1)='tempext=`echo $shared_ext | $SED -e '\''s/\([[^()0-9A-Za-z{}]]\)/\\\\\1/g'\''`; templib=`echo $lib | $SED -e "s/\$tempext\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib; mv \$templib $lib' _LT_TAGVAR(archive_expsym_cmds, $1)='tempext=`echo $shared_ext | $SED -e '\''s/\([[^()0-9A-Za-z{}]]\)/\\\\\1/g'\''`; templib=`echo $lib | $SED -e "s/\$tempext\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib $wl-retain-symbols-file,$export_symbols; mv \$templib $lib' # Commands to make compiler produce verbose output that lists # what "hidden" libraries, object files and flags are used when # linking a shared library. # # There doesn't appear to be a way to prevent this compiler from # explicitly linking system object files so we need to strip them # from the output so that they don't get included in the library # dependencies. output_verbose_link_cmd='templist=`$CC $CFLAGS -v conftest.$objext -o libconftest$shared_ext 2>&1 | $GREP "ld"`; rm -f libconftest$shared_ext; list= ; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "$list"' _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath,$libdir' _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl--export-dynamic' # Archives containing C++ object files must be created using # "CC -Bstatic", where "CC" is the KAI C++ compiler. _LT_TAGVAR(old_archive_cmds, $1)='$CC -Bstatic -o $oldlib $oldobjs' ;; icpc* | ecpc* ) # Intel C++ with_gnu_ld=yes # version 8.0 and above of icpc choke on multiply defined symbols # if we add $predep_objects and $postdep_objects, however 7.1 and # earlier do not add the objects themselves. case `$CC -V 2>&1` in *"Version 7."*) _LT_TAGVAR(archive_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $wl$soname -o $lib' _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $wl$soname $wl-retain-symbols-file $wl$export_symbols -o $lib' ;; *) # Version 8.0 or newer tmp_idyn= case $host_cpu in ia64*) tmp_idyn=' -i_dynamic';; esac _LT_TAGVAR(archive_cmds, $1)='$CC -shared'"$tmp_idyn"' $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared'"$tmp_idyn"' $libobjs $deplibs $compiler_flags $wl-soname $wl$soname $wl-retain-symbols-file $wl$export_symbols -o $lib' ;; esac _LT_TAGVAR(archive_cmds_need_lc, $1)=no _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath,$libdir' _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl--export-dynamic' _LT_TAGVAR(whole_archive_flag_spec, $1)='$wl--whole-archive$convenience $wl--no-whole-archive' ;; pgCC* | pgcpp*) # Portland Group C++ compiler case `$CC -V` in *pgCC\ [[1-5]].* | *pgcpp\ [[1-5]].*) _LT_TAGVAR(prelink_cmds, $1)='tpldir=Template.dir~ rm -rf $tpldir~ $CC --prelink_objects --instantiation_dir $tpldir $objs $libobjs $compile_deplibs~ compile_command="$compile_command `find $tpldir -name \*.o | sort | $NL2SP`"' _LT_TAGVAR(old_archive_cmds, $1)='tpldir=Template.dir~ rm -rf $tpldir~ $CC --prelink_objects --instantiation_dir $tpldir $oldobjs$old_deplibs~ $AR $AR_FLAGS $oldlib$oldobjs$old_deplibs `find $tpldir -name \*.o | sort | $NL2SP`~ $RANLIB $oldlib' _LT_TAGVAR(archive_cmds, $1)='tpldir=Template.dir~ rm -rf $tpldir~ $CC --prelink_objects --instantiation_dir $tpldir $predep_objects $libobjs $deplibs $convenience $postdep_objects~ $CC -shared $pic_flag $predep_objects $libobjs $deplibs `find $tpldir -name \*.o | sort | $NL2SP` $postdep_objects $compiler_flags $wl-soname $wl$soname -o $lib' _LT_TAGVAR(archive_expsym_cmds, $1)='tpldir=Template.dir~ rm -rf $tpldir~ $CC --prelink_objects --instantiation_dir $tpldir $predep_objects $libobjs $deplibs $convenience $postdep_objects~ $CC -shared $pic_flag $predep_objects $libobjs $deplibs `find $tpldir -name \*.o | sort | $NL2SP` $postdep_objects $compiler_flags $wl-soname $wl$soname $wl-retain-symbols-file $wl$export_symbols -o $lib' ;; *) # Version 6 and above use weak symbols _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $wl$soname -o $lib' _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $wl$soname $wl-retain-symbols-file $wl$export_symbols -o $lib' ;; esac _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl--rpath $wl$libdir' _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl--export-dynamic' _LT_TAGVAR(whole_archive_flag_spec, $1)='$wl--whole-archive`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; func_echo_all \"$new_convenience\"` $wl--no-whole-archive' ;; cxx*) # Compaq C++ _LT_TAGVAR(archive_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $wl$soname -o $lib' _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $wl$soname -o $lib $wl-retain-symbols-file $wl$export_symbols' runpath_var=LD_RUN_PATH _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-rpath $libdir' _LT_TAGVAR(hardcode_libdir_separator, $1)=: # Commands to make compiler produce verbose output that lists # what "hidden" libraries, object files and flags are used when # linking a shared library. # # There doesn't appear to be a way to prevent this compiler from # explicitly linking system object files so we need to strip them # from the output so that they don't get included in the library # dependencies. output_verbose_link_cmd='templist=`$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP "ld"`; templist=`func_echo_all "$templist" | $SED "s/\(^.*ld.*\)\( .*ld .*$\)/\1/"`; list= ; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "X$list" | $Xsed' ;; xl* | mpixl* | bgxl*) # IBM XL 8.0 on PPC, with GNU ld _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath $wl$libdir' _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl--export-dynamic' _LT_TAGVAR(archive_cmds, $1)='$CC -qmkshrobj $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' if test yes = "$supports_anon_versioning"; then _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $output_objdir/$libname.ver~ cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~ echo "local: *; };" >> $output_objdir/$libname.ver~ $CC -qmkshrobj $libobjs $deplibs $compiler_flags $wl-soname $wl$soname $wl-version-script $wl$output_objdir/$libname.ver -o $lib' fi ;; *) case `$CC -V 2>&1 | $SED 5q` in *Sun\ C*) # Sun C++ 5.9 _LT_TAGVAR(no_undefined_flag, $1)=' -zdefs' _LT_TAGVAR(archive_cmds, $1)='$CC -G$allow_undefined_flag -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -G$allow_undefined_flag -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-retain-symbols-file $wl$export_symbols' _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' _LT_TAGVAR(whole_archive_flag_spec, $1)='$wl--whole-archive`new_convenience=; for conv in $convenience\"\"; do test -z \"$conv\" || new_convenience=\"$new_convenience,$conv\"; done; func_echo_all \"$new_convenience\"` $wl--no-whole-archive' _LT_TAGVAR(compiler_needs_object, $1)=yes # Not sure whether something based on # $CC $CFLAGS -v conftest.$objext -o libconftest$shared_ext 2>&1 # would be better. output_verbose_link_cmd='func_echo_all' # Archives containing C++ object files must be created using # "CC -xar", where "CC" is the Sun C++ compiler. This is # necessary to make sure instantiated templates are included # in the archive. _LT_TAGVAR(old_archive_cmds, $1)='$CC -xar -o $oldlib $oldobjs' ;; esac ;; esac ;; lynxos*) # FIXME: insert proper C++ library support _LT_TAGVAR(ld_shlibs, $1)=no ;; m88k*) # FIXME: insert proper C++ library support _LT_TAGVAR(ld_shlibs, $1)=no ;; mvs*) case $cc_basename in cxx*) # FIXME: insert proper C++ library support _LT_TAGVAR(ld_shlibs, $1)=no ;; *) # FIXME: insert proper C++ library support _LT_TAGVAR(ld_shlibs, $1)=no ;; esac ;; *-mlibc) _LT_TAGVAR(ld_shlibs, $1)=yes ;; netbsd*) if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $predep_objects $libobjs $deplibs $postdep_objects $linker_flags' wlarc= _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' _LT_TAGVAR(hardcode_direct, $1)=yes _LT_TAGVAR(hardcode_shlibpath_var, $1)=no fi # Workaround some broken pre-1.5 toolchains output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP conftest.$objext | $SED -e "s:-lgcc -lc -lgcc::"' ;; *nto* | *qnx*) _LT_TAGVAR(ld_shlibs, $1)=yes ;; openbsd*) if test -f /usr/libexec/ld.so; then _LT_TAGVAR(hardcode_direct, $1)=yes _LT_TAGVAR(hardcode_shlibpath_var, $1)=no _LT_TAGVAR(hardcode_direct_absolute, $1)=yes _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $lib' _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath,$libdir' if test -z "`echo __ELF__ | $CC -E - | grep __ELF__`"; then _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-retain-symbols-file,$export_symbols -o $lib' _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl-E' _LT_TAGVAR(whole_archive_flag_spec, $1)=$wlarc'--whole-archive$convenience '$wlarc'--no-whole-archive' fi output_verbose_link_cmd=func_echo_all else _LT_TAGVAR(ld_shlibs, $1)=no fi ;; osf3* | osf4* | osf5*) case $cc_basename in KCC*) # Kuck and Associates, Inc. (KAI) C++ Compiler # KCC will only create a shared library if the output file # ends with ".so" (or ".sl" for HP-UX), so rename the library # to its proper name (with version) after linking. _LT_TAGVAR(archive_cmds, $1)='tempext=`echo $shared_ext | $SED -e '\''s/\([[^()0-9A-Za-z{}]]\)/\\\\\1/g'\''`; templib=`echo "$lib" | $SED -e "s/\$tempext\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib; mv \$templib $lib' _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath,$libdir' _LT_TAGVAR(hardcode_libdir_separator, $1)=: # Archives containing C++ object files must be created using # the KAI C++ compiler. case $host in osf3*) _LT_TAGVAR(old_archive_cmds, $1)='$CC -Bstatic -o $oldlib $oldobjs' ;; *) _LT_TAGVAR(old_archive_cmds, $1)='$CC -o $oldlib $oldobjs' ;; esac ;; RCC*) # Rational C++ 2.4.1 # FIXME: insert proper C++ library support _LT_TAGVAR(ld_shlibs, $1)=no ;; cxx*) case $host in osf3*) _LT_TAGVAR(allow_undefined_flag, $1)=' $wl-expect_unresolved $wl\*' _LT_TAGVAR(archive_cmds, $1)='$CC -shared$allow_undefined_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $soname `test -n "$verstring" && func_echo_all "$wl-set_version $verstring"` -update_registry $output_objdir/so_locations -o $lib' _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath $wl$libdir' ;; *) _LT_TAGVAR(allow_undefined_flag, $1)=' -expect_unresolved \*' _LT_TAGVAR(archive_cmds, $1)='$CC -shared$allow_undefined_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -msym -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry $output_objdir/so_locations -o $lib' _LT_TAGVAR(archive_expsym_cmds, $1)='for i in `cat $export_symbols`; do printf "%s %s\\n" -exported_symbol "\$i" >> $lib.exp; done~ echo "-hidden">> $lib.exp~ $CC -shared$allow_undefined_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -msym -soname $soname $wl-input $wl$lib.exp `test -n "$verstring" && $ECHO "-set_version $verstring"` -update_registry $output_objdir/so_locations -o $lib~ $RM $lib.exp' _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-rpath $libdir' ;; esac _LT_TAGVAR(hardcode_libdir_separator, $1)=: # Commands to make compiler produce verbose output that lists # what "hidden" libraries, object files and flags are used when # linking a shared library. # # There doesn't appear to be a way to prevent this compiler from # explicitly linking system object files so we need to strip them # from the output so that they don't get included in the library # dependencies. output_verbose_link_cmd='templist=`$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP "ld" | $GREP -v "ld:"`; templist=`func_echo_all "$templist" | $SED "s/\(^.*ld.*\)\( .*ld.*$\)/\1/"`; list= ; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "$list"' ;; *) if test yes,no = "$GXX,$with_gnu_ld"; then _LT_TAGVAR(allow_undefined_flag, $1)=' $wl-expect_unresolved $wl\*' case $host in osf3*) _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $allow_undefined_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $wl$soname `test -n "$verstring" && func_echo_all "$wl-set_version $wl$verstring"` $wl-update_registry $wl$output_objdir/so_locations -o $lib' ;; *) _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag -nostdlib $allow_undefined_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-msym $wl-soname $wl$soname `test -n "$verstring" && func_echo_all "$wl-set_version $wl$verstring"` $wl-update_registry $wl$output_objdir/so_locations -o $lib' ;; esac _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath $wl$libdir' _LT_TAGVAR(hardcode_libdir_separator, $1)=: # Commands to make compiler produce verbose output that lists # what "hidden" libraries, object files and flags are used when # linking a shared library. output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP " [[-]]L"' else # FIXME: insert proper C++ library support _LT_TAGVAR(ld_shlibs, $1)=no fi ;; esac ;; psos*) # FIXME: insert proper C++ library support _LT_TAGVAR(ld_shlibs, $1)=no ;; serenity*) ;; sunos4*) case $cc_basename in CC*) # Sun C++ 4.x # FIXME: insert proper C++ library support _LT_TAGVAR(ld_shlibs, $1)=no ;; lcc*) # Lucid # FIXME: insert proper C++ library support _LT_TAGVAR(ld_shlibs, $1)=no ;; *) # FIXME: insert proper C++ library support _LT_TAGVAR(ld_shlibs, $1)=no ;; esac ;; solaris*) case $cc_basename in CC* | sunCC*) # Sun C++ 4.2, 5.x and Centerline C++ _LT_TAGVAR(archive_cmds_need_lc,$1)=yes _LT_TAGVAR(no_undefined_flag, $1)=' -zdefs' _LT_TAGVAR(archive_cmds, $1)='$CC -G$allow_undefined_flag -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ $CC -G$allow_undefined_flag $wl-M $wl$lib.exp -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~$RM $lib.exp' _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' _LT_TAGVAR(hardcode_shlibpath_var, $1)=no case $host_os in solaris2.[[0-5]] | solaris2.[[0-5]].*) ;; *) # The compiler driver will combine and reorder linker options, # but understands '-z linker_flag'. # Supported since Solaris 2.6 (maybe 2.5.1?) _LT_TAGVAR(whole_archive_flag_spec, $1)='-z allextract$convenience -z defaultextract' ;; esac _LT_TAGVAR(link_all_deplibs, $1)=yes output_verbose_link_cmd='func_echo_all' # Archives containing C++ object files must be created using # "CC -xar", where "CC" is the Sun C++ compiler. This is # necessary to make sure instantiated templates are included # in the archive. _LT_TAGVAR(old_archive_cmds, $1)='$CC -xar -o $oldlib $oldobjs' ;; gcx*) # Green Hills C++ Compiler _LT_TAGVAR(archive_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-h $wl$soname -o $lib' # The C++ compiler must be used to create the archive. _LT_TAGVAR(old_archive_cmds, $1)='$CC $LDFLAGS -archive -o $oldlib $oldobjs' ;; *) # GNU C++ compiler with Solaris linker if test yes,no = "$GXX,$with_gnu_ld"; then _LT_TAGVAR(no_undefined_flag, $1)=' $wl-z ${wl}defs' if $CC --version | $GREP -v '^2\.7' > /dev/null; then _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-h $wl$soname -o $lib' _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ $CC -shared $pic_flag -nostdlib $wl-M $wl$lib.exp $wl-h $wl$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~$RM $lib.exp' # Commands to make compiler produce verbose output that lists # what "hidden" libraries, object files and flags are used when # linking a shared library. output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP " [[-]]L"' else # g++ 2.7 appears to require '-G' NOT '-shared' on this # platform. _LT_TAGVAR(archive_cmds, $1)='$CC -G -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-h $wl$soname -o $lib' _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ $CC -G -nostdlib $wl-M $wl$lib.exp $wl-h $wl$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~$RM $lib.exp' # Commands to make compiler produce verbose output that lists # what "hidden" libraries, object files and flags are used when # linking a shared library. output_verbose_link_cmd='$CC -G $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP " [[-]]L"' fi _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-R $wl$libdir' case $host_os in solaris2.[[0-5]] | solaris2.[[0-5]].*) ;; *) _LT_TAGVAR(whole_archive_flag_spec, $1)='$wl-z ${wl}allextract$convenience $wl-z ${wl}defaultextract' ;; esac fi ;; esac ;; sysv4*uw2* | sysv5OpenUNIX* | sysv5UnixWare7.[[01]].[[10]]* | unixware7* | sco3.2v5.0.[[024]]*) _LT_TAGVAR(no_undefined_flag, $1)='$wl-z,text' _LT_TAGVAR(archive_cmds_need_lc, $1)=no _LT_TAGVAR(hardcode_shlibpath_var, $1)=no runpath_var='LD_RUN_PATH' case $cc_basename in CC*) _LT_TAGVAR(archive_cmds, $1)='$CC -G $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -G $wl-Bexport:$export_symbols $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' ;; *) _LT_TAGVAR(archive_cmds, $1)='$CC -shared $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $wl-Bexport:$export_symbols $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' ;; esac ;; sysv5* | sco3.2v5* | sco5v6*) # Note: We CANNOT use -z defs as we might desire, because we do not # link with -lc, and that would cause any symbols used from libc to # always be unresolved, which means just about no library would # ever link correctly. If we're not using GNU ld we use -z text # though, which does catch some bad symbols but isn't as heavy-handed # as -z defs. _LT_TAGVAR(no_undefined_flag, $1)='$wl-z,text' _LT_TAGVAR(allow_undefined_flag, $1)='$wl-z,nodefs' _LT_TAGVAR(archive_cmds_need_lc, $1)=no _LT_TAGVAR(hardcode_shlibpath_var, $1)=no _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-R,$libdir' _LT_TAGVAR(hardcode_libdir_separator, $1)=':' _LT_TAGVAR(link_all_deplibs, $1)=yes _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl-Bexport' runpath_var='LD_RUN_PATH' case $cc_basename in CC*) _LT_TAGVAR(archive_cmds, $1)='$CC -G $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -G $wl-Bexport:$export_symbols $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' _LT_TAGVAR(old_archive_cmds, $1)='$CC -Tprelink_objects $oldobjs~ '"$_LT_TAGVAR(old_archive_cmds, $1)" _LT_TAGVAR(reload_cmds, $1)='$CC -Tprelink_objects $reload_objs~ '"$_LT_TAGVAR(reload_cmds, $1)" ;; *) _LT_TAGVAR(archive_cmds, $1)='$CC -shared $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $wl-Bexport:$export_symbols $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' ;; esac ;; tandem*) case $cc_basename in NCC*) # NonStop-UX NCC 3.20 # FIXME: insert proper C++ library support _LT_TAGVAR(ld_shlibs, $1)=no ;; *) # FIXME: insert proper C++ library support _LT_TAGVAR(ld_shlibs, $1)=no ;; esac ;; vxworks*) # FIXME: insert proper C++ library support _LT_TAGVAR(ld_shlibs, $1)=no ;; *) # FIXME: insert proper C++ library support _LT_TAGVAR(ld_shlibs, $1)=no ;; esac AC_MSG_RESULT([$_LT_TAGVAR(ld_shlibs, $1)]) test no = "$_LT_TAGVAR(ld_shlibs, $1)" && can_build_shared=no _LT_TAGVAR(GCC, $1)=$GXX _LT_TAGVAR(LD, $1)=$LD ## CAVEAT EMPTOR: ## There is no encapsulation within the following macros, do not change ## the running order or otherwise move them around unless you know exactly ## what you are doing... _LT_SYS_HIDDEN_LIBDEPS($1) _LT_COMPILER_PIC($1) _LT_COMPILER_C_O($1) _LT_COMPILER_FILE_LOCKS($1) _LT_LINKER_SHLIBS($1) _LT_SYS_DYNAMIC_LINKER($1) _LT_LINKER_HARDCODE_LIBPATH($1) _LT_CONFIG($1) fi # test -n "$compiler" CC=$lt_save_CC CFLAGS=$lt_save_CFLAGS LDCXX=$LD LD=$lt_save_LD GCC=$lt_save_GCC with_gnu_ld=$lt_save_with_gnu_ld lt_cv_path_LDCXX=$lt_cv_path_LD lt_cv_path_LD=$lt_save_path_LD lt_cv_prog_gnu_ldcxx=$lt_cv_prog_gnu_ld lt_cv_prog_gnu_ld=$lt_save_with_gnu_ld fi # test yes != "$_lt_caught_CXX_error" AC_LANG_POP ])# _LT_LANG_CXX_CONFIG # _LT_FUNC_STRIPNAME_CNF # ---------------------- # func_stripname_cnf prefix suffix name # strip PREFIX and SUFFIX off of NAME. # PREFIX and SUFFIX must not contain globbing or regex special # characters, hashes, percent signs, but SUFFIX may contain a leading # dot (in which case that matches only a dot). # # This function is identical to the (non-XSI) version of func_stripname, # except this one can be used by m4 code that may be executed by configure, # rather than the libtool script. m4_defun([_LT_FUNC_STRIPNAME_CNF],[dnl AC_REQUIRE([_LT_DECL_SED]) AC_REQUIRE([_LT_PROG_ECHO_BACKSLASH]) func_stripname_cnf () { case @S|@2 in .*) func_stripname_result=`$ECHO "@S|@3" | $SED "s%^@S|@1%%; s%\\\\@S|@2\$%%"`;; *) func_stripname_result=`$ECHO "@S|@3" | $SED "s%^@S|@1%%; s%@S|@2\$%%"`;; esac } # func_stripname_cnf ])# _LT_FUNC_STRIPNAME_CNF # _LT_SYS_HIDDEN_LIBDEPS([TAGNAME]) # --------------------------------- # Figure out "hidden" library dependencies from verbose # compiler output when linking a shared library. # Parse the compiler output and extract the necessary # objects, libraries and library flags. m4_defun([_LT_SYS_HIDDEN_LIBDEPS], [m4_require([_LT_FILEUTILS_DEFAULTS])dnl AC_REQUIRE([_LT_FUNC_STRIPNAME_CNF])dnl # Dependencies to place before and after the object being linked: _LT_TAGVAR(predep_objects, $1)= _LT_TAGVAR(postdep_objects, $1)= _LT_TAGVAR(predeps, $1)= _LT_TAGVAR(postdeps, $1)= _LT_TAGVAR(compiler_lib_search_path, $1)= dnl we can't use the lt_simple_compile_test_code here, dnl because it contains code intended for an executable, dnl not a library. It's possible we should let each dnl tag define a new lt_????_link_test_code variable, dnl but it's only used here... m4_if([$1], [], [cat > conftest.$ac_ext <<_LT_EOF int a; void foo (void) { a = 0; } _LT_EOF ], [$1], [CXX], [cat > conftest.$ac_ext <<_LT_EOF class Foo { public: Foo (void) { a = 0; } private: int a; }; _LT_EOF ], [$1], [F77], [cat > conftest.$ac_ext <<_LT_EOF subroutine foo implicit none integer*4 a a=0 return end _LT_EOF ], [$1], [FC], [cat > conftest.$ac_ext <<_LT_EOF subroutine foo implicit none integer a a=0 return end _LT_EOF ], [$1], [GCJ], [cat > conftest.$ac_ext <<_LT_EOF public class foo { private int a; public void bar (void) { a = 0; } }; _LT_EOF ], [$1], [GO], [cat > conftest.$ac_ext <<_LT_EOF package foo func foo() { } _LT_EOF ]) _lt_libdeps_save_CFLAGS=$CFLAGS case "$CC $CFLAGS " in #( *\ -flto*\ *) CFLAGS="$CFLAGS -fno-lto" ;; *\ -fwhopr*\ *) CFLAGS="$CFLAGS -fno-whopr" ;; *\ -fuse-linker-plugin*\ *) CFLAGS="$CFLAGS -fno-use-linker-plugin" ;; esac dnl Parse the compiler output and extract the necessary dnl objects, libraries and library flags. if AC_TRY_EVAL(ac_compile); then # Parse the compiler output and extract the necessary # objects, libraries and library flags. # Sentinel used to keep track of whether or not we are before # the conftest object file. pre_test_object_deps_done=no for p in `eval "$output_verbose_link_cmd"`; do case $prev$p in -L* | -R* | -l*) # Some compilers place space between "-{L,R,l}" and the path. # Remove the space. if test x-L = x"$p" || test x-R = x"$p" || test x-l = x"$p"; then prev=$p continue fi # Expand the sysroot to ease extracting the directories later. if test -z "$prev"; then case $p in -L*) func_stripname_cnf '-L' '' "$p"; prev=-L; p=$func_stripname_result ;; -R*) func_stripname_cnf '-R' '' "$p"; prev=-R; p=$func_stripname_result ;; -l*) func_stripname_cnf '-l' '' "$p"; prev=-l; p=$func_stripname_result ;; esac fi case $p in =*) func_stripname_cnf '=' '' "$p"; p=$lt_sysroot$func_stripname_result ;; esac if test no = "$pre_test_object_deps_done"; then case $prev in -L | -R) # Internal compiler library paths should come after those # provided the user. The postdeps already come after the # user supplied libs so there is no need to process them. if test -z "$_LT_TAGVAR(compiler_lib_search_path, $1)"; then _LT_TAGVAR(compiler_lib_search_path, $1)=$prev$p else _LT_TAGVAR(compiler_lib_search_path, $1)="${_LT_TAGVAR(compiler_lib_search_path, $1)} $prev$p" fi ;; # The "-l" case would never come before the object being # linked, so don't bother handling this case. esac else if test -z "$_LT_TAGVAR(postdeps, $1)"; then _LT_TAGVAR(postdeps, $1)=$prev$p else _LT_TAGVAR(postdeps, $1)="${_LT_TAGVAR(postdeps, $1)} $prev$p" fi fi prev= ;; *.lto.$objext) ;; # Ignore GCC LTO objects *.$objext) # This assumes that the test object file only shows up # once in the compiler output. if test "$p" = "conftest.$objext"; then pre_test_object_deps_done=yes continue fi if test no = "$pre_test_object_deps_done"; then if test -z "$_LT_TAGVAR(predep_objects, $1)"; then _LT_TAGVAR(predep_objects, $1)=$p else _LT_TAGVAR(predep_objects, $1)="$_LT_TAGVAR(predep_objects, $1) $p" fi else if test -z "$_LT_TAGVAR(postdep_objects, $1)"; then _LT_TAGVAR(postdep_objects, $1)=$p else _LT_TAGVAR(postdep_objects, $1)="$_LT_TAGVAR(postdep_objects, $1) $p" fi fi ;; *) ;; # Ignore the rest. esac done # Clean up. rm -f a.out a.exe else echo "libtool.m4: error: problem compiling $1 test program" fi $RM -f confest.$objext CFLAGS=$_lt_libdeps_save_CFLAGS # PORTME: override above test on systems where it is broken m4_if([$1], [CXX], [case $host_os in interix[[3-9]]*) # Interix 3.5 installs completely hosed .la files for C++, so rather than # hack all around it, let's just trust "g++" to DTRT. _LT_TAGVAR(predep_objects,$1)= _LT_TAGVAR(postdep_objects,$1)= _LT_TAGVAR(postdeps,$1)= ;; esac ]) case " $_LT_TAGVAR(postdeps, $1) " in *" -lc "*) _LT_TAGVAR(archive_cmds_need_lc, $1)=no ;; esac _LT_TAGVAR(compiler_lib_search_dirs, $1)= if test -n "${_LT_TAGVAR(compiler_lib_search_path, $1)}"; then _LT_TAGVAR(compiler_lib_search_dirs, $1)=`echo " ${_LT_TAGVAR(compiler_lib_search_path, $1)}" | $SED -e 's! -L! !g' -e 's!^ !!'` fi _LT_TAGDECL([], [compiler_lib_search_dirs], [1], [The directories searched by this compiler when creating a shared library]) _LT_TAGDECL([], [predep_objects], [1], [Dependencies to place before and after the objects being linked to create a shared library]) _LT_TAGDECL([], [postdep_objects], [1]) _LT_TAGDECL([], [predeps], [1]) _LT_TAGDECL([], [postdeps], [1]) _LT_TAGDECL([], [compiler_lib_search_path], [1], [The library search path used internally by the compiler when linking a shared library]) ])# _LT_SYS_HIDDEN_LIBDEPS # _LT_LANG_F77_CONFIG([TAG]) # -------------------------- # Ensure that the configuration variables for a Fortran 77 compiler are # suitably defined. These variables are subsequently used by _LT_CONFIG # to write the compiler configuration to 'libtool'. m4_defun([_LT_LANG_F77_CONFIG], [AC_LANG_PUSH(Fortran 77) if test -z "$F77" || test no = "$F77"; then _lt_disable_F77=yes fi _LT_TAGVAR(archive_cmds_need_lc, $1)=no _LT_TAGVAR(allow_undefined_flag, $1)= _LT_TAGVAR(always_export_symbols, $1)=no _LT_TAGVAR(archive_expsym_cmds, $1)= _LT_TAGVAR(export_dynamic_flag_spec, $1)= _LT_TAGVAR(hardcode_direct, $1)=no _LT_TAGVAR(hardcode_direct_absolute, $1)=no _LT_TAGVAR(hardcode_libdir_flag_spec, $1)= _LT_TAGVAR(hardcode_libdir_separator, $1)= _LT_TAGVAR(hardcode_minus_L, $1)=no _LT_TAGVAR(hardcode_automatic, $1)=no _LT_TAGVAR(inherit_rpath, $1)=no _LT_TAGVAR(module_cmds, $1)= _LT_TAGVAR(module_expsym_cmds, $1)= _LT_TAGVAR(link_all_deplibs, $1)=unknown _LT_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds _LT_TAGVAR(reload_flag, $1)=$reload_flag _LT_TAGVAR(reload_cmds, $1)=$reload_cmds _LT_TAGVAR(no_undefined_flag, $1)= _LT_TAGVAR(whole_archive_flag_spec, $1)= _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=no # Source file extension for f77 test sources. ac_ext=f # Object file extension for compiled f77 test sources. objext=o _LT_TAGVAR(objext, $1)=$objext # No sense in running all these tests if we already determined that # the F77 compiler isn't working. Some variables (like enable_shared) # are currently assumed to apply to all compilers on this platform, # and will be corrupted by setting them based on a non-working compiler. if test yes != "$_lt_disable_F77"; then # Code to be used in simple compile tests lt_simple_compile_test_code="\ subroutine t return end " # Code to be used in simple link tests lt_simple_link_test_code="\ program t end " # ltmain only uses $CC for tagged configurations so make sure $CC is set. _LT_TAG_COMPILER # save warnings/boilerplate of simple test code _LT_COMPILER_BOILERPLATE _LT_LINKER_BOILERPLATE # Allow CC to be a program name with arguments. lt_save_CC=$CC lt_save_GCC=$GCC lt_save_CFLAGS=$CFLAGS CC=${F77-"f77"} CFLAGS=$FFLAGS compiler=$CC _LT_TAGVAR(compiler, $1)=$CC _LT_CC_BASENAME([$compiler]) GCC=$G77 if test -n "$compiler"; then AC_MSG_CHECKING([if libtool supports shared libraries]) AC_MSG_RESULT([$can_build_shared]) AC_MSG_CHECKING([whether to build shared libraries]) test no = "$can_build_shared" && enable_shared=no # On AIX, shared libraries and static libraries use the same namespace, and # are all built from PIC. case $host_os in aix3*) test yes = "$enable_shared" && enable_static=no if test -n "$RANLIB"; then archive_cmds="$archive_cmds~\$RANLIB \$lib" postinstall_cmds='$RANLIB $lib' fi ;; aix[[4-9]]*) if test ia64 != "$host_cpu"; then case $enable_shared,$with_aix_soname,$aix_use_runtimelinking in yes,aix,yes) ;; # shared object as lib.so file only yes,svr4,*) ;; # shared object as lib.so archive member only yes,*) enable_static=no ;; # shared object in lib.a archive as well esac fi ;; esac AC_MSG_RESULT([$enable_shared]) AC_MSG_CHECKING([whether to build static libraries]) # Make sure either enable_shared or enable_static is yes. test yes = "$enable_shared" || enable_static=yes AC_MSG_RESULT([$enable_static]) _LT_TAGVAR(GCC, $1)=$G77 _LT_TAGVAR(LD, $1)=$LD ## CAVEAT EMPTOR: ## There is no encapsulation within the following macros, do not change ## the running order or otherwise move them around unless you know exactly ## what you are doing... _LT_COMPILER_PIC($1) _LT_COMPILER_C_O($1) _LT_COMPILER_FILE_LOCKS($1) _LT_LINKER_SHLIBS($1) _LT_SYS_DYNAMIC_LINKER($1) _LT_LINKER_HARDCODE_LIBPATH($1) _LT_CONFIG($1) fi # test -n "$compiler" GCC=$lt_save_GCC CC=$lt_save_CC CFLAGS=$lt_save_CFLAGS fi # test yes != "$_lt_disable_F77" AC_LANG_POP ])# _LT_LANG_F77_CONFIG # _LT_LANG_FC_CONFIG([TAG]) # ------------------------- # Ensure that the configuration variables for a Fortran compiler are # suitably defined. These variables are subsequently used by _LT_CONFIG # to write the compiler configuration to 'libtool'. m4_defun([_LT_LANG_FC_CONFIG], [AC_LANG_PUSH(Fortran) if test -z "$FC" || test no = "$FC"; then _lt_disable_FC=yes fi _LT_TAGVAR(archive_cmds_need_lc, $1)=no _LT_TAGVAR(allow_undefined_flag, $1)= _LT_TAGVAR(always_export_symbols, $1)=no _LT_TAGVAR(archive_expsym_cmds, $1)= _LT_TAGVAR(export_dynamic_flag_spec, $1)= _LT_TAGVAR(hardcode_direct, $1)=no _LT_TAGVAR(hardcode_direct_absolute, $1)=no _LT_TAGVAR(hardcode_libdir_flag_spec, $1)= _LT_TAGVAR(hardcode_libdir_separator, $1)= _LT_TAGVAR(hardcode_minus_L, $1)=no _LT_TAGVAR(hardcode_automatic, $1)=no _LT_TAGVAR(inherit_rpath, $1)=no _LT_TAGVAR(module_cmds, $1)= _LT_TAGVAR(module_expsym_cmds, $1)= _LT_TAGVAR(link_all_deplibs, $1)=unknown _LT_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds _LT_TAGVAR(reload_flag, $1)=$reload_flag _LT_TAGVAR(reload_cmds, $1)=$reload_cmds _LT_TAGVAR(no_undefined_flag, $1)= _LT_TAGVAR(whole_archive_flag_spec, $1)= _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=no # Source file extension for fc test sources. ac_ext=${ac_fc_srcext-f} # Object file extension for compiled fc test sources. objext=o _LT_TAGVAR(objext, $1)=$objext # No sense in running all these tests if we already determined that # the FC compiler isn't working. Some variables (like enable_shared) # are currently assumed to apply to all compilers on this platform, # and will be corrupted by setting them based on a non-working compiler. if test yes != "$_lt_disable_FC"; then # Code to be used in simple compile tests lt_simple_compile_test_code="\ subroutine t return end " # Code to be used in simple link tests lt_simple_link_test_code="\ program t end " # ltmain only uses $CC for tagged configurations so make sure $CC is set. _LT_TAG_COMPILER # save warnings/boilerplate of simple test code _LT_COMPILER_BOILERPLATE _LT_LINKER_BOILERPLATE # Allow CC to be a program name with arguments. lt_save_CC=$CC lt_save_GCC=$GCC lt_save_CFLAGS=$CFLAGS CC=${FC-"f95"} CFLAGS=$FCFLAGS compiler=$CC GCC=$ac_cv_fc_compiler_gnu _LT_TAGVAR(compiler, $1)=$CC _LT_CC_BASENAME([$compiler]) if test -n "$compiler"; then AC_MSG_CHECKING([if libtool supports shared libraries]) AC_MSG_RESULT([$can_build_shared]) AC_MSG_CHECKING([whether to build shared libraries]) test no = "$can_build_shared" && enable_shared=no # On AIX, shared libraries and static libraries use the same namespace, and # are all built from PIC. case $host_os in aix3*) test yes = "$enable_shared" && enable_static=no if test -n "$RANLIB"; then archive_cmds="$archive_cmds~\$RANLIB \$lib" postinstall_cmds='$RANLIB $lib' fi ;; aix[[4-9]]*) if test ia64 != "$host_cpu"; then case $enable_shared,$with_aix_soname,$aix_use_runtimelinking in yes,aix,yes) ;; # shared object as lib.so file only yes,svr4,*) ;; # shared object as lib.so archive member only yes,*) enable_static=no ;; # shared object in lib.a archive as well esac fi ;; esac AC_MSG_RESULT([$enable_shared]) AC_MSG_CHECKING([whether to build static libraries]) # Make sure either enable_shared or enable_static is yes. test yes = "$enable_shared" || enable_static=yes AC_MSG_RESULT([$enable_static]) _LT_TAGVAR(GCC, $1)=$ac_cv_fc_compiler_gnu _LT_TAGVAR(LD, $1)=$LD ## CAVEAT EMPTOR: ## There is no encapsulation within the following macros, do not change ## the running order or otherwise move them around unless you know exactly ## what you are doing... _LT_SYS_HIDDEN_LIBDEPS($1) _LT_COMPILER_PIC($1) _LT_COMPILER_C_O($1) _LT_COMPILER_FILE_LOCKS($1) _LT_LINKER_SHLIBS($1) _LT_SYS_DYNAMIC_LINKER($1) _LT_LINKER_HARDCODE_LIBPATH($1) _LT_CONFIG($1) fi # test -n "$compiler" GCC=$lt_save_GCC CC=$lt_save_CC CFLAGS=$lt_save_CFLAGS fi # test yes != "$_lt_disable_FC" AC_LANG_POP ])# _LT_LANG_FC_CONFIG # _LT_LANG_GCJ_CONFIG([TAG]) # -------------------------- # Ensure that the configuration variables for the GNU Java Compiler compiler # are suitably defined. These variables are subsequently used by _LT_CONFIG # to write the compiler configuration to 'libtool'. m4_defun([_LT_LANG_GCJ_CONFIG], [AC_REQUIRE([LT_PROG_GCJ])dnl AC_LANG_SAVE # Source file extension for Java test sources. ac_ext=java # Object file extension for compiled Java test sources. objext=o _LT_TAGVAR(objext, $1)=$objext # Code to be used in simple compile tests lt_simple_compile_test_code="class foo {}" # Code to be used in simple link tests lt_simple_link_test_code='public class conftest { public static void main(String[[]] argv) {}; }' # ltmain only uses $CC for tagged configurations so make sure $CC is set. _LT_TAG_COMPILER # save warnings/boilerplate of simple test code _LT_COMPILER_BOILERPLATE _LT_LINKER_BOILERPLATE # Allow CC to be a program name with arguments. lt_save_CC=$CC lt_save_CFLAGS=$CFLAGS lt_save_GCC=$GCC GCC=yes CC=${GCJ-"gcj"} CFLAGS=$GCJFLAGS compiler=$CC _LT_TAGVAR(compiler, $1)=$CC _LT_TAGVAR(LD, $1)=$LD _LT_CC_BASENAME([$compiler]) # GCJ did not exist at the time GCC didn't implicitly link libc in. _LT_TAGVAR(archive_cmds_need_lc, $1)=no _LT_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds _LT_TAGVAR(reload_flag, $1)=$reload_flag _LT_TAGVAR(reload_cmds, $1)=$reload_cmds ## CAVEAT EMPTOR: ## There is no encapsulation within the following macros, do not change ## the running order or otherwise move them around unless you know exactly ## what you are doing... if test -n "$compiler"; then _LT_COMPILER_NO_RTTI($1) _LT_COMPILER_PIC($1) _LT_COMPILER_C_O($1) _LT_COMPILER_FILE_LOCKS($1) _LT_LINKER_SHLIBS($1) _LT_LINKER_HARDCODE_LIBPATH($1) _LT_CONFIG($1) fi AC_LANG_RESTORE GCC=$lt_save_GCC CC=$lt_save_CC CFLAGS=$lt_save_CFLAGS ])# _LT_LANG_GCJ_CONFIG # _LT_LANG_GO_CONFIG([TAG]) # -------------------------- # Ensure that the configuration variables for the GNU Go compiler # are suitably defined. These variables are subsequently used by _LT_CONFIG # to write the compiler configuration to 'libtool'. m4_defun([_LT_LANG_GO_CONFIG], [AC_REQUIRE([LT_PROG_GO])dnl AC_LANG_SAVE # Source file extension for Go test sources. ac_ext=go # Object file extension for compiled Go test sources. objext=o _LT_TAGVAR(objext, $1)=$objext # Code to be used in simple compile tests lt_simple_compile_test_code="package main; func main() { }" # Code to be used in simple link tests lt_simple_link_test_code='package main; func main() { }' # ltmain only uses $CC for tagged configurations so make sure $CC is set. _LT_TAG_COMPILER # save warnings/boilerplate of simple test code _LT_COMPILER_BOILERPLATE _LT_LINKER_BOILERPLATE # Allow CC to be a program name with arguments. lt_save_CC=$CC lt_save_CFLAGS=$CFLAGS lt_save_GCC=$GCC GCC=yes CC=${GOC-"gccgo"} CFLAGS=$GOFLAGS compiler=$CC _LT_TAGVAR(compiler, $1)=$CC _LT_TAGVAR(LD, $1)=$LD _LT_CC_BASENAME([$compiler]) # Go did not exist at the time GCC didn't implicitly link libc in. _LT_TAGVAR(archive_cmds_need_lc, $1)=no _LT_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds _LT_TAGVAR(reload_flag, $1)=$reload_flag _LT_TAGVAR(reload_cmds, $1)=$reload_cmds ## CAVEAT EMPTOR: ## There is no encapsulation within the following macros, do not change ## the running order or otherwise move them around unless you know exactly ## what you are doing... if test -n "$compiler"; then _LT_COMPILER_NO_RTTI($1) _LT_COMPILER_PIC($1) _LT_COMPILER_C_O($1) _LT_COMPILER_FILE_LOCKS($1) _LT_LINKER_SHLIBS($1) _LT_LINKER_HARDCODE_LIBPATH($1) _LT_CONFIG($1) fi AC_LANG_RESTORE GCC=$lt_save_GCC CC=$lt_save_CC CFLAGS=$lt_save_CFLAGS ])# _LT_LANG_GO_CONFIG # _LT_LANG_RC_CONFIG([TAG]) # ------------------------- # Ensure that the configuration variables for the Windows resource compiler # are suitably defined. These variables are subsequently used by _LT_CONFIG # to write the compiler configuration to 'libtool'. m4_defun([_LT_LANG_RC_CONFIG], [AC_REQUIRE([LT_PROG_RC])dnl AC_LANG_SAVE # Source file extension for RC test sources. ac_ext=rc # Object file extension for compiled RC test sources. objext=o _LT_TAGVAR(objext, $1)=$objext # Code to be used in simple compile tests lt_simple_compile_test_code='sample MENU { MENUITEM "&Soup", 100, CHECKED }' # Code to be used in simple link tests lt_simple_link_test_code=$lt_simple_compile_test_code # ltmain only uses $CC for tagged configurations so make sure $CC is set. _LT_TAG_COMPILER # save warnings/boilerplate of simple test code _LT_COMPILER_BOILERPLATE _LT_LINKER_BOILERPLATE # Allow CC to be a program name with arguments. lt_save_CC=$CC lt_save_CFLAGS=$CFLAGS lt_save_GCC=$GCC GCC= CC=${RC-"windres"} CFLAGS= compiler=$CC _LT_TAGVAR(compiler, $1)=$CC _LT_CC_BASENAME([$compiler]) _LT_TAGVAR(lt_cv_prog_compiler_c_o, $1)=yes if test -n "$compiler"; then : _LT_CONFIG($1) fi GCC=$lt_save_GCC AC_LANG_RESTORE CC=$lt_save_CC CFLAGS=$lt_save_CFLAGS ])# _LT_LANG_RC_CONFIG # LT_PROG_GCJ # ----------- AC_DEFUN([LT_PROG_GCJ], [m4_ifdef([AC_PROG_GCJ], [AC_PROG_GCJ], [m4_ifdef([A][M_PROG_GCJ], [A][M_PROG_GCJ], [AC_CHECK_TOOL(GCJ, gcj,) test set = "${GCJFLAGS+set}" || GCJFLAGS="-g -O2" AC_SUBST(GCJFLAGS)])])[]dnl ]) # Old name: AU_ALIAS([LT_AC_PROG_GCJ], [LT_PROG_GCJ]) dnl aclocal-1.4 backwards compatibility: dnl AC_DEFUN([LT_AC_PROG_GCJ], []) # LT_PROG_GO # ---------- AC_DEFUN([LT_PROG_GO], [AC_CHECK_TOOL(GOC, gccgo,) ]) # LT_PROG_RC # ---------- AC_DEFUN([LT_PROG_RC], [AC_CHECK_TOOL(RC, windres,) ]) # Old name: AU_ALIAS([LT_AC_PROG_RC], [LT_PROG_RC]) dnl aclocal-1.4 backwards compatibility: dnl AC_DEFUN([LT_AC_PROG_RC], []) # _LT_DECL_EGREP # -------------- # If we don't have a new enough Autoconf to choose the best grep # available, choose the one first in the user's PATH. m4_defun([_LT_DECL_EGREP], [AC_REQUIRE([AC_PROG_EGREP])dnl AC_REQUIRE([AC_PROG_FGREP])dnl test -z "$GREP" && GREP=grep _LT_DECL([], [GREP], [1], [A grep program that handles long lines]) _LT_DECL([], [EGREP], [1], [An ERE matcher]) _LT_DECL([], [FGREP], [1], [A literal string matcher]) dnl Non-bleeding-edge autoconf doesn't subst GREP, so do it here too AC_SUBST([GREP]) ]) # _LT_DECL_OBJDUMP # -------------- # If we don't have a new enough Autoconf to choose the best objdump # available, choose the one first in the user's PATH. m4_defun([_LT_DECL_OBJDUMP], [AC_CHECK_TOOL(OBJDUMP, objdump, false) test -z "$OBJDUMP" && OBJDUMP=objdump _LT_DECL([], [OBJDUMP], [1], [An object symbol dumper]) AC_SUBST([OBJDUMP]) ]) # _LT_DECL_DLLTOOL # ---------------- # Ensure DLLTOOL variable is set. m4_defun([_LT_DECL_DLLTOOL], [AC_CHECK_TOOL(DLLTOOL, dlltool, false) test -z "$DLLTOOL" && DLLTOOL=dlltool _LT_DECL([], [DLLTOOL], [1], [DLL creation program]) AC_SUBST([DLLTOOL]) ]) # _LT_DECL_FILECMD # ---------------- # Check for a file(cmd) program that can be used to detect file type and magic m4_defun([_LT_DECL_FILECMD], [AC_CHECK_PROG([FILECMD], [file], [file], [:]) _LT_DECL([], [FILECMD], [1], [A file(cmd) program that detects file types]) ])# _LD_DECL_FILECMD # _LT_DECL_SED # ------------ # Check for a fully-functional sed program, that truncates # as few characters as possible. Prefer GNU sed if found. m4_defun([_LT_DECL_SED], [AC_PROG_SED test -z "$SED" && SED=sed Xsed="$SED -e 1s/^X//" _LT_DECL([], [SED], [1], [A sed program that does not truncate output]) _LT_DECL([], [Xsed], ["\$SED -e 1s/^X//"], [Sed that helps us avoid accidentally triggering echo(1) options like -n]) ])# _LT_DECL_SED dnl aclocal-1.4 backwards compatibility: dnl AC_DEFUN([LT_AC_PROG_SED], []) # _LT_CHECK_SHELL_FEATURES # ------------------------ # Find out whether the shell is Bourne or XSI compatible, # or has some other useful features. m4_defun([_LT_CHECK_SHELL_FEATURES], [if ( (MAIL=60; unset MAIL) || exit) >/dev/null 2>&1; then lt_unset=unset else lt_unset=false fi _LT_DECL([], [lt_unset], [0], [whether the shell understands "unset"])dnl # test EBCDIC or ASCII case `echo X|tr X '\101'` in A) # ASCII based system # \n is not interpreted correctly by Solaris 8 /usr/ucb/tr lt_SP2NL='tr \040 \012' lt_NL2SP='tr \015\012 \040\040' ;; *) # EBCDIC based system lt_SP2NL='tr \100 \n' lt_NL2SP='tr \r\n \100\100' ;; esac _LT_DECL([SP2NL], [lt_SP2NL], [1], [turn spaces into newlines])dnl _LT_DECL([NL2SP], [lt_NL2SP], [1], [turn newlines into spaces])dnl ])# _LT_CHECK_SHELL_FEATURES # _LT_PATH_CONVERSION_FUNCTIONS # ----------------------------- # Determine what file name conversion functions should be used by # func_to_host_file (and, implicitly, by func_to_host_path). These are needed # for certain cross-compile configurations and native mingw. m4_defun([_LT_PATH_CONVERSION_FUNCTIONS], [AC_REQUIRE([AC_CANONICAL_HOST])dnl AC_REQUIRE([AC_CANONICAL_BUILD])dnl AC_MSG_CHECKING([how to convert $build file names to $host format]) AC_CACHE_VAL(lt_cv_to_host_file_cmd, [case $host in *-*-mingw* ) case $build in *-*-mingw* | *-*-windows* ) # actually msys lt_cv_to_host_file_cmd=func_convert_file_msys_to_w32 ;; *-*-cygwin* ) lt_cv_to_host_file_cmd=func_convert_file_cygwin_to_w32 ;; * ) # otherwise, assume *nix lt_cv_to_host_file_cmd=func_convert_file_nix_to_w32 ;; esac ;; *-*-cygwin* ) case $build in *-*-mingw* | *-*-windows* ) # actually msys lt_cv_to_host_file_cmd=func_convert_file_msys_to_cygwin ;; *-*-cygwin* ) lt_cv_to_host_file_cmd=func_convert_file_noop ;; * ) # otherwise, assume *nix lt_cv_to_host_file_cmd=func_convert_file_nix_to_cygwin ;; esac ;; * ) # unhandled hosts (and "normal" native builds) lt_cv_to_host_file_cmd=func_convert_file_noop ;; esac ]) to_host_file_cmd=$lt_cv_to_host_file_cmd AC_MSG_RESULT([$lt_cv_to_host_file_cmd]) _LT_DECL([to_host_file_cmd], [lt_cv_to_host_file_cmd], [0], [convert $build file names to $host format])dnl AC_MSG_CHECKING([how to convert $build file names to toolchain format]) AC_CACHE_VAL(lt_cv_to_tool_file_cmd, [#assume ordinary cross tools, or native build. lt_cv_to_tool_file_cmd=func_convert_file_noop case $host in *-*-mingw* | *-*-windows* ) case $build in *-*-mingw* | *-*-windows* ) # actually msys lt_cv_to_tool_file_cmd=func_convert_file_msys_to_w32 ;; esac ;; esac ]) to_tool_file_cmd=$lt_cv_to_tool_file_cmd AC_MSG_RESULT([$lt_cv_to_tool_file_cmd]) _LT_DECL([to_tool_file_cmd], [lt_cv_to_tool_file_cmd], [0], [convert $build files to toolchain format])dnl ])# _LT_PATH_CONVERSION_FUNCTIONS ntfs-3g-2026.2.25/m4/lt~obsolete.m40000644000175000017500000001400715152260210012124 # lt~obsolete.m4 -- aclocal satisfying obsolete definitions. -*-Autoconf-*- # # Copyright (C) 2004-2005, 2007, 2009, 2011-2019, 2021-2024 Free # Software Foundation, Inc. # Written by Scott James Remnant, 2004. # # This file is free software; the Free Software Foundation gives # unlimited permission to copy and/or distribute it, with or without # modifications, as long as this notice is preserved. # serial 5 lt~obsolete.m4 # These exist entirely to fool aclocal when bootstrapping libtool. # # In the past libtool.m4 has provided macros via AC_DEFUN (or AU_DEFUN), # which have later been changed to m4_define as they aren't part of the # exported API, or moved to Autoconf or Automake where they belong. # # The trouble is, aclocal is a bit thick. It'll see the old AC_DEFUN # in /usr/share/aclocal/libtool.m4 and remember it, then when it sees us # using a macro with the same name in our local m4/libtool.m4 it'll # pull the old libtool.m4 in (it doesn't see our shiny new m4_define # and doesn't know about Autoconf macros at all.) # # So we provide this file, which has a silly filename so it's always # included after everything else. This provides aclocal with the # AC_DEFUNs it wants, but when m4 processes it, it doesn't do anything # because those macros already exist, or will be overwritten later. # We use AC_DEFUN over AU_DEFUN for compatibility with aclocal-1.6. # # Anytime we withdraw an AC_DEFUN or AU_DEFUN, remember to add it here. # Yes, that means every name once taken will need to remain here until # we give up compatibility with versions before 1.7, at which point # we need to keep only those names which we still refer to. # This is to help aclocal find these macros, as it can't see m4_define. AC_DEFUN([LTOBSOLETE_VERSION], [m4_if([1])]) m4_ifndef([AC_LIBTOOL_LINKER_OPTION], [AC_DEFUN([AC_LIBTOOL_LINKER_OPTION])]) m4_ifndef([AC_PROG_EGREP], [AC_DEFUN([AC_PROG_EGREP])]) m4_ifndef([_LT_AC_PROG_ECHO_BACKSLASH], [AC_DEFUN([_LT_AC_PROG_ECHO_BACKSLASH])]) m4_ifndef([_LT_AC_SHELL_INIT], [AC_DEFUN([_LT_AC_SHELL_INIT])]) m4_ifndef([_LT_AC_SYS_LIBPATH_AIX], [AC_DEFUN([_LT_AC_SYS_LIBPATH_AIX])]) m4_ifndef([_LT_PROG_LTMAIN], [AC_DEFUN([_LT_PROG_LTMAIN])]) m4_ifndef([_LT_AC_TAGVAR], [AC_DEFUN([_LT_AC_TAGVAR])]) m4_ifndef([AC_LTDL_ENABLE_INSTALL], [AC_DEFUN([AC_LTDL_ENABLE_INSTALL])]) m4_ifndef([AC_LTDL_PREOPEN], [AC_DEFUN([AC_LTDL_PREOPEN])]) m4_ifndef([_LT_AC_SYS_COMPILER], [AC_DEFUN([_LT_AC_SYS_COMPILER])]) m4_ifndef([_LT_AC_LOCK], [AC_DEFUN([_LT_AC_LOCK])]) m4_ifndef([AC_LIBTOOL_SYS_OLD_ARCHIVE], [AC_DEFUN([AC_LIBTOOL_SYS_OLD_ARCHIVE])]) m4_ifndef([_LT_AC_TRY_DLOPEN_SELF], [AC_DEFUN([_LT_AC_TRY_DLOPEN_SELF])]) m4_ifndef([AC_LIBTOOL_PROG_CC_C_O], [AC_DEFUN([AC_LIBTOOL_PROG_CC_C_O])]) m4_ifndef([AC_LIBTOOL_SYS_HARD_LINK_LOCKS], [AC_DEFUN([AC_LIBTOOL_SYS_HARD_LINK_LOCKS])]) m4_ifndef([AC_LIBTOOL_OBJDIR], [AC_DEFUN([AC_LIBTOOL_OBJDIR])]) m4_ifndef([AC_LTDL_OBJDIR], [AC_DEFUN([AC_LTDL_OBJDIR])]) m4_ifndef([AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH], [AC_DEFUN([AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH])]) m4_ifndef([AC_LIBTOOL_SYS_LIB_STRIP], [AC_DEFUN([AC_LIBTOOL_SYS_LIB_STRIP])]) m4_ifndef([AC_PATH_MAGIC], [AC_DEFUN([AC_PATH_MAGIC])]) m4_ifndef([AC_PROG_LD_GNU], [AC_DEFUN([AC_PROG_LD_GNU])]) m4_ifndef([AC_PROG_LD_RELOAD_FLAG], [AC_DEFUN([AC_PROG_LD_RELOAD_FLAG])]) m4_ifndef([AC_DEPLIBS_CHECK_METHOD], [AC_DEFUN([AC_DEPLIBS_CHECK_METHOD])]) m4_ifndef([AC_LIBTOOL_PROG_COMPILER_NO_RTTI], [AC_DEFUN([AC_LIBTOOL_PROG_COMPILER_NO_RTTI])]) m4_ifndef([AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE], [AC_DEFUN([AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE])]) m4_ifndef([AC_LIBTOOL_PROG_COMPILER_PIC], [AC_DEFUN([AC_LIBTOOL_PROG_COMPILER_PIC])]) m4_ifndef([AC_LIBTOOL_PROG_LD_SHLIBS], [AC_DEFUN([AC_LIBTOOL_PROG_LD_SHLIBS])]) m4_ifndef([AC_LIBTOOL_POSTDEP_PREDEP], [AC_DEFUN([AC_LIBTOOL_POSTDEP_PREDEP])]) m4_ifndef([LT_AC_PROG_EGREP], [AC_DEFUN([LT_AC_PROG_EGREP])]) m4_ifndef([LT_AC_PROG_SED], [AC_DEFUN([LT_AC_PROG_SED])]) m4_ifndef([_LT_CC_BASENAME], [AC_DEFUN([_LT_CC_BASENAME])]) m4_ifndef([_LT_COMPILER_BOILERPLATE], [AC_DEFUN([_LT_COMPILER_BOILERPLATE])]) m4_ifndef([_LT_LINKER_BOILERPLATE], [AC_DEFUN([_LT_LINKER_BOILERPLATE])]) m4_ifndef([_AC_PROG_LIBTOOL], [AC_DEFUN([_AC_PROG_LIBTOOL])]) m4_ifndef([AC_LIBTOOL_SETUP], [AC_DEFUN([AC_LIBTOOL_SETUP])]) m4_ifndef([_LT_AC_CHECK_DLFCN], [AC_DEFUN([_LT_AC_CHECK_DLFCN])]) m4_ifndef([AC_LIBTOOL_SYS_DYNAMIC_LINKER], [AC_DEFUN([AC_LIBTOOL_SYS_DYNAMIC_LINKER])]) m4_ifndef([_LT_AC_TAGCONFIG], [AC_DEFUN([_LT_AC_TAGCONFIG])]) m4_ifndef([AC_DISABLE_FAST_INSTALL], [AC_DEFUN([AC_DISABLE_FAST_INSTALL])]) m4_ifndef([_LT_AC_LANG_CXX], [AC_DEFUN([_LT_AC_LANG_CXX])]) m4_ifndef([_LT_AC_LANG_F77], [AC_DEFUN([_LT_AC_LANG_F77])]) m4_ifndef([_LT_AC_LANG_GCJ], [AC_DEFUN([_LT_AC_LANG_GCJ])]) m4_ifndef([AC_LIBTOOL_LANG_C_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_C_CONFIG])]) m4_ifndef([_LT_AC_LANG_C_CONFIG], [AC_DEFUN([_LT_AC_LANG_C_CONFIG])]) m4_ifndef([AC_LIBTOOL_LANG_CXX_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_CXX_CONFIG])]) m4_ifndef([_LT_AC_LANG_CXX_CONFIG], [AC_DEFUN([_LT_AC_LANG_CXX_CONFIG])]) m4_ifndef([AC_LIBTOOL_LANG_F77_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_F77_CONFIG])]) m4_ifndef([_LT_AC_LANG_F77_CONFIG], [AC_DEFUN([_LT_AC_LANG_F77_CONFIG])]) m4_ifndef([AC_LIBTOOL_LANG_GCJ_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_GCJ_CONFIG])]) m4_ifndef([_LT_AC_LANG_GCJ_CONFIG], [AC_DEFUN([_LT_AC_LANG_GCJ_CONFIG])]) m4_ifndef([AC_LIBTOOL_LANG_RC_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_RC_CONFIG])]) m4_ifndef([_LT_AC_LANG_RC_CONFIG], [AC_DEFUN([_LT_AC_LANG_RC_CONFIG])]) m4_ifndef([AC_LIBTOOL_CONFIG], [AC_DEFUN([AC_LIBTOOL_CONFIG])]) m4_ifndef([_LT_AC_FILE_LTDLL_C], [AC_DEFUN([_LT_AC_FILE_LTDLL_C])]) m4_ifndef([_LT_REQUIRED_DARWIN_CHECKS], [AC_DEFUN([_LT_REQUIRED_DARWIN_CHECKS])]) m4_ifndef([_LT_AC_PROG_CXXCPP], [AC_DEFUN([_LT_AC_PROG_CXXCPP])]) m4_ifndef([_LT_PREPARE_SED_QUOTE_VARS], [AC_DEFUN([_LT_PREPARE_SED_QUOTE_VARS])]) m4_ifndef([_LT_PROG_ECHO_BACKSLASH], [AC_DEFUN([_LT_PROG_ECHO_BACKSLASH])]) m4_ifndef([_LT_PROG_F77], [AC_DEFUN([_LT_PROG_F77])]) m4_ifndef([_LT_PROG_FC], [AC_DEFUN([_LT_PROG_FC])]) m4_ifndef([_LT_PROG_CXX], [AC_DEFUN([_LT_PROG_CXX])]) ntfs-3g-2026.2.25/include/0000775000175000017500000000000015152260234010501 5ntfs-3g-2026.2.25/include/Makefile.am0000664000175000017500000000011315152260173012452 MAINTAINERCLEANFILES = $(srcdir)/Makefile.in SUBDIRS = ntfs-3g fuse-lite ntfs-3g-2026.2.25/include/Makefile.in0000664000175000017500000004670715152260212012500 # Makefile.in generated by automake 1.17 from Makefile.am. # @configure_input@ # Copyright (C) 1994-2024 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY, to the extent permitted by law; without # even the implied warranty of MERCHANTABILITY or FITNESS FOR A # PARTICULAR PURPOSE. @SET_MAKE@ VPATH = @srcdir@ am__is_gnu_make = { \ if test -z '$(MAKELEVEL)'; then \ false; \ elif test -n '$(MAKE_HOST)'; then \ true; \ elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \ true; \ else \ false; \ fi; \ } am__make_running_with_option = \ case $${target_option-} in \ ?) ;; \ *) echo "am__make_running_with_option: internal error: invalid" \ "target option '$${target_option-}' specified" >&2; \ exit 1;; \ esac; \ has_opt=no; \ sane_makeflags=$$MAKEFLAGS; \ if $(am__is_gnu_make); then \ sane_makeflags=$$MFLAGS; \ else \ case $$MAKEFLAGS in \ *\\[\ \ ]*) \ bs=\\; \ sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \ | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \ esac; \ fi; \ skip_next=no; \ strip_trailopt () \ { \ flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \ }; \ for flg in $$sane_makeflags; do \ test $$skip_next = yes && { skip_next=no; continue; }; \ case $$flg in \ *=*|--*) continue;; \ -*I) strip_trailopt 'I'; skip_next=yes;; \ -*I?*) strip_trailopt 'I';; \ -*O) strip_trailopt 'O'; skip_next=yes;; \ -*O?*) strip_trailopt 'O';; \ -*l) strip_trailopt 'l'; skip_next=yes;; \ -*l?*) strip_trailopt 'l';; \ -[dEDm]) skip_next=yes;; \ -[JT]) skip_next=yes;; \ esac; \ case $$flg in \ *$$target_option*) has_opt=yes; break;; \ esac; \ done; \ test $$has_opt = yes am__make_dryrun = (target_option=n; $(am__make_running_with_option)) am__make_keepgoing = (target_option=k; $(am__make_running_with_option)) am__rm_f = rm -f $(am__rm_f_notfound) am__rm_rf = rm -rf $(am__rm_f_notfound) pkgdatadir = $(datadir)/@PACKAGE@ pkgincludedir = $(includedir)/@PACKAGE@ pkglibdir = $(libdir)/@PACKAGE@ pkglibexecdir = $(libexecdir)/@PACKAGE@ am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd install_sh_DATA = $(install_sh) -c -m 644 install_sh_PROGRAM = $(install_sh) -c install_sh_SCRIPT = $(install_sh) -c INSTALL_HEADER = $(INSTALL_DATA) transform = $(program_transform_name) NORMAL_INSTALL = : PRE_INSTALL = : POST_INSTALL = : NORMAL_UNINSTALL = : PRE_UNINSTALL = : POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ target_triplet = @target@ subdir = include ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \ $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \ $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \ $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) DIST_COMMON = $(srcdir)/Makefile.am $(am__DIST_COMMON) mkinstalldirs = $(install_sh) -d CONFIG_HEADER = $(top_builddir)/config.h CONFIG_CLEAN_FILES = CONFIG_CLEAN_VPATH_FILES = AM_V_P = $(am__v_P_@AM_V@) am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) am__v_P_0 = false am__v_P_1 = : AM_V_GEN = $(am__v_GEN_@AM_V@) am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@) am__v_GEN_0 = @echo " GEN " $@; am__v_GEN_1 = AM_V_at = $(am__v_at_@AM_V@) am__v_at_ = $(am__v_at_@AM_DEFAULT_V@) am__v_at_0 = @ am__v_at_1 = SOURCES = DIST_SOURCES = RECURSIVE_TARGETS = all-recursive check-recursive cscopelist-recursive \ ctags-recursive dvi-recursive html-recursive info-recursive \ install-data-recursive install-dvi-recursive \ install-exec-recursive install-html-recursive \ install-info-recursive install-pdf-recursive \ install-ps-recursive install-recursive installcheck-recursive \ installdirs-recursive pdf-recursive ps-recursive \ tags-recursive uninstall-recursive am__can_run_installinfo = \ case $$AM_UPDATE_INFO_DIR in \ n|no|NO) false;; \ *) (install-info --version) >/dev/null 2>&1;; \ esac RECURSIVE_CLEAN_TARGETS = mostlyclean-recursive clean-recursive \ distclean-recursive maintainer-clean-recursive am__recursive_targets = \ $(RECURSIVE_TARGETS) \ $(RECURSIVE_CLEAN_TARGETS) \ $(am__extra_recursive_targets) AM_RECURSIVE_TARGETS = $(am__recursive_targets:-recursive=) TAGS CTAGS \ distdir distdir-am am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) # Read a list of newline-separated strings from the standard input, # and print each of them once, without duplicates. Input order is # *not* preserved. am__uniquify_input = $(AWK) '\ BEGIN { nonempty = 0; } \ { items[$$0] = 1; nonempty = 1; } \ END { if (nonempty) { for (i in items) print i; }; } \ ' # Make sure the list of sources is unique. This is necessary because, # e.g., the same source file might be shared among _SOURCES variables # for different programs/libraries. am__define_uniq_tagged_files = \ list='$(am__tagged_files)'; \ unique=`for i in $$list; do \ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ done | $(am__uniquify_input)` DIST_SUBDIRS = $(SUBDIRS) am__DIST_COMMON = $(srcdir)/Makefile.in DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) am__relativize = \ dir0=`pwd`; \ sed_first='s,^\([^/]*\)/.*$$,\1,'; \ sed_rest='s,^[^/]*/*,,'; \ sed_last='s,^.*/\([^/]*\)$$,\1,'; \ sed_butlast='s,/*[^/]*$$,,'; \ while test -n "$$dir1"; do \ first=`echo "$$dir1" | sed -e "$$sed_first"`; \ if test "$$first" != "."; then \ if test "$$first" = ".."; then \ dir2=`echo "$$dir0" | sed -e "$$sed_last"`/"$$dir2"; \ dir0=`echo "$$dir0" | sed -e "$$sed_butlast"`; \ else \ first2=`echo "$$dir2" | sed -e "$$sed_first"`; \ if test "$$first2" = "$$first"; then \ dir2=`echo "$$dir2" | sed -e "$$sed_rest"`; \ else \ dir2="../$$dir2"; \ fi; \ dir0="$$dir0"/"$$first"; \ fi; \ fi; \ dir1=`echo "$$dir1" | sed -e "$$sed_rest"`; \ done; \ reldir="$$dir2" ACLOCAL = @ACLOCAL@ AMTAR = @AMTAR@ AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ AR = @AR@ AUTOCONF = @AUTOCONF@ AUTOHEADER = @AUTOHEADER@ AUTOMAKE = @AUTOMAKE@ AWK = @AWK@ CC = @CC@ CCDEPMODE = @CCDEPMODE@ CFLAGS = @CFLAGS@ CPPFLAGS = @CPPFLAGS@ CSCOPE = @CSCOPE@ CTAGS = @CTAGS@ CYGPATH_W = @CYGPATH_W@ DEFS = @DEFS@ DEPDIR = @DEPDIR@ DLLTOOL = @DLLTOOL@ DSYMUTIL = @DSYMUTIL@ DUMPBIN = @DUMPBIN@ ECHO_C = @ECHO_C@ ECHO_N = @ECHO_N@ ECHO_T = @ECHO_T@ EGREP = @EGREP@ ETAGS = @ETAGS@ EXEEXT = @EXEEXT@ FGREP = @FGREP@ FILECMD = @FILECMD@ FUSE_MODULE_CFLAGS = @FUSE_MODULE_CFLAGS@ FUSE_MODULE_LIBS = @FUSE_MODULE_LIBS@ GNUTLS_CFLAGS = @GNUTLS_CFLAGS@ GNUTLS_LIBS = @GNUTLS_LIBS@ GPGRT_CONFIG = @GPGRT_CONFIG@ GREP = @GREP@ INSTALL = @INSTALL@ INSTALL_DATA = @INSTALL_DATA@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ INSTALL_SCRIPT = @INSTALL_SCRIPT@ INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ LD = @LD@ LDCONFIG = @LDCONFIG@ LDFLAGS = @LDFLAGS@ LIBDL = @LIBDL@ LIBFUSE_LITE_CFLAGS = @LIBFUSE_LITE_CFLAGS@ LIBFUSE_LITE_LIBS = @LIBFUSE_LITE_LIBS@ LIBGCRYPT_CFLAGS = @LIBGCRYPT_CFLAGS@ LIBGCRYPT_CONFIG = @LIBGCRYPT_CONFIG@ LIBGCRYPT_LIBS = @LIBGCRYPT_LIBS@ LIBNTFS_3G_VERSION = @LIBNTFS_3G_VERSION@ LIBNTFS_CPPFLAGS = @LIBNTFS_CPPFLAGS@ LIBNTFS_LIBS = @LIBNTFS_LIBS@ LIBOBJS = @LIBOBJS@ LIBS = @LIBS@ LIBTOOL = @LIBTOOL@ LIPO = @LIPO@ LN_S = @LN_S@ LTLIBOBJS = @LTLIBOBJS@ LT_SYS_LIBRARY_PATH = @LT_SYS_LIBRARY_PATH@ MAINT = @MAINT@ MAKEINFO = @MAKEINFO@ MANIFEST_TOOL = @MANIFEST_TOOL@ MKDIR_P = @MKDIR_P@ MKNTFS_CPPFLAGS = @MKNTFS_CPPFLAGS@ MKNTFS_LIBS = @MKNTFS_LIBS@ MV = @MV@ NM = @NM@ NMEDIT = @NMEDIT@ NTFSPROGS_STATIC_LIBS = @NTFSPROGS_STATIC_LIBS@ OBJDUMP = @OBJDUMP@ OBJEXT = @OBJEXT@ OTOOL = @OTOOL@ OTOOL64 = @OTOOL64@ OUTPUT_FORMAT = @OUTPUT_FORMAT@ PACKAGE = @PACKAGE@ PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ PACKAGE_NAME = @PACKAGE_NAME@ PACKAGE_STRING = @PACKAGE_STRING@ PACKAGE_TARNAME = @PACKAGE_TARNAME@ PACKAGE_URL = @PACKAGE_URL@ PACKAGE_VERSION = @PACKAGE_VERSION@ PATH_SEPARATOR = @PATH_SEPARATOR@ PKG_CONFIG = @PKG_CONFIG@ PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ RANLIB = @RANLIB@ RM = @RM@ SED = @SED@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ STRIP = @STRIP@ VERSION = @VERSION@ abs_builddir = @abs_builddir@ abs_srcdir = @abs_srcdir@ abs_top_builddir = @abs_top_builddir@ abs_top_srcdir = @abs_top_srcdir@ ac_ct_AR = @ac_ct_AR@ ac_ct_CC = @ac_ct_CC@ ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ all_includes = @all_includes@ all_libraries = @all_libraries@ am__include = @am__include@ am__leading_dot = @am__leading_dot@ am__quote = @am__quote@ am__rm_f_notfound = @am__rm_f_notfound@ am__tar = @am__tar@ am__untar = @am__untar@ am__xargs_n = @am__xargs_n@ bindir = @bindir@ build = @build@ build_alias = @build_alias@ build_cpu = @build_cpu@ build_os = @build_os@ build_vendor = @build_vendor@ builddir = @builddir@ datadir = @datadir@ datarootdir = @datarootdir@ docdir = @docdir@ dvidir = @dvidir@ exec_prefix = @exec_prefix@ host = @host@ host_alias = @host_alias@ host_cpu = @host_cpu@ host_os = @host_os@ host_vendor = @host_vendor@ htmldir = @htmldir@ includedir = @includedir@ infodir = @infodir@ install_sh = @install_sh@ libdir = @libdir@ libexecdir = @libexecdir@ localedir = @localedir@ localstatedir = @localstatedir@ mandir = @mandir@ mkdir_p = @mkdir_p@ ntfs3gincludedir = @ntfs3gincludedir@ oldincludedir = @oldincludedir@ pdfdir = @pdfdir@ pkgconfigdir = @pkgconfigdir@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ rootbindir = @rootbindir@ rootlibdir = @rootlibdir@ rootsbindir = @rootsbindir@ runstatedir = @runstatedir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ sysconfdir = @sysconfdir@ target = @target@ target_alias = @target_alias@ target_cpu = @target_cpu@ target_os = @target_os@ target_vendor = @target_vendor@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ MAINTAINERCLEANFILES = $(srcdir)/Makefile.in SUBDIRS = ntfs-3g fuse-lite all: all-recursive .SUFFIXES: $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) @for dep in $?; do \ case '$(am__configure_deps)' in \ *$$dep*) \ ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ && { if test -f $@; then exit 0; else break; fi; }; \ exit 1;; \ esac; \ done; \ echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu include/Makefile'; \ $(am__cd) $(top_srcdir) && \ $(AUTOMAKE) --gnu include/Makefile Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status @case '$?' in \ *config.status*) \ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ *) \ echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles)'; \ cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles);; \ esac; $(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh $(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh $(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh $(am__aclocal_m4_deps): mostlyclean-libtool: -rm -f *.lo clean-libtool: -rm -rf .libs _libs # This directory's subdirectories are mostly independent; you can cd # into them and run 'make' without going through this Makefile. # To change the values of 'make' variables: instead of editing Makefiles, # (1) if the variable is set in 'config.status', edit 'config.status' # (which will cause the Makefiles to be regenerated when you run 'make'); # (2) otherwise, pass the desired values on the 'make' command line. $(am__recursive_targets): @fail=; \ if $(am__make_keepgoing); then \ failcom='fail=yes'; \ else \ failcom='exit 1'; \ fi; \ dot_seen=no; \ target=`echo $@ | sed s/-recursive//`; \ case "$@" in \ distclean-* | maintainer-clean-*) list='$(DIST_SUBDIRS)' ;; \ *) list='$(SUBDIRS)' ;; \ esac; \ for subdir in $$list; do \ echo "Making $$target in $$subdir"; \ if test "$$subdir" = "."; then \ dot_seen=yes; \ local_target="$$target-am"; \ else \ local_target="$$target"; \ fi; \ ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \ || eval $$failcom; \ done; \ if test "$$dot_seen" = "no"; then \ $(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \ fi; test -z "$$fail" ID: $(am__tagged_files) $(am__define_uniq_tagged_files); mkid -fID $$unique tags: tags-recursive TAGS: tags tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) set x; \ here=`pwd`; \ if ($(ETAGS) --etags-include --version) >/dev/null 2>&1; then \ include_option=--etags-include; \ empty_fix=.; \ else \ include_option=--include; \ empty_fix=; \ fi; \ list='$(SUBDIRS)'; for subdir in $$list; do \ if test "$$subdir" = .; then :; else \ test ! -f $$subdir/TAGS || \ set "$$@" "$$include_option=$$here/$$subdir/TAGS"; \ fi; \ done; \ $(am__define_uniq_tagged_files); \ shift; \ if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ test -n "$$unique" || unique=$$empty_fix; \ if test $$# -gt 0; then \ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ "$$@" $$unique; \ else \ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ $$unique; \ fi; \ fi ctags: ctags-recursive CTAGS: ctags ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) $(am__define_uniq_tagged_files); \ test -z "$(CTAGS_ARGS)$$unique" \ || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ $$unique GTAGS: here=`$(am__cd) $(top_builddir) && pwd` \ && $(am__cd) $(top_srcdir) \ && gtags -i $(GTAGS_ARGS) "$$here" cscopelist: cscopelist-recursive cscopelist-am: $(am__tagged_files) list='$(am__tagged_files)'; \ case "$(srcdir)" in \ [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \ *) sdir=$(subdir)/$(srcdir) ;; \ esac; \ for i in $$list; do \ if test -f "$$i"; then \ echo "$(subdir)/$$i"; \ else \ echo "$$sdir/$$i"; \ fi; \ done >> $(top_builddir)/cscope.files distclean-tags: -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags distdir: $(BUILT_SOURCES) $(MAKE) $(AM_MAKEFLAGS) distdir-am distdir-am: $(DISTFILES) @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ list='$(DISTFILES)'; \ dist_files=`for file in $$list; do echo $$file; done | \ sed -e "s|^$$srcdirstrip/||;t" \ -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ case $$dist_files in \ */*) $(MKDIR_P) `echo "$$dist_files" | \ sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ sort -u` ;; \ esac; \ for file in $$dist_files; do \ if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ if test -d $$d/$$file; then \ dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ if test -d "$(distdir)/$$file"; then \ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ fi; \ if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ fi; \ cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ else \ test -f "$(distdir)/$$file" \ || cp -p $$d/$$file "$(distdir)/$$file" \ || exit 1; \ fi; \ done @list='$(DIST_SUBDIRS)'; for subdir in $$list; do \ if test "$$subdir" = .; then :; else \ $(am__make_dryrun) \ || test -d "$(distdir)/$$subdir" \ || $(MKDIR_P) "$(distdir)/$$subdir" \ || exit 1; \ dir1=$$subdir; dir2="$(distdir)/$$subdir"; \ $(am__relativize); \ new_distdir=$$reldir; \ dir1=$$subdir; dir2="$(top_distdir)"; \ $(am__relativize); \ new_top_distdir=$$reldir; \ echo " (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) top_distdir="$$new_top_distdir" distdir="$$new_distdir" \\"; \ echo " am__remove_distdir=: am__skip_length_check=: am__skip_mode_fix=: distdir)"; \ ($(am__cd) $$subdir && \ $(MAKE) $(AM_MAKEFLAGS) \ top_distdir="$$new_top_distdir" \ distdir="$$new_distdir" \ am__remove_distdir=: \ am__skip_length_check=: \ am__skip_mode_fix=: \ distdir) \ || exit 1; \ fi; \ done check-am: all-am check: check-recursive all-am: Makefile installdirs: installdirs-recursive installdirs-am: install: install-recursive install-exec: install-exec-recursive install-data: install-data-recursive uninstall: uninstall-recursive install-am: all-am @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am installcheck: installcheck-recursive install-strip: if test -z '$(STRIP)'; then \ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ install; \ else \ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ fi mostlyclean-generic: clean-generic: distclean-generic: -$(am__rm_f) $(CONFIG_CLEAN_FILES) -test . = "$(srcdir)" || $(am__rm_f) $(CONFIG_CLEAN_VPATH_FILES) maintainer-clean-generic: @echo "This command is intended for maintainers to use" @echo "it deletes files that may require special tools to rebuild." -$(am__rm_f) $(MAINTAINERCLEANFILES) clean: clean-recursive clean-am: clean-generic clean-libtool mostlyclean-am distclean: distclean-recursive -rm -f Makefile distclean-am: clean-am distclean-generic distclean-tags dvi: dvi-recursive dvi-am: html: html-recursive html-am: info: info-recursive info-am: install-data-am: install-dvi: install-dvi-recursive install-dvi-am: install-exec-am: install-html: install-html-recursive install-html-am: install-info: install-info-recursive install-info-am: install-man: install-pdf: install-pdf-recursive install-pdf-am: install-ps: install-ps-recursive install-ps-am: installcheck-am: maintainer-clean: maintainer-clean-recursive -rm -f Makefile maintainer-clean-am: distclean-am maintainer-clean-generic mostlyclean: mostlyclean-recursive mostlyclean-am: mostlyclean-generic mostlyclean-libtool pdf: pdf-recursive pdf-am: ps: ps-recursive ps-am: uninstall-am: .MAKE: $(am__recursive_targets) install-am install-strip .PHONY: $(am__recursive_targets) CTAGS GTAGS TAGS all all-am check \ check-am clean clean-generic clean-libtool cscopelist-am ctags \ ctags-am distclean distclean-generic distclean-libtool \ distclean-tags distdir dvi dvi-am html html-am info info-am \ install install-am install-data install-data-am install-dvi \ install-dvi-am install-exec install-exec-am install-html \ install-html-am install-info install-info-am install-man \ install-pdf install-pdf-am install-ps install-ps-am \ install-strip installcheck installcheck-am installdirs \ installdirs-am maintainer-clean maintainer-clean-generic \ mostlyclean mostlyclean-generic mostlyclean-libtool pdf pdf-am \ ps ps-am tags tags-am uninstall uninstall-am .PRECIOUS: Makefile # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. .NOEXPORT: # Tell GNU make to disable its built-in pattern rules. %:: %,v %:: RCS/%,v %:: RCS/% %:: s.% %:: SCCS/s.% ntfs-3g-2026.2.25/include/ntfs-3g/0000775000175000017500000000000015152260234011762 5ntfs-3g-2026.2.25/include/ntfs-3g/cache.h0000664000175000017500000000645215152260173013127 /* * cache.h : deal with indexed LRU caches * * Copyright (c) 2008-2010 Jean-Pierre Andre * * This program/include file 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/include file 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_CACHE_H_ #define _NTFS_CACHE_H_ #include "volume.h" struct CACHED_GENERIC { struct CACHED_GENERIC *next; struct CACHED_GENERIC *previous; void *variable; size_t varsize; union ALIGNMENT payload[0]; } ; struct CACHED_INODE { struct CACHED_INODE *next; struct CACHED_INODE *previous; const char *pathname; size_t varsize; union ALIGNMENT payload[0]; /* above fields must match "struct CACHED_GENERIC" */ u64 inum; } ; struct CACHED_NIDATA { struct CACHED_NIDATA *next; struct CACHED_NIDATA *previous; const char *pathname; /* not used */ size_t varsize; /* not used */ union ALIGNMENT payload[0]; /* above fields must match "struct CACHED_GENERIC" */ u64 inum; ntfs_inode *ni; } ; struct CACHED_LOOKUP { struct CACHED_LOOKUP *next; struct CACHED_LOOKUP *previous; const char *name; size_t namesize; union ALIGNMENT payload[0]; /* above fields must match "struct CACHED_GENERIC" */ u64 parent; u64 inum; } ; enum { CACHE_FREE = 1, CACHE_NOHASH = 2 } ; typedef int (*cache_compare)(const struct CACHED_GENERIC *cached, const struct CACHED_GENERIC *item); typedef void (*cache_free)(const struct CACHED_GENERIC *cached); typedef int (*cache_hash)(const struct CACHED_GENERIC *cached); struct HASH_ENTRY { struct HASH_ENTRY *next; struct CACHED_GENERIC *entry; } ; struct CACHE_HEADER { const char *name; struct CACHED_GENERIC *most_recent_entry; struct CACHED_GENERIC *oldest_entry; struct CACHED_GENERIC *free_entry; struct HASH_ENTRY *free_hash; struct HASH_ENTRY **first_hash; cache_free dofree; cache_hash dohash; unsigned long reads; unsigned long writes; unsigned long hits; int fixed_size; int max_hash; struct CACHED_GENERIC entry[0]; } ; /* cast to generic, avoiding gcc warnings */ #define GENERIC(pstr) ((const struct CACHED_GENERIC*)(const void*)(pstr)) struct CACHED_GENERIC *ntfs_fetch_cache(struct CACHE_HEADER *cache, const struct CACHED_GENERIC *wanted, cache_compare compare); struct CACHED_GENERIC *ntfs_enter_cache(struct CACHE_HEADER *cache, const struct CACHED_GENERIC *item, cache_compare compare); int ntfs_invalidate_cache(struct CACHE_HEADER *cache, const struct CACHED_GENERIC *item, cache_compare compare, int flags); int ntfs_remove_cache(struct CACHE_HEADER *cache, struct CACHED_GENERIC *item, int flags); void ntfs_create_lru_caches(ntfs_volume *vol); void ntfs_free_lru_caches(ntfs_volume *vol); #endif /* _NTFS_CACHE_H_ */ ntfs-3g-2026.2.25/include/ntfs-3g/attrlist.h0000664000175000017500000000332115152260173013722 /* * attrlist.h - Exports for attribute list attribute handling. * Originated from Linux-NTFS project. * * Copyright (c) 2004 Anton Altaparmakov * Copyright (c) 2004 Yura Pakhuchiy * * This program/include file 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/include file 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_ATTRLIST_H #define _NTFS_ATTRLIST_H #include "attrib.h" extern int ntfs_attrlist_need(ntfs_inode *ni); extern int ntfs_attrlist_entry_add(ntfs_inode *ni, ATTR_RECORD *attr); extern int ntfs_attrlist_entry_rm(ntfs_attr_search_ctx *ctx); /** * ntfs_attrlist_mark_dirty - set the attribute list dirty * @ni: ntfs inode which base inode contain dirty attribute list * * Set the attribute list dirty so it is written out later (at the latest at * ntfs_inode_close() time). * * This function cannot fail. */ static __inline__ void ntfs_attrlist_mark_dirty(ntfs_inode *ni) { if (ni->nr_extents == -1) NInoAttrListSetDirty(ni->base_ni); else NInoAttrListSetDirty(ni); } #endif /* defined _NTFS_ATTRLIST_H */ ntfs-3g-2026.2.25/include/ntfs-3g/volume.h0000664000175000017500000002737515152260173013402 /* * volume.h - Exports for NTFS volume handling. Originated from the Linux-NTFS project. * * Copyright (c) 2000-2004 Anton Altaparmakov * Copyright (c) 2004-2005 Richard Russon * Copyright (c) 2005-2006 Yura Pakhuchiy * Copyright (c) 2005-2009 Szabolcs Szakacsits * Copyright (c) 2010 Jean-Pierre Andre * * This program/include file 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/include file 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_VOLUME_H #define _NTFS_VOLUME_H #ifdef HAVE_CONFIG_H #include "config.h" #endif #ifdef HAVE_STDIO_H #include #endif #ifdef HAVE_SYS_PARAM_H #include #endif /* Do not #include here : conflicts with */ #ifdef HAVE_MNTENT_H #include #endif /* Forward declaration */ typedef struct _ntfs_volume ntfs_volume; #include "param.h" #include "types.h" #include "support.h" #include "device.h" #include "inode.h" #include "attrib.h" #include "index.h" /** * enum ntfs_mount_flags - * * Flags for the ntfs_mount() function. */ enum { NTFS_MNT_NONE = 0x00000000, NTFS_MNT_RDONLY = 0x00000001, NTFS_MNT_MAY_RDONLY = 0x02000000, /* Allow fallback to ro */ NTFS_MNT_FORENSIC = 0x04000000, /* No modification during * mount. */ NTFS_MNT_EXCLUSIVE = 0x08000000, NTFS_MNT_RECOVER = 0x10000000, NTFS_MNT_IGNORE_HIBERFILE = 0x20000000, }; typedef unsigned long ntfs_mount_flags; /** * enum ntfs_mounted_flags - * * Flags returned by the ntfs_check_if_mounted() function. */ typedef enum { NTFS_MF_MOUNTED = 1, /* Device is mounted. */ NTFS_MF_ISROOT = 2, /* Device is mounted as system root. */ NTFS_MF_READONLY = 4, /* Device is mounted read-only. */ } ntfs_mounted_flags; extern int ntfs_check_if_mounted(const char *file, unsigned long *mnt_flags); typedef enum { NTFS_VOLUME_OK = 0, NTFS_VOLUME_SYNTAX_ERROR = 11, NTFS_VOLUME_NOT_NTFS = 12, NTFS_VOLUME_CORRUPT = 13, NTFS_VOLUME_HIBERNATED = 14, NTFS_VOLUME_UNCLEAN_UNMOUNT = 15, NTFS_VOLUME_LOCKED = 16, NTFS_VOLUME_RAID = 17, NTFS_VOLUME_UNKNOWN_REASON = 18, NTFS_VOLUME_NO_PRIVILEGE = 19, NTFS_VOLUME_OUT_OF_MEMORY = 20, NTFS_VOLUME_FUSE_ERROR = 21, NTFS_VOLUME_INSECURE = 22 } ntfs_volume_status; typedef enum { NTFS_FILES_INTERIX, NTFS_FILES_WSL, } ntfs_volume_special_files; /** * enum ntfs_volume_state_bits - * * Defined bits for the state field in the ntfs_volume structure. */ typedef enum { NV_ReadOnly, /* 1: Volume is read-only. */ NV_CaseSensitive, /* 1: Volume is mounted case-sensitive. */ NV_LogFileEmpty, /* 1: $logFile journal is empty. */ NV_ShowSysFiles, /* 1: Show NTFS metafiles. */ NV_ShowHidFiles, /* 1: Show files marked hidden. */ NV_HideDotFiles, /* 1: Set hidden flag on dot files */ NV_Compression, /* 1: allow compression */ NV_NoFixupWarn, /* 1: Do not log fixup errors */ NV_FreeSpaceKnown, /* 1: The free space is now known */ } ntfs_volume_state_bits; #define test_nvol_flag(nv, flag) test_bit(NV_##flag, (nv)->state) #define set_nvol_flag(nv, flag) set_bit(NV_##flag, (nv)->state) #define clear_nvol_flag(nv, flag) clear_bit(NV_##flag, (nv)->state) #define NVolReadOnly(nv) test_nvol_flag(nv, ReadOnly) #define NVolSetReadOnly(nv) set_nvol_flag(nv, ReadOnly) #define NVolClearReadOnly(nv) clear_nvol_flag(nv, ReadOnly) #define NVolCaseSensitive(nv) test_nvol_flag(nv, CaseSensitive) #define NVolSetCaseSensitive(nv) set_nvol_flag(nv, CaseSensitive) #define NVolClearCaseSensitive(nv) clear_nvol_flag(nv, CaseSensitive) #define NVolLogFileEmpty(nv) test_nvol_flag(nv, LogFileEmpty) #define NVolSetLogFileEmpty(nv) set_nvol_flag(nv, LogFileEmpty) #define NVolClearLogFileEmpty(nv) clear_nvol_flag(nv, LogFileEmpty) #define NVolShowSysFiles(nv) test_nvol_flag(nv, ShowSysFiles) #define NVolSetShowSysFiles(nv) set_nvol_flag(nv, ShowSysFiles) #define NVolClearShowSysFiles(nv) clear_nvol_flag(nv, ShowSysFiles) #define NVolShowHidFiles(nv) test_nvol_flag(nv, ShowHidFiles) #define NVolSetShowHidFiles(nv) set_nvol_flag(nv, ShowHidFiles) #define NVolClearShowHidFiles(nv) clear_nvol_flag(nv, ShowHidFiles) #define NVolHideDotFiles(nv) test_nvol_flag(nv, HideDotFiles) #define NVolSetHideDotFiles(nv) set_nvol_flag(nv, HideDotFiles) #define NVolClearHideDotFiles(nv) clear_nvol_flag(nv, HideDotFiles) #define NVolCompression(nv) test_nvol_flag(nv, Compression) #define NVolSetCompression(nv) set_nvol_flag(nv, Compression) #define NVolClearCompression(nv) clear_nvol_flag(nv, Compression) #define NVolNoFixupWarn(nv) test_nvol_flag(nv, NoFixupWarn) #define NVolSetNoFixupWarn(nv) set_nvol_flag(nv, NoFixupWarn) #define NVolClearNoFixupWarn(nv) clear_nvol_flag(nv, NoFixupWarn) #define NVolFreeSpaceKnown(nv) test_nvol_flag(nv, FreeSpaceKnown) #define NVolSetFreeSpaceKnown(nv) set_nvol_flag(nv, FreeSpaceKnown) #define NVolClearFreeSpaceKnown(nv) clear_nvol_flag(nv, FreeSpaceKnown) /* * NTFS version 1.1 and 1.2 are used by Windows NT4. * NTFS version 2.x is used by Windows 2000 Beta * NTFS version 3.0 is used by Windows 2000. * NTFS version 3.1 is used by Windows XP, 2003 and Vista. */ #define NTFS_V1_1(major, minor) ((major) == 1 && (minor) == 1) #define NTFS_V1_2(major, minor) ((major) == 1 && (minor) == 2) #define NTFS_V2_X(major, minor) ((major) == 2) #define NTFS_V3_0(major, minor) ((major) == 3 && (minor) == 0) #define NTFS_V3_1(major, minor) ((major) == 3 && (minor) == 1) #define NTFS_BUF_SIZE 8192 /** * struct _ntfs_volume - structure describing an open volume in memory. */ struct _ntfs_volume { union { struct ntfs_device *dev; /* NTFS device associated with the volume. */ void *sb; /* For kernel porting compatibility. */ }; char *vol_name; /* Name of the volume. */ unsigned long state; /* NTFS specific flags describing this volume. See ntfs_volume_state_bits above. */ ntfs_inode *vol_ni; /* ntfs_inode structure for FILE_Volume. */ u8 major_ver; /* Ntfs major version of volume. */ u8 minor_ver; /* Ntfs minor version of volume. */ le16 flags; /* Bit array of VOLUME_* flags. */ u16 sector_size; /* Byte size of a sector. */ u8 sector_size_bits; /* Log(2) of the byte size of a sector. */ u32 cluster_size; /* Byte size of a cluster. */ u32 mft_record_size; /* Byte size of a mft record. */ u32 indx_record_size; /* Byte size of a INDX record. */ u8 cluster_size_bits; /* Log(2) of the byte size of a cluster. */ u8 mft_record_size_bits;/* Log(2) of the byte size of a mft record. */ u8 indx_record_size_bits;/* Log(2) of the byte size of a INDX record. */ /* Variables used by the cluster and mft allocators. */ u8 mft_zone_multiplier; /* Initial mft zone multiplier. */ u8 full_zones; /* cluster zones which are full */ s64 mft_data_pos; /* Mft record number at which to allocate the next mft record. */ LCN mft_zone_start; /* First cluster of the mft zone. */ LCN mft_zone_end; /* First cluster beyond the mft zone. */ LCN mft_zone_pos; /* Current position in the mft zone. */ LCN data1_zone_pos; /* Current position in the first data zone. */ LCN data2_zone_pos; /* Current position in the second data zone. */ s64 nr_clusters; /* Volume size in clusters, hence also the number of bits in lcn_bitmap. */ ntfs_inode *lcnbmp_ni; /* ntfs_inode structure for FILE_Bitmap. */ ntfs_attr *lcnbmp_na; /* ntfs_attr structure for the data attribute of FILE_Bitmap. Each bit represents a cluster on the volume, bit 0 representing lcn 0 and so on. A set bit means that the cluster and vice versa. */ LCN mft_lcn; /* Logical cluster number of the data attribute for FILE_MFT. */ ntfs_inode *mft_ni; /* ntfs_inode structure for FILE_MFT. */ ntfs_attr *mft_na; /* ntfs_attr structure for the data attribute of FILE_MFT. */ ntfs_attr *mftbmp_na; /* ntfs_attr structure for the bitmap attribute of FILE_MFT. Each bit represents an mft record in the $DATA attribute, bit 0 representing mft record 0 and so on. A set bit means that the mft record is in use and vice versa. */ ntfs_inode *secure_ni; /* ntfs_inode structure for FILE $Secure */ ntfs_index_context *secure_xsii; /* index for using $Secure:$SII */ ntfs_index_context *secure_xsdh; /* index for using $Secure:$SDH */ int secure_reentry; /* check for non-rentries */ unsigned int secure_flags; /* flags, see security.h for values */ int mftmirr_size; /* Size of the FILE_MFTMirr in mft records. */ LCN mftmirr_lcn; /* Logical cluster number of the data attribute for FILE_MFTMirr. */ ntfs_inode *mftmirr_ni; /* ntfs_inode structure for FILE_MFTMirr. */ ntfs_attr *mftmirr_na; /* ntfs_attr structure for the data attribute of FILE_MFTMirr. */ ntfschar *upcase; /* Upper case equivalents of all 65536 2-byte Unicode characters. Obtained from FILE_UpCase. */ u32 upcase_len; /* Length in Unicode characters of the upcase table. */ ntfschar *locase; /* Lower case equivalents of all 65536 2-byte Unicode characters. Only if option case_ignore is set. */ ATTR_DEF *attrdef; /* Attribute definitions. Obtained from FILE_AttrDef. */ s32 attrdef_len; /* Size of the attribute definition table in bytes. */ s64 free_clusters; /* Track the number of free clusters which greatly improves statfs() performance */ s64 free_mft_records; /* Same for free mft records (see above) */ BOOL efs_raw; /* volume is mounted for raw access to efs-encrypted files */ ntfs_volume_special_files special_files; /* Implementation of special files */ const char *abs_mnt_point; /* Mount point */ #ifdef XATTR_MAPPINGS struct XATTRMAPPING *xattr_mapping; #endif /* XATTR_MAPPINGS */ #if CACHE_INODE_SIZE struct CACHE_HEADER *xinode_cache; #endif #if CACHE_NIDATA_SIZE struct CACHE_HEADER *nidata_cache; #endif #if CACHE_LOOKUP_SIZE struct CACHE_HEADER *lookup_cache; #endif #if CACHE_SECURID_SIZE struct CACHE_HEADER *securid_cache; #endif #if CACHE_LEGACY_SIZE struct CACHE_HEADER *legacy_cache; #endif }; extern const char *ntfs_home; extern ntfs_volume *ntfs_volume_alloc(void); extern ntfs_volume *ntfs_volume_startup(struct ntfs_device *dev, ntfs_mount_flags flags); extern ntfs_volume *ntfs_device_mount(struct ntfs_device *dev, ntfs_mount_flags flags); extern ntfs_volume *ntfs_mount(const char *name, ntfs_mount_flags flags); extern int ntfs_umount(ntfs_volume *vol, const BOOL force); extern int ntfs_version_is_supported(ntfs_volume *vol); extern int ntfs_volume_check_hiberfile(ntfs_volume *vol, int verbose); extern int ntfs_logfile_reset(ntfs_volume *vol); extern int ntfs_volume_write_flags(ntfs_volume *vol, const le16 flags); extern int ntfs_volume_error(int err); extern void ntfs_mount_error(const char *vol, const char *mntpoint, int err); extern int ntfs_volume_get_free_space(ntfs_volume *vol); extern int ntfs_volume_rename(ntfs_volume *vol, const ntfschar *label, int label_len); extern int ntfs_set_shown_files(ntfs_volume *vol, BOOL show_sys_files, BOOL show_hid_files, BOOL hide_dot_files); extern int ntfs_set_locale(void); extern int ntfs_set_ignore_case(ntfs_volume *vol); #endif /* defined _NTFS_VOLUME_H */ ntfs-3g-2026.2.25/include/ntfs-3g/param.h0000664000175000017500000001243215152260173013157 /* * param.h - Parameter values for ntfs-3g * * Copyright (c) 2009-2010 Jean-Pierre Andre * * This program/include file 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/include file 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_PARAM_H #define _NTFS_PARAM_H #define CACHE_INODE_SIZE 32 /* inode cache, zero or >= 3 and not too big */ #define CACHE_NIDATA_SIZE 64 /* idata cache, zero or >= 3 and not too big */ #define CACHE_LOOKUP_SIZE 64 /* lookup cache, zero or >= 3 and not too big */ #define CACHE_SECURID_SIZE 16 /* securid cache, zero or >= 3 and not too big */ #define CACHE_LEGACY_SIZE 8 /* legacy cache size, zero or >= 3 and not too big */ #define FORCE_FORMAT_v1x 0 /* Insert security data as in NTFS v1.x */ #define OWNERFROMACL 1 /* Get the owner from ACL (not Windows owner) */ /* default security sub-authorities */ enum { DEFSECAUTH1 = -1153374643, /* 3141592653 */ DEFSECAUTH2 = 589793238, DEFSECAUTH3 = 462843383, DEFSECBASE = 10000 }; /* * Parameters for formatting */ /* Up to Windows 10, the cluster size was limited to 64K */ #define NTFS_MAX_CLUSTER_SIZE 2097152 /* Windows 10 Creators allows 2MB */ /* * Parameters for compression */ /* default option for compression */ #define DEFAULT_COMPRESSION 1 /* (log2 of) number of clusters in a compression block for new files */ #define STANDARD_COMPRESSION_UNIT 4 /* maximum cluster size for allowing compression for new files */ #define MAX_COMPRESSION_CLUSTER_SIZE 4096 /* * Parameters for default options */ #define DEFAULT_DMTIME 60 /* default 1mn for delay_mtime */ /* * Use of big write buffers * * With small volumes, the cluster allocator may fail to allocate * enough clusters when the volume is nearly full. At most a run * can be allocated per bitmap chunk. So, there is a danger when the * number of chunks (capacity/(32768*clsiz)) is less than the number * of clusters in the biggest write buffer (131072/clsiz). Hence * a safe minimal capacity is 4GB */ #define SAFE_CAPACITY_FOR_BIG_WRITES 0x100000000LL /* * Parameters for runlists */ /* only update the final extent of a runlist when appending data */ #define PARTIAL_RUNLIST_UPDATING 1 /* * Parameters for upper-case table */ /* Create upper-case tables as defined by Windows 6.1 (Win7) */ #define UPCASE_MAJOR 6 #define UPCASE_MINOR 1 /* * Parameters for user and xattr mappings */ #define XATTRMAPPINGFILE ".NTFS-3G/XattrMapping" /* default mapping file */ /* * Parameters for path canonicalization */ #define MAPPERNAMELTH 256 /* * Permission checking modes for high level and low level * * The choices for high and low lowel are independent, they have * no effect on the library * * Stick to the recommended values unless you understand the consequences * on protection and performances. Use of cacheing is good for * performances, but bad on security with internal fuse or external * fuse older than 2.8 * * On Linux, cacheing is discouraged for the high level interface * in order to get proper support of hard links. As a consequence, * having access control in the file system leads to fewer requests * to the file system and fewer context switches. * * Irrespective of the selected mode, cacheing is always used * in read-only mounts * * Possible values for high level : * 1 : no cache, kernel control (recommended) * 4 : no cache, file system control * 6 : kernel/fuse cache, file system control (OpenIndiana only) * 7 : no cache, kernel control for ACLs * * Possible values for low level : * 2 : no cache, kernel control * 3 : use kernel/fuse cache, kernel control (recommended) * 5 : no cache, file system control * 6 : kernel/fuse cache, file system control (OpenIndiana only) * 8 : no cache, kernel control for ACLs * 9 : kernel/fuse cache, kernel control for ACLs (target) * * Use of options 7, 8 and 9 requires a fuse module upgrade * When Posix ACLs are selected in the configure options, a value * of 6 is added in the mount report. */ #define TIMEOUT_RO 600 /* Attribute time out for read-only mounts */ #if defined(__sun) && defined(__SVR4) /* * Access control by kernel is not implemented on OpenIndiana, * however care is taken of cacheing hard-linked files. */ #define HPERMSCONFIG 6 #define LPERMSCONFIG 6 #else /* defined(__sun) && defined(__SVR4) */ /* * Cacheing by kernel is buggy on Linux when access control is done * by the file system, and also when using hard-linked files on * the fuse high level interface. * Also ACL checks by recent kernels do not prove satisfactory. */ #define HPERMSCONFIG 1 #define LPERMSCONFIG 3 #endif /* defined(__sun) && defined(__SVR4) */ #endif /* defined _NTFS_PARAM_H */ ntfs-3g-2026.2.25/include/ntfs-3g/acls.h0000664000175000017500000001432115152260173013000 /* * * Copyright (c) 2007-2008 Jean-Pierre Andre * */ /* * 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 ACLS_H #define ACLS_H #include "endians.h" /* * JPA configuration modes for security.c / acls.c * should be moved to some config file */ #define BUFSZ 1024 /* buffer size to read mapping file */ #define MAPPINGFILE ".NTFS-3G/UserMapping" /* default mapping file */ #define LINESZ 120 /* maximum useful size of a mapping line */ #define CACHE_PERMISSIONS_BITS 6 /* log2 of unitary allocation of permissions */ #define CACHE_PERMISSIONS_SIZE 262144 /* max cacheable permissions */ /* * Matching of ntfs permissions to Linux permissions * these constants are adapted to endianness * when setting, set them all * when checking, check one is present */ /* flags which are set to mean exec, write or read */ #define FILE_READ (FILE_READ_DATA) #define FILE_WRITE (FILE_WRITE_DATA | FILE_APPEND_DATA \ | READ_CONTROL | FILE_WRITE_ATTRIBUTES | FILE_WRITE_EA) #define FILE_EXEC (FILE_EXECUTE) #define DIR_READ FILE_LIST_DIRECTORY #define DIR_WRITE (FILE_ADD_FILE | FILE_ADD_SUBDIRECTORY | FILE_DELETE_CHILD \ | READ_CONTROL | FILE_WRITE_ATTRIBUTES | FILE_WRITE_EA) #define DIR_EXEC (FILE_TRAVERSE) /* flags tested for meaning exec, write or read */ /* tests for write allow for interpretation of a sticky bit */ #define FILE_GREAD (FILE_READ_DATA | GENERIC_READ) #define FILE_GWRITE (FILE_WRITE_DATA | FILE_APPEND_DATA | GENERIC_WRITE) #define FILE_GEXEC (FILE_EXECUTE | GENERIC_EXECUTE) #define DIR_GREAD (FILE_LIST_DIRECTORY | GENERIC_READ) #define DIR_GWRITE (FILE_ADD_FILE | FILE_ADD_SUBDIRECTORY | GENERIC_WRITE) #define DIR_GEXEC (FILE_TRAVERSE | GENERIC_EXECUTE) /* standard owner (and administrator) rights */ #define OWNER_RIGHTS (DELETE | READ_CONTROL | WRITE_DAC | WRITE_OWNER \ | SYNCHRONIZE \ | FILE_READ_ATTRIBUTES | FILE_WRITE_ATTRIBUTES \ | FILE_READ_EA | FILE_WRITE_EA) /* standard world rights */ #define WORLD_RIGHTS (READ_CONTROL | FILE_READ_ATTRIBUTES | FILE_READ_EA \ | SYNCHRONIZE) /* inheritance flags for files and directories */ #define FILE_INHERITANCE NO_PROPAGATE_INHERIT_ACE #define DIR_INHERITANCE (OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE) /* * To identify NTFS ACL meaning Posix ACL granted to root * we use rights always granted to anybody, so they have no impact * either on Windows or on Linux. */ #define ROOT_OWNER_UNMARK SYNCHRONIZE /* ACL granted to root as owner */ #define ROOT_GROUP_UNMARK FILE_READ_EA /* ACL granted to root as group */ /* * Maximum SID size and a type large enough to hold it */ #define MAX_SID_SIZE (8 + SID_MAX_SUB_AUTHORITIES*4) typedef char BIGSID[MAX_SID_SIZE]; /* * Struct to hold the input mapping file * (private to this module) */ struct MAPLIST { struct MAPLIST *next; char *uidstr; /* uid text from the same record */ char *gidstr; /* gid text from the same record */ char *sidstr; /* sid text from the same record */ char maptext[LINESZ + 1]; }; typedef int (*FILEREADER)(void *fileid, char *buf, size_t size, off_t pos); /* * Constants defined in acls.c */ extern const SID *adminsid; extern const SID *worldsid; /* * Functions defined in acls.c */ BOOL ntfs_valid_descr(const char *securattr, unsigned int attrsz); BOOL ntfs_valid_pattern(const SID *sid); BOOL ntfs_valid_sid(const SID *sid); BOOL ntfs_same_sid(const SID *first, const SID *second); BOOL ntfs_is_user_sid(const SID *usid); int ntfs_sid_size(const SID * sid); unsigned int ntfs_attr_size(const char *attr); const SID *ntfs_find_usid(const struct MAPPING *usermapping, uid_t uid, SID *pdefsid); const SID *ntfs_find_gsid(const struct MAPPING *groupmapping, gid_t gid, SID *pdefsid); uid_t ntfs_find_user(const struct MAPPING *usermapping, const SID *usid); gid_t ntfs_find_group(const struct MAPPING *groupmapping, const SID * gsid); const SID *ntfs_acl_owner(const char *secattr); #if POSIXACLS BOOL ntfs_valid_posix(const struct POSIX_SECURITY *pxdesc); void ntfs_sort_posix(struct POSIX_SECURITY *pxdesc); int ntfs_merge_mode_posix(struct POSIX_SECURITY *pxdesc, mode_t mode); struct POSIX_SECURITY *ntfs_build_inherited_posix( const struct POSIX_SECURITY *pxdesc, mode_t mode, mode_t umask, BOOL isdir); struct POSIX_SECURITY *ntfs_build_basic_posix( const struct POSIX_SECURITY *pxdesc, mode_t mode, mode_t umask, BOOL isdir); struct POSIX_SECURITY *ntfs_replace_acl(const struct POSIX_SECURITY *oldpxdesc, const struct POSIX_ACL *newacl, int count, BOOL deflt); struct POSIX_SECURITY *ntfs_build_permissions_posix( struct MAPPING* const mapping[], const char *securattr, const SID *usid, const SID *gsid, BOOL isdir); struct POSIX_SECURITY *ntfs_merge_descr_posix(const struct POSIX_SECURITY *first, const struct POSIX_SECURITY *second); char *ntfs_build_descr_posix(struct MAPPING* const mapping[], struct POSIX_SECURITY *pxdesc, int isdir, const SID *usid, const SID *gsid); #endif /* POSIXACLS */ int ntfs_inherit_acl(const ACL *oldacl, ACL *newacl, const SID *usid, const SID *gsid, BOOL fordir, le16 inherited); int ntfs_build_permissions(const char *securattr, const SID *usid, const SID *gsid, BOOL isdir); char *ntfs_build_descr(mode_t mode, int isdir, const SID * usid, const SID * gsid); struct MAPLIST *ntfs_read_mapping(FILEREADER reader, void *fileid); struct MAPPING *ntfs_do_user_mapping(struct MAPLIST *firstitem); struct MAPPING *ntfs_do_group_mapping(struct MAPLIST *firstitem); void ntfs_free_mapping(struct MAPPING *mapping[]); #endif /* ACLS_H */ ntfs-3g-2026.2.25/include/ntfs-3g/attrib.h0000664000175000017500000003673115152260173013354 /* * attrib.h - Exports for attribute handling. Originated from the Linux-NTFS project. * * Copyright (c) 2000-2004 Anton Altaparmakov * Copyright (c) 2004-2005 Yura Pakhuchiy * Copyright (c) 2006-2007 Szabolcs Szakacsits * Copyright (c) 2010 Jean-Pierre Andre * * This program/include file 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/include file 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_ATTRIB_H #define _NTFS_ATTRIB_H /* Forward declarations */ typedef struct _ntfs_attr ntfs_attr; typedef struct _ntfs_attr_search_ctx ntfs_attr_search_ctx; #include "types.h" #include "inode.h" #include "unistr.h" #include "runlist.h" #include "volume.h" #include "debug.h" #include "logging.h" extern ntfschar AT_UNNAMED[]; extern ntfschar STREAM_SDS[]; /* The little endian Unicode string $TXF_DATA as a global constant. */ extern ntfschar TXF_DATA[10]; /** * enum ntfs_lcn_special_values - special return values for ntfs_*_vcn_to_lcn() * * Special return values for ntfs_rl_vcn_to_lcn() and ntfs_attr_vcn_to_lcn(). * * TODO: Describe them. */ typedef enum { LCN_HOLE = -1, /* Keep this as highest value or die! */ LCN_RL_NOT_MAPPED = -2, LCN_ENOENT = -3, LCN_EINVAL = -4, LCN_EIO = -5, } ntfs_lcn_special_values; typedef enum { /* ways of processing holes when expanding */ HOLES_NO, HOLES_OK, HOLES_DELAY, HOLES_NONRES } hole_type; /** * struct ntfs_attr_search_ctx - search context used in attribute search functions * @mrec: buffer containing mft record to search * @attr: attribute record in @mrec where to begin/continue search * @is_first: if true lookup_attr() begins search with @attr, else after @attr * * Structure must be initialized to zero before the first call to one of the * attribute search functions. Initialize @mrec to point to the mft record to * search, and @attr to point to the first attribute within @mrec (not necessary * if calling the _first() functions), and set @is_first to TRUE (not necessary * if calling the _first() functions). * * If @is_first is TRUE, the search begins with @attr. If @is_first is FALSE, * the search begins after @attr. This is so that, after the first call to one * of the search attribute functions, we can call the function again, without * any modification of the search context, to automagically get the next * matching attribute. */ struct _ntfs_attr_search_ctx { MFT_RECORD *mrec; ATTR_RECORD *attr; BOOL is_first; ntfs_inode *ntfs_ino; ATTR_LIST_ENTRY *al_entry; ntfs_inode *base_ntfs_ino; MFT_RECORD *base_mrec; ATTR_RECORD *base_attr; }; extern void ntfs_attr_reinit_search_ctx(ntfs_attr_search_ctx *ctx); extern ntfs_attr_search_ctx *ntfs_attr_get_search_ctx(ntfs_inode *ni, MFT_RECORD *mrec); extern void ntfs_attr_put_search_ctx(ntfs_attr_search_ctx *ctx); extern int ntfs_attr_lookup(const ATTR_TYPES type, const ntfschar *name, const u32 name_len, const IGNORE_CASE_BOOL ic, const VCN lowest_vcn, const u8 *val, const u32 val_len, ntfs_attr_search_ctx *ctx); extern int ntfs_attr_position(const ATTR_TYPES type, ntfs_attr_search_ctx *ctx); extern ATTR_DEF *ntfs_attr_find_in_attrdef(const ntfs_volume *vol, const ATTR_TYPES type); /** * ntfs_attrs_walk - syntactic sugar for walking all attributes in an inode * @ctx: initialised attribute search context * * Syntactic sugar for walking attributes in an inode. * * Return 0 on success and -1 on error with errno set to the error code from * ntfs_attr_lookup(). * * Example: When you want to enumerate all attributes in an open ntfs inode * @ni, you can simply do: * * int err; * ntfs_attr_search_ctx *ctx = ntfs_attr_get_search_ctx(ni, NULL); * if (!ctx) * // Error code is in errno. Handle this case. * while (!(err = ntfs_attrs_walk(ctx))) { * ATTR_RECORD *attr = ctx->attr; * // attr now contains the next attribute. Do whatever you want * // with it and then just continue with the while loop. * } * if (err && errno != ENOENT) * // Ooops. An error occurred! You should handle this case. * // Now finished with all attributes in the inode. */ static __inline__ int ntfs_attrs_walk(ntfs_attr_search_ctx *ctx) { return ntfs_attr_lookup(AT_UNUSED, NULL, 0, CASE_SENSITIVE, 0, NULL, 0, ctx); } /** * struct ntfs_attr - ntfs in memory non-resident attribute structure * @rl: if not NULL, the decompressed runlist * @ni: base ntfs inode to which this attribute belongs * @type: attribute type * @name: Unicode name of the attribute * @name_len: length of @name in Unicode characters * @state: NTFS attribute specific flags describing this attribute * @allocated_size: copy from the attribute record * @data_size: copy from the attribute record * @initialized_size: copy from the attribute record * @compressed_size: copy from the attribute record * @compression_block_size: size of a compression block (cb) * @compression_block_size_bits: log2 of the size of a cb * @compression_block_clusters: number of clusters per cb * * This structure exists purely to provide a mechanism of caching the runlist * of an attribute. If you want to operate on a particular attribute extent, * you should not be using this structure at all. If you want to work with a * resident attribute, you should not be using this structure at all. As a * fail-safe check make sure to test NAttrNonResident() and if it is false, you * know you shouldn't be using this structure. * * If you want to work on a resident attribute or on a specific attribute * extent, you should use ntfs_lookup_attr() to retrieve the attribute (extent) * record, edit that, and then write back the mft record (or set the * corresponding ntfs inode dirty for delayed write back). * * @rl is the decompressed runlist of the attribute described by this * structure. Obviously this only makes sense if the attribute is not resident, * i.e. NAttrNonResident() is true. If the runlist hasn't been decompressed yet * @rl is NULL, so be prepared to cope with @rl == NULL. * * @ni is the base ntfs inode of the attribute described by this structure. * * @type is the attribute type (see layout.h for the definition of ATTR_TYPES), * @name and @name_len are the little endian Unicode name and the name length * in Unicode characters of the attribute, respectively. * * @state contains NTFS attribute specific flags describing this attribute * structure. See ntfs_attr_state_bits above. */ struct _ntfs_attr { runlist_element *rl; ntfs_inode *ni; ATTR_TYPES type; ATTR_FLAGS data_flags; ntfschar *name; u32 name_len; unsigned long state; s64 allocated_size; s64 data_size; s64 initialized_size; s64 compressed_size; u32 compression_block_size; u8 compression_block_size_bits; u8 compression_block_clusters; s8 unused_runs; /* pre-reserved entries available */ }; /** * enum ntfs_attr_state_bits - bits for the state field in the ntfs_attr * structure */ typedef enum { NA_Initialized, /* 1: structure is initialized. */ NA_NonResident, /* 1: Attribute is not resident. */ NA_BeingNonResident, /* 1: Attribute is being made not resident. */ NA_FullyMapped, /* 1: Attribute has been fully mapped */ NA_DataAppending, /* 1: Attribute is being appended to */ NA_ComprClosing, /* 1: Compressed attribute is being closed */ NA_RunlistDirty, /* 1: Runlist has been updated */ } ntfs_attr_state_bits; #define test_nattr_flag(na, flag) test_bit(NA_##flag, (na)->state) #define set_nattr_flag(na, flag) set_bit(NA_##flag, (na)->state) #define clear_nattr_flag(na, flag) clear_bit(NA_##flag, (na)->state) #define NAttrInitialized(na) test_nattr_flag(na, Initialized) #define NAttrSetInitialized(na) set_nattr_flag(na, Initialized) #define NAttrClearInitialized(na) clear_nattr_flag(na, Initialized) #define NAttrNonResident(na) test_nattr_flag(na, NonResident) #define NAttrSetNonResident(na) set_nattr_flag(na, NonResident) #define NAttrClearNonResident(na) clear_nattr_flag(na, NonResident) #define NAttrBeingNonResident(na) test_nattr_flag(na, BeingNonResident) #define NAttrSetBeingNonResident(na) set_nattr_flag(na, BeingNonResident) #define NAttrClearBeingNonResident(na) clear_nattr_flag(na, BeingNonResident) #define NAttrFullyMapped(na) test_nattr_flag(na, FullyMapped) #define NAttrSetFullyMapped(na) set_nattr_flag(na, FullyMapped) #define NAttrClearFullyMapped(na) clear_nattr_flag(na, FullyMapped) #define NAttrDataAppending(na) test_nattr_flag(na, DataAppending) #define NAttrSetDataAppending(na) set_nattr_flag(na, DataAppending) #define NAttrClearDataAppending(na) clear_nattr_flag(na, DataAppending) #define NAttrRunlistDirty(na) test_nattr_flag(na, RunlistDirty) #define NAttrSetRunlistDirty(na) set_nattr_flag(na, RunlistDirty) #define NAttrClearRunlistDirty(na) clear_nattr_flag(na, RunlistDirty) #define NAttrComprClosing(na) test_nattr_flag(na, ComprClosing) #define NAttrSetComprClosing(na) set_nattr_flag(na, ComprClosing) #define NAttrClearComprClosing(na) clear_nattr_flag(na, ComprClosing) #define GenNAttrIno(func_name, flag) \ extern int NAttr##func_name(ntfs_attr *na); \ extern void NAttrSet##func_name(ntfs_attr *na); \ extern void NAttrClear##func_name(ntfs_attr *na); GenNAttrIno(Compressed, FILE_ATTR_COMPRESSED) GenNAttrIno(Encrypted, FILE_ATTR_ENCRYPTED) GenNAttrIno(Sparse, FILE_ATTR_SPARSE_FILE) #undef GenNAttrIno /** * union attr_val - Union of all known attribute values * * For convenience. Used in the attr structure. */ typedef union { u8 _default; /* Unnamed u8 to serve as default when just using a_val without specifying any of the below. */ STANDARD_INFORMATION std_inf; ATTR_LIST_ENTRY al_entry; FILE_NAME_ATTR filename; OBJECT_ID_ATTR obj_id; SECURITY_DESCRIPTOR_ATTR sec_desc; VOLUME_NAME vol_name; VOLUME_INFORMATION vol_inf; DATA_ATTR data; INDEX_ROOT index_root; INDEX_BLOCK index_blk; BITMAP_ATTR bmp; REPARSE_POINT reparse; EA_INFORMATION ea_inf; EA_ATTR ea; PROPERTY_SET property_set; LOGGED_UTILITY_STREAM logged_util_stream; EFS_ATTR_HEADER efs; } attr_val; extern void ntfs_attr_init(ntfs_attr *na, const BOOL non_resident, const ATTR_FLAGS data_flags, const BOOL encrypted, const BOOL sparse, const s64 allocated_size, const s64 data_size, const s64 initialized_size, const s64 compressed_size, const u8 compression_unit); /* warning : in the following "name" has to be freeable */ /* or one of constants AT_UNNAMED, NTFS_INDEX_I30 or STREAM_SDS */ extern ntfs_attr *ntfs_attr_open(ntfs_inode *ni, const ATTR_TYPES type, ntfschar *name, u32 name_len); extern void ntfs_attr_close(ntfs_attr *na); extern s64 ntfs_attr_pread(ntfs_attr *na, const s64 pos, s64 count, void *b); extern s64 ntfs_attr_pwrite(ntfs_attr *na, const s64 pos, s64 count, const void *b); extern int ntfs_attr_pclose(ntfs_attr *na); extern void *ntfs_attr_readall(ntfs_inode *ni, const ATTR_TYPES type, ntfschar *name, u32 name_len, s64 *data_size); extern s64 ntfs_attr_mst_pread(ntfs_attr *na, const s64 pos, const s64 bk_cnt, const u32 bk_size, void *dst); extern s64 ntfs_attr_mst_pwrite(ntfs_attr *na, const s64 pos, s64 bk_cnt, const u32 bk_size, void *src); extern int ntfs_attr_map_runlist(ntfs_attr *na, VCN vcn); extern int ntfs_attr_map_whole_runlist(ntfs_attr *na); extern LCN ntfs_attr_vcn_to_lcn(ntfs_attr *na, const VCN vcn); extern runlist_element *ntfs_attr_find_vcn(ntfs_attr *na, const VCN vcn); extern int ntfs_attr_size_bounds_check(const ntfs_volume *vol, const ATTR_TYPES type, const s64 size); extern int ntfs_attr_can_be_resident(const ntfs_volume *vol, const ATTR_TYPES type); int ntfs_attr_make_non_resident(ntfs_attr *na, ntfs_attr_search_ctx *ctx); int ntfs_attr_force_non_resident(ntfs_attr *na); extern int ntfs_make_room_for_attr(MFT_RECORD *m, u8 *pos, u32 size); extern int ntfs_resident_attr_record_add(ntfs_inode *ni, ATTR_TYPES type, const ntfschar *name, u8 name_len, const u8 *val, u32 size, ATTR_FLAGS flags); extern int ntfs_non_resident_attr_record_add(ntfs_inode *ni, ATTR_TYPES type, const ntfschar *name, u8 name_len, VCN lowest_vcn, int dataruns_size, ATTR_FLAGS flags); extern int ntfs_attr_record_rm(ntfs_attr_search_ctx *ctx); extern int ntfs_attr_add(ntfs_inode *ni, ATTR_TYPES type, ntfschar *name, u8 name_len, const u8 *val, s64 size); extern int ntfs_attr_set_flags(ntfs_inode *ni, ATTR_TYPES type, const ntfschar *name, u8 name_len, ATTR_FLAGS flags, ATTR_FLAGS mask); extern int ntfs_attr_rm(ntfs_attr *na); extern int ntfs_attr_record_resize(MFT_RECORD *m, ATTR_RECORD *a, u32 new_size); extern int ntfs_resident_attr_value_resize(MFT_RECORD *m, ATTR_RECORD *a, const u32 new_size); extern int ntfs_attr_record_move_to(ntfs_attr_search_ctx *ctx, ntfs_inode *ni); extern int ntfs_attr_record_move_away(ntfs_attr_search_ctx *ctx, int extra); extern int ntfs_attr_update_mapping_pairs(ntfs_attr *na, VCN from_vcn); extern int ntfs_attr_truncate(ntfs_attr *na, const s64 newsize); extern int ntfs_attr_truncate_solid(ntfs_attr *na, const s64 newsize); /** * get_attribute_value_length - return the length of the value of an attribute * @a: pointer to a buffer containing the attribute record * * Return the byte size of the attribute value of the attribute @a (as it * would be after eventual decompression and filling in of holes if sparse). * If we return 0, check errno. If errno is 0 the actual length was 0, * otherwise errno describes the error. * * FIXME: Describe possible errnos. */ extern s64 ntfs_get_attribute_value_length(const ATTR_RECORD *a); /** * get_attribute_value - return the attribute value of an attribute * @vol: volume on which the attribute is present * @a: attribute to get the value of * @b: destination buffer for the attribute value * * Make a copy of the attribute value of the attribute @a into the destination * buffer @b. Note, that the size of @b has to be at least equal to the value * returned by get_attribute_value_length(@a). * * Return number of bytes copied. If this is zero check errno. If errno is 0 * then nothing was read due to a zero-length attribute value, otherwise * errno describes the error. */ extern s64 ntfs_get_attribute_value(const ntfs_volume *vol, const ATTR_RECORD *a, u8 *b); extern void ntfs_attr_name_free(char **name); extern char *ntfs_attr_name_get(const ntfschar *uname, const int uname_len); extern int ntfs_attr_exist(ntfs_inode *ni, const ATTR_TYPES type, const ntfschar *name, u32 name_len); extern int ntfs_attr_remove(ntfs_inode *ni, const ATTR_TYPES type, ntfschar *name, u32 name_len); extern s64 ntfs_attr_get_free_bits(ntfs_attr *na); extern int ntfs_attr_data_read(ntfs_inode *ni, ntfschar *stream_name, int stream_name_len, char *buf, size_t size, off_t offset); extern int ntfs_attr_data_write(ntfs_inode *ni, ntfschar *stream_name, int stream_name_len, const char *buf, size_t size, off_t offset); extern int ntfs_attr_shrink_size(ntfs_inode *ni, ntfschar *stream_name, int stream_name_len, off_t offset); extern int ntfs_attr_inconsistent(const ATTR_RECORD *a, const MFT_REF mref); #endif /* defined _NTFS_ATTRIB_H */ ntfs-3g-2026.2.25/include/ntfs-3g/runlist.h0000664000175000017500000000630715152260173013563 /* * runlist.h - Exports for runlist handling. Originated from the Linux-NTFS project. * * Copyright (c) 2002 Anton Altaparmakov * Copyright (c) 2002 Richard Russon * * This program/include file 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/include file 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_RUNLIST_H #define _NTFS_RUNLIST_H #include "types.h" /* Forward declarations */ typedef struct _runlist_element runlist_element; typedef runlist_element runlist; #include "attrib.h" #include "volume.h" /** * struct _runlist_element - in memory vcn to lcn mapping array element. * @vcn: starting vcn of the current array element * @lcn: starting lcn of the current array element * @length: length in clusters of the current array element * * The last vcn (in fact the last vcn + 1) is reached when length == 0. * * When lcn == -1 this means that the count vcns starting at vcn are not * physically allocated (i.e. this is a hole / data is sparse). */ struct _runlist_element {/* In memory vcn to lcn mapping structure element. */ VCN vcn; /* vcn = Starting virtual cluster number. */ LCN lcn; /* lcn = Starting logical cluster number. */ s64 length; /* Run length in clusters. */ }; extern runlist_element *ntfs_rl_extend(ntfs_attr *na, runlist_element *rl, int more_entries); extern LCN ntfs_rl_vcn_to_lcn(const runlist_element *rl, const VCN vcn); extern s64 ntfs_rl_pread(const ntfs_volume *vol, const runlist_element *rl, const s64 pos, s64 count, void *b); extern s64 ntfs_rl_pwrite(const ntfs_volume *vol, const runlist_element *rl, s64 ofs, const s64 pos, s64 count, void *b); extern runlist_element *ntfs_runlists_merge(runlist_element *drl, runlist_element *srl); extern runlist_element *ntfs_mapping_pairs_decompress(const ntfs_volume *vol, const ATTR_RECORD *attr, runlist_element *old_rl); extern int ntfs_get_nr_significant_bytes(const s64 n); extern int ntfs_get_size_for_mapping_pairs(const ntfs_volume *vol, const runlist_element *rl, const VCN start_vcn, int max_size); extern int ntfs_write_significant_bytes(u8 *dst, const u8 *dst_max, const s64 n); extern int ntfs_mapping_pairs_build(const ntfs_volume *vol, u8 *dst, const int dst_len, const runlist_element *rl, const VCN start_vcn, runlist_element const **stop_rl); extern int ntfs_rl_truncate(runlist **arl, const VCN start_vcn); extern int ntfs_rl_sparse(runlist *rl); extern s64 ntfs_rl_get_compressed_size(ntfs_volume *vol, runlist *rl); #ifdef NTFS_TEST int test_rl_main(int argc, char *argv[]); #endif #endif /* defined _NTFS_RUNLIST_H */ ntfs-3g-2026.2.25/include/ntfs-3g/unistr.h0000664000175000017500000001171615152260173013407 /* * unistr.h - Exports for Unicode string handling. Originated from the Linux-NTFS * project. * * Copyright (c) 2000-2004 Anton Altaparmakov * * This program/include file 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/include file 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_UNISTR_H #define _NTFS_UNISTR_H #include "types.h" #include "layout.h" extern BOOL ntfs_names_are_equal(const ntfschar *s1, size_t s1_len, const ntfschar *s2, size_t s2_len, const IGNORE_CASE_BOOL ic, const ntfschar *upcase, const u32 upcase_size); extern int ntfs_names_full_collate(const ntfschar *name1, const u32 name1_len, const ntfschar *name2, const u32 name2_len, const IGNORE_CASE_BOOL ic, const ntfschar *upcase, const u32 upcase_len); extern int ntfs_ucsncmp(const ntfschar *s1, const ntfschar *s2, size_t n); extern int ntfs_ucsncasecmp(const ntfschar *s1, const ntfschar *s2, size_t n, const ntfschar *upcase, const u32 upcase_size); extern u32 ntfs_ucsnlen(const ntfschar *s, u32 maxlen); extern ntfschar *ntfs_ucsndup(const ntfschar *s, u32 maxlen); extern void ntfs_name_upcase(ntfschar *name, u32 name_len, const ntfschar *upcase, const u32 upcase_len); extern void ntfs_name_locase(ntfschar *name, u32 name_len, const ntfschar *locase, const u32 locase_len); extern void ntfs_file_value_upcase(FILE_NAME_ATTR *file_name_attr, const ntfschar *upcase, const u32 upcase_len); extern int ntfs_ucstombs(const ntfschar *ins, const int ins_len, char **outs, int outs_len); extern int ntfs_mbstoucs(const char *ins, ntfschar **outs); extern char *ntfs_uppercase_mbs(const char *low, const ntfschar *upcase, u32 upcase_len); extern void ntfs_upcase_table_build(ntfschar *uc, u32 uc_len); extern u32 ntfs_upcase_build_default(ntfschar **upcase); extern ntfschar *ntfs_locase_table_build(const ntfschar *uc, u32 uc_cnt); extern ntfschar *ntfs_str2ucs(const char *s, int *len); extern void ntfs_ucsfree(ntfschar *ucs); extern BOOL ntfs_forbidden_chars(const ntfschar *name, int len, BOOL strict); extern BOOL ntfs_forbidden_names(ntfs_volume *vol, const ntfschar *name, int len, BOOL strict); extern BOOL ntfs_collapsible_chars(ntfs_volume *vol, const ntfschar *shortname, int shortlen, const ntfschar *longname, int longlen); extern int ntfs_set_char_encoding(const char *locale); #if defined(__APPLE__) || defined(__DARWIN__) /** * Mac OS X only. * * Sets file name Unicode normalization form conversion on or off. * normalize=0 : Off * normalize=1 : On * If set to on, all filenames returned by ntfs-3g will be converted to the NFD * normalization form, while all filenames recieved by ntfs-3g will be converted to the NFC * normalization form. Since Windows and most other OS:es use the NFC form while Mac OS X * mostly uses NFD, this conversion increases compatibility between Mac applications and * NTFS-3G. * * @param normalize decides whether or not the string functions will do automatic filename * normalization when converting to and from UTF-8. 0 means normalization is disabled, * 1 means it is enabled. * @return -1 if the argument was invalid or an error occurred, 0 if all went well. */ extern int ntfs_macosx_normalize_filenames(int normalize); /** * Mac OS X only. * * Normalizes the input string "utf8_string" to one of the normalization forms NFD or NFC. * The parameter "composed" decides whether output should be in composed, NFC, form * (composed == 1) or decomposed, NFD, form (composed == 0). * Input is assumed to be properly UTF-8 encoded and null-terminated. Output will be a newly * ntfs_calloc'ed string encoded in UTF-8. It is the callers responsibility to free(...) the * allocated string when it's no longer needed. * * @param utf8_string the input string, which may be in any normalization form. * @param target a pointer where the resulting string will be stored. * @param composed decides which composition form to normalize the input string to. 0 means * composed form (NFC), 1 means decomposed form (NFD). * @return -1 if the normalization failed for some reason, otherwise the length of the * normalized string stored in target. */ extern int ntfs_macosx_normalize_utf8(const char *utf8_string, char **target, int composed); #endif /* defined(__APPLE__) || defined(__DARWIN__) */ #endif /* defined _NTFS_UNISTR_H */ ntfs-3g-2026.2.25/include/ntfs-3g/device_io.h0000664000175000017500000000464115152260173014010 /* * device_io.h - Exports for default device io. Originated from the Linux-NTFS project. * * Copyright (c) 2000-2006 Anton Altaparmakov * * This program/include file 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/include file 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_DEVICE_IO_H #define _NTFS_DEVICE_IO_H #ifdef HAVE_CONFIG_H #include "config.h" #endif #ifndef NO_NTFS_DEVICE_DEFAULT_IO_OPS #if defined(linux) || defined(__uClinux__) || defined(__sun) \ || defined(__APPLE__) || defined(__DARWIN__) /* Make sure the presence of means compiling for Windows */ #undef HAVE_WINDOWS_H #endif #ifndef HAVE_WINDOWS_H /* Not for Windows use standard Unix style low level device operations. */ #define ntfs_device_default_io_ops ntfs_device_unix_io_ops #else /* HAVE_WINDOWS_H */ #ifndef HDIO_GETGEO # define HDIO_GETGEO 0x301 /** * struct hd_geometry - */ struct hd_geometry { unsigned char heads; unsigned char sectors; unsigned short cylinders; unsigned long start; }; #endif #ifndef BLKGETSIZE # define BLKGETSIZE 0x1260 #endif #ifndef BLKSSZGET # define BLKSSZGET 0x1268 #endif #ifndef BLKGETSIZE64 # define BLKGETSIZE64 0x80041272 #endif #ifndef BLKBSZSET # define BLKBSZSET 0x40041271 #endif /* On Windows (and Cygwin) : use Win32 low level device operations. */ #define ntfs_device_default_io_ops ntfs_device_win32_io_ops /* A few useful functions */ int ntfs_win32_set_sparse(int); int ntfs_win32_ftruncate(int fd, s64 size); int ntfs_device_win32_ftruncate(struct ntfs_device*, s64); #endif /* HAVE_WINDOWS_H */ /* Forward declaration. */ struct ntfs_device_operations; extern struct ntfs_device_operations ntfs_device_default_io_ops; #endif /* NO_NTFS_DEVICE_DEFAULT_IO_OPS */ #endif /* defined _NTFS_DEVICE_IO_H */ ntfs-3g-2026.2.25/include/ntfs-3g/device.h0000664000175000017500000001265715152260173013327 /* * device.h - Exports for low level device io. Originated from the Linux-NTFS project. * * Copyright (c) 2000-2013 Anton Altaparmakov * Copyright (c) 2008-2013 Tuxera Inc. * * This program/include file 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/include file 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_DEVICE_H #define _NTFS_DEVICE_H #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "device_io.h" #include "types.h" #include "support.h" #include "volume.h" /** * enum ntfs_device_state_bits - * * Defined bits for the state field in the ntfs_device structure. */ typedef enum { ND_Open, /* 1: Device is open. */ ND_ReadOnly, /* 1: Device is read-only. */ ND_Dirty, /* 1: Device is dirty, needs sync. */ ND_Block, /* 1: Device is a block device. */ ND_Sync, /* 1: Device is mounted with "-o sync" */ } ntfs_device_state_bits; #define test_ndev_flag(nd, flag) test_bit(ND_##flag, (nd)->d_state) #define set_ndev_flag(nd, flag) set_bit(ND_##flag, (nd)->d_state) #define clear_ndev_flag(nd, flag) clear_bit(ND_##flag, (nd)->d_state) #define NDevOpen(nd) test_ndev_flag(nd, Open) #define NDevSetOpen(nd) set_ndev_flag(nd, Open) #define NDevClearOpen(nd) clear_ndev_flag(nd, Open) #define NDevReadOnly(nd) test_ndev_flag(nd, ReadOnly) #define NDevSetReadOnly(nd) set_ndev_flag(nd, ReadOnly) #define NDevClearReadOnly(nd) clear_ndev_flag(nd, ReadOnly) #define NDevDirty(nd) test_ndev_flag(nd, Dirty) #define NDevSetDirty(nd) set_ndev_flag(nd, Dirty) #define NDevClearDirty(nd) clear_ndev_flag(nd, Dirty) #define NDevBlock(nd) test_ndev_flag(nd, Block) #define NDevSetBlock(nd) set_ndev_flag(nd, Block) #define NDevClearBlock(nd) clear_ndev_flag(nd, Block) #define NDevSync(nd) test_ndev_flag(nd, Sync) #define NDevSetSync(nd) set_ndev_flag(nd, Sync) #define NDevClearSync(nd) clear_ndev_flag(nd, Sync) /** * struct ntfs_device - * * The ntfs device structure defining all operations needed to access the low * level device underlying the ntfs volume. * * Note d_heads and d_sectors_per_track are only set as a result of a call to * either ntfs_device_heads_get() or ntfs_device_sectors_per_track_get() (both * calls will set up both fields or if getting them failed they will be left at * -1). */ struct ntfs_device { struct ntfs_device_operations *d_ops; /* Device operations. */ unsigned long d_state; /* State of the device. */ char *d_name; /* Name of device. */ void *d_private; /* Private data used by the device operations. */ int d_heads; /* Disk geometry: number of heads or -1. */ int d_sectors_per_track; /* Disk geometry: number of sectors per track or -1. */ }; struct stat; /** * struct ntfs_device_operations - * * The ntfs device operations defining all operations that can be performed on * the low level device described by an ntfs device structure. */ struct ntfs_device_operations { int (*open)(struct ntfs_device *dev, int flags); int (*close)(struct ntfs_device *dev); s64 (*seek)(struct ntfs_device *dev, s64 offset, int whence); s64 (*read)(struct ntfs_device *dev, void *buf, s64 count); s64 (*write)(struct ntfs_device *dev, const void *buf, s64 count); s64 (*pread)(struct ntfs_device *dev, void *buf, s64 count, s64 offset); s64 (*pwrite)(struct ntfs_device *dev, const void *buf, s64 count, s64 offset); int (*sync)(struct ntfs_device *dev); int (*stat)(struct ntfs_device *dev, struct stat *buf); int (*ioctl)(struct ntfs_device *dev, unsigned long request, void *argp); }; extern struct ntfs_device *ntfs_device_alloc(const char *name, const long state, struct ntfs_device_operations *dops, void *priv_data); extern int ntfs_device_free(struct ntfs_device *dev); extern int ntfs_device_sync(struct ntfs_device *dev); extern s64 ntfs_pread(struct ntfs_device *dev, const s64 pos, s64 count, void *b); extern s64 ntfs_pwrite(struct ntfs_device *dev, const s64 pos, s64 count, const void *b); extern s64 ntfs_mst_pread(struct ntfs_device *dev, const s64 pos, s64 count, const u32 bksize, void *b); extern s64 ntfs_mst_pwrite(struct ntfs_device *dev, const s64 pos, s64 count, const u32 bksize, void *b); extern s64 ntfs_cluster_read(const ntfs_volume *vol, const s64 lcn, const s64 count, void *b); extern s64 ntfs_cluster_write(const ntfs_volume *vol, const s64 lcn, const s64 count, const void *b); extern s64 ntfs_device_size_get(struct ntfs_device *dev, int block_size); extern s64 ntfs_device_partition_start_sector_get(struct ntfs_device *dev); extern int ntfs_device_heads_get(struct ntfs_device *dev); extern int ntfs_device_sectors_per_track_get(struct ntfs_device *dev); extern int ntfs_device_sector_size_get(struct ntfs_device *dev); extern int ntfs_device_block_size_set(struct ntfs_device *dev, int block_size); #endif /* defined _NTFS_DEVICE_H */ ntfs-3g-2026.2.25/include/ntfs-3g/logfile.h0000664000175000017500000004362715152260173013512 /* * logfile.h - Exports for $LogFile handling. Originated from the Linux-NTFS project. * * Copyright (c) 2000-2005 Anton Altaparmakov * Copyright (c) 2016 Jean-Pierre Andre * * This program/include file 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/include file 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_LOGFILE_H #define _NTFS_LOGFILE_H #include "types.h" #include "endians.h" #include "layout.h" /* * Journal ($LogFile) organization: * * Two restart areas present in the first two pages (restart pages, one restart * area in each page). When the volume is dismounted they should be identical, * except for the update sequence array which usually has a different update * sequence number. * * These are followed by log records organized in pages headed by a log record * header going up to log file size. Not all pages contain log records when a * volume is first formatted, but as the volume ages, all records will be used. * When the log file fills up, the records at the beginning are purged (by * modifying the oldest_lsn to a higher value presumably) and writing begins * at the beginning of the file. Effectively, the log file is viewed as a * circular entity. * * NOTE: Windows NT, 2000, and XP all use log file version 1.1 but they accept * versions <= 1.x, including 0.-1. (Yes, that is a minus one in there!) We * probably only want to support 1.1 as this seems to be the current version * and we don't know how that differs from the older versions. The only * exception is if the journal is clean as marked by the two restart pages * then it doesn't matter whether we are on an earlier version. We can just * reinitialize the logfile and start again with version 1.1. */ /* Some $LogFile related constants. */ #define MaxLogFileSize 0x100000000ULL #define DefaultLogPageSize 4096 #define MinLogRecordPages 48 /** * struct RESTART_PAGE_HEADER - Log file restart page header. * * Begins the restart area. */ typedef struct { /*Ofs*/ /* 0 NTFS_RECORD; -- Unfolded here as gcc doesn't like unnamed structs. */ /* 0*/ NTFS_RECORD_TYPES magic;/* The magic is "RSTR". */ /* 4*/ le16 usa_ofs; /* See NTFS_RECORD definition in layout.h. When creating, set this to be immediately after this header structure (without any alignment). */ /* 6*/ le16 usa_count; /* See NTFS_RECORD definition in layout.h. */ /* 8*/ leLSN chkdsk_lsn; /* The last log file sequence number found by chkdsk. Only used when the magic is changed to "CHKD". Otherwise this is zero. */ /* 16*/ le32 system_page_size; /* Byte size of system pages when the log file was created, has to be >= 512 and a power of 2. Use this to calculate the required size of the usa (usa_count) and add it to usa_ofs. Then verify that the result is less than the value of the restart_area_offset. */ /* 20*/ le32 log_page_size; /* Byte size of log file pages, has to be >= 512 and a power of 2. The default is 4096 and is used when the system page size is between 4096 and 8192. Otherwise this is set to the system page size instead. */ /* 24*/ le16 restart_area_offset;/* Byte offset from the start of this header to the RESTART_AREA. Value has to be aligned to 8-byte boundary. When creating, set this to be after the usa. */ /* 26*/ sle16 minor_ver; /* Log file minor version. Only check if major version is 1. */ /* 28*/ sle16 major_ver; /* Log file major version. We only support version 1.1. */ /* 30*/ le16 usn; /* sizeof() = 32 (0x20) bytes */ } __attribute__((__packed__)) RESTART_PAGE_HEADER; /* * Constant for the log client indices meaning that there are no client records * in this particular client array. Also inside the client records themselves, * this means that there are no client records preceding or following this one. */ #define LOGFILE_NO_CLIENT_CPU 0xffff #define LOGFILE_NO_CLIENT const_cpu_to_le16(LOGFILE_NO_CLIENT_CPU) /* * These are the so far known RESTART_AREA_* flags (16-bit) which contain * information about the log file in which they are present. */ enum { RESTART_VOLUME_IS_CLEAN = const_cpu_to_le16(0x0002), RESTART_SPACE_FILLER = 0xffff, /* gcc: Force enum bit width to 16. */ } __attribute__((__packed__)); typedef le16 RESTART_AREA_FLAGS; /** * struct RESTART_AREA - Log file restart area record. * * The offset of this record is found by adding the offset of the * RESTART_PAGE_HEADER to the restart_area_offset value found in it. * See notes at restart_area_offset above. */ typedef struct { /*Ofs*/ /* 0*/ leLSN current_lsn; /* The current, i.e. last LSN inside the log when the restart area was last written. This happens often but what is the interval? Is it just fixed time or is it every time a check point is written or something else? On create set to 0. */ /* 8*/ le16 log_clients; /* Number of log client records in the array of log client records which follows this restart area. Must be 1. */ /* 10*/ le16 client_free_list; /* The index of the first free log client record in the array of log client records. LOGFILE_NO_CLIENT means that there are no free log client records in the array. If != LOGFILE_NO_CLIENT, check that log_clients > client_free_list. On Win2k and presumably earlier, on a clean volume this is != LOGFILE_NO_CLIENT, and it should be 0, i.e. the first (and only) client record is free and thus the logfile is closed and hence clean. A dirty volume would have left the logfile open and hence this would be LOGFILE_NO_CLIENT. On WinXP and presumably later, the logfile is always open, even on clean shutdown so this should always be LOGFILE_NO_CLIENT. */ /* 12*/ le16 client_in_use_list;/* The index of the first in-use log client record in the array of log client records. LOGFILE_NO_CLIENT means that there are no in-use log client records in the array. If != LOGFILE_NO_CLIENT check that log_clients > client_in_use_list. On Win2k and presumably earlier, on a clean volume this is LOGFILE_NO_CLIENT, i.e. there are no client records in use and thus the logfile is closed and hence clean. A dirty volume would have left the logfile open and hence this would be != LOGFILE_NO_CLIENT, and it should be 0, i.e. the first (and only) client record is in use. On WinXP and presumably later, the logfile is always open, even on clean shutdown so this should always be 0. */ /* 14*/ RESTART_AREA_FLAGS flags;/* Flags modifying LFS behaviour. On Win2k and presumably earlier this is always 0. On WinXP and presumably later, if the logfile was shutdown cleanly, the second bit, RESTART_VOLUME_IS_CLEAN, is set. This bit is cleared when the volume is mounted by WinXP and set when the volume is dismounted, thus if the logfile is dirty, this bit is clear. Thus we don't need to check the Windows version to determine if the logfile is clean. Instead if the logfile is closed, we know it must be clean. If it is open and this bit is set, we also know it must be clean. If on the other hand the logfile is open and this bit is clear, we can be almost certain that the logfile is dirty. */ /* 16*/ le32 seq_number_bits; /* How many bits to use for the sequence number. This is calculated as 67 - the number of bits required to store the logfile size in bytes and this can be used in with the specified file_size as a consistency check. */ /* 20*/ le16 restart_area_length;/* Length of the restart area including the client array. Following checks required if version matches. Otherwise, skip them. restart_area_offset + restart_area_length has to be <= system_page_size. Also, restart_area_length has to be >= client_array_offset + (log_clients * sizeof(log client record)). */ /* 22*/ le16 client_array_offset;/* Offset from the start of this record to the first log client record if versions are matched. When creating, set this to be after this restart area structure, aligned to 8-bytes boundary. If the versions do not match, this is ignored and the offset is assumed to be (sizeof(RESTART_AREA) + 7) & ~7, i.e. rounded up to first 8-byte boundary. Either way, client_array_offset has to be aligned to an 8-byte boundary. Also, restart_area_offset + client_array_offset has to be <= 510. Finally, client_array_offset + (log_clients * sizeof(log client record)) has to be <= system_page_size. On Win2k and presumably earlier, this is 0x30, i.e. immediately following this record. On WinXP and presumably later, this is 0x40, i.e. there are 16 extra bytes between this record and the client array. This probably means that the RESTART_AREA record is actually bigger in WinXP and later. */ /* 24*/ sle64 file_size; /* Usable byte size of the log file. If the restart_area_offset + the offset of the file_size are > 510 then corruption has occurred. This is the very first check when starting with the restart_area as if it fails it means that some of the above values will be corrupted by the multi sector transfer protection. The file_size has to be rounded down to be a multiple of the log_page_size in the RESTART_PAGE_HEADER and then it has to be at least big enough to store the two restart pages and 48 (0x30) log record pages. */ /* 32*/ le32 last_lsn_data_length;/* Length of data of last LSN, not including the log record header. On create set to 0. */ /* 36*/ le16 log_record_header_length;/* Byte size of the log record header. If the version matches then check that the value of log_record_header_length is a multiple of 8, i.e. (log_record_header_length + 7) & ~7 == log_record_header_length. When creating set it to sizeof(LOG_RECORD_HEADER), aligned to 8 bytes. */ /* 38*/ le16 log_page_data_offset;/* Offset to the start of data in a log record page. Must be a multiple of 8. On create set it to immediately after the update sequence array of the log record page. */ /* 40*/ le32 restart_log_open_count;/* A counter that gets incremented every time the logfile is restarted which happens at mount time when the logfile is opened. When creating set to a random value. Win2k sets it to the low 32 bits of the current system time in NTFS format (see time.h). */ /* 44*/ le32 reserved; /* Reserved/alignment to 8-byte boundary. */ /* sizeof() = 48 (0x30) bytes */ } __attribute__((__packed__)) RESTART_AREA; /** * struct LOG_CLIENT_RECORD - Log client record. * * The offset of this record is found by adding the offset of the * RESTART_AREA to the client_array_offset value found in it. */ typedef struct { /*Ofs*/ /* 0*/ leLSN oldest_lsn; /* Oldest LSN needed by this client. On create set to 0. */ /* 8*/ leLSN client_restart_lsn;/* LSN at which this client needs to restart the volume, i.e. the current position within the log file. At present, if clean this should = current_lsn in restart area but it probably also = current_lsn when dirty most of the time. At create set to 0. */ /* 16*/ le16 prev_client; /* The offset to the previous log client record in the array of log client records. LOGFILE_NO_CLIENT means there is no previous client record, i.e. this is the first one. This is always LOGFILE_NO_CLIENT. */ /* 18*/ le16 next_client; /* The offset to the next log client record in the array of log client records. LOGFILE_NO_CLIENT means there are no next client records, i.e. this is the last one. This is always LOGFILE_NO_CLIENT. */ /* 20*/ le16 seq_number; /* On Win2k and presumably earlier, this is set to zero every time the logfile is restarted and it is incremented when the logfile is closed at dismount time. Thus it is 0 when dirty and 1 when clean. On WinXP and presumably later, this is always 0. */ /* 22*/ u8 reserved[6]; /* Reserved/alignment. */ /* 28*/ le32 client_name_length;/* Length of client name in bytes. Should always be 8. */ /* 32*/ ntfschar client_name[64];/* Name of the client in Unicode. Should always be "NTFS" with the remaining bytes set to 0. */ /* sizeof() = 160 (0xa0) bytes */ } __attribute__((__packed__)) LOG_CLIENT_RECORD; /** * struct RECORD_PAGE_HEADER - Log page record page header. * * Each log page begins with this header and is followed by several LOG_RECORD * structures, starting at offset 0x40 (the size of this structure and the * following update sequence array and then aligned to 8 byte boundary, but is * this specified anywhere?). */ typedef struct { /* 0 NTFS_RECORD; -- Unfolded here as gcc doesn't like unnamed structs. */ NTFS_RECORD_TYPES magic;/* Usually the magic is "RCRD". */ le16 usa_ofs; /* See NTFS_RECORD definition in layout.h. When creating, set this to be immediately after this header structure (without any alignment). */ le16 usa_count; /* See NTFS_RECORD definition in layout.h. */ union { leLSN last_lsn; sle64 file_offset; } __attribute__((__packed__)) copy; le32 flags; le16 page_count; le16 page_position; le16 next_record_offset; le16 reserved[3]; leLSN last_end_lsn; } __attribute__((__packed__)) RECORD_PAGE_HEADER; /** * enum LOG_RECORD_FLAGS - Possible 16-bit flags for log records. * * Some flags describe what kind of update is being logged. * * (Or is it log record pages?) */ typedef enum { LOG_RECORD_MULTI_PAGE = const_cpu_to_le16(0x0001), /* ??? */ /* The flags below were introduced in Windows 10 */ LOG_RECORD_DELETING = const_cpu_to_le16(0x0002), LOG_RECORD_ADDING = const_cpu_to_le16(0x0004), LOG_RECORD_SIZE_PLACE_HOLDER = 0xffff, /* This has nothing to do with the log record. It is only so gcc knows to make the flags 16-bit. */ } __attribute__((__packed__)) LOG_RECORD_FLAGS; /** * struct LOG_CLIENT_ID - The log client id structure identifying a log client. */ typedef struct { le16 seq_number; le16 client_index; } __attribute__((__packed__)) LOG_CLIENT_ID; /* * LOG_RECORD_TYPE : types of log records */ enum { LOG_STANDARD = const_cpu_to_le32(1), LOG_CHECKPOINT = const_cpu_to_le32(2), LOG_RECORD_TYPE_PLACE_HOLDER = 0xffffffffU } ; typedef le32 LOG_RECORD_TYPE; /* * ATTRIBUTE_FLAGS : flags describing the kind of NTFS record * is being updated. * These flags were introduced in Vista, only two flags are known? */ enum { ACTS_ON_MFT = const_cpu_to_le16(2), ACTS_ON_INDX = const_cpu_to_le16(8), ATTRIBUTE_FLAGS_PLACE_HOLDER = 0xffff, } ; typedef le16 ATTRIBUTE_FLAGS; #define LOG_RECORD_HEAD_SZ 0x30 /* size of header of struct LOG_RECORD */ /** * struct LOG_RECORD - Log record header. * * Each log record seems to have a constant size of 0x70 bytes. */ typedef struct { leLSN this_lsn; leLSN client_previous_lsn; leLSN client_undo_next_lsn; le32 client_data_length; LOG_CLIENT_ID client_id; LOG_RECORD_TYPE record_type; le32 transaction_id; LOG_RECORD_FLAGS log_record_flags; le16 reserved_or_alignment[3]; /* Now are at ofs 0x30 into struct. */ le16 redo_operation; le16 undo_operation; le16 redo_offset; le16 redo_length; union { struct { le16 undo_offset; le16 undo_length; le16 target_attribute; le16 lcns_to_follow; /* Number of lcn_list entries following this entry. */ /* Now at ofs 0x40. */ le16 record_offset; le16 attribute_offset; le16 cluster_index; ATTRIBUTE_FLAGS attribute_flags; leVCN target_vcn; /* Now at ofs 0x50. */ leLCN lcn_list[0]; /* Only present if lcns_to_follow is not 0. */ } __attribute__((__packed__)); struct { leLSN transaction_lsn; leLSN attributes_lsn; leLSN names_lsn; leLSN dirty_pages_lsn; le64 unknown_list[0]; } __attribute__((__packed__)); } __attribute__((__packed__)); } __attribute__((__packed__)) LOG_RECORD; /** * struct BITMAP_ACTION - Bitmap change being logged */ struct BITMAP_ACTION { le32 firstbit; le32 count; } ; /** * struct ATTR - Attribute record. * * The format of an attribute record has changed from Windows 10. * The old format was 44 bytes long, despite having 8 bytes fields, * and this leads to alignment problems in arrays. * This problem does not occur in the new format, which is shorter. * The format being used can generally be determined from size. */ typedef struct { /* Format up to Win10 (44 bytes) */ le64 unknown1; le64 unknown2; le64 inode; leLSN lsn; le32 unknown3; le32 type; le32 unknown4; } __attribute__((__packed__)) ATTR_OLD; typedef struct { /* Format since Win10 (40 bytes) */ le64 unknown1; le64 unknown2; le32 type; le32 unknown3; le64 inode; leLSN lsn; } __attribute__((__packed__)) ATTR_NEW; extern BOOL ntfs_check_logfile(ntfs_attr *log_na, RESTART_PAGE_HEADER **rp); extern BOOL ntfs_is_logfile_clean(ntfs_attr *log_na, RESTART_PAGE_HEADER *rp); extern int ntfs_empty_logfile(ntfs_attr *na); #endif /* defined _NTFS_LOGFILE_H */ ntfs-3g-2026.2.25/include/ntfs-3g/ioctl.h0000664000175000017500000000232715152260173013173 /* * * Copyright (c) 2014 Jean-Pierre Andre * */ /* * 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 IOCTL_H #define IOCTL_H /* * Using an "unsigned long cmd" internally, like in for Linux * Note however that fuse truncates the arg to 32 bits, and that * some commands (e.g. FITRIM) do not fit in a signed 32 bit field. */ int ntfs_ioctl(ntfs_inode *ni, unsigned long cmd, void *arg, unsigned int flags, void *data); #endif /* IOCTL_H */ ntfs-3g-2026.2.25/include/ntfs-3g/types.h0000664000175000017500000000625515152260173013231 /* * types.h - Misc type definitions not related to on-disk structure. * Originated from the Linux-NTFS project. * * Copyright (c) 2000-2004 Anton Altaparmakov * * This program/include file 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/include file 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_TYPES_H #define _NTFS_TYPES_H #ifdef HAVE_CONFIG_H #include "config.h" #endif #if HAVE_STDINT_H || !HAVE_CONFIG_H #include #endif #ifdef HAVE_SYS_TYPES_H #include #endif typedef uint8_t u8; /* Unsigned types of an exact size */ typedef uint16_t u16; typedef uint32_t u32; typedef uint64_t u64; typedef int8_t s8; /* Signed types of an exact size */ typedef int16_t s16; typedef int32_t s32; typedef int64_t s64; typedef u16 le16; typedef u32 le32; typedef u64 le64; typedef u16 be16; typedef u32 be32; typedef u64 be64; /* * Declare s{l,b}e{16,32,64} to be unsigned because we do not want sign * extension on BE architectures. */ typedef u16 sle16; typedef u32 sle32; typedef u64 sle64; typedef u16 sbe16; typedef u32 sbe32; typedef u64 sbe64; typedef le16 ntfschar; /* 2-byte Unicode character type. */ #define UCHAR_T_SIZE_BITS 1 /* * Clusters are signed 64-bit values on NTFS volumes. We define two types, LCN * and VCN, to allow for type checking and better code readability. */ typedef s64 VCN; typedef sle64 leVCN; typedef s64 LCN; typedef sle64 leLCN; /* * The NTFS journal $LogFile uses log sequence numbers which are signed 64-bit * values. We define our own type LSN, to allow for type checking and better * code readability. */ typedef s64 LSN; typedef sle64 leLSN; /* * Cygwin has a collision between our BOOL and 's * As long as this file will be included after were fine. */ #ifndef _WINDEF_H /** * enum BOOL - These are just to make the code more readable... */ typedef enum { #ifndef FALSE FALSE = 0, #endif #ifndef NO NO = 0, #endif #ifndef ZERO ZERO = 0, #endif #ifndef TRUE TRUE = 1, #endif #ifndef YES YES = 1, #endif #ifndef ONE ONE = 1, #endif } BOOL; #endif /* defined _WINDEF_H */ /** * enum IGNORE_CASE_BOOL - */ typedef enum { CASE_SENSITIVE = 0, IGNORE_CASE = 1, } IGNORE_CASE_BOOL; #define STATUS_OK (0) #define STATUS_ERROR (-1) #define STATUS_RESIDENT_ATTRIBUTE_FILLED_MFT (-2) #define STATUS_KEEP_SEARCHING (-3) #define STATUS_NOT_FOUND (-4) /* * Force alignment in a struct if required by processor */ union ALIGNMENT { u64 u64align; void *ptralign; } ; #endif /* defined _NTFS_TYPES_H */ ntfs-3g-2026.2.25/include/ntfs-3g/collate.h0000664000175000017500000000231015152260173013474 /* * collate.h - Defines for NTFS collation handling. Originated from the Linux-NTFS * project. * * Copyright (c) 2004 Anton Altaparmakov * Copyright (c) 2005 Yura Pakhuchiy * * This program/include file 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/include file 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_COLLATE_H #define _NTFS_COLLATE_H #include "types.h" #include "volume.h" #define NTFS_COLLATION_ERROR -2 extern COLLATE ntfs_get_collate_function(COLLATION_RULES); #endif /* _NTFS_COLLATE_H */ ntfs-3g-2026.2.25/include/ntfs-3g/xattrs.h0000664000175000017500000000600215152260173013400 /* * xattrs.h : definitions related to system extended attributes * * Copyright (c) 2010 Jean-Pierre Andre * * This program/include file 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/include file 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_XATTRS_H_ #define _NTFS_XATTRS_H_ /* * Flags that modify setxattr() semantics. These flags are also used by a * number of libntfs-3g functions, such as ntfs_set_ntfs_acl(), which were * originally tied to extended attributes support but now can be used by * applications even if the platform does not support extended attributes. * * Careful: applications including this header should define HAVE_SETXATTR or * HAVE_SYS_XATTR_H if the platform supports extended attributes. Otherwise the * defined flags values may be incorrect (they will be correct for Linux but not * necessarily for other platforms). */ #if defined(HAVE_SETXATTR) || defined(HAVE_SYS_XATTR_H) #include #else #include "compat.h" /* may be needed for ENODATA definition */ #define XATTR_CREATE 1 #define XATTR_REPLACE 2 #endif /* * Identification of data mapped to the system name space */ enum SYSTEMXATTRS { XATTR_UNMAPPED, XATTR_NTFS_ACL, XATTR_NTFS_ATTRIB, XATTR_NTFS_ATTRIB_BE, XATTR_NTFS_EFSINFO, XATTR_NTFS_REPARSE_DATA, XATTR_NTFS_OBJECT_ID, XATTR_NTFS_DOS_NAME, XATTR_NTFS_TIMES, XATTR_NTFS_TIMES_BE, XATTR_NTFS_CRTIME, XATTR_NTFS_CRTIME_BE, XATTR_NTFS_EA, XATTR_POSIX_ACC, XATTR_POSIX_DEF } ; struct XATTRMAPPING { struct XATTRMAPPING *next; enum SYSTEMXATTRS xattr; char name[1]; /* variable length */ } ; #ifdef XATTR_MAPPINGS struct XATTRMAPPING *ntfs_xattr_build_mapping(ntfs_volume *vol, const char *path); void ntfs_xattr_free_mapping(struct XATTRMAPPING*); #endif /* XATTR_MAPPINGS */ enum SYSTEMXATTRS ntfs_xattr_system_type(const char *name, ntfs_volume *vol); struct SECURITY_CONTEXT; int ntfs_xattr_system_getxattr(struct SECURITY_CONTEXT *scx, enum SYSTEMXATTRS attr, ntfs_inode *ni, ntfs_inode *dir_ni, char *value, size_t size); int ntfs_xattr_system_setxattr(struct SECURITY_CONTEXT *scx, enum SYSTEMXATTRS attr, ntfs_inode *ni, ntfs_inode *dir_ni, const char *value, size_t size, int flags); int ntfs_xattr_system_removexattr(struct SECURITY_CONTEXT *scx, enum SYSTEMXATTRS attr, ntfs_inode *ni, ntfs_inode *dir_ni); #endif /* _NTFS_XATTRS_H_ */ ntfs-3g-2026.2.25/include/ntfs-3g/misc.h0000664000175000017500000000215615152260173013014 /* * misc.h : miscellaneous exports * - memory allocation * * Copyright (c) 2008 Jean-Pierre Andre * * This program/include file 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/include file 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_MISC_H_ #define _NTFS_MISC_H_ void *ntfs_calloc(size_t size); void *ntfs_malloc(size_t size); void *ntfs_realloc(void *ptr, size_t size); void ntfs_free(void *ptr); #endif /* _NTFS_MISC_H_ */ ntfs-3g-2026.2.25/include/ntfs-3g/support.h0000664000175000017500000000433415152260173013575 /* * support.h - Useful definitions and macros. Originated from the Linux-NTFS project. * * Copyright (c) 2000-2004 Anton Altaparmakov * * This program/include file 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/include file 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_SUPPORT_H #define _NTFS_SUPPORT_H #ifdef HAVE_CONFIG_H #include "config.h" #endif #ifdef HAVE_STDDEF_H #include #endif /* * Our mailing list. Use this define to prevent typos in email address. */ #define NTFS_DEV_LIST "ntfs-3g-devel@lists.sf.net" /* * Generic macro to convert pointers to values for comparison purposes. */ #ifndef p2n #define p2n(p) ((ptrdiff_t)((ptrdiff_t*)(p))) #endif /* * The classic min and max macros. */ #ifndef min #define min(a,b) ((a) <= (b) ? (a) : (b)) #endif #ifndef max #define max(a,b) ((a) >= (b) ? (a) : (b)) #endif /* * Useful macro for determining the offset of a struct member. */ #ifndef offsetof #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) #endif /* * Simple bit operation macros. NOTE: These are NOT atomic. */ #define test_bit(bit, var) ((var) & (1 << (bit))) #define set_bit(bit, var) (var) |= 1 << (bit) #define clear_bit(bit, var) (var) &= ~(1 << (bit)) #define test_and_set_bit(bit, var) \ ({ \ const BOOL old_state = test_bit(bit, var); \ set_bit(bit, var); \ old_state; \ }) #define test_and_clear_bit(bit, var) \ ({ \ const BOOL old_state = test_bit(bit, var); \ clear_bit(bit, var); \ old_state; \ }) #endif /* defined _NTFS_SUPPORT_H */ ntfs-3g-2026.2.25/include/ntfs-3g/efs.h0000664000175000017500000000215515152260173012635 /* * * Copyright (c) 2009 Martin Bene * * This program/include file 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/include file 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 EFS_H #define EFS_H int ntfs_get_efs_info(ntfs_inode *ni, char *value, size_t size); int ntfs_set_efs_info(ntfs_inode *ni, const char *value, size_t size, int flags); int ntfs_efs_fixup_attribute(ntfs_attr_search_ctx *ctx, ntfs_attr *na); #endif /* EFS_H */ ntfs-3g-2026.2.25/include/ntfs-3g/layout.h0000664000175000017500000033024615152260173013402 /* * layout.h - Ntfs on-disk layout structures. Originated from the Linux-NTFS project. * * Copyright (c) 2000-2005 Anton Altaparmakov * Copyright (c) 2005 Yura Pakhuchiy * Copyright (c) 2005-2006 Szabolcs Szakacsits * * This program/include file 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/include file 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_LAYOUT_H #define _NTFS_LAYOUT_H #include "types.h" #include "endians.h" #include "support.h" /* The NTFS oem_id */ #define magicNTFS const_cpu_to_le64(0x202020205346544e) /* "NTFS " */ #define NTFS_SB_MAGIC 0x5346544e /* 'NTFS' */ /* * Location of bootsector on partition: * The standard NTFS_BOOT_SECTOR is on sector 0 of the partition. * On NT4 and above there is one backup copy of the boot sector to * be found on the last sector of the partition (not normally accessible * from within Windows as the bootsector contained number of sectors * value is one less than the actual value!). * On versions of NT 3.51 and earlier, the backup copy was located at * number of sectors/2 (integer divide), i.e. in the middle of the volume. */ /** * struct BIOS_PARAMETER_BLOCK - BIOS parameter block (bpb) structure. */ typedef struct { le16 bytes_per_sector; /* Size of a sector in bytes. */ u8 sectors_per_cluster; /* Size of a cluster in sectors. */ le16 reserved_sectors; /* zero */ u8 fats; /* zero */ le16 root_entries; /* zero */ le16 sectors; /* zero */ u8 media_type; /* 0xf8 = hard disk */ le16 sectors_per_fat; /* zero */ /*0x0d*/le16 sectors_per_track; /* Required to boot Windows. */ /*0x0f*/le16 heads; /* Required to boot Windows. */ /*0x11*/le32 hidden_sectors; /* Offset to the start of the partition relative to the disk in sectors. Required to boot Windows. */ /*0x15*/le32 large_sectors; /* zero */ /* sizeof() = 25 (0x19) bytes */ } __attribute__((__packed__)) BIOS_PARAMETER_BLOCK; /** * struct NTFS_BOOT_SECTOR - NTFS boot sector structure. */ typedef struct { u8 jump[3]; /* Irrelevant (jump to boot up code).*/ le64 oem_id; /* Magic "NTFS ". */ /*0x0b*/BIOS_PARAMETER_BLOCK bpb; /* See BIOS_PARAMETER_BLOCK. */ u8 physical_drive; /* 0x00 floppy, 0x80 hard disk */ u8 current_head; /* zero */ u8 extended_boot_signature; /* 0x80 */ u8 reserved2; /* zero */ /*0x28*/sle64 number_of_sectors; /* Number of sectors in volume. Gives maximum volume size of 2^63 sectors. Assuming standard sector size of 512 bytes, the maximum byte size is approx. 4.7x10^21 bytes. (-; */ sle64 mft_lcn; /* Cluster location of mft data. */ sle64 mftmirr_lcn; /* Cluster location of copy of mft. */ s8 clusters_per_mft_record; /* Mft record size in clusters. */ u8 reserved0[3]; /* zero */ s8 clusters_per_index_record; /* Index block size in clusters. */ u8 reserved1[3]; /* zero */ le64 volume_serial_number; /* Irrelevant (serial number). */ le32 checksum; /* Boot sector checksum. */ /*0x54*/u8 bootstrap[426]; /* Irrelevant (boot up code). */ le16 end_of_sector_marker; /* End of bootsector magic. Always is 0xaa55 in little endian. */ /* sizeof() = 512 (0x200) bytes */ } __attribute__((__packed__)) NTFS_BOOT_SECTOR; /** * enum NTFS_RECORD_TYPES - * * Magic identifiers present at the beginning of all ntfs record containing * records (like mft records for example). */ typedef enum { /* Found in $MFT/$DATA. */ magic_FILE = const_cpu_to_le32(0x454c4946), /* Mft entry. */ magic_INDX = const_cpu_to_le32(0x58444e49), /* Index buffer. */ magic_HOLE = const_cpu_to_le32(0x454c4f48), /* ? (NTFS 3.0+?) */ /* Found in $LogFile/$DATA. */ magic_RSTR = const_cpu_to_le32(0x52545352), /* Restart page. */ magic_RCRD = const_cpu_to_le32(0x44524352), /* Log record page. */ /* Found in $LogFile/$DATA. (May be found in $MFT/$DATA, also?) */ magic_CHKD = const_cpu_to_le32(0x444b4843), /* Modified by chkdsk. */ /* Found in all ntfs record containing records. */ magic_BAAD = const_cpu_to_le32(0x44414142), /* Failed multi sector transfer was detected. */ /* * Found in $LogFile/$DATA when a page is full or 0xff bytes and is * thus not initialized. User has to initialize the page before using * it. */ magic_empty = const_cpu_to_le32(0xffffffff),/* Record is empty and has to be initialized before it can be used. */ } NTFS_RECORD_TYPES; /* * Generic magic comparison macros. Finally found a use for the ## preprocessor * operator! (-8 */ #define ntfs_is_magic(x, m) ( (u32)(x) == (u32)magic_##m ) #define ntfs_is_magicp(p, m) ( *(u32*)(p) == (u32)magic_##m ) /* * Specialised magic comparison macros for the NTFS_RECORD_TYPES defined above. */ #define ntfs_is_file_record(x) ( ntfs_is_magic (x, FILE) ) #define ntfs_is_file_recordp(p) ( ntfs_is_magicp(p, FILE) ) #define ntfs_is_mft_record(x) ( ntfs_is_file_record(x) ) #define ntfs_is_mft_recordp(p) ( ntfs_is_file_recordp(p) ) #define ntfs_is_indx_record(x) ( ntfs_is_magic (x, INDX) ) #define ntfs_is_indx_recordp(p) ( ntfs_is_magicp(p, INDX) ) #define ntfs_is_hole_record(x) ( ntfs_is_magic (x, HOLE) ) #define ntfs_is_hole_recordp(p) ( ntfs_is_magicp(p, HOLE) ) #define ntfs_is_rstr_record(x) ( ntfs_is_magic (x, RSTR) ) #define ntfs_is_rstr_recordp(p) ( ntfs_is_magicp(p, RSTR) ) #define ntfs_is_rcrd_record(x) ( ntfs_is_magic (x, RCRD) ) #define ntfs_is_rcrd_recordp(p) ( ntfs_is_magicp(p, RCRD) ) #define ntfs_is_chkd_record(x) ( ntfs_is_magic (x, CHKD) ) #define ntfs_is_chkd_recordp(p) ( ntfs_is_magicp(p, CHKD) ) #define ntfs_is_baad_record(x) ( ntfs_is_magic (x, BAAD) ) #define ntfs_is_baad_recordp(p) ( ntfs_is_magicp(p, BAAD) ) #define ntfs_is_empty_record(x) ( ntfs_is_magic (x, empty) ) #define ntfs_is_empty_recordp(p) ( ntfs_is_magicp(p, empty) ) /* * The size of a logical sector in bytes, used as the sequence number stride for * multi-sector transfers. This is intended to be less than or equal to the * physical sector size, since if this were greater than the physical sector * size, then incomplete multi-sector transfers may not be detected. */ #define NTFS_BLOCK_SIZE 512 #define NTFS_BLOCK_SIZE_BITS 9 /** * struct NTFS_RECORD - * * The Update Sequence Array (usa) is an array of the le16 values which belong * to the end of each sector protected by the update sequence record in which * this array is contained. Note that the first entry is the Update Sequence * Number (usn), a cyclic counter of how many times the protected record has * been written to disk. The values 0 and -1 (ie. 0xffff) are not used. All * last le16's of each sector have to be equal to the usn (during reading) or * are set to it (during writing). If they are not, an incomplete multi sector * transfer has occurred when the data was written. * The maximum size for the update sequence array is fixed to: * maximum size = usa_ofs + (usa_count * 2) = 510 bytes * The 510 bytes comes from the fact that the last le16 in the array has to * (obviously) finish before the last le16 of the first 512-byte sector. * This formula can be used as a consistency check in that usa_ofs + * (usa_count * 2) has to be less than or equal to 510. */ typedef struct { NTFS_RECORD_TYPES magic;/* A four-byte magic identifying the record type and/or status. */ le16 usa_ofs; /* Offset to the Update Sequence Array (usa) from the start of the ntfs record. */ le16 usa_count; /* Number of le16 sized entries in the usa including the Update Sequence Number (usn), thus the number of fixups is the usa_count minus 1. */ } __attribute__((__packed__)) NTFS_RECORD; /** * enum NTFS_SYSTEM_FILES - System files mft record numbers. * * All these files are always marked as used in the bitmap attribute of the * mft; presumably in order to avoid accidental allocation for random other * mft records. Also, the sequence number for each of the system files is * always equal to their mft record number and it is never modified. */ typedef enum { FILE_MFT = 0, /* Master file table (mft). Data attribute contains the entries and bitmap attribute records which ones are in use (bit==1). */ FILE_MFTMirr = 1, /* Mft mirror: copy of first four mft records in data attribute. If cluster size > 4kiB, copy of first N mft records, with N = cluster_size / mft_record_size. */ FILE_LogFile = 2, /* Journalling log in data attribute. */ FILE_Volume = 3, /* Volume name attribute and volume information attribute (flags and ntfs version). Windows refers to this file as volume DASD (Direct Access Storage Device). */ FILE_AttrDef = 4, /* Array of attribute definitions in data attribute. */ FILE_root = 5, /* Root directory. */ FILE_Bitmap = 6, /* Allocation bitmap of all clusters (lcns) in data attribute. */ FILE_Boot = 7, /* Boot sector (always at cluster 0) in data attribute. */ FILE_BadClus = 8, /* Contains all bad clusters in the non-resident data attribute. */ FILE_Secure = 9, /* Shared security descriptors in data attribute and two indexes into the descriptors. Appeared in Windows 2000. Before that, this file was named $Quota but was unused. */ FILE_UpCase = 10, /* Uppercase equivalents of all 65536 Unicode characters in data attribute. */ FILE_Extend = 11, /* Directory containing other system files (eg. $ObjId, $Quota, $Reparse and $UsnJrnl). This is new to NTFS3.0. */ FILE_reserved12 = 12, /* Reserved for future use (records 12-15). */ FILE_reserved13 = 13, FILE_reserved14 = 14, FILE_mft_data = 15, /* Reserved for first extent of $MFT:$DATA */ FILE_first_user = 16, /* First user file, used as test limit for whether to allow opening a file or not. */ } NTFS_SYSTEM_FILES; /** * enum MFT_RECORD_FLAGS - * * These are the so far known MFT_RECORD_* flags (16-bit) which contain * information about the mft record in which they are present. * * MFT_RECORD_IS_4 exists on all $Extend sub-files. * It seems that it marks it is a metadata file with MFT record >24, however, * it is unknown if it is limited to metadata files only. * * MFT_RECORD_IS_VIEW_INDEX exists on every metafile with a non directory * index, that means an INDEX_ROOT and an INDEX_ALLOCATION with a name other * than "$I30". It is unknown if it is limited to metadata files only. */ typedef enum { MFT_RECORD_IN_USE = const_cpu_to_le16(0x0001), MFT_RECORD_IS_DIRECTORY = const_cpu_to_le16(0x0002), MFT_RECORD_IS_4 = const_cpu_to_le16(0x0004), MFT_RECORD_IS_VIEW_INDEX = const_cpu_to_le16(0x0008), MFT_REC_SPACE_FILLER = 0xffff, /* Just to make flags 16-bit. */ } __attribute__((__packed__)) MFT_RECORD_FLAGS; /* * mft references (aka file references or file record segment references) are * used whenever a structure needs to refer to a record in the mft. * * A reference consists of a 48-bit index into the mft and a 16-bit sequence * number used to detect stale references. * * For error reporting purposes we treat the 48-bit index as a signed quantity. * * The sequence number is a circular counter (skipping 0) describing how many * times the referenced mft record has been (re)used. This has to match the * sequence number of the mft record being referenced, otherwise the reference * is considered stale and removed (FIXME: only ntfsck or the driver itself?). * * If the sequence number is zero it is assumed that no sequence number * consistency checking should be performed. * * FIXME: Since inodes are 32-bit as of now, the driver needs to always check * for high_part being 0 and if not either BUG(), cause a panic() or handle * the situation in some other way. This shouldn't be a problem as a volume has * to become HUGE in order to need more than 32-bits worth of mft records. * Assuming the standard mft record size of 1kb only the records (never mind * the non-resident attributes, etc.) would require 4Tb of space on their own * for the first 32 bits worth of records. This is only if some strange person * doesn't decide to foul play and make the mft sparse which would be a really * horrible thing to do as it would trash our current driver implementation. )-: * Do I hear screams "we want 64-bit inodes!" ?!? (-; * * FIXME: The mft zone is defined as the first 12% of the volume. This space is * reserved so that the mft can grow contiguously and hence doesn't become * fragmented. Volume free space includes the empty part of the mft zone and * when the volume's free 88% are used up, the mft zone is shrunk by a factor * of 2, thus making more space available for more files/data. This process is * repeated every time there is no more free space except for the mft zone until * there really is no more free space. */ /* * Typedef the MFT_REF as a 64-bit value for easier handling. * Also define two unpacking macros to get to the reference (MREF) and * sequence number (MSEQNO) respectively. * The _LE versions are to be applied on little endian MFT_REFs. * Note: The _LE versions will return a CPU endian formatted value! */ #define MFT_REF_MASK_CPU 0x0000ffffffffffffULL #define MFT_REF_MASK_LE const_cpu_to_le64(MFT_REF_MASK_CPU) typedef u64 MFT_REF; typedef le64 leMFT_REF; /* a little-endian MFT_MREF */ #define MK_MREF(m, s) ((MFT_REF)(((MFT_REF)(s) << 48) | \ ((MFT_REF)(m) & MFT_REF_MASK_CPU))) #define MK_LE_MREF(m, s) const_cpu_to_le64(((MFT_REF)(((MFT_REF)(s) << 48) | \ ((MFT_REF)(m) & MFT_REF_MASK_CPU)))) #define MREF(x) ((u64)((x) & MFT_REF_MASK_CPU)) #define MSEQNO(x) ((u16)(((x) >> 48) & 0xffff)) #define MREF_LE(x) ((u64)(const_le64_to_cpu(x) & MFT_REF_MASK_CPU)) #define MSEQNO_LE(x) ((u16)((const_le64_to_cpu(x) >> 48) & 0xffff)) #define IS_ERR_MREF(x) (((x) & 0x0000800000000000ULL) ? 1 : 0) #define ERR_MREF(x) ((u64)((s64)(x))) #define MREF_ERR(x) ((int)((s64)(x))) /** * struct MFT_RECORD - An MFT record layout (NTFS 3.1+) * * The mft record header present at the beginning of every record in the mft. * This is followed by a sequence of variable length attribute records which * is terminated by an attribute of type AT_END which is a truncated attribute * in that it only consists of the attribute type code AT_END and none of the * other members of the attribute structure are present. */ typedef struct { /*Ofs*/ /* 0 NTFS_RECORD; -- Unfolded here as gcc doesn't like unnamed structs. */ NTFS_RECORD_TYPES magic;/* Usually the magic is "FILE". */ le16 usa_ofs; /* See NTFS_RECORD definition above. */ le16 usa_count; /* See NTFS_RECORD definition above. */ /* 8*/ leLSN lsn; /* $LogFile sequence number for this record. Changed every time the record is modified. */ /* 16*/ le16 sequence_number; /* Number of times this mft record has been reused. (See description for MFT_REF above.) NOTE: The increment (skipping zero) is done when the file is deleted. NOTE: If this is zero it is left zero. */ /* 18*/ le16 link_count; /* Number of hard links, i.e. the number of directory entries referencing this record. NOTE: Only used in mft base records. NOTE: When deleting a directory entry we check the link_count and if it is 1 we delete the file. Otherwise we delete the FILE_NAME_ATTR being referenced by the directory entry from the mft record and decrement the link_count. FIXME: Careful with Win32 + DOS names! */ /* 20*/ le16 attrs_offset; /* Byte offset to the first attribute in this mft record from the start of the mft record. NOTE: Must be aligned to 8-byte boundary. */ /* 22*/ MFT_RECORD_FLAGS flags; /* Bit array of MFT_RECORD_FLAGS. When a file is deleted, the MFT_RECORD_IN_USE flag is set to zero. */ /* 24*/ le32 bytes_in_use; /* Number of bytes used in this mft record. NOTE: Must be aligned to 8-byte boundary. */ /* 28*/ le32 bytes_allocated; /* Number of bytes allocated for this mft record. This should be equal to the mft record size. */ /* 32*/ leMFT_REF base_mft_record; /* This is zero for base mft records. When it is not zero it is a mft reference pointing to the base mft record to which this record belongs (this is then used to locate the attribute list attribute present in the base record which describes this extension record and hence might need modification when the extension record itself is modified, also locating the attribute list also means finding the other potential extents, belonging to the non-base mft record). */ /* 40*/ le16 next_attr_instance; /* The instance number that will be assigned to the next attribute added to this mft record. NOTE: Incremented each time after it is used. NOTE: Every time the mft record is reused this number is set to zero. NOTE: The first instance number is always 0. */ /* The below fields are specific to NTFS 3.1+ (Windows XP and above): */ /* 42*/ le16 reserved; /* Reserved/alignment. */ /* 44*/ le32 mft_record_number; /* Number of this mft record. */ /* sizeof() = 48 bytes */ /* * When (re)using the mft record, we place the update sequence array at this * offset, i.e. before we start with the attributes. This also makes sense, * otherwise we could run into problems with the update sequence array * containing in itself the last two bytes of a sector which would mean that * multi sector transfer protection wouldn't work. As you can't protect data * by overwriting it since you then can't get it back... * When reading we obviously use the data from the ntfs record header. */ } __attribute__((__packed__)) MFT_RECORD; /** * struct MFT_RECORD_OLD - An MFT record layout (NTFS <=3.0) * * This is the version without the NTFS 3.1+ specific fields. */ typedef struct { /*Ofs*/ /* 0 NTFS_RECORD; -- Unfolded here as gcc doesn't like unnamed structs. */ NTFS_RECORD_TYPES magic;/* Usually the magic is "FILE". */ le16 usa_ofs; /* See NTFS_RECORD definition above. */ le16 usa_count; /* See NTFS_RECORD definition above. */ /* 8*/ leLSN lsn; /* $LogFile sequence number for this record. Changed every time the record is modified. */ /* 16*/ le16 sequence_number; /* Number of times this mft record has been reused. (See description for MFT_REF above.) NOTE: The increment (skipping zero) is done when the file is deleted. NOTE: If this is zero it is left zero. */ /* 18*/ le16 link_count; /* Number of hard links, i.e. the number of directory entries referencing this record. NOTE: Only used in mft base records. NOTE: When deleting a directory entry we check the link_count and if it is 1 we delete the file. Otherwise we delete the FILE_NAME_ATTR being referenced by the directory entry from the mft record and decrement the link_count. FIXME: Careful with Win32 + DOS names! */ /* 20*/ le16 attrs_offset; /* Byte offset to the first attribute in this mft record from the start of the mft record. NOTE: Must be aligned to 8-byte boundary. */ /* 22*/ MFT_RECORD_FLAGS flags; /* Bit array of MFT_RECORD_FLAGS. When a file is deleted, the MFT_RECORD_IN_USE flag is set to zero. */ /* 24*/ le32 bytes_in_use; /* Number of bytes used in this mft record. NOTE: Must be aligned to 8-byte boundary. */ /* 28*/ le32 bytes_allocated; /* Number of bytes allocated for this mft record. This should be equal to the mft record size. */ /* 32*/ leMFT_REF base_mft_record; /* This is zero for base mft records. When it is not zero it is a mft reference pointing to the base mft record to which this record belongs (this is then used to locate the attribute list attribute present in the base record which describes this extension record and hence might need modification when the extension record itself is modified, also locating the attribute list also means finding the other potential extents, belonging to the non-base mft record). */ /* 40*/ le16 next_attr_instance; /* The instance number that will be assigned to the next attribute added to this mft record. NOTE: Incremented each time after it is used. NOTE: Every time the mft record is reused this number is set to zero. NOTE: The first instance number is always 0. */ /* sizeof() = 42 bytes */ /* * When (re)using the mft record, we place the update sequence array at this * offset, i.e. before we start with the attributes. This also makes sense, * otherwise we could run into problems with the update sequence array * containing in itself the last two bytes of a sector which would mean that * multi sector transfer protection wouldn't work. As you can't protect data * by overwriting it since you then can't get it back... * When reading we obviously use the data from the ntfs record header. */ } __attribute__((__packed__)) MFT_RECORD_OLD; /** * enum ATTR_TYPES - System defined attributes (32-bit). * * Each attribute type has a corresponding attribute name (Unicode string of * maximum 64 character length) as described by the attribute definitions * present in the data attribute of the $AttrDef system file. * * On NTFS 3.0 volumes the names are just as the types are named in the below * enum exchanging AT_ for the dollar sign ($). If that isn't a revealing * choice of symbol... (-; */ typedef enum { AT_UNUSED = const_cpu_to_le32( 0), AT_STANDARD_INFORMATION = const_cpu_to_le32( 0x10), AT_ATTRIBUTE_LIST = const_cpu_to_le32( 0x20), AT_FILE_NAME = const_cpu_to_le32( 0x30), AT_OBJECT_ID = const_cpu_to_le32( 0x40), AT_SECURITY_DESCRIPTOR = const_cpu_to_le32( 0x50), AT_VOLUME_NAME = const_cpu_to_le32( 0x60), AT_VOLUME_INFORMATION = const_cpu_to_le32( 0x70), AT_DATA = const_cpu_to_le32( 0x80), AT_INDEX_ROOT = const_cpu_to_le32( 0x90), AT_INDEX_ALLOCATION = const_cpu_to_le32( 0xa0), AT_BITMAP = const_cpu_to_le32( 0xb0), AT_REPARSE_POINT = const_cpu_to_le32( 0xc0), AT_EA_INFORMATION = const_cpu_to_le32( 0xd0), AT_EA = const_cpu_to_le32( 0xe0), AT_PROPERTY_SET = const_cpu_to_le32( 0xf0), AT_LOGGED_UTILITY_STREAM = const_cpu_to_le32( 0x100), AT_FIRST_USER_DEFINED_ATTRIBUTE = const_cpu_to_le32( 0x1000), AT_END = const_cpu_to_le32(0xffffffff), } ATTR_TYPES; /** * enum COLLATION_RULES - The collation rules for sorting views/indexes/etc * (32-bit). * * COLLATION_BINARY - Collate by binary compare where the first byte is most * significant. * COLLATION_FILE_NAME - Collate Unicode strings by comparing their 16-bit * coding units, primarily ignoring case using the volume's $UpCase table, * but falling back to a case-sensitive comparison if the names are equal * ignoring case. * COLLATION_UNICODE_STRING - TODO: this is not yet implemented and still needs * to be properly documented --- is it really the same as * COLLATION_FILE_NAME? * COLLATION_NTOFS_ULONG - Sorting is done according to ascending le32 key * values. E.g. used for $SII index in FILE_Secure, which sorts by * security_id (le32). * COLLATION_NTOFS_SID - Sorting is done according to ascending SID values. * E.g. used for $O index in FILE_Extend/$Quota. * COLLATION_NTOFS_SECURITY_HASH - Sorting is done first by ascending hash * values and second by ascending security_id values. E.g. used for $SDH * index in FILE_Secure. * COLLATION_NTOFS_ULONGS - Sorting is done according to a sequence of ascending * le32 key values. E.g. used for $O index in FILE_Extend/$ObjId, which * sorts by object_id (16-byte), by splitting up the object_id in four * le32 values and using them as individual keys. E.g. take the following * two security_ids, stored as follows on disk: * 1st: a1 61 65 b7 65 7b d4 11 9e 3d 00 e0 81 10 42 59 * 2nd: 38 14 37 d2 d2 f3 d4 11 a5 21 c8 6b 79 b1 97 45 * To compare them, they are split into four le32 values each, like so: * 1st: 0xb76561a1 0x11d47b65 0xe0003d9e 0x59421081 * 2nd: 0xd2371438 0x11d4f3d2 0x6bc821a5 0x4597b179 * Now, it is apparent why the 2nd object_id collates after the 1st: the * first le32 value of the 1st object_id is less than the first le32 of * the 2nd object_id. If the first le32 values of both object_ids were * equal then the second le32 values would be compared, etc. */ typedef enum { COLLATION_BINARY = const_cpu_to_le32(0), COLLATION_FILE_NAME = const_cpu_to_le32(1), COLLATION_UNICODE_STRING = const_cpu_to_le32(2), COLLATION_NTOFS_ULONG = const_cpu_to_le32(16), COLLATION_NTOFS_SID = const_cpu_to_le32(17), COLLATION_NTOFS_SECURITY_HASH = const_cpu_to_le32(18), COLLATION_NTOFS_ULONGS = const_cpu_to_le32(19), } COLLATION_RULES; /** * enum ATTR_DEF_FLAGS - * * The flags (32-bit) describing attribute properties in the attribute * definition structure. FIXME: This information is based on Regis's * information and, according to him, it is not certain and probably * incomplete. The INDEXABLE flag is fairly certainly correct as only the file * name attribute has this flag set and this is the only attribute indexed in * NT4. */ typedef enum { ATTR_DEF_INDEXABLE = const_cpu_to_le32(0x02), /* Attribute can be indexed. */ ATTR_DEF_MULTIPLE = const_cpu_to_le32(0x04), /* Attribute type can be present multiple times in the mft records of an inode. */ ATTR_DEF_NOT_ZERO = const_cpu_to_le32(0x08), /* Attribute value must contain at least one non-zero byte. */ ATTR_DEF_INDEXED_UNIQUE = const_cpu_to_le32(0x10), /* Attribute must be indexed and the attribute value must be unique for the attribute type in all of the mft records of an inode. */ ATTR_DEF_NAMED_UNIQUE = const_cpu_to_le32(0x20), /* Attribute must be named and the name must be unique for the attribute type in all of the mft records of an inode. */ ATTR_DEF_RESIDENT = const_cpu_to_le32(0x40), /* Attribute must be resident. */ ATTR_DEF_ALWAYS_LOG = const_cpu_to_le32(0x80), /* Always log modifications to this attribute, regardless of whether it is resident or non-resident. Without this, only log modifications if the attribute is resident. */ } ATTR_DEF_FLAGS; /** * struct ATTR_DEF - * * The data attribute of FILE_AttrDef contains a sequence of attribute * definitions for the NTFS volume. With this, it is supposed to be safe for an * older NTFS driver to mount a volume containing a newer NTFS version without * damaging it (that's the theory. In practice it's: not damaging it too much). * Entries are sorted by attribute type. The flags describe whether the * attribute can be resident/non-resident and possibly other things, but the * actual bits are unknown. */ typedef struct { /*hex ofs*/ /* 0*/ ntfschar name[0x40]; /* Unicode name of the attribute. Zero terminated. */ /* 80*/ ATTR_TYPES type; /* Type of the attribute. */ /* 84*/ le32 display_rule; /* Default display rule. FIXME: What does it mean? (AIA) */ /* 88*/ COLLATION_RULES collation_rule; /* Default collation rule. */ /* 8c*/ ATTR_DEF_FLAGS flags; /* Flags describing the attribute. */ /* 90*/ sle64 min_size; /* Optional minimum attribute size. */ /* 98*/ sle64 max_size; /* Maximum size of attribute. */ /* sizeof() = 0xa0 or 160 bytes */ } __attribute__((__packed__)) ATTR_DEF; /** * enum ATTR_FLAGS - Attribute flags (16-bit). */ typedef enum { ATTR_IS_COMPRESSED = const_cpu_to_le16(0x0001), ATTR_COMPRESSION_MASK = const_cpu_to_le16(0x00ff), /* Compression method mask. Also, first illegal value. */ ATTR_IS_ENCRYPTED = const_cpu_to_le16(0x4000), ATTR_IS_SPARSE = const_cpu_to_le16(0x8000), } __attribute__((__packed__)) ATTR_FLAGS; /* * Attribute compression. * * Only the data attribute is ever compressed in the current ntfs driver in * Windows. Further, compression is only applied when the data attribute is * non-resident. Finally, to use compression, the maximum allowed cluster size * on a volume is 4kib. * * The compression method is based on independently compressing blocks of X * clusters, where X is determined from the compression_unit value found in the * non-resident attribute record header (more precisely: X = 2^compression_unit * clusters). On Windows NT/2k, X always is 16 clusters (compression_unit = 4). * * There are three different cases of how a compression block of X clusters * can be stored: * * 1) The data in the block is all zero (a sparse block): * This is stored as a sparse block in the runlist, i.e. the runlist * entry has length = X and lcn = -1. The mapping pairs array actually * uses a delta_lcn value length of 0, i.e. delta_lcn is not present at * all, which is then interpreted by the driver as lcn = -1. * NOTE: Even uncompressed files can be sparse on NTFS 3.0 volumes, then * the same principles apply as above, except that the length is not * restricted to being any particular value. * * 2) The data in the block is not compressed: * This happens when compression doesn't reduce the size of the block * in clusters. I.e. if compression has a small effect so that the * compressed data still occupies X clusters, then the uncompressed data * is stored in the block. * This case is recognised by the fact that the runlist entry has * length = X and lcn >= 0. The mapping pairs array stores this as * normal with a run length of X and some specific delta_lcn, i.e. * delta_lcn has to be present. * * 3) The data in the block is compressed: * The common case. This case is recognised by the fact that the run * list entry has length L < X and lcn >= 0. The mapping pairs array * stores this as normal with a run length of X and some specific * delta_lcn, i.e. delta_lcn has to be present. This runlist entry is * immediately followed by a sparse entry with length = X - L and * lcn = -1. The latter entry is to make up the vcn counting to the * full compression block size X. * * In fact, life is more complicated because adjacent entries of the same type * can be coalesced. This means that one has to keep track of the number of * clusters handled and work on a basis of X clusters at a time being one * block. An example: if length L > X this means that this particular runlist * entry contains a block of length X and part of one or more blocks of length * L - X. Another example: if length L < X, this does not necessarily mean that * the block is compressed as it might be that the lcn changes inside the block * and hence the following runlist entry describes the continuation of the * potentially compressed block. The block would be compressed if the * following runlist entry describes at least X - L sparse clusters, thus * making up the compression block length as described in point 3 above. (Of * course, there can be several runlist entries with small lengths so that the * sparse entry does not follow the first data containing entry with * length < X.) * * NOTE: At the end of the compressed attribute value, there most likely is not * just the right amount of data to make up a compression block, thus this data * is not even attempted to be compressed. It is just stored as is, unless * the number of clusters it occupies is reduced when compressed in which case * it is stored as a compressed compression block, complete with sparse * clusters at the end. */ /** * enum RESIDENT_ATTR_FLAGS - Flags of resident attributes (8-bit). */ typedef enum { RESIDENT_ATTR_IS_INDEXED = 0x01, /* Attribute is referenced in an index (has implications for deleting and modifying the attribute). */ } __attribute__((__packed__)) RESIDENT_ATTR_FLAGS; /** * struct ATTR_RECORD - Attribute record header. * * Always aligned to 8-byte boundary. */ typedef struct { /*Ofs*/ /* 0*/ ATTR_TYPES type; /* The (32-bit) type of the attribute. */ /* 4*/ le32 length; /* Byte size of the resident part of the attribute (aligned to 8-byte boundary). Used to get to the next attribute. */ /* 8*/ u8 non_resident; /* If 0, attribute is resident. If 1, attribute is non-resident. */ /* 9*/ u8 name_length; /* Unicode character size of name of attribute. 0 if unnamed. */ /* 10*/ le16 name_offset; /* If name_length != 0, the byte offset to the beginning of the name from the attribute record. Note that the name is stored as a Unicode string. When creating, place offset just at the end of the record header. Then, follow with attribute value or mapping pairs array, resident and non-resident attributes respectively, aligning to an 8-byte boundary. */ /* 12*/ ATTR_FLAGS flags; /* Flags describing the attribute. */ /* 14*/ le16 instance; /* The instance of this attribute record. This number is unique within this mft record (see MFT_RECORD/next_attribute_instance notes above for more details). */ /* 16*/ union { /* Resident attributes. */ struct { /* 16 */ le32 value_length; /* Byte size of attribute value. */ /* 20 */ le16 value_offset; /* Byte offset of the attribute value from the start of the attribute record. When creating, align to 8-byte boundary if we have a name present as this might not have a length of a multiple of 8-bytes. */ /* 22 */ RESIDENT_ATTR_FLAGS resident_flags; /* See above. */ /* 23 */ s8 reservedR; /* Reserved/alignment to 8-byte boundary. */ /* 24 */ void *resident_end[0]; /* Use offsetof(ATTR_RECORD, resident_end) to get size of a resident attribute. */ } __attribute__((__packed__)); /* Non-resident attributes. */ struct { /* 16*/ leVCN lowest_vcn; /* Lowest valid virtual cluster number for this portion of the attribute value or 0 if this is the only extent (usually the case). - Only when an attribute list is used does lowest_vcn != 0 ever occur. */ /* 24*/ leVCN highest_vcn; /* Highest valid vcn of this extent of the attribute value. - Usually there is only one portion, so this usually equals the attribute value size in clusters minus 1. Can be -1 for zero length files. Can be 0 for "single extent" attributes. */ /* 32*/ le16 mapping_pairs_offset; /* Byte offset from the beginning of the structure to the mapping pairs array which contains the mappings between the vcns and the logical cluster numbers (lcns). When creating, place this at the end of this record header aligned to 8-byte boundary. */ /* 34*/ u8 compression_unit; /* The compression unit expressed as the log to the base 2 of the number of clusters in a compression unit. 0 means not compressed. (This effectively limits the compression unit size to be a power of two clusters.) WinNT4 only uses a value of 4. */ /* 35*/ u8 reserved1[5]; /* Align to 8-byte boundary. */ /* The sizes below are only used when lowest_vcn is zero, as otherwise it would be difficult to keep them up-to-date.*/ /* 40*/ sle64 allocated_size; /* Byte size of disk space allocated to hold the attribute value. Always is a multiple of the cluster size. When a file is compressed, this field is a multiple of the compression block size (2^compression_unit) and it represents the logically allocated space rather than the actual on disk usage. For this use the compressed_size (see below). */ /* 48*/ sle64 data_size; /* Byte size of the attribute value. Can be larger than allocated_size if attribute value is compressed or sparse. */ /* 56*/ sle64 initialized_size; /* Byte size of initialized portion of the attribute value. Usually equals data_size. */ /* 64 */ void *non_resident_end[0]; /* Use offsetof(ATTR_RECORD, non_resident_end) to get size of a non resident attribute. */ /* sizeof(uncompressed attr) = 64*/ /* 64*/ sle64 compressed_size; /* Byte size of the attribute value after compression. Only present when compressed. Always is a multiple of the cluster size. Represents the actual amount of disk space being used on the disk. */ /* 72 */ void *compressed_end[0]; /* Use offsetof(ATTR_RECORD, compressed_end) to get size of a compressed attribute. */ /* sizeof(compressed attr) = 72*/ } __attribute__((__packed__)); } __attribute__((__packed__)); } __attribute__((__packed__)) ATTR_RECORD; typedef ATTR_RECORD ATTR_REC; /** * enum FILE_ATTR_FLAGS - File attribute flags (32-bit). */ typedef enum { /* * These flags are only present in the STANDARD_INFORMATION attribute * (in the field file_attributes). */ FILE_ATTR_READONLY = const_cpu_to_le32(0x00000001), FILE_ATTR_HIDDEN = const_cpu_to_le32(0x00000002), FILE_ATTR_SYSTEM = const_cpu_to_le32(0x00000004), /* Old DOS volid. Unused in NT. = const_cpu_to_le32(0x00000008), */ FILE_ATTR_DIRECTORY = const_cpu_to_le32(0x00000010), /* FILE_ATTR_DIRECTORY is not considered valid in NT. It is reserved for the DOS SUBDIRECTORY flag. */ FILE_ATTR_ARCHIVE = const_cpu_to_le32(0x00000020), FILE_ATTR_DEVICE = const_cpu_to_le32(0x00000040), FILE_ATTR_NORMAL = const_cpu_to_le32(0x00000080), FILE_ATTR_TEMPORARY = const_cpu_to_le32(0x00000100), FILE_ATTR_SPARSE_FILE = const_cpu_to_le32(0x00000200), FILE_ATTR_REPARSE_POINT = const_cpu_to_le32(0x00000400), FILE_ATTR_COMPRESSED = const_cpu_to_le32(0x00000800), FILE_ATTR_OFFLINE = const_cpu_to_le32(0x00001000), FILE_ATTR_NOT_CONTENT_INDEXED = const_cpu_to_le32(0x00002000), FILE_ATTR_ENCRYPTED = const_cpu_to_le32(0x00004000), /* Supposed to mean no data locally, possibly repurposed */ FILE_ATTRIBUTE_RECALL_ON_OPEN = const_cpu_to_le32(0x00040000), FILE_ATTR_VALID_FLAGS = const_cpu_to_le32(0x00047fb7), /* FILE_ATTR_VALID_FLAGS masks out the old DOS VolId and the FILE_ATTR_DEVICE and preserves everything else. This mask is used to obtain all flags that are valid for reading. */ FILE_ATTR_VALID_SET_FLAGS = const_cpu_to_le32(0x000031a7), /* FILE_ATTR_VALID_SET_FLAGS masks out the old DOS VolId, the FILE_ATTR_DEVICE, FILE_ATTR_DIRECTORY, FILE_ATTR_SPARSE_FILE, FILE_ATTR_REPARSE_POINT, FILE_ATRE_COMPRESSED and FILE_ATTR_ENCRYPTED and preserves the rest. This mask is used to to obtain all flags that are valid for setting. */ /** * FILE_ATTR_I30_INDEX_PRESENT - Is it a directory? * * This is a copy of the MFT_RECORD_IS_DIRECTORY bit from the mft * record, telling us whether this is a directory or not, i.e. whether * it has an index root attribute named "$I30" or not. * * This flag is only present in the FILE_NAME attribute (in the * file_attributes field). */ FILE_ATTR_I30_INDEX_PRESENT = const_cpu_to_le32(0x10000000), /** * FILE_ATTR_VIEW_INDEX_PRESENT - Does have a non-directory index? * * This is a copy of the MFT_RECORD_IS_VIEW_INDEX bit from the mft * record, telling us whether this file has a view index present (eg. * object id index, quota index, one of the security indexes and the * reparse points index). * * This flag is only present in the $STANDARD_INFORMATION and * $FILE_NAME attributes. */ FILE_ATTR_VIEW_INDEX_PRESENT = const_cpu_to_le32(0x20000000), } __attribute__((__packed__)) FILE_ATTR_FLAGS; /* * NOTE on times in NTFS: All times are in MS standard time format, i.e. they * are the number of 100-nanosecond intervals since 1st January 1601, 00:00:00 * universal coordinated time (UTC). (In Linux time starts 1st January 1970, * 00:00:00 UTC and is stored as the number of 1-second intervals since then.) */ /** * struct STANDARD_INFORMATION - Attribute: Standard information (0x10). * * NOTE: Always resident. * NOTE: Present in all base file records on a volume. * NOTE: There is conflicting information about the meaning of each of the time * fields but the meaning as defined below has been verified to be * correct by practical experimentation on Windows NT4 SP6a and is hence * assumed to be the one and only correct interpretation. */ typedef struct { /*Ofs*/ /* 0*/ sle64 creation_time; /* Time file was created. Updated when a filename is changed(?). */ /* 8*/ sle64 last_data_change_time; /* Time the data attribute was last modified. */ /* 16*/ sle64 last_mft_change_time; /* Time this mft record was last modified. */ /* 24*/ sle64 last_access_time; /* Approximate time when the file was last accessed (obviously this is not updated on read-only volumes). In Windows this is only updated when accessed if some time delta has passed since the last update. Also, last access times updates can be disabled altogether for speed. */ /* 32*/ FILE_ATTR_FLAGS file_attributes; /* Flags describing the file. */ /* 36*/ union { /* NTFS 1.2 (and previous, presumably) */ struct { /* 36 */ u8 reserved12[12]; /* Reserved/alignment to 8-byte boundary. */ /* 48 */ void *v1_end[0]; /* Marker for offsetof(). */ } __attribute__((__packed__)); /* sizeof() = 48 bytes */ /* NTFS 3.0 */ struct { /* * If a volume has been upgraded from a previous NTFS version, then these * fields are present only if the file has been accessed since the upgrade. * Recognize the difference by comparing the length of the resident attribute * value. If it is 48, then the following fields are missing. If it is 72 then * the fields are present. Maybe just check like this: * if (resident.ValueLength < sizeof(STANDARD_INFORMATION)) { * Assume NTFS 1.2- format. * If (volume version is 3.0+) * Upgrade attribute to NTFS 3.0 format. * else * Use NTFS 1.2- format for access. * } else * Use NTFS 3.0 format for access. * Only problem is that it might be legal to set the length of the value to * arbitrarily large values thus spoiling this check. - But chkdsk probably * views that as a corruption, assuming that it behaves like this for all * attributes. */ /* 36*/ le32 maximum_versions; /* Maximum allowed versions for file. Zero if version numbering is disabled. */ /* 40*/ le32 version_number; /* This file's version (if any). Set to zero if maximum_versions is zero. */ /* 44*/ le32 class_id; /* Class id from bidirectional class id index (?). */ /* 48*/ le32 owner_id; /* Owner_id of the user owning the file. Translate via $Q index in FILE_Extend /$Quota to the quota control entry for the user owning the file. Zero if quotas are disabled. */ /* 52*/ le32 security_id; /* Security_id for the file. Translate via $SII index and $SDS data stream in FILE_Secure to the security descriptor. */ /* 56*/ le64 quota_charged; /* Byte size of the charge to the quota for all streams of the file. Note: Is zero if quotas are disabled. */ /* 64*/ le64 usn; /* Last update sequence number of the file. This is a direct index into the change (aka usn) journal file. It is zero if the usn journal is disabled. NOTE: To disable the journal need to delete the journal file itself and to then walk the whole mft and set all Usn entries in all mft records to zero! (This can take a while!) The journal is FILE_Extend/$UsnJrnl. Win2k will recreate the journal and initiate logging if necessary when mounting the partition. This, in contrast to disabling the journal is a very fast process, so the user won't even notice it. */ /* 72*/ void *v3_end[0]; /* Marker for offsetof(). */ } __attribute__((__packed__)); } __attribute__((__packed__)); /* sizeof() = 72 bytes (NTFS 3.0) */ } __attribute__((__packed__)) STANDARD_INFORMATION; /** * struct ATTR_LIST_ENTRY - Attribute: Attribute list (0x20). * * - Can be either resident or non-resident. * - Value consists of a sequence of variable length, 8-byte aligned, * ATTR_LIST_ENTRY records. * - The attribute list attribute contains one entry for each attribute of * the file in which the list is located, except for the list attribute * itself. The list is sorted: first by attribute type, second by attribute * name (if present), third by instance number. The extents of one * non-resident attribute (if present) immediately follow after the initial * extent. They are ordered by lowest_vcn and have their instance set to zero. * It is not allowed to have two attributes with all sorting keys equal. * - Further restrictions: * - If not resident, the vcn to lcn mapping array has to fit inside the * base mft record. * - The attribute list attribute value has a maximum size of 256kb. This * is imposed by the Windows cache manager. * - Attribute lists are only used when the attributes of mft record do not * fit inside the mft record despite all attributes (that can be made * non-resident) having been made non-resident. This can happen e.g. when: * - File has a large number of hard links (lots of file name * attributes present). * - The mapping pairs array of some non-resident attribute becomes so * large due to fragmentation that it overflows the mft record. * - The security descriptor is very complex (not applicable to * NTFS 3.0 volumes). * - There are many named streams. */ typedef struct { /*Ofs*/ /* 0*/ ATTR_TYPES type; /* Type of referenced attribute. */ /* 4*/ le16 length; /* Byte size of this entry. */ /* 6*/ u8 name_length; /* Size in Unicode chars of the name of the attribute or 0 if unnamed. */ /* 7*/ u8 name_offset; /* Byte offset to beginning of attribute name (always set this to where the name would start even if unnamed). */ /* 8*/ leVCN lowest_vcn; /* Lowest virtual cluster number of this portion of the attribute value. This is usually 0. It is non-zero for the case where one attribute does not fit into one mft record and thus several mft records are allocated to hold this attribute. In the latter case, each mft record holds one extent of the attribute and there is one attribute list entry for each extent. NOTE: This is DEFINITELY a signed value! The windows driver uses cmp, followed by jg when comparing this, thus it treats it as signed. */ /* 16*/ leMFT_REF mft_reference;/* The reference of the mft record holding the ATTR_RECORD for this portion of the attribute value. */ /* 24*/ le16 instance; /* If lowest_vcn = 0, the instance of the attribute being referenced; otherwise 0. */ /* 26*/ ntfschar name[0]; /* Use when creating only. When reading use name_offset to determine the location of the name. */ /* sizeof() = 26 + (attribute_name_length * 2) bytes */ } __attribute__((__packed__)) ATTR_LIST_ENTRY; /* * The maximum allowed length for a file name. */ #define NTFS_MAX_NAME_LEN 255 /** * enum FILE_NAME_TYPE_FLAGS - Possible namespaces for filenames in ntfs. * (8-bit). */ typedef enum { FILE_NAME_POSIX = 0x00, /* This is the largest namespace. It is case sensitive and allows all Unicode characters except for: '\0' and '/'. Beware that in WinNT/2k files which eg have the same name except for their case will not be distinguished by the standard utilities and thus a "del filename" will delete both "filename" and "fileName" without warning. */ FILE_NAME_WIN32 = 0x01, /* The standard WinNT/2k NTFS long filenames. Case insensitive. All Unicode chars except: '\0', '"', '*', '/', ':', '<', '>', '?', '\' and '|'. Trailing dots and spaces are allowed, even though on Windows a filename with such a suffix can only be created and accessed using a WinNT-style path, i.e. \\?\-prefixed. (If a regular path is used, Windows will strip the trailing dots and spaces, which makes such filenames incompatible with most Windows software.) */ FILE_NAME_DOS = 0x02, /* The standard DOS filenames (8.3 format). Uppercase only. All 8-bit characters greater space, except: '"', '*', '+', ',', '/', ':', ';', '<', '=', '>', '?' and '\'. Trailing dots and spaces are forbidden. */ FILE_NAME_WIN32_AND_DOS = 0x03, /* 3 means that both the Win32 and the DOS filenames are identical and hence have been saved in this single filename record. */ } __attribute__((__packed__)) FILE_NAME_TYPE_FLAGS; /** * struct FILE_NAME_ATTR - Attribute: Filename (0x30). * * NOTE: Always resident. * NOTE: All fields, except the parent_directory, are only updated when the * filename is changed. Until then, they just become out of sync with * reality and the more up to date values are present in the standard * information attribute. * NOTE: There is conflicting information about the meaning of each of the time * fields but the meaning as defined below has been verified to be * correct by practical experimentation on Windows NT4 SP6a and is hence * assumed to be the one and only correct interpretation. */ typedef struct { /*hex ofs*/ /* 0*/ leMFT_REF parent_directory; /* Directory this filename is referenced from. */ /* 8*/ sle64 creation_time; /* Time file was created. */ /* 10*/ sle64 last_data_change_time; /* Time the data attribute was last modified. */ /* 18*/ sle64 last_mft_change_time; /* Time this mft record was last modified. */ /* 20*/ sle64 last_access_time; /* Last time this mft record was accessed. */ /* 28*/ sle64 allocated_size; /* Byte size of on-disk allocated space for the data attribute. So for normal $DATA, this is the allocated_size from the unnamed $DATA attribute and for compressed and/or sparse $DATA, this is the compressed_size from the unnamed $DATA attribute. NOTE: This is a multiple of the cluster size. */ /* 30*/ sle64 data_size; /* Byte size of actual data in data attribute. */ /* 38*/ FILE_ATTR_FLAGS file_attributes; /* Flags describing the file. */ /* 3c*/ union { /* 3c*/ struct { /* 3c*/ le16 packed_ea_size; /* Size of the buffer needed to pack the extended attributes (EAs), if such are present.*/ /* 3e*/ le16 reserved; /* Reserved for alignment. */ } __attribute__((__packed__)); /* 3c*/ le32 reparse_point_tag; /* Type of reparse point, present only in reparse points and only if there are no EAs. */ } __attribute__((__packed__)); /* 40*/ u8 file_name_length; /* Length of file name in (Unicode) characters. */ /* 41*/ FILE_NAME_TYPE_FLAGS file_name_type; /* Namespace of the file name.*/ /* 42*/ ntfschar file_name[0]; /* File name in Unicode. */ } __attribute__((__packed__)) FILE_NAME_ATTR; /** * struct GUID - GUID structures store globally unique identifiers (GUID). * * A GUID is a 128-bit value consisting of one group of eight hexadecimal * digits, followed by three groups of four hexadecimal digits each, followed * by one group of twelve hexadecimal digits. GUIDs are Microsoft's * implementation of the distributed computing environment (DCE) universally * unique identifier (UUID). * * Example of a GUID: * 1F010768-5A73-BC91-0010-A52216A7227B */ typedef struct { le32 data1; /* The first eight hexadecimal digits of the GUID. */ le16 data2; /* The first group of four hexadecimal digits. */ le16 data3; /* The second group of four hexadecimal digits. */ u8 data4[8]; /* The first two bytes are the third group of four hexadecimal digits. The remaining six bytes are the final 12 hexadecimal digits. */ } __attribute__((__packed__)) GUID; /** * struct OBJ_ID_INDEX_DATA - FILE_Extend/$ObjId contains an index named $O. * * This index contains all object_ids present on the volume as the index keys * and the corresponding mft_record numbers as the index entry data parts. * * The data part (defined below) also contains three other object_ids: * birth_volume_id - object_id of FILE_Volume on which the file was first * created. Optional (i.e. can be zero). * birth_object_id - object_id of file when it was first created. Usually * equals the object_id. Optional (i.e. can be zero). * domain_id - Reserved (always zero). */ typedef struct { leMFT_REF mft_reference; /* Mft record containing the object_id in the index entry key. */ union { struct { GUID birth_volume_id; GUID birth_object_id; GUID domain_id; } __attribute__((__packed__)); u8 extended_info[48]; } __attribute__((__packed__)); } __attribute__((__packed__)) OBJ_ID_INDEX_DATA; /** * struct OBJECT_ID_ATTR - Attribute: Object id (NTFS 3.0+) (0x40). * * NOTE: Always resident. */ typedef struct { GUID object_id; /* Unique id assigned to the file.*/ /* The following fields are optional. The attribute value size is 16 bytes, i.e. sizeof(GUID), if these are not present at all. Note, the entries can be present but one or more (or all) can be zero meaning that that particular value(s) is(are) not defined. Note, when the fields are missing here, it is well possible that they are to be found within the $Extend/$ObjId system file indexed under the above object_id. */ union { struct { GUID birth_volume_id; /* Unique id of volume on which the file was first created.*/ GUID birth_object_id; /* Unique id of file when it was first created. */ GUID domain_id; /* Reserved, zero. */ } __attribute__((__packed__)); u8 extended_info[48]; } __attribute__((__packed__)); } __attribute__((__packed__)) OBJECT_ID_ATTR; #if 0 /** * enum IDENTIFIER_AUTHORITIES - * * The pre-defined IDENTIFIER_AUTHORITIES used as SID_IDENTIFIER_AUTHORITY in * the SID structure (see below). */ typedef enum { /* SID string prefix. */ SECURITY_NULL_SID_AUTHORITY = {0, 0, 0, 0, 0, 0}, /* S-1-0 */ SECURITY_WORLD_SID_AUTHORITY = {0, 0, 0, 0, 0, 1}, /* S-1-1 */ SECURITY_LOCAL_SID_AUTHORITY = {0, 0, 0, 0, 0, 2}, /* S-1-2 */ SECURITY_CREATOR_SID_AUTHORITY = {0, 0, 0, 0, 0, 3}, /* S-1-3 */ SECURITY_NON_UNIQUE_AUTHORITY = {0, 0, 0, 0, 0, 4}, /* S-1-4 */ SECURITY_NT_SID_AUTHORITY = {0, 0, 0, 0, 0, 5}, /* S-1-5 */ } IDENTIFIER_AUTHORITIES; #endif /** * enum RELATIVE_IDENTIFIERS - * * These relative identifiers (RIDs) are used with the above identifier * authorities to make up universal well-known SIDs. * * Note: The relative identifier (RID) refers to the portion of a SID, which * identifies a user or group in relation to the authority that issued the SID. * For example, the universal well-known SID Creator Owner ID (S-1-3-0) is * made up of the identifier authority SECURITY_CREATOR_SID_AUTHORITY (3) and * the relative identifier SECURITY_CREATOR_OWNER_RID (0). */ typedef enum { /* Identifier authority. */ SECURITY_NULL_RID = 0, /* S-1-0 */ SECURITY_WORLD_RID = 0, /* S-1-1 */ SECURITY_LOCAL_RID = 0, /* S-1-2 */ SECURITY_CREATOR_OWNER_RID = 0, /* S-1-3 */ SECURITY_CREATOR_GROUP_RID = 1, /* S-1-3 */ SECURITY_CREATOR_OWNER_SERVER_RID = 2, /* S-1-3 */ SECURITY_CREATOR_GROUP_SERVER_RID = 3, /* S-1-3 */ SECURITY_DIALUP_RID = 1, SECURITY_NETWORK_RID = 2, SECURITY_BATCH_RID = 3, SECURITY_INTERACTIVE_RID = 4, SECURITY_SERVICE_RID = 6, SECURITY_ANONYMOUS_LOGON_RID = 7, SECURITY_PROXY_RID = 8, SECURITY_ENTERPRISE_CONTROLLERS_RID=9, SECURITY_SERVER_LOGON_RID = 9, SECURITY_PRINCIPAL_SELF_RID = 0xa, SECURITY_AUTHENTICATED_USER_RID = 0xb, SECURITY_RESTRICTED_CODE_RID = 0xc, SECURITY_TERMINAL_SERVER_RID = 0xd, SECURITY_LOGON_IDS_RID = 5, SECURITY_LOGON_IDS_RID_COUNT = 3, SECURITY_LOCAL_SYSTEM_RID = 0x12, SECURITY_NT_NON_UNIQUE = 0x15, SECURITY_BUILTIN_DOMAIN_RID = 0x20, /* * Well-known domain relative sub-authority values (RIDs). */ /* Users. */ DOMAIN_USER_RID_ADMIN = 0x1f4, DOMAIN_USER_RID_GUEST = 0x1f5, DOMAIN_USER_RID_KRBTGT = 0x1f6, /* Groups. */ DOMAIN_GROUP_RID_ADMINS = 0x200, DOMAIN_GROUP_RID_USERS = 0x201, DOMAIN_GROUP_RID_GUESTS = 0x202, DOMAIN_GROUP_RID_COMPUTERS = 0x203, DOMAIN_GROUP_RID_CONTROLLERS = 0x204, DOMAIN_GROUP_RID_CERT_ADMINS = 0x205, DOMAIN_GROUP_RID_SCHEMA_ADMINS = 0x206, DOMAIN_GROUP_RID_ENTERPRISE_ADMINS= 0x207, DOMAIN_GROUP_RID_POLICY_ADMINS = 0x208, /* Aliases. */ DOMAIN_ALIAS_RID_ADMINS = 0x220, DOMAIN_ALIAS_RID_USERS = 0x221, DOMAIN_ALIAS_RID_GUESTS = 0x222, DOMAIN_ALIAS_RID_POWER_USERS = 0x223, DOMAIN_ALIAS_RID_ACCOUNT_OPS = 0x224, DOMAIN_ALIAS_RID_SYSTEM_OPS = 0x225, DOMAIN_ALIAS_RID_PRINT_OPS = 0x226, DOMAIN_ALIAS_RID_BACKUP_OPS = 0x227, DOMAIN_ALIAS_RID_REPLICATOR = 0x228, DOMAIN_ALIAS_RID_RAS_SERVERS = 0x229, DOMAIN_ALIAS_RID_PREW2KCOMPACCESS = 0x22a, } RELATIVE_IDENTIFIERS; /* * The universal well-known SIDs: * * NULL_SID S-1-0-0 * WORLD_SID S-1-1-0 * LOCAL_SID S-1-2-0 * CREATOR_OWNER_SID S-1-3-0 * CREATOR_GROUP_SID S-1-3-1 * CREATOR_OWNER_SERVER_SID S-1-3-2 * CREATOR_GROUP_SERVER_SID S-1-3-3 * * (Non-unique IDs) S-1-4 * * NT well-known SIDs: * * NT_AUTHORITY_SID S-1-5 * DIALUP_SID S-1-5-1 * * NETWORD_SID S-1-5-2 * BATCH_SID S-1-5-3 * INTERACTIVE_SID S-1-5-4 * SERVICE_SID S-1-5-6 * ANONYMOUS_LOGON_SID S-1-5-7 (aka null logon session) * PROXY_SID S-1-5-8 * SERVER_LOGON_SID S-1-5-9 (aka domain controller account) * SELF_SID S-1-5-10 (self RID) * AUTHENTICATED_USER_SID S-1-5-11 * RESTRICTED_CODE_SID S-1-5-12 (running restricted code) * TERMINAL_SERVER_SID S-1-5-13 (running on terminal server) * * (Logon IDs) S-1-5-5-X-Y * * (NT non-unique IDs) S-1-5-0x15-... * * (Built-in domain) S-1-5-0x20 */ /** * union SID_IDENTIFIER_AUTHORITY - A 48-bit value used in the SID structure * * NOTE: This is stored as a big endian number. */ typedef union { struct { be16 high_part; /* High 16-bits. */ be32 low_part; /* Low 32-bits. */ } __attribute__((__packed__)); u8 value[6]; /* Value as individual bytes. */ } __attribute__((__packed__)) SID_IDENTIFIER_AUTHORITY; /** * struct SID - * * The SID structure is a variable-length structure used to uniquely identify * users or groups. SID stands for security identifier. * * The standard textual representation of the SID is of the form: * S-R-I-S-S... * Where: * - The first "S" is the literal character 'S' identifying the following * digits as a SID. * - R is the revision level of the SID expressed as a sequence of digits * in decimal. * - I is the 48-bit identifier_authority, expressed as digits in decimal, * if I < 2^32, or hexadecimal prefixed by "0x", if I >= 2^32. * - S... is one or more sub_authority values, expressed as digits in * decimal. * * Example SID; the domain-relative SID of the local Administrators group on * Windows NT/2k: * S-1-5-32-544 * This translates to a SID with: * revision = 1, * sub_authority_count = 2, * identifier_authority = {0,0,0,0,0,5}, // SECURITY_NT_AUTHORITY * sub_authority[0] = 32, // SECURITY_BUILTIN_DOMAIN_RID * sub_authority[1] = 544 // DOMAIN_ALIAS_RID_ADMINS */ typedef struct { u8 revision; u8 sub_authority_count; SID_IDENTIFIER_AUTHORITY identifier_authority; le32 sub_authority[1]; /* At least one sub_authority. */ } __attribute__((__packed__)) SID; /** * enum SID_CONSTANTS - Current constants for SIDs. */ typedef enum { SID_REVISION = 1, /* Current revision level. */ SID_MAX_SUB_AUTHORITIES = 15, /* Maximum number of those. */ SID_RECOMMENDED_SUB_AUTHORITIES = 1, /* Will change to around 6 in a future revision. */ } SID_CONSTANTS; /** * enum ACE_TYPES - The predefined ACE types (8-bit, see below). */ typedef enum { ACCESS_MIN_MS_ACE_TYPE = 0, ACCESS_ALLOWED_ACE_TYPE = 0, ACCESS_DENIED_ACE_TYPE = 1, SYSTEM_AUDIT_ACE_TYPE = 2, SYSTEM_ALARM_ACE_TYPE = 3, /* Not implemented as of Win2k. */ ACCESS_MAX_MS_V2_ACE_TYPE = 3, ACCESS_ALLOWED_COMPOUND_ACE_TYPE= 4, ACCESS_MAX_MS_V3_ACE_TYPE = 4, /* The following are Win2k only. */ ACCESS_MIN_MS_OBJECT_ACE_TYPE = 5, ACCESS_ALLOWED_OBJECT_ACE_TYPE = 5, ACCESS_DENIED_OBJECT_ACE_TYPE = 6, SYSTEM_AUDIT_OBJECT_ACE_TYPE = 7, SYSTEM_ALARM_OBJECT_ACE_TYPE = 8, ACCESS_MAX_MS_OBJECT_ACE_TYPE = 8, ACCESS_MAX_MS_V4_ACE_TYPE = 8, /* This one is for WinNT&2k. */ ACCESS_MAX_MS_ACE_TYPE = 8, /* Windows XP and later */ ACCESS_ALLOWED_CALLBACK_ACE_TYPE = 9, ACCESS_DENIED_CALLBACK_ACE_TYPE = 10, ACCESS_ALLOWED_CALLBACK_OBJECT_ACE_TYPE = 11, ACCESS_DENIED_CALLBACK_OBJECT_ACE_TYPE = 12, SYSTEM_AUDIT_CALLBACK_ACE_TYPE = 13, SYSTEM_ALARM_CALLBACK_ACE_TYPE = 14, /* reserved */ SYSTEM_AUDIT_CALLBACK_OBJECT_ACE_TYPE = 15, SYSTEM_ALARM_CALLBACK_OBJECT_ACE_TYPE = 16, /* reserved */ /* Windows Vista and later */ SYSTEM_MANDATORY_LABEL_ACE_TYPE = 17, /* Windows 8 and later */ SYSTEM_RESOURCE_ATTRIBUTE_ACE_TYPE = 18, SYSTEM_SCOPED_POLICY_ID_ACE_TYPE = 19, /* Windows 10 and later */ SYSTEM_PROCESS_TRUST_LABEL_ACE_TYPE = 20, } __attribute__((__packed__)) ACE_TYPES; /** * enum ACE_FLAGS - The ACE flags (8-bit) for audit and inheritance. * * SUCCESSFUL_ACCESS_ACE_FLAG is only used with system audit and alarm ACE * types to indicate that a message is generated (in Windows!) for successful * accesses. * * FAILED_ACCESS_ACE_FLAG is only used with system audit and alarm ACE types * to indicate that a message is generated (in Windows!) for failed accesses. */ typedef enum { /* The inheritance flags. */ OBJECT_INHERIT_ACE = 0x01, CONTAINER_INHERIT_ACE = 0x02, NO_PROPAGATE_INHERIT_ACE = 0x04, INHERIT_ONLY_ACE = 0x08, INHERITED_ACE = 0x10, /* Win2k only. */ VALID_INHERIT_FLAGS = 0x1f, /* The audit flags. */ SUCCESSFUL_ACCESS_ACE_FLAG = 0x40, FAILED_ACCESS_ACE_FLAG = 0x80, } __attribute__((__packed__)) ACE_FLAGS; /** * struct ACE_HEADER - * * An ACE is an access-control entry in an access-control list (ACL). * An ACE defines access to an object for a specific user or group or defines * the types of access that generate system-administration messages or alarms * for a specific user or group. The user or group is identified by a security * identifier (SID). * * Each ACE starts with an ACE_HEADER structure (aligned on 4-byte boundary), * which specifies the type and size of the ACE. The format of the subsequent * data depends on the ACE type. */ typedef struct { ACE_TYPES type; /* Type of the ACE. */ ACE_FLAGS flags; /* Flags describing the ACE. */ le16 size; /* Size in bytes of the ACE. */ } __attribute__((__packed__)) ACE_HEADER; /** * enum ACCESS_MASK - The access mask (32-bit). * * Defines the access rights. */ typedef enum { /* * The specific rights (bits 0 to 15). Depend on the type of the * object being secured by the ACE. */ /* Specific rights for files and directories are as follows: */ /* Right to read data from the file. (FILE) */ FILE_READ_DATA = const_cpu_to_le32(0x00000001), /* Right to list contents of a directory. (DIRECTORY) */ FILE_LIST_DIRECTORY = const_cpu_to_le32(0x00000001), /* Right to write data to the file. (FILE) */ FILE_WRITE_DATA = const_cpu_to_le32(0x00000002), /* Right to create a file in the directory. (DIRECTORY) */ FILE_ADD_FILE = const_cpu_to_le32(0x00000002), /* Right to append data to the file. (FILE) */ FILE_APPEND_DATA = const_cpu_to_le32(0x00000004), /* Right to create a subdirectory. (DIRECTORY) */ FILE_ADD_SUBDIRECTORY = const_cpu_to_le32(0x00000004), /* Right to read extended attributes. (FILE/DIRECTORY) */ FILE_READ_EA = const_cpu_to_le32(0x00000008), /* Right to write extended attributes. (FILE/DIRECTORY) */ FILE_WRITE_EA = const_cpu_to_le32(0x00000010), /* Right to execute a file. (FILE) */ FILE_EXECUTE = const_cpu_to_le32(0x00000020), /* Right to traverse the directory. (DIRECTORY) */ FILE_TRAVERSE = const_cpu_to_le32(0x00000020), /* * Right to delete a directory and all the files it contains (its * children), even if the files are read-only. (DIRECTORY) */ FILE_DELETE_CHILD = const_cpu_to_le32(0x00000040), /* Right to read file attributes. (FILE/DIRECTORY) */ FILE_READ_ATTRIBUTES = const_cpu_to_le32(0x00000080), /* Right to change file attributes. (FILE/DIRECTORY) */ FILE_WRITE_ATTRIBUTES = const_cpu_to_le32(0x00000100), /* * The standard rights (bits 16 to 23). Are independent of the type of * object being secured. */ /* Right to delete the object. */ DELETE = const_cpu_to_le32(0x00010000), /* * Right to read the information in the object's security descriptor, * not including the information in the SACL. I.e. right to read the * security descriptor and owner. */ READ_CONTROL = const_cpu_to_le32(0x00020000), /* Right to modify the DACL in the object's security descriptor. */ WRITE_DAC = const_cpu_to_le32(0x00040000), /* Right to change the owner in the object's security descriptor. */ WRITE_OWNER = const_cpu_to_le32(0x00080000), /* * Right to use the object for synchronization. Enables a process to * wait until the object is in the signalled state. Some object types * do not support this access right. */ SYNCHRONIZE = const_cpu_to_le32(0x00100000), /* * The following STANDARD_RIGHTS_* are combinations of the above for * convenience and are defined by the Win32 API. */ /* These are currently defined to READ_CONTROL. */ STANDARD_RIGHTS_READ = const_cpu_to_le32(0x00020000), STANDARD_RIGHTS_WRITE = const_cpu_to_le32(0x00020000), STANDARD_RIGHTS_EXECUTE = const_cpu_to_le32(0x00020000), /* Combines DELETE, READ_CONTROL, WRITE_DAC, and WRITE_OWNER access. */ STANDARD_RIGHTS_REQUIRED = const_cpu_to_le32(0x000f0000), /* * Combines DELETE, READ_CONTROL, WRITE_DAC, WRITE_OWNER, and * SYNCHRONIZE access. */ STANDARD_RIGHTS_ALL = const_cpu_to_le32(0x001f0000), /* * The access system ACL and maximum allowed access types (bits 24 to * 25, bits 26 to 27 are reserved). */ ACCESS_SYSTEM_SECURITY = const_cpu_to_le32(0x01000000), MAXIMUM_ALLOWED = const_cpu_to_le32(0x02000000), /* * The generic rights (bits 28 to 31). These map onto the standard and * specific rights. */ /* Read, write, and execute access. */ GENERIC_ALL = const_cpu_to_le32(0x10000000), /* Execute access. */ GENERIC_EXECUTE = const_cpu_to_le32(0x20000000), /* * Write access. For files, this maps onto: * FILE_APPEND_DATA | FILE_WRITE_ATTRIBUTES | FILE_WRITE_DATA | * FILE_WRITE_EA | STANDARD_RIGHTS_WRITE | SYNCHRONIZE * For directories, the mapping has the same numerical value. See * above for the descriptions of the rights granted. */ GENERIC_WRITE = const_cpu_to_le32(0x40000000), /* * Read access. For files, this maps onto: * FILE_READ_ATTRIBUTES | FILE_READ_DATA | FILE_READ_EA | * STANDARD_RIGHTS_READ | SYNCHRONIZE * For directories, the mapping has the same numerical value. See * above for the descriptions of the rights granted. */ GENERIC_READ = const_cpu_to_le32(0x80000000), } ACCESS_MASK; /** * struct GENERIC_MAPPING - * * The generic mapping array. Used to denote the mapping of each generic * access right to a specific access mask. * * FIXME: What exactly is this and what is it for? (AIA) */ typedef struct { ACCESS_MASK generic_read; ACCESS_MASK generic_write; ACCESS_MASK generic_execute; ACCESS_MASK generic_all; } __attribute__((__packed__)) GENERIC_MAPPING; /* * The predefined ACE type structures are as defined below. */ /** * struct ACCESS_DENIED_ACE - * * ACCESS_ALLOWED_ACE, ACCESS_DENIED_ACE, SYSTEM_AUDIT_ACE, SYSTEM_ALARM_ACE */ typedef struct { /* 0 ACE_HEADER; -- Unfolded here as gcc doesn't like unnamed structs. */ ACE_TYPES type; /* Type of the ACE. */ ACE_FLAGS flags; /* Flags describing the ACE. */ le16 size; /* Size in bytes of the ACE. */ /* 4*/ ACCESS_MASK mask; /* Access mask associated with the ACE. */ /* 8*/ SID sid; /* The SID associated with the ACE. */ } __attribute__((__packed__)) ACCESS_ALLOWED_ACE, ACCESS_DENIED_ACE, SYSTEM_AUDIT_ACE, SYSTEM_ALARM_ACE; /** * enum OBJECT_ACE_FLAGS - The object ACE flags (32-bit). */ typedef enum { ACE_OBJECT_TYPE_PRESENT = const_cpu_to_le32(1), ACE_INHERITED_OBJECT_TYPE_PRESENT = const_cpu_to_le32(2), } OBJECT_ACE_FLAGS; /** * struct ACCESS_ALLOWED_OBJECT_ACE - */ typedef struct { /* 0 ACE_HEADER; -- Unfolded here as gcc doesn't like unnamed structs. */ ACE_TYPES type; /* Type of the ACE. */ ACE_FLAGS flags; /* Flags describing the ACE. */ le16 size; /* Size in bytes of the ACE. */ /* 4*/ ACCESS_MASK mask; /* Access mask associated with the ACE. */ /* 8*/ OBJECT_ACE_FLAGS object_flags; /* Flags describing the object ACE. */ /* 12*/ GUID object_type; /* 28*/ GUID inherited_object_type; /* 44*/ SID sid; /* The SID associated with the ACE. */ } __attribute__((__packed__)) ACCESS_ALLOWED_OBJECT_ACE, ACCESS_DENIED_OBJECT_ACE, SYSTEM_AUDIT_OBJECT_ACE, SYSTEM_ALARM_OBJECT_ACE; /** * struct ACL - An ACL is an access-control list (ACL). * * An ACL starts with an ACL header structure, which specifies the size of * the ACL and the number of ACEs it contains. The ACL header is followed by * zero or more access control entries (ACEs). The ACL as well as each ACE * are aligned on 4-byte boundaries. */ typedef struct { u8 revision; /* Revision of this ACL. */ u8 alignment1; le16 size; /* Allocated space in bytes for ACL. Includes this header, the ACEs and the remaining free space. */ le16 ace_count; /* Number of ACEs in the ACL. */ le16 alignment2; /* sizeof() = 8 bytes */ } __attribute__((__packed__)) ACL; /** * enum ACL_CONSTANTS - Current constants for ACLs. */ typedef enum { /* Current revision. */ ACL_REVISION = 2, ACL_REVISION_DS = 4, /* History of revisions. */ ACL_REVISION1 = 1, MIN_ACL_REVISION = 2, ACL_REVISION2 = 2, ACL_REVISION3 = 3, ACL_REVISION4 = 4, MAX_ACL_REVISION = 4, } ACL_CONSTANTS; /** * enum SECURITY_DESCRIPTOR_CONTROL - * * The security descriptor control flags (16-bit). * * SE_OWNER_DEFAULTED - This boolean flag, when set, indicates that the * SID pointed to by the Owner field was provided by a * defaulting mechanism rather than explicitly provided by the * original provider of the security descriptor. This may * affect the treatment of the SID with respect to inheritance * of an owner. * * SE_GROUP_DEFAULTED - This boolean flag, when set, indicates that the * SID in the Group field was provided by a defaulting mechanism * rather than explicitly provided by the original provider of * the security descriptor. This may affect the treatment of * the SID with respect to inheritance of a primary group. * * SE_DACL_PRESENT - This boolean flag, when set, indicates that the * security descriptor contains a discretionary ACL. If this * flag is set and the Dacl field of the SECURITY_DESCRIPTOR is * null, then a null ACL is explicitly being specified. * * SE_DACL_DEFAULTED - This boolean flag, when set, indicates that the * ACL pointed to by the Dacl field was provided by a defaulting * mechanism rather than explicitly provided by the original * provider of the security descriptor. This may affect the * treatment of the ACL with respect to inheritance of an ACL. * This flag is ignored if the DaclPresent flag is not set. * * SE_SACL_PRESENT - This boolean flag, when set, indicates that the * security descriptor contains a system ACL pointed to by the * Sacl field. If this flag is set and the Sacl field of the * SECURITY_DESCRIPTOR is null, then an empty (but present) * ACL is being specified. * * SE_SACL_DEFAULTED - This boolean flag, when set, indicates that the * ACL pointed to by the Sacl field was provided by a defaulting * mechanism rather than explicitly provided by the original * provider of the security descriptor. This may affect the * treatment of the ACL with respect to inheritance of an ACL. * This flag is ignored if the SaclPresent flag is not set. * * SE_SELF_RELATIVE - This boolean flag, when set, indicates that the * security descriptor is in self-relative form. In this form, * all fields of the security descriptor are contiguous in memory * and all pointer fields are expressed as offsets from the * beginning of the security descriptor. */ typedef enum { SE_OWNER_DEFAULTED = const_cpu_to_le16(0x0001), SE_GROUP_DEFAULTED = const_cpu_to_le16(0x0002), SE_DACL_PRESENT = const_cpu_to_le16(0x0004), SE_DACL_DEFAULTED = const_cpu_to_le16(0x0008), SE_SACL_PRESENT = const_cpu_to_le16(0x0010), SE_SACL_DEFAULTED = const_cpu_to_le16(0x0020), SE_DACL_AUTO_INHERIT_REQ = const_cpu_to_le16(0x0100), SE_SACL_AUTO_INHERIT_REQ = const_cpu_to_le16(0x0200), SE_DACL_AUTO_INHERITED = const_cpu_to_le16(0x0400), SE_SACL_AUTO_INHERITED = const_cpu_to_le16(0x0800), SE_DACL_PROTECTED = const_cpu_to_le16(0x1000), SE_SACL_PROTECTED = const_cpu_to_le16(0x2000), SE_RM_CONTROL_VALID = const_cpu_to_le16(0x4000), SE_SELF_RELATIVE = const_cpu_to_le16(0x8000), } __attribute__((__packed__)) SECURITY_DESCRIPTOR_CONTROL; /** * struct SECURITY_DESCRIPTOR_RELATIVE - * * Self-relative security descriptor. Contains the owner and group SIDs as well * as the sacl and dacl ACLs inside the security descriptor itself. */ typedef struct { u8 revision; /* Revision level of the security descriptor. */ u8 alignment; SECURITY_DESCRIPTOR_CONTROL control; /* Flags qualifying the type of the descriptor as well as the following fields. */ le32 owner; /* Byte offset to a SID representing an object's owner. If this is NULL, no owner SID is present in the descriptor. */ le32 group; /* Byte offset to a SID representing an object's primary group. If this is NULL, no primary group SID is present in the descriptor. */ le32 sacl; /* Byte offset to a system ACL. Only valid, if SE_SACL_PRESENT is set in the control field. If SE_SACL_PRESENT is set but sacl is NULL, a NULL ACL is specified. */ le32 dacl; /* Byte offset to a discretionary ACL. Only valid, if SE_DACL_PRESENT is set in the control field. If SE_DACL_PRESENT is set but dacl is NULL, a NULL ACL (unconditionally granting access) is specified. */ /* sizeof() = 0x14 bytes */ } __attribute__((__packed__)) SECURITY_DESCRIPTOR_RELATIVE; /** * struct SECURITY_DESCRIPTOR - Absolute security descriptor. * * Does not contain the owner and group SIDs, nor the sacl and dacl ACLs inside * the security descriptor. Instead, it contains pointers to these structures * in memory. Obviously, absolute security descriptors are only useful for in * memory representations of security descriptors. * * On disk, a self-relative security descriptor is used. */ typedef struct { u8 revision; /* Revision level of the security descriptor. */ u8 alignment; SECURITY_DESCRIPTOR_CONTROL control; /* Flags qualifying the type of the descriptor as well as the following fields. */ SID *owner; /* Points to a SID representing an object's owner. If this is NULL, no owner SID is present in the descriptor. */ SID *group; /* Points to a SID representing an object's primary group. If this is NULL, no primary group SID is present in the descriptor. */ ACL *sacl; /* Points to a system ACL. Only valid, if SE_SACL_PRESENT is set in the control field. If SE_SACL_PRESENT is set but sacl is NULL, a NULL ACL is specified. */ ACL *dacl; /* Points to a discretionary ACL. Only valid, if SE_DACL_PRESENT is set in the control field. If SE_DACL_PRESENT is set but dacl is NULL, a NULL ACL (unconditionally granting access) is specified. */ } __attribute__((__packed__)) SECURITY_DESCRIPTOR; /** * enum SECURITY_DESCRIPTOR_CONSTANTS - * * Current constants for security descriptors. */ typedef enum { /* Current revision. */ SECURITY_DESCRIPTOR_REVISION = 1, SECURITY_DESCRIPTOR_REVISION1 = 1, /* The sizes of both the absolute and relative security descriptors is the same as pointers, at least on ia32 architecture are 32-bit. */ SECURITY_DESCRIPTOR_MIN_LENGTH = sizeof(SECURITY_DESCRIPTOR), } SECURITY_DESCRIPTOR_CONSTANTS; /* * Attribute: Security descriptor (0x50). * * A standard self-relative security descriptor. * * NOTE: Can be resident or non-resident. * NOTE: Not used in NTFS 3.0+, as security descriptors are stored centrally * in FILE_Secure and the correct descriptor is found using the security_id * from the standard information attribute. */ typedef SECURITY_DESCRIPTOR_RELATIVE SECURITY_DESCRIPTOR_ATTR; /* * On NTFS 3.0+, all security descriptors are stored in FILE_Secure. Only one * referenced instance of each unique security descriptor is stored. * * FILE_Secure contains no unnamed data attribute, i.e. it has zero length. It * does, however, contain two indexes ($SDH and $SII) as well as a named data * stream ($SDS). * * Every unique security descriptor is assigned a unique security identifier * (security_id, not to be confused with a SID). The security_id is unique for * the NTFS volume and is used as an index into the $SII index, which maps * security_ids to the security descriptor's storage location within the $SDS * data attribute. The $SII index is sorted by ascending security_id. * * A simple hash is computed from each security descriptor. This hash is used * as an index into the $SDH index, which maps security descriptor hashes to * the security descriptor's storage location within the $SDS data attribute. * The $SDH index is sorted by security descriptor hash and is stored in a B+ * tree. When searching $SDH (with the intent of determining whether or not a * new security descriptor is already present in the $SDS data stream), if a * matching hash is found, but the security descriptors do not match, the * search in the $SDH index is continued, searching for a next matching hash. * * When a precise match is found, the security_id corresponding to the security * descriptor in the $SDS attribute is read from the found $SDH index entry and * is stored in the $STANDARD_INFORMATION attribute of the file/directory to * which the security descriptor is being applied. The $STANDARD_INFORMATION * attribute is present in all base mft records (i.e. in all files and * directories). * * If a match is not found, the security descriptor is assigned a new unique * security_id and is added to the $SDS data attribute. Then, entries * referencing the this security descriptor in the $SDS data attribute are * added to the $SDH and $SII indexes. * * Note: Entries are never deleted from FILE_Secure, even if nothing * references an entry any more. */ /** * struct SECURITY_DESCRIPTOR_HEADER - * * This header precedes each security descriptor in the $SDS data stream. * This is also the index entry data part of both the $SII and $SDH indexes. */ typedef struct { le32 hash; /* Hash of the security descriptor. */ le32 security_id; /* The security_id assigned to the descriptor. */ le64 offset; /* Byte offset of this entry in the $SDS stream. */ le32 length; /* Size in bytes of this entry in $SDS stream. */ } __attribute__((__packed__)) SECURITY_DESCRIPTOR_HEADER; /** * struct SDH_INDEX_DATA - */ typedef struct { le32 hash; /* Hash of the security descriptor. */ le32 security_id; /* The security_id assigned to the descriptor. */ le64 offset; /* Byte offset of this entry in the $SDS stream. */ le32 length; /* Size in bytes of this entry in $SDS stream. */ le32 reserved_II; /* Padding - always unicode "II" or zero. This field isn't counted in INDEX_ENTRY's data_length. */ } __attribute__((__packed__)) SDH_INDEX_DATA; /** * struct SII_INDEX_DATA - */ typedef SECURITY_DESCRIPTOR_HEADER SII_INDEX_DATA; /** * struct SDS_ENTRY - * * The $SDS data stream contains the security descriptors, aligned on 16-byte * boundaries, sorted by security_id in a B+ tree. Security descriptors cannot * cross 256kib boundaries (this restriction is imposed by the Windows cache * manager). Each security descriptor is contained in a SDS_ENTRY structure. * Also, each security descriptor is stored twice in the $SDS stream with a * fixed offset of 0x40000 bytes (256kib, the Windows cache manager's max size) * between them; i.e. if a SDS_ENTRY specifies an offset of 0x51d0, then the * the first copy of the security descriptor will be at offset 0x51d0 in the * $SDS data stream and the second copy will be at offset 0x451d0. */ typedef struct { /* 0 SECURITY_DESCRIPTOR_HEADER; -- Unfolded here as gcc doesn't like unnamed structs. */ le32 hash; /* Hash of the security descriptor. */ le32 security_id; /* The security_id assigned to the descriptor. */ le64 offset; /* Byte offset of this entry in the $SDS stream. */ le32 length; /* Size in bytes of this entry in $SDS stream. */ /* 20*/ SECURITY_DESCRIPTOR_RELATIVE sid; /* The self-relative security descriptor. */ } __attribute__((__packed__)) SDS_ENTRY; /** * struct SII_INDEX_KEY - The index entry key used in the $SII index. * * The collation type is COLLATION_NTOFS_ULONG. */ typedef struct { le32 security_id; /* The security_id assigned to the descriptor. */ } __attribute__((__packed__)) SII_INDEX_KEY; /** * struct SDH_INDEX_KEY - The index entry key used in the $SDH index. * * The keys are sorted first by hash and then by security_id. * The collation rule is COLLATION_NTOFS_SECURITY_HASH. */ typedef struct { le32 hash; /* Hash of the security descriptor. */ le32 security_id; /* The security_id assigned to the descriptor. */ } __attribute__((__packed__)) SDH_INDEX_KEY; /** * struct VOLUME_NAME - Attribute: Volume name (0x60). * * NOTE: Always resident. * NOTE: Present only in FILE_Volume. */ typedef struct { ntfschar name[0]; /* The name of the volume in Unicode. */ } __attribute__((__packed__)) VOLUME_NAME; /** * enum VOLUME_FLAGS - Possible flags for the volume (16-bit). */ typedef enum { VOLUME_IS_DIRTY = const_cpu_to_le16(0x0001), VOLUME_RESIZE_LOG_FILE = const_cpu_to_le16(0x0002), VOLUME_UPGRADE_ON_MOUNT = const_cpu_to_le16(0x0004), VOLUME_MOUNTED_ON_NT4 = const_cpu_to_le16(0x0008), VOLUME_DELETE_USN_UNDERWAY = const_cpu_to_le16(0x0010), VOLUME_REPAIR_OBJECT_ID = const_cpu_to_le16(0x0020), VOLUME_CHKDSK_UNDERWAY = const_cpu_to_le16(0x4000), VOLUME_MODIFIED_BY_CHKDSK = const_cpu_to_le16(0x8000), VOLUME_FLAGS_MASK = const_cpu_to_le16(0xc03f), } __attribute__((__packed__)) VOLUME_FLAGS; /** * struct VOLUME_INFORMATION - Attribute: Volume information (0x70). * * NOTE: Always resident. * NOTE: Present only in FILE_Volume. * NOTE: Windows 2000 uses NTFS 3.0 while Windows NT4 service pack 6a uses * NTFS 1.2. I haven't personally seen other values yet. */ typedef struct { le64 reserved; /* Not used (yet?). */ u8 major_ver; /* Major version of the ntfs format. */ u8 minor_ver; /* Minor version of the ntfs format. */ VOLUME_FLAGS flags; /* Bit array of VOLUME_* flags. */ } __attribute__((__packed__)) VOLUME_INFORMATION; /** * struct DATA_ATTR - Attribute: Data attribute (0x80). * * NOTE: Can be resident or non-resident. * * Data contents of a file (i.e. the unnamed stream) or of a named stream. */ typedef struct { u8 data[0]; /* The file's data contents. */ } __attribute__((__packed__)) DATA_ATTR; /** * enum INDEX_HEADER_FLAGS - Index header flags (8-bit). */ typedef enum { /* When index header is in an index root attribute: */ SMALL_INDEX = 0, /* The index is small enough to fit inside the index root attribute and there is no index allocation attribute present. */ LARGE_INDEX = 1, /* The index is too large to fit in the index root attribute and/or an index allocation attribute is present. */ /* * When index header is in an index block, i.e. is part of index * allocation attribute: */ LEAF_NODE = 0, /* This is a leaf node, i.e. there are no more nodes branching off it. */ INDEX_NODE = 1, /* This node indexes other nodes, i.e. is not a leaf node. */ NODE_MASK = 1, /* Mask for accessing the *_NODE bits. */ } __attribute__((__packed__)) INDEX_HEADER_FLAGS; /** * struct INDEX_HEADER - * * This is the header for indexes, describing the INDEX_ENTRY records, which * follow the INDEX_HEADER. Together the index header and the index entries * make up a complete index. * * IMPORTANT NOTE: The offset, length and size structure members are counted * relative to the start of the index header structure and not relative to the * start of the index root or index allocation structures themselves. */ typedef struct { /* 0*/ le32 entries_offset; /* Byte offset from the INDEX_HEADER to first INDEX_ENTRY, aligned to 8-byte boundary. */ /* 4*/ le32 index_length; /* Data size in byte of the INDEX_ENTRY's, including the INDEX_HEADER, aligned to 8. */ /* 8*/ le32 allocated_size; /* Allocated byte size of this index (block), multiple of 8 bytes. See more below. */ /* For the index root attribute, the above two numbers are always equal, as the attribute is resident and it is resized as needed. For the index allocation attribute, the attribute is not resident and the allocated_size is equal to the index_block_size specified by the corresponding INDEX_ROOT attribute minus the INDEX_BLOCK size not counting the INDEX_HEADER part (i.e. minus -24). */ /* 12*/ INDEX_HEADER_FLAGS ih_flags; /* Bit field of INDEX_HEADER_FLAGS. */ /* 13*/ u8 reserved[3]; /* Reserved/align to 8-byte boundary.*/ /* sizeof() == 16 */ } __attribute__((__packed__)) INDEX_HEADER; /** * struct INDEX_ROOT - Attribute: Index root (0x90). * * NOTE: Always resident. * * This is followed by a sequence of index entries (INDEX_ENTRY structures) * as described by the index header. * * When a directory is small enough to fit inside the index root then this * is the only attribute describing the directory. When the directory is too * large to fit in the index root, on the other hand, two additional attributes * are present: an index allocation attribute, containing sub-nodes of the B+ * directory tree (see below), and a bitmap attribute, describing which virtual * cluster numbers (vcns) in the index allocation attribute are in use by an * index block. * * NOTE: The root directory (FILE_root) contains an entry for itself. Other * directories do not contain entries for themselves, though. */ typedef struct { /* 0*/ ATTR_TYPES type; /* Type of the indexed attribute. Is $FILE_NAME for directories, zero for view indexes. No other values allowed. */ /* 4*/ COLLATION_RULES collation_rule; /* Collation rule used to sort the index entries. If type is $FILE_NAME, this must be COLLATION_FILE_NAME. */ /* 8*/ le32 index_block_size; /* Size of index block in bytes (in the index allocation attribute). */ /* 12*/ s8 clusters_per_index_block; /* Size of index block in clusters (in the index allocation attribute), when an index block is >= than a cluster, otherwise sectors per index block. */ /* 13*/ u8 reserved[3]; /* Reserved/align to 8-byte boundary. */ /* 16*/ INDEX_HEADER index; /* Index header describing the following index entries. */ /* sizeof()= 32 bytes */ } __attribute__((__packed__)) INDEX_ROOT; /** * struct INDEX_BLOCK - Attribute: Index allocation (0xa0). * * NOTE: Always non-resident (doesn't make sense to be resident anyway!). * * This is an array of index blocks. Each index block starts with an * INDEX_BLOCK structure containing an index header, followed by a sequence of * index entries (INDEX_ENTRY structures), as described by the INDEX_HEADER. */ typedef struct { /* 0 NTFS_RECORD; -- Unfolded here as gcc doesn't like unnamed structs. */ NTFS_RECORD_TYPES magic;/* Magic is "INDX". */ le16 usa_ofs; /* See NTFS_RECORD definition. */ le16 usa_count; /* See NTFS_RECORD definition. */ /* 8*/ leLSN lsn; /* $LogFile sequence number of the last modification of this index block. */ /* 16*/ leVCN index_block_vcn; /* Virtual cluster number of the index block. */ /* 24*/ INDEX_HEADER index; /* Describes the following index entries. */ /* sizeof()= 40 (0x28) bytes */ /* * When creating the index block, we place the update sequence array at this * offset, i.e. before we start with the index entries. This also makes sense, * otherwise we could run into problems with the update sequence array * containing in itself the last two bytes of a sector which would mean that * multi sector transfer protection wouldn't work. As you can't protect data * by overwriting it since you then can't get it back... * When reading use the data from the ntfs record header. */ } __attribute__((__packed__)) INDEX_BLOCK; typedef INDEX_BLOCK INDEX_ALLOCATION; /** * struct REPARSE_INDEX_KEY - * * The system file FILE_Extend/$Reparse contains an index named $R listing * all reparse points on the volume. The index entry keys are as defined * below. Note, that there is no index data associated with the index entries. * * The index entries are sorted by the index key file_id. The collation rule is * COLLATION_NTOFS_ULONGS. FIXME: Verify whether the reparse_tag is not the * primary key / is not a key at all. (AIA) */ typedef struct { le32 reparse_tag; /* Reparse point type (inc. flags). */ leMFT_REF file_id; /* Mft record of the file containing the reparse point attribute. */ } __attribute__((__packed__)) REPARSE_INDEX_KEY; /** * enum QUOTA_FLAGS - Quota flags (32-bit). */ typedef enum { /* The user quota flags. Names explain meaning. */ QUOTA_FLAG_DEFAULT_LIMITS = const_cpu_to_le32(0x00000001), QUOTA_FLAG_LIMIT_REACHED = const_cpu_to_le32(0x00000002), QUOTA_FLAG_ID_DELETED = const_cpu_to_le32(0x00000004), QUOTA_FLAG_USER_MASK = const_cpu_to_le32(0x00000007), /* Bit mask for user quota flags. */ /* These flags are only present in the quota defaults index entry, i.e. in the entry where owner_id = QUOTA_DEFAULTS_ID. */ QUOTA_FLAG_TRACKING_ENABLED = const_cpu_to_le32(0x00000010), QUOTA_FLAG_ENFORCEMENT_ENABLED = const_cpu_to_le32(0x00000020), QUOTA_FLAG_TRACKING_REQUESTED = const_cpu_to_le32(0x00000040), QUOTA_FLAG_LOG_THRESHOLD = const_cpu_to_le32(0x00000080), QUOTA_FLAG_LOG_LIMIT = const_cpu_to_le32(0x00000100), QUOTA_FLAG_OUT_OF_DATE = const_cpu_to_le32(0x00000200), QUOTA_FLAG_CORRUPT = const_cpu_to_le32(0x00000400), QUOTA_FLAG_PENDING_DELETES = const_cpu_to_le32(0x00000800), } QUOTA_FLAGS; /** * struct QUOTA_CONTROL_ENTRY - * * The system file FILE_Extend/$Quota contains two indexes $O and $Q. Quotas * are on a per volume and per user basis. * * The $Q index contains one entry for each existing user_id on the volume. The * index key is the user_id of the user/group owning this quota control entry, * i.e. the key is the owner_id. The user_id of the owner of a file, i.e. the * owner_id, is found in the standard information attribute. The collation rule * for $Q is COLLATION_NTOFS_ULONG. * * The $O index contains one entry for each user/group who has been assigned * a quota on that volume. The index key holds the SID of the user_id the * entry belongs to, i.e. the owner_id. The collation rule for $O is * COLLATION_NTOFS_SID. * * The $O index entry data is the user_id of the user corresponding to the SID. * This user_id is used as an index into $Q to find the quota control entry * associated with the SID. * * The $Q index entry data is the quota control entry and is defined below. */ typedef struct { le32 version; /* Currently equals 2. */ QUOTA_FLAGS flags; /* Flags describing this quota entry. */ le64 bytes_used; /* How many bytes of the quota are in use. */ sle64 change_time; /* Last time this quota entry was changed. */ sle64 threshold; /* Soft quota (-1 if not limited). */ sle64 limit; /* Hard quota (-1 if not limited). */ sle64 exceeded_time; /* How long the soft quota has been exceeded. */ /* The below field is NOT present for the quota defaults entry. */ SID sid; /* The SID of the user/object associated with this quota entry. If this field is missing then the INDEX_ENTRY is padded to a multiple of 8 with zeros which are not counted in the data_length field. If the sid is present then this structure is padded with zeros to a multiple of 8 and the padding is counted in the INDEX_ENTRY's data_length. */ } __attribute__((__packed__)) QUOTA_CONTROL_ENTRY; /** * struct QUOTA_O_INDEX_DATA - */ typedef struct { le32 owner_id; le32 unknown; /* Always 32. Seems to be padding and it's not counted in the INDEX_ENTRY's data_length. This field shouldn't be really here. */ } __attribute__((__packed__)) QUOTA_O_INDEX_DATA; /** * enum PREDEFINED_OWNER_IDS - Predefined owner_id values (32-bit). */ typedef enum { QUOTA_INVALID_ID = const_cpu_to_le32(0x00000000), QUOTA_DEFAULTS_ID = const_cpu_to_le32(0x00000001), QUOTA_FIRST_USER_ID = const_cpu_to_le32(0x00000100), } PREDEFINED_OWNER_IDS; /** * enum INDEX_ENTRY_FLAGS - Index entry flags (16-bit). */ typedef enum { INDEX_ENTRY_NODE = const_cpu_to_le16(1), /* This entry contains a sub-node, i.e. a reference to an index block in form of a virtual cluster number (see below). */ INDEX_ENTRY_END = const_cpu_to_le16(2), /* This signifies the last entry in an index block. The index entry does not represent a file but it can point to a sub-node. */ INDEX_ENTRY_SPACE_FILLER = 0xffff, /* Just to force 16-bit width. */ } __attribute__((__packed__)) INDEX_ENTRY_FLAGS; /** * struct INDEX_ENTRY_HEADER - This the index entry header (see below). * * ========================================================== * !!!!! SEE DESCRIPTION OF THE FIELDS AT INDEX_ENTRY !!!!! * ========================================================== */ typedef struct { /* 0*/ union { leMFT_REF indexed_file; struct { le16 data_offset; le16 data_length; le32 reservedV; } __attribute__((__packed__)); } __attribute__((__packed__)); /* 8*/ le16 length; /* 10*/ le16 key_length; /* 12*/ INDEX_ENTRY_FLAGS flags; /* 14*/ le16 reserved; /* sizeof() = 16 bytes */ } __attribute__((__packed__)) INDEX_ENTRY_HEADER; /** * struct INDEX_ENTRY - This is an index entry. * * A sequence of such entries follows each INDEX_HEADER structure. Together * they make up a complete index. The index follows either an index root * attribute or an index allocation attribute. * * NOTE: Before NTFS 3.0 only filename attributes were indexed. */ typedef struct { /* 0 INDEX_ENTRY_HEADER; -- Unfolded here as gcc dislikes unnamed structs. */ union { /* Only valid when INDEX_ENTRY_END is not set. */ leMFT_REF indexed_file; /* The mft reference of the file described by this index entry. Used for directory indexes. */ struct { /* Used for views/indexes to find the entry's data. */ le16 data_offset; /* Data byte offset from this INDEX_ENTRY. Follows the index key. */ le16 data_length; /* Data length in bytes. */ le32 reservedV; /* Reserved (zero). */ } __attribute__((__packed__)); } __attribute__((__packed__)); /* 8*/ le16 length; /* Byte size of this index entry, multiple of 8-bytes. Size includes INDEX_ENTRY_HEADER and the optional subnode VCN. See below. */ /* 10*/ le16 key_length; /* Byte size of the key value, which is in the index entry. It follows field reserved. Not multiple of 8-bytes. */ /* 12*/ INDEX_ENTRY_FLAGS ie_flags; /* Bit field of INDEX_ENTRY_* flags. */ /* 14*/ le16 reserved; /* Reserved/align to 8-byte boundary. */ /* End of INDEX_ENTRY_HEADER */ /* 16*/ union { /* The key of the indexed attribute. NOTE: Only present if INDEX_ENTRY_END bit in flags is not set. NOTE: On NTFS versions before 3.0 the only valid key is the FILE_NAME_ATTR. On NTFS 3.0+ the following additional index keys are defined: */ FILE_NAME_ATTR file_name;/* $I30 index in directories. */ SII_INDEX_KEY sii; /* $SII index in $Secure. */ SDH_INDEX_KEY sdh; /* $SDH index in $Secure. */ GUID object_id; /* $O index in FILE_Extend/$ObjId: The object_id of the mft record found in the data part of the index. */ REPARSE_INDEX_KEY reparse; /* $R index in FILE_Extend/$Reparse. */ SID sid; /* $O index in FILE_Extend/$Quota: SID of the owner of the user_id. */ le32 owner_id; /* $Q index in FILE_Extend/$Quota: user_id of the owner of the quota control entry in the data part of the index. */ } __attribute__((__packed__)) key; /* The (optional) index data is inserted here when creating. leVCN vcn; If INDEX_ENTRY_NODE bit in ie_flags is set, the last eight bytes of this index entry contain the virtual cluster number of the index block that holds the entries immediately preceding the current entry. If the key_length is zero, then the vcn immediately follows the INDEX_ENTRY_HEADER. The address of the vcn of "ie" INDEX_ENTRY is given by (char*)ie + le16_to_cpu(ie->length) - sizeof(VCN) */ } __attribute__((__packed__)) INDEX_ENTRY; /** * struct BITMAP_ATTR - Attribute: Bitmap (0xb0). * * Contains an array of bits (aka a bitfield). * * When used in conjunction with the index allocation attribute, each bit * corresponds to one index block within the index allocation attribute. Thus * the number of bits in the bitmap * index block size / cluster size is the * number of clusters in the index allocation attribute. */ typedef struct { u8 bitmap[0]; /* Array of bits. */ } __attribute__((__packed__)) BITMAP_ATTR; /** * enum PREDEFINED_REPARSE_TAGS - * * The reparse point tag defines the type of the reparse point. It also * includes several flags, which further describe the reparse point. * * The reparse point tag is an unsigned 32-bit value divided in three parts: * * 1. The least significant 16 bits (i.e. bits 0 to 15) specify the type of * the reparse point. * 2. The 12 bits after this (i.e. bits 16 to 27) are reserved for future use. * 3. The most significant four bits are flags describing the reparse point. * They are defined as follows: * bit 28: Directory bit. If set, the directory is not a surrogate * and can be used the usual way. * bit 29: Name surrogate bit. If set, the filename is an alias for * another object in the system. * bit 30: High-latency bit. If set, accessing the first byte of data will * be slow. (E.g. the data is stored on a tape drive.) * bit 31: Microsoft bit. If set, the tag is owned by Microsoft. User * defined tags have to use zero here. * 4. Moreover, on Windows 10 : * Some flags may be used in bits 12 to 15 to further describe the * reparse point. */ typedef enum { IO_REPARSE_TAG_DIRECTORY = const_cpu_to_le32(0x10000000), IO_REPARSE_TAG_IS_ALIAS = const_cpu_to_le32(0x20000000), IO_REPARSE_TAG_IS_HIGH_LATENCY = const_cpu_to_le32(0x40000000), IO_REPARSE_TAG_IS_MICROSOFT = const_cpu_to_le32(0x80000000), IO_REPARSE_TAG_RESERVED_ZERO = const_cpu_to_le32(0x00000000), IO_REPARSE_TAG_RESERVED_ONE = const_cpu_to_le32(0x00000001), IO_REPARSE_TAG_RESERVED_RANGE = const_cpu_to_le32(0x00000001), IO_REPARSE_TAG_CSV = const_cpu_to_le32(0x80000009), IO_REPARSE_TAG_DEDUP = const_cpu_to_le32(0x80000013), IO_REPARSE_TAG_DFS = const_cpu_to_le32(0x8000000A), IO_REPARSE_TAG_DFSR = const_cpu_to_le32(0x80000012), IO_REPARSE_TAG_HSM = const_cpu_to_le32(0xC0000004), IO_REPARSE_TAG_HSM2 = const_cpu_to_le32(0x80000006), IO_REPARSE_TAG_MOUNT_POINT = const_cpu_to_le32(0xA0000003), IO_REPARSE_TAG_NFS = const_cpu_to_le32(0x80000014), IO_REPARSE_TAG_SIS = const_cpu_to_le32(0x80000007), IO_REPARSE_TAG_SYMLINK = const_cpu_to_le32(0xA000000C), IO_REPARSE_TAG_WIM = const_cpu_to_le32(0x80000008), IO_REPARSE_TAG_DFM = const_cpu_to_le32(0x80000016), IO_REPARSE_TAG_WOF = const_cpu_to_le32(0x80000017), IO_REPARSE_TAG_WCI = const_cpu_to_le32(0x80000018), IO_REPARSE_TAG_CLOUD = const_cpu_to_le32(0x9000001A), IO_REPARSE_TAG_APPEXECLINK = const_cpu_to_le32(0x8000001B), IO_REPARSE_TAG_GVFS = const_cpu_to_le32(0x9000001C), IO_REPARSE_TAG_LX_SYMLINK = const_cpu_to_le32(0xA000001D), IO_REPARSE_TAG_AF_UNIX = const_cpu_to_le32(0x80000023), IO_REPARSE_TAG_LX_FIFO = const_cpu_to_le32(0x80000024), IO_REPARSE_TAG_LX_CHR = const_cpu_to_le32(0x80000025), IO_REPARSE_TAG_LX_BLK = const_cpu_to_le32(0x80000026), IO_REPARSE_TAG_VALID_VALUES = const_cpu_to_le32(0xf000ffff), IO_REPARSE_PLUGIN_SELECT = const_cpu_to_le32(0xffff0fff), } PREDEFINED_REPARSE_TAGS; /** * struct REPARSE_POINT - Attribute: Reparse point (0xc0). * * NOTE: Can be resident or non-resident. */ typedef struct { le32 reparse_tag; /* Reparse point type (inc. flags). */ le16 reparse_data_length; /* Byte size of reparse data. */ le16 reserved; /* Align to 8-byte boundary. */ u8 reparse_data[0]; /* Meaning depends on reparse_tag. */ } __attribute__((__packed__)) REPARSE_POINT; /** * struct EA_INFORMATION - Attribute: Extended attribute information (0xd0). * * NOTE: Always resident. */ typedef struct { le16 ea_length; /* Byte size of the packed extended attributes. */ le16 need_ea_count; /* The number of extended attributes which have the NEED_EA bit set. */ le32 ea_query_length; /* Byte size of the buffer required to query the extended attributes when calling ZwQueryEaFile() in Windows NT/2k. I.e. the byte size of the unpacked extended attributes. */ } __attribute__((__packed__)) EA_INFORMATION; /** * enum EA_FLAGS - Extended attribute flags (8-bit). */ typedef enum { NEED_EA = 0x80, /* Indicate that the file to which the EA belongs cannot be interpreted without understanding the associated extended attributes. */ } __attribute__((__packed__)) EA_FLAGS; /** * struct EA_ATTR - Attribute: Extended attribute (EA) (0xe0). * * Like the attribute list and the index buffer list, the EA attribute value is * a sequence of EA_ATTR variable length records. * * FIXME: It appears weird that the EA name is not Unicode. Is it true? * FIXME: It seems that name is always uppercased. Is it true? */ typedef struct { le32 next_entry_offset; /* Offset to the next EA_ATTR. */ EA_FLAGS flags; /* Flags describing the EA. */ u8 name_length; /* Length of the name of the extended attribute in bytes. */ le16 value_length; /* Byte size of the EA's value. */ u8 name[0]; /* Name of the EA. */ u8 value[0]; /* The value of the EA. Immediately follows the name. */ } __attribute__((__packed__)) EA_ATTR; /** * struct PROPERTY_SET - Attribute: Property set (0xf0). * * Intended to support Native Structure Storage (NSS) - a feature removed from * NTFS 3.0 during beta testing. */ typedef struct { /* Irrelevant as feature unused. */ } __attribute__((__packed__)) PROPERTY_SET; /** * struct LOGGED_UTILITY_STREAM - Attribute: Logged utility stream (0x100). * * NOTE: Can be resident or non-resident. * * Operations on this attribute are logged to the journal ($LogFile) like * normal metadata changes. * * Used by the Encrypting File System (EFS). All encrypted files have this * attribute with the name $EFS. See below for the relevant structures. */ typedef struct { /* Can be anything the creator chooses. */ } __attribute__((__packed__)) LOGGED_UTILITY_STREAM; /* * $EFS Data Structure: * * The following information is about the data structures that are contained * inside a logged utility stream (0x100) with a name of "$EFS". * * The stream starts with an instance of EFS_ATTR_HEADER. * * Next, at offsets offset_to_ddf_array and offset_to_drf_array (unless any of * them is 0) there is a EFS_DF_ARRAY_HEADER immediately followed by a sequence * of multiple data decryption/recovery fields. * * Each data decryption/recovery field starts with a EFS_DF_HEADER and the next * one (if it exists) can be found by adding EFS_DF_HEADER->df_length bytes to * the offset of the beginning of the current EFS_DF_HEADER. * * The data decryption/recovery field contains an EFS_DF_CERTIFICATE_HEADER, a * SID, an optional GUID, an optional container name, a non-optional user name, * and the encrypted FEK. * * Note all the below are best guesses so may have mistakes/inaccuracies. * Corrections/clarifications/additions are always welcome! * * Ntfs.sys takes an EFS value length of <= 0x54 or > 0x40000 to BSOD, i.e. it * is invalid. */ /** * struct EFS_ATTR_HEADER - "$EFS" header. * * The header of the Logged utility stream (0x100) attribute named "$EFS". */ typedef struct { /* 0*/ le32 length; /* Length of EFS attribute in bytes. */ le32 state; /* Always 0? */ le32 version; /* Efs version. Always 2? */ le32 crypto_api_version; /* Always 0? */ /* 16*/ u8 unknown4[16]; /* MD5 hash of decrypted FEK? This field is created with a call to UuidCreate() so is unlikely to be an MD5 hash and is more likely to be GUID of this encrytped file or something like that. */ /* 32*/ u8 unknown5[16]; /* MD5 hash of DDFs? */ /* 48*/ u8 unknown6[16]; /* MD5 hash of DRFs? */ /* 64*/ le32 offset_to_ddf_array;/* Offset in bytes to the array of data decryption fields (DDF), see below. Zero if no DDFs are present. */ le32 offset_to_drf_array;/* Offset in bytes to the array of data recovery fields (DRF), see below. Zero if no DRFs are present. */ le32 reserved; /* Reserved. */ } __attribute__((__packed__)) EFS_ATTR_HEADER; /** * struct EFS_DF_ARRAY_HEADER - */ typedef struct { le32 df_count; /* Number of data decryption/recovery fields in the array. */ } __attribute__((__packed__)) EFS_DF_ARRAY_HEADER; /** * struct EFS_DF_HEADER - */ typedef struct { /* 0*/ le32 df_length; /* Length of this data decryption/recovery field in bytes. */ le32 cred_header_offset; /* Offset in bytes to the credential header. */ le32 fek_size; /* Size in bytes of the encrypted file encryption key (FEK). */ le32 fek_offset; /* Offset in bytes to the FEK from the start of the data decryption/recovery field. */ /* 16*/ le32 unknown1; /* always 0? Might be just padding. */ } __attribute__((__packed__)) EFS_DF_HEADER; /** * struct EFS_DF_CREDENTIAL_HEADER - */ typedef struct { /* 0*/ le32 cred_length; /* Length of this credential in bytes. */ le32 sid_offset; /* Offset in bytes to the user's sid from start of this structure. Zero if no sid is present. */ /* 8*/ le32 type; /* Type of this credential: 1 = CryptoAPI container. 2 = Unexpected type. 3 = Certificate thumbprint. other = Unknown type. */ union { /* CryptoAPI container. */ struct { /* 12*/ le32 container_name_offset; /* Offset in bytes to the name of the container from start of this structure (may not be zero). */ /* 16*/ le32 provider_name_offset; /* Offset in bytes to the name of the provider from start of this structure (may not be zero). */ le32 public_key_blob_offset; /* Offset in bytes to the public key blob from start of this structure. */ /* 24*/ le32 public_key_blob_size; /* Size in bytes of public key blob. */ } __attribute__((__packed__)); /* Certificate thumbprint. */ struct { /* 12*/ le32 cert_thumbprint_header_size; /* Size in bytes of the header of the certificate thumbprint. */ /* 16*/ le32 cert_thumbprint_header_offset; /* Offset in bytes to the header of the certificate thumbprint from start of this structure. */ le32 unknown1; /* Always 0? Might be padding... */ le32 unknown2; /* Always 0? Might be padding... */ } __attribute__((__packed__)); } __attribute__((__packed__)); } __attribute__((__packed__)) EFS_DF_CREDENTIAL_HEADER; typedef EFS_DF_CREDENTIAL_HEADER EFS_DF_CRED_HEADER; /** * struct EFS_DF_CERTIFICATE_THUMBPRINT_HEADER - */ typedef struct { /* 0*/ le32 thumbprint_offset; /* Offset in bytes to the thumbprint. */ le32 thumbprint_size; /* Size of thumbprint in bytes. */ /* 8*/ le32 container_name_offset; /* Offset in bytes to the name of the container from start of this structure or 0 if no name present. */ le32 provider_name_offset; /* Offset in bytes to the name of the cryptographic provider from start of this structure or 0 if no name present. */ /* 16*/ le32 user_name_offset; /* Offset in bytes to the user name from start of this structure or 0 if no user name present. (This is also known as lpDisplayInformation.) */ } __attribute__((__packed__)) EFS_DF_CERTIFICATE_THUMBPRINT_HEADER; typedef EFS_DF_CERTIFICATE_THUMBPRINT_HEADER EFS_DF_CERT_THUMBPRINT_HEADER; typedef enum { INTX_SYMBOLIC_LINK = const_cpu_to_le64(0x014B4E4C78746E49ULL), /* "IntxLNK\1" */ INTX_CHARACTER_DEVICE = const_cpu_to_le64(0x0052484378746E49ULL), /* "IntxCHR\0" */ INTX_BLOCK_DEVICE = const_cpu_to_le64(0x004B4C4278746E49ULL), /* "IntxBLK\0" */ } INTX_FILE_TYPES; typedef struct { INTX_FILE_TYPES magic; /* Intx file magic. */ union { /* For character and block devices. */ struct { le64 major; /* Major device number. */ le64 minor; /* Minor device number. */ void *device_end[0]; /* Marker for offsetof(). */ } __attribute__((__packed__)); /* For symbolic links. */ ntfschar target[0]; } __attribute__((__packed__)); } __attribute__((__packed__)) INTX_FILE; #endif /* defined _NTFS_LAYOUT_H */ ntfs-3g-2026.2.25/include/ntfs-3g/Makefile.am0000664000175000017500000000117215152260173013741 MAINTAINERCLEANFILES = $(srcdir)/Makefile.in headers = \ acls.h \ attrib.h \ attrlist.h \ bitmap.h \ bootsect.h \ cache.h \ collate.h \ compat.h \ compress.h \ debug.h \ device.h \ device_io.h \ dir.h \ ea.h \ efs.h \ endians.h \ index.h \ inode.h \ ioctl.h \ layout.h \ lcnalloc.h \ logfile.h \ logging.h \ mft.h \ misc.h \ mst.h \ ntfstime.h \ object_id.h \ param.h \ plugin.h \ realpath.h \ reparse.h \ runlist.h \ security.h \ support.h \ types.h \ unistr.h \ volume.h \ xattrs.h if INSTALL_LIBRARY ntfs3ginclude_HEADERS = $(headers) else noinst_HEADERS = $(headers) endif ntfs-3g-2026.2.25/include/ntfs-3g/ntfstime.h0000664000175000017500000000746415152260173013721 /* * ntfstime.h - NTFS time related functions. Originated from the Linux-NTFS project. * * Copyright (c) 2005 Anton Altaparmakov * Copyright (c) 2005 Yura Pakhuchiy * Copyright (c) 2010 Jean-Pierre Andre * * This program/include file 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/include file 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_NTFSTIME_H #define _NTFS_NTFSTIME_H #ifdef HAVE_TIME_H #include #endif #ifdef HAVE_SYS_STAT_H #include #endif #ifdef HAVE_GETTIMEOFDAY #include #endif #include "types.h" /* * assume "struct timespec" is not defined if st_mtime is not defined */ #if !defined(st_mtime) & !defined(__timespec_defined) struct timespec { time_t tv_sec; long tv_nsec; } ; #endif /* * There are four times more conversions of internal representation * to ntfs representation than any other conversion, so the most * efficient internal representation is ntfs representation * (with low endianness) */ typedef sle64 ntfs_time; #define NTFS_TIME_OFFSET ((s64)(369 * 365 + 89) * 24 * 3600 * 10000000) /** * ntfs2timespec - Convert an NTFS time to Unix time * @ntfs_time: An NTFS time in 100ns units since 1601 * * NTFS stores times as the number of 100ns intervals since January 1st 1601 at * 00:00 UTC. This system will not suffer from Y2K problems until ~57000AD. * * Return: A Unix time (number of seconds since 1970, and nanoseconds) */ static __inline__ struct timespec ntfs2timespec(ntfs_time ntfstime) { struct timespec spec; s64 cputime; cputime = sle64_to_cpu(ntfstime); spec.tv_sec = (cputime - (NTFS_TIME_OFFSET)) / 10000000; spec.tv_nsec = (cputime - (NTFS_TIME_OFFSET) - (s64)spec.tv_sec*10000000)*100; /* force zero nsec for overflowing dates */ if ((spec.tv_nsec < 0) || (spec.tv_nsec > 999999999)) spec.tv_nsec = 0; return (spec); } /** * timespec2ntfs - Convert Linux time to NTFS time * @utc_time: Linux time to convert to NTFS * * Convert the Linux time @utc_time to its corresponding NTFS time. * * Linux stores time in a long at present and measures it as the number of * 1-second intervals since 1st January 1970, 00:00:00 UTC * with a separated non-negative nanosecond value * * NTFS uses Microsoft's standard time format which is stored in a sle64 and is * measured as the number of 100 nano-second intervals since 1st January 1601, * 00:00:00 UTC. * * Return: An NTFS time (100ns units since Jan 1601) */ static __inline__ ntfs_time timespec2ntfs(struct timespec spec) { s64 units; units = (s64)spec.tv_sec * 10000000 + NTFS_TIME_OFFSET + spec.tv_nsec/100; return (cpu_to_sle64(units)); } /* * Return the current time in ntfs format */ static __inline__ ntfs_time ntfs_current_time(void) { struct timespec now; #if defined(HAVE_CLOCK_GETTIME) || defined(HAVE_SYS_CLOCK_GETTIME) clock_gettime(CLOCK_REALTIME, &now); #elif defined(HAVE_GETTIMEOFDAY) struct timeval microseconds; gettimeofday(µseconds, (struct timezone*)NULL); now.tv_sec = microseconds.tv_sec; now.tv_nsec = microseconds.tv_usec*1000; #else now.tv_sec = time((time_t*)NULL); now.tv_nsec = 0; #endif return (timespec2ntfs(now)); } #endif /* _NTFS_NTFSTIME_H */ ntfs-3g-2026.2.25/include/ntfs-3g/bitmap.h0000664000175000017500000000570715152260173013342 /* * bitmap.h - Exports for bitmap handling. Originated from the Linux-NTFS project. * * Copyright (c) 2000-2004 Anton Altaparmakov * Copyright (c) 2004-2005 Richard Russon * * This program/include file 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/include file 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_BITMAP_H #define _NTFS_BITMAP_H #include "types.h" #include "attrib.h" /* * NOTES: * * - Operations are 8-bit only to ensure the functions work both on little * and big endian machines! So don't make them 32-bit ops! * - bitmap starts at bit = 0 and ends at bit = bitmap size - 1. * - _Caller_ has to make sure that the bit to operate on is less than the * size of the bitmap. */ extern void ntfs_bit_set(u8 *bitmap, const u64 bit, const u8 new_value); extern char ntfs_bit_get(const u8 *bitmap, const u64 bit); extern char ntfs_bit_get_and_set(u8 *bitmap, const u64 bit, const u8 new_value); extern int ntfs_bitmap_set_run(ntfs_attr *na, s64 start_bit, s64 count); extern int ntfs_bitmap_clear_run(ntfs_attr *na, s64 start_bit, s64 count); /** * ntfs_bitmap_set_bit - set a bit in a bitmap * @na: attribute containing the bitmap * @bit: bit to set * * Set the @bit in the bitmap described by the attribute @na. * * On success return 0 and on error return -1 with errno set to the error code. */ static __inline__ int ntfs_bitmap_set_bit(ntfs_attr *na, s64 bit) { return ntfs_bitmap_set_run(na, bit, 1); } /** * ntfs_bitmap_clear_bit - clear a bit in a bitmap * @na: attribute containing the bitmap * @bit: bit to clear * * Clear @bit in the bitmap described by the attribute @na. * * On success return 0 and on error return -1 with errno set to the error code. */ static __inline__ int ntfs_bitmap_clear_bit(ntfs_attr *na, s64 bit) { return ntfs_bitmap_clear_run(na, bit, 1); } /* * rol32 - rotate a 32-bit value left * * @word: value to rotate * @shift: bits to roll */ static __inline__ u32 ntfs_rol32(u32 word, unsigned int shift) { return (word << shift) | (word >> (32 - shift)); } /* * ror32 - rotate a 32-bit value right * * @word: value to rotate * @shift: bits to roll */ static __inline__ u32 ntfs_ror32(u32 word, unsigned int shift) { return (word >> shift) | (word << (32 - shift)); } #endif /* defined _NTFS_BITMAP_H */ ntfs-3g-2026.2.25/include/ntfs-3g/compat.h0000664000175000017500000000462315152260173013345 /* * compat.h - Tweaks for compatibility with non-Linux systems. * * Copyright (c) 2002 Richard Russon * Copyright (c) 2002-2004 Anton Altaparmakov * Copyright (c) 2008-2009 Szabolcs Szakacsits * Copyright (c) 2019 Jean-Pierre Andre * * This program/include file 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/include file 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_COMPAT_H #define _NTFS_COMPAT_H #ifdef HAVE_CONFIG_H #include "config.h" #endif #ifdef HAVE_SYS_PARAM_H #include #endif #include /* ENODATA */ #ifndef ENODATA #define ENODATA ENOENT #endif #ifndef ELIBBAD #define ELIBBAD ENOEXEC #endif #ifndef ELIBACC #define ELIBACC ENOENT #endif /* xattr APIs in macOS differs from Linux ones in that they expect the special * error code ENOATTR to be returned when an attribute cannot be found. So * define NTFS_NOXATTR_ERRNO to the appropriate "no xattr found" errno value for * the platform. */ #if defined(__APPLE__) || defined(__DARWIN__) #define NTFS_NOXATTR_ERRNO ENOATTR #else #define NTFS_NOXATTR_ERRNO ENODATA #endif #ifndef PATH_MAX #define PATH_MAX 4096 #endif #ifndef HAVE_FFS extern int ffs(int i); #endif /* HAVE_FFS */ #ifndef HAVE_DAEMON extern int daemon(int nochdir, int noclose); #endif /* HAVE_DAEMON */ #ifndef HAVE_STRSEP extern char *strsep(char **stringp, const char *delim); #endif /* HAVE_STRSEP */ #ifdef WINDOWS #define HAVE_STDIO_H /* mimic config.h */ #define HAVE_STDARG_H #define atoll _atoi64 #define fdatasync commit #define __inline__ inline #define __attribute__(X) /*nothing*/ #else /* !defined WINDOWS */ #ifndef O_BINARY #define O_BINARY 0 /* unix is binary by default */ #endif #endif /* defined WINDOWS */ #endif /* defined _NTFS_COMPAT_H */ ntfs-3g-2026.2.25/include/ntfs-3g/mft.h0000664000175000017500000001137015152260173012645 /* * mft.h - Exports for MFT record handling. Originated from the Linux-NTFS project. * * Copyright (c) 2000-2002 Anton Altaparmakov * Copyright (c) 2004-2005 Richard Russon * Copyright (c) 2006-2008 Szabolcs Szakacsits * * This program/include file 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/include file 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_MFT_H #define _NTFS_MFT_H #include "volume.h" #include "inode.h" #include "layout.h" #include "logging.h" extern int ntfs_mft_records_read(const ntfs_volume *vol, const MFT_REF mref, const s64 count, MFT_RECORD *b); /** * ntfs_mft_record_read - read a record from the mft * @vol: volume to read from * @mref: mft record number to read * @b: output data buffer * * Read the mft record specified by @mref from volume @vol into buffer @b. * Return 0 on success or -1 on error, with errno set to the error code. * * The read mft record is mst deprotected and is hence ready to use. The caller * should check the record with is_baad_record() in case mst deprotection * failed. * * NOTE: @b has to be at least of size vol->mft_record_size. */ static __inline__ int ntfs_mft_record_read(const ntfs_volume *vol, const MFT_REF mref, MFT_RECORD *b) { int ret; ntfs_log_enter("Entering for inode %lld\n", (long long)MREF(mref)); ret = ntfs_mft_records_read(vol, mref, 1, b); ntfs_log_leave("\n"); return ret; } extern int ntfs_mft_record_check(const ntfs_volume *vol, const MFT_REF mref, MFT_RECORD *m); extern int ntfs_file_record_read(const ntfs_volume *vol, const MFT_REF mref, MFT_RECORD **mrec, ATTR_RECORD **attr); extern int ntfs_mft_records_write(const ntfs_volume *vol, const MFT_REF mref, const s64 count, MFT_RECORD *b); /** * ntfs_mft_record_write - write an mft record to disk * @vol: volume to write to * @mref: mft record number to write * @b: data buffer containing the mft record to write * * Write the mft record specified by @mref from buffer @b to volume @vol. * Return 0 on success or -1 on error, with errno set to the error code. * * Before the mft record is written, it is mst protected. After the write, it * is deprotected again, thus resulting in an increase in the update sequence * number inside the buffer @b. * * NOTE: @b has to be at least of size vol->mft_record_size. */ static __inline__ int ntfs_mft_record_write(const ntfs_volume *vol, const MFT_REF mref, MFT_RECORD *b) { int ret; ntfs_log_enter("Entering for inode %lld\n", (long long)MREF(mref)); ret = ntfs_mft_records_write(vol, mref, 1, b); ntfs_log_leave("\n"); return ret; } /** * ntfs_mft_record_get_data_size - return number of bytes used in mft record @b * @m: mft record to get the data size of * * Takes the mft record @m and returns the number of bytes used in the record * or 0 on error (i.e. @m is not a valid mft record). Zero is not a valid size * for an mft record as it at least has to have the MFT_RECORD itself and a * zero length attribute of type AT_END, thus making the minimum size 56 bytes. * * Aside: The size is independent of NTFS versions 1.x/3.x because the 8-byte * alignment of the first attribute mask the difference in MFT_RECORD size * between NTFS 1.x and 3.x. Also, you would expect every mft record to * contain an update sequence array as well but that could in theory be * non-existent (don't know if Windows' NTFS driver/chkdsk wouldn't view this * as corruption in itself though). */ static __inline__ u32 ntfs_mft_record_get_data_size(const MFT_RECORD *m) { if (!m || !ntfs_is_mft_record(m->magic)) return 0; /* Get the number of used bytes and return it. */ return le32_to_cpu(m->bytes_in_use); } extern int ntfs_mft_record_layout(const ntfs_volume *vol, const MFT_REF mref, MFT_RECORD *mrec); extern int ntfs_mft_record_format(const ntfs_volume *vol, const MFT_REF mref); extern ntfs_inode *ntfs_mft_record_alloc(ntfs_volume *vol, ntfs_inode *base_ni); extern ntfs_inode *ntfs_mft_rec_alloc(ntfs_volume *vol, BOOL mft_data); extern int ntfs_mft_record_free(ntfs_volume *vol, ntfs_inode *ni); extern int ntfs_mft_usn_dec(MFT_RECORD *mrec); #endif /* defined _NTFS_MFT_H */ ntfs-3g-2026.2.25/include/ntfs-3g/ea.h0000664000175000017500000000230415152260173012441 /* * * Copyright (c) 2014-2021 Jean-Pierre Andre * */ /* * 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 EA_H #define EA_H int ntfs_ea_check_wsldev(ntfs_inode *ni, dev_t *rdevp); int ntfs_ea_set_wsl_not_symlink(ntfs_inode *ni, mode_t mode, dev_t dev); int ntfs_get_ntfs_ea(ntfs_inode *ni, char *value, size_t size); int ntfs_set_ntfs_ea(ntfs_inode *ni, const char *value, size_t size, int flags); int ntfs_remove_ntfs_ea(ntfs_inode *ni); #endif /* EA_H */ ntfs-3g-2026.2.25/include/ntfs-3g/lcnalloc.h0000664000175000017500000000341615152260173013650 /* * lcnalloc.h - Exports for cluster (de)allocation. Originated from the Linux-NTFS * project. * * Copyright (c) 2002 Anton Altaparmakov * Copyright (c) 2004 Yura Pakhuchiy * * This program/include file 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/include file 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_LCNALLOC_H #define _NTFS_LCNALLOC_H #include "types.h" #include "runlist.h" #include "volume.h" /** * enum NTFS_CLUSTER_ALLOCATION_ZONES - */ typedef enum { FIRST_ZONE = 0, /* For sanity checking. */ MFT_ZONE = 0, /* Allocate from $MFT zone. */ DATA_ZONE = 1, /* Allocate from $DATA zone. */ LAST_ZONE = 1, /* For sanity checking. */ } NTFS_CLUSTER_ALLOCATION_ZONES; extern runlist *ntfs_cluster_alloc(ntfs_volume *vol, VCN start_vcn, s64 count, LCN start_lcn, const NTFS_CLUSTER_ALLOCATION_ZONES zone); extern int ntfs_cluster_free_from_rl(ntfs_volume *vol, runlist *rl); extern int ntfs_cluster_free_basic(ntfs_volume *vol, s64 lcn, s64 count); extern int ntfs_cluster_free(ntfs_volume *vol, ntfs_attr *na, VCN start_vcn, s64 count); #endif /* defined _NTFS_LCNALLOC_H */ ntfs-3g-2026.2.25/include/ntfs-3g/compress.h0000664000175000017500000000270715152260173013716 /* * compress.h - Exports for compressed attribute handling. * Originated from the Linux-NTFS project. * * Copyright (c) 2004 Anton Altaparmakov * * This program/include file 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/include file 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_COMPRESS_H #define _NTFS_COMPRESS_H #include "types.h" #include "attrib.h" extern s64 ntfs_compressed_attr_pread(ntfs_attr *na, s64 pos, s64 count, void *b); extern s64 ntfs_compressed_pwrite(ntfs_attr *na, runlist_element *brl, s64 wpos, s64 offs, s64 to_write, s64 rounded, const void *b, int compressed_part, VCN *update_from); extern int ntfs_compressed_close(ntfs_attr *na, runlist_element *brl, s64 offs, VCN *update_from); #endif /* defined _NTFS_COMPRESS_H */ ntfs-3g-2026.2.25/include/ntfs-3g/object_id.h0000664000175000017500000000223215152260173013776 /* * * Copyright (c) 2008 Jean-Pierre Andre * */ /* * 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 OBJECT_ID_H #define OBJECT_ID_H int ntfs_get_ntfs_object_id(ntfs_inode *ni, char *value, size_t size); int ntfs_set_ntfs_object_id(ntfs_inode *ni, const char *value, size_t size, int flags); int ntfs_remove_ntfs_object_id(ntfs_inode *ni); int ntfs_delete_object_id_index(ntfs_inode *ni); #endif /* OBJECT_ID_H */ ntfs-3g-2026.2.25/include/ntfs-3g/realpath.h0000664000175000017500000000071315152260173013656 /* * realpath.h - realpath() aware of device mapper */ #ifndef REALPATH_H #define REALPATH_H #ifdef HAVE_CONFIG_H #include "config.h" #endif #ifdef HAVE_REALPATH #define ntfs_realpath realpath #else extern char *ntfs_realpath(const char *path, char *resolved_path); #endif #ifdef linux extern char *ntfs_realpath_canonicalize(const char *path, char *resolved_path); #else #define ntfs_realpath_canonicalize ntfs_realpath #endif #endif /* REALPATH_H */ ntfs-3g-2026.2.25/include/ntfs-3g/index.h0000664000175000017500000001420215152260173013163 /* * index.h - Defines for NTFS index handling. Originated from the Linux-NTFS project. * * Copyright (c) 2004 Anton Altaparmakov * Copyright (c) 2004-2005 Richard Russon * Copyright (c) 2005 Yura Pakhuchiy * Copyright (c) 2006-2008 Szabolcs Szakacsits * * This program/include file 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/include file 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_INDEX_H #define _NTFS_INDEX_H /* Convenience macros to test the versions of gcc. * Use them like this: * #if __GNUC_PREREQ (2,8) * ... code requiring gcc 2.8 or later ... * #endif * Note - they won't work for gcc1 or glibc1, since the _MINOR macros * were not defined then. */ #ifndef __GNUC_PREREQ # if defined __GNUC__ && defined __GNUC_MINOR__ # define __GNUC_PREREQ(maj, min) \ ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min)) # else # define __GNUC_PREREQ(maj, min) 0 # endif #endif /* allows us to warn about unused results of certain function calls */ #ifndef __attribute_warn_unused_result__ # if __GNUC_PREREQ (3,4) # define __attribute_warn_unused_result__ \ __attribute__ ((__warn_unused_result__)) # else # define __attribute_warn_unused_result__ /* empty */ # endif #endif #include "attrib.h" #include "types.h" #include "layout.h" #include "inode.h" #include "mft.h" #define VCN_INDEX_ROOT_PARENT ((VCN)-2) #define MAX_PARENT_VCN 32 typedef int (*COLLATE)(ntfs_volume *vol, const void *data1, int len1, const void *data2, int len2); /** * struct ntfs_index_context - * @ni: inode containing the @entry described by this context * @name: name of the index described by this context * @name_len: length of the index name * @entry: index entry (points into @ir or @ia) * @data: index entry data (points into @entry) * @data_len: length in bytes of @data * @is_in_root: TRUE if @entry is in @ir or FALSE if it is in @ia * @ir: index root if @is_in_root or NULL otherwise * @actx: attribute search context if in root or NULL otherwise * @ia: index block if @is_in_root is FALSE or NULL otherwise * @ia_na: opened INDEX_ALLOCATION attribute * @parent_pos: parent entries' positions in the index block * @parent_vcn: entry's parent node or VCN_INDEX_ROOT_PARENT * @new_vcn: new VCN if we need to create a new index block * @median: move to the parent if splitting index blocks * @ib_dirty: TRUE if index block was changed * @block_size: index block size * @vcn_size_bits: VCN size bits for this index block * * @ni is the inode this context belongs to. * * @entry is the index entry described by this context. @data and @data_len * are the index entry data and its length in bytes, respectively. @data * simply points into @entry. This is probably what the user is interested in. * * If @is_in_root is TRUE, @entry is in the index root attribute @ir described * by the attribute search context @actx and inode @ni. @ia and * @ib_dirty are undefined in this case. * * If @is_in_root is FALSE, @entry is in the index allocation attribute and @ia * point to the index allocation block and VCN where it's placed, * respectively. @ir and @actx are NULL in this case. @ia_na is opened * INDEX_ALLOCATION attribute. @ib_dirty is TRUE if index block was changed and * FALSE otherwise. * * To obtain a context call ntfs_index_ctx_get(). * * When finished with the @entry and its @data, call ntfs_index_ctx_put() to * free the context and other associated resources. * * If the index entry was modified, call ntfs_index_entry_mark_dirty() before * the call to ntfs_index_ctx_put() to ensure that the changes are written * to disk. */ typedef struct { ntfs_inode *ni; ntfschar *name; u32 name_len; INDEX_ENTRY *entry; void *data; u16 data_len; COLLATE collate; BOOL is_in_root; INDEX_ROOT *ir; ntfs_attr_search_ctx *actx; INDEX_BLOCK *ib; ntfs_attr *ia_na; int parent_pos[MAX_PARENT_VCN]; /* parent entries' positions */ VCN parent_vcn[MAX_PARENT_VCN]; /* entry's parent nodes */ int pindex; /* maximum it's the number of the parent nodes */ BOOL ib_dirty; BOOL bad_index; u32 block_size; u8 vcn_size_bits; } ntfs_index_context; extern ntfs_index_context *ntfs_index_ctx_get(ntfs_inode *ni, ntfschar *name, u32 name_len); extern void ntfs_index_ctx_put(ntfs_index_context *ictx); extern void ntfs_index_ctx_reinit(ntfs_index_context *ictx); extern int ntfs_index_block_inconsistent(const INDEX_BLOCK *ib, u32 block_size, u64 inum, VCN vcn); extern int ntfs_index_entry_inconsistent(const INDEX_ENTRY *ie, COLLATION_RULES collation_rule, u64 inum); extern int ntfs_index_lookup(const void *key, const int key_len, ntfs_index_context *ictx) __attribute_warn_unused_result__; extern INDEX_ENTRY *ntfs_index_next(INDEX_ENTRY *ie, ntfs_index_context *ictx); extern int ntfs_index_add_filename(ntfs_inode *ni, FILE_NAME_ATTR *fn, MFT_REF mref); extern int ntfs_index_remove(ntfs_inode *dir_ni, ntfs_inode *ni, const void *key, const int keylen); extern INDEX_ROOT *ntfs_index_root_get(ntfs_inode *ni, ATTR_RECORD *attr); extern VCN ntfs_ie_get_vcn(INDEX_ENTRY *ie); extern void ntfs_index_entry_mark_dirty(ntfs_index_context *ictx); extern char *ntfs_ie_filename_get(INDEX_ENTRY *ie); extern void ntfs_ie_filename_dump(INDEX_ENTRY *ie); extern void ntfs_ih_filename_dump(INDEX_HEADER *ih); /* the following was added by JPA for use in security.c */ extern int ntfs_ie_add(ntfs_index_context *icx, INDEX_ENTRY *ie); extern int ntfs_index_rm(ntfs_index_context *icx); #endif /* _NTFS_INDEX_H */ ntfs-3g-2026.2.25/include/ntfs-3g/security.h0000664000175000017500000002261515152260173013732 /* * security.h - Exports for handling security/ACLs in NTFS. * Originated from the Linux-NTFS project. * * Copyright (c) 2004 Anton Altaparmakov * Copyright (c) 2005-2006 Szabolcs Szakacsits * Copyright (c) 2007-2010 Jean-Pierre Andre * * This program/include file 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/include file 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_SECURITY_H #define _NTFS_SECURITY_H #include "types.h" #include "layout.h" #include "inode.h" #include "dir.h" #include "endians.h" #ifndef POSIXACLS #define POSIXACLS 0 #endif /* * item in the mapping list */ struct MAPPING { struct MAPPING *next; int xid; /* linux id : uid or gid */ SID *sid; /* Windows id : usid or gsid */ int grcnt; /* group count (for users only) */ gid_t *groups; /* groups which the user is member of */ }; /* * Entry in the permissions cache * Note : this cache is not organized as a generic cache */ struct CACHED_PERMISSIONS { uid_t uid; gid_t gid; le32 inh_fileid; le32 inh_dirid; #if POSIXACLS struct POSIX_SECURITY *pxdesc; unsigned int pxdescsize:16; #endif unsigned int mode:12; unsigned int valid:1; } ; /* * Entry in the permissions cache for directories with no security_id */ struct CACHED_PERMISSIONS_LEGACY { struct CACHED_PERMISSIONS_LEGACY *next; struct CACHED_PERMISSIONS_LEGACY *previous; void *variable; size_t varsize; union ALIGNMENT payload[0]; /* above fields must match "struct CACHED_GENERIC" */ u64 mft_no; struct CACHED_PERMISSIONS perm; } ; /* * Entry in the securid cache */ struct CACHED_SECURID { struct CACHED_SECURID *next; struct CACHED_SECURID *previous; void *variable; size_t varsize; union ALIGNMENT payload[0]; /* above fields must match "struct CACHED_GENERIC" */ uid_t uid; gid_t gid; unsigned int dmode; le32 securid; } ; /* * Header of the security cache * (has no cache structure by itself) */ struct CACHED_PERMISSIONS_HEADER { unsigned int last; /* statistics for permissions */ unsigned long p_writes; unsigned long p_reads; unsigned long p_hits; } ; /* * The whole permissions cache */ struct PERMISSIONS_CACHE { struct CACHED_PERMISSIONS_HEADER head; struct CACHED_PERMISSIONS *cachetable[1]; /* array of variable size */ } ; /* * Security flags values */ enum { SECURITY_DEFAULT, /* rely on fuse for permissions checking */ SECURITY_RAW, /* force same ownership/permissions on files */ SECURITY_ACL, /* enable Posix ACLs (when compiled in) */ SECURITY_ADDSECURIDS, /* upgrade old security descriptors */ SECURITY_STATICGRPS, /* use static groups for access control */ SECURITY_WANTED /* a security related option was present */ } ; /* * Security context, needed by most security functions */ enum { MAPUSERS, MAPGROUPS, MAPCOUNT } ; struct SECURITY_CONTEXT { ntfs_volume *vol; struct MAPPING *mapping[MAPCOUNT]; struct PERMISSIONS_CACHE **pseccache; uid_t uid; /* uid of user requesting (not the mounter) */ gid_t gid; /* gid of user requesting (not the mounter) */ pid_t tid; /* thread id of thread requesting */ mode_t umask; /* umask of requesting thread */ } ; #if POSIXACLS /* * Posix ACL structures */ struct POSIX_ACE { u16 tag; u16 perms; s32 id; } __attribute__((__packed__)); struct POSIX_ACL { u8 version; u8 flags; u16 filler; struct POSIX_ACE ace[0]; } __attribute__((__packed__)); struct POSIX_SECURITY { mode_t mode; int acccnt; int defcnt; int firstdef; u16 tagsset; u16 filler; struct POSIX_ACL acl; } ; /* * Posix tags, cpu-endian 16 bits */ enum { POSIX_ACL_USER_OBJ = 1, POSIX_ACL_USER = 2, POSIX_ACL_GROUP_OBJ = 4, POSIX_ACL_GROUP = 8, POSIX_ACL_MASK = 16, POSIX_ACL_OTHER = 32, POSIX_ACL_SPECIAL = 64 /* internal use only */ } ; #define POSIX_ACL_EXTENSIONS (POSIX_ACL_USER | POSIX_ACL_GROUP | POSIX_ACL_MASK) /* * Posix permissions, cpu-endian 16 bits */ enum { POSIX_PERM_X = 1, POSIX_PERM_W = 2, POSIX_PERM_R = 4, POSIX_PERM_DENIAL = 64 /* internal use only */ } ; #define POSIX_VERSION 2 #endif extern BOOL ntfs_guid_is_zero(const GUID *guid); extern char *ntfs_guid_to_mbs(const GUID *guid, char *guid_str); extern int ntfs_sid_to_mbs_size(const SID *sid); extern char *ntfs_sid_to_mbs(const SID *sid, char *sid_str, size_t sid_str_size); extern void ntfs_generate_guid(GUID *guid); extern int ntfs_sd_add_everyone(ntfs_inode *ni); extern le32 ntfs_security_hash(const SECURITY_DESCRIPTOR_RELATIVE *sd, const u32 len); int ntfs_build_mapping(struct SECURITY_CONTEXT *scx, const char *usermap_path, BOOL allowdef); int ntfs_get_owner_mode(struct SECURITY_CONTEXT *scx, ntfs_inode *ni, struct stat*); int ntfs_set_mode(struct SECURITY_CONTEXT *scx, ntfs_inode *ni, mode_t mode); BOOL ntfs_allowed_as_owner(struct SECURITY_CONTEXT *scx, ntfs_inode *ni); int ntfs_allowed_access(struct SECURITY_CONTEXT *scx, ntfs_inode *ni, int accesstype); int ntfs_allowed_create(struct SECURITY_CONTEXT *scx, ntfs_inode *ni, gid_t *pgid, mode_t *pdsetgid); BOOL old_ntfs_allowed_dir_access(struct SECURITY_CONTEXT *scx, const char *path, int accesstype); #if POSIXACLS le32 ntfs_alloc_securid(struct SECURITY_CONTEXT *scx, uid_t uid, gid_t gid, ntfs_inode *dir_ni, mode_t mode, BOOL isdir); #else le32 ntfs_alloc_securid(struct SECURITY_CONTEXT *scx, uid_t uid, gid_t gid, mode_t mode, BOOL isdir); #endif int ntfs_set_owner(struct SECURITY_CONTEXT *scx, ntfs_inode *ni, uid_t uid, gid_t gid); int ntfs_set_ownmod(struct SECURITY_CONTEXT *scx, ntfs_inode *ni, uid_t uid, gid_t gid, mode_t mode); #if POSIXACLS int ntfs_set_owner_mode(struct SECURITY_CONTEXT *scx, ntfs_inode *ni, uid_t uid, gid_t gid, mode_t mode, struct POSIX_SECURITY *pxdesc); #else int ntfs_set_owner_mode(struct SECURITY_CONTEXT *scx, ntfs_inode *ni, uid_t uid, gid_t gid, mode_t mode); #endif le32 ntfs_inherited_id(struct SECURITY_CONTEXT *scx, ntfs_inode *dir_ni, BOOL fordir); int ntfs_open_secure(ntfs_volume *vol); int ntfs_close_secure(ntfs_volume *vol); void ntfs_destroy_security_context(struct SECURITY_CONTEXT *scx); #if POSIXACLS int ntfs_set_inherited_posix(struct SECURITY_CONTEXT *scx, ntfs_inode *ni, uid_t uid, gid_t gid, ntfs_inode *dir_ni, mode_t mode); int ntfs_get_posix_acl(struct SECURITY_CONTEXT *scx, ntfs_inode *ni, const char *name, char *value, size_t size); int ntfs_set_posix_acl(struct SECURITY_CONTEXT *scx, ntfs_inode *ni, const char *name, const char *value, size_t size, int flags); int ntfs_remove_posix_acl(struct SECURITY_CONTEXT *scx, ntfs_inode *ni, const char *name); #endif int ntfs_get_ntfs_acl(struct SECURITY_CONTEXT *scx, ntfs_inode *ni, char *value, size_t size); int ntfs_set_ntfs_acl(struct SECURITY_CONTEXT *scx, ntfs_inode *ni, const char *value, size_t size, int flags); int ntfs_get_ntfs_attrib(ntfs_inode *ni, char *value, size_t size); int ntfs_set_ntfs_attrib(ntfs_inode *ni, const char *value, size_t size, int flags); /* * Security API for direct access to security descriptors * based on Win32 API */ #define MAGIC_API 0x09042009 struct SECURITY_API { u32 magic; struct SECURITY_CONTEXT security; struct PERMISSIONS_CACHE *seccache; } ; /* * The following constants are used in interfacing external programs. * They are not to be stored on disk and must be defined in their * native cpu representation. * When disk representation (le) is needed, use SE_DACL_PRESENT, etc. */ enum { OWNER_SECURITY_INFORMATION = 1, GROUP_SECURITY_INFORMATION = 2, DACL_SECURITY_INFORMATION = 4, SACL_SECURITY_INFORMATION = 8 } ; int ntfs_get_file_security(struct SECURITY_API *scapi, const char *path, u32 selection, char *buf, u32 buflen, u32 *psize); int ntfs_set_file_security(struct SECURITY_API *scapi, const char *path, u32 selection, const char *attr); int ntfs_get_file_attributes(struct SECURITY_API *scapi, const char *path); BOOL ntfs_set_file_attributes(struct SECURITY_API *scapi, const char *path, s32 attrib); BOOL ntfs_read_directory(struct SECURITY_API *scapi, const char *path, ntfs_filldir_t callback, void *context); int ntfs_read_sds(struct SECURITY_API *scapi, char *buf, u32 size, u32 offset); INDEX_ENTRY *ntfs_read_sii(struct SECURITY_API *scapi, INDEX_ENTRY *entry); INDEX_ENTRY *ntfs_read_sdh(struct SECURITY_API *scapi, INDEX_ENTRY *entry); struct SECURITY_API *ntfs_initialize_file_security(const char *device, unsigned long flags); BOOL ntfs_leave_file_security(struct SECURITY_API *scx); int ntfs_get_usid(struct SECURITY_API *scapi, uid_t uid, char *buf); int ntfs_get_gsid(struct SECURITY_API *scapi, gid_t gid, char *buf); int ntfs_get_user(struct SECURITY_API *scapi, const SID *usid); int ntfs_get_group(struct SECURITY_API *scapi, const SID *gsid); #endif /* defined _NTFS_SECURITY_H */ ntfs-3g-2026.2.25/include/ntfs-3g/logging.h0000664000175000017500000001377715152260173013522 /* * logging.h - Centralised logging. Originated from the Linux-NTFS project. * * Copyright (c) 2005 Richard Russon * Copyright (c) 2007-2008 Szabolcs Szakacsits * * This program/include file 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/include file 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 _LOGGING_H_ #define _LOGGING_H_ #ifdef HAVE_CONFIG_H #include "config.h" #endif #ifdef HAVE_STDARG_H #include #endif #include "types.h" /* Function prototype for the logging handlers */ typedef int (ntfs_log_handler)(const char *function, const char *file, int line, u32 level, void *data, const char *format, va_list args); /* Set the logging handler from one of the functions, below. */ void ntfs_log_set_handler(ntfs_log_handler *handler __attribute__((format(printf, 6, 0)))); /* Logging handlers */ ntfs_log_handler ntfs_log_handler_syslog __attribute__((format(printf, 6, 0))); ntfs_log_handler ntfs_log_handler_fprintf __attribute__((format(printf, 6, 0))); ntfs_log_handler ntfs_log_handler_null __attribute__((format(printf, 6, 0))); ntfs_log_handler ntfs_log_handler_stdout __attribute__((format(printf, 6, 0))); ntfs_log_handler ntfs_log_handler_outerr __attribute__((format(printf, 6, 0))); ntfs_log_handler ntfs_log_handler_stderr __attribute__((format(printf, 6, 0))); /* Enable/disable certain log levels */ u32 ntfs_log_set_levels(u32 levels); u32 ntfs_log_clear_levels(u32 levels); u32 ntfs_log_get_levels(void); /* Enable/disable certain log flags */ u32 ntfs_log_set_flags(u32 flags); u32 ntfs_log_clear_flags(u32 flags); u32 ntfs_log_get_flags(void); /* Turn command-line options into logging flags */ BOOL ntfs_log_parse_option(const char *option); int ntfs_log_redirect(const char *function, const char *file, int line, u32 level, void *data, const char *format, ...) __attribute__((format(printf, 6, 7))); /* Logging levels - Determine what gets logged */ #define NTFS_LOG_LEVEL_DEBUG (1 << 0) /* x = 42 */ #define NTFS_LOG_LEVEL_TRACE (1 << 1) /* Entering function x() */ #define NTFS_LOG_LEVEL_QUIET (1 << 2) /* Quietable output */ #define NTFS_LOG_LEVEL_INFO (1 << 3) /* Volume needs defragmenting */ #define NTFS_LOG_LEVEL_VERBOSE (1 << 4) /* Forced to continue */ #define NTFS_LOG_LEVEL_PROGRESS (1 << 5) /* 54% complete */ #define NTFS_LOG_LEVEL_WARNING (1 << 6) /* You should backup before starting */ #define NTFS_LOG_LEVEL_ERROR (1 << 7) /* Operation failed, no damage done */ #define NTFS_LOG_LEVEL_PERROR (1 << 8) /* Message : standard error description */ #define NTFS_LOG_LEVEL_CRITICAL (1 << 9) /* Operation failed,damage may have occurred */ #define NTFS_LOG_LEVEL_ENTER (1 << 10) /* Enter a function */ #define NTFS_LOG_LEVEL_LEAVE (1 << 11) /* Leave a function */ /* Logging style flags - Manage the style of the output */ #define NTFS_LOG_FLAG_PREFIX (1 << 0) /* Prefix messages with "ERROR: ", etc */ #define NTFS_LOG_FLAG_FILENAME (1 << 1) /* Show the file origin of the message */ #define NTFS_LOG_FLAG_LINE (1 << 2) /* Show the line number of the message */ #define NTFS_LOG_FLAG_FUNCTION (1 << 3) /* Show the function name containing the message */ #define NTFS_LOG_FLAG_ONLYNAME (1 << 4) /* Only display the filename, not the pathname */ /* Macros to simplify logging. One for each level defined above. * Note, ntfs_log_debug/trace have effect only if DEBUG is defined. */ #define ntfs_log_critical(FORMAT, ARGS...) ntfs_log_redirect(__FUNCTION__,__FILE__,__LINE__,NTFS_LOG_LEVEL_CRITICAL,NULL,FORMAT,##ARGS) #define ntfs_log_error(FORMAT, ARGS...) ntfs_log_redirect(__FUNCTION__,__FILE__,__LINE__,NTFS_LOG_LEVEL_ERROR,NULL,FORMAT,##ARGS) #define ntfs_log_info(FORMAT, ARGS...) ntfs_log_redirect(__FUNCTION__,__FILE__,__LINE__,NTFS_LOG_LEVEL_INFO,NULL,FORMAT,##ARGS) #define ntfs_log_perror(FORMAT, ARGS...) ntfs_log_redirect(__FUNCTION__,__FILE__,__LINE__,NTFS_LOG_LEVEL_PERROR,NULL,FORMAT,##ARGS) #define ntfs_log_progress(FORMAT, ARGS...) ntfs_log_redirect(__FUNCTION__,__FILE__,__LINE__,NTFS_LOG_LEVEL_PROGRESS,NULL,FORMAT,##ARGS) #define ntfs_log_quiet(FORMAT, ARGS...) ntfs_log_redirect(__FUNCTION__,__FILE__,__LINE__,NTFS_LOG_LEVEL_QUIET,NULL,FORMAT,##ARGS) #define ntfs_log_verbose(FORMAT, ARGS...) ntfs_log_redirect(__FUNCTION__,__FILE__,__LINE__,NTFS_LOG_LEVEL_VERBOSE,NULL,FORMAT,##ARGS) #define ntfs_log_warning(FORMAT, ARGS...) ntfs_log_redirect(__FUNCTION__,__FILE__,__LINE__,NTFS_LOG_LEVEL_WARNING,NULL,FORMAT,##ARGS) /* By default debug and trace messages are compiled into the program, * but not displayed. */ #ifdef DEBUG #define ntfs_log_debug(FORMAT, ARGS...) ntfs_log_redirect(__FUNCTION__,__FILE__,__LINE__,NTFS_LOG_LEVEL_DEBUG,NULL,FORMAT,##ARGS) #define ntfs_log_trace(FORMAT, ARGS...) ntfs_log_redirect(__FUNCTION__,__FILE__,__LINE__,NTFS_LOG_LEVEL_TRACE,NULL,FORMAT,##ARGS) #define ntfs_log_enter(FORMAT, ARGS...) ntfs_log_redirect(__FUNCTION__,__FILE__,__LINE__,NTFS_LOG_LEVEL_ENTER,NULL,FORMAT,##ARGS) #define ntfs_log_leave(FORMAT, ARGS...) ntfs_log_redirect(__FUNCTION__,__FILE__,__LINE__,NTFS_LOG_LEVEL_LEAVE,NULL,FORMAT,##ARGS) #else #define ntfs_log_debug(FORMAT, ARGS...)do {} while (0) #define ntfs_log_trace(FORMAT, ARGS...)do {} while (0) #define ntfs_log_enter(FORMAT, ARGS...)do {} while (0) #define ntfs_log_leave(FORMAT, ARGS...)do {} while (0) #endif /* DEBUG */ void ntfs_log_early_error(const char *format, ...) __attribute__((format(printf, 1, 2))); #endif /* _LOGGING_H_ */ ntfs-3g-2026.2.25/include/ntfs-3g/Makefile.in0000664000175000017500000004576415152260212013763 # Makefile.in generated by automake 1.17 from Makefile.am. # @configure_input@ # Copyright (C) 1994-2024 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY, to the extent permitted by law; without # even the implied warranty of MERCHANTABILITY or FITNESS FOR A # PARTICULAR PURPOSE. @SET_MAKE@ VPATH = @srcdir@ am__is_gnu_make = { \ if test -z '$(MAKELEVEL)'; then \ false; \ elif test -n '$(MAKE_HOST)'; then \ true; \ elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \ true; \ else \ false; \ fi; \ } am__make_running_with_option = \ case $${target_option-} in \ ?) ;; \ *) echo "am__make_running_with_option: internal error: invalid" \ "target option '$${target_option-}' specified" >&2; \ exit 1;; \ esac; \ has_opt=no; \ sane_makeflags=$$MAKEFLAGS; \ if $(am__is_gnu_make); then \ sane_makeflags=$$MFLAGS; \ else \ case $$MAKEFLAGS in \ *\\[\ \ ]*) \ bs=\\; \ sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \ | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \ esac; \ fi; \ skip_next=no; \ strip_trailopt () \ { \ flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \ }; \ for flg in $$sane_makeflags; do \ test $$skip_next = yes && { skip_next=no; continue; }; \ case $$flg in \ *=*|--*) continue;; \ -*I) strip_trailopt 'I'; skip_next=yes;; \ -*I?*) strip_trailopt 'I';; \ -*O) strip_trailopt 'O'; skip_next=yes;; \ -*O?*) strip_trailopt 'O';; \ -*l) strip_trailopt 'l'; skip_next=yes;; \ -*l?*) strip_trailopt 'l';; \ -[dEDm]) skip_next=yes;; \ -[JT]) skip_next=yes;; \ esac; \ case $$flg in \ *$$target_option*) has_opt=yes; break;; \ esac; \ done; \ test $$has_opt = yes am__make_dryrun = (target_option=n; $(am__make_running_with_option)) am__make_keepgoing = (target_option=k; $(am__make_running_with_option)) am__rm_f = rm -f $(am__rm_f_notfound) am__rm_rf = rm -rf $(am__rm_f_notfound) pkgdatadir = $(datadir)/@PACKAGE@ pkgincludedir = $(includedir)/@PACKAGE@ pkglibdir = $(libdir)/@PACKAGE@ pkglibexecdir = $(libexecdir)/@PACKAGE@ am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd install_sh_DATA = $(install_sh) -c -m 644 install_sh_PROGRAM = $(install_sh) -c install_sh_SCRIPT = $(install_sh) -c INSTALL_HEADER = $(INSTALL_DATA) transform = $(program_transform_name) NORMAL_INSTALL = : PRE_INSTALL = : POST_INSTALL = : NORMAL_UNINSTALL = : PRE_UNINSTALL = : POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ target_triplet = @target@ subdir = include/ntfs-3g ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \ $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \ $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \ $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) DIST_COMMON = $(srcdir)/Makefile.am $(am__noinst_HEADERS_DIST) \ $(am__ntfs3ginclude_HEADERS_DIST) $(am__DIST_COMMON) mkinstalldirs = $(install_sh) -d CONFIG_HEADER = $(top_builddir)/config.h CONFIG_CLEAN_FILES = CONFIG_CLEAN_VPATH_FILES = AM_V_P = $(am__v_P_@AM_V@) am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) am__v_P_0 = false am__v_P_1 = : AM_V_GEN = $(am__v_GEN_@AM_V@) am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@) am__v_GEN_0 = @echo " GEN " $@; am__v_GEN_1 = AM_V_at = $(am__v_at_@AM_V@) am__v_at_ = $(am__v_at_@AM_DEFAULT_V@) am__v_at_0 = @ am__v_at_1 = SOURCES = DIST_SOURCES = am__can_run_installinfo = \ case $$AM_UPDATE_INFO_DIR in \ n|no|NO) false;; \ *) (install-info --version) >/dev/null 2>&1;; \ esac am__noinst_HEADERS_DIST = acls.h attrib.h attrlist.h bitmap.h \ bootsect.h cache.h collate.h compat.h compress.h debug.h \ device.h device_io.h dir.h ea.h efs.h endians.h index.h \ inode.h ioctl.h layout.h lcnalloc.h logfile.h logging.h mft.h \ misc.h mst.h ntfstime.h object_id.h param.h plugin.h \ realpath.h reparse.h runlist.h security.h support.h types.h \ unistr.h volume.h xattrs.h am__ntfs3ginclude_HEADERS_DIST = acls.h attrib.h attrlist.h bitmap.h \ bootsect.h cache.h collate.h compat.h compress.h debug.h \ device.h device_io.h dir.h ea.h efs.h endians.h index.h \ inode.h ioctl.h layout.h lcnalloc.h logfile.h logging.h mft.h \ misc.h mst.h ntfstime.h object_id.h param.h plugin.h \ realpath.h reparse.h runlist.h security.h support.h types.h \ unistr.h volume.h xattrs.h am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; am__vpath_adj = case $$p in \ $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ *) f=$$p;; \ esac; am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`; am__install_max = 40 am__nobase_strip_setup = \ srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'` am__nobase_strip = \ for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||" am__nobase_list = $(am__nobase_strip_setup); \ for p in $$list; do echo "$$p $$p"; done | \ sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \ $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \ if (++n[$$2] == $(am__install_max)) \ { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \ END { for (dir in files) print dir, files[dir] }' am__base_list = \ sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' am__uninstall_files_from_dir = { \ { test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; } \ || { echo " ( cd '$$dir' && rm -f" $$files ")"; \ $(am__cd) "$$dir" && echo $$files | $(am__xargs_n) 40 $(am__rm_f); }; \ } am__installdirs = "$(DESTDIR)$(ntfs3gincludedir)" HEADERS = $(noinst_HEADERS) $(ntfs3ginclude_HEADERS) am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) # Read a list of newline-separated strings from the standard input, # and print each of them once, without duplicates. Input order is # *not* preserved. am__uniquify_input = $(AWK) '\ BEGIN { nonempty = 0; } \ { items[$$0] = 1; nonempty = 1; } \ END { if (nonempty) { for (i in items) print i; }; } \ ' # Make sure the list of sources is unique. This is necessary because, # e.g., the same source file might be shared among _SOURCES variables # for different programs/libraries. am__define_uniq_tagged_files = \ list='$(am__tagged_files)'; \ unique=`for i in $$list; do \ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ done | $(am__uniquify_input)` am__DIST_COMMON = $(srcdir)/Makefile.in DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) ACLOCAL = @ACLOCAL@ AMTAR = @AMTAR@ AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ AR = @AR@ AUTOCONF = @AUTOCONF@ AUTOHEADER = @AUTOHEADER@ AUTOMAKE = @AUTOMAKE@ AWK = @AWK@ CC = @CC@ CCDEPMODE = @CCDEPMODE@ CFLAGS = @CFLAGS@ CPPFLAGS = @CPPFLAGS@ CSCOPE = @CSCOPE@ CTAGS = @CTAGS@ CYGPATH_W = @CYGPATH_W@ DEFS = @DEFS@ DEPDIR = @DEPDIR@ DLLTOOL = @DLLTOOL@ DSYMUTIL = @DSYMUTIL@ DUMPBIN = @DUMPBIN@ ECHO_C = @ECHO_C@ ECHO_N = @ECHO_N@ ECHO_T = @ECHO_T@ EGREP = @EGREP@ ETAGS = @ETAGS@ EXEEXT = @EXEEXT@ FGREP = @FGREP@ FILECMD = @FILECMD@ FUSE_MODULE_CFLAGS = @FUSE_MODULE_CFLAGS@ FUSE_MODULE_LIBS = @FUSE_MODULE_LIBS@ GNUTLS_CFLAGS = @GNUTLS_CFLAGS@ GNUTLS_LIBS = @GNUTLS_LIBS@ GPGRT_CONFIG = @GPGRT_CONFIG@ GREP = @GREP@ INSTALL = @INSTALL@ INSTALL_DATA = @INSTALL_DATA@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ INSTALL_SCRIPT = @INSTALL_SCRIPT@ INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ LD = @LD@ LDCONFIG = @LDCONFIG@ LDFLAGS = @LDFLAGS@ LIBDL = @LIBDL@ LIBFUSE_LITE_CFLAGS = @LIBFUSE_LITE_CFLAGS@ LIBFUSE_LITE_LIBS = @LIBFUSE_LITE_LIBS@ LIBGCRYPT_CFLAGS = @LIBGCRYPT_CFLAGS@ LIBGCRYPT_CONFIG = @LIBGCRYPT_CONFIG@ LIBGCRYPT_LIBS = @LIBGCRYPT_LIBS@ LIBNTFS_3G_VERSION = @LIBNTFS_3G_VERSION@ LIBNTFS_CPPFLAGS = @LIBNTFS_CPPFLAGS@ LIBNTFS_LIBS = @LIBNTFS_LIBS@ LIBOBJS = @LIBOBJS@ LIBS = @LIBS@ LIBTOOL = @LIBTOOL@ LIPO = @LIPO@ LN_S = @LN_S@ LTLIBOBJS = @LTLIBOBJS@ LT_SYS_LIBRARY_PATH = @LT_SYS_LIBRARY_PATH@ MAINT = @MAINT@ MAKEINFO = @MAKEINFO@ MANIFEST_TOOL = @MANIFEST_TOOL@ MKDIR_P = @MKDIR_P@ MKNTFS_CPPFLAGS = @MKNTFS_CPPFLAGS@ MKNTFS_LIBS = @MKNTFS_LIBS@ MV = @MV@ NM = @NM@ NMEDIT = @NMEDIT@ NTFSPROGS_STATIC_LIBS = @NTFSPROGS_STATIC_LIBS@ OBJDUMP = @OBJDUMP@ OBJEXT = @OBJEXT@ OTOOL = @OTOOL@ OTOOL64 = @OTOOL64@ OUTPUT_FORMAT = @OUTPUT_FORMAT@ PACKAGE = @PACKAGE@ PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ PACKAGE_NAME = @PACKAGE_NAME@ PACKAGE_STRING = @PACKAGE_STRING@ PACKAGE_TARNAME = @PACKAGE_TARNAME@ PACKAGE_URL = @PACKAGE_URL@ PACKAGE_VERSION = @PACKAGE_VERSION@ PATH_SEPARATOR = @PATH_SEPARATOR@ PKG_CONFIG = @PKG_CONFIG@ PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ RANLIB = @RANLIB@ RM = @RM@ SED = @SED@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ STRIP = @STRIP@ VERSION = @VERSION@ abs_builddir = @abs_builddir@ abs_srcdir = @abs_srcdir@ abs_top_builddir = @abs_top_builddir@ abs_top_srcdir = @abs_top_srcdir@ ac_ct_AR = @ac_ct_AR@ ac_ct_CC = @ac_ct_CC@ ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ all_includes = @all_includes@ all_libraries = @all_libraries@ am__include = @am__include@ am__leading_dot = @am__leading_dot@ am__quote = @am__quote@ am__rm_f_notfound = @am__rm_f_notfound@ am__tar = @am__tar@ am__untar = @am__untar@ am__xargs_n = @am__xargs_n@ bindir = @bindir@ build = @build@ build_alias = @build_alias@ build_cpu = @build_cpu@ build_os = @build_os@ build_vendor = @build_vendor@ builddir = @builddir@ datadir = @datadir@ datarootdir = @datarootdir@ docdir = @docdir@ dvidir = @dvidir@ exec_prefix = @exec_prefix@ host = @host@ host_alias = @host_alias@ host_cpu = @host_cpu@ host_os = @host_os@ host_vendor = @host_vendor@ htmldir = @htmldir@ includedir = @includedir@ infodir = @infodir@ install_sh = @install_sh@ libdir = @libdir@ libexecdir = @libexecdir@ localedir = @localedir@ localstatedir = @localstatedir@ mandir = @mandir@ mkdir_p = @mkdir_p@ ntfs3gincludedir = @ntfs3gincludedir@ oldincludedir = @oldincludedir@ pdfdir = @pdfdir@ pkgconfigdir = @pkgconfigdir@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ rootbindir = @rootbindir@ rootlibdir = @rootlibdir@ rootsbindir = @rootsbindir@ runstatedir = @runstatedir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ sysconfdir = @sysconfdir@ target = @target@ target_alias = @target_alias@ target_cpu = @target_cpu@ target_os = @target_os@ target_vendor = @target_vendor@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ MAINTAINERCLEANFILES = $(srcdir)/Makefile.in headers = \ acls.h \ attrib.h \ attrlist.h \ bitmap.h \ bootsect.h \ cache.h \ collate.h \ compat.h \ compress.h \ debug.h \ device.h \ device_io.h \ dir.h \ ea.h \ efs.h \ endians.h \ index.h \ inode.h \ ioctl.h \ layout.h \ lcnalloc.h \ logfile.h \ logging.h \ mft.h \ misc.h \ mst.h \ ntfstime.h \ object_id.h \ param.h \ plugin.h \ realpath.h \ reparse.h \ runlist.h \ security.h \ support.h \ types.h \ unistr.h \ volume.h \ xattrs.h @INSTALL_LIBRARY_TRUE@ntfs3ginclude_HEADERS = $(headers) @INSTALL_LIBRARY_FALSE@noinst_HEADERS = $(headers) all: all-am .SUFFIXES: $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) @for dep in $?; do \ case '$(am__configure_deps)' in \ *$$dep*) \ ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ && { if test -f $@; then exit 0; else break; fi; }; \ exit 1;; \ esac; \ done; \ echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu include/ntfs-3g/Makefile'; \ $(am__cd) $(top_srcdir) && \ $(AUTOMAKE) --gnu include/ntfs-3g/Makefile Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status @case '$?' in \ *config.status*) \ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ *) \ echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles)'; \ cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles);; \ esac; $(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh $(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh $(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh $(am__aclocal_m4_deps): mostlyclean-libtool: -rm -f *.lo clean-libtool: -rm -rf .libs _libs install-ntfs3gincludeHEADERS: $(ntfs3ginclude_HEADERS) @$(NORMAL_INSTALL) @list='$(ntfs3ginclude_HEADERS)'; test -n "$(ntfs3gincludedir)" || list=; \ if test -n "$$list"; then \ echo " $(MKDIR_P) '$(DESTDIR)$(ntfs3gincludedir)'"; \ $(MKDIR_P) "$(DESTDIR)$(ntfs3gincludedir)" || exit 1; \ fi; \ for p in $$list; do \ if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ echo "$$d$$p"; \ done | $(am__base_list) | \ while read files; do \ echo " $(INSTALL_HEADER) $$files '$(DESTDIR)$(ntfs3gincludedir)'"; \ $(INSTALL_HEADER) $$files "$(DESTDIR)$(ntfs3gincludedir)" || exit $$?; \ done uninstall-ntfs3gincludeHEADERS: @$(NORMAL_UNINSTALL) @list='$(ntfs3ginclude_HEADERS)'; test -n "$(ntfs3gincludedir)" || list=; \ files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \ dir='$(DESTDIR)$(ntfs3gincludedir)'; $(am__uninstall_files_from_dir) ID: $(am__tagged_files) $(am__define_uniq_tagged_files); mkid -fID $$unique tags: tags-am TAGS: tags tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) set x; \ here=`pwd`; \ $(am__define_uniq_tagged_files); \ shift; \ if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ test -n "$$unique" || unique=$$empty_fix; \ if test $$# -gt 0; then \ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ "$$@" $$unique; \ else \ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ $$unique; \ fi; \ fi ctags: ctags-am CTAGS: ctags ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) $(am__define_uniq_tagged_files); \ test -z "$(CTAGS_ARGS)$$unique" \ || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ $$unique GTAGS: here=`$(am__cd) $(top_builddir) && pwd` \ && $(am__cd) $(top_srcdir) \ && gtags -i $(GTAGS_ARGS) "$$here" cscopelist: cscopelist-am cscopelist-am: $(am__tagged_files) list='$(am__tagged_files)'; \ case "$(srcdir)" in \ [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \ *) sdir=$(subdir)/$(srcdir) ;; \ esac; \ for i in $$list; do \ if test -f "$$i"; then \ echo "$(subdir)/$$i"; \ else \ echo "$$sdir/$$i"; \ fi; \ done >> $(top_builddir)/cscope.files distclean-tags: -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags distdir: $(BUILT_SOURCES) $(MAKE) $(AM_MAKEFLAGS) distdir-am distdir-am: $(DISTFILES) @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ list='$(DISTFILES)'; \ dist_files=`for file in $$list; do echo $$file; done | \ sed -e "s|^$$srcdirstrip/||;t" \ -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ case $$dist_files in \ */*) $(MKDIR_P) `echo "$$dist_files" | \ sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ sort -u` ;; \ esac; \ for file in $$dist_files; do \ if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ if test -d $$d/$$file; then \ dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ if test -d "$(distdir)/$$file"; then \ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ fi; \ if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ fi; \ cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ else \ test -f "$(distdir)/$$file" \ || cp -p $$d/$$file "$(distdir)/$$file" \ || exit 1; \ fi; \ done check-am: all-am check: check-am all-am: Makefile $(HEADERS) installdirs: for dir in "$(DESTDIR)$(ntfs3gincludedir)"; do \ test -z "$$dir" || $(MKDIR_P) "$$dir"; \ done install: install-am install-exec: install-exec-am install-data: install-data-am uninstall: uninstall-am install-am: all-am @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am installcheck: installcheck-am install-strip: if test -z '$(STRIP)'; then \ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ install; \ else \ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ fi mostlyclean-generic: clean-generic: distclean-generic: -$(am__rm_f) $(CONFIG_CLEAN_FILES) -test . = "$(srcdir)" || $(am__rm_f) $(CONFIG_CLEAN_VPATH_FILES) maintainer-clean-generic: @echo "This command is intended for maintainers to use" @echo "it deletes files that may require special tools to rebuild." -$(am__rm_f) $(MAINTAINERCLEANFILES) clean: clean-am clean-am: clean-generic clean-libtool mostlyclean-am distclean: distclean-am -rm -f Makefile distclean-am: clean-am distclean-generic distclean-tags dvi: dvi-am dvi-am: html: html-am html-am: info: info-am info-am: install-data-am: install-ntfs3gincludeHEADERS install-dvi: install-dvi-am install-dvi-am: install-exec-am: install-html: install-html-am install-html-am: install-info: install-info-am install-info-am: install-man: install-pdf: install-pdf-am install-pdf-am: install-ps: install-ps-am install-ps-am: installcheck-am: maintainer-clean: maintainer-clean-am -rm -f Makefile maintainer-clean-am: distclean-am maintainer-clean-generic mostlyclean: mostlyclean-am mostlyclean-am: mostlyclean-generic mostlyclean-libtool pdf: pdf-am pdf-am: ps: ps-am ps-am: uninstall-am: uninstall-ntfs3gincludeHEADERS .MAKE: install-am install-strip .PHONY: CTAGS GTAGS TAGS all all-am check check-am clean clean-generic \ clean-libtool cscopelist-am ctags ctags-am distclean \ distclean-generic distclean-libtool distclean-tags distdir dvi \ dvi-am html html-am info info-am install install-am \ install-data install-data-am install-dvi install-dvi-am \ install-exec install-exec-am install-html install-html-am \ install-info install-info-am install-man \ install-ntfs3gincludeHEADERS install-pdf install-pdf-am \ install-ps install-ps-am install-strip installcheck \ installcheck-am installdirs maintainer-clean \ maintainer-clean-generic mostlyclean mostlyclean-generic \ mostlyclean-libtool pdf pdf-am ps ps-am tags tags-am uninstall \ uninstall-am uninstall-ntfs3gincludeHEADERS .PRECIOUS: Makefile # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. .NOEXPORT: # Tell GNU make to disable its built-in pattern rules. %:: %,v %:: RCS/%,v %:: RCS/% %:: s.% %:: SCCS/s.% ntfs-3g-2026.2.25/include/ntfs-3g/debug.h0000664000175000017500000000302315152260173013141 /* * debug.h - Debugging output functions. Originated from the Linux-NTFS project. * * Copyright (c) 2002-2004 Anton Altaparmakov * * This program/include file 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/include file 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_DEBUG_H #define _NTFS_DEBUG_H #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "logging.h" struct _runlist_element; #ifdef DEBUG extern void ntfs_debug_runlist_dump(const struct _runlist_element *rl); #else static __inline__ void ntfs_debug_runlist_dump(const struct _runlist_element *rl __attribute__((unused))) {} #endif #define NTFS_BUG(msg) \ { \ int ___i = 1; \ ntfs_log_critical("Bug in %s(): %s\n", __FUNCTION__, msg); \ ntfs_log_debug("Forcing segmentation fault!"); \ ___i = ((int*)NULL)[___i]; \ } #endif /* defined _NTFS_DEBUG_H */ ntfs-3g-2026.2.25/include/ntfs-3g/bootsect.h0000664000175000017500000000306715152260173013705 /* * bootsect.h - Exports for bootsector record handling. * Originated from the Linux-NTFS project. * * Copyright (c) 2000-2002 Anton Altaparmakov * Copyright (c) 2006 Szabolcs Szakacsits * * This program/include file 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/include file 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_BOOTSECT_H #define _NTFS_BOOTSECT_H #include "types.h" #include "volume.h" #include "layout.h" /** * ntfs_boot_sector_is_ntfs - check a boot sector for describing an ntfs volume * @b: buffer containing the boot sector * * This function checks the boot sector in @b for describing a valid ntfs * volume. Return TRUE if @b is a valid NTFS boot sector or FALSE otherwise. */ extern BOOL ntfs_boot_sector_is_ntfs(NTFS_BOOT_SECTOR *b); extern int ntfs_boot_sector_parse(ntfs_volume *vol, const NTFS_BOOT_SECTOR *bs); #endif /* defined _NTFS_BOOTSECT_H */ ntfs-3g-2026.2.25/include/ntfs-3g/endians.h0000664000175000017500000002515715152260173013510 /* * endians.h - Definitions related to handling of byte ordering. * Originated from the Linux-NTFS project. * * Copyright (c) 2000-2005 Anton Altaparmakov * * This program/include file 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/include file 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_ENDIANS_H #define _NTFS_ENDIANS_H #ifdef HAVE_CONFIG_H #include "config.h" #endif /* * Notes: * We define the conversion functions including typecasts since the * defaults don't necessarily perform appropriate typecasts. * Also, using our own functions means that we can change them if it * turns out that we do need to use the unaligned access macros on * architectures requiring aligned memory accesses... */ #ifdef HAVE_ENDIAN_H #include #endif #ifdef HAVE_SYS_ENDIAN_H #include #endif #ifdef HAVE_MACHINE_ENDIAN_H #include #endif #ifdef HAVE_SYS_BYTEORDER_H #include #endif #ifdef HAVE_SYS_PARAM_H #include #endif #ifndef __BYTE_ORDER # if defined(_BYTE_ORDER) # define __BYTE_ORDER _BYTE_ORDER # define __LITTLE_ENDIAN _LITTLE_ENDIAN # define __BIG_ENDIAN _BIG_ENDIAN # elif defined(BYTE_ORDER) # define __BYTE_ORDER BYTE_ORDER # define __LITTLE_ENDIAN LITTLE_ENDIAN # define __BIG_ENDIAN BIG_ENDIAN # elif defined(__BYTE_ORDER__) && defined(__LITTLE_ENDIAN__) && \ defined(__BIG_ENDIAN__) # define __BYTE_ORDER __BYTE_ORDER__ # define __LITTLE_ENDIAN __LITTLE_ENDIAN__ # define __BIG_ENDIAN __BIG_ENDIAN__ # elif defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && \ defined(__ORDER_BIG_ENDIAN__) # define __BYTE_ORDER __BYTE_ORDER__ # define __LITTLE_ENDIAN __ORDER_LITTLE_ENDIAN__ # define __BIG_ENDIAN __ORDER_BIG_ENDIAN__ # elif (defined(_LITTLE_ENDIAN) && !defined(_BIG_ENDIAN)) || \ defined(WORDS_LITTLEENDIAN) # define __BYTE_ORDER 1 # define __LITTLE_ENDIAN 1 # define __BIG_ENDIAN 0 # elif (!defined(_LITTLE_ENDIAN) && defined(_BIG_ENDIAN)) || \ defined(WORDS_BIGENDIAN) # define __BYTE_ORDER 0 # define __LITTLE_ENDIAN 1 # define __BIG_ENDIAN 0 # else # error "__BYTE_ORDER is not defined." # endif #endif #define __ntfs_bswap_constant_16(x) \ (u16)((((u16)(x) & 0xff00) >> 8) | \ (((u16)(x) & 0x00ff) << 8)) #define __ntfs_bswap_constant_32(x) \ (u32)((((u32)(x) & 0xff000000u) >> 24) | \ (((u32)(x) & 0x00ff0000u) >> 8) | \ (((u32)(x) & 0x0000ff00u) << 8) | \ (((u32)(x) & 0x000000ffu) << 24)) #define __ntfs_bswap_constant_64(x) \ (u64)((((u64)(x) & 0xff00000000000000ull) >> 56) | \ (((u64)(x) & 0x00ff000000000000ull) >> 40) | \ (((u64)(x) & 0x0000ff0000000000ull) >> 24) | \ (((u64)(x) & 0x000000ff00000000ull) >> 8) | \ (((u64)(x) & 0x00000000ff000000ull) << 8) | \ (((u64)(x) & 0x0000000000ff0000ull) << 24) | \ (((u64)(x) & 0x000000000000ff00ull) << 40) | \ (((u64)(x) & 0x00000000000000ffull) << 56)) #ifdef HAVE_BYTESWAP_H # include #else # define bswap_16(x) __ntfs_bswap_constant_16(x) # define bswap_32(x) __ntfs_bswap_constant_32(x) # define bswap_64(x) __ntfs_bswap_constant_64(x) #endif #if defined(__LITTLE_ENDIAN) && (__BYTE_ORDER == __LITTLE_ENDIAN) #define __le16_to_cpu(x) (x) #define __le32_to_cpu(x) (x) #define __le64_to_cpu(x) (x) #define __cpu_to_le16(x) (x) #define __cpu_to_le32(x) (x) #define __cpu_to_le64(x) (x) #define __constant_le16_to_cpu(x) (x) #define __constant_le32_to_cpu(x) (x) #define __constant_le64_to_cpu(x) (x) #define __constant_cpu_to_le16(x) (x) #define __constant_cpu_to_le32(x) (x) #define __constant_cpu_to_le64(x) (x) #define __be16_to_cpu(x) bswap_16(x) #define __be32_to_cpu(x) bswap_32(x) #define __be64_to_cpu(x) bswap_64(x) #define __cpu_to_be16(x) bswap_16(x) #define __cpu_to_be32(x) bswap_32(x) #define __cpu_to_be64(x) bswap_64(x) #define __constant_be16_to_cpu(x) __ntfs_bswap_constant_16((u16)(x)) #define __constant_be32_to_cpu(x) __ntfs_bswap_constant_32((u32)(x)) #define __constant_be64_to_cpu(x) __ntfs_bswap_constant_64((u64)(x)) #define __constant_cpu_to_be16(x) __ntfs_bswap_constant_16((u16)(x)) #define __constant_cpu_to_be32(x) __ntfs_bswap_constant_32((u32)(x)) #define __constant_cpu_to_be64(x) __ntfs_bswap_constant_64((u64)(x)) #elif defined(__BIG_ENDIAN) && (__BYTE_ORDER == __BIG_ENDIAN) #define __le16_to_cpu(x) bswap_16(x) #define __le32_to_cpu(x) bswap_32(x) #define __le64_to_cpu(x) bswap_64(x) #define __cpu_to_le16(x) bswap_16(x) #define __cpu_to_le32(x) bswap_32(x) #define __cpu_to_le64(x) bswap_64(x) #define __constant_le16_to_cpu(x) __ntfs_bswap_constant_16((u16)(x)) #define __constant_le32_to_cpu(x) __ntfs_bswap_constant_32((u32)(x)) #define __constant_le64_to_cpu(x) __ntfs_bswap_constant_64((u64)(x)) #define __constant_cpu_to_le16(x) __ntfs_bswap_constant_16((u16)(x)) #define __constant_cpu_to_le32(x) __ntfs_bswap_constant_32((u32)(x)) #define __constant_cpu_to_le64(x) __ntfs_bswap_constant_64((u64)(x)) #define __be16_to_cpu(x) (x) #define __be32_to_cpu(x) (x) #define __be64_to_cpu(x) (x) #define __cpu_to_be16(x) (x) #define __cpu_to_be32(x) (x) #define __cpu_to_be64(x) (x) #define __constant_be16_to_cpu(x) (x) #define __constant_be32_to_cpu(x) (x) #define __constant_be64_to_cpu(x) (x) #define __constant_cpu_to_be16(x) (x) #define __constant_cpu_to_be32(x) (x) #define __constant_cpu_to_be64(x) (x) #else #error "You must define __BYTE_ORDER to be __LITTLE_ENDIAN or __BIG_ENDIAN." #endif /* Unsigned from LE to CPU conversion. */ #define le16_to_cpu(x) (u16)__le16_to_cpu((u16)(x)) #define le32_to_cpu(x) (u32)__le32_to_cpu((u32)(x)) #define le64_to_cpu(x) (u64)__le64_to_cpu((u64)(x)) #define le16_to_cpup(x) (u16)__le16_to_cpu(*(const u16*)(x)) #define le32_to_cpup(x) (u32)__le32_to_cpu(*(const u32*)(x)) #define le64_to_cpup(x) (u64)__le64_to_cpu(*(const u64*)(x)) /* Signed from LE to CPU conversion. */ #define sle16_to_cpu(x) (s16)__le16_to_cpu((s16)(x)) #define sle32_to_cpu(x) (s32)__le32_to_cpu((s32)(x)) #define sle64_to_cpu(x) (s64)__le64_to_cpu((s64)(x)) #define sle16_to_cpup(x) (s16)__le16_to_cpu(*(s16*)(x)) #define sle32_to_cpup(x) (s32)__le32_to_cpu(*(s32*)(x)) #define sle64_to_cpup(x) (s64)__le64_to_cpu(*(s64*)(x)) /* Unsigned from CPU to LE conversion. */ #define cpu_to_le16(x) (u16)__cpu_to_le16((u16)(x)) #define cpu_to_le32(x) (u32)__cpu_to_le32((u32)(x)) #define cpu_to_le64(x) (u64)__cpu_to_le64((u64)(x)) #define cpu_to_le16p(x) (u16)__cpu_to_le16(*(u16*)(x)) #define cpu_to_le32p(x) (u32)__cpu_to_le32(*(u32*)(x)) #define cpu_to_le64p(x) (u64)__cpu_to_le64(*(u64*)(x)) /* Signed from CPU to LE conversion. */ #define cpu_to_sle16(x) (s16)__cpu_to_le16((s16)(x)) #define cpu_to_sle32(x) (s32)__cpu_to_le32((s32)(x)) #define cpu_to_sle64(x) (s64)__cpu_to_le64((s64)(x)) #define cpu_to_sle16p(x) (s16)__cpu_to_le16(*(s16*)(x)) #define cpu_to_sle32p(x) (s32)__cpu_to_le32(*(s32*)(x)) #define cpu_to_sle64p(x) (s64)__cpu_to_le64(*(s64*)(x)) /* Unsigned from BE to CPU conversion. */ #define be16_to_cpu(x) (u16)__be16_to_cpu((u16)(x)) #define be32_to_cpu(x) (u32)__be32_to_cpu((u32)(x)) #define be64_to_cpu(x) (u64)__be64_to_cpu((u64)(x)) #define be16_to_cpup(x) (u16)__be16_to_cpu(*(const u16*)(x)) #define be32_to_cpup(x) (u32)__be32_to_cpu(*(const u32*)(x)) #define be64_to_cpup(x) (u64)__be64_to_cpu(*(const u64*)(x)) /* Signed from BE to CPU conversion. */ #define sbe16_to_cpu(x) (s16)__be16_to_cpu((s16)(x)) #define sbe32_to_cpu(x) (s32)__be32_to_cpu((s32)(x)) #define sbe64_to_cpu(x) (s64)__be64_to_cpu((s64)(x)) #define sbe16_to_cpup(x) (s16)__be16_to_cpu(*(s16*)(x)) #define sbe32_to_cpup(x) (s32)__be32_to_cpu(*(s32*)(x)) #define sbe64_to_cpup(x) (s64)__be64_to_cpu(*(s64*)(x)) /* Unsigned from CPU to BE conversion. */ #define cpu_to_be16(x) (u16)__cpu_to_be16((u16)(x)) #define cpu_to_be32(x) (u32)__cpu_to_be32((u32)(x)) #define cpu_to_be64(x) (u64)__cpu_to_be64((u64)(x)) #define cpu_to_be16p(x) (u16)__cpu_to_be16(*(u16*)(x)) #define cpu_to_be32p(x) (u32)__cpu_to_be32(*(u32*)(x)) #define cpu_to_be64p(x) (u64)__cpu_to_be64(*(u64*)(x)) /* Signed from CPU to BE conversion. */ #define cpu_to_sbe16(x) (s16)__cpu_to_be16((s16)(x)) #define cpu_to_sbe32(x) (s32)__cpu_to_be32((s32)(x)) #define cpu_to_sbe64(x) (s64)__cpu_to_be64((s64)(x)) #define cpu_to_sbe16p(x) (s16)__cpu_to_be16(*(s16*)(x)) #define cpu_to_sbe32p(x) (s32)__cpu_to_be32(*(s32*)(x)) #define cpu_to_sbe64p(x) (s64)__cpu_to_be64(*(s64*)(x)) /* Constant endianness conversion defines. */ #define const_le16_to_cpu(x) ((u16) __constant_le16_to_cpu(x)) #define const_le32_to_cpu(x) ((u32) __constant_le32_to_cpu(x)) #define const_le64_to_cpu(x) ((u64) __constant_le64_to_cpu(x)) #define const_cpu_to_le16(x) ((le16) __constant_cpu_to_le16(x)) #define const_cpu_to_le32(x) ((le32) __constant_cpu_to_le32(x)) #define const_cpu_to_le64(x) ((le64) __constant_cpu_to_le64(x)) #define const_sle16_to_cpu(x) ((s16) __constant_le16_to_cpu((le16) x)) #define const_sle32_to_cpu(x) ((s32) __constant_le32_to_cpu((le32) x)) #define const_sle64_to_cpu(x) ((s64) __constant_le64_to_cpu((le64) x)) #define const_cpu_to_sle16(x) ((sle16) __constant_cpu_to_le16((u16) x)) #define const_cpu_to_sle32(x) ((sle32) __constant_cpu_to_le32((u32) x)) #define const_cpu_to_sle64(x) ((sle64) __constant_cpu_to_le64((u64) x)) #define const_be16_to_cpu(x) ((u16) __constant_be16_to_cpu(x))) #define const_be32_to_cpu(x) ((u32) __constant_be32_to_cpu(x))) #define const_be64_to_cpu(x) ((u64) __constant_be64_to_cpu(x))) #define const_cpu_to_be16(x) ((be16) __constant_cpu_to_be16(x)) #define const_cpu_to_be32(x) ((be32) __constant_cpu_to_be32(x)) #define const_cpu_to_be64(x) ((be64) __constant_cpu_to_be64(x)) #define const_sbe16_to_cpu(x) ((s16) __constant_be16_to_cpu((be16) x)) #define const_sbe32_to_cpu(x) ((s32) __constant_be32_to_cpu((be32) x)) #define const_sbe64_to_cpu(x) ((s64) __constant_be64_to_cpu((be64) x)) #define const_cpu_to_sbe16(x) ((sbe16) __constant_cpu_to_be16((u16) x)) #define const_cpu_to_sbe32(x) ((sbe32) __constant_cpu_to_be32((u32) x)) #define const_cpu_to_sbe64(x) ((sbe64) __constant_cpu_to_be64((u64) x)) #endif /* defined _NTFS_ENDIANS_H */ ntfs-3g-2026.2.25/include/ntfs-3g/dir.h0000664000175000017500000001047615152260173012643 /* * dir.h - Exports for directory handling. Originated from the Linux-NTFS project. * * Copyright (c) 2002 Anton Altaparmakov * Copyright (c) 2005-2006 Yura Pakhuchiy * Copyright (c) 2004-2005 Richard Russon * Copyright (c) 2005-2008 Szabolcs Szakacsits * * This program/include file 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/include file 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_DIR_H #define _NTFS_DIR_H #include "types.h" #define PATH_SEP '/' /* * We do not have these under DJGPP, so define our version that do not conflict * with other S_IFs defined under DJGPP. */ #ifdef DJGPP #ifndef S_IFLNK #define S_IFLNK 0120000 #endif #ifndef S_ISLNK #define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK) #endif #ifndef S_IFSOCK #define S_IFSOCK 0140000 #endif #ifndef S_ISSOCK #define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK) #endif #endif /* * The little endian Unicode strings $I30, $SII, $SDH, $O, $Q, $R * as a global constant. */ extern ntfschar NTFS_INDEX_I30[5]; extern ntfschar NTFS_INDEX_SII[5]; extern ntfschar NTFS_INDEX_SDH[5]; extern ntfschar NTFS_INDEX_O[3]; extern ntfschar NTFS_INDEX_Q[3]; extern ntfschar NTFS_INDEX_R[3]; extern u64 ntfs_inode_lookup_by_name(ntfs_inode *dir_ni, const ntfschar *uname, const int uname_len); extern u64 ntfs_inode_lookup_by_mbsname(ntfs_inode *dir_ni, const char *name); extern void ntfs_inode_update_mbsname(ntfs_inode *dir_ni, const char *name, u64 inum); extern ntfs_inode *ntfs_pathname_to_inode(ntfs_volume *vol, ntfs_inode *parent, const char *pathname); extern ntfs_inode *ntfs_create(ntfs_inode *dir_ni, le32 securid, const ntfschar *name, u8 name_len, mode_t type); extern ntfs_inode *ntfs_create_device(ntfs_inode *dir_ni, le32 securid, const ntfschar *name, u8 name_len, mode_t type, dev_t dev); extern ntfs_inode *ntfs_create_symlink(ntfs_inode *dir_ni, le32 securid, const ntfschar *name, u8 name_len, const ntfschar *target, int target_len); extern int ntfs_check_empty_dir(ntfs_inode *ni); extern int ntfs_delete(ntfs_volume *vol, const char *path, ntfs_inode *ni, ntfs_inode *dir_ni, const ntfschar *name, u8 name_len); extern int ntfs_link(ntfs_inode *ni, ntfs_inode *dir_ni, const ntfschar *name, u8 name_len); /* * File types (adapted from include ) */ #define NTFS_DT_UNKNOWN 0 #define NTFS_DT_FIFO 1 #define NTFS_DT_CHR 2 #define NTFS_DT_DIR 4 #define NTFS_DT_BLK 6 #define NTFS_DT_REG 8 #define NTFS_DT_LNK 10 #define NTFS_DT_SOCK 12 #define NTFS_DT_WHT 14 #define NTFS_DT_REPARSE 32 /* * This is the "ntfs_filldir" function type, used by ntfs_readdir() to let * the caller specify what kind of dirent layout it wants to have. * This allows the caller to read directories into their application or * to have different dirent layouts depending on the binary type. */ typedef int (*ntfs_filldir_t)(void *dirent, const ntfschar *name, const int name_len, const int name_type, const s64 pos, const MFT_REF mref, const unsigned dt_type); extern int ntfs_readdir(ntfs_inode *dir_ni, s64 *pos, void *dirent, ntfs_filldir_t filldir); ntfs_inode *ntfs_dir_parent_inode(ntfs_inode *ni); u32 ntfs_interix_types(ntfs_inode *ni); int ntfs_get_ntfs_dos_name(ntfs_inode *ni, ntfs_inode *dir_ni, char *value, size_t size); int ntfs_set_ntfs_dos_name(ntfs_inode *ni, ntfs_inode *dir_ni, const char *value, size_t size, int flags); int ntfs_remove_ntfs_dos_name(ntfs_inode *ni, ntfs_inode *dir_ni); int ntfs_dir_link_cnt(ntfs_inode *ni); #if CACHE_INODE_SIZE struct CACHED_GENERIC; extern int ntfs_dir_inode_hash(const struct CACHED_GENERIC *cached); extern int ntfs_dir_lookup_hash(const struct CACHED_GENERIC *cached); #endif #endif /* defined _NTFS_DIR_H */ ntfs-3g-2026.2.25/include/ntfs-3g/plugin.h0000664000175000017500000001505015152260173013354 /* * plugin.h : define interface for plugin development * * Copyright (c) 2015-2021 Jean-Pierre Andre * */ /* * 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 */ /* * This file defines the interface to ntfs-3g plugins which * add support for processing some type of reparse points. */ #ifndef _NTFS_PLUGIN_H #define _NTFS_PLUGIN_H #include "layout.h" #include "inode.h" #include "dir.h" struct fuse_file_info; struct stat; /* * The plugin operations currently defined. * These functions should return a non-negative value when they * succeed, or a negative errno value when they fail. * They must not close or free their arguments. * The file system must be left in a consistent state after * each individual call. * If an operation is not defined, an EOPNOTSUPP error is * returned to caller. */ typedef struct plugin_operations { /* * Set the attributes st_size, st_blocks and st_mode * into a struct stat. The returned st_mode must at least * define the file type. Depending on the permissions options * used for mounting, the umask will be applied to the returned * permissions, or the permissions will be changed according * to the ACL set on the file. */ int (*getattr)(ntfs_inode *ni, const REPARSE_POINT *reparse, struct stat *stbuf); /* * Open a file for reading or writing * The field fi->flags indicates the kind of opening. * The field fi->fh may be used to store some information which * will be available to subsequent reads and writes. When used * this field must be non-null. * The returned value is zero for success and a negative errno * value for failure. */ int (*open)(ntfs_inode *ni, const REPARSE_POINT *reparse, struct fuse_file_info *fi); /* * Release an open file or directory * This is only called if fi->fh has been set to a non-null * value while opening. It may be used to free some context * specific to the open file or directory * The returned value is zero for success or a negative errno * value for failure. */ int (*release)(ntfs_inode *ni, const REPARSE_POINT *reparse, struct fuse_file_info *fi); /* * Read from an open file * The returned value is the count of bytes which were read * or a negative errno value for failure. * If the returned value is positive, the access time stamp * will be updated after the call. */ int (*read)(ntfs_inode *ni, const REPARSE_POINT *reparse, char *buf, size_t size, off_t offset, struct fuse_file_info *fi); /* * Write to an open file * The file system must be left consistent after each write call, * the file itself must be at least deletable if the application * writing to it is killed for some reason. * The returned value is the count of bytes which were written * or a negative errno value for failure. * If the returned value is positive, the modified time stamp * will be updated after the call. */ int (*write)(ntfs_inode *ni, const REPARSE_POINT *reparse, const char *buf, size_t size, off_t offset, struct fuse_file_info *fi); /* * Get a symbolic link * The symbolic link must be returned in an allocated buffer, * encoded in a zero terminated multibyte string compatible * with the locale mount option. * The returned value is zero for success or a negative errno * value for failure. */ int (*readlink)(ntfs_inode *ni, const REPARSE_POINT *reparse, char **pbuf); /* * Truncate a file (shorten or append zeroes) * The returned value is zero for success or a negative errno * value for failure. * If the returned value is zero, the modified time stamp * will be updated after the call. */ int (*truncate)(ntfs_inode *ni, const REPARSE_POINT *reparse, off_t size); /* * Open a directory * The field fi->flags indicates the kind of opening. * The field fi->fh may be used to store some information which * will be available to subsequent readdir(). When used * this field must be non-null and freed in release(). * The returned value is zero for success and a negative errno * value for failure. */ int (*opendir)(ntfs_inode *ni, const REPARSE_POINT *reparse, struct fuse_file_info *fi); /* * Get entries from a directory * * Use the filldir() function with fillctx argument to return * the directory entries. * Names "." and ".." are expected to be returned. * The returned value is zero for success and a negative errno * value for failure. */ int (*readdir)(ntfs_inode *ni, const REPARSE_POINT *reparse, s64 *pos, void *fillctx, ntfs_filldir_t filldir, struct fuse_file_info *fi); /* * Create a new file of any type * * The returned value is a pointer to the inode created, or * NULL if failed, with errno telling why. */ ntfs_inode *(*create)(ntfs_inode *dir_ni, const REPARSE_POINT *reparse, le32 securid, ntfschar *name, int name_len, mode_t type); /* * Link a new name to a file or directory * Linking a directory is needed for renaming a directory * The returned value is zero for success or a negative errno * value for failure. * If the returned value is zero, the modified time stamp * will be updated after the call. */ int (*link)(ntfs_inode *dir_ni, const REPARSE_POINT *reparse, ntfs_inode *ni, ntfschar *name, int name_len); /* * Unlink a name from a directory * The argument pathname may be NULL * The returned value is zero for success or a negative errno * value for failure. */ int (*unlink)(ntfs_inode *dir_ni, const REPARSE_POINT *reparse, const char *pathname, ntfs_inode *ni, ntfschar *name, int name_len); } plugin_operations_t; /* * Plugin initialization routine * Returns the entry table if successful, otherwise returns NULL * and sets errno (e.g. to EINVAL if the tag is not supported by * the plugin.) */ typedef const struct plugin_operations *(*plugin_init_t)(le32 tag); const struct plugin_operations *init(le32 tag); #endif /* _NTFS_PLUGIN_H */ ntfs-3g-2026.2.25/include/ntfs-3g/mst.h0000664000175000017500000000257515152260173012671 /* * mst.h - Exports for multi sector transfer fixup functions. * Originated from the Linux-NTFS project. * * Copyright (c) 2000-2002 Anton Altaparmakov * * This program/include file 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/include file 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_MST_H #define _NTFS_MST_H #include "types.h" #include "layout.h" #include "volume.h" extern int ntfs_mst_post_read_fixup(NTFS_RECORD *b, const u32 size); extern int ntfs_mst_post_read_fixup_warn(NTFS_RECORD *b, const u32 size, BOOL warn); extern int ntfs_mst_pre_write_fixup(NTFS_RECORD *b, const u32 size); extern void ntfs_mst_post_write_fixup(NTFS_RECORD *b); #endif /* defined _NTFS_MST_H */ ntfs-3g-2026.2.25/include/ntfs-3g/inode.h0000664000175000017500000002032215152260173013152 /* * inode.h - Defines for NTFS inode handling. Originated from the Linux-NTFS project. * * Copyright (c) 2001-2004 Anton Altaparmakov * Copyright (c) 2004-2007 Yura Pakhuchiy * Copyright (c) 2004-2005 Richard Russon * Copyright (c) 2006-2008 Szabolcs Szakacsits * * This program/include file 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/include file 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_INODE_H #define _NTFS_INODE_H /* Forward declaration */ typedef struct _ntfs_inode ntfs_inode; #include "types.h" #include "layout.h" #include "support.h" #include "volume.h" #include "ntfstime.h" /** * enum ntfs_inode_state_bits - * * Defined bits for the state field in the ntfs_inode structure. * (f) = files only, (d) = directories only */ typedef enum { NI_Dirty, /* 1: Mft record needs to be written to disk. */ /* The NI_AttrList* tests only make sense for base inodes. */ NI_AttrList, /* 1: Mft record contains an attribute list. */ NI_AttrListDirty, /* 1: Attribute list needs to be written to the mft record and then to disk. */ NI_FileNameDirty, /* 1: FILE_NAME attributes need to be updated in the index. */ NI_v3_Extensions, /* 1: JPA v3.x extensions present. */ NI_TimesSet, /* 1: Use times which were set */ NI_KnownSize, /* 1: Set if sizes are meaningful */ } ntfs_inode_state_bits; #define test_nino_flag(ni, flag) test_bit(NI_##flag, (ni)->state) #define set_nino_flag(ni, flag) set_bit(NI_##flag, (ni)->state) #define clear_nino_flag(ni, flag) clear_bit(NI_##flag, (ni)->state) #define test_and_set_nino_flag(ni, flag) \ test_and_set_bit(NI_##flag, (ni)->state) #define test_and_clear_nino_flag(ni, flag) \ test_and_clear_bit(NI_##flag, (ni)->state) #define NInoDirty(ni) test_nino_flag(ni, Dirty) #define NInoSetDirty(ni) set_nino_flag(ni, Dirty) #define NInoClearDirty(ni) clear_nino_flag(ni, Dirty) #define NInoTestAndSetDirty(ni) test_and_set_nino_flag(ni, Dirty) #define NInoTestAndClearDirty(ni) test_and_clear_nino_flag(ni, Dirty) #define NInoAttrList(ni) test_nino_flag(ni, AttrList) #define NInoSetAttrList(ni) set_nino_flag(ni, AttrList) #define NInoClearAttrList(ni) clear_nino_flag(ni, AttrList) #define test_nino_al_flag(ni, flag) test_nino_flag(ni, AttrList##flag) #define set_nino_al_flag(ni, flag) set_nino_flag(ni, AttrList##flag) #define clear_nino_al_flag(ni, flag) clear_nino_flag(ni, AttrList##flag) #define test_and_set_nino_al_flag(ni, flag) \ test_and_set_nino_flag(ni, AttrList##flag) #define test_and_clear_nino_al_flag(ni, flag) \ test_and_clear_nino_flag(ni, AttrList##flag) #define NInoAttrListDirty(ni) test_nino_al_flag(ni, Dirty) #define NInoAttrListSetDirty(ni) set_nino_al_flag(ni, Dirty) #define NInoAttrListClearDirty(ni) clear_nino_al_flag(ni, Dirty) #define NInoAttrListTestAndSetDirty(ni) test_and_set_nino_al_flag(ni, Dirty) #define NInoAttrListTestAndClearDirty(ni) test_and_clear_nino_al_flag(ni, Dirty) #define NInoFileNameDirty(ni) test_nino_flag(ni, FileNameDirty) #define NInoFileNameSetDirty(ni) set_nino_flag(ni, FileNameDirty) #define NInoFileNameClearDirty(ni) clear_nino_flag(ni, FileNameDirty) #define NInoFileNameTestAndSetDirty(ni) \ test_and_set_nino_flag(ni, FileNameDirty) #define NInoFileNameTestAndClearDirty(ni) \ test_and_clear_nino_flag(ni, FileNameDirty) /** * struct _ntfs_inode - The NTFS in-memory inode structure. * * It is just used as an extension to the fields already provided in the VFS * inode. */ struct _ntfs_inode { u64 mft_no; /* Inode / mft record number. */ MFT_RECORD *mrec; /* The actual mft record of the inode. */ ntfs_volume *vol; /* Pointer to the ntfs volume of this inode. */ unsigned long state; /* NTFS specific flags describing this inode. See ntfs_inode_state_bits above. */ FILE_ATTR_FLAGS flags; /* Flags describing the file. (Copy from STANDARD_INFORMATION) */ /* * Attribute list support (for use by the attribute lookup functions). * Setup during ntfs_open_inode() for all inodes with attribute lists. * Only valid if NI_AttrList is set in state. */ u32 attr_list_size; /* Length of attribute list value in bytes. */ u8 *attr_list; /* Attribute list value itself. */ /* Below fields are always valid. */ s32 nr_extents; /* For a base mft record, the number of attached extent inodes (0 if none), for extent records this is -1. */ union { /* This union is only used if nr_extents != 0. */ ntfs_inode **extent_nis;/* For nr_extents > 0, array of the ntfs inodes of the extent mft records belonging to this base inode which have been loaded. */ ntfs_inode *base_ni; /* For nr_extents == -1, the ntfs inode of the base mft record. */ }; /* Below fields are valid only for base inode. */ /* * These two fields are used to sync filename index and guaranteed to be * correct, however value in index itself maybe wrong (windows itself * do not update them properly). * For directories, they hold the index size, provided the * flag KnownSize is set. */ s64 data_size; /* Data size of unnamed DATA attribute (or INDEX_ROOT for directories) */ s64 allocated_size; /* Allocated size stored in the filename index. (NOTE: Equal to allocated size of the unnamed data attribute for normal or encrypted files and to compressed size of the unnamed data attribute for sparse or compressed files.) */ /* * These four fields are copy of relevant fields from * STANDARD_INFORMATION attribute and used to sync it and FILE_NAME * attribute in the index. */ ntfs_time creation_time; ntfs_time last_data_change_time; ntfs_time last_mft_change_time; ntfs_time last_access_time; /* NTFS 3.x extensions added by JPA */ /* only if NI_v3_Extensions is set in state */ le32 owner_id; le32 security_id; le64 quota_charged; le64 usn; }; typedef enum { NTFS_UPDATE_ATIME = 1 << 0, NTFS_UPDATE_MTIME = 1 << 1, NTFS_UPDATE_CTIME = 1 << 2, } ntfs_time_update_flags; #define NTFS_UPDATE_MCTIME (NTFS_UPDATE_MTIME | NTFS_UPDATE_CTIME) #define NTFS_UPDATE_AMCTIME (NTFS_UPDATE_ATIME | NTFS_UPDATE_MCTIME) extern ntfs_inode *ntfs_inode_base(ntfs_inode *ni); extern ntfs_inode *ntfs_inode_allocate(ntfs_volume *vol); extern ntfs_inode *ntfs_inode_open(ntfs_volume *vol, const MFT_REF mref); extern int ntfs_inode_close(ntfs_inode *ni); extern int ntfs_inode_close_in_dir(ntfs_inode *ni, ntfs_inode *dir_ni); #if CACHE_NIDATA_SIZE struct CACHED_GENERIC; extern int ntfs_inode_real_close(ntfs_inode *ni); extern void ntfs_inode_invalidate(ntfs_volume *vol, const MFT_REF mref); extern void ntfs_inode_nidata_free(const struct CACHED_GENERIC *cached); extern int ntfs_inode_nidata_hash(const struct CACHED_GENERIC *item); #endif extern ntfs_inode *ntfs_extent_inode_open(ntfs_inode *base_ni, const leMFT_REF mref); extern int ntfs_inode_attach_all_extents(ntfs_inode *ni); extern void ntfs_inode_mark_dirty(ntfs_inode *ni); extern void ntfs_inode_update_times(ntfs_inode *ni, ntfs_time_update_flags mask); extern int ntfs_inode_sync(ntfs_inode *ni); extern int ntfs_inode_add_attrlist(ntfs_inode *ni); extern int ntfs_inode_free_space(ntfs_inode *ni, int size); extern int ntfs_inode_badclus_bad(u64 mft_no, ATTR_RECORD *a); extern int ntfs_inode_get_times(ntfs_inode *ni, char *value, size_t size); extern int ntfs_inode_set_times(ntfs_inode *ni, const char *value, size_t size, int flags); /* debugging */ #define debug_double_inode(num, type) #define debug_cached_inode(ni) #endif /* defined _NTFS_INODE_H */ ntfs-3g-2026.2.25/include/ntfs-3g/reparse.h0000664000175000017500000000323715152260173013523 /* * * Copyright (c) 2008 Jean-Pierre Andre * */ /* * 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 REPARSE_H #define REPARSE_H char *ntfs_make_symlink(ntfs_inode *ni, const char *mnt_point); BOOL ntfs_possible_symlink(ntfs_inode *ni); int ntfs_get_ntfs_reparse_data(ntfs_inode *ni, char *value, size_t size); char *ntfs_get_abslink(ntfs_volume *vol, ntfschar *junction, int count, const char *mnt_point, BOOL isdir); REPARSE_POINT *ntfs_get_reparse_point(ntfs_inode *ni); int ntfs_reparse_check_wsl(ntfs_inode *ni, const REPARSE_POINT *reparse); int ntfs_reparse_set_wsl_symlink(ntfs_inode *ni, const ntfschar *target, int target_len); int ntfs_reparse_set_wsl_not_symlink(ntfs_inode *ni, mode_t mode); int ntfs_set_ntfs_reparse_data(ntfs_inode *ni, const char *value, size_t size, int flags); int ntfs_remove_ntfs_reparse_data(ntfs_inode *ni); int ntfs_delete_reparse_index(ntfs_inode *ni); #endif /* REPARSE_H */ ntfs-3g-2026.2.25/include/fuse-lite/0000775000175000017500000000000015152260235012377 5ntfs-3g-2026.2.25/include/fuse-lite/fuse_lowlevel.h0000664000175000017500000011244615152260173015354 /* FUSE: Filesystem in Userspace Copyright (C) 2001-2007 Miklos Szeredi This program can be distributed under the terms of the GNU LGPLv2. See the file COPYING.LIB. */ #ifndef _FUSE_LOWLEVEL_H_ #define _FUSE_LOWLEVEL_H_ /** @file * * Low level API */ #include "fuse_common.h" #include #include #include #include #include #include #ifdef __cplusplus extern "C" { #endif /* ----------------------------------------------------------- * * Miscellaneous definitions * * ----------------------------------------------------------- */ /** The node ID of the root inode */ #define FUSE_ROOT_ID 1 /** Inode number type */ typedef unsigned long fuse_ino_t; /** Request pointer type */ typedef struct fuse_req *fuse_req_t; /** * Session * * This provides hooks for processing requests, and exiting */ struct fuse_session; /** * Channel * * A communication channel, providing hooks for sending and receiving * messages */ struct fuse_chan; /** Directory entry parameters supplied to fuse_reply_entry() */ struct fuse_entry_param { /** Unique inode number * * In lookup, zero means negative entry (from version 2.5) * Returning ENOENT also means negative entry, but by setting zero * ino the kernel may cache negative entries for entry_timeout * seconds. */ fuse_ino_t ino; /** Generation number for this entry. * * The ino/generation pair should be unique for the filesystem's * lifetime. It must be non-zero, otherwise FUSE will treat it as an * error. */ unsigned long generation; /** Inode attributes. * * Even if attr_timeout == 0, attr must be correct. For example, * for open(), FUSE uses attr.st_size from lookup() to determine * how many bytes to request. If this value is not correct, * incorrect data will be returned. */ struct stat attr; /** Validity timeout (in seconds) for the attributes */ double attr_timeout; /** Validity timeout (in seconds) for the name */ double entry_timeout; }; /** Additional context associated with requests */ struct fuse_ctx { /** User ID of the calling process */ uid_t uid; /** Group ID of the calling process */ gid_t gid; /** Thread ID of the calling process */ pid_t pid; /** Umask of the calling process (introduced in version 2.8) */ mode_t umask; }; /* 'to_set' flags in setattr */ #define FUSE_SET_ATTR_MODE (1 << 0) #define FUSE_SET_ATTR_UID (1 << 1) #define FUSE_SET_ATTR_GID (1 << 2) #define FUSE_SET_ATTR_SIZE (1 << 3) #define FUSE_SET_ATTR_ATIME (1 << 4) #define FUSE_SET_ATTR_MTIME (1 << 5) #define FUSE_SET_ATTR_ATIME_NOW (1 << 7) #define FUSE_SET_ATTR_MTIME_NOW (1 << 8) /* ----------------------------------------------------------- * * Request methods and replies * * ----------------------------------------------------------- */ /** * Low level filesystem operations * * Most of the methods (with the exception of init and destroy) * receive a request handle (fuse_req_t) as their first argument. * This handle must be passed to one of the specified reply functions. * * This may be done inside the method invocation, or after the call * has returned. The request handle is valid until one of the reply * functions is called. * * Other pointer arguments (name, fuse_file_info, etc) are not valid * after the call has returned, so if they are needed later, their * contents have to be copied. * * The filesystem sometimes needs to handle a return value of -ENOENT * from the reply function, which means, that the request was * interrupted, and the reply discarded. For example if * fuse_reply_open() return -ENOENT means, that the release method for * this file will not be called. */ struct fuse_lowlevel_ops { /** * Initialize filesystem * * Called before any other filesystem method * * There's no reply to this function * * @param userdata the user data passed to fuse_lowlevel_new() */ void (*init) (void *userdata, struct fuse_conn_info *conn); /** * Clean up filesystem * * Called on filesystem exit * * There's no reply to this function * * @param userdata the user data passed to fuse_lowlevel_new() */ void (*destroy) (void *userdata); /** * Look up a directory entry by name and get its attributes. * * Valid replies: * fuse_reply_entry * fuse_reply_err * * @param req request handle * @param parent inode number of the parent directory * @param name the name to look up */ void (*lookup) (fuse_req_t req, fuse_ino_t parent, const char *name); /** * Forget about an inode * * The nlookup parameter indicates the number of lookups * previously performed on this inode. * * If the filesystem implements inode lifetimes, it is recommended * that inodes acquire a single reference on each lookup, and lose * nlookup references on each forget. * * The filesystem may ignore forget calls, if the inodes don't * need to have a limited lifetime. * * On unmount it is not guaranteed, that all referenced inodes * will receive a forget message. * * Valid replies: * fuse_reply_none * * @param req request handle * @param ino the inode number * @param nlookup the number of lookups to forget */ void (*forget) (fuse_req_t req, fuse_ino_t ino, unsigned long nlookup); /** * Get file attributes * * Valid replies: * fuse_reply_attr * fuse_reply_err * * @param req request handle * @param ino the inode number * @param fi for future use, currently always NULL */ void (*getattr) (fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi); /** * Set file attributes * * In the 'attr' argument only members indicated by the 'to_set' * bitmask contain valid values. Other members contain undefined * values. * * If the setattr was invoked from the ftruncate() system call * under Linux kernel versions 2.6.15 or later, the fi->fh will * contain the value set by the open method or will be undefined * if the open method didn't set any value. Otherwise (not * ftruncate call, or kernel version earlier than 2.6.15) the fi * parameter will be NULL. * * Valid replies: * fuse_reply_attr * fuse_reply_err * * @param req request handle * @param ino the inode number * @param attr the attributes * @param to_set bit mask of attributes which should be set * @param fi file information, or NULL * * Changed in version 2.5: * file information filled in for ftruncate */ void (*setattr) (fuse_req_t req, fuse_ino_t ino, struct stat *attr, int to_set, struct fuse_file_info *fi); /** * Read symbolic link * * Valid replies: * fuse_reply_readlink * fuse_reply_err * * @param req request handle * @param ino the inode number */ void (*readlink) (fuse_req_t req, fuse_ino_t ino); /** * Create file node * * Create a regular file, character device, block device, fifo or * socket node. * * Valid replies: * fuse_reply_entry * fuse_reply_err * * @param req request handle * @param parent inode number of the parent directory * @param name to create * @param mode file type and mode with which to create the new file * @param rdev the device number (only valid if created file is a device) */ void (*mknod) (fuse_req_t req, fuse_ino_t parent, const char *name, mode_t mode, dev_t rdev); /** * Create a directory * * Valid replies: * fuse_reply_entry * fuse_reply_err * * @param req request handle * @param parent inode number of the parent directory * @param name to create * @param mode with which to create the new file */ void (*mkdir) (fuse_req_t req, fuse_ino_t parent, const char *name, mode_t mode); /** * Remove a file * * Valid replies: * fuse_reply_err * * @param req request handle * @param parent inode number of the parent directory * @param name to remove */ void (*unlink) (fuse_req_t req, fuse_ino_t parent, const char *name); /** * Remove a directory * * Valid replies: * fuse_reply_err * * @param req request handle * @param parent inode number of the parent directory * @param name to remove */ void (*rmdir) (fuse_req_t req, fuse_ino_t parent, const char *name); /** * Create a symbolic link * * Valid replies: * fuse_reply_entry * fuse_reply_err * * @param req request handle * @param link the contents of the symbolic link * @param parent inode number of the parent directory * @param name to create */ void (*symlink) (fuse_req_t req, const char *link, fuse_ino_t parent, const char *name); /** Rename a file * * Valid replies: * fuse_reply_err * * @param req request handle * @param parent inode number of the old parent directory * @param name old name * @param newparent inode number of the new parent directory * @param newname new name */ void (*rename) (fuse_req_t req, fuse_ino_t parent, const char *name, fuse_ino_t newparent, const char *newname); /** * Create a hard link * * Valid replies: * fuse_reply_entry * fuse_reply_err * * @param req request handle * @param ino the old inode number * @param newparent inode number of the new parent directory * @param newname new name to create */ void (*link) (fuse_req_t req, fuse_ino_t ino, fuse_ino_t newparent, const char *newname); /** * Open a file * * Open flags (with the exception of O_CREAT, O_EXCL, O_NOCTTY and * O_TRUNC) are available in fi->flags. * * Filesystem may store an arbitrary file handle (pointer, index, * etc) in fi->fh, and use this in other all other file operations * (read, write, flush, release, fsync). * * Filesystem may also implement stateless file I/O and not store * anything in fi->fh. * * There are also some flags (direct_io, keep_cache) which the * filesystem may set in fi, to change the way the file is opened. * See fuse_file_info structure in for more details. * * Valid replies: * fuse_reply_open * fuse_reply_err * * @param req request handle * @param ino the inode number * @param fi file information */ void (*open) (fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi); /** * Read data * * Read should send exactly the number of bytes requested except * on EOF or error, otherwise the rest of the data will be * substituted with zeroes. An exception to this is when the file * has been opened in 'direct_io' mode, in which case the return * value of the read system call will reflect the return value of * this operation. * * fi->fh will contain the value set by the open method, or will * be undefined if the open method didn't set any value. * * Valid replies: * fuse_reply_buf * fuse_reply_err * * @param req request handle * @param ino the inode number * @param size number of bytes to read * @param off offset to read from * @param fi file information */ void (*read) (fuse_req_t req, fuse_ino_t ino, size_t size, off_t off, struct fuse_file_info *fi); /** * Write data * * Write should return exactly the number of bytes requested * except on error. An exception to this is when the file has * been opened in 'direct_io' mode, in which case the return value * of the write system call will reflect the return value of this * operation. * * fi->fh will contain the value set by the open method, or will * be undefined if the open method didn't set any value. * * Valid replies: * fuse_reply_write * fuse_reply_err * * @param req request handle * @param ino the inode number * @param buf data to write * @param size number of bytes to write * @param off offset to write to * @param fi file information */ void (*write) (fuse_req_t req, fuse_ino_t ino, const char *buf, size_t size, off_t off, struct fuse_file_info *fi); /** * Flush method * * This is called on each close() of the opened file. * * Since file descriptors can be duplicated (dup, dup2, fork), for * one open call there may be many flush calls. * * Filesystems shouldn't assume that flush will always be called * after some writes, or that if will be called at all. * * fi->fh will contain the value set by the open method, or will * be undefined if the open method didn't set any value. * * NOTE: the name of the method is misleading, since (unlike * fsync) the filesystem is not forced to flush pending writes. * One reason to flush data, is if the filesystem wants to return * write errors. * * If the filesystem supports file locking operations (setlk, * getlk) it should remove all locks belonging to 'fi->owner'. * * Valid replies: * fuse_reply_err * * @param req request handle * @param ino the inode number * @param fi file information */ void (*flush) (fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi); /** * Release an open file * * Release is called when there are no more references to an open * file: all file descriptors are closed and all memory mappings * are unmapped. * * For every open call there will be exactly one release call. * * The filesystem may reply with an error, but error values are * not returned to close() or munmap() which triggered the * release. * * fi->fh will contain the value set by the open method, or will * be undefined if the open method didn't set any value. * fi->flags will contain the same flags as for open. * * Valid replies: * fuse_reply_err * * @param req request handle * @param ino the inode number * @param fi file information */ void (*release) (fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi); /** * Synchronize file contents * * If the datasync parameter is non-zero, then only the user data * should be flushed, not the meta data. * * Valid replies: * fuse_reply_err * * @param req request handle * @param ino the inode number * @param datasync flag indicating if only data should be flushed * @param fi file information */ void (*fsync) (fuse_req_t req, fuse_ino_t ino, int datasync, struct fuse_file_info *fi); /** * Open a directory * * Filesystem may store an arbitrary file handle (pointer, index, * etc) in fi->fh, and use this in other all other directory * stream operations (readdir, releasedir, fsyncdir). * * Filesystem may also implement stateless directory I/O and not * store anything in fi->fh, though that makes it impossible to * implement standard conforming directory stream operations in * case the contents of the directory can change between opendir * and releasedir. * * Valid replies: * fuse_reply_open * fuse_reply_err * * @param req request handle * @param ino the inode number * @param fi file information */ void (*opendir) (fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi); /** * Read directory * * Send a buffer filled using fuse_add_direntry(), with size not * exceeding the requested size. Send an empty buffer on end of * stream. * * fi->fh will contain the value set by the opendir method, or * will be undefined if the opendir method didn't set any value. * * Valid replies: * fuse_reply_buf * fuse_reply_err * * @param req request handle * @param ino the inode number * @param size maximum number of bytes to send * @param off offset to continue reading the directory stream * @param fi file information */ void (*readdir) (fuse_req_t req, fuse_ino_t ino, size_t size, off_t off, struct fuse_file_info *fi); /** * Release an open directory * * For every opendir call there will be exactly one releasedir * call. * * fi->fh will contain the value set by the opendir method, or * will be undefined if the opendir method didn't set any value. * * Valid replies: * fuse_reply_err * * @param req request handle * @param ino the inode number * @param fi file information */ void (*releasedir) (fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi); /** * Synchronize directory contents * * If the datasync parameter is non-zero, then only the directory * contents should be flushed, not the meta data. * * fi->fh will contain the value set by the opendir method, or * will be undefined if the opendir method didn't set any value. * * Valid replies: * fuse_reply_err * * @param req request handle * @param ino the inode number * @param datasync flag indicating if only data should be flushed * @param fi file information */ void (*fsyncdir) (fuse_req_t req, fuse_ino_t ino, int datasync, struct fuse_file_info *fi); /** * Get file system statistics * * Valid replies: * fuse_reply_statfs * fuse_reply_err * * @param req request handle * @param ino the inode number, zero means "undefined" */ void (*statfs) (fuse_req_t req, fuse_ino_t ino); /** * Set an extended attribute * * Valid replies: * fuse_reply_err */ void (*setxattr) (fuse_req_t req, fuse_ino_t ino, const char *name, const char *value, size_t size, int flags); /** * Get an extended attribute * * If size is zero, the size of the value should be sent with * fuse_reply_xattr. * * If the size is non-zero, and the value fits in the buffer, the * value should be sent with fuse_reply_buf. * * If the size is too small for the value, the ERANGE error should * be sent. * * Valid replies: * fuse_reply_buf * fuse_reply_xattr * fuse_reply_err * * @param req request handle * @param ino the inode number * @param name of the extended attribute * @param size maximum size of the value to send */ void (*getxattr) (fuse_req_t req, fuse_ino_t ino, const char *name, size_t size); /** * List extended attribute names * * If size is zero, the total size of the attribute list should be * sent with fuse_reply_xattr. * * If the size is non-zero, and the null character separated * attribute list fits in the buffer, the list should be sent with * fuse_reply_buf. * * If the size is too small for the list, the ERANGE error should * be sent. * * Valid replies: * fuse_reply_buf * fuse_reply_xattr * fuse_reply_err * * @param req request handle * @param ino the inode number * @param size maximum size of the list to send */ void (*listxattr) (fuse_req_t req, fuse_ino_t ino, size_t size); /** * Remove an extended attribute * * Valid replies: * fuse_reply_err * * @param req request handle * @param ino the inode number * @param name of the extended attribute */ void (*removexattr) (fuse_req_t req, fuse_ino_t ino, const char *name); /** * Check file access permissions * * This will be called for the access() system call. If the * 'default_permissions' mount option is given, this method is not * called. * * This method is not called under Linux kernel versions 2.4.x * * Introduced in version 2.5 * * Valid replies: * fuse_reply_err * * @param req request handle * @param ino the inode number * @param mask requested access mode */ void (*access) (fuse_req_t req, fuse_ino_t ino, int mask); /** * Create and open a file * * If the file does not exist, first create it with the specified * mode, and then open it. * * Open flags (with the exception of O_NOCTTY) are available in * fi->flags. * * Filesystem may store an arbitrary file handle (pointer, index, * etc) in fi->fh, and use this in other all other file operations * (read, write, flush, release, fsync). * * There are also some flags (direct_io, keep_cache) which the * filesystem may set in fi, to change the way the file is opened. * See fuse_file_info structure in for more details. * * If this method is not implemented or under Linux kernel * versions earlier than 2.6.15, the mknod() and open() methods * will be called instead. * * Introduced in version 2.5 * * Valid replies: * fuse_reply_create * fuse_reply_err * * @param req request handle * @param parent inode number of the parent directory * @param name to create * @param mode file type and mode with which to create the new file * @param fi file information */ void (*create) (fuse_req_t req, fuse_ino_t parent, const char *name, mode_t mode, struct fuse_file_info *fi); /** * Test for a POSIX file lock * * Introduced in version 2.6 * * Valid replies: * fuse_reply_lock * fuse_reply_err * * @param req request handle * @param ino the inode number * @param fi file information * @param lock the region/type to test */ void (*getlk) (fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi, struct flock *lock); /** * Acquire, modify or release a POSIX file lock * * For POSIX threads (NPTL) there's a 1-1 relation between pid and * owner, but otherwise this is not always the case. For checking * lock ownership, 'fi->owner' must be used. The l_pid field in * 'struct flock' should only be used to fill in this field in * getlk(). * * Note: if the locking methods are not implemented, the kernel * will still allow file locking to work locally. Hence these are * only interesting for network filesystems and similar. * * Introduced in version 2.6 * * Valid replies: * fuse_reply_err * * @param req request handle * @param ino the inode number * @param fi file information * @param lock the region/type to test * @param sleep locking operation may sleep */ void (*setlk) (fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi, struct flock *lock, int sleep); /** * Map block index within file to block index within device * * Note: This makes sense only for block device backed filesystems * mounted with the 'blkdev' option * * Introduced in version 2.6 * * Valid replies: * fuse_reply_bmap * fuse_reply_err * * @param req request handle * @param ino the inode number * @param blocksize unit of block index * @param idx block index within file */ void (*bmap) (fuse_req_t req, fuse_ino_t ino, size_t blocksize, uint64_t idx); /** * Ioctl * * Note: For unrestricted ioctls (not allowed for FUSE * servers), data in and out areas can be discovered by giving * iovs and setting FUSE_IOCTL_RETRY in @flags. For * restricted ioctls, kernel prepares in/out data area * according to the information encoded in cmd. * * Introduced in version 2.8 * * Note : the unsigned long request submitted by the application * is truncated to 32 bits, and forwarded as a signed int. * * Valid replies: * fuse_reply_ioctl_retry * fuse_reply_ioctl * fuse_reply_ioctl_iov * fuse_reply_err * * @param req request handle * @param ino the inode number * @param cmd ioctl command * @param arg ioctl argument * @param fi file information * @param flags for FUSE_IOCTL_* flags * @param in_buf data fetched from the caller * @param in_bufsz number of fetched bytes * @param out_bufsz maximum size of output data */ void (*ioctl) (fuse_req_t req, fuse_ino_t ino, int cmd, void *arg, struct fuse_file_info *fi, unsigned flags, const void *in_buf, size_t in_bufsz, size_t out_bufsz); }; /** * Reply with an error code or success * * Possible requests: * all except forget * * unlink, rmdir, rename, flush, release, fsync, fsyncdir, setxattr, * removexattr and setlk may send a zero code * * @param req request handle * @param err the positive error value, or zero for success * @return zero for success, -errno for failure to send reply */ int fuse_reply_err(fuse_req_t req, int err); /** * Don't send reply * * Possible requests: * forget * * @param req request handle */ void fuse_reply_none(fuse_req_t req); /** * Reply with a directory entry * * Possible requests: * lookup, mknod, mkdir, symlink, link * * @param req request handle * @param e the entry parameters * @return zero for success, -errno for failure to send reply */ int fuse_reply_entry(fuse_req_t req, const struct fuse_entry_param *e); /** * Reply with a directory entry and open parameters * * currently the following members of 'fi' are used: * fh, direct_io, keep_cache * * Possible requests: * create * * @param req request handle * @param e the entry parameters * @param fi file information * @return zero for success, -errno for failure to send reply */ int fuse_reply_create(fuse_req_t req, const struct fuse_entry_param *e, const struct fuse_file_info *fi); /** * Reply with attributes * * Possible requests: * getattr, setattr * * @param req request handle * @param the attributes * @param attr_timeout validity timeout (in seconds) for the attributes * @return zero for success, -errno for failure to send reply */ int fuse_reply_attr(fuse_req_t req, const struct stat *attr, double attr_timeout); /** * Reply with the contents of a symbolic link * * Possible requests: * readlink * * @param req request handle * @param link symbolic link contents * @return zero for success, -errno for failure to send reply */ int fuse_reply_readlink(fuse_req_t req, const char *link); /** * Reply with open parameters * * currently the following members of 'fi' are used: * fh, direct_io, keep_cache * * Possible requests: * open, opendir * * @param req request handle * @param fi file information * @return zero for success, -errno for failure to send reply */ int fuse_reply_open(fuse_req_t req, const struct fuse_file_info *fi); /** * Reply with number of bytes written * * Possible requests: * write * * @param req request handle * @param count the number of bytes written * @return zero for success, -errno for failure to send reply */ int fuse_reply_write(fuse_req_t req, size_t count); /** * Reply with data * * Possible requests: * read, readdir, getxattr, listxattr * * @param req request handle * @param buf buffer containing data * @param size the size of data in bytes * @return zero for success, -errno for failure to send reply */ int fuse_reply_buf(fuse_req_t req, const char *buf, size_t size); #ifdef POSIXACLS /** * Reply with data vector * * Possible requests: * read, readdir, getxattr, listxattr * * @param req request handle * @param iov the vector containing the data * @param count the size of vector * @return zero for success, -errno for failure to send reply */ int fuse_reply_iov(fuse_req_t req, const struct iovec *iov, int count); #endif /** * Reply with filesystem statistics * * Possible requests: * statfs * * @param req request handle * @param stbuf filesystem statistics * @return zero for success, -errno for failure to send reply */ int fuse_reply_statfs(fuse_req_t req, const struct statvfs *stbuf); /** * Reply with needed buffer size * * Possible requests: * getxattr, listxattr * * @param req request handle * @param count the buffer size needed in bytes * @return zero for success, -errno for failure to send reply */ int fuse_reply_xattr(fuse_req_t req, size_t count); /** * Reply with file lock information * * Possible requests: * getlk * * @param req request handle * @param lock the lock information * @return zero for success, -errno for failure to send reply */ int fuse_reply_lock(fuse_req_t req, struct flock *lock); /** * Reply with block index * * Possible requests: * bmap * * @param req request handle * @param idx block index within device * @return zero for success, -errno for failure to send reply */ int fuse_reply_bmap(fuse_req_t req, uint64_t idx); /* ----------------------------------------------------------- * * Filling a buffer in readdir * * ----------------------------------------------------------- */ /** * Add a directory entry to the buffer * * Buffer needs to be large enough to hold the entry. Of it's not, * then the entry is not filled in but the size of the entry is still * returned. The caller can check this by comparing the bufsize * parameter with the returned entry size. If the entry size is * larger than the buffer size, the operation failed. * * From the 'stbuf' argument the st_ino field and bits 12-15 of the * st_mode field are used. The other fields are ignored. * * Note: offsets do not necessarily represent physical offsets, and * could be any marker, that enables the implementation to find a * specific point in the directory stream. * * @param req request handle * @param buf the point where the new entry will be added to the buffer * @param bufsize remaining size of the buffer * @param the name of the entry * @param stbuf the file attributes * @param off the offset of the next entry * @return the space needed for the entry */ size_t fuse_add_direntry(fuse_req_t req, char *buf, size_t bufsize, const char *name, const struct stat *stbuf, off_t off); /** * Reply to finish ioctl * * Possible requests: * ioctl * * @param req request handle * @param result result to be passed to the caller * @param buf buffer containing output data * @param size length of output data */ int fuse_reply_ioctl(fuse_req_t req, int result, const void *buf, size_t size); /* ----------------------------------------------------------- * * Utility functions * * ----------------------------------------------------------- */ /** * Get the userdata from the request * * @param req request handle * @return the user data passed to fuse_lowlevel_new() */ void *fuse_req_userdata(fuse_req_t req); /** * Get the context from the request * * The pointer returned by this function will only be valid for the * request's lifetime * * @param req request handle * @return the context structure */ const struct fuse_ctx *fuse_req_ctx(fuse_req_t req); /** * Callback function for an interrupt * * @param req interrupted request * @param data user data */ typedef void (*fuse_interrupt_func_t)(fuse_req_t req, void *data); /** * Register/unregister callback for an interrupt * * If an interrupt has already happened, then the callback function is * called from within this function, hence it's not possible for * interrupts to be lost. * * @param req request handle * @param func the callback function or NULL for unregister * @parm data user data passed to the callback function */ void fuse_req_interrupt_func(fuse_req_t req, fuse_interrupt_func_t func, void *data); /** * Check if a request has already been interrupted * * @param req request handle * @return 1 if the request has been interrupted, 0 otherwise */ int fuse_req_interrupted(fuse_req_t req); /* ----------------------------------------------------------- * * Filesystem setup * * ----------------------------------------------------------- */ #ifdef __SOLARIS__ /* Deprecated, don't use */ int fuse_lowlevel_is_lib_option(const char *opt); #endif /* __SOLARIS__ */ /** * Create a low level session * * @param args argument vector * @param op the low level filesystem operations * @param op_size sizeof(struct fuse_lowlevel_ops) * @param userdata user data * @return the created session object, or NULL on failure */ struct fuse_session *fuse_lowlevel_new(struct fuse_args *args, const struct fuse_lowlevel_ops *op, size_t op_size, void *userdata); /* ----------------------------------------------------------- * * Session interface * * ----------------------------------------------------------- */ /** * Session operations * * This is used in session creation */ struct fuse_session_ops { /** * Hook to process a request (mandatory) * * @param data user data passed to fuse_session_new() * @param buf buffer containing the raw request * @param len request length * @param ch channel on which the request was received */ void (*process) (void *data, const char *buf, size_t len, struct fuse_chan *ch); /** * Hook for session exit and reset (optional) * * @param data user data passed to fuse_session_new() * @param val exited status (1 - exited, 0 - not exited) */ void (*exit) (void *data, int val); /** * Hook for querying the current exited status (optional) * * @param data user data passed to fuse_session_new() * @return 1 if exited, 0 if not exited */ int (*exited) (void *data); /** * Hook for cleaning up the channel on destroy (optional) * * @param data user data passed to fuse_session_new() */ void (*destroy) (void *data); }; /** * Create a new session * * @param op session operations * @param data user data * @return new session object, or NULL on failure */ struct fuse_session *fuse_session_new(struct fuse_session_ops *op, void *data); /** * Assign a channel to a session * * Note: currently only a single channel may be assigned. This may * change in the future * * If a session is destroyed, the assigned channel is also destroyed * * @param se the session * @param ch the channel */ void fuse_session_add_chan(struct fuse_session *se, struct fuse_chan *ch); /** * Remove a channel from a session * * If the channel is not assigned to a session, then this is a no-op * * @param ch the channel to remove */ void fuse_session_remove_chan(struct fuse_chan *ch); /** * Iterate over the channels assigned to a session * * The iterating function needs to start with a NULL channel, and * after that needs to pass the previously returned channel to the * function. * * @param se the session * @param ch the previous channel, or NULL * @return the next channel, or NULL if no more channels exist */ struct fuse_chan *fuse_session_next_chan(struct fuse_session *se, struct fuse_chan *ch); /** * Process a raw request * * @param se the session * @param buf buffer containing the raw request * @param len request length * @param ch channel on which the request was received */ void fuse_session_process(struct fuse_session *se, const char *buf, size_t len, struct fuse_chan *ch); /** * Destroy a session * * @param se the session */ void fuse_session_destroy(struct fuse_session *se); /** * Exit a session * * @param se the session */ void fuse_session_exit(struct fuse_session *se); /** * Reset the exited status of a session * * @param se the session */ void fuse_session_reset(struct fuse_session *se); /** * Query the exited status of a session * * @param se the session * @return 1 if exited, 0 if not exited */ int fuse_session_exited(struct fuse_session *se); /** * Enter a single threaded event loop * * @param se the session * @return 0 on success, -1 on error */ int fuse_session_loop(struct fuse_session *se); /** * Enter a multi-threaded event loop * * @param se the session * @return 0 on success, -1 on error */ int fuse_session_loop_mt(struct fuse_session *se); /* ----------------------------------------------------------- * * Channel interface * * ----------------------------------------------------------- */ /** * Channel operations * * This is used in channel creation */ struct fuse_chan_ops { /** * Hook for receiving a raw request * * @param ch pointer to the channel * @param buf the buffer to store the request in * @param size the size of the buffer * @return the actual size of the raw request, or -1 on error */ int (*receive)(struct fuse_chan **chp, char *buf, size_t size); /** * Hook for sending a raw reply * * A return value of -ENOENT means, that the request was * interrupted, and the reply was discarded * * @param ch the channel * @param iov vector of blocks * @param count the number of blocks in vector * @return zero on success, -errno on failure */ int (*send)(struct fuse_chan *ch, const struct iovec iov[], size_t count); /** * Destroy the channel * * @param ch the channel */ void (*destroy)(struct fuse_chan *ch); }; /** * Create a new channel * * @param op channel operations * @param fd file descriptor of the channel * @param bufsize the minimal receive buffer size * @param data user data * @return the new channel object, or NULL on failure */ struct fuse_chan *fuse_chan_new(struct fuse_chan_ops *op, int fd, size_t bufsize, void *data); /** * Query the file descriptor of the channel * * @param ch the channel * @return the file descriptor passed to fuse_chan_new() */ int fuse_chan_fd(struct fuse_chan *ch); /** * Query the minimal receive buffer size * * @param ch the channel * @return the buffer size passed to fuse_chan_new() */ size_t fuse_chan_bufsize(struct fuse_chan *ch); /** * Query the user data * * @param ch the channel * @return the user data passed to fuse_chan_new() */ void *fuse_chan_data(struct fuse_chan *ch); /** * Query the session to which this channel is assigned * * @param ch the channel * @return the session, or NULL if the channel is not assigned */ struct fuse_session *fuse_chan_session(struct fuse_chan *ch); /** * Receive a raw request * * A return value of -ENODEV means, that the filesystem was unmounted * * @param ch pointer to the channel * @param buf the buffer to store the request in * @param size the size of the buffer * @return the actual size of the raw request, or -errno on error */ int fuse_chan_recv(struct fuse_chan **ch, char *buf, size_t size); /** * Send a raw reply * * A return value of -ENOENT means, that the request was * interrupted, and the reply was discarded * * @param ch the channel * @param iov vector of blocks * @param count the number of blocks in vector * @return zero on success, -errno on failure */ int fuse_chan_send(struct fuse_chan *ch, const struct iovec iov[], size_t count); /** * Destroy a channel * * @param ch the channel */ void fuse_chan_destroy(struct fuse_chan *ch); #ifdef __cplusplus } #endif #endif /* _FUSE_LOWLEVEL_H_ */ ntfs-3g-2026.2.25/include/fuse-lite/fuse_common.h0000664000175000017500000001377515152260173015020 /* FUSE: Filesystem in Userspace Copyright (C) 2001-2007 Miklos Szeredi This program can be distributed under the terms of the GNU LGPLv2. See the file COPYING.LIB. */ /** @file */ #if !defined(_FUSE_H_) && !defined(_FUSE_LOWLEVEL_H_) #error "Never include directly; use or instead." #endif #ifndef _FUSE_COMMON_H_ #define _FUSE_COMMON_H_ #include "fuse_opt.h" #include /* temporary */ #include /** Major version of FUSE library interface */ #define FUSE_MAJOR_VERSION 2 /** Minor version of FUSE library interface */ #ifdef POSIXACLS #define FUSE_MINOR_VERSION 8 #else #define FUSE_MINOR_VERSION 7 #endif #define FUSE_MAKE_VERSION(maj, min) ((maj) * 10 + (min)) #define FUSE_VERSION FUSE_MAKE_VERSION(FUSE_MAJOR_VERSION, FUSE_MINOR_VERSION) /* This interface uses 64 bit off_t */ #if defined(__SOLARIS__) && !defined(__x86_64__) && (_FILE_OFFSET_BITS != 64) #error Please add -D_FILE_OFFSET_BITS=64 to your compile flags! #endif #ifdef __cplusplus extern "C" { #endif #ifdef POSIXACLS /* * FUSE_CAP_DONT_MASK: don't apply umask to file mode on create operations * FUSE_CAP_POSIX_ACL: process Posix ACLs within the kernel */ #define FUSE_CAP_DONT_MASK (1 << 6) #define FUSE_CAP_POSIX_ACL (1 << 18) #endif #define FUSE_CAP_BIG_WRITES (1 << 5) #define FUSE_CAP_IOCTL_DIR (1 << 11) /** * Ioctl flags * * FUSE_IOCTL_COMPAT: 32bit compat ioctl on 64bit machine * FUSE_IOCTL_UNRESTRICTED: not restricted to well-formed ioctls, retry allowed * FUSE_IOCTL_RETRY: retry with new iovecs * FUSE_IOCTL_DIR: is a directory */ #define FUSE_IOCTL_COMPAT (1 << 0) #define FUSE_IOCTL_UNRESTRICTED (1 << 1) #define FUSE_IOCTL_RETRY (1 << 2) #define FUSE_IOCTL_DIR (1 << 4) #define FUSE_IOCTL_MAX_IOV 256 /** * Information about open files * * Changed in version 2.5 */ struct fuse_file_info { /** Open flags. Available in open() and release() */ int flags; /** Old file handle, don't use */ unsigned long fh_old; /** In case of a write operation indicates if this was caused by a writepage */ int writepage; /** Can be filled in by open, to use direct I/O on this file. Introduced in version 2.4 */ unsigned int direct_io : 1; /** Can be filled in by open, to indicate, that cached file data need not be invalidated. Introduced in version 2.4 */ unsigned int keep_cache : 1; /** Indicates a flush operation. Set in flush operation, also maybe set in highlevel lock operation and lowlevel release operation. Introduced in version 2.6 */ unsigned int flush : 1; /** Padding. Do not use*/ unsigned int padding : 29; /** File handle. May be filled in by filesystem in open(). Available in all other file operations */ uint64_t fh; /** Lock owner id. Available in locking operations and flush */ uint64_t lock_owner; }; /** * Connection information, passed to the ->init() method * * Some of the elements are read-write, these can be changed to * indicate the value requested by the filesystem. The requested * value must usually be smaller than the indicated value. */ struct fuse_conn_info { /** * Major version of the protocol (read-only) */ unsigned proto_major; /** * Minor version of the protocol (read-only) */ unsigned proto_minor; /** * Is asynchronous read supported (read-write) */ unsigned async_read; /** * Maximum size of the write buffer */ unsigned max_write; /** * Maximum readahead */ unsigned max_readahead; unsigned capable; unsigned want; /** * For future use. */ unsigned reserved[25]; }; struct fuse_session; struct fuse_chan; /** * Create a FUSE mountpoint * * Returns a control file descriptor suitable for passing to * fuse_new() * * @param mountpoint the mount point path * @param args argument vector * @return the communication channel on success, NULL on failure */ struct fuse_chan *fuse_mount(const char *mountpoint, struct fuse_args *args); /** * Umount a FUSE mountpoint * * @param mountpoint the mount point path * @param ch the communication channel */ void fuse_unmount(const char *mountpoint, struct fuse_chan *ch); #ifdef __SOLARIS__ /** * Parse common options * * The following options are parsed: * * '-f' foreground * '-d' '-odebug' foreground, but keep the debug option * '-s' single threaded * '-h' '--help' help * '-ho' help without header * '-ofsname=..' file system name, if not present, then set to the program * name * * All parameters may be NULL * * @param args argument vector * @param mountpoint the returned mountpoint, should be freed after use * @param multithreaded set to 1 unless the '-s' option is present * @param foreground set to 1 if one of the relevant options is present * @return 0 on success, -1 on failure */ int fuse_parse_cmdline(struct fuse_args *args, char **mountpoint, int *multithreaded, int *foreground); /** * Go into the background * * @param foreground if true, stay in the foreground * @return 0 on success, -1 on failure */ int fuse_daemonize(int foreground); #endif /* __SOLARIS__ */ /** * Get the version of the library * * @return the version */ int fuse_version(void); /* ----------------------------------------------------------- * * Signal handling * * ----------------------------------------------------------- */ /** * Exit session on HUP, TERM and INT signals and ignore PIPE signal * * Stores session in a global variable. May only be called once per * process until fuse_remove_signal_handlers() is called. * * @param se the session to exit * @return 0 on success, -1 on failure */ int fuse_set_signal_handlers(struct fuse_session *se); /** * Restore default signal handlers * * Resets global session. After this fuse_set_signal_handlers() may * be called again. * * @param se the same session as given in fuse_set_signal_handlers() */ void fuse_remove_signal_handlers(struct fuse_session *se); #ifdef __cplusplus } #endif #endif /* _FUSE_COMMON_H_ */ ntfs-3g-2026.2.25/include/fuse-lite/fuse.h0000664000175000017500000005307215152260173013442 /* FUSE: Filesystem in Userspace Copyright (C) 2001-2007 Miklos Szeredi This program can be distributed under the terms of the GNU LGPLv2. See the file COPYING.LIB. */ #ifndef _FUSE_H_ #define _FUSE_H_ /** @file * * This file defines the library interface of FUSE */ #include "fuse_common.h" #include #include #include #include #include #include #ifdef __cplusplus extern "C" { #endif /* ----------------------------------------------------------- * * Basic FUSE API * * ----------------------------------------------------------- */ /** Handle for a FUSE filesystem */ struct fuse; /** Structure containing a raw command */ struct fuse_cmd; /** Function to add an entry in a readdir() operation * * @param buf the buffer passed to the readdir() operation * @param name the file name of the directory entry * @param stat file attributes, can be NULL * @param off offset of the next entry or zero * @return 1 if buffer is full, zero otherwise */ typedef int (*fuse_fill_dir_t) (void *buf, const char *name, const struct stat *stbuf, off_t off); /** * The file system operations: * * Most of these should work very similarly to the well known UNIX * file system operations. A major exception is that instead of * returning an error in 'errno', the operation should return the * negated error value (-errno) directly. * * All methods are optional, but some are essential for a useful * filesystem (e.g. getattr). Open, flush, release, fsync, opendir, * releasedir, fsyncdir, access, create, ftruncate, fgetattr, lock, * init and destroy are special purpose methods, without which a full * featured filesystem can still be implemented. * * Almost all operations take a path which can be of any length. * * Changed in fuse 2.8.0 (regardless of API version) * Previously, paths were limited to a length of PATH_MAX. */ struct fuse_operations { /** Get file attributes. * * Similar to stat(). The 'st_dev' and 'st_blksize' fields are * ignored. The 'st_ino' field is ignored except if the 'use_ino' * mount option is given. */ int (*getattr) (const char *, struct stat *); /** Read the target of a symbolic link * * The buffer should be filled with a null terminated string. The * buffer size argument includes the space for the terminating * null character. If the linkname is too long to fit in the * buffer, it should be truncated. The return value should be 0 * for success. */ int (*readlink) (const char *, char *, size_t); /** Create a file node * * This is called for creation of all non-directory, non-symlink * nodes. If the filesystem defines a create() method, then for * regular files that will be called instead. */ int (*mknod) (const char *, mode_t, dev_t); /** Create a directory * * Note that the mode argument may not have the type specification * bits set, i.e. S_ISDIR(mode) can be false. To obtain the * correct directory type bits use mode|S_IFDIR * */ int (*mkdir) (const char *, mode_t); /** Remove a file */ int (*unlink) (const char *); /** Remove a directory */ int (*rmdir) (const char *); /** Create a symbolic link */ int (*symlink) (const char *, const char *); /** Rename a file */ int (*rename) (const char *, const char *); /** Create a hard link to a file */ int (*link) (const char *, const char *); /** Change the permission bits of a file */ int (*chmod) (const char *, mode_t); /** Change the owner and group of a file */ int (*chown) (const char *, uid_t, gid_t); /** Change the size of a file */ int (*truncate) (const char *, off_t); /** Change the access and/or modification times of a file * * Deprecated, use utimens() instead. */ int (*utime) (const char *, struct utimbuf *); /** File open operation * * No creation (O_CREAT, O_EXCL) and by default also no * truncation (O_TRUNC) flags will be passed to open(). If an * application specifies O_TRUNC, fuse first calls truncate() * and then open(). Only if 'atomic_o_trunc' has been * specified and kernel version is 2.6.24 or later, O_TRUNC is * passed on to open. * * Unless the 'default_permissions' mount option is given, * open should check if the operation is permitted for the * given flags. Optionally open may also return an arbitrary * filehandle in the fuse_file_info structure, which will be * passed to all file operations. * * Changed in version 2.2 */ int (*open) (const char *, struct fuse_file_info *); /** Read data from an open file * * Read should return exactly the number of bytes requested except * on EOF or error, otherwise the rest of the data will be * substituted with zeroes. An exception to this is when the * 'direct_io' mount option is specified, in which case the return * value of the read system call will reflect the return value of * this operation. * * Changed in version 2.2 */ int (*read) (const char *, char *, size_t, off_t, struct fuse_file_info *); /** Write data to an open file * * Write should return exactly the number of bytes requested * except on error. An exception to this is when the 'direct_io' * mount option is specified (see read operation). * * Changed in version 2.2 */ int (*write) (const char *, const char *, size_t, off_t, struct fuse_file_info *); /** Get file system statistics * * The 'f_frsize', 'f_favail', 'f_fsid' and 'f_flag' fields are ignored * * Replaced 'struct statfs' parameter with 'struct statvfs' in * version 2.5 */ int (*statfs) (const char *, struct statvfs *); /** Possibly flush cached data * * BIG NOTE: This is not equivalent to fsync(). It's not a * request to sync dirty data. * * Flush is called on each close() of a file descriptor. So if a * filesystem wants to return write errors in close() and the file * has cached dirty data, this is a good place to write back data * and return any errors. Since many applications ignore close() * errors this is not always useful. * * NOTE: The flush() method may be called more than once for each * open(). This happens if more than one file descriptor refers * to an opened file due to dup(), dup2() or fork() calls. It is * not possible to determine if a flush is final, so each flush * should be treated equally. Multiple write-flush sequences are * relatively rare, so this shouldn't be a problem. * * Filesystems shouldn't assume that flush will always be called * after some writes, or that if will be called at all. * * Changed in version 2.2 */ int (*flush) (const char *, struct fuse_file_info *); /** Release an open file * * Release is called when there are no more references to an open * file: all file descriptors are closed and all memory mappings * are unmapped. * * For every open() call there will be exactly one release() call * with the same flags and file descriptor. It is possible to * have a file opened more than once, in which case only the last * release will mean, that no more reads/writes will happen on the * file. The return value of release is ignored. * * Changed in version 2.2 */ int (*release) (const char *, struct fuse_file_info *); /** Synchronize file contents * * If the datasync parameter is non-zero, then only the user data * should be flushed, not the meta data. * * Changed in version 2.2 */ int (*fsync) (const char *, int, struct fuse_file_info *); /** Set extended attributes */ int (*setxattr) (const char *, const char *, const char *, size_t, int); /** Get extended attributes */ int (*getxattr) (const char *, const char *, char *, size_t); /** List extended attributes */ int (*listxattr) (const char *, char *, size_t); /** Remove extended attributes */ int (*removexattr) (const char *, const char *); /** Open directory * * This method should check if the open operation is permitted for * this directory * * Introduced in version 2.3 */ int (*opendir) (const char *, struct fuse_file_info *); /** Read directory * * The filesystem may choose between two modes of operation: * * 1) The readdir implementation ignores the offset parameter, and * passes zero to the filler function's offset. The filler * function will not return '1' (unless an error happens), so the * whole directory is read in a single readdir operation. * * 2) The readdir implementation keeps track of the offsets of the * directory entries. It uses the offset parameter and always * passes non-zero offset to the filler function. When the buffer * is full (or an error happens) the filler function will return * '1'. * * Introduced in version 2.3 */ int (*readdir) (const char *, void *, fuse_fill_dir_t, off_t, struct fuse_file_info *); /** Release directory * * Introduced in version 2.3 */ int (*releasedir) (const char *, struct fuse_file_info *); /** Synchronize directory contents * * If the datasync parameter is non-zero, then only the user data * should be flushed, not the meta data * * Introduced in version 2.3 */ int (*fsyncdir) (const char *, int, struct fuse_file_info *); /** * Initialize filesystem * * The return value will passed in the private_data field of * fuse_context to all file operations and as a parameter to the * destroy() method. * * Introduced in version 2.3 * Changed in version 2.6 */ void *(*init) (struct fuse_conn_info *conn); /** * Clean up filesystem * * Called on filesystem exit. * * Introduced in version 2.3 */ void (*destroy) (void *); /** * Check file access permissions * * This will be called for the access() system call. If the * 'default_permissions' mount option is given, this method is not * called. * * This method is not called under Linux kernel versions 2.4.x * * Introduced in version 2.5 */ int (*access) (const char *, int); /** * Create and open a file * * If the file does not exist, first create it with the specified * mode, and then open it. * * If this method is not implemented or under Linux kernel * versions earlier than 2.6.15, the mknod() and open() methods * will be called instead. * * Introduced in version 2.5 */ int (*create) (const char *, mode_t, struct fuse_file_info *); /** * Change the size of an open file * * This method is called instead of the truncate() method if the * truncation was invoked from an ftruncate() system call. * * If this method is not implemented or under Linux kernel * versions earlier than 2.6.15, the truncate() method will be * called instead. * * Introduced in version 2.5 */ int (*ftruncate) (const char *, off_t, struct fuse_file_info *); /** * Get attributes from an open file * * This method is called instead of the getattr() method if the * file information is available. * * Currently this is only called after the create() method if that * is implemented (see above). Later it may be called for * invocations of fstat() too. * * Introduced in version 2.5 */ int (*fgetattr) (const char *, struct stat *, struct fuse_file_info *); /** * Perform POSIX file locking operation * * The cmd argument will be either F_GETLK, F_SETLK or F_SETLKW. * * For the meaning of fields in 'struct flock' see the man page * for fcntl(2). The l_whence field will always be set to * SEEK_SET. * * For checking lock ownership, the 'fuse_file_info->owner' * argument must be used. * * For F_GETLK operation, the library will first check currently * held locks, and if a conflicting lock is found it will return * information without calling this method. This ensures, that * for local locks the l_pid field is correctly filled in. The * results may not be accurate in case of race conditions and in * the presence of hard links, but it's unlikly that an * application would rely on accurate GETLK results in these * cases. If a conflicting lock is not found, this method will be * called, and the filesystem may fill out l_pid by a meaningful * value, or it may leave this field zero. * * For F_SETLK and F_SETLKW the l_pid field will be set to the pid * of the process performing the locking operation. * * Note: if this method is not implemented, the kernel will still * allow file locking to work locally. Hence it is only * interesting for network filesystems and similar. * * Introduced in version 2.6 */ int (*lock) (const char *, struct fuse_file_info *, int cmd, struct flock *); /** * Change the access and modification times of a file with * nanosecond resolution * * Introduced in version 2.6 */ int (*utimens) (const char *, const struct timespec tv[2]); /** * Map block index within file to block index within device * * Note: This makes sense only for block device backed filesystems * mounted with the 'blkdev' option * * Introduced in version 2.6 */ int (*bmap) (const char *, size_t blocksize, uint64_t *idx); /** * Ioctl * * flags will have FUSE_IOCTL_COMPAT set for 32bit ioctls in * 64bit environment. The size and direction of data is * determined by _IOC_*() decoding of cmd. For _IOC_NONE, * data will be NULL, for _IOC_WRITE data is out area, for * _IOC_READ in area and if both are set in/out area. In all * non-NULL cases, the area is of _IOC_SIZE(cmd) bytes. * * Introduced in version 2.8 * * Note : the unsigned long request submitted by the application * is truncated to 32 bits, and forwarded as a signed int. */ int (*ioctl) (const char *, int cmd, void *arg, struct fuse_file_info *, unsigned int flags, void *data); /* * The flags below have been discarded, they should not be used */ unsigned int flag_nullpath_ok : 1; /** * Reserved flags, don't set */ unsigned int flag_reserved : 30; }; /** Extra context that may be needed by some filesystems * * The uid, gid and pid fields are not filled in case of a writepage * operation. */ struct fuse_context { /** Pointer to the fuse object */ struct fuse *fuse; /** User ID of the calling process */ uid_t uid; /** Group ID of the calling process */ gid_t gid; /** Thread ID of the calling process */ pid_t pid; /** Private filesystem data */ void *private_data; /** Umask of the calling process (introduced in version 2.8) */ mode_t umask; }; /* ----------------------------------------------------------- * * More detailed API * * ----------------------------------------------------------- */ /** * Create a new FUSE filesystem. * * @param ch the communication channel * @param args argument vector * @param op the filesystem operations * @param op_size the size of the fuse_operations structure * @param user_data user data supplied in the context during the init() method * @return the created FUSE handle */ struct fuse *fuse_new(struct fuse_chan *ch, struct fuse_args *args, const struct fuse_operations *op, size_t op_size, void *user_data); /** * Destroy the FUSE handle. * * The communication channel attached to the handle is also destroyed. * * NOTE: This function does not unmount the filesystem. If this is * needed, call fuse_unmount() before calling this function. * * @param f the FUSE handle */ void fuse_destroy(struct fuse *f); /** * FUSE event loop. * * Requests from the kernel are processed, and the appropriate * operations are called. * * @param f the FUSE handle * @return 0 if no error occurred, -1 otherwise */ int fuse_loop(struct fuse *f); /** * Exit from event loop * * @param f the FUSE handle */ void fuse_exit(struct fuse *f); /** * Get the current context * * The context is only valid for the duration of a filesystem * operation, and thus must not be stored and used later. * * @return the context */ struct fuse_context *fuse_get_context(void); /** * Check if a request has already been interrupted * * @param req request handle * @return 1 if the request has been interrupted, 0 otherwise */ int fuse_interrupted(void); /* * Stacking API */ /** * Fuse filesystem object * * This is opaque object represents a filesystem layer */ struct fuse_fs; /* * These functions call the relevant filesystem operation, and return * the result. * * If the operation is not defined, they return -ENOSYS, with the * exception of fuse_fs_open, fuse_fs_release, fuse_fs_opendir, * fuse_fs_releasedir and fuse_fs_statfs, which return 0. */ int fuse_fs_getattr(struct fuse_fs *fs, const char *path, struct stat *buf); int fuse_fs_fgetattr(struct fuse_fs *fs, const char *path, struct stat *buf, struct fuse_file_info *fi); int fuse_fs_rename(struct fuse_fs *fs, const char *oldpath, const char *newpath); int fuse_fs_unlink(struct fuse_fs *fs, const char *path); int fuse_fs_rmdir(struct fuse_fs *fs, const char *path); int fuse_fs_symlink(struct fuse_fs *fs, const char *linkname, const char *path); int fuse_fs_link(struct fuse_fs *fs, const char *oldpath, const char *newpath); int fuse_fs_release(struct fuse_fs *fs, const char *path, struct fuse_file_info *fi); int fuse_fs_open(struct fuse_fs *fs, const char *path, struct fuse_file_info *fi); int fuse_fs_read(struct fuse_fs *fs, const char *path, char *buf, size_t size, off_t off, struct fuse_file_info *fi); int fuse_fs_write(struct fuse_fs *fs, const char *path, const char *buf, size_t size, off_t off, struct fuse_file_info *fi); int fuse_fs_fsync(struct fuse_fs *fs, const char *path, int datasync, struct fuse_file_info *fi); int fuse_fs_flush(struct fuse_fs *fs, const char *path, struct fuse_file_info *fi); int fuse_fs_statfs(struct fuse_fs *fs, const char *path, struct statvfs *buf); int fuse_fs_opendir(struct fuse_fs *fs, const char *path, struct fuse_file_info *fi); int fuse_fs_readdir(struct fuse_fs *fs, const char *path, void *buf, fuse_fill_dir_t filler, off_t off, struct fuse_file_info *fi); int fuse_fs_fsyncdir(struct fuse_fs *fs, const char *path, int datasync, struct fuse_file_info *fi); int fuse_fs_releasedir(struct fuse_fs *fs, const char *path, struct fuse_file_info *fi); int fuse_fs_create(struct fuse_fs *fs, const char *path, mode_t mode, struct fuse_file_info *fi); int fuse_fs_lock(struct fuse_fs *fs, const char *path, struct fuse_file_info *fi, int cmd, struct flock *lock); int fuse_fs_chmod(struct fuse_fs *fs, const char *path, mode_t mode); int fuse_fs_chown(struct fuse_fs *fs, const char *path, uid_t uid, gid_t gid); int fuse_fs_truncate(struct fuse_fs *fs, const char *path, off_t size); int fuse_fs_ftruncate(struct fuse_fs *fs, const char *path, off_t size, struct fuse_file_info *fi); int fuse_fs_utimens(struct fuse_fs *fs, const char *path, const struct timespec tv[2]); int fuse_fs_access(struct fuse_fs *fs, const char *path, int mask); int fuse_fs_readlink(struct fuse_fs *fs, const char *path, char *buf, size_t len); int fuse_fs_mknod(struct fuse_fs *fs, const char *path, mode_t mode, dev_t rdev); int fuse_fs_mkdir(struct fuse_fs *fs, const char *path, mode_t mode); int fuse_fs_setxattr(struct fuse_fs *fs, const char *path, const char *name, const char *value, size_t size, int flags); int fuse_fs_getxattr(struct fuse_fs *fs, const char *path, const char *name, char *value, size_t size); int fuse_fs_listxattr(struct fuse_fs *fs, const char *path, char *list, size_t size); int fuse_fs_removexattr(struct fuse_fs *fs, const char *path, const char *name); int fuse_fs_bmap(struct fuse_fs *fs, const char *path, size_t blocksize, uint64_t *idx); int fuse_fs_ioctl(struct fuse_fs *fs, const char *path, int cmd, void *arg, struct fuse_file_info *fi, unsigned int flags, void *data); void fuse_fs_init(struct fuse_fs *fs, struct fuse_conn_info *conn); void fuse_fs_destroy(struct fuse_fs *fs); /** * Create a new fuse filesystem object * * This is usually called from the factory of a fuse module to create * a new instance of a filesystem. * * @param op the filesystem operations * @param op_size the size of the fuse_operations structure * @param user_data user data supplied in the context during the init() method * @return a new filesystem object */ struct fuse_fs *fuse_fs_new(const struct fuse_operations *op, size_t op_size, void *user_data); #ifdef __SOLARIS__ /** * Filesystem module * * Filesystem modules are registered with the FUSE_REGISTER_MODULE() * macro. * * If the "-omodules=modname:..." option is present, filesystem * objects are created and pushed onto the stack with the 'factory' * function. */ struct fuse_module { /** * Name of filesystem */ const char *name; /** * Factory for creating filesystem objects * * The function may use and remove options from 'args' that belong * to this module. * * For now the 'fs' vector always contains exactly one filesystem. * This is the filesystem which will be below the newly created * filesystem in the stack. * * @param args the command line arguments * @param fs NULL terminated filesystem object vector * @return the new filesystem object */ struct fuse_fs *(*factory)(struct fuse_args *args, struct fuse_fs *fs[]); struct fuse_module *next; struct fusemod_so *so; int ctr; }; #endif /* __SOLARIS__ */ /* ----------------------------------------------------------- * * Advanced API for event handling, don't worry about this... * * ----------------------------------------------------------- */ /* NOTE: the following functions are deprecated, and will be removed from the 3.0 API. Use the lowlevel session functions instead */ /** Get session from fuse object */ struct fuse_session *fuse_get_session(struct fuse *f); #ifdef __cplusplus } #endif #endif /* _FUSE_H_ */ ntfs-3g-2026.2.25/include/fuse-lite/fuse_kernel.h0000664000175000017500000002154115152260173014776 /* This file defines the kernel interface of FUSE Copyright (C) 2001-2007 Miklos Szeredi This program can be distributed under the terms of the GNU GPL. See the file COPYING. This -- and only this -- header file may also be distributed under the terms of the BSD Licence as follows: Copyright (C) 2001-2007 Miklos Szeredi. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * 7.12 * - add umask flag to input argument of open, mknod and mkdir */ #ifndef linux #include #define __u64 uint64_t #define __u32 uint32_t #define __s32 int32_t #else #include #include #endif /** Version number of this interface */ #define FUSE_KERNEL_VERSION 7 /** Minor version number of this interface * We introduce ourself as 7.18 (Posix ACLS : 7.12, IOCTL_DIR : 7.18) * and we expect features features defined for 7.18, but not implemented * here to not be triggered by ntfs-3g. */ #define FUSE_KERNEL_MINOR_VERSION 18 /* * For binary compatibility with old kernels we accept falling back * to 7.12 or earlier maximum version supported by the kernel */ #define FUSE_KERNEL_MAJOR_FALLBACK 7 #define FUSE_KERNEL_MINOR_FALLBACK 12 /** The node ID of the root inode */ #define FUSE_ROOT_ID 1 /** The major number of the fuse character device */ #define FUSE_MAJOR MISC_MAJOR /** The minor number of the fuse character device */ #define FUSE_MINOR 229 /* Make sure all structures are padded to 64bit boundary, so 32bit userspace works under 64bit kernels */ struct fuse_attr { __u64 ino; __u64 size; __u64 blocks; __u64 atime; __u64 mtime; __u64 ctime; __u32 atimensec; __u32 mtimensec; __u32 ctimensec; __u32 mode; __u32 nlink; __u32 uid; __u32 gid; __u32 rdev; __u64 filling; /* JPA needed for minor >= 12, but meaning unknown */ }; struct fuse_kstatfs { __u64 blocks; __u64 bfree; __u64 bavail; __u64 files; __u64 ffree; __u32 bsize; __u32 namelen; __u32 frsize; __u32 padding; __u32 spare[6]; }; struct fuse_file_lock { __u64 start; __u64 end; __u32 type; __u32 pid; /* tgid */ }; /** * Bitmasks for fuse_setattr_in.valid */ #define FATTR_MODE (1 << 0) #define FATTR_UID (1 << 1) #define FATTR_GID (1 << 2) #define FATTR_SIZE (1 << 3) #define FATTR_ATIME (1 << 4) #define FATTR_MTIME (1 << 5) #define FATTR_FH (1 << 6) /** * Flags returned by the OPEN request * * FOPEN_DIRECT_IO: bypass page cache for this open file * FOPEN_KEEP_CACHE: don't invalidate the data cache on open */ #define FOPEN_DIRECT_IO (1 << 0) #define FOPEN_KEEP_CACHE (1 << 1) /** * INIT request/reply flags * FUSE_BIG_WRITES: allow big writes to be issued to the file system * FUSE_DONT_MASK: don't apply umask to file mode on create operations * FUSE_HAS_IOCTL_DIR: kernel supports ioctl on directories * FUSE_POSIX_ACL: kernel supports Posix ACLs */ #define FUSE_ASYNC_READ (1 << 0) #define FUSE_POSIX_LOCKS (1 << 1) #define FUSE_BIG_WRITES (1 << 5) #define FUSE_DONT_MASK (1 << 6) #define FUSE_HAS_IOCTL_DIR (1 << 11) #define FUSE_POSIX_ACL (1 << 19) /** * Release flags */ #define FUSE_RELEASE_FLUSH (1 << 0) enum fuse_opcode { FUSE_LOOKUP = 1, FUSE_FORGET = 2, /* no reply */ FUSE_GETATTR = 3, FUSE_SETATTR = 4, FUSE_READLINK = 5, FUSE_SYMLINK = 6, FUSE_MKNOD = 8, FUSE_MKDIR = 9, FUSE_UNLINK = 10, FUSE_RMDIR = 11, FUSE_RENAME = 12, FUSE_LINK = 13, FUSE_OPEN = 14, FUSE_READ = 15, FUSE_WRITE = 16, FUSE_STATFS = 17, FUSE_RELEASE = 18, FUSE_FSYNC = 20, FUSE_SETXATTR = 21, FUSE_GETXATTR = 22, FUSE_LISTXATTR = 23, FUSE_REMOVEXATTR = 24, FUSE_FLUSH = 25, FUSE_INIT = 26, FUSE_OPENDIR = 27, FUSE_READDIR = 28, FUSE_RELEASEDIR = 29, FUSE_FSYNCDIR = 30, FUSE_GETLK = 31, FUSE_SETLK = 32, FUSE_SETLKW = 33, FUSE_ACCESS = 34, FUSE_CREATE = 35, FUSE_INTERRUPT = 36, FUSE_BMAP = 37, FUSE_DESTROY = 38, FUSE_IOCTL = 39, }; /* The read buffer is required to be at least 8k, but may be much larger */ #define FUSE_MIN_READ_BUFFER 8192 #define FUSE_COMPAT_ENTRY_OUT_SIZE 120 /* JPA */ struct fuse_entry_out { __u64 nodeid; /* Inode ID */ __u64 generation; /* Inode generation: nodeid:gen must be unique for the fs's lifetime */ __u64 entry_valid; /* Cache timeout for the name */ __u64 attr_valid; /* Cache timeout for the attributes */ __u32 entry_valid_nsec; __u32 attr_valid_nsec; struct fuse_attr attr; }; struct fuse_forget_in { __u64 nlookup; }; #define FUSE_COMPAT_FUSE_ATTR_OUT_SIZE 96 /* JPA */ struct fuse_attr_out { __u64 attr_valid; /* Cache timeout for the attributes */ __u32 attr_valid_nsec; __u32 dummy; struct fuse_attr attr; }; #define FUSE_COMPAT_MKNOD_IN_SIZE 8 struct fuse_mknod_in { __u32 mode; __u32 rdev; __u32 umask; __u32 padding; }; struct fuse_mkdir_in { __u32 mode; __u32 umask; }; struct fuse_rename_in { __u64 newdir; }; struct fuse_link_in { __u64 oldnodeid; }; struct fuse_setattr_in { __u32 valid; __u32 padding; __u64 fh; __u64 size; __u64 unused1; __u64 atime; __u64 mtime; __u64 unused2; __u32 atimensec; __u32 mtimensec; __u32 unused3; __u32 mode; __u32 unused4; __u32 uid; __u32 gid; __u32 unused5; }; struct fuse_open_in { __u32 flags; __u32 mode; /* unused for protocol < 7.12 */ }; struct fuse_create_in { __u32 flags; __u32 mode; __u32 umask; __u32 padding; }; struct fuse_open_out { __u64 fh; __u32 open_flags; __u32 padding; }; struct fuse_release_in { __u64 fh; __u32 flags; __u32 release_flags; __u64 lock_owner; }; struct fuse_flush_in { __u64 fh; __u32 unused; __u32 padding; __u64 lock_owner; }; struct fuse_read_in { __u64 fh; __u64 offset; __u32 size; __u32 padding; }; #define FUSE_COMPAT_WRITE_IN_SIZE 24 /* JPA */ struct fuse_write_in { __u64 fh; __u64 offset; __u32 size; __u32 write_flags; __u64 lock_owner; /* JPA */ __u32 flags; /* JPA */ __u32 padding; /* JPA */ }; struct fuse_write_out { __u32 size; __u32 padding; }; #define FUSE_COMPAT_STATFS_SIZE 48 struct fuse_statfs_out { struct fuse_kstatfs st; }; struct fuse_fsync_in { __u64 fh; __u32 fsync_flags; __u32 padding; }; struct fuse_setxattr_in { __u32 size; __u32 flags; }; struct fuse_getxattr_in { __u32 size; __u32 padding; }; struct fuse_getxattr_out { __u32 size; __u32 padding; }; struct fuse_lk_in { __u64 fh; __u64 owner; struct fuse_file_lock lk; }; struct fuse_lk_out { struct fuse_file_lock lk; }; struct fuse_access_in { __u32 mask; __u32 padding; }; struct fuse_init_in { __u32 major; __u32 minor; __u32 max_readahead; __u32 flags; }; struct fuse_init_out { __u32 major; __u32 minor; __u32 max_readahead; __u32 flags; __u32 unused; __u32 max_write; }; struct fuse_interrupt_in { __u64 unique; }; struct fuse_bmap_in { __u64 block; __u32 blocksize; __u32 padding; }; struct fuse_bmap_out { __u64 block; }; struct fuse_ioctl_in { __u64 fh; __u32 flags; __u32 cmd; __u64 arg; __u32 in_size; __u32 out_size; }; struct fuse_ioctl_iovec { __u64 base; __u64 len; }; struct fuse_ioctl_out { __s32 result; __u32 flags; __u32 in_iovs; __u32 out_iovs; }; struct fuse_in_header { __u32 len; __u32 opcode; __u64 unique; __u64 nodeid; __u32 uid; __u32 gid; __u32 pid; __u32 padding; }; struct fuse_out_header { __u32 len; __s32 error; __u64 unique; }; struct fuse_dirent { __u64 ino; __u64 off; __u32 namelen; __u32 type; char name[0]; }; #define FUSE_NAME_OFFSET offsetof(struct fuse_dirent, name) #define FUSE_DIRENT_ALIGN(x) (((x) + sizeof(__u64) - 1) & ~(sizeof(__u64) - 1)) #define FUSE_DIRENT_SIZE(d) \ FUSE_DIRENT_ALIGN(FUSE_NAME_OFFSET + (d)->namelen) ntfs-3g-2026.2.25/include/fuse-lite/Makefile.am0000664000175000017500000000024415152260173014354 MAINTAINERCLEANFILES = Makefile.in noinst_HEADERS = \ fuse.h \ fuse_common.h \ fuse_lowlevel.h \ fuse_lowlevel_compat.h \ fuse_opt.h \ fuse_kernel.h ntfs-3g-2026.2.25/include/fuse-lite/fuse_opt.h0000664000175000017500000001602315152260173014317 /* FUSE: Filesystem in Userspace Copyright (C) 2001-2007 Miklos Szeredi This program can be distributed under the terms of the GNU LGPLv2. See the file COPYING.LIB. */ #ifndef _FUSE_OPT_H_ #define _FUSE_OPT_H_ /** @file * * This file defines the option parsing interface of FUSE */ #ifdef __cplusplus extern "C" { #endif /** * Option description * * This structure describes a single option, and and action associated * with it, in case it matches. * * More than one such match may occur, in which case the action for * each match is executed. * * There are three possible actions in case of a match: * * i) An integer (int or unsigned) variable determined by 'offset' is * set to 'value' * * ii) The processing function is called, with 'value' as the key * * iii) An integer (any) or string (char *) variable determined by * 'offset' is set to the value of an option parameter * * 'offset' should normally be either set to * * - 'offsetof(struct foo, member)' actions i) and iii) * * - -1 action ii) * * The 'offsetof()' macro is defined in the header. * * The template determines which options match, and also have an * effect on the action. Normally the action is either i) or ii), but * if a format is present in the template, then action iii) is * performed. * * The types of templates are: * * 1) "-x", "-foo", "--foo", "--foo-bar", etc. These match only * themselves. Invalid values are "--" and anything beginning * with "-o" * * 2) "foo", "foo-bar", etc. These match "-ofoo", "-ofoo-bar" or * the relevant option in a comma separated option list * * 3) "bar=", "--foo=", etc. These are variations of 1) and 2) * which have a parameter * * 4) "bar=%s", "--foo=%lu", etc. Same matching as above but perform * action iii). * * 5) "-x ", etc. Matches either "-xparam" or "-x param" as * two separate arguments * * 6) "-x %s", etc. Combination of 4) and 5) * * If the format is "%s", memory is allocated for the string unlike * with scanf(). */ struct fuse_opt { /** Matching template and optional parameter formatting */ const char *templ; /** * Offset of variable within 'data' parameter of fuse_opt_parse() * or -1 */ unsigned long offset; /** * Value to set the variable to, or to be passed as 'key' to the * processing function. Ignored if template has a format */ int value; }; /** * Key option. In case of a match, the processing function will be * called with the specified key. */ #define FUSE_OPT_KEY(templ, key) { templ, -1U, key } /** * Last option. An array of 'struct fuse_opt' must end with a NULL * template value */ #define FUSE_OPT_END { .templ = NULL } /** * Argument list */ struct fuse_args { /** Argument count */ int argc; /** Argument vector. NULL terminated */ char **argv; /** Is 'argv' allocated? */ int allocated; }; /** * Initializer for 'struct fuse_args' */ #define FUSE_ARGS_INIT(argc, argv) { argc, argv, 0 } /** * Key value passed to the processing function if an option did not * match any template */ #define FUSE_OPT_KEY_OPT -1 /** * Key value passed to the processing function for all non-options * * Non-options are the arguments beginning with a charater other than * '-' or all arguments after the special '--' option */ #define FUSE_OPT_KEY_NONOPT -2 /** * Special key value for options to keep * * Argument is not passed to processing function, but behave as if the * processing function returned 1 */ #define FUSE_OPT_KEY_KEEP -3 /** * Special key value for options to discard * * Argument is not passed to processing function, but behave as if the * processing function returned zero */ #define FUSE_OPT_KEY_DISCARD -4 /** * Processing function * * This function is called if * - option did not match any 'struct fuse_opt' * - argument is a non-option * - option did match and offset was set to -1 * * The 'arg' parameter will always contain the whole argument or * option including the parameter if exists. A two-argument option * ("-x foo") is always converted to single arguemnt option of the * form "-xfoo" before this function is called. * * Options of the form '-ofoo' are passed to this function without the * '-o' prefix. * * The return value of this function determines whether this argument * is to be inserted into the output argument vector, or discarded. * * @param data is the user data passed to the fuse_opt_parse() function * @param arg is the whole argument or option * @param key determines why the processing function was called * @param outargs the current output argument list * @return -1 on error, 0 if arg is to be discarded, 1 if arg should be kept */ typedef int (*fuse_opt_proc_t)(void *data, const char *arg, int key, struct fuse_args *outargs); /** * Option parsing function * * If 'args' was returned from a previous call to fuse_opt_parse() or * it was constructed from * * A NULL 'args' is equivalent to an empty argument vector * * A NULL 'opts' is equivalent to an 'opts' array containing a single * end marker * * A NULL 'proc' is equivalent to a processing function always * returning '1' * * @param args is the input and output argument list * @param data is the user data * @param opts is the option description array * @param proc is the processing function * @return -1 on error, 0 on success */ int fuse_opt_parse(struct fuse_args *args, void *data, const struct fuse_opt opts[], fuse_opt_proc_t proc); /** * Add an option to a comma separated option list * * @param opts is a pointer to an option list, may point to a NULL value * @param opt is the option to add * @return -1 on allocation error, 0 on success */ int fuse_opt_add_opt(char **opts, const char *opt); /** * Add an argument to a NULL terminated argument vector * * @param args is the structure containing the current argument list * @param arg is the new argument to add * @return -1 on allocation error, 0 on success */ int fuse_opt_add_arg(struct fuse_args *args, const char *arg); /** * Add an argument at the specified position in a NULL terminated * argument vector * * Adds the argument to the N-th position. This is useful for adding * options at the beggining of the array which must not come after the * special '--' option. * * @param args is the structure containing the current argument list * @param pos is the position at which to add the argument * @param arg is the new argument to add * @return -1 on allocation error, 0 on success */ int fuse_opt_insert_arg(struct fuse_args *args, int pos, const char *arg); /** * Free the contents of argument list * * The structure itself is not freed * * @param args is the structure containing the argument list */ void fuse_opt_free_args(struct fuse_args *args); /** * Check if an option matches * * @param opts is the option description array * @param opt is the option to match * @return 1 if a match is found, 0 if not */ int fuse_opt_match(const struct fuse_opt opts[], const char *opt); #ifdef __cplusplus } #endif #endif /* _FUSE_OPT_H_ */ ntfs-3g-2026.2.25/include/fuse-lite/Makefile.in0000664000175000017500000003660715152260212014373 # Makefile.in generated by automake 1.17 from Makefile.am. # @configure_input@ # Copyright (C) 1994-2024 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY, to the extent permitted by law; without # even the implied warranty of MERCHANTABILITY or FITNESS FOR A # PARTICULAR PURPOSE. @SET_MAKE@ VPATH = @srcdir@ am__is_gnu_make = { \ if test -z '$(MAKELEVEL)'; then \ false; \ elif test -n '$(MAKE_HOST)'; then \ true; \ elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \ true; \ else \ false; \ fi; \ } am__make_running_with_option = \ case $${target_option-} in \ ?) ;; \ *) echo "am__make_running_with_option: internal error: invalid" \ "target option '$${target_option-}' specified" >&2; \ exit 1;; \ esac; \ has_opt=no; \ sane_makeflags=$$MAKEFLAGS; \ if $(am__is_gnu_make); then \ sane_makeflags=$$MFLAGS; \ else \ case $$MAKEFLAGS in \ *\\[\ \ ]*) \ bs=\\; \ sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \ | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \ esac; \ fi; \ skip_next=no; \ strip_trailopt () \ { \ flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \ }; \ for flg in $$sane_makeflags; do \ test $$skip_next = yes && { skip_next=no; continue; }; \ case $$flg in \ *=*|--*) continue;; \ -*I) strip_trailopt 'I'; skip_next=yes;; \ -*I?*) strip_trailopt 'I';; \ -*O) strip_trailopt 'O'; skip_next=yes;; \ -*O?*) strip_trailopt 'O';; \ -*l) strip_trailopt 'l'; skip_next=yes;; \ -*l?*) strip_trailopt 'l';; \ -[dEDm]) skip_next=yes;; \ -[JT]) skip_next=yes;; \ esac; \ case $$flg in \ *$$target_option*) has_opt=yes; break;; \ esac; \ done; \ test $$has_opt = yes am__make_dryrun = (target_option=n; $(am__make_running_with_option)) am__make_keepgoing = (target_option=k; $(am__make_running_with_option)) am__rm_f = rm -f $(am__rm_f_notfound) am__rm_rf = rm -rf $(am__rm_f_notfound) pkgdatadir = $(datadir)/@PACKAGE@ pkgincludedir = $(includedir)/@PACKAGE@ pkglibdir = $(libdir)/@PACKAGE@ pkglibexecdir = $(libexecdir)/@PACKAGE@ am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd install_sh_DATA = $(install_sh) -c -m 644 install_sh_PROGRAM = $(install_sh) -c install_sh_SCRIPT = $(install_sh) -c INSTALL_HEADER = $(INSTALL_DATA) transform = $(program_transform_name) NORMAL_INSTALL = : PRE_INSTALL = : POST_INSTALL = : NORMAL_UNINSTALL = : PRE_UNINSTALL = : POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ target_triplet = @target@ subdir = include/fuse-lite ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \ $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \ $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \ $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) DIST_COMMON = $(srcdir)/Makefile.am $(noinst_HEADERS) \ $(am__DIST_COMMON) mkinstalldirs = $(install_sh) -d CONFIG_HEADER = $(top_builddir)/config.h CONFIG_CLEAN_FILES = CONFIG_CLEAN_VPATH_FILES = AM_V_P = $(am__v_P_@AM_V@) am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) am__v_P_0 = false am__v_P_1 = : AM_V_GEN = $(am__v_GEN_@AM_V@) am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@) am__v_GEN_0 = @echo " GEN " $@; am__v_GEN_1 = AM_V_at = $(am__v_at_@AM_V@) am__v_at_ = $(am__v_at_@AM_DEFAULT_V@) am__v_at_0 = @ am__v_at_1 = SOURCES = DIST_SOURCES = am__can_run_installinfo = \ case $$AM_UPDATE_INFO_DIR in \ n|no|NO) false;; \ *) (install-info --version) >/dev/null 2>&1;; \ esac HEADERS = $(noinst_HEADERS) am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) # Read a list of newline-separated strings from the standard input, # and print each of them once, without duplicates. Input order is # *not* preserved. am__uniquify_input = $(AWK) '\ BEGIN { nonempty = 0; } \ { items[$$0] = 1; nonempty = 1; } \ END { if (nonempty) { for (i in items) print i; }; } \ ' # Make sure the list of sources is unique. This is necessary because, # e.g., the same source file might be shared among _SOURCES variables # for different programs/libraries. am__define_uniq_tagged_files = \ list='$(am__tagged_files)'; \ unique=`for i in $$list; do \ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ done | $(am__uniquify_input)` am__DIST_COMMON = $(srcdir)/Makefile.in DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) ACLOCAL = @ACLOCAL@ AMTAR = @AMTAR@ AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ AR = @AR@ AUTOCONF = @AUTOCONF@ AUTOHEADER = @AUTOHEADER@ AUTOMAKE = @AUTOMAKE@ AWK = @AWK@ CC = @CC@ CCDEPMODE = @CCDEPMODE@ CFLAGS = @CFLAGS@ CPPFLAGS = @CPPFLAGS@ CSCOPE = @CSCOPE@ CTAGS = @CTAGS@ CYGPATH_W = @CYGPATH_W@ DEFS = @DEFS@ DEPDIR = @DEPDIR@ DLLTOOL = @DLLTOOL@ DSYMUTIL = @DSYMUTIL@ DUMPBIN = @DUMPBIN@ ECHO_C = @ECHO_C@ ECHO_N = @ECHO_N@ ECHO_T = @ECHO_T@ EGREP = @EGREP@ ETAGS = @ETAGS@ EXEEXT = @EXEEXT@ FGREP = @FGREP@ FILECMD = @FILECMD@ FUSE_MODULE_CFLAGS = @FUSE_MODULE_CFLAGS@ FUSE_MODULE_LIBS = @FUSE_MODULE_LIBS@ GNUTLS_CFLAGS = @GNUTLS_CFLAGS@ GNUTLS_LIBS = @GNUTLS_LIBS@ GPGRT_CONFIG = @GPGRT_CONFIG@ GREP = @GREP@ INSTALL = @INSTALL@ INSTALL_DATA = @INSTALL_DATA@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ INSTALL_SCRIPT = @INSTALL_SCRIPT@ INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ LD = @LD@ LDCONFIG = @LDCONFIG@ LDFLAGS = @LDFLAGS@ LIBDL = @LIBDL@ LIBFUSE_LITE_CFLAGS = @LIBFUSE_LITE_CFLAGS@ LIBFUSE_LITE_LIBS = @LIBFUSE_LITE_LIBS@ LIBGCRYPT_CFLAGS = @LIBGCRYPT_CFLAGS@ LIBGCRYPT_CONFIG = @LIBGCRYPT_CONFIG@ LIBGCRYPT_LIBS = @LIBGCRYPT_LIBS@ LIBNTFS_3G_VERSION = @LIBNTFS_3G_VERSION@ LIBNTFS_CPPFLAGS = @LIBNTFS_CPPFLAGS@ LIBNTFS_LIBS = @LIBNTFS_LIBS@ LIBOBJS = @LIBOBJS@ LIBS = @LIBS@ LIBTOOL = @LIBTOOL@ LIPO = @LIPO@ LN_S = @LN_S@ LTLIBOBJS = @LTLIBOBJS@ LT_SYS_LIBRARY_PATH = @LT_SYS_LIBRARY_PATH@ MAINT = @MAINT@ MAKEINFO = @MAKEINFO@ MANIFEST_TOOL = @MANIFEST_TOOL@ MKDIR_P = @MKDIR_P@ MKNTFS_CPPFLAGS = @MKNTFS_CPPFLAGS@ MKNTFS_LIBS = @MKNTFS_LIBS@ MV = @MV@ NM = @NM@ NMEDIT = @NMEDIT@ NTFSPROGS_STATIC_LIBS = @NTFSPROGS_STATIC_LIBS@ OBJDUMP = @OBJDUMP@ OBJEXT = @OBJEXT@ OTOOL = @OTOOL@ OTOOL64 = @OTOOL64@ OUTPUT_FORMAT = @OUTPUT_FORMAT@ PACKAGE = @PACKAGE@ PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ PACKAGE_NAME = @PACKAGE_NAME@ PACKAGE_STRING = @PACKAGE_STRING@ PACKAGE_TARNAME = @PACKAGE_TARNAME@ PACKAGE_URL = @PACKAGE_URL@ PACKAGE_VERSION = @PACKAGE_VERSION@ PATH_SEPARATOR = @PATH_SEPARATOR@ PKG_CONFIG = @PKG_CONFIG@ PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ RANLIB = @RANLIB@ RM = @RM@ SED = @SED@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ STRIP = @STRIP@ VERSION = @VERSION@ abs_builddir = @abs_builddir@ abs_srcdir = @abs_srcdir@ abs_top_builddir = @abs_top_builddir@ abs_top_srcdir = @abs_top_srcdir@ ac_ct_AR = @ac_ct_AR@ ac_ct_CC = @ac_ct_CC@ ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ all_includes = @all_includes@ all_libraries = @all_libraries@ am__include = @am__include@ am__leading_dot = @am__leading_dot@ am__quote = @am__quote@ am__rm_f_notfound = @am__rm_f_notfound@ am__tar = @am__tar@ am__untar = @am__untar@ am__xargs_n = @am__xargs_n@ bindir = @bindir@ build = @build@ build_alias = @build_alias@ build_cpu = @build_cpu@ build_os = @build_os@ build_vendor = @build_vendor@ builddir = @builddir@ datadir = @datadir@ datarootdir = @datarootdir@ docdir = @docdir@ dvidir = @dvidir@ exec_prefix = @exec_prefix@ host = @host@ host_alias = @host_alias@ host_cpu = @host_cpu@ host_os = @host_os@ host_vendor = @host_vendor@ htmldir = @htmldir@ includedir = @includedir@ infodir = @infodir@ install_sh = @install_sh@ libdir = @libdir@ libexecdir = @libexecdir@ localedir = @localedir@ localstatedir = @localstatedir@ mandir = @mandir@ mkdir_p = @mkdir_p@ ntfs3gincludedir = @ntfs3gincludedir@ oldincludedir = @oldincludedir@ pdfdir = @pdfdir@ pkgconfigdir = @pkgconfigdir@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ rootbindir = @rootbindir@ rootlibdir = @rootlibdir@ rootsbindir = @rootsbindir@ runstatedir = @runstatedir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ sysconfdir = @sysconfdir@ target = @target@ target_alias = @target_alias@ target_cpu = @target_cpu@ target_os = @target_os@ target_vendor = @target_vendor@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ MAINTAINERCLEANFILES = Makefile.in noinst_HEADERS = \ fuse.h \ fuse_common.h \ fuse_lowlevel.h \ fuse_lowlevel_compat.h \ fuse_opt.h \ fuse_kernel.h all: all-am .SUFFIXES: $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) @for dep in $?; do \ case '$(am__configure_deps)' in \ *$$dep*) \ ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ && { if test -f $@; then exit 0; else break; fi; }; \ exit 1;; \ esac; \ done; \ echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu include/fuse-lite/Makefile'; \ $(am__cd) $(top_srcdir) && \ $(AUTOMAKE) --gnu include/fuse-lite/Makefile Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status @case '$?' in \ *config.status*) \ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ *) \ echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles)'; \ cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles);; \ esac; $(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh $(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh $(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh $(am__aclocal_m4_deps): mostlyclean-libtool: -rm -f *.lo clean-libtool: -rm -rf .libs _libs ID: $(am__tagged_files) $(am__define_uniq_tagged_files); mkid -fID $$unique tags: tags-am TAGS: tags tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) set x; \ here=`pwd`; \ $(am__define_uniq_tagged_files); \ shift; \ if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ test -n "$$unique" || unique=$$empty_fix; \ if test $$# -gt 0; then \ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ "$$@" $$unique; \ else \ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ $$unique; \ fi; \ fi ctags: ctags-am CTAGS: ctags ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) $(am__define_uniq_tagged_files); \ test -z "$(CTAGS_ARGS)$$unique" \ || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ $$unique GTAGS: here=`$(am__cd) $(top_builddir) && pwd` \ && $(am__cd) $(top_srcdir) \ && gtags -i $(GTAGS_ARGS) "$$here" cscopelist: cscopelist-am cscopelist-am: $(am__tagged_files) list='$(am__tagged_files)'; \ case "$(srcdir)" in \ [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \ *) sdir=$(subdir)/$(srcdir) ;; \ esac; \ for i in $$list; do \ if test -f "$$i"; then \ echo "$(subdir)/$$i"; \ else \ echo "$$sdir/$$i"; \ fi; \ done >> $(top_builddir)/cscope.files distclean-tags: -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags distdir: $(BUILT_SOURCES) $(MAKE) $(AM_MAKEFLAGS) distdir-am distdir-am: $(DISTFILES) @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ list='$(DISTFILES)'; \ dist_files=`for file in $$list; do echo $$file; done | \ sed -e "s|^$$srcdirstrip/||;t" \ -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ case $$dist_files in \ */*) $(MKDIR_P) `echo "$$dist_files" | \ sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ sort -u` ;; \ esac; \ for file in $$dist_files; do \ if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ if test -d $$d/$$file; then \ dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ if test -d "$(distdir)/$$file"; then \ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ fi; \ if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ fi; \ cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ else \ test -f "$(distdir)/$$file" \ || cp -p $$d/$$file "$(distdir)/$$file" \ || exit 1; \ fi; \ done check-am: all-am check: check-am all-am: Makefile $(HEADERS) installdirs: install: install-am install-exec: install-exec-am install-data: install-data-am uninstall: uninstall-am install-am: all-am @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am installcheck: installcheck-am install-strip: if test -z '$(STRIP)'; then \ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ install; \ else \ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ fi mostlyclean-generic: clean-generic: distclean-generic: -$(am__rm_f) $(CONFIG_CLEAN_FILES) -test . = "$(srcdir)" || $(am__rm_f) $(CONFIG_CLEAN_VPATH_FILES) maintainer-clean-generic: @echo "This command is intended for maintainers to use" @echo "it deletes files that may require special tools to rebuild." -$(am__rm_f) $(MAINTAINERCLEANFILES) clean: clean-am clean-am: clean-generic clean-libtool mostlyclean-am distclean: distclean-am -rm -f Makefile distclean-am: clean-am distclean-generic distclean-tags dvi: dvi-am dvi-am: html: html-am html-am: info: info-am info-am: install-data-am: install-dvi: install-dvi-am install-dvi-am: install-exec-am: install-html: install-html-am install-html-am: install-info: install-info-am install-info-am: install-man: install-pdf: install-pdf-am install-pdf-am: install-ps: install-ps-am install-ps-am: installcheck-am: maintainer-clean: maintainer-clean-am -rm -f Makefile maintainer-clean-am: distclean-am maintainer-clean-generic mostlyclean: mostlyclean-am mostlyclean-am: mostlyclean-generic mostlyclean-libtool pdf: pdf-am pdf-am: ps: ps-am ps-am: uninstall-am: .MAKE: install-am install-strip .PHONY: CTAGS GTAGS TAGS all all-am check check-am clean clean-generic \ clean-libtool cscopelist-am ctags ctags-am distclean \ distclean-generic distclean-libtool distclean-tags distdir dvi \ dvi-am html html-am info info-am install install-am \ install-data install-data-am install-dvi install-dvi-am \ install-exec install-exec-am install-html install-html-am \ install-info install-info-am install-man install-pdf \ install-pdf-am install-ps install-ps-am install-strip \ installcheck installcheck-am installdirs maintainer-clean \ maintainer-clean-generic mostlyclean mostlyclean-generic \ mostlyclean-libtool pdf pdf-am ps ps-am tags tags-am uninstall \ uninstall-am .PRECIOUS: Makefile # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. .NOEXPORT: # Tell GNU make to disable its built-in pattern rules. %:: %,v %:: RCS/%,v %:: RCS/% %:: s.% %:: SCCS/s.% ntfs-3g-2026.2.25/include/fuse-lite/fuse_lowlevel_compat.h0000664000175000017500000000070215152260173016706 /* FUSE: Filesystem in Userspace Copyright (C) 2001-2007 Miklos Szeredi This program can be distributed under the terms of the GNU LGPLv2. See the file COPYING.LIB. */ /* these definitions provide source compatibility to prior versions. Do not include this file directly! */ size_t fuse_dirent_size(size_t namelen); char *fuse_add_dirent(char *buf, const char *name, const struct stat *stbuf, off_t off); ntfs-3g-2026.2.25/ltmain.sh0000755000175000017500000122300715152260210010616 #! /usr/bin/env sh ## DO NOT EDIT - This file generated from ./build-aux/ltmain.in ## by inline-source v2019-02-19.15 # libtool (GNU libtool) 2.5.4 # Provide generalized library-building support services. # Written by Gordon Matzigkeit , 1996 # Copyright (C) 1996-2019, 2021-2024 Free Software Foundation, Inc. # This is free software; see the source for copying conditions. There is NO # warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # GNU Libtool 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. # # As a special exception to the GNU General Public License, # if you distribute this file as part of a program or library that # is built using GNU Libtool, you may include this file under the # same distribution terms that you use for the rest of that program. # # GNU Libtool 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. If not, see . PROGRAM=libtool PACKAGE=libtool VERSION="2.5.4 Debian-2.5.4-4build1" package_revision=2.5.4 ## ------ ## ## Usage. ## ## ------ ## # Run './libtool --help' for help with using this script from the # command line. ## ------------------------------- ## ## User overridable command paths. ## ## ------------------------------- ## # After configure completes, it has a better idea of some of the # shell tools we need than the defaults used by the functions shared # with bootstrap, so set those here where they can still be over- # ridden by the user, but otherwise take precedence. : ${AUTOCONF="autoconf"} : ${AUTOMAKE="automake"} ## -------------------------- ## ## Source external libraries. ## ## -------------------------- ## # Much of our low-level functionality needs to be sourced from external # libraries, which are installed to $pkgauxdir. # Set a version string for this script. scriptversion=2024-12-01.17; # UTC # General shell script boiler plate, and helper functions. # Written by Gary V. Vaughan, 2004 # This is free software. There is NO warranty; not even for # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # # Copyright (C) 2004-2019, 2021, 2023-2024 Bootstrap Authors # # This file is dual licensed under the terms of the MIT license # , and GPL version 2 or later # . You must apply one of # these licenses when using or redistributing this software or any of # the files within it. See the URLs above, or the file `LICENSE` # included in the Bootstrap distribution for the full license texts. # Please report bugs or propose patches to: # ## ------ ## ## Usage. ## ## ------ ## # Evaluate this file near the top of your script to gain access to # the functions and variables defined here: # # . `echo "$0" | ${SED-sed} 's|[^/]*$||'`/build-aux/funclib.sh # # If you need to override any of the default environment variable # settings, do that before evaluating this file. ## -------------------- ## ## Shell normalisation. ## ## -------------------- ## # Some shells need a little help to be as Bourne compatible as possible. # Before doing anything else, make sure all that help has been provided! DUALCASE=1; export DUALCASE # for MKS sh if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then : emulate sh NULLCMD=: # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which # is contrary to our usage. Disable this feature. alias -g '${1+"$@"}'='"$@"' setopt NO_GLOB_SUBST else case `(set -o) 2>/dev/null` in *posix*) set -o posix ;; esac fi # NLS nuisances: We save the old values in case they are required later. _G_user_locale= _G_safe_locale= for _G_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES do eval "if test set = \"\${$_G_var+set}\"; then save_$_G_var=\$$_G_var $_G_var=C export $_G_var _G_user_locale=\"$_G_var=\\\$save_\$_G_var; \$_G_user_locale\" _G_safe_locale=\"$_G_var=C; \$_G_safe_locale\" fi" done # These NLS vars are set unconditionally (bootstrap issue #24). Unset those # in case the environment reset is needed later and the $save_* variant is not # defined (see the code above). LC_ALL=C LANGUAGE=C export LANGUAGE LC_ALL # Make sure IFS has a sensible default sp=' ' nl=' ' IFS="$sp $nl" # There are apparently some systems that use ';' as a PATH separator! if test "${PATH_SEPARATOR+set}" != set; then PATH_SEPARATOR=: (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && { (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 || PATH_SEPARATOR=';' } fi # func_unset VAR # -------------- # Portably unset VAR. # In some shells, an 'unset VAR' statement leaves a non-zero return # status if VAR is already unset, which might be problematic if the # statement is used at the end of a function (thus poisoning its return # value) or when 'set -e' is active (causing even a spurious abort of # the script in this case). func_unset () { { eval $1=; (eval unset $1) >/dev/null 2>&1 && eval unset $1 || : ; } } # Make sure CDPATH doesn't cause `cd` commands to output the target dir. func_unset CDPATH # Make sure ${,E,F}GREP behave sanely. func_unset GREP_OPTIONS ## ------------------------- ## ## Locate command utilities. ## ## ------------------------- ## # func_executable_p FILE # ---------------------- # Check that FILE is an executable regular file. func_executable_p () { test -f "$1" && test -x "$1" } # func_path_progs PROGS_LIST CHECK_FUNC [PATH] # -------------------------------------------- # Search for either a program that responds to --version with output # containing "GNU", or else returned by CHECK_FUNC otherwise, by # trying all the directories in PATH with each of the elements of # PROGS_LIST. # # CHECK_FUNC should accept the path to a candidate program, and # set $func_check_prog_result if it truncates its output less than # $_G_path_prog_max characters. func_path_progs () { _G_progs_list=$1 _G_check_func=$2 _G_PATH=${3-"$PATH"} _G_path_prog_max=0 _G_path_prog_found=false _G_save_IFS=$IFS; IFS=${PATH_SEPARATOR-:} for _G_dir in $_G_PATH; do IFS=$_G_save_IFS test -z "$_G_dir" && _G_dir=. for _G_prog_name in $_G_progs_list; do for _exeext in '' .EXE; do _G_path_prog=$_G_dir/$_G_prog_name$_exeext func_executable_p "$_G_path_prog" || continue case `"$_G_path_prog" --version 2>&1` in *GNU*) func_path_progs_result=$_G_path_prog _G_path_prog_found=: ;; *) $_G_check_func $_G_path_prog func_path_progs_result=$func_check_prog_result ;; esac $_G_path_prog_found && break 3 done done done IFS=$_G_save_IFS test -z "$func_path_progs_result" && { echo "no acceptable sed could be found in \$PATH" >&2 exit 1 } } # We want to be able to use the functions in this file before configure # has figured out where the best binaries are kept, which means we have # to search for them ourselves - except when the results are already set # where we skip the searches. # Unless the user overrides by setting SED, search the path for either GNU # sed, or the sed that truncates its output the least. test -z "$SED" && { _G_sed_script=s/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/ for _G_i in 1 2 3 4 5 6 7; do _G_sed_script=$_G_sed_script$nl$_G_sed_script done echo "$_G_sed_script" 2>/dev/null | sed 99q >conftest.sed _G_sed_script= func_check_prog_sed () { _G_path_prog=$1 _G_count=0 printf 0123456789 >conftest.in while : do cat conftest.in conftest.in >conftest.tmp mv conftest.tmp conftest.in cp conftest.in conftest.nl echo '' >> conftest.nl "$_G_path_prog" -f conftest.sed conftest.out 2>/dev/null || break diff conftest.out conftest.nl >/dev/null 2>&1 || break _G_count=`expr $_G_count + 1` if test "$_G_count" -gt "$_G_path_prog_max"; then # Best one so far, save it but keep looking for a better one func_check_prog_result=$_G_path_prog _G_path_prog_max=$_G_count fi # 10*(2^10) chars as input seems more than enough test 10 -lt "$_G_count" && break done rm -f conftest.in conftest.tmp conftest.nl conftest.out } func_path_progs "sed gsed" func_check_prog_sed "$PATH:/usr/xpg4/bin" rm -f conftest.sed SED=$func_path_progs_result } # Unless the user overrides by setting GREP, search the path for either GNU # grep, or the grep that truncates its output the least. test -z "$GREP" && { func_check_prog_grep () { _G_path_prog=$1 _G_count=0 _G_path_prog_max=0 printf 0123456789 >conftest.in while : do cat conftest.in conftest.in >conftest.tmp mv conftest.tmp conftest.in cp conftest.in conftest.nl echo 'GREP' >> conftest.nl "$_G_path_prog" -e 'GREP$' -e '-(cannot match)-' conftest.out 2>/dev/null || break diff conftest.out conftest.nl >/dev/null 2>&1 || break _G_count=`expr $_G_count + 1` if test "$_G_count" -gt "$_G_path_prog_max"; then # Best one so far, save it but keep looking for a better one func_check_prog_result=$_G_path_prog _G_path_prog_max=$_G_count fi # 10*(2^10) chars as input seems more than enough test 10 -lt "$_G_count" && break done rm -f conftest.in conftest.tmp conftest.nl conftest.out } func_path_progs "grep ggrep" func_check_prog_grep "$PATH:/usr/xpg4/bin" GREP=$func_path_progs_result } ## ------------------------------- ## ## User overridable command paths. ## ## ------------------------------- ## # All uppercase variable names are used for environment variables. These # variables can be overridden by the user before calling a script that # uses them if a suitable command of that name is not already available # in the command search PATH. : ${CP="cp -f"} : ${ECHO="printf %s\n"} : ${EGREP="$GREP -E"} : ${FGREP="$GREP -F"} : ${LN_S="ln -s"} : ${MAKE="make"} : ${MKDIR="mkdir"} : ${MV="mv -f"} : ${RM="rm -f"} : ${SHELL="${CONFIG_SHELL-/bin/sh}"} ## -------------------- ## ## Useful sed snippets. ## ## -------------------- ## sed_dirname='s|/[^/]*$||' sed_basename='s|^.*/||' # Sed substitution that helps us do robust quoting. It backslashifies # metacharacters that are still active within double-quoted strings. sed_quote_subst='s|\([`"$\\]\)|\\\1|g' # Same as above, but do not quote variable references. sed_double_quote_subst='s/\(["`\\]\)/\\\1/g' # Sed substitution that turns a string into a regex matching for the # string literally. sed_make_literal_regex='s|[].[^$\\*\/]|\\&|g' # Sed substitution that converts a w32 file name or path # that contains forward slashes, into one that contains # (escaped) backslashes. A very naive implementation. sed_naive_backslashify='s|\\\\*|\\|g;s|/|\\|g;s|\\|\\\\|g' # Re-'\' parameter expansions in output of sed_double_quote_subst that # were '\'-ed in input to the same. If an odd number of '\' preceded a # '$' in input to sed_double_quote_subst, that '$' was protected from # expansion. Since each input '\' is now two '\'s, look for any number # of runs of four '\'s followed by two '\'s and then a '$'. '\' that '$'. _G_bs='\\' _G_bs2='\\\\' _G_bs4='\\\\\\\\' _G_dollar='\$' sed_double_backslash="\ s/$_G_bs4/&\\ /g s/^$_G_bs2$_G_dollar/$_G_bs&/ s/\\([^$_G_bs]\\)$_G_bs2$_G_dollar/\\1$_G_bs2$_G_bs$_G_dollar/g s/\n//g" # require_check_ifs_backslash # --------------------------- # Check if we can use backslash as IFS='\' separator, and set # $check_ifs_backshlash_broken to ':' or 'false'. require_check_ifs_backslash=func_require_check_ifs_backslash func_require_check_ifs_backslash () { _G_save_IFS=$IFS IFS='\' _G_check_ifs_backshlash='a\\b' for _G_i in $_G_check_ifs_backshlash do case $_G_i in a) check_ifs_backshlash_broken=false ;; '') break ;; *) check_ifs_backshlash_broken=: break ;; esac done IFS=$_G_save_IFS require_check_ifs_backslash=: } ## ----------------- ## ## Global variables. ## ## ----------------- ## # Except for the global variables explicitly listed below, the following # functions in the '^func_' namespace, and the '^require_' namespace # variables initialised in the 'Resource management' section, sourcing # this file will not pollute your global namespace with anything # else. There's no portable way to scope variables in Bourne shell # though, so actually running these functions will sometimes place # results into a variable named after the function, and often use # temporary variables in the '^_G_' namespace. If you are careful to # avoid using those namespaces casually in your sourcing script, things # should continue to work as you expect. And, of course, you can freely # overwrite any of the functions or variables defined here before # calling anything to customize them. EXIT_SUCCESS=0 EXIT_FAILURE=1 EXIT_MISMATCH=63 # $? = 63 is used to indicate version mismatch to missing. EXIT_SKIP=77 # $? = 77 is used to indicate a skipped test to automake. # Allow overriding, eg assuming that you follow the convention of # putting '$debug_cmd' at the start of all your functions, you can get # bash to show function call trace with: # # debug_cmd='echo "${FUNCNAME[0]} $*" >&2' bash your-script-name debug_cmd=${debug_cmd-":"} exit_cmd=: # By convention, finish your script with: # # exit $exit_status # # so that you can set exit_status to non-zero if you want to indicate # something went wrong during execution without actually bailing out at # the point of failure. exit_status=$EXIT_SUCCESS # Work around backward compatibility issue on IRIX 6.5. On IRIX 6.4+, sh # is ksh but when the shell is invoked as "sh" and the current value of # the _XPG environment variable is not equal to 1 (one), the special # positional parameter $0, within a function call, is the name of the # function. progpath=$0 # The name of this program. progname=`$ECHO "$progpath" |$SED "$sed_basename"` # Make sure we have an absolute progpath for reexecution: case $progpath in [\\/]*|[A-Za-z]:\\*) ;; *[\\/]*) progdir=`$ECHO "$progpath" |$SED "$sed_dirname"` progdir=`cd "$progdir" && pwd` progpath=$progdir/$progname ;; *) _G_IFS=$IFS IFS=${PATH_SEPARATOR-:} for progdir in $PATH; do IFS=$_G_IFS test -x "$progdir/$progname" && break done IFS=$_G_IFS test -n "$progdir" || progdir=`pwd` progpath=$progdir/$progname ;; esac ## ----------------- ## ## Standard options. ## ## ----------------- ## # The following options affect the operation of the functions defined # below, and should be set appropriately depending on run-time para- # meters passed on the command line. opt_dry_run=false opt_quiet=false opt_verbose=false # Categories 'all' and 'none' are always available. Append any others # you will pass as the first argument to func_warning from your own # code. warning_categories= # By default, display warnings according to 'opt_warning_types'. Set # 'warning_func' to ':' to elide all warnings, or func_fatal_error to # treat the next displayed warning as a fatal error. warning_func=func_warn_and_continue # Set to 'all' to display all warnings, 'none' to suppress all # warnings, or a space delimited list of some subset of # 'warning_categories' to display only the listed warnings. opt_warning_types=all ## -------------------- ## ## Resource management. ## ## -------------------- ## # This section contains definitions for functions that each ensure a # particular resource (a file, or a non-empty configuration variable for # example) is available, and if appropriate to extract default values # from pertinent package files. Call them using their associated # 'require_*' variable to ensure that they are executed, at most, once. # # It's entirely deliberate that calling these functions can set # variables that don't obey the namespace limitations obeyed by the rest # of this file, in order that that they be as useful as possible to # callers. # require_term_colors # ------------------- # Allow display of bold text on terminals that support it. require_term_colors=func_require_term_colors func_require_term_colors () { $debug_cmd test -t 1 && { # COLORTERM and USE_ANSI_COLORS environment variables take # precedence, because most terminfo databases neglect to describe # whether color sequences are supported. test -n "${COLORTERM+set}" && : ${USE_ANSI_COLORS="1"} if test 1 = "$USE_ANSI_COLORS"; then # Standard ANSI escape sequences tc_reset='' tc_bold=''; tc_standout='' tc_red=''; tc_green='' tc_blue=''; tc_cyan='' else # Otherwise trust the terminfo database after all. test -n "`tput sgr0 2>/dev/null`" && { tc_reset=`tput sgr0` test -n "`tput bold 2>/dev/null`" && tc_bold=`tput bold` tc_standout=$tc_bold test -n "`tput smso 2>/dev/null`" && tc_standout=`tput smso` test -n "`tput setaf 1 2>/dev/null`" && tc_red=`tput setaf 1` test -n "`tput setaf 2 2>/dev/null`" && tc_green=`tput setaf 2` test -n "`tput setaf 4 2>/dev/null`" && tc_blue=`tput setaf 4` test -n "`tput setaf 5 2>/dev/null`" && tc_cyan=`tput setaf 5` } fi } require_term_colors=: } ## ----------------- ## ## Function library. ## ## ----------------- ## # This section contains a variety of useful functions to call in your # scripts. Take note of the portable wrappers for features provided by # some modern shells, which will fall back to slower equivalents on # less featureful shells. # func_append VAR VALUE # --------------------- # Append VALUE onto the existing contents of VAR. # _G_HAVE_PLUSEQ_OP # Can be empty, in which case the shell is probed, "yes" if += is # usable or anything else if it does not work. if test -z "$_G_HAVE_PLUSEQ_OP" && \ __PLUSEQ_TEST="a" && \ __PLUSEQ_TEST+=" b" 2>/dev/null && \ test "a b" = "$__PLUSEQ_TEST"; then _G_HAVE_PLUSEQ_OP=yes fi if test yes = "$_G_HAVE_PLUSEQ_OP" then # This is an XSI compatible shell, allowing a faster implementation... eval 'func_append () { $debug_cmd eval "$1+=\$2" }' else # ...otherwise fall back to using expr, which is often a shell builtin. func_append () { $debug_cmd eval "$1=\$$1\$2" } fi # func_append_quoted VAR VALUE # ---------------------------- # Quote VALUE and append to the end of shell variable VAR, separated # by a space. if test yes = "$_G_HAVE_PLUSEQ_OP"; then eval 'func_append_quoted () { $debug_cmd func_quote_arg pretty "$2" eval "$1+=\\ \$func_quote_arg_result" }' else func_append_quoted () { $debug_cmd func_quote_arg pretty "$2" eval "$1=\$$1\\ \$func_quote_arg_result" } fi # func_append_uniq VAR VALUE # -------------------------- # Append unique VALUE onto the existing contents of VAR, assuming # entries are delimited by the first character of VALUE. For example: # # func_append_uniq options " --another-option option-argument" # # will only append to $options if " --another-option option-argument " # is not already present somewhere in $options already (note spaces at # each end implied by leading space in second argument). func_append_uniq () { $debug_cmd eval _G_current_value='`$ECHO $'$1'`' _G_delim=`expr "$2" : '\(.\)'` case $_G_delim$_G_current_value$_G_delim in *"$2$_G_delim"*) ;; *) func_append "$@" ;; esac } # func_arith TERM... # ------------------ # Set func_arith_result to the result of evaluating TERMs. test -z "$_G_HAVE_ARITH_OP" \ && (eval 'test 2 = $(( 1 + 1 ))') 2>/dev/null \ && _G_HAVE_ARITH_OP=yes if test yes = "$_G_HAVE_ARITH_OP"; then eval 'func_arith () { $debug_cmd func_arith_result=$(( $* )) }' else func_arith () { $debug_cmd func_arith_result=`expr "$@"` } fi # func_basename FILE # ------------------ # Set func_basename_result to FILE with everything up to and including # the last / stripped. if test yes = "$_G_HAVE_XSI_OPS"; then # If this shell supports suffix pattern removal, then use it to avoid # forking. Hide the definitions single quotes in case the shell chokes # on unsupported syntax... _b='func_basename_result=${1##*/}' _d='case $1 in */*) func_dirname_result=${1%/*}$2 ;; * ) func_dirname_result=$3 ;; esac' else # ...otherwise fall back to using sed. _b='func_basename_result=`$ECHO "$1" |$SED "$sed_basename"`' _d='func_dirname_result=`$ECHO "$1" |$SED "$sed_dirname"` if test "X$func_dirname_result" = "X$1"; then func_dirname_result=$3 else func_append func_dirname_result "$2" fi' fi eval 'func_basename () { $debug_cmd '"$_b"' }' # func_dirname FILE APPEND NONDIR_REPLACEMENT # ------------------------------------------- # Compute the dirname of FILE. If nonempty, add APPEND to the result, # otherwise set result to NONDIR_REPLACEMENT. eval 'func_dirname () { $debug_cmd '"$_d"' }' # func_dirname_and_basename FILE APPEND NONDIR_REPLACEMENT # -------------------------------------------------------- # Perform func_basename and func_dirname in a single function # call: # dirname: Compute the dirname of FILE. If nonempty, # add APPEND to the result, otherwise set result # to NONDIR_REPLACEMENT. # value returned in "$func_dirname_result" # basename: Compute filename of FILE. # value returned in "$func_basename_result" # For efficiency, we do not delegate to the functions above but instead # duplicate the functionality here. eval 'func_dirname_and_basename () { $debug_cmd '"$_b"' '"$_d"' }' # func_echo ARG... # ---------------- # Echo program name prefixed message. func_echo () { $debug_cmd _G_message=$* func_echo_IFS=$IFS IFS=$nl for _G_line in $_G_message; do IFS=$func_echo_IFS $ECHO "$progname: $_G_line" done IFS=$func_echo_IFS } # func_echo_all ARG... # -------------------- # Invoke $ECHO with all args, space-separated. func_echo_all () { $ECHO "$*" } # func_echo_infix_1 INFIX ARG... # ------------------------------ # Echo program name, followed by INFIX on the first line, with any # additional lines not showing INFIX. func_echo_infix_1 () { $debug_cmd $require_term_colors _G_infix=$1; shift _G_indent=$_G_infix _G_prefix="$progname: $_G_infix: " _G_message=$* # Strip color escape sequences before counting printable length for _G_tc in "$tc_reset" "$tc_bold" "$tc_standout" "$tc_red" "$tc_green" "$tc_blue" "$tc_cyan" do test -n "$_G_tc" && { _G_esc_tc=`$ECHO "$_G_tc" | $SED "$sed_make_literal_regex"` _G_indent=`$ECHO "$_G_indent" | $SED "s|$_G_esc_tc||g"` } done _G_indent="$progname: "`echo "$_G_indent" | $SED 's|.| |g'`" " ## exclude from sc_prohibit_nested_quotes func_echo_infix_1_IFS=$IFS IFS=$nl for _G_line in $_G_message; do IFS=$func_echo_infix_1_IFS $ECHO "$_G_prefix$tc_bold$_G_line$tc_reset" >&2 _G_prefix=$_G_indent done IFS=$func_echo_infix_1_IFS } # func_error ARG... # ----------------- # Echo program name prefixed message to standard error. func_error () { $debug_cmd $require_term_colors func_echo_infix_1 " $tc_standout${tc_red}error$tc_reset" "$*" >&2 } # func_fatal_error ARG... # ----------------------- # Echo program name prefixed message to standard error, and exit. func_fatal_error () { $debug_cmd func_error "$*" exit $EXIT_FAILURE } # func_grep EXPRESSION FILENAME # ----------------------------- # Check whether EXPRESSION matches any line of FILENAME, without output. func_grep () { $debug_cmd $GREP "$1" "$2" >/dev/null 2>&1 } # func_len STRING # --------------- # Set func_len_result to the length of STRING. STRING may not # start with a hyphen. test -z "$_G_HAVE_XSI_OPS" \ && (eval 'x=a/b/c; test 5aa/bb/cc = "${#x}${x%%/*}${x%/*}${x#*/}${x##*/}"') 2>/dev/null \ && _G_HAVE_XSI_OPS=yes if test yes = "$_G_HAVE_XSI_OPS"; then eval 'func_len () { $debug_cmd func_len_result=${#1} }' else func_len () { $debug_cmd func_len_result=`expr "$1" : ".*" 2>/dev/null || echo $max_cmd_len` } fi # func_mkdir_p DIRECTORY-PATH # --------------------------- # Make sure the entire path to DIRECTORY-PATH is available. func_mkdir_p () { $debug_cmd _G_directory_path=$1 _G_dir_list= if test -n "$_G_directory_path" && test : != "$opt_dry_run"; then # Protect directory names starting with '-' case $_G_directory_path in -*) _G_directory_path=./$_G_directory_path ;; esac # While some portion of DIR does not yet exist... while test ! -d "$_G_directory_path"; do # ...make a list in topmost first order. Use a colon delimited # list in case some portion of path contains whitespace. _G_dir_list=$_G_directory_path:$_G_dir_list # If the last portion added has no slash in it, the list is done case $_G_directory_path in */*) ;; *) break ;; esac # ...otherwise throw away the child directory and loop _G_directory_path=`$ECHO "$_G_directory_path" | $SED -e "$sed_dirname"` done _G_dir_list=`$ECHO "$_G_dir_list" | $SED 's|:*$||'` func_mkdir_p_IFS=$IFS; IFS=: for _G_dir in $_G_dir_list; do IFS=$func_mkdir_p_IFS # mkdir can fail with a 'File exist' error if two processes # try to create one of the directories concurrently. Don't # stop in that case! $MKDIR "$_G_dir" 2>/dev/null || : done IFS=$func_mkdir_p_IFS # Bail out if we (or some other process) failed to create a directory. test -d "$_G_directory_path" || \ func_fatal_error "Failed to create '$1'" fi } # func_mktempdir [BASENAME] # ------------------------- # Make a temporary directory that won't clash with other running # libtool processes, and avoids race conditions if possible. If # given, BASENAME is the basename for that directory. func_mktempdir () { $debug_cmd _G_template=${TMPDIR-/tmp}/${1-$progname} if test : = "$opt_dry_run"; then # Return a directory name, but don't create it in dry-run mode _G_tmpdir=$_G_template-$$ else # If mktemp works, use that first and foremost _G_tmpdir=`mktemp -d "$_G_template-XXXXXXXX" 2>/dev/null` if test ! -d "$_G_tmpdir"; then # Failing that, at least try and use $RANDOM to avoid a race _G_tmpdir=$_G_template-${RANDOM-0}$$ func_mktempdir_umask=`umask` umask 0077 $MKDIR "$_G_tmpdir" umask $func_mktempdir_umask fi # If we're not in dry-run mode, bomb out on failure test -d "$_G_tmpdir" || \ func_fatal_error "cannot create temporary directory '$_G_tmpdir'" fi $ECHO "$_G_tmpdir" } # func_normal_abspath PATH # ------------------------ # Remove doubled-up and trailing slashes, "." path components, # and cancel out any ".." path components in PATH after making # it an absolute path. func_normal_abspath () { $debug_cmd # These SED scripts presuppose an absolute path with a trailing slash. _G_pathcar='s|^/\([^/]*\).*$|\1|' _G_pathcdr='s|^/[^/]*||' _G_removedotparts=':dotsl s|/\./|/|g t dotsl s|/\.$|/|' _G_collapseslashes='s|/\{1,\}|/|g' _G_finalslash='s|/*$|/|' # Start from root dir and reassemble the path. func_normal_abspath_result= func_normal_abspath_tpath=$1 func_normal_abspath_altnamespace= case $func_normal_abspath_tpath in "") # Empty path, that just means $cwd. func_stripname '' '/' "`pwd`" func_normal_abspath_result=$func_stripname_result return ;; # The next three entries are used to spot a run of precisely # two leading slashes without using negated character classes; # we take advantage of case's first-match behaviour. ///*) # Unusual form of absolute path, do nothing. ;; //*) # Not necessarily an ordinary path; POSIX reserves leading '//' # and for example Cygwin uses it to access remote file shares # over CIFS/SMB, so we conserve a leading double slash if found. func_normal_abspath_altnamespace=/ ;; /*) # Absolute path, do nothing. ;; *) # Relative path, prepend $cwd. func_normal_abspath_tpath=`pwd`/$func_normal_abspath_tpath ;; esac # Cancel out all the simple stuff to save iterations. We also want # the path to end with a slash for ease of parsing, so make sure # there is one (and only one) here. func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \ -e "$_G_removedotparts" -e "$_G_collapseslashes" -e "$_G_finalslash"` while :; do # Processed it all yet? if test / = "$func_normal_abspath_tpath"; then # If we ascended to the root using ".." the result may be empty now. if test -z "$func_normal_abspath_result"; then func_normal_abspath_result=/ fi break fi func_normal_abspath_tcomponent=`$ECHO "$func_normal_abspath_tpath" | $SED \ -e "$_G_pathcar"` func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \ -e "$_G_pathcdr"` # Figure out what to do with it case $func_normal_abspath_tcomponent in "") # Trailing empty path component, ignore it. ;; ..) # Parent dir; strip last assembled component from result. func_dirname "$func_normal_abspath_result" func_normal_abspath_result=$func_dirname_result ;; *) # Actual path component, append it. func_append func_normal_abspath_result "/$func_normal_abspath_tcomponent" ;; esac done # Restore leading double-slash if one was found on entry. func_normal_abspath_result=$func_normal_abspath_altnamespace$func_normal_abspath_result } # func_notquiet ARG... # -------------------- # Echo program name prefixed message only when not in quiet mode. func_notquiet () { $debug_cmd $opt_quiet || func_echo ${1+"$@"} # A bug in bash halts the script if the last line of a function # fails when set -e is in force, so we need another command to # work around that: : } # func_relative_path SRCDIR DSTDIR # -------------------------------- # Set func_relative_path_result to the relative path from SRCDIR to DSTDIR. func_relative_path () { $debug_cmd func_relative_path_result= func_normal_abspath "$1" func_relative_path_tlibdir=$func_normal_abspath_result func_normal_abspath "$2" func_relative_path_tbindir=$func_normal_abspath_result # Ascend the tree starting from libdir while :; do # check if we have found a prefix of bindir case $func_relative_path_tbindir in $func_relative_path_tlibdir) # found an exact match func_relative_path_tcancelled= break ;; $func_relative_path_tlibdir*) # found a matching prefix func_stripname "$func_relative_path_tlibdir" '' "$func_relative_path_tbindir" func_relative_path_tcancelled=$func_stripname_result if test -z "$func_relative_path_result"; then func_relative_path_result=. fi break ;; *) func_dirname $func_relative_path_tlibdir func_relative_path_tlibdir=$func_dirname_result if test -z "$func_relative_path_tlibdir"; then # Have to descend all the way to the root! func_relative_path_result=../$func_relative_path_result func_relative_path_tcancelled=$func_relative_path_tbindir break fi func_relative_path_result=../$func_relative_path_result ;; esac done # Now calculate path; take care to avoid doubling-up slashes. func_stripname '' '/' "$func_relative_path_result" func_relative_path_result=$func_stripname_result func_stripname '/' '/' "$func_relative_path_tcancelled" if test -n "$func_stripname_result"; then func_append func_relative_path_result "/$func_stripname_result" fi # Normalisation. If bindir is libdir, return '.' else relative path. if test -n "$func_relative_path_result"; then func_stripname './' '' "$func_relative_path_result" func_relative_path_result=$func_stripname_result fi test -n "$func_relative_path_result" || func_relative_path_result=. : } # func_quote_portable EVAL ARG # ---------------------------- # Internal function to portably implement func_quote_arg. Note that we still # keep attention to performance here so we as much as possible try to avoid # calling sed binary (so far O(N) complexity as long as func_append is O(1)). func_quote_portable () { $debug_cmd $require_check_ifs_backslash func_quote_portable_result=$2 # one-time-loop (easy break) while true do if $1; then func_quote_portable_result=`$ECHO "$2" | $SED \ -e "$sed_double_quote_subst" -e "$sed_double_backslash"` break fi # Quote for eval. case $func_quote_portable_result in *[\\\`\"\$]*) # Fallback to sed for $func_check_bs_ifs_broken=:, or when the string # contains the shell wildcard characters. case $check_ifs_backshlash_broken$func_quote_portable_result in :*|*[\[\*\?]*) func_quote_portable_result=`$ECHO "$func_quote_portable_result" \ | $SED "$sed_quote_subst"` break ;; esac func_quote_portable_old_IFS=$IFS for _G_char in '\' '`' '"' '$' do # STATE($1) PREV($2) SEPARATOR($3) set start "" "" func_quote_portable_result=dummy"$_G_char$func_quote_portable_result$_G_char"dummy IFS=$_G_char for _G_part in $func_quote_portable_result do case $1 in quote) func_append func_quote_portable_result "$3$2" set quote "$_G_part" "\\$_G_char" ;; start) set first "" "" func_quote_portable_result= ;; first) set quote "$_G_part" "" ;; esac done done IFS=$func_quote_portable_old_IFS ;; *) ;; esac break done func_quote_portable_unquoted_result=$func_quote_portable_result case $func_quote_portable_result in # double-quote args containing shell metacharacters to delay # word splitting, command substitution and variable expansion # for a subsequent eval. # many bourne shells cannot handle close brackets correctly # in scan sets, so we specify it separately. *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") func_quote_portable_result=\"$func_quote_portable_result\" ;; esac } # func_quotefast_eval ARG # ----------------------- # Quote one ARG (internal). This is equivalent to 'func_quote_arg eval ARG', # but optimized for speed. Result is stored in $func_quotefast_eval. if test xyes = `(x=; printf -v x %q yes; echo x"$x") 2>/dev/null`; then printf -v _GL_test_printf_tilde %q '~' if test '\~' = "$_GL_test_printf_tilde"; then func_quotefast_eval () { printf -v func_quotefast_eval_result %q "$1" } else # Broken older Bash implementations. Make those faster too if possible. func_quotefast_eval () { case $1 in '~'*) func_quote_portable false "$1" func_quotefast_eval_result=$func_quote_portable_result ;; *) printf -v func_quotefast_eval_result %q "$1" ;; esac } fi else func_quotefast_eval () { func_quote_portable false "$1" func_quotefast_eval_result=$func_quote_portable_result } fi # func_quote_arg MODEs ARG # ------------------------ # Quote one ARG to be evaled later. MODEs argument may contain zero or more # specifiers listed below separated by ',' character. This function returns two # values: # i) func_quote_arg_result # double-quoted (when needed), suitable for a subsequent eval # ii) func_quote_arg_unquoted_result # has all characters that are still active within double # quotes backslashified. Available only if 'unquoted' is specified. # # Available modes: # ---------------- # 'eval' (default) # - escape shell special characters # 'expand' # - the same as 'eval'; but do not quote variable references # 'pretty' # - request aesthetic output, i.e. '"a b"' instead of 'a\ b'. This might # be used later in func_quote to get output like: 'echo "a b"' instead # of 'echo a\ b'. This is slower than default on some shells. # 'unquoted' # - produce also $func_quote_arg_unquoted_result which does not contain # wrapping double-quotes. # # Examples for 'func_quote_arg pretty,unquoted string': # # string | *_result | *_unquoted_result # ------------+-----------------------+------------------- # " | \" | \" # a b | "a b" | a b # "a b" | "\"a b\"" | \"a b\" # * | "*" | * # z="${x-$y}" | "z=\"\${x-\$y}\"" | z=\"\${x-\$y}\" # # Examples for 'func_quote_arg pretty,unquoted,expand string': # # string | *_result | *_unquoted_result # --------------+---------------------+-------------------- # z="${x-$y}" | "z=\"${x-$y}\"" | z=\"${x-$y}\" func_quote_arg () { _G_quote_expand=false case ,$1, in *,expand,*) _G_quote_expand=: ;; esac case ,$1, in *,pretty,*|*,expand,*|*,unquoted,*) func_quote_portable $_G_quote_expand "$2" func_quote_arg_result=$func_quote_portable_result func_quote_arg_unquoted_result=$func_quote_portable_unquoted_result ;; *) # Faster quote-for-eval for some shells. func_quotefast_eval "$2" func_quote_arg_result=$func_quotefast_eval_result ;; esac } # func_quote MODEs ARGs... # ------------------------ # Quote all ARGs to be evaled later and join them into single command. See # func_quote_arg's description for more info. func_quote () { $debug_cmd _G_func_quote_mode=$1 ; shift func_quote_result= while test 0 -lt $#; do func_quote_arg "$_G_func_quote_mode" "$1" if test -n "$func_quote_result"; then func_append func_quote_result " $func_quote_arg_result" else func_append func_quote_result "$func_quote_arg_result" fi shift done } # func_stripname PREFIX SUFFIX NAME # --------------------------------- # strip PREFIX and SUFFIX from NAME, and store in func_stripname_result. # PREFIX and SUFFIX must not contain globbing or regex special # characters, hashes, percent signs, but SUFFIX may contain a leading # dot (in which case that matches only a dot). if test yes = "$_G_HAVE_XSI_OPS"; then eval 'func_stripname () { $debug_cmd # pdksh 5.2.14 does not do ${X%$Y} correctly if both X and Y are # positional parameters, so assign one to ordinary variable first. func_stripname_result=$3 func_stripname_result=${func_stripname_result#"$1"} func_stripname_result=${func_stripname_result%"$2"} }' else func_stripname () { $debug_cmd case $2 in .*) func_stripname_result=`$ECHO "$3" | $SED -e "s%^$1%%" -e "s%\\\\$2\$%%"`;; *) func_stripname_result=`$ECHO "$3" | $SED -e "s%^$1%%" -e "s%$2\$%%"`;; esac } fi # func_show_eval CMD [FAIL_EXP] # ----------------------------- # Unless opt_quiet is true, then output CMD. Then, if opt_dryrun is # not true, evaluate CMD. If the evaluation of CMD fails, and FAIL_EXP # is given, then evaluate it. func_show_eval () { $debug_cmd _G_cmd=$1 _G_fail_exp=${2-':'} func_quote_arg pretty,expand "$_G_cmd" eval "func_notquiet $func_quote_arg_result" $opt_dry_run || { eval "$_G_cmd" _G_status=$? if test 0 -ne "$_G_status"; then eval "(exit $_G_status); $_G_fail_exp" fi } } # func_show_eval_locale CMD [FAIL_EXP] # ------------------------------------ # Unless opt_quiet is true, then output CMD. Then, if opt_dryrun is # not true, evaluate CMD. If the evaluation of CMD fails, and FAIL_EXP # is given, then evaluate it. Use the saved locale for evaluation. func_show_eval_locale () { $debug_cmd _G_cmd=$1 _G_fail_exp=${2-':'} $opt_quiet || { func_quote_arg expand,pretty "$_G_cmd" eval "func_echo $func_quote_arg_result" } $opt_dry_run || { eval "$_G_user_locale $_G_cmd" _G_status=$? eval "$_G_safe_locale" if test 0 -ne "$_G_status"; then eval "(exit $_G_status); $_G_fail_exp" fi } } # func_tr_sh # ---------- # Turn $1 into a string suitable for a shell variable name. # Result is stored in $func_tr_sh_result. All characters # not in the set a-zA-Z0-9_ are replaced with '_'. Further, # if $1 begins with a digit, a '_' is prepended as well. func_tr_sh () { $debug_cmd case $1 in [0-9]* | *[!a-zA-Z0-9_]*) func_tr_sh_result=`$ECHO "$1" | $SED -e 's/^\([0-9]\)/_\1/' -e 's/[^a-zA-Z0-9_]/_/g'` ;; * ) func_tr_sh_result=$1 ;; esac } # func_verbose ARG... # ------------------- # Echo program name prefixed message in verbose mode only. func_verbose () { $debug_cmd $opt_verbose && func_echo "$*" : } # func_warn_and_continue ARG... # ----------------------------- # Echo program name prefixed warning message to standard error. func_warn_and_continue () { $debug_cmd $require_term_colors func_echo_infix_1 "${tc_red}warning$tc_reset" "$*" >&2 } # func_warning CATEGORY ARG... # ---------------------------- # Echo program name prefixed warning message to standard error. Warning # messages can be filtered according to CATEGORY, where this function # elides messages where CATEGORY is not listed in the global variable # 'opt_warning_types'. func_warning () { $debug_cmd # CATEGORY must be in the warning_categories list! case " $warning_categories " in *" $1 "*) ;; *) func_internal_error "invalid warning category '$1'" ;; esac _G_category=$1 shift case " $opt_warning_types " in *" $_G_category "*) $warning_func ${1+"$@"} ;; esac } # func_sort_ver VER1 VER2 # ----------------------- # 'sort -V' is not generally available. # Note this deviates from the version comparison in automake # in that it treats 1.5 < 1.5.0, and treats 1.4.4a < 1.4-p3a # but this should suffice as we won't be specifying old # version formats or redundant trailing .0 in bootstrap.conf. # If we did want full compatibility then we should probably # use m4_version_compare from autoconf. func_sort_ver () { $debug_cmd printf '%s\n%s\n' "$1" "$2" \ | sort -t. -k 1,1n -k 2,2n -k 3,3n -k 4,4n -k 5,5n -k 6,6n -k 7,7n -k 8,8n -k 9,9n } # func_lt_ver PREV CURR # --------------------- # Return true if PREV and CURR are in the correct order according to # func_sort_ver, otherwise false. Use it like this: # # func_lt_ver "$prev_ver" "$proposed_ver" || func_fatal_error "..." func_lt_ver () { $debug_cmd test "x$1" = x`func_sort_ver "$1" "$2" | $SED 1q` } # Local variables: # mode: shell-script # sh-indentation: 2 # eval: (add-hook 'before-save-hook 'time-stamp) # time-stamp-pattern: "10/scriptversion=%:y-%02m-%02d.%02H; # UTC" # time-stamp-time-zone: "UTC" # End: #! /bin/sh # A portable, pluggable option parser for Bourne shell. # Written by Gary V. Vaughan, 2010 # This is free software. There is NO warranty; not even for # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # # Copyright (C) 2010-2019, 2021, 2023-2024 Bootstrap Authors # # This file is dual licensed under the terms of the MIT license # , and GPL version 2 or later # . You must apply one of # these licenses when using or redistributing this software or any of # the files within it. See the URLs above, or the file `LICENSE` # included in the Bootstrap distribution for the full license texts. # Please report bugs or propose patches to: # # Set a version string for this script. scriptversion=2019-02-19.15; # UTC ## ------ ## ## Usage. ## ## ------ ## # This file is a library for parsing options in your shell scripts along # with assorted other useful supporting features that you can make use # of too. # # For the simplest scripts you might need only: # # #!/bin/sh # . relative/path/to/funclib.sh # . relative/path/to/options-parser # scriptversion=1.0 # func_options ${1+"$@"} # eval set dummy "$func_options_result"; shift # ...rest of your script... # # In order for the '--version' option to work, you will need to have a # suitably formatted comment like the one at the top of this file # starting with '# Written by ' and ending with '# Copyright'. # # For '-h' and '--help' to work, you will also need a one line # description of your script's purpose in a comment directly above the # '# Written by ' line, like the one at the top of this file. # # The default options also support '--debug', which will turn on shell # execution tracing (see the comment above debug_cmd below for another # use), and '--verbose' and the func_verbose function to allow your script # to display verbose messages only when your user has specified # '--verbose'. # # After sourcing this file, you can plug in processing for additional # options by amending the variables from the 'Configuration' section # below, and following the instructions in the 'Option parsing' # section further down. ## -------------- ## ## Configuration. ## ## -------------- ## # You should override these variables in your script after sourcing this # file so that they reflect the customisations you have added to the # option parser. # The usage line for option parsing errors and the start of '-h' and # '--help' output messages. You can embed shell variables for delayed # expansion at the time the message is displayed, but you will need to # quote other shell meta-characters carefully to prevent them being # expanded when the contents are evaled. usage='$progpath [OPTION]...' # Short help message in response to '-h' and '--help'. Add to this or # override it after sourcing this library to reflect the full set of # options your script accepts. usage_message="\ --debug enable verbose shell tracing -W, --warnings=CATEGORY report the warnings falling in CATEGORY [all] -v, --verbose verbosely report processing --version print version information and exit -h, --help print short or long help message and exit " # Additional text appended to 'usage_message' in response to '--help'. long_help_message=" Warning categories include: 'all' show all warnings 'none' turn off all the warnings 'error' warnings are treated as fatal errors" # Help message printed before fatal option parsing errors. fatal_help="Try '\$progname --help' for more information." ## ------------------------- ## ## Hook function management. ## ## ------------------------- ## # This section contains functions for adding, removing, and running hooks # in the main code. A hook is just a list of function names that can be # run in order later on. # func_hookable FUNC_NAME # ----------------------- # Declare that FUNC_NAME will run hooks added with # 'func_add_hook FUNC_NAME ...'. func_hookable () { $debug_cmd func_append hookable_fns " $1" } # func_add_hook FUNC_NAME HOOK_FUNC # --------------------------------- # Request that FUNC_NAME call HOOK_FUNC before it returns. FUNC_NAME must # first have been declared "hookable" by a call to 'func_hookable'. func_add_hook () { $debug_cmd case " $hookable_fns " in *" $1 "*) ;; *) func_fatal_error "'$1' does not accept hook functions." ;; esac eval func_append ${1}_hooks '" $2"' } # func_remove_hook FUNC_NAME HOOK_FUNC # ------------------------------------ # Remove HOOK_FUNC from the list of hook functions to be called by # FUNC_NAME. func_remove_hook () { $debug_cmd eval ${1}_hooks='`$ECHO "\$'$1'_hooks" |$SED "s| '$2'||"`' } # func_propagate_result FUNC_NAME_A FUNC_NAME_B # --------------------------------------------- # If the *_result variable of FUNC_NAME_A _is set_, assign its value to # *_result variable of FUNC_NAME_B. func_propagate_result () { $debug_cmd func_propagate_result_result=: if eval "test \"\${${1}_result+set}\" = set" then eval "${2}_result=\$${1}_result" else func_propagate_result_result=false fi } # func_run_hooks FUNC_NAME [ARG]... # --------------------------------- # Run all hook functions registered to FUNC_NAME. # It's assumed that the list of hook functions contains nothing more # than a whitespace-delimited list of legal shell function names, and # no effort is wasted trying to catch shell meta-characters or preserve # whitespace. func_run_hooks () { $debug_cmd _G_rc_run_hooks=false case " $hookable_fns " in *" $1 "*) ;; *) func_fatal_error "'$1' does not support hook functions." ;; esac eval _G_hook_fns=\$$1_hooks; shift for _G_hook in $_G_hook_fns; do func_unset "${_G_hook}_result" eval $_G_hook '${1+"$@"}' func_propagate_result $_G_hook func_run_hooks if $func_propagate_result_result; then eval set dummy "$func_run_hooks_result"; shift fi done } ## --------------- ## ## Option parsing. ## ## --------------- ## # In order to add your own option parsing hooks, you must accept the # full positional parameter list from your hook function. You may remove # or edit any options that you action, and then pass back the remaining # unprocessed options in '_result', escaped # suitably for 'eval'. # # The '_result' variable is automatically unset # before your hook gets called; for best performance, only set the # *_result variable when necessary (i.e. don't call the 'func_quote' # function unnecessarily because it can be an expensive operation on some # machines). # # Like this: # # my_options_prep () # { # $debug_cmd # # # Extend the existing usage message. # usage_message=$usage_message' # -s, --silent don'\''t print informational messages # ' # # No change in '$@' (ignored completely by this hook). Leave # # my_options_prep_result variable intact. # } # func_add_hook func_options_prep my_options_prep # # # my_silent_option () # { # $debug_cmd # # args_changed=false # # # Note that, for efficiency, we parse as many options as we can # # recognise in a loop before passing the remainder back to the # # caller on the first unrecognised argument we encounter. # while test $# -gt 0; do # opt=$1; shift # case $opt in # --silent|-s) opt_silent=: # args_changed=: # ;; # # Separate non-argument short options: # -s*) func_split_short_opt "$_G_opt" # set dummy "$func_split_short_opt_name" \ # "-$func_split_short_opt_arg" ${1+"$@"} # shift # args_changed=: # ;; # *) # Make sure the first unrecognised option "$_G_opt" # # is added back to "$@" in case we need it later, # # if $args_changed was set to 'true'. # set dummy "$_G_opt" ${1+"$@"}; shift; break ;; # esac # done # # # Only call 'func_quote' here if we processed at least one argument. # if $args_changed; then # func_quote eval ${1+"$@"} # my_silent_option_result=$func_quote_result # fi # } # func_add_hook func_parse_options my_silent_option # # # my_option_validation () # { # $debug_cmd # # $opt_silent && $opt_verbose && func_fatal_help "\ # '--silent' and '--verbose' options are mutually exclusive." # } # func_add_hook func_validate_options my_option_validation # # You'll also need to manually amend $usage_message to reflect the extra # options you parse. It's preferable to append if you can, so that # multiple option parsing hooks can be added safely. # func_options_finish [ARG]... # ---------------------------- # Finishing the option parse loop (call 'func_options' hooks ATM). func_options_finish () { $debug_cmd func_run_hooks func_options ${1+"$@"} func_propagate_result func_run_hooks func_options_finish } # func_options [ARG]... # --------------------- # All the functions called inside func_options are hookable. See the # individual implementations for details. func_hookable func_options func_options () { $debug_cmd _G_options_quoted=false for my_func in options_prep parse_options validate_options options_finish do func_unset func_${my_func}_result func_unset func_run_hooks_result eval func_$my_func '${1+"$@"}' func_propagate_result func_$my_func func_options if $func_propagate_result_result; then eval set dummy "$func_options_result"; shift _G_options_quoted=: fi done $_G_options_quoted || { # As we (func_options) are top-level options-parser function and # nobody quoted "$@" for us yet, we need to do it explicitly for # caller. func_quote eval ${1+"$@"} func_options_result=$func_quote_result } } # func_options_prep [ARG]... # -------------------------- # All initialisations required before starting the option parse loop. # Note that when calling hook functions, we pass through the list of # positional parameters. If a hook function modifies that list, and # needs to propagate that back to rest of this script, then the complete # modified list must be put in 'func_run_hooks_result' before returning. func_hookable func_options_prep func_options_prep () { $debug_cmd # Option defaults: opt_verbose=false opt_warning_types= func_run_hooks func_options_prep ${1+"$@"} func_propagate_result func_run_hooks func_options_prep } # func_parse_options [ARG]... # --------------------------- # The main option parsing loop. func_hookable func_parse_options func_parse_options () { $debug_cmd _G_parse_options_requote=false # this just eases exit handling while test $# -gt 0; do # Defer to hook functions for initial option parsing, so they # get priority in the event of reusing an option name. func_run_hooks func_parse_options ${1+"$@"} func_propagate_result func_run_hooks func_parse_options if $func_propagate_result_result; then eval set dummy "$func_parse_options_result"; shift # Even though we may have changed "$@", we passed the "$@" array # down into the hook and it quoted it for us (because we are in # this if-branch). No need to quote it again. _G_parse_options_requote=false fi # Break out of the loop if we already parsed every option. test $# -gt 0 || break # We expect that one of the options parsed in this function matches # and thus we remove _G_opt from "$@" and need to re-quote. _G_match_parse_options=: _G_opt=$1 shift case $_G_opt in --debug|-x) debug_cmd='set -x' func_echo "enabling shell trace mode" >&2 $debug_cmd ;; --no-warnings|--no-warning|--no-warn) set dummy --warnings none ${1+"$@"} shift ;; --warnings|--warning|-W) if test $# = 0 && func_missing_arg $_G_opt; then _G_parse_options_requote=: break fi case " $warning_categories $1" in *" $1 "*) # trailing space prevents matching last $1 above func_append_uniq opt_warning_types " $1" ;; *all) opt_warning_types=$warning_categories ;; *none) opt_warning_types=none warning_func=: ;; *error) opt_warning_types=$warning_categories warning_func=func_fatal_error ;; *) func_fatal_error \ "unsupported warning category: '$1'" ;; esac shift ;; --verbose|-v) opt_verbose=: ;; --version) func_version ;; -\?|-h) func_usage ;; --help) func_help ;; # Separate optargs to long options (plugins may need this): --*=*) func_split_equals "$_G_opt" set dummy "$func_split_equals_lhs" \ "$func_split_equals_rhs" ${1+"$@"} shift ;; # Separate optargs to short options: -W*) func_split_short_opt "$_G_opt" set dummy "$func_split_short_opt_name" \ "$func_split_short_opt_arg" ${1+"$@"} shift ;; # Separate non-argument short options: -\?*|-h*|-v*|-x*) func_split_short_opt "$_G_opt" set dummy "$func_split_short_opt_name" \ "-$func_split_short_opt_arg" ${1+"$@"} shift ;; --) _G_parse_options_requote=: ; break ;; -*) func_fatal_help "unrecognised option: '$_G_opt'" ;; *) set dummy "$_G_opt" ${1+"$@"}; shift _G_match_parse_options=false break ;; esac if $_G_match_parse_options; then _G_parse_options_requote=: fi done if $_G_parse_options_requote; then # save modified positional parameters for caller func_quote eval ${1+"$@"} func_parse_options_result=$func_quote_result fi } # func_validate_options [ARG]... # ------------------------------ # Perform any sanity checks on option settings and/or unconsumed # arguments. func_hookable func_validate_options func_validate_options () { $debug_cmd # Display all warnings if -W was not given. test -n "$opt_warning_types" || opt_warning_types=" $warning_categories" func_run_hooks func_validate_options ${1+"$@"} func_propagate_result func_run_hooks func_validate_options # Bail if the options were screwed! $exit_cmd $EXIT_FAILURE } ## ----------------- ## ## Helper functions. ## ## ----------------- ## # This section contains the helper functions used by the rest of the # hookable option parser framework in ascii-betical order. # func_fatal_help ARG... # ---------------------- # Echo program name prefixed message to standard error, followed by # a help hint, and exit. func_fatal_help () { $debug_cmd eval \$ECHO \""Usage: $usage"\" eval \$ECHO \""$fatal_help"\" func_error ${1+"$@"} exit $EXIT_FAILURE } # func_help # --------- # Echo long help message to standard output and exit. func_help () { $debug_cmd func_usage_message $ECHO "$long_help_message" exit 0 } # func_missing_arg ARGNAME # ------------------------ # Echo program name prefixed message to standard error and set global # exit_cmd. func_missing_arg () { $debug_cmd func_error "Missing argument for '$1'." exit_cmd=exit } # func_split_equals STRING # ------------------------ # Set func_split_equals_lhs and func_split_equals_rhs shell variables # after splitting STRING at the '=' sign. test -z "$_G_HAVE_XSI_OPS" \ && (eval 'x=a/b/c; test 5aa/bb/cc = "${#x}${x%%/*}${x%/*}${x#*/}${x##*/}"') 2>/dev/null \ && _G_HAVE_XSI_OPS=yes if test yes = "$_G_HAVE_XSI_OPS" then # This is an XSI compatible shell, allowing a faster implementation... eval 'func_split_equals () { $debug_cmd func_split_equals_lhs=${1%%=*} func_split_equals_rhs=${1#*=} if test "x$func_split_equals_lhs" = "x$1"; then func_split_equals_rhs= fi }' else # ...otherwise fall back to using expr, which is often a shell builtin. func_split_equals () { $debug_cmd func_split_equals_lhs=`expr "x$1" : 'x\([^=]*\)'` func_split_equals_rhs= test "x$func_split_equals_lhs=" = "x$1" \ || func_split_equals_rhs=`expr "x$1" : 'x[^=]*=\(.*\)$'` } fi #func_split_equals # func_split_short_opt SHORTOPT # ----------------------------- # Set func_split_short_opt_name and func_split_short_opt_arg shell # variables after splitting SHORTOPT after the 2nd character. if test yes = "$_G_HAVE_XSI_OPS" then # This is an XSI compatible shell, allowing a faster implementation... eval 'func_split_short_opt () { $debug_cmd func_split_short_opt_arg=${1#??} func_split_short_opt_name=${1%"$func_split_short_opt_arg"} }' else # ...otherwise fall back to using expr, which is often a shell builtin. func_split_short_opt () { $debug_cmd func_split_short_opt_name=`expr "x$1" : 'x\(-.\)'` func_split_short_opt_arg=`expr "x$1" : 'x-.\(.*\)$'` } fi #func_split_short_opt # func_usage # ---------- # Echo short help message to standard output and exit. func_usage () { $debug_cmd func_usage_message $ECHO "Run '$progname --help |${PAGER-more}' for full usage" exit 0 } # func_usage_message # ------------------ # Echo short help message to standard output. func_usage_message () { $debug_cmd eval \$ECHO \""Usage: $usage"\" echo $SED -n 's|^# || /^Written by/{ x;p;x } h /^Written by/q' < "$progpath" echo eval \$ECHO \""$usage_message"\" } # func_version # ------------ # Echo version message to standard output and exit. # The version message is extracted from the calling file's header # comments, with leading '# ' stripped: # 1. First display the progname and version # 2. Followed by the header comment line matching /^# Written by / # 3. Then a blank line followed by the first following line matching # /^# Copyright / # 4. Immediately followed by any lines between the previous matches, # except lines preceding the intervening completely blank line. # For example, see the header comments of this file. func_version () { $debug_cmd printf '%s\n' "$progname $scriptversion" $SED -n ' /^# Written by /!b s|^# ||; p; n :fwd2blnk /./ { n b fwd2blnk } p; n :holdwrnt s|^# || s|^# *$|| /^Copyright /!{ /./H n b holdwrnt } s|\((C)\)[ 0-9,-]*[ ,-]\([1-9][0-9]* \)|\1 \2| G s|\(\n\)\n*|\1|g p; q' < "$progpath" exit $? } # Local variables: # mode: shell-script # sh-indentation: 2 # eval: (add-hook 'before-save-hook 'time-stamp) # time-stamp-pattern: "30/scriptversion=%:y-%02m-%02d.%02H; # UTC" # time-stamp-time-zone: "UTC" # End: # Set a version string. scriptversion='(GNU libtool) 2.5.4' # func_version # ------------ # Echo version message to standard output and exit. func_version () { $debug_cmd year=`date +%Y` cat < This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Originally written by Gordon Matzigkeit, 1996 (See AUTHORS for complete contributor listing) EOF exit $? } # func_echo ARG... # ---------------- # Libtool also displays the current mode in messages, so override # funclib.sh func_echo with this custom definition. func_echo () { $debug_cmd _G_message=$* func_echo_IFS=$IFS IFS=$nl for _G_line in $_G_message; do IFS=$func_echo_IFS $ECHO "$progname${opt_mode+: $opt_mode}: $_G_line" done IFS=$func_echo_IFS } ## ---------------- ## ## Options parsing. ## ## ---------------- ## # Hook in the functions to make sure our own options are parsed during # the option parsing loop. usage='$progpath [OPTION]... [MODE-ARG]...' # Short help message in response to '-h'. usage_message="Options: --config show all configuration variables --debug enable verbose shell tracing -n, --dry-run display commands without modifying any files --features display basic configuration information --finish use operation '--mode=finish' --mode=MODE use operation mode MODE --no-finish don't update shared library cache --no-quiet, --no-silent print default informational messages --no-warnings equivalent to '-Wnone' --preserve-dup-deps don't remove duplicate dependency libraries --quiet, --silent don't print informational messages --reorder-cache=DIRS reorder shared library cache for preferred DIRS --tag=TAG use configuration variables from tag TAG -v, --verbose print more informational messages than default --version print version information -W, --warnings=CATEGORY report the warnings falling in CATEGORY [all] -h, --help, --help-all print short, long, or detailed help message " # Additional text appended to 'usage_message' in response to '--help'. func_help () { $debug_cmd func_usage_message $ECHO "$long_help_message MODE must be one of the following: clean remove files from the build directory compile compile a source file into a libtool object execute automatically set library path, then run a program finish complete the installation of libtool libraries install install libraries or executables link create a library or an executable uninstall remove libraries from an installed directory MODE-ARGS vary depending on the MODE. When passed as first option, '--mode=MODE' may be abbreviated as 'MODE' or a unique abbreviation of that. Try '$progname --help --mode=MODE' for a more detailed description of MODE. When reporting a bug, please describe a test case to reproduce it and include the following information: host-triplet: $host shell: $SHELL compiler: $LTCC compiler flags: $LTCFLAGS linker: $LD (gnu? $with_gnu_ld) version: $progname $scriptversion Debian-2.5.4-4build1 automake: `($AUTOMAKE --version) 2>/dev/null |$SED 1q` autoconf: `($AUTOCONF --version) 2>/dev/null |$SED 1q` Report bugs to . GNU libtool home page: . General help using GNU software: ." exit 0 } # func_lo2o OBJECT-NAME # --------------------- # Transform OBJECT-NAME from a '.lo' suffix to the platform specific # object suffix. lo2o=s/\\.lo\$/.$objext/ o2lo=s/\\.$objext\$/.lo/ if test yes = "$_G_HAVE_XSI_OPS"; then eval 'func_lo2o () { case $1 in *.lo) func_lo2o_result=${1%.lo}.$objext ;; * ) func_lo2o_result=$1 ;; esac }' # func_xform LIBOBJ-OR-SOURCE # --------------------------- # Transform LIBOBJ-OR-SOURCE from a '.o' or '.c' (or otherwise) # suffix to a '.lo' libtool-object suffix. eval 'func_xform () { func_xform_result=${1%.*}.lo }' else # ...otherwise fall back to using sed. func_lo2o () { func_lo2o_result=`$ECHO "$1" | $SED "$lo2o"` } func_xform () { func_xform_result=`$ECHO "$1" | $SED 's|\.[^.]*$|.lo|'` } fi # func_fatal_configuration ARG... # ------------------------------- # Echo program name prefixed message to standard error, followed by # a configuration failure hint, and exit. func_fatal_configuration () { func_fatal_error ${1+"$@"} \ "See the $PACKAGE documentation for more information." \ "Fatal configuration error." } # func_config # ----------- # Display the configuration for all the tags in this script. func_config () { re_begincf='^# ### BEGIN LIBTOOL' re_endcf='^# ### END LIBTOOL' # Default configuration. $SED "1,/$re_begincf CONFIG/d;/$re_endcf CONFIG/,\$d" < "$progpath" # Now print the configurations for the tags. for tagname in $taglist; do $SED -n "/$re_begincf TAG CONFIG: $tagname\$/,/$re_endcf TAG CONFIG: $tagname\$/p" < "$progpath" done exit $? } # func_features # ------------- # Display the features supported by this script. func_features () { echo "host: $host" if test yes = "$build_libtool_libs"; then echo "enable shared libraries" else echo "disable shared libraries" fi if test yes = "$build_old_libs"; then echo "enable static libraries" else echo "disable static libraries" fi exit $? } # func_enable_tag TAGNAME # ----------------------- # Verify that TAGNAME is valid, and either flag an error and exit, or # enable the TAGNAME tag. We also add TAGNAME to the global $taglist # variable here. func_enable_tag () { # Global variable: tagname=$1 re_begincf="^# ### BEGIN LIBTOOL TAG CONFIG: $tagname\$" re_endcf="^# ### END LIBTOOL TAG CONFIG: $tagname\$" sed_extractcf=/$re_begincf/,/$re_endcf/p # Validate tagname. case $tagname in *[!-_A-Za-z0-9,/]*) func_fatal_error "invalid tag name: $tagname" ;; esac # Don't test for the "default" C tag, as we know it's # there but not specially marked. case $tagname in CC) ;; *) if $GREP "$re_begincf" "$progpath" >/dev/null 2>&1; then taglist="$taglist $tagname" # Evaluate the configuration. Be careful to quote the path # and the sed script, to avoid splitting on whitespace, but # also don't use non-portable quotes within backquotes within # quotes we have to do it in 2 steps: extractedcf=`$SED -n -e "$sed_extractcf" < "$progpath"` eval "$extractedcf" else func_error "ignoring unknown tag $tagname" fi ;; esac } # func_check_version_match # ------------------------ # Ensure that we are using m4 macros, and libtool script from the same # release of libtool. func_check_version_match () { if test "$package_revision" != "$macro_revision"; then if test "$VERSION" != "$macro_version"; then if test -z "$macro_version"; then cat >&2 <<_LT_EOF $progname: Version mismatch error. This is $PACKAGE $VERSION, but the $progname: definition of this LT_INIT comes from an older release. $progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION $progname: and run autoconf again. _LT_EOF else cat >&2 <<_LT_EOF $progname: Version mismatch error. This is $PACKAGE $VERSION, but the $progname: definition of this LT_INIT comes from $PACKAGE $macro_version. $progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION $progname: and run autoconf again. _LT_EOF fi else cat >&2 <<_LT_EOF $progname: Version mismatch error. This is $PACKAGE $VERSION, revision $package_revision, $progname: but the definition of this LT_INIT comes from revision $macro_revision. $progname: You should recreate aclocal.m4 with macros from revision $package_revision $progname: of $PACKAGE $VERSION and run autoconf again. _LT_EOF fi exit $EXIT_MISMATCH fi } # libtool_options_prep [ARG]... # ----------------------------- # Preparation for options parsed by libtool. libtool_options_prep () { $debug_mode # Option defaults: opt_config=false opt_dlopen= opt_dry_run=false opt_help=false opt_mode= opt_reorder_cache=false opt_preserve_dup_deps=false opt_quiet=false opt_finishing=true opt_warning= nonopt= preserve_args= _G_rc_lt_options_prep=: _G_rc_lt_options_prep=: # Shorthand for --mode=foo, only valid as the first argument case $1 in clean|clea|cle|cl) shift; set dummy --mode clean ${1+"$@"}; shift ;; compile|compil|compi|comp|com|co|c) shift; set dummy --mode compile ${1+"$@"}; shift ;; execute|execut|execu|exec|exe|ex|e) shift; set dummy --mode execute ${1+"$@"}; shift ;; finish|finis|fini|fin|fi|f) shift; set dummy --mode finish ${1+"$@"}; shift ;; install|instal|insta|inst|ins|in|i) shift; set dummy --mode install ${1+"$@"}; shift ;; link|lin|li|l) shift; set dummy --mode link ${1+"$@"}; shift ;; uninstall|uninstal|uninsta|uninst|unins|unin|uni|un|u) shift; set dummy --mode uninstall ${1+"$@"}; shift ;; *) _G_rc_lt_options_prep=false ;; esac if $_G_rc_lt_options_prep; then # Pass back the list of options. func_quote eval ${1+"$@"} libtool_options_prep_result=$func_quote_result fi } func_add_hook func_options_prep libtool_options_prep # libtool_parse_options [ARG]... # --------------------------------- # Provide handling for libtool specific options. libtool_parse_options () { $debug_cmd _G_rc_lt_parse_options=false # Perform our own loop to consume as many options as possible in # each iteration. while test $# -gt 0; do _G_match_lt_parse_options=: _G_opt=$1 shift case $_G_opt in --dry-run|--dryrun|-n) opt_dry_run=: ;; --config) func_config ;; --dlopen|-dlopen) opt_dlopen="${opt_dlopen+$opt_dlopen }$1" shift ;; --preserve-dup-deps) opt_preserve_dup_deps=: ;; --features) func_features ;; --finish) set dummy --mode finish ${1+"$@"}; shift ;; --help) opt_help=: ;; --help-all) opt_help=': help-all' ;; --mode) test $# = 0 && func_missing_arg $_G_opt && break opt_mode=$1 case $1 in # Valid mode arguments: clean|compile|execute|finish|install|link|relink|uninstall) ;; # Catch anything else as an error *) func_error "invalid argument '$1' for $_G_opt" exit_cmd=exit ;; esac shift ;; --no-finish) opt_finishing=false func_append preserve_args " $_G_opt" ;; --no-silent|--no-quiet) opt_quiet=false func_append preserve_args " $_G_opt" ;; --no-warnings|--no-warning|--no-warn) opt_warning=false func_append preserve_args " $_G_opt" ;; --no-verbose) opt_verbose=false func_append preserve_args " $_G_opt" ;; --reorder-cache) opt_reorder_cache=true shared_lib_dirs=$1 if test -n "$shared_lib_dirs"; then case $1 in # Must begin with /: /*) ;; # Catch anything else as an error (relative paths) *) func_error "invalid argument '$1' for $_G_opt" func_error "absolute paths are required for $_G_opt" exit_cmd=exit ;; esac fi shift ;; --silent|--quiet) opt_quiet=: opt_verbose=false func_append preserve_args " $_G_opt" ;; --tag) test $# = 0 && func_missing_arg $_G_opt && break opt_tag=$1 func_append preserve_args " $_G_opt $1" func_enable_tag "$1" shift ;; --verbose|-v) opt_quiet=false opt_verbose=: func_append preserve_args " $_G_opt" ;; # An option not handled by this hook function: *) set dummy "$_G_opt" ${1+"$@"} ; shift _G_match_lt_parse_options=false break ;; esac $_G_match_lt_parse_options && _G_rc_lt_parse_options=: done if $_G_rc_lt_parse_options; then # save modified positional parameters for caller func_quote eval ${1+"$@"} libtool_parse_options_result=$func_quote_result fi } func_add_hook func_parse_options libtool_parse_options # func_warning ARG... # ------------------- # Libtool warnings are not categorized, so override funclib.sh # func_warning with this simpler definition. func_warning () { if $opt_warning; then $debug_cmd $warning_func ${1+"$@"} fi } # libtool_validate_options [ARG]... # --------------------------------- # Perform any sanity checks on option settings and/or unconsumed # arguments. libtool_validate_options () { # save first non-option argument if test 0 -lt $#; then nonopt=$1 shift fi # preserve --debug test : = "$debug_cmd" || func_append preserve_args " --debug" case $host_os in # Solaris2 added to fix http://debbugs.gnu.org/cgi/bugreport.cgi?bug=16452 # see also: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59788 cygwin* | mingw* | windows* | pw32* | cegcc* | solaris2* | os2*) # don't eliminate duplications in $postdeps and $predeps opt_duplicate_compiler_generated_deps=: ;; *) opt_duplicate_compiler_generated_deps=$opt_preserve_dup_deps ;; esac $opt_help || { # Sanity checks first: func_check_version_match test yes != "$build_libtool_libs" \ && test yes != "$build_old_libs" \ && func_fatal_configuration "not configured to build any kind of library" # Darwin sucks eval std_shrext=\"$shrext_cmds\" # Only execute mode is allowed to have -dlopen flags. if test -n "$opt_dlopen" && test execute != "$opt_mode"; then func_error "unrecognized option '-dlopen'" $ECHO "$help" 1>&2 exit $EXIT_FAILURE fi # Change the help message to a mode-specific one. generic_help=$help help="Try '$progname --help --mode=$opt_mode' for more information." } # Pass back the unparsed argument list func_quote eval ${1+"$@"} libtool_validate_options_result=$func_quote_result } func_add_hook func_validate_options libtool_validate_options # Process options as early as possible so that --help and --version # can return quickly. func_options ${1+"$@"} eval set dummy "$func_options_result"; shift ## ----------- ## ## Main. ## ## ----------- ## magic='%%%MAGIC variable%%%' magic_exe='%%%MAGIC EXE variable%%%' # Global variables. extracted_archives= extracted_serial=0 # If this variable is set in any of the actions, the command in it # will be execed at the end. This prevents here-documents from being # left over by shells. exec_cmd= # A function that is used when there is no print builtin or printf. func_fallback_echo () { eval 'cat <<_LTECHO_EOF $1 _LTECHO_EOF' } # func_generated_by_libtool # True iff stdin has been generated by Libtool. This function is only # a basic sanity check; it will hardly flush out determined imposters. func_generated_by_libtool_p () { $GREP "^# Generated by .*$PACKAGE" > /dev/null 2>&1 } # func_lalib_p file # True iff FILE is a libtool '.la' library or '.lo' object file. # This function is only a basic sanity check; it will hardly flush out # determined imposters. func_lalib_p () { test -f "$1" && $SED -e 4q "$1" 2>/dev/null | func_generated_by_libtool_p } # func_lalib_unsafe_p file # True iff FILE is a libtool '.la' library or '.lo' object file. # This function implements the same check as func_lalib_p without # resorting to external programs. To this end, it redirects stdin and # closes it afterwards, without saving the original file descriptor. # As a safety measure, use it only where a negative result would be # fatal anyway. Works if 'file' does not exist. func_lalib_unsafe_p () { lalib_p=no if test -f "$1" && test -r "$1" && exec 5<&0 <"$1"; then for lalib_p_l in 1 2 3 4 do read lalib_p_line case $lalib_p_line in \#\ Generated\ by\ *$PACKAGE* ) lalib_p=yes; break;; esac done exec 0<&5 5<&- fi test yes = "$lalib_p" } # func_ltwrapper_script_p file # True iff FILE is a libtool wrapper script # This function is only a basic sanity check; it will hardly flush out # determined imposters. func_ltwrapper_script_p () { test -f "$1" && $lt_truncate_bin < "$1" 2>/dev/null | func_generated_by_libtool_p } # func_ltwrapper_executable_p file # True iff FILE is a libtool wrapper executable # This function is only a basic sanity check; it will hardly flush out # determined imposters. func_ltwrapper_executable_p () { func_ltwrapper_exec_suffix= case $1 in *.exe) ;; *) func_ltwrapper_exec_suffix=.exe ;; esac $GREP "$magic_exe" "$1$func_ltwrapper_exec_suffix" >/dev/null 2>&1 } # func_ltwrapper_scriptname file # Assumes file is an ltwrapper_executable # uses $file to determine the appropriate filename for a # temporary ltwrapper_script. func_ltwrapper_scriptname () { func_dirname_and_basename "$1" "" "." func_stripname '' '.exe' "$func_basename_result" func_ltwrapper_scriptname_result=$func_dirname_result/$objdir/${func_stripname_result}_ltshwrapper } # func_ltwrapper_p file # True iff FILE is a libtool wrapper script or wrapper executable # This function is only a basic sanity check; it will hardly flush out # determined imposters. func_ltwrapper_p () { func_ltwrapper_script_p "$1" || func_ltwrapper_executable_p "$1" } # func_execute_cmds commands fail_cmd # Execute tilde-delimited COMMANDS. # If FAIL_CMD is given, eval that upon failure. # FAIL_CMD may read-access the current command in variable CMD! func_execute_cmds () { $debug_cmd save_ifs=$IFS; IFS='~' for cmd in $1; do IFS=$sp$nl eval cmd=\"$cmd\" IFS=$save_ifs func_show_eval "$cmd" "${2-:}" done IFS=$save_ifs } # func_source file # Source FILE, adding directory component if necessary. # Note that it is not necessary on cygwin/mingw to append a dot to # FILE even if both FILE and FILE.exe exist: automatic-append-.exe # behavior happens only for exec(3), not for open(2)! Also, sourcing # 'FILE.' does not work on cygwin managed mounts. func_source () { $debug_cmd case $1 in */* | *\\*) . "$1" ;; *) . "./$1" ;; esac } # func_resolve_sysroot PATH # Replace a leading = in PATH with a sysroot. Store the result into # func_resolve_sysroot_result func_resolve_sysroot () { func_resolve_sysroot_result=$1 case $func_resolve_sysroot_result in =*) func_stripname '=' '' "$func_resolve_sysroot_result" func_resolve_sysroot_result=$lt_sysroot$func_stripname_result ;; esac } # func_replace_sysroot PATH # If PATH begins with the sysroot, replace it with = and # store the result into func_replace_sysroot_result. func_replace_sysroot () { case $lt_sysroot:$1 in ?*:"$lt_sysroot"*) func_stripname "$lt_sysroot" '' "$1" func_replace_sysroot_result='='$func_stripname_result ;; *) # Including no sysroot. func_replace_sysroot_result=$1 ;; esac } # func_infer_tag arg # Infer tagged configuration to use if any are available and # if one wasn't chosen via the "--tag" command line option. # Only attempt this if the compiler in the base compile # command doesn't match the default compiler. # arg is usually of the form 'gcc ...' func_infer_tag () { $debug_cmd if test -n "$available_tags" && test -z "$tagname"; then CC_quoted= for arg in $CC; do func_append_quoted CC_quoted "$arg" done CC_expanded=`func_echo_all $CC` CC_quoted_expanded=`func_echo_all $CC_quoted` case $@ in # Blanks in the command may have been stripped by the calling shell, # but not from the CC environment variable when configure was run. " $CC "* | "$CC "* | " $CC_expanded "* | "$CC_expanded "* | \ " $CC_quoted"* | "$CC_quoted "* | " $CC_quoted_expanded "* | "$CC_quoted_expanded "*) ;; # Blanks at the start of $base_compile will cause this to fail # if we don't check for them as well. *) for z in $available_tags; do if $GREP "^# ### BEGIN LIBTOOL TAG CONFIG: $z$" < "$progpath" > /dev/null; then # Evaluate the configuration. eval "`$SED -n -e '/^# ### BEGIN LIBTOOL TAG CONFIG: '$z'$/,/^# ### END LIBTOOL TAG CONFIG: '$z'$/p' < $progpath`" CC_quoted= for arg in $CC; do # Double-quote args containing other shell metacharacters. func_append_quoted CC_quoted "$arg" done CC_expanded=`func_echo_all $CC` CC_quoted_expanded=`func_echo_all $CC_quoted` case "$@ " in " $CC "* | "$CC "* | " $CC_expanded "* | "$CC_expanded "* | \ " $CC_quoted"* | "$CC_quoted "* | " $CC_quoted_expanded "* | "$CC_quoted_expanded "*) # The compiler in the base compile command matches # the one in the tagged configuration. # Assume this is the tagged configuration we want. tagname=$z break ;; esac fi done # If $tagname still isn't set, then no tagged configuration # was found and let the user know that the "--tag" command # line option must be used. if test -z "$tagname"; then func_echo "unable to infer tagged configuration" func_fatal_error "specify a tag with '--tag'" # else # func_verbose "using $tagname tagged configuration" fi ;; esac fi } # func_write_libtool_object output_name pic_name nonpic_name # Create a libtool object file (analogous to a ".la" file), # but don't create it if we're doing a dry run. func_write_libtool_object () { write_libobj=$1 if test yes = "$build_libtool_libs"; then write_lobj=\'$2\' else write_lobj=none fi if test yes = "$build_old_libs"; then write_oldobj=\'$3\' else write_oldobj=none fi $opt_dry_run || { cat >${write_libobj}T </dev/null` if test "$?" -eq 0 && test -n "$func_convert_core_file_wine_to_w32_tmp"; then func_convert_core_file_wine_to_w32_result=`$ECHO "$func_convert_core_file_wine_to_w32_tmp" | $SED -e "$sed_naive_backslashify"` else func_convert_core_file_wine_to_w32_result= fi fi } # end: func_convert_core_file_wine_to_w32 # func_convert_core_path_wine_to_w32 ARG # Helper function used by path conversion functions when $build is *nix, and # $host is mingw, windows, cygwin, or some other w32 environment. Relies on a # correctly configured wine environment available, with the winepath program # in $build's $PATH. Assumes ARG has no leading or trailing path separator # characters. # # ARG is path to be converted from $build format to win32. # Result is available in $func_convert_core_path_wine_to_w32_result. # Unconvertible file (directory) names in ARG are skipped; if no directory names # are convertible, then the result may be empty. func_convert_core_path_wine_to_w32 () { $debug_cmd # unfortunately, winepath doesn't convert paths, only file names func_convert_core_path_wine_to_w32_result= if test -n "$1"; then oldIFS=$IFS IFS=: for func_convert_core_path_wine_to_w32_f in $1; do IFS=$oldIFS func_convert_core_file_wine_to_w32 "$func_convert_core_path_wine_to_w32_f" if test -n "$func_convert_core_file_wine_to_w32_result"; then if test -z "$func_convert_core_path_wine_to_w32_result"; then func_convert_core_path_wine_to_w32_result=$func_convert_core_file_wine_to_w32_result else func_append func_convert_core_path_wine_to_w32_result ";$func_convert_core_file_wine_to_w32_result" fi fi done IFS=$oldIFS fi } # end: func_convert_core_path_wine_to_w32 # func_cygpath ARGS... # Wrapper around calling the cygpath program via LT_CYGPATH. This is used when # when (1) $build is *nix and Cygwin is hosted via a wine environment; or (2) # $build is MSYS and $host is Cygwin, or (3) $build is Cygwin. In case (1) or # (2), returns the Cygwin file name or path in func_cygpath_result (input # file name or path is assumed to be in w32 format, as previously converted # from $build's *nix or MSYS format). In case (3), returns the w32 file name # or path in func_cygpath_result (input file name or path is assumed to be in # Cygwin format). Returns an empty string on error. # # ARGS are passed to cygpath, with the last one being the file name or path to # be converted. # # Specify the absolute *nix (or w32) name to cygpath in the LT_CYGPATH # environment variable; do not put it in $PATH. func_cygpath () { $debug_cmd if test -n "$LT_CYGPATH" && test -f "$LT_CYGPATH"; then func_cygpath_result=`$LT_CYGPATH "$@" 2>/dev/null` if test "$?" -ne 0; then # on failure, ensure result is empty func_cygpath_result= fi else func_cygpath_result= func_error "LT_CYGPATH is empty or specifies non-existent file: '$LT_CYGPATH'" fi } #end: func_cygpath # func_convert_core_msys_to_w32 ARG # Convert file name or path ARG from MSYS format to w32 format. Return # result in func_convert_core_msys_to_w32_result. func_convert_core_msys_to_w32 () { $debug_cmd # awkward: cmd appends spaces to result func_convert_core_msys_to_w32_result=`( cmd //c echo "$1" ) 2>/dev/null | $SED -e 's/[ ]*$//' -e "$sed_naive_backslashify"` } #end: func_convert_core_msys_to_w32 # func_convert_file_check ARG1 ARG2 # Verify that ARG1 (a file name in $build format) was converted to $host # format in ARG2. Otherwise, emit an error message, but continue (resetting # func_to_host_file_result to ARG1). func_convert_file_check () { $debug_cmd if test -z "$2" && test -n "$1"; then func_error "Could not determine host file name corresponding to" func_error " '$1'" func_error "Continuing, but uninstalled executables may not work." # Fallback: func_to_host_file_result=$1 fi } # end func_convert_file_check # func_convert_path_check FROM_PATHSEP TO_PATHSEP FROM_PATH TO_PATH # Verify that FROM_PATH (a path in $build format) was converted to $host # format in TO_PATH. Otherwise, emit an error message, but continue, resetting # func_to_host_file_result to a simplistic fallback value (see below). func_convert_path_check () { $debug_cmd if test -z "$4" && test -n "$3"; then func_error "Could not determine the host path corresponding to" func_error " '$3'" func_error "Continuing, but uninstalled executables may not work." # Fallback. This is a deliberately simplistic "conversion" and # should not be "improved". See libtool.info. if test "x$1" != "x$2"; then lt_replace_pathsep_chars="s|$1|$2|g" func_to_host_path_result=`echo "$3" | $SED -e "$lt_replace_pathsep_chars"` else func_to_host_path_result=$3 fi fi } # end func_convert_path_check # func_convert_path_front_back_pathsep FRONTPAT BACKPAT REPL ORIG # Modifies func_to_host_path_result by prepending REPL if ORIG matches FRONTPAT # and appending REPL if ORIG matches BACKPAT. func_convert_path_front_back_pathsep () { $debug_cmd case $4 in $1 ) func_to_host_path_result=$3$func_to_host_path_result ;; esac case $4 in $2 ) func_append func_to_host_path_result "$3" ;; esac } # end func_convert_path_front_back_pathsep # func_convert_delimited_path PATH ORIG_DELIMITER NEW_DELIMITER # Replaces a delimiter for a given path. func_convert_delimited_path () { converted_path=`$ECHO "$1" | $SED "s#$2#$3#g"` } # end func_convert_delimited_path ################################################## # $build to $host FILE NAME CONVERSION FUNCTIONS # ################################################## # invoked via '$to_host_file_cmd ARG' # # In each case, ARG is the path to be converted from $build to $host format. # Result will be available in $func_to_host_file_result. # func_to_host_file ARG # Converts the file name ARG from $build format to $host format. Return result # in func_to_host_file_result. func_to_host_file () { $debug_cmd $to_host_file_cmd "$1" } # end func_to_host_file # func_to_tool_file ARG LAZY # converts the file name ARG from $build format to toolchain format. Return # result in func_to_tool_file_result. If the conversion in use is listed # in (the comma separated) LAZY, no conversion takes place. func_to_tool_file () { $debug_cmd case ,$2, in *,"$to_tool_file_cmd",*) func_to_tool_file_result=$1 ;; *) $to_tool_file_cmd "$1" func_to_tool_file_result=$func_to_host_file_result ;; esac } # end func_to_tool_file # func_convert_file_noop ARG # Copy ARG to func_to_host_file_result. func_convert_file_noop () { func_to_host_file_result=$1 } # end func_convert_file_noop # func_convert_file_msys_to_w32 ARG # Convert file name ARG from (mingw) MSYS to (mingw) w32 format; automatic # conversion to w32 is not available inside the cwrapper. Returns result in # func_to_host_file_result. func_convert_file_msys_to_w32 () { $debug_cmd func_to_host_file_result=$1 if test -n "$1"; then func_convert_core_msys_to_w32 "$1" func_to_host_file_result=$func_convert_core_msys_to_w32_result fi func_convert_file_check "$1" "$func_to_host_file_result" } # end func_convert_file_msys_to_w32 # func_convert_file_cygwin_to_w32 ARG # Convert file name ARG from Cygwin to w32 format. Returns result in # func_to_host_file_result. func_convert_file_cygwin_to_w32 () { $debug_cmd func_to_host_file_result=$1 if test -n "$1"; then # because $build is cygwin, we call "the" cygpath in $PATH; no need to use # LT_CYGPATH in this case. func_to_host_file_result=`cygpath -m "$1"` fi func_convert_file_check "$1" "$func_to_host_file_result" } # end func_convert_file_cygwin_to_w32 # func_convert_file_nix_to_w32 ARG # Convert file name ARG from *nix to w32 format. Requires a wine environment # and a working winepath. Returns result in func_to_host_file_result. func_convert_file_nix_to_w32 () { $debug_cmd func_to_host_file_result=$1 if test -n "$1"; then func_convert_core_file_wine_to_w32 "$1" func_to_host_file_result=$func_convert_core_file_wine_to_w32_result fi func_convert_file_check "$1" "$func_to_host_file_result" } # end func_convert_file_nix_to_w32 # func_convert_file_msys_to_cygwin ARG # Convert file name ARG from MSYS to Cygwin format. Requires LT_CYGPATH set. # Returns result in func_to_host_file_result. func_convert_file_msys_to_cygwin () { $debug_cmd func_to_host_file_result=$1 if test -n "$1"; then func_convert_core_msys_to_w32 "$1" func_cygpath -u "$func_convert_core_msys_to_w32_result" func_to_host_file_result=$func_cygpath_result fi func_convert_file_check "$1" "$func_to_host_file_result" } # end func_convert_file_msys_to_cygwin # func_convert_file_nix_to_cygwin ARG # Convert file name ARG from *nix to Cygwin format. Requires Cygwin installed # in a wine environment, working winepath, and LT_CYGPATH set. Returns result # in func_to_host_file_result. func_convert_file_nix_to_cygwin () { $debug_cmd func_to_host_file_result=$1 if test -n "$1"; then # convert from *nix to w32, then use cygpath to convert from w32 to cygwin. func_convert_core_file_wine_to_w32 "$1" func_cygpath -u "$func_convert_core_file_wine_to_w32_result" func_to_host_file_result=$func_cygpath_result fi func_convert_file_check "$1" "$func_to_host_file_result" } # end func_convert_file_nix_to_cygwin ############################################# # $build to $host PATH CONVERSION FUNCTIONS # ############################################# # invoked via '$to_host_path_cmd ARG' # # In each case, ARG is the path to be converted from $build to $host format. # The result will be available in $func_to_host_path_result. # # Path separators are also converted from $build format to $host format. If # ARG begins or ends with a path separator character, it is preserved (but # converted to $host format) on output. # # All path conversion functions are named using the following convention: # file name conversion function : func_convert_file_X_to_Y () # path conversion function : func_convert_path_X_to_Y () # where, for any given $build/$host combination the 'X_to_Y' value is the # same. If conversion functions are added for new $build/$host combinations, # the two new functions must follow this pattern, or func_init_to_host_path_cmd # will break. # func_init_to_host_path_cmd # Ensures that function "pointer" variable $to_host_path_cmd is set to the # appropriate value, based on the value of $to_host_file_cmd. to_host_path_cmd= func_init_to_host_path_cmd () { $debug_cmd if test -z "$to_host_path_cmd"; then func_stripname 'func_convert_file_' '' "$to_host_file_cmd" to_host_path_cmd=func_convert_path_$func_stripname_result fi } # func_to_host_path ARG # Converts the path ARG from $build format to $host format. Return result # in func_to_host_path_result. func_to_host_path () { $debug_cmd func_init_to_host_path_cmd $to_host_path_cmd "$1" } # end func_to_host_path # func_convert_path_noop ARG # Copy ARG to func_to_host_path_result. func_convert_path_noop () { func_to_host_path_result=$1 } # end func_convert_path_noop # func_convert_path_msys_to_w32 ARG # Convert path ARG from (mingw) MSYS to (mingw) w32 format; automatic # conversion to w32 is not available inside the cwrapper. Returns result in # func_to_host_path_result. func_convert_path_msys_to_w32 () { $debug_cmd func_to_host_path_result=$1 if test -n "$1"; then # Remove leading and trailing path separator characters from ARG. MSYS # behavior is inconsistent here; cygpath turns them into '.;' and ';.'; # and winepath ignores them completely. func_stripname : : "$1" func_to_host_path_tmp1=$func_stripname_result func_convert_core_msys_to_w32 "$func_to_host_path_tmp1" func_to_host_path_result=$func_convert_core_msys_to_w32_result func_convert_path_check : ";" \ "$func_to_host_path_tmp1" "$func_to_host_path_result" func_convert_path_front_back_pathsep ":*" "*:" ";" "$1" fi } # end func_convert_path_msys_to_w32 # func_convert_path_cygwin_to_w32 ARG # Convert path ARG from Cygwin to w32 format. Returns result in # func_to_host_file_result. func_convert_path_cygwin_to_w32 () { $debug_cmd func_to_host_path_result=$1 if test -n "$1"; then # See func_convert_path_msys_to_w32: func_stripname : : "$1" func_to_host_path_tmp1=$func_stripname_result func_to_host_path_result=`cygpath -m -p "$func_to_host_path_tmp1"` func_convert_path_check : ";" \ "$func_to_host_path_tmp1" "$func_to_host_path_result" func_convert_path_front_back_pathsep ":*" "*:" ";" "$1" fi } # end func_convert_path_cygwin_to_w32 # func_convert_path_nix_to_w32 ARG # Convert path ARG from *nix to w32 format. Requires a wine environment and # a working winepath. Returns result in func_to_host_file_result. func_convert_path_nix_to_w32 () { $debug_cmd func_to_host_path_result=$1 if test -n "$1"; then # See func_convert_path_msys_to_w32: func_stripname : : "$1" func_to_host_path_tmp1=$func_stripname_result func_convert_core_path_wine_to_w32 "$func_to_host_path_tmp1" func_to_host_path_result=$func_convert_core_path_wine_to_w32_result func_convert_path_check : ";" \ "$func_to_host_path_tmp1" "$func_to_host_path_result" func_convert_path_front_back_pathsep ":*" "*:" ";" "$1" fi } # end func_convert_path_nix_to_w32 # func_convert_path_msys_to_cygwin ARG # Convert path ARG from MSYS to Cygwin format. Requires LT_CYGPATH set. # Returns result in func_to_host_file_result. func_convert_path_msys_to_cygwin () { $debug_cmd func_to_host_path_result=$1 if test -n "$1"; then # See func_convert_path_msys_to_w32: func_stripname : : "$1" func_to_host_path_tmp1=$func_stripname_result func_convert_core_msys_to_w32 "$func_to_host_path_tmp1" func_cygpath -u -p "$func_convert_core_msys_to_w32_result" func_to_host_path_result=$func_cygpath_result func_convert_path_check : : \ "$func_to_host_path_tmp1" "$func_to_host_path_result" func_convert_path_front_back_pathsep ":*" "*:" : "$1" fi } # end func_convert_path_msys_to_cygwin # func_convert_path_nix_to_cygwin ARG # Convert path ARG from *nix to Cygwin format. Requires Cygwin installed in a # a wine environment, working winepath, and LT_CYGPATH set. Returns result in # func_to_host_file_result. func_convert_path_nix_to_cygwin () { $debug_cmd func_to_host_path_result=$1 if test -n "$1"; then # Remove leading and trailing path separator characters from # ARG. msys behavior is inconsistent here, cygpath turns them # into '.;' and ';.', and winepath ignores them completely. func_stripname : : "$1" func_to_host_path_tmp1=$func_stripname_result func_convert_core_path_wine_to_w32 "$func_to_host_path_tmp1" func_cygpath -u -p "$func_convert_core_path_wine_to_w32_result" func_to_host_path_result=$func_cygpath_result func_convert_path_check : : \ "$func_to_host_path_tmp1" "$func_to_host_path_result" func_convert_path_front_back_pathsep ":*" "*:" : "$1" fi } # end func_convert_path_nix_to_cygwin # func_dll_def_p FILE # True iff FILE is a Windows DLL '.def' file. # Keep in sync with _LT_DLL_DEF_P in libtool.m4 func_dll_def_p () { $debug_cmd func_dll_def_p_tmp=`$SED -n \ -e 's/^[ ]*//' \ -e '/^\(;.*\)*$/d' \ -e 's/^\(EXPORTS\|LIBRARY\)\([ ].*\)*$/DEF/p' \ -e q \ "$1"` test DEF = "$func_dll_def_p_tmp" } # func_reorder_shared_lib_cache DIRS # Reorder the shared library cache by unconfiguring previous shared library cache # and configuring preferred search directories before previous search directories. # Previous shared library cache: /usr/lib /usr/local/lib # Preferred search directories: /tmp/testing # Reordered shared library cache: /tmp/testing /usr/lib /usr/local/lib func_reorder_shared_lib_cache () { $debug_cmd case $host_os in openbsd*) get_search_directories=`PATH="$PATH:/sbin" ldconfig -r | $GREP "search directories" | $SED "s#.*search directories:\ ##g"` func_convert_delimited_path "$get_search_directories" ':' '\ ' save_search_directories=$converted_path func_convert_delimited_path "$1" ':' '\ ' # Ensure directories exist for dir in $converted_path; do # Ensure each directory is an absolute path case $dir in /*) ;; *) func_error "Directory '$dir' is not an absolute path" exit $EXIT_FAILURE ;; esac # Ensure no trailing slashes func_stripname '' '/' "$dir" dir=$func_stripname_result if test -d "$dir"; then if test -n "$preferred_search_directories"; then preferred_search_directories="$preferred_search_directories $dir" else preferred_search_directories=$dir fi else func_error "Directory '$dir' does not exist" exit $EXIT_FAILURE fi done PATH="$PATH:/sbin" ldconfig -U $save_search_directories PATH="$PATH:/sbin" ldconfig -m $preferred_search_directories $save_search_directories get_search_directories=`PATH="$PATH:/sbin" ldconfig -r | $GREP "search directories" | $SED "s#.*search directories:\ ##g"` func_convert_delimited_path "$get_search_directories" ':' '\ ' reordered_search_directories=$converted_path $ECHO "Original: $save_search_directories" $ECHO "Reordered: $reordered_search_directories" exit $EXIT_SUCCESS ;; *) func_error "--reorder-cache is not supported for host_os=$host_os." exit $EXIT_FAILURE ;; esac } # end func_reorder_shared_lib_cache # func_mode_compile arg... func_mode_compile () { $debug_cmd # Get the compilation command and the source file. base_compile= srcfile=$nonopt # always keep a non-empty value in "srcfile" suppress_opt=yes suppress_output= arg_mode=normal libobj= later= pie_flag= for arg do case $arg_mode in arg ) # do not "continue". Instead, add this to base_compile lastarg=$arg arg_mode=normal ;; target ) libobj=$arg arg_mode=normal continue ;; normal ) # Accept any command-line options. case $arg in -o) test -n "$libobj" && \ func_fatal_error "you cannot specify '-o' more than once" arg_mode=target continue ;; -pie | -fpie | -fPIE) func_append pie_flag " $arg" continue ;; -shared | -static | -prefer-pic | -prefer-non-pic) func_append later " $arg" continue ;; -no-suppress) suppress_opt=no continue ;; -Xcompiler) arg_mode=arg # the next one goes into the "base_compile" arg list continue # The current "srcfile" will either be retained or ;; # replaced later. I would guess that would be a bug. -Wc,*) func_stripname '-Wc,' '' "$arg" args=$func_stripname_result lastarg= save_ifs=$IFS; IFS=, for arg in $args; do IFS=$save_ifs func_append_quoted lastarg "$arg" done IFS=$save_ifs func_stripname ' ' '' "$lastarg" lastarg=$func_stripname_result # Add the arguments to base_compile. func_append base_compile " $lastarg" continue ;; *) # Accept the current argument as the source file. # The previous "srcfile" becomes the current argument. # lastarg=$srcfile srcfile=$arg ;; esac # case $arg ;; esac # case $arg_mode # Aesthetically quote the previous argument. func_append_quoted base_compile "$lastarg" done # for arg case $arg_mode in arg) func_fatal_error "you must specify an argument for -Xcompile" ;; target) func_fatal_error "you must specify a target with '-o'" ;; *) # Get the name of the library object. test -z "$libobj" && { func_basename "$srcfile" libobj=$func_basename_result } ;; esac # Recognize several different file suffixes. # If the user specifies -o file.o, it is replaced with file.lo case $libobj in *.[cCFSifmso] | \ *.ada | *.adb | *.ads | *.asm | \ *.c++ | *.cc | *.ii | *.class | *.cpp | *.cxx | \ *.[fF][09]? | *.for | *.java | *.go | *.obj | *.sx | *.cu | *.cup) func_xform "$libobj" libobj=$func_xform_result ;; esac case $libobj in *.lo) func_lo2o "$libobj"; obj=$func_lo2o_result ;; *) func_fatal_error "cannot determine name of library object from '$libobj'" ;; esac func_infer_tag $base_compile for arg in $later; do case $arg in -shared) test yes = "$build_libtool_libs" \ || func_fatal_configuration "cannot build a shared library" build_old_libs=no continue ;; -static) build_libtool_libs=no build_old_libs=yes continue ;; -prefer-pic) pic_mode=yes continue ;; -prefer-non-pic) pic_mode=no continue ;; esac done func_quote_arg pretty "$libobj" test "X$libobj" != "X$func_quote_arg_result" \ && $ECHO "X$libobj" | $GREP '[]~#^*{};<>?"'"'"' &()|`$[]' \ && func_warning "libobj name '$libobj' may not contain shell special characters." func_dirname_and_basename "$obj" "/" "" objname=$func_basename_result xdir=$func_dirname_result lobj=$xdir$objdir/$objname test -z "$base_compile" && \ func_fatal_help "you must specify a compilation command" # Delete any leftover library objects. if test yes = "$build_old_libs"; then removelist="$obj $lobj $libobj ${libobj}T" else removelist="$lobj $libobj ${libobj}T" fi # On Cygwin there's no "real" PIC flag so we must build both object types case $host_os in cygwin* | mingw* | windows* | pw32* | os2* | cegcc*) pic_mode=default ;; esac if test no = "$pic_mode" && test pass_all != "$deplibs_check_method"; then # non-PIC code in shared libraries is not supported pic_mode=default fi # Calculate the filename of the output object if compiler does # not support -o with -c if test no = "$compiler_c_o"; then output_obj=`$ECHO "$srcfile" | $SED 's%^.*/%%; s%\.[^.]*$%%'`.$objext lockfile=$output_obj.lock else output_obj= need_locks=no lockfile= fi # Lock this critical section if it is needed # We use this script file to make the link, it avoids creating a new file if test yes = "$need_locks"; then until $opt_dry_run || ln "$progpath" "$lockfile" 2>/dev/null; do func_echo "Waiting for $lockfile to be removed" sleep 2 done elif test warn = "$need_locks"; then if test -f "$lockfile"; then $ECHO "\ *** ERROR, $lockfile exists and contains: `cat $lockfile 2>/dev/null` This indicates that another process is trying to use the same temporary object file, and libtool could not work around it because your compiler does not support '-c' and '-o' together. If you repeat this compilation, it may succeed, by chance, but you had better avoid parallel builds (make -j) in this platform, or get a better compiler." $opt_dry_run || $RM $removelist exit $EXIT_FAILURE fi func_append removelist " $output_obj" $ECHO "$srcfile" > "$lockfile" fi $opt_dry_run || $RM $removelist func_append removelist " $lockfile" trap '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE' 1 2 15 func_to_tool_file "$srcfile" func_convert_file_msys_to_w32 srcfile=$func_to_tool_file_result func_quote_arg pretty "$srcfile" qsrcfile=$func_quote_arg_result # Only build a PIC object if we are building libtool libraries. if test yes = "$build_libtool_libs"; then # Without this assignment, base_compile gets emptied. fbsd_hideous_sh_bug=$base_compile if test no != "$pic_mode"; then command="$base_compile $qsrcfile $pic_flag" else # Don't build PIC code command="$base_compile $qsrcfile" fi func_mkdir_p "$xdir$objdir" if test -z "$output_obj"; then # Place PIC objects in $objdir func_append command " -o $lobj" fi func_show_eval_locale "$command" \ 'test -n "$output_obj" && $RM $removelist; exit $EXIT_FAILURE' if test warn = "$need_locks" && test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then $ECHO "\ *** ERROR, $lockfile contains: `cat $lockfile 2>/dev/null` but it should contain: $srcfile This indicates that another process is trying to use the same temporary object file, and libtool could not work around it because your compiler does not support '-c' and '-o' together. If you repeat this compilation, it may succeed, by chance, but you had better avoid parallel builds (make -j) in this platform, or get a better compiler." $opt_dry_run || $RM $removelist exit $EXIT_FAILURE fi # Just move the object if needed, then go on to compile the next one if test -n "$output_obj" && test "X$output_obj" != "X$lobj"; then func_show_eval '$MV "$output_obj" "$lobj"' \ 'error=$?; $opt_dry_run || $RM $removelist; exit $error' fi # Allow error messages only from the first compilation. if test yes = "$suppress_opt"; then suppress_output=' >/dev/null 2>&1' fi fi # Only build a position-dependent object if we build old libraries. if test yes = "$build_old_libs"; then if test yes != "$pic_mode"; then # Don't build PIC code command="$base_compile $qsrcfile$pie_flag" else command="$base_compile $qsrcfile $pic_flag" fi if test yes = "$compiler_c_o"; then func_append command " -o $obj" fi # Suppress compiler output if we already did a PIC compilation. func_append command "$suppress_output" func_show_eval_locale "$command" \ '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE' if test warn = "$need_locks" && test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then $ECHO "\ *** ERROR, $lockfile contains: `cat $lockfile 2>/dev/null` but it should contain: $srcfile This indicates that another process is trying to use the same temporary object file, and libtool could not work around it because your compiler does not support '-c' and '-o' together. If you repeat this compilation, it may succeed, by chance, but you had better avoid parallel builds (make -j) in this platform, or get a better compiler." $opt_dry_run || $RM $removelist exit $EXIT_FAILURE fi # Just move the object if needed if test -n "$output_obj" && test "X$output_obj" != "X$obj"; then func_show_eval '$MV "$output_obj" "$obj"' \ 'error=$?; $opt_dry_run || $RM $removelist; exit $error' fi fi $opt_dry_run || { func_write_libtool_object "$libobj" "$objdir/$objname" "$objname" # Unlock the critical section if it was locked if test no != "$need_locks"; then removelist=$lockfile $RM "$lockfile" fi } exit $EXIT_SUCCESS } $opt_help || { test compile = "$opt_mode" && func_mode_compile ${1+"$@"} } func_mode_help () { # We need to display help for each of the modes. case $opt_mode in "") # Generic help is extracted from the usage comments # at the start of this file. func_help ;; clean) $ECHO \ "Usage: $progname [OPTION]... --mode=clean RM [RM-OPTION]... FILE... Remove files from the build directory. RM is the name of the program to use to delete files associated with each FILE (typically '/bin/rm'). RM-OPTIONS are options (such as '-f') to be passed to RM. If FILE is a libtool library, object or program, all the files associated with it are deleted. Otherwise, only FILE itself is deleted using RM." ;; compile) $ECHO \ "Usage: $progname [OPTION]... --mode=compile COMPILE-COMMAND... SOURCEFILE Compile a source file into a libtool library object. This mode accepts the following additional options: -o OUTPUT-FILE set the output file name to OUTPUT-FILE -no-suppress do not suppress compiler output for multiple passes -prefer-pic try to build PIC objects only -prefer-non-pic try to build non-PIC objects only -shared do not build a '.o' file suitable for static linking -static only build a '.o' file suitable for static linking -Wc,FLAG -Xcompiler FLAG pass FLAG directly to the compiler COMPILE-COMMAND is a command to be used in creating a 'standard' object file from the given SOURCEFILE. The output file name is determined by removing the directory component from SOURCEFILE, then substituting the C source code suffix '.c' with the library object suffix, '.lo'." ;; execute) $ECHO \ "Usage: $progname [OPTION]... --mode=execute COMMAND [ARGS]... Automatically set library path, then run a program. This mode accepts the following additional options: -dlopen FILE add the directory containing FILE to the library path This mode sets the library path environment variable according to '-dlopen' flags. If any of the ARGS are libtool executable wrappers, then they are translated into their corresponding uninstalled binary, and any of their required library directories are added to the library path. Then, COMMAND is executed, with ARGS as arguments." ;; finish) $ECHO \ "Usage: $progname [OPTION]... --mode=finish [LIBDIR]... Complete the installation of libtool libraries. Each LIBDIR is a directory that contains libtool libraries. The commands that this mode executes may require superuser privileges. Use the '--dry-run' option if you just want to see what would be executed." ;; install) $ECHO \ "Usage: $progname [OPTION]... --mode=install INSTALL-COMMAND... Install executables or libraries. INSTALL-COMMAND is the installation command. The first component should be either the 'install' or 'cp' program. The following components of INSTALL-COMMAND are treated specially: -inst-prefix-dir PREFIX-DIR Use PREFIX-DIR as a staging area for installation The rest of the components are interpreted as arguments to that command (only BSD-compatible install options are recognized)." ;; link) $ECHO \ "Usage: $progname [OPTION]... --mode=link LINK-COMMAND... Link object files or libraries together to form another library, or to create an executable program. LINK-COMMAND is a command using the C compiler that you would use to create a program from several object files. The following components of LINK-COMMAND are treated specially: -all-static do not do any dynamic linking at all -avoid-version do not add a version suffix if possible -bindir BINDIR specify path to binaries directory (for systems where libraries must be found in the PATH setting at runtime) -dlopen FILE '-dlpreopen' FILE if it cannot be dlopened at runtime -dlpreopen FILE link in FILE and add its symbols to lt_preloaded_symbols -export-dynamic allow symbols from OUTPUT-FILE to be resolved with dlsym(3) -export-symbols SYMFILE try to export only the symbols listed in SYMFILE -export-symbols-regex REGEX try to export only the symbols matching REGEX -LLIBDIR search LIBDIR for required installed libraries -lNAME OUTPUT-FILE requires the installed library libNAME -module build a library that can dlopened -no-fast-install disable the fast-install mode -no-install link a not-installable executable -no-undefined declare that a library does not refer to external symbols -o OUTPUT-FILE create OUTPUT-FILE from the specified objects -objectlist FILE use a list of object files found in FILE to specify objects -os2dllname NAME force a short DLL name on OS/2 (no effect on other OSes) -precious-files-regex REGEX don't remove output files matching REGEX -release RELEASE specify package release information -rpath LIBDIR the created library will eventually be installed in LIBDIR -R[ ]LIBDIR add LIBDIR to the runtime path of programs and libraries -shared only do dynamic linking of libtool libraries -shrext SUFFIX override the standard shared library file extension -static do not do any dynamic linking of uninstalled libtool libraries -static-libtool-libs do not do any dynamic linking of libtool libraries -version-info CURRENT[:REVISION[:AGE]] specify library version info [each variable defaults to 0] -weak LIBNAME declare that the target provides the LIBNAME interface -Wc,FLAG -Xcompiler FLAG pass linker-specific FLAG directly to the compiler -Wa,FLAG -Xassembler FLAG pass linker-specific FLAG directly to the assembler -Wl,FLAG -Xlinker FLAG pass linker-specific FLAG directly to the linker -XCClinker FLAG pass link-specific FLAG to the compiler driver (CC) All other options (arguments beginning with '-') are ignored. Every other argument is treated as a filename. Files ending in '.la' are treated as uninstalled libtool libraries, other files are standard or library object files. If the OUTPUT-FILE ends in '.la', then a libtool library is created, only library objects ('.lo' files) may be specified, and '-rpath' is required, except when creating a convenience library. If OUTPUT-FILE ends in '.a' or '.lib', then a standard library is created using 'ar' and 'ranlib', or on Windows using 'lib'. If OUTPUT-FILE ends in '.lo' or '.$objext', then a reloadable object file is created, otherwise an executable program is created." ;; uninstall) $ECHO \ "Usage: $progname [OPTION]... --mode=uninstall RM [RM-OPTION]... FILE... Remove libraries from an installation directory. RM is the name of the program to use to delete files associated with each FILE (typically '/bin/rm'). RM-OPTIONS are options (such as '-f') to be passed to RM. If FILE is a libtool library, all the files associated with it are deleted. Otherwise, only FILE itself is deleted using RM." ;; *) func_fatal_help "invalid operation mode '$opt_mode'" ;; esac echo $ECHO "Try '$progname --help' for more information about other modes." } # Now that we've collected a possible --mode arg, show help if necessary if $opt_help; then if test : = "$opt_help"; then func_mode_help else { func_help noexit for opt_mode in compile link execute install finish uninstall clean; do func_mode_help done } | $SED -n '1p; 2,$s/^Usage:/ or: /p' { func_help noexit for opt_mode in compile link execute install finish uninstall clean; do echo func_mode_help done } | $SED '1d /^When reporting/,/^Report/{ H d } $x /information about other modes/d /more detailed .*MODE/d s/^Usage:.*--mode=\([^ ]*\) .*/Description of \1 mode:/' fi exit $? fi # If option '--reorder-cache', reorder the shared library cache and exit. if $opt_reorder_cache; then func_reorder_shared_lib_cache $shared_lib_dirs fi # func_mode_execute arg... func_mode_execute () { $debug_cmd # The first argument is the command name. cmd=$nonopt test -z "$cmd" && \ func_fatal_help "you must specify a COMMAND" # Handle -dlopen flags immediately. for file in $opt_dlopen; do test -f "$file" \ || func_fatal_help "'$file' is not a file" dir= case $file in *.la) func_resolve_sysroot "$file" file=$func_resolve_sysroot_result # Check to see that this really is a libtool archive. func_lalib_unsafe_p "$file" \ || func_fatal_help "'$lib' is not a valid libtool archive" # Read the libtool library. dlname= library_names= func_source "$file" # Skip this library if it cannot be dlopened. if test -z "$dlname"; then # Warn if it was a shared library. test -n "$library_names" && \ func_warning "'$file' was not linked with '-export-dynamic'" continue fi func_dirname "$file" "" "." dir=$func_dirname_result if test -f "$dir/$objdir/$dlname"; then func_append dir "/$objdir" else if test ! -f "$dir/$dlname"; then func_fatal_error "cannot find '$dlname' in '$dir' or '$dir/$objdir'" fi fi ;; *.lo) # Just add the directory containing the .lo file. func_dirname "$file" "" "." dir=$func_dirname_result ;; *) func_warning "'-dlopen' is ignored for non-libtool libraries and objects" continue ;; esac # Get the absolute pathname. absdir=`cd "$dir" && pwd` test -n "$absdir" && dir=$absdir # Now add the directory to shlibpath_var. if eval "test -z \"\$$shlibpath_var\""; then eval "$shlibpath_var=\"\$dir\"" else eval "$shlibpath_var=\"\$dir:\$$shlibpath_var\"" fi done # This variable tells wrapper scripts just to set shlibpath_var # rather than running their programs. libtool_execute_magic=$magic # Check if any of the arguments is a wrapper script. args= for file do case $file in -* | *.la | *.lo ) ;; *) # Do a test to see if this is really a libtool program. if func_ltwrapper_script_p "$file"; then func_source "$file" # Transform arg to wrapped name. file=$progdir/$program elif func_ltwrapper_executable_p "$file"; then func_ltwrapper_scriptname "$file" func_source "$func_ltwrapper_scriptname_result" # Transform arg to wrapped name. file=$progdir/$program fi ;; esac # Quote arguments (to preserve shell metacharacters). func_append_quoted args "$file" done if $opt_dry_run; then # Display what would be done. if test -n "$shlibpath_var"; then eval "\$ECHO \"\$shlibpath_var=\$$shlibpath_var\"" echo "export $shlibpath_var" fi $ECHO "$cmd$args" exit $EXIT_SUCCESS else if test -n "$shlibpath_var"; then # Export the shlibpath_var. eval "export $shlibpath_var" fi # Restore saved environment variables for lt_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES do eval "if test \"\${save_$lt_var+set}\" = set; then $lt_var=\$save_$lt_var; export $lt_var else $lt_unset $lt_var fi" done # Now prepare to actually exec the command. exec_cmd=\$cmd$args fi } test execute = "$opt_mode" && func_mode_execute ${1+"$@"} # func_mode_finish arg... func_mode_finish () { $debug_cmd libs= libdirs= admincmds= for opt in "$nonopt" ${1+"$@"} do if test -d "$opt"; then func_append libdirs " $opt" elif test -f "$opt"; then if func_lalib_unsafe_p "$opt"; then func_append libs " $opt" else func_warning "'$opt' is not a valid libtool archive" fi else func_fatal_error "invalid argument '$opt'" fi done if test -n "$libs"; then if test -n "$lt_sysroot"; then sysroot_regex=`$ECHO "$lt_sysroot" | $SED "$sed_make_literal_regex"` sysroot_cmd="s/\([ ']\)$sysroot_regex/\1/g;" else sysroot_cmd= fi # Remove sysroot references if $opt_dry_run; then for lib in $libs; do echo "removing references to $lt_sysroot and '=' prefixes from $lib" done else tmpdir=`func_mktempdir` for lib in $libs; do $SED -e "$sysroot_cmd s/\([ ']-[LR]\)=/\1/g; s/\([ ']\)=/\1/g" $lib \ > $tmpdir/tmp-la mv -f $tmpdir/tmp-la $lib done ${RM}r "$tmpdir" fi fi if test -n "$finish_cmds$finish_eval" && test -n "$libdirs" && $opt_finishing; then for libdir in $libdirs; do if test -n "$finish_cmds"; then # Do each command in the finish commands. func_execute_cmds "$finish_cmds" 'admincmds="$admincmds '"$cmd"'"' fi if test -n "$finish_eval"; then # Do the single finish_eval. eval cmds=\"$finish_eval\" $opt_dry_run || eval "$cmds" || func_append admincmds " $cmds" fi done fi # Exit here if they wanted silent mode. $opt_quiet && exit $EXIT_SUCCESS if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then echo "----------------------------------------------------------------------" echo "Libraries have been installed in:" for libdir in $libdirs; do $ECHO " $libdir" done if test "false" = "$opt_finishing"; then echo echo "NOTE: finish_cmds were not executed during testing, so you must" echo "manually run ldconfig to add a given test directory, LIBDIR, to" echo "the search path for generated executables." fi echo echo "If you ever happen to want to link against installed libraries" echo "in a given directory, LIBDIR, you must either use libtool, and" echo "specify the full pathname of the library, or use the '-LLIBDIR'" echo "flag during linking and do at least one of the following:" if test -n "$shlibpath_var"; then echo " - add LIBDIR to the '$shlibpath_var' environment variable" echo " during execution" fi if test -n "$runpath_var"; then echo " - add LIBDIR to the '$runpath_var' environment variable" echo " during linking" fi if test -n "$hardcode_libdir_flag_spec"; then libdir=LIBDIR eval flag=\"$hardcode_libdir_flag_spec\" $ECHO " - use the '$flag' linker flag" fi if test -n "$admincmds"; then $ECHO " - have your system administrator run these commands:$admincmds" fi if test -f /etc/ld.so.conf; then echo " - have your system administrator add LIBDIR to '/etc/ld.so.conf'" fi echo echo "See any operating system documentation about shared libraries for" case $host in solaris2.[6789]|solaris2.1[0-9]) echo "more information, such as the ld(1), crle(1) and ld.so(8) manual" echo "pages." ;; *) echo "more information, such as the ld(1) and ld.so(8) manual pages." ;; esac echo "----------------------------------------------------------------------" fi exit $EXIT_SUCCESS } test finish = "$opt_mode" && func_mode_finish ${1+"$@"} # func_mode_install arg... func_mode_install () { $debug_cmd # There may be an optional sh(1) argument at the beginning of # install_prog (especially on Windows NT). if test "$SHELL" = "$nonopt" || test /bin/sh = "$nonopt" || # Allow the use of GNU shtool's install command. case $nonopt in *shtool*) :;; *) false;; esac then # Aesthetically quote it. func_quote_arg pretty "$nonopt" install_prog="$func_quote_arg_result " arg=$1 shift else install_prog= arg=$nonopt fi # The real first argument should be the name of the installation program. # Aesthetically quote it. func_quote_arg pretty "$arg" func_append install_prog "$func_quote_arg_result" install_shared_prog=$install_prog case " $install_prog " in *[\\\ /]cp\ *) install_cp=: ;; *) install_cp=false ;; esac # We need to accept at least all the BSD install flags. dest= files= opts= prev= install_type= isdir=false stripme= no_mode=: for arg do arg2= if test -n "$dest"; then func_append files " $dest" dest=$arg continue fi case $arg in -d) isdir=: ;; -f) if $install_cp; then :; else prev=$arg fi ;; -g | -m | -o) prev=$arg ;; -s) stripme=" -s" continue ;; -*) ;; *) # If the previous option needed an argument, then skip it. if test -n "$prev"; then if test X-m = "X$prev" && test -n "$install_override_mode"; then arg2=$install_override_mode no_mode=false fi prev= else dest=$arg continue fi ;; esac # Aesthetically quote the argument. func_quote_arg pretty "$arg" func_append install_prog " $func_quote_arg_result" if test -n "$arg2"; then func_quote_arg pretty "$arg2" fi func_append install_shared_prog " $func_quote_arg_result" done test -z "$install_prog" && \ func_fatal_help "you must specify an install program" test -n "$prev" && \ func_fatal_help "the '$prev' option requires an argument" if test -n "$install_override_mode" && $no_mode; then if $install_cp; then :; else func_quote_arg pretty "$install_override_mode" func_append install_shared_prog " -m $func_quote_arg_result" fi fi if test -z "$files"; then if test -z "$dest"; then func_fatal_help "no file or destination specified" else func_fatal_help "you must specify a destination" fi fi # Strip any trailing slash from the destination. func_stripname '' '/' "$dest" dest=$func_stripname_result # Check to see that the destination is a directory. test -d "$dest" && isdir=: if $isdir; then destdir=$dest destname= else func_dirname_and_basename "$dest" "" "." destdir=$func_dirname_result destname=$func_basename_result # Not a directory, so check to see that there is only one file specified. set dummy $files; shift test "$#" -gt 1 && \ func_fatal_help "'$dest' is not a directory" fi case $destdir in [\\/]* | [A-Za-z]:[\\/]*) ;; *) for file in $files; do case $file in *.lo) ;; *) func_fatal_help "'$destdir' must be an absolute directory name" ;; esac done ;; esac # This variable tells wrapper scripts just to set variables rather # than running their programs. libtool_install_magic=$magic staticlibs= future_libdirs= current_libdirs= for file in $files; do # Do each installation. case $file in *.$libext) # Do the static libraries later. func_append staticlibs " $file" ;; *.la) func_resolve_sysroot "$file" file=$func_resolve_sysroot_result # Check to see that this really is a libtool archive. func_lalib_unsafe_p "$file" \ || func_fatal_help "'$file' is not a valid libtool archive" library_names= old_library= relink_command= func_source "$file" # Add the libdir to current_libdirs if it is the destination. if test "X$destdir" = "X$libdir"; then case "$current_libdirs " in *" $libdir "*) ;; *) func_append current_libdirs " $libdir" ;; esac else # Note the libdir as a future libdir. case "$future_libdirs " in *" $libdir "*) ;; *) func_append future_libdirs " $libdir" ;; esac fi func_dirname "$file" "/" "" dir=$func_dirname_result func_append dir "$objdir" if test -n "$relink_command"; then # Strip any trailing slash from the destination. func_stripname '' '/' "$libdir" destlibdir=$func_stripname_result func_stripname '' '/' "$destdir" s_destdir=$func_stripname_result # Determine the prefix the user has applied to our future dir. inst_prefix_dir=`$ECHO "X$s_destdir" | $Xsed -e "s%$destlibdir\$%%"` # Don't allow the user to place us outside of our expected # location b/c this prevents finding dependent libraries that # are installed to the same prefix. # At present, this check doesn't affect windows .dll's that # are installed into $libdir/../bin (currently, that works fine) # but it's something to keep an eye on. test "$inst_prefix_dir" = "$destdir" && \ func_fatal_error "error: cannot install '$file' to a directory not ending in $libdir" if test -n "$inst_prefix_dir"; then # Stick the inst_prefix_dir data into the link command. relink_command=`$ECHO "$relink_command" | $SED "s%@inst_prefix_dir@%-inst-prefix-dir $inst_prefix_dir%"` else relink_command=`$ECHO "$relink_command" | $SED "s%@inst_prefix_dir@%%"` fi func_warning "relinking '$file'" func_show_eval "$relink_command" \ 'func_fatal_error "error: relink '\''$file'\'' with the above command before installing it"' fi # See the names of the shared library. set dummy $library_names; shift if test -n "$1"; then realname=$1 shift srcname=$realname test -n "$relink_command" && srcname=${realname}T # Install the shared library and build the symlinks. func_show_eval "$install_shared_prog $dir/$srcname $destdir/$realname" \ 'exit $?' tstripme=$stripme case $host_os in cygwin* | mingw* | windows* | pw32* | cegcc*) case $realname in *.dll.a) tstripme= ;; esac ;; os2*) case $realname in *_dll.a) tstripme= ;; esac ;; esac if test -n "$tstripme" && test -n "$striplib"; then func_show_eval "$striplib $destdir/$realname" 'exit $?' fi if test "$#" -gt 0; then # Delete the old symlinks, and create new ones. # Try 'ln -sf' first, because the 'ln' binary might depend on # the symlink we replace! Solaris /bin/ln does not understand -f, # so we also need to try rm && ln -s. for linkname do test "$linkname" != "$realname" \ && func_show_eval "(cd $destdir && { $LN_S -f $realname $linkname || { $RM $linkname && $LN_S $realname $linkname; }; })" done fi # Do each command in the postinstall commands. lib=$destdir/$realname func_execute_cmds "$postinstall_cmds" 'exit $?' fi # Install the pseudo-library for information purposes. func_basename "$file" name=$func_basename_result instname=$dir/${name}i func_show_eval "$install_prog $instname $destdir/$name" 'exit $?' # Maybe install the static library, too. test -n "$old_library" && func_append staticlibs " $dir/$old_library" ;; *.lo) # Install (i.e. copy) a libtool object. # Figure out destination file name, if it wasn't already specified. if test -n "$destname"; then destfile=$destdir/$destname else func_basename "$file" destfile=$func_basename_result destfile=$destdir/$destfile fi # Deduce the name of the destination old-style object file. case $destfile in *.lo) func_lo2o "$destfile" staticdest=$func_lo2o_result ;; *.$objext) staticdest=$destfile destfile= ;; *) func_fatal_help "cannot copy a libtool object to '$destfile'" ;; esac # Install the libtool object if requested. test -n "$destfile" && \ func_show_eval "$install_prog $file $destfile" 'exit $?' # Install the old object if enabled. if test yes = "$build_old_libs"; then # Deduce the name of the old-style object file. func_lo2o "$file" staticobj=$func_lo2o_result func_show_eval "$install_prog \$staticobj \$staticdest" 'exit $?' fi exit $EXIT_SUCCESS ;; *) # Figure out destination file name, if it wasn't already specified. if test -n "$destname"; then destfile=$destdir/$destname else func_basename "$file" destfile=$func_basename_result destfile=$destdir/$destfile fi # If the file is missing, and there is a .exe on the end, strip it # because it is most likely a libtool script we actually want to # install stripped_ext= case $file in *.exe) if test ! -f "$file"; then func_stripname '' '.exe' "$file" file=$func_stripname_result stripped_ext=.exe fi ;; esac # Do a test to see if this is really a libtool program. case $host in *cygwin* | *mingw* | *windows*) if func_ltwrapper_executable_p "$file"; then func_ltwrapper_scriptname "$file" wrapper=$func_ltwrapper_scriptname_result else func_stripname '' '.exe' "$file" wrapper=$func_stripname_result fi ;; *) wrapper=$file ;; esac if func_ltwrapper_script_p "$wrapper"; then notinst_deplibs= relink_command= func_source "$wrapper" # Check the variables that should have been set. test -z "$generated_by_libtool_version" && \ func_fatal_error "invalid libtool wrapper script '$wrapper'" finalize=: for lib in $notinst_deplibs; do # Check to see that each library is installed. libdir= if test -f "$lib"; then func_source "$lib" fi libfile=$libdir/`$ECHO "$lib" | $SED 's%^.*/%%g'` if test -n "$libdir" && test ! -f "$libfile"; then func_warning "'$lib' has not been installed in '$libdir'" finalize=false fi done relink_command= func_source "$wrapper" outputname= if test no = "$fast_install" && test -n "$relink_command"; then $opt_dry_run || { if $finalize; then tmpdir=`func_mktempdir` func_basename "$file$stripped_ext" file=$func_basename_result outputname=$tmpdir/$file # Replace the output file specification. relink_command=`$ECHO "$relink_command" | $SED 's%@OUTPUT@%'"$outputname"'%g'` $opt_quiet || { func_quote_arg expand,pretty "$relink_command" eval "func_echo $func_quote_arg_result" } if eval "$relink_command"; then : else func_error "error: relink '$file' with the above command before installing it" $opt_dry_run || ${RM}r "$tmpdir" continue fi file=$outputname else func_warning "cannot relink '$file'" fi } else # Install the binary that we compiled earlier. file=`$ECHO "$file$stripped_ext" | $SED "s%\([^/]*\)$%$objdir/\1%"` fi fi # remove .exe since cygwin /usr/bin/install will append another # one anyway case $install_prog,$host in */usr/bin/install*,*cygwin*) case $file:$destfile in *.exe:*.exe) # this is ok ;; *.exe:*) destfile=$destfile.exe ;; *:*.exe) func_stripname '' '.exe' "$destfile" destfile=$func_stripname_result ;; esac ;; esac func_show_eval "$install_prog\$stripme \$file \$destfile" 'exit $?' $opt_dry_run || if test -n "$outputname"; then ${RM}r "$tmpdir" fi ;; esac done for file in $staticlibs; do func_basename "$file" name=$func_basename_result # Set up the ranlib parameters. oldlib=$destdir/$name func_to_tool_file "$oldlib" func_convert_file_msys_to_w32 tool_oldlib=$func_to_tool_file_result func_show_eval "$install_prog \$file \$oldlib" 'exit $?' if test -n "$stripme" && test -n "$old_striplib"; then func_show_eval "$old_striplib $tool_oldlib" 'exit $?' fi # Do each command in the postinstall commands. func_execute_cmds "$old_postinstall_cmds" 'exit $?' done test -n "$future_libdirs" && \ func_warning "remember to run '$progname --finish$future_libdirs'" if test -n "$current_libdirs"; then # Maybe just do a dry run. $opt_dry_run && current_libdirs=" -n$current_libdirs" exec_cmd='$SHELL "$progpath" $preserve_args --finish$current_libdirs' else exit $EXIT_SUCCESS fi } test install = "$opt_mode" && func_mode_install ${1+"$@"} # func_generate_dlsyms outputname originator pic_p # Extract symbols from dlprefiles and create ${outputname}S.o with # a dlpreopen symbol table. func_generate_dlsyms () { $debug_cmd my_outputname=$1 my_originator=$2 my_pic_p=${3-false} my_prefix=`$ECHO "$my_originator" | $SED 's%[^a-zA-Z0-9]%_%g'` my_dlsyms= if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then if test -n "$NM" && test -n "$global_symbol_pipe"; then my_dlsyms=${my_outputname}S.c else func_error "not configured to extract global symbols from dlpreopened files" fi fi if test -n "$my_dlsyms"; then case $my_dlsyms in "") ;; *.c) # Discover the nlist of each of the dlfiles. nlist=$output_objdir/$my_outputname.nm func_show_eval "$RM $nlist ${nlist}S ${nlist}T" # Parse the name list into a source file. func_verbose "creating $output_objdir/$my_dlsyms" $opt_dry_run || $ECHO > "$output_objdir/$my_dlsyms" "\ /* $my_dlsyms - symbol resolution table for '$my_outputname' dlsym emulation. */ /* Generated by $PROGRAM (GNU $PACKAGE) $VERSION */ #ifdef __cplusplus extern \"C\" { #endif #if defined __GNUC__ && (((__GNUC__ == 4) && (__GNUC_MINOR__ >= 4)) || (__GNUC__ > 4)) #pragma GCC diagnostic ignored \"-Wstrict-prototypes\" #endif /* Keep this code in sync between libtool.m4, ltmain, lt_system.h, and tests. */ #if defined _WIN32 || defined __CYGWIN__ || defined _WIN32_WCE /* DATA imports from DLLs on WIN32 can't be const, because runtime relocations are performed -- see ld's documentation on pseudo-relocs. */ # define LT_DLSYM_CONST #elif defined __osf__ /* This system does not cope well with relocations in const data. */ # define LT_DLSYM_CONST #else # define LT_DLSYM_CONST const #endif #define STREQ(s1, s2) (strcmp ((s1), (s2)) == 0) /* External symbol declarations for the compiler. */\ " if test yes = "$dlself"; then func_verbose "generating symbol list for '$output'" $opt_dry_run || echo ': @PROGRAM@ ' > "$nlist" # Add our own program objects to the symbol list. progfiles=`$ECHO "$objs$old_deplibs" | $SP2NL | $SED "$lo2o" | $NL2SP` for progfile in $progfiles; do func_to_tool_file "$progfile" func_convert_file_msys_to_w32 func_verbose "extracting global C symbols from '$func_to_tool_file_result'" $opt_dry_run || eval "$NM $func_to_tool_file_result | $global_symbol_pipe >> '$nlist'" done if test -n "$exclude_expsyms"; then $opt_dry_run || { eval '$EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T' eval '$MV "$nlist"T "$nlist"' } fi if test -n "$export_symbols_regex"; then $opt_dry_run || { eval '$EGREP -e "$export_symbols_regex" "$nlist" > "$nlist"T' eval '$MV "$nlist"T "$nlist"' } fi # Prepare the list of exported symbols if test -z "$export_symbols"; then export_symbols=$output_objdir/$outputname.exp $opt_dry_run || { $RM $export_symbols eval "$SED -n -e '/^: @PROGRAM@ $/d' -e 's/^.* \(.*\)$/\1/p' "'< "$nlist" > "$export_symbols"' case $host in *cygwin* | *mingw* | *windows* | *cegcc* ) eval "echo EXPORTS "'> "$output_objdir/$outputname.def"' eval 'cat "$export_symbols" >> "$output_objdir/$outputname.def"' ;; esac } else $opt_dry_run || { eval "$SED -e 's/\([].[*^$]\)/\\\\\1/g' -e 's/^/ /' -e 's/$/$/'"' < "$export_symbols" > "$output_objdir/$outputname.exp"' eval '$GREP -f "$output_objdir/$outputname.exp" < "$nlist" > "$nlist"T' eval '$MV "$nlist"T "$nlist"' case $host in *cygwin* | *mingw* | *windows* | *cegcc* ) eval "echo EXPORTS "'> "$output_objdir/$outputname.def"' eval 'cat "$nlist" >> "$output_objdir/$outputname.def"' ;; esac } fi fi for dlprefile in $dlprefiles; do func_verbose "extracting global C symbols from '$dlprefile'" func_basename "$dlprefile" name=$func_basename_result case $host in *cygwin* | *mingw* | *windows* | *cegcc* ) # if an import library, we need to obtain dlname if func_win32_import_lib_p "$dlprefile"; then func_tr_sh "$dlprefile" eval "curr_lafile=\$libfile_$func_tr_sh_result" dlprefile_dlbasename= if test -n "$curr_lafile" && func_lalib_p "$curr_lafile"; then # Use subshell, to avoid clobbering current variable values dlprefile_dlname=`source "$curr_lafile" && echo "$dlname"` if test -n "$dlprefile_dlname"; then func_basename "$dlprefile_dlname" dlprefile_dlbasename=$func_basename_result else # no lafile. user explicitly requested -dlpreopen . $sharedlib_from_linklib_cmd "$dlprefile" dlprefile_dlbasename=$sharedlib_from_linklib_result fi fi $opt_dry_run || { if test -n "$dlprefile_dlbasename"; then eval '$ECHO ": $dlprefile_dlbasename" >> "$nlist"' else func_warning "Could not compute DLL name from $name" eval '$ECHO ": $name " >> "$nlist"' fi func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32 case $host in i[3456]86-*-mingw32*) eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe | $SED -e '/I __imp/d' -e 's/I __nm_/D /;s/_nm__//' >> '$nlist'" ;; *) eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe | $SED -e '/I __imp/d' -e 's/I __nm_/D /;s/__nm_//' >> '$nlist'" ;; esac } else # not an import lib $opt_dry_run || { eval '$ECHO ": $name " >> "$nlist"' func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32 eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe >> '$nlist'" } fi ;; *) $opt_dry_run || { eval '$ECHO ": $name " >> "$nlist"' func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32 eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe >> '$nlist'" } ;; esac done $opt_dry_run || { # Make sure we have at least an empty file. test -f "$nlist" || : > "$nlist" if test -n "$exclude_expsyms"; then $EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T $MV "$nlist"T "$nlist" fi # Try sorting and uniquifying the output. if $GREP -v "^: " < "$nlist" | if sort -k 3 /dev/null 2>&1; then sort -k 3 else sort +2 fi | uniq > "$nlist"S; then : else $GREP -v "^: " < "$nlist" > "$nlist"S fi if test -f "$nlist"S; then eval "$global_symbol_to_cdecl"' < "$nlist"S >> "$output_objdir/$my_dlsyms"' else echo '/* NONE */' >> "$output_objdir/$my_dlsyms" fi func_show_eval '$RM "${nlist}I"' if test -n "$global_symbol_to_import"; then eval "$global_symbol_to_import"' < "$nlist"S > "$nlist"I' fi echo >> "$output_objdir/$my_dlsyms" "\ /* The mapping between symbol names and symbols. */ typedef struct { const char *name; void *address; } lt_dlsymlist; extern LT_DLSYM_CONST lt_dlsymlist lt_${my_prefix}_LTX_preloaded_symbols[];\ " if test -s "$nlist"I; then echo >> "$output_objdir/$my_dlsyms" "\ static void lt_syminit(void) { LT_DLSYM_CONST lt_dlsymlist *symbol = lt_${my_prefix}_LTX_preloaded_symbols; for (; symbol->name; ++symbol) {" $SED 's/.*/ if (STREQ (symbol->name, \"&\")) symbol->address = (void *) \&&;/' < "$nlist"I >> "$output_objdir/$my_dlsyms" echo >> "$output_objdir/$my_dlsyms" "\ } }" fi echo >> "$output_objdir/$my_dlsyms" "\ LT_DLSYM_CONST lt_dlsymlist lt_${my_prefix}_LTX_preloaded_symbols[] = { {\"$my_originator\", (void *) 0}," if test -s "$nlist"I; then echo >> "$output_objdir/$my_dlsyms" "\ {\"@INIT@\", (void *) <_syminit}," fi case $need_lib_prefix in no) eval "$global_symbol_to_c_name_address" < "$nlist" >> "$output_objdir/$my_dlsyms" ;; *) eval "$global_symbol_to_c_name_address_lib_prefix" < "$nlist" >> "$output_objdir/$my_dlsyms" ;; esac echo >> "$output_objdir/$my_dlsyms" "\ {0, (void *) 0} }; /* This works around a problem in FreeBSD linker */ #ifdef FREEBSD_WORKAROUND static const void *lt_preloaded_setup() { return lt_${my_prefix}_LTX_preloaded_symbols; } #endif #ifdef __cplusplus } #endif\ " } # !$opt_dry_run pic_flag_for_symtable= case "$compile_command " in *" -static "*) ;; *) case $host in # compiling the symbol table file with pic_flag works around # a FreeBSD bug that causes programs to crash when -lm is # linked before any other PIC object. But we must not use # pic_flag when linking with -static. The problem exists in # FreeBSD 2.2.6 and is fixed in FreeBSD 3.1. *-*-freebsd2.*|*-*-freebsd3.0*|*-*-freebsdelf3.0*) pic_flag_for_symtable=" $pic_flag -DFREEBSD_WORKAROUND" ;; *-*-hpux*) pic_flag_for_symtable=" $pic_flag" ;; *) $my_pic_p && pic_flag_for_symtable=" $pic_flag" ;; esac ;; esac symtab_cflags= for arg in $LTCFLAGS; do case $arg in -pie | -fpie | -fPIE) ;; *) func_append symtab_cflags " $arg" ;; esac done # Now compile the dynamic symbol file. func_show_eval '(cd $output_objdir && $LTCC$symtab_cflags -c$no_builtin_flag$pic_flag_for_symtable "$my_dlsyms")' 'exit $?' # Clean up the generated files. func_show_eval '$RM "$output_objdir/$my_dlsyms" "$nlist" "${nlist}S" "${nlist}T" "${nlist}I"' # Transform the symbol file into the correct name. symfileobj=$output_objdir/${my_outputname}S.$objext case $host in *cygwin* | *mingw* | *windows* | *cegcc* ) if test -f "$output_objdir/$my_outputname.def"; then compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"` finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"` else compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$symfileobj%"` finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$symfileobj%"` fi ;; *) compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$symfileobj%"` finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$symfileobj%"` ;; esac ;; *) func_fatal_error "unknown suffix for '$my_dlsyms'" ;; esac else # We keep going just in case the user didn't refer to # lt_preloaded_symbols. The linker will fail if global_symbol_pipe # really was required. # Nullify the symbol file. compile_command=`$ECHO "$compile_command" | $SED "s% @SYMFILE@%%"` finalize_command=`$ECHO "$finalize_command" | $SED "s% @SYMFILE@%%"` fi } # func_cygming_gnu_implib_p ARG # This predicate returns with zero status (TRUE) if # ARG is a GNU/binutils-style import library. Returns # with nonzero status (FALSE) otherwise. func_cygming_gnu_implib_p () { $debug_cmd func_to_tool_file "$1" func_convert_file_msys_to_w32 func_cygming_gnu_implib_tmp=`$NM "$func_to_tool_file_result" | eval "$global_symbol_pipe" | $EGREP ' (_head_[A-Za-z0-9_]+_[ad]l*|[A-Za-z0-9_]+_[ad]l*_iname)$'` test -n "$func_cygming_gnu_implib_tmp" } # func_cygming_ms_implib_p ARG # This predicate returns with zero status (TRUE) if # ARG is an MS-style import library. Returns # with nonzero status (FALSE) otherwise. func_cygming_ms_implib_p () { $debug_cmd func_to_tool_file "$1" func_convert_file_msys_to_w32 func_cygming_ms_implib_tmp=`$NM "$func_to_tool_file_result" | eval "$global_symbol_pipe" | $GREP '_NULL_IMPORT_DESCRIPTOR'` test -n "$func_cygming_ms_implib_tmp" } # func_win32_libid arg # return the library type of file 'arg' # # Need a lot of goo to handle *both* DLLs and import libs # Has to be a shell function in order to 'eat' the argument # that is supplied when $file_magic_command is called. # Despite the name, also deal with 64 bit binaries. func_win32_libid () { $debug_cmd win32_libid_type=unknown win32_fileres=`file -L $1 2>/dev/null` case $win32_fileres in *ar\ archive\ import\ library*) # definitely import win32_libid_type="x86 archive import" ;; *ar\ archive*) # could be an import, or static # Keep the egrep pattern in sync with the one in _LT_CHECK_MAGIC_METHOD. if eval $OBJDUMP -f $1 | $SED -e '10q' 2>/dev/null | $EGREP 'file format (pei*-i386(.*architecture: i386)?|pe-arm-wince|pe-x86-64|pe-aarch64)' >/dev/null; then case $nm_interface in "MS dumpbin") if func_cygming_ms_implib_p "$1" || func_cygming_gnu_implib_p "$1" then win32_nmres=import else win32_nmres= fi ;; *) func_to_tool_file "$1" func_convert_file_msys_to_w32 win32_nmres=`eval $NM -f posix -A \"$func_to_tool_file_result\" | $SED -n -e ' 1,100{ / I /{ s|.*|import| p q } }'` ;; esac case $win32_nmres in import*) win32_libid_type="x86 archive import";; *) win32_libid_type="x86 archive static";; esac fi ;; *DLL*) win32_libid_type="x86 DLL" ;; *executable*) # but shell scripts are "executable" too... case $win32_fileres in *MS\ Windows\ PE\ Intel*) win32_libid_type="x86 DLL" ;; esac ;; esac $ECHO "$win32_libid_type" } # func_cygming_dll_for_implib ARG # # Platform-specific function to extract the # name of the DLL associated with the specified # import library ARG. # Invoked by eval'ing the libtool variable # $sharedlib_from_linklib_cmd # Result is available in the variable # $sharedlib_from_linklib_result func_cygming_dll_for_implib () { $debug_cmd sharedlib_from_linklib_result=`$DLLTOOL --identify-strict --identify "$1"` } # func_cygming_dll_for_implib_fallback_core SECTION_NAME LIBNAMEs # # The is the core of a fallback implementation of a # platform-specific function to extract the name of the # DLL associated with the specified import library LIBNAME. # # SECTION_NAME is either .idata$6 or .idata$7, depending # on the platform and compiler that created the implib. # # Echos the name of the DLL associated with the # specified import library. func_cygming_dll_for_implib_fallback_core () { $debug_cmd match_literal=`$ECHO "$1" | $SED "$sed_make_literal_regex"` $OBJDUMP -s --section "$1" "$2" 2>/dev/null | $SED '/^Contents of section '"$match_literal"':/{ # Place marker at beginning of archive member dllname section s/.*/====MARK====/ p d } # These lines can sometimes be longer than 43 characters, but # are always uninteresting /:[ ]*file format pe[i]\{,1\}-/d /^In archive [^:]*:/d # Ensure marker is printed /^====MARK====/p # Remove all lines with less than 43 characters /^.\{43\}/!d # From remaining lines, remove first 43 characters s/^.\{43\}//' | $SED -n ' # Join marker and all lines until next marker into a single line /^====MARK====/ b para H $ b para b :para x s/\n//g # Remove the marker s/^====MARK====// # Remove trailing dots and whitespace s/[\. \t]*$// # Print /./p' | # we now have a list, one entry per line, of the stringified # contents of the appropriate section of all members of the # archive that possess that section. Heuristic: eliminate # all those that have a first or second character that is # a '.' (that is, objdump's representation of an unprintable # character.) This should work for all archives with less than # 0x302f exports -- but will fail for DLLs whose name actually # begins with a literal '.' or a single character followed by # a '.'. # # Of those that remain, print the first one. $SED -e '/^\./d;/^.\./d;q' } # func_cygming_dll_for_implib_fallback ARG # Platform-specific function to extract the # name of the DLL associated with the specified # import library ARG. # # This fallback implementation is for use when $DLLTOOL # does not support the --identify-strict option. # Invoked by eval'ing the libtool variable # $sharedlib_from_linklib_cmd # Result is available in the variable # $sharedlib_from_linklib_result func_cygming_dll_for_implib_fallback () { $debug_cmd if func_cygming_gnu_implib_p "$1"; then # binutils import library sharedlib_from_linklib_result=`func_cygming_dll_for_implib_fallback_core '.idata$7' "$1"` elif func_cygming_ms_implib_p "$1"; then # ms-generated import library sharedlib_from_linklib_result=`func_cygming_dll_for_implib_fallback_core '.idata$6' "$1"` else # unknown sharedlib_from_linklib_result= fi } # func_extract_an_archive dir oldlib func_extract_an_archive () { $debug_cmd f_ex_an_ar_dir=$1; shift f_ex_an_ar_oldlib=$1 if test yes = "$lock_old_archive_extraction"; then lockfile=$f_ex_an_ar_oldlib.lock until $opt_dry_run || ln "$progpath" "$lockfile" 2>/dev/null; do func_echo "Waiting for $lockfile to be removed" sleep 2 done fi func_show_eval "(cd \$f_ex_an_ar_dir && $AR x \"\$f_ex_an_ar_oldlib\")" \ 'stat=$?; rm -f "$lockfile"; exit $stat' if test yes = "$lock_old_archive_extraction"; then $opt_dry_run || rm -f "$lockfile" fi if ($AR t "$f_ex_an_ar_oldlib" | sort | sort -uc >/dev/null 2>&1); then : else func_fatal_error "object name conflicts in archive: $f_ex_an_ar_dir/$f_ex_an_ar_oldlib" fi } # func_extract_archives gentop oldlib ... func_extract_archives () { $debug_cmd my_gentop=$1; shift my_oldlibs=${1+"$@"} my_oldobjs= my_xlib= my_xabs= my_xdir= for my_xlib in $my_oldlibs; do # Extract the objects. case $my_xlib in [\\/]* | [A-Za-z]:[\\/]*) my_xabs=$my_xlib ;; *) my_xabs=`pwd`"/$my_xlib" ;; esac func_basename "$my_xlib" my_xlib=$func_basename_result my_xlib_u=$my_xlib while :; do case " $extracted_archives " in *" $my_xlib_u "*) func_arith $extracted_serial + 1 extracted_serial=$func_arith_result my_xlib_u=lt$extracted_serial-$my_xlib ;; *) break ;; esac done extracted_archives="$extracted_archives $my_xlib_u" my_xdir=$my_gentop/$my_xlib_u func_mkdir_p "$my_xdir" case $host in *-darwin*) func_verbose "Extracting $my_xabs" # Do not bother doing anything if just a dry run $opt_dry_run || { darwin_orig_dir=`pwd` cd $my_xdir || exit $? darwin_archive=$my_xabs darwin_curdir=`pwd` func_basename "$darwin_archive" darwin_base_archive=$func_basename_result darwin_arches=`$LIPO -info "$darwin_archive" 2>/dev/null | $GREP Architectures 2>/dev/null || true` if test -n "$darwin_arches"; then darwin_arches=`$ECHO "$darwin_arches" | $SED -e 's/.*are://'` darwin_arch= func_verbose "$darwin_base_archive has multiple architectures $darwin_arches" for darwin_arch in $darwin_arches; do func_mkdir_p "unfat-$$/$darwin_base_archive-$darwin_arch" $LIPO -thin $darwin_arch -output "unfat-$$/$darwin_base_archive-$darwin_arch/$darwin_base_archive" "$darwin_archive" cd "unfat-$$/$darwin_base_archive-$darwin_arch" func_extract_an_archive "`pwd`" "$darwin_base_archive" cd "$darwin_curdir" $RM "unfat-$$/$darwin_base_archive-$darwin_arch/$darwin_base_archive" done # $darwin_arches ## Okay now we've a bunch of thin objects, gotta fatten them up :) darwin_filelist=`find unfat-$$ -type f -name \*.o -print -o -name \*.lo -print | $SED -e "$sed_basename" | sort -u` darwin_file= darwin_files= for darwin_file in $darwin_filelist; do darwin_files=`find unfat-$$ -name $darwin_file -print | sort | $NL2SP` $LIPO -create -output "$darwin_file" $darwin_files done # $darwin_filelist $RM -rf unfat-$$ cd "$darwin_orig_dir" else cd $darwin_orig_dir func_extract_an_archive "$my_xdir" "$my_xabs" fi # $darwin_arches } # !$opt_dry_run ;; *) func_extract_an_archive "$my_xdir" "$my_xabs" ;; esac my_oldobjs="$my_oldobjs "`find $my_xdir -name \*.$objext -print -o -name \*.lo -print | sort | $NL2SP` done func_extract_archives_result=$my_oldobjs } # func_emit_wrapper [arg=no] # # Emit a libtool wrapper script on stdout. # Don't directly open a file because we may want to # incorporate the script contents within a cygwin/mingw/windows # wrapper executable. Must ONLY be called from within # func_mode_link because it depends on a number of variables # set therein. # # ARG is the value that the WRAPPER_SCRIPT_BELONGS_IN_OBJDIR # variable will take. If 'yes', then the emitted script # will assume that the directory where it is stored is # the $objdir directory. This is a cygwin/mingw/windows-specific # behavior. func_emit_wrapper () { func_emit_wrapper_arg1=${1-no} $ECHO "\ #! $SHELL # $output - temporary wrapper script for $objdir/$outputname # Generated by $PROGRAM (GNU $PACKAGE) $VERSION # # The $output program cannot be directly executed until all the libtool # libraries that it depends on are installed. # # This wrapper script should never be moved out of the build directory. # If it is, it will not operate correctly. # Sed substitution that helps us do robust quoting. It backslashifies # metacharacters that are still active within double-quoted strings. sed_quote_subst='$sed_quote_subst' # Be Bourne compatible if test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then emulate sh NULLCMD=: # Zsh 3.x and 4.x performs word splitting on \${1+\"\$@\"}, which # is contrary to our usage. Disable this feature. alias -g '\${1+\"\$@\"}'='\"\$@\"' setopt NO_GLOB_SUBST else case \`(set -o) 2>/dev/null\` in *posix*) set -o posix;; esac fi BIN_SH=xpg4; export BIN_SH # for Tru64 DUALCASE=1; export DUALCASE # for MKS sh # The HP-UX ksh and POSIX shell print the target directory to stdout # if CDPATH is set. (unset CDPATH) >/dev/null 2>&1 && unset CDPATH relink_command=\"$relink_command\" # This environment variable determines our operation mode. if test \"\$libtool_install_magic\" = \"$magic\"; then # install mode needs the following variables: generated_by_libtool_version='$macro_version' notinst_deplibs='$notinst_deplibs' else # When we are sourced in execute mode, \$file and \$ECHO are already set. if test \"\$libtool_execute_magic\" != \"$magic\"; then file=\"\$0\"" func_quote_arg pretty "$ECHO" qECHO=$func_quote_arg_result $ECHO "\ # A function that is used when there is no print builtin or printf. func_fallback_echo () { eval 'cat <<_LTECHO_EOF \$1 _LTECHO_EOF' } ECHO=$qECHO fi # Very basic option parsing. These options are (a) specific to # the libtool wrapper, (b) are identical between the wrapper # /script/ and the wrapper /executable/ that is used only on # windows platforms, and (c) all begin with the string "--lt-" # (application programs are unlikely to have options that match # this pattern). # # There are only two supported options: --lt-debug and # --lt-dump-script. There is, deliberately, no --lt-help. # # The first argument to this parsing function should be the # script's $0 value, followed by "$@". lt_option_debug= func_parse_lt_options () { lt_script_arg0=\$0 shift for lt_opt do case \"\$lt_opt\" in --lt-debug) lt_option_debug=1 ;; --lt-dump-script) lt_dump_D=\`\$ECHO \"X\$lt_script_arg0\" | $SED -e 's/^X//' -e 's%/[^/]*$%%'\` test \"X\$lt_dump_D\" = \"X\$lt_script_arg0\" && lt_dump_D=. lt_dump_F=\`\$ECHO \"X\$lt_script_arg0\" | $SED -e 's/^X//' -e 's%^.*/%%'\` cat \"\$lt_dump_D/\$lt_dump_F\" exit 0 ;; --lt-*) \$ECHO \"Unrecognized --lt- option: '\$lt_opt'\" 1>&2 exit 1 ;; esac done # Print the debug banner immediately: if test -n \"\$lt_option_debug\"; then echo \"$outputname:$output:\$LINENO: libtool wrapper (GNU $PACKAGE) $VERSION\" 1>&2 fi } # Used when --lt-debug. Prints its arguments to stdout # (redirection is the responsibility of the caller) func_lt_dump_args () { lt_dump_args_N=1; for lt_arg do \$ECHO \"$outputname:$output:\$LINENO: newargv[\$lt_dump_args_N]: \$lt_arg\" lt_dump_args_N=\`expr \$lt_dump_args_N + 1\` done } # Core function for launching the target application func_exec_program_core () { " case $host in # Backslashes separate directories on plain windows *-*-mingw* | *-*-windows* | *-*-os2* | *-cegcc*) $ECHO "\ if test -n \"\$lt_option_debug\"; then \$ECHO \"$outputname:$output:\$LINENO: newargv[0]: \$progdir\\\\\$program\" 1>&2 func_lt_dump_args \${1+\"\$@\"} 1>&2 fi exec \"\$progdir\\\\\$program\" \${1+\"\$@\"} " ;; *) $ECHO "\ if test -n \"\$lt_option_debug\"; then \$ECHO \"$outputname:$output:\$LINENO: newargv[0]: \$progdir/\$program\" 1>&2 func_lt_dump_args \${1+\"\$@\"} 1>&2 fi exec \"\$progdir/\$program\" \${1+\"\$@\"} " ;; esac $ECHO "\ \$ECHO \"\$0: cannot exec \$program \$*\" 1>&2 exit 1 } # A function to encapsulate launching the target application # Strips options in the --lt-* namespace from \$@ and # launches target application with the remaining arguments. func_exec_program () { case \" \$* \" in *\\ --lt-*) for lt_wr_arg do case \$lt_wr_arg in --lt-*) ;; *) set x \"\$@\" \"\$lt_wr_arg\"; shift;; esac shift done ;; esac func_exec_program_core \${1+\"\$@\"} } # Parse options func_parse_lt_options \"\$0\" \${1+\"\$@\"} # Find the directory that this script lives in. thisdir=\`\$ECHO \"\$file\" | $SED 's%/[^/]*$%%'\` test \"x\$thisdir\" = \"x\$file\" && thisdir=. # Follow symbolic links until we get to the real thisdir. file=\`ls -ld \"\$file\" | $SED -n 's/.*-> //p'\` while test -n \"\$file\"; do destdir=\`\$ECHO \"\$file\" | $SED 's%/[^/]*\$%%'\` # If there was a directory component, then change thisdir. if test \"x\$destdir\" != \"x\$file\"; then case \"\$destdir\" in [\\\\/]* | [A-Za-z]:[\\\\/]*) thisdir=\"\$destdir\" ;; *) thisdir=\"\$thisdir/\$destdir\" ;; esac fi file=\`\$ECHO \"\$file\" | $SED 's%^.*/%%'\` file=\`ls -ld \"\$thisdir/\$file\" | $SED -n 's/.*-> //p'\` done # Usually 'no', except on cygwin/mingw/windows when embedded into # the cwrapper. WRAPPER_SCRIPT_BELONGS_IN_OBJDIR=$func_emit_wrapper_arg1 if test \"\$WRAPPER_SCRIPT_BELONGS_IN_OBJDIR\" = \"yes\"; then # special case for '.' if test \"\$thisdir\" = \".\"; then thisdir=\`pwd\` fi # remove .libs from thisdir case \"\$thisdir\" in *[\\\\/]$objdir ) thisdir=\`\$ECHO \"\$thisdir\" | $SED 's%[\\\\/][^\\\\/]*$%%'\` ;; $objdir ) thisdir=. ;; esac fi # Try to get the absolute directory name. absdir=\`cd \"\$thisdir\" && pwd\` test -n \"\$absdir\" && thisdir=\"\$absdir\" " if test yes = "$fast_install"; then $ECHO "\ program=lt-'$outputname'$exeext progdir=\"\$thisdir/$objdir\" if test ! -f \"\$progdir/\$program\" || { file=\`ls -1dt \"\$progdir/\$program\" \"\$progdir/../\$program\" 2>/dev/null | $SED 1q\`; \\ test \"X\$file\" != \"X\$progdir/\$program\"; }; then file=\"\$\$-\$program\" if test ! -d \"\$progdir\"; then $MKDIR \"\$progdir\" else $RM \"\$progdir/\$file\" fi" $ECHO "\ # relink executable if necessary if test -n \"\$relink_command\"; then if relink_command_output=\`eval \$relink_command 2>&1\`; then : else \$ECHO \"\$relink_command_output\" >&2 $RM \"\$progdir/\$file\" exit 1 fi fi $MV \"\$progdir/\$file\" \"\$progdir/\$program\" 2>/dev/null || { $RM \"\$progdir/\$program\"; $MV \"\$progdir/\$file\" \"\$progdir/\$program\"; } $RM \"\$progdir/\$file\" fi" else $ECHO "\ program='$outputname' progdir=\"\$thisdir/$objdir\" " fi $ECHO "\ if test -f \"\$progdir/\$program\"; then" # fixup the dll searchpath if we need to. # # Fix the DLL searchpath if we need to. Do this before prepending # to shlibpath, because on Windows, both are PATH and uninstalled # libraries must come first. if test -n "$dllsearchpath"; then $ECHO "\ # Add the dll search path components to the executable PATH PATH=$dllsearchpath:\$PATH " fi # Export our shlibpath_var if we have one. if test yes = "$shlibpath_overrides_runpath" && test -n "$shlibpath_var" && test -n "$temp_rpath"; then $ECHO "\ # Add our own library path to $shlibpath_var $shlibpath_var=\"$temp_rpath\$$shlibpath_var\" # Some systems cannot cope with colon-terminated $shlibpath_var # The second colon is a workaround for a bug in BeOS R4 sed $shlibpath_var=\`\$ECHO \"\$$shlibpath_var\" | $SED 's/::*\$//'\` export $shlibpath_var " fi $ECHO "\ if test \"\$libtool_execute_magic\" != \"$magic\"; then # Run the actual program with our arguments. func_exec_program \${1+\"\$@\"} fi else # The program doesn't exist. \$ECHO \"\$0: error: '\$progdir/\$program' does not exist\" 1>&2 \$ECHO \"This script is just a wrapper for \$program.\" 1>&2 \$ECHO \"See the $PACKAGE documentation for more information.\" 1>&2 exit 1 fi fi\ " } # func_emit_cwrapperexe_src # emit the source code for a wrapper executable on stdout # Must ONLY be called from within func_mode_link because # it depends on a number of variable set therein. func_emit_cwrapperexe_src () { cat < #include #if defined _WIN32 && !defined __GNUC__ # include # include # include #else # include # include # ifdef __CYGWIN__ # include # endif #endif #include #include #include #include #include #include #include #include #define STREQ(s1, s2) (strcmp ((s1), (s2)) == 0) /* declarations of non-ANSI functions */ #if defined __MINGW32__ # ifdef __STRICT_ANSI__ _CRTIMP int __cdecl _putenv (const char *); # endif #elif defined __CYGWIN__ # ifdef __STRICT_ANSI__ char *realpath (const char *, char *); int putenv (char *); int setenv (const char *, const char *, int); # endif /* #elif defined other_platform || defined ... */ #endif /* portability defines, excluding path handling macros */ #if defined _MSC_VER # define setmode _setmode # define stat _stat # define chmod _chmod # define getcwd _getcwd # define putenv _putenv # define S_IXUSR _S_IEXEC #elif defined __MINGW32__ # define setmode _setmode # define stat _stat # define chmod _chmod # define getcwd _getcwd # define putenv _putenv #elif defined __CYGWIN__ # define HAVE_SETENV # define FOPEN_WB "wb" /* #elif defined other platforms ... */ #endif #if defined PATH_MAX # define LT_PATHMAX PATH_MAX #elif defined MAXPATHLEN # define LT_PATHMAX MAXPATHLEN #else # define LT_PATHMAX 1024 #endif #ifndef S_IXOTH # define S_IXOTH 0 #endif #ifndef S_IXGRP # define S_IXGRP 0 #endif /* path handling portability macros */ #ifndef DIR_SEPARATOR # define DIR_SEPARATOR '/' # define PATH_SEPARATOR ':' #endif #if defined _WIN32 || defined __MSDOS__ || defined __DJGPP__ || \ defined __OS2__ # define HAVE_DOS_BASED_FILE_SYSTEM # define FOPEN_WB "wb" # ifndef DIR_SEPARATOR_2 # define DIR_SEPARATOR_2 '\\' # endif # ifndef PATH_SEPARATOR_2 # define PATH_SEPARATOR_2 ';' # endif #endif #ifndef DIR_SEPARATOR_2 # define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR) #else /* DIR_SEPARATOR_2 */ # define IS_DIR_SEPARATOR(ch) \ (((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2)) #endif /* DIR_SEPARATOR_2 */ #ifndef PATH_SEPARATOR_2 # define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR) #else /* PATH_SEPARATOR_2 */ # define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR_2) #endif /* PATH_SEPARATOR_2 */ #ifndef FOPEN_WB # define FOPEN_WB "w" #endif #ifndef _O_BINARY # define _O_BINARY 0 #endif #define XMALLOC(type, num) ((type *) xmalloc ((num) * sizeof(type))) #define XFREE(stale) do { \ if (stale) { free (stale); stale = 0; } \ } while (0) #if defined LT_DEBUGWRAPPER static int lt_debug = 1; #else static int lt_debug = 0; #endif const char *program_name = "libtool-wrapper"; /* in case xstrdup fails */ void *xmalloc (size_t num); char *xstrdup (const char *string); const char *base_name (const char *name); char *find_executable (const char *wrapper); char *chase_symlinks (const char *pathspec); int make_executable (const char *path); int check_executable (const char *path); char *strendzap (char *str, const char *pat); void lt_debugprintf (const char *file, int line, const char *fmt, ...); void lt_fatal (const char *file, int line, const char *message, ...); static const char *nonnull (const char *s); static const char *nonempty (const char *s); void lt_setenv (const char *name, const char *value); char *lt_extend_str (const char *orig_value, const char *add, int to_end); void lt_update_exe_path (const char *name, const char *value); void lt_update_lib_path (const char *name, const char *value); char **prepare_spawn (char **argv); void lt_dump_script (FILE *f); EOF cat <= 0) && (st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH))) return 1; else return 0; } int make_executable (const char *path) { int rval = 0; struct stat st; lt_debugprintf (__FILE__, __LINE__, "(make_executable): %s\n", nonempty (path)); if ((!path) || (!*path)) return 0; if (stat (path, &st) >= 0) { rval = chmod (path, st.st_mode | S_IXOTH | S_IXGRP | S_IXUSR); } return rval; } /* Searches for the full path of the wrapper. Returns newly allocated full path name if found, NULL otherwise Does not chase symlinks, even on platforms that support them. */ char * find_executable (const char *wrapper) { int has_slash = 0; const char *p; const char *p_next; /* static buffer for getcwd */ char tmp[LT_PATHMAX + 1]; size_t tmp_len; char *concat_name; lt_debugprintf (__FILE__, __LINE__, "(find_executable): %s\n", nonempty (wrapper)); if ((wrapper == NULL) || (*wrapper == '\0')) return NULL; /* Absolute path? */ #if defined HAVE_DOS_BASED_FILE_SYSTEM if (isalpha ((unsigned char) wrapper[0]) && wrapper[1] == ':') { concat_name = xstrdup (wrapper); if (check_executable (concat_name)) return concat_name; XFREE (concat_name); } else { #endif if (IS_DIR_SEPARATOR (wrapper[0])) { concat_name = xstrdup (wrapper); if (check_executable (concat_name)) return concat_name; XFREE (concat_name); } #if defined HAVE_DOS_BASED_FILE_SYSTEM } #endif for (p = wrapper; *p; p++) if (*p == '/') { has_slash = 1; break; } if (!has_slash) { /* no slashes; search PATH */ const char *path = getenv ("PATH"); if (path != NULL) { for (p = path; *p; p = p_next) { const char *q; size_t p_len; for (q = p; *q; q++) if (IS_PATH_SEPARATOR (*q)) break; p_len = (size_t) (q - p); p_next = (*q == '\0' ? q : q + 1); if (p_len == 0) { /* empty path: current directory */ if (getcwd (tmp, LT_PATHMAX) == NULL) lt_fatal (__FILE__, __LINE__, "getcwd failed: %s", nonnull (strerror (errno))); tmp_len = strlen (tmp); concat_name = XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1); memcpy (concat_name, tmp, tmp_len); concat_name[tmp_len] = '/'; strcpy (concat_name + tmp_len + 1, wrapper); } else { concat_name = XMALLOC (char, p_len + 1 + strlen (wrapper) + 1); memcpy (concat_name, p, p_len); concat_name[p_len] = '/'; strcpy (concat_name + p_len + 1, wrapper); } if (check_executable (concat_name)) return concat_name; XFREE (concat_name); } } /* not found in PATH; assume curdir */ } /* Relative path | not found in path: prepend cwd */ if (getcwd (tmp, LT_PATHMAX) == NULL) lt_fatal (__FILE__, __LINE__, "getcwd failed: %s", nonnull (strerror (errno))); tmp_len = strlen (tmp); concat_name = XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1); memcpy (concat_name, tmp, tmp_len); concat_name[tmp_len] = '/'; strcpy (concat_name + tmp_len + 1, wrapper); if (check_executable (concat_name)) return concat_name; XFREE (concat_name); return NULL; } char * chase_symlinks (const char *pathspec) { #ifndef S_ISLNK return xstrdup (pathspec); #else char buf[LT_PATHMAX]; struct stat s; char *tmp_pathspec = xstrdup (pathspec); char *p; int has_symlinks = 0; while (strlen (tmp_pathspec) && !has_symlinks) { lt_debugprintf (__FILE__, __LINE__, "checking path component for symlinks: %s\n", tmp_pathspec); if (lstat (tmp_pathspec, &s) == 0) { if (S_ISLNK (s.st_mode) != 0) { has_symlinks = 1; break; } /* search backwards for last DIR_SEPARATOR */ p = tmp_pathspec + strlen (tmp_pathspec) - 1; while ((p > tmp_pathspec) && (!IS_DIR_SEPARATOR (*p))) p--; if ((p == tmp_pathspec) && (!IS_DIR_SEPARATOR (*p))) { /* no more DIR_SEPARATORS left */ break; } *p = '\0'; } else { lt_fatal (__FILE__, __LINE__, "error accessing file \"%s\": %s", tmp_pathspec, nonnull (strerror (errno))); } } XFREE (tmp_pathspec); if (!has_symlinks) { return xstrdup (pathspec); } tmp_pathspec = realpath (pathspec, buf); if (tmp_pathspec == 0) { lt_fatal (__FILE__, __LINE__, "could not follow symlinks for %s", pathspec); } return xstrdup (tmp_pathspec); #endif } char * strendzap (char *str, const char *pat) { size_t len, patlen; assert (str != NULL); assert (pat != NULL); len = strlen (str); patlen = strlen (pat); if (patlen <= len) { str += len - patlen; if (STREQ (str, pat)) *str = '\0'; } return str; } void lt_debugprintf (const char *file, int line, const char *fmt, ...) { va_list args; if (lt_debug) { (void) fprintf (stderr, "%s:%s:%d: ", program_name, file, line); va_start (args, fmt); (void) vfprintf (stderr, fmt, args); va_end (args); } } static void lt_error_core (int exit_status, const char *file, int line, const char *mode, const char *message, va_list ap) { fprintf (stderr, "%s:%s:%d: %s: ", program_name, file, line, mode); vfprintf (stderr, message, ap); fprintf (stderr, ".\n"); if (exit_status >= 0) exit (exit_status); } void lt_fatal (const char *file, int line, const char *message, ...) { va_list ap; va_start (ap, message); lt_error_core (EXIT_FAILURE, file, line, "FATAL", message, ap); va_end (ap); } static const char * nonnull (const char *s) { return s ? s : "(null)"; } static const char * nonempty (const char *s) { return (s && !*s) ? "(empty)" : nonnull (s); } void lt_setenv (const char *name, const char *value) { lt_debugprintf (__FILE__, __LINE__, "(lt_setenv) setting '%s' to '%s'\n", nonnull (name), nonnull (value)); { #ifdef HAVE_SETENV /* always make a copy, for consistency with !HAVE_SETENV */ char *str = xstrdup (value); setenv (name, str, 1); #else size_t len = strlen (name) + 1 + strlen (value) + 1; char *str = XMALLOC (char, len); sprintf (str, "%s=%s", name, value); if (putenv (str) != EXIT_SUCCESS) { XFREE (str); } #endif } } char * lt_extend_str (const char *orig_value, const char *add, int to_end) { char *new_value; if (orig_value && *orig_value) { size_t orig_value_len = strlen (orig_value); size_t add_len = strlen (add); new_value = XMALLOC (char, add_len + orig_value_len + 1); if (to_end) { strcpy (new_value, orig_value); strcpy (new_value + orig_value_len, add); } else { strcpy (new_value, add); strcpy (new_value + add_len, orig_value); } } else { new_value = xstrdup (add); } return new_value; } void lt_update_exe_path (const char *name, const char *value) { lt_debugprintf (__FILE__, __LINE__, "(lt_update_exe_path) modifying '%s' by prepending '%s'\n", nonnull (name), nonnull (value)); if (name && *name && value && *value) { char *new_value = lt_extend_str (getenv (name), value, 0); /* some systems can't cope with a ':'-terminated path #' */ size_t len = strlen (new_value); while ((len > 0) && IS_PATH_SEPARATOR (new_value[len-1])) { new_value[--len] = '\0'; } lt_setenv (name, new_value); XFREE (new_value); } } void lt_update_lib_path (const char *name, const char *value) { lt_debugprintf (__FILE__, __LINE__, "(lt_update_lib_path) modifying '%s' by prepending '%s'\n", nonnull (name), nonnull (value)); if (name && *name && value && *value) { char *new_value = lt_extend_str (getenv (name), value, 0); lt_setenv (name, new_value); XFREE (new_value); } } EOF case $host_os in mingw* | windows*) cat <<"EOF" /* Prepares an argument vector before calling spawn(). Note that spawn() does not by itself call the command interpreter (getenv ("COMSPEC") != NULL ? getenv ("COMSPEC") : ({ OSVERSIONINFO v; v.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); GetVersionEx(&v); v.dwPlatformId == VER_PLATFORM_WIN32_NT; }) ? "cmd.exe" : "command.com"). Instead it simply concatenates the arguments, separated by ' ', and calls CreateProcess(). We must quote the arguments since Win32 CreateProcess() interprets characters like ' ', '\t', '\\', '"' (but not '<' and '>') in a special way: - Space and tab are interpreted as delimiters. They are not treated as delimiters if they are surrounded by double quotes: "...". - Unescaped double quotes are removed from the input. Their only effect is that within double quotes, space and tab are treated like normal characters. - Backslashes not followed by double quotes are not special. - But 2*n+1 backslashes followed by a double quote become n backslashes followed by a double quote (n >= 0): \" -> " \\\" -> \" \\\\\" -> \\" */ #define SHELL_SPECIAL_CHARS "\"\\ \001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037" #define SHELL_SPACE_CHARS " \001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037" char ** prepare_spawn (char **argv) { size_t argc; char **new_argv; size_t i; /* Count number of arguments. */ for (argc = 0; argv[argc] != NULL; argc++) ; /* Allocate new argument vector. */ new_argv = XMALLOC (char *, argc + 1); /* Put quoted arguments into the new argument vector. */ for (i = 0; i < argc; i++) { const char *string = argv[i]; if (string[0] == '\0') new_argv[i] = xstrdup ("\"\""); else if (strpbrk (string, SHELL_SPECIAL_CHARS) != NULL) { int quote_around = (strpbrk (string, SHELL_SPACE_CHARS) != NULL); size_t length; unsigned int backslashes; const char *s; char *quoted_string; char *p; length = 0; backslashes = 0; if (quote_around) length++; for (s = string; *s != '\0'; s++) { char c = *s; if (c == '"') length += backslashes + 1; length++; if (c == '\\') backslashes++; else backslashes = 0; } if (quote_around) length += backslashes + 1; quoted_string = XMALLOC (char, length + 1); p = quoted_string; backslashes = 0; if (quote_around) *p++ = '"'; for (s = string; *s != '\0'; s++) { char c = *s; if (c == '"') { unsigned int j; for (j = backslashes + 1; j > 0; j--) *p++ = '\\'; } *p++ = c; if (c == '\\') backslashes++; else backslashes = 0; } if (quote_around) { unsigned int j; for (j = backslashes; j > 0; j--) *p++ = '\\'; *p++ = '"'; } *p = '\0'; new_argv[i] = quoted_string; } else new_argv[i] = (char *) string; } new_argv[argc] = NULL; return new_argv; } EOF ;; esac cat <<"EOF" void lt_dump_script (FILE* f) { EOF func_emit_wrapper yes | $SED -n -e ' s/^\(.\{79\}\)\(..*\)/\1\ \2/ h s/\([\\"]\)/\\\1/g s/$/\\n/ s/\([^\n]*\).*/ fputs ("\1", f);/p g D' cat <<"EOF" } EOF } # end: func_emit_cwrapperexe_src # func_win32_import_lib_p ARG # True if ARG is an import lib, as indicated by $file_magic_cmd func_win32_import_lib_p () { $debug_cmd case `eval $file_magic_cmd \"\$1\" 2>/dev/null | $SED -e 10q` in *import*) : ;; *) false ;; esac } # func_suncc_cstd_abi # !!ONLY CALL THIS FOR SUN CC AFTER $compile_command IS FULLY EXPANDED!! # Several compiler flags select an ABI that is incompatible with the # Cstd library. Avoid specifying it if any are in CXXFLAGS. func_suncc_cstd_abi () { $debug_cmd case " $compile_command " in *" -compat=g "*|*\ -std=c++[0-9][0-9]\ *|*" -library=stdcxx4 "*|*" -library=stlport4 "*) suncc_use_cstd_abi=no ;; *) suncc_use_cstd_abi=yes ;; esac } # func_mode_link arg... func_mode_link () { $debug_cmd case $host in *-*-cygwin* | *-*-mingw* | *-*-windows* | *-*-pw32* | *-*-os2* | *-cegcc*) # It is impossible to link a dll without this setting, and # we shouldn't force the makefile maintainer to figure out # what system we are compiling for in order to pass an extra # flag for every libtool invocation. # allow_undefined=no # FIXME: Unfortunately, there are problems with the above when trying # to make a dll that has undefined symbols, in which case not # even a static library is built. For now, we need to specify # -no-undefined on the libtool link line when we can be certain # that all symbols are satisfied, otherwise we get a static library. allow_undefined=yes ;; *) allow_undefined=yes ;; esac libtool_args=$nonopt base_compile="$nonopt $@" compile_command=$nonopt finalize_command=$nonopt compile_rpath= compile_rpath_tail= finalize_rpath= compile_shlibpath= finalize_shlibpath= convenience= old_convenience= deplibs= old_deplibs= compiler_flags= linker_flags= dllsearchpath= lib_search_path=`pwd` inst_prefix_dir= new_inherited_linker_flags= avoid_version=no bindir= dlfiles= dlprefiles= dlself=no export_dynamic=no export_symbols= export_symbols_regex= generated= libobjs= ltlibs= module=no no_install=no objs= os2dllname= non_pic_objects= precious_files_regex= prefer_static_libs=no preload=false prev= prevarg= release= rpath= xrpath= perm_rpath= temp_rpath= temp_rpath_tail= thread_safe=no vinfo= vinfo_number=no weak_libs= rpath_arg= single_module=$wl-single_module func_infer_tag $base_compile # We need to know -static, to get the right output filenames. for arg do case $arg in -shared) test yes != "$build_libtool_libs" \ && func_fatal_configuration "cannot build a shared library" build_old_libs=no break ;; -all-static | -static | -static-libtool-libs) case $arg in -all-static) if test yes = "$build_libtool_libs" && test -z "$link_static_flag"; then func_warning "complete static linking is impossible in this configuration" fi if test -n "$link_static_flag"; then dlopen_self=$dlopen_self_static fi prefer_static_libs=yes ;; -static) if test -z "$pic_flag" && test -n "$link_static_flag"; then dlopen_self=$dlopen_self_static fi prefer_static_libs=built ;; -static-libtool-libs) if test -z "$pic_flag" && test -n "$link_static_flag"; then dlopen_self=$dlopen_self_static fi prefer_static_libs=yes ;; esac build_libtool_libs=no build_old_libs=yes break ;; esac done # See if our shared archives depend on static archives. test -n "$old_archive_from_new_cmds" && build_old_libs=yes # Go through the arguments, transforming them on the way. while test "$#" -gt 0; do arg=$1 shift func_quote_arg pretty,unquoted "$arg" qarg=$func_quote_arg_unquoted_result func_append libtool_args " $func_quote_arg_result" # If the previous option needs an argument, assign it. if test -n "$prev"; then case $prev in output) func_append compile_command " @OUTPUT@" func_append finalize_command " @OUTPUT@" ;; esac case $prev in bindir) bindir=$arg prev= continue ;; dlfiles|dlprefiles) $preload || { # Add the symbol object into the linking commands. func_append compile_command " @SYMFILE@" func_append finalize_command " @SYMFILE@" preload=: } case $arg in *.la | *.lo) ;; # We handle these cases below. force) if test no = "$dlself"; then dlself=needless export_dynamic=yes fi prev= continue ;; self) if test dlprefiles = "$prev"; then dlself=yes elif test dlfiles = "$prev" && test yes != "$dlopen_self"; then dlself=yes else dlself=needless export_dynamic=yes fi prev= continue ;; *) if test dlfiles = "$prev"; then func_append dlfiles " $arg" else func_append dlprefiles " $arg" fi prev= continue ;; esac ;; expsyms) export_symbols=$arg test -f "$arg" \ || func_fatal_error "symbol file '$arg' does not exist" prev= continue ;; expsyms_regex) export_symbols_regex=$arg prev= continue ;; framework) case $host in *-*-darwin*) case "$deplibs " in *" $qarg.ltframework "*) ;; *) func_append deplibs " $qarg.ltframework" # this is fixed later ;; esac ;; esac prev= continue ;; inst_prefix) inst_prefix_dir=$arg prev= continue ;; mllvm) # Clang does not use LLVM to link, so we can simply discard any # '-mllvm $arg' options when doing the link step. prev= continue ;; objectlist) if test -f "$arg"; then save_arg=$arg moreargs= for fil in `cat "$save_arg"` do # func_append moreargs " $fil" arg=$fil # A libtool-controlled object. # Check to see that this really is a libtool object. if func_lalib_unsafe_p "$arg"; then pic_object= non_pic_object= # Read the .lo file func_source "$arg" if test -z "$pic_object" || test -z "$non_pic_object" || test none = "$pic_object" && test none = "$non_pic_object"; then func_fatal_error "cannot find name of object for '$arg'" fi # Extract subdirectory from the argument. func_dirname "$arg" "/" "" xdir=$func_dirname_result if test none != "$pic_object"; then # Prepend the subdirectory the object is found in. pic_object=$xdir$pic_object if test dlfiles = "$prev"; then if test yes = "$build_libtool_libs" && test yes = "$dlopen_support"; then func_append dlfiles " $pic_object" prev= continue else # If libtool objects are unsupported, then we need to preload. prev=dlprefiles fi fi # CHECK ME: I think I busted this. -Ossama if test dlprefiles = "$prev"; then # Preload the old-style object. func_append dlprefiles " $pic_object" prev= fi # A PIC object. func_append libobjs " $pic_object" arg=$pic_object fi # Non-PIC object. if test none != "$non_pic_object"; then # Prepend the subdirectory the object is found in. non_pic_object=$xdir$non_pic_object # A standard non-PIC object func_append non_pic_objects " $non_pic_object" if test -z "$pic_object" || test none = "$pic_object"; then arg=$non_pic_object fi else # If the PIC object exists, use it instead. # $xdir was prepended to $pic_object above. non_pic_object=$pic_object func_append non_pic_objects " $non_pic_object" fi else # Only an error if not doing a dry-run. if $opt_dry_run; then # Extract subdirectory from the argument. func_dirname "$arg" "/" "" xdir=$func_dirname_result func_lo2o "$arg" pic_object=$xdir$objdir/$func_lo2o_result non_pic_object=$xdir$func_lo2o_result func_append libobjs " $pic_object" func_append non_pic_objects " $non_pic_object" else func_fatal_error "'$arg' is not a valid libtool object" fi fi done else func_fatal_error "link input file '$arg' does not exist" fi arg=$save_arg prev= continue ;; os2dllname) os2dllname=$arg prev= continue ;; precious_regex) precious_files_regex=$arg prev= continue ;; release) release=-$arg prev= continue ;; rpath | xrpath) # We need an absolute path. case $arg in [\\/]* | [A-Za-z]:[\\/]*) ;; *) func_fatal_error "argument to -rpath is not absolute: $arg" ;; esac if test rpath = "$prev"; then case "$rpath " in *" $arg "*) ;; *) func_append rpath " $arg" ;; esac else case "$xrpath " in *" $arg "*) ;; *) func_append xrpath " $arg" ;; esac fi prev= continue ;; shrext) shrext_cmds=$arg prev= continue ;; weak) func_append weak_libs " $arg" prev= continue ;; xassembler) func_append compiler_flags " -Xassembler $qarg" prev= func_append compile_command " -Xassembler $qarg" func_append finalize_command " -Xassembler $qarg" continue ;; xcclinker) func_append linker_flags " $qarg" func_append compiler_flags " $qarg" prev= func_append compile_command " $qarg" func_append finalize_command " $qarg" continue ;; xcompiler) func_append compiler_flags " $qarg" prev= func_append compile_command " $qarg" func_append finalize_command " $qarg" continue ;; xlinker) func_append linker_flags " $qarg" func_append compiler_flags " $wl$qarg" prev= func_append compile_command " $wl$qarg" func_append finalize_command " $wl$qarg" continue ;; *) eval "$prev=\"\$arg\"" prev= continue ;; esac fi # test -n "$prev" prevarg=$arg case $arg in -all-static) if test -n "$link_static_flag"; then # See comment for -static flag below, for more details. func_append compile_command " $link_static_flag" func_append finalize_command " $link_static_flag" fi continue ;; -allow-undefined) # FIXME: remove this flag sometime in the future. func_fatal_error "'-allow-undefined' must not be used because it is the default" ;; -avoid-version) avoid_version=yes continue ;; -bindir) prev=bindir continue ;; -dlopen) prev=dlfiles continue ;; -dlpreopen) prev=dlprefiles continue ;; -export-dynamic) export_dynamic=yes continue ;; -export-symbols | -export-symbols-regex) if test -n "$export_symbols" || test -n "$export_symbols_regex"; then func_fatal_error "more than one -exported-symbols argument is not allowed" fi if test X-export-symbols = "X$arg"; then prev=expsyms else prev=expsyms_regex fi continue ;; -framework) prev=framework continue ;; -inst-prefix-dir) prev=inst_prefix continue ;; # The native IRIX linker understands -LANG:*, -LIST:* and -LNO:* # so, if we see these flags be careful not to treat them like -L -L[A-Z][A-Z]*:*) case $with_gcc/$host in no/*-*-irix* | /*-*-irix*) func_append compile_command " $arg" func_append finalize_command " $arg" ;; esac continue ;; -L*) func_stripname "-L" '' "$arg" if test -z "$func_stripname_result"; then if test "$#" -gt 0; then func_fatal_error "require no space between '-L' and '$1'" else func_fatal_error "need path for '-L' option" fi fi func_resolve_sysroot "$func_stripname_result" dir=$func_resolve_sysroot_result # We need an absolute path. case $dir in [\\/]* | [A-Za-z]:[\\/]*) ;; *) absdir=`cd "$dir" && pwd` test -z "$absdir" && \ func_fatal_error "cannot determine absolute directory name of '$dir'" dir=$absdir ;; esac case "$deplibs " in *" -L$dir "* | *" $arg "*) # Will only happen for absolute or sysroot arguments ;; *) # Preserve sysroot, but never include relative directories case $dir in [\\/]* | [A-Za-z]:[\\/]* | =*) func_append deplibs " $arg" ;; *) func_append deplibs " -L$dir" ;; esac func_append lib_search_path " $dir" ;; esac case $host in *-*-cygwin* | *-*-mingw* | *-*-windows* | *-*-pw32* | *-*-os2* | *-cegcc*) testbindir=`$ECHO "$dir" | $SED 's*/lib$*/bin*'` case :$dllsearchpath: in *":$dir:"*) ;; ::) dllsearchpath=$dir;; *) func_append dllsearchpath ":$dir";; esac case :$dllsearchpath: in *":$testbindir:"*) ;; ::) dllsearchpath=$testbindir;; *) func_append dllsearchpath ":$testbindir";; esac ;; esac continue ;; -l*) if test X-lc = "X$arg" || test X-lm = "X$arg"; then case $host in *-*-cygwin* | *-*-mingw* | *-*-windows* | *-*-pw32* | *-*-beos* | *-cegcc* | *-*-haiku*) # These systems don't actually have a C or math library (as such) continue ;; *-*-os2*) # These systems don't actually have a C library (as such) test X-lc = "X$arg" && continue ;; *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-midnightbsd*) # Do not include libc due to us having libc/libc_r. test X-lc = "X$arg" && continue ;; *-*-rhapsody* | *-*-darwin1.[012]) # Rhapsody C and math libraries are in the System framework func_append deplibs " System.ltframework" continue ;; *-*-sco3.2v5* | *-*-sco5v6*) # Causes problems with __ctype test X-lc = "X$arg" && continue ;; *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*) # Compiler inserts libc in the correct place for threads to work test X-lc = "X$arg" && continue ;; esac elif test X-lc_r = "X$arg"; then case $host in *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-midnightbsd*) # Do not include libc_r directly, use -pthread flag. continue ;; esac fi func_append deplibs " $arg" continue ;; -mllvm) prev=mllvm continue ;; -module) module=yes continue ;; # Tru64 UNIX uses -model [arg] to determine the layout of C++ # classes, name mangling, and exception handling. # Darwin uses the -arch flag to determine output architecture. # -q