/**
* 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-2010 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
没有合适的资源?快使用搜索试试~ 我知道了~
ntfs-3g-2010.8.8.tgz
4星 · 超过85%的资源 需积分: 17 102 下载量 26 浏览量
2010-09-03
22:33:45
上传
评论
收藏 855KB TGZ 举报
温馨提示
共130个文件
c:45个
h:44个
in:14个
您的centos是不是不支持ntfs啊,下载这个吧,让linux支持ntfs。
资源推荐
资源详情
资源评论
收起资源包目录
ntfs-3g-2010.8.8.tgz (130个子文件)
configure.ac 12KB
Makefile.am 2KB
Makefile.am 2KB
Makefile.am 679B
Makefile.am 573B
Makefile.am 506B
Makefile.am 164B
Makefile.am 75B
AUTHORS 327B
attrib.c 188KB
secaudit.c 168KB
security.c 132KB
lowntfs-3g.c 114KB
ntfs-3g.c 114KB
acls.c 109KB
fuse.c 75KB
dir.c 73KB
runlist.c 62KB
mft.c 58KB
compress.c 49KB
index.c 48KB
volume.c 45KB
inode.c 42KB
win32_io.c 41KB
fuse_lowlevel.c 38KB
unistr.c 38KB
usermap.c 32KB
reparse.c 31KB
logfile.c 24KB
device.c 20KB
lcnalloc.c 20KB
logging.c 16KB
fusermount.c 16KB
object_id.c 16KB
cache.c 15KB
efs.c 11KB
bootsect.c 10KB
fuse_opt.c 9KB
attrlist.c 9KB
unix_io.c 8KB
bitmap.c 8KB
compat.c 8KB
mst.c 8KB
mount.c 7KB
collate.c 6KB
mount_util.c 5KB
fuse_session.c 4KB
ntfs-3g.probe.c 3KB
fuse_kern_chan.c 2KB
debug.c 2KB
fuse_signals.c 2KB
misc.c 2KB
fuse_loop.c 986B
helper.c 814B
ChangeLog 296B
compile 4KB
configure 784KB
COPYING 18KB
CREDITS 710B
depcomp 17KB
config.guess 44KB
layout.h 106KB
fuse_lowlevel.h 36KB
fuse.h 20KB
secaudit.h 19KB
logfile.h 16KB
attrib.h 14KB
volume.h 11KB
security.h 10KB
inode.h 8KB
fuse_kernel.h 8KB
fuse_opt.h 7KB
acls.h 7KB
endians.h 7KB
index.h 6KB
logging.h 6KB
unistr.h 5KB
device.h 5KB
mft.h 5KB
fuse_common.h 4KB
dir.h 4KB
ntfstime.h 4KB
cache.h 3KB
runlist.h 3KB
bitmap.h 3KB
types.h 3KB
param.h 3KB
support.h 2KB
device_io.h 2KB
fuse_misc.h 2KB
compat.h 2KB
lcnalloc.h 2KB
attrlist.h 2KB
bootsect.h 2KB
debug.h 2KB
compress.h 1KB
reparse.h 1KB
mst.h 1KB
collate.h 1KB
object_id.h 1KB
共 130 条
- 1
- 2
资源评论
- qihao1902014-10-31好工具呀,真是救急了哟
- lbkjm12017-08-08linux下挂在windows的盘.
- 普通网友2014-03-13linux下挂在windows的盘
- android顽童2014-02-28可以用谢谢了,谢谢楼主分享了,可以使用这个软件进行挂载操作
hailang424
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功