On 09/17/2010 01:50 AM, Mathias Krause wrote:
Am 16.09.2010 19:20 schrieb Anthony Liguori:
Instead of using FILE, I'd suggest using a BlockDriver to read and write
the data.
I'll fix that as soon as I figured how to use this interface.
I think it would be very nice to add write support too so that writes to
CMOS were persisted across boots.
Indeed. Also I would like to have a command line interface like '-cmos
cmos.bin' instead of the ugly '-global mc146818rtc.file=cmos.bin'. But
I'm not aware how to create such an alias. Any pointers?
Unfortunately, it's a little complicated although it should get better
in the future. The right way to do this today would be:
-drive file=cmos.bin,if=none,id=nvram -global mc146818rtc.drive=nvram
The use of -drive is historic. We'll have a better option in the future
that will look something like:
-blockdev file=cmos.bin,id=nvram -global mc146818rtc.drive=nvram
But in either case, I'd suggest adding an -nvram option that was:
-nvram <filename>
Which would do:
drive_add(optarg, "if=none,id=nvram");
And then in the RTC code, default drive to nvram.
It gets a little tough to handle the case of in memory CMOS.
Regards,
Anthony Liguori
+static long get_file_size(FILE *f)
+{
+ long where, size;
+
+ /* XXX: on Unix systems, using fstat() probably makes more sense */
+
+ where = ftell(f);
+ fseek(f, 0, SEEK_END);
+ size = ftell(f);
+ fseek(f, where, SEEK_SET);
+
+ return size;
+}
BlockDrivers have a getlength() functions.
Would reduce the size of the patch which is always a good thing (tm).
Mathias