📄 dio.c
字号:
{ if (alloc_table((void **) &task->cache->tag_table, (task->cache->max_tags + 3) * sizeof(PAGE_TAG), task->cache->max_tags * sizeof(PAGE_TAG), task) != S_OKAY) return (task->db_status); task->cache->max_tags += 3; /* arbitrary small value */ for (tag_ptr = &task->cache->tag_table[tag_idx]; tag_idx < task->cache->max_tags; ++tag_idx, ++tag_ptr) tag_ptr->lru_page = -1; } tag_ptr = &task->cache->tag_table[*tag]; tag_ptr->lru_page = 0; tag_ptr->num_pages = 0; tag_ptr->lookups = tag_ptr->hits = 0L; ++task->cache->num_tags; return (task->db_status);}/* ====================================================================== Free a page tag*/static void INTERNAL_FCN pgtag_free(short *tag, DB_TASK *task){ if (task->cache->tag_table) { if (*tag >= 0 && *tag < task->cache->max_tags) { task->cache->tag_table[*tag].lru_page = -1; if (--task->cache->num_tags == 0) { psp_freeMemory(task->cache->tag_table, 0); task->cache->tag_table = NULL; } return; } } dberr(SYS_INVPGTAG);}/* ====================================================================== Clear database page cache*/int INTERNAL_FCN dio_clrfile(FILE_NO fno, DB_TASK *task){ return clear_cache(fno, (FILE_NO)(fno+1), task);}int EXTERNAL_FCN dio_clear(int dbn, DB_TASK *task){ FILE_NO from, to; if (dbn == ALL_DBS) { from = 0; to = task->size_ft; } else { if (dbn == CURR_DB) dbn = task->curr_db; from = task->db_table[dbn].ft_offset; to = from + task->db_table[dbn].Size_ft; } return clear_cache(from, to, task);}/* called from: action: d_iclose clear all pages for db d_destroy clear all pages for db d_initfile clear all pages for file d_trabort clear all non-temporary modified pages d_lock clear all non-temporary, non-modifyable static pages*/static int INTERNAL_FCN clear_cache( FILE_NO fr_file, /* clear from file "fr_file" */ FILE_NO to_file, /* ... to (not thru) file "to_file" */ DB_TASK *task){ FILE_NO fno; PAGE_ENTRY *pg_ptr; PAGE_ENTRY *nxt_ptr; PGZERO *pgzero_ptr; FILE_ENTRY *file_ptr; for (fno = fr_file, pgzero_ptr = &task->pgzero[fno]; fno < to_file; fno++, pgzero_ptr++) { for (pg_ptr = pgzero_ptr->pg_ptr; pg_ptr; pg_ptr = nxt_ptr) { nxt_ptr = pg_ptr->n_pg; if (dio_clrpage(pg_ptr, task) != S_OKAY) return (task->db_status); } } /* clear page zeroes */ for (fno = fr_file, pgzero_ptr = &task->pgzero[fno], file_ptr = &task->file_table[fno]; fno < to_file; ++fno, ++pgzero_ptr, ++file_ptr) { pgzero_ptr->pz_next = (F_ADDR) 0; /* force it to be re-read */ if (pgzero_ptr->pz_modified && !(file_ptr->ft_flags & TEMPORARY)) { if (file_ptr->ft_status == OPEN) commit_file(file_ptr->ft_desc, task); } pgzero_ptr->pz_modified = FALSE; file_ptr->ft_flags &= ~NEEDS_COMMIT; } return (task->db_status);}/* ======================================================================*/void INTERNAL_FCN dio_ixclear(DB_TASK *task){ PAGE_ENTRY *ixpg_ptr; int x; for (x = task->cache->ix_pgtab.pgtab_sz, ixpg_ptr = task->cache->ix_pgtab.pg_table; x; --x, ++ixpg_ptr) { if (ixpg_ptr->file != -1) dio_clrpage(ixpg_ptr, task); }}/* ====================================================================== Flush database I/O buffer*/int EXTERNAL_FCN dio_flush(DB_TASK *task){ FILE_NO fno; FILE_ENTRY *file_ptr; PAGE_ENTRY *pg_ptr; PAGE_ENTRY *nxt_ptr; if (task->cache->db_pgtab.pg_table == NULL) return (task->db_status); for (fno = 0, file_ptr = task->file_table; fno < task->size_ft; ++fno, ++file_ptr) { if (file_ptr->ft_flags & TEMPORARY) continue; for (pg_ptr = task->pgzero[fno].pg_ptr; pg_ptr; pg_ptr = nxt_ptr) { nxt_ptr = pg_ptr->n_pg; if (! pg_ptr->modified) { pg_ptr->ovfl_addr = 0L; continue; } if ((task->dboptions & TRLOGGING) && task->trans_id[0] && (! task->trcommit)) { /* flush to overflow/log file -- before tr commit */ if (o_write(pg_ptr, task) != S_OKAY) return (task->db_status); if (pg_ptr->pageno > o_pages(pg_ptr->file, task)) { file_ptr->ft_flags |= NEEDS_COMMIT; /* no need to rewrite this page at task->trcommit time */ } else continue; /* skip call to trlog and reinit of holdcnt, modified */ } else { /* write directly to database */ pg_ptr->ovfl_addr = 0L; if (dio_out(pg_ptr, task) != S_OKAY) return (task->db_status); file_ptr->ft_flags |= NEEDS_COMMIT; } pg_ptr->holdcnt = 0; pg_ptr->modified = FALSE; if (task->trlog_flag) { dtrlog(fno, pg_ptr->pageno, pg_ptr->buff, file_ptr->ft_pgsize, task); } } } /* store the page zero values in the data file and return */ if (dio_pzflush(task) != S_OKAY) return (task->db_status); for (fno = 0, file_ptr = task->file_table; fno < task->size_ft; ++fno, ++file_ptr) { if (file_ptr->ft_flags & TEMPORARY) continue; if (file_ptr->ft_flags & NEEDS_COMMIT) { /* Commit the file even it was closed */ if ((file_ptr->ft_status != OPEN) && dio_open(fno, task) != S_OKAY) return (task->db_status); commit_file(file_ptr->ft_desc, task); file_ptr->ft_flags &= ~NEEDS_COMMIT; } } return (task->db_status);}/* ====================================================================== Database I/O page get for a key file.*/int EXTERNAL_FCN dio_get( FILE_NO fno, F_ADDR page_no, char **page_ptr, int hold, DB_TASK *task){ FILE_ENTRY *file_ptr = &task->file_table[fno]; PAGE_ENTRY *pg_ptr = NULL; if (task->dbopen == 1) { if (!task->app_locks[fno] && !task->excl_locks[fno] && !(file_ptr->ft_flags & STATIC)) { return (dberr(S_NOTLOCKED)); } } if ((task->pgzero[fno].pz_next == (F_ADDR) 0 && dio_pzread(fno, task) != S_OKAY)#ifdef DB_DEBUG || dio_pzcheck(fno, task) != S_OKAY#endif ) return (task->db_status); if (dio_getpg(fno, page_no, task->key_tag, &task->last_keypage, &pg_ptr, task) == S_OKAY) { if (pg_ptr == NULL || pg_ptr->buff == NULL) return (dberr(S_INVPTR)); *page_ptr = pg_ptr->buff; pg_ptr->recently_used = 1; if (hold) ++pg_ptr->holdcnt; } return (task->db_status);}/* ====================================================================== Set modified flag for a page for the key file*/int INTERNAL_FCN dio_touch( FILE_NO fno, F_ADDR page_no, int release, DB_TASK *task){ /* FILE_ENTRY *file_ptr = &task->file_table[fno]; */ PAGE_ENTRY *pg_ptr = NULL; if (task->trans_id[0] && o_fileinit(fno, task) != S_OKAY) return (task->db_status); if (task->dbopen == 1) { /* check shared access privileges */ if (!task->trans_id[0] && !task->excl_locks[fno]) return (dberr(S_NOTRANS)); if (task->app_locks[fno] >= 0 && !task->excl_locks[fno]) return (dberr(S_NOTLOCKED)); } if (dio_findpg(fno, page_no, &task->last_keypage, &pg_ptr, task) != S_OKAY) { /* changed page was lost if not previously marked modified */ dberr(S_FAULT); } else { pg_ptr->recently_used = 1; pg_ptr->modified = TRUE; if (release) { if (--(pg_ptr->holdcnt) < 0) dberr(SYS_INVHOLD); } } return (task->db_status);}/* ====================================================================== Release Hold obtained with dio_get on this key file page*/int EXTERNAL_FCN dio_unget( FILE_NO fno, F_ADDR page_no, int release, DB_TASK *task){ PAGE_ENTRY *pg_ptr = NULL; if (dio_findpg(fno, page_no, &task->last_keypage, &pg_ptr, task) != S_OKAY) { dberr(S_FAULT); } else { if (release) { if (--(pg_ptr->holdcnt) < 0) dberr(SYS_INVHOLD); } } return (task->db_status);}/* ====================================================================== Database I/O read*/int EXTERNAL_FCN dio_read( DB_ADDR dba, char **recptr, int hold, DB_TASK *task){ short file; int offset; DB_ULONG us1, us2; FILE_ENTRY *file_ptr; PAGE_ENTRY *pg_ptr = NULL; DECODE_DBA(dba, &file, &us1); file = NUM2INT(file, ft_offset); file_ptr = &task->file_table[file]; if ((task->pgzero[file].pz_next == (F_ADDR) 0 && dio_pzread(file, task) != S_OKAY)#ifdef DB_DEBUG || dio_pzcheck(file, task) != S_OKAY#endif ) return (task->db_status); if (task->dbopen == 1) { /* check shared access privileges */ if (!task->app_locks[file] && !task->excl_locks[file] && !(file_ptr->ft_flags & STATIC)) { return (dberr(S_NOTLOCKED)); } } us2 = (us1 - 1) / file_ptr->ft_slots; if (dio_getpg(file, us2 + 1, task->db_tag, &task->last_datapage, &pg_ptr, task) == S_OKAY) { if (pg_ptr->buff == NULL) return (dberr(S_INVPTR)); pg_ptr->recently_used = 1; offset = file_ptr->ft_slsize * (int) (us1 - 1 - us2 * file_ptr->ft_slots) + PGHDRSIZE; *recptr = &pg_ptr->buff[offset]; if (hold) ++(pg_ptr->holdcnt); } return (task->db_status);}/* ====================================================================== Database I/O write*/int EXTERNAL_FCN dio_write(DB_ADDR dba, int release, DB_TASK *task){ short file; DB_ULONG us1, us2; FILE_ENTRY *file_ptr; PAGE_ENTRY *pg_ptr = NULL; DECODE_DBA(dba, &file, &us1); file = (FILE_NO) NUM2INT(file, ft_offset); file_ptr = &task->file_table[file]; if (task->trans_id[0] && o_fileinit(file, task) != S_OKAY) return (task->db_status); if (task->dbopen == 1) { if (!task->trans_id[0] && !task->excl_locks[file]) return (dberr(S_NOTRANS)); /* check shared access priviledges */ if (task->app_locks[file] >= 0 && !task->excl_locks[file]) return (dberr(S_NOTLOCKED)); } us2 = (us1 - 1) / file_ptr->ft_slots; if (dio_findpg(file, us2 + 1, &task->last_datapage, &pg_ptr, task) != S_OKAY) { /* changed page was lost if not previously marked modified */ dberr(S_FAULT); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -