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