?? ftl.patch
字號:
+ diff -u linux-2.2.13/include/linux/blk.h.ORIG linux-2.2.13/include/linux/blk.h--- linux-2.2.13/include/linux/blk.h.ORIG Mon Jan 10 13:54:15 2000+++ linux-2.2.13/include/linux/blk.h Mon Jan 10 20:22:48 2000@@ -63,6 +63,7 @@ extern int ez_init(void); extern int bpcd_init(void); extern int ps2esdi_init(void);+extern int ftl_init(void); extern void set_device_ro(kdev_t dev,int flag); void add_blkdev_randomness(int major);+ diff -u linux-2.2.13/include/linux/major.h.ORIG linux-2.2.13/include/linux/major.h--- linux-2.2.13/include/linux/major.h.ORIG Mon Jan 10 01:30:12 2000+++ linux-2.2.13/include/linux/major.h Mon Jan 10 20:21:13 2000@@ -74,6 +74,7 @@ #define APBLOCK_MAJOR 38 /* AP1000 Block device */ #define DDV_MAJOR 39 /* AP1000 DDV block device */ #define NBD_MAJOR 43 /* Network block device */+#define FTL_MAJOR 44 /* FLASH Translation Layer */ #define RISCOM8_NORMAL_MAJOR 48 #define DAC960_MAJOR 48 /* 48..55 */ #define RISCOM8_CALLOUT_MAJOR 49+ diff -u linux-2.2.13/include/linux/ftl.h.ORIG linux-2.2.13/include/linux/ftl.h--- linux-2.2.13/include/linux/ftl.h.ORIG Mon Jan 10 20:34:40 2000+++ linux-2.2.13/include/linux/ftl.h Mon Jan 10 20:34:43 2000@@ -0,0 +1,73 @@+/*+ * ftl.h 1.6 1999/08/28 04:12:33+ *+ * The contents of this file are subject to the Mozilla Public License+ * Version 1.1 (the "License"); you may not use this file except in+ * compliance with the License. You may obtain a copy of the License+ * at http://www.mozilla.org/MPL/+ *+ * Software distributed under the License is distributed on an "AS IS"+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See+ * the License for the specific language governing rights and+ * limitations under the License. + *+ * The initial developer of the original code is David A. Hinds+ * <dhinds@hyper.stanford.edu>. Portions created by David A. Hinds+ * are Copyright (C) 1999 David A. Hinds. All Rights Reserved.+ *+ * Alternatively, the contents of this file may be used under the+ * terms of the GNU Public License version 2 (the "GPL"), in which+ * case the provisions of the GPL are applicable instead of the+ * above. If you wish to allow the use of your version of this file+ * only under the terms of the GPL and not to allow others to use+ * your version of this file under the MPL, indicate your decision by+ * deleting the provisions above and replace them with the notice and+ * other provisions required by the GPL. If you do not delete the+ * provisions above, a recipient may use your version of this file+ * under either the MPL or the GPL.+ */++#ifndef _LINUX_FTL_H+#define _LINUX_FTL_H++typedef struct erase_unit_header_t {+ u_char LinkTargetTuple[5];+ u_char DataOrgTuple[10];+ u_char NumTransferUnits;+ u_int EraseCount;+ u_short LogicalEUN;+ u_char BlockSize;+ u_char EraseUnitSize;+ u_short FirstPhysicalEUN;+ u_short NumEraseUnits;+ u_int FormattedSize;+ u_int FirstVMAddress;+ u_short NumVMPages;+ u_char Flags;+ u_char Code;+ u_int SerialNumber;+ u_int AltEUHOffset;+ u_int BAMOffset;+ u_char Reserved[12];+ u_char EndTuple[2];+} erase_unit_header_t;++/* Flags in erase_unit_header_t */+#define HIDDEN_AREA 0x01+#define REVERSE_POLARITY 0x02+#define DOUBLE_BAI 0x04++/* Definitions for block allocation information */++#define BLOCK_FREE(b) ((b) == 0xffffffff)+#define BLOCK_DELETED(b) (((b) == 0) || ((b) == 0xfffffffe))++#define BLOCK_TYPE(b) ((b) & 0x7f)+#define BLOCK_ADDRESS(b) ((b) & ~0x7f)+#define BLOCK_NUMBER(b) ((b) >> 9)+#define BLOCK_CONTROL 0x30+#define BLOCK_DATA 0x40+#define BLOCK_REPLACEMENT 0x60+#define BLOCK_BAD 0x70++#endif /* _LINUX_FTL_H */+ diff -u linux-2.2.13/drivers/block/Config.in.ORIG linux-2.2.13/drivers/block/Config.in--- linux-2.2.13/drivers/block/Config.in.ORIG Tue Oct 19 22:29:30 1999+++ linux-2.2.13/drivers/block/Config.in Mon Jan 10 20:18:12 2000@@ -116,6 +116,11 @@ if [ "$CONFIG_BLK_DEV_RAM" = "y" ]; then bool ' Initial RAM disk (initrd) support' CONFIG_BLK_DEV_INITRD fi++if [ "$CONFIG_FLASH" = "y" ]; then+ bool 'Flash translation layer support' CONFIG_BLK_DEV_FTL+fi+ tristate 'XT hard disk support' CONFIG_BLK_DEV_XD if [ "$CONFIG_PCI" = "y" ]; then tristate 'Mylex DAC960/DAC1100 PCI RAID Controller support' CONFIG_BLK_DEV_DAC960+ diff -u linux-2.2.13/drivers/block/Makefile.ORIG linux-2.2.13/drivers/block/Makefile--- linux-2.2.13/drivers/block/Makefile.ORIG Tue Oct 19 22:29:41 1999+++ linux-2.2.13/drivers/block/Makefile Mon Jan 10 20:18:18 2000@@ -86,6 +86,10 @@ endif endif +ifeq ($(CONFIG_BLK_DEV_FTL),y)+L_OBJS += ftl.o+endif+ ifeq ($(CONFIG_BLK_DEV_LOOP),y) LX_OBJS += loop.o else+ diff -u linux-2.2.13/drivers/block/ftl.c.ORIG linux-2.2.13/drivers/block/ftl.c--- linux-2.2.13/drivers/block/ftl.c.ORIG Mon Jan 10 20:33:48 2000+++ linux-2.2.13/drivers/block/ftl.c Mon Jan 10 23:49:45 2000@@ -0,0 +1,1511 @@+/*+ * 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+ *+ * ----------------------------+ *+ * This was originally part of the pcmcia 3.x.x distributions.+ * It has been modified to work with the flash device /dev/flash0+ * and redistrubited as GPL according to the copyright notice.+ *+ * Changes are (c) Alexander Larsson (alla@lysator.liu.se or alex@signum.se)+ * and (c) Wolfgang Denk <wd@denx.de>.+ *+ * Original notice follows:+ *======================================================================+ *+ * A Flash Translation Layer memory card driver+ *+ * This driver implements a disk-like block device driver with an+ * apparent block size of 512 bytes for flash memory cards.+ *+ * ftl_cs.c 1.55 1999/09/21 15:21:55+ *+ * The contents of this file are subject to the Mozilla Public+ * License Version 1.1 (the "License"); you may not use this file+ * except in compliance with the License. You may obtain a copy of+ * the License at http://www.mozilla.org/MPL/+ *+ * Software distributed under the License is distributed on an "AS+ * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or+ * implied. See the License for the specific language governing+ * rights and limitations under the License.+ *+ * The initial developer of the original code is David A. Hinds+ * <dhinds@hyper.stanford.edu>. Portions created by David A. Hinds+ * are Copyright (C) 1999 David A. Hinds. All Rights Reserved.+ *+ * Alternatively, the contents of this file may be used under the+ * terms of the GNU Public License version 2 (the "GPL"), in which+ * case the provisions of the GPL are applicable instead of the+ * above. If you wish to allow the use of your version of this file+ * only under the terms of the GPL and not to allow others to use+ * your version of this file under the MPL, indicate your decision+ * by deleting the provisions above and replace them with the notice+ * and other provisions required by the GPL. If you do not delete+ * the provisions above, a recipient may use your version of this+ * file under either the MPL or the GPL.+ *+ * LEGAL NOTE: The FTL format is patented by M-Systems. They have+ * granted a license for its use with PCMCIA devices:+ *+ * "M-Systems grants a royalty-free, non-exclusive license under+ * any presently existing M-Systems intellectual property rights+ * necessary for the design and development of FTL-compatible+ * drivers, file systems and utilities using the data formats with+ * PCMCIA PC Cards as described in the PCMCIA Flash Translation+ * Layer (FTL) Specification."+ *+ * Use of the FTL format for non-PCMCIA applications may be an+ * infringement of these patents. For additional information,+ * contact M-Systems (http://www.m-sys.com) directly.+ *+ *======================================================================+ */++/**+ TODO:+ * Sometimes an erase is done and the newly erased sector is not+ immediately needed. Then the code currently unnessecary blocks.+ To fix this i would need to add a schedule_erase_sector to the+ flash interface.+ */++//#define PSYCHO_DEBUG++#include <linux/kernel.h>+#include <linux/init.h>+#include <linux/sched.h>+#include <linux/ptrace.h>+#include <linux/malloc.h>+#include <linux/string.h>+#include <linux/timer.h>+#include <linux/major.h>+#include <linux/fs.h>+#include <linux/ioctl.h>+#include <linux/hdreg.h>+#include <linux/vmalloc.h>+#include <linux/flash.h>+#include <linux/major.h>+#include <linux/ftl.h>+#include <linux/init.h>+#include <linux/version.h>+#include <asm/io.h>+#include <asm/system.h>+#include <asm/segment.h>+#include <asm/uaccess.h>+#include <stdarg.h>++#undef FLASH_DEBUG++#ifdef FLASH_DEBUG+#define DEBUG(args...) printk(args)+#else+#define DEBUG(args...)+#endif++/*====================================================================*/++/* Boot parameters: */++struct boot_ftl {+ int minor;+ off_t start;+ size_t size;+};++static struct boot_ftl boot_table[] __initdata = {+ /*+ * Definitions for FLASH Device 0:+ */+ { 0, 0, 128 << 10 }, /* 0 - 128 kB = 0.125 MB -> Monitor */+ { 0, 128 << 10, 896 << 10 }, /* 128 kB - 1 MB = 0.875 MB -> Linux-1 */+ { 0, 1 << 20, 1 << 20 }, /* 1 MB - 2 MB = 1.000 MB -> Linux-2 */+ { 0, 2 << 20, 2 << 20 }, /* 2 MB - 4 MB = 2.000 MB -> User Data */+ /*+ * Definitions for FLASH Device 1:+ */+ { 1, 0, 1 << 20 }, /* 0 - 1 MB = 1 MB */+ { 1, 1 << 20, 1 << 20 }, /* 1 - 2 MB = 1 MB */+ { 1, 2 << 20, 2 << 20 }, /* 2 - 4 MB = 2 MB */+};+++++/*====================================================================*/++/* Parameters that can be set with 'insmod' */++static int shuffle_freq = 50;++/*+MODULE_PARM(shuffle_freq, "i");+*/++/*====================================================================*/++/* Funky stuff for setting up a block device */+#define MAJOR_NR FTL_MAJOR+#define DEVICE_NAME "ftl"+#define DEVICE_REQUEST do_ftl_request+#define DEVICE_ON(device)+#define DEVICE_OFF(device)+#define DEVICE_NR(minor) (MINOR(minor)>>4)+#define DEVICE_NO_RANDOM++#define PART_NR(minor) ((minor) & 0x0F)+#define MINOR_NR(dev,part) (((dev)<<4) + (part))++#include <linux/blk.h>++/* Linux version stuff */+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,1)+typedef struct wait_queue *wait_queue_head_t;+#endif++/*====================================================================*/++/* Maximum number of separate ftl devices we'll allow */+#define MAX_DEV 8 /* /devftl[a-h] */++/* Maximum number of partitions in an flash memory */+#define PART_BITS 4+#define MAX_PART 16 /* /dev/ftla + /dev/ftla[1-15] */++/* Maximum number of outstanding erase requests per socket */+#define MAX_ERASE 8++/* Sector size -- shouldn't need to change */+#define SECTOR_SIZE 512++/* Block IO request handler stuff */+static void do_ftl_request(void);++typedef struct mem_region_info_t {+ u_int RegionSize;+ u_int BlockSize;+} mem_region_info_t;+++/* Partition state flags */+#define FTL_FORMATTED 0x01++/* Transfer unit states */+#define XFER_UNKNOWN 0x00+#define XFER_ERASING 0x01+#define XFER_ERASED 0x02+#define XFER_PREPARED 0x03+#define XFER_FAILED 0x04++/* Each memory region corresponds to a minor device */+typedef struct ftl_dev_t {+ flash_device_info_t *flash;+ off_t base_offset;+ kdev_t dev; /* The whole device (eg. /dev/ftla) */+ u_int state;+ u_int *VirtualBlockMap;+ u_int *VirtualPageMap;+ u_int FreeTotal;+ struct eun_info_t {+ u_int Offset;+ u_int EraseCount;+ u_int Free;+ u_int Deleted;+ } *EUNInfo;+ struct xfer_info_t {+ u_int Offset;+ u_int EraseCount;+ u_short state;+ } *XferInfo;+ u_short bam_index;+ u_int *bam_cache;+ u_short DataUnits;+ u_int BlocksPerUnit;+ erase_unit_header_t header;+ mem_region_info_t region;+ int open;+ int locked;++ /*+ eraseq_handle_t eraseq_handle;+ eraseq_entry_t eraseq[MAX_ERASE];+ wait_queue_head_t erase_pending;+ */+} ftl_dev_t;++static ftl_dev_t *dev_table[MAX_DEV] = { NULL, /* ... */ };++static struct hd_struct ftl_hd[MINOR_NR(MAX_DEV, 0)];+static int ftl_sizes[MINOR_NR(MAX_DEV, 0)];+static int ftl_blocksizes[MINOR_NR(MAX_DEV, 0)];++static wait_queue_head_t ftl_wait_open = NULL;++static void ftl_geninit(struct gendisk *gendisk);++static struct gendisk ftl_gendisk = {+ 0, /* Major device number */+ "ftl",+ PART_BITS, /* Bits in partition # */+ MAX_PART, /* Partitions per device */+ MAX_DEV, /* maximum number of devices */+ ftl_geninit, /* init function */+ ftl_hd, /* hd_struct */+ ftl_sizes, /* block sizes */+ MAX_DEV, /* number of "real" devices */+ NULL,+ NULL+};++/*====================================================================*/++static int ftl_ioctl(struct inode *inode, struct file *file,+ u_int cmd, u_long arg);+static int ftl_open(struct inode *inode, struct file *file);+static int ftl_close(struct inode *inode, struct file *file);+static int ftl_reread_partitions(int minor);++static struct file_operations ftl_blk_fops = {+ NULL, /* lseek */+ block_read, /* read */+ block_write, /* write */
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -