haiku/headers/private/file_systems/DeviceOpener.h
Suhel Mehta d72239d23d Move DeviceOpener class to a separate file.
It is used by several of the filesystems, so it seems a good idea to
move it to the shared/ directory.

UFS2, BFS, XFS, EXT2 and EXFAT are adjusted.

Change-Id: I493e37a1e7d3ae24251469f82befd985a3c1dbdd
Reviewed-on: https://review.haiku-os.org/c/haiku/+/2489
Reviewed-by: Adrien Destugues <pulkomandy@gmail.com>
2020-05-10 08:29:31 +00:00

44 lines
1.1 KiB
C++

/*
* Copyright 2008-2010, Axel Dörfler, axeld@pinc-software.de.
* All rights reserved. Distributed under the terms of the MIT License.
*/
#ifndef DEVICEOPENER_H
#define DEVICEOPENER_H
#include "system_dependencies.h"
class DeviceOpener {
public:
DeviceOpener(int fd, int mode);
DeviceOpener(const char* device, int mode);
~DeviceOpener();
int Open(const char* device, int mode);
int Open(int fd, int mode);
void* InitCache(off_t numBlocks, uint32 blockSize);
void RemoveCache(bool allowWrites);
void Keep();
int Device() const { return fDevice; }
int Mode() const { return fMode; }
bool IsReadOnly() const {
return _IsReadOnly(fMode); }
status_t GetSize(off_t* _size,
uint32* _blockSize = NULL);
private:
static bool _IsReadOnly(int mode)
{ return (mode & O_RWMASK) == O_RDONLY; }
static bool _IsReadWrite(int mode)
{ return (mode & O_RWMASK) == O_RDWR; }
int fDevice;
int fMode;
void* fBlockCache;
};
#endif // DEVICEOPENER_H