* UBIFS recovery truncates file to zero size @ 2009-03-11 9:16 Iram Shahzad 2009-03-11 9:51 ` Brijesh Singh 2009-03-11 18:13 ` Reuben Dowle 0 siblings, 2 replies; 10+ messages in thread From: Iram Shahzad @ 2009-03-11 9:16 UTC (permalink / raw) To: linux-mtd Hi I am having the following problem with UBIFS (Linux 2.6.25 + ubifs-v2.6.25). Please could you tell me if this is a known issue. Problem If the power is switched off abruptly while a file is being written, in the next boot the contents of the file is lost. That is, the file becomes zero sized. The problem is reproducable. Thanks in advance. Iram ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: UBIFS recovery truncates file to zero size 2009-03-11 9:16 UBIFS recovery truncates file to zero size Iram Shahzad @ 2009-03-11 9:51 ` Brijesh Singh 2009-03-11 10:31 ` Adrian Hunter 2009-03-11 18:13 ` Reuben Dowle 1 sibling, 1 reply; 10+ messages in thread From: Brijesh Singh @ 2009-03-11 9:51 UTC (permalink / raw) To: Iram Shahzad; +Cc: linux-mtd Hi, On Wed, Mar 11, 2009 at 2:46 PM, Iram Shahzad <iram.shahzad@jp.fujitsu.com> wrote: > Hi > > I am having the following problem with UBIFS (Linux 2.6.25 + ubifs-v2.6.25). > Please could you tell me if this is a known issue. > > Problem > If the power is switched off abruptly while a file is being written, > in the next boot the contents of the file is lost. That is, the file > becomes zero sized. The problem is reproducable. May be because of write-back support. Try disabling it.mount with sync option. For details: http://www.linux-mtd.infradead.org/doc/ubifs.html#L_writeback ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: UBIFS recovery truncates file to zero size 2009-03-11 9:51 ` Brijesh Singh @ 2009-03-11 10:31 ` Adrian Hunter 0 siblings, 0 replies; 10+ messages in thread From: Adrian Hunter @ 2009-03-11 10:31 UTC (permalink / raw) To: Iram Shahzad; +Cc: linux-mtd, Brijesh Singh Brijesh Singh wrote: > On Wed, Mar 11, 2009 at 2:46 PM, Iram Shahzad > <iram.shahzad@jp.fujitsu.com> wrote: >> I am having the following problem with UBIFS (Linux 2.6.25 + ubifs-v2.6.25). >> Please could you tell me if this is a known issue. >> >> Problem >> If the power is switched off abruptly while a file is being written, >> in the next boot the contents of the file is lost. That is, the file >> becomes zero sized. The problem is reproducable. > > May be because of write-back support. Try disabling it.mount with sync option. There was also a problem with busybox implementation of vi which truncated the file to zero length. See revision 21928 here: http://sources.busybox.net/index.py/trunk/busybox/editors/vi.c?view=log&pathrev=22471 ^ permalink raw reply [flat|nested] 10+ messages in thread
* RE: UBIFS recovery truncates file to zero size 2009-03-11 9:16 UBIFS recovery truncates file to zero size Iram Shahzad 2009-03-11 9:51 ` Brijesh Singh @ 2009-03-11 18:13 ` Reuben Dowle 2009-03-12 2:44 ` Iram Shahzad 1 sibling, 1 reply; 10+ messages in thread From: Reuben Dowle @ 2009-03-11 18:13 UTC (permalink / raw) To: Iram Shahzad, linux-mtd The file is kept in the kernel write-back cache, until it is synced by the user (eg. A sync() or fsync() call) or the kernel decides to write it back (seems to be after 30 seconds by default). You can disable write back cache, but if you make lots of small writes to the file this will cause more wear on the flash. It is better to call fsync() when you want the data to be saved. See http://www.linux-mtd.infradead.org/doc/ubifs.html#L_writeback Also be carefull to note the comment about making your updates atomic. Just adding the odd fsync() is not going to truely guarenteed your data is not going to get fried. Reuben -----Original Message----- From: linux-mtd-bounces@lists.infradead.org [mailto:linux-mtd-bounces@lists.infradead.org] On Behalf Of Iram Shahzad Sent: Wednesday, 11 March 2009 10:16 p.m. To: linux-mtd@lists.infradead.org Subject: UBIFS recovery truncates file to zero size Hi I am having the following problem with UBIFS (Linux 2.6.25 + ubifs-v2.6.25). Please could you tell me if this is a known issue. Problem If the power is switched off abruptly while a file is being written, in the next boot the contents of the file is lost. That is, the file becomes zero sized. The problem is reproducable. Thanks in advance. Iram ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/ ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: UBIFS recovery truncates file to zero size 2009-03-11 18:13 ` Reuben Dowle @ 2009-03-12 2:44 ` Iram Shahzad 2009-03-12 8:26 ` Adrian Hunter 0 siblings, 1 reply; 10+ messages in thread From: Iram Shahzad @ 2009-03-12 2:44 UTC (permalink / raw) To: linux-mtd Thanks Brijesh, Adrian, Reuben for your replies. I understood, but please let me confirm further. For the write back enabled case, I was expecting the following behaviour: power went down before the file is sync-ed, so on the next booting the file will be in its old state, that is it will contain the contents which it had before this write. But instead of being in the old state, it becomes empty file. Is this really expected(correct) behaviour? Thanks Iram ----- Original Message ----- From: "Reuben Dowle" <Reuben.Dowle@navico.com> To: "Iram Shahzad" <iram.shahzad@jp.fujitsu.com>; <linux-mtd@lists.infradead.org> Sent: Thursday, March 12, 2009 3:13 AM Subject: RE: UBIFS recovery truncates file to zero size > The file is kept in the kernel write-back cache, until it is synced by > the user (eg. A sync() or fsync() call) or the kernel decides to write > it back (seems to be after 30 seconds by default). > > You can disable write back cache, but if you make lots of small writes > to the file this will cause more wear on the flash. It is better to call > fsync() when you want the data to be saved. > > See http://www.linux-mtd.infradead.org/doc/ubifs.html#L_writeback > > Also be carefull to note the comment about making your updates atomic. > Just adding the odd fsync() is not going to truely guarenteed your data > is not going to get fried. > > Reuben > > -----Original Message----- > From: linux-mtd-bounces@lists.infradead.org > [mailto:linux-mtd-bounces@lists.infradead.org] On Behalf Of Iram Shahzad > Sent: Wednesday, 11 March 2009 10:16 p.m. > To: linux-mtd@lists.infradead.org > Subject: UBIFS recovery truncates file to zero size > > Hi > > I am having the following problem with UBIFS (Linux 2.6.25 + > ubifs-v2.6.25). > Please could you tell me if this is a known issue. > > Problem > If the power is switched off abruptly while a file is being written, > in the next boot the contents of the file is lost. That is, the file > becomes zero sized. The problem is reproducable. > > Thanks in advance. > Iram > > > > ______________________________________________________ > Linux MTD discussion mailing list > http://lists.infradead.org/mailman/listinfo/linux-mtd/ > > ______________________________________________________ > Linux MTD discussion mailing list > http://lists.infradead.org/mailman/listinfo/linux-mtd/ > ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: UBIFS recovery truncates file to zero size 2009-03-12 2:44 ` Iram Shahzad @ 2009-03-12 8:26 ` Adrian Hunter 2009-03-12 8:49 ` Iram Shahzad 0 siblings, 1 reply; 10+ messages in thread From: Adrian Hunter @ 2009-03-12 8:26 UTC (permalink / raw) To: Iram Shahzad; +Cc: linux-mtd Iram Shahzad wrote: > Thanks Brijesh, Adrian, Reuben for your replies. > > I understood, but please let me confirm further. > > For the write back enabled case, I was expecting the > following behaviour: > power went down before the file is sync-ed, so > on the next booting the file will be in its old state, > that is it will contain the contents which it had before > this write. > > But instead of being in the old state, it becomes empty file. > Is this really expected(correct) behaviour? No. How were you updating the file? ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: UBIFS recovery truncates file to zero size 2009-03-12 8:26 ` Adrian Hunter @ 2009-03-12 8:49 ` Iram Shahzad 2009-03-12 10:25 ` Adrian Hunter ` (2 more replies) 0 siblings, 3 replies; 10+ messages in thread From: Iram Shahzad @ 2009-03-12 8:49 UTC (permalink / raw) To: linux-mtd >> For the write back enabled case, I was expecting the >> following behaviour: >> power went down before the file is sync-ed, so >> on the next booting the file will be in its old state, >> that is it will contain the contents which it had before >> this write. >> >> But instead of being in the old state, it becomes empty file. >> Is this really expected(correct) behaviour? > > No. How were you updating the file? The file is updated by a Java application in the following way. ----- FileOutputStream str = new FileOutputStream(aFilename); // some write here str.flush(); str.close(); ----- I switch off the power after confirming that the str.close() has been executed. P.S: If I add str.getFD().sync(); after the str.flush(), the file looks good in the next boot. However my question still remains for the case when I do not call str.getFD().sync: "why the file becomes empty rather than being in its old state?". Thanks Iram ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: UBIFS recovery truncates file to zero size 2009-03-12 8:49 ` Iram Shahzad @ 2009-03-12 10:25 ` Adrian Hunter 2009-03-12 11:08 ` Artem Bityutskiy 2009-03-12 11:11 ` Jamie Lokier 2 siblings, 0 replies; 10+ messages in thread From: Adrian Hunter @ 2009-03-12 10:25 UTC (permalink / raw) To: Iram Shahzad; +Cc: linux-mtd Iram Shahzad wrote: >>> For the write back enabled case, I was expecting the >>> following behaviour: >>> power went down before the file is sync-ed, so >>> on the next booting the file will be in its old state, >>> that is it will contain the contents which it had before >>> this write. >>> >>> But instead of being in the old state, it becomes empty file. >>> Is this really expected(correct) behaviour? >> No. How were you updating the file? > > The file is updated by a Java application in the following way. > > ----- > FileOutputStream str = new FileOutputStream(aFilename); > // some write here > str.flush(); > str.close(); > ----- > > I switch off the power after confirming that the str.close() has been > executed. > > P.S: > If I add str.getFD().sync(); after the str.flush(), the file looks good in > the next boot. However my question still remains for the case > when I do not call str.getFD().sync: > "why the file becomes empty rather than being in its old state?". > > Thanks > Iram > > > > ______________________________________________________ > Linux MTD discussion mailing list > http://lists.infradead.org/mailman/listinfo/linux-mtd/ > What makes you think that: FileOutputStream str = new FileOutputStream(aFilename); does not truncate the file to zero length? ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: UBIFS recovery truncates file to zero size 2009-03-12 8:49 ` Iram Shahzad 2009-03-12 10:25 ` Adrian Hunter @ 2009-03-12 11:08 ` Artem Bityutskiy 2009-03-12 11:11 ` Jamie Lokier 2 siblings, 0 replies; 10+ messages in thread From: Artem Bityutskiy @ 2009-03-12 11:08 UTC (permalink / raw) To: Iram Shahzad; +Cc: linux-mtd On Thu, 2009-03-12 at 17:49 +0900, Iram Shahzad wrote: > >> For the write back enabled case, I was expecting the > >> following behaviour: > >> power went down before the file is sync-ed, so > >> on the next booting the file will be in its old state, > >> that is it will contain the contents which it had before > >> this write. > >> > >> But instead of being in the old state, it becomes empty file. > >> Is this really expected(correct) behaviour? > > > > No. How were you updating the file? > > The file is updated by a Java application in the following way. > > ----- > FileOutputStream str = new FileOutputStream(aFilename); > // some write here > str.flush(); > str.close(); > ----- Please, check whether str.flush()/str.close() cause fsync()/sync(). -- Best regards, Artem Bityutskiy (Битюцкий Артём) ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: UBIFS recovery truncates file to zero size 2009-03-12 8:49 ` Iram Shahzad 2009-03-12 10:25 ` Adrian Hunter 2009-03-12 11:08 ` Artem Bityutskiy @ 2009-03-12 11:11 ` Jamie Lokier 2 siblings, 0 replies; 10+ messages in thread From: Jamie Lokier @ 2009-03-12 11:11 UTC (permalink / raw) To: Iram Shahzad; +Cc: linux-mtd Iram Shahzad wrote: > >>For the write back enabled case, I was expecting the > >>following behaviour: > >> power went down before the file is sync-ed, so > >> on the next booting the file will be in its old state, > >> that is it will contain the contents which it had before > >> this write. > >> > >>But instead of being in the old state, it becomes empty file. > >>Is this really expected(correct) behaviour? > > > >No. How were you updating the file? > > The file is updated by a Java application in the following way. > > ----- > FileOutputStream str = new FileOutputStream(aFilename); "new FileOutputStream" truncates the file. > I switch off the power after confirming that the str.close() has been > executed. > > P.S: > If I add str.getFD().sync(); after the str.flush(), the file looks good in > the next boot. However my question still remains for the case > when I do not call str.getFD().sync: > "why the file becomes empty rather than being in its old state?". str.getFD().sync() won't be reliable if you lose power _between_ "new FileOutputStream" and sync(). If that happens, the file may still be truncated. If you are just appending data, use "new FileOutputStream(aFileName, true)", write, flush, sync, close. If you are changing the file contents, instead write to a temporary file in the same directory, then sync the temporary file (after flush), then do an atomic rename over the original file, then open the directory and sync that somehow. -- Jamie ^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2009-03-12 11:12 UTC | newest] Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2009-03-11 9:16 UBIFS recovery truncates file to zero size Iram Shahzad 2009-03-11 9:51 ` Brijesh Singh 2009-03-11 10:31 ` Adrian Hunter 2009-03-11 18:13 ` Reuben Dowle 2009-03-12 2:44 ` Iram Shahzad 2009-03-12 8:26 ` Adrian Hunter 2009-03-12 8:49 ` Iram Shahzad 2009-03-12 10:25 ` Adrian Hunter 2009-03-12 11:08 ` Artem Bityutskiy 2009-03-12 11:11 ` Jamie Lokier
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.