Contiki 3.x
cfs-ls.c
Go to the documentation of this file.
1 /*
2  * list the number of files in th ecoffee file system
3  */
4 
5 /**
6  * \file
7  * Basic test for CFS/Coffee.
8  * \author
9  * Kirk Martinez, University of Southampton
10  */
11 
12 #include "contiki.h"
13 #include "cfs/cfs.h"
14 #include "cfs/cfs-coffee.h"
15 #include "lib/crc16.h"
16 #include "lib/random.h"
17 
18 #include <stdio.h>
19 #include <string.h>
20 
21 PROCESS(listcoffee_process, "CFS/Coffee dir list process");
22 AUTOSTART_PROCESSES(&listcoffee_process);
23 
24 /* returns the number of files in the directory on Flash
25 */
26 int coffee_du(int *filec, int *bytes)
27 {
28 struct cfs_dir dir;
29 struct cfs_dirent dirent;
30 int dirp;
31 int count = 0;
32 int used = 0;
33 
34 if(cfs_opendir(&dir, "/") == 0) {
35  while(cfs_readdir(&dir, &dirent) != -1) {
36  printf("%s %ld\n",
37  dirent.name, (long)dirent.size);
38  count++;
39  used += (long)dirent.size;
40  }
41  //cfs_closedir(&dir);
42  }
43 else {
44  printf("opendir failed\n");
45  }
46 
47 // no idea how to close dir
48 //cfs_closedir(&dirp);
49 *bytes = used;
50 *filec = count;
51 return(0);
52 }
53 
54 /*---------------------------------------------------------------------------*/
55 PROCESS_THREAD(listcoffee_process, ev, data)
56 {
57 int c;
58 int used;
59 int count;
60  PROCESS_BEGIN();
61 
62  c = coffee_du(&count, &used );
63  printf("%d files %d bytes used\n",count, used);
64  PROCESS_END();
65 }
66 /*---------------------------------------------------------------------------*/
int cfs_opendir(struct cfs_dir *dir, const char *name)
Open a directory for reading directory entries.
Definition: cfs-coffee.c:1283
#define PROCESS_END()
Define the end of a process.
Definition: process.h:131
#define PROCESS(name, strname)
Declare a process.
Definition: process.h:307
#define PROCESS_THREAD(name, ev, data)
Define the body of a process.
Definition: process.h:273
int cfs_readdir(struct cfs_dir *dir, struct cfs_dirent *record)
Read a directory entry.
Definition: cfs-coffee.c:1294
static volatile clock_time_t count
These routines define the AVR-specific calls declared in /core/sys/clock.h CLOCK_SECOND is the number...
Definition: clock.c:80
Header for the Coffee file system.
CFS header file.
Header file for the CRC16 calculcation
#define PROCESS_BEGIN()
Define the beginning of a process.
Definition: process.h:120