125ab0d1aSIngo Weinhold /*
225ab0d1aSIngo Weinhold * Copyright 2007, Ingo Weinhold, ingo_weinhold@gmx.de.
325ab0d1aSIngo Weinhold * Distributed under the terms of the MIT License.
425ab0d1aSIngo Weinhold */
525ab0d1aSIngo Weinhold
6*f75b8de3SAxel Dörfler
725ab0d1aSIngo Weinhold #include "SetStringJob.h"
825ab0d1aSIngo Weinhold
9300868ceSIngo Weinhold #include <syscalls.h>
10300868ceSIngo Weinhold
1125ab0d1aSIngo Weinhold #include "DiskDeviceUtils.h"
1225ab0d1aSIngo Weinhold #include "PartitionReference.h"
1325ab0d1aSIngo Weinhold
1425ab0d1aSIngo Weinhold
1525ab0d1aSIngo Weinhold // constructor
SetStringJob(PartitionReference * partition,PartitionReference * child)1625ab0d1aSIngo Weinhold SetStringJob::SetStringJob(PartitionReference* partition,
1725ab0d1aSIngo Weinhold PartitionReference* child)
18*f75b8de3SAxel Dörfler :
19*f75b8de3SAxel Dörfler DiskDeviceJob(partition, child),
2025ab0d1aSIngo Weinhold fString(NULL)
2125ab0d1aSIngo Weinhold {
2225ab0d1aSIngo Weinhold }
2325ab0d1aSIngo Weinhold
2425ab0d1aSIngo Weinhold
2525ab0d1aSIngo Weinhold // destructor
~SetStringJob()2625ab0d1aSIngo Weinhold SetStringJob::~SetStringJob()
2725ab0d1aSIngo Weinhold {
2825ab0d1aSIngo Weinhold free(fString);
2925ab0d1aSIngo Weinhold }
3025ab0d1aSIngo Weinhold
3125ab0d1aSIngo Weinhold
3225ab0d1aSIngo Weinhold // Init
3325ab0d1aSIngo Weinhold status_t
Init(const char * string,uint32 jobType)3425ab0d1aSIngo Weinhold SetStringJob::Init(const char* string, uint32 jobType)
3525ab0d1aSIngo Weinhold {
3625ab0d1aSIngo Weinhold switch (jobType) {
3725ab0d1aSIngo Weinhold case B_DISK_DEVICE_JOB_SET_NAME:
3825ab0d1aSIngo Weinhold case B_DISK_DEVICE_JOB_SET_CONTENT_NAME:
3925ab0d1aSIngo Weinhold case B_DISK_DEVICE_JOB_SET_TYPE:
4025ab0d1aSIngo Weinhold case B_DISK_DEVICE_JOB_SET_PARAMETERS:
4125ab0d1aSIngo Weinhold case B_DISK_DEVICE_JOB_SET_CONTENT_PARAMETERS:
4225ab0d1aSIngo Weinhold break;
4325ab0d1aSIngo Weinhold default:
4425ab0d1aSIngo Weinhold return B_BAD_VALUE;
4525ab0d1aSIngo Weinhold }
4625ab0d1aSIngo Weinhold
4725ab0d1aSIngo Weinhold fJobType = jobType;
4825ab0d1aSIngo Weinhold SET_STRING_RETURN_ON_ERROR(fString, string);
4925ab0d1aSIngo Weinhold
5025ab0d1aSIngo Weinhold return B_OK;
5125ab0d1aSIngo Weinhold }
5225ab0d1aSIngo Weinhold
5325ab0d1aSIngo Weinhold
5425ab0d1aSIngo Weinhold // Do
5525ab0d1aSIngo Weinhold status_t
Do()5625ab0d1aSIngo Weinhold SetStringJob::Do()
5725ab0d1aSIngo Weinhold {
58300868ceSIngo Weinhold int32 changeCounter = fPartition->ChangeCounter();
59300868ceSIngo Weinhold int32 childChangeCounter = (fChild ? fChild->ChangeCounter() : 0);
60300868ceSIngo Weinhold status_t error;
61300868ceSIngo Weinhold bool updateChildChangeCounter = false;
62300868ceSIngo Weinhold
63300868ceSIngo Weinhold switch (fJobType) {
64300868ceSIngo Weinhold case B_DISK_DEVICE_JOB_SET_NAME:
65300868ceSIngo Weinhold error = _kern_set_partition_name(fPartition->PartitionID(),
66300868ceSIngo Weinhold &changeCounter, fChild->PartitionID(), &childChangeCounter,
67300868ceSIngo Weinhold fString);
68300868ceSIngo Weinhold updateChildChangeCounter = true;
69300868ceSIngo Weinhold break;
70300868ceSIngo Weinhold case B_DISK_DEVICE_JOB_SET_CONTENT_NAME:
71300868ceSIngo Weinhold error = _kern_set_partition_content_name(fPartition->PartitionID(),
72300868ceSIngo Weinhold &changeCounter, fString);
73300868ceSIngo Weinhold break;
74300868ceSIngo Weinhold case B_DISK_DEVICE_JOB_SET_TYPE:
75300868ceSIngo Weinhold error = _kern_set_partition_type(fPartition->PartitionID(),
76300868ceSIngo Weinhold &changeCounter, fChild->PartitionID(), &childChangeCounter,
77300868ceSIngo Weinhold fString);
78300868ceSIngo Weinhold updateChildChangeCounter = true;
79300868ceSIngo Weinhold break;
80300868ceSIngo Weinhold case B_DISK_DEVICE_JOB_SET_PARAMETERS:
81300868ceSIngo Weinhold error = _kern_set_partition_parameters(fPartition->PartitionID(),
82300868ceSIngo Weinhold &changeCounter, fChild->PartitionID(), &childChangeCounter,
83*f75b8de3SAxel Dörfler fString);
84300868ceSIngo Weinhold updateChildChangeCounter = true;
85300868ceSIngo Weinhold break;
86300868ceSIngo Weinhold case B_DISK_DEVICE_JOB_SET_CONTENT_PARAMETERS:
87300868ceSIngo Weinhold error = _kern_set_partition_content_parameters(
88*f75b8de3SAxel Dörfler fPartition->PartitionID(), &changeCounter, fString);
89300868ceSIngo Weinhold break;
90300868ceSIngo Weinhold default:
9125ab0d1aSIngo Weinhold return B_BAD_VALUE;
9225ab0d1aSIngo Weinhold }
9325ab0d1aSIngo Weinhold
94300868ceSIngo Weinhold if (error != B_OK)
95300868ceSIngo Weinhold return error;
96300868ceSIngo Weinhold
97300868ceSIngo Weinhold fPartition->SetChangeCounter(changeCounter);
98300868ceSIngo Weinhold if (updateChildChangeCounter)
99300868ceSIngo Weinhold fChild->SetChangeCounter(childChangeCounter);
100300868ceSIngo Weinhold
101300868ceSIngo Weinhold return B_OK;
102300868ceSIngo Weinhold }
103300868ceSIngo Weinhold
104