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 <[email protected]>
This commit is contained in:
Suhel Mehta
2020-05-10 08:29:31 +00:00
committed by Adrien Destugues
parent e9c3e80c58
commit d72239d23d
19 changed files with 368 additions and 867 deletions
@@ -0,0 +1,43 @@
/*
* Copyright 2008-2010, Axel Dörfler, [email protected].
* 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