~thopiekar/zypper/libzypp-manual-import

« back to all changes in this revision

Viewing changes to zypp/media/Mount.h

  • Committer: Thomas-Karl Pietrowski
  • Date: 2014-01-29 22:44:28 UTC
  • Revision ID: thopiekar@googlemail.com-20140129224428-gpcqnsdakby362n8
firstĀ import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*---------------------------------------------------------------------\
 
2
|                          ____ _   __ __ ___                          |
 
3
|                         |__  / \ / / . \ . \                         |
 
4
|                           / / \ V /|  _/  _/                         |
 
5
|                          / /__ | | | | | |                           |
 
6
|                         /_____||_| |_| |_|                           |
 
7
|                                                                      |
 
8
\---------------------------------------------------------------------*/
 
9
/** \file zypp/media/Mount.h
 
10
 *
 
11
*/
 
12
 
 
13
// -*- C++ -*-
 
14
 
 
15
#ifndef ZYPP_MEDIA_MOUNT_H
 
16
#define ZYPP_MEDIA_MOUNT_H
 
17
 
 
18
#include <set>
 
19
#include <map>
 
20
#include <string>
 
21
#include <iosfwd>
 
22
 
 
23
#include "zypp/ExternalProgram.h"
 
24
#include "zypp/KVMap.h"
 
25
 
 
26
namespace zypp {
 
27
  namespace media {
 
28
 
 
29
 
 
30
    /**
 
31
     * A "struct mntent" like mount entry structure,
 
32
     * but using std::strings.
 
33
     */
 
34
    struct MountEntry
 
35
    {
 
36
        MountEntry(const std::string &source,
 
37
                   const std::string &target,
 
38
                   const std::string &fstype,
 
39
                   const std::string &options,
 
40
                   const int         dumpfreq = 0,
 
41
                   const int         passnum  = 0)
 
42
            : src(source)
 
43
            , dir(target)
 
44
            , type(fstype)
 
45
            , opts(options)
 
46
            , freq(dumpfreq)
 
47
            , pass(passnum)
 
48
        {}
 
49
 
 
50
        std::string src;  //!< name of mounted file system
 
51
        std::string dir;  //!< file system path prefix
 
52
        std::string type; //!< filesystem / mount type
 
53
        std::string opts; //!< mount options
 
54
        int         freq; //!< dump frequency in days
 
55
        int         pass; //!< pass number on parallel fsck
 
56
    };
 
57
 
 
58
    /** \relates MountEntry
 
59
     * A vector of mount entries.
 
60
     */
 
61
    typedef std::vector<MountEntry> MountEntries;
 
62
 
 
63
    /** \relates MountEntry Stream output */
 
64
    std::ostream & operator<<( std::ostream & str, const MountEntry & obj );
 
65
 
 
66
    /**
 
67
     * @short Interface to the mount program
 
68
     */
 
69
    class Mount
 
70
    {
 
71
    public:
 
72
 
 
73
        /**
 
74
         * For passing additional environment variables
 
75
         * to mount
 
76
         **/
 
77
        typedef ExternalProgram::Environment Environment;
 
78
 
 
79
        /**
 
80
         * Mount options. 'key' or 'key=value' pairs, separated by ','
 
81
         **/
 
82
        typedef KVMap<kvmap::KVMapBase::CharSep<'=',','> > Options;
 
83
 
 
84
    public:
 
85
 
 
86
        /**
 
87
        * Create an new instance.
 
88
        */
 
89
        Mount();
 
90
 
 
91
        /**
 
92
        * Clean up.
 
93
        */
 
94
        ~Mount();
 
95
 
 
96
        /**
 
97
        * mount device
 
98
        *
 
99
        * @param source what to mount (e.g. /dev/hda3)
 
100
        * @param target where to mount (e.g. /mnt)
 
101
        * @param filesystem which filesystem to use (e.g. reiserfs) (-t parameter)
 
102
        * @param options mount options (e.g. ro) (-o parameter)
 
103
        * @param environment optinal environment to pass (e.g. PASSWD="sennah")
 
104
        *
 
105
        * \throws MediaException
 
106
        *
 
107
        */
 
108
 
 
109
        void mount ( const std::string& source,
 
110
                        const std::string& target,
 
111
                        const std::string& filesystem,
 
112
                        const std::string& options,
 
113
                        const Environment& environment = Environment() );
 
114
 
 
115
        /** umount device
 
116
         *
 
117
         * @param path device or mountpoint to umount
 
118
        *
 
119
        * \throws MediaException
 
120
        *
 
121
         * */
 
122
        void umount (const std::string& path);
 
123
 
 
124
    public:
 
125
 
 
126
        /**
 
127
        * Return mount entries from /etc/mtab or /etc/fstab file.
 
128
        *
 
129
        * @param mtab The name of the (mounted) file system description
 
130
        *             file to read from. This file should be one /etc/mtab,
 
131
        *             /etc/fstab or /proc/mounts. Default is to read
 
132
        *             /proc/mounts and /etc/mtab in case is not a symlink
 
133
        *             to /proc/mounts.
 
134
        * @returns A vector with mount entries or empty vector if reading
 
135
        *          or parsing of the mtab file(s) failed.
 
136
        */
 
137
        static MountEntries
 
138
        getEntries(const std::string &mtab = "");
 
139
 
 
140
    private:
 
141
 
 
142
        /** The connection to the mount process.
 
143
         * */
 
144
        ExternalProgram *process;
 
145
 
 
146
        /**
 
147
         * Run mount with the specified arguments and handle stderr.
 
148
         * @param argv Mount arguments
 
149
         * @param environment Addittional environment to set
 
150
         * @param stderr_disp How to handle stderr, merged with stdout by default
 
151
         * */
 
152
        void run( const char *const *argv, const Environment& environment,
 
153
                  ExternalProgram::Stderr_Disposition stderr_disp =
 
154
                  ExternalProgram::Stderr_To_Stdout);
 
155
 
 
156
        void run( const char *const *argv,
 
157
                  ExternalProgram::Stderr_Disposition stderr_disp =
 
158
                  ExternalProgram::Stderr_To_Stdout) {
 
159
          Environment notused;
 
160
          run( argv, notused, stderr_disp );
 
161
        }
 
162
 
 
163
        /** Return the exit status of the process, closing the connection if
 
164
         * not already done.
 
165
         * */
 
166
        int Status();
 
167
 
 
168
        /** Forcably kill the process
 
169
         * */
 
170
        void Kill();
 
171
 
 
172
 
 
173
        /** The exit code of the process, or -1 if not yet known.
 
174
         * */
 
175
        int exit_code;
 
176
    };
 
177
 
 
178
 
 
179
  } // namespace media
 
180
} // namespace zypp
 
181
 
 
182
#endif