mirror of
https://github.com/MariaDB/server.git
synced 2025-02-02 03:51:50 +01:00
7b19ba34fc
Page CRC check based on pagecache support added. Loghandler pagecache callbacks support added. Loghandler filecache rewritten. Support of deletting all logs added. storage/maria/Makefile.am: New file with functions for CRC calculation. storage/maria/ma_bitmap.c: Page CRC support. storage/maria/ma_blockrec.c: Removed code replaced by pagecache callbacks. storage/maria/ma_check.c: Page CRC support. storage/maria/ma_create.c: Page CRC support. storage/maria/ma_loghandler.c: Pagecache callbacks support. New file cache support. Removing log files support. storage/maria/ma_loghandler.h: CRC_LENGTH replaced with CRC_SIZE storage/maria/ma_open.c: Page CRC support. storage/maria/ma_page.c: Page CRC support. storage/maria/ma_pagecache.c: Pagecache callbacks support. storage/maria/ma_pagecache.h: Pagecache callbacks support. storage/maria/ma_panic.c: Page CRC support. storage/maria/maria_chk.c: Page CRC support. storage/maria/maria_def.h: Page CRC support. storage/maria/unittest/Makefile.am: New test of removing logs. storage/maria/unittest/ma_maria_log_cleanup.c: Memory leack fixed. storage/maria/unittest/ma_pagecache_consist.c: Pagecache callbacks support. storage/maria/unittest/ma_pagecache_single.c: Pagecache callbacks support. storage/maria/unittest/ma_test_loghandler-t.c: Fixed the test error processing. storage/maria/unittest/ma_test_loghandler_first_lsn-t.c: Fixed the test error processing. storage/maria/unittest/ma_test_loghandler_max_lsn-t.c: Fixed the test error processing. storage/maria/unittest/ma_test_loghandler_multigroup-t.c: Fixed the test error processing. storage/maria/unittest/ma_test_loghandler_multithread-t.c: Fixed the test error processing. storage/maria/unittest/ma_test_loghandler_noflush-t.c: Fixed the test error processing. storage/maria/unittest/ma_test_loghandler_pagecache-t.c: Pagecache callbacks support. storage/maria/unittest/ma_test_loghandler_purge-t.c: Fixed the test error processing. storage/maria/unittest/test_file.c: Removed unneeded sync.
77 lines
2 KiB
C
77 lines
2 KiB
C
#include <tap.h>
|
|
#include <my_sys.h>
|
|
#include <my_dir.h>
|
|
#include "test_file.h"
|
|
|
|
|
|
/*
|
|
Check that file contance correspond to descriptor
|
|
|
|
SYNOPSIS
|
|
test_file()
|
|
file File to test
|
|
file_name Path (and name) of file which is tested
|
|
size size of file
|
|
buff_size size of buffer which is enought to check the file
|
|
desc file descriptor to check with
|
|
|
|
RETURN
|
|
1 file if OK
|
|
0 error
|
|
*/
|
|
|
|
int test_file(PAGECACHE_FILE file, char *file_name,
|
|
off_t size, size_t buff_size, struct file_desc *desc)
|
|
{
|
|
MY_STAT stat_buff, *stat;
|
|
unsigned char *buffr= my_malloc(buff_size, MYF(0));
|
|
off_t pos= 0;
|
|
size_t byte;
|
|
int step= 0;
|
|
int res= 1; /* ok */
|
|
|
|
if ((stat= my_stat(file_name, &stat_buff, MYF(0))) == NULL)
|
|
{
|
|
diag("Can't stat() %s (errno: %d)\n", file_name, errno);
|
|
res= 0;
|
|
goto err;
|
|
}
|
|
if (stat->st_size != size)
|
|
{
|
|
diag("file %s size is %lu (should be %lu)\n",
|
|
file_name, (ulong) stat->st_size, (ulong) size);
|
|
res= 0; /* failed */
|
|
/* continue to get more information */
|
|
}
|
|
|
|
/* check content */
|
|
my_seek(file.file, 0, SEEK_SET, MYF(MY_WME));
|
|
while (desc[step].length != 0)
|
|
{
|
|
if (my_read(file.file, (char*)buffr, desc[step].length, MYF(0)) !=
|
|
desc[step].length)
|
|
{
|
|
diag("Can't read %u bytes from %s (file: %d errno: %d)\n",
|
|
(uint)desc[step].length, file_name, file.file, errno);
|
|
res= 0;
|
|
goto err;
|
|
}
|
|
for (byte= 0; byte < desc[step].length; byte++)
|
|
{
|
|
if (buffr[byte] != desc[step].content)
|
|
{
|
|
diag("content of %s mismatch 0x%x in position %lu instead of 0x%x\n",
|
|
file_name, (uint) buffr[byte], (ulong) (pos + byte),
|
|
desc[step].content);
|
|
res= 0;
|
|
goto err;
|
|
}
|
|
}
|
|
pos+= desc[step].length;
|
|
step++;
|
|
}
|
|
|
|
err:
|
|
my_free(buffr, 0);
|
|
return res;
|
|
}
|