diff --git a/ChangeLog b/ChangeLog index f7791c20..99c29c35 100644 --- a/ChangeLog +++ b/ChangeLog @@ -10,8 +10,8 @@ xx/xx/2006 - x.xx.x - . selected type and name already present in inode. (Szaka) - Extend ntfs_index_{add_filename,rm} to support almost all cases of index operations. (Szaka) - - Support index operations when index root is in the base mft record. - (Yura) + - Support index operations when index root is in the base MFT + record. (Yura) - calloc/malloc -> ntfs_{calloc,malloc} conversions. (Szaka) - ntfsclone: don't create image files with executable bit set. (Szaka) - ntfsclone: metadata cloning: write out extent records. (Szaka) @@ -26,8 +26,8 @@ xx/xx/2006 - x.xx.x - . - ntfsinfo: add ntfs_dump_index_block() and use it. (Szaka) - ntfsinfo: fix output indenting. (Szaka) - ntfsinfo: make stdout line buffered. (Szaka) - - ntfsinfo: fix segfaults when SDS has absolute security descriptor. - (Szaka) + - ntfsinfo: fix segfaults when SDS has absolute security + descriptor. (Szaka) - ntfsinfo: redirect stderr to /dev/null if --debug isn't used in debug mode. (Szaka) - ntfsinfo: fix segfaults on corrupt index blocks. (Szaka) @@ -86,15 +86,18 @@ xx/xx/2006 - x.xx.x - . with. (Anton) - Introduce NTFS_MNT_FORENSIC mount option for logfile dumping for example otherwise the logfile gets wiped out by the mount attempt if - it is not read-only. (Anton) + it is not read-only. (Anton) - Fix ntfsresize to unmount the volume when finished/exiting so it does not leave the volume in an inconsistent state. Somewhat crude solution using atexit() but it works... (Anton) - Raise FUSE dependence to 2.6.1 (the most stable and featured ATM), rename --enable-fuse-module to more clear --enable-ntfsmount and - cleanup autotools scripts a bit. - - ntfsclone: don't check free space if output file is FIFO (Andree + cleanup autotools scripts a bit. (Yura) + - ntfsclone: don't check free space if output file is FIFO. (Andree Leidenfrost) + - Turn ntfs_pathname_to_inode() into ntfs_pathname_to_inode_num() which + returns ntfs inode number instead of opened inode itself. + Reimplement ntfs_pathname_to_inode() as wrapper to new API. (Yura) 21/06/2006 - 1.13.1 - Various fixes. diff --git a/include/ntfs/dir.h b/include/ntfs/dir.h index 4b76c441..600bb3a3 100644 --- a/include/ntfs/dir.h +++ b/include/ntfs/dir.h @@ -65,6 +65,8 @@ 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_pathname_to_inode_num(ntfs_volume *vol, ntfs_inode *parent, + const char *pathname); extern ntfs_inode *ntfs_pathname_to_inode(ntfs_volume *vol, ntfs_inode *parent, const char *pathname); diff --git a/libntfs/dir.c b/libntfs/dir.c index 4f08956c..b25e7ea5 100644 --- a/libntfs/dir.c +++ b/libntfs/dir.c @@ -470,7 +470,8 @@ close_err_out: } /** - * ntfs_pathname_to_inode - Find the inode which represents the given pathname + * ntfs_pathname_to_inode_num - find the inode number 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 @@ -479,43 +480,35 @@ close_err_out: * 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 + * Return: -1 Error, the pathname was invalid, or some other error occurred + * else Success, the pathname was valid */ -ntfs_inode *ntfs_pathname_to_inode(ntfs_volume *vol, ntfs_inode *parent, +u64 ntfs_pathname_to_inode_num(ntfs_volume *vol, ntfs_inode *parent, const char *pathname) { - u64 inum; + u64 inum, result = (u64)-1; int len, err = 0; char *p, *q; - ntfs_inode *ni; - ntfs_inode *result = NULL; + ntfs_inode *ni = NULL; ntfschar *unicode = NULL; char *ascii = NULL; if (!vol || !pathname) { - errno = EINVAL; - return NULL; + err = EINVAL; + goto close; } ntfs_log_trace("Path: '%s'\n", pathname); if (parent) { ni = parent; - } else { - ni = ntfs_inode_open(vol, FILE_root); - if (!ni) { - ntfs_log_debug("Couldn't open the inode of the root " - "directory.\n"); - err = EIO; - goto close; - } - } + } else + inum = FILE_root; unicode = calloc(1, MAX_PATH); ascii = strdup(pathname); if (!unicode || !ascii) { - ntfs_log_debug("Out of memory.\n"); + ntfs_log_error("Out of memory.\n"); err = ENOMEM; goto close; } @@ -525,10 +518,20 @@ ntfs_inode *ntfs_pathname_to_inode(ntfs_volume *vol, ntfs_inode *parent, while (p && *p == PATH_SEP) p++; while (p && *p) { + if (!ni) { + ni = ntfs_inode_open(vol, inum); + if (!ni) { + ntfs_log_debug("Cannot open inode %llu.\n", + (unsigned long long)inum); + err = EIO; + goto close; + } + } + /* Find the end of the first token. */ q = strchr(p, PATH_SEP); if (q != NULL) { - *q = '\0'; + *q = 0; q++; } @@ -547,26 +550,17 @@ ntfs_inode *ntfs_pathname_to_inode(ntfs_volume *vol, ntfs_inode *parent, err = ENOENT; goto close; } + inum = MREF(inum); if (ni != parent) ntfs_inode_close(ni); - - 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; - } + ni = NULL; p = q; - while (p && *p && *p == PATH_SEP) + while (p && *p == PATH_SEP) p++; } - - result = ni; - ni = NULL; + result = inum; close: if (ni && (ni != parent)) ntfs_inode_close(ni); @@ -577,6 +571,30 @@ close: return result; } +/** + * 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; + + inum = ntfs_pathname_to_inode_num(vol, parent, pathname); + if (inum == (u64)-1) + return NULL; + return ntfs_inode_open(vol, inum); +} + /* * The little endian Unicode string ".." for ntfs_readdir(). */ diff --git a/ntfsprogs/ntfsmount.c b/ntfsprogs/ntfsmount.c index 16f089f8..54470d89 100644 --- a/ntfsprogs/ntfsmount.c +++ b/ntfsprogs/ntfsmount.c @@ -4,7 +4,7 @@ * Copyright (c) 2005-2006 Yura Pakhuchiy * Copyright (c) 2005 Yuval Fledel * - * NTFS module for FUSE. + * Userspace NTFS driver. * * 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