acassis commented on code in PR #2228: URL: https://github.com/apache/nuttx-apps/pull/2228#discussion_r1491109249
########## examples/settings/Kconfig: ########## @@ -0,0 +1,61 @@ +# +# For a description of the syntax of this configuration file, +# see the file kconfig-language.txt in the NuttX tools repository. +# + +config EXAMPLES_SETTINGS + tristate "Settings example" + default n + ---help--- + Enable the "settings" example. This uses the functions provided in + utils/settings to test the storage and retrieval of various + configurable parameters + +if EXAMPLES_SETTINGS + +config EXAMPLES_SETTINGS_PROGNAME + string "Program name" + default "settings" + ---help--- + This is the name of the program that will be used when the NSH ELF + program is installed. + +config EXAMPLES_SETTINGS_PRIORITY + int "settings task priority" + default 100 + +config EXAMPLES_SETTINGS_STACKSIZE + int "settings stack size" + default DEFAULT_TASK_STACKSIZE + +choice + prompt "Select settings storage location" + default EXAMPLES_SETTINGS_USE_TMPFS + +config EXAMPLES_SETTINGS_USE_TMPFS + bool "Use TMPFS" + select FS_TMPFS + ---help--- + TMPFS will be enabled and used + +config EXAMPLES_SETTINGS_USE_OTHER + bool "Use existing/other storage media" + +endchoice # Select settings storage location + +if EXAMPLES_SETTINGS_USE_OTHER + +config EXAMPLES_SETTINGS_EXISTING_STORAGE + string "Path to existing storage media" + default "/mnt/sdcard0" Review Comment: Normally /dev/mmcsd0 is mount at /mnt, also the user his other storage (flash, etc) to /mnt ########## examples/settings/settings_main.c: ########## @@ -0,0 +1,301 @@ +/**************************************************************************** + * apps/examples/settings/settings_main.c + * + * 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. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#include <stdio.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <errno.h> +#include <sys/mount.h> +#include <sys/param.h> + +#include "system/settings.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * settings_main + ****************************************************************************/ + +int settings_main(int argc, FAR char *argv[]) +{ + int ret; + int fd; + enum settings_type_e stype; + char text_path[CONFIG_PATH_MAX]; + char bin_path[CONFIG_PATH_MAX]; + const char teststr[] = "I'm a string"; + int testval = 0x5aa5; + char readstr[CONFIG_SYSTEM_SETTINGS_VALUE_SIZE]; + struct stat sbuf; + +#ifdef CONFIG_EXAMPLES_SETTINGS_USE_TMPFS +# ifndef CONFIG_FS_TMPFS +# error TMPFS must be enabled +# endif +# ifndef CONFIG_LIBC_TMPDIR +# error LIBC_TMPDIR must be defined +# endif + if (stat(CONFIG_LIBC_TMPDIR, &sbuf)) + { + ret = nx_mount(NULL, CONFIG_LIBC_TMPDIR, "tmpfs", 0, NULL); + if (ret < 0) + { + printf("ERROR: Failed to mount tmpfs at %s: %d\n", + CONFIG_LIBC_TMPDIR, ret); + goto end; + } + } + + strcpy(bin_path, CONFIG_LIBC_TMPDIR); +#else + strcpy(path, CONFIG_EXAMPLES_SETTINGS_EXISTING_STORAGE); + if (path == NULL) + { + printf("Settings filepath is empty!"); + goto end; + } +#endif + + strcat(bin_path, "/"); + strcat(bin_path, CONFIG_EXAMPLES_SETTINGS_FILENAME); + strcpy(text_path, bin_path); + strcat(bin_path, ".bin"); + strcat(text_path, ".txt"); Review Comment: Always use strnxxx for safety reason (to protect against buffer overflow) ########## examples/settings/Kconfig: ########## @@ -0,0 +1,61 @@ +# +# For a description of the syntax of this configuration file, +# see the file kconfig-language.txt in the NuttX tools repository. +# + +config EXAMPLES_SETTINGS + tristate "Settings example" + default n + ---help--- + Enable the "settings" example. This uses the functions provided in + utils/settings to test the storage and retrieval of various Review Comment: ```suggestion system/settings to test the storage and retrieval of various ########## examples/settings/Kconfig: ########## @@ -0,0 +1,61 @@ +# +# For a description of the syntax of this configuration file, +# see the file kconfig-language.txt in the NuttX tools repository. +# + +config EXAMPLES_SETTINGS + tristate "Settings example" + default n + ---help--- + Enable the "settings" example. This uses the functions provided in + utils/settings to test the storage and retrieval of various + configurable parameters + +if EXAMPLES_SETTINGS + +config EXAMPLES_SETTINGS_PROGNAME + string "Program name" + default "settings" + ---help--- + This is the name of the program that will be used when the NSH ELF + program is installed. + +config EXAMPLES_SETTINGS_PRIORITY + int "settings task priority" + default 100 + +config EXAMPLES_SETTINGS_STACKSIZE + int "settings stack size" + default DEFAULT_TASK_STACKSIZE + +choice + prompt "Select settings storage location" + default EXAMPLES_SETTINGS_USE_TMPFS + +config EXAMPLES_SETTINGS_USE_TMPFS + bool "Use TMPFS" + select FS_TMPFS + ---help--- + TMPFS will be enabled and used + +config EXAMPLES_SETTINGS_USE_OTHER + bool "Use existing/other storage media" + +endchoice # Select settings storage location + +if EXAMPLES_SETTINGS_USE_OTHER + +config EXAMPLES_SETTINGS_EXISTING_STORAGE + string "Path to existing storage media" + default "/mnt/sdcard0" Review Comment: ```suggestion default "/mnt" -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org