/** * @brief 扩展一个文件的空间 * * @param [in/out] head : struct dbSysHead * * @param [in] fid : long 文件标识 * @param [in] extendPage : long 要扩展的页数 * @return int * * @author mengxi * @date 2015/10/20 **/ int extendFileSpace(struct dbSysHead *head, long fid, int extendPage) { long segmentAddr; struct Segment newSegment; struct Segment lastSegment; int allocStaPage; int i; int count; int nPage; int numPage; int idx; numPage = extendPage; allocStaPage = allocatePage(head, numPage); if (allocStaPage < 0) { printf("extendFileSpace error:out of disk space."); exit(0); } segmentAddr = getLastSegmentAddr(head, fid); getSegmentValue(head, segmentAddr, &lastSegment); if (lastSegment.count < PAGE_PER_SEGMENT) { nPage = (numPage < (PAGE_PER_SEGMENT - lastSegment.count)) ? numPage : (PAGE_PER_SEGMENT - lastSegment.count); count = lastSegment.count; for (i = 0; i<nPage; i++) { lastSegment.pageNo[count + i] = allocStaPage; allocStaPage++; } lastSegment.count += nPage; writeSegmentValue(head, segmentAddr, &lastSegment); numPage -= nPage; } if (numPage > 0) { while (numPage > 0) { nPage = (numPage < PAGE_PER_SEGMENT) ? numPage : PAGE_PER_SEGMENT; initSegment(&newSegment, allocStaPage, nPage, fid, segmentAddr, -1); allocStaPage += nPage; lastSegment.nextAddr = (head->desc).segmentAddr + (head->desc).segmentCur * sizeof(struct Segment); newSegment.preAddr = segmentAddr; writeSegmentValue(head, segmentAddr, &lastSegment); segmentAddr = lastSegment.nextAddr; (head->desc).segmentCur++; (head->desc).segmentNum++; lastSegment.count = newSegment.count; lastSegment.nextAddr = newSegment.nextAddr; lastSegment.preAddr = newSegment.preAddr; for (i = 0; i<newSegment.count; i++) { lastSegment.pageNo[i] = newSegment.pageNo[i]; } numPage -= nPage; } writeSegmentValue(head, segmentAddr, &newSegment); } idx = queryFileID(head, fid); head->desc.fileDesc[idx].filePageNum += extendPage; return 0; }
/** * @brief 创建一个文件,为它分配空间 * * @param [in/out] head : struct dbSysHead * * @return int * @retval 返回文件的标识号,即fid * * @author mengxi * @date 2015/10/20 **/ long creatFileSpace(struct dbSysHead *head) { struct Segment newSegment; long segmentAddr; long alloStaPage; int i; if ((head->desc).curFileNum >= MAX_FILE_NUM) { printf("creatFile Space error:total files cannot be more than %d.\n", (head->desc).curFileNum); return -1; } segmentAddr = (head->desc).segmentAddr + sizeof(struct Segment) * (head->desc).segmentCur; alloStaPage = allocatePage(head, PAGE_PER_SEGMENT); if (alloStaPage >= 0) { for (i = 0; i<MAX_FILE_NUM; i++) { if ((head->desc).fileDesc[i].fileID <= 0) { break; } } (head->desc).fileDesc[i].fileID = (head->desc).curfid; (head->desc).fileDesc[i].fileAddr = segmentAddr; (head->desc).fileDesc[i].filePageNum = PAGE_PER_SEGMENT; (head->desc).curFileNum++; initSegment(&newSegment, alloStaPage, PAGE_PER_SEGMENT, (head->desc).fileDesc[i].fileID, -1, -1); rewind(head->fpdesc); fseek(head->fpdesc, (head->desc).fileDesc[i].fileAddr, SEEK_SET); fwrite(&newSegment, sizeof(struct Segment), 1, head->fpdesc); (head->desc).segmentNum++; (head->desc).segmentCur++; (head->desc).curfid++; } else { printf("creatFileSpace error:creat error"); exit(0); } return (head->desc).fileDesc[i].fileID; }
void initializeRobot() { tHTIRS2DSPMode mode = DSP_1200; HTIRS2setDSPMode(IRSeeker, mode); servoChangeRate[blockDump] = 5; servo[blockDump] = BLOCK_SERVO_RETRACTED; servo[middleElev] = SERVO_STOPPED; lightStripInit(0x1F); displayRestingPulse(); /* * Work around the RobotC bug */ initSegment(dead_reckon_from_b3, 0, 0, -12, 100); initSegment(dead_reckon_from_b3, 1, -90, -24, 100); initSegment(dead_reckon_from_b3, 2, -90, 32, 100); initSegment(dead_reckon_from_b3, 2, 0, 0, 0); initSegment(dead_reckon_from_b2, 0, 0, -23, 100); initSegment(dead_reckon_from_b2, 1, -90, -24, 100); initSegment(dead_reckon_from_b2, 2, -90, -32, 100); initSegment(dead_reckon_from_b2, 2, 0, 0, 0); initSegment(dead_reckon_from_b1, 0, 0, -45, 100); initSegment(dead_reckon_from_b1, 1, -90, -24, 100); initSegment(dead_reckon_from_b1, 2, -90, -32, 100); initSegment(dead_reckon_from_b1, 2, 0, 0, 0); initSegment(dead_reckon_from_b0, 0, 0, -55, 100); initSegment(dead_reckon_from_b0, 1, -90, -24, 100); initSegment(dead_reckon_from_b0, 2, -90, -32, 100); initSegment(dead_reckon_from_b0, 2, 0, 0, 0); }