Dobby  3.0
Dobby “Docker based Thingy” is a tool for managing and running OCI containers using crun
LoopMountDetails.h
1 /*
2 * If not stated otherwise in this file or this component's LICENSE file the
3 * following copyright and licenses apply:
4 *
5 * Copyright 2022 Sky UK
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19 /*
20  * File: LoopMountDetails.h
21  *
22  */
23 #ifndef LOOPMOUNTDETAILS_H
24 #define LOOPMOUNTDETAILS_H
25 
26 #include "MountProperties.h"
27 
28 #include <RdkPluginBase.h>
29 
30 #include <sys/types.h>
31 #include <string>
32 #include <list>
33 #include <memory>
34 
35 class RefCountFile;
36 
37 
38 // -----------------------------------------------------------------------------
49 {
50 public:
51  LoopMountDetails() = delete;
55 
56 private:
57  friend class Storage;
58 
59 public:
60  LoopMountDetails(const std::string& rootfsPath,
61  const LoopMountProperties& mount,
62  const uid_t& userId,
63  const gid_t& groupId,
64  const std::shared_ptr<DobbyRdkPluginUtils> &utils);
65 
66 public:
67  bool doLoopMount(const std::string& loopDevice);
68 
69  bool onPreCreate();
70 
71  bool setPermissions();
72 
73  bool remountTempDirectory();
74 
75  bool cleanupTempDirectory();
76 
78 
79 private:
80  std::unique_ptr<RefCountFile> getRefCountFile();
81 
82 private:
83  std::string mMountPointInsideContainer;
84  std::string mTempMountPointOutsideContainer;
85  LoopMountProperties mMount;
86  uid_t mUserId;
87  gid_t mGroupId;
88 
89  const std::shared_ptr<DobbyRdkPluginUtils> mUtils;
90 };
91 
92 #endif // !defined(LOOPMOUNTDETAILS_H)
Class that represents a single loop mount within a container.
Definition: LoopMountDetails.h:49
bool onPreCreate()
Opens the data.img file and mounts it to temp location inside container.
Definition: LoopMountDetails.cpp:76
bool setPermissions()
Sets permissions for container to access directories.
Definition: LoopMountDetails.cpp:216
bool removeNonPersistentImage()
Checks if image should be non persistent and if so remove it.
Definition: LoopMountDetails.cpp:336
bool doLoopMount(const std::string &loopDevice)
Performs the loop mount, this should be called prior to the container being runned.
Definition: LoopMountDetails.cpp:159
bool remountTempDirectory()
Mounts temp directory into desired one, then cleans old files.
Definition: LoopMountDetails.cpp:268
bool cleanupTempDirectory()
Cleans up temp mount and directory.
Definition: LoopMountDetails.cpp:298
std::unique_ptr< RefCountFile > getRefCountFile()
Open the reference count file for the data.img file.
Definition: LoopMountDetails.cpp:378
Class that represents a reference count file.
Definition: RefCountFile.h:41
Dobby RDK Storage Plugin.
Definition: Storage.h:45
LoopMountProperties struct used for Storage plugin.
Definition: MountProperties.h:35