posixVolume.h 3.3 KB

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