xref: /haiku/src/kits/storage/disk_device/jobs/CreateChildJob.cpp (revision 16d5c24e533eb14b7b8a99ee9f3ec9ba66335b1e)
1 /*
2  * Copyright 2007, Ingo Weinhold, ingo_weinhold@gmx.de.
3  * Distributed under the terms of the MIT License.
4  */
5 
6 #include "CreateChildJob.h"
7 
8 #include <syscalls.h>
9 
10 #include "DiskDeviceUtils.h"
11 #include "PartitionReference.h"
12 
13 
14 // constructor
15 CreateChildJob::CreateChildJob(PartitionReference* partition,
16 		PartitionReference* child)
17 	: DiskDeviceJob(partition, child),
18 	  fOffset(0),
19 	  fSize(0),
20 	  fType(NULL),
21 	  fName(NULL),
22 	  fParameters(NULL)
23 {
24 }
25 
26 
27 // destructor
28 CreateChildJob::~CreateChildJob()
29 {
30 	free(fType);
31 	free(fName);
32 	free(fParameters);
33 }
34 
35 
36 // Init
37 status_t
38 CreateChildJob::Init(off_t offset, off_t size, const char* type,
39 	const char* name, const char* parameters)
40 {
41 	fOffset = offset;
42 	fSize = size;
43 
44 	SET_STRING_RETURN_ON_ERROR(fType, type);
45 	SET_STRING_RETURN_ON_ERROR(fName, name);
46 	SET_STRING_RETURN_ON_ERROR(fParameters, parameters);
47 
48 	return B_OK;
49 }
50 
51 
52 // Do
53 status_t
54 CreateChildJob::Do()
55 {
56 	int32 changeCounter = fPartition->ChangeCounter();
57 	partition_id childID;
58 	int32 childChangeCounter;
59 	status_t error = _kern_create_child_partition(fPartition->PartitionID(),
60 		&changeCounter, fOffset, fSize, fType, fName, fParameters,
61 		fParameters ? strlen(fParameters) : 0, &childID, &childChangeCounter);
62 	if (error != B_OK)
63 		return error;
64 
65 	fPartition->SetChangeCounter(changeCounter);
66 	fChild->SetTo(childID, childChangeCounter);
67 
68 	return B_OK;
69 }
70 
71