noux: add SYSCALL_SYNC

File systems using the File_system_session interface can now be
synchronized by using this syscall. This is needed for file system
that maintain an internal cache, which should be flushed.

Fixes #1008.
This commit is contained in:
Josef Söntgen 2013-12-18 12:04:04 +01:00 committed by Norman Feske
parent e1370b558e
commit f71e38702f
8 changed files with 55 additions and 0 deletions

View File

@ -75,6 +75,7 @@ namespace Noux {
SYSCALL_GETTIMEOFDAY,
SYSCALL_CLOCK_GETTIME,
SYSCALL_UTIMES,
SYSCALL_SYNC,
SYSCALL_INVALID = -1
};
@ -122,6 +123,7 @@ namespace Noux {
NOUX_DECL_SYSCALL_NAME(GETTIMEOFDAY)
NOUX_DECL_SYSCALL_NAME(CLOCK_GETTIME)
NOUX_DECL_SYSCALL_NAME(UTIMES)
NOUX_DECL_SYSCALL_NAME(SYNC)
case SYSCALL_INVALID: return 0;
}
return 0;

View File

@ -494,6 +494,8 @@ namespace Noux {
SYSIO_DECL(utimes, { Path path; unsigned long sec; unsigned long usec; },
{ });
SYSIO_DECL(sync, { }, { });
};
};
};

View File

@ -550,6 +550,12 @@ void endpwent(void)
}
extern "C" void sync(void)
{
noux_syscall(Noux::Session::SYSCALL_SYNC);
}
/********************
** Time functions **
********************/

View File

@ -652,6 +652,30 @@ namespace Noux {
char const *name() const { return "dir"; }
/**
* Synchronize all file systems
*
* Only file system using the File_system_session interface are
* synchronized.
*/
void sync()
{
for (File_system *fs = _first_file_system; fs; fs = fs->next) {
Fs_file_system *fs_fs = dynamic_cast<Fs_file_system *>(fs);
if (fs_fs) {
fs_fs->sync();
continue;
}
/* the directory might contain Fs_file_systems */
Dir_file_system *dir_fs = dynamic_cast<Dir_file_system *>(fs);
if (dir_fs) {
dir_fs->sync();
continue;
}
}
}
/********************************
** File I/O service interface **

View File

@ -42,6 +42,15 @@ namespace Noux {
* This function is used for debugging only.
*/
virtual char const *name() const = 0;
/**
* Synchronize file system
*
* This function is only used by a Fs_file_system because such a
* file system may employ a backend, which maintains a internal
* cache, that needs to be flushed.
*/
virtual void sync() { }
};
}

View File

@ -576,6 +576,11 @@ namespace Noux {
char const *name() const { return "fs"; }
void sync()
{
_fs.sync();
}
/********************************
** File I/O service interface **

View File

@ -789,6 +789,12 @@ bool Noux::Child::syscall(Noux::Session::Syscall sc)
return true;
}
case SYSCALL_SYNC:
{
root_dir()->sync();
return true;
}
case SYSCALL_SOCKET:
case SYSCALL_GETSOCKOPT:
case SYSCALL_SETSOCKOPT:

View File

@ -111,6 +111,7 @@ bool Noux::Child::_syscall_net(Noux::Session::Syscall sc)
case SYSCALL_GETTIMEOFDAY:
case SYSCALL_CLOCK_GETTIME:
case SYSCALL_UTIMES:
case SYSCALL_SYNC:
break;
case SYSCALL_SOCKET:
{