lkml.org 
[lkml]   [1998]   [Aug]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectLarge numbers of files.

You can make a directory that is too large to be read with the
usual tools. If you run this program, I'd suggest that you mount
a "scrap" disk on /tmp, because you might have to use mke2fs to
fix the mess.


#include <stdio.h>
#include <unistd.h>
#include <signal.h>
#include <fcntl.h>

int sig = 1;

void foo(int unused)
{
sig = 0;
}
main()
{
int fd;
int nam;
int len;
char fname[0x400];
(void)signal(SIGINT, foo);
(void)signal(SIGQUIT, foo);
for(nam = 0;sig;nam++)
{
len = sprintf(fname,"/tmp/file.%08x",nam);
if((fd = open(fname, O_RDWR|O_CREAT, 0644)) > 0)
{
if(write(fd, fname, len) == len)
(void)close(fd);
else
{
(void)close(fd);
break;
}
}
else
break;
}
puts("Done!");
return 0;
}
If you run this for a few seconds, you will find that the files
exist in /tmp as expected.

If you run this until it errors out from a full file-system, you
(may) find....
# rm -r /tmp <SEGFAULTS>
# rm /tmp/file.00000000 <waits forever and can't be killed>
# ls /tmp <waits forever and can't be killed>
# vi /tmp/file.00000000 <waits forever and can't be killed>
Converting the program to blindly remove each of the files fails
with ENOENT.

total: used: free: shared: buffers: cached:
Mem: 31244288 28897280 2347008 7794688 6348800 15355904
Swap: 133885952 0 133885952
MemTotal: 30512 kB
MemFree: 2292 kB
MemShared: 7612 kB
Buffers: 6200 kB
Cached: 14996 kB
SwapTotal: 130748 kB
SwapFree: 130748 kB

I used a 640 megabyte disk mounted ext2 on /tmp for this test.


Cheers,
Dick Johnson
***** FILE SYSTEM MODIFIED *****
Penguin : Linux version 2.1.113 on an i586 machine (66.15 BogoMips).
Warning : It's hard to remain at the trailing edge of technology.

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.altern.org/andrebalsa/doc/lkml-faq.html

\
 
 \ /
  Last update: 2005-03-22 13:43    [from the cache]
©2003-2011 Jasper Spaans