Bug 1028 - set SPARSE attribute in dos_mode()
set SPARSE attribute in dos_mode()
Product: Samba 3.0
Classification: Unclassified
Component: File Services
All Linux
: P5 minor
: none
Assigned To: Jeremy Allison
Depends on:
  Show dependency treegraph
Reported: 2004-02-01 20:00 UTC by YAMASAKI Hiroyuki
Modified: 2005-08-24 10:18 UTC (History)
0 users

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description YAMASAKI Hiroyuki 2004-02-01 20:00:34 UTC
Sorry for my poor english.

In samba3.0.2rc2 smbd/dosmode.c/dos_mode(), I think below SPARSE attribute code 
is not good for Linux, because linux st_blocks gives the size of the file in 
512-byte blocks. 

>#if defined (HAVE_STAT_ST_BLOCKS) && defined (HAVE_STAT_ST_BLKSIZE)
>    if (sbuf->st_size > sbuf->st_blocks * (SMB_OFF_T)sbuf->st_blksize) {
>        result |= FILE_ATTRIBUTE_SPARSE;
>    }

Linux manpage of stat says :
The value st_size gives the size of the file (if it is a regular 
file or a symlink) in bytes. The size of a symlink is the length 
of the pathname it contains, without trailing NUL. 

The value st_blocks gives the size of the file in 512-byte blocks. 
(This may be smaller than st_size/512 e.g. when the file has holes.)

The value st_blksize gives the "preferred" blocksize for efficient 
file system I/O. (Writing to a file in smaller chunks may cause an 
inefficient read-modify-rewrite.) 

Probably, using STAT_ST_BLOCKSIZE is better way, same as 

And, should make sure SPARSE attribute apply to regular file.

Finally, I think below code is better for Linux.
#if defined (HAVE_STAT_ST_BLOCKS) && defined (STAT_ST_BLOCKSIZE)
    if (S_ISREG(sbuf->st_mode ) && sbuf->st_size > sbuf->st_blocks * 
        result |= FILE_ATTRIBUTE_SPARSE;
Comment 1 Gerald (Jerry) Carter 2005-02-08 21:52:13 UTC
here's one for you jeremy.  Might be interesting or no longer valid.
Comment 2 James Peach (outdated mail address) 2005-06-06 23:20:44 UTC
This fix appears to be in svn HEAD.
Comment 3 Jeremy Allison 2005-06-27 12:07:30 UTC
Added to SAMBA_3_0 and HEAD.
Comment 4 Gerald (Jerry) Carter 2005-08-24 10:18:16 UTC
sorry for the same, cleaning up the database to prevent unecessary reopens of bugs.