[Samba] Re: vfat / ftruncate problem

Uli Luckas luckas at musoft.de
Fri Apr 11 15:51:38 GMT 2003

Am Fre, 2003-04-11 um 16.44 schrieb Tom Schaefer:
> I modified the the source code of vfs-wrap.c, in particular this section:
> result = sys_ftruncate(fd, len);
>         if (result == 0)
>                 goto done;
> to 
> /*result = sys_ftruncate(fd, len);
>         if (result == 0)*/
> result = 0;
>                 goto done;
> recompiled smbd, put the new binary in place, restarted samba and lo and behold it worked!  Now I can copy my 750Meg test file from Windows98SE Windows Explorer to a samba shared vfat partition and the copy starts immediately and completes successfully after a minute or two.
> So, now my question is - What kind of problem(s) if any am I setting myself up for by doing this?

So here you skip all truncate requests where sys_ftruncate does not
succeede. This does not look like a good idea. I guess there usually is
a reason for a function to be called in the first place.

But let's look at your specific situation. There are two kind's of
truncates. An expandig and a shrinking. From the comments in the source
I take it that VFAT truncates work for shrinking but not for expanding.
So at least you can still shrink files. 

When Windows tries to copy a file it seems to expand the destination to
it's final size first. I guess this is just to avoid fragmentation and
to avoid writing 90% of a huge file before failing. So you seem to be
safe in this situation.

An application on the client could choose to ftruncate-expand an empty
file to 4k just to be abel to read 4096 zeros out of it :-) This is
absolutely legal and would fail, as the file would never be
ftruncate-expanded with your modifications.
Honestly, databases do this kind of stuff. And I would not be surprised
if MS-Office apps would use this feature. I can't come up with an
example where bytes beyond the last written byte are ever being read,
but I would not rely on it to never happen.

A much safer Idea would be to skip truncating, returning an error. Maybe
Windows can deal with failing truncates.

result = sys_ftruncate(fd, len);
/*        if (result == 0) */
                goto done;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Dies ist ein digital signierter Nachrichtenteil
Url : http://lists.samba.org/archive/samba/attachments/20030411/35d9eac7/attachment.bin

More information about the samba mailing list