Bugfix: don't try to read/write/append to file if it was not possible to open it. Bugfix: CFS file descriptors that are 0 are OK.
This commit is contained in:
parent
7e4bab3cc8
commit
adbf6c47ab
|
@ -28,7 +28,7 @@
|
||||||
*
|
*
|
||||||
* This file is part of the Contiki operating system.
|
* This file is part of the Contiki operating system.
|
||||||
*
|
*
|
||||||
* $Id: shell-file.c,v 1.3 2008/05/24 08:31:56 oliverschmidt Exp $
|
* $Id: shell-file.c,v 1.4 2008/07/02 14:06:46 adamdunkels Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -75,7 +75,7 @@ PROCESS_THREAD(shell_ls_process, ev, data)
|
||||||
char buf[32];
|
char buf[32];
|
||||||
PROCESS_BEGIN();
|
PROCESS_BEGIN();
|
||||||
|
|
||||||
if(cfs_opendir(&dir, ".") != 0) {
|
if(cfs_opendir(&dir, "/") != 0) {
|
||||||
shell_output_str(&ls_command, "Cannot open directory", "");
|
shell_output_str(&ls_command, "Cannot open directory", "");
|
||||||
} else {
|
} else {
|
||||||
totsize = 0;
|
totsize = 0;
|
||||||
|
@ -101,27 +101,27 @@ PROCESS_THREAD(shell_append_process, ev, data)
|
||||||
|
|
||||||
fd = cfs_open(data, CFS_WRITE | CFS_APPEND);
|
fd = cfs_open(data, CFS_WRITE | CFS_APPEND);
|
||||||
|
|
||||||
if(fd <= 0) {
|
if(fd < 0) {
|
||||||
shell_output_str(&append_command,
|
shell_output_str(&append_command,
|
||||||
"Could not open file for writing: ", data);
|
"append: could not open file for writing: ", data);
|
||||||
}
|
} else {
|
||||||
|
while(1) {
|
||||||
while(1) {
|
struct shell_input *input;
|
||||||
struct shell_input *input;
|
PROCESS_WAIT_EVENT_UNTIL(ev == shell_event_input);
|
||||||
PROCESS_WAIT_EVENT_UNTIL(ev == shell_event_input);
|
input = data;
|
||||||
input = data;
|
/* printf("cat input %d %d\n", input->len1, input->len2);*/
|
||||||
/* printf("cat input %d %d\n", input->len1, input->len2);*/
|
if(input->len1 + input->len2 == 0) {
|
||||||
if(input->len1 + input->len2 == 0) {
|
cfs_close(fd);
|
||||||
cfs_close(fd);
|
PROCESS_EXIT();
|
||||||
PROCESS_EXIT();
|
}
|
||||||
|
|
||||||
|
cfs_write(fd, input->data1, input->len1);
|
||||||
|
cfs_write(fd, input->data2, input->len2);
|
||||||
|
|
||||||
|
shell_output(&append_command,
|
||||||
|
input->data1, input->len1,
|
||||||
|
input->data2, input->len2);
|
||||||
}
|
}
|
||||||
|
|
||||||
cfs_write(fd, input->data1, input->len1);
|
|
||||||
cfs_write(fd, input->data2, input->len2);
|
|
||||||
|
|
||||||
shell_output(&append_command,
|
|
||||||
input->data1, input->len1,
|
|
||||||
input->data2, input->len2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PROCESS_END();
|
PROCESS_END();
|
||||||
|
@ -137,27 +137,27 @@ PROCESS_THREAD(shell_write_process, ev, data)
|
||||||
|
|
||||||
fd = cfs_open(data, CFS_WRITE);
|
fd = cfs_open(data, CFS_WRITE);
|
||||||
|
|
||||||
if(fd <= 0) {
|
if(fd < 0) {
|
||||||
shell_output_str(&write_command,
|
shell_output_str(&write_command,
|
||||||
"Could not open file for writing: ", data);
|
"write: could not open file for writing: ", data);
|
||||||
}
|
} else {
|
||||||
|
while(1) {
|
||||||
while(1) {
|
struct shell_input *input;
|
||||||
struct shell_input *input;
|
PROCESS_WAIT_EVENT_UNTIL(ev == shell_event_input);
|
||||||
PROCESS_WAIT_EVENT_UNTIL(ev == shell_event_input);
|
input = data;
|
||||||
input = data;
|
/* printf("cat input %d %d\n", input->len1, input->len2);*/
|
||||||
/* printf("cat input %d %d\n", input->len1, input->len2);*/
|
if(input->len1 + input->len2 == 0) {
|
||||||
if(input->len1 + input->len2 == 0) {
|
cfs_close(fd);
|
||||||
cfs_close(fd);
|
PROCESS_EXIT();
|
||||||
PROCESS_EXIT();
|
}
|
||||||
|
|
||||||
|
cfs_write(fd, input->data1, input->len1);
|
||||||
|
cfs_write(fd, input->data2, input->len2);
|
||||||
|
|
||||||
|
shell_output(&write_command,
|
||||||
|
input->data1, input->len1,
|
||||||
|
input->data2, input->len2);
|
||||||
}
|
}
|
||||||
|
|
||||||
cfs_write(fd, input->data1, input->len1);
|
|
||||||
cfs_write(fd, input->data2, input->len2);
|
|
||||||
|
|
||||||
shell_output(&write_command,
|
|
||||||
input->data1, input->len1,
|
|
||||||
input->data2, input->len2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PROCESS_END();
|
PROCESS_END();
|
||||||
|
@ -171,36 +171,36 @@ PROCESS_THREAD(shell_read_process, ev, data)
|
||||||
|
|
||||||
fd = cfs_open(data, CFS_READ);
|
fd = cfs_open(data, CFS_READ);
|
||||||
|
|
||||||
if(fd <= 0) {
|
if(fd < 0) {
|
||||||
shell_output_str(&write_command,
|
shell_output_str(&read_command,
|
||||||
"Could not open file for reading: ", data);
|
"read: could not open file for reading: ", data);
|
||||||
}
|
} else {
|
||||||
|
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
char buf[40];
|
char buf[40];
|
||||||
int len;
|
int len;
|
||||||
struct shell_input *input;
|
struct shell_input *input;
|
||||||
|
|
||||||
len = cfs_read(fd, buf, sizeof(buf));
|
len = cfs_read(fd, buf, sizeof(buf));
|
||||||
if(len <= 0) {
|
if(len <= 0) {
|
||||||
cfs_close(fd);
|
|
||||||
PROCESS_EXIT();
|
|
||||||
}
|
|
||||||
shell_output(&read_command,
|
|
||||||
buf, len, "", 0);
|
|
||||||
|
|
||||||
process_post(&shell_read_process, PROCESS_EVENT_CONTINUE, NULL);
|
|
||||||
PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_CONTINUE ||
|
|
||||||
ev == shell_event_input);
|
|
||||||
|
|
||||||
if(ev == shell_event_input) {
|
|
||||||
input = data;
|
|
||||||
/* printf("cat input %d %d\n", input->len1, input->len2);*/
|
|
||||||
if(input->len1 + input->len2 == 0) {
|
|
||||||
cfs_close(fd);
|
cfs_close(fd);
|
||||||
PROCESS_EXIT();
|
PROCESS_EXIT();
|
||||||
}
|
}
|
||||||
|
shell_output(&read_command,
|
||||||
|
buf, len, "", 0);
|
||||||
|
|
||||||
|
process_post(&shell_read_process, PROCESS_EVENT_CONTINUE, NULL);
|
||||||
|
PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_CONTINUE ||
|
||||||
|
ev == shell_event_input);
|
||||||
|
|
||||||
|
if(ev == shell_event_input) {
|
||||||
|
input = data;
|
||||||
|
/* printf("cat input %d %d\n", input->len1, input->len2);*/
|
||||||
|
if(input->len1 + input->len2 == 0) {
|
||||||
|
cfs_close(fd);
|
||||||
|
PROCESS_EXIT();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue