sbuild  1.6.10
sbuild-mntstream.h
1 /* Copyright © 2003,2006-2008 Roger Leigh <rleigh@debian.org>
2  *
3  * schroot is free software: you can redistribute it and/or modify it
4  * under the terms of the GNU General Public License as published by
5  * the Free Software Foundation, either version 3 of the License, or
6  * (at your option) any later version.
7  *
8  * schroot is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  * General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see
15  * <http://www.gnu.org/licenses/>.
16  *
17  *********************************************************************/
18 
19 #ifndef SBUILD_MNTSTREAM_H
20 #define SBUILD_MNTSTREAM_H
21 
22 #include <sbuild/sbuild-custom-error.h>
23 
24 #include <iostream>
25 #include <deque>
26 #include <string>
27 
28 #include <stdio.h>
29 #include <sys/types.h>
30 #include <mntent.h>
31 
32 namespace sbuild
33 {
34 
46  class mntstream
47  {
48  public:
51  {
54  };
55 
58 
65  struct mntentry
66  {
69  {};
70 
76  mntentry (struct mntent const& entry);
77 
79  std::string filesystem_name;
81  std::string directory;
83  std::string type;
85  std::string options;
89  int fsck_pass;
90  };
91 
97  mntstream(std::string const& file);
98 
100  virtual ~mntstream();
101 
112  void open(std::string const& file);
113 
121  void close();
122 
130  bool eof() const;
131 
139  bool bad() const;
140 
147  operator bool ();
148 
155  bool
156  operator ! ();
157 
158  friend mntstream&
159  operator >> (mntstream& stream,
160  mntentry& entry);
161 
162  private:
173  void read (int quantity=1);
174 
176  std::string file;
177 
179  FILE *mntfile;
180 
185  std::deque<mntentry> data;
186 
189 
192  };
193 
202  mntstream&
203  operator >> (mntstream& stream,
204  mntstream::mntentry& entry);
205 
206 }
207 
208 #endif /* SBUILD_MNTSTREAM_H */
209 
210 /*
211  * Local Variables:
212  * mode:C++
213  * End:
214  */
An entry in a mntstream.
Definition: sbuild-mntstream.h:65
mntentry()
The constructor.
Definition: sbuild-mntstream.h:68
virtual ~mntstream()
The destructor.
Definition: sbuild-mntstream.cc:76
Access mounts.
Definition: sbuild-mntstream.h:46
FILE * mntfile
The underlying FILE stream.
Definition: sbuild-mntstream.h:179
Debian source builder components.
Definition: sbuild-auth-null.h:24
std::deque< mntentry > data
A list of mntentries represents the mount file stream as a LIFO stack.
Definition: sbuild-mntstream.h:185
std::string type
Mount type.
Definition: sbuild-mntstream.h:83
error_code
Error codes.
Definition: sbuild-mntstream.h:50
std::string filesystem_name
Name of mounted filesystem.
Definition: sbuild-mntstream.h:79
Failed to read mount file.
Definition: sbuild-mntstream.h:53
friend mntstream & operator>>(mntstream &stream, mntentry &entry)
The overloaded extraction operator.
bool eof() const
Check for End Of File.
Definition: sbuild-mntstream.cc:144
bool bad() const
Check for errors.
Definition: sbuild-mntstream.cc:150
void open(std::string const &file)
Open a mount file for reading.
Definition: sbuild-mntstream.cc:82
void read(int quantity=1)
Read mntents from the underlying FILE stream into the data deque.
Definition: sbuild-mntstream.cc:99
std::string file
The file name.
Definition: sbuild-mntstream.h:176
int dump_frequency
Dump frequency (days).
Definition: sbuild-mntstream.h:87
bool error_status
Error status.
Definition: sbuild-mntstream.h:188
std::string options
Mount options.
Definition: sbuild-mntstream.h:85
Custom error.
Definition: sbuild-custom-error.h:32
Failed to open mount file.
Definition: sbuild-mntstream.h:52
void close()
Close the mount file.
Definition: sbuild-mntstream.cc:129
int fsck_pass
Parallel fsck pass number.
Definition: sbuild-mntstream.h:89
std::string directory
File system path prefix.
Definition: sbuild-mntstream.h:81
mntstream(std::string const &file)
The constructor.
Definition: sbuild-mntstream.cc:65
bool operator!()
Check if the mntstream status is bad.
Definition: sbuild-mntstream.cc:161
bool eof_status
End of File status.
Definition: sbuild-mntstream.h:191
sbuild::custom_error< error_code > error
Exception type.
Definition: sbuild-mntstream.h:57