From patchwork Tue Apr 3 20:37:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 894775 X-Patchwork-Delegate: agraf@suse.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gmx.de Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 40G19v0QcGz9s0y for ; Wed, 4 Apr 2018 06:37:38 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 584B3C21E8A; Tue, 3 Apr 2018 20:37:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id C77FAC21D56; Tue, 3 Apr 2018 20:37:20 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 64560C21CB1; Tue, 3 Apr 2018 20:37:19 +0000 (UTC) Received: from mout.gmx.net (mout.gmx.net [212.227.17.20]) by lists.denx.de (Postfix) with ESMTPS id 19E75C21D56 for ; Tue, 3 Apr 2018 20:37:19 +0000 (UTC) Received: from LPT2.fritz.box ([62.143.246.157]) by mail.gmx.com (mrgmx101 [212.227.17.174]) with ESMTPSA (Nemesis) id 0MQvDO-1exJa42jaI-00ULsD; Tue, 03 Apr 2018 22:37:18 +0200 From: Heinrich Schuchardt To: Alexander Graf Date: Tue, 3 Apr 2018 22:37:11 +0200 Message-Id: <20180403203712.3303-2-xypron.glpk@gmx.de> X-Mailer: git-send-email 2.16.3 In-Reply-To: <20180403203712.3303-1-xypron.glpk@gmx.de> References: <20180403203712.3303-1-xypron.glpk@gmx.de> X-Provags-ID: V03:K1:FTLMZAvVWOxvrtr6Gfb/HeFPFmSkc6IAg+x1JbmDeZd8cr7Wg++ VnZFurDGUrGprgqNPuh4fbfkWsL1EMiGFh5xKqX3u2+3C69KOPAy17SFKYqOJRynksKwhLz Hhb0ge/sg7PaIIyyec24H1Zm0U5Ti4hFXuhUP0CFpxFd67Ijq+vJHnWZa3WhlAlCMgLij95 MW8dZIjueygUNMrnG+pFA== X-UI-Out-Filterresults: notjunk:1; V01:K0:VxLcZzProh4=:+wD9iLEx6qLSY2hXup0fO/ +dbrnZtNcdwF1JDMUfu+WipVaFI0QFW6vWON6OyJMTyfy4jvHLjeJ5PHwCMTgcyanNIpuY+dE q5ic0ERQEpu6uya/MXMCHtxywxZhNNKScDXSp7ToPWuHW5U4+wWveb3RW979AIliQusCLBGrl ezsaK+34buE+k/fBGmyV42PKDV9bzWC4UnOcYCwm10yOI4ZlSJLtaf+bdiRBZ1MKDMQqWNfDX vXSe2DKY9T7pSJC+9bOn5gFJ6RXG99/6zOxQFN2lXc24+8qQeWNcPBHtXOH08uCVX9JZwQJfl u3ogIt+bygPXZgPfMWrgQutQevGzU1/3FuM0HHnhPjVRPrSbxkXWBQuha/t/cwIesu4J/W56y /zbG4nfuCk+w2G8whvU72lJ1EdE8mnJc4lZVL9V3SFttHRP3IRi1JGLEXuD63dttANJkZ579J g0b1wV4sdbxrOqm5O+JR0dp8i7llQwEZH8DOBbQ7eCfvT3Zyu1ZpaI1inoXOHqOrtNLQ7mbXy P0eeIKBMfA/rMHMmRjo3kZgqIsrcLChH0hXQXGlzOoZmNOd2wSYCThucjt0N9swgwgalbbIbu XheKPB0N+/OjH3XzagCqFU3VQ/TDRKW0tNKVpdV7BLn1VFCn4w1BOt1cYaixFlYY47DM+UOzw aHx3VbkWXramv+eB6lyPzoQ6CEghbi8mHo6ivHX85vnfqQwMgj1K5f3NG0kfNwIcDUQkBRqCG T/16KDT3LRrwbYnF7d3wJYsi1gqs3bhSdi9TkcWLGpEuCqqompOAGEfnQiIZ/niZuDt7DvRB2 7t3ePKDKFZJ+hsflGpn4L8sISzZTA== Cc: u-boot@lists.denx.de, Heinrich Schuchardt Subject: [U-Boot] [PATCH 1/2] efi_loader: use correct types in EFI_FILE_PROTOCOL X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" In the EFI_FILE_PROTOCOL buffer sizes and positions are passed as UINTN and not as u64. Signed-off-by: Heinrich Schuchardt --- include/efi_api.h | 14 +++++---- lib/efi_loader/efi_boottime.c | 5 +-- lib/efi_loader/efi_file.c | 47 +++++++++++++++++++++------- lib/efi_selftest/efi_selftest_block_device.c | 2 +- 4 files changed, 47 insertions(+), 21 deletions(-) diff --git a/include/efi_api.h b/include/efi_api.h index c8a41a499d..43c8c891e7 100644 --- a/include/efi_api.h +++ b/include/efi_api.h @@ -837,17 +837,19 @@ struct efi_file_handle { efi_status_t (EFIAPI *close)(struct efi_file_handle *file); efi_status_t (EFIAPI *delete)(struct efi_file_handle *file); efi_status_t (EFIAPI *read)(struct efi_file_handle *file, - u64 *buffer_size, void *buffer); + efi_uintn_t *buffer_size, void *buffer); efi_status_t (EFIAPI *write)(struct efi_file_handle *file, - u64 *buffer_size, void *buffer); + efi_uintn_t *buffer_size, void *buffer); efi_status_t (EFIAPI *getpos)(struct efi_file_handle *file, - u64 *pos); + efi_uintn_t *pos); efi_status_t (EFIAPI *setpos)(struct efi_file_handle *file, - u64 pos); + efi_uintn_t pos); efi_status_t (EFIAPI *getinfo)(struct efi_file_handle *file, - efi_guid_t *info_type, u64 *buffer_size, void *buffer); + efi_guid_t *info_type, efi_uintn_t *buffer_size, + void *buffer); efi_status_t (EFIAPI *setinfo)(struct efi_file_handle *file, - efi_guid_t *info_type, u64 buffer_size, void *buffer); + efi_guid_t *info_type, efi_uintn_t buffer_size, + void *buffer); efi_status_t (EFIAPI *flush)(struct efi_file_handle *file); }; diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c index d15a131e74..7a9449f59c 100644 --- a/lib/efi_loader/efi_boottime.c +++ b/lib/efi_loader/efi_boottime.c @@ -1513,7 +1513,7 @@ efi_status_t efi_load_image_from_path(struct efi_device_path *file_path, struct efi_file_info *info = NULL; struct efi_file_handle *f; static efi_status_t ret; - uint64_t bs; + efi_uintn_t bs; f = efi_file_from_path(file_path); if (!f) @@ -1534,7 +1534,8 @@ efi_status_t efi_load_image_from_path(struct efi_device_path *file_path, if (ret) goto error; - EFI_CALL(ret = f->read(f, &info->file_size, *buffer)); + bs = info->file_size; + EFI_CALL(ret = f->read(f, &bs, *buffer)); error: free(info); diff --git a/lib/efi_loader/efi_file.c b/lib/efi_loader/efi_file.c index 52a4e7438e..1e2751f7cf 100644 --- a/lib/efi_loader/efi_file.c +++ b/lib/efi_loader/efi_file.c @@ -314,29 +314,41 @@ static efi_status_t dir_read(struct file_handle *fh, u64 *buffer_size, } static efi_status_t EFIAPI efi_file_read(struct efi_file_handle *file, - u64 *buffer_size, void *buffer) + efi_uintn_t *buffer_size, void *buffer) { struct file_handle *fh = to_fh(file); efi_status_t ret = EFI_SUCCESS; + u64 bs; EFI_ENTRY("%p, %p, %p", file, buffer_size, buffer); + if (!buffer_size || !buffer) { + ret = EFI_INVALID_PARAMETER; + goto error; + } + if (set_blk_dev(fh)) { ret = EFI_DEVICE_ERROR; goto error; } + bs = *buffer_size; if (fh->isdir) - ret = dir_read(fh, buffer_size, buffer); + ret = dir_read(fh, &bs, buffer); else - ret = file_read(fh, buffer_size, buffer); + ret = file_read(fh, &bs, buffer); + if (bs <= SIZE_MAX) + *buffer_size = bs; + else + *buffer_size = SIZE_MAX; error: return EFI_EXIT(ret); } static efi_status_t EFIAPI efi_file_write(struct efi_file_handle *file, - u64 *buffer_size, void *buffer) + efi_uintn_t *buffer_size, + void *buffer) { struct file_handle *fh = to_fh(file); efi_status_t ret = EFI_SUCCESS; @@ -363,21 +375,27 @@ error: } static efi_status_t EFIAPI efi_file_getpos(struct efi_file_handle *file, - u64 *pos) + efi_uintn_t *pos) { struct file_handle *fh = to_fh(file); + EFI_ENTRY("%p, %p", file, pos); - *pos = fh->offset; - return EFI_EXIT(EFI_SUCCESS); + + if (fh->offset <= SIZE_MAX) { + *pos = fh->offset; + return EFI_EXIT(EFI_SUCCESS); + } else { + return EFI_EXIT(EFI_DEVICE_ERROR); + } } static efi_status_t EFIAPI efi_file_setpos(struct efi_file_handle *file, - u64 pos) + efi_uintn_t pos) { struct file_handle *fh = to_fh(file); efi_status_t ret = EFI_SUCCESS; - EFI_ENTRY("%p, %llu", file, pos); + EFI_ENTRY("%p, %zu", file, pos); if (fh->isdir) { if (pos != 0) { @@ -411,7 +429,9 @@ error: } static efi_status_t EFIAPI efi_file_getinfo(struct efi_file_handle *file, - efi_guid_t *info_type, u64 *buffer_size, void *buffer) + efi_guid_t *info_type, + efi_uintn_t *buffer_size, + void *buffer) { struct file_handle *fh = to_fh(file); efi_status_t ret = EFI_SUCCESS; @@ -461,9 +481,12 @@ error: } static efi_status_t EFIAPI efi_file_setinfo(struct efi_file_handle *file, - efi_guid_t *info_type, u64 buffer_size, void *buffer) + efi_guid_t *info_type, + efi_uintn_t buffer_size, + void *buffer) { - EFI_ENTRY("%p, %p, %llu, %p", file, info_type, buffer_size, buffer); + EFI_ENTRY("%p, %p, %zu, %p", file, info_type, buffer_size, buffer); + return EFI_EXIT(EFI_UNSUPPORTED); } diff --git a/lib/efi_selftest/efi_selftest_block_device.c b/lib/efi_selftest/efi_selftest_block_device.c index 9e4b93d9a6..b07b22465f 100644 --- a/lib/efi_selftest/efi_selftest_block_device.c +++ b/lib/efi_selftest/efi_selftest_block_device.c @@ -302,7 +302,7 @@ static int execute(void) struct efi_device_path *dp_partition; struct efi_simple_file_system_protocol *file_system; struct efi_file_handle *root, *file; - u64 buf_size; + efi_uintn_t buf_size; char buf[16] __aligned(ARCH_DMA_MINALIGN); ret = boottime->connect_controller(disk_handle, NULL, NULL, 1); From patchwork Tue Apr 3 20:37:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 894777 X-Patchwork-Delegate: agraf@suse.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gmx.de Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 40G1Cp5vs7z9s0y for ; Wed, 4 Apr 2018 06:39:18 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 73F8CC21EB1; Tue, 3 Apr 2018 20:38:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 8F515C21E36; Tue, 3 Apr 2018 20:37:22 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 18435C21CB1; Tue, 3 Apr 2018 20:37:20 +0000 (UTC) Received: from mout.gmx.net (mout.gmx.net [212.227.17.22]) by lists.denx.de (Postfix) with ESMTPS id AA656C21CB6 for ; Tue, 3 Apr 2018 20:37:19 +0000 (UTC) Received: from LPT2.fritz.box ([62.143.246.157]) by mail.gmx.com (mrgmx101 [212.227.17.174]) with ESMTPSA (Nemesis) id 0MLS74-1f2uiK3vPe-000Z1V; Tue, 03 Apr 2018 22:37:19 +0200 From: Heinrich Schuchardt To: Alexander Graf Date: Tue, 3 Apr 2018 22:37:12 +0200 Message-Id: <20180403203712.3303-3-xypron.glpk@gmx.de> X-Mailer: git-send-email 2.16.3 In-Reply-To: <20180403203712.3303-1-xypron.glpk@gmx.de> References: <20180403203712.3303-1-xypron.glpk@gmx.de> X-Provags-ID: V03:K1:fdFmAVt7gzHmI3OgDdN7BDyziALskOQYdmlIAlLPGOfvT0GiFhK vimHdzShRBtQRIFm+XKO5HXgLqi6mJn5Vgg0WSDGWi7kzc1Nclh8b0lDMlwIbpj3L1Z2Ekv xkj94lOVnSUhdD6T448HlLxN3QQQ7wPvtV4HfN1iWQUeXtm55hsxXJT1ul4PSmema1Yfuht f41SEyLliN+XHY23jqbOQ== X-UI-Out-Filterresults: notjunk:1; V01:K0:dFcXNqTiom4=:hG0yrW2ND+LNmMG9rCY2An DaBCR+1CwNFzJ87utStMoV765ggnB/5SnmbIvsKzRD3URFD6HeFziugiSiqDkBr5ASxr5wTfR BXzFTHXCW7dv5PUpsE4lVa89yYaZk6e5Cxx/DpDqD1nQUECizaygHbuOfSDGpxogNlN+MqW5/ j0rGpxgf/oho7WqNxpQ9XSaxj1GKAK44dReRhZdUuYlbL1zrW76cISmc8wA1TZKpnXpxn2bvx 7JD3AQOhILKIrgHmZdZbQzeXuzxpTkbFqwLnicBr1W3/IFNjp67KPJE88y4LoRWW9xGrw0B2t zK6Tq5b30DhjIL5XvEdgn1eP+kVZDsRo5iQah+eYcB5GlDU4Nztf5/OdRXg3Nh1/I5GoDJOpo iPREylXOvogXzknuD5P0LoZZ1Ec3rrShSn/C0tkPTd9sCFTFny3trwlmCdZXIQ4I/rU35vnnJ aEAFgfMRgRYtRjRokj82Dlg7k7BjWNZ5bNKwi4CXCWHitR5u2IU3sHrq8Gs7L96jpQDKXQvuh BHSXBpV2/vuU4wfofS8UO1+KWqxboN3WAoh6vIj6bymUK25eiPLnXerLh0ImG3EXleGhgOWOX mLU2Qwdl919DZrthTmSVSB8UR4s1vQV+ro6tk/m8MI/VIFYu60mp9wQ3O7LYbW9lkKwNTJSOI FhmntXoZlQRHakkcRMrMHJL7GPVTaLBtNVqq4ikjlGogqZUELrpaITflDIF5ys9w70XkgLaU4 5ooWSKdfm+TPI6l8a5yicYLsnYaDOfo0aqVS2Zadn+DGUczAJ8pFz8WWLeYcNhL+ufwoPUMPf aJQE+AEBPELoFJsVtsSrnRdlpi6Hw== Cc: u-boot@lists.denx.de, Heinrich Schuchardt Subject: [U-Boot] [PATCH 2/2] efi_loader: implement EFI_FILE_SYSTEM_INFO X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Implement the information type EFI_FILE_SYSTEM_INFO in the service GetInfo() of the EFI_FILE_PROTOCOL. Signed-off-by: Heinrich Schuchardt --- include/efi_api.h | 13 +++++++++++++ include/efi_loader.h | 2 ++ lib/efi_loader/efi_file.c | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+) diff --git a/include/efi_api.h b/include/efi_api.h index 43c8c891e7..16da736113 100644 --- a/include/efi_api.h +++ b/include/efi_api.h @@ -868,6 +868,10 @@ struct efi_simple_file_system_protocol { EFI_GUID(0x9576e92, 0x6d3f, 0x11d2, \ 0x8e, 0x39, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b) +#define EFI_FILE_SYSTEM_INFO_GUID \ + EFI_GUID(0x09576e93, 0x6d3f, 0x11d2, \ + 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b) + #define EFI_FILE_MODE_READ 0x0000000000000001 #define EFI_FILE_MODE_WRITE 0x0000000000000002 #define EFI_FILE_MODE_CREATE 0x8000000000000000 @@ -891,6 +895,15 @@ struct efi_file_info { s16 file_name[0]; }; +struct efi_file_system_info { + u64 size; + u8 read_only; + u64 volume_size; + u64 free_space; + u32 block_size; + u16 volume_label[0]; +}; + #define EFI_DRIVER_BINDING_PROTOCOL_GUID \ EFI_GUID(0x18a031ab, 0xb443, 0x4d1a,\ 0xa5, 0xc0, 0x0c, 0x09, 0x26, 0x1e, 0x9f, 0x71) diff --git a/include/efi_loader.h b/include/efi_loader.h index ee553c667f..ab20773947 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -112,6 +112,8 @@ extern const efi_guid_t efi_guid_loaded_image; extern const efi_guid_t efi_guid_device_path_to_text_protocol; extern const efi_guid_t efi_simple_file_system_protocol_guid; extern const efi_guid_t efi_file_info_guid; +/* GUID for file system information */ +extern const efi_guid_t efi_file_system_info_guid; extern const efi_guid_t efi_guid_device_path_utilities_protocol; extern unsigned int __efi_runtime_start, __efi_runtime_stop; diff --git a/lib/efi_loader/efi_file.c b/lib/efi_loader/efi_file.c index 1e2751f7cf..37a999d0b2 100644 --- a/lib/efi_loader/efi_file.c +++ b/lib/efi_loader/efi_file.c @@ -12,6 +12,9 @@ #include #include +/* GUID for file system information */ +const efi_guid_t efi_file_system_info_guid = EFI_FILE_SYSTEM_INFO_GUID; + struct file_system { struct efi_simple_file_system_protocol base; struct efi_device_path *dp; @@ -472,6 +475,37 @@ static efi_status_t EFIAPI efi_file_getinfo(struct efi_file_handle *file, info->attribute |= EFI_FILE_DIRECTORY; ascii2unicode((u16 *)info->file_name, filename); + } else if (!guidcmp(info_type, &efi_file_system_info_guid)) { + struct efi_file_system_info *info = buffer; + disk_partition_t part; + efi_uintn_t required_size; + int r; + + if (fh->fs->part >= 1) + r = part_get_info(fh->fs->desc, fh->fs->part, &part); + else + r = part_get_info_whole_disk(fh->fs->desc, &part); + if (r < 0) { + ret = EFI_DEVICE_ERROR; + goto error; + } + required_size = sizeof(info) + 2 * + (strlen((const char *)part.name) + 1); + if (*buffer_size < required_size) { + *buffer_size = required_size; + ret = EFI_BUFFER_TOO_SMALL; + goto error; + } + + memset(info, 0, required_size); + + info->size = required_size; + info->read_only = true; + info->volume_size = part.size * part.blksz; + info->free_space = 0; + info->block_size = part.blksz; + ascii2unicode((u16 *)info->volume_label, + (const char *)part.name); } else { ret = EFI_UNSUPPORTED; }