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