Commit fbe4c7df0087c4f26ca7acf21cf0b7c0bc2fbfd2
1 parent
cb0c2a7430
Exists in
smarc_8mq_lf_v2020.04
and in
10 other branches
efi_loader: enable file SetInfo()
EFI shell command edit uses the SetInfo() methods to unset the read only attribute of the file to be edited. So let efi_file_setinfo() return success in this case. Return an error if the function is called for to rename or resize a file as we do not support this yet. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Showing 1 changed file with 65 additions and 2 deletions Side-by-side Diff
lib/efi_loader/efi_file.c
... | ... | @@ -637,9 +637,72 @@ |
637 | 637 | efi_uintn_t buffer_size, |
638 | 638 | void *buffer) |
639 | 639 | { |
640 | - EFI_ENTRY("%p, %p, %zu, %p", file, info_type, buffer_size, buffer); | |
640 | + struct file_handle *fh = to_fh(file); | |
641 | + efi_status_t ret = EFI_UNSUPPORTED; | |
641 | 642 | |
642 | - return EFI_EXIT(EFI_UNSUPPORTED); | |
643 | + EFI_ENTRY("%p, %pUl, %zu, %p", file, info_type, buffer_size, buffer); | |
644 | + | |
645 | + if (!guidcmp(info_type, &efi_file_info_guid)) { | |
646 | + struct efi_file_info *info = (struct efi_file_info *)buffer; | |
647 | + char *filename = basename(fh); | |
648 | + char *new_file_name, *pos; | |
649 | + loff_t file_size; | |
650 | + | |
651 | + if (buffer_size < sizeof(struct efi_file_info)) { | |
652 | + ret = EFI_BAD_BUFFER_SIZE; | |
653 | + goto out; | |
654 | + } | |
655 | + /* We cannot change the directory attribute */ | |
656 | + if (!fh->isdir != !(info->attribute & EFI_FILE_DIRECTORY)) { | |
657 | + ret = EFI_ACCESS_DENIED; | |
658 | + goto out; | |
659 | + } | |
660 | + /* Check for renaming */ | |
661 | + new_file_name = malloc(utf16_utf8_strlen(info->file_name)); | |
662 | + if (!new_file_name) { | |
663 | + ret = EFI_OUT_OF_RESOURCES; | |
664 | + goto out; | |
665 | + } | |
666 | + pos = new_file_name; | |
667 | + utf16_utf8_strcpy(&pos, info->file_name); | |
668 | + if (strcmp(new_file_name, filename)) { | |
669 | + /* TODO: we do not support renaming */ | |
670 | + EFI_PRINT("Renaming not supported\n"); | |
671 | + free(new_file_name); | |
672 | + ret = EFI_ACCESS_DENIED; | |
673 | + goto out; | |
674 | + } | |
675 | + free(new_file_name); | |
676 | + /* Check for truncation */ | |
677 | + if (set_blk_dev(fh)) { | |
678 | + ret = EFI_DEVICE_ERROR; | |
679 | + goto out; | |
680 | + } | |
681 | + if (fs_size(fh->path, &file_size)) { | |
682 | + ret = EFI_DEVICE_ERROR; | |
683 | + goto out; | |
684 | + } | |
685 | + if (file_size != info->file_size) { | |
686 | + /* TODO: we do not support truncation */ | |
687 | + EFI_PRINT("Truncation not supported\n"); | |
688 | + ret = EFI_ACCESS_DENIED; | |
689 | + goto out; | |
690 | + } | |
691 | + /* | |
692 | + * We do not care for the other attributes | |
693 | + * TODO: Support read only | |
694 | + */ | |
695 | + ret = EFI_SUCCESS; | |
696 | + } else if (!guidcmp(info_type, &efi_file_system_info_guid)) { | |
697 | + if (buffer_size < sizeof(struct efi_file_system_info)) { | |
698 | + ret = EFI_BAD_BUFFER_SIZE; | |
699 | + goto out; | |
700 | + } | |
701 | + } else { | |
702 | + ret = EFI_UNSUPPORTED; | |
703 | + } | |
704 | +out: | |
705 | + return EFI_EXIT(ret); | |
643 | 706 | } |
644 | 707 | |
645 | 708 | static efi_status_t EFIAPI efi_file_flush(struct efi_file_handle *file) |