* Partially ported Volume.cpp. Some stuff is still comment out.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27024 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,11 +1,9 @@
|
|||||||
//----------------------------------------------------------------------
|
/*
|
||||||
// This software is part of the OpenBeOS distribution and is covered
|
* Copyright 2008, Salvatore Benedetto, [email protected]
|
||||||
// by the OpenBeOS license.
|
* Copyright 2003, Tyler Dauwalder, [email protected].
|
||||||
//
|
* Distributed under the terms of the MIT License.
|
||||||
// Copyright (c) 2003 Tyler Dauwalder, [email protected]
|
*/
|
||||||
// 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 "Volume.h"
|
||||||
|
|
||||||
#include "Icb.h"
|
#include "Icb.h"
|
||||||
@@ -13,19 +11,19 @@
|
|||||||
#include "PhysicalPartition.h"
|
#include "PhysicalPartition.h"
|
||||||
#include "Recognition.h"
|
#include "Recognition.h"
|
||||||
|
|
||||||
using namespace Udf;
|
|
||||||
|
|
||||||
/*! \brief Creates an unmounted volume with the given id.
|
/*! \brief Creates an unmounted volume with the given id. */
|
||||||
*/
|
Volume::Volume(fs_volume *fsVolume)
|
||||||
Volume::Volume(nspace_id id)
|
:
|
||||||
: fId(id)
|
fBlockCache(NULL),
|
||||||
, fDevice(-1)
|
fBlockShift(0),
|
||||||
, fMounted(false)
|
fBlockSize(0),
|
||||||
, fOffset(0)
|
fDevice(-1),
|
||||||
, fLength(0)
|
fFSVolume(fsVolume),
|
||||||
, fBlockSize(0)
|
fLength(0),
|
||||||
, fBlockShift(0)
|
fMounted(false),
|
||||||
, fRootIcb(NULL)
|
fOffset(0),
|
||||||
|
fRootIcb(NULL)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < UDF_MAX_PARTITION_MAPS; i++)
|
for (int i = 0; i < UDF_MAX_PARTITION_MAPS; i++)
|
||||||
fPartitions[i] = NULL;
|
fPartitions[i] = NULL;
|
||||||
@@ -39,15 +37,15 @@ Volume::~Volume()
|
|||||||
/*! \brief Attempts to mount the given device.
|
/*! \brief Attempts to mount the given device.
|
||||||
|
|
||||||
\param volumeStart The block on the given device whereat the volume begins.
|
\param volumeStart The block on the given device whereat the volume begins.
|
||||||
\param volumeLength The block length of the volume on the given device.
|
\param volumeLength The block numBlocks of the volume on the given device.
|
||||||
*/
|
*/
|
||||||
status_t
|
status_t
|
||||||
Volume::Mount(const char *deviceName, off_t offset, off_t length,
|
Volume::Mount(const char *deviceName, off_t offset, off_t numBlocks,
|
||||||
uint32 blockSize, uint32 flags)
|
uint32 blockSize, uint32 flags)
|
||||||
{
|
{
|
||||||
DEBUG_INIT_ETC("Volume",
|
DEBUG_INIT_ETC("Volume",
|
||||||
("deviceName: `%s', offset: %Ld, length: %Ld, blockSize: %ld, "
|
("deviceName: `%s', offset: %Ld, numBlocks: %Ld, blockSize: %ld, "
|
||||||
"flags: %ld", deviceName, offset, length, blockSize, flags));
|
"flags: %ld", deviceName, offset, numBlocks, blockSize, flags));
|
||||||
if (!deviceName)
|
if (!deviceName)
|
||||||
RETURN(B_BAD_VALUE);
|
RETURN(B_BAD_VALUE);
|
||||||
if (Mounted()) {
|
if (Mounted()) {
|
||||||
@@ -64,7 +62,7 @@ Volume::Mount(const char *deviceName, off_t offset, off_t length,
|
|||||||
|
|
||||||
// If the device is actually a normal file, try to disable the cache
|
// If the device is actually a normal file, try to disable the cache
|
||||||
// for the file in the parent filesystem
|
// for the file in the parent filesystem
|
||||||
#if _KERNEL_MODE
|
#if 0 // _KERNEL_MODE
|
||||||
struct stat stat;
|
struct stat stat;
|
||||||
error = fstat(device, &stat) < 0 ? B_ERROR : B_OK;
|
error = fstat(device, &stat) < 0 ? B_ERROR : B_OK;
|
||||||
if (!error) {
|
if (!error) {
|
||||||
@@ -75,19 +73,19 @@ Volume::Mount(const char *deviceName, off_t offset, off_t length,
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
logical_volume_descriptor logicalVolumeDescriptor;
|
logical_volume_descriptor logicalVolumeDescriptor;
|
||||||
partition_descriptor partitionDescriptors[Udf::kMaxPartitionDescriptors];
|
partition_descriptor partitionDescriptors[kMaxPartitionDescriptors];
|
||||||
uint8 partitionDescriptorCount;
|
uint8 partitionDescriptorCount;
|
||||||
uint32 blockShift;
|
uint32 blockShift;
|
||||||
|
|
||||||
// Run through the volume recognition and descriptor sequences to
|
// Run through the volume recognition and descriptor sequences to
|
||||||
// see if we have a potentially valid UDF volume on our hands
|
// see if we have a potentially valid UDF volume on our hands
|
||||||
error = udf_recognize(device, offset, length, blockSize, blockShift,
|
//error = udf_recognize(device, offset, numBlocks, blockSize, blockShift,
|
||||||
logicalVolumeDescriptor, partitionDescriptors,
|
// logicalVolumeDescriptor, partitionDescriptors,
|
||||||
partitionDescriptorCount);
|
// partitionDescriptorCount);
|
||||||
|
|
||||||
// Set up the block cache
|
// Set up the block cache
|
||||||
if (!error)
|
if (!error)
|
||||||
error = init_cache_for_device(device, length);
|
fBlockCache = block_cache_create(device, numBlocks, blockSize, IsReadOnly());
|
||||||
|
|
||||||
int physicalCount = 0;
|
int physicalCount = 0;
|
||||||
int virtualCount = 0;
|
int virtualCount = 0;
|
||||||
@@ -128,7 +126,7 @@ Volume::Mount(const char *deviceName, off_t offset, off_t length,
|
|||||||
error = partition ? B_OK : B_NO_MEMORY;
|
error = partition ? B_OK : B_NO_MEMORY;
|
||||||
if (!error) {
|
if (!error) {
|
||||||
PRINT(("Adding PhysicalPartition(number: %d, start: %ld, "
|
PRINT(("Adding PhysicalPartition(number: %d, start: %ld, "
|
||||||
"length: %ld)\n", map->partition_number(),
|
"numBlocks: %ld)\n", map->partition_number(),
|
||||||
descriptor->start(), descriptor->length()));
|
descriptor->start(), descriptor->length()));
|
||||||
error = _SetPartition(i, partition);
|
error = _SetPartition(i, partition);
|
||||||
if (!error)
|
if (!error)
|
||||||
@@ -197,7 +195,7 @@ Volume::Mount(const char *deviceName, off_t offset, off_t length,
|
|||||||
if (!error) {
|
if (!error) {
|
||||||
fDevice = device;
|
fDevice = device;
|
||||||
fOffset = offset;
|
fOffset = offset;
|
||||||
fLength = length;
|
fLength = numBlocks;
|
||||||
fBlockSize = blockSize;
|
fBlockSize = blockSize;
|
||||||
fBlockShift = blockShift;
|
fBlockShift = blockShift;
|
||||||
}
|
}
|
||||||
@@ -242,7 +240,7 @@ Volume::Mount(const char *deviceName, off_t offset, off_t length,
|
|||||||
error = fRootIcb ? fRootIcb->InitCheck() : B_NO_MEMORY;
|
error = fRootIcb ? fRootIcb->InitCheck() : B_NO_MEMORY;
|
||||||
}
|
}
|
||||||
if (!error) {
|
if (!error) {
|
||||||
error = new_vnode(Id(), RootIcb()->Id(), (void*)RootIcb());
|
//error = new_vnode(fFSVolume->Id(), RootIcb()->Id(), (void*)RootIcb());
|
||||||
if (error) {
|
if (error) {
|
||||||
PRINT(("Error creating vnode for root icb! "
|
PRINT(("Error creating vnode for root icb! "
|
||||||
"error = 0x%lx, `%s'\n", error,
|
"error = 0x%lx, `%s'\n", error,
|
||||||
@@ -301,9 +299,9 @@ void
|
|||||||
Volume::_Unset()
|
Volume::_Unset()
|
||||||
{
|
{
|
||||||
DEBUG_INIT("Volume");
|
DEBUG_INIT("Volume");
|
||||||
fId = 0;
|
fFSVolume->id = 0;
|
||||||
if (fDevice >= 0) {
|
if (fDevice >= 0) {
|
||||||
remove_cached_device_blocks(fDevice, NO_WRITES);
|
block_cache_delete(fBlockCache, true);
|
||||||
close(fDevice);
|
close(fDevice);
|
||||||
}
|
}
|
||||||
fDevice = -1;
|
fDevice = -1;
|
||||||
@@ -340,10 +338,9 @@ Volume::_SetPartition(uint number, Partition *partition)
|
|||||||
/*! \brief Returns the partition associated with the given number, or
|
/*! \brief Returns the partition associated with the given number, or
|
||||||
NULL if no such partition exists or the number is invalid.
|
NULL if no such partition exists or the number is invalid.
|
||||||
*/
|
*/
|
||||||
Udf::Partition*
|
Partition*
|
||||||
Volume::_GetPartition(uint number)
|
Volume::_GetPartition(uint number)
|
||||||
{
|
{
|
||||||
return (number < UDF_MAX_PARTITION_MAPS)
|
return (number < UDF_MAX_PARTITION_MAPS)
|
||||||
? fPartitions[number] : NULL;
|
? fPartitions[number] : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,90 +1,74 @@
|
|||||||
//----------------------------------------------------------------------
|
/*
|
||||||
// This software is part of the OpenBeOS distribution and is covered
|
* Copyright 2008, Salvatore Benedetto, [email protected]
|
||||||
// by the OpenBeOS license.
|
* Copyright 2003, Tyler Dauwalder, [email protected].
|
||||||
//
|
* Distributed under the terms of the MIT License.
|
||||||
// Copyright (c) 2003 Tyler Dauwalder, [email protected]
|
*/
|
||||||
// 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
|
#ifndef _UDF_VOLUME_H
|
||||||
#define _UDF_VOLUME_H
|
#define _UDF_VOLUME_H
|
||||||
|
|
||||||
/*! \file Volume.h
|
/*! \file Volume.h */
|
||||||
*/
|
|
||||||
|
|
||||||
|
#include <fs_info.h>
|
||||||
|
#include <fs_interface.h>
|
||||||
#include <KernelExport.h>
|
#include <KernelExport.h>
|
||||||
#ifndef _IMPEXP_KERNEL
|
|
||||||
# define _IMPEXP_KERNEL
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef COMPILE_FOR_R5
|
#include <util/kernel_cpp.h>
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
#include "fsproto.h"
|
|
||||||
#ifdef COMPILE_FOR_R5
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "kernel_cpp.h"
|
#include <dirent.h>
|
||||||
#include "UdfDebug.h"
|
|
||||||
|
|
||||||
#include "UdfString.h"
|
#include "UdfString.h"
|
||||||
#include "UdfStructures.h"
|
#include "UdfStructures.h"
|
||||||
#include "Partition.h"
|
#include "Partition.h"
|
||||||
|
|
||||||
namespace Udf {
|
|
||||||
|
|
||||||
class Icb;
|
class Icb;
|
||||||
|
|
||||||
class Volume {
|
class Volume {
|
||||||
public:
|
public:
|
||||||
// Construction/destruction
|
Volume(fs_volume *volume);
|
||||||
Volume(nspace_id id);
|
~Volume();
|
||||||
~Volume();
|
|
||||||
|
status_t Mount(const char *device, off_t offset, off_t length,
|
||||||
// Mounting/unmounting
|
uint32 blockSize, uint32 flags);
|
||||||
status_t Mount(const char *deviceName, off_t offset, off_t length,
|
status_t Unmount();
|
||||||
uint32 blockSize, uint32 flags);
|
|
||||||
status_t Unmount();
|
bool IsReadOnly() { return true; }
|
||||||
|
|
||||||
// Address mapping
|
// Address mapping
|
||||||
status_t MapBlock(long_address address, off_t *mappedBlock);
|
status_t MapBlock(long_address address, off_t *mappedBlock);
|
||||||
status_t MapExtent(long_address logicalExtent, extent_address &physicalExtent);
|
status_t MapExtent(long_address logicalExtent,
|
||||||
|
extent_address &physicalExtent);
|
||||||
|
|
||||||
// Miscellaneous info
|
// Miscellaneous info
|
||||||
const char *Name() const;
|
const char *Name() const;
|
||||||
int Device() const { return fDevice; }
|
int Device() const { return fDevice; }
|
||||||
nspace_id Id() const { return fId; }
|
dev_t ID() const { return fFSVolume ? fFSVolume->id : -1; }
|
||||||
off_t Offset() const { return fOffset; }
|
fs_volume *FSVolume() const { return fFSVolume; }
|
||||||
off_t Length() const { return fLength; }
|
off_t Offset() const { return fOffset; }
|
||||||
uint32 BlockSize() const { return fBlockSize; }
|
off_t Length() const { return fLength; }
|
||||||
uint32 BlockShift() const { return fBlockShift; }
|
void *BlockCache() {return fBlockCache; }
|
||||||
bool Mounted() const { return fMounted; }
|
uint32 BlockSize() const { return fBlockSize; }
|
||||||
Icb* RootIcb() { return fRootIcb; }
|
uint32 BlockShift() const { return fBlockShift; }
|
||||||
|
bool Mounted() const { return fMounted; }
|
||||||
private:
|
Icb* RootIcb() { return fRootIcb; }
|
||||||
Volume(); // unimplemented
|
|
||||||
Volume(const Volume &ref); // unimplemented
|
|
||||||
Volume& operator=(const Volume &ref); // unimplemented
|
|
||||||
|
|
||||||
void _Unset();
|
|
||||||
|
|
||||||
status_t _SetPartition(uint number, Partition *partition);
|
|
||||||
Partition* _GetPartition(uint number);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
nspace_id fId;
|
void _Unset();
|
||||||
int fDevice;
|
|
||||||
bool fMounted;
|
status_t _SetPartition(uint number, Partition *partition);
|
||||||
off_t fOffset;
|
Partition* _GetPartition(uint number);
|
||||||
off_t fLength;
|
|
||||||
uint32 fBlockSize;
|
private:
|
||||||
uint32 fBlockShift;
|
void *fBlockCache;
|
||||||
Partition *fPartitions[UDF_MAX_PARTITION_MAPS];
|
uint32 fBlockShift;
|
||||||
Icb *fRootIcb; // Destroyed by vfs via callback to release_node()
|
uint32 fBlockSize;
|
||||||
String fName;
|
int fDevice;
|
||||||
|
fs_volume *fFSVolume;
|
||||||
|
off_t fLength;
|
||||||
|
bool fMounted;
|
||||||
|
UdfString fName;
|
||||||
|
off_t fOffset;
|
||||||
|
Partition *fPartitions[UDF_MAX_PARTITION_MAPS];
|
||||||
|
Icb *fRootIcb; // Destroyed by vfs via callback to put_node()
|
||||||
};
|
};
|
||||||
|
|
||||||
}; // namespace Udf
|
|
||||||
|
|
||||||
#endif // _UDF_VOLUME_H
|
#endif // _UDF_VOLUME_H
|
||||||
|
|||||||
Reference in New Issue
Block a user