BUG in ext2 file-system (2.0.33 kernel): tried to extend a file using lseek

BUG in ext2 file-system (2.0.33 kernel): tried to extend a file using lseek

Post by Josh Yelo » Mon, 16 Feb 1998 04:00:00



There's an optimization in ext2fs where if a block of a file contains
all zeros, then that block is not stored.  This is particularly relevant
in cases where files are extended with lseek --- the intervening space
is intentionally filled with zeros.  Do you think that could be
contributing to the discrepancy?

- Josh

 
 
 

BUG in ext2 file-system (2.0.33 kernel): tried to extend a file using lseek

Post by Chris Ranki » Tue, 17 Feb 1998 04:00:00


Hello all,

I  have been sweating * trying to get my block quotas to agree on my
ext2 partition recently - it seems that a file-system bug is partly
responsible. I managed to produce this directory entry by extending a
file using lseek() (according to the manual, this use of lseek is
allowed):

bash$ ls -als
total 27
   1 drwxr-xr-x   2 Chris    users        1024 Feb 15 23:09 .
   1 drwxr-xr-x   9 Chris    users        1024 Feb 13 01:04 ..
   1 -rw-r--r--   1 Chris    users          76 Jan 23 00:17 Hello.c
   2 -rw-r--r--   1 Chris    users        1103 Feb 15 16:19 Makefile
   1 -rw-------   1 Chris    users        8016 Feb 15 22:40 TESTME
   3 -rw-r--r--   1 Chris    users        2664 Nov 10 22:18 copy.c

The guilty party here is the file TESTME. I trust you will agree that an
8016-byte file should use more than one block on a 1024 byte-blocksize
filesystem (which I have)...

I have attached the program I used to generate this result.

Have fun with this one,
Cheers,
Chris.

[ testseek.c < 1K ]
#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>

const char *const szTestFile = "./TESTME";
#define FAILURE  -1

typedef struct tagChunk
        {
          int a1, a2, a3, a4;
        } CHUNK;

int main()
{
  int fd;

  fd = open(szTestFile,O_CREAT|O_TRUNC|O_RDWR,S_IRUSR|S_IWUSR);
  if (fd != FAILURE)
  {
    const CHUNK stChunk = {0,0,0,0};
    lseek(fd,500*sizeof(CHUNK),SEEK_SET);
    write(fd,&stChunk,sizeof(stChunk));
    close(fd);
  }

  return 0;

Quote:}


 
 
 

BUG in ext2 file-system (2.0.33 kernel): tried to extend a file using lseek

Post by Marc Slemk » Tue, 17 Feb 1998 04:00:00



Quote:>This is a multi-part message in MIME format.
>--------------6FE5D189D8E3157482700AF4
>Content-Type: text/plain; charset=us-ascii
>Content-Transfer-Encoding: 7bit
>Hello all,
>I  have been sweating * trying to get my block quotas to agree on my
>ext2 partition recently - it seems that a file-system bug is partly
>responsible. I managed to produce this directory entry by extending a
>file using lseek() (according to the manual, this use of lseek is
>allowed):
>bash$ ls -als
>total 27
>   1 drwxr-xr-x   2 Chris    users        1024 Feb 15 23:09 .
>   1 drwxr-xr-x   9 Chris    users        1024 Feb 13 01:04 ..
>   1 -rw-r--r--   1 Chris    users          76 Jan 23 00:17 Hello.c
>   2 -rw-r--r--   1 Chris    users        1103 Feb 15 16:19 Makefile
>   1 -rw-------   1 Chris    users        8016 Feb 15 22:40 TESTME
>   3 -rw-r--r--   1 Chris    users        2664 Nov 10 22:18 copy.c
>The guilty party here is the file TESTME. I trust you will agree that an
>8016-byte file should use more than one block on a 1024 byte-blocksize
>filesystem (which I have)...

Nope.  If there is no data in a big chunk, and the OS knows it,
why[0] would it be dumb enough to write all that to disk when it can
magically recreate it on demand?  One name given to this feature
is "sparse files".

[0] Ok, there are valid reasons why it should write the whole thing
to disk in some cases.  It is a tradeoff.

 
 
 

BUG in ext2 file-system (2.0.33 kernel): tried to extend a file using lseek

Post by Tim Smi » Tue, 17 Feb 1998 04:00:00



Quote:>The guilty party here is the file TESTME. I trust you will agree that an
>8016-byte file should use more than one block on a 1024 byte-blocksize
>filesystem (which I have)...

No, I won't agree to that, and (more importantly) neither does the filesystem.
You've got holes in your file, and the filesystem doesn't bother to allocate
blocks to holes.

--Tim Smith

 
 
 

BUG in ext2 file-system (2.0.33 kernel): tried to extend a file using lseek

Post by Tim Smi » Tue, 17 Feb 1998 04:00:00



Quote:>There's an optimization in ext2fs where if a block of a file contains
>all zeros, then that block is not stored.  This is particularly relevant

No there isn't.  Files that contain interior sections that have never
been written to are assumed to have zeros at skipped locations, and those
zeros are not stored when consecutive groups of them form a block aligned
block sized section, but blocks of zeros you actually write are stored.

--Tim Smith

 
 
 

BUG in ext2 file-system (2.0.33 kernel): tried to extend a file using lseek

Post by Chris Ranki » Wed, 18 Feb 1998 04:00:00



> The guilty party here is the file TESTME. I trust you will agree that an
> 8016-byte file should use more than one block on a 1024 byte-blocksize
> filesystem (which I have)...


> No, I won't agree to that, and (more importantly) neither does the filesystem.
> You've got holes in your file, and the filesystem doesn't bother to allocate
> blocks to holes.

I received a lot of feedback on this issue, including some in private e-mail, and
all of it explaining ext2's support for sparse files. This helps me, but doesn't
solve my -real- problem. I shall elaborate:

I am trying to write my own version of quotacheck (for the sheer hell of it), and
am trying to do so in such a way that I don't depend on the internal structure of
/quota.user etc. To this end I do the following:

-create a blank quota file
-enable quotas
-search the filesystem, compiling a list of which user owns which file (yes, I am
aware of hard/soft links) and how many blocks that file owns. This is done using
lstat(), and I do adjust the "raw" block count to get the number of filesystem
blocks.
-use this info to set the quota using quotactl()
-disable quotas again, thus prompting the kernel to write its data to disc.

There are other considerations such as group quotas and various "what if ...?"
scenarios, but the approach outlined above is the one with the problem. The
problem appears thus:

-Disable quotas and delete any /quota.* files.
-Create a "null" quota file containing a zero entry for root. (I hope to move
away from this, but for now...)
-Enable quotas
-Scan the disc, but don't assign any quotas
-Disable quotas.

The program reports that root is using 18253 blocks for 3189 inodes.

-Repeat the above procedure, but this time DO assign quotas

Output from the quota system: root is using 18261 blocks for 3189 inodes.

- Repeat the procedure, NOT assigning quotas

Output from the filesystem search: root is using 18256 blocks for 3189 inodes.

bash$ ls -als /quota.*
   4 -rw-------   1 root     root        16032 Feb 16 22:25 /quota.user

Conclusion? root's block-quota is 5 blocks astray. I have no idea where these
missing blocks are. However, I do know that the kernel allocated them all while
writing out the quota-file. And the approach the kernel uses to write the
quota-file is to set the file-position to the correct offset and then call the
file's write-operation; i.e. the quota-file is truly a sparse file. I did occur
to me to wonder whether some of the "phantom" blocks are somehow being added into
the block-quota, though.

Any insights would be welcome,
Cheers.
Chris.

 
 
 

1. copy umsdos file system to ext2 file system

I have a fully opperational linux file system on a dos partition installed as a umsdos
system and would like to copy it to a linux ext2 partition. Is this possible?
I am using loadlin to load linux, I do not want to use lilo.
This is my present partition table:

/dev/hdb5  6   dos 16-bit >=32M    slackware 96
/dev/hdb6  83  Linux native        redhat 4.1
/dev/hdb7  83  Linux native        empty ext2 500meg partition

Linux on hdb5 is running perfectly and I have almost 300Megs on it and I don't want
to load it from scratch.

Thaanks in advance,


2. Flagship in LInux Emulation on 4.3-BETA

3. How to access files in ext2 file system in windows(same system)

4. How to tell tcsh to literally display ESC (not as ^[) in prompt

5. Enhanced Filing system - file system like DEC Advanced File system for Linux

6. XMoveWindow hangs (Fvwm95 AutoRaise)

7. Probable bug in ext2 file system

8. BW Netscape icons with Matrox card, 24-bits

9. "Standard Journaled File System" vs "Large File Enabled Journaled File System"

10. Possible EXT2 File System Corruption in Kernel 2.4

11. Linux 2.4 Kernel trouble with 2.2 ext2 file system

12. Kernel 2.0.33: Very high load caused by network driver bug?

13. Compare file modification date using tcsh built-ins