/**
* attrib.c - Attribute handling code. Originated from the Linux-NTFS project.
*
* Copyright (c) 2000-2010 Anton Altaparmakov
* Copyright (c) 2002-2005 Richard Russon
* Copyright (c) 2002-2008 Szabolcs Szakacsits
* Copyright (c) 2004-2007 Yura Pakhuchiy
* Copyright (c) 2007-2013 Jean-Pierre Andre
* Copyright (c) 2010 Erik Larsson
*
* This program/include file is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as published
* by the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program/include file is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* 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 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
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#ifdef HAVE_STDIO_H
#include <stdio.h>
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#endif
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#ifdef HAVE_ERRNO_H
#include <errno.h>
#endif
#ifdef HAVE_LIMITS_H
#include <limits.h>
#endif
#include "param.h"
#include "compat.h"
#include "attrib.h"
#include "attrlist.h"
#include "device.h"
#include "mft.h"
#include "debug.h"
#include "mst.h"
#include "volume.h"
#include "types.h"
#include "layout.h"
#include "inode.h"
#include "runlist.h"
#include "lcnalloc.h"
#include "dir.h"
#include "compress.h"
#include "bitmap.h"
#include "logging.h"
#include "misc.h"
#include "efs.h"
ntfschar AT_UNNAMED[] = { const_cpu_to_le16('\0') };
ntfschar STREAM_SDS[] = { const_cpu_to_le16('$'),
const_cpu_to_le16('S'),
const_cpu_to_le16('D'),
const_cpu_to_le16('S'),
const_cpu_to_le16('\0') };
ntfschar TXF_DATA[] = { const_cpu_to_le16('$'),
const_cpu_to_le16('T'),
const_cpu_to_le16('X'),
const_cpu_to_le16('F'),
const_cpu_to_le16('_'),
const_cpu_to_le16('D'),
const_cpu_to_le16('A'),
const_cpu_to_le16('T'),
const_cpu_to_le16('A'),
const_cpu_to_le16('\0') };
static int NAttrFlag(ntfs_attr *na, FILE_ATTR_FLAGS flag)
{
if (na->type == AT_DATA && na->name == AT_UNNAMED)
return (na->ni->flags & flag);
return 0;
}
static void NAttrSetFlag(ntfs_attr *na, FILE_ATTR_FLAGS flag)
{
if (na->type == AT_DATA && na->name == AT_UNNAMED)
na->ni->flags |= flag;
else
ntfs_log_trace("Denied setting flag %d for not unnamed data "
"attribute\n", flag);
}
static void NAttrClearFlag(ntfs_attr *na, FILE_ATTR_FLAGS flag)
{
if (na->type == AT_DATA && na->name == AT_UNNAMED)
na->ni->flags &= ~flag;
}
#define GenNAttrIno(func_name, flag) \
int NAttr##func_name(ntfs_attr *na) { return NAttrFlag (na, flag); } \
void NAttrSet##func_name(ntfs_attr *na) { NAttrSetFlag (na, flag); } \
void NAttrClear##func_name(ntfs_attr *na){ NAttrClearFlag(na, flag); }
GenNAttrIno(Compressed, FILE_ATTR_COMPRESSED)
GenNAttrIno(Encrypted, FILE_ATTR_ENCRYPTED)
GenNAttrIno(Sparse, FILE_ATTR_SPARSE_FILE)
/**
* ntfs_get_attribute_value_length - Find the length of an attribute
* @a:
*
* Description...
*
* Returns:
*/
s64 ntfs_get_attribute_value_length(const ATTR_RECORD *a)
{
if (!a) {
errno = EINVAL;
return 0;
}
errno = 0;
if (a->non_resident)
return sle64_to_cpu(a->data_size);
return (s64)le32_to_cpu(a->value_length);
}
/**
* ntfs_get_attribute_value - Get a copy of an attribute
* @vol:
* @a:
* @b:
*
* Description...
*
* Returns:
*/
s64 ntfs_get_attribute_value(const ntfs_volume *vol,
const ATTR_RECORD *a, u8 *b)
{
runlist *rl;
s64 total, r;
int i;
/* Sanity checks. */
if (!vol || !a || !b) {
errno = EINVAL;
return 0;
}
/* Complex attribute? */
/*
* Ignore the flags in case they are not zero for an attribute list
* attribute. Windows does not complain about invalid flags and chkdsk
* does not detect or fix them so we need to cope with it, too.
*/
if (a->type != AT_ATTRIBUTE_LIST && a->flags) {
ntfs_log_error("Non-zero (%04x) attribute flags. Cannot handle "
"this yet.\n", le16_to_cpu(a->flags));
errno = EOPNOTSUPP;
return 0;
}
if (!a->non_resident) {
/* Attribute is resident. */
/* Sanity check. */
if (le32_to_cpu(a->value_length) + le16_to_cpu(a->value_offset)
> le32_to_cpu(a->length)) {
return 0;
}
memcpy(b, (const char*)a + le16_to_cpu(a->value_offset),
le32_to_cpu(a->value_length));
errno = 0;
return (s64)le32_to_cpu(a->value_length);
}
/* Attribute is not resident. */
/* If no data, return 0. */
if (!(a->data_size)) {
errno = 0;
return 0;
}
/*
* FIXME: What about attribute lists?!? (AIA)
*/
/* Decompress the mapping pairs array into a runlist. */
rl = ntfs_mapping_pairs_decompress(vol, a, NULL);
if (!rl) {
errno = EINVAL;
return 0;
}
/*
* FIXED: We were overflowing here in a nasty fashion when we
* reach the last cluster in the runlist as the buffer will
* only be big enough to hold data_size bytes while we are
* reading in allocated_size bytes which is usually larger
* than data_size, since the actual data is unlikely to have a
* size equal to a multiple of the cluster size!
* FIXED2: We were also overflowing here in the same fashion
* when the data_size was more than one run smaller than the
* allocated size which happens with Windows XP sometimes.
*/
/* Now load all clusters in the runlist into b. */
for (i = 0, total = 0; rl[i].length; i++) {
if (total + (rl[i].length << vol->cluster_size_bits) >=
sle64_to_cpu(a->data_size)) {
unsigned char *intbuf = NULL;
/*
* We have reached the last run so we were going to
* overflow when executing the ntfs_pread() which is
* BAAAAAAAD!
* Temporary fix:
* Allocate a new buffer with size:
* rl[i].length << vol->cluster_size_bits, do the
* read into our buffer, then memcpy the correct
* amount of data into the caller supplied buffer,
* free our buffer, and continue.
* We have reached the end of data size so we were
* going to overflow in the same fashion.
* Temporary fix: same as above.
*/
intbuf = ntfs_malloc(rl[i].length << vol->cluster_size_bits);
if (!intbuf) {
free(rl);
return 0;
}
/*
* FIXME: If compressed file: Only read if lcn != -1.
* Otherwise, we are dealing with a sparse run and we
* just memset the user buffer to 0 for the length of
* the run, which should be 16 (= compression unit
* size).
* FIXME: Really only when file is compressed, or can
* we have sparse runs in uncompressed files as well?
* - Yes we can, in sparse files! But not necessarily
* size of 16, just run length.
*/
r = ntfs_pread(vol->dev, rl[i].lcn <<
vol->cluster_size_bits, rl[i].length <<
vol->cluster_size_bits, intbuf);
if (r != rl[i].length << vol->cluster_size_bits) {
#define ESTR "Error reading attribute value"
if (r == -1)
ntfs_log_perror(ESTR);
else if (r < rl[i].length <<
vol->cluster_size_bits) {
ntfs_log_debug(ESTR ": Ran out of input data.\n");
errno = EIO;
} else {
ntfs_log_debug(ESTR ": unknown error\n");
errno = EIO;
}
#undef ESTR
free(rl);
free(intbuf);
return 0;
}
memcpy(b + total, intbuf, sle64_to_cpu(a->data_size) -
total);
free(intbuf);
total = sle64_to_cpu(a->data_size);
break;
}
/*
* FIXME: If compressed file: Only read if lcn != -1.
* Otherwise, we are dealing with a sparse run and we just
* memset the user buffer to 0 for the length of the run, which
* should be 16 (= compression unit size).
* FIXME: Really only when file is compressed, or can
* we have sparse runs in uncompres
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
Linux下挂载NTFS文件格式的移动存储设备 (493个子文件)
libntfs-3g.so.85.0.0 1.07MB
ntfs-3g.8 17KB
ntfsclone.8 12KB
ntfsresize.8 12KB
ntfsundelete.8 9KB
mkntfs.8 7KB
ntfs-3g.secaudit.8 7KB
ntfscp.8 4KB
ntfs-3g.usermap.8 3KB
ntfslabel.8 3KB
ntfscat.8 3KB
ntfsls.8 3KB
ntfscluster.8 3KB
ntfsfix.8 2KB
ntfsinfo.8 2KB
ntfs-3g.probe.8 2KB
ntfscmp.8 2KB
ntfsprogs.8 2KB
libntfs-3g.so.85 1.07MB
libntfs-3g.a 1.89MB
libfuse-lite.a 486KB
configure.ac 19KB
Makefile.am 4KB
Makefile.am 3KB
Makefile.am 2KB
Makefile.am 1KB
Makefile.am 600B
Makefile.am 558B
Makefile.am 164B
Makefile.am 75B
AUTHORS 327B
attrib.c 199KB
secaudit.c 179KB
mkntfs.c 156KB
security.c 134KB
ntfsresize.c 116KB
acls.c 111KB
lowntfs-3g.c 102KB
ntfs-3g.c 99KB
fuse.c 85KB
dir.c 76KB
ntfsclone.c 69KB
ntfsinfo.c 67KB
ntfsundelete.c 62KB
runlist.c 61KB
mft.c 58KB
win32_io.c 54KB
ntfswipe.c 51KB
volume.c 51KB
compress.c 49KB
index.c 48KB
ntfsfix.c 44KB
inode.c 43KB
unistr.c 42KB
ntfsdecrypt.c 38KB
fuse_lowlevel.c 38KB
usermap.c 32KB
reparse.c 31KB
utils.c 30KB
ntfsck.c 27KB
device.c 25KB
ntfsdump_logfile.c 24KB
logfile.c 24KB
ntfscmp.c 21KB
sd.c 21KB
mount.c 21KB
boot.c 20KB
lcnalloc.c 20KB
ntfstruncate.c 20KB
ntfsmove.c 20KB
ntfs-3g_common.c 19KB
xattrs.c 19KB
fusermount.c 17KB
logging.c 17KB
ntfsls.c 17KB
object_id.c 16KB
cache.c 15KB
attrdef.c 15KB
ntfscp.c 15KB
ntfscluster.c 14KB
ntfslabel.c 11KB
mount_util.c 11KB
efs.c 11KB
ntfscat.c 11KB
ntfsmftalloc.c 10KB
bootsect.c 10KB
fuse_opt.c 10KB
attrlist.c 9KB
unix_io.c 8KB
bitmap.c 8KB
mst.c 8KB
compat.c 8KB
collate.c 6KB
fuse_session.c 4KB
ntfs-3g.probe.c 4KB
cluster.c 3KB
fuse_kern_chan.c 2KB
realpath.c 2KB
debug.c 2KB
fuse_signals.c 2KB
共 493 条
- 1
- 2
- 3
- 4
- 5
资源评论
HuBei438700
- 粉丝: 0
- 资源: 9
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功