forked from len0rd/rockbox
Added close() return code checks, and an eof-write test.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@2848 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
72f2afbe71
commit
dc9cdc40ed
1 changed files with 55 additions and 16 deletions
|
|
@ -135,8 +135,7 @@ int dbg_mkfile(char* name, int num)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
close(fd);
|
return close(fd);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -191,9 +190,7 @@ int dbg_chkfile(char* name, int size)
|
||||||
block++;
|
block++;
|
||||||
}
|
}
|
||||||
|
|
||||||
close(fd);
|
return close(fd);
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int dbg_wrtest(char* name)
|
int dbg_wrtest(char* name)
|
||||||
|
|
@ -263,9 +260,7 @@ int dbg_wrtest(char* name)
|
||||||
block++;
|
block++;
|
||||||
}
|
}
|
||||||
|
|
||||||
close(fd);
|
return close(fd);
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void dbg_type(char* name)
|
void dbg_type(char* name)
|
||||||
|
|
@ -316,7 +311,8 @@ int dbg_append(char* name)
|
||||||
x = size / CHUNKSIZE;
|
x = size / CHUNKSIZE;
|
||||||
LDEBUGF("Check base is %x (%d)\n",x,size);
|
LDEBUGF("Check base is %x (%d)\n",x,size);
|
||||||
|
|
||||||
close(fd);
|
if (close(fd) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
fd = open(name,O_RDWR|O_APPEND);
|
fd = open(name,O_RDWR|O_APPEND);
|
||||||
if (fd<0) {
|
if (fd<0) {
|
||||||
|
|
@ -329,9 +325,46 @@ int dbg_append(char* name)
|
||||||
if ( rc < 0 )
|
if ( rc < 0 )
|
||||||
panicf("Failed writing data\n");
|
panicf("Failed writing data\n");
|
||||||
|
|
||||||
close(fd);
|
return close(fd);
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
int dbg_test(char* name)
|
||||||
|
{
|
||||||
|
int x=0;
|
||||||
|
int size, fd, rc;
|
||||||
|
char buf[4096];
|
||||||
|
|
||||||
|
fd = open(name,O_RDWR);
|
||||||
|
if (fd<0) {
|
||||||
|
DEBUGF("Failed opening file\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
size = lseek(fd, -1024, SEEK_END);
|
||||||
|
size &= ~7;
|
||||||
|
DEBUGF("File is %d bytes\n", size);
|
||||||
|
x = size / CHUNKSIZE;
|
||||||
|
LDEBUGF("Check base is %x (%d)\n",x,size);
|
||||||
|
|
||||||
|
rc = read(fd, buf, sizeof buf);
|
||||||
|
if ( rc < 0 )
|
||||||
|
panicf("Failed reading data\n");
|
||||||
|
if ( rc == 0 )
|
||||||
|
DEBUGF("EOF\n");
|
||||||
|
|
||||||
|
rc = read(fd, buf, sizeof buf);
|
||||||
|
if ( rc < 0 )
|
||||||
|
panicf("Failed reading data\n");
|
||||||
|
if ( rc == 0 )
|
||||||
|
DEBUGF("EOF\n");
|
||||||
|
|
||||||
|
rc = write(fd, buf, sizeof buf);
|
||||||
|
if ( rc < 0 )
|
||||||
|
panicf("Failed writing data\n");
|
||||||
|
if ( rc == 0 )
|
||||||
|
DEBUGF("Nothing written!\n");
|
||||||
|
|
||||||
|
return close(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
int dbg_dump(char* name, int offset)
|
int dbg_dump(char* name, int offset)
|
||||||
|
|
@ -350,7 +383,8 @@ int dbg_dump(char* name, int offset)
|
||||||
if ( rc < 0 )
|
if ( rc < 0 )
|
||||||
panicf("Error reading data\n");
|
panicf("Error reading data\n");
|
||||||
|
|
||||||
close(fd);
|
if (close(fd) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
dbg_dump_buffer(buf, rc, offset);
|
dbg_dump_buffer(buf, rc, offset);
|
||||||
|
|
||||||
|
|
@ -414,8 +448,7 @@ int dbg_head(char* name)
|
||||||
DEBUGF("Failed reading file: %d\n",rc);
|
DEBUGF("Failed reading file: %d\n",rc);
|
||||||
}
|
}
|
||||||
|
|
||||||
close(fd);
|
return close(fd);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int dbg_trunc(char* name, int size)
|
int dbg_trunc(char* name, int size)
|
||||||
|
|
@ -443,8 +476,7 @@ int dbg_trunc(char* name, int size)
|
||||||
return -2;
|
return -2;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
close(fd);
|
return close(fd);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int dbg_cmd(int argc, char *argv[])
|
int dbg_cmd(int argc, char *argv[])
|
||||||
|
|
@ -478,6 +510,7 @@ int dbg_cmd(int argc, char *argv[])
|
||||||
" trunc <file> <size>\n"
|
" trunc <file> <size>\n"
|
||||||
" wrtest <file>\n"
|
" wrtest <file>\n"
|
||||||
" append <file>\n"
|
" append <file>\n"
|
||||||
|
" test <file>\n"
|
||||||
);
|
);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
@ -570,6 +603,12 @@ int dbg_cmd(int argc, char *argv[])
|
||||||
return dbg_append(arg1);
|
return dbg_append(arg1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!strcasecmp(cmd, "test"))
|
||||||
|
{
|
||||||
|
if (arg1)
|
||||||
|
return dbg_test(arg1);
|
||||||
|
}
|
||||||
|
|
||||||
if (!strcasecmp(cmd, "trunc"))
|
if (!strcasecmp(cmd, "trunc"))
|
||||||
{
|
{
|
||||||
if (arg1 && arg2)
|
if (arg1 && arg2)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue