image: Added functions image_print_info, image_list_unlink, image_hwrev_is_valid
This commit is contained in:
1 parent
238f92ab25
commit
4de49acb49
2 files changed
+68
-2
No files matched your search
+64
-2
@@ -212,6 +212,7 @@ struct image * image_alloc_from_file(const char * file, const char * type, const
|
||||
image->size = lseek(image->fd, 0, SEEK_END);
|
||||
image->offset = 0;
|
||||
image->cur = 0;
|
||||
image->orig_filename = strdup(file);
|
||||
|
||||
image_append(image, type, device, hwrevs, version, layout);
|
||||
|
||||
@@ -262,6 +263,7 @@ void image_free(struct image * image) {
|
||||
free(image->hwrevs);
|
||||
free(image->version);
|
||||
free(image->layout);
|
||||
free(image->orig_filename);
|
||||
|
||||
free(image);
|
||||
|
||||
@@ -357,6 +359,17 @@ void image_list_add(struct image_list ** list, struct image * image) {
|
||||
|
||||
void image_list_del(struct image_list * list) {
|
||||
|
||||
if ( ! list )
|
||||
return;
|
||||
|
||||
image_list_unlink(list);
|
||||
image_free(list->image);
|
||||
free(list);
|
||||
|
||||
}
|
||||
|
||||
void image_list_unlink(struct image_list * list) {
|
||||
|
||||
if ( ! list )
|
||||
return;
|
||||
|
||||
@@ -366,8 +379,8 @@ void image_list_del(struct image_list * list) {
|
||||
if ( list->next )
|
||||
list->next->prev = list->prev;
|
||||
|
||||
image_free(list->image);
|
||||
free(list);
|
||||
list->prev = NULL;
|
||||
list->next = NULL;
|
||||
|
||||
}
|
||||
|
||||
@@ -474,3 +487,52 @@ const char * image_type_to_string(enum image_type type) {
|
||||
return image_types[type];
|
||||
|
||||
}
|
||||
|
||||
int image_hwrev_is_valid(struct image * image, const char * hwrev) {
|
||||
|
||||
const char * ptr = image->hwrevs;
|
||||
const char * oldptr = ptr;
|
||||
|
||||
if ( ! hwrev || ! ptr )
|
||||
return 1;
|
||||
|
||||
while ( (ptr = strchr(ptr, ',')) ) {
|
||||
if ( strncmp(hwrev, oldptr, ptr-oldptr) == 0 )
|
||||
return 1;
|
||||
++ptr;
|
||||
oldptr = ptr;
|
||||
}
|
||||
|
||||
if ( strcmp(hwrev, oldptr) == 0 )
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
void image_print_info(struct image * image) {
|
||||
|
||||
const char * str;
|
||||
|
||||
if ( image->orig_filename )
|
||||
printf("File: %s\n", image->orig_filename);
|
||||
|
||||
str = image_type_to_string(image->type);
|
||||
printf(" Image type: %s\n", str ? str : "unknown");
|
||||
printf(" Image size: %d bytes\n", image->size);
|
||||
|
||||
if ( image->version )
|
||||
printf(" Image version: %s\n", image->version);
|
||||
|
||||
if ( image->device == DEVICE_UNKNOWN )
|
||||
str = "unknown device";
|
||||
else
|
||||
str = device_to_string(image->device);
|
||||
|
||||
if ( str )
|
||||
printf(" Valid for device: %s\n", str);
|
||||
|
||||
if ( image->hwrevs )
|
||||
printf(" Valid for HW revisions: %s\n", image->hwrevs);
|
||||
|
||||
}
|
||||
@@ -56,6 +56,7 @@ struct image {
|
||||
off_t offset;
|
||||
off_t cur;
|
||||
off_t acur;
|
||||
char * orig_filename;
|
||||
};
|
||||
|
||||
struct image_list {
|
||||
@@ -69,13 +70,16 @@ struct image * image_alloc_from_shared_fd(int fd, size_t size, size_t offset, ui
|
||||
void image_free(struct image * image);
|
||||
void image_seek(struct image * image, off_t whence);
|
||||
size_t image_read(struct image * image, void * buf, size_t count);
|
||||
void image_print_info(struct image * image);
|
||||
void image_list_add(struct image_list ** list, struct image * image);
|
||||
void image_list_del(struct image_list * list);
|
||||
void image_list_unlink(struct image_list * list);
|
||||
|
||||
uint16_t image_hash_from_data(struct image * image);
|
||||
enum image_type image_type_from_data(struct image * image);
|
||||
char * image_name_alloc_from_values(struct image * image);
|
||||
enum image_type image_type_from_string(const char * type);
|
||||
const char * image_type_to_string(enum image_type type);
|
||||
int image_hwrev_is_valid(struct image * image, const char * hwrev);
|
||||
|
||||
#endif
|
||||
Reference in new issue
Block a user