[Yaffs-archive] [BUG] in yaffs_unlink()

Luc Van Oostenryck luc.vanoostenryck@easynet.be
Tue, 26 Nov 2002 22:37:33 +0100


--J/dobhs11T7y2rNN
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Hi,

I've found an undiscovered bug in yaffs_unlink():
The problem arise when CONFIG_YAFFS_DISABLE_BACKGROUND_DELETION
is defined and we unlink() the last/only (hard)link to a file,
but this file is still opened by an application
(the attached program can show this quickly).

The problem is easy to understand:
	unlink(2) call	yaffs_unlink()
	who call	yaffs_Unlink()
	who call	yaffs_UnlinkWorker()
	who call	yaffs_UnlinkFile()
	who simply delete everything related to this file:
		directory entry, object header and data.

I will look for this tomorrow (European time).

I will appreciate if you CC any mail related to this to
my stupid email address at work: <project12@banksys.be>.

-- 
Luc Van Oostenryck

--J/dobhs11T7y2rNN
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="test-unlink.c"

#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <stdio.h>

void show_stat(int fd)
{   struct stat buf;
    int rc;

    rc = fstat(fd, &buf);
    if (rc != 0)
    {	perror("fstat() failed");
	exit(1);
    }
    printf("nlink  = %8d\n", buf.st_nlink);
    printf("size   = %8ld\n", buf.st_size);
}

int main(void)
{   int fd;
    int n, nr;
    char buf[1];

    fd = open("in", O_RDONLY);
    if (fd == -1)
    {	perror("open(in) failed");
	exit(1);
    }
show_stat(fd);
    if (unlink("in") != 0)
    {	perror("unlink(in) failed");
	exit(1);
    }
show_stat(fd);			// !!! Crash here in fstat() !!!

    n = 0;
    while ((nr = read(fd, buf, sizeof(buf))) > 0)
    {	n += nr;
    }
    if (nr != 0)
    {	perror("read() failed");
	exit(1);
    }

    printf("readed = %8d\n\n", n);

    sleep(30);
show_stat(fd);
    close(fd);
show_stat(fd);

    return 0;
}

--J/dobhs11T7y2rNN--


---------------------------------------------------------------------------------------
This mailing list is hosted by Toby Churchill open software (www.toby-churchill.org).
If mailing list membership is no longer wanted you can remove yourself from the list by 
sending an email to yaffs-request@toby-churchill.org with the text "unsubscribe" 
(without the quotes) as the subject.