📄 api.lst
字号:
210 1 Cluster=SecToCluster(ApiFileControl.CurrentSectorNum);
211 1 // Sector=ClusterToSec(Cluster);
212 1 ApiFileControl.SectorOffset=ApiFileControl.SectorOffset%(SimpleBpb.BytsPerSec*SimpleBpb.SecPerClus);
213 1 for(; ; )
214 1 {
215 2 pCache=BuffFile;
216 2 pCache+=ApiFileControl.SectorOffset;
217 2 if((SimpleBpb.BytsPerSec*SimpleBpb.SecPerClus - ApiFileControl.SectorOffset) > (bytes - read_bytes))
218 2 max_copy_bytes_in_sector = (bytes - read_bytes);
219 2 else
220 2 max_copy_bytes_in_sector=(SimpleBpb.BytsPerSec*SimpleBpb.SecPerClus - ApiFileControl.SectorOffset);
221 2 ApiFileControl.SectorOffset+=max_copy_bytes_in_sector;
222 2 if(!Read(ApiFileControl.CurrentSectorNum,SimpleBpb.SecPerClus,(BYTE *)BuffFile))
223 2 return FALSE;
224 2 memcpy((char *)buffer, pCache, max_copy_bytes_in_sector);
225 2 // return TRUE;
226 2 read_bytes+=max_copy_bytes_in_sector;
227 2 if(read_bytes>=bytes)
228 2 return TRUE;
229 2 buffer = (char*)buffer + max_copy_bytes_in_sector;
230 2 Cluster=GetListCluster(Cluster);
231 2 ApiFileControl.SectorOffset=0;
232 2 ApiFileControl.CurrentSectorNum=ClusterToSec(Cluster);
233 2
234 2 }//---------end for cycle
235 1 return FALSE;
236 1 }
*** WARNING C280 IN LINE 199 OF API.C: 'i': unreferenced local variable
237 BYTE CloseFile()
238 {
239 1 BYTE Cache[512];
C51 COMPILER V7.06 API 07/30/2008 08:56:14 PAGE 5
240 1 struct _DIR *dir;
241 1 ////////////////////////////////////////////////////////////////////////
242 1 if(ApiFileControl.SectorOffset!=0)
243 1 {
244 2 if(!Write(ApiFileControl.CurrentSectorNum,SimpleBpb.SecPerClus,(unsigned char *)BuffFile,TRUE))
245 2 if(!Write(ApiFileControl.CurrentSectorNum,SimpleBpb.SecPerClus,(unsigned char *)BuffFile,TRUE))
246 2 return FALSE;
247 2 }
248 1 DelayMs(50);
249 1 if(!Read(ApiFileControl.DirSectorNum,1,Cache))
250 1 if(!Read(ApiFileControl.DirSectorNum,1,Cache))
251 1 return FALSE;
252 1 dir = (struct _DIR *)Cache;
253 1 dir += ApiFileControl.DirIndex;
254 1 ApiFileControl.dir.FileSize=DWordSwap(ApiFileControl.dir.FileSize);
255 1 memcpy(dir, &ApiFileControl.dir, sizeof(struct _DIR));
256 1 DelayMs(50);
257 1 if(!Write(ApiFileControl.DirSectorNum,1,Cache,TRUE))
258 1 if(!Write(ApiFileControl.DirSectorNum,1,Cache,TRUE))
259 1 return FALSE;
260 1 if(FatCache[0][256]!=0)
261 1 {
262 2 if(!Write(FatCache[0][256],1,(BYTE *)FatCache[0],0))
263 2 if(!Write(FatCache[0][256],1,(BYTE *)FatCache[0],0))
264 2 return FALSE;
265 2 }
266 1 return TRUE;
267 1 }
268 BYTE SetFileSector(const char * filename,DWORD fileSector,DWORD offset)
269 {
270 1 DWORD FileFirstSector;
271 1 WORD Cluster;
272 1 ////////////////////////////////////////////////////////////////////////
273 1 FileFirstSector=LocateFile(filename, &ApiFileControl);
274 1 if(FileFirstSector==0xffffffff)
275 1 return FALSE;
276 1 ApiFileControl.StartSectorNum = FileFirstSector;
277 1 Cluster=WordSwap(ApiFileControl.dir.FstClusLO);
278 1 for(;;)
279 1 {
280 2 if((GetListCluster(Cluster)==0xffff)||(Cluster==0))
281 2 break;
282 2 Cluster=GetListCluster(Cluster);
283 2 }
284 1 //ApiFileControl.CurrentSectorNum为该簇对应的第一个扇区
285 1 //扇区号移到到了该文件最后一簇的第一个扇区
286 1 if((ClusterToSec(Cluster))>=fileSector>=0)
287 1 ApiFileControl.CurrentSectorNum =fileSector;
288 1 else
289 1 return FALSE;
290 1 ApiFileControl.SectorOffset=offset;
291 1 // ApiFileControl.SectorOffset=(DWordSwap(ApiFileControl.dir.FileSize)%(SimpleBpb.BytsPerSec*SimpleBpb.Sec
-PerClus));
292 1 ApiFileControl.dir.FileSize=DWordSwap(ApiFileControl.dir.FileSize);
293 1 return TRUE;
294 1
295 1 }
296 BYTE DisplayFile()
297 {
298 1 WORD i,j=0,k=0;
299 1 BYTE buf[512];
300 1 struct _DIR *dir;
C51 COMPILER V7.06 API 07/30/2008 08:56:14 PAGE 6
301 1 for(i=0;i<FatParameter.RootDirSectors;i++)
302 1 {
303 2 if(!Read(FatParameter.FirstRootDirSecNum+i,1,buf))
304 2 return FALSE;
305 2 dir=(struct _DIR *)buf;
306 2 for(dir = (struct _DIR *)buf; (BYTE*)dir < buf + SimpleBpb.BytsPerSec; dir++)
307 2 {
308 3 if(dir->Name[0] !='\0')
309 3 {
310 4 // buf=buf+32;
311 4 memcpy((BuffFile+k), (buf+j), 11);
312 4 j+=sizeof(struct _DIR);
313 4 k+=11;
314 4 }
315 3 else if(dir->Name[0]==0)
316 3 return TRUE;
317 3 }
318 2 }
319 1 return FALSE;
320 1 }
321 BYTE DelFile(const char * filename)
322 {
323 1 DWORD FileFirstSector;
324 1 BYTE buf[512];
325 1 WORD Cluster,Cache[256];
326 1 struct _DIR *dir;
327 1 FileFirstSector=LocateFile(filename, &ApiFileControl);
328 1 if(FileFirstSector==0xffffffff)
329 1 return FALSE;
330 1 dir=(struct _DIR *)buf;
331 1 if(!Read(ApiFileControl.DirSectorNum,1,buf))
332 1 return FALSE;
333 1 ApiFileControl.dir.Name[0]=0xe5;
334 1 dir=dir+ApiFileControl.DirIndex;
335 1 memcpy(dir,&ApiFileControl.dir,sizeof(struct _DIR));
336 1 if(!Write(ApiFileControl.DirSectorNum ,1,buf))
*** WARNING C209 IN LINE 336 OF API.C: '_Write': too few actual parameters
337 1 return FALSE;
338 1 Cluster=WordSwap(ApiFileControl.dir.FstClusLO);
339 1 if(!Read(((2*Cluster/SimpleBpb.BytsPerSec)+FatParameter.FirstFatSecNum),1,(BYTE *)Cache))
340 1 return FALSE;
341 1 for(;;)
342 1 {
343 2
344 2 // Cluster=GetListCluster(Cluster);
345 2 Cache[(Cluster%(SimpleBpb.BytsPerSec/2))]=0;
346 2 if((Cluster%(SimpleBpb.BytsPerSec/2))==0)
347 2 {
348 3 if(!Write((2*Cluster/SimpleBpb.BytsPerSec)+FatParameter.FirstFatSecNum,1,(BYTE *)Cache))
*** WARNING C209 IN LINE 348 OF API.C: '_Write': too few actual parameters
349 3 return FALSE;
350 3 if(!Read((2*Cluster/SimpleBpb.BytsPerSec)+FatParameter.FirstFatSecNum),1,(BYTE *)Cache)
*** WARNING C209 IN LINE 350 OF API.C: '_Read': too few actual parameters
351 3 return FALSE;
352 3 }
353 2 Cluster=GetListCluster(Cluster);
354 2 if((GetListCluster(Cluster)==0xffff)||(Cluster==0))
355 2 {
356 3 Cache[(Cluster%(SimpleBpb.BytsPerSec/2))]=0;
357 3 break;
358 3 }
359 2 }
C51 COMPILER V7.06 API 07/30/2008 08:56:14 PAGE 7
360 1 if(!Write((2*Cluster/SimpleBpb.BytsPerSec)+FatParameter.FirstFatSecNum,1,(BYTE *)Cache))
*** WARNING C209 IN LINE 360 OF API.C: '_Write': too few actual parameters
361 1 return FALSE;
362 1 return TRUE;
363 1 }
364 BYTE CreateDir(const char * dirname)
365 {
366 1 BYTE Dotname[]={0X2E,0X20,0X20,0X20,0X20,0X20,0X20,0X20,0X20,0X20,0X20};
367 1 BYTE DotDotname[]={0x2e,0x2e,0X20,0X20,0X20,0X20,0X20,0X20,0X20,0X20,0X20};
368 1 WORD NewCluster,buf[256];
369 1 struct _DIR dir,*pdir;
370 1 BYTE temp[12],NewDirName[11],NewFileName[12],name[11],Cache[512],path[22],i;
371 1 BYTE * p=temp,*p1=NewFileName,*p2;
372 1 struct _FILE file;
373 1 ////////////////////////////////////////////////////////////////////////
374 1 i=0;
375 1 memset(NewDirName,0,11);
376 1 strcpy(path, dirname);
377 1 while(path[i]!='\\')
378 1 {
379 2
380 2 NewDirName[i]=path[i];
381 2 i++;
382 2 if(i>=strlen(dirname))
383 2 break;
384 2 }
385 1 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1
386 1 //核对目录名是否正确
387 1 if(!CheckFileName(NewDirName,p))
388 1 return FALSE;
389 1 //*核对该目录是否已经存在
390 1 if(LocateFile(NewDirName, NULL)!=0xffffffff)
391 1 return FALSE;
392 1 strncpy(name, p, 11);
393 1 memset(&dir, 0, sizeof(dir));
394 1 memcpy(dir.Name, name, 11);
395 1 //定位该目录并获取必要信息
396 1 if(!LocateDir(&dir,&file))
397 1 return FALSE;
398 1 //为该目录寻找一个空簇
399 1 NewCluster= SeekEmptyCluster();
400 1 if(NewCluster==0xffff)
401 1 return FALSE;
402 1 //在FAT里标记该簇
403 1 if(!Read((2*NewCluster/SimpleBpb.BytsPerSec)+FatParameter.FirstFatSecNum,1,(BYTE *)buf))
404 1 return FALSE;
405 1 buf[NewCluster%(SimpleBpb.BytsPerSec/2)]=0xfffff;
406 1 if(!Write((2*NewCluster/SimpleBpb.BytsPerSec)+FatParameter.FirstFatSecNum,1,(BYTE *)buf))
*** WARNING C209 IN LINE 406 OF API.C: '_Write': too few actual parameters
407 1 return FALSE;
408 1 DelayMs(15);
409 1 //Root dir
410 1 if(!Read(file.DirSectorNum,1,(BYTE *)Cache))
411 1 return FALSE;
412 1 pdir = (struct _DIR *)Cache;
413 1 pdir += file.DirIndex;
414 1 pdir->FstClusLO =WordSwap(NewCluster);
415 1 pdir->FileSize=0;
416 1 pdir->Attr=ATTR_DIRECTORY;
417 1 if(!Write(file.DirSectorNum,1,Cache,TRUE))
418 1 if(!Write(file.DirSectorNum,1,Cache,TRUE))
419 1 return FALSE;
C51 COMPILER V7.06 API 07/30/2008 08:56:14 PAGE 8
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -