I have the following code:
#define RAMFILE_NAME "/file.ram"
#define SHOW_RESULT( _fn, _res ) \
printf("\n<FAIL>: " #_fn "() returned %ld %s\n", \
(unsigned long)_res, _res<0?strerror(errno):"");
int createfile( char *name )
{
int fd;
int err;
err = mount( "", "/", "ramfs" );
if ( err < 0 ) { SHOW_RESULT( mount, err ); }
else { printf("\nRAMFS mounted successfully"); }
err = chdir( "/" );
if( err < 0 ) SHOW_RESULT( chdir, err );
// if a file already exists, delete it
if ( access( name, F_OK ) == 0 ) { unlink(name); }
fd = open( name, O_RDWR | O_CREAT );
if( fd < 0 ) { SHOW_RESULT( open, fd ); }
return fd;
}
int umountFilesystem()
{
int err;
err = unlink(RAMFILE_NAME);
if ( err < 0 ) fprintf(stderr,"Failed to delete \"%s\" from
RAMFS.",RAMFILE_NAME);
sleep(1);
err = umount("/");
if( err < 0 ) { SHOW_RESULT( umount, err ); }
return err;
}
I have a calling function that kicks off createFile(RAMFILE_NAME), does some
work with the file and then calls umountFilesystem(), which returns the
following error message through the SHOW_RESULT macro:
<FAIL>: umount() returned -1 Resource busy
The reason I'm trying to un-mount the file system (or FSSYNC) after unlinking
the RAM file is due to the fact that the filesystem is buffered (see:
https://www.sourceware.org/ml/ecos-discuss/2006-01/msg00160.html), which
presents a problem for a limited-resource, embedded system that needs to create
and delete files on a somewhat frequent basis. The solution discussed in that
post is apparently to, "call it using a setinfo call with a FS_INFO_SYNC
operation." However, I do not know how to implement this solution. Could you
provide me an example or offer some help?
Thanks.