Add romfile_size() wrapper for accessing cbfs/qemu_cfg files.
authorKevin O'Connor <kevin@koconnor.net>
Sun, 4 Jul 2010 12:32:38 +0000 (08:32 -0400)
committerKevin O'Connor <kevin@koconnor.net>
Sun, 4 Jul 2010 12:32:38 +0000 (08:32 -0400)
src/paravirt.c
src/paravirt.h

index 00ff58ca4b8362bd5745f43d0ccbde2489d0327a..da72c71d068bde5e0afad43cc23c8972f35980df 100644 (file)
@@ -339,14 +339,21 @@ u32 qemu_cfg_find_file(const char *name)
     return __cfg_next_prefix_file(name, strlen(name) + 1, 0);
 }
 
+int qemu_cfg_size_file(u32 select)
+{
+    if (select != ntohs(LastFile.select))
+        return -1;
+    return ntohl(LastFile.size);
+}
+
 int qemu_cfg_read_file(u32 select, void *dst, u32 maxlen)
 {
     if (!qemu_cfg_present)
         return -1;
     if (!select || select != ntohs(LastFile.select))
         return -1;
-    int len = ntohl(LastFile.size);
-    if (len > maxlen)
+    int len = qemu_cfg_size_file(select);
+    if (len < 0 || len > maxlen)
         return -1;
     qemu_cfg_read_entry(dst, select, len);
     return len;
index 83fe8ecfe4fcc0f82f4e19b92a240b506c4255d8..7d4bc026acb72172a62681d4681a18617bd5ad02 100644 (file)
@@ -70,6 +70,7 @@ struct e820_reservation {
 
 u32 qemu_cfg_next_prefix_file(const char *prefix, u32 prevselect);
 u32 qemu_cfg_find_file(const char *name);
+int qemu_cfg_size_file(u32 select);
 int qemu_cfg_read_file(u32 select, void *dst, u32 maxlen);
 
 // Wrappers that select cbfs or qemu_cfg file interface.
@@ -83,6 +84,11 @@ static inline u32 romfile_find(const char *name) {
         return (u32)cbfs_finddatafile(name);
     return qemu_cfg_find_file(name);
 }
+static inline u32 romfile_size(u32 fileid) {
+    if (CONFIG_COREBOOT)
+        return cbfs_datasize((void*)fileid);
+    return qemu_cfg_size_file(fileid);
+}
 static inline int romfile_copy(u32 fileid, void *dst, u32 maxlen) {
     if (CONFIG_COREBOOT)
         return cbfs_copyfile((void*)fileid, dst, maxlen);