From 63ef915ed5ea004d65744038bfa8c876634b5df3 Mon Sep 17 00:00:00 2001 From: jpandre Date: Thu, 5 Nov 2009 11:27:10 +0000 Subject: [PATCH] ntfs_fuse_filler: truncate too large filenames on OS X (Erik Larsson) --- src/ntfs-3g.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/ntfs-3g.c b/src/ntfs-3g.c index 182f5ef2..949ae550 100644 --- a/src/ntfs-3g.c +++ b/src/ntfs-3g.c @@ -83,6 +83,10 @@ #include #endif +#if defined(__APPLE__) || defined(__DARWIN__) +#include +#endif /* defined(__APPLE__) || defined(__DARWIN__) */ + #include "compat.h" #include "attrib.h" #include "inode.h" @@ -786,11 +790,12 @@ static int ntfs_fuse_filler(ntfs_fuse_fill_context_t *fill_ctx, { char *filename = NULL; int ret = 0; + int filenamelen = -1; if (name_type == FILE_NAME_DOS) return 0; - if (ntfs_ucstombs(name, name_len, &filename, 0) < 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; @@ -813,6 +818,20 @@ static int ntfs_fuse_filler(ntfs_fuse_fill_context_t *fill_ctx, else if (dt_type == NTFS_DT_DIR) st.st_mode = S_IFDIR | (0777 & ~ctx->dmask); +#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); + } +#endif /* defined(__APPLE__) || defined(__DARWIN__) */ + ret = fill_ctx->filler(fill_ctx->buf, filename, &st, 0); }