pax_global_header00006660000000000000000000000064142050637560014522gustar00rootroot0000000000000052 comment=d7f07c32e58850fa092bb98b53c5c570fed8be69 afuse-0.5.0/000077500000000000000000000000001420506375600126275ustar00rootroot00000000000000afuse-0.5.0/.gitignore000066400000000000000000000002501420506375600146140ustar00rootroot00000000000000Makefile* *.o aclocal.m4 autom4te.cache/ compat/.deps/ config.h config.h.in config.log config.status configure depcomp install-sh missing src/.deps/ src/afuse stamp-h1 afuse-0.5.0/.travis.yml000066400000000000000000000002641420506375600147420ustar00rootroot00000000000000language: c compiler: - gcc before_install: - sudo apt-get update -qq - sudo apt-get install -qq libfuse-dev script: ./autogen.sh && ./configure && make && sudo make install afuse-0.5.0/AUTHORS000066400000000000000000000003001420506375600136700ustar00rootroot00000000000000Jacob Bower - jacob.bower@gmail.com (Original author) Pierre Carrier - pierre@gcarrier.fr (Current maintainer) Henry Gebhardt - hsggebhardt@googlemail.com Anders Kaseorg Jeremy Maitin-Shepard afuse-0.5.0/COPYING000066400000000000000000000431221420506375600136640ustar00rootroot00000000000000 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. afuse-0.5.0/COPYING.LIB000066400000000000000000000613031420506375600142720ustar00rootroot00000000000000 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! afuse-0.5.0/ChangeLog000066400000000000000000000000001420506375600143670ustar00rootroot00000000000000afuse-0.5.0/HACKING000066400000000000000000000045351420506375600136250ustar00rootroot00000000000000Development build ----------------- If you get afuse from git, run ./autogen.sh to generate various autotools scripts and config. Contributing ------------ Help is always welcome. Please feel free to jump in, open issues or submit pull requests. For consistency purposes, please reformat your code using GNU indent: $ indent --linux-style *.h *.c TODO ---- While afuse is basically usable, there are a huge number of things which need doing to afuse to make it "good". Here are a list of some of these: * Support multi-threading - Internal 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). * Rather than umounting an FS to ensure directory changes are flushed, it should be possible to flush a handle to the parent dir instead. * More complex automounting schemes * Different commands based on regex's of virtual directories. * Scriptable multi-level virtual directory hierarchy. * 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 interactive automounting. For example we could pop up an X11 window, or switch to other VTs on a Linux 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 environment needs lots of work. * Exit on signal often isn't clean (directory should be unmounted) (actually this seems to work with FUSE 2.3?) * Mounting 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. afuse-0.5.0/Makefile.am000066400000000000000000000001101420506375600146530ustar00rootroot00000000000000if FUSE_OPT_COMPAT compat_dir = compat endif SUBDIRS=$(compat_dir) src afuse-0.5.0/NEWS000066400000000000000000000021461420506375600133310ustar00rootroot00000000000000Version 0.5.0 ------------- * Adds the -o mount_dir=DIR option, which allows users to specify a directory under which all temporary mounts are made. Version 0.4.1 ------------- * Fix bug where afuse crashes on release Version 0.4 ----------- * Mac OS X 10.6+ and FreeBSD are supported. * Added ability to filter paths from auto-mounting via a file of patterns. * The path 'autorun.inf' is hard-coded as a filter to fix a problem in Ubuntu/GNOME 3 desktop environments where a lookup occurs as soon as any afuse mount is made. * Ability to populate root directory using output from an external process. * Added 'exact_getattr' option. Version 0.2 ----------- * New features: + Timeout-based unmounting. + Forced immediate unmounting by removing root directory of auto mounts. * Fixes/optimisations: + Minor performance tweaks. + Better handling of filesystems which are unexpectedly unmounted. 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 afuse-0.5.0/README000066400000000000000000000106461420506375600135160ustar00rootroot00000000000000afuse 0.5.0 https://github.com/pcarrier/afuse/ 0. Contents ----------- 1. Abstract 2. Basic Usage 3. Pre-populating afuse Root 4. Misc Other Features 5. Important 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 afuse runs entirely in user-space by individual users. Thus it 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 such as asking for a password. afuse is distributed under the GPLv2 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. If you are interested in contributing to afuse, please read the HACKING file. 2. Basic 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. Pre-populating afuse Root ---------------------------- By default the afuse root directory is empty until a specific access is made to a directory leading to successful mount. In some cases it may be useful to pre-populate the afuse root with valid directory names. To enable root directory pre-population, use the -o populate_root_command option to specify a command which will provide a list of directory names to populate the root with. This program will be run for every directory list request on the afuse root directory, and should output one dir entry per-line to stdout. As this program is called repeatedly and for every directory listing it should not block/pause for an unreasonable amount of time. Note that when using this mode no actual mounting occurs until a directory access is made to one of the potential mount-points. An example of this usage is provided in the afuse-avahissh shell script (typically installed alongside afuse). This can be started as follows: afuse-avahissh mountpoint/ This script will use avahi to automatically populate the root directory with hosts advertising their sftp service via Avahi. To work correctly both sshfs and avahi-browse must be installed and available to the script. 4. Misc Other Features ---------------------- * By default afuse does not attempt to mount a directory on a getattr operation. This can be disabled using the -o exact_getattr option. This allows getattr to return accurate information but may cause spurious mounts when programs are just checking for the existence of files. * The -o flushwrites option causes write operation on file-systems mounted by afuse to operate synchronously. 5. Important 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 automounted 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). Hopefully these limitations will be removed in later revisions of afuse. afuse-0.5.0/autogen.sh000077500000000000000000000001021420506375600146210ustar00rootroot00000000000000#!/bin/sh set -e autoreconf --install --verbose ./configure "$@" afuse-0.5.0/compat/000077500000000000000000000000001420506375600141125ustar00rootroot00000000000000afuse-0.5.0/compat/Makefile.am000066400000000000000000000001131420506375600161410ustar00rootroot00000000000000noinst_LIBRARIES = libcompat.a libcompat_a_SOURCES = fuse_opt.c fuse_opt.h afuse-0.5.0/compat/fuse_opt.c000066400000000000000000000174401420506375600161100ustar00rootroot00000000000000/* 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; } afuse-0.5.0/compat/fuse_opt.h000066400000000000000000000145611420506375600161160ustar00rootroot00000000000000/* 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_ */ afuse-0.5.0/configure.ac000066400000000000000000000021611420506375600151150ustar00rootroot00000000000000# -*- Autoconf -*- # Process this file with autoconf to produce a configure script. AC_PREREQ(2.59) AC_INIT([afuse], [0.5.0]) AM_INIT_AUTOMAKE AC_PROG_RANLIB AC_CONFIG_SRCDIR([src/afuse.c]) AC_CONFIG_HEADERS([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 -Wall -Wextra $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 getline fgetln]) AC_CONFIG_FILES([Makefile src/Makefile compat/Makefile]) if test "x$ac_cv_func_getline" = "xno" -a "x$ac_cv_func_fgetln" = "xno"; then AC_MSG_ERROR([Neither getline nor fgetln are available, we can't compile]) fi AC_OUTPUT afuse-0.5.0/src/000077500000000000000000000000001420506375600134165ustar00rootroot00000000000000afuse-0.5.0/src/Makefile.am000066400000000000000000000004131420506375600154500ustar00rootroot00000000000000dist_bin_SCRIPTS=afuse-avahissh bin_PROGRAMS=afuse afuse_SOURCES=afuse.c afuse.h fd_list.c fd_list.h dir_list.c dir_list.h utils.c utils.h variable_pairing_heap.h string_sorted_list.c string_sorted_list.h if FUSE_OPT_COMPAT afuse_LDADD = ../compat/libcompat.a endif afuse-0.5.0/src/afuse-avahissh000077500000000000000000000005561420506375600162610ustar00rootroot00000000000000#!/bin/sh cwd="`dirname "$0"`" mnt_templ="sshfs -o BatchMode=yes %r:/ %m" unmnt_templ="fusermount -u -z %m" pop_root_cmd="avahi-browse -trkp _sftp-ssh._tcp | grep '^=' | cut -d';' -f7" timeout="10s" "$cwd"/afuse -o mount_template="$mnt_templ" -o unmount_template="$unmnt_templ" -o populate_root_command="$pop_root_cmd" -o fsname=sshnet -o timeout="$timeout" "$@" afuse-0.5.0/src/afuse.c000066400000000000000000001240711420506375600146720ustar00rootroot00000000000000/* afuse - An automounter using FUSE Copyright (C) 2008-2013 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 // For getline() #define _GNU_SOURCE #endif #include #include #ifndef __USE_BSD // for mkdtemp #define __USE_BSD #endif #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifdef HAVE_SETXATTR #include #if !HAVE_GETLINE && !HAVE_FGETLN #error Need getline or fgetln #endif #ifdef XATTR_NOFOLLOW #define lgetxattr(p, n, v, s) \ getxattr(p, n, v, s, 0, XATTR_NOFOLLOW) #define lsetxattr(p, n, v, s, f) \ setxattr(p, n, v, s, 0, f | XATTR_NOFOLLOW) #define llistxattr(p, list, s) \ listxattr(p, list, s, XATTR_NOFOLLOW) #define lremovexattr(p, n) \ removexattr(p, n, XATTR_NOFOLLOW) #endif /* XATTR_NOFOLLOW */ #endif /* HAVE_SETXATTR */ #include "fd_list.h" #include "dir_list.h" #include "string_sorted_list.h" #include "utils.h" #include "variable_pairing_heap.h" #define TMP_DIR_TEMPLATE "/tmp/afuse-XXXXXX" #define TMP_DIR_TEMPLATE2 "/afuse-XXXXXX" static char *mount_point_directory; static dev_t mount_point_dev; // Data structure filled in when parsing command line args struct user_options_t { char *mount_command_template; char *unmount_command_template; char *populate_root_command; char *filter_file; bool flush_writes; bool exact_getattr; uint64_t auto_unmount_delay; char *mount_dir; } user_options = { NULL, NULL, NULL, NULL, false, false, UINT64_MAX, NULL }; typedef struct _mount_list_t { struct _mount_list_t *next; struct _mount_list_t *prev; char *root_name; char *mount_point; fd_list_t *fd_list; dir_list_t *dir_list; PH_NEW_LINK(struct _mount_list_t) auto_unmount_ph_node; /* This is the sort key for the auto_unmount_ph heap. It will equal UINT64_MAX if this node is not in the heap. */ int64_t auto_unmount_time; } mount_list_t; typedef struct _mount_filter_list_t { struct _mount_filter_list_t *next; char *pattern; } mount_filter_list_t; PH_DECLARE_TYPE(auto_unmount_ph, mount_list_t) PH_DEFINE_TYPE(auto_unmount_ph, mount_list_t, auto_unmount_ph_node, auto_unmount_time) static mount_filter_list_t *mount_filter_list = NULL; #define BLOCK_SIGALRM \ sigset_t block_sigalrm_oldset, block_sigalrm_set; \ sigemptyset(&block_sigalrm_set); \ sigaddset(&block_sigalrm_set, SIGALRM); \ sigprocmask(SIG_BLOCK, &block_sigalrm_set, &block_sigalrm_oldset) #define UNBLOCK_SIGALRM \ sigprocmask(SIG_SETMASK, &block_sigalrm_oldset, NULL) #define DEFAULT_CASE_INVALID_ENUM \ fprintf(stderr, "Unexpected switch value in %s:%s:%d\n", \ __FILE__, __func__, __LINE__); \ exit(1); static auto_unmount_ph_t auto_unmount_ph; static int64_t auto_unmount_next_timeout = INT64_MAX; static void add_mount_filter(const char *glob) { mount_filter_list_t *new_entry; new_entry = my_malloc(sizeof(mount_filter_list_t)); new_entry->pattern = my_strdup(glob); new_entry->next = mount_filter_list; mount_filter_list = new_entry; } static int is_mount_filtered(const char *mount_point) { mount_filter_list_t *current_filter; current_filter = mount_filter_list; while (current_filter) { if (!fnmatch(current_filter->pattern, mount_point, 0)) return 1; current_filter = current_filter->next; } return 0; } static void load_mount_filter_file(const char *filename) { FILE *filter_file; if ((filter_file = fopen(filename, "r")) == NULL) { fprintf(stderr, "Failed to open filter file '%s'\n", filename); exit(1); } char *line = NULL; ssize_t llen; size_t lsize; #ifdef HAVE_GETLINE while ((llen = getline(&line, &lsize, filter_file)) != -1) #else // HAVE_FGETLN while (line = fgetln(filter_file, &llen)) #endif { if (llen >= 1) { if (line[0] == '#') continue; if (line[llen - 1] == '\n') { line[llen - 1] = '\0'; llen--; } } if (llen > 0) add_mount_filter(line); } free(line); fclose(filter_file); } static int64_t from_timeval(const struct timeval *tv) { return (int64_t) tv->tv_sec * 1000000 + ((int64_t) tv->tv_usec); } static void to_timeval(struct timeval *tv, int64_t usec) { tv->tv_sec = usec / 1000000; tv->tv_usec = usec % 1000000; } static int get_retval(int res) { if (res == -1) return -errno; return 0; } static int check_mount(mount_list_t * mount) { struct stat buf; if (lstat(mount->mount_point, &buf) == -1) return 0; if (buf.st_dev == mount_point_dev) return 0; return 1; } static void update_auto_unmount(mount_list_t * mount) { if (user_options.auto_unmount_delay == UINT64_MAX) return; /* Get the current time */ struct timeval tv; mount_list_t *min_mount; int64_t cur_time, next_time; gettimeofday(&tv, NULL); cur_time = from_timeval(&tv); if (mount) { /* Always remove first */ if (mount->auto_unmount_time != INT64_MAX) auto_unmount_ph_remove(&auto_unmount_ph, mount); if (!mount->fd_list && !mount->dir_list) { mount->auto_unmount_time = cur_time + user_options.auto_unmount_delay; auto_unmount_ph_insert(&auto_unmount_ph, mount); } else { mount->auto_unmount_time = INT64_MAX; } } min_mount = auto_unmount_ph_min(&auto_unmount_ph); next_time = min_mount ? min_mount->auto_unmount_time : INT64_MAX; if (next_time != auto_unmount_next_timeout) { struct itimerval itv; auto_unmount_next_timeout = next_time; if (next_time != INT64_MAX) { if (next_time > cur_time) to_timeval(&itv.it_value, next_time - cur_time); else /* Timer is set to expire immediately --- set it to 1 instead */ to_timeval(&itv.it_value, 1); } else { /* Disable the timer */ to_timeval(&itv.it_value, 0); } to_timeval(&itv.it_interval, 0); if (setitimer(ITIMER_REAL, &itv, NULL) != 0) { perror("Error setting timer"); } } } int do_umount(mount_list_t * mount); static void handle_auto_unmount_timer(int x) { (void)x; /* Ignored */ /* Get the current time */ struct timeval tv; int64_t cur_time; mount_list_t *mount; gettimeofday(&tv, NULL); cur_time = from_timeval(&tv); while ((mount = auto_unmount_ph_min(&auto_unmount_ph)) != NULL && mount->auto_unmount_time <= cur_time) { do_umount(mount); } update_auto_unmount(NULL); } mount_list_t *mount_list = NULL; mount_list_t *find_mount(const 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(const char *root_name) { return find_mount(root_name) ? 1 : 0; } mount_list_t *add_mount(const char *root_name, char *mount_point) { 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->mount_point = mount_point; new_mount->next = mount_list; new_mount->prev = NULL; new_mount->fd_list = NULL; new_mount->dir_list = NULL; new_mount->auto_unmount_time = INT64_MAX; if (mount_list) mount_list->prev = new_mount; mount_list = new_mount; update_auto_unmount(new_mount); return new_mount; } void remove_mount(mount_list_t * current_mount) { if (current_mount->auto_unmount_time != INT64_MAX) auto_unmount_ph_remove(&auto_unmount_ph, current_mount); free(current_mount->root_name); free(current_mount->mount_point); 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); update_auto_unmount(NULL); } char *make_mount_point(const char *root_name) { char *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)); free(dir_tmp); return NULL; } return dir_tmp; } // Note: this method strips out quotes and applies them itself as should be appropriate bool run_template(const char *template, const char *mount_point, const char *root_name) { int len = 0; int nargs = 1; int i; char *buf; char *p; char **args; char **arg; bool quote = false; pid_t pid; int status; // 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; case '%': len++; i++; break; } } else if (template[i] == ' ' && !quote) { len++; nargs++; } else if (template[i] == '"') quote = !quote; else if (template[i] == '\\' && template[i + 1]) len++, i++; else len++; buf = my_malloc(len + 1); args = my_malloc((nargs + 1) * sizeof(*args)); p = buf; arg = args; *arg++ = p; for (i = 0; template[i]; i++) if (template[i] == '%') { switch (template[i + 1]) { case 'm': strcpy(p, mount_point); p += strlen(mount_point); i++; break; case 'r': strcpy(p, root_name); p += strlen(root_name); i++; break; case '%': *p++ = '%'; i++; break; } } else if (template[i] == ' ' && !quote) { *p++ = '\0'; *arg++ = p; } else if (template[i] == '"') quote = !quote; else if (template[i] == '\\' && template[i + 1]) *p++ = template[++i]; else *p++ = template[i]; *p = '\0'; *arg = NULL; pid = fork(); if (pid == -1) { fprintf(stderr, "Failed to fork (%s)\n", strerror(errno)); free(args); free(buf); return false; } if (pid == 0) { execvp(args[0], args); abort(); } pid = waitpid(pid, &status, 0); if (pid == -1) { fprintf(stderr, "Failed to waitpid (%s)\n", strerror(errno)); free(args); free(buf); return false; } if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) { fprintf(stderr, "Failed to invoke command: %s\n", args[0]); free(args); free(buf); return false; } free(args); free(buf); return true; } mount_list_t *do_mount(const char *root_name) { char *mount_point; mount_list_t *mount; fprintf(stderr, "Mounting: %s\n", root_name); if (!(mount_point = make_mount_point(root_name))) { fprintf(stderr, "Failed to create mount point directory: %s/%s\n", mount_point_directory, root_name); return NULL; } if (!run_template(user_options.mount_command_template, mount_point, root_name)) { // remove the now unused directory if (rmdir(mount_point) == -1) fprintf(stderr, "Failed to remove mount point dir: %s (%s)", mount_point, strerror(errno)); free(mount_point); return NULL; } mount = add_mount(root_name, mount_point); return mount; } int do_umount(mount_list_t * mount) { fprintf(stderr, "Unmounting: %s\n", mount->root_name); run_template(user_options.unmount_command_template, mount->mount_point, mount->root_name); /* Still unmount anyway */ if (rmdir(mount->mount_point) == -1) fprintf(stderr, "Failed to remove mount point dir: %s (%s)", mount->mount_point, strerror(errno)); remove_mount(mount); return 1; } void unmount_all(void) { fprintf(stderr, "Attempting to unmount all filesystems:\n"); while (mount_list) { fprintf(stderr, "\tUnmounting: %s\n", mount_list->root_name); do_umount(mount_list); } fprintf(stderr, "done.\n"); } void shutdown(void) { BLOCK_SIGALRM; unmount_all(); UNBLOCK_SIGALRM; 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 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; 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_ROOT_SUBDIR, PROC_PATH_PROXY_DIR } proc_result_t; proc_result_t process_path(const char *path_in, char *path_out, char *root_name, int attempt_mount, mount_list_t ** out_mount) { char *path_out_base; int is_child; int len; mount_list_t *mount = NULL; *out_mount = NULL; 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); if (is_mount_filtered(root_name)) return PROC_PATH_FAILED; // Mount filesystem if necessary // 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 && !(mount = find_mount(root_name)) && !(mount = do_mount(root_name))) return PROC_PATH_FAILED; if (mount && !check_mount(mount)) { do_umount(mount); mount = do_mount(root_name); if (!mount) return PROC_PATH_FAILED; } // construct path_out (mount_point_directory + '/' + path_in + '\0') path_out_base = path_out; len = strlen(mount_point_directory); memcpy(path_out, mount_point_directory, len); path_out += len; *path_out++ = '/'; len = strlen(path_in) - 1; memcpy(path_out, path_in + 1, len); path_out += len; *path_out = '\0'; fprintf(stderr, "Path out: %s\n", path_out_base); *out_mount = mount; if (is_child) return PROC_PATH_PROXY_DIR; else if (strlen(root_name)) return PROC_PATH_ROOT_SUBDIR; else return PROC_PATH_ROOT_DIR; } static int afuse_getattr(const char *path, struct stat *stbuf) { char *root_name = alloca(strlen(path)); char *real_path = alloca(max_path_out_len(path)); int retval; mount_list_t *mount; BLOCK_SIGALRM; fprintf(stderr, "> GetAttr\n"); switch (process_path(path, real_path, root_name, 0, &mount)) { case PROC_PATH_FAILED: retval = -ENXIO; break; case PROC_PATH_ROOT_DIR: fprintf(stderr, "Getattr on: (%s) - %s\n", path, root_name); 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; retval = 0; break; case PROC_PATH_ROOT_SUBDIR: if (user_options.exact_getattr) /* try to mount it */ process_path(path, real_path, root_name, 1, &mount); if (!mount) { stbuf->st_mode = S_IFDIR | 0000; if (!user_options.exact_getattr) stbuf->st_mode = S_IFDIR | 0750; 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; retval = 0; break; } case PROC_PATH_PROXY_DIR: retval = get_retval(lstat(real_path, stbuf)); break; default: DEFAULT_CASE_INVALID_ENUM; } if (mount) update_auto_unmount(mount); UNBLOCK_SIGALRM; return retval; } static int afuse_readlink(const char *path, char *buf, size_t size) { int res; char *root_name = alloca(strlen(path)); char *real_path = alloca(max_path_out_len(path)); int retval; mount_list_t *mount; BLOCK_SIGALRM; switch (process_path(path, real_path, root_name, 1, &mount)) { case PROC_PATH_FAILED: retval = -ENXIO; break; case PROC_PATH_ROOT_DIR: retval = -ENOENT; break; case PROC_PATH_ROOT_SUBDIR: if (!mount) { retval = -ENOENT; break; } case PROC_PATH_PROXY_DIR: res = readlink(real_path, buf, size - 1); if (res == -1) { retval = -errno; break; } buf[res] = '\0'; retval = 0; break; default: DEFAULT_CASE_INVALID_ENUM; } if (mount) update_auto_unmount(mount); UNBLOCK_SIGALRM; return retval; } 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)); int retval; BLOCK_SIGALRM; switch (process_path(path, real_path, root_name, 1, &mount)) { case PROC_PATH_FAILED: retval = -ENXIO; break; case PROC_PATH_ROOT_DIR: retval = 0; break; case PROC_PATH_ROOT_SUBDIR: if (!mount) { retval = -EACCES; fi->fh = 0lu; break; } case PROC_PATH_PROXY_DIR: dp = opendir(real_path); if (dp == NULL) { retval = -errno; break; } fi->fh = (unsigned long)dp; if (mount) dir_list_add(&mount->dir_list, dp); retval = 0; break; default: DEFAULT_CASE_INVALID_ENUM; } if (mount) update_auto_unmount(mount); UNBLOCK_SIGALRM; return retval; } static inline DIR *get_dirp(struct fuse_file_info *fi) { return (DIR *) (uintptr_t) fi->fh; } int populate_root_dir(char *pop_cmd, struct list_t **dir_entry_listptr, fuse_fill_dir_t filler, void *buf) { FILE *browser; size_t hsize = 0; ssize_t hlen; char *dir_entry = NULL; if (!pop_cmd) return -1; if ((browser = popen(pop_cmd, "r")) == NULL) { fprintf(stderr, "Failed to execute populate_root_command=%s\n", pop_cmd); return -errno; } int loop_error = 0; #ifdef HAVE_GETLINE while ((hlen = getline(&dir_entry, &hsize, browser)) != -1) #else // HAVE_FGETLN while (dir_entry = fgetln(browser, &hsize)) #endif { if (hlen >= 1 && dir_entry[hlen - 1] == '\n') dir_entry[hlen - 1] = '\0'; fprintf(stderr, "Got entry \"%s\"\n", dir_entry); int insert_err = insert_sorted_if_unique(dir_entry_listptr, dir_entry); if (insert_err == 1) // already in list continue; else if (insert_err) { fprintf(stderr, "populate_root_command: failed on inserting new entry into sorted list.\n"); loop_error = 1; } if (strlen(dir_entry) != 0) filler(buf, dir_entry, NULL, 0); } free(dir_entry); int pclose_err = pclose(browser); if (pclose_err) { int pclose_errno = errno; fprintf(stderr, "populate_root_command: pclose failed, ret %d, status %d, errno %d (%s)\n", pclose_errno, WEXITSTATUS(pclose_errno), pclose_errno, strerror(pclose_errno)); } return loop_error || pclose_err; } 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 *root_name = alloca(strlen(path)); char *real_path = alloca(max_path_out_len(path)); struct list_t *dir_entry_list = NULL; mount_list_t *mount, *next; int retval; BLOCK_SIGALRM; switch (process_path(path, real_path, root_name, 1, &mount)) { case PROC_PATH_FAILED: retval = -ENXIO; break; case PROC_PATH_ROOT_DIR: filler(buf, ".", NULL, 0); filler(buf, "..", NULL, 0); insert_sorted_if_unique(&dir_entry_list, "."); insert_sorted_if_unique(&dir_entry_list, ".."); for (mount = mount_list; mount; mount = next) { next = mount->next; /* Check for dead mounts. */ if (!check_mount(mount)) { do_umount(mount); } else { if (insert_sorted_if_unique (&dir_entry_list, mount->root_name)) retval = -1; filler(buf, mount->root_name, NULL, 0); } } populate_root_dir(user_options.populate_root_command, &dir_entry_list, filler, buf); destroy_list(&dir_entry_list); mount = NULL; retval = 0; break; case PROC_PATH_ROOT_SUBDIR: if (!mount) { retval = (!dp) ? -EBADF : -EACCES; break; } 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; } retval = 0; break; default: DEFAULT_CASE_INVALID_ENUM; } if (mount) update_auto_unmount(mount); UNBLOCK_SIGALRM; return retval; } 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)); int retval; BLOCK_SIGALRM; switch (process_path(path, real_path, root_name, 1, &mount)) { case PROC_PATH_FAILED: retval = -ENXIO; break; case PROC_PATH_ROOT_DIR: retval = 0; break; case PROC_PATH_ROOT_SUBDIR: case PROC_PATH_PROXY_DIR: if (mount) dir_list_remove(&mount->dir_list, dp); if (dp) closedir(dp); retval = 0; break; default: DEFAULT_CASE_INVALID_ENUM; } if (mount) update_auto_unmount(mount); UNBLOCK_SIGALRM; return retval; } static int afuse_mknod(const char *path, mode_t mode, dev_t rdev) { char *root_name = alloca(strlen(path)); char *real_path = alloca(max_path_out_len(path)); mount_list_t *mount; int retval; BLOCK_SIGALRM; fprintf(stderr, "> Mknod\n"); switch (process_path(path, real_path, root_name, 0, &mount)) { case PROC_PATH_FAILED: retval = -ENXIO; break; case PROC_PATH_ROOT_DIR: case PROC_PATH_ROOT_SUBDIR: retval = -ENOTSUP; break; case PROC_PATH_PROXY_DIR: if (S_ISFIFO(mode)) retval = get_retval(mkfifo(real_path, mode)); else retval = get_retval(mknod(real_path, mode, rdev)); break; default: DEFAULT_CASE_INVALID_ENUM; } if (mount) update_auto_unmount(mount); UNBLOCK_SIGALRM; return retval; } static int afuse_mkdir(const char *path, mode_t mode) { char *root_name = alloca(strlen(path)); char *real_path = alloca(max_path_out_len(path)); int retval; mount_list_t *mount; BLOCK_SIGALRM; switch (process_path(path, real_path, root_name, 0, &mount)) { case PROC_PATH_FAILED: retval = -ENXIO; break; case PROC_PATH_ROOT_DIR: case PROC_PATH_ROOT_SUBDIR: retval = -ENOTSUP; break; case PROC_PATH_PROXY_DIR: retval = get_retval(mkdir(real_path, mode)); break; default: DEFAULT_CASE_INVALID_ENUM; } if (mount) update_auto_unmount(mount); UNBLOCK_SIGALRM; return retval; } static int afuse_unlink(const char *path) { char *root_name = alloca(strlen(path)); char *real_path = alloca(max_path_out_len(path)); mount_list_t *mount; int retval; BLOCK_SIGALRM; switch (process_path(path, real_path, root_name, 0, &mount)) { case PROC_PATH_FAILED: retval = -ENXIO; break; case PROC_PATH_ROOT_DIR: case PROC_PATH_ROOT_SUBDIR: retval = -ENOTSUP; break; case PROC_PATH_PROXY_DIR: retval = get_retval(unlink(real_path)); break; default: DEFAULT_CASE_INVALID_ENUM; } if (mount) update_auto_unmount(mount); UNBLOCK_SIGALRM; return retval; } static int afuse_rmdir(const char *path) { char *root_name = alloca(strlen(path)); char *real_path = alloca(max_path_out_len(path)); mount_list_t *mount; int retval; BLOCK_SIGALRM; switch (process_path(path, real_path, root_name, 0, &mount)) { case PROC_PATH_FAILED: retval = -ENXIO; break; case PROC_PATH_ROOT_DIR: retval = -ENOTSUP; break; case PROC_PATH_ROOT_SUBDIR: if (mount) { /* Unmount */ if (mount->dir_list || mount->fd_list) retval = -EBUSY; else { do_umount(mount); mount = NULL; retval = 0; } } else retval = -ENOTSUP; break; case PROC_PATH_PROXY_DIR: retval = get_retval(rmdir(real_path)); break; default: DEFAULT_CASE_INVALID_ENUM; } if (mount) update_auto_unmount(mount); UNBLOCK_SIGALRM; return retval; } static int afuse_symlink(const char *from, const char *to) { char *root_name_to = alloca(strlen(to)); char *real_to_path = alloca(max_path_out_len(to)); mount_list_t *mount; int retval; BLOCK_SIGALRM; switch (process_path(to, real_to_path, root_name_to, 0, &mount)) { case PROC_PATH_FAILED: retval = -ENXIO; break; case PROC_PATH_ROOT_DIR: case PROC_PATH_ROOT_SUBDIR: retval = -ENOTSUP; break; case PROC_PATH_PROXY_DIR: retval = get_retval(symlink(from, real_to_path)); break; default: DEFAULT_CASE_INVALID_ENUM; } if (mount) update_auto_unmount(mount); UNBLOCK_SIGALRM; return retval; } static int afuse_rename(const char *from, const char *to) { char *root_name_from = alloca(strlen(from)); char *root_name_to = alloca(strlen(to)); char *real_from_path = alloca(max_path_out_len(from)); char *real_to_path = alloca(max_path_out_len(to)); mount_list_t *mount_from, *mount_to = NULL; int retval; BLOCK_SIGALRM; switch (process_path (from, real_from_path, root_name_from, 0, &mount_from)) { case PROC_PATH_FAILED: retval = -ENXIO; break; case PROC_PATH_ROOT_DIR: case PROC_PATH_ROOT_SUBDIR: retval = -ENOTSUP; break; case PROC_PATH_PROXY_DIR: switch (process_path (to, real_to_path, root_name_to, 0, &mount_to)) { case PROC_PATH_FAILED: retval = -ENXIO; break; case PROC_PATH_ROOT_DIR: case PROC_PATH_ROOT_SUBDIR: retval = -ENOTSUP; break; case PROC_PATH_PROXY_DIR: retval = get_retval(rename(real_from_path, real_to_path)); break; default: DEFAULT_CASE_INVALID_ENUM; } break; default: DEFAULT_CASE_INVALID_ENUM; } if (mount_to) update_auto_unmount(mount_to); if (mount_from && mount_from != mount_to) update_auto_unmount(mount_from); UNBLOCK_SIGALRM; return retval; } static int afuse_link(const char *from, const char *to) { char *root_name_from = alloca(strlen(from)); char *root_name_to = alloca(strlen(to)); char *real_from_path = alloca(max_path_out_len(from)); char *real_to_path = alloca(max_path_out_len(to)); mount_list_t *mount_to = NULL, *mount_from; int retval; BLOCK_SIGALRM; switch (process_path (from, real_from_path, root_name_from, 0, &mount_from)) { case PROC_PATH_FAILED: retval = -ENXIO; break; case PROC_PATH_ROOT_DIR: case PROC_PATH_ROOT_SUBDIR: retval = -ENOTSUP; break; case PROC_PATH_PROXY_DIR: switch (process_path (to, real_to_path, root_name_to, 0, &mount_to)) { case PROC_PATH_FAILED: retval = -ENXIO; break; case PROC_PATH_ROOT_DIR: case PROC_PATH_ROOT_SUBDIR: retval = -ENOTSUP; break; case PROC_PATH_PROXY_DIR: retval = get_retval(link(real_from_path, real_to_path)); break; default: DEFAULT_CASE_INVALID_ENUM; } break; default: DEFAULT_CASE_INVALID_ENUM; } if (mount_to) update_auto_unmount(mount_to); if (mount_from && mount_from != mount_to) update_auto_unmount(mount_from); UNBLOCK_SIGALRM; return retval; } static int afuse_chmod(const char *path, mode_t mode) { char *root_name = alloca(strlen(path)); char *real_path = alloca(max_path_out_len(path)); mount_list_t *mount; int retval; BLOCK_SIGALRM; switch (process_path(path, real_path, root_name, 0, &mount)) { case PROC_PATH_FAILED: retval = -ENXIO; break; case PROC_PATH_ROOT_DIR: case PROC_PATH_ROOT_SUBDIR: retval = -ENOTSUP; break; case PROC_PATH_PROXY_DIR: retval = get_retval(chmod(real_path, mode)); break; default: DEFAULT_CASE_INVALID_ENUM; } if (mount) update_auto_unmount(mount); UNBLOCK_SIGALRM; return retval; } static int afuse_chown(const char *path, uid_t uid, gid_t gid) { char *root_name = alloca(strlen(path)); char *real_path = alloca(max_path_out_len(path)); mount_list_t *mount; int retval; BLOCK_SIGALRM; switch (process_path(path, real_path, root_name, 0, &mount)) { case PROC_PATH_FAILED: retval = -ENXIO; break; case PROC_PATH_ROOT_DIR: case PROC_PATH_ROOT_SUBDIR: retval = -ENOTSUP; break; case PROC_PATH_PROXY_DIR: retval = get_retval(lchown(real_path, uid, gid)); break; default: DEFAULT_CASE_INVALID_ENUM; } if (mount) update_auto_unmount(mount); UNBLOCK_SIGALRM; return retval; } static int afuse_truncate(const char *path, off_t size) { char *root_name = alloca(strlen(path)); char *real_path = alloca(max_path_out_len(path)); mount_list_t *mount; int retval; BLOCK_SIGALRM; switch (process_path(path, real_path, root_name, 0, &mount)) { case PROC_PATH_FAILED: retval = -ENXIO; break; case PROC_PATH_ROOT_DIR: case PROC_PATH_ROOT_SUBDIR: retval = -ENOTSUP; break; case PROC_PATH_PROXY_DIR: retval = get_retval(truncate(real_path, size)); break; default: DEFAULT_CASE_INVALID_ENUM; } if (mount) update_auto_unmount(mount); UNBLOCK_SIGALRM; return retval; } static int afuse_utime(const char *path, struct utimbuf *buf) { char *root_name = alloca(strlen(path)); char *real_path = alloca(max_path_out_len(path)); mount_list_t *mount; int retval; BLOCK_SIGALRM; switch (process_path(path, real_path, root_name, 0, &mount)) { case PROC_PATH_FAILED: retval = -ENXIO; break; case PROC_PATH_ROOT_DIR: retval = -ENOTSUP; break; case PROC_PATH_ROOT_SUBDIR: if (!mount) { retval = -ENOTSUP; break; } case PROC_PATH_PROXY_DIR: retval = get_retval(utime(real_path, buf)); break; default: DEFAULT_CASE_INVALID_ENUM; } if (mount) update_auto_unmount(mount); UNBLOCK_SIGALRM; return retval; } 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)); int retval; BLOCK_SIGALRM; switch (process_path(path, real_path, root_name, 1, &mount)) { case PROC_PATH_FAILED: retval = -ENXIO; break; case PROC_PATH_ROOT_DIR: case PROC_PATH_ROOT_SUBDIR: retval = -ENOENT; break; case PROC_PATH_PROXY_DIR: fd = open(real_path, fi->flags); if (fd == -1) { retval = -errno; break; } fi->fh = fd; if (mount) fd_list_add(&mount->fd_list, fd); retval = 0; break; default: DEFAULT_CASE_INVALID_ENUM; } if (mount) update_auto_unmount(mount); UNBLOCK_SIGALRM; return retval; } 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; if (user_options.flush_writes) fsync(fi->fh); return res; } static int afuse_release(const char *path, struct fuse_file_info *fi) { char *root_name = alloca(strlen(path)); mount_list_t *mount; int retval; BLOCK_SIGALRM; extract_root_name(path, root_name); mount = find_mount(root_name); retval = get_retval(close(fi->fh)); if (mount) { fd_list_remove(&mount->fd_list, fi->fh); update_auto_unmount(mount); } UNBLOCK_SIGALRM; return retval; } 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); return get_retval(res); } #if FUSE_VERSION >= 25 static int afuse_access(const char *path, int mask) { char *root_name = alloca(strlen(path)); char *real_path = alloca(max_path_out_len(path)); mount_list_t *mount; int retval; BLOCK_SIGALRM; switch (process_path(path, real_path, root_name, 1, &mount)) { case PROC_PATH_FAILED: retval = -ENXIO; break; case PROC_PATH_ROOT_DIR: case PROC_PATH_PROXY_DIR: retval = get_retval(access(real_path, mask)); break; case PROC_PATH_ROOT_SUBDIR: if (mount) retval = get_retval(access(real_path, mask)); else retval = -EACCES; break; default: DEFAULT_CASE_INVALID_ENUM; } if (mount) update_auto_unmount(mount); UNBLOCK_SIGALRM; return retval; } static int afuse_ftruncate(const char *path, off_t size, struct fuse_file_info *fi) { (void)path; return get_retval(ftruncate(fi->fh, size)); } static int afuse_create(const char *path, mode_t mode, struct fuse_file_info *fi) { int fd; char *root_name = alloca(strlen(path)); char *real_path = alloca(max_path_out_len(path)); mount_list_t *mount; int retval; BLOCK_SIGALRM; switch (process_path(path, real_path, root_name, 0, &mount)) { case PROC_PATH_FAILED: retval = -ENXIO; break; case PROC_PATH_ROOT_DIR: case PROC_PATH_ROOT_SUBDIR: retval = -ENOTSUP; break; case PROC_PATH_PROXY_DIR: fd = open(real_path, fi->flags, mode); if (fd == -1) { retval = -errno; break; } fi->fh = fd; retval = 0; break; default: DEFAULT_CASE_INVALID_ENUM; } if (mount) update_auto_unmount(mount); UNBLOCK_SIGALRM; return retval; } static int afuse_fgetattr(const char *path, struct stat *stbuf, struct fuse_file_info *fi) { (void)path; return get_retval(fstat(fi->fh, stbuf)); } #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 { char *root_name = alloca(strlen(path)); char *real_path = alloca(max_path_out_len(path)); mount_list_t *mount; int retval; BLOCK_SIGALRM; switch (process_path(path, real_path, root_name, 1, &mount)) { case PROC_PATH_FAILED: retval = -ENXIO; break; 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; retval = 0; break; case PROC_PATH_ROOT_SUBDIR: if (!mount) { retval = -EACCES; break; } case PROC_PATH_PROXY_DIR: retval = get_retval(statvfs(real_path, stbuf)); break; default: DEFAULT_CASE_INVALID_ENUM; } if (mount) update_auto_unmount(mount); UNBLOCK_SIGALRM; return retval; } void afuse_destroy(void *p) { (void)p; /* Unused */ 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) { char *root_name = alloca(strlen(path)); char *real_path = alloca(max_path_out_len(path)); mount_list_t *mount; int retval; BLOCK_SIGALRM; switch (process_path(path, real_path, root_name, 0, &mount)) { case PROC_PATH_FAILED: retval = -ENXIO; break; case PROC_PATH_ROOT_DIR: retval = -ENOENT; break; case PROC_PATH_ROOT_SUBDIR: if (!mount) { retval = -ENOTSUP; break; } case PROC_PATH_PROXY_DIR: retval = get_retval(lsetxattr(real_path, name, value, size, flags)); break; default: DEFAULT_CASE_INVALID_ENUM; } if (mount) update_auto_unmount(mount); UNBLOCK_SIGALRM; return retval; } static int afuse_getxattr(const char *path, const char *name, char *value, size_t size) { char *root_name = alloca(strlen(path)); char *real_path = alloca(max_path_out_len(path)); mount_list_t *mount; int retval; BLOCK_SIGALRM; switch (process_path(path, real_path, root_name, 1, &mount)) { case PROC_PATH_FAILED: retval = -ENXIO; break; case PROC_PATH_ROOT_DIR: retval = -ENOTSUP; break; case PROC_PATH_ROOT_SUBDIR: if (!mount) { retval = -ENOTSUP; break; } case PROC_PATH_PROXY_DIR: retval = get_retval(lgetxattr(real_path, name, value, size)); break; default: DEFAULT_CASE_INVALID_ENUM; } if (mount) update_auto_unmount(mount); UNBLOCK_SIGALRM; return retval; } static int afuse_listxattr(const char *path, char *list, size_t size) { char *root_name = alloca(strlen(path)); char *real_path = alloca(max_path_out_len(path)); mount_list_t *mount; int retval; BLOCK_SIGALRM; switch (process_path(path, real_path, root_name, 1, &mount)) { case PROC_PATH_FAILED: retval = -ENXIO; break; case PROC_PATH_ROOT_DIR: retval = -ENOTSUP; break; case PROC_PATH_ROOT_SUBDIR: if (!mount) { retval = -ENOTSUP; break; } case PROC_PATH_PROXY_DIR: retval = get_retval(llistxattr(real_path, list, size)); break; default: DEFAULT_CASE_INVALID_ENUM; } if (mount) update_auto_unmount(mount); UNBLOCK_SIGALRM; return retval; } static int afuse_removexattr(const char *path, const char *name) { char *root_name = alloca(strlen(path)); char *real_path = alloca(max_path_out_len(path)); mount_list_t *mount; int retval; BLOCK_SIGALRM; switch (process_path(path, real_path, root_name, 0, &mount)) { case PROC_PATH_FAILED: retval = -ENXIO; break; case PROC_PATH_ROOT_DIR: retval = -ENOTSUP; break; case PROC_PATH_ROOT_SUBDIR: if (!mount) { retval = -ENOTSUP; break; } case PROC_PATH_PROXY_DIR: retval = get_retval(lremovexattr(real_path, name)); break; default: DEFAULT_CASE_INVALID_ENUM; } if (mount) update_auto_unmount(mount); UNBLOCK_SIGALRM; return retval; } #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, KEY_FLUSHWRITES, KEY_EXACT_GETATTR }; #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), AFUSE_OPT("populate_root_command=%s", populate_root_command, 0), AFUSE_OPT("filter_file=%s", filter_file, 0), AFUSE_OPT("mount_dir=%s", mount_dir, 0), AFUSE_OPT("timeout=%llu", auto_unmount_delay, 0), FUSE_OPT_KEY("exact_getattr", KEY_EXACT_GETATTR), FUSE_OPT_KEY("flushwrites", KEY_FLUSHWRITES), 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 (1)\n" " -o unmount_template=CMD template for CMD to execute to unmount (1) (2)\n" " -o populate_root_command=CMD CMD to execute providing root directory list (3)\n" " -o filter_file=FILE FILE listing ignore filters for mount points (4)\n" " -o timeout=TIMEOUT automatically unmount after TIMEOUT seconds\n" " -o flushwrites flushes data to disk for all file writes\n" " -o exact_getattr allows getattr calls to cause a mount\n" " -o mount_dir=DIR place temporary mounts under DIR (default: /tmp)\n" "\n\n" " (1) - When executed, %%r is expanded to the directory name inside the\n" " afuse mount, and %%m is expanded to the actual directory to mount\n" " onto. Both templates are REQUIRED.\n" "\n" " (2) - 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" " (3) - The populate_root command should output one dir entry per line,\n" " and return immediately. It is run for each directory listing request.\n" "\n" " (4) - Each line of the filter file is a shell wildcard filter (glob). A '#'\n" " as the first character on a line ignores a filter.\n" "\n" " The following filter patterns are hard-coded:" "\n", progname); mount_filter_list_t *cur = mount_filter_list; while (cur) { fprintf(stderr, " %s\n", cur->pattern); cur = cur->next; } fprintf(stderr, "\n"); } static int afuse_opt_proc(void *data, const char *arg, int key, struct fuse_args *outargs) { /* Unused */ (void)arg; (void)data; 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); case KEY_FLUSHWRITES: user_options.flush_writes = true; return 0; case KEY_EXACT_GETATTR: user_options.exact_getattr = true; return 0; default: return 1; } } int main(int argc, char *argv[]) { char *temp_dir_name; struct fuse_args args = FUSE_ARGS_INIT(argc, argv); if (fuse_opt_parse(&args, &user_options, afuse_opts, afuse_opt_proc) == -1) return 1; // !!FIXME!! force single-threading for now as data structures are not locked fuse_opt_add_arg(&args, "-s"); // Adjust user specified timeout from seconds to microseconds as required if (user_options.auto_unmount_delay != UINT64_MAX) user_options.auto_unmount_delay *= 1000000; auto_unmount_ph_init(&auto_unmount_ph); /** * Install the SIGALRM signal handler. */ { struct sigaction act; act.sa_handler = &handle_auto_unmount_timer; sigemptyset(&act.sa_mask); act.sa_flags = 0; while (sigaction(SIGALRM, &act, NULL) == -1 && errno == EINTR) continue; } if (!user_options.mount_dir) { temp_dir_name = my_malloc(strlen(TMP_DIR_TEMPLATE)); strcpy(temp_dir_name, TMP_DIR_TEMPLATE); } else { temp_dir_name = my_malloc(strlen(user_options.mount_dir) + strlen(TMP_DIR_TEMPLATE2)); strcpy(temp_dir_name, user_options.mount_dir); strcpy(temp_dir_name + strlen(user_options.mount_dir), TMP_DIR_TEMPLATE2); } // 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 (user_options.filter_file) load_mount_filter_file(user_options.filter_file); if (!(mount_point_directory = mkdtemp(temp_dir_name))) { fprintf(stderr, "Failed to create temporary mount point dir.\n"); return 1; } { struct stat buf; if (lstat(mount_point_directory, &buf) == -1) { fprintf(stderr, "Failed to stat temporary mount point dir.\n"); return 1; } mount_point_dev = buf.st_dev; } umask(0); // !!FIXME!! death by signal doesn't unmount fs return fuse_main(args.argc, args.argv, &afuse_oper); } afuse-0.5.0/src/afuse.h000066400000000000000000000006071420506375600146750ustar00rootroot00000000000000#ifndef __AFUSE_H #define __AFUSE_H // Global definitions in use through afuse source // 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 #endif // __AFUSE_H afuse-0.5.0/src/dir_list.c000066400000000000000000000021461420506375600153760ustar00rootroot00000000000000#define __DIR_LIST_C #include #include #include "afuse.h" #include "utils.h" #include "dir_list.h" void dir_list_add(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 dir_list_remove(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 dir_list_close_all(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++) ; dir_list_remove(dir_list, (*dir_list)->dir); } } bool dir_list_empty(dir_list_t * dir_list) { return (dir_list == NULL) ? true : false; } afuse-0.5.0/src/dir_list.h000066400000000000000000000010331420506375600153750ustar00rootroot00000000000000#ifndef __DIR_LIST_H #define __DIR_LIST_H #include #include typedef struct _dir_list_t { struct _dir_list_t *next; struct _dir_list_t *prev; DIR *dir; } dir_list_t; #undef EXTERN #ifdef __DIR_LIST_C #define EXTERN #else #define EXTERN extern #endif EXTERN void dir_list_add(dir_list_t ** dir_list, DIR * dir); EXTERN void dir_list_remove(dir_list_t ** dir_list, DIR * dir); EXTERN void dir_list_close_all(dir_list_t ** dir_list); EXTERN bool dir_list_empty(dir_list_t * dir_list); #endif // __DIR_LIST_H afuse-0.5.0/src/fd_list.c000066400000000000000000000020421420506375600152040ustar00rootroot00000000000000#define __FD_LIST_C #include #include #include "afuse.h" #include "utils.h" #include "fd_list.h" void fd_list_add(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 fd_list_remove(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 fd_list_close_all(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++) ; fd_list_remove(fd_list, (*fd_list)->fd); } } bool fd_list_empty(fd_list_t * fd_list) { return (fd_list == NULL) ? true : false; } afuse-0.5.0/src/fd_list.h000066400000000000000000000010601420506375600152100ustar00rootroot00000000000000#ifndef __FD_LIST_H #define __FD_LIST_H #include // Link list holding open file descriptors associated with a mount typedef struct _fd_list_t { struct _fd_list_t *next; struct _fd_list_t *prev; int fd; } fd_list_t; #undef EXTERN #ifdef __DIR_LIST_C #define EXTERN #else #define EXTERN extern #endif EXTERN void fd_list_add(fd_list_t ** fd_list, int fd); EXTERN void fd_list_remove(fd_list_t ** fd_list, int fd); EXTERN bool fd_list_empty(fd_list_t * fd_list); EXTERN void fd_list_close_all(fd_list_t ** fd_list); #endif // __FD_LIST_H afuse-0.5.0/src/string_sorted_list.c000066400000000000000000000044171420506375600175110ustar00rootroot00000000000000#include #include #include #include "string_sorted_list.h" struct list_t { struct list_t *prev, *next; char *name; }; static char *stralloccopy(char const *const str) { char *s = malloc((strlen(str) + 1) * sizeof(*s)); if (s != NULL) strcpy(s, str); return s; } static struct list_t *new_list_element(struct list_t *prev, struct list_t *next, char const *const name) { struct list_t *e; e = malloc(sizeof(*e)); if (!e) { return NULL; } e->prev = prev; e->next = next; e->name = stralloccopy(name); if (!e->name) { free(e); return NULL; } return e; } static struct list_t *insert_between(struct list_t *prev, struct list_t *next, char const *const name) { struct list_t *e; e = new_list_element(prev, next, name); if (e == NULL) return NULL; if (prev) prev->next = e; if (next) next->prev = e; return e; } static int update_list(struct list_t **list, struct list_t *prev, struct list_t *next, char const *const name) { struct list_t *e; e = insert_between(prev, next, name); if (e == NULL) return -1; *list = e; return 0; } int insert_sorted_if_unique(struct list_t **list, char const *const name) { struct list_t *prev, *curr, *next; int cmp; if (*list == NULL) return update_list(list, NULL, NULL, name); curr = NULL; next = *list; do { prev = curr; curr = next; cmp = strcmp(name, curr->name); if (cmp == 0) return 1; else if (cmp > 0) next = curr->next; else next = curr->prev; } while (next && next != prev); if (cmp > 0) return update_list(list, curr, curr->next, name); else return update_list(list, curr->prev, curr, name); } void destroy_list(struct list_t **list) { struct list_t *curr, *next; if (*list == NULL) return; curr = (*list)->next; while (curr) { next = curr->next; free(curr); curr = next; } curr = (*list); while (curr) { next = curr->prev; free(curr); curr = next; } *list = NULL; } void print_list(struct list_t const *curr) { if (curr == NULL) { fprintf(stderr, "list is empty\n"); return; } fprintf(stderr, "Sorted list: "); /* go to beginning */ while (curr->prev) curr = curr->prev; do { fprintf(stderr, " %s,", curr->name); curr = curr->next; } while (curr); fprintf(stderr, "\n"); } afuse-0.5.0/src/string_sorted_list.h000066400000000000000000000003651420506375600175140ustar00rootroot00000000000000#ifndef STRING_SORTED_LIST_H #define STRING_SORTED_LIST_H struct list_t; int insert_sorted_if_unique(struct list_t **list, char const *const name); void destroy_list(struct list_t **list); void print_list(struct list_t const *curr); #endif afuse-0.5.0/src/utils.c000066400000000000000000000006301420506375600147210ustar00rootroot00000000000000#define __UTILS_C #include #include #include #include "utils.h" void *my_malloc(size_t size) { void *p; p = malloc(size); if (!p) { fprintf(stderr, "Failed to allocate: %zu bytes of memory.\n", size); exit(1); } return p; } char *my_strdup(const char *str) { char *new_str; new_str = my_malloc(strlen(str) + 1); strcpy(new_str, str); return new_str; } afuse-0.5.0/src/utils.h000066400000000000000000000003621420506375600147300ustar00rootroot00000000000000#ifndef __UTILS_H #define __UTILS_H #include #undef EXTERN #ifdef __UTILS_C #define EXTERN #else #define EXTERN extern #endif EXTERN void *my_malloc(size_t size); EXTERN char *my_strdup(const char *str); #endif // __UTILS_H afuse-0.5.0/src/variable_pairing_heap.h000066400000000000000000000203371420506375600200670ustar00rootroot00000000000000/** * @file variable_pairing_heap.h * * @author Jeremy Maitin-Shepard * * This file defines a type-generic pairing heap implementation as * several macros that generate the implementation code. */ #ifndef _VARIABLE_PAIRING_HEAP_H #define _VARIABLE_PAIRING_HEAP_H #define PH_NEW_LINK(PH_ELEM_TYPE) \ struct \ { \ PH_ELEM_TYPE *child, *next, *prev; \ } #define PH_DECLARE_TYPE(PH_PREFIX, PH_ELEM_TYPE) \ typedef PH_ELEM_TYPE *PH_PREFIX ## _t; \ void PH_PREFIX ## _init(PH_PREFIX ## _t *ph); \ PH_ELEM_TYPE *PH_PREFIX ## _min(PH_PREFIX ## _t *ph); \ void PH_PREFIX ## _insert(PH_PREFIX ## _t *ph, PH_ELEM_TYPE *elem); \ void PH_PREFIX ## _remove(PH_PREFIX ## _t *ph, PH_ELEM_TYPE *elem); \ void PH_PREFIX ## _remove_min(PH_PREFIX ## _t *ph); #define PH_DEFINE_TYPE(PH_PREFIX, PH_ELEM_TYPE, PH_NODE_NAME, PH_KEY_NAME) \ void PH_PREFIX ## _init(PH_PREFIX ## _t *ph) \ { \ *ph = NULL; \ } \ PH_ELEM_TYPE *PH_PREFIX ## _min(PH_PREFIX ## _t *ph) \ { \ return *ph; \ } \ static PH_ELEM_TYPE *PH_PREFIX ## _meld(PH_ELEM_TYPE *a, \ PH_ELEM_TYPE *b) \ { \ if (!b) \ return a; \ if (a->PH_KEY_NAME > b->PH_KEY_NAME) \ { \ PH_ELEM_TYPE *temp = a; \ a = b; \ b = temp; \ } \ b->PH_NODE_NAME.next = a->PH_NODE_NAME.child; \ b->PH_NODE_NAME.prev = a; \ if (a->PH_NODE_NAME.child) \ a->PH_NODE_NAME.child->PH_NODE_NAME.prev = b; \ a->PH_NODE_NAME.child = b; \ return a; \ } \ void PH_PREFIX ## _insert(PH_PREFIX ## _t *ph, PH_ELEM_TYPE *elem) \ { \ elem->PH_NODE_NAME.child = NULL; \ elem->PH_NODE_NAME.next = NULL; \ elem->PH_NODE_NAME.prev = NULL; \ *ph = PH_PREFIX ## _meld(elem, *ph); \ } \ static PH_ELEM_TYPE *PH_PREFIX ## _combine_children(PH_ELEM_TYPE *ph) \ { \ PH_ELEM_TYPE *head = NULL, *tail = NULL, *cur = ph->PH_NODE_NAME.child, \ *next, *nnext, *m = NULL; \ if (!cur) \ return NULL; \ while (1) \ { \ if (!cur->PH_NODE_NAME.next) \ next = NULL; \ else \ next = cur->PH_NODE_NAME.next->PH_NODE_NAME.next; \ m = PH_PREFIX ## _meld(cur, cur->PH_NODE_NAME.next); \ if (tail) \ tail->PH_NODE_NAME.next = m; \ else \ head = m; \ tail = m; \ if (!next) \ break; \ cur = next; \ } \ while (head != tail) \ { \ next = head->PH_NODE_NAME.next; \ nnext = next->PH_NODE_NAME.next; \ m = PH_PREFIX ## _meld(head, next); \ if (next == tail) \ break; \ tail->PH_NODE_NAME.next = m; \ tail = m; \ head = nnext; \ } \ m->PH_NODE_NAME.prev = NULL; \ m->PH_NODE_NAME.next = NULL; \ return m; \ } \ void PH_PREFIX ## _remove_min(PH_PREFIX ## _t *ph) \ { \ *ph = PH_PREFIX ## _combine_children(*ph); \ } \ void PH_PREFIX ## _remove(PH_PREFIX ## _t *ph, PH_ELEM_TYPE *elem) \ { \ if (elem == *ph) \ PH_PREFIX ## _remove_min(ph); \ else \ { \ PH_ELEM_TYPE *prev = elem->PH_NODE_NAME.prev; \ if (prev->PH_NODE_NAME.child == elem) \ prev->PH_NODE_NAME.child = elem->PH_NODE_NAME.next; \ else \ prev->PH_NODE_NAME.next = elem->PH_NODE_NAME.next; \ if (elem->PH_NODE_NAME.next) \ elem->PH_NODE_NAME.next->PH_NODE_NAME.prev = prev; \ *ph = PH_PREFIX ## _meld \ (*ph, PH_PREFIX ## _combine_children(elem)); \ } \ } #endif /* _VARIABLE_PAIRING_HEAP_H */