File indexing completed on 2023-03-17 11:26:53
0001 #ifndef STORAGE_FACTORY_FILE_H
0002 #define STORAGE_FACTORY_FILE_H
0003
0004 #include "Utilities/StorageFactory/interface/IOTypes.h"
0005 #include "Utilities/StorageFactory/interface/IOFlags.h"
0006 #include "Utilities/StorageFactory/interface/Storage.h"
0007 #include <string>
0008
0009 namespace edm::storage {
0010
0011
0012 class File : public Storage {
0013 public:
0014 File();
0015 File(IOFD fd, bool autoclose = true);
0016 File(const char *name, int flags = IOFlags::OpenRead, int perms = 0666);
0017 File(const std::string &name, int flags = IOFlags::OpenRead, int perms = 0666);
0018 ~File() override;
0019
0020
0021
0022 virtual void create(const char *name, bool exclusive = false, int perms = 0666);
0023 virtual void create(const std::string &name, bool exclusive = false, int perms = 0666);
0024 virtual void open(const char *name, int flags = IOFlags::OpenRead, int perms = 0666);
0025 virtual void open(const std::string &name, int flags = IOFlags::OpenRead, int perms = 0666);
0026 virtual void attach(IOFD fd);
0027
0028 using Storage::position;
0029 using Storage::read;
0030 using Storage::readv;
0031 using Storage::write;
0032 using Storage::writev;
0033
0034 IOFD fd() const { return m_fd; }
0035
0036 bool prefetch(const IOPosBuffer *what, IOSize n) override;
0037 IOSize read(void *into, IOSize n) override;
0038 IOSize read(void *into, IOSize n, IOOffset pos) override;
0039 IOSize readv(IOBuffer *into, IOSize length) override;
0040
0041 IOSize write(const void *from, IOSize n) override;
0042 IOSize write(const void *from, IOSize n, IOOffset pos) override;
0043 IOSize writev(const IOBuffer *from, IOSize length) override;
0044
0045 IOOffset size() const override;
0046 IOOffset position(IOOffset offset, Relative whence = SET) override;
0047
0048 void resize(IOOffset size) override;
0049
0050 void flush() override;
0051 void close() override;
0052 virtual void abort();
0053
0054 virtual void setAutoClose(bool closeit);
0055
0056 private:
0057 enum { InternalAutoClose = 4096 };
0058
0059 File(IOFD fd, unsigned flags);
0060
0061 IOSize syswrite(const void *from, IOSize n);
0062 IOSize syswritev(const IOBuffer *from, IOSize length);
0063
0064 File *duplicate(bool copy) const;
0065 File *duplicate(File *child) const;
0066 static IOFD sysduplicate(IOFD fd);
0067 static void sysopen(const char *name, int flags, int perms, IOFD &newfd, unsigned &newflags);
0068 static bool sysclose(IOFD fd, int *error = nullptr);
0069
0070 IOFD m_fd = EDM_IOFD_INVALID;
0071 unsigned m_flags;
0072 };
0073 }
0074 #endif