diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2011-05-02 01:30:30 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2011-05-02 01:30:30 +0000 |
commit | 6e723db07e440e19453f35e8e3a3850e3b4d7373 (patch) | |
tree | 238656fe5bc625b70bf5d74d0ff24d510079503b /apps/examples/nxffs | |
parent | a86b56511ae7a4f183841e3708407625fcec8e2c (diff) | |
download | px4-nuttx-6e723db07e440e19453f35e8e3a3850e3b4d7373.tar.gz px4-nuttx-6e723db07e440e19453f35e8e3a3850e3b4d7373.tar.bz2 px4-nuttx-6e723db07e440e19453f35e8e3a3850e3b4d7373.zip |
More NXFFS bugfixes
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3550 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'apps/examples/nxffs')
-rw-r--r-- | apps/examples/nxffs/nxffs_main.c | 35 |
1 files changed, 23 insertions, 12 deletions
diff --git a/apps/examples/nxffs/nxffs_main.c b/apps/examples/nxffs/nxffs_main.c index 9ba7c5fad..8c12825fa 100644 --- a/apps/examples/nxffs/nxffs_main.c +++ b/apps/examples/nxffs/nxffs_main.c @@ -318,31 +318,41 @@ static ssize_t nxffs_rdblock(int fd, FAR struct nxffs_filedesc_s *file, size_t offset, size_t len) { size_t maxio = (rand() % CONFIG_EXAMPLES_NXFFS_MAXIO) + 1; - size_t nbytestoread = len - offset; ssize_t nbytesread; - if (nbytestoread > maxio) + if (len > maxio) { - nbytestoread = maxio; + len = maxio; } - nbytesread = read(fd, &g_fileimage[offset], nbytestoread); + nbytesread = read(fd, &g_fileimage[offset], len); if (nbytesread < 0) { fprintf(stderr, "Failed to read file: %d\n", errno); fprintf(stderr, " File name: %s\n", file->name); fprintf(stderr, " File size: %d\n", file->len); fprintf(stderr, " Read offset: %d\n", offset); - fprintf(stderr, " Read size: %d\n", nbytestoread); + fprintf(stderr, " Read size: %d\n", len); return ERROR; } - else if (nbytesread != nbytestoread) + else if (nbytesread == 0) + { +#if 0 /* No... we do this on purpose sometimes */ + fprintf(stderr, "Unexpected end-of-file:\n"); + fprintf(stderr, " File name: %s\n", file->name); + fprintf(stderr, " File size: %d\n", file->len); + fprintf(stderr, " Read offset: %d\n", offset); + fprintf(stderr, " Read size: %d\n", len); +#endif + return ERROR; + } + else if (nbytesread != len) { fprintf(stderr, "Partial read:\n"); fprintf(stderr, " File name: %s\n", file->name); fprintf(stderr, " File size: %d\n", file->len); fprintf(stderr, " Read offset: %d\n", offset); - fprintf(stderr, " Read size: %d\n", nbytestoread); + fprintf(stderr, " Read size: %d\n", len); fprintf(stderr, " Bytes read: %d\n", nbytesread); } return nbytesread; @@ -372,7 +382,7 @@ static inline int nxffs_rdfile(FAR struct nxffs_filedesc_s *file) /* Read all of the data info the fileimage buffer using random read sizes */ - for (ntotalread =0; ntotalread < file->len; ) + for (ntotalread = 0; ntotalread < file->len; ) { nbytesread = nxffs_rdblock(fd, file, ntotalread, file->len - ntotalread); if (nbytesread < 0) @@ -399,11 +409,12 @@ static inline int nxffs_rdfile(FAR struct nxffs_filedesc_s *file) /* Try reading past the end of the file */ nbytesread = nxffs_rdblock(fd, file, ntotalread, 1024) ; - if (nbytesread >= 0) + if (nbytesread > 0) { fprintf(stderr, "Read past the end of file\n"); - fprintf(stderr, " File name: %s\n", file->name); - fprintf(stderr, " File size: %d\n", file->len); + fprintf(stderr, " File name: %s\n", file->name); + fprintf(stderr, " File size: %d\n", file->len); + fprintf(stderr, " Bytes read: %d\n", nbytesread); close(fd); return ERROR; } @@ -461,7 +472,7 @@ static int nxffs_verifyfs(void) } else { - fprintf(stderr, "File %d file OK\n", i); + fprintf(stderr, "File %d: OK\n", i); } } } |