posixVolume.h

Engine/source/platformPOSIX/posixVolume.h

More...

Classes:

Namespaces:

namespace
namespace

Detailed Description

  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23
 24#ifndef _POSIXVOLUME_H_
 25#define _POSIXVOLUME_H_
 26
 27#ifndef _VOLUME_H_
 28#include "core/volume.h"
 29#endif
 30
 31#include <stdio.h>
 32#include <sys/stat.h>
 33#include <dirent.h>
 34
 35namespace Torque
 36{
 37using namespace FS;
 38
 39namespace Posix
 40{
 41
 42//-----------------------------------------------------------------------------
 43
 44class PosixFileSystem: public FileSystem
 45{
 46   String _volume;
 47
 48public:
 49   PosixFileSystem(String volume);
 50   ~<a href="/coding/class/classtorque_1_1posix_1_1posixfilesystem/">PosixFileSystem</a>();
 51
 52   String   getTypeStr() const { return "POSIX"; }
 53
 54   FileNodeRef resolve(const Path& path);
 55   FileNodeRef create(const Path& path,FileNode::Mode);
 56   bool remove(const Path& path);
 57   bool rename(const Path& from,const Path& to);
 58   Path mapTo(const Path& path);
 59   Path mapFrom(const Path& path);
 60};
 61
 62
 63//-----------------------------------------------------------------------------
 64/// Posix stdio file access.
 65/// This class makes use the fopen, fread and fwrite for buffered io.
 66class PosixFile: public File
 67{
 68   friend class PosixFileSystem;
 69   Path _path;
 70   String _name;
 71   FILE* _handle;
 72   NodeStatus _status;
 73
 74   PosixFile(const Path& path,String name);
 75   bool _updateInfo();
 76   void _updateStatus();
 77
 78public:
 79   ~<a href="/coding/class/classtorque_1_1posix_1_1posixfile/">PosixFile</a>();
 80
 81   Path getName() const;
 82   NodeStatus getStatus() const;
 83   bool getAttributes(Attributes*);
 84
 85   U32 getPosition();
 86   U32 setPosition(U32,SeekMode);
 87
 88   bool open(AccessMode);
 89   bool close();
 90
 91   U32 read(void* dst, U32 size);
 92   U32 write(const void* src, U32 size);
 93
 94private:
 95   U32 calculateChecksum();
 96};
 97
 98
 99//-----------------------------------------------------------------------------
100
101class PosixDirectory: public Directory
102{
103   friend class PosixFileSystem;
104   Path _path;
105   String _name;
106   DIR* _handle;
107   NodeStatus _status;
108
109   PosixDirectory(const Path& path,String name);
110   void _updateStatus();
111
112public:
113   ~<a href="/coding/class/classtorque_1_1posix_1_1posixdirectory/">PosixDirectory</a>();
114
115   Path getName() const;
116   NodeStatus getStatus() const;
117   bool getAttributes(Attributes*);
118
119   bool open();
120   bool close();
121   bool read(Attributes*);
122
123private:
124   U32 calculateChecksum();
125};
126
127
128} // Namespace
129} // Namespace
130#endif
131