* Style cleanup, no functional change.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38430 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2010-08-29 21:25:12 +00:00
parent 977f0426ee
commit 001d7548ab
@@ -1,11 +1,12 @@
/* /*
* Copyright 2009, Haiku Inc. All rights reserved. * Copyright 2009-2010, Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Michael Lotz <[email protected]> * Michael Lotz <[email protected]>
*/ */
#include <new> #include <new>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@@ -24,16 +25,35 @@
//#define TRACE_OVERLAY //#define TRACE_OVERLAY
#ifdef TRACE_OVERLAY #ifdef TRACE_OVERLAY
#define TRACE(x...) dprintf("attribute_overlay: " x) # define TRACE(x...) dprintf("attribute_overlay: " x)
#define TRACE_VOLUME(x...) dprintf("attribute_overlay: " x) # define TRACE_VOLUME(x...) dprintf("attribute_overlay: " x)
#define TRACE_ALWAYS(x...) dprintf("attribute_overlay: " x) # define TRACE_ALWAYS(x...) dprintf("attribute_overlay: " x)
#else #else
#define TRACE(x...) /* nothing */ # define TRACE(x...) /* nothing */
#define TRACE_VOLUME(x...) /* nothing */ # define TRACE_VOLUME(x...) /* nothing */
#define TRACE_ALWAYS(x...) dprintf("attribute_overlay: " x) # define TRACE_ALWAYS(x...) dprintf("attribute_overlay: " x)
#endif #endif
#define ATTRIBUTE_OVERLAY_FILE_MAGIC 'attr'
#define ATTRIBUTE_OVERLAY_ATTRIBUTE_DIR_NAME "_HAIKU"
#define OVERLAY_CALL(op, params...) \
TRACE("relaying op: " #op "\n"); \
OverlayInode *node = (OverlayInode *)vnode->private_node; \
fs_vnode *superVnode = node->SuperVnode(); \
if (superVnode->ops->op != NULL) \
return superVnode->ops->op(volume->super_volume, superVnode, params); \
return B_UNSUPPORTED;
#define OVERLAY_VOLUME_CALL(op, params...) \
TRACE_VOLUME("relaying volume op: " #op "\n"); \
if (volume->super_volume->ops->op != NULL) \
return volume->super_volume->ops->op(volume->super_volume, params);
namespace attribute_overlay { namespace attribute_overlay {
class AttributeFile; class AttributeFile;
@@ -86,108 +106,108 @@ private:
class AttributeFile { class AttributeFile {
public: public:
AttributeFile(fs_volume *overlay, fs_volume *volume, AttributeFile(fs_volume *overlay,
fs_vnode *vnode); fs_volume *volume, fs_vnode *vnode);
~AttributeFile(); ~AttributeFile();
status_t InitCheck() { return fStatus; } status_t InitCheck() { return fStatus; }
dev_t VolumeID() { return fVolumeID; } dev_t VolumeID() { return fVolumeID; }
ino_t FileInode() { return fFileInode; } ino_t FileInode() { return fFileInode; }
status_t CreateEmpty(); status_t CreateEmpty();
status_t WriteAttributeFile(fs_volume *overlay, status_t WriteAttributeFile(fs_volume *overlay,
fs_volume *volume, fs_vnode *vnode); fs_volume *volume, fs_vnode *vnode);
status_t RemoveAttributeFile(fs_volume *overlay, status_t RemoveAttributeFile(fs_volume *overlay,
fs_volume *volume, fs_vnode *vnode); fs_volume *volume, fs_vnode *vnode);
status_t ReadAttributeDir(struct dirent *dirent, status_t ReadAttributeDir(struct dirent *dirent,
size_t bufferSize, uint32 *numEntries, size_t bufferSize, uint32 *numEntries,
uint32 *index); uint32 *index);
uint32 CountAttributes(); uint32 CountAttributes();
AttributeEntry * FindAttribute(const char *name, AttributeEntry * FindAttribute(const char *name,
uint32 *index = NULL); uint32 *index = NULL);
status_t CreateAttribute(const char *name, type_code type, status_t CreateAttribute(const char *name, type_code type,
int openMode, AttributeEntry **entry); int openMode, AttributeEntry **entry);
status_t OpenAttribute(const char *name, int openMode, status_t OpenAttribute(const char *name, int openMode,
AttributeEntry **entry); AttributeEntry **entry);
status_t RemoveAttribute(const char *name, status_t RemoveAttribute(const char *name,
AttributeEntry **entry); AttributeEntry **entry);
status_t AddAttribute(AttributeEntry *entry); status_t AddAttribute(AttributeEntry *entry);
private: private:
#define ATTRIBUTE_OVERLAY_FILE_MAGIC 'attr' struct attribute_file {
#define ATTRIBUTE_OVERLAY_ATTRIBUTE_DIR_NAME "_HAIKU" uint32 magic;
// ATTRIBUTE_OVERLAY_FILE_MAGIC
uint32 entry_count;
uint8 entries[1];
} _PACKED;
struct attribute_file { status_t fStatus;
uint32 magic; // 'attr' dev_t fVolumeID;
uint32 entry_count; ino_t fFileInode;
uint8 entries[1]; ino_t fDirectoryInode;
} _PACKED; ino_t fAttributeDirInode;
ino_t fAttributeFileInode;
status_t fStatus; attribute_file * fFile;
dev_t fVolumeID; uint32 fAttributeDirIndex;
ino_t fFileInode; AttributeEntry ** fEntries;
ino_t fDirectoryInode;
ino_t fAttributeDirInode;
ino_t fAttributeFileInode;
attribute_file * fFile;
uint32 fAttributeDirIndex;
AttributeEntry ** fEntries;
}; };
class AttributeEntry { class AttributeEntry {
public: public:
AttributeEntry(AttributeFile *parent, AttributeEntry(AttributeFile *parent,
uint8 *buffer); uint8 *buffer);
AttributeEntry(AttributeFile *parent, AttributeEntry(AttributeFile *parent,
const char *name, type_code type); const char *name, type_code type);
~AttributeEntry(); ~AttributeEntry();
status_t InitCheck() { return fStatus; } status_t InitCheck() { return fStatus; }
uint8 * Entry() { return (uint8 *)fEntry; } uint8 * Entry() { return (uint8 *)fEntry; }
size_t EntrySize(); size_t EntrySize();
uint8 * Data() { return fData; } uint8 * Data() { return fData; }
size_t DataSize() { return fEntry->size; } size_t DataSize() { return fEntry->size; }
status_t SetType(type_code type); status_t SetType(type_code type);
type_code Type() { return fEntry->type; } type_code Type() { return fEntry->type; }
status_t SetSize(size_t size); status_t SetSize(size_t size);
uint32 Size() { return fEntry->size; } uint32 Size() { return fEntry->size; }
status_t SetName(const char *name); status_t SetName(const char *name);
const char * Name() { return fEntry->name; } const char * Name() { return fEntry->name; }
uint8 NameLength() { return fEntry->name_length; } uint8 NameLength() { return fEntry->name_length; }
status_t FillDirent(struct dirent *dirent, status_t FillDirent(struct dirent *dirent,
size_t bufferSize, uint32 *numEntries); size_t bufferSize, uint32 *numEntries);
status_t Read(off_t position, void *buffer, size_t *length); status_t Read(off_t position, void *buffer,
status_t Write(off_t position, const void *buffer, size_t *length);
size_t *length); status_t Write(off_t position, const void *buffer,
size_t *length);
status_t ReadStat(struct stat *stat); status_t ReadStat(struct stat *stat);
status_t WriteStat(const struct stat *stat, uint32 statMask); status_t WriteStat(const struct stat *stat,
uint32 statMask);
private: private:
struct attribute_entry { struct attribute_entry {
type_code type; type_code type;
uint32 size; uint32 size;
uint8 name_length; // including 0 byte uint8 name_length; // including 0 byte
char name[1]; // 0 terminated, followed by data char name[1]; // 0 terminated, followed by data
} _PACKED; } _PACKED;
AttributeFile * fParent; AttributeFile * fParent;
attribute_entry * fEntry; attribute_entry * fEntry;
uint8 * fData; uint8 * fData;
status_t fStatus; status_t fStatus;
bool fAllocatedEntry; bool fAllocatedEntry;
bool fAllocatedData; bool fAllocatedData;
}; };
@@ -195,7 +215,8 @@ private:
OverlayVolume::OverlayVolume(fs_volume *volume) OverlayVolume::OverlayVolume(fs_volume *volume)
: fVolume(volume) :
fVolume(volume)
{ {
} }
@@ -210,10 +231,11 @@ OverlayVolume::~OverlayVolume()
OverlayInode::OverlayInode(OverlayVolume *volume, fs_vnode *superVnode, OverlayInode::OverlayInode(OverlayVolume *volume, fs_vnode *superVnode,
ino_t inodeNumber) ino_t inodeNumber)
: fVolume(volume), :
fSuperVnode(*superVnode), fVolume(volume),
fInodeNumber(inodeNumber), fSuperVnode(*superVnode),
fAttributeFile(NULL) fInodeNumber(inodeNumber),
fAttributeFile(NULL)
{ {
TRACE("inode created\n"); TRACE("inode created\n");
} }
@@ -297,15 +319,16 @@ OverlayInode::RemoveAttributeFile()
AttributeFile::AttributeFile(fs_volume *overlay, fs_volume *volume, AttributeFile::AttributeFile(fs_volume *overlay, fs_volume *volume,
fs_vnode *vnode) fs_vnode *vnode)
: fStatus(B_NO_INIT), :
fVolumeID(volume->id), fStatus(B_NO_INIT),
fFileInode(0), fVolumeID(volume->id),
fDirectoryInode(0), fFileInode(0),
fAttributeDirInode(0), fDirectoryInode(0),
fAttributeFileInode(0), fAttributeDirInode(0),
fFile(NULL), fAttributeFileInode(0),
fAttributeDirIndex(0), fFile(NULL),
fEntries(NULL) fAttributeDirIndex(0),
fEntries(NULL)
{ {
if (vnode->ops->get_vnode_name == NULL) { if (vnode->ops->get_vnode_name == NULL) {
TRACE_ALWAYS("cannot get vnode name, hook missing\n"); TRACE_ALWAYS("cannot get vnode name, hook missing\n");
@@ -604,16 +627,18 @@ AttributeFile::WriteAttributeFile(fs_volume *overlay, fs_volume *volume,
return result; return result;
} }
result = get_vnode(overlay, fAttributeFileInode, (void **)&overlayInode); result = get_vnode(overlay, fAttributeFileInode,
(void **)&overlayInode);
if (result != B_OK) { if (result != B_OK) {
TRACE_ALWAYS("getting attribute file vnode after create failed: %s\n", TRACE_ALWAYS("getting attribute file vnode after create failed: "
strerror(result)); "%s\n", strerror(result));
return result; return result;
} }
currentVnode = *overlayInode->SuperVnode(); currentVnode = *overlayInode->SuperVnode();
} else { } else {
result = get_vnode(overlay, fAttributeFileInode, (void **)&overlayInode); result = get_vnode(overlay, fAttributeFileInode,
(void **)&overlayInode);
if (result != B_OK) { if (result != B_OK) {
TRACE_ALWAYS("getting attribute file vnode failed: %s\n", TRACE_ALWAYS("getting attribute file vnode failed: %s\n",
strerror(result)); strerror(result));
@@ -741,7 +766,8 @@ AttributeEntry *
AttributeFile::FindAttribute(const char *name, uint32 *index) AttributeFile::FindAttribute(const char *name, uint32 *index)
{ {
for (uint32 i = 0; i < fFile->entry_count; i++) { for (uint32 i = 0; i < fFile->entry_count; i++) {
if (strncmp(fEntries[i]->Name(), name, fEntries[i]->NameLength()) == 0) { if (strncmp(fEntries[i]->Name(), name, fEntries[i]->NameLength())
== 0) {
if (index) if (index)
*index = i; *index = i;
@@ -759,7 +785,7 @@ AttributeFile::CreateAttribute(const char *name, type_code type, int openMode,
{ {
AttributeEntry *existing = FindAttribute(name); AttributeEntry *existing = FindAttribute(name);
if (existing != NULL) { if (existing != NULL) {
if (openMode & O_TRUNC) if ((openMode & O_TRUNC) != 0)
existing->SetSize(0); existing->SetSize(0);
// attribute already exists, only allow if the attribute type is // attribute already exists, only allow if the attribute type is
@@ -875,12 +901,13 @@ AttributeFile::ReadAttributeDir(struct dirent *dirent, size_t bufferSize,
AttributeEntry::AttributeEntry(AttributeFile *parent, uint8 *buffer) AttributeEntry::AttributeEntry(AttributeFile *parent, uint8 *buffer)
: fParent(parent), :
fEntry(NULL), fParent(parent),
fData(NULL), fEntry(NULL),
fStatus(B_NO_INIT), fData(NULL),
fAllocatedEntry(false), fStatus(B_NO_INIT),
fAllocatedData(false) fAllocatedEntry(false),
fAllocatedData(false)
{ {
if (buffer == NULL) if (buffer == NULL)
return; return;
@@ -893,12 +920,13 @@ AttributeEntry::AttributeEntry(AttributeFile *parent, uint8 *buffer)
AttributeEntry::AttributeEntry(AttributeFile *parent, const char *name, AttributeEntry::AttributeEntry(AttributeFile *parent, const char *name,
type_code type) type_code type)
: fParent(parent), :
fEntry(NULL), fParent(parent),
fData(NULL), fEntry(NULL),
fStatus(B_NO_INIT), fData(NULL),
fAllocatedEntry(false), fStatus(B_NO_INIT),
fAllocatedData(false) fAllocatedEntry(false),
fAllocatedData(false)
{ {
fStatus = SetName(name); fStatus = SetName(name);
if (fStatus != B_OK) if (fStatus != B_OK)
@@ -1075,15 +1103,6 @@ AttributeEntry::WriteStat(const struct stat *stat, uint32 statMask)
// #pragma mark - vnode ops // #pragma mark - vnode ops
#define OVERLAY_CALL(op, params...) \
TRACE("relaying op: " #op "\n"); \
OverlayInode *node = (OverlayInode *)vnode->private_node; \
fs_vnode *superVnode = node->SuperVnode(); \
if (superVnode->ops->op != NULL) \
return superVnode->ops->op(volume->super_volume, superVnode, params); \
return B_UNSUPPORTED;
static status_t static status_t
overlay_put_vnode(fs_volume *volume, fs_vnode *vnode, bool reenter) overlay_put_vnode(fs_volume *volume, fs_vnode *vnode, bool reenter)
{ {
@@ -1624,7 +1643,8 @@ overlay_create_special_node(fs_volume *volume, fs_vnode *vnode,
const char *name, fs_vnode *subVnode, mode_t mode, uint32 flags, const char *name, fs_vnode *subVnode, mode_t mode, uint32 flags,
fs_vnode *_superVnode, ino_t *nodeID) fs_vnode *_superVnode, ino_t *nodeID)
{ {
OVERLAY_CALL(create_special_node, name, subVnode, mode, flags, _superVnode, nodeID) OVERLAY_CALL(create_special_node, name, subVnode, mode, flags, _superVnode,
nodeID)
} }
@@ -1707,12 +1727,6 @@ static fs_vnode_ops sOverlayVnodeOps = {
// #pragma mark - volume ops // #pragma mark - volume ops
#define OVERLAY_VOLUME_CALL(op, params...) \
TRACE_VOLUME("relaying volume op: " #op "\n"); \
if (volume->super_volume->ops->op != NULL) \
return volume->super_volume->ops->op(volume->super_volume, params);
static status_t static status_t
overlay_unmount(fs_volume *volume) overlay_unmount(fs_volume *volume)
{ {
@@ -2004,7 +2018,7 @@ overlay_std_ops(int32 op, ...)
static file_system_module_info sOverlayFileSystem = { static file_system_module_info sOverlayFileSystem = {
{ {
"file_systems/attribute_overlay"B_CURRENT_FS_API_VERSION, "file_systems/attribute_overlay" B_CURRENT_FS_API_VERSION,
0, 0,
overlay_std_ops, overlay_std_ops,
}, },