* 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:
Axel Dörfler 2007-11-12 22:38:39 +00:00
parent 6e122bd99e
commit ef6f42349c

View File

@ -1,35 +1,26 @@
//----------------------------------------------------------------------
// This software is part of the Haiku distribution and is covered
// by the MIT license.
//
// Copyright (c) 2003 Tyler Dauwalder, tyler@dauwalder.net
//---------------------------------------------------------------------
/*
* Copyright 2003 Tyler Akidau, haiku@akidau.net
* Distributed under the terms of the MIT License.
*/
/*!
\file session.cpp
\brief Disk device manager partition module for CD/DVD sessions.
*/
#include <unistd.h>
#include <ddm_modules.h>
#include <DiskDeviceTypes.h>
#include <KernelExport.h>
#include <unistd.h>
#include "Debug.h"
#include "Disc.h"
#define SESSION_PARTITION_MODULE_NAME "partitioning_systems/session/v1"
#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
standard_operations(int32 op, ...)
@ -51,13 +42,13 @@ identify_partition(int fd, partition_data *partition, void **cookie)
"size: %Ld, block_size: %ld, flags: 0x%lx", fd,
partition->id, partition->offset, partition->size,
partition->block_size, partition->flags));
device_geometry geometry;
float result = -1;
if (partition->flags & B_PARTITION_IS_DEVICE
&& partition->block_size == 2048
&& ioctl(fd, B_GET_GEOMETRY, &geometry) == 0
&& geometry.device_type == B_CD)
{
&& geometry.device_type == B_CD) {
Disc *disc = new Disc(fd);
if (disc && disc->InitCheck() == B_OK) {
*cookie = static_cast<void*>(disc);
@ -76,16 +67,14 @@ scan_partition(int fd, partition_data *partition, void *cookie)
"block_size: %ld, cookie: %p", fd, partition->id, partition->offset,
partition->size, partition->block_size, cookie));
status_t error = fd >= 0 && partition && cookie ? B_OK : B_BAD_VALUE;
if (!error) {
Disc *disc = static_cast<Disc*>(cookie);
partition->status = B_PARTITION_VALID;
partition->flags |= B_PARTITION_PARTITIONING_SYSTEM
| B_PARTITION_READ_ONLY;
partition->content_size = partition->size;
partition->content_cookie = disc;
Session *session = NULL;
status_t error = B_OK;
for (int i = 0; (session = disc->GetSession(i)); i++) {
partition_data *child = create_child_partition(partition->id,
i, -1);
@ -105,19 +94,6 @@ scan_partition(int fd, partition_data *partition, void *cookie)
break;
}
child->parameters = NULL;
child->cookie = session;
}
}
// cleanup on error
if (error) {
delete static_cast<Disc*>(cookie);
partition->content_cookie = NULL;
for (int32 i = 0; i < partition->child_count; i++) {
if (partition_data *child = get_child_partition(partition->id, i)) {
delete static_cast<Session *>(child->cookie);
child->cookie = NULL;
}
}
}
PRINT(("error: 0x%lx, `%s'\n", error, strerror(error)));
RETURN(error);
@ -127,32 +103,8 @@ scan_partition(int fd, partition_data *partition, void *cookie)
static void
free_identify_partition_cookie(partition_data */*partition*/, void *cookie)
{
if (cookie) {
DEBUG_INIT_ETC(NULL, ("cookie: %p", 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
scan_partition, // scan_partition
free_identify_partition_cookie, // free_identify_partition_cookie
free_partition_cookie, // free_partition_cookie
free_partition_content_cookie, // free_partition_content_cookie
NULL, // free_partition_cookie
NULL, // free_partition_content_cookie
};
partition_module_info *modules[] = {