Tuesday, December 16, 2003

File Translation Lookaside Buffer


The flowchart from this morning has been expanded, and translates to the following pseudocode:

char* fs_seek(
pid_t process,
long fileHandle,
uint64_t spos) {
uint64_t fPageIdx;
uint64_t newPageIdx;
if (isReadOpen && spos > fileLen) {
sendEOF(process, fileHandle);
return NULL;
fPageIdx = spos / fPageSz; /*get what page we are seeking into*/
if (fPageIdx != currentPage) {
return (spos - (fPageIdx * fPageSz)) + ptrToPage (fileHandle, fPageIdx);
if (newPageIdx = findPgEntry(fileHandle, fPageIdx)) {
switchFpage(fileHandle, newPageIdx);
return (spos - (fPageIdx * fPageSz)) + ptrToPage(fileHandle, fPageIdx);
if (openForWrite && fPageIdx > fileLen / fPageSz) /*writing past EOF page*/
createBlankPage(fileHandle, fPageIdx);
getPageFromSvr(fileHandle, fPageIdx);
switchFpage(fileHandle, fPageIdx);
return (spos - (fPageIdx * fPageSz)) + ptrToPage(fileHandle, fPageIdx);

void switchFpage(
long fileHandle,
uint64_t fPageIdx) {
pid_t forkPid;
uint64_t oldpage = currentPage;
setCurrentPage(fileHandle, fPageIdx);
if (forkPid = fork()) {
if (pageAltered(fileHandle, oldPage)) {
flushPageToSvr(fileHandle, oldPage);

void getPageFromSvr(
long fileHandle,
uint64_t fPageIdx) {
struct fpage fpageent;
fpageent = getPageRemote(Server, fileHandle, fPageIdx);
if (isFullFTLB(fileHandle)) {
addToFTLB(fileHandle, fpageent);

You'll notice, the flowchart explains the logic of the buffering fairly well, while the pseudocode explains the logic of the implimentation (code) in more useful detail than the flowchart. It also *forces* me to take into account how I must structure functions. Anyway, point is, that's my pseudocode. I prefer pseudocode for programming, and flowcharts for processes. Why do I say this here? BECAUSE IN PROGRAMMING CLASS THEY FORCED US TO DIAGRAM OUR PROGRAMS WITH FLOWCHARTS. Think about it. A program of 10-15 lines, in 10-15 flowchart icons, sometimes more icons that lines of code (Program Start, Program End). Flowcharts should be used to figure out WHAT you're going to do, not HOW you're going to do it.

This page is powered by Blogger. Isn't yours?