From 29008bcfd8aa94b0d16ad2f259618200b67c42da Mon Sep 17 00:00:00 2001 From: Tyler Dauwalder Date: Mon, 28 Apr 2003 22:47:29 +0000 Subject: [PATCH] Initial checkin. Currently does nothing particularly useful. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3114 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../kernel/file_systems/udf/Volume.cpp | 68 +++++++++++++++++++ src/add-ons/kernel/file_systems/udf/Volume.h | 55 +++++++++++++++ 2 files changed, 123 insertions(+) create mode 100644 src/add-ons/kernel/file_systems/udf/Volume.cpp create mode 100644 src/add-ons/kernel/file_systems/udf/Volume.h diff --git a/src/add-ons/kernel/file_systems/udf/Volume.cpp b/src/add-ons/kernel/file_systems/udf/Volume.cpp new file mode 100644 index 0000000000..95982c7e8b --- /dev/null +++ b/src/add-ons/kernel/file_systems/udf/Volume.cpp @@ -0,0 +1,68 @@ +//---------------------------------------------------------------------- +// This software is part of the OpenBeOS distribution and is covered +// by the OpenBeOS license. +// +// Copyright (c) 2003 Tyler Dauwalder, tyler@dauwalder.net +// Mad props to Axel Dörfler and his BFS implementation, from which +// this UDF implementation draws much influence (and a little code :-P). +//---------------------------------------------------------------------- +#include "Volume.h" + +#include "Block.h" +#include "Debug.h" + +using namespace UDF; + +//---------------------------------------------------------------------- +// Volume +//---------------------------------------------------------------------- + +/*! \brief Creates an unmounted volume with the given id. +*/ +Volume::Volume(nspace_id id) + : fID(id) + , fDevice(0) + , fReadOnly(false) +{ +} + +status_t +Volume::Identify(int device, off_t base) +{ + return B_ERROR; +} + +/*! \brief Attempts to mount the given device. +*/ +status_t +Volume::Mount(const char *deviceName, uint32 flags) +{ + if (!deviceName) + RETURN_ERROR(B_BAD_VALUE); + + fReadOnly = flags & B_READ_ONLY; + + // Open the device, trying read only if readwrite fails + fDevice = open(deviceName, fReadOnly ? O_RDONLY : O_RDWR); + if (fDevice < B_OK && !fReadOnly) { + fReadOnly = true; + fDevice = open(deviceName, O_RDONLY); + } + if (fDevice < B_OK) + RETURN_ERROR(fDevice); + + // If the device is actually a normal file, try to disable the cache + // for the file in the parent filesystem + struct stat stat; + status_t err = fstat(fDevice, &stat) < 0 ? B_OK : B_ERROR; + if (!err) { + if (stat.st_mode & S_IFREG && ioctl(fDevice, IOCTL_FILE_UNCACHED_IO, NULL) < 0) { + // Probably should die some sort of painful death here. + } + } + + // Now identify the volume + + return B_ERROR; +} + diff --git a/src/add-ons/kernel/file_systems/udf/Volume.h b/src/add-ons/kernel/file_systems/udf/Volume.h new file mode 100644 index 0000000000..1f33179a7d --- /dev/null +++ b/src/add-ons/kernel/file_systems/udf/Volume.h @@ -0,0 +1,55 @@ +//---------------------------------------------------------------------- +// This software is part of the OpenBeOS distribution and is covered +// by the OpenBeOS license. +// +// Copyright (c) 2003 Tyler Dauwalder, tyler@dauwalder.net +// Mad props to Axel Dörfler and his BFS implementation, from which +// this UDF implementation draws much influence (and a little code :-P). +//--------------------------------------------------------------------- +#ifndef _UDF_VOLUME_H +#define _UDF_VOLUME_H + +/*! \file Volume.h +*/ + +#include +extern "C" { + #ifndef _IMPEXP_KERNEL + # define _IMPEXP_KERNEL + #endif + + #include +} + +#include "cpp.h" + +namespace UDF { + +class Volume { +public: + Volume(nspace_id id); + + static status_t Identify(int device) { return Identify(device, 0); } + static status_t Identify(int device, off_t base); + + status_t Mount(const char *deviceName, uint32 flags); + status_t Unmount(); + + nspace_id GetID() { return fID; } + + const char *Name() const; + int Device() const { return fDevice; } + + bool IsReadOnly() const { return fReadOnly; } + + vnode_id ToVnodeID(off_t block) const { return (vnode_id)block; } + +private: + nspace_id fID; + int fDevice; + bool fReadOnly; +}; + +}; // namespace UDF + +#endif // _UDF_VOLUME_H