diff --git a/src/add-ons/kernel/file_systems/ntfs/libntfs/Jamfile b/src/add-ons/kernel/file_systems/ntfs/libntfs/Jamfile index 9a4949ab8e..0fd6b1b3ad 100644 --- a/src/add-ons/kernel/file_systems/ntfs/libntfs/Jamfile +++ b/src/add-ons/kernel/file_systems/ntfs/libntfs/Jamfile @@ -1,6 +1,8 @@ SubDir HAIKU_TOP src add-ons kernel file_systems ntfs libntfs ; -SubDirCcFlags -Wall -Wno-multichar -DHAVE_CONFIG_H=1 -D_BEOS_=1 ; +SetSubDirSupportedPlatformsBeOSCompatible ; + +SubDirCcFlags -Wall -Wno-multichar -DHAVE_CONFIG_H=1 ; StaticLibrary libntfs.a : attrib.c diff --git a/src/add-ons/kernel/file_systems/ntfs/libntfs/attrib.c b/src/add-ons/kernel/file_systems/ntfs/libntfs/attrib.c index f870e6cb90..acec8434d3 100644 --- a/src/add-ons/kernel/file_systems/ntfs/libntfs/attrib.c +++ b/src/add-ons/kernel/file_systems/ntfs/libntfs/attrib.c @@ -4180,8 +4180,9 @@ retry: 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); + 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); diff --git a/src/add-ons/kernel/file_systems/ntfs/libntfs/bootsect.c b/src/add-ons/kernel/file_systems/ntfs/libntfs/bootsect.c index 378d70270f..f13a11cdfd 100644 --- a/src/add-ons/kernel/file_systems/ntfs/libntfs/bootsect.c +++ b/src/add-ons/kernel/file_systems/ntfs/libntfs/bootsect.c @@ -64,25 +64,6 @@ BOOL ntfs_boot_sector_is_ntfs(NTFS_BOOT_SECTOR *b) ntfs_log_debug("Beginning bootsector check.\n"); - /* Calculate the checksum. Note, this is just a simple addition of - all u32 values in the bootsector starting at the beginning and - finishing at the offset of the checksum itself (i.e. not including - the checksum...). */ - if ((void*)b < (void*)&b->checksum) { - u32 *u = (u32 *)b; - u32 *bi = (u32 *)(&b->checksum); - - ntfs_log_debug("Calculating bootsector checksum.\n"); - - for (i = 0; u < bi; ++u) - i += le32_to_cpup(u); - - if (le32_to_cpu(b->checksum) && le32_to_cpu(b->checksum) != i) { - ntfs_log_error("Bootsector checksum failed.\n"); - goto not_ntfs; - } - } - ntfs_log_debug("Checking OEMid, NTFS signature.\n"); if (b->oem_id != cpu_to_le64(0x202020205346544eULL)) { /* "NTFS " */ ntfs_log_error("NTFS signature is missing.\n"); @@ -215,7 +196,8 @@ int ntfs_boot_sector_parse(ntfs_volume *vol, const NTFS_BOOT_SECTOR *bs) 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)", sectors); + ntfs_log_perror("Failed to read last sector (%lld)", + (long long)sectors); ntfs_log_error("Perhaps the volume is a RAID/LDM but it wasn't " "setup yet, or the\nwrong device was used, " "or the partition table is incorrect.\n" ); @@ -232,7 +214,8 @@ int ntfs_boot_sector_parse(ntfs_volume *vol, const NTFS_BOOT_SECTOR *bs) 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", - vol->mft_lcn, vol->mftmirr_lcn, vol->nr_clusters); + (long long)vol->mft_lcn, (long long)vol->mftmirr_lcn, + (long long)vol->nr_clusters); return -1; } diff --git a/src/add-ons/kernel/file_systems/ntfs/libntfs/compat.c b/src/add-ons/kernel/file_systems/ntfs/libntfs/compat.c index a74d9e7b5d..1c31623e02 100644 --- a/src/add-ons/kernel/file_systems/ntfs/libntfs/compat.c +++ b/src/add-ons/kernel/file_systems/ntfs/libntfs/compat.c @@ -20,7 +20,7 @@ * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -//#ifdef WINDOWS +#if defined(WINDOWS) || defined(__BEOS__) || defined (__HAIKU__) #ifdef HAVE_CONFIG_H #include "config.h" @@ -69,5 +69,5 @@ int ffs(int x) } #endif /* HAVE_FFS */ -//#endif /* WINDOWS */ +#endif /* defined(WINDOWS) || defined(__BEOS__) || defined (__HAIKU__) */ diff --git a/src/add-ons/kernel/file_systems/ntfs/libntfs/device.c b/src/add-ons/kernel/file_systems/ntfs/libntfs/device.c index e11708251d..cf4969c385 100644 --- a/src/add-ons/kernel/file_systems/ntfs/libntfs/device.c +++ b/src/add-ons/kernel/file_systems/ntfs/libntfs/device.c @@ -409,7 +409,8 @@ s64 ntfs_cluster_read(const ntfs_volume *vol, const s64 lcn, const s64 count, if (vol->nr_clusters < lcn + count) { errno = ESPIPE; ntfs_log_perror("Trying to read outside of volume " - "(%lld < %lld)", vol->nr_clusters, lcn + count); + "(%lld < %lld)", (long long)vol->nr_clusters, + (long long)lcn + count); return -1; } br = ntfs_pread(vol->dev, lcn << vol->cluster_size_bits, @@ -444,7 +445,8 @@ s64 ntfs_cluster_write(const ntfs_volume *vol, const s64 lcn, if (vol->nr_clusters < lcn + count) { errno = ESPIPE; ntfs_log_perror("Trying to write outside of volume " - "(%lld < %lld)", vol->nr_clusters, lcn + count); + "(%lld < %lld)", (long long)vol->nr_clusters, + (long long)lcn + count); return -1; } if (!NVolReadOnly(vol)) diff --git a/src/add-ons/kernel/file_systems/ntfs/libntfs/dir.c b/src/add-ons/kernel/file_systems/ntfs/libntfs/dir.c index 3036370f1b..118165834b 100644 --- a/src/add-ons/kernel/file_systems/ntfs/libntfs/dir.c +++ b/src/add-ons/kernel/file_systems/ntfs/libntfs/dir.c @@ -259,7 +259,8 @@ descend_into_child_node: if (br != 1) { if (br != -1) errno = EIO; - ntfs_log_perror("Failed to read vcn 0x%llx", vcn); + ntfs_log_perror("Failed to read vcn 0x%llx", + (unsigned long long)vcn); goto close_err_out; } @@ -1047,10 +1048,7 @@ static ntfs_inode *__ntfs_create(ntfs_inode *dir_ni, /* Allocate MFT record for new file. */ ni = ntfs_mft_record_alloc(dir_ni->vol, NULL); if (!ni) { - err = errno; - ntfs_log_error("Could not allocate new MFT record: %s.\n", - strerror(err)); - errno = err; + ntfs_log_perror("Could not allocate new MFT record"); return NULL; } /* @@ -1158,12 +1156,10 @@ static ntfs_inode *__ntfs_create(ntfs_inode *dir_ni, memcpy(data->target, target, target_len * sizeof(ntfschar)); break; -#ifndef _BEOS_ case S_IFSOCK: data = NULL; data_len = 1; break; -#endif default: /* FIFO or regular file. */ data = NULL; data_len = 0; @@ -1258,7 +1254,8 @@ err_out: ntfs_inode *ntfs_create(ntfs_inode *dir_ni, ntfschar *name, u8 name_len, dev_t type) { - if (type != S_IFREG && type != S_IFDIR && type != S_IFIFO /*&& type != S_IFSOCK*/) { + if (type != S_IFREG && type != S_IFDIR && type != S_IFIFO && + type != S_IFSOCK) { ntfs_log_error("Invalid arguments.\n"); return NULL; } @@ -1302,7 +1299,7 @@ int ntfs_check_empty_dir(ntfs_inode *ni) } /* Non-empty directory? */ - if ((na->data_size != sizeof(INDEX_ROOT) + sizeof(INDEX_ENTRY_HEADER))){ + if ((na->data_size != sizeof(INDEX_ROOT) + sizeof(INDEX_ENTRY_HEADER))) { /* Both ENOTEMPTY and EEXIST are ok. We use the more common. */ errno = EEXIST; ntfs_log_debug("Directory is not empty\n"); @@ -1419,7 +1416,7 @@ search: if (ntfs_names_are_equal(fn->file_name, fn->file_name_length, name, name_len, case_sensitive, - ni->vol->upcase, ni->vol->upcase_len)){ + ni->vol->upcase, ni->vol->upcase_len)) { if (fn->file_name_type == FILE_NAME_WIN32) { looking_for_dos_name = TRUE; @@ -1532,7 +1529,7 @@ out: ntfs_inode_close(ni); if (err) { errno = err; - ntfs_log_perror("Could not delete file"); + ntfs_log_debug("Could not delete file: %s\n", strerror(errno)); return -1; } ntfs_log_trace("Done.\n"); diff --git a/src/add-ons/kernel/file_systems/ntfs/libntfs/dir.h b/src/add-ons/kernel/file_systems/ntfs/libntfs/dir.h index 33e1b2e17f..eac72def54 100644 --- a/src/add-ons/kernel/file_systems/ntfs/libntfs/dir.h +++ b/src/add-ons/kernel/file_systems/ntfs/libntfs/dir.h @@ -32,6 +32,14 @@ #define MAX_PATH 1024 #endif +/* + * We do not have S_IFSOCK under BeOS/Haiku + */ +#if defined(__BEOS__) || defined(__HAIKU__) +#ifndef S_IFSOCK +#define S_IFSOCK 0140000 +#endif +#endif /* * We do not have these under DJGPP, so define our version that do not conflict * with other S_IFs defined under DJGPP. diff --git a/src/add-ons/kernel/file_systems/ntfs/libntfs/endians.h b/src/add-ons/kernel/file_systems/ntfs/libntfs/endians.h index ec73c4428d..48c11ff4b8 100644 --- a/src/add-ons/kernel/file_systems/ntfs/libntfs/endians.h +++ b/src/add-ons/kernel/file_systems/ntfs/libntfs/endians.h @@ -1,6 +1,6 @@ /* - * endians.h - Definitions related to handling of byte ordering. Part of the - * Linux-NTFS project. + * endians.h - Definitions related to handling of byte ordering. + * Originated from the Linux-NTFS project. * * Copyright (c) 2000-2005 Anton Altaparmakov * @@ -15,7 +15,7 @@ * 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 Linux-NTFS + * 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 */ @@ -48,6 +48,9 @@ #ifdef HAVE_SYS_BYTEORDER_H #include #endif +#ifdef HAVE_BYTEORDER_H +#include +#endif #ifdef HAVE_SYS_PARAM_H #include #endif diff --git a/src/add-ons/kernel/file_systems/ntfs/libntfs/index.c b/src/add-ons/kernel/file_systems/ntfs/libntfs/index.c index 093ae0f315..0c3fc58aa2 100644 --- a/src/add-ons/kernel/file_systems/ntfs/libntfs/index.c +++ b/src/add-ons/kernel/file_systems/ntfs/libntfs/index.c @@ -88,7 +88,8 @@ static int ntfs_ib_write(ntfs_index_context *icx, VCN vcn, void *buf) 1, icx->block_size, buf); if (ret != 1) { ntfs_log_perror("Failed to write index block %lld of inode " - "%llu", vcn, icx->ni->mft_no); + "%llu", (long long)vcn, + (unsigned long long)icx->ni->mft_no); return STATUS_ERROR; } @@ -397,7 +398,8 @@ static int ntfs_ia_check(ntfs_index_context *icx, INDEX_BLOCK *ib, VCN vcn) if (!ntfs_is_indx_record(ib->magic)) { ntfs_log_error("Corrupt index block signature: vcn %lld inode " - "%llu\n", (long long)vcn, icx->ni->mft_no); + "%llu\n", (long long)vcn, + (unsigned long long)icx->ni->mft_no); return -1; } @@ -405,8 +407,9 @@ static int ntfs_ia_check(ntfs_index_context *icx, INDEX_BLOCK *ib, 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, icx->ni->mft_no); + (long long)sle64_to_cpu(ib->index_block_vcn), + (long long)vcn, + (unsigned long long)icx->ni->mft_no); return -1; } @@ -415,7 +418,8 @@ static int ntfs_ia_check(ntfs_index_context *icx, INDEX_BLOCK *ib, VCN vcn) 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, - icx->ni->mft_no, ib_size, icx->block_size); + (unsigned long long)icx->ni->mft_no, ib_size, + icx->block_size); return -1; } return 0; @@ -489,7 +493,8 @@ static int ntfs_ie_lookup(const void *key, const int key_len, (u8 *)ie + le16_to_cpu(ie->length) > index_end) { errno = ERANGE; ntfs_log_error("Index entry out of bounds in inode " - "%llu.\n", icx->ni->mft_no); + "%llu.\n", + (unsigned long long)icx->ni->mft_no); return STATUS_ERROR; } /* @@ -543,7 +548,8 @@ static int ntfs_ie_lookup(const void *key, const int key_len, *vcn = ntfs_ie_get_vcn(ie); if (*vcn < 0) { errno = EINVAL; - ntfs_log_perror("Negative vcn in inode %llu\n", icx->ni->mft_no); + ntfs_log_perror("Negative vcn in inode %llu\n", + (unsigned long long)icx->ni->mft_no); return STATUS_ERROR; } @@ -560,7 +566,7 @@ static ntfs_attr *ntfs_ia_open(ntfs_index_context *icx, ntfs_inode *ni) 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", ni->mft_no); + "%llu", (unsigned long long)ni->mft_no); return NULL; } @@ -581,7 +587,7 @@ static int ntfs_ib_read(ntfs_index_context *icx, VCN vcn, INDEX_BLOCK *dst) ntfs_log_perror("Failed to read index block"); else ntfs_log_error("Failed to read full index block at " - "%lld\n", pos); + "%lld\n", (long long)pos); return -1; } @@ -755,7 +761,8 @@ descend_into_child_node: 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", ni->mft_no); + "node in inode 0x%llx.\n", + (unsigned long long)ni->mft_no); goto err_out; } diff --git a/src/add-ons/kernel/file_systems/ntfs/libntfs/inode.c b/src/add-ons/kernel/file_systems/ntfs/libntfs/inode.c index 7e22f343e5..3405669e2c 100644 --- a/src/add-ons/kernel/file_systems/ntfs/libntfs/inode.c +++ b/src/add-ons/kernel/file_systems/ntfs/libntfs/inode.c @@ -1099,12 +1099,11 @@ void ntfs_inode_update_atime(ntfs_inode *ni) */ void ntfs_inode_update_time(ntfs_inode *ni) { - if (!NVolReadOnly(ni->vol) && !NVolNoATime(ni->vol) && (ni->mft_no >= - FILE_first_user || ni->mft_no == FILE_root)) { + if (!NVolReadOnly(ni->vol) && + (ni->mft_no >= FILE_first_user || ni->mft_no == FILE_root)) { time_t now; now = time(NULL); - ni->last_access_time = now; ni->last_data_change_time = now; ni->last_mft_change_time = now; NInoFileNameSetDirty(ni); diff --git a/src/add-ons/kernel/file_systems/ntfs/libntfs/lcnalloc.c b/src/add-ons/kernel/file_systems/ntfs/libntfs/lcnalloc.c index 6c593b0686..b1cb10a464 100644 --- a/src/add-ons/kernel/file_systems/ntfs/libntfs/lcnalloc.c +++ b/src/add-ons/kernel/file_systems/ntfs/libntfs/lcnalloc.c @@ -49,10 +49,10 @@ #define NTFS_LCNALLOC_SKIP 4096 -void ntfs_cluster_set_zone_pos(u8 zone, LCN zone_start, LCN zone_end, - LCN *zone_pos, LCN tc, LCN bmp_initial_pos) +static void ntfs_cluster_set_zone_pos(LCN zone_start, LCN zone_end, + LCN *zone_pos, LCN tc, LCN bmp_initial_pos) { - ntfs_log_trace("Before: zone %d = %lld\n", zone, (long long)*zone_pos); + ntfs_log_trace("Before: zone_pos: %lld\n", (long long)*zone_pos); if (tc >= zone_end) { *zone_pos = zone_start; @@ -63,29 +63,29 @@ void ntfs_cluster_set_zone_pos(u8 zone, LCN zone_start, LCN zone_end, tc >= zone_start) *zone_pos = tc; - ntfs_log_trace("After: zone %d = %lld\n", zone, (long long)*zone_pos); + ntfs_log_trace("After: zone_pos: %lld\n", (long long)*zone_pos); } -int ntfs_cluster_update_zone_pos(ntfs_volume *vol, u8 zone, LCN tc, - LCN bmp_initial_pos) +static int ntfs_cluster_update_zone_pos(ntfs_volume *vol, u8 zone, LCN tc, + LCN bmp_initial_pos) { ntfs_log_trace("tc = %lld, zone = %d\n", (long long)tc, zone); switch (zone) { case 1: - ntfs_cluster_set_zone_pos(zone, vol->mft_lcn, + ntfs_cluster_set_zone_pos(vol->mft_lcn, vol->mft_zone_end, &vol->mft_zone_pos, tc, bmp_initial_pos); break; case 2: - ntfs_cluster_set_zone_pos(zone, vol->mft_zone_end, + ntfs_cluster_set_zone_pos(vol->mft_zone_end, vol->nr_clusters, &vol->data1_zone_pos, tc, bmp_initial_pos); break; case 4: - ntfs_cluster_set_zone_pos(zone, 0, + ntfs_cluster_set_zone_pos(0, vol->mft_zone_start, &vol->data2_zone_pos, tc, bmp_initial_pos); diff --git a/src/add-ons/kernel/file_systems/ntfs/libntfs/logfile.c b/src/add-ons/kernel/file_systems/ntfs/libntfs/logfile.c index c41a762bee..9b11926952 100644 --- a/src/add-ons/kernel/file_systems/ntfs/libntfs/logfile.c +++ b/src/add-ons/kernel/file_systems/ntfs/libntfs/logfile.c @@ -655,19 +655,16 @@ BOOL ntfs_is_logfile_clean(ntfs_attr *log_na, RESTART_PAGE_HEADER *rp) 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("Done. ($LogFile is empty.)\n"); + ntfs_log_trace("$LogFile is empty\n"); return TRUE; } if (!rp) { - ntfs_log_error("Restart page header is NULL.\n"); + 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. This is " - "probably a bug in that the $LogFile should " - "have been consistency checked before calling " - "this function.\n"); + ntfs_log_error("Restart page buffer is invalid\n"); return FALSE; } @@ -679,11 +676,13 @@ BOOL ntfs_is_logfile_clean(ntfs_attr *log_na, RESTART_PAGE_HEADER *rp) */ if (ra->client_in_use_list != LOGFILE_NO_CLIENT && !(ra->flags & RESTART_VOLUME_IS_CLEAN)) { - ntfs_log_debug("Done. $LogFile indicates a dirty shutdown.\n"); + ntfs_log_error("$LogFile indicates unclean shutdown (%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("Done. $LogFile indicates a clean shutdown.\n"); + ntfs_log_trace("$LogFile indicates a clean shutdown\n"); return TRUE; } diff --git a/src/add-ons/kernel/file_systems/ntfs/libntfs/logging.c b/src/add-ons/kernel/file_systems/ntfs/libntfs/logging.c index 74568bde95..9ffe8819d7 100644 --- a/src/add-ons/kernel/file_systems/ntfs/libntfs/logging.c +++ b/src/add-ons/kernel/file_systems/ntfs/libntfs/logging.c @@ -195,9 +195,9 @@ u32 ntfs_log_clear_flags(u32 flags) */ static FILE * ntfs_log_get_stream(u32 level) { -#ifdef _BEOS_ +#if defined(__BEOS__) || defined(__HAIKU__) return NULL; -#else +#elif FILE *stream; switch (level) { @@ -220,7 +220,7 @@ static FILE * ntfs_log_get_stream(u32 level) } return stream; -#endif +#endif } /** @@ -415,9 +415,9 @@ int ntfs_log_handler_syslog(const char *function __attribute__((unused)), int ntfs_log_handler_fprintf(const char *function, const char *file, int line, u32 level, void *data, const char *format, va_list args) { -#ifdef _BEOS_ +#if defined(__BEOS__) || defined(__HAIKU__) return 0; -#else +#elif int ret = 0; int olderr = errno; FILE *stream; @@ -487,7 +487,7 @@ int ntfs_log_handler_fprintf(const char *function, const char *file, fflush(stream); errno = olderr; return ret; -#endif +#endif } /** @@ -536,13 +536,13 @@ int ntfs_log_handler_null(const char *function __attribute__((unused)), const ch int ntfs_log_handler_stdout(const char *function, const char *file, int line, u32 level, void *data, const char *format, va_list args) { -#ifndef _BEOS_ +#if defined(__BEOS__) || defined(__HAIKU__) + return 0; +#elif if (!data) data = stdout; return ntfs_log_handler_fprintf(function, file, line, level, data, format, args); -#else - return NULL; #endif } @@ -571,10 +571,14 @@ int ntfs_log_handler_stdout(const char *function, const char *file, int ntfs_log_handler_outerr(const char *function, const char *file, int line, u32 level, void *data, const char *format, va_list args) { +#if defined(__BEOS__) || defined(__HAIKU__) + return 0; +#elif if (!data) data = ntfs_log_get_stream(level); return ntfs_log_handler_fprintf(function, file, line, level, data, format, args); +#endif } /** @@ -601,10 +605,14 @@ int ntfs_log_handler_outerr(const char *function, const char *file, int ntfs_log_handler_stderr(const char *function, const char *file, int line, u32 level, void *data, const char *format, va_list args) { +#if defined(__BEOS__) || defined(__HAIKU__) + return 0; +#elif if (!data) data = stderr; return ntfs_log_handler_fprintf(function, file, line, level, data, format, args); +#endif } diff --git a/src/add-ons/kernel/file_systems/ntfs/libntfs/mft.c b/src/add-ons/kernel/file_systems/ntfs/libntfs/mft.c index 2ef1b4ea4b..028a682450 100644 --- a/src/add-ons/kernel/file_systems/ntfs/libntfs/mft.c +++ b/src/add-ons/kernel/file_systems/ntfs/libntfs/mft.c @@ -92,8 +92,8 @@ int ntfs_mft_records_read(const ntfs_volume *vol, const MFT_REF mref, vol->mft_record_size_bits) { errno = ESPIPE; ntfs_log_perror("Trying to read non-allocated mft records " - "(%lld > %lld)", m + count, - vol->mft_na->initialized_size >> + "(%lld > %lld)", (long long)m + count, + (long long)vol->mft_na->initialized_size >> vol->mft_record_size_bits); return -1; } @@ -155,8 +155,8 @@ int ntfs_mft_records_write(const ntfs_volume *vol, const MFT_REF mref, vol->mft_record_size_bits) { errno = ESPIPE; ntfs_log_perror("Trying to write non-allocated mft records " - "(%lld > %lld)", m + count, - vol->mft_na->initialized_size >> + "(%lld > %lld)", (long long)m + count, + (long long)vol->mft_na->initialized_size >> vol->mft_record_size_bits); return -1; } diff --git a/src/add-ons/kernel/file_systems/ntfs/libntfs/misc.c b/src/add-ons/kernel/file_systems/ntfs/libntfs/misc.c index 9e38347e47..71173fdeb6 100644 --- a/src/add-ons/kernel/file_systems/ntfs/libntfs/misc.c +++ b/src/add-ons/kernel/file_systems/ntfs/libntfs/misc.c @@ -2,6 +2,10 @@ #include "config.h" #endif +#ifdef HAVE_STDLIB_H +#include +#endif + #ifdef HAVE_STDLIB_H #include #endif @@ -34,3 +38,17 @@ void *ntfs_malloc(size_t size) return p; } +#if defined(__BEOS__) || defined(__HAIKU__) +int ntfs_snprintf(char *buff, size_t size, const char *format, ...) +{ + int ret; + char buffer[BUFSIZ]; + va_list args; + va_start(args, format); + memset(buffer,0,BUFSIZ); + ret = sprintf(buffer, format, args); + va_end(args); + strncpy(buff,buffer,size); + return ret; + } +#endif \ No newline at end of file diff --git a/src/add-ons/kernel/file_systems/ntfs/libntfs/misc.h b/src/add-ons/kernel/file_systems/ntfs/libntfs/misc.h index 67cc1eb670..b204c68052 100644 --- a/src/add-ons/kernel/file_systems/ntfs/libntfs/misc.h +++ b/src/add-ons/kernel/file_systems/ntfs/libntfs/misc.h @@ -4,5 +4,8 @@ void *ntfs_calloc(size_t size); void *ntfs_malloc(size_t size); +#if defined(__BEOS__) || defined(__HAIKU__) +#define snprintf ntfs_snprintf +#endif /* defined(__BEOS__) || defined(__HAIKU__) */ #endif /* _NTFS_MISC_H_ */ diff --git a/src/add-ons/kernel/file_systems/ntfs/libntfs/runlist.c b/src/add-ons/kernel/file_systems/ntfs/libntfs/runlist.c index 51723542f9..714bd0e67f 100644 --- a/src/add-ons/kernel/file_systems/ntfs/libntfs/runlist.c +++ b/src/add-ons/kernel/file_systems/ntfs/libntfs/runlist.c @@ -1040,7 +1040,8 @@ s64 ntfs_rl_pread(const ntfs_volume *vol, const runlist_element *rl, 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, pos, count); + "pos: %lld count: %lld]", vol, rl, + (long long)pos, (long long)count); return -1; } if (!count) @@ -1127,7 +1128,8 @@ s64 ntfs_rl_pwrite(const ntfs_volume *vol, const runlist_element *rl, 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, pos, count); + "pos: %lld count: %lld]", vol, rl, + (long long)pos, (long long)count); goto errno_set; } if (!count) diff --git a/src/add-ons/kernel/file_systems/ntfs/libntfs/security.c b/src/add-ons/kernel/file_systems/ntfs/libntfs/security.c index 08534247f7..926a1829af 100644 --- a/src/add-ons/kernel/file_systems/ntfs/libntfs/security.c +++ b/src/add-ons/kernel/file_systems/ntfs/libntfs/security.c @@ -44,21 +44,6 @@ #include "security.h" #include "misc.h" -#ifdef _BEOS_ -int be_snprintf(char *buff, size_t size, const char *format, ...) -{ - int ret; - char temp[1024]; - va_list args; - va_start(args, format); - ret = sprintf(temp, format, args); - va_end(args); - strncpy(buff,temp,size); - return ret; -} -#define snprintf be_snprintf -#endif - /* * The zero GUID. */ diff --git a/src/add-ons/kernel/file_systems/ntfs/libntfs/unistr.c b/src/add-ons/kernel/file_systems/ntfs/libntfs/unistr.c index 9315c1ab7f..7f12892f4e 100644 --- a/src/add-ons/kernel/file_systems/ntfs/libntfs/unistr.c +++ b/src/add-ons/kernel/file_systems/ntfs/libntfs/unistr.c @@ -373,27 +373,28 @@ int ntfs_file_values_compare(const FILE_NAME_ATTR *file_name_attr1, err_val, ic, upcase, upcase_len); } -#ifdef _BEOS_ - - +#if defined(__BEOS__) || defined(__HAIKU__) +/* Encode a single wide character into a sequence of utf8 bytes. + * Returns the number of bytes consumed, or 0 on error. + */ static int -to_utf8(wchar_t c,unsigned char* buf) +ntfs_wc_to_utf8(wchar_t c,unsigned char* buf) { if(c==0) return 0; /* No support for embedded 0 runes */ - if(c<0x80){ + if(c<0x80) { if(buf)buf[0]=(unsigned char)c; return 1; } - if(c<0x800){ - if(buf){ + if(c<0x800) { + if(buf) { buf[0] = 0xc0 | (c>>6); buf[1] = 0x80 | (c & 0x3f); } return 2; } - if(c<0x10000){ - if(buf){ + if(c<0x10000) { + if(buf) { buf[0] = 0xe0 | (c>>12); buf[1] = 0x80 | ((c>>6) & 0x3f); buf[2] = 0x80 | (c & 0x3f); @@ -410,30 +411,30 @@ to_utf8(wchar_t c,unsigned char* buf) * Returns the number of bytes consumed, or 0 on error. */ static int -from_utf8(const unsigned char* str,wchar_t *c) +ntfs_wc_from_utf8(const unsigned char* str,wchar_t *c) { int l=0,i; - if(*str<0x80){ + if(*str<0x80) { *c = *str; return 1; } if(*str<0xc0) /* lead byte must not be 10xxxxxx */ return 0; /* is c0 a possible lead byte? */ - if(*str<0xe0){ /* 110xxxxx */ + if(*str<0xe0) { /* 110xxxxx */ *c = *str & 0x1f; l=2; - }else if(*str<0xf0){ /* 1110xxxx */ + } else if(*str<0xf0) { /* 1110xxxx */ *c = *str & 0xf; l=3; - }else if(*str<0xf8){ /* 11110xxx */ + } else if(*str<0xf8) { /* 11110xxx */ *c = *str & 7; l=4; - }else /* We don't support characters above 0xFFFF in NTFS */ + } else /* We don't support characters above 0xFFFF in NTFS */ return 0; - for(i=1;id_name); goto err_out; } -#endif - +#endif NDevSetOpen(dev); return 0; err_out: @@ -157,8 +157,10 @@ static int ntfs_device_unix_io_close(struct ntfs_device *dev) } if (NDevDirty(dev)) fsync(DEV_FD(dev)); - /* Release exclusive (mandatory) lock on the whole device. */ -#ifndef _BEOS_ + +/* locking not implemented in BeOS */ +#if !defined(__BEOS__) && !defined(__HAIKU__) + /* Release exclusive (mandatory) lock on the whole device. */ memset(&flk, 0, sizeof(flk)); flk.l_type = F_UNLCK; flk.l_whence = SEEK_SET; @@ -243,7 +245,7 @@ static s64 ntfs_device_unix_io_write(struct ntfs_device *dev, const void *buf, static s64 ntfs_device_unix_io_pread(struct ntfs_device *dev, void *buf, s64 count, s64 offset) { -#ifdef _BEOS_ +#if defined(__BEOS__) || defined(__HAIKU__) return read_pos(DEV_FD(dev), offset, buf,count); #else return pread(DEV_FD(dev), buf, count, offset); @@ -269,11 +271,11 @@ static s64 ntfs_device_unix_io_pwrite(struct ntfs_device *dev, const void *buf, return -1; } NDevSetDirty(dev); -#ifdef _BEOS_ +#if defined(__BEOS__) || defined(__HAIKU__) return write_pos(DEV_FD(dev), offset, buf,count); #else return pwrite(DEV_FD(dev), buf, count, offset); -#endif +#endif } /** diff --git a/src/add-ons/kernel/file_systems/ntfs/libntfs/volume.c b/src/add-ons/kernel/file_systems/ntfs/libntfs/volume.c index 6d59437d3a..84db665f06 100644 --- a/src/add-ons/kernel/file_systems/ntfs/libntfs/volume.c +++ b/src/add-ons/kernel/file_systems/ntfs/libntfs/volume.c @@ -203,7 +203,8 @@ static int ntfs_mft_load(ntfs_volume *vol) 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", l); + ntfs_log_error("$MFT/$ATTR_LIST invalid length (%lld).\n", + (long long)l); goto io_error_exit; } vol->mft_ni->attr_list_size = l; @@ -218,7 +219,8 @@ static int ntfs_mft_load(ntfs_volume *vol) } if (l != vol->mft_ni->attr_list_size) { ntfs_log_error("Partial read of $MFT/$ATTR_LIST (%lld != " - "%u).\n", l, vol->mft_ni->attr_list_size); + "%u).\n", (long long)l, + vol->mft_ni->attr_list_size); goto io_error_exit; } @@ -774,7 +776,8 @@ ntfs_volume *ntfs_device_mount(struct ntfs_device *dev, unsigned long flags) ntfs_log_perror("Failed to read $MFT"); else { ntfs_log_error("Failed to read $MFT, unexpected length " - "(%lld != %d).\n", l, vol->mftmirr_size); + "(%lld != %d).\n", (long long)l, + vol->mftmirr_size); errno = EIO; } goto error_exit; @@ -790,7 +793,8 @@ ntfs_volume *ntfs_device_mount(struct ntfs_device *dev, unsigned long flags) else { ntfs_log_error("Failed to read $MFTMirr " "unexpected length (%d != %lld)." - "\n", vol->mftmirr_size, l); + "\n", vol->mftmirr_size, + (long long)l); errno = EIO; } goto error_exit; @@ -917,7 +921,8 @@ ntfs_volume *ntfs_device_mount(struct ntfs_device *dev, unsigned long flags) if (l != na->data_size) { ntfs_log_debug(FAILED); ntfs_log_error("Failed to read $UpCase, unexpected length " - "(%lld != %lld).\n", l, na->data_size); + "(%lld != %lld).\n", (long long)l, + (long long)na->data_size); errno = EIO; goto error_exit; } @@ -1076,7 +1081,8 @@ ntfs_volume *ntfs_device_mount(struct ntfs_device *dev, unsigned long flags) if (l != na->data_size) { ntfs_log_debug(FAILED); ntfs_log_error("Failed to read $AttrDef, unexpected length " - "(%lld != %lld).\n", l, na->data_size); + "(%lld != %lld).\n", (long long)l, + (long long)na->data_size); errno = EIO; goto error_exit; } diff --git a/src/add-ons/kernel/file_systems/ntfs/libntfs/volume.h b/src/add-ons/kernel/file_systems/ntfs/libntfs/volume.h index 7f14ab992d..3b8cde634b 100644 --- a/src/add-ons/kernel/file_systems/ntfs/libntfs/volume.h +++ b/src/add-ons/kernel/file_systems/ntfs/libntfs/volume.h @@ -61,6 +61,8 @@ #endif #endif +#define MS_EXCLUSIVE 0x08000000 + /* Forward declaration */ typedef struct _ntfs_volume ntfs_volume;