"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "libntfs-3g/dir.c" between
ntfs-3g_ntfsprogs-2016.2.22.tgz and ntfs-3g_ntfsprogs-2017.3.23.tgz

About: NTFS-3G is a read-write NTFS driver for Linux and other operating systems. It provides safe handling of the Windows XP, Windows Server 2003, Windows 2000, Windows Vista, Windows Server 2008, Windows 7 and Windows 8 NTFS file systems.

dir.c  (ntfs-3g_ntfsprogs-2016.2.22.tgz):dir.c  (ntfs-3g_ntfsprogs-2017.3.23.tgz)
skipping to change at line 43 skipping to change at line 43
#ifdef HAVE_ERRNO_H #ifdef HAVE_ERRNO_H
#include <errno.h> #include <errno.h>
#endif #endif
#ifdef HAVE_STRING_H #ifdef HAVE_STRING_H
#include <string.h> #include <string.h>
#endif #endif
#ifdef HAVE_SYS_STAT_H #ifdef HAVE_SYS_STAT_H
#include <sys/stat.h> #include <sys/stat.h>
#endif #endif
#ifdef HAVE_SYS_SYSMACROS_H #ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef MAJOR_IN_MKDEV
#include <sys/mkdev.h>
#endif
#ifdef MAJOR_IN_SYSMACROS
#include <sys/sysmacros.h> #include <sys/sysmacros.h>
#endif #endif
#include "param.h" #include "param.h"
#include "types.h" #include "types.h"
#include "debug.h" #include "debug.h"
#include "attrib.h" #include "attrib.h"
#include "inode.h" #include "inode.h"
#include "dir.h" #include "dir.h"
#include "volume.h" #include "volume.h"
#include "mft.h" #include "mft.h"
#include "index.h" #include "index.h"
#include "ntfstime.h" #include "ntfstime.h"
#include "lcnalloc.h" #include "lcnalloc.h"
#include "logging.h" #include "logging.h"
#include "cache.h" #include "cache.h"
#include "misc.h" #include "misc.h"
#include "security.h" #include "security.h"
#include "reparse.h" #include "reparse.h"
#include "object_id.h" #include "object_id.h"
#include "xattrs.h"
#ifdef HAVE_SETXATTR
#include <sys/xattr.h>
#endif
/* /*
* The little endian Unicode strings "$I30", "$SII", "$SDH", "$O" * The little endian Unicode strings "$I30", "$SII", "$SDH", "$O"
* and "$Q" as global constants. * and "$Q" as global constants.
*/ */
ntfschar NTFS_INDEX_I30[5] = { const_cpu_to_le16('$'), const_cpu_to_le16('I'), 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('3'), const_cpu_to_le16('0'),
const_cpu_to_le16('\0') }; const_cpu_to_le16('\0') };
ntfschar NTFS_INDEX_SII[5] = { const_cpu_to_le16('$'), const_cpu_to_le16('S'), 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('I'), const_cpu_to_le16('I'),
skipping to change at line 878 skipping to change at line 881
} INDEX_TYPE; } INDEX_TYPE;
/* /*
* Decode Interix file types * Decode Interix file types
* *
* Non-Interix types are returned as plain files, because a * Non-Interix types are returned as plain files, because a
* Windows user may force patterns very similar to Interix, * Windows user may force patterns very similar to Interix,
* and most metadata files have such similar patters. * and most metadata files have such similar patters.
*/ */
static u32 ntfs_interix_types(ntfs_inode *ni) u32 ntfs_interix_types(ntfs_inode *ni)
{ {
ntfs_attr *na; ntfs_attr *na;
u32 dt_type; u32 dt_type;
le64 magic; le64 magic;
dt_type = NTFS_DT_UNKNOWN; dt_type = NTFS_DT_UNKNOWN;
na = ntfs_attr_open(ni, AT_DATA, NULL, 0); na = ntfs_attr_open(ni, AT_DATA, NULL, 0);
if (na) { if (na) {
/* Unrecognized patterns (eg HID + SYST) are plain files */ /*
dt_type = NTFS_DT_REG; * 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 (na->data_size <= 1) {
if (!(ni->flags & FILE_ATTR_HIDDEN)) if (!(ni->flags & FILE_ATTR_HIDDEN))
dt_type = (na->data_size ? dt_type = (na->data_size ?
NTFS_DT_SOCK : NTFS_DT_FIFO); NTFS_DT_SOCK : NTFS_DT_FIFO);
} else { } else {
if ((na->data_size >= (s64)sizeof(magic)) if ((na->data_size >= (s64)sizeof(magic))
&& (ntfs_attr_pread(na, 0, sizeof(magic), &magic) && (ntfs_attr_pread(na, 0, sizeof(magic), &magic)
== sizeof(magic))) { == sizeof(magic))) {
if (magic == INTX_SYMBOLIC_LINK) if (magic == INTX_SYMBOLIC_LINK)
dt_type = NTFS_DT_LNK; dt_type = NTFS_DT_LNK;
skipping to change at line 1894 skipping to change at line 1903
/* /*
* Search for FILE_NAME attribute with such name. If it's in POSIX or * 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. * 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, * If filename in DOS or in WIN32 namespace, then remove DOS name first,
* only then remove WIN32 name. * only then remove WIN32 name.
*/ */
actx = ntfs_attr_get_search_ctx(ni, NULL); actx = ntfs_attr_get_search_ctx(ni, NULL);
if (!actx) if (!actx)
goto err_out; goto err_out;
search: search:
while (!ntfs_attr_lookup(AT_FILE_NAME, AT_UNNAMED, 0, CASE_SENSITIVE, while (!(err = ntfs_attr_lookup(AT_FILE_NAME, AT_UNNAMED, 0,
0, NULL, 0, actx)) { CASE_SENSITIVE, 0, NULL, 0, actx))) {
#ifdef DEBUG
char *s; char *s;
#endif
IGNORE_CASE_BOOL case_sensitive = IGNORE_CASE; IGNORE_CASE_BOOL case_sensitive = IGNORE_CASE;
errno = 0;
fn = (FILE_NAME_ATTR*)((u8*)actx->attr + fn = (FILE_NAME_ATTR*)((u8*)actx->attr +
le16_to_cpu(actx->attr->value_offset)); le16_to_cpu(actx->attr->value_offset));
#ifdef DEBUG
s = ntfs_attr_name_get(fn->file_name, fn->file_name_length); s = ntfs_attr_name_get(fn->file_name, fn->file_name_length);
ntfs_log_trace("name: '%s' type: %d dos: %d win32: %d " ntfs_log_trace("name: '%s' type: %d dos: %d win32: %d "
"case: %d\n", s, fn->file_name_type, "case: %d\n", s, fn->file_name_type,
looking_for_dos_name, looking_for_win32_name, looking_for_dos_name, looking_for_win32_name,
case_sensitive_match); case_sensitive_match);
ntfs_attr_name_free(&s); ntfs_attr_name_free(&s);
#endif
if (looking_for_dos_name) { if (looking_for_dos_name) {
if (fn->file_name_type == FILE_NAME_DOS) if (fn->file_name_type == FILE_NAME_DOS)
break; break;
else else
continue; continue;
} }
if (looking_for_win32_name) { if (looking_for_win32_name) {
if (fn->file_name_type == FILE_NAME_WIN32) if (fn->file_name_type == FILE_NAME_WIN32)
break; break;
else else
skipping to change at line 1948 skipping to change at line 1960
if (fn->file_name_type == FILE_NAME_WIN32) { if (fn->file_name_type == FILE_NAME_WIN32) {
looking_for_dos_name = TRUE; looking_for_dos_name = TRUE;
ntfs_attr_reinit_search_ctx(actx); ntfs_attr_reinit_search_ctx(actx);
continue; continue;
} }
if (fn->file_name_type == FILE_NAME_DOS) if (fn->file_name_type == FILE_NAME_DOS)
looking_for_dos_name = TRUE; looking_for_dos_name = TRUE;
break; break;
} }
} }
if (errno) { if (err) {
/* /*
* If case sensitive search failed, then try once again * If case sensitive search failed, then try once again
* ignoring case. * ignoring case.
*/ */
if (errno == ENOENT && case_sensitive_match) { if (errno == ENOENT && case_sensitive_match) {
case_sensitive_match = FALSE; case_sensitive_match = FALSE;
ntfs_attr_reinit_search_ctx(actx); ntfs_attr_reinit_search_ctx(actx);
goto search; goto search;
} }
goto err_out; goto err_out;
skipping to change at line 2270 skipping to change at line 2282
inum = le64_to_cpu(fn->parent_directory); inum = le64_to_cpu(fn->parent_directory);
if (inum != (u64)-1) { if (inum != (u64)-1) {
dir_ni = ntfs_inode_open(ni->vol, MREF(inum)); dir_ni = ntfs_inode_open(ni->vol, MREF(inum));
} }
} }
ntfs_attr_put_search_ctx(ctx); ntfs_attr_put_search_ctx(ctx);
} }
return (dir_ni); return (dir_ni);
} }
#ifdef HAVE_SETXATTR
#define MAX_DOS_NAME_LENGTH 12 #define MAX_DOS_NAME_LENGTH 12
/* /*
* Get a DOS name for a file in designated directory * Get a DOS name for a file in designated directory
* *
* Not allowed if there are several non-dos names (EMLINK) * Not allowed if there are several non-dos names (EMLINK)
* *
* Returns size if found * Returns size if found
* 0 if not found * 0 if not found
* -1 if there was an error (described by errno) * -1 if there was an error (described by errno)
skipping to change at line 2418 skipping to change at line 2428
dnum = dir_ni->mft_no; dnum = dir_ni->mft_no;
doslen = get_dos_name(ni, dnum, dosname); doslen = get_dos_name(ni, dnum, dosname);
if (doslen > 0) { if (doslen > 0) {
/* /*
* Found a DOS name for the entry, make * Found a DOS name for the entry, make
* uppercase and encode into the buffer * uppercase and encode into the buffer
* if there is enough space * if there is enough space
*/ */
ntfs_name_upcase(dosname, doslen, ntfs_name_upcase(dosname, doslen,
ni->vol->upcase, ni->vol->upcase_len); ni->vol->upcase, ni->vol->upcase_len);
if (ntfs_ucstombs(dosname, doslen, &outname, size) < 0) { outsize = ntfs_ucstombs(dosname, doslen, &outname, 0);
if (outsize < 0) {
ntfs_log_error("Cannot represent dosname in current local e.\n"); ntfs_log_error("Cannot represent dosname in current local e.\n");
outsize = -errno; outsize = -errno;
} else { } else {
outsize = strlen(outname);
if (value && (outsize <= (int)size)) if (value && (outsize <= (int)size))
memcpy(value, outname, outsize); memcpy(value, outname, outsize);
else else
if (size && (outsize > (int)size)) if (size && (outsize > (int)size))
outsize = -ERANGE; outsize = -ERANGE;
free(outname); free(outname);
} }
} else { } else {
if (doslen == 0) if (doslen == 0)
errno = ENODATA; errno = ENODATA;
skipping to change at line 2643 skipping to change at line 2653
/* copy the string to insert a null char, and truncate */ /* copy the string to insert a null char, and truncate */
if (size > 3*MAX_DOS_NAME_LENGTH) if (size > 3*MAX_DOS_NAME_LENGTH)
size = 3*MAX_DOS_NAME_LENGTH; size = 3*MAX_DOS_NAME_LENGTH;
strncpy(newname, value, size); strncpy(newname, value, size);
/* a long name may be truncated badly and be untranslatable */ /* a long name may be truncated badly and be untranslatable */
newname[size] = 0; newname[size] = 0;
/* convert the string to the NTFS wide chars, and truncate */ /* convert the string to the NTFS wide chars, and truncate */
shortlen = ntfs_mbstoucs(newname, &shortname); shortlen = ntfs_mbstoucs(newname, &shortname);
if (shortlen > MAX_DOS_NAME_LENGTH) if (shortlen > MAX_DOS_NAME_LENGTH)
shortlen = MAX_DOS_NAME_LENGTH; shortlen = MAX_DOS_NAME_LENGTH;
/* make sure the short name has valid chars */
/* 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) if ((shortlen < 0)
|| ntfs_forbidden_names(ni->vol,shortname,shortlen)) { || ntfs_forbidden_names(ni->vol,shortname,shortlen,TRUE)) {
ntfs_inode_close_in_dir(ni,dir_ni); ntfs_inode_close_in_dir(ni,dir_ni);
ntfs_inode_close(dir_ni); ntfs_inode_close(dir_ni);
res = -errno; res = -errno;
return res; return res;
} }
dnum = dir_ni->mft_no; dnum = dir_ni->mft_no;
longlen = get_long_name(ni, dnum, longname); longlen = get_long_name(ni, dnum, longname);
if (longlen > 0) { if (longlen > 0) {
oldlen = get_dos_name(ni, dnum, oldname); oldlen = get_dos_name(ni, dnum, oldname);
if ((oldlen >= 0) if ((oldlen >= 0)
&& !ntfs_forbidden_names(ni->vol, longname, longlen)) { && !ntfs_forbidden_names(ni->vol, longname, longlen,
FALSE)) {
if (oldlen > 0) { if (oldlen > 0) {
if (flags & XATTR_CREATE) { if (flags & XATTR_CREATE) {
res = -1; res = -1;
errno = EEXIST; errno = EEXIST;
} else } else
if ((shortlen == oldlen) if ((shortlen == oldlen)
&& !memcmp(shortname,oldname, && !memcmp(shortname,oldname,
oldlen*sizeof(ntfschar))) oldlen*sizeof(ntfschar)))
/* already set, done */ /* already set, done */
res = 0; res = 0;
skipping to change at line 2777 skipping to change at line 2791
if (!longlen) if (!longlen)
errno = ENOENT; errno = ENOENT;
res = -1; res = -1;
} }
if (!deleted) { if (!deleted) {
ntfs_inode_close_in_dir(ni,dir_ni); ntfs_inode_close_in_dir(ni,dir_ni);
ntfs_inode_close(dir_ni); ntfs_inode_close(dir_ni);
} }
return (res); return (res);
} }
#endif
 End of changes. 17 change blocks. 
19 lines changed or deleted 33 lines changed or added

Home  |  About  |  All  |  Newest  |  Fossies Dox  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTPS