diff options
Diffstat (limited to 'util.c')
-rw-r--r-- | util.c | 29 |
1 files changed, 29 insertions, 0 deletions
@@ -511,6 +511,35 @@ int check_raid(int fd, char *name) return 1; } +int check_clean(int dfd) +{ + void *head, *tail, *pattern; + int i=0, head_clean=0, tail_clean=0; + unsigned char patterns[]={0x00,0x5a,0xff}; + + head = malloc(4096); + tail = malloc(4096); + pattern = malloc(4096); + if (!head || !tail || !pattern) + return 0; + if (lseek(dfd, 0, SEEK_SET) == -1) + return 0; + if (read(dfd, head, 4096) != 4096) + return 0; + if (lseek(dfd, -4096, SEEK_END) == -1) + return 0; + if (read(dfd, tail, 4096) != 4096) + return 0; + while (i < 3) { + memset(pattern, patterns[i++], 4096); + if (memcmp(head, pattern, 4096) == 0) + head_clean++; + if (memcmp(tail, pattern, 4096) == 0) + tail_clean++; + } + return (head_clean && tail_clean); +} + int ask(char *mesg) { char *add = ""; |