fuse-zip-0.7.2/.hg_archival.txt 0000644 0000000 0000000 00000000171 14005532107 014472 0 ustar 0000000 0000000 repo: 38472f434ab14d41686baaa73679d7fe4773f0f2
node: 22f688df78665e73a3b9d4a1bd84f232900897f7
branch: default
tag: 0.7.2
fuse-zip-0.7.2/.gitignore 0000777 0000000 0000000 00000000000 14005532107 015175 2.hgignore ustar 0000000 0000000 fuse-zip-0.7.2/.hgignore 0000644 0000000 0000000 00000000445 14005532107 013213 0 ustar 0000000 0000000 syntax: glob
# ignore vim swapfiles
.*.swp
# ignore source archives
fuse-zip*.tar.gz
# ignore generated files
*.o
fuse-zip
fuse-zip.1.gz
lib/*.a
# tests
tests/whitebox/*.x
# other related projects (needed for performance tests)
others
# utils
utils/dump-extrafld
utils/create-content-size
fuse-zip-0.7.2/.hgsub 0000644 0000000 0000000 00000000014 14005532107 012511 0 ustar 0000000 0000000 wiki = wiki
fuse-zip-0.7.2/.hgsubstate 0000644 0000000 0000000 00000000056 14005532107 013560 0 ustar 0000000 0000000 71d0cc5e1852a98cf2a7089194ff48e8b51a4e31 wiki
fuse-zip-0.7.2/.hgtags 0000644 0000000 0000000 00000002075 14005532107 012667 0 ustar 0000000 0000000 0ac39c893b9516994afab8e0524765a1cd54739b 0.2.0
0d5865a7fb53959088bfd4b1edc028de8c64de53 0.2.6
1e34f469bf9d39a34cf2dcd74be3762f75787cf9 0.2.5
581b06b7cee2b7691125e2907683f4e834e90301 0.1.0
5e0f0c7ae8049eb675386622c53d5f0b487512a6 0.2.3
9513e1d44bf99244b9a037ea30cc01fbe8ea5856 0.2.1
9ab3241a6822263558b2db2a9e26c0f4d2ca524f 0.2.4
fd88cde887ac7405b81f2c9a73a61ed6af2fc99a 0.2.2
80ad596796392ffedd0281c822d8f4bfd537134f 0.2.7
ab463806418aff3429772941253e0f63503b58a2 0.2.8
5edac8c7e535a992741658de1ba1fcb6058e1305 0.2.9
5edac8c7e535a992741658de1ba1fcb6058e1305 0.2.9
95321b27fefb951c3026beddbe5820ef4c3ac4b1 0.2.9
19110f42d5f6ed094bbdeead843a969845b18907 0.2.10
256f2f59af7b8e099479157507852cfd00bbf085 0.2.11
e941c5cc7a9c1eb115fd1f4db7907dddc2cbc8dc 0.2.12
3dd1661895752bb47dc11b37f0c8afa7fff9e272 0.2.13
e7fb616bdf63d7cb3be55c538115e71999855bc1 0.3.0
4226ca631f6f3365174985de97dab23ba1ba3fa6 0.3.1
4226ca631f6f3365174985de97dab23ba1ba3fa6 0.3.1
0e13d2229d40bcfc04d3ee439a04e8d7a13edcc8 0.3.1
94d2f38966e55006069773b677bc5396f4c9376d 0.3.2
d99546ce0477a15c9c0f279451b8d6e06eec55cb 0.4.0
fuse-zip-0.7.2/INSTALL 0000644 0000000 0000000 00000001205 14005532107 012434 0 ustar 0000000 0000000 You need the following libraries:
libfuse >= 2.7 http://fuse.sourceforge.net
libzip >= 1.0 http://libzip.org
The following tools are required for compilation:
C++ compiler g++ 4.8.1 or other modern C++11 compilant compiler
pkg-config http://pkg-config.freedesktop.org/
GNU make http://www.gnu.org/software/make/
The following tools are required for running blackbox auto-tests:
* Tcl >= 8.6
* BLT library
* Tclx >= 8.4
* tcllib
* fusermount from FUSE package
* zip
* unzip
To build fuse-zip do the following:
$ make release
To install do:
# make install
as root or use sudo.
To uninstall:
# make uninstall
fuse-zip-0.7.2/LICENSE 0000644 0000000 0000000 00000104516 14005532107 012421 0 ustar 0000000 0000000
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc.
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
Copyright (C)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
Copyright (C)
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
.
fuse-zip-0.7.2/Makefile 0000644 0000000 0000000 00000004251 14005532107 013047 0 ustar 0000000 0000000 DEST=fuse-zip
prefix=/usr/local
exec_prefix=$(prefix)
bindir=$(exec_prefix)/bin
datarootdir=$(prefix)/share
docdir=$(datarootdir)/doc/$(DEST)
mandir=$(datarootdir)/man
man1dir=$(mandir)/man1
manext=.1
LIBS=-Llib -lfusezip $(shell $(PKG_CONFIG) fuse --libs) $(shell $(PKG_CONFIG) libzip --libs)
LIB=lib/libfusezip.a
CXXFLAGS=-g -O0 -Wall -Wextra -Wconversion -Wsign-conversion -Wlogical-op -Wshadow -pedantic -Werror -std=c++11
RELEASE_CXXFLAGS=-O2 -Wall -Wextra -Wconversion -Wsign-conversion -Wlogical-op -Wshadow -pedantic -Werror -std=c++11
PKG_CONFIG?=pkg-config
FUSEFLAGS=$(shell $(PKG_CONFIG) fuse --cflags)
ZIPFLAGS=$(shell $(PKG_CONFIG) libzip --cflags)
SOURCES=main.cpp
OBJECTS=$(SOURCES:.cpp=.o)
MANSRC=fuse-zip.1
MAN=fuse-zip$(manext).gz
CLEANFILES=$(OBJECTS) $(MAN)
DOCFILES=README.md changelog
INSTALL=install
INSTALL_PROGRAM=$(INSTALL)
INSTALL_DATA=$(INSTALL) -m 644
all: $(DEST)
doc: $(MAN)
doc-clean: man-clean
$(DEST): $(OBJECTS) $(LIB)
$(CXX) $(OBJECTS) $(LDFLAGS) $(LIBS) \
-o $@
main.o: main.cpp
$(CXX) -c $(CXXFLAGS) $(FUSEFLAGS) $(ZIPFLAGS) $< \
-Ilib \
-o $@
$(LIB):
$(MAKE) -C lib
lib-clean:
$(MAKE) -C lib clean
distclean: clean doc-clean
rm -f $(DEST)
clean: lib-clean all-clean check-clean tarball-clean
all-clean:
rm -f $(CLEANFILES)
$(MAN): $(MANSRC)
gzip -c9 $< > $@
man-clean:
rm -f $(MANSRC).gz
install: all doc
mkdir -p "$(DESTDIR)$(bindir)/"
$(INSTALL_PROGRAM) "$(DEST)" "$(DESTDIR)$(bindir)/"
mkdir -p "$(DESTDIR)$(docdir)/"
$(INSTALL_DATA) $(DOCFILES) "$(DESTDIR)$(docdir)/"
mkdir -p "$(DESTDIR)$(man1dir)/"
$(INSTALL_DATA) $(MAN) "$(DESTDIR)$(man1dir)/"
install-strip:
$(MAKE) INSTALL_PROGRAM='$(INSTALL_PROGRAM) -s' install
uninstall:
rm "$(DESTDIR)$(bindir)/$(DEST)"
rm -r "$(DESTDIR)$(docdir)"
rm "$(DESTDIR)$(man1dir)/$(MAN)"
dist:
./makeArchives.sh
tarball-clean:
rm -f fuse-zip-*.tar.gz fuse-zip-tests-*.tar.gz
release:
$(MAKE) CXXFLAGS="$(RELEASE_CXXFLAGS)" all doc
check: $(DEST)
$(MAKE) -C tests
check-clean:
$(MAKE) -C tests clean
valgrind:
$(MAKE) -C tests valgrind
.PHONY: all release doc clean all-clean lib-clean doc-clean check-clean tarball-clean distclean install uninstall dist check valgrind $(LIB)
fuse-zip-0.7.2/README.md 0000644 0000000 0000000 00000012627 14005532107 012674 0 ustar 0000000 0000000 # ABOUT #
fuse-zip is a FUSE file system to navigate, extract, create and modify ZIP and
ZIP64 archives based on libzip implemented in C++.
With fuse-zip you really can work with ZIP archives as real directories.
Unlike KIO or Gnome VFS, it can be used in any application without
modifications.
* File system features:
* Read-only and read-write modes.
* Transparent packing and unpacking.
* File types:
* regular files, sockets, symbolic links, block and character devices, FIFOs;
* hard links (read-only mode).
* Create/edit/rename/delete files and directories.
* Read/modify/save file access modes and owner/group information.
* Sparse files.
* Relative and absolute paths (read-only mode).
* File name encoding conversion on the fly (using iconv module).
* Access to file and archive comments via extended attribute "user.comment".
* File creation/modification/access/change times with nanosecond resolution.
* Time stamp precision:
* at least 1 s resolution for all files;
* 100 ns resolution for all created files or files with NTFS extra field (see also force\_precise\_time option);
* Note: high-resolution time stamps for symbolic links, block and character devices are saved in local directory only.
* ZIP file format features:
* ZIP64: support for more than 65535 files in archive, support for files bigger than 4 Gb.
* Compression methods: store (no compression), deflate, bzip2.
* Time fields: creation, modify and access time.
* UNIX permissions: variable-length UID and GID, file access modes.
* DOS file permissions.
* File and archive comments.
* Supported ZIP format extensions:
* 000A PKWARE NTFS Extra Field - high-precision timestamps;
* 000D PKWARE UNIX Extra Field:
* regular files, sockets, symbolic links, block and character devices, FIFOs;
* hard links (read-only mode);
* 5455 extended timestamp;
* 5855 Info-ZIP UNIX extra field (type 1);
* 7855 Info-ZIP Unix Extra Field (type 2);
* 7875 Info-ZIP New Unix Extra Field - variable-length UIDs and GIDs.
Since version 0.3.0 fuse-zip has support for absolute and parent-relative paths
in file names, but only in read-only mode (-r command line switch). Absolute
paths are displayed under "ROOT" directory, every ".." in path replaced by "UP"
in directory name and "normal" files are placed under "CUR" directory.
File/archive comments are supported since version 0.7.0. To read/modify file
comment use extended attribute "user.comment". Archive comment is accessible
via mount point's extended attribute.
High-precision time stamps (with 100 ns resolution) are supported since version
0.7.0. By default high precision timestamp is saved to archive only for new
files or files with known creation time. You can force high-precision time
saving by specifying '-o force\_precise\_time' option. In this case creation time
will be equal to a first known file modification time.
Release 0.7.0 adds read and write support for all UNIX special file types:
symbolic links, block and character devices, sockets and FIFOs. Hard links are
supported in read-only mode. Note that block/character devices, sockets and FIFOs
are not supported by Info-Zip tools such as unzip.
Unlike other FUSE filesystems, _only_ fuse-zip provides write support to ZIP
archives. Also, fuse-zip is faster than all known implementations on large
archives with many files.
You can download fuse-zip at https://bitbucket.org/agalanin/fuse-zip
Repository mirror: http://galanin.nnov.ru/hg/fuse-zip
# AUTHOR #
Alexander Galanin
* E-mail: al@galanin.nnov.ru
* Home page: http://galanin.nnov.ru/~al/
# LICENSE #
fuse-zip are licensed under GNU GPL v3 or later.
# USAGE #
```
$ mkdir /tmp/zipArchive
$ fuse-zip foobar.zip /tmp/zipArchive
(do something with the mounted file system)
$ fusermount -u /tmp/zipArchive
```
If ZIP file does not exists, it will be created after filesystem unmounting.
Be patient. Wait for fuse-zip process finish after unmounting especially on
a big archives.
If you want to specify character set conversion for file names in archive,
use the following fusermount options:
-omodules=iconv,from_code=$charset1,to_code=$charset2
Those Russian who uses archives from the "other OS" should use CP866 as
'charset1' and locale charset as 'charset2'.
See FUSE documentation for details.
Look at /var/log/user.log in case of any errors.
# PERFORMANCE #
On a small archives fuse-zip have the same performance with commonly used
virtual filesystems like KIO, Gnome GVFS, mc vfs, unpackfs, avfs, fuse-j-zip.
But on large archives with many file (like zipped Linux kernel sources)
fuse-zip have the greatest speed.
You can download test suite from the web-site and make sure that it is true.
# PERMISSIONS #
Support for UNIX file permissions and owner information has been added in
version 0.4. Note that access check will not be performed unless
'-o default\_permissions' mount option is given.
# HINTS #
* Added/changed files resides into memory until you unmount file system.
* Adding/unpacking very big files(more than one half of available memory) may
cause your system swapping. It is a good idea to use zip/unzip in that case
:)
* After adding/modifying files in archive it will be repacked at filesystem
unmount. Hence, your file system must have enough space to keep temporary
files.
* Wait until fuse-zip process is finished after unmount before using archive
file.
fuse-zip-0.7.2/changelog 0000644 0000000 0000000 00000015577 14005532107 013276 0 ustar 0000000 0000000 2021-01-31 Alexander Galanin
* Released 0.7.2:
- Allow pkg-config binary override (patch from François Degros).
- Fix compiler warning (patch from thanhminhmr).
- Add .gitignore since BitBucket repository are now in git format.
2020-06-20 Alexander Galanin
* Released 0.7.1:
- Issue #67: treat file nodes with zero file type bits as regular files.
2019-09-08 Alexander Galanin
* Released 0.7.0:
- PKWARE NTFS extra field support. Support high-precision timestamps
via this extension.
- PKWARE NTFS extra field: preserve 'reserved' field and unknown tags.
- Full read support for PKWARE UNIX extra field features. Write
support for all PKWARE UNIX features except hard links.
- Full support for block/character devices, sockets and FIFOs.
- Read only support for hard links.
- Support for file and archive comments.
- Work-around for PKWARE's interpretation of 'version made by' field.
- Support FUSE 2.9.
- Update ctime on rename.
- Now requires C++11-compilant compiler to build.
2019-08-03 Alexander Galanin
* Released 0.6.2:
- Fixed parsing of Info-Zip New Unix extra field if size of UID or GID
is less than size of uid_t or gid_t.
2019-07-17 Alexander Galanin
* Released 0.6.1:
- Fixed extra field timestamps parsing on 64-bit systems.
- Fixed compilation with gcc 8.3.0 (patch from Michael Davis), closes
issue #55.
2019-03-12 Alexander Galanin
* Released 0.6.0:
- Fixed incompatibility with iconv module.
- inode numbers is now unique.
- Include libzip version on --version output.
- Set minimum libzip version to 1.0, remove deprecated functions usage.
- Fixed extended set of compiler warnings (type conversion, old style
casts).
- Added debug utils.
2018-12-01 Alexander Galanin
* Released 0.5.0:
- #54: Force open in read-only mode if archive file or its parent
directory is not writable.
2018-02-04 Alexander Galanin
* Released 0.4.5:
- #52: Print error message and exit on nonexistent file in read-only mode.
- #51: Check return value of chdir().
- Add Reiner Herrmann's patch to make the build reproducible.
- Fixed errors found by static code analysis.
2017-12-04 Alexander Galanin
* Released 0.4.4:
- Fixed problem with README installation.
2017-12-03 Alexander Galanin
* Released 0.4.3:
- License changed to GPLv3 or later because LGPLv3 is too confusing.
- Support mknod() system call.
- Fixed out of bounds write on sparse file (issue #50).
- Fixed timestamp and file attribute fields saving into archive.
2016-02-28 Alexander Galanin
* Released 0.4.2:
- Properly handle ZIP_SOURCE_SUPPORTS call introduced in libzip 1.0 (fixes #46)
2014-07-04 Alexander Galanin
* Released 0.4.1:
- Fixed problem with subdir module support.
- Applied makefile conventions from GNU Coding Standards.
2014-01-14 Alexander Galanin
* Released 0.4.0:
- Symbolic links (issue #8)
- UNIX file permissions and owner info (issue #36)
- DOS file attributes
- Creation/access time
2013-12-10 Alexander Galanin
* Released 0.3.2:
- Fixed compilation problem on Mac OS X
2013-12-07 Alexander Galanin
* Released 0.3.1:
- Fixed compilation problems
- Fixed memory reservation
2013-06-29 Alexander Galanin
* Released 0.3.0:
- ZIP64 support (issue #30, issue #34, issue #35)
- Relative and absolute paths support (issue #23)
- Fixed compilation problems (issue #29, issue #31)
2010-12-06 Alexander Galanin
* Released 0.2.13:
- Fixed issue #27: Android APK Support
- Fixed issue #28: doesn't honor the -r flag for some zip files
2010-02-07 Alexander Galanin
* Released 0.2.12:
- Fixed problem with lost new file after truncate().
- Fixed problems with rename(): Fixed various rename() problems: lost
path for subdirectory entries, duplicates of moved directories in a
hierarchy, invalid key in map after rename.
- Fixed unitialized values in read() call.
- Fixed memory leaks: buffer allocated for file content not freeed in
NEW state, incorrect buffer size in truncate().
- Fixed non-fatal memory leaks: FUSE options not freeed after use,
memory leak in help/version mode, internal data structures not freeed
if FUSE setup failed.
- More correct corrupted files handling.
- More correct memory insufficiency errors handling.
2010-01-26 Alexander Galanin
* Released 0.2.11:
- Fixed issue #25: does not compile with libfuse <= 2.8
2010-01-09 Alexander Galanin
* Released 0.2.10:
- Fixed issue #14: added '-r' option description.
- Added note about converting file names inside archive (for Russians
who uses 'another OS')
2010-01-08 Alexander Galanin
* Released 0.2.9:
- Fixed issue #22, now command-line options are correctly processed
2009-11-18 Alexander Galanin
* Released 0.2.8:
- Fixed issue #20: incorrect directory size reported
2008-12-06 Alexander Galanin
* Released 0.2.7:
- Fixed segfault if user tried to re-open corrupted file from an
invalid archive.
2008-09-29 Alexander Galanin
* Released 0.2.6:
- Fixed: Compilation error on FreeBSD/Mac OS X with FUSE 2.7
2008-08-24 Alexander Galanin
* Released 0.2.5:
- Fixed: Archives containing files whose parent directory does not
present in archive, reported as broken.
2008-08-09 Alexander Galanin
* Released 0.2.4:
- fixed wrong directory size on 32-bit Linux machines
2008-06-26 Alexander Galanin
* Released 0.2.3:
- fixed problem with time and size of new files
- free space on file system now equal to free space in archive dir
- added missing includes
- removed GNU-specific commands in Makefile
2008-06-16 Alexander Galanin
* Released 0.2.2:
- re-licensed under LGPLv3+
- fixed problem with file modification time
- fixed problems with compilation on non-Linux systems
2008-06-14 Alexander Galanin
* Released 0.2.1:
- fixed bug with file size on 32-bit systems
- fixed compilation problems on non-GNU platforms
- fixed compilation problems on GCC 4.3+
- added stubs for *xattr() system calls
- more checks for error cases
2008-06-11 Alexander Galanin
* Released 0.2.0:
- implemented all functions to mount archive read-write
- big internal refactoring
- added performance tests
- fixed problem with simultaneous file access
- fixed problem with one-character file names
* Known limitations:
- archives with items like '../../somefile' recognited as broken
2008-06-04 Alexander Galanin
* Initial release 0.1.0:
- implemented all base functions for read-only archive support
fuse-zip-0.7.2/config.h 0000644 0000000 0000000 00000002746 14005532107 013034 0 ustar 0000000 0000000 ////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2008-2021 by Alexander Galanin //
// al@galanin.nnov.ru //
// http://galanin.nnov.ru/~al //
// //
// This program is free software: you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation, either version 3 of the License, or //
// (at your option) any later version. //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program. If not, see .//
////////////////////////////////////////////////////////////////////////////
#ifndef CONFIG_H
#define CONFIG_H
#define FUSE_USE_VERSION 27
#define PROGRAM "fuse-zip"
#define VERSION "0.7.2"
#endif
fuse-zip-0.7.2/fuse-zip.1 0000644 0000000 0000000 00000006476 14005532107 013246 0 ustar 0000000 0000000 .\" '\" t
.\" ** The above line should force tbl to be a preprocessor **
.\" Man page for fuse-zip
.TH "fuse-zip" "1" "July 2019" "FUSE filesystem to read and modify ZIP archives" "FUSE filesystem to read and modify ZIP archives"
.SH "NAME"
fuse\-zip \- a FUSE filesystem for zip archives with write support
.SH "SYNOPSIS"
.\" The general command line
.B fuse\-zip
.RI [\| options \|]
zip\-file
mount\-point
.SH "OPTIONS"
.TP
\fB-h\fP
print help
.TP
\fB-V\fP
print version
.TP
\fB-r\fP
open archive in read\-only mode
.TP
\fB-o opt[,opt...]\fP
mount options (refer to
.BR mount.fuse (8)
for details)
.TP
\fB-f\fP
don't detach from terminal
.TP
\fB-d\fP
turn on debugging, also implies \-f
.SS "Specific mount options:"
.TP
\fBforce_precise_time\fP
By default high precision timestamp is saved to archive only for new
files or files with known creation time. You can force high-precision time
saving by specifying '-o force_precise_time' option. In this case creation time
will be equal to a first known file modification time.
.SH "DESCRIPTION"
.B fuse\-zip
is a FUSE filesystem, that enables any program to work with a ZIP archive as though it is a plain directory.
Unlike KIO or Gnome VFS, it can be used in any application without modifications.
Unlike other FUSE filesystems, only fuse\-zip provides write support to ZIP archives.
Also, fuse\-zip is faster than all known implementations on large archives with many files.
Since version 0.3.0 fuse-zip has support for absolute and parent-relative paths
in file names, but only in read-only mode (-r command line switch). Absolute
paths are displayed under "ROOT" directory, every ".." in path replaced by "UP"
in directory name and "normal" files are placed under "CUR" directory.
Support for UNIX file permissions and owner information has been added in
version 0.4.0. See
.B PERMISSIONS
for details.
Since version 0.5.0 fuse-zip forces open in read-only mode if archive file or
its parent directory is not writable.
File/archive comments are supported since version 0.7.0. To read/modify file
comment use extended attribute "user.comment". Archive comment is accessible
via mount point's extended attribute.
If you want to specify character set conversion for file names in archive,
use the following fusermount options:
\-omodules=iconv,from_code=$charset1,to_code=$charset2
See FUSE documentation for details.
.SH "USAGE"
General usage would look like this
.TS
tab (@);
l l.
1@mkdir\ /tmp/zipArchive
2@fuse\-zip foobar.zip /tmp/zipArchive
3@(do something with the mounted file system)
4@fusermount \-u /tmp/zipArchive
.TE
.PP
Be patient. Wait for fuse-zip process finish after unmounting, especially on a big archives.
.SH "PERMISSIONS"
Access check will not be performed unless
\fB-o default_permissions\fP mount option is given.
.SH "FILES"
.TP
.if !'po4a'hide' .I /var/log/user.log
see this file in case any errors occur
.SH "SEE ALSO"
.BR fusermount (1),
.BR mount.fuse (8).
.SH "LICENSE"
.
This is Free Software; this software is licensed under the GPL version 3, as published by the Free Software Foundation, or later.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
.
.SH "AUTHORS"
.
Alexander Galanin http://galanin.nnov.ru/~al
.br
.
This manual page was originally written by Kirill Zaitsev . Updated by Alexander Galanin.
fuse-zip-0.7.2/lib/Makefile 0000644 0000000 0000000 00000001377 14005532107 013623 0 ustar 0000000 0000000 DEST=libfusezip.a
PKG_CONFIG?=pkg-config
LIBS=$(shell $(PKG_CONFIG) fuse --libs) $(shell $(PKG_CONFIG) libzip --libs)
CXXFLAGS=-g -O0 -Wall -Wextra -Wconversion -Wsign-conversion -Wlogical-op -Wshadow -pedantic -Werror -std=c++11
RELEASE_CXXFLAGS=-O2 -Wall -Wextra -Wconversion -Wsign-conversion -Wlogical-op -Wshadow -pedantic -Werror -std=c++11
FUSEFLAGS=$(shell $(PKG_CONFIG) fuse --cflags)
ZIPFLAGS=$(shell $(PKG_CONFIG) libzip --cflags)
SOURCES=$(sort $(wildcard *.cpp))
OBJECTS=$(SOURCES:.cpp=.o)
CLEANFILES=$(OBJECTS) $(DEST)
all: $(DEST)
release:
$(MAKE) CXXFLAGS="$(RELEASE_CXXFLAGS)" all
$(DEST): $(OBJECTS)
$(AR) -cr $@ $(OBJECTS)
.cpp.o:
$(CXX) -c $(CXXFLAGS) $(FUSEFLAGS) $(ZIPFLAGS) $< -o $@
clean:
rm -f $(DEST) $(OBJECTS)
.PHONY: all clean
fuse-zip-0.7.2/lib/bigBuffer.cpp 0000644 0000000 0000000 00000024601 14005532107 014555 0 ustar 0000000 0000000 ////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2008-2019 by Alexander Galanin //
// al@galanin.nnov.ru //
// http://galanin.nnov.ru/~al //
// //
// This program is free software: you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation, either version 3 of the License, or //
// (at your option) any later version. //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program. If not, see .//
////////////////////////////////////////////////////////////////////////////
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "bigBuffer.h"
/**
* Class that keep chunk of file data.
*/
class BigBuffer::ChunkWrapper {
private:
/**
* Pointer that keeps data for chunk. Can be NULL.
*/
char *m_ptr;
public:
/**
* By default internal buffer is NULL, so this can be used for creating
* sparse files.
*/
ChunkWrapper(): m_ptr(NULL) {
}
/**
* Take ownership on internal pointer from 'other' object.
*/
ChunkWrapper(const ChunkWrapper &other) {
m_ptr = other.m_ptr;
const_cast(&other)->m_ptr = NULL;
}
/**
* Free pointer if allocated.
*/
~ChunkWrapper() {
if (m_ptr != NULL) {
free(m_ptr);
}
}
/**
* Take ownership on internal pointer from 'other' object.
*/
ChunkWrapper &operator=(const ChunkWrapper &other) {
if (&other != this) {
m_ptr = other.m_ptr;
const_cast(&other)->m_ptr = NULL;
}
return *this;
}
/**
* Return pointer to internal storage and initialize it if needed.
* @throws
* std::bad_alloc If memory can not be allocated
*/
char *ptr(bool init = false) {
if (init && m_ptr == NULL) {
m_ptr = (char *)malloc(chunkSize);
if (m_ptr == NULL) {
throw std::bad_alloc();
}
}
return m_ptr;
}
/**
* Fill 'dest' with internal buffer content.
* If m_ptr is NULL, destination bytes is zeroed.
*
* @param dest Destination buffer.
* @param offset Offset in internal buffer to start reading from.
* @param count Number of bytes to be read.
*
* @return Number of bytes actually read. It can differ with 'count'
* if offset+count>chunkSize.
*/
size_t read(char *dest, unsigned int offset, size_t count) const {
if (offset + count > chunkSize) {
count = chunkSize - offset;
}
if (m_ptr != NULL) {
memcpy(dest, m_ptr + offset, count);
} else {
memset(dest, 0, count);
}
return count;
}
/**
* Fill internal buffer with bytes from 'src'.
* If m_ptr is NULL, memory for buffer is malloc()-ed and then head of
* allocated space is zeroed. After that byte copying is performed.
*
* @param src Source buffer.
* @param offset Offset in internal buffer to start writting from.
* @param count Number of bytes to be written.
*
* @return Number of bytes actually written. It can differ with
* 'count' if offset+count>chunkSize.
* @throws
* std::bad_alloc If there are no memory for buffer
*/
size_t write(const char *src, unsigned int offset, size_t count) {
if (offset + count > chunkSize) {
count = chunkSize - offset;
}
if (m_ptr == NULL) {
m_ptr = (char *)malloc(chunkSize);
if (m_ptr == NULL) {
throw std::bad_alloc();
}
if (offset > 0) {
memset(m_ptr, 0, offset);
}
}
memcpy(m_ptr + offset, src, count);
return count;
}
/**
* Clear tail of internal buffer with zeroes starting from 'offset'.
*/
void clearTail(unsigned int offset) {
if (m_ptr != NULL && offset < chunkSize) {
memset(m_ptr + offset, 0, chunkSize - offset);
}
}
};
BigBuffer::BigBuffer(): len(0) {
}
BigBuffer::BigBuffer(struct zip *z, zip_uint64_t nodeId, size_t length):
len(length) {
struct zip_file *zf = zip_fopen_index(z, nodeId, 0);
if (zf == NULL) {
syslog(LOG_WARNING, "%s", zip_strerror(z));
throw std::runtime_error(zip_strerror(z));
}
size_t ccount = chunksCount(length);
chunks.resize(ccount, ChunkWrapper());
size_t chunk = 0;
while (length > 0) {
size_t readSize = chunkSize;
if (readSize > length) {
readSize = length;
}
zip_int64_t nr = zip_fread(zf, chunks[chunk].ptr(true), readSize);
if (nr < 0) {
std::string err = zip_file_strerror(zf);
syslog(LOG_WARNING, "%s", err.c_str());
zip_fclose(zf);
throw std::runtime_error(err);
}
++chunk;
length -= static_cast(nr);
if ((nr == 0 || chunk == ccount) && length != 0) {
// Allocated memory are exhausted, but there are unread bytes (or
// file is longer that given length). Possibly CRC error.
zip_fclose(zf);
syslog(LOG_WARNING, "length of file %s differ from data length",
zip_get_name(z, nodeId, ZIP_FL_ENC_RAW));
throw std::runtime_error("data length differ");
}
}
if (zip_fclose(zf)) {
syslog(LOG_WARNING, "%s", zip_strerror(z));
throw std::runtime_error(zip_strerror(z));
}
}
BigBuffer::~BigBuffer() {
}
int BigBuffer::read(char *buf, size_t size, size_t offset) const {
if (offset > len) {
return 0;
}
size_t chunk = chunkNumber(offset);
unsigned int pos = chunkOffset(offset);
if (size > len - offset) {
size = len - offset;
}
if (size > INT_MAX)
size = INT_MAX;
int nread = static_cast(size);
while (size > 0) {
size_t r = chunks[chunk].read(buf, pos, size);
size -= r;
buf += r;
++chunk;
pos = 0;
}
return nread;
}
int BigBuffer::write(const char *buf, size_t size, size_t offset) {
size_t chunk = chunkNumber(offset);
unsigned int pos = chunkOffset(offset);
if (size > INT_MAX)
size = INT_MAX;
int nwritten = static_cast(size);
if (offset > len) {
if (chunkNumber(len) < chunksCount(len)) {
chunks[chunkNumber(len)].clearTail(chunkOffset(len));
}
len = size + offset;
} else if (size > unsigned(len - offset)) {
len = size + offset;
}
chunks.resize(chunksCount(len));
while (size > 0) {
size_t w = chunks[chunk].write(buf, pos, size);
size -= w;
buf += w;
++ chunk;
pos = 0;
}
return nwritten;
}
void BigBuffer::truncate(size_t offset) {
chunks.resize(chunksCount(offset));
if (offset > len && chunkNumber(len) < chunksCount(len)) {
// Fill end of last non-empty chunk with zeroes
chunks[chunkNumber(len)].clearTail(chunkOffset(len));
}
len = offset;
}
zip_int64_t BigBuffer::zipUserFunctionCallback(void *state, void *data,
zip_uint64_t len, enum zip_source_cmd cmd) {
CallBackStruct *b = (CallBackStruct*)state;
switch (cmd) {
case ZIP_SOURCE_OPEN: {
b->pos = 0;
return 0;
}
case ZIP_SOURCE_READ: {
size_t rlen = std::numeric_limits::max();
if (len < rlen)
rlen = static_cast(len);
int r = b->buf->read((char*)data, rlen, b->pos);
b->pos += static_cast(r);
return r;
}
case ZIP_SOURCE_STAT: {
struct zip_stat *st = (struct zip_stat*)data;
zip_stat_init(st);
st->valid = ZIP_STAT_SIZE | ZIP_STAT_MTIME;
st->size = b->buf->len;
st->mtime = b->mtime;
return sizeof(struct zip_stat);
}
case ZIP_SOURCE_FREE: {
delete b;
return 0;
}
case ZIP_SOURCE_CLOSE:
return 0;
case ZIP_SOURCE_ERROR: {
// This code should not be called in normal case because none of
// implemented functions raises error flag.
int *errs = static_cast(data);
errs[0] = ZIP_ER_OPNOTSUPP;
errs[1] = EINVAL;
return 2 * sizeof(int);
}
case ZIP_SOURCE_SUPPORTS:
return ZIP_SOURCE_SUPPORTS_READABLE;
default:
// indicate unsupported operation
return -1;
}
}
int BigBuffer::saveToZip(time_t mtime, struct zip *z, const char *fname,
bool newFile, zip_int64_t &index) {
struct zip_source *s;
struct CallBackStruct *cbs = new CallBackStruct();
cbs->buf = this;
cbs->mtime = mtime;
if ((s=zip_source_function(z, zipUserFunctionCallback, cbs)) == NULL) {
delete cbs;
return -ENOMEM;
}
if (newFile) {
zip_int64_t nid = zip_file_add(z, fname, s, ZIP_FL_ENC_GUESS);
if (nid < 0) {
delete cbs;
zip_source_free(s);
return -ENOMEM;
} else {
// indices are actually in range [0..2^63-1]
index = nid;
}
} else {
assert(index >= 0);
if (zip_file_replace(z, static_cast(index), s, ZIP_FL_ENC_GUESS) < 0) {
delete cbs;
zip_source_free(s);
return -ENOMEM;
}
}
return 0;
}
fuse-zip-0.7.2/lib/bigBuffer.h 0000644 0000000 0000000 00000011743 14005532107 014225 0 ustar 0000000 0000000 ////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2008-2019 by Alexander Galanin //
// al@galanin.nnov.ru //
// http://galanin.nnov.ru/~al //
// //
// This program is free software: you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation, either version 3 of the License, or //
// (at your option) any later version. //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program. If not, see .//
////////////////////////////////////////////////////////////////////////////
#ifndef BIG_BUFFER_H
#define BIG_BUFFER_H
#include
#include
#include
#include "types.h"
class BigBuffer {
private:
//TODO: use >> and <<
static const unsigned int chunkSize = 4*1024; //4 Kilobytes
class ChunkWrapper;
typedef std::vector chunks_t;
struct CallBackStruct {
size_t pos;
const BigBuffer *buf;
time_t mtime;
};
chunks_t chunks;
/**
* Callback for zip_source_function.
* See zip_source_function(3) for details.
*/
static zip_int64_t zipUserFunctionCallback(void *state, void *data,
zip_uint64_t len, enum zip_source_cmd cmd);
/**
* Return number of chunks needed to keep 'size' bytes.
*/
inline static size_t chunksCount(size_t size) {
return (size + chunkSize - 1) / chunkSize;
}
/**
* Return number of chunk where 'offset'-th byte is located.
*/
inline static size_t chunkNumber(size_t offset) {
return offset / chunkSize;
}
/**
* Return offset inside chunk to 'offset'-th byte.
*/
inline static unsigned int chunkOffset(size_t offset) {
return offset % chunkSize;
}
public:
size_t len;
/**
* Create new file buffer without mapping to file in a zip archive
*/
BigBuffer();
/**
* Read file data from file inside zip archive
*
* @param z Zip file
* @param nodeId Node index inside zip file
* @param length File length
* @throws
* std::exception On file read error
* std::bad_alloc On memory insufficiency
*/
BigBuffer(struct zip *z, zip_uint64_t nodeId, size_t length);
~BigBuffer();
/**
* Dispatch read requests to chunks of a file and write result to
* resulting buffer.
* Reading after end of file is not allowed, so 'size' is decreased to
* fit file boundaries.
*
* @param buf destination buffer
* @param size requested bytes count
* @param offset offset to start reading from
* @return number of bytes read
*/
int read(char *buf, size_t size, size_t offset) const;
/**
* Dispatch write request to chunks of a file and grow 'chunks' vector if
* necessary.
* If 'offset' is after file end, tail of last chunk cleared before growing.
*
* @param buf Source buffer
* @param size Number of bytes to be written
* @param offset Offset in file to start writing from
* @return number of bytes written
* @throws
* std::bad_alloc If there are no memory for buffer
*/
int write(const char *buf, size_t size, size_t offset);
/**
* Create (or replace) file element in zip file. Class instance should
* not be destroyed until zip_close() is called.
*
* @param mtime File modification time
* @param z ZIP archive structure
* @param fname File name
* @param newFile Is file not yet created?
* @param index (INOUT) File index in ZIP archive. Set if new file
* is created
* @return
* 0 If successfull
* -ENOMEM If there are no memory
*/
int saveToZip(time_t mtime, struct zip *z, const char *fname,
bool newFile, zip_int64_t &index);
/**
* Truncate buffer at position offset.
* 1. Free chunks after offset
* 2. Resize chunks vector to a new size
* 3. Fill data block that made readable by resize with zeroes
*
* @throws
* std::bad_alloc If insufficient memory available
*/
void truncate(size_t offset);
};
#endif
fuse-zip-0.7.2/lib/dataNode.cpp 0000644 0000000 0000000 00000033623 14005532107 014405 0 ustar 0000000 0000000 ////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2019 by Alexander Galanin //
// al@galanin.nnov.ru //
// http://galanin.nnov.ru/~al //
// //
// This program is free software: you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation, either version 3 of the License, or //
// (at your option) any later version. //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program. If not, see .//
////////////////////////////////////////////////////////////////////////////
#define __STDC_LIMIT_MACROS
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "dataNode.h"
#include "extraField.h"
#include "util.h"
DataNode::DataNode(zip_uint64_t id, mode_t mode, uid_t uid, gid_t gid, dev_t dev) {
_id = id;
_open_count = 0;
_size = 0;
_mode = mode;
_uid = uid;
_gid = gid;
_device = dev;
}
std::shared_ptr DataNode::createNew(mode_t mode, uid_t uid, gid_t gid, dev_t dev) {
std::shared_ptr n(new DataNode(FAKE_ID, mode, uid, gid, dev));
n->_state = NodeState::NEW;
n->_buffer.reset(new BigBuffer());
n->_has_btime = true;
n->_metadataChanged = true;
n->_mtime = n->_atime = n->_ctime = n->_btime = currentTime();
return n;
}
std::shared_ptr DataNode::createTmpDir(mode_t mode, uid_t uid, gid_t gid, dev_t dev) {
std::shared_ptr n(new DataNode(FAKE_ID, mode, uid, gid, dev));
n->_state = NodeState::NEW;
n->_buffer.reset(new BigBuffer());
n->_has_btime = true;
n->_metadataChanged = false;
n->_mtime = n->_atime = n->_ctime = n->_btime = currentTime();
return n;
}
std::shared_ptr DataNode::createExisting(struct zip *zip, zip_uint64_t id, mode_t mode) {
std::shared_ptr n(new DataNode(id, mode, 0, 0, 0));
n->_state = NodeState::CLOSED;
n->_metadataChanged = false;
struct zip_stat stat;
zip_stat_index(zip, id, 0, &stat);
// check that all used fields are valid
zip_uint64_t needValid = ZIP_STAT_NAME | ZIP_STAT_INDEX |
ZIP_STAT_SIZE | ZIP_STAT_MTIME;
// required fields are always valid for existing items or newly added
// directories (see zip_stat_index.c from libzip)
assert((stat.valid & needValid) == needValid);
n->_mtime.tv_sec = n->_atime.tv_sec = n->_ctime.tv_sec = n->_btime.tv_sec = stat.mtime;
n->_mtime.tv_nsec = n->_atime.tv_nsec = n->_ctime.tv_nsec = n->_btime.tv_nsec = 0;
n->_has_btime = false;
n->_size = stat.size;
bool hasPkWareField;
n->processExtraFields(zip, hasPkWareField);
// InfoZIP may produce FIFO-marked node with content, PkZip - can't.
if (S_ISFIFO(n->_mode)) {
unsigned int type = S_IFREG;
if (n->_size == 0 && hasPkWareField)
type = S_IFIFO;
n->_mode = (n->_mode & static_cast(~S_IFMT)) | type;
}
return n;
}
int DataNode::open(struct zip *zip) {
if (_state == NodeState::NEW || _state == NodeState::VIRTUAL_SYMLINK) {
return 0;
}
if (_state == NodeState::OPENED) {
if (_open_count == INT_MAX) {
return -EMFILE;
} else {
++_open_count;
}
}
if (_state == NodeState::CLOSED) {
_open_count = 1;
try {
assert(zip != NULL);
if (_size > std::numeric_limits::max()) {
return -ENOMEM;
}
assert(_id != FAKE_ID);
_buffer.reset(new BigBuffer(zip, _id, static_cast(_size)));
_state = NodeState::OPENED;
}
catch (std::bad_alloc&) {
return -ENOMEM;
}
catch (std::exception&) {
return -EIO;
}
}
return 0;
}
int DataNode::read(char *buf, size_t sz, size_t offset) {
_atime = currentTime();
return _buffer->read(buf, sz, offset);
}
int DataNode::write(const char *buf, size_t sz, size_t offset) {
assert(_state != NodeState::VIRTUAL_SYMLINK);
if (_state == NodeState::OPENED) {
_state = NodeState::CHANGED;
}
_mtime = currentTime();
_metadataChanged = true;
return _buffer->write(buf, sz, offset);
}
int DataNode::close() {
_size = _buffer->len;
if (_state == NodeState::OPENED && --_open_count == 0) {
_buffer.reset();
_state = NodeState::CLOSED;
}
return 0;
}
int DataNode::save(struct zip *zip, const char *full_name, zip_int64_t &index) {
assert(zip != NULL);
assert(full_name != NULL);
return _buffer->saveToZip(_mtime.tv_sec, zip, full_name,
_state == NodeState::NEW, index);
}
//int DataNode::saveMetadata(bool force_precise_time) const {
// assert(zip != NULL);
// assert(_id >= 0);
//
// int res = updateExtraFields(force_precise_time);
// if (res != 0)
// return res;
// return updateExternalAttributes();
//}
int DataNode::truncate(size_t offset) {
assert(_state != NodeState::VIRTUAL_SYMLINK);
if (_state != NodeState::CLOSED) {
if (_state != NodeState::NEW) {
_state = NodeState::CHANGED;
}
try {
_buffer->truncate(offset);
return 0;
}
catch (const std::bad_alloc &) {
return EIO;
}
_mtime = currentTime();
_metadataChanged = true;
} else {
return EBADF;
}
}
zip_uint64_t DataNode::size() const {
if (_state == NodeState::NEW || _state == NodeState::OPENED || _state == NodeState::CHANGED ||
_state == NodeState::VIRTUAL_SYMLINK) {
return _buffer->len;
} else {
return _size;
}
}
/**
* Get timestamp information from extra fields.
* Get owner and group information.
*/
void DataNode::processExtraFields(struct zip *zip, bool &hasPkWareField) {
zip_int16_t count;
// times from timestamp have precedence to UNIX field times
bool mtimeFromTimestamp = false, atimeFromTimestamp = false;
// high-precision timestamps have the highest precedence
bool highPrecisionTime = false;
// UIDs and GIDs from UNIX extra fields with bigger type IDs have
// precedence
int lastProcessedUnixField = 0;
hasPkWareField = false;
assert(zip != NULL);
// read central directory
count = zip_file_extra_fields_count (zip, _id, ZIP_FL_CENTRAL);
if (count > 0) {
for (zip_uint16_t i = 0; i < static_cast(count); ++i) {
struct timespec mt, at, cret;
zip_uint16_t type, len;
const zip_uint8_t *field = zip_file_extra_field_get (zip,
_id, i, &type, &len, ZIP_FL_CENTRAL);
switch (type) {
case FZ_EF_PKWARE_UNIX:
hasPkWareField = true;
processPkWareUnixField(type, len, field,
mtimeFromTimestamp, atimeFromTimestamp, highPrecisionTime,
lastProcessedUnixField);
break;
case FZ_EF_NTFS:
if (ExtraField::parseNtfsExtraField(len, field, mt, at, cret)) {
_mtime = mt;
_atime = at;
_btime = cret;
_has_btime = true;
highPrecisionTime = true;
}
break;
}
}
}
// read local headers
count = zip_file_extra_fields_count (zip, _id, ZIP_FL_LOCAL);
if (count < 0)
return;
for (zip_uint16_t i = 0; i < static_cast(count); ++i) {
bool has_mt, has_at, has_cret;
time_t mt, at, cret;
zip_uint16_t type, len;
const zip_uint8_t *field = zip_file_extra_field_get (zip,
_id, i, &type, &len, ZIP_FL_LOCAL);
switch (type) {
case FZ_EF_TIMESTAMP: {
if (ExtraField::parseExtTimeStamp (len, field, has_mt, mt,
has_at, at, has_cret, cret)) {
if (has_mt && !highPrecisionTime) {
_mtime.tv_sec = mt;
_mtime.tv_nsec = 0;
mtimeFromTimestamp = true;
}
if (has_at && !highPrecisionTime) {
_atime.tv_sec = at;
_atime.tv_nsec = 0;
atimeFromTimestamp = true;
}
if (has_cret && !highPrecisionTime) {
_btime.tv_sec = cret;
_btime.tv_nsec = 0;
_has_btime = true;
}
}
break;
}
case FZ_EF_PKWARE_UNIX:
hasPkWareField = true;
processPkWareUnixField(type, len, field,
mtimeFromTimestamp, atimeFromTimestamp, highPrecisionTime,
lastProcessedUnixField);
break;
case FZ_EF_INFOZIP_UNIX1:
{
bool has_uid_gid;
uid_t uid;
gid_t gid;
if (ExtraField::parseSimpleUnixField (type, len, field,
has_uid_gid, uid, gid, mt, at)) {
if (has_uid_gid && type >= lastProcessedUnixField) {
_uid = uid;
_gid = gid;
lastProcessedUnixField = type;
}
if (!mtimeFromTimestamp && !highPrecisionTime) {
_mtime.tv_sec = mt;
_mtime.tv_nsec = 0;
}
if (!atimeFromTimestamp && !highPrecisionTime) {
_atime.tv_sec = at;
_atime.tv_nsec = 0;
}
}
break;
}
case FZ_EF_INFOZIP_UNIX2:
case FZ_EF_INFOZIP_UNIXN: {
uid_t uid;
gid_t gid;
if (ExtraField::parseUnixUidGidField (type, len, field, uid, gid)) {
if (type >= lastProcessedUnixField) {
_uid = uid;
_gid = gid;
lastProcessedUnixField = type;
}
}
break;
}
case FZ_EF_NTFS: {
struct timespec mts, ats, bts;
if (ExtraField::parseNtfsExtraField(len, field, mts, ats, bts)) {
_mtime = mts;
_atime = ats;
_btime = bts;
_has_btime = true;
highPrecisionTime = true;
}
break;
}
}
}
}
void DataNode::processPkWareUnixField(zip_uint16_t type, zip_uint16_t len, const zip_uint8_t *field,
bool mtimeFromTimestamp, bool atimeFromTimestamp, bool highPrecisionTime,
int &lastProcessedUnixField) {
time_t mt, at;
uid_t uid;
gid_t gid;
dev_t dev;
const char *link;
uint16_t link_len;
if (!ExtraField::parsePkWareUnixField(len, field, _mode, mt, at,
uid, gid, dev, link, link_len))
return;
if (type >= lastProcessedUnixField) {
_uid = uid;
_gid = gid;
lastProcessedUnixField = type;
}
if (!mtimeFromTimestamp && !highPrecisionTime) {
_mtime.tv_sec = mt;
_mtime.tv_nsec = 0;
}
if (!atimeFromTimestamp && !highPrecisionTime) {
_atime.tv_sec = at;
_atime.tv_nsec = 0;
}
_device = dev;
// use PKWARE link target only if link target in Info-ZIP format is not
// specified (empty file content)
if (S_ISLNK(_mode) && _size == 0 && link_len > 0) {
assert(_state == NodeState::CLOSED || _state == NodeState::VIRTUAL_SYMLINK);
if (_state == NodeState::VIRTUAL_SYMLINK)
{
_state = NodeState::CLOSED;
_buffer.reset();
}
_buffer.reset(new BigBuffer());
if (!_buffer)
return;
assert(link != NULL);
_buffer->write(link, link_len, 0);
_state = NodeState::VIRTUAL_SYMLINK;
}
// hardlinks are handled in FuseZipData::build_tree
}
void DataNode::chmod (mode_t mode) {
_mode = (_mode & S_IFMT) | mode;
_ctime = currentTime();
_metadataChanged = true;
}
void DataNode::setUid (uid_t uid) {
_uid = uid;
_metadataChanged = true;
}
void DataNode::setGid (gid_t gid) {
_gid = gid;
_metadataChanged = true;
}
void DataNode::setTimes (const timespec &atime, const timespec &mtime) {
struct timespec now;
if (atime.tv_nsec == UTIME_NOW || mtime.tv_nsec == UTIME_NOW)
now = currentTime();
if (atime.tv_nsec == UTIME_NOW)
_atime = now;
else if (atime.tv_nsec != UTIME_OMIT)
_atime = atime;
if (mtime.tv_nsec == UTIME_NOW)
_mtime = now;
else if (mtime.tv_nsec != UTIME_OMIT)
_mtime = mtime;
_metadataChanged = true;
}
void DataNode::setCTime (const timespec &ctime) {
_ctime = ctime;
_metadataChanged = true;
}
void DataNode::touchCTime() {
_ctime = currentTime();
}
fuse-zip-0.7.2/lib/dataNode.h 0000644 0000000 0000000 00000012335 14005532107 014047 0 ustar 0000000 0000000 ////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2019 by Alexander Galanin //
// al@galanin.nnov.ru //
// http://galanin.nnov.ru/~al //
// //
// This program is free software: you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation, either version 3 of the License, or //
// (at your option) any later version. //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program. If not, see .//
////////////////////////////////////////////////////////////////////////////
#ifndef DATA_NODE_H
#define DATA_NODE_H
#include
#include
#include
#include
#include
#include "types.h"
#include "bigBuffer.h"
class DataNode {
private:
DataNode (const DataNode &) = delete;
DataNode &operator= (const DataNode &) = delete;
static constexpr zip_uint64_t FAKE_ID { std::numeric_limits::max() };
enum class NodeState {
CLOSED,
OPENED,
VIRTUAL_SYMLINK,
CHANGED,
NEW
};
zip_uint64_t _id;
std::unique_ptr _buffer;
int _open_count;
NodeState _state;
zip_uint64_t _size;
bool _has_btime, _metadataChanged;
mode_t _mode;
dev_t _device;
struct timespec _mtime, _atime, _ctime, _btime;
uid_t _uid;
gid_t _gid;
DataNode(zip_uint64_t id, mode_t mode, uid_t uid, gid_t gid, dev_t dev);
void processExtraFields(struct zip *zip, bool &hasPkWareField);
void processPkWareUnixField(zip_uint16_t type, zip_uint16_t len, const zip_uint8_t *field,
bool mtimeFromTimestamp, bool atimeFromTimestamp, bool highPrecisionTime,
int &lastProcessedUnixField);
int updateExtraFields(bool force_precise_time) const;
int updateExternalAttributes() const;
public:
static std::shared_ptr createNew(mode_t mode, uid_t uid, gid_t gid, dev_t dev);
static std::shared_ptr createTmpDir(mode_t mode, uid_t uid, gid_t gid, dev_t dev);
static std::shared_ptr createExisting(struct zip *zip, zip_uint64_t id, mode_t mode);
int open(struct zip *zip);
int read(char *buf, size_t size, size_t offset);
int write(const char *buf, size_t size, size_t offset);
int close();
/**
* Invoke zip_file_add() or zip_file_replace() for file to save it.
* Should be called only if item is needed to ba saved into zip file.
*
* @param zip zip structure pointer
* @param full_name full file name
* @param index file node index (updated if state is NEW)
* @return 0 if success, != 0 on error
*/
int save(struct zip *zip, const char *full_name, zip_int64_t &index);
/**
* Save file metadata to ZIP
* @param force_precise_time force creation of NTFS extra field
* @return libzip error code or 0 on success
*/
int saveMetadata (bool force_precise_time) const;
/**
* Truncate file.
*
* @return
* 0 If successful
* EBADF If file is currently closed
* EIO If insufficient memory available (because ENOMEM not
* listed in truncate() error codes)
*/
int truncate(size_t offset);
inline bool isChanged() const {
return _state == NodeState::CHANGED
|| _state == NodeState::NEW
|| (_state == NodeState::VIRTUAL_SYMLINK && _metadataChanged);
}
inline bool isMetadataChanged() const {
return _metadataChanged;
}
/**
* Change file mode
*/
void chmod (mode_t mode);
inline mode_t mode() const {
return _mode;
}
inline dev_t device() const {
return _device;
}
/**
* set atime and mtime
*/
void setTimes (const timespec &atime, const timespec &mtime);
void setCTime (const timespec &ctime);
void touchCTime();
inline struct timespec atime() const {
return _atime;
}
inline struct timespec ctime() const {
return _ctime;
}
inline struct timespec mtime() const {
return _mtime;
}
inline bool has_btime() const { return _has_btime; }
inline struct timespec btime() const {
return _btime;
}
/**
* owner and group
*/
void setUid (uid_t uid);
void setGid (gid_t gid);
inline uid_t uid () const {
return _uid;
}
inline gid_t gid () const {
return _gid;
}
zip_uint64_t size() const;
};
#endif
fuse-zip-0.7.2/lib/extraField.cpp 0000644 0000000 0000000 00000032756 14005532107 014763 0 ustar 0000000 0000000 ////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2014-2020 by Alexander Galanin //
// al@galanin.nnov.ru //
// http://galanin.nnov.ru/~al //
// //
// This program is free software: you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation, either version 3 of the License, or //
// (at your option) any later version. //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program. If not, see .//
////////////////////////////////////////////////////////////////////////////
#include "extraField.h"
#include
#if ! __APPLE__
# include
#endif // !__APPLE__
#include
#include
static const uint64_t NTFS_TO_UNIX_OFFSET = ((uint64_t)(369 * 365 + 89) * 24 * 3600 * 10000000);
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
#define le_16(x) (x)
#define le_32(x) (x)
#define le_64(x) (x)
#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
uint16_t le_16(uint16_t x) { return __builtin_bswap16(x); }
uint32_t le_32(uint32_t x) { return __builtin_bswap32(x); }
uint64_t le_64(uint64_t x) { return __builtin_bswap64(x); }
#else
# error "bad byte order"
#endif
uint64_t
ExtraField::getLong64 (const zip_uint8_t *&data) {
#pragma pack(push,1)
struct tmp {
uint64_t value;
};
#pragma pack(pop)
uint64_t res = reinterpret_cast(data)->value;
data += 8;
return le_64(res);
}
unsigned long
ExtraField::getLong (const zip_uint8_t *&data) {
#pragma pack(push,1)
struct tmp {
uint32_t value;
};
#pragma pack(pop)
uint32_t res = reinterpret_cast(data)->value;
data += 4;
return le_32(res);
}
unsigned short
ExtraField::getShort (const zip_uint8_t *&data) {
#pragma pack(push,1)
struct tmp {
uint16_t value;
};
#pragma pack(pop)
uint16_t res = reinterpret_cast(data)->value;
data += 2;
return le_16(res);
}
bool
ExtraField::parseExtTimeStamp (zip_uint16_t len, const zip_uint8_t *data,
bool &hasMTime, time_t &mtime, bool &hasATime, time_t &atime,
bool &hasCreTime, time_t &cretime) {
if (len < 1) {
return false;
}
const zip_uint8_t *end = data + len;
unsigned char flags = *data++;
hasMTime = flags & 1;
hasATime = flags & 2;
hasCreTime = flags & 4;
if (hasMTime) {
if (data + 4 > end) {
return false;
}
mtime = static_cast(getLong(data));
}
if (hasATime) {
if (data + 4 > end) {
return false;
}
atime = static_cast(getLong(data));
}
// only check that data format is correct
if (hasCreTime) {
if (data + 4 > end) {
return false;
}
cretime = static_cast(getLong(data));
}
return true;
}
const zip_uint8_t *
ExtraField::createExtTimeStamp (zip_flags_t location,
time_t mtime, time_t atime, bool set_cretime, time_t cretime,
zip_uint16_t &len) {
assert(location == ZIP_FL_LOCAL || location == ZIP_FL_CENTRAL);
// one byte for flags and three 4-byte ints for mtime, atime and cretime
static zip_uint8_t data [1 + 4 * 3];
len = 0;
// mtime and atime
zip_uint8_t flags = 1 | 2;
if (set_cretime) {
flags |= 4;
}
data[len++] = flags;
for (int i = 0; i < 4; ++i) {
data[len++] = static_cast(mtime);
mtime >>= 8;
}
// The central-header extra field contains the modification time only,
// or no timestamp at all.
if (location == ZIP_FL_LOCAL) {
for (int i = 0; i < 4; ++i) {
data[len++] = static_cast(atime);
atime >>= 8;
}
if (set_cretime) {
for (int i = 0; i < 4; ++i) {
data[len++] = static_cast(cretime);
cretime >>= 8;
}
}
}
return data;
}
bool
ExtraField::parseSimpleUnixField (zip_uint16_t type, zip_uint16_t len,
const zip_uint8_t *data,
bool &hasUidGid, uid_t &uid, gid_t &gid,
time_t &mtime, time_t &atime) {
const zip_uint8_t *end = data + len;
switch (type) {
case FZ_EF_PKWARE_UNIX:
case FZ_EF_INFOZIP_UNIX1:
hasUidGid = false;
if (data + 8 > end) {
return false;
}
atime = static_cast(getLong(data));
mtime = static_cast(getLong(data));
if (data + 4 > end)
return true;
hasUidGid = true;
uid = getShort (data);
gid = getShort (data);
break;
default:
return false;
}
return true;
}
bool
ExtraField::parseUnixUidGidField (zip_uint16_t type, zip_uint16_t len,
const zip_uint8_t *data, uid_t &uid, gid_t &gid) {
const zip_uint8_t *end = data + len;
switch (type) {
case FZ_EF_INFOZIP_UNIX2:
if (data + 4 > end) {
return false;
}
uid = getShort (data);
gid = getShort (data);
break;
case FZ_EF_INFOZIP_UNIXN: {
const zip_uint8_t *p;
// version
if (len < 1) {
return false;
}
if (*data++ != 1) {
// unsupported version
return false;
}
// UID
if (data + 1 > end) {
return false;
}
int lenUid = *data++;
if (data + lenUid > end) {
return false;
}
p = data + lenUid;
uid = 0;
int overflowBytes = lenUid - static_cast(sizeof(uid_t));
while (--p >= data) {
if (overflowBytes > 0 && *p != 0) {
// UID overflow
return false;
}
uid = (uid << 8) + *p;
overflowBytes--;
}
data += lenUid;
// GID
if (data + 1 > end) {
return false;
}
int lenGid = *data++;
if (data + lenGid > end) {
return false;
}
p = data + lenGid;
gid = 0;
overflowBytes = lenGid - static_cast(sizeof(gid_t));
while (--p >= data) {
if (overflowBytes > 0 && *p != 0) {
// GID overflow
return false;
}
gid = (gid << 8) + *p;
overflowBytes--;
}
break;
}
default:
return false;
}
return true;
}
#pragma pack(push,1)
struct PkWareUnixExtraField
{
uint32_t atime;
uint32_t mtime;
uint16_t uid;
uint16_t gid;
struct {
uint32_t major;
uint32_t minor;
} dev;
};
#pragma pack(pop)
bool
ExtraField::parsePkWareUnixField(zip_uint16_t len, const zip_uint8_t *data, mode_t mode,
time_t &mtime, time_t &atime, uid_t &uid, gid_t &gid, dev_t &dev,
const char *&link_target, zip_uint16_t &link_target_len) {
const PkWareUnixExtraField *f = reinterpret_cast(data);
if (len < 12) {
return false;
}
atime = static_cast(le_32(f->atime));
mtime = static_cast(le_32(f->mtime));
uid = le_16(f->uid);
gid = le_16(f->gid);
// variable data field
dev = 0;
link_target = NULL;
link_target_len = 0;
if (S_ISBLK(mode) || S_ISCHR(mode)) {
if (len < 20)
return false;
unsigned int maj, min;
maj = static_cast(le_32(f->dev.major));
min = static_cast(le_32(f->dev.minor));
dev = makedev(maj, min);
link_target = NULL;
link_target_len = 0;
} else {
link_target = reinterpret_cast(data + 12);
link_target_len = static_cast(len - 12);
}
return true;
}
const zip_uint8_t *
ExtraField::createPkWareUnixField (time_t mtime, time_t atime,
mode_t mode, uid_t uid, gid_t gid, dev_t dev,
zip_uint16_t &len) {
static PkWareUnixExtraField data;
data.mtime = le_32(static_cast(mtime));
data.atime = le_32(static_cast(atime));
data.uid = le_16(static_cast(uid));
data.gid = le_16(static_cast(gid));
data.dev.major = le_32(major(dev));
data.dev.minor = le_32(minor(dev));
if (S_ISBLK(mode) || S_ISCHR(mode))
len = 20;
else
len = 12;
return reinterpret_cast(&data);
}
inline static timespec ntfs2timespec(uint64_t t) {
timespec ts;
t -= NTFS_TO_UNIX_OFFSET;
ts.tv_sec = static_cast(t / 10000000);
ts.tv_nsec = static_cast(t % 10000000) * 100;
return ts;
}
bool
ExtraField::parseNtfsExtraField (zip_uint16_t len, const zip_uint8_t *data,
struct timespec &mtime, struct timespec &atime, struct timespec &cretime)
{
bool hasTimes = false;
const zip_uint8_t *end = data + len;
data += 4; // skip 'Reserved' field
while (data + 4 < end) {
uint16_t tag = getShort(data);
uint16_t size = getShort(data);
if (data + size > end)
return false;
if (tag == 0x0001) {
if (size < 24)
return false;
mtime = ntfs2timespec(getLong64(data));
atime = ntfs2timespec(getLong64(data));
cretime = ntfs2timespec(getLong64(data));
hasTimes = true;
} else {
data += size;
}
}
return hasTimes;
}
const zip_uint8_t *
ExtraField::createInfoZipNewUnixField (uid_t uid, gid_t gid,
zip_uint16_t &len) {
const int uidLen = sizeof(uid_t), gidLen = sizeof(gid_t);
static zip_uint8_t data [3 + uidLen + gidLen];
len = 0;
// version
data[len++] = 1;
// UID
data[len++] = uidLen;
for (int i = 0; i < uidLen; ++i) {
data[len++] = uid & 0xFF;
uid >>= 8;
}
// GID
data[len++] = gidLen;
for (int i = 0; i < gidLen; ++i) {
data[len++] = gid & 0xFF;
gid >>= 8;
}
return data;
}
#pragma pack(push,1)
struct NtfsExtraFieldFull
{
uint32_t reserved;
uint16_t tag;
uint16_t size;
uint64_t mtime;
uint64_t atime;
uint64_t btime;
};
struct NtfsExtraFieldTag
{
uint16_t tag;
uint16_t size;
uint64_t mtime;
uint64_t atime;
uint64_t btime;
};
#pragma pack(pop)
inline static uint64_t timespec2ntfs(const timespec &ts) {
return static_cast(ts.tv_sec) * 10000000
+ static_cast(ts.tv_nsec) / 100
+ NTFS_TO_UNIX_OFFSET;
}
const zip_uint8_t *
ExtraField::createNtfsExtraField (const timespec &mtime,
const timespec &atime, const timespec &btime, zip_uint16_t &len) {
len = sizeof(NtfsExtraFieldFull);
static NtfsExtraFieldFull data;
data.reserved = 0;
data.tag = le_16(0x0001);
data.size = le_16(24);
data.mtime = le_64(timespec2ntfs(mtime));
data.atime = le_64(timespec2ntfs(atime));
data.btime = le_64(timespec2ntfs(btime));
return reinterpret_cast(&data);
}
zip_uint16_t
ExtraField::editNtfsExtraField (zip_uint16_t len, zip_uint8_t *data,
const timespec &mtime, const timespec &atime, const timespec &btime) {
zip_uint8_t *orig = data;
zip_uint8_t *dest = data;
const zip_uint8_t *end = data + len;
if (data + 4 > end) {
// incomplete 'reserved' field - re-create
NtfsExtraFieldFull *out = reinterpret_cast(dest);
out->reserved = 0;
out->tag = le_16(0x0001);
out->size = le_16(24);
out->mtime = le_64(timespec2ntfs(mtime));
out->atime = le_64(timespec2ntfs(atime));
out->btime = le_64(timespec2ntfs(btime));
return static_cast(sizeof(*out));
}
// skip 'Reserved' field
data += 4;
dest += 4;
while (data + 4 < end) {
// use only header fields
NtfsExtraFieldTag *in = reinterpret_cast(data);
zip_uint16_t tag = le_16(in->tag);
zip_uint16_t size = le_16(in->size);
if (data + 4 + size > end)
break;
if (tag != 0x0001) {
// copy tag content
memmove(dest, data, 4U + size);
dest += 4 + size;
}
data += 4 + size;
}
// fill tag 0001
NtfsExtraFieldTag *out = reinterpret_cast(dest);
out->tag = le_16(0x0001);
out->size = le_16(24);
out->mtime = le_64(timespec2ntfs(mtime));
out->atime = le_64(timespec2ntfs(atime));
out->btime = le_64(timespec2ntfs(btime));
dest += sizeof(*out);
return static_cast(dest - orig);
}
fuse-zip-0.7.2/lib/extraField.h 0000644 0000000 0000000 00000017561 14005532107 014425 0 ustar 0000000 0000000 ////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2014-2019 by Alexander Galanin //
// al@galanin.nnov.ru //
// http://galanin.nnov.ru/~al //
// //
// This program is free software: you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation, either version 3 of the License, or //
// (at your option) any later version. //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program. If not, see .//
////////////////////////////////////////////////////////////////////////////
#ifndef EXTRA_FIELD_H
#define EXTRA_FIELD_H
#include
// ZIP extra fields
#define FZ_EF_TIMESTAMP (0x5455)
#define FZ_EF_NTFS (0x000A)
#define FZ_EF_PKWARE_UNIX (0x000D)
#define FZ_EF_INFOZIP_UNIX1 (0x5855)
#define FZ_EF_INFOZIP_UNIX2 (0x7855)
#define FZ_EF_INFOZIP_UNIXN (0x7875)
#define FZ_EF_NTFS_TIMESTAMP_LENGTH (28U)
struct ExtraField {
/**
* Parse 'Extended Timestamp' LOCAL extra field (0x5455) to get mtime,
* atime and creation time values.
* @param len (IN) field length in bytes
* @param data (IN) field data
* @param hasMTime (OUT) mtime presence
* @param mtime (OUT) file modification time if present
* @param hasATime (OUT) atime presence
* @param atime (OUT) file access time if present
* @param hasCreTime (OUT) creation time presence
* @param cretime (OUT) file creation time if present
* @return successful completion flag
*/
static bool parseExtTimeStamp (zip_uint16_t len, const zip_uint8_t *data,
bool &hasMTime, time_t &mtime, bool &hasATime, time_t &atime,
bool &hasCreTime, time_t &cretime);
/**
* Create 'Extended Timestamp' extra field (0x5455) from mtime and atime.
* Creation time field is filled only if defined.
* @param location location of timestamp field (ZIP_FL_CENTRAL or
* ZIP_FL_LOCAL for central directory and local extra field respectively)
* @param mtime modification time
* @param atime access time
* @param set_cretime true if creation time is defined
* @param cretime creation time
* @param len (OUT) data length
* @return pointer to timestamp data (must not be free()-d)
*/
static const zip_uint8_t *createExtTimeStamp (zip_flags_t location,
time_t mtime, time_t atime, bool set_cretime, time_t cretime,
zip_uint16_t &len);
/**
* Parse Info-ZIP UNIX extra field (5855) to extract UID/GID and (maybe)
* timestamps.
*
* @param type extended field type ID
* @param len field length in bytes
* @param data field data
* @param hasUidGid (OUT) UID and GID are present
* @param uid (OUT) UID
* @param gid (OUT) GID
* @param mtime (OUT) file modification time if present
* @param atime (OUT) file access time if present
* @return successful completion flag
*/
static bool parseSimpleUnixField (zip_uint16_t type, zip_uint16_t len,
const zip_uint8_t *data,
bool &hasUid, uid_t &uid, gid_t &gid,
time_t &mtime, time_t &atime);
/**
* Parse UNIX extra field to extract UID/GID:
* 7855 Info-ZIP Unix Extra Field (type 2)
* 7875 Info-ZIP New Unix Extra Field
*
* @param type extended field type ID
* @param len field length in bytes
* @param data field data
* @param uid (OUT) UID
* @param gid (OUT) GID
* @return successful completion flag
*/
static bool parseUnixUidGidField (zip_uint16_t type, zip_uint16_t len,
const zip_uint8_t *data, uid_t &uid, gid_t &gid);
/**
* Parse PKWARE Unix Extra Field (000D). If file is a device (character or
* block) then device inor-major numbers are extracted into 'dev' parameter.
* For symbolic links and regular files link target pointer is extracted into
* 'link_target' field and 'link_target_len' variables.
*
* @param type extended field type ID
* @param len field length in bytes
* @param data field data
* @param mode UNIX file mode
* @param mtime (OUT) file modification time if present
* @param atime (OUT) file access time if present
* @param uid (OUT) UID
* @param gid (OUT) GID
* @param dev (OUT) device major/minor numbers
* @param link_target (OUT) pointer to a first byte of hard/symbolic link target
* @param link_target_len (OUT) length of hard/symbolic link target
* @return successful completion flag
*/
static bool parsePkWareUnixField(zip_uint16_t len, const zip_uint8_t *data, mode_t mode,
time_t &mtime, time_t &atime, uid_t &uid, gid_t &gid, dev_t &dev,
const char *&link_target, zip_uint16_t &link_target_len);
/**
* Parse NTFS Extra FIeld
*
* @param len field length in bytes
* @param data field data
* @param mtime (OUT) file modification time if present
* @param atime (OUT) file access time if present
* @param cretime (OUT) file creation time if present
* @return successful completion flag
*/
static bool parseNtfsExtraField (zip_uint16_t len, const zip_uint8_t *data,
struct timespec &mtime, struct timespec &atime, struct timespec &cretime);
/**
* Create Info-ZIP New Unix extra field (0x7875)
* @param uid UID
* @param gid GID
* @param len (OUT) data length
* @return pointer to extra field data (must not be free()-d)
*/
static const zip_uint8_t *createInfoZipNewUnixField (uid_t uid, gid_t gid,
zip_uint16_t &len);
/**
* Create PKWARE Unix extra field (0x000D)
* @param mtime modification time
* @param atime access time
* @param mode UNIX file mode
* @param uid UID
* @param gid GID
* @param dev device major/minor numbers
* @param len (OUT) data length
* @return pointer to extra field data (must not be free()-d)
*/
static const zip_uint8_t *createPkWareUnixField (time_t mtime, time_t atime,
mode_t mode, uid_t uid, gid_t gid, dev_t dev,
zip_uint16_t &len);
/**
* Create NTFS Extra Field (0x000A)
* @param mtime modification time
* @param atime access time
* @param btime birth/creation time
* @param len (OUT) data length
* @return pointer to extra field data (must not be free()-d)
*/
static const zip_uint8_t *createNtfsExtraField (const timespec &mtime,
const timespec &atime, const timespec &btime, zip_uint16_t &len);
/**
* Edit existing NTFS Extra Field (0x000A): create/update tag 0001 fields with
* specifed time values. Edit is performed in-place. Allocated memory pointed
* by data must be big enough to keep (len + FZ_EF_NTFS_TIMESTAMP_LENGTH) bytes
*
* @param len original field content length
* @param data original field data
* @param mtime modification time
* @param atime access time
* @param btime birth/creation time
* @return data length
*/
static zip_uint16_t editNtfsExtraField (zip_uint16_t len, zip_uint8_t *data,
const timespec &mtime, const timespec &atime, const timespec &btime);
private:
/**
* Get Intel low-byte/high-byte order 64-bit number from data.
* Pointer is moved to next byte after parsed data.
*/
static uint64_t getLong64 (const zip_uint8_t *&data);
/**
* Get Intel low-byte/high-byte order 32-bit number from data.
* Pointer is moved to next byte after parsed data.
*/
static unsigned long getLong (const zip_uint8_t *&data);
/**
* Get Intel low-byte/high-byte order 16-bit number from data.
* Pointer is moved to next byte after parsed data.
*/
static unsigned short getShort (const zip_uint8_t *&data);
};
#endif
fuse-zip-0.7.2/lib/fileNode.cpp 0000644 0000000 0000000 00000032610 14005532107 014406 0 ustar 0000000 0000000 ////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2008-2019 by Alexander Galanin //
// al@galanin.nnov.ru //
// http://galanin.nnov.ru/~al //
// //
// This program is free software: you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation, either version 3 of the License, or //
// (at your option) any later version. //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program. If not, see .//
////////////////////////////////////////////////////////////////////////////
#define __STDC_LIMIT_MACROS
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "fileNode.h"
#include "extraField.h"
const zip_int64_t FileNode::ROOT_NODE_INDEX = -1;
const zip_int64_t FileNode::NEW_NODE_INDEX = -2;
const zip_int64_t FileNode::TMP_DIR_INDEX = -2;
FileNode::FileNode(struct zip *zip_, const char *fname, zip_int64_t id,
std::shared_ptr data) {
zip = zip_;
full_name = fname;
_id = id;
_data = std::move(data);
m_comment = NULL;
m_commentLen = 0;
m_commentChanged = true;
}
FileNode *FileNode::createFile (struct zip *zip, const char *fname,
uid_t owner, gid_t group, mode_t mode, dev_t dev) {
auto data = DataNode::createNew(mode, owner, group, dev);
FileNode *n = new FileNode(zip, fname, NEW_NODE_INDEX, std::move(data));
if (n == NULL) {
return NULL;
}
n->parse_name();
return n;
}
FileNode *FileNode::createSymlink(struct zip *zip, const char *fname) {
auto data = DataNode::createNew(S_IFLNK | 0777, 0, 0, 0);
FileNode *n = new FileNode(zip, fname, NEW_NODE_INDEX, std::move(data));
if (n == NULL) {
return NULL;
}
n->parse_name();
return n;
}
/**
* Create intermediate directory to build full tree
*/
FileNode *FileNode::createIntermediateDir(struct zip *zip,
const char *fname) {
auto data = DataNode::createTmpDir(S_IFDIR | 0755, 0, 0, 0);
FileNode *n = new FileNode(zip, fname, TMP_DIR_INDEX, std::move(data));
if (n == NULL) {
return NULL;
}
n->m_commentChanged = false;
n->parse_name();
return n;
}
FileNode *FileNode::createDir(struct zip *zip, const char *fname,
zip_int64_t id, uid_t owner, gid_t group, mode_t mode) {
assert(id >= 0);
// FUSE does not pass S_IFDIR bit here
auto data = DataNode::createNew(S_IFDIR | mode, owner, group, 0);
FileNode *n = new FileNode(zip, fname, id, std::move(data));
if (n == NULL) {
return NULL;
}
n->m_commentChanged = false;
n->parse_name();
return n;
}
FileNode *FileNode::createRootNode(struct zip *zip) {
auto data = DataNode::createNew(S_IFDIR | 0755, 0, 0, 0);
FileNode *n = new FileNode(zip, "", ROOT_NODE_INDEX, std::move(data));
if (n == NULL) {
return NULL;
}
n->name = n->full_name.c_str();
int len = 0;
n->m_comment = zip_get_archive_comment(zip, &len, ZIP_FL_ENC_RAW);
n->m_commentChanged = false;
if (len < 0)
n->m_comment = NULL;
else
// RAW comment length can't exceed 16 bits
n->m_commentLen = static_cast(len);
if (n->m_comment != NULL && n->m_comment[0] == '\0')
n->m_comment = NULL;
if (n->m_comment == NULL)
n->m_commentLen = 0;
return n;
}
FileNode *FileNode::createNodeForZipEntry(struct zip *zip,
const char *fname, zip_int64_t id, mode_t mode) {
assert(id >= 0);
auto data = DataNode::createExisting(zip, static_cast(id), mode);
FileNode *n = new FileNode(zip, fname, id, data);
if (n == NULL) {
return NULL;
}
n->parse_name();
n->readComment();
return n;
}
FileNode *FileNode::createHardlink(struct zip *zip,
const char *fname, zip_int64_t id, FileNode *target) {
assert(id >= 0);
FileNode *n = new FileNode(zip, fname, id, target->_data);
if (n == NULL) {
return NULL;
}
n->parse_name();
n->readComment();
return n;
}
FileNode::~FileNode() {
if (m_commentChanged && m_comment != NULL)
delete [] m_comment;
}
/**
* Get short name of a file. If last char is '/' then node is a directory
*/
void FileNode::parse_name() {
assert(!full_name.empty());
const char *lsl = full_name.c_str();
while (*lsl++) {}
lsl--;
while (lsl > full_name.c_str() && *lsl != '/') {
lsl--;
}
// If the last symbol in file name is '/' then it is a directory
if (*lsl == '/' && *(lsl+1) == '\0') {
// It will produce two \0s at the end of file name. I think that
// it is not a problem
full_name[full_name.size() - 1] = 0;
while (lsl > full_name.c_str() && *lsl != '/') {
lsl--;
}
}
// Setting short name of node
if (*lsl == '/') {
lsl++;
}
this->name = lsl;
}
void FileNode::readComment() {
uint32_t len = 0;
m_comment = zip_file_get_comment(zip, id(), &len, ZIP_FL_ENC_RAW);
m_commentChanged = false;
// RAW comment length can't exceed 16 bits
m_commentLen = static_cast(len);
if (m_comment != NULL && m_comment[0] == '\0')
m_comment = NULL;
if (m_comment == NULL)
m_commentLen = 0;
}
void FileNode::appendChild (FileNode *child) {
childs.push_back (child);
}
void FileNode::detachChild (FileNode *child) {
childs.remove (child);
}
void FileNode::rename(const char *new_name) {
full_name = new_name;
_data->touchCTime();
parse_name();
}
int FileNode::open() {
return _data->open(zip);
}
int FileNode::read(char *buf, size_t sz, size_t offset) {
return _data->read(buf, sz, offset);
}
int FileNode::write(const char *buf, size_t sz, size_t offset) {
return _data->write(buf, sz, offset);
}
int FileNode::close() {
return _data->close();
}
int FileNode::save() {
assert (!is_dir());
// index is modified if state == NEW
return _data->save(zip, full_name.c_str(), _id);
}
int FileNode::saveMetadata(bool force_precise_time) const {
assert(zip != NULL);
assert(_id >= 0);
int res = updateExtraFields(force_precise_time);
if (res != 0)
return res;
return updateExternalAttributes();
}
int FileNode::saveComment() const {
if (_id == ROOT_NODE_INDEX)
return zip_set_archive_comment(zip, m_comment, m_commentLen);
else
return zip_file_set_comment(zip, id(), m_comment, m_commentLen, 0);
}
int FileNode::truncate(size_t offset) {
assert(_data);
return _data->truncate(offset);
}
zip_uint64_t FileNode::size() const {
return _data->size();
}
bool FileNode::is_dir() const {
return S_ISDIR(_data->mode());
}
/**
* Save timestamp, owner and group info into extra fields
* @return 0 on success
*/
int FileNode::updateExtraFields (bool force_precise_time) const {
static zip_flags_t locations[] = {ZIP_FL_CENTRAL, ZIP_FL_LOCAL};
assert(_id >= 0);
assert(zip != NULL);
mode_t mode = _data->mode();
timespec mtime = _data->mtime();
timespec atime = _data->atime();
timespec btime = _data->btime();
bool has_btime = _data->has_btime();
for (unsigned int loc = 0; loc < sizeof(locations) / sizeof(locations[0]); ++loc) {
std::unique_ptr ntfs_field;
zip_uint16_t ntfs_field_len = 0;
// remove old extra fields
zip_int16_t count = zip_file_extra_fields_count (zip, id(),
locations[loc]);
const zip_uint8_t *field;
for (zip_int16_t i = count; i >= 0; --i) {
zip_uint16_t type;
zip_uint16_t len;
field = zip_file_extra_field_get (zip, id(), static_cast(i), &type,
&len, locations[loc]);
if (field == NULL)
continue;
if (type == FZ_EF_TIMESTAMP ||
type == FZ_EF_PKWARE_UNIX ||
type == FZ_EF_INFOZIP_UNIX1 ||
type == FZ_EF_INFOZIP_UNIX2 ||
type == FZ_EF_INFOZIP_UNIXN) {
zip_file_extra_field_delete (zip, id(), static_cast(i),
locations[loc]);
}
if (type == FZ_EF_NTFS) {
// back up previous field content
ntfs_field_len = len;
ntfs_field.reset(new zip_uint8_t[len + FZ_EF_NTFS_TIMESTAMP_LENGTH]);
memcpy(ntfs_field.get(), field, len);
zip_file_extra_field_delete (zip, id(), static_cast(i),
locations[loc]);
}
}
// add new extra fields
zip_uint16_t len;
int res;
// add special device or FIFO information
if (S_ISBLK(mode) || S_ISCHR(mode) || S_ISFIFO(mode)) {
field = ExtraField::createPkWareUnixField(mtime.tv_sec, atime.tv_sec, mode,
_data->uid(), _data->gid(), _data->device(), len);
res = zip_file_extra_field_set(zip, id(), FZ_EF_PKWARE_UNIX,
ZIP_EXTRA_FIELD_NEW, field, len, locations[loc]);
if (res != 0) {
return res;
}
// PKZIP 14 for Linux doesn't extract device nodes if extra fields
// other than PKWARE UNIX are present in the central directory
if ((S_ISBLK(mode) || S_ISCHR(mode)) && locations[loc] == ZIP_FL_CENTRAL)
continue;
}
// add timestamps
field = ExtraField::createExtTimeStamp (locations[loc], mtime.tv_sec,
atime.tv_sec, has_btime, btime.tv_sec, len);
res = zip_file_extra_field_set (zip, id(), FZ_EF_TIMESTAMP,
ZIP_EXTRA_FIELD_NEW, field, len, locations[loc]);
if (res != 0) {
return res;
}
// PKZIP 14 for Linux doesn't extract symlinks if NTFS extra field
// is present in the central directory
if ((has_btime || force_precise_time) &&
(locations[loc] == ZIP_FL_LOCAL || !S_ISLNK(mode)))
{
// add high-precision timestamps
if (ntfs_field) {
len = ExtraField::editNtfsExtraField(ntfs_field_len, ntfs_field.get(),
mtime, atime, btime);
field = ntfs_field.get();
} else {
field = ExtraField::createNtfsExtraField (mtime, atime, btime, len);
}
res = zip_file_extra_field_set (zip, id(), FZ_EF_NTFS,
ZIP_EXTRA_FIELD_NEW, field, len, locations[loc]);
if (res != 0) {
return res;
}
}
// add UNIX owner info
field = ExtraField::createInfoZipNewUnixField (_data->uid(), _data->gid(), len);
res = zip_file_extra_field_set (zip, id(), FZ_EF_INFOZIP_UNIXN,
ZIP_EXTRA_FIELD_NEW, field, len, locations[loc]);
if (res != 0) {
return res;
}
}
return 0;
}
void FileNode::chmod (mode_t mode) {
_data->chmod(mode);
}
void FileNode::setUid (uid_t uid) {
_data->setUid(uid);
}
void FileNode::setGid (gid_t gid) {
_data->setGid(gid);
}
/**
* Save OS type and permissions into external attributes
* @return 0 on success or libzip error code (ZIP_ER_MEMORY or ZIP_ER_RDONLY)
*/
int FileNode::updateExternalAttributes() const {
assert(_id >= 0);
assert (zip != NULL);
// save UNIX attributes in high word
mode_t mode = _data->mode() << 16;
// save DOS attributes in low byte
// http://msdn.microsoft.com/en-us/library/windows/desktop/gg258117%28v=vs.85%29.aspx
// http://en.wikipedia.org/wiki/File_Allocation_Table#attributes
if (is_dir()) {
// FILE_ATTRIBUTE_DIRECTORY
mode |= 0x10;
}
if (name[0] == '.') {
// FILE_ATTRIBUTE_HIDDEN
mode |= 2;
}
if (!(mode & S_IWUSR)) {
// FILE_ATTRIBUTE_READONLY
mode |= 1;
}
return zip_file_set_external_attributes (zip, id(), 0,
ZIP_OPSYS_UNIX, mode);
}
void FileNode::setTimes (const timespec &atime, const timespec &mtime) {
_data->setTimes(atime, mtime);
}
void FileNode::setCTime (const timespec &ctime) {
_data->setCTime(ctime);
}
bool FileNode::setComment(const char *value, uint16_t length) {
char *newComment = NULL;
if (value != NULL) {
newComment = new char[length];
if (newComment == NULL)
return false;
memcpy(newComment, value, length);
}
if (m_commentChanged && m_comment != NULL)
delete [] m_comment;
m_comment = newComment;
m_commentLen = length;
m_commentChanged = true;
return true;
}
fuse-zip-0.7.2/lib/fileNode.h 0000644 0000000 0000000 00000015404 14005532107 014055 0 ustar 0000000 0000000 ////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2008-2019 by Alexander Galanin //
// al@galanin.nnov.ru //
// http://galanin.nnov.ru/~al //
// //
// This program is free software: you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation, either version 3 of the License, or //
// (at your option) any later version. //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program. If not, see .//
////////////////////////////////////////////////////////////////////////////
#ifndef FILE_NODE_H
#define FILE_NODE_H
#include
#include
#include
#include
#include "types.h"
#include "bigBuffer.h"
#include "dataNode.h"
class FileNode {
friend class FuseZipData;
private:
// must not be defined
FileNode (const FileNode &);
FileNode &operator= (const FileNode &);
zip_int64_t _id;
std::shared_ptr _data;
struct zip *zip;
const char *m_comment;
uint16_t m_commentLen;
bool m_commentChanged;
void parse_name();
void readComment();
int updateExtraFields(bool force_precise_time) const;
int updateExternalAttributes() const;
static const zip_int64_t ROOT_NODE_INDEX, NEW_NODE_INDEX, TMP_DIR_INDEX;
FileNode(struct zip *zip, const char *fname, zip_int64_t id, std::shared_ptr data);
protected:
static FileNode *createIntermediateDir(struct zip *zip, const char *fname);
public:
/**
* Create new regular file
*/
static FileNode *createFile(struct zip *zip, const char *fname,
uid_t owner, gid_t group, mode_t mode, dev_t dev = 0);
/**
* Create new symbolic link
*/
static FileNode *createSymlink(struct zip *zip, const char *fname);
/**
* Create new directory for ZIP file entry
*/
static FileNode *createDir(struct zip *zip, const char *fname,
zip_int64_t id, uid_t owner, gid_t group, mode_t mode);
/**
* Create root pseudo-node for file system
*/
static FileNode *createRootNode(struct zip *zip);
/**
* Create node for existing ZIP file entry
*/
static FileNode *createNodeForZipEntry(struct zip *zip,
const char *fname, zip_int64_t id, mode_t mode);
/**
* Create hardlink to another node
*/
static FileNode *createHardlink(struct zip *zip,
const char *fname, zip_int64_t id, FileNode *target);
~FileNode();
/**
* return a pointer to data structure
*/
DataNode *data() {
return _data.get();
}
/**
* add child node to list
*/
void appendChild (FileNode *child);
/**
* remove child node from list
*/
void detachChild (FileNode *child);
/**
* Rename file without reparenting
*/
void rename (const char *new_name);
int open();
int read(char *buf, size_t size, size_t offset);
int write(const char *buf, size_t size, size_t offset);
int close();
/**
* Invoke zip_file_add() or zip_file_replace() for file to save it.
* Should be called only if item is needed to ba saved into zip file.
*
* @return 0 if success, != 0 on error
*/
int save();
/**
* Save file metadata to ZIP
* @param force_precise_time force creation of NTFS extra field
* @return libzip error code or 0 on success
*/
int saveMetadata (bool force_precise_time) const;
/**
* Save file or archive comment into ZIP
* @return libzip error code or 0 on success
*/
int saveComment() const;
/**
* Truncate file.
*
* @return
* 0 If successful
* EBADF If file is currently closed
* EIO If insufficient memory available (because ENOMEM not
* listed in truncate() error codes)
*/
int truncate(size_t offset);
inline bool isChanged() const {
return _data->isChanged();
}
inline bool isMetadataChanged() const {
return _data->isMetadataChanged();
}
inline bool isTemporaryDir() const {
return _id == TMP_DIR_INDEX;
}
/**
* Change file mode
*/
void chmod (mode_t mode);
inline mode_t mode() const {
return _data->mode();
}
inline dev_t device() const {
return _data->device();
}
/**
* set atime and mtime
*/
void setTimes (const timespec &atime, const timespec &mtime);
void setCTime (const timespec &ctime);
inline struct timespec atime() const {
return _data->atime();
}
inline struct timespec ctime() const {
return _data->ctime();
}
inline struct timespec mtime() const {
return _data->mtime();
}
/**
* Get parent name
*/
//TODO: rewrite without memory allocation
inline std::string getParentName () const {
if (name > full_name.c_str()) {
return std::string (full_name, 0, static_cast(name - full_name.c_str() - 1));
} else {
return "";
}
}
/**
* owner and group
*/
void setUid (uid_t uid);
void setGid (gid_t gid);
inline uid_t uid () const {
return _data->uid();
}
inline gid_t gid () const {
return _data->gid();
}
zip_uint64_t size() const;
bool present_in_zip() const { return _id >= 0; }
zip_uint64_t id() const { return static_cast(_id); }
void set_id(zip_int64_t id_) {
_id = id_;
// called only from FuseZipData::save, so we're don't worry about 'status' variable value
}
bool is_dir() const;
bool hasComment() const { return m_comment != NULL; }
bool isCommentChanged() const { return m_commentChanged; }
bool setComment(const char *value, uint16_t length);
const char *getComment() const { return m_comment; }
uint16_t getCommentLength() const { return m_commentLen; }
const char *name;
std::string full_name;
nodelist_t childs;
FileNode *parent;
};
#endif
fuse-zip-0.7.2/lib/fuse-zip.cpp 0000644 0000000 0000000 00000044020 14005532107 014421 0 ustar 0000000 0000000 ////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2008-2020 by Alexander Galanin //
// al@galanin.nnov.ru //
// http://galanin.nnov.ru/~al //
// //
// This program is free software: you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation, either version 3 of the License, or //
// (at your option) any later version. //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program. If not, see .//
////////////////////////////////////////////////////////////////////////////
#define STANDARD_BLOCK_SIZE (512)
#define ERROR_STR_BUF_LEN 0x100
#include "../config.h"
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wpedantic"
#include
#pragma GCC diagnostic pop
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "fuse-zip.h"
#include "types.h"
#include "fileNode.h"
#include "fuseZipData.h"
static const char FILE_COMMENT_XATTR_NAME[] = "user.comment";
static const size_t FILE_COMMENT_XATTR_NAME_LENZ = 13; // length including NULL-byte
using namespace std;
//TODO: Move printf-s out this function
FuseZipData *initFuseZip(const char *program, const char *fileName,
bool readonly, bool force_precise_time) {
FuseZipData *data = NULL;
int err;
struct zip *zip_file;
int flags = (readonly) ? ZIP_RDONLY : ZIP_CREATE;
if ((zip_file = zip_open(fileName, flags, &err)) == NULL) {
zip_error_t error;
zip_error_init_with_code(&error, err);
fprintf(stderr, "%s: cannot open ZIP archive %s: %s\n", program, fileName, zip_error_strerror(&error));
zip_error_fini(&error);
return data;
}
try {
// current working directory
char *cwd = (char*)malloc(PATH_MAX + 1);
if (cwd == NULL) {
throw std::bad_alloc();
}
if (getcwd(cwd, PATH_MAX) == NULL) {
perror(NULL);
free(cwd);
return data;
}
data = new FuseZipData(fileName, zip_file, cwd, force_precise_time);
free(cwd);
if (data == NULL) {
throw std::bad_alloc();
}
try {
data->build_tree(readonly);
}
catch (...) {
delete data;
throw;
}
}
catch (std::bad_alloc&) {
syslog(LOG_ERR, "no enough memory");
fprintf(stderr, "%s: no enough memory\n", program);
return NULL;
}
catch (const std::exception &e) {
syslog(LOG_ERR, "error opening ZIP file: %s", e.what());
fprintf(stderr, "%s: unable to open ZIP file: %s\n", program, e.what());
return NULL;
}
return data;
}
void *fusezip_init(struct fuse_conn_info *conn) {
(void) conn;
FuseZipData *data = (FuseZipData*)fuse_get_context()->private_data;
syslog(LOG_INFO, "Mounting file system on %s (cwd=%s)", data->m_archiveName, data->m_cwd.c_str());
return data;
}
inline FuseZipData *get_data() {
return (FuseZipData*)fuse_get_context()->private_data;
}
inline struct zip *get_zip() {
return get_data()->m_zip;
}
void fusezip_destroy(void *data) {
FuseZipData *d = (FuseZipData*)data;
d->save ();
delete d;
syslog(LOG_INFO, "File system unmounted");
}
FileNode *get_file_node(const char *fname) {
return get_data()->find (fname);
}
int fusezip_getattr(const char *path, struct stat *stbuf) {
memset(stbuf, 0, sizeof(struct stat));
if (*path == '\0') {
return -ENOENT;
}
FileNode *node = get_file_node(path + 1);
if (node == NULL) {
return -ENOENT;
}
if (node->is_dir()) {
stbuf->st_nlink = 2 + node->childs.size();
} else {
stbuf->st_nlink = 1;
}
stbuf->st_mode = node->mode();
stbuf->st_blksize = STANDARD_BLOCK_SIZE;
// Interpreting pointer as ulong without loss of data is valid for LP32, ILP32, LP64 and ILP64 data models.
// The only well-known data model that break this is LLP64 (Win64 API).
stbuf->st_ino = reinterpret_cast(node->data());
stbuf->st_blocks = static_cast((node->size() + STANDARD_BLOCK_SIZE - 1) / STANDARD_BLOCK_SIZE);
stbuf->st_size = static_cast(node->size());
#if __APPLE__
stbuf->st_atimespec = node->atime();
stbuf->st_mtimespec = node->mtime();
stbuf->st_ctimespec = node->ctime();
#else // __APPLE__
stbuf->st_atim = node->atime();
stbuf->st_mtim = node->mtime();
stbuf->st_ctim = node->ctime();
#endif // __APPLE__
stbuf->st_uid = node->uid();
stbuf->st_gid = node->gid();
stbuf->st_rdev = node->device();
return 0;
}
int fusezip_readdir(const char *path, void *buf, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *fi) {
(void) offset;
(void) fi;
if (*path == '\0') {
return -ENOENT;
}
FileNode *node = get_file_node(path + 1);
if (node == NULL) {
return -ENOENT;
}
filler(buf, ".", NULL, 0);
filler(buf, "..", NULL, 0);
for (nodelist_t::const_iterator i = node->childs.begin(); i != node->childs.end(); ++i) {
filler(buf, (*i)->name, NULL, 0);
}
return 0;
}
int fusezip_statfs(const char *path, struct statvfs *buf) {
(void) path;
// Getting amount of free space in directory with archive
struct statvfs st;
int err;
if ((err = statvfs(get_data()->m_cwd.c_str(), &st)) != 0) {
return -err;
}
buf->f_bavail = buf->f_bfree = st.f_frsize * st.f_bavail;
buf->f_bsize = 1;
//TODO: may be append archive size?
buf->f_blocks = buf->f_bavail + 0;
buf->f_ffree = 0;
buf->f_favail = 0;
buf->f_files = get_data()->numFiles();
buf->f_namemax = 255;
return 0;
}
int fusezip_open(const char *path, struct fuse_file_info *fi) {
if (*path == '\0') {
return -ENOENT;
}
FileNode *node = get_file_node(path + 1);
if (node == NULL) {
return -ENOENT;
}
if (node->is_dir()) {
return -EISDIR;
}
fi->fh = (uint64_t)node;
try {
return node->open();
}
catch (std::bad_alloc&) {
return -ENOMEM;
}
catch (std::exception&) {
return -EIO;
}
}
int fusezip_create(const char *path, mode_t mode, struct fuse_file_info *fi) {
if (*path == '\0') {
return -EACCES;
}
FileNode *node = get_file_node(path + 1);
if (node != NULL) {
return -EEXIST;
}
node = FileNode::createFile (get_zip(), path + 1,
fuse_get_context()->uid, fuse_get_context()->gid, mode);
if (node == NULL) {
return -ENOMEM;
}
get_data()->insertNode (node);
fi->fh = (uint64_t)node;
return node->open();
}
int fusezip_mknod(const char *path, mode_t mode, dev_t dev) {
if (*path == '\0') {
return -EACCES;
}
FileNode *node = get_file_node(path + 1);
if (node != NULL) {
return -EEXIST;
}
node = FileNode::createFile (get_zip(), path + 1,
fuse_get_context()->uid, fuse_get_context()->gid, mode, dev);
if (node == NULL) {
return -ENOMEM;
}
get_data()->insertNode (node);
return 0;
}
int fusezip_read(const char *path, char *buf, size_t size, off_t offset, struct fuse_file_info *fi) {
(void) path;
if (offset < 0)
return -EINVAL;
return ((FileNode*)fi->fh)->read(buf, size, static_cast(offset));
}
int fusezip_write(const char *path, const char *buf, size_t size, off_t offset, struct fuse_file_info *fi) {
(void) path;
if (offset < 0)
return -EINVAL;
return ((FileNode*)fi->fh)->write(buf, size, static_cast(offset));
}
int fusezip_release (const char *path, struct fuse_file_info *fi) {
(void) path;
return ((FileNode*)fi->fh)->close();
}
int fusezip_ftruncate(const char *path, off_t offset, struct fuse_file_info *fi) {
(void) path;
if (offset < 0)
return -EINVAL;
return -((FileNode*)fi->fh)->truncate(static_cast(offset));
}
int fusezip_truncate(const char *path, off_t offset) {
if (*path == '\0') {
return -EACCES;
}
if (offset < 0)
return -EINVAL;
FileNode *node = get_file_node(path + 1);
if (node == NULL) {
return -ENOENT;
}
if (node->is_dir()) {
return -EISDIR;
}
int res;
if ((res = node->open()) != 0) {
return res;
}
if ((res = node->truncate(static_cast(offset))) != 0) {
node->close();
return -res;
}
return node->close();
}
int fusezip_unlink(const char *path) {
if (*path == '\0') {
return -ENOENT;
}
FileNode *node = get_file_node(path + 1);
if (node == NULL) {
return -ENOENT;
}
if (node->is_dir()) {
return -EISDIR;
}
return -get_data()->removeNode(node);
}
int fusezip_rmdir(const char *path) {
if (*path == '\0') {
return -ENOENT;
}
FileNode *node = get_file_node(path + 1);
if (node == NULL) {
return -ENOENT;
}
if (!node->is_dir()) {
return -ENOTDIR;
}
if (!node->childs.empty()) {
return -ENOTEMPTY;
}
return -get_data()->removeNode(node);
}
int fusezip_mkdir(const char *path, mode_t mode) {
if (*path == '\0') {
return -ENOENT;
}
zip_int64_t idx = zip_dir_add(get_zip(), path + 1, ZIP_FL_ENC_GUESS);
if (idx < 0) {
return -ENOMEM;
}
FileNode *node = FileNode::createDir(get_zip(), path + 1, idx,
fuse_get_context()->uid, fuse_get_context()->gid, mode);
if (node == NULL) {
return -ENOMEM;
}
get_data()->insertNode (node);
return 0;
}
int fusezip_rename(const char *path, const char *new_path) {
if (*path == '\0') {
return -ENOENT;
}
FileNode *node = get_file_node(path + 1);
if (node == NULL) {
return -ENOENT;
}
if (*new_path == '\0') {
return -EINVAL;
}
FileNode *new_node = get_file_node(new_path + 1);
if (new_node != NULL) {
int res = get_data()->removeNode(new_node);
if (res !=0) {
return -res;
}
}
size_t len = strlen(new_path);
size_t oldLen = strlen(path + 1) + 1;
std::string new_name;
if (!node->is_dir()) {
--len;
--oldLen;
}
new_name.reserve(len + ((node->is_dir()) ? 1 : 0));
new_name.append(new_path + 1);
if (node->is_dir()) {
new_name.push_back('/');
}
try {
struct zip *z = get_zip();
// Renaming directory and its content recursively
if (node->is_dir()) {
queue q;
q.push(node);
while (!q.empty()) {
FileNode *n = q.front();
q.pop();
for (nodelist_t::const_iterator i = n->childs.begin(); i != n->childs.end(); ++i) {
FileNode *nn = *i;
q.push(nn);
char *name = (char*)malloc(len + nn->full_name.size() - oldLen + (nn->is_dir() ? 2 : 1));
if (name == NULL) {
//TODO: check that we are have enough memory before entering this loop
return -ENOMEM;
}
strcpy(name, new_name.c_str());
strcpy(name + len, nn->full_name.c_str() + oldLen);
if (nn->is_dir()) {
strcat(name, "/");
}
if (nn->present_in_zip()) {
zip_file_rename(z, nn->id(), name, ZIP_FL_ENC_GUESS);
}
// changing child list may cause loop iterator corruption
get_data()->renameNode (nn, name, false);
free(name);
}
}
}
if (node->present_in_zip()) {
zip_file_rename(z, node->id(), new_name.c_str(), ZIP_FL_ENC_GUESS);
}
get_data()->renameNode (node, new_name.c_str(), true);
return 0;
}
catch (...) {
return -EIO;
}
}
int fusezip_utimens(const char *path, const struct timespec tv[2]) {
if (*path == '\0') {
return -ENOENT;
}
FileNode *node = get_file_node(path + 1);
if (node == NULL) {
return -ENOENT;
}
node->setTimes (tv[0], tv[1]);
return 0;
}
#if ( __APPLE__ )
int fusezip_setxattr(const char *path, const char *name, const char *value, size_t size, int flags, uint32_t) {
#else
int fusezip_setxattr(const char *path, const char *name, const char *value, size_t size, int flags) {
#endif
if (*path == '\0') {
return -ENOENT;
}
FileNode *node = get_file_node(path + 1);
if (node == NULL) {
return -ENOENT;
}
if (strncmp(name, FILE_COMMENT_XATTR_NAME, FILE_COMMENT_XATTR_NAME_LENZ) != 0)
return -ENOTSUP;
if (size > std::numeric_limits::max())
return -ENOSPC;
if ((flags & XATTR_CREATE) && node->hasComment())
return -EEXIST;
if ((flags & XATTR_REPLACE) && !node->hasComment())
return -ENODATA;
if (name == NULL && size != 0)
return -EINVAL;
if (node->setComment(value, static_cast(size)))
return 0;
else
return -ENOSPC;
}
#if ( __APPLE__ )
int fusezip_getxattr(const char *path, const char *name, char *value, size_t size, uint32_t) {
#else
int fusezip_getxattr(const char *path, const char *name, char *value, size_t size) {
#endif
if (*path == '\0') {
return -ENOENT;
}
FileNode *node = get_file_node(path + 1);
if (node == NULL) {
return -ENOENT;
}
if (strncmp(name, FILE_COMMENT_XATTR_NAME, FILE_COMMENT_XATTR_NAME_LENZ) != 0)
return -ENODATA;
if (!node->hasComment())
return -ENODATA;
if (node->getCommentLength() > std::numeric_limits::max())
return -ERANGE;
if (size == 0)
return static_cast(node->getCommentLength());
if (node->getCommentLength() > size)
return -ERANGE;
memcpy(value, node->getComment(), node->getCommentLength());
return static_cast(node->getCommentLength());
}
int fusezip_listxattr(const char *path, char *list, size_t size) {
if (*path == '\0') {
return -ENOENT;
}
FileNode *node = get_file_node(path + 1);
if (node == NULL) {
return -ENOENT;
}
if (node->hasComment()) {
if (size == 0)
return FILE_COMMENT_XATTR_NAME_LENZ;
else if (size < FILE_COMMENT_XATTR_NAME_LENZ)
return -ERANGE;
else {
strncpy(list, FILE_COMMENT_XATTR_NAME, FILE_COMMENT_XATTR_NAME_LENZ);
return FILE_COMMENT_XATTR_NAME_LENZ;
}
} else {
return 0;
}
}
int fusezip_removexattr(const char *path, const char *name) {
if (*path == '\0') {
return -ENOENT;
}
FileNode *node = get_file_node(path + 1);
if (node == NULL) {
return -ENOENT;
}
if (strncmp(name, FILE_COMMENT_XATTR_NAME, FILE_COMMENT_XATTR_NAME_LENZ) != 0)
return -ENODATA;
if (!node->hasComment()) {
return -ENODATA;
}
node->setComment(NULL, 0);
return 0;
}
int fusezip_chmod(const char *path, mode_t mode) {
if (*path == '\0') {
return -ENOENT;
}
FileNode *node = get_file_node(path + 1);
if (node == NULL) {
return -ENOENT;
}
node->chmod(mode);
return 0;
}
int fusezip_chown(const char *path, uid_t uid, gid_t gid) {
if (*path == '\0') {
return -ENOENT;
}
FileNode *node = get_file_node(path + 1);
if (node == NULL) {
return -ENOENT;
}
if (uid != (uid_t) -1) {
node->setUid (uid);
}
if (gid != (gid_t) -1) {
node->setGid (gid);
}
return 0;
}
int fusezip_flush(const char *, struct fuse_file_info *) {
return 0;
}
int fusezip_fsync(const char *, int, struct fuse_file_info *) {
return 0;
}
int fusezip_fsyncdir(const char *, int, struct fuse_file_info *) {
return 0;
}
int fusezip_opendir(const char *, struct fuse_file_info *) {
return 0;
}
int fusezip_releasedir(const char *, struct fuse_file_info *) {
return 0;
}
int fusezip_access(const char *, int) {
return 0;
}
int fusezip_readlink(const char *path, char *buf, size_t size) {
if (*path == '\0') {
return -ENOENT;
}
FileNode *node = get_file_node(path + 1);
if (node == NULL) {
return -ENOENT;
}
if (!S_ISLNK(node->mode())) {
return -EINVAL;
}
int res;
if ((res = node->open()) != 0) {
if (res == -EMFILE) {
res = -ENOMEM;
}
return res;
}
int count = node->read(buf, size - 1, 0);
buf[count] = '\0';
node->close();
return 0;
}
int fusezip_symlink(const char *dest, const char *path) {
if (*path == '\0') {
return -EACCES;
}
FileNode *node = get_file_node(path + 1);
if (node != NULL) {
return -EEXIST;
}
node = FileNode::createSymlink (get_zip(), path + 1);
if (node == NULL) {
return -ENOMEM;
}
get_data()->insertNode (node);
int res;
if ((res = node->open()) != 0) {
if (res == -EMFILE) {
res = -ENOMEM;
}
return res;
}
res = node->write(dest, strlen(dest), 0);
node->close();
return (res < 0) ? -ENOMEM : 0;
}
fuse-zip-0.7.2/lib/fuse-zip.h 0000644 0000000 0000000 00000011005 14005532107 014063 0 ustar 0000000 0000000 ////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2008-2019 by Alexander Galanin //
// al@galanin.nnov.ru //
// http://galanin.nnov.ru/~al //
// //
// This program is free software: you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation, either version 3 of the License, or //
// (at your option) any later version. //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program. If not, see .//
////////////////////////////////////////////////////////////////////////////
#ifndef FUSE_ZIP_H
#define FUSE_ZIP_H
/**
* Main functions of fuse-zip file system (to be called by FUSE library)
*/
extern "C" {
/**
* Initialize libzip and fuse-zip structures.
*
* @param program Program name
* @param fileName ZIP file name
* @param readonly Open in read-only mode
* @param force_precise_time Force creation of precise time extended attributes
* even if btime is not known.
* @return NULL if an error occured, otherwise pointer to FuseZipData structure.
*/
class FuseZipData *initFuseZip(const char *program, const char *fileName,
bool readonly, bool force_precise_time);
/**
* Initialize filesystem
*
* Report current working dir and archive file name to syslog.
*
* @return filesystem-private data
*/
void *fusezip_init(struct fuse_conn_info *conn);
/**
* Destroy filesystem
*
* Save all modified data back to ZIP archive and report to syslog about completion.
* Note that filesystem unmounted before this method finishes
* (see https://bitbucket.org/agalanin/fuse-zip/issues/7).
*/
void fusezip_destroy(void *data);
int fusezip_getattr(const char *path, struct stat *stbuf);
int fusezip_readdir(const char *path, void *buf, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *fi);
int fusezip_statfs(const char *path, struct statvfs *buf);
int fusezip_open(const char *path, struct fuse_file_info *fi);
int fusezip_create(const char *path, mode_t mode, struct fuse_file_info *fi);
int fusezip_mknod(const char *path, mode_t mode, dev_t dev);
int fusezip_read(const char *path, char *buf, size_t size, off_t offset, struct fuse_file_info *fi);
int fusezip_write(const char *path, const char *buf, size_t size, off_t offset, struct fuse_file_info *fi);
int fusezip_release (const char *path, struct fuse_file_info *fi);
int fusezip_ftruncate(const char *path, off_t offset, struct fuse_file_info *fi);
int fusezip_truncate(const char *path, off_t offset);
int fusezip_unlink(const char *path);
int fusezip_rmdir(const char *path);
int fusezip_mkdir(const char *path, mode_t mode);
int fusezip_rename(const char *path, const char *new_path);
int fusezip_utimens(const char *path, const struct timespec tv[2]);
#if ( __APPLE__ )
int fusezip_setxattr(const char *, const char *, const char *, size_t, int, uint32_t);
int fusezip_getxattr(const char *, const char *, char *, size_t, uint32_t);
#else
int fusezip_setxattr(const char *, const char *, const char *, size_t, int);
int fusezip_getxattr(const char *, const char *, char *, size_t);
#endif
int fusezip_listxattr(const char *, char *, size_t);
int fusezip_removexattr(const char *, const char *);
int fusezip_chmod(const char *, mode_t);
int fusezip_chown(const char *, uid_t, gid_t);
int fusezip_flush(const char *, struct fuse_file_info *);
int fusezip_fsync(const char *, int, struct fuse_file_info *);
int fusezip_fsyncdir(const char *, int, struct fuse_file_info *);
int fusezip_opendir(const char *, struct fuse_file_info *);
int fusezip_releasedir(const char *, struct fuse_file_info *);
int fusezip_access(const char *, int);
int fusezip_readlink(const char *, char *, size_t);
int fusezip_symlink(const char *, const char *);
}
#endif
fuse-zip-0.7.2/lib/fuseZipData.cpp 0000644 0000000 0000000 00000042621 14005532107 015103 0 ustar 0000000 0000000 ////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2008-2020 by Alexander Galanin //
// al@galanin.nnov.ru //
// http://galanin.nnov.ru/~al //
// //
// This program is free software: you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation, either version 3 of the License, or //
// (at your option) any later version. //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program. If not, see .//
////////////////////////////////////////////////////////////////////////////
#include
#include
#include
#include
#include
#include
#include "fuseZipData.h"
#include "extraField.h"
#include "util.h"
#define FZ_ATTR_HARDLINK (0x800)
FuseZipData::FuseZipData(const char *archiveName, struct zip *z, const char *cwd,
bool force_precise_time):
m_zip(z), m_archiveName(archiveName), m_cwd(cwd), m_force_precise_time(force_precise_time) {
}
FuseZipData::~FuseZipData() {
if (chdir(m_cwd.c_str()) != 0) {
syslog(LOG_ERR, "Unable to chdir() to archive directory %s: %s. Trying to save file into $TMP or /tmp...",
m_cwd.c_str(), strerror(errno));
const char *tmpDir = getenv("TMP");
if (tmpDir == NULL || chdir(tmpDir) != 0) {
if (tmpDir != NULL) {
syslog(LOG_WARNING, "Unable to chdir() to %s: %s.", tmpDir, strerror(errno));
}
if (chdir("/tmp") != 0) {
syslog(LOG_ERR, "Unable to chdir() to /tmp: %s!", strerror(errno));
}
}
}
int res = zip_close(m_zip);
if (res != 0) {
syslog(LOG_ERR, "Error while closing archive: %s", zip_strerror(m_zip));
}
for (filemap_t::iterator i = files.begin(); i != files.end(); ++i) {
delete i->second;
}
}
void FuseZipData::build_tree(bool readonly) {
m_root = FileNode::createRootNode(m_zip);
if (m_root == NULL) {
throw std::bad_alloc();
}
m_root->parent = NULL;
files[m_root->full_name.c_str()] = m_root;
zip_int64_t n = zip_get_num_entries(m_zip, 0);
// search for absolute or parent-relative paths
bool needPrefix = false;
if (readonly) {
for (zip_int64_t i = 0; i < n; ++i) {
const char *name = zip_get_name(m_zip, static_cast(i), ZIP_FL_ENC_RAW);
if ((name[0] == '/') || (strncmp(name, "../", 3) == 0)) {
needPrefix = true;
}
}
}
// add zip entries for all items except hardlinks
filemap_t origNames;
for (zip_int64_t i = 0; i < n; ++i) {
zip_uint64_t id = static_cast(i);
bool isHardlink;
const char *name = zip_get_name(m_zip, id, ZIP_FL_ENC_RAW);
mode_t mode = getEntryAttributes(id, name, isHardlink);
if (isHardlink)
continue;
attachNode(i, name, mode, readonly, needPrefix, origNames);
}
// add hardlinks
for (zip_int64_t i = 0; i < n; ++i) {
zip_uint64_t id = static_cast(i);
bool isHardlink;
const char *name = zip_get_name(m_zip, id, ZIP_FL_ENC_RAW);
mode_t mode = getEntryAttributes(id, name, isHardlink);
if (!isHardlink)
continue;
bool notHLink = !attachHardlink(i, name, mode, readonly, needPrefix, origNames);
if (notHLink)
attachNode(i, name, mode, readonly, needPrefix, origNames);
else if (!readonly)
throw std::runtime_error("hard links are supported only in read-only mode");
}
// Connect nodes to tree. Missing intermediate nodes created on demand.
for (filemap_t::const_iterator i = files.begin(); i != files.end(); ++i)
{
FileNode *node = i->second;
if (node != m_root) {
connectNodeToTree (node);
}
}
}
void FuseZipData::connectNodeToTree (FileNode *node) {
FileNode *parent = findParent(node);
if (parent == NULL) {
parent = FileNode::createIntermediateDir (m_zip,
node->getParentName().c_str());
if (parent == NULL) {
throw std::bad_alloc();
}
files[parent->full_name.c_str()] = parent;
connectNodeToTree (parent);
} else if (!parent->is_dir()) {
throw std::runtime_error ("bad archive structure");
}
// connecting to parent
node->parent = parent;
parent->appendChild (node);
}
mode_t FuseZipData::getEntryAttributes(zip_uint64_t id, const char *name, bool &isHardlink) {
bool is_dir = false;
size_t len = strlen(name);
if (len > 0)
is_dir = name[len - 1] == '/';
zip_uint8_t opsys;
zip_uint32_t attr;
zip_file_get_external_attributes(m_zip, id, 0, &opsys, &attr);
mode_t unix_mode = attr >> 16;
mode_t mode;
isHardlink = false;
/*
* PKWARE describes "OS made by" now (since 1998) as follows:
* The upper byte indicates the compatibility of the file attribute
* information. If the external file attributes are compatible with MS-DOS
* and can be read by PKZIP for DOS version 2.04g then this value will be
* zero.
*/
if (opsys == ZIP_OPSYS_DOS && (unix_mode & S_IFMT) != 0)
opsys = ZIP_OPSYS_UNIX;
switch (opsys) {
case ZIP_OPSYS_UNIX: {
mode = unix_mode;
// force is_dir value
if (is_dir) {
mode = (mode & static_cast(~S_IFMT)) | S_IFDIR;
} else {
if ((mode & S_IFMT) == S_IFDIR) {
mode = (mode & static_cast(~S_IFMT)) | S_IFREG;
}
if ((mode & S_IFMT) == 0) {
// treat unknown file types as regular
mode = (mode & static_cast(~S_IFMT)) | S_IFREG;
}
}
isHardlink = (attr & FZ_ATTR_HARDLINK) != 0;
if (isHardlink) {
switch (mode & S_IFMT) {
case S_IFLNK:
// PkZip saves hardlink to symlink as a symlink to an original symlink target
isHardlink = true;
break;
case S_IFREG:
// normal hardlink
isHardlink = true;
break;
case S_IFSOCK:
case S_IFIFO:
// create hardlink if destination file exists
isHardlink = true;
break;
case S_IFBLK:
case S_IFCHR:
case S_IFDIR:
// always ignore hardlink flag for devices and dirs
isHardlink = false;
break;
default:
// don't hardlink unknown file types
isHardlink = false;
}
}
break;
}
case ZIP_OPSYS_DOS:
case ZIP_OPSYS_WINDOWS_NTFS:
case ZIP_OPSYS_MVS: {
/*
* Both WINDOWS_NTFS and OPSYS_MVS used here because of
* difference in constant assignment by PKWARE and Info-ZIP
*/
mode = 0444;
// http://msdn.microsoft.com/en-us/library/windows/desktop/gg258117%28v=vs.85%29.aspx
// http://en.wikipedia.org/wiki/File_Allocation_Table#attributes
// FILE_ATTRIBUTE_READONLY
if ((attr & 1) == 0) {
mode |= 0220;
}
// directory
if (is_dir) {
mode |= S_IFDIR | 0111;
} else {
mode |= S_IFREG;
}
break;
}
default: {
if (is_dir) {
mode = S_IFDIR | 0775;
} else {
mode = S_IFREG | 0664;
}
}
}
return mode;
}
void FuseZipData::attachNode(zip_int64_t id, const char *name, mode_t mode, bool readonly,
bool needPrefix, filemap_t &origNames)
{
std::string converted;
convertFileName(name, readonly, needPrefix, converted);
const char *cname = converted.c_str();
if (files.find(cname) != files.end()) {
syslog(LOG_ERR, "duplicated file name: %s", cname);
throw std::runtime_error("duplicate file names");
}
FileNode *node = FileNode::createNodeForZipEntry(m_zip, cname, id, mode);
if (node == NULL) {
throw std::bad_alloc();
}
files[node->full_name.c_str()] = node;
origNames[name] = node;
}
bool FuseZipData::attachHardlink(zip_int64_t sid, const char *name, mode_t mode, bool readonly,
bool needPrefix, filemap_t &origNames)
{
const zip_uint8_t *field;
zip_uint16_t len;
zip_uint64_t id = static_cast(sid);
field = zip_file_extra_field_get_by_id(m_zip, id, FZ_EF_PKWARE_UNIX, 0, &len, ZIP_FL_CENTRAL);
if (!field)
field = zip_file_extra_field_get_by_id(m_zip, id, FZ_EF_PKWARE_UNIX, 0, &len, ZIP_FL_LOCAL);
if (!field) {
// ignoring hardlink without PKWARE UNIX field
syslog(LOG_INFO, "%s: PKWARE UNIX field is absent for hardlink\n", name);
return false;
}
time_t mt, at;
uid_t uid;
gid_t gid;
dev_t dev;
const char *link;
uint16_t link_len;
if (!ExtraField::parsePkWareUnixField(len, field, mode, mt, at,
uid, gid, dev, link, link_len))
{
syslog(LOG_WARNING, "%s: unable to parse PKWARE UNIX field\n", name);
return false;
}
if (link_len == 0 || !link)
{
syslog(LOG_ERR, "%s: hard link target is empty\n", name);
return true;
}
std::string linkStr(link, link_len);
auto it = origNames.find(linkStr.c_str());
if (it == origNames.end())
{
syslog(LOG_ERR, "%s: unable to find link target %s\n", name, linkStr.c_str());
return true;
}
if ((it->second->mode() & S_IFMT) != (mode & S_IFMT))
{
// PkZip saves hard-link flag for symlinks with inode link count > 1.
if (S_ISLNK(mode))
{
return false;
}
else
{
syslog(LOG_ERR, "%s: file format differs with link target %s\n", name, linkStr.c_str());
return true;
}
}
std::string converted;
convertFileName(name, readonly, needPrefix, converted);
const char *cname = converted.c_str();
if (files.find(cname) != files.end()) {
syslog(LOG_ERR, "duplicated file name: %s", cname);
throw std::runtime_error("duplicate file names");
}
FileNode *node = FileNode::createHardlink(m_zip, cname, sid, it->second);
if (node == NULL) {
throw std::bad_alloc();
}
files[node->full_name.c_str()] = node;
origNames[name] = node;
return true;
}
int FuseZipData::removeNode(FileNode *node) {
assert(node != NULL);
assert(node->parent != NULL);
node->parent->detachChild (node);
node->parent->setCTime (currentTime());
files.erase(node->full_name.c_str());
bool present = node->present_in_zip();
zip_uint64_t id = node->id();
delete node;
if (present) {
return (zip_delete (m_zip, id) == 0)? 0 : ENOENT;
} else {
return 0;
}
}
void FuseZipData::validateFileName(const char *fname) {
if (fname[0] == 0) {
throw std::runtime_error("empty file name");
}
if (strstr(fname, "//") != NULL) {
throw std::runtime_error(std::string("bad file name (two slashes): ") + fname);
}
}
void FuseZipData::convertFileName(const char *fname, bool readonly,
bool needPrefix, std::string &converted) {
static const char *UP_PREFIX = "UP";
static const char *CUR_PREFIX = "CUR";
static const char *ROOT_PREFIX = "ROOT";
validateFileName(fname);
assert(fname[0] != 0);
const char *orig = fname;
converted.reserve(strlen(fname) + strlen(ROOT_PREFIX) + 1);
converted = "";
// add prefix
if (fname[0] == '/') {
if (!readonly) {
throw std::runtime_error("absolute paths are not supported in read-write mode");
} else {
assert(needPrefix);
converted.append(ROOT_PREFIX);
++fname;
}
} else {
bool parentRelative = false;
while (strncmp(fname, "../", 3) == 0) {
if (!readonly) {
throw std::runtime_error("paths relative to parent directory are not supported in read-write mode");
}
assert(needPrefix);
converted.append(UP_PREFIX);
fname += strlen("../");
parentRelative = true;
}
if (needPrefix && !parentRelative) {
converted.append(CUR_PREFIX);
}
}
if (needPrefix) {
converted.append("/");
}
if (fname[0] == 0) {
return;
}
assert(fname[0] != '/');
const char *start = fname, *cur;
while (start[0] != 0 && (cur = strchr(start + 1, '/')) != NULL) {
if ((cur - start == 1 && start[0] == '.') ||
(cur - start == 2 && start[0] == '.' && start[1] == '.')) {
throw std::runtime_error(std::string("bad file name: ") + orig);
}
converted.append(start, static_cast(cur - start + 1));
start = cur + 1;
}
// end of string is reached
if (strcmp(start, ".") == 0 || strcmp(start, "..") == 0) {
throw std::runtime_error(std::string("bad file name: ") + orig);
}
converted.append(start);
}
FileNode *FuseZipData::findParent (const FileNode *node) const {
std::string name = node->getParentName();
return find(name.c_str());
}
void FuseZipData::insertNode (FileNode *node) {
FileNode *parent = findParent (node);
assert (parent != NULL);
parent->appendChild (node);
node->parent = parent;
parent->setCTime (node->ctime());
assert (files.find(node->full_name.c_str()) == files.end());
files[node->full_name.c_str()] = node;
}
void FuseZipData::renameNode (FileNode *node, const char *newName, bool
reparent) {
assert(node != NULL);
assert(newName != NULL);
FileNode *parent1 = node->parent, *parent2;
assert (parent1 != NULL);
if (reparent) {
parent1->detachChild (node);
}
files.erase(node->full_name.c_str());
node->rename(newName);
files[node->full_name.c_str()] = node;
if (reparent) {
parent2 = findParent(node);
assert (parent2 != NULL);
parent2->appendChild (node);
node->parent = parent2;
}
if (reparent && parent1 != parent2) {
struct timespec now = currentTime();
parent1->setCTime (now);
parent2->setCTime (now);
}
}
FileNode *FuseZipData::find (const char *fname) const {
filemap_t::const_iterator i = files.find(fname);
if (i == files.end()) {
return NULL;
} else {
return i->second;
}
}
void FuseZipData::save () {
for (filemap_t::const_iterator i = files.begin(); i != files.end(); ++i) {
FileNode *node = i->second;
if (node == m_root) {
if (node->isCommentChanged()) {
int res = node->saveComment();
if (res != 0) {
syslog(LOG_ERR, "Error while saving archive comment: %d", res);
}
}
continue;
}
assert(node != NULL);
bool saveMetadata = node->isMetadataChanged();
if (node->isChanged() && !node->is_dir()) {
saveMetadata = true;
int res = node->save();
if (res != 0) {
saveMetadata = false;
syslog(LOG_ERR, "Error while saving file %s in ZIP archive: %d",
node->full_name.c_str(), res);
}
}
if (saveMetadata) {
if (node->isTemporaryDir()) {
// persist temporary directory
zip_int64_t idx = zip_dir_add(m_zip,
node->full_name.c_str(), ZIP_FL_ENC_GUESS);
if (idx < 0) {
syslog(LOG_ERR, "Unable to save directory %s in ZIP archive",
node->full_name.c_str());
continue;
}
node->set_id(idx);
}
int res = node->saveMetadata(m_force_precise_time);
if (res != 0) {
syslog(LOG_ERR, "Error while saving metadata for file %s in ZIP archive: %d",
node->full_name.c_str(), res);
}
}
if (node->isCommentChanged()) {
int res = node->saveComment();
if (res != 0) {
syslog(LOG_ERR, "Error while saving comment for file %s in ZIP archive: %d",
node->full_name.c_str(), res);
}
}
}
}
fuse-zip-0.7.2/lib/fuseZipData.h 0000644 0000000 0000000 00000011416 14005532107 014546 0 ustar 0000000 0000000 ////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2008-2019 by Alexander Galanin //
// al@galanin.nnov.ru //
// http://galanin.nnov.ru/~al //
// //
// This program is free software: you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation, either version 3 of the License, or //
// (at your option) any later version. //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program. If not, see .//
////////////////////////////////////////////////////////////////////////////
#ifndef FUSEZIP_DATA
#define FUSEZIP_DATA
#include
#include "types.h"
#include "fileNode.h"
class FuseZipData {
private:
/**
* Check that file name is non-empty and does not contain duplicate
* slashes
* @throws std::runtime_exception if name is invalid
*/
static void validateFileName(const char *fname);
/**
* In read-only mode convert file names to replace .. to UP and / to
* ROOT to make absolute and relative paths accessible via file system.
* In read-write mode throw an error if path is absolute or relative to
* parent directory.
* @param fname file name
* @param readonly read-only flag
* @param needPrefix prepend CUR directory prefix to "normal" file
* names to not mix them with parent-relative or absolute
* @param converted result string
* @throws std::runtime_exception if name is invalid
*/
static void convertFileName(const char *fname, bool readonly,
bool needPrefix, std::string &converted);
/**
* Find node parent by its name
*/
FileNode *findParent (const FileNode *node) const;
/**
* Create node parents (if not yet exist) and connect node to
* @throws std::bad_alloc
* @throws std::runtime_error - if parent is not directory
*/
void connectNodeToTree (FileNode *node);
/**
* Get ZIP file entry UNIX mode and PkWare hardlink flag from external attributes field.
*/
mode_t getEntryAttributes(zip_uint64_t id, const char *name, bool &isHardlink);
/**
* create and attach file node
*/
void attachNode(zip_int64_t id, const char *name, mode_t mode, bool readonly,
bool needPrefix, filemap_t &origNames);
/**
* create and attach hardlink node
*/
bool attachHardlink(zip_int64_t id, const char *name, mode_t mode, bool readonly,
bool needPrefix, filemap_t &origNames);
FileNode *m_root;
filemap_t files;
public:
struct zip *m_zip;
const char *m_archiveName;
std::string m_cwd;
const bool m_force_precise_time;
/**
* Keep archiveName and cwd in class fields and build file tree from z.
*
* 'cwd' and 'z' free()-ed in destructor.
* 'archiveName' should be managed externally.
*/
FuseZipData(const char *archiveName, struct zip *z, const char *cwd, bool force_precise_time);
~FuseZipData();
/**
* Detach node from tree, and delete associated entry in zip file if
* present.
*
* @param node Node to remove
* @return Error code or 0 is successful
*/
int removeNode(FileNode *node);
/**
* Build tree of zip file entries from ZIP file
*/
void build_tree(bool readonly);
/**
* Insert new node into tree by adding it to parent's childs list and
* specifying node parent field.
*/
void insertNode (FileNode *node);
/**
* Detach node from old parent, rename, attach to new parent.
* @param node
* @param newName new name
* @param reparent if false, node detaching is not performed
*/
void renameNode (FileNode *node, const char *newName, bool reparent);
/**
* search for node
* @return node or NULL
*/
FileNode *find (const char *fname) const;
/**
* Return number of files in tree
*/
size_t numFiles () const {
return files.size() - 1;
}
/**
* Save archive
*/
void save ();
};
#endif
fuse-zip-0.7.2/lib/types.h 0000644 0000000 0000000 00000004615 14005532107 013476 0 ustar 0000000 0000000 ////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2008-2017 by Alexander Galanin //
// al@galanin.nnov.ru //
// http://galanin.nnov.ru/~al //
// //
// This program is free software: you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation, either version 3 of the License, or //
// (at your option) any later version. //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program. If not, see .//
////////////////////////////////////////////////////////////////////////////
#ifndef FUSEZIP_TYPES_H
#define FUSEZIP_TYPES_H
#include
#include
#include
#include
#include