1 /* 2 * Copyright 2007, Ingo Weinhold, ingo_weinhold@gmx.de. 3 * Distributed under the terms of the MIT License. 4 */ 5 6 7 #include "SetStringJob.h" 8 9 #include <syscalls.h> 10 11 #include "DiskDeviceUtils.h" 12 #include "PartitionReference.h" 13 14 15 // constructor 16 SetStringJob::SetStringJob(PartitionReference* partition, 17 PartitionReference* child) 18 : 19 DiskDeviceJob(partition, child), 20 fString(NULL) 21 { 22 } 23 24 25 // destructor 26 SetStringJob::~SetStringJob() 27 { 28 free(fString); 29 } 30 31 32 // Init 33 status_t 34 SetStringJob::Init(const char* string, uint32 jobType) 35 { 36 switch (jobType) { 37 case B_DISK_DEVICE_JOB_SET_NAME: 38 case B_DISK_DEVICE_JOB_SET_CONTENT_NAME: 39 case B_DISK_DEVICE_JOB_SET_TYPE: 40 case B_DISK_DEVICE_JOB_SET_PARAMETERS: 41 case B_DISK_DEVICE_JOB_SET_CONTENT_PARAMETERS: 42 break; 43 default: 44 return B_BAD_VALUE; 45 } 46 47 fJobType = jobType; 48 SET_STRING_RETURN_ON_ERROR(fString, string); 49 50 return B_OK; 51 } 52 53 54 // Do 55 status_t 56 SetStringJob::Do() 57 { 58 int32 changeCounter = fPartition->ChangeCounter(); 59 int32 childChangeCounter = (fChild ? fChild->ChangeCounter() : 0); 60 status_t error; 61 bool updateChildChangeCounter = false; 62 63 switch (fJobType) { 64 case B_DISK_DEVICE_JOB_SET_NAME: 65 error = _kern_set_partition_name(fPartition->PartitionID(), 66 &changeCounter, fChild->PartitionID(), &childChangeCounter, 67 fString); 68 updateChildChangeCounter = true; 69 break; 70 case B_DISK_DEVICE_JOB_SET_CONTENT_NAME: 71 error = _kern_set_partition_content_name(fPartition->PartitionID(), 72 &changeCounter, fString); 73 break; 74 case B_DISK_DEVICE_JOB_SET_TYPE: 75 error = _kern_set_partition_type(fPartition->PartitionID(), 76 &changeCounter, fChild->PartitionID(), &childChangeCounter, 77 fString); 78 updateChildChangeCounter = true; 79 break; 80 case B_DISK_DEVICE_JOB_SET_PARAMETERS: 81 error = _kern_set_partition_parameters(fPartition->PartitionID(), 82 &changeCounter, fChild->PartitionID(), &childChangeCounter, 83 fString); 84 updateChildChangeCounter = true; 85 break; 86 case B_DISK_DEVICE_JOB_SET_CONTENT_PARAMETERS: 87 error = _kern_set_partition_content_parameters( 88 fPartition->PartitionID(), &changeCounter, fString); 89 break; 90 default: 91 return B_BAD_VALUE; 92 } 93 94 if (error != B_OK) 95 return error; 96 97 fPartition->SetChangeCounter(changeCounter); 98 if (updateChildChangeCounter) 99 fChild->SetChangeCounter(childChangeCounter); 100 101 return B_OK; 102 } 103 104