Linux °æ (¾«»ªÇø)
·¢ÐÅÈË: netiscpu (Ò¹¡îÐǹâµãµã¡î), ÐÅÇø: Linux
±ê Ìâ: NACHOSÂÛ̳(3)
·¢ÐÅÕ¾: ×Ï ¶¡ Ïã (Sun Nov 8 17:27:10 1998), תÐÅ
¼ÄÐÅÈË: ship.bbs@bbs.xmu.edu.cn
±ê Ìâ: NACHOSÂÛ̳(3)(ת¼Ä)
·¢ÐÅÕ¾: »ªÄÏÀí¹¤´óѧ BBSľÃÞÕ¾
ÈÕ ÆÚ: Sun Mar 9 15:01:41 1997
×÷ ¼Ò: solmon (ËùÂÞÃÅÍõ) on board 'Unix'
Ìâ Ä¿: NACHOSÂÛ̳(3)
À´ Ô´: ¹ÄÀËÌýÌÎÕ¾
ÈÕ ÆÚ: Thu Mar 6 23:04:30 1997
³ö ´¦: mysu@JingXian.xmu.edu.cn
µÚÈýÕ Îļþϵͳ
NachosÎļþϵͳµÄ½çÃæÀàËÆÓÚUNIX,ÓÐÓëUNIXµÄcreat,open,close,read,write,
lseekºÍunlinkÏàËÆ(²»ÊÇÍêÈ«Ò»Ñù)µÄϵͳµ÷ÓÃ.Ò»¸öÖØÒªµÄ²»Í¬µãÔÚÓÚNachosÎļþϵ
ͳÊÇÓÃC++ʵÏÖµÄ.Creat(Ï൱ÓÚUNIXÖеÄcreat),Open(open),ºÍRemove(unlink)¶¼ÊÇ
¶¨ÒåÔÚFileSystemÀàÖеÄ,ÒòΪËüÃǶ¼ÊÇÓëÕýÔÚ²Ù×÷µÄÎļþÃûºÍĿ¼ÏàÁªÏµµÄ.
FileSystem::Open·µ»ØÒ»¸öÖ¸Õë,ËüÖ¸ÏòÒ»¸öOpenFile¶ÔÏó,OpenFile¶ÔÏóÓëUNIXÖеÄ
´ò¿ªÎļþÃèÊö·ûÀàËÆ,¿ÉÒÔÓÃÕâ¸ö¶ÔÏóÖ±½Ó¶ÔÎļþ½øÐвÙ×÷,ÈçSeek(lseek), Read
(read), Write(write)Ö»Òª°ÑÕâ¸öOpenFile¶ÔÏóɾ³ý(delete)¾Í¿ÉÒԹرÕ(close)Õâ¸ö
ÒÑ´ò¿ªÎļþÁË.
NachosÎļþϵͳµÄ½á¹¹Èçͼ:
©³©¥©¥©¥©¥©¥©¥©¥©¥©¥©¥©¥©¥©¥©¥©¥©¥©¥©¥©¥©·
©§ ÎÄ ¼þ Óà »§ ©§
©Ç©¥©¥©¥©¥©¥©¥©¥©¥©¥©¥©¥©¥©¥©¥©¥©¥©¥©¥©¥©Ï
©§ FileSystem OpenFile Directory ©§
©Ç©¥©¥©¥©¥©¥©¥©¥©¥©¥©¥©¥©¥©¥©¥©¥©¥©¥©¥©¥©Ï
©§ FileHeader ©§
©Ç©¥©¥©¥©¥©¥©¥©¥©¥©¥©¥©¥©¥©¥©¥©¥©¥©¥©¥©¥©Ï
©§ SynchDisk ©§
©Ç©¥©¥©¥©¥©¥©¥©¥©¥©¥©¥©¥©¥©¥©¥©¥©¥©¥©¥©¥©Ï
©§ Disk ©§
©»©¥©¥©¥©¥©¥©¥©¥©¥©¥©¥©¥©¥©¥©¥©¥©¥©¥©¥©¥©¿
ÔÚNachosÎļþϵͳÖÐ,Ðí¶àÊý¾Ý½á¹¹¼È¿É´æ·ÅÔÚÄÚ´æÀï,ÓÖ¿É´æ·ÅÔÚ´ÅÅÌÀï.ΪÁËÒ»
ÖÂÆð¼û,ÎļþϵͳÖÐSynchdiskÒÔÉϵÄÀ඼ÓÐÒ»¸öFetchFrom³ÉÔ±º¯Êý,Ëü°ÑÊý¾Ý½á¹¹´Ó
´ÅÅ̶Áµ½ÄÚ´æ;»¹ÓÐÒ»¸öWriteBack³ÉÔ±º¯Êý,ËüÓëFetchFromÏà·´,°ÑÊý¾Ý½á¹¹´ÓÄÚ´æд
»Ø´ÅÅÌ.ÔÚÄÚ´æÖеÄÊý¾Ý½á¹¹Óë´ÅÅÌÉϵÄÍêÈ«Ò»ÖÂ,ûÓÐÔö¼õÊý¾ÝÏî,¸ø¹ÜÀí´øÀ´Á˲»ÉÙ
·½±ã.ÔÚÒÔºóµÄ½éÉÜÖÐÕâÁ½¸öº¯Êý²»ÔÙÖظ´ÁË.
ÈÃÎÒÃÇ´ÓÏÂÍùÉÏ·ÖÎöÎļþϵͳ.DiskÄ£ÄâÁËÒ»¸öÎïÀí´ÅÅÌ,ËüµÄ¾ßÌåʵÏÖÔÚ»úÆ÷Ä£
Äⲿ·ÖÒѾ½éÉÜÁË.
SynchDiskÀàÔÚÎïÀí´ÅÅ̵Ļù´¡É϶¨ÒåÁËÒ»¸öͬ²½´ÅÅ̵ijéÏó½çÃæ.Ïó±ðµÄI/OÉ豸
Ò»Ñù,ÎïÀí´ÅÅÌÊÇÒì²½É豸.Óû§Ìá³ö¶ÁдÇëÇóºóÁ¢¼´·µ»Ø,ÕâÒÔºó»áÓÐÒ»¸öÖжϷ¢Éú,
±¨¸æ´ÅÅ̲Ù×÷Íê³É.ͬ²½´ÅÅÌÓÐЩ²»Í¬,½ø³ÌÌá³ö¶ÁдÇëÇóºó½«Ë¯Ãߵȴý,ÒÔºóÔÚ´ÅÅÌÖ
¶ÏµÄ´¦Àíº¯ÊýÖл½ÐÑËü,ËùÒÔ½ø³Ì½«µÈ´ý´ÅÅ̲Ù×÷Íê³Éºó²ÅÄÜ·µ»Ø.
SynchDiskÀàµÄ½çÃæΪ:
©³©¥©¥©¥©¥©¥©¥©¥©¥©¥©¥©¥©
©§ SynchDisk ©§
©Ç©¥©¥©¥©¥©¥©¥©¥©¥©¥©¥©¥©Ï
©§ ReadSector ©§
©§ WriteSector ©§
©»©¥©¥©¥©¥©¥©¥©¥©¥©¥©¥©¥©¿
SynchDiskÀàµÄÉú³Éº¯ÊýÉú³ÉÁËÒ»¸öËø,Ò»¸öÐźÅÁ¿,Ò»¸öÎïÀí´ÅÅ̶ÔÏó,ÓÉÓÚÎïÀí
´ÅÅÌÒ»´ÎÖ»ÄܽÓÊÜÒ»¸ö¶ÁдÇëÇó,Ëø¾ÍÊÇÓÃÀ´ÊµÏÖ¶Áд»¥³âµÄ.ÐźÅÁ¿ÓÃÀ´ÊµÏÖÖжϳÌ
ÐòºÍ·¢³ö´ÅÅÌÇëÇóµÄ³ÌÐòÖ®¼äͬ²½¡£
ReadSector³ÉÔ±º¯ÊýµÄÖ´Ðйý³ÌÈçÏÂ:
1.¹Ø±ÕËø.(Èç¹û±ðµÄ½ø³ÌÕýÔÚ²Ù×÷´ÅÅÌ,Ôò˯Ãߵȴý±ðµÄ½ø³ÌµÄ´ÅÅ̲Ù×÷Í
³É)
2.ÏòÎïÀí´ÅÅÌ·¢¶ÁÊý¾ÝÇëÇó.
3.¶ÔÐźÅÁ¿×÷P²Ù×÷(˯Ãߵȴý´ÅÅ̲Ù×÷µÄÍê³É,½«ÓɶÁ´ÅÅ̵ÄÖжϴ¦Àí³ÌÐò
»½Ðѱ¾½ø³Ì).
4.½âËø.
WriteSector³ÉÔ±º¯ÊýµÄÖ´Ðйý³ÌÓëReadSectorÀàËÆ.
FileHeaderÀàÊÇÓÃÀ´¹ÜÀíÒ»¸öÎļþ¿éÔÚ´ÅÅÌÉÏ·Ö²¼Çé¿öµÄÊý¾Ý½á¹¹.Õâ¸öÊý¾Ý½á¹¹
³ÆΪÎļþ¿ØÖÆ¿é.Îļþ¿ØÖÆ¿éÖл¹¿ÉÒÔ°üÀ¨Ò»Ð©ÓйØÎļþµÄÐÅÏ¢,È糤¶È,ÓµÓÐÕߵȵÈ,
Îļþ¿ØÖÆ¿éÓëUNIXÖеÄi-nodeÀàËÆ.Îļþ¿ØÖÆ¿é¿ÉÒÔ·ÅÔÚÄÚ´æÖлò´ÅÅÌÀï.µ±ËüÔÚ´ÅÅÌ
Àïʱ,Ö»Õ¼ÓÃÒ»¸öÉÈÇø,NachosûÓÐʵÏÖÎļþ¿ØÖÆ¿éµÄ¼ä½Ó¶¨Î»,ËùÒÔÎļþ¿ØÖÆ¿éµÄ´óС
Êǹ̶¨µÄ,Ò²µ¼ÖÂNachosÎļþ×î´ó³¤¶ÈΪ4Kbytes.
FileHeaderµÄ½çÃæΪ:
©³©¥©¥©¥©¥©¥©¥©¥©¥©·
©§ FileHeader ©§
©Ç©¥©¥©¥©¥©¥©¥©¥©¥©Ï
©§ Allocate ©§
©§ Deallocate ©§
©§ ByteToSector ©§
©§ FileLength ©§
©Ç©¥©¥©¥©¥©¥©¥©¥©¥©Ï
©§ numBytes ©§
©§ numSectors ©§
©§ dataSectors[] ©§
©»©¥©¥©¥©¥©¥©¥©¥©¥©¿
ÆäÖÐnumBytes ΪÎļþ³¤¶È,numSectorsΪÎļþÕ¼ÓõÄÉÈÇøÊý,dataSectors[]Êý×é
Ö¸Ã÷ÎļþµÄÿ¸öÊý¾Ý¿é´æ·ÅÔÚµÚ¼¸¸öÉÈÇøÀï.ÀýÈç,ÓÐÒ»¸öÎļþ³¤¶ÈΪ200 byte,Nachos
¶¨ÒåÒ»¸öÉÈÇøµÄ³¤¶ÈΪ128 byte,ÔònumBytes=200, numSectors= ceil(200/128)=2,ÎÄ
¼þÕ¼ÓÃÁËÁ½¸öÉÈÇø,Èç¹ûÎļþµÄµÚÒ»¿é·ÅÔÚµÚ5ÉÈÇø,µÚ¶þ¿é·ÅÔÚµÚ20ÉÈÇø,Ôò
dataSectors[0]=5,dataSectors[1]=20,dataSectorsÊý×éÆäËûÔªËØÖµ²»¶¨,ҲûÓÐÓÃ.
Allocate³ÉÔ±º¯ÊýÓÃÀ´³õʼ»¯Îļþ¿ØÖÆ¿é,Ϊ±¾Îļþ·ÖÅä´ÅÅÌ¿Õ¼ä.ËüµÄÖ´Ðйý³ÌÈç
ÏÂ:
1.¸ù¾ÝÎļþ³¤¶È¶ÔnumBytes,numSectors¸³³õÖµ.
2.Èç¹ûÎļþÐèÒªµÄÉÈÇøÊý´óÓÚ´ÅÅÌÉϵĿÕÏÐÉÈÇøÊý,Ôò·µ»Øʧ°Ü.
3.¸øÎļþ·ÖÅä¿ÕÏÐÉÈÇø,°ÑÉÈÇøºÅ·ÅÈëdataSectorsÊý×é,²¢°ÑÕâЩÉÈÇøµÄʹ
ÓñêÖ¾´Ó¿ÕÏиÄΪÒÑÕ¼ÓÃ.
Deallocate³ÉÔ±º¯ÊýÊÍ·ÅÎļþÕ¼ÓõÄÉÈÇø.
ByteToSector·µ»Ø´æ·Å×ÅÎļþµÚx×Ö½ÚÊý¾ÝµÄÉÈÇøºÅ.
FileLength·µ»ØÎļþ³¤¶È.
OpenFileÀàÓÃÀ´ÊµÏÖÎļþµÄ¶Áд²Ù×÷.Nachos½«ÎļþµÄ²Ù×÷ת»¯Îª¶ÔÉÈÇøµÄ²Ù×÷.
ÔÚÏÖÓÐʵÏÖÖв¢Ã»Óп¼ÂÇÎļþϵͳµÄ²¢·¢ÎÊÌâ,ÕâЩÁô¸øѧÉú×÷Ϊ¿Î³Ì×÷Òµ.OpenFile
µÄ½çÃæΪ:
©³©¥©¥©¥©¥©¥©¥©¥©¥©·
©§ OpenFile ©§
©Ç©¥©¥©¥©¥©¥©¥©¥©¥©Ï
©§ Seek ©§
©§ ReadAt ©§
©§ WriteAt ©§
©§ Read ©§
©§ Write ©§
©§ Length ©§
©Ç©¥©¥©¥©¥©¥©¥©¥©¥©Ï
©§ seekPosition ©§
©§ FileHeader* hdr©§
©»©¥©¥©¥©¥©¥©¥©¥©¥©¿
seekPositionÊÇÎļþµ±Ç°¶ÁдָÕë,hdrÊÇÎļþ¿ØÖÆ¿éµÄµØÖ·.OpenFileµÄÉú³Éº¯Êý
´øÓÐÒ»¸öintÐ͵IJÎÊý,Ö¸Ã÷´æ·ÅÎļþ¿ØÖÆ¿éµÄÉÈÇøºÅ.Éú³Éº¯ÊýÏȸøhdr·ÖÅä¿Õ¼ä,È»ºó
´Ó´ÅÅÌÖжÁ³öÕâ¸öÎļþµÄÎļþ¿ØÖÆ¿é,·ÅÈëhdrÖ¸ÏòµÄÄÚ´æ.seekPositon ¸³Îª0,ʹµÃÎÄ
¼þµ±Ç°¶ÁдָÕëÖ¸ÏòÎļþ¿ªÍ·.
Seek³ÉÔ±º¯Êý½«Îļþµ±Ç°¶ÁдָÕëÒƵ½ÐµÄλÖÃ.
ReadAt/WriteAtÓÃÓÚ¶ÁдÊý¾Ý.¶ÁдµÄ¿ªÊ¼Î»ÖúͶÁдÊý¾Ý³¤¶ÈÓɲÎÊýÖ¸¶¨.ÓÉÓÚ
NachosÎļþ³¤¶È²»¿É¸Ä±ä,ËùÒÔ³¬¹ýÎļþ³¤¶ÈµÄ¶Áд¶¼±»ºöÂÔ.ÓÖÒòΪ´ÅÅ̶Áдµ¥Î»ÊÇ
Õû¸öÉÈÇø,ËùÒÔReadAt¶Á³ö°üÀ¨Òª¶ÁÊý¾ÝµÄËùÓÐÉÈÇø,È»ºóÖ»°ÑÒªÇó¶Á³öµÄÊý¾Ý¿½±´¸ø
µ÷ÓÃÕß.WriteAtÏȶÁ³öдÈëÊý¾ÝËùÔÚµÄÈ«²¿ÉÈÇø,È»ºó°ÑÐÂÊý¾ÝдÈëÒªÐ޸ĵÄλÖÃ,×î
ºó½«ÕâЩÉÈÇøд»Ø´ÅÅÌ,ÕâÑù¾Í±£Ö¤Á˲»»á¸²¸Ç²»Ó¦±»Ð޸ĵIJ¿·Ö.ÕâÁ½¸öº¯Êý·µ»Øʵ
¼Ê¶Á/дµÄ³¤¶È.
Read/Write³ÉÔ±º¯Êý·Ö±ðµ÷ÓÃReadAt/WriteAt³ÉÔ±º¯Êý,´ÓÎļþµ±Ç°¶ÁдָÕë´¦¿ª
ʼ¶Á/дÊý¾Ý.ËüµÄÖ´Ðйý³ÌÈçÏÂ:
1.·Ö±ðµ÷ÓÃReadAt/WriteAtº¯Êý´ÓÎļþµ±Ç°¶ÁдָÕë´¦¿ªÊ¼¶Á/дÊý¾Ý.
2.Îļþµ±Ç°¶ÁдָÕëÏòºóÒƶ¯Êµ¼Ê¶Á/дµÄ³¤¶È.
3.·µ»Øʵ¼Ê¶Á/дµÄ³¤¶È.
Length·µ»ØÎļþ³¤¶È.
NachosµÄĿ¼ÊÇÓÉÒ»×éĿ¼Ïî×é³É,ÿ¸öĿ¼Ïî´ú±íÒ»¸öÎļþ.Ŀ¼ÏîµÄÄÚÈÝÓÐ:ÒÑ
ʹÓñêÖ¾inUse,Îļþ¿ØÖÆ¿éËùÔÚÉÈÇøºÅsector,ÎļþÃû×Öname,ÎļþÃûÓÐ×î´ó³¤¶È,ÕâÑù
ÿ¸öĿ¼ÏÓй̶¨³¤¶È.µ±ÎÒÃÇÖªµÀÎļþËùÔÚĿ¼ºÍÎļþÃûºó,¾Í¿ÉÒÔ´ÓËüËùÔÚĿ¼
ÖÐÕÒµ½Ãû×ÖÓëÖ®ÏàͬµÄĿ¼Ïî,ÓÚÊǾͿÉÒÔÖªµÀ´ËÎļþµÄÎļþ¿ØÖÆ¿éËùÔÚÉÈÇø,¶øÎļþ
¿ØÖÆ¿éÖмǼÁËÎļþÄÚÈÝËùÔÚµÄÉÈÇøºÅ,ÕâÑù¾Í¿ÉÒÔ¶ÁдÕâ¸öÎļþÁË.ÓëÎļþϵͳµÄÆä
ËûÊý¾Ý½á¹¹Ò»Ñù,Ŀ¼½á¹¹¼È¿ÉÒÔ·ÅÔÚÄÚ´æÖÐ,ÓÖ¿ÉÒÔ·ÅÔÚ´ÅÅÌÉÏ.µ±Ëü´æ·ÅÔÚ´ÅÅÌÉÏʱ,
ÊÇ×÷Ϊһ¸ö³£¹æµÄNachosÎļþ´æ´¢µÄ,ÓÉÓÚNachosÎļþ³¤¶È¹Ì¶¨,ËùÒÔĿ¼µÄĿ¼Ïî¸ö
ÊýÔÚÉú³ÉĿ¼ʱ¾Í¹Ì¶¨ÁË,ÒÔºó²»Äܸıä.ÏÖÓÐʵÏÖÖÐ,¶ÔĿ¼²Ù×÷µÄ»¥³âÊÇÓɵ÷ÓÃÕß±£
Ö¤µÄ.
Ŀ¼µÄ½çÃæΪ:
©³©¥©¥©¥©¥©¥©¥©¥©¥©·
©§ Directory ©§
©Ç©¥©¥©¥©¥©¥©¥©¥©¥©Ï
©§ Find ©§
©§ Add ©§
©§ Remove ©§
©§ List ©§
©§ FindIndex ©§
©Ç©¥©¥©¥©¥©¥©¥©¥©¥©Ï
©§ tableSize ©§
©§ table ©§
©»©¥©¥©¥©¥©¥©¥©¥©¥©¿
tableSize·ÅµÄÊÇĿ¼ÏîµÄ¸öÊý,tableÊÇĿ¼ÏîÊý×éµÄµØÖ·.
DirectoryÀàµÄÉú³Éº¯ÊýµÄÖ´Ðйý³ÌÈçÏÂ:
1.´ËĿ¼µÄĿ¼Ïî¸öÊýÓɲÎÊý´«Èë,ÓÃÕâ¸ö²ÎÊý¸ø
tableSize¸³Öµ.
2.¸øĿ¼ÏîÊý×étable·ÖÅä¿Õ¼ä,ËüµÄÔªËظöÊýΪtableSize.
3.½«ËùÓÐĿ¼ÏîµÄʹÓñêÖ¾ÇåÁã.
Ò»¸öĿ¼Àà¶ÔÏó²ÅÉú³Éʱ,Ŀ¼ÏîÄÚÈÝ×ÜÊÇ¿ÕµÄ,Èç¹ûÕâ¸öĿ¼ÒѾ´æÔÚ,¾ÍÐèÒªÓÃ
FetchFrom³ÉÔ±º¯Êý°ÑĿ¼ÏîÄÚÈÝ´Ó´ÅÅÌÉ϶Á³öÀ´.
FindIndex(char* name)³ÉÔ±º¯ÊýÔÚĿ¼ÖÐÑ°ÕÒÎļþÃûΪnameµÄÎļþ,Èç¹ûÕÒµ½¾Í
·µ»Ø´ËÎļþÔÚĿ¼ÏîÊý×éÖеÄË÷Òý,·ñÔò·µ»Ø-1.
Fine(char* name)³ÉÔ±º¯ÊýÔÚĿ¼ÖÐÑ°ÕÒÎļþÃûΪnameµÄÎļþ,Èç¹ûÕÒµ½¾Í·µ»Ø´Ë
ÎļþµÄÎļþ¿ØÖÆ¿éËùÔÚÉÈÇøºÅ,·ñÔò·µ»Ø-1.
bool Add( char* name,int newSector) º¯ÊýÔö¼ÓÒ»¸öÎļþµ½Ä¿Â¼ÖÐ,Õâ¸öÎļþµÄ
Ãû×ÖΪname,Îļþ¿ØÖÆ¿éËùÔÚÉÈÇøºÅΪnewSector.Èç¹ûÌí¼Ó³É¹¦,·µ»ØTRUE.ÔÚÏÂÁÐÇé¿ö
·µ»ØFALSE:
1.Ŀ¼ÖÐÒѾ´æÔÚÕâ¸öÎļþÃû.
2.Ŀ¼ÒÑÂú.
bool Remove( char* name ) °ÑÃû×ÖΪnameµÄÎļþ´ÓĿ¼ÖÐɾ³ý.Èç¹û³É¹¦·µ»Ø
TRUE.ÈôÔÚĿ¼ÖÐûÓÐÕâ¸öÎļþ,Ôòʧ°Ü,·µ»ØFALSE.
List() ÏÔʾĿ¼ÖÐËùÓеÄÎļþ.
FileSystemÊÇNachosµÄÎļþϵͳµÄ¶¥²ã½çÃæ.ËüÌṩÁËһЩÓÃÎļþÃûÀ´²Ù×÷ÎļþµÄ
¹¦ÄÜ.
FileSystemµÄ½çÃæΪ:
©³©¥©¥©¥©¥©¥©¥©¥©¥©·
©§ FileSystem ©§
©Ç©¥©¥©¥©¥©¥©¥©¥©¥©Ï
©§ Creat ©§
©§ Open ©§
©§ Remove ©§
©§ List ©§
©Ç©¥©¥©¥©¥©¥©¥©¥©¥©Ï
©§ freeMapfile ©§
©§ directoryFile ©§
©»©¥©¥©¥©¥©¥©¥©¥©¥©¿
ÆäÖÐfreeMapfileºÍdirectoryFileÊÇÁ½¸öOpenFileÀàµÄÖ¸Õë.
freeMapfileÖ¸ÏòÓÃÀ´¹ÜÀí´ÅÅÌ¿Õ¼äµÄBitMapÎļþ.´ÅÅ̵Äÿ¸öÉÈÇø¶ÔÓ¦BitMapÖÐ
µÄһλ,Èç¹ûÔÚBitMapÖÐÕâλΪ0,Ôò˵Ã÷´ËÉÈÇøΪ¿Õ,·ñÔò˵Ã÷´ËÉÈÇøÒѱ»Ä³¸öÎļþÕ¼
ÓÃ.directoryFileÖ¸Ïò¸ùĿ¼Îļþ.NachosûÓÐʵÏֶ༶Ŀ¼½á¹¹,ËüÖ»ÓÐÒ»¸ö¸ùĿ¼,
ÎļþϵͳµÄËùÓÐÎļþ¶¼·ÅÔÚ¸ùĿ¼ÏÂ.
FileSystemµÄÉú³Éº¯ÊýÓÐÒ»¸öformat²ÎÊý,Èç¹ûËüΪ·ÇÁã,½«¸ñʽ»¯(Format)Õû¸ö
Îļþϵͳ,·ñÔò´ÓÄ£Äâ´ÅÅÌÉ϶Á³öÎļþϵͳµÄÐÅÏ¢.
FormatÎļþϵͳµÄ¹ý³ÌΪ:
1.Éú³ÉÒ»¸ö¿ÕµÄBitMapºÍ¸ùĿ¼.
2.°Ñ´ÅÅÌ0ÉÈÇø·ÖÅä¸øfreeMapfileÎļþµÄÎļþ¿ØÖÆ¿é;
1ÉÈÇø·ÖÅä¸ø¸ùĿ¼µÄÎļþ¿ØÖÆ¿é.
3.ΪÕâÁ½¸öÎļþ·ÖÅä´ÅÅÌ¿Õ¼ä.
4.´ò¿ªÕâÁ½¸öÎļþ,¼´ÔÚÄÚ´æÖÐÉú³ÉÁ½¸öOpenFile¶ÔÏó.
5.°ÑfreeMapfile,directoryFileÁ½¸öÎļþд»Ø´ÅÅÌ.
6.Êͷź¯ÊýÖзÖÅäµÄ¸¨ÖúÄÚ´æ¿Õ¼ä,µ«freeMapfileºÍdirectoryFileÕâÁ½¸ö
OpenFile¶ÔÏóÈÔÈ»±£ÁôÔÚÄÚ´æÖÐ.
Èç¹ûÉú³ÉÎļþϵͳʱ²»ÐèÒª¸ñʽ»¯,¾ÍÖ»Òª´Ó´ÅÅÌÉ϶Á³öfreeMapfile,
directoryFileÁ½¸öÎļþ¼´¿É.
ÎļþϵͳÉú³Éºó,freeMapfile,directoryFileÕâÁ½¸öOpenFile¶ÔÏó×ÜÊDZ£ÁôÔÚÄÚ
´æÖеÄ.
Creat(char* name, int initialSize)³ÉÔ±º¯ÊýÓÃÀ´´´½¨Ò»¸öÐÂÎļþ,ÐÂÎļþµÄÃû
×ÖÊÇname,³¤¶ÈΪinitialSize,ËüµÄÖ´Ðйý³ÌÈçÏÂ:
©³©¥©¥©¥©¥©¥©¥©¥©¥©·
©§ ´Ó´ÅÅ̶ÁÈë¸ù ©§
©§ Ŀ¼Îļþ ©§
©»©¥©¥©¥©×©¥©¥©¥©¥©¿
©§
¡ý
©¥©¥©¥©¥©¥©¥©¥©¥©¥
Ŀ¼ÖÐÒѾ Y
´æÔÚͬÃûÎļþ ©¥©¥©¥©¥©¥©¥©·
©¥©¥©¥©¥©¥©¥©¥©¥©¥ ©§
©§ ©§
©§ N ©§
¡ý ©§
©³©¥©¥©¥©¥©¥©¥©¥©¥©· ©§
©§´Ó´ÅÅ̶ÁÈëBitMap©§ ©§
©§Îļþ,¸øÎļþ¿ØÖÆ ©§ ©§
©§¿é·ÖÅäÒ»¸öÉÈÇø ©§ ©§
©»©¥©¥©¥©×©¥©¥©¥©¥©¿ ©§
©§ ©§
©§ ©§
¡ý ©§
©¥©¥©¥©¥©¥©¥©¥ N ©§
·ÖÅä³É¹¦ ©¥©¥©¥©¥©¥©¥©¥¡ú©§
©¥©¥©¥©¥©¥©¥©¥ ©§
©§ ©§
©§ Y ©§
¡ý ©§
©³©¥©¥©¥©¥©¥©¥©¥©¥©· ©§
©§ ½«Îļþ¼ÓÈë¸ù ©§ ©§
©§ Ŀ¼ ©§ ©§
©»©¥©¥©¥©×©¥©¥©¥©¥©¿ ©§
©§ ©§
¡ý ©§
©¥©¥©¥©¥©¥©¥ N ©§
³É¹¦¼ÓÈë ©¥©¥©¥©¥©¥©¥©¥¡ú©§
©¥©¥©¥©¥©¥©¥ ©§
©§ ©§
©§ Y ©§
¡ý ©§
©³©¥©¥©¥©¥©¥©¥©¥©¥©· ©§
©§ ΪÎļþ·ÖÅä ©§ ©§
©§ ´ÅÅÌ¿Õ¼ä ©§ ©§
©»©¥©¥©¥©×©¥©¥©¥©¥©¿ ©§
©§ ©§
¡ý ©§
©¥©¥©¥©¥©¥©¥ N ©§
·ÖÅä³É¹¦ ©¥©¥©¥©¥©¥©¥©¥¡ú©§
©¥©¥©¥©¥©¥©¥ ©§
©§ ©§
©§ Y ©§
¡ý ©§
©³©¥©¥©¥©¥©¥©¥©¥©¥©· ©§
©§ ½«BitMapÎļþºÍ ©§ ©§
©§ ¸ùĿ¼ÎļþдÈë ©§ ©§
©§ ´ÅÅÌ ©§ ©§
©»©¥©¥©¥©×©¥©¥©¥©¥©¿ ©§
©§ ©§
©§ ©§
¡ý ¡ý
©³©¥©¥©¥©¥©¥©¥©¥©¥©· ©³©¥©¥©¥©¥©¥©¥©¥©¥©·
©§ ·µ»ØTRUE ©§ ©§ ·µ»ØFALSE ©§
©»©¥©¥©¥©¥©¥©¥©¥©¥©¿ ©»©¥©¥©¥©¥©¥©¥©¥©¥©¿
ÔÚCreatº¯ÊýµÄ´¦Àí¹ý³ÌÖÐÖ»ÐÞ¸ÄÄÚ´æÖеÄBitMapºÍ¸ùĿ¼,´ÅÅÌÉϵÄÊý¾Ý²»»á±»
ÐÞ¸Ä,ÕâÑùÈç¹ûÎļþÉú³Éʧ°Ü,Ö»Òª·µ»ØFALSE¼´¿É.Èç¹ûÖ´Ðгɹ¦,²Å°ÑÕâÁ½¸öÎļþд
»Ø´ÅÅÌ.
Remove(char* name)ɾ³ýÎļþÃûΪnameµÄÎļþ.ËüµÄÖ´Ðйý³ÌÈçÏÂ:
1.´Ó´ÅÅ̶ÁÈë¸ùĿ¼Îļþ.
2.Èç¹û¸ùĿ¼ÖÐûÓÐÕâ¸öÎļþ,Ôò·µ»ØFALSE.
3.¶ÁÈë´ËÎļþµÄÎļþ¿ØÖÆ¿é.
4.ÊÍ·Å´ËÎļþÕ¼ÓõĴÅÅÌÉÈÇø,²¢É¾³ýÆäĿ¼Ïî.
5.ÊÍ·Å´ËÎļþµÄÎļþ¿ØÖÆ¿éÕ¼ÓõĴÅÅÌÉÈÇø.
6.°ÑÐ޸ĺóµÄBitMapºÍĿ¼Îļþд»Ø´ÅÅÌ.
7.·µ»ØTRUE.
OpenFile* Open(char* name)³ÉÔ±º¯Êý´ò¿ªÃûΪnameµÄÎļþ,¿ÉÒÔÓ÷µ»ØµÄ
OpenFileÖ¸Õë¶Áд´ËÎļþ.OpenµÄÖ´Ðйý³ÌÈçÏÂ:
1.½«Ä¿Â¼Îļþ¶ÁÈëÄÚ´æ.
2.ÓÃDirectory::Find(char* name)º¯ÊýÇó³önameÎļþµÄÎļþ¿ØÖÆ¿éËùÔÚÉÈ
Çø.
3.¶ÁÈëÎļþ¿ØÖÆ¿é,²¢Éú³É´ËÎļþµÄOpenFile¶ÔÏó.
4.·µ»ØOpenFile¶ÔÏóµÄÖ¸Õë.
List³ÉÔ±º¯ÊýÏÔʾ¸ùĿ¼µÄÄÚÈÝ.
¹Ø±ÕÎļþÖ»Ðëɾ³ý(delete)OpenFile¶ÔÏó¼´¿É.
--
m¡ù À´Ô´:£®¹ÄÀËÌýÌÎÕ¾ bbs.xmu.edu.cn£®[FROM: mysu@JingXian.xmu.ed] m
--
m;32m¡ù ת¼Ä:£®»ªÄÏÍøľÃÞÕ¾ bbs.gznet.edu.cn£®[FROM: mtlab.hit.edu.cn]
--
Enjoy Linux!
-----It's FREE!-----
¡ù À´Ô´:£®×Ï ¶¡ Ïã bbs.hit.edu.cn£®[FROM: mtlab.hit.edu.cn]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
Ò³ÃæÖ´ÐÐʱ¼ä£º206.631ºÁÃë