fs/9p: Fix atomic_open
authorM. Mohan Kumar <mohan@in.ibm.com>
Tue, 5 Feb 2013 08:55:05 +0000 (14:25 +0530)
committerEric Van Hensbergen <ericvh@gmail.com>
Sun, 10 Feb 2013 22:29:59 +0000 (16:29 -0600)
commitb6f4bee02f682d1c86ece297871b78ae01afaaf4
treecebad2fa8b3fbc43a54f115b1f69491d5f8d67a5
parent03f0e022736d123bc42907a958535f4f10d0c4c3
fs/9p: Fix atomic_open

Return EEXISTS if requested file already exists, without this patch open
call will always succeed even if the file exists and user specified
O_CREAT|O_EXCL.

Following test code can be used to verify this patch. Without this patch
executing following test code on 9p mount will result in printing 'test case
failed' always.

main()
{
        int fd;

        /* first create the file */
        fd = open("./file", O_CREAT|O_WRONLY);
        if (fd < 0) {
                perror("open");
                return -1;
        }
        close(fd);

        /* Now opening same file with O_CREAT|O_EXCL should fail */
        fd = open("./file", O_CREAT|O_EXCL);
        if (fd < 0 && errno == EEXIST)
        printf("test case pass\n");
        else
        printf("test case failed\n");
        close(fd);
        return 0;
}

Signed-off-by: M. Mohan Kumar <mohan@in.ibm.com>
Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
fs/9p/vfs_inode_dotl.c