Skip to content

Commit a053169

Browse files
author
Peter Watkins
committed
Initial commit
1 parent 597b700 commit a053169

23 files changed

+2230
-0
lines changed

CHANGES

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Release 0.9.0:
2+
By Peter V. Watkins <[email protected]> (19-May-17)
3+
4+
* First public release of fuse-cpp-ramfs
5+

CMakeLists.txt

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
cmake_minimum_required(VERSION 2.6)
2+
project(fuse-cpp-ramfs)
3+
4+
if(WIN32)
5+
set(SHAREDIR ".")
6+
set(DOCDIR "doc")
7+
elseif(APPLE)
8+
set(SHAREDIR "${CMAKE_INSTALL_PREFIX}/share/${PROJECT_NAME}")
9+
set(DOCDIR "share/doc/${PROJECT_NAME}")
10+
set(MANDIR "share/man")
11+
elseif(UNIX) # Linux, BSD etc
12+
set(SHAREDIR "share/${PROJECT_NAME}")
13+
set(DOCDIR "share/doc/${PROJECT_NAME}")
14+
set(MANDIR "share/man")
15+
endif()
16+
17+
18+
add_subdirectory(src)
19+
add_subdirectory(doc)
20+
21+
#install(DIRECTORY sample_data DESTINATION "${SHAREDIR}")

COPYING

+165
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
GNU LESSER GENERAL PUBLIC LICENSE
2+
Version 3, 29 June 2007
3+
4+
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5+
Everyone is permitted to copy and distribute verbatim copies
6+
of this license document, but changing it is not allowed.
7+
8+
9+
This version of the GNU Lesser General Public License incorporates
10+
the terms and conditions of version 3 of the GNU General Public
11+
License, supplemented by the additional permissions listed below.
12+
13+
0. Additional Definitions.
14+
15+
As used herein, "this License" refers to version 3 of the GNU Lesser
16+
General Public License, and the "GNU GPL" refers to version 3 of the GNU
17+
General Public License.
18+
19+
"The Library" refers to a covered work governed by this License,
20+
other than an Application or a Combined Work as defined below.
21+
22+
An "Application" is any work that makes use of an interface provided
23+
by the Library, but which is not otherwise based on the Library.
24+
Defining a subclass of a class defined by the Library is deemed a mode
25+
of using an interface provided by the Library.
26+
27+
A "Combined Work" is a work produced by combining or linking an
28+
Application with the Library. The particular version of the Library
29+
with which the Combined Work was made is also called the "Linked
30+
Version".
31+
32+
The "Minimal Corresponding Source" for a Combined Work means the
33+
Corresponding Source for the Combined Work, excluding any source code
34+
for portions of the Combined Work that, considered in isolation, are
35+
based on the Application, and not on the Linked Version.
36+
37+
The "Corresponding Application Code" for a Combined Work means the
38+
object code and/or source code for the Application, including any data
39+
and utility programs needed for reproducing the Combined Work from the
40+
Application, but excluding the System Libraries of the Combined Work.
41+
42+
1. Exception to Section 3 of the GNU GPL.
43+
44+
You may convey a covered work under sections 3 and 4 of this License
45+
without being bound by section 3 of the GNU GPL.
46+
47+
2. Conveying Modified Versions.
48+
49+
If you modify a copy of the Library, and, in your modifications, a
50+
facility refers to a function or data to be supplied by an Application
51+
that uses the facility (other than as an argument passed when the
52+
facility is invoked), then you may convey a copy of the modified
53+
version:
54+
55+
a) under this License, provided that you make a good faith effort to
56+
ensure that, in the event an Application does not supply the
57+
function or data, the facility still operates, and performs
58+
whatever part of its purpose remains meaningful, or
59+
60+
b) under the GNU GPL, with none of the additional permissions of
61+
this License applicable to that copy.
62+
63+
3. Object Code Incorporating Material from Library Header Files.
64+
65+
The object code form of an Application may incorporate material from
66+
a header file that is part of the Library. You may convey such object
67+
code under terms of your choice, provided that, if the incorporated
68+
material is not limited to numerical parameters, data structure
69+
layouts and accessors, or small macros, inline functions and templates
70+
(ten or fewer lines in length), you do both of the following:
71+
72+
a) Give prominent notice with each copy of the object code that the
73+
Library is used in it and that the Library and its use are
74+
covered by this License.
75+
76+
b) Accompany the object code with a copy of the GNU GPL and this license
77+
document.
78+
79+
4. Combined Works.
80+
81+
You may convey a Combined Work under terms of your choice that,
82+
taken together, effectively do not restrict modification of the
83+
portions of the Library contained in the Combined Work and reverse
84+
engineering for debugging such modifications, if you also do each of
85+
the following:
86+
87+
a) Give prominent notice with each copy of the Combined Work that
88+
the Library is used in it and that the Library and its use are
89+
covered by this License.
90+
91+
b) Accompany the Combined Work with a copy of the GNU GPL and this license
92+
document.
93+
94+
c) For a Combined Work that displays copyright notices during
95+
execution, include the copyright notice for the Library among
96+
these notices, as well as a reference directing the user to the
97+
copies of the GNU GPL and this license document.
98+
99+
d) Do one of the following:
100+
101+
0) Convey the Minimal Corresponding Source under the terms of this
102+
License, and the Corresponding Application Code in a form
103+
suitable for, and under terms that permit, the user to
104+
recombine or relink the Application with a modified version of
105+
the Linked Version to produce a modified Combined Work, in the
106+
manner specified by section 6 of the GNU GPL for conveying
107+
Corresponding Source.
108+
109+
1) Use a suitable shared library mechanism for linking with the
110+
Library. A suitable mechanism is one that (a) uses at run time
111+
a copy of the Library already present on the user's computer
112+
system, and (b) will operate properly with a modified version
113+
of the Library that is interface-compatible with the Linked
114+
Version.
115+
116+
e) Provide Installation Information, but only if you would otherwise
117+
be required to provide such information under section 6 of the
118+
GNU GPL, and only to the extent that such information is
119+
necessary to install and execute a modified version of the
120+
Combined Work produced by recombining or relinking the
121+
Application with a modified version of the Linked Version. (If
122+
you use option 4d0, the Installation Information must accompany
123+
the Minimal Corresponding Source and Corresponding Application
124+
Code. If you use option 4d1, you must provide the Installation
125+
Information in the manner specified by section 6 of the GNU GPL
126+
for conveying Corresponding Source.)
127+
128+
5. Combined Libraries.
129+
130+
You may place library facilities that are a work based on the
131+
Library side by side in a single library together with other library
132+
facilities that are not Applications and are not covered by this
133+
License, and convey such a combined library under terms of your
134+
choice, if you do both of the following:
135+
136+
a) Accompany the combined library with a copy of the same work based
137+
on the Library, uncombined with any other library facilities,
138+
conveyed under the terms of this License.
139+
140+
b) Give prominent notice with the combined library that part of it
141+
is a work based on the Library, and explaining where to find the
142+
accompanying uncombined form of the same work.
143+
144+
6. Revised Versions of the GNU Lesser General Public License.
145+
146+
The Free Software Foundation may publish revised and/or new versions
147+
of the GNU Lesser General Public License from time to time. Such new
148+
versions will be similar in spirit to the present version, but may
149+
differ in detail to address new problems or concerns.
150+
151+
Each version is given a distinguishing version number. If the
152+
Library as you received it specifies that a certain numbered version
153+
of the GNU Lesser General Public License "or any later version"
154+
applies to it, you have the option of following the terms and
155+
conditions either of that published version or of any later version
156+
published by the Free Software Foundation. If the Library as you
157+
received it does not specify a version number of the GNU Lesser
158+
General Public License, you may choose any version of the GNU Lesser
159+
General Public License ever published by the Free Software Foundation.
160+
161+
If the Library as you received it specifies that a proxy can decide
162+
whether future versions of the GNU Lesser General Public License shall
163+
apply, that proxy's public statement of acceptance of any version is
164+
permanent authorization for you to choose that version for the
165+
Library.

README.rst

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
======================================================================
2+
fuse-cpp-ramfs: An example RAM filesystem using FUSE written in C++
3+
======================================================================
4+
5+
.. contents::
6+
7+
Quick Run
8+
=========
9+
::
10+
11+
cd build
12+
cmake ../src
13+
make
14+
make install
15+
16+
17+
Requirements
18+
============
19+
fuse-cpp-ramfs builds with CMake version 2.6 or greater.
20+
21+
fuse-cpp-ramfs requires the libfuse2-1.0.1 (or later)
22+
filesystem-in-userspace library and header files for successful
23+
compilation. libfuse is available
24+
at:
25+
https://github.com/libfuse/libfuse
26+
https://osxfuse.github.io
27+
28+
--
29+
Peter Watkins
30+
19-May-2017
31+

doc/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
add_subdirectory(english)

doc/english/CMakeLists.txt

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
add_custom_command(OUTPUT fuse-cpp-ramfs.ps
2+
COMMAND groff -e -T ps -man ${CMAKE_CURRENT_SOURCE_DIR}/fuse-cpp-ramfs.man > fuse-cpp-ramfs.ps
3+
DEPENDS fuse-cpp-ramfs.man
4+
COMMENT "Creating postscript file")
5+
add_custom_target(postscript ALL
6+
DEPENDS fuse-cpp-ramfs.ps)
7+
8+
# Set GROFF_NO_SGR because the following txt rule running ul is incompatible with the
9+
# default.
10+
add_custom_command(OUTPUT fuse-cpp-ramfs.1
11+
COMMAND export GROFF_NO_SGR=1 && groff -e -T ascii -man ${CMAKE_CURRENT_SOURCE_DIR}/fuse-cpp-ramfs.man > fuse-cpp-ramfs.1
12+
DEPENDS fuse-cpp-ramfs.man
13+
COMMENT "Creating man page")
14+
add_custom_target(man ALL
15+
DEPENDS fuse-cpp-ramfs.1)
16+
17+
add_custom_command(OUTPUT fuse-cpp-ramfs.txt
18+
COMMAND ul -t dumb fuse-cpp-ramfs.1 > fuse-cpp-ramfs.txt
19+
DEPENDS fuse-cpp-ramfs.1
20+
COMMENT "Creating text file")
21+
add_custom_target(txt ALL
22+
DEPENDS fuse-cpp-ramfs.txt)
23+
24+
add_custom_command(OUTPUT fuse-cpp-ramfs.pdf
25+
COMMAND ps2pdf fuse-cpp-ramfs.ps > fuse-cpp-ramfs.pdf
26+
DEPENDS fuse-cpp-ramfs.ps
27+
COMMENT "Creating pdf file")
28+
add_custom_target(pdf ALL
29+
DEPENDS fuse-cpp-ramfs.pdf)
30+
31+
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/fuse-cpp-ramfs.ps" DESTINATION "${DOCDIR}")
32+
install(FILES fuse-cpp-ramfs.man DESTINATION "${MANDIR}/man1" RENAME fuse-cpp-ramfs.1)
33+
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/fuse-cpp-ramfs.txt" DESTINATION "${DOCDIR}")
34+
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/fuse-cpp-ramfs.pdf" DESTINATION "${DOCDIR}")

doc/english/fuse-cpp-ramfs.man

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
.TH fuse-cpp-ramfs 1 "19 May 2017" "Peter Watkins" "Peter Watkins"
2+
.SH NAME
3+
fuse-cpp-ramfs An example RAM Filesysetem for using FUSE and written in C++.
4+
.SH SYNOPSIS
5+
fuse-cpp-ramfs
6+
.br
7+
.SH DESCRIPTION
8+
\fBfuse-cpp-ramfs\fP An example RAM Filesysetem for using FUSE and written in C++.
9+
\fBfuse-cpp-ramfs\fP is free software, and is designed for operation on POSIX
10+
operating systems. Redistribution and/or modification
11+
is permitted under the terms of the Lesser GNU General Public License, Version 3,
12+
as published by the Free Software Foundation.
13+
.PP
14+
\fBfuse-cpp-ramfs\fP is distributed in the hope that it will be useful, but
15+
WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY
16+
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17+
for more details.
18+
.SH ADDITIONAL INFORMATION
19+
The latest news and information regarding \fBfuse-cpp-ramfs\fP software is
20+
available through the official \fBfuse-cpp-ramfs\fP software web page located
21+
at: \fIhttp://www.github.com/watkipet/fuse-cpp-ramfs\fP.
22+
.SH AUTHORS
23+
.TP
24+
Peter Watkins <\fI[email protected]\fP>
25+
Creator, Lead Developer
26+

src/CMakeLists.txt

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
add_executable(fuse-cpp-ramfs main.cpp directory.cpp inode.cpp symlink.cpp file.cpp util.cpp fuse_cpp_ramfs.cpp special_inode.cpp)
2+
set_property(TARGET fuse-cpp-ramfs PROPERTY CXX_STANDARD 11)
3+
target_compile_definitions(fuse-cpp-ramfs PRIVATE FUSE_USE_VERSION=29)
4+
if(APPLE)
5+
target_link_libraries(fuse-cpp-ramfs osxfuse)
6+
target_compile_definitions(fuse-cpp-ramfs PRIVATE _FILE_OFFSET_BITS=64)
7+
elseif(UNIX) # Linux, BSD etc
8+
target_link_libraries(fuse-cpp-ramfs fuse)
9+
endif()
10+
install(TARGETS fuse-cpp-ramfs DESTINATION bin)

src/directory.cpp

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/** @file directory.cpp
2+
* @copyright 2016 Peter Watkins. All rights reserved.
3+
*/
4+
5+
#include <cstdio>
6+
#include <string>
7+
#include <map>
8+
#include <cerrno>
9+
#include <osxfuse/fuse/fuse_lowlevel.h>
10+
11+
#include "inode.hpp"
12+
#include "directory.hpp"
13+
14+
using namespace std;
15+
16+
/**
17+
Returns a child inode number given the name of the child.
18+
19+
@param name The child file / dir name.
20+
@return The child inode number if the child is found. -1 otherwise.
21+
*/
22+
fuse_ino_t Directory::ChildInodeNumberWithName(const string &name) {
23+
if (m_children.find(name) == m_children.end()) {
24+
return -1;
25+
}
26+
27+
return m_children[name];
28+
}
29+
30+
31+
/**
32+
Changes the inode number of the child with the given name.
33+
34+
@param name The name of the child to update.
35+
@param ino The new inode number.
36+
@return The old inode number before the change.
37+
*/
38+
fuse_ino_t Directory::UpdateChild(const string &name, fuse_ino_t ino) {
39+
fuse_ino_t ino_ret = m_children[name];
40+
m_children[name] = ino;
41+
42+
// TODO: What about directory sizes? Shouldn't we increase the reported size of our dir?
43+
44+
return ino_ret;
45+
}
46+
47+
int Directory::WriteAndReply(fuse_req_t req, const char *buf, size_t size, off_t off) {
48+
return fuse_reply_err(req, EISDIR);
49+
}
50+
51+
int Directory::ReadAndReply(fuse_req_t req, size_t size, off_t off) {
52+
return fuse_reply_err(req, EISDIR);
53+
}

src/directory.hpp

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/** @file directory.hpp
2+
* @copyright 2016 Peter Watkins. All rights reserved.
3+
*/
4+
5+
#ifndef directory_hpp
6+
#define directory_hpp
7+
8+
class Directory : public Inode {
9+
private:
10+
std::map<std::string, fuse_ino_t> m_children;
11+
public:
12+
~Directory() {}
13+
14+
fuse_ino_t ChildInodeNumberWithName(const std::string &name);
15+
fuse_ino_t UpdateChild(const std::string &name, fuse_ino_t ino);
16+
int WriteAndReply(fuse_req_t req, const char *buf, size_t size, off_t off);
17+
int ReadAndReply(fuse_req_t req, size_t size, off_t off);
18+
19+
const std::map<std::string, fuse_ino_t> &Children() { return m_children; }
20+
};
21+
22+
#endif /* directory_hpp */

0 commit comments

Comments
 (0)