Line data Source code
1 : // Snap Websites Server -- read mount points in Linux
2 : // Copyright (c) 2013-2019 Made to Order Software Corp. All Rights Reserved
3 : //
4 : // This program is free software; you can redistribute it and/or modify
5 : // it under the terms of the GNU General Public License as published by
6 : // the Free Software Foundation; either version 2 of the License, or
7 : // (at your option) any later version.
8 : //
9 : // This program is distributed in the hope that it will be useful,
10 : // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 : // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 : // GNU 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, write to the Free Software
16 : // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 :
18 :
19 : // self
20 : //
21 : #include "snapwebsites/mounts.h"
22 :
23 :
24 : // last include
25 : //
26 : #include <snapdev/poison.h>
27 :
28 :
29 :
30 :
31 : namespace snap
32 : {
33 :
34 :
35 :
36 : /** \brief Read all the mount points defined in file defined by \p path.
37 : *
38 : * This function reads all the mount points found in the file pointed by
39 : * \p path and adds them to this mounts object which is a vector.
40 : *
41 : * You have full access to the vector once the mounts constructor returns
42 : * so you can add or delete entries if you want to.
43 : *
44 : * \param[in] path The path to a fstab file such as "/etc/fstab" or
45 : * "/proc/mounts".
46 : */
47 0 : mounts::mounts(std::string const& path)
48 0 : : f_path(path)
49 : {
50 : struct mntent *m;
51 : FILE *in;
52 :
53 0 : in = setmntent(path.c_str(), "r");
54 0 : if(in == nullptr)
55 : {
56 0 : throw snap_mounts_exception_io_error("mounts() cannot open \"/proc/mounts\"");
57 : }
58 :
59 0 : while(m = getmntent(in))
60 : {
61 0 : push_back(mount_entry(m));
62 : }
63 :
64 0 : endmntent(in);
65 0 : }
66 :
67 :
68 :
69 :
70 : } // namespace snap
71 :
72 : // vim: ts=4 sw=4 et
|