⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sdfs_out.lst

📁 基于SD卡的FAT文件系统
💻 LST
📖 第 1 页 / 共 5 页
字号:

000001ea <clust2sect>:
static
DWORD clust2sect (	/* !=0: sector number, 0: failed - invalid cluster# */
	CLUST clust		/* Cluster# to be converted */
)
{
     1ea:	ef 92       	push	r14
     1ec:	ff 92       	push	r15
     1ee:	0f 93       	push	r16
     1f0:	1f 93       	push	r17
     1f2:	cf 93       	push	r28
     1f4:	df 93       	push	r29
     1f6:	7b 01       	movw	r14, r22
     1f8:	8c 01       	movw	r16, r24
	FATFS *fs = FatFs;
     1fa:	c0 91 6d 00 	lds	r28, 0x006D
     1fe:	d0 91 6e 00 	lds	r29, 0x006E


	clust -= 2;
     202:	8e ef       	ldi	r24, 0xFE	; 254
     204:	9f ef       	ldi	r25, 0xFF	; 255
     206:	af ef       	ldi	r26, 0xFF	; 255
     208:	bf ef       	ldi	r27, 0xFF	; 255
     20a:	e8 0e       	add	r14, r24
     20c:	f9 1e       	adc	r15, r25
     20e:	0a 1f       	adc	r16, r26
     210:	1b 1f       	adc	r17, r27
	if (clust >= (fs->max_clust - 2)) return 0;		/* Invalid cluster# */
     212:	88 8d       	ldd	r24, Y+24	; 0x18
     214:	99 8d       	ldd	r25, Y+25	; 0x19
     216:	aa 8d       	ldd	r26, Y+26	; 0x1a
     218:	bb 8d       	ldd	r27, Y+27	; 0x1b
     21a:	02 97       	sbiw	r24, 0x02	; 2
     21c:	a1 09       	sbc	r26, r1
     21e:	b1 09       	sbc	r27, r1
     220:	e8 16       	cp	r14, r24
     222:	f9 06       	cpc	r15, r25
     224:	0a 07       	cpc	r16, r26
     226:	1b 07       	cpc	r17, r27
     228:	28 f0       	brcs	.+10     	; 0x234 <clust2sect+0x4a>
     22a:	20 e0       	ldi	r18, 0x00	; 0
     22c:	30 e0       	ldi	r19, 0x00	; 0
     22e:	40 e0       	ldi	r20, 0x00	; 0
     230:	50 e0       	ldi	r21, 0x00	; 0
     232:	12 c0       	rjmp	.+36     	; 0x258 <clust2sect+0x6e>
	return (DWORD)clust * fs->sects_clust + fs->database;
     234:	2d 8d       	ldd	r18, Y+29	; 0x1d
     236:	33 27       	eor	r19, r19
     238:	44 27       	eor	r20, r20
     23a:	55 27       	eor	r21, r21
     23c:	c8 01       	movw	r24, r16
     23e:	b7 01       	movw	r22, r14
     240:	0e 94 dc 0a 	call	0x15b8	; 0x15b8 <__mulsi3>
     244:	9b 01       	movw	r18, r22
     246:	ac 01       	movw	r20, r24
     248:	88 89       	ldd	r24, Y+16	; 0x10
     24a:	99 89       	ldd	r25, Y+17	; 0x11
     24c:	aa 89       	ldd	r26, Y+18	; 0x12
     24e:	bb 89       	ldd	r27, Y+19	; 0x13
     250:	28 0f       	add	r18, r24
     252:	39 1f       	adc	r19, r25
     254:	4a 1f       	adc	r20, r26
     256:	5b 1f       	adc	r21, r27
}
     258:	ca 01       	movw	r24, r20
     25a:	b9 01       	movw	r22, r18
     25c:	e6 e0       	ldi	r30, 0x06	; 6
     25e:	cd b7       	in	r28, 0x3d	; 61
     260:	de b7       	in	r29, 0x3e	; 62
     262:	0c 94 45 0b 	jmp	0x168a	; 0x168a <__epilogue_restores__+0x18>

00000266 <validate>:




/*-----------------------------------------------------------------------*/
/* Move directory pointer to next                                        */
/*-----------------------------------------------------------------------*/

static
BOOL next_dir_entry (	/* TRUE: successful, FALSE: could not move next */
	DIR *dirobj			/* Pointer to directory object */
)
{
	CLUST clust;
	WORD idx;
	FATFS *fs = FatFs;


	idx = dirobj->index + 1;
	if ((idx & 15) == 0) {		/* Table sector changed? */
		dirobj->sect++;			/* Next sector */
		if (!dirobj->clust) {		/* In static table */
			if (idx >= fs->n_rootdir) return FALSE;	/* Reached to end of table */
		} else {					/* In dynamic table */
			if (((idx / 16) & (fs->sects_clust - 1)) == 0) {	/* Cluster changed? */
				clust = get_cluster(dirobj->clust);			/* Get next cluster */
				if (clust < 2 || clust >= fs->max_clust)	/* Reached to end of table */
					return FALSE;
				dirobj->clust = clust;				/* Initialize for new cluster */
				dirobj->sect = clust2sect(clust);
			}
		}
	}
	dirobj->index = idx;	/* Lower 4 bit of dirobj->index indicates offset in dirobj->sect */
	return TRUE;
}




/*-----------------------------------------------------------------------*/
/* Get file status from directory entry                                  */
/*-----------------------------------------------------------------------*/

#if _FS_MINIMIZE <= 1
static
void get_fileinfo (		/* No return code */
	FILINFO *finfo, 	/* Ptr to store the File Information */
	const BYTE *dir		/* Ptr to the directory entry */
)
{
	BYTE n, c, a;
	char *p;


	p = &finfo->fname[0];
	a = _USE_NTFLAG ? dir[DIR_NTres] : 0;	/* NT flag */
	for (n = 0; n < 8; n++) {	/* Convert file name (body) */
		c = dir[n];
		if (c == ' ') break;
		if (c == 0x05) c = 0xE5;
		if (a & 0x08 && c >= 'A' && c <= 'Z') c += 0x20;
		*p++ = c;
	}
	if (dir[8] != ' ') {		/* Convert file name (extension) */
		*p++ = '.';
		for (n = 8; n < 11; n++) {
			c = dir[n];
			if (c == ' ') break;
			if (a & 0x10 && c >= 'A' && c <= 'Z') c += 0x20;
			*p++ = c;
		}
	}
	*p = '\0';

	finfo->fattrib = dir[DIR_Attr];			/* Attribute */
	finfo->fsize = LD_DWORD(&dir[DIR_FileSize]);	/* Size */
	finfo->fdate = LD_WORD(&dir[DIR_WrtDate]);	/* Date */
	finfo->ftime = LD_WORD(&dir[DIR_WrtTime]);	/* Time */
}
#endif /* _FS_MINIMIZE <= 1 */




/*-----------------------------------------------------------------------*/
/* Pick a paragraph and create the name in format of directory entry     */
/*-----------------------------------------------------------------------*/

static
char make_dirfile (			/* 1: error - detected an invalid format, '\0'or'/': next character */
	const char **path,		/* Pointer to the file path pointer */
	char *dirname			/* Pointer to directory name buffer {Name(8), Ext(3), NT flag(1)} */
)
{
	BYTE n, t, c, a, b;


	memset(dirname, ' ', 8+3);	/* Fill buffer with spaces */
	a = 0; b = 0x18;	/* NT flag */
	n = 0; t = 8;
	for (;;) {
		c = *(*path)++;
		if (c == '\0' || c == '/') {		/* Reached to end of str or directory separator */
			if (n == 0) break;
			dirname[11] = _USE_NTFLAG ? (a & b) : 0;
			return c;
		}
		if (c <= ' ' || c == 0x7F) break;		/* Reject invisible chars */
		if (c == '.') {
			if (!(a & 1) && n >= 1 && n <= 8) {	/* Enter extension part */
				n = 8; t = 11; continue;
			}
			break;
		}
		if (_USE_SJIS && 
			((c >= 0x81 && c <= 0x9F) ||		/* Accept S-JIS code */
		    (c >= 0xE0 && c <= 0xFC))) {
			if (n == 0 && c == 0xE5)		/* Change heading \xE5 to \x05 */
				c = 0x05;
			a ^= 1; goto md_l2;
		}
		if (c == '"') break;				/* Reject " */
		if (c <= ')') goto md_l1;			/* Accept ! # $ % & ' ( ) */
		if (c <= ',') break;				/* Reject * + , */
		if (c <= '9') goto md_l1;			/* Accept - 0-9 */
		if (c <= '?') break;				/* Reject : ; < = > ? */
		if (!(a & 1)) {	/* These checks are not applied to S-JIS 2nd byte */
			if (c == '|') break;			/* Reject | */
			if (c >= '[' && c <= ']') break;/* Reject [ \ ] */
			if (_USE_NTFLAG && c >= 'A' && c <= 'Z')
				(t == 8) ? (b &= ~0x08) : (b &= ~0x10);
			if (c >= 'a' && c <= 'z') {		/* Convert to upper case */
				c -= 0x20;
				if (_USE_NTFLAG) (t == 8) ? (a |= 0x08) : (a |= 0x10);
			}
		}
	md_l1:
		a &= ~1;
	md_l2:
		if (n >= t) break;
		dirname[n++] = c;
	}
	return 1;
}



/*-----------------------------------------------------------------------*/
/* Trace a file path                                                     */
/*-----------------------------------------------------------------------*/

static
FRESULT trace_path (	/* FR_OK(0): successful, !=0: error code */
	DIR *dirobj,		/* Pointer to directory object to return last directory */
	char *fn,			/* Pointer to last segment name to return */
	const char *path,	/* Full-path string to trace a file or directory */
	BYTE **dir			/* Directory pointer in Win[] to retutn */
)
{
	CLUST clust;
	char ds;
	BYTE *dptr = NULL;
	FATFS *fs = FatFs;

	/* Initialize directory object */
	clust = fs->dirbase;
#if _FAT32
	if (fs->fs_type == FS_FAT32) {
		dirobj->clust = dirobj->sclust = clust;
		dirobj->sect = clust2sect(clust);
	} else
#endif
	{
		dirobj->clust = dirobj->sclust = 0;
		dirobj->sect = clust;
	}
	dirobj->index = 0;
	dirobj->fs = fs;

	if (*path == '\0') {							/* Null path means the root directory */
		*dir = NULL; return FR_OK;
	}

	for (;;) {
		ds = make_dirfile(&path, fn);					/* Get a paragraph into fn[] */
		if (ds == 1) return FR_INVALID_NAME;
		for (;;) {
			if (!move_window(dirobj->sect)) return FR_RW_ERROR;
			dptr = &fs->win[(dirobj->index & 15) * 32];		/* Pointer to the directory entry */
			if (dptr[DIR_Name] == 0)						/* Has it reached to end of dir? */
				return !ds ? FR_NO_FILE : FR_NO_PATH;
			if (dptr[DIR_Name] != 0xE5						/* Matched? */
				&& !(dptr[DIR_Attr] & AM_VOL)
				&& !memcmp(&dptr[DIR_Name], fn, 8+3) ) break;
			if (!next_dir_entry(dirobj))					/* Next directory pointer */
				return !ds ? FR_NO_FILE : FR_NO_PATH;
		}
		if (!ds) { *dir = dptr; return FR_OK; }				/* Matched with end of path */
		if (!(dptr[DIR_Attr] & AM_DIR)) return FR_NO_PATH;	/* Cannot trace because it is a file */
		clust =												/* Get cluster# of the directory */
#if _FAT32
			((DWORD)LD_WORD(&dptr[DIR_FstClusHI]) << 16) |
#endif
			LD_WORD(&dptr[DIR_FstClusLO]);
		dirobj->clust = dirobj->sclust = clust;				/* Restart scannig with the new directory */
		dirobj->sect = clust2sect(clust);
		dirobj->index = 2;
	}
}



/*-----------------------------------------------------------------------*/
/* Reserve a directory entry                                             */
/*-----------------------------------------------------------------------*/

#if !_FS_READONLY
static
FRESULT reserve_direntry (	/* FR_OK: successful, FR_DENIED: no free entry, FR_RW_ERROR: a disk error occured */
	DIR *dirobj,			/* Target directory to create new entry */
	BYTE **dir				/* Pointer to pointer to created entry to retutn */
)
{
	CLUST clust;
	DWORD sector;
	BYTE c, n, *dptr;
	FATFS *fs = FatFs;


	/* Re-initialize directory object */
	clust = dirobj->sclust;
	if (clust) {	/* Dyanmic directory table */
		dirobj->clust = clust;
		dirobj->sect = clust2sect(clust);
	} else {		/* Static directory table */
		dirobj->sect = fs->dirbase;
	}
	dirobj->index = 0;

	do {
		if (!move_window(dirobj->sect)) return FR_RW_ERROR;
		dptr = &fs->win[(dirobj->index & 15) * 32];	/* Pointer to the directory entry */
		c = dptr[DIR_Name];
		if (c == 0 || c == 0xE5) {			/* Found an empty entry! */
			*dir = dptr; return FR_OK;
		}
	} while (next_dir_entry(dirobj));				/* Next directory pointer */
	/* Reached to end of the directory table */

	/* Abort when static table or could not stretch dynamic table */
	if (!clust || !(clust = create_chain(dirobj->clust))) return FR_DENIED;
	if (clust == 1 || !move_window(0)) return FR_RW_ERROR;

	fs->winsect = sector = clust2sect(clust);			/* Cleanup the expanded table */
	memset(fs->win, 0, 512);
	for (n = fs->sects_clust; n; n--) {
		if (disk_write(0, fs->win, sector, 1) != RES_OK)
			return FR_RW_ERROR;
		sector++;
	}
	fs->winflag = 1;
	*dir = fs->win;
	return FR_OK;
}
#endif /* !_FS_READONLY */




/*-----------------------------------------------------------------------*/
/* Load boot record and check if it is a FAT boot record                 */
/*-----------------------------------------------------------------------*/

static
BYTE check_fs (		/* 0:The FAT boot record, 1:Valid boot record but not an FAT, 2:Not a boot record or error */
	DWORD sect		/* Sector# to check if it is a FAT boot record or not */
)
{
	FATFS *fs = FatFs;

	if (disk_read(0, fs->win, sect, 1) != RES_OK)	/* Load boot record */
		return 2;
	if (LD_WORD(&fs->win[BS_55AA]) != 0xAA55)		/* Check record signature */
		return 2;

	if (!memcmp(&fs->win[BS_FilSysType], "FAT", 3))	/* Check FAT signature */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -