- cleanup,

- fix copyright,
- disable tracing,
- add support for reading attributes. The current naming is not final as I'm actually experimenting with it.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36152 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
François Revol
2010-04-11 13:56:44 +00:00
parent 8bc3360be8
commit 2365cde279
4 changed files with 27 additions and 36 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2008, Axel Dörfler, [email protected].
* Copyright 2010, François Revol, <[email protected]>.
* This file may be used under the terms of the MIT License.
*/
@@ -31,7 +31,7 @@ AttributeIterator::AttributeIterator(Inode* inode)
size_t length = sizeof(header);
if (fInode->AttributeBlockReadAt(fOffset, (uint8*)&header, &length) == B_OK
&& length == sizeof(header)) {
header.Dump();
//header.Dump();
if (header.IsValid()) {
fOffset = sizeof(header);
TRACE("AttributeIterator::%s: header valid\n", __FUNCTION__);
@@ -63,7 +63,7 @@ AttributeIterator::GetNext(char* name, size_t* _nameLength, ext2_xattr_entry *_e
status_t status = fInode->AttributeBlockReadAt(fOffset, (uint8*)_entry, &length);
TRACE("AttributeIterator::%s:AttributeBlockReadAt(%Ld): 0x%08lx len %d\n",
__FUNCTION__, fOffset, status, length);
_entry->Dump();
//_entry->Dump();
if (status != B_OK)
return status;
@@ -74,13 +74,6 @@ AttributeIterator::GetNext(char* name, size_t* _nameLength, ext2_xattr_entry *_e
if (!_entry->IsValid())
return B_BAD_DATA;
//XXX dead code:
if (_entry->NameLength() == 0) {
fOffset = 0;
return B_ENTRY_NOT_FOUND;
}
TRACE("xattr block offset %Ld: entry ino %Lu, length %u, name length %u,"
" index %d\n",
fOffset, fInode->ID(), _entry->Length(), _entry->NameLength(),
@@ -101,11 +94,10 @@ AttributeIterator::GetNext(char* name, size_t* _nameLength, ext2_xattr_entry *_e
if (status == B_OK) {
const char *indexNames[] = { "0", "user" };
//name[MIN(length, EXT2_XATTR_NAME_LENGTH - 1)] = '\0';
size_t l;
TRACE("AttributeIterator::%s: len %d nlen %d\n",
__FUNCTION__, length, *_nameLength);
TRACE("AttributeIterator::%s: len %d nlen %d\n",
__FUNCTION__, length, *_nameLength);
if (_entry->NameIndex() < ((sizeof(indexNames) / sizeof(indexNames[0]))))
l = snprintf(name, *_nameLength, "%s.%s.%.*s",
"linux", indexNames[_entry->NameIndex()], length, _entry->name);
@@ -119,22 +111,9 @@ AttributeIterator::GetNext(char* name, size_t* _nameLength, ext2_xattr_entry *_e
name[l] = '\0';
}
//name[*_nameLength++] = '\0';
TRACE("AttributeIterator::%s: name %.*s len %d nlen %d\n",
__FUNCTION__, *_nameLength, name, length, *_nameLength);
TRACE("AttributeIterator::%s: name %.*s len %d nlen %d\n",
__FUNCTION__, *_nameLength, name, length, *_nameLength);
/* length = *_nameLength;
if (*_nameLength < length)
length = *_nameLength - 1;
memcpy(name, _entry->name, length);
name[length] = '\0';
*_entry = entry;
*_nameLength = length;
*/
fOffset += _entry->Length();
}
@@ -1,5 +1,5 @@
/*
* Copyright 2008, Axel Dörfler, [email protected].
* Copyright 2010, François Revol, <[email protected]>.
* This file may be used under the terms of the MIT License.
*/
#ifndef ATTRIBUTE_ITERATOR_H
@@ -26,8 +26,6 @@ public:
status_t Find(const char* name, ext2_xattr_entry *_entry);
//ext2_xattr_entry& Entry() const { return fEntry; }
private:
AttributeIterator(const AttributeIterator&);
AttributeIterator &operator=(const AttributeIterator&);
@@ -39,7 +37,6 @@ private:
private:
Inode* fInode;
off_t fOffset;
//ext2_xattr_entry fEntry;
};
#endif // ATTRIBUTE_ITERATOR_H
@@ -12,7 +12,7 @@
#include "CachedBlock.h"
#define TRACE_EXT2
//#define TRACE_EXT2
#ifdef TRACE_EXT2
# define TRACE(x...) dprintf("\33[34mext2:\33[0m " x)
#else
@@ -217,6 +217,7 @@ Inode::ReadAt(off_t pos, uint8* buffer, size_t* _length)
status_t
Inode::AttributeBlockReadAt(off_t pos, uint8* buffer, size_t* _length)
{
TRACE("Inode::%s(%Ld, , %lu)\n", __FUNCTION__, pos, *_length);
size_t length = *_length;
if (!fAttributesBlock) {
@@ -237,6 +238,7 @@ Inode::AttributeBlockReadAt(off_t pos, uint8* buffer, size_t* _length)
return ERANGE;
memcpy(buffer, ((uint8 *)fAttributesBlock) + (uint32)pos, length);
*_length = length;
return B_NO_ERROR;
}
@@ -614,7 +614,7 @@ ext2_open_attr(fs_volume* _volume, fs_vnode* _node, const char* name,
AttributeIterator i(inode);
status_t status = i.Find(name, entry);
if (status == B_OK) {
entry->Dump();
//entry->Dump();
*_cookie = entry;
return B_OK;
}
@@ -647,7 +647,20 @@ static status_t
ext2_read_attr(fs_volume* _volume, fs_vnode* _node, void* cookie,
off_t pos, void* buffer, size_t* length)
{
return ENOSYS;
TRACE("%s()\n", __FUNCTION__);
Inode* inode = (Inode*)_node->private_node;
Volume* volume = (Volume*)_volume->private_volume;
ext2_xattr_entry *entry = (ext2_xattr_entry *)cookie;
if (!entry->IsValid())
return EINVAL;
if (pos < 0 || (pos + *length) > entry->ValueSize())
return ERANGE;
return inode->AttributeBlockReadAt(entry->ValueOffset() + pos,
(uint8 *)buffer, length);
}
@@ -769,7 +782,7 @@ fs_vnode_ops gExt2VnodeOps = {
&ext2_open_attr,
&ext2_close_attr,
&ext2_free_attr_cookie,
NULL, //&ext2_read_attr,
&ext2_read_attr,
NULL, //&ext2_write_attr,
&ext2_read_attr_stat,
NULL, //&ext2_write_attr_stat,