Which function is called when changing a directory in FUSE? - c

I'm making a filesystem using FUSE, and know I have a doubt. When I use the "cd" command in the new filesystem, it changes to directories that doesn't exist.
For example, if the directory "m" doesn't exist, and I make a "cd m" it changes to that directory.
Which is the function that FUSE calls when the directory is changed? Why is the app doing the problem I describe?
Thanks!

Are you implementing getattr? and if so, are you making sure to return -ENOENT if the path they give you doesn't correspond to a file or directory in your system?

Related

fopen() file path in C

I have clone a git repository in C:/Repo. I am trying to open a file which lies in the git at some location ,for example, git/program/slm/error.txt. I am using fopen() API in C language to open the file and the filepath I am specifying is "C:/Repo/git/program/slm/error.txt". The program seems to be working while providing the above mentioned path. But,I want to make this program generic so that it can work on other systems as well as in other systems it is not necessary that the git will be cloned in C:/Repo only,this is local to my system. git/program/slm/error.txt is the relative path and will be common for all the system.
Can anyone please help me how what filepathname should I provide to make it generic so that it works on all the systems?
Take your repository path as commandline argument and then when you want to access the file append the repository path and the relative path that you want to access.

Escaping from chroot()

I'm working on a webserver in UNIX environment with C language. Currently, I have done jailing the process but now I cannot use syslog and logging to a file option and that's basically due to the changed root path.
New root path for the program is it's directory. I could not escape from it to real root "/" in order to use these functions and go back to jail root path again.
Are there any other alternatives or solutions to this?
The whole point of using chroot() is to make the real root inaccessible, so easy formula: If you can break it, you don't need it.
So, you should make syslog accessible from within your chroot environment instead. How? Just openlog() prior to chroot(). After that, you can syslog() even though you wouldn't be able to openlog() it anymore.
If your root is the working directory, don't use chroot, and remove the '/' at the beggining of all the relative path you use, or add '.' before this '/'.
Use chroot only if you want to fully work as if it was your system root.
If both env are on the same file system, you can use hard links so that under the chroot'ed env you see files "outside". It may not be so easy to configure everything to work, but it is possible. Change your viewpoint: don't try to escape from chroot, try to include things into.

where ShellExecute found the exe files

I am writing a program in pure C, using win32 api.
I need to know the full path of a registered program.
For example if I write
ShellExecute(0,0,"chrome",0,0,SW_SHOW)
the chrome browser starts. How can I obtain "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" from "chrome" as ShellExecute does?
In this case Chrome has registered itself in the App Paths registry section. More details over on MSDN: https://msdn.microsoft.com/en-us/library/windows/desktop/ee872121.aspx
Finding an Application Executable
When the ShellExecuteEx function is called with the name of an
executable file in its lpFile parameter, there are several places
where the function looks for the file. We recommend registering your
application in the App Paths registry subkey. Doing so avoids the need
for applications to modify the system PATH environment variable.
The file is sought in the following locations:
The current working directory.
The Windows directory only (no subdirectories are searched).
The Windows\System32 directory.
Directories listed in the PATH environment variable.
Recommended: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths
The documentation tells you how the shell searches, and you can replicate that search.
The function SHEvaluateSystemCommandTemplate does exactly that. It performs the exact same search algorithm that is performed by ShellExecute. You just pass "chrome.exe" (or even just "chrome"), and the full path to the chrome executable is returned in the ppszApplication parameter.

encfs does not mount folder

I have installed encfs to encrypt my directory and files and everything worked well when I installed encfs and configured it. I created two folders, one /XDM/game and second /Private and as encfs works I have to copy my files into /Private folder and this will sync all those files' encrypted version with /XDM/game. But when I restart my pc I have to remount /Private folder for that I am using the following command -
encfs ~/XDM/game ~/Private
But it returns me this error -
encfs ~/XDM/game* ~/Private
EncFS Password:
fuse: mountpoint is not empty
fuse: if you are sure this is safe, use the 'nonempty' mount option
fuse failed. Common problems:
- fuse kernel module not installed (modprobe fuse)
- invalid options -- see usage message
help me with this error please. Thank you in Advance!!!
Short answer is 'In order to mount the directory you need to remove file from /Private folder and try mounting again with
encfs `~/XDM/game ~/Private`'
And long answer, after you configured encfs once you restart computer, you can see your folder /Private empty and to show the files you have to mount folder but if you copy any file in /Private folder and then try to mount then it will give you this error. So first delete the file you pasted/created after you restarted computer and then mount. It should work!
I have written a detailed article to help you understand better.
http://www.linuxandubuntu.com/home/how-to-encrypt-cloud-storage-files-folders-in-linux
I was stuck in a similar scenario once when accidentally trying to write to the encrypted directory. Solved it by doing
encfs -o nonempty <encryptedDirPath> <decryptedDirMountPoint>
There are some repercussions to using the 'nonempty' option though. More here.
If you are not able to unmount the decrypted directory after doing the above, you might need to delete the entry for your stash from Gnome Encfs Manager, in case you are using it.
I was having the same problem where it says that mountpoint is busy or not empty. so, I created another dir. in your case, you can do mkdir ~/Private2. and then, simply treat this as your new mountpoint.
encfs ~/XDM/game ~/Private2.

CakePHP Shell issue

I am just getting started with Cakephp shell and running into issues.
My cake core library is under path d:/libs/cake
My app is setup under d:/servers/htdocs/myapp
I wrote a test shell under d:/servers/htdocs/myapp/vendor/shells
class ReportShell extends Shell {
var $uses = array('Appt');
function main() {
echo $this->Appt->find('first');
}
}
When I try to run this code from d:/servers/htdocs/myapp , It gives me an error
Warning: include_once(d:/servers/htdocs/myapp/config/database.php): failed to open stream: No such file or directory in d:/libs/cake\libs\mode
l\connection_manager.php on line 23
Warning: include_once(): Failed opening 'd:/servers/htdocs/myapp/config/database.php' for inclusion (include_path='.;D:\work\xampp\php\PEAR') in d:/libs/cake\libs\model\connection_manager.php on line 23
Fatal error: ConnectionManager::getDataSource - Non-existent data source default in d:/libs/cake\libs\model\connection_manager.php on line 102
Reason is that it is trying to find database.php under 'd:/servers/htdocs/myapp/config/' and the correct path is 'd:/servers/htdocs/myapp/app/config/database.php'
What am I doing wrong here?
thanks
My app is setup under d:/servers/htdocs/myapp
No, the application directory (holding the config folder) is D:\servers\htdocs\myapp\app\.
Reason is that it is trying to find database.php under 'd:/servers/htdocs/myapp/config/' and the correct path is 'd:/servers/htdocs/myapp/app/config/database.php'
You are in the wrong directory, therefore it can't find your database config.
I wrote a test shell under d:/servers/htdocs/myapp/vendor/shells
Move your shell out of the global vendors folder at D:\servers\htdocs\myapp\vendors\shells to the application's vendors folder at D:\servers\htdocs\myapp\app\vendors\shells instead and try again.
(Note: I'm not actually sure where the global vendors folder should be when you have a setup where the cake and application directories are split from each other, but you definitely have to be in your application directory when running commands and not the myapp directory you're using.)
If you add D:\libs\cake\console\ to your PATH environment variable (remembering to close all cmd.exe processes afterwards) then you will simply be able to execute the following:
D:\servers\htdocs\myapp\app> cake report (from within the application directory)
Otherwise you will need to type the full relative or absolute path to the cake console executable and/or provide CakePHP with the absolute path to the application directory (if you are not in it):
D:\servers\htdocs\myapp\app> ..\..\..\..\libs\cake\console\cake report
D:\servers\htdocs\myapp\app> \libs\cake\console\cake report
D:\libs\cake\console> cake -app D:\servers\htdocs\myapp\app report
D:\> libs\cake\console\cake -app D:\servers\htdocs\myapp\app report
etc...
Hopefully you can see why just adding the correct folder to your PATH makes things a lot easier. :)
Try to run it from within the /app directory or with the -app parameter specified:
cake -app d:/servers/htdocs/myapp/app report
Thanks. Here was the issue
My shell script was under /myapp/vendor/shells which was wrong. It should have been under /myapp/app/vendor/shells. After I moved the file, it worked. Thank you
You should always be in your APP path to execute the cake console.
Your Shell File Should be in ..app/Console/Command/
If your file name is TestShell.php type command app> cake test

Resources