📄 fat.c
字号:
/* * fat.c * * R/O (V)FAT 12/16/32 filesystem implementation by Marcus Sundberg * * 2002-07-28 - rjones@nexus-tech.net - ported to ppcboot v1.1.6 * 2003-03-10 - kharris@nexus-tech.net - ported to uboot * * See file CREDITS for list of people who contributed to this * project. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, * MA 02111-1307 USA */#include <common.h>#include <config.h>#include <fat.h>#include <asm/byteorder.h>#include <part.h>#if (CONFIG_COMMANDS & CFG_CMD_FAT)//#define FAT_DPRINT printf/* * Convert a string to lowercase. */static voiddowncase(char *str){ while (*str != '\0') { TOLOWER(*str); str++; }}static block_dev_desc_t *cur_dev = NULL;static unsigned long part_offset = 0;static int cur_part = 1;#define DOS_PART_TBL_OFFSET 0x1be#define DOS_PART_MAGIC_OFFSET 0x1fe#define DOS_FS_TYPE_OFFSET 0x36int disk_read (__u32 startblock, __u32 getsize, __u8 * bufptr){ startblock += part_offset; if (cur_dev == NULL) return -1; if (cur_dev->block_read) { FAT_DPRINT("startblock: %d, getsize: %d, offset: %d\n", startblock, getsize,part_offset); return cur_dev->block_read (cur_dev->dev, startblock, getsize, (unsigned long *)bufptr); } return -1;}intfat_register_device(block_dev_desc_t *dev_desc, int part_no){ unsigned char buffer[SECTOR_SIZE]; if (!dev_desc->block_read) return -1; cur_dev=dev_desc; /* check if we have a MBR (on floppies we have only a PBR) */ if (dev_desc->block_read (dev_desc->dev, 0, 1, (ulong *) buffer) != 1) { printf ("** Can't read from device %d **\n", dev_desc->dev); return -1; } if (buffer[DOS_PART_MAGIC_OFFSET] != 0x55 || buffer[DOS_PART_MAGIC_OFFSET + 1] != 0xaa) { /* no signature found */ return -1; } if(!strncmp(&buffer[DOS_FS_TYPE_OFFSET],"FAT",3)) { /* ok, we assume we are on a PBR only */ cur_part = 1; part_offset=0; } else {#if (CONFIG_COMMANDS & CFG_CMD_IDE) || (CONFIG_COMMANDS & CFG_CMD_SCSI) || \ (CONFIG_COMMANDS & CFG_CMD_USB) || (CONFIG_COMMANDS & CFG_CMD_MMC) ||defined(CONFIG_SYSTEMACE) disk_partition_t info; if(!get_partition_info(dev_desc, part_no, &info)) { part_offset = info.start; cur_part = part_no; } else { printf ("** Partition %d not valid on device %d **\n",part_no,dev_desc->dev); return -1; }#else /* FIXME we need to determine the start block of the * partition where the DOS FS resides. This can be done * by using the get_partition_info routine. For this * purpose the libpart must be included. */ part_offset=32; cur_part = 1;#endif } return 0;}/* * Get the first occurence of a directory delimiter ('/' or '\') in a string. * Return index into string if found, -1 otherwise. */static intdirdelim(char *str){ char *start = str; while (*str != '\0') { if (ISDIRDELIM(*str)) return str - start; str++; } return -1;}/* * Match volume_info fs_type strings. * Return 0 on match, -1 otherwise. */static intcompare_sign(char *str1, char *str2){ char *end = str1+SIGNLEN; while (str1 != end) { if (*str1 != *str2) { return -1; } str1++; str2++; } return 0;}/* * Extract zero terminated short name from a directory entry. */static void get_name (dir_entry *dirent, char *s_name){ char *ptr; memcpy (s_name, dirent->name, 8); s_name[8] = '\0'; ptr = s_name; while (*ptr && *ptr != ' ') ptr++; if (dirent->ext[0] && dirent->ext[0] != ' ') { *ptr = '.'; ptr++; memcpy (ptr, dirent->ext, 3); ptr[3] = '\0'; while (*ptr && *ptr != ' ') ptr++; } *ptr = '\0'; if (*s_name == DELETED_FLAG) *s_name = '\0'; else if (*s_name == aRING) *s_name = '
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -