You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ma...@apache.org on 2016/04/18 20:04:23 UTC

[05/14] incubator-mynewt-core git commit: fs; add 'cat' CLI command.

fs; add 'cat' CLI command.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/c56aca4a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/c56aca4a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/c56aca4a

Branch: refs/heads/develop
Commit: c56aca4ac6f78f626792e1fc6d9f01e6ebc81d38
Parents: 094ed50
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Wed Apr 13 10:54:24 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Apr 18 10:45:51 2016 -0700

----------------------------------------------------------------------
 fs/fs/src/fs_cli.c                     | 39 +++++++++++++++++++++++++++++
 libs/bootutil/include/bootutil/crc32.h | 26 -------------------
 2 files changed, 39 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c56aca4a/fs/fs/src/fs_cli.c
----------------------------------------------------------------------
diff --git a/fs/fs/src/fs_cli.c b/fs/fs/src/fs_cli.c
index 459533e..4498d87 100644
--- a/fs/fs/src/fs_cli.c
+++ b/fs/fs/src/fs_cli.c
@@ -31,6 +31,7 @@ static int fs_ls_cmd(int argc, char **argv);
 static int fs_rm_cmd(int argc, char **argv);
 static int fs_mkdir_cmd(int argc, char **argv);
 static int fs_mv_cmd(int argc, char **argv);
+static int fs_cat_cmd(int argc, char **argv);
 
 static struct shell_cmd fs_ls_struct = {
     .sc_cmd = "ls",
@@ -48,6 +49,10 @@ static struct shell_cmd fs_mv_struct = {
     .sc_cmd = "mv",
     .sc_cmd_func = fs_mv_cmd
 };
+static struct shell_cmd fs_cat_struct = {
+    .sc_cmd = "cat",
+    .sc_cmd_func = fs_cat_cmd
+};
 
 static void
 fs_ls_file(const char *name, struct fs_file *file)
@@ -180,6 +185,39 @@ out:
     return 0;
 }
 
+static int
+fs_cat_cmd(int argc, char **argv)
+{
+    int rc;
+    struct fs_file *file;
+    char buf[32];
+    uint32_t len;
+
+    if (argc != 2) {
+        console_printf("cat <filename>\n");
+        return -1;
+    }
+
+    rc = fs_open(argv[1], FS_ACCESS_READ, &file);
+    if (rc != FS_EOK) {
+        console_printf("Error opening %s - %d\n", argv[1], rc);
+        return -1;
+    }
+
+    do {
+        rc = fs_read(file, sizeof(buf), buf, &len);
+        if (rc != FS_EOK) {
+            console_printf("\nError reading %s - %d\n", argv[1], rc);
+            break;
+        }
+        console_write(buf, len);
+    } while (len > 0);
+
+    fs_close(file);
+
+    return 0;
+}
+
 void
 fs_cli_init(void)
 {
@@ -187,5 +225,6 @@ fs_cli_init(void)
     shell_cmd_register(&fs_rm_struct);
     shell_cmd_register(&fs_mkdir_struct);
     shell_cmd_register(&fs_mv_struct);
+    shell_cmd_register(&fs_cat_struct);
 }
 #endif /* SHELL_PRESENT */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c56aca4a/libs/bootutil/include/bootutil/crc32.h
----------------------------------------------------------------------
diff --git a/libs/bootutil/include/bootutil/crc32.h b/libs/bootutil/include/bootutil/crc32.h
deleted file mode 100644
index 5dfe221..0000000
--- a/libs/bootutil/include/bootutil/crc32.h
+++ /dev/null
@@ -1,26 +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_CRC32_
-#define H_CRC32_
-
-uint32_t crc32(uint32_t crc, const void *buf, size_t size);
-
-#endif
-