int write_header(azio_stream *s) { char buffer[AZHEADER_SIZE + AZMETA_BUFFER_SIZE]; char *ptr= buffer; s->block_size= AZ_BUFSIZE_WRITE; s->version = (unsigned char)az_magic[1]; s->minor_version = (unsigned char)az_magic[2]; /* Write a very simple .az header: */ memset(buffer, 0, AZHEADER_SIZE + AZMETA_BUFFER_SIZE); *(ptr + AZ_MAGIC_POS)= az_magic[0]; *(ptr + AZ_VERSION_POS)= (unsigned char)s->version; *(ptr + AZ_MINOR_VERSION_POS)= (unsigned char)s->minor_version; *(ptr + AZ_BLOCK_POS)= (unsigned char)(s->block_size/1024); /* Reserved for block size */ *(ptr + AZ_STRATEGY_POS)= (unsigned char)Z_DEFAULT_STRATEGY; /* Compression Type */ int4store(ptr + AZ_FRM_POS, s->frm_start_pos); /* FRM Block */ int4store(ptr + AZ_FRM_LENGTH_POS, s->frm_length); /* FRM Block */ int4store(ptr + AZ_COMMENT_POS, s->comment_start_pos); /* COMMENT Block */ int4store(ptr + AZ_COMMENT_LENGTH_POS, s->comment_length); /* COMMENT Block */ int4store(ptr + AZ_META_POS, 0); /* Meta Block */ int4store(ptr + AZ_META_LENGTH_POS, 0); /* Meta Block */ int8store(ptr + AZ_START_POS, (unsigned long long)s->start); /* Start of Data Block Index Block */ int8store(ptr + AZ_ROW_POS, (unsigned long long)s->rows); /* Start of Data Block Index Block */ int8store(ptr + AZ_FLUSH_POS, (unsigned long long)s->forced_flushes); /* Start of Data Block Index Block */ int8store(ptr + AZ_CHECK_POS, (unsigned long long)s->check_point); /* Start of Data Block Index Block */ int8store(ptr + AZ_AUTOINCREMENT_POS, (unsigned long long)s->auto_increment); /* Start of Data Block Index Block */ int4store(ptr+ AZ_LONGEST_POS , s->longest_row); /* Longest row */ int4store(ptr+ AZ_SHORTEST_POS, s->shortest_row); /* Shorest row */ int4store(ptr+ AZ_FRM_POS, AZHEADER_SIZE + AZMETA_BUFFER_SIZE); /* FRM position */ *(ptr + AZ_DIRTY_POS)= (unsigned char)s->dirty; /* Start of Data Block Index Block */ /* Always begin at the begining, and end there as well */ return my_pwrite(s->file, (uchar*) buffer, AZHEADER_SIZE + AZMETA_BUFFER_SIZE, 0, MYF(MY_NABP)) ? 1 : 0; }
int _mi_decrement_open_count(MI_INFO *info) { char buff[2]; register MYISAM_SHARE *share=info->s; int lock_error=0,write_error=0; if (share->global_changed) { uint old_lock=info->lock_type; share->global_changed=0; lock_error=mi_lock_database(info,F_WRLCK); /* Its not fatal even if we couldn't get the lock ! */ if (share->state.open_count > 0) { share->state.open_count--; mi_int2store(buff,share->state.open_count); write_error=my_pwrite(share->kfile,buff,sizeof(buff), sizeof(share->state.header), MYF(MY_NABP)); } if (!lock_error) lock_error=mi_lock_database(info,old_lock); } return test(lock_error || write_error); }
int _mi_mark_file_changed(MI_INFO *info) { char buff[3]; register MYISAM_SHARE *share=info->s; if (!(share->state.changed & STATE_CHANGED) || ! share->global_changed) { share->state.changed|=(STATE_CHANGED | STATE_NOT_ANALYZED | STATE_NOT_OPTIMIZED_KEYS); if (!share->global_changed) { share->global_changed=1; share->state.open_count++; } if (!share->temporary) { mi_int2store(buff,share->state.open_count); buff[2]=1; /* Mark that it's changed */ return (my_pwrite(share->kfile,buff,sizeof(buff), sizeof(share->state.header), MYF(MY_NABP))); } } return 0; }
/* Check page's consistency: layout is 4 bytes: number 'num' of records in this page, then num occurences of { 4 bytes: record's length 'len'; then 4 bytes unchecked ('tag') then 'len' bytes each equal to the record's sequential number in this page, modulo 256 }, then zeroes. */ uint check_page(uchar *buff, ulong offset, int page_locked, int page_no, int tag) { uint end= sizeof(uint); uint num= uint4korr(buff); uint i; DBUG_ENTER("check_page"); for (i= 0; i < num; i++) { uint len= uint4korr(buff + end); uint j; end+= 4 + 4; if (len + end > TEST_PAGE_SIZE) { diag("incorrect field header #%u by offset %lu\n", i, offset + end); goto err; } for(j= 0; j < len; j++) { if (buff[end + j] != (uchar)((i+1) % 256)) { diag("incorrect %lu byte\n", offset + end + j); goto err; } } end+= len; } for(i= end; i < TEST_PAGE_SIZE; i++) { if (buff[i] != 0) { int h; DBUG_PRINT("err", ("byte %lu (%lu + %u), page %u (%s, end: %u, recs: %u, tag: %d) should be 0\n", offset + i, offset, i, page_no, (page_locked ? "locked" : "unlocked"), end, num, tag)); diag("byte %lu (%lu + %u), page %u (%s, end: %u, recs: %u, tag: %d) should be 0\n", offset + i, offset, i, page_no, (page_locked ? "locked" : "unlocked"), end, num, tag); h= my_open("wrong_page", O_CREAT | O_TRUNC | O_RDWR, MYF(0)); my_pwrite(h, (uchar*) buff, TEST_PAGE_SIZE, 0, MYF(0)); my_close(h, MYF(0)); goto err; } } DBUG_RETURN(end); err: DBUG_PRINT("err", ("try to flush")); if (page_locked) { pagecache_delete(&pagecache, &file1, page_no, PAGECACHE_LOCK_LEFT_WRITELOCKED, 1); } else { flush_pagecache_blocks(&pagecache, &file1, FLUSH_RELEASE); } exit(1); }