summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStef Walter <stef@thewalter.net>2004-04-03 22:13:01 +0000
committerStef Walter <stef@thewalter.net>2004-04-03 22:13:01 +0000
commitbec23685136f78a24a78a6d8840d3865ffbccea9 (patch)
tree1453e0c5f87bb689a3df9c8e524d05d65bcca657
parent3eca787a2b83ff8cf60d2be9e588d4a558b85a85 (diff)
Unix porting.
-rw-r--r--AUTHORS1
-rw-r--r--COPYING31
-rw-r--r--INSTALL8
-rw-r--r--Makefile.am7
-rw-r--r--NEWS1
-rw-r--r--README3
-rw-r--r--configure.in81
-rw-r--r--src/compat.c59
-rw-r--r--src/compat.h141
-rw-r--r--src/drive.h13
-rw-r--r--src/list.c11
-rw-r--r--src/main.c8
-rw-r--r--src/ntfs.h10
-rw-r--r--src/ntfsx.c4
-rw-r--r--src/posix.c16
-rw-r--r--src/scrounge.c22
-rw-r--r--src/scrounge.h2
-rw-r--r--src/unicode.c6
-rw-r--r--src/usuals.h8
19 files changed, 322 insertions, 110 deletions
diff --git a/AUTHORS b/AUTHORS
new file mode 100644
index 0000000..d2e76d6
--- /dev/null
+++ b/AUTHORS
@@ -0,0 +1 @@
+nielsen@memberwebs.com
diff --git a/COPYING b/COPYING
new file mode 100644
index 0000000..763af15
--- /dev/null
+++ b/COPYING
@@ -0,0 +1,31 @@
+
+Copyright (c) 2004, Nate Nielsen
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+
+ * Redistributions of source code must retain the above
+ copyright notice, this list of conditions and the
+ following disclaimer.
+ * 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.
+ * The names of contributors to this software may not be
+ used to endorse or promote products derived from this
+ software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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
+COPYRIGHT OWNER 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.
diff --git a/INSTALL b/INSTALL
new file mode 100644
index 0000000..075fdff
--- /dev/null
+++ b/INSTALL
@@ -0,0 +1,8 @@
+======================================================================
+ SCROUNGE-NTFS INSTALL
+
+QUICK INSTALLATION:
+ # tar -zxvf scrounge-0.8.1.tar.gz
+ # ./configure
+ # make && make install
+
diff --git a/Makefile.am b/Makefile.am
new file mode 100644
index 0000000..ff52d9c
--- /dev/null
+++ b/Makefile.am
@@ -0,0 +1,7 @@
+
+EXTRA_DIST = BUGS
+SUBDIRS = src win32
+
+dist-hook:
+ rm -rf `find $(distdir)/ -name CVS`
+
diff --git a/NEWS b/NEWS
new file mode 100644
index 0000000..c7ab92a
--- /dev/null
+++ b/NEWS
@@ -0,0 +1 @@
+See ChangeLog \ No newline at end of file
diff --git a/README b/README
new file mode 100644
index 0000000..c03ab5c
--- /dev/null
+++ b/README
@@ -0,0 +1,3 @@
+=================================================================
+ SCROUNGE-NTFS README
+
diff --git a/configure.in b/configure.in
new file mode 100644
index 0000000..2b5fac7
--- /dev/null
+++ b/configure.in
@@ -0,0 +1,81 @@
+dnl
+dnl Copyright (c) 2004, Nate Nielsen
+dnl All rights reserved.
+dnl
+dnl Redistribution and use in source and binary forms, with or without
+dnl modification, are permitted provided that the following conditions
+dnl are met:
+dnl
+dnl * Redistributions of source code must retain the above
+dnl copyright notice, this list of conditions and the
+dnl following disclaimer.
+dnl * Redistributions in binary form must reproduce the
+dnl above copyright notice, this list of conditions and
+dnl the following disclaimer in the documentation and/or
+dnl other materials provided with the distribution.
+dnl * The names of contributors to this software may not be
+dnl used to endorse or promote products derived from this
+dnl software without specific prior written permission.
+dnl
+dnl THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+dnl "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+dnl LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+dnl FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+dnl COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+dnl INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+dnl BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+dnl OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+dnl AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+dnl OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+dnl THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+dnl DAMAGE.
+dnl
+dnl
+dnl CONTRIBUTORS
+dnl Nate Nielsen <nielsen@memberwebs.com>
+dnl
+
+dnl Process this file with autoconf to produce a configure script.
+AC_INIT(scrounge-ntfs, 0.8.1, nielsen@memberwebs.com)
+AM_INIT_AUTOMAKE(scrounge-ntfs, 0.8.1)
+
+LDFLAGS="$LDFLAGS -L/usr/local/lib"
+CPPFLAGS="$CPPFLAGS -I/usr/local/include"
+CFLAGS="$CFLAGS -I/usr/local/include"
+
+AC_CONFIG_SRCDIR([src/scrounge.c])
+AM_CONFIG_HEADER([config.h])
+
+# Checks for programs.
+AC_PROG_CC
+AC_PROG_INSTALL
+AC_PROG_LN_S
+AC_PROG_MAKE_SET
+
+# Check for libraries
+
+# Checks for header files.
+AC_HEADER_STDC
+AC_CHECK_HEADERS([stdio.h stddef.h fcntl.h stdlib.h wchar.h assert.h errno.h stdint.h stdarg.h], ,
+ [echo "ERROR: Required C header missing"; exit 1])
+AC_CHECK_HEADERS([string.h io.h unistd.h err.h malloc.h sys/time.h stdint.h])
+
+
+# Checks for typedefs, structures, and compiler characteristics.
+AC_C_CONST
+AC_TYPE_SIZE_T
+AC_HEADER_TIME
+AC_CHECK_SIZEOF(off_t)
+AC_CHECK_TYPES([bool, uint, uint64, uint32, uint16, int64, int32, int16, byte, uint64_t, uint32_t, uint16_t, int64_t, int32_t, int16_t], , , [
+ #include <sys/types.h>
+ #include <stdint.h>
+])
+
+# Required Functions
+AC_CHECK_FUNCS([memset stat strchr strerror sprintf utimes chmod memcmp malloc realloc], ,
+ [echo "ERROR: Required function missing"; exit 1])
+AC_CHECK_FUNCS([getopt strchr strerror getcwd chdir getopt reallocf itow itoa])
+AC_CHECK_FUNCS([wopen wchdir wmkdir lseek64])
+
+AC_CONFIG_FILES([Makefile src/Makefile win32/Makefile])
+AC_OUTPUT
diff --git a/src/compat.c b/src/compat.c
index 14b85e4..171f551 100644
--- a/src/compat.c
+++ b/src/compat.c
@@ -87,7 +87,20 @@ int getopt(int nargc, char* const* nargv, const char* ostr)
return (-1);
}
- if (place[1] && *++place == '-') /* found "--" */
+ if (place[1] && *++place == '-') #include <sys/types.h>
+
+ void *malloc ();
+
+ /* Allocate an N-byte block of memory from the heap.
+ If N is zero, allocate a 1-byte block. */
+
+ void *
+ rpl_malloc (size_t n)
+ {
+ if (n == 0)
+ n = 1;
+ return malloc (n);
+ }/* found "--" */
{
++optind;
place = EMSG;
@@ -138,7 +151,20 @@ int getopt(int nargc, char* const* nargv, const char* ostr)
return (optopt); /* dump back option letter */
}
#endif
+ #include <sys/types.h>
+
+ void *malloc ();
+
+ /* Allocate an N-byte block of memory from the heap.
+ If N is zero, allocate a 1-byte block. */
+ void *
+ rpl_malloc (size_t n)
+ {
+ if (n == 0)
+ n = 1;
+ return malloc (n);
+ }
#ifndef HAVE_ERR_H
@@ -344,18 +370,18 @@ wchar_t* itow(int val, wchar_t* out, int radix)
#endif
#ifndef HAVE_ITOA
-wchar_t* itow(int val, wchar_t* out, int radix)
+char* itoa(int val, char* out, int radix)
{
int mod;
- wchar_t temp;
- wchar_t* end = out;
- wchar_t* beg = out;
+ char temp;
+ char* end = out;
+ char* beg = out;
if(val != 0)
{
/* If negative and decimal*/
if(radix == 10 && val < 0)
- *beg++ = L'-';
+ *beg++ = '-';
/* Convert in reverse order */
while(val != 0)
@@ -363,7 +389,7 @@ wchar_t* itow(int val, wchar_t* out, int radix)
mod = val % radix;
val = val / radix;
- *end++ = (mod < 10) ? L'0' + mod : L'a' + mod - 10;
+ *end++ = (mod < 10) ? '0' + mod : 'a' + mod - 10;
}
*end-- = 0;
@@ -380,10 +406,25 @@ wchar_t* itow(int val, wchar_t* out, int radix)
}
else
{
- beg[0] = L'0';
+ beg[0] = '0';
beg[1] = 0;
}
return out;
}
-#endif \ No newline at end of file
+#endif
+
+#if HAVE_MALLOC == 0
+#undef malloc
+
+/* Allocate an N-byte block of memory from the heap.
+ If N is zero, allocate a 1-byte block. */
+
+void* rpl_malloc (size_t n)
+{
+ if (n == 0)
+ n = 1;
+ return malloc (n);
+}
+
+#endif
diff --git a/src/compat.h b/src/compat.h
index 8f75ef2..0047991 100644
--- a/src/compat.h
+++ b/src/compat.h
@@ -29,6 +29,8 @@
#endif
#endif
+#include <sys/types.h>
+
#ifndef MAX_PATH
#ifdef _MAX_PATH
#define MAX_PATH _MAX_PATH
@@ -75,106 +77,82 @@ typedef unsigned char bool;
#ifndef HAVE_BYTE
typedef unsigned char byte;
-#define HAVE_BYTE
#endif
#ifndef HAVE_UINT
typedef unsigned int uint;
-#define HAVE_UINT
#endif
+#include <stdint.h>
+
#ifndef HAVE_UINT64
- #ifdef _WIN32
- typedef unsigned __int64 uint64;
+ #ifdef HAVE_UINT64_T
+ typedef uint64_t uint64;
#else
- #ifdef HAVE_64BITLONGLONG
- typedef unsigned long long uint64;
+ #ifdef _WIN32
+ typedef unsigned __int64 uint64;
#else
- #ifdef HAVE_64BITLONG
- typedef unsigned long uint64;
- #else
- #error ERROR: Must have a compiler that can handle 64 bit integers
- #endif
+ #error ERROR: Must have a compiler that can handle 64 bit integers
#endif
#endif
#endif
-#ifndef HAVE_UINT32
- #ifdef _WIN32
- typedef unsigned __int32 uint32;
+#ifndef HAVE_INT64
+ #ifdef HAVE_INT64_T
+ typedef int64_t int64;
#else
- #ifdef HAVE_32BITLONG
- typedef unsigned long uint32;
+ #ifdef _WIN32
+ typedef signed __int64 int64;
#else
- #ifdef HAVE_32BITINT
- typedef unsigned int uint32;
- #else
- #error ERROR: Couldn't find a 32 bit integer to use
- #endif
+ #error ERROR: Must have a compiler that can handle 64 bit integers
#endif
#endif
#endif
-#ifndef HAVE_UINT16
- #ifdef _WIN32
- typedef unsigned __int16 uint16;
+#ifndef HAVE_UINT32
+ #ifdef HAVE_UINT32_T
+ typedef uint32_t uint32;
#else
- #ifdef HAVE_16BITSHORT
- typedef unsigned short uint16;
+ #ifdef _WIN32
+ typedef unsigned __int32 uint32;
#else
- #ifdef HAVE_16BITINT
- typedef unsigned int uint16;
- #else
- #error ERROR: Couldn't find a 16 bit integer to use
- #endif
+ #error ERROR: Couldnt determine a 32 bit integer
#endif
#endif
#endif
-#ifndef HAVE_INT64
- #ifdef _WIN32
- typedef signed __int64 int64;
+#ifndef HAVE_INT32
+ #ifdef HAVE_INT32_T
+ typedef int32_t int32;
#else
- #ifdef HAVE_64BITLONGLONG
- typedef signed long long int64;
+ #ifdef _WIN32
+ typedef signed __int32 int32;
#else
- #ifdef HAVE_64BITLONG
- typedef signed long int64;
- #else
- #error ERROR: Must have a compiler that can handle 64 bit integers
- #endif
+ #error ERROR: Couldnt determine a 32 bit integer
#endif
#endif
#endif
-#ifndef HAVE_INT32
- #ifdef _WIN32
- typedef signed __int32 int32;
+#ifndef HAVE_UINT16
+ #ifdef HAVE_UINT16_T
+ typedef uint16_t uint16;
#else
- #ifdef HAVE_32BITLONG
- typedef signed long int32;
+ #ifdef _WIN32
+ typedef unsigned __int16 uint16;
#else
- #ifdef HAVE_32BITINT
- typedef signed int int32;
- #else
- #error ERROR: Couldn't find a 32 bit integer to use
- #endif
+ #error ERROR: Couldnt determine a 16 bit integer
#endif
#endif
#endif
#ifndef HAVE_INT16
- #ifdef _WIN32
- typedef signed __int16 int16;
+ #ifdef HAVE_INT16_T
+ typedef int16_t int16;
#else
- #ifdef HAVE_16BITSHORT
- typedef signed short int16;
+ #ifdef _WIN32
+ typedef signed __int16 int16;
#else
- #ifdef HAVE_16BITINT
- typedef signed int int16;
- #else
- #error ERROR: Couldn't find a 16 bit integer to use
- #endif
+ #error ERROR: Couldnt determine a 16 bit integer
#endif
#endif
#endif
@@ -196,7 +174,20 @@ void err_set_file(void *fp);
void err_set_exit(void (*ef)(int));
void err(int eval, const char *fmt, ...);
void verr(int eval, const char *fmt, va_list ap);
-void errc(int eval, int code, const char *fmt, ...);
+void errc(int eval, int c #include <sys/types.h>
+
+ void *malloc ();
+
+ /* Allocate an N-byte block of memory from the heap.
+ If N is zero, allocate a 1-byte block. */
+
+ void *
+ rpl_malloc (size_t n)
+ {
+ if (n == 0)
+ n = 1;
+ return malloc (n);
+ }ode, const char *fmt, ...);
void verrc(int eval, int code, const char *fmt, va_list ap);
void errx(int eval, const char *fmt, ...);
void verrx(int eval, const char *fmt, va_list ap);
@@ -213,13 +204,14 @@ void* reallocf(void* ptr, size_t size);
#endif
/* Some number conversion stuff */
+#include <wchar.h>
#ifndef HAVE_ITOW
#ifdef _WIN32
#define itow _itow
#define HAVE_ITOW 1
#else
- wchar_t itow(int v, wchar_t* s, int r);
+ wchar_t* itow(int v, wchar_t* s, int r);
#endif
#endif
@@ -228,7 +220,7 @@ void* reallocf(void* ptr, size_t size);
#define itoa _itoa
#define HAVE_ITOA 1
#else
- char itoa(int v, char* s, int r);
+ char* itoa(int v, char* s, int r);
#endif
#endif
@@ -316,6 +308,7 @@ void* reallocf(void* ptr, size_t size);
#define fc_getcwd getcwd
#define fcscpy strcpy
+ #define fcsncpy strncpy
#define fcscat strcat
#define fcslen strlen
#define fcscmp strcmp
@@ -333,7 +326,7 @@ void* reallocf(void* ptr, size_t size);
#ifdef _WIN32
#define lseek64 _lseeki64
#else
- #ifdef HAVE_64BITOFFT
+ #if ( SIZEOF_OFF_T == 8 )
#define lseek64 lseek
#else
#error ERROR: Must have a working 64 bit seek function
@@ -341,10 +334,28 @@ void* reallocf(void* ptr, size_t size);
#endif
#endif
-#include <fnctl.h>
+#include <fcntl.h>
#ifdef O_LARGEFILE
#define OPEN_LARGE_OPTS O_LARGEFILE
#else
#define OPEN_LARGE_OPTS 0
#endif
+#ifndef O_BINARY
+ #ifdef _O_BINARY
+ #define O_BINARY _O_BINARY
+ #else
+ #define O_BINARY 0
+ #endif
+#endif
+
+#ifndef O_RDONLY
+ #ifdef _O_RDONLY
+ #define O_RDONLY _O_RDONLY
+ #else
+ #error ERROR: No O_RDONLY flag found
+ #endif
+#endif
+
+
+#endif /* _COMPAT_H_ */
diff --git a/src/drive.h b/src/drive.h
index 22e7d2d..fdfc0eb 100644
--- a/src/drive.h
+++ b/src/drive.h
@@ -23,10 +23,10 @@
#include "usuals.h"
#define kSectorSize 0x200
-#define kInvalidSector 0xFFFFFFFFFFFFFFFF
+#define kInvalidSector 0xFFFFFFFFFFFFFFFFLL
-typedef struct _ntfsx_mftmap ntfsx_mftmap;
-typedef struct _drivelocks drivelocks;
+struct _ntfsx_mftmap;
+struct _drivelocks;
typedef struct _partitioninfo
{
@@ -37,12 +37,11 @@ typedef struct _partitioninfo
int device; /* A handle to an open device */
/* Some other context stuff about the drive */
- drivelocks* locks;
- ntfsx_mftmap* mftmap;
+ struct _drivelocks* locks;
+ struct _ntfsx_mftmap* mftmap;
}
partitioninfo;
-#pragma pack(push, drive)
#pragma pack(1)
#define kPartition_Invalid 0
@@ -77,7 +76,7 @@ typedef struct _drive_mbr
}
drive_mbr;
-#pragma pack(pop, drive)
+#pragma pack()
#define CLUSTER_TO_SECTOR(info, clus) (((clus) * (info).cluster) + (info).first)
#define SECTOR_TO_BYTES(sec) ((sec) * kSectorSize)
diff --git a/src/list.c b/src/list.c
index 97ac912..fc30ac0 100644
--- a/src/list.c
+++ b/src/list.c
@@ -99,7 +99,7 @@ int printPartitionInfo(int dd, uint64 tblSector)
return 0;
}
-
+#ifdef _WIN32
void scroungeList()
{
char driveName[MAX_PATH];
@@ -113,7 +113,7 @@ void scroungeList()
{
makeDriveName(driveName, i);
- dd = open(driveName, _O_BINARY | _O_RDONLY | OPEN_LARGE_OPTS);
+ dd = open(driveName, O_BINARY | O_RDONLY | OPEN_LARGE_OPTS);
if(dd != -1)
{
printf(kPrintDrive, i);
@@ -122,14 +122,15 @@ void scroungeList()
}
}
}
+#endif
void scroungeListDrive(char* drive)
{
- int dd = open(driveName, _O_BINARY | _O_RDONLY | OPEN_LARGE_OPTS;
+ int dd = open(drive, O_BINARY | O_RDONLY | OPEN_LARGE_OPTS);
if(dd == -1)
- err(1, "couldn't open drive: %s", driveName);
+ err(1, "couldn't open drive: %s", drive);
- printf(kPrintDrivePath, driveName);
+ printf(kPrintDrivePath, drive);
printPartitionInfo(dd, 0);
close(dd);
}
diff --git a/src/main.c b/src/main.c
index b6156d0..9f6e4a2 100644
--- a/src/main.c
+++ b/src/main.c
@@ -77,7 +77,7 @@ int main(int argc, char* argv[])
int mode = 0;
int raw = 0;
partitioninfo pi;
- char driveName[MAX_PATH];
+ char driveName[MAX_PATH + 1];
#ifdef _WIN32
int drive = 0;
#endif
@@ -191,7 +191,9 @@ int main(int argc, char* argv[])
if(argc < 1)
errx(2, "must specify drive name");
- driveName = argv[0];
+ strncpy(driveName, argv[0], MAX_PATH);
+ driveName[MAX_PATH] = 0;
+
argv++;
argc--;
#endif
@@ -220,7 +222,7 @@ int main(int argc, char* argv[])
pi.end = temp;
/* Open the device */
- pi.device = open(driveName, _O_BINARY | _O_RDONLY | OPEN_LARGE_OPTS);
+ pi.device = open(driveName, O_BINARY | O_RDONLY | OPEN_LARGE_OPTS);
if(pi.device == -1)
err(1, "couldn't open drive: %s", driveName);
diff --git a/src/ntfs.h b/src/ntfs.h
index e5eb1ec..06ca6bb 100644
--- a/src/ntfs.h
+++ b/src/ntfs.h
@@ -24,10 +24,8 @@
#include "stddef.h"
#include "drive.h"
-#pragma pack(push, ntfs)
#pragma pack(1)
-
/* WARNING Assumptions: */
#define kNTFS_RecordLen 0x0400
@@ -149,7 +147,11 @@ ntfs_attribnonresident;
#define kNTFS_NameSpaceDOS 0x02
#define kNTFS_NameSpaceWINDOS 0x03
+#ifdef FC_WIDE
#define kNTFS_MFTName L"$MFT"
+#else
+#define kNTFS_MFTName "$MFT"
+#endif
typedef struct _ntfs_attribfilename
{
@@ -181,7 +183,7 @@ typedef struct _ntfs_attriblistrecord
}
ntfs_attriblistrecord;
-#pragma pack(pop, ntfs)
+#pragma pack()
ntfs_attribheader* ntfs_findattribute(ntfs_recordheader* record, uint32 attrType, byte* end);
ntfs_attribheader* ntfs_nextattribute(ntfs_attribheader* attrib, uint32 attrType, byte* end);
@@ -193,6 +195,6 @@ bool ntfs_dofixups(byte* cluster, uint32 size);
/* TODO: Move these declarations elsewhere */
char* unicode_transcode16to8(const wchar_t* src, size_t len);
-wchar_t* unicode_transcode8to16(const char* src, const wchar_t* out, size_t len);
+wchar_t* unicode_transcode8to16(const char* src, wchar_t* out, size_t len);
#endif /* __NTFS_H__ */
diff --git a/src/ntfsx.c b/src/ntfsx.c
index 5d9a526..35f1c23 100644
--- a/src/ntfsx.c
+++ b/src/ntfsx.c
@@ -144,7 +144,7 @@ bool ntfsx_cluster_read(ntfsx_cluster* clus, partitioninfo* info, uint64 begSect
}
pos = SECTOR_TO_BYTES(begSector);
- if(_lseeki64(dd, pos, SEEK_SET) == -1)
+ if(lseek64(dd, pos, SEEK_SET) == -1)
return false;
sz = read(dd, clus->data, clus->size);
@@ -316,7 +316,7 @@ ntfsx_attribute* ntfsx_record_findattribute(ntfsx_record* record, uint32 attrTyp
if(atlr->type == attrType)
{
/* Read in appropriate cluster */
- mftRecord = ntfsx_mftmap_sectorforindex(record->info->mftmap, atlr->refAttrib & 0xFFFFFFFFFFFF);
+ mftRecord = ntfsx_mftmap_sectorforindex(record->info->mftmap, atlr->refAttrib & 0xFFFFFFFFFFFFLL);
r2 = ntfsx_record_alloc(record->info);
if(!r2)
diff --git a/src/posix.c b/src/posix.c
index 0586715..91bb43a 100644
--- a/src/posix.c
+++ b/src/posix.c
@@ -21,6 +21,20 @@
#include "usuals.h"
#include "ntfs.h"
+#include <sys/stat.h>
+#include <unistd.h>
+
+#if TIME_WITH_SYS_TIME
+# include <sys/time.h>
+# include <time.h>
+#else
+# if HAVE_SYS_TIME_H
+# include <sys/time.h>
+# else
+# include <time.h>
+# endif
+#endif
+
/* NOTE: This file assumes that FC_WIDE is off */
/* The NTFS file time is a a 64-bit value representing the
@@ -80,7 +94,7 @@ void setFileAttributes(fchar_t* filename, uint32 flags)
}
else
{
- if(chmod(filename, st.st_mode & ~(S_IWUSR | S_IWGRP | S_IOTH)) == -1)
+ if(chmod(filename, st.st_mode & ~(S_IWUSR | S_IWGRP | S_IWOTH)) == -1)
warn("couldn't set file attributes for: " FC_PRINTF, encoded);
}
}
diff --git a/src/scrounge.c b/src/scrounge.c
index 8baf688..4b4851c 100644
--- a/src/scrounge.c
+++ b/src/scrounge.c
@@ -90,7 +90,7 @@ void processRecordFileBasics(partitioninfo* pi, ntfsx_record* record, filebasics
#ifdef FC_WIDE
wcsncpy(basics->filename, name, len);
#else
- temp = unicode_transcode16to8(basics->filename, len);
+ temp = unicode_transcode16to8(name, len);
if(!temp)
errx(1, "out of memory");
@@ -109,7 +109,7 @@ void processRecordFileBasics(partitioninfo* pi, ntfsx_record* record, filebasics
/* Parent Directory */
- basics->parent = filename->refParent & 0xFFFFFFFFFFFF;
+ basics->parent = filename->refParent & 0xFFFFFFFFFFFFLL;
/* Namespace */
@@ -196,16 +196,16 @@ void processMFTRecord(partitioninfo* pi, uint64 sector, int level)
if(header->flags & kNTFS_RecFlagDir)
{
/* Try to change to the directory */
- if(wchdir(basics.filename) == -1)
+ if(fc_chdir(basics.filename) == -1)
{
- if(wmkdir(basics.filename) == -1)
+ if(fc_mkdir(basics.filename) == -1)
{
warnx("couldn't create directory '" FC_PRINTF "' putting files in parent directory", basics.filename);
}
else
{
setFileAttributes(basics.filename, basics.flags);
- wchdir(basics.filename);
+ fc_chdir(basics.filename);
}
}
@@ -214,7 +214,7 @@ void processMFTRecord(partitioninfo* pi, uint64 sector, int level)
/* Normal file handling: */
- outfile = wopen(basics.filename, _O_BINARY | _O_CREAT | _O_EXCL | _O_WRONLY);
+ outfile = fc_open(basics.filename, O_BINARY | O_CREAT | O_EXCL | O_WRONLY);
fcsncpy(filename2, basics.filename, MAX_PATH);
filename2[MAX_PATH] = 0;
@@ -228,12 +228,12 @@ void processMFTRecord(partitioninfo* pi, uint64 sector, int level)
}
fcscpy(basics.filename, filename2);
- fcscat(basics.filename, L".");
+ fcscat(basics.filename, FC_DOT);
itofc(rename, basics.filename + fcslen(basics.filename), 10);
rename++;
- outfile = fc_open(basics.filename, _O_BINARY | _O_CREAT | _O_EXCL | _O_WRONLY);
+ outfile = fc_open(basics.filename, O_BINARY | O_CREAT | O_EXCL | O_WRONLY);
}
if(outfile == -1)
@@ -462,7 +462,7 @@ void scroungeUsingMFT(partitioninfo* pi)
void scroungeUsingRaw(partitioninfo* pi)
{
byte buffSec[kSectorSize];
- fchar_t dir[_MAX_PATH + 1];
+ fchar_t dir[MAX_PATH + 1];
uint64 sec;
drivelocks locks;
int64 pos;
@@ -472,7 +472,7 @@ void scroungeUsingRaw(partitioninfo* pi)
fprintf(stderr, "[Scrounging raw records...]\n");
/* Save current directory away */
- fc_getcwd(dir, _MAX_PATH);
+ fc_getcwd(dir, MAX_PATH);
/* Get the locks ready */
memset(&locks, 0, sizeof(locks));
@@ -486,7 +486,7 @@ void scroungeUsingRaw(partitioninfo* pi)
/* Read the record */
pos = SECTOR_TO_BYTES(sec);
- if(_lseeki64(pi->device, pos, SEEK_SET) == -1)
+ if(lseek64(pi->device, pos, SEEK_SET) == -1)
errx(1, "can't seek device to sector");
sz = read(pi->device, buffSec, kSectorSize);
diff --git a/src/scrounge.h b/src/scrounge.h
index b1425fd..6ebed43 100644
--- a/src/scrounge.h
+++ b/src/scrounge.h
@@ -23,7 +23,9 @@
#include "drive.h"
void scroungeSearch(partitioninfo* pi);
+#ifdef _WIN32
void scroungeList();
+#endif
void scroungeListDrive(char* drive);
void scroungeUsingMFT(partitioninfo* pi);
void scroungeUsingRaw(partitioninfo* pi);
diff --git a/src/unicode.c b/src/unicode.c
index ea64574..f6197b6 100644
--- a/src/unicode.c
+++ b/src/unicode.c
@@ -57,7 +57,7 @@ char* unicode_transcode16to8(const wchar_t* src, size_t len)
}
}
- ret[pos] = NULL;
+ ret[pos] = 0;
return ret;
}
@@ -67,7 +67,7 @@ char* unicode_transcode16to8(const wchar_t* src, size_t len)
* Since a semi predictable length of the resulting data is
* known, the caller should allocate the memory for this conversion.
*/
-wchar_t* unicode_transcode8to16(const char* src, const wchar_t* out, size_t len)
+wchar_t* unicode_transcode8to16(const char* src, wchar_t* out, size_t len)
{
/* Note: out should always be at least as long as src in chars */
@@ -133,7 +133,7 @@ wchar_t* unicode_transcode8to16(const char* src, const wchar_t* out, size_t len)
}
}
- out[pos] = NULL;
+ out[pos] = 0;
return out;
}
diff --git a/src/usuals.h b/src/usuals.h
index 699adb3..038e8f9 100644
--- a/src/usuals.h
+++ b/src/usuals.h
@@ -64,4 +64,12 @@
#define INTERSECTS(b1, e1, b2, e2) \
((b1) < (e2) && (e1) > (b2))
+#ifndef max
+#define max(a,b) (((a) > (b)) ? (a) : (b))
+#endif
+
+#ifndef min
+#define min(a,b) (((a) < (b)) ? (a) : (b))
+#endif
+
#endif /* __USUALS_H__ */