#pragma region CPL License /* Nuclex Native Framework Copyright (C) 2002-2013 Nuclex Development Labs This library is free software; you can redistribute it and/or modify it under the terms of the IBM Common Public License as published by the IBM Corporation; either version 1.0 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the IBM Common Public License for more details. You should have received a copy of the IBM Common Public License along with this library */ #pragma endregion // CPL License #ifndef NUCLEX_STORAGE_FILESYSTEM_LINUXFILE_H #define NUCLEX_STORAGE_FILESYSTEM_LINUXFILE_H #include "Nuclex/Storage/Config.h" #if defined(NUCLEX_STORAGE_LINUX) #include "Nuclex/Storage/FileSystem/File.h" #include #include namespace Nuclex { namespace Storage { namespace FileSystem { // ------------------------------------------------------------------------------------------- // /// File on a Linux system class LinuxFile : public File { /// Accesses a file on Linux /// Path of the file that will be opened or created public: LinuxFile(const std::string &path); /// Frees all resources owned by the instance public: virtual ~LinuxFile(); /// Determines the size of the file /// The size of the file in bytes public: std::uint64_t GetSize() const; /// Returns the name of the file /// The file's name public: const std::string &GetName() const { return this->name; } /// Returns the path the file is stored at in the native format /// The file's absolute path in the native OS format public: const std::string &GetNativePath() const { return this->path; } /// Reads raw data from the file /// Absolute file position data will be read from /// Buffer into which data will be read /// Number of bytes that will be read public: void ReadAt( std::uint64_t location, void *buffer, std::size_t count ) const; /// Writes raw data into the file /// Absolute file position data will be written to /// Buffer from which data will be taken /// Number of bytes that will be written public: void WriteAt( std::uint64_t location, const void *buffer, std::size_t count ); /// Ensures changes to the file have been written to disk public: void Flush(); /// Closes the file private: void close(); /// Handle of the opened file for Windows' file functions private: mutable int fileHandle; /// Synchronize file accesses from multiple threads /// /// This is required because the Windows file implementation still forces /// a file cursor upon us. Opening multiple file handles would only inrease /// complexity when the underlying hardware cannot do parallel reads anyway. /// private: mutable std::mutex mutex; /// Whether the file is currently opened for writing private: mutable bool isOpenedWritable; /// Absolute path of the file private: std::string path; /// The file's name private: std::string name; }; // ------------------------------------------------------------------------------------------- // }}} // namespace Nuclex::Storage::FileSystem #endif // defined(NUCLEX_STORAGE_LINUX) #endif // NUCLEX_STORAGE_FILESYSTEM_GENERICWINDOWSFILE_H