* The session module deleted its cookie twice, after identifying, and when the
partition cookie was deleted - when removing a CD it would crash. * Since the partition cookies are not needed at all, we don't use it anymore. * scan_partition() deleted the identify cookie on error, but that's not its job - free_identify_cookie() is always called, no matter what scan partition does. * Minor cleanup. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22911 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
6e122bd99e
commit
ef6f42349c
@ -1,35 +1,26 @@
|
|||||||
//----------------------------------------------------------------------
|
/*
|
||||||
// This software is part of the Haiku distribution and is covered
|
* Copyright 2003 Tyler Akidau, haiku@akidau.net
|
||||||
// by the MIT license.
|
* Distributed under the terms of the MIT License.
|
||||||
//
|
*/
|
||||||
// Copyright (c) 2003 Tyler Dauwalder, tyler@dauwalder.net
|
|
||||||
//---------------------------------------------------------------------
|
|
||||||
/*!
|
/*!
|
||||||
\file session.cpp
|
\file session.cpp
|
||||||
\brief Disk device manager partition module for CD/DVD sessions.
|
\brief Disk device manager partition module for CD/DVD sessions.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include <ddm_modules.h>
|
#include <ddm_modules.h>
|
||||||
#include <DiskDeviceTypes.h>
|
#include <DiskDeviceTypes.h>
|
||||||
#include <KernelExport.h>
|
#include <KernelExport.h>
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include "Debug.h"
|
#include "Debug.h"
|
||||||
#include "Disc.h"
|
#include "Disc.h"
|
||||||
|
|
||||||
|
|
||||||
#define SESSION_PARTITION_MODULE_NAME "partitioning_systems/session/v1"
|
#define SESSION_PARTITION_MODULE_NAME "partitioning_systems/session/v1"
|
||||||
#define SESSION_PARTITION_NAME "Multisession Storage Device"
|
#define SESSION_PARTITION_NAME "Multisession Storage Device"
|
||||||
|
|
||||||
static status_t standard_operations(int32 op, ...);
|
|
||||||
static float identify_partition(int fd, partition_data *partition,
|
|
||||||
void **cookie);
|
|
||||||
static status_t scan_partition(int fd, partition_data *partition,
|
|
||||||
void *cookie);
|
|
||||||
static void free_identify_partition_cookie(partition_data *partition,
|
|
||||||
void *cookie);
|
|
||||||
static void free_partition_cookie(partition_data *partition);
|
|
||||||
static void free_partition_content_cookie(partition_data *partition);
|
|
||||||
|
|
||||||
|
|
||||||
static status_t
|
static status_t
|
||||||
standard_operations(int32 op, ...)
|
standard_operations(int32 op, ...)
|
||||||
@ -48,16 +39,16 @@ static float
|
|||||||
identify_partition(int fd, partition_data *partition, void **cookie)
|
identify_partition(int fd, partition_data *partition, void **cookie)
|
||||||
{
|
{
|
||||||
DEBUG_INIT_ETC(NULL, ("fd: %d, id: %ld, offset: %Ld, "
|
DEBUG_INIT_ETC(NULL, ("fd: %d, id: %ld, offset: %Ld, "
|
||||||
"size: %Ld, block_size: %ld, flags: 0x%lx", fd,
|
"size: %Ld, block_size: %ld, flags: 0x%lx", fd,
|
||||||
partition->id, partition->offset, partition->size,
|
partition->id, partition->offset, partition->size,
|
||||||
partition->block_size, partition->flags));
|
partition->block_size, partition->flags));
|
||||||
|
|
||||||
device_geometry geometry;
|
device_geometry geometry;
|
||||||
float result = -1;
|
float result = -1;
|
||||||
if (partition->flags & B_PARTITION_IS_DEVICE
|
if (partition->flags & B_PARTITION_IS_DEVICE
|
||||||
&& partition->block_size == 2048
|
&& partition->block_size == 2048
|
||||||
&& ioctl(fd, B_GET_GEOMETRY, &geometry) == 0
|
&& ioctl(fd, B_GET_GEOMETRY, &geometry) == 0
|
||||||
&& geometry.device_type == B_CD)
|
&& geometry.device_type == B_CD) {
|
||||||
{
|
|
||||||
Disc *disc = new Disc(fd);
|
Disc *disc = new Disc(fd);
|
||||||
if (disc && disc->InitCheck() == B_OK) {
|
if (disc && disc->InitCheck() == B_OK) {
|
||||||
*cookie = static_cast<void*>(disc);
|
*cookie = static_cast<void*>(disc);
|
||||||
@ -73,51 +64,36 @@ static status_t
|
|||||||
scan_partition(int fd, partition_data *partition, void *cookie)
|
scan_partition(int fd, partition_data *partition, void *cookie)
|
||||||
{
|
{
|
||||||
DEBUG_INIT_ETC(NULL, ("fd: %d, id: %ld, offset: %Ld, size: %Ld, "
|
DEBUG_INIT_ETC(NULL, ("fd: %d, id: %ld, offset: %Ld, size: %Ld, "
|
||||||
"block_size: %ld, cookie: %p", fd, partition->id, partition->offset,
|
"block_size: %ld, cookie: %p", fd, partition->id, partition->offset,
|
||||||
partition->size, partition->block_size, cookie));
|
partition->size, partition->block_size, cookie));
|
||||||
|
|
||||||
status_t error = fd >= 0 && partition && cookie ? B_OK : B_BAD_VALUE;
|
Disc *disc = static_cast<Disc*>(cookie);
|
||||||
if (!error) {
|
partition->status = B_PARTITION_VALID;
|
||||||
Disc *disc = static_cast<Disc*>(cookie);
|
partition->flags |= B_PARTITION_PARTITIONING_SYSTEM
|
||||||
partition->status = B_PARTITION_VALID;
|
| B_PARTITION_READ_ONLY;
|
||||||
partition->flags |= B_PARTITION_PARTITIONING_SYSTEM
|
partition->content_size = partition->size;
|
||||||
| B_PARTITION_READ_ONLY;
|
|
||||||
partition->content_size = partition->size;
|
Session *session = NULL;
|
||||||
partition->content_cookie = disc;
|
status_t error = B_OK;
|
||||||
|
for (int i = 0; (session = disc->GetSession(i)); i++) {
|
||||||
Session *session = NULL;
|
partition_data *child = create_child_partition(partition->id,
|
||||||
for (int i = 0; (session = disc->GetSession(i)); i++) {
|
i, -1);
|
||||||
partition_data *child = create_child_partition(partition->id,
|
if (!child) {
|
||||||
i, -1);
|
PRINT(("Unable to create child at index %d.\n", i));
|
||||||
if (!child) {
|
// something went wrong
|
||||||
PRINT(("Unable to create child at index %d.\n", i));
|
error = B_ERROR;
|
||||||
// something went wrong
|
break;
|
||||||
error = B_ERROR;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
child->offset = partition->offset + session->Offset();
|
|
||||||
child->size = session->Size();
|
|
||||||
child->block_size = session->BlockSize();
|
|
||||||
child->flags |= session->Flags();
|
|
||||||
child->type = strdup(session->Type());
|
|
||||||
if (!child->type) {
|
|
||||||
error = B_NO_MEMORY;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
child->parameters = NULL;
|
|
||||||
child->cookie = session;
|
|
||||||
}
|
}
|
||||||
}
|
child->offset = partition->offset + session->Offset();
|
||||||
// cleanup on error
|
child->size = session->Size();
|
||||||
if (error) {
|
child->block_size = session->BlockSize();
|
||||||
delete static_cast<Disc*>(cookie);
|
child->flags |= session->Flags();
|
||||||
partition->content_cookie = NULL;
|
child->type = strdup(session->Type());
|
||||||
for (int32 i = 0; i < partition->child_count; i++) {
|
if (!child->type) {
|
||||||
if (partition_data *child = get_child_partition(partition->id, i)) {
|
error = B_NO_MEMORY;
|
||||||
delete static_cast<Session *>(child->cookie);
|
break;
|
||||||
child->cookie = NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
child->parameters = NULL;
|
||||||
}
|
}
|
||||||
PRINT(("error: 0x%lx, `%s'\n", error, strerror(error)));
|
PRINT(("error: 0x%lx, `%s'\n", error, strerror(error)));
|
||||||
RETURN(error);
|
RETURN(error);
|
||||||
@ -127,32 +103,8 @@ scan_partition(int fd, partition_data *partition, void *cookie)
|
|||||||
static void
|
static void
|
||||||
free_identify_partition_cookie(partition_data */*partition*/, void *cookie)
|
free_identify_partition_cookie(partition_data */*partition*/, void *cookie)
|
||||||
{
|
{
|
||||||
if (cookie) {
|
DEBUG_INIT_ETC(NULL, ("cookie: %p", cookie));
|
||||||
DEBUG_INIT_ETC(NULL, ("cookie: %p", cookie));
|
delete static_cast<Disc*>(cookie);
|
||||||
delete static_cast<Disc*>(cookie);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
|
||||||
free_partition_cookie(partition_data *partition)
|
|
||||||
{
|
|
||||||
if (partition && partition->cookie) {
|
|
||||||
DEBUG_INIT_ETC(NULL, ("partition->cookie: %p", partition->cookie));
|
|
||||||
delete static_cast<Session *>(partition->cookie);
|
|
||||||
partition->cookie = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
|
||||||
free_partition_content_cookie(partition_data *partition)
|
|
||||||
{
|
|
||||||
if (partition && partition->content_cookie) {
|
|
||||||
DEBUG_INIT_ETC(NULL, ("partition->content_cookie: %p", partition->content_cookie));
|
|
||||||
delete static_cast<Disc*>(partition->content_cookie);
|
|
||||||
partition->content_cookie = NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -169,8 +121,8 @@ static partition_module_info sSessionModule = {
|
|||||||
identify_partition, // identify_partition
|
identify_partition, // identify_partition
|
||||||
scan_partition, // scan_partition
|
scan_partition, // scan_partition
|
||||||
free_identify_partition_cookie, // free_identify_partition_cookie
|
free_identify_partition_cookie, // free_identify_partition_cookie
|
||||||
free_partition_cookie, // free_partition_cookie
|
NULL, // free_partition_cookie
|
||||||
free_partition_content_cookie, // free_partition_content_cookie
|
NULL, // free_partition_content_cookie
|
||||||
};
|
};
|
||||||
|
|
||||||
partition_module_info *modules[] = {
|
partition_module_info *modules[] = {
|
||||||
|
Loading…
Reference in New Issue
Block a user