preallocated file size

Nicolas Williams Nicolas.Williams at wdr.com
Mon Feb 7 17:12:26 GMT 2000


On Mon, 7 Feb 100, jeremy at varesearch.com wrote:
> > My initial thoughts go like this: 
> > 
> > typedef struct file_fd_struct { 
> > ... 
> > BOOL check_for_write_at_end; 
> > } file_fd_struct; 
> > 
> > in smbd/open.c open_file() 
> > fds->check_for_write_at_end = True; 
> > ... 
> > 
> > in <the initial write> 
> > if ( fds->check_for_write_at_end == True 
> > && requested_position != 0) { 
> > /* Then application was writing the last block */ 
> > /* of the file first to see if we have enough space. 
> > */ 
> > 
> > fds->check_for_write_at_end == False; 
> > 
> > length = requested_position + len; 
> > (void) fstatvfs(fds->fd, buf); 
> > if (length >= (buf.f_bavail*buf.f_frsize)) { 
> > /* Then the copy will fail eventually, so */ 
> > /* report it now. This will avoid NT (Win2K) 
> > */ 
> > /* assuming it can't fail, and then */ 
> > /* running out of space. The latter leaves */ 
> > /* files full of nulls as the result of a */ 

Well, I think that the 'check_for_write_at_end' flag should be checked
only if the write fails, then do something (such as truncation the file
to 0, to the place where the write failed or unlink the file).

Alternatively see my previous post, where I suggest that Samba prevent
the creation of holey files by SMB clients in the first place.

> I may be away, but through the magic of the internet 
> (and the Computing in High Energy Physics conference :-) I'm still trying 
> to get work done :-) :-). 
> 
> We could prbably do a simpler (and nastier :-) fix, by assuming 
> that if a write fails with ENOSPC, then we should truncate at 
> the requested seek postion for the file. Hmmm. I can see problems 
> with this though - and I *hate* the idea of adding the overhead 
> above to fix what is essentially a client bug... 

Even simpler might be the no-holey-files-by-smb-clients fix.

> Maybe when a client does a filesize set, we should do the 
> above space check. Yes - I like that, it's much 
> cleaner. It also means no special new flag in the fd 
> struct Dave, just do your space check on the setlength 
> call and refuse an error if it would be over quota. 

Well, the problem with doing the filesystem space check when the client
sets the file size without actually allocating the file blocks is that
there may be enough space at the time of the check, and yet the write
may fail later if there are other clients writing to that partition!!

So, methinks that the filesystem space check at file size set time is
only worthwhile if Samba is also going to preallocate the file blocks as
well. This is probably not a cheap operation though...

> What dou you think ? 
> 
> Jeremy. 


Nico
-DISCLAIMER: an automatically appended disclaimer may follow. By posting-
-to a public e-mail mailing list I hereby grant permission to distribute-
-and copy this message.-

This message contains confidential information and is intended only 
for the individual named.  If you are not the named addressee you 
should not disseminate, distribute or copy this e-mail.  Please 
notify the sender immediately by e-mail if you have received this 
e-mail by mistake and delete this e-mail from your system.

E-mail transmission cannot be guaranteed to be secure or error-free 
as information could be intercepted, corrupted, lost, destroyed, 
arrive late or incomplete, or contain viruses.  The sender therefore 
does not accept liability for any errors or omissions in the contents 
of this message which arise as a result of e-mail transmission.  If 
verification is required please request a hard-copy version.  This 
message is provided for informational purposes and should not be 
construed as a solicitation or offer to buy or sell any securities or 
related financial instruments.



More information about the samba-technical mailing list