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