LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Data not correctly saved to disk

I have an application of mine which is intended to run unattended 24/7 collecting data and handling tests. During the application I periodically save working status informations to disk, with the aim of reloading them at program launch and restart working operation where they have left off the last time.

Informations are a fixed volume of data (<20kb) save every minute on the same file; the file is opened and closed in this operation with this function:

int SaveSts (void)
{
	FILE	*stH = NULL;

	stH = fopen (fsts, "rb+");
	if (errno) goto Error;

	// 's' is an array of structures of 'sz' elements
	fwrite ((char *)s, sizeof(status), sz, stH);
	if (errno) goto Error;

Error:
	if (stH) fclose (stH);
	return errno;
}

 

Now I am facing a strange situation in which the user restarts the program finding that saved situation refers to some moment in the past (from a few minutes to several hours) as if the save function weren't working properly event though no error is found in it. It happens after the system has automatically restarted due to OS updates overnight (the system does not handle a close message from the OS -my bad- so it could close improperly in this situation).

 

Beyond double checking my program, I am wandering whether it can depend on some hardware or OS characteristics like the disk cache that delays physical write to disk or whatsoever feature I can't imagine at the moment. Also, I don't know if continuously writing the same amount of information on the same file on disk can introduce some unexpected odd behaviour in the system.

 

Every time I check status file date during program life it is correct, but I could be forcing a disk update just for the fact that I am observing the very file in the Resource Manager Smiley Surprised

 

Anybody has some knowledge to share on this? I am a bit lost on how to determine where the problem is and how to solve it...



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 1 of 6
(4,375 Views)

you certainly checked disk write caching.... is it turned off?

 

Device Manager / Disk Drive / Properties > Policies

0 Kudos
Message 2 of 6
(4,373 Views)

No, I haven't checked and I can't do it now: the PC is on customer's site and I don't have remote access at present. I will contact him and have him check this.

Can this alter normal PC operation and how much? You know, the program is supposed to save test data too while working Smiley Wink

Additionally, could disk caching explain that several hour misalignment?



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 3 of 6
(4,367 Views)

You are right, hours sounds like an excellent counter argument, and with 20 kB / minute any buffer should be filled rather quickly (but this was my only idea...)

0 Kudos
Message 4 of 6
(4,358 Views)
Hi Roberto,

Did you consider using fflush to make sure the buffer is forced into the file?

About OS shutdown, I never used it but there is a function called 'atexit' that registers a function to be called when the program exits. I am not sure it is signaled even for a forced kill of the application.

Hope these help 🙂
S. Eren BALCI
IMESTEK
0 Kudos
Message 5 of 6
(4,352 Views)

Fflush is one of the possible additions, perhaps the most immediate to implement, even though I would say that closing the file has the same effect.

 

I have now working a reduced version of the application with some equipment in my laboratory: next monday I'll see if I can replicate the issue and then apply some correction; fflush and trapping the system closing message are the first I planned.

 

Other suggestions are welcome Smiley Happy



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 6 of 6
(4,348 Views)