1 /*
2 * Copyright (C) 2015-2021 Alibaba Group Holding Limited
3 */
4 #include <fcntl.h>
5 #include <sys/types.h>
6 #include <unistd.h>
7 #include <stdlib.h>
8 #include <stdio.h>
9 #if AOS_COMP_CLI
10 #include "aos/cli.h"
11 #endif
12 #include "ramfs.h"
13
ramfs_example_fn(int argc,char ** argv)14 static void ramfs_example_fn(int argc, char **argv)
15 {
16 (void)argc;
17 (void)argv;
18 int fd;
19 int ret;
20 char teststring = "1234";
21 char readbuf[10];
22
23 ramfs_register("/test");
24 fd = open("/test/file1", O_RDWR);
25 if(fd < 0){
26 printf("ramfs: fd open fail!\r\n");
27 return;
28 }
29 ret = write(fd, teststring, 5);
30 if(ret < 0){
31 printf("ramfs: fd write fail!\r\n");
32 close(fd);
33 return;
34 }
35 lseek(fd, 0, SEEK_SET);
36 ret = read(fd, readbuf, 5);
37 if(ret < 0){
38 printf("ramfs: fd read fail!\r\n");
39 close(fd);
40 return;
41 }
42 if(strncmp(readbuf, teststring, 5)){
43 printf("ramfs: fd test fail! readbuf:%s\r\n",readbuf);
44 }else{
45 printf("ramfs: fd test success!\r\n");
46 }
47 close(fd);
48
49 printf("ramfs comp test success!\r\n");
50 return;
51 }
52
53 #if AOS_COMP_CLI
54 /* reg args: fun, cmd, description*/
55 ALIOS_CLI_CMD_REGISTER(ramfs_example_fn, ramfs_example, ramfs component base example)
56 #endif
57