[BusyBox 0002944]: vi truncates the file synchronously in file_write() but does write() asynchronously.

bugs at busybox.net bugs at busybox.net
Fri Apr 18 21:42:33 UTC 2008


A NOTE has been added to this issue. 
====================================================================== 
http://busybox.net/bugs/view.php?id=2944 
====================================================================== 
Reported By:                kulve
Assigned To:                BusyBox
====================================================================== 
Project:                    BusyBox
Issue ID:                   2944
Category:                   Other
Reproducibility:            always
Severity:                   minor
Priority:                   normal
Status:                     assigned
====================================================================== 
Date Submitted:             04-18-2008 11:13 PDT
Last Modified:              04-18-2008 14:42 PDT
====================================================================== 
Summary:                    vi truncates the file synchronously in file_write()
but does write() asynchronously.
Description: 
Because the file is truncated to zero synchronously for in-place rewriting
and written asynchronously it's vulnarable to losing all data on power
loss. This is easily reproducable with e.g. UBIFS by editing the file,
exiting and then immediately powering the device off (yeah, I should have
run sync before just powering off).

The file_write() should probably be done in a way that would lose only the
changes, not the original file. With smaller files this could be achieved
with e.g. using mv. 
====================================================================== 

---------------------------------------------------------------------- 
 vda - 04-18-08 14:42  
---------------------------------------------------------------------- 
What do you mean "written asynchronously"?
It is written this way:

        fd = open(fn, (O_WRONLY | O_CREAT | O_TRUNC), 0666);
        if (fd < 0)
                return -1;
        cnt = last - first + 1;
        charcnt = full_write(fd, first, cnt);
        if (charcnt == cnt) {
                // good write
                //file_modified = FALSE; // the file has not been
modified
        } else {
                charcnt = 0;
        }
        close(fd);

How do you propose doing it instead? 

Issue History 
Date Modified   Username       Field                    Change               
====================================================================== 
04-18-08 11:13  kulve          New Issue                                    
04-18-08 11:13  kulve          Status                   new => assigned     
04-18-08 11:13  kulve          Assigned To               => BusyBox         
04-18-08 14:42  vda            Note Added: 0006664                          
======================================================================




More information about the busybox-cvs mailing list