deleteFile(char* name) { char map[512]; char dir[512]; int i; int j; int sector; readSector(map, 1); readSector(dir, 2); for(i=0; i<512; i=i+0x20) { for (j=0; j<6; j++) { if(dir[i+j] != name[j]) goto continue_outer_loop; } dir[i] = 0x00; j = i+6; while (dir[j] != 0x00) { sector = dir[j++]; map[sector+1] = 0x00; } continue_outer_loop:; } writeSector(map, 1); writeSector(dir, 2); }
void MifarePlusSL3Commands::writeSectors(int start_sector, int stop_sector, const void* buf, size_t buflen, boost::shared_ptr<AccessInfo> aiToUse) { int i; size_t test_buflen = 0; size_t toWriteLen = 0; if (aiToUse) { boost::shared_ptr<MifarePlusAccessInfo> mAiToUse = boost::dynamic_pointer_cast<MifarePlusAccessInfo>(aiToUse); EXCEPTION_ASSERT(mAiToUse, std::invalid_argument, "aiToUse must be a MifarePlusAccessInfo."); for (i = start_sector; i < stop_sector; ++i) { test_buflen += getNbBlocks(i) * MIFARE_PLUS_BLOCK_SIZE; } if (test_buflen + MIFARE_PLUS_BLOCK_SIZE != buflen) throw EXCEPTION(std::invalid_argument, "Bad buffer parameter. The buffer must fit the sectors size."); test_buflen = 0; for (i = start_sector; i <= stop_sector && test_buflen < buflen; ++i) { toWriteLen = getNbBlocks(i) * MIFARE_PLUS_BLOCK_SIZE; if (toWriteLen + test_buflen > buflen) toWriteLen = buflen - test_buflen; if (mAiToUse->keyB && !mAiToUse->keyB->isEmpty()) writeSector(i, 0, reinterpret_cast<const char*>(buf) + test_buflen, toWriteLen, mAiToUse->keyB, KT_KEY_AES_B); else if (mAiToUse->keyA && !mAiToUse->keyA->isEmpty()) writeSector(i, 0, reinterpret_cast<const char*>(buf) + test_buflen, toWriteLen, mAiToUse->keyA, KT_KEY_AES_A); else throw EXCEPTION(std::invalid_argument, "You must set the writing key using the MifarePlusAccessInfo "); test_buflen += getNbBlocks(i) * MIFARE_PLUS_BLOCK_SIZE; } } }
//deleteFile method int deleteFile(char *fname){ char dirBuffer[512]; char diskmap[512]; struct directory *dir; int i = 0; int j = 0; dir = dirBuffer; readSector(dirBuffer,2); readSector(diskmap,1); for (i; i < 16; i++) { if(compare(fname,dir->entries[i].name) == 1){ for( j = 0; j < 26 ; j++){ if(dir->entries[i].sectors[j]!=0){ diskmap[ dir->entries[i].sectors[j] ] = 0; } } dir->entries[i].sectors[0] = 0x00; dir->entries[i].name[0] = 0x00; writeSector(diskmap,1); writeSector(dirBuffer,2); return 1; } } return -1; }
void deleteFile(char* name){ char directory[SECTORSIZE], map[SECTORSIZE]; int entry, matched; int sector, curSector; readSector(directory, DIRECTORYSECTOR); readSector(map, MAPSECTOR); for(entry=0; entry<MAXFILEENTRY; entry++){ matched = matchNames(name, directory+entry*FILEENTRYLENGTH, NAMELENGTH); if(matched == 1){ break; } } if(matched == 0){ return; } directory[entry*FILEENTRYLENGTH] = FILLERSECTOR; for(sector=0; sector<FILESECTORLENGTH; sector++){ curSector = *(directory+entry*FILEENTRYLENGTH+NAMELENGTH+sector); if(curSector != FILLERSECTOR){ map[curSector] = FILLERSECTOR; }else{ break; } } writeSector(directory, DIRECTORYSECTOR); writeSector(map, MAPSECTOR); return; }
void deleteFile(char * name){ char dir[512]; char map[512]; char index = 0; int i = 6; int sector; char tmp; readSector(dir, 2); readSector(map, 1); index = findFile(dir, name); if(index == 17){ printString("File not found!\n\0"); return; } dir[index*32] = 0x0; while(dir[(index*32) + i] != 0x0){ sector = dir[(index*32)+i]; map[sector] = 0x0; i++; } writeSector(dir, 2); writeSector(map, 1); }
/* deletes a file, and frees sectors */ void deleteFile(char* name) { char mapDir[512]; char diskDir[512]; char* diskPtr = diskDir; int i = 0; readSector(mapDir,1); readSector(diskDir,2); while (i < 16) { if(strcmp(name, diskPtr)) { *diskPtr = 0x0; diskPtr = diskPtr + 6; while (*diskPtr != 0x0) { mapDir[*diskPtr] = 0x0; diskPtr++; } writeSector(mapDir,1); writeSector(diskDir,2); return; } ++i; diskPtr = diskPtr + 32; } error(0); return; }
writeFile(char* name, char* buffer, int secNum) { char map[512]; char dir[512]; int i; int j; int k; int z; int remBytes; char data[512]; readSector(map, 1); readSector(dir, 2); for(i=0; i<512; i=i+0x20) { if (dir[i] != 0x00) { goto continue_outer_loop; } j = 0; k = i; while (name[j] != '\0') { dir[i++] = name[j++]; } z = i-k; if (z > 0) { while (z < 6) { dir[i++] = 0x00; z++; } } k = 0; z = 0; while (k < secNum) { while(z<512) { if (map[z] == 0x00) { map[z] = 0xff; break; } z++; } dir[i++] = z; for (j=0; j<512; j++) { data[j] = buffer[j+k*512]; } writeSector(data, z); k++; } remBytes = 26-secNum; for(j=0; j<remBytes; j++) { dir[i++] = 0x00; } break; continue_outer_loop:; } writeSector(map, 1); writeSector(dir, 2); }
void writeFile(char * name, char * buffer, int numberOfSectors){ char dir[512]; char map[512]; char tmpSect[512]; int dirNum = 0; int i = 0; int sectNum = 0; int k = 0; int iBuf = 0; readSector(dir, 2); readSector(map, 1); dirNum = findFreeDir(dir); if(dirNum >= 16){ return; } // Writing the name in directory while(name[i] != 0x0){ dir[dirNum*32+i] = name[i]; i++; } // Writing data and map for(i = 0; i <= numberOfSectors; i++){ // Locating free sector while(map[sectNum] != 0x0){ sectNum++; } if(i >= 16){ deleteFile(name); return; } printString(name); // Writing to map and directory map[sectNum] = 0xFF; writeSector(map, 0); dir[dirNum*32+6+i] = sectNum; // Writing the sector for(k = 0; k < 512; k++){ tmpSect[k] = buffer[iBuf]; iBuf++; } writeSector(tmpSect, sectNum); } // Filling the rest of the dir entry with 0x00 while(i<16){ dir[dirNum*32+6+i] = 0x0; i++; } writeSector(map, 1); writeSector(dir, 2); }
void writeFile(char* filename, char buffer[]) { char temp[512]; char dir[512]; char map[512]; int i ,k,j,m,l,p,start; char null=0x00; char LineFeed=0xa; i=0; j=0; start=0; interrupt(0x21,2,dir,2,0); while(i<16) { j=0; if( dir[start+j] == null) { while(j<6) { dir[start+j]=filename[j]; j++; } p=0; l=0; while(j<32) { while(map[p]!=null) { p++ ;} dir[start+j]=map[p]; m=dir[start+j]; for(k=0;k<512;k++) { temp[k]=buffer[k+l]; } writeSector(temp,m); j++; l+=512; } break; } start=start+32; i++; } writeSector(dir,2); writeSector(map,1); }
void writeFile(char* filename, char* contents, int numSectors){ char directory[SECTORSIZE], map[SECTORSIZE]; int entry, q, filenameEnd; int sector, sectorCount, currentChar; int remnants; readSector(directory, DIRECTORYSECTOR); readSector(map, MAPSECTOR); /*Find empty directory*/ for(entry=0; entry<MAXFILEENTRY; entry++){ if(directory[entry*FILEENTRYLENGTH] == FILLERSECTOR){ break; } } /*Write filename to directory*/ filenameEnd = 0; for(q=0; q<NAMELENGTH; q++){ if(filename[q] == '\0' || filename[q] == '\r' || filenameEnd){ filenameEnd = 1; directory[entry*FILEENTRYLENGTH+q] = FILLERSECTOR; }else{ directory[entry*FILEENTRYLENGTH+q] = filename[q]; } } /*Find and fill free sectors*/ sectorCount = 0; for(sector=DIRECTORYSECTOR+1; sector<SECTORSIZE && sectorCount<numSectors; sector++){ if(map[sector] != FILLERSECTOR){ map[sector] = FILLERSECTOR; directory[entry*FILEENTRYLENGTH+NAMELENGTH+sectorCount] = sector; writeSector(contents+sectorCount*SECTORSIZE, sector); sectorCount++; } } /*Zero remnants of entry*/ for(remnants=NAMELENGTH+sectorCount+1; remnants<FILEENTRYLENGTH; remnants++){ directory[entry*FILEENTRYLENGTH+remnants] = FILLERSECTOR; } writeSector(directory, DIRECTORYSECTOR); writeSector(map, MAPSECTOR); return; }
void handleInterrupt21(int ax, int bx, int cx, int dx){ switch(ax){ case 0: printString((char*) bx); break; case 1: readString((char*) bx); break; case 2: readSector((char*) bx, cx); break; case 3: readFile((char*) bx,(char *) cx); break; case 4: executeProgram((char*) bx, cx); break; case 5: terminate(); break; case 6: writeSector((char*) bx, cx); break; case 7: deleteFile((char*) bx); break; case 8: writeFile((char *) bx, (char*) cx, dx); break; case 9: listFile((char *) bx); break; } }
void deleteFile(char* c) { char map[512]; char dir[512]; int i = 0; char* base = c; int flag = 1; readSector(map , 1); readSector(dir , 2); while(i < 512) { int j = i; c = base; flag = 1; while(*c != 0x0) { if(*c != dir[j]) { flag = 0; break; } j++; c++; } if(flag == 1) break; i+=32; } dir[i] = 0x00; i+=6; while(dir[i] != 0x00) { map[dir[i]] = 0x00; i++; } writeSector(map , 1); writeSector(dir , 2); }
dword Archive::write( Handle * pHandle, const void * pBuffer, dword nBytes ) { if (! m_Open || !pHandle || !pBuffer || m_Access == READ ) return 0; dword nBytesWritten = 0; while( nBytesWritten < nBytes ) { dword remain = ARCHIVE_SECTOR_SIZE - pHandle->offset; // number of bytes remaing in buffer dword write = nBytes > remain ? remain : nBytes; // number of bytes to copy from this sector // copy the bytes memcpy( pHandle->buffer + pHandle->offset, pBuffer, write ); pHandle->modified = true; // advance the pointers pHandle->offset += write; pHandle->position += write; if ( pHandle->position > pHandle->size ) pHandle->size = pHandle->position; nBytesWritten += write; pBuffer = ((byte *)pBuffer) + write; // do we need to load the next sector if ( remain == write ) { lock(); // was the last sector modified if ( pHandle->modified ) { writeSector( pHandle ); pHandle->modified = false; } dword sector = pHandle->sector; dword nextSector = m_SectorMap[ sector ]; ASSERT( nextSector != SECTOR_FREE ); if ( nextSector == SECTOR_LAST ) { nextSector = allocateSector(); m_SectorMap[ sector ] = nextSector; } pHandle->sector = nextSector; pHandle->offset = 0; readSector( pHandle ); unlock(); } } return nBytesWritten; }
void deleteFile(char* filename) { int m,i,j,start; char map[512]; char dir[512]; readSector(map,1); readSector(dir,2); while(i<16) { j=0; while(j<6) { if( dir[start+j]!=filename[j]) { break; } j++; } if(j==6) { while(j<32) { m= dir[start+j] ; map[m]= 0x00; j++; } for(j=0;j<32;j++) { dir[start+j]=0x00; } break; } start=start+32; i++; } writeSector(dir,2); writeSector(map,1); }
dword Archive::read( Handle * pHandle, void * pBuffer, dword nBytes ) { if (! m_Open || !pHandle || !pBuffer ) return 0; dword nBytesRead = 0; while( nBytesRead < nBytes ) { dword nRemain = ARCHIVE_SECTOR_SIZE - pHandle->offset; // number of bytes remaing in buffer dword nRead = nBytes > nRemain ? nRemain :nBytes; // number of bytes to copy from this sector if ( (pHandle->position + nRead) > pHandle->size ) nRead = pHandle->size - pHandle->position; if ( nRead <= 0 ) break; // copy the bytes memcpy( pBuffer, pHandle->buffer + pHandle->offset, nRead ); // advance the pointers pHandle->offset += nRead; pHandle->position += nRead; nBytesRead += nRead; pBuffer = ((byte *)pBuffer) + nRead; // do we need to load the next sector if ( nRemain == nRead ) { lock(); // was the last sector modified if ( pHandle->modified ) { writeSector( pHandle ); pHandle->modified = false; } dword nextSector = m_SectorMap[ pHandle->sector ]; if ( nextSector == SECTOR_LAST ) break; // already at last sector??!! pHandle->sector = nextSector; pHandle->offset = 0; readSector( pHandle ); unlock(); } // continue reading from next sector if bytes > 0 } // done with read return nBytesRead; }
void deleteFile(char* name, int dirID) { int entryOffset, j; char directoryBuffer[SECTOR_SIZE]; char mapBuffer[SECTOR_SIZE]; /* int sectorPointer = 0; */ readSector(directoryBuffer, dirID); readSector(mapBuffer, MAP_SECTOR); entryOffset = searchDirectory(directoryBuffer, name); if (entryOffset < 0) { char errorMessage[]; errorMessage[0] = 'F'; errorMessage[1] = 'i'; errorMessage[2] = 'l'; errorMessage[3] = 'e'; errorMessage[4] = ' '; errorMessage[5] = 'n'; errorMessage[6] = 'o'; errorMessage[7] = 't'; errorMessage[8] = ' '; errorMessage[9] = 'f'; errorMessage[10] = 'o'; errorMessage[11] = 'u'; errorMessage[12] = 'n'; errorMessage[13] = 'd'; errorMessage[14] = '\0'; printString(errorMessage); return; } directoryBuffer[entryOffset] = 0; for (j = FILE_NAME_LENGTH; j < FILE_ENTRY_LENGTH; j++) { mapBuffer[directoryBuffer[entryOffset + j]] = 0; if (directoryBuffer[entryOffset + j] == 0) { break; } } writeSector(directoryBuffer, 2); writeSector(mapBuffer, 1); }
dword Archive::setPosition( Handle * pHandle, dword position ) { if (! m_Open || !pHandle ) return 0; if ( m_Access == READ && position >= pHandle->size ) return 0; // trying to set the position past the EOF on a read-only archive lock(); // is the current sector data modified, if so then flush the data to disk if ( pHandle->modified ) { writeSector( pHandle ); pHandle->modified = false; } // set the position pHandle->position = position; if ( position > pHandle->size ) pHandle->size = position; // set the correct sector and offset int fileIndex = file( pHandle->key ); if( fileIndex < 0 ) throw Failure(); dword sector = m_Files[ fileIndex ].sector; while( position > ARCHIVE_SECTOR_SIZE ) { dword nextSector = m_SectorMap[ sector ]; ASSERT( nextSector != SECTOR_FREE ); if ( nextSector == SECTOR_LAST ) { nextSector = allocateSector(); m_SectorMap[ sector ] = nextSector; } position -= ARCHIVE_SECTOR_SIZE; sector = nextSector; } pHandle->sector = sector; pHandle->offset = position; // read the sector data readSector( pHandle ); unlock(); return position; }
void handleInterrupt21(int ax, int bx, int cx, int dx) { if(ax==0) { printString(bx); } else if(ax==1) { readString(bx); } else if(ax==2) { readSector(bx,cx); } else if(ax==3) { directory(); } else if(ax==4) { deleteFile(bx); } else if(ax==5) { terminate(); } else if(ax==6) { readFile(bx,cx); } else if(ax==7) { writeSector(bx,cx); } else if(ax==8) { writeFile(bx,cx); } else if(ax==9) { executeProgram(bx); } else if(ax==10) { kill(bx); } else { printString("Invalid use of interrupt 21"); } }
void MifareCommands::setSectorToMAD(long aid, unsigned int sector, boost::shared_ptr<MifareKey> madKeyA, boost::shared_ptr<MifareKey> madKeyB) { MifareAccessInfo::SectorAccessBits sab; if (!madKeyA->isEmpty()) { getMifareChip()->getMifareProfile()->setKey(0, KT_KEY_A, madKeyA); getMifareChip()->getMifareProfile()->setKey(16, KT_KEY_A, madKeyA); } if (madKeyB->isEmpty()) { sab.setTransportConfiguration(); } else { getMifareChip()->getMifareProfile()->setKey(0, KT_KEY_B, madKeyB); getMifareChip()->getMifareProfile()->setKey(16, KT_KEY_B, madKeyB); sab.setAReadBWriteConfiguration(); } if (sector < 16) { if (sector == 0) { THROW_EXCEPTION_WITH_LOG(LibLogicalAccessException, "Can't make reference to the MAD itself."); } unsigned char madbuf[32]; memset(madbuf, 0x00, sizeof(madbuf)); if (readSector(0, 1, madbuf, sizeof(madbuf), sab) != sizeof(madbuf)) { THROW_EXCEPTION_WITH_LOG(LibLogicalAccessException, "Can't read the MAD."); } madbuf[(sector*2)] = aid & 0xff; madbuf[sector*2 + 1] = (aid & 0xff00) >> 8; if (madbuf[1] == 0x00) { madbuf[1] = static_cast<unsigned char>(sector); } madbuf[0] = calculateMADCrc(madbuf, sizeof(madbuf)); if (!writeSector(0, 1, madbuf, sizeof(madbuf), sab)) { THROW_EXCEPTION_WITH_LOG(LibLogicalAccessException, "Can't write the MAD."); } } else { if (sector == 16)
void handleInterrupt21(int ax, int bx, int cx, int dx){ int cur; switch(ax){ case 0x0: /*Print String*/ printString(bx); break; case 0x1: /*Read String*/ readString(bx); break; case 0x2: /*Read Sector*/ readSector(bx, cx); break; case 0x3: /*Read File*/ readFile(bx, cx); break; case 0x4: /*Execute Program*/ executeProgram(bx, NOONE); break; case 0x5: /*Terminate Program*/ terminate(); break; case 0x6: /*Write Sector*/ writeSector(bx, cx); break; case 0x7: /*Delete File*/ deleteFile(bx); break; case 0x8: /*Write File*/ writeFile(bx, cx, dx); break; case 0x9: /*Kill Process*/ killProcess(bx); break; case 0xa: /*Execute Program in Blocking Fashion*/ setKernelDataSegment(); cur = currentProcess; restoreDataSegment(); executeProgram(bx, cur); break; case 0xb: listProcesses(); break; case 0xc: editString(bx); break; default: printString("Interrupt21 got undefined ax."); break; } return; }
void MifareCommands::setSectorToMAD(long aid, unsigned int sector, std::shared_ptr<MifareKey> madKeyA, std::shared_ptr<MifareKey> madKeyB) { MifareAccessInfo::SectorAccessBits sab; if (!madKeyA->isEmpty()) { getMifareChip()->getMifareProfile()->setKey(0, KT_KEY_A, madKeyA); getMifareChip()->getMifareProfile()->setKey(16, KT_KEY_A, madKeyA); } if (madKeyB->isEmpty()) { sab.setTransportConfiguration(); } else { getMifareChip()->getMifareProfile()->setKey(0, KT_KEY_B, madKeyB); getMifareChip()->getMifareProfile()->setKey(16, KT_KEY_B, madKeyB); sab.setAReadBWriteConfiguration(); } if (sector < 16) { if (sector == 0) { THROW_EXCEPTION_WITH_LOG(LibLogicalAccessException, "Can't make reference to the MAD itself."); } std::vector<unsigned char> madbuf = readSector(0, 1, sab); if (!madbuf.size()) { THROW_EXCEPTION_WITH_LOG(LibLogicalAccessException, "Can't read the MAD."); } madbuf[(sector * 2)] = aid & 0xff; madbuf[sector * 2 + 1] = (aid & 0xff00) >> 8; if (madbuf[1] == 0x00) { // BCD Nibble representation madbuf[1] = static_cast<unsigned char>(sector % 10); if (sector >= 10) { madbuf[1] |= 0x10; } } madbuf[0] = calculateMADCrc(&madbuf[0], madbuf.size()); writeSector(0, 1, madbuf, sab); } else { if (sector == 16)
void handleInterrupt21(int ax, int bx, int cx, int dx){ if (ax == 0) { printString(bx); } else if (ax == 1) { readString(bx); } else if (ax == 2) { readSector(bx,cx); } else if(ax == 3){ readFile(bx,cx); }else{ if(ax ==4){ executeProgram(bx,cx); }else{ if(ax==5){ terminate(); }else{ if(ax==6){ writeSector(bx,cx); }else{ if(ax==7){ deleteFile(bx); }else{ if(ax == 8){ writeFile(bx,cx,dx); }else{ printString("ERROR !!!"); } } } } } } }
void deleteFile(char* name){ int i = 0; int j = 0;//number of records in directory int k = 0; // index in directory int p = 0;// parse each record int mapindex=0; char directory[512]; char map[512]; readSector(directory,2); readSector(map,1); while(j<16){ p = 0; k=j*32; while(p<6){ if(name[p]!=directory[k+p]) break ; p++; } if(p==6) directory[k]=0x00; while(p>=6){ mapindex=directory[k+p]-1; map[mapindex]=0x00; if(p==31) break; p++; } if(p==31) break; j++; } writeSector(map,1); writeSector(directory,2); }
// interrupt service routine to manage interrupt vector table void handleInterrupt21(int ax, int bx, int cx, int dx){ if (ax==0){ printString(bx); } else if (ax==1){ readString(bx); } else if (ax==2){ readSector(bx,cx); } else if (ax==3){ readFile(bx,cx,dx); } else if (ax==4){ runProgram(bx,cx); } else if (ax==5){ stop(); } else if (ax==6){ writeSector(bx,cx); } else if (ax==7) { deleteFile(bx); } else if (ax==8){ writeFile(bx,cx,dx); } else if (ax==11){ interrupt(25,0,0,0,0); } else if (ax==12){ clearScreen(bx,cx); } else if (ax==13){ writeInt(bx); } else if (ax==14){ ReadInt(bx); } else if (ax==15){ error(bx); } else if (ax==66){ printChar(bx); } else { printString("Incorrect service call\0"); } }
void handleInterrupt21(int ax, int bx, int cx, int dx){ switch(ax){ case 0: printString(bx); break; case 1: readString(bx); break; case 2: readSector(bx,cx); break; case 3: readFile(bx,cx);break; case 4: executeProgram(bx,cx);break; case 5: terminate(); case 6: writeSector(bx,cx);break; case 7: deleteFile(bx); case 8: writeFile(bx,cx,dx);break; default: printString("error"); break; } }
void handleInterrupt21(int ax, int bx, int cx, int dx) { if (ax == 0) { /* printString */ printString(bx); } else if (ax == 1) { if (cx == 0) { readStringAndReturnSize(bx); } else { *((int*)cx) = readStringAndReturnSize(bx); } } else if (ax == 2) { readSector(bx, cx); } else if (ax == 3) { readFile(bx, cx, ROOT_SECTOR); } else if (ax == 4) { runProgram(bx, ROOT_SECTOR); } else if (ax == 5) { terminate(); } else if (ax == 6) { writeSector(bx, cx); } else if (ax == 7) { deleteFile(bx, ROOT_SECTOR); } else if (ax == 8) { writeFile(bx, cx, dx, ROOT_SECTOR); } else if (ax == 9) { scanDirectory(bx, cx, dx); } else if (ax == 10) { killProcess(bx); } else if (ax == 11) { shellWait(runProgram(bx, ROOT_SECTOR)); } else if (ax == 12) { clear(); } else if (ax == 13) { printProcTable(); } else { char errorMsg[8]; errorMsg[0] = 'E'; errorMsg[1] = 'r'; errorMsg[2] = 'r'; errorMsg[3] = 'o'; errorMsg[4] = 'r'; errorMsg[5] = '!'; errorMsg[6] = '!'; errorMsg[7] = '\0'; printString(errorMsg); } }
// // Do read/write block request // Processes as many 512 byte sectors as are available in the queue // static Uns8 doCommand(virtqDescP queue, virtioBlkReqP blkReq, Uns32 *written) { assert(blkReq->type==VIRTIO_BLK_T_IN || blkReq->type==VIRTIO_BLK_T_OUT); Bool readCmd = (blkReq->type == VIRTIO_BLK_T_IN); Uns64 sector; *written = 0; for (sector=blkReq->sector; bytesAvailVirtq(queue, SECT_SIZE); sector++) { if (sector >= blkCfg->capacity) { bhmMessage( "W", PREFIX"_OOR", "%s past end of disk", readCmd ? "Read" : "Write" ); return VIRTIO_BLK_S_IOERR; } if (readCmd) { Uns8 status = readSector(queue, sector); if (status != VIRTIO_BLK_S_OK) return status; } else { Uns8 status = writeSector(queue, sector); if (status != VIRTIO_BLK_S_OK) return status; *written += SECT_SIZE; } if (DIAG_HIGH) { bhmMessage( "I", PREFIX"_DIO", "%d bytes at sector %s %s", SECT_SIZE, uns64ToString(sector), readCmd ? "Read" : "Written" ); } } return VIRTIO_BLK_S_OK; }
handleInterrupt21(int ax, int bx, int cx, int dx) { //printString("Hello World!\0"); //char *dgb = "AX = x\n"; //dgb[5] = '0' + ax; //printString(dgb); switch(ax) { case 0: printString(bx); break; case 1: readString(bx); break; case 2: readSector(bx, cx); break; case 3: readFile(bx, cx); break; case 4: executeProgram(bx, cx); break; case 5: terminate(); break; case 6: writeSector(bx, cx); break; case 7: deleteFile(bx); break; case 8: writeFile(bx, cx, dx); break; default: printString("Error!"); } }
void Archive::close( Handle * pHandle ) { ASSERT( m_Open && pHandle ); // decrement user count pHandle->users--; if ( pHandle->users > 0 ) return; lock(); int handleIndex = m_Handles.search( pHandle ); if ( handleIndex < 0 ) throw Failure(); // invalid handle was passed in, we didn't find it in our open file list // flush any written data if ( pHandle->modified ) { writeSector( pHandle ); // flush to disk any modified data pHandle->modified = false; } int fileIndex = file( pHandle->key ); if ( fileIndex < 0 ) throw Failure(); // update the file table File & closeFile = m_Files[ fileIndex ]; // update the table if ( pHandle->size != closeFile.size ) { closeFile.size = pHandle->size; // the size of the file has changed, update the table writeTable(); } // remove the handle m_Handles.remove( handleIndex ); // release the handle delete pHandle; unlock(); }
bool FsDevice::write(const Cache::ItemIdentity& ident, Cache::Item* data) { debug(FS_DEVICE, "write - CALL (ident addr=%x) (data addr=%x)\n", &ident, data); const SectorCacheIdent* sector_ident = static_cast<const SectorCacheIdent*>(&ident); // error wrong ItemIdent object if(sector_ident == NULL || data == NULL) { debug(FS_DEVICE, "write - ERROR invalid argument(s).\n"); return false; } debug(FS_DEVICE, "write - writing to sector=%x.\n", sector_ident->getSectorNumber()); debug(FS_DEVICE, "write - data to write=%x.\n", data->getData()); return writeSector(sector_ident->getSectorNumber(), static_cast<const char*>(data->getData()), sector_ident->getSectorSize()); }