diff --git a/src/add-ons/kernel/partitioning_systems/session/session.cpp b/src/add-ons/kernel/partitioning_systems/session/session.cpp index 55d3c9db63..599db99ffd 100644 --- a/src/add-ons/kernel/partitioning_systems/session/session.cpp +++ b/src/add-ons/kernel/partitioning_systems/session/session.cpp @@ -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 + #include #include #include -#include #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, ...) @@ -48,16 +39,16 @@ static float identify_partition(int fd, partition_data *partition, void **cookie) { DEBUG_INIT_ETC(NULL, ("fd: %d, id: %ld, offset: %Ld, " - "size: %Ld, block_size: %ld, flags: 0x%lx", fd, - partition->id, partition->offset, partition->size, - partition->block_size, partition->flags)); + "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) - { + && partition->block_size == 2048 + && ioctl(fd, B_GET_GEOMETRY, &geometry) == 0 + && geometry.device_type == B_CD) { Disc *disc = new Disc(fd); if (disc && disc->InitCheck() == B_OK) { *cookie = static_cast(disc); @@ -73,51 +64,36 @@ static status_t scan_partition(int fd, partition_data *partition, void *cookie) { DEBUG_INIT_ETC(NULL, ("fd: %d, id: %ld, offset: %Ld, size: %Ld, " - "block_size: %ld, cookie: %p", fd, partition->id, partition->offset, - partition->size, partition->block_size, 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(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; - for (int i = 0; (session = disc->GetSession(i)); i++) { - partition_data *child = create_child_partition(partition->id, - i, -1); - if (!child) { - PRINT(("Unable to create child at index %d.\n", i)); - // something went wrong - 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; + Disc *disc = static_cast(cookie); + partition->status = B_PARTITION_VALID; + partition->flags |= B_PARTITION_PARTITIONING_SYSTEM + | B_PARTITION_READ_ONLY; + partition->content_size = partition->size; + + 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); + if (!child) { + PRINT(("Unable to create child at index %d.\n", i)); + // something went wrong + error = B_ERROR; + break; } - } - // cleanup on error - if (error) { - delete static_cast(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(child->cookie); - child->cookie = NULL; - } + 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; } 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(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(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(partition->content_cookie); - partition->content_cookie = NULL; - } + DEBUG_INIT_ETC(NULL, ("cookie: %p", cookie)); + delete static_cast(cookie); } @@ -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[] = {