forked from Imagelibrary/rtems
ftpfs: Fix SIZE command handling
It is invalid to issue a SIZE command once a data transfer is in progress. For reads we issue the SIZE command before the RETR command and get a snapshot of the file size. For writes the file size is initialized to zero and incremented for each write chunk.
This commit is contained in:
@@ -17,6 +17,8 @@ USER anonymous
|
||||
230 User logged in.
|
||||
TYPE I
|
||||
200 Type set to I.
|
||||
SIZE a.txt
|
||||
213 1102
|
||||
PASV
|
||||
227 Entering passive mode (127,0,0,1,4,4).
|
||||
RETR a.txt
|
||||
@@ -41,6 +43,8 @@ USER anonymous
|
||||
230 User logged in.
|
||||
TYPE I
|
||||
200 Type set to I.
|
||||
SIZE b.txt
|
||||
213 1102
|
||||
PASV
|
||||
227 Entering passive mode (127,0,0,1,4,10).
|
||||
RETR b.txt
|
||||
|
||||
@@ -104,7 +104,7 @@ static void change_self_priority(void)
|
||||
rtems_test_assert(sc == RTEMS_SUCCESSFUL);
|
||||
}
|
||||
|
||||
static void create_file(const char *path)
|
||||
static void create_file(const char *path, const void *begin, size_t size)
|
||||
{
|
||||
int rv = 0;
|
||||
int fd = open(path, O_WRONLY);
|
||||
@@ -112,8 +112,8 @@ static void create_file(const char *path)
|
||||
|
||||
rtems_test_assert(fd >= 0);
|
||||
|
||||
n = write(fd, &content [0], sizeof(content));
|
||||
rtems_test_assert(n == (ssize_t) sizeof(content));
|
||||
n = write(fd, begin, size);
|
||||
rtems_test_assert(n == (ssize_t) size);
|
||||
|
||||
rv = close(fd);
|
||||
rtems_test_assert(rv == 0);
|
||||
@@ -126,15 +126,33 @@ static void copy_file(const char *src_path, const char *dest_path)
|
||||
int out = open(dest_path, O_WRONLY);
|
||||
ssize_t n_in = 0;
|
||||
char buf [64];
|
||||
struct stat st_in;
|
||||
struct stat st_out;
|
||||
|
||||
memset(&st_in, 0xff, sizeof(st_in));
|
||||
memset(&st_out, 0xff, sizeof(st_out));
|
||||
|
||||
rtems_test_assert(in >= 0);
|
||||
rtems_test_assert(out >= 0);
|
||||
|
||||
rv = fstat(out, &st_out);
|
||||
rtems_test_assert(rv == 0);
|
||||
|
||||
rtems_test_assert(st_out.st_size == 0);
|
||||
|
||||
while ((n_in = read(in, buf, sizeof(buf))) > 0) {
|
||||
ssize_t n_out = write(out, buf, (size_t) n_in);
|
||||
rtems_test_assert(n_out == n_in);
|
||||
}
|
||||
|
||||
rv = fstat(out, &st_out);
|
||||
rtems_test_assert(rv == 0);
|
||||
|
||||
rv = fstat(in, &st_in);
|
||||
rtems_test_assert(rv == 0);
|
||||
|
||||
rtems_test_assert(st_in.st_size == st_out.st_size);
|
||||
|
||||
rv = close(out);
|
||||
rtems_test_assert(rv == 0);
|
||||
|
||||
@@ -189,7 +207,7 @@ static void test(void)
|
||||
|
||||
initialize_ftpfs();
|
||||
change_self_priority();
|
||||
create_file(file_a);
|
||||
create_file(file_a, &content [0], sizeof(content));
|
||||
copy_file(file_a, file_b);
|
||||
check_file(file_b);
|
||||
check_file_size(file_a, sizeof(content));
|
||||
|
||||
Reference in New Issue
Block a user