[24167] | 1 | /* Copyright © 2008-2009 Jan-Marek Glogowski <glogow@fbihome.de> |
---|
| 2 | * Copyright © 2005-2009 Roger Leigh <rleigh@debian.org> |
---|
| 3 | * |
---|
| 4 | * schroot is free software: you can redistribute it and/or modify it |
---|
| 5 | * under the terms of the GNU General Public License as published by |
---|
| 6 | * the Free Software Foundation, either version 3 of the License, or |
---|
| 7 | * (at your option) any later version. |
---|
| 8 | * |
---|
| 9 | * schroot is distributed in the hope that it will be useful, but |
---|
| 10 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
| 12 | * General Public License for more details. |
---|
| 13 | * |
---|
| 14 | * You should have received a copy of the GNU General Public License |
---|
| 15 | * along with this program. If not, see |
---|
| 16 | * <http://www.gnu.org/licenses/>. |
---|
| 17 | * |
---|
| 18 | *********************************************************************/ |
---|
| 19 | |
---|
| 20 | #ifndef SBUILD_CHROOT_FACET_UNION_H |
---|
| 21 | #define SBUILD_CHROOT_FACET_UNION_H |
---|
| 22 | |
---|
| 23 | #include <sbuild/sbuild-chroot-facet.h> |
---|
| 24 | |
---|
| 25 | namespace sbuild |
---|
| 26 | { |
---|
| 27 | |
---|
| 28 | /** |
---|
| 29 | * Chroot support for filesystem union based sessions. |
---|
| 30 | * |
---|
| 31 | * A chroot may offer session support using a filesystem union like |
---|
| 32 | * aufs or unionfs. A new union type may need to adapt the 10mount |
---|
| 33 | * or 05union script to properly populate the underlay and mount |
---|
| 34 | * directory. The overlay directory and union setup is already |
---|
| 35 | * handled. |
---|
| 36 | */ |
---|
| 37 | class chroot_facet_union : public chroot_facet |
---|
| 38 | { |
---|
| 39 | public: |
---|
| 40 | /// Error codes. |
---|
| 41 | enum error_code |
---|
| 42 | { |
---|
| 43 | UNION_TYPE_UNKNOWN, ///< Unknown filesystem union type. |
---|
| 44 | UNION_OVERLAY_ABS, ///< Union overlay must have an absolute path. |
---|
| 45 | UNION_UNDERLAY_ABS ///< Union underlay must have an absolute path. |
---|
| 46 | }; |
---|
| 47 | |
---|
| 48 | /// Exception type. |
---|
| 49 | typedef custom_error<error_code> error; |
---|
| 50 | |
---|
| 51 | /// A shared_ptr to a chroot facet object. |
---|
| 52 | typedef std::tr1::shared_ptr<chroot_facet_union> ptr; |
---|
| 53 | |
---|
| 54 | /// A shared_ptr to a const chroot facet object. |
---|
| 55 | typedef std::tr1::shared_ptr<const chroot_facet_union> const_ptr; |
---|
| 56 | |
---|
| 57 | private: |
---|
| 58 | /// The constructor. |
---|
| 59 | chroot_facet_union (); |
---|
| 60 | |
---|
| 61 | public: |
---|
| 62 | /// The destructor. |
---|
| 63 | virtual ~chroot_facet_union (); |
---|
| 64 | |
---|
| 65 | /** |
---|
| 66 | * Create a chroot facet. |
---|
| 67 | * |
---|
| 68 | * @returns a shared_ptr to the new chroot facet. |
---|
| 69 | */ |
---|
| 70 | static ptr |
---|
| 71 | create (); |
---|
| 72 | |
---|
| 73 | virtual chroot_facet::ptr |
---|
| 74 | clone () const; |
---|
| 75 | |
---|
| 76 | std::string const& |
---|
| 77 | get_name () const; |
---|
| 78 | |
---|
| 79 | void |
---|
| 80 | clone_source_setup (chroot::ptr& clone) const; |
---|
| 81 | |
---|
| 82 | /** |
---|
| 83 | * Get fs union configured state. |
---|
| 84 | * |
---|
| 85 | * @returns if fs union is configured |
---|
| 86 | */ |
---|
| 87 | bool |
---|
| 88 | get_union_configured () const; |
---|
| 89 | |
---|
| 90 | /** |
---|
| 91 | * Get the filesystem union type. |
---|
| 92 | * |
---|
| 93 | * @see set_union_type |
---|
| 94 | * @returns the union filesytem type. |
---|
| 95 | */ |
---|
| 96 | virtual std::string const& |
---|
| 97 | get_union_type () const; |
---|
| 98 | |
---|
| 99 | /** |
---|
| 100 | * Set the filesystem union type. |
---|
| 101 | * |
---|
| 102 | * Currently supported values are aufs, unionfs and none. |
---|
| 103 | * |
---|
| 104 | * @param union_type the filesystem type. |
---|
| 105 | **/ |
---|
| 106 | virtual void |
---|
| 107 | set_union_type (std::string const& union_type); |
---|
| 108 | |
---|
| 109 | /** |
---|
| 110 | * Get the filesystem union mount options (branch configuration). |
---|
| 111 | * |
---|
| 112 | * @see set_union_mount_options |
---|
| 113 | * @returns the filesystem union branch configuration. |
---|
| 114 | */ |
---|
| 115 | virtual std::string const& |
---|
| 116 | get_union_mount_options () const; |
---|
| 117 | |
---|
| 118 | /** |
---|
| 119 | * Set the filesystem union mount options (branch configuration). |
---|
| 120 | * |
---|
| 121 | * Normally a temporary directory is used as the writeable branch, |
---|
| 122 | * which is removed on session end. This allows the building of a |
---|
| 123 | * complex union which can merge multiple branches. The string has |
---|
| 124 | * to be constructed as expected by the filesystem union type and |
---|
| 125 | * is directly used as the mount '-o' option string. |
---|
| 126 | * |
---|
| 127 | * @param union_mount_options a union filesystem-specific branch |
---|
| 128 | * description |
---|
| 129 | **/ |
---|
| 130 | virtual void |
---|
| 131 | set_union_mount_options (std::string const& union_mount_options); |
---|
| 132 | |
---|
| 133 | /** |
---|
| 134 | * Get the union overlay directory. |
---|
| 135 | * |
---|
| 136 | * @returns the writeable overlay directory. |
---|
| 137 | */ |
---|
| 138 | virtual std::string const& |
---|
| 139 | get_union_overlay_directory () const; |
---|
| 140 | |
---|
| 141 | /** |
---|
| 142 | * Set the union overlay directory. |
---|
| 143 | * |
---|
| 144 | * @returns the writeable overlay directory. |
---|
| 145 | */ |
---|
| 146 | virtual void |
---|
| 147 | set_union_overlay_directory (std::string const& directory); |
---|
| 148 | |
---|
| 149 | /** |
---|
| 150 | * Get the union underlay directory. |
---|
| 151 | * |
---|
| 152 | * @returns the writeable underlay directory. |
---|
| 153 | */ |
---|
| 154 | virtual std::string const& |
---|
| 155 | get_union_underlay_directory () const; |
---|
| 156 | |
---|
| 157 | /** |
---|
| 158 | * Set the union underlay directory. |
---|
| 159 | * |
---|
| 160 | * @returns the writeable underlay directory. |
---|
| 161 | */ |
---|
| 162 | virtual void |
---|
| 163 | set_union_underlay_directory (std::string const& directory); |
---|
| 164 | |
---|
| 165 | virtual void |
---|
| 166 | setup_env (chroot const& chroot, |
---|
| 167 | environment& env) const; |
---|
| 168 | |
---|
| 169 | virtual chroot::session_flags |
---|
| 170 | get_session_flags (chroot const& chroot) const; |
---|
| 171 | |
---|
| 172 | virtual void |
---|
| 173 | get_details (chroot const& chroot, |
---|
| 174 | format_detail& detail) const; |
---|
| 175 | |
---|
| 176 | virtual void |
---|
| 177 | get_keyfile (chroot const& chroot, |
---|
| 178 | keyfile& keyfile) const; |
---|
| 179 | |
---|
| 180 | virtual void |
---|
| 181 | set_keyfile (chroot& chroot, |
---|
| 182 | keyfile const& keyfile, |
---|
| 183 | string_list& used_keys); |
---|
| 184 | |
---|
| 185 | private: |
---|
| 186 | /// filesystem union type. |
---|
| 187 | std::string union_type; |
---|
| 188 | /// Union mount options (branch configuration). |
---|
| 189 | std::string union_mount_options; |
---|
| 190 | /// Union read-write overlay directory. |
---|
| 191 | std::string union_overlay_directory; |
---|
| 192 | /// Union read-only underlay directory. |
---|
| 193 | std::string union_underlay_directory; |
---|
| 194 | }; |
---|
| 195 | |
---|
| 196 | } |
---|
| 197 | |
---|
| 198 | #endif /* SBUILD_CHROOT_FACET_UNION_H */ |
---|
| 199 | |
---|
| 200 | /* |
---|
| 201 | * Local Variables: |
---|
| 202 | * mode:C++ |
---|
| 203 | * End: |
---|
| 204 | */ |
---|