* Renamed error to status
* Replaced some PRINT with TRACE * uncommented udf_recognized function call in Mount method * minor clean up git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27083 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
df8aa69a76
commit
0c3428791d
@ -29,37 +29,40 @@ Volume::Volume(fs_volume *fsVolume)
|
|||||||
fPartitions[i] = NULL;
|
fPartitions[i] = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Volume::~Volume()
|
Volume::~Volume()
|
||||||
{
|
{
|
||||||
_Unset();
|
_Unset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*! \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 numBlocks of the volume on the given device.
|
\param volumeLength The block length of the volume on the given device.
|
||||||
*/
|
*/
|
||||||
status_t
|
status_t
|
||||||
Volume::Mount(const char *deviceName, off_t offset, off_t numBlocks,
|
Volume::Mount(const char *deviceName, off_t offset, off_t length,
|
||||||
uint32 blockSize, uint32 flags)
|
uint32 blockSize, uint32 flags)
|
||||||
{
|
{
|
||||||
DEBUG_INIT_ETC("Volume",
|
TRACE(("Volume::Mount: deviceName = `%s', offset = %Ld, length = %Ld, "
|
||||||
("deviceName: `%s', offset: %Ld, numBlocks: %Ld, blockSize: %ld, "
|
"blockSize: %ld, flags: %ld\n", deviceName, offset, length, blockSize,
|
||||||
"flags: %ld", deviceName, offset, numBlocks, blockSize, flags));
|
flags));
|
||||||
if (!deviceName)
|
if (!deviceName)
|
||||||
RETURN(B_BAD_VALUE);
|
return B_BAD_VALUE;
|
||||||
if (Mounted()) {
|
if (Mounted())
|
||||||
// Already mounted, thank you for asking
|
// Already mounted, thank you for asking
|
||||||
RETURN(B_BUSY);
|
return B_BUSY;
|
||||||
}
|
|
||||||
|
|
||||||
// Open the device read only
|
// Open the device read only
|
||||||
int device = open(deviceName, O_RDONLY);
|
int device = open(deviceName, O_RDONLY);
|
||||||
if (device < B_OK)
|
if (device < B_OK) {
|
||||||
RETURN(device);
|
TRACE_ERROR(("Volume::Mount: failed to open device = %s\n", deviceName));
|
||||||
|
return device;
|
||||||
status_t error = B_OK;
|
}
|
||||||
|
|
||||||
|
status_t status = B_OK;
|
||||||
|
|
||||||
// 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 0 // _KERNEL_MODE
|
#if 0 // _KERNEL_MODE
|
||||||
@ -79,32 +82,36 @@ Volume::Mount(const char *deviceName, off_t offset, off_t numBlocks,
|
|||||||
|
|
||||||
// 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, numBlocks, blockSize, blockShift,
|
status = udf_recognize(device, offset, length, blockSize, blockShift,
|
||||||
// logicalVolumeDescriptor, partitionDescriptors,
|
logicalVolumeDescriptor, partitionDescriptors,
|
||||||
// partitionDescriptorCount);
|
partitionDescriptorCount);
|
||||||
|
|
||||||
// Set up the block cache
|
// Set up the block cache
|
||||||
if (!error)
|
if (!status)
|
||||||
fBlockCache = block_cache_create(device, numBlocks, blockSize, IsReadOnly());
|
fBlockCache = block_cache_create(device, length, blockSize, IsReadOnly());
|
||||||
|
else {
|
||||||
|
TRACE_ERROR(("Volume::Mount: failed to recognize partition\n"));
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
int physicalCount = 0;
|
int physicalCount = 0;
|
||||||
int virtualCount = 0;
|
int virtualCount = 0;
|
||||||
int sparableCount = 0;
|
int sparableCount = 0;
|
||||||
int metadataCount = 0;
|
int metadataCount = 0;
|
||||||
|
|
||||||
// Set up the partitions
|
// Set up the partitions
|
||||||
if (!error) {
|
if (!status) {
|
||||||
// Set up physical and sparable partitions first
|
// Set up physical and sparable partitions first
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
for (uint8 i = 0; i < logicalVolumeDescriptor.partition_map_count()
|
for (uint8 i = 0; i < logicalVolumeDescriptor.partition_map_count()
|
||||||
&& !error; i++)
|
&& !status; i++)
|
||||||
{
|
{
|
||||||
uint8 *maps = logicalVolumeDescriptor.partition_maps();
|
uint8 *maps = logicalVolumeDescriptor.partition_maps();
|
||||||
partition_map_header *header =
|
partition_map_header *header =
|
||||||
reinterpret_cast<partition_map_header*>(maps+offset);
|
reinterpret_cast<partition_map_header*>(maps+offset);
|
||||||
PRINT(("partition map %d (type %d):\n", i, header->type()));
|
TRACE(("partition map %d (type %d):\n", i, header->type()));
|
||||||
if (header->type() == 1) {
|
if (header->type() == 1) {
|
||||||
PRINT(("map type: physical\n"));
|
TRACE(("map type: physical\n"));
|
||||||
physical_partition_map* map =
|
physical_partition_map* map =
|
||||||
reinterpret_cast<physical_partition_map*>(header);
|
reinterpret_cast<physical_partition_map*>(header);
|
||||||
// Find the corresponding partition descriptor
|
// Find the corresponding partition descriptor
|
||||||
@ -123,18 +130,18 @@ Volume::Mount(const char *deviceName, off_t offset, off_t numBlocks,
|
|||||||
map->partition_number(),
|
map->partition_number(),
|
||||||
descriptor->start(),
|
descriptor->start(),
|
||||||
descriptor->length());
|
descriptor->length());
|
||||||
error = partition ? B_OK : B_NO_MEMORY;
|
status = partition ? B_OK : B_NO_MEMORY;
|
||||||
if (!error) {
|
if (!status) {
|
||||||
PRINT(("Adding PhysicalPartition(number: %d, start: %ld, "
|
TRACE(("Adding PhysicalPartition(number: %d, start: %ld, "
|
||||||
"numBlocks: %ld)\n", map->partition_number(),
|
"length: %ld)\n", map->partition_number(),
|
||||||
descriptor->start(), descriptor->length()));
|
descriptor->start(), descriptor->length()));
|
||||||
error = _SetPartition(i, partition);
|
status = _SetPartition(i, partition);
|
||||||
if (!error)
|
if (!status)
|
||||||
physicalCount++;
|
physicalCount++;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
PRINT(("no matching partition descriptor found!\n"));
|
TRACE(("no matching partition descriptor found!\n"));
|
||||||
error = B_ERROR;
|
status = B_ERROR;
|
||||||
}
|
}
|
||||||
} else if (header->type() == 2) {
|
} else if (header->type() == 2) {
|
||||||
// Figure out what kind of type 2 partition map we have based
|
// Figure out what kind of type 2 partition map we have based
|
||||||
@ -143,59 +150,59 @@ Volume::Mount(const char *deviceName, off_t offset, off_t numBlocks,
|
|||||||
DUMP(typeId);
|
DUMP(typeId);
|
||||||
DUMP(kSparablePartitionMapId);
|
DUMP(kSparablePartitionMapId);
|
||||||
if (typeId.matches(kVirtualPartitionMapId)) {
|
if (typeId.matches(kVirtualPartitionMapId)) {
|
||||||
PRINT(("map type: virtual\n"));
|
TRACE(("map type: virtual\n"));
|
||||||
virtual_partition_map* map =
|
virtual_partition_map* map =
|
||||||
reinterpret_cast<virtual_partition_map*>(header);
|
reinterpret_cast<virtual_partition_map*>(header);
|
||||||
virtualCount++;
|
virtualCount++;
|
||||||
(void)map; // kill the warning for now
|
(void)map; // kill the warning for now
|
||||||
} else if (typeId.matches(kSparablePartitionMapId)) {
|
} else if (typeId.matches(kSparablePartitionMapId)) {
|
||||||
PRINT(("map type: sparable\n"));
|
TRACE(("map type: sparable\n"));
|
||||||
sparable_partition_map* map =
|
sparable_partition_map* map =
|
||||||
reinterpret_cast<sparable_partition_map*>(header);
|
reinterpret_cast<sparable_partition_map*>(header);
|
||||||
sparableCount++;
|
sparableCount++;
|
||||||
(void)map; // kill the warning for now
|
(void)map; // kill the warning for now
|
||||||
} else if (typeId.matches(kMetadataPartitionMapId)) {
|
} else if (typeId.matches(kMetadataPartitionMapId)) {
|
||||||
PRINT(("map type: metadata\n"));
|
TRACE(("map type: metadata\n"));
|
||||||
metadata_partition_map* map =
|
metadata_partition_map* map =
|
||||||
reinterpret_cast<metadata_partition_map*>(header);
|
reinterpret_cast<metadata_partition_map*>(header);
|
||||||
metadataCount++;
|
metadataCount++;
|
||||||
(void)map; // kill the warning for now
|
(void)map; // kill the warning for now
|
||||||
} else {
|
} else {
|
||||||
PRINT(("map type: unrecognized (`%.23s')\n",
|
TRACE(("map type: unrecognized (`%.23s')\n",
|
||||||
typeId.identifier()));
|
typeId.identifier()));
|
||||||
error = B_ERROR;
|
status = B_ERROR;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
PRINT(("Invalid partition type %d found!\n", header->type()));
|
TRACE(("Invalid partition type %d found!\n", header->type()));
|
||||||
error = B_ERROR;
|
status = B_ERROR;
|
||||||
}
|
}
|
||||||
offset += header->length();
|
offset += header->length();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do some checking as to what sorts of partitions we've actually found.
|
// Do some checking as to what sorts of partitions we've actually found.
|
||||||
if (!error) {
|
if (!status) {
|
||||||
error = (physicalCount == 1 && virtualCount == 0
|
status = (physicalCount == 1 && virtualCount == 0
|
||||||
&& sparableCount == 0 && metadataCount == 0)
|
&& sparableCount == 0 && metadataCount == 0)
|
||||||
|| (physicalCount == 2 && virtualCount == 0
|
|| (physicalCount == 2 && virtualCount == 0
|
||||||
&& sparableCount == 0 && metadataCount == 0)
|
&& sparableCount == 0 && metadataCount == 0)
|
||||||
? B_OK : B_ERROR;
|
? B_OK : B_ERROR;
|
||||||
if (error) {
|
if (status) {
|
||||||
PRINT(("Invalid partition layout found:\n"));
|
TRACE(("Invalid partition layout found:\n"));
|
||||||
PRINT((" physical partitions: %d\n", physicalCount));
|
TRACE((" physical partitions: %d\n", physicalCount));
|
||||||
PRINT((" virtual partitions: %d\n", virtualCount));
|
TRACE((" virtual partitions: %d\n", virtualCount));
|
||||||
PRINT((" sparable partitions: %d\n", sparableCount));
|
TRACE((" sparable partitions: %d\n", sparableCount));
|
||||||
PRINT((" metadata partitions: %d\n", metadataCount));
|
TRACE((" metadata partitions: %d\n", metadataCount));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// We're now going to start creating Icb's, which will expect
|
// We're now going to start creating Icb's, which will expect
|
||||||
// certain parts of the volume to be initialized properly. Thus,
|
// certain parts of the volume to be initialized properly. Thus,
|
||||||
// we initialize those parts here.
|
// we initialize those parts here.
|
||||||
if (!error) {
|
if (!status) {
|
||||||
fDevice = device;
|
fDevice = device;
|
||||||
fOffset = offset;
|
fOffset = offset;
|
||||||
fLength = numBlocks;
|
fLength = length;
|
||||||
fBlockSize = blockSize;
|
fBlockSize = blockSize;
|
||||||
fBlockShift = blockShift;
|
fBlockShift = blockShift;
|
||||||
}
|
}
|
||||||
@ -203,48 +210,48 @@ Volume::Mount(const char *deviceName, off_t offset, off_t numBlocks,
|
|||||||
// At this point we've found a valid set of volume descriptors and
|
// At this point we've found a valid set of volume descriptors and
|
||||||
// our partitions are all set up. We now need to investigate the file
|
// our partitions are all set up. We now need to investigate the file
|
||||||
// set descriptor pointed to by the logical volume descriptor.
|
// set descriptor pointed to by the logical volume descriptor.
|
||||||
if (!error) {
|
if (!status) {
|
||||||
MemoryChunk chunk(logicalVolumeDescriptor.file_set_address().length());
|
MemoryChunk chunk(logicalVolumeDescriptor.file_set_address().length());
|
||||||
|
|
||||||
error = chunk.InitCheck();
|
status = chunk.InitCheck();
|
||||||
|
|
||||||
if (!error) {
|
if (!status) {
|
||||||
off_t address;
|
off_t address;
|
||||||
// Read in the file set descriptor
|
// Read in the file set descriptor
|
||||||
error = MapBlock(logicalVolumeDescriptor.file_set_address(),
|
status = MapBlock(logicalVolumeDescriptor.file_set_address(),
|
||||||
&address);
|
&address);
|
||||||
if (!error)
|
if (!status)
|
||||||
address <<= blockShift;
|
address <<= blockShift;
|
||||||
if (!error) {
|
if (!status) {
|
||||||
ssize_t bytesRead = read_pos(device, address, chunk.Data(),
|
ssize_t bytesRead = read_pos(device, address, chunk.Data(),
|
||||||
blockSize);
|
blockSize);
|
||||||
if (bytesRead != ssize_t(blockSize)) {
|
if (bytesRead != ssize_t(blockSize)) {
|
||||||
error = B_IO_ERROR;
|
status = B_IO_ERROR;
|
||||||
PRINT(("read_pos(pos:%Ld, len:%ld) failed with: 0x%lx\n",
|
TRACE(("read_pos(pos:%Ld, len:%ld) failed with: 0x%lx\n",
|
||||||
address, blockSize, bytesRead));
|
address, blockSize, bytesRead));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// See if it's valid, and if so, create the root icb
|
// See if it's valid, and if so, create the root icb
|
||||||
if (!error) {
|
if (!status) {
|
||||||
file_set_descriptor *fileSet =
|
file_set_descriptor *fileSet =
|
||||||
reinterpret_cast<file_set_descriptor*>(chunk.Data());
|
reinterpret_cast<file_set_descriptor*>(chunk.Data());
|
||||||
PDUMP(fileSet);
|
PDUMP(fileSet);
|
||||||
error = fileSet->tag().id() == TAGID_FILE_SET_DESCRIPTOR
|
status = fileSet->tag().id() == TAGID_FILE_SET_DESCRIPTOR
|
||||||
? B_OK : B_ERROR;
|
? B_OK : B_ERROR;
|
||||||
if (!error)
|
if (!status)
|
||||||
error = fileSet->tag().init_check(
|
status = fileSet->tag().init_check(
|
||||||
logicalVolumeDescriptor.file_set_address().block());
|
logicalVolumeDescriptor.file_set_address().block());
|
||||||
if (!error) {
|
if (!status) {
|
||||||
PDUMP(fileSet);
|
PDUMP(fileSet);
|
||||||
fRootIcb = new(nothrow) Icb(this, fileSet->root_directory_icb());
|
fRootIcb = new(nothrow) Icb(this, fileSet->root_directory_icb());
|
||||||
error = fRootIcb ? fRootIcb->InitCheck() : B_NO_MEMORY;
|
status = fRootIcb ? fRootIcb->InitCheck() : B_NO_MEMORY;
|
||||||
}
|
}
|
||||||
if (!error) {
|
if (!status) {
|
||||||
//error = new_vnode(fFSVolume->Id(), RootIcb()->Id(), (void*)RootIcb());
|
//status = new_vnode(fFSVolume->Id(), RootIcb()->Id(), (void*)RootIcb());
|
||||||
if (error) {
|
if (status) {
|
||||||
PRINT(("Error creating vnode for root icb! "
|
TRACE(("Error creating vnode for root icb! "
|
||||||
"error = 0x%lx, `%s'\n", error,
|
"status = 0x%lx, `%s'\n", status,
|
||||||
strerror(error)));
|
strerror(status)));
|
||||||
// Clean up the icb we created, since _Unset()
|
// Clean up the icb we created, since _Unset()
|
||||||
// won't do this for us.
|
// won't do this for us.
|
||||||
delete fRootIcb;
|
delete fRootIcb;
|
||||||
@ -258,14 +265,14 @@ Volume::Mount(const char *deviceName, off_t offset, off_t numBlocks,
|
|||||||
// If we've made it this far, we're good to go; set the volume
|
// If we've made it this far, we're good to go; set the volume
|
||||||
// name and then flag that we're mounted. On the other hand, if
|
// name and then flag that we're mounted. On the other hand, if
|
||||||
// an error occurred, we need to clean things up.
|
// an error occurred, we need to clean things up.
|
||||||
if (!error) {
|
if (!status) {
|
||||||
fName.SetTo(logicalVolumeDescriptor.logical_volume_identifier());
|
fName.SetTo(logicalVolumeDescriptor.logical_volume_identifier());
|
||||||
fMounted = true;
|
fMounted = true;
|
||||||
} else {
|
} else {
|
||||||
_Unset();
|
_Unset();
|
||||||
}
|
}
|
||||||
|
|
||||||
RETURN(error);
|
RETURN(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char*
|
const char*
|
||||||
|
Loading…
Reference in New Issue
Block a user