xiaoxiang781216 commented on code in PR #3665:
URL: https://github.com/apache/nuttx-apps/pull/3665#discussion_r3653971536


##########
testing/fs/xipfs/xipfs_main.c:
##########
@@ -0,0 +1,2032 @@
+/****************************************************************************
+ * apps/testing/fs/xipfs/xipfs_main.c
+ *
+ * SPDX-License-Identifier: Apache-2.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.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/ioctl.h>
+#include <sys/mman.h>
+#include <sys/mount.h>
+#include <sys/stat.h>
+#include <sys/wait.h>
+
+#include <dirent.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <malloc.h>
+#include <sched.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <nuttx/fs/ioctl.h>
+#include <nuttx/fs/xipfs.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define MOUNTPT   CONFIG_TESTING_FS_XIPFS_MOUNTPT
+#define MTDDEV    CONFIG_TESTING_FS_XIPFS_MTD
+
+#define PATH(name) MOUNTPT "/" name
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static int g_passed;
+static int g_failed;
+static FAR uint8_t *g_buffer;
+static size_t g_bufsize = 16384;
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+static void report(FAR const char *name, bool ok, FAR const char *detail)
+{
+  if (ok)
+    {
+      g_passed++;
+      printf("  PASS  %s\n", name);
+    }
+  else
+    {
+      g_failed++;
+      printf("  FAIL  %s: %s\n", name, detail ? detail : "");
+    }
+}
+
+#define CHECK(name, cond, detail) report((name), (cond), (detail))
+
+/****************************************************************************
+ * Name: remount
+ *
+ * Description:
+ *   Discard every scrap of in-RAM filesystem state and mount again from the
+ *   medium.  Because the rammtd buffer survives, this is exactly what a
+ *   reboot looks like to the filesystem, which is what makes the power loss
+ *   sweep below meaningful without restarting the simulator.
+ *
+ ****************************************************************************/
+
+static int remount(void)
+{
+  int ret;
+
+  ret = umount(MOUNTPT);
+  if (ret < 0 && errno != ENOENT && errno != EINVAL)
+    {
+      printf("    umount failed: %d\n", errno);
+      return -errno;
+    }
+
+  ret = mount(MTDDEV, MOUNTPT, "xipfs", 0, NULL);
+  if (ret < 0)
+    {
+      return -errno;
+    }
+
+  return 0;
+}
+
+/****************************************************************************
+ * Name: fill_pattern
+ ****************************************************************************/
+
+static void fill_pattern(FAR uint8_t *buf, size_t len, uint8_t seed)
+{
+  size_t i;
+
+  for (i = 0; i < len; i++)
+    {
+      buf[i] = (uint8_t)(seed + (i * 7));
+    }
+}
+
+/****************************************************************************
+ * Name: create_file
+ *
+ * Description:
+ *   Create a file of a known size.  ftruncate is how the exact size is
+ *   declared up front, which is what lets the filesystem reserve the exact
+ *   contiguous extent rather than over-reserving and trimming.
+ *
+ ****************************************************************************/
+
+static int create_file(FAR const char *path, size_t len, uint8_t seed)
+{
+  ssize_t nwritten;
+  int fd;
+  int ret = 0;
+
+  fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0644);
+  if (fd < 0)
+    {
+      return -errno;
+    }
+
+  if (ftruncate(fd, len) < 0)
+    {
+      ret = -errno;
+      goto out;
+    }
+
+  fill_pattern(g_buffer, len, seed);
+
+  nwritten = write(fd, g_buffer, len);
+  if (nwritten != (ssize_t)len)

Review Comment:
   I suppose that the build system doesn't enable sign mismatch comparison 
warning?



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to