root/src/add-ons/kernel/file_systems/packagefs/nodes/UnpackingLeafNode.h
/*
 * Copyright 2009-2013, Ingo Weinhold, ingo_weinhold@gmx.de.
 * Distributed under the terms of the MIT License.
 */
#ifndef LEAF_NODE_H
#define LEAF_NODE_H


#include "Node.h"
#include "PackageLeafNode.h"
#include "UnpackingNode.h"


class UnpackingLeafNode final : public Node, public UnpackingNode {
public:
        static  void*                           operator new(size_t size);
        static  void                            operator delete(void* block);

                                                                UnpackingLeafNode(ino_t id);
        virtual                                         ~UnpackingLeafNode();

        virtual status_t                        VFSInit(dev_t deviceID);
        virtual void                            VFSUninit();

        virtual mode_t                          Mode() const;
        virtual uid_t                           UserID() const;
        virtual gid_t                           GroupID() const;
        virtual timespec                        ModifiedTime() const;
        virtual off_t                           FileSize() const;

        virtual Node*                           GetNode();

        virtual status_t                        AddPackageNode(PackageNode* packageNode,
                                                                        dev_t deviceID);
        virtual void                            RemovePackageNode(PackageNode* packageNode,
                                                                        dev_t deviceID);

        virtual PackageNode*            GetPackageNode();
        virtual bool                            IsOnlyPackageNode(PackageNode* node) const;
        virtual bool                            WillBeFirstPackageNode(
                                                                        PackageNode* packageNode) const;

        virtual void                            PrepareForRemoval();
        virtual status_t                        CloneTransferPackageNodes(ino_t id,
                                                                        UnpackingNode*& _newNode);

        virtual status_t                        Read(off_t offset, void* buffer,
                                                                        size_t* bufferSize);
        virtual status_t                        Read(io_request* request);

        virtual status_t                        ReadSymlink(void* buffer,
                                                                        size_t* bufferSize);

        virtual status_t                        OpenAttributeDirectory(
                                                                        AttributeDirectoryCookie*& _cookie);
        virtual status_t                        OpenAttribute(const StringKey& name,
                                                                        int openMode, AttributeCookie*& _cookie);

        virtual status_t                        IndexAttribute(AttributeIndexer* indexer);
        virtual void*                           IndexCookieForAttribute(const StringKey& name)
                                                                        const;

private:
        inline  PackageLeafNode*        _ActivePackageNode() const;

private:
                        PackageLeafNodeList     fPackageNodes;
                        PackageLeafNode*        fFinalPackageNode;
};


#endif  // LEAF_NODE_H