I'm trying to familiarize myself with modifying Minix system calls and rebuilding the kernel.
I modified mkdir
to print New dir -> <directory-name> <permissions>
every time it was called, unless the directory already existed.
I edited /usr/src/servers/vfs/open.c
, which contains the code for mkdir
.
I added this line of code to line 610:
printf("New dir -> %s %o",fullpath,dirmode);
With this edit, mkdir
printed correctly, except that if the folder already existed, I was getting the following message:
New Dir -> test 755 mkdir: test: file exists
I expected to see:
mkdir: test: file exists
I thought that by adding the printf to the last if-else body near line 610, it would not execute in this case, since this if-else structure checks if the new directory is valid (inode, permissions, etc), and the call should return if the directory already exists. I was mistaken.
What system function or variable should I check to see if the file already exists?
I'm using Minix version 3.2.1.
To test this, I rebuilt just the kernel, like this:
cd /usr/src/releasetools
make hdboot