Ãëàâíàÿ Ðåôåðàòû ïî ðåêëàìå Ðåôåðàòû ïî ôèçèêå Ðåôåðàòû ïî ôèëîñîôèè Ðåôåðàòû ïî ôèíàíñàì Ðåôåðàòû ïî õèìèè Ðåôåðàòû ïî õîçÿéñòâåííîìó ïðàâó Ðåôåðàòû ïî öèôðîâûì óñòðîéñòâàì Ðåôåðàòû ïî ýêîëîãè÷åñêîìó ïðàâó Ðåôåðàòû ïî ýêîíîìèêî-ìàòåìàòè÷åñêîìó ìîäåëèðîâàíèþ Ðåôåðàòû ïî ýêîíîìè÷åñêîé ãåîãðàôèè Ðåôåðàòû ïî ýêîíîìè÷åñêîé òåîðèè Ðåôåðàòû ïî ýòèêå Ðåôåðàòû ïî þðèñïðóäåíöèè Ðåôåðàòû ïî ÿçûêîâåäåíèþ Ðåôåðàòû ïî þðèäè÷åñêèì íàóêàì Ðåôåðàòû ïî èñòîðèè Ðåôåðàòû ïî êîìïüþòåðíûì íàóêàì Ðåôåðàòû ïî ìåäèöèíñêèì íàóêàì Ðåôåðàòû ïî ôèíàíñîâûì íàóêàì Ðåôåðàòû ïî óïðàâëåí÷åñêèì íàóêàì ïñèõîëîãèÿ ïåäàãîãèêà Ïðîìûøëåííîñòü ïðîèçâîäñòâî Áèîëîãèÿ è õèìèÿ ßçûêîçíàíèå ôèëîëîãèÿ Èçäàòåëüñêîå äåëî è ïîëèãðàôèÿ Ðåôåðàòû ïî êðàåâåäåíèþ è ýòíîãðàôèè Ðåôåðàòû ïî ðåëèãèè è ìèôîëîãèè Ðåôåðàòû ïî ìåäèöèíå |
Äèïëîìíàÿ ðàáîòà: Ðîçðîáêà ïðîãðàìíîãî çàáåçïå÷åííÿ ôàéëîâîãî ìåíåäæåðàÄèïëîìíàÿ ðàáîòà: Ðîçðîáêà ïðîãðàìíîãî çàáåçïå÷åííÿ ôàéëîâîãî ìåíåäæåðàÇ̲ÑÒ ÂÑÒÓÏ 1 ÑÒÐÓÊÒÓÐÀ ÏÐÎÃÐÀÌÍÎÃÎ ÇÀÁÅÇÏÅ×ÅÍÍß ÔÀÉËÎÂÎÃÎ ÌÅÍÅÄÆÅÐÓ 2 ÑÒÐÓÊÒÓÐÀ ÄÀÍÈÕ 2.1 Ñòóêòóðè çàâàíòàæóâàëüíîãî çàïèñó 2.2 Ñòðóêòóðà ñëóæáîâî¿ îáëàñò³ FAT 2.3 Ñòðóêòóðà åëåìåíòà êàòàëîãó 2.4 Ïðîãðàìí ñòðóêòóðè 3 ÎÏÈÑ ÀËÃÎÐÈÒ̲ ÏÇ ÔÌ 3.1 Àëãîðèòì ïîøóêó äèñê³â é ³ìåíóâàííÿ äèñê³â 3.2 Àëãîðèòì äîñòóïó ê îá'ºêòàì ôàéëîâî¿ ñèñòåìè 3.3Àëãîðèòì âèçíà÷åííÿ çàéíÿòîãî ì³ñöÿ íà ðîçä³ë³ 3.4 Àëãîðèòì çð³âíÿííÿ äèðåêòîð³é 4 ÎÏÈÑ ÏÐÎÃÐÀÌÍÈÕ ÌÎÄÓ˲Â. 5 ÌÅÒÎÄÈÊÀ ÐÎÁÎÒÈ 6 ÄÎÑ˲ÄÆÅÍÍß ÐÅÇÓËÜÒÀҲ ÂÈÑÍÎÂÎÊ ÄÎÄÀÒÎÊ À - Êîä ïðîãðàìè ôàéëîâîãî ìåíåäæåðó ÂÑÒÓÏ Ìåòîþ äàíîãî ïðîåêòó º ïðàêòè÷íå äîñë³äæåííÿ òà çàñâîºííÿ ïðèéîì³â ðîáîòè ç äèñêîâèìè íàêîïè÷óâà÷àìè ó ñåðåäîâèù³ ÎÑ Windows òà ðîáîòè íà íèçüêîìó ð³âí³ ç ôàéëîâèìè ñèñòåìàìè FAT16/FAT32. Òàêîæ ï³äòðèìóºòüñÿ ðîáîòà ç NTFS. Ïðîãðàìà ðîçðîáëåíà ÿê WINDOWS ïðîãðàìà, íàïèñàíà ìîâîþ Ñ++. ²íòåðôåéñ ïðîãðàìè áóâ ðîçðîáëåíèé ñõîæèé äî ³ñíóþ÷èõ ôàéëîâèõ ìåíåäæåð³â ñåðåäîâèùà Microsoft Windows. 1. ÑÒÐÓÊÒÓÐÀ ÏÐÎÃÐÀÌÍÎÃÎ ÇÀÁÅÇÏÅ×ÅÍÍß ÔÀÉËÎÂÎÃÎ ÌÅÍÅÄÆÅÐÓ Ôàéëîâèé ìåíåäæåð – ïðîãðàìà, ÿêà âèêîíóº â³çóàë³çàö³þ âì³ñòó êàòàëîãó, äîçâîëÿº âèêîíóâàòè ð³çíîìàí³òí³ îïåðàö³¿ ç îá’ºêòàìè êàòàëîãó, íàïðèêëàä, êîï³þâàííÿ, âèäàëåííÿ, ïðàâêà òà ³íø³. Ôàéëîâèé ìåíåäæåð, ÿêèé áóâ ðîçðîáëåíèé çã³äíî ç çàâäàííÿì äî ïðîåêòó âèêîíóº íàñòóïí³ ôóíêö³¿: - ïîøóê ³ íàéìåíóâàííÿ âñ³õ ëîã³÷íèõ äèñê³â ó ìåæàõ äàíî¿ êîíô³ãóðàö³¿ òåõí³÷íèõ çàñîá³â; - âèçíà÷åííÿ õàðàêòåðèñòèê ëîã³÷íèõ äèñê³â; - ïîð³âíÿííÿ äèðåêòîð³é çà ê³ëüê³ñíèì ôàêòîì. Òàêîæ áóëà ðåàë³çîâàíà ï³äòðèìêà äîâãèõ ³ìåí òà êèðèëèö³ äëÿ îá’ºêò³â äèðåêòîð³é. Ñòðóêòóðà ôàéëîâîãî ìåíåäæåðó íà ðèñ. 1.1. Çã³äíî ç³ ñòðóêòóðîþ ôàéëîâèé ìåíåäæåð ìຠ³íòåðôåéñ, â ÿêîìó ìîæíà îáðàòè íàñòóïíó ä³þ. Ñïèñîê ä³é ïîêàçàíèé â ñòðóêòóð³ ÔÌ. Ïðîãðàìà áàãàòîìîäóëüíó ñòðóêòóðó. Êîæíèé ìîäóëü âèêîíóº ñâî¿ ôóíêö³¿. Êîæíà ä³ÿ, ÿêó ìîæíà âèêîíàòè, ðåàë³çîâàíà â îêðåì³é ôóíêö³¿. Âèêëþ÷åííÿ ³ç çàãàëüíîãî ïðàâèë ÿâëÿº ñîáîþ ìîäóëü manager.cpp, ÿêèé ðåàë³çóº ÿê ³íòåðôåéñ (çà ïðàâèëàìè ñòâîðåííÿ VCL) òàê ³ ðîáîòó ç NTFS òà ïîð³âíÿííÿ äèðåêòîð³¿. Òîìó íà ñòðóêòóðí³é ñõåì³ ïðîåêòó â³í çóñòð³÷àºòüñÿ äâ³÷³. Ïðè ñòàðò³ ïðîãðàìè ñïî÷àòêó ñòâîðþºòüñÿ ³íòåðôåéñ êîðèñòóâà÷à, âèêîíóºòüñÿ ïîøóê óñ³õ ëîã³÷íèõ äèñê³â â ìåæàõ äàíî¿ êîíô³ãóðàö³¿ òåõí³÷íèõ çàñîá³â, â³äáóâàºòüñÿ íàéìåíóâàííÿ óñ³õ çíàéäåíèõ äèñê³â. ϳñëÿ öüîãî îáèðàºòüñÿ çàâàíòàæóâàëüíèé äèñê òà ç÷èòóºòüñÿ êîðåíåâèé êàòàëîã öüîãî äèñêó. Âì³ñò êàòàëîãó ïîêàçóºòüñÿ íà åêðàí³. Äàë³ ïðîãðàìà î÷³êó íàñòóïíèõ âêàç³âîê êîðèñòóâà÷à ùîäî ïîäàëüøî¿ ä³ÿëüíîñò³. Ðèñóíîê 1.1 – Ñòðóêòóðà ÔÌ 2 ÑÒÐÓÊÒÓÐÀ ÄÀÍÈÕ Ó ïðîãðàì³ âèêîðèñòîâóþòüñÿ äåê³ëüêà ñòðóêòóð äàíèõ. Ñòðóêòóðè çàâàíòàæóâàëüíîãî çàïèñó, ñëóæáîâî¿ ÷àñòèíè ÔÑ òà åëåìåíòó êàòàëîãó – öå ñèñòåìí³ ñòðóêòóðè. Òàêîæ ïðîãðàìà ì³ñòèòü ³ âëàñí³ ñòðóêòóðè – ³íôîðìàö³ÿ ïðî ëîã³÷í³ äèñêè òà ³íø³. 2.1 Ñòðóêòóðè çàâàíòàæóâàëüíîãî çàïèñó ²íôîðìàö³ÿ ïðî ðîçä³ëè æîðñòêîãî äèñêó çáåð³ãàºòüñÿ ó ïåðøîìó ñåêòîð ïðèñòðîþ. Öå – ãîëîâíèé çàâàíòàæóâàëüíèé çàïèñ MBR (Master Boot Record). Ñòðóêòóðà MBR íàâåäåíà ó òàáë. 2.1. Òàáëèöÿ 2.1 - Ñòðóêòóðà MBR
Îäèí åëåìåíò Partition Table ìîæå âèçíà÷àòè ëîã³÷íèé äèñê àáî ðîçøèðåíèé ðîçä³ë. Ó ìåæàõ îäíîãî æîðñòêîãî äèñêà ìîæå áóòè ëèøå îäèí ðîçøèðåíèé ðîçä³ë. Çàïîâíåííÿ ïîë³â Partition Table âèêîíóºòüñÿ íà åòàï³ ðîçáèâàííÿ äèñêà íà ðîçä³ëè.  òàáë. 2.2 íàâåäåíà ñòðóêòóðà åëåìåíòó Partition Table. Òàáëèöÿ 2.2 - Ñòðóêòóðà åëåìåíòó Partition Table
Ïîëå êîä ñèñòåìè ì³ñòèòü ³íôîðìàö³þ ïðî òèï ÔÑ (îñíîâíèé ðîçä³ë) àáî ïðî îçíàêó ðîçøèðåíîãî ðîçä³ëó (05h, 0Fh). Îñíîâíèé ðîçä³ë îïèñóº ëîã³÷íèé äèñê, àäðåñó ïî÷àòêó ÿêîãî ìîæíà âçÿòè ç ñòðóêòóðè åëåìåíòó Partition Table – ïîëå startsector. Öå æ ïîëå ó åëåìåíò³ Partition Table ïðè îçíàö³ ðîçøèðåíîãî ðîçä³ëó âêàçóº íà âòîðèííó MBR. Öÿ MBR ìîæå ì³ñòèòè ìàêñèìóì äâà åëåìåíòè Partition Table ç ÷îòèðüîõ. Ïåðøèé åëåìåíò áóäå âêàçóâàòè íà ÷åðãîâèé ëîã³÷íèé äèñê, à äðóãèé – íà íàñòóïíó âòîðèííó MBR. Äëÿ îòðèìàííÿ àáñîëþòíî¿ àäðåñè ïî÷àòêó ëîã³÷íîãî äèñêà íåîáõ³äíî äî çíà÷åííÿ ïîëÿ startsector äîäàòè àäðåñó MBR, ó ÿê³é îïèñóºòüñÿ äàíèé äèñê. 2.2 Ñòðóêòóðà ñëóæáîâî îáëàñò³ FAT ϳñëÿ îòðèìàííÿ àáñîëþòíî¿ àäðåñè ïî÷àòêó ëîã³÷íîãî äèñêà â ïðîãðàì âèêîíóºòüñÿ ç÷èòóâàííÿ ïåðøîãî ñåêòîðà äèñêà.  ñèñòåì³ FAT öå çàâàíòàæóâàëüíà îáëàñòü (BOOT – îáëàñòü). BOOT – îáëàñòü ì³ñòèòü ïàðàìåòðè òà õàðàêòåðèñòèêè ëîã³÷íîãî äèñêà. ¯¿ ñòðóêòóðà äëÿ ÔÑ FAT12 òà FAT16 íàâåäåíà ó òàáë. 2.3, à äëÿ ñèñòåìè FAT32 – ó òàáë. 2.4. Òàáëèöÿ 2.3 – Ñòðóêòóðà BOOT – ñåêòîðó äëÿ FAT12 òà FAT16
Òàáëèöÿ 2.4 – Ñòðóêòóðà BOOT – ñåêòîðó äëÿ FAT32
Äàíà ñòðóêòóðà äîçâîëÿº îòðèìàòè äîñòóï äî ³íôîðìàö³éíèõ ïîë³â BOOT-ñåêòîðà íåîáõ³äíîãî ëîã³÷íîãî äèñêà. BOOT-îáëàñòü â ôàéëîâèõ ñèñòåìàõ FAT12,16 çàéìà 1 ñåêòîð, à â ÔÑ FAT32 – 3 ñåêòîðè. Äðóãèé ñåêòîð ì³ñòèòü äîäàòêîâ ïàðàìåòðè òà ñèãíàòóðè, à òðåò³é – ïðîäîâæåííÿ ïðîãðàìè çàâàíòàæåííÿ. Çà çàâàíòàæóâàëüíîþ îáëàñòþ ðîçòàøîâàí³ òàáëèö³ FAT òàáëèö³ êëàñòåð³â. ¯õ ê³ëüê³ñòü âèçíà÷àºòüñÿ ó BOOT-ñåêòîð³. Ó ôàéëîâèõ ñèñòåìàõ FAT12,16 çà òàáëèöÿìè êëàñòåð³â çíàõîäèòüñÿ êîðåíåâèé êàòàëîã. Éîãî ðîçì³ð îáìåæåíèé ê³ëüê³ñòþ åëåìåíò³â, âêàçàíèõ â BOOT-ñåêòîð³. Êîðåíåâèé êàòàëîã FAT32 ìîæå íå ðîçì³ùàòèñÿ â³äðàçó æ çà òàáëèöÿìè êëàñòåð³â òà íå ìຠìåæ ùîäî ñâîãî ðîçì³ðó. Çà âñ³ìà öèìè ñëóæáîâèìè îáëàñòÿìè çíàõîäèòüñÿ îáëàñòü äàíèõ. Òàáëèöÿ FAT ì³ñòèòü ³íôîðìàö³þ ïðî ðîçïîä³ëåííÿ äèñêîâîãî ïðîñòîðó ï³ä îá’ºêòè ÔÑ. Öÿ òàáëèöÿ – ìàñèâ åëåìåíò³â ³ç ðîçì³ðí³ñòþ 12, 16 àáî 32 á³òè â çàëåæíîñò³ â³ä âåðñ³¿ ÔÑ. Íîìåð åëåìåíòó òàáëèö³ FAT â³äïîâ³äຠíîìåðó êëàñòåðà â îáëàñò³ äàíèõ. Ó òàáëèö³ 2.5 íàâåäåí ìîæëèâ³ çíà÷åííÿ îäíîãî åëåìåíòó FAT. Òàáëèöÿ 2.5 – Çíà÷åííÿ åëåìåíòó FAT
Óñ³ ³íø³ çíà÷åííÿ âêàçóþòü íà íàñòóïíèé êëàñòåð. Ïîñë³äîâí³ñòü êëàñòåð³â, ÿêà ìîæå íàëåæàòè îäíîìó îá’ºêòó â òàáëèö³ ÔÀÒ, ïðåäñòàâëÿº ñîáîþ îäíîñïðÿìîâàíèé ñïèñîê, ãîëîâà ÿêîãî â ÿâíîìó âèä³ â³äñóòíÿ, à ê³íåöü âèçíà÷àºòüñÿ îçíàêîþ ê³íöÿ ëàíöþæêà. 2.3 Ñòðóêòóðà åëåìåíòà êàòàëîãó Êîæåí êàòàëîã ïðåäñòàâëÿº ñîáîþ ïîñë³äîâí³ñòü äåñêðèïòîð³â. Ñòðóêòóðà äåñêðèïòîðà îá’ºêòà ç êîðîòêèì ³ì’ÿì íàâåäåíà ó òàáë. 2.6 äëÿ FAT13/FAT16 òà ó òàáë. 2.8 äëÿ FAT32. Ñòðóêòóðà áàéòó àòðèáóòó ó òàáë. 2.7. Òàáëèöÿ 2.6 – Ñòðóêòóðà äåñêðèïòîðà äëÿ FAT12 / FAT16
Òàáëèöÿ 2.7 – Áàéò àòðèáóò³â îá’ºêòà
Òàáëèöÿ 2.8 – Ñòðóêòóðà äåñêðèïòîðà äëÿ FAT32
ßêùî îá’ºêò ³ìåíóºòüñÿ äîâãèì ³ì’ÿì, òî ï³ä íüîãî âèä³ëÿºòüñÿ äåê³ëüêà äåñêðèïòîð³â ñòàíäàðòíîãî ðîçì³ðó (32á). ʳëüê³ñòü äåñêðèïòîð³â âèçíà÷àºòüñÿ äîâæèíîþ ³ìåí³ îá’ºêòà. Ìàêñèìàëüíà äîâæèíà ³ìåí³ îá’ºêòà – 255 ñèìâîë³â, ÿê çáåð³ãàþòüñÿ â ôîðìàò³ UNICODE (ïî äâà áàéòè íà îäèí ñèìâîë). Ó êîæíîìó äåñêðèïòîðó ìîæå çáåð³ãàòèñÿ 13 ñèìâîë³â ³ìåí³ îá’ºêòó. Ñòðóêòóðà äåñêðèïòîðà äëÿ äîâãîãî ³ìåí³ íàâåäåíà ó òàáë. 2.9. Òàáëèöÿ 2.9 – Ñòðóêòóðà äåñêðèïòîðà äëÿ äîâãîãî ³ìåí³
²ì’ÿ â îñòàíí³é ïîðö³¿ äîâãîãî ³ìåí³ ìîæå áóòè ìåíøèì çà 13 ñèìâîë³â. Ó òàêîìó âèïàäêó çíà÷èìà ÷àñòèíà ³ìåí³ çàâåðøóºòüñÿ íóëåì. óñ³ ³íø³ ïîëÿ ³ìåí çàïîâíþþòüñÿ FFFF. Âñ³ íåîáõ³äí³ ïðîãðàìí³ ñòðóêòóðè ïðåäñòàâëåí³ â header- ôàéëàõ. Ö³ëü ¿õíüîãî ñòâîðåííÿ - îðãàí³çàö³ÿ äàíèõ, ïðî÷èòàíèõ ç íîñ³¿â. Íàïðèêëàä, êîæíèé æîðñòêèé äèñê áóäå ïðåäñòàâëåíèé ñòðóêòóðîþ typedef struct _HARDINFO { char nHard; //íîìåð æîðñòêîãî äèñêó void* hDrive; //õåíäë æîðñòêîãî äèñêó UINT dwSectorSize; //ðîçì³ð ñåêòîðà UINT bitsPerSector; //ê³ëüê³ñòü ðîçðÿä³â äëÿ àäðåñàö³¿ âñåðåäèí³ ñåêòîðà UINT dwExtendedAddr; //àäðåñà ðîçøèðåíîãî ðîçä³ëó PLOGICAL_DISC disklist; } HARDINFO, *PHARDINFO; ²íôîðìàö³ÿ ïðî ðîçä³ëè îðãàí³çóºòüñÿ â ñïèñîê ñòðóêòóð, ïî îäíîìó ñïèñêó íà êîæíèé æîðñòêèé äèñê: typedef struct _LOGICAL_DISC { void* next; char nHard; char nDisc; char active; UINT abs_addr; UINT secLength; UINT id; char* cpFS; UINT SN4; UINT gbLength; UINT mbLength;
void* disc_info; UINT prcfree; } LOGICAL_DISC, *PLOGICAL_DISC, **PPLOGICAL_DISC; ϳñëÿ òîãî, ÿê FAT32-ðîçä³ë áóâ â³äêðèòèé äëÿ ÷èòàííÿ, ³íôîðìàö³ÿ ïðî íüîãî çàïèñóºòüñÿ â òàêó ñòðóêòóðó typedef struct _DISC_INFO { char Disc; //ëîã³÷íèé äèñê UINT beginFAT; //àäðåñà ïî÷àòêó FAT-òàáëèö³ ó ñåêòîðàõ UINT nBytePerSector; //ðîçì³ð ñåêòîðà ó áàéòàõ void* hDrive; //õåíäë â³äêðèòîãî ðîçä³ëó char SectPerCluster; //ðîçì³ð êëàñòåðà â ñåêòîðàõ UINT BytesPerCluster; //ðîçì³ð êëàñòåðà â áàéòàõ UINT sizeFAT; //ðîçì³ð FAT-òàáëèö â ñåêòîðàõ UINT* pFAT; //àäðåñà îáðàçó FAT-òàáëèö³ ó ÎÇÓ UINT sizeFATbytes; //ðîçì³ð FAT-òàáëèö³ â áàéòàõ USHORT nFATCopy; //ê³ëüê³ñòü êîï³é FAT USHORT sizeReserved; //ðîçì³ð çàðåçåðâîâàíî¿ îáëàñò³ â ñåêòîðàõ UINT bitsPerSector; //ê³ëüê³ñòü ðîçðÿä³â äëÿ àäðåñàö³¿ âñåðåäèí³ ñåêòîðà UINT RootCluster; //íîìåð ïåðøîãî êëàñòåðà êîðíåâîé äèðåêòîðèè UINT dwRootDirSize; //ê³ëüê³ñòü êëàñòåð³â äëÿ êîðåíåâî¿ äèðåêòî𳿠HDIR hRootDir; //õåíäë êîðåíåâî äèðåêòîð賿 UINT prcfree; BOOL bFAT16; UINT RootSector; UINT nRootElements; } DISC_INFO, *PDISC_INFO; Ñïèñîê ïðî÷èòàíèõ ôàéë³â îðãàí³çóºòüñÿ â ñòðóêòóðó: typedef struct _FILES { char* ansiname; UINT attrib; UINT firstcluster; __int64 filesize; void* next; } FILES, *PFILES; ßêùî íåîáõ³äíî âèâåñòè íà åêðàí óì³ñò ôàéëó, ñïî÷àòêó éîãî âì³ñò áóäå â³äîáðàæåíî â òàêó ñòðóêòóðó: typedef struct _FILEBUF { char* pBuf; char* ansiname; UINT dwLen; } FILEBUF, *PFILEBUF; 3 ÎÏÈÑ ÀËÃÎÐÈÒ̲ ÏÇ ÔÌ Ó öüîìó ïóíêò³ ðîçãëÿäàþòüñÿ ïîñë³äîâíî àëãîðèòìè ïîøóêó òà ³ìåíóâàííÿ äèñê³â, äîñòóïó äî îá’ºêò³â ôàéëîâî¿ ñèñòåìè, âèçíà÷åííÿ çàéíÿòîãî ì³ñöÿ äëÿ ôàéëîâî¿ ñèñòåìè FAT32, FAT16. 3.1 Àëãîðèòì ïîøóêó äèñê³â é ³ìåíóâàííÿ äèñê³â Àëãîðèòì ³ìåíóâàííÿ ëîã³÷íèõ äèñê³â çàñíîâàíî íà çâ³ðåíí³ ñåð³éíîãî íîìåðà, îòðèìàíîãî ëîã³÷íîãî äèñêà ³ç ñåð³éíèì íîìåðîì, çáåðåæåíèì ñèñòåìîþ. Ðèñóíîê 3.1 – Ïîøóê òà íàéìåíóâàííÿ äèñê³â 3.2 Àëãîðèòì äîñòóïó ê îá’ºêòàì ôàéëîâî¿ ñèñòåìè Îñíîâíà êîíöåïö³ÿ ôàéëîâî¿ ñèñòåìè FAT ïîëÿãຠâ ò³ì, ùî êîæíîìó ôàéëó é êàòàëîãó âèä³ëÿºòüñÿ ñòðóêòóðà äàíèõ, íàçèâàíà äåñêðèïòîðîì. Ó ö³é ñòðóêòóð çáåð³ãàºòüñÿ ³ì'ÿ ôàéëó, éîãî ðîçì³ð, ïî÷àòêîâà àäðåñà âì³ñòó ôàéëó é ³íø ìåòàäàí³. Äàíí³ ôàéë³â ³ êàòàëîã³â çáåð³ãàºòüñÿ â áëîêàõ äàíèõ, íàçèâàíèõ êëàñòåðàìè. ßêùî ôàéëó àáî êàòàëîãó âèä³ëÿºòüñÿ á³ëüø îäíîãî êëàñòåðà, ³íø êëàñòåðè çíàõîäÿòü çà äîïîìîãîþ ñòðóêòóðè äàíèõ, íàçèâàíî¿ FAT(File Allocation Table). Ñòðóêòóðà FAT âèêîðèñòîâóºòüñÿ ÿê äëÿ ³äåíòèô³êàö³¿ íàñòóïíèõ êëàñòåð³â ó ôàéëàõ, òàê ³ äëÿ âèçíà÷åííÿ ñòàíó êëàñòåð³â. ²ñíóº òðè âåðñ³¿ FAT: FAT12, FAT16 ³ FAT32. Âîíè â³äð³çíÿþòüñÿ äðóã â³ä äðóãà íàñàìïåðåä ðîçì³ðîì çàïèñó ó ñòðóêòóð³ FAT. Çâ'ÿçêè ì³æ ñòðóêòóðàìè äàíèõ ïîêàçàíî íà ðèñ. 3.4. Ðèñóíîê 3.4 – Çâ’ÿçêè ì³æ ñòðóêòóðàìè äàíèõ Ôàéëîâà ñèñòåìà FAT ä³ëèòüñÿ íà òðè ô³çè÷í³ îáëàñò³ äëÿ FAT32, òà íà ÷îòèðè äëÿ FAT12/16. Ïåðøà îáëàñòü íàçèâàºòüñÿ çàðåçåðâîâàíîþ; â FAT12 ³ FAT16 çàðåçåðâîâàíà îáëàñòü çàéìຠâñüîãî 1 ñåêòîð, àëå ôîðìàëüíî ¿¿ ðîçì³ð âèçíà÷àºòüñÿ â çàâàíòàæóâàëüíîìó ñåêòîð³. Äðóãà îáëàñòü FAT - ì³ñòèòü îñíîâí³ é ðåçåðâí³ ñòðóêòóðè FAT. Âîíà ïî÷èíàºòüñÿ â ñåêòîð³, êîòðèé ðîçòàøîâàíî çà çàðåçåðâîâàíîþ îáëàñòþ, à ¿¿ ðîçì³ð âèçíà÷àºòüñÿ ê³ëüê³ñòþ é ðîçì³ðîì ñòðóêòóð FAT. Òðåòÿ – êîðåíåâèé êàòàëîã, äëÿ FAT12/16 ïî÷èíàºòüñÿ çà îáëàñòþ FAT, à ó FAT32 ìà ïîâ³ëüíå ïîëîæåííÿ ó îáëàñò³ äàíèõ. Îáëàñòü äàíèõ - ì³ñòèòü êëàñòåðè, âèä³ëåí äëÿ çáåð³ãàííÿ ôàéë³â ³ âì³ñòó êàòàëîã³â. Äîñòóï äî ôàéëîâèõ îá’ºêò³â âèêîíóºòüñÿ ç ïðèïóùåííÿ, ùî â³äîìà àäðåñà ïåðøîãî êëàñòåðó îá’ºêòó. Ó äàí³é ðåàë³çàö³¿ àëãîðèòì äîñòóïó äî îá’ºêò³â ì³ñòèòü äâ³ ÷àñòèíè àëãîðèòì ïîøóêó øëÿõó äî ïîòî÷íî¿ äèðåêòî𳿠òà àëãîðèòì ïîøóêó îá’ºêò³â ó çàâàíòàæåí³é äèðåêòîð³¿. Àëãîðèòì ïîøóêó îá’ºêò³â â êàòàëîã³ íàâåäåíî íà ðèñ. 3.2 Àëãîðèòì ïîøóêó ïîòî÷íîãî øëÿõó - ðèñ.3.3 Ðèñóíîê 3.2 – Àëãîðèòì ïîøóêó îá’ºêò³â â êàòàëîã³ Ðèñóíîê 3.3 – Àëãîðèòì ïîøóêó ïîòî÷íîãî øëÿõó 3.3 Àëãîðèòì âèçíà÷åííÿ çàéíÿòîãî ì³ñöÿ íà ðîçä³ë³ Âèçíà÷åííÿ çàéíÿòîãî ì³ñöÿ íà ðîçä³ë³ ðåàë³çóºòüñÿ øëÿõîì àíàë³çó òàáëèö FAT. Âèêîíóºòüñÿ ïåðåâ³ðêà óñ³õ åëåìåíò³â òàáëèö³ FAT. Ðàõóºòüñÿ ê³ëüê³ñòü åëåìåíò³â, ùî ì³ñòÿòü 0. Ö³ åëåìåíòè â ôàéëîâ³é ñèñòåì³ ³äåíòèô³êóþòü íåçàéíÿòå ì³ñöå. Îòæå, ï³ñëÿ ïîâíîãî ïåðåãëÿäó FAT òàáëèö³ â³äîìà ê³ëüê³ñòü åëåìåíò³â FAT òàáëèö³ òà ê³ëüê³ñòü åëåìåíò³â íåçàéíÿòîãî ì³ñöÿ. Çíàõîäèòüñÿ â³äñîòêîâå ñï³ââ³äíîøåííÿ. ×åðåç íüîãî îá÷èñëþºòüñÿ çàéíÿòå ì³ñöå â áàéòàõ. Àëãîðèòì âèçíà÷åííÿ íà ðèñ. 3.4. Ðèñóíîê 3.4 – Àëãîðèòì âèçíà÷åííÿ çàéíÿòîãî ì³ñöÿ 3.4 Àëãîðèòì çð³âíÿííÿ äèðåêòîð³é Ðèñóíîê 3.5 – Àëãîðèòì çð³âíÿííÿ äèðåêòîð³é 4 ÎÏÈÑ ÏÐÎÃÐÀÌÍÈÕ ÌÎÄÓ˲ Òî÷êà âõîäó çíàõîäèòüñÿ ó ìîäóë³ ç íàçâîþ manager.cpp. ϳñëÿ àâòîìàòè÷íî¿ ³í³ö³àë³çàö³¿ ãðàô³÷íîãî ³íòåðôåéñó (âñå öå â³äáóâàºòüñÿ çà ðàõóíîê VCL), âèêîíóºòüñÿ ïîøóê ³ ³ìåíóâàííÿ âñ³õ ëîã³÷íèõ äèñê³â. Êîä, â³äïîâ³äàëüíèé çà öå, çíàõîäèòüñÿ â ìîäóë³ mbrmodule.cpp. Äàë³, ÿêùî çíàéäåíî çàâàíòàæóâàëüíèé ðîçä³ë , ÿêùî ôàéëîâà ñèñòåìà íà íüîìó º îäí³ºþ ç ï³äòðèìóâàíèõ, âèêîíóºòüñÿ ïîøóê óñ³õ ôàéë³â ó êîðåíåâîìó êàòàëîç³. ßêùî ôàéëîâà ñèñòåìà ðîçä³ëó - FAT àáî FAT32 òî ðîáèòüñÿ öå çà äîïîìîãîþ ìîäóëÿ fat32.cpp. ßêùî ôàéëîâà ñèñòåìà – NTFS, òî ïîøóê âèêîíóºòüñÿ íåâåëèêèìè ôóíêö³ÿìè, îïèñàíèìè, áåçïîñåðåäíüî, ó ãîëîâíîìó ìîäóë³ (manager.cpp, íà òàêó ñòðóêòóðó âæå íàãîëîøóâàëîñÿ ðàí³øå). ²íø³ ôàéëîâ³ ñèñòåìè íå ï³äòðèìóþòüñÿ. Êîðîòêèé îïèñ êëþ÷îâèõ ôóíêö³é: PHARDINFO Init(char n); Ôóíêö³ÿ âèêîíóº âñ³ ïîïåðåäí³ ä³¿, íåîáõ³äí³ äëÿ ïîäàëüøî¿ ðîáîòè ç æîðñòêèì äèñêîì(âèêëèê CreateF³le(), âèçíà÷åííÿ ðîçì³ðó ñåêòîðà é ò.ä.). Ó âèïàäêó íåâäà÷³ ïîâåðòຠNULL. BOOL WalkOnMBR(PHARDINFO inf, PPLOGICAL_DISC first); Ôóíêö³ÿ ïðîõîäèòü ïî ëàíöþæêó MBR æîðñòêîãî äèñêà, ïîïåðåäíüî â³äêðèòîãî ôóíêö³ºþ ²n³t void DeInit(PHARDINFO inf); Çâ³ëüíÿº çàéíÿòó ñòðóêòóðàìè ïàì'ÿòü ³ çàêðèâຠäåñêðèïòîð æîðñòêîãî äèñêà PDISC_INFO Fat32Init(char disc); Âèêîíóº âñ³ íåîáõ³äí³ ïîïåðåäí³ ä³¿ äëÿ ðîáîòè ç ëîã³÷íèì äèñêîì, ôàéëîâà ñèñòåìà êîòðîãî FAT àáî FAT32 (ç÷èòóâàííÿ òàáëèö³ FAT, âèçíà÷åííÿ êëàñòåðà êîðåíåâîãî êàòàëîãó òà ³í.) UINT GotoDir(PDISC_INFO info, char* cpPath); Ïîâåðòຠíîìåð êëàñòåðà âèõîäÿ÷è ç³ øëÿõó äî äèðåêòî𳿠UINT ListDirectory(PDISC_INFO info, HDIR hDir,UINT dwDirSize,char* cpObjectName, PFILES* ppfiles); Âèêîíóº ïîáóäîâà ñïèñêó ôàéë³â ó äèðåêòî𳿠àáî ïîøóê åëåìåíòà êàòàëîãó â í³é. PFILES PrintRootDirectory(PDISC_INFO info); Ïîøóê âñ³õ ôàéë³â ó êîðåíåâîìó êàòàëîç³ HDIR LoadDirectory(PDISC_INFO info, UINT cluster, UINT* dirsize); Çàâàíòàæóº âì³ñò çàçíà÷åíîãî ëàíöþæêà êëàñòåð³â íà çãàäêó char* Fat32ReadFile(PDISC_INFO info, UINT FirstCluster, UINT* dwFileSize); ×èòຠâì³ñò ôàéëó, ïåðøèé êëàñòåð êîòðîãî â³äîìèé void Fat32DeInit(PDISC_INFO info); Çâ³ëüíÿº çàéíÿòó ïàì'ÿòü ³ çàêðèâຠäåñêðèïòîðè. void AnalyzeError(char* comment, int iErr); Âèêîíóº àíàë³ç ïîìèëêè, ùî â³äáóëàñÿ, ðåçóëüòàòè âèâîäèòü â MessageBox ãîëîâíîãî â³êíà void createFolder(PDISC_INFO info,AnsiString newDirName) Âèêîíóº äîäàòêîâå çàâäàííÿ ÊÏ. Ñòâîðåííÿ äèðåêòî𳿠â FAT16/32. Ïðèéìຠó ÿêîñò³ ïàðàìåòð³â ñòðóêòóðó íôîðìàö³¿ ïðî ïîòî÷íèé ðîçä³ë òà íàçâó íîâî¿ äèðåêòîð³¿. Ôóíêö³ÿ îòðèìóº ³íø íåîáõ³äí³ äàí³ òà ³íòåðôåéñ äî ðîáîòè ç ðàí³øå ñòâîðåíèõ ôóíêö³é òà ãëîáàëüíèõ çì³ííèõ (îçíàêà êîðåíåâî¿ äèðåêòîð³¿, ïîòî÷íèé øëÿõ, òèï ÔÑ òà ³í.). 5 ÌÅÒÎÄÈÊÈ ÐÎÁÎÒÈ Äëÿ íàâ³ãàö³¿ ñåðåä åëåìåíò³â êàòàëîãó òà ñåðåä ñïèñêó ëîã³÷íèõ äèñê³â âèêîðèñòîâóþòüñÿ 䳿 ìèø³. Äëÿ ïîð³âíÿííÿ äèðåêòî𳿠– îêðåìà êíîïêà «Ñðàâíåíèå ïàïîê». Äëÿ âèáîðó ïîòî÷íîãî äèñêó – âèïàäàþ÷èé ñïèñîê ç óñ³ìà ë³òåðàìè íàÿâíèõ äèñê³â. ϳñëÿ íàòèñêàííÿ íà êíîïêó ïîð³âíÿííÿ äèðåêòîð³é, çàì³ñòü äàííèõ ïðî ïîòî÷íèé ëîã³÷íèé äèñê, ç’ÿâëÿºòüñÿ íôîðìàö³ÿ ùîäî â³äêðèòèõ äèðåêòîð³é â ïàíåëÿõ ìåíåäæåðó.. Ïðè çì³í³ ïîòî÷íîãî äèñêó â³äáóâàºòüñÿ îíîâëåííÿ ³íôîðìàö³¿ ïðî äèñê ó ïðàâ³é ÷àñòèí³ â³êíà, òà ÿêùî çì³íà äèñêà áóëà ó ïðàâîìó â³êí³, òî é òàì â³äíîâëåííÿ. òà îíîâëþºòüñÿ ã³ñòîãðàìà çàéíÿòîãî/â³ëüíîãî ïðîñòîðó. 6 ÄÎÑ˲ÄÆÅÍÍß ÐÅÇÓËÜÒÀҲ ³äðàçó ï³ñëÿ çàïóñêó ôîðìóºòüñÿ ³íòåðôåéñ êîðèñòóâà÷à é âèâîäèòüñÿ âì³ñò êîðåíåâîãî êàòàëîãó àêòèâíîãî ðîçä³ëó. Âèâîäèòüñÿ íàñòóïíà ³íôîðìàö³ÿ ïðî ôàéëè: ³ì'ÿ ôàéëó, ðîçì³ð, àòðèáóòè. Òàêîæ ó ïðàâ³1 ÷àñòèí³ â³êíà âèâîäèòüñÿ äåÿêà ³íôîðìàö³ÿ ïðî ëîã³÷íèé äèñê. Íà ã³ñòîãðàì³ â³äîáðàæåíî ñï³ââ³äíîøåííÿ çàéíÿòîãî é â³ëüíîãî ïðîñòîðó ëîã³÷íîãî äèñêó (ðèñ. 6.1). Ðèñóíîê 6.1 – Ñïèñîê ôàéë³â àêòèâíîãî êàòàëîãó. Ïåðåõ³ä â ³íøó äèðåêòîð³þ çä³éñíþºòüñÿ çà äîïîìîãîþ ìèøêè (ïîäâ³éíå íàòèñêàííÿ) àáî æ íàòèñêàííÿì êëàâ³ø³ ENTER (ïåðåä öèì ïîòð³áíà äèðåêòîð³ÿ ïîâèííà áóòè âèä³ëåíà, öüîãî ìîæíà äîìîãòèñÿ íàæàòèì êëàâ³ø "Íàãîðó" àáî "Óíèç" àáî æ îäèíàðíèì íàòèñêàííÿì ë³âî¿ êëàâ³ø³ ìèø³, ðèñ.6.2). Ðèñóíîê 6.2 – Ñïèñîê ôàéë³â â íåêîðåíåâîìó êàòàëîã³. Çð³âíÿííÿ ìè ïîáà÷èìî, íàæàâøè êíîïêó «Ñðàâíåíèå ïàïîê». Ïðàâîðó÷ â³ä ïàíåëåé áóäå ê³ëüê³ñíà ³íôîðìàö³ÿ ùîäî êîæíî¿ ïàíåë³. (ðèñ. 6.4). Ðèñóíîê 6.4 – â³äîáðàæåííÿ âì³ñòó ê³ëüê³ñíîãî çð³âíÿííÿ ïàïîê. ÂÈÑÍÎÂÎÊ Ó õîä³ âèêîíàííÿ êóðñîâîãî ïðîåêòó áóëà ñòâîðåíà ïðîãðàìà äëÿ ÎÑ Windows. Òàêîæ áóëè ïîêðàùåí³ íàâè÷êè ðîáîòè ç íàêîïè÷óâà÷åì íà æîðñòêîìó ìàãí³òíîìó äèñêó. Áóâ ðîç³áðàíèé íèçüêèé ð³âåíü ñíóâàííÿ ³íôîðìàö³¿ íà æîðñòêîìó äèñêó. Òàê ÿê îñíîâíà óâàãà ïðèä³ëÿëàñÿ ðîáîò³ ç ÔÑ FAT, áóëè çäîáóò³ âè÷åðïí³ çíàííÿ ïðî ñòðóêòóðó ö³º¿ ÔÑ òà íàâè÷êè ðîáîòè ç íåþ íà íèçüêîìó ð³âí³. ÄÎÄÀÒÎÊ À. ÂÈÕ²ÄͲ ÒÅÊCÒÈ ÏÐÎÃÐÀÌÈ MANAGER.CPP //--------------------------------------------------------------------------- #include <vcl.h> #pragma hdrstop #include "manager.h" #include <string.h> #include <vector> #include <math.h> #include "mbrmodule.h" #include "fat32.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma link "CGAUGES" #pragma resource "*.dfm" PHARDINFO hdd[256]; PFILES files, files2; PLOGICAL_DISC currpld, currpld2; char DisplayName[]="#Commander from Hell#"; char path[65536], path2[65536], pat[256], pat2[256], nulpat[256]; //pat,pat2 ïåðåìåííûå äëÿ êîïèðîâàíèÿ èìåíè êîòîðîå áóäåò óäàëÿòñÿ èç ïóòè HANDLE hlistbox,hwnd,hComboBox; UINT iSelected, iSelected2; PFILES mfile; char buf[64]; char pathcpy[1024]; PLOGICAL_DISC pld; PFILEBUF pfb; int fil1, fil2, dir1, dir2; // ñ÷åò÷èêè ôàéëîâ è ïàïîê int fl=0; void AnalyzeError(char* comment, int iErr) %s",comment?comment:"", iErr, locBuf); /******************************************************************************* * Î÷èñòêà ñïèñêà ôàéëîâ, íåîáõîäèìà ïåðåä íà÷àëîì ðàáîòû ñî ñïèñêîì. * * Åñëè çàáûòü ïðî î÷èñòêó, òî ôàéëû íà ýêðàíå íå î÷èñòÿòñÿ, à íîâûå äîáàâÿòñÿ * * â êîíåö * ****************************************************************************** */ void FreeFilesList() { PFILES pfiles, ppred; fil1=0; dir1=0; pfiles = files; while(pfiles) { free(pfiles->ansiname); ppred = pfiles; pfiles =(_FILES*) pfiles->next; free(ppred); } files = NULL; } void FreeFilesList2() { PFILES pfiles, ppred; fil2=0; dir2=0; pfiles = files2; while(pfiles) { free(pfiles->ansiname); ppred = pfiles; pfiles =(_FILES*) pfiles->next; free(ppred); } files2 = NULL; } /******************************************************************************* * Êîíêðåòíàÿ ôóíêöèÿ äëÿ ÷òåíèÿ äèðåêòîðèè â NTFS-òîìå * ******************************************************************************* */ int NTFSReadDir(PLOGICAL_DISC pld, char* pPath) { char pFullPath[1024]; HANDLE hFind; WIN32_FIND_DATA fd; PFILES pfirst = NULL, pfiles, ppred = NULL; if(!pld)return 0; pFullPath[0] = pld->nDisc; pFullPath[1] = ':'; pFullPath[2] = '\\'; pFullPath[3] = 0; if(pPath && pPath[0]!=0)wsprintf(pFullPath+3,pPath); strcat(pFullPath,"*"); if((hFind = FindFirstFile(pFullPath,&fd))==INVALID_HANDLE_VALUE)return 0; if(files)FreeFilesList(); while(1) { pfiles =(_FILES*) malloc(sizeof(FILES)); if(!pfirst)pfirst = pfiles; pfiles->attrib = fd.dwFileAttributes; pfiles->filesize = fd.nFileSizeLow; pfiles->ansiname =(char*) malloc(strlen((const char*)&fd.cFileName)+1); if(ppred)ppred->next = pfiles; wsprintf(pfiles->ansiname,(const char*)&fd.cFileName); ppred = pfiles; if(!FindNextFile(hFind, &fd)) if(GetLastError() == ERROR_NO_MORE_FILES) break; } pfiles->next = NULL; FindClose(hFind); files = pfirst; Form1->APrintFileListExecute(0); return 1; } int NTFSReadDir2(PLOGICAL_DISC pld, char* pPath) { char pFullPath[1024]; HANDLE hFind; WIN32_FIND_DATA fd; PFILES pfirst = NULL, pfiles, ppred = NULL; if(!pld)return 0; pFullPath[0] = pld->nDisc; pFullPath[1] = ':'; pFullPath[2] = '\\'; pFullPath[3] = 0; if(pPath && pPath[0]!=0)wsprintf(pFullPath+3,pPath); strcat(pFullPath,"*"); if((hFind = FindFirstFile(pFullPath,&fd))==INVALID_HANDLE_VALUE)return 0; if(files2)FreeFilesList2(); while(1) { pfiles =(_FILES*) malloc(sizeof(FILES)); if(!pfirst)pfirst = pfiles; pfiles->attrib = fd.dwFileAttributes; pfiles->filesize = fd.nFileSizeLow; pfiles->ansiname =(char*) malloc(strlen((const char*)&fd.cFileName)+1); if(ppred)ppred->next = pfiles; wsprintf(pfiles->ansiname,(const char*)&fd.cFileName); ppred = pfiles; if(!FindNextFile(hFind, &fd)) if(GetLastError() == ERROR_NO_MORE_FILES) break; } pfiles->next = NULL; FindClose(hFind); files2 = pfirst; Form1->APrintFileListExecute2(0); return 1; } /**************************************************************************** * Ïîëó÷åíèå ñâîáîäíîãî ìåñòà â ÌÁ ñâîáîäíîãî òîìà, åñëè îí â NTFS ************************************************************************** */ UINT GetNtfsFreeSpace(PLOGICAL_DISC pld) { __int64 i64FreeBytesToCaller, i64TotalBytes, i64FreeBytes; char szdisk[3]; szdisk[0] = pld->nDisc; szdisk[1] = ':'; szdisk[2] = 0; if(Sysutils::GetDiskFreeSpaceEx (szdisk, i64FreeBytesToCaller, i64TotalBytes, &i64FreeBytes)) { //Application->MessageBoxA(IntToStr(i64FreeBytes/(1024*1024)).c_str(),IntToStr(i64FreeBytes/(1024*1024)).c_str(),MB_OK); return (i64FreeBytes/(1024*1024)); } return 0; } /******************************************************************************* * ×òåíèå çàäàííîé äèðåêòîðèè, îïðåäåëåíèå òîãî, êàêèå ô-öèè äëÿ ýòîãî íàäî * * èñïîëüçîâàòü * ******************************************************************************* */ int ReadDir(PLOGICAL_DISC pld, char* pPath) { ULONG dwDirSize; //ðàçìåð äèðåêòîðèè â êëàñòåðàõ HDIR hDir; //ccûëêà íà äèðåêòîðèþ UINT DirCluster; //íîìåð êëàñòåðà äèðåêòîðèè PDISC_INFO info; PFILES pfirst, pfiles, ppred; char disc; char filename[1024]; char *ptr; char pathh[65356]; //strcpy(pathh,path); if(!pld)return 0; info =(_DISC_INFO*) pld->disc_info; disc = pld->nDisc; if(!info) { if((pld->id == 0x07)||(pld->id == 0x17)) { if(!pld->prcfree)pld->prcfree = GetNtfsFreeSpace(pld); return NTFSReadDir(pld,pPath); } if(!(info =(_DISC_INFO*) pld->disc_info = Fat32Init(disc))) return 0; pld->prcfree = ((PDISC_INFO)(pld->disc_info))->prcfree; } if(pPath && pPath[0]!=0) { DirCluster=GotoDir(info, pPath+1); if(DirCluster) { hDir=LoadDirectory(info, DirCluster, &dwDirSize); ListDirectory(info, hDir, dwDirSize, NULL, &pfirst); free(hDir); } } else pfirst=PrintRootDirectory(info); if(strlen(path)>1) { wsprintf(pathh,path); pathh[strlen(pathh)-1]='\0'; ptr= strrchr(pathh,'\\')+1; if (strcmp(ptr,"..")==0) { pathh[(strrchr(pathh,'\\')-pathh)]='\0'; if (strrchr(pathh,'\\')==pathh) { pfirst=PrintRootDirectory(info); while(strlen(path)>1) strncpy(path+strlen(path)-1,nulpat,1); } else if(pfirst) { if(files)FreeFilesList(); files = pfirst; Form1->APrintFileListExecute(0); return 1; } } else if(pfirst) { if(files)FreeFilesList(); files = pfirst; Form1->APrintFileListExecute(0); return 1; } } else if(pfirst) { if(files)FreeFilesList(); files = pfirst; Form1->APrintFileListExecute(0); return 1; } return 0; } int ReadDir2(PLOGICAL_DISC pld, char* pPath) { ULONG dwDirSize; //ðàçìåð äèðåêòîðèè â êëàñòåðàõ HDIR hDir; //ccûëêà íà äèðåêòîðèþ UINT DirCluster; //íîìåð êëàñòåðà äèðåêòîðèè PDISC_INFO info; PFILES pfirst, pfiles, ppred; char disc; char filename[1024]; char pathh[65356]; char *ptr; //strcpy(pathh,path); if(!pld)return 0; info =(_DISC_INFO*) pld->disc_info; disc = pld->nDisc; if(!info) { if((pld->id == 0x07)||(pld->id == 0x17)) { if(!pld->prcfree)pld->prcfree = GetNtfsFreeSpace(pld); return NTFSReadDir2(pld,pPath); } if(!(info =(_DISC_INFO*) pld->disc_info = Fat32Init(disc))) return 0; pld->prcfree = ((PDISC_INFO)(pld->disc_info))->prcfree; } if(pPath && pPath[0]!=0) { DirCluster=GotoDir(info, pPath+1); if(DirCluster) { hDir=LoadDirectory(info, DirCluster, &dwDirSize); ListDirectory(info, hDir, dwDirSize, NULL, &pfirst); free(hDir); } } else pfirst=PrintRootDirectory(info); if(strlen(path2)>1) { wsprintf(pathh,path2); pathh[strlen(pathh)-1]='\0'; ptr= strrchr(pathh,'\\')+1; if (strcmp(ptr,"..")==0) { pathh[(strrchr(pathh,'\\')-pathh)]='\0'; if (strrchr(pathh,'\\')==pathh) { pfirst=PrintRootDirectory(info); while(strlen(path2)>1) strncpy(path2+strlen(path2)-1,nulpat,1); } else if(pfirst) { if(files2)FreeFilesList(); files2 = pfirst; Form1->APrintFileListExecute2(0); return 1; } } else if(pfirst) { if(files2)FreeFilesList(); files2 = pfirst; Form1->APrintFileListExecute2(0); return 1; } } else if(pfirst) { if(files2)FreeFilesList(); files2 = pfirst; Form1->APrintFileListExecute2(0); return 1; } return 0; } /*-----------------------------------------------------------------------------*/ /******************************************************************************* * Èíèöèàëèçàöèÿ ñïèñêà ðàçäåëîâ * ******************************************************************************* */ void InitPartitionList() { int i, iRetVal, nActive = 0; char combobuf[64]; PHARDINFO inf; PLOGICAL_DISC pld; UCHAR nHDD=0; while(inf = hdd[nHDD] = Init(nHDD)) { pld = inf->disklist; while(pld) { combobuf[0] = pld->nDisc; combobuf[1] = ':'; combobuf[2] = 0; iRetVal = Form1->CBDiskName->ItemIndex; iRetVal = Form1->CBDiskName2->ItemIndex; if(pld->active=='+') { nActive = iRetVal; currpld = pld; } pld =(_LOGICAL_DISC*) pld->next; } nHDD++; } ReadDir(currpld,NULL); ReadDir2(currpld2,NULL); } /*-----------------------------------------------------------------------------*/ /******************************************************************************* * Ïîèñê äèñêà ïî åãî èìåíè * ******************************************************************************* */ PLOGICAL_DISC FindDiskByChar(char disk) { int i = 0; PHARDINFO inf; PLOGICAL_DISC pld; while(inf=hdd[i++]) { pld = inf->disklist; while(pld) { if(pld->nDisc == disk)return pld; pld =(_LOGICAL_DISC*) pld->next; } } return NULL; } /*-----------------------------------------------------------------------------*/ /******************************************************************************* *Ïîèñê äèñêà ïî åãî èíäåêñó, âûçûâàåòñÿ, êîãäà ïðîèñõîäèò ñìåíà òåêóùåãî äèñêà* ******************************************************************************* */ PLOGICAL_DISC FindDiskByIndex(char index) { int i = 0, j = 0; PHARDINFO inf; PLOGICAL_DISC pld; while(inf=hdd[i++]) { pld = inf->disklist; while(pld) { if(j == index)return pld; pld =(_LOGICAL_DISC*) pld->next; j++; } } return NULL; } /******************************************************************************* * Ïîèñê ôàéëà â çàðàíåå ñôîðìèðîâàííîì ñïèñêå ïî åãî èíäåêñó * ******************************************************************************* */ PFILES FindFileByIndex(int index) { int i = 0; PFILES pfiles; pfiles = files; while(pfiles) { if(i == index)return pfiles; pfiles =(_FILES*) pfiles->next; i++; } return NULL; } PFILES FindFileByIndex2(int index) { int i = 0; PFILES pfiles; pfiles = files2; while(pfiles) { if(i == index)return pfiles; pfiles =(_FILES*) pfiles->next; i++; } return NULL; } /******************************************************************************* * Ëîæèìñÿ ñïàòü è îñâîáîæäàåì âñå, ÷òî çàãàäèëè. * ******************************************************************************* */ void DeInitialize() { int i = 0; PHARDINFO inf; PLOGICAL_DISC pld, pred; while(inf=hdd[i++]) { pld = inf->disklist; while(pld) { if(pld->disc_info)Fat32DeInit((_DISC_INFO*)pld->disc_info); pred = pld; pld =(_LOGICAL_DISC*) pld->next; free(pred); } DeInit(inf); } } /*****************************************************************************/ TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } /******************************************************************************* * Ôóíêöèÿ ñïèñêà äåéñòâèé, îáíîâëåíèå ñïèñêà äèñêîâ. Âûïîëíÿåò ïîëíîå * * ïîëíîå îáíîâëåíèå, àíàëîãè÷íî, êàê è ïðè çàïóñêå ïðîãðàììû. * ******************************************************************************* */ void __fastcall TForm1::ARefreshListExecute(TObject *Sender) { int i, iRetVal, nActive = 0; char combobuf[64]; PHARDINFO inf; PLOGICAL_DISC pld; UCHAR nHDD=0; CBDiskName->Items->Clear(); CBDiskName2->Items->Clear(); while(inf = hdd[nHDD] = Init(nHDD)) { pld = inf->disklist; while(pld) { if(pld->nDisc=='?') goto figoviyDisk; combobuf[0] = pld->nDisc; combobuf[1] = ':'; combobuf[2] = 0; iRetVal = CBDiskName->ItemIndex; iRetVal = CBDiskName2->ItemIndex; CBDiskName->Items->Add(combobuf); CBDiskName2->Items->Add(combobuf); if(pld->active=='+') { nActive = iRetVal; currpld = pld; currpld2 = pld; } figoviyDisk: pld =(_LOGICAL_DISC*) pld->next; } nHDD++; } //ReadDir(currpld,NULL); //ReadDir2(currpld,NULL); } /******************************************************************************* * Ïðè ïåðâîì ïîêàçå ôîðìû óñòàíàâëèâàåò òåêóùèé äèñê êàê èíäåêñ çíà÷åíèÿ â * * ñïèñêå äèñêîâ, ýòî çíà÷åíèå âñåãäà èñïîëüçóåòñÿ äëÿ ïîëó÷åíèÿ íîìåðà äèñêà. * ******************************************************************************* */ void __fastcall TForm1::FormShow(TObject *Sender) { CBDiskName2->ItemIndex=0; Form1->CBDiskName2->OnChange(0); CBDiskName->ItemIndex=0; Form1->CBDiskName->OnChange(0); wsprintf(path,"\\"); wsprintf(path2,"\\"); } /******************************************************************************* * Âûâîä ôàéëîâ íà ïàíåëü, ôóíêöèÿ ñïèñêà äåéñòâèé * ******************************************************************************* */ void __fastcall TForm1::APrintFileListExecute(TObject *Sender) { PFILES pfiles; char sz[128]; char s[2048]; int maxx=0; pfiles = files; Form1->Label11->Caption=currpld->cpFS; Form1->Label12->Caption=currpld->mbLength; Form1->Label13->Caption=currpld->abs_addr; Form1->Label14->Caption=currpld->prcfree; Form1->LBFileList->Items->Clear(); //Form1->LBFileList->Items->SetText(""); while(pfiles) { if(pfiles->attrib==8) { pfiles =(_FILES*) pfiles->next; fl=1; continue; } if(pfiles->attrib & FILE_ATTRIBUTE_DIRECTORY){wsprintf(sz,"<DIR>"); dir1++;} else {wsprintf(sz,"%u",pfiles->filesize); fil1++;} //if (!strstr("..",pfiles->ansiname )) dir1-=2; if(pfiles->attrib & FILE_ATTRIBUTE_DIRECTORY) wsprintf(s,"[%-18s] %#10s %02X",pfiles->ansiname,sz,pfiles->attrib); else wsprintf(s,"%-20s %#10s %02X",pfiles->ansiname,sz,pfiles->attrib); Form1->LBFileList->Items->Add(AnsiString(s)); pfiles =(_FILES*) pfiles->next; if (strlen(s)>maxx) maxx=strlen(s); } Form1->LBFileList->ScrollWidth=maxx*8+10; Form1->Edit1->Text = Form1->CBDiskName->Text+'\\'; //if (strlen(path) > 1) dir1 -= 2; Form1->Label22->Caption=dir1; Form1->Label25->Caption=fil1; } void __fastcall TForm1::APrintFileListExecute2(TObject *Sender) { PFILES pfiles; char sz[128]; char s[2048]; int maxx=0; pfiles = files2; Form1->LBFileList2->Items->Clear(); while(pfiles) { if(pfiles->attrib==8) { pfiles =(_FILES*) pfiles->next; continue; } if(pfiles->attrib & FILE_ATTRIBUTE_DIRECTORY){wsprintf(sz,"<DIR>"); dir2++;} else {wsprintf(sz,"%u",pfiles->filesize);/*ltoa((ULONG)pfiles->filesize,sz,10); */fil2++;} if(pfiles->attrib & FILE_ATTRIBUTE_DIRECTORY) wsprintf(s,"[%-18s] %#10s %02X",pfiles->ansiname,sz,pfiles->attrib); else wsprintf(s,"%-20s %#10s %02X",pfiles->ansiname,sz,pfiles->attrib); Form1->LBFileList2->Items->Add(AnsiString(s)); pfiles =(_FILES*) pfiles->next; if (strlen(s)>maxx) maxx=strlen(s); } Form1->LBFileList2->ScrollWidth=maxx*8+10; Form1->Edit2->Text = Form1->CBDiskName2->Text+'\\'; //if (strlen(path2) > 1) dir2 -= 2; Form1->Label27->Caption=dir2; Form1->Label29->Caption=fil2; } ******************************************************************************* * Îáðàáîò÷èê èçìåíåíèÿ èìåíè äèñêà â âûïàäàþùåì ñïèñêå ââåðõó. Îáíîâëÿþòñÿ âñå* * íåîáõîäèìûå äàííûå. * ******************************************************************************* */ void __fastcall TForm1::CBDiskNameChange(TObject *Sender) { LBFileList->Items->Clear(); currpld=FindDiskByChar(*(CBDiskName->Text.SubString(0,1).c_str())); if(currpld == NULL) return; ReadDir(currpld,NULL); wsprintf(path,"\\"); CGauge1->Progress=100-currpld->prcfree/(currpld->mbLength/100); } void __fastcall TForm1::CBDiskName2Change(TObject *Sender) { LBFileList2->Items->Clear(); currpld2=FindDiskByChar(*(CBDiskName2->Text.SubString(0,1).c_str())); if(currpld2 == NULL) return; ReadDir2(currpld2,NULL); wsprintf(path2,"\\"); } /******************************************************************************* * Îáðàáîò÷èê äâîéíîãî ùåë÷êà íà îáëàñòè ïàíåëè ñ ôàéëàìè, îáðàáàòûâàåì òîëüêî * * áåãàíèå ïî äèðåêòîðèÿì. * ******************************************************************************* */ void __fastcall TForm1::LBFileListDblClick(TObject *Sender) { int i; iSelected = LBFileList->ItemIndex; char *ptr; char bufferstr[65356]; char buffpath[2048]; PFILES pfirst, pfiles; if(iSelected == -1)return; mfile = FindFileByIndex(iSelected); /*Ðåàãèðóåì òîëüêî íà âõîä â äèðåêòîðèþ è íà âûõîä èç íåå */ if((mfile->attrib & 0x10)) if((strlen(path)==1) || ((strlen(path)>1)&&(iSelected>0))) { if((strlen(mfile->ansiname)+strlen(path)+3)>sizeof(path))return; strcat(path, mfile->ansiname); wsprintf(bufferstr,mfile->ansiname); strcat(path, "\\"); //ReadDir(currpld,path); if(!ReadDir(currpld,path)) if (strcmp(bufferstr,"..")!=0) { ptr = strrchr(path,'\\'); while((ptr - path) < strlen(path)) strncpy(ptr,nulpat,strlen(path)); ptr = strrchr(path,'\\')+1; while((ptr - path) < strlen(path)) strncpy(ptr,nulpat,strlen(path)); } if(strlen(path) == 0) strcat(path, "\\"); else if(strlen(path) != 1) { if (strcmp(bufferstr,"..")==0) { ptr = strrchr(path,'\\'); while((ptr - path) < strlen(path)) strncpy(ptr,nulpat,strlen(path)); ptr = strrchr(path,'\\'); while((ptr - path) < strlen(path)) strncpy(ptr,nulpat,strlen(path)); ptr = strrchr(path,'\\')+1; while((ptr - path) < strlen(path)) strncpy(ptr,nulpat,strlen(path)); LBFileList->Items->Clear(); ReadDir(currpld,path); } } else { LBFileList->Items->Clear(); ReadDir(currpld,NULL); wsprintf(path,"\\"); } if (strcmp(bufferstr,".")==0) { ptr = strrchr(path,'\\')-1; strncpy(ptr,nulpat,strlen(path)); } Form1->Edit1->Text = Form1->CBDiskName->Text+path; if (strlen(path) > 1) dir1 -= 2; // (buffpath,IntToStr(dir1)); Form1->Label22->Caption=dir1; } } //--------------------------------------------------------------------------- void __fastcall TForm1::LBFileList2DblClick(TObject *Sender) { int i; iSelected2 = LBFileList2->ItemIndex; char *ptr; char bufferstr[65356]; char buffpath2[2048]; PFILES pfirst, pfiles; if(iSelected2 == -1)return; mfile = FindFileByIndex2(iSelected2); /*Ðåàãèðóåì òîëüêî íà âõîä â äèðåêòîðèþ è íà âûõîä èç íåå */ if((mfile->attrib & 0x10)) if((strlen(path2)==1) || ((strlen(path2)>1)&&(iSelected2>0))) { if((strlen(mfile->ansiname)+strlen(path2)+3)>sizeof(path2))return; strcat(path2, mfile->ansiname); wsprintf(bufferstr,mfile->ansiname); strcat(path2, "\\"); //ReadDir2(currpld2,path2); if(!ReadDir2(currpld2,path2)) if (strcmp(bufferstr,"..")!=0) { ptr = strrchr(path2,'\\'); while((ptr - path2) < strlen(path2)) strncpy(ptr,nulpat,strlen(path2)); ptr = strrchr(path2,'\\')+1; while((ptr - path2) < strlen(path2)) strncpy(ptr,nulpat,strlen(path2)); } if(strlen(path2) == 0) strcat(path2, "\\"); else if(strlen(path2) != 1) { if (strcmp(bufferstr,"..")==0) { ptr = strrchr(path2,'\\'); while((ptr - path2) < strlen(path2)) strncpy(ptr,nulpat,strlen(path2)); ptr = strrchr(path2,'\\'); while((ptr - path2) < strlen(path2)) strncpy(ptr,nulpat,strlen(path2)); ptr = strrchr(path2,'\\')+1; while((ptr - path2) < strlen(path2)) strncpy(ptr,nulpat,strlen(path2)); LBFileList2->Items->Clear(); ReadDir2(currpld2,path2); } } else { LBFileList2->Items->Clear(); ReadDir2(currpld2,NULL); wsprintf(path2,"\\"); } if (strcmp(bufferstr,".")==0) { ptr = strrchr(path2,'\\')-1; strncpy(ptr,nulpat,strlen(path2)); } Form1->Edit2->Text = Form1->CBDiskName2->Text+path2; if (strlen(path2) > 1) dir2 -= 2; // (buffpath,IntToStr(dir1)); Form1->Label27->Caption=dir2; } } //--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { Compare->Visible = false; Button2->Visible = true; Button2->SetFocus(); } //--------------------------------------------------------------------------- void __fastcall TForm1::Button2Click(TObject *Sender) { Compare->Visible = true; Button2->Visible = false; Button1->SetFocus(); } //--------------------------------------------------------------------------- FAT32.CPP #include <windows.h> //#include "fat32.h" #include "err.h" /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ //×òåíèå äàííûõ ðàçäåëà BOOL Fat32DataRead(PDISC_INFO info, char* buf, UINT bufsize) { int nRead; BOOL bRetValue=ReadFile(info->hDrive, buf, bufsize,(unsigned long*) &nRead, NULL); if(!bRetValue)AnalyzeError("# Error at ReadFile: ",GetLastError()); return bRetValue; } /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ //ñäâèíóòü óêàçàòåëü âíóòðè ðàçäåëà UINT Fat32DataMovePointer(PDISC_INFO info, UINT secpointer) { UINT iErr; UINT HiPointer=secpointer>>(32-info->bitsPerSector); UINT LoPointer=secpointer<<(info->bitsPerSector); UINT bRetValue=SetFilePointer(info->hDrive,LoPointer,(long*)&HiPointer,FILE_BEGIN); if(bRetValue==-1) { iErr=GetLastError(); if(iErr!=NO_ERROR)AnalyzeError("# Error at SetFilePointer: ",iErr); } return bRetValue; } /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ //íàéòè ñëåäóþùèé ýëåìåíò öåïî÷êè êëàñòåðîâ UINT GetNextFileCluster(PDISC_INFO info, UINT nCurrCluster) { UINT nextcluster;
if(info->bFAT16)nextcluster = ((USHORT*)(info->pFAT))[nCurrCluster]; else nextcluster = info->pFAT[nCurrCluster]; return nextcluster; } /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ UINT Cluster2Sector(PDISC_INFO info, UINT cluster) { UINT retval; if(info->bFAT16) retval = info->sizeReserved+ (info->nFATCopy)*(info->sizeFAT)+ cluster*(info->SectPerCluster); else retval = info->sizeReserved+ (info->nFATCopy)*(info->sizeFAT)+ (cluster-2)*(info->SectPerCluster); return retval; } /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ char* Fat32ReadFile(PDISC_INFO info, UINT FirstCluster, ULONG* dwFileSize) { char* retval = LoadDirectory(info, FirstCluster, dwFileSize); if(dwFileSize)*dwFileSize = (*dwFileSize)*(info->BytesPerCluster); return retval; } /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ //ïðîéòèñü ïî öåïî÷êå êëàñòåðîâ UINT WalkOnFATTable(PDISC_INFO info, UINT FirstCluster, UINT* LastCluster, UINT* nClusters) { UINT fragments=1; UINT predCluster, n=0; UINT currCluster=FirstCluster; while(1) { predCluster=currCluster; n++; currCluster=GetNextFileCluster(info, currCluster); if(currCluster==0)return 0; if(currCluster>=0x0FFFFFF8)break; if(info->bFAT16 && (currCluster>=0xfff8))break; if(currCluster!=(predCluster+1))fragments++; } if(LastCluster)*LastCluster=predCluster; if(nClusters)*nClusters=n; return fragments; } /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ //Çàãðóæàåò äèðåêòîðèþ â ïàìÿòü HDIR LoadDirectory(PDISC_INFO info, UINT cluster, ULONG* dirsize) { UINT sector,currCluster; UINT i; UINT nClusters,dwSize; HDIR hDir; char b[1024];
currCluster=cluster; if(info->bFAT16 && (0 == cluster)) {
nClusters = 1 + (info->nRootElements * 32) / info->BytesPerCluster; dwSize = nClusters * info->BytesPerCluster; //MessageBox(0,"zzz","",MB_OK); }else{ WalkOnFATTable(info,cluster,NULL,&nClusters); dwSize=(info->BytesPerCluster)*nClusters; } hDir=(HDIR)malloc(dwSize); for(i=0;i<nClusters;i++) { if(info->bFAT16 && (0 == cluster)) { sector = info->RootSector; }else sector = Cluster2Sector(info, currCluster); if(Fat32DataMovePointer(info,sector)==-1) { free(hDir); return NULL; } if(!Fat32DataRead(info,hDir+i*(info->BytesPerCluster),info->BytesPerCluster)) { free(hDir); return NULL; } if(info->bFAT16 && (0 == cluster)) {currCluster++;} else { currCluster = GetNextFileCluster(info,currCluster); if(currCluster==0) { free(hDir); return NULL; } } if(currCluster>=0x0FFFFFF8)break; } //MessageBox(0,"zzz2","",MB_OK); if(dirsize)*dirsize=nClusters; return hDir; } /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ //Çàãðóæàåò òàáëèöó FAT â ïàìÿòü BOOL LoadFAT(PDISC_INFO info) { UINT dwSize=(info->sizeFAT)*(info->nBytePerSector); if(Fat32DataMovePointer(info,info->beginFAT)==-1)return 0; info->pFAT=(unsigned int*)malloc(dwSize); if(info->pFAT==NULL)return FALSE; if(!Fat32DataRead(info,(char*)(info->pFAT),dwSize)) { free(info->pFAT); return FALSE; } info->sizeFATbytes=dwSize; return TRUE; } /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ //åñëè pObjectName==NULL òî ïå÷àòàåò ñîäåðæèìîå äèðåêòîðèè, íàõîäÿùåéñÿ â ïàìÿòè //åñëè pObjectName!=NULL èùåò â äèðåêòîðèè äèðåêòîðèþ ñ èìåíåì pObjectName UINT ListDirectory(PDISC_INFO info, HDIR hDir,UINT dwDirSize,char* cpObjectName, PFILES* ppfiles) { UCHAR attrib; UCHAR* p; UCHAR* t; USHORT firstclusterLo,firstclusterHi; UINT i,j,h,firstcluster,filesize; char ansiname[1024]; unsigned char uname[1024]; BOOL IsTheLong=FALSE; PFILES pfiles, pfirst=NULL, ppred=NULL; if(hDir==NULL)return 0; p=hDir; ansiname[11]=0; for(i=0;i<(dwDirSize*(info->BytesPerCluster))/32;i++) { if((p[0]==0xE5) || (p[0] == 0x8F) || (p[11]) == '\b') { p=p+32; continue; } if(p[0]==0)break; attrib=p[11]; if(attrib!=0x0F) { firstclusterLo=(*(USHORT*)&p[26]); firstclusterHi=(*(USHORT*)&p[20]); firstcluster=firstclusterHi; firstcluster=(firstcluster<<16)+firstclusterLo; if(!cpObjectName) { filesize=*(UINT*)&p[28]; pfiles =(_FILES*) malloc(sizeof(FILES)); pfiles->attrib = attrib; pfiles->firstcluster = firstcluster; pfiles->filesize = filesize; if(!pfirst)pfirst = pfiles; if(ppred)ppred->next = pfiles; } for(int g=10;g>1;g--) if(p[g]==' ') p[g]='\0'; memcpy(ansiname,p,11); for(j=10;j>1;j--) if(ansiname[j]!=0x20) { ansiname[j+1]=0; break; } if(IsTheLong) { WideCharToMultiByte(CP_ACP,0,(LPCWSTR)uname,-1,ansiname,sizeof(ansiname),NULL,NULL); IsTheLong=FALSE; } if(cpObjectName) if((!strcmpi(cpObjectName,ansiname)) && ((attrib&0x10)!=0)) return firstcluster; if(!cpObjectName) { pfiles->ansiname =(char*) malloc(strlen(ansiname)+1); strcpy(pfiles->ansiname, ansiname); pfiles->next = NULL; ppred = pfiles; } } else if((p[0]==1)||(p[0]&0x40)) { if(p!=(hDir+dwDirSize)) if((p[0]&0x40)&&((p+32)[11]==0x0F)) { p+=32; continue; } t=p; h=0; memset(uname,0,sizeof(uname)); while(1) { j=t[0];
memcpy(uname+h+00,t+1,10); memcpy(uname+h+10,t+14,12); memcpy(uname+h+22,t+28,4); if(j&0x40) { IsTheLong=TRUE; break; } t-=32; h+=26; if(t<hDir)break; if(t[11]!=0x0F)break; } } p+=32; }
if(ppfiles) *ppfiles = pfirst; return 0; } /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ double GetFreeSpaceEx(PDISC_INFO info)// { unsigned long i; double RET; double freeclusters = 0; double clusters = info->sizeFATbytes / 4; if (clusters == 0) return 0; for(i=0;i<clusters;i++) if(!info->pFAT[i])freeclusters++; RET=(freeclusters * info->BytesPerCluster); RET /= (1024*1024); return RET; } /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ //èíèöèàëèçèðóåò ñòðóêòóðó DISC_INFO PDISC_INFO Fat32Init(char disc) { char LogicalDiskName[]="\\\\.\\X:"; char RootDir[]="X:"; UCHAR buf[2048]; UCHAR signature1; //66 USHORT signature2; //510 UCHAR signature3; //38 UINT i,n; PDISC_INFO info=(_DISC_INFO*)malloc(sizeof(DISC_INFO)); info->Disc=disc; LogicalDiskName[4]=disc; RootDir[0]=disc; info->hDrive=CreateFile( LogicalDiskName, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
if(info->hDrive==INVALID_HANDLE_VALUE) { AnalyzeError("# Error at CreateFile: ",GetLastError()); free(info); return NULL; }
GetDiskFreeSpace(RootDir,NULL,(unsigned long*)&(info->nBytePerSector),NULL,NULL); if(!Fat32DataRead(info, buf, info->nBytePerSector)) { CloseHandle(info->hDrive); free(info); return NULL; } //bFAT16 signature3=*(UCHAR*)&buf[38]; signature1=*(UCHAR*)&buf[66]; signature2=*(USHORT*)&buf[510];
if(signature2!=0xAA55) { //printf("# 55AA sig n'found"); CloseHandle(info->hDrive); free(info); return NULL; } if((signature3==0x29) && (signature1!=0x29)) { //printf("YAAHO!! FAT16!!!!!!!!!"); info->bFAT16 = TRUE;
info->sizeFAT = *(short*)&buf[22]; info->nRootElements = *(short*)&buf[17];
}else{ if(signature1 != 0x29) { //printf("# unknown FS"); free(info); return NULL; } info->bFAT16 = FALSE; info->sizeFAT=*(short*)&buf[36];
} info->nFATCopy=*(short*)&buf[16]; info->sizeReserved=*(short*)&buf[14]; info->SectPerCluster=*(char*)&buf[13]; info->BytesPerCluster=(info->SectPerCluster)*(info->nBytePerSector); info->beginFAT=info->sizeReserved; i=info->nBytePerSector; n=0; while(i=i/2)n++; info->bitsPerSector=n;
if(!LoadFAT(info)) { CloseHandle(info->hDrive); free(info); return NULL; }
if(info->bFAT16) { info->RootSector = info->beginFAT + info->nFATCopy * info->sizeFAT; info->RootCluster = 0; } else { info->RootCluster=*(int*)&buf[44]; info->RootSector = 0; } info->hRootDir=LoadDirectory(info, info->RootCluster,&(info->dwRootDirSize)); info->prcfree = GetFreeSpaceEx(info); return info; } /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ //âîçâðàùàåò êëàñòåð äèðåêòîðèè ðàñïîëîæåííîé ïî ïóòè cpPath UINT GotoDir(PDISC_INFO info, char* cpPath) { UINT i,dwLen=strlen(cpPath); char* pStr=(char*)malloc(dwLen+2); char* cpDirName=pStr; UINT DirCluster; ULONG dwDirSize; HDIR hDir;
hDir=info->hRootDir; dwDirSize=info->dwRootDirSize;
strcpy(pStr,cpPath); if(pStr[dwLen-1]!='\\') { strcat(pStr,"\\"); dwLen++; } for(i=0;i<dwLen;i++) { if(pStr[i]=='\\') { pStr[i]=0; DirCluster=ListDirectory(info, hDir,dwDirSize,cpDirName, NULL); if(hDir!=info->hRootDir)free(hDir); if(!DirCluster) { //printf("# error directory %s not found",cpDirName); free(pStr); return 0; } if(i==(dwLen-1)) { free(pStr); return DirCluster; } hDir=LoadDirectory(info, DirCluster, &dwDirSize); cpDirName=pStr+i+1; }
} free(pStr); return 0; } /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ void Fat32DeInit(PDISC_INFO info) { free(info->pFAT); free(info->hRootDir); CloseHandle(info->hDrive); free(info); } /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ PFILES PrintRootDirectory(PDISC_INFO info) { PFILES pfirst = NULL; ListDirectory(info, info->hRootDir, info->dwRootDirSize, NULL, &pfirst); return pfirst; } MBRMODULE.CPP #include <windows.h> //#include "mbrmodule.h" #include "err.h" char FAT[]="\x01\x04\x06\x0D\x0E"; /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ //Óçíàòü äèñê ïî ñåðèéíîìó íîìåðó char GetDiscBySN(UINT SN) { UINT VolumeSerialNumber; char Drive[4]="X:\\"; int i; for(i=2;i<25;i++) if((GetLogicalDrives()&(1<<i))!=0) { Drive[0] = 'A'+i; switch(GetDriveType(Drive)) { case DRIVE_CDROM: break; default: GetVolumeInformation(Drive, NULL,0, (unsigned long*)&VolumeSerialNumber, NULL,0,NULL,0 ); if(VolumeSerialNumber==SN) return Drive[0]; } } return 0; } /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ //Óçíàòü ôàéëîâóþ ñèñòåìó äèñêà ïî êîäó ôàéëîâîé ñèñòåìû char* GetFileSystem(unsigned char code) /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ //ñäâèíóòü óêàçàòåëü int MovePointer(PHARDINFO inf, UINT secpointer) { UINT iErr; UINT HiPointer=secpointer>>(32-inf->bitsPerSector); UINT LoPointer=secpointer<<(inf->bitsPerSector); UINT bRetValue=SetFilePointer(inf->hDrive,LoPointer,(long*)&HiPointer,FILE_BEGIN); if(bRetValue==-1) { iErr=GetLastError(); if(iErr!=NO_ERROR) { //printf("# error at SetFilePointer: "); AnalyzeError(NULL,iErr); } } return bRetValue; } /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ //×èòàòü îäèí ñåêòîð ñ æåñòêîãî äèñêà void* RawRead(PHARDINFO inf) { UINT iErr, SectorSize, nRead, i, n; void* buf; SectorSize=inf->dwSectorSize; if(!SectorSize)SectorSize=0x200;
buf=malloc(SectorSize); while(!ReadFile(inf->hDrive, buf, SectorSize, (unsigned long*)&nRead, NULL)) { iErr=GetLastError(); free(buf); if((iErr==ERROR_INVALID_PARAMETER)&&(SectorSize<0x8000)) { SectorSize=SectorSize*2; buf=malloc(SectorSize); continue; } //printf("# error at ReadFile: "); AnalyzeError(NULL,iErr); return NULL; }; if(inf->dwSectorSize!=SectorSize) { i=SectorSize; n=0; while(i=i/2)n++; inf->bitsPerSector=n; inf->dwSectorSize=SectorSize; }
return buf; } /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ /*Èçúÿòü ñåðèéíûé íîìåð äëÿ FAT èëè NTFS abs_addr - àäðåñ íà÷àëà ëîãè÷åñêîãî äèñêà â ñåêòîðàõ Serial - àäðåñ 8-áàéòíîãî áóôåðà äëÿ ñåðèéíîãî íîìåðà id - èäåíòèôèêàòîð ôàéëîâîé ñèñòåìû */ BOOL GetDiscSerial(PHARDINFO inf, UINT abs_addr, UCHAR* Serial, UCHAR id) { char* buf; int i; if(MovePointer(inf,abs_addr)==-1)return FALSE; if((buf=(char*)RawRead(inf))==NULL)return FALSE;
switch(id) { case 0x07: //NTFS memcpy(Serial,buf+72,8); break;
case 0x0E: case 0x0C: case 0x0B: //FAT32 memcpy(Serial,buf+67,4); break; default: for(i=0;i<sizeof(FAT);i++) if(id==FAT[i]) { memcpy(Serial,buf+39,4); free(buf); return TRUE; } return FALSE; } free(buf); return TRUE; } /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ void DeInit(PHARDINFO inf) { CloseHandle(inf->hDrive); free(inf); } /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ //Âûâåñòè ñïèñîê ðàçäåëîâ èç Partition Table â MBR PLOGICAL_DISC ListMBR(PHARDINFO inf, UCHAR* pMBR, UINT dwMBRAddr, UINT* pExtended, PPLOGICAL_DISC last) { UCHAR* pPart; UCHAR id,active; UINT ext=0,secBegin,secLength,mbLength=0,gbLength=0; PLOGICAL_DISC first=NULL, pld=NULL, pred=NULL; UINT SectorSize,abs_addr,SN4; UCHAR SN[8];
char* cpFS; int i;
SectorSize=inf->dwSectorSize; pPart=pMBR+0x01BE;
for(i=0;i<4;i++) { id=pPart[4]; if(!id) { pPart+=0x10; continue; } secBegin=*(UINT*)&pPart[8]; secLength=*(UINT*)&pPart[12]; active=pPart[0]; if(active)active='+'; else active='-'; pPart+=0x10; mbLength=secLength/(2*1024)*SectorSize/512; gbLength=mbLength/1024; abs_addr=dwMBRAddr+secBegin;
cpFS=GetFileSystem(id);
if((id==0x0F)||(id==0x05)) { ext=secBegin; continue; } memset(SN,0,sizeof(SN)); GetDiscSerial(inf,abs_addr,SN,id); memcpy(&SN4,SN,4); pred = pld; pld =(_LOGICAL_DISC*) malloc(sizeof(LOGICAL_DISC)); memset(pld, 0, sizeof(LOGICAL_DISC));
if(pred!=NULL) pred->next = pld; else first = pld; pld->nHard = inf->nHard; pld->nDisc = SN4?GetDiscBySN(SN4):'?'; pld->active = active; pld->abs_addr = abs_addr; pld->secLength = secLength; pld->id = id; pld->cpFS = cpFS; pld->SN4 = SN4; pld->gbLength = gbLength; pld->mbLength = mbLength; pld->next = NULL; } *pExtended = ext; *last = pld; return first; } /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ //Ïå÷àòàòü çàãîëîâîê void PrintHead() { //printf("HDD Disc Boot Addr Size FS SN mb/gb\n"); //printf("------------------------------------------------------------------------\n"); } /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ //Ïðîâåðèòü ñèãíàòóðó BOOL CheckMBR(UCHAR* pMBR) { BOOL bRetValue=*(USHORT*)(pMBR+0x01FE)==0xAA55; // if(!bRetValue)printf("# not valid MBR\n"); return bRetValue; } /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ //Ïðîéòèñü ïî öåïî÷êå MBR BOOL WalkOnMBR(PHARDINFO inf, PPLOGICAL_DISC first) { PLOGICAL_DISC pred=NULL, last=NULL; UINT ext,dwNextMBRAddr; void* pMBR;
*first = NULL; if((pMBR=RawRead(inf))==NULL)return FALSE; if(!CheckMBR((unsigned char*)pMBR)) { free(pMBR); return FALSE; } if((*first=ListMBR(inf,(unsigned char*)pMBR,0,&ext,&last))&&ext) { inf->dwExtendedAddr=ext; ext=0; while(1) { free(pMBR); dwNextMBRAddr=ext+inf->dwExtendedAddr; if(MovePointer(inf,dwNextMBRAddr)==-1)return FALSE; if((pMBR=RawRead(inf))==NULL)return FALSE; if(!CheckMBR((unsigned char*)pMBR)) { free(pMBR); return FALSE; } pred = last; pred->next = ListMBR(inf,(unsigned char*)pMBR,dwNextMBRAddr,&ext,&last); if(!ext)break; } } free(pMBR); return TRUE; } /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ PHARDINFO Init(char n) { char HardDiskName[]="\\\\.\\PHYSICALDRIVE0"; void* hDrive; UINT iErr, dwSectorSize; PHARDINFO inf;
HardDiskName[sizeof(HardDiskName)-2]=n+'0'; hDrive=CreateFile( HardDiskName, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL ); if(hDrive==INVALID_HANDLE_VALUE) { iErr=GetLastError(); if(iErr==ERROR_FILE_NOT_FOUND)return NULL; AnalyzeError("# Error at CreateFile: ",iErr); return NULL; }
inf=(_HARDINFO*)malloc(sizeof(HARDINFO)); inf->hDrive=hDrive; inf->nHard=n; inf->dwSectorSize=0; WalkOnMBR(inf, &inf->disklist); return inf;} |
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|