destroy() callback invoked after mount when running as a service

34 views
Skip to first unread message

Alexandros Paraskevaides

unread,
Oct 11, 2023, 1:53:28 AM10/11/23
to WinFsp
Hi,

I'm having an issue where destroy() is invoked right after mount, only when running my application as a windows service. When I run my application normally, the file system is mounted successfully and all operations are functional.

Unfortunately, I can't troubleshoot this problem since it runs as a service and I don't have access to the WinFSP logs. I tried to redirect stdout and stderr to log4j (which i can confirm is done properly as I can see any System.out and System.err messages in my logs), however, that doesn't seem to capture WinFSP logs.

Can anyone help, either by giving some insight to what might be causing the problem with running it as a service, or by advising how I could retrieve WinFSP debug logging when running as a service to be able to troubleshoot the issue?

Many thanks,
Alex

Bill Zissimopoulos

unread,
Oct 11, 2023, 9:50:31 AM10/11/23
to Alexandros Paraskevaides, WinFsp

This sounds like your file system is failing to start.

 

To verify this open the Event Viewer and search in the “Application” log for messages with a “WinFsp” source. You will likely see that your file system terminates immediately after being launched.

 

It is not straightforward to troubleshoot problems for file systems running in the Windows service context, but here are some suggestions.

 

  • You can try running your file system under the SYSTEM account using PSEXEC. Try something like `psexec -d -i -s cmd.exe` to get a command prompt under the SYSTEM account and then launch your file system.

 

  • You can redirect WinFsp debug log output to a file using FspDebugLogSetHandle. However this may not be available to you as it sounds like you are using WinFsp via a Java layer.

 

  • If your file system logs to stderr, these error messages are lost when running in the Windows service context. However you can capture them into a file by specifying a registry setting with name Stderr and value the full file path. You would place this registry setting under the registry key for your file system (e.g. HKLM\SOFTWARE\WOW6432Node\WinFsp\Services\YourFileSystem). This assumes that you are using the WinFsp launcher to run your file system; for more see the Service Architecture document.

 

  • It is also possible to use a debugger such as Visual Studio or WinDbg to debug your file system running in the Windows service context. You would have to run the debugger as administrator, although I have only done this for native code.

 

Bill

--
You received this message because you are subscribed to the Google Groups "WinFsp" group.
To unsubscribe from this group and stop receiving emails from it, send an email to winfsp+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/winfsp/565bdeca-6327-4f68-9b45-ec43f38047e6n%40googlegroups.com.

Alexandros Paraskevaides

unread,
Oct 12, 2023, 4:15:32 AM10/12/23
to WinFsp
Hi Bill,
  • I've tried PSEXEC and running it under the SYSTEM account doesn't seem to recreate the problem.
  • As you said, i'm using WinFsp via a Java layer (jnr-fuse) so that wouldn't be possible.
  • As I mentioned above, I've configured log4j to log any stdout or stderr messages to the application's log, but although my application's stdout and stderr messages are being logged, any winfsp messages are not (if I run my application as a java application, I can see the WinFsp messages in the console). Any idea why this is the case?
  • Not sure if this would work with Java code, I've tried connecting to the java process and can debug successfully with Intellij, but no messages are being printed on the console view.
Regards,

Alex

Bill Zissimopoulos

unread,
Oct 12, 2023, 7:20:35 AM10/12/23
to Alexandros Paraskevaides, WinFsp

As I mentioned above, I've configured log4j to log any stdout or stderr messages to the application's log, but although my application's stdout and stderr messages are being logged, any winfsp messages are not (if I run my application as a java application, I can see the WinFsp messages in the console). Any idea why this is the case?

 

It is likely that log4j knows how to redirect its own messages to a log file, but it does not know how to do this for code that outputs to the process STDOUT and STDERR handles directly. WinFsp-FUSE (i.e. the FUSE layer of WinFsp, which jnr-fuse uses) outputs to the regular process STDERR and would bypass any log4j redirection.

 

In addition to the methods I already listed earlier, you may also try the `-o DebugLog=FILE` FUSE command line option. This should redirect WinFsp debug logs to FILE.

Alexandros Paraskevaides

unread,
Oct 12, 2023, 8:11:53 AM10/12/23
to WinFsp
Setting  `-o DebugLog=FILE` seems to capture WinFsp logging when I run the application normally. Via the service however, WinFsp doesn't actually output anything. It simply creates an empty file. I've noticed though that even if I run it normally, WinFSP messages only come after I try to access the drive. 

Bill Zissimopoulos

unread,
Oct 12, 2023, 8:45:14 AM10/12/23
to Alexandros Paraskevaides, WinFsp

Yes, it sounds like your file system does not even start, so you would not get any debug logs from WinFsp. I believe something is failing while your file system is initializing itself, because the environment that it runs in (the Windows service context) can be very different from the environment of a regular user.

 

If you are using the WinFsp launcher, try the Stderr capture trick I mentioned in my first mail. Otherwise if you are running the file system as a Windows service yourself, you will have to find another way to figure out what is failing.

Ricardo Fonseca

unread,
Oct 13, 2023, 7:11:13 AM10/13/23
to WinFsp
Hello,

WinFSP provides helper functions to run your process as a service, and it is possible to call those functions via Java using JNR.

jnr-winfsp (an open source Java implementation of the WinFSP native API) uses this technique, so feel free to use the code in the service package (which depends on the internal library package) as inspiration, in case you want to continue using the Fuse API through jnr-fuse.

Of course, you could also use jnr-winfsp in its entirety, however that would mean using the WinFSP native API instead of the Fuse API to implement your filesystem functions.
If you follow that route, you will need to build the jnr-winfsp jar manually since we don't (yet) provide a way to import it via a remote Maven repository.

Cheers,
Ricardo
Reply all
Reply to author
Forward
0 new messages