2014-08-20 14:49:41 +00:00
|
|
|
/*
|
|
|
|
* \brief Rtc file system
|
|
|
|
* \author Josef Soentgen
|
|
|
|
* \date 2014-08-20
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2014 Genode Labs GmbH
|
|
|
|
*
|
|
|
|
* This file is part of the Genode OS framework, which is distributed
|
|
|
|
* under the terms of the GNU General Public License version 2.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _INCLUDE__VFS__RTC_FILE_SYSTEM_H_
|
|
|
|
#define _INCLUDE__VFS__RTC_FILE_SYSTEM_H_
|
|
|
|
|
|
|
|
/* Genode includes */
|
|
|
|
#include <rtc_session/connection.h>
|
|
|
|
#include <vfs/file_system.h>
|
|
|
|
|
|
|
|
/* libc includes */
|
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
namespace Vfs { class Rtc_file_system; }
|
|
|
|
|
|
|
|
|
|
|
|
class Vfs::Rtc_file_system : public Single_file_system
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
|
|
|
Rtc::Connection _rtc;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
Rtc_file_system(Xml_node config)
|
|
|
|
:
|
|
|
|
Single_file_system(NODE_TYPE_CHAR_DEVICE, name(), config)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
static char const *name() { return "rtc"; }
|
|
|
|
|
|
|
|
|
|
|
|
/********************************
|
|
|
|
** File I/O service interface **
|
|
|
|
********************************/
|
|
|
|
|
2014-09-09 12:32:31 +00:00
|
|
|
Write_result write(Vfs_handle *, char const *, file_size,
|
|
|
|
file_size &) override
|
2014-08-20 14:49:41 +00:00
|
|
|
{
|
|
|
|
return WRITE_ERR_IO;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Read the current time from the RTC
|
|
|
|
*
|
|
|
|
* On each read the current time is queried and afterwards formated
|
|
|
|
* as '%Y-%m-%d %H:%M\n'.
|
|
|
|
*/
|
2014-09-09 12:32:31 +00:00
|
|
|
Read_result read(Vfs_handle *vfs_handle, char *dst, file_size count,
|
|
|
|
file_size &out_count) override
|
2014-08-20 14:49:41 +00:00
|
|
|
{
|
2015-01-21 10:52:02 +00:00
|
|
|
time_t t = _rtc.current_time() / 1000000ULL;
|
2014-08-20 14:49:41 +00:00
|
|
|
|
|
|
|
struct tm *tm = localtime(&t);
|
|
|
|
|
|
|
|
char buf[16 + 1 + 1];
|
|
|
|
Genode::snprintf(buf, sizeof(buf), "%04d-%02d-%02d %02d:%02d\n",
|
|
|
|
1900 + tm->tm_year, /* years since 1900 */
|
|
|
|
1 + tm->tm_mon, /* months since January [0-11] */
|
|
|
|
tm->tm_mday, tm->tm_hour, tm->tm_min);
|
|
|
|
|
2014-09-09 12:32:31 +00:00
|
|
|
file_size len = count > sizeof(buf) ? sizeof(buf) : count;
|
2014-08-20 14:49:41 +00:00
|
|
|
Genode::memcpy(dst, buf, len);
|
|
|
|
|
|
|
|
out_count = len;
|
|
|
|
|
|
|
|
return READ_OK;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* _INCLUDE__VFS__RTC_FILE_SYSTEM_H_ */
|