From 41dfafbd0396fb3de27587ee037ee591afcd143b Mon Sep 17 00:00:00 2001 From: cjiph Date: Mon, 27 Feb 2006 22:29:34 +0000 Subject: [PATCH] Moved to SVN due to CVS crapness. git-svn-id: https://afuse.svn.sourceforge.net/svnroot/afuse@3 55a4958a-cc0d-0410-919a-9f8291766008 --- AUTHORS | 0 COPYING | 340 +++++++++++ COPYING.LIB | 482 ++++++++++++++++ ChangeLog | 9 + HACKING | 68 +++ INSTALL | 236 ++++++++ Makefile.am | 5 + NEWS | 0 README | 80 +++ add-cruft.sh | 3 + compat/Makefile.am | 2 + compat/fuse_opt.c | 363 ++++++++++++ compat/fuse_opt.h | 231 ++++++++ configure.ac | 36 ++ remove-cruft.sh | 4 + src/Makefile.am | 6 + src/afuse.c | 1373 ++++++++++++++++++++++++++++++++++++++++++++ 17 files changed, 3238 insertions(+) create mode 100644 AUTHORS create mode 100644 COPYING create mode 100644 COPYING.LIB create mode 100644 ChangeLog create mode 100644 HACKING create mode 100644 INSTALL create mode 100644 Makefile.am create mode 100644 NEWS create mode 100644 README create mode 100755 add-cruft.sh create mode 100644 compat/Makefile.am create mode 100644 compat/fuse_opt.c create mode 100644 compat/fuse_opt.h create mode 100644 configure.ac create mode 100755 remove-cruft.sh create mode 100644 src/Makefile.am create mode 100644 src/afuse.c diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..e69de29 diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..623b625 --- /dev/null +++ b/COPYING @@ -0,0 +1,340 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 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. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) 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 +this service 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 make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. 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. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute 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 and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +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 Program or any portion +of it, thus forming a work based on the Program, 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) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +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 Program, 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 Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) 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; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, 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 executable. However, as a +special exception, the source code 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. + +If distribution of executable or 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 counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program 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. + + 5. 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 Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program 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 to +this License. + + 7. 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 Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program 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 Program. + +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. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program 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. + + 9. The Free Software Foundation may publish revised and/or new versions +of the 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 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 Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, 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 + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, 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. + + 12. 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 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. + + 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 +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 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 2 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, 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. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision 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, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This 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 Library General +Public License instead of this License. diff --git a/COPYING.LIB b/COPYING.LIB new file mode 100644 index 0000000..161a3d1 --- /dev/null +++ b/COPYING.LIB @@ -0,0 +1,482 @@ + GNU LIBRARY GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1991 Free Software Foundation, Inc. + 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 library GPL. It is + numbered 2 because it goes with version 2 of the ordinary GPL.] + + 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 Library General Public License, applies to some +specially designated Free Software Foundation software, and to any +other libraries whose authors decide to use it. You can use it for +your libraries, 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 +this service 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 make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the 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 a program 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. + + Our method of protecting your rights has two steps: (1) copyright +the library, and (2) offer you this license which gives you legal +permission to copy, distribute and/or modify the library. + + Also, for each distributor's protection, we want to make certain +that everyone understands that there is no warranty for this free +library. If the library is modified by someone else and passed on, we +want its recipients to know that what they have is not the original +version, so that any problems introduced by others will not reflect on +the original authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that companies distributing free +software will individually obtain patent licenses, thus in effect +transforming the program into proprietary software. To prevent this, +we have made it clear that any patent must be licensed for everyone's +free use or not licensed at all. + + Most GNU software, including some libraries, is covered by the ordinary +GNU General Public License, which was designed for utility programs. This +license, the GNU Library General Public License, applies to certain +designated libraries. This license is quite different from the ordinary +one; be sure to read it in full, and don't assume that anything in it is +the same as in the ordinary license. + + The reason we have a separate public license for some libraries is that +they blur the distinction we usually make between modifying or adding to a +program and simply using it. Linking a program with a library, without +changing the library, is in some sense simply using the library, and is +analogous to running a utility program or application program. However, in +a textual and legal sense, the linked executable is a combined work, a +derivative of the original library, and the ordinary General Public License +treats it as such. + + Because of this blurred distinction, using the ordinary General +Public License for libraries did not effectively promote software +sharing, because most developers did not use the libraries. We +concluded that weaker conditions might promote sharing better. + + However, unrestricted linking of non-free programs would deprive the +users of those programs of all benefit from the free status of the +libraries themselves. This Library General Public License is intended to +permit developers of non-free programs to use free libraries, while +preserving your freedom as a user of such programs to change the free +libraries that are incorporated in them. (We have not seen how to achieve +this as regards changes in header files, but we have achieved it as regards +changes in the actual functions of the Library.) The hope is that this +will lead to faster development of free libraries. + + 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, while the latter only +works together with the library. + + Note that it is possible for a library to be covered by the ordinary +General Public License rather than by this special one. + + GNU LIBRARY GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library which +contains a notice placed by the copyright holder or other authorized +party saying it may be distributed under the terms of this Library +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 compile 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) 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. + + c) 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. + + d) 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 source code 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 to +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 Library 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 + + Appendix: 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 Library General Public + License as published by the Free Software Foundation; either + version 2 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, 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! diff --git a/ChangeLog b/ChangeLog new file mode 100644 index 0000000..635b64b --- /dev/null +++ b/ChangeLog @@ -0,0 +1,9 @@ +Version 0.1.1 +------------- +* Backward compatibility with FUSE 2.3 (to 2.5). +* Internal bug fixes. +* Moved to SVN due to SourceForge CVS being perpetually broken. + +Version 0.1 +----------- +* Initial release diff --git a/HACKING b/HACKING new file mode 100644 index 0000000..00a0a28 --- /dev/null +++ b/HACKING @@ -0,0 +1,68 @@ +CVS Build +--------- +If you get afuse from CVS, run add-cruft.sh to generate the autotool crap. +If your version of the autotools generates files not picked up in the +various .cvsignore files or the remove-cruft.sh script, and you have +CVS write access please add them. Not that add-cruft.sh is likely +to work on your system anyway as the autotools seem to do completely +different things distro to distro. + +I really hate the way the autotools require all these stupid random +files be created for operation and included in releases. Why can't it +just be an actual program used to build source distributions based on +the canonicalised config information? + + +TODO +---- +While it is basically usable, there are a huge number of things which need +doing to afuse to make it a "good" project. Here are a list of some of +these: + +* Support multi-threading - Internatal Data structures need to guarded + before we allow this. + +* Eliminate the proxying - In theory it should be possible for afuse + to mount filesystems within itself. However this seems to cause a + really nasty deadlock. It might be possible for this to work using + multi-threading or rebinding/moving mount points (needs changes to + fusermount). + +* Auto-unmounting on inactivity. + +* More complex automounting schemes + * Different commands based on regex's of virtual directories. + * Use a static list of automountable virtual directories. + * Scriptable multi-level virtual directory hierachy. + +* Refactoring + * Code should be split into multiple files (could be more efficient too). + * Some internal terminology can be confusing. + * alloca's should be converted to VLAs as alloca is non-portable. + * Code should in general be made more portable with the help of the + autotools. + +* More extensive documentation. + +* GUI for asking for interactive automounting. For example we could pop up + an X11 window, or switch to other VTs on a Liunx console. This needs some + thought to be implemented well, maybe it should be done with plug-ins/ + scripts on a per FS basis. + +* Better debugging output. + +* Autotool'ed environemnt needs lots of work. + +* Exit on signal often isn't clean (directory should be unmounted) + (actually this seems to work with FUSE 2.3?) + +* Mouting can sometimes happen in silly situations, for example touching + a file in the afuse root will cause a filesystem of that filename + to be automounted. This does not seem to be avoidable in earlier + versions of FUSE (2.3 for example) as getattr is always called on + the virtual directory on any operation and if this fails the whole + operation is aborted. So it is impossible to distinguish a getattr for + [non]-mounting operations. + +Hopefully I'll get to some of these things in my spare time, however +if you're interested in helping jump on the mailing list at the SF page. diff --git a/INSTALL b/INSTALL new file mode 100644 index 0000000..23e5f25 --- /dev/null +++ b/INSTALL @@ -0,0 +1,236 @@ +Installation Instructions +************************* + +Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2004, 2005 Free +Software Foundation, Inc. + +This file is free documentation; the Free Software Foundation gives +unlimited permission to copy, distribute and modify it. + +Basic Installation +================== + +These are generic installation instructions. + + The `configure' shell script attempts to guess correct values for +various system-dependent variables used during compilation. It uses +those values to create a `Makefile' in each directory of the package. +It may also create one or more `.h' files containing system-dependent +definitions. Finally, it creates a shell script `config.status' that +you can run in the future to recreate the current configuration, and a +file `config.log' containing compiler output (useful mainly for +debugging `configure'). + + It can also use an optional file (typically called `config.cache' +and enabled with `--cache-file=config.cache' or simply `-C') that saves +the results of its tests to speed up reconfiguring. (Caching is +disabled by default to prevent problems with accidental use of stale +cache files.) + + If you need to do unusual things to compile the package, please try +to figure out how `configure' could check whether to do them, and mail +diffs or instructions to the address given in the `README' so they can +be considered for the next release. If you are using the cache, and at +some point `config.cache' contains results you don't want to keep, you +may remove or edit it. + + The file `configure.ac' (or `configure.in') is used to create +`configure' by a program called `autoconf'. You only need +`configure.ac' if you want to change it or regenerate `configure' using +a newer version of `autoconf'. + +The simplest way to compile this package is: + + 1. `cd' to the directory containing the package's source code and type + `./configure' to configure the package for your system. If you're + using `csh' on an old version of System V, you might need to type + `sh ./configure' instead to prevent `csh' from trying to execute + `configure' itself. + + Running `configure' takes awhile. While running, it prints some + messages telling which features it is checking for. + + 2. Type `make' to compile the package. + + 3. Optionally, type `make check' to run any self-tests that come with + the package. + + 4. Type `make install' to install the programs and any data files and + documentation. + + 5. You can remove the program binaries and object files from the + source code directory by typing `make clean'. To also remove the + files that `configure' created (so you can compile the package for + a different kind of computer), type `make distclean'. There is + also a `make maintainer-clean' target, but that is intended mainly + for the package's developers. If you use it, you may have to get + all sorts of other programs in order to regenerate files that came + with the distribution. + +Compilers and Options +===================== + +Some systems require unusual options for compilation or linking that the +`configure' script does not know about. Run `./configure --help' for +details on some of the pertinent environment variables. + + You can give `configure' initial values for configuration parameters +by setting variables in the command line or in the environment. Here +is an example: + + ./configure CC=c89 CFLAGS=-O2 LIBS=-lposix + + *Note Defining Variables::, for more details. + +Compiling For Multiple Architectures +==================================== + +You can compile the package for more than one kind of computer at the +same time, by placing the object files for each architecture in their +own directory. To do this, you must use a version of `make' that +supports the `VPATH' variable, such as GNU `make'. `cd' to the +directory where you want the object files and executables to go and run +the `configure' script. `configure' automatically checks for the +source code in the directory that `configure' is in and in `..'. + + If you have to use a `make' that does not support the `VPATH' +variable, you have to compile the package for one architecture at a +time in the source code directory. After you have installed the +package for one architecture, use `make distclean' before reconfiguring +for another architecture. + +Installation Names +================== + +By default, `make install' installs the package's commands under +`/usr/local/bin', include files under `/usr/local/include', etc. You +can specify an installation prefix other than `/usr/local' by giving +`configure' the option `--prefix=PREFIX'. + + You can specify separate installation prefixes for +architecture-specific files and architecture-independent files. If you +pass the option `--exec-prefix=PREFIX' to `configure', the package uses +PREFIX as the prefix for installing programs and libraries. +Documentation and other data files still use the regular prefix. + + In addition, if you use an unusual directory layout you can give +options like `--bindir=DIR' to specify different values for particular +kinds of files. Run `configure --help' for a list of the directories +you can set and what kinds of files go in them. + + If the package supports it, you can cause programs to be installed +with an extra prefix or suffix on their names by giving `configure' the +option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'. + +Optional Features +================= + +Some packages pay attention to `--enable-FEATURE' options to +`configure', where FEATURE indicates an optional part of the package. +They may also pay attention to `--with-PACKAGE' options, where PACKAGE +is something like `gnu-as' or `x' (for the X Window System). The +`README' should mention any `--enable-' and `--with-' options that the +package recognizes. + + For packages that use the X Window System, `configure' can usually +find the X include and library files automatically, but if it doesn't, +you can use the `configure' options `--x-includes=DIR' and +`--x-libraries=DIR' to specify their locations. + +Specifying the System Type +========================== + +There may be some features `configure' cannot figure out automatically, +but needs to determine by the type of machine the package will run on. +Usually, assuming the package is built to be run on the _same_ +architectures, `configure' can figure that out, but if it prints a +message saying it cannot guess the machine type, give it the +`--build=TYPE' option. TYPE can either be a short name for the system +type, such as `sun4', or a canonical name which has the form: + + CPU-COMPANY-SYSTEM + +where SYSTEM can have one of these forms: + + OS KERNEL-OS + + See the file `config.sub' for the possible values of each field. If +`config.sub' isn't included in this package, then this package doesn't +need to know the machine type. + + If you are _building_ compiler tools for cross-compiling, you should +use the option `--target=TYPE' to select the type of system they will +produce code for. + + If you want to _use_ a cross compiler, that generates code for a +platform different from the build platform, you should specify the +"host" platform (i.e., that on which the generated programs will +eventually be run) with `--host=TYPE'. + +Sharing Defaults +================ + +If you want to set default values for `configure' scripts to share, you +can create a site shell script called `config.site' that gives default +values for variables like `CC', `cache_file', and `prefix'. +`configure' looks for `PREFIX/share/config.site' if it exists, then +`PREFIX/etc/config.site' if it exists. Or, you can set the +`CONFIG_SITE' environment variable to the location of the site script. +A warning: not all `configure' scripts look for a site script. + +Defining Variables +================== + +Variables not defined in a site shell script can be set in the +environment passed to `configure'. However, some packages may run +configure again during the build, and the customized values of these +variables may be lost. In order to avoid this problem, you should set +them in the `configure' command line, using `VAR=value'. For example: + + ./configure CC=/usr/local2/bin/gcc + +causes the specified `gcc' to be used as the C compiler (unless it is +overridden in the site shell script). Here is a another example: + + /bin/bash ./configure CONFIG_SHELL=/bin/bash + +Here the `CONFIG_SHELL=/bin/bash' operand causes subsequent +configuration-related scripts to be executed by `/bin/bash'. + +`configure' Invocation +====================== + +`configure' recognizes the following options to control how it operates. + +`--help' +`-h' + Print a summary of the options to `configure', and exit. + +`--version' +`-V' + Print the version of Autoconf used to generate the `configure' + script, and exit. + +`--cache-file=FILE' + Enable the cache: use and save the results of the tests in FILE, + traditionally `config.cache'. FILE defaults to `/dev/null' to + disable caching. + +`--config-cache' +`-C' + Alias for `--cache-file=config.cache'. + +`--quiet' +`--silent' +`-q' + Do not print messages saying which checks are being made. To + suppress all normal output, redirect it to `/dev/null' (any error + messages will still be shown). + +`--srcdir=DIR' + Look for the package's source code in directory DIR. Usually + `configure' can determine that directory automatically. + +`configure' also accepts some other, not widely useful, options. Run +`configure --help' for more details. + diff --git a/Makefile.am b/Makefile.am new file mode 100644 index 0000000..73d9f48 --- /dev/null +++ b/Makefile.am @@ -0,0 +1,5 @@ +if FUSE_OPT_COMPAT +compat_dir = compat +endif + +SUBDIRS=$(compat_dir) src diff --git a/NEWS b/NEWS new file mode 100644 index 0000000..e69de29 diff --git a/README b/README new file mode 100644 index 0000000..c056cb3 --- /dev/null +++ b/README @@ -0,0 +1,80 @@ +Afuse 0.1 +By Jacob Bower +http://afuse.sourceforge.net/ + + +0. Conents +---------- +1. Abstract +2. Example Usage +3. Notes on Afuse's Operation + + +1. Abstract +----------- +Afuse is an automounting file system implemented in user-space using +FUSE. Afuse currently implements the most basic functionality that can +be expected by an automounter; that is it manages a directory of virtual +directories. If one of these virtual directories is accessed and is not +already automounted, afuse will attempt to mount a filesystem onto that +directory. If the mount succeeds the requested access proceeds as normal, +otherwise it will fail with an error. See the example below for a specific +usage scenario. + +The advantage of using afuse over traditional automounters is that afuse +is designed to run entirely in user-space by individual users. This way an +automounting action can take advantage of the invoking users environment, +for example allowing access to an ssh-agent for password-less sshfs +mounts, or allowing access to a graphical environment to get user input +to complete a mount (i.e. popping up a window asking for a password). + +As this is a very early release of afuse operation is not yet optimal +and many features are missing. If you are interested in plans for +afuse or would like to contribute please see the HACKING file. + +The latest version of afuse can be found at http://afuse.sourceforge.net/ + +Afuse is distributed under the GPL license, details of which can be +found in the COPYING file. Particularly, please note that while afuse +is intended to be useful it is provided with ABSOLUTELY NO WARRANTY. + + +2. Example Usage +---------------- +Example invocation using sshfs: + + afuse -o mount_template="sshfs %r:/ %m" \ + -o unmount_template="fusermount -u -z %m" \ + mountpoint/ + +Now try 'ls mountpoint/user@host/'. + +To unmount use: + + fusermount -u -z mountpoint/ + +All sub mounts should be automatically unmounted. + +For this example to work, the sshfs invocation must not require user +interactivity (i.e. asking for a password). So you probably want to be +using something like ssh-agent. + +Alternatively, if want interactivity, add -f to the afuse invocation. + + +3. Notes on Afuse's Operation +----------------------------- +One of the most important things to note about afuse's operation is that +automounted filesystems accessed through afuse are actually accessed +by proxy. Actual mounts are created in an instance specific directory +in /tmp. _ALL_ accesses to automounted filesystems apparently managed by +afuse go through afuse and are proxied onto the real filesystem mounts +as appropriate. + +While this shouldn't cause any operational problems, it does mean that +operations on afuse automunted filesystems have considerable overhead. +It can also mean that if afuse is not shutdown cleanly (via an unmount +of the afuse filesystem) a stale directory can be left in /tmp of the +form afuse-XXXXXX (where the X's are random characters). + +Hopefuly these limitations will be removed in later revisions of afuse. diff --git a/add-cruft.sh b/add-cruft.sh new file mode 100755 index 0000000..c5a7472 --- /dev/null +++ b/add-cruft.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +autoreconf --install diff --git a/compat/Makefile.am b/compat/Makefile.am new file mode 100644 index 0000000..ae4c01b --- /dev/null +++ b/compat/Makefile.am @@ -0,0 +1,2 @@ +noinst_LIBRARIES = libcompat.a +libcompat_a_SOURCES = fuse_opt.c fuse_opt.h diff --git a/compat/fuse_opt.c b/compat/fuse_opt.c new file mode 100644 index 0000000..4e3720a --- /dev/null +++ b/compat/fuse_opt.c @@ -0,0 +1,363 @@ +/* + FUSE: Filesystem in Userspace + Copyright (C) 2001-2006 Miklos Szeredi + + This file is borrowed from sshfs-fuse. It provides an implementation + of the FUSE command line parsing functions which only appear in + later version of FUSE but are used in afuse. + + This file can be distributed under the terms of the GNU LGPL. + See the file COPYING.LIB +*/ + +#include "fuse_opt.h" + +#include +#include +#include +#include + +struct fuse_opt_context { + void *data; + const struct fuse_opt *opt; + fuse_opt_proc_t proc; + int argctr; + int argc; + char **argv; + struct fuse_args outargs; + char *opts; + int nonopt; +}; + +void fuse_opt_free_args(struct fuse_args *args) +{ + if (args && args->argv && args->allocated) { + int i; + for (i = 0; i < args->argc; i++) + free(args->argv[i]); + free(args->argv); + args->argv = NULL; + args->allocated = 0; + } +} + +static int alloc_failed(void) +{ + fprintf(stderr, "fuse: memory allocation failed\n"); + return -1; +} + +int fuse_opt_add_arg(struct fuse_args *args, const char *arg) +{ + char **newargv; + char *newarg; + + assert(!args->argv || args->allocated); + + newargv = realloc(args->argv, (args->argc + 2) * sizeof(char *)); + newarg = newargv ? strdup(arg) : NULL; + if (!newargv || !newarg) + return alloc_failed(); + + args->argv = newargv; + args->allocated = 1; + args->argv[args->argc++] = newarg; + args->argv[args->argc] = NULL; + return 0; +} + +static int next_arg(struct fuse_opt_context *ctx, const char *opt) +{ + if (ctx->argctr + 1 >= ctx->argc) { + fprintf(stderr, "fuse: missing argument after `%s'\n", opt); + return -1; + } + ctx->argctr++; + return 0; +} + +static int add_arg(struct fuse_opt_context *ctx, const char *arg) +{ + return fuse_opt_add_arg(&ctx->outargs, arg); +} + +int fuse_opt_add_opt(char **opts, const char *opt) +{ + char *newopts; + if (!*opts) + newopts = strdup(opt); + else { + unsigned oldlen = strlen(*opts); + newopts = realloc(*opts, oldlen + 1 + strlen(opt) + 1); + if (newopts) { + newopts[oldlen] = ','; + strcpy(newopts + oldlen + 1, opt); + } + } + if (!newopts) + return alloc_failed(); + + *opts = newopts; + return 0; +} + +static int add_opt(struct fuse_opt_context *ctx, const char *opt) +{ + return fuse_opt_add_opt(&ctx->opts, opt); +} + +static int insert_arg(struct fuse_opt_context *ctx, int pos, const char *arg) +{ + assert(pos <= ctx->outargs.argc); + if (add_arg(ctx, arg) == -1) + return -1; + + if (pos != ctx->outargs.argc - 1) { + char *newarg = ctx->outargs.argv[ctx->outargs.argc - 1]; + memmove(&ctx->outargs.argv[pos + 1], &ctx->outargs.argv[pos], + sizeof(char *) * (ctx->outargs.argc - pos - 1)); + ctx->outargs.argv[pos] = newarg; + } + return 0; +} + +static int call_proc(struct fuse_opt_context *ctx, const char *arg, int key, + int iso) +{ + if (ctx->proc) { + int res = ctx->proc(ctx->data, arg, key, &ctx->outargs); + if (res == -1 || !res) + return res; + } + if (iso) + return add_opt(ctx, arg); + else + return add_arg(ctx, arg); +} + +static int match_template(const char *t, const char *arg, unsigned *sepp) +{ + int arglen = strlen(arg); + const char *sep = strchr(t, '='); + sep = sep ? sep : strchr(t, ' '); + if (sep && (!sep[1] || sep[1] == '%')) { + int tlen = sep - t; + if (sep[0] == '=') + tlen ++; + if (arglen >= tlen && strncmp(arg, t, tlen) == 0) { + *sepp = sep - t; + return 1; + } + } + if (strcmp(t, arg) == 0) { + *sepp = 0; + return 1; + } + return 0; +} + +static const struct fuse_opt *find_opt(const struct fuse_opt *opt, + const char *arg, unsigned *sepp) +{ + for (; opt && opt->template; opt++) + if (match_template(opt->template, arg, sepp)) + return opt; + return NULL; +} + +int fuse_opt_match(const struct fuse_opt *opts, const char *opt) +{ + unsigned dummy; + return find_opt(opts, opt, &dummy) ? 1 : 0; +} + +static int process_opt_param(void *var, const char *format, const char *param, + const char *arg) +{ + assert(format[0] == '%'); + if (format[1] == 's') { + char *copy = strdup(param); + if (!copy) + return alloc_failed(); + + *(char **) var = copy; + } else { + if (sscanf(param, format, var) != 1) { + fprintf(stderr, "fuse: invalid parameter in option `%s'\n", arg); + return -1; + } + } + return 0; +} + +static int process_opt(struct fuse_opt_context *ctx, + const struct fuse_opt *opt, unsigned sep, + const char *arg, int iso) +{ + if (opt->offset == -1U) { + if (call_proc(ctx, arg, opt->value, iso) == -1) + return -1; + } else { + void *var = ctx->data + opt->offset; + if (sep && opt->template[sep + 1]) { + const char *param = arg + sep; + if (opt->template[sep] == '=') + param ++; + if (process_opt_param(var, opt->template + sep + 1, + param, arg) == -1) + return -1; + } else + *(int *)var = opt->value; + } + return 0; +} + +static int process_opt_sep_arg(struct fuse_opt_context *ctx, + const struct fuse_opt *opt, unsigned sep, + const char *arg, int iso) +{ + int res; + char *newarg; + char *param; + + if (next_arg(ctx, arg) == -1) + return -1; + + param = ctx->argv[ctx->argctr]; + newarg = malloc(sep + strlen(param) + 1); + if (!newarg) + return alloc_failed(); + + memcpy(newarg, arg, sep); + strcpy(newarg + sep, param); + res = process_opt(ctx, opt, sep, newarg, iso); + free(newarg); + + return res; +} + +static int process_gopt(struct fuse_opt_context *ctx, const char *arg, int iso) +{ + unsigned sep; + const struct fuse_opt *opt = find_opt(ctx->opt, arg, &sep); + if (opt) { + for (; opt; opt = find_opt(opt + 1, arg, &sep)) { + int res; + if (sep && opt->template[sep] == ' ' && !arg[sep]) + res = process_opt_sep_arg(ctx, opt, sep, arg, iso); + else + res = process_opt(ctx, opt, sep, arg, iso); + if (res == -1) + return -1; + } + return 0; + } else + return call_proc(ctx, arg, FUSE_OPT_KEY_OPT, iso); +} + +static int process_real_option_group(struct fuse_opt_context *ctx, char *opts) +{ + char *sep; + + do { + int res; + sep = strchr(opts, ','); + if (sep) + *sep = '\0'; + res = process_gopt(ctx, opts, 1); + if (res == -1) + return -1; + opts = sep + 1; + } while (sep); + + return 0; +} + +static int process_option_group(struct fuse_opt_context *ctx, const char *opts) +{ + int res; + char *copy; + const char *sep = strchr(opts, ','); + if (!sep) + return process_gopt(ctx, opts, 1); + + copy = strdup(opts); + if (!copy) { + fprintf(stderr, "fuse: memory allocation failed\n"); + return -1; + } + res = process_real_option_group(ctx, copy); + free(copy); + return res; +} + +static int process_one(struct fuse_opt_context *ctx, const char *arg) +{ + if (ctx->nonopt || arg[0] != '-') + return call_proc(ctx, arg, FUSE_OPT_KEY_NONOPT, 0); + else if (arg[1] == 'o') { + if (arg[2]) + return process_option_group(ctx, arg + 2); + else { + if (next_arg(ctx, arg) == -1) + return -1; + + return process_option_group(ctx, ctx->argv[ctx->argctr]); + } + } else if (arg[1] == '-' && !arg[2]) { + if (add_arg(ctx, arg) == -1) + return -1; + ctx->nonopt = ctx->outargs.argc; + return 0; + } else + return process_gopt(ctx, arg, 0); +} + +static int opt_parse(struct fuse_opt_context *ctx) +{ + if (ctx->argc) { + if (add_arg(ctx, ctx->argv[0]) == -1) + return -1; + } + + for (ctx->argctr = 1; ctx->argctr < ctx->argc; ctx->argctr++) + if (process_one(ctx, ctx->argv[ctx->argctr]) == -1) + return -1; + + if (ctx->opts) { + if (insert_arg(ctx, 1, "-o") == -1 || + insert_arg(ctx, 2, ctx->opts) == -1) + return -1; + } + if (ctx->nonopt && ctx->nonopt == ctx->outargs.argc) + ctx->outargs.argv[--ctx->outargs.argc] = NULL; + + return 0; +} + +int fuse_opt_parse(struct fuse_args *args, void *data, + const struct fuse_opt opts[], fuse_opt_proc_t proc) +{ + int res; + struct fuse_opt_context ctx = { + .data = data, + .opt = opts, + .proc = proc, + }; + + if (!args || !args->argv || !args->argc) + return 0; + + ctx.argc = args->argc; + ctx.argv = args->argv; + + res = opt_parse(&ctx); + if (res != -1) { + struct fuse_args tmp = *args; + *args = ctx.outargs; + ctx.outargs = tmp; + } + free(ctx.opts); + fuse_opt_free_args(&ctx.outargs); + return res; +} diff --git a/compat/fuse_opt.h b/compat/fuse_opt.h new file mode 100644 index 0000000..84ad35e --- /dev/null +++ b/compat/fuse_opt.h @@ -0,0 +1,231 @@ +/* + FUSE: Filesystem in Userspace + Copyright (C) 2001-2006 Miklos Szeredi + + This file is borrowed from sshfs-fuse. It provides an implementation + of the FUSE command line parsing functions which only appear in + later version of FUSE but are used in afuse. + + This file can be distributed under the terms of the GNU LGPL. + See the file COPYING.LIB +*/ + +#ifndef _FUSE_OPT_H_ +#define _FUSE_OPT_H_ + +/* This file defines the option parsing interface of FUSE */ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Option description + * + * This structure describes a single option, and and action associated + * with it, in case it matches. + * + * More than one such match may occur, in which case the action for + * each match is executed. + * + * There are three possible actions in case of a match: + * + * i) An integer (int or unsigned) variable determined by 'offset' is + * set to 'value' + * + * ii) The processing function is called, with 'value' as the key + * + * iii) An integer (any) or string (char *) variable determined by + * 'offset' is set to the value of an option parameter + * + * 'offset' should normally be either set to + * + * - 'offsetof(struct foo, member)' actions i) and iii) + * + * - -1 action ii) + * + * The 'offsetof()' macro is defined in the header. + * + * The template determines which options match, and also have an + * effect on the action. Normally the action is either i) or ii), but + * if a format is present in the template, then action iii) is + * performed. + * + * The types of templates are: + * + * 1) "-x", "-foo", "--foo", "--foo-bar", etc. These match only + * themselves. Invalid values are "--" and anything beginning + * with "-o" + * + * 2) "foo", "foo-bar", etc. These match "-ofoo", "-ofoo-bar" or + * the relevant option in a comma separated option list + * + * 3) "bar=", "--foo=", etc. These are variations of 1) and 2) + * which have a parameter + * + * 4) "bar=%s", "--foo=%lu", etc. Same matching as above but perform + * action iii). + * + * 5) "-x ", etc. Matches either "-xparam" or "-x param" as + * two separate arguments + * + * 6) "-x %s", etc. Combination of 4) and 5) + * + * If the format is "%s", memory is allocated for the string unlike + * with scanf(). + */ +struct fuse_opt { + /** Matching template and optional parameter formatting */ + const char *template; + + /** + * Offset of variable within 'data' parameter of fuse_opt_parse() + * or -1 + */ + unsigned long offset; + + /** + * Value to set the variable to, or to be passed as 'key' to the + * processing function. Ignored if template a format + */ + int value; +}; + +/** + * Key option. In case of a match, the processing function will be + * called with the specified key. + */ +#define FUSE_OPT_KEY(template, key) { template, -1U, key } + +/** + * Last option. An array of 'struct fuse_opt' must end with a NULL + * template value + */ +#define FUSE_OPT_END { .template = NULL } + +/** + * Argument list + */ +struct fuse_args { + /** Argument count */ + int argc; + + /** Argument vector. NULL terminated */ + char **argv; + + /** Is 'argv' allocated? */ + int allocated; +}; + +/** + * Initializer for 'struct fuse_args' + */ +#define FUSE_ARGS_INIT(argc, argv) { argc, argv, 0 } + +/** + * Key value passed to the processing function if an option did not + * match any templated + */ +#define FUSE_OPT_KEY_OPT -1 + +/** + * Key value passed to the processing function for all non-options + * + * Non-options are the arguments beginning with a charater other than + * '-' or all arguments after the special '--' option + */ +#define FUSE_OPT_KEY_NONOPT -2 + +/** + * Processing function + * + * This function is called if + * - option did not match any 'struct fuse_opt' + * - argument is a non-option + * - option did match and offset was set to -1 + * + * The 'arg' parameter will always contain the whole argument or + * option including the parameter if exists. A two-argument option + * ("-x foo") is always converted to single arguemnt option of the + * form "-xfoo" before this function is called. + * + * Options of the form '-ofoo' are passed to this function without the + * '-o' prefix. + * + * The return value of this function determines whether this argument + * is to be inserted into the output argument vector, or discarded. + * + * @param data is the user data passed to the fuse_opt_parse() function + * @param arg is the whole argument or option + * @param key determines why the processing function was called + * @param outargs the current output argument list + * @return -1 on error, 0 if arg is to be discarded, 1 if arg should be kept + */ +typedef int (*fuse_opt_proc_t)(void *data, const char *arg, int key, + struct fuse_args *outargs); + +/** + * Option parsing function + * + * If 'args' was returned from a previous call to fuse_opt_parse() or + * it was constructed from + * + * A NULL 'args' is equivalent to an empty argument vector + * + * A NULL 'opts' is equivalent to an 'opts' array containing a single + * end marker + * + * A NULL 'proc' is equivalent to a processing function always + * returning '1' + * + * @param args is the input and output argument list + * @param data is the user data + * @param opts is the option description array + * @param proc is the processing function + * @return -1 on error, 0 on success + */ +int fuse_opt_parse(struct fuse_args *args, void *data, + const struct fuse_opt opts[], fuse_opt_proc_t proc); + +/** + * Add an option to a comma separated option list + * + * @param opts is a pointer to an option list, may point to a NULL value + * @param opt is the option to add + * @return -1 on allocation error, 0 on success + */ +int fuse_opt_add_opt(char **opts, const char *opt); + +/** + * Add an argument to a NULL terminated argument vector + * + * @param args is the structure containing the current argument list + * @param arg is the new argument to add + * @return -1 on allocation error, 0 on success + */ +int fuse_opt_add_arg(struct fuse_args *args, const char *arg); + +/** + * Free the contents of argument list + * + * The structure itself is not freed + * + * @param args is the structure containing the argument list + */ +void fuse_opt_free_args(struct fuse_args *args); + + +/** + * Check if an option matches + * + * @param opts is the option description array + * @param opt is the option to match + * @return 1 if a match is found, 0 if not + */ +int fuse_opt_match(const struct fuse_opt opts[], const char *opt); + +#ifdef __cplusplus +} +#endif + +#endif /* _FUSE_OPT_H_ */ diff --git a/configure.ac b/configure.ac new file mode 100644 index 0000000..db214a9 --- /dev/null +++ b/configure.ac @@ -0,0 +1,36 @@ +# -*- Autoconf -*- +# Process this file with autoconf to produce a configure script. + +AC_PREREQ(2.59) +AC_INIT([afuse], [0.1.1], [jacob.bower@ic.ac.uk]) + +AM_INIT_AUTOMAKE +AC_PROG_RANLIB + +AC_CONFIG_SRCDIR([src/afuse.c]) +AM_CONFIG_HEADER(config.h) + +# Checks for programs. +AC_PROG_CC + +# Checks for libraries. +export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH +PKG_CHECK_MODULES(FUSE, [fuse >= 2.3]) +CFLAGS="$CFLAGS $FUSE_CFLAGS -DFUSE_USE_VERSION=25" +LIBS="$FUSE_LIBS" + +# Check if we need to enable compatibility code for old FUSE versions +have_fuse_opt_parse=no +AC_CHECK_FUNC([fuse_opt_parse], [have_fuse_opt_parse=yes]) +if test "$have_fuse_opt_parse" = no; then + CFLAGS="$CFLAGS -I$PWD/compat" +fi +AM_CONDITIONAL(FUSE_OPT_COMPAT, test "$have_fuse_opt_parse" = no) + + +AC_CHECK_FUNCS([setxattr fdatasync]) + +AC_CONFIG_FILES([Makefile + src/Makefile + compat/Makefile]) +AC_OUTPUT diff --git a/remove-cruft.sh b/remove-cruft.sh new file mode 100755 index 0000000..c9e5d95 --- /dev/null +++ b/remove-cruft.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +make distclean +rm -rf -- -/ autom4te.cache Makefile Makefile.in aclocal.m4 config.h.in config.h afuse*.tar.gz stamp-h* mkinstalldirs config.log config.status configure depcomp install-sh missing src/Makefile.in compat/Makefile.in *.bak *~ .in config.guess config.sub diff --git a/src/Makefile.am b/src/Makefile.am new file mode 100644 index 0000000..423a70a --- /dev/null +++ b/src/Makefile.am @@ -0,0 +1,6 @@ +bin_PROGRAMS=afuse +afuse_SOURCE=afuse.c + +if FUSE_OPT_COMPAT +afuse_LDADD = ../compat/libcompat.a +endif diff --git a/src/afuse.c b/src/afuse.c new file mode 100644 index 0000000..311bdd0 --- /dev/null +++ b/src/afuse.c @@ -0,0 +1,1373 @@ +/* + afuse - An automounter using FUSE + Copyright (C) 2006 Jacob Bower + + Portions of this program derive from examples provided with + FUSE-2.5.2. + + This program can be distributed under the terms of the GNU GPL. + See the file COPYING. +*/ + +#include + +#ifdef linux +// For pread()/pwrite() +#define _XOPEN_SOURCE 500 +#endif + +#include +#include +// for mkdtemp +#define __USE_BSD +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef HAVE_SETXATTR +#include +#endif + +// When closing an fd/dir, the close may fail due to a signal +// this value defines how many times we retry in this case. +// It's useful to try and close as many fd's as possible +// for the proxied fs to increase the chance an umount will +// succeed. +#define CLOSE_MAX_RETRIES 5 + +#define TMP_DIR_TEMPLATE "/tmp/afuse-XXXXXX" +char *mount_point_directory; + +struct user_options_t { + char *mount_command_template; + char *unmount_command_template; +} user_options = {NULL, NULL}; + +typedef struct _fd_list_t { + struct _fd_list_t *next; + struct _fd_list_t *prev; + + int fd; +} fd_list_t; + +typedef struct _dir_list_t { + struct _dir_list_t *next; + struct _dir_list_t *prev; + + DIR *dir; +} dir_list_t; + +typedef struct _mount_list_t { + struct _mount_list_t *next; + struct _mount_list_t *prev; + + char *root_name; + fd_list_t *fd_list; + dir_list_t *dir_list; +} mount_list_t; + +mount_list_t *mount_list = NULL; + +void *my_malloc(size_t size) +{ + void *p; + + p = malloc(size); + + if(!p) { + fprintf(stderr, "Failed to allocate: %d bytes of memory.\n"); + exit(1); + } + + return p; +} + +char *my_strdup(char *str) +{ + char *new_str; + + new_str = my_malloc(strlen(str) + 1); + strcpy(new_str, str); + + return new_str; +} + +mount_list_t *find_mount(char *root_name) +{ + mount_list_t *current_mount = mount_list; + + while(current_mount) { + if( strcmp(root_name, current_mount->root_name) == 0) + return current_mount; + + current_mount = current_mount->next; + } + + return NULL; +} + +int is_mount(char *root_name) +{ + return find_mount(root_name) ? 1 : 0; +} + +void add_fd(fd_list_t **fd_list, int fd) +{ + fd_list_t *new_fd; + + new_fd = my_malloc( sizeof(fd_list_t) ); + new_fd->fd = fd; + new_fd->next = *fd_list; + new_fd->prev = NULL; + + *fd_list = new_fd; +} + +void remove_fd(fd_list_t **fd_list, int fd) +{ + fd_list_t *current_fd = *fd_list; + + while(current_fd) { + if(current_fd->fd == fd) { + if(current_fd->prev) + current_fd->prev->next = current_fd->next; + else + *fd_list = current_fd->next; + if(current_fd->next) + current_fd->next->prev = current_fd->prev; + free(current_fd); + + return; + } + + current_fd = current_fd->next; + } +} + +void add_dir(dir_list_t **dir_list, DIR *dir) +{ + dir_list_t *new_dir; + + new_dir = my_malloc( sizeof(dir_list_t) ); + new_dir->dir = dir; + new_dir->next = *dir_list; + new_dir->prev = NULL; + + *dir_list = new_dir; +} + +void remove_dir(dir_list_t **dir_list, DIR *dir) +{ + dir_list_t *current_dir = *dir_list; + + while(current_dir) { + if(current_dir->dir == dir) { + if(current_dir->prev) + current_dir->prev->next = current_dir->next; + else + *dir_list = current_dir->next; + if(current_dir->next) + current_dir->next->prev = current_dir->prev; + free(current_dir); + + return; + } + + current_dir = current_dir->next; + } +} + +void close_all_fds(fd_list_t **fd_list) +{ + while(*fd_list) { + int retries; + + for(retries = 0; retries < CLOSE_MAX_RETRIES && + close((*fd_list)->fd) == -1 && + errno == EINTR; + retries++); + remove_fd(fd_list, (*fd_list)->fd); + } +} + +void close_all_dirs(dir_list_t **dir_list) +{ + while(*dir_list) { + int retries; + + for(retries = 0; retries < CLOSE_MAX_RETRIES && + closedir((*dir_list)->dir) == -1 && + errno == EINTR; + retries++); + remove_dir(dir_list, (*dir_list)->dir); + } +} + +void add_mount(char *root_name) +{ + mount_list_t *new_mount; + + new_mount = (mount_list_t *)my_malloc( sizeof(mount_list_t) ); + new_mount->root_name = my_strdup(root_name); + + new_mount->next = mount_list; + new_mount->prev = NULL; + new_mount->fd_list = NULL; + new_mount->dir_list = NULL; + if(mount_list) + mount_list->prev = new_mount; + + mount_list = new_mount; +} + + +void remove_mount(char *root_name) +{ + mount_list_t *current_mount = mount_list; + + while(current_mount) { + if( strcmp(root_name, current_mount->root_name) == 0) { + free(current_mount->root_name); + if(current_mount->prev) + current_mount->prev->next = current_mount->next; + else + mount_list = current_mount->next; + if(current_mount->next) + current_mount->next->prev = current_mount->prev; + free(current_mount); + + return; + } + + current_mount = current_mount->next; + } +} + +int make_mount_point(char *root_name) +{ + char *dir_tmp; + int i; + + // First create the mount_point_directory + dir_tmp = my_strdup(mount_point_directory); + for(i = 0; dir_tmp[i]; i++) + if(dir_tmp[i] == '/' && i != 0) { + dir_tmp[i] = '\0'; + if(mkdir(dir_tmp, 0700) == -1 && errno != EEXIST) { + fprintf(stderr, "Cannot create directory: %s (%s)\n", + dir_tmp, strerror(errno)); + return 0; + } + dir_tmp[i] = '/'; + } + free(dir_tmp); + + // Create the mount point + dir_tmp = my_malloc(strlen(mount_point_directory) + 2 + strlen(root_name)); + strcpy(dir_tmp, mount_point_directory); + strcat(dir_tmp, "/"); + strcat(dir_tmp, root_name); + + if(mkdir(dir_tmp, 0700) == -1 && errno != EEXIST) { + fprintf(stderr, "Cannot create directory: %s (%s)\n", + dir_tmp, strerror(errno)); + return 0; + } + free(dir_tmp); + + return 1; +} + + +// !!FIXME!! allow escaping of %'s +char *expand_template(char *template, char *mount_point, char *root_name) +{ + int len = 0; + int i; + char *expanded_name; + char *expanded_name_start; + + // calculate length + for(i = 0; template[i]; i++) + if(template[i] == '%') { + switch(template[i + 1]) + { + case 'm': + len += strlen(mount_point); + i++; + break; + case 'r': + len += strlen(root_name); + i++; + break; + } + } else + len++; + + expanded_name_start = expanded_name = my_malloc(len + 1); + + for(i = 0; template[i]; i++) + if(template[i] == '%') { + int j = 0; + switch(template[i + 1]) + { + case 'm': + while(mount_point[j]) + *expanded_name++ = mount_point[j++]; + i++; + break; + case 'r': + while(root_name[j]) + *expanded_name++ = root_name[j++]; + i++; + break; + } + } else + *expanded_name++ = template[i]; + + *expanded_name = '\0'; + + return expanded_name_start; +} + +int do_mount(char *root_name) +{ + char *mount_point; + char *mount_command; + mount_list_t *mount; + int sysret; + + fprintf(stderr, "Mounting: %s\n", root_name); + + if( !make_mount_point(root_name) ) { + fprintf(stderr, "Failed to create mount point directory: %s/%s\n", + mount_point_directory, root_name); + return 0; + } + + mount_point = alloca(strlen(mount_point_directory) + 2 + strlen(root_name)); + sprintf(mount_point, "%s/%s", mount_point_directory, root_name); + + mount_command = expand_template(user_options.mount_command_template, + mount_point, root_name); + sysret = system(mount_command); + free(mount_command); + + fprintf(stderr, "sysret: %.8x\n", sysret); + + if(sysret) { + fprintf(stderr, "Failed to invoke mount command: \"%s\" (%s)\n", + mount_command, sysret != -1 ? + "Error executing mount" : + strerror(errno)); + + // remove the now unused directory + if( rmdir(mount_point) == -1 ) + fprintf(stderr, "Failed to remove mount point dir: %s (%s)", + mount_point, strerror(errno)); + + return 0; + } + + add_mount(root_name); + + return 1; +} + +int do_umount(char *root_name) +{ + char *mount_point; + char *unmount_command; + mount_list_t *mount; + int sysret; + + fprintf(stderr, "Unmounting: %s\n", root_name); + + mount = find_mount(root_name); + if(!mount) { + fprintf(stderr, "Internal Error: tried to unmount non-existant mount point: %s\n", root_name); + return 1; + } + + mount_point = alloca(strlen(mount_point_directory) + 2 + strlen(root_name)); + sprintf(mount_point, "%s/%s", mount_point_directory, root_name); + + unmount_command = expand_template(user_options.unmount_command_template, + mount_point, root_name); + sysret = system(unmount_command); + free(unmount_command); + if(sysret) { + fprintf(stderr, "Failed to invoke unmount command: \"%s\" (%s)\n", + unmount_command, sysret != -1 ? + "Error executing mount" : + strerror(errno)); + return 0; + } + + // tidy up after succesful unmount + remove_mount(root_name); + if( rmdir(mount_point) == -1 ) + fprintf(stderr, "Failed to remove mount point dir: %s (%s)", + mount_point, strerror(errno)); + + return 1; +} + +void unmount_all(void) +{ + fprintf(stderr, "Attemping to unmount all filesystems:\n"); + + while(mount_list) { + fprintf(stderr, "\tUnmounting: %s\n", mount_list->root_name); + + // if unmount fails, ditch the mount anyway + if( !do_umount(mount_list->root_name) ) + remove_mount(mount_list->root_name); + } + + fprintf(stderr, "done.\n"); +} + +void shutdown(void) +{ + unmount_all(); + + if(rmdir(mount_point_directory) == -1) + fprintf(stderr, "Failed to remove temporary mount point directory: %s (%s)\n", + mount_point_directory, strerror(errno)); +} + +int max_path_out_len(const char *path_in) +{ + return strlen(mount_point_directory) + strlen(path_in) + 2; +} + +// returns true if path is the a child directory of a root node +// e.g. /a/b is a child, /a is not. +int extract_root_name(const char *path, char *root_name) +{ + int i; + int is_child; + + for(i = 1; path[i] && path[i] != '/'; i++) + root_name[i - 1] = path[i]; + root_name[i - 1] = '\0'; + + return strlen(&path[i]); +} + +typedef enum {PROC_PATH_FAILED, PROC_PATH_ROOT_DIR, PROC_PATH_PROXY_DIR} proc_result_t; + +proc_result_t process_path(const char *path_in, char *path_out, int attempt_mount) +{ + int i; + char *root_name = alloca(strlen(path_in)); + char *path_out_base; + int is_child; + + fprintf(stderr, "Path in: %s\n", path_in); + is_child = extract_root_name(path_in, root_name); + fprintf(stderr, "root_name is: %s\n", root_name); + + // Mount filesystem if neccessary + // the combination of is_child and attempt_mount prevent inappropriate + // mounting of a filesystem for example if the user tries to mknod + // in the afuse root this should cause an error not a mount. + // !!FIXME!! this is broken on FUSE < 2.5 (?) because a getattr + // on the root node seems to occur with every single access. + if( //(is_child || attempt_mount ) && + strlen(root_name) > 0 && + !is_mount(root_name) && + !do_mount(root_name)) + return PROC_PATH_FAILED; + + // construct path_out (mount_point_directory + '/' + path_in + '\0') + path_out_base = path_out; + for(i = 0; i < strlen(mount_point_directory); i++) + *path_out++ = mount_point_directory[i]; + *path_out++ = '/'; + for(i = 0; i < strlen(path_in) - 1; i++) + *path_out++ = path_in[i + 1]; + *path_out = '\0'; + fprintf(stderr, "Path out: %s\n", path_out_base); + + return strlen(root_name) ? PROC_PATH_PROXY_DIR : PROC_PATH_ROOT_DIR; +} + +static int afuse_getattr(const char *path, struct stat *stbuf) +{ + int res; + char *root_name = alloca( strlen(path) ); + char *real_path = alloca( max_path_out_len(path) ); + + fprintf(stderr, "> GetAttr\n"); + + switch( process_path(path, real_path, 0) ) + { + case PROC_PATH_FAILED: + return -ENXIO; + + case PROC_PATH_ROOT_DIR: + extract_root_name(path, root_name); + fprintf(stderr, "Getattr on: (%s) - %s\n", path, root_name); + if( is_mount(root_name) || strlen(root_name) == 0) { + stbuf->st_mode = S_IFDIR | 0700; + stbuf->st_nlink = 1; + stbuf->st_uid = getuid(); + stbuf->st_gid = getgid(); + stbuf->st_size = 0; + stbuf->st_blksize = 0; + stbuf->st_blocks = 0; + stbuf->st_atime = 0; + stbuf->st_mtime = 0; + stbuf->st_ctime = 0; + + return 0; + } else + return -ENOENT; + + case PROC_PATH_PROXY_DIR: + res = lstat(real_path, stbuf); + if (res == -1) + return -errno; + + return 0; + } +} + + +static int afuse_readlink(const char *path, char *buf, size_t size) +{ + int res; + char *real_path = alloca( max_path_out_len(path) ); + + switch( process_path(path, real_path, 1) ) + { + case PROC_PATH_FAILED: + return -ENXIO; + + case PROC_PATH_ROOT_DIR: + return -ENOENT; + + case PROC_PATH_PROXY_DIR: + res = readlink(real_path, buf, size - 1); + if (res == -1) + return -errno; + + buf[res] = '\0'; + return 0; + } +} + +static int afuse_opendir(const char *path, struct fuse_file_info *fi) +{ + DIR *dp; + char *root_name = alloca( strlen(path) ); + mount_list_t *mount; + char *real_path = alloca( max_path_out_len(path) ); + + switch( process_path(path, real_path, 1) ) + { + case PROC_PATH_FAILED: + return -ENXIO; + + case PROC_PATH_ROOT_DIR: + return 0; + + case PROC_PATH_PROXY_DIR: + dp = opendir(real_path); + + if (dp == NULL) + return -errno; + + fi->fh = (unsigned long) dp; + extract_root_name(path, root_name); + mount = find_mount(root_name); + if(mount) + add_dir(&mount->dir_list, dp); + return 0; + } +} + +static inline DIR *get_dirp(struct fuse_file_info *fi) +{ + return (DIR *) (uintptr_t) fi->fh; +} + +static int afuse_readdir(const char *path, void *buf, fuse_fill_dir_t filler, + off_t offset, struct fuse_file_info *fi) +{ + DIR *dp = get_dirp(fi); + struct dirent *de; + char *real_path = alloca( max_path_out_len(path) ); + mount_list_t *mount; + + switch( process_path(path, real_path, 1) ) + { + case PROC_PATH_FAILED: + return -ENXIO; + + case PROC_PATH_ROOT_DIR: + filler(buf, ".", NULL, 0); + filler(buf, "..", NULL, 0); + for(mount = mount_list; mount; mount = mount->next) + filler(buf, mount->root_name, NULL, 0); + return 0; + + case PROC_PATH_PROXY_DIR: + seekdir(dp, offset); + while ((de = readdir(dp)) != NULL) { + struct stat st; + memset(&st, 0, sizeof(st)); + st.st_ino = de->d_ino; + st.st_mode = de->d_type << 12; + if (filler(buf, de->d_name, &st, telldir(dp))) + break; + } + + return 0; + } +} + +static int afuse_releasedir(const char *path, struct fuse_file_info *fi) +{ + DIR *dp = get_dirp(fi); + mount_list_t *mount; + char *root_name = alloca( strlen(path) ); + + char *real_path = alloca( max_path_out_len(path) ); + + switch( process_path(path, real_path, 1) ) + { + case PROC_PATH_FAILED: + return -ENXIO; + + case PROC_PATH_ROOT_DIR: + return 0; + + case PROC_PATH_PROXY_DIR: + extract_root_name(path, root_name); + mount = find_mount(root_name); + if(mount) + remove_dir(&mount->dir_list, dp); + + closedir(dp); + + return 0; + } +} + +static int afuse_mknod(const char *path, mode_t mode, dev_t rdev) +{ + int res; + char *real_path = alloca( max_path_out_len(path) ); + + fprintf(stderr, "> Mknod\n"); + + switch( process_path(path, real_path, 0) ) + { + case PROC_PATH_FAILED: + return -ENXIO; + + case PROC_PATH_ROOT_DIR: + return -ENOTSUP; + + case PROC_PATH_PROXY_DIR: + if (S_ISFIFO(mode)) + res = mkfifo(real_path, mode); + else + res = mknod(real_path, mode, rdev); + if (res == -1) + return -errno; + + return 0; + } +} + +static int afuse_mkdir(const char *path, mode_t mode) +{ + int res; + char *real_path = alloca( max_path_out_len(path) ); + + switch( process_path(path, real_path, 0) ) + { + case PROC_PATH_FAILED: + return -ENXIO; + + case PROC_PATH_ROOT_DIR: + return -ENOTSUP; + + case PROC_PATH_PROXY_DIR: + res = mkdir(real_path, mode); + if (res == -1) + return -errno; + + return 0; + } +} + +static int afuse_unlink(const char *path) +{ + int res; + char *real_path = alloca( max_path_out_len(path) ); + + switch( process_path(path, real_path, 0) ) + { + case PROC_PATH_FAILED: + return -ENXIO; + + case PROC_PATH_ROOT_DIR: + return -ENOTSUP; + + case PROC_PATH_PROXY_DIR: + res = unlink(real_path); + if (res == -1) + return -errno; + + return 0; + } +} + +static int afuse_rmdir(const char *path) +{ + int res; + char *real_path = alloca( max_path_out_len(path) ); + + switch( process_path(path, real_path, 0) ) + { + case PROC_PATH_FAILED: + return -ENXIO; + + case PROC_PATH_ROOT_DIR: + return -ENOTSUP; + + case PROC_PATH_PROXY_DIR: + res = rmdir(real_path); + if (res == -1) + return -errno; + + return 0; + } +} + +static int afuse_symlink(const char *from, const char *to) +{ + int res; + char *real_to_path = alloca( max_path_out_len(to) ); + + switch( process_path(to, real_to_path, 0) ) + { + case PROC_PATH_FAILED: + return -ENXIO; + + case PROC_PATH_ROOT_DIR: + return -ENOTSUP; + + case PROC_PATH_PROXY_DIR: + res = symlink(from, real_to_path); + if (res == -1) + return -errno; + + return 0; + } +} + +static int afuse_rename(const char *from, const char *to) +{ + int res; + char *real_from_path = alloca( max_path_out_len(from) ); + char *real_to_path = alloca( max_path_out_len(to) ); + + switch( process_path(from, real_from_path, 0) ) + { + case PROC_PATH_FAILED: + return -ENXIO; + + case PROC_PATH_ROOT_DIR: + return -ENOTSUP; + + case PROC_PATH_PROXY_DIR: + switch( process_path(to, real_to_path, 0) ) + { + case PROC_PATH_FAILED: + return -ENXIO; + + case PROC_PATH_ROOT_DIR: + return -ENOTSUP; + + case PROC_PATH_PROXY_DIR: + res = rename(real_from_path, real_to_path); + if (res == -1) + return -errno; + + return 0; + } + } +} + +static int afuse_link(const char *from, const char *to) +{ + int res; + char *real_from_path = alloca( max_path_out_len(from) ); + char *real_to_path = alloca( max_path_out_len(to) ); + + switch( process_path(from, real_from_path, 0) ) + { + case PROC_PATH_FAILED: + return -ENXIO; + + case PROC_PATH_ROOT_DIR: + return -ENOTSUP; + + case PROC_PATH_PROXY_DIR: + switch( process_path(to, real_to_path, 0) ) + { + case PROC_PATH_FAILED: + return -ENXIO; + + case PROC_PATH_ROOT_DIR: + return -ENOTSUP; + + case PROC_PATH_PROXY_DIR: + res = link(real_from_path, real_to_path); + if (res == -1) + return -errno; + + return 0; + } + } +} + +static int afuse_chmod(const char *path, mode_t mode) +{ + int res; + char *real_path = alloca( max_path_out_len(path) ); + + switch( process_path(path, real_path, 0) ) + { + case PROC_PATH_FAILED: + return -ENXIO; + + case PROC_PATH_ROOT_DIR: + return -ENOTSUP; + + case PROC_PATH_PROXY_DIR: + res = chmod(real_path, mode); + if (res == -1) + return -errno; + + return 0; + } +} + +static int afuse_chown(const char *path, uid_t uid, gid_t gid) +{ + int res; + char *real_path = alloca( max_path_out_len(path) ); + + switch( process_path(path, real_path, 0) ) + { + case PROC_PATH_FAILED: + return -ENXIO; + + case PROC_PATH_ROOT_DIR: + return -ENOTSUP; + + case PROC_PATH_PROXY_DIR: + res = lchown(real_path, uid, gid); + if (res == -1) + return -errno; + + return 0; + } +} + +static int afuse_truncate(const char *path, off_t size) +{ + int res; + char *real_path = alloca( max_path_out_len(path) ); + + switch( process_path(path, real_path, 0) ) + { + case PROC_PATH_FAILED: + return -ENXIO; + + case PROC_PATH_ROOT_DIR: + return -ENOTSUP; + + case PROC_PATH_PROXY_DIR: + res = truncate(real_path, size); + if (res == -1) + return -errno; + + return 0; + } +} + + +static int afuse_utime(const char *path, struct utimbuf *buf) +{ + int res; + char *real_path = alloca( max_path_out_len(path) ); + + switch( process_path(path, real_path, 0) ) + { + case PROC_PATH_FAILED: + return -ENXIO; + + case PROC_PATH_ROOT_DIR: + return -ENOTSUP; + + case PROC_PATH_PROXY_DIR: + res = utime(real_path, buf); + if (res == -1) + return -errno; + + return 0; + } +} + + +static int afuse_open(const char *path, struct fuse_file_info *fi) +{ + int fd; + char *root_name = alloca( strlen(path) ); + mount_list_t *mount; + char *real_path = alloca( max_path_out_len(path) ); + + switch( process_path(path, real_path, 1) ) + { + case PROC_PATH_FAILED: + return -ENXIO; + + case PROC_PATH_ROOT_DIR: + return -ENOENT; + + case PROC_PATH_PROXY_DIR: + fd = open(real_path, fi->flags); + if (fd == -1) + return -errno; + + fi->fh = fd; + extract_root_name(path, root_name); + mount = find_mount(root_name); + if(mount) + add_fd(&mount->fd_list, fd); + return 0; + } +} + +static int afuse_read(const char *path, char *buf, size_t size, off_t offset, + struct fuse_file_info *fi) +{ + int res; + + (void)path; + res = pread(fi->fh, buf, size, offset); + if (res == -1) + res = -errno; + + return res; +} + +static int afuse_write(const char *path, const char *buf, size_t size, + off_t offset, struct fuse_file_info *fi) +{ + int res; + + (void) path; + res = pwrite(fi->fh, buf, size, offset); + if (res == -1) + res = -errno; + + return res; +} + + +static int afuse_release(const char *path, struct fuse_file_info *fi) +{ + char *root_name = alloca( strlen(path) ); + mount_list_t *mount; + + extract_root_name(path, root_name); + mount = find_mount(root_name); + if(mount) + remove_fd(&mount->fd_list, fi->fh); + + close(fi->fh); + + return 0; +} + +static int afuse_fsync(const char *path, int isdatasync, + struct fuse_file_info *fi) +{ + int res; + (void) path; + + #ifndef HAVE_FDATASYNC + (void) isdatasync; + #else + if (isdatasync) + res = fdatasync(fi->fh); + else + #endif + res = fsync(fi->fh); + if (res == -1) + return -errno; + + return 0; +} + +#if FUSE_VERSION >= 25 +static int afuse_access(const char *path, int mask) +{ + int res; + char *real_path = alloca( max_path_out_len(path) ); + + switch( process_path(path, real_path, 1) ) + { + case PROC_PATH_FAILED: + return -ENXIO; + + case PROC_PATH_ROOT_DIR: + case PROC_PATH_PROXY_DIR: + res = access(real_path, mask); + if (res == -1) + return -errno; + + return 0; + } +} + +static int afuse_ftruncate(const char *path, off_t size, + struct fuse_file_info *fi) +{ + int res; + + (void) path; + + res = ftruncate(fi->fh, size); + if (res == -1) + return -errno; + + return 0; +} + +static int afuse_create(const char *path, mode_t mode, struct fuse_file_info *fi) +{ + int fd; + char *real_path = alloca( max_path_out_len(path) ); + + switch( process_path(path, real_path, 0) ) + { + case PROC_PATH_FAILED: + return -ENXIO; + + case PROC_PATH_ROOT_DIR: + return -ENOTSUP; + + case PROC_PATH_PROXY_DIR: + fd = open(real_path, fi->flags, mode); + if (fd == -1) + return -errno; + + fi->fh = fd; + return 0; + } +} + +static int afuse_fgetattr(const char *path, struct stat *stbuf, + struct fuse_file_info *fi) +{ + int res; + + (void) path; + + res = fstat(fi->fh, stbuf); + if (res == -1) + return -errno; + + return 0; +} +#endif + + +#if FUSE_VERSION >= 25 +static int afuse_statfs(const char *path, struct statvfs *stbuf) +#else +static int afuse_statfs(const char *path, struct statfs *stbuf) +#endif +{ + int res; + char *real_path = alloca( max_path_out_len(path) ); + + switch( process_path(path, real_path, 1) ) + { + case PROC_PATH_FAILED: + return -ENXIO; + + case PROC_PATH_ROOT_DIR: +#if FUSE_VERSION >= 25 + stbuf->f_namemax = 0x7fffffff; + stbuf->f_frsize = 512; +#else + stbuf->f_namelen = 0x7fffffff; +#endif + stbuf->f_bsize = 1024; + stbuf->f_blocks = 0; + stbuf->f_bfree = 0; + stbuf->f_bavail = 0; + stbuf->f_files = 0; + stbuf->f_ffree = 0; + return 0; + + case PROC_PATH_PROXY_DIR: + res = statvfs(real_path, stbuf); + if (res == -1) + return -errno; + + return 0; + } +} + +void afuse_destroy(void *p) +{ + shutdown(); +} + +#ifdef HAVE_SETXATTR +/* xattr operations are optional and can safely be left unimplemented */ +static int afuse_setxattr(const char *path, const char *name, const char *value, + size_t size, int flags) +{ + int res; + char *real_path = alloca( max_path_out_len(path) ); + + switch( process_path(path, real_path, 0) ) + { + case PROC_PATH_FAILED: + return -ENXIO; + + case PROC_PATH_ROOT_DIR: + return -ENOENT; + + case PROC_PATH_PROXY_DIR: + res = lsetxattr(real_path, name, value, size, flags); + if (res == -1) + return -errno; + return 0; + } +} + +static int afuse_getxattr(const char *path, const char *name, char *value, + size_t size) +{ + int res; + char *real_path = alloca( max_path_out_len(path) ); + + switch( process_path(path, real_path, 1) ) + { + case PROC_PATH_FAILED: + return -ENXIO; + + case PROC_PATH_ROOT_DIR: + return -ENOTSUP; + + case PROC_PATH_PROXY_DIR: + res = lgetxattr(real_path, name, value, size); + if (res == -1) + return -errno; + return res; + } +} + +static int afuse_listxattr(const char *path, char *list, size_t size) +{ + int res; + char *real_path = alloca( max_path_out_len(path) ); + + switch( process_path(path, real_path, 1) ) + { + case PROC_PATH_FAILED: + return -ENXIO; + + case PROC_PATH_ROOT_DIR: + return -ENOTSUP; + + case PROC_PATH_PROXY_DIR: + res = llistxattr(real_path, list, size); + if (res == -1) + return -errno; + return res; + } +} + +static int afuse_removexattr(const char *path, const char *name) +{ + int res; + char *real_path = alloca( max_path_out_len(path) ); + + switch( process_path(path, real_path, 0) ) + { + case PROC_PATH_FAILED: + return -ENXIO; + + case PROC_PATH_ROOT_DIR: + return -ENOTSUP; + + case PROC_PATH_PROXY_DIR: + res = lremovexattr(real_path, name); + if (res == -1) + return -errno; + return 0; + } +} +#endif /* HAVE_SETXATTR */ + +static struct fuse_operations afuse_oper = { + .getattr = afuse_getattr, + .readlink = afuse_readlink, + .opendir = afuse_opendir, + .readdir = afuse_readdir, + .releasedir = afuse_releasedir, + .mknod = afuse_mknod, + .mkdir = afuse_mkdir, + .symlink = afuse_symlink, + .unlink = afuse_unlink, + .rmdir = afuse_rmdir, + .rename = afuse_rename, + .link = afuse_link, + .chmod = afuse_chmod, + .chown = afuse_chown, + .truncate = afuse_truncate, + .utime = afuse_utime, + .open = afuse_open, + .read = afuse_read, + .write = afuse_write, + .release = afuse_release, + .fsync = afuse_fsync, + .statfs = afuse_statfs, +#if FUSE_VERSION >= 25 + .access = afuse_access, + .create = afuse_create, + .ftruncate = afuse_ftruncate, + .fgetattr = afuse_fgetattr, +#endif + .destroy = afuse_destroy, +#ifdef HAVE_SETXATTR + .setxattr = afuse_setxattr, + .getxattr = afuse_getxattr, + .listxattr = afuse_listxattr, + .removexattr = afuse_removexattr, +#endif +}; + + +enum { + KEY_HELP +}; + +#define AFUSE_OPT(t, p, v) { t, offsetof(struct user_options_t, p), v } + +static struct fuse_opt afuse_opts[] = { + AFUSE_OPT("mount_template=%s", mount_command_template, 0), + AFUSE_OPT("unmount_template=%s", unmount_command_template, 0), + + FUSE_OPT_KEY("-h", KEY_HELP), + FUSE_OPT_KEY("--help", KEY_HELP), + + FUSE_OPT_END +}; + +static void usage(const char *progname) +{ + fprintf(stderr, +"Usage: %s mountpoint [options]\n" +"\n" +" -o opt,[opt...] mount options\n" +" -h --help print help\n" +" -V --version print FUSE version information\n" +"\n" +"afuse options:\n" +" -o mount_template=CMD template for CMD to execute to mount (*)\n" +" -o unmount_template=CMD template for CMD to execute to unmount (*) (**)\n" +"\n\n" +" (*) - When executed, %%r and %%m are expanded in templates to the root\n" +" directory name for the new mount point, and the actual directory to\n" +" mount onto respectively to mount onto. Both templates are REQUIRED.\n" +"\n" +" (**) - The unmount command must perform a lazy unmount operation. E.g. the\n" +" -u -z options to fusermount, or -l for regular mount.\n" +"\n", progname); +} + +static int afuse_opt_proc(void *data, const char *arg, int key, + struct fuse_args *outargs) +{ + struct user_options_t *user_options = (struct user_options_t *)user_options; + + (void) user_options; + (void) arg; + + switch(key) + { + case KEY_HELP: + usage(outargs->argv[0]); + fuse_opt_add_arg(outargs, "-ho"); + fuse_main(outargs->argc, outargs->argv, &afuse_oper); + exit(1); + + default: + return 1; + } +} + +int main(int argc, char *argv[]) +{ + struct fuse_args args = FUSE_ARGS_INIT(argc, argv); + char *temp_dir_name = my_malloc(strlen(TMP_DIR_TEMPLATE)); + strcpy(temp_dir_name, TMP_DIR_TEMPLATE); + + if(fuse_opt_parse(&args, &user_options, afuse_opts, afuse_opt_proc) == -1) + return 1; + + // !!FIXME!! force single-threading for now as datastructures are not locked + fuse_opt_add_arg(&args, "-s"); + + // Check for required parameters + if(!user_options.mount_command_template || !user_options.unmount_command_template) { + fprintf(stderr, "(Un)Mount command templates missing.\n\n"); + usage(argv[0]); + fuse_opt_add_arg(&args, "-ho"); + fuse_main(args.argc, args.argv, &afuse_oper); + + return 1; + } + + if( !(mount_point_directory = mkdtemp(temp_dir_name)) ) { + fprintf(stderr, "Failed to create temporary mount point dir.\n"); + return 1; + } + + umask(0); + + // Register function to tidy up on exit conditions + if( atexit( shutdown ) ) { + fprintf(stderr, "Failed to register exit handler.\n"); + return 1; + } + + // !!FIXME!! death by signal doesn't unmount fs + return fuse_main(args.argc, args.argv, &afuse_oper); +} -- 2.42.0