From fe05b0ac9598f2f7d411a9e164c224dc8bf1c964 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Wed, 30 Jul 2003 17:48:08 +0000 Subject: [PATCH] Added and implemented job related syscalls. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@4137 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../ddm_userland_interface.h | 18 ++-- .../ddm_userland_interface.cpp | 100 +++++++++++++++++- 2 files changed, 109 insertions(+), 9 deletions(-) diff --git a/headers/private/kernel/disk_device_manager/ddm_userland_interface.h b/headers/private/kernel/disk_device_manager/ddm_userland_interface.h index 77a9f93800..49d36a187a 100644 --- a/headers/private/kernel/disk_device_manager/ddm_userland_interface.h +++ b/headers/private/kernel/disk_device_manager/ddm_userland_interface.h @@ -199,15 +199,17 @@ status_t _kern_create_child_partition(partition_id partitionID, partition_id *childID); status_t _kern_delete_partition(partition_id partitionID, int32 changeCounter); -#if 0 - // jobs -status_t get_next_disk_device_job_info(user_disk_device_job_info *info, - int32 *cookie); -status_t get_disk_device_job_info(disk_job_id id, - user_disk_device_job_info *info); -status_t get_disk_device_job_status(disk_job_id id, uint32 *status, - float *progress); +status_t _kern_get_next_disk_device_job_info(int32 *cookie, + user_disk_device_job_info *info); +status_t _kern_get_disk_device_job_info(disk_job_id id, + user_disk_device_job_info *info); +status_t _kern_get_disk_device_job_progress_info(disk_job_id id, + disk_device_job_progress_info *info); +status_t _kern_pause_disk_device_job(disk_job_id id); +status_t _kern_cancel_disk_device_job(disk_job_id id, bool reverse); + +#if 0 // watching status_t start_disk_device_watching(port_id, int32 token, uint32 flags); diff --git a/src/kernel/core/disk_device_manager/ddm_userland_interface.cpp b/src/kernel/core/disk_device_manager/ddm_userland_interface.cpp index 090b857bca..4e52b97593 100644 --- a/src/kernel/core/disk_device_manager/ddm_userland_interface.cpp +++ b/src/kernel/core/disk_device_manager/ddm_userland_interface.cpp @@ -1,13 +1,15 @@ // ddm_userland_interface.cpp +#include #include +#include +#include #include #include #include #include #include -#include "ddm_userland_interface.h" #include "UserDataWriter.h" // get_current_team @@ -1659,3 +1661,99 @@ _kern_delete_partition(partition_id partitionID, int32 changeCounter) return B_OK; } +// _kern_get_next_disk_device_job_info +status_t +_kern_get_next_disk_device_job_info(int32 *cookie, + user_disk_device_job_info *info) +{ + if (!cookie || !info) + return B_BAD_VALUE; + KDiskDeviceManager *manager = KDiskDeviceManager::Default(); + if (ManagerLocker locker = manager) { + // get the next job and an info + while (KDiskDeviceJob *job = manager->NextJob(cookie)) { + // return info only on job scheduled or in progress + switch (job->Status()) { + case B_DISK_DEVICE_JOB_SCHEDULED: + case B_DISK_DEVICE_JOB_IN_PROGRESS: + return job->GetInfo(info); + case B_DISK_DEVICE_JOB_UNINITIALIZED: + case B_DISK_DEVICE_JOB_SUCCEEDED: + case B_DISK_DEVICE_JOB_FAILED: + case B_DISK_DEVICE_JOB_CANCELED: + break; + } + } + } + return B_ENTRY_NOT_FOUND; +} + +// _kern_get_disk_device_job_info +status_t +_kern_get_disk_device_job_info(disk_job_id id, user_disk_device_job_info *info) +{ + if (!info) + return B_BAD_VALUE; + KDiskDeviceManager *manager = KDiskDeviceManager::Default(); + if (ManagerLocker locker = manager) { + // find the job and get the info + if (KDiskDeviceJob *job = manager->FindJob(id)) + return job->GetInfo(info); + } + return B_ENTRY_NOT_FOUND; +} + +// _kern_get_disk_device_job_status +status_t +_kern_get_disk_device_job_progress_info(disk_job_id id, + disk_device_job_progress_info *info) +{ + if (!info) + return B_BAD_VALUE; + KDiskDeviceManager *manager = KDiskDeviceManager::Default(); + if (ManagerLocker locker = manager) { + // find the job and get the info + if (KDiskDeviceJob *job = manager->FindJob(id)) + return job->GetProgressInfo(info); + } + return B_ENTRY_NOT_FOUND; +} + +// _kern_pause_disk_device_job +status_t +_kern_pause_disk_device_job(disk_job_id id) +{ + KDiskDeviceManager *manager = KDiskDeviceManager::Default(); + if (ManagerLocker locker = manager) { + // get the job and the respective job queue + if (KDiskDeviceJob *job = manager->FindJob(id)) { + if (KDiskDeviceJobQueue *jobQueue = job->JobQueue()) { + // only the active job in progress can be paused + if (jobQueue->ActiveJob() != job) + return B_BAD_VALUE; + return jobQueue->Pause(); + } + } + } + return B_ENTRY_NOT_FOUND; +} + +// _kern_cancel_disk_device_job +status_t +_kern_cancel_disk_device_job(disk_job_id id, bool reverse) +{ + KDiskDeviceManager *manager = KDiskDeviceManager::Default(); + if (ManagerLocker locker = manager) { + // get the job and the respective job queue + if (KDiskDeviceJob *job = manager->FindJob(id)) { + if (KDiskDeviceJobQueue *jobQueue = job->JobQueue()) { + // only the active job in progress can be canceled + if (jobQueue->ActiveJob() != job) + return B_BAD_VALUE; + return jobQueue->Cancel(reverse); + } + } + } + return B_ENTRY_NOT_FOUND; +} +