pax_global_header 0000666 0000000 0000000 00000000064 13121032772 0014510 g ustar 00root root 0000000 0000000 52 comment=d3af23322a7619c81ab899818b31223377e92afe
libnfs-libnfs-2.0.0/ 0000775 0000000 0000000 00000000000 13121032772 0014237 5 ustar 00root root 0000000 0000000 libnfs-libnfs-2.0.0/.gitignore 0000664 0000000 0000000 00000000640 13121032772 0016227 0 ustar 00root root 0000000 0000000 .*
*.h
*.c
*.in
*.la
*.a
*.lo
*.o
*.obj
*.lib
*.dll
*.ilk
*.pdb
*.ex?
*-stamp
libnfs-raw-*.x
Makefile
examples/nfsclient-raw
examples/nfsclient-sync
examples/nfsclient-async
examples/nfsclient-bcast
examples/nfsclient-listservers
aclocal.m4
autom4te.cache/
compile
config.guess
config.h.in~
config.log
config.status
config.sub
configure
depcomp
install-sh
libtool
ltmain.sh
missing
stamp-h1
libnfs.pc
!libnfs.pc.in
libnfs-libnfs-2.0.0/CHANGELOG 0000664 0000000 0000000 00000002272 13121032772 0015454 0 ustar 00root root 0000000 0000000 Changes since 1.11.0
BUGS
====
Fix NULL pointer crash in nfs_link().
Clamp read/write size for servers (Ganesha) that offer very large io sizes
instead of failing to connect to the export.
Tell the server to commit all data to stable storage when we close files.
Double free fix: don't call rpc_free_pdu() after rpc_queue_pdu() failure.
Fix for memory leak in rpc_allocate_*().
Fixes to build nfs-ls and nfs-cp on win32.
Abort the mount process correctly if MOUNT/MNT returns error or is cancelled.
Fix memory leak in error path in nfs_create_2_cb().
Fix leak of rpc->inbuf if we destroy the context while we still have PDUs
in flight.
FEATURES
========
Add O_NOFOLLOW support for nfs_open()
Add a new mkdir2 command that also takes a mode argument.
Add a new readlink2 command that avoids having to preallocate the buffer.
Add support for RPC timeouts for both the sync and async interfaces.
Build fixes for Mingw and Cygwin
Update README to document two new Windows builds
Use SOCK_CLOEXEC for the sockets
Make rpc_set{g|u}id() public
Performance optimization: socket: Batch pdu read in rpc_read_from_socket
Low level support for NFSv4 and some examples
Support for building RPC servers
libnfs-libnfs-2.0.0/COPYING 0000664 0000000 0000000 00000001722 13121032772 0015274 0 ustar 00root root 0000000 0000000 Libnfs components fall under two separate licences
The library sources and include directories
===========================================
The nfs client library itself, i.e. the lib and include directories,
is licenced under GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
The protocol definition, .x, files
==================================
These are based on old RFCs and studying how wireshark dissects various packets.
These are distributed under the simplified BSD licence.
The examples directory
================================
The utility and example applications using this library, i.e. the
examples directory, are licenced under 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.
To avoid any confusion, every source file contains a licence boilerplate.
libnfs-libnfs-2.0.0/LICENCE-BSD.txt 0000664 0000000 0000000 00000002661 13121032772 0016455 0 ustar 00root root 0000000 0000000 Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
The views and conclusions contained in the software and documentation are those
of the authors and should not be interpreted as representing official policies,
either expressed or implied, of the FreeBSD Project.
libnfs-libnfs-2.0.0/LICENCE-GPL-3.txt 0000664 0000000 0000000 00000104513 13121032772 0016626 0 ustar 00root root 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
.
libnfs-libnfs-2.0.0/LICENCE-LGPL-2.1.txt 0000664 0000000 0000000 00000063642 13121032772 0017107 0 ustar 00root root 0000000 0000000 GNU LESSER GENERAL PUBLIC LICENSE
Version 2.1, February 1999
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
[This is the first released version of the Lesser GPL. It also counts
as the successor of the GNU Library Public License, version 2, hence
the version number 2.1.]
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
Licenses are intended to guarantee your freedom to share and change
free software--to make sure the software is free for all its users.
This license, the Lesser General Public License, applies to some
specially designated software packages--typically libraries--of the
Free Software Foundation and other authors who decide to use it. You
can use it too, but we suggest you first think carefully about whether
this license or the ordinary General Public License is the better
strategy to use in any particular case, based on the explanations below.
When we speak of free software, we are referring to freedom of use,
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 this service if you wish); that you receive source code or can get
it if you want it; that you can change the software and use pieces of
it in new free programs; and that you are informed that you can do
these things.
To protect your rights, we need to make restrictions that forbid
distributors to deny you these rights or to ask you to surrender these
rights. These restrictions translate to certain responsibilities for
you if you distribute copies of the library or if you modify it.
For example, if you distribute copies of the library, whether gratis
or for a fee, you must give the recipients all the rights that we gave
you. You must make sure that they, too, receive or can get the source
code. If you link other code with the library, you must provide
complete object files to the recipients, so that they can relink them
with the library after making changes to the library and recompiling
it. And you must show them these terms so they know their rights.
We protect your rights with a two-step method: (1) we copyright the
library, and (2) we offer you this license, which gives you legal
permission to copy, distribute and/or modify the library.
To protect each distributor, we want to make it very clear that
there is no warranty for the free library. Also, if the library is
modified by someone else and passed on, the recipients should know
that what they have is not the original version, so that the original
author's reputation will not be affected by problems that might be
introduced by others.
Finally, software patents pose a constant threat to the existence of
any free program. We wish to make sure that a company cannot
effectively restrict the users of a free program by obtaining a
restrictive license from a patent holder. Therefore, we insist that
any patent license obtained for a version of the library must be
consistent with the full freedom of use specified in this license.
Most GNU software, including some libraries, is covered by the
ordinary GNU General Public License. This license, the GNU Lesser
General Public License, applies to certain designated libraries, and
is quite different from the ordinary General Public License. We use
this license for certain libraries in order to permit linking those
libraries into non-free programs.
When a program is linked with a library, whether statically or using
a shared library, the combination of the two is legally speaking a
combined work, a derivative of the original library. The ordinary
General Public License therefore permits such linking only if the
entire combination fits its criteria of freedom. The Lesser General
Public License permits more lax criteria for linking other code with
the library.
We call this license the "Lesser" General Public License because it
does Less to protect the user's freedom than the ordinary General
Public License. It also provides other free software developers Less
of an advantage over competing non-free programs. These disadvantages
are the reason we use the ordinary General Public License for many
libraries. However, the Lesser license provides advantages in certain
special circumstances.
For example, on rare occasions, there may be a special need to
encourage the widest possible use of a certain library, so that it becomes
a de-facto standard. To achieve this, non-free programs must be
allowed to use the library. A more frequent case is that a free
library does the same job as widely used non-free libraries. In this
case, there is little to gain by limiting the free library to free
software only, so we use the Lesser General Public License.
In other cases, permission to use a particular library in non-free
programs enables a greater number of people to use a large body of
free software. For example, permission to use the GNU C Library in
non-free programs enables many more people to use the whole GNU
operating system, as well as its variant, the GNU/Linux operating
system.
Although the Lesser General Public License is Less protective of the
users' freedom, it does ensure that the user of a program that is
linked with the Library has the freedom and the wherewithal to run
that program using a modified version of the Library.
The precise terms and conditions for copying, distribution and
modification follow. Pay close attention to the difference between a
"work based on the library" and a "work that uses the library". The
former contains code derived from the library, whereas the latter must
be combined with the library in order to run.
GNU LESSER GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License Agreement applies to any software library or other
program which contains a notice placed by the copyright holder or
other authorized party saying it may be distributed under the terms of
this Lesser General Public License (also called "this License").
Each licensee is addressed as "you".
A "library" means a collection of software functions and/or data
prepared so as to be conveniently linked with application programs
(which use some of those functions and data) to form executables.
The "Library", below, refers to any such software library or work
which has been distributed under these terms. A "work based on the
Library" means either the Library or any derivative work under
copyright law: that is to say, a work containing the Library or a
portion of it, either verbatim or with modifications and/or translated
straightforwardly into another language. (Hereinafter, translation is
included without limitation in the term "modification".)
"Source code" for a work means the preferred form of the work for
making modifications to it. For a library, complete source code means
all the source code for all modules it contains, plus any associated
interface definition files, plus the scripts used to control compilation
and installation of the library.
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running a program using the Library is not restricted, and output from
such a program is covered only if its contents constitute a work based
on the Library (independent of the use of the Library in a tool for
writing it). Whether that is true depends on what the Library does
and what the program that uses the Library does.
1. You may copy and distribute verbatim copies of the Library's
complete source code as you receive it, in any medium, provided that
you conspicuously and appropriately publish on each copy an
appropriate copyright notice and disclaimer of warranty; keep intact
all the notices that refer to this License and to the absence of any
warranty; and distribute a copy of this License along with the
Library.
You may charge a fee for the physical act of transferring a copy,
and you may at your option offer warranty protection in exchange for a
fee.
2. You may modify your copy or copies of the Library or any portion
of it, thus forming a work based on the Library, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) The modified work must itself be a software library.
b) You must cause the files modified to carry prominent notices
stating that you changed the files and the date of any change.
c) You must cause the whole of the work to be licensed at no
charge to all third parties under the terms of this License.
d) If a facility in the modified Library refers to a function or a
table of data to be supplied by an application program that uses
the facility, other than as an argument passed when the facility
is invoked, then you must make a good faith effort to ensure that,
in the event an application does not supply such function or
table, the facility still operates, and performs whatever part of
its purpose remains meaningful.
(For example, a function in a library to compute square roots has
a purpose that is entirely well-defined independent of the
application. Therefore, Subsection 2d requires that any
application-supplied function or table used by this function must
be optional: if the application does not supply it, the square
root function must still compute square roots.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Library,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Library, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote
it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Library.
In addition, mere aggregation of another work not based on the Library
with the Library (or with a work based on the Library) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may opt to apply the terms of the ordinary GNU General Public
License instead of this License to a given copy of the Library. To do
this, you must alter all the notices that refer to this License, so
that they refer to the ordinary GNU General Public License, version 2,
instead of to this License. (If a newer version than version 2 of the
ordinary GNU General Public License has appeared, then you can specify
that version instead if you wish.) Do not make any other change in
these notices.
Once this change is made in a given copy, it is irreversible for
that copy, so the ordinary GNU General Public License applies to all
subsequent copies and derivative works made from that copy.
This option is useful when you wish to copy part of the code of
the Library into a program that is not a library.
4. You may copy and distribute the Library (or a portion or
derivative of it, under Section 2) in object code or executable form
under the terms of Sections 1 and 2 above provided that you accompany
it with the complete corresponding machine-readable source code, which
must be distributed under the terms of Sections 1 and 2 above on a
medium customarily used for software interchange.
If distribution of object code is made by offering access to copy
from a designated place, then offering equivalent access to copy the
source code from the same place satisfies the requirement to
distribute the source code, even though third parties are not
compelled to copy the source along with the object code.
5. A program that contains no derivative of any portion of the
Library, but is designed to work with the Library by being compiled or
linked with it, is called a "work that uses the Library". Such a
work, in isolation, is not a derivative work of the Library, and
therefore falls outside the scope of this License.
However, linking a "work that uses the Library" with the Library
creates an executable that is a derivative of the Library (because it
contains portions of the Library), rather than a "work that uses the
library". The executable is therefore covered by this License.
Section 6 states terms for distribution of such executables.
When a "work that uses the Library" uses material from a header file
that is part of the Library, the object code for the work may be a
derivative work of the Library even though the source code is not.
Whether this is true is especially significant if the work can be
linked without the Library, or if the work is itself a library. The
threshold for this to be true is not precisely defined by law.
If such an object file uses only numerical parameters, data
structure layouts and accessors, and small macros and small inline
functions (ten lines or less in length), then the use of the object
file is unrestricted, regardless of whether it is legally a derivative
work. (Executables containing this object code plus portions of the
Library will still fall under Section 6.)
Otherwise, if the work is a derivative of the Library, you may
distribute the object code for the work under the terms of Section 6.
Any executables containing that work also fall under Section 6,
whether or not they are linked directly with the Library itself.
6. As an exception to the Sections above, you may also combine or
link a "work that uses the Library" with the Library to produce a
work containing portions of the Library, and distribute that work
under terms of your choice, provided that the terms permit
modification of the work for the customer's own use and reverse
engineering for debugging such modifications.
You must give prominent notice with each copy of the work that the
Library is used in it and that the Library and its use are covered by
this License. You must supply a copy of this License. If the work
during execution displays copyright notices, you must include the
copyright notice for the Library among them, as well as a reference
directing the user to the copy of this License. Also, you must do one
of these things:
a) Accompany the work with the complete corresponding
machine-readable source code for the Library including whatever
changes were used in the work (which must be distributed under
Sections 1 and 2 above); and, if the work is an executable linked
with the Library, with the complete machine-readable "work that
uses the Library", as object code and/or source code, so that the
user can modify the Library and then relink to produce a modified
executable containing the modified Library. (It is understood
that the user who changes the contents of definitions files in the
Library will not necessarily be able to recompile the application
to use the modified definitions.)
b) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (1) uses at run time a
copy of the library already present on the user's computer system,
rather than copying library functions into the executable, and (2)
will operate properly with a modified version of the library, if
the user installs one, as long as the modified version is
interface-compatible with the version that the work was made with.
c) Accompany the work with a written offer, valid for at
least three years, to give the same user the materials
specified in Subsection 6a, above, for a charge no more
than the cost of performing this distribution.
d) If distribution of the work is made by offering access to copy
from a designated place, offer equivalent access to copy the above
specified materials from the same place.
e) Verify that the user has already received a copy of these
materials or that you have already sent this user a copy.
For an executable, the required form of the "work that uses the
Library" must include any data and utility programs needed for
reproducing the executable from it. However, as a special exception,
the materials to be distributed need not include anything that is
normally distributed (in either source or binary form) with the major
components (compiler, kernel, and so on) of the operating system on
which the executable runs, unless that component itself accompanies
the executable.
It may happen that this requirement contradicts the license
restrictions of other proprietary libraries that do not normally
accompany the operating system. Such a contradiction means you cannot
use both them and the Library together in an executable that you
distribute.
7. You may place library facilities that are a work based on the
Library side-by-side in a single library together with other library
facilities not covered by this License, and distribute such a combined
library, provided that the separate distribution of the work based on
the Library and of the other library facilities is otherwise
permitted, and provided that you do these two things:
a) Accompany the combined library with a copy of the same work
based on the Library, uncombined with any other library
facilities. This must be distributed under the terms of the
Sections above.
b) Give prominent notice with the combined library of the fact
that part of it is a work based on the Library, and explaining
where to find the accompanying uncombined form of the same work.
8. You may not copy, modify, sublicense, link with, or distribute
the Library except as expressly provided under this License. Any
attempt otherwise to copy, modify, sublicense, link with, or
distribute the Library is void, and will automatically terminate your
rights under this License. However, parties who have received copies,
or rights, from you under this License will not have their licenses
terminated so long as such parties remain in full compliance.
9. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Library or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Library (or any work based on the
Library), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Library or works based on it.
10. Each time you redistribute the Library (or any work based on the
Library), the recipient automatically receives a license from the
original licensor to copy, distribute, link with or modify the Library
subject to these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties with
this License.
11. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
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
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Library at all. For example, if a patent
license would not permit royalty-free redistribution of the Library by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Library.
If any portion of this section is held invalid or unenforceable under any
particular circumstance, the balance of the section is intended to apply,
and the section as a whole is intended to apply in other circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
12. If the distribution and/or use of the Library is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Library under this License may add
an explicit geographical distribution limitation excluding those countries,
so that distribution is permitted only in or among countries not thus
excluded. In such case, this License incorporates the limitation as if
written in the body of this License.
13. The Free Software Foundation may publish revised and/or new
versions of the Lesser 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 Library
specifies a version number of this License which applies to it and
"any later version", you have the option of following the terms and
conditions either of that version or of any later version published by
the Free Software Foundation. If the Library does not specify a
license version number, you may choose any version ever published by
the Free Software Foundation.
14. If you wish to incorporate parts of the Library into other free
programs whose distribution conditions are incompatible with these,
write to the author to ask for permission. For software which is
copyrighted by the Free Software Foundation, write to the Free
Software Foundation; we sometimes make exceptions for this. Our
decision will be guided by the two goals of preserving the free status
of all derivatives of our free software and of promoting the sharing
and reuse of software generally.
NO WARRANTY
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
OTHER PARTIES PROVIDE THE LIBRARY "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
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
AND/OR REDISTRIBUTE THE LIBRARY 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
LIBRARY (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 LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Libraries
If you develop a new library, and you want it to be of the greatest
possible use to the public, we recommend making it free software that
everyone can redistribute and change. You can do so by permitting
redistribution under these terms (or, alternatively, under the terms of the
ordinary General Public License).
To apply these terms, attach the following notices to the library. It is
safest to attach them to the start of each source file to most effectively
convey 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 library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Also add information on how to contact you by electronic and paper mail.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the library, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the
library `Frob' (a library for tweaking knobs) written by James Random Hacker.
, 1 April 1990
Ty Coon, President of Vice
That's all there is to it!
libnfs-libnfs-2.0.0/Makefile.am 0000664 0000000 0000000 00000000471 13121032772 0016275 0 ustar 00root root 0000000 0000000 SUBDIRS = doc mount nfs nfs4 nlm nsm portmap rquota lib include $(MAYBE_UTILS) . $(MAYBE_EXAMPLES)
ACLOCAL_AMFLAGS = -I m4
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = libnfs.pc
EXTRA_DIST = \
README \
COPYING \
LICENCE-BSD.txt \
LICENCE-GPL-3.txt \
LICENCE-LGPL-2.1.txt \
examples \
libnfs.pc.in
libnfs-libnfs-2.0.0/README 0000664 0000000 0000000 00000015115 13121032772 0015122 0 ustar 00root root 0000000 0000000 LIBNFS is a client library for accessing NFS shares over a network.
LIBNFS offers three different APIs, for different use :
1, RAW : A fully async low level RPC library for NFS protocols
This API is described in include/libnfs-raw.h
it offers a fully async interface to raw XDR encoded blobs.
This API provides very flexible and precise control of the RPC issued.
examples/nfsclient-raw.c provides examples on how to use the raw API
2, NFS ASYNC : A fully asynchronous library for high level vfs functions
This API is described by the *_async() functions in include/libnfs.h.
This API provides a fully async access to posix vfs like functions such as
stat(), read(), ...
examples/nfsclient-async.c provides examples on how to use this API
3, NFS SYNC : A synchronous library for high level vfs functions
This API is described by the *_sync() functions in include/libnfs.h.
This API provides access to posix vfs like functions such as
stat(), read(), ...
examples/nfsclient-sync.c provides examples on how to use this API
NFSv4:
======
NFSv4 is supported but only for the RAW ASYNC interface.
Examples/nfsv4-cat.c is a "simple" example to illustrate how to use
NFSv4 to connect to a server and read a file off the server.
SERVER SUPPORT:
===============
Libnfs supports building RPC servers.
Examples/portmapper-server.c is a small "portmapper" example written using
libnfs.
URL-FORMAT:
===========
Libnfs uses RFC2224 style URLs extended with some minor libnfs extensions.
The basic syntax of these URLs is :
nfs:///path[?arg=val[&arg=val]*]
Arguments supported by libnfs are :
tcp-syncnt= : Number of SYNs to send during the session establish
before failing setting up the tcp connection to the
server.
uid= : UID value to use when talking to the server.
default it 65534 on Windows and getuid() on unixen.
gid= : GID value to use when talking to the server.
default it 65534 on Windows and getgid() on unixen.
readahead= : Enable readahead for files and set the maximum amount
of readahead to bytes.
auto-traverse-mounts=<0|1>
: Should libnfs try to traverse across nested mounts
automatically or not. Default is 1 == enabled.
dircache=<0|1> : Disable/enable directory caching. Enabled by default.
autoreconnect=<-1|0|>=1>
: Control the auto-reconnect behaviour to the NFS session.
-1 : Try to reconnect forever on session failures.
Just like normal NFS clients do.
0 : Disable auto-reconnect completely and immediately
return a failure to the application.
>=1 : Retry to connect back to the server this many
times before failing and returing an error back
to the application.
if= : Interface name (e.g., eth1) to bind; requires `root`
Auto_traverse_mounts
====================
Normally in NFSv3 if a server has nested exports, for example if it would
export both /data and /data/tmp then a client would need to mount
both these exports as well.
The reason is because the NFSv3 protocol does not allow a client request
to return data for an object in a different filesystem/mount.
(legacy, but it is what it is. One reason for this restriction is to
guarantee that inodes are unique across the mounted system.)
This option, when enabled, will make libnfs perform all these mounts
internally for you. This means that one libnfs mount may now have files
with duplicate inode values so if you cache files based on inode
make sure you cache files based on BOTH st.st_ino and st.st_dev.
ROOT vs NON-ROOT
================
When running as root, libnfs tries to allocate a system port for its connection
to the NFS server. When running as non-root it will use a normal
ephemeral port.
Many NFS servers default to a mode where they do not allow non-system
ports from connecting.
These servers require you use the "insecure" export option in /etc/exports
in order to allow libnfs clients to be able to connect.
On Linux we can get around this restriction by setting the NET_BIND_SERVICE
capability for the application binary.
This is set up by running
sudo setcap 'cap_net_bind_service=+ep' /path/to/executable
This capability allows the binary to use systems ports like this even when
not running as root. Thus if you set this capability for your application
you no longer need to edit the export on the NFS server to set "insecure".
I do not know what equivalent "capability" support is available on other
platforms. Please drop me an email if your os of choice has something similar
and I can add it to the README.
DOCUMENTATION
=============
libnfs sources ship with prebuilt manpage(s) in the doc directory.
If you change the manpage sources you need to manually regenerate the new
manpages by running
cd doc
make doc
PLATFORM support
=================
This is a truly multiplatform library.
Linux: - tested with Ubuntu 10.04 - should work with others as well
Cygwin: - tested under 64bit win2k8.
MacOSX: - tested with SDK 10.4 (under Snow Leopard) - should also work with later SDKs and 64Bit
iOS: - tested with iOS SDK 4.2 - running on iOS 4.3.x
FreeBSD:- tested with 8.2
Solaris
Windows:- tested on Windows 7 64 and Windows XP 32 using Visual Studio 10 (see README.win32.txt for build instructions)
- tested on Windows 7 64 using MingW on Linux to cross-compile (Debian and Ubuntu tested)
Android:- tested with NDK r10e - running on Android 4.4 (should work starting from 2.3.3)
AROS: - Build with 'make -f aros/Makefile.AROS'
LD_PRELOAD
==========
examples/ld_nfs.c contains a LD_PRELOADable module that can be used to make
several standard utilities nfs aware.
It is still very incomplete but can be used for basic things such as cat and cp.
Patches to add more coverage is welcome.
Compile with :
gcc -fPIC -shared -o ld_nfs.so examples/ld_nfs.c -ldl -lnfs
Then try things like
LD_NFS_DEBUG=9 LD_PRELOAD=./ld_nfs.so cat nfs://127.0.0.1/data/tmp/foo123
LD_NFS_DEBUG=9 LD_PRELOAD=./ld_nfs.so cp nfs://127.0.0.1/data/tmp/foo123 nfs://127.0.0.1/data/tmp/foo123.copy
This is just a toy preload module. Don't open bugs if it does not work. Send
patches to make it better instead.
RELEASE TARBALLS
================
Release tarballs are available at
https://sites.google.com/site/libnfstarballs/li
MAILING LIST
============
A libnfs mailing list is available at http://groups.google.com/group/libnfs
Announcements of new versions of libnfs will be posted to this list.
libnfs-libnfs-2.0.0/aros/ 0000775 0000000 0000000 00000000000 13121032772 0015203 5 ustar 00root root 0000000 0000000 libnfs-libnfs-2.0.0/aros/Makefile.AROS 0000775 0000000 0000000 00000002737 13121032772 0017422 0 ustar 00root root 0000000 0000000 AR=ar
CC=gcc
CFLAGS=-g -O0 -DAROS=1 -D_U_=" " -DHAVE_SOCKADDR_LEN -I. -Iinclude -Iinclude/nfsc -Iaros -Infs -Imount
OBJS=lib/init.o lib/libnfs.o lib/libnfs-sync.o lib/libnfs-zdr.o lib/pdu.o lib/socket.o
OBJS+=mount/mount.o mount/libnfs-raw-mount.o
OBJS+=nfs/nfs.o nfs/nfsacl.o nfs/libnfs-raw-nfs.o
OBJS+=nlm/nlm.o nlm/libnfs-raw-nlm.o
OBJS+=portmap/portmap.o portmap/libnfs-raw-portmap.o
OBJS+=rquota/rquota.o rquota/libnfs-raw-rquota.o
OBJS+=aros/aros_compat.o
EXAMPLES=examples/nfsclient-listservers examples/nfsclient-sync examples/nfs-cp examples/nfs-ls
all: lib/libnfs.a $(EXAMPLES)
lib/libnfs.a: $(OBJS)
$(AR) cru $@ $(OBJS)
.c.o:
echo $(CC) $(CFLAGS) -c -o $@ $<
$(CC) $(CFLAGS) -c -o $@ $<
install: all
cp lib/libnfs.a GCC:lib
mkdir -p INCLUDE:nfsc
cp include/nfsc/libnfs.h INCLUDE:nfsc
cp include/nfsc/libnfs-raw.h INCLUDE:nfsc
cp include/nfsc/libnfs-zdr.h INCLUDE:nfsc
cp mount/libnfs-raw-mount.h INCLUDE:nfsc
cp nlm/libnfs-raw-nlm.h INCLUDE:nfsc
cp nfs/libnfs-raw-nfs.h INCLUDE:nfsc
cp portmap/libnfs-raw-portmap.h INCLUDE:nfsc
cp rquota/libnfs-raw-rquota.h INCLUDE:nfsc
examples/nfsclient-listservers: examples/nfsclient-listservers.c lib/libnfs.a
$(CC) $(CFLAGS) -o $@ $< lib/libnfs.a
examples/nfsclient-sync: examples/nfsclient-sync.c lib/libnfs.a
$(CC) $(CFLAGS) -o $@ $< lib/libnfs.a
examples/nfs-ls: examples/nfs-ls.c lib/libnfs.a
$(CC) $(CFLAGS) -o $@ $< lib/libnfs.a
examples/nfs-cp: examples/nfs-cp.c lib/libnfs.a
$(CC) $(CFLAGS) -o $@ $< lib/libnfs.a
libnfs-libnfs-2.0.0/aros/aros_compat.c 0000664 0000000 0000000 00000010123 13121032772 0017653 0 ustar 00root root 0000000 0000000 /*
Copyright (C) 2013 by Ronnie Sahlberg
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, see .
*/
#include
#include
#include
#include
#include
#include
#include
#include "aros_compat.h"
#include
#include
#undef poll
int aros_getnameinfo(const struct sockaddr *sa, socklen_t salen,
char *host, size_t hostlen,
char *serv, size_t servlen, int flags)
{
struct sockaddr_in *sin = (struct sockaddr_in *)sa;
if (host) {
snprintf(host, hostlen, Inet_NtoA(sin->sin_addr.s_addr));
}
return 0;
}
int aros_getaddrinfo(const char *node, const char*service,
const struct addrinfo *hints,
struct addrinfo **res)
{
struct sockaddr_in *sin;
sin = malloc(sizeof(struct sockaddr_in));
sin->sin_len = sizeof(struct sockaddr_in);
sin->sin_family=AF_INET;
/* Some error checking would be nice */
sin->sin_addr.s_addr = inet_addr(node);
sin->sin_port=0;
if (service) {
sin->sin_port=htons(atoi(service));
}
*res = malloc(sizeof(struct addrinfo));
(*res)->ai_family = AF_INET;
(*res)->ai_addrlen = sizeof(struct sockaddr_in);
(*res)->ai_addr = (struct sockaddr *)sin;
return 0;
}
void aros_freeaddrinfo(struct addrinfo *res)
{
free(res->ai_addr);
free(res);
}
int aros_inet_pton(int af, char *src, void *dst)
{
struct sockaddr_in sin;
sin.sin_addr.s_addr = inet_addr(src);
memcpy(dst, &sin.sin_addr.s_addr, sizeof(sin.sin_addr.s_addr));
return 1;
}
/* unix device numbers dont really make much sense on aros ... */
int major(int i)
{
return 1;
}
int minor(int i)
{
return 2;
}
struct Library * SocketBase = NULL;
extern int errno;
int h_errno = 0;
void aros_init_socket(void)
{
if (!(SocketBase = OpenLibrary("bsdsocket.library", 4))) {
printf("NoTCP/IP Stack available");
exit(10);
}
if (SocketBaseTags(SBTM_SETVAL(SBTC_ERRNOPTR(sizeof(errno))),
(IPTR)&errno,
SBTM_SETVAL(SBTC_HERRNOLONGPTR),
(IPTR)&h_errno, TAG_DONE)) {
printf("Failed to set ERRNO");
exit(10);
}
}
int aros_poll(struct pollfd *fds, unsigned int nfds, int timo)
{
struct timeval timeout, *toptr;
fd_set ifds, ofds, efds, *ip, *op;
unsigned int i, maxfd = 0;
int rc;
// Set up the file-descriptor sets in ifds, ofds and efds.
FD_ZERO(&ifds);
FD_ZERO(&ofds);
FD_ZERO(&efds);
for (i = 0, op = ip = 0; i < nfds; ++i)
{
fds[i].revents = 0;
if(fds[i].events & (POLLIN|POLLPRI))
{
ip = &ifds;
FD_SET(fds[i].fd, ip);
}
if(fds[i].events & POLLOUT)
{
op = &ofds;
FD_SET(fds[i].fd, op);
}
FD_SET(fds[i].fd, &efds);
if (fds[i].fd > maxfd) {
maxfd = fds[i].fd;
}
}
// Set up the timeval structure for the timeout parameter
if(timo < 0)
{
toptr = 0;
}
else
{
toptr = &timeout;
timeout.tv_sec = timo / 1000;
timeout.tv_usec = (timo - timeout.tv_sec * 1000) * 1000;
}
rc = WaitSelect(maxfd + 1, ip, op, &efds, toptr, NULL);
if(rc <= 0)
return rc;
if(rc > 0)
{
for (i = 0; i < nfds; ++i)
{
int fd = fds[i].fd;
if(fds[i].events & (POLLIN|POLLPRI) && FD_ISSET(fd, &ifds))
fds[i].revents |= POLLIN;
if(fds[i].events & POLLOUT && FD_ISSET(fd, &ofds))
fds[i].revents |= POLLOUT;
if(FD_ISSET(fd, &efds)) // Some error was detected ... should be some way to know.
fds[i].revents |= POLLHUP;
}
}
return rc;
}
libnfs-libnfs-2.0.0/aros/aros_compat.h 0000664 0000000 0000000 00000004053 13121032772 0017665 0 ustar 00root root 0000000 0000000 /*
Copyright (C) 2013 by Ronnie Sahlberg
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, see .
*/
#ifndef AROS_COMPAT_H
#define AROS_COMPAT_H
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define statvfs statfs
#define ioctl IoctlSocket
#define close CloseSocket
#define inet_pton aros_inet_pton
#define freeaddrinfo aros_freeaddrinfo
#define getnameinfo aros_getnameinfo
#define getaddrinfo aros_getaddrinfo
extern struct Library * SocketBase;
void aros_init_socket(void);
#define f_flag f_flags
#define f_favail f_ffree
/* we dont have these at all */
#define f_fsid f_spare[0]
#define f_frsize f_spare[0]
#define f_namemax f_spare[0]
#define POLLIN 0x0001 /* There is data to read */
#define POLLPRI 0x0002 /* There is urgent data to read */
#define POLLOUT 0x0004 /* Writing now will not block */
#define POLLERR 0x0008 /* Error condition */
#define POLLHUP 0x0010 /* Hung up */
#define POLLNVAL 0x0020 /* Invalid request: fd not open */
struct utimbuf {
int actime;
int modtime;
};
struct pollfd {
int fd; /* file descriptor */
short events; /* requested events */
short revents; /* returned events */
};
#define poll(x, y, z) aros_poll(x, y, z)
#endif
libnfs-libnfs-2.0.0/bootstrap 0000775 0000000 0000000 00000000042 13121032772 0016176 0 ustar 00root root 0000000 0000000 #!/bin/sh -e
exec autoreconf -vif
libnfs-libnfs-2.0.0/configure.ac 0000775 0000000 0000000 00000014744 13121032772 0016542 0 ustar 00root root 0000000 0000000 AC_PREREQ(2.50)
AC_INIT([libnfs], [2.0.0], [ronniesahlberg@gmail.com])
AC_CONFIG_HEADERS([config.h])
AM_INIT_AUTOMAKE([-Wall foreign subdir-objects])
AC_CANONICAL_HOST
AC_CONFIG_MACRO_DIR([m4])
m4_pattern_allow([AM_PROG_AR])
AM_PROG_AR
# Work around stupid autoconf default cflags. pt 1
SAVE_CFLAGS="x${CFLAGS}"
AC_PROG_CC
AC_PROG_LIBTOOL
AM_PROG_CC_C_O
PKG_PROG_PKG_CONFIG
# Work around stupid autoconf default cflags. pt 2
if test "$SAVE_CFLAGS" = "x"; then
CFLAGS=""
fi
# We always want 64 bit file offsets
AC_SYS_LARGEFILE
#option: utils
AC_ARG_ENABLE([utils],
[AC_HELP_STRING([--enable-utils],
[Build util programs])],
[MAYBE_UTILS=""],
[MAYBE_UTILS="utils"])
AC_SUBST(MAYBE_UTILS)
#option: examples
AC_ARG_ENABLE([examples],
[AC_HELP_STRING([--enable-examples],
[Build example programs])],
[ENABLE_EXAMPLES=$enableval],
[ENABLE_EXAMPLES="no"])
# We need popt to compile the examples
if test x$ENABLE_EXAMPLES = xyes; then
AC_MSG_CHECKING(whether libpopt is available)
ac_save_LIBS="$LIBS"
LIBS="$LIBS -lpopt"
AC_TRY_LINK([#include ], [
/*
* Just see if we can compile/link with popt
*/
int _argc;
char **_argv;
struct poptOption popt_options[] = {
POPT_TABLEEND
};
poptGetContext(_argv[0], _argc, _argv, popt_options, POPT_CONTEXT_KEEP_FIRST);
], ac_cv_have_popt=yes, ac_cv_have_popt=no)
LIBS="$ac_save_LIBS"
if test "$ac_cv_have_popt" = yes ; then
AC_MSG_RESULT(yes)
MAYBE_EXAMPLES="examples"
else
AC_MSG_RESULT(no)
AC_MSG_NOTICE(You need libpopt to compile the sample libnfs clients.)
AC_MSG_NOTICE(Only the library will be compiled and installed.)
fi
fi
AC_SUBST(MAYBE_EXAMPLES)
AC_MSG_CHECKING(whether SO_BINDTODEVICE is available)
AC_TRY_COMPILE([#include ], [
int i = SO_BINDTODEVICE;
], ac_cv_have_so_bindtodevice=yes, ac_cv_have_so_bindtodevice=no)
if test "$ac_cv_have_so_bindtodevice" = yes ; then
AC_MSG_RESULT(yes)
AC_DEFINE(HAVE_SO_BINDTODEVICE, 1, [Whether our sockets support SO_BINDTODEVICE])
else
AC_MSG_RESULT(no)
AC_MSG_NOTICE(SO_BINDTODEVICE support for if= support is missing.)
AC_MSG_NOTICE(Compiling without if= support.)
fi
AC_ARG_ENABLE([werror], [AS_HELP_STRING([--disable-werror],
[Disables building with -Werror by default])])
if test "$ac_cv_prog_gcc" = yes; then
WARN_CFLAGS="-Wall -Wshadow -Wno-write-strings -Wstrict-prototypes -Wpointer-arith -Wcast-align -Wno-strict-aliasing"
if test "x$enable_werror" != "xno"; then
WARN_CFLAGS="$WARN_CFLAGS -Werror"
fi
fi
AC_SUBST(WARN_CFLAGS)
LIBSOCKET=
SYS=
case $host in
*solaris*)
AC_CHECK_HEADERS([sys/filio.h])
AC_CHECK_HEADERS([sys/sockio.h])
AC_CHECK_LIB([socket], [main], , [AC_MSG_ERROR([Can not find required library])])
AC_CHECK_LIB([nsl], [main], , [AC_MSG_ERROR([Can not find required library])])
;;
*mingw32* | *wince* | *mingwce*)
LIBSOCKET='-lws2_32'
SYS=mingw32
;;
*)
;;
esac
AM_CONDITIONAL(HAVE_WIN32, test "${SYS}" = "mingw32")
AC_SUBST([LIBSOCKET])
# check for sys/sysmacros.h
dnl Check for sys/sysmacros.h
AC_CHECK_HEADERS([sys/sysmacros.h])
# check for poll.h
dnl Check for poll.h
AC_CHECK_HEADERS([poll.h])
# check for unistd.h
dnl Check for unistd.h
AC_CHECK_HEADERS([unistd.h])
# check for netdb.h
dnl Check for netdb.h
AC_CHECK_HEADERS([netdb.h])
# check for utime.h
dnl Check for utime.h
AC_CHECK_HEADERS([utime.h])
# check for net/if.h
dnl Check for net/if.h
AC_CHECK_HEADERS([net/if.h])
# check for sys/time.h
dnl Check for sys/time.h
AC_CHECK_HEADERS([sys/time.h])
# check for sys/ioctl.h
dnl Check for sys/ioctl.h
AC_CHECK_HEADERS([sys/ioctl.h])
# check for sys/vfs.h
dnl Check for sys/vfs.h
AC_CHECK_HEADERS([sys/vfs.h])
# check for sys/statvfs.h
dnl Check for sys/statvfs.h
AC_CHECK_HEADERS([sys/statvfs.h])
# check for fuse.h
dnl Check for fuse.h
AC_CHECK_HEADERS([fuse.h])
# check for sys/socket.h
dnl Check for sys/socket.h
AC_CHECK_HEADERS([sys/socket.h])
# check for netinet/tcp.h
dnl Check for netinet/tcp.h
AC_CHECK_HEADERS([netinet/tcp.h])
# check for netinet/in.h
dnl Check for netinet/in.h
AC_CHECK_HEADERS([netinet/in.h])
# check for arpa/inet.h
dnl Check for arpa/inet.h
AC_CHECK_HEADERS([arpa/inet.h])
# check for SA_LEN
dnl Check if sockaddr data structure includes a "sa_len"
AC_CHECK_MEMBER([struct sockaddr.sa_len],
[ AC_DEFINE(HAVE_SOCKADDR_LEN,1,[Whether sockaddr struct has sa_len]) ],
[],
[
#include
#include
])
# check for sockaddr_storage
dnl Check if sockaddr structure includes a "ss_family"
AC_CHECK_MEMBER([struct sockaddr_storage.ss_family],
[ AC_DEFINE(HAVE_SOCKADDR_STORAGE,1,[Whether we have sockaddr_Storage]) ],
[],
[
#include
#include
])
# check for clock_gettime(CLOCK_MONOTONIC_COARSE)
AC_MSG_CHECKING(if clock_gettime(CLOCK_MONOTONIC_COARSE) is available)
AC_TRY_COMPILE([#include ], [
int i = clock_gettime(CLOCK_MONOTONIC_COARSE, NULL);
], ac_cv_have_clock_gettime=yes, ac_cv_have_clock_gettime=no)
if test "$ac_cv_have_clock_gettime" = yes ; then
AC_MSG_RESULT(yes)
AC_DEFINE(HAVE_CLOCK_GETTIME, 1, [Whether we have clock_gettime])
else
AC_MSG_RESULT(no)
AC_MSG_NOTICE(clock_gettime(CLOCK_MONOTONIC_COARSE) support is missing.)
AC_MSG_NOTICE(Compiling without clock_gettime support..)
fi
# check for tevent + talloc
AC_CACHE_CHECK([for talloc and tevent support],libnfs_cv_HAVE_TALLOC_TEVENT,[
AC_TRY_COMPILE([
#include
#include ],
[struct tevent_context *ctx = tevent_context_init(NULL);
int major = talloc_version_major();],
libiscsi_cv_HAVE_TALLOC_TEVENT=yes,libiscsi_cv_HAVE_TALLOC_TEVENT=no)])
if test x"$libiscsi_cv_HAVE_TALLOC_TEVENT" = x"yes"; then
AC_DEFINE(HAVE_TALLOC_TEVENT,1,[Whether we have talloc nad tevent support])
fi
AM_CONDITIONAL([HAVE_TALLOC_TEVENT], [test $libiscsi_cv_HAVE_TALLOC_TEVENT = yes])
AC_CHECK_MEMBERS([struct stat.st_mtim.tv_nsec])
# check where makedev is defined
AC_HEADER_MAJOR
#output
AC_CONFIG_FILES([Makefile]
[doc/Makefile]
[include/Makefile]
[lib/Makefile]
[mount/Makefile]
[nfs/Makefile]
[nfs4/Makefile]
[nlm/Makefile]
[nsm/Makefile]
[portmap/Makefile]
[rquota/Makefile]
[utils/Makefile]
[examples/Makefile]
)
AC_OUTPUT([libnfs.pc])
libnfs-libnfs-2.0.0/doc/ 0000775 0000000 0000000 00000000000 13121032772 0015004 5 ustar 00root root 0000000 0000000 libnfs-libnfs-2.0.0/doc/Makefile.am 0000664 0000000 0000000 00000001103 13121032772 0017033 0 ustar 00root root 0000000 0000000 XSLTPROC = /usr/bin/xsltproc
EXTRA_DIST = nfs-cat.1 nfs-cat.1.xml nfs-cp.1 nfs-cp.1.xml nfs-ls.1 nfs-ls.1.xml
# Manpages
man1_MANS = nfs-cat.1 nfs-cp.1 nfs-ls.1
doc:
-test -z "$(XSLTPROC)" || $(XSLTPROC) -o nfs-cat.1 http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl nfs-cat.1.xml
-test -z "$(XSLTPROC)" || $(XSLTPROC) -o nfs-cp.1 http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl nfs-cp.1.xml
-test -z "$(XSLTPROC)" || $(XSLTPROC) -o nfs-ls.1 http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl nfs-ls.1.xml
libnfs-libnfs-2.0.0/doc/nfs-cat.1 0000664 0000000 0000000 00000003242 13121032772 0016422 0 ustar 00root root 0000000 0000000 '\" t
.\" Title: nfs-cat
.\" Author: [FIXME: author] [see http://docbook.sf.net/el/author]
.\" Generator: DocBook XSL Stylesheets v1.78.1
.\" Date: 05/24/2015
.\" Manual: nfs-cat: read a file from nfs
.\" Source: nfs-cat
.\" Language: English
.\"
.TH "NFS\-CAT" "1" "05/24/2015" "nfs\-cat" "nfs\-cat: read a file from nfs"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.\" http://bugs.debian.org/507673
.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.\" -----------------------------------------------------------------
.\" * set default formatting
.\" -----------------------------------------------------------------
.\" disable hyphenation
.nh
.\" disable justification (adjust text to left margin only)
.ad l
.\" -----------------------------------------------------------------
.\" * MAIN CONTENT STARTS HERE *
.\" -----------------------------------------------------------------
.SH "NAME"
nfs-cat \- Utility to read a file off NFS
.SH "SYNOPSIS"
.HP \w'\fBnfs\-cat\ \fR\ 'u
\fBnfs\-cat \fR
.SH "DESCRIPTION"
.PP
nfs\-cat is a utility to read a file off an NFS server\&.
.PP
Example: Print the content of a file:
.sp
.if n \{\
.RS 4
.\}
.nf
$ nfs\-cat nfs://127\&.0\&.0\&.1/data/tmp/foo\&.c
.fi
.if n \{\
.RE
.\}
.sp
.SH "SEE ALSO"
.PP
\m[blue]\fB\%http://github.com/sahlberg/libnfs\fR\m[]
libnfs-libnfs-2.0.0/doc/nfs-cat.1.xml 0000664 0000000 0000000 00000001676 13121032772 0017232 0 ustar 00root root 0000000 0000000
nfs-cat
1
nfs-cat
nfs-cat: read a file from nfs
nfs-cat
Utility to read a file off NFS
nfs-cat <NFS-URL>
DESCRIPTION
nfs-cat is a utility to read a file off an NFS server.
Example: Print the content of a file:
$ nfs-cat nfs://127.0.0.1/data/tmp/foo.c
SEE ALSO
libnfs-libnfs-2.0.0/doc/nfs-cp.1 0000664 0000000 0000000 00000003501 13121032772 0016253 0 ustar 00root root 0000000 0000000 '\" t
.\" Title: nfs-cp
.\" Author: [FIXME: author] [see http://docbook.sf.net/el/author]
.\" Generator: DocBook XSL Stylesheets v1.78.1
.\" Date: 05/24/2015
.\" Manual: nfs-cp: copy files to/from an NFS share
.\" Source: nfs-cp
.\" Language: English
.\"
.TH "NFS\-CP" "1" "05/24/2015" "nfs\-cp" "nfs\-cp: copy files to/from an"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.\" http://bugs.debian.org/507673
.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.\" -----------------------------------------------------------------
.\" * set default formatting
.\" -----------------------------------------------------------------
.\" disable hyphenation
.nh
.\" disable justification (adjust text to left margin only)
.ad l
.\" -----------------------------------------------------------------
.\" * MAIN CONTENT STARTS HERE *
.\" -----------------------------------------------------------------
.SH "NAME"
nfs-cp \- Utility to copy files to/from and NFS server
.SH "SYNOPSIS"
.HP \w'\fBnfs\-cp\ \ \fR\ 'u
\fBnfs\-cp \fR
.SH "DESCRIPTION"
.PP
nfs\-cp is a utility to copy files to/from and NFS server\&.
.PP
Examples:
.sp
.if n \{\
.RS 4
.\}
.nf
$ nfs\-cp foo\&.c nfs://127\&.0\&.0\&.1/data/tmp/foo\&.c
$ nfs\-cp nfs://127\&.0\&.0\&.1/data/tmp/foo\&.c bob\&.c
$ nfs\-cp nfs://127\&.0\&.0\&.1/data/tmp/foo\&.c nfs://127\&.0\&.0\&.1/data/tmp/copy\-of\-foo\&.c
.fi
.if n \{\
.RE
.\}
.sp
.SH "SEE ALSO"
.PP
\m[blue]\fB\%http://github.com/sahlberg/libnfs\fR\m[]
libnfs-libnfs-2.0.0/doc/nfs-cp.1.xml 0000664 0000000 0000000 00000002104 13121032772 0017050 0 ustar 00root root 0000000 0000000
nfs-cp
1
nfs-cp
nfs-cp: copy files to/from an NFS share
nfs-cp
Utility to copy files to/from and NFS server
nfs-cp <src> <dst>
DESCRIPTION
nfs-cp is a utility to copy files to/from and NFS server.
Examples:
$ nfs-cp foo.c nfs://127.0.0.1/data/tmp/foo.c
$ nfs-cp nfs://127.0.0.1/data/tmp/foo.c bob.c
$ nfs-cp nfs://127.0.0.1/data/tmp/foo.c nfs://127.0.0.1/data/tmp/copy-of-foo.c
SEE ALSO
libnfs-libnfs-2.0.0/doc/nfs-ls.1 0000664 0000000 0000000 00000006003 13121032772 0016267 0 ustar 00root root 0000000 0000000 '\" t
.\" Title: nfs-ls
.\" Author: [FIXME: author] [see http://docbook.sf.net/el/author]
.\" Generator: DocBook XSL Stylesheets v1.78.1
.\" Date: 05/24/2015
.\" Manual: nfs-ls: list servers, exports and directories
.\" Source: nfs-ls
.\" Language: English
.\"
.TH "NFS\-LS" "1" "05/24/2015" "nfs\-ls" "nfs\-ls: list servers, exports"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.\" http://bugs.debian.org/507673
.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.\" -----------------------------------------------------------------
.\" * set default formatting
.\" -----------------------------------------------------------------
.\" disable hyphenation
.nh
.\" disable justification (adjust text to left margin only)
.ad l
.\" -----------------------------------------------------------------
.\" * MAIN CONTENT STARTS HERE *
.\" -----------------------------------------------------------------
.SH "NAME"
nfs-ls \- Utility to list NFS servers, exports and directories
.SH "SYNOPSIS"
.HP \w'\fBnfs\-ls\ [\ OPTIONS\ ]\ \fR\ 'u
\fBnfs\-ls [ OPTIONS ] \fR
.HP \w'\fBnfs\-ls\fR\ 'u
\fBnfs\-ls\fR [\-R\ \-\-recursive] [\-s\ \-\-summary] [\-D\ \-\-discovery] [\-?\ \-\-help] [\-\-usage]
.SH "DESCRIPTION"
.PP
nfs\-ls is a utility to list NFS servers, exports or directories\&.
.PP
Example: List the content of a directory on the NFS server
.sp
.if n \{\
.RS 4
.\}
.nf
$ nfs\-ls nfs://127\&.0\&.0\&.1/data/tmp
\-rwxrwxr\-x 1 1000 1000 1190802 a\&.out
\-rwxr\-xr\-x 1 1000 1000 13 foo123\&.copy
\-rwxrwxrwx 1 1000 1000 8 foo123\&.writtenx
.fi
.if n \{\
.RE
.\}
.sp
.SH "OPTIONS"
.PP
\-s \-\-summary
.RS 4
Print a summary line at the end of output\&.
.RE
.PP
\-R \-\-recursive
.RS 4
Recursive listing of the specified URL\&.
.RE
.PP
\-D \-\-discovery;
.RS 4
This option is used to discover local NFS servers and to list the exports for specific servers\&.
.sp
When used with the \*(Aqnfs://\*(Aq URL the command will try to detect all local NFS servers and will list their IPs\&.
.sp
When used with a \*(Aqnfs://server\*(Aq the command will list all the exports on the specified server\&.
.sp
Example: Discover and list all local NFS servers
.sp
.if n \{\
.RS 4
.\}
.nf
$ nfs\-ls \-D nfs://
nfs://10\&.10\&.10\&.10
nfs://10\&.0\&.0\&.10
.fi
.if n \{\
.RE
.\}
.sp
Example: List the exports for a server
.sp
.if n \{\
.RS 4
.\}
.nf
$ nfs\-ls \-D nfs://10\&.10\&.10\&.10
nfs://10\&.10\&.10\&.10/foo
nfs://10\&.10\&.10\&.10/bar
.fi
.if n \{\
.RE
.\}
.sp
.RE
.PP
\-? \-\-help
.RS 4
Display basic help text\&.
.RE
.PP
\-\-usage
.RS 4
Display basic usage text\&.
.RE
.SH "SEE ALSO"
.PP
\m[blue]\fB\%http://github.com/sahlberg/libnfs\fR\m[]
libnfs-libnfs-2.0.0/doc/nfs-ls.1.xml 0000664 0000000 0000000 00000006061 13121032772 0017072 0 ustar 00root root 0000000 0000000
nfs-ls
1
nfs-ls
nfs-ls: list servers, exports and directories
nfs-ls
Utility to list NFS servers, exports and directories
nfs-ls [ OPTIONS ] <NFS-URL>
nfs-ls
-R --recursive
-s --summary
-D --discovery
-? --help
--usage
DESCRIPTION
nfs-ls is a utility to list NFS servers, exports or directories.
Example: List the content of a directory on the NFS server
$ nfs-ls nfs://127.0.0.1/data/tmp
-rwxrwxr-x 1 1000 1000 1190802 a.out
-rwxr-xr-x 1 1000 1000 13 foo123.copy
-rwxrwxrwx 1 1000 1000 8 foo123.writtenx
OPTIONS
-s --summary
Print a summary line at the end of output.
-R --recursive
Recursive listing of the specified URL.
-D --discovery;
This option is used to discover local NFS servers and to list
the exports for specific servers.
When used with the 'nfs://' URL the command will try to
detect all local NFS servers and will list their IPs.
When used with a 'nfs://server' the command will
list all the exports on the specified server.
Example: Discover and list all local NFS servers
$ nfs-ls -D nfs://
nfs://10.10.10.10
nfs://10.0.0.10
Example: List the exports for a server
$ nfs-ls -D nfs://10.10.10.10
nfs://10.10.10.10/foo
nfs://10.10.10.10/bar
-? --help
Display basic help text.
--usage
Display basic usage text.
SEE ALSO
libnfs-libnfs-2.0.0/examples/ 0000775 0000000 0000000 00000000000 13121032772 0016055 5 ustar 00root root 0000000 0000000 libnfs-libnfs-2.0.0/examples/Makefile.am 0000664 0000000 0000000 00000001743 13121032772 0020116 0 ustar 00root root 0000000 0000000 noinst_PROGRAMS = nfsclient-async nfsclient-raw nfsclient-sync nfsclient-bcast nfsclient-listservers nfs-io nfs-ln nfs4-cat portmap-client portmap-server
if HAVE_TALLOC_TEVENT
noinst_PROGRAMS += nfs4-cat-talloc
endif
AM_CPPFLAGS = \
-I$(abs_top_srcdir)/include \
-I$(abs_top_srcdir)/include/nfsc \
-I$(abs_top_srcdir)/include/win32 \
-I$(abs_top_srcdir)/mount \
-I$(abs_top_srcdir)/nfs \
-I$(abs_top_srcdir)/nfs4 \
-I$(abs_top_srcdir)/portmap \
-I$(abs_top_srcdir)/rquota \
"-D_U_=__attribute__((unused))"
COMMON_LIBS = ../lib/libnfs.la -lpopt
nfsclient_async_LDADD = $(COMMON_LIBS)
nfsclient_raw_LDADD = $(COMMON_LIBS)
nfsclient_sync_LDADD = $(COMMON_LIBS)
nfsclient_bcast_LDADD = $(COMMON_LIBS)
nfsclient_listservers_LDADD = $(COMMON_LIBS)
nfs_io_LDADD = $(COMMON_LIBS)
nfs_ln_LDADD = $(COMMON_LIBS)
nfs4_cat_LDADD = $(COMMON_LIBS) -levent
nfs4_cat_talloc_LDADD = $(COMMON_LIBS) -ltevent -ltalloc
portmap_client_LDADD = $(COMMON_LIBS)
portmap_server_LDADD = $(COMMON_LIBS) -levent
libnfs-libnfs-2.0.0/examples/ld_nfs.c 0000664 0000000 0000000 00000037301 13121032772 0017472 0 ustar 00root root 0000000 0000000 /*
Copyright (C) 2014 by Ronnie Sahlberg
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 _GNU_SOURCE
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define NFS_MAX_FD 255
static int debug = 0;
#ifndef discard_const
#define discard_const(ptr) ((void *)((intptr_t)(ptr)))
#endif
#define LD_NFS_DPRINTF(level, fmt, args...) \
do { \
if ((debug) >= level) { \
fprintf(stderr,"ld_nfs: "); \
fprintf(stderr, (fmt), ##args); \
fprintf(stderr,"\n"); \
} \
} while (0);
struct nfs_fd_list {
int is_nfs;
struct nfs_context *nfs;
struct nfsfh *fh;
/* so we can reopen and emulate dup2() */
const char *path;
int flags;
mode_t mode;
};
static struct nfs_fd_list nfs_fd_list[NFS_MAX_FD];
int (*real_open)(__const char *path, int flags, mode_t mode);
int open(const char *path, int flags, mode_t mode)
{
if (!strncmp(path, "nfs:", 4)) {
struct nfs_context *nfs;
struct nfs_url *url;
struct nfsfh *fh = NULL;
int ret, fd;
LD_NFS_DPRINTF(9, "open(%s, %x, %o)", path, flags, mode);
nfs = nfs_init_context();
if (nfs == NULL) {
LD_NFS_DPRINTF(1, "Failed to create context");
errno = ENOMEM;
return -1;
}
url = nfs_parse_url_full(nfs, path);
if (url == NULL) {
LD_NFS_DPRINTF(1, "Failed to parse URL: %s\n",
nfs_get_error(nfs));
nfs_destroy_context(nfs);
errno = EINVAL;
return -1;
}
if (nfs_mount(nfs, url->server, url->path) != 0) {
LD_NFS_DPRINTF(1, "Failed to mount nfs share : %s\n",
nfs_get_error(nfs));
nfs_destroy_url(url);
nfs_destroy_context(nfs);
errno = EINVAL;
return -1;
}
if (flags & O_CREAT) {
if ((ret = nfs_creat(nfs, url->file, mode, &fh)) != 0) {
LD_NFS_DPRINTF(1, "Failed to creat nfs file : "
"%s\n", nfs_get_error(nfs));
nfs_destroy_url(url);
nfs_destroy_context(nfs);
errno = -ret;
return -1;
}
} else {
if ((ret = nfs_open(nfs, url->file, flags, &fh)) != 0) {
LD_NFS_DPRINTF(1, "Failed to open nfs file : "
"%s\n", nfs_get_error(nfs));
nfs_destroy_url(url);
nfs_destroy_context(nfs);
errno = -ret;
return -1;
}
}
fd = nfs_get_fd(nfs);
if (fd >= NFS_MAX_FD) {
LD_NFS_DPRINTF(1, "Too many files open");
nfs_destroy_url(url);
nfs_destroy_context(nfs);
errno = ENFILE;
return -1;
}
nfs_fd_list[fd].is_nfs = 1;
nfs_fd_list[fd].nfs = nfs;
nfs_fd_list[fd].fh = fh;
nfs_fd_list[fd].path = strdup(path);
nfs_fd_list[fd].flags = flags;
nfs_fd_list[fd].mode = mode;
nfs_destroy_url(url);
LD_NFS_DPRINTF(9, "open(%s) == %d", path, fd);
return fd;
}
return real_open(path, flags, mode);
}
int open64(const char *path, int flags, mode_t mode)
{
return open(path, flags | O_LARGEFILE, mode);
}
int (*real_close)(int fd);
int close(int fd)
{
if (nfs_fd_list[fd].is_nfs == 1) {
int i;
LD_NFS_DPRINTF(9, "close(%d)", fd);
nfs_fd_list[fd].is_nfs = 0;
nfs_close(nfs_fd_list[fd].nfs, nfs_fd_list[fd].fh);
nfs_fd_list[fd].fh = NULL;
nfs_destroy_context(nfs_fd_list[fd].nfs);
nfs_fd_list[fd].nfs = NULL;
free(discard_const(nfs_fd_list[fd].path));
nfs_fd_list[fd].path = NULL;
return 0;
}
return real_close(fd);
}
ssize_t (*real_read)(int fd, void *buf, size_t count);
ssize_t read(int fd, void *buf, size_t count)
{
if (nfs_fd_list[fd].is_nfs == 1) {
int ret;
LD_NFS_DPRINTF(9, "read(fd:%d count:%d)", fd, (int)count);
if ((ret = nfs_read(nfs_fd_list[fd].nfs, nfs_fd_list[fd].fh,
count, buf)) < 0) {
errno = -ret;
return -1;
}
return ret;
}
return real_read(fd, buf, count);
}
ssize_t (*real_pread)(int fd, void *buf, size_t count, off_t offset);
ssize_t pread(int fd, void *buf, size_t count, off_t offset) {
if (nfs_fd_list[fd].is_nfs == 1) {
int ret;
LD_NFS_DPRINTF(9, "pread(fd:%d offset:%d count:%d)", fd,
(int)offset, (int)count);
if ((ret = nfs_pread(nfs_fd_list[fd].nfs, nfs_fd_list[fd].fh,
offset, count, buf)) < 0) {
errno = -ret;
return -1;
}
return ret;
}
return real_pread(fd, buf, count, offset);
}
ssize_t (*real_write)(int fd, const void *buf, size_t count);
ssize_t write(int fd, const void *buf, size_t count)
{
if (nfs_fd_list[fd].is_nfs == 1) {
int ret;
LD_NFS_DPRINTF(9, "write(fd:%d count:%d)", fd, (int)count);
if ((ret = nfs_write(nfs_fd_list[fd].nfs, nfs_fd_list[fd].fh,
count,
(char *)discard_const(buf))) < 0) {
errno = -ret;
return -1;
}
return ret;
}
return real_write(fd, buf, count);
}
ssize_t (*real_pwrite)(int fd, const void *buf, size_t count, off_t offset);
ssize_t pwrite(int fd, const void *buf, size_t count, off_t offset) {
if (nfs_fd_list[fd].is_nfs == 1) {
int ret;
LD_NFS_DPRINTF(9, "pwrite(fd:%d offset:%d count:%d)", fd,
(int)offset, (int)count);
if ((ret = nfs_pwrite(nfs_fd_list[fd].nfs, nfs_fd_list[fd].fh,
offset, count,
(char *)discard_const(buf))) < 0) {
errno = -ret;
return -1;
}
return ret;
}
return real_pwrite(fd, buf, count, offset);
}
int (*real_dup2)(int oldfd, int newfd);
int dup2(int oldfd, int newfd)
{
close(newfd);
if (nfs_fd_list[oldfd].is_nfs == 1) {
struct nfs_context *nfs;
struct nfs_url *url;
struct nfsfh *fh = NULL;
int ret, fd;
LD_NFS_DPRINTF(9, "dup2(%s:%d, %d)", nfs_fd_list[oldfd].path,
oldfd, newfd);
nfs = nfs_init_context();
if (nfs == NULL) {
LD_NFS_DPRINTF(1, "Failed to create context");
errno = ENOMEM;
return -1;
}
url = nfs_parse_url_full(nfs, nfs_fd_list[oldfd].path);
if (url == NULL) {
LD_NFS_DPRINTF(1, "Failed to parse URL: %s\n",
nfs_get_error(nfs));
nfs_destroy_context(nfs);
errno = EINVAL;
return -1;
}
if (nfs_mount(nfs, url->server, url->path) != 0) {
LD_NFS_DPRINTF(1, "Failed to mount nfs share : %s\n",
nfs_get_error(nfs));
nfs_destroy_url(url);
nfs_destroy_context(nfs);
errno = EINVAL;
return -1;
}
if ((ret = nfs_open(nfs, url->file, nfs_fd_list[oldfd].mode,
&fh)) != 0) {
LD_NFS_DPRINTF(1, "Failed to open nfs file : %s\n",
nfs_get_error(nfs));
nfs_destroy_url(url);
nfs_destroy_context(nfs);
errno = -ret;
return -1;
}
/* We could actually end on the right descriptor by chance */
if (nfs_get_fd(nfs) != newfd) {
if (real_dup2(nfs_get_fd(nfs), newfd) < 0) {
LD_NFS_DPRINTF(1, "Failed to dup2 file : %d",
errno);
return -1;
}
close(rpc_get_fd(nfs_get_rpc_context(nfs)));
rpc_set_fd(nfs_get_rpc_context(nfs), newfd);
}
fd = nfs_get_fd(nfs);
if (fd >= NFS_MAX_FD) {
LD_NFS_DPRINTF(1, "Too many files open");
nfs_destroy_url(url);
nfs_destroy_context(nfs);
errno = ENFILE;
return -1;
}
nfs_fd_list[fd].is_nfs = 1;
nfs_fd_list[fd].nfs = nfs;
nfs_fd_list[fd].fh = fh;
nfs_fd_list[fd].path = strdup(nfs_fd_list[oldfd].path);
nfs_fd_list[fd].flags = nfs_fd_list[oldfd].flags;
nfs_fd_list[fd].mode = nfs_fd_list[oldfd].mode;
nfs_destroy_url(url);
LD_NFS_DPRINTF(9, "dup2(%s) successful",
nfs_fd_list[oldfd].path);
return fd;
}
return real_dup2(oldfd, newfd);
}
int (*real_xstat)(int ver, __const char *path, struct stat *buf);
int __xstat(int ver, const char *path, struct stat *buf)
{
if (!strncmp(path, "nfs:", 4)) {
int fd, ret;
LD_NFS_DPRINTF(9, "__xstat(%s)", path);
fd = open(path, 0, 0);
if (fd == -1) {
return fd;
}
ret = __fxstat(ver, fd, buf);
close(fd);
return ret;
}
return real_xstat(ver, path, buf);
}
int (*real_xstat64)(int ver, __const char *path, struct stat64 *buf);
int __xstat64(int ver, const char *path, struct stat64 *buf)
{
if (!strncmp(path, "nfs:", 4)) {
int fd, ret;
LD_NFS_DPRINTF(9, "__xstat64(%s)", path);
fd = open(path, 0, 0);
if (fd == -1) {
return fd;
}
ret = __fxstat64(ver, fd, buf);
close(fd);
return ret;
}
return real_xstat64(ver, path, buf);
}
int (*real_lxstat)(int ver, __const char *path, struct stat *buf);
int __lxstat(int ver, const char *path, struct stat *buf)
{
if (!strncmp(path, "nfs:", 4)) {
int fd, ret;
LD_NFS_DPRINTF(9, "__lxstat(%s)", path);
fd = open(path, 0, 0);
if (fd == -1) {
return fd;
}
ret = __fxstat(ver, fd, buf);
close(fd);
return ret;
}
return real_lxstat(ver, path, buf);
}
int (*real_lxstat64)(int ver, __const char *path, struct stat64 *buf);
int __lxstat64(int ver, const char *path, struct stat64 *buf)
{
if (!strncmp(path, "nfs:", 4)) {
int fd, ret;
LD_NFS_DPRINTF(9, "__lxstat64(%s)", path);
fd = open(path, 0, 0);
if (fd == -1) {
return fd;
}
ret = __fxstat64(ver, fd, buf);
close(fd);
return ret;
}
return real_lxstat64(ver, path, buf);
}
int (*real_fxstat)(int ver, int fd, struct stat *buf);
int __fxstat(int ver, int fd, struct stat *buf)
{
if (nfs_fd_list[fd].is_nfs == 1) {
int ret;
struct nfs_stat_64 st64;
LD_NFS_DPRINTF(9, "__fxstat(%d)", fd);
if ((ret = nfs_fstat64(nfs_fd_list[fd].nfs, nfs_fd_list[fd].fh,
(void *)&st64)) < 0) {
errno = -ret;
return -1;
}
buf->st_dev = st64.nfs_dev;
buf->st_ino = st64.nfs_ino;
buf->st_mode = st64.nfs_mode;
buf->st_nlink = st64.nfs_nlink;
buf->st_uid = st64.nfs_uid;
buf->st_gid = st64.nfs_gid;
buf->st_rdev = st64.nfs_rdev;
buf->st_size = st64.nfs_size;
buf->st_blksize = st64.nfs_blksize;
buf->st_blocks = st64.nfs_blocks;
buf->st_atim.tv_sec = st64.nfs_atime;
buf->st_atim.tv_usec = st64.nfs_atime_nsec / 1000;
buf->st_mtim.tv_sec = st64.nfs_mtime;
buf->st_mtim.tv_usec = st64.nfs_mtime_nsec / 1000;
buf->st_ctim.tv_sec = st64.nfs_ctime;
buf->st_ctim.tv_usec = st64.nfs_ctime_nsec / 1000;
LD_NFS_DPRINTF(9, "__fxstat(%d) success", fd);
return ret;
}
return real_fxstat(ver, fd, buf);
}
int (*real_fxstat64)(int ver, int fd, struct stat64 *buf);
int __fxstat64(int ver, int fd, struct stat64 *buf)
{
if (nfs_fd_list[fd].is_nfs == 1) {
int ret;
struct nfs_stat_64 st64;
LD_NFS_DPRINTF(9, "__fxstat64(%d)", fd);
if ((ret = nfs_fstat64(nfs_fd_list[fd].nfs, nfs_fd_list[fd].fh,
(void *)&st64)) < 0) {
errno = -ret;
return -1;
}
buf->st_dev = st64.nfs_dev;
buf->st_ino = st64.nfs_ino;
buf->st_mode = st64.nfs_mode;
buf->st_nlink = st64.nfs_nlink;
buf->st_uid = st64.nfs_uid;
buf->st_gid = st64.nfs_gid;
buf->st_rdev = st64.nfs_rdev;
buf->st_size = st64.nfs_size;
buf->st_blksize = st64.nfs_blksize;
buf->st_blocks = st64.nfs_blocks;
buf->st_atim.tv_sec = st64.nfs_atime;
buf->st_atim.tv_usec = st64.nfs_atime_nsec / 1000;
buf->st_mtim.tv_sec = st64.nfs_mtime;
buf->st_mtim.tv_usec = st64.nfs_mtime_nsec / 1000;
buf->st_ctim.tv_sec = st64.nfs_ctime;
buf->st_ctim.tv_usec = st64.nfs_ctime_nsec / 1000;
LD_NFS_DPRINTF(9, "__fxstat64(%d) success", fd);
return ret;
}
return real_fxstat64(ver, fd, buf);
}
int (*real_fallocate)(int fd, int mode, off_t offset, off_t len);
int fallocate(int fd, int mode, off_t offset, off_t len)
{
if (nfs_fd_list[fd].is_nfs == 1) {
LD_NFS_DPRINTF(9, "fallocate(%d)", fd);
errno = EOPNOTSUPP;
return -1;
}
return real_fallocate(fd, mode, offset, len);
}
int (*real_ftruncate)(int fd, off_t len);
int ftruncate(int fd, off_t len)
{
if (nfs_fd_list[fd].is_nfs == 1) {
int ret;
LD_NFS_DPRINTF(9, "ftruncate(%d, %d)", fd, (int)len);
if ((ret = nfs_ftruncate(nfs_fd_list[fd].nfs,
nfs_fd_list[fd].fh,
len)) < 0) {
errno = -ret;
return -1;
}
return 0;
}
return real_ftruncate(fd, len);
}
int (*real_truncate)(const char *path, off_t len);
int truncate(const char *path, off_t len)
{
if (!strncmp(path, "nfs:", 4)) {
int fd, ret;
LD_NFS_DPRINTF(9, "truncate(%s, %d)", path, (int)len);
fd = open(path, 0, 0);
if (fd == -1) {
return fd;
}
ret = ftruncate(fd, len);
close(fd);
return ret;
}
return real_truncate(path, len);
}
int (*real_fchmod)(int fd, mode_t mode);
int fchmod(int fd, mode_t mode)
{
if (nfs_fd_list[fd].is_nfs == 1) {
int ret;
LD_NFS_DPRINTF(9, "fchmod(%d, %o)", fd, (int)mode);
if ((ret = nfs_fchmod(nfs_fd_list[fd].nfs,
nfs_fd_list[fd].fh,
mode)) < 0) {
errno = -ret;
return -1;
}
return 0;
}
return real_fchmod(fd, mode);
}
int (*real_chmod)(const char *path, mode_t mode);
int chmod(const char *path, mode_t mode)
{
if (!strncmp(path, "nfs:", 4)) {
int fd, ret;
LD_NFS_DPRINTF(9, "chmod(%s, %o)", path, (int)mode);
fd = open(path, 0, 0);
if (fd == -1) {
return fd;
}
ret = fchmod(fd, mode);
close(fd);
return ret;
}
return real_chmod(path, mode);
}
static void __attribute__((constructor)) _init(void)
{
int i;
if (getenv("LD_NFS_DEBUG") != NULL) {
debug = atoi(getenv("LD_NFS_DEBUG"));
}
real_open = dlsym(RTLD_NEXT, "open");
if (real_open == NULL) {
LD_NFS_DPRINTF(0, "Failed to dlsym(open)");
exit(10);
}
real_close = dlsym(RTLD_NEXT, "close");
if (real_close == NULL) {
LD_NFS_DPRINTF(0, "Failed to dlsym(close)");
exit(10);
}
real_read = dlsym(RTLD_NEXT, "read");
if (real_read == NULL) {
LD_NFS_DPRINTF(0, "Failed to dlsym(read)");
exit(10);
}
real_pread = dlsym(RTLD_NEXT, "pread");
if (real_pread == NULL) {
LD_NFS_DPRINTF(0, "Failed to dlsym(pread)");
exit(10);
}
real_write = dlsym(RTLD_NEXT, "write");
if (real_write == NULL) {
LD_NFS_DPRINTF(0, "Failed to dlsym(write)");
exit(10);
}
real_pwrite = dlsym(RTLD_NEXT, "pwrite");
if (real_pwrite == NULL) {
LD_NFS_DPRINTF(0, "Failed to dlsym(pwrite)");
exit(10);
}
real_xstat = dlsym(RTLD_NEXT, "__xstat");
if (real_xstat == NULL) {
LD_NFS_DPRINTF(0, "Failed to dlsym(__xstat)");
exit(10);
}
real_xstat64 = dlsym(RTLD_NEXT, "__xstat64");
if (real_xstat64 == NULL) {
LD_NFS_DPRINTF(0, "Failed to dlsym(__xstat64)");
}
real_lxstat = dlsym(RTLD_NEXT, "__lxstat");
if (real_lxstat == NULL) {
LD_NFS_DPRINTF(0, "Failed to dlsym(__lxstat)");
exit(10);
}
real_lxstat64 = dlsym(RTLD_NEXT, "__lxstat64");
if (real_lxstat64 == NULL) {
LD_NFS_DPRINTF(0, "Failed to dlsym(_lxstat64)");
exit(10);
}
real_fxstat = dlsym(RTLD_NEXT, "__fxstat");
if (real_fxstat == NULL) {
LD_NFS_DPRINTF(0, "Failed to dlsym(__fxstat)");
exit(10);
}
real_fxstat64 = dlsym(RTLD_NEXT, "__fxstat64");
if (real_fxstat64 == NULL) {
LD_NFS_DPRINTF(0, "Failed to dlsym(__fxstat64)");
exit(10);
}
real_fallocate = dlsym(RTLD_NEXT, "fallocate");
if (real_fallocate == NULL) {
LD_NFS_DPRINTF(0, "Failed to dlsym(fallocate)");
exit(10);
}
real_dup2 = dlsym(RTLD_NEXT, "dup2");
if (real_dup2 == NULL) {
LD_NFS_DPRINTF(0, "Failed to dlsym(dup2)");
exit(10);
}
real_truncate = dlsym(RTLD_NEXT, "truncate");
if (real_truncate == NULL) {
LD_NFS_DPRINTF(0, "Failed to dlsym(truncate)");
exit(10);
}
real_ftruncate = dlsym(RTLD_NEXT, "ftruncate");
if (real_ftruncate == NULL) {
LD_NFS_DPRINTF(0, "Failed to dlsym(ftruncate)");
exit(10);
}
real_chmod = dlsym(RTLD_NEXT, "chmod");
if (real_chmod == NULL) {
LD_NFS_DPRINTF(0, "Failed to dlsym(chmod)");
exit(10);
}
real_fchmod = dlsym(RTLD_NEXT, "fchmod");
if (real_fchmod == NULL) {
LD_NFS_DPRINTF(0, "Failed to dlsym(fchmod)");
exit(10);
}
}
libnfs-libnfs-2.0.0/examples/nfs-io.c 0000664 0000000 0000000 00000007656 13121032772 0017432 0 ustar 00root root 0000000 0000000 /*
Copyright (C) by Peter Lieven 2013
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 _FILE_OFFSET_BITS 64
#define _GNU_SOURCE
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#ifdef AROS
#include "aros_compat.h"
#endif
#ifdef WIN32
#include "win32_compat.h"
#pragma comment(lib, "ws2_32.lib")
WSADATA wsaData;
#define PRId64 "ll"
#else
#include
#include
#include
#include
#ifndef AROS
#include
#endif
#endif
#ifdef HAVE_UNISTD_H
#include
#endif
#include
#include
#include
#include
#include
#include
#include "libnfs.h"
#include "libnfs-raw.h"
#include "libnfs-raw-mount.h"
void print_usage(void)
{
fprintf(stderr, "Usage: nfs-io [-?|--help|--usage] [stat|creat|trunc|unlink|mkdir|rmdir] \n");
}
int main(int argc, char *argv[])
{
int ret = 1;
struct nfs_context *nfs = NULL;
struct nfsfh *nfsfh = NULL;
struct nfs_url *url = NULL;
#ifdef WIN32
if (WSAStartup(MAKEWORD(2,2), &wsaData) != 0) {
printf("Failed to start Winsock2\n");
exit(10);
}
#endif
#ifdef AROS
aros_init_socket();
#endif
if (argc < 3) {
fprintf(stderr, "No URL specified.\n");
goto finished;
}
nfs = nfs_init_context();
if (nfs == NULL) {
printf("failed to init context\n");
goto finished;
}
url = nfs_parse_url_full(nfs, argv[argc - 1]);
if (url == NULL) {
fprintf(stderr, "%s\n", nfs_get_error(nfs));
goto finished;
}
if (nfs_mount(nfs, url->server, url->path) != 0) {
fprintf(stderr, "Failed to mount nfs share : %s\n", nfs_get_error(nfs));
goto finished;
}
if (!strncmp(argv[1], "creat", 5)) {
ret = nfs_creat(nfs, url->file, 0600, &nfsfh);
} else if (!strncmp(argv[1], "unlink", 6)) {
ret = nfs_unlink(nfs, url->file);
} else if (!strncmp(argv[1], "mkdir", 5)) {
ret = nfs_mkdir(nfs, url->file);
} else if (!strncmp(argv[1], "rmdir", 5)) {
ret = nfs_rmdir(nfs, url->file);
} else if (!strncmp(argv[1], "trunc", 5)) {
ret = nfs_truncate(nfs, url->file, 0);
} else if (!strncmp(argv[1], "stat", 4)) {
struct nfs_stat_64 st;
ret = nfs_stat64(nfs, url->file, &st);
if (!ret) {
switch (st.nfs_mode & S_IFMT) {
#ifndef WIN32
case S_IFLNK:
printf("l");
break;
#endif
case S_IFREG:
printf("-");
break;
case S_IFDIR:
printf("d");
break;
case S_IFCHR:
printf("c");
break;
case S_IFBLK:
printf("b");
break;
}
printf("%c%c%c",
"-r"[!!(st.nfs_mode & S_IRUSR)],
"-w"[!!(st.nfs_mode & S_IWUSR)],
"-x"[!!(st.nfs_mode & S_IXUSR)]
);
printf("%c%c%c",
"-r"[!!(st.nfs_mode & S_IRGRP)],
"-w"[!!(st.nfs_mode & S_IWGRP)],
"-x"[!!(st.nfs_mode & S_IXGRP)]
);
printf("%c%c%c",
"-r"[!!(st.nfs_mode & S_IROTH)],
"-w"[!!(st.nfs_mode & S_IWOTH)],
"-x"[!!(st.nfs_mode & S_IXOTH)]
);
printf(" %2d", (int)st.nfs_nlink);
printf(" %5d", (int)st.nfs_uid);
printf(" %5d", (int)st.nfs_gid);
printf(" %12" PRId64, st.nfs_size);
printf("\n");
}
} else {
goto finished;
}
if (ret) {
fprintf(stderr, "ERROR: %s\n", nfs_get_error(nfs));
}
finished:
if (ret > 0) {
print_usage();
}
nfs_destroy_url(url);
if (nfs != NULL) {
if (nfsfh) {
nfs_close(nfs, nfsfh);
}
nfs_destroy_context(nfs);
}
return !!ret;
}
libnfs-libnfs-2.0.0/examples/nfs-ln.c 0000664 0000000 0000000 00000005107 13121032772 0017421 0 ustar 00root root 0000000 0000000 /* -*- mode:c; tab-width:8; c-basic-offset:8; indent-tabs-mode:nil; -*- */
/*
Copyright (C) by Ronnie Sahlberg 2017
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 _FILE_OFFSET_BITS 64
#define _GNU_SOURCE
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#ifdef AROS
#include "aros_compat.h"
#endif
#ifdef WIN32
#include "win32_compat.h"
#pragma comment(lib, "ws2_32.lib")
WSADATA wsaData;
#define PRId64 "ll"
#else
#include
#include
#include
#include
#ifndef AROS
#include
#endif
#endif
#ifdef HAVE_UNISTD_H
#include
#endif
#include
#include
#include
#include
#include
#include
#include "libnfs.h"
#include "libnfs-raw.h"
#include "libnfs-raw-mount.h"
void print_usage(void)
{
fprintf(stderr, "Usage: nfs-ln \n");
}
int main(int argc, char *argv[])
{
int ret = 1;
struct nfs_context *nfs = NULL;
struct nfsfh *nfsfh = NULL;
struct nfs_url *url = NULL;
#ifdef WIN32
if (WSAStartup(MAKEWORD(2,2), &wsaData) != 0) {
printf("Failed to start Winsock2\n");
exit(10);
}
#endif
#ifdef AROS
aros_init_socket();
#endif
if (argc != 4) {
print_usage();
goto finished;
}
nfs = nfs_init_context();
if (nfs == NULL) {
printf("failed to init context\n");
goto finished;
}
url = nfs_parse_url_full(nfs, argv[1]);
if (url == NULL) {
fprintf(stderr, "%s\n", nfs_get_error(nfs));
goto finished;
}
if (nfs_mount(nfs, url->server, url->path) != 0) {
fprintf(stderr, "Failed to mount nfs share : %s\n",
nfs_get_error(nfs));
goto finished;
}
ret = nfs_link(nfs, argv[2], argv[3]);
if (ret) {
fprintf(stderr, "nfs_link() failed with %s\n",
nfs_get_error(nfs));
goto finished;
}
finished:
if (ret > 0) {
print_usage();
}
nfs_destroy_url(url);
if (nfs != NULL) {
if (nfsfh) {
nfs_close(nfs, nfsfh);
}
nfs_destroy_context(nfs);
}
return !!ret;
}
libnfs-libnfs-2.0.0/examples/nfs4-cat-talloc.c 0000664 0000000 0000000 00000071644 13121032772 0021130 0 ustar 00root root 0000000 0000000 /* -*- mode:c; tab-width:8; c-basic-offset:8; indent-tabs-mode:nil; -*- */
/* THIS IS NOT A PROPER NFS4 CLIENT!
* This software is only meant to illustrate how to plug libnfs into
* an eventsystem like libevent and then use the raw rpc api
* connect to an nfsv4 server and read a file.
* If any kind of error occurs it will immediately terminate by calling
* exit() without even attempting to cleanup.
* If the access to the server is successful it should however run valgrind
* clean.
*
* NFSv4 access is done through the raw async interface and is cumbersome
* to use for NFSv4 due to the richness of the protocol.
* A future aim will be to build better helper functions to make ease
* of use better.
*/
/*
Copyright (C) by Ronnie Sahlberg 2015
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 _FILE_OFFSET_BITS 64
#define _GNU_SOURCE
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#ifdef AROS
#include "aros_compat.h"
#endif
#ifdef WIN32
#include "win32_compat.h"
#pragma comment(lib, "ws2_32.lib")
WSADATA wsaData;
#else
#include
#include
#endif
#ifdef HAVE_POLL_H
#include
#endif
#ifdef HAVE_UNISTD_H
#include
#endif
#include
#include
#include
#include
#include
#include
#include
#include
#include "libnfs.h"
#include "libnfs-raw.h"
#include "libnfs-raw-nfs4.h"
#include
#include
struct tevent_context *ev;
struct client {
struct nfs_context *nfs;
struct rpc_context *rpc;
char *server;
char *path;
struct tevent_fd *fde;
int callback_fd;
/* For SETCLIENTID */
verifier4 verifier;
char *id;
clientid4 clientid;
verifier4 setclientid_confirm;
/* For OPEN */
char *owner;
int op_len;
/* filehandle and state for the open file */
nfs_fh4 fh;
uint32_t seqid;
stateid4 stateid;
/* offset when reading */
uint64_t offset;
int is_finished;
};
static void set_nonblocking(int fd)
{
int v = 0;
#if defined(WIN32)
long nonblocking=1;
v = ioctl(fd, FIONBIO, &nonblocking);
#else
v = fcntl(fd, F_GETFL, 0);
fcntl(fd, F_SETFL, v | O_NONBLOCK);
#endif
}
static int client_destructor(struct client *c)
{
if (c->nfs) {
nfs_destroy_context(c->nfs);
}
if (c->callback_fd != -1) {
close(c->callback_fd);
}
};
void usage(void)
{
fprintf(stderr, "Usage: nfs4-cat-talloc \n");
fprintf(stderr, " is an nfs url.\n");
exit(0);
}
static void update_events(struct rpc_context *rpc,
struct tevent_fd *fde)
{
int events = rpc_which_events(rpc);
int flags = 0;
if (events & POLLIN) {
flags |= TEVENT_FD_READ;
}
if (events & POLLOUT) {
flags |= TEVENT_FD_WRITE;
}
tevent_fd_set_flags(fde, flags);
}
struct server {
struct rpc_context *rpc;
struct tevent_fd *fde;
};
/*
* Helper functions to send client RPC requests.
*/
static void send_setclientid(struct rpc_context *rpc,
rpc_cb cb, void *private_data)
{
struct client *client = private_data;
COMPOUND4args args;
SETCLIENTID4args *sc4args;
nfs_argop4 op[1];
struct sockaddr_storage ss;
socklen_t len = sizeof(ss);
struct sockaddr_in *in;
struct sockaddr_in6 *in6;
char *netid;
char str[240], addr[256];
unsigned short port;
if (getsockname(client->callback_fd, (struct sockaddr *)&ss, &len) < 0) {
fprintf(stderr, "getsockaddr failed\n");
talloc_free(client);
exit(10);
}
switch (ss.ss_family) {
case AF_INET:
netid = "tcp";
in = (struct sockaddr_in *)&ss;
inet_ntop(AF_INET, &in->sin_addr, str, sizeof(str));
port = ntohs(in->sin_port);
break;
case AF_INET6:
netid = "tcp6";
in6 = (struct sockaddr_in6 *)&ss;
inet_ntop(AF_INET6, &in6->sin6_addr, str, sizeof(str));
port = ntohs(in6->sin6_port);
break;
}
sprintf(addr, "%s.%d.%d", str, port >> 8, port & 0xff);
memset(op, 0, sizeof(op));
op[0].argop = OP_SETCLIENTID;
sc4args = &op[0].nfs_argop4_u.opsetclientid;
memcpy(sc4args->client.verifier, client->verifier, sizeof(verifier4));
sc4args->client.id.id_len = strlen(client->id);
sc4args->client.id.id_val = client->id;
sc4args->callback.cb_program = NFS4_CALLBACK;
sc4args->callback.cb_location.r_netid = netid;
sc4args->callback.cb_location.r_addr = addr;
sc4args->callback_ident = 0x00000001;
memset(&args, 0, sizeof(args));
args.argarray.argarray_len = sizeof(op) / sizeof(nfs_argop4);
args.argarray.argarray_val = op;
if (rpc_nfs4_compound_async(rpc, cb, &args, private_data) != 0) {
fprintf(stderr, "Failed to send nfs4 SETCLIENTID request\n");
talloc_free(client);
exit(10);
}
}
static void send_setclientid_confirm(struct rpc_context *rpc,
rpc_cb cb, void *private_data)
{
struct client *client = private_data;
COMPOUND4args args;
SETCLIENTID_CONFIRM4args *scc4args;
nfs_argop4 op[1];
memset(op, 0, sizeof(op));
op[0].argop = OP_SETCLIENTID_CONFIRM;
scc4args = &op[0].nfs_argop4_u.opsetclientid_confirm;
scc4args->clientid = client->clientid;
memcpy(scc4args->setclientid_confirm, client->setclientid_confirm,
NFS4_VERIFIER_SIZE);
memset(&args, 0, sizeof(args));
args.argarray.argarray_len = sizeof(op) / sizeof(nfs_argop4);
args.argarray.argarray_val = op;
if (rpc_nfs4_compound_async(rpc, cb, &args, private_data) != 0) {
fprintf(stderr, "Failed to send nfs4 SETCLIENTID_CONFIRM request\n");
talloc_free(client);
exit(10);
}
}
static void send_getrootfh(struct rpc_context *rpc,
rpc_cb cb, void *private_data)
{
struct client *client = private_data;
COMPOUND4args args;
nfs_argop4 op[2];
memset(op, 0, sizeof(op));
op[0].argop = OP_PUTROOTFH;
op[1].argop = OP_GETFH;
memset(&args, 0, sizeof(args));
args.argarray.argarray_len = sizeof(op) / sizeof(nfs_argop4);
args.argarray.argarray_val = op;
if (rpc_nfs4_compound_async(rpc, cb, &args, private_data) != 0) {
fprintf(stderr, "Failed to send nfs4 GETROOTFH request\n");
talloc_free(client);
exit(10);
}
}
static void send_open(struct rpc_context *rpc, nfs_fh4 dir, char *path,
rpc_cb cb, void *private_data)
{
struct client *client = private_data;
COMPOUND4args args;
ACCESS4args *a4args;
LOOKUP4args *l4args;
OPEN4args *o4args;
nfs_argop4 *op;
int i = 0, idx = 0;
char *tmp;
/*
* Count how many directories we have in the path.
*/
tmp = path;
while (tmp = strchr(tmp, '/')) {
i++;
tmp++;
}
op = talloc_zero_array(client, nfs_argop4, 4 + i);
op[idx].argop = OP_PUTFH;
op[idx].nfs_argop4_u.opputfh.object = dir;
idx++;
while (i-- > 0) {
tmp = strchr(path, '/');
*tmp++ = '\0';
op[idx].argop = OP_LOOKUP;
l4args = &op[idx].nfs_argop4_u.oplookup;
l4args->objname.utf8string_len = strlen(path);
l4args->objname.utf8string_val = path;
idx++;
path = tmp;
}
op[idx].argop = OP_OPEN;
o4args = &op[idx].nfs_argop4_u.opopen;
o4args->seqid = client->seqid;
o4args->share_access = OPEN4_SHARE_ACCESS_READ;
o4args->share_deny = OPEN4_SHARE_DENY_NONE;
o4args->owner.clientid = client->clientid;
o4args->owner.owner.owner_len = strlen(client->owner);
o4args->owner.owner.owner_val = client->owner;
o4args->openhow.opentype = OPEN4_NOCREATE;
o4args->claim.claim = CLAIM_NULL;
o4args->claim.open_claim4_u.file.utf8string_len = strlen(path);
o4args->claim.open_claim4_u.file.utf8string_val = path;
idx++;
op[idx].argop = OP_GETFH;
idx++;
op[idx].argop = OP_ACCESS;
a4args = &op[idx].nfs_argop4_u.opaccess;
a4args->access = ACCESS4_READ;
client->seqid++;
memset(&args, 0, sizeof(args));
args.argarray.argarray_len = idx;
args.argarray.argarray_val = op;
if (rpc_nfs4_compound_async(rpc, cb, &args, private_data) != 0) {
fprintf(stderr, "Failed to send nfs4 OPEN request\n");
talloc_free(client);
exit(10);
}
talloc_free(op);
}
static void send_open_confirm(struct rpc_context *rpc, nfs_fh4 object, rpc_cb cb, void *private_data)
{
struct client *client = private_data;
COMPOUND4args args;
OPEN_CONFIRM4args *oc4args;
PUTFH4args *pfh4args;
nfs_argop4 op[2];
memset(op, 0, sizeof(op));
op[0].argop = OP_PUTFH;
pfh4args = &op[0].nfs_argop4_u.opputfh;
pfh4args->object = object;
op[1].argop = OP_OPEN_CONFIRM;
oc4args = &op[1].nfs_argop4_u.opopen_confirm;
oc4args->open_stateid.seqid = client->seqid;
memcpy(oc4args->open_stateid.other,
client->stateid.other, 12);
oc4args->seqid = client->seqid;
client->seqid++;
memset(&args, 0, sizeof(args));
args.argarray.argarray_len = sizeof(op) / sizeof(nfs_argop4);
args.argarray.argarray_val = op;
if (rpc_nfs4_compound_async(rpc, cb, &args, private_data) != 0) {
fprintf(stderr, "Failed to send nfs4 CLOSE request\n");
talloc_free(client);
exit(10);
}
}
static void send_read(struct rpc_context *rpc, nfs_fh4 object,
uint64_t offset, uint32_t count,
rpc_cb cb, void *private_data)
{
struct client *client = private_data;
COMPOUND4args args;
PUTFH4args *pfh4args;
READ4args *r4args;
nfs_argop4 op[3];
memset(op, 0, sizeof(op));
op[0].argop = OP_PUTFH;
pfh4args = &op[0].nfs_argop4_u.opputfh;
pfh4args->object = object;
op[1].argop = OP_READ;
r4args = &op[1].nfs_argop4_u.opread;
r4args->stateid.seqid = client->seqid;
memcpy(r4args->stateid.other, client->stateid.other, 12);
r4args->offset = offset;
r4args->count = count;
op[2].argop = OP_GETATTR;
memset(&args, 0, sizeof(args));
args.argarray.argarray_len = sizeof(op) / sizeof(nfs_argop4);
args.argarray.argarray_val = op;
if (rpc_nfs4_compound_async(rpc, cb, &args, private_data) != 0) {
fprintf(stderr, "Failed to send nfs4 READ request\n");
talloc_free(client);
exit(10);
}
}
static void send_close(struct rpc_context *rpc, nfs_fh4 object,
rpc_cb cb, void *private_data)
{
struct client *client = private_data;
COMPOUND4args args;
CLOSE4args *c4args;
PUTFH4args *pfh4args;
nfs_argop4 op[2];
memset(op, 0, sizeof(op));
op[0].argop = OP_PUTFH;
pfh4args = &op[0].nfs_argop4_u.opputfh;
pfh4args->object = object;
op[1].argop = OP_CLOSE;
c4args = &op[1].nfs_argop4_u.opclose;
c4args->seqid = client->seqid;
c4args->open_stateid.seqid = client->seqid;
memcpy(c4args->open_stateid.other, client->stateid.other, 12);
client->seqid++;
memset(&args, 0, sizeof(args));
args.argarray.argarray_len = sizeof(op) / sizeof(nfs_argop4);
args.argarray.argarray_val = op;
if (rpc_nfs4_compound_async(rpc, cb, &args, private_data) != 0) {
fprintf(stderr, "Failed to send nfs4 CLOSE request\n");
talloc_free(client);
exit(10);
}
}
/*
* Callbacks for completed requests.
*/
void close_cb(struct rpc_context *rpc, int status, void *data,
void *private_data)
{
struct client *client = private_data;
COMPOUND4res *res = data;
/*
* FINISHED
*/
/*
* Note that we can not start tearing down and destroying the contexts
* right here as we are still in a callback from ... rpc_service().
* Instead flag that we should abort and start doing the teardown
* in client_io once we return from libnfs.
*/
client->is_finished = 1;
}
void read_cb(struct rpc_context *rpc, int status, void *data,
void *private_data)
{
struct client *client = private_data;
COMPOUND4res *res = data;
struct READ4res *r4res;
if (status != RPC_STATUS_SUCCESS) {
fprintf(stderr, "Failed to read file on server %s\n",
client->server);
talloc_free(client);
exit(10);
}
if (res->status != NFS4_OK) {
fprintf(stderr, "Failed to read file on server %s\n",
client->server);
talloc_free(client);
exit(10);
}
r4res = &res->resarray.resarray_val[1].nfs_resop4_u.opread;
write(1,
r4res->READ4res_u.resok4.data.data_val,
r4res->READ4res_u.resok4.data.data_len);
/*
* Are we at end-of-file? If so we can close the file and exit.
*/
if (r4res->READ4res_u.resok4.eof) {
send_close(rpc, client->fh, close_cb, client);
return;
}
/*
* We still have more data to read.
*/
client->offset += r4res->READ4res_u.resok4.data.data_len;
send_read(rpc, client->fh, client->offset, 4096, read_cb, client);
}
void open_confirm_cb(struct rpc_context *rpc, int status, void *data,
void *private_data)
{
struct client *client = private_data;
COMPOUND4res *res = data;
if (status != RPC_STATUS_SUCCESS) {
fprintf(stderr, "Failed to confirm open file on server %s\n",
client->server);
talloc_free(client);
exit(10);
}
if (res->status != NFS4_OK) {
fprintf(stderr, "Failed to confirm open file on server %s\n",
client->server);
talloc_free(client);
exit(10);
}
send_read(rpc, client->fh, client->offset, 4096, read_cb, client);
}
void open_cb(struct rpc_context *rpc, int status, void *data,
void *private_data)
{
struct client *client = private_data;
COMPOUND4res *res = data;
GETFH4res *gfh4res;
OPEN4res *o4res;
int idx;
if (status != RPC_STATUS_SUCCESS) {
fprintf(stderr, "Failed to open file on server %s\n",
client->server);
talloc_free(client);
exit(10);
}
if (res->status != NFS4_OK) {
fprintf(stderr, "Failed to open file on server %s\n",
client->server);
talloc_free(client);
exit(10);
}
/* Find the index for the OPEN opcode */
for (idx = 1; idx < res->resarray.resarray_len - 1; idx++) {
if ((res->resarray.resarray_val[idx].resop == OP_OPEN) &&
(res->resarray.resarray_val[idx + 1].resop == OP_GETFH)) {
break;
}
}
if (idx >= res->resarray.resarray_len - 1) {
fprintf(stderr, "No OP_OPEN in server response\n");
talloc_free(client);
exit(10);
}
/* Store the open handle in the client structure */
gfh4res = &res->resarray.resarray_val[idx+1].nfs_resop4_u.opgetfh;
client->fh.nfs_fh4_len = gfh4res->GETFH4res_u.resok4.object.nfs_fh4_len;
client->fh.nfs_fh4_val = talloc_size(client, client->fh.nfs_fh4_len);
if (client->fh.nfs_fh4_val == NULL) {
fprintf(stderr, "Failed to allocate data for nfs_fh4\n");
talloc_free(client);
exit(10);
}
memcpy(client->fh.nfs_fh4_val,
gfh4res->GETFH4res_u.resok4.object.nfs_fh4_val,
client->fh.nfs_fh4_len);
/* Store stateid for the open handle in the client structure */
o4res = &res->resarray.resarray_val[idx].nfs_resop4_u.opopen;
client->stateid.seqid = o4res->OPEN4res_u.resok4.stateid.seqid;
memcpy(client->stateid.other,
o4res->OPEN4res_u.resok4.stateid.other, 12);
/* Check if server wants us to confirm the open */
if (o4res->OPEN4res_u.resok4.rflags & OPEN4_RESULT_CONFIRM) {
send_open_confirm(rpc, client->fh, open_confirm_cb, client);
return;
}
send_read(rpc, client->fh, client->offset, 4096, read_cb, client);
}
void getrootfh_cb(struct rpc_context *rpc, int status, void *data,
void *private_data)
{
struct client *client = private_data;
COMPOUND4res *res = data;
GETFH4res *gfh4res;
if (status != RPC_STATUS_SUCCESS) {
fprintf(stderr, "Failed to get root filehandle of server %s\n",
client->server);
talloc_free(client);
exit(10);
}
if (res->status != NFS4_OK) {
fprintf(stderr, "Failed to get root filehandle of server %s\n",
client->server);
talloc_free(client);
exit(10);
}
gfh4res = &res->resarray.resarray_val[1].nfs_resop4_u.opgetfh;
send_open(rpc, gfh4res->GETFH4res_u.resok4.object,
client->path, open_cb, client);
}
void setclientid_confirm_cb(struct rpc_context *rpc, int status, void *data,
void *private_data)
{
struct client *client = private_data;
COMPOUND4res *res = data;
char *path;
if (status != RPC_STATUS_SUCCESS) {
fprintf(stderr, "Failed to set client id of server %s\n",
client->server);
talloc_free(client);
exit(10);
}
if (res->status != NFS4_OK) {
fprintf(stderr, "Failed to set client id of server %s\n",
client->server);
talloc_free(client);
exit(10);
}
send_getrootfh(rpc, getrootfh_cb, client);
}
void setclientid_cb(struct rpc_context *rpc, int status, void *data,
void *private_data)
{
struct client *client = private_data;
COMPOUND4res *res = data;
SETCLIENTID4res *sc4res;
if (status != RPC_STATUS_SUCCESS) {
fprintf(stderr, "Failed to set client id on server %s\n",
client->server);
talloc_free(client);
exit(10);
}
if (res->status != NFS4_OK) {
fprintf(stderr, "Failed to set client id on server %s\n",
client->server);
talloc_free(client);
exit(10);
}
sc4res = &res->resarray.resarray_val[0].nfs_resop4_u.opsetclientid;
client->clientid = sc4res->SETCLIENTID4res_u.resok4.clientid;
memcpy(client->setclientid_confirm,
sc4res->SETCLIENTID4res_u.resok4.setclientid_confirm,
NFS4_VERIFIER_SIZE);
send_setclientid_confirm(rpc, setclientid_confirm_cb, client);
}
/*
* NULL procedure for the callback protocol.
*/
static int cb_null_proc(struct rpc_context *rpc, struct rpc_msg *call)
{
rpc_send_reply(rpc, call, NULL, (zdrproc_t)zdr_void, 0);
return 0;
}
/*
* CB_COMPOUND procedure for the callback protocol.
* This is where the server will inform us about lease breaks and similar.
*/
static int cb_compound_proc(struct rpc_context *rpc, struct rpc_msg *call)
{
CB_COMPOUND4args *args = call->body.cbody.args;
fprintf(stderr, "cb_compund_cb. Do something here.\n");
return 0;
}
struct service_proc pt[] = {
{CB_NULL, cb_null_proc,
(zdrproc_t)zdr_void, 0},
{CB_COMPOUND, cb_compound_proc,
(zdrproc_t)zdr_CB_COMPOUND4args, sizeof(CB_COMPOUND4args)},
};
static void server_io(struct tevent_context *ev, struct tevent_fd *fde,
uint16_t events, void *private_data)
{
struct server *server = private_data;
int revents = 0;
if (events & TEVENT_FD_READ) {
revents |= POLLIN;
}
if (events & TEVENT_FD_WRITE) {
revents |= POLLOUT;
}
if (rpc_service(server->rpc, revents) < 0) {
talloc_free(server);
return;
}
update_events(server->rpc, server->fde);
}
static int server_destructor(struct server *s)
{
if (s->rpc) {
rpc_destroy_context(s->rpc);
}
}
/*
* This callback is invoked when others (the nfsv4 server) initiates a
* NFSv4 CALLBACK sessions to us.
* We accept() the connection and create a local rpc server context
* for the callback protocol.
*/
static void client_accept(struct tevent_context *ev, struct tevent_fd *fde,
uint16_t events, void *private_data)
{
struct client *client = private_data;
struct server *server;
struct sockaddr_storage ss;
socklen_t len = sizeof(ss);
int fd;
server = talloc_zero(client, struct server);
talloc_set_destructor(server, server_destructor);
if ((fd = accept(client->callback_fd, (struct sockaddr *)&ss, &len)) < 0) {
fprintf(stderr, "accept failed\n");
talloc_free(server);
return;
}
set_nonblocking(fd);
server->rpc = rpc_init_server_context(fd);
if (server->rpc == NULL) {
fprintf(stderr, "Failed to create server rpc context\n");
talloc_free(server);
return;
}
rpc_register_service(server->rpc, NFS4_CALLBACK, NFS_CB,
pt, sizeof(pt) / sizeof(pt[0]));
server->fde = tevent_add_fd(ev, server, fd, TEVENT_FD_READ,
server_io, server);
tevent_fd_set_auto_close(server->fde);
update_events(server->rpc, server->fde);
}
/*
* This callback is invoked when our async connect() to the server has
* completed. At this point we know which IP address was used locally for
* the connection and can bind our nfsv4 callback server instance to it.
*/
void connect_cb(struct rpc_context *rpc, int status, void *data,
void *private_data)
{
struct client *client = private_data;
struct sockaddr_storage ss;
socklen_t len = sizeof(ss);
struct sockaddr_in *in;
struct sockaddr_in6 *in6;
struct tevent_fd *fde;
if (status != RPC_STATUS_SUCCESS) {
fprintf(stderr, "connection to NFSv4 server %s failed\n",
client->server);
talloc_free(client);
exit(10);
}
/*
* NFSv4 CALLBACK
* Now that we have a client connection we can register a callback
* server port on the same IP address as was used to the outgoing
* client connection. That way we know that the address used by the
* server is routable, and uses the same version of ip, that the client
* supports and can route to.
*/
if (getsockname(rpc_get_fd(rpc), (struct sockaddr *)&ss, &len) < 0) {
fprintf(stderr, "getsockaddr failed\n");
talloc_free(client);
exit(10);
}
switch (ss.ss_family) {
case AF_INET:
in = (struct sockaddr_in *)&ss;
in->sin_port=0;
break;
case AF_INET6:
in6 = (struct sockaddr_in6 *)&ss;
in6->sin6_port=0;
break;
default:
fprintf(stderr, "Can not handle AF_FAMILY:%d", ss.ss_family);
talloc_free(client);
exit(10);
}
client->callback_fd = socket(AF_INET, SOCK_STREAM, 0);
if (client->callback_fd == -1) {
fprintf(stderr, "Failed to create callback socket\n");
talloc_free(client);
exit(10);
}
set_nonblocking(client->callback_fd);
if (bind(client->callback_fd, (struct sockaddr *)&ss, sizeof(ss)) < 0) {
fprintf(stderr, "Failed to bind callback socket\n");
talloc_free(client);
exit(10);
}
if (listen(client->callback_fd, 16) < 0) {
fprintf(stderr, "failed to listen to callback socket\n");
talloc_free(client);
exit(10);
}
fde = tevent_add_fd(ev, client, client->callback_fd, TEVENT_FD_READ,
client_accept, private_data);
tevent_fd_set_auto_close(fde);
update_events(client->rpc, client->fde);
/*
* Now that we are finished setting up the callback server port
* we can proceed and negotiate the nfsv4 client id.
*/
send_setclientid(rpc, setclientid_cb, client);
}
static void client_io(struct tevent_context *ev, struct tevent_fd *fde,
uint16_t events, void *private_data)
{
struct client *client = private_data;
int revents = 0;
if (events & TEVENT_FD_READ) {
revents |= POLLIN;
}
if (events & TEVENT_FD_WRITE) {
revents |= POLLOUT;
}
if (rpc_service(client->rpc, revents) < 0) {
fprintf(stderr, "rpc_service failed\n");
talloc_free(client);
exit(10);
}
update_events(client->rpc, client->fde);
if (client->is_finished) {
talloc_free(client);
}
}
int main(int argc, char *argv[])
{
TALLOC_CTX *ctx = talloc_new(NULL);
struct client *client;
struct nfs_url *url;
int i, fd;
#ifdef WIN32
if (WSAStartup(MAKEWORD(2,2), &wsaData) != 0) {
fprintf(stderr, "Failed to start Winsock2\n");
exit(10);
}
#endif
#ifdef AROS
aros_init_socket();
#endif
srandom(time(NULL) ^ getpid());
if (argc < 2) {
usage();
}
ev = tevent_context_init(ctx);
client = talloc_zero(ctx, struct client);
talloc_set_destructor(client, client_destructor);
client->callback_fd = -1;
client->nfs = nfs_init_context();
if (client->nfs == NULL) {
fprintf(stderr, "failed to init nfs context\n");
talloc_free(ctx);
exit(10);
}
url = nfs_parse_url_dir(client->nfs, argv[1]);
if (url == NULL) {
fprintf(stderr, "failed to parse url\n");
talloc_free(ctx);
exit(10);
}
client->server = talloc_strdup(client, url->server);
client->path = talloc_strdup(client, &url->path[1]); // skip leading '/'
nfs_destroy_url(url);
for (i = 0; i < NFS4_VERIFIER_SIZE; i++) {
client->verifier[i] = random() & 0xff;
}
client->id = talloc_asprintf(client, "Libnfs %s tcp pid:%d",
argv[1], getpid());
client->owner = talloc_asprintf(client, "open id:libnfs pid:%d",
getpid());
/*
* From here on we will mainly use the rpc context directly
* and not the nfs context so lets store the rpc context here
* for easy access.
*/
client->rpc = nfs_get_rpc_context(client->nfs);
if (rpc_connect_program_async(client->rpc, client->server,
NFS4_PROGRAM, NFS_V4,
connect_cb, client) != 0) {
fprintf(stderr, "Failed to start connection: %s\n",
rpc_get_error(client->rpc));
talloc_free(ctx);
exit(10);
}
/*
* Set up the events we need for the outgoing client RPC channel.
*/
fd = rpc_get_fd(client->rpc);
client->fde = tevent_add_fd(ev, client, fd, TEVENT_FD_READ,
client_io, (void *)client);
update_events(client->rpc, client->fde);
tevent_loop_wait(ev);
talloc_free(ctx);
return 0;
}
libnfs-libnfs-2.0.0/examples/nfs4-cat.c 0000664 0000000 0000000 00000072661 13121032772 0017654 0 ustar 00root root 0000000 0000000 /* -*- mode:c; tab-width:8; c-basic-offset:8; indent-tabs-mode:nil; -*- */
/* THIS IS NOT A PROPER NFS4 CLIENT!
* This software is only meant to illustrate how to plug libnfs into
* an eventsystem like libevent and then use the raw rpc api
* connect to an nfsv4 server and read a file.
* If any kind of error occurs it will immediately terminate by calling
* exit() without even attempting to cleanup.
* If the access to the server is successful it should however run valgrind
* clean.
*
* NFSv4 access is done through the raw async interface and is cumbersome
* to use for NFSv4 due to the richness of the protocol.
* A future aim will be to build better helper functions to make ease
* of use better.
*/
/*
Copyright (C) by Ronnie Sahlberg 2015
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 _FILE_OFFSET_BITS 64
#define _GNU_SOURCE
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#ifdef AROS
#include "aros_compat.h"
#endif
#ifdef WIN32
#include "win32_compat.h"
#pragma comment(lib, "ws2_32.lib")
WSADATA wsaData;
#else
#include
#include
#endif
#ifdef HAVE_POLL_H
#include
#endif
#ifdef HAVE_UNISTD_H
#include
#endif
#include
#include
#include
#include
#include
#include
#include
#include
#include "libnfs.h"
#include "libnfs-raw.h"
#include "libnfs-raw-nfs4.h"
#include
struct event_base *base;
struct client {
struct rpc_context *rpc;
struct event *read_event;
struct event *write_event;
struct event *listen_event;
char *server;
char *path;
int op_len;
int is_finished;
verifier4 verifier;
char *id;
char *owner;
clientid4 clientid;
verifier4 setclientid_confirm;
/* filehandle and state for the open file */
nfs_fh4 fh;
uint32_t seqid;
stateid4 stateid;
/* offset when reading */
uint64_t offset;
int callback_fd;
};
struct server {
struct server *next;
struct rpc_context *rpc;
struct event *read_event;
struct event *write_event;
};
struct server *server_list;
void usage(void)
{
fprintf(stderr, "Usage: nfs4-cat \n");
fprintf(stderr, " is an nfs url.\n");
exit(0);
}
static void update_events(struct rpc_context *rpc, struct event *read_event,
struct event *write_event)
{
int events = rpc_which_events(rpc);
if (read_event) {
if (events & POLLIN) {
event_add(read_event, NULL);
} else {
event_del(read_event);
}
}
if (write_event) {
if (events & POLLOUT) {
event_add(write_event, NULL);
} else {
event_del(write_event);
}
}
}
static void free_server(struct server *server)
{
if (server->rpc) {
rpc_disconnect(server->rpc, NULL);
rpc_destroy_context(server->rpc);
server->rpc = NULL;
}
if (server->read_event) {
event_free(server->read_event);
server->read_event = NULL;
}
if (server->write_event) {
event_free(server->write_event);
server->write_event = NULL;
}
free(server);
}
static void server_io(evutil_socket_t fd, short events, void *private_data)
{
struct server *server = private_data;
int revents = 0;
if (events & EV_READ) {
revents |= POLLIN;
}
if (events & EV_WRITE) {
revents |= POLLOUT;
}
if (rpc_service(server->rpc, revents) < 0) {
fprintf(stderr, "rpc_service() failed for server\n");
exit(10);
}
update_events(server->rpc, server->read_event, server->write_event);
}
static void client_io(evutil_socket_t fd, short events, void *private_data)
{
struct client *client = private_data;
struct server *server;
int revents = 0;
if (events & EV_READ) {
revents |= POLLIN;
}
if (events & EV_WRITE) {
revents |= POLLOUT;
}
if (rpc_service(client->rpc, revents) < 0) {
fprintf(stderr, "rpc_service failed\n");
exit(10);
}
update_events(client->rpc, client->read_event, client->write_event);
if (client->is_finished) {
/*
* Stop listening for new connections.
*/
event_free(client->listen_event);
client->listen_event = NULL;
/*
* Stop listening for events on the client context.
*/
event_free(client->read_event);
client->read_event = NULL;
event_free(client->write_event);
client->write_event = NULL;
/*
* Stop listening to server connections.
*/
for (server = server_list; server; server = server->next) {
if (server->read_event) {
event_free(server->read_event);
server->read_event = NULL;
}
if (server->write_event) {
event_free(server->write_event);
server->write_event = NULL;
}
}
}
}
/*
* Helper functions to send client RPC requests.
*/
static void send_setclientid_confirm(struct rpc_context *rpc,
rpc_cb cb, void *private_data)
{
struct client *client = private_data;
COMPOUND4args args;
nfs_argop4 op[1];
memset(op, 0, sizeof(op));
op[0].argop = OP_SETCLIENTID_CONFIRM;
op[0].nfs_argop4_u.opsetclientid_confirm.clientid = client->clientid;
memcpy(op[0].nfs_argop4_u.opsetclientid_confirm.setclientid_confirm, client->setclientid_confirm, NFS4_VERIFIER_SIZE);
memset(&args, 0, sizeof(args));
args.argarray.argarray_len = sizeof(op) / sizeof(nfs_argop4);
args.argarray.argarray_val = op;
if (rpc_nfs4_compound_async(rpc, cb, &args, private_data) != 0) {
fprintf(stderr, "Failed to send nfs4 SETCLIENTID_CONFIRM request\n");
exit(10);
}
}
static void send_setclientid(struct rpc_context *rpc,
rpc_cb cb, void *private_data)
{
struct client *client = private_data;
COMPOUND4args args;
nfs_argop4 op[1];
struct sockaddr_storage ss;
socklen_t len = sizeof(ss);
struct sockaddr_in *in;
struct sockaddr_in6 *in6;
char *netid;
char str[240], addr[256];
unsigned short port;
if (getsockname(client->callback_fd, (struct sockaddr *)&ss, &len) < 0) {
fprintf(stderr, "getsockaddr failed\n");
exit(10);
}
switch (ss.ss_family) {
case AF_INET:
netid = "tcp";
in = (struct sockaddr_in *)&ss;
inet_ntop(AF_INET, &in->sin_addr, str, sizeof(str));
port = ntohs(in->sin_port);
break;
case AF_INET6:
netid = "tcp6";
in6 = (struct sockaddr_in6 *)&ss;
inet_ntop(AF_INET6, &in6->sin6_addr, str, sizeof(str));
port = ntohs(in6->sin6_port);
break;
}
sprintf(addr, "%s.%d.%d", str, port >> 8, port & 0xff);
memset(op, 0, sizeof(op));
op[0].argop = OP_SETCLIENTID;
memcpy(op[0].nfs_argop4_u.opsetclientid.client.verifier, client->verifier, sizeof(verifier4));
op[0].nfs_argop4_u.opsetclientid.client.id.id_len = strlen(client->id);
op[0].nfs_argop4_u.opsetclientid.client.id.id_val = client->id;
op[0].nfs_argop4_u.opsetclientid.callback.cb_program = NFS4_CALLBACK;
op[0].nfs_argop4_u.opsetclientid.callback.cb_location.r_netid = netid;
op[0].nfs_argop4_u.opsetclientid.callback.cb_location.r_addr = addr;
op[0].nfs_argop4_u.opsetclientid.callback_ident = 0x00000001;
memset(&args, 0, sizeof(args));
args.argarray.argarray_len = sizeof(op) / sizeof(nfs_argop4);
args.argarray.argarray_val = op;
if (rpc_nfs4_compound_async(rpc, cb, &args, private_data) != 0) {
fprintf(stderr, "Failed to send nfs4 SETCLIENTID request\n");
exit(10);
}
}
static void send_getrootfh(struct rpc_context *rpc,
rpc_cb cb, void *private_data)
{
COMPOUND4args args;
nfs_argop4 op[2];
memset(op, 0, sizeof(op));
op[0].argop = OP_PUTROOTFH;
op[1].argop = OP_GETFH;
memset(&args, 0, sizeof(args));
args.argarray.argarray_len = sizeof(op) / sizeof(nfs_argop4);
args.argarray.argarray_val = op;
if (rpc_nfs4_compound_async(rpc, cb, &args, private_data) != 0) {
fprintf(stderr, "Failed to send nfs4 GETROOTFH request\n");
exit(10);
}
}
static void send_open(struct rpc_context *rpc, nfs_fh4 dir, char *path,
rpc_cb cb, void *private_data)
{
struct client *client = private_data;
COMPOUND4args args;
nfs_argop4 *op;
int i = 0, idx = 0;
char *tmp;
printf("OPEN called\n");
/*
* Count how many directories we have in the path.
*/
tmp = path;
while (tmp = strchr(tmp, '/')) {
i++;
tmp++;
}
op = malloc(sizeof(nfs_argop4) * (4 + i));
memset(op, 0, sizeof(nfs_argop4) * (4 + i));
op[idx].argop = OP_PUTFH;
op[idx].nfs_argop4_u.opputfh.object = dir;
idx++;
while (i-- > 0) {
tmp = strchr(path, '/');
*tmp++ = '\0';
op[idx].argop = OP_LOOKUP;
op[idx].nfs_argop4_u.oplookup.objname.utf8string_len = strlen(path);
op[idx].nfs_argop4_u.oplookup.objname.utf8string_val = path;
idx++;
path = tmp;
}
op[idx].argop = OP_OPEN;
op[idx].nfs_argop4_u.opopen.seqid = client->seqid;
op[idx].nfs_argop4_u.opopen.share_access = OPEN4_SHARE_ACCESS_READ;
op[idx].nfs_argop4_u.opopen.share_deny = OPEN4_SHARE_DENY_NONE;
op[idx].nfs_argop4_u.opopen.owner.clientid = client->clientid;
op[idx].nfs_argop4_u.opopen.owner.owner.owner_len = strlen(client->owner);
op[idx].nfs_argop4_u.opopen.owner.owner.owner_val = client->owner;
op[idx].nfs_argop4_u.opopen.openhow.opentype = OPEN4_NOCREATE;
op[idx].nfs_argop4_u.opopen.claim.claim = CLAIM_NULL;
op[idx].nfs_argop4_u.opopen.claim.open_claim4_u.file.utf8string_len = strlen(path);
op[idx].nfs_argop4_u.opopen.claim.open_claim4_u.file.utf8string_val = path;
idx++;
op[idx].argop = OP_GETFH;
idx++;
op[idx].argop = OP_ACCESS;
op[idx].nfs_argop4_u.opaccess.access = ACCESS4_READ;
client->seqid++;
memset(&args, 0, sizeof(args));
args.argarray.argarray_len = idx;
args.argarray.argarray_val = op;
if (rpc_nfs4_compound_async(rpc, cb, &args, private_data) != 0) {
fprintf(stderr, "Failed to send nfs4 OPEN request\n");
exit(10);
}
}
static void send_open_confirm(struct rpc_context *rpc, nfs_fh4 object, rpc_cb cb, void *private_data)
{
struct client *client = private_data;
COMPOUND4args args;
nfs_argop4 op[2];
memset(op, 0, sizeof(op));
op[0].argop = OP_PUTFH;
op[0].nfs_argop4_u.opputfh.object = object;
op[1].argop = OP_OPEN_CONFIRM;
op[1].nfs_argop4_u.opopen_confirm.open_stateid.seqid = client->seqid;
memcpy(op[1].nfs_argop4_u.opopen_confirm.open_stateid.other, client->stateid.other, 12);
op[1].nfs_argop4_u.opopen_confirm.seqid = client->seqid;
client->seqid++;
memset(&args, 0, sizeof(args));
args.argarray.argarray_len = sizeof(op) / sizeof(nfs_argop4);
args.argarray.argarray_val = op;
if (rpc_nfs4_compound_async(rpc, cb, &args, private_data) != 0) {
fprintf(stderr, "Failed to send nfs4 CLOSE request\n");
exit(10);
}
}
static void send_read(struct rpc_context *rpc, nfs_fh4 object,
uint64_t offset, uint32_t count,
rpc_cb cb, void *private_data)
{
struct client *client = private_data;
COMPOUND4args args;
nfs_argop4 op[3];
memset(op, 0, sizeof(op));
op[0].argop = OP_PUTFH;
op[0].nfs_argop4_u.opputfh.object = object;
op[1].argop = OP_READ;
op[1].nfs_argop4_u.opread.stateid.seqid = client->seqid;
memcpy(op[1].nfs_argop4_u.opread.stateid.other, client->stateid.other, 12);
op[1].nfs_argop4_u.opread.offset = offset;
op[1].nfs_argop4_u.opread.count = count;
op[2].argop = OP_GETATTR;
memset(&args, 0, sizeof(args));
args.argarray.argarray_len = sizeof(op) / sizeof(nfs_argop4);
args.argarray.argarray_val = op;
if (rpc_nfs4_compound_async(rpc, cb, &args, private_data) != 0) {
fprintf(stderr, "Failed to send nfs4 READ request\n");
exit(10);
}
}
static void send_close(struct rpc_context *rpc, nfs_fh4 object,
rpc_cb cb, void *private_data)
{
struct client *client = private_data;
COMPOUND4args args;
nfs_argop4 op[2];
memset(op, 0, sizeof(op));
op[0].argop = OP_PUTFH;
op[0].nfs_argop4_u.opputfh.object = object;
op[1].argop = OP_CLOSE;
op[1].nfs_argop4_u.opclose.seqid = client->seqid;
op[1].nfs_argop4_u.opclose.open_stateid.seqid = client->seqid;
memcpy(op[1].nfs_argop4_u.opclose.open_stateid.other, client->stateid.other, 12);
client->seqid++;
memset(&args, 0, sizeof(args));
args.argarray.argarray_len = sizeof(op) / sizeof(nfs_argop4);
args.argarray.argarray_val = op;
if (rpc_nfs4_compound_async(rpc, cb, &args, private_data) != 0) {
fprintf(stderr, "Failed to send nfs4 CLOSE request\n");
exit(10);
}
}
/*
* Callbacks for completed requests.
*/
void close_cb(struct rpc_context *rpc, int status, void *data, void *private_data)
{
struct client *client = private_data;
COMPOUND4res *res = data;
/*
* FINISHED
*/
/*
* Note that we can not start tearing down and destroying the contexts
* right here as we are still in a callback from ... rpc_service().
* Instead flag that we should abort and start doing the teardown
* in client_io once we return from libnfs.
*/
client->is_finished = 1;
}
void read_cb(struct rpc_context *rpc, int status, void *data, void *private_data)
{
struct client *client = private_data;
COMPOUND4res *res = data;
if (status != RPC_STATUS_SUCCESS) {
fprintf(stderr, "Failed to read file on server %s\n",
client->server);
exit(10);
}
if (res->status != NFS4_OK) {
fprintf(stderr, "Failed to read file on server %s\n",
client->server);
exit(10);
}
write(1, res->resarray.resarray_val[1].nfs_resop4_u.opread.READ4res_u.resok4.data.data_val, res->resarray.resarray_val[1].nfs_resop4_u.opread.READ4res_u.resok4.data.data_len);
/*
* Are we at end-of-file? If so we can close the file and exit.
*/
if (res->resarray.resarray_val[1].nfs_resop4_u.opread.READ4res_u.resok4.eof) {
send_close(rpc, client->fh, close_cb, client);
return;
}
/*
* We still have more data to read.
*/
client->offset += res->resarray.resarray_val[1].nfs_resop4_u.opread.READ4res_u.resok4.data.data_len;
send_read(rpc, client->fh, client->offset, 4096, read_cb, client);
}
void open_confirm_cb(struct rpc_context *rpc, int status, void *data, void *private_data)
{
struct client *client = private_data;
COMPOUND4res *res = data;
if (status != RPC_STATUS_SUCCESS) {
fprintf(stderr, "Failed to confirm open file on server %s\n",
client->server);
exit(10);
}
if (res->status != NFS4_OK) {
fprintf(stderr, "Failed to confirm open file on server %s\n",
client->server);
exit(10);
}
send_read(rpc, client->fh, client->offset, 4096, read_cb, client);
}
void open_cb(struct rpc_context *rpc, int status, void *data, void *private_data)
{
struct client *client = private_data;
COMPOUND4res *res = data;
int idx;
if (status != RPC_STATUS_SUCCESS) {
fprintf(stderr, "Failed to open file on server %s\n",
client->server);
exit(10);
}
if (res->status != NFS4_OK) {
fprintf(stderr, "Failed to open file on server %s\n",
client->server);
exit(10);
}
/* Find the index for the OPEN opcode */
for (idx = 1; idx < res->resarray.resarray_len - 1; idx++) {
if ((res->resarray.resarray_val[idx].resop == OP_OPEN) &&
(res->resarray.resarray_val[idx + 1].resop == OP_GETFH)) {
break;
}
}
if (idx >= res->resarray.resarray_len - 1) {
fprintf(stderr, "No OP_OPEN in server response\n");
exit(10);
}
/* Store the open handle in the client structure */
client->fh.nfs_fh4_len = res->resarray.resarray_val[idx+1].nfs_resop4_u.opgetfh.GETFH4res_u.resok4.object.nfs_fh4_len;
client->fh.nfs_fh4_val = malloc(client->fh.nfs_fh4_len);
if (client->fh.nfs_fh4_val == NULL) {
fprintf(stderr, "Failed to allocate data for nfs_fh4\n");
exit(10);
}
memcpy(client->fh.nfs_fh4_val, res->resarray.resarray_val[idx+1].nfs_resop4_u.opgetfh.GETFH4res_u.resok4.object.nfs_fh4_val, client->fh.nfs_fh4_len);
/* Store stateid for the open handle in the client structure */
client->stateid.seqid = res->resarray.resarray_val[idx].nfs_resop4_u.opopen.OPEN4res_u.resok4.stateid.seqid;
memcpy(client->stateid.other, res->resarray.resarray_val[idx].nfs_resop4_u.opopen.OPEN4res_u.resok4.stateid.other, 12);
/* Check if server wants us to confirm the open */
if (res->resarray.resarray_val[idx].nfs_resop4_u.opopen.OPEN4res_u.resok4.rflags & OPEN4_RESULT_CONFIRM) {
send_open_confirm(rpc, client->fh, open_confirm_cb, client);
return;
}
send_read(rpc, client->fh, client->offset, 4096, read_cb, client);
}
void getrootfh_cb(struct rpc_context *rpc, int status, void *data,
void *private_data)
{
struct client *client = private_data;
COMPOUND4res *res = data;
if (status != RPC_STATUS_SUCCESS) {
fprintf(stderr, "Failed to get root filehandle of server %s\n",
client->server);
exit(10);
}
if (res->status != NFS4_OK) {
fprintf(stderr, "Failed to get root filehandle of server %s\n",
client->server);
exit(10);
}
send_open(rpc, res->resarray.resarray_val[1].nfs_resop4_u.opgetfh.GETFH4res_u.resok4.object, client->path, open_cb, client);
}
void setclientid_confirm_cb(struct rpc_context *rpc, int status, void *data,
void *private_data)
{
struct client *client = private_data;
COMPOUND4res *res = data;
char *path;
if (status != RPC_STATUS_SUCCESS) {
fprintf(stderr, "Failed to set client id of server %s\n",
client->server);
exit(10);
}
if (res->status != NFS4_OK) {
fprintf(stderr, "Failed to set client id of server %s\n",
client->server);
exit(10);
}
send_getrootfh(rpc, getrootfh_cb, client);
}
void setclientid_cb(struct rpc_context *rpc, int status, void *data,
void *private_data)
{
struct client *client = private_data;
COMPOUND4res *res = data;
if (status != RPC_STATUS_SUCCESS) {
fprintf(stderr, "Failed to set client id on server %s\n",
client->server);
exit(10);
}
if (res->status != NFS4_OK) {
fprintf(stderr, "Failed to set client id on server %s\n",
client->server);
exit(10);
}
client->clientid = res->resarray.resarray_val[0].nfs_resop4_u.opsetclientid.SETCLIENTID4res_u.resok4.clientid;
memcpy(client->setclientid_confirm, res->resarray.resarray_val[0].nfs_resop4_u.opsetclientid.SETCLIENTID4res_u.resok4.setclientid_confirm, NFS4_VERIFIER_SIZE);
send_setclientid_confirm(rpc, setclientid_confirm_cb, client);
}
/*
* NULL procedure for the callback protocol.
*/
static int cb_null_proc(struct rpc_context *rpc, struct rpc_msg *call)
{
rpc_send_reply(rpc, call, NULL, (zdrproc_t)zdr_void, 0);
return 0;
}
/*
* CB_COMPOUND procedure for the callback protocol.
* This is where the server will inform us about lease breaks and similar.
*/
static int cb_compound_proc(struct rpc_context *rpc, struct rpc_msg *call)
{
CB_COMPOUND4args *args = call->body.cbody.args;
fprintf(stderr, "cb_compund_cb. Do something here.\n");
return 0;
}
struct service_proc pt[] = {
{CB_NULL, cb_null_proc,
(zdrproc_t)zdr_void, 0},
{CB_COMPOUND, cb_compound_proc,
(zdrproc_t)zdr_CB_COMPOUND4args, sizeof(CB_COMPOUND4args)},
};
/*
* This callback is invoked when others (the nfsv4 server) initiates a
* NFSv4 CALLBACK sessions to us.
* We accept() the connection and create a local rpc server context
* for the callback protocol.
*/
static void client_accept(evutil_socket_t s, short events, void *private_data)
{
struct client *client = private_data;
struct server *server;
struct sockaddr_storage ss;
socklen_t len = sizeof(ss);
int fd;
server = malloc(sizeof(struct server));
if (server == NULL) {
fprintf(stderr, "failed to malloc server structure\n");
exit(10);
}
memset(server, 0, sizeof(*server));
server->next = server_list;
server_list = server;
if ((fd = accept(s, (struct sockaddr *)&ss, &len)) < 0) {
free_server(server);
fprintf(stderr, "accept failed\n");
exit(10);
}
evutil_make_socket_nonblocking(fd);
server->rpc = rpc_init_server_context(fd);
if (server->rpc == NULL) {
free_server(server);
fprintf(stderr, "Failed to create server rpc context\n");
exit(10);
}
rpc_register_service(server->rpc, NFS4_CALLBACK, NFS_CB,
pt, sizeof(pt) / sizeof(pt[0]));
server->read_event = event_new(base, fd, EV_READ|EV_PERSIST,
server_io, server);
server->write_event = event_new(base, fd, EV_WRITE|EV_PERSIST,
server_io, server);
update_events(server->rpc, server->read_event, server->write_event);
}
/*
* This callback is invoked when our async connect() to the server has
* completed. At this point we know which IP address was used locally for
* the connection and can bind our nfsv4 callback server instance to it.
*/
void connect_cb(struct rpc_context *rpc, int status, void *data _U_,
void *private_data)
{
struct client *client = private_data;
struct sockaddr_storage ss;
socklen_t len = sizeof(ss);
struct sockaddr_in *in;
struct sockaddr_in6 *in6;
if (status != RPC_STATUS_SUCCESS) {
fprintf(stderr, "connection to NFSv4 server %s failed\n",
client->server);
exit(10);
}
/*
* NFSv4 CALLBACK
* Now that we have a client connection we can register a callback
* server port on the same IP address as was used to the outgoing
* client connection. That way we know that the address used by the
* server is routable, and uses the same version of ip, that the client
* supports and can route to.
*/
if (getsockname(rpc_get_fd(rpc), (struct sockaddr *)&ss, &len) < 0) {
fprintf(stderr, "getsockaddr failed\n");
exit(10);
}
switch (ss.ss_family) {
case AF_INET:
in = (struct sockaddr_in *)&ss;
in->sin_port=0;
break;
case AF_INET6:
in6 = (struct sockaddr_in6 *)&ss;
in6->sin6_port=0;
break;
default:
fprintf(stderr, "Can not handle AF_FAMILY:%d", ss.ss_family);
exit(10);
}
client->callback_fd = socket(AF_INET, SOCK_STREAM, 0);
if (client->callback_fd == -1) {
fprintf(stderr, "Failed to create callback socket\n");
exit(10);
}
evutil_make_socket_nonblocking(client->callback_fd);
if (bind(client->callback_fd, (struct sockaddr *)&ss, sizeof(ss)) < 0) {
fprintf(stderr, "Failed to bind callback socket\n");
exit(10);
}
if (listen(client->callback_fd, 16) < 0) {
fprintf(stderr, "failed to listen to callback socket\n");
exit(10);
}
client->listen_event = event_new(base,
client->callback_fd,
EV_READ|EV_PERSIST,
client_accept, private_data);
event_add(client->listen_event, NULL);
/*
* Now that we are finished setting up the callback server port
* we can proceed and negotiate the nfsv4 client id.
*/
send_setclientid(rpc, setclientid_cb, client);
}
int main(int argc, char *argv[])
{
struct nfs_context *nfs;
struct nfs_url *url;
struct client client;
int i, fd;
#ifdef WIN32
if (WSAStartup(MAKEWORD(2,2), &wsaData) != 0) {
fprintf(stderr, "Failed to start Winsock2\n");
exit(10);
}
#endif
#ifdef AROS
aros_init_socket();
#endif
if (argc < 2) {
usage();
}
base = event_base_new();
if (base == NULL) {
fprintf(stderr, "Failed create event context\n");
exit(10);
}
nfs = nfs_init_context();
if (nfs == NULL) {
fprintf(stderr, "failed to init context\n");
exit(10);
}
url = nfs_parse_url_dir(nfs, argv[1]);
if (url == NULL) {
fprintf(stderr, "failed to parse url\n");
exit(10);
}
memset(&client, 0, sizeof(client));
client.rpc = nfs_get_rpc_context(nfs);
client.is_finished = 0;
client.server = url->server;
client.path = &url->path[1]; // skip leading '/'
srandom(time(NULL));
for (i = 0; i < NFS4_VERIFIER_SIZE; i++) {
client.verifier[i] = random() & 0xff;
}
asprintf(&client.id, "Libnfs %s tcp pid:%d", argv[1], getpid());
asprintf(&client.owner, "open id:libnfs pid:%d", getpid());
client.callback_fd = -1;
if (rpc_connect_program_async(client.rpc, url->server,
NFS4_PROGRAM, NFS_V4,
connect_cb, &client) != 0) {
fprintf(stderr, "Failed to start connection\n");
exit(10);
}
/*
* Set up the events we need for the outgoing client RPC channel.
*/
fd = rpc_get_fd(client.rpc);
client.read_event = event_new(base, fd, EV_READ|EV_PERSIST,
client_io, &client);
client.write_event = event_new(base, fd, EV_WRITE|EV_PERSIST,
client_io, &client);
update_events(client.rpc, client.read_event, client.write_event);
/*
* Main event loop.
*/
event_base_dispatch(base);
/*
* Finished cleanly, lets deallocate all resrouces we were using.
*/
/*
* Close the listening socket.
*/
close(client.callback_fd);
/*
* Destroy the client context.
*/
free(client.id);
free(client.owner);
free(client.fh.nfs_fh4_val);
/*
* Destroy all server contexts
*/
while (server_list) {
struct server *server = server_list;
server_list = server->next;
free_server(server);
}
nfs_destroy_url(url);
/*
* This will implicitly close the rpc context and also destroy it.
*/
nfs_destroy_context(nfs);
event_base_free(base);
return 0;
}
libnfs-libnfs-2.0.0/examples/nfsclient-async.c 0000664 0000000 0000000 00000016445 13121032772 0021333 0 ustar 00root root 0000000 0000000 /*
Copyright (C) by Ronnie Sahlberg 2010
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 .
*/
/* Example program using the highlevel async interface.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#ifdef WIN32
#include "win32_compat.h"
#pragma comment(lib, "ws2_32.lib")
WSADATA wsaData;
#else
#include
#endif
#ifdef HAVE_POLL_H
#include
#endif
#ifdef HAVE_UNISTD_H
#include
#endif
#define SERVER "10.1.1.27"
#define EXPORT "/VIRTUAL"
#define NFSFILE "/BOOKS/Classics/Dracula.djvu"
#define NFSDIR "/BOOKS/Classics/"
#include
#include
#include
#include
#include
#include "libnfs.h"
#include "libnfs-raw.h"
#include "libnfs-raw-mount.h"
struct rpc_context *mount_context;
struct client {
char *server;
char *export;
uint32_t mount_port;
struct nfsfh *nfsfh;
int is_finished;
};
void mount_export_cb(struct rpc_context *mount_context, int status, void *data, void *private_data)
{
struct client *client = private_data;
exports export = *(exports *)data;
if (status < 0) {
printf("MOUNT/EXPORT failed with \"%s\"\n", rpc_get_error(mount_context));
exit(10);
}
printf("Got exports list from server %s\n", client->server);
while (export != NULL) {
printf("Export: %s\n", export->ex_dir);
export = export->ex_next;
}
mount_context = NULL;
client->is_finished = 1;
}
void nfs_opendir_cb(int status, struct nfs_context *nfs, void *data, void *private_data)
{
struct client *client = private_data;
struct nfsdir *nfsdir = data;
struct nfsdirent *nfsdirent;
if (status < 0) {
printf("opendir failed with \"%s\"\n", (char *)data);
exit(10);
}
printf("opendir successful\n");
while((nfsdirent = nfs_readdir(nfs, nfsdir)) != NULL) {
printf("Inode:%d Name:%s\n", (int)nfsdirent->inode, nfsdirent->name);
}
nfs_closedir(nfs, nfsdir);
mount_context = rpc_init_context();
if (mount_getexports_async(mount_context, client->server, mount_export_cb, client) != 0) {
printf("Failed to start MOUNT/EXPORT\n");
exit(10);
}
}
void nfs_close_cb(int status, struct nfs_context *nfs, void *data, void *private_data)
{
struct client *client = private_data;
if (status < 0) {
printf("close failed with \"%s\"\n", (char *)data);
exit(10);
}
printf("close successful\n");
printf("call opendir(%s)\n", NFSDIR);
if (nfs_opendir_async(nfs, NFSDIR, nfs_opendir_cb, client) != 0) {
printf("Failed to start async nfs close\n");
exit(10);
}
}
void nfs_fstat64_cb(int status, struct nfs_context *nfs, void *data, void *private_data)
{
struct client *client = private_data;
struct nfs_stat_64 *st;
if (status < 0) {
printf("fstat call failed with \"%s\"\n", (char *)data);
exit(10);
}
printf("Got reply from server for fstat(%s).\n", NFSFILE);
st = (struct nfs_stat_64 *)data;
printf("Mode %04o\n", (int)st->nfs_mode);
printf("Size %d\n", (int)st->nfs_size);
printf("Inode %04o\n", (int)st->nfs_ino);
printf("Close file\n");
if (nfs_close_async(nfs, client->nfsfh, nfs_close_cb, client) != 0) {
printf("Failed to start async nfs close\n");
exit(10);
}
}
void nfs_read_cb(int status, struct nfs_context *nfs, void *data, void *private_data)
{
struct client *client = private_data;
char *read_data;
int i;
if (status < 0) {
printf("read failed with \"%s\"\n", (char *)data);
exit(10);
}
printf("read successful with %d bytes of data\n", status);
read_data = data;
for (i=0;i<16;i++) {
printf("%02x ", read_data[i]&0xff);
}
printf("\n");
printf("Fstat file :%s\n", NFSFILE);
if (nfs_fstat64_async(nfs, client->nfsfh, nfs_fstat64_cb, client) != 0) {
printf("Failed to start async nfs fstat\n");
exit(10);
}
}
void nfs_open_cb(int status, struct nfs_context *nfs, void *data, void *private_data)
{
struct client *client = private_data;
struct nfsfh *nfsfh;
if (status < 0) {
printf("open call failed with \"%s\"\n", (char *)data);
exit(10);
}
nfsfh = data;
client->nfsfh = nfsfh;
printf("Got reply from server for open(%s). Handle:%p\n", NFSFILE, data);
printf("Read first 64 bytes\n");
if (nfs_pread_async(nfs, nfsfh, 0, 64, nfs_read_cb, client) != 0) {
printf("Failed to start async nfs open\n");
exit(10);
}
}
void nfs_stat64_cb(int status, struct nfs_context *nfs, void *data, void *private_data)
{
struct client *client = private_data;
struct nfs_stat_64 *st;
if (status < 0) {
printf("stat call failed with \"%s\"\n", (char *)data);
exit(10);
}
printf("Got reply from server for stat(%s).\n", NFSFILE);
st = (struct nfs_stat_64 *)data;
printf("Mode %04o\n", (unsigned int) st->nfs_mode);
printf("Size %d\n", (int)st->nfs_size);
printf("Inode %04o\n", (int)st->nfs_ino);
printf("Open file for reading :%s\n", NFSFILE);
if (nfs_open_async(nfs, NFSFILE, O_RDONLY, nfs_open_cb, client) != 0) {
printf("Failed to start async nfs open\n");
exit(10);
}
}
void nfs_mount_cb(int status, struct nfs_context *nfs, void *data, void *private_data)
{
struct client *client = private_data;
if (status < 0) {
printf("mount/mnt call failed with \"%s\"\n", (char *)data);
exit(10);
}
printf("Got reply from server for MOUNT/MNT procedure.\n");
printf("Stat file :%s\n", NFSFILE);
if (nfs_stat64_async(nfs, NFSFILE, nfs_stat64_cb, client) != 0) {
printf("Failed to start async nfs stat\n");
exit(10);
}
}
int main(int argc _U_, char *argv[] _U_)
{
struct nfs_context *nfs;
int ret;
struct client client;
struct pollfd pfds[2]; /* nfs:0 mount:1 */
#ifdef WIN32
if (WSAStartup(MAKEWORD(2,2), &wsaData) != 0) {
printf("Failed to start Winsock2\n");
exit(10);
}
#endif
client.server = SERVER;
client.export = EXPORT;
client.is_finished = 0;
nfs = nfs_init_context();
if (nfs == NULL) {
printf("failed to init context\n");
exit(10);
}
ret = nfs_mount_async(nfs, client.server, client.export, nfs_mount_cb, &client);
if (ret != 0) {
printf("Failed to start async nfs mount\n");
exit(10);
}
for (;;) {
int num_fds;
pfds[0].fd = nfs_get_fd(nfs);
pfds[0].events = nfs_which_events(nfs);
num_fds = 1;
if (mount_context != 0 && rpc_get_fd(mount_context) != -1) {
pfds[1].fd = rpc_get_fd(mount_context);
pfds[1].events = rpc_which_events(mount_context);
num_fds = 2;
}
if (poll(&pfds[0], 2, -1) < 0) {
printf("Poll failed");
exit(10);
}
if (mount_context != NULL) {
if (rpc_service(mount_context, pfds[1].revents) < 0) {
printf("rpc_service failed\n");
break;
}
}
if (nfs_service(nfs, pfds[0].revents) < 0) {
printf("nfs_service failed\n");
break;
}
if (client.is_finished) {
break;
}
}
nfs_destroy_context(nfs);
if (mount_context != NULL) {
rpc_destroy_context(mount_context);
mount_context = NULL;
}
printf("nfsclient finished\n");
return 0;
}
libnfs-libnfs-2.0.0/examples/nfsclient-bcast.c 0000664 0000000 0000000 00000013366 13121032772 0021311 0 ustar 00root root 0000000 0000000 /*
Copyright (C) by Ronnie Sahlberg 2011
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 .
*/
/* Example program using the lowlevel raw broadcast interface.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#ifdef WIN32
#include "win32_compat.h"
#pragma comment(lib, "ws2_32.lib")
WSADATA wsaData;
#endif
#ifdef HAVE_POLL_H
#include
#endif
#ifdef HAVE_UNISTD_H
#include
#endif
#include
#include
#include
#include
#ifdef HAVE_SYS_TIME_H
#include
#endif
#ifdef HAVE_NET_IF_H
#include
#endif
#ifdef HAVE_NETDB_H
#include
#endif
#ifdef HAVE_SYS_IOCTL_H
#include
#endif
#ifdef HAVE_SYS_SOCKET_H
#include
#endif
#include "libnfs.h"
#include "libnfs-raw.h"
#include "libnfs-private.h"
#include "libnfs-raw-mount.h"
#include "libnfs-raw-portmap.h"
struct nfs_list_data {
int status;
struct nfs_server_list *srvrs;
};
void free_nfs_srvr_list(struct nfs_server_list *srv)
{
while (srv != NULL) {
struct nfs_server_list *next = srv->next;
free(srv->addr);
free(srv);
srv = next;
}
}
void pm_cb(struct rpc_context *rpc, int status, void *data _U_, void *private_data)
{
struct nfs_list_data *srv_data = private_data;
struct sockaddr *sin;
char hostdd[16];
struct nfs_server_list *srvr;
if (status == RPC_STATUS_CANCEL) {
return;
}
if (status != 0) {
srv_data->status = -1;
return;
}
sin = rpc_get_recv_sockaddr(rpc);
if (sin == NULL) {
rpc_set_error(rpc, "failed to get sockaddr in CALLIT callback");
srv_data->status = -1;
return;
}
if (getnameinfo(sin, sizeof(struct sockaddr_in), &hostdd[0], sizeof(hostdd), NULL, 0, NI_NUMERICHOST) < 0) {
rpc_set_error(rpc, "getnameinfo failed in CALLIT callback");
srv_data->status = -1;
return;
}
srvr = malloc(sizeof(struct nfs_server_list));
if (srvr == NULL) {
rpc_set_error(rpc, "Malloc failed when allocating server structure");
srv_data->status = -1;
return;
}
srvr->addr = strdup(hostdd);
if (srvr->addr == NULL) {
rpc_set_error(rpc, "Strdup failed when allocating server structure");
free(srvr);
srv_data->status = -1;
return;
}
srvr->next = srv_data->srvrs;
srv_data->srvrs = srvr;
}
int main(int argc _U_, char *argv[] _U_)
{
struct rpc_context *rpc;
struct pollfd pfd;
struct ifconf ifc;
int size;
struct timeval tv_start, tv_current;
struct nfs_list_data data = {0, NULL};
struct nfs_server_list *srvr;
char *ptr;
#ifdef WIN32
if (WSAStartup(MAKEWORD(2,2), &wsaData) != 0) {
printf("Failed to start Winsock2\n");
exit(10);
}
#endif
rpc = rpc_init_udp_context();
if (rpc == NULL) {
printf("failed to init context\n");
exit(10);
}
if (rpc_bind_udp(rpc, "0.0.0.0", 0) < 0) {
printf("failed to bind to udp %s\n", rpc_get_error(rpc));
exit(10);
}
/* get list of all interfaces */
size = sizeof(struct ifreq);
ifc.ifc_buf = NULL;
ifc.ifc_len = size;
while(ifc.ifc_len > (size - sizeof(struct ifreq))) {
size *= 2;
free(ifc.ifc_buf);
ifc.ifc_len = size;
ifc.ifc_buf = malloc(size);
memset(ifc.ifc_buf, 0, size);
if (ioctl(rpc_get_fd(rpc), SIOCGIFCONF, (caddr_t)&ifc) < 0) {
printf("ioctl SIOCGIFCONF failed\n");
exit(10);
}
}
for (ptr =(char *)ifc.ifc_buf; ptr < ((char *)ifc.ifc_buf) + ifc.ifc_len; ) {
struct ifreq *ifr;
char bcdd[16];
ifr = (struct ifreq *)ptr;
#ifdef HAVE_SOCKADDR_LEN
if (ifr->ifr_addr.sa_len > sizeof(struct sockaddr)) {
ptr += sizeof(ifr->ifr_name) + ifr->ifr_addr.sa_len;
} else {
ptr += sizeof(ifr->ifr_name) + sizeof(struct sockaddr);
}
#else
ptr += sizeof(struct ifreq);
#endif
if (ifr->ifr_addr.sa_family != AF_INET) {
continue;
}
if (ioctl(rpc_get_fd(rpc), SIOCGIFFLAGS, ifr) < 0) {
printf("ioctl DRBADDR failed\n");
exit(10);
}
if (!(ifr->ifr_flags & IFF_UP)) {
continue;
}
if (ifr->ifr_flags & IFF_LOOPBACK) {
continue;
}
if (!(ifr->ifr_flags & IFF_BROADCAST)) {
continue;
}
if (ioctl(rpc_get_fd(rpc), SIOCGIFBRDADDR, ifr) < 0) {
continue;
}
if (getnameinfo(&ifr->ifr_broadaddr, sizeof(struct sockaddr_in), &bcdd[0], sizeof(bcdd), NULL, 0, NI_NUMERICHOST) < 0) {
continue;
}
if (rpc_set_udp_destination(rpc, bcdd, 111, 1) < 0) {
printf("failed to set udp destination %s\n", rpc_get_error(rpc));
exit(10);
}
if (rpc_pmap2_callit_async(rpc, MOUNT_PROGRAM, 2, 0, NULL, 0, pm_cb, &data) < 0) {
printf("Failed to set up callit function\n");
exit(10);
}
}
free(ifc.ifc_buf);
gettimeofday(&tv_start, NULL);
for(;;) {
int mpt;
pfd.fd = rpc_get_fd(rpc);
pfd.events = rpc_which_events(rpc);
gettimeofday(&tv_current, NULL);
mpt = 1000
- (tv_current.tv_sec *1000 + tv_current.tv_usec / 1000)
+ (tv_start.tv_sec *1000 + tv_start.tv_usec / 1000);
if (poll(&pfd, 1, mpt) < 0) {
printf("Poll failed");
exit(10);
}
if (pfd.revents == 0) {
break;
}
if (rpc_service(rpc, pfd.revents) < 0) {
printf("rpc_service failed with %s\n", rpc_get_error(rpc));
break;
}
}
for (srvr=data.srvrs; srvr; srvr = srvr->next) {
printf("NFS SERVER @ %s\n", srvr->addr);
}
free_nfs_srvr_list(data.srvrs);
rpc_destroy_context(rpc);
rpc=NULL;
return 0;
}
libnfs-libnfs-2.0.0/examples/nfsclient-listservers.c 0000664 0000000 0000000 00000002643 13121032772 0022576 0 ustar 00root root 0000000 0000000 /*
Copyright (C) by Ronnie Sahlberg 2011
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 .
*/
/* Example program showing sync interface to probe for all local servers
*/
#ifdef AROS
#include "aros_compat.h"
#endif
#ifdef WIN32
#include "win32_compat.h"
#pragma comment(lib, "ws2_32.lib")
WSADATA wsaData;
#endif
#include
#include
#include "libnfs.h"
int main(int argc _U_, char *argv[] _U_)
{
struct nfs_server_list *srvrs;
struct nfs_server_list *srv;
#ifdef WIN32
if (WSAStartup(MAKEWORD(2,2), &wsaData) != 0) {
printf("Failed to start Winsock2\n");
exit(10);
}
#endif
#ifdef AROS
aros_init_socket();
#endif
srvrs = nfs_find_local_servers();
for (srv=srvrs; srv; srv = srv->next) {
printf("NFS SERVER @ %s\n", srv->addr);
}
free_nfs_srvr_list(srvrs);
return 0;
}
libnfs-libnfs-2.0.0/examples/nfsclient-raw.c 0000664 0000000 0000000 00000032551 13121032772 0021003 0 ustar 00root root 0000000 0000000 /*
Copyright (C) by Ronnie Sahlberg 2010
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 .
*/
/* Example program using the lowlevel raw interface.
* This allow accurate control of the exact commands that are being used.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#ifdef WIN32
#include "win32_compat.h"
#pragma comment(lib, "ws2_32.lib")
WSADATA wsaData;
#endif
#define SERVER "10.1.1.27"
#define EXPORT "/shared"
#ifdef HAVE_POLL_H
#include
#endif
#ifdef HAVE_NETINET_IN_H
#include
#endif
#include
#include
#include
#include "libnfs.h"
#include "libnfs-raw.h"
#include "libnfs-raw-mount.h"
#include "libnfs-raw-nfs.h"
#include "libnfs-raw-portmap.h"
#include "libnfs-raw-rquota.h"
struct client {
char *server;
char *export;
uint32_t mount_port;
uint32_t rquota_port;
int is_finished;
struct nfs_fh3 rootfh;
};
void rquota_getquota_cb(struct rpc_context *rpc _U_, int status, void *data, void *private_data)
{
struct client *client = private_data;
// GETQUOTA1res *res = data;
if (status == RPC_STATUS_ERROR) {
printf("rquota/getquota call failed with \"%s\"\n", (char *)data);
exit(10);
}
if (status != RPC_STATUS_SUCCESS) {
printf("rquota/getquota call to server %s failed, status:%d\n", client->server, status);
exit(10);
}
printf("rquota responded ok\n");
client->is_finished = 1;
}
void rquota_connect_cb(struct rpc_context *rpc, int status, void *data _U_, void *private_data)
{
struct client *client = private_data;
if (status != RPC_STATUS_SUCCESS) {
printf("connection to RPC.RQUOTAD on server %s failed\n", client->server);
exit(10);
}
printf("Connected to RPC.RQUOTAD on %s:%d\n", client->server, client->rquota_port);
printf("Send GETQUOTA request for uid 100\n");
if (rpc_rquota1_getquota_async(rpc, rquota_getquota_cb, EXPORT, 100, client) != 0) {
printf("Failed to send getquota request\n");
exit(10);
}
}
void acl_getacl_cb(struct rpc_context *rpc _U_, int status, void *data, void *private_data)
{
struct client *client = private_data;
GETACL3res *res = data;
printf("Got NFSACL/GETACL reply\n");
if (status == RPC_STATUS_SUCCESS) {
printf("Got an ACL : ACL status:%d\n", res->status);
if (res->status == NFS3_OK) {
int i;
printf("ACL MASK 0x%08x\n", res->GETACL3res_u.resok.mask);
printf("NUM ACE %d\n", res->GETACL3res_u.resok.ace_count);
for (i=0; iGETACL3res_u.resok.ace.ace_len; i++) {
printf("Type:0x%08x\n", res->GETACL3res_u.resok.ace.ace_val[i].type);
printf("ID:%d\n", res->GETACL3res_u.resok.ace.ace_val[i].id);
printf("Perm:0x%08x\n", res->GETACL3res_u.resok.ace.ace_val[i].perm);
}
}
}
printf("Disconnect socket from nfs server\n");
if (rpc_disconnect(rpc, "normal disconnect") != 0) {
printf("Failed to disconnect socket to nfs\n");
exit(10);
}
printf("Connect to RPC.RQUOTAD on %s:%d\n", client->server, client->rquota_port);
if (rpc_connect_async(rpc, client->server, client->rquota_port, rquota_connect_cb, client) != 0) {
printf("Failed to start connection\n");
exit(10);
}
}
void acl_null_cb(struct rpc_context *rpc _U_, int status, void *data, void *private_data)
{
struct client *client = private_data;
GETACL3args args;
printf("Got NFSACL/NULL reply\n");
printf("Get ACL for root handle\n");
args.dir = client->rootfh;
args.mask = NFSACL_MASK_ACL_ENTRY|NFSACL_MASK_ACL_COUNT|NFSACL_MASK_ACL_DEFAULT_ENTRY|NFSACL_MASK_ACL_DEFAULT_COUNT;
if (rpc_nfsacl_getacl_async(rpc, acl_getacl_cb, &args, client) != 0) {
printf("Failed to send getacl request\n");
exit(10);
}
}
void nfs_fsinfo_cb(struct rpc_context *rpc _U_, int status, void *data, void *private_data)
{
struct client *client = private_data;
FSINFO3res *res = data;
if (status == RPC_STATUS_ERROR) {
printf("nfs/fsinfo call failed with \"%s\"\n", (char *)data);
exit(10);
}
if (status != RPC_STATUS_SUCCESS) {
printf("nfs/fsinfo call to server %s failed, status:%d\n", client->server, status);
exit(10);
}
printf("Got reply from server for NFS/FSINFO procedure.\n");
printf("Read Max:%d\n", (int)res->FSINFO3res_u.resok.rtmax);
printf("Write Max:%d\n", (int)res->FSINFO3res_u.resok.wtmax);
printf("Send NFSACL/NULL request\n");
if (rpc_nfsacl_null_async(rpc, acl_null_cb, client) != 0) {
printf("Failed to send acl/null request\n");
exit(10);
}
}
void nfs_connect_cb(struct rpc_context *rpc, int status, void *data _U_, void *private_data)
{
struct client *client = private_data;
struct FSINFO3args args;
if (status != RPC_STATUS_SUCCESS) {
printf("connection to RPC.MOUNTD on server %s failed\n", client->server);
exit(10);
}
printf("Connected to RPC.NFSD on %s:%d\n", client->server, client->mount_port);
printf("Send FSINFO request\n");
args.fsroot = client->rootfh;
if (rpc_nfs3_fsinfo_async(rpc, nfs_fsinfo_cb, &args, client) != 0) {
printf("Failed to send fsinfo request\n");
exit(10);
}
}
void mount_mnt_cb(struct rpc_context *rpc, int status, void *data, void *private_data)
{
struct client *client = private_data;
mountres3 *mnt = data;
if (status == RPC_STATUS_ERROR) {
printf("mount/mnt call failed with \"%s\"\n", (char *)data);
exit(10);
}
if (status != RPC_STATUS_SUCCESS) {
printf("mount/mnt call to server %s failed, status:%d\n", client->server, status);
exit(10);
}
printf("Got reply from server for MOUNT/MNT procedure.\n");
client->rootfh.data.data_len = mnt->mountres3_u.mountinfo.fhandle.fhandle3_len;
client->rootfh.data.data_val = malloc(client->rootfh.data.data_len);
memcpy(client->rootfh.data.data_val, mnt->mountres3_u.mountinfo.fhandle.fhandle3_val, client->rootfh.data.data_len);
printf("Disconnect socket from mountd server\n");
if (rpc_disconnect(rpc, "normal disconnect") != 0) {
printf("Failed to disconnect socket to mountd\n");
exit(10);
}
printf("Connect to RPC.NFSD on %s:%d\n", client->server, 2049);
if (rpc_connect_async(rpc, client->server, 2049, nfs_connect_cb, client) != 0) {
printf("Failed to start connection\n");
exit(10);
}
}
void mount_export_cb(struct rpc_context *rpc, int status, void *data, void *private_data)
{
struct client *client = private_data;
exports export = *(exports *)data;
if (status == RPC_STATUS_ERROR) {
printf("mount null call failed with \"%s\"\n", (char *)data);
exit(10);
}
if (status != RPC_STATUS_SUCCESS) {
printf("mount null call to server %s failed, status:%d\n", client->server, status);
exit(10);
}
printf("Got reply from server for MOUNT/EXPORT procedure.\n");
while (export != NULL) {
printf("Export: %s\n", export->ex_dir);
export = export->ex_next;
}
printf("Send MOUNT/MNT command for %s\n", client->export);
if (rpc_mount_mnt_async(rpc, mount_mnt_cb, client->export, client) != 0) {
printf("Failed to send mnt request\n");
exit(10);
}
}
void mount_null_cb(struct rpc_context *rpc, int status, void *data, void *private_data)
{
struct client *client = private_data;
if (status == RPC_STATUS_ERROR) {
printf("mount null call failed with \"%s\"\n", (char *)data);
exit(10);
}
if (status != RPC_STATUS_SUCCESS) {
printf("mount null call to server %s failed, status:%d\n", client->server, status);
exit(10);
}
printf("Got reply from server for MOUNT/NULL procedure.\n");
printf("Send MOUNT/EXPORT command\n");
if (rpc_mount_export_async(rpc, mount_export_cb, client) != 0) {
printf("Failed to send export request\n");
exit(10);
}
}
void mount_connect_cb(struct rpc_context *rpc, int status, void *data _U_, void *private_data)
{
struct client *client = private_data;
if (status != RPC_STATUS_SUCCESS) {
printf("connection to RPC.MOUNTD on server %s failed\n", client->server);
exit(10);
}
printf("Connected to RPC.MOUNTD on %s:%d\n", client->server, client->mount_port);
printf("Send NULL request to check if RPC.MOUNTD is actually running\n");
if (rpc_mount_null_async(rpc, mount_null_cb, client) != 0) {
printf("Failed to send null request\n");
exit(10);
}
}
void pmap_getport2_cb(struct rpc_context *rpc, int status, void *data, void *private_data)
{
struct client *client = private_data;
if (status == RPC_STATUS_ERROR) {
printf("portmapper getport call failed with \"%s\"\n", (char *)data);
exit(10);
}
if (status != RPC_STATUS_SUCCESS) {
printf("portmapper getport call to server %s failed, status:%d\n", client->server, status);
exit(10);
}
client->mount_port = *(uint32_t *)data;
printf("GETPORT returned RPC.MOUNTD is on port:%d\n", client->mount_port);
if (client->mount_port == 0) {
printf("RPC.MOUNTD is not available on server : %s:%d\n", client->server, client->mount_port);
exit(10);
}
printf("Disconnect socket from portmap server\n");
if (rpc_disconnect(rpc, "normal disconnect") != 0) {
printf("Failed to disconnect socket to portmapper\n");
exit(10);
}
printf("Connect to RPC.MOUNTD on %s:%d\n", client->server, client->mount_port);
if (rpc_connect_async(rpc, client->server, client->mount_port, mount_connect_cb, client) != 0) {
printf("Failed to start connection\n");
exit(10);
}
}
void pmap_getport1_cb(struct rpc_context *rpc, int status, void *data, void *private_data)
{
struct client *client = private_data;
if (status == RPC_STATUS_ERROR) {
printf("portmapper getport call failed with \"%s\"\n", (char *)data);
exit(10);
}
if (status != RPC_STATUS_SUCCESS) {
printf("portmapper getport call to server %s failed, status:%d\n", client->server, status);
exit(10);
}
client->rquota_port = *(uint32_t *)data;
printf("GETPORT returned RPC.RQUOTAD on port:%d\n", client->rquota_port);
if (client->rquota_port == 0) {
printf("RPC.RQUOTAD is not available on server : %s:%d\n", client->server, client->rquota_port);
// exit(10);
}
printf("Send getport request asking for MOUNT port\n");
if (rpc_pmap2_getport_async(rpc, MOUNT_PROGRAM, MOUNT_V3, IPPROTO_TCP, pmap_getport2_cb, client) != 0) {
printf("Failed to send getport request\n");
exit(10);
}
}
void pmap_dump_cb(struct rpc_context *rpc, int status, void *data, void *private_data)
{
struct client *client = private_data;
struct pmap2_dump_result *dr = data;
struct pmap2_mapping_list *list = dr->list;
if (status == RPC_STATUS_ERROR) {
printf("portmapper null call failed with \"%s\"\n", (char *)data);
exit(10);
}
if (status != RPC_STATUS_SUCCESS) {
printf("portmapper null call to server %s failed, status:%d\n", client->server, status);
exit(10);
}
printf("Got reply from server for PORTMAP/DUMP procedure.\n");
while (list) {
printf("Prog:%d Vers:%d Protocol:%d Port:%d\n",
list->map.prog,
list->map.vers,
list->map.prot,
list->map.port);
list = list->next;
}
printf("Send getport request asking for MOUNT port\n");
if (rpc_pmap2_getport_async(rpc, RQUOTA_PROGRAM, RQUOTA_V1, IPPROTO_TCP, pmap_getport1_cb, client) != 0) {
printf("Failed to send getport request\n");
exit(10);
}
}
void pmap_null_cb(struct rpc_context *rpc, int status, void *data, void *private_data)
{
struct client *client = private_data;
if (status == RPC_STATUS_ERROR) {
printf("portmapper null call failed with \"%s\"\n", (char *)data);
exit(10);
}
if (status != RPC_STATUS_SUCCESS) {
printf("portmapper null call to server %s failed, status:%d\n", client->server, status);
exit(10);
}
printf("Got reply from server for PORTMAP/NULL procedure.\n");
printf("Send PMAP/DUMP command\n");
if (rpc_pmap2_dump_async(rpc, pmap_dump_cb, client) != 0) {
printf("Failed to send getport request\n");
exit(10);
}
}
void pmap_connect_cb(struct rpc_context *rpc, int status, void *data _U_, void *private_data)
{
struct client *client = private_data;
printf("pmap_connect_cb status:%d.\n", status);
if (status != RPC_STATUS_SUCCESS) {
printf("connection to portmapper on server %s failed\n", client->server);
exit(10);
}
printf("Send NULL request to check if portmapper is actually running\n");
if (rpc_pmap2_null_async(rpc, pmap_null_cb, client) != 0) {
printf("Failed to send null request\n");
exit(10);
}
}
int main(int argc _U_, char *argv[] _U_)
{
struct rpc_context *rpc;
struct pollfd pfd;
struct client client;
#ifdef WIN32
if (WSAStartup(MAKEWORD(2,2), &wsaData) != 0) {
printf("Failed to start Winsock2\n");
exit(10);
}
#endif
rpc = rpc_init_context();
if (rpc == NULL) {
printf("failed to init context\n");
exit(10);
}
client.server = SERVER;
client.export = EXPORT;
client.is_finished = 0;
if (rpc_connect_async(rpc, client.server, 111, pmap_connect_cb, &client) != 0) {
printf("Failed to start connection\n");
exit(10);
}
for (;;) {
pfd.fd = rpc_get_fd(rpc);
pfd.events = rpc_which_events(rpc);
if (poll(&pfd, 1, -1) < 0) {
printf("Poll failed");
exit(10);
}
if (rpc_service(rpc, pfd.revents) < 0) {
printf("rpc_service failed\n");
break;
}
if (client.is_finished) {
break;
}
}
rpc_destroy_context(rpc);
rpc=NULL;
printf("nfsclient finished\n");
return 0;
}
libnfs-libnfs-2.0.0/examples/nfsclient-sync.c 0000664 0000000 0000000 00000011404 13121032772 0021160 0 ustar 00root root 0000000 0000000 /*
Copyright (C) by Ronnie Sahlberg 2010
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 _FILE_OFFSET_BITS 64
#define _GNU_SOURCE
/* Example program using the highlevel sync interface
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#ifdef AROS
#include "aros_compat.h"
#endif
#ifdef WIN32
#include "win32_compat.h"
#pragma comment(lib, "ws2_32.lib")
WSADATA wsaData;
#define PRId64 "ll"
#else
#include
#include
#include
#ifndef AROS
#include
#endif
#endif
#ifdef HAVE_UNISTD_H
#include
#endif
#include
#include
#include
#include
#include
#include
#include "libnfs.h"
#include "libnfs-raw.h"
#include "libnfs-raw-mount.h"
struct client {
char *server;
char *export;
uint32_t mount_port;
int is_finished;
};
char buf[3*1024*1024+337];
void print_usage(void)
{
fprintf(stderr, "Usage: nfsclient-sync [-?|--help] [--usage] \n");
}
int main(int argc, char *argv[])
{
struct nfs_context *nfs = NULL;
int i, ret, res;
uint64_t offset;
struct client client;
struct nfs_stat_64 st;
struct nfsfh *nfsfh;
struct nfsdir *nfsdir;
struct nfsdirent *nfsdirent;
struct statvfs svfs;
exports export, tmp;
const char *url = NULL;
char *server = NULL, *path = NULL, *strp;
#ifdef WIN32
if (WSAStartup(MAKEWORD(2,2), &wsaData) != 0) {
printf("Failed to start Winsock2\n");
exit(10);
}
#endif
#ifdef AROS
aros_init_socket();
#endif
url = argv[1];
if (url == NULL) {
fprintf(stderr, "No URL specified.\n");
print_usage();
exit(0);
}
if (strncmp(url, "nfs://", 6)) {
fprintf(stderr, "Invalid URL specified.\n");
print_usage();
exit(0);
}
server = strdup(url + 6);
if (server == NULL) {
fprintf(stderr, "Failed to strdup server string\n");
exit(10);
}
if (server[0] == '/' || server[0] == '\0') {
fprintf(stderr, "Invalid server string.\n");
free(server);
exit(10);
}
strp = strchr(server, '/');
if (strp == NULL) {
fprintf(stderr, "Invalid URL specified.\n");
print_usage();
free(server);
exit(0);
}
path = strdup(strp);
if (path == NULL) {
fprintf(stderr, "Failed to strdup server string\n");
free(server);
exit(10);
}
if (path[0] != '/') {
fprintf(stderr, "Invalid path.\n");
free(server);
free(path);
exit(10);
}
*strp = 0;
client.server = server;
client.export = path;
client.is_finished = 0;
nfs = nfs_init_context();
if (nfs == NULL) {
printf("failed to init context\n");
goto finished;
}
ret = nfs_mount(nfs, client.server, client.export);
if (ret != 0) {
printf("Failed to mount nfs share : %s\n", nfs_get_error(nfs));
goto finished;
}
ret = nfs_opendir(nfs, "/", &nfsdir);
if (ret != 0) {
printf("Failed to opendir(\"/\") %s\n", nfs_get_error(nfs));
exit(10);
}
while((nfsdirent = nfs_readdir(nfs, nfsdir)) != NULL) {
char path[1024];
if (!strcmp(nfsdirent->name, ".") || !strcmp(nfsdirent->name, "..")) {
continue;
}
sprintf(path, "%s/%s", "/", nfsdirent->name);
ret = nfs_stat64(nfs, path, &st);
if (ret != 0) {
fprintf(stderr, "Failed to stat(%s) %s\n", path, nfs_get_error(nfs));
continue;
}
switch (st.nfs_mode & S_IFMT) {
#ifndef WIN32
case S_IFLNK:
#endif
case S_IFREG:
printf("-");
break;
case S_IFDIR:
printf("d");
break;
case S_IFCHR:
printf("c");
break;
case S_IFBLK:
printf("b");
break;
}
printf("%c%c%c",
"-r"[!!(st.nfs_mode & S_IRUSR)],
"-w"[!!(st.nfs_mode & S_IWUSR)],
"-x"[!!(st.nfs_mode & S_IXUSR)]
);
printf("%c%c%c",
"-r"[!!(st.nfs_mode & S_IRGRP)],
"-w"[!!(st.nfs_mode & S_IWGRP)],
"-x"[!!(st.nfs_mode & S_IXGRP)]
);
printf("%c%c%c",
"-r"[!!(st.nfs_mode & S_IROTH)],
"-w"[!!(st.nfs_mode & S_IWOTH)],
"-x"[!!(st.nfs_mode & S_IXOTH)]
);
printf(" %2d", (int)st.nfs_nlink);
printf(" %5d", (int)st.nfs_uid);
printf(" %5d", (int)st.nfs_gid);
printf(" %12" PRId64, st.nfs_size);
printf(" %s\n", nfsdirent->name);
}
nfs_closedir(nfs, nfsdir);
finished:
free(server);
free(path);
if (nfs != NULL) {
nfs_destroy_context(nfs);
}
return 0;
}
libnfs-libnfs-2.0.0/examples/portmap-client.c 0000664 0000000 0000000 00000033657 13121032772 0021175 0 ustar 00root root 0000000 0000000 /*
Copyright (C) by Ronnie Sahlberg 2014
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 .
*/
/* Example program using the lowlevel raw interface.
* This allow accurate control of the exact commands that are being used.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#ifdef WIN32
#include "win32_compat.h"
#pragma comment(lib, "ws2_32.lib")
WSADATA wsaData;
#endif
#ifdef HAVE_POLL_H
#include
#endif
#ifdef HAVE_NETINET_IN_H
#include
#endif
#include
#include
#include
#include
#include
#include
#include "libnfs.h"
#include "libnfs-raw.h"
#include "libnfs-raw-mount.h"
#include "libnfs-raw-nfs.h"
#include "libnfs-raw-portmap.h"
#include "libnfs-raw-rquota.h"
struct client {
int is_finished;
};
void pmap2_dump_cb(struct rpc_context *rpc, int status, void *data, void *private_data)
{
struct client *client = private_data;
struct pmap2_dump_result *dr = data;
struct pmap2_mapping_list *list = dr->list;
if (status == RPC_STATUS_ERROR) {
printf("PORTMAP2/DUMP call failed with \"%s\"\n", (char *)data);
exit(10);
}
if (status != RPC_STATUS_SUCCESS) {
printf("PORTMAP2/DUMP call failed, status:%d\n", status);
exit(10);
}
printf("PORTMAP2/DUMP:\n");
while (list) {
printf(" Prog:%d Vers:%d Protocol:%d Port:%d\n",
list->map.prog,
list->map.vers,
list->map.prot,
list->map.port);
list = list->next;
}
client->is_finished = 1;
}
void pmap3_dump_cb(struct rpc_context *rpc, int status, void *data, void *private_data)
{
struct client *client = private_data;
struct pmap3_dump_result *dr = data;
struct pmap3_mapping_list *list = dr->list;
if (status == RPC_STATUS_ERROR) {
printf("PORTMAP3/DUMP call failed with \"%s\"\n", (char *)data);
exit(10);
}
if (status != RPC_STATUS_SUCCESS) {
printf("PORTMAP3/DUMP call failed, status:%d\n", status);
exit(10);
}
printf("PORTMAP3/DUMP:\n");
while (list) {
printf(" Prog:%d Vers:%d Netid:%s Addr:%s Owner:%s\n",
list->map.prog,
list->map.vers,
list->map.netid,
list->map.addr,
list->map.owner);
list = list->next;
}
client->is_finished = 1;
}
void pmap3_getaddr_cb(struct rpc_context *rpc, int status, void *data, void *private_data)
{
struct client *client = private_data;
struct pmap3_string_result *gar = data;
if (status == RPC_STATUS_ERROR) {
printf("PORTMAP3/GETADDR call failed with \"%s\"\n", (char *)data);
exit(10);
}
if (status != RPC_STATUS_SUCCESS) {
printf("PORTMAP3/GETADDR call failed, status:%d\n", status);
exit(10);
}
printf("PORTMAP3/GETADDR:\n");
printf(" Addr:%s\n", gar->addr);
client->is_finished = 1;
}
void pmap2_set_cb(struct rpc_context *rpc, int status, void *data, void *private_data)
{
struct client *client = private_data;
uint32_t res = *(uint32_t *)data;
if (status == RPC_STATUS_ERROR) {
printf("PORTMAP2/SET call failed with \"%s\"\n", (char *)data);
exit(10);
}
if (status != RPC_STATUS_SUCCESS) {
printf("PORTMAP2/SET call failed, status:%d\n", status);
exit(10);
}
printf("PORTMAP2/SET:\n");
printf(" Res:%d\n", res);
client->is_finished = 1;
}
void pmap2_unset_cb(struct rpc_context *rpc, int status, void *data, void *private_data)
{
struct client *client = private_data;
uint32_t res = *(uint32_t *)data;
if (status == RPC_STATUS_ERROR) {
printf("PORTMAP2/UNSET call failed with \"%s\"\n", (char *)data);
exit(10);
}
if (status != RPC_STATUS_SUCCESS) {
printf("PORTMAP2/UNSET call failed, status:%d\n", status);
exit(10);
}
printf("PORTMAP2/UNSET:\n");
printf(" Res:%d\n", res);
client->is_finished = 1;
}
void pmap3_set_cb(struct rpc_context *rpc, int status, void *data, void *private_data)
{
struct client *client = private_data;
uint32_t res = *(uint32_t *)data;
if (status == RPC_STATUS_ERROR) {
printf("PORTMAP3/SET call failed with \"%s\"\n", (char *)data);
exit(10);
}
if (status != RPC_STATUS_SUCCESS) {
printf("PORTMAP3/SET call failed, status:%d\n", status);
exit(10);
}
printf("PORTMAP3/SET:\n");
printf(" Res:%d\n", res);
client->is_finished = 1;
}
void pmap3_unset_cb(struct rpc_context *rpc, int status, void *data, void *private_data)
{
struct client *client = private_data;
uint32_t res = *(uint32_t *)data;
if (status == RPC_STATUS_ERROR) {
printf("PORTMAP3/UNSET call failed with \"%s\"\n", (char *)data);
exit(10);
}
if (status != RPC_STATUS_SUCCESS) {
printf("PORTMAP3/UNSET call failed, status:%d\n", status);
exit(10);
}
printf("PORTMAP3/UNSET:\n");
printf(" Res:%d\n", res);
client->is_finished = 1;
}
void pmap3_gettime_cb(struct rpc_context *rpc, int status, void *data, void *private_data)
{
struct client *client = private_data;
time_t t = *(uint32_t *)data;
if (status == RPC_STATUS_ERROR) {
printf("PORTMAP3/GETTIME call failed with \"%s\"\n", (char *)data);
exit(10);
}
if (status != RPC_STATUS_SUCCESS) {
printf("PORTMAP3/GETTIME call failed, status:%d\n", status);
exit(10);
}
printf("PORTMAP3/GETTIME:\n");
printf(" Time:%d %s\n", (int)t, ctime(&t));
client->is_finished = 1;
}
void pmap3_uaddr2taddr_cb(struct rpc_context *rpc, int status, void *data, void *private_data)
{
struct client *client = private_data;
struct pmap3_netbuf *nb = data;
struct sockaddr_storage *ss;
char host[256], port[6];
int i;
if (status == RPC_STATUS_ERROR) {
printf("PORTMAP3/UADDR2TADDR call failed with \"%s\"\n", (char *)data);
exit(10);
}
if (status != RPC_STATUS_SUCCESS) {
printf("PORTMAP3/UADDR2TADDR call failed, status:%d\n", status);
exit(10);
}
printf("PORTMAP3/UADDR2TADDR:\n");
printf(" MaxLen:%d\n", nb->maxlen);
printf(" ");
for (i = 0; i < nb->maxlen; i++) {
printf("%02x ", nb->buf.buf_val[i]);
if (i %16 == 15) {
printf("\n ");
}
}
printf("\n");
printf(" ---\n");
ss = (struct sockaddr_storage *)&nb->buf.buf_val[0];
getnameinfo((struct sockaddr *)ss, sizeof(struct sockaddr_storage),
&host[0], sizeof(host), &port[0], sizeof(port),
NI_NUMERICHOST|NI_NUMERICSERV);
switch (ss->ss_family) {
case AF_INET:
printf(" IPv4: %s:%s\n", &host[0], &port[0]);
break;
case AF_INET6:
printf(" IPv6: %s:%s\n", &host[0], &port[0]);
break;
}
client->is_finished = 1;
}
void pmap2_null_cb(struct rpc_context *rpc, int status, void *data, void *private_data)
{
struct client *client = private_data;
if (status == RPC_STATUS_ERROR) {
printf("PORTMAP2/NULL call failed with \"%s\"\n", (char *)data);
exit(10);
}
if (status != RPC_STATUS_SUCCESS) {
printf("PORTMAP2/NULL call failed, status:%d\n", status);
exit(10);
}
printf("PORTMAP2/NULL responded and server is alive\n");
client->is_finished = 1;
}
void pmap3_null_cb(struct rpc_context *rpc, int status, void *data, void *private_data)
{
struct client *client = private_data;
if (status == RPC_STATUS_ERROR) {
printf("PORTMAP3/NULL call failed with \"%s\"\n", (char *)data);
exit(10);
}
if (status != RPC_STATUS_SUCCESS) {
printf("PORTMAP3/NULL call failed, status:%d\n", status);
exit(10);
}
printf("PORTMAP3/NULL responded and server is alive\n");
client->is_finished = 1;
}
void pmap_null_cb(struct rpc_context *rpc, int status, void *data, void *private_data)
{
struct client *client = private_data;
if (status == RPC_STATUS_ERROR) {
printf("PORTMAP/NULL call failed with \"%s\"\n", (char *)data);
exit(10);
}
if (status != RPC_STATUS_SUCCESS) {
printf("PORTMAP/NULL call failed, status:%d\n", status);
exit(10);
}
client->is_finished = 1;
}
void pmap_connect_cb(struct rpc_context *rpc, int status, void *data _U_, void *private_data)
{
struct client *client = private_data;
if (status != RPC_STATUS_SUCCESS) {
printf("connection to portmapper failed\n");
exit(10);
}
if (rpc_pmap2_null_async(rpc, pmap_null_cb, client) != 0) {
printf("Failed to send null request\n");
exit(10);
}
}
static void wait_until_finished(struct rpc_context *rpc, struct client *client)
{
struct pollfd pfd;
client->is_finished = 0;
for (;;) {
pfd.fd = rpc_get_fd(rpc);
pfd.events = rpc_which_events(rpc);
if (poll(&pfd, 1, -1) < 0) {
printf("Poll failed");
exit(10);
}
if (rpc_service(rpc, pfd.revents) < 0) {
printf("rpc_service failed\n");
break;
}
if (client->is_finished) {
break;
}
}
}
int main(int argc _U_, char *argv[] _U_)
{
struct rpc_context *rpc;
struct client client;
char *server = NULL;
int i;
int null2 = 0;
int dump2 = 0;
int null3 = 0;
int set2 = 0;
int unset2 = 0;
int set3 = 0;
int unset3 = 0;
int getaddr3 = 0;
int dump3 = 0;
int gettime3 = 0;
int u2t3 = 0;
int command_found = 0;
int set2prog, set2vers, set2prot, set2port;
int unset2prog, unset2vers, unset2prot, unset2port;
int set3prog, set3vers;
char *set3netid, *set3addr, *set3owner;
int unset3prog, unset3vers;
char *unset3netid, *unset3addr, *unset3owner;
int getaddr3prog, getaddr3vers;
char *getaddr3netid, *getaddr3addr, *getaddr3owner;
char *u2t3string;
#ifdef WIN32
if (WSAStartup(MAKEWORD(2,2), &wsaData) != 0) {
printf("Failed to start Winsock2\n");
exit(10);
}
#endif
rpc = rpc_init_context();
if (rpc == NULL) {
printf("failed to init context\n");
exit(10);
}
for (i = 1; i < argc; i++) {
if (!strcmp(argv[i], "dump2")) {
dump2 = 1;
command_found++;
} else if (!strcmp(argv[i], "null2")) {
null2 = 1;
command_found++;
} else if (!strcmp(argv[i], "set2")) {
set2 = 1;
set2prog = atoi(argv[++i]);
set2vers = atoi(argv[++i]);
set2prot = atoi(argv[++i]);
set2port = atoi(argv[++i]);
command_found++;
} else if (!strcmp(argv[i], "unset2")) {
unset2 = 1;
unset2prog = atoi(argv[++i]);
unset2vers = atoi(argv[++i]);
unset2prot = atoi(argv[++i]);
unset2port = atoi(argv[++i]);
command_found++;
} else if (!strcmp(argv[i], "dump3")) {
dump3 = 1;
command_found++;
} else if (!strcmp(argv[i], "gettime3")) {
gettime3 = 1;
command_found++;
} else if (!strcmp(argv[i], "u2t3")) {
u2t3 = 1;
u2t3string = argv[++i];
command_found++;
} else if (!strcmp(argv[i], "getaddr3")) {
getaddr3 = 1;
getaddr3prog = atoi(argv[++i]);
getaddr3vers = atoi(argv[++i]);
getaddr3netid = argv[++i];
getaddr3addr = argv[++i];
getaddr3owner = argv[++i];
command_found++;
} else if (!strcmp(argv[i], "set3")) {
set3 = 1;
set3prog = atoi(argv[++i]);
set3vers = atoi(argv[++i]);
set3netid = argv[++i];
set3addr = argv[++i];
set3owner = argv[++i];
command_found++;
} else if (!strcmp(argv[i], "null3")) {
null3 = 1;
command_found++;
} else {
server = argv[i];
}
}
if (command_found == 0 || server == NULL) {
fprintf(stderr, "Usage: portmap-client \n");
exit(10);
}
if (rpc_connect_async(rpc, server, 111, pmap_connect_cb, &client) != 0) {
printf("Failed to start connection\n");
exit(10);
}
wait_until_finished(rpc, &client);
if (null2) {
if (rpc_pmap2_null_async(rpc, pmap2_null_cb, &client) != 0) {
printf("Failed to send NULL2 request\n");
exit(10);
}
wait_until_finished(rpc, &client);
}
if (dump2) {
if (rpc_pmap2_dump_async(rpc, pmap2_dump_cb, &client) != 0) {
printf("Failed to send DUMP2 request\n");
exit(10);
}
wait_until_finished(rpc, &client);
}
if (null3) {
if (rpc_pmap3_null_async(rpc, pmap3_null_cb, &client) != 0) {
printf("Failed to send NULL3 request\n");
exit(10);
}
wait_until_finished(rpc, &client);
}
if (dump3) {
if (rpc_pmap3_dump_async(rpc, pmap3_dump_cb, &client) != 0) {
printf("Failed to send DUMP3 request\n");
exit(10);
}
wait_until_finished(rpc, &client);
}
if (gettime3) {
if (rpc_pmap3_gettime_async(rpc, pmap3_gettime_cb, &client) != 0) {
printf("Failed to send GETTIME3 request\n");
exit(10);
}
wait_until_finished(rpc, &client);
}
if (u2t3) {
if (rpc_pmap3_uaddr2taddr_async(rpc, u2t3string, pmap3_uaddr2taddr_cb, &client) != 0) {
printf("Failed to send UADDR2TADDR3 request\n");
exit(10);
}
wait_until_finished(rpc, &client);
}
if (getaddr3) {
struct pmap3_mapping map;
map.prog = getaddr3prog;
map.vers = getaddr3vers;
map.netid = getaddr3netid;
map.addr = getaddr3addr;
map.owner = getaddr3owner;
if (rpc_pmap3_getaddr_async(rpc, &map, pmap3_getaddr_cb, &client) != 0) {
printf("Failed to send GETADDR3 request\n");
exit(10);
}
wait_until_finished(rpc, &client);
}
if (set2) {
if (rpc_pmap2_set_async(rpc, set2prog, set2vers, set2prot, set2port, pmap2_set_cb, &client) != 0) {
printf("Failed to send SET2 request\n");
exit(10);
}
wait_until_finished(rpc, &client);
}
if (unset2) {
if (rpc_pmap2_unset_async(rpc, unset2prog, unset2vers, unset2prot, unset2port, pmap2_unset_cb, &client) != 0) {
printf("Failed to send UNSET2 request\n");
exit(10);
}
wait_until_finished(rpc, &client);
}
if (set3) {
struct pmap3_mapping map;
map.prog = set3prog;
map.vers = set3vers;
map.netid = set3netid;
map.addr = set3addr;
map.owner = set3owner;
if (rpc_pmap3_set_async(rpc, &map, pmap3_set_cb, &client) != 0) {
printf("Failed to send SET3 request\n");
exit(10);
}
wait_until_finished(rpc, &client);
}
if (unset3) {
struct pmap3_mapping map;
map.prog = unset3prog;
map.vers = unset3vers;
map.netid = unset3netid;
map.addr = unset3addr;
map.owner = unset3owner;
if (rpc_pmap3_unset_async(rpc, &map, pmap3_unset_cb, &client) != 0) {
printf("Failed to send UNSET3 request\n");
exit(10);
}
wait_until_finished(rpc, &client);
}
rpc_destroy_context(rpc);
rpc=NULL;
return 0;
}
libnfs-libnfs-2.0.0/examples/portmap-server.c 0000664 0000000 0000000 00000050723 13121032772 0021216 0 ustar 00root root 0000000 0000000 /* -*- mode:c; tab-width:8; c-basic-offset:8; indent-tabs-mode:nil; -*- */
/*
Copyright (C) by Ronnie Sahlberg 2015
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 .
*/
/* This is a very incomplete portmapper that only implements
* a subset of version 2 and threee of the protocol.
* A proper portmapper needs to implement these two versions fully
* as well as version 4.
*
* See this as an example of how to build a simple RPC service
* that supports both UDP and TCP using libnfs.
*/
#define _FILE_OFFSET_BITS 64
#define _GNU_SOURCE
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#ifdef AROS
#include "aros_compat.h"
#endif
#ifdef WIN32
#include "win32_compat.h"
#pragma comment(lib, "ws2_32.lib")
WSADATA wsaData;
#else
#include
#include
#endif
#ifdef HAVE_POLL_H
#include
#endif
#ifdef HAVE_UNISTD_H
#include
#endif
#include
#include
#include
#include
#include
#include
#include
#include
#include "libnfs.h"
#include "libnfs-raw.h"
#include "libnfs-raw-portmap.h"
#include
struct event_base *base;
struct server {
struct rpc_context *rpc;
struct event *read_event;
struct event *write_event;
};
/* Socket where we listen for incomming rpc connections */
struct event *listen_event;
int listen_socket = -1;
/* Socket used for UDP server */
struct server udp_server;
int udp_socket = -1;
struct mapping {
struct mapping *next;
u_int prog;
u_int vers;
int port;
char *netid;
char *addr;
char *owner;
};
struct mapping *map;
void free_map_item(struct mapping *item)
{
free(item->netid);
free(item->addr);
free(item->owner);
free(item);
}
static void free_server(struct server *server)
{
if (server->rpc) {
rpc_disconnect(server->rpc, NULL);
rpc_destroy_context(server->rpc);
}
if (server->read_event) {
event_free(server->read_event);
}
if (server->write_event) {
event_free(server->write_event);
}
free(server);
}
/*
* Based on the state of libnfs and its context, update libevent
* accordingly regarding which events we are interested in.
*/
static void update_events(struct rpc_context *rpc, struct event *read_event,
struct event *write_event)
{
int events = rpc_which_events(rpc);
if (read_event) {
if (events & POLLIN) {
event_add(read_event, NULL);
} else {
event_del(read_event);
}
}
if (write_event) {
if (events & POLLOUT) {
event_add(write_event, NULL);
} else {
event_del(write_event);
}
}
}
/*
* Add a registration for program,version,netid.
*/
int pmap_register(int prog, int vers, char *netid, char *addr,
char *owner)
{
struct mapping *item;
char *str;
int count = 0;
item = malloc(sizeof(struct mapping));
item->prog = prog;
item->vers = vers;
item->netid = netid;
item->addr = addr;
item->owner = owner;
/* The port are the last two dotted decimal fields in the address */
for (str = item->addr + strlen(item->addr) - 1; str >= item->addr; str--) {
if (*str != '.') {
if (*str < '0' || *str > '9') {
break;
}
continue;
}
count++;
if (count == 2) {
int high, low;
sscanf(str, ".%d.%d", &high, &low);
item->port = high * 256 + low;
break;
}
}
item->next = map;
map = item;
}
/*
* Find and return a registration matching program,version,netid.
*/
struct mapping *map_lookup(int prog, int vers, char *netid)
{
struct mapping *tmp;
for (tmp = map; tmp; tmp = tmp->next) {
if (tmp->prog != prog) {
continue;
}
if (tmp->vers != vers) {
continue;
}
if (strcmp(tmp->netid, netid)) {
continue;
}
return tmp;
}
return NULL;
}
/*
* Remove a registration from our map or registrations.
*/
void map_remove(int prog, int vers, char *netid)
{
struct mapping *prev = NULL;
struct mapping *tmp;
for (tmp = map; tmp; prev = tmp, tmp = tmp->next) {
if (tmp->prog != prog) {
continue;
}
if (tmp->vers != vers) {
continue;
}
if (strcmp(tmp->netid, netid)) {
continue;
}
break;
}
if (tmp == NULL) {
return;
}
if (prev) {
prev->next = tmp->next;
} else {
map = tmp->next;
}
free_map_item(tmp);
return;
}
/*
* The NULL procedure. All protocols/versions must provide a NULL procedure
* as index 0.
* It is used by clients, and rpcinfo, to "ping" a service and verify that
* the service is available and that it does support the indicated version.
*/
static int pmap2_null_proc(struct rpc_context *rpc, struct rpc_msg *call)
{
rpc_send_reply(rpc, call, NULL, (zdrproc_t)zdr_void, 0);
return 0;
}
/*
* v2 GETPORT.
* This is the lookup function for portmapper version 2.
* A client provides program, version and protocol (tcp or udp)
* and portmapper returns which port that service is available on,
* (or 0 if no such program is registered.)
*/
static int pmap2_getport_proc(struct rpc_context *rpc, struct rpc_msg *call)
{
PMAP2GETPORTargs *args = call->body.cbody.args;
struct mapping *tmp;
char *netid;
uint32_t port = 0;
if (args->prot == IPPROTO_TCP) {
netid = "tcp";
} else {
netid = "udp";
}
tmp = map_lookup(args->prog, args->vers, netid);
if (tmp) {
port = tmp->port;
}
rpc_send_reply(rpc, call, &port, (zdrproc_t)zdr_uint32_t, sizeof(uint32_t));
return 0;
}
/*
* v2 DUMP.
* This RPC returns a list of all endpoints that are registered with
* portmapper.
*/
static int pmap2_dump_proc(struct rpc_context *rpc, struct rpc_msg *call)
{
PMAP2DUMPres reply;
struct mapping *tmp;
reply.list = NULL;
for (tmp = map; tmp; tmp = tmp->next) {
struct pmap2_mapping_list *tmp_list;
int proto;
/* pmap2 only support ipv4 */
if (!strcmp(tmp->netid, "tcp")) {
proto = IPPROTO_TCP;
} else if (!strcmp(tmp->netid, "udp")) {
proto = IPPROTO_UDP;
} else {
continue;
}
tmp_list = malloc(sizeof(struct pmap2_mapping_list));
tmp_list->map.prog = tmp->prog;
tmp_list->map.vers = tmp->vers;
tmp_list->map.prot = proto;
tmp_list->map.port = tmp->port;
tmp_list->next = reply.list;
reply.list = tmp_list;
}
rpc_send_reply(rpc, call, &reply,
(zdrproc_t)zdr_PMAP2DUMPres, sizeof(PMAP2DUMPres));
while (reply.list) {
struct pmap2_mapping_list *tmp_list = reply.list->next;
free(reply.list);
reply.list = tmp_list;
}
return 0;
}
/*
* v2 SET
* This procedure is used to register and endpoint with portmapper.
*/
static int pmap2_set_proc(struct rpc_context *rpc, struct rpc_msg *call)
{
PMAP2GETPORTargs *args = call->body.cbody.args;
char *prot;
char *addr;
uint32_t response = 1;
if (args->prot == IPPROTO_TCP) {
prot = "tcp";
} else {
prot = "udp";
}
/* Don't update if we already have a mapping */
if (map_lookup(args->prog, args->vers, prot)) {
response = 0;
rpc_send_reply(rpc, call, &response, (zdrproc_t)zdr_uint32_t, sizeof(uint32_t));
return 0;
}
asprintf(&addr, "0.0.0.0.%d.%d", args->port >> 8, args->port & 0xff);
pmap_register(args->prog, args->vers, strdup(prot), addr,
strdup(""));
rpc_send_reply(rpc, call, &response, (zdrproc_t)zdr_uint32_t, sizeof(uint32_t));
return 0;
}
/*
* v2 UNSET
* This procedure is used to remove a registration from portmappers
* list of endpoints.
*/
static int pmap2_unset_proc(struct rpc_context *rpc, struct rpc_msg *call)
{
PMAP2GETPORTargs *args = call->body.cbody.args;
char *prot;
char *addr;
uint32_t response = 1;
if (args->prot == IPPROTO_TCP) {
prot = "tcp";
} else {
prot = "udp";
}
map_remove(args->prog, args->vers, prot);
rpc_send_reply(rpc, call, &response, (zdrproc_t)zdr_uint32_t, sizeof(uint32_t));
return 0;
}
/*
* Service table for portmapper v2.
*
* Service management is table driven in libnfsand this is the table
* that defines which procedures we implement for portmapper v2.
* If clients try to connect to the not-yet-implemented procedures here
* libnfs will automatically respond with an RPC layer error that flags
* PROCEDURE UNAVAILABLE.
*
* This table contains the procedure number, the callback function to implement
* this procedure, the unmarshalling function that libnfs should use to unppack
* the client payload as well as its size.
*
* Version 2 does not support ipv6 so this version of portmapper is
* not too commonly used any more.
*/
struct service_proc pmap2_pt[] = {
{PMAP2_NULL, pmap2_null_proc,
(zdrproc_t)zdr_void, 0},
{PMAP2_SET, pmap2_set_proc,
(zdrproc_t)zdr_PMAP2SETargs, sizeof(PMAP2SETargs)},
{PMAP2_UNSET, pmap2_unset_proc,
(zdrproc_t)zdr_PMAP2UNSETargs, sizeof(PMAP2UNSETargs)},
{PMAP2_GETPORT, pmap2_getport_proc,
(zdrproc_t)zdr_PMAP2GETPORTargs, sizeof(PMAP2GETPORTargs)},
{PMAP2_DUMP, pmap2_dump_proc,
(zdrproc_t)zdr_void, 0},
//{PMAP2_CALLIT, pmap2_...},
};
/*
* The NULL procedure. All protocols/versions must provide a NULL procedure
* as index 0.
* It is used by clients, and rpcinfo, to "ping" a service and verify that
* the service is available and that it does support the indicated version.
*/
static int pmap3_null_proc(struct rpc_context *rpc, struct rpc_msg *call)
{
rpc_send_reply(rpc, call, NULL, (zdrproc_t)zdr_void, 0);
return 0;
}
/*
* v3 DUMP.
* This RPC returns a list of all endpoints that are registered with
* portmapper.
*/
static int pmap3_dump_proc(struct rpc_context *rpc, struct rpc_msg *call)
{
PMAP3DUMPres reply;
struct mapping *tmp;
reply.list = NULL;
for (tmp = map; tmp; tmp = tmp->next) {
struct pmap3_mapping_list *tmp_list;
tmp_list = malloc(sizeof(struct pmap3_mapping_list));
tmp_list->map.prog = tmp->prog;
tmp_list->map.vers = tmp->vers;
tmp_list->map.netid = tmp->netid;
tmp_list->map.addr = tmp->addr;
tmp_list->map.owner = tmp->owner;
tmp_list->next = reply.list;
reply.list = tmp_list;
}
rpc_send_reply(rpc, call, &reply,
(zdrproc_t)zdr_PMAP3DUMPres, sizeof(PMAP3DUMPres));
while (reply.list) {
struct pmap3_mapping_list *tmp_list = reply.list->next;
free(reply.list);
reply.list = tmp_list;
}
return 0;
}
/*
* Service table for portmapper v3.
*
* Service management is table driven in libnfsand this is the table
* that defines which procedures we implement for portmapper v3.
* If clients try to connect to the not-yet-implemented procedures here
* libnfs will automatically respond with an RPC layer error that flags
* PROCEDURE UNAVAILABLE.
*
* This table contains the procedure number, the callback function to implement
* this procedure, the unmarshalling function that libnfs should use to unppack
* the client payload as well as its size.
*/
struct service_proc pmap3_pt[] = {
{PMAP3_NULL, pmap3_null_proc,
(zdrproc_t)zdr_void, 0},
//{PMAP3_SET, pmap3_...},
//{PMAP3_UNSET, pmap3_...},
//{PMAP3_GETADDR, pmap3_...},
{PMAP3_DUMP, pmap3_dump_proc,
(zdrproc_t)zdr_void, 0},
//{PMAP3_CALLIT, pmap3_...},
//{PMAP3_GETTIME, pmap3_...},
//{PMAP3_UADDR2TADDR, pmap3_...},
//{PMAP3_TADDR2UADDR, pmap3_...},
};
/*
* This callback is invoked from the event system when an event we are waiting
* for has become active.
*/
static void server_io(evutil_socket_t fd, short events, void *private_data)
{
struct server *server = private_data;
int revents = 0;
/*
* Translate the libevent read/write flags to the corresponding
* flags that libnfs uses.
*/
if (events & EV_READ) {
revents |= POLLIN;
}
if (events & EV_WRITE) {
revents |= POLLOUT;
}
/*
* Let libnfs process the event.
*/
if (rpc_service(server->rpc, revents) < 0) {
free_server(server);
return;
}
/*
* Update which events we are interested in. It might have changed
* for example if we no longer have any data pending to send
* we no longer need to wait for the socket to become writeable.
*/
update_events(server->rpc, server->read_event, server->write_event);
}
/*
* This callback is invoked when we have a client connecting to our TCP
* port.
*/
static void do_accept(evutil_socket_t s, short events, void *private_data)
{
struct sockaddr_storage ss;
socklen_t len = sizeof(ss);
struct server *server;
int fd;
server = malloc(sizeof(struct server));
if (server == NULL) {
return;
}
memset(server, 0, sizeof(*server));
if ((fd = accept(s, (struct sockaddr *)&ss, &len)) < 0) {
free_server(server);
return;
}
evutil_make_socket_nonblocking(fd);
server->rpc = rpc_init_server_context(fd);
if (server->rpc == NULL) {
close(fd);
free_server(server);
return;
}
/*
* Register both v2 and v3 of the protocol to the new
* server context.
*/
rpc_register_service(server->rpc, PMAP_PROGRAM, PMAP_V2,
pmap2_pt, sizeof(pmap2_pt) / sizeof(pmap2_pt[0]));
rpc_register_service(server->rpc, PMAP_PROGRAM, PMAP_V3,
pmap3_pt, sizeof(pmap3_pt) / sizeof(pmap3_pt[0]));
/*
* Create events for read and write for this new server instance.
*/
server->read_event = event_new(base, fd, EV_READ|EV_PERSIST,
server_io, server);
server->write_event = event_new(base, fd, EV_WRITE|EV_PERSIST,
server_io, server);
update_events(server->rpc, server->read_event, server->write_event);
}
int main(int argc, char *argv[])
{
struct sockaddr_in in;
int one = 1;
#ifdef WIN32
if (WSAStartup(MAKEWORD(2,2), &wsaData) != 0) {
printf("Failed to start Winsock2\n");
return 10;
}
#endif
#ifdef AROS
aros_init_socket();
#endif
base = event_base_new();
if (base == NULL) {
printf("Failed create event context\n");
exit(10);
}
/*
* Portmapper listens on port 111, any address.
* Just initialize it for now as we will need it several times below.
*/
in.sin_family = AF_INET;
in.sin_port = htons(111);
in.sin_addr.s_addr = htonl (INADDR_ANY);
/* This is the portmapper protocol itself which we obviously
* support.
*/
pmap_register(100000, 2, strdup("tcp"), strdup("0.0.0.0.0.111"),
strdup("portmapper-service"));
pmap_register(100000, 2, strdup("udp"), strdup("0.0.0.0.0.111"),
strdup("portmapper-service"));
pmap_register(100000, 3, strdup("tcp"), strdup("0.0.0.0.0.111"),
strdup("portmapper-service"));
pmap_register(100000, 3, strdup("udp"), strdup("0.0.0.0.0.111"),
strdup("portmapper-service"));
/*
* TCP: Set up a listening socket for incoming TCP connections.
* Once clients connect, inside do_accept() we will create a proper
* libnfs server context for each connection.
*/
listen_socket = socket(AF_INET, SOCK_STREAM, 0);
if (listen_socket == -1) {
printf("Failed to create listening socket\n");
exit(10);
}
evutil_make_socket_nonblocking(listen_socket);
setsockopt(listen_socket, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one));
if (bind(listen_socket, (struct sockaddr *)&in, sizeof(in)) < 0) {
printf("Failed to bind listening socket\n");
exit(10);
}
if (listen(listen_socket, 16) < 0) {
printf("failed to listen to socket\n");
exit(10);
}
listen_event = event_new(base,
listen_socket,
EV_READ|EV_PERSIST,
do_accept, NULL);
event_add(listen_event, NULL);
/*
* UDP: Create and bind to the socket we want to use for the UDP server.
*/
udp_socket = socket(AF_INET, SOCK_DGRAM, 0);
if (udp_socket == -1) {
printf("Failed to create udp socket\n");
exit(10);
}
evutil_make_socket_nonblocking(udp_socket);
setsockopt(udp_socket, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one));
if (bind(udp_socket, (struct sockaddr *)&in, sizeof(in)) < 0) {
printf("Failed to bind udp socket\n");
exit(10);
}
/*
* UDP: Create a libnfs server context for this socket.
*/
memset(&udp_server, 0, sizeof(udp_server));
udp_server.rpc = rpc_init_server_context(udp_socket);
/*
* UDP: Register both v2 and v3 of the protocol to the
* UDP server context.
*/
rpc_register_service(udp_server.rpc, PMAP_PROGRAM, PMAP_V2,
pmap2_pt, sizeof(pmap2_pt) / sizeof(pmap2_pt[0]));
rpc_register_service(udp_server.rpc, PMAP_PROGRAM, PMAP_V3,
pmap3_pt, sizeof(pmap3_pt) / sizeof(pmap3_pt[0]));
udp_server.read_event = event_new(base,
udp_socket,
EV_READ|EV_PERSIST,
server_io, &udp_server);
event_add(udp_server.read_event, NULL);
/*
* Everything is now set up. Start the event loop.
*/
event_base_dispatch(base);
return 0;
}
libnfs-libnfs-2.0.0/include/ 0000775 0000000 0000000 00000000000 13121032772 0015662 5 ustar 00root root 0000000 0000000 libnfs-libnfs-2.0.0/include/Makefile.am 0000664 0000000 0000000 00000000634 13121032772 0017721 0 ustar 00root root 0000000 0000000 nfscdir = $(includedir)/nfsc
dist_nfsc_HEADERS = \
nfsc/libnfs.h \
nfsc/libnfs-raw.h \
nfsc/libnfs-zdr.h \
../mount/libnfs-raw-mount.h \
../portmap/libnfs-raw-portmap.h \
../nfs/libnfs-raw-nfs.h \
../nfs4/libnfs-raw-nfs4.h \
../nlm/libnfs-raw-nlm.h \
../nsm/libnfs-raw-nsm.h \
../rquota/libnfs-raw-rquota.h
dist_noinst_HEADERS = \
../win32/win32_compat.h \
libnfs-private.h \
slist.h
libnfs-libnfs-2.0.0/include/libnfs-private.h 0000664 0000000 0000000 00000015050 13121032772 0020761 0 ustar 00root root 0000000 0000000 /*
Copyright (C) 2010 by Ronnie Sahlberg
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, see .
*/
#ifndef _LIBNFS_PRIVATE_H_
#define _LIBNFS_PRIVATE_H_
#ifdef HAVE_CONFIG_H
#include "config.h" /* HAVE_SOCKADDR_STORAGE ? */
#endif
#ifdef HAVE_NET_IF_H
#include
#endif
#ifndef WIN32
#include /* struct sockaddr_storage */
#endif
#if defined(WIN32) && !defined(IFNAMSIZ)
#define IFNAMSIZ 255
#endif
#include "libnfs-zdr.h"
#ifdef __cplusplus
extern "C" {
#endif
#ifndef MIN
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#endif
#ifndef MAX
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
#endif
#if !defined(HAVE_SOCKADDR_STORAGE) && !defined(WIN32)
/*
* RFC 2553: protocol-independent placeholder for socket addresses
*/
#define _SS_MAXSIZE 128
#define _SS_ALIGNSIZE (sizeof(double))
#define _SS_PAD1SIZE (_SS_ALIGNSIZE - sizeof(unsigned char) * 2)
#define _SS_PAD2SIZE (_SS_MAXSIZE - sizeof(unsigned char) * 2 - \
_SS_PAD1SIZE - _SS_ALIGNSIZE)
struct sockaddr_storage {
#ifdef HAVE_SOCKADDR_LEN
unsigned char ss_len; /* address length */
unsigned char ss_family; /* address family */
#else
unsigned short ss_family;
#endif
char __ss_pad1[_SS_PAD1SIZE];
double __ss_align; /* force desired structure storage alignment */
char __ss_pad2[_SS_PAD2SIZE];
};
#endif
struct rpc_fragment {
struct rpc_fragment *next;
uint32_t size;
char *data;
};
#define RPC_CONTEXT_MAGIC 0xc6e46435
#define RPC_PARAM_UNDEFINED -1
/*
* Queue is singly-linked but we hold on to the tail
*/
struct rpc_queue {
struct rpc_pdu *head, *tail;
};
#define HASHES 1024
#define NFS_RA_TIMEOUT 5
#define NFS_MAX_XFER_SIZE (1024 * 1024)
#define ZDR_ENCODE_OVERHEAD 1024
#define ZDR_ENCODEBUF_MINSIZE 4096
struct rpc_endpoint {
struct rpc_endpoint *next;
int program;
int version;
struct service_proc *procs;
int num_procs;
};
struct rpc_context {
uint32_t magic;
int fd;
int old_fd;
int is_connected;
int is_nonblocking;
char *error_string;
rpc_cb connect_cb;
void *connect_data;
struct AUTH *auth;
uint32_t xid;
struct rpc_queue outqueue;
struct sockaddr_storage udp_src;
struct rpc_queue waitpdu[HASHES];
uint32_t waitpdu_len;
uint32_t inpos;
char rm_buf[4];
char *inbuf;
/* special fields for UDP, which can sometimes be BROADCASTed */
int is_udp;
struct sockaddr_storage udp_dest;
int is_broadcast;
/* track the address we connect to so we can auto-reconnect on session failure */
struct sockaddr_storage s;
int auto_reconnect;
int num_retries;
/* fragment reassembly */
struct rpc_fragment *fragments;
/* parameters passable via URL */
int tcp_syncnt;
int uid;
int gid;
uint32_t readahead;
uint32_t pagecache;
uint32_t pagecache_ttl;
int debug;
int timeout;
char ifname[IFNAMSIZ];
/* Is a server context ? */
int is_server_context;
struct rpc_endpoint *endpoints;
};
struct rpc_pdu {
struct rpc_pdu *next;
uint32_t xid;
ZDR zdr;
uint32_t written;
struct rpc_data outdata;
rpc_cb cb;
void *private_data;
/* function to decode the zdr reply data and buffer to decode into */
zdrproc_t zdr_decode_fn;
caddr_t zdr_decode_buf;
uint32_t zdr_decode_bufsize;
#define PDU_DISCARD_AFTER_SENDING 0x00000001
uint32_t flags;
time_t timeout;
};
void rpc_reset_queue(struct rpc_queue *q);
void rpc_enqueue(struct rpc_queue *q, struct rpc_pdu *pdu);
void rpc_return_to_queue(struct rpc_queue *q, struct rpc_pdu *pdu);
unsigned int rpc_hash_xid(uint32_t xid);
struct rpc_pdu *rpc_allocate_pdu(struct rpc_context *rpc, int program, int version, int procedure, rpc_cb cb, void *private_data, zdrproc_t zdr_decode_fn, int zdr_bufsize);
struct rpc_pdu *rpc_allocate_pdu2(struct rpc_context *rpc, int program, int version, int procedure, rpc_cb cb, void *private_data, zdrproc_t zdr_decode_fn, int zdr_bufsize, size_t alloc_hint);
void rpc_free_pdu(struct rpc_context *rpc, struct rpc_pdu *pdu);
int rpc_queue_pdu(struct rpc_context *rpc, struct rpc_pdu *pdu);
uint32_t rpc_get_pdu_size(char *buf);
int rpc_process_pdu(struct rpc_context *rpc, char *buf, int size);
void rpc_error_all_pdus(struct rpc_context *rpc, const char *error);
void rpc_set_error(struct rpc_context *rpc, const char *error_string, ...)
#ifdef __GNUC__
__attribute__((format(printf, 2, 3)))
#endif
;
void nfs_set_error(struct nfs_context *nfs, char *error_string, ...)
#ifdef __GNUC__
__attribute__((format(printf, 2, 3)))
#endif
;
#define RPC_LOG(rpc, level, format, ...) \
do { \
if (level <= rpc->debug) { \
fprintf(stderr, "libnfs:%d " format "\n", level, ## __VA_ARGS__); \
} \
} while (0)
const char *nfs_get_server(struct nfs_context *nfs);
const char *nfs_get_export(struct nfs_context *nfs);
/* we dont want to expose UDP to normal applications/users this is private to libnfs to use exclusively for broadcast RPC */
int rpc_bind_udp(struct rpc_context *rpc, char *addr, int port);
int rpc_set_udp_destination(struct rpc_context *rpc, char *addr, int port, int is_broadcast);
struct rpc_context *rpc_init_udp_context(void);
struct sockaddr *rpc_get_recv_sockaddr(struct rpc_context *rpc);
void rpc_set_autoreconnect(struct rpc_context *rpc, int num_retries);
void rpc_set_interface(struct rpc_context *rpc, const char *ifname);
void rpc_set_tcp_syncnt(struct rpc_context *rpc, int v);
void rpc_set_pagecache(struct rpc_context *rpc, uint32_t v);
void rpc_set_pagecache_ttl(struct rpc_context *rpc, uint32_t v);
void rpc_set_readahead(struct rpc_context *rpc, uint32_t v);
void rpc_set_debug(struct rpc_context *rpc, int level);
void rpc_set_timeout(struct rpc_context *rpc, int timeout);
int rpc_get_timeout(struct rpc_context *rpc);
int rpc_add_fragment(struct rpc_context *rpc, char *data, uint32_t size);
void rpc_free_all_fragments(struct rpc_context *rpc);
int rpc_is_udp_socket(struct rpc_context *rpc);
int rpc_current_time(void);
const struct nfs_fh3 *nfs_get_rootfh(struct nfs_context *nfs);
void *zdr_malloc(ZDR *zdrs, uint32_t size);
#ifdef __cplusplus
}
#endif
#endif /* !_LIBNFS_PRIVATE_H_ */
libnfs-libnfs-2.0.0/include/nfsc/ 0000775 0000000 0000000 00000000000 13121032772 0016613 5 ustar 00root root 0000000 0000000 libnfs-libnfs-2.0.0/include/nfsc/libnfs-raw.h 0000664 0000000 0000000 00000242556 13121032772 0021046 0 ustar 00root root 0000000 0000000 /* -*- mode:c; tab-width:8; c-basic-offset:8; indent-tabs-mode:nil; -*- */
/*
Copyright (C) 2010 by Ronnie Sahlberg
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, see .
*/
/*
* This is the lowlevel interface to access NFS resources.
* Through this interface you have access to the full gamut of nfs and nfs related
* protocol as well as the XDR encoded/decoded structures.
*/
#ifndef _LIBNFS_RAW_H_
#define _LIBNFS_RAW_H_
#include
#include
#ifdef __cplusplus
extern "C" {
#endif
struct rpc_data {
int size;
char *data;
};
struct rpc_context;
struct rpc_context *rpc_init_context(void);
void rpc_destroy_context(struct rpc_context *rpc);
void rpc_set_auth(struct rpc_context *rpc, struct AUTH *auth);
/*
* Used for interfacing the api into an external eventsystem.
*
* rpc_get_fd() returns the file descriptor for the context we need to
* listen for events from.
*
* rpc_which_events() returns which events that we need to poll for.
* This is a combination of the POLLIN and POLLOUT flags.
*
* rpc_service() This function should be called once there are events triggered
* for the filedescriptor. This function takes POLLIN/POLLOUT/POLLHUP/POLLERR
* as arguments.
* This function returns 0 on success or -1 on error. If it returns -1 it
* means that the socket is in an unrecoverable error state (disconnected?)
* and that no further commands can be used.
* When this happens the application should destroy the now errored context
* re-create a new context and reconnect.
*
*/
int rpc_get_fd(struct rpc_context *rpc);
int rpc_which_events(struct rpc_context *rpc);
int rpc_service(struct rpc_context *rpc, int revents);
/*
* Returns the number of commands in-flight. Can be used by the application
* to check if there are any more responses we are awaiting for the server
* or if the connection is completely idle.
*/
int rpc_queue_length(struct rpc_context *rpc);
/*
* Set which UID/GID to use in the authenticator.
* By default libnfs will use getuid()/getgid() where available
* and 65534/65534 where not.
*/
void rpc_set_uid(struct rpc_context *rpc, int uid);
void rpc_set_gid(struct rpc_context *rpc, int gid);
/*
* Create a server context.
*/
struct rpc_context *rpc_init_server_context(int s);
/* This is the callback functions for server contexts.
* These are invoked from the library when a CALL has been received and a
* service procedure has been found that matches the rpc
* program/version/procedure.
*
* The rpc arguments are stored in call->body.cbody.args;
* Example:
* static int pmap2_getport_proc(struct rpc_context *rpc, struct rpc_msg *call)
* {
* pmap2_mapping *args = call->body.cbody.args;
* ...
*
* struct service_proc pmap2_pt[] = {
* {PMAP2_GETPORT, pmap2_getport_proc,
* (zdrproc_t)zdr_pmap2_mapping, sizeof(pmap2_mapping)},
* ...
*
*
* The return value is:
* 0: Procedure was completed normally.
* !0: An abnormal error has occured. It is unrecoverable and the only
* meaningful cause of action is to tear down the connection from
* the client.
*/
typedef int (*service_fn)(struct rpc_context *rpc, struct rpc_msg *call);
struct service_proc {
int proc;
service_fn func;
zdrproc_t decode_fn;
int decode_buf_size;
};
/*
* Register a service callback table for program/version.
* Can only be used with contexts created with rpc_init_server_context()
*/
int rpc_register_service(struct rpc_context *rpc, int program, int version,
struct service_proc *procs, int num_procs);
int rpc_send_reply(struct rpc_context *rpc, struct rpc_msg *call,
void *reply, zdrproc_t encode_fn,
int alloc_hint);
/*
* When an operation failed, this function can extract a detailed error string.
*/
char *rpc_get_error(struct rpc_context *rpc);
/* Utility function to get an RPC context from a NFS context. Useful for doing low level NFSACL
* calls on a NFS context.
*/
struct rpc_context *nfs_get_rpc_context(struct nfs_context *nfs);
/* This function returns the nfs_fh3 structure from a nfsfh structure.
This allows to use a file onened with nfs_open() together with low-level
rpc functions that thake a nfs filehandle
*/
struct nfs_fh3 *nfs_get_fh(struct nfsfh *nfsfh);
/* Control what the next XID value to be used on the context will be.
This can be used when multiple contexts are used to the same server
to avoid that the two contexts have xid collissions.
*/
void rpc_set_next_xid(struct rpc_context *rpc, uint32_t xid);
/* This function can be used to set the file descriptor used for
* the RPC context. It is primarily useful when emulating dup2()
* and similar or where you want full control of the filedescriptor numbers
* used by the rpc socket.
*
* ...
* oldfd = rpc_get_fd(rpc);
* dup2(oldfd, newfd);
* rpc_set_fd(rpc, newfd);
* close(oldfd);
* ...
*/
void rpc_set_fd(struct rpc_context *rpc, int fd);
#define RPC_STATUS_SUCCESS 0
#define RPC_STATUS_ERROR 1
#define RPC_STATUS_CANCEL 2
#define RPC_STATUS_TIMEOUT 3
/*
* Async connection to the tcp port at server:port.
* Function returns
* 0 : The connection was initiated. Once the connection establish finishes, the callback will be invoked.
* <0 : An error occured when trying to set up the connection. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : The tcp connection was successfully established.
* data is NULL.
* RPC_STATUS_ERROR : The connection failed to establish.
* data is the erro string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* : data is NULL.
*/
int rpc_connect_async(struct rpc_context *rpc, const char *server, int port, rpc_cb cb, void *private_data);
/*
* Async function to connect to a specific RPC program/version
* Function returns
* 0 : The connection was initiated. Once the connection establish finishes, the callback will be invoked.
* <0 : An error occured when trying to set up the connection. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : The tcp connection was successfully established.
* data is NULL.
* RPC_STATUS_ERROR : The connection failed to establish.
* data is the erro string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* : data is NULL.
*/
int rpc_connect_program_async(struct rpc_context *rpc, const char *server, int program, int version, rpc_cb cb, void *private_data);
/*
* When disconnecting a connection in flight. All commands in flight will be called with the callback
* and status RPC_STATUS_ERROR. Data will be the error string for the disconnection.
*/
int rpc_disconnect(struct rpc_context *rpc, const char *error);
/*
* PORTMAP v2 FUNCTIONS
*/
/*
* Call PORTMAPPER2/NULL
* Function returns
* 0 : The connection was initiated. Once the connection establish finishes, the callback will be invoked.
* <0 : An error occured when trying to set up the connection. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the portmapper daemon.
* data is NULL.
* RPC_STATUS_ERROR : An error occured when trying to contact the portmapper.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
EXTERN int rpc_pmap2_null_async(struct rpc_context *rpc, rpc_cb cb, void *private_data);
/*
* Call PORTMAPPER2/GETPORT.
* Function returns
* 0 : The connection was initiated. Once the connection establish finishes, the callback will be invoked.
* <0 : An error occured when trying to set up the connection. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the portmapper daemon.
* data is a (uint32_t *), containing the port returned.
* RPC_STATUS_ERROR : An error occured when trying to contact the portmapper.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
EXTERN int rpc_pmap2_getport_async(struct rpc_context *rpc, int program, int version, int protocol, rpc_cb cb, void *private_data);
/*
* Call PORTMAPPER2/SET
* Function returns
* 0 : The connection was initiated. Once the connection establish finishes, the callback will be invoked.
* <0 : An error occured when trying to set up the connection. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the portmapper daemon.
* data is a (uint32_t *), containing status
* RPC_STATUS_ERROR : An error occured when trying to contact the portmapper.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
EXTERN int rpc_pmap2_set_async(struct rpc_context *rpc, int program, int version, int protocol, int port, rpc_cb cb, void *private_data);
/*
* Call PORTMAPPER2/UNSET
* Function returns
* 0 : The connection was initiated. Once the connection establish finishes, the callback will be invoked.
* <0 : An error occured when trying to set up the connection. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the portmapper daemon.
* data is a (uint32_t *), containing status
* RPC_STATUS_ERROR : An error occured when trying to contact the portmapper.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
EXTERN int rpc_pmap2_unset_async(struct rpc_context *rpc, int program, int version, int protocol, int port, rpc_cb cb, void *private_data);
/*
* Call PORTMAPPER2/DUMP.
* Function returns
* 0 : The connection was initiated. Once the connection establish finishes, the callback will be invoked.
* <0 : An error occured when trying to set up the connection. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the portmapper daemon.
* data is struct pmap2_dump_result.
* RPC_STATUS_ERROR : An error occured when trying to contact the portmapper.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
EXTERN int rpc_pmap2_dump_async(struct rpc_context *rpc, rpc_cb cb, void *private_data);
/*
* Call PORTMAPPER2/CALLIT.
* Function returns
* 0 : The connection was initiated. Once the connection establish finishes, the callback will be invoked.
* <0 : An error occured when trying to set up the connection. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the portmapper daemon
* data is a 'pmap2_call_result' pointer.
* RPC_STATUS_ERROR : An error occured when trying to contact the portmapper.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
EXTERN int rpc_pmap2_callit_async(struct rpc_context *rpc, int program, int version, int procedure, char *data, int datalen, rpc_cb cb, void *private_data);
/*
* PORTMAP v3 FUNCTIONS
*/
/*
* Call PORTMAPPER3/NULL
* Function returns
* 0 : The connection was initiated. Once the connection establish finishes, the callback will be invoked.
* <0 : An error occured when trying to set up the connection. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the portmapper daemon.
* data is NULL.
* RPC_STATUS_ERROR : An error occured when trying to contact the portmapper.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
EXTERN int rpc_pmap3_null_async(struct rpc_context *rpc, rpc_cb cb, void *private_data);
/*
* Call PORTMAPPER3/SET.
* Function returns
* 0 : The connection was initiated. Once the connection establish finishes, the callback will be invoked.
* <0 : An error occured when trying to set up the connection. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the portmapper daemon.
* data is uint32_t *
* RPC_STATUS_ERROR : An error occured when trying to contact the portmapper.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
struct pmap3_mapping;
EXTERN int rpc_pmap3_set_async(struct rpc_context *rpc, struct pmap3_mapping *map, rpc_cb cb, void *private_data);
/*
* Call PORTMAPPER3/UNSET.
* Function returns
* 0 : The connection was initiated. Once the connection establish finishes, the callback will be invoked.
* <0 : An error occured when trying to set up the connection. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the portmapper daemon.
* data is uint32_t *
* RPC_STATUS_ERROR : An error occured when trying to contact the portmapper.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
EXTERN int rpc_pmap3_unset_async(struct rpc_context *rpc, struct pmap3_mapping *map, rpc_cb cb, void *private_data);
/*
* Call PORTMAPPER3/GETADDR.
* Function returns
* 0 : The connection was initiated. Once the connection establish finishes, the callback will be invoked.
* <0 : An error occured when trying to set up the connection. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the portmapper daemon.
* data is struct pmap3_string_result.
* RPC_STATUS_ERROR : An error occured when trying to contact the portmapper.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
EXTERN int rpc_pmap3_getaddr_async(struct rpc_context *rpc, struct pmap3_mapping *map, rpc_cb cb, void *private_data);
/*
* Call PORTMAPPER3/DUMP.
* Function returns
* 0 : The connection was initiated. Once the connection establish finishes, the callback will be invoked.
* <0 : An error occured when trying to set up the connection. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the portmapper daemon.
* data is struct pmap3_dump_result.
* RPC_STATUS_ERROR : An error occured when trying to contact the portmapper.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
EXTERN int rpc_pmap3_dump_async(struct rpc_context *rpc, rpc_cb cb, void *private_data);
/*
* Call PORTMAPPER3/CALLIT.
* Function returns
* 0 : The connection was initiated. Once the connection establish finishes, the callback will be invoked.
* <0 : An error occured when trying to set up the connection. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the portmapper daemon
* data is a 'pmap3_call_result' pointer.
* RPC_STATUS_ERROR : An error occured when trying to contact the portmapper.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
EXTERN int rpc_pmap3_callit_async(struct rpc_context *rpc, int program, int version, int procedure, char *data, int datalen, rpc_cb cb, void *private_data);
/*
* Call PORTMAPPER3/GETTIME.
* Function returns
* 0 : The connection was initiated. Once the connection establish finishes, the callback will be invoked.
* <0 : An error occured when trying to set up the connection. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the portmapper daemon.
* data is a uint32_t *.
* RPC_STATUS_ERROR : An error occured when trying to contact the portmapper.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
EXTERN int rpc_pmap3_gettime_async(struct rpc_context *rpc, rpc_cb cb, void *private_data);
/*
* Call PORTMAPPER3/UADDR2TADDR.
* Function returns
* 0 : The connection was initiated. Once the connection establish finishes, the callback will be invoked.
* <0 : An error occured when trying to set up the connection. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the portmapper daemon.
* data is a struct pmap3_netbuf *.
* RPC_STATUS_ERROR : An error occured when trying to contact the portmapper.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
EXTERN int rpc_pmap3_uaddr2taddr_async(struct rpc_context *rpc, char *uaddr, rpc_cb cb, void *private_data);
/*
* Call PORTMAPPER3/TADDR2UADDR.
* Function returns
* 0 : The connection was initiated. Once the connection establish finishes, the callback will be invoked.
* <0 : An error occured when trying to set up the connection. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the portmapper daemon.
* data is a struct pmap3_string_result *.
* RPC_STATUS_ERROR : An error occured when trying to contact the portmapper.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
struct pmap3_netbuf;
EXTERN int rpc_pmap3_taddr2uaddr_async(struct rpc_context *rpc, struct pmap3_netbuf *netbuf, rpc_cb cb, void *private_data);
/*
* MOUNT v3 FUNCTIONS
*/
char *mountstat3_to_str(int stat);
int mountstat3_to_errno(int error);
/*
* Call MOUNT3/NULL
* Function returns
* 0 : The call was initiated. The callback will be invoked when the call completes.
* <0 : An error occured when trying to set up the call. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the mount daemon.
* data is NULL.
* RPC_STATUS_ERROR : An error occured when trying to contact the mount daemon.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
EXTERN int rpc_mount3_null_async(struct rpc_context *rpc, rpc_cb cb, void *private_data);
EXTERN int rpc_mount_null_async(struct rpc_context *rpc, rpc_cb cb, void *private_data);
/*
* Call MOUNT3/MNT
* Function returns
* 0 : The call was initiated. The callback will be invoked when the call completes.
* <0 : An error occured when trying to set up the call. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the mount daemon.
* data is union mountres3.
* RPC_STATUS_ERROR : An error occured when trying to contact the mount daemon.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
EXTERN int rpc_mount3_mnt_async(struct rpc_context *rpc, rpc_cb cb, char *exportname, void *private_data);
EXTERN int rpc_mount_mnt_async(struct rpc_context *rpc, rpc_cb cb, char *exportname, void *private_data);
/*
* Call MOUNT3/DUMP
* Function returns
* 0 : The call was initiated. The callback will be invoked when the call completes.
* <0 : An error occured when trying to set up the call. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the mount daemon.
* data is a mountlist.
* RPC_STATUS_ERROR : An error occured when trying to contact the mount daemon.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
EXTERN int rpc_mount3_dump_async(struct rpc_context *rpc, rpc_cb cb, void *private_data);
EXTERN int rpc_mount_dump_async(struct rpc_context *rpc, rpc_cb cb, void *private_data);
/*
* Call MOUNT3/UMNT
* Function returns
* 0 : The call was initiated. The callback will be invoked when the call completes.
* <0 : An error occured when trying to set up the call. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the mount daemon.
* data NULL.
* RPC_STATUS_ERROR : An error occured when trying to contact the mount daemon.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
EXTERN int rpc_mount3_umnt_async(struct rpc_context *rpc, rpc_cb cb, char *exportname, void *private_data);
EXTERN int rpc_mount_umnt_async(struct rpc_context *rpc, rpc_cb cb, char *exportname, void *private_data);
/*
* Call MOUNT3/UMNTALL
* Function returns
* 0 : The call was initiated. The callback will be invoked when the call completes.
* <0 : An error occured when trying to set up the call. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the mount daemon.
* data NULL.
* RPC_STATUS_ERROR : An error occured when trying to contact the mount daemon.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
EXTERN int rpc_mount3_umntall_async(struct rpc_context *rpc, rpc_cb cb, void *private_data);
EXTERN int rpc_mount_umntall_async(struct rpc_context *rpc, rpc_cb cb, void *private_data);
/*
* Call MOUNT3/EXPORT
* NOTE: You must include 'libnfs-raw-mount.h' to get the definitions of the
* returned structures.
*
* Function returns
* 0 : The call was initiated. The callback will be invoked when the call completes.
* <0 : An error occured when trying to set up the call. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the mount daemon.
* data is a pointer to an exports pointer:
* exports export = *(exports *)data;
* RPC_STATUS_ERROR : An error occured when trying to contact the mount daemon.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
EXTERN int rpc_mount3_export_async(struct rpc_context *rpc, rpc_cb cb, void *private_data);
EXTERN int rpc_mount_export_async(struct rpc_context *rpc, rpc_cb cb, void *private_data);
/*
* MOUNT v1 FUNCTIONS (Used with NFSv2)
*/
/*
* Call MOUNT1/NULL
* Function returns
* 0 : The call was initiated. The callback will be invoked when the call completes.
* <0 : An error occured when trying to set up the call. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the mount daemon.
* data is NULL.
* RPC_STATUS_ERROR : An error occured when trying to contact the mount daemon.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
EXTERN int rpc_mount1_null_async(struct rpc_context *rpc, rpc_cb cb, void *private_data);
/*
* Call MOUNT1/MNT
* Function returns
* 0 : The call was initiated. The callback will be invoked when the call completes.
* <0 : An error occured when trying to set up the call. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the mount daemon.
* data is union mountres1.
* RPC_STATUS_ERROR : An error occured when trying to contact the mount daemon.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
EXTERN int rpc_mount1_mnt_async(struct rpc_context *rpc, rpc_cb cb, char *exportname, void *private_data);
/*
* Call MOUNT1/DUMP
* Function returns
* 0 : The call was initiated. The callback will be invoked when the call completes.
* <0 : An error occured when trying to set up the call. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the mount daemon.
* data is a mountlist.
* RPC_STATUS_ERROR : An error occured when trying to contact the mount daemon.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
EXTERN int rpc_mount1_dump_async(struct rpc_context *rpc, rpc_cb cb, void *private_data);
/*
* Call MOUNT1/UMNT
* Function returns
* 0 : The call was initiated. The callback will be invoked when the call completes.
* <0 : An error occured when trying to set up the call. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the mount daemon.
* data NULL.
* RPC_STATUS_ERROR : An error occured when trying to contact the mount daemon.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
EXTERN int rpc_mount1_umnt_async(struct rpc_context *rpc, rpc_cb cb, char *exportname, void *private_data);
/*
* Call MOUNT1/UMNTALL
* Function returns
* 0 : The call was initiated. The callback will be invoked when the call completes.
* <0 : An error occured when trying to set up the call. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the mount daemon.
* data NULL.
* RPC_STATUS_ERROR : An error occured when trying to contact the mount daemon.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
EXTERN int rpc_mount1_umntall_async(struct rpc_context *rpc, rpc_cb cb, void *private_data);
/*
* Call MOUNT1/EXPORT
* NOTE: You must include 'libnfs-raw-mount.h' to get the definitions of the
* returned structures.
*
* Function returns
* 0 : The call was initiated. The callback will be invoked when the call completes.
* <0 : An error occured when trying to set up the call. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the mount daemon.
* data is a pointer to an exports pointer:
* exports export = *(exports *)data;
* RPC_STATUS_ERROR : An error occured when trying to contact the mount daemon.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
EXTERN int rpc_mount1_export_async(struct rpc_context *rpc, rpc_cb cb, void *private_data);
/*
* NFS v3 FUNCTIONS
*/
struct nfs_fh3;
char *nfsstat3_to_str(int error);
int nfsstat3_to_errno(int error);
/*
* Call NFS3/NULL
* Function returns
* 0 : The call was initiated. The callback will be invoked when the call completes.
* <0 : An error occured when trying to set up the call. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the nfs daemon.
* data is NULL.
* RPC_STATUS_ERROR : An error occured when trying to contact the nfs daemon.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
EXTERN int rpc_nfs3_null_async(struct rpc_context *rpc, rpc_cb cb, void *private_data);
EXTERN int rpc_nfs_null_async(struct rpc_context *rpc, rpc_cb cb, void *private_data);
/*
* Call NFS3/GETATTR
* Function returns
* 0 : The call was initiated. The callback will be invoked when the call completes.
* <0 : An error occured when trying to set up the call. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the nfs daemon.
* data is GETATTR3res
* RPC_STATUS_ERROR : An error occured when trying to contact the nfs daemon.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
struct GETATTR3args;
EXTERN int rpc_nfs3_getattr_async(struct rpc_context *rpc, rpc_cb cb, struct GETATTR3args *args, void *private_data);
EXTERN int rpc_nfs_getattr_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, void *private_data);
/*
* Call NFS3/PATHCONF
* Function returns
* 0 : The call was initiated. The callback will be invoked when the call completes.
* <0 : An error occured when trying to set up the call. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the nfs daemon.
* data is PATHCONF3res
* RPC_STATUS_ERROR : An error occured when trying to contact the nfs daemon.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
struct PATHCONF3args;
EXTERN int rpc_nfs3_pathconf_async(struct rpc_context *rpc, rpc_cb cb, struct PATHCONF3args *args, void *private_data);
EXTERN int rpc_nfs_pathconf_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, void *private_data);
/*
* Call NFS3/LOOKUP
* Function returns
* 0 : The call was initiated. The callback will be invoked when the call completes.
* <0 : An error occured when trying to set up the call. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the nfs daemon.
* data is LOOKUP3res
* RPC_STATUS_ERROR : An error occured when trying to contact the nfs daemon.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
struct LOOKUP3args;
EXTERN int rpc_nfs3_lookup_async(struct rpc_context *rpc, rpc_cb cb, struct LOOKUP3args *args, void *private_data);
EXTERN int rpc_nfs_lookup_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, char *name, void *private_data);
/*
* Call NFS3/ACCESS
* Function returns
* 0 : The call was initiated. The callback will be invoked when the call completes.
* <0 : An error occured when trying to set up the call. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the nfs daemon.
* data is ACCESS3res
* RPC_STATUS_ERROR : An error occured when trying to contact the nfs daemon.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
struct ACCESS3args;
EXTERN int rpc_nfs3_access_async(struct rpc_context *rpc, rpc_cb cb, struct ACCESS3args *args, void *private_data);
EXTERN int rpc_nfs_access_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, int access, void *private_data);
/*
* Call NFS3/READ
* Function returns
* 0 : The call was initiated. The callback will be invoked when the call completes.
* <0 : An error occured when trying to set up the call. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the nfs daemon.
* data is READ3res
* RPC_STATUS_ERROR : An error occured when trying to contact the nfs daemon.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
struct READ3args;
EXTERN int rpc_nfs3_read_async(struct rpc_context *rpc, rpc_cb cb, struct READ3args *args, void *private_data);
EXTERN int rpc_nfs_read_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, uint64_t offset, uint64_t count, void *private_data);
/*
* Call NFS3/WRITE
* Function returns
* 0 : The call was initiated. The callback will be invoked when the call completes.
* <0 : An error occured when trying to set up the call. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the nfs daemon.
* data is WRITE3res *
* RPC_STATUS_ERROR : An error occured when trying to contact the nfs daemon.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
struct WRITE3args;
EXTERN int rpc_nfs3_write_async(struct rpc_context *rpc, rpc_cb cb, struct WRITE3args *args, void *private_data);
EXTERN int rpc_nfs_write_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, char *buf, uint64_t offset, uint64_t count, int stable_how, void *private_data);
/*
* Call NFS3/COMMIT
* Function returns
* 0 : The call was initiated. The callback will be invoked when the call completes.
* <0 : An error occured when trying to set up the call. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the nfs daemon.
* data is COMMIT3res *
* RPC_STATUS_ERROR : An error occured when trying to contact the nfs daemon.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
struct COMMIT3args;
EXTERN int rpc_nfs3_commit_async(struct rpc_context *rpc, rpc_cb cb, struct COMMIT3args *args, void *private_data);
EXTERN int rpc_nfs_commit_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, void *private_data);
/*
* Call NFS3/SETATTR
* Function returns
* 0 : The call was initiated. The callback will be invoked when the call completes.
* <0 : An error occured when trying to set up the call. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the nfs daemon.
* data is SETATTR3res *
* RPC_STATUS_ERROR : An error occured when trying to contact the nfs daemon.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
struct SETATTR3args;
EXTERN int rpc_nfs3_setattr_async(struct rpc_context *rpc, rpc_cb cb, struct SETATTR3args *args, void *private_data);
EXTERN int rpc_nfs_setattr_async(struct rpc_context *rpc, rpc_cb cb, struct SETATTR3args *args, void *private_data);
/*
* Call NFS3/MKDIR
* Function returns
* 0 : The call was initiated. The callback will be invoked when the call completes.
* <0 : An error occured when trying to set up the call. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the nfs daemon.
* data is MKDIR3res *
* RPC_STATUS_ERROR : An error occured when trying to contact the nfs daemon.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
struct MKDIR3args;
EXTERN int rpc_nfs3_mkdir_async(struct rpc_context *rpc, rpc_cb cb, struct MKDIR3args *args, void *private_data);
EXTERN int rpc_nfs_mkdir_async(struct rpc_context *rpc, rpc_cb cb, struct MKDIR3args *args, void *private_data);
/*
* Call NFS3/RMDIR
* Function returns
* 0 : The call was initiated. The callback will be invoked when the call completes.
* <0 : An error occured when trying to set up the call. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the nfs daemon.
* data is RMDIR3res *
* RPC_STATUS_ERROR : An error occured when trying to contact the nfs daemon.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
struct RMDIR3args;
EXTERN int rpc_nfs3_rmdir_async(struct rpc_context *rpc, rpc_cb cb, struct RMDIR3args *args, void *private_data);
EXTERN int rpc_nfs_rmdir_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, char *dir, void *private_data);
/*
* Call NFS3/CREATE
* Function returns
* 0 : The call was initiated. The callback will be invoked when the call completes.
* <0 : An error occured when trying to set up the call. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the nfs daemon.
* data is CREATE3res *
* RPC_STATUS_ERROR : An error occured when trying to contact the nfs daemon.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
struct CREATE3args;
EXTERN int rpc_nfs3_create_async(struct rpc_context *rpc, rpc_cb cb, struct CREATE3args *args, void *private_data);
EXTERN int rpc_nfs_create_async(struct rpc_context *rpc, rpc_cb cb, struct CREATE3args *args, void *private_data);
/*
* Call NFS3/MKNOD
* Function returns
* 0 : The call was initiated. The callback will be invoked when the call completes.
* <0 : An error occured when trying to set up the call. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the nfs daemon.
* data is MKNOD3res *
* RPC_STATUS_ERROR : An error occured when trying to contact the nfs daemon.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
struct MKNOD3args;
EXTERN int rpc_nfs3_mknod_async(struct rpc_context *rpc, rpc_cb cb, struct MKNOD3args *args, void *private_data);
EXTERN int rpc_nfs_mknod_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, char *file, int mode, int major, int minor, void *private_data);
/*
* Call NFS3/REMOVE
* Function returns
* 0 : The call was initiated. The callback will be invoked when the call completes.
* <0 : An error occured when trying to set up the call. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the nfs daemon.
* data is REMOVE3res *
* RPC_STATUS_ERROR : An error occured when trying to contact the nfs daemon.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
struct REMOVE3args;
EXTERN int rpc_nfs3_remove_async(struct rpc_context *rpc, rpc_cb cb, struct REMOVE3args *args, void *private_data);
EXTERN int rpc_nfs_remove_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, char *name, void *private_data);
/*
* Call NFS3/READDIR
* Function returns
* 0 : The call was initiated. The callback will be invoked when the call completes.
* <0 : An error occured when trying to set up the call. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the nfs daemon.
* data is READDIR3res *
* RPC_STATUS_ERROR : An error occured when trying to contact the nfs daemon.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
struct READDIR3args;
EXTERN int rpc_nfs3_readdir_async(struct rpc_context *rpc, rpc_cb cb, struct READDIR3args *args, void *private_data);
EXTERN int rpc_nfs_readdir_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, uint64_t cookie, char *cookieverf, int count, void *private_data);
/*
* Call NFS3/READDIRPLUS
* Function returns
* 0 : The call was initiated. The callback will be invoked when the call completes.
* <0 : An error occured when trying to set up the call. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the nfs daemon.
* data is READDIRPLUS3res *
* RPC_STATUS_ERROR : An error occured when trying to contact the nfs daemon.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
struct READDIRPLUS3args;
EXTERN int rpc_nfs3_readdirplus_async(struct rpc_context *rpc, rpc_cb cb, struct READDIRPLUS3args *args, void *private_data);
EXTERN int rpc_nfs_readdirplus_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, uint64_t cookie, char *cookieverf, int count, void *private_data);
/*
* Call NFS3/FSSTAT
* Function returns
* 0 : The call was initiated. The callback will be invoked when the call completes.
* <0 : An error occured when trying to set up the call. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the nfs daemon.
* data is FSSTAT3res
* RPC_STATUS_ERROR : An error occured when trying to contact the nfs daemon.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
struct FSSTAT3args;
EXTERN int rpc_nfs3_fsstat_async(struct rpc_context *rpc, rpc_cb cb, struct FSSTAT3args *args, void *private_data);
EXTERN int rpc_nfs_fsstat_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, void *private_data);
/*
* Call NFS3/FSINFO
* Function returns
* 0 : The call was initiated. The callback will be invoked when the call completes.
* <0 : An error occured when trying to set up the call. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the nfs daemon.
* data is FSINFO3res
* RPC_STATUS_ERROR : An error occured when trying to contact the nfs daemon.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
struct FSINFO3args;
EXTERN int rpc_nfs3_fsinfo_async(struct rpc_context *rpc, rpc_cb cb, struct FSINFO3args *args, void *private_data);
EXTERN int rpc_nfs_fsinfo_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, void *private_data);
/*
* Call NFS3/READLINK
* Function returns
* 0 : The call was initiated. The callback will be invoked when the call completes.
* <0 : An error occured when trying to set up the call. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the nfs daemon.
* data is READLINK3res *
* RPC_STATUS_ERROR : An error occured when trying to contact the nfs daemon.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
struct READLINK3args;
EXTERN int rpc_nfs3_readlink_async(struct rpc_context *rpc, rpc_cb cb, struct READLINK3args *args, void *private_data);
EXTERN int rpc_nfs_readlink_async(struct rpc_context *rpc, rpc_cb cb, struct READLINK3args *args, void *private_data);
/*
* Call NFS3/SYMLINK
* Function returns
* 0 : The call was initiated. The callback will be invoked when the call completes.
* <0 : An error occured when trying to set up the call. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the nfs daemon.
* data is SYMLINK3res *
* RPC_STATUS_ERROR : An error occured when trying to contact the nfs daemon.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
struct SYMLINK3args;
EXTERN int rpc_nfs3_symlink_async(struct rpc_context *rpc, rpc_cb cb, struct SYMLINK3args *args, void *private_data);
EXTERN int rpc_nfs_symlink_async(struct rpc_context *rpc, rpc_cb cb, struct SYMLINK3args *args, void *private_data);
/*
* Call NFS3/RENAME
* Function returns
* 0 : The call was initiated. The callback will be invoked when the call completes.
* <0 : An error occured when trying to set up the call. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the nfs daemon.
* data is RENAME3res *
* RPC_STATUS_ERROR : An error occured when trying to contact the nfs daemon.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
struct RENAME3args;
EXTERN int rpc_nfs3_rename_async(struct rpc_context *rpc, rpc_cb cb, struct RENAME3args *args, void *private_data);
EXTERN int rpc_nfs_rename_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *olddir, char *oldname, struct nfs_fh3 *newdir, char *newname, void *private_data);
/*
* Call NFS3/LINK
* Function returns
* 0 : The call was initiated. The callback will be invoked when the call completes.
* <0 : An error occured when trying to set up the call. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the nfs daemon.
* data is LINK3res *
* RPC_STATUS_ERROR : An error occured when trying to contact the nfs daemon.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
struct LINK3args;
EXTERN int rpc_nfs3_link_async(struct rpc_context *rpc, rpc_cb cb, struct LINK3args *args, void *private_data);
EXTERN int rpc_nfs_link_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *file, struct nfs_fh3 *newdir, char *newname, void *private_data);
/*
* NFS v2 FUNCTIONS
*/
/*
* Call NFS2/NULL
* Function returns
* 0 : The call was initiated. The callback will be invoked when the call completes.
* <0 : An error occured when trying to set up the call. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the nfs daemon.
* data is NULL.
* RPC_STATUS_ERROR : An error occured when trying to contact the nfs daemon.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
EXTERN int rpc_nfs2_null_async(struct rpc_context *rpc, rpc_cb cb, void *private_data);
/*
* Call NFS2/GETATTR
* Function returns
* 0 : The call was initiated. The callback will be invoked when the call completes.
* <0 : An error occured when trying to set up the call. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the nfs daemon.
* data is GETATTR2res
* RPC_STATUS_ERROR : An error occured when trying to contact the nfs daemon.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
struct GETATTR2args;
EXTERN int rpc_nfs2_getattr_async(struct rpc_context *rpc, rpc_cb cb, struct GETATTR2args *args, void *private_data);
/*
* Call NFS2/SETATTR
* Function returns
* 0 : The call was initiated. The callback will be invoked when the call completes.
* <0 : An error occured when trying to set up the call. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the nfs daemon.
* data is SETATTR2res *
* RPC_STATUS_ERROR : An error occured when trying to contact the nfs daemon.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
struct SETATTR2args;
EXTERN int rpc_nfs2_setattr_async(struct rpc_context *rpc, rpc_cb cb, struct SETATTR2args *args, void *private_data);
/*
* Call NFS2/LOOKUP
* Function returns
* 0 : The call was initiated. The callback will be invoked when the call completes.
* <0 : An error occured when trying to set up the call. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the nfs daemon.
* data is LOOKUP2res
* RPC_STATUS_ERROR : An error occured when trying to contact the nfs daemon.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
struct LOOKUP2args;
EXTERN int rpc_nfs2_lookup_async(struct rpc_context *rpc, rpc_cb cb, struct LOOKUP2args *args, void *private_data);
/*
* Call NFS2/READLINK
* Function returns
* 0 : The call was initiated. The callback will be invoked when the call completes.
* <0 : An error occured when trying to set up the call. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the nfs daemon.
* data is READLINK2res *
* RPC_STATUS_ERROR : An error occured when trying to contact the nfs daemon.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
struct READLINK2args;
EXTERN int rpc_nfs32_readlink_async(struct rpc_context *rpc, rpc_cb cb, struct READLINK2args *args, void *private_data);
/*
* Call NFS2/READ
* Function returns
* 0 : The call was initiated. The callback will be invoked when the call completes.
* <0 : An error occured when trying to set up the call. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the nfs daemon.
* data is READ2res
* RPC_STATUS_ERROR : An error occured when trying to contact the nfs daemon.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
struct READ2args;
EXTERN int rpc_nfs2_read_async(struct rpc_context *rpc, rpc_cb cb, struct READ2args *args, void *private_data);
/*
* Call NFS2/WRITE
* Function returns
* 0 : The call was initiated. The callback will be invoked when the call completes.
* <0 : An error occured when trying to set up the call. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the nfs daemon.
* data is WRITE2res *
* RPC_STATUS_ERROR : An error occured when trying to contact the nfs daemon.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
struct WRITE2args;
EXTERN int rpc_nfs2_write_async(struct rpc_context *rpc, rpc_cb cb, struct WRITE2args *args, void *private_data);
/*
* Call NFS2/CREATE
* Function returns
* 0 : The call was initiated. The callback will be invoked when the call completes.
* <0 : An error occured when trying to set up the call. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the nfs daemon.
* data is CREATE2res *
* RPC_STATUS_ERROR : An error occured when trying to contact the nfs daemon.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
struct CREATE2args;
EXTERN int rpc_nfs2_create_async(struct rpc_context *rpc, rpc_cb cb, struct CREATE2args *args, void *private_data);
/*
* Call NFS2/REMOVE
* Function returns
* 0 : The call was initiated. The callback will be invoked when the call completes.
* <0 : An error occured when trying to set up the call. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the nfs daemon.
* data is REMOVE2res *
* RPC_STATUS_ERROR : An error occured when trying to contact the nfs daemon.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
struct REMOVE2args;
EXTERN int rpc_nfs2_remove_async(struct rpc_context *rpc, rpc_cb cb, struct REMOVE2args *args, void *private_data);
/*
* Call NFS2/RENAME
* Function returns
* 0 : The call was initiated. The callback will be invoked when the call completes.
* <0 : An error occured when trying to set up the call. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the nfs daemon.
* data is RENAME2res *
* RPC_STATUS_ERROR : An error occured when trying to contact the nfs daemon.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
struct RENAME2args;
EXTERN int rpc_nfs2_rename_async(struct rpc_context *rpc, rpc_cb cb, struct RENAME2args *args, void *private_data);
/*
* Call NFS2/LINK
* Function returns
* 0 : The call was initiated. The callback will be invoked when the call completes.
* <0 : An error occured when trying to set up the call. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the nfs daemon.
* data is LINK2res *
* RPC_STATUS_ERROR : An error occured when trying to contact the nfs daemon.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
struct LINK2args;
EXTERN int rpc_nfs2_link_async(struct rpc_context *rpc, rpc_cb cb, struct LINK2args *args, void *private_data);
/*
* Call NFS2/SYMLINK
* Function returns
* 0 : The call was initiated. The callback will be invoked when the call completes.
* <0 : An error occured when trying to set up the call. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the nfs daemon.
* data is SYMLINK2res *
* RPC_STATUS_ERROR : An error occured when trying to contact the nfs daemon.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
struct SYMLINK2args;
EXTERN int rpc_nfs2_symlink_async(struct rpc_context *rpc, rpc_cb cb, struct SYMLINK2args *args, void *private_data);
/*
* Call NFS2/MKDIR
* Function returns
* 0 : The call was initiated. The callback will be invoked when the call completes.
* <0 : An error occured when trying to set up the call. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the nfs daemon.
* data is MKDIR2res *
* RPC_STATUS_ERROR : An error occured when trying to contact the nfs daemon.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
struct MKDIR2args;
EXTERN int rpc_nfs2_mkdir_async(struct rpc_context *rpc, rpc_cb cb, struct MKDIR2args *args, void *private_data);
/*
* Call NFS2/RMDIR
* Function returns
* 0 : The call was initiated. The callback will be invoked when the call completes.
* <0 : An error occured when trying to set up the call. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the nfs daemon.
* data is RMDIR2res *
* RPC_STATUS_ERROR : An error occured when trying to contact the nfs daemon.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
struct RMDIR2args;
EXTERN int rpc_nfs2_rmdir_async(struct rpc_context *rpc, rpc_cb cb, struct RMDIR2args *args, void *private_data);
/*
* Call NFS2/READDIR
* Function returns
* 0 : The call was initiated. The callback will be invoked when the call completes.
* <0 : An error occured when trying to set up the call. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the nfs daemon.
* data is READDIR2res *
* RPC_STATUS_ERROR : An error occured when trying to contact the nfs daemon.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
struct READDIR2args;
EXTERN int rpc_nfs2_readdir_async(struct rpc_context *rpc, rpc_cb cb, struct READDIR2args *args, void *private_data);
/*
* Call NFS2/STATFS
* Function returns
* 0 : The call was initiated. The callback will be invoked when the call completes.
* <0 : An error occured when trying to set up the call. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the nfs daemon.
* data is STATFS2res *
* RPC_STATUS_ERROR : An error occured when trying to contact the nfs daemon.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
struct STATFS2args;
EXTERN int rpc_nfs2_statfs_async(struct rpc_context *rpc, rpc_cb cb, struct STATFS2args *args, void *private_data);
/*
* RQUOTA FUNCTIONS
*/
char *rquotastat_to_str(int error);
int rquotastat_to_errno(int error);
/*
* Call RQUOTA1/NULL
* Function returns
* 0 : The call was initiated. The callback will be invoked when the call completes.
* <0 : An error occured when trying to set up the call. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the rquota daemon.
* data is NULL.
* RPC_STATUS_ERROR : An error occured when trying to contact the rquota daemon.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
EXTERN int rpc_rquota1_null_async(struct rpc_context *rpc, rpc_cb cb, void *private_data);
/*
* Call RQUOTA1/GETQUOTA
* Function returns
* 0 : The call was initiated. The callback will be invoked when the call completes.
* <0 : An error occured when trying to set up the call. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the rquota daemon.
* data is a RQUOTA1res structure.
* RPC_STATUS_ERROR : An error occured when trying to contact the rquota daemon.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
EXTERN int rpc_rquota1_getquota_async(struct rpc_context *rpc, rpc_cb cb, char *exportname, int uid, void *private_data);
/*
* Call RQUOTA1/GETACTIVEQUOTA
* Function returns
* 0 : The call was initiated. The callback will be invoked when the call completes.
* <0 : An error occured when trying to set up the call. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the rquota daemon.
* data is a RQUOTA1res structure.
* RPC_STATUS_ERROR : An error occured when trying to contact the rquota daemon.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
EXTERN int rpc_rquota1_getactivequota_async(struct rpc_context *rpc, rpc_cb cb, char *exportname, int uid, void *private_data);
/*
* Call RQUOTA2/NULL
* Function returns
* 0 : The call was initiated. The callback will be invoked when the call completes.
* <0 : An error occured when trying to set up the call. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the rquota daemon.
* data is NULL.
* RPC_STATUS_ERROR : An error occured when trying to contact the rquota daemon.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
int rpc_rquota2_null_async(struct rpc_context *rpc, rpc_cb cb, void *private_data);
/*
* Call RQUOTA2/GETQUOTA
* Function returns
* 0 : The call was initiated. The callback will be invoked when the call completes.
* <0 : An error occured when trying to set up the call. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the rquota daemon.
* data is a RQUOTA1res structure.
* RPC_STATUS_ERROR : An error occured when trying to contact the rquota daemon.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
int rpc_rquota2_getquota_async(struct rpc_context *rpc, rpc_cb cb, char *exportname, int type, int uid, void *private_data);
/*
* Call RQUOTA2/GETACTIVEQUOTA
* Function returns
* 0 : The call was initiated. The callback will be invoked when the call completes.
* <0 : An error occured when trying to set up the call. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the rquota daemon.
* data is a RQUOTA1res structure.
* RPC_STATUS_ERROR : An error occured when trying to contact the rquota daemon.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
int rpc_rquota2_getactivequota_async(struct rpc_context *rpc, rpc_cb cb, char *exportname, int type, int uid, void *private_data);
/*
* NFSACL functions
*/
/*
* Call NFSACL/NULL
* Call the NULL procedure for the NFSACL
*
* Function returns
* 0 : The call was initiated. The callback will be invoked when the call completes.
* <0 : An error occured when trying to set up the call. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the rquota daemon.
* data is NULL
* RPC_STATUS_ERROR : An error occured when trying to contact the rquota daemon.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
EXTERN int rpc_nfsacl_null_async(struct rpc_context *rpc, rpc_cb cb, void *private_data);
/*
* Call NFSACL/GETACL
*
* Function returns
* 0 : The call was initiated. The callback will be invoked when the call completes.
* <0 : An error occured when trying to set up the call. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the nfs daemon.
* data is a GETACL3res pointer
* RPC_STATUS_ERROR : An error occured when trying to contact the nfs daemon.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
struct GETACL3args;
EXTERN int rpc_nfsacl_getacl_async(struct rpc_context *rpc, rpc_cb cb, struct GETACL3args *args, void *private_data);
/*
* Call NFSACL/SETACL
*
* Function returns
* 0 : The call was initiated. The callback will be invoked when the call completes.
* <0 : An error occured when trying to set up the call. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the nfs daemon.
* data is a SETACL3res pointer
* RPC_STATUS_ERROR : An error occured when trying to contact the nfs daemon.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
struct SETACL3args;
EXTERN int rpc_nfsacl_setacl_async(struct rpc_context *rpc, rpc_cb cb, struct SETACL3args *args, void *private_data);
/*
* NLM functions
*/
char *nlmstat4_to_str(int stat);
/*
* Call NLM/NULL
* Call the NULL procedure for the NLM protocol
*
* Function returns
* 0 : The call was initiated. The callback will be invoked when the call completes.
* <0 : An error occured when trying to set up the call. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the nlm daemon.
* data is NULL
* RPC_STATUS_ERROR : An error occured when trying to contact the nlm daemon.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
EXTERN int rpc_nlm4_null_async(struct rpc_context *rpc, rpc_cb cb, void *private_data);
/*
* Call NLM/TEST
* Call the TEST procedure for the NLM protocol
*
* Function returns
* 0 : The call was initiated. The callback will be invoked when the call completes.
* <0 : An error occured when trying to set up the call. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the nlm daemon.
* data is NLM4_TESTres
* RPC_STATUS_ERROR : An error occured when trying to contact the nlm daemon.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
struct NLM4_TESTargs;
EXTERN int rpc_nlm4_test_async(struct rpc_context *rpc, rpc_cb cb, struct NLM4_TESTargs *args, void *private_data);
/*
* Call NLM/LOCK
* Call the LOCK procedure for the NLM protocol
*
* Function returns
* 0 : The call was initiated. The callback will be invoked when the call completes.
* <0 : An error occured when trying to set up the call. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the nlm daemon.
* data is NLM4_LOCKres
* RPC_STATUS_ERROR : An error occured when trying to contact the nlm daemon.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
struct NLM4_LOCKargs;
EXTERN int rpc_nlm4_lock_async(struct rpc_context *rpc, rpc_cb cb, struct NLM4_LOCKargs *args, void *private_data);
/*
* Call NLM/CANCEL
* Call the CANCEL procedure for the NLM protocol
*
* Function returns
* 0 : The call was initiated. The callback will be invoked when the call completes.
* <0 : An error occured when trying to set up the call. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the nlm daemon.
* data is NLM4_CANCres
* RPC_STATUS_ERROR : An error occured when trying to contact the nlm daemon.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
struct NLM4_CANCargs;
EXTERN int rpc_nlm4_cancel_async(struct rpc_context *rpc, rpc_cb cb, struct NLM4_CANCargs *args, void *private_data);
/*
* Call NLM/UNLOCK
* Call the UNLOCK procedure for the NLM protocol
*
* Function returns
* 0 : The call was initiated. The callback will be invoked when the call completes.
* <0 : An error occured when trying to set up the call. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the nlm daemon.
* data is NLM4_UNLOCKres
* RPC_STATUS_ERROR : An error occured when trying to contact the nlm daemon.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
struct NLM4_UNLOCKargs;
EXTERN int rpc_nlm4_unlock_async(struct rpc_context *rpc, rpc_cb cb, struct NLM4_UNLOCKargs *args, void *private_data);
/*
* NSM functions
*/
char *nsmstat1_to_str(int stat);
/*
* Call NSM/NULL
* Call the NULL procedure for the NSM protocol
*
* Function returns
* 0 : The call was initiated. The callback will be invoked when the call completes.
* <0 : An error occured when trying to set up the call. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the nsm daemon.
* data is NULL
* RPC_STATUS_ERROR : An error occured when trying to contact the nsm daemon.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
EXTERN int rpc_nsm1_null_async(struct rpc_context *rpc, rpc_cb cb, void *private_data);
/*
* Call NSM/STAT
* Call the STAT procedure for the NSM protocol
*
* Function returns
* 0 : The call was initiated. The callback will be invoked when the call completes.
* <0 : An error occured when trying to set up the call. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the nsm daemon.
* data is NSM1_STATres
* RPC_STATUS_ERROR : An error occured when trying to contact the nsm daemon.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
struct NSM1_STATargs;
EXTERN int rpc_nsm1_stat_async(struct rpc_context *rpc, rpc_cb cb, struct NSM1_STATargs *args, void *private_data);
/*
* Call NSM/MON
* Call the MON procedure for the NSM protocol
*
* Function returns
* 0 : The call was initiated. The callback will be invoked when the call completes.
* <0 : An error occured when trying to set up the call. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the nsm daemon.
* data is NSM1_MONres
* RPC_STATUS_ERROR : An error occured when trying to contact the nsm daemon.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
struct NSM1_MONargs;
EXTERN int rpc_nsm1_mon_async(struct rpc_context *rpc, rpc_cb cb, struct NSM1_MONargs *args, void *private_data);
/*
* Call NSM/UNMON
* Call the UNMON procedure for the NSM protocol
*
* Function returns
* 0 : The call was initiated. The callback will be invoked when the call completes.
* <0 : An error occured when trying to set up the call. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the nsm daemon.
* data is NSM1_UNMONres
* RPC_STATUS_ERROR : An error occured when trying to contact the nsm daemon.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
struct NSM1_UNMONargs;
EXTERN int rpc_nsm1_unmon_async(struct rpc_context *rpc, rpc_cb cb, struct NSM1_UNMONargs *args, void *private_data);
/*
* Call NSM/UNMONALL
* Call the UNMONALL procedure for the NSM protocol
*
* Function returns
* 0 : The call was initiated. The callback will be invoked when the call completes.
* <0 : An error occured when trying to set up the call. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the nsm daemon.
* data is NSM1_UNMONALLres
* RPC_STATUS_ERROR : An error occured when trying to contact the nsm daemon.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
struct NSM1_UNMONALLargs;
EXTERN int rpc_nsm1_unmonall_async(struct rpc_context *rpc, rpc_cb cb, struct NSM1_UNMONALLargs *args, void *private_data);
/*
* Call NSM/SIMUCRASH
* Call the SIMUCRASH procedure for the NSM protocol
*
* Function returns
* 0 : The call was initiated. The callback will be invoked when the call completes.
* <0 : An error occured when trying to set up the call. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the nsm daemon.
* data is NULL
* RPC_STATUS_ERROR : An error occured when trying to contact the nsm daemon.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
EXTERN int rpc_nsm1_simucrash_async(struct rpc_context *rpc, rpc_cb cb, void *private_data);
/*
* Call NSM/NOTIFY
* Call the NOTIFY procedure for the NSM protocol
*
* Function returns
* 0 : The call was initiated. The callback will be invoked when the call completes.
* <0 : An error occured when trying to set up the call. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the nsm daemon.
* data is NULL
* RPC_STATUS_ERROR : An error occured when trying to contact the nsm daemon.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
struct NSM1_NOTIFYargs;
EXTERN int rpc_nsm1_notify_async(struct rpc_context *rpc, rpc_cb cb, struct NSM1_NOTIFYargs *args, void *private_data);
/*
* Call NFS4/NULL
* Function returns
* 0 : The call was initiated. The callback will be invoked when the call completes.
* <0 : An error occured when trying to set up the call. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the nfs daemon.
* data is NULL.
* RPC_STATUS_ERROR : An error occured when trying to contact the nfs daemon.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
EXTERN int rpc_nfs4_null_async(struct rpc_context *rpc, rpc_cb cb, void *private_data);
/*
* Call NFS4/COMPOUND
* Function returns
* 0 : The call was initiated. The callback will be invoked when the call completes.
* <0 : An error occured when trying to set up the call. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the nfs daemon.
* data is COMPOUND4res
* RPC_STATUS_ERROR : An error occured when trying to contact the nfs daemon.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
struct COMPOUND4args;
EXTERN int rpc_nfs4_compound_async(struct rpc_context *rpc, rpc_cb cb, struct COMPOUND4args *args, void *private_data);
/*
* Call /NULL
* Function returns
* 0 : The connection was initiated. Once the connection establish finishes, the callback will be invoked.
* <0 : An error occured when trying to set up the connection. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* RPC_STATUS_SUCCESS : We got a successful response from the portmapper daemon.
* data is NULL.
* RPC_STATUS_ERROR : An error occured when trying to contact the portmapper.
* data is the error string.
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
EXTERN int
rpc_null_async(struct rpc_context *rpc, int program, int version, rpc_cb cb, void *private_data);
#ifdef __cplusplus
}
#endif
#endif
libnfs-libnfs-2.0.0/include/nfsc/libnfs-zdr.h 0000664 0000000 0000000 00000015056 13121032772 0021045 0 ustar 00root root 0000000 0000000 /*
Copyright (C) 2012 by Ronnie Sahlberg
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, see .
*/
/*
* This file contains definitions for the built in ZDR implementation.
* This is a very limited ZDR subset that can only marshal to/from a momory buffer,
* i.e. zdrmem_create() buffers.
* It aims to be compatible with normal rpcgen generated functions.
*/
/************************************************************
* Definitions copied from RFC 5531
* and slightly modified.
************************************************************/
#ifndef _LIBNFS_ZDR_H_
#define _LIBNFS_ZDR_H_
#ifdef WIN32
#ifndef CADDR_T_DEFINED
#define CADDR_T_DEFINED
typedef char *caddr_t;
#endif
#endif
#include
#include
#include
#include
#ifdef __cplusplus
extern "C" {
#endif
#define _RPC_RPC_H 1
#define _RPC_ZDR_H 1
#define _RPC_AUTH_H 1
/* we dont need these */
typedef void CLIENT;
struct svc_req {
int _dummy_;
};
typedef void SVCXPRT;
#define ZDR_INLINE(...) NULL
#define IZDR_PUT_U_LONG(...) assert(0)
#define IZDR_GET_U_LONG(...) (assert(0), 0)
#define IZDR_PUT_LONG(...) assert(0)
#define IZDR_GET_LONG(...) (assert(0), 0)
#define IZDR_PUT_BOOL(...) assert(0)
#define IZDR_GET_BOOL(...) (assert(0), 0)
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
enum zdr_op {
ZDR_ENCODE = 0,
ZDR_DECODE = 1
};
struct zdr_mem;
struct ZDR {
enum zdr_op x_op;
caddr_t buf;
int size;
int pos;
struct zdr_mem *mem;
};
typedef struct ZDR ZDR;
typedef uint32_t u_int;
typedef uint32_t enum_t;
typedef uint32_t bool_t;
typedef uint32_t (*zdrproc_t) (ZDR *, void *,...);
#define AUTH_NONE 0
#define AUTH_NULL 0
#define AUTH_UNIX 1
struct opaque_auth {
uint32_t oa_flavor;
caddr_t oa_base;
uint32_t oa_length;
};
extern struct opaque_auth _null_auth;
struct AUTH {
struct opaque_auth ah_cred;
struct opaque_auth ah_verf;
caddr_t ah_private;
};
#define RPC_MSG_VERSION 2
enum msg_type {
CALL = 0,
REPLY = 1
};
enum reply_stat {
MSG_ACCEPTED=0,
MSG_DENIED=1
};
enum accept_stat {
SUCCESS = 0,
PROG_UNAVAIL = 1,
PROG_MISMATCH = 2,
PROC_UNAVAIL = 3,
GARBAGE_ARGS = 4,
SYSTEM_ERR = 5
};
enum reject_stat {
RPC_MISMATCH = 0,
AUTH_ERROR = 1
};
enum auth_stat {
AUTH_OK=0,
/*
* failed at remote end
*/
AUTH_BADCRED = 1, /* bogus credentials (seal broken) */
AUTH_REJECTEDCRED = 2, /* client should begin new session */
AUTH_BADVERF = 3, /* bogus verifier (seal broken) */
AUTH_REJECTEDVERF = 4, /* verifier expired or was replayed */
AUTH_TOOWEAK = 5, /* rejected due to security reasons */
/*
* failed locally
*/
AUTH_INVALIDRESP = 6, /* bogus response verifier */
AUTH_FAILED = 7 /* some unknown reason */
};
struct call_body {
uint32_t rpcvers;
uint32_t prog;
uint32_t vers;
uint32_t proc;
struct opaque_auth cred;
struct opaque_auth verf;
void *args;
};
struct accepted_reply {
struct opaque_auth verf;
uint32_t stat;
union {
struct {
caddr_t where;
zdrproc_t proc;
} results;
struct {
uint32_t low;
uint32_t high;
} mismatch_info;
} reply_data;
};
struct rejected_reply {
enum reject_stat stat;
union {
struct {
uint32_t low;
uint32_t high;
} mismatch_info;
enum auth_stat stat;
} reject_data;
};
struct reply_body {
uint32_t stat;
union {
struct accepted_reply areply;
struct rejected_reply rreply;
} reply;
};
struct rpc_msg {
uint32_t xid;
uint32_t direction;
union {
struct call_body cbody;
struct reply_body rbody;
} body;
};
#define zdrmem_create libnfs_zdrmem_create
void libnfs_zdrmem_create(ZDR *zdrs, const caddr_t addr, uint32_t size, enum zdr_op xop);
#define zdr_destroy libnfs_zdr_destroy
void libnfs_zdr_destroy(ZDR *zdrs);
#define zdr_bytes libnfs_zdr_bytes
bool_t libnfs_zdr_bytes(ZDR *zdrs, char **bufp, uint32_t *size, uint32_t maxsize);
#define zdr_u_int libnfs_zdr_u_int
#define zdr_uint32_t libnfs_zdr_u_int
bool_t libnfs_zdr_u_int(ZDR *zdrs, uint32_t *u);
#define zdr_int libnfs_zdr_int
#define zdr_int32_t libnfs_zdr_int
bool_t libnfs_zdr_int(ZDR *zdrs, int32_t *i);
#define zdr_uint64_t libnfs_zdr_uint64_t
bool_t libnfs_zdr_uint64_t(ZDR *zdrs, uint64_t *u);
#define zdr_int64_t libnfs_zdr_int64_t
bool_t libnfs_zdr_int64_t(ZDR *zdrs, int64_t *i);
#define zdr_enum libnfs_zdr_enum
bool_t libnfs_zdr_enum(ZDR *zdrs, enum_t *e);
#define zdr_bool libnfs_zdr_bool
bool_t libnfs_zdr_bool(ZDR *zdrs, bool_t *b);
#define zdr_void libnfs_zdr_void
bool_t libnfs_zdr_void(ZDR *zdrs, void *);
#define zdr_pointer libnfs_zdr_pointer
bool_t libnfs_zdr_pointer(ZDR *zdrs, char **objp, uint32_t size, zdrproc_t proc);
#define zdr_opaque libnfs_zdr_opaque
bool_t libnfs_zdr_opaque(ZDR *zdrs, char *objp, uint32_t size);
#define zdr_string libnfs_zdr_string
bool_t libnfs_zdr_string(ZDR *zdrs, char **strp, uint32_t maxsize);
#define zdr_array libnfs_zdr_array
bool_t libnfs_zdr_array(ZDR *zdrs, char **arrp, uint32_t *size, uint32_t maxsize, uint32_t elsize, zdrproc_t proc);
#define zdr_setpos libnfs_zdr_setpos
bool_t libnfs_zdr_setpos(ZDR *zdrs, uint32_t pos);
#define zdr_getpos libnfs_zdr_getpos
uint32_t libnfs_zdr_getpos(ZDR *zdrs);
#define zdr_free libnfs_zdr_free
void libnfs_zdr_free(zdrproc_t proc, char *objp);
struct rpc_context;
#define zdr_callmsg libnfs_zdr_callmsg
bool_t libnfs_zdr_callmsg(struct rpc_context *rpc, ZDR *zdrs, struct rpc_msg *msg);
#define zdr_replymsg libnfs_zdr_replymsg
bool_t libnfs_zdr_replymsg(struct rpc_context *rpc, ZDR *zdrs, struct rpc_msg *msg);
#define authnone_create libnfs_authnone_create
struct AUTH *libnfs_authnone_create(void);
#define authunix_create libnfs_authunix_create
struct AUTH *libnfs_authunix_create(const char *host, uint32_t uid, uint32_t gid, uint32_t len, uint32_t *groups);
#define authunix_create_default libnfs_authunix_create_default
struct AUTH *libnfs_authunix_create_default(void);
#define auth_destroy libnfs_auth_destroy
void libnfs_auth_destroy(struct AUTH *auth);
#ifdef __cplusplus
}
#endif
#endif
libnfs-libnfs-2.0.0/include/nfsc/libnfs.h 0000775 0000000 0000000 00000133767 13121032772 0020265 0 ustar 00root root 0000000 0000000 /*
Copyright (C) 2010 by Ronnie Sahlberg
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, see .
*/
/*
* This is the highlevel interface to access NFS resources using a posix-like interface
*/
#ifndef _LIBNFS_H_
#define _LIBNFS_H_
#include
#if defined(__ANDROID__) || defined(AROS) \
|| ( defined(__APPLE__) && defined(__MACH__) )
#include
#else
#include
#endif
#ifdef __cplusplus
extern "C" {
#endif
#define LIBNFS_FEATURE_READAHEAD
#define LIBNFS_FEATURE_PAGECACHE
#define LIBNFS_FEATURE_DEBUG
#define NFS_BLKSIZE 4096
#define NFS_PAGECACHE_DEFAULT_TTL 5
struct nfs_context;
struct rpc_context;
struct nfs_url {
char *server;
char *path;
char *file;
};
#if defined(WIN32)
#define EXTERN __declspec( dllexport )
#else
#define EXTERN
#endif
#ifdef WIN32
#ifdef HAVE_FUSE_H
#include
#else
struct statvfs {
uint32_t f_bsize;
uint32_t f_frsize;
uint64_t f_blocks;
uint64_t f_bfree;
uint64_t f_bavail;
uint32_t f_files;
uint32_t f_ffree;
uint32_t f_favail;
uint32_t f_fsid;
uint32_t f_flag;
uint32_t f_namemax;
};
#endif
#if !defined(__MINGW32__)
struct utimbuf {
time_t actime;
time_t modtime;
};
#endif
#define R_OK 4
#define W_OK 2
#define X_OK 1
#endif
/*
* Used for interfacing the async version of the api into an external
* eventsystem.
*
* nfs_get_fd() returns the file descriptor for the context we need to
* listen for events from.
*
* nfs_which_events() returns which events that we need to poll for.
* This is a combination of the POLLIN and POLLOUT flags.
*
* nfs_service() This function should be called once there are events triggered
* for the filedescriptor. This function takes POLLIN/POLLOUT/POLLHUP/POLLERR
* as arguments.
* This function returns 0 on success or -1 on error. If it returns -1 it
* means that the socket is in an unrecoverable error state (disconnected?)
* and that no further commands can be used.
* When this happens the application should destroy the now errored context
* re-create a new context and reconnect.
*
*/
EXTERN int nfs_get_fd(struct nfs_context *nfs);
EXTERN int nfs_which_events(struct nfs_context *nfs);
EXTERN int nfs_service(struct nfs_context *nfs, int revents);
/*
* Returns the number of commands in-flight. Can be used by the application
* to check if there are any more responses we are awaiting for the server
* or if the connection is completely idle.
*/
EXTERN int nfs_queue_length(struct nfs_context *nfs);
/*
* Used if you need different credentials than the default for the current user.
*/
struct AUTH;
EXTERN void nfs_set_auth(struct nfs_context *nfs, struct AUTH *auth);
/*
* Used if you need to bind to a specific interface.
* Only available on platforms that support SO_BINDTODEVICE.
*/
EXTERN void nfs_set_interface(struct nfs_context *nfs, const char *ifname);
/*
* When an operation failed, this function can extract a detailed error string.
*/
EXTERN char *nfs_get_error(struct nfs_context *nfs);
/*
* Callback for all ASYNC nfs functions
*/
typedef void (*nfs_cb)(int err, struct nfs_context *nfs, void *data, void *private_data);
/*
* Callback for all ASYNC rpc functions
*/
typedef void (*rpc_cb)(struct rpc_context *rpc, int status, void *data, void *private_data);
/*
* NFS CONTEXT.
*/
/*
* Create an NFS context.
* Function returns
* NULL : Failed to create a context.
* *nfs : A pointer to an nfs context.
*/
EXTERN struct nfs_context *nfs_init_context(void);
/*
* Destroy an nfs context.
*/
EXTERN void nfs_destroy_context(struct nfs_context *nfs);
/*
* URL parsing functions.
* These functions all parse a URL of the form
* nfs://server/path/file?argv=val[&arg=val]*
* and returns a nfs_url.
*
* Apart from parsing the URL the functions will also update
* the nfs context to reflect settings controlled via url arguments.
*
* Current URL arguments are :
* tcp-syncnt= : Number of SYNs to send during the session establish
* before failing setting up the TCP connection to the
* server.
* uid= : UID value to use when talking to the server.
* default is 65534 on Windows and getuid() on unixen.
* gid= : GID value to use when talking to the server.
* default is 65534 on Windows and getgid() on unixen.
* readahead= : Enable readahead for files and set the maximum amount
* of readahead to bytes.
* auto-traverse-mounts=<0|1>
* : Should libnfs try to traverse across nested mounts
* automatically or not. Default is 1 == enabled.
* dircache=<0|1> : Disable/enable directory caching. Enabled by default.
* autoreconnect=<-1|0|>=1>
* : Control the auto-reconnect behaviour to the NFS session.
* -1 : Try to reconnect forever on session failures.
* Just like normal NFS clients do.
* 0 : Disable auto-reconnect completely and immediately
* return a failure to the application.
* >=1 : Retry to connect back to the server this many
* times before failing and returing an error back
* to the application.
*/
/*
* Parse a complete NFS URL including, server, path and
* filename. Fail if any component is missing.
*/
EXTERN struct nfs_url *nfs_parse_url_full(struct nfs_context *nfs, const char *url);
/*
* Parse an NFS URL, but do not split path and file. File
* in the resulting struct remains NULL.
*/
EXTERN struct nfs_url *nfs_parse_url_dir(struct nfs_context *nfs, const char *url);
/*
* Parse an NFS URL, but do not fail if file, path or even server is missing.
* Check elements of the resulting struct for NULL.
*/
EXTERN struct nfs_url *nfs_parse_url_incomplete(struct nfs_context *nfs, const char *url);
/*
* Free the URL struct returned by the nfs_parse_url_* functions.
*/
EXTERN void nfs_destroy_url(struct nfs_url *url);
struct nfsfh;
/*
* Get the maximum supported READ3 size by the server
*/
EXTERN uint64_t nfs_get_readmax(struct nfs_context *nfs);
/*
* Get the maximum supported WRITE3 size by the server
*/
EXTERN uint64_t nfs_get_writemax(struct nfs_context *nfs);
/*
* MODIFY CONNECT PARAMETERS
*/
EXTERN void nfs_set_tcp_syncnt(struct nfs_context *nfs, int v);
EXTERN void nfs_set_uid(struct nfs_context *nfs, int uid);
EXTERN void nfs_set_gid(struct nfs_context *nfs, int gid);
EXTERN void nfs_set_pagecache(struct nfs_context *nfs, uint32_t v);
EXTERN void nfs_set_pagecache_ttl(struct nfs_context *nfs, uint32_t v);
EXTERN void nfs_set_readahead(struct nfs_context *nfs, uint32_t v);
EXTERN void nfs_set_debug(struct nfs_context *nfs, int level);
EXTERN void nfs_set_dircache(struct nfs_context *nfs, int enabled);
EXTERN void nfs_set_autoreconnect(struct nfs_context *nfs, int num_retries);
/*
* Invalidate the pagecache
*/
EXTERN void nfs_pagecache_invalidate(struct nfs_context *nfs, struct nfsfh *nfsfh);
/*
* MOUNT THE EXPORT
*/
/*
* Async nfs mount.
* Function returns
* 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
* <0 : An error occured when trying to set up the operation. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* 0 : Success.
* data is NULL
* -errno : An error occured.
* data is the error string.
*/
EXTERN int nfs_mount_async(struct nfs_context *nfs, const char *server, const char *exportname, nfs_cb cb, void *private_data);
/*
* Sync nfs mount.
* Function returns
* 0 : The operation was successful.
* -errno : The command failed.
*/
EXTERN int nfs_mount(struct nfs_context *nfs, const char *server, const char *exportname);
/*
* STAT()
*/
/*
* Async stat()
* Function returns
* 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
* <0 : An error occured when trying to set up the operation. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* 0 : Success.
* data is struct stat *
* -errno : An error occured.
* data is the error string.
*/
/* This function is deprecated. Use nfs_stat64_async() instead */
struct stat;
EXTERN int nfs_stat_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
/*
* Sync stat()
* Function returns
* 0 : The operation was successful.
* -errno : The command failed.
*/
/* This function is deprecated. Use nfs_stat64() instead */
#ifdef WIN32
EXTERN int nfs_stat(struct nfs_context *nfs, const char *path, struct __stat64 *st);
#else
EXTERN int nfs_stat(struct nfs_context *nfs, const char *path, struct stat *st);
#endif
/* nfs_stat64
* 64 bit version if stat. All fields are always 64bit.
* Use these functions instead of nfs_stat[_async](), especially if you
* have weird stat structures.
*/
/*
* STAT()
*/
struct nfs_stat_64 {
uint64_t nfs_dev;
uint64_t nfs_ino;
uint64_t nfs_mode;
uint64_t nfs_nlink;
uint64_t nfs_uid;
uint64_t nfs_gid;
uint64_t nfs_rdev;
uint64_t nfs_size;
uint64_t nfs_blksize;
uint64_t nfs_blocks;
uint64_t nfs_atime;
uint64_t nfs_mtime;
uint64_t nfs_ctime;
uint64_t nfs_atime_nsec;
uint64_t nfs_mtime_nsec;
uint64_t nfs_ctime_nsec;
uint64_t nfs_used;
};
/*
* Async stat()
* Function returns
* 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
* <0 : An error occured when trying to set up the operation. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* 0 : Success.
* data is struct nfs_stat_64 *
* -errno : An error occured.
* data is the error string.
*/
EXTERN int nfs_stat64_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
/*
* Sync stat()
* Function returns
* 0 : The operation was successful.
* -errno : The command failed.
*/
EXTERN int nfs_stat64(struct nfs_context *nfs, const char *path, struct nfs_stat_64 *st);
/*
* Async stat()
*
* Like stat except if the destination is a symbolic link, it acts on the
* symbolic link itself.
*
* Function returns
* 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
* <0 : An error occured when trying to set up the operation. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* 0 : Success.
* data is struct nfs_stat_64 *
* -errno : An error occured.
* data is the error string.
*/
EXTERN int nfs_lstat64_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
/*
* Sync stat()
*
* Like stat except if the destination is a symbolic link, it acts on the
* symbolic link itself.
*
* Function returns
* 0 : The operation was successful.
* -errno : The command failed.
*/
EXTERN int nfs_lstat64(struct nfs_context *nfs, const char *path, struct nfs_stat_64 *st);
/*
* FSTAT()
*/
/*
* Async fstat(nfsfh *)
* Function returns
* 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
* <0 : An error occured when trying to set up the operation. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* 0 : Success.
* data is struct stat *
* -errno : An error occured.
* data is the error string.
*/
/* This function is deprecated. Use nfs_fstat64_async() instead */
EXTERN int nfs_fstat_async(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_cb cb, void *private_data);
/*
* Sync fstat(nfsfh *)
* Function returns
* 0 : The operation was successful.
* -errno : The command failed.
*/
#ifdef WIN32
EXTERN int nfs_fstat(struct nfs_context *nfs, struct nfsfh *nfsfh, struct __stat64 *st);
#else
EXTERN int nfs_fstat(struct nfs_context *nfs, struct nfsfh *nfsfh, struct stat *st);
#endif
/* nfs_fstat64
* 64 bit version of fstat. All fields are always 64bit.
* Use these functions instead of nfs_fstat[_async](), especially if you
* have weird stat structures.
*/
/*
* FSTAT()
*/
/*
* Async fstat(nfsfh *)
* Function returns
* 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
* <0 : An error occured when trying to set up the operation. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* 0 : Success.
* data is struct stat *
* -errno : An error occured.
* data is the error string.
*/
EXTERN int nfs_fstat64_async(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_cb cb, void *private_data);
/*
* Sync fstat(nfsfh *)
* Function returns
* 0 : The operation was successful.
* -errno : The command failed.
*/
EXTERN int nfs_fstat64(struct nfs_context *nfs, struct nfsfh *nfsfh, struct nfs_stat_64 *st);
/*
* UMASK() never blocks, so no special aync/async versions are available
*/
/*
* Sync umask()
* Function returns the old mask.
*/
EXTERN uint16_t nfs_umask(struct nfs_context *nfs, uint16_t mask);
/*
* OPEN()
*/
/*
* Async open()
*
* mode is a combination of the flags :
* O_RDONLY, O_WRONLY, O_RDWR , O_SYNC, O_APPEND, O_TRUNC, O_NOFOLLOW
*
* Function returns
* 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
* <0 : An error occured when trying to set up the operation. The callback will not be invoked.
*
* Supported flags are
* O_NOFOLLOW
* O_APPEND
* O_RDONLY
* O_WRONLY
* O_RDWR
* O_SYNC
* O_TRUNC (Only valid with O_RDWR or O_WRONLY. Ignored otherwise.)
*
* When the callback is invoked, status indicates the result:
* 0 : Success.
* data is a struct *nfsfh;
* The nfsfh is close using nfs_close().
* -errno : An error occured.
* data is the error string.
*/
EXTERN int nfs_open_async(struct nfs_context *nfs, const char *path, int flags, nfs_cb cb, void *private_data);
/*
* Sync open()
* Function returns
* 0 : The operation was successful. *nfsfh is filled in.
* -errno : The command failed.
*/
EXTERN int nfs_open(struct nfs_context *nfs, const char *path, int flags, struct nfsfh **nfsfh);
/*
* CLOSE
*/
/*
* Async close(nfsfh)
*
* Function returns
* 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
* <0 : An error occured when trying to set up the operation. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* 0 : Success.
* data is NULL.
* -errno : An error occured.
* data is the error string.
*/
EXTERN int nfs_close_async(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_cb cb, void *private_data);
/*
* Sync close(nfsfh)
* Function returns
* 0 : The operation was successful.
* -errno : The command failed.
*/
EXTERN int nfs_close(struct nfs_context *nfs, struct nfsfh *nfsfh);
/*
* PREAD()
*/
/*
* Async pread()
*
* Function returns
* 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
* <0 : An error occured when trying to set up the operation. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* >=0 : Success.
* status is numer of bytes read.
* data is a pointer to the returned data.
* -errno : An error occured.
* data is the error string.
*/
EXTERN int nfs_pread_async(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t offset, uint64_t count, nfs_cb cb, void *private_data);
/*
* Sync pread()
* Function returns
* >=0 : numer of bytes read.
* -errno : An error occured.
*/
EXTERN int nfs_pread(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t offset, uint64_t count, void *buf);
/*
* READ()
*/
/*
* Async read()
*
* Function returns
* 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
* <0 : An error occured when trying to set up the operation. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* >=0 : Success.
* status is numer of bytes read.
* data is a pointer to the returned data.
* -errno : An error occured.
* data is the error string.
*/
EXTERN int nfs_read_async(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t count, nfs_cb cb, void *private_data);
/*
* Sync read()
* Function returns
* >=0 : numer of bytes read.
* -errno : An error occured.
*/
EXTERN int nfs_read(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t count, void *buf);
/*
* PWRITE()
*/
/*
* Async pwrite()
*
* Function returns
* 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
* <0 : An error occured when trying to set up the operation. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* >=0 : Success.
* status is numer of bytes written.
* -errno : An error occured.
* data is the error string.
*/
EXTERN int nfs_pwrite_async(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t offset, uint64_t count, const void *buf, nfs_cb cb, void *private_data);
/*
* Sync pwrite()
* Function returns
* >=0 : numer of bytes written.
* -errno : An error occured.
*/
EXTERN int nfs_pwrite(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t offset, uint64_t count, const void *buf);
/*
* WRITE()
*/
/*
* Async write()
*
* Function returns
* 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
* <0 : An error occured when trying to set up the operation. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* >=0 : Success.
* status is numer of bytes written.
* -errno : An error occured.
* data is the error string.
*/
EXTERN int nfs_write_async(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t count, const void *buf, nfs_cb cb, void *private_data);
/*
* Sync write()
* Function returns
* >=0 : numer of bytes written.
* -errno : An error occured.
*/
EXTERN int nfs_write(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t count, const void *buf);
/*
* LSEEK()
*/
/*
* Async lseek()
*
* Function returns
* 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
* <0 : An error occured when trying to set up the operation. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* >=0 : Success.
* data is uint64_t * for the current position.
* -errno : An error occured.
* data is the error string.
*/
EXTERN int nfs_lseek_async(struct nfs_context *nfs, struct nfsfh *nfsfh, int64_t offset, int whence, nfs_cb cb, void *private_data);
/*
* Sync lseek()
* Function returns
* >=0 : numer of bytes read.
* -errno : An error occured.
*/
EXTERN int nfs_lseek(struct nfs_context *nfs, struct nfsfh *nfsfh, int64_t offset, int whence, uint64_t *current_offset);
/*
* FSYNC()
*/
/*
* Async fsync()
*
* Function returns
* 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
* <0 : An error occured when trying to set up the operation. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* 0 : Success.
* -errno : An error occured.
* data is the error string.
*/
EXTERN int nfs_fsync_async(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_cb cb, void *private_data);
/*
* Sync fsync()
* Function returns
* 0 : Success
* -errno : An error occured.
*/
EXTERN int nfs_fsync(struct nfs_context *nfs, struct nfsfh *nfsfh);
/*
* TRUNCATE()
*/
/*
* Async truncate()
*
* Function returns
* 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
* <0 : An error occured when trying to set up the operation. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* 0 : Success.
* -errno : An error occured.
* data is the error string.
*/
EXTERN int nfs_truncate_async(struct nfs_context *nfs, const char *path, uint64_t length, nfs_cb cb, void *private_data);
/*
* Sync truncate()
* Function returns
* 0 : Success
* -errno : An error occured.
*/
EXTERN int nfs_truncate(struct nfs_context *nfs, const char *path, uint64_t length);
/*
* FTRUNCATE()
*/
/*
* Async ftruncate()
*
* Function returns
* 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
* <0 : An error occured when trying to set up the operation. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* 0 : Success.
* -errno : An error occured.
* data is the error string.
*/
EXTERN int nfs_ftruncate_async(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t length, nfs_cb cb, void *private_data);
/*
* Sync ftruncate()
* Function returns
* 0 : Success
* -errno : An error occured.
*/
EXTERN int nfs_ftruncate(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t length);
/*
* MKDIR()
*/
/*
* Async mkdir()
*
* Function returns
* 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
* <0 : An error occured when trying to set up the operation. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* 0 : Success.
* -errno : An error occured.
* data is the error string.
*/
EXTERN int nfs_mkdir_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
/*
* Sync mkdir()
* Function returns
* 0 : Success
* -errno : An error occured.
*/
EXTERN int nfs_mkdir(struct nfs_context *nfs, const char *path);
/*
* Async mkdir2()
*
* Function returns
* 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
* <0 : An error occured when trying to set up the operation. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* 0 : Success.
* -errno : An error occured.
* data is the error string.
*/
EXTERN int nfs_mkdir2_async(struct nfs_context *nfs, const char *path, int mode, nfs_cb cb, void *private_data);
/*
* Sync mkdir2()
* Function returns
* 0 : Success
* -errno : An error occured.
*/
EXTERN int nfs_mkdir2(struct nfs_context *nfs, const char *path, int mode);
/*
* RMDIR()
*/
/*
* Async rmdir()
*
* Function returns
* 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
* <0 : An error occured when trying to set up the operation. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* 0 : Success.
* -errno : An error occured.
* data is the error string.
*/
EXTERN int nfs_rmdir_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
/*
* Sync rmdir()
* Function returns
* 0 : Success
* -errno : An error occured.
*/
EXTERN int nfs_rmdir(struct nfs_context *nfs, const char *path);
/*
* CREAT()
*/
/*
* Async creat()
*
* Function returns
* 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
* <0 : An error occured when trying to set up the operation. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* 0 : Success.
* data is a struct *nfsfh;
* -errno : An error occured.
* data is the error string.
*/
EXTERN int nfs_creat_async(struct nfs_context *nfs, const char *path, int mode, nfs_cb cb, void *private_data);
/*
* Sync creat()
* Function returns
* 0 : Success
* -errno : An error occured.
*/
EXTERN int nfs_creat(struct nfs_context *nfs, const char *path, int mode, struct nfsfh **nfsfh);
/*
* Async create()
*
* Same as nfs_creat_async but allows passing flags:
* O_NOFOLLOW
* O_APPEND
* O_SYNC
* O_EXCL
* O_TRUNC
*
* Function returns
* 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
* <0 : An error occured when trying to set up the operation. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* 0 : Success.
* data is a struct *nfsfh;
* -errno : An error occured.
* data is the error string.
*/
EXTERN int nfs_create_async(struct nfs_context *nfs, const char *path, int flags, int mode, nfs_cb cb, void *private_data);
/*
* Sync create()
* Function returns
* 0 : Success
* -errno : An error occured.
*/
EXTERN int nfs_create(struct nfs_context *nfs, const char *path, int flags, int mode, struct nfsfh **nfsfh);
/*
* MKNOD()
*/
/*
* Async mknod()
*
* Function returns
* 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
* <0 : An error occured when trying to set up the operation. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* 0 : Success.
* -errno : An error occured.
* data is the error string.
*/
EXTERN int nfs_mknod_async(struct nfs_context *nfs, const char *path, int mode, int dev, nfs_cb cb, void *private_data);
/*
* Sync mknod()
* Function returns
* 0 : Success
* -errno : An error occured.
*/
EXTERN int nfs_mknod(struct nfs_context *nfs, const char *path, int mode, int dev);
/*
* UNLINK()
*/
/*
* Async unlink()
*
* Function returns
* 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
* <0 : An error occured when trying to set up the operation. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* 0 : Success.
* data is NULL
* -errno : An error occured.
* data is the error string.
*/
EXTERN int nfs_unlink_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
/*
* Sync unlink()
* Function returns
* 0 : Success
* -errno : An error occured.
*/
EXTERN int nfs_unlink(struct nfs_context *nfs, const char *path);
/*
* OPENDIR()
*/
struct nfsdir;
/*
* Async opendir()
*
* Function returns
* 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
* <0 : An error occured when trying to set up the operation. The callback will not be invoked.
*
* When struct nfsdir * is returned, this resource is closed/freed by calling nfs_closedir()
*
* When the callback is invoked, status indicates the result:
* 0 : Success.
* data is struct nfsdir *
* -errno : An error occured.
* data is the error string.
*/
EXTERN int nfs_opendir_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
/*
* Sync opendir()
* Function returns
* 0 : Success
* -errno : An error occured.
*/
EXTERN int nfs_opendir(struct nfs_context *nfs, const char *path, struct nfsdir **nfsdir);
/*
* READDIR()
*/
struct nfsdirent {
struct nfsdirent *next;
char *name;
uint64_t inode;
/* Some extra fields we get for free through the READDIRPLUS3 call.
You need libnfs-raw-nfs.h for type/mode constants */
uint32_t type; /* NF3REG, NF3DIR, NF3BLK, ... */
uint32_t mode;
uint64_t size;
struct timeval atime;
struct timeval mtime;
struct timeval ctime;
uint32_t uid;
uint32_t gid;
uint32_t nlink;
uint64_t dev;
uint64_t rdev;
uint64_t blksize;
uint64_t blocks;
uint64_t used;
uint32_t atime_nsec;
uint32_t mtime_nsec;
uint32_t ctime_nsec;
};
/*
* nfs_readdir() never blocks, so no special sync/async versions are available
*/
EXTERN struct nfsdirent *nfs_readdir(struct nfs_context *nfs, struct nfsdir *nfsdir);
/*
* SEEKDIR()
*/
/*
* This function will never block so there is no need for an async version.
*/
EXTERN void nfs_seekdir(struct nfs_context *nfs, struct nfsdir *nfsdir,
long loc);
/*
* TELLDIR()
*/
/*
* On success, nfs_telldir() will return a location as a value >= 0.
* On failure, nfs_telldir() will return -1.
*
* This function will never block so there is no need for an async version.
*/
EXTERN long nfs_telldir(struct nfs_context *nfs, struct nfsdir *nfsdir);
/*
* REWINDDIR()
*/
/*
* nfs_rewinddir() cancel all previous nfs_readdir() side effects.
* This function will never block so there is no need for an async version.
*/
EXTERN void nfs_rewinddir(struct nfs_context *nfs, struct nfsdir *nfsdir);
/*
* CLOSEDIR()
*/
/*
* nfs_closedir() never blocks, so no special sync/async versions are available
*/
EXTERN void nfs_closedir(struct nfs_context *nfs, struct nfsdir *nfsdir);
/*
* CHDIR()
*/
/*
* Async chdir()
*
* Function returns
* 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
* <0 : An error occured when trying to set up the operation. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* 0 : Success.
* data is NULL;
* -errno : An error occured.
* data is the error string.
*/
EXTERN int nfs_chdir_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
/*
* Sync chdir()
* Function returns
* 0 : The operation was successful.
* -errno : The command failed.
*/
EXTERN int nfs_chdir(struct nfs_context *nfs, const char *path);
/*
* GETCWD()
*/
/*
* nfs_getcwd() never blocks, so no special sync/async versions are available
*/
/*
* Sync getcwd()
* This function returns a pointer to the current working directory.
* This pointer is only stable until the next [f]chdir or when the
* context is destroyed.
*
* Function returns
* 0 : The operation was successful and *cwd is filled in.
* -errno : The command failed.
*/
EXTERN void nfs_getcwd(struct nfs_context *nfs, const char **cwd);
/*
* STATVFS()
*/
/*
* Async statvfs()
* Function returns
* 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
* <0 : An error occured when trying to set up the operation. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* 0 : Success.
* data is struct statvfs *
* -errno : An error occured.
* data is the error string.
*/
struct statvfs;
EXTERN int nfs_statvfs_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
/*
* Sync statvfs()
* Function returns
* 0 : The operation was successful.
* -errno : The command failed.
*/
EXTERN int nfs_statvfs(struct nfs_context *nfs, const char *path, struct statvfs *svfs);
/*
* READLINK()
*/
/*
* Async readlink()
* Function returns
* 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
* <0 : An error occured when trying to set up the operation. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* 0 : Success.
* data is a char *
* data is only valid during the callback and is automatically freed when the callback returns.
* -errno : An error occured.
* data is the error string.
*/
struct statvfs;
EXTERN int nfs_readlink_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
/*
* Sync readlink()
* Function returns
* 0 : The operation was successful.
* -errno : The command failed.
*/
EXTERN int nfs_readlink(struct nfs_context *nfs, const char *path, char *buf, int bufsize);
/*
* Sync readlink2()
* Function returns
* 0 : The operation was successful.
* -errno : The command failed.
* *bufptr : NULL if the command failed, otherwise the contents of the symlink.
* The caller must free the buffer.
*/
EXTERN int nfs_readlink2(struct nfs_context *nfs, const char *path, char **bufptr);
/*
* CHMOD()
*/
/*
* Async chmod()
* Function returns
* 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
* <0 : An error occured when trying to set up the operation. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* 0 : Success.
* data is NULL
* -errno : An error occured.
* data is the error string.
*/
EXTERN int nfs_chmod_async(struct nfs_context *nfs, const char *path, int mode, nfs_cb cb, void *private_data);
/*
* Sync chmod()
* Function returns
* 0 : The operation was successful.
* -errno : The command failed.
*/
EXTERN int nfs_chmod(struct nfs_context *nfs, const char *path, int mode);
/*
* Async chmod()
*
* Like chmod except if the destination is a symbolic link, it acts on the
* symbolic link itself.
*
* Function returns
* 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
* <0 : An error occured when trying to set up the operation. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* 0 : Success.
* data is NULL
* -errno : An error occured.
* data is the error string.
*/
EXTERN int nfs_lchmod_async(struct nfs_context *nfs, const char *path, int mode, nfs_cb cb, void *private_data);
/*
* Sync chmod()
*
* Like chmod except if the destination is a symbolic link, it acts on the
* symbolic link itself.
*
* Function returns
* 0 : The operation was successful.
* -errno : The command failed.
*/
EXTERN int nfs_lchmod(struct nfs_context *nfs, const char *path, int mode);
/*
* FCHMOD()
*/
/*
* Async fchmod()
* Function returns
* 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
* <0 : An error occured when trying to set up the operation. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* 0 : Success.
* data is NULL
* -errno : An error occured.
* data is the error string.
*/
EXTERN int nfs_fchmod_async(struct nfs_context *nfs, struct nfsfh *nfsfh, int mode, nfs_cb cb, void *private_data);
/*
* Sync fchmod()
* Function returns
* 0 : The operation was successful.
* -errno : The command failed.
*/
EXTERN int nfs_fchmod(struct nfs_context *nfs, struct nfsfh *nfsfh, int mode);
/*
* CHOWN()
*/
/*
* Async chown()
* Function returns
* 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
* <0 : An error occured when trying to set up the operation. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* 0 : Success.
* data is NULL
* -errno : An error occured.
* data is the error string.
*/
EXTERN int nfs_chown_async(struct nfs_context *nfs, const char *path, int uid, int gid, nfs_cb cb, void *private_data);
/*
* Sync chown()
* Function returns
* 0 : The operation was successful.
* -errno : The command failed.
*/
EXTERN int nfs_chown(struct nfs_context *nfs, const char *path, int uid, int gid);
/*
* Async chown()
*
* Like chown except if the destination is a symbolic link, it acts on the
* symbolic link itself.
*
* Function returns
* 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
* <0 : An error occured when trying to set up the operation. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* 0 : Success.
* data is NULL
* -errno : An error occured.
* data is the error string.
*/
EXTERN int nfs_lchown_async(struct nfs_context *nfs, const char *path, int uid, int gid, nfs_cb cb, void *private_data);
/*
* Sync chown()
*
* Like chown except if the destination is a symbolic link, it acts on the
* symbolic link itself.
*
* Function returns
* 0 : The operation was successful.
* -errno : The command failed.
*/
EXTERN int nfs_lchown(struct nfs_context *nfs, const char *path, int uid, int gid);
/*
* FCHOWN()
*/
/*
* Async fchown()
* Function returns
* 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
* <0 : An error occured when trying to set up the operation. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* 0 : Success.
* data is NULL
* -errno : An error occured.
* data is the error string.
*/
EXTERN int nfs_fchown_async(struct nfs_context *nfs, struct nfsfh *nfsfh, int uid, int gid, nfs_cb cb, void *private_data);
/*
* Sync fchown()
* Function returns
* 0 : The operation was successful.
* -errno : The command failed.
*/
EXTERN int nfs_fchown(struct nfs_context *nfs, struct nfsfh *nfsfh, int uid, int gid);
/*
* UTIMES()
*/
/*
* Async utimes()
* Function returns
* 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
* <0 : An error occured when trying to set up the operation. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* 0 : Success.
* data is NULL
* -errno : An error occured.
* data is the error string.
*/
EXTERN int nfs_utimes_async(struct nfs_context *nfs, const char *path, struct timeval *times, nfs_cb cb, void *private_data);
/*
* Sync utimes()
* Function returns
* 0 : The operation was successful.
* -errno : The command failed.
*/
EXTERN int nfs_utimes(struct nfs_context *nfs, const char *path, struct timeval *times);
/*
* Async utimes()
*
* Like utimes except if the destination is a symbolic link, it acts on the
* symbolic link itself.
*
* Function returns
* 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
* <0 : An error occured when trying to set up the operation. The callback will not be invoked.
*
* When the callback is invoked, status indicates the result:
* 0 : Success.
* data is NULL
* -errno : An error occured.
* data is the error string.
*/
EXTERN int nfs_lutimes_async(struct nfs_context *nfs, const char *path, struct timeval *times, nfs_cb cb, void *private_data);
/*
* Sync utimes(