47 #define MAX_FILENAME_LEN 40
48 #define MAX_BLOCKSIZE 40
51 PROCESS(shell_ls_process,
"ls");
56 PROCESS(shell_append_process,
"append");
59 "append <filename>: append to file",
60 &shell_append_process);
61 PROCESS(shell_write_process,
"write");
64 "write <filename>: write to file",
65 &shell_write_process);
66 PROCESS(shell_read_process,
"read");
69 "read <filename> [offset] [block size]: read from a file, with the offset and the block size as options",
71 PROCESS(shell_rm_process,
"rm");
74 "rm <filename>: remove the file named filename",
79 static struct cfs_dir dir;
80 static cfs_offset_t totsize;
81 struct cfs_dirent dirent;
90 totsize += dirent.size;
91 sprintf(buf,
"%lu ", (
unsigned long)dirent.size);
96 sprintf(buf,
"%lu", (
unsigned long)totsize);
115 "append: could not open file for writing: ", data);
121 if(input->len1 + input->len2 == 0) {
126 cfs_write(fd, input->data1, input->len1);
127 cfs_write(fd, input->data2, input->len2);
130 input->data1, input->len1,
131 input->data2, input->len2);
152 "write: could not open file for writing: ", data);
158 if(input->len1 + input->len2 == 0) {
164 if(input->len1 > 0) {
165 r = cfs_write(fd, input->data1, input->len1);
168 if(r >= 0 && input->len2 > 0) {
169 r = cfs_write(fd, input->data2, input->len2);
177 input->data1, input->len1,
178 input->data2, input->len2);
189 static int block_size = MAX_BLOCKSIZE;
191 char filename[MAX_FILENAME_LEN];
194 char buf[MAX_BLOCKSIZE];
201 next = strchr(data,
' ');
203 strncpy(filename, data,
sizeof(filename));
205 len = (int)(next - (
char *)data);
208 "read: filename too short: ", data);
211 if(len > MAX_FILENAME_LEN) {
213 "read: filename too long: ", data);
216 memcpy(filename, data, len);
221 next = strchr(next,
' ');
224 if(block_size > MAX_BLOCKSIZE) {
226 "read: block size too large: ", data);
237 "read: could not open file for reading: ", filename);
241 len = cfs_read(fd, buf, block_size);
256 if(input->len1 + input->len2 == 0) {
279 shell_file_init(
void)
A brief description of what this file is.
int cfs_open(const char *name, int flags)
Open a file.
void shell_output_str(struct shell_command *c, char *text1, const char *text2)
Output strings from a shell command.
#define PROCESS_EXIT()
Exit the currently running process.
cfs_offset_t cfs_seek(int fd, cfs_offset_t offset, int whence)
Seek to a specified position in an open file.
#define PROCESS_BEGIN()
Define the beginning of a process.
#define CFS_WRITE
Specify that cfs_open() should open a file for writing.
#define NULL
The null pointer.
#define CFS_READ
Specify that cfs_open() should open a file for reading.
int cfs_readdir(struct cfs_dir *dir, struct cfs_dirent *record)
Read a directory entry.
int process_post(struct process *p, process_event_t ev, process_data_t data)
Post an asynchronous event.
void shell_output(struct shell_command *c, void *data1, int len1, const void *data2, int len2)
Output data from a shell command.
#define CFS_APPEND
Specify that cfs_open() should append written data to the file rather than overwriting it...
#define PROCESS_THREAD(name, ev, data)
Define the body of a process.
#define PROCESS_END()
Define the end of a process.
unsigned long shell_strtolong(const char *str, const char **retstr)
Convert a string to a number.
int cfs_remove(const char *name)
Remove a file.
#define PROCESS_EXITHANDLER(handler)
Specify an action when a process exits.
Structure for shell input data.
void cfs_closedir(struct cfs_dir *dir)
Close a directory opened with cfs_opendir().
void shell_register_command(struct shell_command *c)
Register a command with the shell.
#define PROCESS_WAIT_EVENT_UNTIL(c)
Wait for an event to be posted to the process, with an extra condition.
#define PROCESS(name, strname)
Declare a process.
int shell_event_input
The event number for shell input data.
int cfs_opendir(struct cfs_dir *dir, const char *name)
Open a directory for reading directory entries.
#define CFS_SEEK_SET
Specify that cfs_seek() should compute the offset from the beginning of the file. ...
#define SHELL_COMMAND(name, command, description, process)
Define a shell command.
void cfs_close(int fd)
Close an open file.