* 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:
Salvatore Benedetto 2008-08-20 16:59:07 +00:00
parent df8aa69a76
commit 0c3428791d

View File

@ -29,37 +29,40 @@ Volume::Volume(fs_volume *fsVolume)
fPartitions[i] = NULL;
}
Volume::~Volume()
{
_Unset();
}
/*! \brief Attempts to mount the given device.
\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
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)
{
DEBUG_INIT_ETC("Volume",
("deviceName: `%s', offset: %Ld, numBlocks: %Ld, blockSize: %ld, "
"flags: %ld", deviceName, offset, numBlocks, blockSize, flags));
TRACE(("Volume::Mount: deviceName = `%s', offset = %Ld, length = %Ld, "
"blockSize: %ld, flags: %ld\n", deviceName, offset, length, blockSize,
flags));
if (!deviceName)
RETURN(B_BAD_VALUE);
if (Mounted()) {
return B_BAD_VALUE;
if (Mounted())
// Already mounted, thank you for asking
RETURN(B_BUSY);
}
return B_BUSY;
// Open the device read only
int device = open(deviceName, O_RDONLY);
if (device < B_OK)
RETURN(device);
status_t error = B_OK;
if (device < B_OK) {
TRACE_ERROR(("Volume::Mount: failed to open device = %s\n", deviceName));
return device;
}
status_t status = B_OK;
// If the device is actually a normal file, try to disable the cache
// for the file in the parent filesystem
#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
// see if we have a potentially valid UDF volume on our hands
//error = udf_recognize(device, offset, numBlocks, blockSize, blockShift,
// logicalVolumeDescriptor, partitionDescriptors,
// partitionDescriptorCount);
status = udf_recognize(device, offset, length, blockSize, blockShift,
logicalVolumeDescriptor, partitionDescriptors,
partitionDescriptorCount);
// Set up the block cache
if (!error)
fBlockCache = block_cache_create(device, numBlocks, blockSize, IsReadOnly());
if (!status)
fBlockCache = block_cache_create(device, length, blockSize, IsReadOnly());
else {
TRACE_ERROR(("Volume::Mount: failed to recognize partition\n"));
return status;
}
int physicalCount = 0;
int virtualCount = 0;
int sparableCount = 0;
int metadataCount = 0;
// Set up the partitions
if (!error) {
if (!status) {
// Set up physical and sparable partitions first
int offset = 0;
for (uint8 i = 0; i < logicalVolumeDescriptor.partition_map_count()
&& !error; i++)
&& !status; i++)
{
uint8 *maps = logicalVolumeDescriptor.partition_maps();
partition_map_header *header =
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) {
PRINT(("map type: physical\n"));
TRACE(("map type: physical\n"));
physical_partition_map* map =
reinterpret_cast<physical_partition_map*>(header);
// Find the corresponding partition descriptor
@ -123,18 +130,18 @@ Volume::Mount(const char *deviceName, off_t offset, off_t numBlocks,
map->partition_number(),
descriptor->start(),
descriptor->length());
error = partition ? B_OK : B_NO_MEMORY;
if (!error) {
PRINT(("Adding PhysicalPartition(number: %d, start: %ld, "
"numBlocks: %ld)\n", map->partition_number(),
status = partition ? B_OK : B_NO_MEMORY;
if (!status) {
TRACE(("Adding PhysicalPartition(number: %d, start: %ld, "
"length: %ld)\n", map->partition_number(),
descriptor->start(), descriptor->length()));
error = _SetPartition(i, partition);
if (!error)
status = _SetPartition(i, partition);
if (!status)
physicalCount++;
}
} else {
PRINT(("no matching partition descriptor found!\n"));
error = B_ERROR;
TRACE(("no matching partition descriptor found!\n"));
status = B_ERROR;
}
} else if (header->type() == 2) {
// 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(kSparablePartitionMapId);
if (typeId.matches(kVirtualPartitionMapId)) {
PRINT(("map type: virtual\n"));
TRACE(("map type: virtual\n"));
virtual_partition_map* map =
reinterpret_cast<virtual_partition_map*>(header);
virtualCount++;
(void)map; // kill the warning for now
} else if (typeId.matches(kSparablePartitionMapId)) {
PRINT(("map type: sparable\n"));
TRACE(("map type: sparable\n"));
sparable_partition_map* map =
reinterpret_cast<sparable_partition_map*>(header);
sparableCount++;
(void)map; // kill the warning for now
} else if (typeId.matches(kMetadataPartitionMapId)) {
PRINT(("map type: metadata\n"));
TRACE(("map type: metadata\n"));
metadata_partition_map* map =
reinterpret_cast<metadata_partition_map*>(header);
metadataCount++;
(void)map; // kill the warning for now
} else {
PRINT(("map type: unrecognized (`%.23s')\n",
TRACE(("map type: unrecognized (`%.23s')\n",
typeId.identifier()));
error = B_ERROR;
status = B_ERROR;
}
} else {
PRINT(("Invalid partition type %d found!\n", header->type()));
error = B_ERROR;
TRACE(("Invalid partition type %d found!\n", header->type()));
status = B_ERROR;
}
offset += header->length();
}
}
// Do some checking as to what sorts of partitions we've actually found.
if (!error) {
error = (physicalCount == 1 && virtualCount == 0
if (!status) {
status = (physicalCount == 1 && virtualCount == 0
&& sparableCount == 0 && metadataCount == 0)
|| (physicalCount == 2 && virtualCount == 0
&& sparableCount == 0 && metadataCount == 0)
? B_OK : B_ERROR;
if (error) {
PRINT(("Invalid partition layout found:\n"));
PRINT((" physical partitions: %d\n", physicalCount));
PRINT((" virtual partitions: %d\n", virtualCount));
PRINT((" sparable partitions: %d\n", sparableCount));
PRINT((" metadata partitions: %d\n", metadataCount));
if (status) {
TRACE(("Invalid partition layout found:\n"));
TRACE((" physical partitions: %d\n", physicalCount));
TRACE((" virtual partitions: %d\n", virtualCount));
TRACE((" sparable partitions: %d\n", sparableCount));
TRACE((" metadata partitions: %d\n", metadataCount));
}
}
// We're now going to start creating Icb's, which will expect
// certain parts of the volume to be initialized properly. Thus,
// we initialize those parts here.
if (!error) {
if (!status) {
fDevice = device;
fOffset = offset;
fLength = numBlocks;
fLength = length;
fBlockSize = blockSize;
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
// our partitions are all set up. We now need to investigate the file
// set descriptor pointed to by the logical volume descriptor.
if (!error) {
if (!status) {
MemoryChunk chunk(logicalVolumeDescriptor.file_set_address().length());
error = chunk.InitCheck();
status = chunk.InitCheck();
if (!error) {
if (!status) {
off_t address;
// Read in the file set descriptor
error = MapBlock(logicalVolumeDescriptor.file_set_address(),
status = MapBlock(logicalVolumeDescriptor.file_set_address(),
&address);
if (!error)
if (!status)
address <<= blockShift;
if (!error) {
if (!status) {
ssize_t bytesRead = read_pos(device, address, chunk.Data(),
blockSize);
if (bytesRead != ssize_t(blockSize)) {
error = B_IO_ERROR;
PRINT(("read_pos(pos:%Ld, len:%ld) failed with: 0x%lx\n",
status = B_IO_ERROR;
TRACE(("read_pos(pos:%Ld, len:%ld) failed with: 0x%lx\n",
address, blockSize, bytesRead));
}
}
// See if it's valid, and if so, create the root icb
if (!error) {
if (!status) {
file_set_descriptor *fileSet =
reinterpret_cast<file_set_descriptor*>(chunk.Data());
PDUMP(fileSet);
error = fileSet->tag().id() == TAGID_FILE_SET_DESCRIPTOR
status = fileSet->tag().id() == TAGID_FILE_SET_DESCRIPTOR
? B_OK : B_ERROR;
if (!error)
error = fileSet->tag().init_check(
if (!status)
status = fileSet->tag().init_check(
logicalVolumeDescriptor.file_set_address().block());
if (!error) {
if (!status) {
PDUMP(fileSet);
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) {
//error = new_vnode(fFSVolume->Id(), RootIcb()->Id(), (void*)RootIcb());
if (error) {
PRINT(("Error creating vnode for root icb! "
"error = 0x%lx, `%s'\n", error,
strerror(error)));
if (!status) {
//status = new_vnode(fFSVolume->Id(), RootIcb()->Id(), (void*)RootIcb());
if (status) {
TRACE(("Error creating vnode for root icb! "
"status = 0x%lx, `%s'\n", status,
strerror(status)));
// Clean up the icb we created, since _Unset()
// won't do this for us.
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
// name and then flag that we're mounted. On the other hand, if
// an error occurred, we need to clean things up.
if (!error) {
if (!status) {
fName.SetTo(logicalVolumeDescriptor.logical_volume_identifier());
fMounted = true;
} else {
_Unset();
}
RETURN(error);
RETURN(status);
}
const char*