This is an automated email from the ASF dual-hosted git repository. sjanc pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
commit 5a3dce7da1170028d1d31bab3e1807e9ab4c9d9d Author: Szymon Janc <[email protected]> AuthorDate: Tue Oct 6 19:05:59 2026 +0200 mgmt/mcumgr/fs_mgmt: Remove OS abstraction layer mcumgr is now part of Mynewt core and there is no need for OS abstraction layer. Mynewt implementation is merged into fs_mgmt.c and fs_mgmt_impl_* functions are made static. fs_mgmt_config.h is removed and syscfg values are used directly. Weak stubs and Mynewt port package are removed. Missing dependencies on mgmt and cborattr are added. Local variables in download handler are initialized as compiler can now see through inlined helpers and reports false positive maybe-uninitialized warning. No functional changes. Assisted-by: Claude:claude-opus-5-5 --- fs/fs/pkg.yml | 2 +- .../cmd/fs_mgmt/include/fs_mgmt/fs_mgmt_config.h | 84 ---------------- .../cmd/fs_mgmt/include/fs_mgmt/fs_mgmt_impl.h | 77 --------------- mgmt/mcumgr/cmd/fs_mgmt/pkg.yml | 3 + mgmt/mcumgr/cmd/fs_mgmt/port/mynewt/pkg.yml | 29 ------ .../cmd/fs_mgmt/port/mynewt/src/mynewt_fs_mgmt.c | 109 --------------------- mgmt/mcumgr/cmd/fs_mgmt/src/fs_mgmt.c | 108 +++++++++++++++++--- mgmt/mcumgr/cmd/fs_mgmt/src/stubs.c | 46 --------- 8 files changed, 101 insertions(+), 357 deletions(-) diff --git a/fs/fs/pkg.yml b/fs/fs/pkg.yml index 4c593502e..bc1f77641 100644 --- a/fs/fs/pkg.yml +++ b/fs/fs/pkg.yml @@ -30,6 +30,6 @@ pkg.deps.FS_CLI: - "@apache-mynewt-core/sys/shell" pkg.deps.FS_MGMT: - - "@apache-mynewt-core/mgmt/mcumgr/cmd/fs_mgmt/port/mynewt" + - "@apache-mynewt-core/mgmt/mcumgr/cmd/fs_mgmt" pkg.whole_archive: true diff --git a/mgmt/mcumgr/cmd/fs_mgmt/include/fs_mgmt/fs_mgmt_config.h b/mgmt/mcumgr/cmd/fs_mgmt/include/fs_mgmt/fs_mgmt_config.h deleted file mode 100644 index 2fd7ae04b..000000000 --- a/mgmt/mcumgr/cmd/fs_mgmt/include/fs_mgmt/fs_mgmt_config.h +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -#ifndef H_FS_MGMT_CONFIG_ -#define H_FS_MGMT_CONFIG_ - -#if defined MYNEWT - -#include "syscfg/syscfg.h" - -#define FS_MGMT_DL_CHUNK_SIZE MYNEWT_VAL(FS_MGMT_DL_CHUNK_SIZE) -#define FS_MGMT_PATH_SIZE MYNEWT_VAL(FS_MGMT_PATH_SIZE) -#define FS_MGMT_UL_CHUNK_SIZE MYNEWT_VAL(FS_MGMT_UL_CHUNK_SIZE) - -#elif defined __ZEPHYR__ - - -#define MCUMGR_BUF_SIZE CONFIG_MCUMGR_BUF_SIZE -/* File chunk needs to fit into MCUGMR_BUF_SZIE with all required headers - * and other data fields; following information takes space off the - * MCUMGR_BUF_SIZE, N is CONFIG_FS_MGMT_MAX_OFFSET_LEN - * MGMT_HDR_SIZE - header that is placed in front of buffer and not - * visible for cbod encoder (see smp_handle_single_req); - * 9 + 1 -- bytes taken by definition of CBOR undefined length map and map - * terminator (break) character; - * 1 + strlen("off") + [1, N] -- CBOR encoded pair of "off" marker and - * offset of the chunk within the file; - * 1 + strlen("data") + [1, N] -- CBOR encoded "data" marker; this marker - * will be followed by file chunk of size FS_MGMT_DL_CHUNK_SIZE - * 1 + strlen("rc") + 1 -- status code of operation; - * 1 + strlen("len") + [1, N] -- CBOR encoded "len" marker and complete - * length of a file; this is only sent once when "off" is 0; - * - * FS_MGMT_DL_CHUNK_SIZE is calculated with most pessimistic estimations, - * that is with headers fields taking most space, i.e. N bytes. - */ -//#define FS_MGMT_DL_CHUNK_SIZE CONFIG_FS_MGMT_DL_CHUNK_SIZE -#define CBOR_AND_OTHER_HDR \ - ((9 + 1) + \ - (1 + 3 + CONFIG_FS_MGMT_MAX_OFFSET_LEN) + \ - (1 + 4 + CONFIG_FS_MGMT_MAX_OFFSET_LEN) + \ - (1 + 2 + 1) + \ - (1 + 3 + CONFIG_FS_MGMT_MAX_OFFSET_LEN)) - -#if defined(CONFIG_FS_MGMT_DL_CHUNK_SIZE_LIMIT) -#if (CONFIG_FS_MGMT_DL_CHUNK_SIZE + CBOR_AND_OTHER_HDR) > MCUMGR_BUF_SIZE -#warning FS_MGMT_DL_CHUNK_SIZE too big, rounding it down. -#else -#define FS_MGMT_DL_CHUNK_SIZE (CONFIG_FS_MGMT_DL_CHUNK_SIZE) -#endif -#endif - -#if !defined(FS_MGMT_DL_CHUNK_SIZE) -#define FS_MGMT_DL_CHUNK_SIZE (MCUMGR_BUF_SIZE - CBOR_AND_OTHER_HDR) -#endif - -#define FS_MGMT_PATH_SIZE CONFIG_FS_MGMT_PATH_SIZE -#define FS_MGMT_UL_CHUNK_SIZE CONFIG_FS_MGMT_UL_CHUNK_SIZE - -#else - -/* No direct support for this OS. The application needs to define the above - * settings itself. - */ - -#endif - -#endif diff --git a/mgmt/mcumgr/cmd/fs_mgmt/include/fs_mgmt/fs_mgmt_impl.h b/mgmt/mcumgr/cmd/fs_mgmt/include/fs_mgmt/fs_mgmt_impl.h deleted file mode 100644 index 3cb30b842..000000000 --- a/mgmt/mcumgr/cmd/fs_mgmt/include/fs_mgmt/fs_mgmt_impl.h +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -/** - * @file - * @brief Declares implementation-specific functions required by file system - * management. The default stubs can be overridden with functions that - * are compatible with the host OS. - */ - -#ifndef H_FS_MGMT_IMPL_ -#define H_FS_MGMT_IMPL_ - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief Retrieves the length of the file at the specified path. - * - * @param path The path of the file to query. - * @param out_len On success, the file length gets written here. - * - * @return 0 on success, MGMT_ERR_[...] code on failure. - */ -int fs_mgmt_impl_filelen(const char *path, size_t *out_len); - -/** - * @brief Reads the specified chunk of file data. - * - * @param path The path of the file to read from. - * @param offset The byte offset to read from. - * @param len The number of bytes to read. - * @param out_data On success, the file data gets written here. - * @param out_len On success, the number of bytes actually read - * gets written here. - * - * @return 0 on success, MGMT_ERR_[...] code on failure. - */ -int fs_mgmt_impl_read(const char *path, size_t offset, size_t len, - void *out_data, size_t *out_len); - -/** - * @brief Writes the specified chunk of file data. A write to offset 0 must - * truncate the file; other offsets must append. - * - * @param path The path of the file to write to. - * @param offset The byte offset to write to. - * @param data The data to write to the file. - * @param len The number of bytes to write. - * - * @return 0 on success, MGMT_ERR_[...] code on failure. - */ -int fs_mgmt_impl_write(const char *path, size_t offset, const void *data, - size_t len); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/mgmt/mcumgr/cmd/fs_mgmt/pkg.yml b/mgmt/mcumgr/cmd/fs_mgmt/pkg.yml index 167dc64ad..04ea034c3 100644 --- a/mgmt/mcumgr/cmd/fs_mgmt/pkg.yml +++ b/mgmt/mcumgr/cmd/fs_mgmt/pkg.yml @@ -24,4 +24,7 @@ pkg.homepage: "http://mynewt.apache.org/" pkg.keywords: pkg.deps: + - '@apache-mynewt-core/kernel/os' - '@apache-mynewt-core/fs/fs' + - '@apache-mynewt-core/mgmt/mcumgr/mgmt' + - '@apache-mynewt-core/encoding/cborattr' diff --git a/mgmt/mcumgr/cmd/fs_mgmt/port/mynewt/pkg.yml b/mgmt/mcumgr/cmd/fs_mgmt/port/mynewt/pkg.yml deleted file mode 100644 index 1971a9b7d..000000000 --- a/mgmt/mcumgr/cmd/fs_mgmt/port/mynewt/pkg.yml +++ /dev/null @@ -1,29 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# - -pkg.name: mgmt/mcumgr/cmd/fs_mgmt/port/mynewt -pkg.description: 'File system command handlers for mcumgr.' -pkg.author: "Apache Mynewt <[email protected]>" -pkg.homepage: "http://mynewt.apache.org/" -pkg.keywords: - -pkg.deps: - - '@apache-mynewt-core/mgmt/mcumgr/cmd/fs_mgmt' - -pkg.whole_archive: true diff --git a/mgmt/mcumgr/cmd/fs_mgmt/port/mynewt/src/mynewt_fs_mgmt.c b/mgmt/mcumgr/cmd/fs_mgmt/port/mynewt/src/mynewt_fs_mgmt.c deleted file mode 100644 index f15a57f96..000000000 --- a/mgmt/mcumgr/cmd/fs_mgmt/port/mynewt/src/mynewt_fs_mgmt.c +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -#include "mgmt/mgmt.h" -#include "fs_mgmt/fs_mgmt_impl.h" -#include "fs/fs.h" - -int -fs_mgmt_impl_filelen(const char *path, size_t *out_len) -{ - struct fs_file *file; - uint32_t file_size; - int rc; - - rc = fs_open(path, FS_ACCESS_READ, &file); - if (rc != 0) { - return MGMT_ERR_EUNKNOWN; - } - - rc = fs_filelen(file, &file_size); - fs_close(file); - if (rc != 0) { - return MGMT_ERR_EUNKNOWN; - } - - *out_len = file_size; - - return 0; -} - -int -fs_mgmt_impl_read(const char *path, size_t offset, size_t len, - void *out_data, size_t *out_len) -{ - struct fs_file *file; - uint32_t bytes_read; - int rc; - - rc = fs_open(path, FS_ACCESS_READ, &file); - if (rc != 0) { - return MGMT_ERR_EUNKNOWN; - } - - rc = fs_seek(file, offset); - if (rc != 0) { - goto done; - } - - rc = fs_read(file, len, out_data, &bytes_read); - if (rc != 0) { - goto done; - } - - *out_len = bytes_read; - -done: - fs_close(file); - - if (rc != 0) { - return MGMT_ERR_EUNKNOWN; - } - - return 0; -} - -int -fs_mgmt_impl_write(const char *path, size_t offset, const void *data, - size_t len) -{ - struct fs_file *file; - uint8_t access; - int rc; - - access = FS_ACCESS_WRITE; - if (offset == 0) { - access |= FS_ACCESS_TRUNCATE; - } else { - access |= FS_ACCESS_APPEND; - } - - rc = fs_open(path, access, &file); - if (rc != 0) { - return MGMT_ERR_EUNKNOWN; - } - - rc = fs_write(file, data, len); - fs_close(file); - if (rc != 0) { - return MGMT_ERR_EUNKNOWN; - } - - return 0; -} diff --git a/mgmt/mcumgr/cmd/fs_mgmt/src/fs_mgmt.c b/mgmt/mcumgr/cmd/fs_mgmt/src/fs_mgmt.c index 996f9b330..fe1292d8e 100644 --- a/mgmt/mcumgr/cmd/fs_mgmt/src/fs_mgmt.c +++ b/mgmt/mcumgr/cmd/fs_mgmt/src/fs_mgmt.c @@ -19,11 +19,96 @@ #include <limits.h> #include <string.h> +#include "os/mynewt.h" +#include "fs/fs.h" #include "cborattr/cborattr.h" #include "mgmt/mgmt.h" #include "fs_mgmt/fs_mgmt.h" -#include "fs_mgmt/fs_mgmt_impl.h" -#include "fs_mgmt/fs_mgmt_config.h" + +static int +fs_mgmt_filelen(const char *path, size_t *out_len) +{ + struct fs_file *file; + uint32_t file_size; + int rc; + + rc = fs_open(path, FS_ACCESS_READ, &file); + if (rc != 0) { + return MGMT_ERR_EUNKNOWN; + } + + rc = fs_filelen(file, &file_size); + fs_close(file); + if (rc != 0) { + return MGMT_ERR_EUNKNOWN; + } + + *out_len = file_size; + + return 0; +} + +static int +fs_mgmt_read(const char *path, size_t offset, size_t len, void *out_data, size_t *out_len) +{ + struct fs_file *file; + uint32_t bytes_read; + int rc; + + rc = fs_open(path, FS_ACCESS_READ, &file); + if (rc != 0) { + return MGMT_ERR_EUNKNOWN; + } + + rc = fs_seek(file, offset); + if (rc != 0) { + goto done; + } + + rc = fs_read(file, len, out_data, &bytes_read); + if (rc != 0) { + goto done; + } + + *out_len = bytes_read; + +done: + fs_close(file); + + if (rc != 0) { + return MGMT_ERR_EUNKNOWN; + } + + return 0; +} + +static int +fs_mgmt_write(const char *path, size_t offset, const void *data, size_t len) +{ + struct fs_file *file; + uint8_t access; + int rc; + + access = FS_ACCESS_WRITE; + if (offset == 0) { + access |= FS_ACCESS_TRUNCATE; + } else { + access |= FS_ACCESS_APPEND; + } + + rc = fs_open(path, access, &file); + if (rc != 0) { + return MGMT_ERR_EUNKNOWN; + } + + rc = fs_write(file, data, len); + fs_close(file); + if (rc != 0) { + return MGMT_ERR_EUNKNOWN; + } + + return 0; +} static mgmt_handler_fn fs_mgmt_file_download; static mgmt_handler_fn fs_mgmt_file_upload; @@ -61,12 +146,12 @@ static struct mgmt_group fs_mgmt_group = { static int fs_mgmt_file_download(struct mgmt_ctxt *ctxt) { - uint8_t file_data[FS_MGMT_DL_CHUNK_SIZE]; - char path[FS_MGMT_PATH_SIZE + 1]; + uint8_t file_data[MYNEWT_VAL(FS_MGMT_DL_CHUNK_SIZE)]; + char path[MYNEWT_VAL(FS_MGMT_PATH_SIZE) + 1]; unsigned long long off; CborError err; - size_t bytes_read; - size_t file_len; + size_t bytes_read = 0; + size_t file_len = 0; int rc; const struct cbor_attr_t dload_attr[] = { @@ -94,14 +179,15 @@ fs_mgmt_file_download(struct mgmt_ctxt *ctxt) * length. */ if (off == 0) { - rc = fs_mgmt_impl_filelen(path, &file_len); + rc = fs_mgmt_filelen(path, &file_len); if (rc != 0) { return rc; } } /* Read the requested chunk from the file. */ - rc = fs_mgmt_impl_read(path, off, FS_MGMT_DL_CHUNK_SIZE, file_data, &bytes_read); + rc = fs_mgmt_read(path, off, MYNEWT_VAL(FS_MGMT_DL_CHUNK_SIZE), file_data, + &bytes_read); if (rc != 0) { return rc; } @@ -153,8 +239,8 @@ fs_mgmt_file_upload_rsp(struct mgmt_ctxt *ctxt, int rc, unsigned long long off) static int fs_mgmt_file_upload(struct mgmt_ctxt *ctxt) { - uint8_t file_data[FS_MGMT_UL_CHUNK_SIZE]; - char file_name[FS_MGMT_PATH_SIZE + 1]; + uint8_t file_data[MYNEWT_VAL(FS_MGMT_UL_CHUNK_SIZE)]; + char file_name[MYNEWT_VAL(FS_MGMT_PATH_SIZE) + 1]; unsigned long long len; unsigned long long off; size_t data_len; @@ -221,7 +307,7 @@ fs_mgmt_file_upload(struct mgmt_ctxt *ctxt) if (data_len > 0) { /* Write the data chunk to the file. */ - rc = fs_mgmt_impl_write(file_name, off, file_data, data_len); + rc = fs_mgmt_write(file_name, off, file_data, data_len); if (rc != 0) { return rc; } diff --git a/mgmt/mcumgr/cmd/fs_mgmt/src/stubs.c b/mgmt/mcumgr/cmd/fs_mgmt/src/stubs.c deleted file mode 100644 index 8b6ab8360..000000000 --- a/mgmt/mcumgr/cmd/fs_mgmt/src/stubs.c +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -/** - * These stubs get linked in when there is no equivalent OS-specific - * implementation. - */ - -#include "mgmt/mgmt.h" -#include "fs_mgmt/fs_mgmt_impl.h" - -int __attribute__((weak)) -fs_mgmt_impl_filelen(const char *path, size_t *out_len) -{ - return MGMT_ERR_ENOTSUP; -} - -int __attribute__((weak)) -fs_mgmt_impl_read(const char *path, size_t offset, size_t len, - void *out_data, size_t *out_len) -{ - return MGMT_ERR_ENOTSUP; -} - -int __attribute__((weak)) -fs_mgmt_impl_write(const char *path, size_t offset, const void *data, - size_t len) -{ - return MGMT_ERR_ENOTSUP; -}
