Jun 26 2010

Be a man… Submit a man-page patch today !

All of us (well, at least some of us) like to test the limit of existing things.. That’s what I tried to do with the below given program. I decided to find the limit of the directories created in directories for an ext3 file system using mkdir(). Any one of you could find the reason behind it ? Well, it was for fun :)

# cat test_max_directories.c
————————————————
#include <stdio.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <errno.h>

int main()
{
char dirname[50];
int i;
/* The max number of subdirectories in one directory for ext3 is 32000 */
int limit = 32001;

for (i = 0; i < limit; i++) {
sprintf(dirname, “testdir%d”, i);
if ((mkdir(dirname, 00777)) == -1) {
perror(“Error in creating directory!”);
printf(“errno = %d\n”, errno);
exit(1);
}
}
return 0;

}

———————–

As expected, strace showed that it failed, however with an EMLINK error:

mkdir(“testdir31998″, 0777)             = -1 EMLINK (Too many links)

Here comes the next  thing…. EMLINK error is not present in the man page of mkdir(2) … Wo hoo… a big chance to submit a patch to Linux Kernel Man page project …. I have started the exciting process of preparing the patch, mail and follow up process.

First, I should download the latest kernel man pages which is now in a git repository:

#apt-get install git-core

#git clone git://git.kernel.org/pub/scm/docs/man-pages/man-pages.git

After check out, I have made the necessary changes in mkdir.2 page and prepared the patch using the command:

# git diff

I got the below listed patch:
————

diff –git a/man2/mkdir.2 b/man2/mkdir.2
index e6cb28c..d01bafd 100644
— a/man2/mkdir.2
+++ b/man2/mkdir.2
@@ -73,6 +73,10 @@ is a symbolic link, dangling or not.
Too many symbolic links were encountered in resolving
.IR pathname .
.TP
+.B EMLINK
+The new directory cannot be created because the number of sub directories
+in a directory is limited to LINK_MAX defined by the file system.
+.TP
.B ENAMETOOLONG
.IR pathname ” was too long.”
.TP

—————————

Here comes the most exciting part… Create a proper mail and convince the man page maintainer to include this to the mkdir man page.

First, I should choose the right mail id’s to send the patch. From the mailing list it should be mailed with:

To: mtk.manpages@googlemail.com

CC: linux-man@vger.kernel.org

(make sure that you are already subscribed to linux-man@vger.kernel.org)

Then it is important to give the correct subject line. It gives the required importance to the patch. A wrong subject line could ruin to chances to mainline your patch . As I have previous experience with this mailing list, I chose the subject line:

[PATCH] mkdir.2: Add EMLINK error

Next important thing is what we should write in the mail. We should support our patch and show it’s importance. It should have the “Signed-off-by : Name <mail id> and properly placed patch along with the mail. Some groups will reject the patch right away if we attach the patch with the mail as a separate attachment.  So, observe the mailing list and then decide how to send the patch.

——————————————-

Dear Michael,

While executing the below given program in ext3 file system, I came
across the EMLINK error in mkdir(2) syscall.

# cat test_max_directories.c

#include <stdio.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <errno.h>

int main()
{
char dirname[50];
int i;
/* The max number of subdirectories in one directory for ext3 is 32000 */
int limit = 32001;

for (i = 0; i < limit; i++) {
sprintf(dirname, “testdir%d”, i);
if ((mkdir(dirname, 00777)) == -1) {
perror(“Error in creating directory!”);
printf(“errno = %d\n”, errno);
exit(1);
}
}
return 0;
}

# ./a.out
Error in creating directory!: Too many links
errno = 29

An strace of this execution shows that the mkdir(2) call generates an
EMLINK error when it reaches the limit of  maximum number of sub
directories in one directory

#strace ./a.out
——————————

—–
…..
mkdir(“testdir31998″, 0777)             = -1 EMLINK (Too many links)
dup(2)                                  = 3
fcntl64(3, F_GETFL)                     = 0×8002 (flags O_RDWR|O_LARGEFILE)
brk(0)                                  = 0x804a000
brk(0x806b000)                          = 0x806b000
fstat64(3, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 2), …}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1,
0) = 0xb7f71000
_llseek(3, 0, 0xbffc3078, SEEK_CUR)     = -1 ESPIPE (Illegal seek)
write(3, “Error in creating directory!: To”…, 45Error in creating
directory!: Too many links
) = 45
close(3)                                = 0
munmap(0xb7f71000, 4096)                = 0
fstat64(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 2), …}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1,
0) = 0xb7f71000
write(1, “errno = 29\n”, 11errno = 29
)            = 11
exit_group(1)                           = ?
Process 16246 detached
———————————–

However, reference to EMLINK is not present in the mkdir(2) man page.
The following patch adds the EMLINK error in the man page of mkdir(2).

Kindly let me know if there are any issues.

Best Regards,
Maxin B. John
www.maxinbjohn.info

Signed-off-by: Maxin B. John <maxinbjohn@gmail.com>

——-

diff –git a/man2/mkdir.2 b/man2/mkdir.2
index e6cb28c..d01bafd 100644
— a/man2/mkdir.2
+++ b/man2/mkdir.2
@@ -73,6 +73,10 @@ is a symbolic link, dangling or not.
Too many symbolic links were encountered in resolving
.IR pathname .
.TP
+.B EMLINK
+The new directory cannot be created because the number of sub directories
+in a directory is limited to LINK_MAX defined by the file system.
+.TP
.B ENAMETOOLONG
.IR pathname ” was too long.”
.TP

—————————————————————————
Next process is to follow it up. I got frustrated when nobody from the list replied to me about the patch for the next two days… So I have sent the follow up mail to the list as a reply to my first mail. All I wanted to show was that my patch was relevant.
—————————–
Hi,

A quick google search shows that the sus v3 version of mkdir(2) has
reference to EMLINK error

http://www.opengroup.org/onlinepubs/000095399/functions/mkdir.html

[EMLINK]
The link count of the parent directory would exceed {LINK_MAX}.

Please let me know your opinion on this.

Best Regards,
Maxin B. John

————————————
There were no replies even after 2 days of sending this mail also. So I just decided to ping the group. A mail as a reply to my previous mails just to let them know that I am waiting to know their opinion:
——
ping …
——
Finally I got this reply from Michael Kerrisk, the Linux Kernel Man pages maintainer:
———————————
Hello Maxin,

- Show quoted text -
On Mon, Jun 21, 2010 at 5:48 PM, Maxin John <maxin.john@gmail.com> wrote:
> Dear Michael,
…..
Thanks for the very precise and well supported bug report!

Yes, the page should be fixed. …..

…………………………
Bingo.. they accepted the patch, with some modifications though… :)
Links:
http://permalink.gmane.org/gmane.linux.man/1484
http://permalink.gmane.org/gmane.linux.man/1471
http://permalink.gmane.org/gmane.linux.man/1478
http://permalink.gmane.org/gmane.linux.man/1483
Come, be a man … Submit some kernel man page patches :)

Get Adobe Flash playerPlugin by wpburn.com wordpress themes