📄 fat.lst
字号:
48 2
49 2 if(!RBC_Read(xxgFatSecNum,1,FATBUF))
50 2 return 0xFFFF;
51 2 ThisFile.FatSectorPointer=xxgFatSecNum;
52 2 }
53 1
54 1 ///////////////////////////////////////////////////
55 1 clusterNum=FATBUF[xxgFatEntOffset+1];
56 1 clusterNum=clusterNum<<8;
57 1 clusterNum+=FATBUF[xxgFatEntOffset];
58 1 return clusterNum;
59 1 }
60
61 unsigned char DeleteClusterLink(unsigned int clusterNum)
62 {
63 1 //unsigned int nextClusterNum;
64 1 unsigned int xxgFatSecNum,xxgFatEntOffset;
65 1 //nextClusterNum=GetNextClusterNum(clusterNum);
C51 COMPILER V7.20 FAT 12/13/2005 15:28:02 PAGE 4
66 1 ////////////////////////////////////////////
67 1 //nextClusterNum=clusterNum;
68 1 while((clusterNum>1)&&(clusterNum<0xfff0))
69 1 {
70 2 xxgFatSecNum=ThisFatSecNum(clusterNum);
71 2 xxgFatEntOffset=ThisFatEntOffset(clusterNum);
72 2 if(RBC_Read(xxgFatSecNum,1,DBUF))
73 2 {
74 3 clusterNum=DBUF[xxgFatEntOffset+1];
75 3 clusterNum=clusterNum<<8;
76 3 clusterNum+=DBUF[xxgFatEntOffset];
77 3 //return clusterNum;
78 3 }
79 2 else
80 2 return FALSE;
81 2 DBUF[xxgFatEntOffset]=0x00;
82 2 DBUF[xxgFatEntOffset+1]=0x00;
83 2 //DelayMs(5);
84 2 if(!RBC_Write(xxgFatSecNum,1,DBUF))
85 2 return FALSE;
86 2 //DelayMs(5);
87 2 if(!RBC_Write(xxgFatSecNum+DeviceInfo.BPB_FATSz16,1,DBUF))
88 2 return FALSE;
89 2 ////////////////////////////////////////////
90 2 }
91 1 return TRUE;
92 1 }
93
94 unsigned int GetClusterNumFromSectorNum(unsigned long sectorNum)
95 {
96 1 unsigned long temp;
97 1 temp=sectorNum-DeviceInfo.FirstDataSector;
98 1 temp=temp/DeviceInfo.BPB_SecPerClus;
99 1 temp=temp+2;
100 1 return (unsigned int)temp;
101 1 }
102 /*
103 unsigned long GetSecNumFromPointer(void)
104 {
105 unsigned int clusterNum,clusterSize;
106 unsigned long temp,pointer;
107 pointer=ThisFile.FilePointer;
108 clusterSize=DeviceInfo.BPB_SecPerClus*DeviceInfo.BPB_BytesPerSec;
109 clusterNum=ThisFile.StartCluster;
110 while(pointer>clusterSize)
111 {
112 pointer-=clusterSize;
113 clusterNum=GetNextClusterNum(clusterNum);
114 }
115 temp=FirstSectorofCluster(clusterNum)+pointer/DeviceInfo.BPB_BytesPerSec;
116 return temp;
117 }
118 */
119 unsigned char GoToPointer(unsigned long pointer)
120 {
121 1 //unsigned char temp;
122 1 unsigned int clusterSize;
123 1 //unsigned long temp;
124 1 //pointer=ThisFile.FilePointer;
125 1 clusterSize=DeviceInfo.BPB_SecPerClus*DeviceInfo.BPB_BytesPerSec;
126 1 ThisFile.ClusterPointer=ThisFile.StartCluster;
127 1 while(pointer>clusterSize)
C51 COMPILER V7.20 FAT 12/13/2005 15:28:02 PAGE 5
128 1 {
129 2 pointer-=clusterSize;
130 2 ThisFile.ClusterPointer=GetNextClusterNum(ThisFile.ClusterPointer);
131 2 if(ThisFile.ClusterPointer==0xffff)
132 2 {
133 3 return FALSE;
134 3 }
135 2 }
136 1 ThisFile.SectorofCluster=pointer/DeviceInfo.BPB_BytesPerSec;
137 1 ThisFile.SectorPointer=FirstSectorofCluster(ThisFile.ClusterPointer)+ThisFile.SectorofCluster;
138 1 ThisFile.OffsetofSector=pointer-ThisFile.SectorofCluster*DeviceInfo.BPB_BytesPerSec;
139 1 ThisFile.FatSectorPointer=0;
140 1 return TRUE;
141 1
142 1 }
143
144 unsigned int GetFreeCusterNum(void)
145 {
146 1 unsigned int clusterNum,i;
147 1 unsigned long sectorNum;
148 1 clusterNum=0;
149 1 sectorNum=DeviceInfo.FatStartSector;
150 1 while(sectorNum<DeviceInfo.BPB_FATSz16+DeviceInfo.FatStartSector)
151 1 {
152 2
153 2 if(!RBC_Read(sectorNum,1,DBUF))
154 2 return 0x0;
155 2 for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+2)
156 2 {
157 3 //clusterNum++;
158 3
159 3 if((DBUF[i]==0)&&(DBUF[i+1]==0))
160 3 {
161 4 DBUF[i]=0xff;
162 4 DBUF[i+1]=0xff;
163 4 //DelayMs(10);
164 4 if(!RBC_Write(sectorNum,1,DBUF))
165 4 return 0x00;
166 4 //DelayMs(10);
167 4 if(!RBC_Write(sectorNum+DeviceInfo.BPB_FATSz16,1,DBUF))
168 4 return 0x00;
169 4
170 4 return clusterNum;
171 4 }
172 3 clusterNum++;
173 3 }
174 2
175 2 sectorNum=2*clusterNum/DeviceInfo.BPB_BytesPerSec+DeviceInfo.FatStartSector;
176 2 //clusterNum+=DeviceInfo.BPB_BytesPerSec;
177 2 //DelayMs(10);
178 2 }
179 1
180 1 return 0x0;
181 1 }
182
183 unsigned int CreateClusterLink(unsigned int currentCluster)
184 {
185 1 unsigned int newCluster;
186 1 unsigned int xxgFatSecNum,xxgFatEntOffset;
187 1
188 1 newCluster=GetFreeCusterNum();
189 1
C51 COMPILER V7.20 FAT 12/13/2005 15:28:02 PAGE 6
190 1 xxgFatSecNum=ThisFatSecNum(currentCluster);
191 1 xxgFatEntOffset=ThisFatEntOffset(currentCluster);
192 1 if(RBC_Read(xxgFatSecNum,1,DBUF))
193 1 {
194 2 //clusterNum=DBUF[xxgFatEntOffset+1];
195 2 //clusterNum=clusterNum<<8;
196 2 //clusterNum+=DBUF[xxgFatEntOffset];
197 2 //return clusterNum;
198 2 DBUF[xxgFatEntOffset]=newCluster;
199 2 DBUF[xxgFatEntOffset+1]=newCluster>>8;
200 2 //DelayMs(5);
201 2 if(!RBC_Write(xxgFatSecNum,1,DBUF))
202 2 return 0x00;
203 2 //DelayMs(10);
204 2 if(!RBC_Write(xxgFatSecNum+DeviceInfo.BPB_FATSz16,1,DBUF))
205 2 return 0x00;
206 2 }
207 1 else
208 1 return 0x00;
209 1
210 1 return newCluster;
211 1 }
C51 COMPILATION COMPLETE. 0 WARNING(S), 114 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -