+++ /dev/null
-CONFIG_32BIT=y
-# CONFIG_64BIT is not set
-CONFIG_AR7=y
-CONFIG_AR7_GPIO=y
-CONFIG_AR7_WDT=y
-# CONFIG_ARCH_HAS_ILOG2_U32 is not set
-# CONFIG_ARCH_HAS_ILOG2_U64 is not set
-# CONFIG_ARCH_SUPPORTS_MSI is not set
-CONFIG_ATM_DRIVERS=y
-CONFIG_BASE_SMALL=0
-CONFIG_BITREVERSE=y
-CONFIG_BOOT_ELF32=y
-# CONFIG_BROADCOM_PHY is not set
-# CONFIG_BT is not set
-CONFIG_CMDLINE="init=/etc/preinit rootfstype=squashfs,jffs2,"
-CONFIG_CPMAC=y
-# CONFIG_CPU_BIG_ENDIAN is not set
-CONFIG_CPU_HAS_LLSC=y
-CONFIG_CPU_HAS_PREFETCH=y
-CONFIG_CPU_HAS_SYNC=y
-CONFIG_CPU_LITTLE_ENDIAN=y
-# CONFIG_CPU_LOONGSON2 is not set
-CONFIG_CPU_MIPS32=y
-CONFIG_CPU_MIPS32_R1=y
-# CONFIG_CPU_MIPS32_R2 is not set
-# CONFIG_CPU_MIPS64_R1 is not set
-# CONFIG_CPU_MIPS64_R2 is not set
-CONFIG_CPU_MIPSR1=y
-# CONFIG_CPU_NEVADA is not set
-# CONFIG_CPU_R10000 is not set
-# CONFIG_CPU_R3000 is not set
-# CONFIG_CPU_R4300 is not set
-# CONFIG_CPU_R4X00 is not set
-# CONFIG_CPU_R5000 is not set
-# CONFIG_CPU_R5432 is not set
-# CONFIG_CPU_R6000 is not set
-# CONFIG_CPU_R8000 is not set
-# CONFIG_CPU_RM7000 is not set
-# CONFIG_CPU_RM9000 is not set
-# CONFIG_CPU_SB1 is not set
-CONFIG_CPU_SUPPORTS_32BIT_KERNEL=y
-CONFIG_CPU_SUPPORTS_HIGHMEM=y
-# CONFIG_CPU_TX39XX is not set
-# CONFIG_CPU_TX49XX is not set
-# CONFIG_CPU_VR41XX is not set
-# CONFIG_DM9000 is not set
-CONFIG_DMA_NEED_PCI_MAP_STATE=y
-CONFIG_DMA_NONCOHERENT=y
-CONFIG_EARLY_PRINTK=y
-CONFIG_FIXED_MII_100_FDX=y
-# CONFIG_FIXED_MII_10_FDX is not set
-CONFIG_FIXED_PHY=y
-CONFIG_FS_POSIX_ACL=y
-CONFIG_GENERIC_FIND_NEXT_BIT=y
-CONFIG_GENERIC_GPIO=y
-CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ=y
-CONFIG_HAS_DMA=y
-CONFIG_HAS_IOMEM=y
-CONFIG_HAS_IOPORT=y
-CONFIG_HID_SUPPORT=n
-CONFIG_HW_HAS_PCI=y
-CONFIG_HW_RANDOM=y
-# CONFIG_I2C is not set
-# CONFIG_IDE is not set
-CONFIG_INITRAMFS_SOURCE=""
-CONFIG_IRQ_CPU=y
-CONFIG_KALLSYMS=y
-# CONFIG_KALLSYMS_EXTRA_PASS is not set
-CONFIG_LEDS_GPIO=y
-CONFIG_LEDS_TRIGGER_DEFAULT_ON=y
-# CONFIG_LEMOTE_FULONG is not set
-# CONFIG_MACH_ALCHEMY is not set
-# CONFIG_MACH_DECSTATION is not set
-# CONFIG_MACH_JAZZ is not set
-# CONFIG_MACH_VR41XX is not set
-CONFIG_MIPS=y
-# CONFIG_MIPS_ATLAS is not set
-# CONFIG_MIPS_COBALT is not set
-CONFIG_MIPS_L1_CACHE_SHIFT=5
-# CONFIG_MIPS_MALTA is not set
-CONFIG_MIPS_MT_DISABLED=y
-# CONFIG_MIPS_MT_SMP is not set
-# CONFIG_MIPS_MT_SMTC is not set
-# CONFIG_MIPS_SEAD is not set
-# CONFIG_MIPS_SIM is not set
-CONFIG_MTD=y
-# CONFIG_MTD_ABSENT is not set
-CONFIG_MTD_AR7_PARTS=y
-CONFIG_MTD_BLKDEVS=y
-CONFIG_MTD_BLOCK=y
-# CONFIG_MTD_BLOCK2MTD is not set
-CONFIG_MTD_CFI=y
-# CONFIG_MTD_CFI_ADV_OPTIONS is not set
-CONFIG_MTD_CFI_AMDSTD=y
-CONFIG_MTD_CFI_I1=y
-CONFIG_MTD_CFI_I2=y
-# CONFIG_MTD_CFI_I4 is not set
-# CONFIG_MTD_CFI_I8 is not set
-CONFIG_MTD_CFI_INTELEXT=y
-CONFIG_MTD_CFI_STAA=y
-CONFIG_MTD_CFI_UTIL=y
-CONFIG_MTD_CHAR=y
-# CONFIG_MTD_CMDLINE_PARTS is not set
-CONFIG_MTD_COMPLEX_MAPPINGS=y
-# CONFIG_MTD_CONCAT is not set
-# CONFIG_MTD_DEBUG is not set
-# CONFIG_MTD_DOC2000 is not set
-# CONFIG_MTD_DOC2001 is not set
-# CONFIG_MTD_DOC2001PLUS is not set
-CONFIG_MTD_GEN_PROBE=y
-# CONFIG_MTD_JEDECPROBE is not set
-CONFIG_MTD_MAP_BANK_WIDTH_1=y
-# CONFIG_MTD_MAP_BANK_WIDTH_16 is not set
-CONFIG_MTD_MAP_BANK_WIDTH_2=y
-# CONFIG_MTD_MAP_BANK_WIDTH_32 is not set
-CONFIG_MTD_MAP_BANK_WIDTH_4=y
-# CONFIG_MTD_MAP_BANK_WIDTH_8 is not set
-# CONFIG_MTD_MTDRAM is not set
-# CONFIG_MTD_ONENAND is not set
-CONFIG_MTD_PARTITIONS=y
-# CONFIG_MTD_PHRAM is not set
-CONFIG_MTD_PHYSMAP=y
-CONFIG_MTD_PHYSMAP_BANKWIDTH=2
-CONFIG_MTD_PHYSMAP_LEN=0
-CONFIG_MTD_PHYSMAP_START=0x10000000
-# CONFIG_MTD_PLATRAM is not set
-# CONFIG_MTD_RAM is not set
-# CONFIG_MTD_REDBOOT_PARTS is not set
-# CONFIG_MTD_ROM is not set
-# CONFIG_MTD_SLRAM is not set
-# CONFIG_NETDEV_1000 is not set
-# CONFIG_NETDEVICES_MULTIQUEUE is not set
-CONFIG_NET_ACT_POLICE=y
-CONFIG_NET_SCH_FIFO=y
-CONFIG_NF_CT_PROTO_GRE=m
-CONFIG_NF_NAT_PROTO_GRE=m
-CONFIG_NO_EXCEPT_FILL=y
-# CONFIG_NO_IOPORT is not set
-# CONFIG_PAGE_SIZE_16KB is not set
-CONFIG_PAGE_SIZE_4KB=y
-# CONFIG_PAGE_SIZE_64KB is not set
-# CONFIG_PAGE_SIZE_8KB is not set
-# CONFIG_PCI is not set
-CONFIG_PHYLIB=y
-# CONFIG_PMC_MSP is not set
-# CONFIG_PMC_YOSEMITE is not set
-# CONFIG_PNX8550_JBS is not set
-# CONFIG_PNX8550_STB810 is not set
-# CONFIG_QSEMI_PHY is not set
-# CONFIG_RTC is not set
-CONFIG_RWSEM_GENERIC_SPINLOCK=y
-CONFIG_SCHED_NO_NO_OMIT_FRAME_POINTER=y
-CONFIG_SCSI_WAIT_SCAN=m
-# CONFIG_SERIAL_8250_EXTENDED is not set
-# CONFIG_SGI_IP22 is not set
-# CONFIG_SGI_IP27 is not set
-# CONFIG_SGI_IP32 is not set
-# CONFIG_SIBYTE_BIGSUR is not set
-# CONFIG_SIBYTE_CARMEL is not set
-# CONFIG_SIBYTE_CRHINE is not set
-# CONFIG_SIBYTE_CRHONE is not set
-# CONFIG_SIBYTE_LITTLESUR is not set
-# CONFIG_SIBYTE_PTSWARM is not set
-# CONFIG_SIBYTE_RHONE is not set
-# CONFIG_SIBYTE_SENTOSA is not set
-# CONFIG_SIBYTE_SWARM is not set
-# CONFIG_SMSC_PHY is not set
-# CONFIG_SOFT_WATCHDOG is not set
-# CONFIG_SPARSEMEM_STATIC is not set
-CONFIG_SWAP_IO_SPACE=y
-CONFIG_SYSVIPC_SYSCTL=y
-CONFIG_SYS_HAS_CPU_MIPS32_R1=y
-CONFIG_SYS_HAS_EARLY_PRINTK=y
-CONFIG_SYS_SUPPORTS_32BIT_KERNEL=y
-CONFIG_SYS_SUPPORTS_ARBIT_HZ=y
-CONFIG_SYS_SUPPORTS_BIG_ENDIAN=y
-CONFIG_SYS_SUPPORTS_KGDB=y
-CONFIG_SYS_SUPPORTS_LITTLE_ENDIAN=y
-# CONFIG_TOSHIBA_JMR3927 is not set
-# CONFIG_TOSHIBA_RBTX4927 is not set
-# CONFIG_TOSHIBA_RBTX4938 is not set
-CONFIG_TRAD_SIGNALS=y
-# CONFIG_UNUSED_SYMBOLS is not set
-# CONFIG_USB_ARCH_HAS_EHCI is not set
-# CONFIG_USB_ARCH_HAS_HCD is not set
-# CONFIG_USB_ARCH_HAS_OHCI is not set
-# CONFIG_USER_NS is not set
-# CONFIG_VGASTATE is not set
-CONFIG_VLYNQ=y
-CONFIG_ZONE_DMA_FLAG=0
+++ /dev/null
-CONFIG_32BIT=y
-# CONFIG_64BIT is not set
-CONFIG_AR7=y
-CONFIG_AR7_GPIO=y
-CONFIG_AR7_WDT=y
-# CONFIG_ARCH_HAS_ILOG2_U32 is not set
-# CONFIG_ARCH_HAS_ILOG2_U64 is not set
-CONFIG_ARCH_POPULATES_NODE_MAP=y
-# CONFIG_ARCH_SUPPORTS_MSI is not set
-CONFIG_ARCH_SUPPORTS_OPROFILE=y
-CONFIG_ATM_DRIVERS=y
-CONFIG_BASE_SMALL=0
-# CONFIG_BCM47XX is not set
-CONFIG_BITREVERSE=y
-CONFIG_BOOT_ELF32=y
-# CONFIG_BROADCOM_PHY is not set
-# CONFIG_BT is not set
-CONFIG_CEVT_R4K=y
-CONFIG_CMDLINE="init=/etc/preinit rootfstype=squashfs,jffs2,"
-CONFIG_CPMAC=y
-# CONFIG_CPU_BIG_ENDIAN is not set
-CONFIG_CPU_HAS_LLSC=y
-CONFIG_CPU_HAS_PREFETCH=y
-CONFIG_CPU_HAS_SYNC=y
-CONFIG_CPU_LITTLE_ENDIAN=y
-# CONFIG_CPU_LOONGSON2 is not set
-CONFIG_CPU_MIPS32=y
-CONFIG_CPU_MIPS32_R1=y
-# CONFIG_CPU_MIPS32_R2 is not set
-# CONFIG_CPU_MIPS64_R1 is not set
-# CONFIG_CPU_MIPS64_R2 is not set
-CONFIG_CPU_MIPSR1=y
-# CONFIG_CPU_NEVADA is not set
-# CONFIG_CPU_R10000 is not set
-# CONFIG_CPU_R3000 is not set
-# CONFIG_CPU_R4300 is not set
-# CONFIG_CPU_R4X00 is not set
-# CONFIG_CPU_R5000 is not set
-# CONFIG_CPU_R5432 is not set
-# CONFIG_CPU_R6000 is not set
-# CONFIG_CPU_R8000 is not set
-# CONFIG_CPU_RM7000 is not set
-# CONFIG_CPU_RM9000 is not set
-# CONFIG_CPU_SB1 is not set
-CONFIG_CPU_SUPPORTS_32BIT_KERNEL=y
-CONFIG_CPU_SUPPORTS_HIGHMEM=y
-# CONFIG_CPU_TX39XX is not set
-# CONFIG_CPU_TX49XX is not set
-# CONFIG_CPU_VR41XX is not set
-CONFIG_CSRC_R4K=y
-# CONFIG_DM9000 is not set
-CONFIG_DMA_NEED_PCI_MAP_STATE=y
-CONFIG_DMA_NONCOHERENT=y
-CONFIG_EARLY_PRINTK=y
-CONFIG_FIXED_PHY=y
-CONFIG_FS_POSIX_ACL=y
-CONFIG_GENERIC_CLOCKEVENTS=y
-CONFIG_GENERIC_CLOCKEVENTS_BUILD=y
-CONFIG_GENERIC_CMOS_UPDATE=y
-CONFIG_GENERIC_FIND_NEXT_BIT=y
-CONFIG_GENERIC_GPIO=y
-CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ=y
-CONFIG_HAS_DMA=y
-CONFIG_HAS_IOMEM=y
-CONFIG_HAS_IOPORT=y
-CONFIG_HW_RANDOM=y
-# CONFIG_I2C is not set
-# CONFIG_IBM_NEW_EMAC_EMAC4 is not set
-# CONFIG_IBM_NEW_EMAC_RGMII is not set
-# CONFIG_IBM_NEW_EMAC_TAH is not set
-# CONFIG_IBM_NEW_EMAC_ZMII is not set
-# CONFIG_IDE is not set
-CONFIG_INITRAMFS_SOURCE=""
-CONFIG_IRQ_CPU=y
-CONFIG_KALLSYMS=y
-# CONFIG_LEDS_ALIX is not set
-CONFIG_LEDS_GPIO=y
-# CONFIG_LEMOTE_FULONG is not set
-# CONFIG_MACH_ALCHEMY is not set
-# CONFIG_MACH_DECSTATION is not set
-# CONFIG_MACH_JAZZ is not set
-# CONFIG_MACH_VR41XX is not set
-# CONFIG_MDIO_BITBANG is not set
-CONFIG_MIPS=y
-# CONFIG_MIPS_ATLAS is not set
-# CONFIG_MIPS_COBALT is not set
-CONFIG_MIPS_L1_CACHE_SHIFT=5
-# CONFIG_MIPS_MALTA is not set
-CONFIG_MIPS_MT_DISABLED=y
-# CONFIG_MIPS_MT_SMP is not set
-# CONFIG_MIPS_MT_SMTC is not set
-# CONFIG_MIPS_SEAD is not set
-# CONFIG_MIPS_SIM is not set
-CONFIG_MTD=y
-# CONFIG_MTD_ABSENT is not set
-CONFIG_MTD_AR7_PARTS=y
-CONFIG_MTD_BLKDEVS=y
-CONFIG_MTD_BLOCK=y
-# CONFIG_MTD_BLOCK2MTD is not set
-CONFIG_MTD_CFI=y
-# CONFIG_MTD_CFI_ADV_OPTIONS is not set
-CONFIG_MTD_CFI_AMDSTD=y
-CONFIG_MTD_CFI_I1=y
-CONFIG_MTD_CFI_I2=y
-# CONFIG_MTD_CFI_I4 is not set
-# CONFIG_MTD_CFI_I8 is not set
-CONFIG_MTD_CFI_INTELEXT=y
-CONFIG_MTD_CFI_STAA=y
-CONFIG_MTD_CFI_UTIL=y
-CONFIG_MTD_CHAR=y
-# CONFIG_MTD_CMDLINE_PARTS is not set
-CONFIG_MTD_COMPLEX_MAPPINGS=y
-# CONFIG_MTD_CONCAT is not set
-# CONFIG_MTD_DEBUG is not set
-# CONFIG_MTD_DOC2000 is not set
-# CONFIG_MTD_DOC2001 is not set
-# CONFIG_MTD_DOC2001PLUS is not set
-CONFIG_MTD_GEN_PROBE=y
-# CONFIG_MTD_JEDECPROBE is not set
-CONFIG_MTD_MAP_BANK_WIDTH_1=y
-# CONFIG_MTD_MAP_BANK_WIDTH_16 is not set
-CONFIG_MTD_MAP_BANK_WIDTH_2=y
-# CONFIG_MTD_MAP_BANK_WIDTH_32 is not set
-CONFIG_MTD_MAP_BANK_WIDTH_4=y
-# CONFIG_MTD_MAP_BANK_WIDTH_8 is not set
-# CONFIG_MTD_MTDRAM is not set
-# CONFIG_MTD_ONENAND is not set
-CONFIG_MTD_PARTITIONS=y
-# CONFIG_MTD_PHRAM is not set
-CONFIG_MTD_PHYSMAP=y
-CONFIG_MTD_PHYSMAP_BANKWIDTH=2
-CONFIG_MTD_PHYSMAP_LEN=0
-CONFIG_MTD_PHYSMAP_START=0x10000000
-# CONFIG_MTD_PLATRAM is not set
-# CONFIG_MTD_RAM is not set
-# CONFIG_MTD_REDBOOT_PARTS is not set
-# CONFIG_MTD_ROM is not set
-# CONFIG_MTD_SLRAM is not set
-CONFIG_NO_EXCEPT_FILL=y
-# CONFIG_NO_IOPORT is not set
-# CONFIG_PAGE_SIZE_16KB is not set
-CONFIG_PAGE_SIZE_4KB=y
-# CONFIG_PAGE_SIZE_64KB is not set
-# CONFIG_PAGE_SIZE_8KB is not set
-CONFIG_PHYLIB=y
-# CONFIG_PMC_MSP is not set
-# CONFIG_PMC_YOSEMITE is not set
-# CONFIG_PNX8550_JBS is not set
-# CONFIG_PNX8550_STB810 is not set
-# CONFIG_QSEMI_PHY is not set
-# CONFIG_RTC is not set
-CONFIG_RTC_LIB=y
-CONFIG_RWSEM_GENERIC_SPINLOCK=y
-CONFIG_SCHED_NO_NO_OMIT_FRAME_POINTER=y
-CONFIG_SCSI_WAIT_SCAN=m
-# CONFIG_SERIAL_8250_EXTENDED is not set
-# CONFIG_SGI_IP22 is not set
-# CONFIG_SGI_IP27 is not set
-# CONFIG_SGI_IP32 is not set
-# CONFIG_SIBYTE_BIGSUR is not set
-# CONFIG_SIBYTE_CARMEL is not set
-# CONFIG_SIBYTE_CRHINE is not set
-# CONFIG_SIBYTE_CRHONE is not set
-# CONFIG_SIBYTE_LITTLESUR is not set
-# CONFIG_SIBYTE_PTSWARM is not set
-# CONFIG_SIBYTE_RHONE is not set
-# CONFIG_SIBYTE_SENTOSA is not set
-# CONFIG_SIBYTE_SWARM is not set
-# CONFIG_SLAB is not set
-CONFIG_SLABINFO=y
-CONFIG_SLUB=y
-# CONFIG_SLUB_DEBUG is not set
-# CONFIG_SMSC_PHY is not set
-# CONFIG_SOFT_WATCHDOG is not set
-# CONFIG_SPARSEMEM_STATIC is not set
-# CONFIG_SPARSEMEM_VMEMMAP_ENABLE is not set
-CONFIG_SSB_POSSIBLE=y
-CONFIG_SWAP_IO_SPACE=y
-CONFIG_SYSVIPC_SYSCTL=y
-CONFIG_SYS_HAS_CPU_MIPS32_R1=y
-CONFIG_SYS_HAS_EARLY_PRINTK=y
-CONFIG_SYS_SUPPORTS_32BIT_KERNEL=y
-CONFIG_SYS_SUPPORTS_ARBIT_HZ=y
-CONFIG_SYS_SUPPORTS_BIG_ENDIAN=y
-CONFIG_SYS_SUPPORTS_KGDB=y
-CONFIG_SYS_SUPPORTS_LITTLE_ENDIAN=y
-CONFIG_TICK_ONESHOT=y
-# CONFIG_TOSHIBA_JMR3927 is not set
-# CONFIG_TOSHIBA_RBTX4927 is not set
-# CONFIG_TOSHIBA_RBTX4938 is not set
-CONFIG_TRAD_SIGNALS=y
-# CONFIG_USB_ARCH_HAS_EHCI is not set
-# CONFIG_USB_ARCH_HAS_HCD is not set
-# CONFIG_USB_ARCH_HAS_OHCI is not set
-# CONFIG_USER_NS is not set
-# CONFIG_VGASTATE is not set
-CONFIG_VLYNQ=y
-CONFIG_ZONE_DMA_FLAG=0
+++ /dev/null
-CONFIG_32BIT=y
-# CONFIG_64BIT is not set
-CONFIG_AR7=y
-CONFIG_AR7_GPIO=y
-CONFIG_AR7_WDT=y
-# CONFIG_ARCH_HAS_ILOG2_U32 is not set
-# CONFIG_ARCH_HAS_ILOG2_U64 is not set
-CONFIG_ARCH_POPULATES_NODE_MAP=y
-# CONFIG_ARCH_SUPPORTS_MSI is not set
-CONFIG_ARCH_SUPPORTS_OPROFILE=y
-CONFIG_ARCH_SUSPEND_POSSIBLE=y
-CONFIG_ATM_DRIVERS=y
-CONFIG_BASE_SMALL=0
-# CONFIG_BCM47XX is not set
-CONFIG_BITREVERSE=y
-CONFIG_BOOT_ELF32=y
-# CONFIG_BROADCOM_PHY is not set
-# CONFIG_BT is not set
-CONFIG_CEVT_R4K=y
-CONFIG_CLASSIC_RCU=y
-CONFIG_CMDLINE="init=/etc/preinit rootfstype=squashfs,jffs2,"
-CONFIG_CPMAC=y
-# CONFIG_CPU_BIG_ENDIAN is not set
-CONFIG_CPU_HAS_LLSC=y
-CONFIG_CPU_HAS_PREFETCH=y
-CONFIG_CPU_HAS_SYNC=y
-CONFIG_CPU_LITTLE_ENDIAN=y
-# CONFIG_CPU_LOONGSON2 is not set
-CONFIG_CPU_MIPS32=y
-CONFIG_CPU_MIPS32_R1=y
-# CONFIG_CPU_MIPS32_R2 is not set
-# CONFIG_CPU_MIPS64_R1 is not set
-# CONFIG_CPU_MIPS64_R2 is not set
-CONFIG_CPU_MIPSR1=y
-# CONFIG_CPU_NEVADA is not set
-# CONFIG_CPU_R10000 is not set
-# CONFIG_CPU_R3000 is not set
-# CONFIG_CPU_R4300 is not set
-# CONFIG_CPU_R4X00 is not set
-# CONFIG_CPU_R5000 is not set
-# CONFIG_CPU_R5432 is not set
-# CONFIG_CPU_R6000 is not set
-# CONFIG_CPU_R8000 is not set
-# CONFIG_CPU_RM7000 is not set
-# CONFIG_CPU_RM9000 is not set
-# CONFIG_CPU_SB1 is not set
-CONFIG_CPU_SUPPORTS_32BIT_KERNEL=y
-CONFIG_CPU_SUPPORTS_HIGHMEM=y
-# CONFIG_CPU_TX39XX is not set
-# CONFIG_CPU_TX49XX is not set
-# CONFIG_CPU_VR41XX is not set
-CONFIG_CRYPTO_AEAD=m
-CONFIG_CRYPTO_AUTHENC=m
-CONFIG_CRYPTO_GF128MUL=m
-CONFIG_CSRC_R4K=y
-# CONFIG_DM9000 is not set
-CONFIG_DMA_NEED_PCI_MAP_STATE=y
-CONFIG_DMA_NONCOHERENT=y
-CONFIG_EARLY_PRINTK=y
-CONFIG_FIXED_PHY=y
-CONFIG_FS_POSIX_ACL=y
-CONFIG_GENERIC_CLOCKEVENTS=y
-CONFIG_GENERIC_CLOCKEVENTS_BUILD=y
-CONFIG_GENERIC_CMOS_UPDATE=y
-CONFIG_GENERIC_FIND_NEXT_BIT=y
-CONFIG_GENERIC_GPIO=y
-CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ=y
-CONFIG_HAS_DMA=y
-CONFIG_HAS_IOMEM=y
-CONFIG_HAS_IOPORT=y
-CONFIG_HAVE_IDE=y
-# CONFIG_HAVE_KPROBES is not set
-# CONFIG_HAVE_KRETPROBES is not set
-CONFIG_HAVE_OPROFILE=y
-CONFIG_HW_RANDOM=y
-# CONFIG_I2C is not set
-# CONFIG_IBM_NEW_EMAC_EMAC4 is not set
-# CONFIG_IBM_NEW_EMAC_RGMII is not set
-# CONFIG_IBM_NEW_EMAC_TAH is not set
-# CONFIG_IBM_NEW_EMAC_ZMII is not set
-# CONFIG_IDE is not set
-CONFIG_INITRAMFS_SOURCE=""
-CONFIG_IRQ_CPU=y
-# CONFIG_ISDN is not set
-CONFIG_KALLSYMS=y
-# CONFIG_LEDS_ALIX is not set
-CONFIG_LEDS_GPIO=y
-# CONFIG_LEMOTE_FULONG is not set
-CONFIG_LZO_COMPRESS=m
-CONFIG_LZO_DECOMPRESS=m
-# CONFIG_MACH_ALCHEMY is not set
-# CONFIG_MACH_DECSTATION is not set
-# CONFIG_MACH_JAZZ is not set
-# CONFIG_MACH_VR41XX is not set
-# CONFIG_MDIO_BITBANG is not set
-# CONFIG_MEMSTICK is not set
-CONFIG_MIPS=y
-# CONFIG_MIPS_ATLAS is not set
-# CONFIG_MIPS_COBALT is not set
-CONFIG_MIPS_L1_CACHE_SHIFT=5
-# CONFIG_MIPS_MALTA is not set
-CONFIG_MIPS_MT_DISABLED=y
-# CONFIG_MIPS_MT_SMP is not set
-# CONFIG_MIPS_MT_SMTC is not set
-# CONFIG_MIPS_SEAD is not set
-# CONFIG_MIPS_SIM is not set
-CONFIG_MTD=y
-# CONFIG_MTD_ABSENT is not set
-CONFIG_MTD_AR7_PARTS=y
-CONFIG_MTD_BLKDEVS=y
-CONFIG_MTD_BLOCK=y
-# CONFIG_MTD_BLOCK2MTD is not set
-CONFIG_MTD_CFI=y
-# CONFIG_MTD_CFI_ADV_OPTIONS is not set
-CONFIG_MTD_CFI_AMDSTD=y
-CONFIG_MTD_CFI_I1=y
-CONFIG_MTD_CFI_I2=y
-# CONFIG_MTD_CFI_I4 is not set
-# CONFIG_MTD_CFI_I8 is not set
-CONFIG_MTD_CFI_INTELEXT=y
-CONFIG_MTD_CFI_STAA=y
-CONFIG_MTD_CFI_UTIL=y
-CONFIG_MTD_CHAR=y
-# CONFIG_MTD_CMDLINE_PARTS is not set
-CONFIG_MTD_COMPLEX_MAPPINGS=y
-# CONFIG_MTD_CONCAT is not set
-# CONFIG_MTD_DEBUG is not set
-# CONFIG_MTD_DOC2000 is not set
-# CONFIG_MTD_DOC2001 is not set
-# CONFIG_MTD_DOC2001PLUS is not set
-CONFIG_MTD_GEN_PROBE=y
-# CONFIG_MTD_JEDECPROBE is not set
-CONFIG_MTD_MAP_BANK_WIDTH_1=y
-# CONFIG_MTD_MAP_BANK_WIDTH_16 is not set
-CONFIG_MTD_MAP_BANK_WIDTH_2=y
-# CONFIG_MTD_MAP_BANK_WIDTH_32 is not set
-CONFIG_MTD_MAP_BANK_WIDTH_4=y
-# CONFIG_MTD_MAP_BANK_WIDTH_8 is not set
-# CONFIG_MTD_MTDRAM is not set
-# CONFIG_MTD_ONENAND is not set
-CONFIG_MTD_PARTITIONS=y
-# CONFIG_MTD_PHRAM is not set
-CONFIG_MTD_PHYSMAP=y
-CONFIG_MTD_PHYSMAP_BANKWIDTH=2
-CONFIG_MTD_PHYSMAP_LEN=0
-CONFIG_MTD_PHYSMAP_START=0x10000000
-# CONFIG_MTD_PLATRAM is not set
-# CONFIG_MTD_RAM is not set
-# CONFIG_MTD_REDBOOT_PARTS is not set
-# CONFIG_MTD_ROM is not set
-# CONFIG_MTD_SLRAM is not set
-CONFIG_NO_EXCEPT_FILL=y
-# CONFIG_NO_IOPORT is not set
-# CONFIG_PAGE_SIZE_16KB is not set
-CONFIG_PAGE_SIZE_4KB=y
-# CONFIG_PAGE_SIZE_64KB is not set
-# CONFIG_PAGE_SIZE_8KB is not set
-CONFIG_PHYLIB=y
-# CONFIG_PMC_MSP is not set
-# CONFIG_PMC_YOSEMITE is not set
-# CONFIG_PNX8550_JBS is not set
-# CONFIG_PNX8550_STB810 is not set
-# CONFIG_QSEMI_PHY is not set
-# CONFIG_REALTEK_PHY is not set
-# CONFIG_RTC is not set
-CONFIG_RTC_LIB=y
-CONFIG_RWSEM_GENERIC_SPINLOCK=y
-CONFIG_SCHED_NO_NO_OMIT_FRAME_POINTER=y
-# CONFIG_SCSI is not set
-# CONFIG_SCSI_DMA is not set
-# CONFIG_SERIAL_8250_EXTENDED is not set
-# CONFIG_SGI_IP22 is not set
-# CONFIG_SGI_IP27 is not set
-# CONFIG_SGI_IP28 is not set
-# CONFIG_SGI_IP32 is not set
-# CONFIG_SIBYTE_BIGSUR is not set
-# CONFIG_SIBYTE_CARMEL is not set
-# CONFIG_SIBYTE_CRHINE is not set
-# CONFIG_SIBYTE_CRHONE is not set
-# CONFIG_SIBYTE_LITTLESUR is not set
-# CONFIG_SIBYTE_RHONE is not set
-# CONFIG_SIBYTE_SENTOSA is not set
-# CONFIG_SIBYTE_SWARM is not set
-# CONFIG_SLAB is not set
-CONFIG_SLABINFO=y
-CONFIG_SLUB=y
-# CONFIG_SLUB_DEBUG is not set
-# CONFIG_SLUB_STATS is not set
-# CONFIG_SMSC_PHY is not set
-# CONFIG_SOFT_WATCHDOG is not set
-# CONFIG_SOUND is not set
-# CONFIG_SPARSEMEM_STATIC is not set
-# CONFIG_SPARSEMEM_VMEMMAP_ENABLE is not set
-CONFIG_SSB_POSSIBLE=y
-CONFIG_SWAP_IO_SPACE=y
-CONFIG_SYSVIPC_SYSCTL=y
-CONFIG_SYS_HAS_CPU_MIPS32_R1=y
-CONFIG_SYS_HAS_EARLY_PRINTK=y
-CONFIG_SYS_SUPPORTS_32BIT_KERNEL=y
-CONFIG_SYS_SUPPORTS_ARBIT_HZ=y
-CONFIG_SYS_SUPPORTS_BIG_ENDIAN=y
-CONFIG_SYS_SUPPORTS_KGDB=y
-CONFIG_SYS_SUPPORTS_LITTLE_ENDIAN=y
-# CONFIG_THERMAL is not set
-CONFIG_TICK_ONESHOT=y
-# CONFIG_TOSHIBA_JMR3927 is not set
-# CONFIG_TOSHIBA_RBTX4927 is not set
-# CONFIG_TOSHIBA_RBTX4938 is not set
-CONFIG_TRAD_SIGNALS=y
-# CONFIG_USB_SUPPORT is not set
-# CONFIG_VGASTATE is not set
-# CONFIG_VIDEO_DEV is not set
-CONFIG_VLYNQ=y
-# CONFIG_W1 is not set
-CONFIG_ZONE_DMA_FLAG=0
+++ /dev/null
-Index: linux-2.6.23.17/arch/mips/Kconfig
-===================================================================
---- linux-2.6.23.17.orig/arch/mips/Kconfig
-+++ linux-2.6.23.17/arch/mips/Kconfig
-@@ -15,6 +15,22 @@ choice
- prompt "System type"
- default SGI_IP22
-
-+config AR7
-+ bool "Texas Instruments AR7"
-+ select BOOT_ELF32
-+ select DMA_NONCOHERENT
-+ select IRQ_CPU
-+ select NO_EXCEPT_FILL
-+ select SWAP_IO_SPACE
-+ select SYS_HAS_CPU_MIPS32_R1
-+ select SYS_HAS_EARLY_PRINTK
-+ select SYS_SUPPORTS_32BIT_KERNEL
-+ select SYS_SUPPORTS_KGDB
-+ select SYS_SUPPORTS_LITTLE_ENDIAN
-+ select SYS_SUPPORTS_BIG_ENDIAN
-+ select GENERIC_GPIO
-+ select GENERIC_HARDIRQS_NO__DO_IRQ
-+
- config MACH_ALCHEMY
- bool "Alchemy processor based machines"
-
-Index: linux-2.6.23.17/arch/mips/kernel/traps.c
-===================================================================
---- linux-2.6.23.17.orig/arch/mips/kernel/traps.c
-+++ linux-2.6.23.17/arch/mips/kernel/traps.c
-@@ -1075,10 +1075,23 @@ void *set_except_vector(int n, void *add
-
- exception_handlers[n] = handler;
- if (n == 0 && cpu_has_divec) {
-- *(volatile u32 *)(ebase + 0x200) = 0x08000000 |
-- (0x03ffffff & (handler >> 2));
-- flush_icache_range(ebase + 0x200, ebase + 0x204);
-- }
-+ if ((handler ^ (ebase + 4)) & 0xfc000000) {
-+ /* lui k0, 0x0000 */
-+ *(u32 *)(ebase + 0x200) = 0x3c1a0000 | (handler >> 16);
-+ /* ori k0, 0x0000 */
-+ *(u32 *)(ebase + 0x204) =
-+ 0x375a0000 | (handler & 0xffff);
-+ /* jr k0 */
-+ *(u32 *)(ebase + 0x208) = 0x03400008;
-+ /* nop */
-+ *(u32 *)(ebase + 0x20C) = 0x00000000;
-+ flush_icache_range(ebase + 0x200, ebase + 0x210);
-+ } else {
-+ *(volatile u32 *)(ebase + 0x200) =
-+ 0x08000000 | (0x03ffffff & (handler >> 2));
-+ flush_icache_range(ebase + 0x200, ebase + 0x204);
-+ }
-+ }
- return (void *)old_handler;
- }
-
-Index: linux-2.6.23.17/arch/mips/Makefile
-===================================================================
---- linux-2.6.23.17.orig/arch/mips/Makefile
-+++ linux-2.6.23.17/arch/mips/Makefile
-@@ -161,6 +161,13 @@ libs-$(CONFIG_SIBYTE_CFE) += arch/mips/s
- #
-
- #
-+# Texas Instruments AR7
-+#
-+core-$(CONFIG_AR7) += arch/mips/ar7/
-+cflags-$(CONFIG_AR7) += -Iinclude/asm-mips/ar7
-+load-$(CONFIG_AR7) += 0xffffffff94100000
-+
-+#
- # Acer PICA 61, Mips Magnum 4000 and Olivetti M700.
- #
- core-$(CONFIG_MACH_JAZZ) += arch/mips/jazz/
-Index: linux-2.6.23.17/include/asm-mips/page.h
-===================================================================
---- linux-2.6.23.17.orig/include/asm-mips/page.h
-+++ linux-2.6.23.17/include/asm-mips/page.h
-@@ -184,8 +184,10 @@ typedef struct { unsigned long pgprot; }
- #define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | VM_EXEC | \
- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
-
--#define UNCAC_ADDR(addr) ((addr) - PAGE_OFFSET + UNCAC_BASE)
--#define CAC_ADDR(addr) ((addr) - UNCAC_BASE + PAGE_OFFSET)
-+#define UNCAC_ADDR(addr) ((addr) - PAGE_OFFSET + UNCAC_BASE + \
-+ PHYS_OFFSET)
-+#define CAC_ADDR(addr) ((addr) - UNCAC_BASE + PAGE_OFFSET - \
-+ PHYS_OFFSET)
-
- #include <asm-generic/memory_model.h>
- #include <asm-generic/page.h>
+++ /dev/null
-Index: linux-2.6.23.17/drivers/mtd/Kconfig
-===================================================================
---- linux-2.6.23.17.orig/drivers/mtd/Kconfig
-+++ linux-2.6.23.17/drivers/mtd/Kconfig
-@@ -160,6 +160,12 @@ config MTD_AFS_PARTS
- for your particular device. It won't happen automatically. The
- 'armflash' map driver (CONFIG_MTD_ARMFLASH) does this, for example.
-
-+config MTD_AR7_PARTS
-+ tristate "TI AR7 partitioning support"
-+ depends on MTD_PARTITIONS
-+ ---help---
-+ TI AR7 partitioning support
-+
- comment "User Modules And Translation Layers"
-
- config MTD_CHAR
-Index: linux-2.6.23.17/drivers/mtd/Makefile
-===================================================================
---- linux-2.6.23.17.orig/drivers/mtd/Makefile
-+++ linux-2.6.23.17/drivers/mtd/Makefile
-@@ -11,6 +11,7 @@ obj-$(CONFIG_MTD_CONCAT) += mtdconcat.o
- obj-$(CONFIG_MTD_REDBOOT_PARTS) += redboot.o
- obj-$(CONFIG_MTD_CMDLINE_PARTS) += cmdlinepart.o
- obj-$(CONFIG_MTD_AFS_PARTS) += afs.o
-+obj-$(CONFIG_MTD_AR7_PARTS) += ar7part.o
-
- # 'Users' - code which presents functionality to userspace.
- obj-$(CONFIG_MTD_CHAR) += mtdchar.o
-Index: linux-2.6.23.17/drivers/mtd/maps/physmap.c
-===================================================================
---- linux-2.6.23.17.orig/drivers/mtd/maps/physmap.c
-+++ linux-2.6.23.17/drivers/mtd/maps/physmap.c
-@@ -74,7 +74,8 @@ static int physmap_flash_remove(struct p
-
- static const char *rom_probe_types[] = { "cfi_probe", "jedec_probe", "map_rom", NULL };
- #ifdef CONFIG_MTD_PARTITIONS
--static const char *part_probe_types[] = { "cmdlinepart", "RedBoot", NULL };
-+static const char *part_probe_types[] = {"cmdlinepart", "RedBoot",
-+ "ar7part", NULL };
- #endif
-
- static int physmap_flash_probe(struct platform_device *dev)
+++ /dev/null
-Index: linux-2.6.23.17/drivers/char/Kconfig
-===================================================================
---- linux-2.6.23.17.orig/drivers/char/Kconfig
-+++ linux-2.6.23.17/drivers/char/Kconfig
-@@ -928,6 +928,15 @@ config MWAVE
- To compile this driver as a module, choose M here: the
- module will be called mwave.
-
-+config AR7_GPIO
-+ tristate "TI AR7 GPIO Support"
-+ depends on AR7
-+ help
-+ Give userspace access to the GPIO pins on the Texas Instruments AR7
-+ processors.
-+
-+ If compiled as a module, it will be called ar7_gpio.
-+
- config SCx200_GPIO
- tristate "NatSemi SCx200 GPIO Support"
- depends on SCx200
-Index: linux-2.6.23.17/drivers/char/Makefile
-===================================================================
---- linux-2.6.23.17.orig/drivers/char/Makefile
-+++ linux-2.6.23.17/drivers/char/Makefile
-@@ -89,6 +89,7 @@ obj-$(CONFIG_COBALT_LCD) += lcd.o
- obj-$(CONFIG_PPDEV) += ppdev.o
- obj-$(CONFIG_NWBUTTON) += nwbutton.o
- obj-$(CONFIG_NWFLASH) += nwflash.o
-+obj-$(CONFIG_AR7_GPIO) += ar7_gpio.o
- obj-$(CONFIG_SCx200_GPIO) += scx200_gpio.o
- obj-$(CONFIG_PC8736x_GPIO) += pc8736x_gpio.o
- obj-$(CONFIG_NSC_GPIO) += nsc_gpio.o
+++ /dev/null
-Index: linux-2.6.23.17/drivers/Kconfig
-===================================================================
---- linux-2.6.23.17.orig/drivers/Kconfig
-+++ linux-2.6.23.17/drivers/Kconfig
-@@ -93,4 +93,6 @@ source "drivers/kvm/Kconfig"
- source "drivers/uio/Kconfig"
-
- source "drivers/lguest/Kconfig"
-+
-+source "drivers/vlynq/Kconfig"
- endmenu
-Index: linux-2.6.23.17/drivers/Makefile
-===================================================================
---- linux-2.6.23.17.orig/drivers/Makefile
-+++ linux-2.6.23.17/drivers/Makefile
-@@ -89,4 +89,5 @@ obj-$(CONFIG_DMA_ENGINE) += dma/
- obj-$(CONFIG_HID) += hid/
- obj-$(CONFIG_PPC_PS3) += ps3/
- obj-$(CONFIG_OF) += of/
-+obj-$(CONFIG_VLYNQ) += vlynq/
- obj-$(CONFIG_GPIO_DEVICE) += gpio/
+++ /dev/null
-Index: linux-2.6.23.17/drivers/char/watchdog/Kconfig
-===================================================================
---- linux-2.6.23.17.orig/drivers/char/watchdog/Kconfig
-+++ linux-2.6.23.17/drivers/char/watchdog/Kconfig
-@@ -583,6 +583,12 @@ config SBC_EPX_C3_WATCHDOG
-
- # MIPS Architecture
-
-+config AR7_WDT
-+ tristate "TI AR7 Watchdog Timer"
-+ depends on WATCHDOG && AR7
-+ help
-+ Hardware driver for the TI AR7 Watchdog Timer.
-+
- config INDYDOG
- tristate "Indy/I2 Hardware Watchdog"
- depends on SGI_IP22
-Index: linux-2.6.23.17/drivers/char/watchdog/Makefile
-===================================================================
---- linux-2.6.23.17.orig/drivers/char/watchdog/Makefile
-+++ linux-2.6.23.17/drivers/char/watchdog/Makefile
-@@ -87,6 +87,7 @@ obj-$(CONFIG_SBC_EPX_C3_WATCHDOG) += sbc
- # M68KNOMMU Architecture
-
- # MIPS Architecture
-+obj-$(CONFIG_AR7_WDT) += ar7_wdt.o
- obj-$(CONFIG_INDYDOG) += indydog.o
- obj-$(CONFIG_WDT_MTX1) += mtx-1_wdt.o
- obj-$(CONFIG_WDT_RM9K_GPI) += rm9k_wdt.o
+++ /dev/null
-Index: linux-2.6.23.17/drivers/net/Kconfig
-===================================================================
---- linux-2.6.23.17.orig/drivers/net/Kconfig
-+++ linux-2.6.23.17/drivers/net/Kconfig
-@@ -1965,6 +1965,15 @@ config SC92031
- To compile this driver as a module, choose M here: the module
- will be called sc92031. This is recommended.
-
-+config CPMAC
-+ tristate "TI AR7 CPMAC Ethernet support (EXPERIMENTAL)"
-+ depends on NET_ETHERNET && EXPERIMENTAL && AR7
-+ select PHYLIB
-+ select FIXED_PHY
-+ select FIXED_MII_100_FDX
-+ help
-+ TI AR7 CPMAC Ethernet support
-+
- config NET_POCKET
- bool "Pocket and portable adapters"
- depends on PARPORT
-Index: linux-2.6.23.17/drivers/net/Makefile
-===================================================================
---- linux-2.6.23.17.orig/drivers/net/Makefile
-+++ linux-2.6.23.17/drivers/net/Makefile
-@@ -156,6 +156,7 @@ obj-$(CONFIG_8139CP) += 8139cp.o
- obj-$(CONFIG_8139TOO) += 8139too.o
- obj-$(CONFIG_ZNET) += znet.o
- obj-$(CONFIG_LAN_SAA9730) += saa9730.o
-+obj-$(CONFIG_CPMAC) += cpmac.o
- obj-$(CONFIG_DEPCA) += depca.o
- obj-$(CONFIG_EWRK3) += ewrk3.o
- obj-$(CONFIG_ATP) += atp.o
+++ /dev/null
-Index: linux-2.6.23.17/drivers/net/phy/fixed.c
-===================================================================
---- linux-2.6.23.17.orig/drivers/net/phy/fixed.c
-+++ linux-2.6.23.17/drivers/net/phy/fixed.c
-@@ -189,6 +189,19 @@ static struct phy_driver fixed_mdio_driv
- .driver = { .owner = THIS_MODULE,},
- };
-
-+static void fixed_mdio_release (struct device * dev)
-+{
-+ struct phy_device *phydev = container_of(dev, struct phy_device, dev);
-+ struct mii_bus *bus = phydev->bus;
-+ struct fixed_info *fixed = bus->priv;
-+
-+ kfree(phydev);
-+ kfree(bus->dev);
-+ kfree(bus);
-+ kfree(fixed->regs);
-+ kfree(fixed);
-+}
-+
- /*-----------------------------------------------------------------------------
- * This func is used to create all the necessary stuff, bind
- * the fixed phy driver and register all it on the mdio_bus_type.
-@@ -224,6 +237,12 @@ static int fixed_mdio_register_device(in
- }
-
- fixed->regs = kzalloc(MII_REGS_NUM*sizeof(int), GFP_KERNEL);
-+ if (NULL == fixed->regs) {
-+ kfree(dev);
-+ kfree(new_bus);
-+ kfree(fixed);
-+ return -ENOMEM;
-+ }
- fixed->regs_num = MII_REGS_NUM;
- fixed->phy_status.speed = speed;
- fixed->phy_status.duplex = duplex;
-@@ -252,8 +271,11 @@ static int fixed_mdio_register_device(in
- fixed->phydev = phydev;
-
- if(NULL == phydev) {
-- err = -ENOMEM;
-- goto device_create_fail;
-+ kfree(dev);
-+ kfree(new_bus);
-+ kfree(fixed->regs);
-+ kfree(fixed);
-+ return -ENOMEM;
- }
-
- phydev->irq = PHY_IGNORE_INTERRUPT;
-@@ -265,8 +287,33 @@ static int fixed_mdio_register_device(in
- else
- snprintf(phydev->dev.bus_id, BUS_ID_SIZE,
- "fixed@%d:%d", speed, duplex);
-+
- phydev->bus = new_bus;
-
-+#if 1
-+ phydev->dev.driver = &fixed_mdio_driver.driver;
-+ phydev->dev.release = fixed_mdio_release;
-+
-+ err = phydev->dev.driver->probe(&phydev->dev);
-+ if(err < 0) {
-+ printk(KERN_ERR "Phy %s: problems with fixed driver\n",
-+ phydev->dev.bus_id);
-+ kfree(phydev);
-+ kfree(dev);
-+ kfree(new_bus);
-+ kfree(fixed->regs);
-+ kfree(fixed);
-+ return err;
-+ }
-+
-+ err = device_register(&phydev->dev);
-+ if(err) {
-+ printk(KERN_ERR "Phy %s failed to register\n",
-+ phydev->dev.bus_id);
-+ }
-+
-+ return 0;
-+#else
- err = device_register(&phydev->dev);
- if(err) {
- printk(KERN_ERR "Phy %s failed to register\n",
-@@ -303,6 +350,7 @@ device_create_fail:
- kfree(fixed);
-
- return err;
-+#endif
- }
- #endif
-
+++ /dev/null
-Index: linux-2.6.23.17/drivers/serial/8250.c
-===================================================================
---- linux-2.6.23.17.orig/drivers/serial/8250.c
-+++ linux-2.6.23.17/drivers/serial/8250.c
-@@ -267,6 +267,13 @@ static const struct serial8250_config ua
- .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10,
- .flags = UART_CAP_FIFO,
- },
-+ [PORT_AR7] = {
-+ .name = "TI-AR7",
-+ .fifo_size = 16,
-+ .tx_loadsz = 16,
-+ .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_00,
-+ .flags = UART_CAP_FIFO | UART_CAP_AFE,
-+ },
- };
-
- #if defined (CONFIG_SERIAL_8250_AU1X00)
-@@ -2455,7 +2462,11 @@ static void serial8250_console_putchar(s
- {
- struct uart_8250_port *up = (struct uart_8250_port *)port;
-
-+#ifdef CONFIG_AR7
-+ wait_for_xmitr(up, BOTH_EMPTY);
-+#else
- wait_for_xmitr(up, UART_LSR_THRE);
-+#endif
- serial_out(up, UART_TX, ch);
- }
-
-Index: linux-2.6.23.17/include/linux/serial_core.h
-===================================================================
---- linux-2.6.23.17.orig/include/linux/serial_core.h
-+++ linux-2.6.23.17/include/linux/serial_core.h
-@@ -40,6 +40,7 @@
- #define PORT_NS16550A 14
- #define PORT_XSCALE 15
- #define PORT_RM9000 16 /* PMC-Sierra RM9xxx internal UART */
-+#define PORT_AR7 16
- #define PORT_MAX_8250 16 /* max port ID */
-
- /*
-Index: linux-2.6.23.17/include/linux/serialP.h
-===================================================================
---- linux-2.6.23.17.orig/include/linux/serialP.h
-+++ linux-2.6.23.17/include/linux/serialP.h
-@@ -135,6 +135,10 @@ struct rs_multiport_struct {
- * the interrupt line _up_ instead of down, so if we register the IRQ
- * while the UART is in that state, we die in an IRQ storm. */
- #define ALPHA_KLUDGE_MCR (UART_MCR_OUT2)
-+#elif defined(CONFIG_AR7)
-+/* This is how it is set up by bootloader... */
-+#define ALPHA_KLUDGE_MCR (UART_MCR_OUT2 | UART_MCR_OUT1 \
-+ | UART_MCR_RTS | UART_MCR_DTR)
- #else
- #define ALPHA_KLUDGE_MCR 0
- #endif
+++ /dev/null
-Index: linux-2.6.24.7/arch/mips/Kconfig
-===================================================================
---- linux-2.6.24.7.orig/arch/mips/Kconfig
-+++ linux-2.6.24.7/arch/mips/Kconfig
-@@ -16,6 +16,24 @@ choice
- prompt "System type"
- default SGI_IP22
-
-+config AR7
-+ bool "Texas Instruments AR7"
-+ select BOOT_ELF32
-+ select DMA_NONCOHERENT
-+ select CEVT_R4K
-+ select CSRC_R4K
-+ select IRQ_CPU
-+ select NO_EXCEPT_FILL
-+ select SWAP_IO_SPACE
-+ select SYS_HAS_CPU_MIPS32_R1
-+ select SYS_HAS_EARLY_PRINTK
-+ select SYS_SUPPORTS_32BIT_KERNEL
-+ select SYS_SUPPORTS_KGDB
-+ select SYS_SUPPORTS_LITTLE_ENDIAN
-+ select SYS_SUPPORTS_BIG_ENDIAN
-+ select GENERIC_GPIO
-+ select GENERIC_HARDIRQS_NO__DO_IRQ
-+
- config MACH_ALCHEMY
- bool "Alchemy processor based machines"
-
-Index: linux-2.6.24.7/arch/mips/kernel/traps.c
-===================================================================
---- linux-2.6.24.7.orig/arch/mips/kernel/traps.c
-+++ linux-2.6.24.7/arch/mips/kernel/traps.c
-@@ -1093,9 +1093,22 @@ void *set_except_vector(int n, void *add
-
- exception_handlers[n] = handler;
- if (n == 0 && cpu_has_divec) {
-- *(u32 *)(ebase + 0x200) = 0x08000000 |
-- (0x03ffffff & (handler >> 2));
-- flush_icache_range(ebase + 0x200, ebase + 0x204);
-+ if ((handler ^ (ebase + 4)) & 0xfc000000) {
-+ /* lui k0, 0x0000 */
-+ *(u32 *)(ebase + 0x200) = 0x3c1a0000 | (handler >> 16);
-+ /* ori k0, 0x0000 */
-+ *(u32 *)(ebase + 0x204) =
-+ 0x375a0000 | (handler & 0xffff);
-+ /* jr k0 */
-+ *(u32 *)(ebase + 0x208) = 0x03400008;
-+ /* nop */
-+ *(u32 *)(ebase + 0x20C) = 0x00000000;
-+ flush_icache_range(ebase + 0x200, ebase + 0x210);
-+ } else {
-+ *(u32 *)(ebase + 0x200) =
-+ 0x08000000 | (0x03ffffff & (handler >> 2));
-+ flush_icache_range(ebase + 0x200, ebase + 0x204);
-+ }
- }
- return (void *)old_handler;
- }
-Index: linux-2.6.24.7/arch/mips/Makefile
-===================================================================
---- linux-2.6.24.7.orig/arch/mips/Makefile
-+++ linux-2.6.24.7/arch/mips/Makefile
-@@ -159,6 +159,13 @@ libs-$(CONFIG_SIBYTE_CFE) += arch/mips/s
- #
-
- #
-+# Texas Instruments AR7
-+#
-+core-$(CONFIG_AR7) += arch/mips/ar7/
-+cflags-$(CONFIG_AR7) += -Iinclude/asm-mips/ar7
-+load-$(CONFIG_AR7) += 0xffffffff94100000
-+
-+#
- # Acer PICA 61, Mips Magnum 4000 and Olivetti M700.
- #
- core-$(CONFIG_MACH_JAZZ) += arch/mips/jazz/
-Index: linux-2.6.24.7/include/asm-mips/page.h
-===================================================================
---- linux-2.6.24.7.orig/include/asm-mips/page.h
-+++ linux-2.6.24.7/include/asm-mips/page.h
-@@ -184,8 +184,10 @@ typedef struct { unsigned long pgprot; }
- #define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | VM_EXEC | \
- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
-
--#define UNCAC_ADDR(addr) ((addr) - PAGE_OFFSET + UNCAC_BASE)
--#define CAC_ADDR(addr) ((addr) - UNCAC_BASE + PAGE_OFFSET)
-+#define UNCAC_ADDR(addr) ((addr) - PAGE_OFFSET + UNCAC_BASE + \
-+ PHYS_OFFSET)
-+#define CAC_ADDR(addr) ((addr) - UNCAC_BASE + PAGE_OFFSET - \
-+ PHYS_OFFSET)
-
- #include <asm-generic/memory_model.h>
- #include <asm-generic/page.h>
+++ /dev/null
-Index: linux-2.6.24.7/drivers/mtd/Kconfig
-===================================================================
---- linux-2.6.24.7.orig/drivers/mtd/Kconfig
-+++ linux-2.6.24.7/drivers/mtd/Kconfig
-@@ -160,6 +160,12 @@ config MTD_AFS_PARTS
- for your particular device. It won't happen automatically. The
- 'armflash' map driver (CONFIG_MTD_ARMFLASH) does this, for example.
-
-+config MTD_AR7_PARTS
-+ tristate "TI AR7 partitioning support"
-+ depends on MTD_PARTITIONS
-+ ---help---
-+ TI AR7 partitioning support
-+
- comment "User Modules And Translation Layers"
-
- config MTD_CHAR
-Index: linux-2.6.24.7/drivers/mtd/Makefile
-===================================================================
---- linux-2.6.24.7.orig/drivers/mtd/Makefile
-+++ linux-2.6.24.7/drivers/mtd/Makefile
-@@ -11,6 +11,7 @@ obj-$(CONFIG_MTD_CONCAT) += mtdconcat.o
- obj-$(CONFIG_MTD_REDBOOT_PARTS) += redboot.o
- obj-$(CONFIG_MTD_CMDLINE_PARTS) += cmdlinepart.o
- obj-$(CONFIG_MTD_AFS_PARTS) += afs.o
-+obj-$(CONFIG_MTD_AR7_PARTS) += ar7part.o
-
- # 'Users' - code which presents functionality to userspace.
- obj-$(CONFIG_MTD_CHAR) += mtdchar.o
-Index: linux-2.6.24.7/drivers/mtd/maps/physmap.c
-===================================================================
---- linux-2.6.24.7.orig/drivers/mtd/maps/physmap.c
-+++ linux-2.6.24.7/drivers/mtd/maps/physmap.c
-@@ -74,7 +74,8 @@ static int physmap_flash_remove(struct p
-
- static const char *rom_probe_types[] = { "cfi_probe", "jedec_probe", "map_rom", NULL };
- #ifdef CONFIG_MTD_PARTITIONS
--static const char *part_probe_types[] = { "cmdlinepart", "RedBoot", NULL };
-+static const char *part_probe_types[] = {"cmdlinepart", "RedBoot",
-+ "ar7part", NULL };
- #endif
-
- static int physmap_flash_probe(struct platform_device *dev)
+++ /dev/null
-Index: linux-2.6.24.7/drivers/char/Kconfig
-===================================================================
---- linux-2.6.24.7.orig/drivers/char/Kconfig
-+++ linux-2.6.24.7/drivers/char/Kconfig
-@@ -904,6 +904,15 @@ config MWAVE
- To compile this driver as a module, choose M here: the
- module will be called mwave.
-
-+config AR7_GPIO
-+ tristate "TI AR7 GPIO Support"
-+ depends on AR7
-+ help
-+ Give userspace access to the GPIO pins on the Texas Instruments AR7
-+ processors.
-+
-+ If compiled as a module, it will be called ar7_gpio.
-+
- config SCx200_GPIO
- tristate "NatSemi SCx200 GPIO Support"
- depends on SCx200
-Index: linux-2.6.24.7/drivers/char/Makefile
-===================================================================
---- linux-2.6.24.7.orig/drivers/char/Makefile
-+++ linux-2.6.24.7/drivers/char/Makefile
-@@ -89,6 +89,7 @@ obj-$(CONFIG_COBALT_LCD) += lcd.o
- obj-$(CONFIG_PPDEV) += ppdev.o
- obj-$(CONFIG_NWBUTTON) += nwbutton.o
- obj-$(CONFIG_NWFLASH) += nwflash.o
-+obj-$(CONFIG_AR7_GPIO) += ar7_gpio.o
- obj-$(CONFIG_SCx200_GPIO) += scx200_gpio.o
- obj-$(CONFIG_PC8736x_GPIO) += pc8736x_gpio.o
- obj-$(CONFIG_NSC_GPIO) += nsc_gpio.o
+++ /dev/null
-Index: linux-2.6.24.7/drivers/Kconfig
-===================================================================
---- linux-2.6.24.7.orig/drivers/Kconfig
-+++ linux-2.6.24.7/drivers/Kconfig
-@@ -96,5 +96,7 @@ source "drivers/kvm/Kconfig"
-
- source "drivers/uio/Kconfig"
-
-+source "drivers/vlynq/Kconfig"
-+
- source "drivers/virtio/Kconfig"
- endmenu
-Index: linux-2.6.24.7/drivers/Makefile
-===================================================================
---- linux-2.6.24.7.orig/drivers/Makefile
-+++ linux-2.6.24.7/drivers/Makefile
-@@ -89,6 +89,7 @@ obj-$(CONFIG_DCA) += dca/
- obj-$(CONFIG_HID) += hid/
- obj-$(CONFIG_PPC_PS3) += ps3/
- obj-$(CONFIG_OF) += of/
-+obj-$(CONFIG_VLYNQ) += vlynq/
- obj-$(CONFIG_SSB) += ssb/
- obj-$(CONFIG_VIRTIO) += virtio/
- obj-$(CONFIG_GPIO_DEVICE) += gpio/
+++ /dev/null
-Index: linux-2.6.24.7/drivers/net/cpmac.c
-===================================================================
---- linux-2.6.24.7.orig/drivers/net/cpmac.c
-+++ linux-2.6.24.7/drivers/net/cpmac.c
-@@ -38,6 +38,7 @@
- #include <linux/platform_device.h>
- #include <linux/dma-mapping.h>
- #include <asm/gpio.h>
-+#include <asm/atomic.h>
-
- MODULE_AUTHOR("Eugene Konev <ejka@imfi.kspu.ru>");
- MODULE_DESCRIPTION("TI AR7 ethernet driver (CPMAC)");
-@@ -207,6 +208,7 @@ struct cpmac_priv {
- struct work_struct reset_work;
- struct platform_device *pdev;
- struct napi_struct napi;
-+ atomic_t reset_pending;
- };
-
- static irqreturn_t cpmac_irq(int, void *);
-@@ -455,6 +457,9 @@ static int cpmac_start_xmit(struct sk_bu
- struct cpmac_desc *desc;
- struct cpmac_priv *priv = netdev_priv(dev);
-
-+ if (unlikely(atomic_read(&priv->reset_pending)))
-+ return NETDEV_TX_BUSY;
-+
- if (unlikely(skb_padto(skb, ETH_ZLEN)))
- return NETDEV_TX_OK;
-
-@@ -634,14 +639,14 @@ static void cpmac_clear_tx(struct net_de
- priv->desc_ring[i].dataflags = 0;
- if (priv->desc_ring[i].skb) {
- dev_kfree_skb_any(priv->desc_ring[i].skb);
-- if (netif_subqueue_stopped(dev, i))
-- netif_wake_subqueue(dev, i);
-+ priv->desc_ring[i].skb = NULL;
- }
- }
- }
-
- static void cpmac_hw_error(struct work_struct *work)
- {
-+ int i;
- struct cpmac_priv *priv =
- container_of(work, struct cpmac_priv, reset_work);
-
-@@ -650,8 +655,47 @@ static void cpmac_hw_error(struct work_s
- spin_unlock(&priv->rx_lock);
- cpmac_clear_tx(priv->dev);
- cpmac_hw_start(priv->dev);
-- napi_enable(&priv->napi);
-- netif_start_queue(priv->dev);
-+ barrier();
-+ atomic_dec(&priv->reset_pending);
-+
-+ for (i = 0; i < CPMAC_QUEUES; i++) {
-+ netif_wake_subqueue(priv->dev, i);
-+ }
-+ netif_wake_queue(priv->dev);
-+ cpmac_write(priv->regs, CPMAC_MAC_INT_ENABLE, 3);
-+}
-+
-+static void cpmac_check_status(struct net_device *dev)
-+{
-+ struct cpmac_priv *priv = netdev_priv(dev);
-+
-+ u32 macstatus = cpmac_read(priv->regs, CPMAC_MAC_STATUS);
-+ int rx_channel = (macstatus >> 8) & 7;
-+ int rx_code = (macstatus >> 12) & 15;
-+ int tx_channel = (macstatus >> 16) & 7;
-+ int tx_code = (macstatus >> 20) & 15;
-+
-+ if (rx_code || tx_code) {
-+ if (netif_msg_drv(priv) && net_ratelimit()) {
-+ /* Can't find any documentation on what these error codes actually are.
-+ * So just log them and hope..
-+ */
-+ if (rx_code)
-+ printk(KERN_WARNING "%s: host error %d on rx channel %d (macstatus %08x), resetting\n",
-+ dev->name, rx_code, rx_channel, macstatus);
-+ if (tx_code)
-+ printk(KERN_WARNING "%s: host error %d on tx channel %d (macstatus %08x), resetting\n",
-+ dev->name, tx_code, tx_channel, macstatus);
-+ }
-+
-+ netif_stop_queue(dev);
-+ cpmac_hw_stop(dev);
-+ if (schedule_work(&priv->reset_work))
-+ atomic_inc(&priv->reset_pending);
-+ if (unlikely(netif_msg_hw(priv)))
-+ cpmac_dump_regs(dev);
-+ }
-+ cpmac_write(priv->regs, CPMAC_MAC_INT_CLEAR, 0xff);
- }
-
- static irqreturn_t cpmac_irq(int irq, void *dev_id)
-@@ -661,9 +705,6 @@ static irqreturn_t cpmac_irq(int irq, vo
- int queue;
- u32 status;
-
-- if (!dev)
-- return IRQ_NONE;
--
- priv = netdev_priv(dev);
-
- status = cpmac_read(priv->regs, CPMAC_MAC_INT_VECTOR);
-@@ -685,49 +726,33 @@ static irqreturn_t cpmac_irq(int irq, vo
-
- cpmac_write(priv->regs, CPMAC_MAC_EOI_VECTOR, 0);
-
-- if (unlikely(status & (MAC_INT_HOST | MAC_INT_STATUS))) {
-- if (netif_msg_drv(priv) && net_ratelimit())
-- printk(KERN_ERR "%s: hw error, resetting...\n",
-- dev->name);
-- netif_stop_queue(dev);
-- napi_disable(&priv->napi);
-- cpmac_hw_stop(dev);
-- schedule_work(&priv->reset_work);
-- if (unlikely(netif_msg_hw(priv)))
-- cpmac_dump_regs(dev);
-- }
-+ if (unlikely(status & (MAC_INT_HOST | MAC_INT_STATUS)))
-+ cpmac_check_status(dev);
-
- return IRQ_HANDLED;
- }
-
- static void cpmac_tx_timeout(struct net_device *dev)
- {
-- struct cpmac_priv *priv = netdev_priv(dev);
- int i;
-+ struct cpmac_priv *priv = netdev_priv(dev);
-
- spin_lock(&priv->lock);
- dev->stats.tx_errors++;
- spin_unlock(&priv->lock);
- if (netif_msg_tx_err(priv) && net_ratelimit())
- printk(KERN_WARNING "%s: transmit timeout\n", dev->name);
-- /*
-- * FIXME: waking up random queue is not the best thing to
-- * do... on the other hand why we got here at all?
-- */
--#ifdef CONFIG_NETDEVICES_MULTIQUEUE
-- for (i = 0; i < CPMAC_QUEUES; i++)
-- if (priv->desc_ring[i].skb) {
-- priv->desc_ring[i].dataflags = 0;
-- dev_kfree_skb_any(priv->desc_ring[i].skb);
-- netif_wake_subqueue(dev, i);
-- break;
-- }
--#else
-- priv->desc_ring[0].dataflags = 0;
-- if (priv->desc_ring[0].skb)
-- dev_kfree_skb_any(priv->desc_ring[0].skb);
-- netif_wake_queue(dev);
--#endif
-+
-+ atomic_inc(&priv->reset_pending);
-+ barrier();
-+ cpmac_clear_tx(dev);
-+ barrier();
-+ atomic_dec(&priv->reset_pending);
-+
-+ netif_wake_queue(priv->dev);
-+ for (i = 0; i < CPMAC_QUEUES; i++) {
-+ netif_wake_subqueue(dev, i);
-+ }
- }
-
- static int cpmac_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
-@@ -848,15 +873,6 @@ static void cpmac_adjust_link(struct net
- spin_unlock(&priv->lock);
- }
-
--static int cpmac_link_update(struct net_device *dev,
-- struct fixed_phy_status *status)
--{
-- status->link = 1;
-- status->speed = 100;
-- status->duplex = 1;
-- return 0;
--}
--
- static int cpmac_open(struct net_device *dev)
- {
- int i, size, res;
-@@ -923,6 +939,7 @@ static int cpmac_open(struct net_device
- goto fail_irq;
- }
-
-+ atomic_set(&priv->reset_pending, 0);
- INIT_WORK(&priv->reset_work, cpmac_hw_error);
- cpmac_hw_start(dev);
-
-@@ -999,11 +1016,11 @@ static int external_switch;
- static int __devinit cpmac_probe(struct platform_device *pdev)
- {
- int rc, phy_id, i;
-+ int mdio_bus_id = cpmac_mii.id;
- struct resource *mem;
- struct cpmac_priv *priv;
- struct net_device *dev;
- struct plat_cpmac_data *pdata;
-- struct fixed_info *fixed_phy;
- DECLARE_MAC_BUF(mac);
-
- pdata = pdev->dev.platform_data;
-@@ -1017,9 +1034,23 @@ static int __devinit cpmac_probe(struct
- }
-
- if (phy_id == PHY_MAX_ADDR) {
-- if (external_switch || dumb_switch)
-+ if (external_switch || dumb_switch) {
-+ struct fixed_phy_status status = {};
-+
-+ mdio_bus_id = 0;
-+
-+ /*
-+ * FIXME: this should be in the platform code!
-+ * Since there is not platform code at all (that is,
-+ * no mainline users of that driver), place it here
-+ * for now.
-+ */
- phy_id = 0;
-- else {
-+ status.link = 1;
-+ status.duplex = 1;
-+ status.speed = 100;
-+ fixed_phy_add(PHY_POLL, phy_id, &status);
-+ } else {
- printk(KERN_ERR "cpmac: no PHY present\n");
- return -ENODEV;
- }
-@@ -1063,32 +1094,8 @@ static int __devinit cpmac_probe(struct
- priv->msg_enable = netif_msg_init(debug_level, 0xff);
- memcpy(dev->dev_addr, pdata->dev_addr, sizeof(dev->dev_addr));
-
-- if (phy_id == 31) {
-- snprintf(priv->phy_name, BUS_ID_SIZE, PHY_ID_FMT, cpmac_mii.id,
-- phy_id);
-- } else {
-- /* Let's try to get a free fixed phy... */
-- for (i = 0; i < MAX_PHY_AMNT; i++) {
-- fixed_phy = fixed_mdio_get_phydev(i);
-- if (!fixed_phy)
-- continue;
-- if (!fixed_phy->phydev->attached_dev) {
-- strncpy(priv->phy_name,
-- fixed_phy->phydev->dev.bus_id,
-- BUS_ID_SIZE);
-- fixed_mdio_set_link_update(fixed_phy->phydev,
-- &cpmac_link_update);
-- goto phy_found;
-- }
-- }
-- if (netif_msg_drv(priv))
-- printk(KERN_ERR "%s: Could not find fixed PHY\n",
-- dev->name);
-- rc = -ENODEV;
-- goto fail;
-- }
-+ snprintf(priv->phy_name, BUS_ID_SIZE, PHY_ID_FMT, mdio_bus_id, phy_id);
-
--phy_found:
- priv->phy = phy_connect(dev, priv->phy_name, &cpmac_adjust_link, 0,
- PHY_INTERFACE_MODE_MII);
- if (IS_ERR(priv->phy)) {
+++ /dev/null
-From 0daaa095cefd9d7091a7ccce2ff89f1ff4feae7a Mon Sep 17 00:00:00 2001
-From: Anton Vorontsov <avorontsov@ru.mvista.com>
-Date: Wed, 5 Mar 2008 14:52:26 +0300
-Subject: [PATCH] AR7/cpmac: convert to new fixed phy infrastructure, now for real
-
-This patch converts platform code to register fixed phys early.
-cpmac driver modified to blindly accept fixed phy id (that is equal
-to platform device id).
-
-Signed-off-by: Anton Vorontsov <avorontsov@ru.mvista.com>
----
- arch/mips/ar7/platform.c | 17 +++++++++++++++++
- drivers/net/cpmac.c | 19 +++----------------
- 2 files changed, 20 insertions(+), 16 deletions(-)
-
-Index: linux-2.6.24.7/arch/mips/ar7/platform.c
-===================================================================
---- linux-2.6.24.7.orig/arch/mips/ar7/platform.c
-+++ linux-2.6.24.7/arch/mips/ar7/platform.c
-@@ -33,6 +33,8 @@
- #include <linux/vlynq.h>
- #include <linux/leds.h>
- #include <linux/string.h>
-+#include <linux/phy.h>
-+#include <linux/phy_fixed.h>
-
- #include <asm/addrspace.h>
- #include <asm/ar7/ar7.h>
-@@ -205,6 +207,13 @@ static struct physmap_flash_data physmap
- .width = 2,
- };
-
-+/* lets assume this is suitable for both high and low cpmacs links */
-+static struct fixed_phy_status fixed_phy_status __initdata = {
-+ .link = 1,
-+ .speed = 100,
-+ .duplex = 1,
-+};
-+
- static struct plat_cpmac_data cpmac_low_data = {
- .reset_bit = 17,
- .power_bit = 20,
-@@ -506,6 +515,10 @@ static int __init ar7_register_devices(v
- }
-
- if (ar7_has_high_cpmac()) {
-+ res = fixed_phy_add(PHY_POLL, cpmac_high.id, &fixed_phy_status);
-+ if (res && res != -ENODEV)
-+ return res;
-+
- cpmac_get_mac(1, cpmac_high_data.dev_addr);
- res = platform_device_register(&cpmac_high);
- if (res)
-@@ -514,6 +527,10 @@ static int __init ar7_register_devices(v
- cpmac_low_data.phy_mask = 0xffffffff;
- }
-
-+ res = fixed_phy_add(PHY_POLL, cpmac_low.id, &fixed_phy_status);
-+ if (res && res != -ENODEV)
-+ return res;
-+
- cpmac_get_mac(0, cpmac_low_data.dev_addr);
- res = platform_device_register(&cpmac_low);
- if (res)
-Index: linux-2.6.24.7/drivers/net/cpmac.c
-===================================================================
---- linux-2.6.24.7.orig/drivers/net/cpmac.c
-+++ linux-2.6.24.7/drivers/net/cpmac.c
-@@ -1035,23 +1035,10 @@ static int __devinit cpmac_probe(struct
-
- if (phy_id == PHY_MAX_ADDR) {
- if (external_switch || dumb_switch) {
-- struct fixed_phy_status status = {};
--
-- mdio_bus_id = 0;
--
-- /*
-- * FIXME: this should be in the platform code!
-- * Since there is not platform code at all (that is,
-- * no mainline users of that driver), place it here
-- * for now.
-- */
-- phy_id = 0;
-- status.link = 1;
-- status.duplex = 1;
-- status.speed = 100;
-- fixed_phy_add(PHY_POLL, phy_id, &status);
-+ mdio_bus_id = 0; /* fixed phys bus */
-+ phy_id = pdev->id;
- } else {
-- printk(KERN_ERR "cpmac: no PHY present\n");
-+ dev_err(&pdev->dev, "no PHY present\n");
- return -ENODEV;
- }
- }
+++ /dev/null
-Index: linux-2.6.24.7/drivers/net/cpmac.c
-===================================================================
---- linux-2.6.24.7.orig/drivers/net/cpmac.c
-+++ linux-2.6.24.7/drivers/net/cpmac.c
-@@ -187,6 +187,7 @@ struct cpmac_desc {
- #define CPMAC_EOQ 0x1000
- struct sk_buff *skb;
- struct cpmac_desc *next;
-+ struct cpmac_desc *prev;
- dma_addr_t mapping;
- dma_addr_t data_mapping;
- };
-@@ -242,6 +243,16 @@ static void cpmac_dump_desc(struct net_d
- printk("\n");
- }
-
-+static void cpmac_dump_all_desc(struct net_device *dev)
-+{
-+ struct cpmac_priv *priv = netdev_priv(dev);
-+ struct cpmac_desc *dump = priv->rx_head;
-+ do {
-+ cpmac_dump_desc(dev, dump);
-+ dump = dump->next;
-+ } while (dump != priv->rx_head);
-+}
-+
- static void cpmac_dump_skb(struct net_device *dev, struct sk_buff *skb)
- {
- int i;
-@@ -413,21 +424,40 @@ static struct sk_buff *cpmac_rx_one(stru
- static int cpmac_poll(struct napi_struct *napi, int budget)
- {
- struct sk_buff *skb;
-- struct cpmac_desc *desc;
-- int received = 0;
-+ struct cpmac_desc *desc, *restart;
- struct cpmac_priv *priv = container_of(napi, struct cpmac_priv, napi);
-+ int received = 0, processed = 0;
-
- spin_lock(&priv->rx_lock);
- if (unlikely(!priv->rx_head)) {
- if (netif_msg_rx_err(priv) && net_ratelimit())
- printk(KERN_WARNING "%s: rx: polling, but no queue\n",
- priv->dev->name);
-+ spin_unlock(&priv->rx_lock);
- netif_rx_complete(priv->dev, napi);
- return 0;
- }
-
- desc = priv->rx_head;
-+ restart = NULL;
- while (((desc->dataflags & CPMAC_OWN) == 0) && (received < budget)) {
-+ processed++;
-+
-+ if ((desc->dataflags & CPMAC_EOQ) != 0) {
-+ /* The last update to eoq->hw_next didn't happen soon enough, and the
-+ * receiver stopped here. Remember this descriptor so we can restart
-+ * the receiver after freeing some space.
-+ */
-+ if (unlikely(restart)) {
-+ if (netif_msg_rx_err(priv))
-+ printk(KERN_ERR "%s: poll found a duplicate EOQ: %p and %p\n",
-+ priv->dev->name, restart, desc);
-+ goto fatal_error;
-+ }
-+
-+ restart = desc->next;
-+ }
-+
- skb = cpmac_rx_one(priv, desc);
- if (likely(skb)) {
- netif_receive_skb(skb);
-@@ -436,19 +466,81 @@ static int cpmac_poll(struct napi_struct
- desc = desc->next;
- }
-
-+ if (desc != priv->rx_head) {
-+ /* We freed some buffers, but not the whole ring, add what we did free to the rx list */
-+ desc->prev->hw_next = (u32)0;
-+ priv->rx_head->prev->hw_next = priv->rx_head->mapping;
-+ }
-+
-+ /* Optimization: If we did not actually process an EOQ (perhaps because of
-+ * quota limits), check to see if the tail of the queue has EOQ set. We
-+ * should immediately restart in that case so that the receiver can restart
-+ * and run in parallel with more packet processing. This lets us handle slightly
-+ * larger bursts before running out of ring space (assuming dev->weight < ring_size)
-+ */
-+ if (!restart &&
-+ (priv->rx_head->prev->dataflags & (CPMAC_OWN|CPMAC_EOQ)) == CPMAC_EOQ &&
-+ (priv->rx_head->dataflags & CPMAC_OWN) != 0) {
-+ /* reset EOQ so the poll loop (above) doesn't try to restart this when it
-+ * eventually gets to this descriptor.
-+ */
-+ priv->rx_head->prev->dataflags &= ~CPMAC_EOQ;
-+ restart = priv->rx_head;
-+ }
-+
-+ if (restart) {
-+ priv->dev->stats.rx_errors++;
-+ priv->dev->stats.rx_fifo_errors++;
-+ if (netif_msg_rx_err(priv) && net_ratelimit())
-+ printk(KERN_WARNING "%s: rx dma ring overrun\n", priv->dev->name);
-+
-+ if (unlikely((restart->dataflags & CPMAC_OWN) == 0)) {
-+ if (netif_msg_drv(priv))
-+ printk(KERN_ERR "%s: cpmac_poll is trying to restart rx from a descriptor that's not free: %p\n",
-+ priv->dev->name, restart);
-+ goto fatal_error;
-+ }
-+
-+ cpmac_write(priv->regs, CPMAC_RX_PTR(0), restart->mapping);
-+ }
-+
- priv->rx_head = desc;
- spin_unlock(&priv->rx_lock);
- if (unlikely(netif_msg_rx_status(priv)))
- printk(KERN_DEBUG "%s: poll processed %d packets\n",
- priv->dev->name, received);
-- if (desc->dataflags & CPMAC_OWN) {
-+ if (processed == 0) {
-+ /* we ran out of packets to read, revert to interrupt-driven mode */
- netif_rx_complete(priv->dev, napi);
-- cpmac_write(priv->regs, CPMAC_RX_PTR(0), (u32)desc->mapping);
- cpmac_write(priv->regs, CPMAC_RX_INT_ENABLE, 1);
- return 0;
- }
-
- return 1;
-+
-+fatal_error:
-+ /* Something went horribly wrong. Reset hardware to try to recover rather than wedging. */
-+
-+ if (netif_msg_drv(priv)) {
-+ printk(KERN_ERR "%s: cpmac_poll is confused. Resetting hardware\n", priv->dev->name);
-+ cpmac_dump_all_desc(priv->dev);
-+ printk(KERN_DEBUG "%s: RX_PTR(0)=0x%08x RX_ACK(0)=0x%08x\n",
-+ priv->dev->name,
-+ cpmac_read(priv->regs, CPMAC_RX_PTR(0)),
-+ cpmac_read(priv->regs, CPMAC_RX_ACK(0)));
-+ }
-+
-+ spin_unlock(&priv->rx_lock);
-+ netif_rx_complete(priv->dev, napi);
-+ netif_stop_queue(priv->dev);
-+ napi_disable(&priv->napi);
-+
-+ atomic_inc(&priv->reset_pending);
-+ cpmac_hw_stop(priv->dev);
-+ if (!schedule_work(&priv->reset_work))
-+ atomic_dec(&priv->reset_pending);
-+ return 0;
-+
- }
-
- static int cpmac_start_xmit(struct sk_buff *skb, struct net_device *dev)
-@@ -625,8 +717,10 @@ static void cpmac_clear_rx(struct net_de
- desc->dataflags = CPMAC_OWN;
- dev->stats.rx_dropped++;
- }
-+ desc->hw_next = desc->next->mapping;
- desc = desc->next;
- }
-+ priv->rx_head->prev->hw_next = 0;
- }
-
- static void cpmac_clear_tx(struct net_device *dev)
-@@ -928,9 +1022,12 @@ static int cpmac_open(struct net_device
- desc->buflen = CPMAC_SKB_SIZE;
- desc->dataflags = CPMAC_OWN;
- desc->next = &priv->rx_head[(i + 1) % priv->ring_size];
-+ desc->next->prev = desc;
- desc->hw_next = (u32)desc->next->mapping;
- }
-
-+ priv->rx_head->prev->hw_next = (u32)0;
-+
- if ((res = request_irq(dev->irq, cpmac_irq, IRQF_SHARED,
- dev->name, dev))) {
- if (netif_msg_drv(priv))
+++ /dev/null
-Index: linux-2.6.24.7/drivers/net/cpmac.c
-===================================================================
---- linux-2.6.24.7.orig/drivers/net/cpmac.c
-+++ linux-2.6.24.7/drivers/net/cpmac.c
-@@ -1178,9 +1178,7 @@ static int __devinit cpmac_probe(struct
- priv->msg_enable = netif_msg_init(debug_level, 0xff);
- memcpy(dev->dev_addr, pdata->dev_addr, sizeof(dev->dev_addr));
-
-- snprintf(priv->phy_name, BUS_ID_SIZE, PHY_ID_FMT, mdio_bus_id, phy_id);
--
-- priv->phy = phy_connect(dev, priv->phy_name, &cpmac_adjust_link, 0,
-+ priv->phy = phy_connect(dev, cpmac_mii.phy_map[phy_id]->dev.bus_id, &cpmac_adjust_link, 0,
- PHY_INTERFACE_MODE_MII);
- if (IS_ERR(priv->phy)) {
- if (netif_msg_drv(priv))
+++ /dev/null
-Index: linux-2.6.24.7/drivers/serial/8250.c
-===================================================================
---- linux-2.6.24.7.orig/drivers/serial/8250.c
-+++ linux-2.6.24.7/drivers/serial/8250.c
-@@ -267,6 +267,13 @@ static const struct serial8250_config ua
- .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10,
- .flags = UART_CAP_FIFO,
- },
-+ [PORT_AR7] = {
-+ .name = "TI-AR7",
-+ .fifo_size = 16,
-+ .tx_loadsz = 16,
-+ .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_00,
-+ .flags = UART_CAP_FIFO | UART_CAP_AFE,
-+ },
- };
-
- #if defined (CONFIG_SERIAL_8250_AU1X00)
-@@ -2453,7 +2460,11 @@ static void serial8250_console_putchar(s
- {
- struct uart_8250_port *up = (struct uart_8250_port *)port;
-
-+#ifdef CONFIG_AR7
-+ wait_for_xmitr(up, BOTH_EMPTY);
-+#else
- wait_for_xmitr(up, UART_LSR_THRE);
-+#endif
- serial_out(up, UART_TX, ch);
- }
-
-Index: linux-2.6.24.7/include/linux/serial_core.h
-===================================================================
---- linux-2.6.24.7.orig/include/linux/serial_core.h
-+++ linux-2.6.24.7/include/linux/serial_core.h
-@@ -40,7 +40,8 @@
- #define PORT_NS16550A 14
- #define PORT_XSCALE 15
- #define PORT_RM9000 16 /* PMC-Sierra RM9xxx internal UART */
--#define PORT_MAX_8250 16 /* max port ID */
-+#define PORT_AR7 17
-+#define PORT_MAX_8250 17 /* max port ID */
-
- /*
- * ARM specific type numbers. These are not currently guaranteed
+++ /dev/null
-Index: linux-2.6.24.7/drivers/net/cpmac.c
-===================================================================
---- linux-2.6.24.7.orig/drivers/net/cpmac.c
-+++ linux-2.6.24.7/drivers/net/cpmac.c
-@@ -936,7 +936,8 @@ static void cpmac_adjust_link(struct net
- int new_state = 0;
-
- spin_lock(&priv->lock);
-- if (priv->phy->link) {
-+ if (1 /* priv->phy->link */ ) {
-+ netif_carrier_on(dev);
- netif_start_queue(dev);
- if (priv->phy->duplex != priv->oldduplex) {
- new_state = 1;
-@@ -948,11 +949,11 @@ static void cpmac_adjust_link(struct net
- priv->oldspeed = priv->phy->speed;
- }
-
-- if (!priv->oldlink) {
-+ /*if (!priv->oldlink) {
- new_state = 1;
-- priv->oldlink = 1;
-+ priv->oldlink = 1;*/
- netif_schedule(dev);
-- }
-+ /*}*/
- } else if (priv->oldlink) {
- netif_stop_queue(dev);
- new_state = 1;
+++ /dev/null
---- a/arch/mips/Kconfig
-+++ b/arch/mips/Kconfig
-@@ -18,6 +18,24 @@
- prompt "System type"
- default SGI_IP22
-
-+config AR7
-+ bool "Texas Instruments AR7"
-+ select BOOT_ELF32
-+ select DMA_NONCOHERENT
-+ select CEVT_R4K
-+ select CSRC_R4K
-+ select IRQ_CPU
-+ select NO_EXCEPT_FILL
-+ select SWAP_IO_SPACE
-+ select SYS_HAS_CPU_MIPS32_R1
-+ select SYS_HAS_EARLY_PRINTK
-+ select SYS_SUPPORTS_32BIT_KERNEL
-+ select SYS_SUPPORTS_KGDB
-+ select SYS_SUPPORTS_LITTLE_ENDIAN
-+ select SYS_SUPPORTS_BIG_ENDIAN
-+ select GENERIC_GPIO
-+ select GENERIC_HARDIRQS_NO__DO_IRQ
-+
- config MACH_ALCHEMY
- bool "Alchemy processor based machines"
-
---- a/arch/mips/kernel/traps.c
-+++ b/arch/mips/kernel/traps.c
-@@ -1112,9 +1112,22 @@
-
- exception_handlers[n] = handler;
- if (n == 0 && cpu_has_divec) {
-- *(u32 *)(ebase + 0x200) = 0x08000000 |
-- (0x03ffffff & (handler >> 2));
-- flush_icache_range(ebase + 0x200, ebase + 0x204);
-+ if ((handler ^ (ebase + 4)) & 0xfc000000) {
-+ /* lui k0, 0x0000 */
-+ *(u32 *)(ebase + 0x200) = 0x3c1a0000 | (handler >> 16);
-+ /* ori k0, 0x0000 */
-+ *(u32 *)(ebase + 0x204) =
-+ 0x375a0000 | (handler & 0xffff);
-+ /* jr k0 */
-+ *(u32 *)(ebase + 0x208) = 0x03400008;
-+ /* nop */
-+ *(u32 *)(ebase + 0x20C) = 0x00000000;
-+ flush_icache_range(ebase + 0x200, ebase + 0x210);
-+ } else {
-+ *(u32 *)(ebase + 0x200) =
-+ 0x08000000 | (0x03ffffff & (handler >> 2));
-+ flush_icache_range(ebase + 0x200, ebase + 0x204);
-+ }
- }
- return (void *)old_handler;
- }
---- a/arch/mips/Makefile
-+++ b/arch/mips/Makefile
-@@ -167,6 +167,13 @@
- #
-
- #
-+# Texas Instruments AR7
-+#
-+core-$(CONFIG_AR7) += arch/mips/ar7/
-+cflags-$(CONFIG_AR7) += -Iinclude/asm-mips/ar7
-+load-$(CONFIG_AR7) += 0xffffffff94100000
-+
-+#
- # Acer PICA 61, Mips Magnum 4000 and Olivetti M700.
- #
- core-$(CONFIG_MACH_JAZZ) += arch/mips/jazz/
---- a/include/asm-mips/page.h
-+++ b/include/asm-mips/page.h
-@@ -182,8 +182,10 @@
- #define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | VM_EXEC | \
- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
-
--#define UNCAC_ADDR(addr) ((addr) - PAGE_OFFSET + UNCAC_BASE)
--#define CAC_ADDR(addr) ((addr) - UNCAC_BASE + PAGE_OFFSET)
-+#define UNCAC_ADDR(addr) ((addr) - PAGE_OFFSET + UNCAC_BASE + \
-+ PHYS_OFFSET)
-+#define CAC_ADDR(addr) ((addr) - UNCAC_BASE + PAGE_OFFSET - \
-+ PHYS_OFFSET)
-
- #include <asm-generic/memory_model.h>
- #include <asm-generic/page.h>
+++ /dev/null
---- a/drivers/mtd/Kconfig
-+++ b/drivers/mtd/Kconfig
-@@ -168,6 +168,12 @@
- the partition map from the children of the flash node,
- as described in Documentation/powerpc/booting-without-of.txt.
-
-+config MTD_AR7_PARTS
-+ tristate "TI AR7 partitioning support"
-+ depends on MTD_PARTITIONS
-+ ---help---
-+ TI AR7 partitioning support
-+
- comment "User Modules And Translation Layers"
-
- config MTD_CHAR
---- a/drivers/mtd/Makefile
-+++ b/drivers/mtd/Makefile
-@@ -12,6 +12,7 @@
- obj-$(CONFIG_MTD_CMDLINE_PARTS) += cmdlinepart.o
- obj-$(CONFIG_MTD_AFS_PARTS) += afs.o
- obj-$(CONFIG_MTD_OF_PARTS) += ofpart.o
-+obj-$(CONFIG_MTD_AR7_PARTS) += ar7part.o
-
- # 'Users' - code which presents functionality to userspace.
- obj-$(CONFIG_MTD_CHAR) += mtdchar.o
---- a/drivers/mtd/maps/physmap.c
-+++ b/drivers/mtd/maps/physmap.c
-@@ -87,7 +87,8 @@
-
- static const char *rom_probe_types[] = { "cfi_probe", "jedec_probe", "map_rom", NULL };
- #ifdef CONFIG_MTD_PARTITIONS
--static const char *part_probe_types[] = { "cmdlinepart", "RedBoot", NULL };
-+static const char *part_probe_types[] = {"cmdlinepart", "RedBoot",
-+ "ar7part", NULL };
- #endif
-
- static int physmap_flash_probe(struct platform_device *dev)
+++ /dev/null
---- a/drivers/char/Kconfig
-+++ b/drivers/char/Kconfig
-@@ -913,6 +913,15 @@
- To compile this driver as a module, choose M here: the
- module will be called mwave.
-
-+config AR7_GPIO
-+ tristate "TI AR7 GPIO Support"
-+ depends on AR7
-+ help
-+ Give userspace access to the GPIO pins on the Texas Instruments AR7
-+ processors.
-+
-+ If compiled as a module, it will be called ar7_gpio.
-+
- config SCx200_GPIO
- tristate "NatSemi SCx200 GPIO Support"
- depends on SCx200
---- a/drivers/char/Makefile
-+++ b/drivers/char/Makefile
-@@ -90,6 +90,7 @@
- obj-$(CONFIG_PPDEV) += ppdev.o
- obj-$(CONFIG_NWBUTTON) += nwbutton.o
- obj-$(CONFIG_NWFLASH) += nwflash.o
-+obj-$(CONFIG_AR7_GPIO) += ar7_gpio.o
- obj-$(CONFIG_SCx200_GPIO) += scx200_gpio.o
- obj-$(CONFIG_PC8736x_GPIO) += pc8736x_gpio.o
- obj-$(CONFIG_NSC_GPIO) += nsc_gpio.o
+++ /dev/null
---- a/drivers/Kconfig
-+++ b/drivers/Kconfig
-@@ -97,4 +97,6 @@
- source "drivers/auxdisplay/Kconfig"
-
- source "drivers/uio/Kconfig"
-+
-+source "drivers/vlynq/Kconfig"
- endmenu
---- a/drivers/Makefile
-+++ b/drivers/Makefile
-@@ -91,5 +91,6 @@
- obj-$(CONFIG_HID) += hid/
- obj-$(CONFIG_PPC_PS3) += ps3/
- obj-$(CONFIG_OF) += of/
-+obj-$(CONFIG_VLYNQ) += vlynq/
- obj-$(CONFIG_SSB) += ssb/
- obj-$(CONFIG_VIRTIO) += virtio/
+++ /dev/null
---- a/drivers/net/cpmac.c
-+++ b/drivers/net/cpmac.c
-@@ -38,6 +38,7 @@
- #include <linux/platform_device.h>
- #include <linux/dma-mapping.h>
- #include <asm/gpio.h>
-+#include <asm/atomic.h>
-
- MODULE_AUTHOR("Eugene Konev <ejka@imfi.kspu.ru>");
- MODULE_DESCRIPTION("TI AR7 ethernet driver (CPMAC)");
-@@ -207,6 +208,7 @@
- struct work_struct reset_work;
- struct platform_device *pdev;
- struct napi_struct napi;
-+ atomic_t reset_pending;
- };
-
- static irqreturn_t cpmac_irq(int, void *);
-@@ -455,6 +457,9 @@
- struct cpmac_desc *desc;
- struct cpmac_priv *priv = netdev_priv(dev);
-
-+ if (unlikely(atomic_read(&priv->reset_pending)))
-+ return NETDEV_TX_BUSY;
-+
- if (unlikely(skb_padto(skb, ETH_ZLEN)))
- return NETDEV_TX_OK;
-
-@@ -634,14 +639,14 @@
- priv->desc_ring[i].dataflags = 0;
- if (priv->desc_ring[i].skb) {
- dev_kfree_skb_any(priv->desc_ring[i].skb);
-- if (netif_subqueue_stopped(dev, i))
-- netif_wake_subqueue(dev, i);
-+ priv->desc_ring[i].skb = NULL;
- }
- }
- }
-
- static void cpmac_hw_error(struct work_struct *work)
- {
-+ int i;
- struct cpmac_priv *priv =
- container_of(work, struct cpmac_priv, reset_work);
-
-@@ -650,8 +655,47 @@
- spin_unlock(&priv->rx_lock);
- cpmac_clear_tx(priv->dev);
- cpmac_hw_start(priv->dev);
-- napi_enable(&priv->napi);
-- netif_start_queue(priv->dev);
-+ barrier();
-+ atomic_dec(&priv->reset_pending);
-+
-+ for (i = 0; i < CPMAC_QUEUES; i++) {
-+ netif_wake_subqueue(priv->dev, i);
-+ }
-+ netif_wake_queue(priv->dev);
-+ cpmac_write(priv->regs, CPMAC_MAC_INT_ENABLE, 3);
-+}
-+
-+static void cpmac_check_status(struct net_device *dev)
-+{
-+ struct cpmac_priv *priv = netdev_priv(dev);
-+
-+ u32 macstatus = cpmac_read(priv->regs, CPMAC_MAC_STATUS);
-+ int rx_channel = (macstatus >> 8) & 7;
-+ int rx_code = (macstatus >> 12) & 15;
-+ int tx_channel = (macstatus >> 16) & 7;
-+ int tx_code = (macstatus >> 20) & 15;
-+
-+ if (rx_code || tx_code) {
-+ if (netif_msg_drv(priv) && net_ratelimit()) {
-+ /* Can't find any documentation on what these error codes actually are.
-+ * So just log them and hope..
-+ */
-+ if (rx_code)
-+ printk(KERN_WARNING "%s: host error %d on rx channel %d (macstatus %08x), resetting\n",
-+ dev->name, rx_code, rx_channel, macstatus);
-+ if (tx_code)
-+ printk(KERN_WARNING "%s: host error %d on tx channel %d (macstatus %08x), resetting\n",
-+ dev->name, tx_code, tx_channel, macstatus);
-+ }
-+
-+ netif_stop_queue(dev);
-+ cpmac_hw_stop(dev);
-+ if (schedule_work(&priv->reset_work))
-+ atomic_inc(&priv->reset_pending);
-+ if (unlikely(netif_msg_hw(priv)))
-+ cpmac_dump_regs(dev);
-+ }
-+ cpmac_write(priv->regs, CPMAC_MAC_INT_CLEAR, 0xff);
- }
-
- static irqreturn_t cpmac_irq(int irq, void *dev_id)
-@@ -682,49 +726,33 @@
-
- cpmac_write(priv->regs, CPMAC_MAC_EOI_VECTOR, 0);
-
-- if (unlikely(status & (MAC_INT_HOST | MAC_INT_STATUS))) {
-- if (netif_msg_drv(priv) && net_ratelimit())
-- printk(KERN_ERR "%s: hw error, resetting...\n",
-- dev->name);
-- netif_stop_queue(dev);
-- napi_disable(&priv->napi);
-- cpmac_hw_stop(dev);
-- schedule_work(&priv->reset_work);
-- if (unlikely(netif_msg_hw(priv)))
-- cpmac_dump_regs(dev);
-- }
-+ if (unlikely(status & (MAC_INT_HOST | MAC_INT_STATUS)))
-+ cpmac_check_status(dev);
-
- return IRQ_HANDLED;
- }
-
- static void cpmac_tx_timeout(struct net_device *dev)
- {
-- struct cpmac_priv *priv = netdev_priv(dev);
- int i;
-+ struct cpmac_priv *priv = netdev_priv(dev);
-
- spin_lock(&priv->lock);
- dev->stats.tx_errors++;
- spin_unlock(&priv->lock);
- if (netif_msg_tx_err(priv) && net_ratelimit())
- printk(KERN_WARNING "%s: transmit timeout\n", dev->name);
-- /*
-- * FIXME: waking up random queue is not the best thing to
-- * do... on the other hand why we got here at all?
-- */
--#ifdef CONFIG_NETDEVICES_MULTIQUEUE
-- for (i = 0; i < CPMAC_QUEUES; i++)
-- if (priv->desc_ring[i].skb) {
-- priv->desc_ring[i].dataflags = 0;
-- dev_kfree_skb_any(priv->desc_ring[i].skb);
-- netif_wake_subqueue(dev, i);
-- break;
-- }
--#else
-- priv->desc_ring[0].dataflags = 0;
-- if (priv->desc_ring[0].skb)
-- dev_kfree_skb_any(priv->desc_ring[0].skb);
-- netif_wake_queue(dev);
--#endif
-+
-+ atomic_inc(&priv->reset_pending);
-+ barrier();
-+ cpmac_clear_tx(dev);
-+ barrier();
-+ atomic_dec(&priv->reset_pending);
-+
-+ netif_wake_queue(priv->dev);
-+ for (i = 0; i < CPMAC_QUEUES; i++) {
-+ netif_wake_subqueue(dev, i);
-+ }
- }
-
- static int cpmac_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
-@@ -911,6 +939,7 @@
- goto fail_irq;
- }
-
-+ atomic_set(&priv->reset_pending, 0);
- INIT_WORK(&priv->reset_work, cpmac_hw_error);
- cpmac_hw_start(dev);
-
+++ /dev/null
---- a/drivers/net/Kconfig
-+++ b/drivers/net/Kconfig
-@@ -1874,7 +1874,7 @@
-
- config CPMAC
- tristate "TI AR7 CPMAC Ethernet support (EXPERIMENTAL)"
-- depends on NET_ETHERNET && EXPERIMENTAL && AR7 && BROKEN
-+ depends on NET_ETHERNET && EXPERIMENTAL && AR7
- select PHYLIB
- help
- TI AR7 CPMAC Ethernet support
+++ /dev/null
-From 0daaa095cefd9d7091a7ccce2ff89f1ff4feae7a Mon Sep 17 00:00:00 2001
-From: Anton Vorontsov <avorontsov@ru.mvista.com>
-Date: Wed, 5 Mar 2008 14:52:26 +0300
-Subject: [PATCH] AR7/cpmac: convert to new fixed phy infrastructure, now for real
-
-This patch converts platform code to register fixed phys early.
-cpmac driver modified to blindly accept fixed phy id (that is equal
-to platform device id).
-
-Signed-off-by: Anton Vorontsov <avorontsov@ru.mvista.com>
----
- arch/mips/ar7/platform.c | 17 +++++++++++++++++
- drivers/net/cpmac.c | 19 +++----------------
- 2 files changed, 20 insertions(+), 16 deletions(-)
-
---- a/arch/mips/ar7/platform.c
-+++ b/arch/mips/ar7/platform.c
-@@ -33,6 +33,8 @@
- #include <linux/vlynq.h>
- #include <linux/leds.h>
- #include <linux/string.h>
-+#include <linux/phy.h>
-+#include <linux/phy_fixed.h>
-
- #include <asm/addrspace.h>
- #include <asm/ar7/ar7.h>
-@@ -205,6 +207,13 @@
- .width = 2,
- };
-
-+/* lets assume this is suitable for both high and low cpmacs links */
-+static struct fixed_phy_status fixed_phy_status __initdata = {
-+ .link = 1,
-+ .speed = 100,
-+ .duplex = 1,
-+};
-+
- static struct plat_cpmac_data cpmac_low_data = {
- .reset_bit = 17,
- .power_bit = 20,
-@@ -506,6 +515,10 @@
- }
-
- if (ar7_has_high_cpmac()) {
-+ res = fixed_phy_add(PHY_POLL, cpmac_high.id, &fixed_phy_status);
-+ if (res && res != -ENODEV)
-+ return res;
-+
- cpmac_get_mac(1, cpmac_high_data.dev_addr);
- res = platform_device_register(&cpmac_high);
- if (res)
-@@ -514,6 +527,10 @@
- cpmac_low_data.phy_mask = 0xffffffff;
- }
-
-+ res = fixed_phy_add(PHY_POLL, cpmac_low.id, &fixed_phy_status);
-+ if (res && res != -ENODEV)
-+ return res;
-+
- cpmac_get_mac(0, cpmac_low_data.dev_addr);
- res = platform_device_register(&cpmac_low);
- if (res)
---- a/drivers/net/cpmac.c
-+++ b/drivers/net/cpmac.c
-@@ -1035,23 +1035,10 @@
-
- if (phy_id == PHY_MAX_ADDR) {
- if (external_switch || dumb_switch) {
-- struct fixed_phy_status status = {};
--
-- mdio_bus_id = 0;
--
-- /*
-- * FIXME: this should be in the platform code!
-- * Since there is not platform code at all (that is,
-- * no mainline users of that driver), place it here
-- * for now.
-- */
-- phy_id = 0;
-- status.link = 1;
-- status.duplex = 1;
-- status.speed = 100;
-- fixed_phy_add(PHY_POLL, phy_id, &status);
-+ mdio_bus_id = 0; /* fixed phys bus */
-+ phy_id = pdev->id;
- } else {
-- printk(KERN_ERR "cpmac: no PHY present\n");
-+ dev_err(&pdev->dev, "no PHY present\n");
- return -ENODEV;
- }
- }
+++ /dev/null
---- a/drivers/net/cpmac.c
-+++ b/drivers/net/cpmac.c
-@@ -187,6 +187,7 @@
- #define CPMAC_EOQ 0x1000
- struct sk_buff *skb;
- struct cpmac_desc *next;
-+ struct cpmac_desc *prev;
- dma_addr_t mapping;
- dma_addr_t data_mapping;
- };
-@@ -242,6 +243,16 @@
- printk("\n");
- }
-
-+static void cpmac_dump_all_desc(struct net_device *dev)
-+{
-+ struct cpmac_priv *priv = netdev_priv(dev);
-+ struct cpmac_desc *dump = priv->rx_head;
-+ do {
-+ cpmac_dump_desc(dev, dump);
-+ dump = dump->next;
-+ } while (dump != priv->rx_head);
-+}
-+
- static void cpmac_dump_skb(struct net_device *dev, struct sk_buff *skb)
- {
- int i;
-@@ -413,21 +424,40 @@
- static int cpmac_poll(struct napi_struct *napi, int budget)
- {
- struct sk_buff *skb;
-- struct cpmac_desc *desc;
-- int received = 0;
-+ struct cpmac_desc *desc, *restart;
- struct cpmac_priv *priv = container_of(napi, struct cpmac_priv, napi);
-+ int received = 0, processed = 0;
-
- spin_lock(&priv->rx_lock);
- if (unlikely(!priv->rx_head)) {
- if (netif_msg_rx_err(priv) && net_ratelimit())
- printk(KERN_WARNING "%s: rx: polling, but no queue\n",
- priv->dev->name);
-+ spin_unlock(&priv->rx_lock);
- netif_rx_complete(priv->dev, napi);
- return 0;
- }
-
- desc = priv->rx_head;
-+ restart = NULL;
- while (((desc->dataflags & CPMAC_OWN) == 0) && (received < budget)) {
-+ processed++;
-+
-+ if ((desc->dataflags & CPMAC_EOQ) != 0) {
-+ /* The last update to eoq->hw_next didn't happen soon enough, and the
-+ * receiver stopped here. Remember this descriptor so we can restart
-+ * the receiver after freeing some space.
-+ */
-+ if (unlikely(restart)) {
-+ if (netif_msg_rx_err(priv))
-+ printk(KERN_ERR "%s: poll found a duplicate EOQ: %p and %p\n",
-+ priv->dev->name, restart, desc);
-+ goto fatal_error;
-+ }
-+
-+ restart = desc->next;
-+ }
-+
- skb = cpmac_rx_one(priv, desc);
- if (likely(skb)) {
- netif_receive_skb(skb);
-@@ -436,19 +466,81 @@
- desc = desc->next;
- }
-
-+ if (desc != priv->rx_head) {
-+ /* We freed some buffers, but not the whole ring, add what we did free to the rx list */
-+ desc->prev->hw_next = (u32)0;
-+ priv->rx_head->prev->hw_next = priv->rx_head->mapping;
-+ }
-+
-+ /* Optimization: If we did not actually process an EOQ (perhaps because of
-+ * quota limits), check to see if the tail of the queue has EOQ set. We
-+ * should immediately restart in that case so that the receiver can restart
-+ * and run in parallel with more packet processing. This lets us handle slightly
-+ * larger bursts before running out of ring space (assuming dev->weight < ring_size)
-+ */
-+ if (!restart &&
-+ (priv->rx_head->prev->dataflags & (CPMAC_OWN|CPMAC_EOQ)) == CPMAC_EOQ &&
-+ (priv->rx_head->dataflags & CPMAC_OWN) != 0) {
-+ /* reset EOQ so the poll loop (above) doesn't try to restart this when it
-+ * eventually gets to this descriptor.
-+ */
-+ priv->rx_head->prev->dataflags &= ~CPMAC_EOQ;
-+ restart = priv->rx_head;
-+ }
-+
-+ if (restart) {
-+ priv->dev->stats.rx_errors++;
-+ priv->dev->stats.rx_fifo_errors++;
-+ if (netif_msg_rx_err(priv) && net_ratelimit())
-+ printk(KERN_WARNING "%s: rx dma ring overrun\n", priv->dev->name);
-+
-+ if (unlikely((restart->dataflags & CPMAC_OWN) == 0)) {
-+ if (netif_msg_drv(priv))
-+ printk(KERN_ERR "%s: cpmac_poll is trying to restart rx from a descriptor that's not free: %p\n",
-+ priv->dev->name, restart);
-+ goto fatal_error;
-+ }
-+
-+ cpmac_write(priv->regs, CPMAC_RX_PTR(0), restart->mapping);
-+ }
-+
- priv->rx_head = desc;
- spin_unlock(&priv->rx_lock);
- if (unlikely(netif_msg_rx_status(priv)))
- printk(KERN_DEBUG "%s: poll processed %d packets\n",
- priv->dev->name, received);
-- if (desc->dataflags & CPMAC_OWN) {
-+ if (processed == 0) {
-+ /* we ran out of packets to read, revert to interrupt-driven mode */
- netif_rx_complete(priv->dev, napi);
-- cpmac_write(priv->regs, CPMAC_RX_PTR(0), (u32)desc->mapping);
- cpmac_write(priv->regs, CPMAC_RX_INT_ENABLE, 1);
- return 0;
- }
-
- return 1;
-+
-+fatal_error:
-+ /* Something went horribly wrong. Reset hardware to try to recover rather than wedging. */
-+
-+ if (netif_msg_drv(priv)) {
-+ printk(KERN_ERR "%s: cpmac_poll is confused. Resetting hardware\n", priv->dev->name);
-+ cpmac_dump_all_desc(priv->dev);
-+ printk(KERN_DEBUG "%s: RX_PTR(0)=0x%08x RX_ACK(0)=0x%08x\n",
-+ priv->dev->name,
-+ cpmac_read(priv->regs, CPMAC_RX_PTR(0)),
-+ cpmac_read(priv->regs, CPMAC_RX_ACK(0)));
-+ }
-+
-+ spin_unlock(&priv->rx_lock);
-+ netif_rx_complete(priv->dev, napi);
-+ netif_stop_queue(priv->dev);
-+ napi_disable(&priv->napi);
-+
-+ atomic_inc(&priv->reset_pending);
-+ cpmac_hw_stop(priv->dev);
-+ if (!schedule_work(&priv->reset_work))
-+ atomic_dec(&priv->reset_pending);
-+ return 0;
-+
- }
-
- static int cpmac_start_xmit(struct sk_buff *skb, struct net_device *dev)
-@@ -625,8 +717,10 @@
- desc->dataflags = CPMAC_OWN;
- dev->stats.rx_dropped++;
- }
-+ desc->hw_next = desc->next->mapping;
- desc = desc->next;
- }
-+ priv->rx_head->prev->hw_next = 0;
- }
-
- static void cpmac_clear_tx(struct net_device *dev)
-@@ -928,9 +1022,12 @@
- desc->buflen = CPMAC_SKB_SIZE;
- desc->dataflags = CPMAC_OWN;
- desc->next = &priv->rx_head[(i + 1) % priv->ring_size];
-+ desc->next->prev = desc;
- desc->hw_next = (u32)desc->next->mapping;
- }
-
-+ priv->rx_head->prev->hw_next = (u32)0;
-+
- if ((res = request_irq(dev->irq, cpmac_irq, IRQF_SHARED,
- dev->name, dev))) {
- if (netif_msg_drv(priv))
+++ /dev/null
---- a/drivers/net/cpmac.c
-+++ b/drivers/net/cpmac.c
-@@ -1178,9 +1178,7 @@
- priv->msg_enable = netif_msg_init(debug_level, 0xff);
- memcpy(dev->dev_addr, pdata->dev_addr, sizeof(dev->dev_addr));
-
-- snprintf(priv->phy_name, BUS_ID_SIZE, PHY_ID_FMT, mdio_bus_id, phy_id);
--
-- priv->phy = phy_connect(dev, priv->phy_name, &cpmac_adjust_link, 0,
-+ priv->phy = phy_connect(dev, cpmac_mii.phy_map[phy_id]->dev.bus_id, &cpmac_adjust_link, 0,
- PHY_INTERFACE_MODE_MII);
- if (IS_ERR(priv->phy)) {
- if (netif_msg_drv(priv))
+++ /dev/null
---- a/drivers/mtd/ar7part.c
-+++ b/drivers/mtd/ar7part.c
-@@ -34,6 +34,10 @@
- #define LOADER_MAGIC1 le32_to_cpu(0xfeedfa42)
- #define LOADER_MAGIC2 le32_to_cpu(0xfeed1281)
-
-+#ifndef SQUASHFS_MAGIC
-+#define SQUASHFS_MAGIC 0x73717368
-+#endif
-+
- struct ar7_bin_rec {
- unsigned int checksum;
- unsigned int length;
-@@ -47,7 +51,8 @@
- unsigned long origin)
- {
- struct ar7_bin_rec header;
-- unsigned int offset, len;
-+ unsigned int offset;
-+ size_t len;
- unsigned int pre_size = master->erasesize, post_size = 0;
- unsigned int root_offset = ROOT_OFFSET;
-
-@@ -66,7 +71,7 @@
- do { /* Try 10 blocks starting from master->erasesize */
- offset = pre_size;
- master->read(master, offset,
-- sizeof(header), &len, (u8 *)&header);
-+ sizeof(header), &len, (uint8_t *)&header);
- if (!strncmp((char *)&header, "TIENV0.8", 8))
- ar7_parts[1].offset = pre_size;
- if (header.checksum == LOADER_MAGIC1)
-@@ -88,7 +93,7 @@
- while (header.length) {
- offset += sizeof(header) + header.length;
- master->read(master, offset, sizeof(header),
-- &len, (u8 *)&header);
-+ &len, (uint8_t *)&header);
- }
- root_offset = offset + sizeof(header) + 4;
- break;
-@@ -96,10 +101,10 @@
- while (header.length) {
- offset += sizeof(header) + header.length;
- master->read(master, offset, sizeof(header),
-- &len, (u8 *)&header);
-+ &len, (uint8_t *)&header);
- }
- root_offset = offset + sizeof(header) + 4 + 0xff;
-- root_offset &= ~(u32)0xff;
-+ root_offset &= ~(uint32_t)0xff;
- break;
- default:
- printk(KERN_WARNING "Unknown magic: %08x\n", header.checksum);
+++ /dev/null
---- a/drivers/serial/8250.c
-+++ b/drivers/serial/8250.c
-@@ -267,6 +267,13 @@
- .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10,
- .flags = UART_CAP_FIFO,
- },
-+ [PORT_AR7] = {
-+ .name = "TI-AR7",
-+ .fifo_size = 16,
-+ .tx_loadsz = 16,
-+ .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_00,
-+ .flags = UART_CAP_FIFO | UART_CAP_AFE,
-+ },
- };
-
- #if defined (CONFIG_SERIAL_8250_AU1X00)
-@@ -2457,7 +2464,11 @@
- {
- struct uart_8250_port *up = (struct uart_8250_port *)port;
-
-+#ifdef CONFIG_AR7
-+ wait_for_xmitr(up, BOTH_EMPTY);
-+#else
- wait_for_xmitr(up, UART_LSR_THRE);
-+#endif
- serial_out(up, UART_TX, ch);
- }
-
---- a/include/linux/serial_core.h
-+++ b/include/linux/serial_core.h
-@@ -40,7 +40,8 @@
- #define PORT_NS16550A 14
- #define PORT_XSCALE 15
- #define PORT_RM9000 16 /* PMC-Sierra RM9xxx internal UART */
--#define PORT_MAX_8250 16 /* max port ID */
-+#define PORT_AR7 17
-+#define PORT_MAX_8250 17 /* max port ID */
-
- /*
- * ARM specific type numbers. These are not currently guaranteed
+++ /dev/null
---- a/drivers/net/cpmac.c
-+++ b/drivers/net/cpmac.c
-@@ -936,7 +936,8 @@
- int new_state = 0;
-
- spin_lock(&priv->lock);
-- if (priv->phy->link) {
-+ if (1 /* priv->phy->link */) {
-+ netif_carrier_on(dev);
- netif_start_queue(dev);
- if (priv->phy->duplex != priv->oldduplex) {
- new_state = 1;
-@@ -948,11 +949,11 @@
- priv->oldspeed = priv->phy->speed;
- }
-
-- if (!priv->oldlink) {
-+ /*if (!priv->oldlink) {
- new_state = 1;
-- priv->oldlink = 1;
-+ priv->oldlink = 1;*/
- netif_schedule(dev);
-- }
-+ /*}*/
- } else if (priv->oldlink) {
- netif_stop_queue(dev);
- new_state = 1;
+++ /dev/null
-CONFIG_32BIT=y
-# CONFIG_64BIT is not set
-CONFIG_64BIT_PHYS_ADDR=y
-# CONFIG_8139TOO is not set
-# CONFIG_ARCH_HAS_ILOG2_U32 is not set
-# CONFIG_ARCH_HAS_ILOG2_U64 is not set
-# CONFIG_ARCH_SUPPORTS_MSI is not set
-# CONFIG_ATM is not set
-CONFIG_BASE_SMALL=0
-CONFIG_BITREVERSE=y
-# CONFIG_BROADCOM_PHY is not set
-CONFIG_CHR_DEV_SG=m
-CONFIG_CMDLINE="root=/dev/mtdblock0 rootfstype=squashfs,jffs2 init=/etc/preinit"
-# CONFIG_CPU_BIG_ENDIAN is not set
-CONFIG_CPU_HAS_LLSC=y
-CONFIG_CPU_HAS_PREFETCH=y
-CONFIG_CPU_HAS_SYNC=y
-CONFIG_CPU_LITTLE_ENDIAN=y
-# CONFIG_CPU_LOONGSON2 is not set
-CONFIG_CPU_MIPS32=y
-CONFIG_CPU_MIPS32_R1=y
-# CONFIG_CPU_MIPS32_R2 is not set
-# CONFIG_CPU_MIPS64_R1 is not set
-# CONFIG_CPU_MIPS64_R2 is not set
-CONFIG_CPU_MIPSR1=y
-# CONFIG_CPU_NEVADA is not set
-# CONFIG_CPU_R10000 is not set
-# CONFIG_CPU_R3000 is not set
-# CONFIG_CPU_R4300 is not set
-# CONFIG_CPU_R4X00 is not set
-# CONFIG_CPU_R5000 is not set
-# CONFIG_CPU_R5432 is not set
-# CONFIG_CPU_R6000 is not set
-# CONFIG_CPU_R8000 is not set
-# CONFIG_CPU_RM7000 is not set
-# CONFIG_CPU_RM9000 is not set
-# CONFIG_CPU_SB1 is not set
-CONFIG_CPU_SUPPORTS_32BIT_KERNEL=y
-CONFIG_CPU_SUPPORTS_HIGHMEM=y
-# CONFIG_CPU_TX39XX is not set
-# CONFIG_CPU_TX49XX is not set
-# CONFIG_CPU_VR41XX is not set
-CONFIG_CRAMFS=m
-CONFIG_CRC16=y
-CONFIG_DEVPORT=y
-# CONFIG_DM9000 is not set
-CONFIG_DMA_NEED_PCI_MAP_STATE=y
-CONFIG_DMA_NONCOHERENT=y
-CONFIG_DUMMY=m
-CONFIG_ELF_CORE=y
-# CONFIG_FIXED_PHY is not set
-CONFIG_FS_POSIX_ACL=y
-CONFIG_GENERIC_FIND_NEXT_BIT=y
-CONFIG_GENERIC_GPIO=y
-# CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ is not set
-# CONFIG_HAMRADIO is not set
-CONFIG_HAS_DMA=y
-CONFIG_HAS_IOMEM=y
-CONFIG_HAS_IOPORT=y
-CONFIG_HID=m
-CONFIG_HID_SUPPORT=y
-CONFIG_HW_HAS_PCI=y
-CONFIG_HW_RANDOM=y
-CONFIG_HZ=250
-# CONFIG_HZ_100 is not set
-CONFIG_HZ_250=y
-CONFIG_I2C=m
-CONFIG_I2C_ALGOBIT=m
-CONFIG_I2C_ALGOPCA=m
-CONFIG_I2C_ALGOPCF=m
-CONFIG_I2C_BOARDINFO=y
-CONFIG_I2C_CHARDEV=m
-# CONFIG_IDE is not set
-CONFIG_INITRAMFS_SOURCE=""
-CONFIG_INPUT=y
-CONFIG_INPUT_KEYBOARD=y
-# CONFIG_KEYBOARD_ATKBD is not set
-CONFIG_KEYBOARD_GPIO=y
-# CONFIG_KEYBOARD_LKKBD is not set
-# CONFIG_KEYBOARD_NEWTON is not set
-# CONFIG_KEYBOARD_STOWAWAY is not set
-# CONFIG_KEYBOARD_SUNKBD is not set
-# CONFIG_KEYBOARD_XTKBD is not set
-# CONFIG_LEDS_ALIX is not set
-CONFIG_LEDS_GPIO=y
-# CONFIG_LEDS_TRIGGERS is not set
-# CONFIG_LEMOTE_FULONG is not set
-CONFIG_MACH_ALCHEMY=y
-# CONFIG_MACH_DECSTATION is not set
-# CONFIG_MACH_JAZZ is not set
-# CONFIG_MACH_VR41XX is not set
-CONFIG_MAGIC_SYSRQ=y
-CONFIG_MIPS=y
-# CONFIG_MIPS_ATLAS is not set
-CONFIG_MIPS_AU1X00_ENET=y
-# CONFIG_MIPS_BOSPORUS is not set
-# CONFIG_MIPS_COBALT is not set
-# CONFIG_MIPS_DB1000 is not set
-# CONFIG_MIPS_DB1100 is not set
-# CONFIG_MIPS_DB1200 is not set
-# CONFIG_MIPS_DB1500 is not set
-# CONFIG_MIPS_DB1550 is not set
-CONFIG_MIPS_L1_CACHE_SHIFT=5
-# CONFIG_MIPS_MALTA is not set
-# CONFIG_MIPS_MIRAGE is not set
-CONFIG_MIPS_MTX1=y
-CONFIG_MIPS_MT_DISABLED=y
-# CONFIG_MIPS_MT_SMP is not set
-# CONFIG_MIPS_MT_SMTC is not set
-# CONFIG_MIPS_PB1000 is not set
-# CONFIG_MIPS_PB1100 is not set
-# CONFIG_MIPS_PB1200 is not set
-# CONFIG_MIPS_PB1500 is not set
-# CONFIG_MIPS_PB1550 is not set
-# CONFIG_MIPS_SEAD is not set
-# CONFIG_MIPS_SIM is not set
-# CONFIG_MIPS_XXS1500 is not set
-CONFIG_MODULE_FORCE_UNLOAD=y
-CONFIG_MTD=y
-# CONFIG_MTD_ABSENT is not set
-# CONFIG_MTD_ALCHEMY is not set
-CONFIG_MTD_BLKDEVS=y
-CONFIG_MTD_BLOCK=y
-# CONFIG_MTD_BLOCK2MTD is not set
-CONFIG_MTD_CFI=y
-# CONFIG_MTD_CFI_ADV_OPTIONS is not set
-CONFIG_MTD_CFI_AMDSTD=y
-CONFIG_MTD_CFI_I1=y
-CONFIG_MTD_CFI_I2=y
-# CONFIG_MTD_CFI_I4 is not set
-# CONFIG_MTD_CFI_I8 is not set
-# CONFIG_MTD_CFI_INTELEXT is not set
-# CONFIG_MTD_CFI_STAA is not set
-CONFIG_MTD_CFI_UTIL=y
-CONFIG_MTD_CHAR=y
-# CONFIG_MTD_CMDLINE_PARTS is not set
-# CONFIG_MTD_COMPLEX_MAPPINGS is not set
-CONFIG_MTD_CONCAT=y
-# CONFIG_MTD_DEBUG is not set
-# CONFIG_MTD_DOC2000 is not set
-# CONFIG_MTD_DOC2001 is not set
-# CONFIG_MTD_DOC2001PLUS is not set
-CONFIG_MTD_GEN_PROBE=y
-# CONFIG_MTD_JEDECPROBE is not set
-CONFIG_MTD_MAP_BANK_WIDTH_1=y
-# CONFIG_MTD_MAP_BANK_WIDTH_16 is not set
-CONFIG_MTD_MAP_BANK_WIDTH_2=y
-# CONFIG_MTD_MAP_BANK_WIDTH_32 is not set
-CONFIG_MTD_MAP_BANK_WIDTH_4=y
-# CONFIG_MTD_MAP_BANK_WIDTH_8 is not set
-# CONFIG_MTD_MTDRAM is not set
-CONFIG_MTD_MTX1=y
-# CONFIG_MTD_ONENAND is not set
-CONFIG_MTD_PARTITIONS=y
-# CONFIG_MTD_PHRAM is not set
-# CONFIG_MTD_PHYSMAP is not set
-# CONFIG_MTD_PLATRAM is not set
-# CONFIG_MTD_PMC551 is not set
-# CONFIG_MTD_RAM is not set
-# CONFIG_MTD_REDBOOT_PARTS is not set
-# CONFIG_MTD_ROM is not set
-# CONFIG_MTD_SLRAM is not set
-# CONFIG_NATSEMI is not set
-# CONFIG_NE2K_PCI is not set
-# CONFIG_NET_SCH_ESFQ_NFCT is not set
-# CONFIG_NET_VENDOR_3COM is not set
-# CONFIG_NO_IOPORT is not set
-# CONFIG_PAGE_SIZE_16KB is not set
-CONFIG_PAGE_SIZE_4KB=y
-# CONFIG_PAGE_SIZE_64KB is not set
-# CONFIG_PAGE_SIZE_8KB is not set
-# CONFIG_PCIPCWATCHDOG is not set
-CONFIG_PHYLIB=y
-# CONFIG_PMC_MSP is not set
-# CONFIG_PMC_YOSEMITE is not set
-# CONFIG_PNX8550_JBS is not set
-# CONFIG_PNX8550_STB810 is not set
-# CONFIG_PPP_MPPE is not set
-# CONFIG_PREVENT_FIRMWARE_BUILD is not set
-# CONFIG_QSEMI_PHY is not set
-CONFIG_RESOURCES_64BIT=y
-# CONFIG_RTC is not set
-CONFIG_RWSEM_GENERIC_SPINLOCK=y
-CONFIG_SCHED_NO_NO_OMIT_FRAME_POINTER=y
-CONFIG_SCSI_CONSTANTS=y
-# CONFIG_SCSI_PROC_FS is not set
-CONFIG_SCSI_WAIT_SCAN=m
-CONFIG_SERIAL_8250_AU1X00=y
-# CONFIG_SERIAL_8250_EXTENDED is not set
-CONFIG_SERIAL_8250_NR_UARTS=4
-CONFIG_SERIAL_8250_PCI=m
-CONFIG_SERIAL_8250_RUNTIME_UARTS=4
-# CONFIG_SGI_IP22 is not set
-# CONFIG_SGI_IP27 is not set
-# CONFIG_SGI_IP32 is not set
-# CONFIG_SIBYTE_BIGSUR is not set
-# CONFIG_SIBYTE_CARMEL is not set
-# CONFIG_SIBYTE_CRHINE is not set
-# CONFIG_SIBYTE_CRHONE is not set
-# CONFIG_SIBYTE_LITTLESUR is not set
-# CONFIG_SIBYTE_PTSWARM is not set
-# CONFIG_SIBYTE_RHONE is not set
-# CONFIG_SIBYTE_SENTOSA is not set
-# CONFIG_SIBYTE_SWARM is not set
-# CONFIG_SMC91X is not set
-# CONFIG_SMSC_PHY is not set
-# CONFIG_SND_AU1X00 is not set
-CONFIG_SOC_AU1500=y
-CONFIG_SOC_AU1X00=y
-CONFIG_SOFT_WATCHDOG=m
-# CONFIG_SPARSEMEM_STATIC is not set
-# CONFIG_STANDALONE is not set
-CONFIG_SYSVIPC_SYSCTL=y
-CONFIG_SYS_HAS_CPU_MIPS32_R1=y
-CONFIG_SYS_SUPPORTS_32BIT_KERNEL=y
-CONFIG_SYS_SUPPORTS_APM_EMULATION=y
-CONFIG_SYS_SUPPORTS_ARBIT_HZ=y
-CONFIG_SYS_SUPPORTS_KGDB=y
-CONFIG_SYS_SUPPORTS_LITTLE_ENDIAN=y
-# CONFIG_TC35815 is not set
-# CONFIG_TMD_HERMES is not set
-# CONFIG_TOSHIBA_JMR3927 is not set
-# CONFIG_TOSHIBA_RBTX4927 is not set
-# CONFIG_TOSHIBA_RBTX4938 is not set
-CONFIG_TRAD_SIGNALS=y
-# CONFIG_USBPCWATCHDOG is not set
-CONFIG_USB_EHCI_HCD=m
-# CONFIG_USB_OHCI_BIG_ENDIAN_DESC is not set
-# CONFIG_USB_OHCI_BIG_ENDIAN_MMIO is not set
-CONFIG_USB_OHCI_HCD=m
-# CONFIG_USB_PWC is not set
-# CONFIG_USB_R8A66597_HCD is not set
-# CONFIG_USB_SERIAL_OTI6858 is not set
-CONFIG_USB_UHCI_HCD=m
-# CONFIG_USER_NS is not set
-CONFIG_V4L_USB_DRIVERS=y
-# CONFIG_VGASTATE is not set
-# CONFIG_VIA_RHINE is not set
-CONFIG_VIDEO_CAPTURE_DRIVERS=y
-# CONFIG_VIDEO_CPIA2 is not set
-CONFIG_VIDEO_V4L1=y
-CONFIG_WDT_MTX1=y
-CONFIG_ZONE_DMA_FLAG=0
+++ /dev/null
-CONFIG_32BIT=y
-# CONFIG_64BIT is not set
-CONFIG_64BIT_PHYS_ADDR=y
-# CONFIG_8139TOO is not set
-# CONFIG_ARCH_HAS_ILOG2_U32 is not set
-# CONFIG_ARCH_HAS_ILOG2_U64 is not set
-CONFIG_ARCH_POPULATES_NODE_MAP=y
-# CONFIG_ARCH_SUPPORTS_MSI is not set
-CONFIG_ARCH_SUPPORTS_OPROFILE=y
-# CONFIG_ATM is not set
-CONFIG_BASE_SMALL=0
-# CONFIG_BCM47XX is not set
-CONFIG_BITREVERSE=y
-# CONFIG_BROADCOM_PHY is not set
-# CONFIG_BT_HCIUART_LL is not set
-CONFIG_CEVT_R4K=y
-CONFIG_CHR_DEV_SG=m
-CONFIG_CMDLINE="root=/dev/mtdblock0 rootfstype=squashfs,jffs2 init=/etc/preinit"
-# CONFIG_CPU_BIG_ENDIAN is not set
-CONFIG_CPU_HAS_LLSC=y
-CONFIG_CPU_HAS_PREFETCH=y
-CONFIG_CPU_HAS_SYNC=y
-CONFIG_CPU_LITTLE_ENDIAN=y
-# CONFIG_CPU_LOONGSON2 is not set
-CONFIG_CPU_MIPS32=y
-CONFIG_CPU_MIPS32_R1=y
-# CONFIG_CPU_MIPS32_R2 is not set
-# CONFIG_CPU_MIPS64_R1 is not set
-# CONFIG_CPU_MIPS64_R2 is not set
-CONFIG_CPU_MIPSR1=y
-# CONFIG_CPU_NEVADA is not set
-# CONFIG_CPU_R10000 is not set
-# CONFIG_CPU_R3000 is not set
-# CONFIG_CPU_R4300 is not set
-# CONFIG_CPU_R4X00 is not set
-# CONFIG_CPU_R5000 is not set
-# CONFIG_CPU_R5432 is not set
-# CONFIG_CPU_R6000 is not set
-# CONFIG_CPU_R8000 is not set
-# CONFIG_CPU_RM7000 is not set
-# CONFIG_CPU_RM9000 is not set
-# CONFIG_CPU_SB1 is not set
-CONFIG_CPU_SUPPORTS_32BIT_KERNEL=y
-CONFIG_CPU_SUPPORTS_HIGHMEM=y
-# CONFIG_CPU_TX39XX is not set
-# CONFIG_CPU_TX49XX is not set
-# CONFIG_CPU_VR41XX is not set
-CONFIG_CRAMFS=m
-CONFIG_CRC16=y
-CONFIG_CSRC_R4K=y
-CONFIG_DEVPORT=y
-# CONFIG_DM9000 is not set
-CONFIG_DMA_NEED_PCI_MAP_STATE=y
-CONFIG_DMA_NONCOHERENT=y
-CONFIG_DUMMY=m
-CONFIG_ELF_CORE=y
-# CONFIG_FIXED_PHY is not set
-CONFIG_FS_POSIX_ACL=y
-CONFIG_GENERIC_CLOCKEVENTS=y
-CONFIG_GENERIC_CLOCKEVENTS_BUILD=y
-CONFIG_GENERIC_CMOS_UPDATE=y
-CONFIG_GENERIC_FIND_NEXT_BIT=y
-CONFIG_GENERIC_GPIO=y
-# CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ is not set
-# CONFIG_HAMRADIO is not set
-CONFIG_HAS_DMA=y
-CONFIG_HAS_IOMEM=y
-CONFIG_HAS_IOPORT=y
-CONFIG_HID=m
-# CONFIG_HIDRAW is not set
-CONFIG_HID_SUPPORT=y
-CONFIG_HW_HAS_PCI=y
-CONFIG_HW_RANDOM=y
-CONFIG_HZ=250
-# CONFIG_HZ_100 is not set
-CONFIG_HZ_250=y
-CONFIG_I2C=m
-CONFIG_I2C_ALGOBIT=m
-CONFIG_I2C_ALGOPCA=m
-CONFIG_I2C_ALGOPCF=m
-CONFIG_I2C_BOARDINFO=y
-CONFIG_I2C_CHARDEV=m
-# CONFIG_IBM_NEW_EMAC_EMAC4 is not set
-# CONFIG_IBM_NEW_EMAC_RGMII is not set
-# CONFIG_IBM_NEW_EMAC_TAH is not set
-# CONFIG_IBM_NEW_EMAC_ZMII is not set
-# CONFIG_IDE is not set
-CONFIG_INITRAMFS_SOURCE=""
-CONFIG_INPUT=y
-CONFIG_INPUT_KEYBOARD=y
-CONFIG_IRQ_CPU=y
-# CONFIG_KEYBOARD_ATKBD is not set
-CONFIG_KEYBOARD_GPIO=y
-# CONFIG_KEYBOARD_LKKBD is not set
-# CONFIG_KEYBOARD_NEWTON is not set
-# CONFIG_KEYBOARD_STOWAWAY is not set
-# CONFIG_KEYBOARD_SUNKBD is not set
-# CONFIG_KEYBOARD_XTKBD is not set
-# CONFIG_LEDS_ALIX is not set
-CONFIG_LEDS_GPIO=y
-# CONFIG_LEDS_TRIGGERS is not set
-# CONFIG_LEMOTE_FULONG is not set
-CONFIG_MACH_ALCHEMY=y
-# CONFIG_MACH_DECSTATION is not set
-# CONFIG_MACH_JAZZ is not set
-# CONFIG_MACH_VR41XX is not set
-CONFIG_MAGIC_SYSRQ=y
-# CONFIG_MDIO_BITBANG is not set
-CONFIG_MIPS=y
-# CONFIG_MIPS_ATLAS is not set
-CONFIG_MIPS_AU1X00_ENET=y
-# CONFIG_MIPS_BOSPORUS is not set
-# CONFIG_MIPS_COBALT is not set
-# CONFIG_MIPS_DB1000 is not set
-# CONFIG_MIPS_DB1100 is not set
-# CONFIG_MIPS_DB1200 is not set
-# CONFIG_MIPS_DB1500 is not set
-# CONFIG_MIPS_DB1550 is not set
-CONFIG_MIPS_L1_CACHE_SHIFT=5
-# CONFIG_MIPS_MALTA is not set
-# CONFIG_MIPS_MIRAGE is not set
-CONFIG_MIPS_MTX1=y
-CONFIG_MIPS_MT_DISABLED=y
-# CONFIG_MIPS_MT_SMP is not set
-# CONFIG_MIPS_MT_SMTC is not set
-# CONFIG_MIPS_PB1000 is not set
-# CONFIG_MIPS_PB1100 is not set
-# CONFIG_MIPS_PB1200 is not set
-# CONFIG_MIPS_PB1500 is not set
-# CONFIG_MIPS_PB1550 is not set
-# CONFIG_MIPS_SEAD is not set
-# CONFIG_MIPS_SIM is not set
-# CONFIG_MIPS_XXS1500 is not set
-CONFIG_MODULE_FORCE_UNLOAD=y
-CONFIG_MTD=y
-# CONFIG_MTD_ABSENT is not set
-# CONFIG_MTD_ALCHEMY is not set
-CONFIG_MTD_BLKDEVS=y
-CONFIG_MTD_BLOCK=y
-# CONFIG_MTD_BLOCK2MTD is not set
-CONFIG_MTD_CFI=y
-# CONFIG_MTD_CFI_ADV_OPTIONS is not set
-CONFIG_MTD_CFI_AMDSTD=y
-CONFIG_MTD_CFI_I1=y
-CONFIG_MTD_CFI_I2=y
-# CONFIG_MTD_CFI_I4 is not set
-# CONFIG_MTD_CFI_I8 is not set
-# CONFIG_MTD_CFI_INTELEXT is not set
-# CONFIG_MTD_CFI_STAA is not set
-CONFIG_MTD_CFI_UTIL=y
-CONFIG_MTD_CHAR=y
-# CONFIG_MTD_CMDLINE_PARTS is not set
-# CONFIG_MTD_COMPLEX_MAPPINGS is not set
-CONFIG_MTD_CONCAT=y
-# CONFIG_MTD_DEBUG is not set
-# CONFIG_MTD_DOC2000 is not set
-# CONFIG_MTD_DOC2001 is not set
-# CONFIG_MTD_DOC2001PLUS is not set
-CONFIG_MTD_GEN_PROBE=y
-# CONFIG_MTD_JEDECPROBE is not set
-CONFIG_MTD_MAP_BANK_WIDTH_1=y
-# CONFIG_MTD_MAP_BANK_WIDTH_16 is not set
-CONFIG_MTD_MAP_BANK_WIDTH_2=y
-# CONFIG_MTD_MAP_BANK_WIDTH_32 is not set
-CONFIG_MTD_MAP_BANK_WIDTH_4=y
-# CONFIG_MTD_MAP_BANK_WIDTH_8 is not set
-# CONFIG_MTD_MTDRAM is not set
-CONFIG_MTD_MTX1=y
-# CONFIG_MTD_ONENAND is not set
-CONFIG_MTD_PARTITIONS=y
-# CONFIG_MTD_PHRAM is not set
-# CONFIG_MTD_PHYSMAP is not set
-# CONFIG_MTD_PLATRAM is not set
-# CONFIG_MTD_PMC551 is not set
-# CONFIG_MTD_RAM is not set
-# CONFIG_MTD_REDBOOT_PARTS is not set
-# CONFIG_MTD_ROM is not set
-# CONFIG_MTD_SLRAM is not set
-# CONFIG_NATSEMI is not set
-# CONFIG_NE2K_PCI is not set
-# CONFIG_NET_SCH_ESFQ_NFCT is not set
-# CONFIG_NET_VENDOR_3COM is not set
-# CONFIG_NO_IOPORT is not set
-# CONFIG_PAGE_SIZE_16KB is not set
-CONFIG_PAGE_SIZE_4KB=y
-# CONFIG_PAGE_SIZE_64KB is not set
-# CONFIG_PAGE_SIZE_8KB is not set
-# CONFIG_PCIPCWATCHDOG is not set
-CONFIG_PCI=y
-CONFIG_PCI_DOMAINS=y
-CONFIG_PHYLIB=y
-# CONFIG_PMC_MSP is not set
-# CONFIG_PMC_YOSEMITE is not set
-# CONFIG_PNX8550_JBS is not set
-# CONFIG_PNX8550_STB810 is not set
-# CONFIG_PPP_MPPE is not set
-# CONFIG_PREVENT_FIRMWARE_BUILD is not set
-# CONFIG_QSEMI_PHY is not set
-CONFIG_RESOURCES_64BIT=y
-# CONFIG_RTC is not set
-CONFIG_RTC_LIB=y
-CONFIG_RWSEM_GENERIC_SPINLOCK=y
-CONFIG_SCHED_NO_NO_OMIT_FRAME_POINTER=y
-CONFIG_SCSI_CONSTANTS=y
-# CONFIG_SCSI_PROC_FS is not set
-CONFIG_SCSI_WAIT_SCAN=m
-CONFIG_SERIAL_8250_AU1X00=y
-# CONFIG_SERIAL_8250_EXTENDED is not set
-CONFIG_SERIAL_8250_NR_UARTS=4
-CONFIG_SERIAL_8250_PCI=m
-CONFIG_SERIAL_8250_RUNTIME_UARTS=4
-# CONFIG_SGI_IP22 is not set
-# CONFIG_SGI_IP27 is not set
-# CONFIG_SGI_IP32 is not set
-# CONFIG_SIBYTE_BIGSUR is not set
-# CONFIG_SIBYTE_CARMEL is not set
-# CONFIG_SIBYTE_CRHINE is not set
-# CONFIG_SIBYTE_CRHONE is not set
-# CONFIG_SIBYTE_LITTLESUR is not set
-# CONFIG_SIBYTE_PTSWARM is not set
-# CONFIG_SIBYTE_RHONE is not set
-# CONFIG_SIBYTE_SENTOSA is not set
-# CONFIG_SIBYTE_SWARM is not set
-CONFIG_SLABINFO=y
-# CONFIG_SMC91X is not set
-# CONFIG_SMSC_PHY is not set
-# CONFIG_SND_AU1X00 is not set
-CONFIG_SOC_AU1500=y
-CONFIG_SOC_AU1X00=y
-CONFIG_SOFT_WATCHDOG=m
-# CONFIG_SPARSEMEM_STATIC is not set
-# CONFIG_SPARSEMEM_VMEMMAP_ENABLE is not set
-CONFIG_SSB_POSSIBLE=y
-# CONFIG_STANDALONE is not set
-CONFIG_SYSVIPC_SYSCTL=y
-CONFIG_SYS_HAS_CPU_MIPS32_R1=y
-CONFIG_SYS_SUPPORTS_32BIT_KERNEL=y
-CONFIG_SYS_SUPPORTS_APM_EMULATION=y
-CONFIG_SYS_SUPPORTS_ARBIT_HZ=y
-CONFIG_SYS_SUPPORTS_KGDB=y
-CONFIG_SYS_SUPPORTS_LITTLE_ENDIAN=y
-# CONFIG_TC35815 is not set
-CONFIG_TICK_ONESHOT=y
-# CONFIG_TMD_HERMES is not set
-# CONFIG_TOSHIBA_JMR3927 is not set
-# CONFIG_TOSHIBA_RBTX4927 is not set
-# CONFIG_TOSHIBA_RBTX4938 is not set
-CONFIG_TRAD_SIGNALS=y
-# CONFIG_USBPCWATCHDOG is not set
-CONFIG_USB=m
-CONFIG_USB_EHCI_HCD=m
-# CONFIG_USB_OHCI_BIG_ENDIAN_DESC is not set
-# CONFIG_USB_OHCI_BIG_ENDIAN_MMIO is not set
-CONFIG_USB_OHCI_HCD=m
-# CONFIG_USB_PWC is not set
-# CONFIG_USB_R8A66597_HCD is not set
-# CONFIG_USB_SERIAL_CH341 is not set
-# CONFIG_USB_SERIAL_OTI6858 is not set
-CONFIG_USB_UHCI_HCD=m
-# CONFIG_USER_NS is not set
-CONFIG_V4L_USB_DRIVERS=y
-# CONFIG_VGASTATE is not set
-# CONFIG_VIA_RHINE is not set
-CONFIG_VIDEO_CAPTURE_DRIVERS=y
-# CONFIG_VIDEO_CPIA2 is not set
-# CONFIG_VIDEO_TCM825X is not set
-CONFIG_VIDEO_V4L1=y
-# CONFIG_VIDEO_VP27SMPX is not set
-CONFIG_WDT_MTX1=y
-CONFIG_ZONE_DMA_FLAG=0
+++ /dev/null
-# CONFIG_6PACK is not set
-# CONFIG_8139CP is not set
-# CONFIG_9P_FS is not set
-# CONFIG_ACENIC is not set
-# CONFIG_ACORN_PARTITION is not set
-# CONFIG_ADAPTEC_STARFIRE is not set
-# CONFIG_ADFS_FS is not set
-# CONFIG_AFFS_FS is not set
-# CONFIG_AFS_FS is not set
-CONFIG_AIRO=m
-CONFIG_AIRO_CS=m
-# CONFIG_AMD8111_ETH is not set
-# CONFIG_AMIGA_PARTITION is not set
-# CONFIG_APPLICOM is not set
-CONFIG_ARCH_FLATMEM_ENABLE=y
-# CONFIG_ARCNET is not set
-CONFIG_ARPD=y
-CONFIG_ASK_IP_FIB_HASH=y
-# CONFIG_ATA is not set
-# CONFIG_ATALK is not set
-# CONFIG_ATARI_PARTITION is not set
-# CONFIG_ATA_OVER_ETH is not set
-# CONFIG_ATL1 is not set
-CONFIG_ATM=m
-# CONFIG_ATMEL is not set
-# CONFIG_ATM_AMBASSADOR is not set
-CONFIG_ATM_BR2684=m
-CONFIG_ATM_BR2684_IPFILTER=y
-CONFIG_ATM_CLIP=m
-CONFIG_ATM_CLIP_NO_ICMP=y
-# CONFIG_ATM_DRIVERS is not set
-CONFIG_ATM_DUMMY=m
-# CONFIG_ATM_ENI is not set
-# CONFIG_ATM_FIRESTREAM is not set
-# CONFIG_ATM_FORE200E_MAYBE is not set
-# CONFIG_ATM_HE is not set
-# CONFIG_ATM_HORIZON is not set
-# CONFIG_ATM_IA is not set
-# CONFIG_ATM_IDT77252 is not set
-# CONFIG_ATM_LANAI is not set
-CONFIG_ATM_LANE=m
-CONFIG_ATM_MPOA=m
-# CONFIG_ATM_NICSTAR is not set
-CONFIG_ATM_TCP=m
-# CONFIG_ATM_ZATM is not set
-# CONFIG_AUDIT is not set
-# CONFIG_AUTOFS4_FS is not set
-# CONFIG_AUTOFS_FS is not set
-CONFIG_AX25=m
-# CONFIG_AX25_DAMA_SLAVE is not set
-# CONFIG_B44 is not set
-# CONFIG_BACKLIGHT_LCD_SUPPORT is not set
-CONFIG_BASE_FULL=y
-# CONFIG_BASLER_EXCITE is not set
-# CONFIG_BAYCOM_EPP is not set
-# CONFIG_BAYCOM_PAR is not set
-# CONFIG_BAYCOM_SER_FDX is not set
-# CONFIG_BAYCOM_SER_HDX is not set
-CONFIG_BCM43XX=m
-CONFIG_BCM43XX_DEBUG=y
-CONFIG_BCM43XX_DMA=y
-CONFIG_BCM43XX_DMA_AND_PIO_MODE=y
-# CONFIG_BCM43XX_DMA_MODE is not set
-CONFIG_BCM43XX_PIO=y
-# CONFIG_BCM43XX_PIO_MODE is not set
-# CONFIG_BEFS_FS is not set
-# CONFIG_BFS_FS is not set
-CONFIG_BINFMT_ELF=y
-# CONFIG_BINFMT_MISC is not set
-# CONFIG_BLK_CPQ_CISS_DA is not set
-# CONFIG_BLK_CPQ_DA is not set
-# CONFIG_BLK_DEV_3W_XXXX_RAID is not set
-# CONFIG_BLK_DEV_AEC62XX is not set
-# CONFIG_BLK_DEV_ALI15X3 is not set
-# CONFIG_BLK_DEV_AMD74XX is not set
-# CONFIG_BLK_DEV_ATIIXP is not set
-# CONFIG_BLK_DEV_CMD640 is not set
-# CONFIG_BLK_DEV_CMD64X is not set
-# CONFIG_BLK_DEV_COW_COMMON is not set
-CONFIG_BLK_DEV_CRYPTOLOOP=m
-# CONFIG_BLK_DEV_CS5520 is not set
-# CONFIG_BLK_DEV_CS5530 is not set
-# CONFIG_BLK_DEV_CS5535 is not set
-# CONFIG_BLK_DEV_CY82C693 is not set
-# CONFIG_BLK_DEV_DAC960 is not set
-# CONFIG_BLK_DEV_DELKIN is not set
-# CONFIG_BLK_DEV_FD is not set
-# CONFIG_BLK_DEV_IDECD is not set
-# CONFIG_BLK_DEV_IDECS is not set
-# CONFIG_BLK_DEV_IDEFLOPPY is not set
-# CONFIG_BLK_DEV_IDEPCI is not set
-# CONFIG_BLK_DEV_IDEPNP is not set
-# CONFIG_BLK_DEV_IDESCSI is not set
-# CONFIG_BLK_DEV_IDETAPE is not set
-# CONFIG_BLK_DEV_IDE_SATA is not set
-CONFIG_BLK_DEV_INITRD=y
-# CONFIG_BLK_DEV_IO_TRACE is not set
-# CONFIG_BLK_DEV_IT8213 is not set
-# CONFIG_BLK_DEV_IT821X is not set
-# CONFIG_BLK_DEV_JMICRON is not set
-CONFIG_BLK_DEV_LOOP=m
-CONFIG_BLK_DEV_NBD=m
-# CONFIG_BLK_DEV_NS87415 is not set
-# CONFIG_BLK_DEV_OFFBOARD is not set
-# CONFIG_BLK_DEV_OPTI621 is not set
-# CONFIG_BLK_DEV_PDC202XX_NEW is not set
-# CONFIG_BLK_DEV_PDC202XX_OLD is not set
-# CONFIG_BLK_DEV_PIIX is not set
-# CONFIG_BLK_DEV_RAM is not set
-# CONFIG_BLK_DEV_RZ1000 is not set
-CONFIG_BLK_DEV_SD=m
-# CONFIG_BLK_DEV_SIIMAGE is not set
-# CONFIG_BLK_DEV_SIS5513 is not set
-# CONFIG_BLK_DEV_SLC90E66 is not set
-# CONFIG_BLK_DEV_SR is not set
-# CONFIG_BLK_DEV_SVWKS is not set
-# CONFIG_BLK_DEV_SX8 is not set
-# CONFIG_BLK_DEV_TC86C001 is not set
-# CONFIG_BLK_DEV_TRIFLEX is not set
-# CONFIG_BLK_DEV_TRM290 is not set
-# CONFIG_BLK_DEV_UB is not set
-# CONFIG_BLK_DEV_UMEM is not set
-CONFIG_BLOCK=y
-# CONFIG_BNX2 is not set
-CONFIG_BONDING=m
-# CONFIG_BPQETHER is not set
-CONFIG_BRIDGE=y
-CONFIG_BRIDGE_EBT_802_3=m
-CONFIG_BRIDGE_EBT_AMONG=m
-CONFIG_BRIDGE_EBT_ARP=m
-CONFIG_BRIDGE_EBT_ARPREPLY=m
-CONFIG_BRIDGE_EBT_BROUTE=m
-CONFIG_BRIDGE_EBT_DNAT=m
-CONFIG_BRIDGE_EBT_IP=m
-CONFIG_BRIDGE_EBT_LIMIT=m
-CONFIG_BRIDGE_EBT_LOG=m
-CONFIG_BRIDGE_EBT_MARK=m
-CONFIG_BRIDGE_EBT_MARK_T=m
-CONFIG_BRIDGE_EBT_NFLOG=m
-CONFIG_BRIDGE_EBT_PKTTYPE=m
-CONFIG_BRIDGE_EBT_REDIRECT=m
-CONFIG_BRIDGE_EBT_SNAT=m
-CONFIG_BRIDGE_EBT_STP=m
-CONFIG_BRIDGE_EBT_T_FILTER=m
-CONFIG_BRIDGE_EBT_T_NAT=m
-CONFIG_BRIDGE_EBT_ULOG=m
-CONFIG_BRIDGE_EBT_VLAN=m
-# CONFIG_BRIDGE_NETFILTER is not set
-CONFIG_BRIDGE_NF_EBTABLES=m
-CONFIG_BROKEN_ON_SMP=y
-CONFIG_BSD_DISKLABEL=y
-CONFIG_BSD_PROCESS_ACCT=y
-# CONFIG_BSD_PROCESS_ACCT_V3 is not set
-CONFIG_BT=m
-CONFIG_BT_BNEP=m
-CONFIG_BT_BNEP_MC_FILTER=y
-CONFIG_BT_BNEP_PROTO_FILTER=y
-# CONFIG_BT_CMTP is not set
-CONFIG_BT_HCIBCM203X=m
-CONFIG_BT_HCIBFUSB=m
-# CONFIG_BT_HCIBLUECARD is not set
-CONFIG_BT_HCIBPA10X=m
-# CONFIG_BT_HCIBT3C is not set
-# CONFIG_BT_HCIBTUART is not set
-# CONFIG_BT_HCIDTL1 is not set
-CONFIG_BT_HCIUART=m
-CONFIG_BT_HCIUART_BCSP=y
-CONFIG_BT_HCIUART_H4=y
-CONFIG_BT_HCIUSB=m
-CONFIG_BT_HCIUSB_SCO=y
-CONFIG_BT_HCIVHCI=m
-CONFIG_BT_HIDP=m
-CONFIG_BT_L2CAP=m
-CONFIG_BT_RFCOMM=m
-CONFIG_BT_RFCOMM_TTY=y
-CONFIG_BT_SCO=m
-CONFIG_BUG=y
-# CONFIG_CAPI_AVM is not set
-# CONFIG_CAPI_EICON is not set
-# CONFIG_CAPI_TRACE is not set
-CONFIG_CARDBUS=y
-# CONFIG_CARDMAN_4000 is not set
-# CONFIG_CARDMAN_4040 is not set
-# CONFIG_CASSINI is not set
-CONFIG_CC_OPTIMIZE_FOR_SIZE=y
-# CONFIG_CDROM_PKTCDVD is not set
-# CONFIG_CHELSIO_T1 is not set
-# CONFIG_CHELSIO_T3 is not set
-# CONFIG_CHR_DEV_OSST is not set
-# CONFIG_CHR_DEV_SCH is not set
-# CONFIG_CHR_DEV_SG is not set
-# CONFIG_CHR_DEV_ST is not set
-# CONFIG_CICADA_PHY is not set
-CONFIG_CIFS=m
-# CONFIG_CIFS_DEBUG2 is not set
-# CONFIG_CIFS_EXPERIMENTAL is not set
-CONFIG_CIFS_POSIX=y
-CONFIG_CIFS_STATS=y
-# CONFIG_CIFS_STATS2 is not set
-# CONFIG_CIFS_WEAK_PW_HASH is not set
-# CONFIG_CIFS_XATTR is not set
-CONFIG_CLS_U32_MARK=y
-CONFIG_CLS_U32_PERF=y
-CONFIG_CMDLINE=""
-# CONFIG_CODA_FS is not set
-CONFIG_CONFIGFS_FS=y
-# CONFIG_CONNECTOR is not set
-# CONFIG_CRAMFS is not set
-CONFIG_CRC16=m
-CONFIG_CRC32=y
-CONFIG_CRC_CCITT=m
-CONFIG_CROSSCOMPILE=y
-CONFIG_CRYPTO=y
-CONFIG_CRYPTO_AES=m
-CONFIG_CRYPTO_ALGAPI=m
-CONFIG_CRYPTO_ANUBIS=m
-CONFIG_CRYPTO_ARC4=m
-CONFIG_CRYPTO_BLKCIPHER=m
-CONFIG_CRYPTO_BLOWFISH=m
-CONFIG_CRYPTO_CAMELLIA=m
-CONFIG_CRYPTO_CAST5=m
-CONFIG_CRYPTO_CAST6=m
-CONFIG_CRYPTO_CBC=m
-CONFIG_CRYPTO_CRC32C=m
-CONFIG_CRYPTO_DEFLATE=m
-CONFIG_CRYPTO_DES=m
-CONFIG_CRYPTO_ECB=m
-# CONFIG_CRYPTO_FCRYPT is not set
-# CONFIG_CRYPTO_GF128MUL is not set
-CONFIG_CRYPTO_HASH=m
-CONFIG_CRYPTO_HMAC=m
-CONFIG_CRYPTO_KHAZAD=m
-# CONFIG_CRYPTO_LRW is not set
-CONFIG_CRYPTO_MANAGER=m
-CONFIG_CRYPTO_MD4=m
-CONFIG_CRYPTO_MD5=m
-CONFIG_CRYPTO_MICHAEL_MIC=m
-CONFIG_CRYPTO_NULL=m
-# CONFIG_CRYPTO_PCBC is not set
-CONFIG_CRYPTO_SERPENT=m
-CONFIG_CRYPTO_SHA1=m
-CONFIG_CRYPTO_SHA256=m
-CONFIG_CRYPTO_SHA512=m
-CONFIG_CRYPTO_TEA=m
-CONFIG_CRYPTO_TEST=m
-CONFIG_CRYPTO_TGR192=m
-CONFIG_CRYPTO_TWOFISH=m
-CONFIG_CRYPTO_TWOFISH_COMMON=m
-CONFIG_CRYPTO_WP512=m
-# CONFIG_CRYPTO_XCBC is not set
-# CONFIG_DAVICOM_PHY is not set
-# CONFIG_DEBUG_FS is not set
-# CONFIG_DEBUG_KERNEL is not set
-# CONFIG_DECNET is not set
-# CONFIG_DEFAULT_AS is not set
-# CONFIG_DEFAULT_BIC is not set
-# CONFIG_DEFAULT_CFQ is not set
-# CONFIG_DEFAULT_CUBIC is not set
-CONFIG_DEFAULT_DEADLINE=y
-# CONFIG_DEFAULT_HTCP is not set
-CONFIG_DEFAULT_IOSCHED="deadline"
-# CONFIG_DEFAULT_NOOP is not set
-# CONFIG_DEFAULT_RENO is not set
-CONFIG_DEFAULT_TCP_CONG="vegas"
-CONFIG_DEFAULT_VEGAS=y
-# CONFIG_DEFAULT_WESTWOOD is not set
-CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
-# CONFIG_DEVFS_DEBUG is not set
-CONFIG_DEVFS_FS=y
-CONFIG_DEVFS_MOUNT=y
-# CONFIG_DGRS is not set
-# CONFIG_DISCONTIGMEM_MANUAL is not set
-# CONFIG_DL2K is not set
-# CONFIG_DLM is not set
-# CONFIG_DMA_ENGINE is not set
-# CONFIG_DNOTIFY is not set
-# CONFIG_DRM is not set
-# CONFIG_DTLK is not set
-# CONFIG_DUMMY is not set
-# CONFIG_DVB is not set
-CONFIG_E100=m
-# CONFIG_E1000 is not set
-# CONFIG_ECONET is not set
-# CONFIG_EEPRO100 is not set
-# CONFIG_EFI_PARTITION is not set
-# CONFIG_EFS_FS is not set
-# CONFIG_ELF_CORE is not set
-CONFIG_EMBEDDED=y
-# CONFIG_ENABLE_MUST_CHECK is not set
-# CONFIG_EPIC100 is not set
-CONFIG_EPOLL=y
-# CONFIG_EQUALIZER is not set
-CONFIG_EXPERIMENTAL=y
-CONFIG_EXPORTFS=m
-CONFIG_EXT2_FS=m
-# CONFIG_EXT2_FS_XATTR is not set
-# CONFIG_EXT2_FS_XIP is not set
-CONFIG_EXT3_FS=m
-# CONFIG_EXT3_FS_XATTR is not set
-# CONFIG_EXT4DEV_FS is not set
-CONFIG_FAT_DEFAULT_CODEPAGE=437
-CONFIG_FAT_DEFAULT_IOCHARSET="iso8859-1"
-CONFIG_FAT_FS=m
-# CONFIG_FB is not set
-# CONFIG_FB_IBM_GXT4500 is not set
-# CONFIG_FDDI is not set
-# CONFIG_FEALNX is not set
-CONFIG_FIB_RULES=y
-CONFIG_FLATMEM=y
-CONFIG_FLATMEM_MANUAL=y
-CONFIG_FLAT_NODE_MEM_MAP=y
-# CONFIG_FORCEDETH is not set
-# CONFIG_FS_POSIX_ACL is not set
-# CONFIG_FTL is not set
-# CONFIG_FUSE_FS is not set
-# CONFIG_FUSION is not set
-# CONFIG_FUSION_FC is not set
-# CONFIG_FUSION_SAS is not set
-# CONFIG_FUSION_SPI is not set
-CONFIG_FUTEX=y
-CONFIG_FW_LOADER=y
-CONFIG_GACT_PROB=y
-# CONFIG_GAMEPORT is not set
-CONFIG_GENERIC_CALIBRATE_DELAY=y
-CONFIG_GENERIC_HARDIRQS=y
-CONFIG_GENERIC_HWEIGHT=y
-CONFIG_GENERIC_IRQ_PROBE=y
-CONFIG_GENERIC_TIME=y
-# CONFIG_GFS2_FS is not set
-CONFIG_GPIO_DEVICE=m
-# CONFIG_HAMACHI is not set
-CONFIG_HAMRADIO=y
-# CONFIG_HAPPYMEAL is not set
-# CONFIG_HEADERS_CHECK is not set
-CONFIG_HERMES=m
-CONFIG_HFSPLUS_FS=m
-CONFIG_HFS_FS=m
-# CONFIG_HID_DEBUG is not set
-# CONFIG_HID_FF is not set
-# CONFIG_HIPPI is not set
-CONFIG_HOSTAP=m
-CONFIG_HOSTAP_CS=m
-CONFIG_HOSTAP_FIRMWARE=y
-CONFIG_HOSTAP_FIRMWARE_NVRAM=y
-CONFIG_HOSTAP_PCI=m
-CONFIG_HOSTAP_PLX=m
-CONFIG_HOTPLUG=y
-# CONFIG_HOTPLUG_PCI is not set
-# CONFIG_HP100 is not set
-# CONFIG_HPFS_FS is not set
-# CONFIG_HUGETLB_PAGE is not set
-# CONFIG_HWMON is not set
-# CONFIG_HWMON_VID is not set
-CONFIG_HZ=100
-CONFIG_HZ_100=y
-# CONFIG_HZ_1000 is not set
-# CONFIG_HZ_1024 is not set
-# CONFIG_HZ_128 is not set
-# CONFIG_HZ_250 is not set
-# CONFIG_HZ_256 is not set
-# CONFIG_HZ_300 is not set
-# CONFIG_HZ_48 is not set
-# CONFIG_I2C_ALGOPCA is not set
-# CONFIG_I2C_ALGOPCF is not set
-# CONFIG_I2C_ALI1535 is not set
-# CONFIG_I2C_ALI1563 is not set
-# CONFIG_I2C_ALI15X3 is not set
-# CONFIG_I2C_AMD756 is not set
-# CONFIG_I2C_AMD8111 is not set
-# CONFIG_I2C_DEBUG_ALGO is not set
-# CONFIG_I2C_DEBUG_BUS is not set
-# CONFIG_I2C_DEBUG_CHIP is not set
-# CONFIG_I2C_DEBUG_CORE is not set
-# CONFIG_I2C_ELEKTOR is not set
-# CONFIG_I2C_I801 is not set
-# CONFIG_I2C_I810 is not set
-# CONFIG_I2C_NFORCE2 is not set
-# CONFIG_I2C_OCORES is not set
-# CONFIG_I2C_PARPORT_LIGHT is not set
-# CONFIG_I2C_PCA_ISA is not set
-# CONFIG_I2C_PIIX4 is not set
-# CONFIG_I2C_PROSAVAGE is not set
-# CONFIG_I2C_SAVAGE4 is not set
-# CONFIG_I2C_SIS5595 is not set
-# CONFIG_I2C_SIS630 is not set
-# CONFIG_I2C_SIS96X is not set
-# CONFIG_I2C_STUB is not set
-# CONFIG_I2C_VIA is not set
-# CONFIG_I2C_VIAPRO is not set
-# CONFIG_I2C_VOODOO3 is not set
-# CONFIG_I2O is not set
-# CONFIG_I82092 is not set
-CONFIG_IDE_MAX_HWIFS=4
-# CONFIG_IDE_TASK_IOCTL is not set
-# CONFIG_IDEDISK_MULTI_MODE is not set
-# CONFIG_IEEE1394 is not set
-CONFIG_IEEE80211=m
-CONFIG_IEEE80211_CRYPT_CCMP=m
-CONFIG_IEEE80211_CRYPT_TKIP=m
-CONFIG_IEEE80211_CRYPT_WEP=m
-# CONFIG_IEEE80211_DEBUG is not set
-CONFIG_IEEE80211_SOFTMAC=m
-# CONFIG_IEEE80211_SOFTMAC_DEBUG is not set
-CONFIG_IFB=m
-CONFIG_IKCONFIG=y
-CONFIG_IKCONFIG_PROC=y
-CONFIG_IMQ=m
-# CONFIG_IMQ_BEHAVIOR_AA is not set
-# CONFIG_IMQ_BEHAVIOR_AB is not set
-CONFIG_IMQ_BEHAVIOR_BA=y
-# CONFIG_IMQ_BEHAVIOR_BB is not set
-CONFIG_IMQ_NUM_DEVS=2
-CONFIG_INET=y
-CONFIG_INET6_AH=m
-CONFIG_INET6_ESP=m
-CONFIG_INET6_IPCOMP=m
-CONFIG_INET6_TUNNEL=m
-CONFIG_INET6_XFRM_MODE_BEET=m
-# CONFIG_INET6_XFRM_MODE_ROUTEOPTIMIZATION is not set
-CONFIG_INET6_XFRM_MODE_TRANSPORT=m
-CONFIG_INET6_XFRM_MODE_TUNNEL=m
-CONFIG_INET6_XFRM_TUNNEL=m
-CONFIG_INET_AH=m
-CONFIG_INET_DCCP_DIAG=m
-CONFIG_INET_DIAG=m
-CONFIG_INET_ESP=m
-CONFIG_INET_IPCOMP=m
-CONFIG_INET_TCP_DIAG=m
-CONFIG_INET_TUNNEL=m
-CONFIG_INET_XFRM_MODE_BEET=m
-CONFIG_INET_XFRM_MODE_TRANSPORT=m
-CONFIG_INET_XFRM_MODE_TUNNEL=m
-CONFIG_INET_XFRM_TUNNEL=m
-# CONFIG_INFINIBAND is not set
-# CONFIG_INFTL is not set
-CONFIG_INIT_ENV_ARG_LIMIT=32
-# CONFIG_INOTIFY is not set
-# CONFIG_INOTIFY_USER is not set
-# CONFIG_INPUT is not set
-# CONFIG_INPUT_ATI_REMOTE is not set
-# CONFIG_INPUT_ATI_REMOTE2 is not set
-# CONFIG_INPUT_EVBUG is not set
-CONFIG_INPUT_EVDEV=m
-# CONFIG_INPUT_FF_MEMLESS is not set
-# CONFIG_INPUT_JOYDEV is not set
-# CONFIG_INPUT_JOYSTICK is not set
-# CONFIG_INPUT_KEYBOARD is not set
-# CONFIG_INPUT_KEYSPAN_REMOTE is not set
-# CONFIG_INPUT_MISC is not set
-# CONFIG_INPUT_MOUSE is not set
-# CONFIG_INPUT_MOUSEDEV is not set
-# CONFIG_INPUT_PCSPKR is not set
-# CONFIG_INPUT_POWERMATE is not set
-# CONFIG_INPUT_TOUCHSCREEN is not set
-# CONFIG_INPUT_TSDEV is not set
-# CONFIG_INPUT_UINPUT is not set
-# CONFIG_INPUT_WISTRON_BTNS is not set
-# CONFIG_IOSCHED_AS is not set
-# CONFIG_IOSCHED_CFQ is not set
-CONFIG_IOSCHED_DEADLINE=y
-CONFIG_IOSCHED_NOOP=y
-CONFIG_IP6_NF_FILTER=m
-CONFIG_IP6_NF_IPTABLES=m
-CONFIG_IP6_NF_MANGLE=m
-CONFIG_IP6_NF_MATCH_AH=m
-CONFIG_IP6_NF_MATCH_EUI64=m
-CONFIG_IP6_NF_MATCH_FRAG=m
-CONFIG_IP6_NF_MATCH_HL=m
-CONFIG_IP6_NF_MATCH_IPV6HEADER=m
-CONFIG_IP6_NF_MATCH_LIMIT=m
-CONFIG_IP6_NF_MATCH_MH=m
-CONFIG_IP6_NF_MATCH_OPTS=m
-CONFIG_IP6_NF_MATCH_OWNER=m
-CONFIG_IP6_NF_MATCH_RT=m
-CONFIG_IP6_NF_QUEUE=m
-CONFIG_IP6_NF_RAW=m
-CONFIG_IP6_NF_TARGET_HL=m
-CONFIG_IP6_NF_TARGET_IMQ=m
-CONFIG_IP6_NF_TARGET_LOG=m
-CONFIG_IP6_NF_TARGET_REJECT=m
-CONFIG_IP6_NF_TARGET_ROUTE=m
-# CONFIG_IPC_NS is not set
-# CONFIG_IPMI_HANDLER is not set
-CONFIG_IPSEC_NAT_TRAVERSAL=y
-CONFIG_IPV6=m
-# CONFIG_IPV6_MIP6 is not set
-# CONFIG_IPV6_MULTIPLE_TABLES is not set
-# CONFIG_IPV6_PRIVACY is not set
-CONFIG_IPV6_ROUTER_PREF=y
-# CONFIG_IPV6_ROUTE_INFO is not set
-CONFIG_IPV6_SIT=m
-# CONFIG_IPV6_TUNNEL is not set
-CONFIG_IPW2100=m
-# CONFIG_IPW2100_DEBUG is not set
-CONFIG_IPW2100_MONITOR=y
-CONFIG_IPW2200=m
-# CONFIG_IPW2200_DEBUG is not set
-CONFIG_IPW2200_MONITOR=y
-# CONFIG_IPW2200_PROMISCUOUS is not set
-# CONFIG_IPW2200_QOS is not set
-# CONFIG_IPW2200_RADIOTAP is not set
-# CONFIG_IPX is not set
-CONFIG_IP_ADVANCED_ROUTER=y
-CONFIG_IP_DCCP=m
-CONFIG_IP_DCCP_ACKVEC=y
-CONFIG_IP_DCCP_CCID2=m
-# CONFIG_IP_DCCP_CCID2_DEBUG is not set
-CONFIG_IP_DCCP_CCID3=m
-# CONFIG_IP_DCCP_CCID3_DEBUG is not set
-CONFIG_IP_DCCP_CCID3_RTO=100
-CONFIG_IP_DCCP_TFRC_LIB=m
-CONFIG_IP_FIB_HASH=y
-# CONFIG_IP_FIB_TRIE is not set
-# CONFIG_IP_MROUTE is not set
-CONFIG_IP_MULTICAST=y
-CONFIG_IP_MULTIPLE_TABLES=y
-CONFIG_IP_NF_AMANDA=m
-CONFIG_IP_NF_ARPFILTER=m
-CONFIG_IP_NF_ARPTABLES=m
-CONFIG_IP_NF_ARP_MANGLE=m
-CONFIG_IP_NF_CONNTRACK=y
-# CONFIG_IP_NF_CONNTRACK_EVENTS is not set
-CONFIG_IP_NF_CONNTRACK_MARK=y
-# CONFIG_IP_NF_CONNTRACK_SUPPORT is not set
-CONFIG_IP_NF_CT_ACCT=y
-CONFIG_IP_NF_CT_PROTO_SCTP=m
-CONFIG_IP_NF_FILTER=y
-CONFIG_IP_NF_FTP=m
-CONFIG_IP_NF_H323=m
-CONFIG_IP_NF_IPTABLES=y
-CONFIG_IP_NF_IRC=m
-CONFIG_IP_NF_MANGLE=y
-CONFIG_IP_NF_MATCH_ADDRTYPE=m
-CONFIG_IP_NF_MATCH_AH=m
-CONFIG_IP_NF_MATCH_ECN=m
-CONFIG_IP_NF_MATCH_HASHLIMIT=m
-CONFIG_IP_NF_MATCH_IPP2P=m
-CONFIG_IP_NF_MATCH_IPRANGE=m
-CONFIG_IP_NF_MATCH_OWNER=m
-CONFIG_IP_NF_MATCH_RECENT=m
-CONFIG_IP_NF_MATCH_SET=m
-CONFIG_IP_NF_MATCH_TIME=m
-CONFIG_IP_NF_MATCH_TOS=m
-CONFIG_IP_NF_MATCH_TTL=m
-CONFIG_IP_NF_NAT=y
-CONFIG_IP_NF_NAT_AMANDA=m
-CONFIG_IP_NF_NAT_FTP=m
-CONFIG_IP_NF_NAT_H323=m
-CONFIG_IP_NF_NAT_IRC=m
-CONFIG_IP_NF_NAT_NEEDED=y
-CONFIG_IP_NF_NAT_PPTP=m
-CONFIG_IP_NF_NAT_SIP=m
-# CONFIG_IP_NF_NAT_SNMP_BASIC is not set
-CONFIG_IP_NF_NAT_TFTP=m
-# CONFIG_IP_NF_NETBIOS_NS is not set
-CONFIG_IP_NF_PPTP=m
-CONFIG_IP_NF_QUEUE=m
-CONFIG_IP_NF_RAW=m
-CONFIG_IP_NF_SET=m
-CONFIG_IP_NF_SET_HASHSIZE=1024
-CONFIG_IP_NF_SET_IPHASH=m
-CONFIG_IP_NF_SET_IPMAP=m
-CONFIG_IP_NF_SET_IPPORTHASH=m
-CONFIG_IP_NF_SET_IPTREE=m
-CONFIG_IP_NF_SET_IPTREEMAP=m
-CONFIG_IP_NF_SET_MACIPMAP=m
-CONFIG_IP_NF_SET_MAX=256
-CONFIG_IP_NF_SET_NETHASH=m
-CONFIG_IP_NF_SET_PORTMAP=m
-CONFIG_IP_NF_SIP=m
-# CONFIG_IP_NF_TARGET_CLUSTERIP is not set
-CONFIG_IP_NF_TARGET_ECN=m
-CONFIG_IP_NF_TARGET_IMQ=m
-CONFIG_IP_NF_TARGET_LOG=m
-CONFIG_IP_NF_TARGET_MASQUERADE=y
-CONFIG_IP_NF_TARGET_NETMAP=m
-CONFIG_IP_NF_TARGET_REDIRECT=y
-CONFIG_IP_NF_TARGET_REJECT=y
-CONFIG_IP_NF_TARGET_ROUTE=m
-CONFIG_IP_NF_TARGET_SAME=m
-CONFIG_IP_NF_TARGET_SET=m
-CONFIG_IP_NF_TARGET_TCPMSS=y
-CONFIG_IP_NF_TARGET_TOS=m
-CONFIG_IP_NF_TARGET_TTL=m
-CONFIG_IP_NF_TARGET_ULOG=m
-CONFIG_IP_NF_TFTP=m
-# CONFIG_IP_PNP is not set
-CONFIG_IP_ROUTE_FWMARK=y
-CONFIG_IP_ROUTE_MULTIPATH=y
-CONFIG_IP_ROUTE_MULTIPATH_CACHED=y
-CONFIG_IP_ROUTE_MULTIPATH_DRR=m
-CONFIG_IP_ROUTE_MULTIPATH_RANDOM=m
-CONFIG_IP_ROUTE_MULTIPATH_RR=m
-CONFIG_IP_ROUTE_MULTIPATH_WRANDOM=m
-CONFIG_IP_ROUTE_VERBOSE=y
-# CONFIG_IP_SCTP is not set
-# CONFIG_IP_VS is not set
-# CONFIG_IRDA is not set
-# CONFIG_ISCSI_TCP is not set
-CONFIG_ISDN=m
-CONFIG_ISDN_CAPI=m
-CONFIG_ISDN_CAPI_CAPI20=m
-CONFIG_ISDN_CAPI_CAPIFS=m
-CONFIG_ISDN_CAPI_CAPIFS_BOOL=y
-CONFIG_ISDN_CAPI_MIDDLEWARE=y
-# CONFIG_ISDN_DRV_AVMB1_VERBOSE_REASON is not set
-# CONFIG_ISDN_I4L is not set
-CONFIG_ISO9660_FS=m
-# CONFIG_IXGB is not set
-CONFIG_JBD=m
-# CONFIG_JBD_DEBUG is not set
-# CONFIG_JFFS2_CMODE_NONE is not set
-CONFIG_JFFS2_CMODE_PRIORITY=y
-# CONFIG_JFFS2_CMODE_SIZE is not set
-CONFIG_JFFS2_COMPRESSION_OPTIONS=y
-CONFIG_JFFS2_FS=y
-CONFIG_JFFS2_FS_DEBUG=0
-CONFIG_JFFS2_FS_WRITEBUFFER=y
-# CONFIG_JFFS2_FS_XATTR is not set
-CONFIG_JFFS2_RTIME=y
-# CONFIG_JFFS2_RUBIN is not set
-CONFIG_JFFS2_SUMMARY=y
-CONFIG_JFFS2_ZLIB=y
-# CONFIG_JFFS_FS is not set
-# CONFIG_JFS_DEBUG is not set
-# CONFIG_JFS_FS is not set
-# CONFIG_JFS_POSIX_ACL is not set
-# CONFIG_JFS_SECURITY is not set
-# CONFIG_JFS_STATISTICS is not set
-CONFIG_JOLIET=y
-# CONFIG_KALLSYMS is not set
-# CONFIG_KARMA_PARTITION is not set
-# CONFIG_KEXEC is not set
-# CONFIG_KEYS is not set
-# CONFIG_KMOD is not set
-# CONFIG_LAPB is not set
-# CONFIG_LASAT is not set
-# CONFIG_LBD is not set
-# CONFIG_LDM_PARTITION is not set
-CONFIG_LEDS_CLASS=y
-CONFIG_LEDS_TRIGGERS=y
-CONFIG_LEDS_TRIGGER_HEARTBEAT=y
-# CONFIG_LEDS_TRIGGER_IDE_DISK is not set
-CONFIG_LEDS_TRIGGER_TIMER=y
-# CONFIG_LEDS_TRIGGER_MORSE is not set
-# CONFIG_LEGACY_PTYS is not set
-CONFIG_LIBCRC32C=m
-CONFIG_LLC=y
-CONFIG_LLC2=m
-CONFIG_LOCALVERSION=""
-# CONFIG_LOCALVERSION_AUTO is not set
-CONFIG_LOCKD=m
-CONFIG_LOCKDEP_SUPPORT=y
-CONFIG_LOCKD_V4=y
-CONFIG_LOG_BUF_SHIFT=14
-# CONFIG_LSF is not set
-# CONFIG_LXT_PHY is not set
-# CONFIG_MAC_EMUMOUSEBTN is not set
-CONFIG_MAC_PARTITION=y
-# CONFIG_MAGIC_SYSRQ is not set
-# CONFIG_MARKEINS is not set
-# CONFIG_MARVELL_PHY is not set
-# CONFIG_MD is not set
-# CONFIG_MEGARAID_LEGACY is not set
-# CONFIG_MEGARAID_NEWGEN is not set
-# CONFIG_MEGARAID_SAS is not set
-# CONFIG_MFD_SM501 is not set
-CONFIG_MII=y
-CONFIG_MINIX_FS=m
-# CONFIG_MINIX_SUBPARTITION is not set
-CONFIG_MINI_FO=y
-CONFIG_MKISS=m
-# CONFIG_MMC is not set
-CONFIG_MMU=y
-CONFIG_MODULES=y
-# CONFIG_MODULE_FORCE_UNLOAD is not set
-# CONFIG_MODULE_SRCVERSION_ALL is not set
-CONFIG_MODULE_UNLOAD=y
-# CONFIG_MODVERSIONS is not set
-CONFIG_MSDOS_FS=m
-CONFIG_MSDOS_PARTITION=y
-# CONFIG_MTD_NAND is not set
-CONFIG_MTD_ROOTFS_ROOT_DEV=y
-CONFIG_MTD_ROOTFS_SPLIT=y
-# CONFIG_MYRI10GE is not set
-# CONFIG_NCP_FS is not set
-CONFIG_NET=y
-# CONFIG_NETCONSOLE is not set
-# CONFIG_NETDEBUG is not set
-CONFIG_NETDEVICES=y
-CONFIG_NETFILTER=y
-# CONFIG_NETFILTER_DEBUG is not set
-# CONFIG_NETFILTER_NETLINK is not set
-CONFIG_NETFILTER_XTABLES=y
-CONFIG_NETFILTER_XT_MATCH_COMMENT=m
-CONFIG_NETFILTER_XT_MATCH_CONNBYTES=m
-CONFIG_NETFILTER_XT_MATCH_CONNMARK=m
-CONFIG_NETFILTER_XT_MATCH_CONNTRACK=y
-CONFIG_NETFILTER_XT_MATCH_DCCP=m
-CONFIG_NETFILTER_XT_MATCH_DSCP=m
-CONFIG_NETFILTER_XT_MATCH_ESP=m
-CONFIG_NETFILTER_XT_MATCH_HASHLIMIT=m
-CONFIG_NETFILTER_XT_MATCH_HELPER=m
-CONFIG_NETFILTER_XT_MATCH_LENGTH=m
-CONFIG_NETFILTER_XT_MATCH_LIMIT=y
-CONFIG_NETFILTER_XT_MATCH_MAC=m
-CONFIG_NETFILTER_XT_MATCH_MARK=m
-CONFIG_NETFILTER_XT_MATCH_MULTIPORT=y
-CONFIG_NETFILTER_XT_MATCH_PHYSDEV=m
-CONFIG_NETFILTER_XT_MATCH_PKTTYPE=m
-CONFIG_NETFILTER_XT_MATCH_POLICY=m
-CONFIG_NETFILTER_XT_MATCH_PORTSCAN=m
-# CONFIG_NETFILTER_XT_MATCH_QUOTA is not set
-CONFIG_NETFILTER_XT_MATCH_REALM=m
-CONFIG_NETFILTER_XT_MATCH_SCTP=m
-CONFIG_NETFILTER_XT_MATCH_STATE=y
-CONFIG_NETFILTER_XT_MATCH_LAYER7=m
-# CONFIG_NETFILTER_XT_MATCH_LAYER7_DEBUG is not set
-# CONFIG_NETFILTER_XT_MATCH_STATISTIC is not set
-CONFIG_NETFILTER_XT_MATCH_STRING=m
-CONFIG_NETFILTER_XT_MATCH_TCPMSS=y
-CONFIG_NETFILTER_XT_TARGET_CHAOS=m
-CONFIG_NETFILTER_XT_TARGET_CLASSIFY=m
-CONFIG_NETFILTER_XT_TARGET_CONNMARK=m
-CONFIG_NETFILTER_XT_TARGET_DELUDE=m
-CONFIG_NETFILTER_XT_TARGET_DSCP=m
-CONFIG_NETFILTER_XT_TARGET_MARK=m
-CONFIG_NETFILTER_XT_TARGET_NFLOG=m
-CONFIG_NETFILTER_XT_TARGET_NFQUEUE=m
-CONFIG_NETFILTER_XT_TARGET_NOTRACK=m
-CONFIG_NETFILTER_XT_TARGET_TCPMSS=y
-# CONFIG_NETPOLL is not set
-# CONFIG_NETROM is not set
-# CONFIG_NETWORK_SECMARK is not set
-# CONFIG_NETXEN_NIC is not set
-CONFIG_NET_ACT_GACT=m
-CONFIG_NET_ACT_IPT=m
-CONFIG_NET_ACT_MIRRED=m
-CONFIG_NET_ACT_PEDIT=m
-CONFIG_NET_ACT_POLICE=m
-# CONFIG_NET_ACT_SIMP is not set
-CONFIG_NET_CLS=y
-CONFIG_NET_CLS_ACT=y
-CONFIG_NET_CLS_BASIC=m
-CONFIG_NET_CLS_FW=m
-CONFIG_NET_CLS_IND=y
-CONFIG_NET_CLS_POLICE=y
-CONFIG_NET_CLS_ROUTE=y
-CONFIG_NET_CLS_ROUTE4=m
-CONFIG_NET_CLS_RSVP=m
-CONFIG_NET_CLS_RSVP6=m
-CONFIG_NET_CLS_TCINDEX=m
-CONFIG_NET_CLS_U32=m
-CONFIG_NET_EMATCH=y
-CONFIG_NET_EMATCH_CMP=m
-CONFIG_NET_EMATCH_META=m
-CONFIG_NET_EMATCH_NBYTE=m
-CONFIG_NET_EMATCH_STACK=32
-CONFIG_NET_EMATCH_TEXT=m
-CONFIG_NET_EMATCH_U32=m
-CONFIG_NET_ESTIMATOR=y
-CONFIG_NET_ETHERNET=y
-# CONFIG_NET_FC is not set
-CONFIG_NET_IPGRE=m
-CONFIG_NET_IPGRE_BROADCAST=y
-CONFIG_NET_IPIP=m
-CONFIG_NET_KEY=m
-# CONFIG_NET_KEY_MIGRATE is not set
-CONFIG_NET_PCI=y
-# CONFIG_NET_PCMCIA is not set
-CONFIG_NET_PKTGEN=m
-# CONFIG_NET_POLL_CONTROLLER is not set
-CONFIG_NET_RADIO=y
-CONFIG_NET_SCHED=y
-CONFIG_NET_SCH_ATM=m
-CONFIG_NET_SCH_CBQ=m
-# CONFIG_NET_SCH_CLK_CPU is not set
-# CONFIG_NET_SCH_CLK_GETTIMEOFDAY is not set
-CONFIG_NET_SCH_CLK_JIFFIES=y
-CONFIG_NET_SCH_DSMARK=m
-CONFIG_NET_SCH_ESFQ=m
-CONFIG_NET_SCH_GRED=m
-CONFIG_NET_SCH_HFSC=m
-CONFIG_NET_SCH_HTB=m
-CONFIG_NET_SCH_INGRESS=m
-CONFIG_NET_SCH_NETEM=m
-CONFIG_NET_SCH_PRIO=m
-CONFIG_NET_SCH_RED=m
-CONFIG_NET_SCH_SFQ=m
-CONFIG_NET_SCH_TBF=m
-CONFIG_NET_SCH_TEQL=m
-# CONFIG_NET_TULIP is not set
-CONFIG_NET_WIRELESS=y
-CONFIG_NET_WIRELESS_RTNETLINK=y
-CONFIG_NEW_LEDS=y
-CONFIG_NFSD=m
-CONFIG_NFSD_TCP=y
-# CONFIG_NFSD_V2_ACL is not set
-CONFIG_NFSD_V3=y
-# CONFIG_NFSD_V3_ACL is not set
-CONFIG_NFSD_V4=y
-# CONFIG_NFS_ACL_SUPPORT is not set
-CONFIG_NFS_COMMON=y
-# CONFIG_NFS_DIRECTIO is not set
-CONFIG_NFS_FS=m
-CONFIG_NFS_V3=y
-# CONFIG_NFS_V3_ACL is not set
-CONFIG_NFS_V4=y
-# CONFIG_NFTL is not set
-CONFIG_NF_CONNTRACK=y
-# CONFIG_NF_CONNTRACK_AMANDA is not set
-CONFIG_NF_CONNTRACK_ENABLED=y
-# CONFIG_NF_CONNTRACK_EVENTS is not set
-CONFIG_NF_CONNTRACK_FTP=m
-CONFIG_NF_CONNTRACK_H323=m
-CONFIG_NF_CONNTRACK_IPV4=y
-CONFIG_NF_CONNTRACK_IPV6=m
-CONFIG_NF_CONNTRACK_IRC=m
-CONFIG_NF_CONNTRACK_MARK=y
-# CONFIG_NF_CONNTRACK_NETBIOS_NS is not set
-# CONFIG_NF_CONNTRACK_PPTP is not set
-CONFIG_NF_CONNTRACK_PROC_COMPAT=y
-# CONFIG_NF_CONNTRACK_SANE is not set
-CONFIG_NF_CONNTRACK_SIP=m
-CONFIG_NF_CONNTRACK_SUPPORT=y
-# CONFIG_NF_CONNTRACK_TFTP is not set
-CONFIG_NF_CT_ACCT=y
-# CONFIG_NF_CT_PROTO_SCTP is not set
-CONFIG_NF_NAT=y
-# CONFIG_NF_NAT_AMANDA is not set
-CONFIG_NF_NAT_FTP=m
-CONFIG_NF_NAT_H323=m
-CONFIG_NF_NAT_IRC=m
-CONFIG_NF_NAT_NEEDED=y
-# CONFIG_NF_NAT_PPTP is not set
-CONFIG_NF_NAT_SIP=m
-# CONFIG_NF_NAT_SNMP_BASIC is not set
-# CONFIG_NF_NAT_TFTP is not set
-CONFIG_NLS=m
-# CONFIG_NLS_ASCII is not set
-CONFIG_NLS_CODEPAGE_1250=m
-# CONFIG_NLS_CODEPAGE_1251 is not set
-CONFIG_NLS_CODEPAGE_437=m
-# CONFIG_NLS_CODEPAGE_737 is not set
-# CONFIG_NLS_CODEPAGE_775 is not set
-CONFIG_NLS_CODEPAGE_850=m
-# CONFIG_NLS_CODEPAGE_852 is not set
-# CONFIG_NLS_CODEPAGE_855 is not set
-# CONFIG_NLS_CODEPAGE_857 is not set
-# CONFIG_NLS_CODEPAGE_860 is not set
-# CONFIG_NLS_CODEPAGE_861 is not set
-# CONFIG_NLS_CODEPAGE_862 is not set
-# CONFIG_NLS_CODEPAGE_863 is not set
-# CONFIG_NLS_CODEPAGE_864 is not set
-# CONFIG_NLS_CODEPAGE_865 is not set
-# CONFIG_NLS_CODEPAGE_866 is not set
-# CONFIG_NLS_CODEPAGE_869 is not set
-# CONFIG_NLS_CODEPAGE_874 is not set
-# CONFIG_NLS_CODEPAGE_932 is not set
-# CONFIG_NLS_CODEPAGE_936 is not set
-# CONFIG_NLS_CODEPAGE_949 is not set
-# CONFIG_NLS_CODEPAGE_950 is not set
-CONFIG_NLS_DEFAULT="iso8859-1"
-CONFIG_NLS_ISO8859_1=m
-# CONFIG_NLS_ISO8859_13 is not set
-# CONFIG_NLS_ISO8859_14 is not set
-CONFIG_NLS_ISO8859_15=m
-# CONFIG_NLS_ISO8859_2 is not set
-# CONFIG_NLS_ISO8859_3 is not set
-# CONFIG_NLS_ISO8859_4 is not set
-# CONFIG_NLS_ISO8859_5 is not set
-# CONFIG_NLS_ISO8859_6 is not set
-# CONFIG_NLS_ISO8859_7 is not set
-# CONFIG_NLS_ISO8859_8 is not set
-# CONFIG_NLS_ISO8859_9 is not set
-CONFIG_NLS_KOI8_R=m
-# CONFIG_NLS_KOI8_U is not set
-CONFIG_NLS_UTF8=m
-CONFIG_NORTEL_HERMES=m
-# CONFIG_NS83820 is not set
-# CONFIG_NTFS_DEBUG is not set
-# CONFIG_NTFS_FS is not set
-# CONFIG_NTFS_RW is not set
-# CONFIG_OCFS2_FS is not set
-# CONFIG_OSF_PARTITION is not set
-CONFIG_PACKET=y
-CONFIG_PACKET_MMAP=y
-# CONFIG_PARPORT is not set
-CONFIG_PARTITION_ADVANCED=y
-# CONFIG_PATA_ALI is not set
-# CONFIG_PATA_AMD is not set
-# CONFIG_PATA_ARTOP is not set
-# CONFIG_PATA_ATIIXP is not set
-# CONFIG_PATA_CMD64X is not set
-# CONFIG_PATA_CS5520 is not set
-# CONFIG_PATA_CS5530 is not set
-# CONFIG_PATA_CS5535 is not set
-# CONFIG_PATA_CYPRESS is not set
-# CONFIG_PATA_EFAR is not set
-# CONFIG_PATA_HPT366 is not set
-# CONFIG_PATA_HPT37X is not set
-# CONFIG_PATA_HPT3X2N is not set
-# CONFIG_PATA_HPT3X3 is not set
-# CONFIG_PATA_ISAPNP is not set
-# CONFIG_PATA_IT8213 is not set
-# CONFIG_PATA_IT821X is not set
-# CONFIG_PATA_JMICRON is not set
-# CONFIG_PATA_LEGACY is not set
-# CONFIG_PATA_MARVELL is not set
-# CONFIG_PATA_MPIIX is not set
-# CONFIG_PATA_NETCELL is not set
-# CONFIG_PATA_NS87410 is not set
-# CONFIG_PATA_OLDPIIX is not set
-# CONFIG_PATA_OPTI is not set
-# CONFIG_PATA_OPTIDMA is not set
-# CONFIG_PATA_PCMCIA is not set
-# CONFIG_PATA_PDC2027X is not set
-# CONFIG_PATA_PDC_OLD is not set
-CONFIG_PATA_PLATFORM=m
-# CONFIG_PATA_QDI is not set
-# CONFIG_PATA_RADISYS is not set
-# CONFIG_PATA_RZ1000 is not set
-# CONFIG_PATA_SC1200 is not set
-# CONFIG_PATA_SERVERWORKS is not set
-# CONFIG_PATA_SIL680 is not set
-# CONFIG_PATA_SIS is not set
-# CONFIG_PATA_TRIFLEX is not set
-# CONFIG_PATA_VIA is not set
-# CONFIG_PATA_WINBOND is not set
-# CONFIG_PATA_WINBOND_VLB is not set
-# CONFIG_PC300TOO is not set
-# CONFIG_PCCARD is not set
-CONFIG_PCI=y
-CONFIG_PCI_ATMEL=m
-CONFIG_PCI_HERMES=m
-# CONFIG_PCMCIA is not set
-# CONFIG_PCMCIA_AHA152X is not set
-# CONFIG_PCMCIA_ATMEL is not set
-# CONFIG_PCMCIA_DEBUG is not set
-# CONFIG_PCMCIA_FDOMAIN is not set
-# CONFIG_PCMCIA_HERMES is not set
-# CONFIG_PCMCIA_IOCTL is not set
-# CONFIG_PCMCIA_LOAD_CIS is not set
-# CONFIG_PCMCIA_NETWAVE is not set
-# CONFIG_PCMCIA_NINJA_SCSI is not set
-# CONFIG_PCMCIA_QLOGIC is not set
-# CONFIG_PCMCIA_RAYCS is not set
-# CONFIG_PCMCIA_SPECTRUM is not set
-# CONFIG_PCMCIA_SYM53C500 is not set
-# CONFIG_PCMCIA_WAVELAN is not set
-# CONFIG_PCMCIA_WL3501 is not set
-# CONFIG_PCNET32 is not set
-# CONFIG_PD6729 is not set
-# CONFIG_PHONE is not set
-# CONFIG_PHYLIB is not set
-CONFIG_PLIST=y
-CONFIG_PLX_HERMES=m
-# CONFIG_PM is not set
-# CONFIG_POSIX_MQUEUE is not set
-CONFIG_PPP=m
-CONFIG_PPPOATM=m
-CONFIG_PPPOE=m
-CONFIG_PPP_ASYNC=m
-CONFIG_PPP_BSDCOMP=m
-CONFIG_PPP_DEFLATE=m
-CONFIG_PPP_FILTER=y
-CONFIG_PPP_MPPE=m
-CONFIG_PPP_MULTILINK=y
-CONFIG_PPP_SYNC_TTY=m
-# CONFIG_PREEMPT is not set
-CONFIG_PREEMPT_NONE=y
-# CONFIG_PREEMPT_VOLUNTARY is not set
-CONFIG_PREVENT_FIRMWARE_BUILD=y
-CONFIG_PRINTK=y
-# CONFIG_PRINTK_TIME is not set
-CONFIG_PRISM54=m
-CONFIG_PROC_FS=y
-CONFIG_PROC_KCORE=y
-CONFIG_PROC_SYSCTL=y
-# CONFIG_PROFILING is not set
-# CONFIG_QEMU is not set
-# CONFIG_QLA3XXX is not set
-# CONFIG_QNX4FS_FS is not set
-# CONFIG_QUOTA is not set
-# CONFIG_R3964 is not set
-# CONFIG_R8169 is not set
-# CONFIG_RADIO_AZTECH is not set
-# CONFIG_RADIO_CADET is not set
-# CONFIG_RADIO_GEMTEK is not set
-# CONFIG_RADIO_GEMTEK_PCI is not set
-# CONFIG_RADIO_MAESTRO is not set
-# CONFIG_RADIO_MAXIRADIO is not set
-# CONFIG_RADIO_RTRACK is not set
-# CONFIG_RADIO_RTRACK2 is not set
-# CONFIG_RADIO_SF16FMI is not set
-# CONFIG_RADIO_SF16FMR2 is not set
-# CONFIG_RADIO_TERRATEC is not set
-# CONFIG_RADIO_TRUST is not set
-# CONFIG_RADIO_TYPHOON is not set
-# CONFIG_RADIO_ZOLTRIX is not set
-# CONFIG_RAID_ATTRS is not set
-CONFIG_RAMFS=y
-# CONFIG_RAW_DRIVER is not set
-# CONFIG_REISERFS_CHECK is not set
-# CONFIG_REISERFS_FS is not set
-# CONFIG_REISERFS_FS_XATTR is not set
-# CONFIG_REISERFS_PROC_INFO is not set
-# CONFIG_RELAY is not set
-# CONFIG_RESOURCES_64BIT is not set
-# CONFIG_RFD_FTL is not set
-# CONFIG_ROMFS_FS is not set
-# CONFIG_ROSE is not set
-CONFIG_RPCSEC_GSS_KRB5=m
-# CONFIG_RPCSEC_GSS_SPKM3 is not set
-# CONFIG_RTC_CLASS is not set
-CONFIG_RTC_DRV_CMOS=y
-CONFIG_RT_MUTEXES=y
-# CONFIG_S2IO is not set
-# CONFIG_SATA_INIC162X is not set
-# CONFIG_SATA_MV is not set
-# CONFIG_SATA_NV is not set
-# CONFIG_SATA_PROMISE is not set
-# CONFIG_SATA_QSTOR is not set
-# CONFIG_SATA_SIL is not set
-# CONFIG_SATA_SIL24 is not set
-# CONFIG_SATA_SIS is not set
-# CONFIG_SATA_SVW is not set
-# CONFIG_SATA_SX4 is not set
-# CONFIG_SATA_ULI is not set
-# CONFIG_SATA_VIA is not set
-# CONFIG_SATA_VITESSE is not set
-# CONFIG_SC92031 is not set
-CONFIG_SCSI=m
-# CONFIG_SCSI_3W_9XXX is not set
-# CONFIG_SCSI_7000FASST is not set
-# CONFIG_SCSI_AACRAID is not set
-# CONFIG_SCSI_ACARD is not set
-# CONFIG_SCSI_ADVANSYS is not set
-# CONFIG_SCSI_AHA152X is not set
-# CONFIG_SCSI_AHA1542 is not set
-# CONFIG_SCSI_AIC79XX is not set
-# CONFIG_SCSI_AIC7XXX is not set
-# CONFIG_SCSI_AIC7XXX_OLD is not set
-# CONFIG_SCSI_AIC94XX is not set
-# CONFIG_SCSI_ARCMSR is not set
-# CONFIG_SCSI_BUSLOGIC is not set
-# CONFIG_SCSI_CONSTANTS is not set
-# CONFIG_SCSI_DC390T is not set
-# CONFIG_SCSI_DC395x is not set
-# CONFIG_SCSI_DEBUG is not set
-# CONFIG_SCSI_DMX3191D is not set
-# CONFIG_SCSI_DPT_I2O is not set
-# CONFIG_SCSI_DTC3280 is not set
-# CONFIG_SCSI_EATA is not set
-# CONFIG_SCSI_FC_ATTRS is not set
-# CONFIG_SCSI_FUTURE_DOMAIN is not set
-# CONFIG_SCSI_GDTH is not set
-# CONFIG_SCSI_GENERIC_NCR5380 is not set
-# CONFIG_SCSI_GENERIC_NCR5380_MMIO is not set
-# CONFIG_SCSI_HPTIOP is not set
-# CONFIG_SCSI_IN2000 is not set
-# CONFIG_SCSI_INIA100 is not set
-# CONFIG_SCSI_INITIO is not set
-# CONFIG_SCSI_IPR is not set
-# CONFIG_SCSI_IPS is not set
-# CONFIG_SCSI_ISCSI_ATTRS is not set
-# CONFIG_SCSI_LOGGING is not set
-# CONFIG_SCSI_LPFC is not set
-CONFIG_SCSI_MULTI_LUN=y
-# CONFIG_SCSI_NCR53C406A is not set
-# CONFIG_SCSI_NETLINK is not set
-# CONFIG_SCSI_NSP32 is not set
-# CONFIG_SCSI_PAS16 is not set
-CONFIG_SCSI_PROC_FS=y
-# CONFIG_SCSI_PSI240I is not set
-# CONFIG_SCSI_QLA_FC is not set
-# CONFIG_SCSI_QLA_ISCSI is not set
-# CONFIG_SCSI_QLOGIC_1280 is not set
-# CONFIG_SCSI_QLOGIC_FAS is not set
-# CONFIG_SCSI_SAS_ATTRS is not set
-# CONFIG_SCSI_SAS_LIBSAS is not set
-# CONFIG_SCSI_SCAN_ASYNC is not set
-# CONFIG_SCSI_SEAGATE is not set
-# CONFIG_SCSI_SPI_ATTRS is not set
-# CONFIG_SCSI_SRP is not set
-# CONFIG_SCSI_STEX is not set
-# CONFIG_SCSI_SYM53C416 is not set
-# CONFIG_SCSI_SYM53C8XX_2 is not set
-# CONFIG_SCSI_T128 is not set
-# CONFIG_SCSI_TGT is not set
-# CONFIG_SCSI_U14_34F is not set
-# CONFIG_SCSI_ULTRASTOR is not set
-# CONFIG_SECURITY is not set
-CONFIG_SELECT_MEMORY_MODEL=y
-# CONFIG_SENSORS_ABITUGURU is not set
-# CONFIG_SENSORS_ADM1021 is not set
-# CONFIG_SENSORS_ADM1025 is not set
-# CONFIG_SENSORS_ADM1026 is not set
-# CONFIG_SENSORS_ADM1029 is not set
-# CONFIG_SENSORS_ADM1031 is not set
-# CONFIG_SENSORS_ADM9240 is not set
-# CONFIG_SENSORS_ASB100 is not set
-# CONFIG_SENSORS_ATXP1 is not set
-# CONFIG_SENSORS_DS1337 is not set
-# CONFIG_SENSORS_DS1374 is not set
-# CONFIG_SENSORS_DS1621 is not set
-# CONFIG_SENSORS_EEPROM is not set
-# CONFIG_SENSORS_F71805F is not set
-# CONFIG_SENSORS_FSCHER is not set
-# CONFIG_SENSORS_FSCPOS is not set
-# CONFIG_SENSORS_GL518SM is not set
-# CONFIG_SENSORS_GL520SM is not set
-# CONFIG_SENSORS_HDAPS is not set
-# CONFIG_SENSORS_IT87 is not set
-# CONFIG_SENSORS_K8TEMP is not set
-# CONFIG_SENSORS_LM63 is not set
-# CONFIG_SENSORS_LM75 is not set
-# CONFIG_SENSORS_LM77 is not set
-# CONFIG_SENSORS_LM78 is not set
-# CONFIG_SENSORS_LM80 is not set
-# CONFIG_SENSORS_LM83 is not set
-# CONFIG_SENSORS_LM85 is not set
-# CONFIG_SENSORS_LM87 is not set
-# CONFIG_SENSORS_LM90 is not set
-# CONFIG_SENSORS_LM92 is not set
-# CONFIG_SENSORS_MAX1619 is not set
-# CONFIG_SENSORS_MAX6875 is not set
-# CONFIG_SENSORS_PC87427 is not set
-# CONFIG_SENSORS_PCA9539 is not set
-# CONFIG_SENSORS_PCF8574 is not set
-# CONFIG_SENSORS_PCF8591 is not set
-# CONFIG_SENSORS_SIS5595 is not set
-# CONFIG_SENSORS_SMSC47B397 is not set
-# CONFIG_SENSORS_SMSC47M1 is not set
-# CONFIG_SENSORS_SMSC47M192 is not set
-# CONFIG_SENSORS_VIA686A is not set
-# CONFIG_SENSORS_VT1211 is not set
-# CONFIG_SENSORS_VT8231 is not set
-# CONFIG_SENSORS_W83627EHF is not set
-# CONFIG_SENSORS_W83627HF is not set
-# CONFIG_SENSORS_W83781D is not set
-# CONFIG_SENSORS_W83791D is not set
-# CONFIG_SENSORS_W83792D is not set
-# CONFIG_SENSORS_W83793 is not set
-# CONFIG_SENSORS_W83L785TS is not set
-CONFIG_SERIAL_8250=y
-CONFIG_SERIAL_8250_CONSOLE=y
-CONFIG_SERIAL_8250_CS=m
-CONFIG_SERIAL_8250_NR_UARTS=2
-# CONFIG_SERIAL_8250_PCI is not set
-CONFIG_SERIAL_8250_RUNTIME_UARTS=2
-CONFIG_SERIAL_CORE=y
-CONFIG_SERIAL_CORE_CONSOLE=y
-# CONFIG_SERIAL_JSM is not set
-# CONFIG_SERIAL_NONSTANDARD is not set
-# CONFIG_SERIAL_UARTLITE is not set
-# CONFIG_SERIO is not set
-# CONFIG_SGI_IOC4 is not set
-# CONFIG_SGI_PARTITION is not set
-# CONFIG_SHAPER is not set
-CONFIG_SHMEM=y
-# CONFIG_SIS190 is not set
-# CONFIG_SIS900 is not set
-# CONFIG_SK98LIN is not set
-# CONFIG_SKGE is not set
-# CONFIG_SKY2 is not set
-CONFIG_SLAB=y
-CONFIG_SLHC=m
-# CONFIG_SLIP is not set
-# CONFIG_SLOB is not set
-# CONFIG_SMB_FS is not set
-# CONFIG_SMB_NLS_DEFAULT is not set
-CONFIG_SND=m
-# CONFIG_SND_AC97_POWER_SAVE is not set
-# CONFIG_SND_AD1816A is not set
-# CONFIG_SND_AD1848 is not set
-# CONFIG_SND_AD1889 is not set
-# CONFIG_SND_ADLIB is not set
-# CONFIG_SND_ALI5451 is not set
-# CONFIG_SND_ALS100 is not set
-# CONFIG_SND_ALS300 is not set
-# CONFIG_SND_ALS4000 is not set
-# CONFIG_SND_ATIIXP is not set
-# CONFIG_SND_ATIIXP_MODEM is not set
-# CONFIG_SND_AU8810 is not set
-# CONFIG_SND_AU8820 is not set
-# CONFIG_SND_AU8830 is not set
-# CONFIG_SND_AZT2320 is not set
-# CONFIG_SND_AZT3328 is not set
-# CONFIG_SND_BT87X is not set
-# CONFIG_SND_CA0106 is not set
-# CONFIG_SND_CMI8330 is not set
-# CONFIG_SND_CMIPCI is not set
-# CONFIG_SND_CS4231 is not set
-# CONFIG_SND_CS4232 is not set
-# CONFIG_SND_CS4236 is not set
-# CONFIG_SND_CS4281 is not set
-# CONFIG_SND_CS46XX is not set
-# CONFIG_SND_CS5535AUDIO is not set
-# CONFIG_SND_DARLA20 is not set
-# CONFIG_SND_DARLA24 is not set
-# CONFIG_SND_DEBUG is not set
-# CONFIG_SND_DT019X is not set
-# CONFIG_SND_DUMMY is not set
-# CONFIG_SND_DYNAMIC_MINORS is not set
-# CONFIG_SND_ECHO3G is not set
-# CONFIG_SND_EMU10K1 is not set
-# CONFIG_SND_EMU10K1X is not set
-# CONFIG_SND_ENS1370 is not set
-# CONFIG_SND_ENS1371 is not set
-# CONFIG_SND_ES1688 is not set
-# CONFIG_SND_ES18XX is not set
-# CONFIG_SND_ES1938 is not set
-# CONFIG_SND_ES1968 is not set
-# CONFIG_SND_ES968 is not set
-# CONFIG_SND_FM801 is not set
-# CONFIG_SND_GINA20 is not set
-# CONFIG_SND_GINA24 is not set
-# CONFIG_SND_GUSCLASSIC is not set
-# CONFIG_SND_GUSEXTREME is not set
-# CONFIG_SND_GUSMAX is not set
-# CONFIG_SND_HDA_INTEL is not set
-# CONFIG_SND_HDSP is not set
-# CONFIG_SND_HDSPM is not set
-CONFIG_SND_HWDEP=m
-# CONFIG_SND_ICE1712 is not set
-# CONFIG_SND_ICE1724 is not set
-# CONFIG_SND_INDIGO is not set
-# CONFIG_SND_INDIGODJ is not set
-# CONFIG_SND_INDIGOIO is not set
-# CONFIG_SND_INTEL8X0 is not set
-# CONFIG_SND_INTEL8X0M is not set
-# CONFIG_SND_INTERWAVE is not set
-# CONFIG_SND_INTERWAVE_STB is not set
-# CONFIG_SND_KORG1212 is not set
-# CONFIG_SND_LAYLA20 is not set
-# CONFIG_SND_LAYLA24 is not set
-# CONFIG_SND_MAESTRO3 is not set
-# CONFIG_SND_MIA is not set
-# CONFIG_SND_MIRO is not set
-# CONFIG_SND_MIXART is not set
-CONFIG_SND_MIXER_OSS=m
-# CONFIG_SND_MONA is not set
-# CONFIG_SND_MPU401 is not set
-# CONFIG_SND_MTPAV is not set
-# CONFIG_SND_NM256 is not set
-# CONFIG_SND_OPL3SA2 is not set
-# CONFIG_SND_OPTI92X_AD1848 is not set
-# CONFIG_SND_OPTI92X_CS4231 is not set
-# CONFIG_SND_OPTI93X is not set
-CONFIG_SND_OSSEMUL=y
-CONFIG_SND_PCM=m
-CONFIG_SND_PCM_OSS=m
-CONFIG_SND_PCM_OSS_PLUGINS=y
-# CONFIG_SND_PCXHR is not set
-# CONFIG_SND_PDAUDIOCF is not set
-CONFIG_SND_RAWMIDI=m
-# CONFIG_SND_RIPTIDE is not set
-# CONFIG_SND_RME32 is not set
-# CONFIG_SND_RME96 is not set
-# CONFIG_SND_RME9652 is not set
-# CONFIG_SND_RTCTIMER is not set
-# CONFIG_SND_SB16 is not set
-# CONFIG_SND_SB8 is not set
-# CONFIG_SND_SBAWE is not set
-# CONFIG_SND_SEQUENCER is not set
-# CONFIG_SND_SERIAL_U16550 is not set
-# CONFIG_SND_SGALAXY is not set
-# CONFIG_SND_SOC is not set
-# CONFIG_SND_SONICVIBES is not set
-# CONFIG_SND_SSCAPE is not set
-# CONFIG_SND_SUPPORT_OLD_API is not set
-CONFIG_SND_TIMER=m
-# CONFIG_SND_TRIDENT is not set
-CONFIG_SND_USB_AUDIO=m
-# CONFIG_SND_USB_USX2Y is not set
-# CONFIG_SND_VERBOSE_PRINTK is not set
-CONFIG_SND_VERBOSE_PROCFS=y
-# CONFIG_SND_VIA82XX is not set
-# CONFIG_SND_VIA82XX_MODEM is not set
-# CONFIG_SND_VX222 is not set
-# CONFIG_SND_VXPOCKET is not set
-# CONFIG_SND_WAVEFRONT is not set
-# CONFIG_SND_YMFPCI is not set
-# CONFIG_SNI_RM is not set
-# CONFIG_SOLARIS_X86_PARTITION is not set
-CONFIG_SOUND=m
-# CONFIG_SOUND_PRIME is not set
-# CONFIG_SPARSEMEM_MANUAL is not set
-# CONFIG_SPI is not set
-# CONFIG_SPI_MASTER is not set
-CONFIG_SPLIT_PTLOCK_CPUS=4
-CONFIG_SQUASHFS=y
-# CONFIG_SQUASHFS_EMBEDDED is not set
-CONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE=3
-# CONFIG_SQUASHFS_VMALLOC is not set
-# CONFIG_SSFDC is not set
-CONFIG_STACKTRACE_SUPPORT=y
-CONFIG_STANDALONE=y
-# CONFIG_STRIP is not set
-# CONFIG_SUNDANCE is not set
-# CONFIG_SUNGEM is not set
-CONFIG_SUNRPC=m
-CONFIG_SUNRPC_GSS=m
-# CONFIG_SUN_PARTITION is not set
-CONFIG_SWAP=y
-# CONFIG_SYNCLINK_CS is not set
-CONFIG_SYN_COOKIES=y
-CONFIG_SYSCTL=y
-CONFIG_SYSCTL_SYSCALL=y
-CONFIG_SYSFS=y
-# CONFIG_SYSFS_DEPRECATED is not set
-CONFIG_SYSVIPC=y
-# CONFIG_SYSV_FS is not set
-# CONFIG_SYS_HYPERVISOR is not set
-# CONFIG_TASKSTATS is not set
-# CONFIG_TCG_TPM is not set
-CONFIG_TCP_CONG_ADVANCED=y
-CONFIG_TCP_CONG_BIC=m
-CONFIG_TCP_CONG_CUBIC=m
-CONFIG_TCP_CONG_HSTCP=m
-CONFIG_TCP_CONG_HTCP=m
-CONFIG_TCP_CONG_HYBLA=m
-CONFIG_TCP_CONG_LP=m
-CONFIG_TCP_CONG_SCALABLE=m
-CONFIG_TCP_CONG_VEGAS=y
-CONFIG_TCP_CONG_VENO=m
-CONFIG_TCP_CONG_WESTWOOD=m
-# CONFIG_TCP_MD5SIG is not set
-CONFIG_TEXTSEARCH=y
-CONFIG_TEXTSEARCH_BM=m
-CONFIG_TEXTSEARCH_FSM=m
-CONFIG_TEXTSEARCH_KMP=m
-# CONFIG_TIFM_CORE is not set
-# CONFIG_TIGON3 is not set
-# CONFIG_TINY_SHMEM is not set
-# CONFIG_TIPC is not set
-# CONFIG_TLAN is not set
-CONFIG_TMD_HERMES=m
-CONFIG_TMPFS=y
-# CONFIG_TMPFS_POSIX_ACL is not set
-# CONFIG_TR is not set
-CONFIG_TRACE_IRQFLAGS_SUPPORT=y
-CONFIG_TUN=m
-# CONFIG_TUNER_3036 is not set
-CONFIG_UDF_FS=m
-CONFIG_UDF_NLS=y
-# CONFIG_UFS_FS is not set
-# CONFIG_ULTRIX_PARTITION is not set
-CONFIG_UNIX=y
-CONFIG_UNIX98_PTYS=y
-# CONFIG_UNIXWARE_DISKLABEL is not set
-CONFIG_USB=m
-# CONFIG_USB_ACECAD is not set
-CONFIG_USB_ACM=m
-# CONFIG_USB_ADUTUX is not set
-# CONFIG_USB_AIPTEK is not set
-CONFIG_USB_ALI_M5632=y
-CONFIG_USB_AN2720=y
-# CONFIG_USB_APPLEDISPLAY is not set
-# CONFIG_USB_APPLETOUCH is not set
-CONFIG_USB_ARCH_HAS_EHCI=y
-CONFIG_USB_ARCH_HAS_HCD=y
-CONFIG_USB_ARCH_HAS_OHCI=y
-CONFIG_USB_ARMLINUX=y
-# CONFIG_USB_ATI_REMOTE is not set
-# CONFIG_USB_ATI_REMOTE2 is not set
-CONFIG_USB_ATM=m
-# CONFIG_USB_AUERSWALD is not set
-# CONFIG_USB_BANDWIDTH is not set
-CONFIG_USB_BELKIN=y
-# CONFIG_USB_BERRY_CHARGE is not set
-CONFIG_USB_CATC=m
-# CONFIG_USB_CXACRU is not set
-# CONFIG_USB_CYPRESS_CY7C63 is not set
-# CONFIG_USB_CYTHERM is not set
-# CONFIG_USB_DABUSB is not set
-# CONFIG_USB_DEBUG is not set
-CONFIG_USB_DEVICEFS=y
-# CONFIG_USB_DSBR is not set
-# CONFIG_USB_DYNAMIC_MINORS is not set
-# CONFIG_USB_EMI26 is not set
-# CONFIG_USB_EMI62 is not set
-# CONFIG_USB_EPSON2888 is not set
-# CONFIG_USB_ET61X251 is not set
-CONFIG_USB_EZUSB=y
-# CONFIG_USB_FTDI_ELAN is not set
-# CONFIG_USB_GADGET is not set
-CONFIG_USB_HID=m
-# CONFIG_USB_HIDDEV is not set
-CONFIG_USB_HIDINPUT=y
-# CONFIG_USB_HIDINPUT_POWERBOOK is not set
-# CONFIG_USB_IBMCAM is not set
-# CONFIG_USB_IDMOUSE is not set
-# CONFIG_USB_IOWARRIOR is not set
-# CONFIG_USB_ISP116X_HCD is not set
-CONFIG_USB_KAWETH=m
-# CONFIG_USB_KBD is not set
-# CONFIG_USB_KBTAB is not set
-# CONFIG_USB_KC2190 is not set
-# CONFIG_USB_KEYSPAN_REMOTE is not set
-# CONFIG_USB_KONICAWC is not set
-# CONFIG_USB_LCD is not set
-# CONFIG_USB_LD is not set
-# CONFIG_USB_LED is not set
-# CONFIG_USB_LEGOTOWER is not set
-# CONFIG_USB_LIBUSUAL is not set
-# CONFIG_USB_MDC800 is not set
-# CONFIG_USB_MICROTEK is not set
-# CONFIG_USB_MON is not set
-# CONFIG_USB_MOUSE is not set
-CONFIG_USB_NET_AX8817X=m
-CONFIG_USB_NET_CDCETHER=m
-CONFIG_USB_NET_CDC_SUBSET=m
-CONFIG_USB_NET_DM9601=m
-CONFIG_USB_NET_GL620A=m
-CONFIG_USB_NET_MCS7830=m
-CONFIG_USB_NET_NET1080=m
-CONFIG_USB_NET_PLUSB=m
-CONFIG_USB_NET_RNDIS_HOST=m
-CONFIG_USB_NET_ZAURUS=m
-# CONFIG_USB_OHCI_BIG_ENDIAN is not set
-# CONFIG_USB_OHCI_HCD is not set
-CONFIG_USB_OHCI_LITTLE_ENDIAN=y
-# CONFIG_USB_OTG is not set
-# CONFIG_USB_OV511 is not set
-CONFIG_USB_PEGASUS=m
-# CONFIG_USB_PHIDGET is not set
-# CONFIG_USB_POWERMATE is not set
-CONFIG_USB_PRINTER=m
-# CONFIG_USB_QUICKCAM_MESSENGER is not set
-# CONFIG_USB_RIO500 is not set
-# CONFIG_USB_RTL8150 is not set
-# CONFIG_USB_SE401 is not set
-CONFIG_USB_SERIAL=m
-CONFIG_USB_SERIAL_AIRCABLE=m
-CONFIG_USB_SERIAL_AIRPRIME=m
-CONFIG_USB_SERIAL_ARK3116=m
-CONFIG_USB_SERIAL_BELKIN=m
-CONFIG_USB_SERIAL_CP2101=m
-CONFIG_USB_SERIAL_CYBERJACK=m
-CONFIG_USB_SERIAL_CYPRESS_M8=m
-# CONFIG_USB_SERIAL_DEBUG is not set
-CONFIG_USB_SERIAL_DIGI_ACCELEPORT=m
-CONFIG_USB_SERIAL_EDGEPORT=m
-CONFIG_USB_SERIAL_EDGEPORT_TI=m
-CONFIG_USB_SERIAL_EMPEG=m
-CONFIG_USB_SERIAL_FTDI_SIO=m
-CONFIG_USB_SERIAL_FUNSOFT=m
-CONFIG_USB_SERIAL_GARMIN=m
-CONFIG_USB_SERIAL_GENERIC=y
-CONFIG_USB_SERIAL_HP4X=m
-CONFIG_USB_SERIAL_IPAQ=m
-CONFIG_USB_SERIAL_IPW=m
-CONFIG_USB_SERIAL_IR=m
-CONFIG_USB_SERIAL_KEYSPAN=m
-CONFIG_USB_SERIAL_KEYSPAN_MPR=y
-CONFIG_USB_SERIAL_KEYSPAN_PDA=m
-CONFIG_USB_SERIAL_KEYSPAN_USA18X=y
-CONFIG_USB_SERIAL_KEYSPAN_USA19=y
-CONFIG_USB_SERIAL_KEYSPAN_USA19QI=y
-CONFIG_USB_SERIAL_KEYSPAN_USA19QW=y
-CONFIG_USB_SERIAL_KEYSPAN_USA19W=y
-CONFIG_USB_SERIAL_KEYSPAN_USA28=y
-CONFIG_USB_SERIAL_KEYSPAN_USA28X=y
-CONFIG_USB_SERIAL_KEYSPAN_USA28XA=y
-CONFIG_USB_SERIAL_KEYSPAN_USA28XB=y
-CONFIG_USB_SERIAL_KEYSPAN_USA49W=y
-CONFIG_USB_SERIAL_KEYSPAN_USA49WLC=y
-CONFIG_USB_SERIAL_KLSI=m
-CONFIG_USB_SERIAL_KOBIL_SCT=m
-CONFIG_USB_SERIAL_MCT_U232=m
-CONFIG_USB_SERIAL_MOS7720=m
-CONFIG_USB_SERIAL_MOS7840=m
-CONFIG_USB_SERIAL_NAVMAN=m
-CONFIG_USB_SERIAL_OMNINET=m
-CONFIG_USB_SERIAL_OPTION=m
-CONFIG_USB_SERIAL_PL2303=m
-CONFIG_USB_SERIAL_SAFE=m
-CONFIG_USB_SERIAL_SAFE_PADDED=y
-CONFIG_USB_SERIAL_SIERRAWIRELESS=m
-CONFIG_USB_SERIAL_TI=m
-CONFIG_USB_SERIAL_VISOR=m
-CONFIG_USB_SERIAL_WHITEHEAT=m
-CONFIG_USB_SERIAL_XIRCOM=m
-# CONFIG_USB_SISUSBVGA is not set
-# CONFIG_USB_SL811_HCD is not set
-# CONFIG_USB_SN9C102 is not set
-CONFIG_USB_SPEEDTOUCH=m
-CONFIG_USB_STORAGE=m
-CONFIG_USB_STORAGE_ALAUDA=y
-CONFIG_USB_STORAGE_DATAFAB=y
-# CONFIG_USB_STORAGE_DEBUG is not set
-CONFIG_USB_STORAGE_DPCM=y
-CONFIG_USB_STORAGE_FREECOM=y
-# CONFIG_USB_STORAGE_ISD200 is not set
-CONFIG_USB_STORAGE_JUMPSHOT=y
-CONFIG_USB_STORAGE_KARMA=y
-# CONFIG_USB_STORAGE_ONETOUCH is not set
-CONFIG_USB_STORAGE_SDDR09=y
-CONFIG_USB_STORAGE_SDDR55=y
-CONFIG_USB_STORAGE_USBAT=y
-# CONFIG_USB_STV680 is not set
-# CONFIG_USB_TEST is not set
-# CONFIG_USB_TOUCHSCREEN is not set
-# CONFIG_USB_TRANCEVIBRATOR is not set
-CONFIG_USB_UEAGLEATM=m
-CONFIG_USB_USBNET=m
-CONFIG_USB_USBNET_MII=m
-# CONFIG_USB_VICAM is not set
-# CONFIG_USB_W9968CF is not set
-# CONFIG_USB_WACOM is not set
-# CONFIG_USB_XPAD is not set
-# CONFIG_USB_XUSBATM is not set
-CONFIG_USB_YEALINK=m
-# CONFIG_USB_ZC0301 is not set
-# CONFIG_USB_ZD1201 is not set
-# CONFIG_USB_ZR364XX is not set
-# CONFIG_UTS_NS is not set
-CONFIG_VFAT_FS=m
-# CONFIG_VIA_VELOCITY is not set
-# CONFIG_VIDEO_ADV7170 is not set
-# CONFIG_VIDEO_ADV7175 is not set
-# CONFIG_VIDEO_ADV_DEBUG is not set
-# CONFIG_VIDEO_BT819 is not set
-# CONFIG_VIDEO_BT848 is not set
-# CONFIG_VIDEO_BT856 is not set
-# CONFIG_VIDEO_BT866 is not set
-# CONFIG_VIDEO_CAFE_CCIC is not set
-# CONFIG_VIDEO_CPIA is not set
-# CONFIG_VIDEO_CS53L32A is not set
-# CONFIG_VIDEO_CX2341X is not set
-# CONFIG_VIDEO_CX25840 is not set
-# CONFIG_VIDEO_CX88 is not set
-CONFIG_VIDEO_DEV=m
-# CONFIG_VIDEO_DPC is not set
-# CONFIG_VIDEO_EM28XX is not set
-# CONFIG_VIDEO_HELPER_CHIPS_AUTO is not set
-# CONFIG_VIDEO_HEXIUM_GEMINI is not set
-# CONFIG_VIDEO_HEXIUM_ORION is not set
-# CONFIG_VIDEO_IVTV is not set
-# CONFIG_VIDEO_KS0127 is not set
-# CONFIG_VIDEO_MSP3400 is not set
-# CONFIG_VIDEO_MXB is not set
-# CONFIG_VIDEO_OV7670 is not set
-# CONFIG_VIDEO_OVCAMCHIP is not set
-# CONFIG_VIDEO_PMS is not set
-# CONFIG_VIDEO_PVRUSB2 is not set
-# CONFIG_VIDEO_SAA5246A is not set
-# CONFIG_VIDEO_SAA5249 is not set
-# CONFIG_VIDEO_SAA7110 is not set
-# CONFIG_VIDEO_SAA7111 is not set
-# CONFIG_VIDEO_SAA7114 is not set
-# CONFIG_VIDEO_SAA711X is not set
-# CONFIG_VIDEO_SAA7127 is not set
-# CONFIG_VIDEO_SAA7134 is not set
-# CONFIG_VIDEO_SAA7185 is not set
-# CONFIG_VIDEO_SAA7191 is not set
-# CONFIG_VIDEO_STRADIS is not set
-# CONFIG_VIDEO_TDA7432 is not set
-# CONFIG_VIDEO_TDA9840 is not set
-# CONFIG_VIDEO_TDA9875 is not set
-# CONFIG_VIDEO_TEA6415C is not set
-# CONFIG_VIDEO_TEA6420 is not set
-# CONFIG_VIDEO_TLV320AIC23B is not set
-# CONFIG_VIDEO_TVAUDIO is not set
-# CONFIG_VIDEO_TVP5150 is not set
-# CONFIG_VIDEO_UPD64031A is not set
-# CONFIG_VIDEO_UPD64083 is not set
-# CONFIG_VIDEO_USBVISION is not set
-# CONFIG_VIDEO_V4L1 is not set
-CONFIG_VIDEO_V4L1_COMPAT=y
-CONFIG_VIDEO_V4L2=y
-# CONFIG_VIDEO_VIVI is not set
-# CONFIG_VIDEO_VPX3220 is not set
-# CONFIG_VIDEO_WM8739 is not set
-# CONFIG_VIDEO_WM8775 is not set
-# CONFIG_VIDEO_ZORAN is not set
-# CONFIG_VITESSE_PHY is not set
-CONFIG_VLAN_8021Q=y
-# CONFIG_VM_EVENT_COUNTERS is not set
-# CONFIG_VT is not set
-# CONFIG_VXFS_FS is not set
-# CONFIG_W1 is not set
-# CONFIG_WAN is not set
-# CONFIG_WAN_ROUTER is not set
-CONFIG_WATCHDOG=y
-# CONFIG_WATCHDOG_NOWAYOUT is not set
-# CONFIG_WDTPCI is not set
-CONFIG_WIRELESS_EXT=y
-# CONFIG_WR_PPMC is not set
-# CONFIG_X25 is not set
-CONFIG_XFRM=y
-# CONFIG_XFRM_MIGRATE is not set
-# CONFIG_XFRM_SUB_POLICY is not set
-CONFIG_XFRM_USER=m
-CONFIG_XFS_FS=m
-# CONFIG_XFS_POSIX_ACL is not set
-# CONFIG_XFS_QUOTA is not set
-# CONFIG_XFS_RT is not set
-# CONFIG_XFS_SECURITY is not set
-# CONFIG_YAFFS_FS is not set
-# CONFIG_YAM is not set
-# CONFIG_YELLOWFIN is not set
-CONFIG_YENTA=m
-# CONFIG_YENTA_O2 is not set
-# CONFIG_YENTA_RICOH is not set
-# CONFIG_YENTA_TI is not set
-# CONFIG_YENTA_TOSHIBA is not set
-CONFIG_ZD1211RW=m
-# CONFIG_ZD1211RW_DEBUG is not set
-CONFIG_ZISOFS=y
-CONFIG_ZISOFS_FS=m
-CONFIG_ZLIB_DEFLATE=y
-CONFIG_ZLIB_INFLATE=y
-CONFIG_ZONE_DMA=y
-CONFIG_ZONE_DMA_FLAG=1
+++ /dev/null
-# CONFIG_6PACK is not set
-# CONFIG_8139CP is not set
-# CONFIG_9P_FS is not set
-# CONFIG_ACENIC is not set
-# CONFIG_ACORN_PARTITION is not set
-# CONFIG_ADAPTEC_STARFIRE is not set
-# CONFIG_ADFS_FS is not set
-# CONFIG_ADM6996_PHY is not set
-# CONFIG_AFFS_FS is not set
-# CONFIG_AFS_FS is not set
-# CONFIG_AF_RXRPC is not set
-CONFIG_AIRO=m
-CONFIG_AIRO_CS=m
-# CONFIG_AMD8111_ETH is not set
-# CONFIG_AMIGA_PARTITION is not set
-CONFIG_ANON_INODES=y
-# CONFIG_APPLICOM is not set
-CONFIG_ARCH_FLATMEM_ENABLE=y
-# CONFIG_ARCNET is not set
-CONFIG_ARPD=y
-CONFIG_ASK_IP_FIB_HASH=y
-# CONFIG_ATA is not set
-# CONFIG_ATALK is not set
-# CONFIG_ATARI_PARTITION is not set
-# CONFIG_ATA_GENERIC is not set
-# CONFIG_ATA_OVER_ETH is not set
-# CONFIG_ATL1 is not set
-CONFIG_ATM=m
-CONFIG_ATMEL=m
-# CONFIG_ATM_AMBASSADOR is not set
-CONFIG_ATM_BR2684=m
-CONFIG_ATM_BR2684_IPFILTER=y
-CONFIG_ATM_CLIP=m
-CONFIG_ATM_CLIP_NO_ICMP=y
-# CONFIG_ATM_DRIVERS is not set
-CONFIG_ATM_DUMMY=m
-# CONFIG_ATM_ENI is not set
-# CONFIG_ATM_FIRESTREAM is not set
-# CONFIG_ATM_FORE200E_MAYBE is not set
-# CONFIG_ATM_HE is not set
-# CONFIG_ATM_HORIZON is not set
-# CONFIG_ATM_IA is not set
-# CONFIG_ATM_IDT77252 is not set
-# CONFIG_ATM_LANAI is not set
-CONFIG_ATM_LANE=m
-CONFIG_ATM_MPOA=m
-# CONFIG_ATM_NICSTAR is not set
-CONFIG_ATM_TCP=m
-# CONFIG_ATM_ZATM is not set
-# CONFIG_AUDIT is not set
-# CONFIG_AUTOFS4_FS is not set
-# CONFIG_AUTOFS_FS is not set
-CONFIG_AX25=m
-# CONFIG_AX25_DAMA_SLAVE is not set
-# CONFIG_AX88796 is not set
-# CONFIG_B44 is not set
-# CONFIG_BACKLIGHT_LCD_SUPPORT is not set
-CONFIG_BASE_FULL=y
-# CONFIG_BASLER_EXCITE is not set
-# CONFIG_BAYCOM_EPP is not set
-# CONFIG_BAYCOM_PAR is not set
-# CONFIG_BAYCOM_SER_FDX is not set
-# CONFIG_BAYCOM_SER_HDX is not set
-CONFIG_BCM43XX=m
-CONFIG_BCM43XX_DEBUG=y
-CONFIG_BCM43XX_DMA=y
-CONFIG_BCM43XX_DMA_AND_PIO_MODE=y
-# CONFIG_BCM43XX_DMA_MODE is not set
-CONFIG_BCM43XX_PIO=y
-# CONFIG_BCM43XX_PIO_MODE is not set
-# CONFIG_BEFS_FS is not set
-# CONFIG_BFS_FS is not set
-CONFIG_BINFMT_ELF=y
-# CONFIG_BINFMT_MISC is not set
-# CONFIG_BLINK is not set
-# CONFIG_BLK_CPQ_CISS_DA is not set
-# CONFIG_BLK_CPQ_DA is not set
-CONFIG_BLK_DEV=y
-# CONFIG_BLK_DEV_3W_XXXX_RAID is not set
-# CONFIG_BLK_DEV_AEC62XX is not set
-# CONFIG_BLK_DEV_ALI15X3 is not set
-# CONFIG_BLK_DEV_AMD74XX is not set
-# CONFIG_BLK_DEV_ATIIXP is not set
-# CONFIG_BLK_DEV_BSG is not set
-# CONFIG_BLK_DEV_CMD640 is not set
-# CONFIG_BLK_DEV_CMD64X is not set
-# CONFIG_BLK_DEV_COW_COMMON is not set
-CONFIG_BLK_DEV_CRYPTOLOOP=m
-# CONFIG_BLK_DEV_CS5520 is not set
-# CONFIG_BLK_DEV_CS5530 is not set
-# CONFIG_BLK_DEV_CS5535 is not set
-# CONFIG_BLK_DEV_CY82C693 is not set
-# CONFIG_BLK_DEV_DAC960 is not set
-# CONFIG_BLK_DEV_DELKIN is not set
-# CONFIG_BLK_DEV_FD is not set
-# CONFIG_BLK_DEV_GENERIC is not set
-# CONFIG_BLK_DEV_HD is not set
-# CONFIG_BLK_DEV_HD_IDE is not set
-# CONFIG_BLK_DEV_HPT34X is not set
-# CONFIG_BLK_DEV_HPT366 is not set
-# CONFIG_BLK_DEV_IDECD is not set
-# CONFIG_BLK_DEV_IDECS is not set
-# CONFIG_BLK_DEV_IDEDMA_FORCED is not set
-# CONFIG_BLK_DEV_IDEFLOPPY is not set
-# CONFIG_BLK_DEV_IDEPCI is not set
-# CONFIG_BLK_DEV_IDEPNP is not set
-# CONFIG_BLK_DEV_IDESCSI is not set
-# CONFIG_BLK_DEV_IDETAPE is not set
-# CONFIG_BLK_DEV_IDE_SATA is not set
-CONFIG_BLK_DEV_INITRD=y
-# CONFIG_BLK_DEV_IO_TRACE is not set
-# CONFIG_BLK_DEV_IT8213 is not set
-# CONFIG_BLK_DEV_IT821X is not set
-# CONFIG_BLK_DEV_JMICRON is not set
-CONFIG_BLK_DEV_LOOP=m
-CONFIG_BLK_DEV_NBD=m
-# CONFIG_BLK_DEV_NS87415 is not set
-# CONFIG_BLK_DEV_OFFBOARD is not set
-# CONFIG_BLK_DEV_OPTI621 is not set
-# CONFIG_BLK_DEV_PDC202XX_NEW is not set
-# CONFIG_BLK_DEV_PDC202XX_OLD is not set
-# CONFIG_BLK_DEV_PIIX is not set
-# CONFIG_BLK_DEV_RAM is not set
-# CONFIG_BLK_DEV_RZ1000 is not set
-# CONFIG_BLK_DEV_SC1200 is not set
-CONFIG_BLK_DEV_SD=m
-# CONFIG_BLK_DEV_SIIMAGE is not set
-# CONFIG_BLK_DEV_SIS5513 is not set
-# CONFIG_BLK_DEV_SL82C105 is not set
-# CONFIG_BLK_DEV_SLC90E66 is not set
-# CONFIG_BLK_DEV_SR is not set
-# CONFIG_BLK_DEV_SVWKS is not set
-# CONFIG_BLK_DEV_SX8 is not set
-# CONFIG_BLK_DEV_TC86C001 is not set
-# CONFIG_BLK_DEV_TRIFLEX is not set
-# CONFIG_BLK_DEV_TRM290 is not set
-# CONFIG_BLK_DEV_UB is not set
-# CONFIG_BLK_DEV_UMEM is not set
-# CONFIG_BLK_DEV_VIA82CXXX is not set
-CONFIG_BLOCK=y
-# CONFIG_BNX2 is not set
-CONFIG_BONDING=m
-# CONFIG_BPQETHER is not set
-CONFIG_BRIDGE=y
-CONFIG_BRIDGE_EBT_802_3=m
-CONFIG_BRIDGE_EBT_AMONG=m
-CONFIG_BRIDGE_EBT_ARP=m
-CONFIG_BRIDGE_EBT_ARPREPLY=m
-CONFIG_BRIDGE_EBT_BROUTE=m
-CONFIG_BRIDGE_EBT_DNAT=m
-CONFIG_BRIDGE_EBT_IP=m
-CONFIG_BRIDGE_EBT_LIMIT=m
-CONFIG_BRIDGE_EBT_LOG=m
-CONFIG_BRIDGE_EBT_MARK=m
-CONFIG_BRIDGE_EBT_MARK_T=m
-CONFIG_BRIDGE_EBT_NFLOG=m
-CONFIG_BRIDGE_EBT_PKTTYPE=m
-CONFIG_BRIDGE_EBT_REDIRECT=m
-CONFIG_BRIDGE_EBT_SNAT=m
-CONFIG_BRIDGE_EBT_STP=m
-CONFIG_BRIDGE_EBT_T_FILTER=m
-CONFIG_BRIDGE_EBT_T_NAT=m
-CONFIG_BRIDGE_EBT_ULOG=m
-CONFIG_BRIDGE_EBT_VLAN=m
-# CONFIG_BRIDGE_NETFILTER is not set
-CONFIG_BRIDGE_NF_EBTABLES=m
-CONFIG_BROKEN_ON_SMP=y
-CONFIG_BSD_DISKLABEL=y
-CONFIG_BSD_PROCESS_ACCT=y
-# CONFIG_BSD_PROCESS_ACCT_V3 is not set
-CONFIG_BT=m
-CONFIG_BT_BNEP=m
-CONFIG_BT_BNEP_MC_FILTER=y
-CONFIG_BT_BNEP_PROTO_FILTER=y
-# CONFIG_BT_CMTP is not set
-CONFIG_BT_HCIBCM203X=m
-CONFIG_BT_HCIBFUSB=m
-# CONFIG_BT_HCIBLUECARD is not set
-CONFIG_BT_HCIBPA10X=m
-# CONFIG_BT_HCIBT3C is not set
-# CONFIG_BT_HCIBTUART is not set
-# CONFIG_BT_HCIDTL1 is not set
-CONFIG_BT_HCIUART=m
-CONFIG_BT_HCIUART_BCSP=y
-CONFIG_BT_HCIUART_H4=y
-CONFIG_BT_HCIUSB=m
-CONFIG_BT_HCIUSB_SCO=y
-CONFIG_BT_HCIVHCI=m
-CONFIG_BT_HIDP=m
-CONFIG_BT_L2CAP=m
-CONFIG_BT_RFCOMM=m
-CONFIG_BT_RFCOMM_TTY=y
-CONFIG_BT_SCO=m
-CONFIG_BUG=y
-# CONFIG_CAPI_AVM is not set
-# CONFIG_CAPI_EICON is not set
-# CONFIG_CAPI_TRACE is not set
-CONFIG_CARDBUS=y
-# CONFIG_CARDMAN_4000 is not set
-# CONFIG_CARDMAN_4040 is not set
-# CONFIG_CASSINI is not set
-CONFIG_CC_OPTIMIZE_FOR_SIZE=y
-# CONFIG_CDROM_PKTCDVD is not set
-# CONFIG_CFG80211 is not set
-# CONFIG_CHELSIO_T1 is not set
-# CONFIG_CHELSIO_T3 is not set
-# CONFIG_CHR_DEV_OSST is not set
-# CONFIG_CHR_DEV_SCH is not set
-# CONFIG_CHR_DEV_SG is not set
-# CONFIG_CHR_DEV_ST is not set
-# CONFIG_CICADA_PHY is not set
-CONFIG_CIFS=m
-# CONFIG_CIFS_DEBUG2 is not set
-# CONFIG_CIFS_EXPERIMENTAL is not set
-CONFIG_CIFS_POSIX=y
-CONFIG_CIFS_STATS=y
-# CONFIG_CIFS_STATS2 is not set
-# CONFIG_CIFS_WEAK_PW_HASH is not set
-# CONFIG_CIFS_XATTR is not set
-CONFIG_CLS_U32_MARK=y
-CONFIG_CLS_U32_PERF=y
-CONFIG_CMDLINE=""
-# CONFIG_CODA_FS is not set
-CONFIG_CONFIGFS_FS=y
-# CONFIG_CONNECTOR is not set
-# CONFIG_CRAMFS is not set
-CONFIG_CRC16=m
-CONFIG_CRC32=y
-# CONFIG_CRC7 is not set
-CONFIG_CRC_CCITT=m
-CONFIG_CRC_ITU_T=m
-CONFIG_CROSSCOMPILE=y
-CONFIG_CRYPTO=y
-CONFIG_CRYPTO_AES=m
-CONFIG_CRYPTO_ALGAPI=m
-CONFIG_CRYPTO_ANUBIS=m
-CONFIG_CRYPTO_ARC4=m
-CONFIG_CRYPTO_BLKCIPHER=m
-CONFIG_CRYPTO_BLOWFISH=m
-CONFIG_CRYPTO_CAMELLIA=m
-CONFIG_CRYPTO_CAST5=m
-CONFIG_CRYPTO_CAST6=m
-CONFIG_CRYPTO_CBC=m
-CONFIG_CRYPTO_CRC32C=m
-# CONFIG_CRYPTO_CRYPTD is not set
-CONFIG_CRYPTO_DEFLATE=m
-CONFIG_CRYPTO_DES=m
-CONFIG_CRYPTO_ECB=m
-# CONFIG_CRYPTO_FCRYPT is not set
-# CONFIG_CRYPTO_GF128MUL is not set
-CONFIG_CRYPTO_HASH=m
-CONFIG_CRYPTO_HMAC=m
-# CONFIG_CRYPTO_HW is not set
-CONFIG_CRYPTO_KHAZAD=m
-# CONFIG_CRYPTO_LRW is not set
-CONFIG_CRYPTO_MANAGER=m
-CONFIG_CRYPTO_MD4=m
-CONFIG_CRYPTO_MD5=m
-CONFIG_CRYPTO_MICHAEL_MIC=m
-CONFIG_CRYPTO_NULL=m
-# CONFIG_CRYPTO_PCBC is not set
-CONFIG_CRYPTO_SERPENT=m
-CONFIG_CRYPTO_SHA1=m
-CONFIG_CRYPTO_SHA256=m
-CONFIG_CRYPTO_SHA512=m
-CONFIG_CRYPTO_TEA=m
-CONFIG_CRYPTO_TEST=m
-CONFIG_CRYPTO_TGR192=m
-CONFIG_CRYPTO_TWOFISH=m
-CONFIG_CRYPTO_TWOFISH_COMMON=m
-CONFIG_CRYPTO_WP512=m
-# CONFIG_CRYPTO_XCBC is not set
-# CONFIG_DAB is not set
-# CONFIG_DAVICOM_PHY is not set
-# CONFIG_DEBUG_FS is not set
-# CONFIG_DEBUG_KERNEL is not set
-# CONFIG_DECNET is not set
-# CONFIG_DEFAULT_AS is not set
-# CONFIG_DEFAULT_BIC is not set
-# CONFIG_DEFAULT_CFQ is not set
-# CONFIG_DEFAULT_CUBIC is not set
-CONFIG_DEFAULT_DEADLINE=y
-# CONFIG_DEFAULT_HTCP is not set
-CONFIG_DEFAULT_IOSCHED="deadline"
-# CONFIG_DEFAULT_NOOP is not set
-# CONFIG_DEFAULT_RENO is not set
-CONFIG_DEFAULT_TCP_CONG="vegas"
-CONFIG_DEFAULT_VEGAS=y
-# CONFIG_DEFAULT_WESTWOOD is not set
-CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
-# CONFIG_DEVFS_DEBUG is not set
-CONFIG_DEVFS_FS=y
-CONFIG_DEVFS_MOUNT=y
-# CONFIG_DGRS is not set
-# CONFIG_DISCONTIGMEM_MANUAL is not set
-# CONFIG_DISPLAY_SUPPORT is not set
-# CONFIG_DL2K is not set
-# CONFIG_DLM is not set
-# CONFIG_DMA_ENGINE is not set
-# CONFIG_DNOTIFY is not set
-# CONFIG_DRM is not set
-# CONFIG_DS1682 is not set
-# CONFIG_DTLK is not set
-# CONFIG_DUMMY is not set
-# CONFIG_DVB is not set
-# CONFIG_DVB_CORE is not set
-CONFIG_E100=m
-# CONFIG_E1000 is not set
-# CONFIG_ECONET is not set
-# CONFIG_EEPRO100 is not set
-CONFIG_EEPROM_93CX6=m
-# CONFIG_EFI_PARTITION is not set
-# CONFIG_EFS_FS is not set
-# CONFIG_ELF_CORE is not set
-CONFIG_EMBEDDED=y
-# CONFIG_ENABLE_MUST_CHECK is not set
-# CONFIG_EPIC100 is not set
-CONFIG_EPOLL=y
-# CONFIG_EQUALIZER is not set
-CONFIG_EVENTFD=y
-CONFIG_EXPERIMENTAL=y
-CONFIG_EXPORTFS=m
-CONFIG_EXT2_FS=m
-# CONFIG_EXT2_FS_XATTR is not set
-# CONFIG_EXT2_FS_XIP is not set
-CONFIG_EXT3_FS=m
-# CONFIG_EXT3_FS_XATTR is not set
-# CONFIG_EXT4DEV_FS is not set
-CONFIG_FAT_DEFAULT_CODEPAGE=437
-CONFIG_FAT_DEFAULT_IOCHARSET="iso8859-1"
-CONFIG_FAT_FS=m
-# CONFIG_FB is not set
-# CONFIG_FB_IBM_GXT4500 is not set
-# CONFIG_FDDI is not set
-# CONFIG_FEALNX is not set
-CONFIG_FIB_RULES=y
-# CONFIG_FIREWIRE is not set
-CONFIG_FLATMEM=y
-CONFIG_FLATMEM_MANUAL=y
-CONFIG_FLAT_NODE_MEM_MAP=y
-# CONFIG_FORCEDETH is not set
-# CONFIG_FS_POSIX_ACL is not set
-# CONFIG_FTL is not set
-# CONFIG_FUSE_FS is not set
-# CONFIG_FUSION is not set
-# CONFIG_FUSION_FC is not set
-# CONFIG_FUSION_SAS is not set
-# CONFIG_FUSION_SPI is not set
-CONFIG_FUTEX=y
-CONFIG_FW_LOADER=y
-CONFIG_GACT_PROB=y
-# CONFIG_GAMEPORT is not set
-CONFIG_GENERIC_CALIBRATE_DELAY=y
-CONFIG_GENERIC_HARDIRQS=y
-CONFIG_GENERIC_HWEIGHT=y
-CONFIG_GENERIC_IRQ_PROBE=y
-CONFIG_GENERIC_TIME=y
-# CONFIG_GFS2_FS is not set
-CONFIG_GPIO_DEVICE=m
-# CONFIG_HAMACHI is not set
-CONFIG_HAMRADIO=y
-# CONFIG_HAPPYMEAL is not set
-# CONFIG_HEADERS_CHECK is not set
-CONFIG_HERMES=m
-CONFIG_HFSPLUS_FS=m
-CONFIG_HFS_FS=m
-# CONFIG_HID is not set
-# CONFIG_HID_DEBUG is not set
-# CONFIG_HID_FF is not set
-# CONFIG_HID_SUPPORT is not set
-CONFIG_HIGH_RES_TIMERS=y
-# CONFIG_HIPPI is not set
-CONFIG_HOSTAP=m
-# CONFIG_HOSTAP_CS is not set
-CONFIG_HOSTAP_FIRMWARE=y
-CONFIG_HOSTAP_FIRMWARE_NVRAM=y
-CONFIG_HOSTAP_PCI=m
-CONFIG_HOSTAP_PLX=m
-CONFIG_HOTPLUG=y
-# CONFIG_HOTPLUG_CPU is not set
-# CONFIG_HOTPLUG_PCI is not set
-# CONFIG_HP100 is not set
-# CONFIG_HPFS_FS is not set
-# CONFIG_HUGETLB_PAGE is not set
-# CONFIG_HWMON is not set
-# CONFIG_HWMON_VID is not set
-CONFIG_HZ=100
-CONFIG_HZ_100=y
-# CONFIG_HZ_1000 is not set
-# CONFIG_HZ_1024 is not set
-# CONFIG_HZ_128 is not set
-# CONFIG_HZ_250 is not set
-# CONFIG_HZ_256 is not set
-# CONFIG_HZ_300 is not set
-# CONFIG_HZ_48 is not set
-# CONFIG_I2C_ALGOPCA is not set
-# CONFIG_I2C_ALGOPCF is not set
-# CONFIG_I2C_ALI1535 is not set
-# CONFIG_I2C_ALI1563 is not set
-# CONFIG_I2C_ALI15X3 is not set
-# CONFIG_I2C_AMD756 is not set
-# CONFIG_I2C_AMD8111 is not set
-# CONFIG_I2C_CHARDEV is not set
-# CONFIG_I2C_DEBUG_ALGO is not set
-# CONFIG_I2C_DEBUG_BUS is not set
-# CONFIG_I2C_DEBUG_CHIP is not set
-# CONFIG_I2C_DEBUG_CORE is not set
-# CONFIG_I2C_ELEKTOR is not set
-# CONFIG_I2C_GPIO is not set
-# CONFIG_I2C_I801 is not set
-# CONFIG_I2C_I810 is not set
-# CONFIG_I2C_NFORCE2 is not set
-# CONFIG_I2C_OCORES is not set
-# CONFIG_I2C_PARPORT_LIGHT is not set
-# CONFIG_I2C_PCA_ISA is not set
-# CONFIG_I2C_PIIX4 is not set
-# CONFIG_I2C_PROSAVAGE is not set
-# CONFIG_I2C_SAVAGE4 is not set
-# CONFIG_I2C_SIMTEC is not set
-# CONFIG_I2C_SIS5595 is not set
-# CONFIG_I2C_SIS630 is not set
-# CONFIG_I2C_SIS96X is not set
-# CONFIG_I2C_STUB is not set
-# CONFIG_I2C_TAOS_EVM is not set
-# CONFIG_I2C_TINY_USB is not set
-# CONFIG_I2C_VIA is not set
-# CONFIG_I2C_VIAPRO is not set
-# CONFIG_I2C_VOODOO3 is not set
-# CONFIG_I2O is not set
-# CONFIG_I82092 is not set
-# CONFIG_ICPLUS_PHY is not set
-# CONFIG_IDEDISK_MULTI_MODE is not set
-# CONFIG_IDEDMA_IVB is not set
-# CONFIG_IDEDMA_ONLYDISK is not set
-# CONFIG_IDEPCI_SHARE_IRQ is not set
-CONFIG_IDE_MAX_HWIFS=4
-CONFIG_IDE_PROC_FS=y
-# CONFIG_IDE_TASK_IOCTL is not set
-# CONFIG_IEEE1394 is not set
-CONFIG_IEEE80211=m
-CONFIG_IEEE80211_CRYPT_CCMP=m
-CONFIG_IEEE80211_CRYPT_TKIP=m
-CONFIG_IEEE80211_CRYPT_WEP=m
-# CONFIG_IEEE80211_DEBUG is not set
-CONFIG_IEEE80211_SOFTMAC=m
-# CONFIG_IEEE80211_SOFTMAC_DEBUG is not set
-CONFIG_IFB=m
-CONFIG_IKCONFIG=y
-CONFIG_IKCONFIG_PROC=y
-CONFIG_IMQ=m
-# CONFIG_IMQ_BEHAVIOR_AA is not set
-# CONFIG_IMQ_BEHAVIOR_AB is not set
-CONFIG_IMQ_BEHAVIOR_BA=y
-# CONFIG_IMQ_BEHAVIOR_BB is not set
-CONFIG_IMQ_NUM_DEVS=2
-CONFIG_INET=y
-CONFIG_INET6_AH=m
-CONFIG_INET6_ESP=m
-CONFIG_INET6_IPCOMP=m
-CONFIG_INET6_TUNNEL=m
-CONFIG_INET6_XFRM_MODE_BEET=m
-# CONFIG_INET6_XFRM_MODE_ROUTEOPTIMIZATION is not set
-CONFIG_INET6_XFRM_MODE_TRANSPORT=m
-CONFIG_INET6_XFRM_MODE_TUNNEL=m
-CONFIG_INET6_XFRM_TUNNEL=m
-CONFIG_INET_AH=m
-CONFIG_INET_DIAG=m
-CONFIG_INET_ESP=m
-CONFIG_INET_IPCOMP=m
-CONFIG_INET_TCP_DIAG=m
-CONFIG_INET_TUNNEL=m
-CONFIG_INET_XFRM_MODE_BEET=m
-CONFIG_INET_XFRM_MODE_TRANSPORT=m
-CONFIG_INET_XFRM_MODE_TUNNEL=m
-CONFIG_INET_XFRM_TUNNEL=m
-# CONFIG_INFINIBAND is not set
-# CONFIG_INFTL is not set
-CONFIG_INIT_ENV_ARG_LIMIT=32
-# CONFIG_INOTIFY is not set
-# CONFIG_INOTIFY_USER is not set
-# CONFIG_INPUT is not set
-# CONFIG_INPUT_ATI_REMOTE is not set
-# CONFIG_INPUT_ATI_REMOTE2 is not set
-# CONFIG_INPUT_EVBUG is not set
-CONFIG_INPUT_EVDEV=m
-# CONFIG_INPUT_FF_MEMLESS is not set
-# CONFIG_INPUT_JOYDEV is not set
-# CONFIG_INPUT_JOYSTICK is not set
-# CONFIG_INPUT_KEYBOARD is not set
-# CONFIG_INPUT_KEYSPAN_REMOTE is not set
-# CONFIG_INPUT_MISC is not set
-# CONFIG_INPUT_MOUSE is not set
-# CONFIG_INPUT_MOUSEDEV is not set
-# CONFIG_INPUT_PCSPKR is not set
-# CONFIG_INPUT_POLLDEV is not set
-# CONFIG_INPUT_POWERMATE is not set
-# CONFIG_INPUT_TABLET is not set
-# CONFIG_INPUT_TOUCHSCREEN is not set
-# CONFIG_INPUT_TSDEV is not set
-# CONFIG_INPUT_UINPUT is not set
-# CONFIG_INPUT_WISTRON_BTNS is not set
-# CONFIG_IOSCHED_AS is not set
-# CONFIG_IOSCHED_CFQ is not set
-CONFIG_IOSCHED_DEADLINE=y
-CONFIG_IOSCHED_NOOP=y
-CONFIG_IP6_NF_FILTER=m
-CONFIG_IP6_NF_IPTABLES=m
-CONFIG_IP6_NF_MANGLE=m
-CONFIG_IP6_NF_MATCH_AH=m
-CONFIG_IP6_NF_MATCH_EUI64=m
-CONFIG_IP6_NF_MATCH_FRAG=m
-CONFIG_IP6_NF_MATCH_HL=m
-CONFIG_IP6_NF_MATCH_IPV6HEADER=m
-CONFIG_IP6_NF_MATCH_LIMIT=m
-CONFIG_IP6_NF_MATCH_MH=m
-CONFIG_IP6_NF_MATCH_OPTS=m
-CONFIG_IP6_NF_MATCH_OWNER=m
-CONFIG_IP6_NF_MATCH_RT=m
-CONFIG_IP6_NF_QUEUE=m
-CONFIG_IP6_NF_RAW=m
-CONFIG_IP6_NF_TARGET_HL=m
-CONFIG_IP6_NF_TARGET_IMQ=m
-CONFIG_IP6_NF_TARGET_LOG=m
-CONFIG_IP6_NF_TARGET_REJECT=m
-CONFIG_IP6_NF_TARGET_ROUTE=m
-# CONFIG_IPC_NS is not set
-# CONFIG_IPMI_HANDLER is not set
-CONFIG_IPSEC_NAT_TRAVERSAL=y
-CONFIG_IPV6=m
-# CONFIG_IPV6_MIP6 is not set
-# CONFIG_IPV6_MROUTE is not set
-# CONFIG_IPV6_MULTIPLE_TABLES is not set
-# CONFIG_IPV6_OPTIMISTIC_DAD is not set
-# CONFIG_IPV6_PRIVACY is not set
-CONFIG_IPV6_ROUTER_PREF=y
-# CONFIG_IPV6_ROUTE_INFO is not set
-CONFIG_IPV6_SIT=m
-# CONFIG_IPV6_TUNNEL is not set
-CONFIG_IPW2100=m
-# CONFIG_IPW2100_DEBUG is not set
-CONFIG_IPW2100_MONITOR=y
-CONFIG_IPW2200=m
-# CONFIG_IPW2200_DEBUG is not set
-CONFIG_IPW2200_MONITOR=y
-# CONFIG_IPW2200_PROMISCUOUS is not set
-# CONFIG_IPW2200_QOS is not set
-# CONFIG_IPW2200_RADIOTAP is not set
-# CONFIG_IPX is not set
-CONFIG_IP_ADVANCED_ROUTER=y
-# CONFIG_IP_DCCP is not set
-CONFIG_IP_FIB_HASH=y
-# CONFIG_IP_FIB_TRIE is not set
-# CONFIG_IP_MROUTE is not set
-CONFIG_IP_MULTICAST=y
-CONFIG_IP_MULTIPLE_TABLES=y
-CONFIG_IP_NF_AMANDA=m
-CONFIG_IP_NF_ARPFILTER=m
-CONFIG_IP_NF_ARPTABLES=m
-CONFIG_IP_NF_ARP_MANGLE=m
-CONFIG_IP_NF_CONNTRACK=y
-# CONFIG_IP_NF_CONNTRACK_EVENTS is not set
-CONFIG_IP_NF_CONNTRACK_MARK=y
-CONFIG_IP_NF_CT_ACCT=y
-CONFIG_IP_NF_CT_PROTO_SCTP=m
-CONFIG_IP_NF_FILTER=m
-CONFIG_IP_NF_FTP=m
-CONFIG_IP_NF_H323=m
-CONFIG_IP_NF_IPTABLES=m
-CONFIG_IP_NF_IRC=m
-CONFIG_IP_NF_MANGLE=m
-CONFIG_IP_NF_MATCH_ADDRTYPE=m
-CONFIG_IP_NF_MATCH_AH=m
-CONFIG_IP_NF_MATCH_ECN=m
-CONFIG_IP_NF_MATCH_HASHLIMIT=m
-CONFIG_IP_NF_MATCH_IPP2P=m
-CONFIG_IP_NF_MATCH_IPRANGE=m
-CONFIG_NETFILTER_XT_MATCH_LAYER7=m
-# CONFIG_NETFILTER_XT_MATCH_LAYER7_DEBUG is not set
-CONFIG_IP_NF_MATCH_OWNER=m
-CONFIG_IP_NF_MATCH_RECENT=m
-CONFIG_IP_NF_MATCH_SET=m
-CONFIG_IP_NF_MATCH_TIME=m
-CONFIG_IP_NF_MATCH_TOS=m
-CONFIG_IP_NF_MATCH_TTL=m
-CONFIG_IP_NF_NAT=y
-CONFIG_IP_NF_NAT_AMANDA=m
-CONFIG_IP_NF_NAT_FTP=m
-CONFIG_IP_NF_NAT_H323=m
-CONFIG_IP_NF_NAT_IRC=m
-CONFIG_IP_NF_NAT_NEEDED=y
-CONFIG_IP_NF_NAT_PPTP=m
-CONFIG_IP_NF_NAT_SIP=m
-# CONFIG_IP_NF_NAT_SNMP_BASIC is not set
-CONFIG_IP_NF_NAT_TFTP=m
-# CONFIG_IP_NF_NETBIOS_NS is not set
-CONFIG_IP_NF_PPTP=m
-CONFIG_IP_NF_QUEUE=m
-CONFIG_IP_NF_RAW=m
-CONFIG_IP_NF_SET=m
-CONFIG_IP_NF_SET_HASHSIZE=1024
-CONFIG_IP_NF_SET_IPHASH=m
-CONFIG_IP_NF_SET_IPMAP=m
-CONFIG_IP_NF_SET_IPPORTHASH=m
-CONFIG_IP_NF_SET_IPTREE=m
-CONFIG_IP_NF_SET_IPTREEMAP=m
-CONFIG_IP_NF_SET_MACIPMAP=m
-CONFIG_IP_NF_SET_MAX=256
-CONFIG_IP_NF_SET_NETHASH=m
-CONFIG_IP_NF_SET_PORTMAP=m
-CONFIG_IP_NF_SIP=m
-# CONFIG_IP_NF_TARGET_CLUSTERIP is not set
-CONFIG_IP_NF_TARGET_ECN=m
-CONFIG_IP_NF_TARGET_IMQ=m
-CONFIG_IP_NF_TARGET_LOG=m
-CONFIG_IP_NF_TARGET_MASQUERADE=m
-CONFIG_IP_NF_TARGET_NETMAP=m
-CONFIG_IP_NF_TARGET_REDIRECT=m
-CONFIG_IP_NF_TARGET_REJECT=m
-CONFIG_IP_NF_TARGET_ROUTE=m
-CONFIG_IP_NF_TARGET_SAME=m
-CONFIG_IP_NF_TARGET_SET=m
-CONFIG_IP_NF_TARGET_TOS=m
-CONFIG_IP_NF_TARGET_TTL=m
-CONFIG_IP_NF_TARGET_ULOG=m
-CONFIG_IP_NF_TFTP=m
-# CONFIG_IP_PNP is not set
-CONFIG_IP_ROUTE_FWMARK=y
-CONFIG_IP_ROUTE_MULTIPATH=y
-CONFIG_IP_ROUTE_MULTIPATH_CACHED=y
-CONFIG_IP_ROUTE_MULTIPATH_DRR=m
-CONFIG_IP_ROUTE_MULTIPATH_RANDOM=m
-CONFIG_IP_ROUTE_MULTIPATH_RR=m
-CONFIG_IP_ROUTE_MULTIPATH_WRANDOM=m
-CONFIG_IP_ROUTE_VERBOSE=y
-# CONFIG_IP_SCTP is not set
-# CONFIG_IP_VS is not set
-# CONFIG_IRDA is not set
-# CONFIG_ISCSI_TCP is not set
-CONFIG_ISDN=m
-CONFIG_ISDN_CAPI=m
-CONFIG_ISDN_CAPI_CAPI20=m
-CONFIG_ISDN_CAPI_CAPIFS=m
-CONFIG_ISDN_CAPI_CAPIFS_BOOL=y
-CONFIG_ISDN_CAPI_MIDDLEWARE=y
-# CONFIG_ISDN_DRV_AVMB1_VERBOSE_REASON is not set
-# CONFIG_ISDN_I4L is not set
-CONFIG_ISO9660_FS=m
-# CONFIG_IXGB is not set
-CONFIG_JBD=m
-# CONFIG_JBD_DEBUG is not set
-# CONFIG_JFFS2_CMODE_NONE is not set
-CONFIG_JFFS2_CMODE_PRIORITY=y
-# CONFIG_JFFS2_CMODE_SIZE is not set
-CONFIG_JFFS2_COMPRESSION_OPTIONS=y
-CONFIG_JFFS2_FS=y
-CONFIG_JFFS2_FS_DEBUG=0
-CONFIG_JFFS2_FS_WRITEBUFFER=y
-# CONFIG_JFFS2_FS_XATTR is not set
-CONFIG_JFFS2_RTIME=y
-# CONFIG_JFFS2_RUBIN is not set
-CONFIG_JFFS2_SUMMARY=y
-CONFIG_JFFS2_ZLIB=y
-# CONFIG_JFFS_FS is not set
-# CONFIG_JFS_DEBUG is not set
-# CONFIG_JFS_FS is not set
-# CONFIG_JFS_POSIX_ACL is not set
-# CONFIG_JFS_SECURITY is not set
-# CONFIG_JFS_STATISTICS is not set
-CONFIG_JOLIET=y
-# CONFIG_KALLSYMS is not set
-# CONFIG_KALLSYMS_EXTRA_PASS is not set
-# CONFIG_KARMA_PARTITION is not set
-# CONFIG_KEXEC is not set
-# CONFIG_KEYS is not set
-# CONFIG_KMOD is not set
-# CONFIG_LAPB is not set
-# CONFIG_LASAT is not set
-# CONFIG_LBD is not set
-# CONFIG_LDM_PARTITION is not set
-CONFIG_LEDS_CLASS=y
-CONFIG_LEDS_TRIGGERS=y
-CONFIG_LEDS_TRIGGER_HEARTBEAT=y
-# CONFIG_LEDS_TRIGGER_IDE_DISK is not set
-# CONFIG_LEDS_TRIGGER_MORSE is not set
-CONFIG_LEDS_TRIGGER_TIMER=y
-# CONFIG_LEDS_TRIGGER_DEFAULT_ON is not set
-# CONFIG_LEDS_TRIGGER_NETDEV is not set
-# CONFIG_LEGACY_PTYS is not set
-CONFIG_LIBCRC32C=m
-# CONFIG_LIBERTAS is not set
-# CONFIG_LIBERTAS_USB is not set
-CONFIG_LLC=y
-CONFIG_LLC2=m
-CONFIG_LOCALVERSION=""
-# CONFIG_LOCALVERSION_AUTO is not set
-CONFIG_LOCKD=m
-CONFIG_LOCKDEP_SUPPORT=y
-CONFIG_LOCKD_V4=y
-CONFIG_LOG_BUF_SHIFT=14
-# CONFIG_LSF is not set
-# CONFIG_LXT_PHY is not set
-# CONFIG_MAC80211 is not set
-# CONFIG_MAC80211_DEBUG is not set
-# CONFIG_MAC80211_LEDS is not set
-# CONFIG_MACVLAN is not set
-# CONFIG_MAC_EMUMOUSEBTN is not set
-CONFIG_MAC_PARTITION=y
-# CONFIG_MAGIC_SYSRQ is not set
-# CONFIG_MARKEINS is not set
-# CONFIG_MARVELL_PHY is not set
-# CONFIG_MD is not set
-# CONFIG_MEGARAID_LEGACY is not set
-# CONFIG_MEGARAID_NEWGEN is not set
-# CONFIG_MEGARAID_SAS is not set
-# CONFIG_MFD_SM501 is not set
-CONFIG_MII=y
-CONFIG_MINIX_FS=m
-# CONFIG_MINIX_SUBPARTITION is not set
-CONFIG_MINI_FO=y
-CONFIG_MISC_DEVICES=y
-CONFIG_MKISS=m
-# CONFIG_MMC is not set
-CONFIG_MMU=y
-CONFIG_MODULES=y
-# CONFIG_MODULE_FORCE_UNLOAD is not set
-# CONFIG_MODULE_SRCVERSION_ALL is not set
-CONFIG_MODULE_UNLOAD=y
-# CONFIG_MODVERSIONS is not set
-# CONFIG_MOUSE_APPLETOUCH is not set
-# CONFIG_MOUSE_INPORT is not set
-# CONFIG_MOUSE_LOGIBM is not set
-# CONFIG_MOUSE_PC110PAD is not set
-CONFIG_MSDOS_FS=m
-CONFIG_MSDOS_PARTITION=y
-# CONFIG_MTD_DATAFLASH is not set
-# CONFIG_MTD_M25P80 is not set
-# CONFIG_MTD_NAND is not set
-# CONFIG_MTD_REDBOOT_PARTS_UNALLOCATED is not set
-CONFIG_MTD_ROOTFS_ROOT_DEV=y
-CONFIG_MTD_ROOTFS_SPLIT=y
-# CONFIG_MTD_UBI is not set
-# CONFIG_MVSWITCH_PHY is not set
-# CONFIG_MWAVE is not set
-# CONFIG_MYRI10GE is not set
-# CONFIG_NCP_FS is not set
-CONFIG_NET=y
-# CONFIG_NETCONSOLE is not set
-# CONFIG_NETDEBUG is not set
-CONFIG_NETDEVICES=y
-# CONFIG_NETDEVICES_MULTIQUEUE is not set
-# CONFIG_NETDEV_1000 is not set
-# CONFIG_NETDEV_10000 is not set
-CONFIG_NETFILTER=y
-# CONFIG_NETFILTER_DEBUG is not set
-# CONFIG_NETFILTER_NETLINK is not set
-CONFIG_NETFILTER_XTABLES=m
-CONFIG_NETFILTER_XT_MATCH_COMMENT=m
-CONFIG_NETFILTER_XT_MATCH_CONNBYTES=m
-CONFIG_NETFILTER_XT_MATCH_CONNLIMIT=m
-CONFIG_NETFILTER_XT_MATCH_CONNMARK=m
-CONFIG_NETFILTER_XT_MATCH_CONNTRACK=m
-CONFIG_NETFILTER_XT_MATCH_DCCP=m
-CONFIG_NETFILTER_XT_MATCH_DSCP=m
-CONFIG_NETFILTER_XT_MATCH_ESP=m
-CONFIG_NETFILTER_XT_MATCH_HASHLIMIT=m
-CONFIG_NETFILTER_XT_MATCH_HELPER=m
-CONFIG_NETFILTER_XT_MATCH_LENGTH=m
-CONFIG_NETFILTER_XT_MATCH_LIMIT=m
-CONFIG_NETFILTER_XT_MATCH_MAC=m
-CONFIG_NETFILTER_XT_MATCH_MARK=m
-CONFIG_NETFILTER_XT_MATCH_MULTIPORT=m
-CONFIG_NETFILTER_XT_MATCH_PHYSDEV=m
-CONFIG_NETFILTER_XT_MATCH_PKTTYPE=m
-CONFIG_NETFILTER_XT_MATCH_POLICY=m
-CONFIG_NETFILTER_XT_MATCH_PORTSCAN=m
-# CONFIG_NETFILTER_XT_MATCH_QUOTA is not set
-CONFIG_NETFILTER_XT_MATCH_REALM=m
-CONFIG_NETFILTER_XT_MATCH_SCTP=m
-CONFIG_NETFILTER_XT_MATCH_STATE=m
-# CONFIG_NETFILTER_XT_MATCH_STATISTIC is not set
-CONFIG_NETFILTER_XT_MATCH_STRING=m
-CONFIG_NETFILTER_XT_MATCH_TCPMSS=m
-CONFIG_NETFILTER_XT_MATCH_U32=m
-CONFIG_NETFILTER_XT_TARGET_CHAOS=m
-CONFIG_NETFILTER_XT_TARGET_CLASSIFY=m
-CONFIG_NETFILTER_XT_TARGET_CONNMARK=m
-CONFIG_NETFILTER_XT_TARGET_DELUDE=m
-CONFIG_NETFILTER_XT_TARGET_DSCP=m
-CONFIG_NETFILTER_XT_TARGET_MARK=m
-CONFIG_NETFILTER_XT_TARGET_NFLOG=m
-CONFIG_NETFILTER_XT_TARGET_NFQUEUE=m
-CONFIG_NETFILTER_XT_TARGET_NOTRACK=m
-CONFIG_NETFILTER_XT_TARGET_TARPIT=m
-CONFIG_NETFILTER_XT_TARGET_TCPMSS=m
-CONFIG_NETFILTER_XT_TARGET_TRACE=m
-# CONFIG_NETPOLL is not set
-# CONFIG_NETROM is not set
-# CONFIG_NETWORK_SECMARK is not set
-# CONFIG_NETXEN_NIC is not set
-# CONFIG_NET_9P is not set
-CONFIG_NET_ACT_GACT=m
-CONFIG_NET_ACT_IPT=m
-CONFIG_NET_ACT_MIRRED=m
-CONFIG_NET_ACT_PEDIT=m
-CONFIG_NET_ACT_POLICE=y
-# CONFIG_NET_ACT_SIMP is not set
-CONFIG_NET_CLS=y
-CONFIG_NET_CLS_ACT=y
-CONFIG_NET_CLS_BASIC=m
-CONFIG_NET_CLS_FW=m
-CONFIG_NET_CLS_IND=y
-CONFIG_NET_CLS_POLICE=y
-CONFIG_NET_CLS_ROUTE=y
-CONFIG_NET_CLS_ROUTE4=m
-CONFIG_NET_CLS_RSVP=m
-CONFIG_NET_CLS_RSVP6=m
-CONFIG_NET_CLS_TCINDEX=m
-CONFIG_NET_CLS_U32=m
-CONFIG_NET_EMATCH=y
-CONFIG_NET_EMATCH_CMP=m
-CONFIG_NET_EMATCH_META=m
-CONFIG_NET_EMATCH_NBYTE=m
-CONFIG_NET_EMATCH_STACK=32
-CONFIG_NET_EMATCH_TEXT=m
-CONFIG_NET_EMATCH_U32=m
-CONFIG_NET_ESTIMATOR=y
-CONFIG_NET_ETHERNET=y
-# CONFIG_NET_FC is not set
-CONFIG_NET_IPGRE=m
-CONFIG_NET_IPGRE_BROADCAST=y
-CONFIG_NET_IPIP=m
-# CONFIG_NET_ISA is not set
-CONFIG_NET_KEY=m
-# CONFIG_NET_KEY_MIGRATE is not set
-CONFIG_NET_PCI=y
-# CONFIG_NET_PCMCIA is not set
-CONFIG_NET_PKTGEN=m
-# CONFIG_NET_POLL_CONTROLLER is not set
-CONFIG_NET_RADIO=y
-# CONFIG_NET_SB1000 is not set
-CONFIG_NET_SCHED=y
-CONFIG_NET_SCH_ATM=m
-CONFIG_NET_SCH_CBQ=m
-# CONFIG_NET_SCH_CLK_CPU is not set
-# CONFIG_NET_SCH_CLK_GETTIMEOFDAY is not set
-CONFIG_NET_SCH_CLK_JIFFIES=y
-CONFIG_NET_SCH_DSMARK=m
-CONFIG_NET_SCH_ESFQ=m
-CONFIG_NET_SCH_ESFQ_NFCT=y
-CONFIG_NET_SCH_FIFO=y
-CONFIG_NET_SCH_GRED=m
-CONFIG_NET_SCH_HFSC=m
-CONFIG_NET_SCH_HTB=m
-CONFIG_NET_SCH_INGRESS=m
-CONFIG_NET_SCH_NETEM=m
-CONFIG_NET_SCH_PRIO=m
-CONFIG_NET_SCH_RED=m
-CONFIG_NET_SCH_RR=m
-CONFIG_NET_SCH_SFQ=m
-CONFIG_NET_SCH_TBF=m
-CONFIG_NET_SCH_TEQL=m
-# CONFIG_NET_TULIP is not set
-CONFIG_NET_WIRELESS=y
-CONFIG_NET_WIRELESS_RTNETLINK=y
-# CONFIG_NEW_GPIO is not set
-CONFIG_NEW_LEDS=y
-CONFIG_NFSD=m
-CONFIG_NFSD_TCP=y
-# CONFIG_NFSD_V2_ACL is not set
-CONFIG_NFSD_V3=y
-# CONFIG_NFSD_V3_ACL is not set
-CONFIG_NFSD_V4=y
-# CONFIG_NFS_ACL_SUPPORT is not set
-CONFIG_NFS_COMMON=y
-# CONFIG_NFS_DIRECTIO is not set
-CONFIG_NFS_FS=m
-CONFIG_NFS_V3=y
-# CONFIG_NFS_V3_ACL is not set
-CONFIG_NFS_V4=y
-# CONFIG_NFTL is not set
-CONFIG_NF_CONNTRACK=m
-CONFIG_NF_CONNTRACK_AMANDA=m
-CONFIG_NF_CONNTRACK_ENABLED=y
-# CONFIG_NF_CONNTRACK_EVENTS is not set
-CONFIG_NF_CONNTRACK_FTP=m
-CONFIG_NF_CONNTRACK_H323=m
-CONFIG_NF_CONNTRACK_IPV4=m
-CONFIG_NF_CONNTRACK_IPV6=m
-CONFIG_NF_CONNTRACK_IRC=m
-CONFIG_NF_CONNTRACK_MARK=y
-# CONFIG_NF_CONNTRACK_NETBIOS_NS is not set
-CONFIG_NF_CONNTRACK_PPTP=m
-CONFIG_NF_CONNTRACK_PROC_COMPAT=y
-CONFIG_NF_CONNTRACK_RTSP=m
-# CONFIG_NF_CONNTRACK_SANE is not set
-CONFIG_NF_CONNTRACK_SIP=m
-CONFIG_NF_CONNTRACK_SUPPORT=y
-CONFIG_NF_CONNTRACK_TFTP=m
-CONFIG_NF_CT_ACCT=y
-CONFIG_NF_CT_PROTO_GRE=m
-# CONFIG_NF_CT_PROTO_SCTP is not set
-# CONFIG_NF_CT_PROTO_UDPLITE is not set
-CONFIG_NF_NAT=m
-CONFIG_NF_NAT_AMANDA=m
-CONFIG_NF_NAT_FTP=m
-CONFIG_NF_NAT_H323=m
-CONFIG_NF_NAT_IRC=m
-CONFIG_NF_NAT_NEEDED=y
-CONFIG_NF_NAT_PPTP=m
-CONFIG_NF_NAT_PROTO_GRE=m
-CONFIG_NF_NAT_RTSP=m
-CONFIG_NF_NAT_SIP=m
-CONFIG_NF_NAT_SNMP_BASIC=m
-CONFIG_NF_NAT_TFTP=m
-CONFIG_NLS=m
-# CONFIG_NLS_ASCII is not set
-CONFIG_NLS_CODEPAGE_1250=m
-# CONFIG_NLS_CODEPAGE_1251 is not set
-CONFIG_NLS_CODEPAGE_437=m
-# CONFIG_NLS_CODEPAGE_737 is not set
-# CONFIG_NLS_CODEPAGE_775 is not set
-CONFIG_NLS_CODEPAGE_850=m
-# CONFIG_NLS_CODEPAGE_852 is not set
-# CONFIG_NLS_CODEPAGE_855 is not set
-# CONFIG_NLS_CODEPAGE_857 is not set
-# CONFIG_NLS_CODEPAGE_860 is not set
-# CONFIG_NLS_CODEPAGE_861 is not set
-# CONFIG_NLS_CODEPAGE_862 is not set
-# CONFIG_NLS_CODEPAGE_863 is not set
-# CONFIG_NLS_CODEPAGE_864 is not set
-# CONFIG_NLS_CODEPAGE_865 is not set
-# CONFIG_NLS_CODEPAGE_866 is not set
-# CONFIG_NLS_CODEPAGE_869 is not set
-# CONFIG_NLS_CODEPAGE_874 is not set
-# CONFIG_NLS_CODEPAGE_932 is not set
-# CONFIG_NLS_CODEPAGE_936 is not set
-# CONFIG_NLS_CODEPAGE_949 is not set
-# CONFIG_NLS_CODEPAGE_950 is not set
-CONFIG_NLS_DEFAULT="iso8859-1"
-CONFIG_NLS_ISO8859_1=m
-# CONFIG_NLS_ISO8859_13 is not set
-# CONFIG_NLS_ISO8859_14 is not set
-CONFIG_NLS_ISO8859_15=m
-# CONFIG_NLS_ISO8859_2 is not set
-# CONFIG_NLS_ISO8859_3 is not set
-# CONFIG_NLS_ISO8859_4 is not set
-# CONFIG_NLS_ISO8859_5 is not set
-# CONFIG_NLS_ISO8859_6 is not set
-# CONFIG_NLS_ISO8859_7 is not set
-# CONFIG_NLS_ISO8859_8 is not set
-# CONFIG_NLS_ISO8859_9 is not set
-CONFIG_NLS_KOI8_R=m
-# CONFIG_NLS_KOI8_U is not set
-CONFIG_NLS_UTF8=m
-CONFIG_NORTEL_HERMES=m
-# CONFIG_NO_HZ is not set
-# CONFIG_NS83820 is not set
-# CONFIG_NTFS_DEBUG is not set
-# CONFIG_NTFS_FS is not set
-# CONFIG_NTFS_RW is not set
-# CONFIG_OCFS2_FS is not set
-# CONFIG_OSF_PARTITION is not set
-CONFIG_PACKET=y
-CONFIG_PACKET_MMAP=y
-# CONFIG_PARPORT is not set
-# CONFIG_PARPORT_PC is not set
-CONFIG_PARTITION_ADVANCED=y
-# CONFIG_PATA_ALI is not set
-# CONFIG_PATA_AMD is not set
-# CONFIG_PATA_ARTOP is not set
-# CONFIG_PATA_ATIIXP is not set
-# CONFIG_PATA_CMD640_PCI is not set
-# CONFIG_PATA_CMD64X is not set
-# CONFIG_PATA_CS5520 is not set
-# CONFIG_PATA_CS5530 is not set
-# CONFIG_PATA_CS5535 is not set
-# CONFIG_PATA_CYPRESS is not set
-# CONFIG_PATA_EFAR is not set
-# CONFIG_PATA_HPT366 is not set
-# CONFIG_PATA_HPT37X is not set
-# CONFIG_PATA_HPT3X2N is not set
-# CONFIG_PATA_HPT3X3 is not set
-# CONFIG_PATA_ISAPNP is not set
-# CONFIG_PATA_IT8213 is not set
-# CONFIG_PATA_IT821X is not set
-# CONFIG_PATA_JMICRON is not set
-# CONFIG_PATA_LEGACY is not set
-# CONFIG_PATA_MARVELL is not set
-# CONFIG_PATA_MPIIX is not set
-# CONFIG_PATA_NETCELL is not set
-# CONFIG_PATA_NS87410 is not set
-# CONFIG_PATA_OLDPIIX is not set
-# CONFIG_PATA_OPTI is not set
-# CONFIG_PATA_OPTIDMA is not set
-# CONFIG_PATA_PCMCIA is not set
-# CONFIG_PATA_PDC2027X is not set
-# CONFIG_PATA_PDC_OLD is not set
-CONFIG_PATA_PLATFORM=m
-# CONFIG_PATA_QDI is not set
-# CONFIG_PATA_RADISYS is not set
-# CONFIG_PATA_RZ1000 is not set
-# CONFIG_PATA_SC1200 is not set
-# CONFIG_PATA_SERVERWORKS is not set
-# CONFIG_PATA_SIL680 is not set
-# CONFIG_PATA_SIS is not set
-# CONFIG_PATA_TRIFLEX is not set
-# CONFIG_PATA_VIA is not set
-# CONFIG_PATA_WINBOND is not set
-# CONFIG_PATA_WINBOND_VLB is not set
-# CONFIG_PC300TOO is not set
-# CONFIG_PCCARD is not set
-# CONFIG_PCI is not set
-# CONFIG_PCI_ATMEL is not set
-CONFIG_PCI_HERMES=m
-# CONFIG_PCMCIA is not set
-# CONFIG_PCMCIA_AHA152X is not set
-# CONFIG_PCMCIA_ATMEL is not set
-# CONFIG_PCMCIA_DEBUG is not set
-# CONFIG_PCMCIA_FDOMAIN is not set
-# CONFIG_PCMCIA_HERMES is not set
-# CONFIG_PCMCIA_IOCTL is not set
-# CONFIG_PCMCIA_LOAD_CIS is not set
-# CONFIG_PCMCIA_NETWAVE is not set
-# CONFIG_PCMCIA_NINJA_SCSI is not set
-# CONFIG_PCMCIA_QLOGIC is not set
-# CONFIG_PCMCIA_RAYCS is not set
-# CONFIG_PCMCIA_SPECTRUM is not set
-# CONFIG_PCMCIA_SYM53C500 is not set
-# CONFIG_PCMCIA_WAVELAN is not set
-# CONFIG_PCMCIA_WL3501 is not set
-# CONFIG_PCNET32 is not set
-# CONFIG_PD6729 is not set
-# CONFIG_PDC_ADMA is not set
-# CONFIG_PHANTOM is not set
-# CONFIG_PHONE is not set
-# CONFIG_PHYLIB is not set
-CONFIG_PLIST=y
-CONFIG_PLX_HERMES=m
-# CONFIG_PM is not set
-# CONFIG_POSIX_MQUEUE is not set
-# CONFIG_POWER_SUPPLY is not set
-CONFIG_PPP=m
-CONFIG_PPPOATM=m
-CONFIG_PPPOE=m
-CONFIG_PPPOL2TP=m
-CONFIG_PPP_ASYNC=m
-CONFIG_PPP_BSDCOMP=m
-CONFIG_PPP_DEFLATE=m
-CONFIG_PPP_FILTER=y
-CONFIG_PPP_MPPE=m
-CONFIG_PPP_MULTILINK=y
-CONFIG_PPP_SYNC_TTY=m
-# CONFIG_PPS is not set
-# CONFIG_PREEMPT is not set
-CONFIG_PREEMPT_NONE=y
-# CONFIG_PREEMPT_VOLUNTARY is not set
-CONFIG_PREVENT_FIRMWARE_BUILD=y
-CONFIG_PRINTK=y
-# CONFIG_PRINTK_TIME is not set
-CONFIG_PRISM54=m
-CONFIG_PROC_FS=y
-CONFIG_PROC_KCORE=y
-CONFIG_PROC_SYSCTL=y
-# CONFIG_PROFILING is not set
-# CONFIG_QEMU is not set
-# CONFIG_QLA3XXX is not set
-# CONFIG_QNX4FS_FS is not set
-# CONFIG_QUOTA is not set
-# CONFIG_R3964 is not set
-# CONFIG_R8169 is not set
-# CONFIG_RADIO_ADAPTERS is not set
-# CONFIG_RADIO_AZTECH is not set
-# CONFIG_RADIO_CADET is not set
-# CONFIG_RADIO_GEMTEK is not set
-# CONFIG_RADIO_GEMTEK_PCI is not set
-# CONFIG_RADIO_MAESTRO is not set
-# CONFIG_RADIO_MAXIRADIO is not set
-# CONFIG_RADIO_RTRACK is not set
-# CONFIG_RADIO_RTRACK2 is not set
-# CONFIG_RADIO_SF16FMI is not set
-# CONFIG_RADIO_SF16FMR2 is not set
-# CONFIG_RADIO_TERRATEC is not set
-# CONFIG_RADIO_TRUST is not set
-# CONFIG_RADIO_TYPHOON is not set
-# CONFIG_RADIO_ZOLTRIX is not set
-# CONFIG_RAID_ATTRS is not set
-CONFIG_RAMFS=y
-# CONFIG_RAW_DRIVER is not set
-# CONFIG_REISERFS_CHECK is not set
-# CONFIG_REISERFS_FS is not set
-# CONFIG_REISERFS_FS_XATTR is not set
-# CONFIG_REISERFS_PROC_INFO is not set
-# CONFIG_RELAY is not set
-# CONFIG_RESOURCES_64BIT is not set
-# CONFIG_RFD_FTL is not set
-# CONFIG_RFKILL is not set
-# CONFIG_ROMFS_FS is not set
-# CONFIG_ROSE is not set
-CONFIG_RPCSEC_GSS_KRB5=m
-# CONFIG_RPCSEC_GSS_SPKM3 is not set
-# CONFIG_RTC_CLASS is not set
-CONFIG_RTC_DRV_CMOS=y
-# CONFIG_RTC_DRV_MAX6900 is not set
-# CONFIG_RTL8187 is not set
-CONFIG_RT_MUTEXES=y
-# CONFIG_S2IO is not set
-# CONFIG_SATA_AHCI is not set
-# CONFIG_SATA_INIC162X is not set
-# CONFIG_SATA_MV is not set
-# CONFIG_SATA_NV is not set
-# CONFIG_SATA_PROMISE is not set
-# CONFIG_SATA_QSTOR is not set
-# CONFIG_SATA_SIL is not set
-# CONFIG_SATA_SIL24 is not set
-# CONFIG_SATA_SIS is not set
-# CONFIG_SATA_SVW is not set
-# CONFIG_SATA_SX4 is not set
-# CONFIG_SATA_ULI is not set
-# CONFIG_SATA_VIA is not set
-# CONFIG_SATA_VITESSE is not set
-# CONFIG_SC92031 is not set
-CONFIG_SCSI=m
-# CONFIG_SCSI_3W_9XXX is not set
-# CONFIG_SCSI_7000FASST is not set
-# CONFIG_SCSI_AACRAID is not set
-# CONFIG_SCSI_ACARD is not set
-# CONFIG_SCSI_ADVANSYS is not set
-# CONFIG_SCSI_AHA152X is not set
-# CONFIG_SCSI_AHA1542 is not set
-# CONFIG_SCSI_AIC79XX is not set
-# CONFIG_SCSI_AIC7XXX is not set
-# CONFIG_SCSI_AIC7XXX_OLD is not set
-# CONFIG_SCSI_AIC94XX is not set
-# CONFIG_SCSI_ARCMSR is not set
-# CONFIG_SCSI_BUSLOGIC is not set
-# CONFIG_SCSI_CONSTANTS is not set
-# CONFIG_SCSI_DC390T is not set
-# CONFIG_SCSI_DC395x is not set
-# CONFIG_SCSI_DEBUG is not set
-CONFIG_SCSI_DMA=y
-# CONFIG_SCSI_DMX3191D is not set
-# CONFIG_SCSI_DPT_I2O is not set
-# CONFIG_SCSI_DTC3280 is not set
-# CONFIG_SCSI_EATA is not set
-# CONFIG_SCSI_ESP_CORE is not set
-# CONFIG_SCSI_FC_ATTRS is not set
-# CONFIG_SCSI_FUTURE_DOMAIN is not set
-# CONFIG_SCSI_GDTH is not set
-# CONFIG_SCSI_GENERIC_NCR5380 is not set
-# CONFIG_SCSI_GENERIC_NCR5380_MMIO is not set
-# CONFIG_SCSI_HPTIOP is not set
-# CONFIG_SCSI_IN2000 is not set
-# CONFIG_SCSI_INIA100 is not set
-# CONFIG_SCSI_INITIO is not set
-# CONFIG_SCSI_IPR is not set
-# CONFIG_SCSI_IPS is not set
-# CONFIG_SCSI_ISCSI_ATTRS is not set
-# CONFIG_SCSI_LOGGING is not set
-CONFIG_SCSI_LOWLEVEL=y
-# CONFIG_SCSI_LPFC is not set
-CONFIG_SCSI_MULTI_LUN=y
-# CONFIG_SCSI_NCR53C406A is not set
-# CONFIG_SCSI_NETLINK is not set
-# CONFIG_SCSI_NSP32 is not set
-# CONFIG_SCSI_PAS16 is not set
-CONFIG_SCSI_PROC_FS=y
-# CONFIG_SCSI_PSI240I is not set
-# CONFIG_SCSI_QLA_FC is not set
-# CONFIG_SCSI_QLA_ISCSI is not set
-# CONFIG_SCSI_QLOGIC_1280 is not set
-# CONFIG_SCSI_QLOGIC_FAS is not set
-# CONFIG_SCSI_SAS_ATTRS is not set
-# CONFIG_SCSI_SAS_LIBSAS is not set
-# CONFIG_SCSI_SCAN_ASYNC is not set
-# CONFIG_SCSI_SEAGATE is not set
-# CONFIG_SCSI_SPI_ATTRS is not set
-# CONFIG_SCSI_SRP is not set
-# CONFIG_SCSI_STEX is not set
-# CONFIG_SCSI_SYM53C416 is not set
-# CONFIG_SCSI_SYM53C8XX_2 is not set
-# CONFIG_SCSI_T128 is not set
-# CONFIG_SCSI_TGT is not set
-# CONFIG_SCSI_U14_34F is not set
-# CONFIG_SCSI_ULTRASTOR is not set
-# CONFIG_SECCOMP is not set
-# CONFIG_SECURITY is not set
-CONFIG_SELECT_MEMORY_MODEL=y
-# CONFIG_SENSORS_ABITUGURU is not set
-# CONFIG_SENSORS_ABITUGURU3 is not set
-# CONFIG_SENSORS_AD7418 is not set
-# CONFIG_SENSORS_ADM1021 is not set
-# CONFIG_SENSORS_ADM1025 is not set
-# CONFIG_SENSORS_ADM1026 is not set
-# CONFIG_SENSORS_ADM1029 is not set
-# CONFIG_SENSORS_ADM1031 is not set
-# CONFIG_SENSORS_ADM9240 is not set
-# CONFIG_SENSORS_APPLESMC is not set
-# CONFIG_SENSORS_ASB100 is not set
-# CONFIG_SENSORS_ATXP1 is not set
-# CONFIG_SENSORS_CORETEMP is not set
-# CONFIG_SENSORS_DME1737 is not set
-# CONFIG_SENSORS_DS1337 is not set
-# CONFIG_SENSORS_DS1374 is not set
-# CONFIG_SENSORS_DS1621 is not set
-# CONFIG_SENSORS_EEPROM is not set
-# CONFIG_SENSORS_F71805F is not set
-# CONFIG_SENSORS_FSCHER is not set
-# CONFIG_SENSORS_FSCPOS is not set
-# CONFIG_SENSORS_GL518SM is not set
-# CONFIG_SENSORS_GL520SM is not set
-# CONFIG_SENSORS_HDAPS is not set
-# CONFIG_SENSORS_IT87 is not set
-# CONFIG_SENSORS_K8TEMP is not set
-# CONFIG_SENSORS_LM63 is not set
-# CONFIG_SENSORS_LM70 is not set
-# CONFIG_SENSORS_LM75 is not set
-# CONFIG_SENSORS_LM77 is not set
-# CONFIG_SENSORS_LM78 is not set
-# CONFIG_SENSORS_LM80 is not set
-# CONFIG_SENSORS_LM83 is not set
-# CONFIG_SENSORS_LM85 is not set
-# CONFIG_SENSORS_LM87 is not set
-# CONFIG_SENSORS_LM90 is not set
-# CONFIG_SENSORS_LM92 is not set
-# CONFIG_SENSORS_LM93 is not set
-# CONFIG_SENSORS_MAX1619 is not set
-# CONFIG_SENSORS_MAX6650 is not set
-# CONFIG_SENSORS_MAX6875 is not set
-# CONFIG_SENSORS_PC87427 is not set
-# CONFIG_SENSORS_PCA9539 is not set
-# CONFIG_SENSORS_PCF8574 is not set
-# CONFIG_SENSORS_PCF8591 is not set
-# CONFIG_SENSORS_SIS5595 is not set
-# CONFIG_SENSORS_SMSC47B397 is not set
-# CONFIG_SENSORS_SMSC47M1 is not set
-# CONFIG_SENSORS_SMSC47M192 is not set
-# CONFIG_SENSORS_THMC50 is not set
-# CONFIG_SENSORS_TSL2550 is not set
-# CONFIG_SENSORS_VIA686A is not set
-# CONFIG_SENSORS_VT1211 is not set
-# CONFIG_SENSORS_VT8231 is not set
-# CONFIG_SENSORS_W83627EHF is not set
-# CONFIG_SENSORS_W83627HF is not set
-# CONFIG_SENSORS_W83781D is not set
-# CONFIG_SENSORS_W83791D is not set
-# CONFIG_SENSORS_W83792D is not set
-# CONFIG_SENSORS_W83793 is not set
-# CONFIG_SENSORS_W83L785TS is not set
-CONFIG_SERIAL_8250=y
-CONFIG_SERIAL_8250_CONSOLE=y
-CONFIG_SERIAL_8250_CS=m
-CONFIG_SERIAL_8250_NR_UARTS=2
-# CONFIG_SERIAL_8250_PCI is not set
-CONFIG_SERIAL_8250_RUNTIME_UARTS=2
-CONFIG_SERIAL_CORE=y
-CONFIG_SERIAL_CORE_CONSOLE=y
-# CONFIG_SERIAL_JSM is not set
-# CONFIG_SERIAL_NONSTANDARD is not set
-# CONFIG_SERIAL_UARTLITE is not set
-# CONFIG_SERIO is not set
-# CONFIG_SGI_IOC4 is not set
-# CONFIG_SGI_PARTITION is not set
-# CONFIG_SHAPER is not set
-CONFIG_SHMEM=y
-CONFIG_SIGNALFD=y
-# CONFIG_SIS190 is not set
-# CONFIG_SIS900 is not set
-# CONFIG_SK98LIN is not set
-# CONFIG_SKGE is not set
-# CONFIG_SKY2 is not set
-CONFIG_SLAB=y
-CONFIG_SLHC=m
-# CONFIG_SLIP is not set
-# CONFIG_SLOB is not set
-# CONFIG_SLUB is not set
-# CONFIG_SMB_FS is not set
-# CONFIG_SMB_NLS_DEFAULT is not set
-CONFIG_SND=m
-# CONFIG_SND_AC97_POWER_SAVE is not set
-# CONFIG_SND_AD1816A is not set
-# CONFIG_SND_AD1848 is not set
-# CONFIG_SND_AD1889 is not set
-# CONFIG_SND_ADLIB is not set
-# CONFIG_SND_ALI5451 is not set
-# CONFIG_SND_ALS100 is not set
-# CONFIG_SND_ALS300 is not set
-# CONFIG_SND_ALS4000 is not set
-# CONFIG_SND_ATIIXP is not set
-# CONFIG_SND_ATIIXP_MODEM is not set
-# CONFIG_SND_AU8810 is not set
-# CONFIG_SND_AU8820 is not set
-# CONFIG_SND_AU8830 is not set
-# CONFIG_SND_AZT2320 is not set
-# CONFIG_SND_AZT3328 is not set
-# CONFIG_SND_BT87X is not set
-# CONFIG_SND_CA0106 is not set
-# CONFIG_SND_CMI8330 is not set
-# CONFIG_SND_CMIPCI is not set
-# CONFIG_SND_CS4231 is not set
-# CONFIG_SND_CS4232 is not set
-# CONFIG_SND_CS4236 is not set
-# CONFIG_SND_CS4281 is not set
-# CONFIG_SND_CS46XX is not set
-# CONFIG_SND_CS5535AUDIO is not set
-# CONFIG_SND_DARLA20 is not set
-# CONFIG_SND_DARLA24 is not set
-# CONFIG_SND_DEBUG is not set
-# CONFIG_SND_DT019X is not set
-# CONFIG_SND_DUMMY is not set
-# CONFIG_SND_DYNAMIC_MINORS is not set
-# CONFIG_SND_ECHO3G is not set
-# CONFIG_SND_EMU10K1 is not set
-# CONFIG_SND_EMU10K1X is not set
-# CONFIG_SND_ENS1370 is not set
-# CONFIG_SND_ENS1371 is not set
-# CONFIG_SND_ES1688 is not set
-# CONFIG_SND_ES18XX is not set
-# CONFIG_SND_ES1938 is not set
-# CONFIG_SND_ES1968 is not set
-# CONFIG_SND_ES968 is not set
-# CONFIG_SND_FM801 is not set
-# CONFIG_SND_GINA20 is not set
-# CONFIG_SND_GINA24 is not set
-# CONFIG_SND_GUSCLASSIC is not set
-# CONFIG_SND_GUSEXTREME is not set
-# CONFIG_SND_GUSMAX is not set
-# CONFIG_SND_HDA_INTEL is not set
-# CONFIG_SND_HDSP is not set
-# CONFIG_SND_HDSPM is not set
-CONFIG_SND_HWDEP=m
-# CONFIG_SND_ICE1712 is not set
-# CONFIG_SND_ICE1724 is not set
-# CONFIG_SND_INDIGO is not set
-# CONFIG_SND_INDIGODJ is not set
-# CONFIG_SND_INDIGOIO is not set
-# CONFIG_SND_INTEL8X0 is not set
-# CONFIG_SND_INTEL8X0M is not set
-# CONFIG_SND_INTERWAVE is not set
-# CONFIG_SND_INTERWAVE_STB is not set
-# CONFIG_SND_KORG1212 is not set
-# CONFIG_SND_LAYLA20 is not set
-# CONFIG_SND_LAYLA24 is not set
-# CONFIG_SND_MAESTRO3 is not set
-# CONFIG_SND_MIA is not set
-# CONFIG_SND_MIRO is not set
-# CONFIG_SND_MIXART is not set
-CONFIG_SND_MIXER_OSS=m
-# CONFIG_SND_MONA is not set
-# CONFIG_SND_MPU401 is not set
-# CONFIG_SND_MTPAV is not set
-# CONFIG_SND_NM256 is not set
-# CONFIG_SND_OPL3SA2 is not set
-# CONFIG_SND_OPTI92X_AD1848 is not set
-# CONFIG_SND_OPTI92X_CS4231 is not set
-# CONFIG_SND_OPTI93X is not set
-CONFIG_SND_OSSEMUL=y
-CONFIG_SND_PCM=m
-CONFIG_SND_PCM_OSS=m
-CONFIG_SND_PCM_OSS_PLUGINS=y
-# CONFIG_SND_PCXHR is not set
-# CONFIG_SND_PDAUDIOCF is not set
-CONFIG_SND_RAWMIDI=m
-# CONFIG_SND_RIPTIDE is not set
-# CONFIG_SND_RME32 is not set
-# CONFIG_SND_RME96 is not set
-# CONFIG_SND_RME9652 is not set
-# CONFIG_SND_RTCTIMER is not set
-# CONFIG_SND_SB16 is not set
-# CONFIG_SND_SB8 is not set
-# CONFIG_SND_SBAWE is not set
-# CONFIG_SND_SEQUENCER is not set
-# CONFIG_SND_SERIAL_U16550 is not set
-# CONFIG_SND_SGALAXY is not set
-# CONFIG_SND_SOC is not set
-# CONFIG_SND_SONICVIBES is not set
-# CONFIG_SND_SSCAPE is not set
-# CONFIG_SND_SUPPORT_OLD_API is not set
-CONFIG_SND_TIMER=m
-# CONFIG_SND_TRIDENT is not set
-CONFIG_SND_USB_AUDIO=m
-# CONFIG_SND_USB_CAIAQ is not set
-# CONFIG_SND_USB_USX2Y is not set
-# CONFIG_SND_VERBOSE_PRINTK is not set
-CONFIG_SND_VERBOSE_PROCFS=y
-# CONFIG_SND_VIA82XX is not set
-# CONFIG_SND_VIA82XX_MODEM is not set
-# CONFIG_SND_VX222 is not set
-# CONFIG_SND_VXPOCKET is not set
-# CONFIG_SND_WAVEFRONT is not set
-# CONFIG_SND_YMFPCI is not set
-# CONFIG_SNI_RM is not set
-# CONFIG_SOLARIS_X86_PARTITION is not set
-CONFIG_SOUND=m
-# CONFIG_SOUND_PRIME is not set
-# CONFIG_SPARSEMEM_MANUAL is not set
-# CONFIG_SPI is not set
-# CONFIG_SPI_DEBUG is not set
-# CONFIG_SPI_MASTER is not set
-# CONFIG_SPI_AT25 is not set
-# CONFIG_SPI_TLE62X0 is not set
-CONFIG_SPLIT_PTLOCK_CPUS=4
-CONFIG_SQUASHFS=y
-# CONFIG_SQUASHFS_EMBEDDED is not set
-CONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE=3
-# CONFIG_SQUASHFS_VMALLOC is not set
-# CONFIG_SSFDC is not set
-CONFIG_STACKTRACE_SUPPORT=y
-CONFIG_STANDALONE=y
-# CONFIG_STRIP is not set
-# CONFIG_SUNDANCE is not set
-# CONFIG_SUNGEM is not set
-CONFIG_SUNRPC=m
-# CONFIG_SUNRPC_BIND34 is not set
-CONFIG_SUNRPC_GSS=m
-# CONFIG_SUN_PARTITION is not set
-CONFIG_SUSPEND_UP_POSSIBLE=y
-CONFIG_SWAP=y
-# CONFIG_SYNCLINK_CS is not set
-CONFIG_SYN_COOKIES=y
-CONFIG_SYSCTL=y
-CONFIG_SYSCTL_SYSCALL=y
-CONFIG_SYSFS=y
-# CONFIG_SYSFS_DEPRECATED is not set
-# CONFIG_SYSV68_PARTITION is not set
-CONFIG_SYSVIPC=y
-# CONFIG_SYSV_FS is not set
-# CONFIG_SYS_HYPERVISOR is not set
-# CONFIG_TASKSTATS is not set
-# CONFIG_TCG_TPM is not set
-CONFIG_TCP_CONG_ADVANCED=y
-CONFIG_TCP_CONG_BIC=m
-CONFIG_TCP_CONG_CUBIC=m
-CONFIG_TCP_CONG_HSTCP=m
-CONFIG_TCP_CONG_HTCP=m
-CONFIG_TCP_CONG_HYBLA=m
-CONFIG_TCP_CONG_ILLINOIS=m
-CONFIG_TCP_CONG_LP=m
-CONFIG_TCP_CONG_SCALABLE=m
-CONFIG_TCP_CONG_VEGAS=y
-CONFIG_TCP_CONG_VENO=m
-CONFIG_TCP_CONG_WESTWOOD=m
-CONFIG_TCP_CONG_YEAH=m
-# CONFIG_TCP_MD5SIG is not set
-CONFIG_TEXTSEARCH=y
-CONFIG_TEXTSEARCH_BM=m
-CONFIG_TEXTSEARCH_FSM=m
-CONFIG_TEXTSEARCH_KMP=m
-# CONFIG_TIFM_CORE is not set
-# CONFIG_TIGON3 is not set
-CONFIG_TIMERFD=y
-# CONFIG_TINY_SHMEM is not set
-# CONFIG_TIPC is not set
-# CONFIG_TLAN is not set
-CONFIG_TMD_HERMES=m
-CONFIG_TMPFS=y
-# CONFIG_TMPFS_POSIX_ACL is not set
-# CONFIG_TR is not set
-CONFIG_TRACE_IRQFLAGS_SUPPORT=y
-CONFIG_TUN=m
-# CONFIG_TUNER_3036 is not set
-# CONFIG_TUNER_TEA5761 is not set
-CONFIG_UDF_FS=m
-CONFIG_UDF_NLS=y
-# CONFIG_UFS_FS is not set
-# CONFIG_UIO is not set
-# CONFIG_ULTRIX_PARTITION is not set
-CONFIG_UNIX=y
-CONFIG_UNIX98_PTYS=y
-# CONFIG_UNIXWARE_DISKLABEL is not set
-# CONFIG_UNUSED_SYMBOLS is not set
-# CONFIG_USB is not set
-# CONFIG_USB_ACECAD is not set
-CONFIG_USB_ACM=m
-# CONFIG_USB_ADUTUX is not set
-# CONFIG_USB_AIPTEK is not set
-CONFIG_USB_ALI_M5632=y
-CONFIG_USB_AN2720=y
-# CONFIG_USB_APPLEDISPLAY is not set
-# CONFIG_USB_APPLETOUCH is not set
-CONFIG_USB_ARCH_HAS_EHCI=y
-CONFIG_USB_ARCH_HAS_HCD=y
-CONFIG_USB_ARCH_HAS_OHCI=y
-CONFIG_USB_ARMLINUX=y
-# CONFIG_USB_ATI_REMOTE is not set
-# CONFIG_USB_ATI_REMOTE2 is not set
-CONFIG_USB_ATM=m
-# CONFIG_USB_AUERSWALD is not set
-# CONFIG_USB_BANDWIDTH is not set
-CONFIG_USB_BELKIN=y
-# CONFIG_USB_BERRY_CHARGE is not set
-CONFIG_USB_CATC=m
-# CONFIG_USB_CXACRU is not set
-# CONFIG_USB_CYPRESS_CY7C63 is not set
-# CONFIG_USB_CYTHERM is not set
-# CONFIG_USB_DABUSB is not set
-# CONFIG_USB_DEBUG is not set
-CONFIG_USB_DEVICEFS=y
-# CONFIG_USB_DEVICE_CLASS is not set
-# CONFIG_USB_DSBR is not set
-# CONFIG_USB_DYNAMIC_MINORS is not set
-# CONFIG_USB_EHCI_ROOT_HUB_TT is not set
-# CONFIG_USB_EHCI_SPLIT_ISO is not set
-# CONFIG_USB_EHCI_TT_NEWSCHED is not set
-# CONFIG_USB_EMI26 is not set
-# CONFIG_USB_EMI62 is not set
-# CONFIG_USB_EPSON2888 is not set
-# CONFIG_USB_ET61X251 is not set
-CONFIG_USB_EZUSB=y
-# CONFIG_USB_FTDI_ELAN is not set
-# CONFIG_USB_GADGET is not set
-CONFIG_USB_HID=m
-# CONFIG_USB_HIDDEV is not set
-CONFIG_USB_HIDINPUT=y
-# CONFIG_USB_HIDINPUT_POWERBOOK is not set
-# CONFIG_USB_IBMCAM is not set
-# CONFIG_USB_IDMOUSE is not set
-# CONFIG_USB_IOWARRIOR is not set
-# CONFIG_USB_ISP116X_HCD is not set
-CONFIG_USB_KAWETH=m
-# CONFIG_USB_KBD is not set
-# CONFIG_USB_KBTAB is not set
-# CONFIG_USB_KC2190 is not set
-# CONFIG_USB_KEYSPAN_REMOTE is not set
-# CONFIG_USB_KONICAWC is not set
-# CONFIG_USB_LCD is not set
-# CONFIG_USB_LD is not set
-# CONFIG_USB_LED is not set
-# CONFIG_USB_LEGOTOWER is not set
-# CONFIG_USB_LIBUSUAL is not set
-# CONFIG_USB_MDC800 is not set
-# CONFIG_USB_MICROTEK is not set
-# CONFIG_USB_MON is not set
-# CONFIG_USB_MOUSE is not set
-CONFIG_USB_NET_AX8817X=m
-CONFIG_USB_NET_CDCETHER=m
-CONFIG_USB_NET_CDC_SUBSET=m
-CONFIG_USB_NET_DM9601=m
-CONFIG_USB_NET_GL620A=m
-CONFIG_USB_NET_MCS7830=m
-CONFIG_USB_NET_NET1080=m
-CONFIG_USB_NET_PLUSB=m
-CONFIG_USB_NET_RNDIS_HOST=m
-CONFIG_USB_NET_ZAURUS=m
-# CONFIG_USB_OHCI_BIG_ENDIAN is not set
-# CONFIG_USB_OHCI_HCD is not set
-CONFIG_USB_OHCI_LITTLE_ENDIAN=y
-# CONFIG_USB_OTG is not set
-# CONFIG_USB_OV511 is not set
-CONFIG_USB_PEGASUS=m
-# CONFIG_USB_PHIDGET is not set
-# CONFIG_USB_POWERMATE is not set
-CONFIG_USB_PRINTER=m
-# CONFIG_USB_QUICKCAM_MESSENGER is not set
-# CONFIG_USB_RIO500 is not set
-# CONFIG_USB_RTL8150 is not set
-# CONFIG_USB_SE401 is not set
-CONFIG_USB_SERIAL=m
-CONFIG_USB_SERIAL_AIRCABLE=m
-CONFIG_USB_SERIAL_AIRPRIME=m
-CONFIG_USB_SERIAL_ARK3116=m
-CONFIG_USB_SERIAL_BELKIN=m
-CONFIG_USB_SERIAL_CP2101=m
-CONFIG_USB_SERIAL_CYBERJACK=m
-CONFIG_USB_SERIAL_CYPRESS_M8=m
-# CONFIG_USB_SERIAL_DEBUG is not set
-CONFIG_USB_SERIAL_DIGI_ACCELEPORT=m
-CONFIG_USB_SERIAL_EDGEPORT=m
-CONFIG_USB_SERIAL_EDGEPORT_TI=m
-CONFIG_USB_SERIAL_EMPEG=m
-CONFIG_USB_SERIAL_FTDI_SIO=m
-CONFIG_USB_SERIAL_FUNSOFT=m
-CONFIG_USB_SERIAL_GARMIN=m
-CONFIG_USB_SERIAL_GENERIC=y
-CONFIG_USB_SERIAL_HP4X=m
-CONFIG_USB_SERIAL_IPAQ=m
-CONFIG_USB_SERIAL_IPW=m
-CONFIG_USB_SERIAL_IR=m
-CONFIG_USB_SERIAL_KEYSPAN=m
-CONFIG_USB_SERIAL_KEYSPAN_MPR=y
-CONFIG_USB_SERIAL_KEYSPAN_PDA=m
-CONFIG_USB_SERIAL_KEYSPAN_USA18X=y
-CONFIG_USB_SERIAL_KEYSPAN_USA19=y
-CONFIG_USB_SERIAL_KEYSPAN_USA19QI=y
-CONFIG_USB_SERIAL_KEYSPAN_USA19QW=y
-CONFIG_USB_SERIAL_KEYSPAN_USA19W=y
-CONFIG_USB_SERIAL_KEYSPAN_USA28=y
-CONFIG_USB_SERIAL_KEYSPAN_USA28X=y
-CONFIG_USB_SERIAL_KEYSPAN_USA28XA=y
-CONFIG_USB_SERIAL_KEYSPAN_USA28XB=y
-CONFIG_USB_SERIAL_KEYSPAN_USA49W=y
-CONFIG_USB_SERIAL_KEYSPAN_USA49WLC=y
-CONFIG_USB_SERIAL_KLSI=m
-CONFIG_USB_SERIAL_KOBIL_SCT=m
-CONFIG_USB_SERIAL_MCT_U232=m
-CONFIG_USB_SERIAL_MOS7720=m
-CONFIG_USB_SERIAL_MOS7840=m
-CONFIG_USB_SERIAL_NAVMAN=m
-CONFIG_USB_SERIAL_OMNINET=m
-CONFIG_USB_SERIAL_OPTION=m
-CONFIG_USB_SERIAL_OTI6858=m
-CONFIG_USB_SERIAL_PL2303=m
-CONFIG_USB_SERIAL_SAFE=m
-CONFIG_USB_SERIAL_SAFE_PADDED=y
-CONFIG_USB_SERIAL_SIERRAWIRELESS=m
-CONFIG_USB_SERIAL_TI=m
-CONFIG_USB_SERIAL_VISOR=m
-CONFIG_USB_SERIAL_WHITEHEAT=m
-CONFIG_USB_SERIAL_XIRCOM=m
-# CONFIG_USB_SISUSBVGA is not set
-# CONFIG_USB_SL811_HCD is not set
-# CONFIG_USB_SN9C102 is not set
-CONFIG_USB_SPEEDTOUCH=m
-CONFIG_USB_STORAGE=m
-CONFIG_USB_STORAGE_ALAUDA=y
-CONFIG_USB_STORAGE_DATAFAB=y
-# CONFIG_USB_STORAGE_DEBUG is not set
-CONFIG_USB_STORAGE_DPCM=y
-CONFIG_USB_STORAGE_FREECOM=y
-# CONFIG_USB_STORAGE_ISD200 is not set
-CONFIG_USB_STORAGE_JUMPSHOT=y
-CONFIG_USB_STORAGE_KARMA=y
-# CONFIG_USB_STORAGE_ONETOUCH is not set
-CONFIG_USB_STORAGE_SDDR09=y
-CONFIG_USB_STORAGE_SDDR55=y
-CONFIG_USB_STORAGE_USBAT=y
-# CONFIG_USB_STV680 is not set
-CONFIG_USB_SUPPORT=y
-# CONFIG_USB_TEST is not set
-# CONFIG_USB_TOUCHSCREEN is not set
-# CONFIG_USB_TRANCEVIBRATOR is not set
-CONFIG_USB_UEAGLEATM=m
-CONFIG_USB_USBNET=m
-CONFIG_USB_USBNET_MII=m
-# CONFIG_USB_VICAM is not set
-# CONFIG_USB_W9968CF is not set
-# CONFIG_USB_WACOM is not set
-# CONFIG_USB_XPAD is not set
-# CONFIG_USB_XUSBATM is not set
-CONFIG_USB_YEALINK=m
-# CONFIG_USB_ZC0301 is not set
-# CONFIG_USB_ZD1201 is not set
-# CONFIG_USB_ZR364XX is not set
-# CONFIG_UTS_NS is not set
-CONFIG_VFAT_FS=m
-# CONFIG_VIA_VELOCITY is not set
-# CONFIG_VIDEO_ADV7170 is not set
-# CONFIG_VIDEO_ADV7175 is not set
-# CONFIG_VIDEO_ADV_DEBUG is not set
-# CONFIG_VIDEO_BT819 is not set
-# CONFIG_VIDEO_BT848 is not set
-# CONFIG_VIDEO_BT856 is not set
-# CONFIG_VIDEO_BT866 is not set
-# CONFIG_VIDEO_CAFE_CCIC is not set
-# CONFIG_VIDEO_CAPTURE_DRIVERS is not set
-# CONFIG_VIDEO_CPIA is not set
-# CONFIG_VIDEO_CS53L32A is not set
-# CONFIG_VIDEO_CX2341X is not set
-# CONFIG_VIDEO_CX25840 is not set
-# CONFIG_VIDEO_CX88 is not set
-CONFIG_VIDEO_DEV=m
-# CONFIG_VIDEO_DPC is not set
-# CONFIG_VIDEO_EM28XX is not set
-# CONFIG_VIDEO_HELPER_CHIPS_AUTO is not set
-# CONFIG_VIDEO_HEXIUM_GEMINI is not set
-# CONFIG_VIDEO_HEXIUM_ORION is not set
-# CONFIG_VIDEO_IVTV is not set
-# CONFIG_VIDEO_KS0127 is not set
-# CONFIG_VIDEO_MSP3400 is not set
-# CONFIG_VIDEO_MXB is not set
-# CONFIG_VIDEO_OUTPUT_CONTROL is not set
-# CONFIG_VIDEO_OV7670 is not set
-# CONFIG_VIDEO_OVCAMCHIP is not set
-# CONFIG_VIDEO_PMS is not set
-# CONFIG_VIDEO_PVRUSB2 is not set
-# CONFIG_VIDEO_SAA5246A is not set
-# CONFIG_VIDEO_SAA5249 is not set
-# CONFIG_VIDEO_SAA7110 is not set
-# CONFIG_VIDEO_SAA7111 is not set
-# CONFIG_VIDEO_SAA7114 is not set
-# CONFIG_VIDEO_SAA711X is not set
-# CONFIG_VIDEO_SAA7127 is not set
-# CONFIG_VIDEO_SAA7134 is not set
-# CONFIG_VIDEO_SAA7185 is not set
-# CONFIG_VIDEO_SAA7191 is not set
-# CONFIG_VIDEO_STRADIS is not set
-# CONFIG_VIDEO_TDA7432 is not set
-# CONFIG_VIDEO_TDA9840 is not set
-# CONFIG_VIDEO_TDA9875 is not set
-# CONFIG_VIDEO_TEA6415C is not set
-# CONFIG_VIDEO_TEA6420 is not set
-# CONFIG_VIDEO_TLV320AIC23B is not set
-# CONFIG_VIDEO_TVAUDIO is not set
-# CONFIG_VIDEO_TVP5150 is not set
-# CONFIG_VIDEO_UPD64031A is not set
-# CONFIG_VIDEO_UPD64083 is not set
-# CONFIG_VIDEO_USBVISION is not set
-# CONFIG_VIDEO_V4L1 is not set
-CONFIG_VIDEO_V4L1_COMPAT=y
-CONFIG_VIDEO_V4L2=y
-# CONFIG_VIDEO_VIVI is not set
-# CONFIG_VIDEO_VPX3220 is not set
-# CONFIG_VIDEO_WM8739 is not set
-# CONFIG_VIDEO_WM8775 is not set
-# CONFIG_VIDEO_ZORAN is not set
-CONFIG_VIRT_TO_BUS=y
-# CONFIG_VITESSE_PHY is not set
-CONFIG_VLAN_8021Q=y
-# CONFIG_VM_EVENT_COUNTERS is not set
-# CONFIG_VT is not set
-# CONFIG_VXFS_FS is not set
-CONFIG_W1=m
-# CONFIG_W1_MASTER_DS1WM is not set
-# CONFIG_W1_MASTER_DS2482 is not set
-# CONFIG_W1_MASTER_DS2490 is not set
-# CONFIG_W1_MASTER_GPIO is not set
-# CONFIG_W1_MASTER_MATROX is not set
-# CONFIG_W1_SLAVE_DS2433 is not set
-# CONFIG_W1_SLAVE_DS2760 is not set
-# CONFIG_W1_SLAVE_SMEM is not set
-# CONFIG_W1_SLAVE_THERM is not set
-# CONFIG_W83627HF_WDT is not set
-# CONFIG_W83697HF_WDT is not set
-# CONFIG_W83877F_WDT is not set
-# CONFIG_W83977F_WDT is not set
-# CONFIG_WAN is not set
-# CONFIG_WAN_ROUTER is not set
-CONFIG_WATCHDOG=y
-# CONFIG_WATCHDOG_NOWAYOUT is not set
-# CONFIG_WDTPCI is not set
-CONFIG_WIRELESS_EXT=y
-CONFIG_WLAN_80211=y
-# CONFIG_WLAN_PRE80211 is not set
-# CONFIG_WR_PPMC is not set
-# CONFIG_X25 is not set
-CONFIG_XFRM=y
-# CONFIG_XFRM_MIGRATE is not set
-# CONFIG_XFRM_SUB_POLICY is not set
-CONFIG_XFRM_USER=m
-CONFIG_XFS_FS=m
-# CONFIG_XFS_POSIX_ACL is not set
-# CONFIG_XFS_QUOTA is not set
-# CONFIG_XFS_RT is not set
-# CONFIG_XFS_SECURITY is not set
-# CONFIG_YAFFS_FS is not set
-# CONFIG_YAM is not set
-# CONFIG_YELLOWFIN is not set
-CONFIG_YENTA=m
-# CONFIG_YENTA_O2 is not set
-# CONFIG_YENTA_RICOH is not set
-# CONFIG_YENTA_TI is not set
-# CONFIG_YENTA_TOSHIBA is not set
-CONFIG_ZD1211RW=m
-# CONFIG_ZD1211RW_DEBUG is not set
-CONFIG_ZISOFS=y
-CONFIG_ZISOFS_FS=m
-CONFIG_ZLIB_DEFLATE=y
-CONFIG_ZLIB_INFLATE=y
-CONFIG_ZONE_DMA=y
-CONFIG_ZONE_DMA_FLAG=1
+++ /dev/null
-Index: linux-2.6.21.7/fs/Kconfig
-===================================================================
---- linux-2.6.21.7.orig/fs/Kconfig
-+++ linux-2.6.21.7/fs/Kconfig
-@@ -1371,6 +1371,71 @@ config CRAMFS
-
- If unsure, say N.
-
-+config SQUASHFS
-+ tristate "SquashFS 3.0 - Squashed file system support"
-+ select ZLIB_INFLATE
-+ help
-+ Saying Y here includes support for SquashFS 3.0 (a Compressed Read-Only File
-+ System). Squashfs is a highly compressed read-only filesystem for Linux.
-+ It uses zlib compression to compress both files, inodes and directories.
-+ Inodes in the system are very small and all blocks are packed to minimise
-+ data overhead. Block sizes greater than 4K are supported up to a maximum of 64K.
-+ SquashFS 3.0 supports 64 bit filesystems and files (larger than 4GB), full
-+ uid/gid information, hard links and timestamps.
-+
-+ Squashfs is intended for general read-only filesystem use, for archival
-+ use (i.e. in cases where a .tar.gz file may be used), and in embedded
-+ systems where low overhead is needed. Further information and filesystem tools
-+ are available from http://squashfs.sourceforge.net.
-+
-+ If you want to compile this as a module ( = code which can be
-+ inserted in and removed from the running kernel whenever you want),
-+ say M here and read <file:Documentation/modules.txt>. The module
-+ will be called squashfs. Note that the root file system (the one
-+ containing the directory /) cannot be compiled as a module.
-+
-+ If unsure, say N.
-+
-+config SQUASHFS_EMBEDDED
-+
-+ bool "Additional options for memory-constrained systems"
-+ depends on SQUASHFS
-+ default n
-+ help
-+ Saying Y here allows you to specify cache sizes and how Squashfs
-+ allocates memory. This is only intended for memory constrained
-+ systems.
-+
-+ If unsure, say N.
-+
-+config SQUASHFS_FRAGMENT_CACHE_SIZE
-+ int "Number of fragments cached" if SQUASHFS_EMBEDDED
-+ depends on SQUASHFS
-+ default "3"
-+ help
-+ By default SquashFS caches the last 3 fragments read from
-+ the filesystem. Increasing this amount may mean SquashFS
-+ has to re-read fragments less often from disk, at the expense
-+ of extra system memory. Decreasing this amount will mean
-+ SquashFS uses less memory at the expense of extra reads from disk.
-+
-+ Note there must be at least one cached fragment. Anything
-+ much more than three will probably not make much difference.
-+
-+config SQUASHFS_VMALLOC
-+ bool "Use Vmalloc rather than Kmalloc" if SQUASHFS_EMBEDDED
-+ depends on SQUASHFS
-+ default n
-+ help
-+ By default SquashFS uses kmalloc to obtain fragment cache memory.
-+ Kmalloc memory is the standard kernel allocator, but it can fail
-+ on memory constrained systems. Because of the way Vmalloc works,
-+ Vmalloc can succeed when kmalloc fails. Specifying this option
-+ will make SquashFS always use Vmalloc to allocate the
-+ fragment cache memory.
-+
-+ If unsure, say N.
-+
- config VXFS_FS
- tristate "FreeVxFS file system support (VERITAS VxFS(TM) compatible)"
- depends on BLOCK
-Index: linux-2.6.21.7/fs/Makefile
-===================================================================
---- linux-2.6.21.7.orig/fs/Makefile
-+++ linux-2.6.21.7/fs/Makefile
-@@ -68,6 +68,7 @@ obj-$(CONFIG_JBD) += jbd/
- obj-$(CONFIG_JBD2) += jbd2/
- obj-$(CONFIG_EXT2_FS) += ext2/
- obj-$(CONFIG_CRAMFS) += cramfs/
-+obj-$(CONFIG_SQUASHFS) += squashfs/
- obj-$(CONFIG_RAMFS) += ramfs/
- obj-$(CONFIG_HUGETLBFS) += hugetlbfs/
- obj-$(CONFIG_CODA_FS) += coda/
-Index: linux-2.6.21.7/fs/squashfs/inode.c
-===================================================================
---- /dev/null
-+++ linux-2.6.21.7/fs/squashfs/inode.c
-@@ -0,0 +1,2124 @@
-+/*
-+ * Squashfs - a compressed read only filesystem for Linux
-+ *
-+ * Copyright (c) 2002, 2003, 2004, 2005, 2006
-+ * Phillip Lougher <phillip@lougher.org.uk>
-+ *
-+ * 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,
-+ * 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-+ *
-+ * inode.c
-+ */
-+
-+#include <linux/types.h>
-+#include <linux/squashfs_fs.h>
-+#include <linux/module.h>
-+#include <linux/errno.h>
-+#include <linux/slab.h>
-+#include <linux/fs.h>
-+#include <linux/smp_lock.h>
-+#include <linux/slab.h>
-+#include <linux/squashfs_fs_sb.h>
-+#include <linux/squashfs_fs_i.h>
-+#include <linux/buffer_head.h>
-+#include <linux/vfs.h>
-+#include <linux/init.h>
-+#include <linux/dcache.h>
-+#include <linux/wait.h>
-+#include <linux/zlib.h>
-+#include <linux/blkdev.h>
-+#include <linux/vmalloc.h>
-+#include <asm/uaccess.h>
-+#include <asm/semaphore.h>
-+
-+#include "squashfs.h"
-+
-+static void squashfs_put_super(struct super_block *);
-+static int squashfs_statfs(struct dentry *, struct kstatfs *);
-+static int squashfs_symlink_readpage(struct file *file, struct page *page);
-+static int squashfs_readpage(struct file *file, struct page *page);
-+static int squashfs_readpage4K(struct file *file, struct page *page);
-+static int squashfs_readdir(struct file *, void *, filldir_t);
-+static struct inode *squashfs_alloc_inode(struct super_block *sb);
-+static void squashfs_destroy_inode(struct inode *inode);
-+static int init_inodecache(void);
-+static void destroy_inodecache(void);
-+static struct dentry *squashfs_lookup(struct inode *, struct dentry *,
-+ struct nameidata *);
-+static struct inode *squashfs_iget(struct super_block *s, squashfs_inode_t inode);
-+static long long read_blocklist(struct inode *inode, int index,
-+ int readahead_blks, char *block_list,
-+ unsigned short **block_p, unsigned int *bsize);
-+static int squashfs_get_sb(struct file_system_type *, int,
-+ const char *, void *, struct vfsmount *);
-+
-+
-+static z_stream stream;
-+
-+static struct file_system_type squashfs_fs_type = {
-+ .owner = THIS_MODULE,
-+ .name = "squashfs",
-+ .get_sb = squashfs_get_sb,
-+ .kill_sb = kill_block_super,
-+ .fs_flags = FS_REQUIRES_DEV
-+};
-+
-+static unsigned char squashfs_filetype_table[] = {
-+ DT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK
-+};
-+
-+static struct super_operations squashfs_ops = {
-+ .alloc_inode = squashfs_alloc_inode,
-+ .destroy_inode = squashfs_destroy_inode,
-+ .statfs = squashfs_statfs,
-+ .put_super = squashfs_put_super,
-+};
-+
-+SQSH_EXTERN struct address_space_operations squashfs_symlink_aops = {
-+ .readpage = squashfs_symlink_readpage
-+};
-+
-+SQSH_EXTERN struct address_space_operations squashfs_aops = {
-+ .readpage = squashfs_readpage
-+};
-+
-+SQSH_EXTERN struct address_space_operations squashfs_aops_4K = {
-+ .readpage = squashfs_readpage4K
-+};
-+
-+static struct file_operations squashfs_dir_ops = {
-+ .read = generic_read_dir,
-+ .readdir = squashfs_readdir
-+};
-+
-+SQSH_EXTERN struct inode_operations squashfs_dir_inode_ops = {
-+ .lookup = squashfs_lookup
-+};
-+
-+
-+static struct buffer_head *get_block_length(struct super_block *s,
-+ int *cur_index, int *offset, int *c_byte)
-+{
-+ struct squashfs_sb_info *msblk = s->s_fs_info;
-+ unsigned short temp;
-+ struct buffer_head *bh;
-+
-+ if (!(bh = sb_bread(s, *cur_index)))
-+ goto out;
-+
-+ if (msblk->devblksize - *offset == 1) {
-+ if (msblk->swap)
-+ ((unsigned char *) &temp)[1] = *((unsigned char *)
-+ (bh->b_data + *offset));
-+ else
-+ ((unsigned char *) &temp)[0] = *((unsigned char *)
-+ (bh->b_data + *offset));
-+ brelse(bh);
-+ if (!(bh = sb_bread(s, ++(*cur_index))))
-+ goto out;
-+ if (msblk->swap)
-+ ((unsigned char *) &temp)[0] = *((unsigned char *)
-+ bh->b_data);
-+ else
-+ ((unsigned char *) &temp)[1] = *((unsigned char *)
-+ bh->b_data);
-+ *c_byte = temp;
-+ *offset = 1;
-+ } else {
-+ if (msblk->swap) {
-+ ((unsigned char *) &temp)[1] = *((unsigned char *)
-+ (bh->b_data + *offset));
-+ ((unsigned char *) &temp)[0] = *((unsigned char *)
-+ (bh->b_data + *offset + 1));
-+ } else {
-+ ((unsigned char *) &temp)[0] = *((unsigned char *)
-+ (bh->b_data + *offset));
-+ ((unsigned char *) &temp)[1] = *((unsigned char *)
-+ (bh->b_data + *offset + 1));
-+ }
-+ *c_byte = temp;
-+ *offset += 2;
-+ }
-+
-+ if (SQUASHFS_CHECK_DATA(msblk->sblk.flags)) {
-+ if (*offset == msblk->devblksize) {
-+ brelse(bh);
-+ if (!(bh = sb_bread(s, ++(*cur_index))))
-+ goto out;
-+ *offset = 0;
-+ }
-+ if (*((unsigned char *) (bh->b_data + *offset)) !=
-+ SQUASHFS_MARKER_BYTE) {
-+ ERROR("Metadata block marker corrupt @ %x\n",
-+ *cur_index);
-+ brelse(bh);
-+ goto out;
-+ }
-+ (*offset)++;
-+ }
-+ return bh;
-+
-+out:
-+ return NULL;
-+}
-+
-+
-+SQSH_EXTERN unsigned int squashfs_read_data(struct super_block *s, char *buffer,
-+ long long index, unsigned int length,
-+ long long *next_index)
-+{
-+ struct squashfs_sb_info *msblk = s->s_fs_info;
-+ struct buffer_head *bh[((SQUASHFS_FILE_MAX_SIZE - 1) >>
-+ msblk->devblksize_log2) + 2];
-+ unsigned int offset = index & ((1 << msblk->devblksize_log2) - 1);
-+ unsigned int cur_index = index >> msblk->devblksize_log2;
-+ int bytes, avail_bytes, b = 0, k;
-+ char *c_buffer;
-+ unsigned int compressed;
-+ unsigned int c_byte = length;
-+
-+ if (c_byte) {
-+ bytes = msblk->devblksize - offset;
-+ compressed = SQUASHFS_COMPRESSED_BLOCK(c_byte);
-+ c_buffer = compressed ? msblk->read_data : buffer;
-+ c_byte = SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte);
-+
-+ TRACE("Block @ 0x%llx, %scompressed size %d\n", index, compressed
-+ ? "" : "un", (unsigned int) c_byte);
-+
-+ if (!(bh[0] = sb_getblk(s, cur_index)))
-+ goto block_release;
-+
-+ for (b = 1; bytes < c_byte; b++) {
-+ if (!(bh[b] = sb_getblk(s, ++cur_index)))
-+ goto block_release;
-+ bytes += msblk->devblksize;
-+ }
-+ ll_rw_block(READ, b, bh);
-+ } else {
-+ if (!(bh[0] = get_block_length(s, &cur_index, &offset,
-+ &c_byte)))
-+ goto read_failure;
-+
-+ bytes = msblk->devblksize - offset;
-+ compressed = SQUASHFS_COMPRESSED(c_byte);
-+ c_buffer = compressed ? msblk->read_data : buffer;
-+ c_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);
-+
-+ TRACE("Block @ 0x%llx, %scompressed size %d\n", index, compressed
-+ ? "" : "un", (unsigned int) c_byte);
-+
-+ for (b = 1; bytes < c_byte; b++) {
-+ if (!(bh[b] = sb_getblk(s, ++cur_index)))
-+ goto block_release;
-+ bytes += msblk->devblksize;
-+ }
-+ ll_rw_block(READ, b - 1, bh + 1);
-+ }
-+
-+ if (compressed)
-+ down(&msblk->read_data_mutex);
-+
-+ for (bytes = 0, k = 0; k < b; k++) {
-+ avail_bytes = (c_byte - bytes) > (msblk->devblksize - offset) ?
-+ msblk->devblksize - offset :
-+ c_byte - bytes;
-+ wait_on_buffer(bh[k]);
-+ if (!buffer_uptodate(bh[k]))
-+ goto block_release;
-+ memcpy(c_buffer + bytes, bh[k]->b_data + offset, avail_bytes);
-+ bytes += avail_bytes;
-+ offset = 0;
-+ brelse(bh[k]);
-+ }
-+
-+ /*
-+ * uncompress block
-+ */
-+ if (compressed) {
-+ int zlib_err;
-+
-+ stream.next_in = c_buffer;
-+ stream.avail_in = c_byte;
-+ stream.next_out = buffer;
-+ stream.avail_out = msblk->read_size;
-+
-+ if (((zlib_err = zlib_inflateInit(&stream)) != Z_OK) ||
-+ ((zlib_err = zlib_inflate(&stream, Z_FINISH))
-+ != Z_STREAM_END) || ((zlib_err =
-+ zlib_inflateEnd(&stream)) != Z_OK)) {
-+ ERROR("zlib_fs returned unexpected result 0x%x\n",
-+ zlib_err);
-+ bytes = 0;
-+ } else
-+ bytes = stream.total_out;
-+
-+ up(&msblk->read_data_mutex);
-+ }
-+
-+ if (next_index)
-+ *next_index = index + c_byte + (length ? 0 :
-+ (SQUASHFS_CHECK_DATA(msblk->sblk.flags)
-+ ? 3 : 2));
-+ return bytes;
-+
-+block_release:
-+ while (--b >= 0)
-+ brelse(bh[b]);
-+
-+read_failure:
-+ ERROR("sb_bread failed reading block 0x%x\n", cur_index);
-+ return 0;
-+}
-+
-+
-+SQSH_EXTERN int squashfs_get_cached_block(struct super_block *s, char *buffer,
-+ long long block, unsigned int offset,
-+ int length, long long *next_block,
-+ unsigned int *next_offset)
-+{
-+ struct squashfs_sb_info *msblk = s->s_fs_info;
-+ int n, i, bytes, return_length = length;
-+ long long next_index;
-+
-+ TRACE("Entered squashfs_get_cached_block [%llx:%x]\n", block, offset);
-+
-+ while ( 1 ) {
-+ for (i = 0; i < SQUASHFS_CACHED_BLKS; i++)
-+ if (msblk->block_cache[i].block == block)
-+ break;
-+
-+ down(&msblk->block_cache_mutex);
-+
-+ if (i == SQUASHFS_CACHED_BLKS) {
-+ /* read inode header block */
-+ for (i = msblk->next_cache, n = SQUASHFS_CACHED_BLKS;
-+ n ; n --, i = (i + 1) %
-+ SQUASHFS_CACHED_BLKS)
-+ if (msblk->block_cache[i].block !=
-+ SQUASHFS_USED_BLK)
-+ break;
-+
-+ if (n == 0) {
-+ wait_queue_t wait;
-+
-+ init_waitqueue_entry(&wait, current);
-+ add_wait_queue(&msblk->waitq, &wait);
-+ set_current_state(TASK_UNINTERRUPTIBLE);
-+ up(&msblk->block_cache_mutex);
-+ schedule();
-+ set_current_state(TASK_RUNNING);
-+ remove_wait_queue(&msblk->waitq, &wait);
-+ continue;
-+ }
-+ msblk->next_cache = (i + 1) % SQUASHFS_CACHED_BLKS;
-+
-+ if (msblk->block_cache[i].block ==
-+ SQUASHFS_INVALID_BLK) {
-+ if (!(msblk->block_cache[i].data =
-+ kmalloc(SQUASHFS_METADATA_SIZE,
-+ GFP_KERNEL))) {
-+ ERROR("Failed to allocate cache"
-+ "block\n");
-+ up(&msblk->block_cache_mutex);
-+ goto out;
-+ }
-+ }
-+
-+ msblk->block_cache[i].block = SQUASHFS_USED_BLK;
-+ up(&msblk->block_cache_mutex);
-+
-+ if (!(msblk->block_cache[i].length =
-+ squashfs_read_data(s,
-+ msblk->block_cache[i].data,
-+ block, 0, &next_index))) {
-+ ERROR("Unable to read cache block [%llx:%x]\n",
-+ block, offset);
-+ goto out;
-+ }
-+
-+ down(&msblk->block_cache_mutex);
-+ wake_up(&msblk->waitq);
-+ msblk->block_cache[i].block = block;
-+ msblk->block_cache[i].next_index = next_index;
-+ TRACE("Read cache block [%llx:%x]\n", block, offset);
-+ }
-+
-+ if (msblk->block_cache[i].block != block) {
-+ up(&msblk->block_cache_mutex);
-+ continue;
-+ }
-+
-+ if ((bytes = msblk->block_cache[i].length - offset) >= length) {
-+ if (buffer)
-+ memcpy(buffer, msblk->block_cache[i].data +
-+ offset, length);
-+ if (msblk->block_cache[i].length - offset == length) {
-+ *next_block = msblk->block_cache[i].next_index;
-+ *next_offset = 0;
-+ } else {
-+ *next_block = block;
-+ *next_offset = offset + length;
-+ }
-+ up(&msblk->block_cache_mutex);
-+ goto finish;
-+ } else {
-+ if (buffer) {
-+ memcpy(buffer, msblk->block_cache[i].data +
-+ offset, bytes);
-+ buffer += bytes;
-+ }
-+ block = msblk->block_cache[i].next_index;
-+ up(&msblk->block_cache_mutex);
-+ length -= bytes;
-+ offset = 0;
-+ }
-+ }
-+
-+finish:
-+ return return_length;
-+out:
-+ return 0;
-+}
-+
-+
-+static int get_fragment_location(struct super_block *s, unsigned int fragment,
-+ long long *fragment_start_block,
-+ unsigned int *fragment_size)
-+{
-+ struct squashfs_sb_info *msblk = s->s_fs_info;
-+ long long start_block =
-+ msblk->fragment_index[SQUASHFS_FRAGMENT_INDEX(fragment)];
-+ int offset = SQUASHFS_FRAGMENT_INDEX_OFFSET(fragment);
-+ struct squashfs_fragment_entry fragment_entry;
-+
-+ if (msblk->swap) {
-+ struct squashfs_fragment_entry sfragment_entry;
-+
-+ if (!squashfs_get_cached_block(s, (char *) &sfragment_entry,
-+ start_block, offset,
-+ sizeof(sfragment_entry), &start_block,
-+ &offset))
-+ goto out;
-+ SQUASHFS_SWAP_FRAGMENT_ENTRY(&fragment_entry, &sfragment_entry);
-+ } else
-+ if (!squashfs_get_cached_block(s, (char *) &fragment_entry,
-+ start_block, offset,
-+ sizeof(fragment_entry), &start_block,
-+ &offset))
-+ goto out;
-+
-+ *fragment_start_block = fragment_entry.start_block;
-+ *fragment_size = fragment_entry.size;
-+
-+ return 1;
-+
-+out:
-+ return 0;
-+}
-+
-+
-+SQSH_EXTERN void release_cached_fragment(struct squashfs_sb_info *msblk, struct
-+ squashfs_fragment_cache *fragment)
-+{
-+ down(&msblk->fragment_mutex);
-+ fragment->locked --;
-+ wake_up(&msblk->fragment_wait_queue);
-+ up(&msblk->fragment_mutex);
-+}
-+
-+
-+SQSH_EXTERN struct squashfs_fragment_cache *get_cached_fragment(struct super_block
-+ *s, long long start_block,
-+ int length)
-+{
-+ int i, n;
-+ struct squashfs_sb_info *msblk = s->s_fs_info;
-+
-+ while ( 1 ) {
-+ down(&msblk->fragment_mutex);
-+
-+ for (i = 0; i < SQUASHFS_CACHED_FRAGMENTS &&
-+ msblk->fragment[i].block != start_block; i++);
-+
-+ if (i == SQUASHFS_CACHED_FRAGMENTS) {
-+ for (i = msblk->next_fragment, n =
-+ SQUASHFS_CACHED_FRAGMENTS; n &&
-+ msblk->fragment[i].locked; n--, i = (i + 1) %
-+ SQUASHFS_CACHED_FRAGMENTS);
-+
-+ if (n == 0) {
-+ wait_queue_t wait;
-+
-+ init_waitqueue_entry(&wait, current);
-+ add_wait_queue(&msblk->fragment_wait_queue,
-+ &wait);
-+ set_current_state(TASK_UNINTERRUPTIBLE);
-+ up(&msblk->fragment_mutex);
-+ schedule();
-+ set_current_state(TASK_RUNNING);
-+ remove_wait_queue(&msblk->fragment_wait_queue,
-+ &wait);
-+ continue;
-+ }
-+ msblk->next_fragment = (msblk->next_fragment + 1) %
-+ SQUASHFS_CACHED_FRAGMENTS;
-+
-+ if (msblk->fragment[i].data == NULL)
-+ if (!(msblk->fragment[i].data = SQUASHFS_ALLOC
-+ (SQUASHFS_FILE_MAX_SIZE))) {
-+ ERROR("Failed to allocate fragment "
-+ "cache block\n");
-+ up(&msblk->fragment_mutex);
-+ goto out;
-+ }
-+
-+ msblk->fragment[i].block = SQUASHFS_INVALID_BLK;
-+ msblk->fragment[i].locked = 1;
-+ up(&msblk->fragment_mutex);
-+
-+ if (!(msblk->fragment[i].length = squashfs_read_data(s,
-+ msblk->fragment[i].data,
-+ start_block, length, NULL))) {
-+ ERROR("Unable to read fragment cache block "
-+ "[%llx]\n", start_block);
-+ msblk->fragment[i].locked = 0;
-+ goto out;
-+ }
-+
-+ msblk->fragment[i].block = start_block;
-+ TRACE("New fragment %d, start block %lld, locked %d\n",
-+ i, msblk->fragment[i].block,
-+ msblk->fragment[i].locked);
-+ break;
-+ }
-+
-+ msblk->fragment[i].locked++;
-+ up(&msblk->fragment_mutex);
-+ TRACE("Got fragment %d, start block %lld, locked %d\n", i,
-+ msblk->fragment[i].block,
-+ msblk->fragment[i].locked);
-+ break;
-+ }
-+
-+ return &msblk->fragment[i];
-+
-+out:
-+ return NULL;
-+}
-+
-+
-+static struct inode *squashfs_new_inode(struct super_block *s,
-+ struct squashfs_base_inode_header *inodeb)
-+{
-+ struct squashfs_sb_info *msblk = s->s_fs_info;
-+ struct inode *i = new_inode(s);
-+
-+ if (i) {
-+ i->i_ino = inodeb->inode_number;
-+ i->i_mtime.tv_sec = inodeb->mtime;
-+ i->i_atime.tv_sec = inodeb->mtime;
-+ i->i_ctime.tv_sec = inodeb->mtime;
-+ i->i_uid = msblk->uid[inodeb->uid];
-+ i->i_mode = inodeb->mode;
-+ i->i_size = 0;
-+ if (inodeb->guid == SQUASHFS_GUIDS)
-+ i->i_gid = i->i_uid;
-+ else
-+ i->i_gid = msblk->guid[inodeb->guid];
-+ }
-+
-+ return i;
-+}
-+
-+
-+static struct inode *squashfs_iget(struct super_block *s, squashfs_inode_t inode)
-+{
-+ struct inode *i;
-+ struct squashfs_sb_info *msblk = s->s_fs_info;
-+ struct squashfs_super_block *sblk = &msblk->sblk;
-+ long long block = SQUASHFS_INODE_BLK(inode) +
-+ sblk->inode_table_start;
-+ unsigned int offset = SQUASHFS_INODE_OFFSET(inode);
-+ long long next_block;
-+ unsigned int next_offset;
-+ union squashfs_inode_header id, sid;
-+ struct squashfs_base_inode_header *inodeb = &id.base,
-+ *sinodeb = &sid.base;
-+
-+ TRACE("Entered squashfs_iget\n");
-+
-+ if (msblk->swap) {
-+ if (!squashfs_get_cached_block(s, (char *) sinodeb, block,
-+ offset, sizeof(*sinodeb), &next_block,
-+ &next_offset))
-+ goto failed_read;
-+ SQUASHFS_SWAP_BASE_INODE_HEADER(inodeb, sinodeb,
-+ sizeof(*sinodeb));
-+ } else
-+ if (!squashfs_get_cached_block(s, (char *) inodeb, block,
-+ offset, sizeof(*inodeb), &next_block,
-+ &next_offset))
-+ goto failed_read;
-+
-+ switch(inodeb->inode_type) {
-+ case SQUASHFS_FILE_TYPE: {
-+ unsigned int frag_size;
-+ long long frag_blk;
-+ struct squashfs_reg_inode_header *inodep = &id.reg;
-+ struct squashfs_reg_inode_header *sinodep = &sid.reg;
-+
-+ if (msblk->swap) {
-+ if (!squashfs_get_cached_block(s, (char *)
-+ sinodep, block, offset,
-+ sizeof(*sinodep), &next_block,
-+ &next_offset))
-+ goto failed_read;
-+ SQUASHFS_SWAP_REG_INODE_HEADER(inodep, sinodep);
-+ } else
-+ if (!squashfs_get_cached_block(s, (char *)
-+ inodep, block, offset,
-+ sizeof(*inodep), &next_block,
-+ &next_offset))
-+ goto failed_read;
-+
-+ frag_blk = SQUASHFS_INVALID_BLK;
-+ if (inodep->fragment != SQUASHFS_INVALID_FRAG &&
-+ !get_fragment_location(s,
-+ inodep->fragment, &frag_blk, &frag_size))
-+ goto failed_read;
-+
-+ if((i = squashfs_new_inode(s, inodeb)) == NULL)
-+ goto failed_read1;
-+
-+ i->i_nlink = 1;
-+ i->i_size = inodep->file_size;
-+ i->i_fop = &generic_ro_fops;
-+ i->i_mode |= S_IFREG;
-+ i->i_blocks = ((i->i_size - 1) >> 9) + 1;
-+ SQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;
-+ SQUASHFS_I(i)->u.s1.fragment_size = frag_size;
-+ SQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;
-+ SQUASHFS_I(i)->start_block = inodep->start_block;
-+ SQUASHFS_I(i)->u.s1.block_list_start = next_block;
-+ SQUASHFS_I(i)->offset = next_offset;
-+ if (sblk->block_size > 4096)
-+ i->i_data.a_ops = &squashfs_aops;
-+ else
-+ i->i_data.a_ops = &squashfs_aops_4K;
-+
-+ TRACE("File inode %x:%x, start_block %llx, "
-+ "block_list_start %llx, offset %x\n",
-+ SQUASHFS_INODE_BLK(inode), offset,
-+ inodep->start_block, next_block,
-+ next_offset);
-+ break;
-+ }
-+ case SQUASHFS_LREG_TYPE: {
-+ unsigned int frag_size;
-+ long long frag_blk;
-+ struct squashfs_lreg_inode_header *inodep = &id.lreg;
-+ struct squashfs_lreg_inode_header *sinodep = &sid.lreg;
-+
-+ if (msblk->swap) {
-+ if (!squashfs_get_cached_block(s, (char *)
-+ sinodep, block, offset,
-+ sizeof(*sinodep), &next_block,
-+ &next_offset))
-+ goto failed_read;
-+ SQUASHFS_SWAP_LREG_INODE_HEADER(inodep, sinodep);
-+ } else
-+ if (!squashfs_get_cached_block(s, (char *)
-+ inodep, block, offset,
-+ sizeof(*inodep), &next_block,
-+ &next_offset))
-+ goto failed_read;
-+
-+ frag_blk = SQUASHFS_INVALID_BLK;
-+ if (inodep->fragment != SQUASHFS_INVALID_FRAG &&
-+ !get_fragment_location(s,
-+ inodep->fragment, &frag_blk, &frag_size))
-+ goto failed_read;
-+
-+ if((i = squashfs_new_inode(s, inodeb)) == NULL)
-+ goto failed_read1;
-+
-+ i->i_nlink = inodep->nlink;
-+ i->i_size = inodep->file_size;
-+ i->i_fop = &generic_ro_fops;
-+ i->i_mode |= S_IFREG;
-+ i->i_blocks = ((i->i_size - 1) >> 9) + 1;
-+ SQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;
-+ SQUASHFS_I(i)->u.s1.fragment_size = frag_size;
-+ SQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;
-+ SQUASHFS_I(i)->start_block = inodep->start_block;
-+ SQUASHFS_I(i)->u.s1.block_list_start = next_block;
-+ SQUASHFS_I(i)->offset = next_offset;
-+ if (sblk->block_size > 4096)
-+ i->i_data.a_ops = &squashfs_aops;
-+ else
-+ i->i_data.a_ops = &squashfs_aops_4K;
-+
-+ TRACE("File inode %x:%x, start_block %llx, "
-+ "block_list_start %llx, offset %x\n",
-+ SQUASHFS_INODE_BLK(inode), offset,
-+ inodep->start_block, next_block,
-+ next_offset);
-+ break;
-+ }
-+ case SQUASHFS_DIR_TYPE: {
-+ struct squashfs_dir_inode_header *inodep = &id.dir;
-+ struct squashfs_dir_inode_header *sinodep = &sid.dir;
-+
-+ if (msblk->swap) {
-+ if (!squashfs_get_cached_block(s, (char *)
-+ sinodep, block, offset,
-+ sizeof(*sinodep), &next_block,
-+ &next_offset))
-+ goto failed_read;
-+ SQUASHFS_SWAP_DIR_INODE_HEADER(inodep, sinodep);
-+ } else
-+ if (!squashfs_get_cached_block(s, (char *)
-+ inodep, block, offset,
-+ sizeof(*inodep), &next_block,
-+ &next_offset))
-+ goto failed_read;
-+
-+ if((i = squashfs_new_inode(s, inodeb)) == NULL)
-+ goto failed_read1;
-+
-+ i->i_nlink = inodep->nlink;
-+ i->i_size = inodep->file_size;
-+ i->i_op = &squashfs_dir_inode_ops;
-+ i->i_fop = &squashfs_dir_ops;
-+ i->i_mode |= S_IFDIR;
-+ SQUASHFS_I(i)->start_block = inodep->start_block;
-+ SQUASHFS_I(i)->offset = inodep->offset;
-+ SQUASHFS_I(i)->u.s2.directory_index_count = 0;
-+ SQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;
-+
-+ TRACE("Directory inode %x:%x, start_block %x, offset "
-+ "%x\n", SQUASHFS_INODE_BLK(inode),
-+ offset, inodep->start_block,
-+ inodep->offset);
-+ break;
-+ }
-+ case SQUASHFS_LDIR_TYPE: {
-+ struct squashfs_ldir_inode_header *inodep = &id.ldir;
-+ struct squashfs_ldir_inode_header *sinodep = &sid.ldir;
-+
-+ if (msblk->swap) {
-+ if (!squashfs_get_cached_block(s, (char *)
-+ sinodep, block, offset,
-+ sizeof(*sinodep), &next_block,
-+ &next_offset))
-+ goto failed_read;
-+ SQUASHFS_SWAP_LDIR_INODE_HEADER(inodep,
-+ sinodep);
-+ } else
-+ if (!squashfs_get_cached_block(s, (char *)
-+ inodep, block, offset,
-+ sizeof(*inodep), &next_block,
-+ &next_offset))
-+ goto failed_read;
-+
-+ if((i = squashfs_new_inode(s, inodeb)) == NULL)
-+ goto failed_read1;
-+
-+ i->i_nlink = inodep->nlink;
-+ i->i_size = inodep->file_size;
-+ i->i_op = &squashfs_dir_inode_ops;
-+ i->i_fop = &squashfs_dir_ops;
-+ i->i_mode |= S_IFDIR;
-+ SQUASHFS_I(i)->start_block = inodep->start_block;
-+ SQUASHFS_I(i)->offset = inodep->offset;
-+ SQUASHFS_I(i)->u.s2.directory_index_start = next_block;
-+ SQUASHFS_I(i)->u.s2.directory_index_offset =
-+ next_offset;
-+ SQUASHFS_I(i)->u.s2.directory_index_count =
-+ inodep->i_count;
-+ SQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;
-+
-+ TRACE("Long directory inode %x:%x, start_block %x, "
-+ "offset %x\n",
-+ SQUASHFS_INODE_BLK(inode), offset,
-+ inodep->start_block, inodep->offset);
-+ break;
-+ }
-+ case SQUASHFS_SYMLINK_TYPE: {
-+ struct squashfs_symlink_inode_header *inodep =
-+ &id.symlink;
-+ struct squashfs_symlink_inode_header *sinodep =
-+ &sid.symlink;
-+
-+ if (msblk->swap) {
-+ if (!squashfs_get_cached_block(s, (char *)
-+ sinodep, block, offset,
-+ sizeof(*sinodep), &next_block,
-+ &next_offset))
-+ goto failed_read;
-+ SQUASHFS_SWAP_SYMLINK_INODE_HEADER(inodep,
-+ sinodep);
-+ } else
-+ if (!squashfs_get_cached_block(s, (char *)
-+ inodep, block, offset,
-+ sizeof(*inodep), &next_block,
-+ &next_offset))
-+ goto failed_read;
-+
-+ if((i = squashfs_new_inode(s, inodeb)) == NULL)
-+ goto failed_read1;
-+
-+ i->i_nlink = inodep->nlink;
-+ i->i_size = inodep->symlink_size;
-+ i->i_op = &page_symlink_inode_operations;
-+ i->i_data.a_ops = &squashfs_symlink_aops;
-+ i->i_mode |= S_IFLNK;
-+ SQUASHFS_I(i)->start_block = next_block;
-+ SQUASHFS_I(i)->offset = next_offset;
-+
-+ TRACE("Symbolic link inode %x:%x, start_block %llx, "
-+ "offset %x\n",
-+ SQUASHFS_INODE_BLK(inode), offset,
-+ next_block, next_offset);
-+ break;
-+ }
-+ case SQUASHFS_BLKDEV_TYPE:
-+ case SQUASHFS_CHRDEV_TYPE: {
-+ struct squashfs_dev_inode_header *inodep = &id.dev;
-+ struct squashfs_dev_inode_header *sinodep = &sid.dev;
-+
-+ if (msblk->swap) {
-+ if (!squashfs_get_cached_block(s, (char *)
-+ sinodep, block, offset,
-+ sizeof(*sinodep), &next_block,
-+ &next_offset))
-+ goto failed_read;
-+ SQUASHFS_SWAP_DEV_INODE_HEADER(inodep, sinodep);
-+ } else
-+ if (!squashfs_get_cached_block(s, (char *)
-+ inodep, block, offset,
-+ sizeof(*inodep), &next_block,
-+ &next_offset))
-+ goto failed_read;
-+
-+ if ((i = squashfs_new_inode(s, inodeb)) == NULL)
-+ goto failed_read1;
-+
-+ i->i_nlink = inodep->nlink;
-+ i->i_mode |= (inodeb->inode_type ==
-+ SQUASHFS_CHRDEV_TYPE) ? S_IFCHR :
-+ S_IFBLK;
-+ init_special_inode(i, i->i_mode,
-+ old_decode_dev(inodep->rdev));
-+
-+ TRACE("Device inode %x:%x, rdev %x\n",
-+ SQUASHFS_INODE_BLK(inode), offset,
-+ inodep->rdev);
-+ break;
-+ }
-+ case SQUASHFS_FIFO_TYPE:
-+ case SQUASHFS_SOCKET_TYPE: {
-+ struct squashfs_ipc_inode_header *inodep = &id.ipc;
-+ struct squashfs_ipc_inode_header *sinodep = &sid.ipc;
-+
-+ if (msblk->swap) {
-+ if (!squashfs_get_cached_block(s, (char *)
-+ sinodep, block, offset,
-+ sizeof(*sinodep), &next_block,
-+ &next_offset))
-+ goto failed_read;
-+ SQUASHFS_SWAP_IPC_INODE_HEADER(inodep, sinodep);
-+ } else
-+ if (!squashfs_get_cached_block(s, (char *)
-+ inodep, block, offset,
-+ sizeof(*inodep), &next_block,
-+ &next_offset))
-+ goto failed_read;
-+
-+ if ((i = squashfs_new_inode(s, inodeb)) == NULL)
-+ goto failed_read1;
-+
-+ i->i_nlink = inodep->nlink;
-+ i->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)
-+ ? S_IFIFO : S_IFSOCK;
-+ init_special_inode(i, i->i_mode, 0);
-+ break;
-+ }
-+ default:
-+ ERROR("Unknown inode type %d in squashfs_iget!\n",
-+ inodeb->inode_type);
-+ goto failed_read1;
-+ }
-+
-+ insert_inode_hash(i);
-+ return i;
-+
-+failed_read:
-+ ERROR("Unable to read inode [%llx:%x]\n", block, offset);
-+
-+failed_read1:
-+ return NULL;
-+}
-+
-+
-+static int read_fragment_index_table(struct super_block *s)
-+{
-+ struct squashfs_sb_info *msblk = s->s_fs_info;
-+ struct squashfs_super_block *sblk = &msblk->sblk;
-+
-+ /* Allocate fragment index table */
-+ if (!(msblk->fragment_index = kmalloc(SQUASHFS_FRAGMENT_INDEX_BYTES
-+ (sblk->fragments), GFP_KERNEL))) {
-+ ERROR("Failed to allocate uid/gid table\n");
-+ return 0;
-+ }
-+
-+ if (SQUASHFS_FRAGMENT_INDEX_BYTES(sblk->fragments) &&
-+ !squashfs_read_data(s, (char *)
-+ msblk->fragment_index,
-+ sblk->fragment_table_start,
-+ SQUASHFS_FRAGMENT_INDEX_BYTES
-+ (sblk->fragments) |
-+ SQUASHFS_COMPRESSED_BIT_BLOCK, NULL)) {
-+ ERROR("unable to read fragment index table\n");
-+ return 0;
-+ }
-+
-+ if (msblk->swap) {
-+ int i;
-+ long long fragment;
-+
-+ for (i = 0; i < SQUASHFS_FRAGMENT_INDEXES(sblk->fragments);
-+ i++) {
-+ SQUASHFS_SWAP_FRAGMENT_INDEXES((&fragment),
-+ &msblk->fragment_index[i], 1);
-+ msblk->fragment_index[i] = fragment;
-+ }
-+ }
-+
-+ return 1;
-+}
-+
-+
-+static int supported_squashfs_filesystem(struct squashfs_sb_info *msblk, int silent)
-+{
-+ struct squashfs_super_block *sblk = &msblk->sblk;
-+
-+ msblk->iget = squashfs_iget;
-+ msblk->read_blocklist = read_blocklist;
-+ msblk->read_fragment_index_table = read_fragment_index_table;
-+
-+ if (sblk->s_major == 1) {
-+ if (!squashfs_1_0_supported(msblk)) {
-+ SERROR("Major/Minor mismatch, Squashfs 1.0 filesystems "
-+ "are unsupported\n");
-+ SERROR("Please recompile with "
-+ "Squashfs 1.0 support enabled\n");
-+ return 0;
-+ }
-+ } else if (sblk->s_major == 2) {
-+ if (!squashfs_2_0_supported(msblk)) {
-+ SERROR("Major/Minor mismatch, Squashfs 2.0 filesystems "
-+ "are unsupported\n");
-+ SERROR("Please recompile with "
-+ "Squashfs 2.0 support enabled\n");
-+ return 0;
-+ }
-+ } else if(sblk->s_major != SQUASHFS_MAJOR || sblk->s_minor >
-+ SQUASHFS_MINOR) {
-+ SERROR("Major/Minor mismatch, trying to mount newer %d.%d "
-+ "filesystem\n", sblk->s_major, sblk->s_minor);
-+ SERROR("Please update your kernel\n");
-+ return 0;
-+ }
-+
-+ return 1;
-+}
-+
-+
-+static int squashfs_fill_super(struct super_block *s, void *data, int silent)
-+{
-+ struct squashfs_sb_info *msblk;
-+ struct squashfs_super_block *sblk;
-+ int i;
-+ char b[BDEVNAME_SIZE];
-+ struct inode *root;
-+
-+ TRACE("Entered squashfs_read_superblock\n");
-+
-+ if (!(s->s_fs_info = kmalloc(sizeof(struct squashfs_sb_info),
-+ GFP_KERNEL))) {
-+ ERROR("Failed to allocate superblock\n");
-+ goto failure;
-+ }
-+ memset(s->s_fs_info, 0, sizeof(struct squashfs_sb_info));
-+ msblk = s->s_fs_info;
-+ sblk = &msblk->sblk;
-+
-+ msblk->devblksize = sb_min_blocksize(s, BLOCK_SIZE);
-+ msblk->devblksize_log2 = ffz(~msblk->devblksize);
-+
-+ init_MUTEX(&msblk->read_data_mutex);
-+ init_MUTEX(&msblk->read_page_mutex);
-+ init_MUTEX(&msblk->block_cache_mutex);
-+ init_MUTEX(&msblk->fragment_mutex);
-+ init_MUTEX(&msblk->meta_index_mutex);
-+
-+ init_waitqueue_head(&msblk->waitq);
-+ init_waitqueue_head(&msblk->fragment_wait_queue);
-+
-+ if (!squashfs_read_data(s, (char *) sblk, SQUASHFS_START,
-+ sizeof(struct squashfs_super_block) |
-+ SQUASHFS_COMPRESSED_BIT_BLOCK, NULL)) {
-+ SERROR("unable to read superblock\n");
-+ goto failed_mount;
-+ }
-+
-+ /* Check it is a SQUASHFS superblock */
-+ msblk->swap = 0;
-+ if ((s->s_magic = sblk->s_magic) != SQUASHFS_MAGIC) {
-+ if (sblk->s_magic == SQUASHFS_MAGIC_SWAP) {
-+ struct squashfs_super_block ssblk;
-+
-+ WARNING("Mounting a different endian SQUASHFS "
-+ "filesystem on %s\n", bdevname(s->s_bdev, b));
-+
-+ SQUASHFS_SWAP_SUPER_BLOCK(&ssblk, sblk);
-+ memcpy(sblk, &ssblk, sizeof(struct squashfs_super_block));
-+ msblk->swap = 1;
-+ } else {
-+ SERROR("Can't find a SQUASHFS superblock on %s\n",
-+ bdevname(s->s_bdev, b));
-+ goto failed_mount;
-+ }
-+ }
-+
-+ /* Check the MAJOR & MINOR versions */
-+ if(!supported_squashfs_filesystem(msblk, silent))
-+ goto failed_mount;
-+
-+ TRACE("Found valid superblock on %s\n", bdevname(s->s_bdev, b));
-+ TRACE("Inodes are %scompressed\n",
-+ SQUASHFS_UNCOMPRESSED_INODES
-+ (sblk->flags) ? "un" : "");
-+ TRACE("Data is %scompressed\n",
-+ SQUASHFS_UNCOMPRESSED_DATA(sblk->flags)
-+ ? "un" : "");
-+ TRACE("Check data is %s present in the filesystem\n",
-+ SQUASHFS_CHECK_DATA(sblk->flags) ?
-+ "" : "not");
-+ TRACE("Filesystem size %lld bytes\n", sblk->bytes_used);
-+ TRACE("Block size %d\n", sblk->block_size);
-+ TRACE("Number of inodes %d\n", sblk->inodes);
-+ if (sblk->s_major > 1)
-+ TRACE("Number of fragments %d\n", sblk->fragments);
-+ TRACE("Number of uids %d\n", sblk->no_uids);
-+ TRACE("Number of gids %d\n", sblk->no_guids);
-+ TRACE("sblk->inode_table_start %llx\n", sblk->inode_table_start);
-+ TRACE("sblk->directory_table_start %llx\n", sblk->directory_table_start);
-+ if (sblk->s_major > 1)
-+ TRACE("sblk->fragment_table_start %llx\n",
-+ sblk->fragment_table_start);
-+ TRACE("sblk->uid_start %llx\n", sblk->uid_start);
-+
-+ s->s_flags |= MS_RDONLY;
-+ s->s_op = &squashfs_ops;
-+
-+ /* Init inode_table block pointer array */
-+ if (!(msblk->block_cache = kmalloc(sizeof(struct squashfs_cache) *
-+ SQUASHFS_CACHED_BLKS, GFP_KERNEL))) {
-+ ERROR("Failed to allocate block cache\n");
-+ goto failed_mount;
-+ }
-+
-+ for (i = 0; i < SQUASHFS_CACHED_BLKS; i++)
-+ msblk->block_cache[i].block = SQUASHFS_INVALID_BLK;
-+
-+ msblk->next_cache = 0;
-+
-+ /* Allocate read_data block */
-+ msblk->read_size = (sblk->block_size < SQUASHFS_METADATA_SIZE) ?
-+ SQUASHFS_METADATA_SIZE :
-+ sblk->block_size;
-+
-+ if (!(msblk->read_data = kmalloc(msblk->read_size, GFP_KERNEL))) {
-+ ERROR("Failed to allocate read_data block\n");
-+ goto failed_mount;
-+ }
-+
-+ /* Allocate read_page block */
-+ if (!(msblk->read_page = kmalloc(sblk->block_size, GFP_KERNEL))) {
-+ ERROR("Failed to allocate read_page block\n");
-+ goto failed_mount;
-+ }
-+
-+ /* Allocate uid and gid tables */
-+ if (!(msblk->uid = kmalloc((sblk->no_uids + sblk->no_guids) *
-+ sizeof(unsigned int), GFP_KERNEL))) {
-+ ERROR("Failed to allocate uid/gid table\n");
-+ goto failed_mount;
-+ }
-+ msblk->guid = msblk->uid + sblk->no_uids;
-+
-+ if (msblk->swap) {
-+ unsigned int suid[sblk->no_uids + sblk->no_guids];
-+
-+ if (!squashfs_read_data(s, (char *) &suid, sblk->uid_start,
-+ ((sblk->no_uids + sblk->no_guids) *
-+ sizeof(unsigned int)) |
-+ SQUASHFS_COMPRESSED_BIT_BLOCK, NULL)) {
-+ ERROR("unable to read uid/gid table\n");
-+ goto failed_mount;
-+ }
-+
-+ SQUASHFS_SWAP_DATA(msblk->uid, suid, (sblk->no_uids +
-+ sblk->no_guids), (sizeof(unsigned int) * 8));
-+ } else
-+ if (!squashfs_read_data(s, (char *) msblk->uid, sblk->uid_start,
-+ ((sblk->no_uids + sblk->no_guids) *
-+ sizeof(unsigned int)) |
-+ SQUASHFS_COMPRESSED_BIT_BLOCK, NULL)) {
-+ ERROR("unable to read uid/gid table\n");
-+ goto failed_mount;
-+ }
-+
-+
-+ if (sblk->s_major == 1 && squashfs_1_0_supported(msblk))
-+ goto allocate_root;
-+
-+ if (!(msblk->fragment = kmalloc(sizeof(struct squashfs_fragment_cache) *
-+ SQUASHFS_CACHED_FRAGMENTS, GFP_KERNEL))) {
-+ ERROR("Failed to allocate fragment block cache\n");
-+ goto failed_mount;
-+ }
-+
-+ for (i = 0; i < SQUASHFS_CACHED_FRAGMENTS; i++) {
-+ msblk->fragment[i].locked = 0;
-+ msblk->fragment[i].block = SQUASHFS_INVALID_BLK;
-+ msblk->fragment[i].data = NULL;
-+ }
-+
-+ msblk->next_fragment = 0;
-+
-+ /* Allocate fragment index table */
-+ if (msblk->read_fragment_index_table(s) == 0)
-+ goto failed_mount;
-+
-+allocate_root:
-+ if ((root = (msblk->iget)(s, sblk->root_inode)) == NULL)
-+ goto failed_mount;
-+
-+ if ((s->s_root = d_alloc_root(root)) == NULL) {
-+ ERROR("Root inode create failed\n");
-+ iput(root);
-+ goto failed_mount;
-+ }
-+
-+ TRACE("Leaving squashfs_read_super\n");
-+ return 0;
-+
-+failed_mount:
-+ kfree(msblk->fragment_index);
-+ kfree(msblk->fragment);
-+ kfree(msblk->uid);
-+ kfree(msblk->read_page);
-+ kfree(msblk->read_data);
-+ kfree(msblk->block_cache);
-+ kfree(msblk->fragment_index_2);
-+ kfree(s->s_fs_info);
-+ s->s_fs_info = NULL;
-+ return -EINVAL;
-+
-+failure:
-+ return -ENOMEM;
-+}
-+
-+
-+static int squashfs_statfs(struct dentry *dentry, struct kstatfs *buf)
-+{
-+ struct squashfs_sb_info *msblk = dentry->d_inode->i_sb->s_fs_info;
-+ struct squashfs_super_block *sblk = &msblk->sblk;
-+
-+ TRACE("Entered squashfs_statfs\n");
-+
-+ buf->f_type = SQUASHFS_MAGIC;
-+ buf->f_bsize = sblk->block_size;
-+ buf->f_blocks = ((sblk->bytes_used - 1) >> sblk->block_log) + 1;
-+ buf->f_bfree = buf->f_bavail = 0;
-+ buf->f_files = sblk->inodes;
-+ buf->f_ffree = 0;
-+ buf->f_namelen = SQUASHFS_NAME_LEN;
-+
-+ return 0;
-+}
-+
-+
-+static int squashfs_symlink_readpage(struct file *file, struct page *page)
-+{
-+ struct inode *inode = page->mapping->host;
-+ int index = page->index << PAGE_CACHE_SHIFT, length, bytes;
-+ long long block = SQUASHFS_I(inode)->start_block;
-+ int offset = SQUASHFS_I(inode)->offset;
-+ void *pageaddr = kmap(page);
-+
-+ TRACE("Entered squashfs_symlink_readpage, page index %ld, start block "
-+ "%llx, offset %x\n", page->index,
-+ SQUASHFS_I(inode)->start_block,
-+ SQUASHFS_I(inode)->offset);
-+
-+ for (length = 0; length < index; length += bytes) {
-+ if (!(bytes = squashfs_get_cached_block(inode->i_sb, NULL,
-+ block, offset, PAGE_CACHE_SIZE, &block,
-+ &offset))) {
-+ ERROR("Unable to read symbolic link [%llx:%x]\n", block,
-+ offset);
-+ goto skip_read;
-+ }
-+ }
-+
-+ if (length != index) {
-+ ERROR("(squashfs_symlink_readpage) length != index\n");
-+ bytes = 0;
-+ goto skip_read;
-+ }
-+
-+ bytes = (i_size_read(inode) - length) > PAGE_CACHE_SIZE ? PAGE_CACHE_SIZE :
-+ i_size_read(inode) - length;
-+
-+ if (!(bytes = squashfs_get_cached_block(inode->i_sb, pageaddr, block,
-+ offset, bytes, &block, &offset)))
-+ ERROR("Unable to read symbolic link [%llx:%x]\n", block, offset);
-+
-+skip_read:
-+ memset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);
-+ kunmap(page);
-+ SetPageUptodate(page);
-+ unlock_page(page);
-+
-+ return 0;
-+}
-+
-+
-+struct meta_index *locate_meta_index(struct inode *inode, int index, int offset)
-+{
-+ struct meta_index *meta = NULL;
-+ struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
-+ int i;
-+
-+ down(&msblk->meta_index_mutex);
-+
-+ TRACE("locate_meta_index: index %d, offset %d\n", index, offset);
-+
-+ if(msblk->meta_index == NULL)
-+ goto not_allocated;
-+
-+ for (i = 0; i < SQUASHFS_META_NUMBER; i ++)
-+ if (msblk->meta_index[i].inode_number == inode->i_ino &&
-+ msblk->meta_index[i].offset >= offset &&
-+ msblk->meta_index[i].offset <= index &&
-+ msblk->meta_index[i].locked == 0) {
-+ TRACE("locate_meta_index: entry %d, offset %d\n", i,
-+ msblk->meta_index[i].offset);
-+ meta = &msblk->meta_index[i];
-+ offset = meta->offset;
-+ }
-+
-+ if (meta)
-+ meta->locked = 1;
-+
-+not_allocated:
-+ up(&msblk->meta_index_mutex);
-+
-+ return meta;
-+}
-+
-+
-+struct meta_index *empty_meta_index(struct inode *inode, int offset, int skip)
-+{
-+ struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
-+ struct meta_index *meta = NULL;
-+ int i;
-+
-+ down(&msblk->meta_index_mutex);
-+
-+ TRACE("empty_meta_index: offset %d, skip %d\n", offset, skip);
-+
-+ if(msblk->meta_index == NULL) {
-+ if (!(msblk->meta_index = kmalloc(sizeof(struct meta_index) *
-+ SQUASHFS_META_NUMBER, GFP_KERNEL))) {
-+ ERROR("Failed to allocate meta_index\n");
-+ goto failed;
-+ }
-+ for(i = 0; i < SQUASHFS_META_NUMBER; i++) {
-+ msblk->meta_index[i].inode_number = 0;
-+ msblk->meta_index[i].locked = 0;
-+ }
-+ msblk->next_meta_index = 0;
-+ }
-+
-+ for(i = SQUASHFS_META_NUMBER; i &&
-+ msblk->meta_index[msblk->next_meta_index].locked; i --)
-+ msblk->next_meta_index = (msblk->next_meta_index + 1) %
-+ SQUASHFS_META_NUMBER;
-+
-+ if(i == 0) {
-+ TRACE("empty_meta_index: failed!\n");
-+ goto failed;
-+ }
-+
-+ TRACE("empty_meta_index: returned meta entry %d, %p\n",
-+ msblk->next_meta_index,
-+ &msblk->meta_index[msblk->next_meta_index]);
-+
-+ meta = &msblk->meta_index[msblk->next_meta_index];
-+ msblk->next_meta_index = (msblk->next_meta_index + 1) %
-+ SQUASHFS_META_NUMBER;
-+
-+ meta->inode_number = inode->i_ino;
-+ meta->offset = offset;
-+ meta->skip = skip;
-+ meta->entries = 0;
-+ meta->locked = 1;
-+
-+failed:
-+ up(&msblk->meta_index_mutex);
-+ return meta;
-+}
-+
-+
-+void release_meta_index(struct inode *inode, struct meta_index *meta)
-+{
-+ meta->locked = 0;
-+}
-+
-+
-+static int read_block_index(struct super_block *s, int blocks, char *block_list,
-+ long long *start_block, int *offset)
-+{
-+ struct squashfs_sb_info *msblk = s->s_fs_info;
-+ unsigned int *block_listp;
-+ int block = 0;
-+
-+ if (msblk->swap) {
-+ char sblock_list[blocks << 2];
-+
-+ if (!squashfs_get_cached_block(s, sblock_list, *start_block,
-+ *offset, blocks << 2, start_block, offset)) {
-+ ERROR("Unable to read block list [%llx:%x]\n",
-+ *start_block, *offset);
-+ goto failure;
-+ }
-+ SQUASHFS_SWAP_INTS(((unsigned int *)block_list),
-+ ((unsigned int *)sblock_list), blocks);
-+ } else
-+ if (!squashfs_get_cached_block(s, block_list, *start_block,
-+ *offset, blocks << 2, start_block, offset)) {
-+ ERROR("Unable to read block list [%llx:%x]\n",
-+ *start_block, *offset);
-+ goto failure;
-+ }
-+
-+ for (block_listp = (unsigned int *) block_list; blocks;
-+ block_listp++, blocks --)
-+ block += SQUASHFS_COMPRESSED_SIZE_BLOCK(*block_listp);
-+
-+ return block;
-+
-+failure:
-+ return -1;
-+}
-+
-+
-+#define SIZE 256
-+
-+static inline int calculate_skip(int blocks) {
-+ int skip = (blocks - 1) / ((SQUASHFS_SLOTS * SQUASHFS_META_ENTRIES + 1) * SQUASHFS_META_INDEXES);
-+ return skip >= 7 ? 7 : skip + 1;
-+}
-+
-+
-+static int get_meta_index(struct inode *inode, int index,
-+ long long *index_block, int *index_offset,
-+ long long *data_block, char *block_list)
-+{
-+ struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
-+ struct squashfs_super_block *sblk = &msblk->sblk;
-+ int skip = calculate_skip(i_size_read(inode) >> sblk->block_log);
-+ int offset = 0;
-+ struct meta_index *meta;
-+ struct meta_entry *meta_entry;
-+ long long cur_index_block = SQUASHFS_I(inode)->u.s1.block_list_start;
-+ int cur_offset = SQUASHFS_I(inode)->offset;
-+ long long cur_data_block = SQUASHFS_I(inode)->start_block;
-+ int i;
-+
-+ index /= SQUASHFS_META_INDEXES * skip;
-+
-+ while ( offset < index ) {
-+ meta = locate_meta_index(inode, index, offset + 1);
-+
-+ if (meta == NULL) {
-+ if ((meta = empty_meta_index(inode, offset + 1,
-+ skip)) == NULL)
-+ goto all_done;
-+ } else {
-+ offset = index < meta->offset + meta->entries ? index :
-+ meta->offset + meta->entries - 1;
-+ meta_entry = &meta->meta_entry[offset - meta->offset];
-+ cur_index_block = meta_entry->index_block + sblk->inode_table_start;
-+ cur_offset = meta_entry->offset;
-+ cur_data_block = meta_entry->data_block;
-+ TRACE("get_meta_index: offset %d, meta->offset %d, "
-+ "meta->entries %d\n", offset, meta->offset,
-+ meta->entries);
-+ TRACE("get_meta_index: index_block 0x%llx, offset 0x%x"
-+ " data_block 0x%llx\n", cur_index_block,
-+ cur_offset, cur_data_block);
-+ }
-+
-+ for (i = meta->offset + meta->entries; i <= index &&
-+ i < meta->offset + SQUASHFS_META_ENTRIES; i++) {
-+ int blocks = skip * SQUASHFS_META_INDEXES;
-+
-+ while (blocks) {
-+ int block = blocks > (SIZE >> 2) ? (SIZE >> 2) :
-+ blocks;
-+ int res = read_block_index(inode->i_sb, block,
-+ block_list, &cur_index_block,
-+ &cur_offset);
-+
-+ if (res == -1)
-+ goto failed;
-+
-+ cur_data_block += res;
-+ blocks -= block;
-+ }
-+
-+ meta_entry = &meta->meta_entry[i - meta->offset];
-+ meta_entry->index_block = cur_index_block - sblk->inode_table_start;
-+ meta_entry->offset = cur_offset;
-+ meta_entry->data_block = cur_data_block;
-+ meta->entries ++;
-+ offset ++;
-+ }
-+
-+ TRACE("get_meta_index: meta->offset %d, meta->entries %d\n",
-+ meta->offset, meta->entries);
-+
-+ release_meta_index(inode, meta);
-+ }
-+
-+all_done:
-+ *index_block = cur_index_block;
-+ *index_offset = cur_offset;
-+ *data_block = cur_data_block;
-+
-+ return offset * SQUASHFS_META_INDEXES * skip;
-+
-+failed:
-+ release_meta_index(inode, meta);
-+ return -1;
-+}
-+
-+
-+static long long read_blocklist(struct inode *inode, int index,
-+ int readahead_blks, char *block_list,
-+ unsigned short **block_p, unsigned int *bsize)
-+{
-+ long long block_ptr;
-+ int offset;
-+ long long block;
-+ int res = get_meta_index(inode, index, &block_ptr, &offset, &block,
-+ block_list);
-+
-+ TRACE("read_blocklist: res %d, index %d, block_ptr 0x%llx, offset"
-+ " 0x%x, block 0x%llx\n", res, index, block_ptr, offset,
-+ block);
-+
-+ if(res == -1)
-+ goto failure;
-+
-+ index -= res;
-+
-+ while ( index ) {
-+ int blocks = index > (SIZE >> 2) ? (SIZE >> 2) : index;
-+ int res = read_block_index(inode->i_sb, blocks, block_list,
-+ &block_ptr, &offset);
-+ if (res == -1)
-+ goto failure;
-+ block += res;
-+ index -= blocks;
-+ }
-+
-+ if (read_block_index(inode->i_sb, 1, block_list,
-+ &block_ptr, &offset) == -1)
-+ goto failure;
-+ *bsize = *((unsigned int *) block_list);
-+
-+ return block;
-+
-+failure:
-+ return 0;
-+}
-+
-+
-+static int squashfs_readpage(struct file *file, struct page *page)
-+{
-+ struct inode *inode = page->mapping->host;
-+ struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
-+ struct squashfs_super_block *sblk = &msblk->sblk;
-+ unsigned char block_list[SIZE];
-+ long long block;
-+ unsigned int bsize, i = 0, bytes = 0, byte_offset = 0;
-+ int index = page->index >> (sblk->block_log - PAGE_CACHE_SHIFT);
-+ void *pageaddr;
-+ struct squashfs_fragment_cache *fragment = NULL;
-+ char *data_ptr = msblk->read_page;
-+
-+ int mask = (1 << (sblk->block_log - PAGE_CACHE_SHIFT)) - 1;
-+ int start_index = page->index & ~mask;
-+ int end_index = start_index | mask;
-+
-+ TRACE("Entered squashfs_readpage, page index %lx, start block %llx\n",
-+ page->index,
-+ SQUASHFS_I(inode)->start_block);
-+
-+ if (page->index >= ((i_size_read(inode) + PAGE_CACHE_SIZE - 1) >>
-+ PAGE_CACHE_SHIFT))
-+ goto skip_read;
-+
-+ if (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK
-+ || index < (i_size_read(inode) >>
-+ sblk->block_log)) {
-+ if ((block = (msblk->read_blocklist)(inode, index, 1,
-+ block_list, NULL, &bsize)) == 0)
-+ goto skip_read;
-+
-+ down(&msblk->read_page_mutex);
-+
-+ if (!(bytes = squashfs_read_data(inode->i_sb, msblk->read_page,
-+ block, bsize, NULL))) {
-+ ERROR("Unable to read page, block %llx, size %x\n", block,
-+ bsize);
-+ up(&msblk->read_page_mutex);
-+ goto skip_read;
-+ }
-+ } else {
-+ if ((fragment = get_cached_fragment(inode->i_sb,
-+ SQUASHFS_I(inode)->
-+ u.s1.fragment_start_block,
-+ SQUASHFS_I(inode)->u.s1.fragment_size))
-+ == NULL) {
-+ ERROR("Unable to read page, block %llx, size %x\n",
-+ SQUASHFS_I(inode)->
-+ u.s1.fragment_start_block,
-+ (int) SQUASHFS_I(inode)->
-+ u.s1.fragment_size);
-+ goto skip_read;
-+ }
-+ bytes = SQUASHFS_I(inode)->u.s1.fragment_offset +
-+ (i_size_read(inode) & (sblk->block_size
-+ - 1));
-+ byte_offset = SQUASHFS_I(inode)->u.s1.fragment_offset;
-+ data_ptr = fragment->data;
-+ }
-+
-+ for (i = start_index; i <= end_index && byte_offset < bytes;
-+ i++, byte_offset += PAGE_CACHE_SIZE) {
-+ struct page *push_page;
-+ int available_bytes = (bytes - byte_offset) > PAGE_CACHE_SIZE ?
-+ PAGE_CACHE_SIZE : bytes - byte_offset;
-+
-+ TRACE("bytes %d, i %d, byte_offset %d, available_bytes %d\n",
-+ bytes, i, byte_offset, available_bytes);
-+
-+ if (i == page->index) {
-+ pageaddr = kmap_atomic(page, KM_USER0);
-+ memcpy(pageaddr, data_ptr + byte_offset,
-+ available_bytes);
-+ memset(pageaddr + available_bytes, 0,
-+ PAGE_CACHE_SIZE - available_bytes);
-+ kunmap_atomic(pageaddr, KM_USER0);
-+ flush_dcache_page(page);
-+ SetPageUptodate(page);
-+ unlock_page(page);
-+ } else if ((push_page =
-+ grab_cache_page_nowait(page->mapping, i))) {
-+ pageaddr = kmap_atomic(push_page, KM_USER0);
-+
-+ memcpy(pageaddr, data_ptr + byte_offset,
-+ available_bytes);
-+ memset(pageaddr + available_bytes, 0,
-+ PAGE_CACHE_SIZE - available_bytes);
-+ kunmap_atomic(pageaddr, KM_USER0);
-+ flush_dcache_page(push_page);
-+ SetPageUptodate(push_page);
-+ unlock_page(push_page);
-+ page_cache_release(push_page);
-+ }
-+ }
-+
-+ if (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK
-+ || index < (i_size_read(inode) >>
-+ sblk->block_log))
-+ up(&msblk->read_page_mutex);
-+ else
-+ release_cached_fragment(msblk, fragment);
-+
-+ return 0;
-+
-+skip_read:
-+ pageaddr = kmap_atomic(page, KM_USER0);
-+ memset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);
-+ kunmap_atomic(pageaddr, KM_USER0);
-+ flush_dcache_page(page);
-+ SetPageUptodate(page);
-+ unlock_page(page);
-+
-+ return 0;
-+}
-+
-+
-+static int squashfs_readpage4K(struct file *file, struct page *page)
-+{
-+ struct inode *inode = page->mapping->host;
-+ struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
-+ struct squashfs_super_block *sblk = &msblk->sblk;
-+ unsigned char block_list[SIZE];
-+ long long block;
-+ unsigned int bsize, bytes = 0;
-+ void *pageaddr;
-+
-+ TRACE("Entered squashfs_readpage4K, page index %lx, start block %llx\n",
-+ page->index,
-+ SQUASHFS_I(inode)->start_block);
-+
-+ if (page->index >= ((i_size_read(inode) + PAGE_CACHE_SIZE - 1) >>
-+ PAGE_CACHE_SHIFT)) {
-+ pageaddr = kmap_atomic(page, KM_USER0);
-+ goto skip_read;
-+ }
-+
-+ if (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK
-+ || page->index < (i_size_read(inode) >>
-+ sblk->block_log)) {
-+ block = (msblk->read_blocklist)(inode, page->index, 1,
-+ block_list, NULL, &bsize);
-+
-+ down(&msblk->read_page_mutex);
-+ bytes = squashfs_read_data(inode->i_sb, msblk->read_page, block,
-+ bsize, NULL);
-+ pageaddr = kmap_atomic(page, KM_USER0);
-+ if (bytes)
-+ memcpy(pageaddr, msblk->read_page, bytes);
-+ else
-+ ERROR("Unable to read page, block %llx, size %x\n",
-+ block, bsize);
-+ up(&msblk->read_page_mutex);
-+ } else {
-+ struct squashfs_fragment_cache *fragment =
-+ get_cached_fragment(inode->i_sb,
-+ SQUASHFS_I(inode)->
-+ u.s1.fragment_start_block,
-+ SQUASHFS_I(inode)-> u.s1.fragment_size);
-+ pageaddr = kmap_atomic(page, KM_USER0);
-+ if (fragment) {
-+ bytes = i_size_read(inode) & (sblk->block_size - 1);
-+ memcpy(pageaddr, fragment->data + SQUASHFS_I(inode)->
-+ u.s1.fragment_offset, bytes);
-+ release_cached_fragment(msblk, fragment);
-+ } else
-+ ERROR("Unable to read page, block %llx, size %x\n",
-+ SQUASHFS_I(inode)->
-+ u.s1.fragment_start_block, (int)
-+ SQUASHFS_I(inode)-> u.s1.fragment_size);
-+ }
-+
-+skip_read:
-+ memset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);
-+ kunmap_atomic(pageaddr, KM_USER0);
-+ flush_dcache_page(page);
-+ SetPageUptodate(page);
-+ unlock_page(page);
-+
-+ return 0;
-+}
-+
-+
-+static int get_dir_index_using_offset(struct super_block *s, long long
-+ *next_block, unsigned int *next_offset,
-+ long long index_start,
-+ unsigned int index_offset, int i_count,
-+ long long f_pos)
-+{
-+ struct squashfs_sb_info *msblk = s->s_fs_info;
-+ struct squashfs_super_block *sblk = &msblk->sblk;
-+ int i, length = 0;
-+ struct squashfs_dir_index index;
-+
-+ TRACE("Entered get_dir_index_using_offset, i_count %d, f_pos %d\n",
-+ i_count, (unsigned int) f_pos);
-+
-+ f_pos =- 3;
-+ if (f_pos == 0)
-+ goto finish;
-+
-+ for (i = 0; i < i_count; i++) {
-+ if (msblk->swap) {
-+ struct squashfs_dir_index sindex;
-+ squashfs_get_cached_block(s, (char *) &sindex,
-+ index_start, index_offset,
-+ sizeof(sindex), &index_start,
-+ &index_offset);
-+ SQUASHFS_SWAP_DIR_INDEX(&index, &sindex);
-+ } else
-+ squashfs_get_cached_block(s, (char *) &index,
-+ index_start, index_offset,
-+ sizeof(index), &index_start,
-+ &index_offset);
-+
-+ if (index.index > f_pos)
-+ break;
-+
-+ squashfs_get_cached_block(s, NULL, index_start, index_offset,
-+ index.size + 1, &index_start,
-+ &index_offset);
-+
-+ length = index.index;
-+ *next_block = index.start_block + sblk->directory_table_start;
-+ }
-+
-+ *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
-+
-+finish:
-+ return length + 3;
-+}
-+
-+
-+static int get_dir_index_using_name(struct super_block *s, long long
-+ *next_block, unsigned int *next_offset,
-+ long long index_start,
-+ unsigned int index_offset, int i_count,
-+ const char *name, int size)
-+{
-+ struct squashfs_sb_info *msblk = s->s_fs_info;
-+ struct squashfs_super_block *sblk = &msblk->sblk;
-+ int i, length = 0;
-+ char buffer[sizeof(struct squashfs_dir_index) + SQUASHFS_NAME_LEN + 1];
-+ struct squashfs_dir_index *index = (struct squashfs_dir_index *) buffer;
-+ char str[SQUASHFS_NAME_LEN + 1];
-+
-+ TRACE("Entered get_dir_index_using_name, i_count %d\n", i_count);
-+
-+ strncpy(str, name, size);
-+ str[size] = '\0';
-+
-+ for (i = 0; i < i_count; i++) {
-+ if (msblk->swap) {
-+ struct squashfs_dir_index sindex;
-+ squashfs_get_cached_block(s, (char *) &sindex,
-+ index_start, index_offset,
-+ sizeof(sindex), &index_start,
-+ &index_offset);
-+ SQUASHFS_SWAP_DIR_INDEX(index, &sindex);
-+ } else
-+ squashfs_get_cached_block(s, (char *) index,
-+ index_start, index_offset,
-+ sizeof(struct squashfs_dir_index),
-+ &index_start, &index_offset);
-+
-+ squashfs_get_cached_block(s, index->name, index_start,
-+ index_offset, index->size + 1,
-+ &index_start, &index_offset);
-+
-+ index->name[index->size + 1] = '\0';
-+
-+ if (strcmp(index->name, str) > 0)
-+ break;
-+
-+ length = index->index;
-+ *next_block = index->start_block + sblk->directory_table_start;
-+ }
-+
-+ *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
-+ return length + 3;
-+}
-+
-+
-+static int squashfs_readdir(struct file *file, void *dirent, filldir_t filldir)
-+{
-+ struct inode *i = file->f_dentry->d_inode;
-+ struct squashfs_sb_info *msblk = i->i_sb->s_fs_info;
-+ struct squashfs_super_block *sblk = &msblk->sblk;
-+ long long next_block = SQUASHFS_I(i)->start_block +
-+ sblk->directory_table_start;
-+ int next_offset = SQUASHFS_I(i)->offset, length = 0, dirs_read = 0,
-+ dir_count;
-+ struct squashfs_dir_header dirh;
-+ char buffer[sizeof(struct squashfs_dir_entry) + SQUASHFS_NAME_LEN + 1];
-+ struct squashfs_dir_entry *dire = (struct squashfs_dir_entry *) buffer;
-+
-+ TRACE("Entered squashfs_readdir [%llx:%x]\n", next_block, next_offset);
-+
-+ while(file->f_pos < 3) {
-+ char *name;
-+ int size, i_ino;
-+
-+ if(file->f_pos == 0) {
-+ name = ".";
-+ size = 1;
-+ i_ino = i->i_ino;
-+ } else {
-+ name = "..";
-+ size = 2;
-+ i_ino = SQUASHFS_I(i)->u.s2.parent_inode;
-+ }
-+ TRACE("Calling filldir(%x, %s, %d, %d, %d, %d)\n",
-+ (unsigned int) dirent, name, size, (int)
-+ file->f_pos, i_ino,
-+ squashfs_filetype_table[1]);
-+
-+ if (filldir(dirent, name, size,
-+ file->f_pos, i_ino,
-+ squashfs_filetype_table[1]) < 0) {
-+ TRACE("Filldir returned less than 0\n");
-+ goto finish;
-+ }
-+ file->f_pos += size;
-+ dirs_read++;
-+ }
-+
-+ length = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,
-+ SQUASHFS_I(i)->u.s2.directory_index_start,
-+ SQUASHFS_I(i)->u.s2.directory_index_offset,
-+ SQUASHFS_I(i)->u.s2.directory_index_count,
-+ file->f_pos);
-+
-+ while (length < i_size_read(i)) {
-+ /* read directory header */
-+ if (msblk->swap) {
-+ struct squashfs_dir_header sdirh;
-+
-+ if (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,
-+ next_block, next_offset, sizeof(sdirh),
-+ &next_block, &next_offset))
-+ goto failed_read;
-+
-+ length += sizeof(sdirh);
-+ SQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);
-+ } else {
-+ if (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,
-+ next_block, next_offset, sizeof(dirh),
-+ &next_block, &next_offset))
-+ goto failed_read;
-+
-+ length += sizeof(dirh);
-+ }
-+
-+ dir_count = dirh.count + 1;
-+ while (dir_count--) {
-+ if (msblk->swap) {
-+ struct squashfs_dir_entry sdire;
-+ if (!squashfs_get_cached_block(i->i_sb, (char *)
-+ &sdire, next_block, next_offset,
-+ sizeof(sdire), &next_block,
-+ &next_offset))
-+ goto failed_read;
-+
-+ length += sizeof(sdire);
-+ SQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);
-+ } else {
-+ if (!squashfs_get_cached_block(i->i_sb, (char *)
-+ dire, next_block, next_offset,
-+ sizeof(*dire), &next_block,
-+ &next_offset))
-+ goto failed_read;
-+
-+ length += sizeof(*dire);
-+ }
-+
-+ if (!squashfs_get_cached_block(i->i_sb, dire->name,
-+ next_block, next_offset,
-+ dire->size + 1, &next_block,
-+ &next_offset))
-+ goto failed_read;
-+
-+ length += dire->size + 1;
-+
-+ if (file->f_pos >= length)
-+ continue;
-+
-+ dire->name[dire->size + 1] = '\0';
-+
-+ TRACE("Calling filldir(%x, %s, %d, %d, %x:%x, %d, %d)\n",
-+ (unsigned int) dirent, dire->name,
-+ dire->size + 1, (int) file->f_pos,
-+ dirh.start_block, dire->offset,
-+ dirh.inode_number + dire->inode_number,
-+ squashfs_filetype_table[dire->type]);
-+
-+ if (filldir(dirent, dire->name, dire->size + 1,
-+ file->f_pos,
-+ dirh.inode_number + dire->inode_number,
-+ squashfs_filetype_table[dire->type])
-+ < 0) {
-+ TRACE("Filldir returned less than 0\n");
-+ goto finish;
-+ }
-+ file->f_pos = length;
-+ dirs_read++;
-+ }
-+ }
-+
-+finish:
-+ return dirs_read;
-+
-+failed_read:
-+ ERROR("Unable to read directory block [%llx:%x]\n", next_block,
-+ next_offset);
-+ return 0;
-+}
-+
-+
-+static struct dentry *squashfs_lookup(struct inode *i, struct dentry *dentry,
-+ struct nameidata *nd)
-+{
-+ const unsigned char *name = dentry->d_name.name;
-+ int len = dentry->d_name.len;
-+ struct inode *inode = NULL;
-+ struct squashfs_sb_info *msblk = i->i_sb->s_fs_info;
-+ struct squashfs_super_block *sblk = &msblk->sblk;
-+ long long next_block = SQUASHFS_I(i)->start_block +
-+ sblk->directory_table_start;
-+ int next_offset = SQUASHFS_I(i)->offset, length = 0,
-+ dir_count;
-+ struct squashfs_dir_header dirh;
-+ char buffer[sizeof(struct squashfs_dir_entry) + SQUASHFS_NAME_LEN];
-+ struct squashfs_dir_entry *dire = (struct squashfs_dir_entry *) buffer;
-+
-+ TRACE("Entered squashfs_lookup [%llx:%x]\n", next_block, next_offset);
-+
-+ if (len > SQUASHFS_NAME_LEN)
-+ goto exit_loop;
-+
-+ length = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,
-+ SQUASHFS_I(i)->u.s2.directory_index_start,
-+ SQUASHFS_I(i)->u.s2.directory_index_offset,
-+ SQUASHFS_I(i)->u.s2.directory_index_count, name,
-+ len);
-+
-+ while (length < i_size_read(i)) {
-+ /* read directory header */
-+ if (msblk->swap) {
-+ struct squashfs_dir_header sdirh;
-+ if (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,
-+ next_block, next_offset, sizeof(sdirh),
-+ &next_block, &next_offset))
-+ goto failed_read;
-+
-+ length += sizeof(sdirh);
-+ SQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);
-+ } else {
-+ if (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,
-+ next_block, next_offset, sizeof(dirh),
-+ &next_block, &next_offset))
-+ goto failed_read;
-+
-+ length += sizeof(dirh);
-+ }
-+
-+ dir_count = dirh.count + 1;
-+ while (dir_count--) {
-+ if (msblk->swap) {
-+ struct squashfs_dir_entry sdire;
-+ if (!squashfs_get_cached_block(i->i_sb, (char *)
-+ &sdire, next_block,next_offset,
-+ sizeof(sdire), &next_block,
-+ &next_offset))
-+ goto failed_read;
-+
-+ length += sizeof(sdire);
-+ SQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);
-+ } else {
-+ if (!squashfs_get_cached_block(i->i_sb, (char *)
-+ dire, next_block,next_offset,
-+ sizeof(*dire), &next_block,
-+ &next_offset))
-+ goto failed_read;
-+
-+ length += sizeof(*dire);
-+ }
-+
-+ if (!squashfs_get_cached_block(i->i_sb, dire->name,
-+ next_block, next_offset, dire->size + 1,
-+ &next_block, &next_offset))
-+ goto failed_read;
-+
-+ length += dire->size + 1;
-+
-+ if (name[0] < dire->name[0])
-+ goto exit_loop;
-+
-+ if ((len == dire->size + 1) && !strncmp(name,
-+ dire->name, len)) {
-+ squashfs_inode_t ino =
-+ SQUASHFS_MKINODE(dirh.start_block,
-+ dire->offset);
-+
-+ TRACE("calling squashfs_iget for directory "
-+ "entry %s, inode %x:%x, %d\n", name,
-+ dirh.start_block, dire->offset,
-+ dirh.inode_number + dire->inode_number);
-+
-+ inode = (msblk->iget)(i->i_sb, ino);
-+
-+ goto exit_loop;
-+ }
-+ }
-+ }
-+
-+exit_loop:
-+ d_add(dentry, inode);
-+ return ERR_PTR(0);
-+
-+failed_read:
-+ ERROR("Unable to read directory block [%llx:%x]\n", next_block,
-+ next_offset);
-+ goto exit_loop;
-+}
-+
-+
-+static void squashfs_put_super(struct super_block *s)
-+{
-+ int i;
-+
-+ if (s->s_fs_info) {
-+ struct squashfs_sb_info *sbi = s->s_fs_info;
-+ if (sbi->block_cache)
-+ for (i = 0; i < SQUASHFS_CACHED_BLKS; i++)
-+ if (sbi->block_cache[i].block !=
-+ SQUASHFS_INVALID_BLK)
-+ kfree(sbi->block_cache[i].data);
-+ if (sbi->fragment)
-+ for (i = 0; i < SQUASHFS_CACHED_FRAGMENTS; i++)
-+ SQUASHFS_FREE(sbi->fragment[i].data);
-+ kfree(sbi->fragment);
-+ kfree(sbi->block_cache);
-+ kfree(sbi->read_data);
-+ kfree(sbi->read_page);
-+ kfree(sbi->uid);
-+ kfree(sbi->fragment_index);
-+ kfree(sbi->fragment_index_2);
-+ kfree(sbi->meta_index);
-+ kfree(s->s_fs_info);
-+ s->s_fs_info = NULL;
-+ }
-+}
-+
-+
-+static int squashfs_get_sb(struct file_system_type *fs_type,
-+ int flags, const char *dev_name, void *data,
-+ struct vfsmount *mnt)
-+{
-+ return get_sb_bdev(fs_type, flags, dev_name, data, squashfs_fill_super, mnt);
-+}
-+
-+
-+static int __init init_squashfs_fs(void)
-+{
-+ int err = init_inodecache();
-+ if (err)
-+ goto out;
-+
-+ printk(KERN_INFO "squashfs: version 3.0 (2006/03/15) "
-+ "Phillip Lougher\n");
-+
-+ if (!(stream.workspace = vmalloc(zlib_inflate_workspacesize()))) {
-+ ERROR("Failed to allocate zlib workspace\n");
-+ destroy_inodecache();
-+ err = -ENOMEM;
-+ goto out;
-+ }
-+
-+ if ((err = register_filesystem(&squashfs_fs_type))) {
-+ vfree(stream.workspace);
-+ destroy_inodecache();
-+ }
-+
-+out:
-+ return err;
-+}
-+
-+
-+static void __exit exit_squashfs_fs(void)
-+{
-+ vfree(stream.workspace);
-+ unregister_filesystem(&squashfs_fs_type);
-+ destroy_inodecache();
-+}
-+
-+
-+static struct kmem_cache * squashfs_inode_cachep;
-+
-+
-+static struct inode *squashfs_alloc_inode(struct super_block *sb)
-+{
-+ struct squashfs_inode_info *ei;
-+ ei = kmem_cache_alloc(squashfs_inode_cachep, GFP_KERNEL);
-+ if (!ei)
-+ return NULL;
-+ return &ei->vfs_inode;
-+}
-+
-+
-+static void squashfs_destroy_inode(struct inode *inode)
-+{
-+ kmem_cache_free(squashfs_inode_cachep, SQUASHFS_I(inode));
-+}
-+
-+
-+static void init_once(void * foo, struct kmem_cache * cachep, unsigned long flags)
-+{
-+ struct squashfs_inode_info *ei = foo;
-+
-+ if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) ==
-+ SLAB_CTOR_CONSTRUCTOR)
-+ inode_init_once(&ei->vfs_inode);
-+}
-+
-+
-+static int __init init_inodecache(void)
-+{
-+ squashfs_inode_cachep = kmem_cache_create("squashfs_inode_cache",
-+ sizeof(struct squashfs_inode_info),
-+ 0, SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT,
-+ init_once, NULL);
-+ if (squashfs_inode_cachep == NULL)
-+ return -ENOMEM;
-+ return 0;
-+}
-+
-+
-+static void destroy_inodecache(void)
-+{
-+ kmem_cache_destroy(squashfs_inode_cachep);
-+}
-+
-+
-+module_init(init_squashfs_fs);
-+module_exit(exit_squashfs_fs);
-+MODULE_DESCRIPTION("squashfs, a compressed read-only filesystem");
-+MODULE_AUTHOR("Phillip Lougher <phillip@lougher.org.uk>");
-+MODULE_LICENSE("GPL");
-Index: linux-2.6.21.7/fs/squashfs/Makefile
-===================================================================
---- /dev/null
-+++ linux-2.6.21.7/fs/squashfs/Makefile
-@@ -0,0 +1,7 @@
-+#
-+# Makefile for the linux squashfs routines.
-+#
-+
-+obj-$(CONFIG_SQUASHFS) += squashfs.o
-+squashfs-y += inode.o
-+squashfs-y += squashfs2_0.o
-Index: linux-2.6.21.7/fs/squashfs/squashfs2_0.c
-===================================================================
---- /dev/null
-+++ linux-2.6.21.7/fs/squashfs/squashfs2_0.c
-@@ -0,0 +1,758 @@
-+/*
-+ * Squashfs - a compressed read only filesystem for Linux
-+ *
-+ * Copyright (c) 2002, 2003, 2004, 2005, 2006
-+ * Phillip Lougher <phillip@lougher.org.uk>
-+ *
-+ * 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,
-+ * 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-+ *
-+ * squashfs2_0.c
-+ */
-+
-+#include <linux/types.h>
-+#include <linux/squashfs_fs.h>
-+#include <linux/module.h>
-+#include <linux/errno.h>
-+#include <linux/slab.h>
-+#include <linux/fs.h>
-+#include <linux/smp_lock.h>
-+#include <linux/slab.h>
-+#include <linux/squashfs_fs_sb.h>
-+#include <linux/squashfs_fs_i.h>
-+#include <linux/buffer_head.h>
-+#include <linux/vfs.h>
-+#include <linux/init.h>
-+#include <linux/dcache.h>
-+#include <linux/wait.h>
-+#include <linux/zlib.h>
-+#include <linux/blkdev.h>
-+#include <linux/vmalloc.h>
-+#include <asm/uaccess.h>
-+#include <asm/semaphore.h>
-+
-+#include "squashfs.h"
-+static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir);
-+static struct dentry *squashfs_lookup_2(struct inode *, struct dentry *,
-+ struct nameidata *);
-+
-+static struct file_operations squashfs_dir_ops_2 = {
-+ .read = generic_read_dir,
-+ .readdir = squashfs_readdir_2
-+};
-+
-+static struct inode_operations squashfs_dir_inode_ops_2 = {
-+ .lookup = squashfs_lookup_2
-+};
-+
-+static unsigned char squashfs_filetype_table[] = {
-+ DT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK
-+};
-+
-+static int read_fragment_index_table_2(struct super_block *s)
-+{
-+ struct squashfs_sb_info *msblk = s->s_fs_info;
-+ struct squashfs_super_block *sblk = &msblk->sblk;
-+
-+ if (!(msblk->fragment_index_2 = kmalloc(SQUASHFS_FRAGMENT_INDEX_BYTES_2
-+ (sblk->fragments), GFP_KERNEL))) {
-+ ERROR("Failed to allocate uid/gid table\n");
-+ return 0;
-+ }
-+
-+ if (SQUASHFS_FRAGMENT_INDEX_BYTES_2(sblk->fragments) &&
-+ !squashfs_read_data(s, (char *)
-+ msblk->fragment_index_2,
-+ sblk->fragment_table_start,
-+ SQUASHFS_FRAGMENT_INDEX_BYTES_2
-+ (sblk->fragments) |
-+ SQUASHFS_COMPRESSED_BIT_BLOCK, NULL)) {
-+ ERROR("unable to read fragment index table\n");
-+ return 0;
-+ }
-+
-+ if (msblk->swap) {
-+ int i;
-+ unsigned int fragment;
-+
-+ for (i = 0; i < SQUASHFS_FRAGMENT_INDEXES_2(sblk->fragments);
-+ i++) {
-+ SQUASHFS_SWAP_FRAGMENT_INDEXES_2((&fragment),
-+ &msblk->fragment_index_2[i], 1);
-+ msblk->fragment_index_2[i] = fragment;
-+ }
-+ }
-+
-+ return 1;
-+}
-+
-+
-+static int get_fragment_location_2(struct super_block *s, unsigned int fragment,
-+ long long *fragment_start_block,
-+ unsigned int *fragment_size)
-+{
-+ struct squashfs_sb_info *msblk = s->s_fs_info;
-+ long long start_block =
-+ msblk->fragment_index_2[SQUASHFS_FRAGMENT_INDEX_2(fragment)];
-+ int offset = SQUASHFS_FRAGMENT_INDEX_OFFSET_2(fragment);
-+ struct squashfs_fragment_entry_2 fragment_entry;
-+
-+ if (msblk->swap) {
-+ struct squashfs_fragment_entry_2 sfragment_entry;
-+
-+ if (!squashfs_get_cached_block(s, (char *) &sfragment_entry,
-+ start_block, offset,
-+ sizeof(sfragment_entry), &start_block,
-+ &offset))
-+ goto out;
-+ SQUASHFS_SWAP_FRAGMENT_ENTRY_2(&fragment_entry, &sfragment_entry);
-+ } else
-+ if (!squashfs_get_cached_block(s, (char *) &fragment_entry,
-+ start_block, offset,
-+ sizeof(fragment_entry), &start_block,
-+ &offset))
-+ goto out;
-+
-+ *fragment_start_block = fragment_entry.start_block;
-+ *fragment_size = fragment_entry.size;
-+
-+ return 1;
-+
-+out:
-+ return 0;
-+}
-+
-+
-+static struct inode *squashfs_new_inode(struct super_block *s,
-+ struct squashfs_base_inode_header_2 *inodeb, unsigned int ino)
-+{
-+ struct squashfs_sb_info *msblk = s->s_fs_info;
-+ struct squashfs_super_block *sblk = &msblk->sblk;
-+ struct inode *i = new_inode(s);
-+
-+ if (i) {
-+ i->i_ino = ino;
-+ i->i_mtime.tv_sec = sblk->mkfs_time;
-+ i->i_atime.tv_sec = sblk->mkfs_time;
-+ i->i_ctime.tv_sec = sblk->mkfs_time;
-+ i->i_uid = msblk->uid[inodeb->uid];
-+ i->i_mode = inodeb->mode;
-+ i->i_nlink = 1;
-+ i->i_size = 0;
-+ if (inodeb->guid == SQUASHFS_GUIDS)
-+ i->i_gid = i->i_uid;
-+ else
-+ i->i_gid = msblk->guid[inodeb->guid];
-+ }
-+
-+ return i;
-+}
-+
-+
-+static struct inode *squashfs_iget_2(struct super_block *s, squashfs_inode_t inode)
-+{
-+ struct inode *i;
-+ struct squashfs_sb_info *msblk = s->s_fs_info;
-+ struct squashfs_super_block *sblk = &msblk->sblk;
-+ unsigned int block = SQUASHFS_INODE_BLK(inode) +
-+ sblk->inode_table_start;
-+ unsigned int offset = SQUASHFS_INODE_OFFSET(inode);
-+ unsigned int ino = SQUASHFS_MK_VFS_INODE(block
-+ - sblk->inode_table_start, offset);
-+ long long next_block;
-+ unsigned int next_offset;
-+ union squashfs_inode_header_2 id, sid;
-+ struct squashfs_base_inode_header_2 *inodeb = &id.base,
-+ *sinodeb = &sid.base;
-+
-+ TRACE("Entered squashfs_iget\n");
-+
-+ if (msblk->swap) {
-+ if (!squashfs_get_cached_block(s, (char *) sinodeb, block,
-+ offset, sizeof(*sinodeb), &next_block,
-+ &next_offset))
-+ goto failed_read;
-+ SQUASHFS_SWAP_BASE_INODE_HEADER_2(inodeb, sinodeb,
-+ sizeof(*sinodeb));
-+ } else
-+ if (!squashfs_get_cached_block(s, (char *) inodeb, block,
-+ offset, sizeof(*inodeb), &next_block,
-+ &next_offset))
-+ goto failed_read;
-+
-+ switch(inodeb->inode_type) {
-+ case SQUASHFS_FILE_TYPE: {
-+ struct squashfs_reg_inode_header_2 *inodep = &id.reg;
-+ struct squashfs_reg_inode_header_2 *sinodep = &sid.reg;
-+ long long frag_blk;
-+ unsigned int frag_size;
-+
-+ if (msblk->swap) {
-+ if (!squashfs_get_cached_block(s, (char *)
-+ sinodep, block, offset,
-+ sizeof(*sinodep), &next_block,
-+ &next_offset))
-+ goto failed_read;
-+ SQUASHFS_SWAP_REG_INODE_HEADER_2(inodep, sinodep);
-+ } else
-+ if (!squashfs_get_cached_block(s, (char *)
-+ inodep, block, offset,
-+ sizeof(*inodep), &next_block,
-+ &next_offset))
-+ goto failed_read;
-+
-+ frag_blk = SQUASHFS_INVALID_BLK;
-+ if (inodep->fragment != SQUASHFS_INVALID_FRAG &&
-+ !get_fragment_location_2(s,
-+ inodep->fragment, &frag_blk, &frag_size))
-+ goto failed_read;
-+
-+ if((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
-+ goto failed_read1;
-+
-+ i->i_size = inodep->file_size;
-+ i->i_fop = &generic_ro_fops;
-+ i->i_mode |= S_IFREG;
-+ i->i_mtime.tv_sec = inodep->mtime;
-+ i->i_atime.tv_sec = inodep->mtime;
-+ i->i_ctime.tv_sec = inodep->mtime;
-+ i->i_blocks = ((i->i_size - 1) >> 9) + 1;
-+ i->i_blksize = PAGE_CACHE_SIZE;
-+ SQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;
-+ SQUASHFS_I(i)->u.s1.fragment_size = frag_size;
-+ SQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;
-+ SQUASHFS_I(i)->start_block = inodep->start_block;
-+ SQUASHFS_I(i)->u.s1.block_list_start = next_block;
-+ SQUASHFS_I(i)->offset = next_offset;
-+ if (sblk->block_size > 4096)
-+ i->i_data.a_ops = &squashfs_aops;
-+ else
-+ i->i_data.a_ops = &squashfs_aops_4K;
-+
-+ TRACE("File inode %x:%x, start_block %x, "
-+ "block_list_start %llx, offset %x\n",
-+ SQUASHFS_INODE_BLK(inode), offset,
-+ inodep->start_block, next_block,
-+ next_offset);
-+ break;
-+ }
-+ case SQUASHFS_DIR_TYPE: {
-+ struct squashfs_dir_inode_header_2 *inodep = &id.dir;
-+ struct squashfs_dir_inode_header_2 *sinodep = &sid.dir;
-+
-+ if (msblk->swap) {
-+ if (!squashfs_get_cached_block(s, (char *)
-+ sinodep, block, offset,
-+ sizeof(*sinodep), &next_block,
-+ &next_offset))
-+ goto failed_read;
-+ SQUASHFS_SWAP_DIR_INODE_HEADER_2(inodep, sinodep);
-+ } else
-+ if (!squashfs_get_cached_block(s, (char *)
-+ inodep, block, offset,
-+ sizeof(*inodep), &next_block,
-+ &next_offset))
-+ goto failed_read;
-+
-+ if((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
-+ goto failed_read1;
-+
-+ i->i_size = inodep->file_size;
-+ i->i_op = &squashfs_dir_inode_ops_2;
-+ i->i_fop = &squashfs_dir_ops_2;
-+ i->i_mode |= S_IFDIR;
-+ i->i_mtime.tv_sec = inodep->mtime;
-+ i->i_atime.tv_sec = inodep->mtime;
-+ i->i_ctime.tv_sec = inodep->mtime;
-+ SQUASHFS_I(i)->start_block = inodep->start_block;
-+ SQUASHFS_I(i)->offset = inodep->offset;
-+ SQUASHFS_I(i)->u.s2.directory_index_count = 0;
-+ SQUASHFS_I(i)->u.s2.parent_inode = 0;
-+
-+ TRACE("Directory inode %x:%x, start_block %x, offset "
-+ "%x\n", SQUASHFS_INODE_BLK(inode),
-+ offset, inodep->start_block,
-+ inodep->offset);
-+ break;
-+ }
-+ case SQUASHFS_LDIR_TYPE: {
-+ struct squashfs_ldir_inode_header_2 *inodep = &id.ldir;
-+ struct squashfs_ldir_inode_header_2 *sinodep = &sid.ldir;
-+
-+ if (msblk->swap) {
-+ if (!squashfs_get_cached_block(s, (char *)
-+ sinodep, block, offset,
-+ sizeof(*sinodep), &next_block,
-+ &next_offset))
-+ goto failed_read;
-+ SQUASHFS_SWAP_LDIR_INODE_HEADER_2(inodep,
-+ sinodep);
-+ } else
-+ if (!squashfs_get_cached_block(s, (char *)
-+ inodep, block, offset,
-+ sizeof(*inodep), &next_block,
-+ &next_offset))
-+ goto failed_read;
-+
-+ if((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
-+ goto failed_read1;
-+
-+ i->i_size = inodep->file_size;
-+ i->i_op = &squashfs_dir_inode_ops_2;
-+ i->i_fop = &squashfs_dir_ops_2;
-+ i->i_mode |= S_IFDIR;
-+ i->i_mtime.tv_sec = inodep->mtime;
-+ i->i_atime.tv_sec = inodep->mtime;
-+ i->i_ctime.tv_sec = inodep->mtime;
-+ SQUASHFS_I(i)->start_block = inodep->start_block;
-+ SQUASHFS_I(i)->offset = inodep->offset;
-+ SQUASHFS_I(i)->u.s2.directory_index_start = next_block;
-+ SQUASHFS_I(i)->u.s2.directory_index_offset =
-+ next_offset;
-+ SQUASHFS_I(i)->u.s2.directory_index_count =
-+ inodep->i_count;
-+ SQUASHFS_I(i)->u.s2.parent_inode = 0;
-+
-+ TRACE("Long directory inode %x:%x, start_block %x, "
-+ "offset %x\n",
-+ SQUASHFS_INODE_BLK(inode), offset,
-+ inodep->start_block, inodep->offset);
-+ break;
-+ }
-+ case SQUASHFS_SYMLINK_TYPE: {
-+ struct squashfs_symlink_inode_header_2 *inodep =
-+ &id.symlink;
-+ struct squashfs_symlink_inode_header_2 *sinodep =
-+ &sid.symlink;
-+
-+ if (msblk->swap) {
-+ if (!squashfs_get_cached_block(s, (char *)
-+ sinodep, block, offset,
-+ sizeof(*sinodep), &next_block,
-+ &next_offset))
-+ goto failed_read;
-+ SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(inodep,
-+ sinodep);
-+ } else
-+ if (!squashfs_get_cached_block(s, (char *)
-+ inodep, block, offset,
-+ sizeof(*inodep), &next_block,
-+ &next_offset))
-+ goto failed_read;
-+
-+ if((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
-+ goto failed_read1;
-+
-+ i->i_size = inodep->symlink_size;
-+ i->i_op = &page_symlink_inode_operations;
-+ i->i_data.a_ops = &squashfs_symlink_aops;
-+ i->i_mode |= S_IFLNK;
-+ SQUASHFS_I(i)->start_block = next_block;
-+ SQUASHFS_I(i)->offset = next_offset;
-+
-+ TRACE("Symbolic link inode %x:%x, start_block %llx, "
-+ "offset %x\n",
-+ SQUASHFS_INODE_BLK(inode), offset,
-+ next_block, next_offset);
-+ break;
-+ }
-+ case SQUASHFS_BLKDEV_TYPE:
-+ case SQUASHFS_CHRDEV_TYPE: {
-+ struct squashfs_dev_inode_header_2 *inodep = &id.dev;
-+ struct squashfs_dev_inode_header_2 *sinodep = &sid.dev;
-+
-+ if (msblk->swap) {
-+ if (!squashfs_get_cached_block(s, (char *)
-+ sinodep, block, offset,
-+ sizeof(*sinodep), &next_block,
-+ &next_offset))
-+ goto failed_read;
-+ SQUASHFS_SWAP_DEV_INODE_HEADER_2(inodep, sinodep);
-+ } else
-+ if (!squashfs_get_cached_block(s, (char *)
-+ inodep, block, offset,
-+ sizeof(*inodep), &next_block,
-+ &next_offset))
-+ goto failed_read;
-+
-+ if ((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
-+ goto failed_read1;
-+
-+ i->i_mode |= (inodeb->inode_type ==
-+ SQUASHFS_CHRDEV_TYPE) ? S_IFCHR :
-+ S_IFBLK;
-+ init_special_inode(i, i->i_mode,
-+ old_decode_dev(inodep->rdev));
-+
-+ TRACE("Device inode %x:%x, rdev %x\n",
-+ SQUASHFS_INODE_BLK(inode), offset,
-+ inodep->rdev);
-+ break;
-+ }
-+ case SQUASHFS_FIFO_TYPE:
-+ case SQUASHFS_SOCKET_TYPE: {
-+ if ((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
-+ goto failed_read1;
-+
-+ i->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)
-+ ? S_IFIFO : S_IFSOCK;
-+ init_special_inode(i, i->i_mode, 0);
-+ break;
-+ }
-+ default:
-+ ERROR("Unknown inode type %d in squashfs_iget!\n",
-+ inodeb->inode_type);
-+ goto failed_read1;
-+ }
-+
-+ insert_inode_hash(i);
-+ return i;
-+
-+failed_read:
-+ ERROR("Unable to read inode [%x:%x]\n", block, offset);
-+
-+failed_read1:
-+ return NULL;
-+}
-+
-+
-+static int get_dir_index_using_offset(struct super_block *s, long long
-+ *next_block, unsigned int *next_offset,
-+ long long index_start,
-+ unsigned int index_offset, int i_count,
-+ long long f_pos)
-+{
-+ struct squashfs_sb_info *msblk = s->s_fs_info;
-+ struct squashfs_super_block *sblk = &msblk->sblk;
-+ int i, length = 0;
-+ struct squashfs_dir_index_2 index;
-+
-+ TRACE("Entered get_dir_index_using_offset, i_count %d, f_pos %d\n",
-+ i_count, (unsigned int) f_pos);
-+
-+ if (f_pos == 0)
-+ goto finish;
-+
-+ for (i = 0; i < i_count; i++) {
-+ if (msblk->swap) {
-+ struct squashfs_dir_index_2 sindex;
-+ squashfs_get_cached_block(s, (char *) &sindex,
-+ index_start, index_offset,
-+ sizeof(sindex), &index_start,
-+ &index_offset);
-+ SQUASHFS_SWAP_DIR_INDEX_2(&index, &sindex);
-+ } else
-+ squashfs_get_cached_block(s, (char *) &index,
-+ index_start, index_offset,
-+ sizeof(index), &index_start,
-+ &index_offset);
-+
-+ if (index.index > f_pos)
-+ break;
-+
-+ squashfs_get_cached_block(s, NULL, index_start, index_offset,
-+ index.size + 1, &index_start,
-+ &index_offset);
-+
-+ length = index.index;
-+ *next_block = index.start_block + sblk->directory_table_start;
-+ }
-+
-+ *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
-+
-+finish:
-+ return length;
-+}
-+
-+
-+static int get_dir_index_using_name(struct super_block *s, long long
-+ *next_block, unsigned int *next_offset,
-+ long long index_start,
-+ unsigned int index_offset, int i_count,
-+ const char *name, int size)
-+{
-+ struct squashfs_sb_info *msblk = s->s_fs_info;
-+ struct squashfs_super_block *sblk = &msblk->sblk;
-+ int i, length = 0;
-+ char buffer[sizeof(struct squashfs_dir_index_2) + SQUASHFS_NAME_LEN + 1];
-+ struct squashfs_dir_index_2 *index = (struct squashfs_dir_index_2 *) buffer;
-+ char str[SQUASHFS_NAME_LEN + 1];
-+
-+ TRACE("Entered get_dir_index_using_name, i_count %d\n", i_count);
-+
-+ strncpy(str, name, size);
-+ str[size] = '\0';
-+
-+ for (i = 0; i < i_count; i++) {
-+ if (msblk->swap) {
-+ struct squashfs_dir_index_2 sindex;
-+ squashfs_get_cached_block(s, (char *) &sindex,
-+ index_start, index_offset,
-+ sizeof(sindex), &index_start,
-+ &index_offset);
-+ SQUASHFS_SWAP_DIR_INDEX_2(index, &sindex);
-+ } else
-+ squashfs_get_cached_block(s, (char *) index,
-+ index_start, index_offset,
-+ sizeof(struct squashfs_dir_index_2),
-+ &index_start, &index_offset);
-+
-+ squashfs_get_cached_block(s, index->name, index_start,
-+ index_offset, index->size + 1,
-+ &index_start, &index_offset);
-+
-+ index->name[index->size + 1] = '\0';
-+
-+ if (strcmp(index->name, str) > 0)
-+ break;
-+
-+ length = index->index;
-+ *next_block = index->start_block + sblk->directory_table_start;
-+ }
-+
-+ *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
-+ return length;
-+}
-+
-+
-+static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir)
-+{
-+ struct inode *i = file->f_dentry->d_inode;
-+ struct squashfs_sb_info *msblk = i->i_sb->s_fs_info;
-+ struct squashfs_super_block *sblk = &msblk->sblk;
-+ long long next_block = SQUASHFS_I(i)->start_block +
-+ sblk->directory_table_start;
-+ int next_offset = SQUASHFS_I(i)->offset, length = 0, dirs_read = 0,
-+ dir_count;
-+ struct squashfs_dir_header_2 dirh;
-+ char buffer[sizeof(struct squashfs_dir_entry_2) + SQUASHFS_NAME_LEN + 1];
-+ struct squashfs_dir_entry_2 *dire = (struct squashfs_dir_entry_2 *) buffer;
-+
-+ TRACE("Entered squashfs_readdir_2 [%llx:%x]\n", next_block, next_offset);
-+
-+ length = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,
-+ SQUASHFS_I(i)->u.s2.directory_index_start,
-+ SQUASHFS_I(i)->u.s2.directory_index_offset,
-+ SQUASHFS_I(i)->u.s2.directory_index_count,
-+ file->f_pos);
-+
-+ while (length < i_size_read(i)) {
-+ /* read directory header */
-+ if (msblk->swap) {
-+ struct squashfs_dir_header_2 sdirh;
-+
-+ if (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,
-+ next_block, next_offset, sizeof(sdirh),
-+ &next_block, &next_offset))
-+ goto failed_read;
-+
-+ length += sizeof(sdirh);
-+ SQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);
-+ } else {
-+ if (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,
-+ next_block, next_offset, sizeof(dirh),
-+ &next_block, &next_offset))
-+ goto failed_read;
-+
-+ length += sizeof(dirh);
-+ }
-+
-+ dir_count = dirh.count + 1;
-+ while (dir_count--) {
-+ if (msblk->swap) {
-+ struct squashfs_dir_entry_2 sdire;
-+ if (!squashfs_get_cached_block(i->i_sb, (char *)
-+ &sdire, next_block, next_offset,
-+ sizeof(sdire), &next_block,
-+ &next_offset))
-+ goto failed_read;
-+
-+ length += sizeof(sdire);
-+ SQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);
-+ } else {
-+ if (!squashfs_get_cached_block(i->i_sb, (char *)
-+ dire, next_block, next_offset,
-+ sizeof(*dire), &next_block,
-+ &next_offset))
-+ goto failed_read;
-+
-+ length += sizeof(*dire);
-+ }
-+
-+ if (!squashfs_get_cached_block(i->i_sb, dire->name,
-+ next_block, next_offset,
-+ dire->size + 1, &next_block,
-+ &next_offset))
-+ goto failed_read;
-+
-+ length += dire->size + 1;
-+
-+ if (file->f_pos >= length)
-+ continue;
-+
-+ dire->name[dire->size + 1] = '\0';
-+
-+ TRACE("Calling filldir(%x, %s, %d, %d, %x:%x, %d)\n",
-+ (unsigned int) dirent, dire->name,
-+ dire->size + 1, (int) file->f_pos,
-+ dirh.start_block, dire->offset,
-+ squashfs_filetype_table[dire->type]);
-+
-+ if (filldir(dirent, dire->name, dire->size + 1,
-+ file->f_pos, SQUASHFS_MK_VFS_INODE(
-+ dirh.start_block, dire->offset),
-+ squashfs_filetype_table[dire->type])
-+ < 0) {
-+ TRACE("Filldir returned less than 0\n");
-+ goto finish;
-+ }
-+ file->f_pos = length;
-+ dirs_read++;
-+ }
-+ }
-+
-+finish:
-+ return dirs_read;
-+
-+failed_read:
-+ ERROR("Unable to read directory block [%llx:%x]\n", next_block,
-+ next_offset);
-+ return 0;
-+}
-+
-+
-+static struct dentry *squashfs_lookup_2(struct inode *i, struct dentry *dentry,
-+ struct nameidata *nd)
-+{
-+ const unsigned char *name = dentry->d_name.name;
-+ int len = dentry->d_name.len;
-+ struct inode *inode = NULL;
-+ struct squashfs_sb_info *msblk = i->i_sb->s_fs_info;
-+ struct squashfs_super_block *sblk = &msblk->sblk;
-+ long long next_block = SQUASHFS_I(i)->start_block +
-+ sblk->directory_table_start;
-+ int next_offset = SQUASHFS_I(i)->offset, length = 0,
-+ dir_count;
-+ struct squashfs_dir_header_2 dirh;
-+ char buffer[sizeof(struct squashfs_dir_entry_2) + SQUASHFS_NAME_LEN];
-+ struct squashfs_dir_entry_2 *dire = (struct squashfs_dir_entry_2 *) buffer;
-+ int sorted = sblk->s_major == 2 && sblk->s_minor >= 1;
-+
-+ TRACE("Entered squashfs_lookup [%llx:%x]\n", next_block, next_offset);
-+
-+ if (len > SQUASHFS_NAME_LEN)
-+ goto exit_loop;
-+
-+ length = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,
-+ SQUASHFS_I(i)->u.s2.directory_index_start,
-+ SQUASHFS_I(i)->u.s2.directory_index_offset,
-+ SQUASHFS_I(i)->u.s2.directory_index_count, name,
-+ len);
-+
-+ while (length < i_size_read(i)) {
-+ /* read directory header */
-+ if (msblk->swap) {
-+ struct squashfs_dir_header_2 sdirh;
-+ if (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,
-+ next_block, next_offset, sizeof(sdirh),
-+ &next_block, &next_offset))
-+ goto failed_read;
-+
-+ length += sizeof(sdirh);
-+ SQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);
-+ } else {
-+ if (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,
-+ next_block, next_offset, sizeof(dirh),
-+ &next_block, &next_offset))
-+ goto failed_read;
-+
-+ length += sizeof(dirh);
-+ }
-+
-+ dir_count = dirh.count + 1;
-+ while (dir_count--) {
-+ if (msblk->swap) {
-+ struct squashfs_dir_entry_2 sdire;
-+ if (!squashfs_get_cached_block(i->i_sb, (char *)
-+ &sdire, next_block,next_offset,
-+ sizeof(sdire), &next_block,
-+ &next_offset))
-+ goto failed_read;
-+
-+ length += sizeof(sdire);
-+ SQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);
-+ } else {
-+ if (!squashfs_get_cached_block(i->i_sb, (char *)
-+ dire, next_block,next_offset,
-+ sizeof(*dire), &next_block,
-+ &next_offset))
-+ goto failed_read;
-+
-+ length += sizeof(*dire);
-+ }
-+
-+ if (!squashfs_get_cached_block(i->i_sb, dire->name,
-+ next_block, next_offset, dire->size + 1,
-+ &next_block, &next_offset))
-+ goto failed_read;
-+
-+ length += dire->size + 1;
-+
-+ if (sorted && name[0] < dire->name[0])
-+ goto exit_loop;
-+
-+ if ((len == dire->size + 1) && !strncmp(name,
-+ dire->name, len)) {
-+ squashfs_inode_t ino =
-+ SQUASHFS_MKINODE(dirh.start_block,
-+ dire->offset);
-+
-+ TRACE("calling squashfs_iget for directory "
-+ "entry %s, inode %x:%x, %lld\n", name,
-+ dirh.start_block, dire->offset, ino);
-+
-+ inode = (msblk->iget)(i->i_sb, ino);
-+
-+ goto exit_loop;
-+ }
-+ }
-+ }
-+
-+exit_loop:
-+ d_add(dentry, inode);
-+ return ERR_PTR(0);
-+
-+failed_read:
-+ ERROR("Unable to read directory block [%llx:%x]\n", next_block,
-+ next_offset);
-+ goto exit_loop;
-+}
-+
-+
-+int squashfs_2_0_supported(struct squashfs_sb_info *msblk)
-+{
-+ struct squashfs_super_block *sblk = &msblk->sblk;
-+
-+ msblk->iget = squashfs_iget_2;
-+ msblk->read_fragment_index_table = read_fragment_index_table_2;
-+
-+ sblk->bytes_used = sblk->bytes_used_2;
-+ sblk->uid_start = sblk->uid_start_2;
-+ sblk->guid_start = sblk->guid_start_2;
-+ sblk->inode_table_start = sblk->inode_table_start_2;
-+ sblk->directory_table_start = sblk->directory_table_start_2;
-+ sblk->fragment_table_start = sblk->fragment_table_start_2;
-+
-+ return 1;
-+}
-Index: linux-2.6.21.7/fs/squashfs/squashfs.h
-===================================================================
---- /dev/null
-+++ linux-2.6.21.7/fs/squashfs/squashfs.h
-@@ -0,0 +1,86 @@
-+/*
-+ * Squashfs - a compressed read only filesystem for Linux
-+ *
-+ * Copyright (c) 2002, 2003, 2004, 2005, 2006
-+ * Phillip Lougher <phillip@lougher.org.uk>
-+ *
-+ * 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,
-+ * 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-+ *
-+ * squashfs.h
-+ */
-+
-+#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY
-+#undef CONFIG_SQUASHFS_1_0_COMPATIBILITY
-+#endif
-+
-+#ifdef SQUASHFS_TRACE
-+#define TRACE(s, args...) printk(KERN_NOTICE "SQUASHFS: "s, ## args)
-+#else
-+#define TRACE(s, args...) {}
-+#endif
-+
-+#define ERROR(s, args...) printk(KERN_ERR "SQUASHFS error: "s, ## args)
-+
-+#define SERROR(s, args...) do { \
-+ if (!silent) \
-+ printk(KERN_ERR "SQUASHFS error: "s, ## args);\
-+ } while(0)
-+
-+#define WARNING(s, args...) printk(KERN_WARNING "SQUASHFS: "s, ## args)
-+
-+static inline struct squashfs_inode_info *SQUASHFS_I(struct inode *inode)
-+{
-+ return list_entry(inode, struct squashfs_inode_info, vfs_inode);
-+}
-+
-+#if defined(CONFIG_SQUASHFS_1_0_COMPATIBILITY ) || defined(CONFIG_SQUASHFS_2_0_COMPATIBILITY)
-+#define SQSH_EXTERN
-+extern unsigned int squashfs_read_data(struct super_block *s, char *buffer,
-+ long long index, unsigned int length,
-+ long long *next_index);
-+extern int squashfs_get_cached_block(struct super_block *s, char *buffer,
-+ long long block, unsigned int offset,
-+ int length, long long *next_block,
-+ unsigned int *next_offset);
-+extern void release_cached_fragment(struct squashfs_sb_info *msblk, struct
-+ squashfs_fragment_cache *fragment);
-+extern struct squashfs_fragment_cache *get_cached_fragment(struct super_block
-+ *s, long long start_block,
-+ int length);
-+extern struct address_space_operations squashfs_symlink_aops;
-+extern struct address_space_operations squashfs_aops;
-+extern struct address_space_operations squashfs_aops_4K;
-+extern struct inode_operations squashfs_dir_inode_ops;
-+#else
-+#define SQSH_EXTERN static
-+#endif
-+
-+#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY
-+extern int squashfs_1_0_supported(struct squashfs_sb_info *msblk);
-+#else
-+static inline int squashfs_1_0_supported(struct squashfs_sb_info *msblk)
-+{
-+ return 0;
-+}
-+#endif
-+
-+#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY
-+extern int squashfs_2_0_supported(struct squashfs_sb_info *msblk);
-+#else
-+static inline int squashfs_2_0_supported(struct squashfs_sb_info *msblk)
-+{
-+ return 0;
-+}
-+#endif
-Index: linux-2.6.21.7/include/linux/squashfs_fs.h
-===================================================================
---- /dev/null
-+++ linux-2.6.21.7/include/linux/squashfs_fs.h
-@@ -0,0 +1,911 @@
-+#ifndef SQUASHFS_FS
-+#define SQUASHFS_FS
-+
-+/*
-+ * Squashfs
-+ *
-+ * Copyright (c) 2002, 2003, 2004, 2005, 2006
-+ * Phillip Lougher <phillip@lougher.org.uk>
-+ *
-+ * 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,
-+ * 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-+ *
-+ * squashfs_fs.h
-+ */
-+
-+#ifndef CONFIG_SQUASHFS_2_0_COMPATIBILITY
-+#define CONFIG_SQUASHFS_2_0_COMPATIBILITY
-+#endif
-+
-+#ifdef CONFIG_SQUASHFS_VMALLOC
-+#define SQUASHFS_ALLOC(a) vmalloc(a)
-+#define SQUASHFS_FREE(a) vfree(a)
-+#else
-+#define SQUASHFS_ALLOC(a) kmalloc(a, GFP_KERNEL)
-+#define SQUASHFS_FREE(a) kfree(a)
-+#endif
-+#define SQUASHFS_CACHED_FRAGMENTS CONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE
-+#define SQUASHFS_MAJOR 3
-+#define SQUASHFS_MINOR 0
-+#define SQUASHFS_MAGIC 0x73717368
-+#define SQUASHFS_MAGIC_SWAP 0x68737173
-+#define SQUASHFS_START 0
-+
-+/* size of metadata (inode and directory) blocks */
-+#define SQUASHFS_METADATA_SIZE 8192
-+#define SQUASHFS_METADATA_LOG 13
-+
-+/* default size of data blocks */
-+#define SQUASHFS_FILE_SIZE 65536
-+#define SQUASHFS_FILE_LOG 16
-+
-+#define SQUASHFS_FILE_MAX_SIZE 65536
-+
-+/* Max number of uids and gids */
-+#define SQUASHFS_UIDS 256
-+#define SQUASHFS_GUIDS 255
-+
-+/* Max length of filename (not 255) */
-+#define SQUASHFS_NAME_LEN 256
-+
-+#define SQUASHFS_INVALID ((long long) 0xffffffffffff)
-+#define SQUASHFS_INVALID_FRAG ((unsigned int) 0xffffffff)
-+#define SQUASHFS_INVALID_BLK ((long long) -1)
-+#define SQUASHFS_USED_BLK ((long long) -2)
-+
-+/* Filesystem flags */
-+#define SQUASHFS_NOI 0
-+#define SQUASHFS_NOD 1
-+#define SQUASHFS_CHECK 2
-+#define SQUASHFS_NOF 3
-+#define SQUASHFS_NO_FRAG 4
-+#define SQUASHFS_ALWAYS_FRAG 5
-+#define SQUASHFS_DUPLICATE 6
-+
-+#define SQUASHFS_BIT(flag, bit) ((flag >> bit) & 1)
-+
-+#define SQUASHFS_UNCOMPRESSED_INODES(flags) SQUASHFS_BIT(flags, \
-+ SQUASHFS_NOI)
-+
-+#define SQUASHFS_UNCOMPRESSED_DATA(flags) SQUASHFS_BIT(flags, \
-+ SQUASHFS_NOD)
-+
-+#define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
-+ SQUASHFS_NOF)
-+
-+#define SQUASHFS_NO_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
-+ SQUASHFS_NO_FRAG)
-+
-+#define SQUASHFS_ALWAYS_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
-+ SQUASHFS_ALWAYS_FRAG)
-+
-+#define SQUASHFS_DUPLICATES(flags) SQUASHFS_BIT(flags, \
-+ SQUASHFS_DUPLICATE)
-+
-+#define SQUASHFS_CHECK_DATA(flags) SQUASHFS_BIT(flags, \
-+ SQUASHFS_CHECK)
-+
-+#define SQUASHFS_MKFLAGS(noi, nod, check_data, nof, no_frag, always_frag, \
-+ duplicate_checking) (noi | (nod << 1) | (check_data << 2) \
-+ | (nof << 3) | (no_frag << 4) | (always_frag << 5) | \
-+ (duplicate_checking << 6))
-+
-+/* Max number of types and file types */
-+#define SQUASHFS_DIR_TYPE 1
-+#define SQUASHFS_FILE_TYPE 2
-+#define SQUASHFS_SYMLINK_TYPE 3
-+#define SQUASHFS_BLKDEV_TYPE 4
-+#define SQUASHFS_CHRDEV_TYPE 5
-+#define SQUASHFS_FIFO_TYPE 6
-+#define SQUASHFS_SOCKET_TYPE 7
-+#define SQUASHFS_LDIR_TYPE 8
-+#define SQUASHFS_LREG_TYPE 9
-+
-+/* 1.0 filesystem type definitions */
-+#define SQUASHFS_TYPES 5
-+#define SQUASHFS_IPC_TYPE 0
-+
-+/* Flag whether block is compressed or uncompressed, bit is set if block is
-+ * uncompressed */
-+#define SQUASHFS_COMPRESSED_BIT (1 << 15)
-+
-+#define SQUASHFS_COMPRESSED_SIZE(B) (((B) & ~SQUASHFS_COMPRESSED_BIT) ? \
-+ (B) & ~SQUASHFS_COMPRESSED_BIT : SQUASHFS_COMPRESSED_BIT)
-+
-+#define SQUASHFS_COMPRESSED(B) (!((B) & SQUASHFS_COMPRESSED_BIT))
-+
-+#define SQUASHFS_COMPRESSED_BIT_BLOCK (1 << 24)
-+
-+#define SQUASHFS_COMPRESSED_SIZE_BLOCK(B) (((B) & \
-+ ~SQUASHFS_COMPRESSED_BIT_BLOCK) ? (B) & \
-+ ~SQUASHFS_COMPRESSED_BIT_BLOCK : SQUASHFS_COMPRESSED_BIT_BLOCK)
-+
-+#define SQUASHFS_COMPRESSED_BLOCK(B) (!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))
-+
-+/*
-+ * Inode number ops. Inodes consist of a compressed block number, and an
-+ * uncompressed offset within that block
-+ */
-+#define SQUASHFS_INODE_BLK(a) ((unsigned int) ((a) >> 16))
-+
-+#define SQUASHFS_INODE_OFFSET(a) ((unsigned int) ((a) & 0xffff))
-+
-+#define SQUASHFS_MKINODE(A, B) ((squashfs_inode_t)(((squashfs_inode_t) (A)\
-+ << 16) + (B)))
-+
-+/* Compute 32 bit VFS inode number from squashfs inode number */
-+#define SQUASHFS_MK_VFS_INODE(a, b) ((unsigned int) (((a) << 8) + \
-+ ((b) >> 2) + 1))
-+/* XXX */
-+
-+/* Translate between VFS mode and squashfs mode */
-+#define SQUASHFS_MODE(a) ((a) & 0xfff)
-+
-+/* fragment and fragment table defines */
-+#define SQUASHFS_FRAGMENT_BYTES(A) (A * sizeof(struct squashfs_fragment_entry))
-+
-+#define SQUASHFS_FRAGMENT_INDEX(A) (SQUASHFS_FRAGMENT_BYTES(A) / \
-+ SQUASHFS_METADATA_SIZE)
-+
-+#define SQUASHFS_FRAGMENT_INDEX_OFFSET(A) (SQUASHFS_FRAGMENT_BYTES(A) % \
-+ SQUASHFS_METADATA_SIZE)
-+
-+#define SQUASHFS_FRAGMENT_INDEXES(A) ((SQUASHFS_FRAGMENT_BYTES(A) + \
-+ SQUASHFS_METADATA_SIZE - 1) / \
-+ SQUASHFS_METADATA_SIZE)
-+
-+#define SQUASHFS_FRAGMENT_INDEX_BYTES(A) (SQUASHFS_FRAGMENT_INDEXES(A) *\
-+ sizeof(long long))
-+
-+/* cached data constants for filesystem */
-+#define SQUASHFS_CACHED_BLKS 8
-+
-+#define SQUASHFS_MAX_FILE_SIZE_LOG 64
-+
-+#define SQUASHFS_MAX_FILE_SIZE ((long long) 1 << \
-+ (SQUASHFS_MAX_FILE_SIZE_LOG - 2))
-+
-+#define SQUASHFS_MARKER_BYTE 0xff
-+
-+/* meta index cache */
-+#define SQUASHFS_META_INDEXES (SQUASHFS_METADATA_SIZE / sizeof(unsigned int))
-+#define SQUASHFS_META_ENTRIES 31
-+#define SQUASHFS_META_NUMBER 8
-+#define SQUASHFS_SLOTS 4
-+
-+struct meta_entry {
-+ long long data_block;
-+ unsigned int index_block;
-+ unsigned short offset;
-+ unsigned short pad;
-+};
-+
-+struct meta_index {
-+ unsigned int inode_number;
-+ unsigned int offset;
-+ unsigned short entries;
-+ unsigned short skip;
-+ unsigned short locked;
-+ unsigned short pad;
-+ struct meta_entry meta_entry[SQUASHFS_META_ENTRIES];
-+};
-+
-+
-+/*
-+ * definitions for structures on disk
-+ */
-+
-+typedef long long squashfs_block_t;
-+typedef long long squashfs_inode_t;
-+
-+struct squashfs_super_block {
-+ unsigned int s_magic;
-+ unsigned int inodes;
-+ unsigned int bytes_used_2;
-+ unsigned int uid_start_2;
-+ unsigned int guid_start_2;
-+ unsigned int inode_table_start_2;
-+ unsigned int directory_table_start_2;
-+ unsigned int s_major:16;
-+ unsigned int s_minor:16;
-+ unsigned int block_size_1:16;
-+ unsigned int block_log:16;
-+ unsigned int flags:8;
-+ unsigned int no_uids:8;
-+ unsigned int no_guids:8;
-+ unsigned int mkfs_time /* time of filesystem creation */;
-+ squashfs_inode_t root_inode;
-+ unsigned int block_size;
-+ unsigned int fragments;
-+ unsigned int fragment_table_start_2;
-+ long long bytes_used;
-+ long long uid_start;
-+ long long guid_start;
-+ long long inode_table_start;
-+ long long directory_table_start;
-+ long long fragment_table_start;
-+ long long unused;
-+} __attribute__ ((packed));
-+
-+struct squashfs_dir_index {
-+ unsigned int index;
-+ unsigned int start_block;
-+ unsigned char size;
-+ unsigned char name[0];
-+} __attribute__ ((packed));
-+
-+#define SQUASHFS_BASE_INODE_HEADER \
-+ unsigned int inode_type:4; \
-+ unsigned int mode:12; \
-+ unsigned int uid:8; \
-+ unsigned int guid:8; \
-+ unsigned int mtime; \
-+ unsigned int inode_number;
-+
-+struct squashfs_base_inode_header {
-+ SQUASHFS_BASE_INODE_HEADER;
-+} __attribute__ ((packed));
-+
-+struct squashfs_ipc_inode_header {
-+ SQUASHFS_BASE_INODE_HEADER;
-+ unsigned int nlink;
-+} __attribute__ ((packed));
-+
-+struct squashfs_dev_inode_header {
-+ SQUASHFS_BASE_INODE_HEADER;
-+ unsigned int nlink;
-+ unsigned short rdev;
-+} __attribute__ ((packed));
-+
-+struct squashfs_symlink_inode_header {
-+ SQUASHFS_BASE_INODE_HEADER;
-+ unsigned int nlink;
-+ unsigned short symlink_size;
-+ char symlink[0];
-+} __attribute__ ((packed));
-+
-+struct squashfs_reg_inode_header {
-+ SQUASHFS_BASE_INODE_HEADER;
-+ squashfs_block_t start_block;
-+ unsigned int fragment;
-+ unsigned int offset;
-+ unsigned int file_size;
-+ unsigned short block_list[0];
-+} __attribute__ ((packed));
-+
-+struct squashfs_lreg_inode_header {
-+ SQUASHFS_BASE_INODE_HEADER;
-+ unsigned int nlink;
-+ squashfs_block_t start_block;
-+ unsigned int fragment;
-+ unsigned int offset;
-+ long long file_size;
-+ unsigned short block_list[0];
-+} __attribute__ ((packed));
-+
-+struct squashfs_dir_inode_header {
-+ SQUASHFS_BASE_INODE_HEADER;
-+ unsigned int nlink;
-+ unsigned int file_size:19;
-+ unsigned int offset:13;
-+ unsigned int start_block;
-+ unsigned int parent_inode;
-+} __attribute__ ((packed));
-+
-+struct squashfs_ldir_inode_header {
-+ SQUASHFS_BASE_INODE_HEADER;
-+ unsigned int nlink;
-+ unsigned int file_size:27;
-+ unsigned int offset:13;
-+ unsigned int start_block;
-+ unsigned int i_count:16;
-+ unsigned int parent_inode;
-+ struct squashfs_dir_index index[0];
-+} __attribute__ ((packed));
-+
-+union squashfs_inode_header {
-+ struct squashfs_base_inode_header base;
-+ struct squashfs_dev_inode_header dev;
-+ struct squashfs_symlink_inode_header symlink;
-+ struct squashfs_reg_inode_header reg;
-+ struct squashfs_lreg_inode_header lreg;
-+ struct squashfs_dir_inode_header dir;
-+ struct squashfs_ldir_inode_header ldir;
-+ struct squashfs_ipc_inode_header ipc;
-+};
-+
-+struct squashfs_dir_entry {
-+ unsigned int offset:13;
-+ unsigned int type:3;
-+ unsigned int size:8;
-+ int inode_number:16;
-+ char name[0];
-+} __attribute__ ((packed));
-+
-+struct squashfs_dir_header {
-+ unsigned int count:8;
-+ unsigned int start_block;
-+ unsigned int inode_number;
-+} __attribute__ ((packed));
-+
-+struct squashfs_fragment_entry {
-+ long long start_block;
-+ unsigned int size;
-+ unsigned int unused;
-+} __attribute__ ((packed));
-+
-+extern int squashfs_uncompress_block(void *d, int dstlen, void *s, int srclen);
-+extern int squashfs_uncompress_init(void);
-+extern int squashfs_uncompress_exit(void);
-+
-+/*
-+ * macros to convert each packed bitfield structure from little endian to big
-+ * endian and vice versa. These are needed when creating or using a filesystem
-+ * on a machine with different byte ordering to the target architecture.
-+ *
-+ */
-+
-+#define SQUASHFS_SWAP_START \
-+ int bits;\
-+ int b_pos;\
-+ unsigned long long val;\
-+ unsigned char *s;\
-+ unsigned char *d;
-+
-+#define SQUASHFS_SWAP_SUPER_BLOCK(s, d) {\
-+ SQUASHFS_SWAP_START\
-+ SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_super_block));\
-+ SQUASHFS_SWAP((s)->s_magic, d, 0, 32);\
-+ SQUASHFS_SWAP((s)->inodes, d, 32, 32);\
-+ SQUASHFS_SWAP((s)->bytes_used_2, d, 64, 32);\
-+ SQUASHFS_SWAP((s)->uid_start_2, d, 96, 32);\
-+ SQUASHFS_SWAP((s)->guid_start_2, d, 128, 32);\
-+ SQUASHFS_SWAP((s)->inode_table_start_2, d, 160, 32);\
-+ SQUASHFS_SWAP((s)->directory_table_start_2, d, 192, 32);\
-+ SQUASHFS_SWAP((s)->s_major, d, 224, 16);\
-+ SQUASHFS_SWAP((s)->s_minor, d, 240, 16);\
-+ SQUASHFS_SWAP((s)->block_size_1, d, 256, 16);\
-+ SQUASHFS_SWAP((s)->block_log, d, 272, 16);\
-+ SQUASHFS_SWAP((s)->flags, d, 288, 8);\
-+ SQUASHFS_SWAP((s)->no_uids, d, 296, 8);\
-+ SQUASHFS_SWAP((s)->no_guids, d, 304, 8);\
-+ SQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\
-+ SQUASHFS_SWAP((s)->root_inode, d, 344, 64);\
-+ SQUASHFS_SWAP((s)->block_size, d, 408, 32);\
-+ SQUASHFS_SWAP((s)->fragments, d, 440, 32);\
-+ SQUASHFS_SWAP((s)->fragment_table_start_2, d, 472, 32);\
-+ SQUASHFS_SWAP((s)->bytes_used, d, 504, 64);\
-+ SQUASHFS_SWAP((s)->uid_start, d, 568, 64);\
-+ SQUASHFS_SWAP((s)->guid_start, d, 632, 64);\
-+ SQUASHFS_SWAP((s)->inode_table_start, d, 696, 64);\
-+ SQUASHFS_SWAP((s)->directory_table_start, d, 760, 64);\
-+ SQUASHFS_SWAP((s)->fragment_table_start, d, 824, 64);\
-+ SQUASHFS_SWAP((s)->unused, d, 888, 64);\
-+}
-+
-+#define SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\
-+ SQUASHFS_MEMSET(s, d, n);\
-+ SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
-+ SQUASHFS_SWAP((s)->mode, d, 4, 12);\
-+ SQUASHFS_SWAP((s)->uid, d, 16, 8);\
-+ SQUASHFS_SWAP((s)->guid, d, 24, 8);\
-+ SQUASHFS_SWAP((s)->mtime, d, 32, 32);\
-+ SQUASHFS_SWAP((s)->inode_number, d, 64, 32);
-+
-+#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, n) {\
-+ SQUASHFS_SWAP_START\
-+ SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\
-+}
-+
-+#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) {\
-+ SQUASHFS_SWAP_START\
-+ SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
-+ sizeof(struct squashfs_ipc_inode_header))\
-+ SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
-+}
-+
-+#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) {\
-+ SQUASHFS_SWAP_START\
-+ SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
-+ sizeof(struct squashfs_dev_inode_header)); \
-+ SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
-+ SQUASHFS_SWAP((s)->rdev, d, 128, 16);\
-+}
-+
-+#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) {\
-+ SQUASHFS_SWAP_START\
-+ SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
-+ sizeof(struct squashfs_symlink_inode_header));\
-+ SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
-+ SQUASHFS_SWAP((s)->symlink_size, d, 128, 16);\
-+}
-+
-+#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) {\
-+ SQUASHFS_SWAP_START\
-+ SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
-+ sizeof(struct squashfs_reg_inode_header));\
-+ SQUASHFS_SWAP((s)->start_block, d, 96, 64);\
-+ SQUASHFS_SWAP((s)->fragment, d, 160, 32);\
-+ SQUASHFS_SWAP((s)->offset, d, 192, 32);\
-+ SQUASHFS_SWAP((s)->file_size, d, 224, 32);\
-+}
-+
-+#define SQUASHFS_SWAP_LREG_INODE_HEADER(s, d) {\
-+ SQUASHFS_SWAP_START\
-+ SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
-+ sizeof(struct squashfs_lreg_inode_header));\
-+ SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
-+ SQUASHFS_SWAP((s)->start_block, d, 128, 64);\
-+ SQUASHFS_SWAP((s)->fragment, d, 192, 32);\
-+ SQUASHFS_SWAP((s)->offset, d, 224, 32);\
-+ SQUASHFS_SWAP((s)->file_size, d, 256, 64);\
-+}
-+
-+#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) {\
-+ SQUASHFS_SWAP_START\
-+ SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
-+ sizeof(struct squashfs_dir_inode_header));\
-+ SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
-+ SQUASHFS_SWAP((s)->file_size, d, 128, 19);\
-+ SQUASHFS_SWAP((s)->offset, d, 147, 13);\
-+ SQUASHFS_SWAP((s)->start_block, d, 160, 32);\
-+ SQUASHFS_SWAP((s)->parent_inode, d, 192, 32);\
-+}
-+
-+#define SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d) {\
-+ SQUASHFS_SWAP_START\
-+ SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
-+ sizeof(struct squashfs_ldir_inode_header));\
-+ SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
-+ SQUASHFS_SWAP((s)->file_size, d, 128, 27);\
-+ SQUASHFS_SWAP((s)->offset, d, 155, 13);\
-+ SQUASHFS_SWAP((s)->start_block, d, 168, 32);\
-+ SQUASHFS_SWAP((s)->i_count, d, 200, 16);\
-+ SQUASHFS_SWAP((s)->parent_inode, d, 216, 32);\
-+}
-+
-+#define SQUASHFS_SWAP_DIR_INDEX(s, d) {\
-+ SQUASHFS_SWAP_START\
-+ SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index));\
-+ SQUASHFS_SWAP((s)->index, d, 0, 32);\
-+ SQUASHFS_SWAP((s)->start_block, d, 32, 32);\
-+ SQUASHFS_SWAP((s)->size, d, 64, 8);\
-+}
-+
-+#define SQUASHFS_SWAP_DIR_HEADER(s, d) {\
-+ SQUASHFS_SWAP_START\
-+ SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header));\
-+ SQUASHFS_SWAP((s)->count, d, 0, 8);\
-+ SQUASHFS_SWAP((s)->start_block, d, 8, 32);\
-+ SQUASHFS_SWAP((s)->inode_number, d, 40, 32);\
-+}
-+
-+#define SQUASHFS_SWAP_DIR_ENTRY(s, d) {\
-+ SQUASHFS_SWAP_START\
-+ SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry));\
-+ SQUASHFS_SWAP((s)->offset, d, 0, 13);\
-+ SQUASHFS_SWAP((s)->type, d, 13, 3);\
-+ SQUASHFS_SWAP((s)->size, d, 16, 8);\
-+ SQUASHFS_SWAP((s)->inode_number, d, 24, 16);\
-+}
-+
-+#define SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d) {\
-+ SQUASHFS_SWAP_START\
-+ SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry));\
-+ SQUASHFS_SWAP((s)->start_block, d, 0, 64);\
-+ SQUASHFS_SWAP((s)->size, d, 64, 32);\
-+}
-+
-+#define SQUASHFS_SWAP_SHORTS(s, d, n) {\
-+ int entry;\
-+ int bit_position;\
-+ SQUASHFS_SWAP_START\
-+ SQUASHFS_MEMSET(s, d, n * 2);\
-+ for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
-+ 16)\
-+ SQUASHFS_SWAP(s[entry], d, bit_position, 16);\
-+}
-+
-+#define SQUASHFS_SWAP_INTS(s, d, n) {\
-+ int entry;\
-+ int bit_position;\
-+ SQUASHFS_SWAP_START\
-+ SQUASHFS_MEMSET(s, d, n * 4);\
-+ for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
-+ 32)\
-+ SQUASHFS_SWAP(s[entry], d, bit_position, 32);\
-+}
-+
-+#define SQUASHFS_SWAP_LONG_LONGS(s, d, n) {\
-+ int entry;\
-+ int bit_position;\
-+ SQUASHFS_SWAP_START\
-+ SQUASHFS_MEMSET(s, d, n * 8);\
-+ for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
-+ 64)\
-+ SQUASHFS_SWAP(s[entry], d, bit_position, 64);\
-+}
-+
-+#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\
-+ int entry;\
-+ int bit_position;\
-+ SQUASHFS_SWAP_START\
-+ SQUASHFS_MEMSET(s, d, n * bits / 8);\
-+ for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
-+ bits)\
-+ SQUASHFS_SWAP(s[entry], d, bit_position, bits);\
-+}
-+
-+#define SQUASHFS_SWAP_FRAGMENT_INDEXES(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)
-+
-+#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY
-+
-+struct squashfs_base_inode_header_1 {
-+ unsigned int inode_type:4;
-+ unsigned int mode:12; /* protection */
-+ unsigned int uid:4; /* index into uid table */
-+ unsigned int guid:4; /* index into guid table */
-+} __attribute__ ((packed));
-+
-+struct squashfs_ipc_inode_header_1 {
-+ unsigned int inode_type:4;
-+ unsigned int mode:12; /* protection */
-+ unsigned int uid:4; /* index into uid table */
-+ unsigned int guid:4; /* index into guid table */
-+ unsigned int type:4;
-+ unsigned int offset:4;
-+} __attribute__ ((packed));
-+
-+struct squashfs_dev_inode_header_1 {
-+ unsigned int inode_type:4;
-+ unsigned int mode:12; /* protection */
-+ unsigned int uid:4; /* index into uid table */
-+ unsigned int guid:4; /* index into guid table */
-+ unsigned short rdev;
-+} __attribute__ ((packed));
-+
-+struct squashfs_symlink_inode_header_1 {
-+ unsigned int inode_type:4;
-+ unsigned int mode:12; /* protection */
-+ unsigned int uid:4; /* index into uid table */
-+ unsigned int guid:4; /* index into guid table */
-+ unsigned short symlink_size;
-+ char symlink[0];
-+} __attribute__ ((packed));
-+
-+struct squashfs_reg_inode_header_1 {
-+ unsigned int inode_type:4;
-+ unsigned int mode:12; /* protection */
-+ unsigned int uid:4; /* index into uid table */
-+ unsigned int guid:4; /* index into guid table */
-+ unsigned int mtime;
-+ unsigned int start_block;
-+ unsigned int file_size:32;
-+ unsigned short block_list[0];
-+} __attribute__ ((packed));
-+
-+struct squashfs_dir_inode_header_1 {
-+ unsigned int inode_type:4;
-+ unsigned int mode:12; /* protection */
-+ unsigned int uid:4; /* index into uid table */
-+ unsigned int guid:4; /* index into guid table */
-+ unsigned int file_size:19;
-+ unsigned int offset:13;
-+ unsigned int mtime;
-+ unsigned int start_block:24;
-+} __attribute__ ((packed));
-+
-+#define SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n) \
-+ SQUASHFS_MEMSET(s, d, n);\
-+ SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
-+ SQUASHFS_SWAP((s)->mode, d, 4, 12);\
-+ SQUASHFS_SWAP((s)->uid, d, 16, 4);\
-+ SQUASHFS_SWAP((s)->guid, d, 20, 4);
-+
-+#define SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, n) {\
-+ SQUASHFS_SWAP_START\
-+ SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n)\
-+}
-+
-+#define SQUASHFS_SWAP_IPC_INODE_HEADER_1(s, d) {\
-+ SQUASHFS_SWAP_START\
-+ SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
-+ sizeof(struct squashfs_ipc_inode_header_1));\
-+ SQUASHFS_SWAP((s)->type, d, 24, 4);\
-+ SQUASHFS_SWAP((s)->offset, d, 28, 4);\
-+}
-+
-+#define SQUASHFS_SWAP_DEV_INODE_HEADER_1(s, d) {\
-+ SQUASHFS_SWAP_START\
-+ SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
-+ sizeof(struct squashfs_dev_inode_header_1));\
-+ SQUASHFS_SWAP((s)->rdev, d, 24, 16);\
-+}
-+
-+#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(s, d) {\
-+ SQUASHFS_SWAP_START\
-+ SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
-+ sizeof(struct squashfs_symlink_inode_header_1));\
-+ SQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\
-+}
-+
-+#define SQUASHFS_SWAP_REG_INODE_HEADER_1(s, d) {\
-+ SQUASHFS_SWAP_START\
-+ SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
-+ sizeof(struct squashfs_reg_inode_header_1));\
-+ SQUASHFS_SWAP((s)->mtime, d, 24, 32);\
-+ SQUASHFS_SWAP((s)->start_block, d, 56, 32);\
-+ SQUASHFS_SWAP((s)->file_size, d, 88, 32);\
-+}
-+
-+#define SQUASHFS_SWAP_DIR_INODE_HEADER_1(s, d) {\
-+ SQUASHFS_SWAP_START\
-+ SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
-+ sizeof(struct squashfs_dir_inode_header_1));\
-+ SQUASHFS_SWAP((s)->file_size, d, 24, 19);\
-+ SQUASHFS_SWAP((s)->offset, d, 43, 13);\
-+ SQUASHFS_SWAP((s)->mtime, d, 56, 32);\
-+ SQUASHFS_SWAP((s)->start_block, d, 88, 24);\
-+}
-+
-+#endif
-+
-+#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY
-+
-+struct squashfs_dir_index_2 {
-+ unsigned int index:27;
-+ unsigned int start_block:29;
-+ unsigned char size;
-+ unsigned char name[0];
-+} __attribute__ ((packed));
-+
-+struct squashfs_base_inode_header_2 {
-+ unsigned int inode_type:4;
-+ unsigned int mode:12; /* protection */
-+ unsigned int uid:8; /* index into uid table */
-+ unsigned int guid:8; /* index into guid table */
-+} __attribute__ ((packed));
-+
-+struct squashfs_ipc_inode_header_2 {
-+ unsigned int inode_type:4;
-+ unsigned int mode:12; /* protection */
-+ unsigned int uid:8; /* index into uid table */
-+ unsigned int guid:8; /* index into guid table */
-+} __attribute__ ((packed));
-+
-+struct squashfs_dev_inode_header_2 {
-+ unsigned int inode_type:4;
-+ unsigned int mode:12; /* protection */
-+ unsigned int uid:8; /* index into uid table */
-+ unsigned int guid:8; /* index into guid table */
-+ unsigned short rdev;
-+} __attribute__ ((packed));
-+
-+struct squashfs_symlink_inode_header_2 {
-+ unsigned int inode_type:4;
-+ unsigned int mode:12; /* protection */
-+ unsigned int uid:8; /* index into uid table */
-+ unsigned int guid:8; /* index into guid table */
-+ unsigned short symlink_size;
-+ char symlink[0];
-+} __attribute__ ((packed));
-+
-+struct squashfs_reg_inode_header_2 {
-+ unsigned int inode_type:4;
-+ unsigned int mode:12; /* protection */
-+ unsigned int uid:8; /* index into uid table */
-+ unsigned int guid:8; /* index into guid table */
-+ unsigned int mtime;
-+ unsigned int start_block;
-+ unsigned int fragment;
-+ unsigned int offset;
-+ unsigned int file_size:32;
-+ unsigned short block_list[0];
-+} __attribute__ ((packed));
-+
-+struct squashfs_dir_inode_header_2 {
-+ unsigned int inode_type:4;
-+ unsigned int mode:12; /* protection */
-+ unsigned int uid:8; /* index into uid table */
-+ unsigned int guid:8; /* index into guid table */
-+ unsigned int file_size:19;
-+ unsigned int offset:13;
-+ unsigned int mtime;
-+ unsigned int start_block:24;
-+} __attribute__ ((packed));
-+
-+struct squashfs_ldir_inode_header_2 {
-+ unsigned int inode_type:4;
-+ unsigned int mode:12; /* protection */
-+ unsigned int uid:8; /* index into uid table */
-+ unsigned int guid:8; /* index into guid table */
-+ unsigned int file_size:27;
-+ unsigned int offset:13;
-+ unsigned int mtime;
-+ unsigned int start_block:24;
-+ unsigned int i_count:16;
-+ struct squashfs_dir_index_2 index[0];
-+} __attribute__ ((packed));
-+
-+union squashfs_inode_header_2 {
-+ struct squashfs_base_inode_header_2 base;
-+ struct squashfs_dev_inode_header_2 dev;
-+ struct squashfs_symlink_inode_header_2 symlink;
-+ struct squashfs_reg_inode_header_2 reg;
-+ struct squashfs_dir_inode_header_2 dir;
-+ struct squashfs_ldir_inode_header_2 ldir;
-+ struct squashfs_ipc_inode_header_2 ipc;
-+};
-+
-+struct squashfs_dir_header_2 {
-+ unsigned int count:8;
-+ unsigned int start_block:24;
-+} __attribute__ ((packed));
-+
-+struct squashfs_dir_entry_2 {
-+ unsigned int offset:13;
-+ unsigned int type:3;
-+ unsigned int size:8;
-+ char name[0];
-+} __attribute__ ((packed));
-+
-+struct squashfs_fragment_entry_2 {
-+ unsigned int start_block;
-+ unsigned int size;
-+} __attribute__ ((packed));
-+
-+#define SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\
-+ SQUASHFS_MEMSET(s, d, n);\
-+ SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
-+ SQUASHFS_SWAP((s)->mode, d, 4, 12);\
-+ SQUASHFS_SWAP((s)->uid, d, 16, 8);\
-+ SQUASHFS_SWAP((s)->guid, d, 24, 8);\
-+
-+#define SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, n) {\
-+ SQUASHFS_SWAP_START\
-+ SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\
-+}
-+
-+#define SQUASHFS_SWAP_IPC_INODE_HEADER_2(s, d) \
-+ SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, sizeof(struct squashfs_ipc_inode_header_2))
-+
-+#define SQUASHFS_SWAP_DEV_INODE_HEADER_2(s, d) {\
-+ SQUASHFS_SWAP_START\
-+ SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
-+ sizeof(struct squashfs_dev_inode_header_2)); \
-+ SQUASHFS_SWAP((s)->rdev, d, 32, 16);\
-+}
-+
-+#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(s, d) {\
-+ SQUASHFS_SWAP_START\
-+ SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
-+ sizeof(struct squashfs_symlink_inode_header_2));\
-+ SQUASHFS_SWAP((s)->symlink_size, d, 32, 16);\
-+}
-+
-+#define SQUASHFS_SWAP_REG_INODE_HEADER_2(s, d) {\
-+ SQUASHFS_SWAP_START\
-+ SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
-+ sizeof(struct squashfs_reg_inode_header_2));\
-+ SQUASHFS_SWAP((s)->mtime, d, 32, 32);\
-+ SQUASHFS_SWAP((s)->start_block, d, 64, 32);\
-+ SQUASHFS_SWAP((s)->fragment, d, 96, 32);\
-+ SQUASHFS_SWAP((s)->offset, d, 128, 32);\
-+ SQUASHFS_SWAP((s)->file_size, d, 160, 32);\
-+}
-+
-+#define SQUASHFS_SWAP_DIR_INODE_HEADER_2(s, d) {\
-+ SQUASHFS_SWAP_START\
-+ SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
-+ sizeof(struct squashfs_dir_inode_header_2));\
-+ SQUASHFS_SWAP((s)->file_size, d, 32, 19);\
-+ SQUASHFS_SWAP((s)->offset, d, 51, 13);\
-+ SQUASHFS_SWAP((s)->mtime, d, 64, 32);\
-+ SQUASHFS_SWAP((s)->start_block, d, 96, 24);\
-+}
-+
-+#define SQUASHFS_SWAP_LDIR_INODE_HEADER_2(s, d) {\
-+ SQUASHFS_SWAP_START\
-+ SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
-+ sizeof(struct squashfs_ldir_inode_header_2));\
-+ SQUASHFS_SWAP((s)->file_size, d, 32, 27);\
-+ SQUASHFS_SWAP((s)->offset, d, 59, 13);\
-+ SQUASHFS_SWAP((s)->mtime, d, 72, 32);\
-+ SQUASHFS_SWAP((s)->start_block, d, 104, 24);\
-+ SQUASHFS_SWAP((s)->i_count, d, 128, 16);\
-+}
-+
-+#define SQUASHFS_SWAP_DIR_INDEX_2(s, d) {\
-+ SQUASHFS_SWAP_START\
-+ SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index_2));\
-+ SQUASHFS_SWAP((s)->index, d, 0, 27);\
-+ SQUASHFS_SWAP((s)->start_block, d, 27, 29);\
-+ SQUASHFS_SWAP((s)->size, d, 56, 8);\
-+}
-+#define SQUASHFS_SWAP_DIR_HEADER_2(s, d) {\
-+ SQUASHFS_SWAP_START\
-+ SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header_2));\
-+ SQUASHFS_SWAP((s)->count, d, 0, 8);\
-+ SQUASHFS_SWAP((s)->start_block, d, 8, 24);\
-+}
-+
-+#define SQUASHFS_SWAP_DIR_ENTRY_2(s, d) {\
-+ SQUASHFS_SWAP_START\
-+ SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry_2));\
-+ SQUASHFS_SWAP((s)->offset, d, 0, 13);\
-+ SQUASHFS_SWAP((s)->type, d, 13, 3);\
-+ SQUASHFS_SWAP((s)->size, d, 16, 8);\
-+}
-+
-+#define SQUASHFS_SWAP_FRAGMENT_ENTRY_2(s, d) {\
-+ SQUASHFS_SWAP_START\
-+ SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry_2));\
-+ SQUASHFS_SWAP((s)->start_block, d, 0, 32);\
-+ SQUASHFS_SWAP((s)->size, d, 32, 32);\
-+}
-+
-+#define SQUASHFS_SWAP_FRAGMENT_INDEXES_2(s, d, n) SQUASHFS_SWAP_INTS(s, d, n)
-+
-+/* fragment and fragment table defines */
-+#define SQUASHFS_FRAGMENT_BYTES_2(A) (A * sizeof(struct squashfs_fragment_entry_2))
-+
-+#define SQUASHFS_FRAGMENT_INDEX_2(A) (SQUASHFS_FRAGMENT_BYTES_2(A) / \
-+ SQUASHFS_METADATA_SIZE)
-+
-+#define SQUASHFS_FRAGMENT_INDEX_OFFSET_2(A) (SQUASHFS_FRAGMENT_BYTES_2(A) % \
-+ SQUASHFS_METADATA_SIZE)
-+
-+#define SQUASHFS_FRAGMENT_INDEXES_2(A) ((SQUASHFS_FRAGMENT_BYTES_2(A) + \
-+ SQUASHFS_METADATA_SIZE - 1) / \
-+ SQUASHFS_METADATA_SIZE)
-+
-+#define SQUASHFS_FRAGMENT_INDEX_BYTES_2(A) (SQUASHFS_FRAGMENT_INDEXES_2(A) *\
-+ sizeof(int))
-+
-+#endif
-+
-+#ifdef __KERNEL__
-+
-+/*
-+ * macros used to swap each structure entry, taking into account
-+ * bitfields and different bitfield placing conventions on differing
-+ * architectures
-+ */
-+
-+#include <asm/byteorder.h>
-+
-+#ifdef __BIG_ENDIAN
-+ /* convert from little endian to big endian */
-+#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \
-+ tbits, b_pos)
-+#else
-+ /* convert from big endian to little endian */
-+#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \
-+ tbits, 64 - tbits - b_pos)
-+#endif
-+
-+#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\
-+ b_pos = pos % 8;\
-+ val = 0;\
-+ s = (unsigned char *)p + (pos / 8);\
-+ d = ((unsigned char *) &val) + 7;\
-+ for(bits = 0; bits < (tbits + b_pos); bits += 8) \
-+ *d-- = *s++;\
-+ value = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\
-+}
-+
-+#define SQUASHFS_MEMSET(s, d, n) memset(s, 0, n);
-+
-+#endif
-+#endif
-Index: linux-2.6.21.7/include/linux/squashfs_fs_i.h
-===================================================================
---- /dev/null
-+++ linux-2.6.21.7/include/linux/squashfs_fs_i.h
-@@ -0,0 +1,45 @@
-+#ifndef SQUASHFS_FS_I
-+#define SQUASHFS_FS_I
-+/*
-+ * Squashfs
-+ *
-+ * Copyright (c) 2002, 2003, 2004, 2005, 2006
-+ * Phillip Lougher <phillip@lougher.org.uk>
-+ *
-+ * 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,
-+ * 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-+ *
-+ * squashfs_fs_i.h
-+ */
-+
-+struct squashfs_inode_info {
-+ long long start_block;
-+ unsigned int offset;
-+ union {
-+ struct {
-+ long long fragment_start_block;
-+ unsigned int fragment_size;
-+ unsigned int fragment_offset;
-+ long long block_list_start;
-+ } s1;
-+ struct {
-+ long long directory_index_start;
-+ unsigned int directory_index_offset;
-+ unsigned int directory_index_count;
-+ unsigned int parent_inode;
-+ } s2;
-+ } u;
-+ struct inode vfs_inode;
-+};
-+#endif
-Index: linux-2.6.21.7/include/linux/squashfs_fs_sb.h
-===================================================================
---- /dev/null
-+++ linux-2.6.21.7/include/linux/squashfs_fs_sb.h
-@@ -0,0 +1,74 @@
-+#ifndef SQUASHFS_FS_SB
-+#define SQUASHFS_FS_SB
-+/*
-+ * Squashfs
-+ *
-+ * Copyright (c) 2002, 2003, 2004, 2005, 2006
-+ * Phillip Lougher <phillip@lougher.org.uk>
-+ *
-+ * 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,
-+ * 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-+ *
-+ * squashfs_fs_sb.h
-+ */
-+
-+#include <linux/squashfs_fs.h>
-+
-+struct squashfs_cache {
-+ long long block;
-+ int length;
-+ long long next_index;
-+ char *data;
-+};
-+
-+struct squashfs_fragment_cache {
-+ long long block;
-+ int length;
-+ unsigned int locked;
-+ char *data;
-+};
-+
-+struct squashfs_sb_info {
-+ struct squashfs_super_block sblk;
-+ int devblksize;
-+ int devblksize_log2;
-+ int swap;
-+ struct squashfs_cache *block_cache;
-+ struct squashfs_fragment_cache *fragment;
-+ int next_cache;
-+ int next_fragment;
-+ int next_meta_index;
-+ unsigned int *uid;
-+ unsigned int *guid;
-+ long long *fragment_index;
-+ unsigned int *fragment_index_2;
-+ unsigned int read_size;
-+ char *read_data;
-+ char *read_page;
-+ struct semaphore read_data_mutex;
-+ struct semaphore read_page_mutex;
-+ struct semaphore block_cache_mutex;
-+ struct semaphore fragment_mutex;
-+ struct semaphore meta_index_mutex;
-+ wait_queue_head_t waitq;
-+ wait_queue_head_t fragment_wait_queue;
-+ struct meta_index *meta_index;
-+ struct inode *(*iget)(struct super_block *s, squashfs_inode_t \
-+ inode);
-+ long long (*read_blocklist)(struct inode *inode, int \
-+ index, int readahead_blks, char *block_list, \
-+ unsigned short **block_p, unsigned int *bsize);
-+ int (*read_fragment_index_table)(struct super_block *s);
-+};
-+#endif
-Index: linux-2.6.21.7/init/do_mounts_rd.c
-===================================================================
---- linux-2.6.21.7.orig/init/do_mounts_rd.c
-+++ linux-2.6.21.7/init/do_mounts_rd.c
-@@ -5,6 +5,7 @@
- #include <linux/ext2_fs.h>
- #include <linux/romfs_fs.h>
- #include <linux/cramfs_fs.h>
-+#include <linux/squashfs_fs.h>
- #include <linux/initrd.h>
- #include <linux/string.h>
-
-@@ -39,6 +40,7 @@ static int __init crd_load(int in_fd, in
- * numbers could not be found.
- *
- * We currently check for the following magic numbers:
-+ * squashfs
- * minix
- * ext2
- * romfs
-@@ -53,6 +55,7 @@ identify_ramdisk_image(int fd, int start
- struct ext2_super_block *ext2sb;
- struct romfs_super_block *romfsb;
- struct cramfs_super *cramfsb;
-+ struct squashfs_super_block *squashfsb;
- int nblocks = -1;
- unsigned char *buf;
-
-@@ -64,6 +67,7 @@ identify_ramdisk_image(int fd, int start
- ext2sb = (struct ext2_super_block *) buf;
- romfsb = (struct romfs_super_block *) buf;
- cramfsb = (struct cramfs_super *) buf;
-+ squashfsb = (struct squashfs_super_block *) buf;
- memset(buf, 0xe5, size);
-
- /*
-@@ -101,6 +105,15 @@ identify_ramdisk_image(int fd, int start
- goto done;
- }
-
-+ /* squashfs is at block zero too */
-+ if (squashfsb->s_magic == SQUASHFS_MAGIC) {
-+ printk(KERN_NOTICE
-+ "RAMDISK: squashfs filesystem found at block %d\n",
-+ start_block);
-+ nblocks = (squashfsb->bytes_used+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;
-+ goto done;
-+ }
-+
- /*
- * Read block 1 to test for minix and ext2 superblock
- */
+++ /dev/null
-Index: linux-2.6.21.7/include/linux/LzmaDecode.h
-===================================================================
---- /dev/null
-+++ linux-2.6.21.7/include/linux/LzmaDecode.h
-@@ -0,0 +1,100 @@
-+/*
-+ LzmaDecode.h
-+ LZMA Decoder interface
-+
-+ LZMA SDK 4.05 Copyright (c) 1999-2004 Igor Pavlov (2004-08-25)
-+ http://www.7-zip.org/
-+
-+ LZMA SDK is licensed under two licenses:
-+ 1) GNU Lesser General Public License (GNU LGPL)
-+ 2) Common Public License (CPL)
-+ It means that you can select one of these two licenses and
-+ follow rules of that license.
-+
-+ SPECIAL EXCEPTION:
-+ Igor Pavlov, as the author of this code, expressly permits you to
-+ statically or dynamically link your code (or bind by name) to the
-+ interfaces of this file without subjecting your linked code to the
-+ terms of the CPL or GNU LGPL. Any modifications or additions
-+ to this file, however, are subject to the LGPL or CPL terms.
-+*/
-+
-+#ifndef __LZMADECODE_H
-+#define __LZMADECODE_H
-+
-+/* #define _LZMA_IN_CB */
-+/* Use callback for input data */
-+
-+/* #define _LZMA_OUT_READ */
-+/* Use read function for output data */
-+
-+/* #define _LZMA_PROB32 */
-+/* It can increase speed on some 32-bit CPUs,
-+ but memory usage will be doubled in that case */
-+
-+/* #define _LZMA_LOC_OPT */
-+/* Enable local speed optimizations inside code */
-+
-+#ifndef UInt32
-+#ifdef _LZMA_UINT32_IS_ULONG
-+#define UInt32 unsigned long
-+#else
-+#define UInt32 unsigned int
-+#endif
-+#endif
-+
-+#ifdef _LZMA_PROB32
-+#define CProb UInt32
-+#else
-+#define CProb unsigned short
-+#endif
-+
-+#define LZMA_RESULT_OK 0
-+#define LZMA_RESULT_DATA_ERROR 1
-+#define LZMA_RESULT_NOT_ENOUGH_MEM 2
-+
-+#ifdef _LZMA_IN_CB
-+typedef struct _ILzmaInCallback
-+{
-+ int (*Read)(void *object, unsigned char **buffer, UInt32 *bufferSize);
-+} ILzmaInCallback;
-+#endif
-+
-+#define LZMA_BASE_SIZE 1846
-+#define LZMA_LIT_SIZE 768
-+
-+/*
-+bufferSize = (LZMA_BASE_SIZE + (LZMA_LIT_SIZE << (lc + lp)))* sizeof(CProb)
-+bufferSize += 100 in case of _LZMA_OUT_READ
-+by default CProb is unsigned short,
-+but if specify _LZMA_PROB_32, CProb will be UInt32(unsigned int)
-+*/
-+
-+#ifdef _LZMA_OUT_READ
-+int LzmaDecoderInit(
-+ unsigned char *buffer, UInt32 bufferSize,
-+ int lc, int lp, int pb,
-+ unsigned char *dictionary, UInt32 dictionarySize,
-+ #ifdef _LZMA_IN_CB
-+ ILzmaInCallback *inCallback
-+ #else
-+ unsigned char *inStream, UInt32 inSize
-+ #endif
-+);
-+#endif
-+
-+int LzmaDecode(
-+ unsigned char *buffer,
-+ #ifndef _LZMA_OUT_READ
-+ UInt32 bufferSize,
-+ int lc, int lp, int pb,
-+ #ifdef _LZMA_IN_CB
-+ ILzmaInCallback *inCallback,
-+ #else
-+ unsigned char *inStream, UInt32 inSize,
-+ #endif
-+ #endif
-+ unsigned char *outStream, UInt32 outSize,
-+ UInt32 *outSizeProcessed);
-+
-+#endif
-Index: linux-2.6.21.7/lib/LzmaDecode.c
-===================================================================
---- /dev/null
-+++ linux-2.6.21.7/lib/LzmaDecode.c
-@@ -0,0 +1,663 @@
-+/*
-+ LzmaDecode.c
-+ LZMA Decoder
-+
-+ LZMA SDK 4.05 Copyright (c) 1999-2004 Igor Pavlov (2004-08-25)
-+ http://www.7-zip.org/
-+
-+ LZMA SDK is licensed under two licenses:
-+ 1) GNU Lesser General Public License (GNU LGPL)
-+ 2) Common Public License (CPL)
-+ It means that you can select one of these two licenses and
-+ follow rules of that license.
-+
-+ SPECIAL EXCEPTION:
-+ Igor Pavlov, as the author of this code, expressly permits you to
-+ statically or dynamically link your code (or bind by name) to the
-+ interfaces of this file without subjecting your linked code to the
-+ terms of the CPL or GNU LGPL. Any modifications or additions
-+ to this file, however, are subject to the LGPL or CPL terms.
-+*/
-+
-+#include <linux/LzmaDecode.h>
-+
-+#ifndef Byte
-+#define Byte unsigned char
-+#endif
-+
-+#define kNumTopBits 24
-+#define kTopValue ((UInt32)1 << kNumTopBits)
-+
-+#define kNumBitModelTotalBits 11
-+#define kBitModelTotal (1 << kNumBitModelTotalBits)
-+#define kNumMoveBits 5
-+
-+typedef struct _CRangeDecoder
-+{
-+ Byte *Buffer;
-+ Byte *BufferLim;
-+ UInt32 Range;
-+ UInt32 Code;
-+ #ifdef _LZMA_IN_CB
-+ ILzmaInCallback *InCallback;
-+ int Result;
-+ #endif
-+ int ExtraBytes;
-+} CRangeDecoder;
-+
-+Byte RangeDecoderReadByte(CRangeDecoder *rd)
-+{
-+ if (rd->Buffer == rd->BufferLim)
-+ {
-+ #ifdef _LZMA_IN_CB
-+ UInt32 size;
-+ rd->Result = rd->InCallback->Read(rd->InCallback, &rd->Buffer, &size);
-+ rd->BufferLim = rd->Buffer + size;
-+ if (size == 0)
-+ #endif
-+ {
-+ rd->ExtraBytes = 1;
-+ return 0xFF;
-+ }
-+ }
-+ return (*rd->Buffer++);
-+}
-+
-+/* #define ReadByte (*rd->Buffer++) */
-+#define ReadByte (RangeDecoderReadByte(rd))
-+
-+void RangeDecoderInit(CRangeDecoder *rd,
-+ #ifdef _LZMA_IN_CB
-+ ILzmaInCallback *inCallback
-+ #else
-+ Byte *stream, UInt32 bufferSize
-+ #endif
-+ )
-+{
-+ int i;
-+ #ifdef _LZMA_IN_CB
-+ rd->InCallback = inCallback;
-+ rd->Buffer = rd->BufferLim = 0;
-+ #else
-+ rd->Buffer = stream;
-+ rd->BufferLim = stream + bufferSize;
-+ #endif
-+ rd->ExtraBytes = 0;
-+ rd->Code = 0;
-+ rd->Range = (0xFFFFFFFF);
-+ for(i = 0; i < 5; i++)
-+ rd->Code = (rd->Code << 8) | ReadByte;
-+}
-+
-+#define RC_INIT_VAR UInt32 range = rd->Range; UInt32 code = rd->Code;
-+#define RC_FLUSH_VAR rd->Range = range; rd->Code = code;
-+#define RC_NORMALIZE if (range < kTopValue) { range <<= 8; code = (code << 8) | ReadByte; }
-+
-+UInt32 RangeDecoderDecodeDirectBits(CRangeDecoder *rd, int numTotalBits)
-+{
-+ RC_INIT_VAR
-+ UInt32 result = 0;
-+ int i;
-+ for (i = numTotalBits; i > 0; i--)
-+ {
-+ /* UInt32 t; */
-+ range >>= 1;
-+
-+ result <<= 1;
-+ if (code >= range)
-+ {
-+ code -= range;
-+ result |= 1;
-+ }
-+ /*
-+ t = (code - range) >> 31;
-+ t &= 1;
-+ code -= range & (t - 1);
-+ result = (result + result) | (1 - t);
-+ */
-+ RC_NORMALIZE
-+ }
-+ RC_FLUSH_VAR
-+ return result;
-+}
-+
-+int RangeDecoderBitDecode(CProb *prob, CRangeDecoder *rd)
-+{
-+ UInt32 bound = (rd->Range >> kNumBitModelTotalBits) * *prob;
-+ if (rd->Code < bound)
-+ {
-+ rd->Range = bound;
-+ *prob += (kBitModelTotal - *prob) >> kNumMoveBits;
-+ if (rd->Range < kTopValue)
-+ {
-+ rd->Code = (rd->Code << 8) | ReadByte;
-+ rd->Range <<= 8;
-+ }
-+ return 0;
-+ }
-+ else
-+ {
-+ rd->Range -= bound;
-+ rd->Code -= bound;
-+ *prob -= (*prob) >> kNumMoveBits;
-+ if (rd->Range < kTopValue)
-+ {
-+ rd->Code = (rd->Code << 8) | ReadByte;
-+ rd->Range <<= 8;
-+ }
-+ return 1;
-+ }
-+}
-+
-+#define RC_GET_BIT2(prob, mi, A0, A1) \
-+ UInt32 bound = (range >> kNumBitModelTotalBits) * *prob; \
-+ if (code < bound) \
-+ { A0; range = bound; *prob += (kBitModelTotal - *prob) >> kNumMoveBits; mi <<= 1; } \
-+ else \
-+ { A1; range -= bound; code -= bound; *prob -= (*prob) >> kNumMoveBits; mi = (mi + mi) + 1; } \
-+ RC_NORMALIZE
-+
-+#define RC_GET_BIT(prob, mi) RC_GET_BIT2(prob, mi, ; , ;)
-+
-+int RangeDecoderBitTreeDecode(CProb *probs, int numLevels, CRangeDecoder *rd)
-+{
-+ int mi = 1;
-+ int i;
-+ #ifdef _LZMA_LOC_OPT
-+ RC_INIT_VAR
-+ #endif
-+ for(i = numLevels; i > 0; i--)
-+ {
-+ #ifdef _LZMA_LOC_OPT
-+ CProb *prob = probs + mi;
-+ RC_GET_BIT(prob, mi)
-+ #else
-+ mi = (mi + mi) + RangeDecoderBitDecode(probs + mi, rd);
-+ #endif
-+ }
-+ #ifdef _LZMA_LOC_OPT
-+ RC_FLUSH_VAR
-+ #endif
-+ return mi - (1 << numLevels);
-+}
-+
-+int RangeDecoderReverseBitTreeDecode(CProb *probs, int numLevels, CRangeDecoder *rd)
-+{
-+ int mi = 1;
-+ int i;
-+ int symbol = 0;
-+ #ifdef _LZMA_LOC_OPT
-+ RC_INIT_VAR
-+ #endif
-+ for(i = 0; i < numLevels; i++)
-+ {
-+ #ifdef _LZMA_LOC_OPT
-+ CProb *prob = probs + mi;
-+ RC_GET_BIT2(prob, mi, ; , symbol |= (1 << i))
-+ #else
-+ int bit = RangeDecoderBitDecode(probs + mi, rd);
-+ mi = mi + mi + bit;
-+ symbol |= (bit << i);
-+ #endif
-+ }
-+ #ifdef _LZMA_LOC_OPT
-+ RC_FLUSH_VAR
-+ #endif
-+ return symbol;
-+}
-+
-+Byte LzmaLiteralDecode(CProb *probs, CRangeDecoder *rd)
-+{
-+ int symbol = 1;
-+ #ifdef _LZMA_LOC_OPT
-+ RC_INIT_VAR
-+ #endif
-+ do
-+ {
-+ #ifdef _LZMA_LOC_OPT
-+ CProb *prob = probs + symbol;
-+ RC_GET_BIT(prob, symbol)
-+ #else
-+ symbol = (symbol + symbol) | RangeDecoderBitDecode(probs + symbol, rd);
-+ #endif
-+ }
-+ while (symbol < 0x100);
-+ #ifdef _LZMA_LOC_OPT
-+ RC_FLUSH_VAR
-+ #endif
-+ return symbol;
-+}
-+
-+Byte LzmaLiteralDecodeMatch(CProb *probs, CRangeDecoder *rd, Byte matchByte)
-+{
-+ int symbol = 1;
-+ #ifdef _LZMA_LOC_OPT
-+ RC_INIT_VAR
-+ #endif
-+ do
-+ {
-+ int bit;
-+ int matchBit = (matchByte >> 7) & 1;
-+ matchByte <<= 1;
-+ #ifdef _LZMA_LOC_OPT
-+ {
-+ CProb *prob = probs + ((1 + matchBit) << 8) + symbol;
-+ RC_GET_BIT2(prob, symbol, bit = 0, bit = 1)
-+ }
-+ #else
-+ bit = RangeDecoderBitDecode(probs + ((1 + matchBit) << 8) + symbol, rd);
-+ symbol = (symbol << 1) | bit;
-+ #endif
-+ if (matchBit != bit)
-+ {
-+ while (symbol < 0x100)
-+ {
-+ #ifdef _LZMA_LOC_OPT
-+ CProb *prob = probs + symbol;
-+ RC_GET_BIT(prob, symbol)
-+ #else
-+ symbol = (symbol + symbol) | RangeDecoderBitDecode(probs + symbol, rd);
-+ #endif
-+ }
-+ break;
-+ }
-+ }
-+ while (symbol < 0x100);
-+ #ifdef _LZMA_LOC_OPT
-+ RC_FLUSH_VAR
-+ #endif
-+ return symbol;
-+}
-+
-+#define kNumPosBitsMax 4
-+#define kNumPosStatesMax (1 << kNumPosBitsMax)
-+
-+#define kLenNumLowBits 3
-+#define kLenNumLowSymbols (1 << kLenNumLowBits)
-+#define kLenNumMidBits 3
-+#define kLenNumMidSymbols (1 << kLenNumMidBits)
-+#define kLenNumHighBits 8
-+#define kLenNumHighSymbols (1 << kLenNumHighBits)
-+
-+#define LenChoice 0
-+#define LenChoice2 (LenChoice + 1)
-+#define LenLow (LenChoice2 + 1)
-+#define LenMid (LenLow + (kNumPosStatesMax << kLenNumLowBits))
-+#define LenHigh (LenMid + (kNumPosStatesMax << kLenNumMidBits))
-+#define kNumLenProbs (LenHigh + kLenNumHighSymbols)
-+
-+int LzmaLenDecode(CProb *p, CRangeDecoder *rd, int posState)
-+{
-+ if(RangeDecoderBitDecode(p + LenChoice, rd) == 0)
-+ return RangeDecoderBitTreeDecode(p + LenLow +
-+ (posState << kLenNumLowBits), kLenNumLowBits, rd);
-+ if(RangeDecoderBitDecode(p + LenChoice2, rd) == 0)
-+ return kLenNumLowSymbols + RangeDecoderBitTreeDecode(p + LenMid +
-+ (posState << kLenNumMidBits), kLenNumMidBits, rd);
-+ return kLenNumLowSymbols + kLenNumMidSymbols +
-+ RangeDecoderBitTreeDecode(p + LenHigh, kLenNumHighBits, rd);
-+}
-+
-+#define kNumStates 12
-+
-+#define kStartPosModelIndex 4
-+#define kEndPosModelIndex 14
-+#define kNumFullDistances (1 << (kEndPosModelIndex >> 1))
-+
-+#define kNumPosSlotBits 6
-+#define kNumLenToPosStates 4
-+
-+#define kNumAlignBits 4
-+#define kAlignTableSize (1 << kNumAlignBits)
-+
-+#define kMatchMinLen 2
-+
-+#define IsMatch 0
-+#define IsRep (IsMatch + (kNumStates << kNumPosBitsMax))
-+#define IsRepG0 (IsRep + kNumStates)
-+#define IsRepG1 (IsRepG0 + kNumStates)
-+#define IsRepG2 (IsRepG1 + kNumStates)
-+#define IsRep0Long (IsRepG2 + kNumStates)
-+#define PosSlot (IsRep0Long + (kNumStates << kNumPosBitsMax))
-+#define SpecPos (PosSlot + (kNumLenToPosStates << kNumPosSlotBits))
-+#define Align (SpecPos + kNumFullDistances - kEndPosModelIndex)
-+#define LenCoder (Align + kAlignTableSize)
-+#define RepLenCoder (LenCoder + kNumLenProbs)
-+#define Literal (RepLenCoder + kNumLenProbs)
-+
-+#if Literal != LZMA_BASE_SIZE
-+StopCompilingDueBUG
-+#endif
-+
-+#ifdef _LZMA_OUT_READ
-+
-+typedef struct _LzmaVarState
-+{
-+ CRangeDecoder RangeDecoder;
-+ Byte *Dictionary;
-+ UInt32 DictionarySize;
-+ UInt32 DictionaryPos;
-+ UInt32 GlobalPos;
-+ UInt32 Reps[4];
-+ int lc;
-+ int lp;
-+ int pb;
-+ int State;
-+ int PreviousIsMatch;
-+ int RemainLen;
-+} LzmaVarState;
-+
-+int LzmaDecoderInit(
-+ unsigned char *buffer, UInt32 bufferSize,
-+ int lc, int lp, int pb,
-+ unsigned char *dictionary, UInt32 dictionarySize,
-+ #ifdef _LZMA_IN_CB
-+ ILzmaInCallback *inCallback
-+ #else
-+ unsigned char *inStream, UInt32 inSize
-+ #endif
-+ )
-+{
-+ LzmaVarState *vs = (LzmaVarState *)buffer;
-+ CProb *p = (CProb *)(buffer + sizeof(LzmaVarState));
-+ UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + lp));
-+ UInt32 i;
-+ if (bufferSize < numProbs * sizeof(CProb) + sizeof(LzmaVarState))
-+ return LZMA_RESULT_NOT_ENOUGH_MEM;
-+ vs->Dictionary = dictionary;
-+ vs->DictionarySize = dictionarySize;
-+ vs->DictionaryPos = 0;
-+ vs->GlobalPos = 0;
-+ vs->Reps[0] = vs->Reps[1] = vs->Reps[2] = vs->Reps[3] = 1;
-+ vs->lc = lc;
-+ vs->lp = lp;
-+ vs->pb = pb;
-+ vs->State = 0;
-+ vs->PreviousIsMatch = 0;
-+ vs->RemainLen = 0;
-+ dictionary[dictionarySize - 1] = 0;
-+ for (i = 0; i < numProbs; i++)
-+ p[i] = kBitModelTotal >> 1;
-+ RangeDecoderInit(&vs->RangeDecoder,
-+ #ifdef _LZMA_IN_CB
-+ inCallback
-+ #else
-+ inStream, inSize
-+ #endif
-+ );
-+ return LZMA_RESULT_OK;
-+}
-+
-+int LzmaDecode(unsigned char *buffer,
-+ unsigned char *outStream, UInt32 outSize,
-+ UInt32 *outSizeProcessed)
-+{
-+ LzmaVarState *vs = (LzmaVarState *)buffer;
-+ CProb *p = (CProb *)(buffer + sizeof(LzmaVarState));
-+ CRangeDecoder rd = vs->RangeDecoder;
-+ int state = vs->State;
-+ int previousIsMatch = vs->PreviousIsMatch;
-+ Byte previousByte;
-+ UInt32 rep0 = vs->Reps[0], rep1 = vs->Reps[1], rep2 = vs->Reps[2], rep3 = vs->Reps[3];
-+ UInt32 nowPos = 0;
-+ UInt32 posStateMask = (1 << (vs->pb)) - 1;
-+ UInt32 literalPosMask = (1 << (vs->lp)) - 1;
-+ int lc = vs->lc;
-+ int len = vs->RemainLen;
-+ UInt32 globalPos = vs->GlobalPos;
-+
-+ Byte *dictionary = vs->Dictionary;
-+ UInt32 dictionarySize = vs->DictionarySize;
-+ UInt32 dictionaryPos = vs->DictionaryPos;
-+
-+ if (len == -1)
-+ {
-+ *outSizeProcessed = 0;
-+ return LZMA_RESULT_OK;
-+ }
-+
-+ while(len > 0 && nowPos < outSize)
-+ {
-+ UInt32 pos = dictionaryPos - rep0;
-+ if (pos >= dictionarySize)
-+ pos += dictionarySize;
-+ outStream[nowPos++] = dictionary[dictionaryPos] = dictionary[pos];
-+ if (++dictionaryPos == dictionarySize)
-+ dictionaryPos = 0;
-+ len--;
-+ }
-+ if (dictionaryPos == 0)
-+ previousByte = dictionary[dictionarySize - 1];
-+ else
-+ previousByte = dictionary[dictionaryPos - 1];
-+#else
-+
-+int LzmaDecode(
-+ Byte *buffer, UInt32 bufferSize,
-+ int lc, int lp, int pb,
-+ #ifdef _LZMA_IN_CB
-+ ILzmaInCallback *inCallback,
-+ #else
-+ unsigned char *inStream, UInt32 inSize,
-+ #endif
-+ unsigned char *outStream, UInt32 outSize,
-+ UInt32 *outSizeProcessed)
-+{
-+ UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + lp));
-+ CProb *p = (CProb *)buffer;
-+ CRangeDecoder rd;
-+ UInt32 i;
-+ int state = 0;
-+ int previousIsMatch = 0;
-+ Byte previousByte = 0;
-+ UInt32 rep0 = 1, rep1 = 1, rep2 = 1, rep3 = 1;
-+ UInt32 nowPos = 0;
-+ UInt32 posStateMask = (1 << pb) - 1;
-+ UInt32 literalPosMask = (1 << lp) - 1;
-+ int len = 0;
-+ if (bufferSize < numProbs * sizeof(CProb))
-+ return LZMA_RESULT_NOT_ENOUGH_MEM;
-+ for (i = 0; i < numProbs; i++)
-+ p[i] = kBitModelTotal >> 1;
-+ RangeDecoderInit(&rd,
-+ #ifdef _LZMA_IN_CB
-+ inCallback
-+ #else
-+ inStream, inSize
-+ #endif
-+ );
-+#endif
-+
-+ *outSizeProcessed = 0;
-+ while(nowPos < outSize)
-+ {
-+ int posState = (int)(
-+ (nowPos
-+ #ifdef _LZMA_OUT_READ
-+ + globalPos
-+ #endif
-+ )
-+ & posStateMask);
-+ #ifdef _LZMA_IN_CB
-+ if (rd.Result != LZMA_RESULT_OK)
-+ return rd.Result;
-+ #endif
-+ if (rd.ExtraBytes != 0)
-+ return LZMA_RESULT_DATA_ERROR;
-+ if (RangeDecoderBitDecode(p + IsMatch + (state << kNumPosBitsMax) + posState, &rd) == 0)
-+ {
-+ CProb *probs = p + Literal + (LZMA_LIT_SIZE *
-+ (((
-+ (nowPos
-+ #ifdef _LZMA_OUT_READ
-+ + globalPos
-+ #endif
-+ )
-+ & literalPosMask) << lc) + (previousByte >> (8 - lc))));
-+
-+ if (state < 4) state = 0;
-+ else if (state < 10) state -= 3;
-+ else state -= 6;
-+ if (previousIsMatch)
-+ {
-+ Byte matchByte;
-+ #ifdef _LZMA_OUT_READ
-+ UInt32 pos = dictionaryPos - rep0;
-+ if (pos >= dictionarySize)
-+ pos += dictionarySize;
-+ matchByte = dictionary[pos];
-+ #else
-+ matchByte = outStream[nowPos - rep0];
-+ #endif
-+ previousByte = LzmaLiteralDecodeMatch(probs, &rd, matchByte);
-+ previousIsMatch = 0;
-+ }
-+ else
-+ previousByte = LzmaLiteralDecode(probs, &rd);
-+ outStream[nowPos++] = previousByte;
-+ #ifdef _LZMA_OUT_READ
-+ dictionary[dictionaryPos] = previousByte;
-+ if (++dictionaryPos == dictionarySize)
-+ dictionaryPos = 0;
-+ #endif
-+ }
-+ else
-+ {
-+ previousIsMatch = 1;
-+ if (RangeDecoderBitDecode(p + IsRep + state, &rd) == 1)
-+ {
-+ if (RangeDecoderBitDecode(p + IsRepG0 + state, &rd) == 0)
-+ {
-+ if (RangeDecoderBitDecode(p + IsRep0Long + (state << kNumPosBitsMax) + posState, &rd) == 0)
-+ {
-+ #ifdef _LZMA_OUT_READ
-+ UInt32 pos;
-+ #endif
-+ if (
-+ (nowPos
-+ #ifdef _LZMA_OUT_READ
-+ + globalPos
-+ #endif
-+ )
-+ == 0)
-+ return LZMA_RESULT_DATA_ERROR;
-+ state = state < 7 ? 9 : 11;
-+ #ifdef _LZMA_OUT_READ
-+ pos = dictionaryPos - rep0;
-+ if (pos >= dictionarySize)
-+ pos += dictionarySize;
-+ previousByte = dictionary[pos];
-+ dictionary[dictionaryPos] = previousByte;
-+ if (++dictionaryPos == dictionarySize)
-+ dictionaryPos = 0;
-+ #else
-+ previousByte = outStream[nowPos - rep0];
-+ #endif
-+ outStream[nowPos++] = previousByte;
-+ continue;
-+ }
-+ }
-+ else
-+ {
-+ UInt32 distance;
-+ if(RangeDecoderBitDecode(p + IsRepG1 + state, &rd) == 0)
-+ distance = rep1;
-+ else
-+ {
-+ if(RangeDecoderBitDecode(p + IsRepG2 + state, &rd) == 0)
-+ distance = rep2;
-+ else
-+ {
-+ distance = rep3;
-+ rep3 = rep2;
-+ }
-+ rep2 = rep1;
-+ }
-+ rep1 = rep0;
-+ rep0 = distance;
-+ }
-+ len = LzmaLenDecode(p + RepLenCoder, &rd, posState);
-+ state = state < 7 ? 8 : 11;
-+ }
-+ else
-+ {
-+ int posSlot;
-+ rep3 = rep2;
-+ rep2 = rep1;
-+ rep1 = rep0;
-+ state = state < 7 ? 7 : 10;
-+ len = LzmaLenDecode(p + LenCoder, &rd, posState);
-+ posSlot = RangeDecoderBitTreeDecode(p + PosSlot +
-+ ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) <<
-+ kNumPosSlotBits), kNumPosSlotBits, &rd);
-+ if (posSlot >= kStartPosModelIndex)
-+ {
-+ int numDirectBits = ((posSlot >> 1) - 1);
-+ rep0 = ((2 | ((UInt32)posSlot & 1)) << numDirectBits);
-+ if (posSlot < kEndPosModelIndex)
-+ {
-+ rep0 += RangeDecoderReverseBitTreeDecode(
-+ p + SpecPos + rep0 - posSlot - 1, numDirectBits, &rd);
-+ }
-+ else
-+ {
-+ rep0 += RangeDecoderDecodeDirectBits(&rd,
-+ numDirectBits - kNumAlignBits) << kNumAlignBits;
-+ rep0 += RangeDecoderReverseBitTreeDecode(p + Align, kNumAlignBits, &rd);
-+ }
-+ }
-+ else
-+ rep0 = posSlot;
-+ rep0++;
-+ }
-+ if (rep0 == (UInt32)(0))
-+ {
-+ /* it's for stream version */
-+ len = -1;
-+ break;
-+ }
-+ if (rep0 > nowPos
-+ #ifdef _LZMA_OUT_READ
-+ + globalPos
-+ #endif
-+ )
-+ {
-+ return LZMA_RESULT_DATA_ERROR;
-+ }
-+ len += kMatchMinLen;
-+ do
-+ {
-+ #ifdef _LZMA_OUT_READ
-+ UInt32 pos = dictionaryPos - rep0;
-+ if (pos >= dictionarySize)
-+ pos += dictionarySize;
-+ previousByte = dictionary[pos];
-+ dictionary[dictionaryPos] = previousByte;
-+ if (++dictionaryPos == dictionarySize)
-+ dictionaryPos = 0;
-+ #else
-+ previousByte = outStream[nowPos - rep0];
-+ #endif
-+ outStream[nowPos++] = previousByte;
-+ len--;
-+ }
-+ while(len > 0 && nowPos < outSize);
-+ }
-+ }
-+
-+ #ifdef _LZMA_OUT_READ
-+ vs->RangeDecoder = rd;
-+ vs->DictionaryPos = dictionaryPos;
-+ vs->GlobalPos = globalPos + nowPos;
-+ vs->Reps[0] = rep0;
-+ vs->Reps[1] = rep1;
-+ vs->Reps[2] = rep2;
-+ vs->Reps[3] = rep3;
-+ vs->State = state;
-+ vs->PreviousIsMatch = previousIsMatch;
-+ vs->RemainLen = len;
-+ #endif
-+
-+ *outSizeProcessed = nowPos;
-+ return LZMA_RESULT_OK;
-+}
-Index: linux-2.6.21.7/lib/Makefile
-===================================================================
---- linux-2.6.21.7.orig/lib/Makefile
-+++ linux-2.6.21.7/lib/Makefile
-@@ -12,7 +12,7 @@ lib-$(CONFIG_SMP) += cpumask.o
-
- lib-y += kobject.o kref.o kobject_uevent.o klist.o
-
--obj-y += sort.o parser.o halfmd4.o debug_locks.o random32.o bust_spinlocks.o
-+obj-y += sort.o parser.o halfmd4.o debug_locks.o random32.o bust_spinlocks.o LzmaDecode.o
-
- ifeq ($(CONFIG_DEBUG_KOBJECT),y)
- CFLAGS_kobject.o += -DDEBUG
-@@ -56,6 +56,7 @@ obj-$(CONFIG_SMP) += percpu_counter.o
- obj-$(CONFIG_AUDIT_GENERIC) += audit.o
-
- obj-$(CONFIG_SWIOTLB) += swiotlb.o
-+
- obj-$(CONFIG_FAULT_INJECTION) += fault-inject.o
-
- lib-$(CONFIG_GENERIC_BUG) += bug.o
+++ /dev/null
-Index: linux-2.6.21.7/fs/squashfs/inode.c
-===================================================================
---- linux-2.6.21.7.orig/fs/squashfs/inode.c
-+++ linux-2.6.21.7/fs/squashfs/inode.c
-@@ -4,6 +4,9 @@
- * Copyright (c) 2002, 2003, 2004, 2005, 2006
- * Phillip Lougher <phillip@lougher.org.uk>
- *
-+ * LZMA decompressor support added by Oleg I. Vdovikin
-+ * Copyright (c) 2005 Oleg I.Vdovikin <oleg@cs.msu.su>
-+ *
- * 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,
-@@ -21,6 +24,7 @@
- * inode.c
- */
-
-+#define SQUASHFS_LZMA
- #include <linux/types.h>
- #include <linux/squashfs_fs.h>
- #include <linux/module.h>
-@@ -44,6 +48,19 @@
-
- #include "squashfs.h"
-
-+#ifdef SQUASHFS_LZMA
-+#include <linux/LzmaDecode.h>
-+
-+/* default LZMA settings, should be in sync with mksquashfs */
-+#define LZMA_LC 3
-+#define LZMA_LP 0
-+#define LZMA_PB 2
-+
-+#define LZMA_WORKSPACE_SIZE ((LZMA_BASE_SIZE + \
-+ (LZMA_LIT_SIZE << (LZMA_LC + LZMA_LP))) * sizeof(CProb))
-+
-+#endif
-+
- static void squashfs_put_super(struct super_block *);
- static int squashfs_statfs(struct dentry *, struct kstatfs *);
- static int squashfs_symlink_readpage(struct file *file, struct page *page);
-@@ -64,7 +81,11 @@ static int squashfs_get_sb(struct file_s
- const char *, void *, struct vfsmount *);
-
-
-+#ifdef SQUASHFS_LZMA
-+static unsigned char lzma_workspace[LZMA_WORKSPACE_SIZE];
-+#else
- static z_stream stream;
-+#endif
-
- static struct file_system_type squashfs_fs_type = {
- .owner = THIS_MODULE,
-@@ -249,6 +270,15 @@ SQSH_EXTERN unsigned int squashfs_read_d
- if (compressed) {
- int zlib_err;
-
-+#ifdef SQUASHFS_LZMA
-+ if ((zlib_err = LzmaDecode(lzma_workspace,
-+ LZMA_WORKSPACE_SIZE, LZMA_LC, LZMA_LP, LZMA_PB,
-+ c_buffer, c_byte, buffer, msblk->read_size, &bytes)) != LZMA_RESULT_OK)
-+ {
-+ ERROR("lzma returned unexpected result 0x%x\n", zlib_err);
-+ bytes = 0;
-+ }
-+#else
- stream.next_in = c_buffer;
- stream.avail_in = c_byte;
- stream.next_out = buffer;
-@@ -263,7 +293,7 @@ SQSH_EXTERN unsigned int squashfs_read_d
- bytes = 0;
- } else
- bytes = stream.total_out;
--
-+#endif
- up(&msblk->read_data_mutex);
- }
-
-@@ -2045,15 +2075,19 @@ static int __init init_squashfs_fs(void)
- printk(KERN_INFO "squashfs: version 3.0 (2006/03/15) "
- "Phillip Lougher\n");
-
-+#ifndef SQUASHFS_LZMA
- if (!(stream.workspace = vmalloc(zlib_inflate_workspacesize()))) {
- ERROR("Failed to allocate zlib workspace\n");
- destroy_inodecache();
- err = -ENOMEM;
- goto out;
- }
-+#endif
-
- if ((err = register_filesystem(&squashfs_fs_type))) {
-+#ifndef SQUASHFS_LZMA
- vfree(stream.workspace);
-+#endif
- destroy_inodecache();
- }
-
-@@ -2064,7 +2098,9 @@ out:
-
- static void __exit exit_squashfs_fs(void)
- {
-+#ifndef SQUASHFS_LZMA
- vfree(stream.workspace);
-+#endif
- unregister_filesystem(&squashfs_fs_type);
- destroy_inodecache();
- }
+++ /dev/null
-Index: linux-2.6.21.7/Makefile
-===================================================================
---- linux-2.6.21.7.orig/Makefile
-+++ linux-2.6.21.7/Makefile
-@@ -507,6 +507,9 @@ CFLAGS += $(call cc-option, -fn
- NOSTDINC_FLAGS += -nostdinc -isystem $(shell $(CC) -print-file-name=include)
- CHECKFLAGS += $(NOSTDINC_FLAGS)
-
-+# improve gcc optimization
-+CFLAGS += $(call cc-option,-funit-at-a-time,)
-+
- # warn about C99 declaration after statement
- CFLAGS += $(call cc-option,-Wdeclaration-after-statement,)
-
+++ /dev/null
-Index: linux-2.6.21.7/include/asm-mips/system.h
-===================================================================
---- linux-2.6.21.7.orig/include/asm-mips/system.h
-+++ linux-2.6.21.7/include/asm-mips/system.h
-@@ -188,7 +188,7 @@ extern __u64 __xchg_u64_unsupported_on_3
- if something tries to do an invalid xchg(). */
- extern void __xchg_called_with_bad_pointer(void);
-
--static inline unsigned long __xchg(unsigned long x, volatile void * ptr, int size)
-+static __always_inline unsigned long __xchg(unsigned long x, volatile void * ptr, int size)
- {
- switch (size) {
- case 4:
+++ /dev/null
-Index: linux-2.6.21.7/drivers/mtd/chips/cfi_cmdset_0002.c
-===================================================================
---- linux-2.6.21.7.orig/drivers/mtd/chips/cfi_cmdset_0002.c
-+++ linux-2.6.21.7/drivers/mtd/chips/cfi_cmdset_0002.c
-@@ -51,6 +51,7 @@
- #define SST49LF040B 0x0050
- #define SST49LF008A 0x005a
- #define AT49BV6416 0x00d6
-+#define MANUFACTURER_SAMSUNG 0x00ec
-
- static int cfi_amdstd_read (struct mtd_info *, loff_t, size_t, size_t *, u_char *);
- static int cfi_amdstd_write_words(struct mtd_info *, loff_t, size_t, size_t *, const u_char *);
-@@ -294,12 +295,19 @@ struct mtd_info *cfi_cmdset_0002(struct
-
- if (extp->MajorVersion != '1' ||
- (extp->MinorVersion < '0' || extp->MinorVersion > '4')) {
-- printk(KERN_ERR " Unknown Amd/Fujitsu Extended Query "
-- "version %c.%c.\n", extp->MajorVersion,
-- extp->MinorVersion);
-- kfree(extp);
-- kfree(mtd);
-- return NULL;
-+ if (cfi->mfr == MANUFACTURER_SAMSUNG &&
-+ (extp->MajorVersion == '3' && extp->MinorVersion == '3')) {
-+ printk(KERN_NOTICE " Newer Samsung flash detected, "
-+ "should be compatibile with Amd/Fujitsu.\n");
-+ }
-+ else {
-+ printk(KERN_ERR " Unknown Amd/Fujitsu Extended Query "
-+ "version %c.%c.\n", extp->MajorVersion,
-+ extp->MinorVersion);
-+ kfree(extp);
-+ kfree(mtd);
-+ return NULL;
-+ }
- }
-
- /* Install our own private info structure */
+++ /dev/null
-Index: linux-2.6.21.7/drivers/mtd/chips/cfi_cmdset_0001.c
-===================================================================
---- linux-2.6.21.7.orig/drivers/mtd/chips/cfi_cmdset_0001.c
-+++ linux-2.6.21.7/drivers/mtd/chips/cfi_cmdset_0001.c
-@@ -919,7 +919,7 @@ static void __xipram xip_enable(struct m
-
- static int __xipram xip_wait_for_operation(
- struct map_info *map, struct flchip *chip,
-- unsigned long adr, unsigned int chip_op_time )
-+ unsigned long adr, int *chip_op_time )
- {
- struct cfi_private *cfi = map->fldrv_priv;
- struct cfi_pri_intelext *cfip = cfi->cmdset_priv;
-@@ -928,7 +928,7 @@ static int __xipram xip_wait_for_operati
- flstate_t oldstate, newstate;
-
- start = xip_currtime();
-- usec = chip_op_time * 8;
-+ usec = *chip_op_time * 8;
- if (usec == 0)
- usec = 500000;
- done = 0;
-@@ -1038,8 +1038,8 @@ static int __xipram xip_wait_for_operati
- #define XIP_INVAL_CACHED_RANGE(map, from, size) \
- INVALIDATE_CACHED_RANGE(map, from, size)
-
--#define INVAL_CACHE_AND_WAIT(map, chip, cmd_adr, inval_adr, inval_len, usec) \
-- xip_wait_for_operation(map, chip, cmd_adr, usec)
-+#define INVAL_CACHE_AND_WAIT(map, chip, cmd_adr, inval_adr, inval_len, p_usec) \
-+ xip_wait_for_operation(map, chip, cmd_adr, p_usec)
-
- #else
-
-@@ -1051,65 +1051,65 @@ static int __xipram xip_wait_for_operati
- static int inval_cache_and_wait_for_operation(
- struct map_info *map, struct flchip *chip,
- unsigned long cmd_adr, unsigned long inval_adr, int inval_len,
-- unsigned int chip_op_time)
-+ int *chip_op_time )
- {
- struct cfi_private *cfi = map->fldrv_priv;
- map_word status, status_OK = CMD(0x80);
-- int chip_state = chip->state;
-- unsigned int timeo, sleep_time;
-+ int z, chip_state = chip->state;
-+ unsigned long timeo;
-
- spin_unlock(chip->mutex);
- if (inval_len)
- INVALIDATE_CACHED_RANGE(map, inval_adr, inval_len);
-+ if (*chip_op_time)
-+ cfi_udelay(*chip_op_time);
- spin_lock(chip->mutex);
-
-- /* set our timeout to 8 times the expected delay */
-- timeo = chip_op_time * 8;
-- if (!timeo)
-- timeo = 500000;
-- sleep_time = chip_op_time / 2;
-+ timeo = *chip_op_time * 8 * HZ / 1000000;
-+ if (timeo < HZ/2)
-+ timeo = HZ/2;
-+ timeo += jiffies;
-
-+ z = 0;
- for (;;) {
-+ if (chip->state != chip_state) {
-+ /* Someone's suspended the operation: sleep */
-+ DECLARE_WAITQUEUE(wait, current);
-+
-+ set_current_state(TASK_UNINTERRUPTIBLE);
-+ add_wait_queue(&chip->wq, &wait);
-+ spin_unlock(chip->mutex);
-+ schedule();
-+ remove_wait_queue(&chip->wq, &wait);
-+ timeo = jiffies + (HZ / 2); /* FIXME */
-+ spin_lock(chip->mutex);
-+ continue;
-+ }
-+
- status = map_read(map, cmd_adr);
- if (map_word_andequal(map, status, status_OK, status_OK))
- break;
-
-- if (!timeo) {
-+ /* OK Still waiting */
-+ if (time_after(jiffies, timeo)) {
- map_write(map, CMD(0x70), cmd_adr);
- chip->state = FL_STATUS;
- return -ETIME;
- }
-
-- /* OK Still waiting. Drop the lock, wait a while and retry. */
-+ /* Latency issues. Drop the lock, wait a while and retry */
-+ z++;
- spin_unlock(chip->mutex);
-- if (sleep_time >= 1000000/HZ) {
-- /*
-- * Half of the normal delay still remaining
-- * can be performed with a sleeping delay instead
-- * of busy waiting.
-- */
-- msleep(sleep_time/1000);
-- timeo -= sleep_time;
-- sleep_time = 1000000/HZ;
-- } else {
-- udelay(1);
-- cond_resched();
-- timeo--;
-- }
-+ cfi_udelay(1);
- spin_lock(chip->mutex);
--
-- while (chip->state != chip_state) {
-- /* Someone's suspended the operation: sleep */
-- DECLARE_WAITQUEUE(wait, current);
-- set_current_state(TASK_UNINTERRUPTIBLE);
-- add_wait_queue(&chip->wq, &wait);
-- spin_unlock(chip->mutex);
-- schedule();
-- remove_wait_queue(&chip->wq, &wait);
-- spin_lock(chip->mutex);
-- }
- }
-
-+ if (!z) {
-+ if (!--(*chip_op_time))
-+ *chip_op_time = 1;
-+ } else if (z > 1)
-+ ++(*chip_op_time);
-+
- /* Done and happy. */
- chip->state = FL_STATUS;
- return 0;
-@@ -1118,7 +1118,8 @@ static int inval_cache_and_wait_for_oper
- #endif
-
- #define WAIT_TIMEOUT(map, chip, adr, udelay) \
-- INVAL_CACHE_AND_WAIT(map, chip, adr, 0, 0, udelay);
-+ ({ int __udelay = (udelay); \
-+ INVAL_CACHE_AND_WAIT(map, chip, adr, 0, 0, &__udelay); })
-
-
- static int do_point_onechip (struct map_info *map, struct flchip *chip, loff_t adr, size_t len)
-@@ -1342,7 +1343,7 @@ static int __xipram do_write_oneword(str
-
- ret = INVAL_CACHE_AND_WAIT(map, chip, adr,
- adr, map_bankwidth(map),
-- chip->word_write_time);
-+ &chip->word_write_time);
- if (ret) {
- xip_enable(map, chip, adr);
- printk(KERN_ERR "%s: word write error (status timeout)\n", map->name);
-@@ -1579,7 +1580,7 @@ static int __xipram do_write_buffer(stru
-
- ret = INVAL_CACHE_AND_WAIT(map, chip, cmd_adr,
- adr, len,
-- chip->buffer_write_time);
-+ &chip->buffer_write_time);
- if (ret) {
- map_write(map, CMD(0x70), cmd_adr);
- chip->state = FL_STATUS;
-@@ -1714,7 +1715,7 @@ static int __xipram do_erase_oneblock(st
-
- ret = INVAL_CACHE_AND_WAIT(map, chip, adr,
- adr, len,
-- chip->erase_time);
-+ &chip->erase_time);
- if (ret) {
- map_write(map, CMD(0x70), adr);
- chip->state = FL_STATUS;
+++ /dev/null
-Index: linux-2.6.21.7/fs/squashfs/Makefile
-===================================================================
---- linux-2.6.21.7.orig/fs/squashfs/Makefile
-+++ linux-2.6.21.7/fs/squashfs/Makefile
-@@ -4,4 +4,3 @@
-
- obj-$(CONFIG_SQUASHFS) += squashfs.o
- squashfs-y += inode.o
--squashfs-y += squashfs2_0.o
-Index: linux-2.6.21.7/fs/squashfs/squashfs.h
-===================================================================
---- linux-2.6.21.7.orig/fs/squashfs/squashfs.h
-+++ linux-2.6.21.7/fs/squashfs/squashfs.h
-@@ -24,6 +24,9 @@
- #ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY
- #undef CONFIG_SQUASHFS_1_0_COMPATIBILITY
- #endif
-+#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY
-+#undef CONFIG_SQUASHFS_2_0_COMPATIBILITY
-+#endif
-
- #ifdef SQUASHFS_TRACE
- #define TRACE(s, args...) printk(KERN_NOTICE "SQUASHFS: "s, ## args)
+++ /dev/null
-Index: linux-2.6.21.7/arch/mips/kernel/head.S
-===================================================================
---- linux-2.6.21.7.orig/arch/mips/kernel/head.S
-+++ linux-2.6.21.7/arch/mips/kernel/head.S
-@@ -129,11 +129,15 @@
- #endif
- .endm
-
-+
-+ j kernel_entry
-+ nop
-+
- /*
- * Reserved space for exception handlers.
- * Necessary for machines which link their kernels at KSEG0.
- */
-- .fill 0x400
-+ .align 10
-
- EXPORT(stext) # used for profiling
- EXPORT(_stext)
+++ /dev/null
-Index: linux-2.6.21.7/arch/mips/mm/tlbex.c
-===================================================================
---- linux-2.6.21.7.orig/arch/mips/mm/tlbex.c
-+++ linux-2.6.21.7/arch/mips/mm/tlbex.c
-@@ -887,7 +887,6 @@ static __init void build_tlb_write_entry
- case CPU_R10000:
- case CPU_R12000:
- case CPU_R14000:
-- case CPU_4KC:
- case CPU_SB1:
- case CPU_SB1A:
- case CPU_4KSC:
-@@ -915,6 +914,7 @@ static __init void build_tlb_write_entry
- tlbw(p);
- break;
-
-+ case CPU_4KC:
- case CPU_4KEC:
- case CPU_24K:
- case CPU_34K:
+++ /dev/null
-Index: linux-2.6.21.7/arch/mips/defconfig
-===================================================================
---- linux-2.6.21.7.orig/arch/mips/defconfig
-+++ linux-2.6.21.7/arch/mips/defconfig
-@@ -69,6 +69,7 @@ CONFIG_GENERIC_FIND_NEXT_BIT=y
- CONFIG_GENERIC_HWEIGHT=y
- CONFIG_GENERIC_CALIBRATE_DELAY=y
- CONFIG_GENERIC_TIME=y
-+CONFIG_GENERIC_GPIO=n
- CONFIG_SCHED_NO_NO_OMIT_FRAME_POINTER=y
- # CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ is not set
- CONFIG_ARC=y
-Index: linux-2.6.21.7/arch/mips/Kconfig
-===================================================================
---- linux-2.6.21.7.orig/arch/mips/Kconfig
-+++ linux-2.6.21.7/arch/mips/Kconfig
-@@ -869,6 +869,10 @@ config GENERIC_TIME
- bool
- default y
-
-+config GENERIC_GPIO
-+ bool
-+ default n
-+
- config SCHED_NO_NO_OMIT_FRAME_POINTER
- bool
- default y
-Index: linux-2.6.21.7/include/asm-mips/gpio.h
-===================================================================
---- /dev/null
-+++ linux-2.6.21.7/include/asm-mips/gpio.h
-@@ -0,0 +1,6 @@
-+#ifndef _ASM_MIPS_GPIO_H
-+#define _ASM_MIPS_GPIO_H
-+
-+#include <gpio.h>
-+
-+#endif /* _ASM_MIPS_GPIO_H */
+++ /dev/null
-Index: linux-2.6.21.7/drivers/mtd/Kconfig
-===================================================================
---- linux-2.6.21.7.orig/drivers/mtd/Kconfig
-+++ linux-2.6.21.7/drivers/mtd/Kconfig
-@@ -49,6 +49,16 @@ config MTD_PARTITIONS
- devices. Partitioning on NFTL 'devices' is a different - that's the
- 'normal' form of partitioning used on a block device.
-
-+config MTD_ROOTFS_ROOT_DEV
-+ bool "Automatically set 'rootfs' partition to be root filesystem"
-+ depends on MTD_PARTITIONS
-+ default y
-+
-+config MTD_ROOTFS_SPLIT
-+ bool "Automatically split 'rootfs' partition for squashfs"
-+ depends on MTD_PARTITIONS
-+ default y
-+
- config MTD_REDBOOT_PARTS
- tristate "RedBoot partition table parsing"
- depends on MTD_PARTITIONS
-Index: linux-2.6.21.7/drivers/mtd/mtdpart.c
-===================================================================
---- linux-2.6.21.7.orig/drivers/mtd/mtdpart.c
-+++ linux-2.6.21.7/drivers/mtd/mtdpart.c
-@@ -20,6 +20,8 @@
- #include <linux/mtd/mtd.h>
- #include <linux/mtd/partitions.h>
- #include <linux/mtd/compatmac.h>
-+#include <linux/squashfs_fs.h>
-+#include <linux/root_dev.h>
-
- /* Our partition linked list */
- static LIST_HEAD(mtd_partitions);
-@@ -308,6 +310,266 @@ int del_mtd_partitions(struct mtd_info *
- return 0;
- }
-
-+static u_int32_t cur_offset = 0;
-+static int add_one_partition(struct mtd_info *master, const struct mtd_partition *part,
-+ int i, struct mtd_part **slp)
-+{
-+ struct mtd_part *slave;
-+
-+ /* allocate the partition structure */
-+ slave = kzalloc (sizeof(*slave), GFP_KERNEL);
-+ if (!slave) {
-+ printk ("memory allocation error while creating partitions for \"%s\"\n",
-+ master->name);
-+ del_mtd_partitions(master);
-+ return -ENOMEM;
-+ }
-+ list_add(&slave->list, &mtd_partitions);
-+
-+ /* set up the MTD object for this partition */
-+ slave->mtd.type = master->type;
-+ slave->mtd.flags = master->flags & ~part->mask_flags;
-+ slave->mtd.size = part->size;
-+ slave->mtd.writesize = master->writesize;
-+ slave->mtd.oobsize = master->oobsize;
-+ slave->mtd.oobavail = master->oobavail;
-+ slave->mtd.subpage_sft = master->subpage_sft;
-+
-+ slave->mtd.name = part->name;
-+ slave->mtd.bank_size = master->bank_size;
-+ slave->mtd.owner = master->owner;
-+
-+ slave->mtd.read = part_read;
-+ slave->mtd.write = part_write;
-+
-+ if(master->point && master->unpoint){
-+ slave->mtd.point = part_point;
-+ slave->mtd.unpoint = part_unpoint;
-+ }
-+
-+ if (master->read_oob)
-+ slave->mtd.read_oob = part_read_oob;
-+ if (master->write_oob)
-+ slave->mtd.write_oob = part_write_oob;
-+ if(master->read_user_prot_reg)
-+ slave->mtd.read_user_prot_reg = part_read_user_prot_reg;
-+ if(master->read_fact_prot_reg)
-+ slave->mtd.read_fact_prot_reg = part_read_fact_prot_reg;
-+ if(master->write_user_prot_reg)
-+ slave->mtd.write_user_prot_reg = part_write_user_prot_reg;
-+ if(master->lock_user_prot_reg)
-+ slave->mtd.lock_user_prot_reg = part_lock_user_prot_reg;
-+ if(master->get_user_prot_info)
-+ slave->mtd.get_user_prot_info = part_get_user_prot_info;
-+ if(master->get_fact_prot_info)
-+ slave->mtd.get_fact_prot_info = part_get_fact_prot_info;
-+ if (master->sync)
-+ slave->mtd.sync = part_sync;
-+ if (!i && master->suspend && master->resume) {
-+ slave->mtd.suspend = part_suspend;
-+ slave->mtd.resume = part_resume;
-+ }
-+ if (master->writev)
-+ slave->mtd.writev = part_writev;
-+ if (master->lock)
-+ slave->mtd.lock = part_lock;
-+ if (master->unlock)
-+ slave->mtd.unlock = part_unlock;
-+ if (master->block_isbad)
-+ slave->mtd.block_isbad = part_block_isbad;
-+ if (master->block_markbad)
-+ slave->mtd.block_markbad = part_block_markbad;
-+ slave->mtd.erase = part_erase;
-+ slave->master = master;
-+ slave->offset = part->offset;
-+ slave->index = i;
-+
-+ if (slave->offset == MTDPART_OFS_APPEND)
-+ slave->offset = cur_offset;
-+ if (slave->offset == MTDPART_OFS_NXTBLK) {
-+ slave->offset = cur_offset;
-+ if ((cur_offset % master->erasesize) != 0) {
-+ /* Round up to next erasesize */
-+ slave->offset = ((cur_offset / master->erasesize) + 1) * master->erasesize;
-+ printk(KERN_NOTICE "Moving partition %d: "
-+ "0x%08x -> 0x%08x\n", i,
-+ cur_offset, slave->offset);
-+ }
-+ }
-+ if (slave->mtd.size == MTDPART_SIZ_FULL)
-+ slave->mtd.size = master->size - slave->offset;
-+ cur_offset = slave->offset + slave->mtd.size;
-+
-+ printk (KERN_NOTICE "0x%08x-0x%08x : \"%s\"\n", slave->offset,
-+ slave->offset + slave->mtd.size, slave->mtd.name);
-+
-+ /* let's do some sanity checks */
-+ if (slave->offset >= master->size) {
-+ /* let's register it anyway to preserve ordering */
-+ slave->offset = 0;
-+ slave->mtd.size = 0;
-+ printk ("mtd: partition \"%s\" is out of reach -- disabled\n",
-+ part->name);
-+ }
-+ if (slave->offset + slave->mtd.size > master->size) {
-+ slave->mtd.size = master->size - slave->offset;
-+ printk ("mtd: partition \"%s\" extends beyond the end of device \"%s\" -- size truncated to %#x\n",
-+ part->name, master->name, slave->mtd.size);
-+ }
-+ if (master->numeraseregions>1) {
-+ /* Deal with variable erase size stuff */
-+ int i;
-+ struct mtd_erase_region_info *regions = master->eraseregions;
-+
-+ /* Find the first erase regions which is part of this partition. */
-+ for (i=0; i < master->numeraseregions && slave->offset >= regions[i].offset; i++)
-+ ;
-+
-+ for (i--; i < master->numeraseregions && slave->offset + slave->mtd.size > regions[i].offset; i++) {
-+ if (slave->mtd.erasesize < regions[i].erasesize) {
-+ slave->mtd.erasesize = regions[i].erasesize;
-+ }
-+ }
-+ } else {
-+ /* Single erase size */
-+ slave->mtd.erasesize = master->erasesize;
-+ }
-+
-+ if ((slave->mtd.flags & MTD_WRITEABLE) &&
-+ (slave->offset % slave->mtd.erasesize)) {
-+ /* Doesn't start on a boundary of major erase size */
-+ /* FIXME: Let it be writable if it is on a boundary of _minor_ erase size though */
-+ slave->mtd.flags &= ~MTD_WRITEABLE;
-+ printk ("mtd: partition \"%s\" doesn't start on an erase block boundary -- force read-only\n",
-+ part->name);
-+ }
-+ if ((slave->mtd.flags & MTD_WRITEABLE) &&
-+ (slave->mtd.size % slave->mtd.erasesize)) {
-+ slave->mtd.flags &= ~MTD_WRITEABLE;
-+ printk ("mtd: partition \"%s\" doesn't end on an erase block -- force read-only\n",
-+ part->name);
-+ }
-+
-+ slave->mtd.ecclayout = master->ecclayout;
-+ if (master->block_isbad) {
-+ uint32_t offs = 0;
-+
-+ while(offs < slave->mtd.size) {
-+ if (master->block_isbad(master,
-+ offs + slave->offset))
-+ slave->mtd.ecc_stats.badblocks++;
-+ offs += slave->mtd.erasesize;
-+ }
-+ }
-+
-+ if(part->mtdp)
-+ { /* store the object pointer (caller may or may not register it */
-+ *part->mtdp = &slave->mtd;
-+ slave->registered = 0;
-+ }
-+ else
-+ {
-+ /* register our partition */
-+ add_mtd_device(&slave->mtd);
-+ slave->registered = 1;
-+ }
-+
-+ if (slp)
-+ *slp = slave;
-+
-+ return 0;
-+}
-+
-+#ifdef CONFIG_MTD_ROOTFS_SPLIT
-+#define ROOTFS_SPLIT_NAME "rootfs_data"
-+static int split_squashfs(struct mtd_info *master, struct mtd_partition *old,
-+ struct mtd_partition **new)
-+{
-+ struct mtd_partition *part = NULL;
-+ int len;
-+ char buf[512];
-+ struct squashfs_super_block *sb = (struct squashfs_super_block *) buf;
-+ int ret;
-+
-+ ret = master->read(master, old->offset, sizeof(*sb), &len, buf);
-+ if (ret) {
-+ printk(KERN_ALERT "split_squashfs: error occured while reading "
-+ "from \"%s\"\n", master->name);
-+ goto out;
-+ }
-+
-+ if (len != sizeof(*sb)) {
-+ printk(KERN_ALERT "split_squashfs: unable to read superblock "
-+ "from \"%s\"\n", master->name);
-+ ret=-1;
-+ goto out;
-+ }
-+
-+ if (*((u32 *) buf) != SQUASHFS_MAGIC) {
-+ printk(KERN_ALERT "split_squasfs: no squashfs found in \"%s\"\n",
-+ master->name);
-+ ret=0;
-+ goto out;
-+ }
-+
-+ if (sb->bytes_used <= 0) {
-+ printk(KERN_ALERT "split_squashfs: squashfs is empty in \"%s\"\n",
-+ master->name);
-+ ret=0;
-+ goto out;
-+ }
-+
-+ part = kmalloc(sizeof(*part)+sizeof(ROOTFS_SPLIT_NAME)+1, GFP_KERNEL);
-+ if (part == NULL) {
-+ printk(KERN_INFO "split_squashfs: no memory for partition \"%s\"\n",
-+ ROOTFS_SPLIT_NAME);
-+ ret = -ENOMEM;
-+ goto out;
-+ }
-+
-+ memcpy(part, old, sizeof(*part));
-+ part->name = (unsigned char *)&part[1];
-+ strcpy(part->name, ROOTFS_SPLIT_NAME);
-+
-+ len = (u32) sb->bytes_used;
-+ len += (part->offset & 0x000fffff);
-+ len += (master->erasesize - 1);
-+ len &= ~(master->erasesize - 1);
-+ len -= (part->offset & 0x000fffff);
-+ part->offset += len;
-+ part->size -= len;
-+
-+ ret = 0;
-+
-+out:
-+ *new = part;
-+ return ret;
-+}
-+
-+static int split_rootfs_data(struct mtd_info *master, struct mtd_partition *part,
-+ int index)
-+{
-+ struct mtd_partition *dpart;
-+ int ret;
-+
-+ ret = split_squashfs(master, part, &dpart);
-+ if (ret)
-+ return ret;
-+
-+ if (dpart == NULL)
-+ return 1;
-+
-+ printk(KERN_INFO "mtd: partition \"%s\" created automatically, ofs=%X, len=%X \n",
-+ ROOTFS_SPLIT_NAME, dpart->offset, dpart->size);
-+
-+ ret = add_one_partition(master, dpart, index, NULL);
-+ if (ret)
-+ kfree(dpart);
-+
-+ return ret;
-+}
-+#endif /* CONFIG_MTD_ROOTFS_SPLIT */
-+
- /*
- * This function, given a master MTD object and a partition table, creates
- * and registers slave MTD objects which are bound to the master according to
-@@ -320,169 +582,31 @@ int add_mtd_partitions(struct mtd_info *
- int nbparts)
- {
- struct mtd_part *slave;
-- u_int32_t cur_offset = 0;
-- int i;
-+ struct mtd_partition *part;
-+ int i, j, ret = 0;
-
- printk (KERN_NOTICE "Creating %d MTD partitions on \"%s\":\n", nbparts, master->name);
-
-- for (i = 0; i < nbparts; i++) {
--
-- /* allocate the partition structure */
-- slave = kzalloc (sizeof(*slave), GFP_KERNEL);
-- if (!slave) {
-- printk ("memory allocation error while creating partitions for \"%s\"\n",
-- master->name);
-- del_mtd_partitions(master);
-- return -ENOMEM;
-- }
-- list_add(&slave->list, &mtd_partitions);
--
-- /* set up the MTD object for this partition */
-- slave->mtd.type = master->type;
-- slave->mtd.flags = master->flags & ~parts[i].mask_flags;
-- slave->mtd.size = parts[i].size;
-- slave->mtd.writesize = master->writesize;
-- slave->mtd.oobsize = master->oobsize;
-- slave->mtd.oobavail = master->oobavail;
-- slave->mtd.subpage_sft = master->subpage_sft;
--
-- slave->mtd.name = parts[i].name;
-- slave->mtd.bank_size = master->bank_size;
-- slave->mtd.owner = master->owner;
--
-- slave->mtd.read = part_read;
-- slave->mtd.write = part_write;
--
-- if(master->point && master->unpoint){
-- slave->mtd.point = part_point;
-- slave->mtd.unpoint = part_unpoint;
-- }
--
-- if (master->read_oob)
-- slave->mtd.read_oob = part_read_oob;
-- if (master->write_oob)
-- slave->mtd.write_oob = part_write_oob;
-- if(master->read_user_prot_reg)
-- slave->mtd.read_user_prot_reg = part_read_user_prot_reg;
-- if(master->read_fact_prot_reg)
-- slave->mtd.read_fact_prot_reg = part_read_fact_prot_reg;
-- if(master->write_user_prot_reg)
-- slave->mtd.write_user_prot_reg = part_write_user_prot_reg;
-- if(master->lock_user_prot_reg)
-- slave->mtd.lock_user_prot_reg = part_lock_user_prot_reg;
-- if(master->get_user_prot_info)
-- slave->mtd.get_user_prot_info = part_get_user_prot_info;
-- if(master->get_fact_prot_info)
-- slave->mtd.get_fact_prot_info = part_get_fact_prot_info;
-- if (master->sync)
-- slave->mtd.sync = part_sync;
-- if (!i && master->suspend && master->resume) {
-- slave->mtd.suspend = part_suspend;
-- slave->mtd.resume = part_resume;
-- }
-- if (master->writev)
-- slave->mtd.writev = part_writev;
-- if (master->lock)
-- slave->mtd.lock = part_lock;
-- if (master->unlock)
-- slave->mtd.unlock = part_unlock;
-- if (master->block_isbad)
-- slave->mtd.block_isbad = part_block_isbad;
-- if (master->block_markbad)
-- slave->mtd.block_markbad = part_block_markbad;
-- slave->mtd.erase = part_erase;
-- slave->master = master;
-- slave->offset = parts[i].offset;
-- slave->index = i;
--
-- if (slave->offset == MTDPART_OFS_APPEND)
-- slave->offset = cur_offset;
-- if (slave->offset == MTDPART_OFS_NXTBLK) {
-- slave->offset = cur_offset;
-- if ((cur_offset % master->erasesize) != 0) {
-- /* Round up to next erasesize */
-- slave->offset = ((cur_offset / master->erasesize) + 1) * master->erasesize;
-- printk(KERN_NOTICE "Moving partition %d: "
-- "0x%08x -> 0x%08x\n", i,
-- cur_offset, slave->offset);
-- }
-- }
-- if (slave->mtd.size == MTDPART_SIZ_FULL)
-- slave->mtd.size = master->size - slave->offset;
-- cur_offset = slave->offset + slave->mtd.size;
--
-- printk (KERN_NOTICE "0x%08x-0x%08x : \"%s\"\n", slave->offset,
-- slave->offset + slave->mtd.size, slave->mtd.name);
--
-- /* let's do some sanity checks */
-- if (slave->offset >= master->size) {
-- /* let's register it anyway to preserve ordering */
-- slave->offset = 0;
-- slave->mtd.size = 0;
-- printk ("mtd: partition \"%s\" is out of reach -- disabled\n",
-- parts[i].name);
-- }
-- if (slave->offset + slave->mtd.size > master->size) {
-- slave->mtd.size = master->size - slave->offset;
-- printk ("mtd: partition \"%s\" extends beyond the end of device \"%s\" -- size truncated to %#x\n",
-- parts[i].name, master->name, slave->mtd.size);
-- }
-- if (master->numeraseregions>1) {
-- /* Deal with variable erase size stuff */
-- int i;
-- struct mtd_erase_region_info *regions = master->eraseregions;
--
-- /* Find the first erase regions which is part of this partition. */
-- for (i=0; i < master->numeraseregions && slave->offset >= regions[i].offset; i++)
-- ;
--
-- for (i--; i < master->numeraseregions && slave->offset + slave->mtd.size > regions[i].offset; i++) {
-- if (slave->mtd.erasesize < regions[i].erasesize) {
-- slave->mtd.erasesize = regions[i].erasesize;
-- }
-- }
-- } else {
-- /* Single erase size */
-- slave->mtd.erasesize = master->erasesize;
-- }
--
-- if ((slave->mtd.flags & MTD_WRITEABLE) &&
-- (slave->offset % slave->mtd.erasesize)) {
-- /* Doesn't start on a boundary of major erase size */
-- /* FIXME: Let it be writable if it is on a boundary of _minor_ erase size though */
-- slave->mtd.flags &= ~MTD_WRITEABLE;
-- printk ("mtd: partition \"%s\" doesn't start on an erase block boundary -- force read-only\n",
-- parts[i].name);
-- }
-- if ((slave->mtd.flags & MTD_WRITEABLE) &&
-- (slave->mtd.size % slave->mtd.erasesize)) {
-- slave->mtd.flags &= ~MTD_WRITEABLE;
-- printk ("mtd: partition \"%s\" doesn't end on an erase block -- force read-only\n",
-- parts[i].name);
-- }
--
-- slave->mtd.ecclayout = master->ecclayout;
-- if (master->block_isbad) {
-- uint32_t offs = 0;
--
-- while(offs < slave->mtd.size) {
-- if (master->block_isbad(master,
-- offs + slave->offset))
-- slave->mtd.ecc_stats.badblocks++;
-- offs += slave->mtd.erasesize;
-+ for (i = 0, j = 0; i < nbparts; i++) {
-+ part = (struct mtd_partition *) &parts[i];
-+ ret = add_one_partition(master, part, j, &slave);
-+ if (ret)
-+ return ret;
-+ j++;
-+
-+ if (strcmp(part->name, "rootfs") == 0 && slave->registered) {
-+#ifdef CONFIG_MTD_ROOTFS_ROOT_DEV
-+ if (ROOT_DEV == 0) {
-+ printk(KERN_NOTICE "mtd: partition \"rootfs\" "
-+ "set to be root filesystem\n");
-+ ROOT_DEV = MKDEV(MTD_BLOCK_MAJOR, slave->mtd.index);
- }
-- }
--
-- if(parts[i].mtdp)
-- { /* store the object pointer (caller may or may not register it */
-- *parts[i].mtdp = &slave->mtd;
-- slave->registered = 0;
-- }
-- else
-- {
-- /* register our partition */
-- add_mtd_device(&slave->mtd);
-- slave->registered = 1;
-+#endif
-+#ifdef CONFIG_MTD_ROOTFS_SPLIT
-+ ret = split_rootfs_data(master, part, j);
-+ if (ret == 0)
-+ j++;
-+#endif
- }
- }
-
+++ /dev/null
-Index: linux-2.6.21.7/drivers/mtd/devices/block2mtd.c
-===================================================================
---- linux-2.6.21.7.orig/drivers/mtd/devices/block2mtd.c
-+++ linux-2.6.21.7/drivers/mtd/devices/block2mtd.c
-@@ -16,6 +16,7 @@
- #include <linux/list.h>
- #include <linux/init.h>
- #include <linux/mtd/mtd.h>
-+#include <linux/mtd/partitions.h>
- #include <linux/buffer_head.h>
- #include <linux/mutex.h>
- #include <linux/mount.h>
-@@ -288,10 +289,11 @@ static void block2mtd_free_device(struct
-
-
- /* FIXME: ensure that mtd->size % erase_size == 0 */
--static struct block2mtd_dev *add_device(char *devname, int erase_size)
-+static struct block2mtd_dev *add_device(char *devname, int erase_size, char *mtdname)
- {
- struct block_device *bdev;
- struct block2mtd_dev *dev;
-+ struct mtd_partition *part;
-
- if (!devname)
- return NULL;
-@@ -330,14 +332,18 @@ static struct block2mtd_dev *add_device(
-
- /* Setup the MTD structure */
- /* make the name contain the block device in */
-- dev->mtd.name = kmalloc(sizeof("block2mtd: ") + strlen(devname),
-- GFP_KERNEL);
-+
-+ if (!mtdname)
-+ mtdname = devname;
-+
-+ dev->mtd.name = kmalloc(strlen(mtdname) + 1, GFP_KERNEL);
-+
- if (!dev->mtd.name)
- goto devinit_err;
-+
-+ strcpy(dev->mtd.name, mtdname);
-
-- sprintf(dev->mtd.name, "block2mtd: %s", devname);
--
-- dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK;
-+ dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK & ~(erase_size - 1);
- dev->mtd.erasesize = erase_size;
- dev->mtd.writesize = 1;
- dev->mtd.type = MTD_RAM;
-@@ -349,15 +355,18 @@ static struct block2mtd_dev *add_device(
- dev->mtd.read = block2mtd_read;
- dev->mtd.priv = dev;
- dev->mtd.owner = THIS_MODULE;
--
-- if (add_mtd_device(&dev->mtd)) {
-+
-+ part = kzalloc(sizeof(struct mtd_partition), GFP_KERNEL);
-+ part->name = dev->mtd.name;
-+ part->offset = 0;
-+ part->size = dev->mtd.size;
-+ if (add_mtd_partitions(&dev->mtd, part, 1)) {
- /* Device didnt get added, so free the entry */
- goto devinit_err;
- }
- list_add(&dev->list, &blkmtd_device_list);
- INFO("mtd%d: [%s] erase_size = %dKiB [%d]", dev->mtd.index,
-- dev->mtd.name + strlen("blkmtd: "),
-- dev->mtd.erasesize >> 10, dev->mtd.erasesize);
-+ mtdname, dev->mtd.erasesize >> 10, dev->mtd.erasesize);
- return dev;
-
- devinit_err:
-@@ -430,9 +439,9 @@ static __initdata char block2mtd_paramli
-
- static int block2mtd_setup2(const char *val)
- {
-- char buf[80 + 12]; /* 80 for device, 12 for erase size */
-+ char buf[80 + 12 + 80]; /* 80 for device, 12 for erase size, 80 for name */
- char *str = buf;
-- char *token[2];
-+ char *token[3];
- char *name;
- size_t erase_size = PAGE_SIZE;
- int i, ret;
-@@ -443,7 +452,7 @@ static int block2mtd_setup2(const char *
- strcpy(str, val);
- kill_final_newline(str);
-
-- for (i = 0; i < 2; i++)
-+ for (i = 0; i < 3; i++)
- token[i] = strsep(&str, ",");
-
- if (str)
-@@ -463,8 +472,10 @@ static int block2mtd_setup2(const char *
- parse_err("illegal erase size");
- }
- }
-+ if (token[2] && (strlen(token[2]) + 1 > 80))
-+ parse_err("mtd device name too long");
-
-- add_device(name, erase_size);
-+ add_device(name, erase_size, token[2]);
-
- return 0;
- }
-@@ -498,7 +509,7 @@ static int block2mtd_setup(const char *v
-
-
- module_param_call(block2mtd, block2mtd_setup, NULL, NULL, 0200);
--MODULE_PARM_DESC(block2mtd, "Device to use. \"block2mtd=<dev>[,<erasesize>]\"");
-+MODULE_PARM_DESC(block2mtd, "Device to use. \"block2mtd=<dev>[,<erasesize>[,<name>]]\"");
-
- static int __init block2mtd_init(void)
- {
+++ /dev/null
-Index: linux-2.6.21.7/net/netfilter/Kconfig
-===================================================================
---- linux-2.6.21.7.orig/net/netfilter/Kconfig
-+++ linux-2.6.21.7/net/netfilter/Kconfig
-@@ -640,6 +640,27 @@ config NETFILTER_XT_MATCH_STATE
-
- To compile it as a module, choose M here. If unsure, say N.
-
-+config NETFILTER_XT_MATCH_LAYER7
-+ tristate '"layer7" match support'
-+ depends on NETFILTER_XTABLES
-+ depends on EXPERIMENTAL && (IP_NF_CONNTRACK || NF_CONNTRACK)
-+ depends on NF_CT_ACCT
-+ help
-+ Say Y if you want to be able to classify connections (and their
-+ packets) based on regular expression matching of their application
-+ layer data. This is one way to classify applications such as
-+ peer-to-peer filesharing systems that do not always use the same
-+ port.
-+
-+ To compile it as a module, choose M here. If unsure, say N.
-+
-+config NETFILTER_XT_MATCH_LAYER7_DEBUG
-+ bool 'Layer 7 debugging output'
-+ depends on NETFILTER_XT_MATCH_LAYER7
-+ help
-+ Say Y to get lots of debugging output.
-+
-+
- config NETFILTER_XT_MATCH_STATISTIC
- tristate '"statistic" match support'
- depends on NETFILTER_XTABLES
-Index: linux-2.6.21.7/net/netfilter/Makefile
-===================================================================
---- linux-2.6.21.7.orig/net/netfilter/Makefile
-+++ linux-2.6.21.7/net/netfilter/Makefile
-@@ -68,6 +68,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_QUOTA) +
- obj-$(CONFIG_NETFILTER_XT_MATCH_REALM) += xt_realm.o
- obj-$(CONFIG_NETFILTER_XT_MATCH_SCTP) += xt_sctp.o
- obj-$(CONFIG_NETFILTER_XT_MATCH_STATE) += xt_state.o
-+obj-$(CONFIG_NETFILTER_XT_MATCH_LAYER7) += xt_layer7.o
- obj-$(CONFIG_NETFILTER_XT_MATCH_STATISTIC) += xt_statistic.o
- obj-$(CONFIG_NETFILTER_XT_MATCH_STRING) += xt_string.o
- obj-$(CONFIG_NETFILTER_XT_MATCH_TCPMSS) += xt_tcpmss.o
-Index: linux-2.6.21.7/net/netfilter/xt_layer7.c
-===================================================================
---- /dev/null
-+++ linux-2.6.21.7/net/netfilter/xt_layer7.c
-@@ -0,0 +1,634 @@
-+/*
-+ Kernel module to match application layer (OSI layer 7) data in connections.
-+
-+ http://l7-filter.sf.net
-+
-+ (C) 2003, 2004, 2005, 2006, 2007 Matthew Strait and Ethan Sommer.
-+
-+ 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.
-+ http://www.gnu.org/licenses/gpl.txt
-+
-+ Based on ipt_string.c (C) 2000 Emmanuel Roger <winfield@freegates.be>,
-+ xt_helper.c (C) 2002 Harald Welte and cls_layer7.c (C) 2003 Matthew Strait,
-+ Ethan Sommer, Justin Levandoski.
-+*/
-+
-+#include <linux/spinlock.h>
-+#include <linux/version.h>
-+#include <net/ip.h>
-+#include <net/tcp.h>
-+#include <linux/module.h>
-+#include <linux/skbuff.h>
-+#include <linux/netfilter.h>
-+#include <net/netfilter/nf_conntrack.h>
-+#include <net/netfilter/nf_conntrack_core.h>
-+#include <linux/netfilter/x_tables.h>
-+#include <linux/netfilter/xt_layer7.h>
-+#include <linux/ctype.h>
-+#include <linux/proc_fs.h>
-+
-+#include "regexp/regexp.c"
-+
-+MODULE_LICENSE("GPL");
-+MODULE_AUTHOR("Matthew Strait <quadong@users.sf.net>, Ethan Sommer <sommere@users.sf.net>");
-+MODULE_DESCRIPTION("iptables application layer match module");
-+MODULE_ALIAS("ipt_layer7");
-+MODULE_VERSION("2.17");
-+
-+static int maxdatalen = 2048; // this is the default
-+module_param(maxdatalen, int, 0444);
-+MODULE_PARM_DESC(maxdatalen, "maximum bytes of data looked at by l7-filter");
-+#ifdef CONFIG_NETFILTER_XT_MATCH_LAYER7_DEBUG
-+ #define DPRINTK(format,args...) printk(format,##args)
-+#else
-+ #define DPRINTK(format,args...)
-+#endif
-+
-+#define TOTAL_PACKETS master_conntrack->counters[IP_CT_DIR_ORIGINAL].packets + \
-+ master_conntrack->counters[IP_CT_DIR_REPLY].packets
-+
-+/* Number of packets whose data we look at.
-+This can be modified through /proc/net/layer7_numpackets */
-+static int num_packets = 10;
-+
-+static struct pattern_cache {
-+ char * regex_string;
-+ regexp * pattern;
-+ struct pattern_cache * next;
-+} * first_pattern_cache = NULL;
-+
-+DEFINE_SPINLOCK(l7_lock);
-+
-+#ifdef CONFIG_IP_NF_MATCH_LAYER7_DEBUG
-+/* Converts an unfriendly string into a friendly one by
-+replacing unprintables with periods and all whitespace with " ". */
-+static char * friendly_print(unsigned char * s)
-+{
-+ char * f = kmalloc(strlen(s) + 1, GFP_ATOMIC);
-+ int i;
-+
-+ if(!f) {
-+ if (net_ratelimit())
-+ printk(KERN_ERR "layer7: out of memory in "
-+ "friendly_print, bailing.\n");
-+ return NULL;
-+ }
-+
-+ for(i = 0; i < strlen(s); i++){
-+ if(isprint(s[i]) && s[i] < 128) f[i] = s[i];
-+ else if(isspace(s[i])) f[i] = ' ';
-+ else f[i] = '.';
-+ }
-+ f[i] = '\0';
-+ return f;
-+}
-+
-+static char dec2hex(int i)
-+{
-+ switch (i) {
-+ case 0 ... 9:
-+ return (i + '0');
-+ break;
-+ case 10 ... 15:
-+ return (i - 10 + 'a');
-+ break;
-+ default:
-+ if (net_ratelimit())
-+ printk("layer7: Problem in dec2hex\n");
-+ return '\0';
-+ }
-+}
-+
-+static char * hex_print(unsigned char * s)
-+{
-+ char * g = kmalloc(strlen(s)*3 + 1, GFP_ATOMIC);
-+ int i;
-+
-+ if(!g) {
-+ if (net_ratelimit())
-+ printk(KERN_ERR "layer7: out of memory in hex_print, "
-+ "bailing.\n");
-+ return NULL;
-+ }
-+
-+ for(i = 0; i < strlen(s); i++) {
-+ g[i*3 ] = dec2hex(s[i]/16);
-+ g[i*3 + 1] = dec2hex(s[i]%16);
-+ g[i*3 + 2] = ' ';
-+ }
-+ g[i*3] = '\0';
-+
-+ return g;
-+}
-+#endif // DEBUG
-+
-+/* Use instead of regcomp. As we expect to be seeing the same regexps over and
-+over again, it make sense to cache the results. */
-+static regexp * compile_and_cache(const char * regex_string,
-+ const char * protocol)
-+{
-+ struct pattern_cache * node = first_pattern_cache;
-+ struct pattern_cache * last_pattern_cache = first_pattern_cache;
-+ struct pattern_cache * tmp;
-+ unsigned int len;
-+
-+ while (node != NULL) {
-+ if (!strcmp(node->regex_string, regex_string))
-+ return node->pattern;
-+
-+ last_pattern_cache = node;/* points at the last non-NULL node */
-+ node = node->next;
-+ }
-+
-+ /* If we reach the end of the list, then we have not yet cached
-+ the pattern for this regex. Let's do that now.
-+ Be paranoid about running out of memory to avoid list corruption. */
-+ tmp = kmalloc(sizeof(struct pattern_cache), GFP_ATOMIC);
-+
-+ if(!tmp) {
-+ if (net_ratelimit())
-+ printk(KERN_ERR "layer7: out of memory in "
-+ "compile_and_cache, bailing.\n");
-+ return NULL;
-+ }
-+
-+ tmp->regex_string = kmalloc(strlen(regex_string) + 1, GFP_ATOMIC);
-+ tmp->pattern = kmalloc(sizeof(struct regexp), GFP_ATOMIC);
-+ tmp->next = NULL;
-+
-+ if(!tmp->regex_string || !tmp->pattern) {
-+ if (net_ratelimit())
-+ printk(KERN_ERR "layer7: out of memory in "
-+ "compile_and_cache, bailing.\n");
-+ kfree(tmp->regex_string);
-+ kfree(tmp->pattern);
-+ kfree(tmp);
-+ return NULL;
-+ }
-+
-+ /* Ok. The new node is all ready now. */
-+ node = tmp;
-+
-+ if(first_pattern_cache == NULL) /* list is empty */
-+ first_pattern_cache = node; /* make node the beginning */
-+ else
-+ last_pattern_cache->next = node; /* attach node to the end */
-+
-+ /* copy the string and compile the regex */
-+ len = strlen(regex_string);
-+ DPRINTK("About to compile this: \"%s\"\n", regex_string);
-+ node->pattern = regcomp((char *)regex_string, &len);
-+ if ( !node->pattern ) {
-+ if (net_ratelimit())
-+ printk(KERN_ERR "layer7: Error compiling regexp "
-+ "\"%s\" (%s)\n",
-+ regex_string, protocol);
-+ /* pattern is now cached as NULL, so we won't try again. */
-+ }
-+
-+ strcpy(node->regex_string, regex_string);
-+ return node->pattern;
-+}
-+
-+static int can_handle(const struct sk_buff *skb)
-+{
-+ if(!ip_hdr(skb)) /* not IP */
-+ return 0;
-+ if(ip_hdr(skb)->protocol != IPPROTO_TCP &&
-+ ip_hdr(skb)->protocol != IPPROTO_UDP &&
-+ ip_hdr(skb)->protocol != IPPROTO_ICMP)
-+ return 0;
-+ return 1;
-+}
-+
-+/* Returns offset the into the skb->data that the application data starts */
-+static int app_data_offset(const struct sk_buff *skb)
-+{
-+ /* In case we are ported somewhere (ebtables?) where ip_hdr(skb)
-+ isn't set, this can be gotten from 4*(skb->data[0] & 0x0f) as well. */
-+ int ip_hl = 4*ip_hdr(skb)->ihl;
-+
-+ if( ip_hdr(skb)->protocol == IPPROTO_TCP ) {
-+ /* 12 == offset into TCP header for the header length field.
-+ Can't get this with skb->h.th->doff because the tcphdr
-+ struct doesn't get set when routing (this is confirmed to be
-+ true in Netfilter as well as QoS.) */
-+ int tcp_hl = 4*(skb->data[ip_hl + 12] >> 4);
-+
-+ return ip_hl + tcp_hl;
-+ } else if( ip_hdr(skb)->protocol == IPPROTO_UDP ) {
-+ return ip_hl + 8; /* UDP header is always 8 bytes */
-+ } else if( ip_hdr(skb)->protocol == IPPROTO_ICMP ) {
-+ return ip_hl + 8; /* ICMP header is 8 bytes */
-+ } else {
-+ if (net_ratelimit())
-+ printk(KERN_ERR "layer7: tried to handle unknown "
-+ "protocol!\n");
-+ return ip_hl + 8; /* something reasonable */
-+ }
-+}
-+
-+/* handles whether there's a match when we aren't appending data anymore */
-+static int match_no_append(struct nf_conn * conntrack,
-+ struct nf_conn * master_conntrack,
-+ enum ip_conntrack_info ctinfo,
-+ enum ip_conntrack_info master_ctinfo,
-+ const struct xt_layer7_info * info)
-+{
-+ /* If we're in here, throw the app data away */
-+ if(master_conntrack->layer7.app_data != NULL) {
-+
-+ #ifdef CONFIG_IP_NF_MATCH_LAYER7_DEBUG
-+ if(!master_conntrack->layer7.app_proto) {
-+ char * f =
-+ friendly_print(master_conntrack->layer7.app_data);
-+ char * g =
-+ hex_print(master_conntrack->layer7.app_data);
-+ DPRINTK("\nl7-filter gave up after %d bytes "
-+ "(%d packets):\n%s\n",
-+ strlen(f), TOTAL_PACKETS, f);
-+ kfree(f);
-+ DPRINTK("In hex: %s\n", g);
-+ kfree(g);
-+ }
-+ #endif
-+
-+ kfree(master_conntrack->layer7.app_data);
-+ master_conntrack->layer7.app_data = NULL; /* don't free again */
-+ }
-+
-+ if(master_conntrack->layer7.app_proto){
-+ /* Here child connections set their .app_proto (for /proc) */
-+ if(!conntrack->layer7.app_proto) {
-+ conntrack->layer7.app_proto =
-+ kmalloc(strlen(master_conntrack->layer7.app_proto)+1,
-+ GFP_ATOMIC);
-+ if(!conntrack->layer7.app_proto){
-+ if (net_ratelimit())
-+ printk(KERN_ERR "layer7: out of memory "
-+ "in match_no_append, "
-+ "bailing.\n");
-+ return 1;
-+ }
-+ strcpy(conntrack->layer7.app_proto,
-+ master_conntrack->layer7.app_proto);
-+ }
-+
-+ return (!strcmp(master_conntrack->layer7.app_proto,
-+ info->protocol));
-+ }
-+ else {
-+ /* If not classified, set to "unknown" to distinguish from
-+ connections that are still being tested. */
-+ master_conntrack->layer7.app_proto =
-+ kmalloc(strlen("unknown")+1, GFP_ATOMIC);
-+ if(!master_conntrack->layer7.app_proto){
-+ if (net_ratelimit())
-+ printk(KERN_ERR "layer7: out of memory in "
-+ "match_no_append, bailing.\n");
-+ return 1;
-+ }
-+ strcpy(master_conntrack->layer7.app_proto, "unknown");
-+ return 0;
-+ }
-+}
-+
-+/* add the new app data to the conntrack. Return number of bytes added. */
-+static int add_data(struct nf_conn * master_conntrack,
-+ char * app_data, int appdatalen)
-+{
-+ int length = 0, i;
-+ int oldlength = master_conntrack->layer7.app_data_len;
-+
-+ /* This is a fix for a race condition by Deti Fliegl. However, I'm not
-+ clear on whether the race condition exists or whether this really
-+ fixes it. I might just be being dense... Anyway, if it's not really
-+ a fix, all it does is waste a very small amount of time. */
-+ if(!master_conntrack->layer7.app_data) return 0;
-+
-+ /* Strip nulls. Make everything lower case (our regex lib doesn't
-+ do case insensitivity). Add it to the end of the current data. */
-+ for(i = 0; i < maxdatalen-oldlength-1 &&
-+ i < appdatalen; i++) {
-+ if(app_data[i] != '\0') {
-+ /* the kernel version of tolower mungs 'upper ascii' */
-+ master_conntrack->layer7.app_data[length+oldlength] =
-+ isascii(app_data[i])?
-+ tolower(app_data[i]) : app_data[i];
-+ length++;
-+ }
-+ }
-+
-+ master_conntrack->layer7.app_data[length+oldlength] = '\0';
-+ master_conntrack->layer7.app_data_len = length + oldlength;
-+
-+ return length;
-+}
-+
-+/* taken from drivers/video/modedb.c */
-+static int my_atoi(const char *s)
-+{
-+ int val = 0;
-+
-+ for (;; s++) {
-+ switch (*s) {
-+ case '0'...'9':
-+ val = 10*val+(*s-'0');
-+ break;
-+ default:
-+ return val;
-+ }
-+ }
-+}
-+
-+/* write out num_packets to userland. */
-+static int layer7_read_proc(char* page, char ** start, off_t off, int count,
-+ int* eof, void * data)
-+{
-+ if(num_packets > 99 && net_ratelimit())
-+ printk(KERN_ERR "layer7: NOT REACHED. num_packets too big\n");
-+
-+ page[0] = num_packets/10 + '0';
-+ page[1] = num_packets%10 + '0';
-+ page[2] = '\n';
-+ page[3] = '\0';
-+
-+ *eof=1;
-+
-+ return 3;
-+}
-+
-+/* Read in num_packets from userland */
-+static int layer7_write_proc(struct file* file, const char* buffer,
-+ unsigned long count, void *data)
-+{
-+ char * foo = kmalloc(count, GFP_ATOMIC);
-+
-+ if(!foo){
-+ if (net_ratelimit())
-+ printk(KERN_ERR "layer7: out of memory, bailing. "
-+ "num_packets unchanged.\n");
-+ return count;
-+ }
-+
-+ if(copy_from_user(foo, buffer, count)) {
-+ return -EFAULT;
-+ }
-+
-+
-+ num_packets = my_atoi(foo);
-+ kfree (foo);
-+
-+ /* This has an arbitrary limit to make the math easier. I'm lazy.
-+ But anyway, 99 is a LOT! If you want more, you're doing it wrong! */
-+ if(num_packets > 99) {
-+ printk(KERN_WARNING "layer7: num_packets can't be > 99.\n");
-+ num_packets = 99;
-+ } else if(num_packets < 1) {
-+ printk(KERN_WARNING "layer7: num_packets can't be < 1.\n");
-+ num_packets = 1;
-+ }
-+
-+ return count;
-+}
-+
-+static int
-+match(const struct sk_buff *skbin,
-+ const struct net_device *in,
-+ const struct net_device *out,
-+ const struct xt_match *match,
-+ const void *matchinfo,
-+ int offset,
-+ unsigned int protoff,
-+ int *hotdrop)
-+{
-+ /* sidestep const without getting a compiler warning... */
-+ struct sk_buff * skb = (struct sk_buff *)skbin;
-+
-+ const struct xt_layer7_info * info = matchinfo;
-+ enum ip_conntrack_info master_ctinfo, ctinfo;
-+ struct nf_conn *master_conntrack, *conntrack;
-+ unsigned char * app_data;
-+ unsigned int pattern_result, appdatalen;
-+ regexp * comppattern;
-+
-+ /* Be paranoid/incompetent - lock the entire match function. */
-+ spin_lock_bh(&l7_lock);
-+
-+ if(!can_handle(skb)){
-+ DPRINTK("layer7: This is some protocol I can't handle.\n");
-+ spin_unlock_bh(&l7_lock);
-+ return info->invert;
-+ }
-+
-+ /* Treat parent & all its children together as one connection, except
-+ for the purpose of setting conntrack->layer7.app_proto in the actual
-+ connection. This makes /proc/net/ip_conntrack more satisfying. */
-+ if(!(conntrack = nf_ct_get(skb, &ctinfo)) ||
-+ !(master_conntrack=nf_ct_get(skb,&master_ctinfo))){
-+ DPRINTK("layer7: couldn't get conntrack.\n");
-+ spin_unlock_bh(&l7_lock);
-+ return info->invert;
-+ }
-+
-+ /* Try to get a master conntrack (and its master etc) for FTP, etc. */
-+ while (master_ct(master_conntrack) != NULL)
-+ master_conntrack = master_ct(master_conntrack);
-+
-+ /* if we've classified it or seen too many packets */
-+ if(TOTAL_PACKETS > num_packets ||
-+ master_conntrack->layer7.app_proto) {
-+
-+ pattern_result = match_no_append(conntrack, master_conntrack,
-+ ctinfo, master_ctinfo, info);
-+
-+ /* skb->cb[0] == seen. Don't do things twice if there are
-+ multiple l7 rules. I'm not sure that using cb for this purpose
-+ is correct, even though it says "put your private variables
-+ there". But it doesn't look like it is being used for anything
-+ else in the skbs that make it here. */
-+ skb->cb[0] = 1; /* marking it seen here's probably irrelevant */
-+
-+ spin_unlock_bh(&l7_lock);
-+ return (pattern_result ^ info->invert);
-+ }
-+
-+ if(skb_is_nonlinear(skb)){
-+ if(skb_linearize(skb) != 0){
-+ if (net_ratelimit())
-+ printk(KERN_ERR "layer7: failed to linearize "
-+ "packet, bailing.\n");
-+ spin_unlock_bh(&l7_lock);
-+ return info->invert;
-+ }
-+ }
-+
-+ /* now that the skb is linearized, it's safe to set these. */
-+ app_data = skb->data + app_data_offset(skb);
-+ appdatalen = skb_tail_pointer(skb) - app_data;
-+
-+ /* the return value gets checked later, when we're ready to use it */
-+ comppattern = compile_and_cache(info->pattern, info->protocol);
-+
-+ /* On the first packet of a connection, allocate space for app data */
-+ if(TOTAL_PACKETS == 1 && !skb->cb[0] &&
-+ !master_conntrack->layer7.app_data){
-+ master_conntrack->layer7.app_data =
-+ kmalloc(maxdatalen, GFP_ATOMIC);
-+ if(!master_conntrack->layer7.app_data){
-+ if (net_ratelimit())
-+ printk(KERN_ERR "layer7: out of memory in "
-+ "match, bailing.\n");
-+ spin_unlock_bh(&l7_lock);
-+ return info->invert;
-+ }
-+
-+ master_conntrack->layer7.app_data[0] = '\0';
-+ }
-+
-+ /* Can be here, but unallocated, if numpackets is increased near
-+ the beginning of a connection */
-+ if(master_conntrack->layer7.app_data == NULL){
-+ spin_unlock_bh(&l7_lock);
-+ return (info->invert); /* unmatched */
-+ }
-+
-+ if(!skb->cb[0]){
-+ int newbytes;
-+ newbytes = add_data(master_conntrack, app_data, appdatalen);
-+
-+ if(newbytes == 0) { /* didn't add any data */
-+ skb->cb[0] = 1;
-+ /* Didn't match before, not going to match now */
-+ spin_unlock_bh(&l7_lock);
-+ return info->invert;
-+ }
-+ }
-+
-+ /* If looking for "unknown", then never match. "Unknown" means that
-+ we've given up; we're still trying with these packets. */
-+ if(!strcmp(info->protocol, "unknown")) {
-+ pattern_result = 0;
-+ /* If looking for "unset", then always match. "Unset" means that we
-+ haven't yet classified the connection. */
-+ } else if(!strcmp(info->protocol, "unset")) {
-+ pattern_result = 2;
-+ DPRINTK("layer7: matched unset: not yet classified "
-+ "(%d/%d packets)\n", TOTAL_PACKETS, num_packets);
-+ /* If the regexp failed to compile, don't bother running it */
-+ } else if(comppattern &&
-+ regexec(comppattern, master_conntrack->layer7.app_data)){
-+ DPRINTK("layer7: matched %s\n", info->protocol);
-+ pattern_result = 1;
-+ } else pattern_result = 0;
-+
-+ if(pattern_result == 1) {
-+ master_conntrack->layer7.app_proto =
-+ kmalloc(strlen(info->protocol)+1, GFP_ATOMIC);
-+ if(!master_conntrack->layer7.app_proto){
-+ if (net_ratelimit())
-+ printk(KERN_ERR "layer7: out of memory in "
-+ "match, bailing.\n");
-+ spin_unlock_bh(&l7_lock);
-+ return (pattern_result ^ info->invert);
-+ }
-+ strcpy(master_conntrack->layer7.app_proto, info->protocol);
-+ } else if(pattern_result > 1) { /* cleanup from "unset" */
-+ pattern_result = 1;
-+ }
-+
-+ /* mark the packet seen */
-+ skb->cb[0] = 1;
-+
-+ spin_unlock_bh(&l7_lock);
-+ return (pattern_result ^ info->invert);
-+}
-+
-+static int check(const char *tablename,
-+ const void *inf,
-+ const struct xt_match *match,
-+ void *matchinfo,
-+ unsigned int hook_mask)
-+
-+{
-+ // load nf_conntrack_ipv4
-+ if (nf_ct_l3proto_try_module_get(match->family) < 0) {
-+ printk(KERN_WARNING "can't load conntrack support for "
-+ "proto=%d\n", match->family);
-+ return false;
-+ }
-+ return true;
-+}
-+
-+static void
-+destroy(const struct xt_match *match, void *matchinfo)
-+{
-+ nf_ct_l3proto_module_put(match->family);
-+}
-+
-+static struct xt_match xt_layer7_match[] = {
-+{
-+ .name = "layer7",
-+ .family = AF_INET,
-+ .checkentry = check,
-+ .match = match,
-+ .destroy = destroy,
-+ .matchsize = sizeof(struct xt_layer7_info),
-+ .me = THIS_MODULE
-+}
-+};
-+
-+static void layer7_cleanup_proc(void)
-+{
-+#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,23)
-+ remove_proc_entry("layer7_numpackets", proc_net);
-+#else
-+ remove_proc_entry("layer7_numpackets", init_net.proc_net);
-+#endif
-+}
-+
-+/* register the proc file */
-+static void layer7_init_proc(void)
-+{
-+ struct proc_dir_entry* entry;
-+#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,23)
-+ entry = create_proc_entry("layer7_numpackets", 0644, proc_net);
-+#else
-+ entry = create_proc_entry("layer7_numpackets", 0644, init_net.proc_net);
-+#endif
-+ entry->read_proc = layer7_read_proc;
-+ entry->write_proc = layer7_write_proc;
-+}
-+
-+static int __init xt_layer7_init(void)
-+{
-+ need_conntrack();
-+
-+ layer7_init_proc();
-+ if(maxdatalen < 1) {
-+ printk(KERN_WARNING "layer7: maxdatalen can't be < 1, "
-+ "using 1\n");
-+ maxdatalen = 1;
-+ }
-+ /* This is not a hard limit. It's just here to prevent people from
-+ bringing their slow machines to a grinding halt. */
-+ else if(maxdatalen > 65536) {
-+ printk(KERN_WARNING "layer7: maxdatalen can't be > 65536, "
-+ "using 65536\n");
-+ maxdatalen = 65536;
-+ }
-+ return xt_register_matches(xt_layer7_match,
-+ ARRAY_SIZE(xt_layer7_match));
-+}
-+
-+static void __exit xt_layer7_fini(void)
-+{
-+ layer7_cleanup_proc();
-+ xt_unregister_matches(xt_layer7_match, ARRAY_SIZE(xt_layer7_match));
-+}
-+
-+module_init(xt_layer7_init);
-+module_exit(xt_layer7_fini);
-Index: linux-2.6.21.7/net/netfilter/regexp/regexp.c
-===================================================================
---- /dev/null
-+++ linux-2.6.21.7/net/netfilter/regexp/regexp.c
-@@ -0,0 +1,1197 @@
-+/*
-+ * regcomp and regexec -- regsub and regerror are elsewhere
-+ * @(#)regexp.c 1.3 of 18 April 87
-+ *
-+ * Copyright (c) 1986 by University of Toronto.
-+ * Written by Henry Spencer. Not derived from licensed software.
-+ *
-+ * Permission is granted to anyone to use this software for any
-+ * purpose on any computer system, and to redistribute it freely,
-+ * subject to the following restrictions:
-+ *
-+ * 1. The author is not responsible for the consequences of use of
-+ * this software, no matter how awful, even if they arise
-+ * from defects in it.
-+ *
-+ * 2. The origin of this software must not be misrepresented, either
-+ * by explicit claim or by omission.
-+ *
-+ * 3. Altered versions must be plainly marked as such, and must not
-+ * be misrepresented as being the original software.
-+ *
-+ * Beware that some of this code is subtly aware of the way operator
-+ * precedence is structured in regular expressions. Serious changes in
-+ * regular-expression syntax might require a total rethink.
-+ *
-+ * This code was modified by Ethan Sommer to work within the kernel
-+ * (it now uses kmalloc etc..)
-+ *
-+ * Modified slightly by Matthew Strait to use more modern C.
-+ */
-+
-+#include "regexp.h"
-+#include "regmagic.h"
-+
-+/* added by ethan and matt. Lets it work in both kernel and user space.
-+(So iptables can use it, for instance.) Yea, it goes both ways... */
-+#if __KERNEL__
-+ #define malloc(foo) kmalloc(foo,GFP_ATOMIC)
-+#else
-+ #define printk(format,args...) printf(format,##args)
-+#endif
-+
-+void regerror(char * s)
-+{
-+ printk("<3>Regexp: %s\n", s);
-+ /* NOTREACHED */
-+}
-+
-+/*
-+ * The "internal use only" fields in regexp.h are present to pass info from
-+ * compile to execute that permits the execute phase to run lots faster on
-+ * simple cases. They are:
-+ *
-+ * regstart char that must begin a match; '\0' if none obvious
-+ * reganch is the match anchored (at beginning-of-line only)?
-+ * regmust string (pointer into program) that match must include, or NULL
-+ * regmlen length of regmust string
-+ *
-+ * Regstart and reganch permit very fast decisions on suitable starting points
-+ * for a match, cutting down the work a lot. Regmust permits fast rejection
-+ * of lines that cannot possibly match. The regmust tests are costly enough
-+ * that regcomp() supplies a regmust only if the r.e. contains something
-+ * potentially expensive (at present, the only such thing detected is * or +
-+ * at the start of the r.e., which can involve a lot of backup). Regmlen is
-+ * supplied because the test in regexec() needs it and regcomp() is computing
-+ * it anyway.
-+ */
-+
-+/*
-+ * Structure for regexp "program". This is essentially a linear encoding
-+ * of a nondeterministic finite-state machine (aka syntax charts or
-+ * "railroad normal form" in parsing technology). Each node is an opcode
-+ * plus a "next" pointer, possibly plus an operand. "Next" pointers of
-+ * all nodes except BRANCH implement concatenation; a "next" pointer with
-+ * a BRANCH on both ends of it is connecting two alternatives. (Here we
-+ * have one of the subtle syntax dependencies: an individual BRANCH (as
-+ * opposed to a collection of them) is never concatenated with anything
-+ * because of operator precedence.) The operand of some types of node is
-+ * a literal string; for others, it is a node leading into a sub-FSM. In
-+ * particular, the operand of a BRANCH node is the first node of the branch.
-+ * (NB this is *not* a tree structure: the tail of the branch connects
-+ * to the thing following the set of BRANCHes.) The opcodes are:
-+ */
-+
-+/* definition number opnd? meaning */
-+#define END 0 /* no End of program. */
-+#define BOL 1 /* no Match "" at beginning of line. */
-+#define EOL 2 /* no Match "" at end of line. */
-+#define ANY 3 /* no Match any one character. */
-+#define ANYOF 4 /* str Match any character in this string. */
-+#define ANYBUT 5 /* str Match any character not in this string. */
-+#define BRANCH 6 /* node Match this alternative, or the next... */
-+#define BACK 7 /* no Match "", "next" ptr points backward. */
-+#define EXACTLY 8 /* str Match this string. */
-+#define NOTHING 9 /* no Match empty string. */
-+#define STAR 10 /* node Match this (simple) thing 0 or more times. */
-+#define PLUS 11 /* node Match this (simple) thing 1 or more times. */
-+#define OPEN 20 /* no Mark this point in input as start of #n. */
-+ /* OPEN+1 is number 1, etc. */
-+#define CLOSE 30 /* no Analogous to OPEN. */
-+
-+/*
-+ * Opcode notes:
-+ *
-+ * BRANCH The set of branches constituting a single choice are hooked
-+ * together with their "next" pointers, since precedence prevents
-+ * anything being concatenated to any individual branch. The
-+ * "next" pointer of the last BRANCH in a choice points to the
-+ * thing following the whole choice. This is also where the
-+ * final "next" pointer of each individual branch points; each
-+ * branch starts with the operand node of a BRANCH node.
-+ *
-+ * BACK Normal "next" pointers all implicitly point forward; BACK
-+ * exists to make loop structures possible.
-+ *
-+ * STAR,PLUS '?', and complex '*' and '+', are implemented as circular
-+ * BRANCH structures using BACK. Simple cases (one character
-+ * per match) are implemented with STAR and PLUS for speed
-+ * and to minimize recursive plunges.
-+ *
-+ * OPEN,CLOSE ...are numbered at compile time.
-+ */
-+
-+/*
-+ * A node is one char of opcode followed by two chars of "next" pointer.
-+ * "Next" pointers are stored as two 8-bit pieces, high order first. The
-+ * value is a positive offset from the opcode of the node containing it.
-+ * An operand, if any, simply follows the node. (Note that much of the
-+ * code generation knows about this implicit relationship.)
-+ *
-+ * Using two bytes for the "next" pointer is vast overkill for most things,
-+ * but allows patterns to get big without disasters.
-+ */
-+#define OP(p) (*(p))
-+#define NEXT(p) (((*((p)+1)&0377)<<8) + (*((p)+2)&0377))
-+#define OPERAND(p) ((p) + 3)
-+
-+/*
-+ * See regmagic.h for one further detail of program structure.
-+ */
-+
-+
-+/*
-+ * Utility definitions.
-+ */
-+#ifndef CHARBITS
-+#define UCHARAT(p) ((int)*(unsigned char *)(p))
-+#else
-+#define UCHARAT(p) ((int)*(p)&CHARBITS)
-+#endif
-+
-+#define FAIL(m) { regerror(m); return(NULL); }
-+#define ISMULT(c) ((c) == '*' || (c) == '+' || (c) == '?')
-+#define META "^$.[()|?+*\\"
-+
-+/*
-+ * Flags to be passed up and down.
-+ */
-+#define HASWIDTH 01 /* Known never to match null string. */
-+#define SIMPLE 02 /* Simple enough to be STAR/PLUS operand. */
-+#define SPSTART 04 /* Starts with * or +. */
-+#define WORST 0 /* Worst case. */
-+
-+/*
-+ * Global work variables for regcomp().
-+ */
-+struct match_globals {
-+char *reginput; /* String-input pointer. */
-+char *regbol; /* Beginning of input, for ^ check. */
-+char **regstartp; /* Pointer to startp array. */
-+char **regendp; /* Ditto for endp. */
-+char *regparse; /* Input-scan pointer. */
-+int regnpar; /* () count. */
-+char regdummy;
-+char *regcode; /* Code-emit pointer; ®dummy = don't. */
-+long regsize; /* Code size. */
-+};
-+
-+/*
-+ * Forward declarations for regcomp()'s friends.
-+ */
-+#ifndef STATIC
-+#define STATIC static
-+#endif
-+STATIC char *reg(struct match_globals *g, int paren,int *flagp);
-+STATIC char *regbranch(struct match_globals *g, int *flagp);
-+STATIC char *regpiece(struct match_globals *g, int *flagp);
-+STATIC char *regatom(struct match_globals *g, int *flagp);
-+STATIC char *regnode(struct match_globals *g, char op);
-+STATIC char *regnext(struct match_globals *g, char *p);
-+STATIC void regc(struct match_globals *g, char b);
-+STATIC void reginsert(struct match_globals *g, char op, char *opnd);
-+STATIC void regtail(struct match_globals *g, char *p, char *val);
-+STATIC void regoptail(struct match_globals *g, char *p, char *val);
-+
-+
-+__kernel_size_t my_strcspn(const char *s1,const char *s2)
-+{
-+ char *scan1;
-+ char *scan2;
-+ int count;
-+
-+ count = 0;
-+ for (scan1 = (char *)s1; *scan1 != '\0'; scan1++) {
-+ for (scan2 = (char *)s2; *scan2 != '\0';) /* ++ moved down. */
-+ if (*scan1 == *scan2++)
-+ return(count);
-+ count++;
-+ }
-+ return(count);
-+}
-+
-+/*
-+ - regcomp - compile a regular expression into internal code
-+ *
-+ * We can't allocate space until we know how big the compiled form will be,
-+ * but we can't compile it (and thus know how big it is) until we've got a
-+ * place to put the code. So we cheat: we compile it twice, once with code
-+ * generation turned off and size counting turned on, and once "for real".
-+ * This also means that we don't allocate space until we are sure that the
-+ * thing really will compile successfully, and we never have to move the
-+ * code and thus invalidate pointers into it. (Note that it has to be in
-+ * one piece because free() must be able to free it all.)
-+ *
-+ * Beware that the optimization-preparation code in here knows about some
-+ * of the structure of the compiled regexp.
-+ */
-+regexp *
-+regcomp(char *exp,int *patternsize)
-+{
-+ register regexp *r;
-+ register char *scan;
-+ register char *longest;
-+ register int len;
-+ int flags;
-+ struct match_globals g;
-+
-+ /* commented out by ethan
-+ extern char *malloc();
-+ */
-+
-+ if (exp == NULL)
-+ FAIL("NULL argument");
-+
-+ /* First pass: determine size, legality. */
-+ g.regparse = exp;
-+ g.regnpar = 1;
-+ g.regsize = 0L;
-+ g.regcode = &g.regdummy;
-+ regc(&g, MAGIC);
-+ if (reg(&g, 0, &flags) == NULL)
-+ return(NULL);
-+
-+ /* Small enough for pointer-storage convention? */
-+ if (g.regsize >= 32767L) /* Probably could be 65535L. */
-+ FAIL("regexp too big");
-+
-+ /* Allocate space. */
-+ *patternsize=sizeof(regexp) + (unsigned)g.regsize;
-+ r = (regexp *)malloc(sizeof(regexp) + (unsigned)g.regsize);
-+ if (r == NULL)
-+ FAIL("out of space");
-+
-+ /* Second pass: emit code. */
-+ g.regparse = exp;
-+ g.regnpar = 1;
-+ g.regcode = r->program;
-+ regc(&g, MAGIC);
-+ if (reg(&g, 0, &flags) == NULL)
-+ return(NULL);
-+
-+ /* Dig out information for optimizations. */
-+ r->regstart = '\0'; /* Worst-case defaults. */
-+ r->reganch = 0;
-+ r->regmust = NULL;
-+ r->regmlen = 0;
-+ scan = r->program+1; /* First BRANCH. */
-+ if (OP(regnext(&g, scan)) == END) { /* Only one top-level choice. */
-+ scan = OPERAND(scan);
-+
-+ /* Starting-point info. */
-+ if (OP(scan) == EXACTLY)
-+ r->regstart = *OPERAND(scan);
-+ else if (OP(scan) == BOL)
-+ r->reganch++;
-+
-+ /*
-+ * If there's something expensive in the r.e., find the
-+ * longest literal string that must appear and make it the
-+ * regmust. Resolve ties in favor of later strings, since
-+ * the regstart check works with the beginning of the r.e.
-+ * and avoiding duplication strengthens checking. Not a
-+ * strong reason, but sufficient in the absence of others.
-+ */
-+ if (flags&SPSTART) {
-+ longest = NULL;
-+ len = 0;
-+ for (; scan != NULL; scan = regnext(&g, scan))
-+ if (OP(scan) == EXACTLY && strlen(OPERAND(scan)) >= len) {
-+ longest = OPERAND(scan);
-+ len = strlen(OPERAND(scan));
-+ }
-+ r->regmust = longest;
-+ r->regmlen = len;
-+ }
-+ }
-+
-+ return(r);
-+}
-+
-+/*
-+ - reg - regular expression, i.e. main body or parenthesized thing
-+ *
-+ * Caller must absorb opening parenthesis.
-+ *
-+ * Combining parenthesis handling with the base level of regular expression
-+ * is a trifle forced, but the need to tie the tails of the branches to what
-+ * follows makes it hard to avoid.
-+ */
-+static char *
-+reg(struct match_globals *g, int paren, int *flagp /* Parenthesized? */ )
-+{
-+ register char *ret;
-+ register char *br;
-+ register char *ender;
-+ register int parno = 0; /* 0 makes gcc happy */
-+ int flags;
-+
-+ *flagp = HASWIDTH; /* Tentatively. */
-+
-+ /* Make an OPEN node, if parenthesized. */
-+ if (paren) {
-+ if (g->regnpar >= NSUBEXP)
-+ FAIL("too many ()");
-+ parno = g->regnpar;
-+ g->regnpar++;
-+ ret = regnode(g, OPEN+parno);
-+ } else
-+ ret = NULL;
-+
-+ /* Pick up the branches, linking them together. */
-+ br = regbranch(g, &flags);
-+ if (br == NULL)
-+ return(NULL);
-+ if (ret != NULL)
-+ regtail(g, ret, br); /* OPEN -> first. */
-+ else
-+ ret = br;
-+ if (!(flags&HASWIDTH))
-+ *flagp &= ~HASWIDTH;
-+ *flagp |= flags&SPSTART;
-+ while (*g->regparse == '|') {
-+ g->regparse++;
-+ br = regbranch(g, &flags);
-+ if (br == NULL)
-+ return(NULL);
-+ regtail(g, ret, br); /* BRANCH -> BRANCH. */
-+ if (!(flags&HASWIDTH))
-+ *flagp &= ~HASWIDTH;
-+ *flagp |= flags&SPSTART;
-+ }
-+
-+ /* Make a closing node, and hook it on the end. */
-+ ender = regnode(g, (paren) ? CLOSE+parno : END);
-+ regtail(g, ret, ender);
-+
-+ /* Hook the tails of the branches to the closing node. */
-+ for (br = ret; br != NULL; br = regnext(g, br))
-+ regoptail(g, br, ender);
-+
-+ /* Check for proper termination. */
-+ if (paren && *g->regparse++ != ')') {
-+ FAIL("unmatched ()");
-+ } else if (!paren && *g->regparse != '\0') {
-+ if (*g->regparse == ')') {
-+ FAIL("unmatched ()");
-+ } else
-+ FAIL("junk on end"); /* "Can't happen". */
-+ /* NOTREACHED */
-+ }
-+
-+ return(ret);
-+}
-+
-+/*
-+ - regbranch - one alternative of an | operator
-+ *
-+ * Implements the concatenation operator.
-+ */
-+static char *
-+regbranch(struct match_globals *g, int *flagp)
-+{
-+ register char *ret;
-+ register char *chain;
-+ register char *latest;
-+ int flags;
-+
-+ *flagp = WORST; /* Tentatively. */
-+
-+ ret = regnode(g, BRANCH);
-+ chain = NULL;
-+ while (*g->regparse != '\0' && *g->regparse != '|' && *g->regparse != ')') {
-+ latest = regpiece(g, &flags);
-+ if (latest == NULL)
-+ return(NULL);
-+ *flagp |= flags&HASWIDTH;
-+ if (chain == NULL) /* First piece. */
-+ *flagp |= flags&SPSTART;
-+ else
-+ regtail(g, chain, latest);
-+ chain = latest;
-+ }
-+ if (chain == NULL) /* Loop ran zero times. */
-+ (void) regnode(g, NOTHING);
-+
-+ return(ret);
-+}
-+
-+/*
-+ - regpiece - something followed by possible [*+?]
-+ *
-+ * Note that the branching code sequences used for ? and the general cases
-+ * of * and + are somewhat optimized: they use the same NOTHING node as
-+ * both the endmarker for their branch list and the body of the last branch.
-+ * It might seem that this node could be dispensed with entirely, but the
-+ * endmarker role is not redundant.
-+ */
-+static char *
-+regpiece(struct match_globals *g, int *flagp)
-+{
-+ register char *ret;
-+ register char op;
-+ register char *next;
-+ int flags;
-+
-+ ret = regatom(g, &flags);
-+ if (ret == NULL)
-+ return(NULL);
-+
-+ op = *g->regparse;
-+ if (!ISMULT(op)) {
-+ *flagp = flags;
-+ return(ret);
-+ }
-+
-+ if (!(flags&HASWIDTH) && op != '?')
-+ FAIL("*+ operand could be empty");
-+ *flagp = (op != '+') ? (WORST|SPSTART) : (WORST|HASWIDTH);
-+
-+ if (op == '*' && (flags&SIMPLE))
-+ reginsert(g, STAR, ret);
-+ else if (op == '*') {
-+ /* Emit x* as (x&|), where & means "self". */
-+ reginsert(g, BRANCH, ret); /* Either x */
-+ regoptail(g, ret, regnode(g, BACK)); /* and loop */
-+ regoptail(g, ret, ret); /* back */
-+ regtail(g, ret, regnode(g, BRANCH)); /* or */
-+ regtail(g, ret, regnode(g, NOTHING)); /* null. */
-+ } else if (op == '+' && (flags&SIMPLE))
-+ reginsert(g, PLUS, ret);
-+ else if (op == '+') {
-+ /* Emit x+ as x(&|), where & means "self". */
-+ next = regnode(g, BRANCH); /* Either */
-+ regtail(g, ret, next);
-+ regtail(g, regnode(g, BACK), ret); /* loop back */
-+ regtail(g, next, regnode(g, BRANCH)); /* or */
-+ regtail(g, ret, regnode(g, NOTHING)); /* null. */
-+ } else if (op == '?') {
-+ /* Emit x? as (x|) */
-+ reginsert(g, BRANCH, ret); /* Either x */
-+ regtail(g, ret, regnode(g, BRANCH)); /* or */
-+ next = regnode(g, NOTHING); /* null. */
-+ regtail(g, ret, next);
-+ regoptail(g, ret, next);
-+ }
-+ g->regparse++;
-+ if (ISMULT(*g->regparse))
-+ FAIL("nested *?+");
-+
-+ return(ret);
-+}
-+
-+/*
-+ - regatom - the lowest level
-+ *
-+ * Optimization: gobbles an entire sequence of ordinary characters so that
-+ * it can turn them into a single node, which is smaller to store and
-+ * faster to run. Backslashed characters are exceptions, each becoming a
-+ * separate node; the code is simpler that way and it's not worth fixing.
-+ */
-+static char *
-+regatom(struct match_globals *g, int *flagp)
-+{
-+ register char *ret;
-+ int flags;
-+
-+ *flagp = WORST; /* Tentatively. */
-+
-+ switch (*g->regparse++) {
-+ case '^':
-+ ret = regnode(g, BOL);
-+ break;
-+ case '$':
-+ ret = regnode(g, EOL);
-+ break;
-+ case '.':
-+ ret = regnode(g, ANY);
-+ *flagp |= HASWIDTH|SIMPLE;
-+ break;
-+ case '[': {
-+ register int class;
-+ register int classend;
-+
-+ if (*g->regparse == '^') { /* Complement of range. */
-+ ret = regnode(g, ANYBUT);
-+ g->regparse++;
-+ } else
-+ ret = regnode(g, ANYOF);
-+ if (*g->regparse == ']' || *g->regparse == '-')
-+ regc(g, *g->regparse++);
-+ while (*g->regparse != '\0' && *g->regparse != ']') {
-+ if (*g->regparse == '-') {
-+ g->regparse++;
-+ if (*g->regparse == ']' || *g->regparse == '\0')
-+ regc(g, '-');
-+ else {
-+ class = UCHARAT(g->regparse-2)+1;
-+ classend = UCHARAT(g->regparse);
-+ if (class > classend+1)
-+ FAIL("invalid [] range");
-+ for (; class <= classend; class++)
-+ regc(g, class);
-+ g->regparse++;
-+ }
-+ } else
-+ regc(g, *g->regparse++);
-+ }
-+ regc(g, '\0');
-+ if (*g->regparse != ']')
-+ FAIL("unmatched []");
-+ g->regparse++;
-+ *flagp |= HASWIDTH|SIMPLE;
-+ }
-+ break;
-+ case '(':
-+ ret = reg(g, 1, &flags);
-+ if (ret == NULL)
-+ return(NULL);
-+ *flagp |= flags&(HASWIDTH|SPSTART);
-+ break;
-+ case '\0':
-+ case '|':
-+ case ')':
-+ FAIL("internal urp"); /* Supposed to be caught earlier. */
-+ break;
-+ case '?':
-+ case '+':
-+ case '*':
-+ FAIL("?+* follows nothing");
-+ break;
-+ case '\\':
-+ if (*g->regparse == '\0')
-+ FAIL("trailing \\");
-+ ret = regnode(g, EXACTLY);
-+ regc(g, *g->regparse++);
-+ regc(g, '\0');
-+ *flagp |= HASWIDTH|SIMPLE;
-+ break;
-+ default: {
-+ register int len;
-+ register char ender;
-+
-+ g->regparse--;
-+ len = my_strcspn((const char *)g->regparse, (const char *)META);
-+ if (len <= 0)
-+ FAIL("internal disaster");
-+ ender = *(g->regparse+len);
-+ if (len > 1 && ISMULT(ender))
-+ len--; /* Back off clear of ?+* operand. */
-+ *flagp |= HASWIDTH;
-+ if (len == 1)
-+ *flagp |= SIMPLE;
-+ ret = regnode(g, EXACTLY);
-+ while (len > 0) {
-+ regc(g, *g->regparse++);
-+ len--;
-+ }
-+ regc(g, '\0');
-+ }
-+ break;
-+ }
-+
-+ return(ret);
-+}
-+
-+/*
-+ - regnode - emit a node
-+ */
-+static char * /* Location. */
-+regnode(struct match_globals *g, char op)
-+{
-+ register char *ret;
-+ register char *ptr;
-+
-+ ret = g->regcode;
-+ if (ret == &g->regdummy) {
-+ g->regsize += 3;
-+ return(ret);
-+ }
-+
-+ ptr = ret;
-+ *ptr++ = op;
-+ *ptr++ = '\0'; /* Null "next" pointer. */
-+ *ptr++ = '\0';
-+ g->regcode = ptr;
-+
-+ return(ret);
-+}
-+
-+/*
-+ - regc - emit (if appropriate) a byte of code
-+ */
-+static void
-+regc(struct match_globals *g, char b)
-+{
-+ if (g->regcode != &g->regdummy)
-+ *g->regcode++ = b;
-+ else
-+ g->regsize++;
-+}
-+
-+/*
-+ - reginsert - insert an operator in front of already-emitted operand
-+ *
-+ * Means relocating the operand.
-+ */
-+static void
-+reginsert(struct match_globals *g, char op, char* opnd)
-+{
-+ register char *src;
-+ register char *dst;
-+ register char *place;
-+
-+ if (g->regcode == &g->regdummy) {
-+ g->regsize += 3;
-+ return;
-+ }
-+
-+ src = g->regcode;
-+ g->regcode += 3;
-+ dst = g->regcode;
-+ while (src > opnd)
-+ *--dst = *--src;
-+
-+ place = opnd; /* Op node, where operand used to be. */
-+ *place++ = op;
-+ *place++ = '\0';
-+ *place++ = '\0';
-+}
-+
-+/*
-+ - regtail - set the next-pointer at the end of a node chain
-+ */
-+static void
-+regtail(struct match_globals *g, char *p, char *val)
-+{
-+ register char *scan;
-+ register char *temp;
-+ register int offset;
-+
-+ if (p == &g->regdummy)
-+ return;
-+
-+ /* Find last node. */
-+ scan = p;
-+ for (;;) {
-+ temp = regnext(g, scan);
-+ if (temp == NULL)
-+ break;
-+ scan = temp;
-+ }
-+
-+ if (OP(scan) == BACK)
-+ offset = scan - val;
-+ else
-+ offset = val - scan;
-+ *(scan+1) = (offset>>8)&0377;
-+ *(scan+2) = offset&0377;
-+}
-+
-+/*
-+ - regoptail - regtail on operand of first argument; nop if operandless
-+ */
-+static void
-+regoptail(struct match_globals *g, char *p, char *val)
-+{
-+ /* "Operandless" and "op != BRANCH" are synonymous in practice. */
-+ if (p == NULL || p == &g->regdummy || OP(p) != BRANCH)
-+ return;
-+ regtail(g, OPERAND(p), val);
-+}
-+
-+/*
-+ * regexec and friends
-+ */
-+
-+
-+/*
-+ * Forwards.
-+ */
-+STATIC int regtry(struct match_globals *g, regexp *prog, char *string);
-+STATIC int regmatch(struct match_globals *g, char *prog);
-+STATIC int regrepeat(struct match_globals *g, char *p);
-+
-+#ifdef DEBUG
-+int regnarrate = 0;
-+void regdump();
-+STATIC char *regprop(char *op);
-+#endif
-+
-+/*
-+ - regexec - match a regexp against a string
-+ */
-+int
-+regexec(regexp *prog, char *string)
-+{
-+ register char *s;
-+ struct match_globals g;
-+
-+ /* Be paranoid... */
-+ if (prog == NULL || string == NULL) {
-+ printk("<3>Regexp: NULL parameter\n");
-+ return(0);
-+ }
-+
-+ /* Check validity of program. */
-+ if (UCHARAT(prog->program) != MAGIC) {
-+ printk("<3>Regexp: corrupted program\n");
-+ return(0);
-+ }
-+
-+ /* If there is a "must appear" string, look for it. */
-+ if (prog->regmust != NULL) {
-+ s = string;
-+ while ((s = strchr(s, prog->regmust[0])) != NULL) {
-+ if (strncmp(s, prog->regmust, prog->regmlen) == 0)
-+ break; /* Found it. */
-+ s++;
-+ }
-+ if (s == NULL) /* Not present. */
-+ return(0);
-+ }
-+
-+ /* Mark beginning of line for ^ . */
-+ g.regbol = string;
-+
-+ /* Simplest case: anchored match need be tried only once. */
-+ if (prog->reganch)
-+ return(regtry(&g, prog, string));
-+
-+ /* Messy cases: unanchored match. */
-+ s = string;
-+ if (prog->regstart != '\0')
-+ /* We know what char it must start with. */
-+ while ((s = strchr(s, prog->regstart)) != NULL) {
-+ if (regtry(&g, prog, s))
-+ return(1);
-+ s++;
-+ }
-+ else
-+ /* We don't -- general case. */
-+ do {
-+ if (regtry(&g, prog, s))
-+ return(1);
-+ } while (*s++ != '\0');
-+
-+ /* Failure. */
-+ return(0);
-+}
-+
-+/*
-+ - regtry - try match at specific point
-+ */
-+static int /* 0 failure, 1 success */
-+regtry(struct match_globals *g, regexp *prog, char *string)
-+{
-+ register int i;
-+ register char **sp;
-+ register char **ep;
-+
-+ g->reginput = string;
-+ g->regstartp = prog->startp;
-+ g->regendp = prog->endp;
-+
-+ sp = prog->startp;
-+ ep = prog->endp;
-+ for (i = NSUBEXP; i > 0; i--) {
-+ *sp++ = NULL;
-+ *ep++ = NULL;
-+ }
-+ if (regmatch(g, prog->program + 1)) {
-+ prog->startp[0] = string;
-+ prog->endp[0] = g->reginput;
-+ return(1);
-+ } else
-+ return(0);
-+}
-+
-+/*
-+ - regmatch - main matching routine
-+ *
-+ * Conceptually the strategy is simple: check to see whether the current
-+ * node matches, call self recursively to see whether the rest matches,
-+ * and then act accordingly. In practice we make some effort to avoid
-+ * recursion, in particular by going through "ordinary" nodes (that don't
-+ * need to know whether the rest of the match failed) by a loop instead of
-+ * by recursion.
-+ */
-+static int /* 0 failure, 1 success */
-+regmatch(struct match_globals *g, char *prog)
-+{
-+ register char *scan = prog; /* Current node. */
-+ char *next; /* Next node. */
-+
-+#ifdef DEBUG
-+ if (scan != NULL && regnarrate)
-+ fprintf(stderr, "%s(\n", regprop(scan));
-+#endif
-+ while (scan != NULL) {
-+#ifdef DEBUG
-+ if (regnarrate)
-+ fprintf(stderr, "%s...\n", regprop(scan));
-+#endif
-+ next = regnext(g, scan);
-+
-+ switch (OP(scan)) {
-+ case BOL:
-+ if (g->reginput != g->regbol)
-+ return(0);
-+ break;
-+ case EOL:
-+ if (*g->reginput != '\0')
-+ return(0);
-+ break;
-+ case ANY:
-+ if (*g->reginput == '\0')
-+ return(0);
-+ g->reginput++;
-+ break;
-+ case EXACTLY: {
-+ register int len;
-+ register char *opnd;
-+
-+ opnd = OPERAND(scan);
-+ /* Inline the first character, for speed. */
-+ if (*opnd != *g->reginput)
-+ return(0);
-+ len = strlen(opnd);
-+ if (len > 1 && strncmp(opnd, g->reginput, len) != 0)
-+ return(0);
-+ g->reginput += len;
-+ }
-+ break;
-+ case ANYOF:
-+ if (*g->reginput == '\0' || strchr(OPERAND(scan), *g->reginput) == NULL)
-+ return(0);
-+ g->reginput++;
-+ break;
-+ case ANYBUT:
-+ if (*g->reginput == '\0' || strchr(OPERAND(scan), *g->reginput) != NULL)
-+ return(0);
-+ g->reginput++;
-+ break;
-+ case NOTHING:
-+ case BACK:
-+ break;
-+ case OPEN+1:
-+ case OPEN+2:
-+ case OPEN+3:
-+ case OPEN+4:
-+ case OPEN+5:
-+ case OPEN+6:
-+ case OPEN+7:
-+ case OPEN+8:
-+ case OPEN+9: {
-+ register int no;
-+ register char *save;
-+
-+ no = OP(scan) - OPEN;
-+ save = g->reginput;
-+
-+ if (regmatch(g, next)) {
-+ /*
-+ * Don't set startp if some later
-+ * invocation of the same parentheses
-+ * already has.
-+ */
-+ if (g->regstartp[no] == NULL)
-+ g->regstartp[no] = save;
-+ return(1);
-+ } else
-+ return(0);
-+ }
-+ break;
-+ case CLOSE+1:
-+ case CLOSE+2:
-+ case CLOSE+3:
-+ case CLOSE+4:
-+ case CLOSE+5:
-+ case CLOSE+6:
-+ case CLOSE+7:
-+ case CLOSE+8:
-+ case CLOSE+9:
-+ {
-+ register int no;
-+ register char *save;
-+
-+ no = OP(scan) - CLOSE;
-+ save = g->reginput;
-+
-+ if (regmatch(g, next)) {
-+ /*
-+ * Don't set endp if some later
-+ * invocation of the same parentheses
-+ * already has.
-+ */
-+ if (g->regendp[no] == NULL)
-+ g->regendp[no] = save;
-+ return(1);
-+ } else
-+ return(0);
-+ }
-+ break;
-+ case BRANCH: {
-+ register char *save;
-+
-+ if (OP(next) != BRANCH) /* No choice. */
-+ next = OPERAND(scan); /* Avoid recursion. */
-+ else {
-+ do {
-+ save = g->reginput;
-+ if (regmatch(g, OPERAND(scan)))
-+ return(1);
-+ g->reginput = save;
-+ scan = regnext(g, scan);
-+ } while (scan != NULL && OP(scan) == BRANCH);
-+ return(0);
-+ /* NOTREACHED */
-+ }
-+ }
-+ break;
-+ case STAR:
-+ case PLUS: {
-+ register char nextch;
-+ register int no;
-+ register char *save;
-+ register int min;
-+
-+ /*
-+ * Lookahead to avoid useless match attempts
-+ * when we know what character comes next.
-+ */
-+ nextch = '\0';
-+ if (OP(next) == EXACTLY)
-+ nextch = *OPERAND(next);
-+ min = (OP(scan) == STAR) ? 0 : 1;
-+ save = g->reginput;
-+ no = regrepeat(g, OPERAND(scan));
-+ while (no >= min) {
-+ /* If it could work, try it. */
-+ if (nextch == '\0' || *g->reginput == nextch)
-+ if (regmatch(g, next))
-+ return(1);
-+ /* Couldn't or didn't -- back up. */
-+ no--;
-+ g->reginput = save + no;
-+ }
-+ return(0);
-+ }
-+ break;
-+ case END:
-+ return(1); /* Success! */
-+ break;
-+ default:
-+ printk("<3>Regexp: memory corruption\n");
-+ return(0);
-+ break;
-+ }
-+
-+ scan = next;
-+ }
-+
-+ /*
-+ * We get here only if there's trouble -- normally "case END" is
-+ * the terminating point.
-+ */
-+ printk("<3>Regexp: corrupted pointers\n");
-+ return(0);
-+}
-+
-+/*
-+ - regrepeat - repeatedly match something simple, report how many
-+ */
-+static int
-+regrepeat(struct match_globals *g, char *p)
-+{
-+ register int count = 0;
-+ register char *scan;
-+ register char *opnd;
-+
-+ scan = g->reginput;
-+ opnd = OPERAND(p);
-+ switch (OP(p)) {
-+ case ANY:
-+ count = strlen(scan);
-+ scan += count;
-+ break;
-+ case EXACTLY:
-+ while (*opnd == *scan) {
-+ count++;
-+ scan++;
-+ }
-+ break;
-+ case ANYOF:
-+ while (*scan != '\0' && strchr(opnd, *scan) != NULL) {
-+ count++;
-+ scan++;
-+ }
-+ break;
-+ case ANYBUT:
-+ while (*scan != '\0' && strchr(opnd, *scan) == NULL) {
-+ count++;
-+ scan++;
-+ }
-+ break;
-+ default: /* Oh dear. Called inappropriately. */
-+ printk("<3>Regexp: internal foulup\n");
-+ count = 0; /* Best compromise. */
-+ break;
-+ }
-+ g->reginput = scan;
-+
-+ return(count);
-+}
-+
-+/*
-+ - regnext - dig the "next" pointer out of a node
-+ */
-+static char*
-+regnext(struct match_globals *g, char *p)
-+{
-+ register int offset;
-+
-+ if (p == &g->regdummy)
-+ return(NULL);
-+
-+ offset = NEXT(p);
-+ if (offset == 0)
-+ return(NULL);
-+
-+ if (OP(p) == BACK)
-+ return(p-offset);
-+ else
-+ return(p+offset);
-+}
-+
-+#ifdef DEBUG
-+
-+STATIC char *regprop();
-+
-+/*
-+ - regdump - dump a regexp onto stdout in vaguely comprehensible form
-+ */
-+void
-+regdump(regexp *r)
-+{
-+ register char *s;
-+ register char op = EXACTLY; /* Arbitrary non-END op. */
-+ register char *next;
-+ /* extern char *strchr(); */
-+
-+
-+ s = r->program + 1;
-+ while (op != END) { /* While that wasn't END last time... */
-+ op = OP(s);
-+ printf("%2d%s", s-r->program, regprop(s)); /* Where, what. */
-+ next = regnext(s);
-+ if (next == NULL) /* Next ptr. */
-+ printf("(0)");
-+ else
-+ printf("(%d)", (s-r->program)+(next-s));
-+ s += 3;
-+ if (op == ANYOF || op == ANYBUT || op == EXACTLY) {
-+ /* Literal string, where present. */
-+ while (*s != '\0') {
-+ putchar(*s);
-+ s++;
-+ }
-+ s++;
-+ }
-+ putchar('\n');
-+ }
-+
-+ /* Header fields of interest. */
-+ if (r->regstart != '\0')
-+ printf("start `%c' ", r->regstart);
-+ if (r->reganch)
-+ printf("anchored ");
-+ if (r->regmust != NULL)
-+ printf("must have \"%s\"", r->regmust);
-+ printf("\n");
-+}
-+
-+/*
-+ - regprop - printable representation of opcode
-+ */
-+static char *
-+regprop(char *op)
-+{
-+#define BUFLEN 50
-+ register char *p;
-+ static char buf[BUFLEN];
-+
-+ strcpy(buf, ":");
-+
-+ switch (OP(op)) {
-+ case BOL:
-+ p = "BOL";
-+ break;
-+ case EOL:
-+ p = "EOL";
-+ break;
-+ case ANY:
-+ p = "ANY";
-+ break;
-+ case ANYOF:
-+ p = "ANYOF";
-+ break;
-+ case ANYBUT:
-+ p = "ANYBUT";
-+ break;
-+ case BRANCH:
-+ p = "BRANCH";
-+ break;
-+ case EXACTLY:
-+ p = "EXACTLY";
-+ break;
-+ case NOTHING:
-+ p = "NOTHING";
-+ break;
-+ case BACK:
-+ p = "BACK";
-+ break;
-+ case END:
-+ p = "END";
-+ break;
-+ case OPEN+1:
-+ case OPEN+2:
-+ case OPEN+3:
-+ case OPEN+4:
-+ case OPEN+5:
-+ case OPEN+6:
-+ case OPEN+7:
-+ case OPEN+8:
-+ case OPEN+9:
-+ snprintf(buf+strlen(buf),BUFLEN-strlen(buf), "OPEN%d", OP(op)-OPEN);
-+ p = NULL;
-+ break;
-+ case CLOSE+1:
-+ case CLOSE+2:
-+ case CLOSE+3:
-+ case CLOSE+4:
-+ case CLOSE+5:
-+ case CLOSE+6:
-+ case CLOSE+7:
-+ case CLOSE+8:
-+ case CLOSE+9:
-+ snprintf(buf+strlen(buf),BUFLEN-strlen(buf), "CLOSE%d", OP(op)-CLOSE);
-+ p = NULL;
-+ break;
-+ case STAR:
-+ p = "STAR";
-+ break;
-+ case PLUS:
-+ p = "PLUS";
-+ break;
-+ default:
-+ printk("<3>Regexp: corrupted opcode\n");
-+ break;
-+ }
-+ if (p != NULL)
-+ strncat(buf, p, BUFLEN-strlen(buf));
-+ return(buf);
-+}
-+#endif
-+
-+
-Index: linux-2.6.21.7/net/netfilter/regexp/regexp.h
-===================================================================
---- /dev/null
-+++ linux-2.6.21.7/net/netfilter/regexp/regexp.h
-@@ -0,0 +1,41 @@
-+/*
-+ * Definitions etc. for regexp(3) routines.
-+ *
-+ * Caveat: this is V8 regexp(3) [actually, a reimplementation thereof],
-+ * not the System V one.
-+ */
-+
-+#ifndef REGEXP_H
-+#define REGEXP_H
-+
-+
-+/*
-+http://www.opensource.apple.com/darwinsource/10.3/expect-1/expect/expect.h ,
-+which contains a version of this library, says:
-+
-+ *
-+ * NSUBEXP must be at least 10, and no greater than 117 or the parser
-+ * will not work properly.
-+ *
-+
-+However, it looks rather like this library is limited to 10. If you think
-+otherwise, let us know.
-+*/
-+
-+#define NSUBEXP 10
-+typedef struct regexp {
-+ char *startp[NSUBEXP];
-+ char *endp[NSUBEXP];
-+ char regstart; /* Internal use only. */
-+ char reganch; /* Internal use only. */
-+ char *regmust; /* Internal use only. */
-+ int regmlen; /* Internal use only. */
-+ char program[1]; /* Unwarranted chumminess with compiler. */
-+} regexp;
-+
-+regexp * regcomp(char *exp, int *patternsize);
-+int regexec(regexp *prog, char *string);
-+void regsub(regexp *prog, char *source, char *dest);
-+void regerror(char *s);
-+
-+#endif
-Index: linux-2.6.21.7/net/netfilter/regexp/regmagic.h
-===================================================================
---- /dev/null
-+++ linux-2.6.21.7/net/netfilter/regexp/regmagic.h
-@@ -0,0 +1,5 @@
-+/*
-+ * The first byte of the regexp internal "program" is actually this magic
-+ * number; the start node begins in the second byte.
-+ */
-+#define MAGIC 0234
-Index: linux-2.6.21.7/net/netfilter/regexp/regsub.c
-===================================================================
---- /dev/null
-+++ linux-2.6.21.7/net/netfilter/regexp/regsub.c
-@@ -0,0 +1,95 @@
-+/*
-+ * regsub
-+ * @(#)regsub.c 1.3 of 2 April 86
-+ *
-+ * Copyright (c) 1986 by University of Toronto.
-+ * Written by Henry Spencer. Not derived from licensed software.
-+ *
-+ * Permission is granted to anyone to use this software for any
-+ * purpose on any computer system, and to redistribute it freely,
-+ * subject to the following restrictions:
-+ *
-+ * 1. The author is not responsible for the consequences of use of
-+ * this software, no matter how awful, even if they arise
-+ * from defects in it.
-+ *
-+ * 2. The origin of this software must not be misrepresented, either
-+ * by explicit claim or by omission.
-+ *
-+ * 3. Altered versions must be plainly marked as such, and must not
-+ * be misrepresented as being the original software.
-+ *
-+ *
-+ * This code was modified by Ethan Sommer to work within the kernel
-+ * (it now uses kmalloc etc..)
-+ *
-+ */
-+#include "regexp.h"
-+#include "regmagic.h"
-+#include <linux/string.h>
-+
-+
-+#ifndef CHARBITS
-+#define UCHARAT(p) ((int)*(unsigned char *)(p))
-+#else
-+#define UCHARAT(p) ((int)*(p)&CHARBITS)
-+#endif
-+
-+#if 0
-+//void regerror(char * s)
-+//{
-+// printk("regexp(3): %s", s);
-+// /* NOTREACHED */
-+//}
-+#endif
-+
-+/*
-+ - regsub - perform substitutions after a regexp match
-+ */
-+void
-+regsub(regexp * prog, char * source, char * dest)
-+{
-+ register char *src;
-+ register char *dst;
-+ register char c;
-+ register int no;
-+ register int len;
-+
-+ /* Not necessary and gcc doesn't like it -MLS */
-+ /*extern char *strncpy();*/
-+
-+ if (prog == NULL || source == NULL || dest == NULL) {
-+ regerror("NULL parm to regsub");
-+ return;
-+ }
-+ if (UCHARAT(prog->program) != MAGIC) {
-+ regerror("damaged regexp fed to regsub");
-+ return;
-+ }
-+
-+ src = source;
-+ dst = dest;
-+ while ((c = *src++) != '\0') {
-+ if (c == '&')
-+ no = 0;
-+ else if (c == '\\' && '0' <= *src && *src <= '9')
-+ no = *src++ - '0';
-+ else
-+ no = -1;
-+
-+ if (no < 0) { /* Ordinary character. */
-+ if (c == '\\' && (*src == '\\' || *src == '&'))
-+ c = *src++;
-+ *dst++ = c;
-+ } else if (prog->startp[no] != NULL && prog->endp[no] != NULL) {
-+ len = prog->endp[no] - prog->startp[no];
-+ (void) strncpy(dst, prog->startp[no], len);
-+ dst += len;
-+ if (len != 0 && *(dst-1) == '\0') { /* strncpy hit NUL. */
-+ regerror("damaged match string");
-+ return;
-+ }
-+ }
-+ }
-+ *dst++ = '\0';
-+}
-Index: linux-2.6.21.7/net/netfilter/nf_conntrack_core.c
-===================================================================
---- linux-2.6.21.7.orig/net/netfilter/nf_conntrack_core.c
-+++ linux-2.6.21.7/net/netfilter/nf_conntrack_core.c
-@@ -352,6 +352,14 @@ destroy_conntrack(struct nf_conntrack *n
- * too. */
- nf_ct_remove_expectations(ct);
-
-+ #if defined(CONFIG_NETFILTER_XT_MATCH_LAYER7) || defined(CONFIG_NETFILTER_XT_MATCH_LAYER7_MODULE)
-+ if(ct->layer7.app_proto)
-+ kfree(ct->layer7.app_proto);
-+ if(ct->layer7.app_data)
-+ kfree(ct->layer7.app_data);
-+ #endif
-+
-+
- /* We overload first tuple to link into unconfirmed list. */
- if (!nf_ct_is_confirmed(ct)) {
- BUG_ON(list_empty(&ct->tuplehash[IP_CT_DIR_ORIGINAL].list));
-Index: linux-2.6.21.7/net/netfilter/nf_conntrack_standalone.c
-===================================================================
---- linux-2.6.21.7.orig/net/netfilter/nf_conntrack_standalone.c
-+++ linux-2.6.21.7/net/netfilter/nf_conntrack_standalone.c
-@@ -195,7 +195,12 @@ static int ct_seq_show(struct seq_file *
- return -ENOSPC;
- #endif
-
-- if (seq_printf(s, "use=%u\n", atomic_read(&conntrack->ct_general.use)))
-+#if defined(CONFIG_NETFILTER_XT_MATCH_LAYER7) || defined(CONFIG_NETFILTER_XT_MATCH_LAYER7_MODULE)
-+ if(conntrack->layer7.app_proto)
-+ if(seq_printf(s, "l7proto=%s ", conntrack->layer7.app_proto))
-+ return -ENOSPC;
-+#endif
-+ if (seq_printf(s, "asdfuse=%u\n", atomic_read(&conntrack->ct_general.use)))
- return -ENOSPC;
-
- return 0;
-Index: linux-2.6.21.7/include/net/netfilter/nf_conntrack.h
-===================================================================
---- linux-2.6.21.7.orig/include/net/netfilter/nf_conntrack.h
-+++ linux-2.6.21.7/include/net/netfilter/nf_conntrack.h
-@@ -128,6 +128,22 @@ struct nf_conn
- u_int32_t secmark;
- #endif
-
-+#if defined(CONFIG_NETFILTER_XT_MATCH_LAYER7) || \
-+ defined(CONFIG_NETFILTER_XT_MATCH_LAYER7_MODULE)
-+ struct {
-+ /*
-+ * e.g. "http". NULL before decision. "unknown" after decision
-+ * if no match.
-+ */
-+ char *app_proto;
-+ /*
-+ * application layer data so far. NULL after match decision.
-+ */
-+ char *app_data;
-+ unsigned int app_data_len;
-+ } layer7;
-+#endif
-+
- /* Storage reserved for other modules: */
- union nf_conntrack_proto proto;
-
-Index: linux-2.6.21.7/include/linux/netfilter/xt_layer7.h
-===================================================================
---- /dev/null
-+++ linux-2.6.21.7/include/linux/netfilter/xt_layer7.h
-@@ -0,0 +1,13 @@
-+#ifndef _XT_LAYER7_H
-+#define _XT_LAYER7_H
-+
-+#define MAX_PATTERN_LEN 8192
-+#define MAX_PROTOCOL_LEN 256
-+
-+struct xt_layer7_info {
-+ char protocol[MAX_PROTOCOL_LEN];
-+ char pattern[MAX_PATTERN_LEN];
-+ u_int8_t invert;
-+};
-+
-+#endif /* _XT_LAYER7_H */
+++ /dev/null
-Index: linux-2.6.21.7/include/linux/netfilter/xt_layer7.h
-===================================================================
---- linux-2.6.21.7.orig/include/linux/netfilter/xt_layer7.h
-+++ linux-2.6.21.7/include/linux/netfilter/xt_layer7.h
-@@ -8,6 +8,7 @@ struct xt_layer7_info {
- char protocol[MAX_PROTOCOL_LEN];
- char pattern[MAX_PATTERN_LEN];
- u_int8_t invert;
-+ u_int8_t pkt;
- };
-
- #endif /* _XT_LAYER7_H */
-Index: linux-2.6.21.7/net/netfilter/xt_layer7.c
-===================================================================
---- linux-2.6.21.7.orig/net/netfilter/xt_layer7.c
-+++ linux-2.6.21.7/net/netfilter/xt_layer7.c
-@@ -297,34 +297,36 @@ static int match_no_append(struct nf_con
- }
-
- /* add the new app data to the conntrack. Return number of bytes added. */
--static int add_data(struct nf_conn * master_conntrack,
-- char * app_data, int appdatalen)
-+static int add_datastr(char *target, int offset, char *app_data, int len)
- {
- int length = 0, i;
-- int oldlength = master_conntrack->layer7.app_data_len;
--
-- /* This is a fix for a race condition by Deti Fliegl. However, I'm not
-- clear on whether the race condition exists or whether this really
-- fixes it. I might just be being dense... Anyway, if it's not really
-- a fix, all it does is waste a very small amount of time. */
-- if(!master_conntrack->layer7.app_data) return 0;
-+
-+ if (!target) return 0;
-
- /* Strip nulls. Make everything lower case (our regex lib doesn't
- do case insensitivity). Add it to the end of the current data. */
-- for(i = 0; i < maxdatalen-oldlength-1 &&
-- i < appdatalen; i++) {
-+ for(i = 0; i < maxdatalen-offset-1 && i < len; i++) {
- if(app_data[i] != '\0') {
- /* the kernel version of tolower mungs 'upper ascii' */
-- master_conntrack->layer7.app_data[length+oldlength] =
-+ target[length+offset] =
- isascii(app_data[i])?
- tolower(app_data[i]) : app_data[i];
- length++;
- }
- }
-+ target[length+offset] = '\0';
-+
-+ return length;
-+}
-
-- master_conntrack->layer7.app_data[length+oldlength] = '\0';
-- master_conntrack->layer7.app_data_len = length + oldlength;
-+/* add the new app data to the conntrack. Return number of bytes added. */
-+static int add_data(struct nf_conn * master_conntrack,
-+ char * app_data, int appdatalen)
-+{
-+ int length;
-
-+ length = add_datastr(master_conntrack->layer7.app_data, master_conntrack->layer7.app_data_len, app_data, appdatalen);
-+ master_conntrack->layer7.app_data_len += length;
- return length;
- }
-
-@@ -411,7 +413,7 @@ match(const struct sk_buff *skbin,
- const struct xt_layer7_info * info = matchinfo;
- enum ip_conntrack_info master_ctinfo, ctinfo;
- struct nf_conn *master_conntrack, *conntrack;
-- unsigned char * app_data;
-+ unsigned char *app_data, *tmp_data;
- unsigned int pattern_result, appdatalen;
- regexp * comppattern;
-
-@@ -439,8 +441,8 @@ match(const struct sk_buff *skbin,
- master_conntrack = master_ct(master_conntrack);
-
- /* if we've classified it or seen too many packets */
-- if(TOTAL_PACKETS > num_packets ||
-- master_conntrack->layer7.app_proto) {
-+ if(!info->pkt && (TOTAL_PACKETS > num_packets ||
-+ master_conntrack->layer7.app_proto)) {
-
- pattern_result = match_no_append(conntrack, master_conntrack,
- ctinfo, master_ctinfo, info);
-@@ -473,6 +475,25 @@ match(const struct sk_buff *skbin,
- /* the return value gets checked later, when we're ready to use it */
- comppattern = compile_and_cache(info->pattern, info->protocol);
-
-+ if (info->pkt) {
-+ tmp_data = kmalloc(maxdatalen, GFP_ATOMIC);
-+ if(!tmp_data){
-+ if (net_ratelimit())
-+ printk(KERN_ERR "layer7: out of memory in match, bailing.\n");
-+ return info->invert;
-+ }
-+
-+ tmp_data[0] = '\0';
-+ add_datastr(tmp_data, 0, app_data, appdatalen);
-+ pattern_result = ((comppattern && regexec(comppattern, tmp_data)) ? 1 : 0);
-+
-+ kfree(tmp_data);
-+ tmp_data = NULL;
-+ spin_unlock_bh(&l7_lock);
-+
-+ return (pattern_result ^ info->invert);
-+ }
-+
- /* On the first packet of a connection, allocate space for app data */
- if(TOTAL_PACKETS == 1 && !skb->cb[0] &&
- !master_conntrack->layer7.app_data){
+++ /dev/null
-Index: linux-2.6.21.7/include/linux/netfilter_ipv4/ipt_ipp2p.h
-===================================================================
---- /dev/null
-+++ linux-2.6.21.7/include/linux/netfilter_ipv4/ipt_ipp2p.h
-@@ -0,0 +1,31 @@
-+#ifndef __IPT_IPP2P_H
-+#define __IPT_IPP2P_H
-+#define IPP2P_VERSION "0.8.1_rc1"
-+
-+struct ipt_p2p_info {
-+ int cmd;
-+ int debug;
-+};
-+
-+#endif //__IPT_IPP2P_H
-+
-+#define SHORT_HAND_IPP2P 1 /* --ipp2p switch*/
-+//#define SHORT_HAND_DATA 4 /* --ipp2p-data switch*/
-+#define SHORT_HAND_NONE 5 /* no short hand*/
-+
-+#define IPP2P_EDK (1 << 1)
-+#define IPP2P_DATA_KAZAA (1 << 2)
-+#define IPP2P_DATA_EDK (1 << 3)
-+#define IPP2P_DATA_DC (1 << 4)
-+#define IPP2P_DC (1 << 5)
-+#define IPP2P_DATA_GNU (1 << 6)
-+#define IPP2P_GNU (1 << 7)
-+#define IPP2P_KAZAA (1 << 8)
-+#define IPP2P_BIT (1 << 9)
-+#define IPP2P_APPLE (1 << 10)
-+#define IPP2P_SOUL (1 << 11)
-+#define IPP2P_WINMX (1 << 12)
-+#define IPP2P_ARES (1 << 13)
-+#define IPP2P_MUTE (1 << 14)
-+#define IPP2P_WASTE (1 << 15)
-+#define IPP2P_XDCC (1 << 16)
-Index: linux-2.6.21.7/net/ipv4/netfilter/ipt_ipp2p.c
-===================================================================
---- /dev/null
-+++ linux-2.6.21.7/net/ipv4/netfilter/ipt_ipp2p.c
-@@ -0,0 +1,882 @@
-+#if defined(MODVERSIONS)
-+#include <linux/modversions.h>
-+#endif
-+#include <linux/module.h>
-+#include <linux/netfilter_ipv4/ip_tables.h>
-+#include <linux/version.h>
-+#include <linux/netfilter_ipv4/ipt_ipp2p.h>
-+#include <net/tcp.h>
-+#include <net/udp.h>
-+
-+#define get_u8(X,O) (*(__u8 *)(X + O))
-+#define get_u16(X,O) (*(__u16 *)(X + O))
-+#define get_u32(X,O) (*(__u32 *)(X + O))
-+
-+MODULE_AUTHOR("Eicke Friedrich/Klaus Degner <ipp2p@ipp2p.org>");
-+MODULE_DESCRIPTION("An extension to iptables to identify P2P traffic.");
-+MODULE_LICENSE("GPL");
-+
-+
-+/*Search for UDP eDonkey/eMule/Kad commands*/
-+int
-+udp_search_edk (unsigned char *haystack, int packet_len)
-+{
-+ unsigned char *t = haystack;
-+ t += 8;
-+
-+ switch (t[0]) {
-+ case 0xe3:
-+ { /*edonkey*/
-+ switch (t[1])
-+ {
-+ /* client -> server status request */
-+ case 0x96:
-+ if (packet_len == 14) return ((IPP2P_EDK * 100) + 50);
-+ break;
-+ /* server -> client status request */
-+ case 0x97: if (packet_len == 42) return ((IPP2P_EDK * 100) + 51);
-+ break;
-+ /* server description request */
-+ /* e3 2a ff f0 .. | size == 6 */
-+ case 0xa2: if ( (packet_len == 14) && ( get_u16(t,2) == __constant_htons(0xfff0) ) ) return ((IPP2P_EDK * 100) + 52);
-+ break;
-+ /* server description response */
-+ /* e3 a3 ff f0 .. | size > 40 && size < 200 */
-+ //case 0xa3: return ((IPP2P_EDK * 100) + 53);
-+ // break;
-+ case 0x9a: if (packet_len==26) return ((IPP2P_EDK * 100) + 54);
-+ break;
-+
-+ case 0x92: if (packet_len==18) return ((IPP2P_EDK * 100) + 55);
-+ break;
-+ }
-+ break;
-+ }
-+ case 0xe4:
-+ {
-+ switch (t[1])
-+ {
-+ /* e4 20 .. | size == 43 */
-+ case 0x20: if ((packet_len == 43) && (t[2] != 0x00) && (t[34] != 0x00)) return ((IPP2P_EDK * 100) + 60);
-+ break;
-+ /* e4 00 .. 00 | size == 35 ? */
-+ case 0x00: if ((packet_len == 35) && (t[26] == 0x00)) return ((IPP2P_EDK * 100) + 61);
-+ break;
-+ /* e4 10 .. 00 | size == 35 ? */
-+ case 0x10: if ((packet_len == 35) && (t[26] == 0x00)) return ((IPP2P_EDK * 100) + 62);
-+ break;
-+ /* e4 18 .. 00 | size == 35 ? */
-+ case 0x18: if ((packet_len == 35) && (t[26] == 0x00)) return ((IPP2P_EDK * 100) + 63);
-+ break;
-+ /* e4 52 .. | size = 44 */
-+ case 0x52: if (packet_len == 44 ) return ((IPP2P_EDK * 100) + 64);
-+ break;
-+ /* e4 58 .. | size == 6 */
-+ case 0x58: if (packet_len == 14 ) return ((IPP2P_EDK * 100) + 65);
-+ break;
-+ /* e4 59 .. | size == 2 */
-+ case 0x59: if (packet_len == 10 )return ((IPP2P_EDK * 100) + 66);
-+ break;
-+ /* e4 28 .. | packet_len == 52,77,102,127... */
-+ case 0x28: if (((packet_len-52) % 25) == 0) return ((IPP2P_EDK * 100) + 67);
-+ break;
-+ /* e4 50 xx xx | size == 4 */
-+ case 0x50: if (packet_len == 12) return ((IPP2P_EDK * 100) + 68);
-+ break;
-+ /* e4 40 xx xx | size == 48 */
-+ case 0x40: if (packet_len == 56) return ((IPP2P_EDK * 100) + 69);
-+ break;
-+ }
-+ break;
-+ }
-+ } /* end of switch (t[0]) */
-+ return 0;
-+}/*udp_search_edk*/
-+
-+
-+/*Search for UDP Gnutella commands*/
-+int
-+udp_search_gnu (unsigned char *haystack, int packet_len)
-+{
-+ unsigned char *t = haystack;
-+ t += 8;
-+
-+ if (memcmp(t, "GND", 3) == 0) return ((IPP2P_GNU * 100) + 51);
-+ if (memcmp(t, "GNUTELLA ", 9) == 0) return ((IPP2P_GNU * 100) + 52);
-+ return 0;
-+}/*udp_search_gnu*/
-+
-+
-+/*Search for UDP KaZaA commands*/
-+int
-+udp_search_kazaa (unsigned char *haystack, int packet_len)
-+{
-+ unsigned char *t = haystack;
-+
-+ if (t[packet_len-1] == 0x00){
-+ t += (packet_len - 6);
-+ if (memcmp(t, "KaZaA", 5) == 0) return (IPP2P_KAZAA * 100 +50);
-+ }
-+
-+ return 0;
-+}/*udp_search_kazaa*/
-+
-+/*Search for UDP DirectConnect commands*/
-+int
-+udp_search_directconnect (unsigned char *haystack, int packet_len)
-+{
-+ unsigned char *t = haystack;
-+ if ((*(t + 8) == 0x24) && (*(t + packet_len - 1) == 0x7c)) {
-+ t+=8;
-+ if (memcmp(t, "SR ", 3) == 0) return ((IPP2P_DC * 100) + 60);
-+ if (memcmp(t, "Ping ", 5) == 0) return ((IPP2P_DC * 100) + 61);
-+ }
-+ return 0;
-+}/*udp_search_directconnect*/
-+
-+
-+
-+/*Search for UDP BitTorrent commands*/
-+int
-+udp_search_bit (unsigned char *haystack, int packet_len)
-+{
-+ switch(packet_len)
-+ {
-+ case 24:
-+ /* ^ 00 00 04 17 27 10 19 80 */
-+ if ((ntohl(get_u32(haystack, 8)) == 0x00000417) && (ntohl(get_u32(haystack, 12)) == 0x27101980))
-+ return (IPP2P_BIT * 100 + 50);
-+ break;
-+ case 44:
-+ if (get_u32(haystack, 16) == __constant_htonl(0x00000400) && get_u32(haystack, 36) == __constant_htonl(0x00000104))
-+ return (IPP2P_BIT * 100 + 51);
-+ if (get_u32(haystack, 16) == __constant_htonl(0x00000400))
-+ return (IPP2P_BIT * 100 + 61);
-+ break;
-+ case 65:
-+ if (get_u32(haystack, 16) == __constant_htonl(0x00000404) && get_u32(haystack, 36) == __constant_htonl(0x00000104))
-+ return (IPP2P_BIT * 100 + 52);
-+ if (get_u32(haystack, 16) == __constant_htonl(0x00000404))
-+ return (IPP2P_BIT * 100 + 62);
-+ break;
-+ case 67:
-+ if (get_u32(haystack, 16) == __constant_htonl(0x00000406) && get_u32(haystack, 36) == __constant_htonl(0x00000104))
-+ return (IPP2P_BIT * 100 + 53);
-+ if (get_u32(haystack, 16) == __constant_htonl(0x00000406))
-+ return (IPP2P_BIT * 100 + 63);
-+ break;
-+ case 211:
-+ if (get_u32(haystack, 8) == __constant_htonl(0x00000405))
-+ return (IPP2P_BIT * 100 + 54);
-+ break;
-+ case 29:
-+ if ((get_u32(haystack, 8) == __constant_htonl(0x00000401)))
-+ return (IPP2P_BIT * 100 + 55);
-+ break;
-+ case 52:
-+ if (get_u32(haystack,8) == __constant_htonl(0x00000827) &&
-+ get_u32(haystack,12) == __constant_htonl(0x37502950))
-+ return (IPP2P_BIT * 100 + 80);
-+ break;
-+ default:
-+ /* this packet does not have a constant size */
-+ if (packet_len >= 40 && get_u32(haystack, 16) == __constant_htonl(0x00000402) && get_u32(haystack, 36) == __constant_htonl(0x00000104))
-+ return (IPP2P_BIT * 100 + 56);
-+ break;
-+ }
-+
-+ /* some extra-bitcomet rules:
-+ * "d1:" [a|r] "d2:id20:"
-+ */
-+ if (packet_len > 30 && get_u8(haystack, 8) == 'd' && get_u8(haystack, 9) == '1' && get_u8(haystack, 10) == ':' )
-+ {
-+ if (get_u8(haystack, 11) == 'a' || get_u8(haystack, 11) == 'r')
-+ {
-+ if (memcmp(haystack+12,"d2:id20:",8)==0)
-+ return (IPP2P_BIT * 100 + 57);
-+ }
-+ }
-+
-+#if 0
-+ /* bitlord rules */
-+ /* packetlen must be bigger than 40 */
-+ /* first 4 bytes are zero */
-+ if (packet_len > 40 && get_u32(haystack, 8) == 0x00000000)
-+ {
-+ /* first rule: 00 00 00 00 01 00 00 xx xx xx xx 00 00 00 00*/
-+ if (get_u32(haystack, 12) == 0x00000000 &&
-+ get_u32(haystack, 16) == 0x00010000 &&
-+ get_u32(haystack, 24) == 0x00000000 )
-+ return (IPP2P_BIT * 100 + 71);
-+
-+ /* 00 01 00 00 0d 00 00 xx xx xx xx 00 00 00 00*/
-+ if (get_u32(haystack, 12) == 0x00000001 &&
-+ get_u32(haystack, 16) == 0x000d0000 &&
-+ get_u32(haystack, 24) == 0x00000000 )
-+ return (IPP2P_BIT * 100 + 71);
-+
-+
-+ }
-+#endif
-+
-+ return 0;
-+}/*udp_search_bit*/
-+
-+
-+
-+/*Search for Ares commands*/
-+//#define IPP2P_DEBUG_ARES
-+int
-+search_ares (const unsigned char *payload, const u16 plen)
-+//int search_ares (unsigned char *haystack, int packet_len, int head_len)
-+{
-+// const unsigned char *t = haystack + head_len;
-+
-+ /* all ares packets start with */
-+ if (payload[1] == 0 && (plen - payload[0]) == 3)
-+ {
-+ switch (payload[2])
-+ {
-+ case 0x5a:
-+ /* ares connect */
-+ if ( plen == 6 && payload[5] == 0x05 ) return ((IPP2P_ARES * 100) + 1);
-+ break;
-+ case 0x09:
-+ /* ares search, min 3 chars --> 14 bytes
-+ * lets define a search can be up to 30 chars --> max 34 bytes
-+ */
-+ if ( plen >= 14 && plen <= 34 ) return ((IPP2P_ARES * 100) + 1);
-+ break;
-+#ifdef IPP2P_DEBUG_ARES
-+ default:
-+ printk(KERN_DEBUG "Unknown Ares command %x recognized, len: %u \n", (unsigned int) payload[2],plen);
-+#endif /* IPP2P_DEBUG_ARES */
-+ }
-+ }
-+
-+#if 0
-+ /* found connect packet: 03 00 5a 04 03 05 */
-+ /* new version ares 1.8: 03 00 5a xx xx 05 */
-+ if ((plen) == 6){ /* possible connect command*/
-+ if ((payload[0] == 0x03) && (payload[1] == 0x00) && (payload[2] == 0x5a) && (payload[5] == 0x05))
-+ return ((IPP2P_ARES * 100) + 1);
-+ }
-+ if ((plen) == 60){ /* possible download command*/
-+ if ((payload[59] == 0x0a) && (payload[58] == 0x0a)){
-+ if (memcmp(t, "PUSH SHA1:", 10) == 0) /* found download command */
-+ return ((IPP2P_ARES * 100) + 2);
-+ }
-+ }
-+#endif
-+
-+ return 0;
-+} /*search_ares*/
-+
-+/*Search for SoulSeek commands*/
-+int
-+search_soul (const unsigned char *payload, const u16 plen)
-+{
-+//#define IPP2P_DEBUG_SOUL
-+ /* match: xx xx xx xx | xx = sizeof(payload) - 4 */
-+ if (get_u32(payload, 0) == (plen - 4)){
-+ const __u32 m=get_u32(payload, 4);
-+ /* match 00 yy yy 00, yy can be everything */
-+ if ( get_u8(payload, 4) == 0x00 && get_u8(payload, 7) == 0x00 )
-+ {
-+#ifdef IPP2P_DEBUG_SOUL
-+ printk(KERN_DEBUG "0: Soulseek command 0x%x recognized\n",get_u32(payload, 4));
-+#endif /* IPP2P_DEBUG_SOUL */
-+ return ((IPP2P_SOUL * 100) + 1);
-+ }
-+
-+ /* next match: 01 yy 00 00 | yy can be everything */
-+ if ( get_u8(payload, 4) == 0x01 && get_u16(payload, 6) == 0x0000 )
-+ {
-+#ifdef IPP2P_DEBUG_SOUL
-+ printk(KERN_DEBUG "1: Soulseek command 0x%x recognized\n",get_u16(payload, 4));
-+#endif /* IPP2P_DEBUG_SOUL */
-+ return ((IPP2P_SOUL * 100) + 2);
-+ }
-+
-+ /* other soulseek commandos are: 1-5,7,9,13-18,22,23,26,28,35-37,40-46,50,51,60,62-69,91,92,1001 */
-+ /* try to do this in an intelligent way */
-+ /* get all small commandos */
-+ switch(m)
-+ {
-+ case 7:
-+ case 9:
-+ case 22:
-+ case 23:
-+ case 26:
-+ case 28:
-+ case 50:
-+ case 51:
-+ case 60:
-+ case 91:
-+ case 92:
-+ case 1001:
-+#ifdef IPP2P_DEBUG_SOUL
-+ printk(KERN_DEBUG "2: Soulseek command 0x%x recognized\n",get_u16(payload, 4));
-+#endif /* IPP2P_DEBUG_SOUL */
-+ return ((IPP2P_SOUL * 100) + 3);
-+ }
-+
-+ if (m > 0 && m < 6 )
-+ {
-+#ifdef IPP2P_DEBUG_SOUL
-+ printk(KERN_DEBUG "3: Soulseek command 0x%x recognized\n",get_u16(payload, 4));
-+#endif /* IPP2P_DEBUG_SOUL */
-+ return ((IPP2P_SOUL * 100) + 4);
-+ }
-+ if (m > 12 && m < 19 )
-+ {
-+#ifdef IPP2P_DEBUG_SOUL
-+ printk(KERN_DEBUG "4: Soulseek command 0x%x recognized\n",get_u16(payload, 4));
-+#endif /* IPP2P_DEBUG_SOUL */
-+ return ((IPP2P_SOUL * 100) + 5);
-+ }
-+
-+ if (m > 34 && m < 38 )
-+ {
-+#ifdef IPP2P_DEBUG_SOUL
-+ printk(KERN_DEBUG "5: Soulseek command 0x%x recognized\n",get_u16(payload, 4));
-+#endif /* IPP2P_DEBUG_SOUL */
-+ return ((IPP2P_SOUL * 100) + 6);
-+ }
-+
-+ if (m > 39 && m < 47 )
-+ {
-+#ifdef IPP2P_DEBUG_SOUL
-+ printk(KERN_DEBUG "6: Soulseek command 0x%x recognized\n",get_u16(payload, 4));
-+#endif /* IPP2P_DEBUG_SOUL */
-+ return ((IPP2P_SOUL * 100) + 7);
-+ }
-+
-+ if (m > 61 && m < 70 )
-+ {
-+#ifdef IPP2P_DEBUG_SOUL
-+ printk(KERN_DEBUG "7: Soulseek command 0x%x recognized\n",get_u16(payload, 4));
-+#endif /* IPP2P_DEBUG_SOUL */
-+ return ((IPP2P_SOUL * 100) + 8);
-+ }
-+
-+#ifdef IPP2P_DEBUG_SOUL
-+ printk(KERN_DEBUG "unknown SOULSEEK command: 0x%x, first 16 bit: 0x%x, first 8 bit: 0x%x ,soulseek ???\n",get_u32(payload, 4),get_u16(payload, 4) >> 16,get_u8(payload, 4) >> 24);
-+#endif /* IPP2P_DEBUG_SOUL */
-+ }
-+
-+ /* match 14 00 00 00 01 yy 00 00 00 STRING(YY) 01 00 00 00 00 46|50 00 00 00 00 */
-+ /* without size at the beginning !!! */
-+ if ( get_u32(payload, 0) == 0x14 && get_u8(payload, 4) == 0x01 )
-+ {
-+ __u32 y=get_u32(payload, 5);
-+ /* we need 19 chars + string */
-+ if ( (y + 19) <= (plen) )
-+ {
-+ const unsigned char *w=payload+9+y;
-+ if (get_u32(w, 0) == 0x01 && ( get_u16(w, 4) == 0x4600 || get_u16(w, 4) == 0x5000) && get_u32(w, 6) == 0x00);
-+#ifdef IPP2P_DEBUG_SOUL
-+ printk(KERN_DEBUG "Soulssek special client command recognized\n");
-+#endif /* IPP2P_DEBUG_SOUL */
-+ return ((IPP2P_SOUL * 100) + 9);
-+ }
-+ }
-+ return 0;
-+}
-+
-+
-+/*Search for WinMX commands*/
-+int
-+search_winmx (const unsigned char *payload, const u16 plen)
-+{
-+//#define IPP2P_DEBUG_WINMX
-+ if (((plen) == 4) && (memcmp(payload, "SEND", 4) == 0)) return ((IPP2P_WINMX * 100) + 1);
-+ if (((plen) == 3) && (memcmp(payload, "GET", 3) == 0)) return ((IPP2P_WINMX * 100) + 2);
-+ //if (packet_len < (head_len + 10)) return 0;
-+ if (plen < 10) return 0;
-+
-+ if ((memcmp(payload, "SEND", 4) == 0) || (memcmp(payload, "GET", 3) == 0)){
-+ u16 c=4;
-+ const u16 end=plen-2;
-+ u8 count=0;
-+ while (c < end)
-+ {
-+ if (payload[c]== 0x20 && payload[c+1] == 0x22)
-+ {
-+ c++;
-+ count++;
-+ if (count>=2) return ((IPP2P_WINMX * 100) + 3);
-+ }
-+ c++;
-+ }
-+ }
-+
-+ if ( plen == 149 && payload[0] == '8' )
-+ {
-+#ifdef IPP2P_DEBUG_WINMX
-+ printk(KERN_INFO "maybe WinMX\n");
-+#endif
-+ if (get_u32(payload,17) == 0 && get_u32(payload,21) == 0 && get_u32(payload,25) == 0 &&
-+// get_u32(payload,33) == __constant_htonl(0x71182b1a) && get_u32(payload,37) == __constant_htonl(0x05050000) &&
-+// get_u32(payload,133) == __constant_htonl(0x31097edf) && get_u32(payload,145) == __constant_htonl(0xdcb8f792))
-+ get_u16(payload,39) == 0 && get_u16(payload,135) == __constant_htons(0x7edf) && get_u16(payload,147) == __constant_htons(0xf792))
-+
-+ {
-+#ifdef IPP2P_DEBUG_WINMX
-+ printk(KERN_INFO "got WinMX\n");
-+#endif
-+ return ((IPP2P_WINMX * 100) + 4);
-+ }
-+ }
-+ return 0;
-+} /*search_winmx*/
-+
-+
-+/*Search for appleJuice commands*/
-+int
-+search_apple (const unsigned char *payload, const u16 plen)
-+{
-+ if ( (plen > 7) && (payload[6] == 0x0d) && (payload[7] == 0x0a) && (memcmp(payload, "ajprot", 6) == 0)) return (IPP2P_APPLE * 100);
-+
-+ return 0;
-+}
-+
-+
-+/*Search for BitTorrent commands*/
-+int
-+search_bittorrent (const unsigned char *payload, const u16 plen)
-+{
-+ if (plen > 20)
-+ {
-+ /* test for match 0x13+"BitTorrent protocol" */
-+ if (payload[0] == 0x13)
-+ {
-+ if (memcmp(payload+1, "BitTorrent protocol", 19) == 0) return (IPP2P_BIT * 100);
-+ }
-+
-+ /* get tracker commandos, all starts with GET /
-+ * then it can follow: scrape| announce
-+ * and then ?hash_info=
-+ */
-+ if (memcmp(payload,"GET /",5) == 0)
-+ {
-+ /* message scrape */
-+ if ( memcmp(payload+5,"scrape?info_hash=",17)==0 ) return (IPP2P_BIT * 100 + 1);
-+ /* message announce */
-+ if ( memcmp(payload+5,"announce?info_hash=",19)==0 ) return (IPP2P_BIT * 100 + 2);
-+ }
-+ }
-+ else
-+ {
-+ /* bitcomet encryptes the first packet, so we have to detect another
-+ * one later in the flow */
-+ /* first try failed, too many missdetections */
-+ //if ( size == 5 && get_u32(t,0) == __constant_htonl(1) && t[4] < 3) return (IPP2P_BIT * 100 + 3);
-+
-+ /* second try: block request packets */
-+ if ( plen == 17 && get_u32(payload,0) == __constant_htonl(0x0d) && payload[4] == 0x06 && get_u32(payload,13) == __constant_htonl(0x4000) ) return (IPP2P_BIT * 100 + 3);
-+ }
-+
-+ return 0;
-+}
-+
-+
-+
-+/*check for Kazaa get command*/
-+int
-+search_kazaa (const unsigned char *payload, const u16 plen)
-+
-+{
-+ if ((payload[plen-2] == 0x0d) && (payload[plen-1] == 0x0a) && memcmp(payload, "GET /.hash=", 11) == 0)
-+ return (IPP2P_DATA_KAZAA * 100);
-+
-+ return 0;
-+}
-+
-+
-+/*check for gnutella get command*/
-+int
-+search_gnu (const unsigned char *payload, const u16 plen)
-+{
-+ if ((payload[plen-2] == 0x0d) && (payload[plen-1] == 0x0a))
-+ {
-+ if (memcmp(payload, "GET /get/", 9) == 0) return ((IPP2P_DATA_GNU * 100) + 1);
-+ if (memcmp(payload, "GET /uri-res/", 13) == 0) return ((IPP2P_DATA_GNU * 100) + 2);
-+ }
-+ return 0;
-+}
-+
-+
-+/*check for gnutella get commands and other typical data*/
-+int
-+search_all_gnu (const unsigned char *payload, const u16 plen)
-+{
-+
-+ if ((payload[plen-2] == 0x0d) && (payload[plen-1] == 0x0a))
-+ {
-+
-+ if (memcmp(payload, "GNUTELLA CONNECT/", 17) == 0) return ((IPP2P_GNU * 100) + 1);
-+ if (memcmp(payload, "GNUTELLA/", 9) == 0) return ((IPP2P_GNU * 100) + 2);
-+
-+
-+ if ((memcmp(payload, "GET /get/", 9) == 0) || (memcmp(payload, "GET /uri-res/", 13) == 0))
-+ {
-+ u16 c=8;
-+ const u16 end=plen-22;
-+ while (c < end) {
-+ if ( payload[c] == 0x0a && payload[c+1] == 0x0d && ((memcmp(&payload[c+2], "X-Gnutella-", 11) == 0) || (memcmp(&payload[c+2], "X-Queue:", 8) == 0)))
-+ return ((IPP2P_GNU * 100) + 3);
-+ c++;
-+ }
-+ }
-+ }
-+ return 0;
-+}
-+
-+
-+/*check for KaZaA download commands and other typical data*/
-+int
-+search_all_kazaa (const unsigned char *payload, const u16 plen)
-+{
-+ if ((payload[plen-2] == 0x0d) && (payload[plen-1] == 0x0a))
-+ {
-+
-+ if (memcmp(payload, "GIVE ", 5) == 0) return ((IPP2P_KAZAA * 100) + 1);
-+
-+ if (memcmp(payload, "GET /", 5) == 0) {
-+ u16 c = 8;
-+ const u16 end=plen-22;
-+ while (c < end) {
-+ if ( payload[c] == 0x0a && payload[c+1] == 0x0d && ((memcmp(&payload[c+2], "X-Kazaa-Username: ", 18) == 0) || (memcmp(&payload[c+2], "User-Agent: PeerEnabler/", 24) == 0)))
-+ return ((IPP2P_KAZAA * 100) + 2);
-+ c++;
-+ }
-+ }
-+ }
-+ return 0;
-+}
-+
-+/*fast check for edonkey file segment transfer command*/
-+int
-+search_edk (const unsigned char *payload, const u16 plen)
-+{
-+ if (payload[0] != 0xe3)
-+ return 0;
-+ else {
-+ if (payload[5] == 0x47)
-+ return (IPP2P_DATA_EDK * 100);
-+ else
-+ return 0;
-+ }
-+}
-+
-+
-+
-+/*intensive but slower search for some edonkey packets including size-check*/
-+int
-+search_all_edk (const unsigned char *payload, const u16 plen)
-+{
-+ if (payload[0] != 0xe3)
-+ return 0;
-+ else {
-+ //t += head_len;
-+ const u16 cmd = get_u16(payload, 1);
-+ if (cmd == (plen - 5)) {
-+ switch (payload[5]) {
-+ case 0x01: return ((IPP2P_EDK * 100) + 1); /*Client: hello or Server:hello*/
-+ case 0x4c: return ((IPP2P_EDK * 100) + 9); /*Client: Hello-Answer*/
-+ }
-+ }
-+ return 0;
-+ }
-+}
-+
-+
-+/*fast check for Direct Connect send command*/
-+int
-+search_dc (const unsigned char *payload, const u16 plen)
-+{
-+
-+ if (payload[0] != 0x24 )
-+ return 0;
-+ else {
-+ if (memcmp(&payload[1], "Send|", 5) == 0)
-+ return (IPP2P_DATA_DC * 100);
-+ else
-+ return 0;
-+ }
-+
-+}
-+
-+
-+/*intensive but slower check for all direct connect packets*/
-+int
-+search_all_dc (const unsigned char *payload, const u16 plen)
-+{
-+// unsigned char *t = haystack;
-+
-+ if (payload[0] == 0x24 && payload[plen-1] == 0x7c)
-+ {
-+ const unsigned char *t=&payload[1];
-+ /* Client-Hub-Protocol */
-+ if (memcmp(t, "Lock ", 5) == 0) return ((IPP2P_DC * 100) + 1);
-+ /* Client-Client-Protocol, some are already recognized by client-hub (like lock) */
-+ if (memcmp(t, "MyNick ", 7) == 0) return ((IPP2P_DC * 100) + 38);
-+ }
-+ return 0;
-+}
-+
-+/*check for mute*/
-+int
-+search_mute (const unsigned char *payload, const u16 plen)
-+{
-+ if ( plen == 209 || plen == 345 || plen == 473 || plen == 609 || plen == 1121 )
-+ {
-+ //printk(KERN_DEBUG "size hit: %u",size);
-+ if (memcmp(payload,"PublicKey: ",11) == 0 )
-+ {
-+ return ((IPP2P_MUTE * 100) + 0);
-+
-+/* if (memcmp(t+size-14,"\x0aEndPublicKey\x0a",14) == 0)
-+ {
-+ printk(KERN_DEBUG "end pubic key hit: %u",size);
-+
-+ }*/
-+ }
-+ }
-+ return 0;
-+}
-+
-+
-+/* check for xdcc */
-+int
-+search_xdcc (const unsigned char *payload, const u16 plen)
-+{
-+ /* search in small packets only */
-+ if (plen > 20 && plen < 200 && payload[plen-1] == 0x0a && payload[plen-2] == 0x0d && memcmp(payload,"PRIVMSG ",8) == 0)
-+ {
-+
-+ u16 x=10;
-+ const u16 end=plen - 13;
-+
-+ /* is seems to be a irc private massage, chedck for xdcc command */
-+ while (x < end)
-+ {
-+ if (payload[x] == ':')
-+ {
-+ if ( memcmp(&payload[x+1],"xdcc send #",11) == 0 )
-+ return ((IPP2P_XDCC * 100) + 0);
-+ }
-+ x++;
-+ }
-+ }
-+ return 0;
-+}
-+
-+/* search for waste */
-+int search_waste(const unsigned char *payload, const u16 plen)
-+{
-+ if ( plen >= 8 && memcmp(payload,"GET.sha1:",9) == 0)
-+ return ((IPP2P_WASTE * 100) + 0);
-+
-+ return 0;
-+}
-+
-+
-+static struct {
-+ int command;
-+ __u8 short_hand; /*for fucntions included in short hands*/
-+ int packet_len;
-+ int (*function_name) (const unsigned char *, const u16);
-+} matchlist[] = {
-+ {IPP2P_EDK,SHORT_HAND_IPP2P,20, &search_all_edk},
-+// {IPP2P_DATA_KAZAA,SHORT_HAND_DATA,200, &search_kazaa},
-+// {IPP2P_DATA_EDK,SHORT_HAND_DATA,60, &search_edk},
-+// {IPP2P_DATA_DC,SHORT_HAND_DATA,26, &search_dc},
-+ {IPP2P_DC,SHORT_HAND_IPP2P,5, search_all_dc},
-+// {IPP2P_DATA_GNU,SHORT_HAND_DATA,40, &search_gnu},
-+ {IPP2P_GNU,SHORT_HAND_IPP2P,5, &search_all_gnu},
-+ {IPP2P_KAZAA,SHORT_HAND_IPP2P,5, &search_all_kazaa},
-+ {IPP2P_BIT,SHORT_HAND_IPP2P,20, &search_bittorrent},
-+ {IPP2P_APPLE,SHORT_HAND_IPP2P,5, &search_apple},
-+ {IPP2P_SOUL,SHORT_HAND_IPP2P,5, &search_soul},
-+ {IPP2P_WINMX,SHORT_HAND_IPP2P,2, &search_winmx},
-+ {IPP2P_ARES,SHORT_HAND_IPP2P,5, &search_ares},
-+ {IPP2P_MUTE,SHORT_HAND_NONE,200, &search_mute},
-+ {IPP2P_WASTE,SHORT_HAND_NONE,5, &search_waste},
-+ {IPP2P_XDCC,SHORT_HAND_NONE,5, &search_xdcc},
-+ {0,0,0,NULL}
-+};
-+
-+
-+static struct {
-+ int command;
-+ __u8 short_hand; /*for fucntions included in short hands*/
-+ int packet_len;
-+ int (*function_name) (unsigned char *, int);
-+} udp_list[] = {
-+ {IPP2P_KAZAA,SHORT_HAND_IPP2P,14, &udp_search_kazaa},
-+ {IPP2P_BIT,SHORT_HAND_IPP2P,23, &udp_search_bit},
-+ {IPP2P_GNU,SHORT_HAND_IPP2P,11, &udp_search_gnu},
-+ {IPP2P_EDK,SHORT_HAND_IPP2P,9, &udp_search_edk},
-+ {IPP2P_DC,SHORT_HAND_IPP2P,12, &udp_search_directconnect},
-+ {0,0,0,NULL}
-+};
-+
-+
-+static int
-+match(const struct sk_buff *skb,
-+ const struct net_device *in,
-+ const struct net_device *out,
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
-+ const struct xt_match *match,
-+#endif
-+ const void *matchinfo,
-+ int offset,
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
-+ unsigned int protoff,
-+#elif LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
-+ const void *hdr,
-+ u_int16_t datalen,
-+#endif
-+ int *hotdrop)
-+{
-+ const struct ipt_p2p_info *info = matchinfo;
-+ unsigned char *haystack;
-+ struct iphdr *ip = ip_hdr(skb);
-+ int p2p_result = 0, i = 0;
-+// int head_len;
-+ int hlen = ntohs(ip->tot_len)-(ip->ihl*4); /*hlen = packet-data length*/
-+
-+ /*must not be a fragment*/
-+ if (offset) {
-+ if (info->debug) printk("IPP2P.match: offset found %i \n",offset);
-+ return 0;
-+ }
-+
-+ /*make sure that skb is linear*/
-+ if(skb_is_nonlinear(skb)){
-+ if (info->debug) printk("IPP2P.match: nonlinear skb found\n");
-+ return 0;
-+ }
-+
-+
-+ haystack=(char *)ip+(ip->ihl*4); /*haystack = packet data*/
-+
-+ switch (ip->protocol){
-+ case IPPROTO_TCP: /*what to do with a TCP packet*/
-+ {
-+ struct tcphdr *tcph = (void *) ip + ip->ihl * 4;
-+
-+ if (tcph->fin) return 0; /*if FIN bit is set bail out*/
-+ if (tcph->syn) return 0; /*if SYN bit is set bail out*/
-+ if (tcph->rst) return 0; /*if RST bit is set bail out*/
-+
-+ haystack += tcph->doff * 4; /*get TCP-Header-Size*/
-+ hlen -= tcph->doff * 4;
-+ while (matchlist[i].command) {
-+ if ((((info->cmd & matchlist[i].command) == matchlist[i].command) ||
-+ ((info->cmd & matchlist[i].short_hand) == matchlist[i].short_hand)) &&
-+ (hlen > matchlist[i].packet_len)) {
-+ p2p_result = matchlist[i].function_name(haystack, hlen);
-+ if (p2p_result)
-+ {
-+ if (info->debug) printk("IPP2P.debug:TCP-match: %i from: %u.%u.%u.%u:%i to: %u.%u.%u.%u:%i Length: %i\n",
-+ p2p_result, NIPQUAD(ip->saddr),ntohs(tcph->source), NIPQUAD(ip->daddr),ntohs(tcph->dest),hlen);
-+ return p2p_result;
-+ }
-+ }
-+ i++;
-+ }
-+ return p2p_result;
-+ }
-+
-+ case IPPROTO_UDP: /*what to do with an UDP packet*/
-+ {
-+ struct udphdr *udph = (void *) ip + ip->ihl * 4;
-+
-+ while (udp_list[i].command){
-+ if ((((info->cmd & udp_list[i].command) == udp_list[i].command) ||
-+ ((info->cmd & udp_list[i].short_hand) == udp_list[i].short_hand)) &&
-+ (hlen > udp_list[i].packet_len)) {
-+ p2p_result = udp_list[i].function_name(haystack, hlen);
-+ if (p2p_result){
-+ if (info->debug) printk("IPP2P.debug:UDP-match: %i from: %u.%u.%u.%u:%i to: %u.%u.%u.%u:%i Length: %i\n",
-+ p2p_result, NIPQUAD(ip->saddr),ntohs(udph->source), NIPQUAD(ip->daddr),ntohs(udph->dest),hlen);
-+ return p2p_result;
-+ }
-+ }
-+ i++;
-+ }
-+ return p2p_result;
-+ }
-+
-+ default: return 0;
-+ }
-+}
-+
-+
-+
-+static int
-+checkentry(const char *tablename,
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
-+ const void *ip,
-+ const struct xt_match *match,
-+#else
-+ const struct ipt_ip *ip,
-+#endif
-+ void *matchinfo,
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
-+ unsigned int matchsize,
-+#endif
-+ unsigned int hook_mask)
-+{
-+ /* Must specify -p tcp */
-+/* if (ip->proto != IPPROTO_TCP || (ip->invflags & IPT_INV_PROTO)) {
-+ * printk("ipp2p: Only works on TCP packets, use -p tcp\n");
-+ * return 0;
-+ * }*/
-+ return 1;
-+}
-+
-+
-+
-+
-+static struct ipt_match ipp2p_match = {
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
-+ { NULL, NULL },
-+ "ipp2p",
-+ &match,
-+ &checkentry,
-+ NULL,
-+ THIS_MODULE
-+#endif
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
-+ .name = "ipp2p",
-+ .match = &match,
-+ .family = AF_INET,
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
-+ .matchsize = sizeof(struct ipt_p2p_info),
-+#endif
-+ .checkentry = &checkentry,
-+ .me = THIS_MODULE,
-+#endif
-+};
-+
-+
-+static int __init init(void)
-+{
-+ printk(KERN_INFO "IPP2P v%s loading\n", IPP2P_VERSION);
-+ return xt_register_match(&ipp2p_match);
-+}
-+
-+static void __exit fini(void)
-+{
-+ xt_unregister_match(&ipp2p_match);
-+ printk(KERN_INFO "IPP2P v%s unloaded\n", IPP2P_VERSION);
-+}
-+
-+module_init(init);
-+module_exit(fini);
-+
-+
-Index: linux-2.6.21.7/net/ipv4/netfilter/Kconfig
-===================================================================
---- linux-2.6.21.7.orig/net/ipv4/netfilter/Kconfig
-+++ linux-2.6.21.7/net/ipv4/netfilter/Kconfig
-@@ -245,6 +245,12 @@ config IP_NF_MATCH_IPRANGE
-
- To compile it as a module, choose M here. If unsure, say N.
-
-+config IP_NF_MATCH_IPP2P
-+ tristate "IPP2P"
-+ depends on IP_NF_IPTABLES
-+ help
-+ Module for matching traffic of various Peer-to-Peer applications
-+
- config IP_NF_MATCH_TOS
- tristate "TOS match support"
- depends on IP_NF_IPTABLES
-Index: linux-2.6.21.7/net/ipv4/netfilter/Makefile
-===================================================================
---- linux-2.6.21.7.orig/net/ipv4/netfilter/Makefile
-+++ linux-2.6.21.7/net/ipv4/netfilter/Makefile
-@@ -91,6 +91,7 @@ obj-$(CONFIG_IP_NF_MATCH_ECN) += ipt_ecn
- obj-$(CONFIG_IP_NF_MATCH_AH) += ipt_ah.o
- obj-$(CONFIG_IP_NF_MATCH_TTL) += ipt_ttl.o
- obj-$(CONFIG_IP_NF_MATCH_ADDRTYPE) += ipt_addrtype.o
-+obj-$(CONFIG_IP_NF_MATCH_IPP2P) += ipt_ipp2p.o
-
- # targets
- obj-$(CONFIG_IP_NF_TARGET_REJECT) += ipt_REJECT.o
+++ /dev/null
-Index: linux-2.6.21.7/include/net/xfrmudp.h
-===================================================================
---- /dev/null
-+++ linux-2.6.21.7/include/net/xfrmudp.h
-@@ -0,0 +1,10 @@
-+/*
-+ * pointer to function for type that xfrm4_input wants, to permit
-+ * decoupling of XFRM from udp.c
-+ */
-+#define HAVE_XFRM4_UDP_REGISTER
-+
-+typedef int (*xfrm4_rcv_encap_t)(struct sk_buff *skb, __u16 encap_type);
-+extern int udp4_register_esp_rcvencap(xfrm4_rcv_encap_t func
-+ , xfrm4_rcv_encap_t *oldfunc);
-+extern int udp4_unregister_esp_rcvencap(xfrm4_rcv_encap_t func);
-Index: linux-2.6.21.7/net/ipv4/Kconfig
-===================================================================
---- linux-2.6.21.7.orig/net/ipv4/Kconfig
-+++ linux-2.6.21.7/net/ipv4/Kconfig
-@@ -266,6 +266,12 @@ config NET_IPGRE_BROADCAST
- Network), but can be distributed all over the Internet. If you want
- to do that, say Y here and to "IP multicast routing" below.
-
-+config IPSEC_NAT_TRAVERSAL
-+ bool "IPSEC NAT-Traversal (KLIPS compatible)"
-+ depends on INET
-+ ---help---
-+ Includes support for RFC3947/RFC3948 NAT-Traversal of ESP over UDP.
-+
- config IP_MROUTE
- bool "IP: multicast routing"
- depends on IP_MULTICAST
-Index: linux-2.6.21.7/net/ipv4/udp.c
-===================================================================
---- linux-2.6.21.7.orig/net/ipv4/udp.c
-+++ linux-2.6.21.7/net/ipv4/udp.c
-@@ -101,12 +101,15 @@
- #include <net/route.h>
- #include <net/checksum.h>
- #include <net/xfrm.h>
-+#include <net/xfrmudp.h>
- #include "udp_impl.h"
-
- /*
- * Snmp MIB for the UDP layer
- */
-
-+static xfrm4_rcv_encap_t xfrm4_rcv_encap_func;
-+
- DEFINE_SNMP_STAT(struct udp_mib, udp_statistics) __read_mostly;
-
- struct hlist_head udp_hash[UDP_HTABLE_SIZE];
-@@ -915,6 +918,42 @@ int udp_disconnect(struct sock *sk, int
- return 0;
- }
-
-+#if defined(CONFIG_XFRM) || defined(CONFIG_IPSEC_NAT_TRAVERSAL)
-+
-+/* if XFRM isn't a module, then register it directly. */
-+#if 0 && !defined(CONFIG_XFRM_MODULE) && !defined(CONFIG_IPSEC_NAT_TRAVERSAL)
-+static xfrm4_rcv_encap_t xfrm4_rcv_encap_func = xfrm4_rcv_encap;
-+#else
-+static xfrm4_rcv_encap_t xfrm4_rcv_encap_func = NULL;
-+#endif
-+
-+int udp4_register_esp_rcvencap(xfrm4_rcv_encap_t func
-+ , xfrm4_rcv_encap_t *oldfunc)
-+{
-+ if(oldfunc != NULL) {
-+ *oldfunc = xfrm4_rcv_encap_func;
-+ }
-+
-+#if 0
-+ if(xfrm4_rcv_encap_func != NULL)
-+ return -1;
-+#endif
-+
-+ xfrm4_rcv_encap_func = func;
-+ return 0;
-+}
-+
-+int udp4_unregister_esp_rcvencap(xfrm4_rcv_encap_t func)
-+{
-+ if(xfrm4_rcv_encap_func != func)
-+ return -1;
-+
-+ xfrm4_rcv_encap_func = NULL;
-+ return 0;
-+}
-+#endif /* CONFIG_XFRM_MODULE || CONFIG_IPSEC_NAT_TRAVERSAL */
-+
-+
- /* return:
- * 1 if the the UDP system should process it
- * 0 if we should drop this packet
-@@ -922,7 +961,7 @@ int udp_disconnect(struct sock *sk, int
- */
- static int udp_encap_rcv(struct sock * sk, struct sk_buff *skb)
- {
--#ifndef CONFIG_XFRM
-+#if !defined(CONFIG_XFRM) && !defined(CONFIG_IPSEC_NAT_TRAVERSAL)
- return 1;
- #else
- struct udp_sock *up = udp_sk(sk);
-@@ -937,11 +976,11 @@ static int udp_encap_rcv(struct sock * s
- /* if we're overly short, let UDP handle it */
- len = skb->len - sizeof(struct udphdr);
- if (len <= 0)
-- return 1;
-+ return 2;
-
- /* if this is not encapsulated socket, then just return now */
- if (!encap_type)
-- return 1;
-+ return 3;
-
- /* If this is a paged skb, make sure we pull up
- * whatever data we need to look at. */
-@@ -964,7 +1003,7 @@ static int udp_encap_rcv(struct sock * s
- len = sizeof(struct udphdr);
- } else
- /* Must be an IKE packet.. pass it through */
-- return 1;
-+ return 4;
- break;
- case UDP_ENCAP_ESPINUDP_NON_IKE:
- /* Check if this is a keepalive packet. If so, eat it. */
-@@ -977,7 +1016,7 @@ static int udp_encap_rcv(struct sock * s
- len = sizeof(struct udphdr) + 2 * sizeof(u32);
- } else
- /* Must be an IKE packet.. pass it through */
-- return 1;
-+ return 5;
- break;
- }
-
-@@ -988,6 +1027,8 @@ static int udp_encap_rcv(struct sock * s
- */
- if (skb_cloned(skb) && pskb_expand_head(skb, 0, 0, GFP_ATOMIC))
- return 0;
-+ if (skb_cloned(skb) && pskb_expand_head(skb, 0, 0, GFP_ATOMIC))
-+ return 0;
-
- /* Now we can update and verify the packet length... */
- iph = skb->nh.iph;
-@@ -1051,9 +1092,13 @@ int udp_queue_rcv_skb(struct sock * sk,
- return 0;
- }
- if (ret < 0) {
-- /* process the ESP packet */
-- ret = xfrm4_rcv_encap(skb, up->encap_type);
-- UDP_INC_STATS_BH(UDP_MIB_INDATAGRAMS, up->pcflag);
-+ if(xfrm4_rcv_encap_func != NULL) {
-+ ret = (*xfrm4_rcv_encap_func)(skb, up->encap_type);
-+ UDP_INC_STATS_BH(UDP_MIB_INDATAGRAMS, up->pcflag);
-+ } else {
-+ UDP_INC_STATS_BH(UDP_MIB_INERRORS, up->pcflag);
-+ ret = 1;
-+ }
- return -ret;
- }
- /* FALLTHROUGH -- it's a UDP Packet */
-@@ -1733,3 +1778,9 @@ EXPORT_SYMBOL(udp_poll);
- EXPORT_SYMBOL(udp_proc_register);
- EXPORT_SYMBOL(udp_proc_unregister);
- #endif
-+
-+#if defined(CONFIG_IPSEC_NAT_TRAVERSAL)
-+EXPORT_SYMBOL(udp4_register_esp_rcvencap);
-+EXPORT_SYMBOL(udp4_unregister_esp_rcvencap);
-+#endif
-+
+++ /dev/null
-Index: linux-2.6.21.7/include/linux/netfilter_ipv4/ip_set.h
-===================================================================
---- /dev/null
-+++ linux-2.6.21.7/include/linux/netfilter_ipv4/ip_set.h
-@@ -0,0 +1,498 @@
-+#ifndef _IP_SET_H
-+#define _IP_SET_H
-+
-+/* Copyright (C) 2000-2002 Joakim Axelsson <gozem@linux.nu>
-+ * Patrick Schaaf <bof@bof.de>
-+ * Martin Josefsson <gandalf@wlug.westbo.se>
-+ * Copyright (C) 2003-2004 Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
-+ *
-+ * This program is free software; you can redistribute it and/or modify
-+ * it under the terms of the GNU General Public License version 2 as
-+ * published by the Free Software Foundation.
-+ */
-+
-+#if 0
-+#define IP_SET_DEBUG
-+#endif
-+
-+/*
-+ * A sockopt of such quality has hardly ever been seen before on the open
-+ * market! This little beauty, hardly ever used: above 64, so it's
-+ * traditionally used for firewalling, not touched (even once!) by the
-+ * 2.0, 2.2 and 2.4 kernels!
-+ *
-+ * Comes with its own certificate of authenticity, valid anywhere in the
-+ * Free world!
-+ *
-+ * Rusty, 19.4.2000
-+ */
-+#define SO_IP_SET 83
-+
-+/*
-+ * Heavily modify by Joakim Axelsson 08.03.2002
-+ * - Made it more modulebased
-+ *
-+ * Additional heavy modifications by Jozsef Kadlecsik 22.02.2004
-+ * - bindings added
-+ * - in order to "deal with" backward compatibility, renamed to ipset
-+ */
-+
-+/*
-+ * Used so that the kernel module and ipset-binary can match their versions
-+ */
-+#define IP_SET_PROTOCOL_VERSION 2
-+
-+#define IP_SET_MAXNAMELEN 32 /* set names and set typenames */
-+
-+/* Lets work with our own typedef for representing an IP address.
-+ * We hope to make the code more portable, possibly to IPv6...
-+ *
-+ * The representation works in HOST byte order, because most set types
-+ * will perform arithmetic operations and compare operations.
-+ *
-+ * For now the type is an uint32_t.
-+ *
-+ * Make sure to ONLY use the functions when translating and parsing
-+ * in order to keep the host byte order and make it more portable:
-+ * parse_ip()
-+ * parse_mask()
-+ * parse_ipandmask()
-+ * ip_tostring()
-+ * (Joakim: where are they???)
-+ */
-+
-+typedef uint32_t ip_set_ip_t;
-+
-+/* Sets are identified by an id in kernel space. Tweak with ip_set_id_t
-+ * and IP_SET_INVALID_ID if you want to increase the max number of sets.
-+ */
-+typedef uint16_t ip_set_id_t;
-+
-+#define IP_SET_INVALID_ID 65535
-+
-+/* How deep we follow bindings */
-+#define IP_SET_MAX_BINDINGS 6
-+
-+/*
-+ * Option flags for kernel operations (ipt_set_info)
-+ */
-+#define IPSET_SRC 0x01 /* Source match/add */
-+#define IPSET_DST 0x02 /* Destination match/add */
-+#define IPSET_MATCH_INV 0x04 /* Inverse matching */
-+
-+/*
-+ * Set features
-+ */
-+#define IPSET_TYPE_IP 0x01 /* IP address type of set */
-+#define IPSET_TYPE_PORT 0x02 /* Port type of set */
-+#define IPSET_DATA_SINGLE 0x04 /* Single data storage */
-+#define IPSET_DATA_DOUBLE 0x08 /* Double data storage */
-+
-+/* Reserved keywords */
-+#define IPSET_TOKEN_DEFAULT ":default:"
-+#define IPSET_TOKEN_ALL ":all:"
-+
-+/* SO_IP_SET operation constants, and their request struct types.
-+ *
-+ * Operation ids:
-+ * 0-99: commands with version checking
-+ * 100-199: add/del/test/bind/unbind
-+ * 200-299: list, save, restore
-+ */
-+
-+/* Single shot operations:
-+ * version, create, destroy, flush, rename and swap
-+ *
-+ * Sets are identified by name.
-+ */
-+
-+#define IP_SET_REQ_STD \
-+ unsigned op; \
-+ unsigned version; \
-+ char name[IP_SET_MAXNAMELEN]
-+
-+#define IP_SET_OP_CREATE 0x00000001 /* Create a new (empty) set */
-+struct ip_set_req_create {
-+ IP_SET_REQ_STD;
-+ char typename[IP_SET_MAXNAMELEN];
-+};
-+
-+#define IP_SET_OP_DESTROY 0x00000002 /* Remove a (empty) set */
-+struct ip_set_req_std {
-+ IP_SET_REQ_STD;
-+};
-+
-+#define IP_SET_OP_FLUSH 0x00000003 /* Remove all IPs in a set */
-+/* Uses ip_set_req_std */
-+
-+#define IP_SET_OP_RENAME 0x00000004 /* Rename a set */
-+/* Uses ip_set_req_create */
-+
-+#define IP_SET_OP_SWAP 0x00000005 /* Swap two sets */
-+/* Uses ip_set_req_create */
-+
-+union ip_set_name_index {
-+ char name[IP_SET_MAXNAMELEN];
-+ ip_set_id_t index;
-+};
-+
-+#define IP_SET_OP_GET_BYNAME 0x00000006 /* Get set index by name */
-+struct ip_set_req_get_set {
-+ unsigned op;
-+ unsigned version;
-+ union ip_set_name_index set;
-+};
-+
-+#define IP_SET_OP_GET_BYINDEX 0x00000007 /* Get set name by index */
-+/* Uses ip_set_req_get_set */
-+
-+#define IP_SET_OP_VERSION 0x00000100 /* Ask kernel version */
-+struct ip_set_req_version {
-+ unsigned op;
-+ unsigned version;
-+};
-+
-+/* Double shots operations:
-+ * add, del, test, bind and unbind.
-+ *
-+ * First we query the kernel to get the index and type of the target set,
-+ * then issue the command. Validity of IP is checked in kernel in order
-+ * to minimalize sockopt operations.
-+ */
-+
-+/* Get minimal set data for add/del/test/bind/unbind IP */
-+#define IP_SET_OP_ADT_GET 0x00000010 /* Get set and type */
-+struct ip_set_req_adt_get {
-+ unsigned op;
-+ unsigned version;
-+ union ip_set_name_index set;
-+ char typename[IP_SET_MAXNAMELEN];
-+};
-+
-+#define IP_SET_REQ_BYINDEX \
-+ unsigned op; \
-+ ip_set_id_t index;
-+
-+struct ip_set_req_adt {
-+ IP_SET_REQ_BYINDEX;
-+};
-+
-+#define IP_SET_OP_ADD_IP 0x00000101 /* Add an IP to a set */
-+/* Uses ip_set_req_adt, with type specific addage */
-+
-+#define IP_SET_OP_DEL_IP 0x00000102 /* Remove an IP from a set */
-+/* Uses ip_set_req_adt, with type specific addage */
-+
-+#define IP_SET_OP_TEST_IP 0x00000103 /* Test an IP in a set */
-+/* Uses ip_set_req_adt, with type specific addage */
-+
-+#define IP_SET_OP_BIND_SET 0x00000104 /* Bind an IP to a set */
-+/* Uses ip_set_req_bind, with type specific addage */
-+struct ip_set_req_bind {
-+ IP_SET_REQ_BYINDEX;
-+ char binding[IP_SET_MAXNAMELEN];
-+};
-+
-+#define IP_SET_OP_UNBIND_SET 0x00000105 /* Unbind an IP from a set */
-+/* Uses ip_set_req_bind, with type speficic addage
-+ * index = 0 means unbinding for all sets */
-+
-+#define IP_SET_OP_TEST_BIND_SET 0x00000106 /* Test binding an IP to a set */
-+/* Uses ip_set_req_bind, with type specific addage */
-+
-+/* Multiple shots operations: list, save, restore.
-+ *
-+ * - check kernel version and query the max number of sets
-+ * - get the basic information on all sets
-+ * and size required for the next step
-+ * - get actual set data: header, data, bindings
-+ */
-+
-+/* Get max_sets and the index of a queried set
-+ */
-+#define IP_SET_OP_MAX_SETS 0x00000020
-+struct ip_set_req_max_sets {
-+ unsigned op;
-+ unsigned version;
-+ ip_set_id_t max_sets; /* max_sets */
-+ ip_set_id_t sets; /* real number of sets */
-+ union ip_set_name_index set; /* index of set if name used */
-+};
-+
-+/* Get the id and name of the sets plus size for next step */
-+#define IP_SET_OP_LIST_SIZE 0x00000201
-+#define IP_SET_OP_SAVE_SIZE 0x00000202
-+struct ip_set_req_setnames {
-+ unsigned op;
-+ ip_set_id_t index; /* set to list/save */
-+ size_t size; /* size to get setdata/bindings */
-+ /* followed by sets number of struct ip_set_name_list */
-+};
-+
-+struct ip_set_name_list {
-+ char name[IP_SET_MAXNAMELEN];
-+ char typename[IP_SET_MAXNAMELEN];
-+ ip_set_id_t index;
-+ ip_set_id_t id;
-+};
-+
-+/* The actual list operation */
-+#define IP_SET_OP_LIST 0x00000203
-+struct ip_set_req_list {
-+ IP_SET_REQ_BYINDEX;
-+ /* sets number of struct ip_set_list in reply */
-+};
-+
-+struct ip_set_list {
-+ ip_set_id_t index;
-+ ip_set_id_t binding;
-+ u_int32_t ref;
-+ size_t header_size; /* Set header data of header_size */
-+ size_t members_size; /* Set members data of members_size */
-+ size_t bindings_size; /* Set bindings data of bindings_size */
-+};
-+
-+struct ip_set_hash_list {
-+ ip_set_ip_t ip;
-+ ip_set_id_t binding;
-+};
-+
-+/* The save operation */
-+#define IP_SET_OP_SAVE 0x00000204
-+/* Uses ip_set_req_list, in the reply replaced by
-+ * sets number of struct ip_set_save plus a marker
-+ * ip_set_save followed by ip_set_hash_save structures.
-+ */
-+struct ip_set_save {
-+ ip_set_id_t index;
-+ ip_set_id_t binding;
-+ size_t header_size; /* Set header data of header_size */
-+ size_t members_size; /* Set members data of members_size */
-+};
-+
-+/* At restoring, ip == 0 means default binding for the given set: */
-+struct ip_set_hash_save {
-+ ip_set_ip_t ip;
-+ ip_set_id_t id;
-+ ip_set_id_t binding;
-+};
-+
-+/* The restore operation */
-+#define IP_SET_OP_RESTORE 0x00000205
-+/* Uses ip_set_req_setnames followed by ip_set_restore structures
-+ * plus a marker ip_set_restore, followed by ip_set_hash_save
-+ * structures.
-+ */
-+struct ip_set_restore {
-+ char name[IP_SET_MAXNAMELEN];
-+ char typename[IP_SET_MAXNAMELEN];
-+ ip_set_id_t index;
-+ size_t header_size; /* Create data of header_size */
-+ size_t members_size; /* Set members data of members_size */
-+};
-+
-+static inline int bitmap_bytes(ip_set_ip_t a, ip_set_ip_t b)
-+{
-+ return 4 * ((((b - a + 8) / 8) + 3) / 4);
-+}
-+
-+#ifdef __KERNEL__
-+
-+#define ip_set_printk(format, args...) \
-+ do { \
-+ printk("%s: %s: ", __FILE__, __FUNCTION__); \
-+ printk(format "\n" , ## args); \
-+ } while (0)
-+
-+#if defined(IP_SET_DEBUG)
-+#define DP(format, args...) \
-+ do { \
-+ printk("%s: %s (DBG): ", __FILE__, __FUNCTION__);\
-+ printk(format "\n" , ## args); \
-+ } while (0)
-+#define IP_SET_ASSERT(x) \
-+ do { \
-+ if (!(x)) \
-+ printk("IP_SET_ASSERT: %s:%i(%s)\n", \
-+ __FILE__, __LINE__, __FUNCTION__); \
-+ } while (0)
-+#else
-+#define DP(format, args...)
-+#define IP_SET_ASSERT(x)
-+#endif
-+
-+struct ip_set;
-+
-+/*
-+ * The ip_set_type definition - one per set type, e.g. "ipmap".
-+ *
-+ * Each individual set has a pointer, set->type, going to one
-+ * of these structures. Function pointers inside the structure implement
-+ * the real behaviour of the sets.
-+ *
-+ * If not mentioned differently, the implementation behind the function
-+ * pointers of a set_type, is expected to return 0 if ok, and a negative
-+ * errno (e.g. -EINVAL) on error.
-+ */
-+struct ip_set_type {
-+ struct list_head list; /* next in list of set types */
-+
-+ /* test for IP in set (kernel: iptables -m set src|dst)
-+ * return 0 if not in set, 1 if in set.
-+ */
-+ int (*testip_kernel) (struct ip_set *set,
-+ const struct sk_buff * skb,
-+ ip_set_ip_t *ip,
-+ const u_int32_t *flags,
-+ unsigned char index);
-+
-+ /* test for IP in set (userspace: ipset -T set IP)
-+ * return 0 if not in set, 1 if in set.
-+ */
-+ int (*testip) (struct ip_set *set,
-+ const void *data, size_t size,
-+ ip_set_ip_t *ip);
-+
-+ /*
-+ * Size of the data structure passed by when
-+ * adding/deletin/testing an entry.
-+ */
-+ size_t reqsize;
-+
-+ /* Add IP into set (userspace: ipset -A set IP)
-+ * Return -EEXIST if the address is already in the set,
-+ * and -ERANGE if the address lies outside the set bounds.
-+ * If the address was not already in the set, 0 is returned.
-+ */
-+ int (*addip) (struct ip_set *set,
-+ const void *data, size_t size,
-+ ip_set_ip_t *ip);
-+
-+ /* Add IP into set (kernel: iptables ... -j SET set src|dst)
-+ * Return -EEXIST if the address is already in the set,
-+ * and -ERANGE if the address lies outside the set bounds.
-+ * If the address was not already in the set, 0 is returned.
-+ */
-+ int (*addip_kernel) (struct ip_set *set,
-+ const struct sk_buff * skb,
-+ ip_set_ip_t *ip,
-+ const u_int32_t *flags,
-+ unsigned char index);
-+
-+ /* remove IP from set (userspace: ipset -D set --entry x)
-+ * Return -EEXIST if the address is NOT in the set,
-+ * and -ERANGE if the address lies outside the set bounds.
-+ * If the address really was in the set, 0 is returned.
-+ */
-+ int (*delip) (struct ip_set *set,
-+ const void *data, size_t size,
-+ ip_set_ip_t *ip);
-+
-+ /* remove IP from set (kernel: iptables ... -j SET --entry x)
-+ * Return -EEXIST if the address is NOT in the set,
-+ * and -ERANGE if the address lies outside the set bounds.
-+ * If the address really was in the set, 0 is returned.
-+ */
-+ int (*delip_kernel) (struct ip_set *set,
-+ const struct sk_buff * skb,
-+ ip_set_ip_t *ip,
-+ const u_int32_t *flags,
-+ unsigned char index);
-+
-+ /* new set creation - allocated type specific items
-+ */
-+ int (*create) (struct ip_set *set,
-+ const void *data, size_t size);
-+
-+ /* retry the operation after successfully tweaking the set
-+ */
-+ int (*retry) (struct ip_set *set);
-+
-+ /* set destruction - free type specific items
-+ * There is no return value.
-+ * Can be called only when child sets are destroyed.
-+ */
-+ void (*destroy) (struct ip_set *set);
-+
-+ /* set flushing - reset all bits in the set, or something similar.
-+ * There is no return value.
-+ */
-+ void (*flush) (struct ip_set *set);
-+
-+ /* Listing: size needed for header
-+ */
-+ size_t header_size;
-+
-+ /* Listing: Get the header
-+ *
-+ * Fill in the information in "data".
-+ * This function is always run after list_header_size() under a
-+ * writelock on the set. Therefor is the length of "data" always
-+ * correct.
-+ */
-+ void (*list_header) (const struct ip_set *set,
-+ void *data);
-+
-+ /* Listing: Get the size for the set members
-+ */
-+ int (*list_members_size) (const struct ip_set *set);
-+
-+ /* Listing: Get the set members
-+ *
-+ * Fill in the information in "data".
-+ * This function is always run after list_member_size() under a
-+ * writelock on the set. Therefor is the length of "data" always
-+ * correct.
-+ */
-+ void (*list_members) (const struct ip_set *set,
-+ void *data);
-+
-+ char typename[IP_SET_MAXNAMELEN];
-+ unsigned char features;
-+ int protocol_version;
-+
-+ /* Set this to THIS_MODULE if you are a module, otherwise NULL */
-+ struct module *me;
-+};
-+
-+extern int ip_set_register_set_type(struct ip_set_type *set_type);
-+extern void ip_set_unregister_set_type(struct ip_set_type *set_type);
-+
-+/* A generic ipset */
-+struct ip_set {
-+ char name[IP_SET_MAXNAMELEN]; /* the name of the set */
-+ rwlock_t lock; /* lock for concurrency control */
-+ ip_set_id_t id; /* set id for swapping */
-+ ip_set_id_t binding; /* default binding for the set */
-+ atomic_t ref; /* in kernel and in hash references */
-+ struct ip_set_type *type; /* the set types */
-+ void *data; /* pooltype specific data */
-+};
-+
-+/* Structure to bind set elements to sets */
-+struct ip_set_hash {
-+ struct list_head list; /* list of clashing entries in hash */
-+ ip_set_ip_t ip; /* ip from set */
-+ ip_set_id_t id; /* set id */
-+ ip_set_id_t binding; /* set we bind the element to */
-+};
-+
-+/* register and unregister set references */
-+extern ip_set_id_t ip_set_get_byname(const char name[IP_SET_MAXNAMELEN]);
-+extern ip_set_id_t ip_set_get_byindex(ip_set_id_t id);
-+extern void ip_set_put(ip_set_id_t id);
-+
-+/* API for iptables set match, and SET target */
-+extern void ip_set_addip_kernel(ip_set_id_t id,
-+ const struct sk_buff *skb,
-+ const u_int32_t *flags);
-+extern void ip_set_delip_kernel(ip_set_id_t id,
-+ const struct sk_buff *skb,
-+ const u_int32_t *flags);
-+extern int ip_set_testip_kernel(ip_set_id_t id,
-+ const struct sk_buff *skb,
-+ const u_int32_t *flags);
-+
-+#endif /* __KERNEL__ */
-+
-+#endif /*_IP_SET_H*/
-Index: linux-2.6.21.7/include/linux/netfilter_ipv4/ip_set_iphash.h
-===================================================================
---- /dev/null
-+++ linux-2.6.21.7/include/linux/netfilter_ipv4/ip_set_iphash.h
-@@ -0,0 +1,30 @@
-+#ifndef __IP_SET_IPHASH_H
-+#define __IP_SET_IPHASH_H
-+
-+#include <linux/netfilter_ipv4/ip_set.h>
-+
-+#define SETTYPE_NAME "iphash"
-+#define MAX_RANGE 0x0000FFFF
-+
-+struct ip_set_iphash {
-+ ip_set_ip_t *members; /* the iphash proper */
-+ uint32_t elements; /* number of elements */
-+ uint32_t hashsize; /* hash size */
-+ uint16_t probes; /* max number of probes */
-+ uint16_t resize; /* resize factor in percent */
-+ ip_set_ip_t netmask; /* netmask */
-+ void *initval[0]; /* initvals for jhash_1word */
-+};
-+
-+struct ip_set_req_iphash_create {
-+ uint32_t hashsize;
-+ uint16_t probes;
-+ uint16_t resize;
-+ ip_set_ip_t netmask;
-+};
-+
-+struct ip_set_req_iphash {
-+ ip_set_ip_t ip;
-+};
-+
-+#endif /* __IP_SET_IPHASH_H */
-Index: linux-2.6.21.7/include/linux/netfilter_ipv4/ip_set_ipmap.h
-===================================================================
---- /dev/null
-+++ linux-2.6.21.7/include/linux/netfilter_ipv4/ip_set_ipmap.h
-@@ -0,0 +1,56 @@
-+#ifndef __IP_SET_IPMAP_H
-+#define __IP_SET_IPMAP_H
-+
-+#include <linux/netfilter_ipv4/ip_set.h>
-+
-+#define SETTYPE_NAME "ipmap"
-+#define MAX_RANGE 0x0000FFFF
-+
-+struct ip_set_ipmap {
-+ void *members; /* the ipmap proper */
-+ ip_set_ip_t first_ip; /* host byte order, included in range */
-+ ip_set_ip_t last_ip; /* host byte order, included in range */
-+ ip_set_ip_t netmask; /* subnet netmask */
-+ ip_set_ip_t sizeid; /* size of set in IPs */
-+ ip_set_ip_t hosts; /* number of hosts in a subnet */
-+};
-+
-+struct ip_set_req_ipmap_create {
-+ ip_set_ip_t from;
-+ ip_set_ip_t to;
-+ ip_set_ip_t netmask;
-+};
-+
-+struct ip_set_req_ipmap {
-+ ip_set_ip_t ip;
-+};
-+
-+unsigned int
-+mask_to_bits(ip_set_ip_t mask)
-+{
-+ unsigned int bits = 32;
-+ ip_set_ip_t maskaddr;
-+
-+ if (mask == 0xFFFFFFFF)
-+ return bits;
-+
-+ maskaddr = 0xFFFFFFFE;
-+ while (--bits >= 0 && maskaddr != mask)
-+ maskaddr <<= 1;
-+
-+ return bits;
-+}
-+
-+ip_set_ip_t
-+range_to_mask(ip_set_ip_t from, ip_set_ip_t to, unsigned int *bits)
-+{
-+ ip_set_ip_t mask = 0xFFFFFFFE;
-+
-+ *bits = 32;
-+ while (--(*bits) >= 0 && mask && (to & mask) != from)
-+ mask <<= 1;
-+
-+ return mask;
-+}
-+
-+#endif /* __IP_SET_IPMAP_H */
-Index: linux-2.6.21.7/include/linux/netfilter_ipv4/ip_set_ipporthash.h
-===================================================================
---- /dev/null
-+++ linux-2.6.21.7/include/linux/netfilter_ipv4/ip_set_ipporthash.h
-@@ -0,0 +1,34 @@
-+#ifndef __IP_SET_IPPORTHASH_H
-+#define __IP_SET_IPPORTHASH_H
-+
-+#include <linux/netfilter_ipv4/ip_set.h>
-+
-+#define SETTYPE_NAME "ipporthash"
-+#define MAX_RANGE 0x0000FFFF
-+#define INVALID_PORT (MAX_RANGE + 1)
-+
-+struct ip_set_ipporthash {
-+ ip_set_ip_t *members; /* the ipporthash proper */
-+ uint32_t elements; /* number of elements */
-+ uint32_t hashsize; /* hash size */
-+ uint16_t probes; /* max number of probes */
-+ uint16_t resize; /* resize factor in percent */
-+ ip_set_ip_t first_ip; /* host byte order, included in range */
-+ ip_set_ip_t last_ip; /* host byte order, included in range */
-+ void *initval[0]; /* initvals for jhash_1word */
-+};
-+
-+struct ip_set_req_ipporthash_create {
-+ uint32_t hashsize;
-+ uint16_t probes;
-+ uint16_t resize;
-+ ip_set_ip_t from;
-+ ip_set_ip_t to;
-+};
-+
-+struct ip_set_req_ipporthash {
-+ ip_set_ip_t ip;
-+ ip_set_ip_t port;
-+};
-+
-+#endif /* __IP_SET_IPPORTHASH_H */
-Index: linux-2.6.21.7/include/linux/netfilter_ipv4/ip_set_iptree.h
-===================================================================
---- /dev/null
-+++ linux-2.6.21.7/include/linux/netfilter_ipv4/ip_set_iptree.h
-@@ -0,0 +1,40 @@
-+#ifndef __IP_SET_IPTREE_H
-+#define __IP_SET_IPTREE_H
-+
-+#include <linux/netfilter_ipv4/ip_set.h>
-+
-+#define SETTYPE_NAME "iptree"
-+#define MAX_RANGE 0x0000FFFF
-+
-+struct ip_set_iptreed {
-+ unsigned long expires[256]; /* x.x.x.ADDR */
-+};
-+
-+struct ip_set_iptreec {
-+ struct ip_set_iptreed *tree[256]; /* x.x.ADDR.* */
-+};
-+
-+struct ip_set_iptreeb {
-+ struct ip_set_iptreec *tree[256]; /* x.ADDR.*.* */
-+};
-+
-+struct ip_set_iptree {
-+ unsigned int timeout;
-+ unsigned int gc_interval;
-+#ifdef __KERNEL__
-+ uint32_t elements; /* number of elements */
-+ struct timer_list gc;
-+ struct ip_set_iptreeb *tree[256]; /* ADDR.*.*.* */
-+#endif
-+};
-+
-+struct ip_set_req_iptree_create {
-+ unsigned int timeout;
-+};
-+
-+struct ip_set_req_iptree {
-+ ip_set_ip_t ip;
-+ unsigned int timeout;
-+};
-+
-+#endif /* __IP_SET_IPTREE_H */
-Index: linux-2.6.21.7/include/linux/netfilter_ipv4/ip_set_iptreemap.h
-===================================================================
---- /dev/null
-+++ linux-2.6.21.7/include/linux/netfilter_ipv4/ip_set_iptreemap.h
-@@ -0,0 +1,40 @@
-+#ifndef __IP_SET_IPTREEMAP_H
-+#define __IP_SET_IPTREEMAP_H
-+
-+#include <linux/netfilter_ipv4/ip_set.h>
-+
-+#define SETTYPE_NAME "iptreemap"
-+
-+#ifdef __KERNEL__
-+struct ip_set_iptreemap_d {
-+ unsigned char bitmap[32]; /* x.x.x.y */
-+};
-+
-+struct ip_set_iptreemap_c {
-+ struct ip_set_iptreemap_d *tree[256]; /* x.x.y.x */
-+};
-+
-+struct ip_set_iptreemap_b {
-+ struct ip_set_iptreemap_c *tree[256]; /* x.y.x.x */
-+ unsigned char dirty[32];
-+};
-+#endif
-+
-+struct ip_set_iptreemap {
-+ unsigned int gc_interval;
-+#ifdef __KERNEL__
-+ struct timer_list gc;
-+ struct ip_set_iptreemap_b *tree[256]; /* y.x.x.x */
-+#endif
-+};
-+
-+struct ip_set_req_iptreemap_create {
-+ unsigned int gc_interval;
-+};
-+
-+struct ip_set_req_iptreemap {
-+ ip_set_ip_t start;
-+ ip_set_ip_t end;
-+};
-+
-+#endif /* __IP_SET_IPTREEMAP_H */
-Index: linux-2.6.21.7/include/linux/netfilter_ipv4/ip_set_jhash.h
-===================================================================
---- /dev/null
-+++ linux-2.6.21.7/include/linux/netfilter_ipv4/ip_set_jhash.h
-@@ -0,0 +1,148 @@
-+#ifndef _LINUX_IPSET_JHASH_H
-+#define _LINUX_IPSET_JHASH_H
-+
-+/* This is a copy of linux/jhash.h but the types u32/u8 are changed
-+ * to __u32/__u8 so that the header file can be included into
-+ * userspace code as well. Jozsef Kadlecsik (kadlec@blackhole.kfki.hu)
-+ */
-+
-+/* jhash.h: Jenkins hash support.
-+ *
-+ * Copyright (C) 1996 Bob Jenkins (bob_jenkins@burtleburtle.net)
-+ *
-+ * http://burtleburtle.net/bob/hash/
-+ *
-+ * These are the credits from Bob's sources:
-+ *
-+ * lookup2.c, by Bob Jenkins, December 1996, Public Domain.
-+ * hash(), hash2(), hash3, and mix() are externally useful functions.
-+ * Routines to test the hash are included if SELF_TEST is defined.
-+ * You can use this free for any purpose. It has no warranty.
-+ *
-+ * Copyright (C) 2003 David S. Miller (davem@redhat.com)
-+ *
-+ * I've modified Bob's hash to be useful in the Linux kernel, and
-+ * any bugs present are surely my fault. -DaveM
-+ */
-+
-+/* NOTE: Arguments are modified. */
-+#define __jhash_mix(a, b, c) \
-+{ \
-+ a -= b; a -= c; a ^= (c>>13); \
-+ b -= c; b -= a; b ^= (a<<8); \
-+ c -= a; c -= b; c ^= (b>>13); \
-+ a -= b; a -= c; a ^= (c>>12); \
-+ b -= c; b -= a; b ^= (a<<16); \
-+ c -= a; c -= b; c ^= (b>>5); \
-+ a -= b; a -= c; a ^= (c>>3); \
-+ b -= c; b -= a; b ^= (a<<10); \
-+ c -= a; c -= b; c ^= (b>>15); \
-+}
-+
-+/* The golden ration: an arbitrary value */
-+#define JHASH_GOLDEN_RATIO 0x9e3779b9
-+
-+/* The most generic version, hashes an arbitrary sequence
-+ * of bytes. No alignment or length assumptions are made about
-+ * the input key.
-+ */
-+static inline __u32 jhash(void *key, __u32 length, __u32 initval)
-+{
-+ __u32 a, b, c, len;
-+ __u8 *k = key;
-+
-+ len = length;
-+ a = b = JHASH_GOLDEN_RATIO;
-+ c = initval;
-+
-+ while (len >= 12) {
-+ a += (k[0] +((__u32)k[1]<<8) +((__u32)k[2]<<16) +((__u32)k[3]<<24));
-+ b += (k[4] +((__u32)k[5]<<8) +((__u32)k[6]<<16) +((__u32)k[7]<<24));
-+ c += (k[8] +((__u32)k[9]<<8) +((__u32)k[10]<<16)+((__u32)k[11]<<24));
-+
-+ __jhash_mix(a,b,c);
-+
-+ k += 12;
-+ len -= 12;
-+ }
-+
-+ c += length;
-+ switch (len) {
-+ case 11: c += ((__u32)k[10]<<24);
-+ case 10: c += ((__u32)k[9]<<16);
-+ case 9 : c += ((__u32)k[8]<<8);
-+ case 8 : b += ((__u32)k[7]<<24);
-+ case 7 : b += ((__u32)k[6]<<16);
-+ case 6 : b += ((__u32)k[5]<<8);
-+ case 5 : b += k[4];
-+ case 4 : a += ((__u32)k[3]<<24);
-+ case 3 : a += ((__u32)k[2]<<16);
-+ case 2 : a += ((__u32)k[1]<<8);
-+ case 1 : a += k[0];
-+ };
-+
-+ __jhash_mix(a,b,c);
-+
-+ return c;
-+}
-+
-+/* A special optimized version that handles 1 or more of __u32s.
-+ * The length parameter here is the number of __u32s in the key.
-+ */
-+static inline __u32 jhash2(__u32 *k, __u32 length, __u32 initval)
-+{
-+ __u32 a, b, c, len;
-+
-+ a = b = JHASH_GOLDEN_RATIO;
-+ c = initval;
-+ len = length;
-+
-+ while (len >= 3) {
-+ a += k[0];
-+ b += k[1];
-+ c += k[2];
-+ __jhash_mix(a, b, c);
-+ k += 3; len -= 3;
-+ }
-+
-+ c += length * 4;
-+
-+ switch (len) {
-+ case 2 : b += k[1];
-+ case 1 : a += k[0];
-+ };
-+
-+ __jhash_mix(a,b,c);
-+
-+ return c;
-+}
-+
-+
-+/* A special ultra-optimized versions that knows they are hashing exactly
-+ * 3, 2 or 1 word(s).
-+ *
-+ * NOTE: In partilar the "c += length; __jhash_mix(a,b,c);" normally
-+ * done at the end is not done here.
-+ */
-+static inline __u32 jhash_3words(__u32 a, __u32 b, __u32 c, __u32 initval)
-+{
-+ a += JHASH_GOLDEN_RATIO;
-+ b += JHASH_GOLDEN_RATIO;
-+ c += initval;
-+
-+ __jhash_mix(a, b, c);
-+
-+ return c;
-+}
-+
-+static inline __u32 jhash_2words(__u32 a, __u32 b, __u32 initval)
-+{
-+ return jhash_3words(a, b, 0, initval);
-+}
-+
-+static inline __u32 jhash_1word(__u32 a, __u32 initval)
-+{
-+ return jhash_3words(a, 0, 0, initval);
-+}
-+
-+#endif /* _LINUX_IPSET_JHASH_H */
-Index: linux-2.6.21.7/include/linux/netfilter_ipv4/ip_set_macipmap.h
-===================================================================
---- /dev/null
-+++ linux-2.6.21.7/include/linux/netfilter_ipv4/ip_set_macipmap.h
-@@ -0,0 +1,38 @@
-+#ifndef __IP_SET_MACIPMAP_H
-+#define __IP_SET_MACIPMAP_H
-+
-+#include <linux/netfilter_ipv4/ip_set.h>
-+
-+#define SETTYPE_NAME "macipmap"
-+#define MAX_RANGE 0x0000FFFF
-+
-+/* general flags */
-+#define IPSET_MACIP_MATCHUNSET 1
-+
-+/* per ip flags */
-+#define IPSET_MACIP_ISSET 1
-+
-+struct ip_set_macipmap {
-+ void *members; /* the macipmap proper */
-+ ip_set_ip_t first_ip; /* host byte order, included in range */
-+ ip_set_ip_t last_ip; /* host byte order, included in range */
-+ u_int32_t flags;
-+};
-+
-+struct ip_set_req_macipmap_create {
-+ ip_set_ip_t from;
-+ ip_set_ip_t to;
-+ u_int32_t flags;
-+};
-+
-+struct ip_set_req_macipmap {
-+ ip_set_ip_t ip;
-+ unsigned char ethernet[ETH_ALEN];
-+};
-+
-+struct ip_set_macip {
-+ unsigned short flags;
-+ unsigned char ethernet[ETH_ALEN];
-+};
-+
-+#endif /* __IP_SET_MACIPMAP_H */
-Index: linux-2.6.21.7/include/linux/netfilter_ipv4/ip_set_malloc.h
-===================================================================
---- /dev/null
-+++ linux-2.6.21.7/include/linux/netfilter_ipv4/ip_set_malloc.h
-@@ -0,0 +1,116 @@
-+#ifndef _IP_SET_MALLOC_H
-+#define _IP_SET_MALLOC_H
-+
-+#ifdef __KERNEL__
-+
-+/* Memory allocation and deallocation */
-+static size_t max_malloc_size = 0;
-+
-+static inline void init_max_malloc_size(void)
-+{
-+#define CACHE(x) max_malloc_size = x;
-+#include <linux/kmalloc_sizes.h>
-+#undef CACHE
-+}
-+
-+static inline void * ip_set_malloc(size_t bytes)
-+{
-+ if (bytes > max_malloc_size)
-+ return vmalloc(bytes);
-+ else
-+ return kmalloc(bytes, GFP_KERNEL);
-+}
-+
-+static inline void ip_set_free(void * data, size_t bytes)
-+{
-+ if (bytes > max_malloc_size)
-+ vfree(data);
-+ else
-+ kfree(data);
-+}
-+
-+struct harray {
-+ size_t max_elements;
-+ void *arrays[0];
-+};
-+
-+static inline void *
-+harray_malloc(size_t hashsize, size_t typesize, int flags)
-+{
-+ struct harray *harray;
-+ size_t max_elements, size, i, j;
-+
-+ if (!max_malloc_size)
-+ init_max_malloc_size();
-+
-+ if (typesize > max_malloc_size)
-+ return NULL;
-+
-+ max_elements = max_malloc_size/typesize;
-+ size = hashsize/max_elements;
-+ if (hashsize % max_elements)
-+ size++;
-+
-+ /* Last pointer signals end of arrays */
-+ harray = kmalloc(sizeof(struct harray) + (size + 1) * sizeof(void *),
-+ flags);
-+
-+ if (!harray)
-+ return NULL;
-+
-+ for (i = 0; i < size - 1; i++) {
-+ harray->arrays[i] = kmalloc(max_elements * typesize, flags);
-+ if (!harray->arrays[i])
-+ goto undo;
-+ memset(harray->arrays[i], 0, max_elements * typesize);
-+ }
-+ harray->arrays[i] = kmalloc((hashsize - i * max_elements) * typesize,
-+ flags);
-+ if (!harray->arrays[i])
-+ goto undo;
-+ memset(harray->arrays[i], 0, (hashsize - i * max_elements) * typesize);
-+
-+ harray->max_elements = max_elements;
-+ harray->arrays[size] = NULL;
-+
-+ return (void *)harray;
-+
-+ undo:
-+ for (j = 0; j < i; j++) {
-+ kfree(harray->arrays[j]);
-+ }
-+ kfree(harray);
-+ return NULL;
-+}
-+
-+static inline void harray_free(void *h)
-+{
-+ struct harray *harray = (struct harray *) h;
-+ size_t i;
-+
-+ for (i = 0; harray->arrays[i] != NULL; i++)
-+ kfree(harray->arrays[i]);
-+ kfree(harray);
-+}
-+
-+static inline void harray_flush(void *h, size_t hashsize, size_t typesize)
-+{
-+ struct harray *harray = (struct harray *) h;
-+ size_t i;
-+
-+ for (i = 0; harray->arrays[i+1] != NULL; i++)
-+ memset(harray->arrays[i], 0, harray->max_elements * typesize);
-+ memset(harray->arrays[i], 0,
-+ (hashsize - i * harray->max_elements) * typesize);
-+}
-+
-+#define HARRAY_ELEM(h, type, which) \
-+({ \
-+ struct harray *__h = (struct harray *)(h); \
-+ ((type)((__h)->arrays[(which)/(__h)->max_elements]) \
-+ + (which)%(__h)->max_elements); \
-+})
-+
-+#endif /* __KERNEL__ */
-+
-+#endif /*_IP_SET_MALLOC_H*/
-Index: linux-2.6.21.7/include/linux/netfilter_ipv4/ip_set_nethash.h
-===================================================================
---- /dev/null
-+++ linux-2.6.21.7/include/linux/netfilter_ipv4/ip_set_nethash.h
-@@ -0,0 +1,55 @@
-+#ifndef __IP_SET_NETHASH_H
-+#define __IP_SET_NETHASH_H
-+
-+#include <linux/netfilter_ipv4/ip_set.h>
-+
-+#define SETTYPE_NAME "nethash"
-+#define MAX_RANGE 0x0000FFFF
-+
-+struct ip_set_nethash {
-+ ip_set_ip_t *members; /* the nethash proper */
-+ uint32_t elements; /* number of elements */
-+ uint32_t hashsize; /* hash size */
-+ uint16_t probes; /* max number of probes */
-+ uint16_t resize; /* resize factor in percent */
-+ unsigned char cidr[30]; /* CIDR sizes */
-+ void *initval[0]; /* initvals for jhash_1word */
-+};
-+
-+struct ip_set_req_nethash_create {
-+ uint32_t hashsize;
-+ uint16_t probes;
-+ uint16_t resize;
-+};
-+
-+struct ip_set_req_nethash {
-+ ip_set_ip_t ip;
-+ unsigned char cidr;
-+};
-+
-+static unsigned char shifts[] = {255, 253, 249, 241, 225, 193, 129, 1};
-+
-+static inline ip_set_ip_t
-+pack(ip_set_ip_t ip, unsigned char cidr)
-+{
-+ ip_set_ip_t addr, *paddr = &addr;
-+ unsigned char n, t, *a;
-+
-+ addr = htonl(ip & (0xFFFFFFFF << (32 - (cidr))));
-+#ifdef __KERNEL__
-+ DP("ip:%u.%u.%u.%u/%u", NIPQUAD(addr), cidr);
-+#endif
-+ n = cidr / 8;
-+ t = cidr % 8;
-+ a = &((unsigned char *)paddr)[n];
-+ *a = *a /(1 << (8 - t)) + shifts[t];
-+#ifdef __KERNEL__
-+ DP("n: %u, t: %u, a: %u", n, t, *a);
-+ DP("ip:%u.%u.%u.%u/%u, %u.%u.%u.%u",
-+ HIPQUAD(ip), cidr, NIPQUAD(addr));
-+#endif
-+
-+ return ntohl(addr);
-+}
-+
-+#endif /* __IP_SET_NETHASH_H */
-Index: linux-2.6.21.7/include/linux/netfilter_ipv4/ip_set_portmap.h
-===================================================================
---- /dev/null
-+++ linux-2.6.21.7/include/linux/netfilter_ipv4/ip_set_portmap.h
-@@ -0,0 +1,25 @@
-+#ifndef __IP_SET_PORTMAP_H
-+#define __IP_SET_PORTMAP_H
-+
-+#include <linux/netfilter_ipv4/ip_set.h>
-+
-+#define SETTYPE_NAME "portmap"
-+#define MAX_RANGE 0x0000FFFF
-+#define INVALID_PORT (MAX_RANGE + 1)
-+
-+struct ip_set_portmap {
-+ void *members; /* the portmap proper */
-+ ip_set_ip_t first_port; /* host byte order, included in range */
-+ ip_set_ip_t last_port; /* host byte order, included in range */
-+};
-+
-+struct ip_set_req_portmap_create {
-+ ip_set_ip_t from;
-+ ip_set_ip_t to;
-+};
-+
-+struct ip_set_req_portmap {
-+ ip_set_ip_t port;
-+};
-+
-+#endif /* __IP_SET_PORTMAP_H */
-Index: linux-2.6.21.7/include/linux/netfilter_ipv4/ipt_set.h
-===================================================================
---- /dev/null
-+++ linux-2.6.21.7/include/linux/netfilter_ipv4/ipt_set.h
-@@ -0,0 +1,21 @@
-+#ifndef _IPT_SET_H
-+#define _IPT_SET_H
-+
-+#include <linux/netfilter_ipv4/ip_set.h>
-+
-+struct ipt_set_info {
-+ ip_set_id_t index;
-+ u_int32_t flags[IP_SET_MAX_BINDINGS + 1];
-+};
-+
-+/* match info */
-+struct ipt_set_info_match {
-+ struct ipt_set_info match_set;
-+};
-+
-+struct ipt_set_info_target {
-+ struct ipt_set_info add_set;
-+ struct ipt_set_info del_set;
-+};
-+
-+#endif /*_IPT_SET_H*/
-Index: linux-2.6.21.7/net/ipv4/netfilter/ip_set.c
-===================================================================
---- /dev/null
-+++ linux-2.6.21.7/net/ipv4/netfilter/ip_set.c
-@@ -0,0 +1,2003 @@
-+/* Copyright (C) 2000-2002 Joakim Axelsson <gozem@linux.nu>
-+ * Patrick Schaaf <bof@bof.de>
-+ * Copyright (C) 2003-2004 Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
-+ *
-+ * This program is free software; you can redistribute it and/or modify
-+ * it under the terms of the GNU General Public License version 2 as
-+ * published by the Free Software Foundation.
-+ */
-+
-+/* Kernel module for IP set management */
-+
-+#include <linux/version.h>
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
-+#include <linux/config.h>
-+#endif
-+#include <linux/module.h>
-+#include <linux/moduleparam.h>
-+#include <linux/kmod.h>
-+#include <linux/ip.h>
-+#include <linux/skbuff.h>
-+#include <linux/random.h>
-+#include <linux/jhash.h>
-+#include <linux/netfilter_ipv4/ip_tables.h>
-+#include <linux/errno.h>
-+#include <asm/uaccess.h>
-+#include <asm/bitops.h>
-+#include <asm/semaphore.h>
-+#include <linux/spinlock.h>
-+#include <linux/vmalloc.h>
-+
-+#define ASSERT_READ_LOCK(x)
-+#define ASSERT_WRITE_LOCK(x)
-+#include <linux/netfilter_ipv4/ip_set.h>
-+
-+static struct list_head set_type_list; /* all registered sets */
-+static struct ip_set **ip_set_list; /* all individual sets */
-+static DEFINE_RWLOCK(ip_set_lock); /* protects the lists and the hash */
-+static DECLARE_MUTEX(ip_set_app_mutex); /* serializes user access */
-+static ip_set_id_t ip_set_max = CONFIG_IP_NF_SET_MAX;
-+static ip_set_id_t ip_set_bindings_hash_size = CONFIG_IP_NF_SET_HASHSIZE;
-+static struct list_head *ip_set_hash; /* hash of bindings */
-+static unsigned int ip_set_hash_random; /* random seed */
-+
-+/*
-+ * Sets are identified either by the index in ip_set_list or by id.
-+ * The id never changes and is used to find a key in the hash.
-+ * The index may change by swapping and used at all other places
-+ * (set/SET netfilter modules, binding value, etc.)
-+ *
-+ * Userspace requests are serialized by ip_set_mutex and sets can
-+ * be deleted only from userspace. Therefore ip_set_list locking
-+ * must obey the following rules:
-+ *
-+ * - kernel requests: read and write locking mandatory
-+ * - user requests: read locking optional, write locking mandatory
-+ */
-+
-+static inline void
-+__ip_set_get(ip_set_id_t index)
-+{
-+ atomic_inc(&ip_set_list[index]->ref);
-+}
-+
-+static inline void
-+__ip_set_put(ip_set_id_t index)
-+{
-+ atomic_dec(&ip_set_list[index]->ref);
-+}
-+
-+/*
-+ * Binding routines
-+ */
-+
-+static inline struct ip_set_hash *
-+__ip_set_find(u_int32_t key, ip_set_id_t id, ip_set_ip_t ip)
-+{
-+ struct ip_set_hash *set_hash;
-+
-+ list_for_each_entry(set_hash, &ip_set_hash[key], list)
-+ if (set_hash->id == id && set_hash->ip == ip)
-+ return set_hash;
-+
-+ return NULL;
-+}
-+
-+static ip_set_id_t
-+ip_set_find_in_hash(ip_set_id_t id, ip_set_ip_t ip)
-+{
-+ u_int32_t key = jhash_2words(id, ip, ip_set_hash_random)
-+ % ip_set_bindings_hash_size;
-+ struct ip_set_hash *set_hash;
-+
-+ ASSERT_READ_LOCK(&ip_set_lock);
-+ IP_SET_ASSERT(ip_set_list[id]);
-+ DP("set: %s, ip: %u.%u.%u.%u", ip_set_list[id]->name, HIPQUAD(ip));
-+
-+ set_hash = __ip_set_find(key, id, ip);
-+
-+ DP("set: %s, ip: %u.%u.%u.%u, binding: %s", ip_set_list[id]->name,
-+ HIPQUAD(ip),
-+ set_hash != NULL ? ip_set_list[set_hash->binding]->name : "");
-+
-+ return (set_hash != NULL ? set_hash->binding : IP_SET_INVALID_ID);
-+}
-+
-+static inline void
-+__set_hash_del(struct ip_set_hash *set_hash)
-+{
-+ ASSERT_WRITE_LOCK(&ip_set_lock);
-+ IP_SET_ASSERT(ip_set_list[set_hash->binding]);
-+
-+ __ip_set_put(set_hash->binding);
-+ list_del(&set_hash->list);
-+ kfree(set_hash);
-+}
-+
-+static int
-+ip_set_hash_del(ip_set_id_t id, ip_set_ip_t ip)
-+{
-+ u_int32_t key = jhash_2words(id, ip, ip_set_hash_random)
-+ % ip_set_bindings_hash_size;
-+ struct ip_set_hash *set_hash;
-+
-+ IP_SET_ASSERT(ip_set_list[id]);
-+ DP("set: %s, ip: %u.%u.%u.%u", ip_set_list[id]->name, HIPQUAD(ip));
-+ write_lock_bh(&ip_set_lock);
-+ set_hash = __ip_set_find(key, id, ip);
-+ DP("set: %s, ip: %u.%u.%u.%u, binding: %s", ip_set_list[id]->name,
-+ HIPQUAD(ip),
-+ set_hash != NULL ? ip_set_list[set_hash->binding]->name : "");
-+
-+ if (set_hash != NULL)
-+ __set_hash_del(set_hash);
-+ write_unlock_bh(&ip_set_lock);
-+ return 0;
-+}
-+
-+static int
-+ip_set_hash_add(ip_set_id_t id, ip_set_ip_t ip, ip_set_id_t binding)
-+{
-+ u_int32_t key = jhash_2words(id, ip, ip_set_hash_random)
-+ % ip_set_bindings_hash_size;
-+ struct ip_set_hash *set_hash;
-+ int ret = 0;
-+
-+ IP_SET_ASSERT(ip_set_list[id]);
-+ IP_SET_ASSERT(ip_set_list[binding]);
-+ DP("set: %s, ip: %u.%u.%u.%u, binding: %s", ip_set_list[id]->name,
-+ HIPQUAD(ip), ip_set_list[binding]->name);
-+ write_lock_bh(&ip_set_lock);
-+ set_hash = __ip_set_find(key, id, ip);
-+ if (!set_hash) {
-+ set_hash = kmalloc(sizeof(struct ip_set_hash), GFP_ATOMIC);
-+ if (!set_hash) {
-+ ret = -ENOMEM;
-+ goto unlock;
-+ }
-+ INIT_LIST_HEAD(&set_hash->list);
-+ set_hash->id = id;
-+ set_hash->ip = ip;
-+ list_add(&set_hash->list, &ip_set_hash[key]);
-+ } else {
-+ IP_SET_ASSERT(ip_set_list[set_hash->binding]);
-+ DP("overwrite binding: %s",
-+ ip_set_list[set_hash->binding]->name);
-+ __ip_set_put(set_hash->binding);
-+ }
-+ set_hash->binding = binding;
-+ __ip_set_get(set_hash->binding);
-+ DP("stored: key %u, id %u (%s), ip %u.%u.%u.%u, binding %u (%s)",
-+ key, id, ip_set_list[id]->name,
-+ HIPQUAD(ip), binding, ip_set_list[binding]->name);
-+ unlock:
-+ write_unlock_bh(&ip_set_lock);
-+ return ret;
-+}
-+
-+#define FOREACH_HASH_DO(fn, args...) \
-+({ \
-+ ip_set_id_t __key; \
-+ struct ip_set_hash *__set_hash; \
-+ \
-+ for (__key = 0; __key < ip_set_bindings_hash_size; __key++) { \
-+ list_for_each_entry(__set_hash, &ip_set_hash[__key], list) \
-+ fn(__set_hash , ## args); \
-+ } \
-+})
-+
-+#define FOREACH_HASH_RW_DO(fn, args...) \
-+({ \
-+ ip_set_id_t __key; \
-+ struct ip_set_hash *__set_hash, *__n; \
-+ \
-+ ASSERT_WRITE_LOCK(&ip_set_lock); \
-+ for (__key = 0; __key < ip_set_bindings_hash_size; __key++) { \
-+ list_for_each_entry_safe(__set_hash, __n, &ip_set_hash[__key], list)\
-+ fn(__set_hash , ## args); \
-+ } \
-+})
-+
-+/* Add, del and test set entries from kernel */
-+
-+#define follow_bindings(index, set, ip) \
-+((index = ip_set_find_in_hash((set)->id, ip)) != IP_SET_INVALID_ID \
-+ || (index = (set)->binding) != IP_SET_INVALID_ID)
-+
-+int
-+ip_set_testip_kernel(ip_set_id_t index,
-+ const struct sk_buff *skb,
-+ const u_int32_t *flags)
-+{
-+ struct ip_set *set;
-+ ip_set_ip_t ip;
-+ int res;
-+ unsigned char i = 0;
-+
-+ IP_SET_ASSERT(flags[i]);
-+ read_lock_bh(&ip_set_lock);
-+ do {
-+ set = ip_set_list[index];
-+ IP_SET_ASSERT(set);
-+ DP("set %s, index %u", set->name, index);
-+ read_lock_bh(&set->lock);
-+ res = set->type->testip_kernel(set, skb, &ip, flags, i++);
-+ read_unlock_bh(&set->lock);
-+ i += !!(set->type->features & IPSET_DATA_DOUBLE);
-+ } while (res > 0
-+ && flags[i]
-+ && follow_bindings(index, set, ip));
-+ read_unlock_bh(&ip_set_lock);
-+
-+ return res;
-+}
-+
-+void
-+ip_set_addip_kernel(ip_set_id_t index,
-+ const struct sk_buff *skb,
-+ const u_int32_t *flags)
-+{
-+ struct ip_set *set;
-+ ip_set_ip_t ip;
-+ int res;
-+ unsigned char i = 0;
-+
-+ IP_SET_ASSERT(flags[i]);
-+ retry:
-+ read_lock_bh(&ip_set_lock);
-+ do {
-+ set = ip_set_list[index];
-+ IP_SET_ASSERT(set);
-+ DP("set %s, index %u", set->name, index);
-+ write_lock_bh(&set->lock);
-+ res = set->type->addip_kernel(set, skb, &ip, flags, i++);
-+ write_unlock_bh(&set->lock);
-+ i += !!(set->type->features & IPSET_DATA_DOUBLE);
-+ } while ((res == 0 || res == -EEXIST)
-+ && flags[i]
-+ && follow_bindings(index, set, ip));
-+ read_unlock_bh(&ip_set_lock);
-+
-+ if (res == -EAGAIN
-+ && set->type->retry
-+ && (res = set->type->retry(set)) == 0)
-+ goto retry;
-+}
-+
-+void
-+ip_set_delip_kernel(ip_set_id_t index,
-+ const struct sk_buff *skb,
-+ const u_int32_t *flags)
-+{
-+ struct ip_set *set;
-+ ip_set_ip_t ip;
-+ int res;
-+ unsigned char i = 0;
-+
-+ IP_SET_ASSERT(flags[i]);
-+ read_lock_bh(&ip_set_lock);
-+ do {
-+ set = ip_set_list[index];
-+ IP_SET_ASSERT(set);
-+ DP("set %s, index %u", set->name, index);
-+ write_lock_bh(&set->lock);
-+ res = set->type->delip_kernel(set, skb, &ip, flags, i++);
-+ write_unlock_bh(&set->lock);
-+ i += !!(set->type->features & IPSET_DATA_DOUBLE);
-+ } while ((res == 0 || res == -EEXIST)
-+ && flags[i]
-+ && follow_bindings(index, set, ip));
-+ read_unlock_bh(&ip_set_lock);
-+}
-+
-+/* Register and deregister settype */
-+
-+static inline struct ip_set_type *
-+find_set_type(const char *name)
-+{
-+ struct ip_set_type *set_type;
-+
-+ list_for_each_entry(set_type, &set_type_list, list)
-+ if (!strncmp(set_type->typename, name, IP_SET_MAXNAMELEN - 1))
-+ return set_type;
-+ return NULL;
-+}
-+
-+int
-+ip_set_register_set_type(struct ip_set_type *set_type)
-+{
-+ int ret = 0;
-+
-+ if (set_type->protocol_version != IP_SET_PROTOCOL_VERSION) {
-+ ip_set_printk("'%s' uses wrong protocol version %u (want %u)",
-+ set_type->typename,
-+ set_type->protocol_version,
-+ IP_SET_PROTOCOL_VERSION);
-+ return -EINVAL;
-+ }
-+
-+ write_lock_bh(&ip_set_lock);
-+ if (find_set_type(set_type->typename)) {
-+ /* Duplicate! */
-+ ip_set_printk("'%s' already registered!",
-+ set_type->typename);
-+ ret = -EINVAL;
-+ goto unlock;
-+ }
-+ if (!try_module_get(THIS_MODULE)) {
-+ ret = -EFAULT;
-+ goto unlock;
-+ }
-+ list_add(&set_type->list, &set_type_list);
-+ DP("'%s' registered.", set_type->typename);
-+ unlock:
-+ write_unlock_bh(&ip_set_lock);
-+ return ret;
-+}
-+
-+void
-+ip_set_unregister_set_type(struct ip_set_type *set_type)
-+{
-+ write_lock_bh(&ip_set_lock);
-+ if (!find_set_type(set_type->typename)) {
-+ ip_set_printk("'%s' not registered?",
-+ set_type->typename);
-+ goto unlock;
-+ }
-+ list_del(&set_type->list);
-+ module_put(THIS_MODULE);
-+ DP("'%s' unregistered.", set_type->typename);
-+ unlock:
-+ write_unlock_bh(&ip_set_lock);
-+
-+}
-+
-+/*
-+ * Userspace routines
-+ */
-+
-+/*
-+ * Find set by name, reference it once. The reference makes sure the
-+ * thing pointed to, does not go away under our feet. Drop the reference
-+ * later, using ip_set_put().
-+ */
-+ip_set_id_t
-+ip_set_get_byname(const char *name)
-+{
-+ ip_set_id_t i, index = IP_SET_INVALID_ID;
-+
-+ down(&ip_set_app_mutex);
-+ for (i = 0; i < ip_set_max; i++) {
-+ if (ip_set_list[i] != NULL
-+ && strcmp(ip_set_list[i]->name, name) == 0) {
-+ __ip_set_get(i);
-+ index = i;
-+ break;
-+ }
-+ }
-+ up(&ip_set_app_mutex);
-+ return index;
-+}
-+
-+/*
-+ * Find set by index, reference it once. The reference makes sure the
-+ * thing pointed to, does not go away under our feet. Drop the reference
-+ * later, using ip_set_put().
-+ */
-+ip_set_id_t
-+ip_set_get_byindex(ip_set_id_t index)
-+{
-+ down(&ip_set_app_mutex);
-+
-+ if (index >= ip_set_max)
-+ return IP_SET_INVALID_ID;
-+
-+ if (ip_set_list[index])
-+ __ip_set_get(index);
-+ else
-+ index = IP_SET_INVALID_ID;
-+
-+ up(&ip_set_app_mutex);
-+ return index;
-+}
-+
-+/*
-+ * If the given set pointer points to a valid set, decrement
-+ * reference count by 1. The caller shall not assume the index
-+ * to be valid, after calling this function.
-+ */
-+void ip_set_put(ip_set_id_t index)
-+{
-+ down(&ip_set_app_mutex);
-+ if (ip_set_list[index])
-+ __ip_set_put(index);
-+ up(&ip_set_app_mutex);
-+}
-+
-+/* Find a set by name or index */
-+static ip_set_id_t
-+ip_set_find_byname(const char *name)
-+{
-+ ip_set_id_t i, index = IP_SET_INVALID_ID;
-+
-+ for (i = 0; i < ip_set_max; i++) {
-+ if (ip_set_list[i] != NULL
-+ && strcmp(ip_set_list[i]->name, name) == 0) {
-+ index = i;
-+ break;
-+ }
-+ }
-+ return index;
-+}
-+
-+static ip_set_id_t
-+ip_set_find_byindex(ip_set_id_t index)
-+{
-+ if (index >= ip_set_max || ip_set_list[index] == NULL)
-+ index = IP_SET_INVALID_ID;
-+
-+ return index;
-+}
-+
-+/*
-+ * Add, del, test, bind and unbind
-+ */
-+
-+static inline int
-+__ip_set_testip(struct ip_set *set,
-+ const void *data,
-+ size_t size,
-+ ip_set_ip_t *ip)
-+{
-+ int res;
-+
-+ read_lock_bh(&set->lock);
-+ res = set->type->testip(set, data, size, ip);
-+ read_unlock_bh(&set->lock);
-+
-+ return res;
-+}
-+
-+static int
-+__ip_set_addip(ip_set_id_t index,
-+ const void *data,
-+ size_t size)
-+{
-+ struct ip_set *set = ip_set_list[index];
-+ ip_set_ip_t ip;
-+ int res;
-+
-+ IP_SET_ASSERT(set);
-+ do {
-+ write_lock_bh(&set->lock);
-+ res = set->type->addip(set, data, size, &ip);
-+ write_unlock_bh(&set->lock);
-+ } while (res == -EAGAIN
-+ && set->type->retry
-+ && (res = set->type->retry(set)) == 0);
-+
-+ return res;
-+}
-+
-+static int
-+ip_set_addip(ip_set_id_t index,
-+ const void *data,
-+ size_t size)
-+{
-+
-+ return __ip_set_addip(index,
-+ data + sizeof(struct ip_set_req_adt),
-+ size - sizeof(struct ip_set_req_adt));
-+}
-+
-+static int
-+ip_set_delip(ip_set_id_t index,
-+ const void *data,
-+ size_t size)
-+{
-+ struct ip_set *set = ip_set_list[index];
-+ ip_set_ip_t ip;
-+ int res;
-+
-+ IP_SET_ASSERT(set);
-+ write_lock_bh(&set->lock);
-+ res = set->type->delip(set,
-+ data + sizeof(struct ip_set_req_adt),
-+ size - sizeof(struct ip_set_req_adt),
-+ &ip);
-+ write_unlock_bh(&set->lock);
-+
-+ return res;
-+}
-+
-+static int
-+ip_set_testip(ip_set_id_t index,
-+ const void *data,
-+ size_t size)
-+{
-+ struct ip_set *set = ip_set_list[index];
-+ ip_set_ip_t ip;
-+ int res;
-+
-+ IP_SET_ASSERT(set);
-+ res = __ip_set_testip(set,
-+ data + sizeof(struct ip_set_req_adt),
-+ size - sizeof(struct ip_set_req_adt),
-+ &ip);
-+
-+ return (res > 0 ? -EEXIST : res);
-+}
-+
-+static int
-+ip_set_bindip(ip_set_id_t index,
-+ const void *data,
-+ size_t size)
-+{
-+ struct ip_set *set = ip_set_list[index];
-+ struct ip_set_req_bind *req_bind;
-+ ip_set_id_t binding;
-+ ip_set_ip_t ip;
-+ int res;
-+
-+ IP_SET_ASSERT(set);
-+ if (size < sizeof(struct ip_set_req_bind))
-+ return -EINVAL;
-+
-+ req_bind = (struct ip_set_req_bind *) data;
-+ req_bind->binding[IP_SET_MAXNAMELEN - 1] = '\0';
-+
-+ if (strcmp(req_bind->binding, IPSET_TOKEN_DEFAULT) == 0) {
-+ /* Default binding of a set */
-+ char *binding_name;
-+
-+ if (size != sizeof(struct ip_set_req_bind) + IP_SET_MAXNAMELEN)
-+ return -EINVAL;
-+
-+ binding_name = (char *)(data + sizeof(struct ip_set_req_bind));
-+ binding_name[IP_SET_MAXNAMELEN - 1] = '\0';
-+
-+ binding = ip_set_find_byname(binding_name);
-+ if (binding == IP_SET_INVALID_ID)
-+ return -ENOENT;
-+
-+ write_lock_bh(&ip_set_lock);
-+ /* Sets as binding values are referenced */
-+ if (set->binding != IP_SET_INVALID_ID)
-+ __ip_set_put(set->binding);
-+ set->binding = binding;
-+ __ip_set_get(set->binding);
-+ write_unlock_bh(&ip_set_lock);
-+
-+ return 0;
-+ }
-+ binding = ip_set_find_byname(req_bind->binding);
-+ if (binding == IP_SET_INVALID_ID)
-+ return -ENOENT;
-+
-+ res = __ip_set_testip(set,
-+ data + sizeof(struct ip_set_req_bind),
-+ size - sizeof(struct ip_set_req_bind),
-+ &ip);
-+ DP("set %s, ip: %u.%u.%u.%u, binding %s",
-+ set->name, HIPQUAD(ip), ip_set_list[binding]->name);
-+
-+ if (res >= 0)
-+ res = ip_set_hash_add(set->id, ip, binding);
-+
-+ return res;
-+}
-+
-+#define FOREACH_SET_DO(fn, args...) \
-+({ \
-+ ip_set_id_t __i; \
-+ struct ip_set *__set; \
-+ \
-+ for (__i = 0; __i < ip_set_max; __i++) { \
-+ __set = ip_set_list[__i]; \
-+ if (__set != NULL) \
-+ fn(__set , ##args); \
-+ } \
-+})
-+
-+static inline void
-+__set_hash_del_byid(struct ip_set_hash *set_hash, ip_set_id_t id)
-+{
-+ if (set_hash->id == id)
-+ __set_hash_del(set_hash);
-+}
-+
-+static inline void
-+__unbind_default(struct ip_set *set)
-+{
-+ if (set->binding != IP_SET_INVALID_ID) {
-+ /* Sets as binding values are referenced */
-+ __ip_set_put(set->binding);
-+ set->binding = IP_SET_INVALID_ID;
-+ }
-+}
-+
-+static int
-+ip_set_unbindip(ip_set_id_t index,
-+ const void *data,
-+ size_t size)
-+{
-+ struct ip_set *set;
-+ struct ip_set_req_bind *req_bind;
-+ ip_set_ip_t ip;
-+ int res;
-+
-+ DP("");
-+ if (size < sizeof(struct ip_set_req_bind))
-+ return -EINVAL;
-+
-+ req_bind = (struct ip_set_req_bind *) data;
-+ req_bind->binding[IP_SET_MAXNAMELEN - 1] = '\0';
-+
-+ DP("%u %s", index, req_bind->binding);
-+ if (index == IP_SET_INVALID_ID) {
-+ /* unbind :all: */
-+ if (strcmp(req_bind->binding, IPSET_TOKEN_DEFAULT) == 0) {
-+ /* Default binding of sets */
-+ write_lock_bh(&ip_set_lock);
-+ FOREACH_SET_DO(__unbind_default);
-+ write_unlock_bh(&ip_set_lock);
-+ return 0;
-+ } else if (strcmp(req_bind->binding, IPSET_TOKEN_ALL) == 0) {
-+ /* Flush all bindings of all sets*/
-+ write_lock_bh(&ip_set_lock);
-+ FOREACH_HASH_RW_DO(__set_hash_del);
-+ write_unlock_bh(&ip_set_lock);
-+ return 0;
-+ }
-+ DP("unreachable reached!");
-+ return -EINVAL;
-+ }
-+
-+ set = ip_set_list[index];
-+ IP_SET_ASSERT(set);
-+ if (strcmp(req_bind->binding, IPSET_TOKEN_DEFAULT) == 0) {
-+ /* Default binding of set */
-+ ip_set_id_t binding = ip_set_find_byindex(set->binding);
-+
-+ if (binding == IP_SET_INVALID_ID)
-+ return -ENOENT;
-+
-+ write_lock_bh(&ip_set_lock);
-+ /* Sets in hash values are referenced */
-+ __ip_set_put(set->binding);
-+ set->binding = IP_SET_INVALID_ID;
-+ write_unlock_bh(&ip_set_lock);
-+
-+ return 0;
-+ } else if (strcmp(req_bind->binding, IPSET_TOKEN_ALL) == 0) {
-+ /* Flush all bindings */
-+
-+ write_lock_bh(&ip_set_lock);
-+ FOREACH_HASH_RW_DO(__set_hash_del_byid, set->id);
-+ write_unlock_bh(&ip_set_lock);
-+ return 0;
-+ }
-+
-+ res = __ip_set_testip(set,
-+ data + sizeof(struct ip_set_req_bind),
-+ size - sizeof(struct ip_set_req_bind),
-+ &ip);
-+
-+ DP("set %s, ip: %u.%u.%u.%u", set->name, HIPQUAD(ip));
-+ if (res >= 0)
-+ res = ip_set_hash_del(set->id, ip);
-+
-+ return res;
-+}
-+
-+static int
-+ip_set_testbind(ip_set_id_t index,
-+ const void *data,
-+ size_t size)
-+{
-+ struct ip_set *set = ip_set_list[index];
-+ struct ip_set_req_bind *req_bind;
-+ ip_set_id_t binding;
-+ ip_set_ip_t ip;
-+ int res;
-+
-+ IP_SET_ASSERT(set);
-+ if (size < sizeof(struct ip_set_req_bind))
-+ return -EINVAL;
-+
-+ req_bind = (struct ip_set_req_bind *) data;
-+ req_bind->binding[IP_SET_MAXNAMELEN - 1] = '\0';
-+
-+ if (strcmp(req_bind->binding, IPSET_TOKEN_DEFAULT) == 0) {
-+ /* Default binding of set */
-+ char *binding_name;
-+
-+ if (size != sizeof(struct ip_set_req_bind) + IP_SET_MAXNAMELEN)
-+ return -EINVAL;
-+
-+ binding_name = (char *)(data + sizeof(struct ip_set_req_bind));
-+ binding_name[IP_SET_MAXNAMELEN - 1] = '\0';
-+
-+ binding = ip_set_find_byname(binding_name);
-+ if (binding == IP_SET_INVALID_ID)
-+ return -ENOENT;
-+
-+ res = (set->binding == binding) ? -EEXIST : 0;
-+
-+ return res;
-+ }
-+ binding = ip_set_find_byname(req_bind->binding);
-+ if (binding == IP_SET_INVALID_ID)
-+ return -ENOENT;
-+
-+
-+ res = __ip_set_testip(set,
-+ data + sizeof(struct ip_set_req_bind),
-+ size - sizeof(struct ip_set_req_bind),
-+ &ip);
-+ DP("set %s, ip: %u.%u.%u.%u, binding %s",
-+ set->name, HIPQUAD(ip), ip_set_list[binding]->name);
-+
-+ if (res >= 0)
-+ res = (ip_set_find_in_hash(set->id, ip) == binding)
-+ ? -EEXIST : 0;
-+
-+ return res;
-+}
-+
-+static struct ip_set_type *
-+find_set_type_rlock(const char *typename)
-+{
-+ struct ip_set_type *type;
-+
-+ read_lock_bh(&ip_set_lock);
-+ type = find_set_type(typename);
-+ if (type == NULL)
-+ read_unlock_bh(&ip_set_lock);
-+
-+ return type;
-+}
-+
-+static int
-+find_free_id(const char *name,
-+ ip_set_id_t *index,
-+ ip_set_id_t *id)
-+{
-+ ip_set_id_t i;
-+
-+ *id = IP_SET_INVALID_ID;
-+ for (i = 0; i < ip_set_max; i++) {
-+ if (ip_set_list[i] == NULL) {
-+ if (*id == IP_SET_INVALID_ID)
-+ *id = *index = i;
-+ } else if (strcmp(name, ip_set_list[i]->name) == 0)
-+ /* Name clash */
-+ return -EEXIST;
-+ }
-+ if (*id == IP_SET_INVALID_ID)
-+ /* No free slot remained */
-+ return -ERANGE;
-+ /* Check that index is usable as id (swapping) */
-+ check:
-+ for (i = 0; i < ip_set_max; i++) {
-+ if (ip_set_list[i] != NULL
-+ && ip_set_list[i]->id == *id) {
-+ *id = i;
-+ goto check;
-+ }
-+ }
-+ return 0;
-+}
-+
-+/*
-+ * Create a set
-+ */
-+static int
-+ip_set_create(const char *name,
-+ const char *typename,
-+ ip_set_id_t restore,
-+ const void *data,
-+ size_t size)
-+{
-+ struct ip_set *set;
-+ ip_set_id_t index = 0, id;
-+ int res = 0;
-+
-+ DP("setname: %s, typename: %s, id: %u", name, typename, restore);
-+ /*
-+ * First, and without any locks, allocate and initialize
-+ * a normal base set structure.
-+ */
-+ set = kmalloc(sizeof(struct ip_set), GFP_KERNEL);
-+ if (!set)
-+ return -ENOMEM;
-+ set->lock = RW_LOCK_UNLOCKED;
-+ strncpy(set->name, name, IP_SET_MAXNAMELEN);
-+ set->binding = IP_SET_INVALID_ID;
-+ atomic_set(&set->ref, 0);
-+
-+ /*
-+ * Next, take the &ip_set_lock, check that we know the type,
-+ * and take a reference on the type, to make sure it
-+ * stays available while constructing our new set.
-+ *
-+ * After referencing the type, we drop the &ip_set_lock,
-+ * and let the new set construction run without locks.
-+ */
-+ set->type = find_set_type_rlock(typename);
-+ if (set->type == NULL) {
-+ /* Try loading the module */
-+ char modulename[IP_SET_MAXNAMELEN + strlen("ip_set_") + 1];
-+ strcpy(modulename, "ip_set_");
-+ strcat(modulename, typename);
-+ DP("try to load %s", modulename);
-+ request_module(modulename);
-+ set->type = find_set_type_rlock(typename);
-+ }
-+ if (set->type == NULL) {
-+ ip_set_printk("no set type '%s', set '%s' not created",
-+ typename, name);
-+ res = -ENOENT;
-+ goto out;
-+ }
-+ if (!try_module_get(set->type->me)) {
-+ read_unlock_bh(&ip_set_lock);
-+ res = -EFAULT;
-+ goto out;
-+ }
-+ read_unlock_bh(&ip_set_lock);
-+
-+ /*
-+ * Without holding any locks, create private part.
-+ */
-+ res = set->type->create(set, data, size);
-+ if (res != 0)
-+ goto put_out;
-+
-+ /* BTW, res==0 here. */
-+
-+ /*
-+ * Here, we have a valid, constructed set. &ip_set_lock again,
-+ * find free id/index and check that it is not already in
-+ * ip_set_list.
-+ */
-+ write_lock_bh(&ip_set_lock);
-+ if ((res = find_free_id(set->name, &index, &id)) != 0) {
-+ DP("no free id!");
-+ goto cleanup;
-+ }
-+
-+ /* Make sure restore gets the same index */
-+ if (restore != IP_SET_INVALID_ID && index != restore) {
-+ DP("Can't restore, sets are screwed up");
-+ res = -ERANGE;
-+ goto cleanup;
-+ }
-+
-+ /*
-+ * Finally! Add our shiny new set to the list, and be done.
-+ */
-+ DP("create: '%s' created with index %u, id %u!", set->name, index, id);
-+ set->id = id;
-+ ip_set_list[index] = set;
-+ write_unlock_bh(&ip_set_lock);
-+ return res;
-+
-+ cleanup:
-+ write_unlock_bh(&ip_set_lock);
-+ set->type->destroy(set);
-+ put_out:
-+ module_put(set->type->me);
-+ out:
-+ kfree(set);
-+ return res;
-+}
-+
-+/*
-+ * Destroy a given existing set
-+ */
-+static void
-+ip_set_destroy_set(ip_set_id_t index)
-+{
-+ struct ip_set *set = ip_set_list[index];
-+
-+ IP_SET_ASSERT(set);
-+ DP("set: %s", set->name);
-+ write_lock_bh(&ip_set_lock);
-+ FOREACH_HASH_RW_DO(__set_hash_del_byid, set->id);
-+ if (set->binding != IP_SET_INVALID_ID)
-+ __ip_set_put(set->binding);
-+ ip_set_list[index] = NULL;
-+ write_unlock_bh(&ip_set_lock);
-+
-+ /* Must call it without holding any lock */
-+ set->type->destroy(set);
-+ module_put(set->type->me);
-+ kfree(set);
-+}
-+
-+/*
-+ * Destroy a set - or all sets
-+ * Sets must not be referenced/used.
-+ */
-+static int
-+ip_set_destroy(ip_set_id_t index)
-+{
-+ ip_set_id_t i;
-+
-+ /* ref modification always protected by the mutex */
-+ if (index != IP_SET_INVALID_ID) {
-+ if (atomic_read(&ip_set_list[index]->ref))
-+ return -EBUSY;
-+ ip_set_destroy_set(index);
-+ } else {
-+ for (i = 0; i < ip_set_max; i++) {
-+ if (ip_set_list[i] != NULL
-+ && (atomic_read(&ip_set_list[i]->ref)))
-+ return -EBUSY;
-+ }
-+
-+ for (i = 0; i < ip_set_max; i++) {
-+ if (ip_set_list[i] != NULL)
-+ ip_set_destroy_set(i);
-+ }
-+ }
-+ return 0;
-+}
-+
-+static void
-+ip_set_flush_set(struct ip_set *set)
-+{
-+ DP("set: %s %u", set->name, set->id);
-+
-+ write_lock_bh(&set->lock);
-+ set->type->flush(set);
-+ write_unlock_bh(&set->lock);
-+}
-+
-+/*
-+ * Flush data in a set - or in all sets
-+ */
-+static int
-+ip_set_flush(ip_set_id_t index)
-+{
-+ if (index != IP_SET_INVALID_ID) {
-+ IP_SET_ASSERT(ip_set_list[index]);
-+ ip_set_flush_set(ip_set_list[index]);
-+ } else
-+ FOREACH_SET_DO(ip_set_flush_set);
-+
-+ return 0;
-+}
-+
-+/* Rename a set */
-+static int
-+ip_set_rename(ip_set_id_t index, const char *name)
-+{
-+ struct ip_set *set = ip_set_list[index];
-+ ip_set_id_t i;
-+ int res = 0;
-+
-+ DP("set: %s to %s", set->name, name);
-+ write_lock_bh(&ip_set_lock);
-+ for (i = 0; i < ip_set_max; i++) {
-+ if (ip_set_list[i] != NULL
-+ && strncmp(ip_set_list[i]->name,
-+ name,
-+ IP_SET_MAXNAMELEN - 1) == 0) {
-+ res = -EEXIST;
-+ goto unlock;
-+ }
-+ }
-+ strncpy(set->name, name, IP_SET_MAXNAMELEN);
-+ unlock:
-+ write_unlock_bh(&ip_set_lock);
-+ return res;
-+}
-+
-+/*
-+ * Swap two sets so that name/index points to the other.
-+ * References are also swapped.
-+ */
-+static int
-+ip_set_swap(ip_set_id_t from_index, ip_set_id_t to_index)
-+{
-+ struct ip_set *from = ip_set_list[from_index];
-+ struct ip_set *to = ip_set_list[to_index];
-+ char from_name[IP_SET_MAXNAMELEN];
-+ u_int32_t from_ref;
-+
-+ DP("set: %s to %s", from->name, to->name);
-+ /* Features must not change. Artifical restriction. */
-+ if (from->type->features != to->type->features)
-+ return -ENOEXEC;
-+
-+ /* No magic here: ref munging protected by the mutex */
-+ write_lock_bh(&ip_set_lock);
-+ strncpy(from_name, from->name, IP_SET_MAXNAMELEN);
-+ from_ref = atomic_read(&from->ref);
-+
-+ strncpy(from->name, to->name, IP_SET_MAXNAMELEN);
-+ atomic_set(&from->ref, atomic_read(&to->ref));
-+ strncpy(to->name, from_name, IP_SET_MAXNAMELEN);
-+ atomic_set(&to->ref, from_ref);
-+
-+ ip_set_list[from_index] = to;
-+ ip_set_list[to_index] = from;
-+
-+ write_unlock_bh(&ip_set_lock);
-+ return 0;
-+}
-+
-+/*
-+ * List set data
-+ */
-+
-+static inline void
-+__set_hash_bindings_size_list(struct ip_set_hash *set_hash,
-+ ip_set_id_t id, size_t *size)
-+{
-+ if (set_hash->id == id)
-+ *size += sizeof(struct ip_set_hash_list);
-+}
-+
-+static inline void
-+__set_hash_bindings_size_save(struct ip_set_hash *set_hash,
-+ ip_set_id_t id, size_t *size)
-+{
-+ if (set_hash->id == id)
-+ *size += sizeof(struct ip_set_hash_save);
-+}
-+
-+static inline void
-+__set_hash_bindings(struct ip_set_hash *set_hash,
-+ ip_set_id_t id, void *data, int *used)
-+{
-+ if (set_hash->id == id) {
-+ struct ip_set_hash_list *hash_list =
-+ (struct ip_set_hash_list *)(data + *used);
-+
-+ hash_list->ip = set_hash->ip;
-+ hash_list->binding = set_hash->binding;
-+ *used += sizeof(struct ip_set_hash_list);
-+ }
-+}
-+
-+static int ip_set_list_set(ip_set_id_t index,
-+ void *data,
-+ int *used,
-+ int len)
-+{
-+ struct ip_set *set = ip_set_list[index];
-+ struct ip_set_list *set_list;
-+
-+ /* Pointer to our header */
-+ set_list = (struct ip_set_list *) (data + *used);
-+
-+ DP("set: %s, used: %d %p %p", set->name, *used, data, data + *used);
-+
-+ /* Get and ensure header size */
-+ if (*used + sizeof(struct ip_set_list) > len)
-+ goto not_enough_mem;
-+ *used += sizeof(struct ip_set_list);
-+
-+ read_lock_bh(&set->lock);
-+ /* Get and ensure set specific header size */
-+ set_list->header_size = set->type->header_size;
-+ if (*used + set_list->header_size > len)
-+ goto unlock_set;
-+
-+ /* Fill in the header */
-+ set_list->index = index;
-+ set_list->binding = set->binding;
-+ set_list->ref = atomic_read(&set->ref);
-+
-+ /* Fill in set spefific header data */
-+ set->type->list_header(set, data + *used);
-+ *used += set_list->header_size;
-+
-+ /* Get and ensure set specific members size */
-+ set_list->members_size = set->type->list_members_size(set);
-+ if (*used + set_list->members_size > len)
-+ goto unlock_set;
-+
-+ /* Fill in set spefific members data */
-+ set->type->list_members(set, data + *used);
-+ *used += set_list->members_size;
-+ read_unlock_bh(&set->lock);
-+
-+ /* Bindings */
-+
-+ /* Get and ensure set specific bindings size */
-+ set_list->bindings_size = 0;
-+ FOREACH_HASH_DO(__set_hash_bindings_size_list,
-+ set->id, &set_list->bindings_size);
-+ if (*used + set_list->bindings_size > len)
-+ goto not_enough_mem;
-+
-+ /* Fill in set spefific bindings data */
-+ FOREACH_HASH_DO(__set_hash_bindings, set->id, data, used);
-+
-+ return 0;
-+
-+ unlock_set:
-+ read_unlock_bh(&set->lock);
-+ not_enough_mem:
-+ DP("not enough mem, try again");
-+ return -EAGAIN;
-+}
-+
-+/*
-+ * Save sets
-+ */
-+static int ip_set_save_set(ip_set_id_t index,
-+ void *data,
-+ int *used,
-+ int len)
-+{
-+ struct ip_set *set;
-+ struct ip_set_save *set_save;
-+
-+ /* Pointer to our header */
-+ set_save = (struct ip_set_save *) (data + *used);
-+
-+ /* Get and ensure header size */
-+ if (*used + sizeof(struct ip_set_save) > len)
-+ goto not_enough_mem;
-+ *used += sizeof(struct ip_set_save);
-+
-+ set = ip_set_list[index];
-+ DP("set: %s, used: %u(%u) %p %p", set->name, *used, len,
-+ data, data + *used);
-+
-+ read_lock_bh(&set->lock);
-+ /* Get and ensure set specific header size */
-+ set_save->header_size = set->type->header_size;
-+ if (*used + set_save->header_size > len)
-+ goto unlock_set;
-+
-+ /* Fill in the header */
-+ set_save->index = index;
-+ set_save->binding = set->binding;
-+
-+ /* Fill in set spefific header data */
-+ set->type->list_header(set, data + *used);
-+ *used += set_save->header_size;
-+
-+ DP("set header filled: %s, used: %u(%u) %p %p", set->name, *used,
-+ set_save->header_size, data, data + *used);
-+ /* Get and ensure set specific members size */
-+ set_save->members_size = set->type->list_members_size(set);
-+ if (*used + set_save->members_size > len)
-+ goto unlock_set;
-+
-+ /* Fill in set spefific members data */
-+ set->type->list_members(set, data + *used);
-+ *used += set_save->members_size;
-+ read_unlock_bh(&set->lock);
-+ DP("set members filled: %s, used: %u(%u) %p %p", set->name, *used,
-+ set_save->members_size, data, data + *used);
-+ return 0;
-+
-+ unlock_set:
-+ read_unlock_bh(&set->lock);
-+ not_enough_mem:
-+ DP("not enough mem, try again");
-+ return -EAGAIN;
-+}
-+
-+static inline void
-+__set_hash_save_bindings(struct ip_set_hash *set_hash,
-+ ip_set_id_t id,
-+ void *data,
-+ int *used,
-+ int len,
-+ int *res)
-+{
-+ if (*res == 0
-+ && (id == IP_SET_INVALID_ID || set_hash->id == id)) {
-+ struct ip_set_hash_save *hash_save =
-+ (struct ip_set_hash_save *)(data + *used);
-+ /* Ensure bindings size */
-+ if (*used + sizeof(struct ip_set_hash_save) > len) {
-+ *res = -ENOMEM;
-+ return;
-+ }
-+ hash_save->id = set_hash->id;
-+ hash_save->ip = set_hash->ip;
-+ hash_save->binding = set_hash->binding;
-+ *used += sizeof(struct ip_set_hash_save);
-+ }
-+}
-+
-+static int ip_set_save_bindings(ip_set_id_t index,
-+ void *data,
-+ int *used,
-+ int len)
-+{
-+ int res = 0;
-+ struct ip_set_save *set_save;
-+
-+ DP("used %u, len %u", *used, len);
-+ /* Get and ensure header size */
-+ if (*used + sizeof(struct ip_set_save) > len)
-+ return -ENOMEM;
-+
-+ /* Marker */
-+ set_save = (struct ip_set_save *) (data + *used);
-+ set_save->index = IP_SET_INVALID_ID;
-+ set_save->header_size = 0;
-+ set_save->members_size = 0;
-+ *used += sizeof(struct ip_set_save);
-+
-+ DP("marker added used %u, len %u", *used, len);
-+ /* Fill in bindings data */
-+ if (index != IP_SET_INVALID_ID)
-+ /* Sets are identified by id in hash */
-+ index = ip_set_list[index]->id;
-+ FOREACH_HASH_DO(__set_hash_save_bindings, index, data, used, len, &res);
-+
-+ return res;
-+}
-+
-+/*
-+ * Restore sets
-+ */
-+static int ip_set_restore(void *data,
-+ int len)
-+{
-+ int res = 0;
-+ int line = 0, used = 0, members_size;
-+ struct ip_set *set;
-+ struct ip_set_hash_save *hash_save;
-+ struct ip_set_restore *set_restore;
-+ ip_set_id_t index;
-+
-+ /* Loop to restore sets */
-+ while (1) {
-+ line++;
-+
-+ DP("%u %u %u", used, sizeof(struct ip_set_restore), len);
-+ /* Get and ensure header size */
-+ if (used + sizeof(struct ip_set_restore) > len)
-+ return line;
-+ set_restore = (struct ip_set_restore *) (data + used);
-+ used += sizeof(struct ip_set_restore);
-+
-+ /* Ensure data size */
-+ if (used
-+ + set_restore->header_size
-+ + set_restore->members_size > len)
-+ return line;
-+
-+ /* Check marker */
-+ if (set_restore->index == IP_SET_INVALID_ID) {
-+ line--;
-+ goto bindings;
-+ }
-+
-+ /* Try to create the set */
-+ DP("restore %s %s", set_restore->name, set_restore->typename);
-+ res = ip_set_create(set_restore->name,
-+ set_restore->typename,
-+ set_restore->index,
-+ data + used,
-+ set_restore->header_size);
-+
-+ if (res != 0)
-+ return line;
-+ used += set_restore->header_size;
-+
-+ index = ip_set_find_byindex(set_restore->index);
-+ DP("index %u, restore_index %u", index, set_restore->index);
-+ if (index != set_restore->index)
-+ return line;
-+ /* Try to restore members data */
-+ set = ip_set_list[index];
-+ members_size = 0;
-+ DP("members_size %u reqsize %u",
-+ set_restore->members_size, set->type->reqsize);
-+ while (members_size + set->type->reqsize <=
-+ set_restore->members_size) {
-+ line++;
-+ DP("members: %u, line %u", members_size, line);
-+ res = __ip_set_addip(index,
-+ data + used + members_size,
-+ set->type->reqsize);
-+ if (!(res == 0 || res == -EEXIST))
-+ return line;
-+ members_size += set->type->reqsize;
-+ }
-+
-+ DP("members_size %u %u",
-+ set_restore->members_size, members_size);
-+ if (members_size != set_restore->members_size)
-+ return line++;
-+ used += set_restore->members_size;
-+ }
-+
-+ bindings:
-+ /* Loop to restore bindings */
-+ while (used < len) {
-+ line++;
-+
-+ DP("restore binding, line %u", line);
-+ /* Get and ensure size */
-+ if (used + sizeof(struct ip_set_hash_save) > len)
-+ return line;
-+ hash_save = (struct ip_set_hash_save *) (data + used);
-+ used += sizeof(struct ip_set_hash_save);
-+
-+ /* hash_save->id is used to store the index */
-+ index = ip_set_find_byindex(hash_save->id);
-+ DP("restore binding index %u, id %u, %u -> %u",
-+ index, hash_save->id, hash_save->ip, hash_save->binding);
-+ if (index != hash_save->id)
-+ return line;
-+ if (ip_set_find_byindex(hash_save->binding) == IP_SET_INVALID_ID) {
-+ DP("corrupt binding set index %u", hash_save->binding);
-+ return line;
-+ }
-+ set = ip_set_list[hash_save->id];
-+ /* Null valued IP means default binding */
-+ if (hash_save->ip)
-+ res = ip_set_hash_add(set->id,
-+ hash_save->ip,
-+ hash_save->binding);
-+ else {
-+ IP_SET_ASSERT(set->binding == IP_SET_INVALID_ID);
-+ write_lock_bh(&ip_set_lock);
-+ set->binding = hash_save->binding;
-+ __ip_set_get(set->binding);
-+ write_unlock_bh(&ip_set_lock);
-+ DP("default binding: %u", set->binding);
-+ }
-+ if (res != 0)
-+ return line;
-+ }
-+ if (used != len)
-+ return line;
-+
-+ return 0;
-+}
-+
-+static int
-+ip_set_sockfn_set(struct sock *sk, int optval, void *user, unsigned int len)
-+{
-+ void *data;
-+ int res = 0; /* Assume OK */
-+ unsigned *op;
-+ struct ip_set_req_adt *req_adt;
-+ ip_set_id_t index = IP_SET_INVALID_ID;
-+ int (*adtfn)(ip_set_id_t index,
-+ const void *data, size_t size);
-+ struct fn_table {
-+ int (*fn)(ip_set_id_t index,
-+ const void *data, size_t size);
-+ } adtfn_table[] =
-+ { { ip_set_addip }, { ip_set_delip }, { ip_set_testip},
-+ { ip_set_bindip}, { ip_set_unbindip }, { ip_set_testbind },
-+ };
-+
-+ DP("optval=%d, user=%p, len=%d", optval, user, len);
-+ if (!capable(CAP_NET_ADMIN))
-+ return -EPERM;
-+ if (optval != SO_IP_SET)
-+ return -EBADF;
-+ if (len <= sizeof(unsigned)) {
-+ ip_set_printk("short userdata (want >%zu, got %u)",
-+ sizeof(unsigned), len);
-+ return -EINVAL;
-+ }
-+ data = vmalloc(len);
-+ if (!data) {
-+ DP("out of mem for %u bytes", len);
-+ return -ENOMEM;
-+ }
-+ if (copy_from_user(data, user, len) != 0) {
-+ res = -EFAULT;
-+ goto done;
-+ }
-+ if (down_interruptible(&ip_set_app_mutex)) {
-+ res = -EINTR;
-+ goto done;
-+ }
-+
-+ op = (unsigned *)data;
-+ DP("op=%x", *op);
-+
-+ if (*op < IP_SET_OP_VERSION) {
-+ /* Check the version at the beginning of operations */
-+ struct ip_set_req_version *req_version =
-+ (struct ip_set_req_version *) data;
-+ if (req_version->version != IP_SET_PROTOCOL_VERSION) {
-+ res = -EPROTO;
-+ goto done;
-+ }
-+ }
-+
-+ switch (*op) {
-+ case IP_SET_OP_CREATE:{
-+ struct ip_set_req_create *req_create
-+ = (struct ip_set_req_create *) data;
-+
-+ if (len < sizeof(struct ip_set_req_create)) {
-+ ip_set_printk("short CREATE data (want >=%zu, got %u)",
-+ sizeof(struct ip_set_req_create), len);
-+ res = -EINVAL;
-+ goto done;
-+ }
-+ req_create->name[IP_SET_MAXNAMELEN - 1] = '\0';
-+ req_create->typename[IP_SET_MAXNAMELEN - 1] = '\0';
-+ res = ip_set_create(req_create->name,
-+ req_create->typename,
-+ IP_SET_INVALID_ID,
-+ data + sizeof(struct ip_set_req_create),
-+ len - sizeof(struct ip_set_req_create));
-+ goto done;
-+ }
-+ case IP_SET_OP_DESTROY:{
-+ struct ip_set_req_std *req_destroy
-+ = (struct ip_set_req_std *) data;
-+
-+ if (len != sizeof(struct ip_set_req_std)) {
-+ ip_set_printk("invalid DESTROY data (want %zu, got %u)",
-+ sizeof(struct ip_set_req_std), len);
-+ res = -EINVAL;
-+ goto done;
-+ }
-+ if (strcmp(req_destroy->name, IPSET_TOKEN_ALL) == 0) {
-+ /* Destroy all sets */
-+ index = IP_SET_INVALID_ID;
-+ } else {
-+ req_destroy->name[IP_SET_MAXNAMELEN - 1] = '\0';
-+ index = ip_set_find_byname(req_destroy->name);
-+
-+ if (index == IP_SET_INVALID_ID) {
-+ res = -ENOENT;
-+ goto done;
-+ }
-+ }
-+
-+ res = ip_set_destroy(index);
-+ goto done;
-+ }
-+ case IP_SET_OP_FLUSH:{
-+ struct ip_set_req_std *req_flush =
-+ (struct ip_set_req_std *) data;
-+
-+ if (len != sizeof(struct ip_set_req_std)) {
-+ ip_set_printk("invalid FLUSH data (want %zu, got %u)",
-+ sizeof(struct ip_set_req_std), len);
-+ res = -EINVAL;
-+ goto done;
-+ }
-+ if (strcmp(req_flush->name, IPSET_TOKEN_ALL) == 0) {
-+ /* Flush all sets */
-+ index = IP_SET_INVALID_ID;
-+ } else {
-+ req_flush->name[IP_SET_MAXNAMELEN - 1] = '\0';
-+ index = ip_set_find_byname(req_flush->name);
-+
-+ if (index == IP_SET_INVALID_ID) {
-+ res = -ENOENT;
-+ goto done;
-+ }
-+ }
-+ res = ip_set_flush(index);
-+ goto done;
-+ }
-+ case IP_SET_OP_RENAME:{
-+ struct ip_set_req_create *req_rename
-+ = (struct ip_set_req_create *) data;
-+
-+ if (len != sizeof(struct ip_set_req_create)) {
-+ ip_set_printk("invalid RENAME data (want %zu, got %u)",
-+ sizeof(struct ip_set_req_create), len);
-+ res = -EINVAL;
-+ goto done;
-+ }
-+
-+ req_rename->name[IP_SET_MAXNAMELEN - 1] = '\0';
-+ req_rename->typename[IP_SET_MAXNAMELEN - 1] = '\0';
-+
-+ index = ip_set_find_byname(req_rename->name);
-+ if (index == IP_SET_INVALID_ID) {
-+ res = -ENOENT;
-+ goto done;
-+ }
-+ res = ip_set_rename(index, req_rename->typename);
-+ goto done;
-+ }
-+ case IP_SET_OP_SWAP:{
-+ struct ip_set_req_create *req_swap
-+ = (struct ip_set_req_create *) data;
-+ ip_set_id_t to_index;
-+
-+ if (len != sizeof(struct ip_set_req_create)) {
-+ ip_set_printk("invalid SWAP data (want %zu, got %u)",
-+ sizeof(struct ip_set_req_create), len);
-+ res = -EINVAL;
-+ goto done;
-+ }
-+
-+ req_swap->name[IP_SET_MAXNAMELEN - 1] = '\0';
-+ req_swap->typename[IP_SET_MAXNAMELEN - 1] = '\0';
-+
-+ index = ip_set_find_byname(req_swap->name);
-+ if (index == IP_SET_INVALID_ID) {
-+ res = -ENOENT;
-+ goto done;
-+ }
-+ to_index = ip_set_find_byname(req_swap->typename);
-+ if (to_index == IP_SET_INVALID_ID) {
-+ res = -ENOENT;
-+ goto done;
-+ }
-+ res = ip_set_swap(index, to_index);
-+ goto done;
-+ }
-+ default:
-+ break; /* Set identified by id */
-+ }
-+
-+ /* There we may have add/del/test/bind/unbind/test_bind operations */
-+ if (*op < IP_SET_OP_ADD_IP || *op > IP_SET_OP_TEST_BIND_SET) {
-+ res = -EBADMSG;
-+ goto done;
-+ }
-+ adtfn = adtfn_table[*op - IP_SET_OP_ADD_IP].fn;
-+
-+ if (len < sizeof(struct ip_set_req_adt)) {
-+ ip_set_printk("short data in adt request (want >=%zu, got %u)",
-+ sizeof(struct ip_set_req_adt), len);
-+ res = -EINVAL;
-+ goto done;
-+ }
-+ req_adt = (struct ip_set_req_adt *) data;
-+
-+ /* -U :all: :all:|:default: uses IP_SET_INVALID_ID */
-+ if (!(*op == IP_SET_OP_UNBIND_SET
-+ && req_adt->index == IP_SET_INVALID_ID)) {
-+ index = ip_set_find_byindex(req_adt->index);
-+ if (index == IP_SET_INVALID_ID) {
-+ res = -ENOENT;
-+ goto done;
-+ }
-+ }
-+ res = adtfn(index, data, len);
-+
-+ done:
-+ up(&ip_set_app_mutex);
-+ vfree(data);
-+ if (res > 0)
-+ res = 0;
-+ DP("final result %d", res);
-+ return res;
-+}
-+
-+static int
-+ip_set_sockfn_get(struct sock *sk, int optval, void *user, int *len)
-+{
-+ int res = 0;
-+ unsigned *op;
-+ ip_set_id_t index = IP_SET_INVALID_ID;
-+ void *data;
-+ int copylen = *len;
-+
-+ DP("optval=%d, user=%p, len=%d", optval, user, *len);
-+ if (!capable(CAP_NET_ADMIN))
-+ return -EPERM;
-+ if (optval != SO_IP_SET)
-+ return -EBADF;
-+ if (*len < sizeof(unsigned)) {
-+ ip_set_printk("short userdata (want >=%zu, got %d)",
-+ sizeof(unsigned), *len);
-+ return -EINVAL;
-+ }
-+ data = vmalloc(*len);
-+ if (!data) {
-+ DP("out of mem for %d bytes", *len);
-+ return -ENOMEM;
-+ }
-+ if (copy_from_user(data, user, *len) != 0) {
-+ res = -EFAULT;
-+ goto done;
-+ }
-+ if (down_interruptible(&ip_set_app_mutex)) {
-+ res = -EINTR;
-+ goto done;
-+ }
-+
-+ op = (unsigned *) data;
-+ DP("op=%x", *op);
-+
-+ if (*op < IP_SET_OP_VERSION) {
-+ /* Check the version at the beginning of operations */
-+ struct ip_set_req_version *req_version =
-+ (struct ip_set_req_version *) data;
-+ if (req_version->version != IP_SET_PROTOCOL_VERSION) {
-+ res = -EPROTO;
-+ goto done;
-+ }
-+ }
-+
-+ switch (*op) {
-+ case IP_SET_OP_VERSION: {
-+ struct ip_set_req_version *req_version =
-+ (struct ip_set_req_version *) data;
-+
-+ if (*len != sizeof(struct ip_set_req_version)) {
-+ ip_set_printk("invalid VERSION (want %zu, got %d)",
-+ sizeof(struct ip_set_req_version),
-+ *len);
-+ res = -EINVAL;
-+ goto done;
-+ }
-+
-+ req_version->version = IP_SET_PROTOCOL_VERSION;
-+ res = copy_to_user(user, req_version,
-+ sizeof(struct ip_set_req_version));
-+ goto done;
-+ }
-+ case IP_SET_OP_GET_BYNAME: {
-+ struct ip_set_req_get_set *req_get
-+ = (struct ip_set_req_get_set *) data;
-+
-+ if (*len != sizeof(struct ip_set_req_get_set)) {
-+ ip_set_printk("invalid GET_BYNAME (want %zu, got %d)",
-+ sizeof(struct ip_set_req_get_set), *len);
-+ res = -EINVAL;
-+ goto done;
-+ }
-+ req_get->set.name[IP_SET_MAXNAMELEN - 1] = '\0';
-+ index = ip_set_find_byname(req_get->set.name);
-+ req_get->set.index = index;
-+ goto copy;
-+ }
-+ case IP_SET_OP_GET_BYINDEX: {
-+ struct ip_set_req_get_set *req_get
-+ = (struct ip_set_req_get_set *) data;
-+
-+ if (*len != sizeof(struct ip_set_req_get_set)) {
-+ ip_set_printk("invalid GET_BYINDEX (want %zu, got %d)",
-+ sizeof(struct ip_set_req_get_set), *len);
-+ res = -EINVAL;
-+ goto done;
-+ }
-+ req_get->set.name[IP_SET_MAXNAMELEN - 1] = '\0';
-+ index = ip_set_find_byindex(req_get->set.index);
-+ strncpy(req_get->set.name,
-+ index == IP_SET_INVALID_ID ? ""
-+ : ip_set_list[index]->name, IP_SET_MAXNAMELEN);
-+ goto copy;
-+ }
-+ case IP_SET_OP_ADT_GET: {
-+ struct ip_set_req_adt_get *req_get
-+ = (struct ip_set_req_adt_get *) data;
-+
-+ if (*len != sizeof(struct ip_set_req_adt_get)) {
-+ ip_set_printk("invalid ADT_GET (want %zu, got %d)",
-+ sizeof(struct ip_set_req_adt_get), *len);
-+ res = -EINVAL;
-+ goto done;
-+ }
-+ req_get->set.name[IP_SET_MAXNAMELEN - 1] = '\0';
-+ index = ip_set_find_byname(req_get->set.name);
-+ if (index != IP_SET_INVALID_ID) {
-+ req_get->set.index = index;
-+ strncpy(req_get->typename,
-+ ip_set_list[index]->type->typename,
-+ IP_SET_MAXNAMELEN - 1);
-+ } else {
-+ res = -ENOENT;
-+ goto done;
-+ }
-+ goto copy;
-+ }
-+ case IP_SET_OP_MAX_SETS: {
-+ struct ip_set_req_max_sets *req_max_sets
-+ = (struct ip_set_req_max_sets *) data;
-+ ip_set_id_t i;
-+
-+ if (*len != sizeof(struct ip_set_req_max_sets)) {
-+ ip_set_printk("invalid MAX_SETS (want %zu, got %d)",
-+ sizeof(struct ip_set_req_max_sets), *len);
-+ res = -EINVAL;
-+ goto done;
-+ }
-+
-+ if (strcmp(req_max_sets->set.name, IPSET_TOKEN_ALL) == 0) {
-+ req_max_sets->set.index = IP_SET_INVALID_ID;
-+ } else {
-+ req_max_sets->set.name[IP_SET_MAXNAMELEN - 1] = '\0';
-+ req_max_sets->set.index =
-+ ip_set_find_byname(req_max_sets->set.name);
-+ if (req_max_sets->set.index == IP_SET_INVALID_ID) {
-+ res = -ENOENT;
-+ goto done;
-+ }
-+ }
-+ req_max_sets->max_sets = ip_set_max;
-+ req_max_sets->sets = 0;
-+ for (i = 0; i < ip_set_max; i++) {
-+ if (ip_set_list[i] != NULL)
-+ req_max_sets->sets++;
-+ }
-+ goto copy;
-+ }
-+ case IP_SET_OP_LIST_SIZE:
-+ case IP_SET_OP_SAVE_SIZE: {
-+ struct ip_set_req_setnames *req_setnames
-+ = (struct ip_set_req_setnames *) data;
-+ struct ip_set_name_list *name_list;
-+ struct ip_set *set;
-+ ip_set_id_t i;
-+ int used;
-+
-+ if (*len < sizeof(struct ip_set_req_setnames)) {
-+ ip_set_printk("short LIST_SIZE (want >=%zu, got %d)",
-+ sizeof(struct ip_set_req_setnames), *len);
-+ res = -EINVAL;
-+ goto done;
-+ }
-+
-+ req_setnames->size = 0;
-+ used = sizeof(struct ip_set_req_setnames);
-+ for (i = 0; i < ip_set_max; i++) {
-+ if (ip_set_list[i] == NULL)
-+ continue;
-+ name_list = (struct ip_set_name_list *)
-+ (data + used);
-+ used += sizeof(struct ip_set_name_list);
-+ if (used > copylen) {
-+ res = -EAGAIN;
-+ goto done;
-+ }
-+ set = ip_set_list[i];
-+ /* Fill in index, name, etc. */
-+ name_list->index = i;
-+ name_list->id = set->id;
-+ strncpy(name_list->name,
-+ set->name,
-+ IP_SET_MAXNAMELEN - 1);
-+ strncpy(name_list->typename,
-+ set->type->typename,
-+ IP_SET_MAXNAMELEN - 1);
-+ DP("filled %s of type %s, index %u\n",
-+ name_list->name, name_list->typename,
-+ name_list->index);
-+ if (!(req_setnames->index == IP_SET_INVALID_ID
-+ || req_setnames->index == i))
-+ continue;
-+ /* Update size */
-+ switch (*op) {
-+ case IP_SET_OP_LIST_SIZE: {
-+ req_setnames->size += sizeof(struct ip_set_list)
-+ + set->type->header_size
-+ + set->type->list_members_size(set);
-+ /* Sets are identified by id in the hash */
-+ FOREACH_HASH_DO(__set_hash_bindings_size_list,
-+ set->id, &req_setnames->size);
-+ break;
-+ }
-+ case IP_SET_OP_SAVE_SIZE: {
-+ req_setnames->size += sizeof(struct ip_set_save)
-+ + set->type->header_size
-+ + set->type->list_members_size(set);
-+ FOREACH_HASH_DO(__set_hash_bindings_size_save,
-+ set->id, &req_setnames->size);
-+ break;
-+ }
-+ default:
-+ break;
-+ }
-+ }
-+ if (copylen != used) {
-+ res = -EAGAIN;
-+ goto done;
-+ }
-+ goto copy;
-+ }
-+ case IP_SET_OP_LIST: {
-+ struct ip_set_req_list *req_list
-+ = (struct ip_set_req_list *) data;
-+ ip_set_id_t i;
-+ int used;
-+
-+ if (*len < sizeof(struct ip_set_req_list)) {
-+ ip_set_printk("short LIST (want >=%zu, got %d)",
-+ sizeof(struct ip_set_req_list), *len);
-+ res = -EINVAL;
-+ goto done;
-+ }
-+ index = req_list->index;
-+ if (index != IP_SET_INVALID_ID
-+ && ip_set_find_byindex(index) != index) {
-+ res = -ENOENT;
-+ goto done;
-+ }
-+ used = 0;
-+ if (index == IP_SET_INVALID_ID) {
-+ /* List all sets */
-+ for (i = 0; i < ip_set_max && res == 0; i++) {
-+ if (ip_set_list[i] != NULL)
-+ res = ip_set_list_set(i, data, &used, *len);
-+ }
-+ } else {
-+ /* List an individual set */
-+ res = ip_set_list_set(index, data, &used, *len);
-+ }
-+ if (res != 0)
-+ goto done;
-+ else if (copylen != used) {
-+ res = -EAGAIN;
-+ goto done;
-+ }
-+ goto copy;
-+ }
-+ case IP_SET_OP_SAVE: {
-+ struct ip_set_req_list *req_save
-+ = (struct ip_set_req_list *) data;
-+ ip_set_id_t i;
-+ int used;
-+
-+ if (*len < sizeof(struct ip_set_req_list)) {
-+ ip_set_printk("short SAVE (want >=%zu, got %d)",
-+ sizeof(struct ip_set_req_list), *len);
-+ res = -EINVAL;
-+ goto done;
-+ }
-+ index = req_save->index;
-+ if (index != IP_SET_INVALID_ID
-+ && ip_set_find_byindex(index) != index) {
-+ res = -ENOENT;
-+ goto done;
-+ }
-+ used = 0;
-+ if (index == IP_SET_INVALID_ID) {
-+ /* Save all sets */
-+ for (i = 0; i < ip_set_max && res == 0; i++) {
-+ if (ip_set_list[i] != NULL)
-+ res = ip_set_save_set(i, data, &used, *len);
-+ }
-+ } else {
-+ /* Save an individual set */
-+ res = ip_set_save_set(index, data, &used, *len);
-+ }
-+ if (res == 0)
-+ res = ip_set_save_bindings(index, data, &used, *len);
-+
-+ if (res != 0)
-+ goto done;
-+ else if (copylen != used) {
-+ res = -EAGAIN;
-+ goto done;
-+ }
-+ goto copy;
-+ }
-+ case IP_SET_OP_RESTORE: {
-+ struct ip_set_req_setnames *req_restore
-+ = (struct ip_set_req_setnames *) data;
-+ int line;
-+
-+ if (*len < sizeof(struct ip_set_req_setnames)
-+ || *len != req_restore->size) {
-+ ip_set_printk("invalid RESTORE (want =%zu, got %d)",
-+ req_restore->size, *len);
-+ res = -EINVAL;
-+ goto done;
-+ }
-+ line = ip_set_restore(data + sizeof(struct ip_set_req_setnames),
-+ req_restore->size - sizeof(struct ip_set_req_setnames));
-+ DP("ip_set_restore: %u", line);
-+ if (line != 0) {
-+ res = -EAGAIN;
-+ req_restore->size = line;
-+ copylen = sizeof(struct ip_set_req_setnames);
-+ goto copy;
-+ }
-+ goto done;
-+ }
-+ default:
-+ res = -EBADMSG;
-+ goto done;
-+ } /* end of switch(op) */
-+
-+ copy:
-+ DP("set %s, copylen %u", index != IP_SET_INVALID_ID
-+ && ip_set_list[index]
-+ ? ip_set_list[index]->name
-+ : ":all:", copylen);
-+ res = copy_to_user(user, data, copylen);
-+
-+ done:
-+ up(&ip_set_app_mutex);
-+ vfree(data);
-+ if (res > 0)
-+ res = 0;
-+ DP("final result %d", res);
-+ return res;
-+}
-+
-+static struct nf_sockopt_ops so_set = {
-+ .pf = PF_INET,
-+ .set_optmin = SO_IP_SET,
-+ .set_optmax = SO_IP_SET + 1,
-+ .set = &ip_set_sockfn_set,
-+ .get_optmin = SO_IP_SET,
-+ .get_optmax = SO_IP_SET + 1,
-+ .get = &ip_set_sockfn_get,
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,23)
-+ .owner = THIS_MODULE,
-+#endif
-+};
-+
-+static int max_sets, hash_size;
-+module_param(max_sets, int, 0600);
-+MODULE_PARM_DESC(max_sets, "maximal number of sets");
-+module_param(hash_size, int, 0600);
-+MODULE_PARM_DESC(hash_size, "hash size for bindings");
-+MODULE_LICENSE("GPL");
-+MODULE_AUTHOR("Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>");
-+MODULE_DESCRIPTION("module implementing core IP set support");
-+
-+static int __init ip_set_init(void)
-+{
-+ int res;
-+ ip_set_id_t i;
-+
-+ get_random_bytes(&ip_set_hash_random, 4);
-+ if (max_sets)
-+ ip_set_max = max_sets;
-+ ip_set_list = vmalloc(sizeof(struct ip_set *) * ip_set_max);
-+ if (!ip_set_list) {
-+ printk(KERN_ERR "Unable to create ip_set_list\n");
-+ return -ENOMEM;
-+ }
-+ memset(ip_set_list, 0, sizeof(struct ip_set *) * ip_set_max);
-+ if (hash_size)
-+ ip_set_bindings_hash_size = hash_size;
-+ ip_set_hash = vmalloc(sizeof(struct list_head) * ip_set_bindings_hash_size);
-+ if (!ip_set_hash) {
-+ printk(KERN_ERR "Unable to create ip_set_hash\n");
-+ vfree(ip_set_list);
-+ return -ENOMEM;
-+ }
-+ for (i = 0; i < ip_set_bindings_hash_size; i++)
-+ INIT_LIST_HEAD(&ip_set_hash[i]);
-+
-+ INIT_LIST_HEAD(&set_type_list);
-+
-+ res = nf_register_sockopt(&so_set);
-+ if (res != 0) {
-+ ip_set_printk("SO_SET registry failed: %d", res);
-+ vfree(ip_set_list);
-+ vfree(ip_set_hash);
-+ return res;
-+ }
-+ return 0;
-+}
-+
-+static void __exit ip_set_fini(void)
-+{
-+ /* There can't be any existing set or binding */
-+ nf_unregister_sockopt(&so_set);
-+ vfree(ip_set_list);
-+ vfree(ip_set_hash);
-+ DP("these are the famous last words");
-+}
-+
-+EXPORT_SYMBOL(ip_set_register_set_type);
-+EXPORT_SYMBOL(ip_set_unregister_set_type);
-+
-+EXPORT_SYMBOL(ip_set_get_byname);
-+EXPORT_SYMBOL(ip_set_get_byindex);
-+EXPORT_SYMBOL(ip_set_put);
-+
-+EXPORT_SYMBOL(ip_set_addip_kernel);
-+EXPORT_SYMBOL(ip_set_delip_kernel);
-+EXPORT_SYMBOL(ip_set_testip_kernel);
-+
-+module_init(ip_set_init);
-+module_exit(ip_set_fini);
-Index: linux-2.6.21.7/net/ipv4/netfilter/ip_set_iphash.c
-===================================================================
---- /dev/null
-+++ linux-2.6.21.7/net/ipv4/netfilter/ip_set_iphash.c
-@@ -0,0 +1,429 @@
-+/* Copyright (C) 2003-2004 Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
-+ *
-+ * This program is free software; you can redistribute it and/or modify
-+ * it under the terms of the GNU General Public License version 2 as
-+ * published by the Free Software Foundation.
-+ */
-+
-+/* Kernel module implementing an ip hash set */
-+
-+#include <linux/module.h>
-+#include <linux/ip.h>
-+#include <linux/skbuff.h>
-+#include <linux/version.h>
-+#include <linux/jhash.h>
-+#include <linux/netfilter_ipv4/ip_tables.h>
-+#include <linux/netfilter_ipv4/ip_set.h>
-+#include <linux/errno.h>
-+#include <asm/uaccess.h>
-+#include <asm/bitops.h>
-+#include <linux/spinlock.h>
-+#include <linux/vmalloc.h>
-+#include <linux/random.h>
-+
-+#include <net/ip.h>
-+
-+#include <linux/netfilter_ipv4/ip_set_malloc.h>
-+#include <linux/netfilter_ipv4/ip_set_iphash.h>
-+
-+static int limit = MAX_RANGE;
-+
-+static inline __u32
-+jhash_ip(const struct ip_set_iphash *map, uint16_t i, ip_set_ip_t ip)
-+{
-+ return jhash_1word(ip, *(((uint32_t *) map->initval) + i));
-+}
-+
-+static inline __u32
-+hash_id(struct ip_set *set, ip_set_ip_t ip, ip_set_ip_t *hash_ip)
-+{
-+ struct ip_set_iphash *map = (struct ip_set_iphash *) set->data;
-+ __u32 id;
-+ u_int16_t i;
-+ ip_set_ip_t *elem;
-+
-+ *hash_ip = ip & map->netmask;
-+ DP("set: %s, ip:%u.%u.%u.%u, %u.%u.%u.%u, %u.%u.%u.%u",
-+ set->name, HIPQUAD(ip), HIPQUAD(*hash_ip), HIPQUAD(map->netmask));
-+
-+ for (i = 0; i < map->probes; i++) {
-+ id = jhash_ip(map, i, *hash_ip) % map->hashsize;
-+ DP("hash key: %u", id);
-+ elem = HARRAY_ELEM(map->members, ip_set_ip_t *, id);
-+ if (*elem == *hash_ip)
-+ return id;
-+ /* No shortcut at testing - there can be deleted
-+ * entries. */
-+ }
-+ return UINT_MAX;
-+}
-+
-+static inline int
-+__testip(struct ip_set *set, ip_set_ip_t ip, ip_set_ip_t *hash_ip)
-+{
-+ return (ip && hash_id(set, ip, hash_ip) != UINT_MAX);
-+}
-+
-+static int
-+testip(struct ip_set *set, const void *data, size_t size,
-+ ip_set_ip_t *hash_ip)
-+{
-+ struct ip_set_req_iphash *req =
-+ (struct ip_set_req_iphash *) data;
-+
-+ if (size != sizeof(struct ip_set_req_iphash)) {
-+ ip_set_printk("data length wrong (want %zu, have %zu)",
-+ sizeof(struct ip_set_req_iphash),
-+ size);
-+ return -EINVAL;
-+ }
-+ return __testip(set, req->ip, hash_ip);
-+}
-+
-+static int
-+testip_kernel(struct ip_set *set,
-+ const struct sk_buff *skb,
-+ ip_set_ip_t *hash_ip,
-+ const u_int32_t *flags,
-+ unsigned char index)
-+{
-+ return __testip(set,
-+ ntohl(flags[index] & IPSET_SRC
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-+ ? ip_hdr(skb)->saddr
-+ : ip_hdr(skb)->daddr),
-+#else
-+ ? skb->nh.iph->saddr
-+ : skb->nh.iph->daddr),
-+#endif
-+ hash_ip);
-+}
-+
-+static inline int
-+__addip(struct ip_set_iphash *map, ip_set_ip_t ip, ip_set_ip_t *hash_ip)
-+{
-+ __u32 probe;
-+ u_int16_t i;
-+ ip_set_ip_t *elem;
-+
-+ if (!ip || map->elements >= limit)
-+ return -ERANGE;
-+
-+ *hash_ip = ip & map->netmask;
-+
-+ for (i = 0; i < map->probes; i++) {
-+ probe = jhash_ip(map, i, *hash_ip) % map->hashsize;
-+ elem = HARRAY_ELEM(map->members, ip_set_ip_t *, probe);
-+ if (*elem == *hash_ip)
-+ return -EEXIST;
-+ if (!*elem) {
-+ *elem = *hash_ip;
-+ map->elements++;
-+ return 0;
-+ }
-+ }
-+ /* Trigger rehashing */
-+ return -EAGAIN;
-+}
-+
-+static int
-+addip(struct ip_set *set, const void *data, size_t size,
-+ ip_set_ip_t *hash_ip)
-+{
-+ struct ip_set_req_iphash *req =
-+ (struct ip_set_req_iphash *) data;
-+
-+ if (size != sizeof(struct ip_set_req_iphash)) {
-+ ip_set_printk("data length wrong (want %zu, have %zu)",
-+ sizeof(struct ip_set_req_iphash),
-+ size);
-+ return -EINVAL;
-+ }
-+ return __addip((struct ip_set_iphash *) set->data, req->ip, hash_ip);
-+}
-+
-+static int
-+addip_kernel(struct ip_set *set,
-+ const struct sk_buff *skb,
-+ ip_set_ip_t *hash_ip,
-+ const u_int32_t *flags,
-+ unsigned char index)
-+{
-+ return __addip((struct ip_set_iphash *) set->data,
-+ ntohl(flags[index] & IPSET_SRC
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-+ ? ip_hdr(skb)->saddr
-+ : ip_hdr(skb)->daddr),
-+#else
-+ ? skb->nh.iph->saddr
-+ : skb->nh.iph->daddr),
-+#endif
-+ hash_ip);
-+}
-+
-+static int retry(struct ip_set *set)
-+{
-+ struct ip_set_iphash *map = (struct ip_set_iphash *) set->data;
-+ ip_set_ip_t hash_ip, *elem;
-+ void *members;
-+ u_int32_t i, hashsize = map->hashsize;
-+ int res;
-+ struct ip_set_iphash *tmp;
-+
-+ if (map->resize == 0)
-+ return -ERANGE;
-+
-+ again:
-+ res = 0;
-+
-+ /* Calculate new hash size */
-+ hashsize += (hashsize * map->resize)/100;
-+ if (hashsize == map->hashsize)
-+ hashsize++;
-+
-+ ip_set_printk("rehashing of set %s triggered: "
-+ "hashsize grows from %u to %u",
-+ set->name, map->hashsize, hashsize);
-+
-+ tmp = kmalloc(sizeof(struct ip_set_iphash)
-+ + map->probes * sizeof(uint32_t), GFP_ATOMIC);
-+ if (!tmp) {
-+ DP("out of memory for %d bytes",
-+ sizeof(struct ip_set_iphash)
-+ + map->probes * sizeof(uint32_t));
-+ return -ENOMEM;
-+ }
-+ tmp->members = harray_malloc(hashsize, sizeof(ip_set_ip_t), GFP_ATOMIC);
-+ if (!tmp->members) {
-+ DP("out of memory for %d bytes", hashsize * sizeof(ip_set_ip_t));
-+ kfree(tmp);
-+ return -ENOMEM;
-+ }
-+ tmp->hashsize = hashsize;
-+ tmp->elements = 0;
-+ tmp->probes = map->probes;
-+ tmp->resize = map->resize;
-+ tmp->netmask = map->netmask;
-+ memcpy(tmp->initval, map->initval, map->probes * sizeof(uint32_t));
-+
-+ write_lock_bh(&set->lock);
-+ map = (struct ip_set_iphash *) set->data; /* Play safe */
-+ for (i = 0; i < map->hashsize && res == 0; i++) {
-+ elem = HARRAY_ELEM(map->members, ip_set_ip_t *, i);
-+ if (*elem)
-+ res = __addip(tmp, *elem, &hash_ip);
-+ }
-+ if (res) {
-+ /* Failure, try again */
-+ write_unlock_bh(&set->lock);
-+ harray_free(tmp->members);
-+ kfree(tmp);
-+ goto again;
-+ }
-+
-+ /* Success at resizing! */
-+ members = map->members;
-+
-+ map->hashsize = tmp->hashsize;
-+ map->members = tmp->members;
-+ write_unlock_bh(&set->lock);
-+
-+ harray_free(members);
-+ kfree(tmp);
-+
-+ return 0;
-+}
-+
-+static inline int
-+__delip(struct ip_set *set, ip_set_ip_t ip, ip_set_ip_t *hash_ip)
-+{
-+ struct ip_set_iphash *map = (struct ip_set_iphash *) set->data;
-+ ip_set_ip_t id, *elem;
-+
-+ if (!ip)
-+ return -ERANGE;
-+
-+ id = hash_id(set, ip, hash_ip);
-+ if (id == UINT_MAX)
-+ return -EEXIST;
-+
-+ elem = HARRAY_ELEM(map->members, ip_set_ip_t *, id);
-+ *elem = 0;
-+ map->elements--;
-+
-+ return 0;
-+}
-+
-+static int
-+delip(struct ip_set *set, const void *data, size_t size,
-+ ip_set_ip_t *hash_ip)
-+{
-+ struct ip_set_req_iphash *req =
-+ (struct ip_set_req_iphash *) data;
-+
-+ if (size != sizeof(struct ip_set_req_iphash)) {
-+ ip_set_printk("data length wrong (want %zu, have %zu)",
-+ sizeof(struct ip_set_req_iphash),
-+ size);
-+ return -EINVAL;
-+ }
-+ return __delip(set, req->ip, hash_ip);
-+}
-+
-+static int
-+delip_kernel(struct ip_set *set,
-+ const struct sk_buff *skb,
-+ ip_set_ip_t *hash_ip,
-+ const u_int32_t *flags,
-+ unsigned char index)
-+{
-+ return __delip(set,
-+ ntohl(flags[index] & IPSET_SRC
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-+ ? ip_hdr(skb)->saddr
-+ : ip_hdr(skb)->daddr),
-+#else
-+ ? skb->nh.iph->saddr
-+ : skb->nh.iph->daddr),
-+#endif
-+ hash_ip);
-+}
-+
-+static int create(struct ip_set *set, const void *data, size_t size)
-+{
-+ struct ip_set_req_iphash_create *req =
-+ (struct ip_set_req_iphash_create *) data;
-+ struct ip_set_iphash *map;
-+ uint16_t i;
-+
-+ if (size != sizeof(struct ip_set_req_iphash_create)) {
-+ ip_set_printk("data length wrong (want %zu, have %zu)",
-+ sizeof(struct ip_set_req_iphash_create),
-+ size);
-+ return -EINVAL;
-+ }
-+
-+ if (req->hashsize < 1) {
-+ ip_set_printk("hashsize too small");
-+ return -ENOEXEC;
-+ }
-+
-+ if (req->probes < 1) {
-+ ip_set_printk("probes too small");
-+ return -ENOEXEC;
-+ }
-+
-+ map = kmalloc(sizeof(struct ip_set_iphash)
-+ + req->probes * sizeof(uint32_t), GFP_KERNEL);
-+ if (!map) {
-+ DP("out of memory for %d bytes",
-+ sizeof(struct ip_set_iphash)
-+ + req->probes * sizeof(uint32_t));
-+ return -ENOMEM;
-+ }
-+ for (i = 0; i < req->probes; i++)
-+ get_random_bytes(((uint32_t *) map->initval)+i, 4);
-+ map->elements = 0;
-+ map->hashsize = req->hashsize;
-+ map->probes = req->probes;
-+ map->resize = req->resize;
-+ map->netmask = req->netmask;
-+ map->members = harray_malloc(map->hashsize, sizeof(ip_set_ip_t), GFP_KERNEL);
-+ if (!map->members) {
-+ DP("out of memory for %d bytes", map->hashsize * sizeof(ip_set_ip_t));
-+ kfree(map);
-+ return -ENOMEM;
-+ }
-+
-+ set->data = map;
-+ return 0;
-+}
-+
-+static void destroy(struct ip_set *set)
-+{
-+ struct ip_set_iphash *map = (struct ip_set_iphash *) set->data;
-+
-+ harray_free(map->members);
-+ kfree(map);
-+
-+ set->data = NULL;
-+}
-+
-+static void flush(struct ip_set *set)
-+{
-+ struct ip_set_iphash *map = (struct ip_set_iphash *) set->data;
-+ harray_flush(map->members, map->hashsize, sizeof(ip_set_ip_t));
-+ map->elements = 0;
-+}
-+
-+static void list_header(const struct ip_set *set, void *data)
-+{
-+ struct ip_set_iphash *map = (struct ip_set_iphash *) set->data;
-+ struct ip_set_req_iphash_create *header =
-+ (struct ip_set_req_iphash_create *) data;
-+
-+ header->hashsize = map->hashsize;
-+ header->probes = map->probes;
-+ header->resize = map->resize;
-+ header->netmask = map->netmask;
-+}
-+
-+static int list_members_size(const struct ip_set *set)
-+{
-+ struct ip_set_iphash *map = (struct ip_set_iphash *) set->data;
-+
-+ return (map->hashsize * sizeof(ip_set_ip_t));
-+}
-+
-+static void list_members(const struct ip_set *set, void *data)
-+{
-+ struct ip_set_iphash *map = (struct ip_set_iphash *) set->data;
-+ ip_set_ip_t i, *elem;
-+
-+ for (i = 0; i < map->hashsize; i++) {
-+ elem = HARRAY_ELEM(map->members, ip_set_ip_t *, i);
-+ ((ip_set_ip_t *)data)[i] = *elem;
-+ }
-+}
-+
-+static struct ip_set_type ip_set_iphash = {
-+ .typename = SETTYPE_NAME,
-+ .features = IPSET_TYPE_IP | IPSET_DATA_SINGLE,
-+ .protocol_version = IP_SET_PROTOCOL_VERSION,
-+ .create = &create,
-+ .destroy = &destroy,
-+ .flush = &flush,
-+ .reqsize = sizeof(struct ip_set_req_iphash),
-+ .addip = &addip,
-+ .addip_kernel = &addip_kernel,
-+ .retry = &retry,
-+ .delip = &delip,
-+ .delip_kernel = &delip_kernel,
-+ .testip = &testip,
-+ .testip_kernel = &testip_kernel,
-+ .header_size = sizeof(struct ip_set_req_iphash_create),
-+ .list_header = &list_header,
-+ .list_members_size = &list_members_size,
-+ .list_members = &list_members,
-+ .me = THIS_MODULE,
-+};
-+
-+MODULE_LICENSE("GPL");
-+MODULE_AUTHOR("Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>");
-+MODULE_DESCRIPTION("iphash type of IP sets");
-+module_param(limit, int, 0600);
-+MODULE_PARM_DESC(limit, "maximal number of elements stored in the sets");
-+
-+static int __init ip_set_iphash_init(void)
-+{
-+ return ip_set_register_set_type(&ip_set_iphash);
-+}
-+
-+static void __exit ip_set_iphash_fini(void)
-+{
-+ /* FIXME: possible race with ip_set_create() */
-+ ip_set_unregister_set_type(&ip_set_iphash);
-+}
-+
-+module_init(ip_set_iphash_init);
-+module_exit(ip_set_iphash_fini);
-Index: linux-2.6.21.7/net/ipv4/netfilter/ip_set_ipmap.c
-===================================================================
---- /dev/null
-+++ linux-2.6.21.7/net/ipv4/netfilter/ip_set_ipmap.c
-@@ -0,0 +1,336 @@
-+/* Copyright (C) 2000-2002 Joakim Axelsson <gozem@linux.nu>
-+ * Patrick Schaaf <bof@bof.de>
-+ * Copyright (C) 2003-2004 Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
-+ *
-+ * This program is free software; you can redistribute it and/or modify
-+ * it under the terms of the GNU General Public License version 2 as
-+ * published by the Free Software Foundation.
-+ */
-+
-+/* Kernel module implementing an IP set type: the single bitmap type */
-+
-+#include <linux/module.h>
-+#include <linux/ip.h>
-+#include <linux/skbuff.h>
-+#include <linux/version.h>
-+#include <linux/netfilter_ipv4/ip_tables.h>
-+#include <linux/netfilter_ipv4/ip_set.h>
-+#include <linux/errno.h>
-+#include <asm/uaccess.h>
-+#include <asm/bitops.h>
-+#include <linux/spinlock.h>
-+
-+#include <linux/netfilter_ipv4/ip_set_ipmap.h>
-+
-+static inline ip_set_ip_t
-+ip_to_id(const struct ip_set_ipmap *map, ip_set_ip_t ip)
-+{
-+ return (ip - map->first_ip)/map->hosts;
-+}
-+
-+static inline int
-+__testip(struct ip_set *set, ip_set_ip_t ip, ip_set_ip_t *hash_ip)
-+{
-+ struct ip_set_ipmap *map = (struct ip_set_ipmap *) set->data;
-+
-+ if (ip < map->first_ip || ip > map->last_ip)
-+ return -ERANGE;
-+
-+ *hash_ip = ip & map->netmask;
-+ DP("set: %s, ip:%u.%u.%u.%u, %u.%u.%u.%u",
-+ set->name, HIPQUAD(ip), HIPQUAD(*hash_ip));
-+ return !!test_bit(ip_to_id(map, *hash_ip), map->members);
-+}
-+
-+static int
-+testip(struct ip_set *set, const void *data, size_t size,
-+ ip_set_ip_t *hash_ip)
-+{
-+ struct ip_set_req_ipmap *req =
-+ (struct ip_set_req_ipmap *) data;
-+
-+ if (size != sizeof(struct ip_set_req_ipmap)) {
-+ ip_set_printk("data length wrong (want %zu, have %zu)",
-+ sizeof(struct ip_set_req_ipmap),
-+ size);
-+ return -EINVAL;
-+ }
-+ return __testip(set, req->ip, hash_ip);
-+}
-+
-+static int
-+testip_kernel(struct ip_set *set,
-+ const struct sk_buff *skb,
-+ ip_set_ip_t *hash_ip,
-+ const u_int32_t *flags,
-+ unsigned char index)
-+{
-+ int res = __testip(set,
-+ ntohl(flags[index] & IPSET_SRC
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-+ ? ip_hdr(skb)->saddr
-+ : ip_hdr(skb)->daddr),
-+#else
-+ ? skb->nh.iph->saddr
-+ : skb->nh.iph->daddr),
-+#endif
-+ hash_ip);
-+ return (res < 0 ? 0 : res);
-+}
-+
-+static inline int
-+__addip(struct ip_set *set, ip_set_ip_t ip, ip_set_ip_t *hash_ip)
-+{
-+ struct ip_set_ipmap *map = (struct ip_set_ipmap *) set->data;
-+
-+ if (ip < map->first_ip || ip > map->last_ip)
-+ return -ERANGE;
-+
-+ *hash_ip = ip & map->netmask;
-+ DP("%u.%u.%u.%u, %u.%u.%u.%u", HIPQUAD(ip), HIPQUAD(*hash_ip));
-+ if (test_and_set_bit(ip_to_id(map, *hash_ip), map->members))
-+ return -EEXIST;
-+
-+ return 0;
-+}
-+
-+static int
-+addip(struct ip_set *set, const void *data, size_t size,
-+ ip_set_ip_t *hash_ip)
-+{
-+ struct ip_set_req_ipmap *req =
-+ (struct ip_set_req_ipmap *) data;
-+
-+ if (size != sizeof(struct ip_set_req_ipmap)) {
-+ ip_set_printk("data length wrong (want %zu, have %zu)",
-+ sizeof(struct ip_set_req_ipmap),
-+ size);
-+ return -EINVAL;
-+ }
-+ DP("%u.%u.%u.%u", HIPQUAD(req->ip));
-+ return __addip(set, req->ip, hash_ip);
-+}
-+
-+static int
-+addip_kernel(struct ip_set *set,
-+ const struct sk_buff *skb,
-+ ip_set_ip_t *hash_ip,
-+ const u_int32_t *flags,
-+ unsigned char index)
-+{
-+ return __addip(set,
-+ ntohl(flags[index] & IPSET_SRC
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-+ ? ip_hdr(skb)->saddr
-+ : ip_hdr(skb)->daddr),
-+#else
-+ ? skb->nh.iph->saddr
-+ : skb->nh.iph->daddr),
-+#endif
-+ hash_ip);
-+}
-+
-+static inline int
-+__delip(struct ip_set *set, ip_set_ip_t ip, ip_set_ip_t *hash_ip)
-+{
-+ struct ip_set_ipmap *map = (struct ip_set_ipmap *) set->data;
-+
-+ if (ip < map->first_ip || ip > map->last_ip)
-+ return -ERANGE;
-+
-+ *hash_ip = ip & map->netmask;
-+ DP("%u.%u.%u.%u, %u.%u.%u.%u", HIPQUAD(ip), HIPQUAD(*hash_ip));
-+ if (!test_and_clear_bit(ip_to_id(map, *hash_ip), map->members))
-+ return -EEXIST;
-+
-+ return 0;
-+}
-+
-+static int
-+delip(struct ip_set *set, const void *data, size_t size,
-+ ip_set_ip_t *hash_ip)
-+{
-+ struct ip_set_req_ipmap *req =
-+ (struct ip_set_req_ipmap *) data;
-+
-+ if (size != sizeof(struct ip_set_req_ipmap)) {
-+ ip_set_printk("data length wrong (want %zu, have %zu)",
-+ sizeof(struct ip_set_req_ipmap),
-+ size);
-+ return -EINVAL;
-+ }
-+ return __delip(set, req->ip, hash_ip);
-+}
-+
-+static int
-+delip_kernel(struct ip_set *set,
-+ const struct sk_buff *skb,
-+ ip_set_ip_t *hash_ip,
-+ const u_int32_t *flags,
-+ unsigned char index)
-+{
-+ return __delip(set,
-+ ntohl(flags[index] & IPSET_SRC
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-+ ? ip_hdr(skb)->saddr
-+ : ip_hdr(skb)->daddr),
-+#else
-+ ? skb->nh.iph->saddr
-+ : skb->nh.iph->daddr),
-+#endif
-+ hash_ip);
-+}
-+
-+static int create(struct ip_set *set, const void *data, size_t size)
-+{
-+ int newbytes;
-+ struct ip_set_req_ipmap_create *req =
-+ (struct ip_set_req_ipmap_create *) data;
-+ struct ip_set_ipmap *map;
-+
-+ if (size != sizeof(struct ip_set_req_ipmap_create)) {
-+ ip_set_printk("data length wrong (want %zu, have %zu)",
-+ sizeof(struct ip_set_req_ipmap_create),
-+ size);
-+ return -EINVAL;
-+ }
-+
-+ DP("from %u.%u.%u.%u to %u.%u.%u.%u",
-+ HIPQUAD(req->from), HIPQUAD(req->to));
-+
-+ if (req->from > req->to) {
-+ DP("bad ip range");
-+ return -ENOEXEC;
-+ }
-+
-+ map = kmalloc(sizeof(struct ip_set_ipmap), GFP_KERNEL);
-+ if (!map) {
-+ DP("out of memory for %d bytes",
-+ sizeof(struct ip_set_ipmap));
-+ return -ENOMEM;
-+ }
-+ map->first_ip = req->from;
-+ map->last_ip = req->to;
-+ map->netmask = req->netmask;
-+
-+ if (req->netmask == 0xFFFFFFFF) {
-+ map->hosts = 1;
-+ map->sizeid = map->last_ip - map->first_ip + 1;
-+ } else {
-+ unsigned int mask_bits, netmask_bits;
-+ ip_set_ip_t mask;
-+
-+ map->first_ip &= map->netmask; /* Should we better bark? */
-+
-+ mask = range_to_mask(map->first_ip, map->last_ip, &mask_bits);
-+ netmask_bits = mask_to_bits(map->netmask);
-+
-+ if ((!mask && (map->first_ip || map->last_ip != 0xFFFFFFFF))
-+ || netmask_bits <= mask_bits)
-+ return -ENOEXEC;
-+
-+ DP("mask_bits %u, netmask_bits %u",
-+ mask_bits, netmask_bits);
-+ map->hosts = 2 << (32 - netmask_bits - 1);
-+ map->sizeid = 2 << (netmask_bits - mask_bits - 1);
-+ }
-+ if (map->sizeid > MAX_RANGE + 1) {
-+ ip_set_printk("range too big (max %d addresses)",
-+ MAX_RANGE+1);
-+ kfree(map);
-+ return -ENOEXEC;
-+ }
-+ DP("hosts %u, sizeid %u", map->hosts, map->sizeid);
-+ newbytes = bitmap_bytes(0, map->sizeid - 1);
-+ map->members = kmalloc(newbytes, GFP_KERNEL);
-+ if (!map->members) {
-+ DP("out of memory for %d bytes", newbytes);
-+ kfree(map);
-+ return -ENOMEM;
-+ }
-+ memset(map->members, 0, newbytes);
-+
-+ set->data = map;
-+ return 0;
-+}
-+
-+static void destroy(struct ip_set *set)
-+{
-+ struct ip_set_ipmap *map = (struct ip_set_ipmap *) set->data;
-+
-+ kfree(map->members);
-+ kfree(map);
-+
-+ set->data = NULL;
-+}
-+
-+static void flush(struct ip_set *set)
-+{
-+ struct ip_set_ipmap *map = (struct ip_set_ipmap *) set->data;
-+ memset(map->members, 0, bitmap_bytes(0, map->sizeid - 1));
-+}
-+
-+static void list_header(const struct ip_set *set, void *data)
-+{
-+ struct ip_set_ipmap *map = (struct ip_set_ipmap *) set->data;
-+ struct ip_set_req_ipmap_create *header =
-+ (struct ip_set_req_ipmap_create *) data;
-+
-+ header->from = map->first_ip;
-+ header->to = map->last_ip;
-+ header->netmask = map->netmask;
-+}
-+
-+static int list_members_size(const struct ip_set *set)
-+{
-+ struct ip_set_ipmap *map = (struct ip_set_ipmap *) set->data;
-+
-+ return bitmap_bytes(0, map->sizeid - 1);
-+}
-+
-+static void list_members(const struct ip_set *set, void *data)
-+{
-+ struct ip_set_ipmap *map = (struct ip_set_ipmap *) set->data;
-+ int bytes = bitmap_bytes(0, map->sizeid - 1);
-+
-+ memcpy(data, map->members, bytes);
-+}
-+
-+static struct ip_set_type ip_set_ipmap = {
-+ .typename = SETTYPE_NAME,
-+ .features = IPSET_TYPE_IP | IPSET_DATA_SINGLE,
-+ .protocol_version = IP_SET_PROTOCOL_VERSION,
-+ .create = &create,
-+ .destroy = &destroy,
-+ .flush = &flush,
-+ .reqsize = sizeof(struct ip_set_req_ipmap),
-+ .addip = &addip,
-+ .addip_kernel = &addip_kernel,
-+ .delip = &delip,
-+ .delip_kernel = &delip_kernel,
-+ .testip = &testip,
-+ .testip_kernel = &testip_kernel,
-+ .header_size = sizeof(struct ip_set_req_ipmap_create),
-+ .list_header = &list_header,
-+ .list_members_size = &list_members_size,
-+ .list_members = &list_members,
-+ .me = THIS_MODULE,
-+};
-+
-+MODULE_LICENSE("GPL");
-+MODULE_AUTHOR("Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>");
-+MODULE_DESCRIPTION("ipmap type of IP sets");
-+
-+static int __init ip_set_ipmap_init(void)
-+{
-+ return ip_set_register_set_type(&ip_set_ipmap);
-+}
-+
-+static void __exit ip_set_ipmap_fini(void)
-+{
-+ /* FIXME: possible race with ip_set_create() */
-+ ip_set_unregister_set_type(&ip_set_ipmap);
-+}
-+
-+module_init(ip_set_ipmap_init);
-+module_exit(ip_set_ipmap_fini);
-Index: linux-2.6.21.7/net/ipv4/netfilter/ip_set_ipporthash.c
-===================================================================
---- /dev/null
-+++ linux-2.6.21.7/net/ipv4/netfilter/ip_set_ipporthash.c
-@@ -0,0 +1,581 @@
-+/* Copyright (C) 2003-2004 Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
-+ *
-+ * This program is free software; you can redistribute it and/or modify
-+ * it under the terms of the GNU General Public License version 2 as
-+ * published by the Free Software Foundation.
-+ */
-+
-+/* Kernel module implementing an ip+port hash set */
-+
-+#include <linux/module.h>
-+#include <linux/ip.h>
-+#include <linux/tcp.h>
-+#include <linux/udp.h>
-+#include <linux/skbuff.h>
-+#include <linux/version.h>
-+#include <linux/jhash.h>
-+#include <linux/netfilter_ipv4/ip_tables.h>
-+#include <linux/netfilter_ipv4/ip_set.h>
-+#include <linux/errno.h>
-+#include <asm/uaccess.h>
-+#include <asm/bitops.h>
-+#include <linux/spinlock.h>
-+#include <linux/vmalloc.h>
-+#include <linux/random.h>
-+
-+#include <net/ip.h>
-+
-+#include <linux/netfilter_ipv4/ip_set_malloc.h>
-+#include <linux/netfilter_ipv4/ip_set_ipporthash.h>
-+
-+static int limit = MAX_RANGE;
-+
-+/* We must handle non-linear skbs */
-+static inline ip_set_ip_t
-+get_port(const struct sk_buff *skb, u_int32_t flags)
-+{
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-+ struct iphdr *iph = ip_hdr(skb);
-+#else
-+ struct iphdr *iph = skb->nh.iph;
-+#endif
-+ u_int16_t offset = ntohs(iph->frag_off) & IP_OFFSET;
-+
-+ switch (iph->protocol) {
-+ case IPPROTO_TCP: {
-+ struct tcphdr tcph;
-+
-+ /* See comments at tcp_match in ip_tables.c */
-+ if (offset)
-+ return INVALID_PORT;
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-+ if (skb_copy_bits(skb, ip_hdr(skb)->ihl*4, &tcph, sizeof(tcph)) < 0)
-+#else
-+ if (skb_copy_bits(skb, skb->nh.iph->ihl*4, &tcph, sizeof(tcph)) < 0)
-+#endif
-+ /* No choice either */
-+ return INVALID_PORT;
-+
-+ return ntohs(flags & IPSET_SRC ?
-+ tcph.source : tcph.dest);
-+ }
-+ case IPPROTO_UDP: {
-+ struct udphdr udph;
-+
-+ if (offset)
-+ return INVALID_PORT;
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-+ if (skb_copy_bits(skb, ip_hdr(skb)->ihl*4, &udph, sizeof(udph)) < 0)
-+#else
-+ if (skb_copy_bits(skb, skb->nh.iph->ihl*4, &udph, sizeof(udph)) < 0)
-+#endif
-+ /* No choice either */
-+ return INVALID_PORT;
-+
-+ return ntohs(flags & IPSET_SRC ?
-+ udph.source : udph.dest);
-+ }
-+ default:
-+ return INVALID_PORT;
-+ }
-+}
-+
-+static inline __u32
-+jhash_ip(const struct ip_set_ipporthash *map, uint16_t i, ip_set_ip_t ip)
-+{
-+ return jhash_1word(ip, *(((uint32_t *) map->initval) + i));
-+}
-+
-+#define HASH_IP(map, ip, port) (port + ((ip - ((map)->first_ip)) << 16))
-+
-+static inline __u32
-+hash_id(struct ip_set *set, ip_set_ip_t ip, ip_set_ip_t port,
-+ ip_set_ip_t *hash_ip)
-+{
-+ struct ip_set_ipporthash *map =
-+ (struct ip_set_ipporthash *) set->data;
-+ __u32 id;
-+ u_int16_t i;
-+ ip_set_ip_t *elem;
-+
-+ *hash_ip = HASH_IP(map, ip, port);
-+ DP("set: %s, ipport:%u.%u.%u.%u:%u, %u.%u.%u.%u",
-+ set->name, HIPQUAD(ip), port, HIPQUAD(*hash_ip));
-+
-+ for (i = 0; i < map->probes; i++) {
-+ id = jhash_ip(map, i, *hash_ip) % map->hashsize;
-+ DP("hash key: %u", id);
-+ elem = HARRAY_ELEM(map->members, ip_set_ip_t *, id);
-+ if (*elem == *hash_ip)
-+ return id;
-+ /* No shortcut at testing - there can be deleted
-+ * entries. */
-+ }
-+ return UINT_MAX;
-+}
-+
-+static inline int
-+__testip(struct ip_set *set, ip_set_ip_t ip, ip_set_ip_t port,
-+ ip_set_ip_t *hash_ip)
-+{
-+ struct ip_set_ipporthash *map = (struct ip_set_ipporthash *) set->data;
-+
-+ if (ip < map->first_ip || ip > map->last_ip)
-+ return -ERANGE;
-+
-+ return (hash_id(set, ip, port, hash_ip) != UINT_MAX);
-+}
-+
-+static int
-+testip(struct ip_set *set, const void *data, size_t size,
-+ ip_set_ip_t *hash_ip)
-+{
-+ struct ip_set_req_ipporthash *req =
-+ (struct ip_set_req_ipporthash *) data;
-+
-+ if (size != sizeof(struct ip_set_req_ipporthash)) {
-+ ip_set_printk("data length wrong (want %zu, have %zu)",
-+ sizeof(struct ip_set_req_ipporthash),
-+ size);
-+ return -EINVAL;
-+ }
-+ return __testip(set, req->ip, req->port, hash_ip);
-+}
-+
-+static int
-+testip_kernel(struct ip_set *set,
-+ const struct sk_buff *skb,
-+ ip_set_ip_t *hash_ip,
-+ const u_int32_t *flags,
-+ unsigned char index)
-+{
-+ ip_set_ip_t port;
-+ int res;
-+
-+ if (flags[index+1] == 0)
-+ return 0;
-+
-+ port = get_port(skb, flags[index+1]);
-+
-+ DP("flag: %s src: %u.%u.%u.%u dst: %u.%u.%u.%u",
-+ flags[index] & IPSET_SRC ? "SRC" : "DST",
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-+ NIPQUAD(ip_hdr(skb)->saddr),
-+ NIPQUAD(ip_hdr(skb)->daddr));
-+#else
-+ NIPQUAD(skb->nh.iph->saddr),
-+ NIPQUAD(skb->nh.iph->daddr));
-+#endif
-+ DP("flag %s port %u",
-+ flags[index+1] & IPSET_SRC ? "SRC" : "DST",
-+ port);
-+ if (port == INVALID_PORT)
-+ return 0;
-+
-+ res = __testip(set,
-+ ntohl(flags[index] & IPSET_SRC
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-+ ? ip_hdr(skb)->saddr
-+ : ip_hdr(skb)->daddr),
-+#else
-+ ? skb->nh.iph->saddr
-+ : skb->nh.iph->daddr),
-+#endif
-+ port,
-+ hash_ip);
-+ return (res < 0 ? 0 : res);
-+
-+}
-+
-+static inline int
-+__add_haship(struct ip_set_ipporthash *map, ip_set_ip_t hash_ip)
-+{
-+ __u32 probe;
-+ u_int16_t i;
-+ ip_set_ip_t *elem;
-+
-+ for (i = 0; i < map->probes; i++) {
-+ probe = jhash_ip(map, i, hash_ip) % map->hashsize;
-+ elem = HARRAY_ELEM(map->members, ip_set_ip_t *, probe);
-+ if (*elem == hash_ip)
-+ return -EEXIST;
-+ if (!*elem) {
-+ *elem = hash_ip;
-+ map->elements++;
-+ return 0;
-+ }
-+ }
-+ /* Trigger rehashing */
-+ return -EAGAIN;
-+}
-+
-+static inline int
-+__addip(struct ip_set_ipporthash *map, ip_set_ip_t ip, ip_set_ip_t port,
-+ ip_set_ip_t *hash_ip)
-+{
-+ if (map->elements > limit)
-+ return -ERANGE;
-+ if (ip < map->first_ip || ip > map->last_ip)
-+ return -ERANGE;
-+
-+ *hash_ip = HASH_IP(map, ip, port);
-+
-+ return __add_haship(map, *hash_ip);
-+}
-+
-+static int
-+addip(struct ip_set *set, const void *data, size_t size,
-+ ip_set_ip_t *hash_ip)
-+{
-+ struct ip_set_req_ipporthash *req =
-+ (struct ip_set_req_ipporthash *) data;
-+
-+ if (size != sizeof(struct ip_set_req_ipporthash)) {
-+ ip_set_printk("data length wrong (want %zu, have %zu)",
-+ sizeof(struct ip_set_req_ipporthash),
-+ size);
-+ return -EINVAL;
-+ }
-+ return __addip((struct ip_set_ipporthash *) set->data,
-+ req->ip, req->port, hash_ip);
-+}
-+
-+static int
-+addip_kernel(struct ip_set *set,
-+ const struct sk_buff *skb,
-+ ip_set_ip_t *hash_ip,
-+ const u_int32_t *flags,
-+ unsigned char index)
-+{
-+ ip_set_ip_t port;
-+
-+ if (flags[index+1] == 0)
-+ return -EINVAL;
-+
-+ port = get_port(skb, flags[index+1]);
-+
-+ DP("flag: %s src: %u.%u.%u.%u dst: %u.%u.%u.%u",
-+ flags[index] & IPSET_SRC ? "SRC" : "DST",
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-+ NIPQUAD(ip_hdr(skb)->saddr),
-+ NIPQUAD(ip_hdr(skb)->daddr));
-+#else
-+ NIPQUAD(skb->nh.iph->saddr),
-+ NIPQUAD(skb->nh.iph->daddr));
-+#endif
-+ DP("flag %s port %u",
-+ flags[index+1] & IPSET_SRC ? "SRC" : "DST",
-+ port);
-+ if (port == INVALID_PORT)
-+ return -EINVAL;
-+
-+ return __addip((struct ip_set_ipporthash *) set->data,
-+ ntohl(flags[index] & IPSET_SRC
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-+ ? ip_hdr(skb)->saddr
-+ : ip_hdr(skb)->daddr),
-+#else
-+ ? skb->nh.iph->saddr
-+ : skb->nh.iph->daddr),
-+#endif
-+ port,
-+ hash_ip);
-+}
-+
-+static int retry(struct ip_set *set)
-+{
-+ struct ip_set_ipporthash *map = (struct ip_set_ipporthash *) set->data;
-+ ip_set_ip_t *elem;
-+ void *members;
-+ u_int32_t i, hashsize = map->hashsize;
-+ int res;
-+ struct ip_set_ipporthash *tmp;
-+
-+ if (map->resize == 0)
-+ return -ERANGE;
-+
-+ again:
-+ res = 0;
-+
-+ /* Calculate new hash size */
-+ hashsize += (hashsize * map->resize)/100;
-+ if (hashsize == map->hashsize)
-+ hashsize++;
-+
-+ ip_set_printk("rehashing of set %s triggered: "
-+ "hashsize grows from %u to %u",
-+ set->name, map->hashsize, hashsize);
-+
-+ tmp = kmalloc(sizeof(struct ip_set_ipporthash)
-+ + map->probes * sizeof(uint32_t), GFP_ATOMIC);
-+ if (!tmp) {
-+ DP("out of memory for %d bytes",
-+ sizeof(struct ip_set_ipporthash)
-+ + map->probes * sizeof(uint32_t));
-+ return -ENOMEM;
-+ }
-+ tmp->members = harray_malloc(hashsize, sizeof(ip_set_ip_t), GFP_ATOMIC);
-+ if (!tmp->members) {
-+ DP("out of memory for %d bytes", hashsize * sizeof(ip_set_ip_t));
-+ kfree(tmp);
-+ return -ENOMEM;
-+ }
-+ tmp->hashsize = hashsize;
-+ tmp->elements = 0;
-+ tmp->probes = map->probes;
-+ tmp->resize = map->resize;
-+ tmp->first_ip = map->first_ip;
-+ tmp->last_ip = map->last_ip;
-+ memcpy(tmp->initval, map->initval, map->probes * sizeof(uint32_t));
-+
-+ write_lock_bh(&set->lock);
-+ map = (struct ip_set_ipporthash *) set->data; /* Play safe */
-+ for (i = 0; i < map->hashsize && res == 0; i++) {
-+ elem = HARRAY_ELEM(map->members, ip_set_ip_t *, i);
-+ if (*elem)
-+ res = __add_haship(tmp, *elem);
-+ }
-+ if (res) {
-+ /* Failure, try again */
-+ write_unlock_bh(&set->lock);
-+ harray_free(tmp->members);
-+ kfree(tmp);
-+ goto again;
-+ }
-+
-+ /* Success at resizing! */
-+ members = map->members;
-+
-+ map->hashsize = tmp->hashsize;
-+ map->members = tmp->members;
-+ write_unlock_bh(&set->lock);
-+
-+ harray_free(members);
-+ kfree(tmp);
-+
-+ return 0;
-+}
-+
-+static inline int
-+__delip(struct ip_set *set, ip_set_ip_t ip, ip_set_ip_t port,
-+ ip_set_ip_t *hash_ip)
-+{
-+ struct ip_set_ipporthash *map = (struct ip_set_ipporthash *) set->data;
-+ ip_set_ip_t id;
-+ ip_set_ip_t *elem;
-+
-+ if (ip < map->first_ip || ip > map->last_ip)
-+ return -ERANGE;
-+
-+ id = hash_id(set, ip, port, hash_ip);
-+
-+ if (id == UINT_MAX)
-+ return -EEXIST;
-+
-+ elem = HARRAY_ELEM(map->members, ip_set_ip_t *, id);
-+ *elem = 0;
-+ map->elements--;
-+
-+ return 0;
-+}
-+
-+static int
-+delip(struct ip_set *set, const void *data, size_t size,
-+ ip_set_ip_t *hash_ip)
-+{
-+ struct ip_set_req_ipporthash *req =
-+ (struct ip_set_req_ipporthash *) data;
-+
-+ if (size != sizeof(struct ip_set_req_ipporthash)) {
-+ ip_set_printk("data length wrong (want %zu, have %zu)",
-+ sizeof(struct ip_set_req_ipporthash),
-+ size);
-+ return -EINVAL;
-+ }
-+ return __delip(set, req->ip, req->port, hash_ip);
-+}
-+
-+static int
-+delip_kernel(struct ip_set *set,
-+ const struct sk_buff *skb,
-+ ip_set_ip_t *hash_ip,
-+ const u_int32_t *flags,
-+ unsigned char index)
-+{
-+ ip_set_ip_t port;
-+
-+ if (flags[index+1] == 0)
-+ return -EINVAL;
-+
-+ port = get_port(skb, flags[index+1]);
-+
-+ DP("flag: %s src: %u.%u.%u.%u dst: %u.%u.%u.%u",
-+ flags[index] & IPSET_SRC ? "SRC" : "DST",
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-+ NIPQUAD(ip_hdr(skb)->saddr),
-+ NIPQUAD(ip_hdr(skb)->daddr));
-+#else
-+ NIPQUAD(skb->nh.iph->saddr),
-+ NIPQUAD(skb->nh.iph->daddr));
-+#endif
-+ DP("flag %s port %u",
-+ flags[index+1] & IPSET_SRC ? "SRC" : "DST",
-+ port);
-+ if (port == INVALID_PORT)
-+ return -EINVAL;
-+
-+ return __delip(set,
-+ ntohl(flags[index] & IPSET_SRC
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-+ ? ip_hdr(skb)->saddr
-+ : ip_hdr(skb)->daddr),
-+#else
-+ ? skb->nh.iph->saddr
-+ : skb->nh.iph->daddr),
-+#endif
-+ port,
-+ hash_ip);
-+}
-+
-+static int create(struct ip_set *set, const void *data, size_t size)
-+{
-+ struct ip_set_req_ipporthash_create *req =
-+ (struct ip_set_req_ipporthash_create *) data;
-+ struct ip_set_ipporthash *map;
-+ uint16_t i;
-+
-+ if (size != sizeof(struct ip_set_req_ipporthash_create)) {
-+ ip_set_printk("data length wrong (want %zu, have %zu)",
-+ sizeof(struct ip_set_req_ipporthash_create),
-+ size);
-+ return -EINVAL;
-+ }
-+
-+ if (req->hashsize < 1) {
-+ ip_set_printk("hashsize too small");
-+ return -ENOEXEC;
-+ }
-+
-+ if (req->probes < 1) {
-+ ip_set_printk("probes too small");
-+ return -ENOEXEC;
-+ }
-+
-+ map = kmalloc(sizeof(struct ip_set_ipporthash)
-+ + req->probes * sizeof(uint32_t), GFP_KERNEL);
-+ if (!map) {
-+ DP("out of memory for %d bytes",
-+ sizeof(struct ip_set_ipporthash)
-+ + req->probes * sizeof(uint32_t));
-+ return -ENOMEM;
-+ }
-+ for (i = 0; i < req->probes; i++)
-+ get_random_bytes(((uint32_t *) map->initval)+i, 4);
-+ map->elements = 0;
-+ map->hashsize = req->hashsize;
-+ map->probes = req->probes;
-+ map->resize = req->resize;
-+ map->first_ip = req->from;
-+ map->last_ip = req->to;
-+ map->members = harray_malloc(map->hashsize, sizeof(ip_set_ip_t), GFP_KERNEL);
-+ if (!map->members) {
-+ DP("out of memory for %d bytes", map->hashsize * sizeof(ip_set_ip_t));
-+ kfree(map);
-+ return -ENOMEM;
-+ }
-+
-+ set->data = map;
-+ return 0;
-+}
-+
-+static void destroy(struct ip_set *set)
-+{
-+ struct ip_set_ipporthash *map = (struct ip_set_ipporthash *) set->data;
-+
-+ harray_free(map->members);
-+ kfree(map);
-+
-+ set->data = NULL;
-+}
-+
-+static void flush(struct ip_set *set)
-+{
-+ struct ip_set_ipporthash *map = (struct ip_set_ipporthash *) set->data;
-+ harray_flush(map->members, map->hashsize, sizeof(ip_set_ip_t));
-+ map->elements = 0;
-+}
-+
-+static void list_header(const struct ip_set *set, void *data)
-+{
-+ struct ip_set_ipporthash *map = (struct ip_set_ipporthash *) set->data;
-+ struct ip_set_req_ipporthash_create *header =
-+ (struct ip_set_req_ipporthash_create *) data;
-+
-+ header->hashsize = map->hashsize;
-+ header->probes = map->probes;
-+ header->resize = map->resize;
-+ header->from = map->first_ip;
-+ header->to = map->last_ip;
-+}
-+
-+static int list_members_size(const struct ip_set *set)
-+{
-+ struct ip_set_ipporthash *map = (struct ip_set_ipporthash *) set->data;
-+
-+ return (map->hashsize * sizeof(ip_set_ip_t));
-+}
-+
-+static void list_members(const struct ip_set *set, void *data)
-+{
-+ struct ip_set_ipporthash *map = (struct ip_set_ipporthash *) set->data;
-+ ip_set_ip_t i, *elem;
-+
-+ for (i = 0; i < map->hashsize; i++) {
-+ elem = HARRAY_ELEM(map->members, ip_set_ip_t *, i);
-+ ((ip_set_ip_t *)data)[i] = *elem;
-+ }
-+}
-+
-+static struct ip_set_type ip_set_ipporthash = {
-+ .typename = SETTYPE_NAME,
-+ .features = IPSET_TYPE_IP | IPSET_TYPE_PORT | IPSET_DATA_DOUBLE,
-+ .protocol_version = IP_SET_PROTOCOL_VERSION,
-+ .create = &create,
-+ .destroy = &destroy,
-+ .flush = &flush,
-+ .reqsize = sizeof(struct ip_set_req_ipporthash),
-+ .addip = &addip,
-+ .addip_kernel = &addip_kernel,
-+ .retry = &retry,
-+ .delip = &delip,
-+ .delip_kernel = &delip_kernel,
-+ .testip = &testip,
-+ .testip_kernel = &testip_kernel,
-+ .header_size = sizeof(struct ip_set_req_ipporthash_create),
-+ .list_header = &list_header,
-+ .list_members_size = &list_members_size,
-+ .list_members = &list_members,
-+ .me = THIS_MODULE,
-+};
-+
-+MODULE_LICENSE("GPL");
-+MODULE_AUTHOR("Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>");
-+MODULE_DESCRIPTION("ipporthash type of IP sets");
-+module_param(limit, int, 0600);
-+MODULE_PARM_DESC(limit, "maximal number of elements stored in the sets");
-+
-+static int __init ip_set_ipporthash_init(void)
-+{
-+ return ip_set_register_set_type(&ip_set_ipporthash);
-+}
-+
-+static void __exit ip_set_ipporthash_fini(void)
-+{
-+ /* FIXME: possible race with ip_set_create() */
-+ ip_set_unregister_set_type(&ip_set_ipporthash);
-+}
-+
-+module_init(ip_set_ipporthash_init);
-+module_exit(ip_set_ipporthash_fini);
-Index: linux-2.6.21.7/net/ipv4/netfilter/ip_set_iptree.c
-===================================================================
---- /dev/null
-+++ linux-2.6.21.7/net/ipv4/netfilter/ip_set_iptree.c
-@@ -0,0 +1,612 @@
-+/* Copyright (C) 2005 Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
-+ *
-+ * This program is free software; you can redistribute it and/or modify
-+ * it under the terms of the GNU General Public License version 2 as
-+ * published by the Free Software Foundation.
-+ */
-+
-+/* Kernel module implementing an IP set type: the iptree type */
-+
-+#include <linux/version.h>
-+#include <linux/module.h>
-+#include <linux/ip.h>
-+#include <linux/skbuff.h>
-+#include <linux/slab.h>
-+#include <linux/delay.h>
-+#include <linux/netfilter_ipv4/ip_tables.h>
-+#include <linux/netfilter_ipv4/ip_set.h>
-+#include <linux/errno.h>
-+#include <asm/uaccess.h>
-+#include <asm/bitops.h>
-+#include <linux/spinlock.h>
-+
-+/* Backward compatibility */
-+#ifndef __nocast
-+#define __nocast
-+#endif
-+
-+#include <linux/netfilter_ipv4/ip_set_iptree.h>
-+
-+static int limit = MAX_RANGE;
-+
-+/* Garbage collection interval in seconds: */
-+#define IPTREE_GC_TIME 5*60
-+/* Sleep so many milliseconds before trying again
-+ * to delete the gc timer at destroying/flushing a set */
-+#define IPTREE_DESTROY_SLEEP 100
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,21)
-+static struct kmem_cache *branch_cachep;
-+static struct kmem_cache *leaf_cachep;
-+#else
-+static kmem_cache_t *branch_cachep;
-+static kmem_cache_t *leaf_cachep;
-+#endif
-+
-+#if defined(__LITTLE_ENDIAN)
-+#define ABCD(a,b,c,d,addrp) do { \
-+ a = ((unsigned char *)addrp)[3]; \
-+ b = ((unsigned char *)addrp)[2]; \
-+ c = ((unsigned char *)addrp)[1]; \
-+ d = ((unsigned char *)addrp)[0]; \
-+} while (0)
-+#elif defined(__BIG_ENDIAN)
-+#define ABCD(a,b,c,d,addrp) do { \
-+ a = ((unsigned char *)addrp)[0]; \
-+ b = ((unsigned char *)addrp)[1]; \
-+ c = ((unsigned char *)addrp)[2]; \
-+ d = ((unsigned char *)addrp)[3]; \
-+} while (0)
-+#else
-+#error "Please fix asm/byteorder.h"
-+#endif /* __LITTLE_ENDIAN */
-+
-+#define TESTIP_WALK(map, elem, branch) do { \
-+ if ((map)->tree[elem]) { \
-+ branch = (map)->tree[elem]; \
-+ } else \
-+ return 0; \
-+} while (0)
-+
-+static inline int
-+__testip(struct ip_set *set, ip_set_ip_t ip, ip_set_ip_t *hash_ip)
-+{
-+ struct ip_set_iptree *map = (struct ip_set_iptree *) set->data;
-+ struct ip_set_iptreeb *btree;
-+ struct ip_set_iptreec *ctree;
-+ struct ip_set_iptreed *dtree;
-+ unsigned char a,b,c,d;
-+
-+ if (!ip)
-+ return -ERANGE;
-+
-+ *hash_ip = ip;
-+ ABCD(a, b, c, d, hash_ip);
-+ DP("%u %u %u %u timeout %u", a, b, c, d, map->timeout);
-+ TESTIP_WALK(map, a, btree);
-+ TESTIP_WALK(btree, b, ctree);
-+ TESTIP_WALK(ctree, c, dtree);
-+ DP("%lu %lu", dtree->expires[d], jiffies);
-+ return dtree->expires[d]
-+ && (!map->timeout
-+ || time_after(dtree->expires[d], jiffies));
-+}
-+
-+static int
-+testip(struct ip_set *set, const void *data, size_t size,
-+ ip_set_ip_t *hash_ip)
-+{
-+ struct ip_set_req_iptree *req =
-+ (struct ip_set_req_iptree *) data;
-+
-+ if (size != sizeof(struct ip_set_req_iptree)) {
-+ ip_set_printk("data length wrong (want %zu, have %zu)",
-+ sizeof(struct ip_set_req_iptree),
-+ size);
-+ return -EINVAL;
-+ }
-+ return __testip(set, req->ip, hash_ip);
-+}
-+
-+static int
-+testip_kernel(struct ip_set *set,
-+ const struct sk_buff *skb,
-+ ip_set_ip_t *hash_ip,
-+ const u_int32_t *flags,
-+ unsigned char index)
-+{
-+ int res;
-+
-+ DP("flag: %s src: %u.%u.%u.%u dst: %u.%u.%u.%u",
-+ flags[index] & IPSET_SRC ? "SRC" : "DST",
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-+ NIPQUAD(ip_hdr(skb)->saddr),
-+ NIPQUAD(ip_hdr(skb)->daddr));
-+#else
-+ NIPQUAD(skb->nh.iph->saddr),
-+ NIPQUAD(skb->nh.iph->daddr));
-+#endif
-+
-+ res = __testip(set,
-+ ntohl(flags[index] & IPSET_SRC
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-+ ? ip_hdr(skb)->saddr
-+ : ip_hdr(skb)->daddr),
-+#else
-+ ? skb->nh.iph->saddr
-+ : skb->nh.iph->daddr),
-+#endif
-+ hash_ip);
-+ return (res < 0 ? 0 : res);
-+}
-+
-+#define ADDIP_WALK(map, elem, branch, type, cachep) do { \
-+ if ((map)->tree[elem]) { \
-+ DP("found %u", elem); \
-+ branch = (map)->tree[elem]; \
-+ } else { \
-+ branch = (type *) \
-+ kmem_cache_alloc(cachep, GFP_ATOMIC); \
-+ if (branch == NULL) \
-+ return -ENOMEM; \
-+ memset(branch, 0, sizeof(*branch)); \
-+ (map)->tree[elem] = branch; \
-+ DP("alloc %u", elem); \
-+ } \
-+} while (0)
-+
-+static inline int
-+__addip(struct ip_set *set, ip_set_ip_t ip, unsigned int timeout,
-+ ip_set_ip_t *hash_ip)
-+{
-+ struct ip_set_iptree *map = (struct ip_set_iptree *) set->data;
-+ struct ip_set_iptreeb *btree;
-+ struct ip_set_iptreec *ctree;
-+ struct ip_set_iptreed *dtree;
-+ unsigned char a,b,c,d;
-+ int ret = 0;
-+
-+ if (!ip || map->elements >= limit)
-+ /* We could call the garbage collector
-+ * but it's probably overkill */
-+ return -ERANGE;
-+
-+ *hash_ip = ip;
-+ ABCD(a, b, c, d, hash_ip);
-+ DP("%u %u %u %u timeout %u", a, b, c, d, timeout);
-+ ADDIP_WALK(map, a, btree, struct ip_set_iptreeb, branch_cachep);
-+ ADDIP_WALK(btree, b, ctree, struct ip_set_iptreec, branch_cachep);
-+ ADDIP_WALK(ctree, c, dtree, struct ip_set_iptreed, leaf_cachep);
-+ if (dtree->expires[d]
-+ && (!map->timeout || time_after(dtree->expires[d], jiffies)))
-+ ret = -EEXIST;
-+ dtree->expires[d] = map->timeout ? (timeout * HZ + jiffies) : 1;
-+ /* Lottery: I won! */
-+ if (dtree->expires[d] == 0)
-+ dtree->expires[d] = 1;
-+ DP("%u %lu", d, dtree->expires[d]);
-+ if (ret == 0)
-+ map->elements++;
-+ return ret;
-+}
-+
-+static int
-+addip(struct ip_set *set, const void *data, size_t size,
-+ ip_set_ip_t *hash_ip)
-+{
-+ struct ip_set_iptree *map = (struct ip_set_iptree *) set->data;
-+ struct ip_set_req_iptree *req =
-+ (struct ip_set_req_iptree *) data;
-+
-+ if (size != sizeof(struct ip_set_req_iptree)) {
-+ ip_set_printk("data length wrong (want %zu, have %zu)",
-+ sizeof(struct ip_set_req_iptree),
-+ size);
-+ return -EINVAL;
-+ }
-+ DP("%u.%u.%u.%u %u", HIPQUAD(req->ip), req->timeout);
-+ return __addip(set, req->ip,
-+ req->timeout ? req->timeout : map->timeout,
-+ hash_ip);
-+}
-+
-+static int
-+addip_kernel(struct ip_set *set,
-+ const struct sk_buff *skb,
-+ ip_set_ip_t *hash_ip,
-+ const u_int32_t *flags,
-+ unsigned char index)
-+{
-+ struct ip_set_iptree *map = (struct ip_set_iptree *) set->data;
-+
-+ return __addip(set,
-+ ntohl(flags[index] & IPSET_SRC
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-+ ? ip_hdr(skb)->saddr
-+ : ip_hdr(skb)->daddr),
-+#else
-+ ? skb->nh.iph->saddr
-+ : skb->nh.iph->daddr),
-+#endif
-+ map->timeout,
-+ hash_ip);
-+}
-+
-+#define DELIP_WALK(map, elem, branch) do { \
-+ if ((map)->tree[elem]) { \
-+ branch = (map)->tree[elem]; \
-+ } else \
-+ return -EEXIST; \
-+} while (0)
-+
-+static inline int
-+__delip(struct ip_set *set, ip_set_ip_t ip, ip_set_ip_t *hash_ip)
-+{
-+ struct ip_set_iptree *map = (struct ip_set_iptree *) set->data;
-+ struct ip_set_iptreeb *btree;
-+ struct ip_set_iptreec *ctree;
-+ struct ip_set_iptreed *dtree;
-+ unsigned char a,b,c,d;
-+
-+ if (!ip)
-+ return -ERANGE;
-+
-+ *hash_ip = ip;
-+ ABCD(a, b, c, d, hash_ip);
-+ DELIP_WALK(map, a, btree);
-+ DELIP_WALK(btree, b, ctree);
-+ DELIP_WALK(ctree, c, dtree);
-+
-+ if (dtree->expires[d]) {
-+ dtree->expires[d] = 0;
-+ map->elements--;
-+ return 0;
-+ }
-+ return -EEXIST;
-+}
-+
-+static int
-+delip(struct ip_set *set, const void *data, size_t size,
-+ ip_set_ip_t *hash_ip)
-+{
-+ struct ip_set_req_iptree *req =
-+ (struct ip_set_req_iptree *) data;
-+
-+ if (size != sizeof(struct ip_set_req_iptree)) {
-+ ip_set_printk("data length wrong (want %zu, have %zu)",
-+ sizeof(struct ip_set_req_iptree),
-+ size);
-+ return -EINVAL;
-+ }
-+ return __delip(set, req->ip, hash_ip);
-+}
-+
-+static int
-+delip_kernel(struct ip_set *set,
-+ const struct sk_buff *skb,
-+ ip_set_ip_t *hash_ip,
-+ const u_int32_t *flags,
-+ unsigned char index)
-+{
-+ return __delip(set,
-+ ntohl(flags[index] & IPSET_SRC
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-+ ? ip_hdr(skb)->saddr
-+ : ip_hdr(skb)->daddr),
-+#else
-+ ? skb->nh.iph->saddr
-+ : skb->nh.iph->daddr),
-+#endif
-+ hash_ip);
-+}
-+
-+#define LOOP_WALK_BEGIN(map, i, branch) \
-+ for (i = 0; i < 256; i++) { \
-+ if (!(map)->tree[i]) \
-+ continue; \
-+ branch = (map)->tree[i]
-+
-+#define LOOP_WALK_END }
-+
-+static void ip_tree_gc(unsigned long ul_set)
-+{
-+ struct ip_set *set = (void *) ul_set;
-+ struct ip_set_iptree *map = (struct ip_set_iptree *) set->data;
-+ struct ip_set_iptreeb *btree;
-+ struct ip_set_iptreec *ctree;
-+ struct ip_set_iptreed *dtree;
-+ unsigned int a,b,c,d;
-+ unsigned char i,j,k;
-+
-+ i = j = k = 0;
-+ DP("gc: %s", set->name);
-+ write_lock_bh(&set->lock);
-+ LOOP_WALK_BEGIN(map, a, btree);
-+ LOOP_WALK_BEGIN(btree, b, ctree);
-+ LOOP_WALK_BEGIN(ctree, c, dtree);
-+ for (d = 0; d < 256; d++) {
-+ if (dtree->expires[d]) {
-+ DP("gc: %u %u %u %u: expires %lu jiffies %lu",
-+ a, b, c, d,
-+ dtree->expires[d], jiffies);
-+ if (map->timeout
-+ && time_before(dtree->expires[d], jiffies)) {
-+ dtree->expires[d] = 0;
-+ map->elements--;
-+ } else
-+ k = 1;
-+ }
-+ }
-+ if (k == 0) {
-+ DP("gc: %s: leaf %u %u %u empty",
-+ set->name, a, b, c);
-+ kmem_cache_free(leaf_cachep, dtree);
-+ ctree->tree[c] = NULL;
-+ } else {
-+ DP("gc: %s: leaf %u %u %u not empty",
-+ set->name, a, b, c);
-+ j = 1;
-+ k = 0;
-+ }
-+ LOOP_WALK_END;
-+ if (j == 0) {
-+ DP("gc: %s: branch %u %u empty",
-+ set->name, a, b);
-+ kmem_cache_free(branch_cachep, ctree);
-+ btree->tree[b] = NULL;
-+ } else {
-+ DP("gc: %s: branch %u %u not empty",
-+ set->name, a, b);
-+ i = 1;
-+ j = k = 0;
-+ }
-+ LOOP_WALK_END;
-+ if (i == 0) {
-+ DP("gc: %s: branch %u empty",
-+ set->name, a);
-+ kmem_cache_free(branch_cachep, btree);
-+ map->tree[a] = NULL;
-+ } else {
-+ DP("gc: %s: branch %u not empty",
-+ set->name, a);
-+ i = j = k = 0;
-+ }
-+ LOOP_WALK_END;
-+ write_unlock_bh(&set->lock);
-+
-+ map->gc.expires = jiffies + map->gc_interval * HZ;
-+ add_timer(&map->gc);
-+}
-+
-+static inline void init_gc_timer(struct ip_set *set)
-+{
-+ struct ip_set_iptree *map = (struct ip_set_iptree *) set->data;
-+
-+ /* Even if there is no timeout for the entries,
-+ * we still have to call gc because delete
-+ * do not clean up empty branches */
-+ map->gc_interval = IPTREE_GC_TIME;
-+ init_timer(&map->gc);
-+ map->gc.data = (unsigned long) set;
-+ map->gc.function = ip_tree_gc;
-+ map->gc.expires = jiffies + map->gc_interval * HZ;
-+ add_timer(&map->gc);
-+}
-+
-+static int create(struct ip_set *set, const void *data, size_t size)
-+{
-+ struct ip_set_req_iptree_create *req =
-+ (struct ip_set_req_iptree_create *) data;
-+ struct ip_set_iptree *map;
-+
-+ if (size != sizeof(struct ip_set_req_iptree_create)) {
-+ ip_set_printk("data length wrong (want %zu, have %zu)",
-+ sizeof(struct ip_set_req_iptree_create),
-+ size);
-+ return -EINVAL;
-+ }
-+
-+ map = kmalloc(sizeof(struct ip_set_iptree), GFP_KERNEL);
-+ if (!map) {
-+ DP("out of memory for %d bytes",
-+ sizeof(struct ip_set_iptree));
-+ return -ENOMEM;
-+ }
-+ memset(map, 0, sizeof(*map));
-+ map->timeout = req->timeout;
-+ map->elements = 0;
-+ set->data = map;
-+
-+ init_gc_timer(set);
-+
-+ return 0;
-+}
-+
-+static void __flush(struct ip_set_iptree *map)
-+{
-+ struct ip_set_iptreeb *btree;
-+ struct ip_set_iptreec *ctree;
-+ struct ip_set_iptreed *dtree;
-+ unsigned int a,b,c;
-+
-+ LOOP_WALK_BEGIN(map, a, btree);
-+ LOOP_WALK_BEGIN(btree, b, ctree);
-+ LOOP_WALK_BEGIN(ctree, c, dtree);
-+ kmem_cache_free(leaf_cachep, dtree);
-+ LOOP_WALK_END;
-+ kmem_cache_free(branch_cachep, ctree);
-+ LOOP_WALK_END;
-+ kmem_cache_free(branch_cachep, btree);
-+ LOOP_WALK_END;
-+ map->elements = 0;
-+}
-+
-+static void destroy(struct ip_set *set)
-+{
-+ struct ip_set_iptree *map = (struct ip_set_iptree *) set->data;
-+
-+ /* gc might be running */
-+ while (!del_timer(&map->gc))
-+ msleep(IPTREE_DESTROY_SLEEP);
-+ __flush(map);
-+ kfree(map);
-+ set->data = NULL;
-+}
-+
-+static void flush(struct ip_set *set)
-+{
-+ struct ip_set_iptree *map = (struct ip_set_iptree *) set->data;
-+ unsigned int timeout = map->timeout;
-+
-+ /* gc might be running */
-+ while (!del_timer(&map->gc))
-+ msleep(IPTREE_DESTROY_SLEEP);
-+ __flush(map);
-+ memset(map, 0, sizeof(*map));
-+ map->timeout = timeout;
-+
-+ init_gc_timer(set);
-+}
-+
-+static void list_header(const struct ip_set *set, void *data)
-+{
-+ struct ip_set_iptree *map = (struct ip_set_iptree *) set->data;
-+ struct ip_set_req_iptree_create *header =
-+ (struct ip_set_req_iptree_create *) data;
-+
-+ header->timeout = map->timeout;
-+}
-+
-+static int list_members_size(const struct ip_set *set)
-+{
-+ struct ip_set_iptree *map = (struct ip_set_iptree *) set->data;
-+ struct ip_set_iptreeb *btree;
-+ struct ip_set_iptreec *ctree;
-+ struct ip_set_iptreed *dtree;
-+ unsigned int a,b,c,d;
-+ unsigned int count = 0;
-+
-+ LOOP_WALK_BEGIN(map, a, btree);
-+ LOOP_WALK_BEGIN(btree, b, ctree);
-+ LOOP_WALK_BEGIN(ctree, c, dtree);
-+ for (d = 0; d < 256; d++) {
-+ if (dtree->expires[d]
-+ && (!map->timeout || time_after(dtree->expires[d], jiffies)))
-+ count++;
-+ }
-+ LOOP_WALK_END;
-+ LOOP_WALK_END;
-+ LOOP_WALK_END;
-+
-+ DP("members %u", count);
-+ return (count * sizeof(struct ip_set_req_iptree));
-+}
-+
-+static void list_members(const struct ip_set *set, void *data)
-+{
-+ struct ip_set_iptree *map = (struct ip_set_iptree *) set->data;
-+ struct ip_set_iptreeb *btree;
-+ struct ip_set_iptreec *ctree;
-+ struct ip_set_iptreed *dtree;
-+ unsigned int a,b,c,d;
-+ size_t offset = 0;
-+ struct ip_set_req_iptree *entry;
-+
-+ LOOP_WALK_BEGIN(map, a, btree);
-+ LOOP_WALK_BEGIN(btree, b, ctree);
-+ LOOP_WALK_BEGIN(ctree, c, dtree);
-+ for (d = 0; d < 256; d++) {
-+ if (dtree->expires[d]
-+ && (!map->timeout || time_after(dtree->expires[d], jiffies))) {
-+ entry = (struct ip_set_req_iptree *)(data + offset);
-+ entry->ip = ((a << 24) | (b << 16) | (c << 8) | d);
-+ entry->timeout = !map->timeout ? 0
-+ : (dtree->expires[d] - jiffies)/HZ;
-+ offset += sizeof(struct ip_set_req_iptree);
-+ }
-+ }
-+ LOOP_WALK_END;
-+ LOOP_WALK_END;
-+ LOOP_WALK_END;
-+}
-+
-+static struct ip_set_type ip_set_iptree = {
-+ .typename = SETTYPE_NAME,
-+ .features = IPSET_TYPE_IP | IPSET_DATA_SINGLE,
-+ .protocol_version = IP_SET_PROTOCOL_VERSION,
-+ .create = &create,
-+ .destroy = &destroy,
-+ .flush = &flush,
-+ .reqsize = sizeof(struct ip_set_req_iptree),
-+ .addip = &addip,
-+ .addip_kernel = &addip_kernel,
-+ .delip = &delip,
-+ .delip_kernel = &delip_kernel,
-+ .testip = &testip,
-+ .testip_kernel = &testip_kernel,
-+ .header_size = sizeof(struct ip_set_req_iptree_create),
-+ .list_header = &list_header,
-+ .list_members_size = &list_members_size,
-+ .list_members = &list_members,
-+ .me = THIS_MODULE,
-+};
-+
-+MODULE_LICENSE("GPL");
-+MODULE_AUTHOR("Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>");
-+MODULE_DESCRIPTION("iptree type of IP sets");
-+module_param(limit, int, 0600);
-+MODULE_PARM_DESC(limit, "maximal number of elements stored in the sets");
-+
-+static int __init ip_set_iptree_init(void)
-+{
-+ int ret;
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,23)
-+ branch_cachep = kmem_cache_create("ip_set_iptreeb",
-+ sizeof(struct ip_set_iptreeb),
-+ 0, 0, NULL);
-+#else
-+ branch_cachep = kmem_cache_create("ip_set_iptreeb",
-+ sizeof(struct ip_set_iptreeb),
-+ 0, 0, NULL, NULL);
-+#endif
-+ if (!branch_cachep) {
-+ printk(KERN_ERR "Unable to create ip_set_iptreeb slab cache\n");
-+ ret = -ENOMEM;
-+ goto out;
-+ }
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,23)
-+ leaf_cachep = kmem_cache_create("ip_set_iptreed",
-+ sizeof(struct ip_set_iptreed),
-+ 0, 0, NULL);
-+#else
-+ leaf_cachep = kmem_cache_create("ip_set_iptreed",
-+ sizeof(struct ip_set_iptreed),
-+ 0, 0, NULL, NULL);
-+#endif
-+ if (!leaf_cachep) {
-+ printk(KERN_ERR "Unable to create ip_set_iptreed slab cache\n");
-+ ret = -ENOMEM;
-+ goto free_branch;
-+ }
-+ ret = ip_set_register_set_type(&ip_set_iptree);
-+ if (ret == 0)
-+ goto out;
-+
-+ kmem_cache_destroy(leaf_cachep);
-+ free_branch:
-+ kmem_cache_destroy(branch_cachep);
-+ out:
-+ return ret;
-+}
-+
-+static void __exit ip_set_iptree_fini(void)
-+{
-+ /* FIXME: possible race with ip_set_create() */
-+ ip_set_unregister_set_type(&ip_set_iptree);
-+ kmem_cache_destroy(leaf_cachep);
-+ kmem_cache_destroy(branch_cachep);
-+}
-+
-+module_init(ip_set_iptree_init);
-+module_exit(ip_set_iptree_fini);
-Index: linux-2.6.21.7/net/ipv4/netfilter/ip_set_iptreemap.c
-===================================================================
---- /dev/null
-+++ linux-2.6.21.7/net/ipv4/netfilter/ip_set_iptreemap.c
-@@ -0,0 +1,829 @@
-+/* Copyright (C) 2007 Sven Wegener <sven.wegener@stealer.net>
-+ *
-+ * This program is free software; you can redistribute it and/or modify it
-+ * under the terms of the GNU General Public License version 2 as published by
-+ * the Free Software Foundation.
-+ */
-+
-+/* This modules implements the iptreemap ipset type. It uses bitmaps to
-+ * represent every single IPv4 address as a single bit. The bitmaps are managed
-+ * in a tree structure, where the first three octets of an addresses are used
-+ * as an index to find the bitmap and the last octet is used as the bit number.
-+ */
-+
-+#include <linux/version.h>
-+#include <linux/module.h>
-+#include <linux/ip.h>
-+#include <linux/skbuff.h>
-+#include <linux/slab.h>
-+#include <linux/delay.h>
-+#include <linux/netfilter_ipv4/ip_tables.h>
-+#include <linux/netfilter_ipv4/ip_set.h>
-+#include <linux/errno.h>
-+#include <asm/uaccess.h>
-+#include <asm/bitops.h>
-+#include <linux/spinlock.h>
-+
-+#include <linux/netfilter_ipv4/ip_set_iptreemap.h>
-+
-+#define IPTREEMAP_DEFAULT_GC_TIME (5 * 60)
-+#define IPTREEMAP_DESTROY_SLEEP (100)
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,21)
-+static struct kmem_cache *cachep_b;
-+static struct kmem_cache *cachep_c;
-+static struct kmem_cache *cachep_d;
-+#else
-+static kmem_cache_t *cachep_b;
-+static kmem_cache_t *cachep_c;
-+static kmem_cache_t *cachep_d;
-+#endif
-+
-+static struct ip_set_iptreemap_d *fullbitmap_d;
-+static struct ip_set_iptreemap_c *fullbitmap_c;
-+static struct ip_set_iptreemap_b *fullbitmap_b;
-+
-+#if defined(__LITTLE_ENDIAN)
-+#define ABCD(a, b, c, d, addr) \
-+ do { \
-+ a = ((unsigned char *)addr)[3]; \
-+ b = ((unsigned char *)addr)[2]; \
-+ c = ((unsigned char *)addr)[1]; \
-+ d = ((unsigned char *)addr)[0]; \
-+ } while (0)
-+#elif defined(__BIG_ENDIAN)
-+#define ABCD(a,b,c,d,addrp) do { \
-+ a = ((unsigned char *)addrp)[0]; \
-+ b = ((unsigned char *)addrp)[1]; \
-+ c = ((unsigned char *)addrp)[2]; \
-+ d = ((unsigned char *)addrp)[3]; \
-+} while (0)
-+#else
-+#error "Please fix asm/byteorder.h"
-+#endif /* __LITTLE_ENDIAN */
-+
-+#define TESTIP_WALK(map, elem, branch, full) \
-+ do { \
-+ branch = (map)->tree[elem]; \
-+ if (!branch) \
-+ return 0; \
-+ else if (branch == full) \
-+ return 1; \
-+ } while (0)
-+
-+#define ADDIP_WALK(map, elem, branch, type, cachep, full) \
-+ do { \
-+ branch = (map)->tree[elem]; \
-+ if (!branch) { \
-+ branch = (type *) kmem_cache_alloc(cachep, GFP_ATOMIC); \
-+ if (!branch) \
-+ return -ENOMEM; \
-+ memset(branch, 0, sizeof(*branch)); \
-+ (map)->tree[elem] = branch; \
-+ } else if (branch == full) { \
-+ return -EEXIST; \
-+ } \
-+ } while (0)
-+
-+#define ADDIP_RANGE_LOOP(map, a, a1, a2, hint, branch, full, cachep, free) \
-+ for (a = a1; a <= a2; a++) { \
-+ branch = (map)->tree[a]; \
-+ if (branch != full) { \
-+ if ((a > a1 && a < a2) || (hint)) { \
-+ if (branch) \
-+ free(branch); \
-+ (map)->tree[a] = full; \
-+ continue; \
-+ } else if (!branch) { \
-+ branch = kmem_cache_alloc(cachep, GFP_ATOMIC); \
-+ if (!branch) \
-+ return -ENOMEM; \
-+ memset(branch, 0, sizeof(*branch)); \
-+ (map)->tree[a] = branch; \
-+ }
-+
-+#define ADDIP_RANGE_LOOP_END() \
-+ } \
-+ }
-+
-+#define DELIP_WALK(map, elem, branch, cachep, full, flags) \
-+ do { \
-+ branch = (map)->tree[elem]; \
-+ if (!branch) { \
-+ return -EEXIST; \
-+ } else if (branch == full) { \
-+ branch = kmem_cache_alloc(cachep, flags); \
-+ if (!branch) \
-+ return -ENOMEM; \
-+ memcpy(branch, full, sizeof(*full)); \
-+ (map)->tree[elem] = branch; \
-+ } \
-+ } while (0)
-+
-+#define DELIP_RANGE_LOOP(map, a, a1, a2, hint, branch, full, cachep, free, flags) \
-+ for (a = a1; a <= a2; a++) { \
-+ branch = (map)->tree[a]; \
-+ if (branch) { \
-+ if ((a > a1 && a < a2) || (hint)) { \
-+ if (branch != full) \
-+ free(branch); \
-+ (map)->tree[a] = NULL; \
-+ continue; \
-+ } else if (branch == full) { \
-+ branch = kmem_cache_alloc(cachep, flags); \
-+ if (!branch) \
-+ return -ENOMEM; \
-+ memcpy(branch, full, sizeof(*branch)); \
-+ (map)->tree[a] = branch; \
-+ }
-+
-+#define DELIP_RANGE_LOOP_END() \
-+ } \
-+ }
-+
-+#define LOOP_WALK_BEGIN(map, i, branch) \
-+ for (i = 0; i < 256; i++) { \
-+ branch = (map)->tree[i]; \
-+ if (likely(!branch)) \
-+ continue;
-+
-+#define LOOP_WALK_END() \
-+ }
-+
-+#define LOOP_WALK_BEGIN_GC(map, i, branch, full, cachep, count) \
-+ count = -256; \
-+ for (i = 0; i < 256; i++) { \
-+ branch = (map)->tree[i]; \
-+ if (likely(!branch)) \
-+ continue; \
-+ count++; \
-+ if (branch == full) { \
-+ count++; \
-+ continue; \
-+ }
-+
-+#define LOOP_WALK_END_GC(map, i, branch, full, cachep, count) \
-+ if (-256 == count) { \
-+ kmem_cache_free(cachep, branch); \
-+ (map)->tree[i] = NULL; \
-+ } else if (256 == count) { \
-+ kmem_cache_free(cachep, branch); \
-+ (map)->tree[i] = full; \
-+ } \
-+ }
-+
-+#define LOOP_WALK_BEGIN_COUNT(map, i, branch, inrange, count) \
-+ for (i = 0; i < 256; i++) { \
-+ if (!(map)->tree[i]) { \
-+ if (inrange) { \
-+ count++; \
-+ inrange = 0; \
-+ } \
-+ continue; \
-+ } \
-+ branch = (map)->tree[i];
-+
-+#define LOOP_WALK_END_COUNT() \
-+ }
-+
-+#define MIN(a, b) (a < b ? a : b)
-+#define MAX(a, b) (a > b ? a : b)
-+
-+#define GETVALUE1(a, a1, b1, r) \
-+ (a == a1 ? b1 : r)
-+
-+#define GETVALUE2(a, b, a1, b1, c1, r) \
-+ (a == a1 && b == b1 ? c1 : r)
-+
-+#define GETVALUE3(a, b, c, a1, b1, c1, d1, r) \
-+ (a == a1 && b == b1 && c == c1 ? d1 : r)
-+
-+#define CHECK1(a, a1, a2, b1, b2, c1, c2, d1, d2) \
-+ ( \
-+ GETVALUE1(a, a1, b1, 0) == 0 \
-+ && GETVALUE1(a, a2, b2, 255) == 255 \
-+ && c1 == 0 \
-+ && c2 == 255 \
-+ && d1 == 0 \
-+ && d2 == 255 \
-+ )
-+
-+#define CHECK2(a, b, a1, a2, b1, b2, c1, c2, d1, d2) \
-+ ( \
-+ GETVALUE2(a, b, a1, b1, c1, 0) == 0 \
-+ && GETVALUE2(a, b, a2, b2, c2, 255) == 255 \
-+ && d1 == 0 \
-+ && d2 == 255 \
-+ )
-+
-+#define CHECK3(a, b, c, a1, a2, b1, b2, c1, c2, d1, d2) \
-+ ( \
-+ GETVALUE3(a, b, c, a1, b1, c1, d1, 0) == 0 \
-+ && GETVALUE3(a, b, c, a2, b2, c2, d2, 255) == 255 \
-+ )
-+
-+
-+static inline void
-+free_d(struct ip_set_iptreemap_d *map)
-+{
-+ kmem_cache_free(cachep_d, map);
-+}
-+
-+static inline void
-+free_c(struct ip_set_iptreemap_c *map)
-+{
-+ struct ip_set_iptreemap_d *dtree;
-+ unsigned int i;
-+
-+ LOOP_WALK_BEGIN(map, i, dtree) {
-+ if (dtree != fullbitmap_d)
-+ free_d(dtree);
-+ } LOOP_WALK_END();
-+
-+ kmem_cache_free(cachep_c, map);
-+}
-+
-+static inline void
-+free_b(struct ip_set_iptreemap_b *map)
-+{
-+ struct ip_set_iptreemap_c *ctree;
-+ unsigned int i;
-+
-+ LOOP_WALK_BEGIN(map, i, ctree) {
-+ if (ctree != fullbitmap_c)
-+ free_c(ctree);
-+ } LOOP_WALK_END();
-+
-+ kmem_cache_free(cachep_b, map);
-+}
-+
-+static inline int
-+__testip(struct ip_set *set, ip_set_ip_t ip, ip_set_ip_t *hash_ip)
-+{
-+ struct ip_set_iptreemap *map = (struct ip_set_iptreemap *) set->data;
-+ struct ip_set_iptreemap_b *btree;
-+ struct ip_set_iptreemap_c *ctree;
-+ struct ip_set_iptreemap_d *dtree;
-+ unsigned char a, b, c, d;
-+
-+ *hash_ip = ip;
-+
-+ ABCD(a, b, c, d, hash_ip);
-+
-+ TESTIP_WALK(map, a, btree, fullbitmap_b);
-+ TESTIP_WALK(btree, b, ctree, fullbitmap_c);
-+ TESTIP_WALK(ctree, c, dtree, fullbitmap_d);
-+
-+ return !!test_bit(d, (void *) dtree->bitmap);
-+}
-+
-+static int
-+testip(struct ip_set *set, const void *data, size_t size, ip_set_ip_t *hash_ip)
-+{
-+ struct ip_set_req_iptreemap *req = (struct ip_set_req_iptreemap *) data;
-+
-+ if (size != sizeof(struct ip_set_req_iptreemap)) {
-+ ip_set_printk("data length wrong (want %zu, have %zu)", sizeof(struct ip_set_req_iptreemap), size);
-+ return -EINVAL;
-+ }
-+
-+ return __testip(set, req->start, hash_ip);
-+}
-+
-+static int
-+testip_kernel(struct ip_set *set, const struct sk_buff *skb, ip_set_ip_t *hash_ip, const u_int32_t *flags, unsigned char index)
-+{
-+ int res;
-+
-+ res = __testip(set,
-+ ntohl(flags[index] & IPSET_SRC
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-+ ? ip_hdr(skb)->saddr
-+ : ip_hdr(skb)->daddr),
-+#else
-+ ? skb->nh.iph->saddr
-+ : skb->nh.iph->daddr),
-+#endif
-+ hash_ip);
-+
-+ return (res < 0 ? 0 : res);
-+}
-+
-+static inline int
-+__addip_single(struct ip_set *set, ip_set_ip_t ip, ip_set_ip_t *hash_ip)
-+{
-+ struct ip_set_iptreemap *map = (struct ip_set_iptreemap *) set->data;
-+ struct ip_set_iptreemap_b *btree;
-+ struct ip_set_iptreemap_c *ctree;
-+ struct ip_set_iptreemap_d *dtree;
-+ unsigned char a, b, c, d;
-+
-+ *hash_ip = ip;
-+
-+ ABCD(a, b, c, d, hash_ip);
-+
-+ ADDIP_WALK(map, a, btree, struct ip_set_iptreemap_b, cachep_b, fullbitmap_b);
-+ ADDIP_WALK(btree, b, ctree, struct ip_set_iptreemap_c, cachep_c, fullbitmap_c);
-+ ADDIP_WALK(ctree, c, dtree, struct ip_set_iptreemap_d, cachep_d, fullbitmap_d);
-+
-+ if (test_and_set_bit(d, (void *) dtree->bitmap))
-+ return -EEXIST;
-+
-+ set_bit(b, (void *) btree->dirty);
-+
-+ return 0;
-+}
-+
-+static inline int
-+__addip_range(struct ip_set *set, ip_set_ip_t start, ip_set_ip_t end, ip_set_ip_t *hash_ip)
-+{
-+ struct ip_set_iptreemap *map = (struct ip_set_iptreemap *) set->data;
-+ struct ip_set_iptreemap_b *btree;
-+ struct ip_set_iptreemap_c *ctree;
-+ struct ip_set_iptreemap_d *dtree;
-+ unsigned int a, b, c, d;
-+ unsigned char a1, b1, c1, d1;
-+ unsigned char a2, b2, c2, d2;
-+
-+ if (start == end)
-+ return __addip_single(set, start, hash_ip);
-+
-+ *hash_ip = start;
-+
-+ ABCD(a1, b1, c1, d1, &start);
-+ ABCD(a2, b2, c2, d2, &end);
-+
-+ /* This is sooo ugly... */
-+ ADDIP_RANGE_LOOP(map, a, a1, a2, CHECK1(a, a1, a2, b1, b2, c1, c2, d1, d2), btree, fullbitmap_b, cachep_b, free_b) {
-+ ADDIP_RANGE_LOOP(btree, b, GETVALUE1(a, a1, b1, 0), GETVALUE1(a, a2, b2, 255), CHECK2(a, b, a1, a2, b1, b2, c1, c2, d1, d2), ctree, fullbitmap_c, cachep_c, free_c) {
-+ ADDIP_RANGE_LOOP(ctree, c, GETVALUE2(a, b, a1, b1, c1, 0), GETVALUE2(a, b, a2, b2, c2, 255), CHECK3(a, b, c, a1, a2, b1, b2, c1, c2, d1, d2), dtree, fullbitmap_d, cachep_d, free_d) {
-+ for (d = GETVALUE3(a, b, c, a1, b1, c1, d1, 0); d <= GETVALUE3(a, b, c, a2, b2, c2, d2, 255); d++)
-+ set_bit(d, (void *) dtree->bitmap);
-+ set_bit(b, (void *) btree->dirty);
-+ } ADDIP_RANGE_LOOP_END();
-+ } ADDIP_RANGE_LOOP_END();
-+ } ADDIP_RANGE_LOOP_END();
-+
-+ return 0;
-+}
-+
-+static int
-+addip(struct ip_set *set, const void *data, size_t size, ip_set_ip_t *hash_ip)
-+{
-+ struct ip_set_req_iptreemap *req = (struct ip_set_req_iptreemap *) data;
-+
-+ if (size != sizeof(struct ip_set_req_iptreemap)) {
-+ ip_set_printk("data length wrong (want %zu, have %zu)", sizeof(struct ip_set_req_iptreemap), size);
-+ return -EINVAL;
-+ }
-+
-+ return __addip_range(set, MIN(req->start, req->end), MAX(req->start, req->end), hash_ip);
-+}
-+
-+static int
-+addip_kernel(struct ip_set *set, const struct sk_buff *skb, ip_set_ip_t *hash_ip, const u_int32_t *flags, unsigned char index)
-+{
-+
-+ return __addip_single(set,
-+ ntohl(flags[index] & IPSET_SRC
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-+ ? ip_hdr(skb)->saddr
-+ : ip_hdr(skb)->daddr),
-+#else
-+ ? skb->nh.iph->saddr
-+ : skb->nh.iph->daddr),
-+#endif
-+ hash_ip);
-+}
-+
-+static inline int
-+__delip_single(struct ip_set *set, ip_set_ip_t ip, ip_set_ip_t *hash_ip, unsigned int __nocast flags)
-+{
-+ struct ip_set_iptreemap *map = (struct ip_set_iptreemap *) set->data;
-+ struct ip_set_iptreemap_b *btree;
-+ struct ip_set_iptreemap_c *ctree;
-+ struct ip_set_iptreemap_d *dtree;
-+ unsigned char a,b,c,d;
-+
-+ *hash_ip = ip;
-+
-+ ABCD(a, b, c, d, hash_ip);
-+
-+ DELIP_WALK(map, a, btree, cachep_b, fullbitmap_b, flags);
-+ DELIP_WALK(btree, b, ctree, cachep_c, fullbitmap_c, flags);
-+ DELIP_WALK(ctree, c, dtree, cachep_d, fullbitmap_d, flags);
-+
-+ if (!test_and_clear_bit(d, (void *) dtree->bitmap))
-+ return -EEXIST;
-+
-+ set_bit(b, (void *) btree->dirty);
-+
-+ return 0;
-+}
-+
-+static inline int
-+__delip_range(struct ip_set *set, ip_set_ip_t start, ip_set_ip_t end, ip_set_ip_t *hash_ip, unsigned int __nocast flags)
-+{
-+ struct ip_set_iptreemap *map = (struct ip_set_iptreemap *) set->data;
-+ struct ip_set_iptreemap_b *btree;
-+ struct ip_set_iptreemap_c *ctree;
-+ struct ip_set_iptreemap_d *dtree;
-+ unsigned int a, b, c, d;
-+ unsigned char a1, b1, c1, d1;
-+ unsigned char a2, b2, c2, d2;
-+
-+ if (start == end)
-+ return __delip_single(set, start, hash_ip, flags);
-+
-+ *hash_ip = start;
-+
-+ ABCD(a1, b1, c1, d1, &start);
-+ ABCD(a2, b2, c2, d2, &end);
-+
-+ /* This is sooo ugly... */
-+ DELIP_RANGE_LOOP(map, a, a1, a2, CHECK1(a, a1, a2, b1, b2, c1, c2, d1, d2), btree, fullbitmap_b, cachep_b, free_b, flags) {
-+ DELIP_RANGE_LOOP(btree, b, GETVALUE1(a, a1, b1, 0), GETVALUE1(a, a2, b2, 255), CHECK2(a, b, a1, a2, b1, b2, c1, c2, d1, d2), ctree, fullbitmap_c, cachep_c, free_c, flags) {
-+ DELIP_RANGE_LOOP(ctree, c, GETVALUE2(a, b, a1, b1, c1, 0), GETVALUE2(a, b, a2, b2, c2, 255), CHECK3(a, b, c, a1, a2, b1, b2, c1, c2, d1, d2), dtree, fullbitmap_d, cachep_d, free_d, flags) {
-+ for (d = GETVALUE3(a, b, c, a1, b1, c1, d1, 0); d <= GETVALUE3(a, b, c, a2, b2, c2, d2, 255); d++)
-+ clear_bit(d, (void *) dtree->bitmap);
-+ set_bit(b, (void *) btree->dirty);
-+ } DELIP_RANGE_LOOP_END();
-+ } DELIP_RANGE_LOOP_END();
-+ } DELIP_RANGE_LOOP_END();
-+
-+ return 0;
-+}
-+
-+static int
-+delip(struct ip_set *set, const void *data, size_t size, ip_set_ip_t *hash_ip)
-+{
-+ struct ip_set_req_iptreemap *req = (struct ip_set_req_iptreemap *) data;
-+
-+ if (size != sizeof(struct ip_set_req_iptreemap)) {
-+ ip_set_printk("data length wrong (want %zu, have %zu)", sizeof(struct ip_set_req_iptreemap), size);
-+ return -EINVAL;
-+ }
-+
-+ return __delip_range(set, MIN(req->start, req->end), MAX(req->start, req->end), hash_ip, GFP_KERNEL);
-+}
-+
-+static int
-+delip_kernel(struct ip_set *set, const struct sk_buff *skb, ip_set_ip_t *hash_ip, const u_int32_t *flags, unsigned char index)
-+{
-+ return __delip_single(set,
-+ ntohl(flags[index] & IPSET_SRC
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-+ ? ip_hdr(skb)->saddr
-+ : ip_hdr(skb)->daddr),
-+#else
-+ ? skb->nh.iph->saddr
-+ : skb->nh.iph->daddr),
-+#endif
-+ hash_ip,
-+ GFP_ATOMIC);
-+}
-+
-+/* Check the status of the bitmap
-+ * -1 == all bits cleared
-+ * 1 == all bits set
-+ * 0 == anything else
-+ */
-+static inline int
-+bitmap_status(struct ip_set_iptreemap_d *dtree)
-+{
-+ unsigned char first = dtree->bitmap[0];
-+ int a;
-+
-+ for (a = 1; a < 32; a++)
-+ if (dtree->bitmap[a] != first)
-+ return 0;
-+
-+ return (first == 0 ? -1 : (first == 255 ? 1 : 0));
-+}
-+
-+static void
-+gc(unsigned long addr)
-+{
-+ struct ip_set *set = (struct ip_set *) addr;
-+ struct ip_set_iptreemap *map = (struct ip_set_iptreemap *) set->data;
-+ struct ip_set_iptreemap_b *btree;
-+ struct ip_set_iptreemap_c *ctree;
-+ struct ip_set_iptreemap_d *dtree;
-+ unsigned int a, b, c;
-+ int i, j, k;
-+
-+ write_lock_bh(&set->lock);
-+
-+ LOOP_WALK_BEGIN_GC(map, a, btree, fullbitmap_b, cachep_b, i) {
-+ LOOP_WALK_BEGIN_GC(btree, b, ctree, fullbitmap_c, cachep_c, j) {
-+ if (!test_and_clear_bit(b, (void *) btree->dirty))
-+ continue;
-+ LOOP_WALK_BEGIN_GC(ctree, c, dtree, fullbitmap_d, cachep_d, k) {
-+ switch (bitmap_status(dtree)) {
-+ case -1:
-+ kmem_cache_free(cachep_d, dtree);
-+ ctree->tree[c] = NULL;
-+ k--;
-+ break;
-+ case 1:
-+ kmem_cache_free(cachep_d, dtree);
-+ ctree->tree[c] = fullbitmap_d;
-+ k++;
-+ break;
-+ }
-+ } LOOP_WALK_END();
-+ } LOOP_WALK_END_GC(btree, b, ctree, fullbitmap_c, cachep_c, k);
-+ } LOOP_WALK_END_GC(map, a, btree, fullbitmap_b, cachep_b, j);
-+
-+ write_unlock_bh(&set->lock);
-+
-+ map->gc.expires = jiffies + map->gc_interval * HZ;
-+ add_timer(&map->gc);
-+}
-+
-+static inline void
-+init_gc_timer(struct ip_set *set)
-+{
-+ struct ip_set_iptreemap *map = (struct ip_set_iptreemap *) set->data;
-+
-+ init_timer(&map->gc);
-+ map->gc.data = (unsigned long) set;
-+ map->gc.function = gc;
-+ map->gc.expires = jiffies + map->gc_interval * HZ;
-+ add_timer(&map->gc);
-+}
-+
-+static int create(struct ip_set *set, const void *data, size_t size)
-+{
-+ struct ip_set_req_iptreemap_create *req = (struct ip_set_req_iptreemap_create *) data;
-+ struct ip_set_iptreemap *map;
-+
-+ if (size != sizeof(struct ip_set_req_iptreemap_create)) {
-+ ip_set_printk("data length wrong (want %zu, have %zu)", sizeof(struct ip_set_req_iptreemap_create), size);
-+ return -EINVAL;
-+ }
-+
-+ map = kzalloc(sizeof(*map), GFP_KERNEL);
-+ if (!map)
-+ return -ENOMEM;
-+
-+ map->gc_interval = req->gc_interval ? req->gc_interval : IPTREEMAP_DEFAULT_GC_TIME;
-+ set->data = map;
-+
-+ init_gc_timer(set);
-+
-+ return 0;
-+}
-+
-+static inline void __flush(struct ip_set_iptreemap *map)
-+{
-+ struct ip_set_iptreemap_b *btree;
-+ unsigned int a;
-+
-+ LOOP_WALK_BEGIN(map, a, btree);
-+ if (btree != fullbitmap_b)
-+ free_b(btree);
-+ LOOP_WALK_END();
-+}
-+
-+static void destroy(struct ip_set *set)
-+{
-+ struct ip_set_iptreemap *map = (struct ip_set_iptreemap *) set->data;
-+
-+ while (!del_timer(&map->gc))
-+ msleep(IPTREEMAP_DESTROY_SLEEP);
-+
-+ __flush(map);
-+ kfree(map);
-+
-+ set->data = NULL;
-+}
-+
-+static void flush(struct ip_set *set)
-+{
-+ struct ip_set_iptreemap *map = (struct ip_set_iptreemap *) set->data;
-+
-+ while (!del_timer(&map->gc))
-+ msleep(IPTREEMAP_DESTROY_SLEEP);
-+
-+ __flush(map);
-+
-+ memset(map, 0, sizeof(*map));
-+
-+ init_gc_timer(set);
-+}
-+
-+static void list_header(const struct ip_set *set, void *data)
-+{
-+ struct ip_set_iptreemap *map = (struct ip_set_iptreemap *) set->data;
-+ struct ip_set_req_iptreemap_create *header = (struct ip_set_req_iptreemap_create *) data;
-+
-+ header->gc_interval = map->gc_interval;
-+}
-+
-+static int list_members_size(const struct ip_set *set)
-+{
-+ struct ip_set_iptreemap *map = (struct ip_set_iptreemap *) set->data;
-+ struct ip_set_iptreemap_b *btree;
-+ struct ip_set_iptreemap_c *ctree;
-+ struct ip_set_iptreemap_d *dtree;
-+ unsigned int a, b, c, d, inrange = 0, count = 0;
-+
-+ LOOP_WALK_BEGIN_COUNT(map, a, btree, inrange, count) {
-+ LOOP_WALK_BEGIN_COUNT(btree, b, ctree, inrange, count) {
-+ LOOP_WALK_BEGIN_COUNT(ctree, c, dtree, inrange, count) {
-+ for (d = 0; d < 256; d++) {
-+ if (test_bit(d, (void *) dtree->bitmap)) {
-+ inrange = 1;
-+ } else if (inrange) {
-+ count++;
-+ inrange = 0;
-+ }
-+ }
-+ } LOOP_WALK_END_COUNT();
-+ } LOOP_WALK_END_COUNT();
-+ } LOOP_WALK_END_COUNT();
-+
-+ if (inrange)
-+ count++;
-+
-+ return (count * sizeof(struct ip_set_req_iptreemap));
-+}
-+
-+static inline size_t add_member(void *data, size_t offset, ip_set_ip_t start, ip_set_ip_t end)
-+{
-+ struct ip_set_req_iptreemap *entry = (struct ip_set_req_iptreemap *) (data + offset);
-+
-+ entry->start = start;
-+ entry->end = end;
-+
-+ return sizeof(*entry);
-+}
-+
-+static void list_members(const struct ip_set *set, void *data)
-+{
-+ struct ip_set_iptreemap *map = (struct ip_set_iptreemap *) set->data;
-+ struct ip_set_iptreemap_b *btree;
-+ struct ip_set_iptreemap_c *ctree;
-+ struct ip_set_iptreemap_d *dtree;
-+ unsigned int a, b, c, d, inrange = 0;
-+ size_t offset = 0;
-+ ip_set_ip_t start = 0, end = 0, ip;
-+
-+ LOOP_WALK_BEGIN(map, a, btree) {
-+ LOOP_WALK_BEGIN(btree, b, ctree) {
-+ LOOP_WALK_BEGIN(ctree, c, dtree) {
-+ for (d = 0; d < 256; d++) {
-+ if (test_bit(d, (void *) dtree->bitmap)) {
-+ ip = ((a << 24) | (b << 16) | (c << 8) | d);
-+ if (!inrange) {
-+ inrange = 1;
-+ start = ip;
-+ } else if (end < ip - 1) {
-+ offset += add_member(data, offset, start, end);
-+ start = ip;
-+ }
-+ end = ip;
-+ } else if (inrange) {
-+ offset += add_member(data, offset, start, end);
-+ inrange = 0;
-+ }
-+ }
-+ } LOOP_WALK_END();
-+ } LOOP_WALK_END();
-+ } LOOP_WALK_END();
-+
-+ if (inrange)
-+ add_member(data, offset, start, end);
-+}
-+
-+static struct ip_set_type ip_set_iptreemap = {
-+ .typename = SETTYPE_NAME,
-+ .features = IPSET_TYPE_IP | IPSET_DATA_SINGLE,
-+ .protocol_version = IP_SET_PROTOCOL_VERSION,
-+ .create = create,
-+ .destroy = destroy,
-+ .flush = flush,
-+ .reqsize = sizeof(struct ip_set_req_iptreemap),
-+ .addip = addip,
-+ .addip_kernel = addip_kernel,
-+ .delip = delip,
-+ .delip_kernel = delip_kernel,
-+ .testip = testip,
-+ .testip_kernel = testip_kernel,
-+ .header_size = sizeof(struct ip_set_req_iptreemap_create),
-+ .list_header = list_header,
-+ .list_members_size = list_members_size,
-+ .list_members = list_members,
-+ .me = THIS_MODULE,
-+};
-+
-+MODULE_LICENSE("GPL");
-+MODULE_AUTHOR("Sven Wegener <sven.wegener@stealer.net>");
-+MODULE_DESCRIPTION("iptreemap type of IP sets");
-+
-+static int __init ip_set_iptreemap_init(void)
-+{
-+ int ret = -ENOMEM;
-+ int a;
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,23)
-+ cachep_b = kmem_cache_create("ip_set_iptreemap_b",
-+ sizeof(struct ip_set_iptreemap_b),
-+ 0, 0, NULL);
-+#else
-+ cachep_b = kmem_cache_create("ip_set_iptreemap_b",
-+ sizeof(struct ip_set_iptreemap_b),
-+ 0, 0, NULL, NULL);
-+#endif
-+ if (!cachep_b) {
-+ ip_set_printk("Unable to create ip_set_iptreemap_b slab cache");
-+ goto out;
-+ }
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,23)
-+ cachep_c = kmem_cache_create("ip_set_iptreemap_c",
-+ sizeof(struct ip_set_iptreemap_c),
-+ 0, 0, NULL);
-+#else
-+ cachep_c = kmem_cache_create("ip_set_iptreemap_c",
-+ sizeof(struct ip_set_iptreemap_c),
-+ 0, 0, NULL, NULL);
-+#endif
-+ if (!cachep_c) {
-+ ip_set_printk("Unable to create ip_set_iptreemap_c slab cache");
-+ goto outb;
-+ }
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,23)
-+ cachep_d = kmem_cache_create("ip_set_iptreemap_d",
-+ sizeof(struct ip_set_iptreemap_d),
-+ 0, 0, NULL);
-+#else
-+ cachep_d = kmem_cache_create("ip_set_iptreemap_d",
-+ sizeof(struct ip_set_iptreemap_d),
-+ 0, 0, NULL, NULL);
-+#endif
-+ if (!cachep_d) {
-+ ip_set_printk("Unable to create ip_set_iptreemap_d slab cache");
-+ goto outc;
-+ }
-+
-+ fullbitmap_d = kmem_cache_alloc(cachep_d, GFP_KERNEL);
-+ if (!fullbitmap_d)
-+ goto outd;
-+
-+ fullbitmap_c = kmem_cache_alloc(cachep_c, GFP_KERNEL);
-+ if (!fullbitmap_c)
-+ goto outbitmapd;
-+
-+ fullbitmap_b = kmem_cache_alloc(cachep_b, GFP_KERNEL);
-+ if (!fullbitmap_b)
-+ goto outbitmapc;
-+
-+ ret = ip_set_register_set_type(&ip_set_iptreemap);
-+ if (0 > ret)
-+ goto outbitmapb;
-+
-+ /* Now init our global bitmaps */
-+ memset(fullbitmap_d->bitmap, 0xff, sizeof(fullbitmap_d->bitmap));
-+
-+ for (a = 0; a < 256; a++)
-+ fullbitmap_c->tree[a] = fullbitmap_d;
-+
-+ for (a = 0; a < 256; a++)
-+ fullbitmap_b->tree[a] = fullbitmap_c;
-+ memset(fullbitmap_b->dirty, 0, sizeof(fullbitmap_b->dirty));
-+
-+ return 0;
-+
-+outbitmapb:
-+ kmem_cache_free(cachep_b, fullbitmap_b);
-+outbitmapc:
-+ kmem_cache_free(cachep_c, fullbitmap_c);
-+outbitmapd:
-+ kmem_cache_free(cachep_d, fullbitmap_d);
-+outd:
-+ kmem_cache_destroy(cachep_d);
-+outc:
-+ kmem_cache_destroy(cachep_c);
-+outb:
-+ kmem_cache_destroy(cachep_b);
-+out:
-+
-+ return ret;
-+}
-+
-+static void __exit ip_set_iptreemap_fini(void)
-+{
-+ ip_set_unregister_set_type(&ip_set_iptreemap);
-+ kmem_cache_free(cachep_d, fullbitmap_d);
-+ kmem_cache_free(cachep_c, fullbitmap_c);
-+ kmem_cache_free(cachep_b, fullbitmap_b);
-+ kmem_cache_destroy(cachep_d);
-+ kmem_cache_destroy(cachep_c);
-+ kmem_cache_destroy(cachep_b);
-+}
-+
-+module_init(ip_set_iptreemap_init);
-+module_exit(ip_set_iptreemap_fini);
-Index: linux-2.6.21.7/net/ipv4/netfilter/ip_set_macipmap.c
-===================================================================
---- /dev/null
-+++ linux-2.6.21.7/net/ipv4/netfilter/ip_set_macipmap.c
-@@ -0,0 +1,375 @@
-+/* Copyright (C) 2000-2002 Joakim Axelsson <gozem@linux.nu>
-+ * Patrick Schaaf <bof@bof.de>
-+ * Martin Josefsson <gandalf@wlug.westbo.se>
-+ * Copyright (C) 2003-2004 Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
-+ *
-+ * This program is free software; you can redistribute it and/or modify
-+ * it under the terms of the GNU General Public License version 2 as
-+ * published by the Free Software Foundation.
-+ */
-+
-+/* Kernel module implementing an IP set type: the macipmap type */
-+
-+#include <linux/module.h>
-+#include <linux/ip.h>
-+#include <linux/skbuff.h>
-+#include <linux/version.h>
-+#include <linux/netfilter_ipv4/ip_tables.h>
-+#include <linux/netfilter_ipv4/ip_set.h>
-+#include <linux/errno.h>
-+#include <asm/uaccess.h>
-+#include <asm/bitops.h>
-+#include <linux/spinlock.h>
-+#include <linux/if_ether.h>
-+#include <linux/vmalloc.h>
-+
-+#include <linux/netfilter_ipv4/ip_set_malloc.h>
-+#include <linux/netfilter_ipv4/ip_set_macipmap.h>
-+
-+static int
-+testip(struct ip_set *set, const void *data, size_t size, ip_set_ip_t *hash_ip)
-+{
-+ struct ip_set_macipmap *map = (struct ip_set_macipmap *) set->data;
-+ struct ip_set_macip *table = (struct ip_set_macip *) map->members;
-+ struct ip_set_req_macipmap *req = (struct ip_set_req_macipmap *) data;
-+
-+ if (size != sizeof(struct ip_set_req_macipmap)) {
-+ ip_set_printk("data length wrong (want %zu, have %zu)",
-+ sizeof(struct ip_set_req_macipmap),
-+ size);
-+ return -EINVAL;
-+ }
-+
-+ if (req->ip < map->first_ip || req->ip > map->last_ip)
-+ return -ERANGE;
-+
-+ *hash_ip = req->ip;
-+ DP("set: %s, ip:%u.%u.%u.%u, %u.%u.%u.%u",
-+ set->name, HIPQUAD(req->ip), HIPQUAD(*hash_ip));
-+ if (test_bit(IPSET_MACIP_ISSET,
-+ (void *) &table[req->ip - map->first_ip].flags)) {
-+ return (memcmp(req->ethernet,
-+ &table[req->ip - map->first_ip].ethernet,
-+ ETH_ALEN) == 0);
-+ } else {
-+ return (map->flags & IPSET_MACIP_MATCHUNSET ? 1 : 0);
-+ }
-+}
-+
-+static int
-+testip_kernel(struct ip_set *set,
-+ const struct sk_buff *skb,
-+ ip_set_ip_t *hash_ip,
-+ const u_int32_t *flags,
-+ unsigned char index)
-+{
-+ struct ip_set_macipmap *map =
-+ (struct ip_set_macipmap *) set->data;
-+ struct ip_set_macip *table =
-+ (struct ip_set_macip *) map->members;
-+ ip_set_ip_t ip;
-+
-+ ip = ntohl(flags[index] & IPSET_SRC
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-+ ? ip_hdr(skb)->saddr
-+ : ip_hdr(skb)->daddr);
-+#else
-+ ? skb->nh.iph->saddr
-+ : skb->nh.iph->daddr);
-+#endif
-+
-+ if (ip < map->first_ip || ip > map->last_ip)
-+ return 0;
-+
-+ *hash_ip = ip;
-+ DP("set: %s, ip:%u.%u.%u.%u, %u.%u.%u.%u",
-+ set->name, HIPQUAD(ip), HIPQUAD(*hash_ip));
-+ if (test_bit(IPSET_MACIP_ISSET,
-+ (void *) &table[ip - map->first_ip].flags)) {
-+ /* Is mac pointer valid?
-+ * If so, compare... */
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-+ return (skb_mac_header(skb) >= skb->head
-+ && (skb_mac_header(skb) + ETH_HLEN) <= skb->data
-+#else
-+ return (skb->mac.raw >= skb->head
-+ && (skb->mac.raw + ETH_HLEN) <= skb->data
-+#endif
-+ && (memcmp(eth_hdr(skb)->h_source,
-+ &table[ip - map->first_ip].ethernet,
-+ ETH_ALEN) == 0));
-+ } else {
-+ return (map->flags & IPSET_MACIP_MATCHUNSET ? 1 : 0);
-+ }
-+}
-+
-+/* returns 0 on success */
-+static inline int
-+__addip(struct ip_set *set,
-+ ip_set_ip_t ip, unsigned char *ethernet, ip_set_ip_t *hash_ip)
-+{
-+ struct ip_set_macipmap *map =
-+ (struct ip_set_macipmap *) set->data;
-+ struct ip_set_macip *table =
-+ (struct ip_set_macip *) map->members;
-+
-+ if (ip < map->first_ip || ip > map->last_ip)
-+ return -ERANGE;
-+ if (test_and_set_bit(IPSET_MACIP_ISSET,
-+ (void *) &table[ip - map->first_ip].flags))
-+ return -EEXIST;
-+
-+ *hash_ip = ip;
-+ DP("%u.%u.%u.%u, %u.%u.%u.%u", HIPQUAD(ip), HIPQUAD(*hash_ip));
-+ memcpy(&table[ip - map->first_ip].ethernet, ethernet, ETH_ALEN);
-+ return 0;
-+}
-+
-+static int
-+addip(struct ip_set *set, const void *data, size_t size,
-+ ip_set_ip_t *hash_ip)
-+{
-+ struct ip_set_req_macipmap *req =
-+ (struct ip_set_req_macipmap *) data;
-+
-+ if (size != sizeof(struct ip_set_req_macipmap)) {
-+ ip_set_printk("data length wrong (want %zu, have %zu)",
-+ sizeof(struct ip_set_req_macipmap),
-+ size);
-+ return -EINVAL;
-+ }
-+ return __addip(set, req->ip, req->ethernet, hash_ip);
-+}
-+
-+static int
-+addip_kernel(struct ip_set *set,
-+ const struct sk_buff *skb,
-+ ip_set_ip_t *hash_ip,
-+ const u_int32_t *flags,
-+ unsigned char index)
-+{
-+ ip_set_ip_t ip;
-+
-+ ip = ntohl(flags[index] & IPSET_SRC
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-+ ? ip_hdr(skb)->saddr
-+ : ip_hdr(skb)->daddr);
-+#else
-+ ? skb->nh.iph->saddr
-+ : skb->nh.iph->daddr);
-+#endif
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-+ if (!(skb_mac_header(skb) >= skb->head
-+ && (skb_mac_header(skb) + ETH_HLEN) <= skb->data))
-+#else
-+ if (!(skb->mac.raw >= skb->head
-+ && (skb->mac.raw + ETH_HLEN) <= skb->data))
-+#endif
-+ return -EINVAL;
-+
-+ return __addip(set, ip, eth_hdr(skb)->h_source, hash_ip);
-+}
-+
-+static inline int
-+__delip(struct ip_set *set, ip_set_ip_t ip, ip_set_ip_t *hash_ip)
-+{
-+ struct ip_set_macipmap *map =
-+ (struct ip_set_macipmap *) set->data;
-+ struct ip_set_macip *table =
-+ (struct ip_set_macip *) map->members;
-+
-+ if (ip < map->first_ip || ip > map->last_ip)
-+ return -ERANGE;
-+ if (!test_and_clear_bit(IPSET_MACIP_ISSET,
-+ (void *)&table[ip - map->first_ip].flags))
-+ return -EEXIST;
-+
-+ *hash_ip = ip;
-+ DP("%u.%u.%u.%u, %u.%u.%u.%u", HIPQUAD(ip), HIPQUAD(*hash_ip));
-+ return 0;
-+}
-+
-+static int
-+delip(struct ip_set *set, const void *data, size_t size,
-+ ip_set_ip_t *hash_ip)
-+{
-+ struct ip_set_req_macipmap *req =
-+ (struct ip_set_req_macipmap *) data;
-+
-+ if (size != sizeof(struct ip_set_req_macipmap)) {
-+ ip_set_printk("data length wrong (want %zu, have %zu)",
-+ sizeof(struct ip_set_req_macipmap),
-+ size);
-+ return -EINVAL;
-+ }
-+ return __delip(set, req->ip, hash_ip);
-+}
-+
-+static int
-+delip_kernel(struct ip_set *set,
-+ const struct sk_buff *skb,
-+ ip_set_ip_t *hash_ip,
-+ const u_int32_t *flags,
-+ unsigned char index)
-+{
-+ return __delip(set,
-+ ntohl(flags[index] & IPSET_SRC
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-+ ? ip_hdr(skb)->saddr
-+ : ip_hdr(skb)->daddr),
-+#else
-+ ? skb->nh.iph->saddr
-+ : skb->nh.iph->daddr),
-+#endif
-+ hash_ip);
-+}
-+
-+static inline size_t members_size(ip_set_id_t from, ip_set_id_t to)
-+{
-+ return (size_t)((to - from + 1) * sizeof(struct ip_set_macip));
-+}
-+
-+static int create(struct ip_set *set, const void *data, size_t size)
-+{
-+ int newbytes;
-+ struct ip_set_req_macipmap_create *req =
-+ (struct ip_set_req_macipmap_create *) data;
-+ struct ip_set_macipmap *map;
-+
-+ if (size != sizeof(struct ip_set_req_macipmap_create)) {
-+ ip_set_printk("data length wrong (want %zu, have %zu)",
-+ sizeof(struct ip_set_req_macipmap_create),
-+ size);
-+ return -EINVAL;
-+ }
-+
-+ DP("from %u.%u.%u.%u to %u.%u.%u.%u",
-+ HIPQUAD(req->from), HIPQUAD(req->to));
-+
-+ if (req->from > req->to) {
-+ DP("bad ip range");
-+ return -ENOEXEC;
-+ }
-+
-+ if (req->to - req->from > MAX_RANGE) {
-+ ip_set_printk("range too big (max %d addresses)",
-+ MAX_RANGE+1);
-+ return -ENOEXEC;
-+ }
-+
-+ map = kmalloc(sizeof(struct ip_set_macipmap), GFP_KERNEL);
-+ if (!map) {
-+ DP("out of memory for %d bytes",
-+ sizeof(struct ip_set_macipmap));
-+ return -ENOMEM;
-+ }
-+ map->flags = req->flags;
-+ map->first_ip = req->from;
-+ map->last_ip = req->to;
-+ newbytes = members_size(map->first_ip, map->last_ip);
-+ map->members = ip_set_malloc(newbytes);
-+ DP("members: %u %p", newbytes, map->members);
-+ if (!map->members) {
-+ DP("out of memory for %d bytes", newbytes);
-+ kfree(map);
-+ return -ENOMEM;
-+ }
-+ memset(map->members, 0, newbytes);
-+
-+ set->data = map;
-+ return 0;
-+}
-+
-+static void destroy(struct ip_set *set)
-+{
-+ struct ip_set_macipmap *map =
-+ (struct ip_set_macipmap *) set->data;
-+
-+ ip_set_free(map->members, members_size(map->first_ip, map->last_ip));
-+ kfree(map);
-+
-+ set->data = NULL;
-+}
-+
-+static void flush(struct ip_set *set)
-+{
-+ struct ip_set_macipmap *map =
-+ (struct ip_set_macipmap *) set->data;
-+ memset(map->members, 0, members_size(map->first_ip, map->last_ip));
-+}
-+
-+static void list_header(const struct ip_set *set, void *data)
-+{
-+ struct ip_set_macipmap *map =
-+ (struct ip_set_macipmap *) set->data;
-+ struct ip_set_req_macipmap_create *header =
-+ (struct ip_set_req_macipmap_create *) data;
-+
-+ DP("list_header %x %x %u", map->first_ip, map->last_ip,
-+ map->flags);
-+
-+ header->from = map->first_ip;
-+ header->to = map->last_ip;
-+ header->flags = map->flags;
-+}
-+
-+static int list_members_size(const struct ip_set *set)
-+{
-+ struct ip_set_macipmap *map =
-+ (struct ip_set_macipmap *) set->data;
-+
-+ DP("%u", members_size(map->first_ip, map->last_ip));
-+ return members_size(map->first_ip, map->last_ip);
-+}
-+
-+static void list_members(const struct ip_set *set, void *data)
-+{
-+ struct ip_set_macipmap *map =
-+ (struct ip_set_macipmap *) set->data;
-+
-+ int bytes = members_size(map->first_ip, map->last_ip);
-+
-+ DP("members: %u %p", bytes, map->members);
-+ memcpy(data, map->members, bytes);
-+}
-+
-+static struct ip_set_type ip_set_macipmap = {
-+ .typename = SETTYPE_NAME,
-+ .features = IPSET_TYPE_IP | IPSET_DATA_SINGLE,
-+ .protocol_version = IP_SET_PROTOCOL_VERSION,
-+ .create = &create,
-+ .destroy = &destroy,
-+ .flush = &flush,
-+ .reqsize = sizeof(struct ip_set_req_macipmap),
-+ .addip = &addip,
-+ .addip_kernel = &addip_kernel,
-+ .delip = &delip,
-+ .delip_kernel = &delip_kernel,
-+ .testip = &testip,
-+ .testip_kernel = &testip_kernel,
-+ .header_size = sizeof(struct ip_set_req_macipmap_create),
-+ .list_header = &list_header,
-+ .list_members_size = &list_members_size,
-+ .list_members = &list_members,
-+ .me = THIS_MODULE,
-+};
-+
-+MODULE_LICENSE("GPL");
-+MODULE_AUTHOR("Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>");
-+MODULE_DESCRIPTION("macipmap type of IP sets");
-+
-+static int __init ip_set_macipmap_init(void)
-+{
-+ init_max_malloc_size();
-+ return ip_set_register_set_type(&ip_set_macipmap);
-+}
-+
-+static void __exit ip_set_macipmap_fini(void)
-+{
-+ /* FIXME: possible race with ip_set_create() */
-+ ip_set_unregister_set_type(&ip_set_macipmap);
-+}
-+
-+module_init(ip_set_macipmap_init);
-+module_exit(ip_set_macipmap_fini);
-Index: linux-2.6.21.7/net/ipv4/netfilter/ip_set_nethash.c
-===================================================================
---- /dev/null
-+++ linux-2.6.21.7/net/ipv4/netfilter/ip_set_nethash.c
-@@ -0,0 +1,497 @@
-+/* Copyright (C) 2003-2004 Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
-+ *
-+ * This program is free software; you can redistribute it and/or modify
-+ * it under the terms of the GNU General Public License version 2 as
-+ * published by the Free Software Foundation.
-+ */
-+
-+/* Kernel module implementing a cidr nethash set */
-+
-+#include <linux/module.h>
-+#include <linux/ip.h>
-+#include <linux/skbuff.h>
-+#include <linux/version.h>
-+#include <linux/jhash.h>
-+#include <linux/netfilter_ipv4/ip_tables.h>
-+#include <linux/netfilter_ipv4/ip_set.h>
-+#include <linux/errno.h>
-+#include <asm/uaccess.h>
-+#include <asm/bitops.h>
-+#include <linux/spinlock.h>
-+#include <linux/vmalloc.h>
-+#include <linux/random.h>
-+
-+#include <net/ip.h>
-+
-+#include <linux/netfilter_ipv4/ip_set_malloc.h>
-+#include <linux/netfilter_ipv4/ip_set_nethash.h>
-+
-+static int limit = MAX_RANGE;
-+
-+static inline __u32
-+jhash_ip(const struct ip_set_nethash *map, uint16_t i, ip_set_ip_t ip)
-+{
-+ return jhash_1word(ip, *(((uint32_t *) map->initval) + i));
-+}
-+
-+static inline __u32
-+hash_id_cidr(struct ip_set_nethash *map,
-+ ip_set_ip_t ip,
-+ unsigned char cidr,
-+ ip_set_ip_t *hash_ip)
-+{
-+ __u32 id;
-+ u_int16_t i;
-+ ip_set_ip_t *elem;
-+
-+ *hash_ip = pack(ip, cidr);
-+
-+ for (i = 0; i < map->probes; i++) {
-+ id = jhash_ip(map, i, *hash_ip) % map->hashsize;
-+ DP("hash key: %u", id);
-+ elem = HARRAY_ELEM(map->members, ip_set_ip_t *, id);
-+ if (*elem == *hash_ip)
-+ return id;
-+ }
-+ return UINT_MAX;
-+}
-+
-+static inline __u32
-+hash_id(struct ip_set *set, ip_set_ip_t ip, ip_set_ip_t *hash_ip)
-+{
-+ struct ip_set_nethash *map = (struct ip_set_nethash *) set->data;
-+ __u32 id = UINT_MAX;
-+ int i;
-+
-+ for (i = 0; i < 30 && map->cidr[i]; i++) {
-+ id = hash_id_cidr(map, ip, map->cidr[i], hash_ip);
-+ if (id != UINT_MAX)
-+ break;
-+ }
-+ return id;
-+}
-+
-+static inline int
-+__testip_cidr(struct ip_set *set, ip_set_ip_t ip, unsigned char cidr,
-+ ip_set_ip_t *hash_ip)
-+{
-+ struct ip_set_nethash *map = (struct ip_set_nethash *) set->data;
-+
-+ return (ip && hash_id_cidr(map, ip, cidr, hash_ip) != UINT_MAX);
-+}
-+
-+static inline int
-+__testip(struct ip_set *set, ip_set_ip_t ip, ip_set_ip_t *hash_ip)
-+{
-+ return (ip && hash_id(set, ip, hash_ip) != UINT_MAX);
-+}
-+
-+static int
-+testip(struct ip_set *set, const void *data, size_t size,
-+ ip_set_ip_t *hash_ip)
-+{
-+ struct ip_set_req_nethash *req =
-+ (struct ip_set_req_nethash *) data;
-+
-+ if (size != sizeof(struct ip_set_req_nethash)) {
-+ ip_set_printk("data length wrong (want %zu, have %zu)",
-+ sizeof(struct ip_set_req_nethash),
-+ size);
-+ return -EINVAL;
-+ }
-+ return (req->cidr == 32 ? __testip(set, req->ip, hash_ip)
-+ : __testip_cidr(set, req->ip, req->cidr, hash_ip));
-+}
-+
-+static int
-+testip_kernel(struct ip_set *set,
-+ const struct sk_buff *skb,
-+ ip_set_ip_t *hash_ip,
-+ const u_int32_t *flags,
-+ unsigned char index)
-+{
-+ return __testip(set,
-+ ntohl(flags[index] & IPSET_SRC
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-+ ? ip_hdr(skb)->saddr
-+ : ip_hdr(skb)->daddr),
-+#else
-+ ? skb->nh.iph->saddr
-+ : skb->nh.iph->daddr),
-+#endif
-+ hash_ip);
-+}
-+
-+static inline int
-+__addip_base(struct ip_set_nethash *map, ip_set_ip_t ip)
-+{
-+ __u32 probe;
-+ u_int16_t i;
-+ ip_set_ip_t *elem;
-+
-+ for (i = 0; i < map->probes; i++) {
-+ probe = jhash_ip(map, i, ip) % map->hashsize;
-+ elem = HARRAY_ELEM(map->members, ip_set_ip_t *, probe);
-+ if (*elem == ip)
-+ return -EEXIST;
-+ if (!*elem) {
-+ *elem = ip;
-+ map->elements++;
-+ return 0;
-+ }
-+ }
-+ /* Trigger rehashing */
-+ return -EAGAIN;
-+}
-+
-+static inline int
-+__addip(struct ip_set_nethash *map, ip_set_ip_t ip, unsigned char cidr,
-+ ip_set_ip_t *hash_ip)
-+{
-+ if (!ip || map->elements >= limit)
-+ return -ERANGE;
-+
-+ *hash_ip = pack(ip, cidr);
-+ DP("%u.%u.%u.%u/%u, %u.%u.%u.%u", HIPQUAD(ip), cidr, HIPQUAD(*hash_ip));
-+
-+ return __addip_base(map, *hash_ip);
-+}
-+
-+static void
-+update_cidr_sizes(struct ip_set_nethash *map, unsigned char cidr)
-+{
-+ unsigned char next;
-+ int i;
-+
-+ for (i = 0; i < 30 && map->cidr[i]; i++) {
-+ if (map->cidr[i] == cidr) {
-+ return;
-+ } else if (map->cidr[i] < cidr) {
-+ next = map->cidr[i];
-+ map->cidr[i] = cidr;
-+ cidr = next;
-+ }
-+ }
-+ if (i < 30)
-+ map->cidr[i] = cidr;
-+}
-+
-+static int
-+addip(struct ip_set *set, const void *data, size_t size,
-+ ip_set_ip_t *hash_ip)
-+{
-+ struct ip_set_req_nethash *req =
-+ (struct ip_set_req_nethash *) data;
-+ int ret;
-+
-+ if (size != sizeof(struct ip_set_req_nethash)) {
-+ ip_set_printk("data length wrong (want %zu, have %zu)",
-+ sizeof(struct ip_set_req_nethash),
-+ size);
-+ return -EINVAL;
-+ }
-+ ret = __addip((struct ip_set_nethash *) set->data,
-+ req->ip, req->cidr, hash_ip);
-+
-+ if (ret == 0)
-+ update_cidr_sizes((struct ip_set_nethash *) set->data,
-+ req->cidr);
-+
-+ return ret;
-+}
-+
-+static int
-+addip_kernel(struct ip_set *set,
-+ const struct sk_buff *skb,
-+ ip_set_ip_t *hash_ip,
-+ const u_int32_t *flags,
-+ unsigned char index)
-+{
-+ struct ip_set_nethash *map = (struct ip_set_nethash *) set->data;
-+ int ret = -ERANGE;
-+ ip_set_ip_t ip = ntohl(flags[index] & IPSET_SRC
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-+ ? ip_hdr(skb)->saddr
-+ : ip_hdr(skb)->daddr);
-+#else
-+ ? skb->nh.iph->saddr
-+ : skb->nh.iph->daddr);
-+#endif
-+
-+ if (map->cidr[0])
-+ ret = __addip(map, ip, map->cidr[0], hash_ip);
-+
-+ return ret;
-+}
-+
-+static int retry(struct ip_set *set)
-+{
-+ struct ip_set_nethash *map = (struct ip_set_nethash *) set->data;
-+ ip_set_ip_t *elem;
-+ void *members;
-+ u_int32_t i, hashsize = map->hashsize;
-+ int res;
-+ struct ip_set_nethash *tmp;
-+
-+ if (map->resize == 0)
-+ return -ERANGE;
-+
-+ again:
-+ res = 0;
-+
-+ /* Calculate new parameters */
-+ hashsize += (hashsize * map->resize)/100;
-+ if (hashsize == map->hashsize)
-+ hashsize++;
-+
-+ ip_set_printk("rehashing of set %s triggered: "
-+ "hashsize grows from %u to %u",
-+ set->name, map->hashsize, hashsize);
-+
-+ tmp = kmalloc(sizeof(struct ip_set_nethash)
-+ + map->probes * sizeof(uint32_t), GFP_ATOMIC);
-+ if (!tmp) {
-+ DP("out of memory for %d bytes",
-+ sizeof(struct ip_set_nethash)
-+ + map->probes * sizeof(uint32_t));
-+ return -ENOMEM;
-+ }
-+ tmp->members = harray_malloc(hashsize, sizeof(ip_set_ip_t), GFP_ATOMIC);
-+ if (!tmp->members) {
-+ DP("out of memory for %d bytes", hashsize * sizeof(ip_set_ip_t));
-+ kfree(tmp);
-+ return -ENOMEM;
-+ }
-+ tmp->hashsize = hashsize;
-+ tmp->elements = 0;
-+ tmp->probes = map->probes;
-+ tmp->resize = map->resize;
-+ memcpy(tmp->initval, map->initval, map->probes * sizeof(uint32_t));
-+ memcpy(tmp->cidr, map->cidr, 30 * sizeof(unsigned char));
-+
-+ write_lock_bh(&set->lock);
-+ map = (struct ip_set_nethash *) set->data; /* Play safe */
-+ for (i = 0; i < map->hashsize && res == 0; i++) {
-+ elem = HARRAY_ELEM(map->members, ip_set_ip_t *, i);
-+ if (*elem)
-+ res = __addip_base(tmp, *elem);
-+ }
-+ if (res) {
-+ /* Failure, try again */
-+ write_unlock_bh(&set->lock);
-+ harray_free(tmp->members);
-+ kfree(tmp);
-+ goto again;
-+ }
-+
-+ /* Success at resizing! */
-+ members = map->members;
-+
-+ map->hashsize = tmp->hashsize;
-+ map->members = tmp->members;
-+ write_unlock_bh(&set->lock);
-+
-+ harray_free(members);
-+ kfree(tmp);
-+
-+ return 0;
-+}
-+
-+static inline int
-+__delip(struct ip_set_nethash *map, ip_set_ip_t ip, unsigned char cidr,
-+ ip_set_ip_t *hash_ip)
-+{
-+ ip_set_ip_t id, *elem;
-+
-+ if (!ip)
-+ return -ERANGE;
-+
-+ id = hash_id_cidr(map, ip, cidr, hash_ip);
-+ if (id == UINT_MAX)
-+ return -EEXIST;
-+
-+ elem = HARRAY_ELEM(map->members, ip_set_ip_t *, id);
-+ *elem = 0;
-+ map->elements--;
-+ return 0;
-+}
-+
-+static int
-+delip(struct ip_set *set, const void *data, size_t size,
-+ ip_set_ip_t *hash_ip)
-+{
-+ struct ip_set_req_nethash *req =
-+ (struct ip_set_req_nethash *) data;
-+
-+ if (size != sizeof(struct ip_set_req_nethash)) {
-+ ip_set_printk("data length wrong (want %zu, have %zu)",
-+ sizeof(struct ip_set_req_nethash),
-+ size);
-+ return -EINVAL;
-+ }
-+ /* TODO: no garbage collection in map->cidr */
-+ return __delip((struct ip_set_nethash *) set->data,
-+ req->ip, req->cidr, hash_ip);
-+}
-+
-+static int
-+delip_kernel(struct ip_set *set,
-+ const struct sk_buff *skb,
-+ ip_set_ip_t *hash_ip,
-+ const u_int32_t *flags,
-+ unsigned char index)
-+{
-+ struct ip_set_nethash *map = (struct ip_set_nethash *) set->data;
-+ int ret = -ERANGE;
-+ ip_set_ip_t ip = ntohl(flags[index] & IPSET_SRC
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-+ ? ip_hdr(skb)->saddr
-+ : ip_hdr(skb)->daddr);
-+#else
-+ ? skb->nh.iph->saddr
-+ : skb->nh.iph->daddr);
-+#endif
-+
-+ if (map->cidr[0])
-+ ret = __delip(map, ip, map->cidr[0], hash_ip);
-+
-+ return ret;
-+}
-+
-+static int create(struct ip_set *set, const void *data, size_t size)
-+{
-+ struct ip_set_req_nethash_create *req =
-+ (struct ip_set_req_nethash_create *) data;
-+ struct ip_set_nethash *map;
-+ uint16_t i;
-+
-+ if (size != sizeof(struct ip_set_req_nethash_create)) {
-+ ip_set_printk("data length wrong (want %zu, have %zu)",
-+ sizeof(struct ip_set_req_nethash_create),
-+ size);
-+ return -EINVAL;
-+ }
-+
-+ if (req->hashsize < 1) {
-+ ip_set_printk("hashsize too small");
-+ return -ENOEXEC;
-+ }
-+ if (req->probes < 1) {
-+ ip_set_printk("probes too small");
-+ return -ENOEXEC;
-+ }
-+
-+ map = kmalloc(sizeof(struct ip_set_nethash)
-+ + req->probes * sizeof(uint32_t), GFP_KERNEL);
-+ if (!map) {
-+ DP("out of memory for %d bytes",
-+ sizeof(struct ip_set_nethash)
-+ + req->probes * sizeof(uint32_t));
-+ return -ENOMEM;
-+ }
-+ for (i = 0; i < req->probes; i++)
-+ get_random_bytes(((uint32_t *) map->initval)+i, 4);
-+ map->elements = 0;
-+ map->hashsize = req->hashsize;
-+ map->probes = req->probes;
-+ map->resize = req->resize;
-+ memset(map->cidr, 0, 30 * sizeof(unsigned char));
-+ map->members = harray_malloc(map->hashsize, sizeof(ip_set_ip_t), GFP_KERNEL);
-+ if (!map->members) {
-+ DP("out of memory for %d bytes", map->hashsize * sizeof(ip_set_ip_t));
-+ kfree(map);
-+ return -ENOMEM;
-+ }
-+
-+ set->data = map;
-+ return 0;
-+}
-+
-+static void destroy(struct ip_set *set)
-+{
-+ struct ip_set_nethash *map = (struct ip_set_nethash *) set->data;
-+
-+ harray_free(map->members);
-+ kfree(map);
-+
-+ set->data = NULL;
-+}
-+
-+static void flush(struct ip_set *set)
-+{
-+ struct ip_set_nethash *map = (struct ip_set_nethash *) set->data;
-+ harray_flush(map->members, map->hashsize, sizeof(ip_set_ip_t));
-+ memset(map->cidr, 0, 30 * sizeof(unsigned char));
-+ map->elements = 0;
-+}
-+
-+static void list_header(const struct ip_set *set, void *data)
-+{
-+ struct ip_set_nethash *map = (struct ip_set_nethash *) set->data;
-+ struct ip_set_req_nethash_create *header =
-+ (struct ip_set_req_nethash_create *) data;
-+
-+ header->hashsize = map->hashsize;
-+ header->probes = map->probes;
-+ header->resize = map->resize;
-+}
-+
-+static int list_members_size(const struct ip_set *set)
-+{
-+ struct ip_set_nethash *map = (struct ip_set_nethash *) set->data;
-+
-+ return (map->hashsize * sizeof(ip_set_ip_t));
-+}
-+
-+static void list_members(const struct ip_set *set, void *data)
-+{
-+ struct ip_set_nethash *map = (struct ip_set_nethash *) set->data;
-+ ip_set_ip_t i, *elem;
-+
-+ for (i = 0; i < map->hashsize; i++) {
-+ elem = HARRAY_ELEM(map->members, ip_set_ip_t *, i);
-+ ((ip_set_ip_t *)data)[i] = *elem;
-+ }
-+}
-+
-+static struct ip_set_type ip_set_nethash = {
-+ .typename = SETTYPE_NAME,
-+ .features = IPSET_TYPE_IP | IPSET_DATA_SINGLE,
-+ .protocol_version = IP_SET_PROTOCOL_VERSION,
-+ .create = &create,
-+ .destroy = &destroy,
-+ .flush = &flush,
-+ .reqsize = sizeof(struct ip_set_req_nethash),
-+ .addip = &addip,
-+ .addip_kernel = &addip_kernel,
-+ .retry = &retry,
-+ .delip = &delip,
-+ .delip_kernel = &delip_kernel,
-+ .testip = &testip,
-+ .testip_kernel = &testip_kernel,
-+ .header_size = sizeof(struct ip_set_req_nethash_create),
-+ .list_header = &list_header,
-+ .list_members_size = &list_members_size,
-+ .list_members = &list_members,
-+ .me = THIS_MODULE,
-+};
-+
-+MODULE_LICENSE("GPL");
-+MODULE_AUTHOR("Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>");
-+MODULE_DESCRIPTION("nethash type of IP sets");
-+module_param(limit, int, 0600);
-+MODULE_PARM_DESC(limit, "maximal number of elements stored in the sets");
-+
-+static int __init ip_set_nethash_init(void)
-+{
-+ return ip_set_register_set_type(&ip_set_nethash);
-+}
-+
-+static void __exit ip_set_nethash_fini(void)
-+{
-+ /* FIXME: possible race with ip_set_create() */
-+ ip_set_unregister_set_type(&ip_set_nethash);
-+}
-+
-+module_init(ip_set_nethash_init);
-+module_exit(ip_set_nethash_fini);
-Index: linux-2.6.21.7/net/ipv4/netfilter/ip_set_portmap.c
-===================================================================
---- /dev/null
-+++ linux-2.6.21.7/net/ipv4/netfilter/ip_set_portmap.c
-@@ -0,0 +1,346 @@
-+/* Copyright (C) 2003-2004 Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
-+ *
-+ * This program is free software; you can redistribute it and/or modify
-+ * it under the terms of the GNU General Public License version 2 as
-+ * published by the Free Software Foundation.
-+ */
-+
-+/* Kernel module implementing a port set type as a bitmap */
-+
-+#include <linux/module.h>
-+#include <linux/ip.h>
-+#include <linux/tcp.h>
-+#include <linux/udp.h>
-+#include <linux/skbuff.h>
-+#include <linux/version.h>
-+#include <linux/netfilter_ipv4/ip_tables.h>
-+#include <linux/netfilter_ipv4/ip_set.h>
-+#include <linux/errno.h>
-+#include <asm/uaccess.h>
-+#include <asm/bitops.h>
-+#include <linux/spinlock.h>
-+
-+#include <net/ip.h>
-+
-+#include <linux/netfilter_ipv4/ip_set_portmap.h>
-+
-+/* We must handle non-linear skbs */
-+static inline ip_set_ip_t
-+get_port(const struct sk_buff *skb, u_int32_t flags)
-+{
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-+ struct iphdr *iph = ip_hdr(skb);
-+#else
-+ struct iphdr *iph = skb->nh.iph;
-+#endif
-+ u_int16_t offset = ntohs(iph->frag_off) & IP_OFFSET;
-+ switch (iph->protocol) {
-+ case IPPROTO_TCP: {
-+ struct tcphdr tcph;
-+
-+ /* See comments at tcp_match in ip_tables.c */
-+ if (offset)
-+ return INVALID_PORT;
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-+ if (skb_copy_bits(skb, ip_hdr(skb)->ihl*4, &tcph, sizeof(tcph)) < 0)
-+#else
-+ if (skb_copy_bits(skb, skb->nh.iph->ihl*4, &tcph, sizeof(tcph)) < 0)
-+#endif
-+ /* No choice either */
-+ return INVALID_PORT;
-+
-+ return ntohs(flags & IPSET_SRC ?
-+ tcph.source : tcph.dest);
-+ }
-+ case IPPROTO_UDP: {
-+ struct udphdr udph;
-+
-+ if (offset)
-+ return INVALID_PORT;
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-+ if (skb_copy_bits(skb, ip_hdr(skb)->ihl*4, &udph, sizeof(udph)) < 0)
-+#else
-+ if (skb_copy_bits(skb, skb->nh.iph->ihl*4, &udph, sizeof(udph)) < 0)
-+#endif
-+ /* No choice either */
-+ return INVALID_PORT;
-+
-+ return ntohs(flags & IPSET_SRC ?
-+ udph.source : udph.dest);
-+ }
-+ default:
-+ return INVALID_PORT;
-+ }
-+}
-+
-+static inline int
-+__testport(struct ip_set *set, ip_set_ip_t port, ip_set_ip_t *hash_port)
-+{
-+ struct ip_set_portmap *map = (struct ip_set_portmap *) set->data;
-+
-+ if (port < map->first_port || port > map->last_port)
-+ return -ERANGE;
-+
-+ *hash_port = port;
-+ DP("set: %s, port:%u, %u", set->name, port, *hash_port);
-+ return !!test_bit(port - map->first_port, map->members);
-+}
-+
-+static int
-+testport(struct ip_set *set, const void *data, size_t size,
-+ ip_set_ip_t *hash_port)
-+{
-+ struct ip_set_req_portmap *req =
-+ (struct ip_set_req_portmap *) data;
-+
-+ if (size != sizeof(struct ip_set_req_portmap)) {
-+ ip_set_printk("data length wrong (want %zu, have %zu)",
-+ sizeof(struct ip_set_req_portmap),
-+ size);
-+ return -EINVAL;
-+ }
-+ return __testport(set, req->port, hash_port);
-+}
-+
-+static int
-+testport_kernel(struct ip_set *set,
-+ const struct sk_buff *skb,
-+ ip_set_ip_t *hash_port,
-+ const u_int32_t *flags,
-+ unsigned char index)
-+{
-+ int res;
-+ ip_set_ip_t port = get_port(skb, flags[index]);
-+
-+ DP("flag %s port %u", flags[index] & IPSET_SRC ? "SRC" : "DST", port);
-+ if (port == INVALID_PORT)
-+ return 0;
-+
-+ res = __testport(set, port, hash_port);
-+
-+ return (res < 0 ? 0 : res);
-+}
-+
-+static inline int
-+__addport(struct ip_set *set, ip_set_ip_t port, ip_set_ip_t *hash_port)
-+{
-+ struct ip_set_portmap *map = (struct ip_set_portmap *) set->data;
-+
-+ if (port < map->first_port || port > map->last_port)
-+ return -ERANGE;
-+ if (test_and_set_bit(port - map->first_port, map->members))
-+ return -EEXIST;
-+
-+ *hash_port = port;
-+ DP("port %u", port);
-+ return 0;
-+}
-+
-+static int
-+addport(struct ip_set *set, const void *data, size_t size,
-+ ip_set_ip_t *hash_port)
-+{
-+ struct ip_set_req_portmap *req =
-+ (struct ip_set_req_portmap *) data;
-+
-+ if (size != sizeof(struct ip_set_req_portmap)) {
-+ ip_set_printk("data length wrong (want %zu, have %zu)",
-+ sizeof(struct ip_set_req_portmap),
-+ size);
-+ return -EINVAL;
-+ }
-+ return __addport(set, req->port, hash_port);
-+}
-+
-+static int
-+addport_kernel(struct ip_set *set,
-+ const struct sk_buff *skb,
-+ ip_set_ip_t *hash_port,
-+ const u_int32_t *flags,
-+ unsigned char index)
-+{
-+ ip_set_ip_t port = get_port(skb, flags[index]);
-+
-+ if (port == INVALID_PORT)
-+ return -EINVAL;
-+
-+ return __addport(set, port, hash_port);
-+}
-+
-+static inline int
-+__delport(struct ip_set *set, ip_set_ip_t port, ip_set_ip_t *hash_port)
-+{
-+ struct ip_set_portmap *map = (struct ip_set_portmap *) set->data;
-+
-+ if (port < map->first_port || port > map->last_port)
-+ return -ERANGE;
-+ if (!test_and_clear_bit(port - map->first_port, map->members))
-+ return -EEXIST;
-+
-+ *hash_port = port;
-+ DP("port %u", port);
-+ return 0;
-+}
-+
-+static int
-+delport(struct ip_set *set, const void *data, size_t size,
-+ ip_set_ip_t *hash_port)
-+{
-+ struct ip_set_req_portmap *req =
-+ (struct ip_set_req_portmap *) data;
-+
-+ if (size != sizeof(struct ip_set_req_portmap)) {
-+ ip_set_printk("data length wrong (want %zu, have %zu)",
-+ sizeof(struct ip_set_req_portmap),
-+ size);
-+ return -EINVAL;
-+ }
-+ return __delport(set, req->port, hash_port);
-+}
-+
-+static int
-+delport_kernel(struct ip_set *set,
-+ const struct sk_buff *skb,
-+ ip_set_ip_t *hash_port,
-+ const u_int32_t *flags,
-+ unsigned char index)
-+{
-+ ip_set_ip_t port = get_port(skb, flags[index]);
-+
-+ if (port == INVALID_PORT)
-+ return -EINVAL;
-+
-+ return __delport(set, port, hash_port);
-+}
-+
-+static int create(struct ip_set *set, const void *data, size_t size)
-+{
-+ int newbytes;
-+ struct ip_set_req_portmap_create *req =
-+ (struct ip_set_req_portmap_create *) data;
-+ struct ip_set_portmap *map;
-+
-+ if (size != sizeof(struct ip_set_req_portmap_create)) {
-+ ip_set_printk("data length wrong (want %zu, have %zu)",
-+ sizeof(struct ip_set_req_portmap_create),
-+ size);
-+ return -EINVAL;
-+ }
-+
-+ DP("from %u to %u", req->from, req->to);
-+
-+ if (req->from > req->to) {
-+ DP("bad port range");
-+ return -ENOEXEC;
-+ }
-+
-+ if (req->to - req->from > MAX_RANGE) {
-+ ip_set_printk("range too big (max %d ports)",
-+ MAX_RANGE+1);
-+ return -ENOEXEC;
-+ }
-+
-+ map = kmalloc(sizeof(struct ip_set_portmap), GFP_KERNEL);
-+ if (!map) {
-+ DP("out of memory for %d bytes",
-+ sizeof(struct ip_set_portmap));
-+ return -ENOMEM;
-+ }
-+ map->first_port = req->from;
-+ map->last_port = req->to;
-+ newbytes = bitmap_bytes(req->from, req->to);
-+ map->members = kmalloc(newbytes, GFP_KERNEL);
-+ if (!map->members) {
-+ DP("out of memory for %d bytes", newbytes);
-+ kfree(map);
-+ return -ENOMEM;
-+ }
-+ memset(map->members, 0, newbytes);
-+
-+ set->data = map;
-+ return 0;
-+}
-+
-+static void destroy(struct ip_set *set)
-+{
-+ struct ip_set_portmap *map = (struct ip_set_portmap *) set->data;
-+
-+ kfree(map->members);
-+ kfree(map);
-+
-+ set->data = NULL;
-+}
-+
-+static void flush(struct ip_set *set)
-+{
-+ struct ip_set_portmap *map = (struct ip_set_portmap *) set->data;
-+ memset(map->members, 0, bitmap_bytes(map->first_port, map->last_port));
-+}
-+
-+static void list_header(const struct ip_set *set, void *data)
-+{
-+ struct ip_set_portmap *map = (struct ip_set_portmap *) set->data;
-+ struct ip_set_req_portmap_create *header =
-+ (struct ip_set_req_portmap_create *) data;
-+
-+ DP("list_header %u %u", map->first_port, map->last_port);
-+
-+ header->from = map->first_port;
-+ header->to = map->last_port;
-+}
-+
-+static int list_members_size(const struct ip_set *set)
-+{
-+ struct ip_set_portmap *map = (struct ip_set_portmap *) set->data;
-+
-+ return bitmap_bytes(map->first_port, map->last_port);
-+}
-+
-+static void list_members(const struct ip_set *set, void *data)
-+{
-+ struct ip_set_portmap *map = (struct ip_set_portmap *) set->data;
-+ int bytes = bitmap_bytes(map->first_port, map->last_port);
-+
-+ memcpy(data, map->members, bytes);
-+}
-+
-+static struct ip_set_type ip_set_portmap = {
-+ .typename = SETTYPE_NAME,
-+ .features = IPSET_TYPE_PORT | IPSET_DATA_SINGLE,
-+ .protocol_version = IP_SET_PROTOCOL_VERSION,
-+ .create = &create,
-+ .destroy = &destroy,
-+ .flush = &flush,
-+ .reqsize = sizeof(struct ip_set_req_portmap),
-+ .addip = &addport,
-+ .addip_kernel = &addport_kernel,
-+ .delip = &delport,
-+ .delip_kernel = &delport_kernel,
-+ .testip = &testport,
-+ .testip_kernel = &testport_kernel,
-+ .header_size = sizeof(struct ip_set_req_portmap_create),
-+ .list_header = &list_header,
-+ .list_members_size = &list_members_size,
-+ .list_members = &list_members,
-+ .me = THIS_MODULE,
-+};
-+
-+MODULE_LICENSE("GPL");
-+MODULE_AUTHOR("Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>");
-+MODULE_DESCRIPTION("portmap type of IP sets");
-+
-+static int __init ip_set_portmap_init(void)
-+{
-+ return ip_set_register_set_type(&ip_set_portmap);
-+}
-+
-+static void __exit ip_set_portmap_fini(void)
-+{
-+ /* FIXME: possible race with ip_set_create() */
-+ ip_set_unregister_set_type(&ip_set_portmap);
-+}
-+
-+module_init(ip_set_portmap_init);
-+module_exit(ip_set_portmap_fini);
-Index: linux-2.6.21.7/net/ipv4/netfilter/ipt_set.c
-===================================================================
---- /dev/null
-+++ linux-2.6.21.7/net/ipv4/netfilter/ipt_set.c
-@@ -0,0 +1,160 @@
-+/* Copyright (C) 2000-2002 Joakim Axelsson <gozem@linux.nu>
-+ * Patrick Schaaf <bof@bof.de>
-+ * Martin Josefsson <gandalf@wlug.westbo.se>
-+ * Copyright (C) 2003-2004 Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
-+ *
-+ * This program is free software; you can redistribute it and/or modify
-+ * it under the terms of the GNU General Public License version 2 as
-+ * published by the Free Software Foundation.
-+ */
-+
-+/* Kernel module to match an IP set. */
-+
-+#include <linux/module.h>
-+#include <linux/ip.h>
-+#include <linux/skbuff.h>
-+#include <linux/version.h>
-+
-+#include <linux/netfilter_ipv4/ip_tables.h>
-+#include <linux/netfilter_ipv4/ip_set.h>
-+#include <linux/netfilter_ipv4/ipt_set.h>
-+
-+static inline int
-+match_set(const struct ipt_set_info *info,
-+ const struct sk_buff *skb,
-+ int inv)
-+{
-+ if (ip_set_testip_kernel(info->index, skb, info->flags))
-+ inv = !inv;
-+ return inv;
-+}
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,23)
-+static bool
-+#else
-+static int
-+#endif
-+match(const struct sk_buff *skb,
-+ const struct net_device *in,
-+ const struct net_device *out,
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17)
-+ const struct xt_match *match,
-+#endif
-+ const void *matchinfo,
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,23)
-+ int offset, unsigned int protoff, bool *hotdrop)
-+#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ int offset, unsigned int protoff, int *hotdrop)
-+#else
-+ int offset, int *hotdrop)
-+#endif
-+{
-+ const struct ipt_set_info_match *info = matchinfo;
-+
-+ return match_set(&info->match_set,
-+ skb,
-+ info->match_set.flags[0] & IPSET_MATCH_INV);
-+}
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,23)
-+bool
-+#else
-+static int
-+#endif
-+checkentry(const char *tablename,
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ const void *inf,
-+#else
-+ const struct ipt_ip *ip,
-+#endif
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17)
-+ const struct xt_match *match,
-+#endif
-+ void *matchinfo,
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
-+ unsigned int matchsize,
-+#endif
-+ unsigned int hook_mask)
-+{
-+ struct ipt_set_info_match *info =
-+ (struct ipt_set_info_match *) matchinfo;
-+ ip_set_id_t index;
-+
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
-+ if (matchsize != IPT_ALIGN(sizeof(struct ipt_set_info_match))) {
-+ ip_set_printk("invalid matchsize %d", matchsize);
-+ return 0;
-+ }
-+#endif
-+
-+ index = ip_set_get_byindex(info->match_set.index);
-+
-+ if (index == IP_SET_INVALID_ID) {
-+ ip_set_printk("Cannot find set indentified by id %u to match",
-+ info->match_set.index);
-+ return 0; /* error */
-+ }
-+ if (info->match_set.flags[IP_SET_MAX_BINDINGS] != 0) {
-+ ip_set_printk("That's nasty!");
-+ return 0; /* error */
-+ }
-+
-+ return 1;
-+}
-+
-+static void destroy(
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17)
-+ const struct xt_match *match,
-+#endif
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
-+ void *matchinfo, unsigned int matchsize)
-+#else
-+ void *matchinfo)
-+#endif
-+{
-+ struct ipt_set_info_match *info = matchinfo;
-+
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
-+ if (matchsize != IPT_ALIGN(sizeof(struct ipt_set_info_match))) {
-+ ip_set_printk("invalid matchsize %d", matchsize);
-+ return;
-+ }
-+#endif
-+ ip_set_put(info->match_set.index);
-+}
-+
-+static struct ipt_match set_match = {
-+ .name = "set",
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,21)
-+ .family = AF_INET,
-+#endif
-+ .match = &match,
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17)
-+ .matchsize = sizeof(struct ipt_set_info_match),
-+#endif
-+ .checkentry = &checkentry,
-+ .destroy = &destroy,
-+ .me = THIS_MODULE
-+};
-+
-+MODULE_LICENSE("GPL");
-+MODULE_AUTHOR("Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>");
-+MODULE_DESCRIPTION("iptables IP set match module");
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,21)
-+#define ipt_register_match xt_register_match
-+#define ipt_unregister_match xt_unregister_match
-+#endif
-+
-+static int __init ipt_ipset_init(void)
-+{
-+ return ipt_register_match(&set_match);
-+}
-+
-+static void __exit ipt_ipset_fini(void)
-+{
-+ ipt_unregister_match(&set_match);
-+}
-+
-+module_init(ipt_ipset_init);
-+module_exit(ipt_ipset_fini);
-Index: linux-2.6.21.7/net/ipv4/netfilter/ipt_SET.c
-===================================================================
---- /dev/null
-+++ linux-2.6.21.7/net/ipv4/netfilter/ipt_SET.c
-@@ -0,0 +1,172 @@
-+/* Copyright (C) 2000-2002 Joakim Axelsson <gozem@linux.nu>
-+ * Patrick Schaaf <bof@bof.de>
-+ * Martin Josefsson <gandalf@wlug.westbo.se>
-+ * Copyright (C) 2003-2004 Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
-+ *
-+ * This program is free software; you can redistribute it and/or modify
-+ * it under the terms of the GNU General Public License version 2 as
-+ * published by the Free Software Foundation.
-+ */
-+
-+/* ipt_SET.c - netfilter target to manipulate IP sets */
-+
-+#include <linux/types.h>
-+#include <linux/ip.h>
-+#include <linux/timer.h>
-+#include <linux/module.h>
-+#include <linux/netfilter.h>
-+#include <linux/netdevice.h>
-+#include <linux/if.h>
-+#include <linux/inetdevice.h>
-+#include <linux/version.h>
-+#include <net/protocol.h>
-+#include <net/checksum.h>
-+#include <linux/netfilter_ipv4.h>
-+#include <linux/netfilter_ipv4/ip_tables.h>
-+#include <linux/netfilter_ipv4/ipt_set.h>
-+
-+static unsigned int
-+target(struct sk_buff **pskb,
-+ const struct net_device *in,
-+ const struct net_device *out,
-+ unsigned int hooknum,
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17)
-+ const struct xt_target *target,
-+#endif
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
-+ const void *targinfo,
-+ void *userinfo)
-+#else
-+ const void *targinfo)
-+#endif
-+{
-+ const struct ipt_set_info_target *info = targinfo;
-+
-+ if (info->add_set.index != IP_SET_INVALID_ID)
-+ ip_set_addip_kernel(info->add_set.index,
-+ *pskb,
-+ info->add_set.flags);
-+ if (info->del_set.index != IP_SET_INVALID_ID)
-+ ip_set_delip_kernel(info->del_set.index,
-+ *pskb,
-+ info->del_set.flags);
-+
-+ return IPT_CONTINUE;
-+}
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,23)
-+static bool
-+#else
-+static int
-+#endif
-+checkentry(const char *tablename,
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ const void *e,
-+#else
-+ const struct ipt_entry *e,
-+#endif
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17)
-+ const struct xt_target *target,
-+#endif
-+ void *targinfo,
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
-+ unsigned int targinfosize,
-+#endif
-+ unsigned int hook_mask)
-+{
-+ struct ipt_set_info_target *info =
-+ (struct ipt_set_info_target *) targinfo;
-+ ip_set_id_t index;
-+
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
-+ if (targinfosize != IPT_ALIGN(sizeof(*info))) {
-+ DP("bad target info size %u", targinfosize);
-+ return 0;
-+ }
-+#endif
-+
-+ if (info->add_set.index != IP_SET_INVALID_ID) {
-+ index = ip_set_get_byindex(info->add_set.index);
-+ if (index == IP_SET_INVALID_ID) {
-+ ip_set_printk("cannot find add_set index %u as target",
-+ info->add_set.index);
-+ return 0; /* error */
-+ }
-+ }
-+
-+ if (info->del_set.index != IP_SET_INVALID_ID) {
-+ index = ip_set_get_byindex(info->del_set.index);
-+ if (index == IP_SET_INVALID_ID) {
-+ ip_set_printk("cannot find del_set index %u as target",
-+ info->del_set.index);
-+ return 0; /* error */
-+ }
-+ }
-+ if (info->add_set.flags[IP_SET_MAX_BINDINGS] != 0
-+ || info->del_set.flags[IP_SET_MAX_BINDINGS] != 0) {
-+ ip_set_printk("That's nasty!");
-+ return 0; /* error */
-+ }
-+
-+ return 1;
-+}
-+
-+static void destroy(
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17)
-+ const struct xt_target *target,
-+#endif
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
-+ void *targetinfo, unsigned int targetsize)
-+#else
-+ void *targetinfo)
-+#endif
-+{
-+ struct ipt_set_info_target *info = targetinfo;
-+
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
-+ if (targetsize != IPT_ALIGN(sizeof(struct ipt_set_info_target))) {
-+ ip_set_printk("invalid targetsize %d", targetsize);
-+ return;
-+ }
-+#endif
-+ if (info->add_set.index != IP_SET_INVALID_ID)
-+ ip_set_put(info->add_set.index);
-+ if (info->del_set.index != IP_SET_INVALID_ID)
-+ ip_set_put(info->del_set.index);
-+}
-+
-+static struct ipt_target SET_target = {
-+ .name = "SET",
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,21)
-+ .family = AF_INET,
-+#endif
-+ .target = target,
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17)
-+ .targetsize = sizeof(struct ipt_set_info_target),
-+#endif
-+ .checkentry = checkentry,
-+ .destroy = destroy,
-+ .me = THIS_MODULE
-+};
-+
-+MODULE_LICENSE("GPL");
-+MODULE_AUTHOR("Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>");
-+MODULE_DESCRIPTION("iptables IP set target module");
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,21)
-+#define ipt_register_target xt_register_target
-+#define ipt_unregister_target xt_unregister_target
-+#endif
-+
-+static int __init ipt_SET_init(void)
-+{
-+ return ipt_register_target(&SET_target);
-+}
-+
-+static void __exit ipt_SET_fini(void)
-+{
-+ ipt_unregister_target(&SET_target);
-+}
-+
-+module_init(ipt_SET_init);
-+module_exit(ipt_SET_fini);
-Index: linux-2.6.21.7/net/ipv4/netfilter/Kconfig
-===================================================================
---- linux-2.6.21.7.orig/net/ipv4/netfilter/Kconfig
-+++ linux-2.6.21.7/net/ipv4/netfilter/Kconfig
-@@ -663,5 +663,122 @@ config IP_NF_ARP_MANGLE
- Allows altering the ARP packet payload: source and destination
- hardware and network addresses.
-
-+config IP_NF_SET
-+ tristate "IP set support"
-+ depends on INET && NETFILTER
-+ help
-+ This option adds IP set support to the kernel.
-+ In order to define and use sets, you need the userspace utility
-+ ipset(8).
-+
-+ To compile it as a module, choose M here. If unsure, say N.
-+
-+config IP_NF_SET_MAX
-+ int "Maximum number of IP sets"
-+ default 256
-+ range 2 65534
-+ depends on IP_NF_SET
-+ help
-+ You can define here default value of the maximum number
-+ of IP sets for the kernel.
-+
-+ The value can be overriden by the 'max_sets' module
-+ parameter of the 'ip_set' module.
-+
-+config IP_NF_SET_HASHSIZE
-+ int "Hash size for bindings of IP sets"
-+ default 1024
-+ depends on IP_NF_SET
-+ help
-+ You can define here default value of the hash size for
-+ bindings of IP sets.
-+
-+ The value can be overriden by the 'hash_size' module
-+ parameter of the 'ip_set' module.
-+
-+config IP_NF_SET_IPMAP
-+ tristate "ipmap set support"
-+ depends on IP_NF_SET
-+ help
-+ This option adds the ipmap set type support.
-+
-+ To compile it as a module, choose M here. If unsure, say N.
-+
-+config IP_NF_SET_MACIPMAP
-+ tristate "macipmap set support"
-+ depends on IP_NF_SET
-+ help
-+ This option adds the macipmap set type support.
-+
-+ To compile it as a module, choose M here. If unsure, say N.
-+
-+config IP_NF_SET_PORTMAP
-+ tristate "portmap set support"
-+ depends on IP_NF_SET
-+ help
-+ This option adds the portmap set type support.
-+
-+ To compile it as a module, choose M here. If unsure, say N.
-+
-+config IP_NF_SET_IPHASH
-+ tristate "iphash set support"
-+ depends on IP_NF_SET
-+ help
-+ This option adds the iphash set type support.
-+
-+ To compile it as a module, choose M here. If unsure, say N.
-+
-+config IP_NF_SET_NETHASH
-+ tristate "nethash set support"
-+ depends on IP_NF_SET
-+ help
-+ This option adds the nethash set type support.
-+
-+ To compile it as a module, choose M here. If unsure, say N.
-+
-+config IP_NF_SET_IPPORTHASH
-+ tristate "ipporthash set support"
-+ depends on IP_NF_SET
-+ help
-+ This option adds the ipporthash set type support.
-+
-+ To compile it as a module, choose M here. If unsure, say N.
-+
-+config IP_NF_SET_IPTREE
-+ tristate "iptree set support"
-+ depends on IP_NF_SET
-+ help
-+ This option adds the iptree set type support.
-+
-+ To compile it as a module, choose M here. If unsure, say N.
-+
-+config IP_NF_SET_IPTREEMAP
-+ tristate "iptreemap set support"
-+ depends on IP_NF_SET
-+ help
-+ This option adds the iptreemap set type support.
-+
-+ To compile it as a module, choose M here. If unsure, say N.
-+
-+config IP_NF_MATCH_SET
-+ tristate "set match support"
-+ depends on IP_NF_SET
-+ help
-+ Set matching matches against given IP sets.
-+ You need the ipset utility to create and set up the sets.
-+
-+ To compile it as a module, choose M here. If unsure, say N.
-+
-+config IP_NF_TARGET_SET
-+ tristate "SET target support"
-+ depends on IP_NF_SET
-+ help
-+ The SET target makes possible to add/delete entries
-+ in IP sets.
-+ You need the ipset utility to create and set up the sets.
-+
-+ To compile it as a module, choose M here. If unsure, say N.
-+
-+
- endmenu
-
-Index: linux-2.6.21.7/net/ipv4/netfilter/Makefile
-===================================================================
---- linux-2.6.21.7.orig/net/ipv4/netfilter/Makefile
-+++ linux-2.6.21.7/net/ipv4/netfilter/Makefile
-@@ -90,6 +90,7 @@ obj-$(CONFIG_IP_NF_MATCH_RECENT) += ipt_
- obj-$(CONFIG_IP_NF_MATCH_ECN) += ipt_ecn.o
- obj-$(CONFIG_IP_NF_MATCH_AH) += ipt_ah.o
- obj-$(CONFIG_IP_NF_MATCH_TTL) += ipt_ttl.o
-+obj-$(CONFIG_IP_NF_MATCH_SET) += ipt_set.o
- obj-$(CONFIG_IP_NF_MATCH_ADDRTYPE) += ipt_addrtype.o
- obj-$(CONFIG_IP_NF_MATCH_IPP2P) += ipt_ipp2p.o
-
-@@ -106,6 +107,18 @@ obj-$(CONFIG_IP_NF_TARGET_LOG) += ipt_LO
- obj-$(CONFIG_IP_NF_TARGET_ULOG) += ipt_ULOG.o
- obj-$(CONFIG_IP_NF_TARGET_CLUSTERIP) += ipt_CLUSTERIP.o
- obj-$(CONFIG_IP_NF_TARGET_TTL) += ipt_TTL.o
-+obj-$(CONFIG_IP_NF_TARGET_SET) += ipt_SET.o
-+
-+# sets
-+obj-$(CONFIG_IP_NF_SET) += ip_set.o
-+obj-$(CONFIG_IP_NF_SET_IPMAP) += ip_set_ipmap.o
-+obj-$(CONFIG_IP_NF_SET_PORTMAP) += ip_set_portmap.o
-+obj-$(CONFIG_IP_NF_SET_MACIPMAP) += ip_set_macipmap.o
-+obj-$(CONFIG_IP_NF_SET_IPHASH) += ip_set_iphash.o
-+obj-$(CONFIG_IP_NF_SET_NETHASH) += ip_set_nethash.o
-+obj-$(CONFIG_IP_NF_SET_IPPORTHASH) += ip_set_ipporthash.o
-+obj-$(CONFIG_IP_NF_SET_IPTREE) += ip_set_iptree.o
-+obj-$(CONFIG_IP_NF_SET_IPTREEMAP) += ip_set_iptreemap.o
-
- # generic ARP tables
- obj-$(CONFIG_IP_NF_ARPTABLES) += arp_tables.o
+++ /dev/null
-Index: linux-2.6.21.7/include/linux/netfilter_ipv4/ipt_time.h
-===================================================================
---- /dev/null
-+++ linux-2.6.21.7/include/linux/netfilter_ipv4/ipt_time.h
-@@ -0,0 +1,18 @@
-+#ifndef __ipt_time_h_included__
-+#define __ipt_time_h_included__
-+
-+
-+struct ipt_time_info {
-+ u_int8_t days_match; /* 1 bit per day. -SMTWTFS */
-+ u_int16_t time_start; /* 0 < time_start < 23*60+59 = 1439 */
-+ u_int16_t time_stop; /* 0:0 < time_stat < 23:59 */
-+
-+ /* FIXME: Keep this one for userspace iptables binary compability: */
-+ u_int8_t kerneltime; /* ignore skb time (and use kerneltime) or not. */
-+
-+ time_t date_start;
-+ time_t date_stop;
-+};
-+
-+
-+#endif /* __ipt_time_h_included__ */
-Index: linux-2.6.21.7/net/ipv4/netfilter/ipt_time.c
-===================================================================
---- /dev/null
-+++ linux-2.6.21.7/net/ipv4/netfilter/ipt_time.c
-@@ -0,0 +1,178 @@
-+/*
-+ This is a module which is used for time matching
-+ It is using some modified code from dietlibc (localtime() function)
-+ that you can find at http://www.fefe.de/dietlibc/
-+ This file is distributed under the terms of the GNU General Public
-+ License (GPL). Copies of the GPL can be obtained from: ftp://prep.ai.mit.edu/pub/gnu/GPL
-+ 2001-05-04 Fabrice MARIE <fabrice@netfilter.org> : initial development.
-+ 2001-21-05 Fabrice MARIE <fabrice@netfilter.org> : bug fix in the match code,
-+ thanks to "Zeng Yu" <zengy@capitel.com.cn> for bug report.
-+ 2001-26-09 Fabrice MARIE <fabrice@netfilter.org> : force the match to be in LOCAL_IN or PRE_ROUTING only.
-+ 2001-30-11 Fabrice : added the possibility to use the match in FORWARD/OUTPUT with a little hack,
-+ added Nguyen Dang Phuoc Dong <dongnd@tlnet.com.vn> patch to support timezones.
-+ 2004-05-02 Fabrice : added support for date matching, from an idea of Fabien COELHO.
-+*/
-+
-+#include <linux/module.h>
-+#include <linux/skbuff.h>
-+#include <linux/netfilter_ipv4/ip_tables.h>
-+#include <linux/netfilter_ipv4/ipt_time.h>
-+#include <linux/time.h>
-+
-+MODULE_AUTHOR("Fabrice MARIE <fabrice@netfilter.org>");
-+MODULE_DESCRIPTION("Match arrival timestamp/date");
-+MODULE_LICENSE("GPL");
-+
-+struct tm
-+{
-+ int tm_sec; /* Seconds. [0-60] (1 leap second) */
-+ int tm_min; /* Minutes. [0-59] */
-+ int tm_hour; /* Hours. [0-23] */
-+ int tm_mday; /* Day. [1-31] */
-+ int tm_mon; /* Month. [0-11] */
-+ int tm_year; /* Year - 1900. */
-+ int tm_wday; /* Day of week. [0-6] */
-+ int tm_yday; /* Days in year.[0-365] */
-+ int tm_isdst; /* DST. [-1/0/1]*/
-+
-+ long int tm_gmtoff; /* we don't care, we count from GMT */
-+ const char *tm_zone; /* we don't care, we count from GMT */
-+};
-+
-+void
-+localtime(const u32 time, struct tm *r);
-+
-+static int
-+match(const struct sk_buff *skb,
-+ const struct net_device *in,
-+ const struct net_device *out,
-+ const struct xt_match *match,
-+ const void *matchinfo,
-+ int offset,
-+ unsigned int protoff,
-+ int *hotdrop)
-+{
-+ const struct ipt_time_info *info = matchinfo; /* match info for rule */
-+ struct tm currenttime; /* time human readable */
-+ u_int8_t days_of_week[7] = {64, 32, 16, 8, 4, 2, 1};
-+ u_int16_t packet_time;
-+
-+ /* We might not have a timestamp, get one */
-+ if (skb->tstamp.off_sec == 0)
-+ __net_timestamp((struct sk_buff *)skb);
-+
-+ /* First we make sure we are in the date start-stop boundaries */
-+ if ((skb->tstamp.off_sec < info->date_start) || (skb->tstamp.off_sec > info->date_stop))
-+ return 0; /* We are outside the date boundaries */
-+
-+ /* Transform the timestamp of the packet, in a human readable form */
-+ localtime(skb->tstamp.off_sec, ¤ttime);
-+
-+ /* check if we match this timestamp, we start by the days... */
-+ if ((days_of_week[currenttime.tm_wday] & info->days_match) != days_of_week[currenttime.tm_wday])
-+ return 0; /* the day doesn't match */
-+
-+ /* ... check the time now */
-+ packet_time = (currenttime.tm_hour * 60) + currenttime.tm_min;
-+ if ((packet_time < info->time_start) || (packet_time > info->time_stop))
-+ return 0;
-+
-+ /* here we match ! */
-+ return 1;
-+}
-+
-+static int
-+checkentry(const char *tablename,
-+ const void *ip,
-+ const struct xt_match *match,
-+ void *matchinfo,
-+ unsigned int hook_mask)
-+{
-+ struct ipt_time_info *info = matchinfo; /* match info for rule */
-+
-+ /* First, check that we are in the correct hooks */
-+ if (hook_mask
-+ & ~((1 << NF_IP_PRE_ROUTING) | (1 << NF_IP_LOCAL_IN) | (1 << NF_IP_FORWARD) | (1 << NF_IP_LOCAL_OUT)))
-+ {
-+ printk("ipt_time: error, only valid for PRE_ROUTING, LOCAL_IN, FORWARD and OUTPUT)\n");
-+ return 0;
-+ }
-+
-+ /* Now check the coherence of the data ... */
-+ if ((info->time_start > 1439) || /* 23*60+59 = 1439*/
-+ (info->time_stop > 1439))
-+ {
-+ printk(KERN_WARNING "ipt_time: invalid argument\n");
-+ return 0;
-+ }
-+
-+ return 1;
-+}
-+
-+static struct ipt_match time_match = {
-+ .name = "time",
-+ .match = &match,
-+ .matchsize = sizeof(struct ipt_time_info),
-+ .checkentry = &checkentry,
-+ .me = THIS_MODULE
-+};
-+
-+static int __init init(void)
-+{
-+ printk("ipt_time loading\n");
-+ return xt_register_match(&time_match);
-+}
-+
-+static void __exit fini(void)
-+{
-+ xt_unregister_match(&time_match);
-+ printk("ipt_time unloaded\n");
-+}
-+
-+module_init(init);
-+module_exit(fini);
-+
-+
-+/* The part below is borowed and modified from dietlibc */
-+
-+/* seconds per day */
-+#define SPD 24*60*60
-+
-+void
-+localtime(const u32 time, struct tm *r) {
-+ u32 i, timep;
-+ extern struct timezone sys_tz;
-+ const unsigned int __spm[12] =
-+ { 0,
-+ (31),
-+ (31+28),
-+ (31+28+31),
-+ (31+28+31+30),
-+ (31+28+31+30+31),
-+ (31+28+31+30+31+30),
-+ (31+28+31+30+31+30+31),
-+ (31+28+31+30+31+30+31+31),
-+ (31+28+31+30+31+30+31+31+30),
-+ (31+28+31+30+31+30+31+31+30+31),
-+ (31+28+31+30+31+30+31+31+30+31+30),
-+ };
-+ register u32 work;
-+
-+ timep = time - (sys_tz.tz_minuteswest * 60);
-+ work=timep%(SPD);
-+ r->tm_sec=work%60; work/=60;
-+ r->tm_min=work%60; r->tm_hour=work/60;
-+ work=timep/(SPD);
-+ r->tm_wday=(4+work)%7;
-+ for (i=1970; ; ++i) {
-+ register time_t k= (!(i%4) && ((i%100) || !(i%400)))?366:365;
-+ if (work>k)
-+ work-=k;
-+ else
-+ break;
-+ }
-+ r->tm_year=i-1900;
-+ for (i=11; i && __spm[i]>work; --i) ;
-+ r->tm_mon=i;
-+ r->tm_mday=work-__spm[i]+1;
-+}
-Index: linux-2.6.21.7/net/ipv4/netfilter/Kconfig
-===================================================================
---- linux-2.6.21.7.orig/net/ipv4/netfilter/Kconfig
-+++ linux-2.6.21.7/net/ipv4/netfilter/Kconfig
-@@ -260,6 +260,22 @@ config IP_NF_MATCH_TOS
-
- To compile it as a module, choose M here. If unsure, say N.
-
-+
-+config IP_NF_MATCH_TIME
-+ tristate 'TIME match support'
-+ depends on IP_NF_IPTABLES
-+ help
-+ This option adds a `time' match, which allows you
-+ to match based on the packet arrival time/date
-+ (arrival time/date at the machine which netfilter is running on) or
-+ departure time/date (for locally generated packets).
-+
-+ If you say Y here, try iptables -m time --help for more information.
-+ If you want to compile it as a module, say M here and read
-+
-+ Documentation/modules.txt. If unsure, say `N'.
-+
-+
- config IP_NF_MATCH_RECENT
- tristate "recent match support"
- depends on IP_NF_IPTABLES
-Index: linux-2.6.21.7/net/ipv4/netfilter/Makefile
-===================================================================
---- linux-2.6.21.7.orig/net/ipv4/netfilter/Makefile
-+++ linux-2.6.21.7/net/ipv4/netfilter/Makefile
-@@ -86,6 +86,7 @@ obj-$(CONFIG_IP_NF_RAW) += iptable_raw.o
- obj-$(CONFIG_IP_NF_MATCH_IPRANGE) += ipt_iprange.o
- obj-$(CONFIG_IP_NF_MATCH_OWNER) += ipt_owner.o
- obj-$(CONFIG_IP_NF_MATCH_TOS) += ipt_tos.o
-+obj-$(CONFIG_IP_NF_MATCH_TIME) += ipt_time.o
- obj-$(CONFIG_IP_NF_MATCH_RECENT) += ipt_recent.o
- obj-$(CONFIG_IP_NF_MATCH_ECN) += ipt_ecn.o
- obj-$(CONFIG_IP_NF_MATCH_AH) += ipt_ah.o
+++ /dev/null
-Index: linux-2.6.21.7/drivers/net/imq.c
-===================================================================
---- /dev/null
-+++ linux-2.6.21.7/drivers/net/imq.c
-@@ -0,0 +1,402 @@
-+/*
-+ * Pseudo-driver for the intermediate queue device.
-+ *
-+ * 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.
-+ *
-+ * Authors: Patrick McHardy, <kaber@trash.net>
-+ *
-+ * The first version was written by Martin Devera, <devik@cdi.cz>
-+ *
-+ * Credits: Jan Rafaj <imq2t@cedric.vabo.cz>
-+ * - Update patch to 2.4.21
-+ * Sebastian Strollo <sstrollo@nortelnetworks.com>
-+ * - Fix "Dead-loop on netdevice imq"-issue
-+ * Marcel Sebek <sebek64@post.cz>
-+ * - Update to 2.6.2-rc1
-+ *
-+ * After some time of inactivity there is a group taking care
-+ * of IMQ again: http://www.linuximq.net
-+ *
-+ *
-+ * 2004/06/30 - New version of IMQ patch to kernels <=2.6.7 including
-+ * the following changes:
-+ *
-+ * - Correction of ipv6 support "+"s issue (Hasso Tepper)
-+ * - Correction of imq_init_devs() issue that resulted in
-+ * kernel OOPS unloading IMQ as module (Norbert Buchmuller)
-+ * - Addition of functionality to choose number of IMQ devices
-+ * during kernel config (Andre Correa)
-+ * - Addition of functionality to choose how IMQ hooks on
-+ * PRE and POSTROUTING (after or before NAT) (Andre Correa)
-+ * - Cosmetic corrections (Norbert Buchmuller) (Andre Correa)
-+ *
-+ *
-+ * 2005/12/16 - IMQ versions between 2.6.7 and 2.6.13 were
-+ * released with almost no problems. 2.6.14-x was released
-+ * with some important changes: nfcache was removed; After
-+ * some weeks of trouble we figured out that some IMQ fields
-+ * in skb were missing in skbuff.c - skb_clone and copy_skb_header.
-+ * These functions are correctly patched by this new patch version.
-+ *
-+ * Thanks for all who helped to figure out all the problems with
-+ * 2.6.14.x: Patrick McHardy, Rune Kock, VeNoMouS, Max CtRiX,
-+ * Kevin Shanahan, Richard Lucassen, Valery Dachev (hopefully
-+ * I didn't forget anybody). I apologize again for my lack of time.
-+ *
-+ * More info at: http://www.linuximq.net/ (Andre Correa)
-+ */
-+
-+#include <linux/module.h>
-+#include <linux/kernel.h>
-+#include <linux/moduleparam.h>
-+#include <linux/skbuff.h>
-+#include <linux/netdevice.h>
-+#include <linux/rtnetlink.h>
-+#include <linux/if_arp.h>
-+#include <linux/netfilter.h>
-+#include <linux/netfilter_ipv4.h>
-+#if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
-+ #include <linux/netfilter_ipv6.h>
-+#endif
-+#include <linux/imq.h>
-+#include <net/pkt_sched.h>
-+
-+extern int qdisc_restart1(struct net_device *dev);
-+
-+static nf_hookfn imq_nf_hook;
-+
-+static struct nf_hook_ops imq_ingress_ipv4 = {
-+ .hook = imq_nf_hook,
-+ .owner = THIS_MODULE,
-+ .pf = PF_INET,
-+ .hooknum = NF_IP_PRE_ROUTING,
-+#if defined(CONFIG_IMQ_BEHAVIOR_BA) || defined(CONFIG_IMQ_BEHAVIOR_BB)
-+ .priority = NF_IP_PRI_MANGLE + 1
-+#else
-+ .priority = NF_IP_PRI_NAT_DST + 1
-+#endif
-+};
-+
-+static struct nf_hook_ops imq_egress_ipv4 = {
-+ .hook = imq_nf_hook,
-+ .owner = THIS_MODULE,
-+ .pf = PF_INET,
-+ .hooknum = NF_IP_POST_ROUTING,
-+#if defined(CONFIG_IMQ_BEHAVIOR_AA) || defined(CONFIG_IMQ_BEHAVIOR_BA)
-+ .priority = NF_IP_PRI_LAST
-+#else
-+ .priority = NF_IP_PRI_NAT_SRC - 1
-+#endif
-+};
-+
-+#if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
-+static struct nf_hook_ops imq_ingress_ipv6 = {
-+ .hook = imq_nf_hook,
-+ .owner = THIS_MODULE,
-+ .pf = PF_INET6,
-+ .hooknum = NF_IP6_PRE_ROUTING,
-+#if defined(CONFIG_IMQ_BEHAVIOR_BA) || defined(CONFIG_IMQ_BEHAVIOR_BB)
-+ .priority = NF_IP6_PRI_MANGLE + 1
-+#else
-+ .priority = NF_IP6_PRI_NAT_DST + 1
-+#endif
-+};
-+
-+static struct nf_hook_ops imq_egress_ipv6 = {
-+ .hook = imq_nf_hook,
-+ .owner = THIS_MODULE,
-+ .pf = PF_INET6,
-+ .hooknum = NF_IP6_POST_ROUTING,
-+#if defined(CONFIG_IMQ_BEHAVIOR_AA) || defined(CONFIG_IMQ_BEHAVIOR_BA)
-+ .priority = NF_IP6_PRI_LAST
-+#else
-+ .priority = NF_IP6_PRI_NAT_SRC - 1
-+#endif
-+};
-+#endif
-+
-+#if defined(CONFIG_IMQ_NUM_DEVS)
-+static unsigned int numdevs = CONFIG_IMQ_NUM_DEVS;
-+#else
-+static unsigned int numdevs = 2;
-+#endif
-+
-+static struct net_device *imq_devs;
-+
-+static struct net_device_stats *imq_get_stats(struct net_device *dev)
-+{
-+ return (struct net_device_stats *)dev->priv;
-+}
-+
-+/* called for packets kfree'd in qdiscs at places other than enqueue */
-+static void imq_skb_destructor(struct sk_buff *skb)
-+{
-+ struct nf_info *info = skb->nf_info;
-+
-+ if (info) {
-+ if (info->indev)
-+ dev_put(info->indev);
-+ if (info->outdev)
-+ dev_put(info->outdev);
-+ kfree(info);
-+ }
-+}
-+
-+static int imq_dev_xmit(struct sk_buff *skb, struct net_device *dev)
-+{
-+ struct net_device_stats *stats = (struct net_device_stats*) dev->priv;
-+
-+ stats->tx_bytes += skb->len;
-+ stats->tx_packets++;
-+
-+ skb->imq_flags = 0;
-+ skb->destructor = NULL;
-+
-+ dev->trans_start = jiffies;
-+ nf_reinject(skb, skb->nf_info, NF_ACCEPT);
-+ return 0;
-+}
-+
-+static int imq_nf_queue(struct sk_buff *skb, struct nf_info *info, unsigned queue_num, void *data)
-+{
-+ struct net_device *dev;
-+ struct net_device_stats *stats;
-+ struct sk_buff *skb2 = NULL;
-+ struct Qdisc *q;
-+ unsigned int index = skb->imq_flags&IMQ_F_IFMASK;
-+ int ret = -1;
-+
-+ if (index > numdevs)
-+ return -1;
-+
-+ dev = imq_devs + index;
-+ if (!(dev->flags & IFF_UP)) {
-+ skb->imq_flags = 0;
-+ nf_reinject(skb, info, NF_ACCEPT);
-+ return 0;
-+ }
-+ dev->last_rx = jiffies;
-+
-+ if (skb->destructor) {
-+ skb2 = skb;
-+ skb = skb_clone(skb, GFP_ATOMIC);
-+ if (!skb)
-+ return -1;
-+ }
-+ skb->nf_info = info;
-+
-+ stats = (struct net_device_stats *)dev->priv;
-+ stats->rx_bytes+= skb->len;
-+ stats->rx_packets++;
-+
-+ spin_lock_bh(&dev->queue_lock);
-+ q = dev->qdisc;
-+ if (q->enqueue) {
-+ q->enqueue(skb_get(skb), q);
-+ if (skb_shared(skb)) {
-+ skb->destructor = imq_skb_destructor;
-+ kfree_skb(skb);
-+ ret = 0;
-+ }
-+ }
-+ if (spin_is_locked(&dev->_xmit_lock))
-+ netif_schedule(dev);
-+ else
-+ while (!netif_queue_stopped(dev) && qdisc_restart1(dev) < 0)
-+ /* NOTHING */;
-+
-+ spin_unlock_bh(&dev->queue_lock);
-+
-+ if (skb2)
-+ kfree_skb(ret ? skb : skb2);
-+
-+ return ret;
-+}
-+
-+static struct nf_queue_handler nfqh = {
-+ .name = "imq",
-+ .outfn = imq_nf_queue,
-+};
-+
-+static unsigned int imq_nf_hook(unsigned int hook, struct sk_buff **pskb,
-+ const struct net_device *indev,
-+ const struct net_device *outdev,
-+ int (*okfn)(struct sk_buff *))
-+{
-+ if ((*pskb)->imq_flags & IMQ_F_ENQUEUE)
-+ return NF_QUEUE;
-+
-+ return NF_ACCEPT;
-+}
-+
-+
-+static int __init imq_init_hooks(void)
-+{
-+ int err;
-+
-+ err = nf_register_queue_handler(PF_INET, &nfqh);
-+ if (err > 0)
-+ goto err1;
-+ if ((err = nf_register_hook(&imq_ingress_ipv4)))
-+ goto err2;
-+ if ((err = nf_register_hook(&imq_egress_ipv4)))
-+ goto err3;
-+#if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
-+ if ((err = nf_register_queue_handler(PF_INET6, &nfqh)))
-+ goto err4;
-+ if ((err = nf_register_hook(&imq_ingress_ipv6)))
-+ goto err5;
-+ if ((err = nf_register_hook(&imq_egress_ipv6)))
-+ goto err6;
-+#endif
-+
-+ return 0;
-+
-+#if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
-+err6:
-+ nf_unregister_hook(&imq_ingress_ipv6);
-+err5:
-+ nf_unregister_queue_handler(PF_INET6);
-+err4:
-+ nf_unregister_hook(&imq_egress_ipv4);
-+#endif
-+err3:
-+ nf_unregister_hook(&imq_ingress_ipv4);
-+err2:
-+ nf_unregister_queue_handler(PF_INET);
-+err1:
-+ return err;
-+}
-+
-+static void __exit imq_unhook(void)
-+{
-+ nf_unregister_hook(&imq_ingress_ipv4);
-+ nf_unregister_hook(&imq_egress_ipv4);
-+ nf_unregister_queue_handler(PF_INET);
-+#if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
-+ nf_unregister_hook(&imq_ingress_ipv6);
-+ nf_unregister_hook(&imq_egress_ipv6);
-+ nf_unregister_queue_handler(PF_INET6);
-+#endif
-+}
-+
-+static int __init imq_dev_init(struct net_device *dev)
-+{
-+ dev->hard_start_xmit = imq_dev_xmit;
-+ dev->type = ARPHRD_VOID;
-+ dev->mtu = 1500;
-+ dev->tx_queue_len = 30;
-+ dev->flags = IFF_NOARP;
-+ dev->priv = kmalloc(sizeof(struct net_device_stats), GFP_KERNEL);
-+ if (dev->priv == NULL)
-+ return -ENOMEM;
-+ memset(dev->priv, 0, sizeof(struct net_device_stats));
-+ dev->get_stats = imq_get_stats;
-+
-+ return 0;
-+}
-+
-+static void imq_dev_uninit(struct net_device *dev)
-+{
-+ kfree(dev->priv);
-+}
-+
-+static int __init imq_init_devs(void)
-+{
-+ struct net_device *dev;
-+ int i,j;
-+ j = numdevs;
-+
-+ if (!numdevs || numdevs > IMQ_MAX_DEVS) {
-+ printk(KERN_ERR "IMQ: numdevs has to be betweed 1 and %u\n",
-+ IMQ_MAX_DEVS);
-+ return -EINVAL;
-+ }
-+
-+ imq_devs = kmalloc(sizeof(struct net_device) * numdevs, GFP_KERNEL);
-+ if (!imq_devs)
-+ return -ENOMEM;
-+ memset(imq_devs, 0, sizeof(struct net_device) * numdevs);
-+
-+ /* we start counting at zero */
-+ numdevs--;
-+
-+ for (i = 0, dev = imq_devs; i <= numdevs; i++, dev++) {
-+ SET_MODULE_OWNER(dev);
-+ strcpy(dev->name, "imq%d");
-+ dev->init = imq_dev_init;
-+ dev->uninit = imq_dev_uninit;
-+
-+ if (register_netdev(dev) < 0)
-+ goto err_register;
-+ }
-+ printk(KERN_INFO "IMQ starting with %u devices...\n", j);
-+ return 0;
-+
-+err_register:
-+ for (; i; i--)
-+ unregister_netdev(--dev);
-+ kfree(imq_devs);
-+ return -EIO;
-+}
-+
-+static void imq_cleanup_devs(void)
-+{
-+ int i;
-+ struct net_device *dev = imq_devs;
-+
-+ for (i = 0; i <= numdevs; i++)
-+ unregister_netdev(dev++);
-+
-+ kfree(imq_devs);
-+}
-+
-+static int __init imq_init_module(void)
-+{
-+ int err;
-+
-+ if ((err = imq_init_devs())) {
-+ printk(KERN_ERR "IMQ: Error trying imq_init_devs()\n");
-+ return err;
-+ }
-+ if ((err = imq_init_hooks())) {
-+ printk(KERN_ERR "IMQ: Error trying imq_init_hooks()\n");
-+ imq_cleanup_devs();
-+ return err;
-+ }
-+
-+ printk(KERN_INFO "IMQ driver loaded successfully.\n");
-+
-+#if defined(CONFIG_IMQ_BEHAVIOR_BA) || defined(CONFIG_IMQ_BEHAVIOR_BB)
-+ printk(KERN_INFO "\tHooking IMQ before NAT on PREROUTING.\n");
-+#else
-+ printk(KERN_INFO "\tHooking IMQ after NAT on PREROUTING.\n");
-+#endif
-+#if defined(CONFIG_IMQ_BEHAVIOR_AB) || defined(CONFIG_IMQ_BEHAVIOR_BB)
-+ printk(KERN_INFO "\tHooking IMQ before NAT on POSTROUTING.\n");
-+#else
-+ printk(KERN_INFO "\tHooking IMQ after NAT on POSTROUTING.\n");
-+#endif
-+
-+ return 0;
-+}
-+
-+static void __exit imq_cleanup_module(void)
-+{
-+ imq_unhook();
-+ imq_cleanup_devs();
-+ printk(KERN_INFO "IMQ driver unloaded successfully.\n");
-+}
-+
-+
-+module_init(imq_init_module);
-+module_exit(imq_cleanup_module);
-+
-+module_param(numdevs, int, 0);
-+MODULE_PARM_DESC(numdevs, "number of IMQ devices (how many imq* devices will be created)");
-+MODULE_AUTHOR("http://www.linuximq.net");
-+MODULE_DESCRIPTION("Pseudo-driver for the intermediate queue device. See http://www.linuximq.net/ for more information.");
-+MODULE_LICENSE("GPL");
-Index: linux-2.6.21.7/drivers/net/Kconfig
-===================================================================
---- linux-2.6.21.7.orig/drivers/net/Kconfig
-+++ linux-2.6.21.7/drivers/net/Kconfig
-@@ -96,6 +96,129 @@ config EQUALIZER
- To compile this driver as a module, choose M here: the module
- will be called eql. If unsure, say N.
-
-+config IMQ
-+ tristate "IMQ (intermediate queueing device) support"
-+ depends on NETDEVICES && NETFILTER
-+ ---help---
-+ The IMQ device(s) is used as placeholder for QoS queueing
-+ disciplines. Every packet entering/leaving the IP stack can be
-+ directed through the IMQ device where it's enqueued/dequeued to the
-+ attached qdisc. This allows you to treat network devices as classes
-+ and distribute bandwidth among them. Iptables is used to specify
-+ through which IMQ device, if any, packets travel.
-+
-+ More information at: http://www.linuximq.net/
-+
-+ To compile this driver as a module, choose M here: the module
-+ will be called imq. If unsure, say N.
-+
-+choice
-+ prompt "IMQ behavior (PRE/POSTROUTING)"
-+ depends on IMQ
-+ default IMQ_BEHAVIOR_BA
-+ help
-+
-+ This settings defines how IMQ behaves in respect to its
-+ hooking in PREROUTING and POSTROUTING.
-+
-+ IMQ can work in any of the following ways:
-+
-+ PREROUTING | POSTROUTING
-+ -----------------|-------------------
-+ #1 After NAT | After NAT
-+ #2 After NAT | Before NAT
-+ #3 Before NAT | After NAT
-+ #4 Before NAT | Before NAT
-+
-+ The default behavior is to hook before NAT on PREROUTING
-+ and after NAT on POSTROUTING (#3).
-+
-+ This settings are specially usefull when trying to use IMQ
-+ to shape NATed clients.
-+
-+ More information can be found at: www.linuximq.net
-+
-+ If not sure leave the default settings alone.
-+
-+config IMQ_BEHAVIOR_AA
-+ bool "IMQ AA"
-+ help
-+ This settings defines how IMQ behaves in respect to its
-+ hooking in PREROUTING and POSTROUTING.
-+
-+ Choosing this option will make IMQ hook like this:
-+
-+ PREROUTING: After NAT
-+ POSTROUTING: After NAT
-+
-+ More information can be found at: www.linuximq.net
-+
-+ If not sure leave the default settings alone.
-+
-+config IMQ_BEHAVIOR_AB
-+ bool "IMQ AB"
-+ help
-+ This settings defines how IMQ behaves in respect to its
-+ hooking in PREROUTING and POSTROUTING.
-+
-+ Choosing this option will make IMQ hook like this:
-+
-+ PREROUTING: After NAT
-+ POSTROUTING: Before NAT
-+
-+ More information can be found at: www.linuximq.net
-+
-+ If not sure leave the default settings alone.
-+
-+config IMQ_BEHAVIOR_BA
-+ bool "IMQ BA"
-+ help
-+ This settings defines how IMQ behaves in respect to its
-+ hooking in PREROUTING and POSTROUTING.
-+
-+ Choosing this option will make IMQ hook like this:
-+
-+ PREROUTING: Before NAT
-+ POSTROUTING: After NAT
-+
-+ More information can be found at: www.linuximq.net
-+
-+ If not sure leave the default settings alone.
-+
-+config IMQ_BEHAVIOR_BB
-+ bool "IMQ BB"
-+ help
-+ This settings defines how IMQ behaves in respect to its
-+ hooking in PREROUTING and POSTROUTING.
-+
-+ Choosing this option will make IMQ hook like this:
-+
-+ PREROUTING: Before NAT
-+ POSTROUTING: Before NAT
-+
-+ More information can be found at: www.linuximq.net
-+
-+ If not sure leave the default settings alone.
-+
-+endchoice
-+
-+config IMQ_NUM_DEVS
-+
-+ int "Number of IMQ devices"
-+ range 2 8
-+ depends on IMQ
-+ default "2"
-+ help
-+
-+ This settings defines how many IMQ devices will be
-+ created.
-+
-+ The default value is 2.
-+
-+ More information can be found at: www.linuximq.net
-+
-+ If not sure leave the default settings alone.
-+
- config TUN
- tristate "Universal TUN/TAP device driver support"
- select CRC32
-Index: linux-2.6.21.7/drivers/net/Makefile
-===================================================================
---- linux-2.6.21.7.orig/drivers/net/Makefile
-+++ linux-2.6.21.7/drivers/net/Makefile
-@@ -124,6 +124,7 @@ obj-$(CONFIG_SLIP) += slip.o
- obj-$(CONFIG_SLHC) += slhc.o
-
- obj-$(CONFIG_DUMMY) += dummy.o
-+obj-$(CONFIG_IMQ) += imq.o
- obj-$(CONFIG_IFB) += ifb.o
- obj-$(CONFIG_DE600) += de600.o
- obj-$(CONFIG_DE620) += de620.o
-Index: linux-2.6.21.7/include/linux/imq.h
-===================================================================
---- /dev/null
-+++ linux-2.6.21.7/include/linux/imq.h
-@@ -0,0 +1,9 @@
-+#ifndef _IMQ_H
-+#define _IMQ_H
-+
-+#define IMQ_MAX_DEVS 16
-+
-+#define IMQ_F_IFMASK 0x7f
-+#define IMQ_F_ENQUEUE 0x80
-+
-+#endif /* _IMQ_H */
-Index: linux-2.6.21.7/include/linux/netfilter_ipv4/ipt_IMQ.h
-===================================================================
---- /dev/null
-+++ linux-2.6.21.7/include/linux/netfilter_ipv4/ipt_IMQ.h
-@@ -0,0 +1,8 @@
-+#ifndef _IPT_IMQ_H
-+#define _IPT_IMQ_H
-+
-+struct ipt_imq_info {
-+ unsigned int todev; /* target imq device */
-+};
-+
-+#endif /* _IPT_IMQ_H */
-Index: linux-2.6.21.7/include/linux/netfilter_ipv6/ip6t_IMQ.h
-===================================================================
---- /dev/null
-+++ linux-2.6.21.7/include/linux/netfilter_ipv6/ip6t_IMQ.h
-@@ -0,0 +1,8 @@
-+#ifndef _IP6T_IMQ_H
-+#define _IP6T_IMQ_H
-+
-+struct ip6t_imq_info {
-+ unsigned int todev; /* target imq device */
-+};
-+
-+#endif /* _IP6T_IMQ_H */
-Index: linux-2.6.21.7/include/linux/skbuff.h
-===================================================================
---- linux-2.6.21.7.orig/include/linux/skbuff.h
-+++ linux-2.6.21.7/include/linux/skbuff.h
-@@ -294,6 +294,10 @@ struct sk_buff {
- #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
- struct sk_buff *nfct_reasm;
- #endif
-+#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
-+ unsigned char imq_flags;
-+ struct nf_info *nf_info;
-+#endif
- #ifdef CONFIG_BRIDGE_NETFILTER
- struct nf_bridge_info *nf_bridge;
- #endif
-Index: linux-2.6.21.7/net/core/dev.c
-===================================================================
---- linux-2.6.21.7.orig/net/core/dev.c
-+++ linux-2.6.21.7/net/core/dev.c
-@@ -94,6 +94,9 @@
- #include <linux/skbuff.h>
- #include <net/sock.h>
- #include <linux/rtnetlink.h>
-+#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
-+#include <linux/imq.h>
-+#endif
- #include <linux/proc_fs.h>
- #include <linux/seq_file.h>
- #include <linux/stat.h>
-@@ -1340,7 +1343,11 @@ static int dev_gso_segment(struct sk_buf
- int dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
- {
- if (likely(!skb->next)) {
-- if (netdev_nit)
-+ if (netdev_nit
-+#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
-+ && !(skb->imq_flags & IMQ_F_ENQUEUE)
-+#endif
-+ )
- dev_queue_xmit_nit(skb, dev);
-
- if (netif_needs_gso(dev, skb)) {
-Index: linux-2.6.21.7/net/core/skbuff.c
-===================================================================
---- linux-2.6.21.7.orig/net/core/skbuff.c
-+++ linux-2.6.21.7/net/core/skbuff.c
-@@ -430,6 +430,10 @@ struct sk_buff *skb_clone(struct sk_buff
- C(nfct_reasm);
- nf_conntrack_get_reasm(skb->nfct_reasm);
- #endif
-+#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
-+ C(imq_flags);
-+ C(nf_info);
-+#endif /*CONFIG_IMQ*/
- #ifdef CONFIG_BRIDGE_NETFILTER
- C(nf_bridge);
- nf_bridge_get(skb->nf_bridge);
-@@ -494,6 +498,10 @@ static void copy_skb_header(struct sk_bu
- #if defined(CONFIG_IP_VS) || defined(CONFIG_IP_VS_MODULE)
- new->ipvs_property = old->ipvs_property;
- #endif
-+#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
-+ new->imq_flags = old->imq_flags;
-+ new->nf_info = old->nf_info;
-+#endif /*CONFIG_IMQ*/
- #ifdef CONFIG_BRIDGE_NETFILTER
- new->nf_bridge = old->nf_bridge;
- nf_bridge_get(old->nf_bridge);
-Index: linux-2.6.21.7/net/ipv4/netfilter/ipt_IMQ.c
-===================================================================
---- /dev/null
-+++ linux-2.6.21.7/net/ipv4/netfilter/ipt_IMQ.c
-@@ -0,0 +1,69 @@
-+/*
-+ * This target marks packets to be enqueued to an imq device
-+ */
-+#include <linux/module.h>
-+#include <linux/skbuff.h>
-+#include <linux/netfilter_ipv4/ip_tables.h>
-+#include <linux/netfilter_ipv4/ipt_IMQ.h>
-+#include <linux/imq.h>
-+
-+static unsigned int imq_target(struct sk_buff **pskb,
-+ const struct net_device *in,
-+ const struct net_device *out,
-+ unsigned int hooknum,
-+ const struct xt_target *target,
-+ const void *targinfo)
-+{
-+ struct ipt_imq_info *mr = (struct ipt_imq_info*)targinfo;
-+
-+ (*pskb)->imq_flags = mr->todev | IMQ_F_ENQUEUE;
-+
-+ return XT_CONTINUE;
-+}
-+
-+static int imq_checkentry(const char *tablename,
-+ const void *e,
-+ const struct xt_target *target,
-+ void *targinfo,
-+ unsigned int hook_mask)
-+{
-+ struct ipt_imq_info *mr;
-+
-+ mr = (struct ipt_imq_info*)targinfo;
-+
-+ if (mr->todev > IMQ_MAX_DEVS) {
-+ printk(KERN_WARNING
-+ "IMQ: invalid device specified, highest is %u\n",
-+ IMQ_MAX_DEVS);
-+ return 0;
-+ }
-+
-+ return 1;
-+}
-+
-+static struct xt_target ipt_imq_reg = {
-+ .name = "IMQ",
-+ .family = AF_INET,
-+ .target = imq_target,
-+ .targetsize = sizeof(struct ipt_imq_info),
-+ .checkentry = imq_checkentry,
-+ .me = THIS_MODULE,
-+ .table = "mangle"
-+};
-+
-+static int __init init(void)
-+{
-+ return xt_register_target(&ipt_imq_reg);
-+}
-+
-+static void __exit fini(void)
-+{
-+ xt_unregister_target(&ipt_imq_reg);
-+}
-+
-+module_init(init);
-+module_exit(fini);
-+
-+MODULE_AUTHOR("http://www.linuximq.net");
-+MODULE_DESCRIPTION("Pseudo-driver for the intermediate queue device. See http://www.linuximq.net/ for more information.");
-+MODULE_LICENSE("GPL");
-Index: linux-2.6.21.7/net/ipv4/netfilter/Kconfig
-===================================================================
---- linux-2.6.21.7.orig/net/ipv4/netfilter/Kconfig
-+++ linux-2.6.21.7/net/ipv4/netfilter/Kconfig
-@@ -587,6 +587,17 @@ config IP_NF_MANGLE
-
- To compile it as a module, choose M here. If unsure, say N.
-
-+config IP_NF_TARGET_IMQ
-+ tristate "IMQ target support"
-+ depends on IP_NF_MANGLE
-+ help
-+ This option adds a `IMQ' target which is used to specify if and
-+ to which IMQ device packets should get enqueued/dequeued.
-+
-+ For more information visit: http://www.linuximq.net/
-+
-+ To compile it as a module, choose M here. If unsure, say N.
-+
- config IP_NF_TARGET_TOS
- tristate "TOS target support"
- depends on IP_NF_MANGLE
-Index: linux-2.6.21.7/net/ipv4/netfilter/Makefile
-===================================================================
---- linux-2.6.21.7.orig/net/ipv4/netfilter/Makefile
-+++ linux-2.6.21.7/net/ipv4/netfilter/Makefile
-@@ -99,6 +99,7 @@ obj-$(CONFIG_IP_NF_MATCH_IPP2P) += ipt_i
- obj-$(CONFIG_IP_NF_TARGET_REJECT) += ipt_REJECT.o
- obj-$(CONFIG_IP_NF_TARGET_TOS) += ipt_TOS.o
- obj-$(CONFIG_IP_NF_TARGET_ECN) += ipt_ECN.o
-+obj-$(CONFIG_IP_NF_TARGET_IMQ) += ipt_IMQ.o
- obj-$(CONFIG_IP_NF_TARGET_MASQUERADE) += ipt_MASQUERADE.o
- obj-$(CONFIG_IP_NF_TARGET_REDIRECT) += ipt_REDIRECT.o
- obj-$(CONFIG_IP_NF_TARGET_NETMAP) += ipt_NETMAP.o
-Index: linux-2.6.21.7/net/ipv6/netfilter/ip6t_IMQ.c
-===================================================================
---- /dev/null
-+++ linux-2.6.21.7/net/ipv6/netfilter/ip6t_IMQ.c
-@@ -0,0 +1,69 @@
-+/*
-+ * This target marks packets to be enqueued to an imq device
-+ */
-+#include <linux/module.h>
-+#include <linux/skbuff.h>
-+#include <linux/netfilter_ipv6/ip6_tables.h>
-+#include <linux/netfilter_ipv6/ip6t_IMQ.h>
-+#include <linux/imq.h>
-+
-+static unsigned int imq_target(struct sk_buff **pskb,
-+ const struct net_device *in,
-+ const struct net_device *out,
-+ unsigned int hooknum,
-+ const struct xt_target *target,
-+ const void *targinfo)
-+{
-+ struct ip6t_imq_info *mr = (struct ip6t_imq_info*)targinfo;
-+
-+ (*pskb)->imq_flags = mr->todev | IMQ_F_ENQUEUE;
-+
-+ return XT_CONTINUE;
-+}
-+
-+static int imq_checkentry(const char *tablename,
-+ const void *entry,
-+ const struct xt_target *target,
-+ void *targinfo,
-+ unsigned int hook_mask)
-+{
-+ struct ip6t_imq_info *mr;
-+
-+ mr = (struct ip6t_imq_info*)targinfo;
-+
-+ if (mr->todev > IMQ_MAX_DEVS) {
-+ printk(KERN_WARNING
-+ "IMQ: invalid device specified, highest is %u\n",
-+ IMQ_MAX_DEVS);
-+ return 0;
-+ }
-+
-+ return 1;
-+}
-+
-+static struct xt_target ip6t_imq_reg = {
-+ .name = "IMQ",
-+ .family = AF_INET6,
-+ .target = imq_target,
-+ .targetsize = sizeof(struct ip6t_imq_info),
-+ .table = "mangle",
-+ .checkentry = imq_checkentry,
-+ .me = THIS_MODULE
-+};
-+
-+static int __init init(void)
-+{
-+ return xt_register_target(&ip6t_imq_reg);
-+}
-+
-+static void __exit fini(void)
-+{
-+ xt_unregister_target(&ip6t_imq_reg);
-+}
-+
-+module_init(init);
-+module_exit(fini);
-+
-+MODULE_AUTHOR("http://www.linuximq.net");
-+MODULE_DESCRIPTION("Pseudo-driver for the intermediate queue device. See http://www.linuximq.net/ for more information.");
-+MODULE_LICENSE("GPL");
-Index: linux-2.6.21.7/net/ipv6/netfilter/Kconfig
-===================================================================
---- linux-2.6.21.7.orig/net/ipv6/netfilter/Kconfig
-+++ linux-2.6.21.7/net/ipv6/netfilter/Kconfig
-@@ -173,6 +173,15 @@ config IP6_NF_MANGLE
-
- To compile it as a module, choose M here. If unsure, say N.
-
-+config IP6_NF_TARGET_IMQ
-+ tristate "IMQ target support"
-+ depends on IP6_NF_MANGLE
-+ help
-+ This option adds a `IMQ' target which is used to specify if and
-+ to which imq device packets should get enqueued/dequeued.
-+
-+ To compile it as a module, choose M here. If unsure, say N.
-+
- config IP6_NF_TARGET_HL
- tristate 'HL (hoplimit) target support'
- depends on IP6_NF_MANGLE
-Index: linux-2.6.21.7/net/ipv6/netfilter/Makefile
-===================================================================
---- linux-2.6.21.7.orig/net/ipv6/netfilter/Makefile
-+++ linux-2.6.21.7/net/ipv6/netfilter/Makefile
-@@ -13,6 +13,7 @@ obj-$(CONFIG_IP6_NF_MATCH_EUI64) += ip6t
- obj-$(CONFIG_IP6_NF_MATCH_OWNER) += ip6t_owner.o
- obj-$(CONFIG_IP6_NF_FILTER) += ip6table_filter.o
- obj-$(CONFIG_IP6_NF_MANGLE) += ip6table_mangle.o
-+obj-$(CONFIG_IP6_NF_TARGET_IMQ) += ip6t_IMQ.o
- obj-$(CONFIG_IP6_NF_TARGET_HL) += ip6t_HL.o
- obj-$(CONFIG_IP6_NF_QUEUE) += ip6_queue.o
- obj-$(CONFIG_IP6_NF_TARGET_LOG) += ip6t_LOG.o
-Index: linux-2.6.21.7/net/sched/sch_generic.c
-===================================================================
---- linux-2.6.21.7.orig/net/sched/sch_generic.c
-+++ linux-2.6.21.7/net/sched/sch_generic.c
-@@ -87,7 +87,6 @@ void qdisc_unlock_tree(struct net_device
-
- NOTE: Called under dev->queue_lock with locally disabled BH.
- */
--
- static inline int qdisc_restart(struct net_device *dev)
- {
- struct Qdisc *q = dev->qdisc;
-@@ -181,6 +180,11 @@ requeue:
- return q->q.qlen;
- }
-
-+int qdisc_restart1(struct net_device *dev)
-+{
-+ return qdisc_restart(dev);
-+}
-+
- void __qdisc_run(struct net_device *dev)
- {
- if (unlikely(dev->qdisc == &noop_qdisc))
-@@ -617,3 +621,4 @@ EXPORT_SYMBOL(qdisc_destroy);
- EXPORT_SYMBOL(qdisc_reset);
- EXPORT_SYMBOL(qdisc_lock_tree);
- EXPORT_SYMBOL(qdisc_unlock_tree);
-+EXPORT_SYMBOL(qdisc_restart1);
+++ /dev/null
-Index: linux-2.6.21.7/include/linux/netfilter_ipv4/ipt_ROUTE.h
-===================================================================
---- /dev/null
-+++ linux-2.6.21.7/include/linux/netfilter_ipv4/ipt_ROUTE.h
-@@ -0,0 +1,23 @@
-+/* Header file for iptables ipt_ROUTE target
-+ *
-+ * (C) 2002 by Cédric de Launois <delaunois@info.ucl.ac.be>
-+ *
-+ * This software is distributed under GNU GPL v2, 1991
-+ */
-+#ifndef _IPT_ROUTE_H_target
-+#define _IPT_ROUTE_H_target
-+
-+#define IPT_ROUTE_IFNAMSIZ 16
-+
-+struct ipt_route_target_info {
-+ char oif[IPT_ROUTE_IFNAMSIZ]; /* Output Interface Name */
-+ char iif[IPT_ROUTE_IFNAMSIZ]; /* Input Interface Name */
-+ u_int32_t gw; /* IP address of gateway */
-+ u_int8_t flags;
-+};
-+
-+/* Values for "flags" field */
-+#define IPT_ROUTE_CONTINUE 0x01
-+#define IPT_ROUTE_TEE 0x02
-+
-+#endif /*_IPT_ROUTE_H_target*/
-Index: linux-2.6.21.7/include/linux/netfilter_ipv6/ip6t_ROUTE.h
-===================================================================
---- /dev/null
-+++ linux-2.6.21.7/include/linux/netfilter_ipv6/ip6t_ROUTE.h
-@@ -0,0 +1,23 @@
-+/* Header file for iptables ip6t_ROUTE target
-+ *
-+ * (C) 2003 by Cédric de Launois <delaunois@info.ucl.ac.be>
-+ *
-+ * This software is distributed under GNU GPL v2, 1991
-+ */
-+#ifndef _IPT_ROUTE_H_target
-+#define _IPT_ROUTE_H_target
-+
-+#define IP6T_ROUTE_IFNAMSIZ 16
-+
-+struct ip6t_route_target_info {
-+ char oif[IP6T_ROUTE_IFNAMSIZ]; /* Output Interface Name */
-+ char iif[IP6T_ROUTE_IFNAMSIZ]; /* Input Interface Name */
-+ u_int32_t gw[4]; /* IPv6 address of gateway */
-+ u_int8_t flags;
-+};
-+
-+/* Values for "flags" field */
-+#define IP6T_ROUTE_CONTINUE 0x01
-+#define IP6T_ROUTE_TEE 0x02
-+
-+#endif /*_IP6T_ROUTE_H_target*/
-Index: linux-2.6.21.7/net/ipv4/netfilter/ipt_ROUTE.c
-===================================================================
---- /dev/null
-+++ linux-2.6.21.7/net/ipv4/netfilter/ipt_ROUTE.c
-@@ -0,0 +1,483 @@
-+/*
-+ * This implements the ROUTE target, which enables you to setup unusual
-+ * routes not supported by the standard kernel routing table.
-+ *
-+ * Copyright (C) 2002 Cedric de Launois <delaunois@info.ucl.ac.be>
-+ *
-+ * v 1.11 2004/11/23
-+ *
-+ * This software is distributed under GNU GPL v2, 1991
-+ */
-+
-+#include <linux/module.h>
-+#include <linux/skbuff.h>
-+#include <linux/ip.h>
-+#include <linux/netfilter_ipv4/ip_tables.h>
-+#include <linux/netfilter_ipv4/ip_conntrack.h>
-+#include <linux/netfilter_ipv4/ipt_ROUTE.h>
-+#include <linux/netdevice.h>
-+#include <linux/route.h>
-+#include <linux/version.h>
-+#include <linux/if_arp.h>
-+#include <net/ip.h>
-+#include <net/route.h>
-+#include <net/icmp.h>
-+#include <net/checksum.h>
-+
-+#if 0
-+#define DEBUGP printk
-+#else
-+#define DEBUGP(format, args...)
-+#endif
-+
-+MODULE_LICENSE("GPL");
-+MODULE_AUTHOR("Cedric de Launois <delaunois@info.ucl.ac.be>");
-+MODULE_DESCRIPTION("iptables ROUTE target module");
-+
-+/* Try to route the packet according to the routing keys specified in
-+ * route_info. Keys are :
-+ * - ifindex :
-+ * 0 if no oif preferred,
-+ * otherwise set to the index of the desired oif
-+ * - route_info->gw :
-+ * 0 if no gateway specified,
-+ * otherwise set to the next host to which the pkt must be routed
-+ * If success, skb->dev is the output device to which the packet must
-+ * be sent and skb->dst is not NULL
-+ *
-+ * RETURN: -1 if an error occured
-+ * 1 if the packet was succesfully routed to the
-+ * destination desired
-+ * 0 if the kernel routing table could not route the packet
-+ * according to the keys specified
-+ */
-+static int route(struct sk_buff *skb,
-+ unsigned int ifindex,
-+ const struct ipt_route_target_info *route_info)
-+{
-+ int err;
-+ struct rtable *rt;
-+ struct iphdr *iph = skb->nh.iph;
-+ struct flowi fl = {
-+ .oif = ifindex,
-+ .nl_u = {
-+ .ip4_u = {
-+ .daddr = iph->daddr,
-+ .saddr = 0,
-+ .tos = RT_TOS(iph->tos),
-+ .scope = RT_SCOPE_UNIVERSE,
-+ }
-+ }
-+ };
-+
-+ /* The destination address may be overloaded by the target */
-+ if (route_info->gw)
-+ fl.fl4_dst = route_info->gw;
-+
-+ /* Trying to route the packet using the standard routing table. */
-+ if ((err = ip_route_output_key(&rt, &fl))) {
-+ if (net_ratelimit())
-+ DEBUGP("ipt_ROUTE: couldn't route pkt (err: %i)",err);
-+ return -1;
-+ }
-+
-+ /* Drop old route. */
-+ dst_release(skb->dst);
-+ skb->dst = NULL;
-+
-+ /* Success if no oif specified or if the oif correspond to the
-+ * one desired */
-+ if (!ifindex || rt->u.dst.dev->ifindex == ifindex) {
-+ skb->dst = &rt->u.dst;
-+ skb->dev = skb->dst->dev;
-+ skb->protocol = htons(ETH_P_IP);
-+ return 1;
-+ }
-+
-+ /* The interface selected by the routing table is not the one
-+ * specified by the user. This may happen because the dst address
-+ * is one of our own addresses.
-+ */
-+ if (net_ratelimit())
-+ DEBUGP("ipt_ROUTE: failed to route as desired gw=%u.%u.%u.%u oif=%i (got oif=%i)\n",
-+ NIPQUAD(route_info->gw), ifindex, rt->u.dst.dev->ifindex);
-+
-+ return 0;
-+}
-+
-+
-+/* Stolen from ip_finish_output2
-+ * PRE : skb->dev is set to the device we are leaving by
-+ * skb->dst is not NULL
-+ * POST: the packet is sent with the link layer header pushed
-+ * the packet is destroyed
-+ */
-+static void ip_direct_send(struct sk_buff *skb)
-+{
-+ struct dst_entry *dst = skb->dst;
-+ struct hh_cache *hh = dst->hh;
-+ struct net_device *dev = dst->dev;
-+ int hh_len = LL_RESERVED_SPACE(dev);
-+
-+ /* Be paranoid, rather than too clever. */
-+ if (unlikely(skb_headroom(skb) < hh_len && dev->hard_header)) {
-+ struct sk_buff *skb2;
-+
-+ skb2 = skb_realloc_headroom(skb, LL_RESERVED_SPACE(dev));
-+ if (skb2 == NULL) {
-+ kfree_skb(skb);
-+ return;
-+ }
-+ if (skb->sk)
-+ skb_set_owner_w(skb2, skb->sk);
-+ kfree_skb(skb);
-+ skb = skb2;
-+ }
-+
-+ if (hh) {
-+ int hh_alen;
-+
-+ read_lock_bh(&hh->hh_lock);
-+ hh_alen = HH_DATA_ALIGN(hh->hh_len);
-+ memcpy(skb->data - hh_alen, hh->hh_data, hh_alen);
-+ read_unlock_bh(&hh->hh_lock);
-+ skb_push(skb, hh->hh_len);
-+ hh->hh_output(skb);
-+ } else if (dst->neighbour)
-+ dst->neighbour->output(skb);
-+ else {
-+ if (net_ratelimit())
-+ DEBUGP(KERN_DEBUG "ipt_ROUTE: no hdr & no neighbour cache!\n");
-+ kfree_skb(skb);
-+ }
-+}
-+
-+
-+/* PRE : skb->dev is set to the device we are leaving by
-+ * POST: - the packet is directly sent to the skb->dev device, without
-+ * pushing the link layer header.
-+ * - the packet is destroyed
-+ */
-+static inline int dev_direct_send(struct sk_buff *skb)
-+{
-+ return dev_queue_xmit(skb);
-+}
-+
-+
-+static unsigned int route_oif(const struct ipt_route_target_info *route_info,
-+ struct sk_buff *skb)
-+{
-+ unsigned int ifindex = 0;
-+ struct net_device *dev_out = NULL;
-+
-+ /* The user set the interface name to use.
-+ * Getting the current interface index.
-+ */
-+ if ((dev_out = dev_get_by_name(route_info->oif))) {
-+ ifindex = dev_out->ifindex;
-+ } else {
-+ /* Unknown interface name : packet dropped */
-+ if (net_ratelimit())
-+ DEBUGP("ipt_ROUTE: oif interface %s not found\n", route_info->oif);
-+ return NF_DROP;
-+ }
-+
-+ /* Trying the standard way of routing packets */
-+ switch (route(skb, ifindex, route_info)) {
-+ case 1:
-+ dev_put(dev_out);
-+ if (route_info->flags & IPT_ROUTE_CONTINUE)
-+ return IPT_CONTINUE;
-+
-+ ip_direct_send(skb);
-+ return NF_STOLEN;
-+
-+ case 0:
-+ /* Failed to send to oif. Trying the hard way */
-+ if (route_info->flags & IPT_ROUTE_CONTINUE)
-+ return NF_DROP;
-+
-+ if (net_ratelimit())
-+ DEBUGP("ipt_ROUTE: forcing the use of %i\n",
-+ ifindex);
-+
-+ /* We have to force the use of an interface.
-+ * This interface must be a tunnel interface since
-+ * otherwise we can't guess the hw address for
-+ * the packet. For a tunnel interface, no hw address
-+ * is needed.
-+ */
-+ if ((dev_out->type != ARPHRD_TUNNEL)
-+ && (dev_out->type != ARPHRD_IPGRE)) {
-+ if (net_ratelimit())
-+ DEBUGP("ipt_ROUTE: can't guess the hw addr !\n");
-+ dev_put(dev_out);
-+ return NF_DROP;
-+ }
-+
-+ /* Send the packet. This will also free skb
-+ * Do not go through the POST_ROUTING hook because
-+ * skb->dst is not set and because it will probably
-+ * get confused by the destination IP address.
-+ */
-+ skb->dev = dev_out;
-+ dev_direct_send(skb);
-+ dev_put(dev_out);
-+ return NF_STOLEN;
-+
-+ default:
-+ /* Unexpected error */
-+ dev_put(dev_out);
-+ return NF_DROP;
-+ }
-+}
-+
-+
-+static unsigned int route_iif(const struct ipt_route_target_info *route_info,
-+ struct sk_buff *skb)
-+{
-+ struct net_device *dev_in = NULL;
-+
-+ /* Getting the current interface index. */
-+ if (!(dev_in = dev_get_by_name(route_info->iif))) {
-+ if (net_ratelimit())
-+ DEBUGP("ipt_ROUTE: iif interface %s not found\n", route_info->iif);
-+ return NF_DROP;
-+ }
-+
-+ skb->dev = dev_in;
-+ dst_release(skb->dst);
-+ skb->dst = NULL;
-+
-+ netif_rx(skb);
-+ dev_put(dev_in);
-+ return NF_STOLEN;
-+}
-+
-+
-+static unsigned int route_gw(const struct ipt_route_target_info *route_info,
-+ struct sk_buff *skb)
-+{
-+ if (route(skb, 0, route_info)!=1)
-+ return NF_DROP;
-+
-+ if (route_info->flags & IPT_ROUTE_CONTINUE)
-+ return IPT_CONTINUE;
-+
-+ ip_direct_send(skb);
-+ return NF_STOLEN;
-+}
-+
-+
-+/* To detect and deter routed packet loopback when using the --tee option,
-+ * we take a page out of the raw.patch book: on the copied skb, we set up
-+ * a fake ->nfct entry, pointing to the local &route_tee_track. We skip
-+ * routing packets when we see they already have that ->nfct.
-+ */
-+
-+static struct ip_conntrack route_tee_track;
-+
-+static unsigned int ipt_route_target(struct sk_buff **pskb,
-+ const struct net_device *in,
-+ const struct net_device *out,
-+ unsigned int hooknum,
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17)
-+ const struct xt_target *target,
-+#endif
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
-+ const void *targinfo,
-+ void *userinfo)
-+#else
-+ const void *targinfo)
-+#endif
-+{
-+ const struct ipt_route_target_info *route_info = targinfo;
-+ struct sk_buff *skb = *pskb;
-+ unsigned int res;
-+
-+ if (skb->nfct == &route_tee_track.ct_general) {
-+ /* Loopback - a packet we already routed, is to be
-+ * routed another time. Avoid that, now.
-+ */
-+ if (net_ratelimit())
-+ DEBUGP(KERN_DEBUG "ipt_ROUTE: loopback - DROP!\n");
-+ return NF_DROP;
-+ }
-+
-+ /* If we are at PREROUTING or INPUT hook
-+ * the TTL isn't decreased by the IP stack
-+ */
-+ if (hooknum == NF_IP_PRE_ROUTING ||
-+ hooknum == NF_IP_LOCAL_IN) {
-+
-+ struct iphdr *iph = skb->nh.iph;
-+
-+ if (iph->ttl <= 1) {
-+ struct rtable *rt;
-+ struct flowi fl = {
-+ .oif = 0,
-+ .nl_u = {
-+ .ip4_u = {
-+ .daddr = iph->daddr,
-+ .saddr = iph->saddr,
-+ .tos = RT_TOS(iph->tos),
-+ .scope = ((iph->tos & RTO_ONLINK) ?
-+ RT_SCOPE_LINK :
-+ RT_SCOPE_UNIVERSE)
-+ }
-+ }
-+ };
-+
-+ if (ip_route_output_key(&rt, &fl)) {
-+ return NF_DROP;
-+ }
-+
-+ if (skb->dev == rt->u.dst.dev) {
-+ /* Drop old route. */
-+ dst_release(skb->dst);
-+ skb->dst = &rt->u.dst;
-+
-+ /* this will traverse normal stack, and
-+ * thus call conntrack on the icmp packet */
-+ icmp_send(skb, ICMP_TIME_EXCEEDED,
-+ ICMP_EXC_TTL, 0);
-+ }
-+
-+ return NF_DROP;
-+ }
-+
-+ /*
-+ * If we are at INPUT the checksum must be recalculated since
-+ * the length could change as the result of a defragmentation.
-+ */
-+ if(hooknum == NF_IP_LOCAL_IN) {
-+ iph->ttl = iph->ttl - 1;
-+ iph->check = 0;
-+ iph->check = ip_fast_csum((unsigned char *)iph, iph->ihl);
-+ } else {
-+ ip_decrease_ttl(iph);
-+ }
-+ }
-+
-+ if ((route_info->flags & IPT_ROUTE_TEE)) {
-+ /*
-+ * Copy the *pskb, and route the copy. Will later return
-+ * IPT_CONTINUE for the original skb, which should continue
-+ * on its way as if nothing happened. The copy should be
-+ * independantly delivered to the ROUTE --gw.
-+ */
-+ skb = skb_copy(*pskb, GFP_ATOMIC);
-+ if (!skb) {
-+ if (net_ratelimit())
-+ DEBUGP(KERN_DEBUG "ipt_ROUTE: copy failed!\n");
-+ return IPT_CONTINUE;
-+ }
-+ }
-+
-+ /* Tell conntrack to forget this packet since it may get confused
-+ * when a packet is leaving with dst address == our address.
-+ * Good idea ? Dunno. Need advice.
-+ *
-+ * NEW: mark the skb with our &route_tee_track, so we avoid looping
-+ * on any already routed packet.
-+ */
-+ if (!(route_info->flags & IPT_ROUTE_CONTINUE)) {
-+ nf_conntrack_put(skb->nfct);
-+ skb->nfct = &route_tee_track.ct_general;
-+ skb->nfctinfo = IP_CT_NEW;
-+ nf_conntrack_get(skb->nfct);
-+ }
-+
-+ if (route_info->oif[0] != '\0') {
-+ res = route_oif(route_info, skb);
-+ } else if (route_info->iif[0] != '\0') {
-+ res = route_iif(route_info, skb);
-+ } else if (route_info->gw) {
-+ res = route_gw(route_info, skb);
-+ } else {
-+ if (net_ratelimit())
-+ DEBUGP(KERN_DEBUG "ipt_ROUTE: no parameter !\n");
-+ res = IPT_CONTINUE;
-+ }
-+
-+ if ((route_info->flags & IPT_ROUTE_TEE))
-+ res = IPT_CONTINUE;
-+
-+ return res;
-+}
-+
-+
-+static int ipt_route_checkentry(const char *tablename,
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ const void *e,
-+#else
-+ const struct ipt_ip *ip,
-+#endif
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17)
-+ const struct xt_target *target,
-+#endif
-+ void *targinfo,
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
-+ unsigned int targinfosize,
-+#endif
-+ unsigned int hook_mask)
-+{
-+ if (strcmp(tablename, "mangle") != 0) {
-+ printk("ipt_ROUTE: bad table `%s', use the `mangle' table.\n",
-+ tablename);
-+ return 0;
-+ }
-+
-+ if (hook_mask & ~( (1 << NF_IP_PRE_ROUTING)
-+ | (1 << NF_IP_LOCAL_IN)
-+ | (1 << NF_IP_FORWARD)
-+ | (1 << NF_IP_LOCAL_OUT)
-+ | (1 << NF_IP_POST_ROUTING))) {
-+ printk("ipt_ROUTE: bad hook\n");
-+ return 0;
-+ }
-+
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
-+ if (targinfosize != IPT_ALIGN(sizeof(struct ipt_route_target_info))) {
-+ printk(KERN_WARNING "ipt_ROUTE: targinfosize %u != %Zu\n",
-+ targinfosize,
-+ IPT_ALIGN(sizeof(struct ipt_route_target_info)));
-+ return 0;
-+ }
-+#endif
-+
-+ return 1;
-+}
-+
-+
-+static struct ipt_target ipt_route_reg = {
-+ .name = "ROUTE",
-+ .target = ipt_route_target,
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17)
-+ .targetsize = sizeof(struct ipt_route_target_info),
-+#endif
-+ .checkentry = ipt_route_checkentry,
-+ .me = THIS_MODULE,
-+};
-+
-+static int __init init(void)
-+{
-+ /* Set up fake conntrack (stolen from raw.patch):
-+ - to never be deleted, not in any hashes */
-+ atomic_set(&route_tee_track.ct_general.use, 1);
-+ /* - and look it like as a confirmed connection */
-+ set_bit(IPS_CONFIRMED_BIT, &route_tee_track.status);
-+ /* Initialize fake conntrack so that NAT will skip it */
-+ route_tee_track.status |= IPS_NAT_DONE_MASK;
-+
-+ return xt_register_target(&ipt_route_reg);
-+}
-+
-+
-+static void __exit fini(void)
-+{
-+ xt_unregister_target(&ipt_route_reg);
-+}
-+
-+module_init(init);
-+module_exit(fini);
-Index: linux-2.6.21.7/net/ipv4/netfilter/Kconfig
-===================================================================
---- linux-2.6.21.7.orig/net/ipv4/netfilter/Kconfig
-+++ linux-2.6.21.7/net/ipv4/netfilter/Kconfig
-@@ -807,5 +807,22 @@ config IP_NF_TARGET_SET
- To compile it as a module, choose M here. If unsure, say N.
-
-
-+config IP_NF_TARGET_ROUTE
-+ tristate 'ROUTE target support'
-+ depends on IP_NF_MANGLE
-+ help
-+ This option adds a `ROUTE' target, which enables you to setup unusual
-+ routes. For example, the ROUTE lets you route a received packet through
-+ an interface or towards a host, even if the regular destination of the
-+ packet is the router itself. The ROUTE target is also able to change the
-+ incoming interface of a packet.
-+
-+ The target can be or not a final target. It has to be used inside the
-+ mangle table.
-+
-+ If you want to compile it as a module, say M here and read
-+ Documentation/modules.txt. The module will be called ipt_ROUTE.o.
-+ If unsure, say `N'.
-+
- endmenu
-
-Index: linux-2.6.21.7/net/ipv4/netfilter/Makefile
-===================================================================
---- linux-2.6.21.7.orig/net/ipv4/netfilter/Makefile
-+++ linux-2.6.21.7/net/ipv4/netfilter/Makefile
-@@ -102,6 +102,7 @@ obj-$(CONFIG_IP_NF_TARGET_ECN) += ipt_EC
- obj-$(CONFIG_IP_NF_TARGET_IMQ) += ipt_IMQ.o
- obj-$(CONFIG_IP_NF_TARGET_MASQUERADE) += ipt_MASQUERADE.o
- obj-$(CONFIG_IP_NF_TARGET_REDIRECT) += ipt_REDIRECT.o
-+obj-$(CONFIG_IP_NF_TARGET_ROUTE) += ipt_ROUTE.o
- obj-$(CONFIG_IP_NF_TARGET_NETMAP) += ipt_NETMAP.o
- obj-$(CONFIG_IP_NF_TARGET_SAME) += ipt_SAME.o
- obj-$(CONFIG_IP_NF_NAT_SNMP_BASIC) += ip_nat_snmp_basic.o
-Index: linux-2.6.21.7/net/ipv6/ipv6_syms.c
-===================================================================
---- linux-2.6.21.7.orig/net/ipv6/ipv6_syms.c
-+++ linux-2.6.21.7/net/ipv6/ipv6_syms.c
-@@ -10,6 +10,7 @@ EXPORT_SYMBOL(icmpv6_send);
- EXPORT_SYMBOL(icmpv6_statistics);
- EXPORT_SYMBOL(icmpv6_err_convert);
- EXPORT_SYMBOL(ndisc_mc_map);
-+EXPORT_SYMBOL(nd_tbl);
- EXPORT_SYMBOL(register_inet6addr_notifier);
- EXPORT_SYMBOL(unregister_inet6addr_notifier);
- EXPORT_SYMBOL(ip6_route_output);
-Index: linux-2.6.21.7/net/ipv6/netfilter/ip6t_ROUTE.c
-===================================================================
---- /dev/null
-+++ linux-2.6.21.7/net/ipv6/netfilter/ip6t_ROUTE.c
-@@ -0,0 +1,330 @@
-+/*
-+ * This implements the ROUTE v6 target, which enables you to setup unusual
-+ * routes not supported by the standard kernel routing table.
-+ *
-+ * Copyright (C) 2003 Cedric de Launois <delaunois@info.ucl.ac.be>
-+ *
-+ * v 1.1 2004/11/23
-+ *
-+ * This software is distributed under GNU GPL v2, 1991
-+ */
-+
-+#include <linux/module.h>
-+#include <linux/skbuff.h>
-+#include <linux/ipv6.h>
-+#include <linux/netfilter_ipv6/ip6_tables.h>
-+#include <linux/netfilter_ipv6/ip6t_ROUTE.h>
-+#include <linux/netdevice.h>
-+#include <linux/version.h>
-+#include <net/ipv6.h>
-+#include <net/ndisc.h>
-+#include <net/ip6_route.h>
-+#include <linux/icmpv6.h>
-+
-+#if 1
-+#define DEBUGP printk
-+#else
-+#define DEBUGP(format, args...)
-+#endif
-+
-+#define NIP6(addr) \
-+ ntohs((addr).s6_addr16[0]), \
-+ ntohs((addr).s6_addr16[1]), \
-+ ntohs((addr).s6_addr16[2]), \
-+ ntohs((addr).s6_addr16[3]), \
-+ ntohs((addr).s6_addr16[4]), \
-+ ntohs((addr).s6_addr16[5]), \
-+ ntohs((addr).s6_addr16[6]), \
-+ ntohs((addr).s6_addr16[7])
-+
-+/* Route the packet according to the routing keys specified in
-+ * route_info. Keys are :
-+ * - ifindex :
-+ * 0 if no oif preferred,
-+ * otherwise set to the index of the desired oif
-+ * - route_info->gw :
-+ * 0 if no gateway specified,
-+ * otherwise set to the next host to which the pkt must be routed
-+ * If success, skb->dev is the output device to which the packet must
-+ * be sent and skb->dst is not NULL
-+ *
-+ * RETURN: 1 if the packet was succesfully routed to the
-+ * destination desired
-+ * 0 if the kernel routing table could not route the packet
-+ * according to the keys specified
-+ */
-+static int
-+route6(struct sk_buff *skb,
-+ unsigned int ifindex,
-+ const struct ip6t_route_target_info *route_info)
-+{
-+ struct rt6_info *rt = NULL;
-+ struct ipv6hdr *ipv6h = skb->nh.ipv6h;
-+ struct in6_addr *gw = (struct in6_addr*)&route_info->gw;
-+
-+ DEBUGP("ip6t_ROUTE: called with: ");
-+ DEBUGP("DST=%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x ", NIP6(ipv6h->daddr));
-+ DEBUGP("GATEWAY=%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x ", NIP6(*gw));
-+ DEBUGP("OUT=%s\n", route_info->oif);
-+
-+ if (ipv6_addr_any(gw))
-+ rt = rt6_lookup(&ipv6h->daddr, &ipv6h->saddr, ifindex, 1);
-+ else
-+ rt = rt6_lookup(gw, &ipv6h->saddr, ifindex, 1);
-+
-+ if (!rt)
-+ goto no_route;
-+
-+ DEBUGP("ip6t_ROUTE: routing gives: ");
-+ DEBUGP("DST=%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x ", NIP6(rt->rt6i_dst.addr));
-+ DEBUGP("GATEWAY=%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x ", NIP6(rt->rt6i_gateway));
-+ DEBUGP("OUT=%s\n", rt->rt6i_dev->name);
-+
-+ if (ifindex && rt->rt6i_dev->ifindex!=ifindex)
-+ goto wrong_route;
-+
-+ if (!rt->rt6i_nexthop) {
-+ DEBUGP("ip6t_ROUTE: discovering neighbour\n");
-+ rt->rt6i_nexthop = ndisc_get_neigh(rt->rt6i_dev, &rt->rt6i_dst.addr);
-+ }
-+
-+ /* Drop old route. */
-+ dst_release(skb->dst);
-+ skb->dst = &rt->u.dst;
-+ skb->dev = rt->rt6i_dev;
-+ return 1;
-+
-+ wrong_route:
-+ dst_release(&rt->u.dst);
-+ no_route:
-+ if (!net_ratelimit())
-+ return 0;
-+
-+ printk("ip6t_ROUTE: no explicit route found ");
-+ if (ifindex)
-+ printk("via interface %s ", route_info->oif);
-+ if (!ipv6_addr_any(gw))
-+ printk("via gateway %04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x", NIP6(*gw));
-+ printk("\n");
-+ return 0;
-+}
-+
-+
-+/* Stolen from ip6_output_finish
-+ * PRE : skb->dev is set to the device we are leaving by
-+ * skb->dst is not NULL
-+ * POST: the packet is sent with the link layer header pushed
-+ * the packet is destroyed
-+ */
-+static void ip_direct_send(struct sk_buff *skb)
-+{
-+ struct dst_entry *dst = skb->dst;
-+ struct hh_cache *hh = dst->hh;
-+
-+ if (hh) {
-+ read_lock_bh(&hh->hh_lock);
-+ memcpy(skb->data - 16, hh->hh_data, 16);
-+ read_unlock_bh(&hh->hh_lock);
-+ skb_push(skb, hh->hh_len);
-+ hh->hh_output(skb);
-+ } else if (dst->neighbour)
-+ dst->neighbour->output(skb);
-+ else {
-+ if (net_ratelimit())
-+ DEBUGP(KERN_DEBUG "ip6t_ROUTE: no hdr & no neighbour cache!\n");
-+ kfree_skb(skb);
-+ }
-+}
-+
-+
-+static unsigned int
-+route6_oif(const struct ip6t_route_target_info *route_info,
-+ struct sk_buff *skb)
-+{
-+ unsigned int ifindex = 0;
-+ struct net_device *dev_out = NULL;
-+
-+ /* The user set the interface name to use.
-+ * Getting the current interface index.
-+ */
-+ if ((dev_out = dev_get_by_name(route_info->oif))) {
-+ ifindex = dev_out->ifindex;
-+ } else {
-+ /* Unknown interface name : packet dropped */
-+ if (net_ratelimit())
-+ DEBUGP("ip6t_ROUTE: oif interface %s not found\n", route_info->oif);
-+
-+ if (route_info->flags & IP6T_ROUTE_CONTINUE)
-+ return IP6T_CONTINUE;
-+ else
-+ return NF_DROP;
-+ }
-+
-+ /* Trying the standard way of routing packets */
-+ if (route6(skb, ifindex, route_info)) {
-+ dev_put(dev_out);
-+ if (route_info->flags & IP6T_ROUTE_CONTINUE)
-+ return IP6T_CONTINUE;
-+
-+ ip_direct_send(skb);
-+ return NF_STOLEN;
-+ } else
-+ return NF_DROP;
-+}
-+
-+
-+static unsigned int
-+route6_gw(const struct ip6t_route_target_info *route_info,
-+ struct sk_buff *skb)
-+{
-+ if (route6(skb, 0, route_info)) {
-+ if (route_info->flags & IP6T_ROUTE_CONTINUE)
-+ return IP6T_CONTINUE;
-+
-+ ip_direct_send(skb);
-+ return NF_STOLEN;
-+ } else
-+ return NF_DROP;
-+}
-+
-+
-+static unsigned int
-+ip6t_route_target(struct sk_buff **pskb,
-+ const struct net_device *in,
-+ const struct net_device *out,
-+ unsigned int hooknum,
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17)
-+ const struct xt_target *target,
-+#endif
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
-+ const void *targinfo,
-+ void *userinfo)
-+#else
-+ const void *targinfo)
-+#endif
-+{
-+ const struct ip6t_route_target_info *route_info = targinfo;
-+ struct sk_buff *skb = *pskb;
-+ struct in6_addr *gw = (struct in6_addr*)&route_info->gw;
-+ unsigned int res;
-+
-+ if (route_info->flags & IP6T_ROUTE_CONTINUE)
-+ goto do_it;
-+
-+ /* If we are at PREROUTING or INPUT hook
-+ * the TTL isn't decreased by the IP stack
-+ */
-+ if (hooknum == NF_IP6_PRE_ROUTING ||
-+ hooknum == NF_IP6_LOCAL_IN) {
-+
-+ struct ipv6hdr *ipv6h = skb->nh.ipv6h;
-+
-+ if (ipv6h->hop_limit <= 1) {
-+ /* Force OUTPUT device used as source address */
-+ skb->dev = skb->dst->dev;
-+
-+ icmpv6_send(skb, ICMPV6_TIME_EXCEED,
-+ ICMPV6_EXC_HOPLIMIT, 0, skb->dev);
-+
-+ return NF_DROP;
-+ }
-+
-+ ipv6h->hop_limit--;
-+ }
-+
-+ if ((route_info->flags & IP6T_ROUTE_TEE)) {
-+ /*
-+ * Copy the *pskb, and route the copy. Will later return
-+ * IP6T_CONTINUE for the original skb, which should continue
-+ * on its way as if nothing happened. The copy should be
-+ * independantly delivered to the ROUTE --gw.
-+ */
-+ skb = skb_copy(*pskb, GFP_ATOMIC);
-+ if (!skb) {
-+ if (net_ratelimit())
-+ DEBUGP(KERN_DEBUG "ip6t_ROUTE: copy failed!\n");
-+ return IP6T_CONTINUE;
-+ }
-+ }
-+
-+do_it:
-+ if (route_info->oif[0]) {
-+ res = route6_oif(route_info, skb);
-+ } else if (!ipv6_addr_any(gw)) {
-+ res = route6_gw(route_info, skb);
-+ } else {
-+ if (net_ratelimit())
-+ DEBUGP(KERN_DEBUG "ip6t_ROUTE: no parameter !\n");
-+ res = IP6T_CONTINUE;
-+ }
-+
-+ if ((route_info->flags & IP6T_ROUTE_TEE))
-+ res = IP6T_CONTINUE;
-+
-+ return res;
-+}
-+
-+
-+static int
-+ip6t_route_checkentry(const char *tablename,
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ const void *entry,
-+#else
-+ const struct ip6t_entry *entry
-+#endif
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17)
-+ const struct xt_target *target,
-+#endif
-+ void *targinfo,
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
-+ unsigned int targinfosize,
-+#endif
-+ unsigned int hook_mask)
-+{
-+ if (strcmp(tablename, "mangle") != 0) {
-+ printk("ip6t_ROUTE: can only be called from \"mangle\" table.\n");
-+ return 0;
-+ }
-+
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
-+ if (targinfosize != IP6T_ALIGN(sizeof(struct ip6t_route_target_info))) {
-+ printk(KERN_WARNING "ip6t_ROUTE: targinfosize %u != %Zu\n",
-+ targinfosize,
-+ IP6T_ALIGN(sizeof(struct ip6t_route_target_info)));
-+ return 0;
-+ }
-+#endif
-+
-+ return 1;
-+}
-+
-+
-+static struct ip6t_target ip6t_route_reg = {
-+ .name = "ROUTE",
-+ .target = ip6t_route_target,
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17)
-+ .targetsize = sizeof(struct ip6t_route_target_info),
-+#endif
-+ .checkentry = ip6t_route_checkentry,
-+ .me = THIS_MODULE
-+};
-+
-+
-+static int __init init(void)
-+{
-+ printk(KERN_DEBUG "registering ipv6 ROUTE target\n");
-+ if (xt_register_target(&ip6t_route_reg))
-+ return -EINVAL;
-+
-+ return 0;
-+}
-+
-+
-+static void __exit fini(void)
-+{
-+ xt_unregister_target(&ip6t_route_reg);
-+}
-+
-+module_init(init);
-+module_exit(fini);
-+MODULE_LICENSE("GPL");
-Index: linux-2.6.21.7/net/ipv6/netfilter/Kconfig
-===================================================================
---- linux-2.6.21.7.orig/net/ipv6/netfilter/Kconfig
-+++ linux-2.6.21.7/net/ipv6/netfilter/Kconfig
-@@ -209,5 +209,18 @@ config IP6_NF_RAW
- If you want to compile it as a module, say M here and read
- <file:Documentation/modules.txt>. If unsure, say `N'.
-
-+config IP6_NF_TARGET_ROUTE
-+ tristate 'ROUTE target support'
-+ depends on IP6_NF_MANGLE
-+ help
-+ This option adds a `ROUTE' target, which enables you to setup unusual
-+ routes. The ROUTE target is also able to change the incoming interface
-+ of a packet.
-+
-+ The target can be or not a final target. It has to be used inside the
-+ mangle table.
-+
-+ Not working as a module.
-+
- endmenu
-
-Index: linux-2.6.21.7/net/ipv6/netfilter/Makefile
-===================================================================
---- linux-2.6.21.7.orig/net/ipv6/netfilter/Makefile
-+++ linux-2.6.21.7/net/ipv6/netfilter/Makefile
-@@ -20,6 +20,7 @@ obj-$(CONFIG_IP6_NF_TARGET_LOG) += ip6t_
- obj-$(CONFIG_IP6_NF_RAW) += ip6table_raw.o
- obj-$(CONFIG_IP6_NF_MATCH_HL) += ip6t_hl.o
- obj-$(CONFIG_IP6_NF_TARGET_REJECT) += ip6t_REJECT.o
-+obj-$(CONFIG_IP6_NF_TARGET_ROUTE) += ip6t_ROUTE.o
- obj-$(CONFIG_IP6_NF_MATCH_MH) += ip6t_mh.o
-
- # objects for l3 independent conntrack
+++ /dev/null
-Index: linux-2.6.21.7/include/linux/netfilter/oot_conntrack.h
-===================================================================
---- /dev/null
-+++ linux-2.6.21.7/include/linux/netfilter/oot_conntrack.h
-@@ -0,0 +1,5 @@
-+#if defined(CONFIG_IP_NF_CONNTRACK) || defined(CONFIG_IP_NF_CONNTRACK_MODULE)
-+# include <linux/netfilter_ipv4/ip_conntrack.h>
-+#else /* linux-2.6.20+ */
-+# include <net/netfilter/nf_nat_rule.h>
-+#endif
-Index: linux-2.6.21.7/include/linux/netfilter/oot_trans.h
-===================================================================
---- /dev/null
-+++ linux-2.6.21.7/include/linux/netfilter/oot_trans.h
-@@ -0,0 +1,14 @@
-+/* Out of tree workarounds */
-+#include <linux/version.h>
-+#if LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 18)
-+# define HAVE_MATCHINFOSIZE 1
-+# define HAVE_TARGUSERINFO 1
-+# define HAVE_TARGINFOSIZE 1
-+#endif
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 20)
-+# define nfmark mark
-+#endif
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 21)
-+# define tcp_v4_check(tcph, tcph_sz, s, d, csp) \
-+ tcp_v4_check((tcph_sz), (s), (d), (csp))
-+#endif
-Index: linux-2.6.21.7/include/linux/netfilter/xt_CHAOS.h
-===================================================================
---- /dev/null
-+++ linux-2.6.21.7/include/linux/netfilter/xt_CHAOS.h
-@@ -0,0 +1,14 @@
-+#ifndef _LINUX_NETFILTER_XT_CHAOS_H
-+#define _LINUX_NETFILTER_XT_CHAOS_H 1
-+
-+enum xt_chaos_target_variant {
-+ XTCHAOS_NORMAL,
-+ XTCHAOS_TARPIT,
-+ XTCHAOS_DELUDE,
-+};
-+
-+struct xt_chaos_target_info {
-+ uint8_t variant;
-+};
-+
-+#endif /* _LINUX_NETFILTER_XT_CHAOS_H */
-Index: linux-2.6.21.7/include/linux/netfilter/xt_portscan.h
-===================================================================
---- /dev/null
-+++ linux-2.6.21.7/include/linux/netfilter/xt_portscan.h
-@@ -0,0 +1,8 @@
-+#ifndef _LINUX_NETFILTER_XT_PORTSCAN_H
-+#define _LINUX_NETFILTER_XT_PORTSCAN_H 1
-+
-+struct xt_portscan_match_info {
-+ uint8_t match_stealth, match_syn, match_cn, match_gr;
-+};
-+
-+#endif /* _LINUX_NETFILTER_XT_PORTSCAN_H */
-Index: linux-2.6.21.7/net/netfilter/find_match.c
-===================================================================
---- /dev/null
-+++ linux-2.6.21.7/net/netfilter/find_match.c
-@@ -0,0 +1,39 @@
-+/*
-+ xt_request_find_match
-+ by Jan Engelhardt <jengelh [at] gmx de>, 2006 - 2007
-+
-+ Based upon linux-2.6.18.5/net/netfilter/x_tables.c:
-+ Copyright (C) 2006-2006 Harald Welte <laforge@netfilter.org>
-+ This program is free software; you can redistribute it and/or modify
-+ it under the terms of the GNU General Public License version 2 as
-+ published by the Free Software Foundation.
-+*/
-+#include <linux/err.h>
-+#include <linux/netfilter_arp.h>
-+#include <linux/socket.h>
-+#include <linux/netfilter/x_tables.h>
-+
-+/*
-+ * Yeah this code is sub-optimal, but the function is missing in
-+ * mainline so far. -jengelh
-+ */
-+static struct xt_match *xt_request_find_match_lo(int af, const char *name,
-+ u8 revision)
-+{
-+ static const char *const xt_prefix[] = {
-+ [AF_INET] = "ip",
-+ [AF_INET6] = "ip6",
-+ [NF_ARP] = "arp",
-+ };
-+ struct xt_match *match;
-+
-+ match = try_then_request_module(xt_find_match(af, name, revision),
-+ "%st_%s", xt_prefix[af], name);
-+ if (IS_ERR(match) || match == NULL)
-+ return NULL;
-+
-+ return match;
-+}
-+
-+/* In case it goes into mainline, let this out-of-tree package compile */
-+#define xt_request_find_match xt_request_find_match_lo
-Index: linux-2.6.21.7/net/netfilter/Kconfig
-===================================================================
---- linux-2.6.21.7.orig/net/netfilter/Kconfig
-+++ linux-2.6.21.7/net/netfilter/Kconfig
-@@ -287,6 +287,14 @@ config NETFILTER_XTABLES
-
- # alphabetically ordered list of targets
-
-+config NETFILTER_XT_TARGET_CHAOS
-+ tristate '"CHAOS" target support'
-+ depends on NETFILTER_XTABLES
-+ help
-+ This option adds a `CHAOS' target.
-+
-+ To compile it as a module, choose M here. If unsure, say N.
-+
- config NETFILTER_XT_TARGET_CLASSIFY
- tristate '"CLASSIFY" target support'
- depends on NETFILTER_XTABLES
-@@ -315,6 +323,14 @@ config NETFILTER_XT_TARGET_CONNMARK
- <file:Documentation/modules.txt>. The module will be called
- ipt_CONNMARK.o. If unsure, say `N'.
-
-+config NETFILTER_XT_TARGET_DELUDE
-+ tristate '"DELUDE" target support'
-+ depends on NETFILTER_XTABLES
-+ help
-+ This option adds a `DELUDE' target.
-+
-+ To compile it as a module, choose M here. If unsure, say N.
-+
- config NETFILTER_XT_TARGET_DSCP
- tristate '"DSCP" target support'
- depends on NETFILTER_XTABLES
-@@ -563,6 +579,14 @@ config NETFILTER_XT_MATCH_POLICY
-
- To compile it as a module, choose M here. If unsure, say N.
-
-+config NETFILTER_XT_MATCH_PORTSCAN
-+ tristate '"portscan" match support'
-+ depends on NETFILTER_XTABLES
-+ help
-+ This option adds a 'portscan' match support.
-+
-+ To compile it as a module, choose M here. If unsure, say N.
-+
- config NETFILTER_XT_MATCH_MULTIPORT
- tristate "Multiple port match support"
- depends on NETFILTER_XTABLES
-Index: linux-2.6.21.7/net/netfilter/Makefile
-===================================================================
---- linux-2.6.21.7.orig/net/netfilter/Makefile
-+++ linux-2.6.21.7/net/netfilter/Makefile
-@@ -47,6 +47,8 @@ obj-$(CONFIG_NETFILTER_XT_TARGET_NOTRACK
- obj-$(CONFIG_NETFILTER_XT_TARGET_SECMARK) += xt_SECMARK.o
- obj-$(CONFIG_NETFILTER_XT_TARGET_TCPMSS) += xt_TCPMSS.o
- obj-$(CONFIG_NETFILTER_XT_TARGET_CONNSECMARK) += xt_CONNSECMARK.o
-+obj-$(CONFIG_NETFILTER_XT_TARGET_CHAOS) += xt_CHAOS.o
-+obj-$(CONFIG_NETFILTER_XT_TARGET_DELUDE) += xt_DELUDE.o
-
- # matches
- obj-$(CONFIG_NETFILTER_XT_MATCH_COMMENT) += xt_comment.o
-@@ -74,3 +76,4 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_STRING)
- obj-$(CONFIG_NETFILTER_XT_MATCH_TCPMSS) += xt_tcpmss.o
- obj-$(CONFIG_NETFILTER_XT_MATCH_PHYSDEV) += xt_physdev.o
- obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
-+obj-$(CONFIG_NETFILTER_XT_MATCH_PORTSCAN) += xt_portscan.o
-Index: linux-2.6.21.7/net/netfilter/xt_CHAOS.c
-===================================================================
---- /dev/null
-+++ linux-2.6.21.7/net/netfilter/xt_CHAOS.c
-@@ -0,0 +1,200 @@
-+/*
-+ * CHAOS target for netfilter
-+ * Copyright © CC Computer Consultants GmbH, 2006 - 2007
-+ * Contact: Jan Engelhardt <jengelh@computergmbh.de>
-+ *
-+ * This program is free software; you can redistribute it and/or modify
-+ * it under the terms of the GNU General Public License; either version
-+ * 2 or 3 as published by the Free Software Foundation.
-+ */
-+#include <linux/icmp.h>
-+#include <linux/in.h>
-+#include <linux/ip.h>
-+#include <linux/module.h>
-+#include <linux/skbuff.h>
-+#include <linux/stat.h>
-+#include <linux/netfilter/x_tables.h>
-+#include <linux/netfilter/xt_tcpudp.h>
-+#include <linux/netfilter_ipv4/ipt_REJECT.h>
-+#include <net/ip.h>
-+#if defined(_LOCAL)
-+# include "xt_CHAOS.h"
-+# include "find_match.c"
-+#elif defined(CONFIG_NETFILTER_XT_TARGET_CHAOS) || \
-+ defined(CONFIG_NETFILTER_XT_TARGET_CHAOS_MODULE)
-+# include <linux/netfilter/xt_CHAOS.h>
-+# include "find_match.c"
-+#else
-+# include "xt_CHAOS.h"
-+# include "find_match.c"
-+#endif
-+#define PFX KBUILD_MODNAME ": "
-+
-+/* Module parameters */
-+static unsigned int reject_percentage = ~0U * .01;
-+static unsigned int delude_percentage = ~0U * .0101;
-+module_param(reject_percentage, uint, S_IRUGO | S_IWUSR);
-+module_param(delude_percentage, uint, S_IRUGO | S_IWUSR);
-+
-+/* References to other matches/targets */
-+static struct xt_match *xm_tcp;
-+static struct xt_target *xt_delude, *xt_reject, *xt_tarpit;
-+
-+static int have_delude, have_tarpit;
-+
-+/* Static data for other matches/targets */
-+static const struct ipt_reject_info reject_params = {
-+ .with = ICMP_HOST_UNREACH,
-+};
-+
-+static const struct xt_tcp tcp_params = {
-+ .spts = {0, ~0},
-+ .dpts = {0, ~0},
-+};
-+
-+/* CHAOS functions */
-+static void xt_chaos_total(const struct xt_chaos_target_info *info,
-+ struct sk_buff **pskb, const struct net_device *in,
-+ const struct net_device *out, unsigned int hooknum)
-+{
-+ const struct iphdr *iph = ip_hdr(*pskb);
-+ const int protoff = 4 * iph->ihl;
-+ const int offset = ntohs(iph->frag_off) & IP_OFFSET;
-+ const struct xt_target *destiny;
-+ int hotdrop = 0, ret;
-+
-+ ret = xm_tcp->match(*pskb, in, out, xm_tcp, &tcp_params,
-+ offset, protoff, &hotdrop);
-+ if (!ret || hotdrop || (unsigned int)net_random() > delude_percentage)
-+ return;
-+
-+ destiny = (info->variant == XTCHAOS_TARPIT) ? xt_tarpit : xt_delude;
-+ destiny->target(pskb, in, out, hooknum, destiny, NULL);
-+ return;
-+}
-+
-+static unsigned int chaos_tg(struct sk_buff **pskb,
-+ const struct net_device *in, const struct net_device *out,
-+ unsigned int hooknum, const struct xt_target *target, const void *targinfo)
-+{
-+ /*
-+ * Equivalent to:
-+ * -A chaos -m statistic --mode random --probability \
-+ * $reject_percentage -j REJECT --reject-with host-unreach;
-+ * -A chaos -p tcp -m statistic --mode random --probability \
-+ * $delude_percentage -j DELUDE;
-+ * -A chaos -j DROP;
-+ */
-+ const struct xt_chaos_target_info *info = targinfo;
-+ const struct iphdr *iph = ip_hdr(*pskb);
-+
-+ if ((unsigned int)net_random() <= reject_percentage)
-+ return xt_reject->target(pskb, in, out, hooknum, target,
-+ &reject_params);
-+
-+ /* TARPIT/DELUDE may not be called from the OUTPUT chain */
-+ if (iph->protocol == IPPROTO_TCP &&
-+ info->variant != XTCHAOS_NORMAL && hooknum != NF_IP_LOCAL_OUT)
-+ xt_chaos_total(info, pskb, in, out, hooknum);
-+
-+ return NF_DROP;
-+}
-+
-+static int chaos_tg_check(const char *tablename, const void *entry,
-+ const struct xt_target *target, void *targinfo, unsigned int hook_mask)
-+{
-+ const struct xt_chaos_target_info *info = targinfo;
-+
-+ if (info->variant == XTCHAOS_DELUDE && !have_delude) {
-+ printk(KERN_WARNING PFX "Error: Cannot use --delude when "
-+ "DELUDE module not available\n");
-+ return false;
-+ }
-+ if (info->variant == XTCHAOS_TARPIT && !have_tarpit) {
-+ printk(KERN_WARNING PFX "Error: Cannot use --tarpit when "
-+ "TARPIT module not available\n");
-+ return false;
-+ }
-+
-+ return true;
-+}
-+
-+static struct xt_target chaos_tg_reg = {
-+ .name = "CHAOS",
-+ .family = AF_INET,
-+ .table = "filter",
-+ .hooks = (1 << NF_IP_LOCAL_IN) | (1 << NF_IP_FORWARD) |
-+ (1 << NF_IP_LOCAL_OUT),
-+ .checkentry = chaos_tg_check,
-+ .target = chaos_tg,
-+ .targetsize = sizeof(struct xt_chaos_target_info),
-+ .me = THIS_MODULE,
-+};
-+
-+static int __init chaos_tg_init(void)
-+{
-+ int ret = -EINVAL;
-+
-+ xm_tcp = xt_request_find_match(AF_INET, "tcp", 0);
-+ if (xm_tcp == NULL) {
-+ printk(KERN_WARNING PFX "Error: Could not find or load "
-+ "\"tcp\" match\n");
-+ return -EINVAL;
-+ }
-+
-+ xt_reject = xt_request_find_target(AF_INET, "REJECT", 0);
-+ if (xt_reject == NULL) {
-+ printk(KERN_WARNING PFX "Error: Could not find or load "
-+ "\"REJECT\" target\n");
-+ goto out2;
-+ }
-+
-+ xt_tarpit = xt_request_find_target(AF_INET, "TARPIT", 0);
-+ have_tarpit = xt_tarpit != NULL;
-+ if (!have_tarpit)
-+ printk(KERN_WARNING PFX "Warning: Could not find or load "
-+ "\"TARPIT\" target\n");
-+
-+ xt_delude = xt_request_find_target(AF_INET, "DELUDE", 0);
-+ have_delude = xt_delude != NULL;
-+ if (!have_delude)
-+ printk(KERN_WARNING PFX "Warning: Could not find or load "
-+ "\"DELUDE\" target\n");
-+
-+ if ((ret = xt_register_target(&chaos_tg_reg)) != 0) {
-+ printk(KERN_WARNING PFX "xt_register_target returned "
-+ "error %d\n", ret);
-+ goto out3;
-+ }
-+
-+ return 0;
-+
-+ out3:
-+ if (have_delude)
-+ module_put(xt_delude->me);
-+ if (have_tarpit)
-+ module_put(xt_tarpit->me);
-+ module_put(xt_reject->me);
-+ out2:
-+ module_put(xm_tcp->me);
-+ return ret;
-+}
-+
-+static void __exit chaos_tg_exit(void)
-+{
-+ xt_unregister_target(&chaos_tg_reg);
-+ module_put(xm_tcp->me);
-+ module_put(xt_reject->me);
-+ if (have_delude)
-+ module_put(xt_delude->me);
-+ if (have_tarpit)
-+ module_put(xt_tarpit->me);
-+ return;
-+}
-+
-+module_init(chaos_tg_init);
-+module_exit(chaos_tg_exit);
-+MODULE_AUTHOR("Jan Engelhardt <jengelh@computergmbh.de>");
-+MODULE_DESCRIPTION("netfilter \"CHAOS\" target");
-+MODULE_LICENSE("GPL");
-+MODULE_ALIAS("ipt_CHAOS");
-Index: linux-2.6.21.7/net/netfilter/xt_DELUDE.c
-===================================================================
---- /dev/null
-+++ linux-2.6.21.7/net/netfilter/xt_DELUDE.c
-@@ -0,0 +1,197 @@
-+/*
-+ * DELUDE target
-+ * Copyright © CC Computer Consultants GmbH, 2007
-+ * Contact: Jan Engelhardt <jengelh@computergmbh.de>
-+ *
-+ * Based upon linux-2.6.18.5/net/ipv4/netfilter/ipt_REJECT.c:
-+ * (C) 1999-2001 Paul `Rusty' Russell
-+ * (C) 2002-2004 Netfilter Core Team <coreteam@netfilter.org>
-+ *
-+ * xt_DELUDE acts like REJECT, but does reply with SYN-ACK on SYN.
-+ *
-+ * This program is free software; you can redistribute it and/or modify
-+ * it under the terms of the GNU General Public License version 2 as
-+ * published by the Free Software Foundation.
-+ */
-+#include <linux/module.h>
-+#include <linux/skbuff.h>
-+#include <linux/ip.h>
-+#include <linux/tcp.h>
-+#include <linux/netfilter/x_tables.h>
-+#ifdef CONFIG_BRIDGE_NETFILTER
-+# include <linux/netfilter_bridge.h>
-+#endif
-+#include <net/tcp.h>
-+#define PFX KBUILD_MODNAME ": "
-+
-+static void delude_send_reset(struct sk_buff *oldskb, unsigned int hook)
-+{
-+ struct tcphdr _otcph, *oth, *tcph;
-+ unsigned int addr_type;
-+ struct sk_buff *nskb;
-+ u_int16_t tmp_port;
-+ u_int32_t tmp_addr;
-+ struct iphdr *niph;
-+ bool needs_ack;
-+
-+ /* IP header checks: fragment. */
-+ if (ip_hdr(oldskb)->frag_off & htons(IP_OFFSET))
-+ return;
-+
-+ oth = skb_header_pointer(oldskb, ip_hdrlen(oldskb),
-+ sizeof(_otcph), &_otcph);
-+ if (oth == NULL)
-+ return;
-+
-+ /* No RST for RST. */
-+ if (oth->rst)
-+ return;
-+
-+ /* Check checksum */
-+ if (nf_ip_checksum(oldskb, hook, ip_hdrlen(oldskb), IPPROTO_TCP))
-+ return;
-+
-+ /* We need a linear, writeable skb. We also need to expand
-+ headroom in case hh_len of incoming interface < hh_len of
-+ outgoing interface */
-+ nskb = skb_copy_expand(oldskb, LL_MAX_HEADER, skb_tailroom(oldskb),
-+ GFP_ATOMIC);
-+ if (!nskb)
-+ return;
-+
-+ /* This packet will not be the same as the other: clear nf fields */
-+ nf_reset(nskb);
-+ nskb->mark = 0;
-+ skb_init_secmark(nskb);
-+
-+ skb_shinfo(nskb)->gso_size = 0;
-+ skb_shinfo(nskb)->gso_segs = 0;
-+ skb_shinfo(nskb)->gso_type = 0;
-+
-+ tcph = (struct tcphdr *)(skb_network_header(nskb) + ip_hdrlen(nskb));
-+
-+ /* Swap source and dest */
-+ niph = ip_hdr(nskb);
-+ tmp_addr = niph->saddr;
-+ niph->saddr = niph->daddr;
-+ niph->daddr = tmp_addr;
-+ tmp_port = tcph->source;
-+ tcph->source = tcph->dest;
-+ tcph->dest = tmp_port;
-+
-+ /* Truncate to length (no data) */
-+ tcph->doff = sizeof(struct tcphdr) / 4;
-+ skb_trim(nskb, ip_hdrlen(nskb) + sizeof(struct tcphdr));
-+ niph->tot_len = htons(nskb->len);
-+
-+ if (oth->syn && !oth->ack && !oth->rst && !oth->fin) {
-+ /* DELUDE essential part */
-+ tcph->ack_seq = htonl(ntohl(oth->seq) + oth->syn + oth->fin +
-+ oldskb->len - ip_hdrlen(oldskb) -
-+ (oth->doff << 2));
-+ tcph->seq = false;
-+ tcph->ack = true;
-+ } else {
-+ if (!tcph->ack) {
-+ needs_ack = true;
-+ tcph->ack_seq = htonl(ntohl(oth->seq) + oth->syn +
-+ oth->fin + oldskb->len -
-+ ip_hdrlen(oldskb) - (oth->doff<<2));
-+ tcph->seq = false;
-+ } else {
-+ needs_ack = false;
-+ tcph->seq = oth->ack_seq;
-+ tcph->ack_seq = false;
-+ }
-+
-+ /* Reset flags */
-+ ((u_int8_t *)tcph)[13] = 0;
-+ tcph->rst = true;
-+ tcph->ack = needs_ack;
-+ }
-+
-+ tcph->window = 0;
-+ tcph->urg_ptr = 0;
-+
-+ /* Adjust TCP checksum */
-+ tcph->check = 0;
-+ tcph->check = tcp_v4_check(sizeof(struct tcphdr), niph->saddr,
-+ niph->daddr, csum_partial((char *)tcph,
-+ sizeof(struct tcphdr), 0));
-+
-+ /* Set DF, id = 0 */
-+ niph->frag_off = htons(IP_DF);
-+ niph->id = 0;
-+
-+ addr_type = RTN_UNSPEC;
-+#ifdef CONFIG_BRIDGE_NETFILTER
-+ if (hook != NF_IP_FORWARD || (nskb->nf_bridge != NULL &&
-+ nskb->nf_bridge->mask & BRNF_BRIDGED))
-+#else
-+ if (hook != NF_IP_FORWARD)
-+#endif
-+ addr_type = RTN_LOCAL;
-+
-+ if (ip_route_me_harder(&nskb, addr_type))
-+ goto free_nskb;
-+
-+ nskb->ip_summed = CHECKSUM_NONE;
-+
-+ /* Adjust IP TTL */
-+ niph->ttl = dst_metric(nskb->dst, RTAX_HOPLIMIT);
-+
-+ /* Adjust IP checksum */
-+ niph->check = 0;
-+ niph->check = ip_fast_csum(skb_network_header(nskb), niph->ihl);
-+
-+ /* "Never happens" */
-+ if (nskb->len > dst_mtu(nskb->dst))
-+ goto free_nskb;
-+
-+ nf_ct_attach(nskb, oldskb);
-+
-+ NF_HOOK(PF_INET, NF_IP_LOCAL_OUT, nskb, NULL, nskb->dst->dev,
-+ dst_output);
-+ return;
-+
-+ free_nskb:
-+ kfree_skb(nskb);
-+}
-+
-+static unsigned int delude_tg(struct sk_buff **pskb,
-+ const struct net_device *in, const struct net_device *out,
-+ unsigned int hooknum, const struct xt_target *target, const void *targinfo)
-+{
-+ /* WARNING: This code causes reentry within iptables.
-+ This means that the iptables jump stack is now crap. We
-+ must return an absolute verdict. --RR */
-+ delude_send_reset(*pskb, hooknum);
-+ return NF_DROP;
-+}
-+
-+static struct xt_target delude_tg_reg = {
-+ .name = "DELUDE",
-+ .family = AF_INET,
-+ .table = "filter",
-+ .hooks = (1 << NF_IP_LOCAL_IN) | (1 << NF_IP_FORWARD),
-+ .target = delude_tg,
-+ .proto = IPPROTO_TCP,
-+ .me = THIS_MODULE,
-+};
-+
-+static int __init delude_tg_init(void)
-+{
-+ return xt_register_target(&delude_tg_reg);
-+}
-+
-+static void __exit delude_tg_exit(void)
-+{
-+ xt_unregister_target(&delude_tg_reg);
-+}
-+
-+module_init(delude_tg_init);
-+module_exit(delude_tg_exit);
-+MODULE_AUTHOR("Jan Engelhardt <jengelh@computergmbh.de>");
-+MODULE_DESCRIPTION("netfilter \"DELUDE\" target");
-+MODULE_LICENSE("GPL");
-+MODULE_ALIAS("ipt_DELUDE");
-Index: linux-2.6.21.7/net/netfilter/xt_portscan.c
-===================================================================
---- /dev/null
-+++ linux-2.6.21.7/net/netfilter/xt_portscan.c
-@@ -0,0 +1,269 @@
-+/*
-+ * portscan match for netfilter
-+ * Copyright © CC Computer Consultants GmbH, 2006 - 2007
-+ * Contact: Jan Engelhardt <jengelh@computergmbh.de>
-+ *
-+ * This program is free software; you can redistribute it and/or modify
-+ * it under the terms of the GNU General Public License; either version
-+ * 2 or 3 as published by the Free Software Foundation.
-+ */
-+#include <linux/in.h>
-+#include <linux/ip.h>
-+#include <linux/module.h>
-+#include <linux/moduleparam.h>
-+#include <linux/skbuff.h>
-+#include <linux/stat.h>
-+#include <linux/tcp.h>
-+#include <linux/types.h>
-+#include <linux/version.h>
-+#include <linux/netfilter/x_tables.h>
-+#include <linux/netfilter/xt_tcpudp.h>
-+#include <net/netfilter/nf_nat_rule.h>
-+#if defined(_LOCAL)
-+# include "xt_portscan.h"
-+#elif defined(CONFIG_NETFILTER_XT_MATCH_PORTSCAN) || \
-+ defined(CONFIG_NETFILTER_XT_MATCH_PORTSCAN_MODULE)
-+# include <linux/netfilter/xt_portscan.h>
-+#else
-+# include "xt_portscan.h"
-+#endif
-+#define PFX KBUILD_MODNAME ": "
-+
-+enum {
-+ TCP_FLAGS_ALL3 = TCP_FLAG_FIN | TCP_FLAG_RST | TCP_FLAG_SYN,
-+ TCP_FLAGS_ALL4 = TCP_FLAGS_ALL3 | TCP_FLAG_ACK,
-+ TCP_FLAGS_ALL6 = TCP_FLAGS_ALL4 | TCP_FLAG_PSH | TCP_FLAG_URG,
-+};
-+
-+/* Module parameters */
-+static unsigned int
-+ connmark_mask = ~0,
-+ packet_mask = ~0,
-+ mark_seen = 0x9,
-+ mark_synrcv = 0x1,
-+ mark_closed = 0x2,
-+ mark_synscan = 0x3,
-+ mark_estab1 = 0x4,
-+ mark_estab2 = 0x5,
-+ mark_cnscan = 0x6,
-+ mark_grscan = 0x7,
-+ mark_valid = 0x8;
-+
-+module_param(connmark_mask, uint, S_IRUGO | S_IWUSR);
-+module_param(packet_mask, uint, S_IRUGO | S_IWUSR);
-+module_param(mark_seen, uint, S_IRUGO | S_IWUSR);
-+module_param(mark_synrcv, uint, S_IRUGO | S_IWUSR);
-+module_param(mark_closed, uint, S_IRUGO | S_IWUSR);
-+module_param(mark_synscan, uint, S_IRUGO | S_IWUSR);
-+module_param(mark_estab1, uint, S_IRUGO | S_IWUSR);
-+module_param(mark_estab2, uint, S_IRUGO | S_IWUSR);
-+module_param(mark_cnscan, uint, S_IRUGO | S_IWUSR);
-+module_param(mark_grscan, uint, S_IRUGO | S_IWUSR);
-+module_param(mark_valid, uint, S_IRUGO | S_IWUSR);
-+MODULE_PARM_DESC(connmark_mask, "only set specified bits in connection mark");
-+MODULE_PARM_DESC(packet_mask, "only set specified bits in packet mark");
-+MODULE_PARM_DESC(mark_seen, "nfmark value for packet-seen state");
-+MODULE_PARM_DESC(mark_synrcv, "connmark value for SYN Received state");
-+MODULE_PARM_DESC(mark_closed, "connmark value for closed state");
-+MODULE_PARM_DESC(mark_synscan, "connmark value for SYN Scan state");
-+MODULE_PARM_DESC(mark_estab1, "connmark value for Established-1 state");
-+MODULE_PARM_DESC(mark_estab2, "connmark value for Established-2 state");
-+MODULE_PARM_DESC(mark_cnscan, "connmark value for Connect Scan state");
-+MODULE_PARM_DESC(mark_grscan, "connmark value for Grab Scan state");
-+MODULE_PARM_DESC(mark_valid, "connmark value for Valid state");
-+
-+/* TCP flag functions */
-+static inline bool tflg_ack4(const struct tcphdr *th)
-+{
-+ return (tcp_flag_word(th) & TCP_FLAGS_ALL4) == TCP_FLAG_ACK;
-+}
-+
-+static inline bool tflg_ack6(const struct tcphdr *th)
-+{
-+ return (tcp_flag_word(th) & TCP_FLAGS_ALL6) == TCP_FLAG_ACK;
-+}
-+
-+static inline bool tflg_fin(const struct tcphdr *th)
-+{
-+ return (tcp_flag_word(th) & TCP_FLAGS_ALL3) == TCP_FLAG_FIN;
-+}
-+
-+static inline bool tflg_rst(const struct tcphdr *th)
-+{
-+ return (tcp_flag_word(th) & TCP_FLAGS_ALL3) == TCP_FLAG_RST;
-+}
-+
-+static inline bool tflg_rstack(const struct tcphdr *th)
-+{
-+ return (tcp_flag_word(th) & TCP_FLAGS_ALL4) ==
-+ (TCP_FLAG_ACK | TCP_FLAG_RST);
-+}
-+
-+static inline bool tflg_syn(const struct tcphdr *th)
-+{
-+ return (tcp_flag_word(th) & TCP_FLAGS_ALL4) == TCP_FLAG_SYN;
-+}
-+
-+static inline bool tflg_synack(const struct tcphdr *th)
-+{
-+ return (tcp_flag_word(th) & TCP_FLAGS_ALL4) ==
-+ (TCP_FLAG_SYN | TCP_FLAG_ACK);
-+}
-+
-+/* portscan functions */
-+static inline bool portscan_mt_stealth(const struct tcphdr *th)
-+{
-+ /*
-+ * "Connection refused" replies to our own probes must not be matched.
-+ */
-+ if (tflg_rstack(th))
-+ return false;
-+
-+ if (tflg_rst(th) && printk_ratelimit()) {
-+ printk(KERN_WARNING PFX "Warning: Pure RST received\n");
-+ return false;
-+ }
-+
-+ /*
-+ * -p tcp ! --syn -m conntrack --ctstate INVALID: Looking for non-start
-+ * packets that are not associated with any connection -- this will
-+ * match most scan types (NULL, XMAS, FIN) and ridiculous flag
-+ * combinations (SYN-RST, SYN-FIN, SYN-FIN-RST, FIN-RST, etc.).
-+ */
-+ return !tflg_syn(th);
-+}
-+
-+static inline unsigned int portscan_mt_full(int mark,
-+ enum ip_conntrack_info ctstate, bool loopback, const struct tcphdr *tcph,
-+ unsigned int payload_len)
-+{
-+ if (mark == mark_estab2) {
-+ /*
-+ * -m connmark --mark $ESTAB2
-+ */
-+ if (tflg_ack4(tcph) && payload_len == 0)
-+ return mark; /* keep mark */
-+ else if (tflg_rst(tcph) || tflg_fin(tcph))
-+ return mark_grscan;
-+ else
-+ return mark_valid;
-+ } else if (mark == mark_estab1) {
-+ /*
-+ * -m connmark --mark $ESTAB1
-+ */
-+ if (tflg_rst(tcph) || tflg_fin(tcph))
-+ return mark_cnscan;
-+ else if (!loopback && tflg_ack4(tcph) && payload_len == 0)
-+ return mark_estab2;
-+ else
-+ return mark_valid;
-+ } else if (mark == mark_synrcv) {
-+ /*
-+ * -m connmark --mark $SYN
-+ */
-+ if (loopback && tflg_synack(tcph))
-+ return mark; /* keep mark */
-+ else if (loopback && tflg_rstack(tcph))
-+ return mark_closed;
-+ else if (tflg_ack6(tcph))
-+ return mark_estab1;
-+ else
-+ return mark_synscan;
-+ } else if (ctstate == IP_CT_NEW && tflg_syn(tcph)) {
-+ /*
-+ * -p tcp --syn --ctstate NEW
-+ */
-+ return mark_synrcv;
-+ }
-+ return mark;
-+}
-+
-+static int portscan_mt(const struct sk_buff *skb,
-+ const struct net_device *in, const struct net_device *out,
-+ const struct xt_match *match, const void *matchinfo, int offset,
-+ unsigned int protoff, int *hotdrop)
-+{
-+ const struct xt_portscan_match_info *info = matchinfo;
-+ enum ip_conntrack_info ctstate;
-+ const struct tcphdr *tcph;
-+ struct nf_conn *ctdata;
-+ struct tcphdr tcph_buf;
-+
-+ tcph = skb_header_pointer(skb, protoff, sizeof(tcph_buf), &tcph_buf);
-+ if (tcph == NULL)
-+ return false;
-+
-+ /* Check for invalid packets: -m conntrack --ctstate INVALID */
-+ if ((ctdata = nf_ct_get(skb, &ctstate)) == NULL) {
-+ if (info->match_stealth)
-+ return portscan_mt_stealth(tcph);
-+ /*
-+ * If @ctdata is NULL, we cannot match the other scan
-+ * types, return.
-+ */
-+ return false;
-+ }
-+
-+ /*
-+ * If -m portscan was previously applied to this packet, the rules we
-+ * simulate must not be run through again. And for speedup, do not call
-+ * it either when the connection is already VALID.
-+ */
-+ if ((ctdata->mark & connmark_mask) == mark_valid ||
-+ (skb->mark & packet_mask) != mark_seen) {
-+ unsigned int n;
-+
-+ n = portscan_mt_full(ctdata->mark & connmark_mask, ctstate,
-+ in == &loopback_dev, tcph,
-+ skb->len - protoff - 4 * tcph->doff);
-+
-+ ctdata->mark = (ctdata->mark & ~connmark_mask) | n;
-+ ((struct sk_buff *)skb)->mark =
-+ (skb->mark & ~packet_mask) ^ mark_seen;
-+ }
-+
-+ return (info->match_syn && ctdata->mark == mark_synscan) ||
-+ (info->match_cn && ctdata->mark == mark_cnscan) ||
-+ (info->match_gr && ctdata->mark == mark_grscan);
-+}
-+
-+static int portscan_mt_check(const char *tablename, const void *entry,
-+ const struct xt_match *match, void *matchinfo, unsigned int hook_mask)
-+{
-+ const struct xt_portscan_match_info *info = matchinfo;
-+
-+ if ((info->match_stealth & ~1) || (info->match_syn & ~1) ||
-+ (info->match_cn & ~1) || (info->match_gr & ~1)) {
-+ printk(KERN_WARNING PFX "Invalid flags\n");
-+ return false;
-+ }
-+ return true;
-+}
-+
-+static struct xt_match portscan_mt_reg __read_mostly = {
-+ .name = "portscan",
-+ .family = AF_INET,
-+ .match = portscan_mt,
-+ .checkentry = portscan_mt_check,
-+ .matchsize = sizeof(struct xt_portscan_match_info),
-+ .proto = IPPROTO_TCP,
-+ .me = THIS_MODULE,
-+};
-+
-+static int __init portscan_mt_init(void)
-+{
-+ return xt_register_match(&portscan_mt_reg);
-+}
-+
-+static void __exit portscan_mt_exit(void)
-+{
-+ xt_unregister_match(&portscan_mt_reg);
-+ return;
-+}
-+
-+module_init(portscan_mt_init);
-+module_exit(portscan_mt_exit);
-+MODULE_AUTHOR("Jan Engelhardt <jengelh@computergmbh.de>");
-+MODULE_DESCRIPTION("netfilter \"portscan\" match");
-+MODULE_LICENSE("GPL");
-+MODULE_ALIAS("ipt_portscan");
+++ /dev/null
-Index: linux-2.6.21.7/net/netfilter/Kconfig
-===================================================================
---- linux-2.6.21.7.orig/net/netfilter/Kconfig
-+++ linux-2.6.21.7/net/netfilter/Kconfig
-@@ -414,6 +414,23 @@ config NETFILTER_XT_TARGET_CONNSECMARK
-
- To compile it as a module, choose M here. If unsure, say N.
-
-+config NETFILTER_XT_TARGET_TARPIT
-+ tristate '"TARPIT" target support'
-+ depends on NETFILTER_XTABLES
-+ ---help---
-+ Adds a TARPIT target to iptables, which captures and holds
-+ incoming TCP connections using no local per-connection resources.
-+ Connections are accepted, but immediately switched to the persist
-+ state (0 byte window), in which the remote side stops sending data
-+ and asks to continue every 60-240 seconds. Attempts to close the
-+ connection are ignored, forcing the remote side to time out the
-+ connection in 12-24 minutes.
-+
-+ This offers similar functionality to LaBrea
-+ <http://www.hackbusters.net/LaBrea/>, but does not require dedicated
-+ hardware or IPs. Any TCP port that you would normally DROP or REJECT
-+ can instead become a tarpit.
-+
- config NETFILTER_XT_TARGET_TCPMSS
- tristate '"TCPMSS" target support'
- depends on NETFILTER_XTABLES && (IPV6 || IPV6=n)
-Index: linux-2.6.21.7/net/netfilter/Makefile
-===================================================================
---- linux-2.6.21.7.orig/net/netfilter/Makefile
-+++ linux-2.6.21.7/net/netfilter/Makefile
-@@ -45,6 +45,7 @@ obj-$(CONFIG_NETFILTER_XT_TARGET_NFQUEUE
- obj-$(CONFIG_NETFILTER_XT_TARGET_NFLOG) += xt_NFLOG.o
- obj-$(CONFIG_NETFILTER_XT_TARGET_NOTRACK) += xt_NOTRACK.o
- obj-$(CONFIG_NETFILTER_XT_TARGET_SECMARK) += xt_SECMARK.o
-+obj-$(CONFIG_NETFILTER_XT_TARGET_TARPIT) += xt_TARPIT.o
- obj-$(CONFIG_NETFILTER_XT_TARGET_TCPMSS) += xt_TCPMSS.o
- obj-$(CONFIG_NETFILTER_XT_TARGET_CONNSECMARK) += xt_CONNSECMARK.o
- obj-$(CONFIG_NETFILTER_XT_TARGET_CHAOS) += xt_CHAOS.o
-Index: linux-2.6.21.7/net/netfilter/xt_TARPIT.c
-===================================================================
---- /dev/null
-+++ linux-2.6.21.7/net/netfilter/xt_TARPIT.c
-@@ -0,0 +1,280 @@
-+/*
-+ * Kernel module to capture and hold incoming TCP connections using
-+ * no local per-connection resources.
-+ *
-+ * Based on ipt_REJECT.c and offering functionality similar to
-+ * LaBrea <http://www.hackbusters.net/LaBrea/>.
-+ *
-+ * Copyright (c) 2002 Aaron Hopkins <tools@die.net>
-+ *
-+ * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
-+ *
-+ * Goal:
-+ * - Allow incoming TCP connections to be established.
-+ * - Passing data should result in the connection being switched to the
-+ * persist state (0 byte window), in which the remote side stops sending
-+ * data and asks to continue every 60 seconds.
-+ * - Attempts to shut down the connection should be ignored completely, so
-+ * the remote side ends up having to time it out.
-+ *
-+ * This means:
-+ * - Reply to TCP SYN,!ACK,!RST,!FIN with SYN-ACK, window 5 bytes
-+ * - Reply to TCP SYN,ACK,!RST,!FIN with RST to prevent spoofing
-+ * - Reply to TCP !SYN,!RST,!FIN with ACK, window 0 bytes, rate-limited
-+ */
-+
-+#include <linux/version.h>
-+#include <linux/module.h>
-+#include <linux/skbuff.h>
-+#include <linux/ip.h>
-+#include <net/ip.h>
-+#include <net/tcp.h>
-+#include <net/icmp.h>
-+struct in_device;
-+#include <net/route.h>
-+#include <linux/random.h>
-+#include <linux/netfilter_ipv4/ip_tables.h>
-+
-+#if 0
-+#define DEBUGP printk
-+#else
-+#define DEBUGP(format, args...)
-+#endif
-+
-+/* Stolen from ip_finish_output2 */
-+static int ip_direct_send(struct sk_buff *skb)
-+{
-+ struct dst_entry *dst = skb->dst;
-+
-+ if (dst->hh != NULL)
-+ return neigh_hh_output(dst->hh, skb);
-+ else if (dst->neighbour != NULL)
-+ return dst->neighbour->output(skb);
-+
-+ if (net_ratelimit())
-+ printk(KERN_DEBUG "TARPIT ip_direct_send: no header cache and no neighbor!\n");
-+
-+ kfree_skb(skb);
-+ return -EINVAL;
-+}
-+
-+
-+/* Send reply */
-+static void tarpit_tcp(const struct sk_buff *oskb, struct rtable *ort,
-+ unsigned int local)
-+{
-+ struct sk_buff *nskb;
-+ struct rtable *nrt;
-+ struct tcphdr *otcph, *ntcph;
-+ struct flowi fl = {};
-+ unsigned int otcplen;
-+ u_int16_t tmp;
-+
-+ const struct iphdr *oiph = ip_hdr(oskb);
-+ struct iphdr *niph;
-+
-+ /* A truncated TCP header is not going to be useful */
-+ if (oskb->len < ip_hdrlen(oskb) + sizeof(struct tcphdr))
-+ return;
-+
-+ otcph = (void *)oiph + ip_hdrlen(oskb);
-+ otcplen = oskb->len - ip_hdrlen(oskb);
-+
-+ /* No replies for RST or FIN */
-+ if (otcph->rst || otcph->fin)
-+ return;
-+
-+ /* No reply to !SYN,!ACK. Rate-limit replies to !SYN,ACKs */
-+ if (!otcph->syn && (!otcph->ack || !xrlim_allow(&ort->u.dst, 1*HZ)))
-+ return;
-+
-+ /* Check checksum. */
-+ if (tcp_v4_check(otcplen, oiph->saddr, oiph->daddr,
-+ csum_partial((char *)otcph, otcplen, 0)) != 0)
-+ return;
-+
-+ /*
-+ * Copy skb (even if skb is about to be dropped, we cannot just
-+ * clone it because there may be other things, such as tcpdump,
-+ * interested in it)
-+ */
-+ nskb = skb_copy(oskb, GFP_ATOMIC);
-+ if (nskb == NULL)
-+ return;
-+
-+ niph = ip_hdr(nskb);
-+
-+ /* This packet will not be the same as the other: clear nf fields */
-+ nf_conntrack_put(nskb->nfct);
-+ nskb->nfct = NULL;
-+#ifdef CONFIG_NETFILTER_DEBUG
-+ nskb->nf_debug = 0;
-+#endif
-+
-+ ntcph = (void *)niph + ip_hdrlen(nskb);
-+
-+ /* Truncate to length (no data) */
-+ ntcph->doff = sizeof(struct tcphdr)/4;
-+ skb_trim(nskb, ip_hdrlen(nskb) + sizeof(struct tcphdr));
-+ niph->tot_len = htons(nskb->len);
-+
-+ /* Swap source and dest */
-+ niph->daddr = xchg(&niph->saddr, niph->daddr);
-+ tmp = ntcph->source;
-+ ntcph->source = ntcph->dest;
-+ ntcph->dest = tmp;
-+
-+ /* Use supplied sequence number or make a new one */
-+ ntcph->seq = otcph->ack ? otcph->ack_seq
-+ : htonl(secure_tcp_sequence_number(niph->saddr,
-+ niph->daddr,
-+ ntcph->source,
-+ ntcph->dest));
-+
-+ /* Our SYN-ACKs must have a >0 window */
-+ ntcph->window = (otcph->syn && !otcph->ack) ? htons(5) : 0;
-+
-+ ntcph->urg_ptr = 0;
-+
-+ /* Reset flags */
-+ ((u_int8_t *)ntcph)[13] = 0;
-+
-+ if (otcph->syn && otcph->ack) {
-+ ntcph->rst = 1;
-+ ntcph->ack_seq = 0;
-+ } else {
-+ ntcph->syn = otcph->syn;
-+ ntcph->ack = 1;
-+ ntcph->ack_seq = htonl(ntohl(otcph->seq) + otcph->syn);
-+ }
-+
-+ /* Adjust TCP checksum */
-+ ntcph->check = 0;
-+ ntcph->check = tcp_v4_check(sizeof(struct tcphdr),
-+ niph->saddr,
-+ niph->daddr,
-+ csum_partial((char *)ntcph,
-+ sizeof(struct tcphdr), 0));
-+
-+ fl.nl_u.ip4_u.daddr = niph->daddr;
-+ fl.nl_u.ip4_u.saddr = local ? niph->saddr : 0;
-+ fl.nl_u.ip4_u.tos = RT_TOS(niph->tos) | RTO_CONN;
-+ fl.oif = 0;
-+
-+ if (ip_route_output_key(&nrt, &fl))
-+ goto free_nskb;
-+
-+ dst_release(nskb->dst);
-+ nskb->dst = &nrt->u.dst;
-+
-+ /* Adjust IP TTL */
-+ niph->ttl = dst_metric(nskb->dst, RTAX_HOPLIMIT);
-+
-+ /* Set DF, id = 0 */
-+ niph->frag_off = htons(IP_DF);
-+ niph->id = 0;
-+
-+ /* Adjust IP checksum */
-+ niph->check = 0;
-+ niph->check = ip_fast_csum((unsigned char *)niph, niph->ihl);
-+
-+ /* "Never happens" */
-+ if (nskb->len > dst_mtu(nskb->dst))
-+ goto free_nskb;
-+
-+ ip_direct_send(nskb);
-+ return;
-+
-+ free_nskb:
-+ kfree_skb(nskb);
-+}
-+
-+static unsigned int xt_tarpit_target(struct sk_buff **pskb,
-+ const struct net_device *in,
-+ const struct net_device *out,
-+ unsigned int hooknum,
-+ const struct xt_target *target,
-+ const void *targinfo)
-+{
-+ const struct sk_buff *skb = *pskb;
-+ const struct iphdr *iph = ip_hdr(skb);
-+ struct rtable *rt = (void *)skb->dst;
-+
-+ /* Do we have an input route cache entry? */
-+ if (rt == NULL)
-+ return NF_DROP;
-+
-+ /* No replies to physical multicast/broadcast */
-+ if (skb->pkt_type != PACKET_HOST && skb->pkt_type != PACKET_OTHERHOST)
-+ return NF_DROP;
-+
-+ /* Now check at the protocol level */
-+ if (rt->rt_flags & (RTCF_BROADCAST | RTCF_MULTICAST))
-+ return NF_DROP;
-+
-+ /*
-+ * Our naive response construction does not deal with IP
-+ * options, and probably should not try.
-+ */
-+ if (iph->ihl * 4 != sizeof(struct iphdr))
-+ return NF_DROP;
-+
-+ /* We are not interested in fragments */
-+ if (iph->frag_off & htons(IP_OFFSET))
-+ return NF_DROP;
-+
-+ tarpit_tcp(skb, rt, hooknum == NF_IP_LOCAL_IN);
-+ return NF_DROP;
-+}
-+
-+static int xt_tarpit_check(const char *tablename, const void *entry,
-+ const struct xt_target *target, void *targinfo,
-+ unsigned int hook_mask)
-+{
-+ bool invalid;
-+
-+ if (strcmp(tablename, "raw") == 0 && hook_mask == NF_IP_PRE_ROUTING)
-+ return true;
-+ if (strcmp(tablename, "filter") != 0)
-+ return false;
-+ invalid = hook_mask & ~((1 << NF_IP_LOCAL_IN) | (1 << NF_IP_FORWARD));
-+ return !invalid;
-+}
-+
-+static struct xt_target xt_tarpit_reg = {
-+ .name = "TARPIT",
-+ .family = AF_INET,
-+ .proto = IPPROTO_TCP,
-+ .target = xt_tarpit_target,
-+ .checkentry = xt_tarpit_check,
-+ .me = THIS_MODULE,
-+};
-+
-+static int __init xt_tarpit_init(void)
-+{
-+ return xt_register_target(&xt_tarpit_reg);
-+}
-+
-+static void __exit xt_tarpit_exit(void)
-+{
-+ xt_unregister_target(&xt_tarpit_reg);
-+}
-+
-+module_init(xt_tarpit_init);
-+module_exit(xt_tarpit_exit);
-+MODULE_DESCRIPTION("netfilter xt_TARPIT target module");
-+MODULE_AUTHOR("Jan Engelhardt <jengelh@gmx.de>");
-+MODULE_LICENSE("GPL");
-+MODULE_ALIAS("ipt_TARPIT");
+++ /dev/null
-Index: linux-2.6.21.7/net/netfilter/Kconfig
-===================================================================
---- linux-2.6.21.7.orig/net/netfilter/Kconfig
-+++ linux-2.6.21.7/net/netfilter/Kconfig
-@@ -165,7 +165,7 @@ config NF_CONNTRACK_FTP
-
- config NF_CONNTRACK_H323
- tristate "H.323 protocol support (EXPERIMENTAL)"
-- depends on EXPERIMENTAL && NF_CONNTRACK && (IPV6 || IPV6=n)
-+ depends on EXPERIMENTAL && NF_CONNTRACK
- help
- H.323 is a VoIP signalling protocol from ITU-T. As one of the most
- important VoIP protocols, it is widely used by voice hardware and
-@@ -433,7 +433,7 @@ config NETFILTER_XT_TARGET_TARPIT
-
- config NETFILTER_XT_TARGET_TCPMSS
- tristate '"TCPMSS" target support'
-- depends on NETFILTER_XTABLES && (IPV6 || IPV6=n)
-+ depends on NETFILTER_XTABLES
- ---help---
- This option adds a `TCPMSS' target, which allows you to alter the
- MSS value of TCP SYN packets, to control the maximum size for that
+++ /dev/null
-Index: linux-2.6.21.7/include/linux/pkt_sched.h
-===================================================================
---- linux-2.6.21.7.orig/include/linux/pkt_sched.h
-+++ linux-2.6.21.7/include/linux/pkt_sched.h
-@@ -146,8 +146,40 @@ struct tc_sfq_qopt
- *
- * The only reason for this is efficiency, it is possible
- * to change these parameters in compile time.
-+ *
-+ * If you need to play with these values use esfq instead.
- */
-
-+/* ESFQ section */
-+
-+enum
-+{
-+ /* traditional */
-+ TCA_SFQ_HASH_CLASSIC,
-+ TCA_SFQ_HASH_DST,
-+ TCA_SFQ_HASH_SRC,
-+ TCA_SFQ_HASH_FWMARK,
-+ /* direct */
-+ TCA_SFQ_HASH_DSTDIR,
-+ TCA_SFQ_HASH_SRCDIR,
-+ TCA_SFQ_HASH_FWMARKDIR,
-+ /* conntrack */
-+ TCA_SFQ_HASH_CTORIGDST,
-+ TCA_SFQ_HASH_CTORIGSRC,
-+ TCA_SFQ_HASH_CTREPLDST,
-+ TCA_SFQ_HASH_CTREPLSRC,
-+};
-+
-+struct tc_esfq_qopt
-+{
-+ unsigned quantum; /* Bytes per round allocated to flow */
-+ int perturb_period; /* Period of hash perturbation */
-+ __u32 limit; /* Maximal packets in queue */
-+ unsigned divisor; /* Hash divisor */
-+ unsigned flows; /* Maximal number of flows */
-+ unsigned hash_kind; /* Hash function to use for flow identification */
-+};
-+
- /* RED section */
-
- enum
-Index: linux-2.6.21.7/net/sched/Kconfig
-===================================================================
---- linux-2.6.21.7.orig/net/sched/Kconfig
-+++ linux-2.6.21.7/net/sched/Kconfig
-@@ -189,6 +189,26 @@ config NET_SCH_SFQ
- To compile this code as a module, choose M here: the
- module will be called sch_sfq.
-
-+config NET_SCH_ESFQ
-+ tristate "Enhanced Stochastic Fairness Queueing (ESFQ)"
-+ ---help---
-+ Say Y here if you want to use the Enhanced Stochastic Fairness
-+ Queueing (ESFQ) packet scheduling algorithm for some of your network
-+ devices or as a leaf discipline for a classful qdisc such as HTB or
-+ CBQ (see the top of <file:net/sched/sch_esfq.c> for details and
-+ references to the SFQ algorithm).
-+
-+ This is an enchanced SFQ version which allows you to control some
-+ hardcoded values in the SFQ scheduler.
-+
-+ ESFQ also adds control of the hash function used to identify packet
-+ flows. The original SFQ discipline hashes by connection; ESFQ add
-+ several other hashing methods, such as by src IP or by dst IP, which
-+ can be more fair to users in some networking situations.
-+
-+ To compile this code as a module, choose M here: the
-+ module will be called sch_esfq.
-+
- config NET_SCH_TEQL
- tristate "True Link Equalizer (TEQL)"
- ---help---
-Index: linux-2.6.21.7/net/sched/Makefile
-===================================================================
---- linux-2.6.21.7.orig/net/sched/Makefile
-+++ linux-2.6.21.7/net/sched/Makefile
-@@ -23,6 +23,7 @@ obj-$(CONFIG_NET_SCH_GRED) += sch_gred.o
- obj-$(CONFIG_NET_SCH_INGRESS) += sch_ingress.o
- obj-$(CONFIG_NET_SCH_DSMARK) += sch_dsmark.o
- obj-$(CONFIG_NET_SCH_SFQ) += sch_sfq.o
-+obj-$(CONFIG_NET_SCH_ESFQ) += sch_esfq.o
- obj-$(CONFIG_NET_SCH_TBF) += sch_tbf.o
- obj-$(CONFIG_NET_SCH_TEQL) += sch_teql.o
- obj-$(CONFIG_NET_SCH_PRIO) += sch_prio.o
-Index: linux-2.6.21.7/net/sched/sch_esfq.c
-===================================================================
---- /dev/null
-+++ linux-2.6.21.7/net/sched/sch_esfq.c
-@@ -0,0 +1,704 @@
-+/*
-+ * net/sched/sch_esfq.c Extended Stochastic Fairness Queueing discipline.
-+ *
-+ * 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.
-+ *
-+ * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
-+ *
-+ * Changes: Alexander Atanasov, <alex@ssi.bg>
-+ * Added dynamic depth,limit,divisor,hash_kind options.
-+ * Added dst and src hashes.
-+ *
-+ * Alexander Clouter, <alex@digriz.org.uk>
-+ * Ported ESFQ to Linux 2.6.
-+ *
-+ * Corey Hickey, <bugfood-c@fatooh.org>
-+ * Maintenance of the Linux 2.6 port.
-+ * Added fwmark hash (thanks to Robert Kurjata).
-+ * Added direct hashing for src, dst, and fwmark.
-+ * Added usage of jhash.
-+ *
-+ */
-+
-+#include <linux/module.h>
-+#include <asm/uaccess.h>
-+#include <asm/system.h>
-+#include <linux/bitops.h>
-+#include <linux/types.h>
-+#include <linux/kernel.h>
-+#include <linux/jiffies.h>
-+#include <linux/string.h>
-+#include <linux/mm.h>
-+#include <linux/socket.h>
-+#include <linux/sockios.h>
-+#include <linux/in.h>
-+#include <linux/errno.h>
-+#include <linux/interrupt.h>
-+#include <linux/if_ether.h>
-+#include <linux/inet.h>
-+#include <linux/netdevice.h>
-+#include <linux/etherdevice.h>
-+#include <linux/notifier.h>
-+#include <linux/init.h>
-+#include <net/ip.h>
-+#include <linux/ipv6.h>
-+#include <net/route.h>
-+#include <linux/skbuff.h>
-+#include <net/sock.h>
-+#include <net/pkt_sched.h>
-+#include <linux/jhash.h>
-+
-+#ifdef CONFIG_NF_CONNTRACK_ENABLED
-+#include <net/netfilter/nf_conntrack.h>
-+#endif
-+
-+/* Stochastic Fairness Queuing algorithm.
-+ For more comments look at sch_sfq.c.
-+ The difference is that you can change limit, depth,
-+ hash table size and choose alternate hash types.
-+
-+ classic: same as in sch_sfq.c
-+ dst: destination IP address
-+ src: source IP address
-+ fwmark: netfilter mark value
-+ dst_direct:
-+ src_direct:
-+ fwmark_direct: direct hashing of the above sources
-+ ctorigdst: original destination IP address
-+ ctorigsrc: original source IP address
-+ ctrepldst: reply destination IP address
-+ ctreplsrc: reply source IP
-+
-+*/
-+
-+
-+/* This type should contain at least SFQ_DEPTH*2 values */
-+typedef unsigned int esfq_index;
-+
-+struct esfq_head
-+{
-+ esfq_index next;
-+ esfq_index prev;
-+};
-+
-+struct esfq_sched_data
-+{
-+/* Parameters */
-+ int perturb_period;
-+ unsigned quantum; /* Allotment per round: MUST BE >= MTU */
-+ int limit;
-+ unsigned depth;
-+ unsigned hash_divisor;
-+ unsigned hash_kind;
-+/* Variables */
-+ struct timer_list perturb_timer;
-+ int perturbation;
-+ esfq_index tail; /* Index of current slot in round */
-+ esfq_index max_depth; /* Maximal depth */
-+
-+ esfq_index *ht; /* Hash table */
-+ esfq_index *next; /* Active slots link */
-+ short *allot; /* Current allotment per slot */
-+ unsigned short *hash; /* Hash value indexed by slots */
-+ struct sk_buff_head *qs; /* Slot queue */
-+ struct esfq_head *dep; /* Linked list of slots, indexed by depth */
-+ unsigned dyn_min; /* For dynamic divisor adjustment; minimum value seen */
-+ unsigned dyn_max; /* maximum value seen */
-+ unsigned dyn_range; /* saved range */
-+};
-+
-+/* This contains the info we will hash. */
-+struct esfq_packet_info
-+{
-+ u32 proto; /* protocol or port */
-+ u32 src; /* source from packet header */
-+ u32 dst; /* destination from packet header */
-+ u32 ctorigsrc; /* original source from conntrack */
-+ u32 ctorigdst; /* original destination from conntrack */
-+ u32 ctreplsrc; /* reply source from conntrack */
-+ u32 ctrepldst; /* reply destination from conntrack */
-+ u32 mark; /* netfilter mark (fwmark) */
-+};
-+
-+/* Hash input values directly into the "nearest" slot, taking into account the
-+ * range of input values seen. This is most useful when the hash table is at
-+ * least as large as the range of possible values.
-+ * Note: this functionality was added before the change to using jhash, and may
-+ * no longer be useful. */
-+static __inline__ unsigned esfq_hash_direct(struct esfq_sched_data *q, u32 h)
-+{
-+ /* adjust minimum and maximum */
-+ if (h < q->dyn_min || h > q->dyn_max) {
-+ q->dyn_min = h < q->dyn_min ? h : q->dyn_min;
-+ q->dyn_max = h > q->dyn_max ? h : q->dyn_max;
-+
-+ /* find new range */
-+ if ((q->dyn_range = q->dyn_max - q->dyn_min) >= q->hash_divisor)
-+ printk(KERN_WARNING "ESFQ: (direct hash) Input range %u is larger than hash "
-+ "table. See ESFQ README for details.\n", q->dyn_range);
-+ }
-+
-+ /* hash input values into slot numbers */
-+ if (q->dyn_min == q->dyn_max)
-+ return 0; /* only one value seen; avoid division by 0 */
-+ else
-+ return (h - q->dyn_min) * (q->hash_divisor - 1) / q->dyn_range;
-+}
-+
-+static __inline__ unsigned esfq_jhash_1word(struct esfq_sched_data *q,u32 a)
-+{
-+ return jhash_1word(a, q->perturbation) & (q->hash_divisor-1);
-+}
-+
-+static __inline__ unsigned esfq_jhash_2words(struct esfq_sched_data *q, u32 a, u32 b)
-+{
-+ return jhash_2words(a, b, q->perturbation) & (q->hash_divisor-1);
-+}
-+
-+static __inline__ unsigned esfq_jhash_3words(struct esfq_sched_data *q, u32 a, u32 b, u32 c)
-+{
-+ return jhash_3words(a, b, c, q->perturbation) & (q->hash_divisor-1);
-+}
-+
-+
-+static unsigned esfq_hash(struct esfq_sched_data *q, struct sk_buff *skb)
-+{
-+ struct esfq_packet_info info;
-+#ifdef CONFIG_NF_CONNTRACK_ENABLED
-+ enum ip_conntrack_info ctinfo;
-+ struct nf_conn *ct = nf_ct_get(skb, &ctinfo);
-+#endif
-+
-+ switch (skb->protocol) {
-+ case __constant_htons(ETH_P_IP):
-+ {
-+ struct iphdr *iph = skb->nh.iph;
-+ info.dst = iph->daddr;
-+ info.src = iph->saddr;
-+ if (!(iph->frag_off&htons(IP_MF|IP_OFFSET)) &&
-+ (iph->protocol == IPPROTO_TCP ||
-+ iph->protocol == IPPROTO_UDP ||
-+ iph->protocol == IPPROTO_SCTP ||
-+ iph->protocol == IPPROTO_DCCP ||
-+ iph->protocol == IPPROTO_ESP))
-+ info.proto = *(((u32*)iph) + iph->ihl);
-+ else
-+ info.proto = iph->protocol;
-+ break;
-+ }
-+ case __constant_htons(ETH_P_IPV6):
-+ {
-+ struct ipv6hdr *iph = skb->nh.ipv6h;
-+ /* Hash ipv6 addresses into a u32. This isn't ideal,
-+ * but the code is simple. */
-+ info.dst = jhash2(iph->daddr.s6_addr32, 4, q->perturbation);
-+ info.src = jhash2(iph->saddr.s6_addr32, 4, q->perturbation);
-+ if (iph->nexthdr == IPPROTO_TCP ||
-+ iph->nexthdr == IPPROTO_UDP ||
-+ iph->nexthdr == IPPROTO_SCTP ||
-+ iph->nexthdr == IPPROTO_DCCP ||
-+ iph->nexthdr == IPPROTO_ESP)
-+ info.proto = *(u32*)&iph[1];
-+ else
-+ info.proto = iph->nexthdr;
-+ break;
-+ }
-+ default:
-+ info.dst = (u32)(unsigned long)skb->dst;
-+ info.src = (u32)(unsigned long)skb->sk;
-+ info.proto = skb->protocol;
-+ }
-+
-+ info.mark = skb->mark;
-+
-+#ifdef CONFIG_NF_CONNTRACK_ENABLED
-+ /* defaults if there is no conntrack info */
-+ info.ctorigsrc = info.src;
-+ info.ctorigdst = info.dst;
-+ info.ctreplsrc = info.dst;
-+ info.ctrepldst = info.src;
-+ /* collect conntrack info */
-+ if (ct && ct != &nf_conntrack_untracked) {
-+ if (skb->protocol == __constant_htons(ETH_P_IP)) {
-+ info.ctorigsrc = ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.u3.ip;
-+ info.ctorigdst = ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.u3.ip;
-+ info.ctreplsrc = ct->tuplehash[IP_CT_DIR_REPLY].tuple.src.u3.ip;
-+ info.ctrepldst = ct->tuplehash[IP_CT_DIR_REPLY].tuple.dst.u3.ip;
-+ }
-+ else if (skb->protocol == __constant_htons(ETH_P_IPV6)) {
-+ /* Again, hash ipv6 addresses into a single u32. */
-+ info.ctorigsrc = jhash2(ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.u3.ip6, 4, q->perturbation);
-+ info.ctorigdst = jhash2(ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.u3.ip6, 4, q->perturbation);
-+ info.ctreplsrc = jhash2(ct->tuplehash[IP_CT_DIR_REPLY].tuple.src.u3.ip6, 4, q->perturbation);
-+ info.ctrepldst = jhash2(ct->tuplehash[IP_CT_DIR_REPLY].tuple.dst.u3.ip6, 4, q->perturbation);
-+ }
-+
-+ }
-+#endif
-+
-+ switch(q->hash_kind)
-+ {
-+ case TCA_SFQ_HASH_CLASSIC:
-+ return esfq_jhash_3words(q, info.dst, info.src, info.proto);
-+ case TCA_SFQ_HASH_DST:
-+ return esfq_jhash_1word(q, info.dst);
-+ case TCA_SFQ_HASH_DSTDIR:
-+ return esfq_hash_direct(q, ntohl(info.dst));
-+ case TCA_SFQ_HASH_SRC:
-+ return esfq_jhash_1word(q, info.src);
-+ case TCA_SFQ_HASH_SRCDIR:
-+ return esfq_hash_direct(q, ntohl(info.src));
-+ case TCA_SFQ_HASH_FWMARK:
-+ return esfq_jhash_1word(q, info.mark);
-+ case TCA_SFQ_HASH_FWMARKDIR:
-+ return esfq_hash_direct(q, info.mark);
-+#ifdef CONFIG_NF_CONNTRACK_ENABLED
-+ case TCA_SFQ_HASH_CTORIGDST:
-+ return esfq_jhash_1word(q, info.ctorigdst);
-+ case TCA_SFQ_HASH_CTORIGSRC:
-+ return esfq_jhash_1word(q, info.ctorigsrc);
-+ case TCA_SFQ_HASH_CTREPLDST:
-+ return esfq_jhash_1word(q, info.ctrepldst);
-+ case TCA_SFQ_HASH_CTREPLSRC:
-+ return esfq_jhash_1word(q, info.ctreplsrc);
-+#endif
-+ default:
-+ if (net_ratelimit())
-+ printk(KERN_WARNING "ESFQ: Unknown hash method. Falling back to classic.\n");
-+ }
-+ return esfq_jhash_3words(q, info.dst, info.src, info.proto);
-+}
-+
-+static inline void esfq_link(struct esfq_sched_data *q, esfq_index x)
-+{
-+ esfq_index p, n;
-+ int d = q->qs[x].qlen + q->depth;
-+
-+ p = d;
-+ n = q->dep[d].next;
-+ q->dep[x].next = n;
-+ q->dep[x].prev = p;
-+ q->dep[p].next = q->dep[n].prev = x;
-+}
-+
-+static inline void esfq_dec(struct esfq_sched_data *q, esfq_index x)
-+{
-+ esfq_index p, n;
-+
-+ n = q->dep[x].next;
-+ p = q->dep[x].prev;
-+ q->dep[p].next = n;
-+ q->dep[n].prev = p;
-+
-+ if (n == p && q->max_depth == q->qs[x].qlen + 1)
-+ q->max_depth--;
-+
-+ esfq_link(q, x);
-+}
-+
-+static inline void esfq_inc(struct esfq_sched_data *q, esfq_index x)
-+{
-+ esfq_index p, n;
-+ int d;
-+
-+ n = q->dep[x].next;
-+ p = q->dep[x].prev;
-+ q->dep[p].next = n;
-+ q->dep[n].prev = p;
-+ d = q->qs[x].qlen;
-+ if (q->max_depth < d)
-+ q->max_depth = d;
-+
-+ esfq_link(q, x);
-+}
-+
-+static unsigned int esfq_drop(struct Qdisc *sch)
-+{
-+ struct esfq_sched_data *q = qdisc_priv(sch);
-+ esfq_index d = q->max_depth;
-+ struct sk_buff *skb;
-+ unsigned int len;
-+
-+ /* Queue is full! Find the longest slot and
-+ drop a packet from it */
-+
-+ if (d > 1) {
-+ esfq_index x = q->dep[d+q->depth].next;
-+ skb = q->qs[x].prev;
-+ len = skb->len;
-+ __skb_unlink(skb, &q->qs[x]);
-+ kfree_skb(skb);
-+ esfq_dec(q, x);
-+ sch->q.qlen--;
-+ sch->qstats.drops++;
-+ sch->qstats.backlog -= len;
-+ return len;
-+ }
-+
-+ if (d == 1) {
-+ /* It is difficult to believe, but ALL THE SLOTS HAVE LENGTH 1. */
-+ d = q->next[q->tail];
-+ q->next[q->tail] = q->next[d];
-+ q->allot[q->next[d]] += q->quantum;
-+ skb = q->qs[d].prev;
-+ len = skb->len;
-+ __skb_unlink(skb, &q->qs[d]);
-+ kfree_skb(skb);
-+ esfq_dec(q, d);
-+ sch->q.qlen--;
-+ q->ht[q->hash[d]] = q->depth;
-+ sch->qstats.drops++;
-+ sch->qstats.backlog -= len;
-+ return len;
-+ }
-+
-+ return 0;
-+}
-+
-+static int
-+esfq_enqueue(struct sk_buff *skb, struct Qdisc* sch)
-+{
-+ struct esfq_sched_data *q = qdisc_priv(sch);
-+ unsigned hash = esfq_hash(q, skb);
-+ unsigned depth = q->depth;
-+ esfq_index x;
-+
-+ x = q->ht[hash];
-+ if (x == depth) {
-+ q->ht[hash] = x = q->dep[depth].next;
-+ q->hash[x] = hash;
-+ }
-+ sch->qstats.backlog += skb->len;
-+ __skb_queue_tail(&q->qs[x], skb);
-+ esfq_inc(q, x);
-+ if (q->qs[x].qlen == 1) { /* The flow is new */
-+ if (q->tail == depth) { /* It is the first flow */
-+ q->tail = x;
-+ q->next[x] = x;
-+ q->allot[x] = q->quantum;
-+ } else {
-+ q->next[x] = q->next[q->tail];
-+ q->next[q->tail] = x;
-+ q->tail = x;
-+ }
-+ }
-+ if (++sch->q.qlen < q->limit-1) {
-+ sch->bstats.bytes += skb->len;
-+ sch->bstats.packets++;
-+ return 0;
-+ }
-+
-+ esfq_drop(sch);
-+ return NET_XMIT_CN;
-+}
-+
-+static int
-+esfq_requeue(struct sk_buff *skb, struct Qdisc* sch)
-+{
-+ struct esfq_sched_data *q = qdisc_priv(sch);
-+ unsigned hash = esfq_hash(q, skb);
-+ unsigned depth = q->depth;
-+ esfq_index x;
-+
-+ x = q->ht[hash];
-+ if (x == depth) {
-+ q->ht[hash] = x = q->dep[depth].next;
-+ q->hash[x] = hash;
-+ }
-+ sch->qstats.backlog += skb->len;
-+ __skb_queue_head(&q->qs[x], skb);
-+ esfq_inc(q, x);
-+ if (q->qs[x].qlen == 1) { /* The flow is new */
-+ if (q->tail == depth) { /* It is the first flow */
-+ q->tail = x;
-+ q->next[x] = x;
-+ q->allot[x] = q->quantum;
-+ } else {
-+ q->next[x] = q->next[q->tail];
-+ q->next[q->tail] = x;
-+ q->tail = x;
-+ }
-+ }
-+ if (++sch->q.qlen < q->limit - 1) {
-+ sch->qstats.requeues++;
-+ return 0;
-+ }
-+
-+ sch->qstats.drops++;
-+ esfq_drop(sch);
-+ return NET_XMIT_CN;
-+}
-+
-+
-+
-+
-+static struct sk_buff *
-+esfq_dequeue(struct Qdisc* sch)
-+{
-+ struct esfq_sched_data *q = qdisc_priv(sch);
-+ struct sk_buff *skb;
-+ unsigned depth = q->depth;
-+ esfq_index a, old_a;
-+
-+ /* No active slots */
-+ if (q->tail == depth)
-+ return NULL;
-+
-+ a = old_a = q->next[q->tail];
-+
-+ /* Grab packet */
-+ skb = __skb_dequeue(&q->qs[a]);
-+ esfq_dec(q, a);
-+ sch->q.qlen--;
-+ sch->qstats.backlog -= skb->len;
-+
-+ /* Is the slot empty? */
-+ if (q->qs[a].qlen == 0) {
-+ q->ht[q->hash[a]] = depth;
-+ a = q->next[a];
-+ if (a == old_a) {
-+ q->tail = depth;
-+ return skb;
-+ }
-+ q->next[q->tail] = a;
-+ q->allot[a] += q->quantum;
-+ } else if ((q->allot[a] -= skb->len) <= 0) {
-+ q->tail = a;
-+ a = q->next[a];
-+ q->allot[a] += q->quantum;
-+ }
-+
-+ return skb;
-+}
-+
-+static void
-+esfq_reset(struct Qdisc* sch)
-+{
-+ struct sk_buff *skb;
-+
-+ while ((skb = esfq_dequeue(sch)) != NULL)
-+ kfree_skb(skb);
-+}
-+
-+static void esfq_perturbation(unsigned long arg)
-+{
-+ struct Qdisc *sch = (struct Qdisc*)arg;
-+ struct esfq_sched_data *q = qdisc_priv(sch);
-+
-+ q->perturbation = net_random()&0x1F;
-+
-+ if (q->perturb_period) {
-+ q->perturb_timer.expires = jiffies + q->perturb_period;
-+ add_timer(&q->perturb_timer);
-+ }
-+}
-+
-+static int esfq_change(struct Qdisc *sch, struct rtattr *opt)
-+{
-+ struct esfq_sched_data *q = qdisc_priv(sch);
-+ struct tc_esfq_qopt *ctl = RTA_DATA(opt);
-+ int old_perturb = q->perturb_period;
-+
-+ if (opt->rta_len < RTA_LENGTH(sizeof(*ctl)))
-+ return -EINVAL;
-+
-+ sch_tree_lock(sch);
-+ q->quantum = ctl->quantum ? : psched_mtu(sch->dev);
-+ q->perturb_period = ctl->perturb_period*HZ;
-+// q->hash_divisor = ctl->divisor;
-+// q->tail = q->limit = q->depth = ctl->flows;
-+
-+ if (ctl->limit)
-+ q->limit = min_t(u32, ctl->limit, q->depth);
-+
-+ if (ctl->hash_kind) {
-+ q->hash_kind = ctl->hash_kind;
-+ if (q->hash_kind != TCA_SFQ_HASH_CLASSIC)
-+ q->perturb_period = 0;
-+ }
-+
-+ // is sch_tree_lock enough to do this ?
-+ while (sch->q.qlen >= q->limit-1)
-+ esfq_drop(sch);
-+
-+ if (old_perturb)
-+ del_timer(&q->perturb_timer);
-+ if (q->perturb_period) {
-+ q->perturb_timer.expires = jiffies + q->perturb_period;
-+ add_timer(&q->perturb_timer);
-+ } else {
-+ q->perturbation = 0;
-+ }
-+ sch_tree_unlock(sch);
-+ return 0;
-+}
-+
-+static int esfq_init(struct Qdisc *sch, struct rtattr *opt)
-+{
-+ struct esfq_sched_data *q = qdisc_priv(sch);
-+ struct tc_esfq_qopt *ctl;
-+ esfq_index p = ~0U/2;
-+ int i;
-+
-+ if (opt && opt->rta_len < RTA_LENGTH(sizeof(*ctl)))
-+ return -EINVAL;
-+
-+ init_timer(&q->perturb_timer);
-+ q->perturb_timer.data = (unsigned long)sch;
-+ q->perturb_timer.function = esfq_perturbation;
-+ q->perturbation = 0;
-+ q->hash_kind = TCA_SFQ_HASH_CLASSIC;
-+ q->max_depth = 0;
-+ q->dyn_min = ~0U; /* maximum value for this type */
-+ q->dyn_max = 0; /* dyn_min/dyn_max will be set properly upon first packet */
-+ if (opt == NULL) {
-+ q->quantum = psched_mtu(sch->dev);
-+ q->perturb_period = 0;
-+ q->hash_divisor = 1024;
-+ q->tail = q->limit = q->depth = 128;
-+
-+ } else {
-+ ctl = RTA_DATA(opt);
-+ q->quantum = ctl->quantum ? : psched_mtu(sch->dev);
-+ q->perturb_period = ctl->perturb_period*HZ;
-+ q->hash_divisor = ctl->divisor ? : 1024;
-+ q->tail = q->limit = q->depth = ctl->flows ? : 128;
-+
-+ if ( q->depth > p - 1 )
-+ return -EINVAL;
-+
-+ if (ctl->limit)
-+ q->limit = min_t(u32, ctl->limit, q->depth);
-+
-+ if (ctl->hash_kind) {
-+ q->hash_kind = ctl->hash_kind;
-+ }
-+
-+ if (q->perturb_period) {
-+ q->perturb_timer.expires = jiffies + q->perturb_period;
-+ add_timer(&q->perturb_timer);
-+ }
-+ }
-+
-+ q->ht = kmalloc(q->hash_divisor*sizeof(esfq_index), GFP_KERNEL);
-+ if (!q->ht)
-+ goto err_case;
-+
-+ q->dep = kmalloc((1+q->depth*2)*sizeof(struct esfq_head), GFP_KERNEL);
-+ if (!q->dep)
-+ goto err_case;
-+ q->next = kmalloc(q->depth*sizeof(esfq_index), GFP_KERNEL);
-+ if (!q->next)
-+ goto err_case;
-+
-+ q->allot = kmalloc(q->depth*sizeof(short), GFP_KERNEL);
-+ if (!q->allot)
-+ goto err_case;
-+ q->hash = kmalloc(q->depth*sizeof(unsigned short), GFP_KERNEL);
-+ if (!q->hash)
-+ goto err_case;
-+ q->qs = kmalloc(q->depth*sizeof(struct sk_buff_head), GFP_KERNEL);
-+ if (!q->qs)
-+ goto err_case;
-+
-+ for (i=0; i< q->hash_divisor; i++)
-+ q->ht[i] = q->depth;
-+ for (i=0; i<q->depth; i++) {
-+ skb_queue_head_init(&q->qs[i]);
-+ q->dep[i+q->depth].next = i+q->depth;
-+ q->dep[i+q->depth].prev = i+q->depth;
-+ }
-+
-+ for (i=0; i<q->depth; i++)
-+ esfq_link(q, i);
-+ return 0;
-+err_case:
-+ del_timer(&q->perturb_timer);
-+ if (q->ht)
-+ kfree(q->ht);
-+ if (q->dep)
-+ kfree(q->dep);
-+ if (q->next)
-+ kfree(q->next);
-+ if (q->allot)
-+ kfree(q->allot);
-+ if (q->hash)
-+ kfree(q->hash);
-+ if (q->qs)
-+ kfree(q->qs);
-+ return -ENOBUFS;
-+}
-+
-+static void esfq_destroy(struct Qdisc *sch)
-+{
-+ struct esfq_sched_data *q = qdisc_priv(sch);
-+ del_timer(&q->perturb_timer);
-+ if(q->ht)
-+ kfree(q->ht);
-+ if(q->dep)
-+ kfree(q->dep);
-+ if(q->next)
-+ kfree(q->next);
-+ if(q->allot)
-+ kfree(q->allot);
-+ if(q->hash)
-+ kfree(q->hash);
-+ if(q->qs)
-+ kfree(q->qs);
-+}
-+
-+static int esfq_dump(struct Qdisc *sch, struct sk_buff *skb)
-+{
-+ struct esfq_sched_data *q = qdisc_priv(sch);
-+ unsigned char *b = skb->tail;
-+ struct tc_esfq_qopt opt;
-+
-+ opt.quantum = q->quantum;
-+ opt.perturb_period = q->perturb_period/HZ;
-+
-+ opt.limit = q->limit;
-+ opt.divisor = q->hash_divisor;
-+ opt.flows = q->depth;
-+ opt.hash_kind = q->hash_kind;
-+
-+ RTA_PUT(skb, TCA_OPTIONS, sizeof(opt), &opt);
-+
-+ return skb->len;
-+
-+rtattr_failure:
-+ skb_trim(skb, b - skb->data);
-+ return -1;
-+}
-+
-+static struct Qdisc_ops esfq_qdisc_ops =
-+{
-+ .next = NULL,
-+ .cl_ops = NULL,
-+ .id = "esfq",
-+ .priv_size = sizeof(struct esfq_sched_data),
-+ .enqueue = esfq_enqueue,
-+ .dequeue = esfq_dequeue,
-+ .requeue = esfq_requeue,
-+ .drop = esfq_drop,
-+ .init = esfq_init,
-+ .reset = esfq_reset,
-+ .destroy = esfq_destroy,
-+ .change = NULL, /* esfq_change - needs more work */
-+ .dump = esfq_dump,
-+ .owner = THIS_MODULE,
-+};
-+
-+static int __init esfq_module_init(void)
-+{
-+ return register_qdisc(&esfq_qdisc_ops);
-+}
-+static void __exit esfq_module_exit(void)
-+{
-+ unregister_qdisc(&esfq_qdisc_ops);
-+}
-+module_init(esfq_module_init)
-+module_exit(esfq_module_exit)
-+MODULE_LICENSE("GPL");
+++ /dev/null
-Index: linux-2.6.21.7/include/linux/netfilter_ipv4/ip_nat.h
-===================================================================
---- linux-2.6.21.7.orig/include/linux/netfilter_ipv4/ip_nat.h
-+++ linux-2.6.21.7/include/linux/netfilter_ipv4/ip_nat.h
-@@ -64,6 +64,13 @@ struct ip_nat_info
-
- struct ip_conntrack;
-
-+/* Call input routing for SNAT-ed traffic */
-+extern unsigned int ip_nat_route_input(unsigned int hooknum,
-+ struct sk_buff **pskb,
-+ const struct net_device *in,
-+ const struct net_device *out,
-+ int (*okfn)(struct sk_buff *));
-+
- /* Set up the info structure to map into this range. */
- extern unsigned int ip_nat_setup_info(struct ip_conntrack *conntrack,
- const struct ip_nat_range *range,
-Index: linux-2.6.21.7/include/linux/rtnetlink.h
-===================================================================
---- linux-2.6.21.7.orig/include/linux/rtnetlink.h
-+++ linux-2.6.21.7/include/linux/rtnetlink.h
-@@ -293,6 +293,8 @@ struct rtnexthop
- #define RTNH_F_DEAD 1 /* Nexthop is dead (used by multipath) */
- #define RTNH_F_PERVASIVE 2 /* Do recursive gateway lookup */
- #define RTNH_F_ONLINK 4 /* Gateway is forced on link */
-+#define RTNH_F_SUSPECT 8 /* We don't know the real state */
-+#define RTNH_F_BADSTATE (RTNH_F_DEAD | RTNH_F_SUSPECT)
-
- /* Macros to handle hexthops */
-
-Index: linux-2.6.21.7/include/net/flow.h
-===================================================================
---- linux-2.6.21.7.orig/include/net/flow.h
-+++ linux-2.6.21.7/include/net/flow.h
-@@ -19,6 +19,8 @@ struct flowi {
- struct {
- __be32 daddr;
- __be32 saddr;
-+ __u32 lsrc;
-+ __u32 gw;
- __u8 tos;
- __u8 scope;
- } ip4_u;
-@@ -43,6 +45,8 @@ struct flowi {
- #define fl6_flowlabel nl_u.ip6_u.flowlabel
- #define fl4_dst nl_u.ip4_u.daddr
- #define fl4_src nl_u.ip4_u.saddr
-+#define fl4_lsrc nl_u.ip4_u.lsrc
-+#define fl4_gw nl_u.ip4_u.gw
- #define fl4_tos nl_u.ip4_u.tos
- #define fl4_scope nl_u.ip4_u.scope
-
-Index: linux-2.6.21.7/net/ipv4/route.c
-===================================================================
---- linux-2.6.21.7.orig/net/ipv4/route.c
-+++ linux-2.6.21.7/net/ipv4/route.c
-@@ -1208,6 +1208,7 @@ void ip_rt_redirect(__be32 old_gw, __be3
-
- /* Gateway is different ... */
- rt->rt_gateway = new_gw;
-+ if (rt->fl.fl4_gw) rt->fl.fl4_gw = new_gw;
-
- /* Redirect received -> path was valid */
- dst_confirm(&rth->u.dst);
-@@ -1643,6 +1644,7 @@ static int ip_route_input_mc(struct sk_b
- rth->fl.fl4_tos = tos;
- rth->fl.mark = skb->mark;
- rth->fl.fl4_src = saddr;
-+ rth->fl.fl4_lsrc = 0;
- rth->rt_src = saddr;
- #ifdef CONFIG_NET_CLS_ROUTE
- rth->u.dst.tclassid = itag;
-@@ -1653,6 +1655,7 @@ static int ip_route_input_mc(struct sk_b
- dev_hold(rth->u.dst.dev);
- rth->idev = in_dev_get(rth->u.dst.dev);
- rth->fl.oif = 0;
-+ rth->fl.fl4_gw = 0;
- rth->rt_gateway = daddr;
- rth->rt_spec_dst= spec_dst;
- rth->rt_type = RTN_MULTICAST;
-@@ -1716,7 +1719,7 @@ static void ip_handle_martian_source(str
- static inline int __mkroute_input(struct sk_buff *skb,
- struct fib_result* res,
- struct in_device *in_dev,
-- __be32 daddr, __be32 saddr, u32 tos,
-+ __be32 daddr, __be32 saddr, u32 tos, u32 lsrc,
- struct rtable **result)
- {
-
-@@ -1751,6 +1754,7 @@ static inline int __mkroute_input(struct
- flags |= RTCF_DIRECTSRC;
-
- if (out_dev == in_dev && err && !(flags & (RTCF_NAT | RTCF_MASQ)) &&
-+ !lsrc &&
- (IN_DEV_SHARED_MEDIA(out_dev) ||
- inet_addr_onlink(out_dev, saddr, FIB_RES_GW(*res))))
- flags |= RTCF_DOREDIRECT;
-@@ -1788,6 +1792,7 @@ static inline int __mkroute_input(struct
- rth->fl.mark = skb->mark;
- rth->fl.fl4_src = saddr;
- rth->rt_src = saddr;
-+ rth->fl.fl4_lsrc = lsrc;
- rth->rt_gateway = daddr;
- rth->rt_iif =
- rth->fl.iif = in_dev->dev->ifindex;
-@@ -1795,6 +1800,7 @@ static inline int __mkroute_input(struct
- dev_hold(rth->u.dst.dev);
- rth->idev = in_dev_get(rth->u.dst.dev);
- rth->fl.oif = 0;
-+ rth->fl.fl4_gw = 0;
- rth->rt_spec_dst= spec_dst;
-
- rth->u.dst.input = ip_forward;
-@@ -1816,19 +1822,21 @@ static inline int ip_mkroute_input_def(s
- struct fib_result* res,
- const struct flowi *fl,
- struct in_device *in_dev,
-- __be32 daddr, __be32 saddr, u32 tos)
-+ __be32 daddr, __be32 saddr, u32 tos,
-+ u32 lsrc)
- {
- struct rtable* rth = NULL;
- int err;
- unsigned hash;
-
-+ fib_select_default(fl, res);
- #ifdef CONFIG_IP_ROUTE_MULTIPATH
-- if (res->fi && res->fi->fib_nhs > 1 && fl->oif == 0)
-+ if (res->fi && res->fi->fib_nhs > 1)
- fib_select_multipath(fl, res);
- #endif
-
- /* create a routing cache entry */
-- err = __mkroute_input(skb, res, in_dev, daddr, saddr, tos, &rth);
-+ err = __mkroute_input(skb, res, in_dev, daddr, saddr, tos, lsrc, &rth);
- if (err)
- return err;
-
-@@ -1841,7 +1849,8 @@ static inline int ip_mkroute_input(struc
- struct fib_result* res,
- const struct flowi *fl,
- struct in_device *in_dev,
-- __be32 daddr, __be32 saddr, u32 tos)
-+ __be32 daddr, __be32 saddr, u32 tos,
-+ u32 lsrc)
- {
- #ifdef CONFIG_IP_ROUTE_MULTIPATH_CACHED
- struct rtable* rth = NULL, *rtres;
-@@ -1857,7 +1866,7 @@ static inline int ip_mkroute_input(struc
- /* distinguish between multipath and singlepath */
- if (hopcount < 2)
- return ip_mkroute_input_def(skb, res, fl, in_dev, daddr,
-- saddr, tos);
-+ saddr, tos, 0);
-
- /* add all alternatives to the routing cache */
- for (hop = 0; hop < hopcount; hop++) {
-@@ -1869,7 +1878,7 @@ static inline int ip_mkroute_input(struc
-
- /* create a routing cache entry */
- err = __mkroute_input(skb, res, in_dev, daddr, saddr, tos,
-- &rth);
-+ 0, &rth);
- if (err)
- return err;
-
-@@ -1889,7 +1898,7 @@ static inline int ip_mkroute_input(struc
- skb->dst = &rtres->u.dst;
- return err;
- #else /* CONFIG_IP_ROUTE_MULTIPATH_CACHED */
-- return ip_mkroute_input_def(skb, res, fl, in_dev, daddr, saddr, tos);
-+ return ip_mkroute_input_def(skb, res, fl, in_dev, daddr, saddr, tos, lsrc);
- #endif /* CONFIG_IP_ROUTE_MULTIPATH_CACHED */
- }
-
-@@ -1905,18 +1914,18 @@ static inline int ip_mkroute_input(struc
- */
-
- static int ip_route_input_slow(struct sk_buff *skb, __be32 daddr, __be32 saddr,
-- u8 tos, struct net_device *dev)
-+ u8 tos, struct net_device *dev, u32 lsrc)
- {
- struct fib_result res;
- struct in_device *in_dev = in_dev_get(dev);
- struct flowi fl = { .nl_u = { .ip4_u =
- { .daddr = daddr,
-- .saddr = saddr,
-+ .saddr = lsrc ? : saddr,
- .tos = tos,
- .scope = RT_SCOPE_UNIVERSE,
- } },
- .mark = skb->mark,
-- .iif = dev->ifindex };
-+ .iif = lsrc? loopback_dev.ifindex : dev->ifindex };
- unsigned flags = 0;
- u32 itag = 0;
- struct rtable * rth;
-@@ -1949,6 +1958,12 @@ static int ip_route_input_slow(struct sk
- if (BADCLASS(daddr) || ZERONET(daddr) || LOOPBACK(daddr))
- goto martian_destination;
-
-+ if (lsrc) {
-+ if (MULTICAST(lsrc) || BADCLASS(lsrc) ||
-+ ZERONET(lsrc) || LOOPBACK(lsrc))
-+ goto e_inval;
-+ }
-+
- /*
- * Now we are ready to route packet.
- */
-@@ -1958,6 +1973,10 @@ static int ip_route_input_slow(struct sk
- goto no_route;
- }
- free_res = 1;
-+ if (lsrc && res.type != RTN_UNICAST && res.type != RTN_NAT)
-+ goto e_inval;
-+ fl.iif = dev->ifindex;
-+ fl.fl4_src = saddr;
-
- RT_CACHE_STAT_INC(in_slow_tot);
-
-@@ -1982,7 +2001,7 @@ static int ip_route_input_slow(struct sk
- if (res.type != RTN_UNICAST)
- goto martian_destination;
-
-- err = ip_mkroute_input(skb, &res, &fl, in_dev, daddr, saddr, tos);
-+ err = ip_mkroute_input(skb, &res, &fl, in_dev, daddr, saddr, tos, lsrc);
- if (err == -ENOBUFS)
- goto e_nobufs;
- if (err == -EINVAL)
-@@ -1997,6 +2016,8 @@ out: return err;
- brd_input:
- if (skb->protocol != htons(ETH_P_IP))
- goto e_inval;
-+ if (lsrc)
-+ goto e_inval;
-
- if (ZERONET(saddr))
- spec_dst = inet_select_addr(dev, 0, RT_SCOPE_LINK);
-@@ -2037,6 +2058,7 @@ local_input:
- rth->u.dst.dev = &loopback_dev;
- dev_hold(rth->u.dst.dev);
- rth->idev = in_dev_get(rth->u.dst.dev);
-+ rth->fl.fl4_gw = 0;
- rth->rt_gateway = daddr;
- rth->rt_spec_dst= spec_dst;
- rth->u.dst.input= ip_local_deliver;
-@@ -2086,8 +2108,9 @@ martian_source:
- goto e_inval;
- }
-
--int ip_route_input(struct sk_buff *skb, __be32 daddr, __be32 saddr,
-- u8 tos, struct net_device *dev)
-+static inline int
-+ip_route_input_cached(struct sk_buff *skb, __be32 daddr, __be32 saddr,
-+ u8 tos, struct net_device *dev, u32 lsrc)
- {
- struct rtable * rth;
- unsigned hash;
-@@ -2102,6 +2125,7 @@ int ip_route_input(struct sk_buff *skb,
- if (rth->fl.fl4_dst == daddr &&
- rth->fl.fl4_src == saddr &&
- rth->fl.iif == iif &&
-+ rth->fl.fl4_lsrc == lsrc &&
- rth->fl.oif == 0 &&
- rth->fl.mark == skb->mark &&
- rth->fl.fl4_tos == tos) {
-@@ -2148,7 +2172,19 @@ int ip_route_input(struct sk_buff *skb,
- rcu_read_unlock();
- return -EINVAL;
- }
-- return ip_route_input_slow(skb, daddr, saddr, tos, dev);
-+ return ip_route_input_slow(skb, daddr, saddr, tos, dev, lsrc);
-+}
-+
-+int ip_route_input(struct sk_buff *skb, u32 daddr, u32 saddr,
-+ u8 tos, struct net_device *dev)
-+{
-+ return ip_route_input_cached(skb, daddr, saddr, tos, dev, 0);
-+}
-+
-+int ip_route_input_lookup(struct sk_buff *skb, u32 daddr, u32 saddr,
-+ u8 tos, struct net_device *dev, u32 lsrc)
-+{
-+ return ip_route_input_cached(skb, daddr, saddr, tos, dev, lsrc);
- }
-
- static inline int __mkroute_output(struct rtable **result,
-@@ -2227,6 +2263,7 @@ static inline int __mkroute_output(struc
- rth->fl.fl4_tos = tos;
- rth->fl.fl4_src = oldflp->fl4_src;
- rth->fl.oif = oldflp->oif;
-+ rth->fl.fl4_gw = oldflp->fl4_gw;
- rth->fl.mark = oldflp->mark;
- rth->rt_dst = fl->fl4_dst;
- rth->rt_src = fl->fl4_src;
-@@ -2367,6 +2404,7 @@ static int ip_route_output_slow(struct r
- struct flowi fl = { .nl_u = { .ip4_u =
- { .daddr = oldflp->fl4_dst,
- .saddr = oldflp->fl4_src,
-+ .gw = oldflp->fl4_gw,
- .tos = tos & IPTOS_RT_MASK,
- .scope = ((tos & RTO_ONLINK) ?
- RT_SCOPE_LINK :
-@@ -2470,6 +2508,7 @@ static int ip_route_output_slow(struct r
- dev_out = &loopback_dev;
- dev_hold(dev_out);
- fl.oif = loopback_dev.ifindex;
-+ fl.fl4_gw = 0;
- res.type = RTN_LOCAL;
- flags |= RTCF_LOCAL;
- goto make_route;
-@@ -2477,7 +2516,7 @@ static int ip_route_output_slow(struct r
-
- if (fib_lookup(&fl, &res)) {
- res.fi = NULL;
-- if (oldflp->oif) {
-+ if (oldflp->oif && dev_out->flags & IFF_UP) {
- /* Apparently, routing tables are wrong. Assume,
- that the destination is on link.
-
-@@ -2517,6 +2556,7 @@ static int ip_route_output_slow(struct r
- dev_out = &loopback_dev;
- dev_hold(dev_out);
- fl.oif = dev_out->ifindex;
-+ fl.fl4_gw = 0;
- if (res.fi)
- fib_info_put(res.fi);
- res.fi = NULL;
-@@ -2524,13 +2564,12 @@ static int ip_route_output_slow(struct r
- goto make_route;
- }
-
-+ if (res.type == RTN_UNICAST)
-+ fib_select_default(&fl, &res);
- #ifdef CONFIG_IP_ROUTE_MULTIPATH
-- if (res.fi->fib_nhs > 1 && fl.oif == 0)
-+ if (res.fi->fib_nhs > 1)
- fib_select_multipath(&fl, &res);
-- else
- #endif
-- if (!res.prefixlen && res.type == RTN_UNICAST && !fl.oif)
-- fib_select_default(&fl, &res);
-
- if (!fl.fl4_src)
- fl.fl4_src = FIB_RES_PREFSRC(res);
-@@ -2567,6 +2606,7 @@ int __ip_route_output_key(struct rtable
- rth->fl.fl4_src == flp->fl4_src &&
- rth->fl.iif == 0 &&
- rth->fl.oif == flp->oif &&
-+ rth->fl.fl4_gw == flp->fl4_gw &&
- rth->fl.mark == flp->mark &&
- !((rth->fl.fl4_tos ^ flp->fl4_tos) &
- (IPTOS_RT_MASK | RTO_ONLINK))) {
-@@ -3199,3 +3239,4 @@ int __init ip_rt_init(void)
- EXPORT_SYMBOL(__ip_select_ident);
- EXPORT_SYMBOL(ip_route_input);
- EXPORT_SYMBOL(ip_route_output_key);
-+EXPORT_SYMBOL(ip_route_input_lookup);
+++ /dev/null
-Index: linux-2.6.21.7/arch/mips/Makefile
-===================================================================
---- linux-2.6.21.7.orig/arch/mips/Makefile
-+++ linux-2.6.21.7/arch/mips/Makefile
-@@ -605,6 +605,9 @@ core-$(CONFIG_TOSHIBA_RBTX4938) += arch/
- core-$(CONFIG_TOSHIBA_RBTX4938) += arch/mips/tx4938/common/
- load-$(CONFIG_TOSHIBA_RBTX4938) += 0xffffffff80100000
-
-+# temporary until string.h is fixed
-+cflags-y += -ffreestanding
-+
- cflags-y += -Iinclude/asm-mips/mach-generic
- drivers-$(CONFIG_PCI) += arch/mips/pci/
-
+++ /dev/null
-Index: linux-2.6.21.7/fs/jffs2/build.c
-===================================================================
---- linux-2.6.21.7.orig/fs/jffs2/build.c
-+++ linux-2.6.21.7/fs/jffs2/build.c
-@@ -107,6 +107,17 @@ static int jffs2_build_filesystem(struct
- dbg_fsbuild("scanned flash completely\n");
- jffs2_dbg_dump_block_lists_nolock(c);
-
-+ if (c->flags & (1 << 7)) {
-+ printk("%s(): unlocking the mtd device... ", __func__);
-+ if (c->mtd->unlock)
-+ c->mtd->unlock(c->mtd, 0, c->mtd->size);
-+ printk("done.\n");
-+
-+ printk("%s(): erasing all blocks after the end marker... ", __func__);
-+ jffs2_erase_pending_blocks(c, -1);
-+ printk("done.\n");
-+ }
-+
- dbg_fsbuild("pass 1 starting\n");
- c->flags |= JFFS2_SB_FLAG_BUILDING;
- /* Now scan the directory tree, increasing nlink according to every dirent found. */
-Index: linux-2.6.21.7/fs/jffs2/scan.c
-===================================================================
---- linux-2.6.21.7.orig/fs/jffs2/scan.c
-+++ linux-2.6.21.7/fs/jffs2/scan.c
-@@ -143,9 +143,12 @@ int jffs2_scan_medium(struct jffs2_sb_in
-
- /* reset summary info for next eraseblock scan */
- jffs2_sum_reset_collected(s);
--
-- ret = jffs2_scan_eraseblock(c, jeb, buf_size?flashbuf:(flashbuf+jeb->offset),
-- buf_size, s);
-+
-+ if (c->flags & (1 << 7))
-+ ret = BLK_STATE_ALLFF;
-+ else
-+ ret = jffs2_scan_eraseblock(c, jeb, buf_size?flashbuf:(flashbuf+jeb->offset),
-+ buf_size, s);
-
- if (ret < 0)
- goto out;
-@@ -546,6 +549,17 @@ static int jffs2_scan_eraseblock (struct
- return err;
- }
-
-+ if ((buf[0] == 0xde) &&
-+ (buf[1] == 0xad) &&
-+ (buf[2] == 0xc0) &&
-+ (buf[3] == 0xde)) {
-+ /* end of filesystem. erase everything after this point */
-+ printk("%s(): End of filesystem marker found at 0x%x\n", __func__, jeb->offset);
-+ c->flags |= (1 << 7);
-+
-+ return BLK_STATE_ALLFF;
-+ }
-+
- /* We temporarily use 'ofs' as a pointer into the buffer/jeb */
- ofs = 0;
-
+++ /dev/null
-Index: linux-2.6.21.7/include/asm-powerpc/segment.h
-===================================================================
---- /dev/null
-+++ linux-2.6.21.7/include/asm-powerpc/segment.h
-@@ -0,0 +1,6 @@
-+#ifndef _ASM_SEGMENT_H
-+#define _ASM_SEGMENT_H
-+
-+/* Only here because we have some old header files that expect it.. */
-+
-+#endif /* _ASM_SEGMENT_H */
+++ /dev/null
-Index: linux-2.6.21.7/drivers/net/r8169.c
-===================================================================
---- linux-2.6.21.7.orig/drivers/net/r8169.c
-+++ linux-2.6.21.7/drivers/net/r8169.c
-@@ -494,7 +494,7 @@ static int rtl8169_poll(struct net_devic
- #endif
-
- static const u16 rtl8169_intr_mask =
-- SYSErr | LinkChg | RxOverflow | RxFIFOOver | TxErr | TxOK | RxErr | RxOK;
-+ LinkChg | RxOverflow | RxFIFOOver | TxErr | TxOK | RxErr | RxOK;
- static const u16 rtl8169_napi_event =
- RxOK | RxOverflow | RxFIFOOver | TxOK | TxErr;
- static const unsigned int rtl8169_rx_config =
-@@ -2652,10 +2652,12 @@ rtl8169_interrupt(int irq, void *dev_ins
- if (!(status & rtl8169_intr_mask))
- break;
-
-+#if 0
- if (unlikely(status & SYSErr)) {
- rtl8169_pcierr_interrupt(dev);
- break;
- }
-+#endif
-
- if (status & LinkChg)
- rtl8169_check_link_status(dev, tp, ioaddr);
+++ /dev/null
-Index: linux-2.6.21.7/fs/Kconfig
-===================================================================
---- linux-2.6.21.7.orig/fs/Kconfig
-+++ linux-2.6.21.7/fs/Kconfig
-@@ -461,6 +461,9 @@ config OCFS2_DEBUG_MASKLOG
- This option will enlarge your kernel, but it allows debugging of
- ocfs2 filesystem issues.
-
-+config MINI_FO
-+ tristate "Mini fanout overlay filesystem"
-+
- config MINIX_FS
- tristate "Minix fs support"
- help
-Index: linux-2.6.21.7/fs/Makefile
-===================================================================
---- linux-2.6.21.7.orig/fs/Makefile
-+++ linux-2.6.21.7/fs/Makefile
-@@ -72,6 +72,7 @@ obj-$(CONFIG_SQUASHFS) += squashfs/
- obj-$(CONFIG_RAMFS) += ramfs/
- obj-$(CONFIG_HUGETLBFS) += hugetlbfs/
- obj-$(CONFIG_CODA_FS) += coda/
-+obj-$(CONFIG_MINI_FO) += mini_fo/
- obj-$(CONFIG_MINIX_FS) += minix/
- obj-$(CONFIG_FAT_FS) += fat/
- obj-$(CONFIG_MSDOS_FS) += msdos/
-Index: linux-2.6.21.7/fs/mini_fo/aux.c
-===================================================================
---- /dev/null
-+++ linux-2.6.21.7/fs/mini_fo/aux.c
-@@ -0,0 +1,580 @@
-+/*
-+ * Copyright (c) 1997-2003 Erez Zadok
-+ * Copyright (c) 2001-2003 Stony Brook University
-+ *
-+ * For specific licensing information, see the COPYING file distributed with
-+ * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
-+ *
-+ * This Copyright notice must be kept intact and distributed with all
-+ * fistgen sources INCLUDING sources generated by fistgen.
-+ */
-+/*
-+ * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
-+ *
-+ * 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.
-+ */
-+/*
-+ * $Id$
-+ */
-+
-+#ifdef HAVE_CONFIG_H
-+# include <config.h>
-+#endif
-+
-+#include "fist.h"
-+#include "mini_fo.h"
-+
-+/* check if file exists in storage */
-+int exists_in_storage(dentry_t *dentry)
-+{
-+ check_mini_fo_dentry(dentry);
-+ if(dtost(dentry) == MODIFIED || dtost(dentry) == CREATED || dtost(dentry) == DEL_REWRITTEN)
-+ return 1;
-+ return 0;
-+}
-+
-+/* check if dentry is in an existing state */
-+int is_mini_fo_existant(dentry_t *dentry)
-+{
-+ check_mini_fo_dentry(dentry);
-+
-+ if(dtost(dentry) == DELETED || dtost(dentry) == NON_EXISTANT)
-+ return 0;
-+ else
-+ return 1;
-+}
-+
-+/*
-+ * This function will create a negative storage dentry for
-+ * dentry, what is required for many create like options.
-+ * It will create the storage structure if necessary.
-+ */
-+int get_neg_sto_dentry(dentry_t *dentry)
-+{
-+ int err = 0;
-+ unsigned int len;
-+ const unsigned char *name;
-+
-+ if(!dentry ||
-+ !dtopd(dentry) ||
-+ !(dtost(dentry) == UNMODIFIED ||
-+ dtost(dentry) == NON_EXISTANT ||
-+ dtost(dentry) == DELETED)) {
-+ printk(KERN_CRIT "mini_fo: get_neg_sto_dentry: invalid dentry passed.\n");
-+ err = -1;
-+ goto out;
-+ }
-+ /* Have we got a neg. dentry already? */
-+ if(dtohd2(dentry)) {
-+ err = 0;
-+ goto out;
-+ }
-+ if(dtost(dentry->d_parent) == UNMODIFIED) {
-+ /* build sto struct */
-+ err = build_sto_structure(dentry->d_parent->d_parent, dentry->d_parent);
-+ if(err ||
-+ dtost(dentry->d_parent) != MODIFIED) {
-+ printk(KERN_CRIT "mini_fo: get_neg_sto_dentry: ERROR building sto structure.\n");
-+ err = -1;
-+ goto out;
-+ }
-+ }
-+
-+ len = dentry->d_name.len;
-+ name = dentry->d_name.name;
-+
-+ dtohd2(dentry) =
-+ lookup_one_len(name, dtohd2(dentry->d_parent), len);
-+
-+ out:
-+ return err;
-+}
-+
-+int check_mini_fo_dentry(dentry_t *dentry)
-+{
-+ ASSERT(dentry != NULL);
-+ ASSERT(dtopd(dentry) != NULL);
-+ ASSERT((dtohd(dentry) != NULL) || (dtohd2(dentry) != NULL));
-+
-+/* if(dtost(dentry) == MODIFIED) { */
-+/* ASSERT(dentry->d_inode != NULL); */
-+/* ASSERT(dtohd(dentry) != NULL); */
-+/* ASSERT(dtohd(dentry)->d_inode != NULL); */
-+/* ASSERT(dtohd2(dentry) != NULL); */
-+/* ASSERT(dtohd2(dentry)->d_inode != NULL); */
-+/* } */
-+/* else if(dtost(dentry) == UNMODIFIED) { */
-+/* ASSERT(dentry->d_inode != NULL); */
-+/* ASSERT( */
-+/* } */
-+ return 0;
-+}
-+
-+int check_mini_fo_file(file_t *file)
-+{
-+ ASSERT(file != NULL);
-+ ASSERT(ftopd(file) != NULL);
-+ ASSERT(file->f_dentry != NULL);
-+
-+ /* violent checking, check depending of state and type
-+ * if(S_ISDIR(file->f_dentry->d_inode->i_mode)) {}
-+ */
-+ ASSERT((ftohf(file) != NULL) || (ftohf2(file) != NULL));
-+ return 0;
-+}
-+
-+int check_mini_fo_inode(inode_t *inode)
-+{
-+ ASSERT(inode != NULL);
-+ ASSERT(itopd(inode) != NULL);
-+ ASSERT((itohi(inode) != NULL) || (itohi2(inode) != NULL));
-+ return 0;
-+}
-+
-+/*
-+ * will walk a base path as provided by get_mini_fo_bpath and return
-+ * the (hopefully ;-) ) positive dentry of the renamed base dir.
-+ *
-+ * This does some work of path_init.
-+ */
-+dentry_t *bpath_walk(super_block_t *sb, char *bpath)
-+{
-+ int err;
-+ struct nameidata nd;
-+
-+ /* be paranoid */
-+ if(!bpath || bpath[0] != '/') {
-+ printk(KERN_CRIT "mini_fo: bpath_walk: Invalid string.\n");
-+ return NULL;
-+ }
-+ if(!sb || !stopd(sb)) {
-+ printk(KERN_CRIT "mini_fo: bpath_walk: Invalid sb.\n");
-+ return NULL;
-+ }
-+
-+ /* setup nd as path_init does */
-+ nd.last_type = LAST_ROOT; /* if there are only slashes... */
-+ nd.flags = LOOKUP_FOLLOW;
-+ /* fix this: how do I reach this lock?
-+ * read_lock(¤t->fs->lock); */
-+ nd.mnt = mntget(stopd(sb)->hidden_mnt);
-+ nd.dentry = dget(stopd(sb)->base_dir_dentry);
-+ /* read_unlock(¤t->fs->lock); */
-+
-+ err = path_walk(bpath+1, &nd);
-+
-+ /* validate */
-+ if (err || !nd.dentry || !nd.dentry->d_inode) {
-+ printk(KERN_CRIT "mini_fo: bpath_walk: path_walk failed.\n");
-+ return NULL;
-+ }
-+ return nd.dentry;
-+}
-+
-+
-+/* returns the full path of the basefile incl. its name */
-+int get_mini_fo_bpath(dentry_t *dentry, char **bpath, int *bpath_len)
-+{
-+ char *buf_walker;
-+ int len = 0;
-+ dentry_t *sky_walker;
-+
-+ if(!dentry || !dtohd(dentry)) {
-+ printk(KERN_CRIT "mini_fo: get_mini_fo_bpath: invalid dentry passed.\n");
-+ return -1;
-+ }
-+ sky_walker = dtohd(dentry);
-+
-+ do {
-+ len += sky_walker->d_name.len + 1 ; /* 1 for '/' */
-+ sky_walker = sky_walker->d_parent;
-+ } while(sky_walker != stopd(dentry->d_inode->i_sb)->base_dir_dentry);
-+
-+ /* 1 to oil the loop */
-+ *bpath = (char*) kmalloc(len + 1, GFP_KERNEL);
-+ if(!*bpath) {
-+ printk(KERN_CRIT "mini_fo: get_mini_fo_bpath: out of mem.\n");
-+ return -1;
-+ }
-+ buf_walker = *bpath+len; /* put it on last char */
-+ *buf_walker = '\n';
-+ sky_walker = dtohd(dentry);
-+
-+ do {
-+ buf_walker -= sky_walker->d_name.len;
-+ strncpy(buf_walker,
-+ sky_walker->d_name.name,
-+ sky_walker->d_name.len);
-+ *(--buf_walker) = '/';
-+ sky_walker = sky_walker->d_parent;
-+ } while(sky_walker != stopd(dentry->d_inode->i_sb)->base_dir_dentry);
-+
-+ /* bpath_len doesn't count newline! */
-+ *bpath_len = len;
-+ return 0;
-+}
-+
-+int mini_fo_cp_cont(dentry_t *tgt_dentry, struct vfsmount *tgt_mnt,
-+ dentry_t *src_dentry, struct vfsmount *src_mnt)
-+{
-+ void *buf;
-+ mm_segment_t old_fs;
-+ file_t *tgt_file;
-+ file_t *src_file;
-+ int bytes, len, tmp, err;
-+ err = 0;
-+
-+ if(!(tgt_dentry->d_inode && src_dentry->d_inode)) {
-+ printk(KERN_CRIT "mini_fo_cp_cont: ERROR, neg. dentry passed.\n");
-+ err = -EINVAL;
-+ goto out;
-+ }
-+
-+ dget(tgt_dentry);
-+ dget(src_dentry);
-+ mntget(tgt_mnt);
-+ mntget(src_mnt);
-+
-+ /* open file write only */
-+ tgt_file = dentry_open(tgt_dentry, tgt_mnt, 0x1);
-+ if(!tgt_file || IS_ERR(tgt_file)) {
-+ printk(KERN_CRIT "mini_fo_cp_cont: ERROR opening target file.\n");
-+ err = PTR_ERR(tgt_file);
-+ goto out_err;
-+ }
-+
-+ /* open file read only */
-+ src_file = dentry_open(src_dentry, src_mnt, 0x0);
-+ if(!src_file || IS_ERR(src_file)) {
-+ printk(KERN_CRIT "mini_fo_cp_cont: ERROR opening source file.\n");
-+ err = PTR_ERR(src_file);
-+
-+ /* close target file */
-+ fput(tgt_file);
-+ goto out_err;
-+ }
-+
-+ /* check if the filesystem(s) support read respective write */
-+ if(!src_file->f_op->read || !tgt_file->f_op->write) {
-+ printk(KERN_CRIT "mini_fo_cp_cont: ERROR, no fs read or write support.\n");
-+ err = -EPERM;
-+ goto out_close;
-+ }
-+
-+ /* allocate a page for transfering the data */
-+ buf = (void *) __get_free_page(GFP_KERNEL);
-+ if(!buf) {
-+ printk(KERN_CRIT "mini_fo_cp_cont: ERROR, out of kernel mem.\n");
-+ goto out_err;
-+ }
-+
-+ tgt_file->f_pos = 0;
-+ src_file->f_pos = 0;
-+
-+ old_fs = get_fs();
-+ set_fs(KERNEL_DS);
-+
-+ /* Doing this I assume that a read operation will return a full
-+ * buffer while there is still data to read, and a less than
-+ * full buffer when all data has been read.
-+ */
-+ bytes = len = PAGE_SIZE;
-+ while(bytes == len) {
-+ bytes = src_file->f_op->read(src_file, buf, len,
-+ &src_file->f_pos);
-+ tmp = tgt_file->f_op->write(tgt_file, buf, bytes,
-+ &tgt_file->f_pos);
-+ if(tmp != bytes) {
-+ printk(KERN_CRIT "mini_fo_cp_cont: ERROR writing.\n");
-+ goto out_close_unset;
-+ }
-+ }
-+
-+ free_page((unsigned long) buf);
-+ set_fs(old_fs);
-+ fput(tgt_file);
-+ fput(src_file);
-+ goto out;
-+
-+ out_close_unset:
-+ free_page((unsigned long) buf);
-+ set_fs(old_fs);
-+
-+ out_close:
-+ fput(tgt_file);
-+ fput(src_file);
-+
-+ out_err:
-+ dput(tgt_dentry);
-+ dput(src_dentry);
-+
-+ /* mk: not sure if this need to be done */
-+ mntput(tgt_mnt);
-+ mntput(src_mnt);
-+
-+ out:
-+ return err;
-+}
-+
-+/* mk:
-+ * ndl (no-duplicate list) stuff
-+ * This is used in mini_fo_readdir, to save the storage directory contents
-+ * and later when reading base, match them against the list in order
-+ * to avoid duplicates.
-+ */
-+
-+/* add a file specified by name and len to the ndl
-+ * Return values: 0 on success, <0 on failure.
-+ */
-+int ndl_add_entry(struct readdir_data *rd, const char *name, int len)
-+{
-+ struct ndl_entry *tmp_entry;
-+
-+ tmp_entry = (struct ndl_entry *)
-+ kmalloc(sizeof(struct ndl_entry), GFP_KERNEL);
-+ if(!tmp_entry) {
-+ printk(KERN_CRIT "mini_fo: ndl_add_entry: out of mem.\n");
-+ return -ENOMEM;
-+ }
-+ tmp_entry->name = (char*) kmalloc(len, GFP_KERNEL);
-+ if(!tmp_entry->name) {
-+ printk(KERN_CRIT "mini_fo: ndl_add_entry: out of mem.\n");
-+ return -ENOMEM;
-+ }
-+ strncpy(tmp_entry->name, name, len);
-+ tmp_entry->len = len;
-+
-+ list_add(&tmp_entry->list, &rd->ndl_list);
-+ rd->ndl_size++;
-+ return 0;
-+}
-+
-+/* delete all list entries and free memory */
-+void ndl_put_list(struct readdir_data *rd)
-+{
-+ struct list_head *tmp;
-+ struct ndl_entry *tmp_entry;
-+
-+ if(rd->ndl_size <= 0)
-+ return;
-+ while(!list_empty(&rd->ndl_list)) {
-+ tmp = rd->ndl_list.next;
-+ list_del(tmp);
-+ tmp_entry = list_entry(tmp, struct ndl_entry, list);
-+ kfree(tmp_entry->name);
-+ kfree(tmp_entry);
-+ }
-+ rd->ndl_size = 0;
-+}
-+
-+/* Check if a file specified by name and len is in the ndl
-+ * Return value: 0 if not in list, 1 if file is found in ndl.
-+ */
-+int ndl_check_entry(struct readdir_data *rd, const char *name, int len)
-+{
-+ struct list_head *tmp;
-+ struct ndl_entry *tmp_entry;
-+
-+ if(rd->ndl_size <= 0)
-+ return 0;
-+
-+ list_for_each(tmp, &rd->ndl_list) {
-+ tmp_entry = list_entry(tmp, struct ndl_entry, list);
-+ if(tmp_entry->len != len)
-+ continue;
-+ if(!strncmp(tmp_entry->name, name, len))
-+ return 1;
-+ }
-+ return 0;
-+}
-+
-+/* mk:
-+ * Recursive function to create corresponding directorys in the storage fs.
-+ * The function will build the storage directorys up to dentry.
-+ */
-+int build_sto_structure(dentry_t *dir, dentry_t *dentry)
-+{
-+ int err;
-+ dentry_t *hidden_sto_dentry;
-+ dentry_t *hidden_sto_dir_dentry;
-+
-+ if(dentry->d_parent != dir) {
-+ printk(KERN_CRIT "mini_fo: build_sto_structure: invalid parameter or meta data corruption [1].\n");
-+ return 1;
-+ }
-+
-+ if(dtost(dir) != MODIFIED) {
-+ err = build_sto_structure(dir->d_parent, dentry->d_parent);
-+ if(err)
-+ return err;
-+ }
-+
-+ /* ok, coming back again. */
-+ check_mini_fo_dentry(dentry);
-+ hidden_sto_dentry = dtohd2(dentry);
-+
-+ if(!hidden_sto_dentry) {
-+ /*
-+ * This is the case after creating the first
-+ * hidden_sto_dentry.
-+ * After one negative storage_dentry, all pointers to
-+ * hidden_storage dentries are set to NULL. We need to
-+ * create the negative dentry before we create the storage
-+ * file.
-+ */
-+ unsigned int len;
-+ const unsigned char *name;
-+ len = dtohd(dentry)->d_name.len;
-+ name = dtohd(dentry)->d_name.name;
-+ hidden_sto_dentry = lookup_one_len(name, dtohd2(dir), len);
-+ dtohd2(dentry) = hidden_sto_dentry;
-+ }
-+
-+ /* was: hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry); */
-+ hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
-+#else
-+ down(&hidden_sto_dir_dentry->d_inode->i_sem);
-+#endif
-+ /* lets be safe */
-+ if(dtohd2(dir) != hidden_sto_dir_dentry) {
-+ printk(KERN_CRIT "mini_fo: build_sto_structure: invalid parameter or meta data corruption [2].\n");
-+ return 1;
-+ }
-+
-+ /* check for errors in lock_parent */
-+ err = PTR_ERR(hidden_sto_dir_dentry);
-+ if(IS_ERR(hidden_sto_dir_dentry)) {
-+ printk(KERN_CRIT "mini_fo: build_sto_structure: lock_parent failed.\n");
-+ return err;
-+ }
-+
-+ err = vfs_mkdir(hidden_sto_dir_dentry->d_inode,
-+ hidden_sto_dentry,
-+ dir->d_inode->i_mode);
-+
-+ if(err) {
-+ printk(KERN_CRIT "mini_fo: build_sto_structure: failed to create storage dir [1].\n");
-+ /* was: unlock_dir(dir); */
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_unlock(&dir->d_inode->i_mutex);
-+#else
-+ up(&dir->d_inode->i_sem);
-+#endif
-+ dput(dir);
-+ return err;
-+ }
-+
-+ /* everything ok! */
-+ if(!dtohd2(dentry)->d_inode) {
-+ printk(KERN_CRIT "mini_fo: build_sto_structure: failed to create storage dir [2].\n");
-+ /* was: unlock_dir(dir); */
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_unlock(&dir->d_inode->i_mutex);
-+#else
-+ up(&dir->d_inode->i_sem);
-+#endif
-+ dput(dir);
-+ return 1;
-+ }
-+
-+ /* interpose the new inode and set new state */
-+ itohi2(dentry->d_inode) = igrab(dtohd2(dentry)->d_inode);
-+ dtopd(dentry)->state = MODIFIED;
-+
-+ /* initalize the wol list */
-+ itopd(dentry->d_inode)->deleted_list_size = -1;
-+ itopd(dentry->d_inode)->renamed_list_size = -1;
-+ meta_build_lists(dentry);
-+
-+ fist_copy_attr_all(dentry->d_inode, itohi2(dentry->d_inode));
-+ fist_copy_attr_timesizes(dir->d_inode,
-+ hidden_sto_dir_dentry->d_inode);
-+ dir->d_inode->i_nlink++;
-+ /* was: unlock_dir(hidden_sto_dir_dentry); */
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
-+#else
-+ up(&hidden_sto_dir_dentry->d_inode->i_sem);
-+#endif
-+ dput(hidden_sto_dir_dentry);
-+ return 0;
-+}
-+
-+
-+#if 0 /* unused */
-+
-+/*
-+ * Read "len" bytes from "filename" into "buf".
-+ * "buf" is in kernel space.
-+ */
-+int
-+mini_fo_read_file(const char *filename, void *buf, int len)
-+{
-+ file_t *filp;
-+ mm_segment_t oldfs;
-+ int bytes;
-+ /* Chroot? Maybe NULL isn't right here */
-+ filp = filp_open(filename, O_RDONLY, 0);
-+ if (!filp || IS_ERR(filp)) {
-+ printk("mini_fo_read_file err %d\n", (int) PTR_ERR(filp));
-+ return -1; /* or do something else */
-+ }
-+
-+ if (!filp->f_op->read)
-+ return -2; /* file(system) doesn't allow reads */
-+
-+ /* now read len bytes from offset 0 */
-+ filp->f_pos = 0; /* start offset */
-+ oldfs = get_fs();
-+ set_fs(KERNEL_DS);
-+ bytes = filp->f_op->read(filp, buf, len, &filp->f_pos);
-+ set_fs(oldfs);
-+
-+ /* close the file */
-+ fput(filp);
-+
-+ return bytes;
-+}
-+
-+
-+
-+/*
-+ * Write "len" bytes from "buf" to "filename"
-+ * "buf" is in kernel space.
-+ */
-+int
-+mini_fo_write_file(const char *filename, void *buf, int len)
-+{
-+ file_t *filp;
-+ mm_segment_t oldfs;
-+ int bytes;
-+ /* Chroot? Maybe NULL isn't right here */
-+ filp = filp_open(filename, O_RDWR|O_CREAT, 0640);
-+ if (!filp || IS_ERR(filp)) {
-+ printk("mini_fo_write_file err %d\n", (int) PTR_ERR(filp));
-+ return -1; /* or do something else */
-+ }
-+
-+ if (!filp->f_op->write)
-+ return -2; /* file(system) doesn't allow writes */
-+
-+ /* now write len bytes from offset 0 */
-+ filp->f_pos = 0; /* start offset */
-+ oldfs = get_fs();
-+ set_fs(KERNEL_DS);
-+ bytes = filp->f_op->write(filp, buf, len, &filp->f_pos);
-+ set_fs(oldfs);
-+
-+ /* close the file */
-+ fput(filp);
-+
-+ return bytes;
-+}
-+
-+#endif /* unused */
-+
-Index: linux-2.6.21.7/fs/mini_fo/ChangeLog
-===================================================================
---- /dev/null
-+++ linux-2.6.21.7/fs/mini_fo/ChangeLog
-@@ -0,0 +1,281 @@
-+2006-01-24 Markus Klotzbuecher <mk@mary.denx.de>
-+
-+ * Add tons of ugly ifdefs to Ed L. Cashin's mutex patch to
-+ retain backwards compatibility.
-+
-+2006-01-24 Ed L. Cashin <ecashin@coraid.com>
-+
-+ * Support for the new mutex infrastructure
-+ (7892f2f48d165a34b0b8130c8a195dfd807b8cb6)
-+
-+2005-10-15 Markus Klotzbuecher <mk@localhost.localdomain>
-+
-+ * Bugfix for a serious memory leak in mini_fo_follow_link.
-+
-+2005-09-21 Markus Klotzbuecher <mk@mary>
-+
-+ * new release 0.6.1
-+
-+ * fix of a compiler warning due to changes in 2.6.13
-+
-+2005-09-21 Klaus Wenninger <klaus.wenninger@siemens.com>
-+
-+ * file.c: readdir: fix for a bug that caused directory entries
-+ to show up twice when using storage filesystems such as
-+ minixfs or pramfs.
-+
-+2005-06-30 Eric Lammerts <eric@lammerts.org>
-+
-+ * fix for an oops when overwriting a binary thats beeing
-+ executed.
-+
-+2005-06-09 <mk@mary>
-+
-+ * Renamed overlay to mini_fo-overlay.
-+
-+ * Added mini_fo-merge script to allow merging of storage and base
-+ after making modifications.
-+
-+2005-05-22 root <mk@mary>
-+
-+ * Added overlay script that allows to easily mount mini_fo ontop
-+ of a given base directory
-+
-+2005-05-10 <mk@mary>
-+
-+ * inode.c: xattr functions return -EOPNOSUPP instead of
-+ -ENOSUPP, what confuses "ls -l"
-+
-+ * Changed license from LGPL to GPL.
-+
-+2005-05-08 root <mk@mary>
-+
-+ * Makefile: clean it up and added make install and make
-+ uninstall.
-+
-+2005-05-06 <mk@mary>
-+
-+ * merged devel branch back to main. [v0-6-0-pre3]
-+
-+ * removed unused files print.c and fist_ioctl. [devel-0-0-18]
-+
-+ * ioctl: removed fist_ioctl stuff, that is not needed for
-+ now.
-+
-+2005-05-03 <mk@mary>
-+
-+ * file.c: simplified mini_fo_open and mini_fo_setattr using
-+ new state changing functions. [devel-0-0-17]
-+
-+ * inode.c: Fixed getattr state bug (see below) in 2.4 function
-+ mini_fo_inode revalidate.
-+
-+ * inode.c: found an other bug in mini_fo_getattr. States are not
-+ reliable in this function, as a file can be opened, unlinked and
-+ the getattr function called. This results in a deleted dentry
-+ with an inode. Fix is to ignore states and simply use the inode
-+ available.
-+
-+2005-04-29 <mk@mary>
-+
-+ * file.c: Bugfix and cleanup in fasync and fsync. [devel-0-0-16]
-+
-+ * file.c: do not use mini_fo_lock so the generic version is
-+ used (I guess).
-+
-+ * inode.c: getattr, never call getattr on lower files, as this
-+ will cause the inum to change.
-+
-+ * inode.c: rename_reg_file renamed to rename_nondir, as it
-+ doesn't matter as long it't not a dir. Removed all
-+ rename_dev_file etc.
-+
-+ * tagged as devel-0-0-15
-+
-+ * inode.c: added support for chosing support for extended
-+ attrs at compile time by XATTR define in mini_fo.h .
-+
-+ * inode.c: fixed mini_fo_getattr to use mini_fo inode and not
-+ lower again, what avoids inode number changes that confused
-+ rm again. This is the proper solution.
-+
-+2005-04-24 <mk@mary>
-+
-+ * all files: updated Copyright notive to 2005. [devel-0-0-14]
-+
-+ * inode.c: fixed mini_fo_getattr to not change the inode
-+ number, even if lower files change.
-+
-+ * super.c: fixed a bug that caused deleted base file to show
-+ up suddenly after some time, or after creating a special
-+ file. The problem was that after some time or after special
-+ file creating sync_sb_inodes is called by the vfs, that
-+ called our mini_fo_put_inode. There was (wrongly) called
-+ __meta_put_lists, that nuked the lists, although the inode
-+ was going to continue its life. Moving __meta_put_lists to
-+ mini_fo_clear_inode, where an inode is really destroyed,
-+ solved the problem.
-+
-+
-+2005-04-23 <mk@mary>
-+
-+ * state.c, aux.c: more cleaning up and
-+ simplifications. [devel-0-0-13]
-+
-+ * inode.c: implemented mini_fo_getattr, that was required for
-+ 2.6 because inode_revalidate has been remove there, and the
-+ old "du" bug returned.
-+
-+
-+2005-04-20 <mk@mary>
-+
-+ * aux.c: get_neg_sto_dentry(): allow to be called for dentries
-+ in state UNMODIFIED, NON_EXISTANT _and_ DELETED.
-+
-+2005-04-19 <mk@mary>
-+
-+ * Fixed a bug under 2.6 that caused files deleted via mini_fo
-+ not to be deleted properly and therefore the fs filled up
-+ untill no memory was left. [devel-0-0-12]
-+
-+ * Added basic hard link support. This means that creating
-+ hardlinks will work, but existing ones will be treated as
-+ individual files. [devel-0-0-11]
-+
-+2005-04-17 <mk@mary>
-+
-+ * Bugfixes
-+
-+2005-04-13 root <mk@mary>
-+
-+ * Added file state.c for the state transition
-+ functions. Doesn't work very well yet, though...
-+
-+2005-04-12 <mk@mary>
-+
-+ * Porting to 2.6 started, which is easier than expected, also
-+ due to Olivier previous work.
-+
-+2005-04-08 <mk@mary>
-+
-+ * Fixed the bug that caused du to return invalid sizes of
-+ directory trees. The problem was that
-+ mini_fo_inode_revalidate didn't always copy the attributes
-+ from the base inode properly.
-+
-+2005-04-01 Markus Klotzbuecher <mk@chasey>
-+
-+ * Merged devel branch back to main trunk and updated the
-+ RELEASE notes. This will be 0-6-0-pre1.
-+
-+2005-03-31 Markus Klotzbuecher <mk@chasey>
-+
-+ * Fixed some bugs in rename_reg_file, that only showed up in
-+ the kernel compile test. Kernel compiles cleanly ontop of
-+ mini_fo, now also make mrproper etc. work. Seems pretty stable.
-+
-+2005-03-28 Markus Klotzbuecher <mk@chasey>
-+
-+ * Many, many directory renaming bugfixes and a lot of other
-+ cleanup. Dir renaming seems to work relatively stable.
-+
-+2005-03-22 Markus Klotzbuecher <mk@chasey>
-+
-+ * Finished implementing lightweight directory renaming. Some
-+ basic testing indicates it works fine.
-+ Next is to implement testcases for the testsuite and confirm
-+ everything is really working ok.
-+
-+2005-03-18 Markus Klotzbuecher <mk@chasey>
-+
-+ * Finished implementing meta.c stuff required for directory
-+ renaming.
-+
-+2005-03-17 Markus Klotzbuecher <mk@chasey>
-+
-+ * Fixed all compile warnings + an extremly old bug that
-+ somehow crept in while reworking the wol stuff to the META
-+ system. Turning on -Werror again... :-)
-+
-+ * Fixed some bugs in the new rename_reg_file function.
-+
-+ * Rewrote mini_fo rename and split it into several
-+ subfunctions, that handle the different types
-+ seperately. Rewrote the regular file function aswell, as it
-+ was implemented somewhat inefficient.
-+
-+2005-03-16 Markus Klotzbuecher <mk@chasey>
-+
-+ * Implemented new META subsystem, removed old WOL stuff in favor
-+ if it.
-+
-+ * After some basic testing everything seems ok...
-+
-+2005-03-11 Markus Klotzbuecher <mk@chasey>
-+
-+ * Renaming a non regular file caused trouble because I always
-+ tried to copy the contents. Now I only do this for regular
-+ files. mini_fo_rename still isn't implemented properly, renaming
-+ of device files, symlinks etc. results in a empty regular file
-+ instead of the proper type.
-+
-+ * Directory renaming suddenly works! What a surprise! I guess
-+ this is because renaming is implemented as making a copy and
-+ removing the original. Still this might not work
-+ everywhere...
-+
-+2005-03-09 Markus Klotzbuecher <mk@chasey>
-+
-+ * Bugfix, when a mini_fo directory that exists in storage
-+ (state: MODIFIED, CREATED and DEL_REWRITTEN) is deleted, a
-+ possibly existing WOL file contained in it needs to be
-+ deleted too.
-+
-+ * Starting cleanup: defined state names in order to get rid of
-+ the state numbers.
-+
-+2005-03-08 Markus Klotzbuecher <mk@chasey>
-+
-+ * Makefile fix, fist_ioctl was built against wrong sources if ARCH=um
-+
-+ * Fixed a bug in dentry.c, mini_fo_d_hash. In state 4 =
-+ DEL_REWRITTEN the hash was calculated from the base dentry,
-+ which was wrong and and caused assertions in
-+ __mini_fo_hidden_dentry to fail.
-+
-+2005-02-21 <mk@mary>
-+
-+ * Implemented directory deleting (inode.c)
-+
-+ * main.c: made mini_fo_parse_options a little more robust.
-+
-+2004-12-22 <mk@mary>
-+
-+ * Makefile cleanup and uml stuff, removed unneccessary files
-+
-+ * Created a new and hopefully more informative README
-+
-+ * CHANGELOG: created a new CHANGELOG and added old entries reversely
-+
-+
-+2004-10-24 Gleb Natapov <gleb@nbase.co.il>
-+
-+ * Fix: owner and group where not correctly copied from base to
-+ storage.
-+
-+
-+2004-10-05 Gleb Natapov <gleb@nbase.co.il>
-+
-+ * Implementation of fsync, fasync and lock mini_fo functions.
-+
-+
-+2004-09-29 Bob Lee <bob@pantasys.com>
-+
-+ * Fix of a serious pointer bug
-+
-+
-+2004-09-28 Gleb Natapov <gleb@nbase.co.il>
-+
-+ * Implementation of mini_fo_mknod and mini_fo_rename, support
-+ for device files.
-+
-Index: linux-2.6.21.7/fs/mini_fo/dentry.c
-===================================================================
---- /dev/null
-+++ linux-2.6.21.7/fs/mini_fo/dentry.c
-@@ -0,0 +1,244 @@
-+/*
-+ * Copyright (c) 1997-2003 Erez Zadok
-+ * Copyright (c) 2001-2003 Stony Brook University
-+ *
-+ * For specific licensing information, see the COPYING file distributed with
-+ * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
-+ *
-+ * This Copyright notice must be kept intact and distributed with all
-+ * fistgen sources INCLUDING sources generated by fistgen.
-+ */
-+/*
-+ * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
-+ *
-+ * 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.
-+ */
-+
-+/*
-+ * $Id$
-+ */
-+
-+#ifdef HAVE_CONFIG_H
-+# include <config.h>
-+#endif
-+
-+#include "fist.h"
-+#include "mini_fo.h"
-+
-+/*
-+ * THIS IS A BOOLEAN FUNCTION: returns 1 if valid, 0 otherwise.
-+ */
-+STATIC int
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
-+mini_fo_d_revalidate(dentry_t *dentry, struct nameidata *nd)
-+#else
-+mini_fo_d_revalidate(dentry_t *dentry, int flags)
-+#endif
-+{
-+ int err1 = 1; /* valid = 1, invalid = 0 */
-+ int err2 = 1;
-+ dentry_t *hidden_dentry;
-+ dentry_t *hidden_sto_dentry;
-+
-+
-+ check_mini_fo_dentry(dentry);
-+
-+ hidden_dentry = dtohd(dentry);
-+ hidden_sto_dentry = dtohd2(dentry);
-+
-+ if(hidden_dentry &&
-+ hidden_dentry->d_op &&
-+ hidden_dentry->d_op->d_revalidate) {
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
-+ err1 = hidden_dentry->d_op->d_revalidate(hidden_dentry, nd);
-+#else
-+ err1 = hidden_dentry->d_op->d_revalidate(hidden_dentry, flags);
-+#endif
-+ }
-+ if(hidden_sto_dentry &&
-+ hidden_sto_dentry->d_op &&
-+ hidden_sto_dentry->d_op->d_revalidate) {
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
-+ err2 = hidden_sto_dentry->d_op->d_revalidate(hidden_sto_dentry,
-+ nd);
-+#else
-+ err2 = hidden_sto_dentry->d_op->d_revalidate(hidden_sto_dentry,
-+ flags);
-+#endif
-+ }
-+
-+ /* mk: if one of the lower level dentries are valid,
-+ * the mini_fo dentry is too.
-+ */
-+ return (err1 || err2);
-+}
-+
-+
-+STATIC int
-+mini_fo_d_hash(dentry_t *dentry, qstr_t *name)
-+{
-+ int err = 0;
-+ dentry_t *hidden_dentry;
-+ dentry_t *hidden_sto_dentry;
-+
-+ /* hidden_dentry = mini_fo_hidden_dentry(dentry);
-+ * hidden_sto_dentry = mini_fo_hidden_sto_dentry(dentry); */
-+
-+ /* state 1, 3, 4, 5: build the hash for the storage dentry */
-+ if((dtopd(dentry)->state == MODIFIED) ||
-+ (dtopd(dentry)->state == CREATED) ||
-+ (dtopd(dentry)->state == DEL_REWRITTEN) ||
-+ (dtopd(dentry)->state == DELETED)) {
-+ hidden_sto_dentry = dtohd2(dentry);
-+ if(hidden_sto_dentry &&
-+ hidden_sto_dentry->d_op &&
-+ hidden_sto_dentry->d_op->d_hash) {
-+ err = hidden_sto_dentry->d_op->d_hash(hidden_sto_dentry, name);
-+ }
-+ goto out;
-+ }
-+ /* state 2: build the hash for the base dentry */
-+ if(dtopd(dentry)->state == UNMODIFIED) {
-+ hidden_dentry = dtohd(dentry);
-+ if(hidden_dentry &&
-+ hidden_dentry->d_op &&
-+ hidden_dentry->d_op->d_hash) {
-+ err = hidden_dentry->d_op->d_hash(hidden_dentry, name);
-+ }
-+ goto out;
-+ }
-+ /* state 6: build hash for the dentry that exists */
-+ if(dtopd(dentry)->state == NON_EXISTANT) {
-+ hidden_sto_dentry = dtohd2(dentry);
-+ if(hidden_sto_dentry &&
-+ hidden_sto_dentry->d_op &&
-+ hidden_sto_dentry->d_op->d_hash) {
-+ err = hidden_sto_dentry->d_op->d_hash(hidden_sto_dentry, name);
-+ goto out;
-+ }
-+ hidden_dentry = dtohd(dentry);
-+ if(hidden_dentry &&
-+ hidden_dentry->d_op &&
-+ hidden_dentry->d_op->d_hash) {
-+ err = hidden_dentry->d_op->d_hash(hidden_dentry, name);
-+ goto out;
-+ }
-+ }
-+
-+ printk(KERN_CRIT "mini_fo: d_hash: invalid state detected.\n");
-+
-+ out:
-+ return err;
-+}
-+
-+
-+STATIC int
-+mini_fo_d_compare(dentry_t *dentry, qstr_t *a, qstr_t *b)
-+{
-+ int err;
-+ dentry_t *hidden_dentry=NULL;
-+
-+ /* hidden_dentry = mini_fo_hidden_dentry(dentry); */
-+ if(dtohd2(dentry))
-+ hidden_dentry = dtohd2(dentry);
-+ else if(dtohd(dentry))
-+ hidden_dentry = dtohd(dentry);
-+
-+ if (hidden_dentry && hidden_dentry->d_op && hidden_dentry->d_op->d_compare) {
-+ err = hidden_dentry->d_op->d_compare(hidden_dentry, a, b);
-+ } else {
-+ err = ((a->len != b->len) || memcmp(a->name, b->name, b->len));
-+ }
-+
-+ return err;
-+}
-+
-+
-+int
-+mini_fo_d_delete(dentry_t *dentry)
-+{
-+ dentry_t *hidden_dentry;
-+ dentry_t *hidden_sto_dentry;
-+ int err = 0;
-+
-+ /* this could be a negative dentry, so check first */
-+ if (!dtopd(dentry)) {
-+ printk(KERN_CRIT "mini_fo_d_delete: negative dentry passed.\n");
-+ goto out;
-+ }
-+ hidden_dentry = dtohd(dentry);
-+ hidden_sto_dentry = dtohd2(dentry);
-+
-+ if(hidden_dentry) {
-+ if(hidden_dentry->d_op &&
-+ hidden_dentry->d_op->d_delete) {
-+ err = hidden_dentry->d_op->d_delete(hidden_dentry);
-+ }
-+ }
-+ if(hidden_sto_dentry) {
-+ if(hidden_sto_dentry->d_op &&
-+ hidden_sto_dentry->d_op->d_delete) {
-+ err = hidden_sto_dentry->d_op->d_delete(hidden_sto_dentry);
-+ }
-+ }
-+
-+ out:
-+ return err;
-+}
-+
-+
-+void
-+mini_fo_d_release(dentry_t *dentry)
-+{
-+ dentry_t *hidden_dentry;
-+ dentry_t *hidden_sto_dentry;
-+
-+
-+ /* this could be a negative dentry, so check first */
-+ if (!dtopd(dentry)) {
-+ printk(KERN_CRIT "mini_fo_d_release: no private data.\n");
-+ goto out;
-+ }
-+ hidden_dentry = dtohd(dentry);
-+ hidden_sto_dentry = dtohd2(dentry);
-+
-+ if(hidden_dentry) {
-+ /* decrement hidden dentry's counter and free its inode */
-+ dput(hidden_dentry);
-+ }
-+ if(hidden_sto_dentry) {
-+ /* decrement hidden dentry's counter and free its inode */
-+ dput(hidden_sto_dentry);
-+ }
-+
-+ /* free private data (mini_fo_dentry_info) here */
-+ kfree(dtopd(dentry));
-+ __dtopd(dentry) = NULL; /* just to be safe */
-+ out:
-+ return;
-+}
-+
-+
-+/*
-+ * we don't really need mini_fo_d_iput, because dentry_iput will call iput() if
-+ * mini_fo_d_iput is not defined. We left this implemented for ease of
-+ * tracing/debugging.
-+ */
-+void
-+mini_fo_d_iput(dentry_t *dentry, inode_t *inode)
-+{
-+ iput(inode);
-+}
-+
-+
-+struct dentry_operations mini_fo_dops = {
-+ d_revalidate: mini_fo_d_revalidate,
-+ d_hash: mini_fo_d_hash,
-+ d_compare: mini_fo_d_compare,
-+ d_release: mini_fo_d_release,
-+ d_delete: mini_fo_d_delete,
-+ d_iput: mini_fo_d_iput,
-+};
-Index: linux-2.6.21.7/fs/mini_fo/file.c
-===================================================================
---- /dev/null
-+++ linux-2.6.21.7/fs/mini_fo/file.c
-@@ -0,0 +1,713 @@
-+/*
-+ * Copyright (c) 1997-2003 Erez Zadok
-+ * Copyright (c) 2001-2003 Stony Brook University
-+ *
-+ * For specific licensing information, see the COPYING file distributed with
-+ * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
-+ *
-+ * This Copyright notice must be kept intact and distributed with all
-+ * fistgen sources INCLUDING sources generated by fistgen.
-+ */
-+/*
-+ * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
-+ *
-+ * 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.
-+ */
-+
-+/*
-+ * $Id$
-+ */
-+
-+#ifdef HAVE_CONFIG_H
-+# include <config.h>
-+#endif
-+
-+#include "fist.h"
-+#include "mini_fo.h"
-+#define ROUND_UP(x) (((x)+sizeof(long)-1) & ~(sizeof(long)-1))
-+
-+/*******************
-+ * File Operations *
-+ *******************/
-+
-+STATIC loff_t
-+mini_fo_llseek(file_t *file, loff_t offset, int origin)
-+{
-+ loff_t err;
-+ file_t *hidden_file = NULL;
-+
-+ if(S_ISDIR(file->f_dentry->d_inode->i_mode)) {
-+ /* Check if trying to llseek from a directory */
-+ err = -EISDIR;
-+ goto out;
-+ }
-+ if (ftopd(file) != NULL) {
-+ if(ftohf2(file)) {
-+ hidden_file = ftohf2(file);
-+ } else {
-+ hidden_file = ftohf(file);
-+ }
-+ }
-+
-+ /* always set hidden position to this one */
-+ hidden_file->f_pos = file->f_pos;
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
-+ memcpy(&(hidden_file->f_ra),
-+ &(file->f_ra),
-+ sizeof(struct file_ra_state));
-+#else
-+ if (file->f_reada) { /* update readahead information if needed */
-+ hidden_file->f_reada = file->f_reada;
-+ hidden_file->f_ramax = file->f_ramax;
-+ hidden_file->f_raend = file->f_raend;
-+ hidden_file->f_ralen = file->f_ralen;
-+ hidden_file->f_rawin = file->f_rawin;
-+ }
-+#endif
-+ if (hidden_file->f_op && hidden_file->f_op->llseek)
-+ err = hidden_file->f_op->llseek(hidden_file, offset, origin);
-+ else
-+ err = generic_file_llseek(hidden_file, offset, origin);
-+
-+ if (err < 0)
-+ goto out;
-+
-+ if (err != file->f_pos) {
-+ file->f_pos = err;
-+ // ION maybe this?
-+ // file->f_pos = hidden_file->f_pos;
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
-+ file->f_reada = 0;
-+#endif
-+ file->f_version++;
-+ }
-+
-+ out:
-+ return err;
-+}
-+
-+
-+/* mk: fanout capable */
-+STATIC ssize_t
-+mini_fo_read(file_t *file, char *buf, size_t count, loff_t *ppos)
-+{
-+ int err = -EINVAL;
-+ file_t *hidden_file = NULL;
-+ loff_t pos = *ppos;
-+
-+ if(S_ISDIR(file->f_dentry->d_inode->i_mode)) {
-+ /* Check if trying to read from a directory */
-+ /* printk(KERN_CRIT "mini_fo_read: ERROR: trying to read data from a directory.\n"); */
-+ err = -EISDIR;
-+ goto out;
-+ }
-+
-+ if (ftopd(file) != NULL) {
-+ if(ftohf2(file)) {
-+ hidden_file = ftohf2(file);
-+ } else {
-+ hidden_file = ftohf(file);
-+ }
-+ }
-+
-+ if (!hidden_file->f_op || !hidden_file->f_op->read)
-+ goto out;
-+
-+ err = hidden_file->f_op->read(hidden_file, buf, count, &pos);
-+ *ppos = pos;
-+
-+ if (err >= 0) {
-+ /* atime should also be updated for reads of size zero or more */
-+ fist_copy_attr_atime(file->f_dentry->d_inode,
-+ hidden_file->f_dentry->d_inode);
-+ }
-+
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
-+ /*
-+ * MAJOR HACK
-+ * because pread() does not have any way to tell us that it is
-+ * our caller, then we don't know for sure if we have to update
-+ * the file positions. This hack relies on read() having passed us
-+ * the "real" pointer of its struct file's f_pos field.
-+ */
-+ if (ppos == &file->f_pos)
-+ hidden_file->f_pos = *ppos = pos;
-+ if (hidden_file->f_reada) { /* update readahead information if needed */
-+ file->f_reada = hidden_file->f_reada;
-+ file->f_ramax = hidden_file->f_ramax;
-+ file->f_raend = hidden_file->f_raend;
-+ file->f_ralen = hidden_file->f_ralen;
-+ file->f_rawin = hidden_file->f_rawin;
-+ }
-+#else
-+ memcpy(&(file->f_ra),&(hidden_file->f_ra),sizeof(struct file_ra_state));
-+#endif
-+
-+ out:
-+ return err;
-+}
-+
-+
-+/* this mini_fo_write() does not modify data pages! */
-+STATIC ssize_t
-+mini_fo_write(file_t *file, const char *buf, size_t count, loff_t *ppos)
-+{
-+ int err = -EINVAL;
-+ file_t *hidden_file = NULL;
-+ inode_t *inode;
-+ inode_t *hidden_inode;
-+ loff_t pos = *ppos;
-+
-+ /* mk: fan out: */
-+ if (ftopd(file) != NULL) {
-+ if(ftohf2(file)) {
-+ hidden_file = ftohf2(file);
-+ } else {
-+ /* This is bad! We have no storage file to write to. This
-+ * should never happen because if a file is opened for
-+ * writing, a copy should have been made earlier.
-+ */
-+ printk(KERN_CRIT "mini_fo: write : ERROR, no storage file to write.\n");
-+ err = -EINVAL;
-+ goto out;
-+ }
-+ }
-+
-+ inode = file->f_dentry->d_inode;
-+ hidden_inode = itohi2(inode);
-+ if(!hidden_inode) {
-+ printk(KERN_CRIT "mini_fo: write: no sto inode found, not good.\n");
-+ goto out;
-+ }
-+
-+ if (!hidden_file->f_op || !hidden_file->f_op->write)
-+ goto out;
-+
-+ /* adjust for append -- seek to the end of the file */
-+ if (file->f_flags & O_APPEND)
-+ pos = inode->i_size;
-+
-+ err = hidden_file->f_op->write(hidden_file, buf, count, &pos);
-+
-+ /*
-+ * copy ctime and mtime from lower layer attributes
-+ * atime is unchanged for both layers
-+ */
-+ if (err >= 0)
-+ fist_copy_attr_times(inode, hidden_inode);
-+
-+ *ppos = pos;
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
-+ /*
-+ * XXX: MAJOR HACK
-+ *
-+ * because pwrite() does not have any way to tell us that it is
-+ * our caller, then we don't know for sure if we have to update
-+ * the file positions. This hack relies on write() having passed us
-+ * the "real" pointer of its struct file's f_pos field.
-+ */
-+ if (ppos == &file->f_pos)
-+ hidden_file->f_pos = *ppos = pos;
-+#endif
-+ /* update this inode's size */
-+ if (pos > inode->i_size)
-+ inode->i_size = pos;
-+
-+ out:
-+ return err;
-+}
-+
-+/* Global variable to hold a file_t pointer.
-+ * This serves to allow mini_fo_filldir function to know which file is
-+ * beeing read, which is required for two reasons:
-+ *
-+ * - be able to call wol functions in order to avoid listing deleted
-+ * base files.
-+ * - if we're reading a directory which is in state 1, we need to
-+ * maintain a list (in mini_fo_filldir) of which files allready
-+ * have been copied to userspace,to detect files existing in base
-+ * and storage and not list them twice.
-+ */
-+filldir_t mini_fo_filldir_orig;
-+file_t *mini_fo_filldir_file;
-+
-+/* mainly copied from fs/readdir.c */
-+STATIC int
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
-+mini_fo_filldir(void * __buf, const char * name, int namlen, loff_t offset,
-+ u64 ino, unsigned int d_type)
-+#else
-+mini_fo_filldir(void * __buf, const char * name, int namlen, loff_t offset,
-+ ino_t ino, unsigned int d_type)
-+#endif
-+{
-+ struct getdents_callback * buf = (struct getdents_callback *) __buf;
-+ file_t* file = mini_fo_filldir_file;
-+
-+ /* In theses states we filter meta files in storage (WOL) */
-+ if(file && (dtopd(file->f_dentry)->state == MODIFIED ||
-+ dtopd(file->f_dentry)->state == CREATED ||
-+ dtopd(file->f_dentry)->state == DEL_REWRITTEN)) {
-+
-+ int tmp = strlen(META_FILENAME);
-+ if(tmp == namlen) {
-+ if(!strncmp(name, META_FILENAME, namlen))
-+ return 0;
-+ }
-+ }
-+
-+ /* check if we are merging the contents of storage and base */
-+ if(file && dtopd(file->f_dentry)->state == MODIFIED) {
-+ /* check if we are still reading storage contents, if
-+ * yes, we just save the name of the file for duplicate
-+ * checking later. */
-+
-+ if(!ftopd(file)->rd.sto_done) {
-+ /* put file into ndl list */
-+ if(ndl_add_entry(&ftopd(file)->rd, name, namlen))
-+ printk(KERN_CRIT "mini_fo_filldir: Error adding to ndl.\n");
-+ } else {
-+ /* check if file has been deleted */
-+ if(meta_check_d_entry(file->f_dentry, name, namlen))
-+ return 0;
-+
-+ /* do duplicate checking */
-+ if(ndl_check_entry(&ftopd(file)->rd, name, namlen))
-+ return 0;
-+ }
-+ }
-+
-+ return mini_fo_filldir_orig(buf, name, namlen, offset, ino, d_type);
-+}
-+
-+
-+STATIC int
-+mini_fo_readdir(file_t *file, void *dirent, filldir_t filldir)
-+{
-+ int err = 0;/* mk: ??? -ENOTDIR; */
-+ file_t *hidden_file = NULL;
-+ file_t *hidden_sto_file = NULL;
-+ inode_t *inode;
-+ struct getdents_callback *buf;
-+ int oldcount;
-+
-+#if defined(FIST_FILTER_NAME) || defined(FIST_FILTER_SCA)
-+ struct mini_fo_getdents_callback buf;
-+#endif /* FIST_FILTER_NAME || FIST_FILTER_SCA */
-+
-+ buf = (struct getdents_callback *) dirent;
-+ oldcount = buf->count;
-+ inode = file->f_dentry->d_inode;
-+ mini_fo_filldir_file = file;
-+ mini_fo_filldir_orig = filldir;
-+
-+ ftopd(file)->rd.sto_done = 0;
-+ do {
-+ if (ftopd(file) != NULL) {
-+ if(ftohf2(file)) {
-+ hidden_sto_file = ftohf2(file);
-+ err = vfs_readdir(hidden_sto_file, mini_fo_filldir, dirent);
-+ file->f_pos = hidden_sto_file->f_pos;
-+ if (err > 0)
-+ fist_copy_attr_atime(inode, hidden_sto_file->f_dentry->d_inode);
-+ /* not finshed yet, we'll be called again */
-+ if (buf->count != oldcount)
-+ break;
-+ }
-+
-+ ftopd(file)->rd.sto_done = 1;
-+
-+ if(ftohf(file)) {
-+ hidden_file = ftohf(file);
-+ err = vfs_readdir(hidden_file, mini_fo_filldir, dirent);
-+ file->f_pos = hidden_file->f_pos;
-+ if (err > 0)
-+ fist_copy_attr_atime(inode, hidden_file->f_dentry->d_inode);
-+ }
-+
-+ }
-+ } while (0);
-+
-+ /* mk:
-+ * we need to check if all the directory data has been copied to userspace,
-+ * or if we will be called again by userspace to complete the operation.
-+ */
-+ if(buf->count == oldcount) {
-+ ndl_put_list(&ftopd(file)->rd);
-+ }
-+
-+ /* unset this, safe */
-+ mini_fo_filldir_file = NULL;
-+ return err;
-+}
-+
-+
-+STATIC unsigned int
-+mini_fo_poll(file_t *file, poll_table *wait)
-+{
-+ unsigned int mask = DEFAULT_POLLMASK;
-+ file_t *hidden_file = NULL;
-+
-+ if (ftopd(file) != NULL) {
-+ if(ftohf2(file)) {
-+ hidden_file = ftohf2(file);
-+ } else {
-+ hidden_file = ftohf(file);
-+ }
-+ }
-+
-+ if (!hidden_file->f_op || !hidden_file->f_op->poll)
-+ goto out;
-+
-+ mask = hidden_file->f_op->poll(hidden_file, wait);
-+
-+ out:
-+ return mask;
-+}
-+
-+/* FIST-LITE special version of mmap */
-+STATIC int
-+mini_fo_mmap(file_t *file, vm_area_t *vma)
-+{
-+ int err = 0;
-+ file_t *hidden_file = NULL;
-+
-+ /* fanout capability */
-+ if (ftopd(file) != NULL) {
-+ if(ftohf2(file)) {
-+ hidden_file = ftohf2(file);
-+ } else {
-+ hidden_file = ftohf(file);
-+ }
-+ }
-+
-+ ASSERT(hidden_file != NULL);
-+ ASSERT(hidden_file->f_op != NULL);
-+ ASSERT(hidden_file->f_op->mmap != NULL);
-+
-+ vma->vm_file = hidden_file;
-+ err = hidden_file->f_op->mmap(hidden_file, vma);
-+ get_file(hidden_file); /* make sure it doesn't get freed on us */
-+ fput(file); /* no need to keep extra ref on ours */
-+
-+ return err;
-+}
-+
-+
-+
-+STATIC int
-+mini_fo_open(inode_t *inode, file_t *file)
-+{
-+ int err = 0;
-+ int hidden_flags;
-+ file_t *hidden_file = NULL;
-+ dentry_t *hidden_dentry = NULL;
-+
-+ /* fanout stuff */
-+ file_t *hidden_sto_file = NULL;
-+ dentry_t *hidden_sto_dentry = NULL;
-+
-+ __ftopd(file) =
-+ kmalloc(sizeof(struct mini_fo_file_info), GFP_KERNEL);
-+ if (!ftopd(file)) {
-+ err = -ENOMEM;
-+ goto out;
-+ }
-+
-+ /* init the readdir_helper structure */
-+ INIT_LIST_HEAD(&ftopd(file)->rd.ndl_list);
-+ ftopd(file)->rd.ndl_size = 0;
-+
-+ /* In certain paths this could stay uninitalized and cause trouble */
-+ ftohf(file) = NULL;
-+ ftohf2(file) = NULL;
-+ hidden_flags = file->f_flags;
-+
-+ /* create storage files? */
-+ if(dtost(file->f_dentry) == UNMODIFIED) {
-+ if(!IS_WRITE_FLAG(file->f_flags)) {
-+ hidden_dentry = dtohd(file->f_dentry);
-+ dget(hidden_dentry);
-+ /* dentry_open will decrement mnt refcnt if err.
-+ * otherwise fput() will do an mntput() for us upon file close. */
-+ mntget(stopd(inode->i_sb)->hidden_mnt);
-+ hidden_file = dentry_open(hidden_dentry,
-+ stopd(inode->i_sb)->hidden_mnt,
-+ hidden_flags);
-+ if (IS_ERR(hidden_file)) {
-+ err = PTR_ERR(hidden_file);
-+ dput(hidden_dentry);
-+ goto out;
-+ }
-+ ftohf(file) = hidden_file; /* link two files */
-+ goto out;
-+ }
-+ else {
-+ if(S_ISDIR(file->f_dentry->d_inode->i_mode)) {
-+ err = dir_unmod_to_mod(file->f_dentry);
-+ } else
-+ err = nondir_unmod_to_mod(file->f_dentry, 1);
-+
-+ if (err) {
-+ printk("mini_fo_open: ERROR creating storage file.\n");
-+ goto out;
-+ }
-+ }
-+ }
-+ hidden_sto_dentry = dtohd2(file->f_dentry);
-+ dget(hidden_sto_dentry);
-+
-+ if(dtopd(file->f_dentry)->state == MODIFIED) {
-+ /* Directorys are special, interpose on both lower level files */
-+ if(S_ISDIR(itohi(inode)->i_mode)) {
-+ /* check for invalid file types of lower level files */
-+ if(!(S_ISDIR(itohi(inode)->i_mode) && S_ISDIR(itohi2(inode)->i_mode))) {
-+ printk(KERN_CRIT "mini_fo_open: meta data corruption detected.\n");
-+ dput(hidden_sto_dentry);
-+ err = -EINVAL;
-+ goto out;
-+ }
-+
-+ /* lower level directorys are ok, open the base file */
-+ hidden_dentry = dtohd(file->f_dentry);
-+ dget(hidden_dentry);
-+
-+ mntget(stopd(inode->i_sb)->hidden_mnt);
-+ hidden_file = dentry_open(hidden_dentry,
-+ stopd(inode->i_sb)->hidden_mnt,
-+ hidden_flags);
-+ if (IS_ERR(hidden_file)) {
-+ err = PTR_ERR(hidden_file);
-+ dput(hidden_dentry);
-+ dput(hidden_sto_dentry);
-+ goto out;
-+ }
-+ ftohf(file) = hidden_file; /* link the two files */
-+ }
-+ }
-+
-+ if(!exists_in_storage(file->f_dentry)) {
-+ printk(KERN_CRIT "mini_fo_open: invalid file state detected.\n");
-+ err = -EINVAL;
-+ dput(hidden_sto_dentry);
-+
-+ /* If the base file has been opened, we need to close it here */
-+ if(ftohf(file)) {
-+ if (hidden_file->f_op && hidden_file->f_op->flush)
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
-+ hidden_file->f_op->flush(hidden_file, NULL);
-+#else
-+ hidden_file->f_op->flush(hidden_file);
-+#endif
-+ dput(hidden_dentry);
-+ }
-+ goto out;
-+ }
-+
-+ /* ok, now we can safely open the storage file */
-+ mntget(stopd(inode->i_sb)->hidden_mnt2);
-+ hidden_sto_file = dentry_open(hidden_sto_dentry,
-+ stopd(inode->i_sb)->hidden_mnt2,
-+ hidden_flags);
-+
-+ /* dentry_open dputs the dentry if it fails */
-+ if (IS_ERR(hidden_sto_file)) {
-+ err = PTR_ERR(hidden_sto_file);
-+ /* close base file if open */
-+ if(ftohf(file)) {
-+ if (hidden_file->f_op && hidden_file->f_op->flush)
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
-+ hidden_file->f_op->flush(hidden_file, NULL);
-+#else
-+ hidden_file->f_op->flush(hidden_file);
-+#endif
-+ dput(hidden_dentry);
-+ }
-+ goto out;
-+ }
-+ ftohf2(file) = hidden_sto_file; /* link storage file */
-+
-+ out:
-+ if (err < 0 && ftopd(file)) {
-+ kfree(ftopd(file));
-+ }
-+ return err;
-+}
-+
-+STATIC int
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
-+mini_fo_flush(file_t *file, fl_owner_t id)
-+#else
-+mini_fo_flush(file_t *file)
-+#endif
-+{
-+ int err1 = 0; /* assume ok (see open.c:close_fp) */
-+ int err2 = 0;
-+ file_t *hidden_file = NULL;
-+
-+ check_mini_fo_file(file);
-+
-+ /* mk: we don't do any state checking here, as its not worth the time.
-+ * Just flush the lower level files if they exist.
-+ */
-+ if(ftopd(file) != NULL) {
-+ if(ftohf(file) != NULL) {
-+ hidden_file = ftohf(file);
-+ if (hidden_file->f_op && hidden_file->f_op->flush)
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
-+ err1 = hidden_file->f_op->flush(hidden_file, id);
-+#else
-+ err1 = hidden_file->f_op->flush(hidden_file);
-+#endif
-+ }
-+ if(ftohf2(file) != NULL) {
-+ hidden_file = ftohf2(file);
-+ if (hidden_file->f_op && hidden_file->f_op->flush)
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
-+ err2 = hidden_file->f_op->flush(hidden_file, id);
-+#else
-+ err2 = hidden_file->f_op->flush(hidden_file);
-+#endif
-+ }
-+ }
-+ return (err1 | err2);
-+}
-+
-+
-+STATIC int
-+mini_fo_release(inode_t *inode, file_t *file)
-+{
-+ int err = 0;
-+ file_t *hidden_file = NULL;
-+
-+ if (ftopd(file) != NULL) {
-+ if(ftohf(file)) {
-+ hidden_file = ftohf(file);
-+ fput(hidden_file);
-+ }
-+ if(ftohf2(file)) {
-+ hidden_file = ftohf2(file);
-+ fput(hidden_file);
-+ }
-+ kfree(ftopd(file));
-+ }
-+ return err;
-+}
-+
-+STATIC int
-+mini_fo_fsync(file_t *file, dentry_t *dentry, int datasync)
-+{
-+ int err1 = 0;
-+ int err2 = 0;
-+ file_t *hidden_file = NULL;
-+ dentry_t *hidden_dentry;
-+
-+ check_mini_fo_file(file);
-+
-+ if ((hidden_file = ftohf(file)) != NULL) {
-+ hidden_dentry = dtohd(dentry);
-+ if (hidden_file->f_op && hidden_file->f_op->fsync) {
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_lock(&hidden_dentry->d_inode->i_mutex);
-+#else
-+ down(&hidden_dentry->d_inode->i_sem);
-+#endif
-+ err1 = hidden_file->f_op->fsync(hidden_file, hidden_dentry, datasync);
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_unlock(&hidden_dentry->d_inode->i_mutex);
-+#else
-+ up(&hidden_dentry->d_inode->i_sem);
-+#endif
-+ }
-+ }
-+
-+ if ((hidden_file = ftohf2(file)) != NULL) {
-+ hidden_dentry = dtohd2(dentry);
-+ if (hidden_file->f_op && hidden_file->f_op->fsync) {
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_lock(&hidden_dentry->d_inode->i_mutex);
-+#else
-+ down(&hidden_dentry->d_inode->i_sem);
-+#endif
-+ err2 = hidden_file->f_op->fsync(hidden_file, hidden_dentry, datasync);
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_unlock(&hidden_dentry->d_inode->i_mutex);
-+#else
-+ up(&hidden_dentry->d_inode->i_sem);
-+#endif
-+ }
-+ }
-+ else
-+ goto err;
-+
-+err:
-+ return (err1 || err2);
-+}
-+
-+
-+STATIC int
-+mini_fo_fasync(int fd, file_t *file, int flag)
-+{
-+ int err1 = 0;
-+ int err2 = 0;
-+
-+ file_t *hidden_file = NULL;
-+
-+ check_mini_fo_file(file);
-+
-+ if((hidden_file = ftohf(file)) != NULL) {
-+ err1 = hidden_file->f_op->fasync(fd, hidden_file, flag);
-+ }
-+ if((hidden_file = ftohf2(file)) != NULL) {
-+ err2 = hidden_file->f_op->fasync(fd, hidden_file, flag);
-+ }
-+
-+ return (err1 || err2);
-+}
-+
-+
-+
-+struct file_operations mini_fo_dir_fops =
-+ {
-+ read: generic_read_dir,
-+ write: mini_fo_write,
-+ readdir: mini_fo_readdir,
-+ poll: mini_fo_poll,
-+ /* ioctl: mini_fo_ioctl, */
-+ mmap: mini_fo_mmap,
-+ open: mini_fo_open,
-+ flush: mini_fo_flush,
-+ release: mini_fo_release,
-+ fsync: mini_fo_fsync,
-+ fasync: mini_fo_fasync,
-+ /* not needed lock: mini_fo_lock, */
-+ /* not needed: readv */
-+ /* not needed: writev */
-+ /* not implemented: sendpage */
-+ /* not implemented: get_unmapped_area */
-+ };
-+
-+struct file_operations mini_fo_main_fops =
-+ {
-+ llseek: mini_fo_llseek,
-+ read: mini_fo_read,
-+ write: mini_fo_write,
-+ readdir: mini_fo_readdir,
-+ poll: mini_fo_poll,
-+ /* ioctl: mini_fo_ioctl, */
-+ mmap: mini_fo_mmap,
-+ open: mini_fo_open,
-+ flush: mini_fo_flush,
-+ release: mini_fo_release,
-+ fsync: mini_fo_fsync,
-+ fasync: mini_fo_fasync,
-+ /* not needed: lock: mini_fo_lock, */
-+ /* not needed: readv */
-+ /* not needed: writev */
-+ /* not implemented: sendpage */
-+ /* not implemented: get_unmapped_area */
-+ };
-Index: linux-2.6.21.7/fs/mini_fo/fist.h
-===================================================================
---- /dev/null
-+++ linux-2.6.21.7/fs/mini_fo/fist.h
-@@ -0,0 +1,252 @@
-+/*
-+ * Copyright (c) 1997-2003 Erez Zadok
-+ * Copyright (c) 2001-2003 Stony Brook University
-+ *
-+ * For specific licensing information, see the COPYING file distributed with
-+ * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
-+ *
-+ * This Copyright notice must be kept intact and distributed with all
-+ * fistgen sources INCLUDING sources generated by fistgen.
-+ */
-+/*
-+ * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
-+ *
-+ * 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.
-+ */
-+
-+
-+/*
-+ * $Id$
-+ */
-+
-+#ifndef __FIST_H_
-+#define __FIST_H_
-+
-+/*
-+ * KERNEL ONLY CODE:
-+ */
-+#ifdef __KERNEL__
-+#include <linux/version.h>
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,19)
-+#include <linux/autoconf.h>
-+#else
-+#include <linux/config.h>
-+#endif
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
-+#ifdef CONFIG_MODVERSIONS
-+# define MODVERSIONS
-+# include <linux/modversions.h>
-+#endif /* CONFIG_MODVERSIONS */
-+#endif /* KERNEL_VERSION < 2.6.0 */
-+#include <linux/sched.h>
-+#include <linux/kernel.h>
-+#include <linux/mm.h>
-+#include <linux/string.h>
-+#include <linux/stat.h>
-+#include <linux/errno.h>
-+#include <linux/wait.h>
-+#include <linux/limits.h>
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
-+#include <linux/locks.h>
-+#else
-+#include <linux/buffer_head.h>
-+#include <linux/pagemap.h>
-+#include <linux/namei.h>
-+#include <linux/module.h>
-+#include <linux/mount.h>
-+#include <linux/page-flags.h>
-+#include <linux/writeback.h>
-+#include <linux/statfs.h>
-+#endif
-+#include <linux/smp.h>
-+#include <linux/smp_lock.h>
-+#include <linux/file.h>
-+#include <linux/slab.h>
-+#include <linux/vmalloc.h>
-+#include <linux/poll.h>
-+#include <linux/list.h>
-+#include <linux/init.h>
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20)
-+#include <linux/xattr.h>
-+#endif
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
-+#include <linux/security.h>
-+#endif
-+
-+#include <linux/swap.h>
-+
-+#include <asm/system.h>
-+/* #include <asm/segment.h> */
-+#include <asm/mman.h>
-+#include <linux/seq_file.h>
-+
-+/*
-+ * MACROS:
-+ */
-+
-+/* those mapped to ATTR_* were copied from linux/fs.h */
-+#define FA_MODE ATTR_MODE
-+#define FA_UID ATTR_UID
-+#define FA_GID ATTR_GID
-+#define FA_SIZE ATTR_SIZE
-+#define FA_ATIME ATTR_ATIME
-+#define FA_MTIME ATTR_MTIME
-+#define FA_CTIME ATTR_CTIME
-+#define FA_ATIME_SET ATTR_ATIME_SET
-+#define FA_MTIME_SET ATTR_MTIME_SET
-+#define FA_FORCE ATTR_FORCE
-+#define FA_ATTR_FLAGS ATTR_ATTR_FLAG
-+
-+/* must be greater than all other ATTR_* flags! */
-+#define FA_NLINK 2048
-+#define FA_BLKSIZE 4096
-+#define FA_BLOCKS 8192
-+#define FA_TIMES (FA_ATIME|FA_MTIME|FA_CTIME)
-+#define FA_ALL 0
-+
-+/* macros to manage changes between kernels */
-+#define INODE_DATA(i) (&(i)->i_data)
-+
-+#define MIN(x,y) ((x < y) ? (x) : (y))
-+#define MAX(x,y) ((x > y) ? (x) : (y))
-+#define MAXPATHLEN PATH_MAX
-+
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,5)
-+# define lookup_one_len(a,b,c) lookup_one(a,b)
-+#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,4,5) */
-+
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,8)
-+# define generic_file_llseek default_llseek
-+#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,4,8) */
-+
-+#ifndef SEEK_SET
-+# define SEEK_SET 0
-+#endif /* not SEEK_SET */
-+
-+#ifndef SEEK_CUR
-+# define SEEK_CUR 1
-+#endif /* not SEEK_CUR */
-+
-+#ifndef SEEK_END
-+# define SEEK_END 2
-+#endif /* not SEEK_END */
-+
-+#ifndef DEFAULT_POLLMASK
-+# define DEFAULT_POLLMASK (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM)
-+#endif /* not DEFAULT_POLLMASK */
-+
-+/* XXX: fix this so fistgen generates kfree() code directly */
-+#define kfree_s(a,b) kfree(a)
-+
-+/*
-+ * TYPEDEFS:
-+ */
-+typedef struct dentry dentry_t;
-+typedef struct file file_t;
-+typedef struct inode inode_t;
-+typedef inode_t vnode_t;
-+typedef struct page page_t;
-+typedef struct qstr qstr_t;
-+typedef struct super_block super_block_t;
-+typedef super_block_t vfs_t;
-+typedef struct vm_area_struct vm_area_t;
-+
-+
-+/*
-+ * EXTERNALS:
-+ */
-+
-+#define FPPF(str,page) printk("PPF %s 0x%x/%d: Lck:%d Err:%d Ref:%d Upd:%d Other::%d:%d:%d:%d:\n", \
-+ str, \
-+ (int) page, \
-+ (int) page->index, \
-+ (PageLocked(page) ? 1 : 0), \
-+ (PageError(page) ? 1 : 0), \
-+ (PageReferenced(page) ? 1 : 0), \
-+ (Page_Uptodate(page) ? 1 : 0), \
-+ (PageDecrAfter(page) ? 1 : 0), \
-+ (PageSlab(page) ? 1 : 0), \
-+ (PageSwapCache(page) ? 1 : 0), \
-+ (PageReserved(page) ? 1 : 0) \
-+ )
-+#define EZKDBG printk("EZK %s:%d:%s\n",__FILE__,__LINE__,__FUNCTION__)
-+#if 0
-+# define EZKDBG1 printk("EZK %s:%d\n",__FILE__,__LINE__)
-+#else
-+# define EZKDBG1
-+#endif
-+
-+extern int fist_get_debug_value(void);
-+extern int fist_set_debug_value(int val);
-+#if 0 /* mini_fo doesn't need these */
-+extern void fist_dprint_internal(int level, char *str,...);
-+extern void fist_print_dentry(char *str, const dentry_t *dentry);
-+extern void fist_print_inode(char *str, const inode_t *inode);
-+extern void fist_print_file(char *str, const file_t *file);
-+extern void fist_print_buffer_flags(char *str, struct buffer_head *buffer);
-+extern void fist_print_page_flags(char *str, page_t *page);
-+extern void fist_print_page_bytes(char *str, page_t *page);
-+extern void fist_print_pte_flags(char *str, const page_t *page);
-+extern void fist_checkinode(inode_t *inode, char *msg);
-+extern void fist_print_sb(char *str, const super_block_t *sb);
-+
-+/* §$% by mk: special debug functions */
-+extern void fist_mk_print_dentry(char *str, const dentry_t *dentry);
-+extern void fist_mk_print_inode(char *str, const inode_t *inode);
-+
-+extern char *add_indent(void);
-+extern char *del_indent(void);
-+#endif/* mini_fo doesn't need these */
-+
-+
-+#define STATIC
-+#define ASSERT(EX) \
-+do { \
-+ if (!(EX)) { \
-+ printk(KERN_CRIT "ASSERTION FAILED: %s at %s:%d (%s)\n", #EX, \
-+ __FILE__, __LINE__, __FUNCTION__); \
-+ (*((char *)0))=0; \
-+ } \
-+} while (0)
-+/* same ASSERT, but tell me who was the caller of the function */
-+#define ASSERT2(EX) \
-+do { \
-+ if (!(EX)) { \
-+ printk(KERN_CRIT "ASSERTION FAILED (caller): %s at %s:%d (%s)\n", #EX, \
-+ file, line, func); \
-+ (*((char *)0))=0; \
-+ } \
-+} while (0)
-+
-+#if 0 /* mini_fo doesn't need these */
-+#define dprintk(format, args...) printk(KERN_DEBUG format, ##args)
-+#define fist_dprint(level, str, args...) fist_dprint_internal(level, KERN_DEBUG str, ## args)
-+#define print_entry_location() fist_dprint(4, "%sIN: %s %s:%d\n", add_indent(), __FUNCTION__, __FILE__, __LINE__)
-+#define print_exit_location() fist_dprint(4, "%s OUT: %s %s:%d\n", del_indent(), __FUNCTION__, __FILE__, __LINE__)
-+#define print_exit_status(status) fist_dprint(4, "%s OUT: %s %s:%d, STATUS: %d\n", del_indent(), __FUNCTION__, __FILE__, __LINE__, status)
-+#define print_exit_pointer(status) \
-+do { \
-+ if (IS_ERR(status)) \
-+ fist_dprint(4, "%s OUT: %s %s:%d, RESULT: %ld\n", del_indent(), __FUNCTION__, __FILE__, __LINE__, PTR_ERR(status)); \
-+ else \
-+ fist_dprint(4, "%s OUT: %s %s:%d, RESULT: 0x%x\n", del_indent(), __FUNCTION__, __FILE__, __LINE__, PTR_ERR(status)); \
-+} while (0)
-+#endif/* mini_fo doesn't need these */
-+
-+#endif /* __KERNEL__ */
-+
-+
-+/*
-+ * DEFINITIONS FOR USER AND KERNEL CODE:
-+ * (Note: ioctl numbers 1--9 are reserved for fistgen, the rest
-+ * are auto-generated automatically based on the user's .fist file.)
-+ */
-+# define FIST_IOCTL_GET_DEBUG_VALUE _IOR(0x15, 1, int)
-+# define FIST_IOCTL_SET_DEBUG_VALUE _IOW(0x15, 2, int)
-+
-+#endif /* not __FIST_H_ */
-Index: linux-2.6.21.7/fs/mini_fo/inode.c
-===================================================================
---- /dev/null
-+++ linux-2.6.21.7/fs/mini_fo/inode.c
-@@ -0,0 +1,1564 @@
-+/*
-+ * Copyright (c) 1997-2003 Erez Zadok
-+ * Copyright (c) 2001-2003 Stony Brook University
-+ *
-+ * For specific licensing information, see the COPYING file distributed with
-+ * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
-+ *
-+ * This Copyright notice must be kept intact and distributed with all
-+ * fistgen sources INCLUDING sources generated by fistgen.
-+ */
-+/*
-+ * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
-+ *
-+ * 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.
-+ */
-+
-+/*
-+ * $Id$
-+ */
-+
-+#ifdef HAVE_CONFIG_H
-+# include <config.h>
-+#endif
-+
-+#include "fist.h"
-+#include "mini_fo.h"
-+
-+STATIC int
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
-+mini_fo_create(inode_t *dir, dentry_t *dentry, int mode, struct nameidata *nd)
-+#else
-+mini_fo_create(inode_t *dir, dentry_t *dentry, int mode)
-+#endif
-+{
-+ int err = 0;
-+
-+ check_mini_fo_dentry(dentry);
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
-+ err = create_sto_reg_file(dentry, mode, nd);
-+#else
-+ err = create_sto_reg_file(dentry, mode);
-+#endif
-+ check_mini_fo_dentry(dentry);
-+ return err;
-+}
-+
-+
-+STATIC dentry_t *
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
-+mini_fo_lookup(inode_t *dir, dentry_t *dentry, struct nameidata* nd)
-+#else
-+mini_fo_lookup(inode_t *dir, dentry_t *dentry)
-+#endif
-+{
-+ int err = 0;
-+ dentry_t *hidden_dir_dentry;
-+ dentry_t *hidden_dentry = NULL;
-+
-+ dentry_t *hidden_sto_dir_dentry;
-+ dentry_t *hidden_sto_dentry = NULL;
-+
-+ /* whiteout flag */
-+ int del_flag = 0;
-+ char *bpath = NULL;
-+
-+ const char *name;
-+ unsigned int namelen;
-+
-+ /* Don't allow lookups of META-files */
-+ namelen = strlen(META_FILENAME);
-+ if(namelen == dentry->d_name.len) {
-+ if(!strncmp(dentry->d_name.name, META_FILENAME, namelen)) {
-+ err = -ENOENT;
-+ goto out;
-+ }
-+ }
-+
-+ hidden_dir_dentry = dtohd(dentry->d_parent);
-+ hidden_sto_dir_dentry = dtohd2(dentry->d_parent);
-+
-+ name = dentry->d_name.name;
-+ namelen = dentry->d_name.len;
-+
-+ /* must initialize dentry operations */
-+ dentry->d_op = &mini_fo_dops;
-+
-+ /* setup the del_flag */
-+ del_flag = __meta_check_d_entry(dir, name, namelen);
-+ bpath = __meta_check_r_entry(dir, name, namelen);
-+
-+ /* perform the lookups of base and storage files:
-+ *
-+ * This caused some serious trouble, as a lookup_one_len passing
-+ * a negative dentry oopses. Solution is to only do the lookup
-+ * if the dentry is positive, else we set it to NULL
-+ * More trouble, who said a *_dir_dentry can't be NULL?
-+ */
-+ if(bpath) {
-+ /* Cross-Interposing (C), yeah! */
-+ hidden_dentry = bpath_walk(dir->i_sb, bpath);
-+ if(!hidden_dentry || !hidden_dentry->d_inode) {
-+ printk(KERN_CRIT "mini_fo_lookup: bpath_walk failed.\n");
-+ err= -EINVAL;
-+ goto out;
-+ }
-+
-+ /* this can be set up safely without fear of spaghetti
-+ * interposing as it is only used for copying times */
-+ hidden_dir_dentry = hidden_dentry->d_parent;
-+ kfree(bpath);
-+ }
-+ else if(hidden_dir_dentry && hidden_dir_dentry->d_inode)
-+ hidden_dentry =
-+ lookup_one_len(name, hidden_dir_dentry, namelen);
-+ else
-+ hidden_dentry = NULL;
-+
-+ if(hidden_sto_dir_dentry && hidden_sto_dir_dentry->d_inode)
-+ hidden_sto_dentry =
-+ lookup_one_len(name, hidden_sto_dir_dentry, namelen);
-+ else
-+ hidden_sto_dentry = NULL;
-+
-+ /* catch error in lookup */
-+ if (IS_ERR(hidden_dentry) || IS_ERR(hidden_sto_dentry)) {
-+ /* mk: we need to call dput on the dentry, whose
-+ * lookup_one_len operation failed, in order to avoid
-+ * unmount trouble.
-+ */
-+ if(IS_ERR(hidden_dentry)) {
-+ printk(KERN_CRIT "mini_fo_lookup: ERR from base dentry, lookup failed.\n");
-+ err = PTR_ERR(hidden_dentry);
-+ } else {
-+ dput(hidden_dentry);
-+ }
-+ if(IS_ERR(hidden_sto_dentry)) {
-+ printk(KERN_CRIT "mini_fo_lookup: ERR from storage dentry, lookup failed.\n");
-+ err = PTR_ERR(hidden_sto_dentry);
-+ } else {
-+ dput(hidden_sto_dentry);
-+ }
-+ goto out;
-+ }
-+
-+ /* allocate dentry private data */
-+ __dtopd(dentry) = (struct mini_fo_dentry_info *)
-+ kmalloc(sizeof(struct mini_fo_dentry_info), GFP_KERNEL);
-+
-+ if (!dtopd(dentry)) {
-+ err = -ENOMEM;
-+ goto out_dput;
-+ }
-+
-+ /* check for different states of the mini_fo file to be looked up. */
-+
-+ /* state 1, file has been modified */
-+ if(hidden_dentry && hidden_sto_dentry &&
-+ hidden_dentry->d_inode && hidden_sto_dentry->d_inode && !del_flag) {
-+
-+ /* update parent directory's atime */
-+ fist_copy_attr_atime(dir, hidden_sto_dir_dentry->d_inode);
-+
-+ dtopd(dentry)->state = MODIFIED;
-+ dtohd(dentry) = hidden_dentry;
-+ dtohd2(dentry) = hidden_sto_dentry;
-+
-+ err = mini_fo_tri_interpose(hidden_dentry,
-+ hidden_sto_dentry,
-+ dentry, dir->i_sb, 1);
-+ if (err) {
-+ printk(KERN_CRIT "mini_fo_lookup: error interposing (state1).\n");
-+ goto out_free;
-+ }
-+ goto out;
-+ }
-+ /* state 2, file is unmodified */
-+ if(hidden_dentry && hidden_dentry->d_inode && !del_flag) {
-+
-+ fist_copy_attr_atime(dir, hidden_dir_dentry->d_inode);
-+
-+ dtopd(dentry)->state = UNMODIFIED;
-+ dtohd(dentry) = hidden_dentry;
-+ dtohd2(dentry) = hidden_sto_dentry; /* could be negative */
-+
-+ err = mini_fo_tri_interpose(hidden_dentry,
-+ hidden_sto_dentry,
-+ dentry, dir->i_sb, 1);
-+ if (err) {
-+ printk(KERN_CRIT "mini_fo_lookup: error interposing (state2).\n");
-+ goto out_free;
-+ }
-+ goto out;
-+ }
-+ /* state 3, file has been newly created */
-+ if(hidden_sto_dentry && hidden_sto_dentry->d_inode && !del_flag) {
-+
-+ fist_copy_attr_atime(dir, hidden_sto_dir_dentry->d_inode);
-+ dtopd(dentry)->state = CREATED;
-+ dtohd(dentry) = hidden_dentry; /* could be negative */
-+ dtohd2(dentry) = hidden_sto_dentry;
-+
-+ err = mini_fo_tri_interpose(hidden_dentry,
-+ hidden_sto_dentry,
-+ dentry, dir->i_sb, 1);
-+ if (err) {
-+ printk(KERN_CRIT "mini_fo_lookup: error interposing (state3).\n");
-+ goto out_free;
-+ }
-+ goto out;
-+ }
-+
-+ /* state 4, file has deleted and created again. */
-+ if(hidden_dentry && hidden_sto_dentry &&
-+ hidden_dentry->d_inode &&
-+ hidden_sto_dentry->d_inode && del_flag) {
-+
-+ fist_copy_attr_atime(dir, hidden_sto_dir_dentry->d_inode);
-+ dtopd(dentry)->state = DEL_REWRITTEN;
-+ dtohd(dentry) = NULL;
-+ dtohd2(dentry) = hidden_sto_dentry;
-+
-+ err = mini_fo_tri_interpose(NULL,
-+ hidden_sto_dentry,
-+ dentry, dir->i_sb, 1);
-+ if (err) {
-+ printk(KERN_CRIT "mini_fo_lookup: error interposing (state4).\n");
-+ goto out_free;
-+ }
-+ /* We will never need this dentry again, as the file has been
-+ * deleted from base */
-+ dput(hidden_dentry);
-+ goto out;
-+ }
-+ /* state 5, file has been deleted in base */
-+ if(hidden_dentry && hidden_sto_dentry &&
-+ hidden_dentry->d_inode &&
-+ !hidden_sto_dentry->d_inode && del_flag) {
-+
-+ /* check which parents atime we need for updating */
-+ if(hidden_sto_dir_dentry->d_inode)
-+ fist_copy_attr_atime(dir,
-+ hidden_sto_dir_dentry->d_inode);
-+ else
-+ fist_copy_attr_atime(dir,
-+ hidden_dir_dentry->d_inode);
-+
-+ dtopd(dentry)->state = DELETED;
-+ dtohd(dentry) = NULL;
-+ dtohd2(dentry) = hidden_sto_dentry;
-+
-+ /* add negative dentry to dcache to speed up lookups */
-+ d_add(dentry, NULL);
-+ dput(hidden_dentry);
-+ goto out;
-+ }
-+ /* state 6, file does not exist */
-+ if(((hidden_dentry && !hidden_dentry->d_inode) ||
-+ (hidden_sto_dentry && !hidden_sto_dentry->d_inode)) && !del_flag)
-+ {
-+ /* check which parents atime we need for updating */
-+ if(hidden_sto_dir_dentry && hidden_sto_dir_dentry->d_inode)
-+ fist_copy_attr_atime(dir, hidden_sto_dir_dentry->d_inode);
-+ else
-+ fist_copy_attr_atime(dir, hidden_dir_dentry->d_inode);
-+
-+ dtopd(dentry)->state = NON_EXISTANT;
-+ dtohd(dentry) = hidden_dentry;
-+ dtohd2(dentry) = hidden_sto_dentry;
-+ d_add(dentry, NULL);
-+ goto out;
-+ }
-+
-+ /* if we get to here, were in an invalid state. bad. */
-+ printk(KERN_CRIT "mini_fo_lookup: ERROR, meta data corruption detected.\n");
-+
-+ /* end state checking */
-+ out_free:
-+ d_drop(dentry); /* so that our bad dentry will get destroyed */
-+ kfree(dtopd(dentry));
-+ __dtopd(dentry) = NULL; /* be safe */
-+
-+ out_dput:
-+ if(hidden_dentry)
-+ dput(hidden_dentry);
-+ if(hidden_sto_dentry)
-+ dput(hidden_sto_dentry); /* drops usage count and marks for release */
-+
-+ out:
-+ /* initalize wol if file exists and is directory */
-+ if(dentry->d_inode) {
-+ if(S_ISDIR(dentry->d_inode->i_mode)) {
-+ itopd(dentry->d_inode)->deleted_list_size = -1;
-+ itopd(dentry->d_inode)->renamed_list_size = -1;
-+ meta_build_lists(dentry);
-+ }
-+ }
-+ return ERR_PTR(err);
-+}
-+
-+
-+STATIC int
-+mini_fo_link(dentry_t *old_dentry, inode_t *dir, dentry_t *new_dentry)
-+{
-+ int err;
-+ dentry_t *hidden_old_dentry;
-+ dentry_t *hidden_new_dentry;
-+ dentry_t *hidden_dir_dentry;
-+
-+
-+ check_mini_fo_dentry(old_dentry);
-+ check_mini_fo_dentry(new_dentry);
-+ check_mini_fo_inode(dir);
-+
-+ /* no links to directorys and existing targets target allowed */
-+ if(S_ISDIR(old_dentry->d_inode->i_mode) ||
-+ is_mini_fo_existant(new_dentry)) {
-+ err = -EPERM;
-+ goto out;
-+ }
-+
-+ /* bring it directly from unmod to del_rew */
-+ if(dtost(old_dentry) == UNMODIFIED) {
-+ err = nondir_unmod_to_mod(old_dentry, 1);
-+ if(err) {
-+ err = -EINVAL;
-+ goto out;
-+ }
-+ err = meta_add_d_entry(old_dentry->d_parent,
-+ old_dentry->d_name.name,
-+ old_dentry->d_name.len);
-+ if(err) {
-+ err = -EINVAL;
-+ goto out;
-+ }
-+ dput(dtohd(old_dentry));
-+ dtohd(old_dentry) = NULL;
-+ dtost(old_dentry) = DEL_REWRITTEN;
-+ }
-+
-+ err = get_neg_sto_dentry(new_dentry);
-+ if(err) {
-+ err = -EINVAL;
-+ goto out;
-+ }
-+
-+ hidden_old_dentry = dtohd2(old_dentry);
-+ hidden_new_dentry = dtohd2(new_dentry);
-+
-+ dget(hidden_old_dentry);
-+ dget(hidden_new_dentry);
-+
-+ /* was: hidden_dir_dentry = lock_parent(hidden_new_dentry); */
-+ hidden_dir_dentry = dget(hidden_new_dentry->d_parent);
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_lock(&hidden_dir_dentry->d_inode->i_mutex);
-+#else
-+ down(&hidden_dir_dentry->d_inode->i_sem);
-+#endif
-+
-+ err = vfs_link(hidden_old_dentry,
-+ hidden_dir_dentry->d_inode,
-+ hidden_new_dentry);
-+ if (err || !hidden_new_dentry->d_inode)
-+ goto out_lock;
-+
-+ dtost(new_dentry) = CREATED;
-+ err = mini_fo_tri_interpose(NULL, hidden_new_dentry, new_dentry, dir->i_sb, 0);
-+ if (err)
-+ goto out_lock;
-+
-+ fist_copy_attr_timesizes(dir, hidden_new_dentry->d_inode);
-+ /* propagate number of hard-links */
-+ old_dentry->d_inode->i_nlink = itohi2(old_dentry->d_inode)->i_nlink;
-+
-+ out_lock:
-+ /* was: unlock_dir(hidden_dir_dentry); */
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_unlock(&hidden_dir_dentry->d_inode->i_mutex);
-+#else
-+ up(&hidden_dir_dentry->d_inode->i_sem);
-+#endif
-+ dput(hidden_dir_dentry);
-+
-+ dput(hidden_new_dentry);
-+ dput(hidden_old_dentry);
-+ if (!new_dentry->d_inode)
-+ d_drop(new_dentry);
-+
-+ out:
-+ return err;
-+}
-+
-+
-+STATIC int
-+mini_fo_unlink(inode_t *dir, dentry_t *dentry)
-+{
-+ int err = 0;
-+
-+ dget(dentry);
-+ if(dtopd(dentry)->state == MODIFIED) {
-+ err = nondir_mod_to_del(dentry);
-+ goto out;
-+ }
-+ else if(dtopd(dentry)->state == UNMODIFIED) {
-+ err = nondir_unmod_to_del(dentry);
-+ goto out;
-+ }
-+ else if(dtopd(dentry)->state == CREATED) {
-+ err = nondir_creat_to_del(dentry);
-+ goto out;
-+ }
-+ else if(dtopd(dentry)->state == DEL_REWRITTEN) {
-+ err = nondir_del_rew_to_del(dentry);
-+ goto out;
-+ }
-+
-+ printk(KERN_CRIT "mini_fo_unlink: ERROR, invalid state detected.\n");
-+
-+ out:
-+ fist_copy_attr_times(dir, itohi2(dentry->d_parent->d_inode));
-+
-+ if(!err) {
-+ /* is this causing my pain? d_delete(dentry); */
-+ d_drop(dentry);
-+ }
-+
-+ dput(dentry);
-+ return err;
-+}
-+
-+
-+STATIC int
-+mini_fo_symlink(inode_t *dir, dentry_t *dentry, const char *symname)
-+{
-+ int err=0;
-+ dentry_t *hidden_sto_dentry;
-+ dentry_t *hidden_sto_dir_dentry;
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
-+ umode_t mode;
-+#endif
-+
-+ /* Fail if the symlink file exists */
-+ if(!(dtost(dentry) == DELETED ||
-+ dtost(dentry) == NON_EXISTANT)) {
-+ err = -EEXIST;
-+ goto out;
-+ }
-+
-+ err = get_neg_sto_dentry(dentry);
-+ if(err) {
-+ err = -EINVAL;
-+ goto out;
-+ }
-+ hidden_sto_dentry = dtohd2(dentry);
-+
-+ dget(hidden_sto_dentry);
-+ /* was: hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry); */
-+ hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
-+#else
-+ down(&hidden_sto_dir_dentry->d_inode->i_sem);
-+#endif
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
-+ mode = S_IALLUGO;
-+ err = vfs_symlink(hidden_sto_dir_dentry->d_inode,
-+ hidden_sto_dentry, symname, mode);
-+#else
-+ err = vfs_symlink(hidden_sto_dir_dentry->d_inode,
-+ hidden_sto_dentry,
-+ symname);
-+#endif
-+ if (err || !hidden_sto_dentry->d_inode)
-+ goto out_lock;
-+
-+ if(dtost(dentry) == DELETED) {
-+ dtost(dentry) = DEL_REWRITTEN;
-+ err = mini_fo_tri_interpose(NULL, hidden_sto_dentry, dentry, dir->i_sb, 0);
-+ if(err)
-+ goto out_lock;
-+ } else if(dtost(dentry) == NON_EXISTANT) {
-+ dtost(dentry) = CREATED;
-+ err = mini_fo_tri_interpose(dtohd(dentry), hidden_sto_dentry, dentry, dir->i_sb, 0);
-+ if(err)
-+ goto out_lock;
-+ }
-+ fist_copy_attr_timesizes(dir, hidden_sto_dir_dentry->d_inode);
-+
-+ out_lock:
-+ /* was: unlock_dir(hidden_sto_dir_dentry); */
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
-+#else
-+ up(&hidden_sto_dir_dentry->d_inode->i_sem);
-+#endif
-+ dput(hidden_sto_dir_dentry);
-+
-+ dput(hidden_sto_dentry);
-+ if (!dentry->d_inode)
-+ d_drop(dentry);
-+ out:
-+ return err;
-+}
-+
-+STATIC int
-+mini_fo_mkdir(inode_t *dir, dentry_t *dentry, int mode)
-+{
-+ int err;
-+
-+ err = create_sto_dir(dentry, mode);
-+
-+ check_mini_fo_dentry(dentry);
-+
-+ return err;
-+}
-+
-+
-+STATIC int
-+mini_fo_rmdir(inode_t *dir, dentry_t *dentry)
-+{
-+ int err = 0;
-+
-+ dentry_t *hidden_sto_dentry;
-+ dentry_t *hidden_sto_dir_dentry;
-+ dentry_t *meta_dentry;
-+ inode_t *hidden_sto_dir = NULL;
-+
-+ check_mini_fo_dentry(dentry);
-+ check_mini_fo_inode(dir);
-+
-+ dget(dentry);
-+ if(dtopd(dentry)->state == MODIFIED) {
-+ /* XXX: disabled, because it does not bother to check files on
-+ * the original filesystem - just a hack, but better than simply
-+ * removing it without testing */
-+ err = -EINVAL;
-+ goto out;
-+
-+ hidden_sto_dir = itohi2(dir);
-+ hidden_sto_dentry = dtohd2(dentry);
-+
-+ /* was:hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry); */
-+ hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
-+#else
-+ down(&hidden_sto_dir_dentry->d_inode->i_sem);
-+#endif
-+
-+ /* Delete an old WOL file contained in the storage dir */
-+ meta_dentry = lookup_one_len(META_FILENAME,
-+ hidden_sto_dentry,
-+ strlen(META_FILENAME));
-+ if(meta_dentry->d_inode) {
-+ err = vfs_unlink(hidden_sto_dentry->d_inode, meta_dentry);
-+ dput(meta_dentry);
-+ if(!err)
-+ d_delete(meta_dentry);
-+ }
-+
-+ err = vfs_rmdir(hidden_sto_dir, hidden_sto_dentry);
-+ dput(hidden_sto_dentry);
-+ if(!err)
-+ d_delete(hidden_sto_dentry);
-+
-+ /* propagate number of hard-links */
-+ dentry->d_inode->i_nlink = itohi2(dentry->d_inode)->i_nlink;
-+
-+ dput(dtohd(dentry));
-+
-+ dtohd(dentry) = NULL;
-+ dtopd(dentry)->state = DELETED;
-+
-+ /* carefull with R files */
-+ if( __meta_is_r_entry(dir,
-+ dentry->d_name.name,
-+ dentry->d_name.len) == 1) {
-+ err = meta_remove_r_entry(dentry->d_parent,
-+ dentry->d_name.name,
-+ dentry->d_name.len);
-+ if(err) {
-+ printk(KERN_CRIT "mini_fo: rmdir: meta_remove_r_entry failed.\n");
-+ goto out;
-+ }
-+ }
-+ else {
-+ /* ok, add deleted file to META */
-+ meta_add_d_entry(dentry->d_parent,
-+ dentry->d_name.name,
-+ dentry->d_name.len);
-+ }
-+ /* was: unlock_dir(hidden_sto_dir_dentry); */
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
-+#else
-+ up(&hidden_sto_dir_dentry->d_inode->i_sem);
-+#endif
-+ dput(hidden_sto_dir_dentry);
-+ goto out;
-+ }
-+ else if(dtopd(dentry)->state == UNMODIFIED) {
-+ /* XXX: simply adding it to the delete list here is fscking dangerous!
-+ * as a temporary hack, i will disable rmdir on unmodified directories
-+ * for now.
-+ */
-+ err = -EINVAL;
-+ goto out;
-+
-+ err = get_neg_sto_dentry(dentry);
-+ if(err) {
-+ err = -EINVAL;
-+ goto out;
-+ }
-+
-+ /* dput base dentry, this will relase the inode and free the
-+ * dentry, as we will never need it again. */
-+ dput(dtohd(dentry));
-+ dtohd(dentry) = NULL;
-+ dtopd(dentry)->state = DELETED;
-+
-+ /* add deleted file to META-file */
-+ meta_add_d_entry(dentry->d_parent,
-+ dentry->d_name.name,
-+ dentry->d_name.len);
-+ goto out;
-+ }
-+ else if(dtopd(dentry)->state == CREATED) {
-+ hidden_sto_dir = itohi2(dir);
-+ hidden_sto_dentry = dtohd2(dentry);
-+
-+ /* was: hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry);*/
-+ hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
-+#else
-+ down(&hidden_sto_dir_dentry->d_inode->i_sem);
-+#endif
-+
-+ /* Delete an old WOL file contained in the storage dir */
-+ meta_dentry = lookup_one_len(META_FILENAME,
-+ hidden_sto_dentry,
-+ strlen(META_FILENAME));
-+ if(meta_dentry->d_inode) {
-+ /* is this necessary? dget(meta_dentry); */
-+ err = vfs_unlink(hidden_sto_dentry->d_inode,
-+ meta_dentry);
-+ dput(meta_dentry);
-+ if(!err)
-+ d_delete(meta_dentry);
-+ }
-+
-+ err = vfs_rmdir(hidden_sto_dir, hidden_sto_dentry);
-+ dput(hidden_sto_dentry);
-+ if(!err)
-+ d_delete(hidden_sto_dentry);
-+
-+ /* propagate number of hard-links */
-+ dentry->d_inode->i_nlink = itohi2(dentry->d_inode)->i_nlink;
-+ dtopd(dentry)->state = NON_EXISTANT;
-+
-+ /* was: unlock_dir(hidden_sto_dir_dentry); */
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
-+#else
-+ up(&hidden_sto_dir_dentry->d_inode->i_sem);
-+#endif
-+ dput(hidden_sto_dir_dentry);
-+
-+ goto out;
-+ }
-+ else if(dtopd(dentry)->state == DEL_REWRITTEN) {
-+ hidden_sto_dir = itohi2(dir);
-+ hidden_sto_dentry = dtohd2(dentry);
-+
-+ /* was: hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry);*/
-+ hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
-+#else
-+ down(&hidden_sto_dir_dentry->d_inode->i_sem);
-+#endif
-+
-+ /* Delete an old WOL file contained in the storage dir */
-+ meta_dentry = lookup_one_len(META_FILENAME,
-+ hidden_sto_dentry,
-+ strlen(META_FILENAME));
-+ if(meta_dentry->d_inode) {
-+ /* is this necessary? dget(meta_dentry); */
-+ err = vfs_unlink(hidden_sto_dentry->d_inode,
-+ meta_dentry);
-+ dput(meta_dentry);
-+ if(!err)
-+ d_delete(meta_dentry);
-+ }
-+
-+ err = vfs_rmdir(hidden_sto_dir, hidden_sto_dentry);
-+ dput(hidden_sto_dentry);
-+ if(!err)
-+ d_delete(hidden_sto_dentry);
-+
-+ /* propagate number of hard-links */
-+ dentry->d_inode->i_nlink = itohi2(dentry->d_inode)->i_nlink;
-+ dtopd(dentry)->state = DELETED;
-+ /* was: unlock_dir(hidden_sto_dir_dentry); */
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
-+#else
-+ up(&hidden_sto_dir_dentry->d_inode->i_sem);
-+#endif
-+ dput(hidden_sto_dir_dentry);
-+ goto out;
-+ }
-+
-+ printk(KERN_CRIT "mini_fo_rmdir: ERROR, invalid state detected.\n");
-+
-+ out:
-+ if(!err) {
-+ d_drop(dentry);
-+ }
-+
-+ fist_copy_attr_times(dir, itohi2(dentry->d_parent->d_inode));
-+ dput(dentry);
-+
-+ return err;
-+}
-+
-+
-+STATIC int
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
-+mini_fo_mknod(inode_t *dir, dentry_t *dentry, int mode, dev_t dev)
-+#else
-+mini_fo_mknod(inode_t *dir, dentry_t *dentry, int mode, int dev)
-+#endif
-+{
-+ int err = 0;
-+
-+ check_mini_fo_dentry(dentry);
-+
-+ err = create_sto_nod(dentry, mode, dev);
-+ if(err) {
-+ printk(KERN_CRIT "mini_fo_mknod: creating sto nod failed.\n");
-+ err = -EINVAL;
-+ }
-+
-+ check_mini_fo_dentry(dentry);
-+ return err;
-+}
-+
-+
-+STATIC int
-+mini_fo_rename(inode_t *old_dir, dentry_t *old_dentry,
-+ inode_t *new_dir, dentry_t *new_dentry)
-+{
-+ /* dispatch */
-+ if(S_ISDIR(old_dentry->d_inode->i_mode))
-+ return rename_directory(old_dir, old_dentry, new_dir, new_dentry);
-+ return rename_nondir(old_dir, old_dentry, new_dir, new_dentry);
-+
-+}
-+
-+int rename_directory(inode_t *old_dir, dentry_t *old_dentry,
-+ inode_t *new_dir, dentry_t *new_dentry)
-+{
-+ int err, bpath_len;
-+ char *bpath;
-+
-+ dentry_t *hidden_old_dentry;
-+ dentry_t *hidden_new_dentry;
-+ dentry_t *hidden_old_dir_dentry;
-+ dentry_t *hidden_new_dir_dentry;
-+
-+ err = 0;
-+ bpath = NULL;
-+ bpath_len = 0;
-+
-+ /* this is a test, chuck out if it works */
-+ if(!(dtopd(new_dentry)->state == DELETED ||
-+ dtopd(new_dentry)->state == NON_EXISTANT)) {
-+ printk(KERN_CRIT "mini_fo: rename_directory: \
-+ uh, ah, new_dentry not negative.\n");
-+ /* return -1; */
-+ }
-+
-+ /* state = UNMODIFIED */
-+ if(dtopd(old_dentry)->state == UNMODIFIED) {
-+ err = dir_unmod_to_mod(old_dentry);
-+ if (err)
-+ goto out;
-+ }
-+
-+ /* state = MODIFIED */
-+ if(dtopd(old_dentry)->state == MODIFIED) {
-+ bpath = meta_check_r_entry(old_dentry->d_parent,
-+ old_dentry->d_name.name,
-+ old_dentry->d_name.len);
-+ if(bpath) {
-+ err = meta_remove_r_entry(old_dentry->d_parent,
-+ old_dentry->d_name.name,
-+ old_dentry->d_name.len);
-+ if(err) {
-+ printk(KERN_CRIT "mini_fo: rename_directory:\
-+ meta_remove_r_entry \
-+ failed.\n");
-+ goto out;
-+ }
-+ err = meta_add_r_entry(new_dentry->d_parent,
-+ bpath,
-+ strlen(bpath),
-+ new_dentry->d_name.name,
-+ new_dentry->d_name.len);
-+ kfree(bpath);
-+ }
-+ else {/* wol it */
-+ err = meta_add_d_entry(old_dentry->d_parent,
-+ old_dentry->d_name.name,
-+ old_dentry->d_name.len);
-+ if (err)
-+ goto out;
-+ /* put it on rename list */
-+ err = get_mini_fo_bpath(old_dentry,
-+ &bpath,
-+ &bpath_len);
-+ if (err)
-+ goto out;
-+ err = meta_add_r_entry(new_dentry->d_parent,
-+ bpath, bpath_len,
-+ new_dentry->d_name.name,
-+ new_dentry->d_name.len);
-+ if (err)
-+ goto out;
-+ }
-+ /* no state change, MODIFIED stays MODIFIED */
-+ }
-+ /* state = CREATED */
-+ if(dtopd(old_dentry)->state == CREATED ||
-+ dtopd(old_dentry)->state == DEL_REWRITTEN) {
-+ if(dtohd(old_dentry))
-+ dput(dtohd(old_dentry));
-+
-+ if(dtopd(new_dentry)->state == DELETED) {
-+ dtopd(old_dentry)->state = DEL_REWRITTEN;
-+ dtohd(old_dentry) = NULL;
-+ }
-+ else if(dtopd(new_dentry)->state == NON_EXISTANT) {
-+ dtopd(old_dentry)->state = CREATED;
-+ /* steal new dentry's neg. base dentry */
-+ dtohd(old_dentry) = dtohd(new_dentry);
-+ dtohd(new_dentry) = NULL;
-+ }
-+ }
-+ if(dtopd(new_dentry)->state == UNMODIFIED ||
-+ dtopd(new_dentry)->state == NON_EXISTANT) {
-+ err = get_neg_sto_dentry(new_dentry);
-+ if(err)
-+ goto out;
-+ }
-+
-+ /* now move sto file */
-+ hidden_old_dentry = dtohd2(old_dentry);
-+ hidden_new_dentry = dtohd2(new_dentry);
-+
-+ dget(hidden_old_dentry);
-+ dget(hidden_new_dentry);
-+
-+ hidden_old_dir_dentry = dget(hidden_old_dentry->d_parent);
-+ hidden_new_dir_dentry = dget(hidden_new_dentry->d_parent);
-+ double_lock(hidden_old_dir_dentry, hidden_new_dir_dentry);
-+
-+ err = vfs_rename(hidden_old_dir_dentry->d_inode, hidden_old_dentry,
-+ hidden_new_dir_dentry->d_inode, hidden_new_dentry);
-+ if(err)
-+ goto out_lock;
-+
-+ fist_copy_attr_all(new_dir, hidden_new_dir_dentry->d_inode);
-+ if (new_dir != old_dir)
-+ fist_copy_attr_all(old_dir,
-+ hidden_old_dir_dentry->d_inode);
-+
-+ out_lock:
-+ /* double_unlock will dput the new/old parent dentries
-+ * whose refcnts were incremented via get_parent above. */
-+ double_unlock(hidden_old_dir_dentry, hidden_new_dir_dentry);
-+ dput(hidden_new_dentry);
-+ dput(hidden_old_dentry);
-+
-+ out:
-+ return err;
-+}
-+
-+int rename_nondir(inode_t *old_dir, dentry_t *old_dentry,
-+ inode_t *new_dir, dentry_t *new_dentry)
-+{
-+ int err=0;
-+
-+ check_mini_fo_dentry(old_dentry);
-+ check_mini_fo_dentry(new_dentry);
-+ check_mini_fo_inode(old_dir);
-+ check_mini_fo_inode(new_dir);
-+
-+ /* state: UNMODIFIED */
-+ if(dtost(old_dentry) == UNMODIFIED) {
-+ err = nondir_unmod_to_mod(old_dentry, 1);
-+ if(err) {
-+ err = -EINVAL;
-+ goto out;
-+ }
-+ }
-+
-+ /* the easy states */
-+ if(exists_in_storage(old_dentry)) {
-+
-+ dentry_t *hidden_old_dentry;
-+ dentry_t *hidden_new_dentry;
-+ dentry_t *hidden_old_dir_dentry;
-+ dentry_t *hidden_new_dir_dentry;
-+
-+ /* if old file is MODIFIED, add it to the deleted_list */
-+ if(dtopd(old_dentry)->state == MODIFIED) {
-+ meta_add_d_entry(old_dentry->d_parent,
-+ old_dentry->d_name.name,
-+ old_dentry->d_name.len);
-+
-+ dput(dtohd(old_dentry));
-+ }
-+ /* if old file is CREATED, we only release the base dentry */
-+ if(dtopd(old_dentry)->state == CREATED) {
-+ if(dtohd(old_dentry))
-+ dput(dtohd(old_dentry));
-+ }
-+
-+ /* now setup the new states (depends on new_dentry state) */
-+ /* new dentry state = MODIFIED */
-+ if(dtopd(new_dentry)->state == MODIFIED) {
-+ meta_add_d_entry(new_dentry->d_parent,
-+ new_dentry->d_name.name,
-+ new_dentry->d_name.len);
-+
-+ /* new dentry will be d_put'ed later by the vfs
-+ * so don't do it here
-+ * dput(dtohd(new_dentry));
-+ */
-+ dtohd(old_dentry) = NULL;
-+ dtopd(old_dentry)->state = DEL_REWRITTEN;
-+ }
-+ /* new dentry state = UNMODIFIED */
-+ else if(dtopd(new_dentry)->state == UNMODIFIED) {
-+ if(get_neg_sto_dentry(new_dentry))
-+ return -EINVAL;
-+
-+ meta_add_d_entry(new_dentry->d_parent,
-+ new_dentry->d_name.name,
-+ new_dentry->d_name.len);
-+
-+ /* is this right??? */
-+ /*dput(dtohd(new_dentry));*/
-+ dtohd(old_dentry) = NULL;
-+ dtopd(old_dentry)->state = DEL_REWRITTEN;
-+ }
-+ /* new dentry state = CREATED */
-+ else if(dtopd(new_dentry)->state == CREATED) {
-+ /* we keep the neg. base dentry (if exists) */
-+ dtohd(old_dentry) = dtohd(new_dentry);
-+ /* ...and set it to Null, or we'll get
-+ * dcache.c:345 if it gets dput twice... */
-+ dtohd(new_dentry) = NULL;
-+ dtopd(old_dentry)->state = CREATED;
-+ }
-+ /* new dentry state = NON_EXISTANT */
-+ else if(dtopd(new_dentry)->state == NON_EXISTANT) {
-+ if(get_neg_sto_dentry(new_dentry))
-+ return -EINVAL;
-+
-+ /* we keep the neg. base dentry (if exists) */
-+ dtohd(old_dentry) = dtohd(new_dentry);
-+ /* ...and set it to Null, or we'll get
-+ * Dr. dcache.c:345 if it gets dput twice... */
-+ dtohd(new_dentry) = NULL;
-+ dtopd(old_dentry)->state = CREATED;
-+ }
-+ /* new dentry state = DEL_REWRITTEN or DELETED */
-+ else if(dtopd(new_dentry)->state == DEL_REWRITTEN ||
-+ dtopd(new_dentry)->state == DELETED) {
-+ dtohd(old_dentry) = NULL;
-+ dtopd(old_dentry)->state = DEL_REWRITTEN;
-+ }
-+ else { /* not possible, uhh, ahh */
-+ printk(KERN_CRIT
-+ "mini_fo: rename_reg_file: invalid state detected [1].\n");
-+ return -1;
-+ }
-+
-+ /* now we definitely have a sto file */
-+ hidden_old_dentry = dtohd2(old_dentry);
-+ hidden_new_dentry = dtohd2(new_dentry);
-+
-+ dget(hidden_old_dentry);
-+ dget(hidden_new_dentry);
-+
-+ hidden_old_dir_dentry = dget(hidden_old_dentry->d_parent);
-+ hidden_new_dir_dentry = dget(hidden_new_dentry->d_parent);
-+ double_lock(hidden_old_dir_dentry, hidden_new_dir_dentry);
-+
-+ err = vfs_rename(hidden_old_dir_dentry->d_inode,
-+ hidden_old_dentry,
-+ hidden_new_dir_dentry->d_inode,
-+ hidden_new_dentry);
-+ if(err)
-+ goto out_lock;
-+
-+ fist_copy_attr_all(new_dir, hidden_new_dir_dentry->d_inode);
-+ if (new_dir != old_dir)
-+ fist_copy_attr_all(old_dir, hidden_old_dir_dentry->d_inode);
-+
-+ out_lock:
-+ /* double_unlock will dput the new/old parent dentries
-+ * whose refcnts were incremented via get_parent above.
-+ */
-+ double_unlock(hidden_old_dir_dentry, hidden_new_dir_dentry);
-+ dput(hidden_new_dentry);
-+ dput(hidden_old_dentry);
-+ out:
-+ return err;
-+ }
-+ else { /* invalid state */
-+ printk(KERN_CRIT "mini_fo: rename_reg_file: ERROR: invalid state detected [2].\n");
-+ return -1;
-+ }
-+}
-+
-+
-+STATIC int
-+mini_fo_readlink(dentry_t *dentry, char *buf, int bufsiz)
-+{
-+ int err=0;
-+ dentry_t *hidden_dentry = NULL;
-+
-+ if(dtohd2(dentry) && dtohd2(dentry)->d_inode) {
-+ hidden_dentry = dtohd2(dentry);
-+ } else if(dtohd(dentry) && dtohd(dentry)->d_inode) {
-+ hidden_dentry = dtohd(dentry);
-+ } else {
-+ goto out;
-+ }
-+
-+ if (!hidden_dentry->d_inode->i_op ||
-+ !hidden_dentry->d_inode->i_op->readlink) {
-+ err = -EINVAL; goto out;
-+ }
-+
-+ err = hidden_dentry->d_inode->i_op->readlink(hidden_dentry,
-+ buf,
-+ bufsiz);
-+ if (err > 0)
-+ fist_copy_attr_atime(dentry->d_inode, hidden_dentry->d_inode);
-+
-+ out:
-+ return err;
-+}
-+
-+
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,13)
-+static int mini_fo_follow_link(dentry_t *dentry, struct nameidata *nd)
-+#else
-+static void* mini_fo_follow_link(dentry_t *dentry, struct nameidata *nd)
-+#endif
-+{
-+ char *buf;
-+ int len = PAGE_SIZE, err;
-+ mm_segment_t old_fs;
-+
-+ /* in 2.6 this is freed by mini_fo_put_link called by __do_follow_link */
-+ buf = kmalloc(len, GFP_KERNEL);
-+ if (!buf) {
-+ err = -ENOMEM;
-+ goto out;
-+ }
-+
-+ /* read the symlink, and then we will follow it */
-+ old_fs = get_fs();
-+ set_fs(KERNEL_DS);
-+ err = dentry->d_inode->i_op->readlink(dentry, buf, len);
-+ set_fs(old_fs);
-+ if (err < 0) {
-+ kfree(buf);
-+ buf = NULL;
-+ goto out;
-+ }
-+ buf[err] = 0;
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
-+ nd_set_link(nd, buf);
-+ err = 0;
-+#else
-+ err = vfs_follow_link(nd, buf);
-+#endif
-+
-+ out:
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
-+ kfree(buf);
-+#endif
-+
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,13)
-+ return err;
-+#else
-+ return ERR_PTR(err);
-+#endif
-+}
-+
-+STATIC
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,13)
-+void mini_fo_put_link(struct dentry *dentry, struct nameidata *nd)
-+#else
-+void mini_fo_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
-+#endif
-+{
-+ char *link;
-+ link = nd_get_link(nd);
-+ kfree(link);
-+}
-+#endif
-+
-+STATIC int
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
-+mini_fo_permission(inode_t *inode, int mask, struct nameidata *nd)
-+#else
-+mini_fo_permission(inode_t *inode, int mask)
-+#endif
-+{
-+ inode_t *hidden_inode;
-+ int mode;
-+ int err;
-+
-+ if(itohi2(inode)) {
-+ hidden_inode = itohi2(inode);
-+ } else {
-+ hidden_inode = itohi(inode);
-+ }
-+ mode = inode->i_mode;
-+
-+ /* not really needed, as permission handles everything:
-+ * err = vfs_permission(inode, mask);
-+ * if (err)
-+ * goto out;
-+ */
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
-+ err = permission(hidden_inode, mask, nd);
-+#else
-+ err = permission(hidden_inode, mask);
-+#endif
-+
-+ /* out: */
-+ return err;
-+}
-+
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
-+STATIC int
-+mini_fo_inode_revalidate(dentry_t *dentry)
-+{
-+ int err = 0;
-+ dentry_t *hidden_dentry;
-+ inode_t *hidden_inode;
-+
-+ ASSERT(dentry->d_inode);
-+ ASSERT(itopd(dentry->d_inode));
-+
-+ if(itohi2(dentry->d_inode)) {
-+ hidden_dentry = dtohd2(dentry);
-+ hidden_inode = hidden_dentry->d_inode;
-+ } else if(itohi(dentry->d_inode)) {
-+ hidden_dentry = dtohd(dentry);
-+ hidden_inode = hidden_dentry->d_inode;
-+ } else {
-+ printk(KERN_CRIT "mini_fo_inode_revalidate: ERROR, invalid state detected.\n");
-+ err = -ENOENT;
-+ goto out;
-+ }
-+ if (hidden_inode && hidden_inode->i_op && hidden_inode->i_op->revalidate){
-+ err = hidden_inode->i_op->revalidate(hidden_dentry);
-+ if (err)
-+ goto out;
-+ }
-+ fist_copy_attr_all(dentry->d_inode, hidden_inode);
-+ out:
-+ return err;
-+}
-+#endif
-+
-+STATIC int
-+mini_fo_setattr(dentry_t *dentry, struct iattr *ia)
-+{
-+ int err = 0;
-+
-+ check_mini_fo_dentry(dentry);
-+
-+ if(!is_mini_fo_existant(dentry)) {
-+ printk(KERN_CRIT "mini_fo_setattr: ERROR, invalid state detected [1].\n");
-+ goto out;
-+ }
-+
-+ if(dtost(dentry) == UNMODIFIED) {
-+ if(!IS_COPY_FLAG(ia->ia_valid))
-+ goto out; /* we ignore these changes to base */
-+
-+ if(S_ISDIR(dentry->d_inode->i_mode)) {
-+ err = dir_unmod_to_mod(dentry);
-+ } else {
-+ /* we copy contents if file is not beeing truncated */
-+ if(S_ISREG(dentry->d_inode->i_mode) &&
-+ !(ia->ia_size == 0 && (ia->ia_valid & ATTR_SIZE))) {
-+ err = nondir_unmod_to_mod(dentry, 1);
-+ } else
-+ err = nondir_unmod_to_mod(dentry, 0);
-+ }
-+ if(err) {
-+ err = -EINVAL;
-+ printk(KERN_CRIT "mini_fo_setattr: ERROR changing states.\n");
-+ goto out;
-+ }
-+ }
-+ if(!exists_in_storage(dentry)) {
-+ printk(KERN_CRIT "mini_fo_setattr: ERROR, invalid state detected [2].\n");
-+ err = -EINVAL;
-+ goto out;
-+ }
-+ ASSERT(dentry->d_inode);
-+ ASSERT(dtohd2(dentry));
-+ ASSERT(itopd(dentry->d_inode));
-+ ASSERT(itohi2(dentry->d_inode));
-+
-+ err = notify_change(dtohd2(dentry), ia);
-+ fist_copy_attr_all(dentry->d_inode, itohi2(dentry->d_inode));
-+ out:
-+ return err;
-+}
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
-+STATIC int
-+mini_fo_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
-+{
-+ int err = 0;
-+ dentry_t *hidden_dentry;
-+
-+ ASSERT(dentry->d_inode);
-+ ASSERT(itopd(dentry->d_inode));
-+
-+ if(itohi2(dentry->d_inode)) {
-+ hidden_dentry = dtohd2(dentry);
-+ } else if(itohi(dentry->d_inode)) {
-+ hidden_dentry = dtohd(dentry);
-+ } else {
-+ printk(KERN_CRIT "mini_fo_getattr: ERROR, invalid state detected.\n");
-+ err = -ENOENT;
-+ goto out;
-+ }
-+ fist_copy_attr_all(dentry->d_inode, hidden_dentry->d_inode);
-+
-+ ASSERT(hidden_dentry);
-+ ASSERT(hidden_dentry->d_inode);
-+ ASSERT(hidden_dentry->d_inode->i_op);
-+
-+ generic_fillattr(dentry->d_inode, stat);
-+ if (!stat->blksize) {
-+ struct super_block *s = hidden_dentry->d_inode->i_sb;
-+ unsigned blocks;
-+ blocks = (stat->size+s->s_blocksize-1) >> s->s_blocksize_bits;
-+ stat->blocks = (s->s_blocksize / 512) * blocks;
-+ stat->blksize = s->s_blocksize;
-+ }
-+ out:
-+ return err;
-+}
-+#endif
-+
-+#if defined(XATTR) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20))
-+#if 0 /* no xattr_alloc() and xattr_free() */
-+/* This is lifted from fs/xattr.c */
-+static void *
-+xattr_alloc(size_t size, size_t limit)
-+{
-+ void *ptr;
-+
-+ if (size > limit)
-+ return ERR_PTR(-E2BIG);
-+
-+ if (!size) /* size request, no buffer is needed */
-+ return NULL;
-+ else if (size <= PAGE_SIZE)
-+ ptr = kmalloc((unsigned long) size, GFP_KERNEL);
-+ else
-+ ptr = vmalloc((unsigned long) size);
-+ if (!ptr)
-+ return ERR_PTR(-ENOMEM);
-+ return ptr;
-+}
-+
-+static void
-+xattr_free(void *ptr, size_t size)
-+{
-+ if (!size) /* size request, no buffer was needed */
-+ return;
-+ else if (size <= PAGE_SIZE)
-+ kfree(ptr);
-+ else
-+ vfree(ptr);
-+}
-+#endif /* no xattr_alloc() and xattr_free() */
-+
-+/* BKL held by caller.
-+ * dentry->d_inode->i_sem down
-+ */
-+STATIC int
-+mini_fo_getxattr(struct dentry *dentry, const char *name, void *value, size_t size) {
-+ struct dentry *hidden_dentry = NULL;
-+ int err = -EOPNOTSUPP;
-+ /* Define these anyway so we don't need as much ifdef'ed code. */
-+ char *encoded_name = NULL;
-+ char *encoded_value = NULL;
-+
-+ check_mini_fo_dentry(dentry);
-+
-+ if(exists_in_storage(dentry))
-+ hidden_dentry = dtohd2(dentry);
-+ else
-+ hidden_dentry = dtohd(dentry);
-+
-+ ASSERT(hidden_dentry);
-+ ASSERT(hidden_dentry->d_inode);
-+ ASSERT(hidden_dentry->d_inode->i_op);
-+
-+ if (hidden_dentry->d_inode->i_op->getxattr) {
-+ encoded_name = (char *)name;
-+ encoded_value = (char *)value;
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_lock(&hidden_dentry->d_inode->i_mutex);
-+#else
-+ down(&hidden_dentry->d_inode->i_sem);
-+#endif
-+ /* lock_kernel() already done by caller. */
-+ err = hidden_dentry->d_inode->i_op->getxattr(hidden_dentry, encoded_name, encoded_value, size);
-+ /* unlock_kernel() will be done by caller. */
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_lock(&hidden_dentry->d_inode->i_mutex);
-+#else
-+ up(&hidden_dentry->d_inode->i_sem);
-+#endif
-+ }
-+ return err;
-+}
-+
-+/* BKL held by caller.
-+ * dentry->d_inode->i_sem down
-+ */
-+STATIC int
-+#if ((LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,21) \
-+ && LINUX_VERSION_CODE <= KERNEL_VERSION(2,4,23)) \
-+ || LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
-+mini_fo_setxattr(struct dentry *dentry, const char *name,
-+ const void *value, size_t size, int flags)
-+#else
-+mini_fo_setxattr(struct dentry *dentry, const char *name,
-+ void *value, size_t size, int flags)
-+#endif
-+
-+{
-+ struct dentry *hidden_dentry = NULL;
-+ int err = -EOPNOTSUPP;
-+
-+ /* Define these anyway, so we don't have as much ifdef'ed code. */
-+ char *encoded_value = NULL;
-+ char *encoded_name = NULL;
-+
-+ check_mini_fo_dentry(dentry);
-+
-+ if(exists_in_storage(dentry))
-+ hidden_dentry = dtohd2(dentry);
-+ else
-+ hidden_dentry = dtohd(dentry);
-+
-+ ASSERT(hidden_dentry);
-+ ASSERT(hidden_dentry->d_inode);
-+ ASSERT(hidden_dentry->d_inode->i_op);
-+
-+ if (hidden_dentry->d_inode->i_op->setxattr) {
-+ encoded_name = (char *)name;
-+ encoded_value = (char *)value;
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_lock(&hidden_dentry->d_inode->i_mutex);
-+#else
-+ down(&hidden_dentry->d_inode->i_sem);
-+#endif
-+ /* lock_kernel() already done by caller. */
-+ err = hidden_dentry->d_inode->i_op->setxattr(hidden_dentry, encoded_name, encoded_value, size, flags);
-+ /* unlock_kernel() will be done by caller. */
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_unlock(&hidden_dentry->d_inode->i_mutex);
-+#else
-+ up(&hidden_dentry->d_inode->i_sem);
-+#endif
-+ }
-+ return err;
-+}
-+
-+/* BKL held by caller.
-+ * dentry->d_inode->i_sem down
-+ */
-+STATIC int
-+mini_fo_removexattr(struct dentry *dentry, const char *name) {
-+ struct dentry *hidden_dentry = NULL;
-+ int err = -EOPNOTSUPP;
-+ char *encoded_name;
-+
-+ check_mini_fo_dentry(dentry);
-+
-+ if(exists_in_storage(dentry))
-+ hidden_dentry = dtohd2(dentry);
-+ else
-+ hidden_dentry = dtohd(dentry);
-+
-+ ASSERT(hidden_dentry);
-+ ASSERT(hidden_dentry->d_inode);
-+ ASSERT(hidden_dentry->d_inode->i_op);
-+
-+ if (hidden_dentry->d_inode->i_op->removexattr) {
-+ encoded_name = (char *)name;
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_lock(&hidden_dentry->d_inode->i_mutex);
-+#else
-+ down(&hidden_dentry->d_inode->i_sem);
-+#endif
-+ /* lock_kernel() already done by caller. */
-+ err = hidden_dentry->d_inode->i_op->removexattr(hidden_dentry, encoded_name);
-+ /* unlock_kernel() will be done by caller. */
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_unlock(&hidden_dentry->d_inode->i_mutex);
-+#else
-+ up(&hidden_dentry->d_inode->i_sem);
-+#endif
-+ }
-+ return err;
-+}
-+
-+/* BKL held by caller.
-+ * dentry->d_inode->i_sem down
-+ */
-+STATIC int
-+mini_fo_listxattr(struct dentry *dentry, char *list, size_t size) {
-+ struct dentry *hidden_dentry = NULL;
-+ int err = -EOPNOTSUPP;
-+ char *encoded_list = NULL;
-+
-+ check_mini_fo_dentry(dentry);
-+
-+ if(exists_in_storage(dentry))
-+ hidden_dentry = dtohd2(dentry);
-+ else
-+ hidden_dentry = dtohd(dentry);
-+
-+ ASSERT(hidden_dentry);
-+ ASSERT(hidden_dentry->d_inode);
-+ ASSERT(hidden_dentry->d_inode->i_op);
-+
-+ if (hidden_dentry->d_inode->i_op->listxattr) {
-+ encoded_list = list;
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_lock(&hidden_dentry->d_inode->i_mutex);
-+#else
-+ down(&hidden_dentry->d_inode->i_sem);
-+#endif
-+ /* lock_kernel() already done by caller. */
-+ err = hidden_dentry->d_inode->i_op->listxattr(hidden_dentry, encoded_list, size);
-+ /* unlock_kernel() will be done by caller. */
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_unlock(&hidden_dentry->d_inode->i_mutex);
-+#else
-+ up(&hidden_dentry->d_inode->i_sem);
-+#endif
-+ }
-+ return err;
-+}
-+# endif /* defined(XATTR) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20)) */
-+
-+struct inode_operations mini_fo_symlink_iops =
-+ {
-+ readlink: mini_fo_readlink,
-+ follow_link: mini_fo_follow_link,
-+ /* mk: permission: mini_fo_permission, */
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
-+ revalidate: mini_fo_inode_revalidate,
-+#endif
-+ setattr: mini_fo_setattr,
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
-+ getattr: mini_fo_getattr,
-+ put_link: mini_fo_put_link,
-+#endif
-+
-+#if defined(XATTR) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20))
-+ setxattr: mini_fo_setxattr,
-+ getxattr: mini_fo_getxattr,
-+ listxattr: mini_fo_listxattr,
-+ removexattr: mini_fo_removexattr
-+# endif /* defined(XATTR) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20)) */
-+ };
-+
-+struct inode_operations mini_fo_dir_iops =
-+ {
-+ create: mini_fo_create,
-+ lookup: mini_fo_lookup,
-+ link: mini_fo_link,
-+ unlink: mini_fo_unlink,
-+ symlink: mini_fo_symlink,
-+ mkdir: mini_fo_mkdir,
-+ rmdir: mini_fo_rmdir,
-+ mknod: mini_fo_mknod,
-+ rename: mini_fo_rename,
-+ /* no readlink/follow_link for non-symlinks */
-+ // off because we have setattr
-+ // truncate: mini_fo_truncate,
-+ /* mk:permission: mini_fo_permission, */
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
-+ revalidate: mini_fo_inode_revalidate,
-+#endif
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
-+ getattr: mini_fo_getattr,
-+#endif
-+ setattr: mini_fo_setattr,
-+#if defined(XATTR) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20))
-+ setxattr: mini_fo_setxattr,
-+ getxattr: mini_fo_getxattr,
-+ listxattr: mini_fo_listxattr,
-+ removexattr: mini_fo_removexattr
-+# endif /* XATTR && LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20) */
-+ };
-+
-+struct inode_operations mini_fo_main_iops =
-+ {
-+ /* permission: mini_fo_permission, */
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
-+ revalidate: mini_fo_inode_revalidate,
-+#endif
-+ setattr: mini_fo_setattr,
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
-+ getattr: mini_fo_getattr,
-+#endif
-+#if defined(XATTR) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20))
-+ setxattr: mini_fo_setxattr,
-+ getxattr: mini_fo_getxattr,
-+ listxattr: mini_fo_listxattr,
-+ removexattr: mini_fo_removexattr
-+# endif /* XATTR && LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20) */
-+ };
-Index: linux-2.6.21.7/fs/mini_fo/main.c
-===================================================================
---- /dev/null
-+++ linux-2.6.21.7/fs/mini_fo/main.c
-@@ -0,0 +1,423 @@
-+/*
-+ * Copyright (c) 1997-2003 Erez Zadok
-+ * Copyright (c) 2001-2003 Stony Brook University
-+ *
-+ * For specific licensing information, see the COPYING file distributed with
-+ * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
-+ *
-+ * This Copyright notice must be kept intact and distributed with all
-+ * fistgen sources INCLUDING sources generated by fistgen.
-+ */
-+/*
-+ * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
-+ *
-+ * 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.
-+ */
-+
-+/*
-+ * $Id$
-+ */
-+
-+#ifdef HAVE_CONFIG_H
-+# include <config.h>
-+#endif
-+
-+#include "fist.h"
-+#include "mini_fo.h"
-+#include <linux/module.h>
-+
-+/* This definition must only appear after we include <linux/module.h> */
-+#ifndef MODULE_LICENSE
-+# define MODULE_LICENSE(bison)
-+#endif /* not MODULE_LICENSE */
-+
-+/*
-+ * This is the mini_fo tri interpose function, which extends the
-+ * functionality of the regular interpose by interposing a higher
-+ * level inode on top of two lower level ones: the base filesystem
-+ * inode and the storage filesystem inode.
-+ *
-+ * sb we pass is mini_fo's super_block
-+ */
-+int
-+mini_fo_tri_interpose(dentry_t *hidden_dentry,
-+ dentry_t *hidden_sto_dentry,
-+ dentry_t *dentry, super_block_t *sb, int flag)
-+{
-+ inode_t *hidden_inode = NULL;
-+ inode_t *hidden_sto_inode = NULL; /* store corresponding storage inode */
-+ int err = 0;
-+ inode_t *inode;
-+
-+ /* Pointer to hidden_sto_inode if exists, else to hidden_inode.
-+ * This is used to copy the attributes of the correct inode. */
-+ inode_t *master_inode;
-+
-+ if(hidden_dentry)
-+ hidden_inode = hidden_dentry->d_inode;
-+ if(hidden_sto_dentry)
-+ hidden_sto_inode = hidden_sto_dentry->d_inode;
-+
-+ ASSERT(dentry->d_inode == NULL);
-+
-+ /* mk: One of the inodes associated with the dentrys is likely to
-+ * be NULL, so carefull:
-+ */
-+ ASSERT((hidden_inode != NULL) || (hidden_sto_inode != NULL));
-+
-+ if(hidden_sto_inode)
-+ master_inode = hidden_sto_inode;
-+ else
-+ master_inode = hidden_inode;
-+
-+ /*
-+ * We allocate our new inode below, by calling iget.
-+ * iget will call our read_inode which will initialize some
-+ * of the new inode's fields
-+ */
-+
-+ /*
-+ * original: inode = iget(sb, hidden_inode->i_ino);
-+ */
-+ inode = iget(sb, iunique(sb, 25));
-+ if (!inode) {
-+ err = -EACCES; /* should be impossible??? */
-+ goto out;
-+ }
-+
-+ /*
-+ * interpose the inode if not already interposed
-+ * this is possible if the inode is being reused
-+ * XXX: what happens if we get_empty_inode() but there's another already?
-+ * for now, ASSERT() that this can't happen; fix later.
-+ */
-+ if (itohi(inode) != NULL) {
-+ printk(KERN_CRIT "mini_fo_tri_interpose: itohi(inode) != NULL.\n");
-+ }
-+ if (itohi2(inode) != NULL) {
-+ printk(KERN_CRIT "mini_fo_tri_interpose: itohi2(inode) != NULL.\n");
-+ }
-+
-+ /* mk: Carefull, igrab can't handle NULL inodes (ok, why should it?), so
-+ * we need to check here:
-+ */
-+ if(hidden_inode)
-+ itohi(inode) = igrab(hidden_inode);
-+ else
-+ itohi(inode) = NULL;
-+
-+ if(hidden_sto_inode)
-+ itohi2(inode) = igrab(hidden_sto_inode);
-+ else
-+ itohi2(inode) = NULL;
-+
-+
-+ /* Use different set of inode ops for symlinks & directories*/
-+ if (S_ISLNK(master_inode->i_mode))
-+ inode->i_op = &mini_fo_symlink_iops;
-+ else if (S_ISDIR(master_inode->i_mode))
-+ inode->i_op = &mini_fo_dir_iops;
-+
-+ /* Use different set of file ops for directories */
-+ if (S_ISDIR(master_inode->i_mode))
-+ inode->i_fop = &mini_fo_dir_fops;
-+
-+ /* properly initialize special inodes */
-+ if (S_ISBLK(master_inode->i_mode) || S_ISCHR(master_inode->i_mode) ||
-+ S_ISFIFO(master_inode->i_mode) || S_ISSOCK(master_inode->i_mode)) {
-+ init_special_inode(inode, master_inode->i_mode, master_inode->i_rdev);
-+ }
-+
-+ /* Fix our inode's address operations to that of the lower inode */
-+ if (inode->i_mapping->a_ops != master_inode->i_mapping->a_ops) {
-+ inode->i_mapping->a_ops = master_inode->i_mapping->a_ops;
-+ }
-+
-+ /* only (our) lookup wants to do a d_add */
-+ if (flag)
-+ d_add(dentry, inode);
-+ else
-+ d_instantiate(dentry, inode);
-+
-+ ASSERT(dtopd(dentry) != NULL);
-+
-+ /* all well, copy inode attributes */
-+ fist_copy_attr_all(inode, master_inode);
-+
-+ out:
-+ return err;
-+}
-+
-+/* parse mount options "base=" and "sto=" */
-+dentry_t *
-+mini_fo_parse_options(super_block_t *sb, char *options)
-+{
-+ dentry_t *hidden_root = ERR_PTR(-EINVAL);
-+ dentry_t *hidden_root2 = ERR_PTR(-EINVAL);
-+ struct nameidata nd, nd2;
-+ char *name, *tmp, *end;
-+ int err = 0;
-+
-+ /* We don't want to go off the end of our arguments later on. */
-+ for (end = options; *end; end++);
-+
-+ while (options < end) {
-+ tmp = options;
-+ while (*tmp && *tmp != ',')
-+ tmp++;
-+ *tmp = '\0';
-+ if (!strncmp("base=", options, 5)) {
-+ name = options + 5;
-+ printk(KERN_INFO "mini_fo: using base directory: %s\n", name);
-+
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
-+ if (path_init(name, LOOKUP_FOLLOW, &nd))
-+ err = path_walk(name, &nd);
-+#else
-+ err = path_lookup(name, LOOKUP_FOLLOW, &nd);
-+#endif
-+ if (err) {
-+ printk(KERN_CRIT "mini_fo: error accessing hidden directory '%s'\n", name);
-+ hidden_root = ERR_PTR(err);
-+ goto out;
-+ }
-+ hidden_root = nd.dentry;
-+ stopd(sb)->base_dir_dentry = nd.dentry;
-+ stopd(sb)->hidden_mnt = nd.mnt;
-+
-+ } else if(!strncmp("sto=", options, 4)) {
-+ /* parse the storage dir */
-+ name = options + 4;
-+ printk(KERN_INFO "mini_fo: using storage directory: %s\n", name);
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
-+ if(path_init(name, LOOKUP_FOLLOW, &nd2))
-+ err = path_walk(name, &nd2);
-+#else
-+ err = path_lookup(name, LOOKUP_FOLLOW, &nd2);
-+#endif
-+ if(err) {
-+ printk(KERN_CRIT "mini_fo: error accessing hidden storage directory '%s'\n", name);
-+
-+ hidden_root2 = ERR_PTR(err);
-+ goto out;
-+ }
-+ hidden_root2 = nd2.dentry;
-+ stopd(sb)->storage_dir_dentry = nd2.dentry;
-+ stopd(sb)->hidden_mnt2 = nd2.mnt;
-+ stohs2(sb) = hidden_root2->d_sb;
-+
-+ /* validate storage dir, this is done in
-+ * mini_fo_read_super for the base directory.
-+ */
-+ if (IS_ERR(hidden_root2)) {
-+ printk(KERN_WARNING "mini_fo_parse_options: storage dentry lookup failed (err = %ld)\n", PTR_ERR(hidden_root2));
-+ goto out;
-+ }
-+ if (!hidden_root2->d_inode) {
-+ printk(KERN_WARNING "mini_fo_parse_options: no storage dir to interpose on.\n");
-+ goto out;
-+ }
-+ stohs2(sb) = hidden_root2->d_sb;
-+ } else {
-+ printk(KERN_WARNING "mini_fo: unrecognized option '%s'\n", options);
-+ hidden_root = ERR_PTR(-EINVAL);
-+ goto out;
-+ }
-+ options = tmp + 1;
-+ }
-+
-+ out:
-+ if(IS_ERR(hidden_root2))
-+ return hidden_root2;
-+ return hidden_root;
-+}
-+
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
-+static int
-+#else
-+super_block_t *
-+#endif
-+mini_fo_read_super(super_block_t *sb, void *raw_data, int silent)
-+{
-+ dentry_t *hidden_root;
-+ int err = 0;
-+
-+ if (!raw_data) {
-+ printk(KERN_WARNING "mini_fo_read_super: missing argument\n");
-+ err = -EINVAL;
-+ goto out;
-+ }
-+ /*
-+ * Allocate superblock private data
-+ */
-+ __stopd(sb) = kmalloc(sizeof(struct mini_fo_sb_info), GFP_KERNEL);
-+ if (!stopd(sb)) {
-+ printk(KERN_WARNING "%s: out of memory\n", __FUNCTION__);
-+ err = -ENOMEM;
-+ goto out;
-+ }
-+ stohs(sb) = NULL;
-+
-+ hidden_root = mini_fo_parse_options(sb, raw_data);
-+ if (IS_ERR(hidden_root)) {
-+ printk(KERN_WARNING "mini_fo_read_super: lookup_dentry failed (err = %ld)\n", PTR_ERR(hidden_root));
-+ err = PTR_ERR(hidden_root);
-+ goto out_free;
-+ }
-+ if (!hidden_root->d_inode) {
-+ printk(KERN_WARNING "mini_fo_read_super: no directory to interpose on\n");
-+ goto out_free;
-+ }
-+ stohs(sb) = hidden_root->d_sb;
-+
-+ /*
-+ * Linux 2.4.2-ac3 and beyond has code in
-+ * mm/filemap.c:generic_file_write() that requires sb->s_maxbytes
-+ * to be populated. If not set, all write()s under that sb will
-+ * return 0.
-+ *
-+ * Linux 2.4.4+ automatically sets s_maxbytes to MAX_NON_LFS;
-+ * the filesystem should override it only if it supports LFS.
-+ */
-+ /* non-SCA code is good to go with LFS */
-+ sb->s_maxbytes = hidden_root->d_sb->s_maxbytes;
-+
-+ sb->s_op = &mini_fo_sops;
-+ /*
-+ * we can't use d_alloc_root if we want to use
-+ * our own interpose function unchanged,
-+ * so we simply replicate *most* of the code in d_alloc_root here
-+ */
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
-+ sb->s_root = d_alloc(NULL, &(const struct qstr) { "/", 1, 0 });
-+#else
-+ sb->s_root = d_alloc(NULL, &(const struct qstr){hash: 0, name: "/", len : 1});
-+#endif
-+ if (IS_ERR(sb->s_root)) {
-+ printk(KERN_WARNING "mini_fo_read_super: d_alloc failed\n");
-+ err = -ENOMEM;
-+ goto out_dput;
-+ }
-+
-+ sb->s_root->d_op = &mini_fo_dops;
-+ sb->s_root->d_sb = sb;
-+ sb->s_root->d_parent = sb->s_root;
-+
-+ /* link the upper and lower dentries */
-+ __dtopd(sb->s_root) = (struct mini_fo_dentry_info *)
-+ kmalloc(sizeof(struct mini_fo_dentry_info), GFP_KERNEL);
-+ if (!dtopd(sb->s_root)) {
-+ err = -ENOMEM;
-+ goto out_dput2;
-+ }
-+ dtopd(sb->s_root)->state = MODIFIED;
-+ dtohd(sb->s_root) = hidden_root;
-+
-+ /* fanout relevant, interpose on storage root dentry too */
-+ dtohd2(sb->s_root) = stopd(sb)->storage_dir_dentry;
-+
-+ /* ...and call tri-interpose to interpose root dir inodes
-+ * if (mini_fo_interpose(hidden_root, sb->s_root, sb, 0))
-+ */
-+ if(mini_fo_tri_interpose(hidden_root, dtohd2(sb->s_root), sb->s_root, sb, 0))
-+ goto out_dput2;
-+
-+ /* initalize the wol list */
-+ itopd(sb->s_root->d_inode)->deleted_list_size = -1;
-+ itopd(sb->s_root->d_inode)->renamed_list_size = -1;
-+ meta_build_lists(sb->s_root);
-+
-+ goto out;
-+
-+ out_dput2:
-+ dput(sb->s_root);
-+ out_dput:
-+ dput(hidden_root);
-+ dput(dtohd2(sb->s_root)); /* release the hidden_sto_dentry too */
-+ out_free:
-+ kfree(stopd(sb));
-+ __stopd(sb) = NULL;
-+ out:
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
-+ return err;
-+#else
-+ if (err) {
-+ return ERR_PTR(err);
-+ } else {
-+ return sb;
-+ }
-+#endif
-+}
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
-+static int mini_fo_get_sb(struct file_system_type *fs_type,
-+ int flags, const char *dev_name,
-+ void *raw_data, struct vfsmount *mnt)
-+{
-+ return get_sb_nodev(fs_type, flags, raw_data, mini_fo_read_super, mnt);
-+}
-+#else
-+static struct super_block *mini_fo_get_sb(struct file_system_type *fs_type,
-+ int flags, const char *dev_name,
-+ void *raw_data)
-+{
-+ return get_sb_nodev(fs_type, flags, raw_data, mini_fo_read_super);
-+}
-+#endif
-+
-+void mini_fo_kill_block_super(struct super_block *sb)
-+{
-+ generic_shutdown_super(sb);
-+ /*
-+ * XXX: BUG: Halcrow: Things get unstable sometime after this point:
-+ * lib/rwsem-spinlock.c:127: spin_is_locked on uninitialized
-+ * fs/fs-writeback.c:402: spin_lock(fs/super.c:a0381828) already
-+ * locked by fs/fs-writeback.c/402
-+ *
-+ * Apparently, someone's not releasing a lock on sb_lock...
-+ */
-+}
-+
-+static struct file_system_type mini_fo_fs_type = {
-+ .owner = THIS_MODULE,
-+ .name = "mini_fo",
-+ .get_sb = mini_fo_get_sb,
-+ .kill_sb = mini_fo_kill_block_super,
-+ .fs_flags = 0,
-+};
-+
-+
-+#else
-+static DECLARE_FSTYPE(mini_fo_fs_type, "mini_fo", mini_fo_read_super, 0);
-+#endif
-+
-+static int __init init_mini_fo_fs(void)
-+{
-+ printk("Registering mini_fo version $Id$\n");
-+ return register_filesystem(&mini_fo_fs_type);
-+}
-+static void __exit exit_mini_fo_fs(void)
-+{
-+ printk("Unregistering mini_fo version $Id$\n");
-+ unregister_filesystem(&mini_fo_fs_type);
-+}
-+
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
-+EXPORT_NO_SYMBOLS;
-+#endif
-+
-+MODULE_AUTHOR("Erez Zadok <ezk@cs.sunysb.edu>");
-+MODULE_DESCRIPTION("FiST-generated mini_fo filesystem");
-+MODULE_LICENSE("GPL");
-+
-+/* MODULE_PARM(fist_debug_var, "i"); */
-+/* MODULE_PARM_DESC(fist_debug_var, "Debug level"); */
-+
-+module_init(init_mini_fo_fs)
-+module_exit(exit_mini_fo_fs)
-Index: linux-2.6.21.7/fs/mini_fo/Makefile
-===================================================================
---- /dev/null
-+++ linux-2.6.21.7/fs/mini_fo/Makefile
-@@ -0,0 +1,17 @@
-+#
-+# Makefile for mini_fo 2.4 and 2.6 Linux kernels
-+#
-+# Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
-+#
-+# 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.
-+#
-+
-+obj-$(CONFIG_MINI_FO) := mini_fo.o
-+mini_fo-objs := meta.o dentry.o file.o inode.o main.o super.o state.o aux.o
-+
-+# dependencies
-+${mini_fo-objs}: mini_fo.h fist.h
-+
-Index: linux-2.6.21.7/fs/mini_fo/meta.c
-===================================================================
---- /dev/null
-+++ linux-2.6.21.7/fs/mini_fo/meta.c
-@@ -0,0 +1,1000 @@
-+/*
-+ * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
-+ *
-+ * 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.
-+ */
-+
-+#ifdef HAVE_CONFIG_H
-+# include <config.h>
-+#endif /* HAVE_CONFIG_H */
-+#include "fist.h"
-+#include "mini_fo.h"
-+
-+int meta_build_lists(dentry_t *dentry)
-+{
-+ struct mini_fo_inode_info *inode_info;
-+
-+ dentry_t *meta_dentry = 0;
-+ file_t *meta_file = 0;
-+ mm_segment_t old_fs;
-+ void *buf;
-+
-+ int bytes, len;
-+ struct vfsmount *meta_mnt;
-+ char *entry;
-+
-+ inode_info = itopd(dentry->d_inode);
-+ if(!(inode_info->deleted_list_size == -1 &&
-+ inode_info->renamed_list_size == -1)) {
-+ printk(KERN_CRIT "mini_fo: meta_build_lists: \
-+ Error, list(s) not virgin.\n");
-+ return -1;
-+ }
-+
-+ /* init our meta lists */
-+ INIT_LIST_HEAD(&inode_info->deleted_list);
-+ inode_info->deleted_list_size = 0;
-+
-+ INIT_LIST_HEAD(&inode_info->renamed_list);
-+ inode_info->renamed_list_size = 0;
-+
-+ /* might there be a META-file? */
-+ if(dtohd2(dentry) && dtohd2(dentry)->d_inode) {
-+ meta_dentry = lookup_one_len(META_FILENAME,
-+ dtohd2(dentry),
-+ strlen(META_FILENAME));
-+ if(!meta_dentry->d_inode) {
-+ dput(meta_dentry);
-+ goto out_ok;
-+ }
-+ /* $%& err, is this correct? */
-+ meta_mnt = stopd(dentry->d_inode->i_sb)->hidden_mnt2;
-+ mntget(meta_mnt);
-+
-+
-+ /* open META-file for reading */
-+ meta_file = dentry_open(meta_dentry, meta_mnt, 0x0);
-+ if(!meta_file || IS_ERR(meta_file)) {
-+ printk(KERN_CRIT "mini_fo: meta_build_lists: \
-+ ERROR opening META file.\n");
-+ goto out_err;
-+ }
-+
-+ /* check if fs supports reading */
-+ if(!meta_file->f_op->read) {
-+ printk(KERN_CRIT "mini_fo: meta_build_lists: \
-+ ERROR, fs does not support reading.\n");
-+ goto out_err_close;
-+ }
-+
-+ /* allocate a page for transfering the data */
-+ buf = (void *) __get_free_page(GFP_KERNEL);
-+ if(!buf) {
-+ printk(KERN_CRIT "mini_fo: meta_build_lists: \
-+ ERROR, out of mem.\n");
-+ goto out_err_close;
-+ }
-+ meta_file->f_pos = 0;
-+ old_fs = get_fs();
-+ set_fs(KERNEL_DS);
-+ do {
-+ char *c;
-+ bytes = meta_file->f_op->read(meta_file, buf, PAGE_SIZE, &meta_file->f_pos);
-+ if(bytes == PAGE_SIZE) {
-+ /* trim a cut off filename and adjust f_pos to get it next time */
-+ for(c = (char*) buf+PAGE_SIZE;
-+ *c != '\n';
-+ c--, bytes--, meta_file->f_pos--);
-+ }
-+ entry = (char *) buf;
-+ while(entry < (char *) buf+bytes) {
-+
-+ char *old_path;
-+ char *dir_name;
-+ int old_len, new_len;
-+
-+ /* len without '\n'*/
-+ len = (int) (strchr(entry, '\n') - entry);
-+ switch (*entry) {
-+ case 'D':
-+ /* format: "D filename" */
-+ meta_list_add_d_entry(dentry,
-+ entry+2,
-+ len-2);
-+ break;
-+ case 'R':
-+ /* format: "R path/xy/dir newDir" */
-+ old_path = entry+2;
-+ dir_name = strchr(old_path, ' ') + 1;
-+ old_len = dir_name - old_path - 1;
-+ new_len = ((int) entry) + len - ((int ) dir_name);
-+ meta_list_add_r_entry(dentry,
-+ old_path,
-+ old_len,
-+ dir_name,
-+ new_len);
-+ break;
-+ default:
-+ /* unknown entry type detected */
-+ break;
-+ }
-+ entry += len+1;
-+ }
-+
-+ } while(meta_file->f_pos < meta_dentry->d_inode->i_size);
-+
-+ free_page((unsigned long) buf);
-+ set_fs(old_fs);
-+ fput(meta_file);
-+ }
-+ goto out_ok;
-+
-+ out_err_close:
-+ fput(meta_file);
-+ out_err:
-+ mntput(meta_mnt);
-+ dput(meta_dentry);
-+ return -1;
-+ out_ok:
-+ return 1; /* check this!!! inode_info->wol_size; */
-+}
-+
-+/* cleanups up all lists and free's the mem by dentry */
-+int meta_put_lists(dentry_t *dentry)
-+{
-+ if(!dentry || !dentry->d_inode) {
-+ printk("mini_fo: meta_put_lists: invalid dentry passed.\n");
-+ return -1;
-+ }
-+ return __meta_put_lists(dentry->d_inode);
-+}
-+
-+/* cleanups up all lists and free's the mem by inode */
-+int __meta_put_lists(inode_t *inode)
-+{
-+ int err = 0;
-+ if(!inode || !itopd(inode)) {
-+ printk("mini_fo: __meta_put_lists: invalid inode passed.\n");
-+ return -1;
-+ }
-+ err = __meta_put_d_list(inode);
-+ err |= __meta_put_r_list(inode);
-+ return err;
-+}
-+
-+int meta_sync_lists(dentry_t *dentry)
-+{
-+ int err = 0;
-+ if(!dentry || !dentry->d_inode) {
-+ printk("mini_fo: meta_sync_lists: \
-+ invalid dentry passed.\n");
-+ return -1;
-+ }
-+ err = meta_sync_d_list(dentry, 0);
-+ err |= meta_sync_r_list(dentry, 1);
-+ return err;
-+}
-+
-+
-+/* remove all D entries from the renamed list and free the mem */
-+int __meta_put_d_list(inode_t *inode)
-+{
-+ struct list_head *tmp;
-+ struct deleted_entry *del_entry;
-+ struct mini_fo_inode_info *inode_info;
-+
-+ if(!inode || !itopd(inode)) {
-+ printk(KERN_CRIT "mini_fo: __meta_put_d_list: \
-+ invalid inode passed.\n");
-+ return -1;
-+ }
-+ inode_info = itopd(inode);
-+
-+ /* nuke the DELETED-list */
-+ if(inode_info->deleted_list_size <= 0)
-+ return 0;
-+
-+ while(!list_empty(&inode_info->deleted_list)) {
-+ tmp = inode_info->deleted_list.next;
-+ list_del(tmp);
-+ del_entry = list_entry(tmp, struct deleted_entry, list);
-+ kfree(del_entry->name);
-+ kfree(del_entry);
-+ }
-+ inode_info->deleted_list_size = 0;
-+
-+ return 0;
-+}
-+
-+/* remove all R entries from the renamed list and free the mem */
-+int __meta_put_r_list(inode_t *inode)
-+{
-+ struct list_head *tmp;
-+ struct renamed_entry *ren_entry;
-+ struct mini_fo_inode_info *inode_info;
-+
-+ if(!inode || !itopd(inode)) {
-+ printk(KERN_CRIT "mini_fo: meta_put_r_list: invalid inode.\n");
-+ return -1;
-+ }
-+ inode_info = itopd(inode);
-+
-+ /* nuke the RENAMED-list */
-+ if(inode_info->renamed_list_size <= 0)
-+ return 0;
-+
-+ while(!list_empty(&inode_info->renamed_list)) {
-+ tmp = inode_info->renamed_list.next;
-+ list_del(tmp);
-+ ren_entry = list_entry(tmp, struct renamed_entry, list);
-+ kfree(ren_entry->new_name);
-+ kfree(ren_entry->old_name);
-+ kfree(ren_entry);
-+ }
-+ inode_info->renamed_list_size = 0;
-+
-+ return 0;
-+}
-+
-+int meta_add_d_entry(dentry_t *dentry, const char *name, int len)
-+{
-+ int err = 0;
-+ err = meta_list_add_d_entry(dentry, name, len);
-+ err |= meta_write_d_entry(dentry,name,len);
-+ return err;
-+}
-+
-+/* add a D entry to the deleted list */
-+int meta_list_add_d_entry(dentry_t *dentry, const char *name, int len)
-+{
-+ struct deleted_entry *del_entry;
-+ struct mini_fo_inode_info *inode_info;
-+
-+ if(!dentry || !dentry->d_inode) {
-+ printk(KERN_CRIT "mini_fo: meta_list_add_d_entry: \
-+ invalid dentry passed.\n");
-+ return -1;
-+ }
-+ inode_info = itopd(dentry->d_inode);
-+
-+ if(inode_info->deleted_list_size < 0)
-+ return -1;
-+
-+ del_entry = (struct deleted_entry *)
-+ kmalloc(sizeof(struct deleted_entry), GFP_KERNEL);
-+ del_entry->name = (char*) kmalloc(len, GFP_KERNEL);
-+ if(!del_entry || !del_entry->name) {
-+ printk(KERN_CRIT "mini_fo: meta_list_add_d_entry: \
-+ out of mem.\n");
-+ kfree(del_entry->name);
-+ kfree(del_entry);
-+ return -ENOMEM;
-+ }
-+
-+ strncpy(del_entry->name, name, len);
-+ del_entry->len = len;
-+
-+ list_add(&del_entry->list, &inode_info->deleted_list);
-+ inode_info->deleted_list_size++;
-+ return 0;
-+}
-+
-+int meta_add_r_entry(dentry_t *dentry,
-+ const char *old_name, int old_len,
-+ const char *new_name, int new_len)
-+{
-+ int err = 0;
-+ err = meta_list_add_r_entry(dentry,
-+ old_name, old_len,
-+ new_name, new_len);
-+ err |= meta_write_r_entry(dentry,
-+ old_name, old_len,
-+ new_name, new_len);
-+ return err;
-+}
-+
-+/* add a R entry to the renamed list */
-+int meta_list_add_r_entry(dentry_t *dentry,
-+ const char *old_name, int old_len,
-+ const char *new_name, int new_len)
-+{
-+ struct renamed_entry *ren_entry;
-+ struct mini_fo_inode_info *inode_info;
-+
-+ if(!dentry || !dentry->d_inode) {
-+ printk(KERN_CRIT "mini_fo: meta_list_add_r_entry: \
-+ invalid dentry passed.\n");
-+ return -1;
-+ }
-+ inode_info = itopd(dentry->d_inode);
-+
-+ if(inode_info->renamed_list_size < 0)
-+ return -1;
-+
-+ ren_entry = (struct renamed_entry *)
-+ kmalloc(sizeof(struct renamed_entry), GFP_KERNEL);
-+ ren_entry->old_name = (char*) kmalloc(old_len, GFP_KERNEL);
-+ ren_entry->new_name = (char*) kmalloc(new_len, GFP_KERNEL);
-+
-+ if(!ren_entry || !ren_entry->old_name || !ren_entry->new_name) {
-+ printk(KERN_CRIT "mini_fo: meta_list_add_r_entry: \
-+ out of mem.\n");
-+ kfree(ren_entry->new_name);
-+ kfree(ren_entry->old_name);
-+ kfree(ren_entry);
-+ return -ENOMEM;
-+ }
-+
-+ strncpy(ren_entry->old_name, old_name, old_len);
-+ ren_entry->old_len = old_len;
-+ strncpy(ren_entry->new_name, new_name, new_len);
-+ ren_entry->new_len = new_len;
-+
-+ list_add(&ren_entry->list, &inode_info->renamed_list);
-+ inode_info->renamed_list_size++;
-+ return 0;
-+}
-+
-+
-+int meta_remove_r_entry(dentry_t *dentry, const char *name, int len)
-+{
-+ int err = 0;
-+ if(!dentry || !dentry->d_inode) {
-+ printk(KERN_CRIT
-+ "mini_fo: meta_remove_r_entry: \
-+ invalid dentry passed.\n");
-+ return -1;
-+ }
-+
-+ err = meta_list_remove_r_entry(dentry, name, len);
-+ err |= meta_sync_lists(dentry);
-+ return err;
-+}
-+
-+int meta_list_remove_r_entry(dentry_t *dentry, const char *name, int len)
-+{
-+ if(!dentry || !dentry->d_inode) {
-+ printk(KERN_CRIT
-+ "mini_fo: meta_list_remove_r_entry: \
-+ invalid dentry passed.\n");
-+ return -1;
-+ }
-+ return __meta_list_remove_r_entry(dentry->d_inode, name, len);
-+}
-+
-+int __meta_list_remove_r_entry(inode_t *inode, const char *name, int len)
-+{
-+ struct list_head *tmp;
-+ struct renamed_entry *ren_entry;
-+ struct mini_fo_inode_info *inode_info;
-+
-+ if(!inode || !itopd(inode))
-+ printk(KERN_CRIT
-+ "mini_fo: __meta_list_remove_r_entry: \
-+ invalid inode passed.\n");
-+ inode_info = itopd(inode);
-+
-+ if(inode_info->renamed_list_size < 0)
-+ return -1;
-+ if(inode_info->renamed_list_size == 0)
-+ return 1;
-+
-+ list_for_each(tmp, &inode_info->renamed_list) {
-+ ren_entry = list_entry(tmp, struct renamed_entry, list);
-+ if(ren_entry->new_len != len)
-+ continue;
-+
-+ if(!strncmp(ren_entry->new_name, name, len)) {
-+ list_del(tmp);
-+ kfree(ren_entry->new_name);
-+ kfree(ren_entry->old_name);
-+ kfree(ren_entry);
-+ inode_info->renamed_list_size--;
-+ return 0;
-+ }
-+ }
-+ return 1;
-+}
-+
-+
-+/* append a single D entry to the meta file */
-+int meta_write_d_entry(dentry_t *dentry, const char *name, int len)
-+{
-+ dentry_t *meta_dentry = 0;
-+ file_t *meta_file = 0;
-+ mm_segment_t old_fs;
-+
-+ int bytes, err;
-+ struct vfsmount *meta_mnt = 0;
-+ char *buf;
-+
-+ err = 0;
-+
-+ if(itopd(dentry->d_inode)->deleted_list_size < 0) {
-+ err = -1;
-+ goto out;
-+ }
-+
-+ if(dtopd(dentry)->state == UNMODIFIED) {
-+ err = build_sto_structure(dentry->d_parent, dentry);
-+ if(err) {
-+ printk(KERN_CRIT "mini_fo: meta_write_d_entry: \
-+ build_sto_structure failed.\n");
-+ goto out;
-+ }
-+ }
-+ meta_dentry = lookup_one_len(META_FILENAME,
-+ dtohd2(dentry), strlen (META_FILENAME));
-+
-+ /* We need to create a META-file */
-+ if(!meta_dentry->d_inode) {
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
-+ vfs_create(dtohd2(dentry)->d_inode,
-+ meta_dentry,
-+ S_IRUSR | S_IWUSR,
-+ NULL);
-+#else
-+ vfs_create(dtohd2(dentry)->d_inode,
-+ meta_dentry,
-+ S_IRUSR | S_IWUSR);
-+#endif
-+ }
-+ /* open META-file for writing */
-+ meta_file = dentry_open(meta_dentry, meta_mnt, 0x1);
-+ if(!meta_file || IS_ERR(meta_file)) {
-+ printk(KERN_CRIT "mini_fo: meta_write_d_entry: \
-+ ERROR opening meta file.\n");
-+ mntput(meta_mnt); /* $%& is this necessary? */
-+ dput(meta_dentry);
-+ err = -1;
-+ goto out;
-+ }
-+
-+ /* check if fs supports writing */
-+ if(!meta_file->f_op->write) {
-+ printk(KERN_CRIT "mini_fo: meta_write_d_entry: \
-+ ERROR, fs does not support writing.\n");
-+ goto out_err_close;
-+ }
-+
-+ meta_file->f_pos = meta_dentry->d_inode->i_size; /* append */
-+ old_fs = get_fs();
-+ set_fs(KERNEL_DS);
-+
-+ /* size: len for name, 1 for \n and 2 for "D " */
-+ buf = (char *) kmalloc(len+3, GFP_KERNEL);
-+ if (!buf) {
-+ printk(KERN_CRIT "mini_fo: meta_write_d_entry: \
-+ out of mem.\n");
-+ return -ENOMEM;
-+ }
-+
-+ buf[0] = 'D';
-+ buf[1] = ' ';
-+ strncpy(buf+2, name, len);
-+ buf[len+2] = '\n';
-+ bytes = meta_file->f_op->write(meta_file, buf, len+3,
-+ &meta_file->f_pos);
-+ if(bytes != len+3) {
-+ printk(KERN_CRIT "mini_fo: meta_write_d_entry: \
-+ ERROR writing.\n");
-+ err = -1;
-+ }
-+ kfree(buf);
-+ set_fs(old_fs);
-+
-+ out_err_close:
-+ fput(meta_file);
-+ out:
-+ return err;
-+}
-+
-+/* append a single R entry to the meta file */
-+int meta_write_r_entry(dentry_t *dentry,
-+ const char *old_name, int old_len,
-+ const char *new_name, int new_len)
-+{
-+ dentry_t *meta_dentry = 0;
-+ file_t *meta_file = 0;
-+ mm_segment_t old_fs;
-+
-+ int bytes, err, buf_len;
-+ struct vfsmount *meta_mnt = 0;
-+ char *buf;
-+
-+
-+ err = 0;
-+
-+ if(itopd(dentry->d_inode)->renamed_list_size < 0) {
-+ err = -1;
-+ goto out;
-+ }
-+
-+ /* build the storage structure? */
-+ if(dtopd(dentry)->state == UNMODIFIED) {
-+ err = build_sto_structure(dentry->d_parent, dentry);
-+ if(err) {
-+ printk(KERN_CRIT "mini_fo: meta_write_r_entry: \
-+ build_sto_structure failed.\n");
-+ goto out;
-+ }
-+ }
-+ meta_dentry = lookup_one_len(META_FILENAME,
-+ dtohd2(dentry),
-+ strlen (META_FILENAME));
-+ if(!meta_dentry->d_inode) {
-+ /* We need to create a META-file */
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
-+ vfs_create(dtohd2(dentry)->d_inode,
-+ meta_dentry, S_IRUSR | S_IWUSR, NULL);
-+#else
-+ vfs_create(dtohd2(dentry)->d_inode,
-+ meta_dentry, S_IRUSR | S_IWUSR);
-+#endif
-+ }
-+ /* open META-file for writing */
-+ meta_file = dentry_open(meta_dentry, meta_mnt, 0x1);
-+ if(!meta_file || IS_ERR(meta_file)) {
-+ printk(KERN_CRIT "mini_fo: meta_write_r_entry: \
-+ ERROR opening meta file.\n");
-+ mntput(meta_mnt);
-+ dput(meta_dentry);
-+ err = -1;
-+ goto out;
-+ }
-+
-+ /* check if fs supports writing */
-+ if(!meta_file->f_op->write) {
-+ printk(KERN_CRIT "mini_fo: meta_write_r_entry: \
-+ ERROR, fs does not support writing.\n");
-+ goto out_err_close;
-+ }
-+
-+ meta_file->f_pos = meta_dentry->d_inode->i_size; /* append */
-+ old_fs = get_fs();
-+ set_fs(KERNEL_DS);
-+
-+ /* size: 2 for "R ", old_len+new_len for names, 1 blank+1 \n */
-+ buf_len = old_len + new_len + 4;
-+ buf = (char *) kmalloc(buf_len, GFP_KERNEL);
-+ if (!buf) {
-+ printk(KERN_CRIT "mini_fo: meta_write_r_entry: out of mem.\n");
-+ return -ENOMEM;
-+ }
-+
-+ buf[0] = 'R';
-+ buf[1] = ' ';
-+ strncpy(buf + 2, old_name, old_len);
-+ buf[old_len + 2] = ' ';
-+ strncpy(buf + old_len + 3, new_name, new_len);
-+ buf[buf_len -1] = '\n';
-+ bytes = meta_file->f_op->write(meta_file, buf, buf_len, &meta_file->f_pos);
-+ if(bytes != buf_len) {
-+ printk(KERN_CRIT "mini_fo: meta_write_r_entry: ERROR writing.\n");
-+ err = -1;
-+ }
-+
-+ kfree(buf);
-+ set_fs(old_fs);
-+
-+ out_err_close:
-+ fput(meta_file);
-+ out:
-+ return err;
-+}
-+
-+/* sync D list to disk, append data if app_flag is 1 */
-+/* check the meta_mnt, which seems not to be used (properly) */
-+
-+int meta_sync_d_list(dentry_t *dentry, int app_flag)
-+{
-+ dentry_t *meta_dentry;
-+ file_t *meta_file;
-+ mm_segment_t old_fs;
-+
-+ int bytes, err;
-+ struct vfsmount *meta_mnt;
-+ char *buf;
-+
-+ struct list_head *tmp;
-+ struct deleted_entry *del_entry;
-+ struct mini_fo_inode_info *inode_info;
-+
-+ err = 0;
-+ meta_file=0;
-+ meta_mnt=0;
-+
-+ if(!dentry || !dentry->d_inode) {
-+ printk(KERN_CRIT "mini_fo: meta_sync_d_list: \
-+ invalid inode passed.\n");
-+ err = -1;
-+ goto out;
-+ }
-+ inode_info = itopd(dentry->d_inode);
-+
-+ if(inode_info->deleted_list_size < 0) {
-+ err = -1;
-+ goto out;
-+ }
-+
-+ /* ok, there is something to sync */
-+
-+ /* build the storage structure? */
-+ if(!dtohd2(dentry) && !itohi2(dentry->d_inode)) {
-+ err = build_sto_structure(dentry->d_parent, dentry);
-+ if(err) {
-+ printk(KERN_CRIT "mini_fo: meta_sync_d_list: \
-+ build_sto_structure failed.\n");
-+ goto out;
-+ }
-+ }
-+ meta_dentry = lookup_one_len(META_FILENAME,
-+ dtohd2(dentry),
-+ strlen(META_FILENAME));
-+ if(!meta_dentry->d_inode) {
-+ /* We need to create a META-file */
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
-+ vfs_create(dtohd2(dentry)->d_inode,
-+ meta_dentry, S_IRUSR | S_IWUSR, NULL);
-+#else
-+ vfs_create(dtohd2(dentry)->d_inode,
-+ meta_dentry, S_IRUSR | S_IWUSR);
-+#endif
-+ app_flag = 0;
-+ }
-+ /* need we truncate the meta file? */
-+ if(!app_flag) {
-+ struct iattr newattrs;
-+ newattrs.ia_size = 0;
-+ newattrs.ia_valid = ATTR_SIZE | ATTR_CTIME;
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_lock(&meta_dentry->d_inode->i_mutex);
-+#else
-+ down(&meta_dentry->d_inode->i_sem);
-+#endif
-+ err = notify_change(meta_dentry, &newattrs);
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_unlock(&meta_dentry->d_inode->i_mutex);
-+#else
-+ up(&meta_dentry->d_inode->i_sem);
-+#endif
-+
-+ if(err || meta_dentry->d_inode->i_size != 0) {
-+ printk(KERN_CRIT "mini_fo: meta_sync_d_list: \
-+ ERROR truncating meta file.\n");
-+ goto out_err_close;
-+ }
-+ }
-+
-+ /* open META-file for writing */
-+ meta_file = dentry_open(meta_dentry, meta_mnt, 0x1);
-+ if(!meta_file || IS_ERR(meta_file)) {
-+ printk(KERN_CRIT "mini_fo: meta_sync_d_list: \
-+ ERROR opening meta file.\n");
-+ /* we don't mntget so we dont't mntput (for now)
-+ * mntput(meta_mnt);
-+ */
-+ dput(meta_dentry);
-+ err = -1;
-+ goto out;
-+ }
-+
-+ /* check if fs supports writing */
-+ if(!meta_file->f_op->write) {
-+ printk(KERN_CRIT "mini_fo: meta_sync_d_list: \
-+ ERROR, fs does not support writing.\n");
-+ goto out_err_close;
-+ }
-+
-+ meta_file->f_pos = meta_dentry->d_inode->i_size; /* append */
-+ old_fs = get_fs();
-+ set_fs(KERNEL_DS);
-+
-+ /* here we go... */
-+ list_for_each(tmp, &inode_info->deleted_list) {
-+ del_entry = list_entry(tmp, struct deleted_entry, list);
-+
-+ /* size: len for name, 1 for \n and 2 for "D " */
-+ buf = (char *) kmalloc(del_entry->len+3, GFP_KERNEL);
-+ if (!buf) {
-+ printk(KERN_CRIT "mini_fo: meta_sync_d_list: \
-+ out of mem.\n");
-+ return -ENOMEM;
-+ }
-+
-+ buf[0] = 'D';
-+ buf[1] = ' ';
-+ strncpy(buf+2, del_entry->name, del_entry->len);
-+ buf[del_entry->len+2] = '\n';
-+ bytes = meta_file->f_op->write(meta_file, buf,
-+ del_entry->len+3,
-+ &meta_file->f_pos);
-+ if(bytes != del_entry->len+3) {
-+ printk(KERN_CRIT "mini_fo: meta_sync_d_list: \
-+ ERROR writing.\n");
-+ err |= -1;
-+ }
-+ kfree(buf);
-+ }
-+ set_fs(old_fs);
-+
-+ out_err_close:
-+ fput(meta_file);
-+ out:
-+ return err;
-+
-+}
-+
-+int meta_sync_r_list(dentry_t *dentry, int app_flag)
-+{
-+ dentry_t *meta_dentry;
-+ file_t *meta_file;
-+ mm_segment_t old_fs;
-+
-+ int bytes, err, buf_len;
-+ struct vfsmount *meta_mnt;
-+ char *buf;
-+
-+ struct list_head *tmp;
-+ struct renamed_entry *ren_entry;
-+ struct mini_fo_inode_info *inode_info;
-+
-+ err = 0;
-+ meta_file=0;
-+ meta_mnt=0;
-+
-+ if(!dentry || !dentry->d_inode) {
-+ printk(KERN_CRIT "mini_fo: meta_sync_r_list: \
-+ invalid dentry passed.\n");
-+ err = -1;
-+ goto out;
-+ }
-+ inode_info = itopd(dentry->d_inode);
-+
-+ if(inode_info->deleted_list_size < 0) {
-+ err = -1;
-+ goto out;
-+ }
-+
-+ /* ok, there is something to sync */
-+
-+ /* build the storage structure? */
-+ if(!dtohd2(dentry) && !itohi2(dentry->d_inode)) {
-+ err = build_sto_structure(dentry->d_parent, dentry);
-+ if(err) {
-+ printk(KERN_CRIT "mini_fo: meta_sync_r_list: \
-+ build_sto_structure failed.\n");
-+ goto out;
-+ }
-+ }
-+ meta_dentry = lookup_one_len(META_FILENAME,
-+ dtohd2(dentry),
-+ strlen(META_FILENAME));
-+ if(!meta_dentry->d_inode) {
-+ /* We need to create a META-file */
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
-+ vfs_create(dtohd2(dentry)->d_inode,
-+ meta_dentry, S_IRUSR | S_IWUSR, NULL);
-+#else
-+ vfs_create(dtohd2(dentry)->d_inode,
-+ meta_dentry, S_IRUSR | S_IWUSR);
-+#endif
-+ app_flag = 0;
-+ }
-+ /* need we truncate the meta file? */
-+ if(!app_flag) {
-+ struct iattr newattrs;
-+ newattrs.ia_size = 0;
-+ newattrs.ia_valid = ATTR_SIZE | ATTR_CTIME;
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_lock(&meta_dentry->d_inode->i_mutex);
-+#else
-+ down(&meta_dentry->d_inode->i_sem);
-+#endif
-+ err = notify_change(meta_dentry, &newattrs);
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_unlock(&meta_dentry->d_inode->i_mutex);
-+#else
-+ up(&meta_dentry->d_inode->i_sem);
-+#endif
-+ if(err || meta_dentry->d_inode->i_size != 0) {
-+ printk(KERN_CRIT "mini_fo: meta_sync_r_list: \
-+ ERROR truncating meta file.\n");
-+ goto out_err_close;
-+ }
-+ }
-+
-+ /* open META-file for writing */
-+ meta_file = dentry_open(meta_dentry, meta_mnt, 0x1);
-+ if(!meta_file || IS_ERR(meta_file)) {
-+ printk(KERN_CRIT "mini_fo: meta_sync_r_list: \
-+ ERROR opening meta file.\n");
-+ /* we don't mntget so we dont't mntput (for now)
-+ * mntput(meta_mnt);
-+ */
-+ dput(meta_dentry);
-+ err = -1;
-+ goto out;
-+ }
-+
-+ /* check if fs supports writing */
-+ if(!meta_file->f_op->write) {
-+ printk(KERN_CRIT "mini_fo: meta_sync_r_list: \
-+ ERROR, fs does not support writing.\n");
-+ goto out_err_close;
-+ }
-+
-+ meta_file->f_pos = meta_dentry->d_inode->i_size; /* append */
-+ old_fs = get_fs();
-+ set_fs(KERNEL_DS);
-+
-+ /* here we go... */
-+ list_for_each(tmp, &inode_info->renamed_list) {
-+ ren_entry = list_entry(tmp, struct renamed_entry, list);
-+ /* size:
-+ * 2 for "R ", old_len+new_len for names, 1 blank+1 \n */
-+ buf_len = ren_entry->old_len + ren_entry->new_len + 4;
-+ buf = (char *) kmalloc(buf_len, GFP_KERNEL);
-+ if (!buf) {
-+ printk(KERN_CRIT "mini_fo: meta_sync_r_list: \
-+ out of mem.\n");
-+ return -ENOMEM;
-+ }
-+ buf[0] = 'R';
-+ buf[1] = ' ';
-+ strncpy(buf + 2, ren_entry->old_name, ren_entry->old_len);
-+ buf[ren_entry->old_len + 2] = ' ';
-+ strncpy(buf + ren_entry->old_len + 3,
-+ ren_entry->new_name, ren_entry->new_len);
-+ buf[buf_len - 1] = '\n';
-+ bytes = meta_file->f_op->write(meta_file, buf,
-+ buf_len, &meta_file->f_pos);
-+ if(bytes != buf_len) {
-+ printk(KERN_CRIT "mini_fo: meta_sync_r_list: \
-+ ERROR writing.\n");
-+ err |= -1;
-+ }
-+ kfree(buf);
-+ }
-+ set_fs(old_fs);
-+
-+ out_err_close:
-+ fput(meta_file);
-+ out:
-+ return err;
-+}
-+
-+int meta_check_d_entry(dentry_t *dentry, const char *name, int len)
-+{
-+ if(!dentry || !dentry->d_inode)
-+ printk(KERN_CRIT "mini_fo: meta_check_d_dentry: \
-+ invalid dentry passed.\n");
-+ return __meta_check_d_entry(dentry->d_inode, name, len);
-+}
-+
-+int __meta_check_d_entry(inode_t *inode, const char *name, int len)
-+{
-+ struct list_head *tmp;
-+ struct deleted_entry *del_entry;
-+ struct mini_fo_inode_info *inode_info;
-+
-+ if(!inode || !itopd(inode))
-+ printk(KERN_CRIT "mini_fo: __meta_check_d_dentry: \
-+ invalid inode passed.\n");
-+
-+ inode_info = itopd(inode);
-+
-+ if(inode_info->deleted_list_size <= 0)
-+ return 0;
-+
-+ list_for_each(tmp, &inode_info->deleted_list) {
-+ del_entry = list_entry(tmp, struct deleted_entry, list);
-+ if(del_entry->len != len)
-+ continue;
-+
-+ if(!strncmp(del_entry->name, name, len))
-+ return 1;
-+ }
-+ return 0;
-+}
-+
-+/*
-+ * check if file has been renamed and return path to orig. base dir.
-+ * Implements no error return values so far, what of course sucks.
-+ * String is null terminated.'
-+ */
-+char* meta_check_r_entry(dentry_t *dentry, const char *name, int len)
-+{
-+ if(!dentry || !dentry->d_inode) {
-+ printk(KERN_CRIT "mini_fo: meta_check_r_dentry: \
-+ invalid dentry passed.\n");
-+ return NULL;
-+ }
-+ return __meta_check_r_entry(dentry->d_inode, name, len);
-+}
-+
-+char* __meta_check_r_entry(inode_t *inode, const char *name, int len)
-+{
-+ struct list_head *tmp;
-+ struct renamed_entry *ren_entry;
-+ struct mini_fo_inode_info *inode_info;
-+ char *old_path;
-+
-+ if(!inode || !itopd(inode)) {
-+ printk(KERN_CRIT "mini_fo: meta_check_r_dentry: \
-+ invalid inode passed.\n");
-+ return NULL;
-+ }
-+ inode_info = itopd(inode);
-+
-+ if(inode_info->renamed_list_size <= 0)
-+ return NULL;
-+
-+ list_for_each(tmp, &inode_info->renamed_list) {
-+ ren_entry = list_entry(tmp, struct renamed_entry, list);
-+ if(ren_entry->new_len != len)
-+ continue;
-+
-+ if(!strncmp(ren_entry->new_name, name, len)) {
-+ old_path = (char *)
-+ kmalloc(ren_entry->old_len+1, GFP_KERNEL);
-+ strncpy(old_path,
-+ ren_entry->old_name,
-+ ren_entry->old_len);
-+ old_path[ren_entry->old_len]='\0';
-+ return old_path;
-+ }
-+ }
-+ return NULL;
-+}
-+
-+/*
-+ * This version only checks if entry exists and return:
-+ * 1 if exists,
-+ * 0 if not,
-+ * -1 if error.
-+ */
-+int meta_is_r_entry(dentry_t *dentry, const char *name, int len)
-+{
-+ if(!dentry || !dentry->d_inode) {
-+ printk(KERN_CRIT "mini_fo: meta_check_r_dentry [2]: \
-+ invalid dentry passed.\n");
-+ return -1;
-+ }
-+ return __meta_is_r_entry(dentry->d_inode, name, len);
-+}
-+
-+int __meta_is_r_entry(inode_t *inode, const char *name, int len)
-+{
-+ struct list_head *tmp;
-+ struct renamed_entry *ren_entry;
-+ struct mini_fo_inode_info *inode_info;
-+
-+ if(!inode || !itopd(inode)) {
-+ printk(KERN_CRIT "mini_fo: meta_check_r_dentry [2]: \
-+ invalid inode passed.\n");
-+ return -1;
-+ }
-+ inode_info = itopd(inode);
-+
-+ if(inode_info->renamed_list_size <= 0)
-+ return -1;
-+
-+ list_for_each(tmp, &inode_info->renamed_list) {
-+ ren_entry = list_entry(tmp, struct renamed_entry, list);
-+ if(ren_entry->new_len != len)
-+ continue;
-+
-+ if(!strncmp(ren_entry->new_name, name, len))
-+ return 1;
-+ }
-+ return 0;
-+}
-+
-Index: linux-2.6.21.7/fs/mini_fo/mini_fo.h
-===================================================================
---- /dev/null
-+++ linux-2.6.21.7/fs/mini_fo/mini_fo.h
-@@ -0,0 +1,510 @@
-+/*
-+ * Copyright (c) 1997-2003 Erez Zadok
-+ * Copyright (c) 2001-2003 Stony Brook University
-+ *
-+ * For specific licensing information, see the COPYING file distributed with
-+ * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
-+ *
-+ * This Copyright notice must be kept intact and distributed with all
-+ * fistgen sources INCLUDING sources generated by fistgen.
-+ */
-+/*
-+ * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
-+ *
-+ * 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.
-+ */
-+
-+/*
-+ * $Id$
-+ */
-+
-+#ifndef __MINI_FO_H_
-+#define __MINI_FO_H_
-+
-+#ifdef __KERNEL__
-+
-+/* META stuff */
-+#define META_FILENAME "META_dAfFgHE39ktF3HD2sr"
-+
-+/* use xattrs? */
-+#define XATTR
-+
-+/* File attributes that when changed, result in a file beeing copied to storage */
-+#define COPY_FLAGS ATTR_MODE | ATTR_UID | ATTR_GID | ATTR_SIZE
-+
-+/*
-+ * mini_fo filestates
-+ */
-+#define MODIFIED 1
-+#define UNMODIFIED 2
-+#define CREATED 3
-+#define DEL_REWRITTEN 4
-+#define DELETED 5
-+#define NON_EXISTANT 6
-+
-+/* fist file systems superblock magic */
-+# define MINI_FO_SUPER_MAGIC 0xf15f
-+
-+/*
-+ * STRUCTURES:
-+ */
-+
-+/* mini_fo inode data in memory */
-+struct mini_fo_inode_info {
-+ inode_t *wii_inode;
-+ inode_t *wii_inode2; /* pointer to storage inode */
-+
-+ /* META-data lists */
-+ /* deleted list, ex wol */
-+ struct list_head deleted_list;
-+ int deleted_list_size;
-+
-+ /* renamed list */
-+ struct list_head renamed_list;
-+ int renamed_list_size;
-+
-+ /* add other lists here ... */
-+};
-+
-+/* mini_fo dentry data in memory */
-+struct mini_fo_dentry_info {
-+ dentry_t *wdi_dentry;
-+ dentry_t *wdi_dentry2; /* pointer to storage dentry */
-+ unsigned int state; /* state of the mini_fo dentry */
-+};
-+
-+
-+/* mini_fo super-block data in memory */
-+struct mini_fo_sb_info {
-+ super_block_t *wsi_sb, *wsi_sb2; /* mk: might point to the same sb */
-+ struct vfsmount *hidden_mnt, *hidden_mnt2;
-+ dentry_t *base_dir_dentry;
-+ dentry_t *storage_dir_dentry;
-+ ;
-+};
-+
-+/* readdir_data, readdir helper struct */
-+struct readdir_data {
-+ struct list_head ndl_list; /* linked list head ptr */
-+ int ndl_size; /* list size */
-+ int sto_done; /* flag to show that the storage dir entries have
-+ * all been read an now follow base entries */
-+};
-+
-+/* file private data. */
-+struct mini_fo_file_info {
-+ struct file *wfi_file;
-+ struct file *wfi_file2; /* pointer to storage file */
-+ struct readdir_data rd;
-+};
-+
-+/* struct ndl_entry */
-+struct ndl_entry {
-+ struct list_head list;
-+ char *name;
-+ int len;
-+};
-+
-+/********************************
-+ * META-data structures
-+ ********************************/
-+
-+/* deleted entry */
-+struct deleted_entry {
-+ struct list_head list;
-+ char *name;
-+ int len;
-+};
-+
-+/* renamed entry */
-+struct renamed_entry {
-+ struct list_head list;
-+ char *old_name; /* old directory with full path */
-+ int old_len; /* length of above string */
-+ char *new_name; /* new directory name */
-+ int new_len; /* length of above string */
-+};
-+
-+/* attr_change entry */
-+struct attr_change_entry {
-+ struct list_head list;
-+ char *name;
-+ int len;
-+};
-+
-+/* link entry */
-+struct link_entry {
-+ struct list_head list;
-+ int links_moved;
-+ int inum_base;
-+ int inum_sto;
-+ char *weird_name;
-+ int weird_name_len;
-+};
-+
-+
-+/* Some other stuff required for mini_fo_filldir64, copied from
-+ * fs/readdir.c
-+ */
-+
-+#define ROUND_UP64(x) (((x)+sizeof(u64)-1) & ~(sizeof(u64)-1))
-+#define NAME_OFFSET(de) ((int) ((de)->d_name - (char *) (de)))
-+
-+
-+struct linux_dirent64 {
-+ u64 d_ino;
-+ s64 d_off;
-+ unsigned short d_reclen;
-+ unsigned char d_type;
-+ char d_name[0];
-+};
-+
-+
-+struct getdents_callback64 {
-+ struct linux_dirent64 * current_dir;
-+ struct linux_dirent64 * previous;
-+ int count;
-+ int error;
-+};
-+
-+struct linux_dirent {
-+ unsigned long d_ino;
-+ unsigned long d_off;
-+ unsigned short d_reclen;
-+ char d_name[1];
-+};
-+
-+struct getdents_callback {
-+ struct linux_dirent * current_dir;
-+ struct linux_dirent * previous;
-+ int count;
-+ int error;
-+};
-+
-+
-+/*
-+ * MACROS:
-+ */
-+
-+/* file TO private_data */
-+# define ftopd(file) ((struct mini_fo_file_info *)((file)->private_data))
-+# define __ftopd(file) ((file)->private_data)
-+/* file TO hidden_file */
-+# define ftohf(file) ((ftopd(file))->wfi_file)
-+# define ftohf2(file) ((ftopd(file))->wfi_file2)
-+
-+/* inode TO private_data */
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
-+# define itopd(ino) ((struct mini_fo_inode_info *)(ino)->i_private)
-+# define __itopd(ino) ((ino)->i_private)
-+#else
-+# define itopd(ino) ((struct mini_fo_inode_info *)(ino)->u.generic_ip)
-+# define __itopd(ino) ((ino)->u.generic_ip)
-+#endif
-+/* inode TO hidden_inode */
-+# define itohi(ino) (itopd(ino)->wii_inode)
-+# define itohi2(ino) (itopd(ino)->wii_inode2)
-+
-+/* superblock TO private_data */
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
-+# define stopd(super) ((struct mini_fo_sb_info *)(super)->s_fs_info)
-+# define __stopd(super) ((super)->s_fs_info)
-+#else
-+# define stopd(super) ((struct mini_fo_sb_info *)(super)->u.generic_sbp)
-+# define __stopd(super) ((super)->u.generic_sbp)
-+#endif
-+
-+/* unused? # define vfs2priv stopd */
-+/* superblock TO hidden_superblock */
-+
-+# define stohs(super) (stopd(super)->wsi_sb)
-+# define stohs2(super) (stopd(super)->wsi_sb2)
-+
-+/* dentry TO private_data */
-+# define dtopd(dentry) ((struct mini_fo_dentry_info *)(dentry)->d_fsdata)
-+# define __dtopd(dentry) ((dentry)->d_fsdata)
-+/* dentry TO hidden_dentry */
-+# define dtohd(dent) (dtopd(dent)->wdi_dentry)
-+# define dtohd2(dent) (dtopd(dent)->wdi_dentry2)
-+
-+/* dentry to state */
-+# define dtost(dent) (dtopd(dent)->state)
-+# define sbt(sb) ((sb)->s_type->name)
-+
-+#define IS_WRITE_FLAG(flag) (flag & (O_RDWR | O_WRONLY | O_APPEND))
-+#define IS_COPY_FLAG(flag) (flag & (COPY_FLAGS))
-+
-+/* macros to simplify non-SCA code */
-+# define MALLOC_PAGE_POINTERS(hidden_pages, num_hidden_pages)
-+# define MALLOC_PAGEDATA_POINTERS(hidden_pages_data, num_hidden_pages)
-+# define FREE_PAGE_POINTERS(hidden_pages, num)
-+# define FREE_PAGEDATA_POINTERS(hidden_pages_data, num)
-+# define FOR_EACH_PAGE
-+# define CURRENT_HIDDEN_PAGE hidden_page
-+# define CURRENT_HIDDEN_PAGEDATA hidden_page_data
-+# define CURRENT_HIDDEN_PAGEINDEX page->index
-+
-+/*
-+ * EXTERNALS:
-+ */
-+extern struct file_operations mini_fo_main_fops;
-+extern struct file_operations mini_fo_dir_fops;
-+extern struct inode_operations mini_fo_main_iops;
-+extern struct inode_operations mini_fo_dir_iops;
-+extern struct inode_operations mini_fo_symlink_iops;
-+extern struct super_operations mini_fo_sops;
-+extern struct dentry_operations mini_fo_dops;
-+extern struct vm_operations_struct mini_fo_shared_vmops;
-+extern struct vm_operations_struct mini_fo_private_vmops;
-+extern struct address_space_operations mini_fo_aops;
-+
-+#if 0 /* unused by mini_fo */
-+extern int mini_fo_interpose(dentry_t *hidden_dentry, dentry_t *this_dentry, super_block_t *sb, int flag);
-+#if defined(FIST_FILTER_DATA) || defined(FIST_FILTER_SCA)
-+extern page_t *mini_fo_get1page(file_t *file, int index);
-+extern int mini_fo_fill_zeros(file_t *file, page_t *page, unsigned from);
-+# endif /* FIST_FILTER_DATA || FIST_FILTER_SCA */
-+
-+
-+# define mini_fo_hidden_dentry(d) __mini_fo_hidden_dentry(__FILE__,__FUNCTION__,__LINE__,(d))
-+# define mini_fo_hidden_sto_dentry(d) __mini_fo_hidden_sto_dentry(__FILE__,__FUNCTION__,__LINE__,(d))
-+
-+extern dentry_t *__mini_fo_hidden_dentry(char *file, char *func, int line, dentry_t *this_dentry);
-+extern dentry_t *__mini_fo_hidden_sto_dentry(char *file, char *func, int line, dentry_t *this_dentry);
-+
-+extern int mini_fo_read_file(const char *filename, void *buf, int len);
-+extern int mini_fo_write_file(const char *filename, void *buf, int len);
-+extern dentry_t *fist_lookup(dentry_t *dir, const char *name, vnode_t **out, uid_t uid, gid_t gid);
-+#endif /* unused by mini_fo */
-+
-+/* state transition functions */
-+extern int nondir_unmod_to_mod(dentry_t *dentry, int cp_flag);
-+extern int nondir_del_rew_to_del(dentry_t *dentry);
-+extern int nondir_creat_to_del(dentry_t *dentry);
-+extern int nondir_mod_to_del(dentry_t *dentry);
-+extern int nondir_unmod_to_del(dentry_t *dentry);
-+
-+extern int dir_unmod_to_mod(dentry_t *dentry);
-+
-+/* rename specials */
-+extern int rename_directory(inode_t *old_dir, dentry_t *old_dentry, inode_t *new_dir, dentry_t *new_dentry);
-+extern int rename_nondir(inode_t *old_dir, dentry_t *old_dentry, inode_t *new_dir, dentry_t *new_dentry);
-+
-+/* misc stuff */
-+extern int mini_fo_tri_interpose(dentry_t *hidden_dentry,
-+ dentry_t *hidden_sto_dentry,
-+ dentry_t *dentry,
-+ super_block_t *sb, int flag);
-+
-+extern int mini_fo_cp_cont(dentry_t *tgt_dentry, struct vfsmount *tgt_mnt,
-+ dentry_t *src_dentry, struct vfsmount *src_mnt);
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
-+extern int mini_fo_create(inode_t *dir, dentry_t *dentry, int mode, struct nameidata *nd);
-+
-+extern int create_sto_nod(dentry_t *dentry, int mode, dev_t dev);
-+extern int create_sto_reg_file(dentry_t *dentry, int mode, struct nameidata *nd);
-+#else
-+extern int mini_fo_create(inode_t *dir, dentry_t *dentry, int mode);
-+
-+extern int create_sto_nod(dentry_t *dentry, int mode, int dev);
-+extern int create_sto_reg_file(dentry_t *dentry, int mode);
-+#endif
-+
-+extern int create_sto_dir(dentry_t *dentry, int mode);
-+
-+extern int exists_in_storage(dentry_t *dentry);
-+extern int is_mini_fo_existant(dentry_t *dentry);
-+extern int get_neg_sto_dentry(dentry_t *dentry);
-+extern int build_sto_structure(dentry_t *dir, dentry_t *dentry);
-+extern int get_mini_fo_bpath(dentry_t *dentry, char **bpath, int *bpath_len);
-+extern dentry_t *bpath_walk(super_block_t *sb, char *bpath);
-+extern int bpath_put(dentry_t *dentry);
-+
-+/* check_mini_fo types functions */
-+extern int check_mini_fo_dentry(dentry_t *dentry);
-+extern int check_mini_fo_file(file_t *file);
-+extern int check_mini_fo_inode(inode_t *inode);
-+
-+/* General meta functions, can be called from outside of meta.c */
-+extern int meta_build_lists(dentry_t *dentry);
-+extern int meta_put_lists(dentry_t *dentry);
-+extern int __meta_put_lists(inode_t *inode);
-+
-+extern int meta_add_d_entry(dentry_t *dentry, const char *name, int len);
-+extern int meta_add_r_entry(dentry_t *dentry,
-+ const char *old_name, int old_len,
-+ const char *new_name, int new_len);
-+
-+extern int meta_remove_r_entry(dentry_t *dentry, const char *name, int len);
-+
-+extern int meta_check_d_entry(dentry_t *dentry, const char *name, int len);
-+extern int __meta_check_d_entry(inode_t *inode, const char *name, int len);
-+
-+extern char* meta_check_r_entry(dentry_t *dentry, const char *name, int len);
-+extern char* __meta_check_r_entry(inode_t *inode, const char *name, int len);
-+extern int meta_is_r_entry(dentry_t *dentry, const char *name, int len);
-+extern int __meta_is_r_entry(inode_t *inode, const char *name, int len);
-+
-+/* Specific meta functions, should be called only inside meta.c */
-+extern int __meta_put_d_list(inode_t *inode);
-+extern int __meta_put_r_list(inode_t *inode);
-+
-+extern int meta_list_add_d_entry(dentry_t *dentry,
-+ const char *name, int len);
-+extern int meta_list_add_r_entry(dentry_t *dentry,
-+ const char *old_name, int old_len,
-+ const char *new_name, int new_len);
-+
-+extern int meta_list_remove_r_entry(dentry_t *dentry,
-+ const char *name, int len);
-+
-+extern int __meta_list_remove_r_entry(inode_t *inode,
-+ const char *name, int len);
-+
-+extern int meta_write_d_entry(dentry_t *dentry, const char *name, int len);
-+extern int meta_write_r_entry(dentry_t *dentry,
-+ const char *old_name, int old_len,
-+ const char *new_name, int new_len);
-+
-+extern int meta_sync_lists(dentry_t *dentry);
-+extern int meta_sync_d_list(dentry_t *dentry, int app_flag);
-+extern int meta_sync_r_list(dentry_t *dentry, int app_flag);
-+
-+/* ndl stuff */
-+extern int ndl_add_entry(struct readdir_data *rd, const char *name, int len);
-+extern void ndl_put_list(struct readdir_data *rd);
-+extern int ndl_check_entry(struct readdir_data *rd,
-+ const char *name, int len);
-+
-+
-+# define copy_inode_size(dst, src) \
-+ dst->i_size = src->i_size; \
-+ dst->i_blocks = src->i_blocks;
-+
-+static inline void
-+fist_copy_attr_atime(inode_t *dest, const inode_t *src)
-+{
-+ ASSERT(dest != NULL);
-+ ASSERT(src != NULL);
-+ dest->i_atime = src->i_atime;
-+}
-+static inline void
-+fist_copy_attr_times(inode_t *dest, const inode_t *src)
-+{
-+ ASSERT(dest != NULL);
-+ ASSERT(src != NULL);
-+ dest->i_atime = src->i_atime;
-+ dest->i_mtime = src->i_mtime;
-+ dest->i_ctime = src->i_ctime;
-+}
-+static inline void
-+fist_copy_attr_timesizes(inode_t *dest, const inode_t *src)
-+{
-+ ASSERT(dest != NULL);
-+ ASSERT(src != NULL);
-+ dest->i_atime = src->i_atime;
-+ dest->i_mtime = src->i_mtime;
-+ dest->i_ctime = src->i_ctime;
-+ copy_inode_size(dest, src);
-+}
-+static inline void
-+fist_copy_attr_all(inode_t *dest, const inode_t *src)
-+{
-+ ASSERT(dest != NULL);
-+ ASSERT(src != NULL);
-+ dest->i_mode = src->i_mode;
-+ dest->i_nlink = src->i_nlink;
-+ dest->i_uid = src->i_uid;
-+ dest->i_gid = src->i_gid;
-+ dest->i_rdev = src->i_rdev;
-+ dest->i_atime = src->i_atime;
-+ dest->i_mtime = src->i_mtime;
-+ dest->i_ctime = src->i_ctime;
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
-+ dest->i_blksize = src->i_blksize;
-+#endif
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,12)
-+ dest->i_blkbits = src->i_blkbits;
-+# endif /* linux 2.4.12 and newer */
-+ copy_inode_size(dest, src);
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
-+ dest->i_attr_flags = src->i_attr_flags;
-+#else
-+ dest->i_flags = src->i_flags;
-+#endif
-+}
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
-+/* copied from linux/fs.h */
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+static inline void double_lock(struct dentry *d1, struct dentry *d2)
-+{
-+ struct mutex *m1 = &d1->d_inode->i_mutex;
-+ struct mutex *m2 = &d2->d_inode->i_mutex;
-+ if (m1 != m2) {
-+ if ((unsigned long) m1 < (unsigned long) m2) {
-+ struct mutex *tmp = m2;
-+ m2 = m1; m1 = tmp;
-+ }
-+ mutex_lock(m1);
-+ }
-+ mutex_lock(m2);
-+}
-+
-+static inline void double_unlock(struct dentry *d1, struct dentry *d2)
-+{
-+ struct mutex *m1 = &d1->d_inode->i_mutex;
-+ struct mutex *m2 = &d2->d_inode->i_mutex;
-+ mutex_unlock(m1);
-+ if (m1 != m2)
-+ mutex_unlock(m2);
-+ dput(d1);
-+ dput(d2);
-+}
-+
-+#else
-+static inline void double_down(struct semaphore *s1, struct semaphore *s2)
-+{
-+ if (s1 != s2) {
-+ if ((unsigned long) s1 < (unsigned long) s2) {
-+ struct semaphore *tmp = s2;
-+ s2 = s1; s1 = tmp;
-+ }
-+ down(s1);
-+ }
-+ down(s2);
-+}
-+
-+static inline void double_up(struct semaphore *s1, struct semaphore *s2)
-+{
-+ up(s1);
-+ if (s1 != s2)
-+ up(s2);
-+}
-+
-+static inline void double_lock(struct dentry *d1, struct dentry *d2)
-+{
-+ double_down(&d1->d_inode->i_sem, &d2->d_inode->i_sem);
-+}
-+
-+static inline void double_unlock(struct dentry *d1, struct dentry *d2)
-+{
-+ double_up(&d1->d_inode->i_sem,&d2->d_inode->i_sem);
-+ dput(d1);
-+ dput(d2);
-+}
-+#endif /* if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16) */
-+#endif /* if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) */
-+#endif /* __KERNEL__ */
-+
-+/*
-+ * Definitions for user and kernel code
-+ */
-+
-+/* ioctls */
-+
-+#endif /* not __MINI_FO_H_ */
-Index: linux-2.6.21.7/fs/mini_fo/mini_fo-merge
-===================================================================
---- /dev/null
-+++ linux-2.6.21.7/fs/mini_fo/mini_fo-merge
-@@ -0,0 +1,180 @@
-+#!/bin/bash
-+#
-+# Copyright (C) 2005 Markus Klotzbuecher <mk@creamnet.de>
-+# 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.
-+#
-+
-+BASE=
-+STO=
-+HELP=
-+DRYRUN=
-+VERBOSE=
-+TMP="/tmp/"
-+META_NAME="META_dAfFgHE39ktF3HD2sr"
-+SKIP_DEL_LIST="skip-delete-list.mini_fo-merge"
-+
-+COMMAND=
-+exec_command()
-+{
-+ if [ x$DRYRUN == "xset" ]; then
-+ echo " would run: $COMMAND"
-+ elif ! [ x$DRYRUN == "xset" ]; then
-+ if [ x$VERBOSE == "xset" ]; then
-+ echo " running: $COMMAND"
-+ fi
-+ eval $COMMAND
-+ fi
-+}
-+
-+usage()
-+{
-+cat <<EOF
-+
-+USAGE: $0 -b <base dir> -s <storage dir>
-+Version 0.1
-+
-+This script merges the contents of a mini_fo storage file system back
-+to the base file system.
-+
-+!!! Warning: This will modify the base filesystem and can destroy data
-+ if used wrongly.
-+
-+Options:
-+ -b <base dir>
-+ the directory of the base file system.
-+
-+ -s <storage dir>
-+ the directory of the storage file system.
-+
-+ -d dry run, will not change anything and print the commands that
-+ would be executed.
-+
-+ -t tmp dir for storing temporary file. default: $TMP
-+
-+ -v show what operations are performed.
-+
-+ -h displays this message.
-+
-+EOF
-+}
-+
-+# parse parameters
-+while getopts hdvt:b:s: OPTS
-+ do
-+ case $OPTS in
-+ h) HELP="set";;
-+ d) DRYRUN="set";;
-+ v) VERBOSE="set";;
-+ b) BASE="$OPTARG";;
-+ s) STO="$OPTARG";;
-+ t) TMP="$OPTARG";;
-+ ?) usage
-+ exit 1;;
-+ esac
-+done
-+
-+if [ "x$HELP" == "xset" ]; then
-+ usage
-+ exit -1
-+fi
-+
-+if ! [ -d "$BASE" ] || ! [ -d "$STO" ]; then
-+ echo -e "$0:\n Error, -s and/or -b argument missing. type $0 -h for help."
-+ exit -1;
-+fi
-+
-+# get full paths
-+pushd $STO; STO=`pwd`; popd
-+pushd $BASE; BASE=`pwd`; popd
-+TMP=${TMP%/}
-+
-+
-+cat<<EOF
-+###############################################################################
-+# mini_fo-merge
-+#
-+# base dir: $BASE
-+# storage dir: $STO
-+# meta filename: $META_NAME
-+# dry run: $DRYRUN
-+# verbose: $VERBOSE
-+# tmp files: $TMP
-+###############################################################################
-+
-+EOF
-+
-+rm $TMP/$SKIP_DEL_LIST
-+
-+# first process all renamed dirs
-+echo "Merging renamed directories..."
-+pushd $STO &> /dev/null
-+find . -name $META_NAME -type f -print0 | xargs -0 -e grep -e '^R ' | tr -s ':R' ' ' | while read ENTRY; do
-+ echo "entry: $ENTRY"
-+ META_FILE=`echo $ENTRY | cut -d ' ' -f 1`
-+ OLD_B_DIR=`echo $ENTRY | cut -d ' ' -f 2 | sed -e 's/\///'`
-+ NEW_NAME=`echo $ENTRY | cut -d ' ' -f 3`
-+ NEW_B_DIR=`echo $META_FILE | sed -e "s/$META_NAME/$NEW_NAME/" | sed -e 's/^\.\///'`
-+ echo "META_FILE: $META_FILE"
-+ echo "OLD_B_DIR: $OLD_B_DIR"
-+ echo "NEW_NAME: $NEW_NAME"
-+ echo "NEW_B_DIR: $NEW_B_DIR"
-+
-+ pushd $BASE &> /dev/null
-+ # remove an existing dir in storage
-+ COMMAND="rm -rf $NEW_B_DIR"; exec_command
-+ COMMAND="cp -R $OLD_B_DIR $NEW_B_DIR"; exec_command
-+ echo ""
-+ popd &> /dev/null
-+
-+ # remember this dir to exclude it from deleting later
-+ echo $NEW_B_DIR >> $TMP/$SKIP_DEL_LIST
-+done
-+
-+# delete all whiteouted files from base
-+echo -e "\nDeleting whiteout'ed files from base file system..."
-+find . -name $META_NAME -type f -print0 | xargs -0 -e grep -e '^D ' | sed -e 's/:D//' | while read ENTRY; do
-+ META_FILE=`echo $ENTRY | cut -d ' ' -f 1`
-+ DEL_NAME=`echo $ENTRY | cut -d ' ' -f 2`
-+ DEL_FILE=`echo $META_FILE | sed -e "s/$META_NAME/$DEL_NAME/" | sed -e 's/^\.\///'`
-+ grep -x $DEL_FILE $TMP/$SKIP_DEL_LIST &> /dev/null
-+ if [ $? -ne 0 ]; then
-+ pushd $BASE &> /dev/null
-+ COMMAND="rm -rf $DEL_FILE"; exec_command
-+ popd &> /dev/null
-+ else
-+ echo " excluding: $DEL_FILE as in skip-del-list."
-+ fi
-+done
-+
-+# create all dirs and update permissions
-+echo -e "\nSetting up directory structures in base file system..."
-+find . -type d | sed -e 's/^\.\///' | while read DIR; do
-+ PERMS=`stat -c %a $DIR`
-+ DIR_UID=`stat -c %u $DIR`
-+ DIR_GID=`stat -c %g $DIR`
-+ pushd $BASE &> /dev/null
-+ if ! [ -d $DIR ]; then
-+ COMMAND="mkdir -p $DIR"; exec_command
-+ fi
-+ COMMAND="chmod $PERMS $DIR"; exec_command
-+ COMMAND="chown $DIR_UID:$DIR_GID $DIR"; exec_command
-+ popd &> /dev/null
-+done
-+
-+# merge all non-directory files
-+echo -e "\nMerging all non-directory files...."
-+for i in b c p f l s; do
-+ find . -type $i | sed -e 's/^\.\///' | grep -v "$META_NAME" | while read FILE; do
-+ pushd $BASE #&> /dev/null
-+ COMMAND="cp -df $STO/$FILE $BASE/$FILE"; exec_command
-+ popd &> /dev/null
-+ done
-+done
-+popd &> /dev/null
-+
-+#rm $TMP/$SKIP_DEL_LIST
-+
-+echo "Done!"
-Index: linux-2.6.21.7/fs/mini_fo/mini_fo-overlay
-===================================================================
---- /dev/null
-+++ linux-2.6.21.7/fs/mini_fo/mini_fo-overlay
-@@ -0,0 +1,130 @@
-+#!/bin/bash
-+#
-+# Copyright (C) 2005 Markus Klotzbuecher <mk@creamnet.de>
-+# 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.
-+#
-+
-+HELP=
-+SUFF=
-+MNTP=
-+MNT_DIR="/mnt"
-+STO=
-+STO_DIR="/tmp"
-+BASE=
-+
-+usage()
-+{
-+cat <<EOF
-+
-+Usage: $0 [-s suffix] [-d sto_dir_dir] [-m mount point] base_dir
-+Version 0.1
-+
-+This script overlays the given base directory using the mini_fo file
-+system. If only the base directory base_dir is given, $0
-+will use a storage directory called "sto-<base_dir_name>" in $STO_DIR,
-+and mount point "mini_fo-<base_dir_dir>" in $MNT_DIR.
-+
-+Options:
-+ -s <suffix>
-+ add given suffix to storage directory and the mount
-+ point. This is usefull for overlaying one base directory
-+ several times and avoiding conflicts with storage directory
-+ names and mount points.
-+
-+ -d <sto_dir_dir>
-+ change the directory in which the storage directory will be
-+ created (default is currently "$STO_DIR".
-+
-+ -m <mount point>
-+ use an alternative directory to create the mini_fo
-+ mountpoint (default is currently "$MNT_DIR".
-+
-+ -h displays this message.
-+
-+EOF
-+exit 1;
-+}
-+
-+while getopts hm:s:d: OPTS
-+ do
-+ case $OPTS in
-+ s) SUFF="$OPTARG";;
-+ d) STO_DIR="$OPTARG";;
-+ m) MNT_DIR="$OPTARG";;
-+ h) HELP="set";;
-+ ?) usage
-+ exit 1;;
-+ esac
-+done
-+shift $(($OPTIND - 1))
-+
-+BASE="$1"
-+
-+if [ "x$HELP" == "xset" ]; then
-+ usage
-+ exit -1
-+fi
-+
-+# fix suffix
-+if [ "x$SUFF" != "x" ]; then
-+ SUFF="-$SUFF"
-+fi
-+
-+# kill trailing slashes
-+MNT_DIR=${MNT_DIR%/}
-+STO_DIR=${STO_DIR%/}
-+BASE=${BASE%/}
-+
-+
-+if ! [ -d "$BASE" ]; then
-+ echo "invalid base dir $BASE, run $0 -h for help."
-+ exit -1
-+fi
-+
-+# check opts
-+if ! [ -d "$MNT_DIR" ]; then
-+ echo "invalid mount dir $MNT_DIR, run $0 -h for help."
-+ exit -1
-+fi
-+
-+if ! [ -d "$STO_DIR" ]; then
-+ echo "invalid sto_dir_dir $STO_DIR, run $0 -h for help."
-+ exit -1
-+fi
-+
-+MNTP="$MNT_DIR/mini_fo-`basename $BASE`$SUFF"
-+STO="$STO_DIR/sto-`basename $BASE`$SUFF"
-+
-+# create the mount point if it doesn't exist
-+mkdir -p $MNTP
-+if [ $? -ne 0 ]; then
-+ echo "Error, failed to create mount point $MNTP"
-+fi
-+
-+mkdir -p $STO
-+if [ $? -ne 0 ]; then
-+ echo "Error, failed to create storage dir $STO"
-+fi
-+
-+# check if fs is already mounted
-+mount | grep mini_fo | grep $MNTP &> /dev/null
-+if [ $? -eq 0 ]; then
-+ echo "Error, existing mini_fo mount at $MNTP."
-+ exit -1
-+fi
-+
-+mount | grep mini_fo | grep $STO &> /dev/null
-+if [ $? -eq 0 ]; then
-+ echo "Error, $STO seems to be used already."
-+ exit -1
-+fi
-+
-+# mount
-+mount -t mini_fo -o base=$BASE,sto=$STO $BASE $MNTP
-+
-+if [ $? -ne 0 ]; then
-+ echo "Error, mounting failed, maybe no permisson to mount?"
-+fi
-Index: linux-2.6.21.7/fs/mini_fo/mmap.c
-===================================================================
---- /dev/null
-+++ linux-2.6.21.7/fs/mini_fo/mmap.c
-@@ -0,0 +1,637 @@
-+/*
-+ * Copyright (c) 1997-2003 Erez Zadok
-+ * Copyright (c) 2001-2003 Stony Brook University
-+ *
-+ * For specific licensing information, see the COPYING file distributed with
-+ * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
-+ *
-+ * This Copyright notice must be kept intact and distributed with all
-+ * fistgen sources INCLUDING sources generated by fistgen.
-+ */
-+/*
-+ * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
-+ *
-+ * 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.
-+ */
-+
-+/*
-+ * $Id$
-+ */
-+
-+#ifdef HAVE_CONFIG_H
-+# include <config.h>
-+#endif /* HAVE_CONFIG_H */
-+
-+#include "fist.h"
-+#include "mini_fo.h"
-+
-+
-+#ifdef FIST_COUNT_WRITES
-+/* for counting writes in the middle vs. regular writes */
-+unsigned long count_writes = 0, count_writes_middle = 0;
-+#endif /* FIST_COUNT_WRITES */
-+
-+/* forward declaration of commit write and prepare write */
-+STATIC int mini_fo_commit_write(file_t *file, page_t *page, unsigned from, unsigned to);
-+STATIC int mini_fo_prepare_write(file_t *file, page_t *page, unsigned from, unsigned to);
-+
-+
-+/*
-+ * Function for handling creation of holes when lseek-ing past the
-+ * end of the file and then writing some data.
-+ */
-+int
-+mini_fo_fill_zeros(file_t* file, page_t *page, unsigned from)
-+{
-+ int err = 0;
-+ dentry_t *dentry = file->f_dentry;
-+ inode_t *inode = dentry->d_inode;
-+ page_t *tmp_page;
-+ int index;
-+
-+ print_entry_location();
-+
-+ for (index = inode->i_size >> PAGE_CACHE_SHIFT; index < page->index; index++) {
-+ tmp_page = mini_fo_get1page(file, index);
-+ if (IS_ERR(tmp_page)) {
-+ err = PTR_ERR(tmp_page);
-+ goto out;
-+ }
-+
-+ /*
-+ * zero out rest of the contents of the page between the appropriate
-+ * offsets.
-+ */
-+ memset((char*)page_address(tmp_page) + (inode->i_size & ~PAGE_CACHE_MASK), 0, PAGE_CACHE_SIZE - (inode->i_size & ~PAGE_CACHE_MASK));
-+
-+ if (! (err = mini_fo_prepare_write(file, tmp_page, 0, PAGE_CACHE_SIZE)))
-+ err = mini_fo_commit_write(file, tmp_page, 0, PAGE_CACHE_SIZE);
-+
-+ page_cache_release(tmp_page);
-+ if (err < 0)
-+ goto out;
-+ if (current->need_resched)
-+ schedule();
-+ }
-+
-+ /* zero out appropriate parts of last page */
-+
-+ /*
-+ * if the encoding type is block, then adjust the 'from' (where the
-+ * zeroing will start) offset appropriately
-+ */
-+ from = from & (~(FIST_ENCODING_BLOCKSIZE - 1));
-+
-+ if ((from - (inode->i_size & ~PAGE_CACHE_MASK)) > 0) {
-+
-+ memset((char*)page_address(page) + (inode->i_size & ~PAGE_CACHE_MASK), 0, from - (inode->i_size & ~PAGE_CACHE_MASK));
-+ if (! (err = mini_fo_prepare_write(file, page, 0, PAGE_CACHE_SIZE)))
-+ err = mini_fo_commit_write(file, page, 0, PAGE_CACHE_SIZE);
-+
-+ if (err < 0)
-+ goto out;
-+ if (current->need_resched)
-+ schedule();
-+ }
-+
-+ out:
-+ print_exit_status(err);
-+ return err;
-+}
-+
-+
-+
-+STATIC int
-+mini_fo_writepage(page_t *page)
-+{
-+ int err = -EIO;
-+ inode_t *inode;
-+ inode_t *hidden_inode;
-+ page_t *hidden_page;
-+ char *kaddr, *hidden_kaddr;
-+
-+ print_entry_location();
-+
-+ inode = page->mapping->host;
-+ hidden_inode = itohi(inode);
-+
-+ /*
-+ * writepage is called when shared mmap'ed files need to write
-+ * their pages, while prepare/commit_write are called from the
-+ * non-paged write() interface. (However, in 2.3 the two interfaces
-+ * share the same cache, while in 2.2 they didn't.)
-+ *
-+ * So we pretty much have to duplicate much of what commit_write does.
-+ */
-+
-+ /* find lower page (returns a locked page) */
-+ hidden_page = grab_cache_page(hidden_inode->i_mapping, page->index);
-+ if (!hidden_page)
-+ goto out;
-+
-+ /* get page address, and encode it */
-+ kaddr = (char *) kmap(page);
-+ hidden_kaddr = (char*) kmap(hidden_page);
-+ mini_fo_encode_block(kaddr, hidden_kaddr, PAGE_CACHE_SIZE, inode, inode->i_sb, page->index);
-+ /* if encode_block could fail, then return error */
-+ kunmap(page);
-+ kunmap(hidden_page);
-+
-+ /* call lower writepage (expects locked page) */
-+ err = hidden_inode->i_mapping->a_ops->writepage(hidden_page);
-+
-+ /*
-+ * update mtime and ctime of lower level file system
-+ * mini_fo' mtime and ctime are updated by generic_file_write
-+ */
-+ hidden_inode->i_mtime = hidden_inode->i_ctime = CURRENT_TIME;
-+
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,1)
-+ UnlockPage(hidden_page); /* b/c grab_cache_page locked it */
-+# endif /* kernel older than 2.4.1 */
-+ page_cache_release(hidden_page); /* b/c grab_cache_page increased refcnt */
-+
-+ if (err)
-+ ClearPageUptodate(page);
-+ else
-+ SetPageUptodate(page);
-+ out:
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,1)
-+ UnlockPage(page);
-+# endif /* kernel 2.4.1 and newer */
-+ print_exit_status(err);
-+ return err;
-+}
-+
-+
-+/*
-+ * get one page from cache or lower f/s, return error otherwise.
-+ * returns unlocked, up-to-date page (if ok), with increased refcnt.
-+ */
-+page_t *
-+mini_fo_get1page(file_t *file, int index)
-+{
-+ page_t *page;
-+ dentry_t *dentry;
-+ inode_t *inode;
-+ struct address_space *mapping;
-+ int err;
-+
-+ print_entry_location();
-+
-+ dentry = file->f_dentry; /* CPW: Moved below print_entry_location */
-+ inode = dentry->d_inode;
-+ mapping = inode->i_mapping;
-+
-+ fist_dprint(8, "%s: read page index %d pid %d\n", __FUNCTION__, index, current->pid);
-+ if (index < 0) {
-+ printk("%s BUG: index=%d\n", __FUNCTION__, index);
-+ page = ERR_PTR(-EIO);
-+ goto out;
-+ }
-+ page = read_cache_page(mapping,
-+ index,
-+ (filler_t *) mapping->a_ops->readpage,
-+ (void *) file);
-+ if (IS_ERR(page))
-+ goto out;
-+ wait_on_page(page);
-+ if (!Page_Uptodate(page)) {
-+ lock_page(page);
-+ err = mapping->a_ops->readpage(file, page);
-+ if (err) {
-+ page = ERR_PTR(err);
-+ goto out;
-+ }
-+ wait_on_page(page);
-+ if (!Page_Uptodate(page)) {
-+ page = ERR_PTR(-EIO);
-+ goto out;
-+ }
-+ }
-+
-+ out:
-+ print_exit_pointer(page);
-+ return page;
-+}
-+
-+
-+/*
-+ * get one page from cache or lower f/s, return error otherwise.
-+ * similar to get1page, but doesn't guarantee that it will return
-+ * an unlocked page.
-+ */
-+page_t *
-+mini_fo_get1page_cached(file_t *file, int index)
-+{
-+ page_t *page;
-+ dentry_t *dentry;
-+ inode_t *inode;
-+ struct address_space *mapping;
-+ int err;
-+
-+ print_entry_location();
-+
-+ dentry = file->f_dentry; /* CPW: Moved below print_entry_location */
-+ inode = dentry->d_inode;
-+ mapping = inode->i_mapping;
-+
-+ fist_dprint(8, "%s: read page index %d pid %d\n", __FUNCTION__, index, current->pid);
-+ if (index < 0) {
-+ printk("%s BUG: index=%d\n", __FUNCTION__, index);
-+ page = ERR_PTR(-EIO);
-+ goto out;
-+ }
-+ page = read_cache_page(mapping,
-+ index,
-+ (filler_t *) mapping->a_ops->readpage,
-+ (void *) file);
-+ if (IS_ERR(page))
-+ goto out;
-+
-+ out:
-+ print_exit_pointer(page);
-+ return page;
-+}
-+
-+
-+/*
-+ * readpage is called from generic_page_read and the fault handler.
-+ * If your file system uses generic_page_read for the read op, it
-+ * must implement readpage.
-+ *
-+ * Readpage expects a locked page, and must unlock it.
-+ */
-+STATIC int
-+mini_fo_do_readpage(file_t *file, page_t *page)
-+{
-+ int err = -EIO;
-+ dentry_t *dentry;
-+ file_t *hidden_file = NULL;
-+ dentry_t *hidden_dentry;
-+ inode_t *inode;
-+ inode_t *hidden_inode;
-+ char *page_data;
-+ page_t *hidden_page;
-+ char *hidden_page_data;
-+ int real_size;
-+
-+ print_entry_location();
-+
-+ dentry = file->f_dentry; /* CPW: Moved below print_entry_location */
-+ if (ftopd(file) != NULL)
-+ hidden_file = ftohf(file);
-+ hidden_dentry = dtohd(dentry);
-+ inode = dentry->d_inode;
-+ hidden_inode = itohi(inode);
-+
-+ fist_dprint(7, "%s: requesting page %d from file %s\n", __FUNCTION__, page->index, dentry->d_name.name);
-+
-+ MALLOC_PAGE_POINTERS(hidden_pages, num_hidden_pages);
-+ MALLOC_PAGEDATA_POINTERS(hidden_pages_data, num_hidden_pages);
-+ FOR_EACH_PAGE
-+ CURRENT_HIDDEN_PAGE = NULL;
-+
-+ /* find lower page (returns a locked page) */
-+ FOR_EACH_PAGE {
-+ fist_dprint(8, "%s: Current page index = %d\n", __FUNCTION__, CURRENT_HIDDEN_PAGEINDEX);
-+ CURRENT_HIDDEN_PAGE = read_cache_page(hidden_inode->i_mapping,
-+ CURRENT_HIDDEN_PAGEINDEX,
-+ (filler_t *) hidden_inode->i_mapping->a_ops->readpage,
-+ (void *) hidden_file);
-+ if (IS_ERR(CURRENT_HIDDEN_PAGE)) {
-+ err = PTR_ERR(CURRENT_HIDDEN_PAGE);
-+ CURRENT_HIDDEN_PAGE = NULL;
-+ goto out_release;
-+ }
-+ }
-+
-+ /*
-+ * wait for the page data to show up
-+ * (signaled by readpage as unlocking the page)
-+ */
-+ FOR_EACH_PAGE {
-+ wait_on_page(CURRENT_HIDDEN_PAGE);
-+ if (!Page_Uptodate(CURRENT_HIDDEN_PAGE)) {
-+ /*
-+ * call readpage() again if we returned from wait_on_page with a
-+ * page that's not up-to-date; that can happen when a partial
-+ * page has a few buffers which are ok, but not the whole
-+ * page.
-+ */
-+ lock_page(CURRENT_HIDDEN_PAGE);
-+ err = hidden_inode->i_mapping->a_ops->readpage(hidden_file,
-+ CURRENT_HIDDEN_PAGE);
-+ if (err) {
-+ CURRENT_HIDDEN_PAGE = NULL;
-+ goto out_release;
-+ }
-+ wait_on_page(CURRENT_HIDDEN_PAGE);
-+ if (!Page_Uptodate(CURRENT_HIDDEN_PAGE)) {
-+ err = -EIO;
-+ goto out_release;
-+ }
-+ }
-+ }
-+
-+ /* map pages, get their addresses */
-+ page_data = (char *) kmap(page);
-+ FOR_EACH_PAGE
-+ CURRENT_HIDDEN_PAGEDATA = (char *) kmap(CURRENT_HIDDEN_PAGE);
-+
-+ /* if decode_block could fail, then return error */
-+ err = 0;
-+ real_size = hidden_inode->i_size - (page->index << PAGE_CACHE_SHIFT);
-+ if (real_size <= 0)
-+ memset(page_data, 0, PAGE_CACHE_SIZE);
-+ else if (real_size < PAGE_CACHE_SIZE) {
-+ mini_fo_decode_block(hidden_page_data, page_data, real_size, inode, inode->i_sb, page->index);
-+ memset(page_data + real_size, 0, PAGE_CACHE_SIZE - real_size);
-+ } else
-+ mini_fo_decode_block(hidden_page_data, page_data, PAGE_CACHE_SIZE, inode, inode->i_sb, page->index);
-+
-+ FOR_EACH_PAGE
-+ kunmap(CURRENT_HIDDEN_PAGE);
-+ kunmap(page);
-+
-+ out_release:
-+ FOR_EACH_PAGE
-+ if (CURRENT_HIDDEN_PAGE)
-+ page_cache_release(CURRENT_HIDDEN_PAGE); /* undo read_cache_page */
-+
-+ FREE_PAGE_POINTERS(hidden_pages, num_hidden_pages);
-+ FREE_PAGEDATA_POINTERS(hidden_pages_data, num_hidden_pages);
-+
-+ out:
-+ if (err == 0)
-+ SetPageUptodate(page);
-+ else
-+ ClearPageUptodate(page);
-+
-+ print_exit_status(err);
-+ return err;
-+}
-+
-+
-+STATIC int
-+mini_fo_readpage(file_t *file, page_t *page)
-+{
-+ int err;
-+ print_entry_location();
-+
-+ err = mini_fo_do_readpage(file, page);
-+
-+ /*
-+ * we have to unlock our page, b/c we _might_ have gotten a locked page.
-+ * but we no longer have to wakeup on our page here, b/c UnlockPage does
-+ * it
-+ */
-+ UnlockPage(page);
-+
-+ print_exit_status(err);
-+ return err;
-+}
-+
-+
-+STATIC int
-+mini_fo_prepare_write(file_t *file, page_t *page, unsigned from, unsigned to)
-+{
-+ int err = 0;
-+
-+ print_entry_location();
-+
-+ /*
-+ * we call kmap(page) only here, and do the kunmap
-+ * and the actual downcalls, including unlockpage and uncache
-+ * in commit_write.
-+ */
-+ kmap(page);
-+
-+ /* fast path for whole page writes */
-+ if (from == 0 && to == PAGE_CACHE_SIZE)
-+ goto out;
-+ /* read the page to "revalidate" our data */
-+ /* call the helper function which doesn't unlock the page */
-+ if (!Page_Uptodate(page))
-+ err = mini_fo_do_readpage(file, page);
-+
-+ out:
-+ print_exit_status(err);
-+ return err;
-+}
-+
-+
-+
-+STATIC int
-+mini_fo_commit_write(file_t *file, page_t *page, unsigned from, unsigned to)
-+{
-+ int err = -ENOMEM;
-+ inode_t *inode;
-+ inode_t *hidden_inode;
-+ page_t *hidden_page;
-+ file_t *hidden_file = NULL;
-+ loff_t pos;
-+ unsigned bytes = to - from;
-+ unsigned hidden_from, hidden_to, hidden_bytes;
-+
-+ print_entry_location();
-+
-+ inode = page->mapping->host; /* CPW: Moved below print_entry_location */
-+ hidden_inode = itohi(inode);
-+
-+ ASSERT(file != NULL);
-+ /*
-+ * here we have a kmapped page, with data from the user copied
-+ * into it. we need to encode_block it, and then call the lower
-+ * commit_write. We also need to simulate same behavior of
-+ * generic_file_write, and call prepare_write on the lower f/s first.
-+ */
-+#ifdef FIST_COUNT_WRITES
-+ count_writes++;
-+# endif /* FIST_COUNT_WRITES */
-+
-+ /* this is append and/or extend -- we can't have holes so fill them in */
-+ if (page->index > (hidden_inode->i_size >> PAGE_CACHE_SHIFT)) {
-+ page_t *tmp_page;
-+ int index;
-+ for (index = hidden_inode->i_size >> PAGE_CACHE_SHIFT; index < page->index; index++) {
-+ tmp_page = mini_fo_get1page(file, index);
-+ if (IS_ERR(tmp_page)) {
-+ err = PTR_ERR(tmp_page);
-+ goto out;
-+ }
-+ /* zero out the contents of the page at the appropriate offsets */
-+ memset((char*)page_address(tmp_page) + (inode->i_size & ~PAGE_CACHE_MASK), 0, PAGE_CACHE_SIZE - (inode->i_size & ~PAGE_CACHE_MASK));
-+ if (!(err = mini_fo_prepare_write(file, tmp_page, 0, PAGE_CACHE_SIZE)))
-+ err = mini_fo_commit_write(file, tmp_page, 0, PAGE_CACHE_SIZE);
-+ page_cache_release(tmp_page);
-+ if (err < 0)
-+ goto out;
-+ if (current->need_resched)
-+ schedule();
-+ }
-+ }
-+
-+ if (ftopd(file) != NULL)
-+ hidden_file = ftohf(file);
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_lock(&hidden_inode->i_mutex);
-+#else
-+ down(&hidden_inode->i_sem);
-+#endif
-+ /* find lower page (returns a locked page) */
-+ hidden_page = grab_cache_page(hidden_inode->i_mapping, page->index);
-+ if (!hidden_page)
-+ goto out;
-+
-+#if FIST_ENCODING_BLOCKSIZE > 1
-+# error encoding_blocksize greater than 1 is not yet supported
-+# endif /* FIST_ENCODING_BLOCKSIZE > 1 */
-+
-+ hidden_from = from & (~(FIST_ENCODING_BLOCKSIZE - 1));
-+ hidden_to = ((to + FIST_ENCODING_BLOCKSIZE - 1) & (~(FIST_ENCODING_BLOCKSIZE - 1)));
-+ if ((page->index << PAGE_CACHE_SHIFT) + to > hidden_inode->i_size) {
-+
-+ /*
-+ * if this call to commit_write had introduced holes and the code
-+ * for handling holes was invoked, then the beginning of this page
-+ * must be zeroed out
-+ * zero out bytes from 'size_of_file%pagesize' to 'from'.
-+ */
-+ if ((hidden_from - (inode->i_size & ~PAGE_CACHE_MASK)) > 0)
-+ memset((char*)page_address(page) + (inode->i_size & ~PAGE_CACHE_MASK), 0, hidden_from - (inode->i_size & ~PAGE_CACHE_MASK));
-+
-+ }
-+ hidden_bytes = hidden_to - hidden_from;
-+
-+ /* call lower prepare_write */
-+ err = -EINVAL;
-+ if (hidden_inode->i_mapping &&
-+ hidden_inode->i_mapping->a_ops &&
-+ hidden_inode->i_mapping->a_ops->prepare_write)
-+ err = hidden_inode->i_mapping->a_ops->prepare_write(hidden_file,
-+ hidden_page,
-+ hidden_from,
-+ hidden_to);
-+ if (err)
-+ /* don't leave locked pages behind, esp. on an ENOSPC */
-+ goto out_unlock;
-+
-+ fist_dprint(8, "%s: encoding %d bytes\n", __FUNCTION__, hidden_bytes);
-+ mini_fo_encode_block((char *) page_address(page) + hidden_from, (char*) page_address(hidden_page) + hidden_from, hidden_bytes, inode, inode->i_sb, page->index);
-+ /* if encode_block could fail, then goto unlock and return error */
-+
-+ /* call lower commit_write */
-+ err = hidden_inode->i_mapping->a_ops->commit_write(hidden_file,
-+ hidden_page,
-+ hidden_from,
-+ hidden_to);
-+
-+ if (err < 0)
-+ goto out_unlock;
-+
-+ err = bytes; /* convert error to no. of bytes */
-+
-+ inode->i_blocks = hidden_inode->i_blocks;
-+ /* we may have to update i_size */
-+ pos = (page->index << PAGE_CACHE_SHIFT) + to;
-+ if (pos > inode->i_size)
-+ inode->i_size = pos;
-+
-+ /*
-+ * update mtime and ctime of lower level file system
-+ * mini_fo' mtime and ctime are updated by generic_file_write
-+ */
-+ hidden_inode->i_mtime = hidden_inode->i_ctime = CURRENT_TIME;
-+
-+ mark_inode_dirty_sync(inode);
-+
-+ out_unlock:
-+ UnlockPage(hidden_page);
-+ page_cache_release(hidden_page);
-+ kunmap(page); /* kmap was done in prepare_write */
-+ out:
-+ /* we must set our page as up-to-date */
-+ if (err < 0)
-+ ClearPageUptodate(page);
-+ else
-+ SetPageUptodate(page);
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_unlock(&hidden_inode->i_mutex);
-+#else
-+ up(&hidden_inode->i_sem);
-+#endif
-+ print_exit_status(err);
-+ return err; /* assume all is ok */
-+}
-+
-+
-+STATIC int
-+mini_fo_bmap(struct address_space *mapping, long block)
-+{
-+ int err = 0;
-+ inode_t *inode;
-+ inode_t *hidden_inode;
-+
-+ print_entry_location();
-+
-+ inode = (inode_t *) mapping->host;
-+ hidden_inode = itohi(inode);
-+
-+ if (hidden_inode->i_mapping->a_ops->bmap)
-+ err = hidden_inode->i_mapping->a_ops->bmap(hidden_inode->i_mapping, block);
-+ print_exit_location();
-+ return err;
-+}
-+
-+
-+/*
-+ * This function is copied verbatim from mm/filemap.c.
-+ * XXX: It should be simply moved to some header file instead -- bug Al about it!
-+ */
-+static inline int sync_page(struct page *page)
-+{
-+ struct address_space *mapping = page->mapping;
-+
-+ if (mapping && mapping->a_ops && mapping->a_ops->sync_page)
-+ return mapping->a_ops->sync_page(page);
-+ return 0;
-+}
-+
-+
-+/*
-+ * XXX: we may not need this function if not FIST_FILTER_DATA.
-+ * FIXME: for FIST_FILTER_SCA, get all lower pages and sync them each.
-+ */
-+STATIC int
-+mini_fo_sync_page(page_t *page)
-+{
-+ int err = 0;
-+ inode_t *inode;
-+ inode_t *hidden_inode;
-+ page_t *hidden_page;
-+
-+ print_entry_location();
-+
-+ inode = page->mapping->host; /* CPW: Moved below print_entry_location */
-+ hidden_inode = itohi(inode);
-+
-+ /* find lower page (returns a locked page) */
-+ hidden_page = grab_cache_page(hidden_inode->i_mapping, page->index);
-+ if (!hidden_page)
-+ goto out;
-+
-+ err = sync_page(hidden_page);
-+
-+ UnlockPage(hidden_page); /* b/c grab_cache_page locked it */
-+ page_cache_release(hidden_page); /* b/c grab_cache_page increased refcnt */
-+
-+ out:
-+ print_exit_status(err);
-+ return err;
-+}
-Index: linux-2.6.21.7/fs/mini_fo/README
-===================================================================
---- /dev/null
-+++ linux-2.6.21.7/fs/mini_fo/README
-@@ -0,0 +1,163 @@
-+README for the mini_fo overlay file system
-+=========================================
-+
-+
-+WHAT IS MINI_FO?
-+----------------
-+
-+mini_fo is a virtual kernel file system that can make read-only
-+file systems writable. This is done by redirecting modifying operations
-+to a writeable location called "storage directory", and leaving the
-+original data in the "base directory" untouched. When reading, the
-+file system merges the modifed and original data so that only the
-+newest versions will appear. This occurs transparently to the user,
-+who can access the data like on any other read-write file system.
-+
-+Base and storage directories may be located on the same or on
-+different partitions and may be of different file system types. While
-+the storage directory obviously needs to be writable, the base may or
-+may not be writable, what doesn't matter as it will no be modified
-+anyway.
-+
-+
-+WHAT IS GOOD FOR?
-+-----------------
-+
-+The primary purpose of the mini_fo file system is to allow easy
-+software updates to embedded systems, that often store their root
-+file system in a read-only flash file system, but there are many
-+more as for example sandboxing, or for allowing live-cds to
-+permanently store information.
-+
-+
-+BUILDING
-+--------
-+This should be simple. Adjust the Makefile to point to the correct
-+kernel headers you want to build the module for. Then:
-+
-+ # make
-+
-+should build "mini_fo.o" for a 2.4 kernel or "mini_fo.ko" for a 2.6
-+kernel.
-+
-+If you are building the module for you current kernel, you can install
-+the module (as root):
-+
-+ # make install
-+
-+or uninstall with
-+
-+ # make uninstall
-+
-+
-+USING THE FILE SYSTEM
-+--------------------
-+
-+the general mount syntax is:
-+
-+ mount -t mini_fo -o base=<base directory>,sto=<storage directory>\
-+ <base directory> <mount point>
-+
-+Example:
-+
-+You have mounted a cdrom to /mnt/cdrom and want to modifiy some files
-+on it:
-+
-+load the module (as root)
-+
-+ # insmod mini_fo.o for a 2.4 kernel or
-+
-+ # insmod mini_fo.ko for a 2.6 kernel
-+
-+
-+create a storage dir in tmp and a mountpoint for mini_fo:
-+
-+ # mkdir /tmp/sto
-+ # mkdir /mnt/mini_fo
-+
-+and mount the mini_fo file system:
-+
-+ # mount -t mini_fo -o base=/mnt/cdrom,sto=/tmp/sto /mnt/cdrom /mnt/mini_fo
-+
-+
-+Now the data stored on the cd can be accessed via the mini_fo
-+mountpoint just like any read-write file system, files can be modified
-+and deleted, new ones can be created and so on. When done unmount the
-+file system:
-+
-+ # unmount /mnt/mini_fo
-+
-+Note that if the file system is mounted again using the same storage
-+file system, of course it will appear in the modified state again. If
-+you remount it using an new empty storage directory, it will be
-+unmodified. Therefore by executing:
-+
-+ # cd /tmp/sto
-+ # rm -rf *
-+
-+you can nuke all the changes you made to the original file system. But
-+ remember NEVER do this while the mini_fo file system is mounted!
-+
-+
-+Alternatively you can use the mini_fo-overlay bash script, that
-+simplifies managing mini_fo mounts. See TOOLS Section.
-+
-+
-+TOOLS
-+-----
-+
-+mini_fo-merge (experimental):
-+
-+This is a bash script that will merge changes contained in the storage
-+directory back to the base directory. This allows mini_fo to function
-+as a cache file system by overlaying a slow (network, ...) file system
-+and using a fast (ramdisk, ...) as storage. When done, changes can be
-+merged back to the (slow) base with mini_fo-merge. See "mini_fo-merge
-+-h" for details.
-+
-+It can be usefull for merging changes back after a successfull test
-+(patches, software updates...)
-+
-+
-+mini_fo-overlay:
-+
-+This bash script simplifies managing one or more mini_fo mounts. For
-+overlaying a directory called "basedir1", you can just call:
-+
-+ # mini_fo-overlay basedir1
-+
-+This will mount mini_fo with "basedir1" as base, "/tmp/sto-basedir1/"
-+as storage to "/mnt/mini_fo-basedir1/". It has more options though,
-+type "mini_fo-overlay -h" for details.
-+
-+
-+DOCUMENTATION, REPORTING BUGS, GETTING HELP
-+-------------------------------------------
-+
-+Please visit the mini_fo project page at:
-+
-+http://www.denx.de/twiki/bin/view/Know/MiniFOHome
-+
-+
-+WARNINGS
-+--------
-+
-+Never modify the base or the storage directorys while the mini_fo
-+file system is mounted, or you might crash you system. Simply accessing
-+and reading should not cause any trouble.
-+
-+Exporting a mini_fo mount point via NFS has not been tested, and may
-+or may not work.
-+
-+Check the RELEASE_NOTES for details on bugs and features.
-+
-+
-+
-+Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
-+
-+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.
-+
-+
-Index: linux-2.6.21.7/fs/mini_fo/RELEASE_NOTES
-===================================================================
---- /dev/null
-+++ linux-2.6.21.7/fs/mini_fo/RELEASE_NOTES
-@@ -0,0 +1,111 @@
-+Release: mini_fo-0.6.1 (v0-6-1)
-+Date: 21.09.2005
-+
-+
-+Changes:
-+--------
-+v0-6-1:
-+
-+- bugfixes (see ChangeLog)
-+
-+- two helper scripts "mini_fo_merge" and "mini_fo_overlay" (see
-+ README for details).
-+
-+v0-6-0:
-+
-+- Support for 2.4 and 2.6 (see Makefile)
-+
-+- Partial hard link support (creating works as expected, but already
-+ existing links in the base file system will be treated as if they
-+ were individual files).
-+
-+- Various bugfixes and cleanups.
-+
-+
-+v0-6-0-pre1:
-+
-+- This is mini_fo-0-6-0-pre1! This release is a complete rewrite of
-+ many vital mini_fo parts such as the old whiteout list code which
-+ has been replaced by the new META subsystem.
-+
-+- Light weight directory renaming implemented. This means if a
-+ directory is renamed via the mini_fo filesystem this will no longer
-+ result in a complete copy in storage, instead only one empty
-+ directory will be created. All base filed contained in the original
-+ directory stay there until modified.
-+
-+- Special files (creating, renaming, deleting etc.) now working.
-+
-+- Many bugfixes and cleanup, mini_fo is now a lot more stable.
-+
-+
-+v0-5-10:
-+
-+- Final release of the 0-5-* versions. Next will be a complete rewrite
-+ of many features. This release contains several bugfixes related to
-+ directory renaming.
-+
-+
-+v0-5-10-pre6:
-+
-+- Lots of cleanup and several bugfixes related to directory deleting
-+
-+- Directory renaming suddenly works, what is most likely due to the
-+ fact tha that "mv" is smart: if the classic rename doesn't work it
-+ will assume that source and target file are on different fs and will
-+ copy the directory and try to remove the source directory. Until
-+ directory removing wasn't implemented, it would fail to do this and
-+ rollback.
-+ So, directory renaming works for now, but it doesn't yet do what you
-+ would expect from a overlay fs, so use with care.
-+
-+
-+v0-5-10-pre5:
-+
-+- implemented directory deleting
-+- made parsing of mount options more stable
-+- New format of mount options! (See README)
-+- I can't reproduce the unknown panic with 2.4.25 anymore, so I'll
-+ happily assume it never existed!
-+
-+
-+Implemented features:
-+---------------------
-+
-+- creating hard links (see BUGS on already existing hard links)
-+- lightweight directory renaming
-+- renaming device files, pipes, sockets, etc.
-+- creating, renaming, deleting of special files
-+- deleting directorys
-+- general directory reading (simple "ls" )
-+- creating files in existing directorys
-+- creating directorys
-+- renaming files.
-+- reading and writing files (involves opening)
-+- appending to files (creates copy in storage)
-+- deleting files
-+- llseek works too, what allows editors to work
-+- persistency (a deleted file stay deleted over remounts)
-+- use of symbolic links
-+- creating of device files
-+
-+
-+Not (yet) implemented features:
-+-------------------------------
-+
-+- full hard link support.
-+
-+
-+
-+BUGS:
-+-----
-+
-+Hard links in the base file system will be treated as individual
-+files, not as links to one inode.
-+
-+The main problem with hard links isn't allowing to create them, but
-+their pure existence. If you modify a base hard link, the changes made
-+will only show up on this link, the other link will remain in the
-+original state. I hope to fix this someday. Please note that this does
-+not effect the special hard links '.' and '..', that are handled
-+seperately by the lower fs.
-Index: linux-2.6.21.7/fs/mini_fo/state.c
-===================================================================
---- /dev/null
-+++ linux-2.6.21.7/fs/mini_fo/state.c
-@@ -0,0 +1,620 @@
-+/*
-+ * Copyright (C) 2005 Markus Klotzbuecher <mk@creamnet.de>
-+ *
-+ * 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.
-+ */
-+
-+#ifdef HAVE_CONFIG_H
-+# include <config.h>
-+#endif /* HAVE_CONFIG_H */
-+
-+#include "fist.h"
-+#include "mini_fo.h"
-+
-+
-+/* create the storage file, setup new states */
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
-+int create_sto_reg_file(dentry_t *dentry, int mode, struct nameidata *nd)
-+#else
-+int create_sto_reg_file(dentry_t *dentry, int mode)
-+#endif
-+{
-+ int err = 0;
-+ inode_t *dir;
-+ dentry_t *hidden_sto_dentry;
-+ dentry_t *hidden_sto_dir_dentry;
-+
-+ if(exists_in_storage(dentry)) {
-+ printk(KERN_CRIT "mini_fo: create_sto_file: wrong type or state.\n");
-+ err = -EINVAL;
-+ goto out;
-+ }
-+ err = get_neg_sto_dentry(dentry);
-+
-+ if (err) {
-+ printk(KERN_CRIT "mini_fo: create_sto_file: ERROR getting neg. sto dentry.\n");
-+ goto out;
-+ }
-+
-+ dir = dentry->d_parent->d_inode;
-+ hidden_sto_dentry = dtohd2(dentry);
-+
-+ /* lock parent */
-+ hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
-+#else
-+ down(&hidden_sto_dir_dentry->d_inode->i_sem);
-+#endif
-+
-+ err = PTR_ERR(hidden_sto_dir_dentry);
-+ if (IS_ERR(hidden_sto_dir_dentry))
-+ goto out;
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
-+ err = vfs_create(hidden_sto_dir_dentry->d_inode,
-+ hidden_sto_dentry,
-+ mode, nd);
-+#else
-+ err = vfs_create(hidden_sto_dir_dentry->d_inode,
-+ hidden_sto_dentry,
-+ mode);
-+#endif
-+ if(err) {
-+ printk(KERN_CRIT "mini_fo: create_sto_file: ERROR creating sto file.\n");
-+ goto out_lock;
-+ }
-+
-+ if(!dtohd2(dentry)->d_inode) {
-+ printk(KERN_CRIT "mini_fo: create_sto_file: ERROR creating sto file [2].\n");
-+ err = -EINVAL;
-+ goto out_lock;
-+ }
-+
-+ /* interpose the new inode */
-+ if(dtost(dentry) == DELETED) {
-+ dtost(dentry) = DEL_REWRITTEN;
-+ err = mini_fo_tri_interpose(NULL, hidden_sto_dentry, dentry, dir->i_sb, 0);
-+ if(err)
-+ goto out_lock;
-+ }
-+ else if(dtost(dentry) == NON_EXISTANT) {
-+ dtost(dentry) = CREATED;
-+ err = mini_fo_tri_interpose(dtohd(dentry), hidden_sto_dentry, dentry, dir->i_sb, 0);
-+ if(err)
-+ goto out_lock;
-+ }
-+ else if(dtost(dentry) == UNMODIFIED) {
-+ dtost(dentry) = MODIFIED;
-+ /* interpose on new inode */
-+ if(itohi2(dentry->d_inode) != NULL) {
-+ printk(KERN_CRIT "mini_fo: create_sto_file: invalid inode detected.\n");
-+ err = -EINVAL;
-+ goto out_lock;
-+ }
-+ itohi2(dentry->d_inode) = igrab(dtohd2(dentry)->d_inode);
-+ }
-+ fist_copy_attr_timesizes(dentry->d_parent->d_inode,
-+ hidden_sto_dir_dentry->d_inode);
-+
-+ out_lock:
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
-+#else
-+ up(&hidden_sto_dir_dentry->d_inode->i_sem);
-+#endif
-+ dput(hidden_sto_dir_dentry);
-+ out:
-+ return err;
-+}
-+
-+/* create the sto dir, setup states */
-+int create_sto_dir(dentry_t *dentry, int mode)
-+{
-+ int err = 0;
-+ inode_t *dir;
-+ dentry_t *hidden_sto_dentry;
-+ dentry_t *hidden_sto_dir_dentry;
-+
-+ /* had to take the "!S_ISDIR(mode))" check out, because it failed */
-+ if(exists_in_storage(dentry)) {
-+ printk(KERN_CRIT "mini_fo: create_sto_dir: wrong type or state.\\
-+n");
-+ err = -EINVAL;
-+ goto out;
-+ }
-+
-+ err = get_neg_sto_dentry(dentry);
-+ if(err) {
-+ err = -EINVAL;
-+ goto out;
-+ }
-+
-+ dir = dentry->d_parent->d_inode;
-+ hidden_sto_dentry = dtohd2(dentry);
-+
-+ /* was: hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry); */
-+ hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
-+#else
-+ down(&hidden_sto_dir_dentry->d_inode->i_sem);
-+#endif
-+
-+ err = PTR_ERR(hidden_sto_dir_dentry);
-+ if (IS_ERR(hidden_sto_dir_dentry))
-+ goto out;
-+
-+ err = vfs_mkdir(hidden_sto_dir_dentry->d_inode,
-+ hidden_sto_dentry,
-+ mode);
-+ if(err) {
-+ printk(KERN_CRIT "mini_fo: create_sto_dir: ERROR creating sto dir.\n");
-+ goto out_lock;
-+ }
-+
-+ if(!dtohd2(dentry)->d_inode) {
-+ printk(KERN_CRIT "mini_fo: create_sto_dir: ERROR creating sto dir [2].\n");
-+ err = -EINVAL;
-+ goto out_lock;
-+ }
-+
-+ /* interpose the new inode */
-+ if(dtost(dentry) == DELETED) {
-+ dtost(dentry) = DEL_REWRITTEN;
-+ err = mini_fo_tri_interpose(NULL, hidden_sto_dentry, dentry, dir->i_sb, 0);
-+ if(err)
-+ goto out_lock;
-+ }
-+ else if(dtopd(dentry)->state == NON_EXISTANT) {
-+ dtopd(dentry)->state = CREATED;
-+ err = mini_fo_tri_interpose(dtohd(dentry), hidden_sto_dentry, dentry, dir->i_sb, 0);
-+ if(err)
-+ goto out_lock;
-+ }
-+ else if(dtopd(dentry)->state == UNMODIFIED) {
-+ dtopd(dentry)->state = MODIFIED;
-+ /* interpose on new inode */
-+ if(itohi2(dentry->d_inode) != NULL) {
-+ printk(KERN_CRIT "mini_fo: create_sto_dir: ERROR, invalid inode detected.\n");
-+ err = -EINVAL;
-+ goto out_lock;
-+ }
-+ itohi2(dentry->d_inode) = igrab(dtohd2(dentry)->d_inode);
-+ }
-+
-+ fist_copy_attr_timesizes(dir, hidden_sto_dir_dentry->d_inode);
-+
-+ /* initalize the wol list */
-+ itopd(dentry->d_inode)->deleted_list_size = -1;
-+ itopd(dentry->d_inode)->renamed_list_size = -1;
-+ meta_build_lists(dentry);
-+
-+
-+ out_lock:
-+ /* was: unlock_dir(hidden_sto_dir_dentry); */
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
-+#else
-+ up(&hidden_sto_dir_dentry->d_inode->i_sem);
-+#endif
-+ dput(hidden_sto_dir_dentry);
-+ out:
-+ return err;
-+}
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
-+int create_sto_nod(dentry_t *dentry, int mode, dev_t dev)
-+#else
-+int create_sto_nod(dentry_t *dentry, int mode, int dev)
-+#endif
-+{
-+ int err = 0;
-+ inode_t *dir;
-+ dentry_t *hidden_sto_dentry;
-+ dentry_t *hidden_sto_dir_dentry;
-+
-+ if(exists_in_storage(dentry)) {
-+ err = -EEXIST;
-+ goto out;
-+ }
-+ err = get_neg_sto_dentry(dentry);
-+
-+ if (err) {
-+ printk(KERN_CRIT "mini_fo: create_sto_nod: ERROR getting neg. sto dentry.\n");
-+ goto out;
-+ }
-+
-+ dir = dentry->d_parent->d_inode;
-+ hidden_sto_dentry = dtohd2(dentry);
-+
-+ /* lock parent */
-+ hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
-+#else
-+ down(&hidden_sto_dir_dentry->d_inode->i_sem);
-+#endif
-+
-+ err = PTR_ERR(hidden_sto_dir_dentry);
-+ if (IS_ERR(hidden_sto_dir_dentry))
-+ goto out;
-+
-+ err = vfs_mknod(hidden_sto_dir_dentry->d_inode, hidden_sto_dentry, mode, dev);
-+ if(err)
-+ goto out_lock;
-+
-+ if(!dtohd2(dentry)->d_inode) {
-+ printk(KERN_CRIT "mini_fo: create_sto_nod: creating storage inode failed [1].\n");
-+ err = -EINVAL; /* return something indicating failure */
-+ goto out_lock;
-+ }
-+
-+ /* interpose the new inode */
-+ if(dtost(dentry) == DELETED) {
-+ dtost(dentry) = DEL_REWRITTEN;
-+ err = mini_fo_tri_interpose(NULL, hidden_sto_dentry, dentry, dir->i_sb, 0);
-+ if(err)
-+ goto out_lock;
-+ }
-+ else if(dtost(dentry) == NON_EXISTANT) {
-+ dtost(dentry) = CREATED;
-+ err = mini_fo_tri_interpose(dtohd(dentry), hidden_sto_dentry, dentry, dir->i_sb, 0);
-+ if(err)
-+ goto out_lock;
-+ }
-+ else if(dtost(dentry) == UNMODIFIED) {
-+ dtost(dentry) = MODIFIED;
-+ /* interpose on new inode */
-+ if(itohi2(dentry->d_inode) != NULL) {
-+ printk(KERN_CRIT "mini_fo: create_sto_nod: error, invalid inode detected.\n");
-+ err = -EINVAL;
-+ goto out_lock;
-+ }
-+ itohi2(dentry->d_inode) = igrab(dtohd2(dentry)->d_inode);
-+ }
-+
-+ fist_copy_attr_timesizes(dir, hidden_sto_dir_dentry->d_inode);
-+
-+ out_lock:
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
-+#else
-+ up(&hidden_sto_dir_dentry->d_inode->i_sem);
-+#endif
-+ dput(hidden_sto_dir_dentry);
-+ out:
-+ return err;
-+}
-+
-+
-+/* unimplemented (and possibly not usefull):
-+
-+ nondir-del_to_del_rew
-+ nondir-non_exist_to_creat
-+
-+ dir-unmod_to_del
-+ dir-mod_to_del
-+ dir-creat_to_del
-+ dir-del_rew_to_del
-+ dir-del_to_del_rew
-+ dir-non_exist_to_creat
-+*/
-+
-+
-+/* bring a file of any type from state UNMODIFIED to MODIFIED */
-+int nondir_unmod_to_mod(dentry_t *dentry, int cp_flag)
-+{
-+ int err = 0;
-+ struct vfsmount *tgt_mnt;
-+ struct vfsmount *src_mnt;
-+ dentry_t *tgt_dentry;
-+ dentry_t *src_dentry;
-+ dentry_t *hidden_sto_dentry;
-+ dentry_t *hidden_sto_dir_dentry;
-+
-+ check_mini_fo_dentry(dentry);
-+
-+ if((dtost(dentry) != UNMODIFIED) ||
-+ S_ISDIR(dentry->d_inode->i_mode)) {
-+ printk(KERN_CRIT "mini_fo: nondir_unmod_to_mod: \
-+ wrong type or state.\n");
-+ err = -1;
-+ goto out;
-+ }
-+ err = get_neg_sto_dentry(dentry);
-+
-+ if (err) {
-+ printk(KERN_CRIT "mini_fo: nondir_unmod_to_mod: \
-+ ERROR getting neg. sto dentry.\n");
-+ goto out;
-+ }
-+
-+ /* create sto file */
-+ hidden_sto_dentry = dtohd2(dentry);
-+
-+ /* lock parent */
-+ hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
-+#else
-+ down(&hidden_sto_dir_dentry->d_inode->i_sem);
-+#endif
-+
-+ err = PTR_ERR(hidden_sto_dir_dentry);
-+ if (IS_ERR(hidden_sto_dir_dentry))
-+ goto out;
-+
-+ /* handle different types of nondirs */
-+ if(S_ISCHR(dentry->d_inode->i_mode) ||
-+ S_ISBLK(dentry->d_inode->i_mode)) {
-+ err = vfs_mknod(hidden_sto_dir_dentry->d_inode,
-+ hidden_sto_dentry,
-+ dtohd(dentry)->d_inode->i_mode,
-+ dtohd(dentry)->d_inode->i_rdev);
-+ }
-+
-+ else if(S_ISREG(dentry->d_inode->i_mode)) {
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
-+ err = vfs_create(hidden_sto_dir_dentry->d_inode,
-+ hidden_sto_dentry,
-+ dtohd(dentry)->d_inode->i_mode, NULL);
-+#else
-+ err = vfs_create(hidden_sto_dir_dentry->d_inode,
-+ hidden_sto_dentry,
-+ dtohd(dentry)->d_inode->i_mode);
-+#endif
-+ }
-+ if(err) {
-+ printk(KERN_CRIT "mini_fo: nondir_unmod_to_mod: \
-+ ERROR creating sto file.\n");
-+ goto out_lock;
-+ }
-+
-+ /* interpose on new inode */
-+ if(itohi2(dentry->d_inode) != NULL) {
-+ printk(KERN_CRIT "mini_fo: nondir_unmod_to_mod: \
-+ ERROR, invalid inode detected.\n");
-+ err = -EINVAL;
-+ goto out_lock;
-+ }
-+
-+ itohi2(dentry->d_inode) = igrab(dtohd2(dentry)->d_inode);
-+
-+ fist_copy_attr_timesizes(dentry->d_parent->d_inode,
-+ hidden_sto_dir_dentry->d_inode);
-+ dtost(dentry) = MODIFIED;
-+
-+ /* copy contents if regular file and cp_flag = 1 */
-+ if((cp_flag == 1) && S_ISREG(dentry->d_inode->i_mode)) {
-+
-+ /* unlock first */
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
-+#else
-+ up(&hidden_sto_dir_dentry->d_inode->i_sem);
-+#endif
-+
-+ dput(hidden_sto_dir_dentry);
-+
-+ tgt_dentry = dtohd2(dentry);
-+ tgt_mnt = stopd(dentry->d_inode->i_sb)->hidden_mnt2;
-+ src_dentry = dtohd(dentry);
-+ src_mnt = stopd(dentry->d_inode->i_sb)->hidden_mnt;
-+
-+ err = mini_fo_cp_cont(tgt_dentry, tgt_mnt,
-+ src_dentry, src_mnt);
-+ if(err) {
-+ printk(KERN_CRIT "mini_fo: nondir_unmod_to_mod: \
-+ ERROR copying contents.\n");
-+ }
-+ goto out;
-+ }
-+
-+ out_lock:
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
-+#else
-+ up(&hidden_sto_dir_dentry->d_inode->i_sem);
-+#endif
-+ dput(hidden_sto_dir_dentry);
-+ out:
-+ return err;
-+}
-+
-+/* this function is currently identical to nondir_creat_to_del */
-+int nondir_del_rew_to_del(dentry_t *dentry)
-+{
-+ return nondir_creat_to_del(dentry);
-+}
-+
-+int nondir_creat_to_del(dentry_t *dentry)
-+{
-+ int err = 0;
-+
-+ inode_t *hidden_sto_dir_inode;
-+ dentry_t *hidden_sto_dir_dentry;
-+ dentry_t *hidden_sto_dentry;
-+
-+ check_mini_fo_dentry(dentry);
-+
-+ /* for now this function serves for both state DEL_REWRITTEN and
-+ * CREATED */
-+ if(!(dtost(dentry) == CREATED || (dtost(dentry) == DEL_REWRITTEN)) ||
-+ S_ISDIR(dentry->d_inode->i_mode)) {
-+ printk(KERN_CRIT "mini_fo: nondir_mod_to_del/del_rew_to_del: \
-+ wrong type or state.\n");
-+ err = -1;
-+ goto out;
-+ }
-+
-+ hidden_sto_dir_inode = itohi2(dentry->d_parent->d_inode);
-+ hidden_sto_dentry = dtohd2(dentry);
-+
-+ /* was: hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry);*/
-+ hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
-+#else
-+ down(&hidden_sto_dir_dentry->d_inode->i_sem);
-+#endif
-+
-+ /* avoid destroying the hidden inode if the file is in use */
-+ dget(hidden_sto_dentry);
-+ err = vfs_unlink(hidden_sto_dir_inode, hidden_sto_dentry);
-+ dput(hidden_sto_dentry);
-+ if(!err)
-+ d_delete(hidden_sto_dentry);
-+
-+ /* propagate number of hard-links */
-+ dentry->d_inode->i_nlink = itohi2(dentry->d_inode)->i_nlink;
-+
-+ dtost(dentry) = NON_EXISTANT;
-+
-+ /* was: unlock_dir(hidden_sto_dir_dentry); */
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
-+#else
-+ up(&hidden_sto_dir_dentry->d_inode->i_sem);
-+#endif
-+ dput(hidden_sto_dir_dentry);
-+
-+ out:
-+ return err;
-+}
-+
-+int nondir_mod_to_del(dentry_t *dentry)
-+{
-+ int err;
-+ dentry_t *hidden_sto_dentry;
-+ inode_t *hidden_sto_dir_inode;
-+ dentry_t *hidden_sto_dir_dentry;
-+
-+ check_mini_fo_dentry(dentry);
-+
-+ if(dtost(dentry) != MODIFIED ||
-+ S_ISDIR(dentry->d_inode->i_mode)) {
-+ printk(KERN_CRIT "mini_fo: nondir_mod_to_del: \
-+ wrong type or state.\n");
-+ err = -1;
-+ goto out;
-+ }
-+
-+ hidden_sto_dir_inode = itohi2(dentry->d_parent->d_inode);
-+ hidden_sto_dentry = dtohd2(dentry);
-+
-+ /* was hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry); */
-+ hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
-+#else
-+ down(&hidden_sto_dir_dentry->d_inode->i_sem);
-+#endif
-+
-+ /* avoid destroying the hidden inode if the file is in use */
-+ dget(hidden_sto_dentry);
-+ err = vfs_unlink(hidden_sto_dir_inode, hidden_sto_dentry);
-+ dput(hidden_sto_dentry);
-+ if(!err)
-+ d_delete(hidden_sto_dentry);
-+
-+ /* propagate number of hard-links */
-+ dentry->d_inode->i_nlink = itohi2(dentry->d_inode)->i_nlink;
-+
-+ /* dput base dentry, this will relase the inode and free the
-+ * dentry, as we will never need it again. */
-+ dput(dtohd(dentry));
-+ dtohd(dentry) = NULL;
-+ dtost(dentry) = DELETED;
-+
-+ /* add deleted file to META-file */
-+ meta_add_d_entry(dentry->d_parent,
-+ dentry->d_name.name,
-+ dentry->d_name.len);
-+
-+ /* was: unlock_dir(hidden_sto_dir_dentry); */
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
-+#else
-+ up(&hidden_sto_dir_dentry->d_inode->i_sem);
-+#endif
-+ dput(hidden_sto_dir_dentry);
-+
-+ out:
-+ return err;
-+}
-+
-+int nondir_unmod_to_del(dentry_t *dentry)
-+{
-+ int err = 0;
-+
-+ check_mini_fo_dentry(dentry);
-+
-+ if(dtost(dentry) != UNMODIFIED ||
-+ S_ISDIR(dentry->d_inode->i_mode)) {
-+ printk(KERN_CRIT "mini_fo: nondir_unmod_to_del: \
-+ wrong type or state.\n");
-+ err = -1;
-+ goto out;
-+ }
-+
-+ /* next we have to get a negative dentry for the storage file */
-+ err = get_neg_sto_dentry(dentry);
-+
-+ if(err)
-+ goto out;
-+
-+ /* add deleted file to META lists */
-+ err = meta_add_d_entry(dentry->d_parent,
-+ dentry->d_name.name,
-+ dentry->d_name.len);
-+
-+ if(err)
-+ goto out;
-+
-+ /* dput base dentry, this will relase the inode and free the
-+ * dentry, as we will never need it again. */
-+ dput(dtohd(dentry));
-+ dtohd(dentry) = NULL;
-+ dtost(dentry) = DELETED;
-+
-+ out:
-+ return err;
-+}
-+
-+/* bring a dir from state UNMODIFIED to MODIFIED */
-+int dir_unmod_to_mod(dentry_t *dentry)
-+{
-+ int err;
-+
-+ check_mini_fo_dentry(dentry);
-+
-+ if(dtost(dentry) != UNMODIFIED ||
-+ !S_ISDIR(dentry->d_inode->i_mode)) {
-+ printk(KERN_CRIT "mini_fo: dir_unmod_to_mod: \
-+ wrong type or state.\n");
-+ err = -1;
-+ goto out;
-+ }
-+
-+ /* this creates our dir incl. sto. structure */
-+ err = build_sto_structure(dentry->d_parent, dentry);
-+ if(err) {
-+ printk(KERN_CRIT "mini_fo: dir_unmod_to_mod: \
-+ build_sto_structure failed.\n");
-+ goto out;
-+ }
-+ out:
-+ return err;
-+}
-+
-Index: linux-2.6.21.7/fs/mini_fo/super.c
-===================================================================
---- /dev/null
-+++ linux-2.6.21.7/fs/mini_fo/super.c
-@@ -0,0 +1,281 @@
-+/*
-+ * Copyright (c) 1997-2003 Erez Zadok
-+ * Copyright (c) 2001-2003 Stony Brook University
-+ *
-+ * For specific licensing information, see the COPYING file distributed with
-+ * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
-+ *
-+ * This Copyright notice must be kept intact and distributed with all
-+ * fistgen sources INCLUDING sources generated by fistgen.
-+ */
-+/*
-+ * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
-+ *
-+ * 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.
-+ */
-+
-+/*
-+ * $Id$
-+ */
-+
-+#ifdef HAVE_CONFIG_H
-+# include <config.h>
-+#endif
-+
-+#include "fist.h"
-+#include "mini_fo.h"
-+
-+
-+STATIC void
-+mini_fo_read_inode(inode_t *inode)
-+{
-+ static struct address_space_operations mini_fo_empty_aops;
-+
-+ __itopd(inode) = kmalloc(sizeof(struct mini_fo_inode_info), GFP_KERNEL);
-+ if (!itopd(inode)) {
-+ printk("<0>%s:%s:%d: No kernel memory!\n", __FILE__, __FUNCTION__, __LINE__);
-+ ASSERT(NULL);
-+ }
-+ itohi(inode) = NULL;
-+ itohi2(inode) = NULL;
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
-+ inode->i_version++;
-+#else
-+ inode->i_version = ++event; /* increment inode version */
-+#endif
-+ inode->i_op = &mini_fo_main_iops;
-+ inode->i_fop = &mini_fo_main_fops;
-+#if 0
-+ /*
-+ * XXX: To export a file system via NFS, it has to have the
-+ * FS_REQUIRES_DEV flag, so turn it on. But should we inherit it from
-+ * the lower file system, or can we allow our file system to be exported
-+ * even if the lower one cannot be natively exported.
-+ */
-+ inode->i_sb->s_type->fs_flags |= FS_REQUIRES_DEV;
-+ /*
-+ * OK, the above was a hack, which is now turned off because it may
-+ * cause a panic/oops on some systems. The correct way to export a
-+ * "nodev" filesystem is via using nfs-utils > 1.0 and the "fsid=" export
-+ * parameter, which requires 2.4.20 or later.
-+ */
-+#endif
-+ /* I don't think ->a_ops is ever allowed to be NULL */
-+ inode->i_mapping->a_ops = &mini_fo_empty_aops;
-+}
-+
-+
-+#if defined(FIST_DEBUG) || defined(FIST_FILTER_SCA)
-+/*
-+ * No need to call write_inode() on the lower inode, as it
-+ * will have been marked 'dirty' anyway. But we might need
-+ * to write some of our own stuff to disk.
-+ */
-+STATIC void
-+mini_fo_write_inode(inode_t *inode, int sync)
-+{
-+ print_entry_location();
-+ print_exit_location();
-+}
-+#endif /* defined(FIST_DEBUG) || defined(FIST_FILTER_SCA) */
-+
-+
-+STATIC void
-+mini_fo_put_inode(inode_t *inode)
-+{
-+ /*
-+ * This is really funky stuff:
-+ * Basically, if i_count == 1, iput will then decrement it and this inode will be destroyed.
-+ * It is currently holding a reference to the hidden inode.
-+ * Therefore, it needs to release that reference by calling iput on the hidden inode.
-+ * iput() _will_ do it for us (by calling our clear_inode), but _only_ if i_nlink == 0.
-+ * The problem is, NFS keeps i_nlink == 1 for silly_rename'd files.
-+ * So we must for our i_nlink to 0 here to trick iput() into calling our clear_inode.
-+ */
-+ if (atomic_read(&inode->i_count) == 1)
-+ inode->i_nlink = 0;
-+}
-+
-+
-+#if defined(FIST_DEBUG) || defined(FIST_FILTER_SCA)
-+/*
-+ * we now define delete_inode, because there are two VFS paths that may
-+ * destroy an inode: one of them calls clear inode before doing everything
-+ * else that's needed, and the other is fine. This way we truncate the inode
-+ * size (and its pages) and then clear our own inode, which will do an iput
-+ * on our and the lower inode.
-+ */
-+STATIC void
-+mini_fo_delete_inode(inode_t *inode)
-+{
-+ print_entry_location();
-+
-+ fist_checkinode(inode, "mini_fo_delete_inode IN");
-+ inode->i_size = 0; /* every f/s seems to do that */
-+ clear_inode(inode);
-+
-+ print_exit_location();
-+}
-+#endif /* defined(FIST_DEBUG) || defined(FIST_FILTER_SCA) */
-+
-+
-+/* final actions when unmounting a file system */
-+STATIC void
-+mini_fo_put_super(super_block_t *sb)
-+{
-+ if (stopd(sb)) {
-+ mntput(stopd(sb)->hidden_mnt);
-+ mntput(stopd(sb)->hidden_mnt2);
-+
-+ /* mk: no! dput(stopd(sb)->base_dir_dentry);
-+ dput(stopd(sb)->storage_dir_dentry); */
-+
-+ kfree(stopd(sb));
-+ __stopd(sb) = NULL;
-+ }
-+}
-+
-+
-+#ifdef NOT_NEEDED
-+/*
-+ * This is called in do_umount before put_super.
-+ * The superblock lock is not held yet.
-+ * We probably do not need to define this or call write_super
-+ * on the hidden_sb, because sync_supers() will get to hidden_sb
-+ * sooner or later. But it is also called from file_fsync()...
-+ */
-+STATIC void
-+mini_fo_write_super(super_block_t *sb)
-+{
-+ return;
-+}
-+#endif /* NOT_NEEDED */
-+
-+
-+STATIC int
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
-+mini_fo_statfs(struct dentry *d, struct kstatfs *buf)
-+#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
-+mini_fo_statfs(super_block_t *sb, struct kstatfs *buf)
-+#else
-+mini_fo_statfs(super_block_t *sb, struct statfs *buf)
-+#endif
-+{
-+ int err = 0;
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
-+ struct dentry *hidden_d;
-+
-+ hidden_d = dtohd(d);
-+ err = vfs_statfs(hidden_d, buf);
-+#else
-+ super_block_t *hidden_sb;
-+
-+ hidden_sb = stohs(sb);
-+ err = vfs_statfs(hidden_sb, buf);
-+#endif
-+
-+ return err;
-+}
-+
-+
-+/*
-+ * XXX: not implemented. This is not allowed yet.
-+ * Should we call this on the hidden_sb? Probably not.
-+ */
-+STATIC int
-+mini_fo_remount_fs(super_block_t *sb, int *flags, char *data)
-+{
-+ //printk(KERN_CRIT "mini_fo_remount_fs: WARNING, this function is umimplemented.\n");
-+ return -ENOSYS;
-+}
-+
-+
-+/*
-+ * Called by iput() when the inode reference count reached zero
-+ * and the inode is not hashed anywhere. Used to clear anything
-+ * that needs to be, before the inode is completely destroyed and put
-+ * on the inode free list.
-+ */
-+STATIC void
-+mini_fo_clear_inode(inode_t *inode)
-+{
-+ /*
-+ * Decrement a reference to a hidden_inode, which was incremented
-+ * by our read_inode when it was created initially.
-+ */
-+
-+ /* release the wol_list */
-+ if(S_ISDIR(inode->i_mode)) {
-+ __meta_put_lists(inode);
-+ }
-+
-+ /* mk: fan out fun */
-+ if(itohi(inode))
-+ iput(itohi(inode));
-+ if(itohi2(inode))
-+ iput(itohi2(inode));
-+
-+ // XXX: why this assertion fails?
-+ // because it doesn't like us
-+ // ASSERT((inode->i_state & I_DIRTY) == 0);
-+ kfree(itopd(inode));
-+ __itopd(inode) = NULL;
-+}
-+
-+
-+/*
-+ * Called in do_umount() if the MNT_FORCE flag was used and this
-+ * function is defined. See comment in linux/fs/super.c:do_umount().
-+ * Used only in nfs, to kill any pending RPC tasks, so that subsequent
-+ * code can actually succeed and won't leave tasks that need handling.
-+ *
-+ * PS. I wonder if this is somehow useful to undo damage that was
-+ * left in the kernel after a user level file server (such as amd)
-+ * dies.
-+ */
-+STATIC void
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
-+mini_fo_umount_begin(struct vfsmount *mnt, int flags)
-+{
-+ struct vfsmount *hidden_mnt;
-+
-+ hidden_mnt = stopd(mnt->mnt_sb)->hidden_mnt;
-+
-+ if (hidden_mnt->mnt_sb->s_op->umount_begin)
-+ hidden_mnt->mnt_sb->s_op->umount_begin(hidden_mnt, flags);
-+
-+}
-+#else
-+mini_fo_umount_begin(super_block_t *sb)
-+{
-+ super_block_t *hidden_sb;
-+
-+ hidden_sb = stohs(sb);
-+
-+ if (hidden_sb->s_op->umount_begin)
-+ hidden_sb->s_op->umount_begin(hidden_sb);
-+
-+}
-+#endif
-+
-+
-+struct super_operations mini_fo_sops =
-+{
-+ read_inode: mini_fo_read_inode,
-+#if defined(FIST_DEBUG) || defined(FIST_FILTER_SCA)
-+ write_inode: mini_fo_write_inode,
-+#endif /* defined(FIST_DEBUG) || defined(FIST_FILTER_SCA) */
-+ put_inode: mini_fo_put_inode,
-+#if defined(FIST_DEBUG) || defined(FIST_FILTER_SCA)
-+ delete_inode: mini_fo_delete_inode,
-+#endif /* defined(FIST_DEBUG) || defined(FIST_FILTER_SCA) */
-+ put_super: mini_fo_put_super,
-+ statfs: mini_fo_statfs,
-+ remount_fs: mini_fo_remount_fs,
-+ clear_inode: mini_fo_clear_inode,
-+ umount_begin: mini_fo_umount_begin,
-+};
+++ /dev/null
-Index: linux-2.6.21.7/include/linux/netdevice.h
-===================================================================
---- linux-2.6.21.7.orig/include/linux/netdevice.h
-+++ linux-2.6.21.7/include/linux/netdevice.h
-@@ -532,6 +532,8 @@ struct net_device
- struct device dev;
- /* space for optional statistics and wireless sysfs groups */
- struct attribute_group *sysfs_groups[3];
-+
-+ void *ieee80211_ptr;
- };
- #define to_net_dev(d) container_of(d, struct net_device, dev)
-
+++ /dev/null
-Index: linux-2.6.21.7/drivers/mtd/devices/block2mtd.c
-===================================================================
---- linux-2.6.21.7.orig/drivers/mtd/devices/block2mtd.c
-+++ linux-2.6.21.7/drivers/mtd/devices/block2mtd.c
-@@ -41,7 +41,7 @@ struct block2mtd_dev {
- static LIST_HEAD(blkmtd_device_list);
-
-
--#define PAGE_READAHEAD 64
-+#define PAGE_READAHEAD 0
- static void cache_readahead(struct address_space *mapping, int index)
- {
- filler_t *filler = (filler_t*)mapping->a_ops->readpage;
+++ /dev/null
-Index: linux-2.6.21.7/drivers/mtd/devices/block2mtd.c
-===================================================================
---- linux-2.6.21.7.orig/drivers/mtd/devices/block2mtd.c
-+++ linux-2.6.21.7/drivers/mtd/devices/block2mtd.c
-@@ -112,7 +112,7 @@ static int _block2mtd_erase(struct block
- if (IS_ERR(page))
- return PTR_ERR(page);
-
-- max = (u_long*)page_address(page) + PAGE_SIZE;
-+ max = (u_long*) ((u8 *) page_address(page) + PAGE_SIZE);
- for (p=(u_long*)page_address(page); p<max; p++)
- if (*p != -1UL) {
- lock_page(page);
+++ /dev/null
-Index: linux-2.6.21.7/lib/kobject_uevent.c
-===================================================================
---- linux-2.6.21.7.orig/lib/kobject_uevent.c
-+++ linux-2.6.21.7/lib/kobject_uevent.c
-@@ -30,9 +30,22 @@ u64 uevent_seqnum;
- char uevent_helper[UEVENT_HELPER_PATH_LEN] = "/sbin/hotplug";
- static DEFINE_SPINLOCK(sequence_lock);
- #if defined(CONFIG_NET)
--static struct sock *uevent_sock;
-+struct sock *uevent_sock = NULL;
-+EXPORT_SYMBOL_GPL(uevent_sock);
- #endif
-
-+u64 uevent_next_seqnum(void)
-+{
-+ u64 seq;
-+
-+ spin_lock(&sequence_lock);
-+ seq = ++uevent_seqnum;
-+ spin_unlock(&sequence_lock);
-+
-+ return seq;
-+}
-+EXPORT_SYMBOL_GPL(uevent_next_seqnum);
-+
- static char *action_to_string(enum kobject_action action)
- {
- switch (action) {
-@@ -171,9 +184,7 @@ int kobject_uevent_env(struct kobject *k
- }
-
- /* we will send an event, request a new sequence number */
-- spin_lock(&sequence_lock);
-- seq = ++uevent_seqnum;
-- spin_unlock(&sequence_lock);
-+ seq = uevent_next_seqnum();
- sprintf(seq_buff, "SEQNUM=%llu", (unsigned long long)seq);
-
- #if defined(CONFIG_NET)
+++ /dev/null
---- a/drivers/char/Kconfig
-+++ b/drivers/char/Kconfig
-@@ -984,6 +984,13 @@
-
- If compiled as a module, it will be called cs5535_gpio.
-
-+config GPIO_DEVICE
-+ tristate "GPIO device support"
-+ depends on GENERIC_GPIO
-+ help
-+ Say Y to enable Linux GPIO device support. This allows control of
-+ GPIO pins using a character device
-+
- config GPIO_VR41XX
- tristate "NEC VR4100 series General-purpose I/O Unit support"
- depends on CPU_VR41XX
---- a/drivers/char/Makefile
-+++ b/drivers/char/Makefile
-@@ -90,6 +90,7 @@
- obj-$(CONFIG_PC8736x_GPIO) += pc8736x_gpio.o
- obj-$(CONFIG_NSC_GPIO) += nsc_gpio.o
- obj-$(CONFIG_CS5535_GPIO) += cs5535_gpio.o
-+obj-$(CONFIG_GPIO_DEVICE) += gpio_dev.o
- obj-$(CONFIG_GPIO_VR41XX) += vr41xx_giu.o
- obj-$(CONFIG_TANBAC_TB0219) += tb0219.o
- obj-$(CONFIG_TELCLOCK) += tlclk.o
+++ /dev/null
-Index: linux-2.6.21.7/fs/Kconfig
-===================================================================
---- linux-2.6.21.7.orig/fs/Kconfig
-+++ linux-2.6.21.7/fs/Kconfig
-@@ -419,6 +419,7 @@ config FS_POSIX_ACL
-
- source "fs/xfs/Kconfig"
- source "fs/gfs2/Kconfig"
-+source "fs/yaffs2/Kconfig"
-
- config OCFS2_FS
- tristate "OCFS2 file system support"
-Index: linux-2.6.21.7/fs/Makefile
-===================================================================
---- linux-2.6.21.7.orig/fs/Makefile
-+++ linux-2.6.21.7/fs/Makefile
-@@ -116,3 +116,4 @@ obj-$(CONFIG_HPPFS) += hppfs/
- obj-$(CONFIG_DEBUG_FS) += debugfs/
- obj-$(CONFIG_OCFS2_FS) += ocfs2/
- obj-$(CONFIG_GFS2_FS) += gfs2/
-+obj-$(CONFIG_YAFFS_FS) += yaffs2/
+++ /dev/null
---- a/fs/yaffs2/yaffs_fs.c
-+++ b/fs/yaffs2/yaffs_fs.c
-@@ -969,7 +970,7 @@
- f->f_version = inode->i_version;
- }
-
-- list_for_each(i, &obj->variant.directoryVariant.children) {
-+ list_for_each(i, (struct list_head *)&obj->variant.directoryVariant.children) {
- curoffs++;
- if (curoffs >= offset) {
- l = list_entry(i, yaffs_Object, siblings);
-@@ -1273,7 +1275,7 @@
-
- if (target &&
- target->variantType == YAFFS_OBJECT_TYPE_DIRECTORY &&
-- !list_empty(&target->variant.directoryVariant.children)) {
-+ !list_empty((struct list_head *)&target->variant.directoryVariant.children)) {
-
- T(YAFFS_TRACE_OS, (KERN_DEBUG "target is non-empty dir\n"));
-
-@@ -1529,7 +1531,7 @@
- yaffs_GrossUnlock(dev);
-
- /* we assume this is protected by lock_kernel() in mount/umount */
-- list_del(&dev->devList);
-+ list_del((struct list_head *)&dev->devList);
-
- if(dev->spareBuffer){
- YFREE(dev->spareBuffer);
-@@ -1864,7 +1866,7 @@
- dev->skipCheckpointWrite = options.skip_checkpoint_write;
-
- /* we assume this is protected by lock_kernel() in mount/umount */
-- list_add_tail(&dev->devList, &yaffs_dev_list);
-+ list_add_tail((struct list_head *)&dev->devList, &yaffs_dev_list);
-
- init_MUTEX(&dev->grossLock);
-
---- a/fs/yaffs2/yaffs_mtdif1.c
-+++ b/fs/yaffs2/yaffs_mtdif1.c
-@@ -323,7 +323,7 @@
- * Always returns YAFFS_OK.
- */
- int nandmtd1_QueryNANDBlock(struct yaffs_DeviceStruct *dev, int blockNo,
-- yaffs_BlockState * pState, int *pSequenceNumber)
-+ yaffs_BlockState * pState, __u32 *pSequenceNumber)
- {
- struct mtd_info * mtd = dev->genericDevice;
- int chunkNo = blockNo * dev->nChunksPerBlock;
---- a/fs/yaffs2/yaffs_mtdif1.h
-+++ b/fs/yaffs2/yaffs_mtdif1.h
-@@ -23,6 +23,6 @@
- int nandmtd1_MarkNANDBlockBad(struct yaffs_DeviceStruct *dev, int blockNo);
-
- int nandmtd1_QueryNANDBlock(struct yaffs_DeviceStruct *dev, int blockNo,
-- yaffs_BlockState * state, int *sequenceNumber);
-+ yaffs_BlockState * state, __u32 *sequenceNumber);
-
- #endif
---- a/fs/yaffs2/yaffs_mtdif2.c
-+++ b/fs/yaffs2/yaffs_mtdif2.c
-@@ -204,7 +204,7 @@
- }
-
- int nandmtd2_QueryNANDBlock(struct yaffs_DeviceStruct *dev, int blockNo,
-- yaffs_BlockState * state, int *sequenceNumber)
-+ yaffs_BlockState * state, __u32 *sequenceNumber)
- {
- struct mtd_info *mtd = (struct mtd_info *)(dev->genericDevice);
- int retval;
---- a/fs/yaffs2/yaffs_mtdif2.h
-+++ b/fs/yaffs2/yaffs_mtdif2.h
-@@ -24,6 +24,6 @@
- __u8 * data, yaffs_ExtendedTags * tags);
- int nandmtd2_MarkNANDBlockBad(struct yaffs_DeviceStruct *dev, int blockNo);
- int nandmtd2_QueryNANDBlock(struct yaffs_DeviceStruct *dev, int blockNo,
-- yaffs_BlockState * state, int *sequenceNumber);
-+ yaffs_BlockState * state, __u32 *sequenceNumber);
-
- #endif
+++ /dev/null
-Index: linux-2.6.21.7/include/linux/time.h
-===================================================================
---- linux-2.6.21.7.orig/include/linux/time.h
-+++ linux-2.6.21.7/include/linux/time.h
-@@ -1,6 +1,10 @@
- #ifndef _LINUX_TIME_H
- #define _LINUX_TIME_H
-
-+#ifndef __KERNEL__
-+#include <time.h>
-+#else
-+
- #include <linux/types.h>
-
- #ifdef __KERNEL__
-@@ -224,4 +228,6 @@ struct itimerval {
- */
- #define TIMER_ABSTIME 0x01
-
-+#endif /* __KERNEL__ DEBIAN */
-+
- #endif
-Index: linux-2.6.21.7/include/linux/types.h
-===================================================================
---- linux-2.6.21.7.orig/include/linux/types.h
-+++ linux-2.6.21.7/include/linux/types.h
-@@ -1,6 +1,14 @@
- #ifndef _LINUX_TYPES_H
- #define _LINUX_TYPES_H
-
-+/* Debian: Use userland types instead. */
-+#ifndef __KERNEL__
-+# include <sys/types.h>
-+/* For other kernel headers. */
-+# include <linux/posix_types.h>
-+# include <asm/types.h>
-+#else
-+
- #ifdef __KERNEL__
-
- #define BITS_TO_LONGS(bits) \
-@@ -162,6 +170,8 @@ typedef unsigned long blkcnt_t;
-
- #endif /* __KERNEL_STRICT_NAMES */
-
-+#endif /* __KERNEL__ DEBIAN */
-+
- /*
- * Below are truly Linux-specific types that should never collide with
- * any application/library that wants linux/types.h.
+++ /dev/null
-Index: linux-2.6.21.7/scripts/genksyms/parse.c_shipped
-===================================================================
---- linux-2.6.21.7.orig/scripts/genksyms/parse.c_shipped
-+++ linux-2.6.21.7/scripts/genksyms/parse.c_shipped
-@@ -144,7 +144,9 @@
-
-
- #include <assert.h>
-+#ifndef __APPLE__
- #include <malloc.h>
-+#endif
- #include "genksyms.h"
-
- static int is_typedef;
-Index: linux-2.6.21.7/scripts/genksyms/parse.y
-===================================================================
---- linux-2.6.21.7.orig/scripts/genksyms/parse.y
-+++ linux-2.6.21.7/scripts/genksyms/parse.y
-@@ -24,7 +24,9 @@
- %{
-
- #include <assert.h>
-+#ifndef __APPLE__
- #include <malloc.h>
-+#endif
- #include "genksyms.h"
-
- static int is_typedef;
-Index: linux-2.6.21.7/scripts/kallsyms.c
-===================================================================
---- linux-2.6.21.7.orig/scripts/kallsyms.c
-+++ linux-2.6.21.7/scripts/kallsyms.c
-@@ -30,6 +30,35 @@
- #include <stdlib.h>
- #include <string.h>
- #include <ctype.h>
-+#ifdef __APPLE__
-+/* Darwin has no memmem implementation, this one is ripped of the uClibc-0.9.28 source */
-+void *memmem (const void *haystack, size_t haystack_len,
-+ const void *needle, size_t needle_len)
-+{
-+ const char *begin;
-+ const char *const last_possible
-+ = (const char *) haystack + haystack_len - needle_len;
-+
-+ if (needle_len == 0)
-+ /* The first occurrence of the empty string is deemed to occur at
-+ the beginning of the string. */
-+ return (void *) haystack;
-+
-+ /* Sanity check, otherwise the loop might search through the whole
-+ memory. */
-+ if (__builtin_expect (haystack_len < needle_len, 0))
-+ return NULL;
-+
-+ for (begin = (const char *) haystack; begin <= last_possible; ++begin)
-+ if (begin[0] == ((const char *) needle)[0] &&
-+ !memcmp ((const void *) &begin[1],
-+ (const void *) ((const char *) needle + 1),
-+ needle_len - 1))
-+ return (void *) begin;
-+
-+ return NULL;
-+}
-+#endif
-
- #define KSYM_NAME_LEN 127
-
-Index: linux-2.6.21.7/scripts/kconfig/Makefile
-===================================================================
---- linux-2.6.21.7.orig/scripts/kconfig/Makefile
-+++ linux-2.6.21.7/scripts/kconfig/Makefile
-@@ -87,6 +87,9 @@ check-lxdialog := $(srctree)/$(src)/lxd
- # we really need to do so. (Do not call gcc as part of make mrproper)
- HOST_EXTRACFLAGS = $(shell $(CONFIG_SHELL) $(check-lxdialog) -ccflags)
- HOST_LOADLIBES = $(shell $(CONFIG_SHELL) $(check-lxdialog) -ldflags $(HOSTCC))
-+ifeq ($(shell uname -s),Darwin)
-+HOST_LOADLIBES += -lncurses
-+endif
-
- HOST_EXTRACFLAGS += -DLOCALE
-
-Index: linux-2.6.21.7/scripts/mod/file2alias.c
-===================================================================
---- linux-2.6.21.7.orig/scripts/mod/file2alias.c
-+++ linux-2.6.21.7/scripts/mod/file2alias.c
-@@ -37,7 +37,21 @@ typedef unsigned char __u8;
- * even potentially has different endianness and word sizes, since
- * we handle those differences explicitly below */
- #include "../../include/linux/mod_devicetable.h"
-+#ifndef __APPLE__
- #include "../../include/linux/input.h"
-+#else
-+#define EV_MAX 0x1f
-+#define KEY_MUTE 113
-+#define KEY_MIN_INTERESTING KEY_MUTE
-+#define KEY_MAX 0x1ff
-+#define REL_MAX 0x0f
-+#define ABS_MAX 0x3f
-+#define MSC_MAX 0x07
-+#define LED_MAX 0x0f
-+#define SND_MAX 0x07
-+#define FF_MAX 0x7f
-+#define SW_MAX 0x0f
-+#endif
-
- #define ADD(str, sep, cond, field) \
- do { \
-Index: linux-2.6.21.7/scripts/mod/mk_elfconfig.c
-===================================================================
---- linux-2.6.21.7.orig/scripts/mod/mk_elfconfig.c
-+++ linux-2.6.21.7/scripts/mod/mk_elfconfig.c
-@@ -1,7 +1,11 @@
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
-+#ifndef __APPLE__
- #include <elf.h>
-+#else
-+#include "../../../../../tools/sstrip/include/elf.h"
-+#endif
-
- int
- main(int argc, char **argv)
-Index: linux-2.6.21.7/scripts/mod/modpost.h
-===================================================================
---- linux-2.6.21.7.orig/scripts/mod/modpost.h
-+++ linux-2.6.21.7/scripts/mod/modpost.h
-@@ -7,7 +7,11 @@
- #include <sys/mman.h>
- #include <fcntl.h>
- #include <unistd.h>
-+#ifndef __APPLE__
- #include <elf.h>
-+#else
-+#include "../../../../../tools/sstrip/include/elf.h"
-+#endif
-
- #include "elfconfig.h"
-
-Index: linux-2.6.21.7/scripts/mod/sumversion.c
-===================================================================
---- linux-2.6.21.7.orig/scripts/mod/sumversion.c
-+++ linux-2.6.21.7/scripts/mod/sumversion.c
-@@ -8,6 +8,9 @@
- #include <errno.h>
- #include <string.h>
- #include "modpost.h"
-+#ifdef __APPLE__
-+#include <limits.h>
-+#endif
-
- /*
- * Stolen form Cryptographic API.
+++ /dev/null
-Index: linux-2.6.21.7/drivers/net/wireless/hostap/hostap_ap.c
-===================================================================
---- linux-2.6.21.7.orig/drivers/net/wireless/hostap/hostap_ap.c
-+++ linux-2.6.21.7/drivers/net/wireless/hostap/hostap_ap.c
-@@ -2346,13 +2346,13 @@ int prism2_ap_get_sta_qual(local_info_t
- addr[count].sa_family = ARPHRD_ETHER;
- memcpy(addr[count].sa_data, sta->addr, ETH_ALEN);
- if (sta->last_rx_silence == 0)
-- qual[count].qual = sta->last_rx_signal < 27 ?
-- 0 : (sta->last_rx_signal - 27) * 92 / 127;
-+ qual[count].qual = (sta->last_rx_signal - 156) == 0 ?
-+ 0 : (sta->last_rx_signal - 156) * 92 / 64;
- else
-- qual[count].qual = sta->last_rx_signal -
-- sta->last_rx_silence - 35;
-- qual[count].level = HFA384X_LEVEL_TO_dBm(sta->last_rx_signal);
-- qual[count].noise = HFA384X_LEVEL_TO_dBm(sta->last_rx_silence);
-+ qual[count].qual = (sta->last_rx_signal -
-+ sta->last_rx_silence) * 92 / 64;
-+ qual[count].level = sta->last_rx_signal;
-+ qual[count].noise = sta->last_rx_silence;
- qual[count].updated = sta->last_rx_updated;
-
- sta->last_rx_updated = IW_QUAL_DBM;
-@@ -2417,13 +2417,13 @@ int prism2_ap_translate_scan(struct net_
- memset(&iwe, 0, sizeof(iwe));
- iwe.cmd = IWEVQUAL;
- if (sta->last_rx_silence == 0)
-- iwe.u.qual.qual = sta->last_rx_signal < 27 ?
-- 0 : (sta->last_rx_signal - 27) * 92 / 127;
-+ iwe.u.qual.qual = (sta->last_rx_signal -156) == 0 ?
-+ 0 : (sta->last_rx_signal - 156) * 92 / 64;
- else
-- iwe.u.qual.qual = sta->last_rx_signal -
-- sta->last_rx_silence - 35;
-- iwe.u.qual.level = HFA384X_LEVEL_TO_dBm(sta->last_rx_signal);
-- iwe.u.qual.noise = HFA384X_LEVEL_TO_dBm(sta->last_rx_silence);
-+ iwe.u.qual.qual = (sta->last_rx_signal -
-+ sta->last_rx_silence) * 92 / 64;
-+ iwe.u.qual.level = sta->last_rx_signal;
-+ iwe.u.qual.noise = sta->last_rx_silence;
- iwe.u.qual.updated = sta->last_rx_updated;
- iwe.len = IW_EV_QUAL_LEN;
- current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
-Index: linux-2.6.21.7/drivers/net/wireless/hostap/hostap_config.h
-===================================================================
---- linux-2.6.21.7.orig/drivers/net/wireless/hostap/hostap_config.h
-+++ linux-2.6.21.7/drivers/net/wireless/hostap/hostap_config.h
-@@ -47,4 +47,9 @@
- */
- /* #define PRISM2_NO_STATION_MODES */
-
-+/* Enable TX power Setting functions
-+ * (min att = -128 , max att = 127)
-+ */
-+#define RAW_TXPOWER_SETTING
-+
- #endif /* HOSTAP_CONFIG_H */
-Index: linux-2.6.21.7/drivers/net/wireless/hostap/hostap.h
-===================================================================
---- linux-2.6.21.7.orig/drivers/net/wireless/hostap/hostap.h
-+++ linux-2.6.21.7/drivers/net/wireless/hostap/hostap.h
-@@ -90,6 +90,7 @@ extern const struct iw_handler_def hosta
- extern const struct ethtool_ops prism2_ethtool_ops;
-
- int hostap_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd);
-+int hostap_restore_power(struct net_device *dev);
-
-
- #endif /* HOSTAP_H */
-Index: linux-2.6.21.7/drivers/net/wireless/hostap/hostap_hw.c
-===================================================================
---- linux-2.6.21.7.orig/drivers/net/wireless/hostap/hostap_hw.c
-+++ linux-2.6.21.7/drivers/net/wireless/hostap/hostap_hw.c
-@@ -933,6 +933,7 @@ static int hfa384x_set_rid(struct net_de
- prism2_hw_reset(dev);
- }
-
-+ hostap_restore_power(dev);
- return res;
- }
-
-Index: linux-2.6.21.7/drivers/net/wireless/hostap/hostap_info.c
-===================================================================
---- linux-2.6.21.7.orig/drivers/net/wireless/hostap/hostap_info.c
-+++ linux-2.6.21.7/drivers/net/wireless/hostap/hostap_info.c
-@@ -428,6 +428,11 @@ static void handle_info_queue_linkstatus
- }
-
- /* Get BSSID if we have a valid AP address */
-+
-+ if ( val == HFA384X_LINKSTATUS_CONNECTED ||
-+ val == HFA384X_LINKSTATUS_DISCONNECTED )
-+ hostap_restore_power(local->dev);
-+
- if (connected) {
- netif_carrier_on(local->dev);
- netif_carrier_on(local->ddev);
-Index: linux-2.6.21.7/drivers/net/wireless/hostap/hostap_ioctl.c
-===================================================================
---- linux-2.6.21.7.orig/drivers/net/wireless/hostap/hostap_ioctl.c
-+++ linux-2.6.21.7/drivers/net/wireless/hostap/hostap_ioctl.c
-@@ -1504,23 +1504,20 @@ static int prism2_txpower_hfa386x_to_dBm
- val = 255;
-
- tmp = val;
-- tmp >>= 2;
-
-- return -12 - tmp;
-+ return tmp;
- }
-
- static u16 prism2_txpower_dBm_to_hfa386x(int val)
- {
- signed char tmp;
-
-- if (val > 20)
-- return 128;
-- else if (val < -43)
-+ if (val > 127)
- return 127;
-+ else if (val < -128)
-+ return 128;
-
- tmp = val;
-- tmp = -12 - tmp;
-- tmp <<= 2;
-
- return (unsigned char) tmp;
- }
-@@ -4080,3 +4077,35 @@ int hostap_ioctl(struct net_device *dev,
-
- return ret;
- }
-+
-+/* BUG FIX: Restore power setting value when lost due to F/W bug */
-+
-+int hostap_restore_power(struct net_device *dev)
-+{
-+ struct hostap_interface *iface = dev->priv;
-+ local_info_t *local = iface->local;
-+
-+ u16 val;
-+ int ret = 0;
-+
-+ if (local->txpower_type == PRISM2_TXPOWER_OFF) {
-+ val = 0xff; /* use all standby and sleep modes */
-+ ret = local->func->cmd(dev, HFA384X_CMDCODE_WRITEMIF,
-+ HFA386X_CR_A_D_TEST_MODES2,
-+ &val, NULL);
-+ }
-+
-+#ifdef RAW_TXPOWER_SETTING
-+ if (local->txpower_type == PRISM2_TXPOWER_FIXED) {
-+ val = HFA384X_TEST_CFG_BIT_ALC;
-+ local->func->cmd(dev, HFA384X_CMDCODE_TEST |
-+ (HFA384X_TEST_CFG_BITS << 8), 0, &val, NULL);
-+ val = prism2_txpower_dBm_to_hfa386x(local->txpower);
-+ ret = (local->func->cmd(dev, HFA384X_CMDCODE_WRITEMIF,
-+ HFA386X_CR_MANUAL_TX_POWER, &val, NULL));
-+ }
-+#endif /* RAW_TXPOWER_SETTING */
-+ return (ret ? -EOPNOTSUPP : 0);
-+}
-+
-+EXPORT_SYMBOL(hostap_restore_power);
+++ /dev/null
-Index: linux-2.6.21.7/include/linux/stddef.h
-===================================================================
---- linux-2.6.21.7.orig/include/linux/stddef.h
-+++ linux-2.6.21.7/include/linux/stddef.h
-@@ -16,6 +16,7 @@ enum {
- false = 0,
- true = 1
- };
-+#endif /* __KERNEL__ */
-
- #undef offsetof
- #ifdef __compiler_offsetof
-@@ -23,6 +24,5 @@ enum {
- #else
- #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
- #endif
--#endif /* __KERNEL__ */
-
- #endif
+++ /dev/null
-Index: linux-2.6.21.7/scripts/gen_initramfs_list.sh
-===================================================================
---- linux-2.6.21.7.orig/scripts/gen_initramfs_list.sh
-+++ linux-2.6.21.7/scripts/gen_initramfs_list.sh
-@@ -125,7 +125,7 @@ parse() {
- str="${ftype} ${name} ${location} ${str}"
- ;;
- "nod")
-- local dev=`LC_ALL=C ls -l "${location}"`
-+ local dev=`LC_ALL=C ls -l --time-style=locale "${location}"`
- local maj=`field 5 ${dev}`
- local min=`field 6 ${dev}`
- maj=${maj%,}
-@@ -135,7 +135,7 @@ parse() {
- str="${ftype} ${name} ${str} ${dev} ${maj} ${min}"
- ;;
- "slink")
-- local target=`field 11 $(LC_ALL=C ls -l "${location}")`
-+ local target=`field 11 $(LC_ALL=C ls -l --time-style=locale "${location}")`
- str="${ftype} ${name} ${target} ${str}"
- ;;
- *)
+++ /dev/null
-Index: linux-2.6.21.7/include/linux/ip.h
-===================================================================
---- linux-2.6.21.7.orig/include/linux/ip.h
-+++ linux-2.6.21.7/include/linux/ip.h
-@@ -104,6 +104,16 @@ struct iphdr {
- /*The options start here. */
- };
-
-+#ifdef __KERNEL__
-+#include <linux/skbuff.h>
-+
-+static inline struct iphdr *ip_hdr(const struct sk_buff *skb)
-+{
-+ return (struct iphdr *)skb_network_header(skb);
-+}
-+
-+#endif
-+
- struct ip_auth_hdr {
- __u8 nexthdr;
- __u8 hdrlen; /* This one is measured in 32 bit units! */
-Index: linux-2.6.21.7/include/linux/skbuff.h
-===================================================================
---- linux-2.6.21.7.orig/include/linux/skbuff.h
-+++ linux-2.6.21.7/include/linux/skbuff.h
-@@ -966,6 +966,16 @@ static inline void skb_reserve(struct sk
- skb->tail += len;
- }
-
-+static inline unsigned char *skb_network_header(const struct sk_buff *skb)
-+{
-+ return skb->nh.raw;
-+}
-+
-+static inline unsigned char *skb_tail_pointer(const struct sk_buff *skb)
-+{
-+ return skb->tail;
-+}
-+
- /*
- * CPUs often take a performance hit when accessing unaligned memory
- * locations. The actual performance hit varies, it can be small if the
-Index: linux-2.6.21.7/include/net/ip.h
-===================================================================
---- linux-2.6.21.7.orig/include/net/ip.h
-+++ linux-2.6.21.7/include/net/ip.h
-@@ -43,6 +43,11 @@ struct inet_skb_parm
- #define IPSKB_REROUTED 16
- };
-
-+static inline unsigned int ip_hdrlen(const struct sk_buff *skb)
-+{
-+ return ip_hdr(skb)->ihl * 4;
-+}
-+
- struct ipcm_cookie
- {
- __be32 addr;
+++ /dev/null
---- a/fs/Kconfig
-+++ b/fs/Kconfig
-@@ -1364,6 +1364,71 @@
-
- If unsure, say N.
-
-+config SQUASHFS
-+ tristate "SquashFS 3.0 - Squashed file system support"
-+ select ZLIB_INFLATE
-+ help
-+ Saying Y here includes support for SquashFS 3.0 (a Compressed Read-Only File
-+ System). Squashfs is a highly compressed read-only filesystem for Linux.
-+ It uses zlib compression to compress both files, inodes and directories.
-+ Inodes in the system are very small and all blocks are packed to minimise
-+ data overhead. Block sizes greater than 4K are supported up to a maximum of 64K.
-+ SquashFS 3.0 supports 64 bit filesystems and files (larger than 4GB), full
-+ uid/gid information, hard links and timestamps.
-+
-+ Squashfs is intended for general read-only filesystem use, for archival
-+ use (i.e. in cases where a .tar.gz file may be used), and in embedded
-+ systems where low overhead is needed. Further information and filesystem tools
-+ are available from http://squashfs.sourceforge.net.
-+
-+ If you want to compile this as a module ( = code which can be
-+ inserted in and removed from the running kernel whenever you want),
-+ say M here and read <file:Documentation/modules.txt>. The module
-+ will be called squashfs. Note that the root file system (the one
-+ containing the directory /) cannot be compiled as a module.
-+
-+ If unsure, say N.
-+
-+config SQUASHFS_EMBEDDED
-+
-+ bool "Additional options for memory-constrained systems"
-+ depends on SQUASHFS
-+ default n
-+ help
-+ Saying Y here allows you to specify cache sizes and how Squashfs
-+ allocates memory. This is only intended for memory constrained
-+ systems.
-+
-+ If unsure, say N.
-+
-+config SQUASHFS_FRAGMENT_CACHE_SIZE
-+ int "Number of fragments cached" if SQUASHFS_EMBEDDED
-+ depends on SQUASHFS
-+ default "3"
-+ help
-+ By default SquashFS caches the last 3 fragments read from
-+ the filesystem. Increasing this amount may mean SquashFS
-+ has to re-read fragments less often from disk, at the expense
-+ of extra system memory. Decreasing this amount will mean
-+ SquashFS uses less memory at the expense of extra reads from disk.
-+
-+ Note there must be at least one cached fragment. Anything
-+ much more than three will probably not make much difference.
-+
-+config SQUASHFS_VMALLOC
-+ bool "Use Vmalloc rather than Kmalloc" if SQUASHFS_EMBEDDED
-+ depends on SQUASHFS
-+ default n
-+ help
-+ By default SquashFS uses kmalloc to obtain fragment cache memory.
-+ Kmalloc memory is the standard kernel allocator, but it can fail
-+ on memory constrained systems. Because of the way Vmalloc works,
-+ Vmalloc can succeed when kmalloc fails. Specifying this option
-+ will make SquashFS always use Vmalloc to allocate the
-+ fragment cache memory.
-+
-+ If unsure, say N.
-+
- config VXFS_FS
- tristate "FreeVxFS file system support (VERITAS VxFS(TM) compatible)"
- depends on BLOCK
---- a/fs/Makefile
-+++ b/fs/Makefile
-@@ -72,6 +72,7 @@
- obj-$(CONFIG_JBD2) += jbd2/
- obj-$(CONFIG_EXT2_FS) += ext2/
- obj-$(CONFIG_CRAMFS) += cramfs/
-+obj-$(CONFIG_SQUASHFS) += squashfs/
- obj-$(CONFIG_RAMFS) += ramfs/
- obj-$(CONFIG_HUGETLBFS) += hugetlbfs/
- obj-$(CONFIG_CODA_FS) += coda/
---- /dev/null
-+++ b/fs/squashfs/inode.c
-@@ -0,0 +1,2122 @@
-+/*
-+ * Squashfs - a compressed read only filesystem for Linux
-+ *
-+ * Copyright (c) 2002, 2003, 2004, 2005, 2006
-+ * Phillip Lougher <phillip@lougher.org.uk>
-+ *
-+ * 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,
-+ * 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-+ *
-+ * inode.c
-+ */
-+
-+#include <linux/types.h>
-+#include <linux/squashfs_fs.h>
-+#include <linux/module.h>
-+#include <linux/errno.h>
-+#include <linux/slab.h>
-+#include <linux/fs.h>
-+#include <linux/smp_lock.h>
-+#include <linux/slab.h>
-+#include <linux/squashfs_fs_sb.h>
-+#include <linux/squashfs_fs_i.h>
-+#include <linux/buffer_head.h>
-+#include <linux/vfs.h>
-+#include <linux/init.h>
-+#include <linux/dcache.h>
-+#include <linux/wait.h>
-+#include <linux/zlib.h>
-+#include <linux/blkdev.h>
-+#include <linux/vmalloc.h>
-+#include <asm/uaccess.h>
-+#include <asm/semaphore.h>
-+
-+#include "squashfs.h"
-+
-+static void squashfs_put_super(struct super_block *);
-+static int squashfs_statfs(struct dentry *, struct kstatfs *);
-+static int squashfs_symlink_readpage(struct file *file, struct page *page);
-+static int squashfs_readpage(struct file *file, struct page *page);
-+static int squashfs_readpage4K(struct file *file, struct page *page);
-+static int squashfs_readdir(struct file *, void *, filldir_t);
-+static struct inode *squashfs_alloc_inode(struct super_block *sb);
-+static void squashfs_destroy_inode(struct inode *inode);
-+static int init_inodecache(void);
-+static void destroy_inodecache(void);
-+static struct dentry *squashfs_lookup(struct inode *, struct dentry *,
-+ struct nameidata *);
-+static struct inode *squashfs_iget(struct super_block *s, squashfs_inode_t inode);
-+static long long read_blocklist(struct inode *inode, int index,
-+ int readahead_blks, char *block_list,
-+ unsigned short **block_p, unsigned int *bsize);
-+static int squashfs_get_sb(struct file_system_type *, int,
-+ const char *, void *, struct vfsmount *);
-+
-+
-+static z_stream stream;
-+
-+static struct file_system_type squashfs_fs_type = {
-+ .owner = THIS_MODULE,
-+ .name = "squashfs",
-+ .get_sb = squashfs_get_sb,
-+ .kill_sb = kill_block_super,
-+ .fs_flags = FS_REQUIRES_DEV
-+};
-+
-+static unsigned char squashfs_filetype_table[] = {
-+ DT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK
-+};
-+
-+static struct super_operations squashfs_ops = {
-+ .alloc_inode = squashfs_alloc_inode,
-+ .destroy_inode = squashfs_destroy_inode,
-+ .statfs = squashfs_statfs,
-+ .put_super = squashfs_put_super,
-+};
-+
-+SQSH_EXTERN struct address_space_operations squashfs_symlink_aops = {
-+ .readpage = squashfs_symlink_readpage
-+};
-+
-+SQSH_EXTERN struct address_space_operations squashfs_aops = {
-+ .readpage = squashfs_readpage
-+};
-+
-+SQSH_EXTERN struct address_space_operations squashfs_aops_4K = {
-+ .readpage = squashfs_readpage4K
-+};
-+
-+static struct file_operations squashfs_dir_ops = {
-+ .read = generic_read_dir,
-+ .readdir = squashfs_readdir
-+};
-+
-+SQSH_EXTERN struct inode_operations squashfs_dir_inode_ops = {
-+ .lookup = squashfs_lookup
-+};
-+
-+
-+static struct buffer_head *get_block_length(struct super_block *s,
-+ int *cur_index, int *offset, int *c_byte)
-+{
-+ struct squashfs_sb_info *msblk = s->s_fs_info;
-+ unsigned short temp;
-+ struct buffer_head *bh;
-+
-+ if (!(bh = sb_bread(s, *cur_index)))
-+ goto out;
-+
-+ if (msblk->devblksize - *offset == 1) {
-+ if (msblk->swap)
-+ ((unsigned char *) &temp)[1] = *((unsigned char *)
-+ (bh->b_data + *offset));
-+ else
-+ ((unsigned char *) &temp)[0] = *((unsigned char *)
-+ (bh->b_data + *offset));
-+ brelse(bh);
-+ if (!(bh = sb_bread(s, ++(*cur_index))))
-+ goto out;
-+ if (msblk->swap)
-+ ((unsigned char *) &temp)[0] = *((unsigned char *)
-+ bh->b_data);
-+ else
-+ ((unsigned char *) &temp)[1] = *((unsigned char *)
-+ bh->b_data);
-+ *c_byte = temp;
-+ *offset = 1;
-+ } else {
-+ if (msblk->swap) {
-+ ((unsigned char *) &temp)[1] = *((unsigned char *)
-+ (bh->b_data + *offset));
-+ ((unsigned char *) &temp)[0] = *((unsigned char *)
-+ (bh->b_data + *offset + 1));
-+ } else {
-+ ((unsigned char *) &temp)[0] = *((unsigned char *)
-+ (bh->b_data + *offset));
-+ ((unsigned char *) &temp)[1] = *((unsigned char *)
-+ (bh->b_data + *offset + 1));
-+ }
-+ *c_byte = temp;
-+ *offset += 2;
-+ }
-+
-+ if (SQUASHFS_CHECK_DATA(msblk->sblk.flags)) {
-+ if (*offset == msblk->devblksize) {
-+ brelse(bh);
-+ if (!(bh = sb_bread(s, ++(*cur_index))))
-+ goto out;
-+ *offset = 0;
-+ }
-+ if (*((unsigned char *) (bh->b_data + *offset)) !=
-+ SQUASHFS_MARKER_BYTE) {
-+ ERROR("Metadata block marker corrupt @ %x\n",
-+ *cur_index);
-+ brelse(bh);
-+ goto out;
-+ }
-+ (*offset)++;
-+ }
-+ return bh;
-+
-+out:
-+ return NULL;
-+}
-+
-+
-+SQSH_EXTERN unsigned int squashfs_read_data(struct super_block *s, char *buffer,
-+ long long index, unsigned int length,
-+ long long *next_index)
-+{
-+ struct squashfs_sb_info *msblk = s->s_fs_info;
-+ struct buffer_head *bh[((SQUASHFS_FILE_MAX_SIZE - 1) >>
-+ msblk->devblksize_log2) + 2];
-+ unsigned int offset = index & ((1 << msblk->devblksize_log2) - 1);
-+ unsigned int cur_index = index >> msblk->devblksize_log2;
-+ int bytes, avail_bytes, b = 0, k;
-+ char *c_buffer;
-+ unsigned int compressed;
-+ unsigned int c_byte = length;
-+
-+ if (c_byte) {
-+ bytes = msblk->devblksize - offset;
-+ compressed = SQUASHFS_COMPRESSED_BLOCK(c_byte);
-+ c_buffer = compressed ? msblk->read_data : buffer;
-+ c_byte = SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte);
-+
-+ TRACE("Block @ 0x%llx, %scompressed size %d\n", index, compressed
-+ ? "" : "un", (unsigned int) c_byte);
-+
-+ if (!(bh[0] = sb_getblk(s, cur_index)))
-+ goto block_release;
-+
-+ for (b = 1; bytes < c_byte; b++) {
-+ if (!(bh[b] = sb_getblk(s, ++cur_index)))
-+ goto block_release;
-+ bytes += msblk->devblksize;
-+ }
-+ ll_rw_block(READ, b, bh);
-+ } else {
-+ if (!(bh[0] = get_block_length(s, &cur_index, &offset,
-+ &c_byte)))
-+ goto read_failure;
-+
-+ bytes = msblk->devblksize - offset;
-+ compressed = SQUASHFS_COMPRESSED(c_byte);
-+ c_buffer = compressed ? msblk->read_data : buffer;
-+ c_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);
-+
-+ TRACE("Block @ 0x%llx, %scompressed size %d\n", index, compressed
-+ ? "" : "un", (unsigned int) c_byte);
-+
-+ for (b = 1; bytes < c_byte; b++) {
-+ if (!(bh[b] = sb_getblk(s, ++cur_index)))
-+ goto block_release;
-+ bytes += msblk->devblksize;
-+ }
-+ ll_rw_block(READ, b - 1, bh + 1);
-+ }
-+
-+ if (compressed)
-+ down(&msblk->read_data_mutex);
-+
-+ for (bytes = 0, k = 0; k < b; k++) {
-+ avail_bytes = (c_byte - bytes) > (msblk->devblksize - offset) ?
-+ msblk->devblksize - offset :
-+ c_byte - bytes;
-+ wait_on_buffer(bh[k]);
-+ if (!buffer_uptodate(bh[k]))
-+ goto block_release;
-+ memcpy(c_buffer + bytes, bh[k]->b_data + offset, avail_bytes);
-+ bytes += avail_bytes;
-+ offset = 0;
-+ brelse(bh[k]);
-+ }
-+
-+ /*
-+ * uncompress block
-+ */
-+ if (compressed) {
-+ int zlib_err;
-+
-+ stream.next_in = c_buffer;
-+ stream.avail_in = c_byte;
-+ stream.next_out = buffer;
-+ stream.avail_out = msblk->read_size;
-+
-+ if (((zlib_err = zlib_inflateInit(&stream)) != Z_OK) ||
-+ ((zlib_err = zlib_inflate(&stream, Z_FINISH))
-+ != Z_STREAM_END) || ((zlib_err =
-+ zlib_inflateEnd(&stream)) != Z_OK)) {
-+ ERROR("zlib_fs returned unexpected result 0x%x\n",
-+ zlib_err);
-+ bytes = 0;
-+ } else
-+ bytes = stream.total_out;
-+
-+ up(&msblk->read_data_mutex);
-+ }
-+
-+ if (next_index)
-+ *next_index = index + c_byte + (length ? 0 :
-+ (SQUASHFS_CHECK_DATA(msblk->sblk.flags)
-+ ? 3 : 2));
-+ return bytes;
-+
-+block_release:
-+ while (--b >= 0)
-+ brelse(bh[b]);
-+
-+read_failure:
-+ ERROR("sb_bread failed reading block 0x%x\n", cur_index);
-+ return 0;
-+}
-+
-+
-+SQSH_EXTERN int squashfs_get_cached_block(struct super_block *s, char *buffer,
-+ long long block, unsigned int offset,
-+ int length, long long *next_block,
-+ unsigned int *next_offset)
-+{
-+ struct squashfs_sb_info *msblk = s->s_fs_info;
-+ int n, i, bytes, return_length = length;
-+ long long next_index;
-+
-+ TRACE("Entered squashfs_get_cached_block [%llx:%x]\n", block, offset);
-+
-+ while ( 1 ) {
-+ for (i = 0; i < SQUASHFS_CACHED_BLKS; i++)
-+ if (msblk->block_cache[i].block == block)
-+ break;
-+
-+ down(&msblk->block_cache_mutex);
-+
-+ if (i == SQUASHFS_CACHED_BLKS) {
-+ /* read inode header block */
-+ for (i = msblk->next_cache, n = SQUASHFS_CACHED_BLKS;
-+ n ; n --, i = (i + 1) %
-+ SQUASHFS_CACHED_BLKS)
-+ if (msblk->block_cache[i].block !=
-+ SQUASHFS_USED_BLK)
-+ break;
-+
-+ if (n == 0) {
-+ wait_queue_t wait;
-+
-+ init_waitqueue_entry(&wait, current);
-+ add_wait_queue(&msblk->waitq, &wait);
-+ set_current_state(TASK_UNINTERRUPTIBLE);
-+ up(&msblk->block_cache_mutex);
-+ schedule();
-+ set_current_state(TASK_RUNNING);
-+ remove_wait_queue(&msblk->waitq, &wait);
-+ continue;
-+ }
-+ msblk->next_cache = (i + 1) % SQUASHFS_CACHED_BLKS;
-+
-+ if (msblk->block_cache[i].block ==
-+ SQUASHFS_INVALID_BLK) {
-+ if (!(msblk->block_cache[i].data =
-+ kmalloc(SQUASHFS_METADATA_SIZE,
-+ GFP_KERNEL))) {
-+ ERROR("Failed to allocate cache"
-+ "block\n");
-+ up(&msblk->block_cache_mutex);
-+ goto out;
-+ }
-+ }
-+
-+ msblk->block_cache[i].block = SQUASHFS_USED_BLK;
-+ up(&msblk->block_cache_mutex);
-+
-+ if (!(msblk->block_cache[i].length =
-+ squashfs_read_data(s,
-+ msblk->block_cache[i].data,
-+ block, 0, &next_index))) {
-+ ERROR("Unable to read cache block [%llx:%x]\n",
-+ block, offset);
-+ goto out;
-+ }
-+
-+ down(&msblk->block_cache_mutex);
-+ wake_up(&msblk->waitq);
-+ msblk->block_cache[i].block = block;
-+ msblk->block_cache[i].next_index = next_index;
-+ TRACE("Read cache block [%llx:%x]\n", block, offset);
-+ }
-+
-+ if (msblk->block_cache[i].block != block) {
-+ up(&msblk->block_cache_mutex);
-+ continue;
-+ }
-+
-+ if ((bytes = msblk->block_cache[i].length - offset) >= length) {
-+ if (buffer)
-+ memcpy(buffer, msblk->block_cache[i].data +
-+ offset, length);
-+ if (msblk->block_cache[i].length - offset == length) {
-+ *next_block = msblk->block_cache[i].next_index;
-+ *next_offset = 0;
-+ } else {
-+ *next_block = block;
-+ *next_offset = offset + length;
-+ }
-+ up(&msblk->block_cache_mutex);
-+ goto finish;
-+ } else {
-+ if (buffer) {
-+ memcpy(buffer, msblk->block_cache[i].data +
-+ offset, bytes);
-+ buffer += bytes;
-+ }
-+ block = msblk->block_cache[i].next_index;
-+ up(&msblk->block_cache_mutex);
-+ length -= bytes;
-+ offset = 0;
-+ }
-+ }
-+
-+finish:
-+ return return_length;
-+out:
-+ return 0;
-+}
-+
-+
-+static int get_fragment_location(struct super_block *s, unsigned int fragment,
-+ long long *fragment_start_block,
-+ unsigned int *fragment_size)
-+{
-+ struct squashfs_sb_info *msblk = s->s_fs_info;
-+ long long start_block =
-+ msblk->fragment_index[SQUASHFS_FRAGMENT_INDEX(fragment)];
-+ int offset = SQUASHFS_FRAGMENT_INDEX_OFFSET(fragment);
-+ struct squashfs_fragment_entry fragment_entry;
-+
-+ if (msblk->swap) {
-+ struct squashfs_fragment_entry sfragment_entry;
-+
-+ if (!squashfs_get_cached_block(s, (char *) &sfragment_entry,
-+ start_block, offset,
-+ sizeof(sfragment_entry), &start_block,
-+ &offset))
-+ goto out;
-+ SQUASHFS_SWAP_FRAGMENT_ENTRY(&fragment_entry, &sfragment_entry);
-+ } else
-+ if (!squashfs_get_cached_block(s, (char *) &fragment_entry,
-+ start_block, offset,
-+ sizeof(fragment_entry), &start_block,
-+ &offset))
-+ goto out;
-+
-+ *fragment_start_block = fragment_entry.start_block;
-+ *fragment_size = fragment_entry.size;
-+
-+ return 1;
-+
-+out:
-+ return 0;
-+}
-+
-+
-+SQSH_EXTERN void release_cached_fragment(struct squashfs_sb_info *msblk, struct
-+ squashfs_fragment_cache *fragment)
-+{
-+ down(&msblk->fragment_mutex);
-+ fragment->locked --;
-+ wake_up(&msblk->fragment_wait_queue);
-+ up(&msblk->fragment_mutex);
-+}
-+
-+
-+SQSH_EXTERN struct squashfs_fragment_cache *get_cached_fragment(struct super_block
-+ *s, long long start_block,
-+ int length)
-+{
-+ int i, n;
-+ struct squashfs_sb_info *msblk = s->s_fs_info;
-+
-+ while ( 1 ) {
-+ down(&msblk->fragment_mutex);
-+
-+ for (i = 0; i < SQUASHFS_CACHED_FRAGMENTS &&
-+ msblk->fragment[i].block != start_block; i++);
-+
-+ if (i == SQUASHFS_CACHED_FRAGMENTS) {
-+ for (i = msblk->next_fragment, n =
-+ SQUASHFS_CACHED_FRAGMENTS; n &&
-+ msblk->fragment[i].locked; n--, i = (i + 1) %
-+ SQUASHFS_CACHED_FRAGMENTS);
-+
-+ if (n == 0) {
-+ wait_queue_t wait;
-+
-+ init_waitqueue_entry(&wait, current);
-+ add_wait_queue(&msblk->fragment_wait_queue,
-+ &wait);
-+ set_current_state(TASK_UNINTERRUPTIBLE);
-+ up(&msblk->fragment_mutex);
-+ schedule();
-+ set_current_state(TASK_RUNNING);
-+ remove_wait_queue(&msblk->fragment_wait_queue,
-+ &wait);
-+ continue;
-+ }
-+ msblk->next_fragment = (msblk->next_fragment + 1) %
-+ SQUASHFS_CACHED_FRAGMENTS;
-+
-+ if (msblk->fragment[i].data == NULL)
-+ if (!(msblk->fragment[i].data = SQUASHFS_ALLOC
-+ (SQUASHFS_FILE_MAX_SIZE))) {
-+ ERROR("Failed to allocate fragment "
-+ "cache block\n");
-+ up(&msblk->fragment_mutex);
-+ goto out;
-+ }
-+
-+ msblk->fragment[i].block = SQUASHFS_INVALID_BLK;
-+ msblk->fragment[i].locked = 1;
-+ up(&msblk->fragment_mutex);
-+
-+ if (!(msblk->fragment[i].length = squashfs_read_data(s,
-+ msblk->fragment[i].data,
-+ start_block, length, NULL))) {
-+ ERROR("Unable to read fragment cache block "
-+ "[%llx]\n", start_block);
-+ msblk->fragment[i].locked = 0;
-+ goto out;
-+ }
-+
-+ msblk->fragment[i].block = start_block;
-+ TRACE("New fragment %d, start block %lld, locked %d\n",
-+ i, msblk->fragment[i].block,
-+ msblk->fragment[i].locked);
-+ break;
-+ }
-+
-+ msblk->fragment[i].locked++;
-+ up(&msblk->fragment_mutex);
-+ TRACE("Got fragment %d, start block %lld, locked %d\n", i,
-+ msblk->fragment[i].block,
-+ msblk->fragment[i].locked);
-+ break;
-+ }
-+
-+ return &msblk->fragment[i];
-+
-+out:
-+ return NULL;
-+}
-+
-+
-+static struct inode *squashfs_new_inode(struct super_block *s,
-+ struct squashfs_base_inode_header *inodeb)
-+{
-+ struct squashfs_sb_info *msblk = s->s_fs_info;
-+ struct inode *i = new_inode(s);
-+
-+ if (i) {
-+ i->i_ino = inodeb->inode_number;
-+ i->i_mtime.tv_sec = inodeb->mtime;
-+ i->i_atime.tv_sec = inodeb->mtime;
-+ i->i_ctime.tv_sec = inodeb->mtime;
-+ i->i_uid = msblk->uid[inodeb->uid];
-+ i->i_mode = inodeb->mode;
-+ i->i_size = 0;
-+ if (inodeb->guid == SQUASHFS_GUIDS)
-+ i->i_gid = i->i_uid;
-+ else
-+ i->i_gid = msblk->guid[inodeb->guid];
-+ }
-+
-+ return i;
-+}
-+
-+
-+static struct inode *squashfs_iget(struct super_block *s, squashfs_inode_t inode)
-+{
-+ struct inode *i;
-+ struct squashfs_sb_info *msblk = s->s_fs_info;
-+ struct squashfs_super_block *sblk = &msblk->sblk;
-+ long long block = SQUASHFS_INODE_BLK(inode) +
-+ sblk->inode_table_start;
-+ unsigned int offset = SQUASHFS_INODE_OFFSET(inode);
-+ long long next_block;
-+ unsigned int next_offset;
-+ union squashfs_inode_header id, sid;
-+ struct squashfs_base_inode_header *inodeb = &id.base,
-+ *sinodeb = &sid.base;
-+
-+ TRACE("Entered squashfs_iget\n");
-+
-+ if (msblk->swap) {
-+ if (!squashfs_get_cached_block(s, (char *) sinodeb, block,
-+ offset, sizeof(*sinodeb), &next_block,
-+ &next_offset))
-+ goto failed_read;
-+ SQUASHFS_SWAP_BASE_INODE_HEADER(inodeb, sinodeb,
-+ sizeof(*sinodeb));
-+ } else
-+ if (!squashfs_get_cached_block(s, (char *) inodeb, block,
-+ offset, sizeof(*inodeb), &next_block,
-+ &next_offset))
-+ goto failed_read;
-+
-+ switch(inodeb->inode_type) {
-+ case SQUASHFS_FILE_TYPE: {
-+ unsigned int frag_size;
-+ long long frag_blk;
-+ struct squashfs_reg_inode_header *inodep = &id.reg;
-+ struct squashfs_reg_inode_header *sinodep = &sid.reg;
-+
-+ if (msblk->swap) {
-+ if (!squashfs_get_cached_block(s, (char *)
-+ sinodep, block, offset,
-+ sizeof(*sinodep), &next_block,
-+ &next_offset))
-+ goto failed_read;
-+ SQUASHFS_SWAP_REG_INODE_HEADER(inodep, sinodep);
-+ } else
-+ if (!squashfs_get_cached_block(s, (char *)
-+ inodep, block, offset,
-+ sizeof(*inodep), &next_block,
-+ &next_offset))
-+ goto failed_read;
-+
-+ frag_blk = SQUASHFS_INVALID_BLK;
-+ if (inodep->fragment != SQUASHFS_INVALID_FRAG &&
-+ !get_fragment_location(s,
-+ inodep->fragment, &frag_blk, &frag_size))
-+ goto failed_read;
-+
-+ if((i = squashfs_new_inode(s, inodeb)) == NULL)
-+ goto failed_read1;
-+
-+ i->i_nlink = 1;
-+ i->i_size = inodep->file_size;
-+ i->i_fop = &generic_ro_fops;
-+ i->i_mode |= S_IFREG;
-+ i->i_blocks = ((i->i_size - 1) >> 9) + 1;
-+ SQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;
-+ SQUASHFS_I(i)->u.s1.fragment_size = frag_size;
-+ SQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;
-+ SQUASHFS_I(i)->start_block = inodep->start_block;
-+ SQUASHFS_I(i)->u.s1.block_list_start = next_block;
-+ SQUASHFS_I(i)->offset = next_offset;
-+ if (sblk->block_size > 4096)
-+ i->i_data.a_ops = &squashfs_aops;
-+ else
-+ i->i_data.a_ops = &squashfs_aops_4K;
-+
-+ TRACE("File inode %x:%x, start_block %llx, "
-+ "block_list_start %llx, offset %x\n",
-+ SQUASHFS_INODE_BLK(inode), offset,
-+ inodep->start_block, next_block,
-+ next_offset);
-+ break;
-+ }
-+ case SQUASHFS_LREG_TYPE: {
-+ unsigned int frag_size;
-+ long long frag_blk;
-+ struct squashfs_lreg_inode_header *inodep = &id.lreg;
-+ struct squashfs_lreg_inode_header *sinodep = &sid.lreg;
-+
-+ if (msblk->swap) {
-+ if (!squashfs_get_cached_block(s, (char *)
-+ sinodep, block, offset,
-+ sizeof(*sinodep), &next_block,
-+ &next_offset))
-+ goto failed_read;
-+ SQUASHFS_SWAP_LREG_INODE_HEADER(inodep, sinodep);
-+ } else
-+ if (!squashfs_get_cached_block(s, (char *)
-+ inodep, block, offset,
-+ sizeof(*inodep), &next_block,
-+ &next_offset))
-+ goto failed_read;
-+
-+ frag_blk = SQUASHFS_INVALID_BLK;
-+ if (inodep->fragment != SQUASHFS_INVALID_FRAG &&
-+ !get_fragment_location(s,
-+ inodep->fragment, &frag_blk, &frag_size))
-+ goto failed_read;
-+
-+ if((i = squashfs_new_inode(s, inodeb)) == NULL)
-+ goto failed_read1;
-+
-+ i->i_nlink = inodep->nlink;
-+ i->i_size = inodep->file_size;
-+ i->i_fop = &generic_ro_fops;
-+ i->i_mode |= S_IFREG;
-+ i->i_blocks = ((i->i_size - 1) >> 9) + 1;
-+ SQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;
-+ SQUASHFS_I(i)->u.s1.fragment_size = frag_size;
-+ SQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;
-+ SQUASHFS_I(i)->start_block = inodep->start_block;
-+ SQUASHFS_I(i)->u.s1.block_list_start = next_block;
-+ SQUASHFS_I(i)->offset = next_offset;
-+ if (sblk->block_size > 4096)
-+ i->i_data.a_ops = &squashfs_aops;
-+ else
-+ i->i_data.a_ops = &squashfs_aops_4K;
-+
-+ TRACE("File inode %x:%x, start_block %llx, "
-+ "block_list_start %llx, offset %x\n",
-+ SQUASHFS_INODE_BLK(inode), offset,
-+ inodep->start_block, next_block,
-+ next_offset);
-+ break;
-+ }
-+ case SQUASHFS_DIR_TYPE: {
-+ struct squashfs_dir_inode_header *inodep = &id.dir;
-+ struct squashfs_dir_inode_header *sinodep = &sid.dir;
-+
-+ if (msblk->swap) {
-+ if (!squashfs_get_cached_block(s, (char *)
-+ sinodep, block, offset,
-+ sizeof(*sinodep), &next_block,
-+ &next_offset))
-+ goto failed_read;
-+ SQUASHFS_SWAP_DIR_INODE_HEADER(inodep, sinodep);
-+ } else
-+ if (!squashfs_get_cached_block(s, (char *)
-+ inodep, block, offset,
-+ sizeof(*inodep), &next_block,
-+ &next_offset))
-+ goto failed_read;
-+
-+ if((i = squashfs_new_inode(s, inodeb)) == NULL)
-+ goto failed_read1;
-+
-+ i->i_nlink = inodep->nlink;
-+ i->i_size = inodep->file_size;
-+ i->i_op = &squashfs_dir_inode_ops;
-+ i->i_fop = &squashfs_dir_ops;
-+ i->i_mode |= S_IFDIR;
-+ SQUASHFS_I(i)->start_block = inodep->start_block;
-+ SQUASHFS_I(i)->offset = inodep->offset;
-+ SQUASHFS_I(i)->u.s2.directory_index_count = 0;
-+ SQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;
-+
-+ TRACE("Directory inode %x:%x, start_block %x, offset "
-+ "%x\n", SQUASHFS_INODE_BLK(inode),
-+ offset, inodep->start_block,
-+ inodep->offset);
-+ break;
-+ }
-+ case SQUASHFS_LDIR_TYPE: {
-+ struct squashfs_ldir_inode_header *inodep = &id.ldir;
-+ struct squashfs_ldir_inode_header *sinodep = &sid.ldir;
-+
-+ if (msblk->swap) {
-+ if (!squashfs_get_cached_block(s, (char *)
-+ sinodep, block, offset,
-+ sizeof(*sinodep), &next_block,
-+ &next_offset))
-+ goto failed_read;
-+ SQUASHFS_SWAP_LDIR_INODE_HEADER(inodep,
-+ sinodep);
-+ } else
-+ if (!squashfs_get_cached_block(s, (char *)
-+ inodep, block, offset,
-+ sizeof(*inodep), &next_block,
-+ &next_offset))
-+ goto failed_read;
-+
-+ if((i = squashfs_new_inode(s, inodeb)) == NULL)
-+ goto failed_read1;
-+
-+ i->i_nlink = inodep->nlink;
-+ i->i_size = inodep->file_size;
-+ i->i_op = &squashfs_dir_inode_ops;
-+ i->i_fop = &squashfs_dir_ops;
-+ i->i_mode |= S_IFDIR;
-+ SQUASHFS_I(i)->start_block = inodep->start_block;
-+ SQUASHFS_I(i)->offset = inodep->offset;
-+ SQUASHFS_I(i)->u.s2.directory_index_start = next_block;
-+ SQUASHFS_I(i)->u.s2.directory_index_offset =
-+ next_offset;
-+ SQUASHFS_I(i)->u.s2.directory_index_count =
-+ inodep->i_count;
-+ SQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;
-+
-+ TRACE("Long directory inode %x:%x, start_block %x, "
-+ "offset %x\n",
-+ SQUASHFS_INODE_BLK(inode), offset,
-+ inodep->start_block, inodep->offset);
-+ break;
-+ }
-+ case SQUASHFS_SYMLINK_TYPE: {
-+ struct squashfs_symlink_inode_header *inodep =
-+ &id.symlink;
-+ struct squashfs_symlink_inode_header *sinodep =
-+ &sid.symlink;
-+
-+ if (msblk->swap) {
-+ if (!squashfs_get_cached_block(s, (char *)
-+ sinodep, block, offset,
-+ sizeof(*sinodep), &next_block,
-+ &next_offset))
-+ goto failed_read;
-+ SQUASHFS_SWAP_SYMLINK_INODE_HEADER(inodep,
-+ sinodep);
-+ } else
-+ if (!squashfs_get_cached_block(s, (char *)
-+ inodep, block, offset,
-+ sizeof(*inodep), &next_block,
-+ &next_offset))
-+ goto failed_read;
-+
-+ if((i = squashfs_new_inode(s, inodeb)) == NULL)
-+ goto failed_read1;
-+
-+ i->i_nlink = inodep->nlink;
-+ i->i_size = inodep->symlink_size;
-+ i->i_op = &page_symlink_inode_operations;
-+ i->i_data.a_ops = &squashfs_symlink_aops;
-+ i->i_mode |= S_IFLNK;
-+ SQUASHFS_I(i)->start_block = next_block;
-+ SQUASHFS_I(i)->offset = next_offset;
-+
-+ TRACE("Symbolic link inode %x:%x, start_block %llx, "
-+ "offset %x\n",
-+ SQUASHFS_INODE_BLK(inode), offset,
-+ next_block, next_offset);
-+ break;
-+ }
-+ case SQUASHFS_BLKDEV_TYPE:
-+ case SQUASHFS_CHRDEV_TYPE: {
-+ struct squashfs_dev_inode_header *inodep = &id.dev;
-+ struct squashfs_dev_inode_header *sinodep = &sid.dev;
-+
-+ if (msblk->swap) {
-+ if (!squashfs_get_cached_block(s, (char *)
-+ sinodep, block, offset,
-+ sizeof(*sinodep), &next_block,
-+ &next_offset))
-+ goto failed_read;
-+ SQUASHFS_SWAP_DEV_INODE_HEADER(inodep, sinodep);
-+ } else
-+ if (!squashfs_get_cached_block(s, (char *)
-+ inodep, block, offset,
-+ sizeof(*inodep), &next_block,
-+ &next_offset))
-+ goto failed_read;
-+
-+ if ((i = squashfs_new_inode(s, inodeb)) == NULL)
-+ goto failed_read1;
-+
-+ i->i_nlink = inodep->nlink;
-+ i->i_mode |= (inodeb->inode_type ==
-+ SQUASHFS_CHRDEV_TYPE) ? S_IFCHR :
-+ S_IFBLK;
-+ init_special_inode(i, i->i_mode,
-+ old_decode_dev(inodep->rdev));
-+
-+ TRACE("Device inode %x:%x, rdev %x\n",
-+ SQUASHFS_INODE_BLK(inode), offset,
-+ inodep->rdev);
-+ break;
-+ }
-+ case SQUASHFS_FIFO_TYPE:
-+ case SQUASHFS_SOCKET_TYPE: {
-+ struct squashfs_ipc_inode_header *inodep = &id.ipc;
-+ struct squashfs_ipc_inode_header *sinodep = &sid.ipc;
-+
-+ if (msblk->swap) {
-+ if (!squashfs_get_cached_block(s, (char *)
-+ sinodep, block, offset,
-+ sizeof(*sinodep), &next_block,
-+ &next_offset))
-+ goto failed_read;
-+ SQUASHFS_SWAP_IPC_INODE_HEADER(inodep, sinodep);
-+ } else
-+ if (!squashfs_get_cached_block(s, (char *)
-+ inodep, block, offset,
-+ sizeof(*inodep), &next_block,
-+ &next_offset))
-+ goto failed_read;
-+
-+ if ((i = squashfs_new_inode(s, inodeb)) == NULL)
-+ goto failed_read1;
-+
-+ i->i_nlink = inodep->nlink;
-+ i->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)
-+ ? S_IFIFO : S_IFSOCK;
-+ init_special_inode(i, i->i_mode, 0);
-+ break;
-+ }
-+ default:
-+ ERROR("Unknown inode type %d in squashfs_iget!\n",
-+ inodeb->inode_type);
-+ goto failed_read1;
-+ }
-+
-+ insert_inode_hash(i);
-+ return i;
-+
-+failed_read:
-+ ERROR("Unable to read inode [%llx:%x]\n", block, offset);
-+
-+failed_read1:
-+ return NULL;
-+}
-+
-+
-+static int read_fragment_index_table(struct super_block *s)
-+{
-+ struct squashfs_sb_info *msblk = s->s_fs_info;
-+ struct squashfs_super_block *sblk = &msblk->sblk;
-+
-+ /* Allocate fragment index table */
-+ if (!(msblk->fragment_index = kmalloc(SQUASHFS_FRAGMENT_INDEX_BYTES
-+ (sblk->fragments), GFP_KERNEL))) {
-+ ERROR("Failed to allocate uid/gid table\n");
-+ return 0;
-+ }
-+
-+ if (SQUASHFS_FRAGMENT_INDEX_BYTES(sblk->fragments) &&
-+ !squashfs_read_data(s, (char *)
-+ msblk->fragment_index,
-+ sblk->fragment_table_start,
-+ SQUASHFS_FRAGMENT_INDEX_BYTES
-+ (sblk->fragments) |
-+ SQUASHFS_COMPRESSED_BIT_BLOCK, NULL)) {
-+ ERROR("unable to read fragment index table\n");
-+ return 0;
-+ }
-+
-+ if (msblk->swap) {
-+ int i;
-+ long long fragment;
-+
-+ for (i = 0; i < SQUASHFS_FRAGMENT_INDEXES(sblk->fragments);
-+ i++) {
-+ SQUASHFS_SWAP_FRAGMENT_INDEXES((&fragment),
-+ &msblk->fragment_index[i], 1);
-+ msblk->fragment_index[i] = fragment;
-+ }
-+ }
-+
-+ return 1;
-+}
-+
-+
-+static int supported_squashfs_filesystem(struct squashfs_sb_info *msblk, int silent)
-+{
-+ struct squashfs_super_block *sblk = &msblk->sblk;
-+
-+ msblk->iget = squashfs_iget;
-+ msblk->read_blocklist = read_blocklist;
-+ msblk->read_fragment_index_table = read_fragment_index_table;
-+
-+ if (sblk->s_major == 1) {
-+ if (!squashfs_1_0_supported(msblk)) {
-+ SERROR("Major/Minor mismatch, Squashfs 1.0 filesystems "
-+ "are unsupported\n");
-+ SERROR("Please recompile with "
-+ "Squashfs 1.0 support enabled\n");
-+ return 0;
-+ }
-+ } else if (sblk->s_major == 2) {
-+ if (!squashfs_2_0_supported(msblk)) {
-+ SERROR("Major/Minor mismatch, Squashfs 2.0 filesystems "
-+ "are unsupported\n");
-+ SERROR("Please recompile with "
-+ "Squashfs 2.0 support enabled\n");
-+ return 0;
-+ }
-+ } else if(sblk->s_major != SQUASHFS_MAJOR || sblk->s_minor >
-+ SQUASHFS_MINOR) {
-+ SERROR("Major/Minor mismatch, trying to mount newer %d.%d "
-+ "filesystem\n", sblk->s_major, sblk->s_minor);
-+ SERROR("Please update your kernel\n");
-+ return 0;
-+ }
-+
-+ return 1;
-+}
-+
-+
-+static int squashfs_fill_super(struct super_block *s, void *data, int silent)
-+{
-+ struct squashfs_sb_info *msblk;
-+ struct squashfs_super_block *sblk;
-+ int i;
-+ char b[BDEVNAME_SIZE];
-+ struct inode *root;
-+
-+ TRACE("Entered squashfs_read_superblock\n");
-+
-+ if (!(s->s_fs_info = kmalloc(sizeof(struct squashfs_sb_info),
-+ GFP_KERNEL))) {
-+ ERROR("Failed to allocate superblock\n");
-+ goto failure;
-+ }
-+ memset(s->s_fs_info, 0, sizeof(struct squashfs_sb_info));
-+ msblk = s->s_fs_info;
-+ sblk = &msblk->sblk;
-+
-+ msblk->devblksize = sb_min_blocksize(s, BLOCK_SIZE);
-+ msblk->devblksize_log2 = ffz(~msblk->devblksize);
-+
-+ init_MUTEX(&msblk->read_data_mutex);
-+ init_MUTEX(&msblk->read_page_mutex);
-+ init_MUTEX(&msblk->block_cache_mutex);
-+ init_MUTEX(&msblk->fragment_mutex);
-+ init_MUTEX(&msblk->meta_index_mutex);
-+
-+ init_waitqueue_head(&msblk->waitq);
-+ init_waitqueue_head(&msblk->fragment_wait_queue);
-+
-+ if (!squashfs_read_data(s, (char *) sblk, SQUASHFS_START,
-+ sizeof(struct squashfs_super_block) |
-+ SQUASHFS_COMPRESSED_BIT_BLOCK, NULL)) {
-+ SERROR("unable to read superblock\n");
-+ goto failed_mount;
-+ }
-+
-+ /* Check it is a SQUASHFS superblock */
-+ msblk->swap = 0;
-+ if ((s->s_magic = sblk->s_magic) != SQUASHFS_MAGIC) {
-+ if (sblk->s_magic == SQUASHFS_MAGIC_SWAP) {
-+ struct squashfs_super_block ssblk;
-+
-+ WARNING("Mounting a different endian SQUASHFS "
-+ "filesystem on %s\n", bdevname(s->s_bdev, b));
-+
-+ SQUASHFS_SWAP_SUPER_BLOCK(&ssblk, sblk);
-+ memcpy(sblk, &ssblk, sizeof(struct squashfs_super_block));
-+ msblk->swap = 1;
-+ } else {
-+ SERROR("Can't find a SQUASHFS superblock on %s\n",
-+ bdevname(s->s_bdev, b));
-+ goto failed_mount;
-+ }
-+ }
-+
-+ /* Check the MAJOR & MINOR versions */
-+ if(!supported_squashfs_filesystem(msblk, silent))
-+ goto failed_mount;
-+
-+ TRACE("Found valid superblock on %s\n", bdevname(s->s_bdev, b));
-+ TRACE("Inodes are %scompressed\n",
-+ SQUASHFS_UNCOMPRESSED_INODES
-+ (sblk->flags) ? "un" : "");
-+ TRACE("Data is %scompressed\n",
-+ SQUASHFS_UNCOMPRESSED_DATA(sblk->flags)
-+ ? "un" : "");
-+ TRACE("Check data is %s present in the filesystem\n",
-+ SQUASHFS_CHECK_DATA(sblk->flags) ?
-+ "" : "not");
-+ TRACE("Filesystem size %lld bytes\n", sblk->bytes_used);
-+ TRACE("Block size %d\n", sblk->block_size);
-+ TRACE("Number of inodes %d\n", sblk->inodes);
-+ if (sblk->s_major > 1)
-+ TRACE("Number of fragments %d\n", sblk->fragments);
-+ TRACE("Number of uids %d\n", sblk->no_uids);
-+ TRACE("Number of gids %d\n", sblk->no_guids);
-+ TRACE("sblk->inode_table_start %llx\n", sblk->inode_table_start);
-+ TRACE("sblk->directory_table_start %llx\n", sblk->directory_table_start);
-+ if (sblk->s_major > 1)
-+ TRACE("sblk->fragment_table_start %llx\n",
-+ sblk->fragment_table_start);
-+ TRACE("sblk->uid_start %llx\n", sblk->uid_start);
-+
-+ s->s_flags |= MS_RDONLY;
-+ s->s_op = &squashfs_ops;
-+
-+ /* Init inode_table block pointer array */
-+ if (!(msblk->block_cache = kmalloc(sizeof(struct squashfs_cache) *
-+ SQUASHFS_CACHED_BLKS, GFP_KERNEL))) {
-+ ERROR("Failed to allocate block cache\n");
-+ goto failed_mount;
-+ }
-+
-+ for (i = 0; i < SQUASHFS_CACHED_BLKS; i++)
-+ msblk->block_cache[i].block = SQUASHFS_INVALID_BLK;
-+
-+ msblk->next_cache = 0;
-+
-+ /* Allocate read_data block */
-+ msblk->read_size = (sblk->block_size < SQUASHFS_METADATA_SIZE) ?
-+ SQUASHFS_METADATA_SIZE :
-+ sblk->block_size;
-+
-+ if (!(msblk->read_data = kmalloc(msblk->read_size, GFP_KERNEL))) {
-+ ERROR("Failed to allocate read_data block\n");
-+ goto failed_mount;
-+ }
-+
-+ /* Allocate read_page block */
-+ if (!(msblk->read_page = kmalloc(sblk->block_size, GFP_KERNEL))) {
-+ ERROR("Failed to allocate read_page block\n");
-+ goto failed_mount;
-+ }
-+
-+ /* Allocate uid and gid tables */
-+ if (!(msblk->uid = kmalloc((sblk->no_uids + sblk->no_guids) *
-+ sizeof(unsigned int), GFP_KERNEL))) {
-+ ERROR("Failed to allocate uid/gid table\n");
-+ goto failed_mount;
-+ }
-+ msblk->guid = msblk->uid + sblk->no_uids;
-+
-+ if (msblk->swap) {
-+ unsigned int suid[sblk->no_uids + sblk->no_guids];
-+
-+ if (!squashfs_read_data(s, (char *) &suid, sblk->uid_start,
-+ ((sblk->no_uids + sblk->no_guids) *
-+ sizeof(unsigned int)) |
-+ SQUASHFS_COMPRESSED_BIT_BLOCK, NULL)) {
-+ ERROR("unable to read uid/gid table\n");
-+ goto failed_mount;
-+ }
-+
-+ SQUASHFS_SWAP_DATA(msblk->uid, suid, (sblk->no_uids +
-+ sblk->no_guids), (sizeof(unsigned int) * 8));
-+ } else
-+ if (!squashfs_read_data(s, (char *) msblk->uid, sblk->uid_start,
-+ ((sblk->no_uids + sblk->no_guids) *
-+ sizeof(unsigned int)) |
-+ SQUASHFS_COMPRESSED_BIT_BLOCK, NULL)) {
-+ ERROR("unable to read uid/gid table\n");
-+ goto failed_mount;
-+ }
-+
-+
-+ if (sblk->s_major == 1 && squashfs_1_0_supported(msblk))
-+ goto allocate_root;
-+
-+ if (!(msblk->fragment = kmalloc(sizeof(struct squashfs_fragment_cache) *
-+ SQUASHFS_CACHED_FRAGMENTS, GFP_KERNEL))) {
-+ ERROR("Failed to allocate fragment block cache\n");
-+ goto failed_mount;
-+ }
-+
-+ for (i = 0; i < SQUASHFS_CACHED_FRAGMENTS; i++) {
-+ msblk->fragment[i].locked = 0;
-+ msblk->fragment[i].block = SQUASHFS_INVALID_BLK;
-+ msblk->fragment[i].data = NULL;
-+ }
-+
-+ msblk->next_fragment = 0;
-+
-+ /* Allocate fragment index table */
-+ if (msblk->read_fragment_index_table(s) == 0)
-+ goto failed_mount;
-+
-+allocate_root:
-+ if ((root = (msblk->iget)(s, sblk->root_inode)) == NULL)
-+ goto failed_mount;
-+
-+ if ((s->s_root = d_alloc_root(root)) == NULL) {
-+ ERROR("Root inode create failed\n");
-+ iput(root);
-+ goto failed_mount;
-+ }
-+
-+ TRACE("Leaving squashfs_read_super\n");
-+ return 0;
-+
-+failed_mount:
-+ kfree(msblk->fragment_index);
-+ kfree(msblk->fragment);
-+ kfree(msblk->uid);
-+ kfree(msblk->read_page);
-+ kfree(msblk->read_data);
-+ kfree(msblk->block_cache);
-+ kfree(msblk->fragment_index_2);
-+ kfree(s->s_fs_info);
-+ s->s_fs_info = NULL;
-+ return -EINVAL;
-+
-+failure:
-+ return -ENOMEM;
-+}
-+
-+
-+static int squashfs_statfs(struct dentry *dentry, struct kstatfs *buf)
-+{
-+ struct squashfs_sb_info *msblk = dentry->d_inode->i_sb->s_fs_info;
-+ struct squashfs_super_block *sblk = &msblk->sblk;
-+
-+ TRACE("Entered squashfs_statfs\n");
-+
-+ buf->f_type = SQUASHFS_MAGIC;
-+ buf->f_bsize = sblk->block_size;
-+ buf->f_blocks = ((sblk->bytes_used - 1) >> sblk->block_log) + 1;
-+ buf->f_bfree = buf->f_bavail = 0;
-+ buf->f_files = sblk->inodes;
-+ buf->f_ffree = 0;
-+ buf->f_namelen = SQUASHFS_NAME_LEN;
-+
-+ return 0;
-+}
-+
-+
-+static int squashfs_symlink_readpage(struct file *file, struct page *page)
-+{
-+ struct inode *inode = page->mapping->host;
-+ int index = page->index << PAGE_CACHE_SHIFT, length, bytes;
-+ long long block = SQUASHFS_I(inode)->start_block;
-+ int offset = SQUASHFS_I(inode)->offset;
-+ void *pageaddr = kmap(page);
-+
-+ TRACE("Entered squashfs_symlink_readpage, page index %ld, start block "
-+ "%llx, offset %x\n", page->index,
-+ SQUASHFS_I(inode)->start_block,
-+ SQUASHFS_I(inode)->offset);
-+
-+ for (length = 0; length < index; length += bytes) {
-+ if (!(bytes = squashfs_get_cached_block(inode->i_sb, NULL,
-+ block, offset, PAGE_CACHE_SIZE, &block,
-+ &offset))) {
-+ ERROR("Unable to read symbolic link [%llx:%x]\n", block,
-+ offset);
-+ goto skip_read;
-+ }
-+ }
-+
-+ if (length != index) {
-+ ERROR("(squashfs_symlink_readpage) length != index\n");
-+ bytes = 0;
-+ goto skip_read;
-+ }
-+
-+ bytes = (i_size_read(inode) - length) > PAGE_CACHE_SIZE ? PAGE_CACHE_SIZE :
-+ i_size_read(inode) - length;
-+
-+ if (!(bytes = squashfs_get_cached_block(inode->i_sb, pageaddr, block,
-+ offset, bytes, &block, &offset)))
-+ ERROR("Unable to read symbolic link [%llx:%x]\n", block, offset);
-+
-+skip_read:
-+ memset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);
-+ kunmap(page);
-+ SetPageUptodate(page);
-+ unlock_page(page);
-+
-+ return 0;
-+}
-+
-+
-+struct meta_index *locate_meta_index(struct inode *inode, int index, int offset)
-+{
-+ struct meta_index *meta = NULL;
-+ struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
-+ int i;
-+
-+ down(&msblk->meta_index_mutex);
-+
-+ TRACE("locate_meta_index: index %d, offset %d\n", index, offset);
-+
-+ if(msblk->meta_index == NULL)
-+ goto not_allocated;
-+
-+ for (i = 0; i < SQUASHFS_META_NUMBER; i ++)
-+ if (msblk->meta_index[i].inode_number == inode->i_ino &&
-+ msblk->meta_index[i].offset >= offset &&
-+ msblk->meta_index[i].offset <= index &&
-+ msblk->meta_index[i].locked == 0) {
-+ TRACE("locate_meta_index: entry %d, offset %d\n", i,
-+ msblk->meta_index[i].offset);
-+ meta = &msblk->meta_index[i];
-+ offset = meta->offset;
-+ }
-+
-+ if (meta)
-+ meta->locked = 1;
-+
-+not_allocated:
-+ up(&msblk->meta_index_mutex);
-+
-+ return meta;
-+}
-+
-+
-+struct meta_index *empty_meta_index(struct inode *inode, int offset, int skip)
-+{
-+ struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
-+ struct meta_index *meta = NULL;
-+ int i;
-+
-+ down(&msblk->meta_index_mutex);
-+
-+ TRACE("empty_meta_index: offset %d, skip %d\n", offset, skip);
-+
-+ if(msblk->meta_index == NULL) {
-+ if (!(msblk->meta_index = kmalloc(sizeof(struct meta_index) *
-+ SQUASHFS_META_NUMBER, GFP_KERNEL))) {
-+ ERROR("Failed to allocate meta_index\n");
-+ goto failed;
-+ }
-+ for(i = 0; i < SQUASHFS_META_NUMBER; i++) {
-+ msblk->meta_index[i].inode_number = 0;
-+ msblk->meta_index[i].locked = 0;
-+ }
-+ msblk->next_meta_index = 0;
-+ }
-+
-+ for(i = SQUASHFS_META_NUMBER; i &&
-+ msblk->meta_index[msblk->next_meta_index].locked; i --)
-+ msblk->next_meta_index = (msblk->next_meta_index + 1) %
-+ SQUASHFS_META_NUMBER;
-+
-+ if(i == 0) {
-+ TRACE("empty_meta_index: failed!\n");
-+ goto failed;
-+ }
-+
-+ TRACE("empty_meta_index: returned meta entry %d, %p\n",
-+ msblk->next_meta_index,
-+ &msblk->meta_index[msblk->next_meta_index]);
-+
-+ meta = &msblk->meta_index[msblk->next_meta_index];
-+ msblk->next_meta_index = (msblk->next_meta_index + 1) %
-+ SQUASHFS_META_NUMBER;
-+
-+ meta->inode_number = inode->i_ino;
-+ meta->offset = offset;
-+ meta->skip = skip;
-+ meta->entries = 0;
-+ meta->locked = 1;
-+
-+failed:
-+ up(&msblk->meta_index_mutex);
-+ return meta;
-+}
-+
-+
-+void release_meta_index(struct inode *inode, struct meta_index *meta)
-+{
-+ meta->locked = 0;
-+}
-+
-+
-+static int read_block_index(struct super_block *s, int blocks, char *block_list,
-+ long long *start_block, int *offset)
-+{
-+ struct squashfs_sb_info *msblk = s->s_fs_info;
-+ unsigned int *block_listp;
-+ int block = 0;
-+
-+ if (msblk->swap) {
-+ char sblock_list[blocks << 2];
-+
-+ if (!squashfs_get_cached_block(s, sblock_list, *start_block,
-+ *offset, blocks << 2, start_block, offset)) {
-+ ERROR("Unable to read block list [%llx:%x]\n",
-+ *start_block, *offset);
-+ goto failure;
-+ }
-+ SQUASHFS_SWAP_INTS(((unsigned int *)block_list),
-+ ((unsigned int *)sblock_list), blocks);
-+ } else
-+ if (!squashfs_get_cached_block(s, block_list, *start_block,
-+ *offset, blocks << 2, start_block, offset)) {
-+ ERROR("Unable to read block list [%llx:%x]\n",
-+ *start_block, *offset);
-+ goto failure;
-+ }
-+
-+ for (block_listp = (unsigned int *) block_list; blocks;
-+ block_listp++, blocks --)
-+ block += SQUASHFS_COMPRESSED_SIZE_BLOCK(*block_listp);
-+
-+ return block;
-+
-+failure:
-+ return -1;
-+}
-+
-+
-+#define SIZE 256
-+
-+static inline int calculate_skip(int blocks) {
-+ int skip = (blocks - 1) / ((SQUASHFS_SLOTS * SQUASHFS_META_ENTRIES + 1) * SQUASHFS_META_INDEXES);
-+ return skip >= 7 ? 7 : skip + 1;
-+}
-+
-+
-+static int get_meta_index(struct inode *inode, int index,
-+ long long *index_block, int *index_offset,
-+ long long *data_block, char *block_list)
-+{
-+ struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
-+ struct squashfs_super_block *sblk = &msblk->sblk;
-+ int skip = calculate_skip(i_size_read(inode) >> sblk->block_log);
-+ int offset = 0;
-+ struct meta_index *meta;
-+ struct meta_entry *meta_entry;
-+ long long cur_index_block = SQUASHFS_I(inode)->u.s1.block_list_start;
-+ int cur_offset = SQUASHFS_I(inode)->offset;
-+ long long cur_data_block = SQUASHFS_I(inode)->start_block;
-+ int i;
-+
-+ index /= SQUASHFS_META_INDEXES * skip;
-+
-+ while ( offset < index ) {
-+ meta = locate_meta_index(inode, index, offset + 1);
-+
-+ if (meta == NULL) {
-+ if ((meta = empty_meta_index(inode, offset + 1,
-+ skip)) == NULL)
-+ goto all_done;
-+ } else {
-+ offset = index < meta->offset + meta->entries ? index :
-+ meta->offset + meta->entries - 1;
-+ meta_entry = &meta->meta_entry[offset - meta->offset];
-+ cur_index_block = meta_entry->index_block + sblk->inode_table_start;
-+ cur_offset = meta_entry->offset;
-+ cur_data_block = meta_entry->data_block;
-+ TRACE("get_meta_index: offset %d, meta->offset %d, "
-+ "meta->entries %d\n", offset, meta->offset,
-+ meta->entries);
-+ TRACE("get_meta_index: index_block 0x%llx, offset 0x%x"
-+ " data_block 0x%llx\n", cur_index_block,
-+ cur_offset, cur_data_block);
-+ }
-+
-+ for (i = meta->offset + meta->entries; i <= index &&
-+ i < meta->offset + SQUASHFS_META_ENTRIES; i++) {
-+ int blocks = skip * SQUASHFS_META_INDEXES;
-+
-+ while (blocks) {
-+ int block = blocks > (SIZE >> 2) ? (SIZE >> 2) :
-+ blocks;
-+ int res = read_block_index(inode->i_sb, block,
-+ block_list, &cur_index_block,
-+ &cur_offset);
-+
-+ if (res == -1)
-+ goto failed;
-+
-+ cur_data_block += res;
-+ blocks -= block;
-+ }
-+
-+ meta_entry = &meta->meta_entry[i - meta->offset];
-+ meta_entry->index_block = cur_index_block - sblk->inode_table_start;
-+ meta_entry->offset = cur_offset;
-+ meta_entry->data_block = cur_data_block;
-+ meta->entries ++;
-+ offset ++;
-+ }
-+
-+ TRACE("get_meta_index: meta->offset %d, meta->entries %d\n",
-+ meta->offset, meta->entries);
-+
-+ release_meta_index(inode, meta);
-+ }
-+
-+all_done:
-+ *index_block = cur_index_block;
-+ *index_offset = cur_offset;
-+ *data_block = cur_data_block;
-+
-+ return offset * SQUASHFS_META_INDEXES * skip;
-+
-+failed:
-+ release_meta_index(inode, meta);
-+ return -1;
-+}
-+
-+
-+static long long read_blocklist(struct inode *inode, int index,
-+ int readahead_blks, char *block_list,
-+ unsigned short **block_p, unsigned int *bsize)
-+{
-+ long long block_ptr;
-+ int offset;
-+ long long block;
-+ int res = get_meta_index(inode, index, &block_ptr, &offset, &block,
-+ block_list);
-+
-+ TRACE("read_blocklist: res %d, index %d, block_ptr 0x%llx, offset"
-+ " 0x%x, block 0x%llx\n", res, index, block_ptr, offset,
-+ block);
-+
-+ if(res == -1)
-+ goto failure;
-+
-+ index -= res;
-+
-+ while ( index ) {
-+ int blocks = index > (SIZE >> 2) ? (SIZE >> 2) : index;
-+ int res = read_block_index(inode->i_sb, blocks, block_list,
-+ &block_ptr, &offset);
-+ if (res == -1)
-+ goto failure;
-+ block += res;
-+ index -= blocks;
-+ }
-+
-+ if (read_block_index(inode->i_sb, 1, block_list,
-+ &block_ptr, &offset) == -1)
-+ goto failure;
-+ *bsize = *((unsigned int *) block_list);
-+
-+ return block;
-+
-+failure:
-+ return 0;
-+}
-+
-+
-+static int squashfs_readpage(struct file *file, struct page *page)
-+{
-+ struct inode *inode = page->mapping->host;
-+ struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
-+ struct squashfs_super_block *sblk = &msblk->sblk;
-+ unsigned char block_list[SIZE];
-+ long long block;
-+ unsigned int bsize, i = 0, bytes = 0, byte_offset = 0;
-+ int index = page->index >> (sblk->block_log - PAGE_CACHE_SHIFT);
-+ void *pageaddr;
-+ struct squashfs_fragment_cache *fragment = NULL;
-+ char *data_ptr = msblk->read_page;
-+
-+ int mask = (1 << (sblk->block_log - PAGE_CACHE_SHIFT)) - 1;
-+ int start_index = page->index & ~mask;
-+ int end_index = start_index | mask;
-+
-+ TRACE("Entered squashfs_readpage, page index %lx, start block %llx\n",
-+ page->index,
-+ SQUASHFS_I(inode)->start_block);
-+
-+ if (page->index >= ((i_size_read(inode) + PAGE_CACHE_SIZE - 1) >>
-+ PAGE_CACHE_SHIFT))
-+ goto skip_read;
-+
-+ if (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK
-+ || index < (i_size_read(inode) >>
-+ sblk->block_log)) {
-+ if ((block = (msblk->read_blocklist)(inode, index, 1,
-+ block_list, NULL, &bsize)) == 0)
-+ goto skip_read;
-+
-+ down(&msblk->read_page_mutex);
-+
-+ if (!(bytes = squashfs_read_data(inode->i_sb, msblk->read_page,
-+ block, bsize, NULL))) {
-+ ERROR("Unable to read page, block %llx, size %x\n", block,
-+ bsize);
-+ up(&msblk->read_page_mutex);
-+ goto skip_read;
-+ }
-+ } else {
-+ if ((fragment = get_cached_fragment(inode->i_sb,
-+ SQUASHFS_I(inode)->
-+ u.s1.fragment_start_block,
-+ SQUASHFS_I(inode)->u.s1.fragment_size))
-+ == NULL) {
-+ ERROR("Unable to read page, block %llx, size %x\n",
-+ SQUASHFS_I(inode)->
-+ u.s1.fragment_start_block,
-+ (int) SQUASHFS_I(inode)->
-+ u.s1.fragment_size);
-+ goto skip_read;
-+ }
-+ bytes = SQUASHFS_I(inode)->u.s1.fragment_offset +
-+ (i_size_read(inode) & (sblk->block_size
-+ - 1));
-+ byte_offset = SQUASHFS_I(inode)->u.s1.fragment_offset;
-+ data_ptr = fragment->data;
-+ }
-+
-+ for (i = start_index; i <= end_index && byte_offset < bytes;
-+ i++, byte_offset += PAGE_CACHE_SIZE) {
-+ struct page *push_page;
-+ int available_bytes = (bytes - byte_offset) > PAGE_CACHE_SIZE ?
-+ PAGE_CACHE_SIZE : bytes - byte_offset;
-+
-+ TRACE("bytes %d, i %d, byte_offset %d, available_bytes %d\n",
-+ bytes, i, byte_offset, available_bytes);
-+
-+ if (i == page->index) {
-+ pageaddr = kmap_atomic(page, KM_USER0);
-+ memcpy(pageaddr, data_ptr + byte_offset,
-+ available_bytes);
-+ memset(pageaddr + available_bytes, 0,
-+ PAGE_CACHE_SIZE - available_bytes);
-+ kunmap_atomic(pageaddr, KM_USER0);
-+ flush_dcache_page(page);
-+ SetPageUptodate(page);
-+ unlock_page(page);
-+ } else if ((push_page =
-+ grab_cache_page_nowait(page->mapping, i))) {
-+ pageaddr = kmap_atomic(push_page, KM_USER0);
-+
-+ memcpy(pageaddr, data_ptr + byte_offset,
-+ available_bytes);
-+ memset(pageaddr + available_bytes, 0,
-+ PAGE_CACHE_SIZE - available_bytes);
-+ kunmap_atomic(pageaddr, KM_USER0);
-+ flush_dcache_page(push_page);
-+ SetPageUptodate(push_page);
-+ unlock_page(push_page);
-+ page_cache_release(push_page);
-+ }
-+ }
-+
-+ if (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK
-+ || index < (i_size_read(inode) >>
-+ sblk->block_log))
-+ up(&msblk->read_page_mutex);
-+ else
-+ release_cached_fragment(msblk, fragment);
-+
-+ return 0;
-+
-+skip_read:
-+ pageaddr = kmap_atomic(page, KM_USER0);
-+ memset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);
-+ kunmap_atomic(pageaddr, KM_USER0);
-+ flush_dcache_page(page);
-+ SetPageUptodate(page);
-+ unlock_page(page);
-+
-+ return 0;
-+}
-+
-+
-+static int squashfs_readpage4K(struct file *file, struct page *page)
-+{
-+ struct inode *inode = page->mapping->host;
-+ struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
-+ struct squashfs_super_block *sblk = &msblk->sblk;
-+ unsigned char block_list[SIZE];
-+ long long block;
-+ unsigned int bsize, bytes = 0;
-+ void *pageaddr;
-+
-+ TRACE("Entered squashfs_readpage4K, page index %lx, start block %llx\n",
-+ page->index,
-+ SQUASHFS_I(inode)->start_block);
-+
-+ if (page->index >= ((i_size_read(inode) + PAGE_CACHE_SIZE - 1) >>
-+ PAGE_CACHE_SHIFT)) {
-+ pageaddr = kmap_atomic(page, KM_USER0);
-+ goto skip_read;
-+ }
-+
-+ if (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK
-+ || page->index < (i_size_read(inode) >>
-+ sblk->block_log)) {
-+ block = (msblk->read_blocklist)(inode, page->index, 1,
-+ block_list, NULL, &bsize);
-+
-+ down(&msblk->read_page_mutex);
-+ bytes = squashfs_read_data(inode->i_sb, msblk->read_page, block,
-+ bsize, NULL);
-+ pageaddr = kmap_atomic(page, KM_USER0);
-+ if (bytes)
-+ memcpy(pageaddr, msblk->read_page, bytes);
-+ else
-+ ERROR("Unable to read page, block %llx, size %x\n",
-+ block, bsize);
-+ up(&msblk->read_page_mutex);
-+ } else {
-+ struct squashfs_fragment_cache *fragment =
-+ get_cached_fragment(inode->i_sb,
-+ SQUASHFS_I(inode)->
-+ u.s1.fragment_start_block,
-+ SQUASHFS_I(inode)-> u.s1.fragment_size);
-+ pageaddr = kmap_atomic(page, KM_USER0);
-+ if (fragment) {
-+ bytes = i_size_read(inode) & (sblk->block_size - 1);
-+ memcpy(pageaddr, fragment->data + SQUASHFS_I(inode)->
-+ u.s1.fragment_offset, bytes);
-+ release_cached_fragment(msblk, fragment);
-+ } else
-+ ERROR("Unable to read page, block %llx, size %x\n",
-+ SQUASHFS_I(inode)->
-+ u.s1.fragment_start_block, (int)
-+ SQUASHFS_I(inode)-> u.s1.fragment_size);
-+ }
-+
-+skip_read:
-+ memset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);
-+ kunmap_atomic(pageaddr, KM_USER0);
-+ flush_dcache_page(page);
-+ SetPageUptodate(page);
-+ unlock_page(page);
-+
-+ return 0;
-+}
-+
-+
-+static int get_dir_index_using_offset(struct super_block *s, long long
-+ *next_block, unsigned int *next_offset,
-+ long long index_start,
-+ unsigned int index_offset, int i_count,
-+ long long f_pos)
-+{
-+ struct squashfs_sb_info *msblk = s->s_fs_info;
-+ struct squashfs_super_block *sblk = &msblk->sblk;
-+ int i, length = 0;
-+ struct squashfs_dir_index index;
-+
-+ TRACE("Entered get_dir_index_using_offset, i_count %d, f_pos %d\n",
-+ i_count, (unsigned int) f_pos);
-+
-+ f_pos =- 3;
-+ if (f_pos == 0)
-+ goto finish;
-+
-+ for (i = 0; i < i_count; i++) {
-+ if (msblk->swap) {
-+ struct squashfs_dir_index sindex;
-+ squashfs_get_cached_block(s, (char *) &sindex,
-+ index_start, index_offset,
-+ sizeof(sindex), &index_start,
-+ &index_offset);
-+ SQUASHFS_SWAP_DIR_INDEX(&index, &sindex);
-+ } else
-+ squashfs_get_cached_block(s, (char *) &index,
-+ index_start, index_offset,
-+ sizeof(index), &index_start,
-+ &index_offset);
-+
-+ if (index.index > f_pos)
-+ break;
-+
-+ squashfs_get_cached_block(s, NULL, index_start, index_offset,
-+ index.size + 1, &index_start,
-+ &index_offset);
-+
-+ length = index.index;
-+ *next_block = index.start_block + sblk->directory_table_start;
-+ }
-+
-+ *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
-+
-+finish:
-+ return length + 3;
-+}
-+
-+
-+static int get_dir_index_using_name(struct super_block *s, long long
-+ *next_block, unsigned int *next_offset,
-+ long long index_start,
-+ unsigned int index_offset, int i_count,
-+ const char *name, int size)
-+{
-+ struct squashfs_sb_info *msblk = s->s_fs_info;
-+ struct squashfs_super_block *sblk = &msblk->sblk;
-+ int i, length = 0;
-+ char buffer[sizeof(struct squashfs_dir_index) + SQUASHFS_NAME_LEN + 1];
-+ struct squashfs_dir_index *index = (struct squashfs_dir_index *) buffer;
-+ char str[SQUASHFS_NAME_LEN + 1];
-+
-+ TRACE("Entered get_dir_index_using_name, i_count %d\n", i_count);
-+
-+ strncpy(str, name, size);
-+ str[size] = '\0';
-+
-+ for (i = 0; i < i_count; i++) {
-+ if (msblk->swap) {
-+ struct squashfs_dir_index sindex;
-+ squashfs_get_cached_block(s, (char *) &sindex,
-+ index_start, index_offset,
-+ sizeof(sindex), &index_start,
-+ &index_offset);
-+ SQUASHFS_SWAP_DIR_INDEX(index, &sindex);
-+ } else
-+ squashfs_get_cached_block(s, (char *) index,
-+ index_start, index_offset,
-+ sizeof(struct squashfs_dir_index),
-+ &index_start, &index_offset);
-+
-+ squashfs_get_cached_block(s, index->name, index_start,
-+ index_offset, index->size + 1,
-+ &index_start, &index_offset);
-+
-+ index->name[index->size + 1] = '\0';
-+
-+ if (strcmp(index->name, str) > 0)
-+ break;
-+
-+ length = index->index;
-+ *next_block = index->start_block + sblk->directory_table_start;
-+ }
-+
-+ *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
-+ return length + 3;
-+}
-+
-+
-+static int squashfs_readdir(struct file *file, void *dirent, filldir_t filldir)
-+{
-+ struct inode *i = file->f_dentry->d_inode;
-+ struct squashfs_sb_info *msblk = i->i_sb->s_fs_info;
-+ struct squashfs_super_block *sblk = &msblk->sblk;
-+ long long next_block = SQUASHFS_I(i)->start_block +
-+ sblk->directory_table_start;
-+ int next_offset = SQUASHFS_I(i)->offset, length = 0, dirs_read = 0,
-+ dir_count;
-+ struct squashfs_dir_header dirh;
-+ char buffer[sizeof(struct squashfs_dir_entry) + SQUASHFS_NAME_LEN + 1];
-+ struct squashfs_dir_entry *dire = (struct squashfs_dir_entry *) buffer;
-+
-+ TRACE("Entered squashfs_readdir [%llx:%x]\n", next_block, next_offset);
-+
-+ while(file->f_pos < 3) {
-+ char *name;
-+ int size, i_ino;
-+
-+ if(file->f_pos == 0) {
-+ name = ".";
-+ size = 1;
-+ i_ino = i->i_ino;
-+ } else {
-+ name = "..";
-+ size = 2;
-+ i_ino = SQUASHFS_I(i)->u.s2.parent_inode;
-+ }
-+ TRACE("Calling filldir(%x, %s, %d, %d, %d, %d)\n",
-+ (unsigned int) dirent, name, size, (int)
-+ file->f_pos, i_ino,
-+ squashfs_filetype_table[1]);
-+
-+ if (filldir(dirent, name, size,
-+ file->f_pos, i_ino,
-+ squashfs_filetype_table[1]) < 0) {
-+ TRACE("Filldir returned less than 0\n");
-+ goto finish;
-+ }
-+ file->f_pos += size;
-+ dirs_read++;
-+ }
-+
-+ length = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,
-+ SQUASHFS_I(i)->u.s2.directory_index_start,
-+ SQUASHFS_I(i)->u.s2.directory_index_offset,
-+ SQUASHFS_I(i)->u.s2.directory_index_count,
-+ file->f_pos);
-+
-+ while (length < i_size_read(i)) {
-+ /* read directory header */
-+ if (msblk->swap) {
-+ struct squashfs_dir_header sdirh;
-+
-+ if (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,
-+ next_block, next_offset, sizeof(sdirh),
-+ &next_block, &next_offset))
-+ goto failed_read;
-+
-+ length += sizeof(sdirh);
-+ SQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);
-+ } else {
-+ if (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,
-+ next_block, next_offset, sizeof(dirh),
-+ &next_block, &next_offset))
-+ goto failed_read;
-+
-+ length += sizeof(dirh);
-+ }
-+
-+ dir_count = dirh.count + 1;
-+ while (dir_count--) {
-+ if (msblk->swap) {
-+ struct squashfs_dir_entry sdire;
-+ if (!squashfs_get_cached_block(i->i_sb, (char *)
-+ &sdire, next_block, next_offset,
-+ sizeof(sdire), &next_block,
-+ &next_offset))
-+ goto failed_read;
-+
-+ length += sizeof(sdire);
-+ SQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);
-+ } else {
-+ if (!squashfs_get_cached_block(i->i_sb, (char *)
-+ dire, next_block, next_offset,
-+ sizeof(*dire), &next_block,
-+ &next_offset))
-+ goto failed_read;
-+
-+ length += sizeof(*dire);
-+ }
-+
-+ if (!squashfs_get_cached_block(i->i_sb, dire->name,
-+ next_block, next_offset,
-+ dire->size + 1, &next_block,
-+ &next_offset))
-+ goto failed_read;
-+
-+ length += dire->size + 1;
-+
-+ if (file->f_pos >= length)
-+ continue;
-+
-+ dire->name[dire->size + 1] = '\0';
-+
-+ TRACE("Calling filldir(%x, %s, %d, %d, %x:%x, %d, %d)\n",
-+ (unsigned int) dirent, dire->name,
-+ dire->size + 1, (int) file->f_pos,
-+ dirh.start_block, dire->offset,
-+ dirh.inode_number + dire->inode_number,
-+ squashfs_filetype_table[dire->type]);
-+
-+ if (filldir(dirent, dire->name, dire->size + 1,
-+ file->f_pos,
-+ dirh.inode_number + dire->inode_number,
-+ squashfs_filetype_table[dire->type])
-+ < 0) {
-+ TRACE("Filldir returned less than 0\n");
-+ goto finish;
-+ }
-+ file->f_pos = length;
-+ dirs_read++;
-+ }
-+ }
-+
-+finish:
-+ return dirs_read;
-+
-+failed_read:
-+ ERROR("Unable to read directory block [%llx:%x]\n", next_block,
-+ next_offset);
-+ return 0;
-+}
-+
-+
-+static struct dentry *squashfs_lookup(struct inode *i, struct dentry *dentry,
-+ struct nameidata *nd)
-+{
-+ const unsigned char *name = dentry->d_name.name;
-+ int len = dentry->d_name.len;
-+ struct inode *inode = NULL;
-+ struct squashfs_sb_info *msblk = i->i_sb->s_fs_info;
-+ struct squashfs_super_block *sblk = &msblk->sblk;
-+ long long next_block = SQUASHFS_I(i)->start_block +
-+ sblk->directory_table_start;
-+ int next_offset = SQUASHFS_I(i)->offset, length = 0,
-+ dir_count;
-+ struct squashfs_dir_header dirh;
-+ char buffer[sizeof(struct squashfs_dir_entry) + SQUASHFS_NAME_LEN];
-+ struct squashfs_dir_entry *dire = (struct squashfs_dir_entry *) buffer;
-+
-+ TRACE("Entered squashfs_lookup [%llx:%x]\n", next_block, next_offset);
-+
-+ if (len > SQUASHFS_NAME_LEN)
-+ goto exit_loop;
-+
-+ length = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,
-+ SQUASHFS_I(i)->u.s2.directory_index_start,
-+ SQUASHFS_I(i)->u.s2.directory_index_offset,
-+ SQUASHFS_I(i)->u.s2.directory_index_count, name,
-+ len);
-+
-+ while (length < i_size_read(i)) {
-+ /* read directory header */
-+ if (msblk->swap) {
-+ struct squashfs_dir_header sdirh;
-+ if (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,
-+ next_block, next_offset, sizeof(sdirh),
-+ &next_block, &next_offset))
-+ goto failed_read;
-+
-+ length += sizeof(sdirh);
-+ SQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);
-+ } else {
-+ if (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,
-+ next_block, next_offset, sizeof(dirh),
-+ &next_block, &next_offset))
-+ goto failed_read;
-+
-+ length += sizeof(dirh);
-+ }
-+
-+ dir_count = dirh.count + 1;
-+ while (dir_count--) {
-+ if (msblk->swap) {
-+ struct squashfs_dir_entry sdire;
-+ if (!squashfs_get_cached_block(i->i_sb, (char *)
-+ &sdire, next_block,next_offset,
-+ sizeof(sdire), &next_block,
-+ &next_offset))
-+ goto failed_read;
-+
-+ length += sizeof(sdire);
-+ SQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);
-+ } else {
-+ if (!squashfs_get_cached_block(i->i_sb, (char *)
-+ dire, next_block,next_offset,
-+ sizeof(*dire), &next_block,
-+ &next_offset))
-+ goto failed_read;
-+
-+ length += sizeof(*dire);
-+ }
-+
-+ if (!squashfs_get_cached_block(i->i_sb, dire->name,
-+ next_block, next_offset, dire->size + 1,
-+ &next_block, &next_offset))
-+ goto failed_read;
-+
-+ length += dire->size + 1;
-+
-+ if (name[0] < dire->name[0])
-+ goto exit_loop;
-+
-+ if ((len == dire->size + 1) && !strncmp(name,
-+ dire->name, len)) {
-+ squashfs_inode_t ino =
-+ SQUASHFS_MKINODE(dirh.start_block,
-+ dire->offset);
-+
-+ TRACE("calling squashfs_iget for directory "
-+ "entry %s, inode %x:%x, %d\n", name,
-+ dirh.start_block, dire->offset,
-+ dirh.inode_number + dire->inode_number);
-+
-+ inode = (msblk->iget)(i->i_sb, ino);
-+
-+ goto exit_loop;
-+ }
-+ }
-+ }
-+
-+exit_loop:
-+ d_add(dentry, inode);
-+ return ERR_PTR(0);
-+
-+failed_read:
-+ ERROR("Unable to read directory block [%llx:%x]\n", next_block,
-+ next_offset);
-+ goto exit_loop;
-+}
-+
-+
-+static void squashfs_put_super(struct super_block *s)
-+{
-+ int i;
-+
-+ if (s->s_fs_info) {
-+ struct squashfs_sb_info *sbi = s->s_fs_info;
-+ if (sbi->block_cache)
-+ for (i = 0; i < SQUASHFS_CACHED_BLKS; i++)
-+ if (sbi->block_cache[i].block !=
-+ SQUASHFS_INVALID_BLK)
-+ kfree(sbi->block_cache[i].data);
-+ if (sbi->fragment)
-+ for (i = 0; i < SQUASHFS_CACHED_FRAGMENTS; i++)
-+ SQUASHFS_FREE(sbi->fragment[i].data);
-+ kfree(sbi->fragment);
-+ kfree(sbi->block_cache);
-+ kfree(sbi->read_data);
-+ kfree(sbi->read_page);
-+ kfree(sbi->uid);
-+ kfree(sbi->fragment_index);
-+ kfree(sbi->fragment_index_2);
-+ kfree(sbi->meta_index);
-+ kfree(s->s_fs_info);
-+ s->s_fs_info = NULL;
-+ }
-+}
-+
-+
-+static int squashfs_get_sb(struct file_system_type *fs_type,
-+ int flags, const char *dev_name, void *data,
-+ struct vfsmount *mnt)
-+{
-+ return get_sb_bdev(fs_type, flags, dev_name, data, squashfs_fill_super, mnt);
-+}
-+
-+
-+static int __init init_squashfs_fs(void)
-+{
-+ int err = init_inodecache();
-+ if (err)
-+ goto out;
-+
-+ printk(KERN_INFO "squashfs: version 3.0 (2006/03/15) "
-+ "Phillip Lougher\n");
-+
-+ if (!(stream.workspace = vmalloc(zlib_inflate_workspacesize()))) {
-+ ERROR("Failed to allocate zlib workspace\n");
-+ destroy_inodecache();
-+ err = -ENOMEM;
-+ goto out;
-+ }
-+
-+ if ((err = register_filesystem(&squashfs_fs_type))) {
-+ vfree(stream.workspace);
-+ destroy_inodecache();
-+ }
-+
-+out:
-+ return err;
-+}
-+
-+
-+static void __exit exit_squashfs_fs(void)
-+{
-+ vfree(stream.workspace);
-+ unregister_filesystem(&squashfs_fs_type);
-+ destroy_inodecache();
-+}
-+
-+
-+static struct kmem_cache * squashfs_inode_cachep;
-+
-+
-+static struct inode *squashfs_alloc_inode(struct super_block *sb)
-+{
-+ struct squashfs_inode_info *ei;
-+ ei = kmem_cache_alloc(squashfs_inode_cachep, GFP_KERNEL);
-+ if (!ei)
-+ return NULL;
-+ return &ei->vfs_inode;
-+}
-+
-+
-+static void squashfs_destroy_inode(struct inode *inode)
-+{
-+ kmem_cache_free(squashfs_inode_cachep, SQUASHFS_I(inode));
-+}
-+
-+
-+static void init_once(void * foo, struct kmem_cache * cachep, unsigned long flags)
-+{
-+ struct squashfs_inode_info *ei = foo;
-+
-+ inode_init_once(&ei->vfs_inode);
-+}
-+
-+
-+static int __init init_inodecache(void)
-+{
-+ squashfs_inode_cachep = kmem_cache_create("squashfs_inode_cache",
-+ sizeof(struct squashfs_inode_info),
-+ 0, SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT,
-+ init_once);
-+ if (squashfs_inode_cachep == NULL)
-+ return -ENOMEM;
-+ return 0;
-+}
-+
-+
-+static void destroy_inodecache(void)
-+{
-+ kmem_cache_destroy(squashfs_inode_cachep);
-+}
-+
-+
-+module_init(init_squashfs_fs);
-+module_exit(exit_squashfs_fs);
-+MODULE_DESCRIPTION("squashfs, a compressed read-only filesystem");
-+MODULE_AUTHOR("Phillip Lougher <phillip@lougher.org.uk>");
-+MODULE_LICENSE("GPL");
---- /dev/null
-+++ b/fs/squashfs/Makefile
-@@ -0,0 +1,7 @@
-+#
-+# Makefile for the linux squashfs routines.
-+#
-+
-+obj-$(CONFIG_SQUASHFS) += squashfs.o
-+squashfs-y += inode.o
-+squashfs-y += squashfs2_0.o
---- /dev/null
-+++ b/fs/squashfs/squashfs2_0.c
-@@ -0,0 +1,758 @@
-+/*
-+ * Squashfs - a compressed read only filesystem for Linux
-+ *
-+ * Copyright (c) 2002, 2003, 2004, 2005, 2006
-+ * Phillip Lougher <phillip@lougher.org.uk>
-+ *
-+ * 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,
-+ * 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-+ *
-+ * squashfs2_0.c
-+ */
-+
-+#include <linux/types.h>
-+#include <linux/squashfs_fs.h>
-+#include <linux/module.h>
-+#include <linux/errno.h>
-+#include <linux/slab.h>
-+#include <linux/fs.h>
-+#include <linux/smp_lock.h>
-+#include <linux/slab.h>
-+#include <linux/squashfs_fs_sb.h>
-+#include <linux/squashfs_fs_i.h>
-+#include <linux/buffer_head.h>
-+#include <linux/vfs.h>
-+#include <linux/init.h>
-+#include <linux/dcache.h>
-+#include <linux/wait.h>
-+#include <linux/zlib.h>
-+#include <linux/blkdev.h>
-+#include <linux/vmalloc.h>
-+#include <asm/uaccess.h>
-+#include <asm/semaphore.h>
-+
-+#include "squashfs.h"
-+static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir);
-+static struct dentry *squashfs_lookup_2(struct inode *, struct dentry *,
-+ struct nameidata *);
-+
-+static struct file_operations squashfs_dir_ops_2 = {
-+ .read = generic_read_dir,
-+ .readdir = squashfs_readdir_2
-+};
-+
-+static struct inode_operations squashfs_dir_inode_ops_2 = {
-+ .lookup = squashfs_lookup_2
-+};
-+
-+static unsigned char squashfs_filetype_table[] = {
-+ DT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK
-+};
-+
-+static int read_fragment_index_table_2(struct super_block *s)
-+{
-+ struct squashfs_sb_info *msblk = s->s_fs_info;
-+ struct squashfs_super_block *sblk = &msblk->sblk;
-+
-+ if (!(msblk->fragment_index_2 = kmalloc(SQUASHFS_FRAGMENT_INDEX_BYTES_2
-+ (sblk->fragments), GFP_KERNEL))) {
-+ ERROR("Failed to allocate uid/gid table\n");
-+ return 0;
-+ }
-+
-+ if (SQUASHFS_FRAGMENT_INDEX_BYTES_2(sblk->fragments) &&
-+ !squashfs_read_data(s, (char *)
-+ msblk->fragment_index_2,
-+ sblk->fragment_table_start,
-+ SQUASHFS_FRAGMENT_INDEX_BYTES_2
-+ (sblk->fragments) |
-+ SQUASHFS_COMPRESSED_BIT_BLOCK, NULL)) {
-+ ERROR("unable to read fragment index table\n");
-+ return 0;
-+ }
-+
-+ if (msblk->swap) {
-+ int i;
-+ unsigned int fragment;
-+
-+ for (i = 0; i < SQUASHFS_FRAGMENT_INDEXES_2(sblk->fragments);
-+ i++) {
-+ SQUASHFS_SWAP_FRAGMENT_INDEXES_2((&fragment),
-+ &msblk->fragment_index_2[i], 1);
-+ msblk->fragment_index_2[i] = fragment;
-+ }
-+ }
-+
-+ return 1;
-+}
-+
-+
-+static int get_fragment_location_2(struct super_block *s, unsigned int fragment,
-+ long long *fragment_start_block,
-+ unsigned int *fragment_size)
-+{
-+ struct squashfs_sb_info *msblk = s->s_fs_info;
-+ long long start_block =
-+ msblk->fragment_index_2[SQUASHFS_FRAGMENT_INDEX_2(fragment)];
-+ int offset = SQUASHFS_FRAGMENT_INDEX_OFFSET_2(fragment);
-+ struct squashfs_fragment_entry_2 fragment_entry;
-+
-+ if (msblk->swap) {
-+ struct squashfs_fragment_entry_2 sfragment_entry;
-+
-+ if (!squashfs_get_cached_block(s, (char *) &sfragment_entry,
-+ start_block, offset,
-+ sizeof(sfragment_entry), &start_block,
-+ &offset))
-+ goto out;
-+ SQUASHFS_SWAP_FRAGMENT_ENTRY_2(&fragment_entry, &sfragment_entry);
-+ } else
-+ if (!squashfs_get_cached_block(s, (char *) &fragment_entry,
-+ start_block, offset,
-+ sizeof(fragment_entry), &start_block,
-+ &offset))
-+ goto out;
-+
-+ *fragment_start_block = fragment_entry.start_block;
-+ *fragment_size = fragment_entry.size;
-+
-+ return 1;
-+
-+out:
-+ return 0;
-+}
-+
-+
-+static struct inode *squashfs_new_inode(struct super_block *s,
-+ struct squashfs_base_inode_header_2 *inodeb, unsigned int ino)
-+{
-+ struct squashfs_sb_info *msblk = s->s_fs_info;
-+ struct squashfs_super_block *sblk = &msblk->sblk;
-+ struct inode *i = new_inode(s);
-+
-+ if (i) {
-+ i->i_ino = ino;
-+ i->i_mtime.tv_sec = sblk->mkfs_time;
-+ i->i_atime.tv_sec = sblk->mkfs_time;
-+ i->i_ctime.tv_sec = sblk->mkfs_time;
-+ i->i_uid = msblk->uid[inodeb->uid];
-+ i->i_mode = inodeb->mode;
-+ i->i_nlink = 1;
-+ i->i_size = 0;
-+ if (inodeb->guid == SQUASHFS_GUIDS)
-+ i->i_gid = i->i_uid;
-+ else
-+ i->i_gid = msblk->guid[inodeb->guid];
-+ }
-+
-+ return i;
-+}
-+
-+
-+static struct inode *squashfs_iget_2(struct super_block *s, squashfs_inode_t inode)
-+{
-+ struct inode *i;
-+ struct squashfs_sb_info *msblk = s->s_fs_info;
-+ struct squashfs_super_block *sblk = &msblk->sblk;
-+ unsigned int block = SQUASHFS_INODE_BLK(inode) +
-+ sblk->inode_table_start;
-+ unsigned int offset = SQUASHFS_INODE_OFFSET(inode);
-+ unsigned int ino = SQUASHFS_MK_VFS_INODE(block
-+ - sblk->inode_table_start, offset);
-+ long long next_block;
-+ unsigned int next_offset;
-+ union squashfs_inode_header_2 id, sid;
-+ struct squashfs_base_inode_header_2 *inodeb = &id.base,
-+ *sinodeb = &sid.base;
-+
-+ TRACE("Entered squashfs_iget\n");
-+
-+ if (msblk->swap) {
-+ if (!squashfs_get_cached_block(s, (char *) sinodeb, block,
-+ offset, sizeof(*sinodeb), &next_block,
-+ &next_offset))
-+ goto failed_read;
-+ SQUASHFS_SWAP_BASE_INODE_HEADER_2(inodeb, sinodeb,
-+ sizeof(*sinodeb));
-+ } else
-+ if (!squashfs_get_cached_block(s, (char *) inodeb, block,
-+ offset, sizeof(*inodeb), &next_block,
-+ &next_offset))
-+ goto failed_read;
-+
-+ switch(inodeb->inode_type) {
-+ case SQUASHFS_FILE_TYPE: {
-+ struct squashfs_reg_inode_header_2 *inodep = &id.reg;
-+ struct squashfs_reg_inode_header_2 *sinodep = &sid.reg;
-+ long long frag_blk;
-+ unsigned int frag_size;
-+
-+ if (msblk->swap) {
-+ if (!squashfs_get_cached_block(s, (char *)
-+ sinodep, block, offset,
-+ sizeof(*sinodep), &next_block,
-+ &next_offset))
-+ goto failed_read;
-+ SQUASHFS_SWAP_REG_INODE_HEADER_2(inodep, sinodep);
-+ } else
-+ if (!squashfs_get_cached_block(s, (char *)
-+ inodep, block, offset,
-+ sizeof(*inodep), &next_block,
-+ &next_offset))
-+ goto failed_read;
-+
-+ frag_blk = SQUASHFS_INVALID_BLK;
-+ if (inodep->fragment != SQUASHFS_INVALID_FRAG &&
-+ !get_fragment_location_2(s,
-+ inodep->fragment, &frag_blk, &frag_size))
-+ goto failed_read;
-+
-+ if((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
-+ goto failed_read1;
-+
-+ i->i_size = inodep->file_size;
-+ i->i_fop = &generic_ro_fops;
-+ i->i_mode |= S_IFREG;
-+ i->i_mtime.tv_sec = inodep->mtime;
-+ i->i_atime.tv_sec = inodep->mtime;
-+ i->i_ctime.tv_sec = inodep->mtime;
-+ i->i_blocks = ((i->i_size - 1) >> 9) + 1;
-+ i->i_blksize = PAGE_CACHE_SIZE;
-+ SQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;
-+ SQUASHFS_I(i)->u.s1.fragment_size = frag_size;
-+ SQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;
-+ SQUASHFS_I(i)->start_block = inodep->start_block;
-+ SQUASHFS_I(i)->u.s1.block_list_start = next_block;
-+ SQUASHFS_I(i)->offset = next_offset;
-+ if (sblk->block_size > 4096)
-+ i->i_data.a_ops = &squashfs_aops;
-+ else
-+ i->i_data.a_ops = &squashfs_aops_4K;
-+
-+ TRACE("File inode %x:%x, start_block %x, "
-+ "block_list_start %llx, offset %x\n",
-+ SQUASHFS_INODE_BLK(inode), offset,
-+ inodep->start_block, next_block,
-+ next_offset);
-+ break;
-+ }
-+ case SQUASHFS_DIR_TYPE: {
-+ struct squashfs_dir_inode_header_2 *inodep = &id.dir;
-+ struct squashfs_dir_inode_header_2 *sinodep = &sid.dir;
-+
-+ if (msblk->swap) {
-+ if (!squashfs_get_cached_block(s, (char *)
-+ sinodep, block, offset,
-+ sizeof(*sinodep), &next_block,
-+ &next_offset))
-+ goto failed_read;
-+ SQUASHFS_SWAP_DIR_INODE_HEADER_2(inodep, sinodep);
-+ } else
-+ if (!squashfs_get_cached_block(s, (char *)
-+ inodep, block, offset,
-+ sizeof(*inodep), &next_block,
-+ &next_offset))
-+ goto failed_read;
-+
-+ if((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
-+ goto failed_read1;
-+
-+ i->i_size = inodep->file_size;
-+ i->i_op = &squashfs_dir_inode_ops_2;
-+ i->i_fop = &squashfs_dir_ops_2;
-+ i->i_mode |= S_IFDIR;
-+ i->i_mtime.tv_sec = inodep->mtime;
-+ i->i_atime.tv_sec = inodep->mtime;
-+ i->i_ctime.tv_sec = inodep->mtime;
-+ SQUASHFS_I(i)->start_block = inodep->start_block;
-+ SQUASHFS_I(i)->offset = inodep->offset;
-+ SQUASHFS_I(i)->u.s2.directory_index_count = 0;
-+ SQUASHFS_I(i)->u.s2.parent_inode = 0;
-+
-+ TRACE("Directory inode %x:%x, start_block %x, offset "
-+ "%x\n", SQUASHFS_INODE_BLK(inode),
-+ offset, inodep->start_block,
-+ inodep->offset);
-+ break;
-+ }
-+ case SQUASHFS_LDIR_TYPE: {
-+ struct squashfs_ldir_inode_header_2 *inodep = &id.ldir;
-+ struct squashfs_ldir_inode_header_2 *sinodep = &sid.ldir;
-+
-+ if (msblk->swap) {
-+ if (!squashfs_get_cached_block(s, (char *)
-+ sinodep, block, offset,
-+ sizeof(*sinodep), &next_block,
-+ &next_offset))
-+ goto failed_read;
-+ SQUASHFS_SWAP_LDIR_INODE_HEADER_2(inodep,
-+ sinodep);
-+ } else
-+ if (!squashfs_get_cached_block(s, (char *)
-+ inodep, block, offset,
-+ sizeof(*inodep), &next_block,
-+ &next_offset))
-+ goto failed_read;
-+
-+ if((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
-+ goto failed_read1;
-+
-+ i->i_size = inodep->file_size;
-+ i->i_op = &squashfs_dir_inode_ops_2;
-+ i->i_fop = &squashfs_dir_ops_2;
-+ i->i_mode |= S_IFDIR;
-+ i->i_mtime.tv_sec = inodep->mtime;
-+ i->i_atime.tv_sec = inodep->mtime;
-+ i->i_ctime.tv_sec = inodep->mtime;
-+ SQUASHFS_I(i)->start_block = inodep->start_block;
-+ SQUASHFS_I(i)->offset = inodep->offset;
-+ SQUASHFS_I(i)->u.s2.directory_index_start = next_block;
-+ SQUASHFS_I(i)->u.s2.directory_index_offset =
-+ next_offset;
-+ SQUASHFS_I(i)->u.s2.directory_index_count =
-+ inodep->i_count;
-+ SQUASHFS_I(i)->u.s2.parent_inode = 0;
-+
-+ TRACE("Long directory inode %x:%x, start_block %x, "
-+ "offset %x\n",
-+ SQUASHFS_INODE_BLK(inode), offset,
-+ inodep->start_block, inodep->offset);
-+ break;
-+ }
-+ case SQUASHFS_SYMLINK_TYPE: {
-+ struct squashfs_symlink_inode_header_2 *inodep =
-+ &id.symlink;
-+ struct squashfs_symlink_inode_header_2 *sinodep =
-+ &sid.symlink;
-+
-+ if (msblk->swap) {
-+ if (!squashfs_get_cached_block(s, (char *)
-+ sinodep, block, offset,
-+ sizeof(*sinodep), &next_block,
-+ &next_offset))
-+ goto failed_read;
-+ SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(inodep,
-+ sinodep);
-+ } else
-+ if (!squashfs_get_cached_block(s, (char *)
-+ inodep, block, offset,
-+ sizeof(*inodep), &next_block,
-+ &next_offset))
-+ goto failed_read;
-+
-+ if((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
-+ goto failed_read1;
-+
-+ i->i_size = inodep->symlink_size;
-+ i->i_op = &page_symlink_inode_operations;
-+ i->i_data.a_ops = &squashfs_symlink_aops;
-+ i->i_mode |= S_IFLNK;
-+ SQUASHFS_I(i)->start_block = next_block;
-+ SQUASHFS_I(i)->offset = next_offset;
-+
-+ TRACE("Symbolic link inode %x:%x, start_block %llx, "
-+ "offset %x\n",
-+ SQUASHFS_INODE_BLK(inode), offset,
-+ next_block, next_offset);
-+ break;
-+ }
-+ case SQUASHFS_BLKDEV_TYPE:
-+ case SQUASHFS_CHRDEV_TYPE: {
-+ struct squashfs_dev_inode_header_2 *inodep = &id.dev;
-+ struct squashfs_dev_inode_header_2 *sinodep = &sid.dev;
-+
-+ if (msblk->swap) {
-+ if (!squashfs_get_cached_block(s, (char *)
-+ sinodep, block, offset,
-+ sizeof(*sinodep), &next_block,
-+ &next_offset))
-+ goto failed_read;
-+ SQUASHFS_SWAP_DEV_INODE_HEADER_2(inodep, sinodep);
-+ } else
-+ if (!squashfs_get_cached_block(s, (char *)
-+ inodep, block, offset,
-+ sizeof(*inodep), &next_block,
-+ &next_offset))
-+ goto failed_read;
-+
-+ if ((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
-+ goto failed_read1;
-+
-+ i->i_mode |= (inodeb->inode_type ==
-+ SQUASHFS_CHRDEV_TYPE) ? S_IFCHR :
-+ S_IFBLK;
-+ init_special_inode(i, i->i_mode,
-+ old_decode_dev(inodep->rdev));
-+
-+ TRACE("Device inode %x:%x, rdev %x\n",
-+ SQUASHFS_INODE_BLK(inode), offset,
-+ inodep->rdev);
-+ break;
-+ }
-+ case SQUASHFS_FIFO_TYPE:
-+ case SQUASHFS_SOCKET_TYPE: {
-+ if ((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
-+ goto failed_read1;
-+
-+ i->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)
-+ ? S_IFIFO : S_IFSOCK;
-+ init_special_inode(i, i->i_mode, 0);
-+ break;
-+ }
-+ default:
-+ ERROR("Unknown inode type %d in squashfs_iget!\n",
-+ inodeb->inode_type);
-+ goto failed_read1;
-+ }
-+
-+ insert_inode_hash(i);
-+ return i;
-+
-+failed_read:
-+ ERROR("Unable to read inode [%x:%x]\n", block, offset);
-+
-+failed_read1:
-+ return NULL;
-+}
-+
-+
-+static int get_dir_index_using_offset(struct super_block *s, long long
-+ *next_block, unsigned int *next_offset,
-+ long long index_start,
-+ unsigned int index_offset, int i_count,
-+ long long f_pos)
-+{
-+ struct squashfs_sb_info *msblk = s->s_fs_info;
-+ struct squashfs_super_block *sblk = &msblk->sblk;
-+ int i, length = 0;
-+ struct squashfs_dir_index_2 index;
-+
-+ TRACE("Entered get_dir_index_using_offset, i_count %d, f_pos %d\n",
-+ i_count, (unsigned int) f_pos);
-+
-+ if (f_pos == 0)
-+ goto finish;
-+
-+ for (i = 0; i < i_count; i++) {
-+ if (msblk->swap) {
-+ struct squashfs_dir_index_2 sindex;
-+ squashfs_get_cached_block(s, (char *) &sindex,
-+ index_start, index_offset,
-+ sizeof(sindex), &index_start,
-+ &index_offset);
-+ SQUASHFS_SWAP_DIR_INDEX_2(&index, &sindex);
-+ } else
-+ squashfs_get_cached_block(s, (char *) &index,
-+ index_start, index_offset,
-+ sizeof(index), &index_start,
-+ &index_offset);
-+
-+ if (index.index > f_pos)
-+ break;
-+
-+ squashfs_get_cached_block(s, NULL, index_start, index_offset,
-+ index.size + 1, &index_start,
-+ &index_offset);
-+
-+ length = index.index;
-+ *next_block = index.start_block + sblk->directory_table_start;
-+ }
-+
-+ *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
-+
-+finish:
-+ return length;
-+}
-+
-+
-+static int get_dir_index_using_name(struct super_block *s, long long
-+ *next_block, unsigned int *next_offset,
-+ long long index_start,
-+ unsigned int index_offset, int i_count,
-+ const char *name, int size)
-+{
-+ struct squashfs_sb_info *msblk = s->s_fs_info;
-+ struct squashfs_super_block *sblk = &msblk->sblk;
-+ int i, length = 0;
-+ char buffer[sizeof(struct squashfs_dir_index_2) + SQUASHFS_NAME_LEN + 1];
-+ struct squashfs_dir_index_2 *index = (struct squashfs_dir_index_2 *) buffer;
-+ char str[SQUASHFS_NAME_LEN + 1];
-+
-+ TRACE("Entered get_dir_index_using_name, i_count %d\n", i_count);
-+
-+ strncpy(str, name, size);
-+ str[size] = '\0';
-+
-+ for (i = 0; i < i_count; i++) {
-+ if (msblk->swap) {
-+ struct squashfs_dir_index_2 sindex;
-+ squashfs_get_cached_block(s, (char *) &sindex,
-+ index_start, index_offset,
-+ sizeof(sindex), &index_start,
-+ &index_offset);
-+ SQUASHFS_SWAP_DIR_INDEX_2(index, &sindex);
-+ } else
-+ squashfs_get_cached_block(s, (char *) index,
-+ index_start, index_offset,
-+ sizeof(struct squashfs_dir_index_2),
-+ &index_start, &index_offset);
-+
-+ squashfs_get_cached_block(s, index->name, index_start,
-+ index_offset, index->size + 1,
-+ &index_start, &index_offset);
-+
-+ index->name[index->size + 1] = '\0';
-+
-+ if (strcmp(index->name, str) > 0)
-+ break;
-+
-+ length = index->index;
-+ *next_block = index->start_block + sblk->directory_table_start;
-+ }
-+
-+ *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
-+ return length;
-+}
-+
-+
-+static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir)
-+{
-+ struct inode *i = file->f_dentry->d_inode;
-+ struct squashfs_sb_info *msblk = i->i_sb->s_fs_info;
-+ struct squashfs_super_block *sblk = &msblk->sblk;
-+ long long next_block = SQUASHFS_I(i)->start_block +
-+ sblk->directory_table_start;
-+ int next_offset = SQUASHFS_I(i)->offset, length = 0, dirs_read = 0,
-+ dir_count;
-+ struct squashfs_dir_header_2 dirh;
-+ char buffer[sizeof(struct squashfs_dir_entry_2) + SQUASHFS_NAME_LEN + 1];
-+ struct squashfs_dir_entry_2 *dire = (struct squashfs_dir_entry_2 *) buffer;
-+
-+ TRACE("Entered squashfs_readdir_2 [%llx:%x]\n", next_block, next_offset);
-+
-+ length = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,
-+ SQUASHFS_I(i)->u.s2.directory_index_start,
-+ SQUASHFS_I(i)->u.s2.directory_index_offset,
-+ SQUASHFS_I(i)->u.s2.directory_index_count,
-+ file->f_pos);
-+
-+ while (length < i_size_read(i)) {
-+ /* read directory header */
-+ if (msblk->swap) {
-+ struct squashfs_dir_header_2 sdirh;
-+
-+ if (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,
-+ next_block, next_offset, sizeof(sdirh),
-+ &next_block, &next_offset))
-+ goto failed_read;
-+
-+ length += sizeof(sdirh);
-+ SQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);
-+ } else {
-+ if (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,
-+ next_block, next_offset, sizeof(dirh),
-+ &next_block, &next_offset))
-+ goto failed_read;
-+
-+ length += sizeof(dirh);
-+ }
-+
-+ dir_count = dirh.count + 1;
-+ while (dir_count--) {
-+ if (msblk->swap) {
-+ struct squashfs_dir_entry_2 sdire;
-+ if (!squashfs_get_cached_block(i->i_sb, (char *)
-+ &sdire, next_block, next_offset,
-+ sizeof(sdire), &next_block,
-+ &next_offset))
-+ goto failed_read;
-+
-+ length += sizeof(sdire);
-+ SQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);
-+ } else {
-+ if (!squashfs_get_cached_block(i->i_sb, (char *)
-+ dire, next_block, next_offset,
-+ sizeof(*dire), &next_block,
-+ &next_offset))
-+ goto failed_read;
-+
-+ length += sizeof(*dire);
-+ }
-+
-+ if (!squashfs_get_cached_block(i->i_sb, dire->name,
-+ next_block, next_offset,
-+ dire->size + 1, &next_block,
-+ &next_offset))
-+ goto failed_read;
-+
-+ length += dire->size + 1;
-+
-+ if (file->f_pos >= length)
-+ continue;
-+
-+ dire->name[dire->size + 1] = '\0';
-+
-+ TRACE("Calling filldir(%x, %s, %d, %d, %x:%x, %d)\n",
-+ (unsigned int) dirent, dire->name,
-+ dire->size + 1, (int) file->f_pos,
-+ dirh.start_block, dire->offset,
-+ squashfs_filetype_table[dire->type]);
-+
-+ if (filldir(dirent, dire->name, dire->size + 1,
-+ file->f_pos, SQUASHFS_MK_VFS_INODE(
-+ dirh.start_block, dire->offset),
-+ squashfs_filetype_table[dire->type])
-+ < 0) {
-+ TRACE("Filldir returned less than 0\n");
-+ goto finish;
-+ }
-+ file->f_pos = length;
-+ dirs_read++;
-+ }
-+ }
-+
-+finish:
-+ return dirs_read;
-+
-+failed_read:
-+ ERROR("Unable to read directory block [%llx:%x]\n", next_block,
-+ next_offset);
-+ return 0;
-+}
-+
-+
-+static struct dentry *squashfs_lookup_2(struct inode *i, struct dentry *dentry,
-+ struct nameidata *nd)
-+{
-+ const unsigned char *name = dentry->d_name.name;
-+ int len = dentry->d_name.len;
-+ struct inode *inode = NULL;
-+ struct squashfs_sb_info *msblk = i->i_sb->s_fs_info;
-+ struct squashfs_super_block *sblk = &msblk->sblk;
-+ long long next_block = SQUASHFS_I(i)->start_block +
-+ sblk->directory_table_start;
-+ int next_offset = SQUASHFS_I(i)->offset, length = 0,
-+ dir_count;
-+ struct squashfs_dir_header_2 dirh;
-+ char buffer[sizeof(struct squashfs_dir_entry_2) + SQUASHFS_NAME_LEN];
-+ struct squashfs_dir_entry_2 *dire = (struct squashfs_dir_entry_2 *) buffer;
-+ int sorted = sblk->s_major == 2 && sblk->s_minor >= 1;
-+
-+ TRACE("Entered squashfs_lookup [%llx:%x]\n", next_block, next_offset);
-+
-+ if (len > SQUASHFS_NAME_LEN)
-+ goto exit_loop;
-+
-+ length = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,
-+ SQUASHFS_I(i)->u.s2.directory_index_start,
-+ SQUASHFS_I(i)->u.s2.directory_index_offset,
-+ SQUASHFS_I(i)->u.s2.directory_index_count, name,
-+ len);
-+
-+ while (length < i_size_read(i)) {
-+ /* read directory header */
-+ if (msblk->swap) {
-+ struct squashfs_dir_header_2 sdirh;
-+ if (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,
-+ next_block, next_offset, sizeof(sdirh),
-+ &next_block, &next_offset))
-+ goto failed_read;
-+
-+ length += sizeof(sdirh);
-+ SQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);
-+ } else {
-+ if (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,
-+ next_block, next_offset, sizeof(dirh),
-+ &next_block, &next_offset))
-+ goto failed_read;
-+
-+ length += sizeof(dirh);
-+ }
-+
-+ dir_count = dirh.count + 1;
-+ while (dir_count--) {
-+ if (msblk->swap) {
-+ struct squashfs_dir_entry_2 sdire;
-+ if (!squashfs_get_cached_block(i->i_sb, (char *)
-+ &sdire, next_block,next_offset,
-+ sizeof(sdire), &next_block,
-+ &next_offset))
-+ goto failed_read;
-+
-+ length += sizeof(sdire);
-+ SQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);
-+ } else {
-+ if (!squashfs_get_cached_block(i->i_sb, (char *)
-+ dire, next_block,next_offset,
-+ sizeof(*dire), &next_block,
-+ &next_offset))
-+ goto failed_read;
-+
-+ length += sizeof(*dire);
-+ }
-+
-+ if (!squashfs_get_cached_block(i->i_sb, dire->name,
-+ next_block, next_offset, dire->size + 1,
-+ &next_block, &next_offset))
-+ goto failed_read;
-+
-+ length += dire->size + 1;
-+
-+ if (sorted && name[0] < dire->name[0])
-+ goto exit_loop;
-+
-+ if ((len == dire->size + 1) && !strncmp(name,
-+ dire->name, len)) {
-+ squashfs_inode_t ino =
-+ SQUASHFS_MKINODE(dirh.start_block,
-+ dire->offset);
-+
-+ TRACE("calling squashfs_iget for directory "
-+ "entry %s, inode %x:%x, %lld\n", name,
-+ dirh.start_block, dire->offset, ino);
-+
-+ inode = (msblk->iget)(i->i_sb, ino);
-+
-+ goto exit_loop;
-+ }
-+ }
-+ }
-+
-+exit_loop:
-+ d_add(dentry, inode);
-+ return ERR_PTR(0);
-+
-+failed_read:
-+ ERROR("Unable to read directory block [%llx:%x]\n", next_block,
-+ next_offset);
-+ goto exit_loop;
-+}
-+
-+
-+int squashfs_2_0_supported(struct squashfs_sb_info *msblk)
-+{
-+ struct squashfs_super_block *sblk = &msblk->sblk;
-+
-+ msblk->iget = squashfs_iget_2;
-+ msblk->read_fragment_index_table = read_fragment_index_table_2;
-+
-+ sblk->bytes_used = sblk->bytes_used_2;
-+ sblk->uid_start = sblk->uid_start_2;
-+ sblk->guid_start = sblk->guid_start_2;
-+ sblk->inode_table_start = sblk->inode_table_start_2;
-+ sblk->directory_table_start = sblk->directory_table_start_2;
-+ sblk->fragment_table_start = sblk->fragment_table_start_2;
-+
-+ return 1;
-+}
---- /dev/null
-+++ b/fs/squashfs/squashfs.h
-@@ -0,0 +1,86 @@
-+/*
-+ * Squashfs - a compressed read only filesystem for Linux
-+ *
-+ * Copyright (c) 2002, 2003, 2004, 2005, 2006
-+ * Phillip Lougher <phillip@lougher.org.uk>
-+ *
-+ * 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,
-+ * 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-+ *
-+ * squashfs.h
-+ */
-+
-+#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY
-+#undef CONFIG_SQUASHFS_1_0_COMPATIBILITY
-+#endif
-+
-+#ifdef SQUASHFS_TRACE
-+#define TRACE(s, args...) printk(KERN_NOTICE "SQUASHFS: "s, ## args)
-+#else
-+#define TRACE(s, args...) {}
-+#endif
-+
-+#define ERROR(s, args...) printk(KERN_ERR "SQUASHFS error: "s, ## args)
-+
-+#define SERROR(s, args...) do { \
-+ if (!silent) \
-+ printk(KERN_ERR "SQUASHFS error: "s, ## args);\
-+ } while(0)
-+
-+#define WARNING(s, args...) printk(KERN_WARNING "SQUASHFS: "s, ## args)
-+
-+static inline struct squashfs_inode_info *SQUASHFS_I(struct inode *inode)
-+{
-+ return list_entry(inode, struct squashfs_inode_info, vfs_inode);
-+}
-+
-+#if defined(CONFIG_SQUASHFS_1_0_COMPATIBILITY ) || defined(CONFIG_SQUASHFS_2_0_COMPATIBILITY)
-+#define SQSH_EXTERN
-+extern unsigned int squashfs_read_data(struct super_block *s, char *buffer,
-+ long long index, unsigned int length,
-+ long long *next_index);
-+extern int squashfs_get_cached_block(struct super_block *s, char *buffer,
-+ long long block, unsigned int offset,
-+ int length, long long *next_block,
-+ unsigned int *next_offset);
-+extern void release_cached_fragment(struct squashfs_sb_info *msblk, struct
-+ squashfs_fragment_cache *fragment);
-+extern struct squashfs_fragment_cache *get_cached_fragment(struct super_block
-+ *s, long long start_block,
-+ int length);
-+extern struct address_space_operations squashfs_symlink_aops;
-+extern struct address_space_operations squashfs_aops;
-+extern struct address_space_operations squashfs_aops_4K;
-+extern struct inode_operations squashfs_dir_inode_ops;
-+#else
-+#define SQSH_EXTERN static
-+#endif
-+
-+#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY
-+extern int squashfs_1_0_supported(struct squashfs_sb_info *msblk);
-+#else
-+static inline int squashfs_1_0_supported(struct squashfs_sb_info *msblk)
-+{
-+ return 0;
-+}
-+#endif
-+
-+#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY
-+extern int squashfs_2_0_supported(struct squashfs_sb_info *msblk);
-+#else
-+static inline int squashfs_2_0_supported(struct squashfs_sb_info *msblk)
-+{
-+ return 0;
-+}
-+#endif
---- a/include/linux/magic.h
-+++ b/include/linux/magic.h
-@@ -35,6 +35,9 @@
- #define REISER2FS_SUPER_MAGIC_STRING "ReIsEr2Fs"
- #define REISER2FS_JR_SUPER_MAGIC_STRING "ReIsEr3Fs"
-
-+#define SQUASHFS_MAGIC 0x73717368
-+#define SQUASHFS_MAGIC_SWAP 0x68737173
-+
- #define SMB_SUPER_MAGIC 0x517B
- #define USBDEVICE_SUPER_MAGIC 0x9fa2
-
---- /dev/null
-+++ b/include/linux/squashfs_fs.h
-@@ -0,0 +1,911 @@
-+#ifndef SQUASHFS_FS
-+#define SQUASHFS_FS
-+
-+/*
-+ * Squashfs
-+ *
-+ * Copyright (c) 2002, 2003, 2004, 2005, 2006
-+ * Phillip Lougher <phillip@lougher.org.uk>
-+ *
-+ * 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,
-+ * 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-+ *
-+ * squashfs_fs.h
-+ */
-+
-+#ifndef CONFIG_SQUASHFS_2_0_COMPATIBILITY
-+#define CONFIG_SQUASHFS_2_0_COMPATIBILITY
-+#endif
-+
-+#ifdef CONFIG_SQUASHFS_VMALLOC
-+#define SQUASHFS_ALLOC(a) vmalloc(a)
-+#define SQUASHFS_FREE(a) vfree(a)
-+#else
-+#define SQUASHFS_ALLOC(a) kmalloc(a, GFP_KERNEL)
-+#define SQUASHFS_FREE(a) kfree(a)
-+#endif
-+#define SQUASHFS_CACHED_FRAGMENTS CONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE
-+#define SQUASHFS_MAJOR 3
-+#define SQUASHFS_MINOR 0
-+#define SQUASHFS_START 0
-+
-+/* size of metadata (inode and directory) blocks */
-+#define SQUASHFS_METADATA_SIZE 8192
-+#define SQUASHFS_METADATA_LOG 13
-+
-+/* default size of data blocks */
-+#define SQUASHFS_FILE_SIZE 65536
-+#define SQUASHFS_FILE_LOG 16
-+
-+#define SQUASHFS_FILE_MAX_SIZE 65536
-+
-+/* Max number of uids and gids */
-+#define SQUASHFS_UIDS 256
-+#define SQUASHFS_GUIDS 255
-+
-+/* Max length of filename (not 255) */
-+#define SQUASHFS_NAME_LEN 256
-+
-+#define SQUASHFS_INVALID ((long long) 0xffffffffffff)
-+#define SQUASHFS_INVALID_FRAG ((unsigned int) 0xffffffff)
-+#define SQUASHFS_INVALID_BLK ((long long) -1)
-+#define SQUASHFS_USED_BLK ((long long) -2)
-+
-+/* Filesystem flags */
-+#define SQUASHFS_NOI 0
-+#define SQUASHFS_NOD 1
-+#define SQUASHFS_CHECK 2
-+#define SQUASHFS_NOF 3
-+#define SQUASHFS_NO_FRAG 4
-+#define SQUASHFS_ALWAYS_FRAG 5
-+#define SQUASHFS_DUPLICATE 6
-+
-+#define SQUASHFS_BIT(flag, bit) ((flag >> bit) & 1)
-+
-+#define SQUASHFS_UNCOMPRESSED_INODES(flags) SQUASHFS_BIT(flags, \
-+ SQUASHFS_NOI)
-+
-+#define SQUASHFS_UNCOMPRESSED_DATA(flags) SQUASHFS_BIT(flags, \
-+ SQUASHFS_NOD)
-+
-+#define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
-+ SQUASHFS_NOF)
-+
-+#define SQUASHFS_NO_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
-+ SQUASHFS_NO_FRAG)
-+
-+#define SQUASHFS_ALWAYS_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
-+ SQUASHFS_ALWAYS_FRAG)
-+
-+#define SQUASHFS_DUPLICATES(flags) SQUASHFS_BIT(flags, \
-+ SQUASHFS_DUPLICATE)
-+
-+#define SQUASHFS_CHECK_DATA(flags) SQUASHFS_BIT(flags, \
-+ SQUASHFS_CHECK)
-+
-+#define SQUASHFS_MKFLAGS(noi, nod, check_data, nof, no_frag, always_frag, \
-+ duplicate_checking) (noi | (nod << 1) | (check_data << 2) \
-+ | (nof << 3) | (no_frag << 4) | (always_frag << 5) | \
-+ (duplicate_checking << 6))
-+
-+/* Max number of types and file types */
-+#define SQUASHFS_DIR_TYPE 1
-+#define SQUASHFS_FILE_TYPE 2
-+#define SQUASHFS_SYMLINK_TYPE 3
-+#define SQUASHFS_BLKDEV_TYPE 4
-+#define SQUASHFS_CHRDEV_TYPE 5
-+#define SQUASHFS_FIFO_TYPE 6
-+#define SQUASHFS_SOCKET_TYPE 7
-+#define SQUASHFS_LDIR_TYPE 8
-+#define SQUASHFS_LREG_TYPE 9
-+
-+/* 1.0 filesystem type definitions */
-+#define SQUASHFS_TYPES 5
-+#define SQUASHFS_IPC_TYPE 0
-+
-+/* Flag whether block is compressed or uncompressed, bit is set if block is
-+ * uncompressed */
-+#define SQUASHFS_COMPRESSED_BIT (1 << 15)
-+
-+#define SQUASHFS_COMPRESSED_SIZE(B) (((B) & ~SQUASHFS_COMPRESSED_BIT) ? \
-+ (B) & ~SQUASHFS_COMPRESSED_BIT : SQUASHFS_COMPRESSED_BIT)
-+
-+#define SQUASHFS_COMPRESSED(B) (!((B) & SQUASHFS_COMPRESSED_BIT))
-+
-+#define SQUASHFS_COMPRESSED_BIT_BLOCK (1 << 24)
-+
-+#define SQUASHFS_COMPRESSED_SIZE_BLOCK(B) (((B) & \
-+ ~SQUASHFS_COMPRESSED_BIT_BLOCK) ? (B) & \
-+ ~SQUASHFS_COMPRESSED_BIT_BLOCK : SQUASHFS_COMPRESSED_BIT_BLOCK)
-+
-+#define SQUASHFS_COMPRESSED_BLOCK(B) (!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))
-+
-+/*
-+ * Inode number ops. Inodes consist of a compressed block number, and an
-+ * uncompressed offset within that block
-+ */
-+#define SQUASHFS_INODE_BLK(a) ((unsigned int) ((a) >> 16))
-+
-+#define SQUASHFS_INODE_OFFSET(a) ((unsigned int) ((a) & 0xffff))
-+
-+#define SQUASHFS_MKINODE(A, B) ((squashfs_inode_t)(((squashfs_inode_t) (A)\
-+ << 16) + (B)))
-+
-+/* Compute 32 bit VFS inode number from squashfs inode number */
-+#define SQUASHFS_MK_VFS_INODE(a, b) ((unsigned int) (((a) << 8) + \
-+ ((b) >> 2) + 1))
-+/* XXX */
-+
-+/* Translate between VFS mode and squashfs mode */
-+#define SQUASHFS_MODE(a) ((a) & 0xfff)
-+
-+/* fragment and fragment table defines */
-+#define SQUASHFS_FRAGMENT_BYTES(A) (A * sizeof(struct squashfs_fragment_entry))
-+
-+#define SQUASHFS_FRAGMENT_INDEX(A) (SQUASHFS_FRAGMENT_BYTES(A) / \
-+ SQUASHFS_METADATA_SIZE)
-+
-+#define SQUASHFS_FRAGMENT_INDEX_OFFSET(A) (SQUASHFS_FRAGMENT_BYTES(A) % \
-+ SQUASHFS_METADATA_SIZE)
-+
-+#define SQUASHFS_FRAGMENT_INDEXES(A) ((SQUASHFS_FRAGMENT_BYTES(A) + \
-+ SQUASHFS_METADATA_SIZE - 1) / \
-+ SQUASHFS_METADATA_SIZE)
-+
-+#define SQUASHFS_FRAGMENT_INDEX_BYTES(A) (SQUASHFS_FRAGMENT_INDEXES(A) *\
-+ sizeof(long long))
-+
-+/* cached data constants for filesystem */
-+#define SQUASHFS_CACHED_BLKS 8
-+
-+#define SQUASHFS_MAX_FILE_SIZE_LOG 64
-+
-+#define SQUASHFS_MAX_FILE_SIZE ((long long) 1 << \
-+ (SQUASHFS_MAX_FILE_SIZE_LOG - 2))
-+
-+#define SQUASHFS_MARKER_BYTE 0xff
-+
-+/* meta index cache */
-+#define SQUASHFS_META_INDEXES (SQUASHFS_METADATA_SIZE / sizeof(unsigned int))
-+#define SQUASHFS_META_ENTRIES 31
-+#define SQUASHFS_META_NUMBER 8
-+#define SQUASHFS_SLOTS 4
-+
-+#include <linux/magic.h>
-+
-+struct meta_entry {
-+ long long data_block;
-+ unsigned int index_block;
-+ unsigned short offset;
-+ unsigned short pad;
-+};
-+
-+struct meta_index {
-+ unsigned int inode_number;
-+ unsigned int offset;
-+ unsigned short entries;
-+ unsigned short skip;
-+ unsigned short locked;
-+ unsigned short pad;
-+ struct meta_entry meta_entry[SQUASHFS_META_ENTRIES];
-+};
-+
-+
-+/*
-+ * definitions for structures on disk
-+ */
-+
-+typedef long long squashfs_block_t;
-+typedef long long squashfs_inode_t;
-+
-+struct squashfs_super_block {
-+ unsigned int s_magic;
-+ unsigned int inodes;
-+ unsigned int bytes_used_2;
-+ unsigned int uid_start_2;
-+ unsigned int guid_start_2;
-+ unsigned int inode_table_start_2;
-+ unsigned int directory_table_start_2;
-+ unsigned int s_major:16;
-+ unsigned int s_minor:16;
-+ unsigned int block_size_1:16;
-+ unsigned int block_log:16;
-+ unsigned int flags:8;
-+ unsigned int no_uids:8;
-+ unsigned int no_guids:8;
-+ unsigned int mkfs_time /* time of filesystem creation */;
-+ squashfs_inode_t root_inode;
-+ unsigned int block_size;
-+ unsigned int fragments;
-+ unsigned int fragment_table_start_2;
-+ long long bytes_used;
-+ long long uid_start;
-+ long long guid_start;
-+ long long inode_table_start;
-+ long long directory_table_start;
-+ long long fragment_table_start;
-+ long long unused;
-+} __attribute__ ((packed));
-+
-+struct squashfs_dir_index {
-+ unsigned int index;
-+ unsigned int start_block;
-+ unsigned char size;
-+ unsigned char name[0];
-+} __attribute__ ((packed));
-+
-+#define SQUASHFS_BASE_INODE_HEADER \
-+ unsigned int inode_type:4; \
-+ unsigned int mode:12; \
-+ unsigned int uid:8; \
-+ unsigned int guid:8; \
-+ unsigned int mtime; \
-+ unsigned int inode_number;
-+
-+struct squashfs_base_inode_header {
-+ SQUASHFS_BASE_INODE_HEADER;
-+} __attribute__ ((packed));
-+
-+struct squashfs_ipc_inode_header {
-+ SQUASHFS_BASE_INODE_HEADER;
-+ unsigned int nlink;
-+} __attribute__ ((packed));
-+
-+struct squashfs_dev_inode_header {
-+ SQUASHFS_BASE_INODE_HEADER;
-+ unsigned int nlink;
-+ unsigned short rdev;
-+} __attribute__ ((packed));
-+
-+struct squashfs_symlink_inode_header {
-+ SQUASHFS_BASE_INODE_HEADER;
-+ unsigned int nlink;
-+ unsigned short symlink_size;
-+ char symlink[0];
-+} __attribute__ ((packed));
-+
-+struct squashfs_reg_inode_header {
-+ SQUASHFS_BASE_INODE_HEADER;
-+ squashfs_block_t start_block;
-+ unsigned int fragment;
-+ unsigned int offset;
-+ unsigned int file_size;
-+ unsigned short block_list[0];
-+} __attribute__ ((packed));
-+
-+struct squashfs_lreg_inode_header {
-+ SQUASHFS_BASE_INODE_HEADER;
-+ unsigned int nlink;
-+ squashfs_block_t start_block;
-+ unsigned int fragment;
-+ unsigned int offset;
-+ long long file_size;
-+ unsigned short block_list[0];
-+} __attribute__ ((packed));
-+
-+struct squashfs_dir_inode_header {
-+ SQUASHFS_BASE_INODE_HEADER;
-+ unsigned int nlink;
-+ unsigned int file_size:19;
-+ unsigned int offset:13;
-+ unsigned int start_block;
-+ unsigned int parent_inode;
-+} __attribute__ ((packed));
-+
-+struct squashfs_ldir_inode_header {
-+ SQUASHFS_BASE_INODE_HEADER;
-+ unsigned int nlink;
-+ unsigned int file_size:27;
-+ unsigned int offset:13;
-+ unsigned int start_block;
-+ unsigned int i_count:16;
-+ unsigned int parent_inode;
-+ struct squashfs_dir_index index[0];
-+} __attribute__ ((packed));
-+
-+union squashfs_inode_header {
-+ struct squashfs_base_inode_header base;
-+ struct squashfs_dev_inode_header dev;
-+ struct squashfs_symlink_inode_header symlink;
-+ struct squashfs_reg_inode_header reg;
-+ struct squashfs_lreg_inode_header lreg;
-+ struct squashfs_dir_inode_header dir;
-+ struct squashfs_ldir_inode_header ldir;
-+ struct squashfs_ipc_inode_header ipc;
-+};
-+
-+struct squashfs_dir_entry {
-+ unsigned int offset:13;
-+ unsigned int type:3;
-+ unsigned int size:8;
-+ int inode_number:16;
-+ char name[0];
-+} __attribute__ ((packed));
-+
-+struct squashfs_dir_header {
-+ unsigned int count:8;
-+ unsigned int start_block;
-+ unsigned int inode_number;
-+} __attribute__ ((packed));
-+
-+struct squashfs_fragment_entry {
-+ long long start_block;
-+ unsigned int size;
-+ unsigned int unused;
-+} __attribute__ ((packed));
-+
-+extern int squashfs_uncompress_block(void *d, int dstlen, void *s, int srclen);
-+extern int squashfs_uncompress_init(void);
-+extern int squashfs_uncompress_exit(void);
-+
-+/*
-+ * macros to convert each packed bitfield structure from little endian to big
-+ * endian and vice versa. These are needed when creating or using a filesystem
-+ * on a machine with different byte ordering to the target architecture.
-+ *
-+ */
-+
-+#define SQUASHFS_SWAP_START \
-+ int bits;\
-+ int b_pos;\
-+ unsigned long long val;\
-+ unsigned char *s;\
-+ unsigned char *d;
-+
-+#define SQUASHFS_SWAP_SUPER_BLOCK(s, d) {\
-+ SQUASHFS_SWAP_START\
-+ SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_super_block));\
-+ SQUASHFS_SWAP((s)->s_magic, d, 0, 32);\
-+ SQUASHFS_SWAP((s)->inodes, d, 32, 32);\
-+ SQUASHFS_SWAP((s)->bytes_used_2, d, 64, 32);\
-+ SQUASHFS_SWAP((s)->uid_start_2, d, 96, 32);\
-+ SQUASHFS_SWAP((s)->guid_start_2, d, 128, 32);\
-+ SQUASHFS_SWAP((s)->inode_table_start_2, d, 160, 32);\
-+ SQUASHFS_SWAP((s)->directory_table_start_2, d, 192, 32);\
-+ SQUASHFS_SWAP((s)->s_major, d, 224, 16);\
-+ SQUASHFS_SWAP((s)->s_minor, d, 240, 16);\
-+ SQUASHFS_SWAP((s)->block_size_1, d, 256, 16);\
-+ SQUASHFS_SWAP((s)->block_log, d, 272, 16);\
-+ SQUASHFS_SWAP((s)->flags, d, 288, 8);\
-+ SQUASHFS_SWAP((s)->no_uids, d, 296, 8);\
-+ SQUASHFS_SWAP((s)->no_guids, d, 304, 8);\
-+ SQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\
-+ SQUASHFS_SWAP((s)->root_inode, d, 344, 64);\
-+ SQUASHFS_SWAP((s)->block_size, d, 408, 32);\
-+ SQUASHFS_SWAP((s)->fragments, d, 440, 32);\
-+ SQUASHFS_SWAP((s)->fragment_table_start_2, d, 472, 32);\
-+ SQUASHFS_SWAP((s)->bytes_used, d, 504, 64);\
-+ SQUASHFS_SWAP((s)->uid_start, d, 568, 64);\
-+ SQUASHFS_SWAP((s)->guid_start, d, 632, 64);\
-+ SQUASHFS_SWAP((s)->inode_table_start, d, 696, 64);\
-+ SQUASHFS_SWAP((s)->directory_table_start, d, 760, 64);\
-+ SQUASHFS_SWAP((s)->fragment_table_start, d, 824, 64);\
-+ SQUASHFS_SWAP((s)->unused, d, 888, 64);\
-+}
-+
-+#define SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\
-+ SQUASHFS_MEMSET(s, d, n);\
-+ SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
-+ SQUASHFS_SWAP((s)->mode, d, 4, 12);\
-+ SQUASHFS_SWAP((s)->uid, d, 16, 8);\
-+ SQUASHFS_SWAP((s)->guid, d, 24, 8);\
-+ SQUASHFS_SWAP((s)->mtime, d, 32, 32);\
-+ SQUASHFS_SWAP((s)->inode_number, d, 64, 32);
-+
-+#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, n) {\
-+ SQUASHFS_SWAP_START\
-+ SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\
-+}
-+
-+#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) {\
-+ SQUASHFS_SWAP_START\
-+ SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
-+ sizeof(struct squashfs_ipc_inode_header))\
-+ SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
-+}
-+
-+#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) {\
-+ SQUASHFS_SWAP_START\
-+ SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
-+ sizeof(struct squashfs_dev_inode_header)); \
-+ SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
-+ SQUASHFS_SWAP((s)->rdev, d, 128, 16);\
-+}
-+
-+#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) {\
-+ SQUASHFS_SWAP_START\
-+ SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
-+ sizeof(struct squashfs_symlink_inode_header));\
-+ SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
-+ SQUASHFS_SWAP((s)->symlink_size, d, 128, 16);\
-+}
-+
-+#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) {\
-+ SQUASHFS_SWAP_START\
-+ SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
-+ sizeof(struct squashfs_reg_inode_header));\
-+ SQUASHFS_SWAP((s)->start_block, d, 96, 64);\
-+ SQUASHFS_SWAP((s)->fragment, d, 160, 32);\
-+ SQUASHFS_SWAP((s)->offset, d, 192, 32);\
-+ SQUASHFS_SWAP((s)->file_size, d, 224, 32);\
-+}
-+
-+#define SQUASHFS_SWAP_LREG_INODE_HEADER(s, d) {\
-+ SQUASHFS_SWAP_START\
-+ SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
-+ sizeof(struct squashfs_lreg_inode_header));\
-+ SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
-+ SQUASHFS_SWAP((s)->start_block, d, 128, 64);\
-+ SQUASHFS_SWAP((s)->fragment, d, 192, 32);\
-+ SQUASHFS_SWAP((s)->offset, d, 224, 32);\
-+ SQUASHFS_SWAP((s)->file_size, d, 256, 64);\
-+}
-+
-+#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) {\
-+ SQUASHFS_SWAP_START\
-+ SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
-+ sizeof(struct squashfs_dir_inode_header));\
-+ SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
-+ SQUASHFS_SWAP((s)->file_size, d, 128, 19);\
-+ SQUASHFS_SWAP((s)->offset, d, 147, 13);\
-+ SQUASHFS_SWAP((s)->start_block, d, 160, 32);\
-+ SQUASHFS_SWAP((s)->parent_inode, d, 192, 32);\
-+}
-+
-+#define SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d) {\
-+ SQUASHFS_SWAP_START\
-+ SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
-+ sizeof(struct squashfs_ldir_inode_header));\
-+ SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
-+ SQUASHFS_SWAP((s)->file_size, d, 128, 27);\
-+ SQUASHFS_SWAP((s)->offset, d, 155, 13);\
-+ SQUASHFS_SWAP((s)->start_block, d, 168, 32);\
-+ SQUASHFS_SWAP((s)->i_count, d, 200, 16);\
-+ SQUASHFS_SWAP((s)->parent_inode, d, 216, 32);\
-+}
-+
-+#define SQUASHFS_SWAP_DIR_INDEX(s, d) {\
-+ SQUASHFS_SWAP_START\
-+ SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index));\
-+ SQUASHFS_SWAP((s)->index, d, 0, 32);\
-+ SQUASHFS_SWAP((s)->start_block, d, 32, 32);\
-+ SQUASHFS_SWAP((s)->size, d, 64, 8);\
-+}
-+
-+#define SQUASHFS_SWAP_DIR_HEADER(s, d) {\
-+ SQUASHFS_SWAP_START\
-+ SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header));\
-+ SQUASHFS_SWAP((s)->count, d, 0, 8);\
-+ SQUASHFS_SWAP((s)->start_block, d, 8, 32);\
-+ SQUASHFS_SWAP((s)->inode_number, d, 40, 32);\
-+}
-+
-+#define SQUASHFS_SWAP_DIR_ENTRY(s, d) {\
-+ SQUASHFS_SWAP_START\
-+ SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry));\
-+ SQUASHFS_SWAP((s)->offset, d, 0, 13);\
-+ SQUASHFS_SWAP((s)->type, d, 13, 3);\
-+ SQUASHFS_SWAP((s)->size, d, 16, 8);\
-+ SQUASHFS_SWAP((s)->inode_number, d, 24, 16);\
-+}
-+
-+#define SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d) {\
-+ SQUASHFS_SWAP_START\
-+ SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry));\
-+ SQUASHFS_SWAP((s)->start_block, d, 0, 64);\
-+ SQUASHFS_SWAP((s)->size, d, 64, 32);\
-+}
-+
-+#define SQUASHFS_SWAP_SHORTS(s, d, n) {\
-+ int entry;\
-+ int bit_position;\
-+ SQUASHFS_SWAP_START\
-+ SQUASHFS_MEMSET(s, d, n * 2);\
-+ for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
-+ 16)\
-+ SQUASHFS_SWAP(s[entry], d, bit_position, 16);\
-+}
-+
-+#define SQUASHFS_SWAP_INTS(s, d, n) {\
-+ int entry;\
-+ int bit_position;\
-+ SQUASHFS_SWAP_START\
-+ SQUASHFS_MEMSET(s, d, n * 4);\
-+ for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
-+ 32)\
-+ SQUASHFS_SWAP(s[entry], d, bit_position, 32);\
-+}
-+
-+#define SQUASHFS_SWAP_LONG_LONGS(s, d, n) {\
-+ int entry;\
-+ int bit_position;\
-+ SQUASHFS_SWAP_START\
-+ SQUASHFS_MEMSET(s, d, n * 8);\
-+ for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
-+ 64)\
-+ SQUASHFS_SWAP(s[entry], d, bit_position, 64);\
-+}
-+
-+#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\
-+ int entry;\
-+ int bit_position;\
-+ SQUASHFS_SWAP_START\
-+ SQUASHFS_MEMSET(s, d, n * bits / 8);\
-+ for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
-+ bits)\
-+ SQUASHFS_SWAP(s[entry], d, bit_position, bits);\
-+}
-+
-+#define SQUASHFS_SWAP_FRAGMENT_INDEXES(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)
-+
-+#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY
-+
-+struct squashfs_base_inode_header_1 {
-+ unsigned int inode_type:4;
-+ unsigned int mode:12; /* protection */
-+ unsigned int uid:4; /* index into uid table */
-+ unsigned int guid:4; /* index into guid table */
-+} __attribute__ ((packed));
-+
-+struct squashfs_ipc_inode_header_1 {
-+ unsigned int inode_type:4;
-+ unsigned int mode:12; /* protection */
-+ unsigned int uid:4; /* index into uid table */
-+ unsigned int guid:4; /* index into guid table */
-+ unsigned int type:4;
-+ unsigned int offset:4;
-+} __attribute__ ((packed));
-+
-+struct squashfs_dev_inode_header_1 {
-+ unsigned int inode_type:4;
-+ unsigned int mode:12; /* protection */
-+ unsigned int uid:4; /* index into uid table */
-+ unsigned int guid:4; /* index into guid table */
-+ unsigned short rdev;
-+} __attribute__ ((packed));
-+
-+struct squashfs_symlink_inode_header_1 {
-+ unsigned int inode_type:4;
-+ unsigned int mode:12; /* protection */
-+ unsigned int uid:4; /* index into uid table */
-+ unsigned int guid:4; /* index into guid table */
-+ unsigned short symlink_size;
-+ char symlink[0];
-+} __attribute__ ((packed));
-+
-+struct squashfs_reg_inode_header_1 {
-+ unsigned int inode_type:4;
-+ unsigned int mode:12; /* protection */
-+ unsigned int uid:4; /* index into uid table */
-+ unsigned int guid:4; /* index into guid table */
-+ unsigned int mtime;
-+ unsigned int start_block;
-+ unsigned int file_size:32;
-+ unsigned short block_list[0];
-+} __attribute__ ((packed));
-+
-+struct squashfs_dir_inode_header_1 {
-+ unsigned int inode_type:4;
-+ unsigned int mode:12; /* protection */
-+ unsigned int uid:4; /* index into uid table */
-+ unsigned int guid:4; /* index into guid table */
-+ unsigned int file_size:19;
-+ unsigned int offset:13;
-+ unsigned int mtime;
-+ unsigned int start_block:24;
-+} __attribute__ ((packed));
-+
-+#define SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n) \
-+ SQUASHFS_MEMSET(s, d, n);\
-+ SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
-+ SQUASHFS_SWAP((s)->mode, d, 4, 12);\
-+ SQUASHFS_SWAP((s)->uid, d, 16, 4);\
-+ SQUASHFS_SWAP((s)->guid, d, 20, 4);
-+
-+#define SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, n) {\
-+ SQUASHFS_SWAP_START\
-+ SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n)\
-+}
-+
-+#define SQUASHFS_SWAP_IPC_INODE_HEADER_1(s, d) {\
-+ SQUASHFS_SWAP_START\
-+ SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
-+ sizeof(struct squashfs_ipc_inode_header_1));\
-+ SQUASHFS_SWAP((s)->type, d, 24, 4);\
-+ SQUASHFS_SWAP((s)->offset, d, 28, 4);\
-+}
-+
-+#define SQUASHFS_SWAP_DEV_INODE_HEADER_1(s, d) {\
-+ SQUASHFS_SWAP_START\
-+ SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
-+ sizeof(struct squashfs_dev_inode_header_1));\
-+ SQUASHFS_SWAP((s)->rdev, d, 24, 16);\
-+}
-+
-+#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(s, d) {\
-+ SQUASHFS_SWAP_START\
-+ SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
-+ sizeof(struct squashfs_symlink_inode_header_1));\
-+ SQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\
-+}
-+
-+#define SQUASHFS_SWAP_REG_INODE_HEADER_1(s, d) {\
-+ SQUASHFS_SWAP_START\
-+ SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
-+ sizeof(struct squashfs_reg_inode_header_1));\
-+ SQUASHFS_SWAP((s)->mtime, d, 24, 32);\
-+ SQUASHFS_SWAP((s)->start_block, d, 56, 32);\
-+ SQUASHFS_SWAP((s)->file_size, d, 88, 32);\
-+}
-+
-+#define SQUASHFS_SWAP_DIR_INODE_HEADER_1(s, d) {\
-+ SQUASHFS_SWAP_START\
-+ SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
-+ sizeof(struct squashfs_dir_inode_header_1));\
-+ SQUASHFS_SWAP((s)->file_size, d, 24, 19);\
-+ SQUASHFS_SWAP((s)->offset, d, 43, 13);\
-+ SQUASHFS_SWAP((s)->mtime, d, 56, 32);\
-+ SQUASHFS_SWAP((s)->start_block, d, 88, 24);\
-+}
-+
-+#endif
-+
-+#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY
-+
-+struct squashfs_dir_index_2 {
-+ unsigned int index:27;
-+ unsigned int start_block:29;
-+ unsigned char size;
-+ unsigned char name[0];
-+} __attribute__ ((packed));
-+
-+struct squashfs_base_inode_header_2 {
-+ unsigned int inode_type:4;
-+ unsigned int mode:12; /* protection */
-+ unsigned int uid:8; /* index into uid table */
-+ unsigned int guid:8; /* index into guid table */
-+} __attribute__ ((packed));
-+
-+struct squashfs_ipc_inode_header_2 {
-+ unsigned int inode_type:4;
-+ unsigned int mode:12; /* protection */
-+ unsigned int uid:8; /* index into uid table */
-+ unsigned int guid:8; /* index into guid table */
-+} __attribute__ ((packed));
-+
-+struct squashfs_dev_inode_header_2 {
-+ unsigned int inode_type:4;
-+ unsigned int mode:12; /* protection */
-+ unsigned int uid:8; /* index into uid table */
-+ unsigned int guid:8; /* index into guid table */
-+ unsigned short rdev;
-+} __attribute__ ((packed));
-+
-+struct squashfs_symlink_inode_header_2 {
-+ unsigned int inode_type:4;
-+ unsigned int mode:12; /* protection */
-+ unsigned int uid:8; /* index into uid table */
-+ unsigned int guid:8; /* index into guid table */
-+ unsigned short symlink_size;
-+ char symlink[0];
-+} __attribute__ ((packed));
-+
-+struct squashfs_reg_inode_header_2 {
-+ unsigned int inode_type:4;
-+ unsigned int mode:12; /* protection */
-+ unsigned int uid:8; /* index into uid table */
-+ unsigned int guid:8; /* index into guid table */
-+ unsigned int mtime;
-+ unsigned int start_block;
-+ unsigned int fragment;
-+ unsigned int offset;
-+ unsigned int file_size:32;
-+ unsigned short block_list[0];
-+} __attribute__ ((packed));
-+
-+struct squashfs_dir_inode_header_2 {
-+ unsigned int inode_type:4;
-+ unsigned int mode:12; /* protection */
-+ unsigned int uid:8; /* index into uid table */
-+ unsigned int guid:8; /* index into guid table */
-+ unsigned int file_size:19;
-+ unsigned int offset:13;
-+ unsigned int mtime;
-+ unsigned int start_block:24;
-+} __attribute__ ((packed));
-+
-+struct squashfs_ldir_inode_header_2 {
-+ unsigned int inode_type:4;
-+ unsigned int mode:12; /* protection */
-+ unsigned int uid:8; /* index into uid table */
-+ unsigned int guid:8; /* index into guid table */
-+ unsigned int file_size:27;
-+ unsigned int offset:13;
-+ unsigned int mtime;
-+ unsigned int start_block:24;
-+ unsigned int i_count:16;
-+ struct squashfs_dir_index_2 index[0];
-+} __attribute__ ((packed));
-+
-+union squashfs_inode_header_2 {
-+ struct squashfs_base_inode_header_2 base;
-+ struct squashfs_dev_inode_header_2 dev;
-+ struct squashfs_symlink_inode_header_2 symlink;
-+ struct squashfs_reg_inode_header_2 reg;
-+ struct squashfs_dir_inode_header_2 dir;
-+ struct squashfs_ldir_inode_header_2 ldir;
-+ struct squashfs_ipc_inode_header_2 ipc;
-+};
-+
-+struct squashfs_dir_header_2 {
-+ unsigned int count:8;
-+ unsigned int start_block:24;
-+} __attribute__ ((packed));
-+
-+struct squashfs_dir_entry_2 {
-+ unsigned int offset:13;
-+ unsigned int type:3;
-+ unsigned int size:8;
-+ char name[0];
-+} __attribute__ ((packed));
-+
-+struct squashfs_fragment_entry_2 {
-+ unsigned int start_block;
-+ unsigned int size;
-+} __attribute__ ((packed));
-+
-+#define SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\
-+ SQUASHFS_MEMSET(s, d, n);\
-+ SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
-+ SQUASHFS_SWAP((s)->mode, d, 4, 12);\
-+ SQUASHFS_SWAP((s)->uid, d, 16, 8);\
-+ SQUASHFS_SWAP((s)->guid, d, 24, 8);\
-+
-+#define SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, n) {\
-+ SQUASHFS_SWAP_START\
-+ SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\
-+}
-+
-+#define SQUASHFS_SWAP_IPC_INODE_HEADER_2(s, d) \
-+ SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, sizeof(struct squashfs_ipc_inode_header_2))
-+
-+#define SQUASHFS_SWAP_DEV_INODE_HEADER_2(s, d) {\
-+ SQUASHFS_SWAP_START\
-+ SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
-+ sizeof(struct squashfs_dev_inode_header_2)); \
-+ SQUASHFS_SWAP((s)->rdev, d, 32, 16);\
-+}
-+
-+#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(s, d) {\
-+ SQUASHFS_SWAP_START\
-+ SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
-+ sizeof(struct squashfs_symlink_inode_header_2));\
-+ SQUASHFS_SWAP((s)->symlink_size, d, 32, 16);\
-+}
-+
-+#define SQUASHFS_SWAP_REG_INODE_HEADER_2(s, d) {\
-+ SQUASHFS_SWAP_START\
-+ SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
-+ sizeof(struct squashfs_reg_inode_header_2));\
-+ SQUASHFS_SWAP((s)->mtime, d, 32, 32);\
-+ SQUASHFS_SWAP((s)->start_block, d, 64, 32);\
-+ SQUASHFS_SWAP((s)->fragment, d, 96, 32);\
-+ SQUASHFS_SWAP((s)->offset, d, 128, 32);\
-+ SQUASHFS_SWAP((s)->file_size, d, 160, 32);\
-+}
-+
-+#define SQUASHFS_SWAP_DIR_INODE_HEADER_2(s, d) {\
-+ SQUASHFS_SWAP_START\
-+ SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
-+ sizeof(struct squashfs_dir_inode_header_2));\
-+ SQUASHFS_SWAP((s)->file_size, d, 32, 19);\
-+ SQUASHFS_SWAP((s)->offset, d, 51, 13);\
-+ SQUASHFS_SWAP((s)->mtime, d, 64, 32);\
-+ SQUASHFS_SWAP((s)->start_block, d, 96, 24);\
-+}
-+
-+#define SQUASHFS_SWAP_LDIR_INODE_HEADER_2(s, d) {\
-+ SQUASHFS_SWAP_START\
-+ SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
-+ sizeof(struct squashfs_ldir_inode_header_2));\
-+ SQUASHFS_SWAP((s)->file_size, d, 32, 27);\
-+ SQUASHFS_SWAP((s)->offset, d, 59, 13);\
-+ SQUASHFS_SWAP((s)->mtime, d, 72, 32);\
-+ SQUASHFS_SWAP((s)->start_block, d, 104, 24);\
-+ SQUASHFS_SWAP((s)->i_count, d, 128, 16);\
-+}
-+
-+#define SQUASHFS_SWAP_DIR_INDEX_2(s, d) {\
-+ SQUASHFS_SWAP_START\
-+ SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index_2));\
-+ SQUASHFS_SWAP((s)->index, d, 0, 27);\
-+ SQUASHFS_SWAP((s)->start_block, d, 27, 29);\
-+ SQUASHFS_SWAP((s)->size, d, 56, 8);\
-+}
-+#define SQUASHFS_SWAP_DIR_HEADER_2(s, d) {\
-+ SQUASHFS_SWAP_START\
-+ SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header_2));\
-+ SQUASHFS_SWAP((s)->count, d, 0, 8);\
-+ SQUASHFS_SWAP((s)->start_block, d, 8, 24);\
-+}
-+
-+#define SQUASHFS_SWAP_DIR_ENTRY_2(s, d) {\
-+ SQUASHFS_SWAP_START\
-+ SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry_2));\
-+ SQUASHFS_SWAP((s)->offset, d, 0, 13);\
-+ SQUASHFS_SWAP((s)->type, d, 13, 3);\
-+ SQUASHFS_SWAP((s)->size, d, 16, 8);\
-+}
-+
-+#define SQUASHFS_SWAP_FRAGMENT_ENTRY_2(s, d) {\
-+ SQUASHFS_SWAP_START\
-+ SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry_2));\
-+ SQUASHFS_SWAP((s)->start_block, d, 0, 32);\
-+ SQUASHFS_SWAP((s)->size, d, 32, 32);\
-+}
-+
-+#define SQUASHFS_SWAP_FRAGMENT_INDEXES_2(s, d, n) SQUASHFS_SWAP_INTS(s, d, n)
-+
-+/* fragment and fragment table defines */
-+#define SQUASHFS_FRAGMENT_BYTES_2(A) (A * sizeof(struct squashfs_fragment_entry_2))
-+
-+#define SQUASHFS_FRAGMENT_INDEX_2(A) (SQUASHFS_FRAGMENT_BYTES_2(A) / \
-+ SQUASHFS_METADATA_SIZE)
-+
-+#define SQUASHFS_FRAGMENT_INDEX_OFFSET_2(A) (SQUASHFS_FRAGMENT_BYTES_2(A) % \
-+ SQUASHFS_METADATA_SIZE)
-+
-+#define SQUASHFS_FRAGMENT_INDEXES_2(A) ((SQUASHFS_FRAGMENT_BYTES_2(A) + \
-+ SQUASHFS_METADATA_SIZE - 1) / \
-+ SQUASHFS_METADATA_SIZE)
-+
-+#define SQUASHFS_FRAGMENT_INDEX_BYTES_2(A) (SQUASHFS_FRAGMENT_INDEXES_2(A) *\
-+ sizeof(int))
-+
-+#endif
-+
-+#ifdef __KERNEL__
-+
-+/*
-+ * macros used to swap each structure entry, taking into account
-+ * bitfields and different bitfield placing conventions on differing
-+ * architectures
-+ */
-+
-+#include <asm/byteorder.h>
-+
-+#ifdef __BIG_ENDIAN
-+ /* convert from little endian to big endian */
-+#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \
-+ tbits, b_pos)
-+#else
-+ /* convert from big endian to little endian */
-+#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \
-+ tbits, 64 - tbits - b_pos)
-+#endif
-+
-+#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\
-+ b_pos = pos % 8;\
-+ val = 0;\
-+ s = (unsigned char *)p + (pos / 8);\
-+ d = ((unsigned char *) &val) + 7;\
-+ for(bits = 0; bits < (tbits + b_pos); bits += 8) \
-+ *d-- = *s++;\
-+ value = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\
-+}
-+
-+#define SQUASHFS_MEMSET(s, d, n) memset(s, 0, n);
-+
-+#endif
-+#endif
---- /dev/null
-+++ b/include/linux/squashfs_fs_i.h
-@@ -0,0 +1,45 @@
-+#ifndef SQUASHFS_FS_I
-+#define SQUASHFS_FS_I
-+/*
-+ * Squashfs
-+ *
-+ * Copyright (c) 2002, 2003, 2004, 2005, 2006
-+ * Phillip Lougher <phillip@lougher.org.uk>
-+ *
-+ * 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,
-+ * 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-+ *
-+ * squashfs_fs_i.h
-+ */
-+
-+struct squashfs_inode_info {
-+ long long start_block;
-+ unsigned int offset;
-+ union {
-+ struct {
-+ long long fragment_start_block;
-+ unsigned int fragment_size;
-+ unsigned int fragment_offset;
-+ long long block_list_start;
-+ } s1;
-+ struct {
-+ long long directory_index_start;
-+ unsigned int directory_index_offset;
-+ unsigned int directory_index_count;
-+ unsigned int parent_inode;
-+ } s2;
-+ } u;
-+ struct inode vfs_inode;
-+};
-+#endif
---- /dev/null
-+++ b/include/linux/squashfs_fs_sb.h
-@@ -0,0 +1,74 @@
-+#ifndef SQUASHFS_FS_SB
-+#define SQUASHFS_FS_SB
-+/*
-+ * Squashfs
-+ *
-+ * Copyright (c) 2002, 2003, 2004, 2005, 2006
-+ * Phillip Lougher <phillip@lougher.org.uk>
-+ *
-+ * 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,
-+ * 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-+ *
-+ * squashfs_fs_sb.h
-+ */
-+
-+#include <linux/squashfs_fs.h>
-+
-+struct squashfs_cache {
-+ long long block;
-+ int length;
-+ long long next_index;
-+ char *data;
-+};
-+
-+struct squashfs_fragment_cache {
-+ long long block;
-+ int length;
-+ unsigned int locked;
-+ char *data;
-+};
-+
-+struct squashfs_sb_info {
-+ struct squashfs_super_block sblk;
-+ int devblksize;
-+ int devblksize_log2;
-+ int swap;
-+ struct squashfs_cache *block_cache;
-+ struct squashfs_fragment_cache *fragment;
-+ int next_cache;
-+ int next_fragment;
-+ int next_meta_index;
-+ unsigned int *uid;
-+ unsigned int *guid;
-+ long long *fragment_index;
-+ unsigned int *fragment_index_2;
-+ unsigned int read_size;
-+ char *read_data;
-+ char *read_page;
-+ struct semaphore read_data_mutex;
-+ struct semaphore read_page_mutex;
-+ struct semaphore block_cache_mutex;
-+ struct semaphore fragment_mutex;
-+ struct semaphore meta_index_mutex;
-+ wait_queue_head_t waitq;
-+ wait_queue_head_t fragment_wait_queue;
-+ struct meta_index *meta_index;
-+ struct inode *(*iget)(struct super_block *s, squashfs_inode_t \
-+ inode);
-+ long long (*read_blocklist)(struct inode *inode, int \
-+ index, int readahead_blks, char *block_list, \
-+ unsigned short **block_p, unsigned int *bsize);
-+ int (*read_fragment_index_table)(struct super_block *s);
-+};
-+#endif
---- a/init/do_mounts_rd.c
-+++ b/init/do_mounts_rd.c
-@@ -5,6 +5,7 @@
- #include <linux/ext2_fs.h>
- #include <linux/romfs_fs.h>
- #include <linux/cramfs_fs.h>
-+#include <linux/squashfs_fs.h>
- #include <linux/initrd.h>
- #include <linux/string.h>
-
-@@ -39,6 +40,7 @@
- * numbers could not be found.
- *
- * We currently check for the following magic numbers:
-+ * squashfs
- * minix
- * ext2
- * romfs
-@@ -53,6 +55,7 @@
- struct ext2_super_block *ext2sb;
- struct romfs_super_block *romfsb;
- struct cramfs_super *cramfsb;
-+ struct squashfs_super_block *squashfsb;
- int nblocks = -1;
- unsigned char *buf;
-
-@@ -64,6 +67,7 @@
- ext2sb = (struct ext2_super_block *) buf;
- romfsb = (struct romfs_super_block *) buf;
- cramfsb = (struct cramfs_super *) buf;
-+ squashfsb = (struct squashfs_super_block *) buf;
- memset(buf, 0xe5, size);
-
- /*
-@@ -101,6 +105,15 @@
- goto done;
- }
-
-+ /* squashfs is at block zero too */
-+ if (squashfsb->s_magic == SQUASHFS_MAGIC) {
-+ printk(KERN_NOTICE
-+ "RAMDISK: squashfs filesystem found at block %d\n",
-+ start_block);
-+ nblocks = (squashfsb->bytes_used+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;
-+ goto done;
-+ }
-+
- /*
- * Read block 1 to test for minix and ext2 superblock
- */
+++ /dev/null
---- /dev/null
-+++ b/include/linux/LzmaDecode.h
-@@ -0,0 +1,100 @@
-+/*
-+ LzmaDecode.h
-+ LZMA Decoder interface
-+
-+ LZMA SDK 4.05 Copyright (c) 1999-2004 Igor Pavlov (2004-08-25)
-+ http://www.7-zip.org/
-+
-+ LZMA SDK is licensed under two licenses:
-+ 1) GNU Lesser General Public License (GNU LGPL)
-+ 2) Common Public License (CPL)
-+ It means that you can select one of these two licenses and
-+ follow rules of that license.
-+
-+ SPECIAL EXCEPTION:
-+ Igor Pavlov, as the author of this code, expressly permits you to
-+ statically or dynamically link your code (or bind by name) to the
-+ interfaces of this file without subjecting your linked code to the
-+ terms of the CPL or GNU LGPL. Any modifications or additions
-+ to this file, however, are subject to the LGPL or CPL terms.
-+*/
-+
-+#ifndef __LZMADECODE_H
-+#define __LZMADECODE_H
-+
-+/* #define _LZMA_IN_CB */
-+/* Use callback for input data */
-+
-+/* #define _LZMA_OUT_READ */
-+/* Use read function for output data */
-+
-+/* #define _LZMA_PROB32 */
-+/* It can increase speed on some 32-bit CPUs,
-+ but memory usage will be doubled in that case */
-+
-+/* #define _LZMA_LOC_OPT */
-+/* Enable local speed optimizations inside code */
-+
-+#ifndef UInt32
-+#ifdef _LZMA_UINT32_IS_ULONG
-+#define UInt32 unsigned long
-+#else
-+#define UInt32 unsigned int
-+#endif
-+#endif
-+
-+#ifdef _LZMA_PROB32
-+#define CProb UInt32
-+#else
-+#define CProb unsigned short
-+#endif
-+
-+#define LZMA_RESULT_OK 0
-+#define LZMA_RESULT_DATA_ERROR 1
-+#define LZMA_RESULT_NOT_ENOUGH_MEM 2
-+
-+#ifdef _LZMA_IN_CB
-+typedef struct _ILzmaInCallback
-+{
-+ int (*Read)(void *object, unsigned char **buffer, UInt32 *bufferSize);
-+} ILzmaInCallback;
-+#endif
-+
-+#define LZMA_BASE_SIZE 1846
-+#define LZMA_LIT_SIZE 768
-+
-+/*
-+bufferSize = (LZMA_BASE_SIZE + (LZMA_LIT_SIZE << (lc + lp)))* sizeof(CProb)
-+bufferSize += 100 in case of _LZMA_OUT_READ
-+by default CProb is unsigned short,
-+but if specify _LZMA_PROB_32, CProb will be UInt32(unsigned int)
-+*/
-+
-+#ifdef _LZMA_OUT_READ
-+int LzmaDecoderInit(
-+ unsigned char *buffer, UInt32 bufferSize,
-+ int lc, int lp, int pb,
-+ unsigned char *dictionary, UInt32 dictionarySize,
-+ #ifdef _LZMA_IN_CB
-+ ILzmaInCallback *inCallback
-+ #else
-+ unsigned char *inStream, UInt32 inSize
-+ #endif
-+);
-+#endif
-+
-+int LzmaDecode(
-+ unsigned char *buffer,
-+ #ifndef _LZMA_OUT_READ
-+ UInt32 bufferSize,
-+ int lc, int lp, int pb,
-+ #ifdef _LZMA_IN_CB
-+ ILzmaInCallback *inCallback,
-+ #else
-+ unsigned char *inStream, UInt32 inSize,
-+ #endif
-+ #endif
-+ unsigned char *outStream, UInt32 outSize,
-+ UInt32 *outSizeProcessed);
-+
-+#endif
---- /dev/null
-+++ b/lib/LzmaDecode.c
-@@ -0,0 +1,663 @@
-+/*
-+ LzmaDecode.c
-+ LZMA Decoder
-+
-+ LZMA SDK 4.05 Copyright (c) 1999-2004 Igor Pavlov (2004-08-25)
-+ http://www.7-zip.org/
-+
-+ LZMA SDK is licensed under two licenses:
-+ 1) GNU Lesser General Public License (GNU LGPL)
-+ 2) Common Public License (CPL)
-+ It means that you can select one of these two licenses and
-+ follow rules of that license.
-+
-+ SPECIAL EXCEPTION:
-+ Igor Pavlov, as the author of this code, expressly permits you to
-+ statically or dynamically link your code (or bind by name) to the
-+ interfaces of this file without subjecting your linked code to the
-+ terms of the CPL or GNU LGPL. Any modifications or additions
-+ to this file, however, are subject to the LGPL or CPL terms.
-+*/
-+
-+#include <linux/LzmaDecode.h>
-+
-+#ifndef Byte
-+#define Byte unsigned char
-+#endif
-+
-+#define kNumTopBits 24
-+#define kTopValue ((UInt32)1 << kNumTopBits)
-+
-+#define kNumBitModelTotalBits 11
-+#define kBitModelTotal (1 << kNumBitModelTotalBits)
-+#define kNumMoveBits 5
-+
-+typedef struct _CRangeDecoder
-+{
-+ Byte *Buffer;
-+ Byte *BufferLim;
-+ UInt32 Range;
-+ UInt32 Code;
-+ #ifdef _LZMA_IN_CB
-+ ILzmaInCallback *InCallback;
-+ int Result;
-+ #endif
-+ int ExtraBytes;
-+} CRangeDecoder;
-+
-+Byte RangeDecoderReadByte(CRangeDecoder *rd)
-+{
-+ if (rd->Buffer == rd->BufferLim)
-+ {
-+ #ifdef _LZMA_IN_CB
-+ UInt32 size;
-+ rd->Result = rd->InCallback->Read(rd->InCallback, &rd->Buffer, &size);
-+ rd->BufferLim = rd->Buffer + size;
-+ if (size == 0)
-+ #endif
-+ {
-+ rd->ExtraBytes = 1;
-+ return 0xFF;
-+ }
-+ }
-+ return (*rd->Buffer++);
-+}
-+
-+/* #define ReadByte (*rd->Buffer++) */
-+#define ReadByte (RangeDecoderReadByte(rd))
-+
-+void RangeDecoderInit(CRangeDecoder *rd,
-+ #ifdef _LZMA_IN_CB
-+ ILzmaInCallback *inCallback
-+ #else
-+ Byte *stream, UInt32 bufferSize
-+ #endif
-+ )
-+{
-+ int i;
-+ #ifdef _LZMA_IN_CB
-+ rd->InCallback = inCallback;
-+ rd->Buffer = rd->BufferLim = 0;
-+ #else
-+ rd->Buffer = stream;
-+ rd->BufferLim = stream + bufferSize;
-+ #endif
-+ rd->ExtraBytes = 0;
-+ rd->Code = 0;
-+ rd->Range = (0xFFFFFFFF);
-+ for(i = 0; i < 5; i++)
-+ rd->Code = (rd->Code << 8) | ReadByte;
-+}
-+
-+#define RC_INIT_VAR UInt32 range = rd->Range; UInt32 code = rd->Code;
-+#define RC_FLUSH_VAR rd->Range = range; rd->Code = code;
-+#define RC_NORMALIZE if (range < kTopValue) { range <<= 8; code = (code << 8) | ReadByte; }
-+
-+UInt32 RangeDecoderDecodeDirectBits(CRangeDecoder *rd, int numTotalBits)
-+{
-+ RC_INIT_VAR
-+ UInt32 result = 0;
-+ int i;
-+ for (i = numTotalBits; i > 0; i--)
-+ {
-+ /* UInt32 t; */
-+ range >>= 1;
-+
-+ result <<= 1;
-+ if (code >= range)
-+ {
-+ code -= range;
-+ result |= 1;
-+ }
-+ /*
-+ t = (code - range) >> 31;
-+ t &= 1;
-+ code -= range & (t - 1);
-+ result = (result + result) | (1 - t);
-+ */
-+ RC_NORMALIZE
-+ }
-+ RC_FLUSH_VAR
-+ return result;
-+}
-+
-+int RangeDecoderBitDecode(CProb *prob, CRangeDecoder *rd)
-+{
-+ UInt32 bound = (rd->Range >> kNumBitModelTotalBits) * *prob;
-+ if (rd->Code < bound)
-+ {
-+ rd->Range = bound;
-+ *prob += (kBitModelTotal - *prob) >> kNumMoveBits;
-+ if (rd->Range < kTopValue)
-+ {
-+ rd->Code = (rd->Code << 8) | ReadByte;
-+ rd->Range <<= 8;
-+ }
-+ return 0;
-+ }
-+ else
-+ {
-+ rd->Range -= bound;
-+ rd->Code -= bound;
-+ *prob -= (*prob) >> kNumMoveBits;
-+ if (rd->Range < kTopValue)
-+ {
-+ rd->Code = (rd->Code << 8) | ReadByte;
-+ rd->Range <<= 8;
-+ }
-+ return 1;
-+ }
-+}
-+
-+#define RC_GET_BIT2(prob, mi, A0, A1) \
-+ UInt32 bound = (range >> kNumBitModelTotalBits) * *prob; \
-+ if (code < bound) \
-+ { A0; range = bound; *prob += (kBitModelTotal - *prob) >> kNumMoveBits; mi <<= 1; } \
-+ else \
-+ { A1; range -= bound; code -= bound; *prob -= (*prob) >> kNumMoveBits; mi = (mi + mi) + 1; } \
-+ RC_NORMALIZE
-+
-+#define RC_GET_BIT(prob, mi) RC_GET_BIT2(prob, mi, ; , ;)
-+
-+int RangeDecoderBitTreeDecode(CProb *probs, int numLevels, CRangeDecoder *rd)
-+{
-+ int mi = 1;
-+ int i;
-+ #ifdef _LZMA_LOC_OPT
-+ RC_INIT_VAR
-+ #endif
-+ for(i = numLevels; i > 0; i--)
-+ {
-+ #ifdef _LZMA_LOC_OPT
-+ CProb *prob = probs + mi;
-+ RC_GET_BIT(prob, mi)
-+ #else
-+ mi = (mi + mi) + RangeDecoderBitDecode(probs + mi, rd);
-+ #endif
-+ }
-+ #ifdef _LZMA_LOC_OPT
-+ RC_FLUSH_VAR
-+ #endif
-+ return mi - (1 << numLevels);
-+}
-+
-+int RangeDecoderReverseBitTreeDecode(CProb *probs, int numLevels, CRangeDecoder *rd)
-+{
-+ int mi = 1;
-+ int i;
-+ int symbol = 0;
-+ #ifdef _LZMA_LOC_OPT
-+ RC_INIT_VAR
-+ #endif
-+ for(i = 0; i < numLevels; i++)
-+ {
-+ #ifdef _LZMA_LOC_OPT
-+ CProb *prob = probs + mi;
-+ RC_GET_BIT2(prob, mi, ; , symbol |= (1 << i))
-+ #else
-+ int bit = RangeDecoderBitDecode(probs + mi, rd);
-+ mi = mi + mi + bit;
-+ symbol |= (bit << i);
-+ #endif
-+ }
-+ #ifdef _LZMA_LOC_OPT
-+ RC_FLUSH_VAR
-+ #endif
-+ return symbol;
-+}
-+
-+Byte LzmaLiteralDecode(CProb *probs, CRangeDecoder *rd)
-+{
-+ int symbol = 1;
-+ #ifdef _LZMA_LOC_OPT
-+ RC_INIT_VAR
-+ #endif
-+ do
-+ {
-+ #ifdef _LZMA_LOC_OPT
-+ CProb *prob = probs + symbol;
-+ RC_GET_BIT(prob, symbol)
-+ #else
-+ symbol = (symbol + symbol) | RangeDecoderBitDecode(probs + symbol, rd);
-+ #endif
-+ }
-+ while (symbol < 0x100);
-+ #ifdef _LZMA_LOC_OPT
-+ RC_FLUSH_VAR
-+ #endif
-+ return symbol;
-+}
-+
-+Byte LzmaLiteralDecodeMatch(CProb *probs, CRangeDecoder *rd, Byte matchByte)
-+{
-+ int symbol = 1;
-+ #ifdef _LZMA_LOC_OPT
-+ RC_INIT_VAR
-+ #endif
-+ do
-+ {
-+ int bit;
-+ int matchBit = (matchByte >> 7) & 1;
-+ matchByte <<= 1;
-+ #ifdef _LZMA_LOC_OPT
-+ {
-+ CProb *prob = probs + ((1 + matchBit) << 8) + symbol;
-+ RC_GET_BIT2(prob, symbol, bit = 0, bit = 1)
-+ }
-+ #else
-+ bit = RangeDecoderBitDecode(probs + ((1 + matchBit) << 8) + symbol, rd);
-+ symbol = (symbol << 1) | bit;
-+ #endif
-+ if (matchBit != bit)
-+ {
-+ while (symbol < 0x100)
-+ {
-+ #ifdef _LZMA_LOC_OPT
-+ CProb *prob = probs + symbol;
-+ RC_GET_BIT(prob, symbol)
-+ #else
-+ symbol = (symbol + symbol) | RangeDecoderBitDecode(probs + symbol, rd);
-+ #endif
-+ }
-+ break;
-+ }
-+ }
-+ while (symbol < 0x100);
-+ #ifdef _LZMA_LOC_OPT
-+ RC_FLUSH_VAR
-+ #endif
-+ return symbol;
-+}
-+
-+#define kNumPosBitsMax 4
-+#define kNumPosStatesMax (1 << kNumPosBitsMax)
-+
-+#define kLenNumLowBits 3
-+#define kLenNumLowSymbols (1 << kLenNumLowBits)
-+#define kLenNumMidBits 3
-+#define kLenNumMidSymbols (1 << kLenNumMidBits)
-+#define kLenNumHighBits 8
-+#define kLenNumHighSymbols (1 << kLenNumHighBits)
-+
-+#define LenChoice 0
-+#define LenChoice2 (LenChoice + 1)
-+#define LenLow (LenChoice2 + 1)
-+#define LenMid (LenLow + (kNumPosStatesMax << kLenNumLowBits))
-+#define LenHigh (LenMid + (kNumPosStatesMax << kLenNumMidBits))
-+#define kNumLenProbs (LenHigh + kLenNumHighSymbols)
-+
-+int LzmaLenDecode(CProb *p, CRangeDecoder *rd, int posState)
-+{
-+ if(RangeDecoderBitDecode(p + LenChoice, rd) == 0)
-+ return RangeDecoderBitTreeDecode(p + LenLow +
-+ (posState << kLenNumLowBits), kLenNumLowBits, rd);
-+ if(RangeDecoderBitDecode(p + LenChoice2, rd) == 0)
-+ return kLenNumLowSymbols + RangeDecoderBitTreeDecode(p + LenMid +
-+ (posState << kLenNumMidBits), kLenNumMidBits, rd);
-+ return kLenNumLowSymbols + kLenNumMidSymbols +
-+ RangeDecoderBitTreeDecode(p + LenHigh, kLenNumHighBits, rd);
-+}
-+
-+#define kNumStates 12
-+
-+#define kStartPosModelIndex 4
-+#define kEndPosModelIndex 14
-+#define kNumFullDistances (1 << (kEndPosModelIndex >> 1))
-+
-+#define kNumPosSlotBits 6
-+#define kNumLenToPosStates 4
-+
-+#define kNumAlignBits 4
-+#define kAlignTableSize (1 << kNumAlignBits)
-+
-+#define kMatchMinLen 2
-+
-+#define IsMatch 0
-+#define IsRep (IsMatch + (kNumStates << kNumPosBitsMax))
-+#define IsRepG0 (IsRep + kNumStates)
-+#define IsRepG1 (IsRepG0 + kNumStates)
-+#define IsRepG2 (IsRepG1 + kNumStates)
-+#define IsRep0Long (IsRepG2 + kNumStates)
-+#define PosSlot (IsRep0Long + (kNumStates << kNumPosBitsMax))
-+#define SpecPos (PosSlot + (kNumLenToPosStates << kNumPosSlotBits))
-+#define Align (SpecPos + kNumFullDistances - kEndPosModelIndex)
-+#define LenCoder (Align + kAlignTableSize)
-+#define RepLenCoder (LenCoder + kNumLenProbs)
-+#define Literal (RepLenCoder + kNumLenProbs)
-+
-+#if Literal != LZMA_BASE_SIZE
-+StopCompilingDueBUG
-+#endif
-+
-+#ifdef _LZMA_OUT_READ
-+
-+typedef struct _LzmaVarState
-+{
-+ CRangeDecoder RangeDecoder;
-+ Byte *Dictionary;
-+ UInt32 DictionarySize;
-+ UInt32 DictionaryPos;
-+ UInt32 GlobalPos;
-+ UInt32 Reps[4];
-+ int lc;
-+ int lp;
-+ int pb;
-+ int State;
-+ int PreviousIsMatch;
-+ int RemainLen;
-+} LzmaVarState;
-+
-+int LzmaDecoderInit(
-+ unsigned char *buffer, UInt32 bufferSize,
-+ int lc, int lp, int pb,
-+ unsigned char *dictionary, UInt32 dictionarySize,
-+ #ifdef _LZMA_IN_CB
-+ ILzmaInCallback *inCallback
-+ #else
-+ unsigned char *inStream, UInt32 inSize
-+ #endif
-+ )
-+{
-+ LzmaVarState *vs = (LzmaVarState *)buffer;
-+ CProb *p = (CProb *)(buffer + sizeof(LzmaVarState));
-+ UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + lp));
-+ UInt32 i;
-+ if (bufferSize < numProbs * sizeof(CProb) + sizeof(LzmaVarState))
-+ return LZMA_RESULT_NOT_ENOUGH_MEM;
-+ vs->Dictionary = dictionary;
-+ vs->DictionarySize = dictionarySize;
-+ vs->DictionaryPos = 0;
-+ vs->GlobalPos = 0;
-+ vs->Reps[0] = vs->Reps[1] = vs->Reps[2] = vs->Reps[3] = 1;
-+ vs->lc = lc;
-+ vs->lp = lp;
-+ vs->pb = pb;
-+ vs->State = 0;
-+ vs->PreviousIsMatch = 0;
-+ vs->RemainLen = 0;
-+ dictionary[dictionarySize - 1] = 0;
-+ for (i = 0; i < numProbs; i++)
-+ p[i] = kBitModelTotal >> 1;
-+ RangeDecoderInit(&vs->RangeDecoder,
-+ #ifdef _LZMA_IN_CB
-+ inCallback
-+ #else
-+ inStream, inSize
-+ #endif
-+ );
-+ return LZMA_RESULT_OK;
-+}
-+
-+int LzmaDecode(unsigned char *buffer,
-+ unsigned char *outStream, UInt32 outSize,
-+ UInt32 *outSizeProcessed)
-+{
-+ LzmaVarState *vs = (LzmaVarState *)buffer;
-+ CProb *p = (CProb *)(buffer + sizeof(LzmaVarState));
-+ CRangeDecoder rd = vs->RangeDecoder;
-+ int state = vs->State;
-+ int previousIsMatch = vs->PreviousIsMatch;
-+ Byte previousByte;
-+ UInt32 rep0 = vs->Reps[0], rep1 = vs->Reps[1], rep2 = vs->Reps[2], rep3 = vs->Reps[3];
-+ UInt32 nowPos = 0;
-+ UInt32 posStateMask = (1 << (vs->pb)) - 1;
-+ UInt32 literalPosMask = (1 << (vs->lp)) - 1;
-+ int lc = vs->lc;
-+ int len = vs->RemainLen;
-+ UInt32 globalPos = vs->GlobalPos;
-+
-+ Byte *dictionary = vs->Dictionary;
-+ UInt32 dictionarySize = vs->DictionarySize;
-+ UInt32 dictionaryPos = vs->DictionaryPos;
-+
-+ if (len == -1)
-+ {
-+ *outSizeProcessed = 0;
-+ return LZMA_RESULT_OK;
-+ }
-+
-+ while(len > 0 && nowPos < outSize)
-+ {
-+ UInt32 pos = dictionaryPos - rep0;
-+ if (pos >= dictionarySize)
-+ pos += dictionarySize;
-+ outStream[nowPos++] = dictionary[dictionaryPos] = dictionary[pos];
-+ if (++dictionaryPos == dictionarySize)
-+ dictionaryPos = 0;
-+ len--;
-+ }
-+ if (dictionaryPos == 0)
-+ previousByte = dictionary[dictionarySize - 1];
-+ else
-+ previousByte = dictionary[dictionaryPos - 1];
-+#else
-+
-+int LzmaDecode(
-+ Byte *buffer, UInt32 bufferSize,
-+ int lc, int lp, int pb,
-+ #ifdef _LZMA_IN_CB
-+ ILzmaInCallback *inCallback,
-+ #else
-+ unsigned char *inStream, UInt32 inSize,
-+ #endif
-+ unsigned char *outStream, UInt32 outSize,
-+ UInt32 *outSizeProcessed)
-+{
-+ UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + lp));
-+ CProb *p = (CProb *)buffer;
-+ CRangeDecoder rd;
-+ UInt32 i;
-+ int state = 0;
-+ int previousIsMatch = 0;
-+ Byte previousByte = 0;
-+ UInt32 rep0 = 1, rep1 = 1, rep2 = 1, rep3 = 1;
-+ UInt32 nowPos = 0;
-+ UInt32 posStateMask = (1 << pb) - 1;
-+ UInt32 literalPosMask = (1 << lp) - 1;
-+ int len = 0;
-+ if (bufferSize < numProbs * sizeof(CProb))
-+ return LZMA_RESULT_NOT_ENOUGH_MEM;
-+ for (i = 0; i < numProbs; i++)
-+ p[i] = kBitModelTotal >> 1;
-+ RangeDecoderInit(&rd,
-+ #ifdef _LZMA_IN_CB
-+ inCallback
-+ #else
-+ inStream, inSize
-+ #endif
-+ );
-+#endif
-+
-+ *outSizeProcessed = 0;
-+ while(nowPos < outSize)
-+ {
-+ int posState = (int)(
-+ (nowPos
-+ #ifdef _LZMA_OUT_READ
-+ + globalPos
-+ #endif
-+ )
-+ & posStateMask);
-+ #ifdef _LZMA_IN_CB
-+ if (rd.Result != LZMA_RESULT_OK)
-+ return rd.Result;
-+ #endif
-+ if (rd.ExtraBytes != 0)
-+ return LZMA_RESULT_DATA_ERROR;
-+ if (RangeDecoderBitDecode(p + IsMatch + (state << kNumPosBitsMax) + posState, &rd) == 0)
-+ {
-+ CProb *probs = p + Literal + (LZMA_LIT_SIZE *
-+ (((
-+ (nowPos
-+ #ifdef _LZMA_OUT_READ
-+ + globalPos
-+ #endif
-+ )
-+ & literalPosMask) << lc) + (previousByte >> (8 - lc))));
-+
-+ if (state < 4) state = 0;
-+ else if (state < 10) state -= 3;
-+ else state -= 6;
-+ if (previousIsMatch)
-+ {
-+ Byte matchByte;
-+ #ifdef _LZMA_OUT_READ
-+ UInt32 pos = dictionaryPos - rep0;
-+ if (pos >= dictionarySize)
-+ pos += dictionarySize;
-+ matchByte = dictionary[pos];
-+ #else
-+ matchByte = outStream[nowPos - rep0];
-+ #endif
-+ previousByte = LzmaLiteralDecodeMatch(probs, &rd, matchByte);
-+ previousIsMatch = 0;
-+ }
-+ else
-+ previousByte = LzmaLiteralDecode(probs, &rd);
-+ outStream[nowPos++] = previousByte;
-+ #ifdef _LZMA_OUT_READ
-+ dictionary[dictionaryPos] = previousByte;
-+ if (++dictionaryPos == dictionarySize)
-+ dictionaryPos = 0;
-+ #endif
-+ }
-+ else
-+ {
-+ previousIsMatch = 1;
-+ if (RangeDecoderBitDecode(p + IsRep + state, &rd) == 1)
-+ {
-+ if (RangeDecoderBitDecode(p + IsRepG0 + state, &rd) == 0)
-+ {
-+ if (RangeDecoderBitDecode(p + IsRep0Long + (state << kNumPosBitsMax) + posState, &rd) == 0)
-+ {
-+ #ifdef _LZMA_OUT_READ
-+ UInt32 pos;
-+ #endif
-+ if (
-+ (nowPos
-+ #ifdef _LZMA_OUT_READ
-+ + globalPos
-+ #endif
-+ )
-+ == 0)
-+ return LZMA_RESULT_DATA_ERROR;
-+ state = state < 7 ? 9 : 11;
-+ #ifdef _LZMA_OUT_READ
-+ pos = dictionaryPos - rep0;
-+ if (pos >= dictionarySize)
-+ pos += dictionarySize;
-+ previousByte = dictionary[pos];
-+ dictionary[dictionaryPos] = previousByte;
-+ if (++dictionaryPos == dictionarySize)
-+ dictionaryPos = 0;
-+ #else
-+ previousByte = outStream[nowPos - rep0];
-+ #endif
-+ outStream[nowPos++] = previousByte;
-+ continue;
-+ }
-+ }
-+ else
-+ {
-+ UInt32 distance;
-+ if(RangeDecoderBitDecode(p + IsRepG1 + state, &rd) == 0)
-+ distance = rep1;
-+ else
-+ {
-+ if(RangeDecoderBitDecode(p + IsRepG2 + state, &rd) == 0)
-+ distance = rep2;
-+ else
-+ {
-+ distance = rep3;
-+ rep3 = rep2;
-+ }
-+ rep2 = rep1;
-+ }
-+ rep1 = rep0;
-+ rep0 = distance;
-+ }
-+ len = LzmaLenDecode(p + RepLenCoder, &rd, posState);
-+ state = state < 7 ? 8 : 11;
-+ }
-+ else
-+ {
-+ int posSlot;
-+ rep3 = rep2;
-+ rep2 = rep1;
-+ rep1 = rep0;
-+ state = state < 7 ? 7 : 10;
-+ len = LzmaLenDecode(p + LenCoder, &rd, posState);
-+ posSlot = RangeDecoderBitTreeDecode(p + PosSlot +
-+ ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) <<
-+ kNumPosSlotBits), kNumPosSlotBits, &rd);
-+ if (posSlot >= kStartPosModelIndex)
-+ {
-+ int numDirectBits = ((posSlot >> 1) - 1);
-+ rep0 = ((2 | ((UInt32)posSlot & 1)) << numDirectBits);
-+ if (posSlot < kEndPosModelIndex)
-+ {
-+ rep0 += RangeDecoderReverseBitTreeDecode(
-+ p + SpecPos + rep0 - posSlot - 1, numDirectBits, &rd);
-+ }
-+ else
-+ {
-+ rep0 += RangeDecoderDecodeDirectBits(&rd,
-+ numDirectBits - kNumAlignBits) << kNumAlignBits;
-+ rep0 += RangeDecoderReverseBitTreeDecode(p + Align, kNumAlignBits, &rd);
-+ }
-+ }
-+ else
-+ rep0 = posSlot;
-+ rep0++;
-+ }
-+ if (rep0 == (UInt32)(0))
-+ {
-+ /* it's for stream version */
-+ len = -1;
-+ break;
-+ }
-+ if (rep0 > nowPos
-+ #ifdef _LZMA_OUT_READ
-+ + globalPos
-+ #endif
-+ )
-+ {
-+ return LZMA_RESULT_DATA_ERROR;
-+ }
-+ len += kMatchMinLen;
-+ do
-+ {
-+ #ifdef _LZMA_OUT_READ
-+ UInt32 pos = dictionaryPos - rep0;
-+ if (pos >= dictionarySize)
-+ pos += dictionarySize;
-+ previousByte = dictionary[pos];
-+ dictionary[dictionaryPos] = previousByte;
-+ if (++dictionaryPos == dictionarySize)
-+ dictionaryPos = 0;
-+ #else
-+ previousByte = outStream[nowPos - rep0];
-+ #endif
-+ outStream[nowPos++] = previousByte;
-+ len--;
-+ }
-+ while(len > 0 && nowPos < outSize);
-+ }
-+ }
-+
-+ #ifdef _LZMA_OUT_READ
-+ vs->RangeDecoder = rd;
-+ vs->DictionaryPos = dictionaryPos;
-+ vs->GlobalPos = globalPos + nowPos;
-+ vs->Reps[0] = rep0;
-+ vs->Reps[1] = rep1;
-+ vs->Reps[2] = rep2;
-+ vs->Reps[3] = rep3;
-+ vs->State = state;
-+ vs->PreviousIsMatch = previousIsMatch;
-+ vs->RemainLen = len;
-+ #endif
-+
-+ *outSizeProcessed = nowPos;
-+ return LZMA_RESULT_OK;
-+}
---- a/lib/Makefile
-+++ b/lib/Makefile
-@@ -13,7 +13,7 @@
- lib-y += kobject.o kref.o kobject_uevent.o klist.o
-
- obj-y += div64.o sort.o parser.o halfmd4.o debug_locks.o random32.o \
-- bust_spinlocks.o hexdump.o kasprintf.o
-+ bust_spinlocks.o hexdump.o kasprintf.o LzmaDecode.o
-
- ifeq ($(CONFIG_DEBUG_KOBJECT),y)
- CFLAGS_kobject.o += -DDEBUG
-@@ -62,6 +62,7 @@
- obj-$(CONFIG_AUDIT_GENERIC) += audit.o
-
- obj-$(CONFIG_SWIOTLB) += swiotlb.o
-+
- obj-$(CONFIG_FAULT_INJECTION) += fault-inject.o
-
- lib-$(CONFIG_GENERIC_BUG) += bug.o
+++ /dev/null
---- a/fs/squashfs/inode.c
-+++ b/fs/squashfs/inode.c
-@@ -4,6 +4,9 @@
- * Copyright (c) 2002, 2003, 2004, 2005, 2006
- * Phillip Lougher <phillip@lougher.org.uk>
- *
-+ * LZMA decompressor support added by Oleg I. Vdovikin
-+ * Copyright (c) 2005 Oleg I.Vdovikin <oleg@cs.msu.su>
-+ *
- * 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,
-@@ -21,6 +24,7 @@
- * inode.c
- */
-
-+#define SQUASHFS_LZMA
- #include <linux/types.h>
- #include <linux/squashfs_fs.h>
- #include <linux/module.h>
-@@ -44,6 +48,19 @@
-
- #include "squashfs.h"
-
-+#ifdef SQUASHFS_LZMA
-+#include <linux/LzmaDecode.h>
-+
-+/* default LZMA settings, should be in sync with mksquashfs */
-+#define LZMA_LC 3
-+#define LZMA_LP 0
-+#define LZMA_PB 2
-+
-+#define LZMA_WORKSPACE_SIZE ((LZMA_BASE_SIZE + \
-+ (LZMA_LIT_SIZE << (LZMA_LC + LZMA_LP))) * sizeof(CProb))
-+
-+#endif
-+
- static void squashfs_put_super(struct super_block *);
- static int squashfs_statfs(struct dentry *, struct kstatfs *);
- static int squashfs_symlink_readpage(struct file *file, struct page *page);
-@@ -64,7 +81,11 @@
- const char *, void *, struct vfsmount *);
-
-
-+#ifdef SQUASHFS_LZMA
-+static unsigned char lzma_workspace[LZMA_WORKSPACE_SIZE];
-+#else
- static z_stream stream;
-+#endif
-
- static struct file_system_type squashfs_fs_type = {
- .owner = THIS_MODULE,
-@@ -249,6 +270,15 @@
- if (compressed) {
- int zlib_err;
-
-+#ifdef SQUASHFS_LZMA
-+ if ((zlib_err = LzmaDecode(lzma_workspace,
-+ LZMA_WORKSPACE_SIZE, LZMA_LC, LZMA_LP, LZMA_PB,
-+ c_buffer, c_byte, buffer, msblk->read_size, &bytes)) != LZMA_RESULT_OK)
-+ {
-+ ERROR("lzma returned unexpected result 0x%x\n", zlib_err);
-+ bytes = 0;
-+ }
-+#else
- stream.next_in = c_buffer;
- stream.avail_in = c_byte;
- stream.next_out = buffer;
-@@ -263,7 +293,7 @@
- bytes = 0;
- } else
- bytes = stream.total_out;
--
-+#endif
- up(&msblk->read_data_mutex);
- }
-
-@@ -2045,15 +2075,19 @@
- printk(KERN_INFO "squashfs: version 3.0 (2006/03/15) "
- "Phillip Lougher\n");
-
-+#ifndef SQUASHFS_LZMA
- if (!(stream.workspace = vmalloc(zlib_inflate_workspacesize()))) {
- ERROR("Failed to allocate zlib workspace\n");
- destroy_inodecache();
- err = -ENOMEM;
- goto out;
- }
-+#endif
-
- if ((err = register_filesystem(&squashfs_fs_type))) {
-+#ifndef SQUASHFS_LZMA
- vfree(stream.workspace);
-+#endif
- destroy_inodecache();
- }
-
-@@ -2064,7 +2098,9 @@
-
- static void __exit exit_squashfs_fs(void)
- {
-+#ifndef SQUASHFS_LZMA
- vfree(stream.workspace);
-+#endif
- unregister_filesystem(&squashfs_fs_type);
- destroy_inodecache();
- }
+++ /dev/null
---- a/Makefile
-+++ b/Makefile
-@@ -508,6 +508,9 @@
- NOSTDINC_FLAGS += -nostdinc -isystem $(shell $(CC) -print-file-name=include)
- CHECKFLAGS += $(NOSTDINC_FLAGS)
-
-+# improve gcc optimization
-+CFLAGS += $(call cc-option,-funit-at-a-time,)
-+
- # warn about C99 declaration after statement
- CFLAGS += $(call cc-option,-Wdeclaration-after-statement,)
-
+++ /dev/null
---- a/include/asm-mips/system.h
-+++ b/include/asm-mips/system.h
-@@ -181,7 +181,7 @@
- if something tries to do an invalid xchg(). */
- extern void __xchg_called_with_bad_pointer(void);
-
--static inline unsigned long __xchg(unsigned long x, volatile void * ptr, int size)
-+static __always_inline unsigned long __xchg(unsigned long x, volatile void * ptr, int size)
- {
- switch (size) {
- case 4:
+++ /dev/null
---- a/drivers/mtd/chips/cfi_cmdset_0002.c
-+++ b/drivers/mtd/chips/cfi_cmdset_0002.c
-@@ -51,6 +51,7 @@
- #define SST49LF040B 0x0050
- #define SST49LF008A 0x005a
- #define AT49BV6416 0x00d6
-+#define MANUFACTURER_SAMSUNG 0x00ec
-
- static int cfi_amdstd_read (struct mtd_info *, loff_t, size_t, size_t *, u_char *);
- static int cfi_amdstd_write_words(struct mtd_info *, loff_t, size_t, size_t *, const u_char *);
-@@ -294,12 +295,19 @@
-
- if (extp->MajorVersion != '1' ||
- (extp->MinorVersion < '0' || extp->MinorVersion > '4')) {
-- printk(KERN_ERR " Unknown Amd/Fujitsu Extended Query "
-- "version %c.%c.\n", extp->MajorVersion,
-- extp->MinorVersion);
-- kfree(extp);
-- kfree(mtd);
-- return NULL;
-+ if (cfi->mfr == MANUFACTURER_SAMSUNG &&
-+ (extp->MajorVersion == '3' && extp->MinorVersion == '3')) {
-+ printk(KERN_NOTICE " Newer Samsung flash detected, "
-+ "should be compatibile with Amd/Fujitsu.\n");
-+ }
-+ else {
-+ printk(KERN_ERR " Unknown Amd/Fujitsu Extended Query "
-+ "version %c.%c.\n", extp->MajorVersion,
-+ extp->MinorVersion);
-+ kfree(extp);
-+ kfree(mtd);
-+ return NULL;
-+ }
- }
-
- /* Install our own private info structure */
+++ /dev/null
---- a/drivers/mtd/chips/cfi_cmdset_0001.c
-+++ b/drivers/mtd/chips/cfi_cmdset_0001.c
-@@ -933,7 +933,7 @@
-
- static int __xipram xip_wait_for_operation(
- struct map_info *map, struct flchip *chip,
-- unsigned long adr, unsigned int chip_op_time )
-+ unsigned long adr, int *chip_op_time )
- {
- struct cfi_private *cfi = map->fldrv_priv;
- struct cfi_pri_intelext *cfip = cfi->cmdset_priv;
-@@ -942,7 +942,7 @@
- flstate_t oldstate, newstate;
-
- start = xip_currtime();
-- usec = chip_op_time * 8;
-+ usec = *chip_op_time * 8;
- if (usec == 0)
- usec = 500000;
- done = 0;
-@@ -1052,8 +1052,8 @@
- #define XIP_INVAL_CACHED_RANGE(map, from, size) \
- INVALIDATE_CACHED_RANGE(map, from, size)
-
--#define INVAL_CACHE_AND_WAIT(map, chip, cmd_adr, inval_adr, inval_len, usec) \
-- xip_wait_for_operation(map, chip, cmd_adr, usec)
-+#define INVAL_CACHE_AND_WAIT(map, chip, cmd_adr, inval_adr, inval_len, p_usec) \
-+ xip_wait_for_operation(map, chip, cmd_adr, p_usec)
-
- #else
-
-@@ -1065,65 +1065,65 @@
- static int inval_cache_and_wait_for_operation(
- struct map_info *map, struct flchip *chip,
- unsigned long cmd_adr, unsigned long inval_adr, int inval_len,
-- unsigned int chip_op_time)
-+ int *chip_op_time )
- {
- struct cfi_private *cfi = map->fldrv_priv;
- map_word status, status_OK = CMD(0x80);
-- int chip_state = chip->state;
-- unsigned int timeo, sleep_time;
-+ int z, chip_state = chip->state;
-+ unsigned long timeo;
-
- spin_unlock(chip->mutex);
- if (inval_len)
- INVALIDATE_CACHED_RANGE(map, inval_adr, inval_len);
-+ if (*chip_op_time)
-+ cfi_udelay(*chip_op_time);
- spin_lock(chip->mutex);
-
-- /* set our timeout to 8 times the expected delay */
-- timeo = chip_op_time * 8;
-- if (!timeo)
-- timeo = 500000;
-- sleep_time = chip_op_time / 2;
-+ timeo = *chip_op_time * 8 * HZ / 1000000;
-+ if (timeo < HZ/2)
-+ timeo = HZ/2;
-+ timeo += jiffies;
-
-+ z = 0;
- for (;;) {
-+ if (chip->state != chip_state) {
-+ /* Someone's suspended the operation: sleep */
-+ DECLARE_WAITQUEUE(wait, current);
-+
-+ set_current_state(TASK_UNINTERRUPTIBLE);
-+ add_wait_queue(&chip->wq, &wait);
-+ spin_unlock(chip->mutex);
-+ schedule();
-+ remove_wait_queue(&chip->wq, &wait);
-+ timeo = jiffies + (HZ / 2); /* FIXME */
-+ spin_lock(chip->mutex);
-+ continue;
-+ }
-+
- status = map_read(map, cmd_adr);
- if (map_word_andequal(map, status, status_OK, status_OK))
- break;
-
-- if (!timeo) {
-+ /* OK Still waiting */
-+ if (time_after(jiffies, timeo)) {
- map_write(map, CMD(0x70), cmd_adr);
- chip->state = FL_STATUS;
- return -ETIME;
- }
-
-- /* OK Still waiting. Drop the lock, wait a while and retry. */
-+ /* Latency issues. Drop the lock, wait a while and retry */
-+ z++;
- spin_unlock(chip->mutex);
-- if (sleep_time >= 1000000/HZ) {
-- /*
-- * Half of the normal delay still remaining
-- * can be performed with a sleeping delay instead
-- * of busy waiting.
-- */
-- msleep(sleep_time/1000);
-- timeo -= sleep_time;
-- sleep_time = 1000000/HZ;
-- } else {
-- udelay(1);
-- cond_resched();
-- timeo--;
-- }
-+ cfi_udelay(1);
- spin_lock(chip->mutex);
--
-- while (chip->state != chip_state) {
-- /* Someone's suspended the operation: sleep */
-- DECLARE_WAITQUEUE(wait, current);
-- set_current_state(TASK_UNINTERRUPTIBLE);
-- add_wait_queue(&chip->wq, &wait);
-- spin_unlock(chip->mutex);
-- schedule();
-- remove_wait_queue(&chip->wq, &wait);
-- spin_lock(chip->mutex);
-- }
- }
-
-+ if (!z) {
-+ if (!--(*chip_op_time))
-+ *chip_op_time = 1;
-+ } else if (z > 1)
-+ ++(*chip_op_time);
-+
- /* Done and happy. */
- chip->state = FL_STATUS;
- return 0;
-@@ -1132,7 +1132,8 @@
- #endif
-
- #define WAIT_TIMEOUT(map, chip, adr, udelay) \
-- INVAL_CACHE_AND_WAIT(map, chip, adr, 0, 0, udelay);
-+ ({ int __udelay = (udelay); \
-+ INVAL_CACHE_AND_WAIT(map, chip, adr, 0, 0, &__udelay); })
-
-
- static int do_point_onechip (struct map_info *map, struct flchip *chip, loff_t adr, size_t len)
-@@ -1356,7 +1357,7 @@
-
- ret = INVAL_CACHE_AND_WAIT(map, chip, adr,
- adr, map_bankwidth(map),
-- chip->word_write_time);
-+ &chip->word_write_time);
- if (ret) {
- xip_enable(map, chip, adr);
- printk(KERN_ERR "%s: word write error (status timeout)\n", map->name);
-@@ -1593,7 +1594,7 @@
-
- ret = INVAL_CACHE_AND_WAIT(map, chip, cmd_adr,
- adr, len,
-- chip->buffer_write_time);
-+ &chip->buffer_write_time);
- if (ret) {
- map_write(map, CMD(0x70), cmd_adr);
- chip->state = FL_STATUS;
-@@ -1728,7 +1729,7 @@
-
- ret = INVAL_CACHE_AND_WAIT(map, chip, adr,
- adr, len,
-- chip->erase_time);
-+ &chip->erase_time);
- if (ret) {
- map_write(map, CMD(0x70), adr);
- chip->state = FL_STATUS;
+++ /dev/null
---- a/fs/squashfs/Makefile
-+++ b/fs/squashfs/Makefile
-@@ -4,4 +4,3 @@
-
- obj-$(CONFIG_SQUASHFS) += squashfs.o
- squashfs-y += inode.o
--squashfs-y += squashfs2_0.o
---- a/fs/squashfs/squashfs.h
-+++ b/fs/squashfs/squashfs.h
-@@ -24,6 +24,9 @@
- #ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY
- #undef CONFIG_SQUASHFS_1_0_COMPATIBILITY
- #endif
-+#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY
-+#undef CONFIG_SQUASHFS_2_0_COMPATIBILITY
-+#endif
-
- #ifdef SQUASHFS_TRACE
- #define TRACE(s, args...) printk(KERN_NOTICE "SQUASHFS: "s, ## args)
+++ /dev/null
---- a/arch/mips/kernel/head.S
-+++ b/arch/mips/kernel/head.S
-@@ -130,6 +130,8 @@
- #endif
- .endm
-
-+ j kernel_entry
-+ nop
- #ifndef CONFIG_NO_EXCEPT_FILL
- /*
- * Reserved space for exception handlers.
+++ /dev/null
---- a/arch/mips/mm/tlbex.c
-+++ b/arch/mips/mm/tlbex.c
-@@ -902,7 +902,6 @@
- case CPU_R10000:
- case CPU_R12000:
- case CPU_R14000:
-- case CPU_4KC:
- case CPU_SB1:
- case CPU_SB1A:
- case CPU_4KSC:
-@@ -933,6 +932,7 @@
- tlbw(p);
- break;
-
-+ case CPU_4KC:
- case CPU_4KEC:
- case CPU_24K:
- case CPU_34K:
+++ /dev/null
---- a/arch/mips/kernel/gdb-stub.c
-+++ b/arch/mips/kernel/gdb-stub.c
-@@ -656,6 +656,7 @@
- *epc = (unsigned long)async_breakpoint;
- }
-
-+#ifdef CONFIG_SMP
- static void kgdb_wait(void *arg)
- {
- unsigned flags;
-@@ -668,6 +669,7 @@
-
- local_irq_restore(flags);
- }
-+#endif
-
- /*
- * GDB stub needs to call kgdb_wait on all processor with interrupts
+++ /dev/null
---- a/drivers/mtd/devices/block2mtd.c
-+++ b/drivers/mtd/devices/block2mtd.c
-@@ -16,6 +16,7 @@
- #include <linux/list.h>
- #include <linux/init.h>
- #include <linux/mtd/mtd.h>
-+#include <linux/mtd/partitions.h>
- #include <linux/buffer_head.h>
- #include <linux/mutex.h>
- #include <linux/mount.h>
-@@ -237,10 +238,11 @@
-
-
- /* FIXME: ensure that mtd->size % erase_size == 0 */
--static struct block2mtd_dev *add_device(char *devname, int erase_size)
-+static struct block2mtd_dev *add_device(char *devname, int erase_size, char *mtdname)
- {
- struct block_device *bdev;
- struct block2mtd_dev *dev;
-+ struct mtd_partition *part;
-
- if (!devname)
- return NULL;
-@@ -279,14 +281,18 @@
-
- /* Setup the MTD structure */
- /* make the name contain the block device in */
-- dev->mtd.name = kmalloc(sizeof("block2mtd: ") + strlen(devname),
-- GFP_KERNEL);
-+
-+ if (!mtdname)
-+ mtdname = devname;
-+
-+ dev->mtd.name = kmalloc(strlen(mtdname) + 1, GFP_KERNEL);
-+
- if (!dev->mtd.name)
- goto devinit_err;
-+
-+ strcpy(dev->mtd.name, mtdname);
-
-- sprintf(dev->mtd.name, "block2mtd: %s", devname);
--
-- dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK;
-+ dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK & ~(erase_size - 1);
- dev->mtd.erasesize = erase_size;
- dev->mtd.writesize = 1;
- dev->mtd.type = MTD_RAM;
-@@ -298,15 +304,18 @@
- dev->mtd.read = block2mtd_read;
- dev->mtd.priv = dev;
- dev->mtd.owner = THIS_MODULE;
--
-- if (add_mtd_device(&dev->mtd)) {
-+
-+ part = kzalloc(sizeof(struct mtd_partition), GFP_KERNEL);
-+ part->name = dev->mtd.name;
-+ part->offset = 0;
-+ part->size = dev->mtd.size;
-+ if (add_mtd_partitions(&dev->mtd, part, 1)) {
- /* Device didnt get added, so free the entry */
- goto devinit_err;
- }
- list_add(&dev->list, &blkmtd_device_list);
- INFO("mtd%d: [%s] erase_size = %dKiB [%d]", dev->mtd.index,
-- dev->mtd.name + strlen("blkmtd: "),
-- dev->mtd.erasesize >> 10, dev->mtd.erasesize);
-+ mtdname, dev->mtd.erasesize >> 10, dev->mtd.erasesize);
- return dev;
-
- devinit_err:
-@@ -379,9 +388,9 @@
-
- static int block2mtd_setup2(const char *val)
- {
-- char buf[80 + 12]; /* 80 for device, 12 for erase size */
-+ char buf[80 + 12 + 80]; /* 80 for device, 12 for erase size, 80 for name */
- char *str = buf;
-- char *token[2];
-+ char *token[3];
- char *name;
- size_t erase_size = PAGE_SIZE;
- int i, ret;
-@@ -392,7 +401,7 @@
- strcpy(str, val);
- kill_final_newline(str);
-
-- for (i = 0; i < 2; i++)
-+ for (i = 0; i < 3; i++)
- token[i] = strsep(&str, ",");
-
- if (str)
-@@ -412,8 +421,10 @@
- parse_err("illegal erase size");
- }
- }
-+ if (token[2] && (strlen(token[2]) + 1 > 80))
-+ parse_err("mtd device name too long");
-
-- add_device(name, erase_size);
-+ add_device(name, erase_size, token[2]);
-
- return 0;
- }
-@@ -447,7 +458,7 @@
-
-
- module_param_call(block2mtd, block2mtd_setup, NULL, NULL, 0200);
--MODULE_PARM_DESC(block2mtd, "Device to use. \"block2mtd=<dev>[,<erasesize>]\"");
-+MODULE_PARM_DESC(block2mtd, "Device to use. \"block2mtd=<dev>[,<erasesize>[,<name>]]\"");
-
- static int __init block2mtd_init(void)
- {
+++ /dev/null
---- a/drivers/mtd/Kconfig
-+++ b/drivers/mtd/Kconfig
-@@ -47,6 +47,16 @@
- devices. Partitioning on NFTL 'devices' is a different - that's the
- 'normal' form of partitioning used on a block device.
-
-+config MTD_ROOTFS_ROOT_DEV
-+ bool "Automatically set 'rootfs' partition to be root filesystem"
-+ depends on MTD_PARTITIONS
-+ default y
-+
-+config MTD_ROOTFS_SPLIT
-+ bool "Automatically split 'rootfs' partition for squashfs"
-+ depends on MTD_PARTITIONS
-+ default y
-+
- config MTD_REDBOOT_PARTS
- tristate "RedBoot partition table parsing"
- depends on MTD_PARTITIONS
---- a/drivers/mtd/mtdpart.c
-+++ b/drivers/mtd/mtdpart.c
-@@ -20,6 +20,8 @@
- #include <linux/mtd/mtd.h>
- #include <linux/mtd/partitions.h>
- #include <linux/mtd/compatmac.h>
-+#include <linux/squashfs_fs.h>
-+#include <linux/root_dev.h>
-
- /* Our partition linked list */
- static LIST_HEAD(mtd_partitions);
-@@ -39,7 +41,7 @@
- * the pointer to that structure with this macro.
- */
- #define PART(x) ((struct mtd_part *)(x))
--
-+#define IS_PART(mtd) (mtd->read == part_read)
-
- /*
- * MTD methods which simply translate the effective address and pass through
-@@ -308,6 +310,312 @@
- return 0;
- }
-
-+static u_int32_t cur_offset = 0;
-+static int add_one_partition(struct mtd_info *master, const struct mtd_partition *part,
-+ int i, struct mtd_part **slp)
-+{
-+ struct mtd_part *slave;
-+
-+ /* allocate the partition structure */
-+ slave = kzalloc (sizeof(*slave), GFP_KERNEL);
-+ if (!slave) {
-+ printk ("memory allocation error while creating partitions for \"%s\"\n",
-+ master->name);
-+ del_mtd_partitions(master);
-+ return -ENOMEM;
-+ }
-+ list_add(&slave->list, &mtd_partitions);
-+
-+ /* set up the MTD object for this partition */
-+ slave->mtd.type = master->type;
-+ slave->mtd.flags = master->flags & ~part->mask_flags;
-+ slave->mtd.size = part->size;
-+ slave->mtd.writesize = master->writesize;
-+ slave->mtd.oobsize = master->oobsize;
-+ slave->mtd.oobavail = master->oobavail;
-+ slave->mtd.subpage_sft = master->subpage_sft;
-+
-+ slave->mtd.name = part->name;
-+ slave->mtd.owner = master->owner;
-+
-+ slave->mtd.read = part_read;
-+ slave->mtd.write = part_write;
-+ slave->mtd.refresh_device = part->refresh_partition;
-+
-+ if(master->point && master->unpoint){
-+ slave->mtd.point = part_point;
-+ slave->mtd.unpoint = part_unpoint;
-+ }
-+
-+ if (master->read_oob)
-+ slave->mtd.read_oob = part_read_oob;
-+ if (master->write_oob)
-+ slave->mtd.write_oob = part_write_oob;
-+ if(master->read_user_prot_reg)
-+ slave->mtd.read_user_prot_reg = part_read_user_prot_reg;
-+ if(master->read_fact_prot_reg)
-+ slave->mtd.read_fact_prot_reg = part_read_fact_prot_reg;
-+ if(master->write_user_prot_reg)
-+ slave->mtd.write_user_prot_reg = part_write_user_prot_reg;
-+ if(master->lock_user_prot_reg)
-+ slave->mtd.lock_user_prot_reg = part_lock_user_prot_reg;
-+ if(master->get_user_prot_info)
-+ slave->mtd.get_user_prot_info = part_get_user_prot_info;
-+ if(master->get_fact_prot_info)
-+ slave->mtd.get_fact_prot_info = part_get_fact_prot_info;
-+ if (master->sync)
-+ slave->mtd.sync = part_sync;
-+ if (!i && master->suspend && master->resume) {
-+ slave->mtd.suspend = part_suspend;
-+ slave->mtd.resume = part_resume;
-+ }
-+ if (master->writev)
-+ slave->mtd.writev = part_writev;
-+ if (master->lock)
-+ slave->mtd.lock = part_lock;
-+ if (master->unlock)
-+ slave->mtd.unlock = part_unlock;
-+ if (master->block_isbad)
-+ slave->mtd.block_isbad = part_block_isbad;
-+ if (master->block_markbad)
-+ slave->mtd.block_markbad = part_block_markbad;
-+ slave->mtd.erase = part_erase;
-+ slave->master = master;
-+ slave->offset = part->offset;
-+ slave->index = i;
-+
-+ if (slave->offset == MTDPART_OFS_APPEND)
-+ slave->offset = cur_offset;
-+ if (slave->offset == MTDPART_OFS_NXTBLK) {
-+ slave->offset = cur_offset;
-+ if ((cur_offset % master->erasesize) != 0) {
-+ /* Round up to next erasesize */
-+ slave->offset = ((cur_offset / master->erasesize) + 1) * master->erasesize;
-+ printk(KERN_NOTICE "Moving partition %d: "
-+ "0x%08x -> 0x%08x\n", i,
-+ cur_offset, slave->offset);
-+ }
-+ }
-+ if (slave->mtd.size == MTDPART_SIZ_FULL)
-+ slave->mtd.size = master->size - slave->offset;
-+ cur_offset = slave->offset + slave->mtd.size;
-+
-+ printk (KERN_NOTICE "0x%08x-0x%08x : \"%s\"\n", slave->offset,
-+ slave->offset + slave->mtd.size, slave->mtd.name);
-+
-+ /* let's do some sanity checks */
-+ if (slave->offset >= master->size) {
-+ /* let's register it anyway to preserve ordering */
-+ slave->offset = 0;
-+ slave->mtd.size = 0;
-+ printk ("mtd: partition \"%s\" is out of reach -- disabled\n",
-+ part->name);
-+ }
-+ if (slave->offset + slave->mtd.size > master->size) {
-+ slave->mtd.size = master->size - slave->offset;
-+ printk ("mtd: partition \"%s\" extends beyond the end of device \"%s\" -- size truncated to %#x\n",
-+ part->name, master->name, slave->mtd.size);
-+ }
-+ if (master->numeraseregions>1) {
-+ /* Deal with variable erase size stuff */
-+ int i;
-+ struct mtd_erase_region_info *regions = master->eraseregions;
-+
-+ /* Find the first erase regions which is part of this partition. */
-+ for (i=0; i < master->numeraseregions && slave->offset >= regions[i].offset; i++)
-+ ;
-+
-+ for (i--; i < master->numeraseregions && slave->offset + slave->mtd.size > regions[i].offset; i++) {
-+ if (slave->mtd.erasesize < regions[i].erasesize) {
-+ slave->mtd.erasesize = regions[i].erasesize;
-+ }
-+ }
-+ } else {
-+ /* Single erase size */
-+ slave->mtd.erasesize = master->erasesize;
-+ }
-+
-+ if ((slave->mtd.flags & MTD_WRITEABLE) &&
-+ (slave->offset % slave->mtd.erasesize)) {
-+ /* Doesn't start on a boundary of major erase size */
-+ /* FIXME: Let it be writable if it is on a boundary of _minor_ erase size though */
-+ slave->mtd.flags &= ~MTD_WRITEABLE;
-+ printk ("mtd: partition \"%s\" doesn't start on an erase block boundary -- force read-only\n",
-+ part->name);
-+ }
-+ if ((slave->mtd.flags & MTD_WRITEABLE) &&
-+ (slave->mtd.size % slave->mtd.erasesize)) {
-+ slave->mtd.flags &= ~MTD_WRITEABLE;
-+ printk ("mtd: partition \"%s\" doesn't end on an erase block -- force read-only\n",
-+ part->name);
-+ }
-+
-+ slave->mtd.ecclayout = master->ecclayout;
-+ if (master->block_isbad) {
-+ uint32_t offs = 0;
-+
-+ while(offs < slave->mtd.size) {
-+ if (master->block_isbad(master,
-+ offs + slave->offset))
-+ slave->mtd.ecc_stats.badblocks++;
-+ offs += slave->mtd.erasesize;
-+ }
-+ }
-+
-+ if(part->mtdp)
-+ { /* store the object pointer (caller may or may not register it */
-+ *part->mtdp = &slave->mtd;
-+ slave->registered = 0;
-+ }
-+ else
-+ {
-+ /* register our partition */
-+ add_mtd_device(&slave->mtd);
-+ slave->registered = 1;
-+ }
-+
-+ if (slp)
-+ *slp = slave;
-+
-+ return 0;
-+}
-+
-+#ifdef CONFIG_MTD_ROOTFS_SPLIT
-+#define ROOTFS_SPLIT_NAME "rootfs_data"
-+#define ROOTFS_REMOVED_NAME "<removed>"
-+static int split_squashfs(struct mtd_info *master, int offset, int *split_offset)
-+{
-+ char buf[512];
-+ struct squashfs_super_block *sb = (struct squashfs_super_block *) buf;
-+ int len, ret;
-+
-+ ret = master->read(master, offset, sizeof(*sb), &len, buf);
-+ if (ret || (len != sizeof(*sb))) {
-+ printk(KERN_ALERT "split_squashfs: error occured while reading "
-+ "from \"%s\"\n", master->name);
-+ return -EINVAL;
-+ }
-+
-+ if (*((u32 *) buf) != SQUASHFS_MAGIC) {
-+ printk(KERN_ALERT "split_squashfs: no squashfs found in \"%s\"\n",
-+ master->name);
-+ *split_offset = 0;
-+ return 0;
-+ }
-+
-+ if (sb->bytes_used <= 0) {
-+ printk(KERN_ALERT "split_squashfs: squashfs is empty in \"%s\"\n",
-+ master->name);
-+ *split_offset = 0;
-+ return 0;
-+ }
-+
-+ len = (u32) sb->bytes_used;
-+ len += (offset & 0x000fffff);
-+ len += (master->erasesize - 1);
-+ len &= ~(master->erasesize - 1);
-+ len -= (offset & 0x000fffff);
-+ *split_offset = offset + len;
-+
-+ return 0;
-+}
-+
-+static int split_rootfs_data(struct mtd_info *master, struct mtd_info *rpart, struct mtd_partition *part,
-+ int index)
-+{
-+ struct mtd_partition *dpart;
-+ struct mtd_part *slave = NULL;
-+ int split_offset = 0;
-+ int ret;
-+
-+ ret = split_squashfs(master, part->offset, &split_offset);
-+ if (ret)
-+ return ret;
-+
-+ if (split_offset <= 0)
-+ return 0;
-+
-+ dpart = kmalloc(sizeof(*part)+sizeof(ROOTFS_SPLIT_NAME)+1, GFP_KERNEL);
-+ if (dpart == NULL) {
-+ printk(KERN_INFO "split_squashfs: no memory for partition \"%s\"\n",
-+ ROOTFS_SPLIT_NAME);
-+ return -ENOMEM;
-+ }
-+
-+ memcpy(dpart, part, sizeof(*part));
-+ dpart->name = (unsigned char *)&dpart[1];
-+ strcpy(dpart->name, ROOTFS_SPLIT_NAME);
-+
-+ dpart->size -= split_offset - dpart->offset;
-+ dpart->offset = split_offset;
-+
-+ if (dpart == NULL)
-+ return 1;
-+
-+ printk(KERN_INFO "mtd: partition \"%s\" created automatically, ofs=%X, len=%X \n",
-+ ROOTFS_SPLIT_NAME, dpart->offset, dpart->size);
-+
-+ ret = add_one_partition(master, dpart, index, &slave);
-+ if (ret)
-+ kfree(dpart);
-+ else if (slave)
-+ rpart->split = &slave->mtd;
-+
-+ return ret;
-+}
-+
-+static int refresh_rootfs_split(struct mtd_info *mtd)
-+{
-+ struct mtd_partition tpart;
-+ struct mtd_part *part;
-+ int index = 0;
-+ int offset, size;
-+ int ret;
-+
-+ part = PART(mtd);
-+
-+ /* check for the new squashfs offset first */
-+ ret = split_squashfs(part->master, part->offset, &offset);
-+ if (ret)
-+ return ret;
-+
-+ if ((offset > 0) && !mtd->split) {
-+ printk(KERN_INFO "%s: creating new split partition for \"%s\"\n", __func__, mtd->name);
-+ /* if we don't have a rootfs split partition, create a new one */
-+ tpart.name = mtd->name;
-+ tpart.size = mtd->size;
-+ tpart.offset = part->offset;
-+
-+ /* find the index of the last partition */
-+ if (!list_empty(&mtd_partitions))
-+ index = list_first_entry(&mtd_partitions, struct mtd_part, list)->index + 1;
-+
-+ return split_rootfs_data(part->master, &part->mtd, &tpart, index);
-+ } else if ((offset > 0) && mtd->split) {
-+ /* update the offsets of the existing partition */
-+ size = mtd->size + part->offset - offset;
-+
-+ part = PART(mtd->split);
-+ part->offset = offset;
-+ part->mtd.size = size;
-+ printk(KERN_INFO "%s: %s partition \"" ROOTFS_SPLIT_NAME "\", offset: 0x%06x (0x%06x)\n",
-+ __func__, (!strcmp(part->mtd.name, ROOTFS_SPLIT_NAME) ? "updating" : "creating"),
-+ part->offset, part->mtd.size);
-+ strcpy(part->mtd.name, ROOTFS_SPLIT_NAME);
-+ } else if ((offset <= 0) && mtd->split) {
-+ printk(KERN_INFO "%s: removing partition \"%s\"\n", __func__, mtd->split->name);
-+
-+ /* mark existing partition as removed */
-+ part = PART(mtd->split);
-+ strcpy(part->mtd.name, ROOTFS_REMOVED_NAME);
-+ part->offset = 0;
-+ part->mtd.size = 0;
-+ }
-+
-+ return 0;
-+}
-+#endif /* CONFIG_MTD_ROOTFS_SPLIT */
-+
- /*
- * This function, given a master MTD object and a partition table, creates
- * and registers slave MTD objects which are bound to the master according to
-@@ -320,168 +628,31 @@
- int nbparts)
- {
- struct mtd_part *slave;
-- u_int32_t cur_offset = 0;
-- int i;
-+ struct mtd_partition *part;
-+ int i, j, ret = 0;
-
- printk (KERN_NOTICE "Creating %d MTD partitions on \"%s\":\n", nbparts, master->name);
-
-- for (i = 0; i < nbparts; i++) {
--
-- /* allocate the partition structure */
-- slave = kzalloc (sizeof(*slave), GFP_KERNEL);
-- if (!slave) {
-- printk ("memory allocation error while creating partitions for \"%s\"\n",
-- master->name);
-- del_mtd_partitions(master);
-- return -ENOMEM;
-- }
-- list_add(&slave->list, &mtd_partitions);
--
-- /* set up the MTD object for this partition */
-- slave->mtd.type = master->type;
-- slave->mtd.flags = master->flags & ~parts[i].mask_flags;
-- slave->mtd.size = parts[i].size;
-- slave->mtd.writesize = master->writesize;
-- slave->mtd.oobsize = master->oobsize;
-- slave->mtd.oobavail = master->oobavail;
-- slave->mtd.subpage_sft = master->subpage_sft;
--
-- slave->mtd.name = parts[i].name;
-- slave->mtd.owner = master->owner;
--
-- slave->mtd.read = part_read;
-- slave->mtd.write = part_write;
--
-- if(master->point && master->unpoint){
-- slave->mtd.point = part_point;
-- slave->mtd.unpoint = part_unpoint;
-- }
--
-- if (master->read_oob)
-- slave->mtd.read_oob = part_read_oob;
-- if (master->write_oob)
-- slave->mtd.write_oob = part_write_oob;
-- if(master->read_user_prot_reg)
-- slave->mtd.read_user_prot_reg = part_read_user_prot_reg;
-- if(master->read_fact_prot_reg)
-- slave->mtd.read_fact_prot_reg = part_read_fact_prot_reg;
-- if(master->write_user_prot_reg)
-- slave->mtd.write_user_prot_reg = part_write_user_prot_reg;
-- if(master->lock_user_prot_reg)
-- slave->mtd.lock_user_prot_reg = part_lock_user_prot_reg;
-- if(master->get_user_prot_info)
-- slave->mtd.get_user_prot_info = part_get_user_prot_info;
-- if(master->get_fact_prot_info)
-- slave->mtd.get_fact_prot_info = part_get_fact_prot_info;
-- if (master->sync)
-- slave->mtd.sync = part_sync;
-- if (!i && master->suspend && master->resume) {
-- slave->mtd.suspend = part_suspend;
-- slave->mtd.resume = part_resume;
-- }
-- if (master->writev)
-- slave->mtd.writev = part_writev;
-- if (master->lock)
-- slave->mtd.lock = part_lock;
-- if (master->unlock)
-- slave->mtd.unlock = part_unlock;
-- if (master->block_isbad)
-- slave->mtd.block_isbad = part_block_isbad;
-- if (master->block_markbad)
-- slave->mtd.block_markbad = part_block_markbad;
-- slave->mtd.erase = part_erase;
-- slave->master = master;
-- slave->offset = parts[i].offset;
-- slave->index = i;
--
-- if (slave->offset == MTDPART_OFS_APPEND)
-- slave->offset = cur_offset;
-- if (slave->offset == MTDPART_OFS_NXTBLK) {
-- slave->offset = cur_offset;
-- if ((cur_offset % master->erasesize) != 0) {
-- /* Round up to next erasesize */
-- slave->offset = ((cur_offset / master->erasesize) + 1) * master->erasesize;
-- printk(KERN_NOTICE "Moving partition %d: "
-- "0x%08x -> 0x%08x\n", i,
-- cur_offset, slave->offset);
-- }
-- }
-- if (slave->mtd.size == MTDPART_SIZ_FULL)
-- slave->mtd.size = master->size - slave->offset;
-- cur_offset = slave->offset + slave->mtd.size;
--
-- printk (KERN_NOTICE "0x%08x-0x%08x : \"%s\"\n", slave->offset,
-- slave->offset + slave->mtd.size, slave->mtd.name);
--
-- /* let's do some sanity checks */
-- if (slave->offset >= master->size) {
-- /* let's register it anyway to preserve ordering */
-- slave->offset = 0;
-- slave->mtd.size = 0;
-- printk ("mtd: partition \"%s\" is out of reach -- disabled\n",
-- parts[i].name);
-- }
-- if (slave->offset + slave->mtd.size > master->size) {
-- slave->mtd.size = master->size - slave->offset;
-- printk ("mtd: partition \"%s\" extends beyond the end of device \"%s\" -- size truncated to %#x\n",
-- parts[i].name, master->name, slave->mtd.size);
-- }
-- if (master->numeraseregions>1) {
-- /* Deal with variable erase size stuff */
-- int i;
-- struct mtd_erase_region_info *regions = master->eraseregions;
--
-- /* Find the first erase regions which is part of this partition. */
-- for (i=0; i < master->numeraseregions && slave->offset >= regions[i].offset; i++)
-- ;
--
-- for (i--; i < master->numeraseregions && slave->offset + slave->mtd.size > regions[i].offset; i++) {
-- if (slave->mtd.erasesize < regions[i].erasesize) {
-- slave->mtd.erasesize = regions[i].erasesize;
-- }
-+ for (i = 0, j = 0; i < nbparts; i++) {
-+ part = (struct mtd_partition *) &parts[i];
-+ ret = add_one_partition(master, part, j, &slave);
-+ if (ret)
-+ return ret;
-+ j++;
-+
-+ if (strcmp(part->name, "rootfs") == 0 && slave->registered) {
-+#ifdef CONFIG_MTD_ROOTFS_ROOT_DEV
-+ if (ROOT_DEV == 0) {
-+ printk(KERN_NOTICE "mtd: partition \"rootfs\" "
-+ "set to be root filesystem\n");
-+ ROOT_DEV = MKDEV(MTD_BLOCK_MAJOR, slave->mtd.index);
- }
-- } else {
-- /* Single erase size */
-- slave->mtd.erasesize = master->erasesize;
-- }
--
-- if ((slave->mtd.flags & MTD_WRITEABLE) &&
-- (slave->offset % slave->mtd.erasesize)) {
-- /* Doesn't start on a boundary of major erase size */
-- /* FIXME: Let it be writable if it is on a boundary of _minor_ erase size though */
-- slave->mtd.flags &= ~MTD_WRITEABLE;
-- printk ("mtd: partition \"%s\" doesn't start on an erase block boundary -- force read-only\n",
-- parts[i].name);
-- }
-- if ((slave->mtd.flags & MTD_WRITEABLE) &&
-- (slave->mtd.size % slave->mtd.erasesize)) {
-- slave->mtd.flags &= ~MTD_WRITEABLE;
-- printk ("mtd: partition \"%s\" doesn't end on an erase block -- force read-only\n",
-- parts[i].name);
-- }
--
-- slave->mtd.ecclayout = master->ecclayout;
-- if (master->block_isbad) {
-- uint32_t offs = 0;
--
-- while(offs < slave->mtd.size) {
-- if (master->block_isbad(master,
-- offs + slave->offset))
-- slave->mtd.ecc_stats.badblocks++;
-- offs += slave->mtd.erasesize;
-- }
-- }
--
-- if(parts[i].mtdp)
-- { /* store the object pointer (caller may or may not register it */
-- *parts[i].mtdp = &slave->mtd;
-- slave->registered = 0;
-- }
-- else
-- {
-- /* register our partition */
-- add_mtd_device(&slave->mtd);
-- slave->registered = 1;
-+#endif
-+#ifdef CONFIG_MTD_ROOTFS_SPLIT
-+ ret = split_rootfs_data(master, &slave->mtd, part, j);
-+ if (ret == 0)
-+ j++;
-+#endif
- }
- }
-
-@@ -557,6 +728,32 @@
- return ret;
- }
-
-+int refresh_mtd_partitions(struct mtd_info *mtd)
-+{
-+ int ret = 0;
-+
-+ if (IS_PART(mtd)) {
-+ struct mtd_part *part;
-+ struct mtd_info *master;
-+
-+ part = PART(mtd);
-+ master = part->master;
-+ if (master->refresh_device)
-+ ret = master->refresh_device(master);
-+ }
-+
-+ if (!ret && mtd->refresh_device)
-+ ret = mtd->refresh_device(mtd);
-+
-+#ifdef CONFIG_MTD_ROOTFS_SPLIT
-+ if (!ret && IS_PART(mtd) && !strcmp(mtd->name, "rootfs"))
-+ refresh_rootfs_split(mtd);
-+#endif
-+
-+ return 0;
-+}
-+
- EXPORT_SYMBOL_GPL(parse_mtd_partitions);
-+EXPORT_SYMBOL_GPL(refresh_mtd_partitions);
- EXPORT_SYMBOL_GPL(register_mtd_parser);
- EXPORT_SYMBOL_GPL(deregister_mtd_parser);
---- a/drivers/mtd/devices/block2mtd.c
-+++ b/drivers/mtd/devices/block2mtd.c
-@@ -34,6 +34,8 @@
- struct block_device *blkdev;
- struct mtd_info mtd;
- struct mutex write_mutex;
-+ rwlock_t bdev_mutex;
-+ char devname[0];
- };
-
-
-@@ -86,6 +88,12 @@
- size_t len = instr->len;
- int err;
-
-+ read_lock(&dev->bdev_mutex);
-+ if (!dev->blkdev) {
-+ err = -EINVAL;
-+ goto done;
-+ }
-+
- instr->state = MTD_ERASING;
- mutex_lock(&dev->write_mutex);
- err = _block2mtd_erase(dev, from, len);
-@@ -98,6 +106,10 @@
-
- instr->state = MTD_ERASE_DONE;
- mtd_erase_callback(instr);
-+
-+done:
-+ read_unlock(&dev->bdev_mutex);
-+
- return err;
- }
-
-@@ -109,10 +121,14 @@
- struct page *page;
- int index = from >> PAGE_SHIFT;
- int offset = from & (PAGE_SIZE-1);
-- int cpylen;
-+ int cpylen, err = 0;
-+
-+ read_lock(&dev->bdev_mutex);
-+ if (!dev->blkdev || (from > mtd->size)) {
-+ err = -EINVAL;
-+ goto done;
-+ }
-
-- if (from > mtd->size)
-- return -EINVAL;
- if (from + len > mtd->size)
- len = mtd->size - from;
-
-@@ -127,10 +143,14 @@
- len = len - cpylen;
-
- page = page_read(dev->blkdev->bd_inode->i_mapping, index);
-- if (!page)
-- return -ENOMEM;
-- if (IS_ERR(page))
-- return PTR_ERR(page);
-+ if (!page) {
-+ err = -ENOMEM;
-+ goto done;
-+ }
-+ if (IS_ERR(page)) {
-+ err = PTR_ERR(page);
-+ goto done;
-+ }
-
- memcpy(buf, page_address(page) + offset, cpylen);
- page_cache_release(page);
-@@ -141,7 +161,10 @@
- offset = 0;
- index++;
- }
-- return 0;
-+
-+done:
-+ read_unlock(&dev->bdev_mutex);
-+ return err;
- }
-
-
-@@ -193,12 +216,22 @@
- size_t *retlen, const u_char *buf)
- {
- struct block2mtd_dev *dev = mtd->priv;
-- int err;
-+ int err = 0;
-+
-+ read_lock(&dev->bdev_mutex);
-+ if (!dev->blkdev) {
-+ err = -EINVAL;
-+ goto done;
-+ }
-
- if (!len)
-- return 0;
-- if (to >= mtd->size)
-- return -ENOSPC;
-+ goto done;
-+
-+ if (to >= mtd->size) {
-+ err = -ENOSPC;
-+ goto done;
-+ }
-+
- if (to + len > mtd->size)
- len = mtd->size - to;
-
-@@ -207,6 +240,9 @@
- mutex_unlock(&dev->write_mutex);
- if (err > 0)
- err = 0;
-+
-+done:
-+ read_unlock(&dev->bdev_mutex);
- return err;
- }
-
-@@ -215,51 +251,29 @@
- static void block2mtd_sync(struct mtd_info *mtd)
- {
- struct block2mtd_dev *dev = mtd->priv;
-- sync_blockdev(dev->blkdev);
-- return;
--}
--
--
--static void block2mtd_free_device(struct block2mtd_dev *dev)
--{
-- if (!dev)
-- return;
--
-- kfree(dev->mtd.name);
-
-- if (dev->blkdev) {
-- invalidate_mapping_pages(dev->blkdev->bd_inode->i_mapping,
-- 0, -1);
-- close_bdev_excl(dev->blkdev);
-- }
-+ read_lock(&dev->bdev_mutex);
-+ if (dev->blkdev)
-+ sync_blockdev(dev->blkdev);
-+ read_unlock(&dev->bdev_mutex);
-
-- kfree(dev);
-+ return;
- }
-
-
--/* FIXME: ensure that mtd->size % erase_size == 0 */
--static struct block2mtd_dev *add_device(char *devname, int erase_size, char *mtdname)
-+static int _open_bdev(struct block2mtd_dev *dev)
- {
- struct block_device *bdev;
-- struct block2mtd_dev *dev;
-- struct mtd_partition *part;
--
-- if (!devname)
-- return NULL;
--
-- dev = kzalloc(sizeof(struct block2mtd_dev), GFP_KERNEL);
-- if (!dev)
-- return NULL;
-
- /* Get a handle on the device */
-- bdev = open_bdev_excl(devname, O_RDWR, NULL);
-+ bdev = open_bdev_excl(dev->devname, O_RDWR, NULL);
- #ifndef MODULE
- if (IS_ERR(bdev)) {
-
- /* We might not have rootfs mounted at this point. Try
- to resolve the device name by other means. */
-
-- dev_t devt = name_to_dev_t(devname);
-+ dev_t devt = name_to_dev_t(dev->devname);
- if (devt) {
- bdev = open_by_devnum(devt, FMODE_WRITE | FMODE_READ);
- }
-@@ -267,17 +281,96 @@
- #endif
-
- if (IS_ERR(bdev)) {
-- ERROR("error: cannot open device %s", devname);
-- goto devinit_err;
-+ ERROR("error: cannot open device %s", dev->devname);
-+ return 1;
- }
- dev->blkdev = bdev;
-
- if (MAJOR(bdev->bd_dev) == MTD_BLOCK_MAJOR) {
- ERROR("attempting to use an MTD device as a block device");
-- goto devinit_err;
-+ return 1;
- }
-
-+ return 0;
-+}
-+
-+static void _close_bdev(struct block2mtd_dev *dev)
-+{
-+ struct block_device *bdev;
-+
-+ if (!dev->blkdev)
-+ return;
-+
-+ bdev = dev->blkdev;
-+ invalidate_mapping_pages(dev->blkdev->bd_inode->i_mapping, 0, -1);
-+ close_bdev_excl(dev->blkdev);
-+ dev->blkdev = NULL;
-+}
-+
-+static void block2mtd_free_device(struct block2mtd_dev *dev)
-+{
-+ if (!dev)
-+ return;
-+
-+ kfree(dev->mtd.name);
-+ _close_bdev(dev);
-+ kfree(dev);
-+}
-+
-+
-+static int block2mtd_refresh(struct mtd_info *mtd)
-+{
-+ struct block2mtd_dev *dev = mtd->priv;
-+ struct block_device *bdev;
-+ dev_t devt;
-+ int err = 0;
-+
-+ /* no other mtd function can run at this point */
-+ write_lock(&dev->bdev_mutex);
-+
-+ /* get the device number for the whole disk */
-+ devt = MKDEV(MAJOR(dev->blkdev->bd_dev), 0);
-+
-+ /* close the old block device */
-+ _close_bdev(dev);
-+
-+ /* open the whole disk, issue a partition rescan, then */
-+ bdev = open_by_devnum(devt, FMODE_WRITE | FMODE_READ);
-+ if (!bdev || !bdev->bd_disk)
-+ err = -EINVAL;
-+ else {
-+ err = rescan_partitions(bdev->bd_disk, bdev);
-+ }
-+ if (bdev)
-+ close_bdev_excl(bdev);
-+
-+ /* try to open the partition block device again */
-+ _open_bdev(dev);
-+ write_unlock(&dev->bdev_mutex);
-+
-+ return err;
-+}
-+
-+/* FIXME: ensure that mtd->size % erase_size == 0 */
-+static struct block2mtd_dev *add_device(char *devname, int erase_size, char *mtdname)
-+{
-+ struct block2mtd_dev *dev;
-+ struct mtd_partition *part;
-+
-+ if (!devname)
-+ return NULL;
-+
-+ dev = kzalloc(sizeof(struct block2mtd_dev) + strlen(devname) + 1, GFP_KERNEL);
-+ if (!dev)
-+ return NULL;
-+
-+ strcpy(dev->devname, devname);
-+
-+ if (_open_bdev(dev))
-+ goto devinit_err;
-+
- mutex_init(&dev->write_mutex);
-+ rwlock_init(&dev->bdev_mutex);
-
- /* Setup the MTD structure */
- /* make the name contain the block device in */
-@@ -304,6 +397,7 @@
- dev->mtd.read = block2mtd_read;
- dev->mtd.priv = dev;
- dev->mtd.owner = THIS_MODULE;
-+ dev->mtd.refresh_device = block2mtd_refresh;
-
- part = kzalloc(sizeof(struct mtd_partition), GFP_KERNEL);
- part->name = dev->mtd.name;
---- a/drivers/mtd/mtdchar.c
-+++ b/drivers/mtd/mtdchar.c
-@@ -17,6 +17,7 @@
-
- #include <linux/mtd/mtd.h>
- #include <linux/mtd/compatmac.h>
-+#include <linux/mtd/partitions.h>
-
- #include <asm/uaccess.h>
-
-@@ -753,6 +754,13 @@
- file->f_pos = 0;
- break;
- }
-+#ifdef CONFIG_MTD_PARTITIONS
-+ case MTDREFRESH:
-+ {
-+ ret = refresh_mtd_partitions(mtd);
-+ break;
-+ }
-+#endif
-
- default:
- ret = -ENOTTY;
---- a/include/linux/mtd/mtd.h
-+++ b/include/linux/mtd/mtd.h
-@@ -98,6 +98,7 @@
- uint8_t *oobbuf;
- };
-
-+struct mtd_info;
- struct mtd_info {
- u_char type;
- u_int32_t flags;
-@@ -195,6 +196,9 @@
- struct module *owner;
- int usecount;
-
-+ int (*refresh_device)(struct mtd_info *mtd);
-+ struct mtd_info *split;
-+
- /* If the driver is something smart, like UBI, it may need to maintain
- * its own reference counting. The below functions are only for driver.
- * The driver may register its callbacks. These callbacks are not
---- a/include/linux/mtd/partitions.h
-+++ b/include/linux/mtd/partitions.h
-@@ -36,6 +36,7 @@
- * erasesize aligned (e.g. use MTDPART_OFS_NEXTBLK).
- */
-
-+struct mtd_partition;
- struct mtd_partition {
- char *name; /* identifier string */
- u_int32_t size; /* partition size */
-@@ -43,6 +44,7 @@
- u_int32_t mask_flags; /* master MTD flags to mask out for this partition */
- struct nand_ecclayout *ecclayout; /* out of band layout for this partition (NAND only)*/
- struct mtd_info **mtdp; /* pointer to store the MTD object */
-+ int (*refresh_partition)(struct mtd_info *);
- };
-
- #define MTDPART_OFS_NXTBLK (-2)
-@@ -52,6 +54,7 @@
-
- int add_mtd_partitions(struct mtd_info *, const struct mtd_partition *, int);
- int del_mtd_partitions(struct mtd_info *);
-+int refresh_mtd_partitions(struct mtd_info *);
-
- /*
- * Functions dealing with the various ways of partitioning the space
---- a/include/mtd/mtd-abi.h
-+++ b/include/mtd/mtd-abi.h
-@@ -95,6 +95,7 @@
- #define ECCGETLAYOUT _IOR('M', 17, struct nand_ecclayout)
- #define ECCGETSTATS _IOR('M', 18, struct mtd_ecc_stats)
- #define MTDFILEMODE _IO('M', 19)
-+#define MTDREFRESH _IO('M', 23)
-
- /*
- * Obsolete legacy interface. Keep it in order not to break userspace
+++ /dev/null
---- a/drivers/mtd/redboot.c
-+++ b/drivers/mtd/redboot.c
-@@ -236,14 +236,21 @@
- #endif
- names += strlen(names)+1;
-
--#ifdef CONFIG_MTD_REDBOOT_PARTS_UNALLOCATED
- if(fl->next && fl->img->flash_base + fl->img->size + master->erasesize <= fl->next->img->flash_base) {
-- i++;
-- parts[i].offset = parts[i-1].size + parts[i-1].offset;
-- parts[i].size = fl->next->img->flash_base - parts[i].offset;
-- parts[i].name = nullname;
-- }
-+ if (!strcmp(parts[i].name, "rootfs")) {
-+ parts[i].size = fl->next->img->flash_base;
-+ parts[i].size &= ~(master->erasesize - 1);
-+ parts[i].size -= parts[i].offset;
-+#ifdef CONFIG_MTD_REDBOOT_PARTS_UNALLOCATED
-+ nrparts--;
-+ } else {
-+ i++;
-+ parts[i].offset = parts[i-1].size + parts[i-1].offset;
-+ parts[i].size = fl->next->img->flash_base - parts[i].offset;
-+ parts[i].name = nullname;
- #endif
-+ }
-+ }
- tmp_fl = fl;
- fl = fl->next;
- kfree(tmp_fl);
+++ /dev/null
---- a/include/linux/mtd/nand.h
-+++ b/include/linux/mtd/nand.h
-@@ -572,6 +572,7 @@
- int chip_delay;
- unsigned int options;
- const char **part_probe_types;
-+ int (*chip_fixup)(struct mtd_info *mtd);
- void *priv;
- };
-
---- a/drivers/mtd/nand/plat_nand.c
-+++ b/drivers/mtd/nand/plat_nand.c
-@@ -70,7 +70,18 @@
- platform_set_drvdata(pdev, data);
-
- /* Scan to find existance of the device */
-- if (nand_scan(&data->mtd, 1)) {
-+ if (nand_scan_ident(&data->mtd, 1)) {
-+ res = -ENXIO;
-+ goto out;
-+ }
-+
-+ if (pdata->chip.chip_fixup) {
-+ res = pdata->chip.chip_fixup(&data->mtd);
-+ if (res)
-+ goto out;
-+ }
-+
-+ if (nand_scan_tail(&data->mtd)) {
- res = -ENXIO;
- goto out;
- }
+++ /dev/null
---- a/net/netfilter/Kconfig
-+++ b/net/netfilter/Kconfig
-@@ -633,6 +633,27 @@
-
- To compile it as a module, choose M here. If unsure, say N.
-
-+config NETFILTER_XT_MATCH_LAYER7
-+ tristate '"layer7" match support'
-+ depends on NETFILTER_XTABLES
-+ depends on EXPERIMENTAL && (IP_NF_CONNTRACK || NF_CONNTRACK)
-+ depends on NF_CT_ACCT
-+ help
-+ Say Y if you want to be able to classify connections (and their
-+ packets) based on regular expression matching of their application
-+ layer data. This is one way to classify applications such as
-+ peer-to-peer filesharing systems that do not always use the same
-+ port.
-+
-+ To compile it as a module, choose M here. If unsure, say N.
-+
-+config NETFILTER_XT_MATCH_LAYER7_DEBUG
-+ bool 'Layer 7 debugging output'
-+ depends on NETFILTER_XT_MATCH_LAYER7
-+ help
-+ Say Y to get lots of debugging output.
-+
-+
- config NETFILTER_XT_MATCH_STATISTIC
- tristate '"statistic" match support'
- depends on NETFILTER_XTABLES
---- a/net/netfilter/Makefile
-+++ b/net/netfilter/Makefile
-@@ -71,6 +71,7 @@
- obj-$(CONFIG_NETFILTER_XT_MATCH_REALM) += xt_realm.o
- obj-$(CONFIG_NETFILTER_XT_MATCH_SCTP) += xt_sctp.o
- obj-$(CONFIG_NETFILTER_XT_MATCH_STATE) += xt_state.o
-+obj-$(CONFIG_NETFILTER_XT_MATCH_LAYER7) += xt_layer7.o
- obj-$(CONFIG_NETFILTER_XT_MATCH_STATISTIC) += xt_statistic.o
- obj-$(CONFIG_NETFILTER_XT_MATCH_STRING) += xt_string.o
- obj-$(CONFIG_NETFILTER_XT_MATCH_TCPMSS) += xt_tcpmss.o
---- /dev/null
-+++ b/net/netfilter/xt_layer7.c
-@@ -0,0 +1,634 @@
-+/*
-+ Kernel module to match application layer (OSI layer 7) data in connections.
-+
-+ http://l7-filter.sf.net
-+
-+ (C) 2003, 2004, 2005, 2006, 2007 Matthew Strait and Ethan Sommer.
-+
-+ 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.
-+ http://www.gnu.org/licenses/gpl.txt
-+
-+ Based on ipt_string.c (C) 2000 Emmanuel Roger <winfield@freegates.be>,
-+ xt_helper.c (C) 2002 Harald Welte and cls_layer7.c (C) 2003 Matthew Strait,
-+ Ethan Sommer, Justin Levandoski.
-+*/
-+
-+#include <linux/spinlock.h>
-+#include <linux/version.h>
-+#include <net/ip.h>
-+#include <net/tcp.h>
-+#include <linux/module.h>
-+#include <linux/skbuff.h>
-+#include <linux/netfilter.h>
-+#include <net/netfilter/nf_conntrack.h>
-+#include <net/netfilter/nf_conntrack_core.h>
-+#include <linux/netfilter/x_tables.h>
-+#include <linux/netfilter/xt_layer7.h>
-+#include <linux/ctype.h>
-+#include <linux/proc_fs.h>
-+
-+#include "regexp/regexp.c"
-+
-+MODULE_LICENSE("GPL");
-+MODULE_AUTHOR("Matthew Strait <quadong@users.sf.net>, Ethan Sommer <sommere@users.sf.net>");
-+MODULE_DESCRIPTION("iptables application layer match module");
-+MODULE_ALIAS("ipt_layer7");
-+MODULE_VERSION("2.17");
-+
-+static int maxdatalen = 2048; // this is the default
-+module_param(maxdatalen, int, 0444);
-+MODULE_PARM_DESC(maxdatalen, "maximum bytes of data looked at by l7-filter");
-+#ifdef CONFIG_NETFILTER_XT_MATCH_LAYER7_DEBUG
-+ #define DPRINTK(format,args...) printk(format,##args)
-+#else
-+ #define DPRINTK(format,args...)
-+#endif
-+
-+#define TOTAL_PACKETS master_conntrack->counters[IP_CT_DIR_ORIGINAL].packets + \
-+ master_conntrack->counters[IP_CT_DIR_REPLY].packets
-+
-+/* Number of packets whose data we look at.
-+This can be modified through /proc/net/layer7_numpackets */
-+static int num_packets = 10;
-+
-+static struct pattern_cache {
-+ char * regex_string;
-+ regexp * pattern;
-+ struct pattern_cache * next;
-+} * first_pattern_cache = NULL;
-+
-+DEFINE_SPINLOCK(l7_lock);
-+
-+#ifdef CONFIG_IP_NF_MATCH_LAYER7_DEBUG
-+/* Converts an unfriendly string into a friendly one by
-+replacing unprintables with periods and all whitespace with " ". */
-+static char * friendly_print(unsigned char * s)
-+{
-+ char * f = kmalloc(strlen(s) + 1, GFP_ATOMIC);
-+ int i;
-+
-+ if(!f) {
-+ if (net_ratelimit())
-+ printk(KERN_ERR "layer7: out of memory in "
-+ "friendly_print, bailing.\n");
-+ return NULL;
-+ }
-+
-+ for(i = 0; i < strlen(s); i++){
-+ if(isprint(s[i]) && s[i] < 128) f[i] = s[i];
-+ else if(isspace(s[i])) f[i] = ' ';
-+ else f[i] = '.';
-+ }
-+ f[i] = '\0';
-+ return f;
-+}
-+
-+static char dec2hex(int i)
-+{
-+ switch (i) {
-+ case 0 ... 9:
-+ return (i + '0');
-+ break;
-+ case 10 ... 15:
-+ return (i - 10 + 'a');
-+ break;
-+ default:
-+ if (net_ratelimit())
-+ printk("layer7: Problem in dec2hex\n");
-+ return '\0';
-+ }
-+}
-+
-+static char * hex_print(unsigned char * s)
-+{
-+ char * g = kmalloc(strlen(s)*3 + 1, GFP_ATOMIC);
-+ int i;
-+
-+ if(!g) {
-+ if (net_ratelimit())
-+ printk(KERN_ERR "layer7: out of memory in hex_print, "
-+ "bailing.\n");
-+ return NULL;
-+ }
-+
-+ for(i = 0; i < strlen(s); i++) {
-+ g[i*3 ] = dec2hex(s[i]/16);
-+ g[i*3 + 1] = dec2hex(s[i]%16);
-+ g[i*3 + 2] = ' ';
-+ }
-+ g[i*3] = '\0';
-+
-+ return g;
-+}
-+#endif // DEBUG
-+
-+/* Use instead of regcomp. As we expect to be seeing the same regexps over and
-+over again, it make sense to cache the results. */
-+static regexp * compile_and_cache(const char * regex_string,
-+ const char * protocol)
-+{
-+ struct pattern_cache * node = first_pattern_cache;
-+ struct pattern_cache * last_pattern_cache = first_pattern_cache;
-+ struct pattern_cache * tmp;
-+ unsigned int len;
-+
-+ while (node != NULL) {
-+ if (!strcmp(node->regex_string, regex_string))
-+ return node->pattern;
-+
-+ last_pattern_cache = node;/* points at the last non-NULL node */
-+ node = node->next;
-+ }
-+
-+ /* If we reach the end of the list, then we have not yet cached
-+ the pattern for this regex. Let's do that now.
-+ Be paranoid about running out of memory to avoid list corruption. */
-+ tmp = kmalloc(sizeof(struct pattern_cache), GFP_ATOMIC);
-+
-+ if(!tmp) {
-+ if (net_ratelimit())
-+ printk(KERN_ERR "layer7: out of memory in "
-+ "compile_and_cache, bailing.\n");
-+ return NULL;
-+ }
-+
-+ tmp->regex_string = kmalloc(strlen(regex_string) + 1, GFP_ATOMIC);
-+ tmp->pattern = kmalloc(sizeof(struct regexp), GFP_ATOMIC);
-+ tmp->next = NULL;
-+
-+ if(!tmp->regex_string || !tmp->pattern) {
-+ if (net_ratelimit())
-+ printk(KERN_ERR "layer7: out of memory in "
-+ "compile_and_cache, bailing.\n");
-+ kfree(tmp->regex_string);
-+ kfree(tmp->pattern);
-+ kfree(tmp);
-+ return NULL;
-+ }
-+
-+ /* Ok. The new node is all ready now. */
-+ node = tmp;
-+
-+ if(first_pattern_cache == NULL) /* list is empty */
-+ first_pattern_cache = node; /* make node the beginning */
-+ else
-+ last_pattern_cache->next = node; /* attach node to the end */
-+
-+ /* copy the string and compile the regex */
-+ len = strlen(regex_string);
-+ DPRINTK("About to compile this: \"%s\"\n", regex_string);
-+ node->pattern = regcomp((char *)regex_string, &len);
-+ if ( !node->pattern ) {
-+ if (net_ratelimit())
-+ printk(KERN_ERR "layer7: Error compiling regexp "
-+ "\"%s\" (%s)\n",
-+ regex_string, protocol);
-+ /* pattern is now cached as NULL, so we won't try again. */
-+ }
-+
-+ strcpy(node->regex_string, regex_string);
-+ return node->pattern;
-+}
-+
-+static int can_handle(const struct sk_buff *skb)
-+{
-+ if(!ip_hdr(skb)) /* not IP */
-+ return 0;
-+ if(ip_hdr(skb)->protocol != IPPROTO_TCP &&
-+ ip_hdr(skb)->protocol != IPPROTO_UDP &&
-+ ip_hdr(skb)->protocol != IPPROTO_ICMP)
-+ return 0;
-+ return 1;
-+}
-+
-+/* Returns offset the into the skb->data that the application data starts */
-+static int app_data_offset(const struct sk_buff *skb)
-+{
-+ /* In case we are ported somewhere (ebtables?) where ip_hdr(skb)
-+ isn't set, this can be gotten from 4*(skb->data[0] & 0x0f) as well. */
-+ int ip_hl = 4*ip_hdr(skb)->ihl;
-+
-+ if( ip_hdr(skb)->protocol == IPPROTO_TCP ) {
-+ /* 12 == offset into TCP header for the header length field.
-+ Can't get this with skb->h.th->doff because the tcphdr
-+ struct doesn't get set when routing (this is confirmed to be
-+ true in Netfilter as well as QoS.) */
-+ int tcp_hl = 4*(skb->data[ip_hl + 12] >> 4);
-+
-+ return ip_hl + tcp_hl;
-+ } else if( ip_hdr(skb)->protocol == IPPROTO_UDP ) {
-+ return ip_hl + 8; /* UDP header is always 8 bytes */
-+ } else if( ip_hdr(skb)->protocol == IPPROTO_ICMP ) {
-+ return ip_hl + 8; /* ICMP header is 8 bytes */
-+ } else {
-+ if (net_ratelimit())
-+ printk(KERN_ERR "layer7: tried to handle unknown "
-+ "protocol!\n");
-+ return ip_hl + 8; /* something reasonable */
-+ }
-+}
-+
-+/* handles whether there's a match when we aren't appending data anymore */
-+static int match_no_append(struct nf_conn * conntrack,
-+ struct nf_conn * master_conntrack,
-+ enum ip_conntrack_info ctinfo,
-+ enum ip_conntrack_info master_ctinfo,
-+ const struct xt_layer7_info * info)
-+{
-+ /* If we're in here, throw the app data away */
-+ if(master_conntrack->layer7.app_data != NULL) {
-+
-+ #ifdef CONFIG_IP_NF_MATCH_LAYER7_DEBUG
-+ if(!master_conntrack->layer7.app_proto) {
-+ char * f =
-+ friendly_print(master_conntrack->layer7.app_data);
-+ char * g =
-+ hex_print(master_conntrack->layer7.app_data);
-+ DPRINTK("\nl7-filter gave up after %d bytes "
-+ "(%d packets):\n%s\n",
-+ strlen(f), TOTAL_PACKETS, f);
-+ kfree(f);
-+ DPRINTK("In hex: %s\n", g);
-+ kfree(g);
-+ }
-+ #endif
-+
-+ kfree(master_conntrack->layer7.app_data);
-+ master_conntrack->layer7.app_data = NULL; /* don't free again */
-+ }
-+
-+ if(master_conntrack->layer7.app_proto){
-+ /* Here child connections set their .app_proto (for /proc) */
-+ if(!conntrack->layer7.app_proto) {
-+ conntrack->layer7.app_proto =
-+ kmalloc(strlen(master_conntrack->layer7.app_proto)+1,
-+ GFP_ATOMIC);
-+ if(!conntrack->layer7.app_proto){
-+ if (net_ratelimit())
-+ printk(KERN_ERR "layer7: out of memory "
-+ "in match_no_append, "
-+ "bailing.\n");
-+ return 1;
-+ }
-+ strcpy(conntrack->layer7.app_proto,
-+ master_conntrack->layer7.app_proto);
-+ }
-+
-+ return (!strcmp(master_conntrack->layer7.app_proto,
-+ info->protocol));
-+ }
-+ else {
-+ /* If not classified, set to "unknown" to distinguish from
-+ connections that are still being tested. */
-+ master_conntrack->layer7.app_proto =
-+ kmalloc(strlen("unknown")+1, GFP_ATOMIC);
-+ if(!master_conntrack->layer7.app_proto){
-+ if (net_ratelimit())
-+ printk(KERN_ERR "layer7: out of memory in "
-+ "match_no_append, bailing.\n");
-+ return 1;
-+ }
-+ strcpy(master_conntrack->layer7.app_proto, "unknown");
-+ return 0;
-+ }
-+}
-+
-+/* add the new app data to the conntrack. Return number of bytes added. */
-+static int add_data(struct nf_conn * master_conntrack,
-+ char * app_data, int appdatalen)
-+{
-+ int length = 0, i;
-+ int oldlength = master_conntrack->layer7.app_data_len;
-+
-+ /* This is a fix for a race condition by Deti Fliegl. However, I'm not
-+ clear on whether the race condition exists or whether this really
-+ fixes it. I might just be being dense... Anyway, if it's not really
-+ a fix, all it does is waste a very small amount of time. */
-+ if(!master_conntrack->layer7.app_data) return 0;
-+
-+ /* Strip nulls. Make everything lower case (our regex lib doesn't
-+ do case insensitivity). Add it to the end of the current data. */
-+ for(i = 0; i < maxdatalen-oldlength-1 &&
-+ i < appdatalen; i++) {
-+ if(app_data[i] != '\0') {
-+ /* the kernel version of tolower mungs 'upper ascii' */
-+ master_conntrack->layer7.app_data[length+oldlength] =
-+ isascii(app_data[i])?
-+ tolower(app_data[i]) : app_data[i];
-+ length++;
-+ }
-+ }
-+
-+ master_conntrack->layer7.app_data[length+oldlength] = '\0';
-+ master_conntrack->layer7.app_data_len = length + oldlength;
-+
-+ return length;
-+}
-+
-+/* taken from drivers/video/modedb.c */
-+static int my_atoi(const char *s)
-+{
-+ int val = 0;
-+
-+ for (;; s++) {
-+ switch (*s) {
-+ case '0'...'9':
-+ val = 10*val+(*s-'0');
-+ break;
-+ default:
-+ return val;
-+ }
-+ }
-+}
-+
-+/* write out num_packets to userland. */
-+static int layer7_read_proc(char* page, char ** start, off_t off, int count,
-+ int* eof, void * data)
-+{
-+ if(num_packets > 99 && net_ratelimit())
-+ printk(KERN_ERR "layer7: NOT REACHED. num_packets too big\n");
-+
-+ page[0] = num_packets/10 + '0';
-+ page[1] = num_packets%10 + '0';
-+ page[2] = '\n';
-+ page[3] = '\0';
-+
-+ *eof=1;
-+
-+ return 3;
-+}
-+
-+/* Read in num_packets from userland */
-+static int layer7_write_proc(struct file* file, const char* buffer,
-+ unsigned long count, void *data)
-+{
-+ char * foo = kmalloc(count, GFP_ATOMIC);
-+
-+ if(!foo){
-+ if (net_ratelimit())
-+ printk(KERN_ERR "layer7: out of memory, bailing. "
-+ "num_packets unchanged.\n");
-+ return count;
-+ }
-+
-+ if(copy_from_user(foo, buffer, count)) {
-+ return -EFAULT;
-+ }
-+
-+
-+ num_packets = my_atoi(foo);
-+ kfree (foo);
-+
-+ /* This has an arbitrary limit to make the math easier. I'm lazy.
-+ But anyway, 99 is a LOT! If you want more, you're doing it wrong! */
-+ if(num_packets > 99) {
-+ printk(KERN_WARNING "layer7: num_packets can't be > 99.\n");
-+ num_packets = 99;
-+ } else if(num_packets < 1) {
-+ printk(KERN_WARNING "layer7: num_packets can't be < 1.\n");
-+ num_packets = 1;
-+ }
-+
-+ return count;
-+}
-+
-+static bool
-+match(const struct sk_buff *skbin,
-+ const struct net_device *in,
-+ const struct net_device *out,
-+ const struct xt_match *match,
-+ const void *matchinfo,
-+ int offset,
-+ unsigned int protoff,
-+ bool *hotdrop)
-+{
-+ /* sidestep const without getting a compiler warning... */
-+ struct sk_buff * skb = (struct sk_buff *)skbin;
-+
-+ const struct xt_layer7_info * info = matchinfo;
-+ enum ip_conntrack_info master_ctinfo, ctinfo;
-+ struct nf_conn *master_conntrack, *conntrack;
-+ unsigned char * app_data;
-+ unsigned int pattern_result, appdatalen;
-+ regexp * comppattern;
-+
-+ /* Be paranoid/incompetent - lock the entire match function. */
-+ spin_lock_bh(&l7_lock);
-+
-+ if(!can_handle(skb)){
-+ DPRINTK("layer7: This is some protocol I can't handle.\n");
-+ spin_unlock_bh(&l7_lock);
-+ return info->invert;
-+ }
-+
-+ /* Treat parent & all its children together as one connection, except
-+ for the purpose of setting conntrack->layer7.app_proto in the actual
-+ connection. This makes /proc/net/ip_conntrack more satisfying. */
-+ if(!(conntrack = nf_ct_get(skb, &ctinfo)) ||
-+ !(master_conntrack=nf_ct_get(skb,&master_ctinfo))){
-+ DPRINTK("layer7: couldn't get conntrack.\n");
-+ spin_unlock_bh(&l7_lock);
-+ return info->invert;
-+ }
-+
-+ /* Try to get a master conntrack (and its master etc) for FTP, etc. */
-+ while (master_ct(master_conntrack) != NULL)
-+ master_conntrack = master_ct(master_conntrack);
-+
-+ /* if we've classified it or seen too many packets */
-+ if(TOTAL_PACKETS > num_packets ||
-+ master_conntrack->layer7.app_proto) {
-+
-+ pattern_result = match_no_append(conntrack, master_conntrack,
-+ ctinfo, master_ctinfo, info);
-+
-+ /* skb->cb[0] == seen. Don't do things twice if there are
-+ multiple l7 rules. I'm not sure that using cb for this purpose
-+ is correct, even though it says "put your private variables
-+ there". But it doesn't look like it is being used for anything
-+ else in the skbs that make it here. */
-+ skb->cb[0] = 1; /* marking it seen here's probably irrelevant */
-+
-+ spin_unlock_bh(&l7_lock);
-+ return (pattern_result ^ info->invert);
-+ }
-+
-+ if(skb_is_nonlinear(skb)){
-+ if(skb_linearize(skb) != 0){
-+ if (net_ratelimit())
-+ printk(KERN_ERR "layer7: failed to linearize "
-+ "packet, bailing.\n");
-+ spin_unlock_bh(&l7_lock);
-+ return info->invert;
-+ }
-+ }
-+
-+ /* now that the skb is linearized, it's safe to set these. */
-+ app_data = skb->data + app_data_offset(skb);
-+ appdatalen = skb_tail_pointer(skb) - app_data;
-+
-+ /* the return value gets checked later, when we're ready to use it */
-+ comppattern = compile_and_cache(info->pattern, info->protocol);
-+
-+ /* On the first packet of a connection, allocate space for app data */
-+ if(TOTAL_PACKETS == 1 && !skb->cb[0] &&
-+ !master_conntrack->layer7.app_data){
-+ master_conntrack->layer7.app_data =
-+ kmalloc(maxdatalen, GFP_ATOMIC);
-+ if(!master_conntrack->layer7.app_data){
-+ if (net_ratelimit())
-+ printk(KERN_ERR "layer7: out of memory in "
-+ "match, bailing.\n");
-+ spin_unlock_bh(&l7_lock);
-+ return info->invert;
-+ }
-+
-+ master_conntrack->layer7.app_data[0] = '\0';
-+ }
-+
-+ /* Can be here, but unallocated, if numpackets is increased near
-+ the beginning of a connection */
-+ if(master_conntrack->layer7.app_data == NULL){
-+ spin_unlock_bh(&l7_lock);
-+ return (info->invert); /* unmatched */
-+ }
-+
-+ if(!skb->cb[0]){
-+ int newbytes;
-+ newbytes = add_data(master_conntrack, app_data, appdatalen);
-+
-+ if(newbytes == 0) { /* didn't add any data */
-+ skb->cb[0] = 1;
-+ /* Didn't match before, not going to match now */
-+ spin_unlock_bh(&l7_lock);
-+ return info->invert;
-+ }
-+ }
-+
-+ /* If looking for "unknown", then never match. "Unknown" means that
-+ we've given up; we're still trying with these packets. */
-+ if(!strcmp(info->protocol, "unknown")) {
-+ pattern_result = 0;
-+ /* If looking for "unset", then always match. "Unset" means that we
-+ haven't yet classified the connection. */
-+ } else if(!strcmp(info->protocol, "unset")) {
-+ pattern_result = 2;
-+ DPRINTK("layer7: matched unset: not yet classified "
-+ "(%d/%d packets)\n", TOTAL_PACKETS, num_packets);
-+ /* If the regexp failed to compile, don't bother running it */
-+ } else if(comppattern &&
-+ regexec(comppattern, master_conntrack->layer7.app_data)){
-+ DPRINTK("layer7: matched %s\n", info->protocol);
-+ pattern_result = 1;
-+ } else pattern_result = 0;
-+
-+ if(pattern_result == 1) {
-+ master_conntrack->layer7.app_proto =
-+ kmalloc(strlen(info->protocol)+1, GFP_ATOMIC);
-+ if(!master_conntrack->layer7.app_proto){
-+ if (net_ratelimit())
-+ printk(KERN_ERR "layer7: out of memory in "
-+ "match, bailing.\n");
-+ spin_unlock_bh(&l7_lock);
-+ return (pattern_result ^ info->invert);
-+ }
-+ strcpy(master_conntrack->layer7.app_proto, info->protocol);
-+ } else if(pattern_result > 1) { /* cleanup from "unset" */
-+ pattern_result = 1;
-+ }
-+
-+ /* mark the packet seen */
-+ skb->cb[0] = 1;
-+
-+ spin_unlock_bh(&l7_lock);
-+ return (pattern_result ^ info->invert);
-+}
-+
-+static bool check(const char *tablename,
-+ const void *inf,
-+ const struct xt_match *match,
-+ void *matchinfo,
-+ unsigned int hook_mask)
-+
-+{
-+ // load nf_conntrack_ipv4
-+ if (nf_ct_l3proto_try_module_get(match->family) < 0) {
-+ printk(KERN_WARNING "can't load conntrack support for "
-+ "proto=%d\n", match->family);
-+ return false;
-+ }
-+ return true;
-+}
-+
-+static void
-+destroy(const struct xt_match *match, void *matchinfo)
-+{
-+ nf_ct_l3proto_module_put(match->family);
-+}
-+
-+static struct xt_match xt_layer7_match[] = {
-+{
-+ .name = "layer7",
-+ .family = AF_INET,
-+ .checkentry = check,
-+ .match = match,
-+ .destroy = destroy,
-+ .matchsize = sizeof(struct xt_layer7_info),
-+ .me = THIS_MODULE
-+}
-+};
-+
-+static void layer7_cleanup_proc(void)
-+{
-+#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,23)
-+ remove_proc_entry("layer7_numpackets", proc_net);
-+#else
-+ remove_proc_entry("layer7_numpackets", init_net.proc_net);
-+#endif
-+}
-+
-+/* register the proc file */
-+static void layer7_init_proc(void)
-+{
-+ struct proc_dir_entry* entry;
-+#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,23)
-+ entry = create_proc_entry("layer7_numpackets", 0644, proc_net);
-+#else
-+ entry = create_proc_entry("layer7_numpackets", 0644, init_net.proc_net);
-+#endif
-+ entry->read_proc = layer7_read_proc;
-+ entry->write_proc = layer7_write_proc;
-+}
-+
-+static int __init xt_layer7_init(void)
-+{
-+ need_conntrack();
-+
-+ layer7_init_proc();
-+ if(maxdatalen < 1) {
-+ printk(KERN_WARNING "layer7: maxdatalen can't be < 1, "
-+ "using 1\n");
-+ maxdatalen = 1;
-+ }
-+ /* This is not a hard limit. It's just here to prevent people from
-+ bringing their slow machines to a grinding halt. */
-+ else if(maxdatalen > 65536) {
-+ printk(KERN_WARNING "layer7: maxdatalen can't be > 65536, "
-+ "using 65536\n");
-+ maxdatalen = 65536;
-+ }
-+ return xt_register_matches(xt_layer7_match,
-+ ARRAY_SIZE(xt_layer7_match));
-+}
-+
-+static void __exit xt_layer7_fini(void)
-+{
-+ layer7_cleanup_proc();
-+ xt_unregister_matches(xt_layer7_match, ARRAY_SIZE(xt_layer7_match));
-+}
-+
-+module_init(xt_layer7_init);
-+module_exit(xt_layer7_fini);
---- /dev/null
-+++ b/net/netfilter/regexp/regexp.c
-@@ -0,0 +1,1197 @@
-+/*
-+ * regcomp and regexec -- regsub and regerror are elsewhere
-+ * @(#)regexp.c 1.3 of 18 April 87
-+ *
-+ * Copyright (c) 1986 by University of Toronto.
-+ * Written by Henry Spencer. Not derived from licensed software.
-+ *
-+ * Permission is granted to anyone to use this software for any
-+ * purpose on any computer system, and to redistribute it freely,
-+ * subject to the following restrictions:
-+ *
-+ * 1. The author is not responsible for the consequences of use of
-+ * this software, no matter how awful, even if they arise
-+ * from defects in it.
-+ *
-+ * 2. The origin of this software must not be misrepresented, either
-+ * by explicit claim or by omission.
-+ *
-+ * 3. Altered versions must be plainly marked as such, and must not
-+ * be misrepresented as being the original software.
-+ *
-+ * Beware that some of this code is subtly aware of the way operator
-+ * precedence is structured in regular expressions. Serious changes in
-+ * regular-expression syntax might require a total rethink.
-+ *
-+ * This code was modified by Ethan Sommer to work within the kernel
-+ * (it now uses kmalloc etc..)
-+ *
-+ * Modified slightly by Matthew Strait to use more modern C.
-+ */
-+
-+#include "regexp.h"
-+#include "regmagic.h"
-+
-+/* added by ethan and matt. Lets it work in both kernel and user space.
-+(So iptables can use it, for instance.) Yea, it goes both ways... */
-+#if __KERNEL__
-+ #define malloc(foo) kmalloc(foo,GFP_ATOMIC)
-+#else
-+ #define printk(format,args...) printf(format,##args)
-+#endif
-+
-+void regerror(char * s)
-+{
-+ printk("<3>Regexp: %s\n", s);
-+ /* NOTREACHED */
-+}
-+
-+/*
-+ * The "internal use only" fields in regexp.h are present to pass info from
-+ * compile to execute that permits the execute phase to run lots faster on
-+ * simple cases. They are:
-+ *
-+ * regstart char that must begin a match; '\0' if none obvious
-+ * reganch is the match anchored (at beginning-of-line only)?
-+ * regmust string (pointer into program) that match must include, or NULL
-+ * regmlen length of regmust string
-+ *
-+ * Regstart and reganch permit very fast decisions on suitable starting points
-+ * for a match, cutting down the work a lot. Regmust permits fast rejection
-+ * of lines that cannot possibly match. The regmust tests are costly enough
-+ * that regcomp() supplies a regmust only if the r.e. contains something
-+ * potentially expensive (at present, the only such thing detected is * or +
-+ * at the start of the r.e., which can involve a lot of backup). Regmlen is
-+ * supplied because the test in regexec() needs it and regcomp() is computing
-+ * it anyway.
-+ */
-+
-+/*
-+ * Structure for regexp "program". This is essentially a linear encoding
-+ * of a nondeterministic finite-state machine (aka syntax charts or
-+ * "railroad normal form" in parsing technology). Each node is an opcode
-+ * plus a "next" pointer, possibly plus an operand. "Next" pointers of
-+ * all nodes except BRANCH implement concatenation; a "next" pointer with
-+ * a BRANCH on both ends of it is connecting two alternatives. (Here we
-+ * have one of the subtle syntax dependencies: an individual BRANCH (as
-+ * opposed to a collection of them) is never concatenated with anything
-+ * because of operator precedence.) The operand of some types of node is
-+ * a literal string; for others, it is a node leading into a sub-FSM. In
-+ * particular, the operand of a BRANCH node is the first node of the branch.
-+ * (NB this is *not* a tree structure: the tail of the branch connects
-+ * to the thing following the set of BRANCHes.) The opcodes are:
-+ */
-+
-+/* definition number opnd? meaning */
-+#define END 0 /* no End of program. */
-+#define BOL 1 /* no Match "" at beginning of line. */
-+#define EOL 2 /* no Match "" at end of line. */
-+#define ANY 3 /* no Match any one character. */
-+#define ANYOF 4 /* str Match any character in this string. */
-+#define ANYBUT 5 /* str Match any character not in this string. */
-+#define BRANCH 6 /* node Match this alternative, or the next... */
-+#define BACK 7 /* no Match "", "next" ptr points backward. */
-+#define EXACTLY 8 /* str Match this string. */
-+#define NOTHING 9 /* no Match empty string. */
-+#define STAR 10 /* node Match this (simple) thing 0 or more times. */
-+#define PLUS 11 /* node Match this (simple) thing 1 or more times. */
-+#define OPEN 20 /* no Mark this point in input as start of #n. */
-+ /* OPEN+1 is number 1, etc. */
-+#define CLOSE 30 /* no Analogous to OPEN. */
-+
-+/*
-+ * Opcode notes:
-+ *
-+ * BRANCH The set of branches constituting a single choice are hooked
-+ * together with their "next" pointers, since precedence prevents
-+ * anything being concatenated to any individual branch. The
-+ * "next" pointer of the last BRANCH in a choice points to the
-+ * thing following the whole choice. This is also where the
-+ * final "next" pointer of each individual branch points; each
-+ * branch starts with the operand node of a BRANCH node.
-+ *
-+ * BACK Normal "next" pointers all implicitly point forward; BACK
-+ * exists to make loop structures possible.
-+ *
-+ * STAR,PLUS '?', and complex '*' and '+', are implemented as circular
-+ * BRANCH structures using BACK. Simple cases (one character
-+ * per match) are implemented with STAR and PLUS for speed
-+ * and to minimize recursive plunges.
-+ *
-+ * OPEN,CLOSE ...are numbered at compile time.
-+ */
-+
-+/*
-+ * A node is one char of opcode followed by two chars of "next" pointer.
-+ * "Next" pointers are stored as two 8-bit pieces, high order first. The
-+ * value is a positive offset from the opcode of the node containing it.
-+ * An operand, if any, simply follows the node. (Note that much of the
-+ * code generation knows about this implicit relationship.)
-+ *
-+ * Using two bytes for the "next" pointer is vast overkill for most things,
-+ * but allows patterns to get big without disasters.
-+ */
-+#define OP(p) (*(p))
-+#define NEXT(p) (((*((p)+1)&0377)<<8) + (*((p)+2)&0377))
-+#define OPERAND(p) ((p) + 3)
-+
-+/*
-+ * See regmagic.h for one further detail of program structure.
-+ */
-+
-+
-+/*
-+ * Utility definitions.
-+ */
-+#ifndef CHARBITS
-+#define UCHARAT(p) ((int)*(unsigned char *)(p))
-+#else
-+#define UCHARAT(p) ((int)*(p)&CHARBITS)
-+#endif
-+
-+#define FAIL(m) { regerror(m); return(NULL); }
-+#define ISMULT(c) ((c) == '*' || (c) == '+' || (c) == '?')
-+#define META "^$.[()|?+*\\"
-+
-+/*
-+ * Flags to be passed up and down.
-+ */
-+#define HASWIDTH 01 /* Known never to match null string. */
-+#define SIMPLE 02 /* Simple enough to be STAR/PLUS operand. */
-+#define SPSTART 04 /* Starts with * or +. */
-+#define WORST 0 /* Worst case. */
-+
-+/*
-+ * Global work variables for regcomp().
-+ */
-+struct match_globals {
-+char *reginput; /* String-input pointer. */
-+char *regbol; /* Beginning of input, for ^ check. */
-+char **regstartp; /* Pointer to startp array. */
-+char **regendp; /* Ditto for endp. */
-+char *regparse; /* Input-scan pointer. */
-+int regnpar; /* () count. */
-+char regdummy;
-+char *regcode; /* Code-emit pointer; ®dummy = don't. */
-+long regsize; /* Code size. */
-+};
-+
-+/*
-+ * Forward declarations for regcomp()'s friends.
-+ */
-+#ifndef STATIC
-+#define STATIC static
-+#endif
-+STATIC char *reg(struct match_globals *g, int paren,int *flagp);
-+STATIC char *regbranch(struct match_globals *g, int *flagp);
-+STATIC char *regpiece(struct match_globals *g, int *flagp);
-+STATIC char *regatom(struct match_globals *g, int *flagp);
-+STATIC char *regnode(struct match_globals *g, char op);
-+STATIC char *regnext(struct match_globals *g, char *p);
-+STATIC void regc(struct match_globals *g, char b);
-+STATIC void reginsert(struct match_globals *g, char op, char *opnd);
-+STATIC void regtail(struct match_globals *g, char *p, char *val);
-+STATIC void regoptail(struct match_globals *g, char *p, char *val);
-+
-+
-+__kernel_size_t my_strcspn(const char *s1,const char *s2)
-+{
-+ char *scan1;
-+ char *scan2;
-+ int count;
-+
-+ count = 0;
-+ for (scan1 = (char *)s1; *scan1 != '\0'; scan1++) {
-+ for (scan2 = (char *)s2; *scan2 != '\0';) /* ++ moved down. */
-+ if (*scan1 == *scan2++)
-+ return(count);
-+ count++;
-+ }
-+ return(count);
-+}
-+
-+/*
-+ - regcomp - compile a regular expression into internal code
-+ *
-+ * We can't allocate space until we know how big the compiled form will be,
-+ * but we can't compile it (and thus know how big it is) until we've got a
-+ * place to put the code. So we cheat: we compile it twice, once with code
-+ * generation turned off and size counting turned on, and once "for real".
-+ * This also means that we don't allocate space until we are sure that the
-+ * thing really will compile successfully, and we never have to move the
-+ * code and thus invalidate pointers into it. (Note that it has to be in
-+ * one piece because free() must be able to free it all.)
-+ *
-+ * Beware that the optimization-preparation code in here knows about some
-+ * of the structure of the compiled regexp.
-+ */
-+regexp *
-+regcomp(char *exp,int *patternsize)
-+{
-+ register regexp *r;
-+ register char *scan;
-+ register char *longest;
-+ register int len;
-+ int flags;
-+ struct match_globals g;
-+
-+ /* commented out by ethan
-+ extern char *malloc();
-+ */
-+
-+ if (exp == NULL)
-+ FAIL("NULL argument");
-+
-+ /* First pass: determine size, legality. */
-+ g.regparse = exp;
-+ g.regnpar = 1;
-+ g.regsize = 0L;
-+ g.regcode = &g.regdummy;
-+ regc(&g, MAGIC);
-+ if (reg(&g, 0, &flags) == NULL)
-+ return(NULL);
-+
-+ /* Small enough for pointer-storage convention? */
-+ if (g.regsize >= 32767L) /* Probably could be 65535L. */
-+ FAIL("regexp too big");
-+
-+ /* Allocate space. */
-+ *patternsize=sizeof(regexp) + (unsigned)g.regsize;
-+ r = (regexp *)malloc(sizeof(regexp) + (unsigned)g.regsize);
-+ if (r == NULL)
-+ FAIL("out of space");
-+
-+ /* Second pass: emit code. */
-+ g.regparse = exp;
-+ g.regnpar = 1;
-+ g.regcode = r->program;
-+ regc(&g, MAGIC);
-+ if (reg(&g, 0, &flags) == NULL)
-+ return(NULL);
-+
-+ /* Dig out information for optimizations. */
-+ r->regstart = '\0'; /* Worst-case defaults. */
-+ r->reganch = 0;
-+ r->regmust = NULL;
-+ r->regmlen = 0;
-+ scan = r->program+1; /* First BRANCH. */
-+ if (OP(regnext(&g, scan)) == END) { /* Only one top-level choice. */
-+ scan = OPERAND(scan);
-+
-+ /* Starting-point info. */
-+ if (OP(scan) == EXACTLY)
-+ r->regstart = *OPERAND(scan);
-+ else if (OP(scan) == BOL)
-+ r->reganch++;
-+
-+ /*
-+ * If there's something expensive in the r.e., find the
-+ * longest literal string that must appear and make it the
-+ * regmust. Resolve ties in favor of later strings, since
-+ * the regstart check works with the beginning of the r.e.
-+ * and avoiding duplication strengthens checking. Not a
-+ * strong reason, but sufficient in the absence of others.
-+ */
-+ if (flags&SPSTART) {
-+ longest = NULL;
-+ len = 0;
-+ for (; scan != NULL; scan = regnext(&g, scan))
-+ if (OP(scan) == EXACTLY && strlen(OPERAND(scan)) >= len) {
-+ longest = OPERAND(scan);
-+ len = strlen(OPERAND(scan));
-+ }
-+ r->regmust = longest;
-+ r->regmlen = len;
-+ }
-+ }
-+
-+ return(r);
-+}
-+
-+/*
-+ - reg - regular expression, i.e. main body or parenthesized thing
-+ *
-+ * Caller must absorb opening parenthesis.
-+ *
-+ * Combining parenthesis handling with the base level of regular expression
-+ * is a trifle forced, but the need to tie the tails of the branches to what
-+ * follows makes it hard to avoid.
-+ */
-+static char *
-+reg(struct match_globals *g, int paren, int *flagp /* Parenthesized? */ )
-+{
-+ register char *ret;
-+ register char *br;
-+ register char *ender;
-+ register int parno = 0; /* 0 makes gcc happy */
-+ int flags;
-+
-+ *flagp = HASWIDTH; /* Tentatively. */
-+
-+ /* Make an OPEN node, if parenthesized. */
-+ if (paren) {
-+ if (g->regnpar >= NSUBEXP)
-+ FAIL("too many ()");
-+ parno = g->regnpar;
-+ g->regnpar++;
-+ ret = regnode(g, OPEN+parno);
-+ } else
-+ ret = NULL;
-+
-+ /* Pick up the branches, linking them together. */
-+ br = regbranch(g, &flags);
-+ if (br == NULL)
-+ return(NULL);
-+ if (ret != NULL)
-+ regtail(g, ret, br); /* OPEN -> first. */
-+ else
-+ ret = br;
-+ if (!(flags&HASWIDTH))
-+ *flagp &= ~HASWIDTH;
-+ *flagp |= flags&SPSTART;
-+ while (*g->regparse == '|') {
-+ g->regparse++;
-+ br = regbranch(g, &flags);
-+ if (br == NULL)
-+ return(NULL);
-+ regtail(g, ret, br); /* BRANCH -> BRANCH. */
-+ if (!(flags&HASWIDTH))
-+ *flagp &= ~HASWIDTH;
-+ *flagp |= flags&SPSTART;
-+ }
-+
-+ /* Make a closing node, and hook it on the end. */
-+ ender = regnode(g, (paren) ? CLOSE+parno : END);
-+ regtail(g, ret, ender);
-+
-+ /* Hook the tails of the branches to the closing node. */
-+ for (br = ret; br != NULL; br = regnext(g, br))
-+ regoptail(g, br, ender);
-+
-+ /* Check for proper termination. */
-+ if (paren && *g->regparse++ != ')') {
-+ FAIL("unmatched ()");
-+ } else if (!paren && *g->regparse != '\0') {
-+ if (*g->regparse == ')') {
-+ FAIL("unmatched ()");
-+ } else
-+ FAIL("junk on end"); /* "Can't happen". */
-+ /* NOTREACHED */
-+ }
-+
-+ return(ret);
-+}
-+
-+/*
-+ - regbranch - one alternative of an | operator
-+ *
-+ * Implements the concatenation operator.
-+ */
-+static char *
-+regbranch(struct match_globals *g, int *flagp)
-+{
-+ register char *ret;
-+ register char *chain;
-+ register char *latest;
-+ int flags;
-+
-+ *flagp = WORST; /* Tentatively. */
-+
-+ ret = regnode(g, BRANCH);
-+ chain = NULL;
-+ while (*g->regparse != '\0' && *g->regparse != '|' && *g->regparse != ')') {
-+ latest = regpiece(g, &flags);
-+ if (latest == NULL)
-+ return(NULL);
-+ *flagp |= flags&HASWIDTH;
-+ if (chain == NULL) /* First piece. */
-+ *flagp |= flags&SPSTART;
-+ else
-+ regtail(g, chain, latest);
-+ chain = latest;
-+ }
-+ if (chain == NULL) /* Loop ran zero times. */
-+ (void) regnode(g, NOTHING);
-+
-+ return(ret);
-+}
-+
-+/*
-+ - regpiece - something followed by possible [*+?]
-+ *
-+ * Note that the branching code sequences used for ? and the general cases
-+ * of * and + are somewhat optimized: they use the same NOTHING node as
-+ * both the endmarker for their branch list and the body of the last branch.
-+ * It might seem that this node could be dispensed with entirely, but the
-+ * endmarker role is not redundant.
-+ */
-+static char *
-+regpiece(struct match_globals *g, int *flagp)
-+{
-+ register char *ret;
-+ register char op;
-+ register char *next;
-+ int flags;
-+
-+ ret = regatom(g, &flags);
-+ if (ret == NULL)
-+ return(NULL);
-+
-+ op = *g->regparse;
-+ if (!ISMULT(op)) {
-+ *flagp = flags;
-+ return(ret);
-+ }
-+
-+ if (!(flags&HASWIDTH) && op != '?')
-+ FAIL("*+ operand could be empty");
-+ *flagp = (op != '+') ? (WORST|SPSTART) : (WORST|HASWIDTH);
-+
-+ if (op == '*' && (flags&SIMPLE))
-+ reginsert(g, STAR, ret);
-+ else if (op == '*') {
-+ /* Emit x* as (x&|), where & means "self". */
-+ reginsert(g, BRANCH, ret); /* Either x */
-+ regoptail(g, ret, regnode(g, BACK)); /* and loop */
-+ regoptail(g, ret, ret); /* back */
-+ regtail(g, ret, regnode(g, BRANCH)); /* or */
-+ regtail(g, ret, regnode(g, NOTHING)); /* null. */
-+ } else if (op == '+' && (flags&SIMPLE))
-+ reginsert(g, PLUS, ret);
-+ else if (op == '+') {
-+ /* Emit x+ as x(&|), where & means "self". */
-+ next = regnode(g, BRANCH); /* Either */
-+ regtail(g, ret, next);
-+ regtail(g, regnode(g, BACK), ret); /* loop back */
-+ regtail(g, next, regnode(g, BRANCH)); /* or */
-+ regtail(g, ret, regnode(g, NOTHING)); /* null. */
-+ } else if (op == '?') {
-+ /* Emit x? as (x|) */
-+ reginsert(g, BRANCH, ret); /* Either x */
-+ regtail(g, ret, regnode(g, BRANCH)); /* or */
-+ next = regnode(g, NOTHING); /* null. */
-+ regtail(g, ret, next);
-+ regoptail(g, ret, next);
-+ }
-+ g->regparse++;
-+ if (ISMULT(*g->regparse))
-+ FAIL("nested *?+");
-+
-+ return(ret);
-+}
-+
-+/*
-+ - regatom - the lowest level
-+ *
-+ * Optimization: gobbles an entire sequence of ordinary characters so that
-+ * it can turn them into a single node, which is smaller to store and
-+ * faster to run. Backslashed characters are exceptions, each becoming a
-+ * separate node; the code is simpler that way and it's not worth fixing.
-+ */
-+static char *
-+regatom(struct match_globals *g, int *flagp)
-+{
-+ register char *ret;
-+ int flags;
-+
-+ *flagp = WORST; /* Tentatively. */
-+
-+ switch (*g->regparse++) {
-+ case '^':
-+ ret = regnode(g, BOL);
-+ break;
-+ case '$':
-+ ret = regnode(g, EOL);
-+ break;
-+ case '.':
-+ ret = regnode(g, ANY);
-+ *flagp |= HASWIDTH|SIMPLE;
-+ break;
-+ case '[': {
-+ register int class;
-+ register int classend;
-+
-+ if (*g->regparse == '^') { /* Complement of range. */
-+ ret = regnode(g, ANYBUT);
-+ g->regparse++;
-+ } else
-+ ret = regnode(g, ANYOF);
-+ if (*g->regparse == ']' || *g->regparse == '-')
-+ regc(g, *g->regparse++);
-+ while (*g->regparse != '\0' && *g->regparse != ']') {
-+ if (*g->regparse == '-') {
-+ g->regparse++;
-+ if (*g->regparse == ']' || *g->regparse == '\0')
-+ regc(g, '-');
-+ else {
-+ class = UCHARAT(g->regparse-2)+1;
-+ classend = UCHARAT(g->regparse);
-+ if (class > classend+1)
-+ FAIL("invalid [] range");
-+ for (; class <= classend; class++)
-+ regc(g, class);
-+ g->regparse++;
-+ }
-+ } else
-+ regc(g, *g->regparse++);
-+ }
-+ regc(g, '\0');
-+ if (*g->regparse != ']')
-+ FAIL("unmatched []");
-+ g->regparse++;
-+ *flagp |= HASWIDTH|SIMPLE;
-+ }
-+ break;
-+ case '(':
-+ ret = reg(g, 1, &flags);
-+ if (ret == NULL)
-+ return(NULL);
-+ *flagp |= flags&(HASWIDTH|SPSTART);
-+ break;
-+ case '\0':
-+ case '|':
-+ case ')':
-+ FAIL("internal urp"); /* Supposed to be caught earlier. */
-+ break;
-+ case '?':
-+ case '+':
-+ case '*':
-+ FAIL("?+* follows nothing");
-+ break;
-+ case '\\':
-+ if (*g->regparse == '\0')
-+ FAIL("trailing \\");
-+ ret = regnode(g, EXACTLY);
-+ regc(g, *g->regparse++);
-+ regc(g, '\0');
-+ *flagp |= HASWIDTH|SIMPLE;
-+ break;
-+ default: {
-+ register int len;
-+ register char ender;
-+
-+ g->regparse--;
-+ len = my_strcspn((const char *)g->regparse, (const char *)META);
-+ if (len <= 0)
-+ FAIL("internal disaster");
-+ ender = *(g->regparse+len);
-+ if (len > 1 && ISMULT(ender))
-+ len--; /* Back off clear of ?+* operand. */
-+ *flagp |= HASWIDTH;
-+ if (len == 1)
-+ *flagp |= SIMPLE;
-+ ret = regnode(g, EXACTLY);
-+ while (len > 0) {
-+ regc(g, *g->regparse++);
-+ len--;
-+ }
-+ regc(g, '\0');
-+ }
-+ break;
-+ }
-+
-+ return(ret);
-+}
-+
-+/*
-+ - regnode - emit a node
-+ */
-+static char * /* Location. */
-+regnode(struct match_globals *g, char op)
-+{
-+ register char *ret;
-+ register char *ptr;
-+
-+ ret = g->regcode;
-+ if (ret == &g->regdummy) {
-+ g->regsize += 3;
-+ return(ret);
-+ }
-+
-+ ptr = ret;
-+ *ptr++ = op;
-+ *ptr++ = '\0'; /* Null "next" pointer. */
-+ *ptr++ = '\0';
-+ g->regcode = ptr;
-+
-+ return(ret);
-+}
-+
-+/*
-+ - regc - emit (if appropriate) a byte of code
-+ */
-+static void
-+regc(struct match_globals *g, char b)
-+{
-+ if (g->regcode != &g->regdummy)
-+ *g->regcode++ = b;
-+ else
-+ g->regsize++;
-+}
-+
-+/*
-+ - reginsert - insert an operator in front of already-emitted operand
-+ *
-+ * Means relocating the operand.
-+ */
-+static void
-+reginsert(struct match_globals *g, char op, char* opnd)
-+{
-+ register char *src;
-+ register char *dst;
-+ register char *place;
-+
-+ if (g->regcode == &g->regdummy) {
-+ g->regsize += 3;
-+ return;
-+ }
-+
-+ src = g->regcode;
-+ g->regcode += 3;
-+ dst = g->regcode;
-+ while (src > opnd)
-+ *--dst = *--src;
-+
-+ place = opnd; /* Op node, where operand used to be. */
-+ *place++ = op;
-+ *place++ = '\0';
-+ *place++ = '\0';
-+}
-+
-+/*
-+ - regtail - set the next-pointer at the end of a node chain
-+ */
-+static void
-+regtail(struct match_globals *g, char *p, char *val)
-+{
-+ register char *scan;
-+ register char *temp;
-+ register int offset;
-+
-+ if (p == &g->regdummy)
-+ return;
-+
-+ /* Find last node. */
-+ scan = p;
-+ for (;;) {
-+ temp = regnext(g, scan);
-+ if (temp == NULL)
-+ break;
-+ scan = temp;
-+ }
-+
-+ if (OP(scan) == BACK)
-+ offset = scan - val;
-+ else
-+ offset = val - scan;
-+ *(scan+1) = (offset>>8)&0377;
-+ *(scan+2) = offset&0377;
-+}
-+
-+/*
-+ - regoptail - regtail on operand of first argument; nop if operandless
-+ */
-+static void
-+regoptail(struct match_globals *g, char *p, char *val)
-+{
-+ /* "Operandless" and "op != BRANCH" are synonymous in practice. */
-+ if (p == NULL || p == &g->regdummy || OP(p) != BRANCH)
-+ return;
-+ regtail(g, OPERAND(p), val);
-+}
-+
-+/*
-+ * regexec and friends
-+ */
-+
-+
-+/*
-+ * Forwards.
-+ */
-+STATIC int regtry(struct match_globals *g, regexp *prog, char *string);
-+STATIC int regmatch(struct match_globals *g, char *prog);
-+STATIC int regrepeat(struct match_globals *g, char *p);
-+
-+#ifdef DEBUG
-+int regnarrate = 0;
-+void regdump();
-+STATIC char *regprop(char *op);
-+#endif
-+
-+/*
-+ - regexec - match a regexp against a string
-+ */
-+int
-+regexec(regexp *prog, char *string)
-+{
-+ register char *s;
-+ struct match_globals g;
-+
-+ /* Be paranoid... */
-+ if (prog == NULL || string == NULL) {
-+ printk("<3>Regexp: NULL parameter\n");
-+ return(0);
-+ }
-+
-+ /* Check validity of program. */
-+ if (UCHARAT(prog->program) != MAGIC) {
-+ printk("<3>Regexp: corrupted program\n");
-+ return(0);
-+ }
-+
-+ /* If there is a "must appear" string, look for it. */
-+ if (prog->regmust != NULL) {
-+ s = string;
-+ while ((s = strchr(s, prog->regmust[0])) != NULL) {
-+ if (strncmp(s, prog->regmust, prog->regmlen) == 0)
-+ break; /* Found it. */
-+ s++;
-+ }
-+ if (s == NULL) /* Not present. */
-+ return(0);
-+ }
-+
-+ /* Mark beginning of line for ^ . */
-+ g.regbol = string;
-+
-+ /* Simplest case: anchored match need be tried only once. */
-+ if (prog->reganch)
-+ return(regtry(&g, prog, string));
-+
-+ /* Messy cases: unanchored match. */
-+ s = string;
-+ if (prog->regstart != '\0')
-+ /* We know what char it must start with. */
-+ while ((s = strchr(s, prog->regstart)) != NULL) {
-+ if (regtry(&g, prog, s))
-+ return(1);
-+ s++;
-+ }
-+ else
-+ /* We don't -- general case. */
-+ do {
-+ if (regtry(&g, prog, s))
-+ return(1);
-+ } while (*s++ != '\0');
-+
-+ /* Failure. */
-+ return(0);
-+}
-+
-+/*
-+ - regtry - try match at specific point
-+ */
-+static int /* 0 failure, 1 success */
-+regtry(struct match_globals *g, regexp *prog, char *string)
-+{
-+ register int i;
-+ register char **sp;
-+ register char **ep;
-+
-+ g->reginput = string;
-+ g->regstartp = prog->startp;
-+ g->regendp = prog->endp;
-+
-+ sp = prog->startp;
-+ ep = prog->endp;
-+ for (i = NSUBEXP; i > 0; i--) {
-+ *sp++ = NULL;
-+ *ep++ = NULL;
-+ }
-+ if (regmatch(g, prog->program + 1)) {
-+ prog->startp[0] = string;
-+ prog->endp[0] = g->reginput;
-+ return(1);
-+ } else
-+ return(0);
-+}
-+
-+/*
-+ - regmatch - main matching routine
-+ *
-+ * Conceptually the strategy is simple: check to see whether the current
-+ * node matches, call self recursively to see whether the rest matches,
-+ * and then act accordingly. In practice we make some effort to avoid
-+ * recursion, in particular by going through "ordinary" nodes (that don't
-+ * need to know whether the rest of the match failed) by a loop instead of
-+ * by recursion.
-+ */
-+static int /* 0 failure, 1 success */
-+regmatch(struct match_globals *g, char *prog)
-+{
-+ register char *scan = prog; /* Current node. */
-+ char *next; /* Next node. */
-+
-+#ifdef DEBUG
-+ if (scan != NULL && regnarrate)
-+ fprintf(stderr, "%s(\n", regprop(scan));
-+#endif
-+ while (scan != NULL) {
-+#ifdef DEBUG
-+ if (regnarrate)
-+ fprintf(stderr, "%s...\n", regprop(scan));
-+#endif
-+ next = regnext(g, scan);
-+
-+ switch (OP(scan)) {
-+ case BOL:
-+ if (g->reginput != g->regbol)
-+ return(0);
-+ break;
-+ case EOL:
-+ if (*g->reginput != '\0')
-+ return(0);
-+ break;
-+ case ANY:
-+ if (*g->reginput == '\0')
-+ return(0);
-+ g->reginput++;
-+ break;
-+ case EXACTLY: {
-+ register int len;
-+ register char *opnd;
-+
-+ opnd = OPERAND(scan);
-+ /* Inline the first character, for speed. */
-+ if (*opnd != *g->reginput)
-+ return(0);
-+ len = strlen(opnd);
-+ if (len > 1 && strncmp(opnd, g->reginput, len) != 0)
-+ return(0);
-+ g->reginput += len;
-+ }
-+ break;
-+ case ANYOF:
-+ if (*g->reginput == '\0' || strchr(OPERAND(scan), *g->reginput) == NULL)
-+ return(0);
-+ g->reginput++;
-+ break;
-+ case ANYBUT:
-+ if (*g->reginput == '\0' || strchr(OPERAND(scan), *g->reginput) != NULL)
-+ return(0);
-+ g->reginput++;
-+ break;
-+ case NOTHING:
-+ case BACK:
-+ break;
-+ case OPEN+1:
-+ case OPEN+2:
-+ case OPEN+3:
-+ case OPEN+4:
-+ case OPEN+5:
-+ case OPEN+6:
-+ case OPEN+7:
-+ case OPEN+8:
-+ case OPEN+9: {
-+ register int no;
-+ register char *save;
-+
-+ no = OP(scan) - OPEN;
-+ save = g->reginput;
-+
-+ if (regmatch(g, next)) {
-+ /*
-+ * Don't set startp if some later
-+ * invocation of the same parentheses
-+ * already has.
-+ */
-+ if (g->regstartp[no] == NULL)
-+ g->regstartp[no] = save;
-+ return(1);
-+ } else
-+ return(0);
-+ }
-+ break;
-+ case CLOSE+1:
-+ case CLOSE+2:
-+ case CLOSE+3:
-+ case CLOSE+4:
-+ case CLOSE+5:
-+ case CLOSE+6:
-+ case CLOSE+7:
-+ case CLOSE+8:
-+ case CLOSE+9:
-+ {
-+ register int no;
-+ register char *save;
-+
-+ no = OP(scan) - CLOSE;
-+ save = g->reginput;
-+
-+ if (regmatch(g, next)) {
-+ /*
-+ * Don't set endp if some later
-+ * invocation of the same parentheses
-+ * already has.
-+ */
-+ if (g->regendp[no] == NULL)
-+ g->regendp[no] = save;
-+ return(1);
-+ } else
-+ return(0);
-+ }
-+ break;
-+ case BRANCH: {
-+ register char *save;
-+
-+ if (OP(next) != BRANCH) /* No choice. */
-+ next = OPERAND(scan); /* Avoid recursion. */
-+ else {
-+ do {
-+ save = g->reginput;
-+ if (regmatch(g, OPERAND(scan)))
-+ return(1);
-+ g->reginput = save;
-+ scan = regnext(g, scan);
-+ } while (scan != NULL && OP(scan) == BRANCH);
-+ return(0);
-+ /* NOTREACHED */
-+ }
-+ }
-+ break;
-+ case STAR:
-+ case PLUS: {
-+ register char nextch;
-+ register int no;
-+ register char *save;
-+ register int min;
-+
-+ /*
-+ * Lookahead to avoid useless match attempts
-+ * when we know what character comes next.
-+ */
-+ nextch = '\0';
-+ if (OP(next) == EXACTLY)
-+ nextch = *OPERAND(next);
-+ min = (OP(scan) == STAR) ? 0 : 1;
-+ save = g->reginput;
-+ no = regrepeat(g, OPERAND(scan));
-+ while (no >= min) {
-+ /* If it could work, try it. */
-+ if (nextch == '\0' || *g->reginput == nextch)
-+ if (regmatch(g, next))
-+ return(1);
-+ /* Couldn't or didn't -- back up. */
-+ no--;
-+ g->reginput = save + no;
-+ }
-+ return(0);
-+ }
-+ break;
-+ case END:
-+ return(1); /* Success! */
-+ break;
-+ default:
-+ printk("<3>Regexp: memory corruption\n");
-+ return(0);
-+ break;
-+ }
-+
-+ scan = next;
-+ }
-+
-+ /*
-+ * We get here only if there's trouble -- normally "case END" is
-+ * the terminating point.
-+ */
-+ printk("<3>Regexp: corrupted pointers\n");
-+ return(0);
-+}
-+
-+/*
-+ - regrepeat - repeatedly match something simple, report how many
-+ */
-+static int
-+regrepeat(struct match_globals *g, char *p)
-+{
-+ register int count = 0;
-+ register char *scan;
-+ register char *opnd;
-+
-+ scan = g->reginput;
-+ opnd = OPERAND(p);
-+ switch (OP(p)) {
-+ case ANY:
-+ count = strlen(scan);
-+ scan += count;
-+ break;
-+ case EXACTLY:
-+ while (*opnd == *scan) {
-+ count++;
-+ scan++;
-+ }
-+ break;
-+ case ANYOF:
-+ while (*scan != '\0' && strchr(opnd, *scan) != NULL) {
-+ count++;
-+ scan++;
-+ }
-+ break;
-+ case ANYBUT:
-+ while (*scan != '\0' && strchr(opnd, *scan) == NULL) {
-+ count++;
-+ scan++;
-+ }
-+ break;
-+ default: /* Oh dear. Called inappropriately. */
-+ printk("<3>Regexp: internal foulup\n");
-+ count = 0; /* Best compromise. */
-+ break;
-+ }
-+ g->reginput = scan;
-+
-+ return(count);
-+}
-+
-+/*
-+ - regnext - dig the "next" pointer out of a node
-+ */
-+static char*
-+regnext(struct match_globals *g, char *p)
-+{
-+ register int offset;
-+
-+ if (p == &g->regdummy)
-+ return(NULL);
-+
-+ offset = NEXT(p);
-+ if (offset == 0)
-+ return(NULL);
-+
-+ if (OP(p) == BACK)
-+ return(p-offset);
-+ else
-+ return(p+offset);
-+}
-+
-+#ifdef DEBUG
-+
-+STATIC char *regprop();
-+
-+/*
-+ - regdump - dump a regexp onto stdout in vaguely comprehensible form
-+ */
-+void
-+regdump(regexp *r)
-+{
-+ register char *s;
-+ register char op = EXACTLY; /* Arbitrary non-END op. */
-+ register char *next;
-+ /* extern char *strchr(); */
-+
-+
-+ s = r->program + 1;
-+ while (op != END) { /* While that wasn't END last time... */
-+ op = OP(s);
-+ printf("%2d%s", s-r->program, regprop(s)); /* Where, what. */
-+ next = regnext(s);
-+ if (next == NULL) /* Next ptr. */
-+ printf("(0)");
-+ else
-+ printf("(%d)", (s-r->program)+(next-s));
-+ s += 3;
-+ if (op == ANYOF || op == ANYBUT || op == EXACTLY) {
-+ /* Literal string, where present. */
-+ while (*s != '\0') {
-+ putchar(*s);
-+ s++;
-+ }
-+ s++;
-+ }
-+ putchar('\n');
-+ }
-+
-+ /* Header fields of interest. */
-+ if (r->regstart != '\0')
-+ printf("start `%c' ", r->regstart);
-+ if (r->reganch)
-+ printf("anchored ");
-+ if (r->regmust != NULL)
-+ printf("must have \"%s\"", r->regmust);
-+ printf("\n");
-+}
-+
-+/*
-+ - regprop - printable representation of opcode
-+ */
-+static char *
-+regprop(char *op)
-+{
-+#define BUFLEN 50
-+ register char *p;
-+ static char buf[BUFLEN];
-+
-+ strcpy(buf, ":");
-+
-+ switch (OP(op)) {
-+ case BOL:
-+ p = "BOL";
-+ break;
-+ case EOL:
-+ p = "EOL";
-+ break;
-+ case ANY:
-+ p = "ANY";
-+ break;
-+ case ANYOF:
-+ p = "ANYOF";
-+ break;
-+ case ANYBUT:
-+ p = "ANYBUT";
-+ break;
-+ case BRANCH:
-+ p = "BRANCH";
-+ break;
-+ case EXACTLY:
-+ p = "EXACTLY";
-+ break;
-+ case NOTHING:
-+ p = "NOTHING";
-+ break;
-+ case BACK:
-+ p = "BACK";
-+ break;
-+ case END:
-+ p = "END";
-+ break;
-+ case OPEN+1:
-+ case OPEN+2:
-+ case OPEN+3:
-+ case OPEN+4:
-+ case OPEN+5:
-+ case OPEN+6:
-+ case OPEN+7:
-+ case OPEN+8:
-+ case OPEN+9:
-+ snprintf(buf+strlen(buf),BUFLEN-strlen(buf), "OPEN%d", OP(op)-OPEN);
-+ p = NULL;
-+ break;
-+ case CLOSE+1:
-+ case CLOSE+2:
-+ case CLOSE+3:
-+ case CLOSE+4:
-+ case CLOSE+5:
-+ case CLOSE+6:
-+ case CLOSE+7:
-+ case CLOSE+8:
-+ case CLOSE+9:
-+ snprintf(buf+strlen(buf),BUFLEN-strlen(buf), "CLOSE%d", OP(op)-CLOSE);
-+ p = NULL;
-+ break;
-+ case STAR:
-+ p = "STAR";
-+ break;
-+ case PLUS:
-+ p = "PLUS";
-+ break;
-+ default:
-+ printk("<3>Regexp: corrupted opcode\n");
-+ break;
-+ }
-+ if (p != NULL)
-+ strncat(buf, p, BUFLEN-strlen(buf));
-+ return(buf);
-+}
-+#endif
-+
-+
---- /dev/null
-+++ b/net/netfilter/regexp/regexp.h
-@@ -0,0 +1,41 @@
-+/*
-+ * Definitions etc. for regexp(3) routines.
-+ *
-+ * Caveat: this is V8 regexp(3) [actually, a reimplementation thereof],
-+ * not the System V one.
-+ */
-+
-+#ifndef REGEXP_H
-+#define REGEXP_H
-+
-+
-+/*
-+http://www.opensource.apple.com/darwinsource/10.3/expect-1/expect/expect.h ,
-+which contains a version of this library, says:
-+
-+ *
-+ * NSUBEXP must be at least 10, and no greater than 117 or the parser
-+ * will not work properly.
-+ *
-+
-+However, it looks rather like this library is limited to 10. If you think
-+otherwise, let us know.
-+*/
-+
-+#define NSUBEXP 10
-+typedef struct regexp {
-+ char *startp[NSUBEXP];
-+ char *endp[NSUBEXP];
-+ char regstart; /* Internal use only. */
-+ char reganch; /* Internal use only. */
-+ char *regmust; /* Internal use only. */
-+ int regmlen; /* Internal use only. */
-+ char program[1]; /* Unwarranted chumminess with compiler. */
-+} regexp;
-+
-+regexp * regcomp(char *exp, int *patternsize);
-+int regexec(regexp *prog, char *string);
-+void regsub(regexp *prog, char *source, char *dest);
-+void regerror(char *s);
-+
-+#endif
---- /dev/null
-+++ b/net/netfilter/regexp/regmagic.h
-@@ -0,0 +1,5 @@
-+/*
-+ * The first byte of the regexp internal "program" is actually this magic
-+ * number; the start node begins in the second byte.
-+ */
-+#define MAGIC 0234
---- /dev/null
-+++ b/net/netfilter/regexp/regsub.c
-@@ -0,0 +1,95 @@
-+/*
-+ * regsub
-+ * @(#)regsub.c 1.3 of 2 April 86
-+ *
-+ * Copyright (c) 1986 by University of Toronto.
-+ * Written by Henry Spencer. Not derived from licensed software.
-+ *
-+ * Permission is granted to anyone to use this software for any
-+ * purpose on any computer system, and to redistribute it freely,
-+ * subject to the following restrictions:
-+ *
-+ * 1. The author is not responsible for the consequences of use of
-+ * this software, no matter how awful, even if they arise
-+ * from defects in it.
-+ *
-+ * 2. The origin of this software must not be misrepresented, either
-+ * by explicit claim or by omission.
-+ *
-+ * 3. Altered versions must be plainly marked as such, and must not
-+ * be misrepresented as being the original software.
-+ *
-+ *
-+ * This code was modified by Ethan Sommer to work within the kernel
-+ * (it now uses kmalloc etc..)
-+ *
-+ */
-+#include "regexp.h"
-+#include "regmagic.h"
-+#include <linux/string.h>
-+
-+
-+#ifndef CHARBITS
-+#define UCHARAT(p) ((int)*(unsigned char *)(p))
-+#else
-+#define UCHARAT(p) ((int)*(p)&CHARBITS)
-+#endif
-+
-+#if 0
-+//void regerror(char * s)
-+//{
-+// printk("regexp(3): %s", s);
-+// /* NOTREACHED */
-+//}
-+#endif
-+
-+/*
-+ - regsub - perform substitutions after a regexp match
-+ */
-+void
-+regsub(regexp * prog, char * source, char * dest)
-+{
-+ register char *src;
-+ register char *dst;
-+ register char c;
-+ register int no;
-+ register int len;
-+
-+ /* Not necessary and gcc doesn't like it -MLS */
-+ /*extern char *strncpy();*/
-+
-+ if (prog == NULL || source == NULL || dest == NULL) {
-+ regerror("NULL parm to regsub");
-+ return;
-+ }
-+ if (UCHARAT(prog->program) != MAGIC) {
-+ regerror("damaged regexp fed to regsub");
-+ return;
-+ }
-+
-+ src = source;
-+ dst = dest;
-+ while ((c = *src++) != '\0') {
-+ if (c == '&')
-+ no = 0;
-+ else if (c == '\\' && '0' <= *src && *src <= '9')
-+ no = *src++ - '0';
-+ else
-+ no = -1;
-+
-+ if (no < 0) { /* Ordinary character. */
-+ if (c == '\\' && (*src == '\\' || *src == '&'))
-+ c = *src++;
-+ *dst++ = c;
-+ } else if (prog->startp[no] != NULL && prog->endp[no] != NULL) {
-+ len = prog->endp[no] - prog->startp[no];
-+ (void) strncpy(dst, prog->startp[no], len);
-+ dst += len;
-+ if (len != 0 && *(dst-1) == '\0') { /* strncpy hit NUL. */
-+ regerror("damaged match string");
-+ return;
-+ }
-+ }
-+ }
-+ *dst++ = '\0';
-+}
---- a/net/netfilter/nf_conntrack_core.c
-+++ b/net/netfilter/nf_conntrack_core.c
-@@ -207,6 +207,14 @@
- * too. */
- nf_ct_remove_expectations(ct);
-
-+ #if defined(CONFIG_NETFILTER_XT_MATCH_LAYER7) || defined(CONFIG_NETFILTER_XT_MATCH_LAYER7_MODULE)
-+ if(ct->layer7.app_proto)
-+ kfree(ct->layer7.app_proto);
-+ if(ct->layer7.app_data)
-+ kfree(ct->layer7.app_data);
-+ #endif
-+
-+
- /* We overload first tuple to link into unconfirmed list. */
- if (!nf_ct_is_confirmed(ct)) {
- BUG_ON(hlist_unhashed(&ct->tuplehash[IP_CT_DIR_ORIGINAL].hnode));
---- a/net/netfilter/nf_conntrack_standalone.c
-+++ b/net/netfilter/nf_conntrack_standalone.c
-@@ -179,7 +179,12 @@
- return -ENOSPC;
- #endif
-
-- if (seq_printf(s, "use=%u\n", atomic_read(&conntrack->ct_general.use)))
-+#if defined(CONFIG_NETFILTER_XT_MATCH_LAYER7) || defined(CONFIG_NETFILTER_XT_MATCH_LAYER7_MODULE)
-+ if(conntrack->layer7.app_proto)
-+ if(seq_printf(s, "l7proto=%s ", conntrack->layer7.app_proto))
-+ return -ENOSPC;
-+#endif
-+ if (seq_printf(s, "asdfuse=%u\n", atomic_read(&conntrack->ct_general.use)))
- return -ENOSPC;
-
- return 0;
---- a/include/net/netfilter/nf_conntrack.h
-+++ b/include/net/netfilter/nf_conntrack.h
-@@ -127,6 +127,22 @@
- u_int32_t secmark;
- #endif
-
-+#if defined(CONFIG_NETFILTER_XT_MATCH_LAYER7) || \
-+ defined(CONFIG_NETFILTER_XT_MATCH_LAYER7_MODULE)
-+ struct {
-+ /*
-+ * e.g. "http". NULL before decision. "unknown" after decision
-+ * if no match.
-+ */
-+ char *app_proto;
-+ /*
-+ * application layer data so far. NULL after match decision.
-+ */
-+ char *app_data;
-+ unsigned int app_data_len;
-+ } layer7;
-+#endif
-+
- /* Storage reserved for other modules: */
- union nf_conntrack_proto proto;
-
---- /dev/null
-+++ b/include/linux/netfilter/xt_layer7.h
-@@ -0,0 +1,13 @@
-+#ifndef _XT_LAYER7_H
-+#define _XT_LAYER7_H
-+
-+#define MAX_PATTERN_LEN 8192
-+#define MAX_PROTOCOL_LEN 256
-+
-+struct xt_layer7_info {
-+ char protocol[MAX_PROTOCOL_LEN];
-+ char pattern[MAX_PATTERN_LEN];
-+ u_int8_t invert;
-+};
-+
-+#endif /* _XT_LAYER7_H */
+++ /dev/null
---- a/include/linux/netfilter/xt_layer7.h
-+++ b/include/linux/netfilter/xt_layer7.h
-@@ -8,6 +8,7 @@
- char protocol[MAX_PROTOCOL_LEN];
- char pattern[MAX_PATTERN_LEN];
- u_int8_t invert;
-+ u_int8_t pkt;
- };
-
- #endif /* _XT_LAYER7_H */
---- a/net/netfilter/xt_layer7.c
-+++ b/net/netfilter/xt_layer7.c
-@@ -297,34 +297,36 @@
- }
-
- /* add the new app data to the conntrack. Return number of bytes added. */
--static int add_data(struct nf_conn * master_conntrack,
-- char * app_data, int appdatalen)
-+static int add_datastr(char *target, int offset, char *app_data, int len)
- {
- int length = 0, i;
-- int oldlength = master_conntrack->layer7.app_data_len;
--
-- /* This is a fix for a race condition by Deti Fliegl. However, I'm not
-- clear on whether the race condition exists or whether this really
-- fixes it. I might just be being dense... Anyway, if it's not really
-- a fix, all it does is waste a very small amount of time. */
-- if(!master_conntrack->layer7.app_data) return 0;
-+
-+ if (!target) return 0;
-
- /* Strip nulls. Make everything lower case (our regex lib doesn't
- do case insensitivity). Add it to the end of the current data. */
-- for(i = 0; i < maxdatalen-oldlength-1 &&
-- i < appdatalen; i++) {
-+ for(i = 0; i < maxdatalen-offset-1 && i < len; i++) {
- if(app_data[i] != '\0') {
- /* the kernel version of tolower mungs 'upper ascii' */
-- master_conntrack->layer7.app_data[length+oldlength] =
-+ target[length+offset] =
- isascii(app_data[i])?
- tolower(app_data[i]) : app_data[i];
- length++;
- }
- }
-+ target[length+offset] = '\0';
-+
-+ return length;
-+}
-
-- master_conntrack->layer7.app_data[length+oldlength] = '\0';
-- master_conntrack->layer7.app_data_len = length + oldlength;
-+/* add the new app data to the conntrack. Return number of bytes added. */
-+static int add_data(struct nf_conn * master_conntrack,
-+ char * app_data, int appdatalen)
-+{
-+ int length;
-
-+ length = add_datastr(master_conntrack->layer7.app_data, master_conntrack->layer7.app_data_len, app_data, appdatalen);
-+ master_conntrack->layer7.app_data_len += length;
- return length;
- }
-
-@@ -411,7 +413,7 @@
- const struct xt_layer7_info * info = matchinfo;
- enum ip_conntrack_info master_ctinfo, ctinfo;
- struct nf_conn *master_conntrack, *conntrack;
-- unsigned char * app_data;
-+ unsigned char *app_data, *tmp_data;
- unsigned int pattern_result, appdatalen;
- regexp * comppattern;
-
-@@ -439,8 +441,8 @@
- master_conntrack = master_ct(master_conntrack);
-
- /* if we've classified it or seen too many packets */
-- if(TOTAL_PACKETS > num_packets ||
-- master_conntrack->layer7.app_proto) {
-+ if(!info->pkt && (TOTAL_PACKETS > num_packets ||
-+ master_conntrack->layer7.app_proto)) {
-
- pattern_result = match_no_append(conntrack, master_conntrack,
- ctinfo, master_ctinfo, info);
-@@ -473,6 +475,25 @@
- /* the return value gets checked later, when we're ready to use it */
- comppattern = compile_and_cache(info->pattern, info->protocol);
-
-+ if (info->pkt) {
-+ tmp_data = kmalloc(maxdatalen, GFP_ATOMIC);
-+ if(!tmp_data){
-+ if (net_ratelimit())
-+ printk(KERN_ERR "layer7: out of memory in match, bailing.\n");
-+ return info->invert;
-+ }
-+
-+ tmp_data[0] = '\0';
-+ add_datastr(tmp_data, 0, app_data, appdatalen);
-+ pattern_result = ((comppattern && regexec(comppattern, tmp_data)) ? 1 : 0);
-+
-+ kfree(tmp_data);
-+ tmp_data = NULL;
-+ spin_unlock_bh(&l7_lock);
-+
-+ return (pattern_result ^ info->invert);
-+ }
-+
- /* On the first packet of a connection, allocate space for app data */
- if(TOTAL_PACKETS == 1 && !skb->cb[0] &&
- !master_conntrack->layer7.app_data){
+++ /dev/null
---- /dev/null
-+++ b/include/linux/netfilter_ipv4/ipt_ipp2p.h
-@@ -0,0 +1,31 @@
-+#ifndef __IPT_IPP2P_H
-+#define __IPT_IPP2P_H
-+#define IPP2P_VERSION "0.8.1_rc1"
-+
-+struct ipt_p2p_info {
-+ int cmd;
-+ int debug;
-+};
-+
-+#endif //__IPT_IPP2P_H
-+
-+#define SHORT_HAND_IPP2P 1 /* --ipp2p switch*/
-+//#define SHORT_HAND_DATA 4 /* --ipp2p-data switch*/
-+#define SHORT_HAND_NONE 5 /* no short hand*/
-+
-+#define IPP2P_EDK (1 << 1)
-+#define IPP2P_DATA_KAZAA (1 << 2)
-+#define IPP2P_DATA_EDK (1 << 3)
-+#define IPP2P_DATA_DC (1 << 4)
-+#define IPP2P_DC (1 << 5)
-+#define IPP2P_DATA_GNU (1 << 6)
-+#define IPP2P_GNU (1 << 7)
-+#define IPP2P_KAZAA (1 << 8)
-+#define IPP2P_BIT (1 << 9)
-+#define IPP2P_APPLE (1 << 10)
-+#define IPP2P_SOUL (1 << 11)
-+#define IPP2P_WINMX (1 << 12)
-+#define IPP2P_ARES (1 << 13)
-+#define IPP2P_MUTE (1 << 14)
-+#define IPP2P_WASTE (1 << 15)
-+#define IPP2P_XDCC (1 << 16)
---- /dev/null
-+++ b/net/ipv4/netfilter/ipt_ipp2p.c
-@@ -0,0 +1,856 @@
-+#if defined(MODVERSIONS)
-+#include <linux/modversions.h>
-+#endif
-+#include <linux/module.h>
-+#include <linux/netfilter_ipv4/ip_tables.h>
-+#include <linux/version.h>
-+#include <linux/netfilter_ipv4/ipt_ipp2p.h>
-+#include <net/tcp.h>
-+#include <net/udp.h>
-+
-+#define get_u8(X,O) (*(__u8 *)(X + O))
-+#define get_u16(X,O) (*(__u16 *)(X + O))
-+#define get_u32(X,O) (*(__u32 *)(X + O))
-+
-+MODULE_AUTHOR("Eicke Friedrich/Klaus Degner <ipp2p@ipp2p.org>");
-+MODULE_DESCRIPTION("An extension to iptables to identify P2P traffic.");
-+MODULE_LICENSE("GPL");
-+
-+
-+/*Search for UDP eDonkey/eMule/Kad commands*/
-+int
-+udp_search_edk (unsigned char *haystack, int packet_len)
-+{
-+ unsigned char *t = haystack;
-+ t += 8;
-+
-+ switch (t[0]) {
-+ case 0xe3:
-+ { /*edonkey*/
-+ switch (t[1])
-+ {
-+ /* client -> server status request */
-+ case 0x96:
-+ if (packet_len == 14) return ((IPP2P_EDK * 100) + 50);
-+ break;
-+ /* server -> client status request */
-+ case 0x97: if (packet_len == 42) return ((IPP2P_EDK * 100) + 51);
-+ break;
-+ /* server description request */
-+ /* e3 2a ff f0 .. | size == 6 */
-+ case 0xa2: if ( (packet_len == 14) && ( get_u16(t,2) == __constant_htons(0xfff0) ) ) return ((IPP2P_EDK * 100) + 52);
-+ break;
-+ /* server description response */
-+ /* e3 a3 ff f0 .. | size > 40 && size < 200 */
-+ //case 0xa3: return ((IPP2P_EDK * 100) + 53);
-+ // break;
-+ case 0x9a: if (packet_len==26) return ((IPP2P_EDK * 100) + 54);
-+ break;
-+
-+ case 0x92: if (packet_len==18) return ((IPP2P_EDK * 100) + 55);
-+ break;
-+ }
-+ break;
-+ }
-+ case 0xe4:
-+ {
-+ switch (t[1])
-+ {
-+ /* e4 20 .. | size == 43 */
-+ case 0x20: if ((packet_len == 43) && (t[2] != 0x00) && (t[34] != 0x00)) return ((IPP2P_EDK * 100) + 60);
-+ break;
-+ /* e4 00 .. 00 | size == 35 ? */
-+ case 0x00: if ((packet_len == 35) && (t[26] == 0x00)) return ((IPP2P_EDK * 100) + 61);
-+ break;
-+ /* e4 10 .. 00 | size == 35 ? */
-+ case 0x10: if ((packet_len == 35) && (t[26] == 0x00)) return ((IPP2P_EDK * 100) + 62);
-+ break;
-+ /* e4 18 .. 00 | size == 35 ? */
-+ case 0x18: if ((packet_len == 35) && (t[26] == 0x00)) return ((IPP2P_EDK * 100) + 63);
-+ break;
-+ /* e4 52 .. | size = 44 */
-+ case 0x52: if (packet_len == 44 ) return ((IPP2P_EDK * 100) + 64);
-+ break;
-+ /* e4 58 .. | size == 6 */
-+ case 0x58: if (packet_len == 14 ) return ((IPP2P_EDK * 100) + 65);
-+ break;
-+ /* e4 59 .. | size == 2 */
-+ case 0x59: if (packet_len == 10 )return ((IPP2P_EDK * 100) + 66);
-+ break;
-+ /* e4 28 .. | packet_len == 52,77,102,127... */
-+ case 0x28: if (((packet_len-52) % 25) == 0) return ((IPP2P_EDK * 100) + 67);
-+ break;
-+ /* e4 50 xx xx | size == 4 */
-+ case 0x50: if (packet_len == 12) return ((IPP2P_EDK * 100) + 68);
-+ break;
-+ /* e4 40 xx xx | size == 48 */
-+ case 0x40: if (packet_len == 56) return ((IPP2P_EDK * 100) + 69);
-+ break;
-+ }
-+ break;
-+ }
-+ } /* end of switch (t[0]) */
-+ return 0;
-+}/*udp_search_edk*/
-+
-+
-+/*Search for UDP Gnutella commands*/
-+int
-+udp_search_gnu (unsigned char *haystack, int packet_len)
-+{
-+ unsigned char *t = haystack;
-+ t += 8;
-+
-+ if (memcmp(t, "GND", 3) == 0) return ((IPP2P_GNU * 100) + 51);
-+ if (memcmp(t, "GNUTELLA ", 9) == 0) return ((IPP2P_GNU * 100) + 52);
-+ return 0;
-+}/*udp_search_gnu*/
-+
-+
-+/*Search for UDP KaZaA commands*/
-+int
-+udp_search_kazaa (unsigned char *haystack, int packet_len)
-+{
-+ unsigned char *t = haystack;
-+
-+ if (t[packet_len-1] == 0x00){
-+ t += (packet_len - 6);
-+ if (memcmp(t, "KaZaA", 5) == 0) return (IPP2P_KAZAA * 100 +50);
-+ }
-+
-+ return 0;
-+}/*udp_search_kazaa*/
-+
-+/*Search for UDP DirectConnect commands*/
-+int
-+udp_search_directconnect (unsigned char *haystack, int packet_len)
-+{
-+ unsigned char *t = haystack;
-+ if ((*(t + 8) == 0x24) && (*(t + packet_len - 1) == 0x7c)) {
-+ t+=8;
-+ if (memcmp(t, "SR ", 3) == 0) return ((IPP2P_DC * 100) + 60);
-+ if (memcmp(t, "Ping ", 5) == 0) return ((IPP2P_DC * 100) + 61);
-+ }
-+ return 0;
-+}/*udp_search_directconnect*/
-+
-+
-+
-+/*Search for UDP BitTorrent commands*/
-+int
-+udp_search_bit (unsigned char *haystack, int packet_len)
-+{
-+ switch(packet_len)
-+ {
-+ case 24:
-+ /* ^ 00 00 04 17 27 10 19 80 */
-+ if ((ntohl(get_u32(haystack, 8)) == 0x00000417) && (ntohl(get_u32(haystack, 12)) == 0x27101980))
-+ return (IPP2P_BIT * 100 + 50);
-+ break;
-+ case 44:
-+ if (get_u32(haystack, 16) == __constant_htonl(0x00000400) && get_u32(haystack, 36) == __constant_htonl(0x00000104))
-+ return (IPP2P_BIT * 100 + 51);
-+ if (get_u32(haystack, 16) == __constant_htonl(0x00000400))
-+ return (IPP2P_BIT * 100 + 61);
-+ break;
-+ case 65:
-+ if (get_u32(haystack, 16) == __constant_htonl(0x00000404) && get_u32(haystack, 36) == __constant_htonl(0x00000104))
-+ return (IPP2P_BIT * 100 + 52);
-+ if (get_u32(haystack, 16) == __constant_htonl(0x00000404))
-+ return (IPP2P_BIT * 100 + 62);
-+ break;
-+ case 67:
-+ if (get_u32(haystack, 16) == __constant_htonl(0x00000406) && get_u32(haystack, 36) == __constant_htonl(0x00000104))
-+ return (IPP2P_BIT * 100 + 53);
-+ if (get_u32(haystack, 16) == __constant_htonl(0x00000406))
-+ return (IPP2P_BIT * 100 + 63);
-+ break;
-+ case 211:
-+ if (get_u32(haystack, 8) == __constant_htonl(0x00000405))
-+ return (IPP2P_BIT * 100 + 54);
-+ break;
-+ case 29:
-+ if ((get_u32(haystack, 8) == __constant_htonl(0x00000401)))
-+ return (IPP2P_BIT * 100 + 55);
-+ break;
-+ case 52:
-+ if (get_u32(haystack,8) == __constant_htonl(0x00000827) &&
-+ get_u32(haystack,12) == __constant_htonl(0x37502950))
-+ return (IPP2P_BIT * 100 + 80);
-+ break;
-+ default:
-+ /* this packet does not have a constant size */
-+ if (packet_len >= 40 && get_u32(haystack, 16) == __constant_htonl(0x00000402) && get_u32(haystack, 36) == __constant_htonl(0x00000104))
-+ return (IPP2P_BIT * 100 + 56);
-+ break;
-+ }
-+
-+ /* some extra-bitcomet rules:
-+ * "d1:" [a|r] "d2:id20:"
-+ */
-+ if (packet_len > 30 && get_u8(haystack, 8) == 'd' && get_u8(haystack, 9) == '1' && get_u8(haystack, 10) == ':' )
-+ {
-+ if (get_u8(haystack, 11) == 'a' || get_u8(haystack, 11) == 'r')
-+ {
-+ if (memcmp(haystack+12,"d2:id20:",8)==0)
-+ return (IPP2P_BIT * 100 + 57);
-+ }
-+ }
-+
-+#if 0
-+ /* bitlord rules */
-+ /* packetlen must be bigger than 40 */
-+ /* first 4 bytes are zero */
-+ if (packet_len > 40 && get_u32(haystack, 8) == 0x00000000)
-+ {
-+ /* first rule: 00 00 00 00 01 00 00 xx xx xx xx 00 00 00 00*/
-+ if (get_u32(haystack, 12) == 0x00000000 &&
-+ get_u32(haystack, 16) == 0x00010000 &&
-+ get_u32(haystack, 24) == 0x00000000 )
-+ return (IPP2P_BIT * 100 + 71);
-+
-+ /* 00 01 00 00 0d 00 00 xx xx xx xx 00 00 00 00*/
-+ if (get_u32(haystack, 12) == 0x00000001 &&
-+ get_u32(haystack, 16) == 0x000d0000 &&
-+ get_u32(haystack, 24) == 0x00000000 )
-+ return (IPP2P_BIT * 100 + 71);
-+
-+
-+ }
-+#endif
-+
-+ return 0;
-+}/*udp_search_bit*/
-+
-+
-+
-+/*Search for Ares commands*/
-+//#define IPP2P_DEBUG_ARES
-+int
-+search_ares (const unsigned char *payload, const u16 plen)
-+//int search_ares (unsigned char *haystack, int packet_len, int head_len)
-+{
-+// const unsigned char *t = haystack + head_len;
-+
-+ /* all ares packets start with */
-+ if (payload[1] == 0 && (plen - payload[0]) == 3)
-+ {
-+ switch (payload[2])
-+ {
-+ case 0x5a:
-+ /* ares connect */
-+ if ( plen == 6 && payload[5] == 0x05 ) return ((IPP2P_ARES * 100) + 1);
-+ break;
-+ case 0x09:
-+ /* ares search, min 3 chars --> 14 bytes
-+ * lets define a search can be up to 30 chars --> max 34 bytes
-+ */
-+ if ( plen >= 14 && plen <= 34 ) return ((IPP2P_ARES * 100) + 1);
-+ break;
-+#ifdef IPP2P_DEBUG_ARES
-+ default:
-+ printk(KERN_DEBUG "Unknown Ares command %x recognized, len: %u \n", (unsigned int) payload[2],plen);
-+#endif /* IPP2P_DEBUG_ARES */
-+ }
-+ }
-+
-+#if 0
-+ /* found connect packet: 03 00 5a 04 03 05 */
-+ /* new version ares 1.8: 03 00 5a xx xx 05 */
-+ if ((plen) == 6){ /* possible connect command*/
-+ if ((payload[0] == 0x03) && (payload[1] == 0x00) && (payload[2] == 0x5a) && (payload[5] == 0x05))
-+ return ((IPP2P_ARES * 100) + 1);
-+ }
-+ if ((plen) == 60){ /* possible download command*/
-+ if ((payload[59] == 0x0a) && (payload[58] == 0x0a)){
-+ if (memcmp(t, "PUSH SHA1:", 10) == 0) /* found download command */
-+ return ((IPP2P_ARES * 100) + 2);
-+ }
-+ }
-+#endif
-+
-+ return 0;
-+} /*search_ares*/
-+
-+/*Search for SoulSeek commands*/
-+int
-+search_soul (const unsigned char *payload, const u16 plen)
-+{
-+//#define IPP2P_DEBUG_SOUL
-+ /* match: xx xx xx xx | xx = sizeof(payload) - 4 */
-+ if (get_u32(payload, 0) == (plen - 4)){
-+ const __u32 m=get_u32(payload, 4);
-+ /* match 00 yy yy 00, yy can be everything */
-+ if ( get_u8(payload, 4) == 0x00 && get_u8(payload, 7) == 0x00 )
-+ {
-+#ifdef IPP2P_DEBUG_SOUL
-+ printk(KERN_DEBUG "0: Soulseek command 0x%x recognized\n",get_u32(payload, 4));
-+#endif /* IPP2P_DEBUG_SOUL */
-+ return ((IPP2P_SOUL * 100) + 1);
-+ }
-+
-+ /* next match: 01 yy 00 00 | yy can be everything */
-+ if ( get_u8(payload, 4) == 0x01 && get_u16(payload, 6) == 0x0000 )
-+ {
-+#ifdef IPP2P_DEBUG_SOUL
-+ printk(KERN_DEBUG "1: Soulseek command 0x%x recognized\n",get_u16(payload, 4));
-+#endif /* IPP2P_DEBUG_SOUL */
-+ return ((IPP2P_SOUL * 100) + 2);
-+ }
-+
-+ /* other soulseek commandos are: 1-5,7,9,13-18,22,23,26,28,35-37,40-46,50,51,60,62-69,91,92,1001 */
-+ /* try to do this in an intelligent way */
-+ /* get all small commandos */
-+ switch(m)
-+ {
-+ case 7:
-+ case 9:
-+ case 22:
-+ case 23:
-+ case 26:
-+ case 28:
-+ case 50:
-+ case 51:
-+ case 60:
-+ case 91:
-+ case 92:
-+ case 1001:
-+#ifdef IPP2P_DEBUG_SOUL
-+ printk(KERN_DEBUG "2: Soulseek command 0x%x recognized\n",get_u16(payload, 4));
-+#endif /* IPP2P_DEBUG_SOUL */
-+ return ((IPP2P_SOUL * 100) + 3);
-+ }
-+
-+ if (m > 0 && m < 6 )
-+ {
-+#ifdef IPP2P_DEBUG_SOUL
-+ printk(KERN_DEBUG "3: Soulseek command 0x%x recognized\n",get_u16(payload, 4));
-+#endif /* IPP2P_DEBUG_SOUL */
-+ return ((IPP2P_SOUL * 100) + 4);
-+ }
-+ if (m > 12 && m < 19 )
-+ {
-+#ifdef IPP2P_DEBUG_SOUL
-+ printk(KERN_DEBUG "4: Soulseek command 0x%x recognized\n",get_u16(payload, 4));
-+#endif /* IPP2P_DEBUG_SOUL */
-+ return ((IPP2P_SOUL * 100) + 5);
-+ }
-+
-+ if (m > 34 && m < 38 )
-+ {
-+#ifdef IPP2P_DEBUG_SOUL
-+ printk(KERN_DEBUG "5: Soulseek command 0x%x recognized\n",get_u16(payload, 4));
-+#endif /* IPP2P_DEBUG_SOUL */
-+ return ((IPP2P_SOUL * 100) + 6);
-+ }
-+
-+ if (m > 39 && m < 47 )
-+ {
-+#ifdef IPP2P_DEBUG_SOUL
-+ printk(KERN_DEBUG "6: Soulseek command 0x%x recognized\n",get_u16(payload, 4));
-+#endif /* IPP2P_DEBUG_SOUL */
-+ return ((IPP2P_SOUL * 100) + 7);
-+ }
-+
-+ if (m > 61 && m < 70 )
-+ {
-+#ifdef IPP2P_DEBUG_SOUL
-+ printk(KERN_DEBUG "7: Soulseek command 0x%x recognized\n",get_u16(payload, 4));
-+#endif /* IPP2P_DEBUG_SOUL */
-+ return ((IPP2P_SOUL * 100) + 8);
-+ }
-+
-+#ifdef IPP2P_DEBUG_SOUL
-+ printk(KERN_DEBUG "unknown SOULSEEK command: 0x%x, first 16 bit: 0x%x, first 8 bit: 0x%x ,soulseek ???\n",get_u32(payload, 4),get_u16(payload, 4) >> 16,get_u8(payload, 4) >> 24);
-+#endif /* IPP2P_DEBUG_SOUL */
-+ }
-+
-+ /* match 14 00 00 00 01 yy 00 00 00 STRING(YY) 01 00 00 00 00 46|50 00 00 00 00 */
-+ /* without size at the beginning !!! */
-+ if ( get_u32(payload, 0) == 0x14 && get_u8(payload, 4) == 0x01 )
-+ {
-+ __u32 y=get_u32(payload, 5);
-+ /* we need 19 chars + string */
-+ if ( (y + 19) <= (plen) )
-+ {
-+ const unsigned char *w=payload+9+y;
-+ if (get_u32(w, 0) == 0x01 && ( get_u16(w, 4) == 0x4600 || get_u16(w, 4) == 0x5000) && get_u32(w, 6) == 0x00);
-+#ifdef IPP2P_DEBUG_SOUL
-+ printk(KERN_DEBUG "Soulssek special client command recognized\n");
-+#endif /* IPP2P_DEBUG_SOUL */
-+ return ((IPP2P_SOUL * 100) + 9);
-+ }
-+ }
-+ return 0;
-+}
-+
-+
-+/*Search for WinMX commands*/
-+int
-+search_winmx (const unsigned char *payload, const u16 plen)
-+{
-+//#define IPP2P_DEBUG_WINMX
-+ if (((plen) == 4) && (memcmp(payload, "SEND", 4) == 0)) return ((IPP2P_WINMX * 100) + 1);
-+ if (((plen) == 3) && (memcmp(payload, "GET", 3) == 0)) return ((IPP2P_WINMX * 100) + 2);
-+ //if (packet_len < (head_len + 10)) return 0;
-+ if (plen < 10) return 0;
-+
-+ if ((memcmp(payload, "SEND", 4) == 0) || (memcmp(payload, "GET", 3) == 0)){
-+ u16 c=4;
-+ const u16 end=plen-2;
-+ u8 count=0;
-+ while (c < end)
-+ {
-+ if (payload[c]== 0x20 && payload[c+1] == 0x22)
-+ {
-+ c++;
-+ count++;
-+ if (count>=2) return ((IPP2P_WINMX * 100) + 3);
-+ }
-+ c++;
-+ }
-+ }
-+
-+ if ( plen == 149 && payload[0] == '8' )
-+ {
-+#ifdef IPP2P_DEBUG_WINMX
-+ printk(KERN_INFO "maybe WinMX\n");
-+#endif
-+ if (get_u32(payload,17) == 0 && get_u32(payload,21) == 0 && get_u32(payload,25) == 0 &&
-+// get_u32(payload,33) == __constant_htonl(0x71182b1a) && get_u32(payload,37) == __constant_htonl(0x05050000) &&
-+// get_u32(payload,133) == __constant_htonl(0x31097edf) && get_u32(payload,145) == __constant_htonl(0xdcb8f792))
-+ get_u16(payload,39) == 0 && get_u16(payload,135) == __constant_htons(0x7edf) && get_u16(payload,147) == __constant_htons(0xf792))
-+
-+ {
-+#ifdef IPP2P_DEBUG_WINMX
-+ printk(KERN_INFO "got WinMX\n");
-+#endif
-+ return ((IPP2P_WINMX * 100) + 4);
-+ }
-+ }
-+ return 0;
-+} /*search_winmx*/
-+
-+
-+/*Search for appleJuice commands*/
-+int
-+search_apple (const unsigned char *payload, const u16 plen)
-+{
-+ if ( (plen > 7) && (payload[6] == 0x0d) && (payload[7] == 0x0a) && (memcmp(payload, "ajprot", 6) == 0)) return (IPP2P_APPLE * 100);
-+
-+ return 0;
-+}
-+
-+
-+/*Search for BitTorrent commands*/
-+int
-+search_bittorrent (const unsigned char *payload, const u16 plen)
-+{
-+ if (plen > 20)
-+ {
-+ /* test for match 0x13+"BitTorrent protocol" */
-+ if (payload[0] == 0x13)
-+ {
-+ if (memcmp(payload+1, "BitTorrent protocol", 19) == 0) return (IPP2P_BIT * 100);
-+ }
-+
-+ /* get tracker commandos, all starts with GET /
-+ * then it can follow: scrape| announce
-+ * and then ?hash_info=
-+ */
-+ if (memcmp(payload,"GET /",5) == 0)
-+ {
-+ /* message scrape */
-+ if ( memcmp(payload+5,"scrape?info_hash=",17)==0 ) return (IPP2P_BIT * 100 + 1);
-+ /* message announce */
-+ if ( memcmp(payload+5,"announce?info_hash=",19)==0 ) return (IPP2P_BIT * 100 + 2);
-+ }
-+ }
-+ else
-+ {
-+ /* bitcomet encryptes the first packet, so we have to detect another
-+ * one later in the flow */
-+ /* first try failed, too many missdetections */
-+ //if ( size == 5 && get_u32(t,0) == __constant_htonl(1) && t[4] < 3) return (IPP2P_BIT * 100 + 3);
-+
-+ /* second try: block request packets */
-+ if ( plen == 17 && get_u32(payload,0) == __constant_htonl(0x0d) && payload[4] == 0x06 && get_u32(payload,13) == __constant_htonl(0x4000) ) return (IPP2P_BIT * 100 + 3);
-+ }
-+
-+ return 0;
-+}
-+
-+
-+
-+/*check for Kazaa get command*/
-+int
-+search_kazaa (const unsigned char *payload, const u16 plen)
-+
-+{
-+ if ((payload[plen-2] == 0x0d) && (payload[plen-1] == 0x0a) && memcmp(payload, "GET /.hash=", 11) == 0)
-+ return (IPP2P_DATA_KAZAA * 100);
-+
-+ return 0;
-+}
-+
-+
-+/*check for gnutella get command*/
-+int
-+search_gnu (const unsigned char *payload, const u16 plen)
-+{
-+ if ((payload[plen-2] == 0x0d) && (payload[plen-1] == 0x0a))
-+ {
-+ if (memcmp(payload, "GET /get/", 9) == 0) return ((IPP2P_DATA_GNU * 100) + 1);
-+ if (memcmp(payload, "GET /uri-res/", 13) == 0) return ((IPP2P_DATA_GNU * 100) + 2);
-+ }
-+ return 0;
-+}
-+
-+
-+/*check for gnutella get commands and other typical data*/
-+int
-+search_all_gnu (const unsigned char *payload, const u16 plen)
-+{
-+
-+ if ((payload[plen-2] == 0x0d) && (payload[plen-1] == 0x0a))
-+ {
-+
-+ if (memcmp(payload, "GNUTELLA CONNECT/", 17) == 0) return ((IPP2P_GNU * 100) + 1);
-+ if (memcmp(payload, "GNUTELLA/", 9) == 0) return ((IPP2P_GNU * 100) + 2);
-+
-+
-+ if ((memcmp(payload, "GET /get/", 9) == 0) || (memcmp(payload, "GET /uri-res/", 13) == 0))
-+ {
-+ u16 c=8;
-+ const u16 end=plen-22;
-+ while (c < end) {
-+ if ( payload[c] == 0x0a && payload[c+1] == 0x0d && ((memcmp(&payload[c+2], "X-Gnutella-", 11) == 0) || (memcmp(&payload[c+2], "X-Queue:", 8) == 0)))
-+ return ((IPP2P_GNU * 100) + 3);
-+ c++;
-+ }
-+ }
-+ }
-+ return 0;
-+}
-+
-+
-+/*check for KaZaA download commands and other typical data*/
-+int
-+search_all_kazaa (const unsigned char *payload, const u16 plen)
-+{
-+ if ((payload[plen-2] == 0x0d) && (payload[plen-1] == 0x0a))
-+ {
-+
-+ if (memcmp(payload, "GIVE ", 5) == 0) return ((IPP2P_KAZAA * 100) + 1);
-+
-+ if (memcmp(payload, "GET /", 5) == 0) {
-+ u16 c = 8;
-+ const u16 end=plen-22;
-+ while (c < end) {
-+ if ( payload[c] == 0x0a && payload[c+1] == 0x0d && ((memcmp(&payload[c+2], "X-Kazaa-Username: ", 18) == 0) || (memcmp(&payload[c+2], "User-Agent: PeerEnabler/", 24) == 0)))
-+ return ((IPP2P_KAZAA * 100) + 2);
-+ c++;
-+ }
-+ }
-+ }
-+ return 0;
-+}
-+
-+/*fast check for edonkey file segment transfer command*/
-+int
-+search_edk (const unsigned char *payload, const u16 plen)
-+{
-+ if (payload[0] != 0xe3)
-+ return 0;
-+ else {
-+ if (payload[5] == 0x47)
-+ return (IPP2P_DATA_EDK * 100);
-+ else
-+ return 0;
-+ }
-+}
-+
-+
-+
-+/*intensive but slower search for some edonkey packets including size-check*/
-+int
-+search_all_edk (const unsigned char *payload, const u16 plen)
-+{
-+ if (payload[0] != 0xe3)
-+ return 0;
-+ else {
-+ //t += head_len;
-+ const u16 cmd = get_u16(payload, 1);
-+ if (cmd == (plen - 5)) {
-+ switch (payload[5]) {
-+ case 0x01: return ((IPP2P_EDK * 100) + 1); /*Client: hello or Server:hello*/
-+ case 0x4c: return ((IPP2P_EDK * 100) + 9); /*Client: Hello-Answer*/
-+ }
-+ }
-+ return 0;
-+ }
-+}
-+
-+
-+/*fast check for Direct Connect send command*/
-+int
-+search_dc (const unsigned char *payload, const u16 plen)
-+{
-+
-+ if (payload[0] != 0x24 )
-+ return 0;
-+ else {
-+ if (memcmp(&payload[1], "Send|", 5) == 0)
-+ return (IPP2P_DATA_DC * 100);
-+ else
-+ return 0;
-+ }
-+
-+}
-+
-+
-+/*intensive but slower check for all direct connect packets*/
-+int
-+search_all_dc (const unsigned char *payload, const u16 plen)
-+{
-+// unsigned char *t = haystack;
-+
-+ if (payload[0] == 0x24 && payload[plen-1] == 0x7c)
-+ {
-+ const unsigned char *t=&payload[1];
-+ /* Client-Hub-Protocol */
-+ if (memcmp(t, "Lock ", 5) == 0) return ((IPP2P_DC * 100) + 1);
-+ /* Client-Client-Protocol, some are already recognized by client-hub (like lock) */
-+ if (memcmp(t, "MyNick ", 7) == 0) return ((IPP2P_DC * 100) + 38);
-+ }
-+ return 0;
-+}
-+
-+/*check for mute*/
-+int
-+search_mute (const unsigned char *payload, const u16 plen)
-+{
-+ if ( plen == 209 || plen == 345 || plen == 473 || plen == 609 || plen == 1121 )
-+ {
-+ //printk(KERN_DEBUG "size hit: %u",size);
-+ if (memcmp(payload,"PublicKey: ",11) == 0 )
-+ {
-+ return ((IPP2P_MUTE * 100) + 0);
-+
-+/* if (memcmp(t+size-14,"\x0aEndPublicKey\x0a",14) == 0)
-+ {
-+ printk(KERN_DEBUG "end pubic key hit: %u",size);
-+
-+ }*/
-+ }
-+ }
-+ return 0;
-+}
-+
-+
-+/* check for xdcc */
-+int
-+search_xdcc (const unsigned char *payload, const u16 plen)
-+{
-+ /* search in small packets only */
-+ if (plen > 20 && plen < 200 && payload[plen-1] == 0x0a && payload[plen-2] == 0x0d && memcmp(payload,"PRIVMSG ",8) == 0)
-+ {
-+
-+ u16 x=10;
-+ const u16 end=plen - 13;
-+
-+ /* is seems to be a irc private massage, chedck for xdcc command */
-+ while (x < end)
-+ {
-+ if (payload[x] == ':')
-+ {
-+ if ( memcmp(&payload[x+1],"xdcc send #",11) == 0 )
-+ return ((IPP2P_XDCC * 100) + 0);
-+ }
-+ x++;
-+ }
-+ }
-+ return 0;
-+}
-+
-+/* search for waste */
-+int search_waste(const unsigned char *payload, const u16 plen)
-+{
-+ if ( plen >= 8 && memcmp(payload,"GET.sha1:",9) == 0)
-+ return ((IPP2P_WASTE * 100) + 0);
-+
-+ return 0;
-+}
-+
-+
-+static struct {
-+ int command;
-+ __u8 short_hand; /*for fucntions included in short hands*/
-+ int packet_len;
-+ int (*function_name) (const unsigned char *, const u16);
-+} matchlist[] = {
-+ {IPP2P_EDK,SHORT_HAND_IPP2P,20, &search_all_edk},
-+// {IPP2P_DATA_KAZAA,SHORT_HAND_DATA,200, &search_kazaa},
-+// {IPP2P_DATA_EDK,SHORT_HAND_DATA,60, &search_edk},
-+// {IPP2P_DATA_DC,SHORT_HAND_DATA,26, &search_dc},
-+ {IPP2P_DC,SHORT_HAND_IPP2P,5, search_all_dc},
-+// {IPP2P_DATA_GNU,SHORT_HAND_DATA,40, &search_gnu},
-+ {IPP2P_GNU,SHORT_HAND_IPP2P,5, &search_all_gnu},
-+ {IPP2P_KAZAA,SHORT_HAND_IPP2P,5, &search_all_kazaa},
-+ {IPP2P_BIT,SHORT_HAND_IPP2P,20, &search_bittorrent},
-+ {IPP2P_APPLE,SHORT_HAND_IPP2P,5, &search_apple},
-+ {IPP2P_SOUL,SHORT_HAND_IPP2P,5, &search_soul},
-+ {IPP2P_WINMX,SHORT_HAND_IPP2P,2, &search_winmx},
-+ {IPP2P_ARES,SHORT_HAND_IPP2P,5, &search_ares},
-+ {IPP2P_MUTE,SHORT_HAND_NONE,200, &search_mute},
-+ {IPP2P_WASTE,SHORT_HAND_NONE,5, &search_waste},
-+ {IPP2P_XDCC,SHORT_HAND_NONE,5, &search_xdcc},
-+ {0,0,0,NULL}
-+};
-+
-+
-+static struct {
-+ int command;
-+ __u8 short_hand; /*for fucntions included in short hands*/
-+ int packet_len;
-+ int (*function_name) (unsigned char *, int);
-+} udp_list[] = {
-+ {IPP2P_KAZAA,SHORT_HAND_IPP2P,14, &udp_search_kazaa},
-+ {IPP2P_BIT,SHORT_HAND_IPP2P,23, &udp_search_bit},
-+ {IPP2P_GNU,SHORT_HAND_IPP2P,11, &udp_search_gnu},
-+ {IPP2P_EDK,SHORT_HAND_IPP2P,9, &udp_search_edk},
-+ {IPP2P_DC,SHORT_HAND_IPP2P,12, &udp_search_directconnect},
-+ {0,0,0,NULL}
-+};
-+
-+
-+static bool
-+match(const struct sk_buff *skb,
-+ const struct net_device *in,
-+ const struct net_device *out,
-+ const struct xt_match *match,
-+ const void *matchinfo,
-+ int offset,
-+ unsigned int protoff,
-+ bool *hotdrop)
-+{
-+ const struct ipt_p2p_info *info = matchinfo;
-+ unsigned char *haystack;
-+ struct iphdr *ip = ip_hdr(skb);
-+ int p2p_result = 0, i = 0;
-+// int head_len;
-+ int hlen = ntohs(ip->tot_len)-(ip->ihl*4); /*hlen = packet-data length*/
-+
-+ /*must not be a fragment*/
-+ if (offset) {
-+ if (info->debug) printk("IPP2P.match: offset found %i \n",offset);
-+ return 0;
-+ }
-+
-+ /*make sure that skb is linear*/
-+ if(skb_is_nonlinear(skb)){
-+ if (info->debug) printk("IPP2P.match: nonlinear skb found\n");
-+ return 0;
-+ }
-+
-+
-+ haystack=(char *)ip+(ip->ihl*4); /*haystack = packet data*/
-+
-+ switch (ip->protocol){
-+ case IPPROTO_TCP: /*what to do with a TCP packet*/
-+ {
-+ struct tcphdr *tcph = (void *) ip + ip->ihl * 4;
-+
-+ if (tcph->fin) return 0; /*if FIN bit is set bail out*/
-+ if (tcph->syn) return 0; /*if SYN bit is set bail out*/
-+ if (tcph->rst) return 0; /*if RST bit is set bail out*/
-+
-+ haystack += tcph->doff * 4; /*get TCP-Header-Size*/
-+ hlen -= tcph->doff * 4;
-+ while (matchlist[i].command) {
-+ if ((((info->cmd & matchlist[i].command) == matchlist[i].command) ||
-+ ((info->cmd & matchlist[i].short_hand) == matchlist[i].short_hand)) &&
-+ (hlen > matchlist[i].packet_len)) {
-+ p2p_result = matchlist[i].function_name(haystack, hlen);
-+ if (p2p_result)
-+ {
-+ if (info->debug) printk("IPP2P.debug:TCP-match: %i from: %u.%u.%u.%u:%i to: %u.%u.%u.%u:%i Length: %i\n",
-+ p2p_result, NIPQUAD(ip->saddr),ntohs(tcph->source), NIPQUAD(ip->daddr),ntohs(tcph->dest),hlen);
-+ return p2p_result;
-+ }
-+ }
-+ i++;
-+ }
-+ return p2p_result;
-+ }
-+
-+ case IPPROTO_UDP: /*what to do with an UDP packet*/
-+ {
-+ struct udphdr *udph = (void *) ip + ip->ihl * 4;
-+
-+ while (udp_list[i].command){
-+ if ((((info->cmd & udp_list[i].command) == udp_list[i].command) ||
-+ ((info->cmd & udp_list[i].short_hand) == udp_list[i].short_hand)) &&
-+ (hlen > udp_list[i].packet_len)) {
-+ p2p_result = udp_list[i].function_name(haystack, hlen);
-+ if (p2p_result){
-+ if (info->debug) printk("IPP2P.debug:UDP-match: %i from: %u.%u.%u.%u:%i to: %u.%u.%u.%u:%i Length: %i\n",
-+ p2p_result, NIPQUAD(ip->saddr),ntohs(udph->source), NIPQUAD(ip->daddr),ntohs(udph->dest),hlen);
-+ return p2p_result;
-+ }
-+ }
-+ i++;
-+ }
-+ return p2p_result;
-+ }
-+
-+ default: return 0;
-+ }
-+}
-+
-+
-+
-+static bool
-+checkentry(const char *tablename,
-+ const void *ip,
-+ const struct xt_match *match,
-+ void *matchinfo,
-+ unsigned int hook_mask)
-+{
-+ /* Must specify -p tcp */
-+/* if (ip->proto != IPPROTO_TCP || (ip->invflags & IPT_INV_PROTO)) {
-+ * printk("ipp2p: Only works on TCP packets, use -p tcp\n");
-+ * return 0;
-+ * }*/
-+ return 1;
-+}
-+
-+
-+
-+
-+static struct ipt_match ipp2p_match = {
-+ .name = "ipp2p",
-+ .match = &match,
-+ .family = AF_INET,
-+ .matchsize = sizeof(struct ipt_p2p_info),
-+ .checkentry = &checkentry,
-+ .me = THIS_MODULE,
-+};
-+
-+
-+static int __init init(void)
-+{
-+ printk(KERN_INFO "IPP2P v%s loading\n", IPP2P_VERSION);
-+ return xt_register_match(&ipp2p_match);
-+}
-+
-+static void __exit fini(void)
-+{
-+ xt_unregister_match(&ipp2p_match);
-+ printk(KERN_INFO "IPP2P v%s unloaded\n", IPP2P_VERSION);
-+}
-+
-+module_init(init);
-+module_exit(fini);
-+
-+
---- a/net/ipv4/netfilter/Kconfig
-+++ b/net/ipv4/netfilter/Kconfig
-@@ -63,6 +63,12 @@
-
- To compile it as a module, choose M here. If unsure, say N.
-
-+config IP_NF_MATCH_IPP2P
-+ tristate "IPP2P"
-+ depends on IP_NF_IPTABLES
-+ help
-+ Module for matching traffic of various Peer-to-Peer applications
-+
- config IP_NF_MATCH_TOS
- tristate "TOS match support"
- depends on IP_NF_IPTABLES
---- a/net/ipv4/netfilter/Makefile
-+++ b/net/ipv4/netfilter/Makefile
-@@ -50,6 +50,8 @@
- obj-$(CONFIG_IP_NF_MATCH_TTL) += ipt_ttl.o
- obj-$(CONFIG_IP_NF_MATCH_ADDRTYPE) += ipt_addrtype.o
-
-+obj-$(CONFIG_IP_NF_MATCH_IPP2P) += ipt_ipp2p.o
-+
- # targets
- obj-$(CONFIG_IP_NF_TARGET_REJECT) += ipt_REJECT.o
- obj-$(CONFIG_IP_NF_TARGET_TOS) += ipt_TOS.o
+++ /dev/null
---- /dev/null
-+++ b/include/net/xfrmudp.h
-@@ -0,0 +1,10 @@
-+/*
-+ * pointer to function for type that xfrm4_input wants, to permit
-+ * decoupling of XFRM from udp.c
-+ */
-+#define HAVE_XFRM4_UDP_REGISTER
-+
-+typedef int (*xfrm4_rcv_encap_t)(struct sk_buff *skb, __u16 encap_type);
-+extern int udp4_register_esp_rcvencap(xfrm4_rcv_encap_t func
-+ , xfrm4_rcv_encap_t *oldfunc);
-+extern int udp4_unregister_esp_rcvencap(xfrm4_rcv_encap_t func);
---- a/net/ipv4/Kconfig
-+++ b/net/ipv4/Kconfig
-@@ -224,6 +224,12 @@
- Network), but can be distributed all over the Internet. If you want
- to do that, say Y here and to "IP multicast routing" below.
-
-+config IPSEC_NAT_TRAVERSAL
-+ bool "IPSEC NAT-Traversal (KLIPS compatible)"
-+ depends on INET
-+ ---help---
-+ Includes support for RFC3947/RFC3948 NAT-Traversal of ESP over UDP.
-+
- config IP_MROUTE
- bool "IP: multicast routing"
- depends on IP_MULTICAST
---- a/net/ipv4/xfrm4_input.c
-+++ b/net/ipv4/xfrm4_input.c
-@@ -15,6 +15,7 @@
- #include <linux/netfilter_ipv4.h>
- #include <net/ip.h>
- #include <net/xfrm.h>
-+#include <net/xfrmudp.h>
-
- static int xfrm4_parse_spi(struct sk_buff *skb, u8 nexthdr, __be32 *spi, __be32 *seq)
- {
-@@ -161,6 +162,29 @@
- return 0;
- }
-
-+#ifdef CONFIG_IPSEC_NAT_TRAVERSAL
-+static xfrm4_rcv_encap_t xfrm4_rcv_encap_func = NULL;
-+
-+int udp4_register_esp_rcvencap(xfrm4_rcv_encap_t func,
-+ xfrm4_rcv_encap_t *oldfunc)
-+{
-+ if(oldfunc != NULL)
-+ *oldfunc = xfrm4_rcv_encap_func;
-+
-+ xfrm4_rcv_encap_func = func;
-+ return 0;
-+}
-+
-+int udp4_unregister_esp_rcvencap(xfrm4_rcv_encap_t func)
-+{
-+ if(xfrm4_rcv_encap_func != func)
-+ return -1;
-+
-+ xfrm4_rcv_encap_func = NULL;
-+ return 0;
-+}
-+#endif /* CONFIG_IPSEC_NAT_TRAVERSAL */
-+
- /* If it's a keepalive packet, then just eat it.
- * If it's an encapsulated packet, then pass it to the
- * IPsec xfrm input.
-@@ -251,7 +275,13 @@
- iph->protocol = IPPROTO_ESP;
-
- /* process ESP */
-+#ifdef CONFIG_IPSEC_NAT_TRAVERSAL
-+ if(xfrm4_rcv_encap_func == NULL)
-+ goto drop;
-+ ret = (*xfrm4_rcv_encap_func)(skb, up->encap_type);
-+#else
- ret = xfrm4_rcv_encap(skb, encap_type);
-+#endif
- return ret;
-
- drop:
-@@ -265,3 +295,8 @@
- }
-
- EXPORT_SYMBOL(xfrm4_rcv);
-+
-+#ifdef CONFIG_IPSEC_NAT_TRAVERSAL
-+EXPORT_SYMBOL(udp4_register_esp_rcvencap);
-+EXPORT_SYMBOL(udp4_unregister_esp_rcvencap);
-+#endif
+++ /dev/null
---- /dev/null
-+++ b/include/linux/netfilter_ipv4/ip_set.h
-@@ -0,0 +1,498 @@
-+#ifndef _IP_SET_H
-+#define _IP_SET_H
-+
-+/* Copyright (C) 2000-2002 Joakim Axelsson <gozem@linux.nu>
-+ * Patrick Schaaf <bof@bof.de>
-+ * Martin Josefsson <gandalf@wlug.westbo.se>
-+ * Copyright (C) 2003-2004 Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
-+ *
-+ * This program is free software; you can redistribute it and/or modify
-+ * it under the terms of the GNU General Public License version 2 as
-+ * published by the Free Software Foundation.
-+ */
-+
-+#if 0
-+#define IP_SET_DEBUG
-+#endif
-+
-+/*
-+ * A sockopt of such quality has hardly ever been seen before on the open
-+ * market! This little beauty, hardly ever used: above 64, so it's
-+ * traditionally used for firewalling, not touched (even once!) by the
-+ * 2.0, 2.2 and 2.4 kernels!
-+ *
-+ * Comes with its own certificate of authenticity, valid anywhere in the
-+ * Free world!
-+ *
-+ * Rusty, 19.4.2000
-+ */
-+#define SO_IP_SET 83
-+
-+/*
-+ * Heavily modify by Joakim Axelsson 08.03.2002
-+ * - Made it more modulebased
-+ *
-+ * Additional heavy modifications by Jozsef Kadlecsik 22.02.2004
-+ * - bindings added
-+ * - in order to "deal with" backward compatibility, renamed to ipset
-+ */
-+
-+/*
-+ * Used so that the kernel module and ipset-binary can match their versions
-+ */
-+#define IP_SET_PROTOCOL_VERSION 2
-+
-+#define IP_SET_MAXNAMELEN 32 /* set names and set typenames */
-+
-+/* Lets work with our own typedef for representing an IP address.
-+ * We hope to make the code more portable, possibly to IPv6...
-+ *
-+ * The representation works in HOST byte order, because most set types
-+ * will perform arithmetic operations and compare operations.
-+ *
-+ * For now the type is an uint32_t.
-+ *
-+ * Make sure to ONLY use the functions when translating and parsing
-+ * in order to keep the host byte order and make it more portable:
-+ * parse_ip()
-+ * parse_mask()
-+ * parse_ipandmask()
-+ * ip_tostring()
-+ * (Joakim: where are they???)
-+ */
-+
-+typedef uint32_t ip_set_ip_t;
-+
-+/* Sets are identified by an id in kernel space. Tweak with ip_set_id_t
-+ * and IP_SET_INVALID_ID if you want to increase the max number of sets.
-+ */
-+typedef uint16_t ip_set_id_t;
-+
-+#define IP_SET_INVALID_ID 65535
-+
-+/* How deep we follow bindings */
-+#define IP_SET_MAX_BINDINGS 6
-+
-+/*
-+ * Option flags for kernel operations (ipt_set_info)
-+ */
-+#define IPSET_SRC 0x01 /* Source match/add */
-+#define IPSET_DST 0x02 /* Destination match/add */
-+#define IPSET_MATCH_INV 0x04 /* Inverse matching */
-+
-+/*
-+ * Set features
-+ */
-+#define IPSET_TYPE_IP 0x01 /* IP address type of set */
-+#define IPSET_TYPE_PORT 0x02 /* Port type of set */
-+#define IPSET_DATA_SINGLE 0x04 /* Single data storage */
-+#define IPSET_DATA_DOUBLE 0x08 /* Double data storage */
-+
-+/* Reserved keywords */
-+#define IPSET_TOKEN_DEFAULT ":default:"
-+#define IPSET_TOKEN_ALL ":all:"
-+
-+/* SO_IP_SET operation constants, and their request struct types.
-+ *
-+ * Operation ids:
-+ * 0-99: commands with version checking
-+ * 100-199: add/del/test/bind/unbind
-+ * 200-299: list, save, restore
-+ */
-+
-+/* Single shot operations:
-+ * version, create, destroy, flush, rename and swap
-+ *
-+ * Sets are identified by name.
-+ */
-+
-+#define IP_SET_REQ_STD \
-+ unsigned op; \
-+ unsigned version; \
-+ char name[IP_SET_MAXNAMELEN]
-+
-+#define IP_SET_OP_CREATE 0x00000001 /* Create a new (empty) set */
-+struct ip_set_req_create {
-+ IP_SET_REQ_STD;
-+ char typename[IP_SET_MAXNAMELEN];
-+};
-+
-+#define IP_SET_OP_DESTROY 0x00000002 /* Remove a (empty) set */
-+struct ip_set_req_std {
-+ IP_SET_REQ_STD;
-+};
-+
-+#define IP_SET_OP_FLUSH 0x00000003 /* Remove all IPs in a set */
-+/* Uses ip_set_req_std */
-+
-+#define IP_SET_OP_RENAME 0x00000004 /* Rename a set */
-+/* Uses ip_set_req_create */
-+
-+#define IP_SET_OP_SWAP 0x00000005 /* Swap two sets */
-+/* Uses ip_set_req_create */
-+
-+union ip_set_name_index {
-+ char name[IP_SET_MAXNAMELEN];
-+ ip_set_id_t index;
-+};
-+
-+#define IP_SET_OP_GET_BYNAME 0x00000006 /* Get set index by name */
-+struct ip_set_req_get_set {
-+ unsigned op;
-+ unsigned version;
-+ union ip_set_name_index set;
-+};
-+
-+#define IP_SET_OP_GET_BYINDEX 0x00000007 /* Get set name by index */
-+/* Uses ip_set_req_get_set */
-+
-+#define IP_SET_OP_VERSION 0x00000100 /* Ask kernel version */
-+struct ip_set_req_version {
-+ unsigned op;
-+ unsigned version;
-+};
-+
-+/* Double shots operations:
-+ * add, del, test, bind and unbind.
-+ *
-+ * First we query the kernel to get the index and type of the target set,
-+ * then issue the command. Validity of IP is checked in kernel in order
-+ * to minimalize sockopt operations.
-+ */
-+
-+/* Get minimal set data for add/del/test/bind/unbind IP */
-+#define IP_SET_OP_ADT_GET 0x00000010 /* Get set and type */
-+struct ip_set_req_adt_get {
-+ unsigned op;
-+ unsigned version;
-+ union ip_set_name_index set;
-+ char typename[IP_SET_MAXNAMELEN];
-+};
-+
-+#define IP_SET_REQ_BYINDEX \
-+ unsigned op; \
-+ ip_set_id_t index;
-+
-+struct ip_set_req_adt {
-+ IP_SET_REQ_BYINDEX;
-+};
-+
-+#define IP_SET_OP_ADD_IP 0x00000101 /* Add an IP to a set */
-+/* Uses ip_set_req_adt, with type specific addage */
-+
-+#define IP_SET_OP_DEL_IP 0x00000102 /* Remove an IP from a set */
-+/* Uses ip_set_req_adt, with type specific addage */
-+
-+#define IP_SET_OP_TEST_IP 0x00000103 /* Test an IP in a set */
-+/* Uses ip_set_req_adt, with type specific addage */
-+
-+#define IP_SET_OP_BIND_SET 0x00000104 /* Bind an IP to a set */
-+/* Uses ip_set_req_bind, with type specific addage */
-+struct ip_set_req_bind {
-+ IP_SET_REQ_BYINDEX;
-+ char binding[IP_SET_MAXNAMELEN];
-+};
-+
-+#define IP_SET_OP_UNBIND_SET 0x00000105 /* Unbind an IP from a set */
-+/* Uses ip_set_req_bind, with type speficic addage
-+ * index = 0 means unbinding for all sets */
-+
-+#define IP_SET_OP_TEST_BIND_SET 0x00000106 /* Test binding an IP to a set */
-+/* Uses ip_set_req_bind, with type specific addage */
-+
-+/* Multiple shots operations: list, save, restore.
-+ *
-+ * - check kernel version and query the max number of sets
-+ * - get the basic information on all sets
-+ * and size required for the next step
-+ * - get actual set data: header, data, bindings
-+ */
-+
-+/* Get max_sets and the index of a queried set
-+ */
-+#define IP_SET_OP_MAX_SETS 0x00000020
-+struct ip_set_req_max_sets {
-+ unsigned op;
-+ unsigned version;
-+ ip_set_id_t max_sets; /* max_sets */
-+ ip_set_id_t sets; /* real number of sets */
-+ union ip_set_name_index set; /* index of set if name used */
-+};
-+
-+/* Get the id and name of the sets plus size for next step */
-+#define IP_SET_OP_LIST_SIZE 0x00000201
-+#define IP_SET_OP_SAVE_SIZE 0x00000202
-+struct ip_set_req_setnames {
-+ unsigned op;
-+ ip_set_id_t index; /* set to list/save */
-+ size_t size; /* size to get setdata/bindings */
-+ /* followed by sets number of struct ip_set_name_list */
-+};
-+
-+struct ip_set_name_list {
-+ char name[IP_SET_MAXNAMELEN];
-+ char typename[IP_SET_MAXNAMELEN];
-+ ip_set_id_t index;
-+ ip_set_id_t id;
-+};
-+
-+/* The actual list operation */
-+#define IP_SET_OP_LIST 0x00000203
-+struct ip_set_req_list {
-+ IP_SET_REQ_BYINDEX;
-+ /* sets number of struct ip_set_list in reply */
-+};
-+
-+struct ip_set_list {
-+ ip_set_id_t index;
-+ ip_set_id_t binding;
-+ u_int32_t ref;
-+ size_t header_size; /* Set header data of header_size */
-+ size_t members_size; /* Set members data of members_size */
-+ size_t bindings_size; /* Set bindings data of bindings_size */
-+};
-+
-+struct ip_set_hash_list {
-+ ip_set_ip_t ip;
-+ ip_set_id_t binding;
-+};
-+
-+/* The save operation */
-+#define IP_SET_OP_SAVE 0x00000204
-+/* Uses ip_set_req_list, in the reply replaced by
-+ * sets number of struct ip_set_save plus a marker
-+ * ip_set_save followed by ip_set_hash_save structures.
-+ */
-+struct ip_set_save {
-+ ip_set_id_t index;
-+ ip_set_id_t binding;
-+ size_t header_size; /* Set header data of header_size */
-+ size_t members_size; /* Set members data of members_size */
-+};
-+
-+/* At restoring, ip == 0 means default binding for the given set: */
-+struct ip_set_hash_save {
-+ ip_set_ip_t ip;
-+ ip_set_id_t id;
-+ ip_set_id_t binding;
-+};
-+
-+/* The restore operation */
-+#define IP_SET_OP_RESTORE 0x00000205
-+/* Uses ip_set_req_setnames followed by ip_set_restore structures
-+ * plus a marker ip_set_restore, followed by ip_set_hash_save
-+ * structures.
-+ */
-+struct ip_set_restore {
-+ char name[IP_SET_MAXNAMELEN];
-+ char typename[IP_SET_MAXNAMELEN];
-+ ip_set_id_t index;
-+ size_t header_size; /* Create data of header_size */
-+ size_t members_size; /* Set members data of members_size */
-+};
-+
-+static inline int bitmap_bytes(ip_set_ip_t a, ip_set_ip_t b)
-+{
-+ return 4 * ((((b - a + 8) / 8) + 3) / 4);
-+}
-+
-+#ifdef __KERNEL__
-+
-+#define ip_set_printk(format, args...) \
-+ do { \
-+ printk("%s: %s: ", __FILE__, __FUNCTION__); \
-+ printk(format "\n" , ## args); \
-+ } while (0)
-+
-+#if defined(IP_SET_DEBUG)
-+#define DP(format, args...) \
-+ do { \
-+ printk("%s: %s (DBG): ", __FILE__, __FUNCTION__);\
-+ printk(format "\n" , ## args); \
-+ } while (0)
-+#define IP_SET_ASSERT(x) \
-+ do { \
-+ if (!(x)) \
-+ printk("IP_SET_ASSERT: %s:%i(%s)\n", \
-+ __FILE__, __LINE__, __FUNCTION__); \
-+ } while (0)
-+#else
-+#define DP(format, args...)
-+#define IP_SET_ASSERT(x)
-+#endif
-+
-+struct ip_set;
-+
-+/*
-+ * The ip_set_type definition - one per set type, e.g. "ipmap".
-+ *
-+ * Each individual set has a pointer, set->type, going to one
-+ * of these structures. Function pointers inside the structure implement
-+ * the real behaviour of the sets.
-+ *
-+ * If not mentioned differently, the implementation behind the function
-+ * pointers of a set_type, is expected to return 0 if ok, and a negative
-+ * errno (e.g. -EINVAL) on error.
-+ */
-+struct ip_set_type {
-+ struct list_head list; /* next in list of set types */
-+
-+ /* test for IP in set (kernel: iptables -m set src|dst)
-+ * return 0 if not in set, 1 if in set.
-+ */
-+ int (*testip_kernel) (struct ip_set *set,
-+ const struct sk_buff * skb,
-+ ip_set_ip_t *ip,
-+ const u_int32_t *flags,
-+ unsigned char index);
-+
-+ /* test for IP in set (userspace: ipset -T set IP)
-+ * return 0 if not in set, 1 if in set.
-+ */
-+ int (*testip) (struct ip_set *set,
-+ const void *data, size_t size,
-+ ip_set_ip_t *ip);
-+
-+ /*
-+ * Size of the data structure passed by when
-+ * adding/deletin/testing an entry.
-+ */
-+ size_t reqsize;
-+
-+ /* Add IP into set (userspace: ipset -A set IP)
-+ * Return -EEXIST if the address is already in the set,
-+ * and -ERANGE if the address lies outside the set bounds.
-+ * If the address was not already in the set, 0 is returned.
-+ */
-+ int (*addip) (struct ip_set *set,
-+ const void *data, size_t size,
-+ ip_set_ip_t *ip);
-+
-+ /* Add IP into set (kernel: iptables ... -j SET set src|dst)
-+ * Return -EEXIST if the address is already in the set,
-+ * and -ERANGE if the address lies outside the set bounds.
-+ * If the address was not already in the set, 0 is returned.
-+ */
-+ int (*addip_kernel) (struct ip_set *set,
-+ const struct sk_buff * skb,
-+ ip_set_ip_t *ip,
-+ const u_int32_t *flags,
-+ unsigned char index);
-+
-+ /* remove IP from set (userspace: ipset -D set --entry x)
-+ * Return -EEXIST if the address is NOT in the set,
-+ * and -ERANGE if the address lies outside the set bounds.
-+ * If the address really was in the set, 0 is returned.
-+ */
-+ int (*delip) (struct ip_set *set,
-+ const void *data, size_t size,
-+ ip_set_ip_t *ip);
-+
-+ /* remove IP from set (kernel: iptables ... -j SET --entry x)
-+ * Return -EEXIST if the address is NOT in the set,
-+ * and -ERANGE if the address lies outside the set bounds.
-+ * If the address really was in the set, 0 is returned.
-+ */
-+ int (*delip_kernel) (struct ip_set *set,
-+ const struct sk_buff * skb,
-+ ip_set_ip_t *ip,
-+ const u_int32_t *flags,
-+ unsigned char index);
-+
-+ /* new set creation - allocated type specific items
-+ */
-+ int (*create) (struct ip_set *set,
-+ const void *data, size_t size);
-+
-+ /* retry the operation after successfully tweaking the set
-+ */
-+ int (*retry) (struct ip_set *set);
-+
-+ /* set destruction - free type specific items
-+ * There is no return value.
-+ * Can be called only when child sets are destroyed.
-+ */
-+ void (*destroy) (struct ip_set *set);
-+
-+ /* set flushing - reset all bits in the set, or something similar.
-+ * There is no return value.
-+ */
-+ void (*flush) (struct ip_set *set);
-+
-+ /* Listing: size needed for header
-+ */
-+ size_t header_size;
-+
-+ /* Listing: Get the header
-+ *
-+ * Fill in the information in "data".
-+ * This function is always run after list_header_size() under a
-+ * writelock on the set. Therefor is the length of "data" always
-+ * correct.
-+ */
-+ void (*list_header) (const struct ip_set *set,
-+ void *data);
-+
-+ /* Listing: Get the size for the set members
-+ */
-+ int (*list_members_size) (const struct ip_set *set);
-+
-+ /* Listing: Get the set members
-+ *
-+ * Fill in the information in "data".
-+ * This function is always run after list_member_size() under a
-+ * writelock on the set. Therefor is the length of "data" always
-+ * correct.
-+ */
-+ void (*list_members) (const struct ip_set *set,
-+ void *data);
-+
-+ char typename[IP_SET_MAXNAMELEN];
-+ unsigned char features;
-+ int protocol_version;
-+
-+ /* Set this to THIS_MODULE if you are a module, otherwise NULL */
-+ struct module *me;
-+};
-+
-+extern int ip_set_register_set_type(struct ip_set_type *set_type);
-+extern void ip_set_unregister_set_type(struct ip_set_type *set_type);
-+
-+/* A generic ipset */
-+struct ip_set {
-+ char name[IP_SET_MAXNAMELEN]; /* the name of the set */
-+ rwlock_t lock; /* lock for concurrency control */
-+ ip_set_id_t id; /* set id for swapping */
-+ ip_set_id_t binding; /* default binding for the set */
-+ atomic_t ref; /* in kernel and in hash references */
-+ struct ip_set_type *type; /* the set types */
-+ void *data; /* pooltype specific data */
-+};
-+
-+/* Structure to bind set elements to sets */
-+struct ip_set_hash {
-+ struct list_head list; /* list of clashing entries in hash */
-+ ip_set_ip_t ip; /* ip from set */
-+ ip_set_id_t id; /* set id */
-+ ip_set_id_t binding; /* set we bind the element to */
-+};
-+
-+/* register and unregister set references */
-+extern ip_set_id_t ip_set_get_byname(const char name[IP_SET_MAXNAMELEN]);
-+extern ip_set_id_t ip_set_get_byindex(ip_set_id_t id);
-+extern void ip_set_put(ip_set_id_t id);
-+
-+/* API for iptables set match, and SET target */
-+extern void ip_set_addip_kernel(ip_set_id_t id,
-+ const struct sk_buff *skb,
-+ const u_int32_t *flags);
-+extern void ip_set_delip_kernel(ip_set_id_t id,
-+ const struct sk_buff *skb,
-+ const u_int32_t *flags);
-+extern int ip_set_testip_kernel(ip_set_id_t id,
-+ const struct sk_buff *skb,
-+ const u_int32_t *flags);
-+
-+#endif /* __KERNEL__ */
-+
-+#endif /*_IP_SET_H*/
---- /dev/null
-+++ b/include/linux/netfilter_ipv4/ip_set_iphash.h
-@@ -0,0 +1,30 @@
-+#ifndef __IP_SET_IPHASH_H
-+#define __IP_SET_IPHASH_H
-+
-+#include <linux/netfilter_ipv4/ip_set.h>
-+
-+#define SETTYPE_NAME "iphash"
-+#define MAX_RANGE 0x0000FFFF
-+
-+struct ip_set_iphash {
-+ ip_set_ip_t *members; /* the iphash proper */
-+ uint32_t elements; /* number of elements */
-+ uint32_t hashsize; /* hash size */
-+ uint16_t probes; /* max number of probes */
-+ uint16_t resize; /* resize factor in percent */
-+ ip_set_ip_t netmask; /* netmask */
-+ void *initval[0]; /* initvals for jhash_1word */
-+};
-+
-+struct ip_set_req_iphash_create {
-+ uint32_t hashsize;
-+ uint16_t probes;
-+ uint16_t resize;
-+ ip_set_ip_t netmask;
-+};
-+
-+struct ip_set_req_iphash {
-+ ip_set_ip_t ip;
-+};
-+
-+#endif /* __IP_SET_IPHASH_H */
---- /dev/null
-+++ b/include/linux/netfilter_ipv4/ip_set_ipmap.h
-@@ -0,0 +1,56 @@
-+#ifndef __IP_SET_IPMAP_H
-+#define __IP_SET_IPMAP_H
-+
-+#include <linux/netfilter_ipv4/ip_set.h>
-+
-+#define SETTYPE_NAME "ipmap"
-+#define MAX_RANGE 0x0000FFFF
-+
-+struct ip_set_ipmap {
-+ void *members; /* the ipmap proper */
-+ ip_set_ip_t first_ip; /* host byte order, included in range */
-+ ip_set_ip_t last_ip; /* host byte order, included in range */
-+ ip_set_ip_t netmask; /* subnet netmask */
-+ ip_set_ip_t sizeid; /* size of set in IPs */
-+ ip_set_ip_t hosts; /* number of hosts in a subnet */
-+};
-+
-+struct ip_set_req_ipmap_create {
-+ ip_set_ip_t from;
-+ ip_set_ip_t to;
-+ ip_set_ip_t netmask;
-+};
-+
-+struct ip_set_req_ipmap {
-+ ip_set_ip_t ip;
-+};
-+
-+unsigned int
-+mask_to_bits(ip_set_ip_t mask)
-+{
-+ unsigned int bits = 32;
-+ ip_set_ip_t maskaddr;
-+
-+ if (mask == 0xFFFFFFFF)
-+ return bits;
-+
-+ maskaddr = 0xFFFFFFFE;
-+ while (--bits >= 0 && maskaddr != mask)
-+ maskaddr <<= 1;
-+
-+ return bits;
-+}
-+
-+ip_set_ip_t
-+range_to_mask(ip_set_ip_t from, ip_set_ip_t to, unsigned int *bits)
-+{
-+ ip_set_ip_t mask = 0xFFFFFFFE;
-+
-+ *bits = 32;
-+ while (--(*bits) >= 0 && mask && (to & mask) != from)
-+ mask <<= 1;
-+
-+ return mask;
-+}
-+
-+#endif /* __IP_SET_IPMAP_H */
---- /dev/null
-+++ b/include/linux/netfilter_ipv4/ip_set_ipporthash.h
-@@ -0,0 +1,34 @@
-+#ifndef __IP_SET_IPPORTHASH_H
-+#define __IP_SET_IPPORTHASH_H
-+
-+#include <linux/netfilter_ipv4/ip_set.h>
-+
-+#define SETTYPE_NAME "ipporthash"
-+#define MAX_RANGE 0x0000FFFF
-+#define INVALID_PORT (MAX_RANGE + 1)
-+
-+struct ip_set_ipporthash {
-+ ip_set_ip_t *members; /* the ipporthash proper */
-+ uint32_t elements; /* number of elements */
-+ uint32_t hashsize; /* hash size */
-+ uint16_t probes; /* max number of probes */
-+ uint16_t resize; /* resize factor in percent */
-+ ip_set_ip_t first_ip; /* host byte order, included in range */
-+ ip_set_ip_t last_ip; /* host byte order, included in range */
-+ void *initval[0]; /* initvals for jhash_1word */
-+};
-+
-+struct ip_set_req_ipporthash_create {
-+ uint32_t hashsize;
-+ uint16_t probes;
-+ uint16_t resize;
-+ ip_set_ip_t from;
-+ ip_set_ip_t to;
-+};
-+
-+struct ip_set_req_ipporthash {
-+ ip_set_ip_t ip;
-+ ip_set_ip_t port;
-+};
-+
-+#endif /* __IP_SET_IPPORTHASH_H */
---- /dev/null
-+++ b/include/linux/netfilter_ipv4/ip_set_iptree.h
-@@ -0,0 +1,40 @@
-+#ifndef __IP_SET_IPTREE_H
-+#define __IP_SET_IPTREE_H
-+
-+#include <linux/netfilter_ipv4/ip_set.h>
-+
-+#define SETTYPE_NAME "iptree"
-+#define MAX_RANGE 0x0000FFFF
-+
-+struct ip_set_iptreed {
-+ unsigned long expires[256]; /* x.x.x.ADDR */
-+};
-+
-+struct ip_set_iptreec {
-+ struct ip_set_iptreed *tree[256]; /* x.x.ADDR.* */
-+};
-+
-+struct ip_set_iptreeb {
-+ struct ip_set_iptreec *tree[256]; /* x.ADDR.*.* */
-+};
-+
-+struct ip_set_iptree {
-+ unsigned int timeout;
-+ unsigned int gc_interval;
-+#ifdef __KERNEL__
-+ uint32_t elements; /* number of elements */
-+ struct timer_list gc;
-+ struct ip_set_iptreeb *tree[256]; /* ADDR.*.*.* */
-+#endif
-+};
-+
-+struct ip_set_req_iptree_create {
-+ unsigned int timeout;
-+};
-+
-+struct ip_set_req_iptree {
-+ ip_set_ip_t ip;
-+ unsigned int timeout;
-+};
-+
-+#endif /* __IP_SET_IPTREE_H */
---- /dev/null
-+++ b/include/linux/netfilter_ipv4/ip_set_iptreemap.h
-@@ -0,0 +1,40 @@
-+#ifndef __IP_SET_IPTREEMAP_H
-+#define __IP_SET_IPTREEMAP_H
-+
-+#include <linux/netfilter_ipv4/ip_set.h>
-+
-+#define SETTYPE_NAME "iptreemap"
-+
-+#ifdef __KERNEL__
-+struct ip_set_iptreemap_d {
-+ unsigned char bitmap[32]; /* x.x.x.y */
-+};
-+
-+struct ip_set_iptreemap_c {
-+ struct ip_set_iptreemap_d *tree[256]; /* x.x.y.x */
-+};
-+
-+struct ip_set_iptreemap_b {
-+ struct ip_set_iptreemap_c *tree[256]; /* x.y.x.x */
-+ unsigned char dirty[32];
-+};
-+#endif
-+
-+struct ip_set_iptreemap {
-+ unsigned int gc_interval;
-+#ifdef __KERNEL__
-+ struct timer_list gc;
-+ struct ip_set_iptreemap_b *tree[256]; /* y.x.x.x */
-+#endif
-+};
-+
-+struct ip_set_req_iptreemap_create {
-+ unsigned int gc_interval;
-+};
-+
-+struct ip_set_req_iptreemap {
-+ ip_set_ip_t start;
-+ ip_set_ip_t end;
-+};
-+
-+#endif /* __IP_SET_IPTREEMAP_H */
---- /dev/null
-+++ b/include/linux/netfilter_ipv4/ip_set_jhash.h
-@@ -0,0 +1,148 @@
-+#ifndef _LINUX_IPSET_JHASH_H
-+#define _LINUX_IPSET_JHASH_H
-+
-+/* This is a copy of linux/jhash.h but the types u32/u8 are changed
-+ * to __u32/__u8 so that the header file can be included into
-+ * userspace code as well. Jozsef Kadlecsik (kadlec@blackhole.kfki.hu)
-+ */
-+
-+/* jhash.h: Jenkins hash support.
-+ *
-+ * Copyright (C) 1996 Bob Jenkins (bob_jenkins@burtleburtle.net)
-+ *
-+ * http://burtleburtle.net/bob/hash/
-+ *
-+ * These are the credits from Bob's sources:
-+ *
-+ * lookup2.c, by Bob Jenkins, December 1996, Public Domain.
-+ * hash(), hash2(), hash3, and mix() are externally useful functions.
-+ * Routines to test the hash are included if SELF_TEST is defined.
-+ * You can use this free for any purpose. It has no warranty.
-+ *
-+ * Copyright (C) 2003 David S. Miller (davem@redhat.com)
-+ *
-+ * I've modified Bob's hash to be useful in the Linux kernel, and
-+ * any bugs present are surely my fault. -DaveM
-+ */
-+
-+/* NOTE: Arguments are modified. */
-+#define __jhash_mix(a, b, c) \
-+{ \
-+ a -= b; a -= c; a ^= (c>>13); \
-+ b -= c; b -= a; b ^= (a<<8); \
-+ c -= a; c -= b; c ^= (b>>13); \
-+ a -= b; a -= c; a ^= (c>>12); \
-+ b -= c; b -= a; b ^= (a<<16); \
-+ c -= a; c -= b; c ^= (b>>5); \
-+ a -= b; a -= c; a ^= (c>>3); \
-+ b -= c; b -= a; b ^= (a<<10); \
-+ c -= a; c -= b; c ^= (b>>15); \
-+}
-+
-+/* The golden ration: an arbitrary value */
-+#define JHASH_GOLDEN_RATIO 0x9e3779b9
-+
-+/* The most generic version, hashes an arbitrary sequence
-+ * of bytes. No alignment or length assumptions are made about
-+ * the input key.
-+ */
-+static inline __u32 jhash(void *key, __u32 length, __u32 initval)
-+{
-+ __u32 a, b, c, len;
-+ __u8 *k = key;
-+
-+ len = length;
-+ a = b = JHASH_GOLDEN_RATIO;
-+ c = initval;
-+
-+ while (len >= 12) {
-+ a += (k[0] +((__u32)k[1]<<8) +((__u32)k[2]<<16) +((__u32)k[3]<<24));
-+ b += (k[4] +((__u32)k[5]<<8) +((__u32)k[6]<<16) +((__u32)k[7]<<24));
-+ c += (k[8] +((__u32)k[9]<<8) +((__u32)k[10]<<16)+((__u32)k[11]<<24));
-+
-+ __jhash_mix(a,b,c);
-+
-+ k += 12;
-+ len -= 12;
-+ }
-+
-+ c += length;
-+ switch (len) {
-+ case 11: c += ((__u32)k[10]<<24);
-+ case 10: c += ((__u32)k[9]<<16);
-+ case 9 : c += ((__u32)k[8]<<8);
-+ case 8 : b += ((__u32)k[7]<<24);
-+ case 7 : b += ((__u32)k[6]<<16);
-+ case 6 : b += ((__u32)k[5]<<8);
-+ case 5 : b += k[4];
-+ case 4 : a += ((__u32)k[3]<<24);
-+ case 3 : a += ((__u32)k[2]<<16);
-+ case 2 : a += ((__u32)k[1]<<8);
-+ case 1 : a += k[0];
-+ };
-+
-+ __jhash_mix(a,b,c);
-+
-+ return c;
-+}
-+
-+/* A special optimized version that handles 1 or more of __u32s.
-+ * The length parameter here is the number of __u32s in the key.
-+ */
-+static inline __u32 jhash2(__u32 *k, __u32 length, __u32 initval)
-+{
-+ __u32 a, b, c, len;
-+
-+ a = b = JHASH_GOLDEN_RATIO;
-+ c = initval;
-+ len = length;
-+
-+ while (len >= 3) {
-+ a += k[0];
-+ b += k[1];
-+ c += k[2];
-+ __jhash_mix(a, b, c);
-+ k += 3; len -= 3;
-+ }
-+
-+ c += length * 4;
-+
-+ switch (len) {
-+ case 2 : b += k[1];
-+ case 1 : a += k[0];
-+ };
-+
-+ __jhash_mix(a,b,c);
-+
-+ return c;
-+}
-+
-+
-+/* A special ultra-optimized versions that knows they are hashing exactly
-+ * 3, 2 or 1 word(s).
-+ *
-+ * NOTE: In partilar the "c += length; __jhash_mix(a,b,c);" normally
-+ * done at the end is not done here.
-+ */
-+static inline __u32 jhash_3words(__u32 a, __u32 b, __u32 c, __u32 initval)
-+{
-+ a += JHASH_GOLDEN_RATIO;
-+ b += JHASH_GOLDEN_RATIO;
-+ c += initval;
-+
-+ __jhash_mix(a, b, c);
-+
-+ return c;
-+}
-+
-+static inline __u32 jhash_2words(__u32 a, __u32 b, __u32 initval)
-+{
-+ return jhash_3words(a, b, 0, initval);
-+}
-+
-+static inline __u32 jhash_1word(__u32 a, __u32 initval)
-+{
-+ return jhash_3words(a, 0, 0, initval);
-+}
-+
-+#endif /* _LINUX_IPSET_JHASH_H */
---- /dev/null
-+++ b/include/linux/netfilter_ipv4/ip_set_macipmap.h
-@@ -0,0 +1,38 @@
-+#ifndef __IP_SET_MACIPMAP_H
-+#define __IP_SET_MACIPMAP_H
-+
-+#include <linux/netfilter_ipv4/ip_set.h>
-+
-+#define SETTYPE_NAME "macipmap"
-+#define MAX_RANGE 0x0000FFFF
-+
-+/* general flags */
-+#define IPSET_MACIP_MATCHUNSET 1
-+
-+/* per ip flags */
-+#define IPSET_MACIP_ISSET 1
-+
-+struct ip_set_macipmap {
-+ void *members; /* the macipmap proper */
-+ ip_set_ip_t first_ip; /* host byte order, included in range */
-+ ip_set_ip_t last_ip; /* host byte order, included in range */
-+ u_int32_t flags;
-+};
-+
-+struct ip_set_req_macipmap_create {
-+ ip_set_ip_t from;
-+ ip_set_ip_t to;
-+ u_int32_t flags;
-+};
-+
-+struct ip_set_req_macipmap {
-+ ip_set_ip_t ip;
-+ unsigned char ethernet[ETH_ALEN];
-+};
-+
-+struct ip_set_macip {
-+ unsigned short flags;
-+ unsigned char ethernet[ETH_ALEN];
-+};
-+
-+#endif /* __IP_SET_MACIPMAP_H */
---- /dev/null
-+++ b/include/linux/netfilter_ipv4/ip_set_malloc.h
-@@ -0,0 +1,116 @@
-+#ifndef _IP_SET_MALLOC_H
-+#define _IP_SET_MALLOC_H
-+
-+#ifdef __KERNEL__
-+
-+/* Memory allocation and deallocation */
-+static size_t max_malloc_size = 0;
-+
-+static inline void init_max_malloc_size(void)
-+{
-+#define CACHE(x) max_malloc_size = x;
-+#include <linux/kmalloc_sizes.h>
-+#undef CACHE
-+}
-+
-+static inline void * ip_set_malloc(size_t bytes)
-+{
-+ if (bytes > max_malloc_size)
-+ return vmalloc(bytes);
-+ else
-+ return kmalloc(bytes, GFP_KERNEL);
-+}
-+
-+static inline void ip_set_free(void * data, size_t bytes)
-+{
-+ if (bytes > max_malloc_size)
-+ vfree(data);
-+ else
-+ kfree(data);
-+}
-+
-+struct harray {
-+ size_t max_elements;
-+ void *arrays[0];
-+};
-+
-+static inline void *
-+harray_malloc(size_t hashsize, size_t typesize, int flags)
-+{
-+ struct harray *harray;
-+ size_t max_elements, size, i, j;
-+
-+ if (!max_malloc_size)
-+ init_max_malloc_size();
-+
-+ if (typesize > max_malloc_size)
-+ return NULL;
-+
-+ max_elements = max_malloc_size/typesize;
-+ size = hashsize/max_elements;
-+ if (hashsize % max_elements)
-+ size++;
-+
-+ /* Last pointer signals end of arrays */
-+ harray = kmalloc(sizeof(struct harray) + (size + 1) * sizeof(void *),
-+ flags);
-+
-+ if (!harray)
-+ return NULL;
-+
-+ for (i = 0; i < size - 1; i++) {
-+ harray->arrays[i] = kmalloc(max_elements * typesize, flags);
-+ if (!harray->arrays[i])
-+ goto undo;
-+ memset(harray->arrays[i], 0, max_elements * typesize);
-+ }
-+ harray->arrays[i] = kmalloc((hashsize - i * max_elements) * typesize,
-+ flags);
-+ if (!harray->arrays[i])
-+ goto undo;
-+ memset(harray->arrays[i], 0, (hashsize - i * max_elements) * typesize);
-+
-+ harray->max_elements = max_elements;
-+ harray->arrays[size] = NULL;
-+
-+ return (void *)harray;
-+
-+ undo:
-+ for (j = 0; j < i; j++) {
-+ kfree(harray->arrays[j]);
-+ }
-+ kfree(harray);
-+ return NULL;
-+}
-+
-+static inline void harray_free(void *h)
-+{
-+ struct harray *harray = (struct harray *) h;
-+ size_t i;
-+
-+ for (i = 0; harray->arrays[i] != NULL; i++)
-+ kfree(harray->arrays[i]);
-+ kfree(harray);
-+}
-+
-+static inline void harray_flush(void *h, size_t hashsize, size_t typesize)
-+{
-+ struct harray *harray = (struct harray *) h;
-+ size_t i;
-+
-+ for (i = 0; harray->arrays[i+1] != NULL; i++)
-+ memset(harray->arrays[i], 0, harray->max_elements * typesize);
-+ memset(harray->arrays[i], 0,
-+ (hashsize - i * harray->max_elements) * typesize);
-+}
-+
-+#define HARRAY_ELEM(h, type, which) \
-+({ \
-+ struct harray *__h = (struct harray *)(h); \
-+ ((type)((__h)->arrays[(which)/(__h)->max_elements]) \
-+ + (which)%(__h)->max_elements); \
-+})
-+
-+#endif /* __KERNEL__ */
-+
-+#endif /*_IP_SET_MALLOC_H*/
---- /dev/null
-+++ b/include/linux/netfilter_ipv4/ip_set_nethash.h
-@@ -0,0 +1,55 @@
-+#ifndef __IP_SET_NETHASH_H
-+#define __IP_SET_NETHASH_H
-+
-+#include <linux/netfilter_ipv4/ip_set.h>
-+
-+#define SETTYPE_NAME "nethash"
-+#define MAX_RANGE 0x0000FFFF
-+
-+struct ip_set_nethash {
-+ ip_set_ip_t *members; /* the nethash proper */
-+ uint32_t elements; /* number of elements */
-+ uint32_t hashsize; /* hash size */
-+ uint16_t probes; /* max number of probes */
-+ uint16_t resize; /* resize factor in percent */
-+ unsigned char cidr[30]; /* CIDR sizes */
-+ void *initval[0]; /* initvals for jhash_1word */
-+};
-+
-+struct ip_set_req_nethash_create {
-+ uint32_t hashsize;
-+ uint16_t probes;
-+ uint16_t resize;
-+};
-+
-+struct ip_set_req_nethash {
-+ ip_set_ip_t ip;
-+ unsigned char cidr;
-+};
-+
-+static unsigned char shifts[] = {255, 253, 249, 241, 225, 193, 129, 1};
-+
-+static inline ip_set_ip_t
-+pack(ip_set_ip_t ip, unsigned char cidr)
-+{
-+ ip_set_ip_t addr, *paddr = &addr;
-+ unsigned char n, t, *a;
-+
-+ addr = htonl(ip & (0xFFFFFFFF << (32 - (cidr))));
-+#ifdef __KERNEL__
-+ DP("ip:%u.%u.%u.%u/%u", NIPQUAD(addr), cidr);
-+#endif
-+ n = cidr / 8;
-+ t = cidr % 8;
-+ a = &((unsigned char *)paddr)[n];
-+ *a = *a /(1 << (8 - t)) + shifts[t];
-+#ifdef __KERNEL__
-+ DP("n: %u, t: %u, a: %u", n, t, *a);
-+ DP("ip:%u.%u.%u.%u/%u, %u.%u.%u.%u",
-+ HIPQUAD(ip), cidr, NIPQUAD(addr));
-+#endif
-+
-+ return ntohl(addr);
-+}
-+
-+#endif /* __IP_SET_NETHASH_H */
---- /dev/null
-+++ b/include/linux/netfilter_ipv4/ip_set_portmap.h
-@@ -0,0 +1,25 @@
-+#ifndef __IP_SET_PORTMAP_H
-+#define __IP_SET_PORTMAP_H
-+
-+#include <linux/netfilter_ipv4/ip_set.h>
-+
-+#define SETTYPE_NAME "portmap"
-+#define MAX_RANGE 0x0000FFFF
-+#define INVALID_PORT (MAX_RANGE + 1)
-+
-+struct ip_set_portmap {
-+ void *members; /* the portmap proper */
-+ ip_set_ip_t first_port; /* host byte order, included in range */
-+ ip_set_ip_t last_port; /* host byte order, included in range */
-+};
-+
-+struct ip_set_req_portmap_create {
-+ ip_set_ip_t from;
-+ ip_set_ip_t to;
-+};
-+
-+struct ip_set_req_portmap {
-+ ip_set_ip_t port;
-+};
-+
-+#endif /* __IP_SET_PORTMAP_H */
---- /dev/null
-+++ b/include/linux/netfilter_ipv4/ipt_set.h
-@@ -0,0 +1,21 @@
-+#ifndef _IPT_SET_H
-+#define _IPT_SET_H
-+
-+#include <linux/netfilter_ipv4/ip_set.h>
-+
-+struct ipt_set_info {
-+ ip_set_id_t index;
-+ u_int32_t flags[IP_SET_MAX_BINDINGS + 1];
-+};
-+
-+/* match info */
-+struct ipt_set_info_match {
-+ struct ipt_set_info match_set;
-+};
-+
-+struct ipt_set_info_target {
-+ struct ipt_set_info add_set;
-+ struct ipt_set_info del_set;
-+};
-+
-+#endif /*_IPT_SET_H*/
---- /dev/null
-+++ b/net/ipv4/netfilter/ip_set.c
-@@ -0,0 +1,2003 @@
-+/* Copyright (C) 2000-2002 Joakim Axelsson <gozem@linux.nu>
-+ * Patrick Schaaf <bof@bof.de>
-+ * Copyright (C) 2003-2004 Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
-+ *
-+ * This program is free software; you can redistribute it and/or modify
-+ * it under the terms of the GNU General Public License version 2 as
-+ * published by the Free Software Foundation.
-+ */
-+
-+/* Kernel module for IP set management */
-+
-+#include <linux/version.h>
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
-+#include <linux/config.h>
-+#endif
-+#include <linux/module.h>
-+#include <linux/moduleparam.h>
-+#include <linux/kmod.h>
-+#include <linux/ip.h>
-+#include <linux/skbuff.h>
-+#include <linux/random.h>
-+#include <linux/jhash.h>
-+#include <linux/netfilter_ipv4/ip_tables.h>
-+#include <linux/errno.h>
-+#include <asm/uaccess.h>
-+#include <asm/bitops.h>
-+#include <asm/semaphore.h>
-+#include <linux/spinlock.h>
-+#include <linux/vmalloc.h>
-+
-+#define ASSERT_READ_LOCK(x)
-+#define ASSERT_WRITE_LOCK(x)
-+#include <linux/netfilter_ipv4/ip_set.h>
-+
-+static struct list_head set_type_list; /* all registered sets */
-+static struct ip_set **ip_set_list; /* all individual sets */
-+static DEFINE_RWLOCK(ip_set_lock); /* protects the lists and the hash */
-+static DECLARE_MUTEX(ip_set_app_mutex); /* serializes user access */
-+static ip_set_id_t ip_set_max = CONFIG_IP_NF_SET_MAX;
-+static ip_set_id_t ip_set_bindings_hash_size = CONFIG_IP_NF_SET_HASHSIZE;
-+static struct list_head *ip_set_hash; /* hash of bindings */
-+static unsigned int ip_set_hash_random; /* random seed */
-+
-+/*
-+ * Sets are identified either by the index in ip_set_list or by id.
-+ * The id never changes and is used to find a key in the hash.
-+ * The index may change by swapping and used at all other places
-+ * (set/SET netfilter modules, binding value, etc.)
-+ *
-+ * Userspace requests are serialized by ip_set_mutex and sets can
-+ * be deleted only from userspace. Therefore ip_set_list locking
-+ * must obey the following rules:
-+ *
-+ * - kernel requests: read and write locking mandatory
-+ * - user requests: read locking optional, write locking mandatory
-+ */
-+
-+static inline void
-+__ip_set_get(ip_set_id_t index)
-+{
-+ atomic_inc(&ip_set_list[index]->ref);
-+}
-+
-+static inline void
-+__ip_set_put(ip_set_id_t index)
-+{
-+ atomic_dec(&ip_set_list[index]->ref);
-+}
-+
-+/*
-+ * Binding routines
-+ */
-+
-+static inline struct ip_set_hash *
-+__ip_set_find(u_int32_t key, ip_set_id_t id, ip_set_ip_t ip)
-+{
-+ struct ip_set_hash *set_hash;
-+
-+ list_for_each_entry(set_hash, &ip_set_hash[key], list)
-+ if (set_hash->id == id && set_hash->ip == ip)
-+ return set_hash;
-+
-+ return NULL;
-+}
-+
-+static ip_set_id_t
-+ip_set_find_in_hash(ip_set_id_t id, ip_set_ip_t ip)
-+{
-+ u_int32_t key = jhash_2words(id, ip, ip_set_hash_random)
-+ % ip_set_bindings_hash_size;
-+ struct ip_set_hash *set_hash;
-+
-+ ASSERT_READ_LOCK(&ip_set_lock);
-+ IP_SET_ASSERT(ip_set_list[id]);
-+ DP("set: %s, ip: %u.%u.%u.%u", ip_set_list[id]->name, HIPQUAD(ip));
-+
-+ set_hash = __ip_set_find(key, id, ip);
-+
-+ DP("set: %s, ip: %u.%u.%u.%u, binding: %s", ip_set_list[id]->name,
-+ HIPQUAD(ip),
-+ set_hash != NULL ? ip_set_list[set_hash->binding]->name : "");
-+
-+ return (set_hash != NULL ? set_hash->binding : IP_SET_INVALID_ID);
-+}
-+
-+static inline void
-+__set_hash_del(struct ip_set_hash *set_hash)
-+{
-+ ASSERT_WRITE_LOCK(&ip_set_lock);
-+ IP_SET_ASSERT(ip_set_list[set_hash->binding]);
-+
-+ __ip_set_put(set_hash->binding);
-+ list_del(&set_hash->list);
-+ kfree(set_hash);
-+}
-+
-+static int
-+ip_set_hash_del(ip_set_id_t id, ip_set_ip_t ip)
-+{
-+ u_int32_t key = jhash_2words(id, ip, ip_set_hash_random)
-+ % ip_set_bindings_hash_size;
-+ struct ip_set_hash *set_hash;
-+
-+ IP_SET_ASSERT(ip_set_list[id]);
-+ DP("set: %s, ip: %u.%u.%u.%u", ip_set_list[id]->name, HIPQUAD(ip));
-+ write_lock_bh(&ip_set_lock);
-+ set_hash = __ip_set_find(key, id, ip);
-+ DP("set: %s, ip: %u.%u.%u.%u, binding: %s", ip_set_list[id]->name,
-+ HIPQUAD(ip),
-+ set_hash != NULL ? ip_set_list[set_hash->binding]->name : "");
-+
-+ if (set_hash != NULL)
-+ __set_hash_del(set_hash);
-+ write_unlock_bh(&ip_set_lock);
-+ return 0;
-+}
-+
-+static int
-+ip_set_hash_add(ip_set_id_t id, ip_set_ip_t ip, ip_set_id_t binding)
-+{
-+ u_int32_t key = jhash_2words(id, ip, ip_set_hash_random)
-+ % ip_set_bindings_hash_size;
-+ struct ip_set_hash *set_hash;
-+ int ret = 0;
-+
-+ IP_SET_ASSERT(ip_set_list[id]);
-+ IP_SET_ASSERT(ip_set_list[binding]);
-+ DP("set: %s, ip: %u.%u.%u.%u, binding: %s", ip_set_list[id]->name,
-+ HIPQUAD(ip), ip_set_list[binding]->name);
-+ write_lock_bh(&ip_set_lock);
-+ set_hash = __ip_set_find(key, id, ip);
-+ if (!set_hash) {
-+ set_hash = kmalloc(sizeof(struct ip_set_hash), GFP_ATOMIC);
-+ if (!set_hash) {
-+ ret = -ENOMEM;
-+ goto unlock;
-+ }
-+ INIT_LIST_HEAD(&set_hash->list);
-+ set_hash->id = id;
-+ set_hash->ip = ip;
-+ list_add(&set_hash->list, &ip_set_hash[key]);
-+ } else {
-+ IP_SET_ASSERT(ip_set_list[set_hash->binding]);
-+ DP("overwrite binding: %s",
-+ ip_set_list[set_hash->binding]->name);
-+ __ip_set_put(set_hash->binding);
-+ }
-+ set_hash->binding = binding;
-+ __ip_set_get(set_hash->binding);
-+ DP("stored: key %u, id %u (%s), ip %u.%u.%u.%u, binding %u (%s)",
-+ key, id, ip_set_list[id]->name,
-+ HIPQUAD(ip), binding, ip_set_list[binding]->name);
-+ unlock:
-+ write_unlock_bh(&ip_set_lock);
-+ return ret;
-+}
-+
-+#define FOREACH_HASH_DO(fn, args...) \
-+({ \
-+ ip_set_id_t __key; \
-+ struct ip_set_hash *__set_hash; \
-+ \
-+ for (__key = 0; __key < ip_set_bindings_hash_size; __key++) { \
-+ list_for_each_entry(__set_hash, &ip_set_hash[__key], list) \
-+ fn(__set_hash , ## args); \
-+ } \
-+})
-+
-+#define FOREACH_HASH_RW_DO(fn, args...) \
-+({ \
-+ ip_set_id_t __key; \
-+ struct ip_set_hash *__set_hash, *__n; \
-+ \
-+ ASSERT_WRITE_LOCK(&ip_set_lock); \
-+ for (__key = 0; __key < ip_set_bindings_hash_size; __key++) { \
-+ list_for_each_entry_safe(__set_hash, __n, &ip_set_hash[__key], list)\
-+ fn(__set_hash , ## args); \
-+ } \
-+})
-+
-+/* Add, del and test set entries from kernel */
-+
-+#define follow_bindings(index, set, ip) \
-+((index = ip_set_find_in_hash((set)->id, ip)) != IP_SET_INVALID_ID \
-+ || (index = (set)->binding) != IP_SET_INVALID_ID)
-+
-+int
-+ip_set_testip_kernel(ip_set_id_t index,
-+ const struct sk_buff *skb,
-+ const u_int32_t *flags)
-+{
-+ struct ip_set *set;
-+ ip_set_ip_t ip;
-+ int res;
-+ unsigned char i = 0;
-+
-+ IP_SET_ASSERT(flags[i]);
-+ read_lock_bh(&ip_set_lock);
-+ do {
-+ set = ip_set_list[index];
-+ IP_SET_ASSERT(set);
-+ DP("set %s, index %u", set->name, index);
-+ read_lock_bh(&set->lock);
-+ res = set->type->testip_kernel(set, skb, &ip, flags, i++);
-+ read_unlock_bh(&set->lock);
-+ i += !!(set->type->features & IPSET_DATA_DOUBLE);
-+ } while (res > 0
-+ && flags[i]
-+ && follow_bindings(index, set, ip));
-+ read_unlock_bh(&ip_set_lock);
-+
-+ return res;
-+}
-+
-+void
-+ip_set_addip_kernel(ip_set_id_t index,
-+ const struct sk_buff *skb,
-+ const u_int32_t *flags)
-+{
-+ struct ip_set *set;
-+ ip_set_ip_t ip;
-+ int res;
-+ unsigned char i = 0;
-+
-+ IP_SET_ASSERT(flags[i]);
-+ retry:
-+ read_lock_bh(&ip_set_lock);
-+ do {
-+ set = ip_set_list[index];
-+ IP_SET_ASSERT(set);
-+ DP("set %s, index %u", set->name, index);
-+ write_lock_bh(&set->lock);
-+ res = set->type->addip_kernel(set, skb, &ip, flags, i++);
-+ write_unlock_bh(&set->lock);
-+ i += !!(set->type->features & IPSET_DATA_DOUBLE);
-+ } while ((res == 0 || res == -EEXIST)
-+ && flags[i]
-+ && follow_bindings(index, set, ip));
-+ read_unlock_bh(&ip_set_lock);
-+
-+ if (res == -EAGAIN
-+ && set->type->retry
-+ && (res = set->type->retry(set)) == 0)
-+ goto retry;
-+}
-+
-+void
-+ip_set_delip_kernel(ip_set_id_t index,
-+ const struct sk_buff *skb,
-+ const u_int32_t *flags)
-+{
-+ struct ip_set *set;
-+ ip_set_ip_t ip;
-+ int res;
-+ unsigned char i = 0;
-+
-+ IP_SET_ASSERT(flags[i]);
-+ read_lock_bh(&ip_set_lock);
-+ do {
-+ set = ip_set_list[index];
-+ IP_SET_ASSERT(set);
-+ DP("set %s, index %u", set->name, index);
-+ write_lock_bh(&set->lock);
-+ res = set->type->delip_kernel(set, skb, &ip, flags, i++);
-+ write_unlock_bh(&set->lock);
-+ i += !!(set->type->features & IPSET_DATA_DOUBLE);
-+ } while ((res == 0 || res == -EEXIST)
-+ && flags[i]
-+ && follow_bindings(index, set, ip));
-+ read_unlock_bh(&ip_set_lock);
-+}
-+
-+/* Register and deregister settype */
-+
-+static inline struct ip_set_type *
-+find_set_type(const char *name)
-+{
-+ struct ip_set_type *set_type;
-+
-+ list_for_each_entry(set_type, &set_type_list, list)
-+ if (!strncmp(set_type->typename, name, IP_SET_MAXNAMELEN - 1))
-+ return set_type;
-+ return NULL;
-+}
-+
-+int
-+ip_set_register_set_type(struct ip_set_type *set_type)
-+{
-+ int ret = 0;
-+
-+ if (set_type->protocol_version != IP_SET_PROTOCOL_VERSION) {
-+ ip_set_printk("'%s' uses wrong protocol version %u (want %u)",
-+ set_type->typename,
-+ set_type->protocol_version,
-+ IP_SET_PROTOCOL_VERSION);
-+ return -EINVAL;
-+ }
-+
-+ write_lock_bh(&ip_set_lock);
-+ if (find_set_type(set_type->typename)) {
-+ /* Duplicate! */
-+ ip_set_printk("'%s' already registered!",
-+ set_type->typename);
-+ ret = -EINVAL;
-+ goto unlock;
-+ }
-+ if (!try_module_get(THIS_MODULE)) {
-+ ret = -EFAULT;
-+ goto unlock;
-+ }
-+ list_add(&set_type->list, &set_type_list);
-+ DP("'%s' registered.", set_type->typename);
-+ unlock:
-+ write_unlock_bh(&ip_set_lock);
-+ return ret;
-+}
-+
-+void
-+ip_set_unregister_set_type(struct ip_set_type *set_type)
-+{
-+ write_lock_bh(&ip_set_lock);
-+ if (!find_set_type(set_type->typename)) {
-+ ip_set_printk("'%s' not registered?",
-+ set_type->typename);
-+ goto unlock;
-+ }
-+ list_del(&set_type->list);
-+ module_put(THIS_MODULE);
-+ DP("'%s' unregistered.", set_type->typename);
-+ unlock:
-+ write_unlock_bh(&ip_set_lock);
-+
-+}
-+
-+/*
-+ * Userspace routines
-+ */
-+
-+/*
-+ * Find set by name, reference it once. The reference makes sure the
-+ * thing pointed to, does not go away under our feet. Drop the reference
-+ * later, using ip_set_put().
-+ */
-+ip_set_id_t
-+ip_set_get_byname(const char *name)
-+{
-+ ip_set_id_t i, index = IP_SET_INVALID_ID;
-+
-+ down(&ip_set_app_mutex);
-+ for (i = 0; i < ip_set_max; i++) {
-+ if (ip_set_list[i] != NULL
-+ && strcmp(ip_set_list[i]->name, name) == 0) {
-+ __ip_set_get(i);
-+ index = i;
-+ break;
-+ }
-+ }
-+ up(&ip_set_app_mutex);
-+ return index;
-+}
-+
-+/*
-+ * Find set by index, reference it once. The reference makes sure the
-+ * thing pointed to, does not go away under our feet. Drop the reference
-+ * later, using ip_set_put().
-+ */
-+ip_set_id_t
-+ip_set_get_byindex(ip_set_id_t index)
-+{
-+ down(&ip_set_app_mutex);
-+
-+ if (index >= ip_set_max)
-+ return IP_SET_INVALID_ID;
-+
-+ if (ip_set_list[index])
-+ __ip_set_get(index);
-+ else
-+ index = IP_SET_INVALID_ID;
-+
-+ up(&ip_set_app_mutex);
-+ return index;
-+}
-+
-+/*
-+ * If the given set pointer points to a valid set, decrement
-+ * reference count by 1. The caller shall not assume the index
-+ * to be valid, after calling this function.
-+ */
-+void ip_set_put(ip_set_id_t index)
-+{
-+ down(&ip_set_app_mutex);
-+ if (ip_set_list[index])
-+ __ip_set_put(index);
-+ up(&ip_set_app_mutex);
-+}
-+
-+/* Find a set by name or index */
-+static ip_set_id_t
-+ip_set_find_byname(const char *name)
-+{
-+ ip_set_id_t i, index = IP_SET_INVALID_ID;
-+
-+ for (i = 0; i < ip_set_max; i++) {
-+ if (ip_set_list[i] != NULL
-+ && strcmp(ip_set_list[i]->name, name) == 0) {
-+ index = i;
-+ break;
-+ }
-+ }
-+ return index;
-+}
-+
-+static ip_set_id_t
-+ip_set_find_byindex(ip_set_id_t index)
-+{
-+ if (index >= ip_set_max || ip_set_list[index] == NULL)
-+ index = IP_SET_INVALID_ID;
-+
-+ return index;
-+}
-+
-+/*
-+ * Add, del, test, bind and unbind
-+ */
-+
-+static inline int
-+__ip_set_testip(struct ip_set *set,
-+ const void *data,
-+ size_t size,
-+ ip_set_ip_t *ip)
-+{
-+ int res;
-+
-+ read_lock_bh(&set->lock);
-+ res = set->type->testip(set, data, size, ip);
-+ read_unlock_bh(&set->lock);
-+
-+ return res;
-+}
-+
-+static int
-+__ip_set_addip(ip_set_id_t index,
-+ const void *data,
-+ size_t size)
-+{
-+ struct ip_set *set = ip_set_list[index];
-+ ip_set_ip_t ip;
-+ int res;
-+
-+ IP_SET_ASSERT(set);
-+ do {
-+ write_lock_bh(&set->lock);
-+ res = set->type->addip(set, data, size, &ip);
-+ write_unlock_bh(&set->lock);
-+ } while (res == -EAGAIN
-+ && set->type->retry
-+ && (res = set->type->retry(set)) == 0);
-+
-+ return res;
-+}
-+
-+static int
-+ip_set_addip(ip_set_id_t index,
-+ const void *data,
-+ size_t size)
-+{
-+
-+ return __ip_set_addip(index,
-+ data + sizeof(struct ip_set_req_adt),
-+ size - sizeof(struct ip_set_req_adt));
-+}
-+
-+static int
-+ip_set_delip(ip_set_id_t index,
-+ const void *data,
-+ size_t size)
-+{
-+ struct ip_set *set = ip_set_list[index];
-+ ip_set_ip_t ip;
-+ int res;
-+
-+ IP_SET_ASSERT(set);
-+ write_lock_bh(&set->lock);
-+ res = set->type->delip(set,
-+ data + sizeof(struct ip_set_req_adt),
-+ size - sizeof(struct ip_set_req_adt),
-+ &ip);
-+ write_unlock_bh(&set->lock);
-+
-+ return res;
-+}
-+
-+static int
-+ip_set_testip(ip_set_id_t index,
-+ const void *data,
-+ size_t size)
-+{
-+ struct ip_set *set = ip_set_list[index];
-+ ip_set_ip_t ip;
-+ int res;
-+
-+ IP_SET_ASSERT(set);
-+ res = __ip_set_testip(set,
-+ data + sizeof(struct ip_set_req_adt),
-+ size - sizeof(struct ip_set_req_adt),
-+ &ip);
-+
-+ return (res > 0 ? -EEXIST : res);
-+}
-+
-+static int
-+ip_set_bindip(ip_set_id_t index,
-+ const void *data,
-+ size_t size)
-+{
-+ struct ip_set *set = ip_set_list[index];
-+ struct ip_set_req_bind *req_bind;
-+ ip_set_id_t binding;
-+ ip_set_ip_t ip;
-+ int res;
-+
-+ IP_SET_ASSERT(set);
-+ if (size < sizeof(struct ip_set_req_bind))
-+ return -EINVAL;
-+
-+ req_bind = (struct ip_set_req_bind *) data;
-+ req_bind->binding[IP_SET_MAXNAMELEN - 1] = '\0';
-+
-+ if (strcmp(req_bind->binding, IPSET_TOKEN_DEFAULT) == 0) {
-+ /* Default binding of a set */
-+ char *binding_name;
-+
-+ if (size != sizeof(struct ip_set_req_bind) + IP_SET_MAXNAMELEN)
-+ return -EINVAL;
-+
-+ binding_name = (char *)(data + sizeof(struct ip_set_req_bind));
-+ binding_name[IP_SET_MAXNAMELEN - 1] = '\0';
-+
-+ binding = ip_set_find_byname(binding_name);
-+ if (binding == IP_SET_INVALID_ID)
-+ return -ENOENT;
-+
-+ write_lock_bh(&ip_set_lock);
-+ /* Sets as binding values are referenced */
-+ if (set->binding != IP_SET_INVALID_ID)
-+ __ip_set_put(set->binding);
-+ set->binding = binding;
-+ __ip_set_get(set->binding);
-+ write_unlock_bh(&ip_set_lock);
-+
-+ return 0;
-+ }
-+ binding = ip_set_find_byname(req_bind->binding);
-+ if (binding == IP_SET_INVALID_ID)
-+ return -ENOENT;
-+
-+ res = __ip_set_testip(set,
-+ data + sizeof(struct ip_set_req_bind),
-+ size - sizeof(struct ip_set_req_bind),
-+ &ip);
-+ DP("set %s, ip: %u.%u.%u.%u, binding %s",
-+ set->name, HIPQUAD(ip), ip_set_list[binding]->name);
-+
-+ if (res >= 0)
-+ res = ip_set_hash_add(set->id, ip, binding);
-+
-+ return res;
-+}
-+
-+#define FOREACH_SET_DO(fn, args...) \
-+({ \
-+ ip_set_id_t __i; \
-+ struct ip_set *__set; \
-+ \
-+ for (__i = 0; __i < ip_set_max; __i++) { \
-+ __set = ip_set_list[__i]; \
-+ if (__set != NULL) \
-+ fn(__set , ##args); \
-+ } \
-+})
-+
-+static inline void
-+__set_hash_del_byid(struct ip_set_hash *set_hash, ip_set_id_t id)
-+{
-+ if (set_hash->id == id)
-+ __set_hash_del(set_hash);
-+}
-+
-+static inline void
-+__unbind_default(struct ip_set *set)
-+{
-+ if (set->binding != IP_SET_INVALID_ID) {
-+ /* Sets as binding values are referenced */
-+ __ip_set_put(set->binding);
-+ set->binding = IP_SET_INVALID_ID;
-+ }
-+}
-+
-+static int
-+ip_set_unbindip(ip_set_id_t index,
-+ const void *data,
-+ size_t size)
-+{
-+ struct ip_set *set;
-+ struct ip_set_req_bind *req_bind;
-+ ip_set_ip_t ip;
-+ int res;
-+
-+ DP("");
-+ if (size < sizeof(struct ip_set_req_bind))
-+ return -EINVAL;
-+
-+ req_bind = (struct ip_set_req_bind *) data;
-+ req_bind->binding[IP_SET_MAXNAMELEN - 1] = '\0';
-+
-+ DP("%u %s", index, req_bind->binding);
-+ if (index == IP_SET_INVALID_ID) {
-+ /* unbind :all: */
-+ if (strcmp(req_bind->binding, IPSET_TOKEN_DEFAULT) == 0) {
-+ /* Default binding of sets */
-+ write_lock_bh(&ip_set_lock);
-+ FOREACH_SET_DO(__unbind_default);
-+ write_unlock_bh(&ip_set_lock);
-+ return 0;
-+ } else if (strcmp(req_bind->binding, IPSET_TOKEN_ALL) == 0) {
-+ /* Flush all bindings of all sets*/
-+ write_lock_bh(&ip_set_lock);
-+ FOREACH_HASH_RW_DO(__set_hash_del);
-+ write_unlock_bh(&ip_set_lock);
-+ return 0;
-+ }
-+ DP("unreachable reached!");
-+ return -EINVAL;
-+ }
-+
-+ set = ip_set_list[index];
-+ IP_SET_ASSERT(set);
-+ if (strcmp(req_bind->binding, IPSET_TOKEN_DEFAULT) == 0) {
-+ /* Default binding of set */
-+ ip_set_id_t binding = ip_set_find_byindex(set->binding);
-+
-+ if (binding == IP_SET_INVALID_ID)
-+ return -ENOENT;
-+
-+ write_lock_bh(&ip_set_lock);
-+ /* Sets in hash values are referenced */
-+ __ip_set_put(set->binding);
-+ set->binding = IP_SET_INVALID_ID;
-+ write_unlock_bh(&ip_set_lock);
-+
-+ return 0;
-+ } else if (strcmp(req_bind->binding, IPSET_TOKEN_ALL) == 0) {
-+ /* Flush all bindings */
-+
-+ write_lock_bh(&ip_set_lock);
-+ FOREACH_HASH_RW_DO(__set_hash_del_byid, set->id);
-+ write_unlock_bh(&ip_set_lock);
-+ return 0;
-+ }
-+
-+ res = __ip_set_testip(set,
-+ data + sizeof(struct ip_set_req_bind),
-+ size - sizeof(struct ip_set_req_bind),
-+ &ip);
-+
-+ DP("set %s, ip: %u.%u.%u.%u", set->name, HIPQUAD(ip));
-+ if (res >= 0)
-+ res = ip_set_hash_del(set->id, ip);
-+
-+ return res;
-+}
-+
-+static int
-+ip_set_testbind(ip_set_id_t index,
-+ const void *data,
-+ size_t size)
-+{
-+ struct ip_set *set = ip_set_list[index];
-+ struct ip_set_req_bind *req_bind;
-+ ip_set_id_t binding;
-+ ip_set_ip_t ip;
-+ int res;
-+
-+ IP_SET_ASSERT(set);
-+ if (size < sizeof(struct ip_set_req_bind))
-+ return -EINVAL;
-+
-+ req_bind = (struct ip_set_req_bind *) data;
-+ req_bind->binding[IP_SET_MAXNAMELEN - 1] = '\0';
-+
-+ if (strcmp(req_bind->binding, IPSET_TOKEN_DEFAULT) == 0) {
-+ /* Default binding of set */
-+ char *binding_name;
-+
-+ if (size != sizeof(struct ip_set_req_bind) + IP_SET_MAXNAMELEN)
-+ return -EINVAL;
-+
-+ binding_name = (char *)(data + sizeof(struct ip_set_req_bind));
-+ binding_name[IP_SET_MAXNAMELEN - 1] = '\0';
-+
-+ binding = ip_set_find_byname(binding_name);
-+ if (binding == IP_SET_INVALID_ID)
-+ return -ENOENT;
-+
-+ res = (set->binding == binding) ? -EEXIST : 0;
-+
-+ return res;
-+ }
-+ binding = ip_set_find_byname(req_bind->binding);
-+ if (binding == IP_SET_INVALID_ID)
-+ return -ENOENT;
-+
-+
-+ res = __ip_set_testip(set,
-+ data + sizeof(struct ip_set_req_bind),
-+ size - sizeof(struct ip_set_req_bind),
-+ &ip);
-+ DP("set %s, ip: %u.%u.%u.%u, binding %s",
-+ set->name, HIPQUAD(ip), ip_set_list[binding]->name);
-+
-+ if (res >= 0)
-+ res = (ip_set_find_in_hash(set->id, ip) == binding)
-+ ? -EEXIST : 0;
-+
-+ return res;
-+}
-+
-+static struct ip_set_type *
-+find_set_type_rlock(const char *typename)
-+{
-+ struct ip_set_type *type;
-+
-+ read_lock_bh(&ip_set_lock);
-+ type = find_set_type(typename);
-+ if (type == NULL)
-+ read_unlock_bh(&ip_set_lock);
-+
-+ return type;
-+}
-+
-+static int
-+find_free_id(const char *name,
-+ ip_set_id_t *index,
-+ ip_set_id_t *id)
-+{
-+ ip_set_id_t i;
-+
-+ *id = IP_SET_INVALID_ID;
-+ for (i = 0; i < ip_set_max; i++) {
-+ if (ip_set_list[i] == NULL) {
-+ if (*id == IP_SET_INVALID_ID)
-+ *id = *index = i;
-+ } else if (strcmp(name, ip_set_list[i]->name) == 0)
-+ /* Name clash */
-+ return -EEXIST;
-+ }
-+ if (*id == IP_SET_INVALID_ID)
-+ /* No free slot remained */
-+ return -ERANGE;
-+ /* Check that index is usable as id (swapping) */
-+ check:
-+ for (i = 0; i < ip_set_max; i++) {
-+ if (ip_set_list[i] != NULL
-+ && ip_set_list[i]->id == *id) {
-+ *id = i;
-+ goto check;
-+ }
-+ }
-+ return 0;
-+}
-+
-+/*
-+ * Create a set
-+ */
-+static int
-+ip_set_create(const char *name,
-+ const char *typename,
-+ ip_set_id_t restore,
-+ const void *data,
-+ size_t size)
-+{
-+ struct ip_set *set;
-+ ip_set_id_t index = 0, id;
-+ int res = 0;
-+
-+ DP("setname: %s, typename: %s, id: %u", name, typename, restore);
-+ /*
-+ * First, and without any locks, allocate and initialize
-+ * a normal base set structure.
-+ */
-+ set = kmalloc(sizeof(struct ip_set), GFP_KERNEL);
-+ if (!set)
-+ return -ENOMEM;
-+ set->lock = RW_LOCK_UNLOCKED;
-+ strncpy(set->name, name, IP_SET_MAXNAMELEN);
-+ set->binding = IP_SET_INVALID_ID;
-+ atomic_set(&set->ref, 0);
-+
-+ /*
-+ * Next, take the &ip_set_lock, check that we know the type,
-+ * and take a reference on the type, to make sure it
-+ * stays available while constructing our new set.
-+ *
-+ * After referencing the type, we drop the &ip_set_lock,
-+ * and let the new set construction run without locks.
-+ */
-+ set->type = find_set_type_rlock(typename);
-+ if (set->type == NULL) {
-+ /* Try loading the module */
-+ char modulename[IP_SET_MAXNAMELEN + strlen("ip_set_") + 1];
-+ strcpy(modulename, "ip_set_");
-+ strcat(modulename, typename);
-+ DP("try to load %s", modulename);
-+ request_module(modulename);
-+ set->type = find_set_type_rlock(typename);
-+ }
-+ if (set->type == NULL) {
-+ ip_set_printk("no set type '%s', set '%s' not created",
-+ typename, name);
-+ res = -ENOENT;
-+ goto out;
-+ }
-+ if (!try_module_get(set->type->me)) {
-+ read_unlock_bh(&ip_set_lock);
-+ res = -EFAULT;
-+ goto out;
-+ }
-+ read_unlock_bh(&ip_set_lock);
-+
-+ /*
-+ * Without holding any locks, create private part.
-+ */
-+ res = set->type->create(set, data, size);
-+ if (res != 0)
-+ goto put_out;
-+
-+ /* BTW, res==0 here. */
-+
-+ /*
-+ * Here, we have a valid, constructed set. &ip_set_lock again,
-+ * find free id/index and check that it is not already in
-+ * ip_set_list.
-+ */
-+ write_lock_bh(&ip_set_lock);
-+ if ((res = find_free_id(set->name, &index, &id)) != 0) {
-+ DP("no free id!");
-+ goto cleanup;
-+ }
-+
-+ /* Make sure restore gets the same index */
-+ if (restore != IP_SET_INVALID_ID && index != restore) {
-+ DP("Can't restore, sets are screwed up");
-+ res = -ERANGE;
-+ goto cleanup;
-+ }
-+
-+ /*
-+ * Finally! Add our shiny new set to the list, and be done.
-+ */
-+ DP("create: '%s' created with index %u, id %u!", set->name, index, id);
-+ set->id = id;
-+ ip_set_list[index] = set;
-+ write_unlock_bh(&ip_set_lock);
-+ return res;
-+
-+ cleanup:
-+ write_unlock_bh(&ip_set_lock);
-+ set->type->destroy(set);
-+ put_out:
-+ module_put(set->type->me);
-+ out:
-+ kfree(set);
-+ return res;
-+}
-+
-+/*
-+ * Destroy a given existing set
-+ */
-+static void
-+ip_set_destroy_set(ip_set_id_t index)
-+{
-+ struct ip_set *set = ip_set_list[index];
-+
-+ IP_SET_ASSERT(set);
-+ DP("set: %s", set->name);
-+ write_lock_bh(&ip_set_lock);
-+ FOREACH_HASH_RW_DO(__set_hash_del_byid, set->id);
-+ if (set->binding != IP_SET_INVALID_ID)
-+ __ip_set_put(set->binding);
-+ ip_set_list[index] = NULL;
-+ write_unlock_bh(&ip_set_lock);
-+
-+ /* Must call it without holding any lock */
-+ set->type->destroy(set);
-+ module_put(set->type->me);
-+ kfree(set);
-+}
-+
-+/*
-+ * Destroy a set - or all sets
-+ * Sets must not be referenced/used.
-+ */
-+static int
-+ip_set_destroy(ip_set_id_t index)
-+{
-+ ip_set_id_t i;
-+
-+ /* ref modification always protected by the mutex */
-+ if (index != IP_SET_INVALID_ID) {
-+ if (atomic_read(&ip_set_list[index]->ref))
-+ return -EBUSY;
-+ ip_set_destroy_set(index);
-+ } else {
-+ for (i = 0; i < ip_set_max; i++) {
-+ if (ip_set_list[i] != NULL
-+ && (atomic_read(&ip_set_list[i]->ref)))
-+ return -EBUSY;
-+ }
-+
-+ for (i = 0; i < ip_set_max; i++) {
-+ if (ip_set_list[i] != NULL)
-+ ip_set_destroy_set(i);
-+ }
-+ }
-+ return 0;
-+}
-+
-+static void
-+ip_set_flush_set(struct ip_set *set)
-+{
-+ DP("set: %s %u", set->name, set->id);
-+
-+ write_lock_bh(&set->lock);
-+ set->type->flush(set);
-+ write_unlock_bh(&set->lock);
-+}
-+
-+/*
-+ * Flush data in a set - or in all sets
-+ */
-+static int
-+ip_set_flush(ip_set_id_t index)
-+{
-+ if (index != IP_SET_INVALID_ID) {
-+ IP_SET_ASSERT(ip_set_list[index]);
-+ ip_set_flush_set(ip_set_list[index]);
-+ } else
-+ FOREACH_SET_DO(ip_set_flush_set);
-+
-+ return 0;
-+}
-+
-+/* Rename a set */
-+static int
-+ip_set_rename(ip_set_id_t index, const char *name)
-+{
-+ struct ip_set *set = ip_set_list[index];
-+ ip_set_id_t i;
-+ int res = 0;
-+
-+ DP("set: %s to %s", set->name, name);
-+ write_lock_bh(&ip_set_lock);
-+ for (i = 0; i < ip_set_max; i++) {
-+ if (ip_set_list[i] != NULL
-+ && strncmp(ip_set_list[i]->name,
-+ name,
-+ IP_SET_MAXNAMELEN - 1) == 0) {
-+ res = -EEXIST;
-+ goto unlock;
-+ }
-+ }
-+ strncpy(set->name, name, IP_SET_MAXNAMELEN);
-+ unlock:
-+ write_unlock_bh(&ip_set_lock);
-+ return res;
-+}
-+
-+/*
-+ * Swap two sets so that name/index points to the other.
-+ * References are also swapped.
-+ */
-+static int
-+ip_set_swap(ip_set_id_t from_index, ip_set_id_t to_index)
-+{
-+ struct ip_set *from = ip_set_list[from_index];
-+ struct ip_set *to = ip_set_list[to_index];
-+ char from_name[IP_SET_MAXNAMELEN];
-+ u_int32_t from_ref;
-+
-+ DP("set: %s to %s", from->name, to->name);
-+ /* Features must not change. Artifical restriction. */
-+ if (from->type->features != to->type->features)
-+ return -ENOEXEC;
-+
-+ /* No magic here: ref munging protected by the mutex */
-+ write_lock_bh(&ip_set_lock);
-+ strncpy(from_name, from->name, IP_SET_MAXNAMELEN);
-+ from_ref = atomic_read(&from->ref);
-+
-+ strncpy(from->name, to->name, IP_SET_MAXNAMELEN);
-+ atomic_set(&from->ref, atomic_read(&to->ref));
-+ strncpy(to->name, from_name, IP_SET_MAXNAMELEN);
-+ atomic_set(&to->ref, from_ref);
-+
-+ ip_set_list[from_index] = to;
-+ ip_set_list[to_index] = from;
-+
-+ write_unlock_bh(&ip_set_lock);
-+ return 0;
-+}
-+
-+/*
-+ * List set data
-+ */
-+
-+static inline void
-+__set_hash_bindings_size_list(struct ip_set_hash *set_hash,
-+ ip_set_id_t id, size_t *size)
-+{
-+ if (set_hash->id == id)
-+ *size += sizeof(struct ip_set_hash_list);
-+}
-+
-+static inline void
-+__set_hash_bindings_size_save(struct ip_set_hash *set_hash,
-+ ip_set_id_t id, size_t *size)
-+{
-+ if (set_hash->id == id)
-+ *size += sizeof(struct ip_set_hash_save);
-+}
-+
-+static inline void
-+__set_hash_bindings(struct ip_set_hash *set_hash,
-+ ip_set_id_t id, void *data, int *used)
-+{
-+ if (set_hash->id == id) {
-+ struct ip_set_hash_list *hash_list =
-+ (struct ip_set_hash_list *)(data + *used);
-+
-+ hash_list->ip = set_hash->ip;
-+ hash_list->binding = set_hash->binding;
-+ *used += sizeof(struct ip_set_hash_list);
-+ }
-+}
-+
-+static int ip_set_list_set(ip_set_id_t index,
-+ void *data,
-+ int *used,
-+ int len)
-+{
-+ struct ip_set *set = ip_set_list[index];
-+ struct ip_set_list *set_list;
-+
-+ /* Pointer to our header */
-+ set_list = (struct ip_set_list *) (data + *used);
-+
-+ DP("set: %s, used: %d %p %p", set->name, *used, data, data + *used);
-+
-+ /* Get and ensure header size */
-+ if (*used + sizeof(struct ip_set_list) > len)
-+ goto not_enough_mem;
-+ *used += sizeof(struct ip_set_list);
-+
-+ read_lock_bh(&set->lock);
-+ /* Get and ensure set specific header size */
-+ set_list->header_size = set->type->header_size;
-+ if (*used + set_list->header_size > len)
-+ goto unlock_set;
-+
-+ /* Fill in the header */
-+ set_list->index = index;
-+ set_list->binding = set->binding;
-+ set_list->ref = atomic_read(&set->ref);
-+
-+ /* Fill in set spefific header data */
-+ set->type->list_header(set, data + *used);
-+ *used += set_list->header_size;
-+
-+ /* Get and ensure set specific members size */
-+ set_list->members_size = set->type->list_members_size(set);
-+ if (*used + set_list->members_size > len)
-+ goto unlock_set;
-+
-+ /* Fill in set spefific members data */
-+ set->type->list_members(set, data + *used);
-+ *used += set_list->members_size;
-+ read_unlock_bh(&set->lock);
-+
-+ /* Bindings */
-+
-+ /* Get and ensure set specific bindings size */
-+ set_list->bindings_size = 0;
-+ FOREACH_HASH_DO(__set_hash_bindings_size_list,
-+ set->id, &set_list->bindings_size);
-+ if (*used + set_list->bindings_size > len)
-+ goto not_enough_mem;
-+
-+ /* Fill in set spefific bindings data */
-+ FOREACH_HASH_DO(__set_hash_bindings, set->id, data, used);
-+
-+ return 0;
-+
-+ unlock_set:
-+ read_unlock_bh(&set->lock);
-+ not_enough_mem:
-+ DP("not enough mem, try again");
-+ return -EAGAIN;
-+}
-+
-+/*
-+ * Save sets
-+ */
-+static int ip_set_save_set(ip_set_id_t index,
-+ void *data,
-+ int *used,
-+ int len)
-+{
-+ struct ip_set *set;
-+ struct ip_set_save *set_save;
-+
-+ /* Pointer to our header */
-+ set_save = (struct ip_set_save *) (data + *used);
-+
-+ /* Get and ensure header size */
-+ if (*used + sizeof(struct ip_set_save) > len)
-+ goto not_enough_mem;
-+ *used += sizeof(struct ip_set_save);
-+
-+ set = ip_set_list[index];
-+ DP("set: %s, used: %u(%u) %p %p", set->name, *used, len,
-+ data, data + *used);
-+
-+ read_lock_bh(&set->lock);
-+ /* Get and ensure set specific header size */
-+ set_save->header_size = set->type->header_size;
-+ if (*used + set_save->header_size > len)
-+ goto unlock_set;
-+
-+ /* Fill in the header */
-+ set_save->index = index;
-+ set_save->binding = set->binding;
-+
-+ /* Fill in set spefific header data */
-+ set->type->list_header(set, data + *used);
-+ *used += set_save->header_size;
-+
-+ DP("set header filled: %s, used: %u(%u) %p %p", set->name, *used,
-+ set_save->header_size, data, data + *used);
-+ /* Get and ensure set specific members size */
-+ set_save->members_size = set->type->list_members_size(set);
-+ if (*used + set_save->members_size > len)
-+ goto unlock_set;
-+
-+ /* Fill in set spefific members data */
-+ set->type->list_members(set, data + *used);
-+ *used += set_save->members_size;
-+ read_unlock_bh(&set->lock);
-+ DP("set members filled: %s, used: %u(%u) %p %p", set->name, *used,
-+ set_save->members_size, data, data + *used);
-+ return 0;
-+
-+ unlock_set:
-+ read_unlock_bh(&set->lock);
-+ not_enough_mem:
-+ DP("not enough mem, try again");
-+ return -EAGAIN;
-+}
-+
-+static inline void
-+__set_hash_save_bindings(struct ip_set_hash *set_hash,
-+ ip_set_id_t id,
-+ void *data,
-+ int *used,
-+ int len,
-+ int *res)
-+{
-+ if (*res == 0
-+ && (id == IP_SET_INVALID_ID || set_hash->id == id)) {
-+ struct ip_set_hash_save *hash_save =
-+ (struct ip_set_hash_save *)(data + *used);
-+ /* Ensure bindings size */
-+ if (*used + sizeof(struct ip_set_hash_save) > len) {
-+ *res = -ENOMEM;
-+ return;
-+ }
-+ hash_save->id = set_hash->id;
-+ hash_save->ip = set_hash->ip;
-+ hash_save->binding = set_hash->binding;
-+ *used += sizeof(struct ip_set_hash_save);
-+ }
-+}
-+
-+static int ip_set_save_bindings(ip_set_id_t index,
-+ void *data,
-+ int *used,
-+ int len)
-+{
-+ int res = 0;
-+ struct ip_set_save *set_save;
-+
-+ DP("used %u, len %u", *used, len);
-+ /* Get and ensure header size */
-+ if (*used + sizeof(struct ip_set_save) > len)
-+ return -ENOMEM;
-+
-+ /* Marker */
-+ set_save = (struct ip_set_save *) (data + *used);
-+ set_save->index = IP_SET_INVALID_ID;
-+ set_save->header_size = 0;
-+ set_save->members_size = 0;
-+ *used += sizeof(struct ip_set_save);
-+
-+ DP("marker added used %u, len %u", *used, len);
-+ /* Fill in bindings data */
-+ if (index != IP_SET_INVALID_ID)
-+ /* Sets are identified by id in hash */
-+ index = ip_set_list[index]->id;
-+ FOREACH_HASH_DO(__set_hash_save_bindings, index, data, used, len, &res);
-+
-+ return res;
-+}
-+
-+/*
-+ * Restore sets
-+ */
-+static int ip_set_restore(void *data,
-+ int len)
-+{
-+ int res = 0;
-+ int line = 0, used = 0, members_size;
-+ struct ip_set *set;
-+ struct ip_set_hash_save *hash_save;
-+ struct ip_set_restore *set_restore;
-+ ip_set_id_t index;
-+
-+ /* Loop to restore sets */
-+ while (1) {
-+ line++;
-+
-+ DP("%u %u %u", used, sizeof(struct ip_set_restore), len);
-+ /* Get and ensure header size */
-+ if (used + sizeof(struct ip_set_restore) > len)
-+ return line;
-+ set_restore = (struct ip_set_restore *) (data + used);
-+ used += sizeof(struct ip_set_restore);
-+
-+ /* Ensure data size */
-+ if (used
-+ + set_restore->header_size
-+ + set_restore->members_size > len)
-+ return line;
-+
-+ /* Check marker */
-+ if (set_restore->index == IP_SET_INVALID_ID) {
-+ line--;
-+ goto bindings;
-+ }
-+
-+ /* Try to create the set */
-+ DP("restore %s %s", set_restore->name, set_restore->typename);
-+ res = ip_set_create(set_restore->name,
-+ set_restore->typename,
-+ set_restore->index,
-+ data + used,
-+ set_restore->header_size);
-+
-+ if (res != 0)
-+ return line;
-+ used += set_restore->header_size;
-+
-+ index = ip_set_find_byindex(set_restore->index);
-+ DP("index %u, restore_index %u", index, set_restore->index);
-+ if (index != set_restore->index)
-+ return line;
-+ /* Try to restore members data */
-+ set = ip_set_list[index];
-+ members_size = 0;
-+ DP("members_size %u reqsize %u",
-+ set_restore->members_size, set->type->reqsize);
-+ while (members_size + set->type->reqsize <=
-+ set_restore->members_size) {
-+ line++;
-+ DP("members: %u, line %u", members_size, line);
-+ res = __ip_set_addip(index,
-+ data + used + members_size,
-+ set->type->reqsize);
-+ if (!(res == 0 || res == -EEXIST))
-+ return line;
-+ members_size += set->type->reqsize;
-+ }
-+
-+ DP("members_size %u %u",
-+ set_restore->members_size, members_size);
-+ if (members_size != set_restore->members_size)
-+ return line++;
-+ used += set_restore->members_size;
-+ }
-+
-+ bindings:
-+ /* Loop to restore bindings */
-+ while (used < len) {
-+ line++;
-+
-+ DP("restore binding, line %u", line);
-+ /* Get and ensure size */
-+ if (used + sizeof(struct ip_set_hash_save) > len)
-+ return line;
-+ hash_save = (struct ip_set_hash_save *) (data + used);
-+ used += sizeof(struct ip_set_hash_save);
-+
-+ /* hash_save->id is used to store the index */
-+ index = ip_set_find_byindex(hash_save->id);
-+ DP("restore binding index %u, id %u, %u -> %u",
-+ index, hash_save->id, hash_save->ip, hash_save->binding);
-+ if (index != hash_save->id)
-+ return line;
-+ if (ip_set_find_byindex(hash_save->binding) == IP_SET_INVALID_ID) {
-+ DP("corrupt binding set index %u", hash_save->binding);
-+ return line;
-+ }
-+ set = ip_set_list[hash_save->id];
-+ /* Null valued IP means default binding */
-+ if (hash_save->ip)
-+ res = ip_set_hash_add(set->id,
-+ hash_save->ip,
-+ hash_save->binding);
-+ else {
-+ IP_SET_ASSERT(set->binding == IP_SET_INVALID_ID);
-+ write_lock_bh(&ip_set_lock);
-+ set->binding = hash_save->binding;
-+ __ip_set_get(set->binding);
-+ write_unlock_bh(&ip_set_lock);
-+ DP("default binding: %u", set->binding);
-+ }
-+ if (res != 0)
-+ return line;
-+ }
-+ if (used != len)
-+ return line;
-+
-+ return 0;
-+}
-+
-+static int
-+ip_set_sockfn_set(struct sock *sk, int optval, void *user, unsigned int len)
-+{
-+ void *data;
-+ int res = 0; /* Assume OK */
-+ unsigned *op;
-+ struct ip_set_req_adt *req_adt;
-+ ip_set_id_t index = IP_SET_INVALID_ID;
-+ int (*adtfn)(ip_set_id_t index,
-+ const void *data, size_t size);
-+ struct fn_table {
-+ int (*fn)(ip_set_id_t index,
-+ const void *data, size_t size);
-+ } adtfn_table[] =
-+ { { ip_set_addip }, { ip_set_delip }, { ip_set_testip},
-+ { ip_set_bindip}, { ip_set_unbindip }, { ip_set_testbind },
-+ };
-+
-+ DP("optval=%d, user=%p, len=%d", optval, user, len);
-+ if (!capable(CAP_NET_ADMIN))
-+ return -EPERM;
-+ if (optval != SO_IP_SET)
-+ return -EBADF;
-+ if (len <= sizeof(unsigned)) {
-+ ip_set_printk("short userdata (want >%zu, got %u)",
-+ sizeof(unsigned), len);
-+ return -EINVAL;
-+ }
-+ data = vmalloc(len);
-+ if (!data) {
-+ DP("out of mem for %u bytes", len);
-+ return -ENOMEM;
-+ }
-+ if (copy_from_user(data, user, len) != 0) {
-+ res = -EFAULT;
-+ goto done;
-+ }
-+ if (down_interruptible(&ip_set_app_mutex)) {
-+ res = -EINTR;
-+ goto done;
-+ }
-+
-+ op = (unsigned *)data;
-+ DP("op=%x", *op);
-+
-+ if (*op < IP_SET_OP_VERSION) {
-+ /* Check the version at the beginning of operations */
-+ struct ip_set_req_version *req_version =
-+ (struct ip_set_req_version *) data;
-+ if (req_version->version != IP_SET_PROTOCOL_VERSION) {
-+ res = -EPROTO;
-+ goto done;
-+ }
-+ }
-+
-+ switch (*op) {
-+ case IP_SET_OP_CREATE:{
-+ struct ip_set_req_create *req_create
-+ = (struct ip_set_req_create *) data;
-+
-+ if (len < sizeof(struct ip_set_req_create)) {
-+ ip_set_printk("short CREATE data (want >=%zu, got %u)",
-+ sizeof(struct ip_set_req_create), len);
-+ res = -EINVAL;
-+ goto done;
-+ }
-+ req_create->name[IP_SET_MAXNAMELEN - 1] = '\0';
-+ req_create->typename[IP_SET_MAXNAMELEN - 1] = '\0';
-+ res = ip_set_create(req_create->name,
-+ req_create->typename,
-+ IP_SET_INVALID_ID,
-+ data + sizeof(struct ip_set_req_create),
-+ len - sizeof(struct ip_set_req_create));
-+ goto done;
-+ }
-+ case IP_SET_OP_DESTROY:{
-+ struct ip_set_req_std *req_destroy
-+ = (struct ip_set_req_std *) data;
-+
-+ if (len != sizeof(struct ip_set_req_std)) {
-+ ip_set_printk("invalid DESTROY data (want %zu, got %u)",
-+ sizeof(struct ip_set_req_std), len);
-+ res = -EINVAL;
-+ goto done;
-+ }
-+ if (strcmp(req_destroy->name, IPSET_TOKEN_ALL) == 0) {
-+ /* Destroy all sets */
-+ index = IP_SET_INVALID_ID;
-+ } else {
-+ req_destroy->name[IP_SET_MAXNAMELEN - 1] = '\0';
-+ index = ip_set_find_byname(req_destroy->name);
-+
-+ if (index == IP_SET_INVALID_ID) {
-+ res = -ENOENT;
-+ goto done;
-+ }
-+ }
-+
-+ res = ip_set_destroy(index);
-+ goto done;
-+ }
-+ case IP_SET_OP_FLUSH:{
-+ struct ip_set_req_std *req_flush =
-+ (struct ip_set_req_std *) data;
-+
-+ if (len != sizeof(struct ip_set_req_std)) {
-+ ip_set_printk("invalid FLUSH data (want %zu, got %u)",
-+ sizeof(struct ip_set_req_std), len);
-+ res = -EINVAL;
-+ goto done;
-+ }
-+ if (strcmp(req_flush->name, IPSET_TOKEN_ALL) == 0) {
-+ /* Flush all sets */
-+ index = IP_SET_INVALID_ID;
-+ } else {
-+ req_flush->name[IP_SET_MAXNAMELEN - 1] = '\0';
-+ index = ip_set_find_byname(req_flush->name);
-+
-+ if (index == IP_SET_INVALID_ID) {
-+ res = -ENOENT;
-+ goto done;
-+ }
-+ }
-+ res = ip_set_flush(index);
-+ goto done;
-+ }
-+ case IP_SET_OP_RENAME:{
-+ struct ip_set_req_create *req_rename
-+ = (struct ip_set_req_create *) data;
-+
-+ if (len != sizeof(struct ip_set_req_create)) {
-+ ip_set_printk("invalid RENAME data (want %zu, got %u)",
-+ sizeof(struct ip_set_req_create), len);
-+ res = -EINVAL;
-+ goto done;
-+ }
-+
-+ req_rename->name[IP_SET_MAXNAMELEN - 1] = '\0';
-+ req_rename->typename[IP_SET_MAXNAMELEN - 1] = '\0';
-+
-+ index = ip_set_find_byname(req_rename->name);
-+ if (index == IP_SET_INVALID_ID) {
-+ res = -ENOENT;
-+ goto done;
-+ }
-+ res = ip_set_rename(index, req_rename->typename);
-+ goto done;
-+ }
-+ case IP_SET_OP_SWAP:{
-+ struct ip_set_req_create *req_swap
-+ = (struct ip_set_req_create *) data;
-+ ip_set_id_t to_index;
-+
-+ if (len != sizeof(struct ip_set_req_create)) {
-+ ip_set_printk("invalid SWAP data (want %zu, got %u)",
-+ sizeof(struct ip_set_req_create), len);
-+ res = -EINVAL;
-+ goto done;
-+ }
-+
-+ req_swap->name[IP_SET_MAXNAMELEN - 1] = '\0';
-+ req_swap->typename[IP_SET_MAXNAMELEN - 1] = '\0';
-+
-+ index = ip_set_find_byname(req_swap->name);
-+ if (index == IP_SET_INVALID_ID) {
-+ res = -ENOENT;
-+ goto done;
-+ }
-+ to_index = ip_set_find_byname(req_swap->typename);
-+ if (to_index == IP_SET_INVALID_ID) {
-+ res = -ENOENT;
-+ goto done;
-+ }
-+ res = ip_set_swap(index, to_index);
-+ goto done;
-+ }
-+ default:
-+ break; /* Set identified by id */
-+ }
-+
-+ /* There we may have add/del/test/bind/unbind/test_bind operations */
-+ if (*op < IP_SET_OP_ADD_IP || *op > IP_SET_OP_TEST_BIND_SET) {
-+ res = -EBADMSG;
-+ goto done;
-+ }
-+ adtfn = adtfn_table[*op - IP_SET_OP_ADD_IP].fn;
-+
-+ if (len < sizeof(struct ip_set_req_adt)) {
-+ ip_set_printk("short data in adt request (want >=%zu, got %u)",
-+ sizeof(struct ip_set_req_adt), len);
-+ res = -EINVAL;
-+ goto done;
-+ }
-+ req_adt = (struct ip_set_req_adt *) data;
-+
-+ /* -U :all: :all:|:default: uses IP_SET_INVALID_ID */
-+ if (!(*op == IP_SET_OP_UNBIND_SET
-+ && req_adt->index == IP_SET_INVALID_ID)) {
-+ index = ip_set_find_byindex(req_adt->index);
-+ if (index == IP_SET_INVALID_ID) {
-+ res = -ENOENT;
-+ goto done;
-+ }
-+ }
-+ res = adtfn(index, data, len);
-+
-+ done:
-+ up(&ip_set_app_mutex);
-+ vfree(data);
-+ if (res > 0)
-+ res = 0;
-+ DP("final result %d", res);
-+ return res;
-+}
-+
-+static int
-+ip_set_sockfn_get(struct sock *sk, int optval, void *user, int *len)
-+{
-+ int res = 0;
-+ unsigned *op;
-+ ip_set_id_t index = IP_SET_INVALID_ID;
-+ void *data;
-+ int copylen = *len;
-+
-+ DP("optval=%d, user=%p, len=%d", optval, user, *len);
-+ if (!capable(CAP_NET_ADMIN))
-+ return -EPERM;
-+ if (optval != SO_IP_SET)
-+ return -EBADF;
-+ if (*len < sizeof(unsigned)) {
-+ ip_set_printk("short userdata (want >=%zu, got %d)",
-+ sizeof(unsigned), *len);
-+ return -EINVAL;
-+ }
-+ data = vmalloc(*len);
-+ if (!data) {
-+ DP("out of mem for %d bytes", *len);
-+ return -ENOMEM;
-+ }
-+ if (copy_from_user(data, user, *len) != 0) {
-+ res = -EFAULT;
-+ goto done;
-+ }
-+ if (down_interruptible(&ip_set_app_mutex)) {
-+ res = -EINTR;
-+ goto done;
-+ }
-+
-+ op = (unsigned *) data;
-+ DP("op=%x", *op);
-+
-+ if (*op < IP_SET_OP_VERSION) {
-+ /* Check the version at the beginning of operations */
-+ struct ip_set_req_version *req_version =
-+ (struct ip_set_req_version *) data;
-+ if (req_version->version != IP_SET_PROTOCOL_VERSION) {
-+ res = -EPROTO;
-+ goto done;
-+ }
-+ }
-+
-+ switch (*op) {
-+ case IP_SET_OP_VERSION: {
-+ struct ip_set_req_version *req_version =
-+ (struct ip_set_req_version *) data;
-+
-+ if (*len != sizeof(struct ip_set_req_version)) {
-+ ip_set_printk("invalid VERSION (want %zu, got %d)",
-+ sizeof(struct ip_set_req_version),
-+ *len);
-+ res = -EINVAL;
-+ goto done;
-+ }
-+
-+ req_version->version = IP_SET_PROTOCOL_VERSION;
-+ res = copy_to_user(user, req_version,
-+ sizeof(struct ip_set_req_version));
-+ goto done;
-+ }
-+ case IP_SET_OP_GET_BYNAME: {
-+ struct ip_set_req_get_set *req_get
-+ = (struct ip_set_req_get_set *) data;
-+
-+ if (*len != sizeof(struct ip_set_req_get_set)) {
-+ ip_set_printk("invalid GET_BYNAME (want %zu, got %d)",
-+ sizeof(struct ip_set_req_get_set), *len);
-+ res = -EINVAL;
-+ goto done;
-+ }
-+ req_get->set.name[IP_SET_MAXNAMELEN - 1] = '\0';
-+ index = ip_set_find_byname(req_get->set.name);
-+ req_get->set.index = index;
-+ goto copy;
-+ }
-+ case IP_SET_OP_GET_BYINDEX: {
-+ struct ip_set_req_get_set *req_get
-+ = (struct ip_set_req_get_set *) data;
-+
-+ if (*len != sizeof(struct ip_set_req_get_set)) {
-+ ip_set_printk("invalid GET_BYINDEX (want %zu, got %d)",
-+ sizeof(struct ip_set_req_get_set), *len);
-+ res = -EINVAL;
-+ goto done;
-+ }
-+ req_get->set.name[IP_SET_MAXNAMELEN - 1] = '\0';
-+ index = ip_set_find_byindex(req_get->set.index);
-+ strncpy(req_get->set.name,
-+ index == IP_SET_INVALID_ID ? ""
-+ : ip_set_list[index]->name, IP_SET_MAXNAMELEN);
-+ goto copy;
-+ }
-+ case IP_SET_OP_ADT_GET: {
-+ struct ip_set_req_adt_get *req_get
-+ = (struct ip_set_req_adt_get *) data;
-+
-+ if (*len != sizeof(struct ip_set_req_adt_get)) {
-+ ip_set_printk("invalid ADT_GET (want %zu, got %d)",
-+ sizeof(struct ip_set_req_adt_get), *len);
-+ res = -EINVAL;
-+ goto done;
-+ }
-+ req_get->set.name[IP_SET_MAXNAMELEN - 1] = '\0';
-+ index = ip_set_find_byname(req_get->set.name);
-+ if (index != IP_SET_INVALID_ID) {
-+ req_get->set.index = index;
-+ strncpy(req_get->typename,
-+ ip_set_list[index]->type->typename,
-+ IP_SET_MAXNAMELEN - 1);
-+ } else {
-+ res = -ENOENT;
-+ goto done;
-+ }
-+ goto copy;
-+ }
-+ case IP_SET_OP_MAX_SETS: {
-+ struct ip_set_req_max_sets *req_max_sets
-+ = (struct ip_set_req_max_sets *) data;
-+ ip_set_id_t i;
-+
-+ if (*len != sizeof(struct ip_set_req_max_sets)) {
-+ ip_set_printk("invalid MAX_SETS (want %zu, got %d)",
-+ sizeof(struct ip_set_req_max_sets), *len);
-+ res = -EINVAL;
-+ goto done;
-+ }
-+
-+ if (strcmp(req_max_sets->set.name, IPSET_TOKEN_ALL) == 0) {
-+ req_max_sets->set.index = IP_SET_INVALID_ID;
-+ } else {
-+ req_max_sets->set.name[IP_SET_MAXNAMELEN - 1] = '\0';
-+ req_max_sets->set.index =
-+ ip_set_find_byname(req_max_sets->set.name);
-+ if (req_max_sets->set.index == IP_SET_INVALID_ID) {
-+ res = -ENOENT;
-+ goto done;
-+ }
-+ }
-+ req_max_sets->max_sets = ip_set_max;
-+ req_max_sets->sets = 0;
-+ for (i = 0; i < ip_set_max; i++) {
-+ if (ip_set_list[i] != NULL)
-+ req_max_sets->sets++;
-+ }
-+ goto copy;
-+ }
-+ case IP_SET_OP_LIST_SIZE:
-+ case IP_SET_OP_SAVE_SIZE: {
-+ struct ip_set_req_setnames *req_setnames
-+ = (struct ip_set_req_setnames *) data;
-+ struct ip_set_name_list *name_list;
-+ struct ip_set *set;
-+ ip_set_id_t i;
-+ int used;
-+
-+ if (*len < sizeof(struct ip_set_req_setnames)) {
-+ ip_set_printk("short LIST_SIZE (want >=%zu, got %d)",
-+ sizeof(struct ip_set_req_setnames), *len);
-+ res = -EINVAL;
-+ goto done;
-+ }
-+
-+ req_setnames->size = 0;
-+ used = sizeof(struct ip_set_req_setnames);
-+ for (i = 0; i < ip_set_max; i++) {
-+ if (ip_set_list[i] == NULL)
-+ continue;
-+ name_list = (struct ip_set_name_list *)
-+ (data + used);
-+ used += sizeof(struct ip_set_name_list);
-+ if (used > copylen) {
-+ res = -EAGAIN;
-+ goto done;
-+ }
-+ set = ip_set_list[i];
-+ /* Fill in index, name, etc. */
-+ name_list->index = i;
-+ name_list->id = set->id;
-+ strncpy(name_list->name,
-+ set->name,
-+ IP_SET_MAXNAMELEN - 1);
-+ strncpy(name_list->typename,
-+ set->type->typename,
-+ IP_SET_MAXNAMELEN - 1);
-+ DP("filled %s of type %s, index %u\n",
-+ name_list->name, name_list->typename,
-+ name_list->index);
-+ if (!(req_setnames->index == IP_SET_INVALID_ID
-+ || req_setnames->index == i))
-+ continue;
-+ /* Update size */
-+ switch (*op) {
-+ case IP_SET_OP_LIST_SIZE: {
-+ req_setnames->size += sizeof(struct ip_set_list)
-+ + set->type->header_size
-+ + set->type->list_members_size(set);
-+ /* Sets are identified by id in the hash */
-+ FOREACH_HASH_DO(__set_hash_bindings_size_list,
-+ set->id, &req_setnames->size);
-+ break;
-+ }
-+ case IP_SET_OP_SAVE_SIZE: {
-+ req_setnames->size += sizeof(struct ip_set_save)
-+ + set->type->header_size
-+ + set->type->list_members_size(set);
-+ FOREACH_HASH_DO(__set_hash_bindings_size_save,
-+ set->id, &req_setnames->size);
-+ break;
-+ }
-+ default:
-+ break;
-+ }
-+ }
-+ if (copylen != used) {
-+ res = -EAGAIN;
-+ goto done;
-+ }
-+ goto copy;
-+ }
-+ case IP_SET_OP_LIST: {
-+ struct ip_set_req_list *req_list
-+ = (struct ip_set_req_list *) data;
-+ ip_set_id_t i;
-+ int used;
-+
-+ if (*len < sizeof(struct ip_set_req_list)) {
-+ ip_set_printk("short LIST (want >=%zu, got %d)",
-+ sizeof(struct ip_set_req_list), *len);
-+ res = -EINVAL;
-+ goto done;
-+ }
-+ index = req_list->index;
-+ if (index != IP_SET_INVALID_ID
-+ && ip_set_find_byindex(index) != index) {
-+ res = -ENOENT;
-+ goto done;
-+ }
-+ used = 0;
-+ if (index == IP_SET_INVALID_ID) {
-+ /* List all sets */
-+ for (i = 0; i < ip_set_max && res == 0; i++) {
-+ if (ip_set_list[i] != NULL)
-+ res = ip_set_list_set(i, data, &used, *len);
-+ }
-+ } else {
-+ /* List an individual set */
-+ res = ip_set_list_set(index, data, &used, *len);
-+ }
-+ if (res != 0)
-+ goto done;
-+ else if (copylen != used) {
-+ res = -EAGAIN;
-+ goto done;
-+ }
-+ goto copy;
-+ }
-+ case IP_SET_OP_SAVE: {
-+ struct ip_set_req_list *req_save
-+ = (struct ip_set_req_list *) data;
-+ ip_set_id_t i;
-+ int used;
-+
-+ if (*len < sizeof(struct ip_set_req_list)) {
-+ ip_set_printk("short SAVE (want >=%zu, got %d)",
-+ sizeof(struct ip_set_req_list), *len);
-+ res = -EINVAL;
-+ goto done;
-+ }
-+ index = req_save->index;
-+ if (index != IP_SET_INVALID_ID
-+ && ip_set_find_byindex(index) != index) {
-+ res = -ENOENT;
-+ goto done;
-+ }
-+ used = 0;
-+ if (index == IP_SET_INVALID_ID) {
-+ /* Save all sets */
-+ for (i = 0; i < ip_set_max && res == 0; i++) {
-+ if (ip_set_list[i] != NULL)
-+ res = ip_set_save_set(i, data, &used, *len);
-+ }
-+ } else {
-+ /* Save an individual set */
-+ res = ip_set_save_set(index, data, &used, *len);
-+ }
-+ if (res == 0)
-+ res = ip_set_save_bindings(index, data, &used, *len);
-+
-+ if (res != 0)
-+ goto done;
-+ else if (copylen != used) {
-+ res = -EAGAIN;
-+ goto done;
-+ }
-+ goto copy;
-+ }
-+ case IP_SET_OP_RESTORE: {
-+ struct ip_set_req_setnames *req_restore
-+ = (struct ip_set_req_setnames *) data;
-+ int line;
-+
-+ if (*len < sizeof(struct ip_set_req_setnames)
-+ || *len != req_restore->size) {
-+ ip_set_printk("invalid RESTORE (want =%zu, got %d)",
-+ req_restore->size, *len);
-+ res = -EINVAL;
-+ goto done;
-+ }
-+ line = ip_set_restore(data + sizeof(struct ip_set_req_setnames),
-+ req_restore->size - sizeof(struct ip_set_req_setnames));
-+ DP("ip_set_restore: %u", line);
-+ if (line != 0) {
-+ res = -EAGAIN;
-+ req_restore->size = line;
-+ copylen = sizeof(struct ip_set_req_setnames);
-+ goto copy;
-+ }
-+ goto done;
-+ }
-+ default:
-+ res = -EBADMSG;
-+ goto done;
-+ } /* end of switch(op) */
-+
-+ copy:
-+ DP("set %s, copylen %u", index != IP_SET_INVALID_ID
-+ && ip_set_list[index]
-+ ? ip_set_list[index]->name
-+ : ":all:", copylen);
-+ res = copy_to_user(user, data, copylen);
-+
-+ done:
-+ up(&ip_set_app_mutex);
-+ vfree(data);
-+ if (res > 0)
-+ res = 0;
-+ DP("final result %d", res);
-+ return res;
-+}
-+
-+static struct nf_sockopt_ops so_set = {
-+ .pf = PF_INET,
-+ .set_optmin = SO_IP_SET,
-+ .set_optmax = SO_IP_SET + 1,
-+ .set = &ip_set_sockfn_set,
-+ .get_optmin = SO_IP_SET,
-+ .get_optmax = SO_IP_SET + 1,
-+ .get = &ip_set_sockfn_get,
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,23)
-+ .owner = THIS_MODULE,
-+#endif
-+};
-+
-+static int max_sets, hash_size;
-+module_param(max_sets, int, 0600);
-+MODULE_PARM_DESC(max_sets, "maximal number of sets");
-+module_param(hash_size, int, 0600);
-+MODULE_PARM_DESC(hash_size, "hash size for bindings");
-+MODULE_LICENSE("GPL");
-+MODULE_AUTHOR("Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>");
-+MODULE_DESCRIPTION("module implementing core IP set support");
-+
-+static int __init ip_set_init(void)
-+{
-+ int res;
-+ ip_set_id_t i;
-+
-+ get_random_bytes(&ip_set_hash_random, 4);
-+ if (max_sets)
-+ ip_set_max = max_sets;
-+ ip_set_list = vmalloc(sizeof(struct ip_set *) * ip_set_max);
-+ if (!ip_set_list) {
-+ printk(KERN_ERR "Unable to create ip_set_list\n");
-+ return -ENOMEM;
-+ }
-+ memset(ip_set_list, 0, sizeof(struct ip_set *) * ip_set_max);
-+ if (hash_size)
-+ ip_set_bindings_hash_size = hash_size;
-+ ip_set_hash = vmalloc(sizeof(struct list_head) * ip_set_bindings_hash_size);
-+ if (!ip_set_hash) {
-+ printk(KERN_ERR "Unable to create ip_set_hash\n");
-+ vfree(ip_set_list);
-+ return -ENOMEM;
-+ }
-+ for (i = 0; i < ip_set_bindings_hash_size; i++)
-+ INIT_LIST_HEAD(&ip_set_hash[i]);
-+
-+ INIT_LIST_HEAD(&set_type_list);
-+
-+ res = nf_register_sockopt(&so_set);
-+ if (res != 0) {
-+ ip_set_printk("SO_SET registry failed: %d", res);
-+ vfree(ip_set_list);
-+ vfree(ip_set_hash);
-+ return res;
-+ }
-+ return 0;
-+}
-+
-+static void __exit ip_set_fini(void)
-+{
-+ /* There can't be any existing set or binding */
-+ nf_unregister_sockopt(&so_set);
-+ vfree(ip_set_list);
-+ vfree(ip_set_hash);
-+ DP("these are the famous last words");
-+}
-+
-+EXPORT_SYMBOL(ip_set_register_set_type);
-+EXPORT_SYMBOL(ip_set_unregister_set_type);
-+
-+EXPORT_SYMBOL(ip_set_get_byname);
-+EXPORT_SYMBOL(ip_set_get_byindex);
-+EXPORT_SYMBOL(ip_set_put);
-+
-+EXPORT_SYMBOL(ip_set_addip_kernel);
-+EXPORT_SYMBOL(ip_set_delip_kernel);
-+EXPORT_SYMBOL(ip_set_testip_kernel);
-+
-+module_init(ip_set_init);
-+module_exit(ip_set_fini);
---- /dev/null
-+++ b/net/ipv4/netfilter/ip_set_iphash.c
-@@ -0,0 +1,429 @@
-+/* Copyright (C) 2003-2004 Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
-+ *
-+ * This program is free software; you can redistribute it and/or modify
-+ * it under the terms of the GNU General Public License version 2 as
-+ * published by the Free Software Foundation.
-+ */
-+
-+/* Kernel module implementing an ip hash set */
-+
-+#include <linux/module.h>
-+#include <linux/ip.h>
-+#include <linux/skbuff.h>
-+#include <linux/version.h>
-+#include <linux/jhash.h>
-+#include <linux/netfilter_ipv4/ip_tables.h>
-+#include <linux/netfilter_ipv4/ip_set.h>
-+#include <linux/errno.h>
-+#include <asm/uaccess.h>
-+#include <asm/bitops.h>
-+#include <linux/spinlock.h>
-+#include <linux/vmalloc.h>
-+#include <linux/random.h>
-+
-+#include <net/ip.h>
-+
-+#include <linux/netfilter_ipv4/ip_set_malloc.h>
-+#include <linux/netfilter_ipv4/ip_set_iphash.h>
-+
-+static int limit = MAX_RANGE;
-+
-+static inline __u32
-+jhash_ip(const struct ip_set_iphash *map, uint16_t i, ip_set_ip_t ip)
-+{
-+ return jhash_1word(ip, *(((uint32_t *) map->initval) + i));
-+}
-+
-+static inline __u32
-+hash_id(struct ip_set *set, ip_set_ip_t ip, ip_set_ip_t *hash_ip)
-+{
-+ struct ip_set_iphash *map = (struct ip_set_iphash *) set->data;
-+ __u32 id;
-+ u_int16_t i;
-+ ip_set_ip_t *elem;
-+
-+ *hash_ip = ip & map->netmask;
-+ DP("set: %s, ip:%u.%u.%u.%u, %u.%u.%u.%u, %u.%u.%u.%u",
-+ set->name, HIPQUAD(ip), HIPQUAD(*hash_ip), HIPQUAD(map->netmask));
-+
-+ for (i = 0; i < map->probes; i++) {
-+ id = jhash_ip(map, i, *hash_ip) % map->hashsize;
-+ DP("hash key: %u", id);
-+ elem = HARRAY_ELEM(map->members, ip_set_ip_t *, id);
-+ if (*elem == *hash_ip)
-+ return id;
-+ /* No shortcut at testing - there can be deleted
-+ * entries. */
-+ }
-+ return UINT_MAX;
-+}
-+
-+static inline int
-+__testip(struct ip_set *set, ip_set_ip_t ip, ip_set_ip_t *hash_ip)
-+{
-+ return (ip && hash_id(set, ip, hash_ip) != UINT_MAX);
-+}
-+
-+static int
-+testip(struct ip_set *set, const void *data, size_t size,
-+ ip_set_ip_t *hash_ip)
-+{
-+ struct ip_set_req_iphash *req =
-+ (struct ip_set_req_iphash *) data;
-+
-+ if (size != sizeof(struct ip_set_req_iphash)) {
-+ ip_set_printk("data length wrong (want %zu, have %zu)",
-+ sizeof(struct ip_set_req_iphash),
-+ size);
-+ return -EINVAL;
-+ }
-+ return __testip(set, req->ip, hash_ip);
-+}
-+
-+static int
-+testip_kernel(struct ip_set *set,
-+ const struct sk_buff *skb,
-+ ip_set_ip_t *hash_ip,
-+ const u_int32_t *flags,
-+ unsigned char index)
-+{
-+ return __testip(set,
-+ ntohl(flags[index] & IPSET_SRC
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-+ ? ip_hdr(skb)->saddr
-+ : ip_hdr(skb)->daddr),
-+#else
-+ ? skb->nh.iph->saddr
-+ : skb->nh.iph->daddr),
-+#endif
-+ hash_ip);
-+}
-+
-+static inline int
-+__addip(struct ip_set_iphash *map, ip_set_ip_t ip, ip_set_ip_t *hash_ip)
-+{
-+ __u32 probe;
-+ u_int16_t i;
-+ ip_set_ip_t *elem;
-+
-+ if (!ip || map->elements >= limit)
-+ return -ERANGE;
-+
-+ *hash_ip = ip & map->netmask;
-+
-+ for (i = 0; i < map->probes; i++) {
-+ probe = jhash_ip(map, i, *hash_ip) % map->hashsize;
-+ elem = HARRAY_ELEM(map->members, ip_set_ip_t *, probe);
-+ if (*elem == *hash_ip)
-+ return -EEXIST;
-+ if (!*elem) {
-+ *elem = *hash_ip;
-+ map->elements++;
-+ return 0;
-+ }
-+ }
-+ /* Trigger rehashing */
-+ return -EAGAIN;
-+}
-+
-+static int
-+addip(struct ip_set *set, const void *data, size_t size,
-+ ip_set_ip_t *hash_ip)
-+{
-+ struct ip_set_req_iphash *req =
-+ (struct ip_set_req_iphash *) data;
-+
-+ if (size != sizeof(struct ip_set_req_iphash)) {
-+ ip_set_printk("data length wrong (want %zu, have %zu)",
-+ sizeof(struct ip_set_req_iphash),
-+ size);
-+ return -EINVAL;
-+ }
-+ return __addip((struct ip_set_iphash *) set->data, req->ip, hash_ip);
-+}
-+
-+static int
-+addip_kernel(struct ip_set *set,
-+ const struct sk_buff *skb,
-+ ip_set_ip_t *hash_ip,
-+ const u_int32_t *flags,
-+ unsigned char index)
-+{
-+ return __addip((struct ip_set_iphash *) set->data,
-+ ntohl(flags[index] & IPSET_SRC
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-+ ? ip_hdr(skb)->saddr
-+ : ip_hdr(skb)->daddr),
-+#else
-+ ? skb->nh.iph->saddr
-+ : skb->nh.iph->daddr),
-+#endif
-+ hash_ip);
-+}
-+
-+static int retry(struct ip_set *set)
-+{
-+ struct ip_set_iphash *map = (struct ip_set_iphash *) set->data;
-+ ip_set_ip_t hash_ip, *elem;
-+ void *members;
-+ u_int32_t i, hashsize = map->hashsize;
-+ int res;
-+ struct ip_set_iphash *tmp;
-+
-+ if (map->resize == 0)
-+ return -ERANGE;
-+
-+ again:
-+ res = 0;
-+
-+ /* Calculate new hash size */
-+ hashsize += (hashsize * map->resize)/100;
-+ if (hashsize == map->hashsize)
-+ hashsize++;
-+
-+ ip_set_printk("rehashing of set %s triggered: "
-+ "hashsize grows from %u to %u",
-+ set->name, map->hashsize, hashsize);
-+
-+ tmp = kmalloc(sizeof(struct ip_set_iphash)
-+ + map->probes * sizeof(uint32_t), GFP_ATOMIC);
-+ if (!tmp) {
-+ DP("out of memory for %d bytes",
-+ sizeof(struct ip_set_iphash)
-+ + map->probes * sizeof(uint32_t));
-+ return -ENOMEM;
-+ }
-+ tmp->members = harray_malloc(hashsize, sizeof(ip_set_ip_t), GFP_ATOMIC);
-+ if (!tmp->members) {
-+ DP("out of memory for %d bytes", hashsize * sizeof(ip_set_ip_t));
-+ kfree(tmp);
-+ return -ENOMEM;
-+ }
-+ tmp->hashsize = hashsize;
-+ tmp->elements = 0;
-+ tmp->probes = map->probes;
-+ tmp->resize = map->resize;
-+ tmp->netmask = map->netmask;
-+ memcpy(tmp->initval, map->initval, map->probes * sizeof(uint32_t));
-+
-+ write_lock_bh(&set->lock);
-+ map = (struct ip_set_iphash *) set->data; /* Play safe */
-+ for (i = 0; i < map->hashsize && res == 0; i++) {
-+ elem = HARRAY_ELEM(map->members, ip_set_ip_t *, i);
-+ if (*elem)
-+ res = __addip(tmp, *elem, &hash_ip);
-+ }
-+ if (res) {
-+ /* Failure, try again */
-+ write_unlock_bh(&set->lock);
-+ harray_free(tmp->members);
-+ kfree(tmp);
-+ goto again;
-+ }
-+
-+ /* Success at resizing! */
-+ members = map->members;
-+
-+ map->hashsize = tmp->hashsize;
-+ map->members = tmp->members;
-+ write_unlock_bh(&set->lock);
-+
-+ harray_free(members);
-+ kfree(tmp);
-+
-+ return 0;
-+}
-+
-+static inline int
-+__delip(struct ip_set *set, ip_set_ip_t ip, ip_set_ip_t *hash_ip)
-+{
-+ struct ip_set_iphash *map = (struct ip_set_iphash *) set->data;
-+ ip_set_ip_t id, *elem;
-+
-+ if (!ip)
-+ return -ERANGE;
-+
-+ id = hash_id(set, ip, hash_ip);
-+ if (id == UINT_MAX)
-+ return -EEXIST;
-+
-+ elem = HARRAY_ELEM(map->members, ip_set_ip_t *, id);
-+ *elem = 0;
-+ map->elements--;
-+
-+ return 0;
-+}
-+
-+static int
-+delip(struct ip_set *set, const void *data, size_t size,
-+ ip_set_ip_t *hash_ip)
-+{
-+ struct ip_set_req_iphash *req =
-+ (struct ip_set_req_iphash *) data;
-+
-+ if (size != sizeof(struct ip_set_req_iphash)) {
-+ ip_set_printk("data length wrong (want %zu, have %zu)",
-+ sizeof(struct ip_set_req_iphash),
-+ size);
-+ return -EINVAL;
-+ }
-+ return __delip(set, req->ip, hash_ip);
-+}
-+
-+static int
-+delip_kernel(struct ip_set *set,
-+ const struct sk_buff *skb,
-+ ip_set_ip_t *hash_ip,
-+ const u_int32_t *flags,
-+ unsigned char index)
-+{
-+ return __delip(set,
-+ ntohl(flags[index] & IPSET_SRC
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-+ ? ip_hdr(skb)->saddr
-+ : ip_hdr(skb)->daddr),
-+#else
-+ ? skb->nh.iph->saddr
-+ : skb->nh.iph->daddr),
-+#endif
-+ hash_ip);
-+}
-+
-+static int create(struct ip_set *set, const void *data, size_t size)
-+{
-+ struct ip_set_req_iphash_create *req =
-+ (struct ip_set_req_iphash_create *) data;
-+ struct ip_set_iphash *map;
-+ uint16_t i;
-+
-+ if (size != sizeof(struct ip_set_req_iphash_create)) {
-+ ip_set_printk("data length wrong (want %zu, have %zu)",
-+ sizeof(struct ip_set_req_iphash_create),
-+ size);
-+ return -EINVAL;
-+ }
-+
-+ if (req->hashsize < 1) {
-+ ip_set_printk("hashsize too small");
-+ return -ENOEXEC;
-+ }
-+
-+ if (req->probes < 1) {
-+ ip_set_printk("probes too small");
-+ return -ENOEXEC;
-+ }
-+
-+ map = kmalloc(sizeof(struct ip_set_iphash)
-+ + req->probes * sizeof(uint32_t), GFP_KERNEL);
-+ if (!map) {
-+ DP("out of memory for %d bytes",
-+ sizeof(struct ip_set_iphash)
-+ + req->probes * sizeof(uint32_t));
-+ return -ENOMEM;
-+ }
-+ for (i = 0; i < req->probes; i++)
-+ get_random_bytes(((uint32_t *) map->initval)+i, 4);
-+ map->elements = 0;
-+ map->hashsize = req->hashsize;
-+ map->probes = req->probes;
-+ map->resize = req->resize;
-+ map->netmask = req->netmask;
-+ map->members = harray_malloc(map->hashsize, sizeof(ip_set_ip_t), GFP_KERNEL);
-+ if (!map->members) {
-+ DP("out of memory for %d bytes", map->hashsize * sizeof(ip_set_ip_t));
-+ kfree(map);
-+ return -ENOMEM;
-+ }
-+
-+ set->data = map;
-+ return 0;
-+}
-+
-+static void destroy(struct ip_set *set)
-+{
-+ struct ip_set_iphash *map = (struct ip_set_iphash *) set->data;
-+
-+ harray_free(map->members);
-+ kfree(map);
-+
-+ set->data = NULL;
-+}
-+
-+static void flush(struct ip_set *set)
-+{
-+ struct ip_set_iphash *map = (struct ip_set_iphash *) set->data;
-+ harray_flush(map->members, map->hashsize, sizeof(ip_set_ip_t));
-+ map->elements = 0;
-+}
-+
-+static void list_header(const struct ip_set *set, void *data)
-+{
-+ struct ip_set_iphash *map = (struct ip_set_iphash *) set->data;
-+ struct ip_set_req_iphash_create *header =
-+ (struct ip_set_req_iphash_create *) data;
-+
-+ header->hashsize = map->hashsize;
-+ header->probes = map->probes;
-+ header->resize = map->resize;
-+ header->netmask = map->netmask;
-+}
-+
-+static int list_members_size(const struct ip_set *set)
-+{
-+ struct ip_set_iphash *map = (struct ip_set_iphash *) set->data;
-+
-+ return (map->hashsize * sizeof(ip_set_ip_t));
-+}
-+
-+static void list_members(const struct ip_set *set, void *data)
-+{
-+ struct ip_set_iphash *map = (struct ip_set_iphash *) set->data;
-+ ip_set_ip_t i, *elem;
-+
-+ for (i = 0; i < map->hashsize; i++) {
-+ elem = HARRAY_ELEM(map->members, ip_set_ip_t *, i);
-+ ((ip_set_ip_t *)data)[i] = *elem;
-+ }
-+}
-+
-+static struct ip_set_type ip_set_iphash = {
-+ .typename = SETTYPE_NAME,
-+ .features = IPSET_TYPE_IP | IPSET_DATA_SINGLE,
-+ .protocol_version = IP_SET_PROTOCOL_VERSION,
-+ .create = &create,
-+ .destroy = &destroy,
-+ .flush = &flush,
-+ .reqsize = sizeof(struct ip_set_req_iphash),
-+ .addip = &addip,
-+ .addip_kernel = &addip_kernel,
-+ .retry = &retry,
-+ .delip = &delip,
-+ .delip_kernel = &delip_kernel,
-+ .testip = &testip,
-+ .testip_kernel = &testip_kernel,
-+ .header_size = sizeof(struct ip_set_req_iphash_create),
-+ .list_header = &list_header,
-+ .list_members_size = &list_members_size,
-+ .list_members = &list_members,
-+ .me = THIS_MODULE,
-+};
-+
-+MODULE_LICENSE("GPL");
-+MODULE_AUTHOR("Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>");
-+MODULE_DESCRIPTION("iphash type of IP sets");
-+module_param(limit, int, 0600);
-+MODULE_PARM_DESC(limit, "maximal number of elements stored in the sets");
-+
-+static int __init ip_set_iphash_init(void)
-+{
-+ return ip_set_register_set_type(&ip_set_iphash);
-+}
-+
-+static void __exit ip_set_iphash_fini(void)
-+{
-+ /* FIXME: possible race with ip_set_create() */
-+ ip_set_unregister_set_type(&ip_set_iphash);
-+}
-+
-+module_init(ip_set_iphash_init);
-+module_exit(ip_set_iphash_fini);
---- /dev/null
-+++ b/net/ipv4/netfilter/ip_set_ipmap.c
-@@ -0,0 +1,336 @@
-+/* Copyright (C) 2000-2002 Joakim Axelsson <gozem@linux.nu>
-+ * Patrick Schaaf <bof@bof.de>
-+ * Copyright (C) 2003-2004 Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
-+ *
-+ * This program is free software; you can redistribute it and/or modify
-+ * it under the terms of the GNU General Public License version 2 as
-+ * published by the Free Software Foundation.
-+ */
-+
-+/* Kernel module implementing an IP set type: the single bitmap type */
-+
-+#include <linux/module.h>
-+#include <linux/ip.h>
-+#include <linux/skbuff.h>
-+#include <linux/version.h>
-+#include <linux/netfilter_ipv4/ip_tables.h>
-+#include <linux/netfilter_ipv4/ip_set.h>
-+#include <linux/errno.h>
-+#include <asm/uaccess.h>
-+#include <asm/bitops.h>
-+#include <linux/spinlock.h>
-+
-+#include <linux/netfilter_ipv4/ip_set_ipmap.h>
-+
-+static inline ip_set_ip_t
-+ip_to_id(const struct ip_set_ipmap *map, ip_set_ip_t ip)
-+{
-+ return (ip - map->first_ip)/map->hosts;
-+}
-+
-+static inline int
-+__testip(struct ip_set *set, ip_set_ip_t ip, ip_set_ip_t *hash_ip)
-+{
-+ struct ip_set_ipmap *map = (struct ip_set_ipmap *) set->data;
-+
-+ if (ip < map->first_ip || ip > map->last_ip)
-+ return -ERANGE;
-+
-+ *hash_ip = ip & map->netmask;
-+ DP("set: %s, ip:%u.%u.%u.%u, %u.%u.%u.%u",
-+ set->name, HIPQUAD(ip), HIPQUAD(*hash_ip));
-+ return !!test_bit(ip_to_id(map, *hash_ip), map->members);
-+}
-+
-+static int
-+testip(struct ip_set *set, const void *data, size_t size,
-+ ip_set_ip_t *hash_ip)
-+{
-+ struct ip_set_req_ipmap *req =
-+ (struct ip_set_req_ipmap *) data;
-+
-+ if (size != sizeof(struct ip_set_req_ipmap)) {
-+ ip_set_printk("data length wrong (want %zu, have %zu)",
-+ sizeof(struct ip_set_req_ipmap),
-+ size);
-+ return -EINVAL;
-+ }
-+ return __testip(set, req->ip, hash_ip);
-+}
-+
-+static int
-+testip_kernel(struct ip_set *set,
-+ const struct sk_buff *skb,
-+ ip_set_ip_t *hash_ip,
-+ const u_int32_t *flags,
-+ unsigned char index)
-+{
-+ int res = __testip(set,
-+ ntohl(flags[index] & IPSET_SRC
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-+ ? ip_hdr(skb)->saddr
-+ : ip_hdr(skb)->daddr),
-+#else
-+ ? skb->nh.iph->saddr
-+ : skb->nh.iph->daddr),
-+#endif
-+ hash_ip);
-+ return (res < 0 ? 0 : res);
-+}
-+
-+static inline int
-+__addip(struct ip_set *set, ip_set_ip_t ip, ip_set_ip_t *hash_ip)
-+{
-+ struct ip_set_ipmap *map = (struct ip_set_ipmap *) set->data;
-+
-+ if (ip < map->first_ip || ip > map->last_ip)
-+ return -ERANGE;
-+
-+ *hash_ip = ip & map->netmask;
-+ DP("%u.%u.%u.%u, %u.%u.%u.%u", HIPQUAD(ip), HIPQUAD(*hash_ip));
-+ if (test_and_set_bit(ip_to_id(map, *hash_ip), map->members))
-+ return -EEXIST;
-+
-+ return 0;
-+}
-+
-+static int
-+addip(struct ip_set *set, const void *data, size_t size,
-+ ip_set_ip_t *hash_ip)
-+{
-+ struct ip_set_req_ipmap *req =
-+ (struct ip_set_req_ipmap *) data;
-+
-+ if (size != sizeof(struct ip_set_req_ipmap)) {
-+ ip_set_printk("data length wrong (want %zu, have %zu)",
-+ sizeof(struct ip_set_req_ipmap),
-+ size);
-+ return -EINVAL;
-+ }
-+ DP("%u.%u.%u.%u", HIPQUAD(req->ip));
-+ return __addip(set, req->ip, hash_ip);
-+}
-+
-+static int
-+addip_kernel(struct ip_set *set,
-+ const struct sk_buff *skb,
-+ ip_set_ip_t *hash_ip,
-+ const u_int32_t *flags,
-+ unsigned char index)
-+{
-+ return __addip(set,
-+ ntohl(flags[index] & IPSET_SRC
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-+ ? ip_hdr(skb)->saddr
-+ : ip_hdr(skb)->daddr),
-+#else
-+ ? skb->nh.iph->saddr
-+ : skb->nh.iph->daddr),
-+#endif
-+ hash_ip);
-+}
-+
-+static inline int
-+__delip(struct ip_set *set, ip_set_ip_t ip, ip_set_ip_t *hash_ip)
-+{
-+ struct ip_set_ipmap *map = (struct ip_set_ipmap *) set->data;
-+
-+ if (ip < map->first_ip || ip > map->last_ip)
-+ return -ERANGE;
-+
-+ *hash_ip = ip & map->netmask;
-+ DP("%u.%u.%u.%u, %u.%u.%u.%u", HIPQUAD(ip), HIPQUAD(*hash_ip));
-+ if (!test_and_clear_bit(ip_to_id(map, *hash_ip), map->members))
-+ return -EEXIST;
-+
-+ return 0;
-+}
-+
-+static int
-+delip(struct ip_set *set, const void *data, size_t size,
-+ ip_set_ip_t *hash_ip)
-+{
-+ struct ip_set_req_ipmap *req =
-+ (struct ip_set_req_ipmap *) data;
-+
-+ if (size != sizeof(struct ip_set_req_ipmap)) {
-+ ip_set_printk("data length wrong (want %zu, have %zu)",
-+ sizeof(struct ip_set_req_ipmap),
-+ size);
-+ return -EINVAL;
-+ }
-+ return __delip(set, req->ip, hash_ip);
-+}
-+
-+static int
-+delip_kernel(struct ip_set *set,
-+ const struct sk_buff *skb,
-+ ip_set_ip_t *hash_ip,
-+ const u_int32_t *flags,
-+ unsigned char index)
-+{
-+ return __delip(set,
-+ ntohl(flags[index] & IPSET_SRC
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-+ ? ip_hdr(skb)->saddr
-+ : ip_hdr(skb)->daddr),
-+#else
-+ ? skb->nh.iph->saddr
-+ : skb->nh.iph->daddr),
-+#endif
-+ hash_ip);
-+}
-+
-+static int create(struct ip_set *set, const void *data, size_t size)
-+{
-+ int newbytes;
-+ struct ip_set_req_ipmap_create *req =
-+ (struct ip_set_req_ipmap_create *) data;
-+ struct ip_set_ipmap *map;
-+
-+ if (size != sizeof(struct ip_set_req_ipmap_create)) {
-+ ip_set_printk("data length wrong (want %zu, have %zu)",
-+ sizeof(struct ip_set_req_ipmap_create),
-+ size);
-+ return -EINVAL;
-+ }
-+
-+ DP("from %u.%u.%u.%u to %u.%u.%u.%u",
-+ HIPQUAD(req->from), HIPQUAD(req->to));
-+
-+ if (req->from > req->to) {
-+ DP("bad ip range");
-+ return -ENOEXEC;
-+ }
-+
-+ map = kmalloc(sizeof(struct ip_set_ipmap), GFP_KERNEL);
-+ if (!map) {
-+ DP("out of memory for %d bytes",
-+ sizeof(struct ip_set_ipmap));
-+ return -ENOMEM;
-+ }
-+ map->first_ip = req->from;
-+ map->last_ip = req->to;
-+ map->netmask = req->netmask;
-+
-+ if (req->netmask == 0xFFFFFFFF) {
-+ map->hosts = 1;
-+ map->sizeid = map->last_ip - map->first_ip + 1;
-+ } else {
-+ unsigned int mask_bits, netmask_bits;
-+ ip_set_ip_t mask;
-+
-+ map->first_ip &= map->netmask; /* Should we better bark? */
-+
-+ mask = range_to_mask(map->first_ip, map->last_ip, &mask_bits);
-+ netmask_bits = mask_to_bits(map->netmask);
-+
-+ if ((!mask && (map->first_ip || map->last_ip != 0xFFFFFFFF))
-+ || netmask_bits <= mask_bits)
-+ return -ENOEXEC;
-+
-+ DP("mask_bits %u, netmask_bits %u",
-+ mask_bits, netmask_bits);
-+ map->hosts = 2 << (32 - netmask_bits - 1);
-+ map->sizeid = 2 << (netmask_bits - mask_bits - 1);
-+ }
-+ if (map->sizeid > MAX_RANGE + 1) {
-+ ip_set_printk("range too big (max %d addresses)",
-+ MAX_RANGE+1);
-+ kfree(map);
-+ return -ENOEXEC;
-+ }
-+ DP("hosts %u, sizeid %u", map->hosts, map->sizeid);
-+ newbytes = bitmap_bytes(0, map->sizeid - 1);
-+ map->members = kmalloc(newbytes, GFP_KERNEL);
-+ if (!map->members) {
-+ DP("out of memory for %d bytes", newbytes);
-+ kfree(map);
-+ return -ENOMEM;
-+ }
-+ memset(map->members, 0, newbytes);
-+
-+ set->data = map;
-+ return 0;
-+}
-+
-+static void destroy(struct ip_set *set)
-+{
-+ struct ip_set_ipmap *map = (struct ip_set_ipmap *) set->data;
-+
-+ kfree(map->members);
-+ kfree(map);
-+
-+ set->data = NULL;
-+}
-+
-+static void flush(struct ip_set *set)
-+{
-+ struct ip_set_ipmap *map = (struct ip_set_ipmap *) set->data;
-+ memset(map->members, 0, bitmap_bytes(0, map->sizeid - 1));
-+}
-+
-+static void list_header(const struct ip_set *set, void *data)
-+{
-+ struct ip_set_ipmap *map = (struct ip_set_ipmap *) set->data;
-+ struct ip_set_req_ipmap_create *header =
-+ (struct ip_set_req_ipmap_create *) data;
-+
-+ header->from = map->first_ip;
-+ header->to = map->last_ip;
-+ header->netmask = map->netmask;
-+}
-+
-+static int list_members_size(const struct ip_set *set)
-+{
-+ struct ip_set_ipmap *map = (struct ip_set_ipmap *) set->data;
-+
-+ return bitmap_bytes(0, map->sizeid - 1);
-+}
-+
-+static void list_members(const struct ip_set *set, void *data)
-+{
-+ struct ip_set_ipmap *map = (struct ip_set_ipmap *) set->data;
-+ int bytes = bitmap_bytes(0, map->sizeid - 1);
-+
-+ memcpy(data, map->members, bytes);
-+}
-+
-+static struct ip_set_type ip_set_ipmap = {
-+ .typename = SETTYPE_NAME,
-+ .features = IPSET_TYPE_IP | IPSET_DATA_SINGLE,
-+ .protocol_version = IP_SET_PROTOCOL_VERSION,
-+ .create = &create,
-+ .destroy = &destroy,
-+ .flush = &flush,
-+ .reqsize = sizeof(struct ip_set_req_ipmap),
-+ .addip = &addip,
-+ .addip_kernel = &addip_kernel,
-+ .delip = &delip,
-+ .delip_kernel = &delip_kernel,
-+ .testip = &testip,
-+ .testip_kernel = &testip_kernel,
-+ .header_size = sizeof(struct ip_set_req_ipmap_create),
-+ .list_header = &list_header,
-+ .list_members_size = &list_members_size,
-+ .list_members = &list_members,
-+ .me = THIS_MODULE,
-+};
-+
-+MODULE_LICENSE("GPL");
-+MODULE_AUTHOR("Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>");
-+MODULE_DESCRIPTION("ipmap type of IP sets");
-+
-+static int __init ip_set_ipmap_init(void)
-+{
-+ return ip_set_register_set_type(&ip_set_ipmap);
-+}
-+
-+static void __exit ip_set_ipmap_fini(void)
-+{
-+ /* FIXME: possible race with ip_set_create() */
-+ ip_set_unregister_set_type(&ip_set_ipmap);
-+}
-+
-+module_init(ip_set_ipmap_init);
-+module_exit(ip_set_ipmap_fini);
---- /dev/null
-+++ b/net/ipv4/netfilter/ip_set_ipporthash.c
-@@ -0,0 +1,581 @@
-+/* Copyright (C) 2003-2004 Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
-+ *
-+ * This program is free software; you can redistribute it and/or modify
-+ * it under the terms of the GNU General Public License version 2 as
-+ * published by the Free Software Foundation.
-+ */
-+
-+/* Kernel module implementing an ip+port hash set */
-+
-+#include <linux/module.h>
-+#include <linux/ip.h>
-+#include <linux/tcp.h>
-+#include <linux/udp.h>
-+#include <linux/skbuff.h>
-+#include <linux/version.h>
-+#include <linux/jhash.h>
-+#include <linux/netfilter_ipv4/ip_tables.h>
-+#include <linux/netfilter_ipv4/ip_set.h>
-+#include <linux/errno.h>
-+#include <asm/uaccess.h>
-+#include <asm/bitops.h>
-+#include <linux/spinlock.h>
-+#include <linux/vmalloc.h>
-+#include <linux/random.h>
-+
-+#include <net/ip.h>
-+
-+#include <linux/netfilter_ipv4/ip_set_malloc.h>
-+#include <linux/netfilter_ipv4/ip_set_ipporthash.h>
-+
-+static int limit = MAX_RANGE;
-+
-+/* We must handle non-linear skbs */
-+static inline ip_set_ip_t
-+get_port(const struct sk_buff *skb, u_int32_t flags)
-+{
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-+ struct iphdr *iph = ip_hdr(skb);
-+#else
-+ struct iphdr *iph = skb->nh.iph;
-+#endif
-+ u_int16_t offset = ntohs(iph->frag_off) & IP_OFFSET;
-+
-+ switch (iph->protocol) {
-+ case IPPROTO_TCP: {
-+ struct tcphdr tcph;
-+
-+ /* See comments at tcp_match in ip_tables.c */
-+ if (offset)
-+ return INVALID_PORT;
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-+ if (skb_copy_bits(skb, ip_hdr(skb)->ihl*4, &tcph, sizeof(tcph)) < 0)
-+#else
-+ if (skb_copy_bits(skb, skb->nh.iph->ihl*4, &tcph, sizeof(tcph)) < 0)
-+#endif
-+ /* No choice either */
-+ return INVALID_PORT;
-+
-+ return ntohs(flags & IPSET_SRC ?
-+ tcph.source : tcph.dest);
-+ }
-+ case IPPROTO_UDP: {
-+ struct udphdr udph;
-+
-+ if (offset)
-+ return INVALID_PORT;
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-+ if (skb_copy_bits(skb, ip_hdr(skb)->ihl*4, &udph, sizeof(udph)) < 0)
-+#else
-+ if (skb_copy_bits(skb, skb->nh.iph->ihl*4, &udph, sizeof(udph)) < 0)
-+#endif
-+ /* No choice either */
-+ return INVALID_PORT;
-+
-+ return ntohs(flags & IPSET_SRC ?
-+ udph.source : udph.dest);
-+ }
-+ default:
-+ return INVALID_PORT;
-+ }
-+}
-+
-+static inline __u32
-+jhash_ip(const struct ip_set_ipporthash *map, uint16_t i, ip_set_ip_t ip)
-+{
-+ return jhash_1word(ip, *(((uint32_t *) map->initval) + i));
-+}
-+
-+#define HASH_IP(map, ip, port) (port + ((ip - ((map)->first_ip)) << 16))
-+
-+static inline __u32
-+hash_id(struct ip_set *set, ip_set_ip_t ip, ip_set_ip_t port,
-+ ip_set_ip_t *hash_ip)
-+{
-+ struct ip_set_ipporthash *map =
-+ (struct ip_set_ipporthash *) set->data;
-+ __u32 id;
-+ u_int16_t i;
-+ ip_set_ip_t *elem;
-+
-+ *hash_ip = HASH_IP(map, ip, port);
-+ DP("set: %s, ipport:%u.%u.%u.%u:%u, %u.%u.%u.%u",
-+ set->name, HIPQUAD(ip), port, HIPQUAD(*hash_ip));
-+
-+ for (i = 0; i < map->probes; i++) {
-+ id = jhash_ip(map, i, *hash_ip) % map->hashsize;
-+ DP("hash key: %u", id);
-+ elem = HARRAY_ELEM(map->members, ip_set_ip_t *, id);
-+ if (*elem == *hash_ip)
-+ return id;
-+ /* No shortcut at testing - there can be deleted
-+ * entries. */
-+ }
-+ return UINT_MAX;
-+}
-+
-+static inline int
-+__testip(struct ip_set *set, ip_set_ip_t ip, ip_set_ip_t port,
-+ ip_set_ip_t *hash_ip)
-+{
-+ struct ip_set_ipporthash *map = (struct ip_set_ipporthash *) set->data;
-+
-+ if (ip < map->first_ip || ip > map->last_ip)
-+ return -ERANGE;
-+
-+ return (hash_id(set, ip, port, hash_ip) != UINT_MAX);
-+}
-+
-+static int
-+testip(struct ip_set *set, const void *data, size_t size,
-+ ip_set_ip_t *hash_ip)
-+{
-+ struct ip_set_req_ipporthash *req =
-+ (struct ip_set_req_ipporthash *) data;
-+
-+ if (size != sizeof(struct ip_set_req_ipporthash)) {
-+ ip_set_printk("data length wrong (want %zu, have %zu)",
-+ sizeof(struct ip_set_req_ipporthash),
-+ size);
-+ return -EINVAL;
-+ }
-+ return __testip(set, req->ip, req->port, hash_ip);
-+}
-+
-+static int
-+testip_kernel(struct ip_set *set,
-+ const struct sk_buff *skb,
-+ ip_set_ip_t *hash_ip,
-+ const u_int32_t *flags,
-+ unsigned char index)
-+{
-+ ip_set_ip_t port;
-+ int res;
-+
-+ if (flags[index+1] == 0)
-+ return 0;
-+
-+ port = get_port(skb, flags[index+1]);
-+
-+ DP("flag: %s src: %u.%u.%u.%u dst: %u.%u.%u.%u",
-+ flags[index] & IPSET_SRC ? "SRC" : "DST",
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-+ NIPQUAD(ip_hdr(skb)->saddr),
-+ NIPQUAD(ip_hdr(skb)->daddr));
-+#else
-+ NIPQUAD(skb->nh.iph->saddr),
-+ NIPQUAD(skb->nh.iph->daddr));
-+#endif
-+ DP("flag %s port %u",
-+ flags[index+1] & IPSET_SRC ? "SRC" : "DST",
-+ port);
-+ if (port == INVALID_PORT)
-+ return 0;
-+
-+ res = __testip(set,
-+ ntohl(flags[index] & IPSET_SRC
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-+ ? ip_hdr(skb)->saddr
-+ : ip_hdr(skb)->daddr),
-+#else
-+ ? skb->nh.iph->saddr
-+ : skb->nh.iph->daddr),
-+#endif
-+ port,
-+ hash_ip);
-+ return (res < 0 ? 0 : res);
-+
-+}
-+
-+static inline int
-+__add_haship(struct ip_set_ipporthash *map, ip_set_ip_t hash_ip)
-+{
-+ __u32 probe;
-+ u_int16_t i;
-+ ip_set_ip_t *elem;
-+
-+ for (i = 0; i < map->probes; i++) {
-+ probe = jhash_ip(map, i, hash_ip) % map->hashsize;
-+ elem = HARRAY_ELEM(map->members, ip_set_ip_t *, probe);
-+ if (*elem == hash_ip)
-+ return -EEXIST;
-+ if (!*elem) {
-+ *elem = hash_ip;
-+ map->elements++;
-+ return 0;
-+ }
-+ }
-+ /* Trigger rehashing */
-+ return -EAGAIN;
-+}
-+
-+static inline int
-+__addip(struct ip_set_ipporthash *map, ip_set_ip_t ip, ip_set_ip_t port,
-+ ip_set_ip_t *hash_ip)
-+{
-+ if (map->elements > limit)
-+ return -ERANGE;
-+ if (ip < map->first_ip || ip > map->last_ip)
-+ return -ERANGE;
-+
-+ *hash_ip = HASH_IP(map, ip, port);
-+
-+ return __add_haship(map, *hash_ip);
-+}
-+
-+static int
-+addip(struct ip_set *set, const void *data, size_t size,
-+ ip_set_ip_t *hash_ip)
-+{
-+ struct ip_set_req_ipporthash *req =
-+ (struct ip_set_req_ipporthash *) data;
-+
-+ if (size != sizeof(struct ip_set_req_ipporthash)) {
-+ ip_set_printk("data length wrong (want %zu, have %zu)",
-+ sizeof(struct ip_set_req_ipporthash),
-+ size);
-+ return -EINVAL;
-+ }
-+ return __addip((struct ip_set_ipporthash *) set->data,
-+ req->ip, req->port, hash_ip);
-+}
-+
-+static int
-+addip_kernel(struct ip_set *set,
-+ const struct sk_buff *skb,
-+ ip_set_ip_t *hash_ip,
-+ const u_int32_t *flags,
-+ unsigned char index)
-+{
-+ ip_set_ip_t port;
-+
-+ if (flags[index+1] == 0)
-+ return -EINVAL;
-+
-+ port = get_port(skb, flags[index+1]);
-+
-+ DP("flag: %s src: %u.%u.%u.%u dst: %u.%u.%u.%u",
-+ flags[index] & IPSET_SRC ? "SRC" : "DST",
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-+ NIPQUAD(ip_hdr(skb)->saddr),
-+ NIPQUAD(ip_hdr(skb)->daddr));
-+#else
-+ NIPQUAD(skb->nh.iph->saddr),
-+ NIPQUAD(skb->nh.iph->daddr));
-+#endif
-+ DP("flag %s port %u",
-+ flags[index+1] & IPSET_SRC ? "SRC" : "DST",
-+ port);
-+ if (port == INVALID_PORT)
-+ return -EINVAL;
-+
-+ return __addip((struct ip_set_ipporthash *) set->data,
-+ ntohl(flags[index] & IPSET_SRC
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-+ ? ip_hdr(skb)->saddr
-+ : ip_hdr(skb)->daddr),
-+#else
-+ ? skb->nh.iph->saddr
-+ : skb->nh.iph->daddr),
-+#endif
-+ port,
-+ hash_ip);
-+}
-+
-+static int retry(struct ip_set *set)
-+{
-+ struct ip_set_ipporthash *map = (struct ip_set_ipporthash *) set->data;
-+ ip_set_ip_t *elem;
-+ void *members;
-+ u_int32_t i, hashsize = map->hashsize;
-+ int res;
-+ struct ip_set_ipporthash *tmp;
-+
-+ if (map->resize == 0)
-+ return -ERANGE;
-+
-+ again:
-+ res = 0;
-+
-+ /* Calculate new hash size */
-+ hashsize += (hashsize * map->resize)/100;
-+ if (hashsize == map->hashsize)
-+ hashsize++;
-+
-+ ip_set_printk("rehashing of set %s triggered: "
-+ "hashsize grows from %u to %u",
-+ set->name, map->hashsize, hashsize);
-+
-+ tmp = kmalloc(sizeof(struct ip_set_ipporthash)
-+ + map->probes * sizeof(uint32_t), GFP_ATOMIC);
-+ if (!tmp) {
-+ DP("out of memory for %d bytes",
-+ sizeof(struct ip_set_ipporthash)
-+ + map->probes * sizeof(uint32_t));
-+ return -ENOMEM;
-+ }
-+ tmp->members = harray_malloc(hashsize, sizeof(ip_set_ip_t), GFP_ATOMIC);
-+ if (!tmp->members) {
-+ DP("out of memory for %d bytes", hashsize * sizeof(ip_set_ip_t));
-+ kfree(tmp);
-+ return -ENOMEM;
-+ }
-+ tmp->hashsize = hashsize;
-+ tmp->elements = 0;
-+ tmp->probes = map->probes;
-+ tmp->resize = map->resize;
-+ tmp->first_ip = map->first_ip;
-+ tmp->last_ip = map->last_ip;
-+ memcpy(tmp->initval, map->initval, map->probes * sizeof(uint32_t));
-+
-+ write_lock_bh(&set->lock);
-+ map = (struct ip_set_ipporthash *) set->data; /* Play safe */
-+ for (i = 0; i < map->hashsize && res == 0; i++) {
-+ elem = HARRAY_ELEM(map->members, ip_set_ip_t *, i);
-+ if (*elem)
-+ res = __add_haship(tmp, *elem);
-+ }
-+ if (res) {
-+ /* Failure, try again */
-+ write_unlock_bh(&set->lock);
-+ harray_free(tmp->members);
-+ kfree(tmp);
-+ goto again;
-+ }
-+
-+ /* Success at resizing! */
-+ members = map->members;
-+
-+ map->hashsize = tmp->hashsize;
-+ map->members = tmp->members;
-+ write_unlock_bh(&set->lock);
-+
-+ harray_free(members);
-+ kfree(tmp);
-+
-+ return 0;
-+}
-+
-+static inline int
-+__delip(struct ip_set *set, ip_set_ip_t ip, ip_set_ip_t port,
-+ ip_set_ip_t *hash_ip)
-+{
-+ struct ip_set_ipporthash *map = (struct ip_set_ipporthash *) set->data;
-+ ip_set_ip_t id;
-+ ip_set_ip_t *elem;
-+
-+ if (ip < map->first_ip || ip > map->last_ip)
-+ return -ERANGE;
-+
-+ id = hash_id(set, ip, port, hash_ip);
-+
-+ if (id == UINT_MAX)
-+ return -EEXIST;
-+
-+ elem = HARRAY_ELEM(map->members, ip_set_ip_t *, id);
-+ *elem = 0;
-+ map->elements--;
-+
-+ return 0;
-+}
-+
-+static int
-+delip(struct ip_set *set, const void *data, size_t size,
-+ ip_set_ip_t *hash_ip)
-+{
-+ struct ip_set_req_ipporthash *req =
-+ (struct ip_set_req_ipporthash *) data;
-+
-+ if (size != sizeof(struct ip_set_req_ipporthash)) {
-+ ip_set_printk("data length wrong (want %zu, have %zu)",
-+ sizeof(struct ip_set_req_ipporthash),
-+ size);
-+ return -EINVAL;
-+ }
-+ return __delip(set, req->ip, req->port, hash_ip);
-+}
-+
-+static int
-+delip_kernel(struct ip_set *set,
-+ const struct sk_buff *skb,
-+ ip_set_ip_t *hash_ip,
-+ const u_int32_t *flags,
-+ unsigned char index)
-+{
-+ ip_set_ip_t port;
-+
-+ if (flags[index+1] == 0)
-+ return -EINVAL;
-+
-+ port = get_port(skb, flags[index+1]);
-+
-+ DP("flag: %s src: %u.%u.%u.%u dst: %u.%u.%u.%u",
-+ flags[index] & IPSET_SRC ? "SRC" : "DST",
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-+ NIPQUAD(ip_hdr(skb)->saddr),
-+ NIPQUAD(ip_hdr(skb)->daddr));
-+#else
-+ NIPQUAD(skb->nh.iph->saddr),
-+ NIPQUAD(skb->nh.iph->daddr));
-+#endif
-+ DP("flag %s port %u",
-+ flags[index+1] & IPSET_SRC ? "SRC" : "DST",
-+ port);
-+ if (port == INVALID_PORT)
-+ return -EINVAL;
-+
-+ return __delip(set,
-+ ntohl(flags[index] & IPSET_SRC
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-+ ? ip_hdr(skb)->saddr
-+ : ip_hdr(skb)->daddr),
-+#else
-+ ? skb->nh.iph->saddr
-+ : skb->nh.iph->daddr),
-+#endif
-+ port,
-+ hash_ip);
-+}
-+
-+static int create(struct ip_set *set, const void *data, size_t size)
-+{
-+ struct ip_set_req_ipporthash_create *req =
-+ (struct ip_set_req_ipporthash_create *) data;
-+ struct ip_set_ipporthash *map;
-+ uint16_t i;
-+
-+ if (size != sizeof(struct ip_set_req_ipporthash_create)) {
-+ ip_set_printk("data length wrong (want %zu, have %zu)",
-+ sizeof(struct ip_set_req_ipporthash_create),
-+ size);
-+ return -EINVAL;
-+ }
-+
-+ if (req->hashsize < 1) {
-+ ip_set_printk("hashsize too small");
-+ return -ENOEXEC;
-+ }
-+
-+ if (req->probes < 1) {
-+ ip_set_printk("probes too small");
-+ return -ENOEXEC;
-+ }
-+
-+ map = kmalloc(sizeof(struct ip_set_ipporthash)
-+ + req->probes * sizeof(uint32_t), GFP_KERNEL);
-+ if (!map) {
-+ DP("out of memory for %d bytes",
-+ sizeof(struct ip_set_ipporthash)
-+ + req->probes * sizeof(uint32_t));
-+ return -ENOMEM;
-+ }
-+ for (i = 0; i < req->probes; i++)
-+ get_random_bytes(((uint32_t *) map->initval)+i, 4);
-+ map->elements = 0;
-+ map->hashsize = req->hashsize;
-+ map->probes = req->probes;
-+ map->resize = req->resize;
-+ map->first_ip = req->from;
-+ map->last_ip = req->to;
-+ map->members = harray_malloc(map->hashsize, sizeof(ip_set_ip_t), GFP_KERNEL);
-+ if (!map->members) {
-+ DP("out of memory for %d bytes", map->hashsize * sizeof(ip_set_ip_t));
-+ kfree(map);
-+ return -ENOMEM;
-+ }
-+
-+ set->data = map;
-+ return 0;
-+}
-+
-+static void destroy(struct ip_set *set)
-+{
-+ struct ip_set_ipporthash *map = (struct ip_set_ipporthash *) set->data;
-+
-+ harray_free(map->members);
-+ kfree(map);
-+
-+ set->data = NULL;
-+}
-+
-+static void flush(struct ip_set *set)
-+{
-+ struct ip_set_ipporthash *map = (struct ip_set_ipporthash *) set->data;
-+ harray_flush(map->members, map->hashsize, sizeof(ip_set_ip_t));
-+ map->elements = 0;
-+}
-+
-+static void list_header(const struct ip_set *set, void *data)
-+{
-+ struct ip_set_ipporthash *map = (struct ip_set_ipporthash *) set->data;
-+ struct ip_set_req_ipporthash_create *header =
-+ (struct ip_set_req_ipporthash_create *) data;
-+
-+ header->hashsize = map->hashsize;
-+ header->probes = map->probes;
-+ header->resize = map->resize;
-+ header->from = map->first_ip;
-+ header->to = map->last_ip;
-+}
-+
-+static int list_members_size(const struct ip_set *set)
-+{
-+ struct ip_set_ipporthash *map = (struct ip_set_ipporthash *) set->data;
-+
-+ return (map->hashsize * sizeof(ip_set_ip_t));
-+}
-+
-+static void list_members(const struct ip_set *set, void *data)
-+{
-+ struct ip_set_ipporthash *map = (struct ip_set_ipporthash *) set->data;
-+ ip_set_ip_t i, *elem;
-+
-+ for (i = 0; i < map->hashsize; i++) {
-+ elem = HARRAY_ELEM(map->members, ip_set_ip_t *, i);
-+ ((ip_set_ip_t *)data)[i] = *elem;
-+ }
-+}
-+
-+static struct ip_set_type ip_set_ipporthash = {
-+ .typename = SETTYPE_NAME,
-+ .features = IPSET_TYPE_IP | IPSET_TYPE_PORT | IPSET_DATA_DOUBLE,
-+ .protocol_version = IP_SET_PROTOCOL_VERSION,
-+ .create = &create,
-+ .destroy = &destroy,
-+ .flush = &flush,
-+ .reqsize = sizeof(struct ip_set_req_ipporthash),
-+ .addip = &addip,
-+ .addip_kernel = &addip_kernel,
-+ .retry = &retry,
-+ .delip = &delip,
-+ .delip_kernel = &delip_kernel,
-+ .testip = &testip,
-+ .testip_kernel = &testip_kernel,
-+ .header_size = sizeof(struct ip_set_req_ipporthash_create),
-+ .list_header = &list_header,
-+ .list_members_size = &list_members_size,
-+ .list_members = &list_members,
-+ .me = THIS_MODULE,
-+};
-+
-+MODULE_LICENSE("GPL");
-+MODULE_AUTHOR("Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>");
-+MODULE_DESCRIPTION("ipporthash type of IP sets");
-+module_param(limit, int, 0600);
-+MODULE_PARM_DESC(limit, "maximal number of elements stored in the sets");
-+
-+static int __init ip_set_ipporthash_init(void)
-+{
-+ return ip_set_register_set_type(&ip_set_ipporthash);
-+}
-+
-+static void __exit ip_set_ipporthash_fini(void)
-+{
-+ /* FIXME: possible race with ip_set_create() */
-+ ip_set_unregister_set_type(&ip_set_ipporthash);
-+}
-+
-+module_init(ip_set_ipporthash_init);
-+module_exit(ip_set_ipporthash_fini);
---- /dev/null
-+++ b/net/ipv4/netfilter/ip_set_iptree.c
-@@ -0,0 +1,612 @@
-+/* Copyright (C) 2005 Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
-+ *
-+ * This program is free software; you can redistribute it and/or modify
-+ * it under the terms of the GNU General Public License version 2 as
-+ * published by the Free Software Foundation.
-+ */
-+
-+/* Kernel module implementing an IP set type: the iptree type */
-+
-+#include <linux/version.h>
-+#include <linux/module.h>
-+#include <linux/ip.h>
-+#include <linux/skbuff.h>
-+#include <linux/slab.h>
-+#include <linux/delay.h>
-+#include <linux/netfilter_ipv4/ip_tables.h>
-+#include <linux/netfilter_ipv4/ip_set.h>
-+#include <linux/errno.h>
-+#include <asm/uaccess.h>
-+#include <asm/bitops.h>
-+#include <linux/spinlock.h>
-+
-+/* Backward compatibility */
-+#ifndef __nocast
-+#define __nocast
-+#endif
-+
-+#include <linux/netfilter_ipv4/ip_set_iptree.h>
-+
-+static int limit = MAX_RANGE;
-+
-+/* Garbage collection interval in seconds: */
-+#define IPTREE_GC_TIME 5*60
-+/* Sleep so many milliseconds before trying again
-+ * to delete the gc timer at destroying/flushing a set */
-+#define IPTREE_DESTROY_SLEEP 100
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,21)
-+static struct kmem_cache *branch_cachep;
-+static struct kmem_cache *leaf_cachep;
-+#else
-+static kmem_cache_t *branch_cachep;
-+static kmem_cache_t *leaf_cachep;
-+#endif
-+
-+#if defined(__LITTLE_ENDIAN)
-+#define ABCD(a,b,c,d,addrp) do { \
-+ a = ((unsigned char *)addrp)[3]; \
-+ b = ((unsigned char *)addrp)[2]; \
-+ c = ((unsigned char *)addrp)[1]; \
-+ d = ((unsigned char *)addrp)[0]; \
-+} while (0)
-+#elif defined(__BIG_ENDIAN)
-+#define ABCD(a,b,c,d,addrp) do { \
-+ a = ((unsigned char *)addrp)[0]; \
-+ b = ((unsigned char *)addrp)[1]; \
-+ c = ((unsigned char *)addrp)[2]; \
-+ d = ((unsigned char *)addrp)[3]; \
-+} while (0)
-+#else
-+#error "Please fix asm/byteorder.h"
-+#endif /* __LITTLE_ENDIAN */
-+
-+#define TESTIP_WALK(map, elem, branch) do { \
-+ if ((map)->tree[elem]) { \
-+ branch = (map)->tree[elem]; \
-+ } else \
-+ return 0; \
-+} while (0)
-+
-+static inline int
-+__testip(struct ip_set *set, ip_set_ip_t ip, ip_set_ip_t *hash_ip)
-+{
-+ struct ip_set_iptree *map = (struct ip_set_iptree *) set->data;
-+ struct ip_set_iptreeb *btree;
-+ struct ip_set_iptreec *ctree;
-+ struct ip_set_iptreed *dtree;
-+ unsigned char a,b,c,d;
-+
-+ if (!ip)
-+ return -ERANGE;
-+
-+ *hash_ip = ip;
-+ ABCD(a, b, c, d, hash_ip);
-+ DP("%u %u %u %u timeout %u", a, b, c, d, map->timeout);
-+ TESTIP_WALK(map, a, btree);
-+ TESTIP_WALK(btree, b, ctree);
-+ TESTIP_WALK(ctree, c, dtree);
-+ DP("%lu %lu", dtree->expires[d], jiffies);
-+ return dtree->expires[d]
-+ && (!map->timeout
-+ || time_after(dtree->expires[d], jiffies));
-+}
-+
-+static int
-+testip(struct ip_set *set, const void *data, size_t size,
-+ ip_set_ip_t *hash_ip)
-+{
-+ struct ip_set_req_iptree *req =
-+ (struct ip_set_req_iptree *) data;
-+
-+ if (size != sizeof(struct ip_set_req_iptree)) {
-+ ip_set_printk("data length wrong (want %zu, have %zu)",
-+ sizeof(struct ip_set_req_iptree),
-+ size);
-+ return -EINVAL;
-+ }
-+ return __testip(set, req->ip, hash_ip);
-+}
-+
-+static int
-+testip_kernel(struct ip_set *set,
-+ const struct sk_buff *skb,
-+ ip_set_ip_t *hash_ip,
-+ const u_int32_t *flags,
-+ unsigned char index)
-+{
-+ int res;
-+
-+ DP("flag: %s src: %u.%u.%u.%u dst: %u.%u.%u.%u",
-+ flags[index] & IPSET_SRC ? "SRC" : "DST",
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-+ NIPQUAD(ip_hdr(skb)->saddr),
-+ NIPQUAD(ip_hdr(skb)->daddr));
-+#else
-+ NIPQUAD(skb->nh.iph->saddr),
-+ NIPQUAD(skb->nh.iph->daddr));
-+#endif
-+
-+ res = __testip(set,
-+ ntohl(flags[index] & IPSET_SRC
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-+ ? ip_hdr(skb)->saddr
-+ : ip_hdr(skb)->daddr),
-+#else
-+ ? skb->nh.iph->saddr
-+ : skb->nh.iph->daddr),
-+#endif
-+ hash_ip);
-+ return (res < 0 ? 0 : res);
-+}
-+
-+#define ADDIP_WALK(map, elem, branch, type, cachep) do { \
-+ if ((map)->tree[elem]) { \
-+ DP("found %u", elem); \
-+ branch = (map)->tree[elem]; \
-+ } else { \
-+ branch = (type *) \
-+ kmem_cache_alloc(cachep, GFP_ATOMIC); \
-+ if (branch == NULL) \
-+ return -ENOMEM; \
-+ memset(branch, 0, sizeof(*branch)); \
-+ (map)->tree[elem] = branch; \
-+ DP("alloc %u", elem); \
-+ } \
-+} while (0)
-+
-+static inline int
-+__addip(struct ip_set *set, ip_set_ip_t ip, unsigned int timeout,
-+ ip_set_ip_t *hash_ip)
-+{
-+ struct ip_set_iptree *map = (struct ip_set_iptree *) set->data;
-+ struct ip_set_iptreeb *btree;
-+ struct ip_set_iptreec *ctree;
-+ struct ip_set_iptreed *dtree;
-+ unsigned char a,b,c,d;
-+ int ret = 0;
-+
-+ if (!ip || map->elements >= limit)
-+ /* We could call the garbage collector
-+ * but it's probably overkill */
-+ return -ERANGE;
-+
-+ *hash_ip = ip;
-+ ABCD(a, b, c, d, hash_ip);
-+ DP("%u %u %u %u timeout %u", a, b, c, d, timeout);
-+ ADDIP_WALK(map, a, btree, struct ip_set_iptreeb, branch_cachep);
-+ ADDIP_WALK(btree, b, ctree, struct ip_set_iptreec, branch_cachep);
-+ ADDIP_WALK(ctree, c, dtree, struct ip_set_iptreed, leaf_cachep);
-+ if (dtree->expires[d]
-+ && (!map->timeout || time_after(dtree->expires[d], jiffies)))
-+ ret = -EEXIST;
-+ dtree->expires[d] = map->timeout ? (timeout * HZ + jiffies) : 1;
-+ /* Lottery: I won! */
-+ if (dtree->expires[d] == 0)
-+ dtree->expires[d] = 1;
-+ DP("%u %lu", d, dtree->expires[d]);
-+ if (ret == 0)
-+ map->elements++;
-+ return ret;
-+}
-+
-+static int
-+addip(struct ip_set *set, const void *data, size_t size,
-+ ip_set_ip_t *hash_ip)
-+{
-+ struct ip_set_iptree *map = (struct ip_set_iptree *) set->data;
-+ struct ip_set_req_iptree *req =
-+ (struct ip_set_req_iptree *) data;
-+
-+ if (size != sizeof(struct ip_set_req_iptree)) {
-+ ip_set_printk("data length wrong (want %zu, have %zu)",
-+ sizeof(struct ip_set_req_iptree),
-+ size);
-+ return -EINVAL;
-+ }
-+ DP("%u.%u.%u.%u %u", HIPQUAD(req->ip), req->timeout);
-+ return __addip(set, req->ip,
-+ req->timeout ? req->timeout : map->timeout,
-+ hash_ip);
-+}
-+
-+static int
-+addip_kernel(struct ip_set *set,
-+ const struct sk_buff *skb,
-+ ip_set_ip_t *hash_ip,
-+ const u_int32_t *flags,
-+ unsigned char index)
-+{
-+ struct ip_set_iptree *map = (struct ip_set_iptree *) set->data;
-+
-+ return __addip(set,
-+ ntohl(flags[index] & IPSET_SRC
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-+ ? ip_hdr(skb)->saddr
-+ : ip_hdr(skb)->daddr),
-+#else
-+ ? skb->nh.iph->saddr
-+ : skb->nh.iph->daddr),
-+#endif
-+ map->timeout,
-+ hash_ip);
-+}
-+
-+#define DELIP_WALK(map, elem, branch) do { \
-+ if ((map)->tree[elem]) { \
-+ branch = (map)->tree[elem]; \
-+ } else \
-+ return -EEXIST; \
-+} while (0)
-+
-+static inline int
-+__delip(struct ip_set *set, ip_set_ip_t ip, ip_set_ip_t *hash_ip)
-+{
-+ struct ip_set_iptree *map = (struct ip_set_iptree *) set->data;
-+ struct ip_set_iptreeb *btree;
-+ struct ip_set_iptreec *ctree;
-+ struct ip_set_iptreed *dtree;
-+ unsigned char a,b,c,d;
-+
-+ if (!ip)
-+ return -ERANGE;
-+
-+ *hash_ip = ip;
-+ ABCD(a, b, c, d, hash_ip);
-+ DELIP_WALK(map, a, btree);
-+ DELIP_WALK(btree, b, ctree);
-+ DELIP_WALK(ctree, c, dtree);
-+
-+ if (dtree->expires[d]) {
-+ dtree->expires[d] = 0;
-+ map->elements--;
-+ return 0;
-+ }
-+ return -EEXIST;
-+}
-+
-+static int
-+delip(struct ip_set *set, const void *data, size_t size,
-+ ip_set_ip_t *hash_ip)
-+{
-+ struct ip_set_req_iptree *req =
-+ (struct ip_set_req_iptree *) data;
-+
-+ if (size != sizeof(struct ip_set_req_iptree)) {
-+ ip_set_printk("data length wrong (want %zu, have %zu)",
-+ sizeof(struct ip_set_req_iptree),
-+ size);
-+ return -EINVAL;
-+ }
-+ return __delip(set, req->ip, hash_ip);
-+}
-+
-+static int
-+delip_kernel(struct ip_set *set,
-+ const struct sk_buff *skb,
-+ ip_set_ip_t *hash_ip,
-+ const u_int32_t *flags,
-+ unsigned char index)
-+{
-+ return __delip(set,
-+ ntohl(flags[index] & IPSET_SRC
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-+ ? ip_hdr(skb)->saddr
-+ : ip_hdr(skb)->daddr),
-+#else
-+ ? skb->nh.iph->saddr
-+ : skb->nh.iph->daddr),
-+#endif
-+ hash_ip);
-+}
-+
-+#define LOOP_WALK_BEGIN(map, i, branch) \
-+ for (i = 0; i < 256; i++) { \
-+ if (!(map)->tree[i]) \
-+ continue; \
-+ branch = (map)->tree[i]
-+
-+#define LOOP_WALK_END }
-+
-+static void ip_tree_gc(unsigned long ul_set)
-+{
-+ struct ip_set *set = (void *) ul_set;
-+ struct ip_set_iptree *map = (struct ip_set_iptree *) set->data;
-+ struct ip_set_iptreeb *btree;
-+ struct ip_set_iptreec *ctree;
-+ struct ip_set_iptreed *dtree;
-+ unsigned int a,b,c,d;
-+ unsigned char i,j,k;
-+
-+ i = j = k = 0;
-+ DP("gc: %s", set->name);
-+ write_lock_bh(&set->lock);
-+ LOOP_WALK_BEGIN(map, a, btree);
-+ LOOP_WALK_BEGIN(btree, b, ctree);
-+ LOOP_WALK_BEGIN(ctree, c, dtree);
-+ for (d = 0; d < 256; d++) {
-+ if (dtree->expires[d]) {
-+ DP("gc: %u %u %u %u: expires %lu jiffies %lu",
-+ a, b, c, d,
-+ dtree->expires[d], jiffies);
-+ if (map->timeout
-+ && time_before(dtree->expires[d], jiffies)) {
-+ dtree->expires[d] = 0;
-+ map->elements--;
-+ } else
-+ k = 1;
-+ }
-+ }
-+ if (k == 0) {
-+ DP("gc: %s: leaf %u %u %u empty",
-+ set->name, a, b, c);
-+ kmem_cache_free(leaf_cachep, dtree);
-+ ctree->tree[c] = NULL;
-+ } else {
-+ DP("gc: %s: leaf %u %u %u not empty",
-+ set->name, a, b, c);
-+ j = 1;
-+ k = 0;
-+ }
-+ LOOP_WALK_END;
-+ if (j == 0) {
-+ DP("gc: %s: branch %u %u empty",
-+ set->name, a, b);
-+ kmem_cache_free(branch_cachep, ctree);
-+ btree->tree[b] = NULL;
-+ } else {
-+ DP("gc: %s: branch %u %u not empty",
-+ set->name, a, b);
-+ i = 1;
-+ j = k = 0;
-+ }
-+ LOOP_WALK_END;
-+ if (i == 0) {
-+ DP("gc: %s: branch %u empty",
-+ set->name, a);
-+ kmem_cache_free(branch_cachep, btree);
-+ map->tree[a] = NULL;
-+ } else {
-+ DP("gc: %s: branch %u not empty",
-+ set->name, a);
-+ i = j = k = 0;
-+ }
-+ LOOP_WALK_END;
-+ write_unlock_bh(&set->lock);
-+
-+ map->gc.expires = jiffies + map->gc_interval * HZ;
-+ add_timer(&map->gc);
-+}
-+
-+static inline void init_gc_timer(struct ip_set *set)
-+{
-+ struct ip_set_iptree *map = (struct ip_set_iptree *) set->data;
-+
-+ /* Even if there is no timeout for the entries,
-+ * we still have to call gc because delete
-+ * do not clean up empty branches */
-+ map->gc_interval = IPTREE_GC_TIME;
-+ init_timer(&map->gc);
-+ map->gc.data = (unsigned long) set;
-+ map->gc.function = ip_tree_gc;
-+ map->gc.expires = jiffies + map->gc_interval * HZ;
-+ add_timer(&map->gc);
-+}
-+
-+static int create(struct ip_set *set, const void *data, size_t size)
-+{
-+ struct ip_set_req_iptree_create *req =
-+ (struct ip_set_req_iptree_create *) data;
-+ struct ip_set_iptree *map;
-+
-+ if (size != sizeof(struct ip_set_req_iptree_create)) {
-+ ip_set_printk("data length wrong (want %zu, have %zu)",
-+ sizeof(struct ip_set_req_iptree_create),
-+ size);
-+ return -EINVAL;
-+ }
-+
-+ map = kmalloc(sizeof(struct ip_set_iptree), GFP_KERNEL);
-+ if (!map) {
-+ DP("out of memory for %d bytes",
-+ sizeof(struct ip_set_iptree));
-+ return -ENOMEM;
-+ }
-+ memset(map, 0, sizeof(*map));
-+ map->timeout = req->timeout;
-+ map->elements = 0;
-+ set->data = map;
-+
-+ init_gc_timer(set);
-+
-+ return 0;
-+}
-+
-+static void __flush(struct ip_set_iptree *map)
-+{
-+ struct ip_set_iptreeb *btree;
-+ struct ip_set_iptreec *ctree;
-+ struct ip_set_iptreed *dtree;
-+ unsigned int a,b,c;
-+
-+ LOOP_WALK_BEGIN(map, a, btree);
-+ LOOP_WALK_BEGIN(btree, b, ctree);
-+ LOOP_WALK_BEGIN(ctree, c, dtree);
-+ kmem_cache_free(leaf_cachep, dtree);
-+ LOOP_WALK_END;
-+ kmem_cache_free(branch_cachep, ctree);
-+ LOOP_WALK_END;
-+ kmem_cache_free(branch_cachep, btree);
-+ LOOP_WALK_END;
-+ map->elements = 0;
-+}
-+
-+static void destroy(struct ip_set *set)
-+{
-+ struct ip_set_iptree *map = (struct ip_set_iptree *) set->data;
-+
-+ /* gc might be running */
-+ while (!del_timer(&map->gc))
-+ msleep(IPTREE_DESTROY_SLEEP);
-+ __flush(map);
-+ kfree(map);
-+ set->data = NULL;
-+}
-+
-+static void flush(struct ip_set *set)
-+{
-+ struct ip_set_iptree *map = (struct ip_set_iptree *) set->data;
-+ unsigned int timeout = map->timeout;
-+
-+ /* gc might be running */
-+ while (!del_timer(&map->gc))
-+ msleep(IPTREE_DESTROY_SLEEP);
-+ __flush(map);
-+ memset(map, 0, sizeof(*map));
-+ map->timeout = timeout;
-+
-+ init_gc_timer(set);
-+}
-+
-+static void list_header(const struct ip_set *set, void *data)
-+{
-+ struct ip_set_iptree *map = (struct ip_set_iptree *) set->data;
-+ struct ip_set_req_iptree_create *header =
-+ (struct ip_set_req_iptree_create *) data;
-+
-+ header->timeout = map->timeout;
-+}
-+
-+static int list_members_size(const struct ip_set *set)
-+{
-+ struct ip_set_iptree *map = (struct ip_set_iptree *) set->data;
-+ struct ip_set_iptreeb *btree;
-+ struct ip_set_iptreec *ctree;
-+ struct ip_set_iptreed *dtree;
-+ unsigned int a,b,c,d;
-+ unsigned int count = 0;
-+
-+ LOOP_WALK_BEGIN(map, a, btree);
-+ LOOP_WALK_BEGIN(btree, b, ctree);
-+ LOOP_WALK_BEGIN(ctree, c, dtree);
-+ for (d = 0; d < 256; d++) {
-+ if (dtree->expires[d]
-+ && (!map->timeout || time_after(dtree->expires[d], jiffies)))
-+ count++;
-+ }
-+ LOOP_WALK_END;
-+ LOOP_WALK_END;
-+ LOOP_WALK_END;
-+
-+ DP("members %u", count);
-+ return (count * sizeof(struct ip_set_req_iptree));
-+}
-+
-+static void list_members(const struct ip_set *set, void *data)
-+{
-+ struct ip_set_iptree *map = (struct ip_set_iptree *) set->data;
-+ struct ip_set_iptreeb *btree;
-+ struct ip_set_iptreec *ctree;
-+ struct ip_set_iptreed *dtree;
-+ unsigned int a,b,c,d;
-+ size_t offset = 0;
-+ struct ip_set_req_iptree *entry;
-+
-+ LOOP_WALK_BEGIN(map, a, btree);
-+ LOOP_WALK_BEGIN(btree, b, ctree);
-+ LOOP_WALK_BEGIN(ctree, c, dtree);
-+ for (d = 0; d < 256; d++) {
-+ if (dtree->expires[d]
-+ && (!map->timeout || time_after(dtree->expires[d], jiffies))) {
-+ entry = (struct ip_set_req_iptree *)(data + offset);
-+ entry->ip = ((a << 24) | (b << 16) | (c << 8) | d);
-+ entry->timeout = !map->timeout ? 0
-+ : (dtree->expires[d] - jiffies)/HZ;
-+ offset += sizeof(struct ip_set_req_iptree);
-+ }
-+ }
-+ LOOP_WALK_END;
-+ LOOP_WALK_END;
-+ LOOP_WALK_END;
-+}
-+
-+static struct ip_set_type ip_set_iptree = {
-+ .typename = SETTYPE_NAME,
-+ .features = IPSET_TYPE_IP | IPSET_DATA_SINGLE,
-+ .protocol_version = IP_SET_PROTOCOL_VERSION,
-+ .create = &create,
-+ .destroy = &destroy,
-+ .flush = &flush,
-+ .reqsize = sizeof(struct ip_set_req_iptree),
-+ .addip = &addip,
-+ .addip_kernel = &addip_kernel,
-+ .delip = &delip,
-+ .delip_kernel = &delip_kernel,
-+ .testip = &testip,
-+ .testip_kernel = &testip_kernel,
-+ .header_size = sizeof(struct ip_set_req_iptree_create),
-+ .list_header = &list_header,
-+ .list_members_size = &list_members_size,
-+ .list_members = &list_members,
-+ .me = THIS_MODULE,
-+};
-+
-+MODULE_LICENSE("GPL");
-+MODULE_AUTHOR("Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>");
-+MODULE_DESCRIPTION("iptree type of IP sets");
-+module_param(limit, int, 0600);
-+MODULE_PARM_DESC(limit, "maximal number of elements stored in the sets");
-+
-+static int __init ip_set_iptree_init(void)
-+{
-+ int ret;
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,23)
-+ branch_cachep = kmem_cache_create("ip_set_iptreeb",
-+ sizeof(struct ip_set_iptreeb),
-+ 0, 0, NULL);
-+#else
-+ branch_cachep = kmem_cache_create("ip_set_iptreeb",
-+ sizeof(struct ip_set_iptreeb),
-+ 0, 0, NULL, NULL);
-+#endif
-+ if (!branch_cachep) {
-+ printk(KERN_ERR "Unable to create ip_set_iptreeb slab cache\n");
-+ ret = -ENOMEM;
-+ goto out;
-+ }
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,23)
-+ leaf_cachep = kmem_cache_create("ip_set_iptreed",
-+ sizeof(struct ip_set_iptreed),
-+ 0, 0, NULL);
-+#else
-+ leaf_cachep = kmem_cache_create("ip_set_iptreed",
-+ sizeof(struct ip_set_iptreed),
-+ 0, 0, NULL, NULL);
-+#endif
-+ if (!leaf_cachep) {
-+ printk(KERN_ERR "Unable to create ip_set_iptreed slab cache\n");
-+ ret = -ENOMEM;
-+ goto free_branch;
-+ }
-+ ret = ip_set_register_set_type(&ip_set_iptree);
-+ if (ret == 0)
-+ goto out;
-+
-+ kmem_cache_destroy(leaf_cachep);
-+ free_branch:
-+ kmem_cache_destroy(branch_cachep);
-+ out:
-+ return ret;
-+}
-+
-+static void __exit ip_set_iptree_fini(void)
-+{
-+ /* FIXME: possible race with ip_set_create() */
-+ ip_set_unregister_set_type(&ip_set_iptree);
-+ kmem_cache_destroy(leaf_cachep);
-+ kmem_cache_destroy(branch_cachep);
-+}
-+
-+module_init(ip_set_iptree_init);
-+module_exit(ip_set_iptree_fini);
---- /dev/null
-+++ b/net/ipv4/netfilter/ip_set_iptreemap.c
-@@ -0,0 +1,829 @@
-+/* Copyright (C) 2007 Sven Wegener <sven.wegener@stealer.net>
-+ *
-+ * This program is free software; you can redistribute it and/or modify it
-+ * under the terms of the GNU General Public License version 2 as published by
-+ * the Free Software Foundation.
-+ */
-+
-+/* This modules implements the iptreemap ipset type. It uses bitmaps to
-+ * represent every single IPv4 address as a single bit. The bitmaps are managed
-+ * in a tree structure, where the first three octets of an addresses are used
-+ * as an index to find the bitmap and the last octet is used as the bit number.
-+ */
-+
-+#include <linux/version.h>
-+#include <linux/module.h>
-+#include <linux/ip.h>
-+#include <linux/skbuff.h>
-+#include <linux/slab.h>
-+#include <linux/delay.h>
-+#include <linux/netfilter_ipv4/ip_tables.h>
-+#include <linux/netfilter_ipv4/ip_set.h>
-+#include <linux/errno.h>
-+#include <asm/uaccess.h>
-+#include <asm/bitops.h>
-+#include <linux/spinlock.h>
-+
-+#include <linux/netfilter_ipv4/ip_set_iptreemap.h>
-+
-+#define IPTREEMAP_DEFAULT_GC_TIME (5 * 60)
-+#define IPTREEMAP_DESTROY_SLEEP (100)
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,21)
-+static struct kmem_cache *cachep_b;
-+static struct kmem_cache *cachep_c;
-+static struct kmem_cache *cachep_d;
-+#else
-+static kmem_cache_t *cachep_b;
-+static kmem_cache_t *cachep_c;
-+static kmem_cache_t *cachep_d;
-+#endif
-+
-+static struct ip_set_iptreemap_d *fullbitmap_d;
-+static struct ip_set_iptreemap_c *fullbitmap_c;
-+static struct ip_set_iptreemap_b *fullbitmap_b;
-+
-+#if defined(__LITTLE_ENDIAN)
-+#define ABCD(a, b, c, d, addr) \
-+ do { \
-+ a = ((unsigned char *)addr)[3]; \
-+ b = ((unsigned char *)addr)[2]; \
-+ c = ((unsigned char *)addr)[1]; \
-+ d = ((unsigned char *)addr)[0]; \
-+ } while (0)
-+#elif defined(__BIG_ENDIAN)
-+#define ABCD(a,b,c,d,addrp) do { \
-+ a = ((unsigned char *)addrp)[0]; \
-+ b = ((unsigned char *)addrp)[1]; \
-+ c = ((unsigned char *)addrp)[2]; \
-+ d = ((unsigned char *)addrp)[3]; \
-+} while (0)
-+#else
-+#error "Please fix asm/byteorder.h"
-+#endif /* __LITTLE_ENDIAN */
-+
-+#define TESTIP_WALK(map, elem, branch, full) \
-+ do { \
-+ branch = (map)->tree[elem]; \
-+ if (!branch) \
-+ return 0; \
-+ else if (branch == full) \
-+ return 1; \
-+ } while (0)
-+
-+#define ADDIP_WALK(map, elem, branch, type, cachep, full) \
-+ do { \
-+ branch = (map)->tree[elem]; \
-+ if (!branch) { \
-+ branch = (type *) kmem_cache_alloc(cachep, GFP_ATOMIC); \
-+ if (!branch) \
-+ return -ENOMEM; \
-+ memset(branch, 0, sizeof(*branch)); \
-+ (map)->tree[elem] = branch; \
-+ } else if (branch == full) { \
-+ return -EEXIST; \
-+ } \
-+ } while (0)
-+
-+#define ADDIP_RANGE_LOOP(map, a, a1, a2, hint, branch, full, cachep, free) \
-+ for (a = a1; a <= a2; a++) { \
-+ branch = (map)->tree[a]; \
-+ if (branch != full) { \
-+ if ((a > a1 && a < a2) || (hint)) { \
-+ if (branch) \
-+ free(branch); \
-+ (map)->tree[a] = full; \
-+ continue; \
-+ } else if (!branch) { \
-+ branch = kmem_cache_alloc(cachep, GFP_ATOMIC); \
-+ if (!branch) \
-+ return -ENOMEM; \
-+ memset(branch, 0, sizeof(*branch)); \
-+ (map)->tree[a] = branch; \
-+ }
-+
-+#define ADDIP_RANGE_LOOP_END() \
-+ } \
-+ }
-+
-+#define DELIP_WALK(map, elem, branch, cachep, full, flags) \
-+ do { \
-+ branch = (map)->tree[elem]; \
-+ if (!branch) { \
-+ return -EEXIST; \
-+ } else if (branch == full) { \
-+ branch = kmem_cache_alloc(cachep, flags); \
-+ if (!branch) \
-+ return -ENOMEM; \
-+ memcpy(branch, full, sizeof(*full)); \
-+ (map)->tree[elem] = branch; \
-+ } \
-+ } while (0)
-+
-+#define DELIP_RANGE_LOOP(map, a, a1, a2, hint, branch, full, cachep, free, flags) \
-+ for (a = a1; a <= a2; a++) { \
-+ branch = (map)->tree[a]; \
-+ if (branch) { \
-+ if ((a > a1 && a < a2) || (hint)) { \
-+ if (branch != full) \
-+ free(branch); \
-+ (map)->tree[a] = NULL; \
-+ continue; \
-+ } else if (branch == full) { \
-+ branch = kmem_cache_alloc(cachep, flags); \
-+ if (!branch) \
-+ return -ENOMEM; \
-+ memcpy(branch, full, sizeof(*branch)); \
-+ (map)->tree[a] = branch; \
-+ }
-+
-+#define DELIP_RANGE_LOOP_END() \
-+ } \
-+ }
-+
-+#define LOOP_WALK_BEGIN(map, i, branch) \
-+ for (i = 0; i < 256; i++) { \
-+ branch = (map)->tree[i]; \
-+ if (likely(!branch)) \
-+ continue;
-+
-+#define LOOP_WALK_END() \
-+ }
-+
-+#define LOOP_WALK_BEGIN_GC(map, i, branch, full, cachep, count) \
-+ count = -256; \
-+ for (i = 0; i < 256; i++) { \
-+ branch = (map)->tree[i]; \
-+ if (likely(!branch)) \
-+ continue; \
-+ count++; \
-+ if (branch == full) { \
-+ count++; \
-+ continue; \
-+ }
-+
-+#define LOOP_WALK_END_GC(map, i, branch, full, cachep, count) \
-+ if (-256 == count) { \
-+ kmem_cache_free(cachep, branch); \
-+ (map)->tree[i] = NULL; \
-+ } else if (256 == count) { \
-+ kmem_cache_free(cachep, branch); \
-+ (map)->tree[i] = full; \
-+ } \
-+ }
-+
-+#define LOOP_WALK_BEGIN_COUNT(map, i, branch, inrange, count) \
-+ for (i = 0; i < 256; i++) { \
-+ if (!(map)->tree[i]) { \
-+ if (inrange) { \
-+ count++; \
-+ inrange = 0; \
-+ } \
-+ continue; \
-+ } \
-+ branch = (map)->tree[i];
-+
-+#define LOOP_WALK_END_COUNT() \
-+ }
-+
-+#define MIN(a, b) (a < b ? a : b)
-+#define MAX(a, b) (a > b ? a : b)
-+
-+#define GETVALUE1(a, a1, b1, r) \
-+ (a == a1 ? b1 : r)
-+
-+#define GETVALUE2(a, b, a1, b1, c1, r) \
-+ (a == a1 && b == b1 ? c1 : r)
-+
-+#define GETVALUE3(a, b, c, a1, b1, c1, d1, r) \
-+ (a == a1 && b == b1 && c == c1 ? d1 : r)
-+
-+#define CHECK1(a, a1, a2, b1, b2, c1, c2, d1, d2) \
-+ ( \
-+ GETVALUE1(a, a1, b1, 0) == 0 \
-+ && GETVALUE1(a, a2, b2, 255) == 255 \
-+ && c1 == 0 \
-+ && c2 == 255 \
-+ && d1 == 0 \
-+ && d2 == 255 \
-+ )
-+
-+#define CHECK2(a, b, a1, a2, b1, b2, c1, c2, d1, d2) \
-+ ( \
-+ GETVALUE2(a, b, a1, b1, c1, 0) == 0 \
-+ && GETVALUE2(a, b, a2, b2, c2, 255) == 255 \
-+ && d1 == 0 \
-+ && d2 == 255 \
-+ )
-+
-+#define CHECK3(a, b, c, a1, a2, b1, b2, c1, c2, d1, d2) \
-+ ( \
-+ GETVALUE3(a, b, c, a1, b1, c1, d1, 0) == 0 \
-+ && GETVALUE3(a, b, c, a2, b2, c2, d2, 255) == 255 \
-+ )
-+
-+
-+static inline void
-+free_d(struct ip_set_iptreemap_d *map)
-+{
-+ kmem_cache_free(cachep_d, map);
-+}
-+
-+static inline void
-+free_c(struct ip_set_iptreemap_c *map)
-+{
-+ struct ip_set_iptreemap_d *dtree;
-+ unsigned int i;
-+
-+ LOOP_WALK_BEGIN(map, i, dtree) {
-+ if (dtree != fullbitmap_d)
-+ free_d(dtree);
-+ } LOOP_WALK_END();
-+
-+ kmem_cache_free(cachep_c, map);
-+}
-+
-+static inline void
-+free_b(struct ip_set_iptreemap_b *map)
-+{
-+ struct ip_set_iptreemap_c *ctree;
-+ unsigned int i;
-+
-+ LOOP_WALK_BEGIN(map, i, ctree) {
-+ if (ctree != fullbitmap_c)
-+ free_c(ctree);
-+ } LOOP_WALK_END();
-+
-+ kmem_cache_free(cachep_b, map);
-+}
-+
-+static inline int
-+__testip(struct ip_set *set, ip_set_ip_t ip, ip_set_ip_t *hash_ip)
-+{
-+ struct ip_set_iptreemap *map = (struct ip_set_iptreemap *) set->data;
-+ struct ip_set_iptreemap_b *btree;
-+ struct ip_set_iptreemap_c *ctree;
-+ struct ip_set_iptreemap_d *dtree;
-+ unsigned char a, b, c, d;
-+
-+ *hash_ip = ip;
-+
-+ ABCD(a, b, c, d, hash_ip);
-+
-+ TESTIP_WALK(map, a, btree, fullbitmap_b);
-+ TESTIP_WALK(btree, b, ctree, fullbitmap_c);
-+ TESTIP_WALK(ctree, c, dtree, fullbitmap_d);
-+
-+ return !!test_bit(d, (void *) dtree->bitmap);
-+}
-+
-+static int
-+testip(struct ip_set *set, const void *data, size_t size, ip_set_ip_t *hash_ip)
-+{
-+ struct ip_set_req_iptreemap *req = (struct ip_set_req_iptreemap *) data;
-+
-+ if (size != sizeof(struct ip_set_req_iptreemap)) {
-+ ip_set_printk("data length wrong (want %zu, have %zu)", sizeof(struct ip_set_req_iptreemap), size);
-+ return -EINVAL;
-+ }
-+
-+ return __testip(set, req->start, hash_ip);
-+}
-+
-+static int
-+testip_kernel(struct ip_set *set, const struct sk_buff *skb, ip_set_ip_t *hash_ip, const u_int32_t *flags, unsigned char index)
-+{
-+ int res;
-+
-+ res = __testip(set,
-+ ntohl(flags[index] & IPSET_SRC
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-+ ? ip_hdr(skb)->saddr
-+ : ip_hdr(skb)->daddr),
-+#else
-+ ? skb->nh.iph->saddr
-+ : skb->nh.iph->daddr),
-+#endif
-+ hash_ip);
-+
-+ return (res < 0 ? 0 : res);
-+}
-+
-+static inline int
-+__addip_single(struct ip_set *set, ip_set_ip_t ip, ip_set_ip_t *hash_ip)
-+{
-+ struct ip_set_iptreemap *map = (struct ip_set_iptreemap *) set->data;
-+ struct ip_set_iptreemap_b *btree;
-+ struct ip_set_iptreemap_c *ctree;
-+ struct ip_set_iptreemap_d *dtree;
-+ unsigned char a, b, c, d;
-+
-+ *hash_ip = ip;
-+
-+ ABCD(a, b, c, d, hash_ip);
-+
-+ ADDIP_WALK(map, a, btree, struct ip_set_iptreemap_b, cachep_b, fullbitmap_b);
-+ ADDIP_WALK(btree, b, ctree, struct ip_set_iptreemap_c, cachep_c, fullbitmap_c);
-+ ADDIP_WALK(ctree, c, dtree, struct ip_set_iptreemap_d, cachep_d, fullbitmap_d);
-+
-+ if (test_and_set_bit(d, (void *) dtree->bitmap))
-+ return -EEXIST;
-+
-+ set_bit(b, (void *) btree->dirty);
-+
-+ return 0;
-+}
-+
-+static inline int
-+__addip_range(struct ip_set *set, ip_set_ip_t start, ip_set_ip_t end, ip_set_ip_t *hash_ip)
-+{
-+ struct ip_set_iptreemap *map = (struct ip_set_iptreemap *) set->data;
-+ struct ip_set_iptreemap_b *btree;
-+ struct ip_set_iptreemap_c *ctree;
-+ struct ip_set_iptreemap_d *dtree;
-+ unsigned int a, b, c, d;
-+ unsigned char a1, b1, c1, d1;
-+ unsigned char a2, b2, c2, d2;
-+
-+ if (start == end)
-+ return __addip_single(set, start, hash_ip);
-+
-+ *hash_ip = start;
-+
-+ ABCD(a1, b1, c1, d1, &start);
-+ ABCD(a2, b2, c2, d2, &end);
-+
-+ /* This is sooo ugly... */
-+ ADDIP_RANGE_LOOP(map, a, a1, a2, CHECK1(a, a1, a2, b1, b2, c1, c2, d1, d2), btree, fullbitmap_b, cachep_b, free_b) {
-+ ADDIP_RANGE_LOOP(btree, b, GETVALUE1(a, a1, b1, 0), GETVALUE1(a, a2, b2, 255), CHECK2(a, b, a1, a2, b1, b2, c1, c2, d1, d2), ctree, fullbitmap_c, cachep_c, free_c) {
-+ ADDIP_RANGE_LOOP(ctree, c, GETVALUE2(a, b, a1, b1, c1, 0), GETVALUE2(a, b, a2, b2, c2, 255), CHECK3(a, b, c, a1, a2, b1, b2, c1, c2, d1, d2), dtree, fullbitmap_d, cachep_d, free_d) {
-+ for (d = GETVALUE3(a, b, c, a1, b1, c1, d1, 0); d <= GETVALUE3(a, b, c, a2, b2, c2, d2, 255); d++)
-+ set_bit(d, (void *) dtree->bitmap);
-+ set_bit(b, (void *) btree->dirty);
-+ } ADDIP_RANGE_LOOP_END();
-+ } ADDIP_RANGE_LOOP_END();
-+ } ADDIP_RANGE_LOOP_END();
-+
-+ return 0;
-+}
-+
-+static int
-+addip(struct ip_set *set, const void *data, size_t size, ip_set_ip_t *hash_ip)
-+{
-+ struct ip_set_req_iptreemap *req = (struct ip_set_req_iptreemap *) data;
-+
-+ if (size != sizeof(struct ip_set_req_iptreemap)) {
-+ ip_set_printk("data length wrong (want %zu, have %zu)", sizeof(struct ip_set_req_iptreemap), size);
-+ return -EINVAL;
-+ }
-+
-+ return __addip_range(set, MIN(req->start, req->end), MAX(req->start, req->end), hash_ip);
-+}
-+
-+static int
-+addip_kernel(struct ip_set *set, const struct sk_buff *skb, ip_set_ip_t *hash_ip, const u_int32_t *flags, unsigned char index)
-+{
-+
-+ return __addip_single(set,
-+ ntohl(flags[index] & IPSET_SRC
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-+ ? ip_hdr(skb)->saddr
-+ : ip_hdr(skb)->daddr),
-+#else
-+ ? skb->nh.iph->saddr
-+ : skb->nh.iph->daddr),
-+#endif
-+ hash_ip);
-+}
-+
-+static inline int
-+__delip_single(struct ip_set *set, ip_set_ip_t ip, ip_set_ip_t *hash_ip, unsigned int __nocast flags)
-+{
-+ struct ip_set_iptreemap *map = (struct ip_set_iptreemap *) set->data;
-+ struct ip_set_iptreemap_b *btree;
-+ struct ip_set_iptreemap_c *ctree;
-+ struct ip_set_iptreemap_d *dtree;
-+ unsigned char a,b,c,d;
-+
-+ *hash_ip = ip;
-+
-+ ABCD(a, b, c, d, hash_ip);
-+
-+ DELIP_WALK(map, a, btree, cachep_b, fullbitmap_b, flags);
-+ DELIP_WALK(btree, b, ctree, cachep_c, fullbitmap_c, flags);
-+ DELIP_WALK(ctree, c, dtree, cachep_d, fullbitmap_d, flags);
-+
-+ if (!test_and_clear_bit(d, (void *) dtree->bitmap))
-+ return -EEXIST;
-+
-+ set_bit(b, (void *) btree->dirty);
-+
-+ return 0;
-+}
-+
-+static inline int
-+__delip_range(struct ip_set *set, ip_set_ip_t start, ip_set_ip_t end, ip_set_ip_t *hash_ip, unsigned int __nocast flags)
-+{
-+ struct ip_set_iptreemap *map = (struct ip_set_iptreemap *) set->data;
-+ struct ip_set_iptreemap_b *btree;
-+ struct ip_set_iptreemap_c *ctree;
-+ struct ip_set_iptreemap_d *dtree;
-+ unsigned int a, b, c, d;
-+ unsigned char a1, b1, c1, d1;
-+ unsigned char a2, b2, c2, d2;
-+
-+ if (start == end)
-+ return __delip_single(set, start, hash_ip, flags);
-+
-+ *hash_ip = start;
-+
-+ ABCD(a1, b1, c1, d1, &start);
-+ ABCD(a2, b2, c2, d2, &end);
-+
-+ /* This is sooo ugly... */
-+ DELIP_RANGE_LOOP(map, a, a1, a2, CHECK1(a, a1, a2, b1, b2, c1, c2, d1, d2), btree, fullbitmap_b, cachep_b, free_b, flags) {
-+ DELIP_RANGE_LOOP(btree, b, GETVALUE1(a, a1, b1, 0), GETVALUE1(a, a2, b2, 255), CHECK2(a, b, a1, a2, b1, b2, c1, c2, d1, d2), ctree, fullbitmap_c, cachep_c, free_c, flags) {
-+ DELIP_RANGE_LOOP(ctree, c, GETVALUE2(a, b, a1, b1, c1, 0), GETVALUE2(a, b, a2, b2, c2, 255), CHECK3(a, b, c, a1, a2, b1, b2, c1, c2, d1, d2), dtree, fullbitmap_d, cachep_d, free_d, flags) {
-+ for (d = GETVALUE3(a, b, c, a1, b1, c1, d1, 0); d <= GETVALUE3(a, b, c, a2, b2, c2, d2, 255); d++)
-+ clear_bit(d, (void *) dtree->bitmap);
-+ set_bit(b, (void *) btree->dirty);
-+ } DELIP_RANGE_LOOP_END();
-+ } DELIP_RANGE_LOOP_END();
-+ } DELIP_RANGE_LOOP_END();
-+
-+ return 0;
-+}
-+
-+static int
-+delip(struct ip_set *set, const void *data, size_t size, ip_set_ip_t *hash_ip)
-+{
-+ struct ip_set_req_iptreemap *req = (struct ip_set_req_iptreemap *) data;
-+
-+ if (size != sizeof(struct ip_set_req_iptreemap)) {
-+ ip_set_printk("data length wrong (want %zu, have %zu)", sizeof(struct ip_set_req_iptreemap), size);
-+ return -EINVAL;
-+ }
-+
-+ return __delip_range(set, MIN(req->start, req->end), MAX(req->start, req->end), hash_ip, GFP_KERNEL);
-+}
-+
-+static int
-+delip_kernel(struct ip_set *set, const struct sk_buff *skb, ip_set_ip_t *hash_ip, const u_int32_t *flags, unsigned char index)
-+{
-+ return __delip_single(set,
-+ ntohl(flags[index] & IPSET_SRC
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-+ ? ip_hdr(skb)->saddr
-+ : ip_hdr(skb)->daddr),
-+#else
-+ ? skb->nh.iph->saddr
-+ : skb->nh.iph->daddr),
-+#endif
-+ hash_ip,
-+ GFP_ATOMIC);
-+}
-+
-+/* Check the status of the bitmap
-+ * -1 == all bits cleared
-+ * 1 == all bits set
-+ * 0 == anything else
-+ */
-+static inline int
-+bitmap_status(struct ip_set_iptreemap_d *dtree)
-+{
-+ unsigned char first = dtree->bitmap[0];
-+ int a;
-+
-+ for (a = 1; a < 32; a++)
-+ if (dtree->bitmap[a] != first)
-+ return 0;
-+
-+ return (first == 0 ? -1 : (first == 255 ? 1 : 0));
-+}
-+
-+static void
-+gc(unsigned long addr)
-+{
-+ struct ip_set *set = (struct ip_set *) addr;
-+ struct ip_set_iptreemap *map = (struct ip_set_iptreemap *) set->data;
-+ struct ip_set_iptreemap_b *btree;
-+ struct ip_set_iptreemap_c *ctree;
-+ struct ip_set_iptreemap_d *dtree;
-+ unsigned int a, b, c;
-+ int i, j, k;
-+
-+ write_lock_bh(&set->lock);
-+
-+ LOOP_WALK_BEGIN_GC(map, a, btree, fullbitmap_b, cachep_b, i) {
-+ LOOP_WALK_BEGIN_GC(btree, b, ctree, fullbitmap_c, cachep_c, j) {
-+ if (!test_and_clear_bit(b, (void *) btree->dirty))
-+ continue;
-+ LOOP_WALK_BEGIN_GC(ctree, c, dtree, fullbitmap_d, cachep_d, k) {
-+ switch (bitmap_status(dtree)) {
-+ case -1:
-+ kmem_cache_free(cachep_d, dtree);
-+ ctree->tree[c] = NULL;
-+ k--;
-+ break;
-+ case 1:
-+ kmem_cache_free(cachep_d, dtree);
-+ ctree->tree[c] = fullbitmap_d;
-+ k++;
-+ break;
-+ }
-+ } LOOP_WALK_END();
-+ } LOOP_WALK_END_GC(btree, b, ctree, fullbitmap_c, cachep_c, k);
-+ } LOOP_WALK_END_GC(map, a, btree, fullbitmap_b, cachep_b, j);
-+
-+ write_unlock_bh(&set->lock);
-+
-+ map->gc.expires = jiffies + map->gc_interval * HZ;
-+ add_timer(&map->gc);
-+}
-+
-+static inline void
-+init_gc_timer(struct ip_set *set)
-+{
-+ struct ip_set_iptreemap *map = (struct ip_set_iptreemap *) set->data;
-+
-+ init_timer(&map->gc);
-+ map->gc.data = (unsigned long) set;
-+ map->gc.function = gc;
-+ map->gc.expires = jiffies + map->gc_interval * HZ;
-+ add_timer(&map->gc);
-+}
-+
-+static int create(struct ip_set *set, const void *data, size_t size)
-+{
-+ struct ip_set_req_iptreemap_create *req = (struct ip_set_req_iptreemap_create *) data;
-+ struct ip_set_iptreemap *map;
-+
-+ if (size != sizeof(struct ip_set_req_iptreemap_create)) {
-+ ip_set_printk("data length wrong (want %zu, have %zu)", sizeof(struct ip_set_req_iptreemap_create), size);
-+ return -EINVAL;
-+ }
-+
-+ map = kzalloc(sizeof(*map), GFP_KERNEL);
-+ if (!map)
-+ return -ENOMEM;
-+
-+ map->gc_interval = req->gc_interval ? req->gc_interval : IPTREEMAP_DEFAULT_GC_TIME;
-+ set->data = map;
-+
-+ init_gc_timer(set);
-+
-+ return 0;
-+}
-+
-+static inline void __flush(struct ip_set_iptreemap *map)
-+{
-+ struct ip_set_iptreemap_b *btree;
-+ unsigned int a;
-+
-+ LOOP_WALK_BEGIN(map, a, btree);
-+ if (btree != fullbitmap_b)
-+ free_b(btree);
-+ LOOP_WALK_END();
-+}
-+
-+static void destroy(struct ip_set *set)
-+{
-+ struct ip_set_iptreemap *map = (struct ip_set_iptreemap *) set->data;
-+
-+ while (!del_timer(&map->gc))
-+ msleep(IPTREEMAP_DESTROY_SLEEP);
-+
-+ __flush(map);
-+ kfree(map);
-+
-+ set->data = NULL;
-+}
-+
-+static void flush(struct ip_set *set)
-+{
-+ struct ip_set_iptreemap *map = (struct ip_set_iptreemap *) set->data;
-+
-+ while (!del_timer(&map->gc))
-+ msleep(IPTREEMAP_DESTROY_SLEEP);
-+
-+ __flush(map);
-+
-+ memset(map, 0, sizeof(*map));
-+
-+ init_gc_timer(set);
-+}
-+
-+static void list_header(const struct ip_set *set, void *data)
-+{
-+ struct ip_set_iptreemap *map = (struct ip_set_iptreemap *) set->data;
-+ struct ip_set_req_iptreemap_create *header = (struct ip_set_req_iptreemap_create *) data;
-+
-+ header->gc_interval = map->gc_interval;
-+}
-+
-+static int list_members_size(const struct ip_set *set)
-+{
-+ struct ip_set_iptreemap *map = (struct ip_set_iptreemap *) set->data;
-+ struct ip_set_iptreemap_b *btree;
-+ struct ip_set_iptreemap_c *ctree;
-+ struct ip_set_iptreemap_d *dtree;
-+ unsigned int a, b, c, d, inrange = 0, count = 0;
-+
-+ LOOP_WALK_BEGIN_COUNT(map, a, btree, inrange, count) {
-+ LOOP_WALK_BEGIN_COUNT(btree, b, ctree, inrange, count) {
-+ LOOP_WALK_BEGIN_COUNT(ctree, c, dtree, inrange, count) {
-+ for (d = 0; d < 256; d++) {
-+ if (test_bit(d, (void *) dtree->bitmap)) {
-+ inrange = 1;
-+ } else if (inrange) {
-+ count++;
-+ inrange = 0;
-+ }
-+ }
-+ } LOOP_WALK_END_COUNT();
-+ } LOOP_WALK_END_COUNT();
-+ } LOOP_WALK_END_COUNT();
-+
-+ if (inrange)
-+ count++;
-+
-+ return (count * sizeof(struct ip_set_req_iptreemap));
-+}
-+
-+static inline size_t add_member(void *data, size_t offset, ip_set_ip_t start, ip_set_ip_t end)
-+{
-+ struct ip_set_req_iptreemap *entry = (struct ip_set_req_iptreemap *) (data + offset);
-+
-+ entry->start = start;
-+ entry->end = end;
-+
-+ return sizeof(*entry);
-+}
-+
-+static void list_members(const struct ip_set *set, void *data)
-+{
-+ struct ip_set_iptreemap *map = (struct ip_set_iptreemap *) set->data;
-+ struct ip_set_iptreemap_b *btree;
-+ struct ip_set_iptreemap_c *ctree;
-+ struct ip_set_iptreemap_d *dtree;
-+ unsigned int a, b, c, d, inrange = 0;
-+ size_t offset = 0;
-+ ip_set_ip_t start = 0, end = 0, ip;
-+
-+ LOOP_WALK_BEGIN(map, a, btree) {
-+ LOOP_WALK_BEGIN(btree, b, ctree) {
-+ LOOP_WALK_BEGIN(ctree, c, dtree) {
-+ for (d = 0; d < 256; d++) {
-+ if (test_bit(d, (void *) dtree->bitmap)) {
-+ ip = ((a << 24) | (b << 16) | (c << 8) | d);
-+ if (!inrange) {
-+ inrange = 1;
-+ start = ip;
-+ } else if (end < ip - 1) {
-+ offset += add_member(data, offset, start, end);
-+ start = ip;
-+ }
-+ end = ip;
-+ } else if (inrange) {
-+ offset += add_member(data, offset, start, end);
-+ inrange = 0;
-+ }
-+ }
-+ } LOOP_WALK_END();
-+ } LOOP_WALK_END();
-+ } LOOP_WALK_END();
-+
-+ if (inrange)
-+ add_member(data, offset, start, end);
-+}
-+
-+static struct ip_set_type ip_set_iptreemap = {
-+ .typename = SETTYPE_NAME,
-+ .features = IPSET_TYPE_IP | IPSET_DATA_SINGLE,
-+ .protocol_version = IP_SET_PROTOCOL_VERSION,
-+ .create = create,
-+ .destroy = destroy,
-+ .flush = flush,
-+ .reqsize = sizeof(struct ip_set_req_iptreemap),
-+ .addip = addip,
-+ .addip_kernel = addip_kernel,
-+ .delip = delip,
-+ .delip_kernel = delip_kernel,
-+ .testip = testip,
-+ .testip_kernel = testip_kernel,
-+ .header_size = sizeof(struct ip_set_req_iptreemap_create),
-+ .list_header = list_header,
-+ .list_members_size = list_members_size,
-+ .list_members = list_members,
-+ .me = THIS_MODULE,
-+};
-+
-+MODULE_LICENSE("GPL");
-+MODULE_AUTHOR("Sven Wegener <sven.wegener@stealer.net>");
-+MODULE_DESCRIPTION("iptreemap type of IP sets");
-+
-+static int __init ip_set_iptreemap_init(void)
-+{
-+ int ret = -ENOMEM;
-+ int a;
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,23)
-+ cachep_b = kmem_cache_create("ip_set_iptreemap_b",
-+ sizeof(struct ip_set_iptreemap_b),
-+ 0, 0, NULL);
-+#else
-+ cachep_b = kmem_cache_create("ip_set_iptreemap_b",
-+ sizeof(struct ip_set_iptreemap_b),
-+ 0, 0, NULL, NULL);
-+#endif
-+ if (!cachep_b) {
-+ ip_set_printk("Unable to create ip_set_iptreemap_b slab cache");
-+ goto out;
-+ }
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,23)
-+ cachep_c = kmem_cache_create("ip_set_iptreemap_c",
-+ sizeof(struct ip_set_iptreemap_c),
-+ 0, 0, NULL);
-+#else
-+ cachep_c = kmem_cache_create("ip_set_iptreemap_c",
-+ sizeof(struct ip_set_iptreemap_c),
-+ 0, 0, NULL, NULL);
-+#endif
-+ if (!cachep_c) {
-+ ip_set_printk("Unable to create ip_set_iptreemap_c slab cache");
-+ goto outb;
-+ }
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,23)
-+ cachep_d = kmem_cache_create("ip_set_iptreemap_d",
-+ sizeof(struct ip_set_iptreemap_d),
-+ 0, 0, NULL);
-+#else
-+ cachep_d = kmem_cache_create("ip_set_iptreemap_d",
-+ sizeof(struct ip_set_iptreemap_d),
-+ 0, 0, NULL, NULL);
-+#endif
-+ if (!cachep_d) {
-+ ip_set_printk("Unable to create ip_set_iptreemap_d slab cache");
-+ goto outc;
-+ }
-+
-+ fullbitmap_d = kmem_cache_alloc(cachep_d, GFP_KERNEL);
-+ if (!fullbitmap_d)
-+ goto outd;
-+
-+ fullbitmap_c = kmem_cache_alloc(cachep_c, GFP_KERNEL);
-+ if (!fullbitmap_c)
-+ goto outbitmapd;
-+
-+ fullbitmap_b = kmem_cache_alloc(cachep_b, GFP_KERNEL);
-+ if (!fullbitmap_b)
-+ goto outbitmapc;
-+
-+ ret = ip_set_register_set_type(&ip_set_iptreemap);
-+ if (0 > ret)
-+ goto outbitmapb;
-+
-+ /* Now init our global bitmaps */
-+ memset(fullbitmap_d->bitmap, 0xff, sizeof(fullbitmap_d->bitmap));
-+
-+ for (a = 0; a < 256; a++)
-+ fullbitmap_c->tree[a] = fullbitmap_d;
-+
-+ for (a = 0; a < 256; a++)
-+ fullbitmap_b->tree[a] = fullbitmap_c;
-+ memset(fullbitmap_b->dirty, 0, sizeof(fullbitmap_b->dirty));
-+
-+ return 0;
-+
-+outbitmapb:
-+ kmem_cache_free(cachep_b, fullbitmap_b);
-+outbitmapc:
-+ kmem_cache_free(cachep_c, fullbitmap_c);
-+outbitmapd:
-+ kmem_cache_free(cachep_d, fullbitmap_d);
-+outd:
-+ kmem_cache_destroy(cachep_d);
-+outc:
-+ kmem_cache_destroy(cachep_c);
-+outb:
-+ kmem_cache_destroy(cachep_b);
-+out:
-+
-+ return ret;
-+}
-+
-+static void __exit ip_set_iptreemap_fini(void)
-+{
-+ ip_set_unregister_set_type(&ip_set_iptreemap);
-+ kmem_cache_free(cachep_d, fullbitmap_d);
-+ kmem_cache_free(cachep_c, fullbitmap_c);
-+ kmem_cache_free(cachep_b, fullbitmap_b);
-+ kmem_cache_destroy(cachep_d);
-+ kmem_cache_destroy(cachep_c);
-+ kmem_cache_destroy(cachep_b);
-+}
-+
-+module_init(ip_set_iptreemap_init);
-+module_exit(ip_set_iptreemap_fini);
---- /dev/null
-+++ b/net/ipv4/netfilter/ip_set_macipmap.c
-@@ -0,0 +1,375 @@
-+/* Copyright (C) 2000-2002 Joakim Axelsson <gozem@linux.nu>
-+ * Patrick Schaaf <bof@bof.de>
-+ * Martin Josefsson <gandalf@wlug.westbo.se>
-+ * Copyright (C) 2003-2004 Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
-+ *
-+ * This program is free software; you can redistribute it and/or modify
-+ * it under the terms of the GNU General Public License version 2 as
-+ * published by the Free Software Foundation.
-+ */
-+
-+/* Kernel module implementing an IP set type: the macipmap type */
-+
-+#include <linux/module.h>
-+#include <linux/ip.h>
-+#include <linux/skbuff.h>
-+#include <linux/version.h>
-+#include <linux/netfilter_ipv4/ip_tables.h>
-+#include <linux/netfilter_ipv4/ip_set.h>
-+#include <linux/errno.h>
-+#include <asm/uaccess.h>
-+#include <asm/bitops.h>
-+#include <linux/spinlock.h>
-+#include <linux/if_ether.h>
-+#include <linux/vmalloc.h>
-+
-+#include <linux/netfilter_ipv4/ip_set_malloc.h>
-+#include <linux/netfilter_ipv4/ip_set_macipmap.h>
-+
-+static int
-+testip(struct ip_set *set, const void *data, size_t size, ip_set_ip_t *hash_ip)
-+{
-+ struct ip_set_macipmap *map = (struct ip_set_macipmap *) set->data;
-+ struct ip_set_macip *table = (struct ip_set_macip *) map->members;
-+ struct ip_set_req_macipmap *req = (struct ip_set_req_macipmap *) data;
-+
-+ if (size != sizeof(struct ip_set_req_macipmap)) {
-+ ip_set_printk("data length wrong (want %zu, have %zu)",
-+ sizeof(struct ip_set_req_macipmap),
-+ size);
-+ return -EINVAL;
-+ }
-+
-+ if (req->ip < map->first_ip || req->ip > map->last_ip)
-+ return -ERANGE;
-+
-+ *hash_ip = req->ip;
-+ DP("set: %s, ip:%u.%u.%u.%u, %u.%u.%u.%u",
-+ set->name, HIPQUAD(req->ip), HIPQUAD(*hash_ip));
-+ if (test_bit(IPSET_MACIP_ISSET,
-+ (void *) &table[req->ip - map->first_ip].flags)) {
-+ return (memcmp(req->ethernet,
-+ &table[req->ip - map->first_ip].ethernet,
-+ ETH_ALEN) == 0);
-+ } else {
-+ return (map->flags & IPSET_MACIP_MATCHUNSET ? 1 : 0);
-+ }
-+}
-+
-+static int
-+testip_kernel(struct ip_set *set,
-+ const struct sk_buff *skb,
-+ ip_set_ip_t *hash_ip,
-+ const u_int32_t *flags,
-+ unsigned char index)
-+{
-+ struct ip_set_macipmap *map =
-+ (struct ip_set_macipmap *) set->data;
-+ struct ip_set_macip *table =
-+ (struct ip_set_macip *) map->members;
-+ ip_set_ip_t ip;
-+
-+ ip = ntohl(flags[index] & IPSET_SRC
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-+ ? ip_hdr(skb)->saddr
-+ : ip_hdr(skb)->daddr);
-+#else
-+ ? skb->nh.iph->saddr
-+ : skb->nh.iph->daddr);
-+#endif
-+
-+ if (ip < map->first_ip || ip > map->last_ip)
-+ return 0;
-+
-+ *hash_ip = ip;
-+ DP("set: %s, ip:%u.%u.%u.%u, %u.%u.%u.%u",
-+ set->name, HIPQUAD(ip), HIPQUAD(*hash_ip));
-+ if (test_bit(IPSET_MACIP_ISSET,
-+ (void *) &table[ip - map->first_ip].flags)) {
-+ /* Is mac pointer valid?
-+ * If so, compare... */
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-+ return (skb_mac_header(skb) >= skb->head
-+ && (skb_mac_header(skb) + ETH_HLEN) <= skb->data
-+#else
-+ return (skb->mac.raw >= skb->head
-+ && (skb->mac.raw + ETH_HLEN) <= skb->data
-+#endif
-+ && (memcmp(eth_hdr(skb)->h_source,
-+ &table[ip - map->first_ip].ethernet,
-+ ETH_ALEN) == 0));
-+ } else {
-+ return (map->flags & IPSET_MACIP_MATCHUNSET ? 1 : 0);
-+ }
-+}
-+
-+/* returns 0 on success */
-+static inline int
-+__addip(struct ip_set *set,
-+ ip_set_ip_t ip, unsigned char *ethernet, ip_set_ip_t *hash_ip)
-+{
-+ struct ip_set_macipmap *map =
-+ (struct ip_set_macipmap *) set->data;
-+ struct ip_set_macip *table =
-+ (struct ip_set_macip *) map->members;
-+
-+ if (ip < map->first_ip || ip > map->last_ip)
-+ return -ERANGE;
-+ if (test_and_set_bit(IPSET_MACIP_ISSET,
-+ (void *) &table[ip - map->first_ip].flags))
-+ return -EEXIST;
-+
-+ *hash_ip = ip;
-+ DP("%u.%u.%u.%u, %u.%u.%u.%u", HIPQUAD(ip), HIPQUAD(*hash_ip));
-+ memcpy(&table[ip - map->first_ip].ethernet, ethernet, ETH_ALEN);
-+ return 0;
-+}
-+
-+static int
-+addip(struct ip_set *set, const void *data, size_t size,
-+ ip_set_ip_t *hash_ip)
-+{
-+ struct ip_set_req_macipmap *req =
-+ (struct ip_set_req_macipmap *) data;
-+
-+ if (size != sizeof(struct ip_set_req_macipmap)) {
-+ ip_set_printk("data length wrong (want %zu, have %zu)",
-+ sizeof(struct ip_set_req_macipmap),
-+ size);
-+ return -EINVAL;
-+ }
-+ return __addip(set, req->ip, req->ethernet, hash_ip);
-+}
-+
-+static int
-+addip_kernel(struct ip_set *set,
-+ const struct sk_buff *skb,
-+ ip_set_ip_t *hash_ip,
-+ const u_int32_t *flags,
-+ unsigned char index)
-+{
-+ ip_set_ip_t ip;
-+
-+ ip = ntohl(flags[index] & IPSET_SRC
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-+ ? ip_hdr(skb)->saddr
-+ : ip_hdr(skb)->daddr);
-+#else
-+ ? skb->nh.iph->saddr
-+ : skb->nh.iph->daddr);
-+#endif
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-+ if (!(skb_mac_header(skb) >= skb->head
-+ && (skb_mac_header(skb) + ETH_HLEN) <= skb->data))
-+#else
-+ if (!(skb->mac.raw >= skb->head
-+ && (skb->mac.raw + ETH_HLEN) <= skb->data))
-+#endif
-+ return -EINVAL;
-+
-+ return __addip(set, ip, eth_hdr(skb)->h_source, hash_ip);
-+}
-+
-+static inline int
-+__delip(struct ip_set *set, ip_set_ip_t ip, ip_set_ip_t *hash_ip)
-+{
-+ struct ip_set_macipmap *map =
-+ (struct ip_set_macipmap *) set->data;
-+ struct ip_set_macip *table =
-+ (struct ip_set_macip *) map->members;
-+
-+ if (ip < map->first_ip || ip > map->last_ip)
-+ return -ERANGE;
-+ if (!test_and_clear_bit(IPSET_MACIP_ISSET,
-+ (void *)&table[ip - map->first_ip].flags))
-+ return -EEXIST;
-+
-+ *hash_ip = ip;
-+ DP("%u.%u.%u.%u, %u.%u.%u.%u", HIPQUAD(ip), HIPQUAD(*hash_ip));
-+ return 0;
-+}
-+
-+static int
-+delip(struct ip_set *set, const void *data, size_t size,
-+ ip_set_ip_t *hash_ip)
-+{
-+ struct ip_set_req_macipmap *req =
-+ (struct ip_set_req_macipmap *) data;
-+
-+ if (size != sizeof(struct ip_set_req_macipmap)) {
-+ ip_set_printk("data length wrong (want %zu, have %zu)",
-+ sizeof(struct ip_set_req_macipmap),
-+ size);
-+ return -EINVAL;
-+ }
-+ return __delip(set, req->ip, hash_ip);
-+}
-+
-+static int
-+delip_kernel(struct ip_set *set,
-+ const struct sk_buff *skb,
-+ ip_set_ip_t *hash_ip,
-+ const u_int32_t *flags,
-+ unsigned char index)
-+{
-+ return __delip(set,
-+ ntohl(flags[index] & IPSET_SRC
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-+ ? ip_hdr(skb)->saddr
-+ : ip_hdr(skb)->daddr),
-+#else
-+ ? skb->nh.iph->saddr
-+ : skb->nh.iph->daddr),
-+#endif
-+ hash_ip);
-+}
-+
-+static inline size_t members_size(ip_set_id_t from, ip_set_id_t to)
-+{
-+ return (size_t)((to - from + 1) * sizeof(struct ip_set_macip));
-+}
-+
-+static int create(struct ip_set *set, const void *data, size_t size)
-+{
-+ int newbytes;
-+ struct ip_set_req_macipmap_create *req =
-+ (struct ip_set_req_macipmap_create *) data;
-+ struct ip_set_macipmap *map;
-+
-+ if (size != sizeof(struct ip_set_req_macipmap_create)) {
-+ ip_set_printk("data length wrong (want %zu, have %zu)",
-+ sizeof(struct ip_set_req_macipmap_create),
-+ size);
-+ return -EINVAL;
-+ }
-+
-+ DP("from %u.%u.%u.%u to %u.%u.%u.%u",
-+ HIPQUAD(req->from), HIPQUAD(req->to));
-+
-+ if (req->from > req->to) {
-+ DP("bad ip range");
-+ return -ENOEXEC;
-+ }
-+
-+ if (req->to - req->from > MAX_RANGE) {
-+ ip_set_printk("range too big (max %d addresses)",
-+ MAX_RANGE+1);
-+ return -ENOEXEC;
-+ }
-+
-+ map = kmalloc(sizeof(struct ip_set_macipmap), GFP_KERNEL);
-+ if (!map) {
-+ DP("out of memory for %d bytes",
-+ sizeof(struct ip_set_macipmap));
-+ return -ENOMEM;
-+ }
-+ map->flags = req->flags;
-+ map->first_ip = req->from;
-+ map->last_ip = req->to;
-+ newbytes = members_size(map->first_ip, map->last_ip);
-+ map->members = ip_set_malloc(newbytes);
-+ DP("members: %u %p", newbytes, map->members);
-+ if (!map->members) {
-+ DP("out of memory for %d bytes", newbytes);
-+ kfree(map);
-+ return -ENOMEM;
-+ }
-+ memset(map->members, 0, newbytes);
-+
-+ set->data = map;
-+ return 0;
-+}
-+
-+static void destroy(struct ip_set *set)
-+{
-+ struct ip_set_macipmap *map =
-+ (struct ip_set_macipmap *) set->data;
-+
-+ ip_set_free(map->members, members_size(map->first_ip, map->last_ip));
-+ kfree(map);
-+
-+ set->data = NULL;
-+}
-+
-+static void flush(struct ip_set *set)
-+{
-+ struct ip_set_macipmap *map =
-+ (struct ip_set_macipmap *) set->data;
-+ memset(map->members, 0, members_size(map->first_ip, map->last_ip));
-+}
-+
-+static void list_header(const struct ip_set *set, void *data)
-+{
-+ struct ip_set_macipmap *map =
-+ (struct ip_set_macipmap *) set->data;
-+ struct ip_set_req_macipmap_create *header =
-+ (struct ip_set_req_macipmap_create *) data;
-+
-+ DP("list_header %x %x %u", map->first_ip, map->last_ip,
-+ map->flags);
-+
-+ header->from = map->first_ip;
-+ header->to = map->last_ip;
-+ header->flags = map->flags;
-+}
-+
-+static int list_members_size(const struct ip_set *set)
-+{
-+ struct ip_set_macipmap *map =
-+ (struct ip_set_macipmap *) set->data;
-+
-+ DP("%u", members_size(map->first_ip, map->last_ip));
-+ return members_size(map->first_ip, map->last_ip);
-+}
-+
-+static void list_members(const struct ip_set *set, void *data)
-+{
-+ struct ip_set_macipmap *map =
-+ (struct ip_set_macipmap *) set->data;
-+
-+ int bytes = members_size(map->first_ip, map->last_ip);
-+
-+ DP("members: %u %p", bytes, map->members);
-+ memcpy(data, map->members, bytes);
-+}
-+
-+static struct ip_set_type ip_set_macipmap = {
-+ .typename = SETTYPE_NAME,
-+ .features = IPSET_TYPE_IP | IPSET_DATA_SINGLE,
-+ .protocol_version = IP_SET_PROTOCOL_VERSION,
-+ .create = &create,
-+ .destroy = &destroy,
-+ .flush = &flush,
-+ .reqsize = sizeof(struct ip_set_req_macipmap),
-+ .addip = &addip,
-+ .addip_kernel = &addip_kernel,
-+ .delip = &delip,
-+ .delip_kernel = &delip_kernel,
-+ .testip = &testip,
-+ .testip_kernel = &testip_kernel,
-+ .header_size = sizeof(struct ip_set_req_macipmap_create),
-+ .list_header = &list_header,
-+ .list_members_size = &list_members_size,
-+ .list_members = &list_members,
-+ .me = THIS_MODULE,
-+};
-+
-+MODULE_LICENSE("GPL");
-+MODULE_AUTHOR("Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>");
-+MODULE_DESCRIPTION("macipmap type of IP sets");
-+
-+static int __init ip_set_macipmap_init(void)
-+{
-+ init_max_malloc_size();
-+ return ip_set_register_set_type(&ip_set_macipmap);
-+}
-+
-+static void __exit ip_set_macipmap_fini(void)
-+{
-+ /* FIXME: possible race with ip_set_create() */
-+ ip_set_unregister_set_type(&ip_set_macipmap);
-+}
-+
-+module_init(ip_set_macipmap_init);
-+module_exit(ip_set_macipmap_fini);
---- /dev/null
-+++ b/net/ipv4/netfilter/ip_set_nethash.c
-@@ -0,0 +1,497 @@
-+/* Copyright (C) 2003-2004 Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
-+ *
-+ * This program is free software; you can redistribute it and/or modify
-+ * it under the terms of the GNU General Public License version 2 as
-+ * published by the Free Software Foundation.
-+ */
-+
-+/* Kernel module implementing a cidr nethash set */
-+
-+#include <linux/module.h>
-+#include <linux/ip.h>
-+#include <linux/skbuff.h>
-+#include <linux/version.h>
-+#include <linux/jhash.h>
-+#include <linux/netfilter_ipv4/ip_tables.h>
-+#include <linux/netfilter_ipv4/ip_set.h>
-+#include <linux/errno.h>
-+#include <asm/uaccess.h>
-+#include <asm/bitops.h>
-+#include <linux/spinlock.h>
-+#include <linux/vmalloc.h>
-+#include <linux/random.h>
-+
-+#include <net/ip.h>
-+
-+#include <linux/netfilter_ipv4/ip_set_malloc.h>
-+#include <linux/netfilter_ipv4/ip_set_nethash.h>
-+
-+static int limit = MAX_RANGE;
-+
-+static inline __u32
-+jhash_ip(const struct ip_set_nethash *map, uint16_t i, ip_set_ip_t ip)
-+{
-+ return jhash_1word(ip, *(((uint32_t *) map->initval) + i));
-+}
-+
-+static inline __u32
-+hash_id_cidr(struct ip_set_nethash *map,
-+ ip_set_ip_t ip,
-+ unsigned char cidr,
-+ ip_set_ip_t *hash_ip)
-+{
-+ __u32 id;
-+ u_int16_t i;
-+ ip_set_ip_t *elem;
-+
-+ *hash_ip = pack(ip, cidr);
-+
-+ for (i = 0; i < map->probes; i++) {
-+ id = jhash_ip(map, i, *hash_ip) % map->hashsize;
-+ DP("hash key: %u", id);
-+ elem = HARRAY_ELEM(map->members, ip_set_ip_t *, id);
-+ if (*elem == *hash_ip)
-+ return id;
-+ }
-+ return UINT_MAX;
-+}
-+
-+static inline __u32
-+hash_id(struct ip_set *set, ip_set_ip_t ip, ip_set_ip_t *hash_ip)
-+{
-+ struct ip_set_nethash *map = (struct ip_set_nethash *) set->data;
-+ __u32 id = UINT_MAX;
-+ int i;
-+
-+ for (i = 0; i < 30 && map->cidr[i]; i++) {
-+ id = hash_id_cidr(map, ip, map->cidr[i], hash_ip);
-+ if (id != UINT_MAX)
-+ break;
-+ }
-+ return id;
-+}
-+
-+static inline int
-+__testip_cidr(struct ip_set *set, ip_set_ip_t ip, unsigned char cidr,
-+ ip_set_ip_t *hash_ip)
-+{
-+ struct ip_set_nethash *map = (struct ip_set_nethash *) set->data;
-+
-+ return (ip && hash_id_cidr(map, ip, cidr, hash_ip) != UINT_MAX);
-+}
-+
-+static inline int
-+__testip(struct ip_set *set, ip_set_ip_t ip, ip_set_ip_t *hash_ip)
-+{
-+ return (ip && hash_id(set, ip, hash_ip) != UINT_MAX);
-+}
-+
-+static int
-+testip(struct ip_set *set, const void *data, size_t size,
-+ ip_set_ip_t *hash_ip)
-+{
-+ struct ip_set_req_nethash *req =
-+ (struct ip_set_req_nethash *) data;
-+
-+ if (size != sizeof(struct ip_set_req_nethash)) {
-+ ip_set_printk("data length wrong (want %zu, have %zu)",
-+ sizeof(struct ip_set_req_nethash),
-+ size);
-+ return -EINVAL;
-+ }
-+ return (req->cidr == 32 ? __testip(set, req->ip, hash_ip)
-+ : __testip_cidr(set, req->ip, req->cidr, hash_ip));
-+}
-+
-+static int
-+testip_kernel(struct ip_set *set,
-+ const struct sk_buff *skb,
-+ ip_set_ip_t *hash_ip,
-+ const u_int32_t *flags,
-+ unsigned char index)
-+{
-+ return __testip(set,
-+ ntohl(flags[index] & IPSET_SRC
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-+ ? ip_hdr(skb)->saddr
-+ : ip_hdr(skb)->daddr),
-+#else
-+ ? skb->nh.iph->saddr
-+ : skb->nh.iph->daddr),
-+#endif
-+ hash_ip);
-+}
-+
-+static inline int
-+__addip_base(struct ip_set_nethash *map, ip_set_ip_t ip)
-+{
-+ __u32 probe;
-+ u_int16_t i;
-+ ip_set_ip_t *elem;
-+
-+ for (i = 0; i < map->probes; i++) {
-+ probe = jhash_ip(map, i, ip) % map->hashsize;
-+ elem = HARRAY_ELEM(map->members, ip_set_ip_t *, probe);
-+ if (*elem == ip)
-+ return -EEXIST;
-+ if (!*elem) {
-+ *elem = ip;
-+ map->elements++;
-+ return 0;
-+ }
-+ }
-+ /* Trigger rehashing */
-+ return -EAGAIN;
-+}
-+
-+static inline int
-+__addip(struct ip_set_nethash *map, ip_set_ip_t ip, unsigned char cidr,
-+ ip_set_ip_t *hash_ip)
-+{
-+ if (!ip || map->elements >= limit)
-+ return -ERANGE;
-+
-+ *hash_ip = pack(ip, cidr);
-+ DP("%u.%u.%u.%u/%u, %u.%u.%u.%u", HIPQUAD(ip), cidr, HIPQUAD(*hash_ip));
-+
-+ return __addip_base(map, *hash_ip);
-+}
-+
-+static void
-+update_cidr_sizes(struct ip_set_nethash *map, unsigned char cidr)
-+{
-+ unsigned char next;
-+ int i;
-+
-+ for (i = 0; i < 30 && map->cidr[i]; i++) {
-+ if (map->cidr[i] == cidr) {
-+ return;
-+ } else if (map->cidr[i] < cidr) {
-+ next = map->cidr[i];
-+ map->cidr[i] = cidr;
-+ cidr = next;
-+ }
-+ }
-+ if (i < 30)
-+ map->cidr[i] = cidr;
-+}
-+
-+static int
-+addip(struct ip_set *set, const void *data, size_t size,
-+ ip_set_ip_t *hash_ip)
-+{
-+ struct ip_set_req_nethash *req =
-+ (struct ip_set_req_nethash *) data;
-+ int ret;
-+
-+ if (size != sizeof(struct ip_set_req_nethash)) {
-+ ip_set_printk("data length wrong (want %zu, have %zu)",
-+ sizeof(struct ip_set_req_nethash),
-+ size);
-+ return -EINVAL;
-+ }
-+ ret = __addip((struct ip_set_nethash *) set->data,
-+ req->ip, req->cidr, hash_ip);
-+
-+ if (ret == 0)
-+ update_cidr_sizes((struct ip_set_nethash *) set->data,
-+ req->cidr);
-+
-+ return ret;
-+}
-+
-+static int
-+addip_kernel(struct ip_set *set,
-+ const struct sk_buff *skb,
-+ ip_set_ip_t *hash_ip,
-+ const u_int32_t *flags,
-+ unsigned char index)
-+{
-+ struct ip_set_nethash *map = (struct ip_set_nethash *) set->data;
-+ int ret = -ERANGE;
-+ ip_set_ip_t ip = ntohl(flags[index] & IPSET_SRC
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-+ ? ip_hdr(skb)->saddr
-+ : ip_hdr(skb)->daddr);
-+#else
-+ ? skb->nh.iph->saddr
-+ : skb->nh.iph->daddr);
-+#endif
-+
-+ if (map->cidr[0])
-+ ret = __addip(map, ip, map->cidr[0], hash_ip);
-+
-+ return ret;
-+}
-+
-+static int retry(struct ip_set *set)
-+{
-+ struct ip_set_nethash *map = (struct ip_set_nethash *) set->data;
-+ ip_set_ip_t *elem;
-+ void *members;
-+ u_int32_t i, hashsize = map->hashsize;
-+ int res;
-+ struct ip_set_nethash *tmp;
-+
-+ if (map->resize == 0)
-+ return -ERANGE;
-+
-+ again:
-+ res = 0;
-+
-+ /* Calculate new parameters */
-+ hashsize += (hashsize * map->resize)/100;
-+ if (hashsize == map->hashsize)
-+ hashsize++;
-+
-+ ip_set_printk("rehashing of set %s triggered: "
-+ "hashsize grows from %u to %u",
-+ set->name, map->hashsize, hashsize);
-+
-+ tmp = kmalloc(sizeof(struct ip_set_nethash)
-+ + map->probes * sizeof(uint32_t), GFP_ATOMIC);
-+ if (!tmp) {
-+ DP("out of memory for %d bytes",
-+ sizeof(struct ip_set_nethash)
-+ + map->probes * sizeof(uint32_t));
-+ return -ENOMEM;
-+ }
-+ tmp->members = harray_malloc(hashsize, sizeof(ip_set_ip_t), GFP_ATOMIC);
-+ if (!tmp->members) {
-+ DP("out of memory for %d bytes", hashsize * sizeof(ip_set_ip_t));
-+ kfree(tmp);
-+ return -ENOMEM;
-+ }
-+ tmp->hashsize = hashsize;
-+ tmp->elements = 0;
-+ tmp->probes = map->probes;
-+ tmp->resize = map->resize;
-+ memcpy(tmp->initval, map->initval, map->probes * sizeof(uint32_t));
-+ memcpy(tmp->cidr, map->cidr, 30 * sizeof(unsigned char));
-+
-+ write_lock_bh(&set->lock);
-+ map = (struct ip_set_nethash *) set->data; /* Play safe */
-+ for (i = 0; i < map->hashsize && res == 0; i++) {
-+ elem = HARRAY_ELEM(map->members, ip_set_ip_t *, i);
-+ if (*elem)
-+ res = __addip_base(tmp, *elem);
-+ }
-+ if (res) {
-+ /* Failure, try again */
-+ write_unlock_bh(&set->lock);
-+ harray_free(tmp->members);
-+ kfree(tmp);
-+ goto again;
-+ }
-+
-+ /* Success at resizing! */
-+ members = map->members;
-+
-+ map->hashsize = tmp->hashsize;
-+ map->members = tmp->members;
-+ write_unlock_bh(&set->lock);
-+
-+ harray_free(members);
-+ kfree(tmp);
-+
-+ return 0;
-+}
-+
-+static inline int
-+__delip(struct ip_set_nethash *map, ip_set_ip_t ip, unsigned char cidr,
-+ ip_set_ip_t *hash_ip)
-+{
-+ ip_set_ip_t id, *elem;
-+
-+ if (!ip)
-+ return -ERANGE;
-+
-+ id = hash_id_cidr(map, ip, cidr, hash_ip);
-+ if (id == UINT_MAX)
-+ return -EEXIST;
-+
-+ elem = HARRAY_ELEM(map->members, ip_set_ip_t *, id);
-+ *elem = 0;
-+ map->elements--;
-+ return 0;
-+}
-+
-+static int
-+delip(struct ip_set *set, const void *data, size_t size,
-+ ip_set_ip_t *hash_ip)
-+{
-+ struct ip_set_req_nethash *req =
-+ (struct ip_set_req_nethash *) data;
-+
-+ if (size != sizeof(struct ip_set_req_nethash)) {
-+ ip_set_printk("data length wrong (want %zu, have %zu)",
-+ sizeof(struct ip_set_req_nethash),
-+ size);
-+ return -EINVAL;
-+ }
-+ /* TODO: no garbage collection in map->cidr */
-+ return __delip((struct ip_set_nethash *) set->data,
-+ req->ip, req->cidr, hash_ip);
-+}
-+
-+static int
-+delip_kernel(struct ip_set *set,
-+ const struct sk_buff *skb,
-+ ip_set_ip_t *hash_ip,
-+ const u_int32_t *flags,
-+ unsigned char index)
-+{
-+ struct ip_set_nethash *map = (struct ip_set_nethash *) set->data;
-+ int ret = -ERANGE;
-+ ip_set_ip_t ip = ntohl(flags[index] & IPSET_SRC
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-+ ? ip_hdr(skb)->saddr
-+ : ip_hdr(skb)->daddr);
-+#else
-+ ? skb->nh.iph->saddr
-+ : skb->nh.iph->daddr);
-+#endif
-+
-+ if (map->cidr[0])
-+ ret = __delip(map, ip, map->cidr[0], hash_ip);
-+
-+ return ret;
-+}
-+
-+static int create(struct ip_set *set, const void *data, size_t size)
-+{
-+ struct ip_set_req_nethash_create *req =
-+ (struct ip_set_req_nethash_create *) data;
-+ struct ip_set_nethash *map;
-+ uint16_t i;
-+
-+ if (size != sizeof(struct ip_set_req_nethash_create)) {
-+ ip_set_printk("data length wrong (want %zu, have %zu)",
-+ sizeof(struct ip_set_req_nethash_create),
-+ size);
-+ return -EINVAL;
-+ }
-+
-+ if (req->hashsize < 1) {
-+ ip_set_printk("hashsize too small");
-+ return -ENOEXEC;
-+ }
-+ if (req->probes < 1) {
-+ ip_set_printk("probes too small");
-+ return -ENOEXEC;
-+ }
-+
-+ map = kmalloc(sizeof(struct ip_set_nethash)
-+ + req->probes * sizeof(uint32_t), GFP_KERNEL);
-+ if (!map) {
-+ DP("out of memory for %d bytes",
-+ sizeof(struct ip_set_nethash)
-+ + req->probes * sizeof(uint32_t));
-+ return -ENOMEM;
-+ }
-+ for (i = 0; i < req->probes; i++)
-+ get_random_bytes(((uint32_t *) map->initval)+i, 4);
-+ map->elements = 0;
-+ map->hashsize = req->hashsize;
-+ map->probes = req->probes;
-+ map->resize = req->resize;
-+ memset(map->cidr, 0, 30 * sizeof(unsigned char));
-+ map->members = harray_malloc(map->hashsize, sizeof(ip_set_ip_t), GFP_KERNEL);
-+ if (!map->members) {
-+ DP("out of memory for %d bytes", map->hashsize * sizeof(ip_set_ip_t));
-+ kfree(map);
-+ return -ENOMEM;
-+ }
-+
-+ set->data = map;
-+ return 0;
-+}
-+
-+static void destroy(struct ip_set *set)
-+{
-+ struct ip_set_nethash *map = (struct ip_set_nethash *) set->data;
-+
-+ harray_free(map->members);
-+ kfree(map);
-+
-+ set->data = NULL;
-+}
-+
-+static void flush(struct ip_set *set)
-+{
-+ struct ip_set_nethash *map = (struct ip_set_nethash *) set->data;
-+ harray_flush(map->members, map->hashsize, sizeof(ip_set_ip_t));
-+ memset(map->cidr, 0, 30 * sizeof(unsigned char));
-+ map->elements = 0;
-+}
-+
-+static void list_header(const struct ip_set *set, void *data)
-+{
-+ struct ip_set_nethash *map = (struct ip_set_nethash *) set->data;
-+ struct ip_set_req_nethash_create *header =
-+ (struct ip_set_req_nethash_create *) data;
-+
-+ header->hashsize = map->hashsize;
-+ header->probes = map->probes;
-+ header->resize = map->resize;
-+}
-+
-+static int list_members_size(const struct ip_set *set)
-+{
-+ struct ip_set_nethash *map = (struct ip_set_nethash *) set->data;
-+
-+ return (map->hashsize * sizeof(ip_set_ip_t));
-+}
-+
-+static void list_members(const struct ip_set *set, void *data)
-+{
-+ struct ip_set_nethash *map = (struct ip_set_nethash *) set->data;
-+ ip_set_ip_t i, *elem;
-+
-+ for (i = 0; i < map->hashsize; i++) {
-+ elem = HARRAY_ELEM(map->members, ip_set_ip_t *, i);
-+ ((ip_set_ip_t *)data)[i] = *elem;
-+ }
-+}
-+
-+static struct ip_set_type ip_set_nethash = {
-+ .typename = SETTYPE_NAME,
-+ .features = IPSET_TYPE_IP | IPSET_DATA_SINGLE,
-+ .protocol_version = IP_SET_PROTOCOL_VERSION,
-+ .create = &create,
-+ .destroy = &destroy,
-+ .flush = &flush,
-+ .reqsize = sizeof(struct ip_set_req_nethash),
-+ .addip = &addip,
-+ .addip_kernel = &addip_kernel,
-+ .retry = &retry,
-+ .delip = &delip,
-+ .delip_kernel = &delip_kernel,
-+ .testip = &testip,
-+ .testip_kernel = &testip_kernel,
-+ .header_size = sizeof(struct ip_set_req_nethash_create),
-+ .list_header = &list_header,
-+ .list_members_size = &list_members_size,
-+ .list_members = &list_members,
-+ .me = THIS_MODULE,
-+};
-+
-+MODULE_LICENSE("GPL");
-+MODULE_AUTHOR("Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>");
-+MODULE_DESCRIPTION("nethash type of IP sets");
-+module_param(limit, int, 0600);
-+MODULE_PARM_DESC(limit, "maximal number of elements stored in the sets");
-+
-+static int __init ip_set_nethash_init(void)
-+{
-+ return ip_set_register_set_type(&ip_set_nethash);
-+}
-+
-+static void __exit ip_set_nethash_fini(void)
-+{
-+ /* FIXME: possible race with ip_set_create() */
-+ ip_set_unregister_set_type(&ip_set_nethash);
-+}
-+
-+module_init(ip_set_nethash_init);
-+module_exit(ip_set_nethash_fini);
---- /dev/null
-+++ b/net/ipv4/netfilter/ip_set_portmap.c
-@@ -0,0 +1,346 @@
-+/* Copyright (C) 2003-2004 Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
-+ *
-+ * This program is free software; you can redistribute it and/or modify
-+ * it under the terms of the GNU General Public License version 2 as
-+ * published by the Free Software Foundation.
-+ */
-+
-+/* Kernel module implementing a port set type as a bitmap */
-+
-+#include <linux/module.h>
-+#include <linux/ip.h>
-+#include <linux/tcp.h>
-+#include <linux/udp.h>
-+#include <linux/skbuff.h>
-+#include <linux/version.h>
-+#include <linux/netfilter_ipv4/ip_tables.h>
-+#include <linux/netfilter_ipv4/ip_set.h>
-+#include <linux/errno.h>
-+#include <asm/uaccess.h>
-+#include <asm/bitops.h>
-+#include <linux/spinlock.h>
-+
-+#include <net/ip.h>
-+
-+#include <linux/netfilter_ipv4/ip_set_portmap.h>
-+
-+/* We must handle non-linear skbs */
-+static inline ip_set_ip_t
-+get_port(const struct sk_buff *skb, u_int32_t flags)
-+{
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-+ struct iphdr *iph = ip_hdr(skb);
-+#else
-+ struct iphdr *iph = skb->nh.iph;
-+#endif
-+ u_int16_t offset = ntohs(iph->frag_off) & IP_OFFSET;
-+ switch (iph->protocol) {
-+ case IPPROTO_TCP: {
-+ struct tcphdr tcph;
-+
-+ /* See comments at tcp_match in ip_tables.c */
-+ if (offset)
-+ return INVALID_PORT;
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-+ if (skb_copy_bits(skb, ip_hdr(skb)->ihl*4, &tcph, sizeof(tcph)) < 0)
-+#else
-+ if (skb_copy_bits(skb, skb->nh.iph->ihl*4, &tcph, sizeof(tcph)) < 0)
-+#endif
-+ /* No choice either */
-+ return INVALID_PORT;
-+
-+ return ntohs(flags & IPSET_SRC ?
-+ tcph.source : tcph.dest);
-+ }
-+ case IPPROTO_UDP: {
-+ struct udphdr udph;
-+
-+ if (offset)
-+ return INVALID_PORT;
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-+ if (skb_copy_bits(skb, ip_hdr(skb)->ihl*4, &udph, sizeof(udph)) < 0)
-+#else
-+ if (skb_copy_bits(skb, skb->nh.iph->ihl*4, &udph, sizeof(udph)) < 0)
-+#endif
-+ /* No choice either */
-+ return INVALID_PORT;
-+
-+ return ntohs(flags & IPSET_SRC ?
-+ udph.source : udph.dest);
-+ }
-+ default:
-+ return INVALID_PORT;
-+ }
-+}
-+
-+static inline int
-+__testport(struct ip_set *set, ip_set_ip_t port, ip_set_ip_t *hash_port)
-+{
-+ struct ip_set_portmap *map = (struct ip_set_portmap *) set->data;
-+
-+ if (port < map->first_port || port > map->last_port)
-+ return -ERANGE;
-+
-+ *hash_port = port;
-+ DP("set: %s, port:%u, %u", set->name, port, *hash_port);
-+ return !!test_bit(port - map->first_port, map->members);
-+}
-+
-+static int
-+testport(struct ip_set *set, const void *data, size_t size,
-+ ip_set_ip_t *hash_port)
-+{
-+ struct ip_set_req_portmap *req =
-+ (struct ip_set_req_portmap *) data;
-+
-+ if (size != sizeof(struct ip_set_req_portmap)) {
-+ ip_set_printk("data length wrong (want %zu, have %zu)",
-+ sizeof(struct ip_set_req_portmap),
-+ size);
-+ return -EINVAL;
-+ }
-+ return __testport(set, req->port, hash_port);
-+}
-+
-+static int
-+testport_kernel(struct ip_set *set,
-+ const struct sk_buff *skb,
-+ ip_set_ip_t *hash_port,
-+ const u_int32_t *flags,
-+ unsigned char index)
-+{
-+ int res;
-+ ip_set_ip_t port = get_port(skb, flags[index]);
-+
-+ DP("flag %s port %u", flags[index] & IPSET_SRC ? "SRC" : "DST", port);
-+ if (port == INVALID_PORT)
-+ return 0;
-+
-+ res = __testport(set, port, hash_port);
-+
-+ return (res < 0 ? 0 : res);
-+}
-+
-+static inline int
-+__addport(struct ip_set *set, ip_set_ip_t port, ip_set_ip_t *hash_port)
-+{
-+ struct ip_set_portmap *map = (struct ip_set_portmap *) set->data;
-+
-+ if (port < map->first_port || port > map->last_port)
-+ return -ERANGE;
-+ if (test_and_set_bit(port - map->first_port, map->members))
-+ return -EEXIST;
-+
-+ *hash_port = port;
-+ DP("port %u", port);
-+ return 0;
-+}
-+
-+static int
-+addport(struct ip_set *set, const void *data, size_t size,
-+ ip_set_ip_t *hash_port)
-+{
-+ struct ip_set_req_portmap *req =
-+ (struct ip_set_req_portmap *) data;
-+
-+ if (size != sizeof(struct ip_set_req_portmap)) {
-+ ip_set_printk("data length wrong (want %zu, have %zu)",
-+ sizeof(struct ip_set_req_portmap),
-+ size);
-+ return -EINVAL;
-+ }
-+ return __addport(set, req->port, hash_port);
-+}
-+
-+static int
-+addport_kernel(struct ip_set *set,
-+ const struct sk_buff *skb,
-+ ip_set_ip_t *hash_port,
-+ const u_int32_t *flags,
-+ unsigned char index)
-+{
-+ ip_set_ip_t port = get_port(skb, flags[index]);
-+
-+ if (port == INVALID_PORT)
-+ return -EINVAL;
-+
-+ return __addport(set, port, hash_port);
-+}
-+
-+static inline int
-+__delport(struct ip_set *set, ip_set_ip_t port, ip_set_ip_t *hash_port)
-+{
-+ struct ip_set_portmap *map = (struct ip_set_portmap *) set->data;
-+
-+ if (port < map->first_port || port > map->last_port)
-+ return -ERANGE;
-+ if (!test_and_clear_bit(port - map->first_port, map->members))
-+ return -EEXIST;
-+
-+ *hash_port = port;
-+ DP("port %u", port);
-+ return 0;
-+}
-+
-+static int
-+delport(struct ip_set *set, const void *data, size_t size,
-+ ip_set_ip_t *hash_port)
-+{
-+ struct ip_set_req_portmap *req =
-+ (struct ip_set_req_portmap *) data;
-+
-+ if (size != sizeof(struct ip_set_req_portmap)) {
-+ ip_set_printk("data length wrong (want %zu, have %zu)",
-+ sizeof(struct ip_set_req_portmap),
-+ size);
-+ return -EINVAL;
-+ }
-+ return __delport(set, req->port, hash_port);
-+}
-+
-+static int
-+delport_kernel(struct ip_set *set,
-+ const struct sk_buff *skb,
-+ ip_set_ip_t *hash_port,
-+ const u_int32_t *flags,
-+ unsigned char index)
-+{
-+ ip_set_ip_t port = get_port(skb, flags[index]);
-+
-+ if (port == INVALID_PORT)
-+ return -EINVAL;
-+
-+ return __delport(set, port, hash_port);
-+}
-+
-+static int create(struct ip_set *set, const void *data, size_t size)
-+{
-+ int newbytes;
-+ struct ip_set_req_portmap_create *req =
-+ (struct ip_set_req_portmap_create *) data;
-+ struct ip_set_portmap *map;
-+
-+ if (size != sizeof(struct ip_set_req_portmap_create)) {
-+ ip_set_printk("data length wrong (want %zu, have %zu)",
-+ sizeof(struct ip_set_req_portmap_create),
-+ size);
-+ return -EINVAL;
-+ }
-+
-+ DP("from %u to %u", req->from, req->to);
-+
-+ if (req->from > req->to) {
-+ DP("bad port range");
-+ return -ENOEXEC;
-+ }
-+
-+ if (req->to - req->from > MAX_RANGE) {
-+ ip_set_printk("range too big (max %d ports)",
-+ MAX_RANGE+1);
-+ return -ENOEXEC;
-+ }
-+
-+ map = kmalloc(sizeof(struct ip_set_portmap), GFP_KERNEL);
-+ if (!map) {
-+ DP("out of memory for %d bytes",
-+ sizeof(struct ip_set_portmap));
-+ return -ENOMEM;
-+ }
-+ map->first_port = req->from;
-+ map->last_port = req->to;
-+ newbytes = bitmap_bytes(req->from, req->to);
-+ map->members = kmalloc(newbytes, GFP_KERNEL);
-+ if (!map->members) {
-+ DP("out of memory for %d bytes", newbytes);
-+ kfree(map);
-+ return -ENOMEM;
-+ }
-+ memset(map->members, 0, newbytes);
-+
-+ set->data = map;
-+ return 0;
-+}
-+
-+static void destroy(struct ip_set *set)
-+{
-+ struct ip_set_portmap *map = (struct ip_set_portmap *) set->data;
-+
-+ kfree(map->members);
-+ kfree(map);
-+
-+ set->data = NULL;
-+}
-+
-+static void flush(struct ip_set *set)
-+{
-+ struct ip_set_portmap *map = (struct ip_set_portmap *) set->data;
-+ memset(map->members, 0, bitmap_bytes(map->first_port, map->last_port));
-+}
-+
-+static void list_header(const struct ip_set *set, void *data)
-+{
-+ struct ip_set_portmap *map = (struct ip_set_portmap *) set->data;
-+ struct ip_set_req_portmap_create *header =
-+ (struct ip_set_req_portmap_create *) data;
-+
-+ DP("list_header %u %u", map->first_port, map->last_port);
-+
-+ header->from = map->first_port;
-+ header->to = map->last_port;
-+}
-+
-+static int list_members_size(const struct ip_set *set)
-+{
-+ struct ip_set_portmap *map = (struct ip_set_portmap *) set->data;
-+
-+ return bitmap_bytes(map->first_port, map->last_port);
-+}
-+
-+static void list_members(const struct ip_set *set, void *data)
-+{
-+ struct ip_set_portmap *map = (struct ip_set_portmap *) set->data;
-+ int bytes = bitmap_bytes(map->first_port, map->last_port);
-+
-+ memcpy(data, map->members, bytes);
-+}
-+
-+static struct ip_set_type ip_set_portmap = {
-+ .typename = SETTYPE_NAME,
-+ .features = IPSET_TYPE_PORT | IPSET_DATA_SINGLE,
-+ .protocol_version = IP_SET_PROTOCOL_VERSION,
-+ .create = &create,
-+ .destroy = &destroy,
-+ .flush = &flush,
-+ .reqsize = sizeof(struct ip_set_req_portmap),
-+ .addip = &addport,
-+ .addip_kernel = &addport_kernel,
-+ .delip = &delport,
-+ .delip_kernel = &delport_kernel,
-+ .testip = &testport,
-+ .testip_kernel = &testport_kernel,
-+ .header_size = sizeof(struct ip_set_req_portmap_create),
-+ .list_header = &list_header,
-+ .list_members_size = &list_members_size,
-+ .list_members = &list_members,
-+ .me = THIS_MODULE,
-+};
-+
-+MODULE_LICENSE("GPL");
-+MODULE_AUTHOR("Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>");
-+MODULE_DESCRIPTION("portmap type of IP sets");
-+
-+static int __init ip_set_portmap_init(void)
-+{
-+ return ip_set_register_set_type(&ip_set_portmap);
-+}
-+
-+static void __exit ip_set_portmap_fini(void)
-+{
-+ /* FIXME: possible race with ip_set_create() */
-+ ip_set_unregister_set_type(&ip_set_portmap);
-+}
-+
-+module_init(ip_set_portmap_init);
-+module_exit(ip_set_portmap_fini);
---- /dev/null
-+++ b/net/ipv4/netfilter/ipt_set.c
-@@ -0,0 +1,160 @@
-+/* Copyright (C) 2000-2002 Joakim Axelsson <gozem@linux.nu>
-+ * Patrick Schaaf <bof@bof.de>
-+ * Martin Josefsson <gandalf@wlug.westbo.se>
-+ * Copyright (C) 2003-2004 Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
-+ *
-+ * This program is free software; you can redistribute it and/or modify
-+ * it under the terms of the GNU General Public License version 2 as
-+ * published by the Free Software Foundation.
-+ */
-+
-+/* Kernel module to match an IP set. */
-+
-+#include <linux/module.h>
-+#include <linux/ip.h>
-+#include <linux/skbuff.h>
-+#include <linux/version.h>
-+
-+#include <linux/netfilter_ipv4/ip_tables.h>
-+#include <linux/netfilter_ipv4/ip_set.h>
-+#include <linux/netfilter_ipv4/ipt_set.h>
-+
-+static inline int
-+match_set(const struct ipt_set_info *info,
-+ const struct sk_buff *skb,
-+ int inv)
-+{
-+ if (ip_set_testip_kernel(info->index, skb, info->flags))
-+ inv = !inv;
-+ return inv;
-+}
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,23)
-+static bool
-+#else
-+static int
-+#endif
-+match(const struct sk_buff *skb,
-+ const struct net_device *in,
-+ const struct net_device *out,
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17)
-+ const struct xt_match *match,
-+#endif
-+ const void *matchinfo,
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,23)
-+ int offset, unsigned int protoff, bool *hotdrop)
-+#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ int offset, unsigned int protoff, int *hotdrop)
-+#else
-+ int offset, int *hotdrop)
-+#endif
-+{
-+ const struct ipt_set_info_match *info = matchinfo;
-+
-+ return match_set(&info->match_set,
-+ skb,
-+ info->match_set.flags[0] & IPSET_MATCH_INV);
-+}
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,23)
-+bool
-+#else
-+static int
-+#endif
-+checkentry(const char *tablename,
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ const void *inf,
-+#else
-+ const struct ipt_ip *ip,
-+#endif
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17)
-+ const struct xt_match *match,
-+#endif
-+ void *matchinfo,
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
-+ unsigned int matchsize,
-+#endif
-+ unsigned int hook_mask)
-+{
-+ struct ipt_set_info_match *info =
-+ (struct ipt_set_info_match *) matchinfo;
-+ ip_set_id_t index;
-+
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
-+ if (matchsize != IPT_ALIGN(sizeof(struct ipt_set_info_match))) {
-+ ip_set_printk("invalid matchsize %d", matchsize);
-+ return 0;
-+ }
-+#endif
-+
-+ index = ip_set_get_byindex(info->match_set.index);
-+
-+ if (index == IP_SET_INVALID_ID) {
-+ ip_set_printk("Cannot find set indentified by id %u to match",
-+ info->match_set.index);
-+ return 0; /* error */
-+ }
-+ if (info->match_set.flags[IP_SET_MAX_BINDINGS] != 0) {
-+ ip_set_printk("That's nasty!");
-+ return 0; /* error */
-+ }
-+
-+ return 1;
-+}
-+
-+static void destroy(
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17)
-+ const struct xt_match *match,
-+#endif
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
-+ void *matchinfo, unsigned int matchsize)
-+#else
-+ void *matchinfo)
-+#endif
-+{
-+ struct ipt_set_info_match *info = matchinfo;
-+
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
-+ if (matchsize != IPT_ALIGN(sizeof(struct ipt_set_info_match))) {
-+ ip_set_printk("invalid matchsize %d", matchsize);
-+ return;
-+ }
-+#endif
-+ ip_set_put(info->match_set.index);
-+}
-+
-+static struct ipt_match set_match = {
-+ .name = "set",
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,21)
-+ .family = AF_INET,
-+#endif
-+ .match = &match,
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17)
-+ .matchsize = sizeof(struct ipt_set_info_match),
-+#endif
-+ .checkentry = &checkentry,
-+ .destroy = &destroy,
-+ .me = THIS_MODULE
-+};
-+
-+MODULE_LICENSE("GPL");
-+MODULE_AUTHOR("Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>");
-+MODULE_DESCRIPTION("iptables IP set match module");
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,21)
-+#define ipt_register_match xt_register_match
-+#define ipt_unregister_match xt_unregister_match
-+#endif
-+
-+static int __init ipt_ipset_init(void)
-+{
-+ return ipt_register_match(&set_match);
-+}
-+
-+static void __exit ipt_ipset_fini(void)
-+{
-+ ipt_unregister_match(&set_match);
-+}
-+
-+module_init(ipt_ipset_init);
-+module_exit(ipt_ipset_fini);
---- /dev/null
-+++ b/net/ipv4/netfilter/ipt_SET.c
-@@ -0,0 +1,172 @@
-+/* Copyright (C) 2000-2002 Joakim Axelsson <gozem@linux.nu>
-+ * Patrick Schaaf <bof@bof.de>
-+ * Martin Josefsson <gandalf@wlug.westbo.se>
-+ * Copyright (C) 2003-2004 Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
-+ *
-+ * This program is free software; you can redistribute it and/or modify
-+ * it under the terms of the GNU General Public License version 2 as
-+ * published by the Free Software Foundation.
-+ */
-+
-+/* ipt_SET.c - netfilter target to manipulate IP sets */
-+
-+#include <linux/types.h>
-+#include <linux/ip.h>
-+#include <linux/timer.h>
-+#include <linux/module.h>
-+#include <linux/netfilter.h>
-+#include <linux/netdevice.h>
-+#include <linux/if.h>
-+#include <linux/inetdevice.h>
-+#include <linux/version.h>
-+#include <net/protocol.h>
-+#include <net/checksum.h>
-+#include <linux/netfilter_ipv4.h>
-+#include <linux/netfilter_ipv4/ip_tables.h>
-+#include <linux/netfilter_ipv4/ipt_set.h>
-+
-+static unsigned int
-+target(struct sk_buff **pskb,
-+ const struct net_device *in,
-+ const struct net_device *out,
-+ unsigned int hooknum,
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17)
-+ const struct xt_target *target,
-+#endif
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
-+ const void *targinfo,
-+ void *userinfo)
-+#else
-+ const void *targinfo)
-+#endif
-+{
-+ const struct ipt_set_info_target *info = targinfo;
-+
-+ if (info->add_set.index != IP_SET_INVALID_ID)
-+ ip_set_addip_kernel(info->add_set.index,
-+ *pskb,
-+ info->add_set.flags);
-+ if (info->del_set.index != IP_SET_INVALID_ID)
-+ ip_set_delip_kernel(info->del_set.index,
-+ *pskb,
-+ info->del_set.flags);
-+
-+ return IPT_CONTINUE;
-+}
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,23)
-+static bool
-+#else
-+static int
-+#endif
-+checkentry(const char *tablename,
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ const void *e,
-+#else
-+ const struct ipt_entry *e,
-+#endif
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17)
-+ const struct xt_target *target,
-+#endif
-+ void *targinfo,
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
-+ unsigned int targinfosize,
-+#endif
-+ unsigned int hook_mask)
-+{
-+ struct ipt_set_info_target *info =
-+ (struct ipt_set_info_target *) targinfo;
-+ ip_set_id_t index;
-+
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
-+ if (targinfosize != IPT_ALIGN(sizeof(*info))) {
-+ DP("bad target info size %u", targinfosize);
-+ return 0;
-+ }
-+#endif
-+
-+ if (info->add_set.index != IP_SET_INVALID_ID) {
-+ index = ip_set_get_byindex(info->add_set.index);
-+ if (index == IP_SET_INVALID_ID) {
-+ ip_set_printk("cannot find add_set index %u as target",
-+ info->add_set.index);
-+ return 0; /* error */
-+ }
-+ }
-+
-+ if (info->del_set.index != IP_SET_INVALID_ID) {
-+ index = ip_set_get_byindex(info->del_set.index);
-+ if (index == IP_SET_INVALID_ID) {
-+ ip_set_printk("cannot find del_set index %u as target",
-+ info->del_set.index);
-+ return 0; /* error */
-+ }
-+ }
-+ if (info->add_set.flags[IP_SET_MAX_BINDINGS] != 0
-+ || info->del_set.flags[IP_SET_MAX_BINDINGS] != 0) {
-+ ip_set_printk("That's nasty!");
-+ return 0; /* error */
-+ }
-+
-+ return 1;
-+}
-+
-+static void destroy(
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17)
-+ const struct xt_target *target,
-+#endif
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
-+ void *targetinfo, unsigned int targetsize)
-+#else
-+ void *targetinfo)
-+#endif
-+{
-+ struct ipt_set_info_target *info = targetinfo;
-+
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
-+ if (targetsize != IPT_ALIGN(sizeof(struct ipt_set_info_target))) {
-+ ip_set_printk("invalid targetsize %d", targetsize);
-+ return;
-+ }
-+#endif
-+ if (info->add_set.index != IP_SET_INVALID_ID)
-+ ip_set_put(info->add_set.index);
-+ if (info->del_set.index != IP_SET_INVALID_ID)
-+ ip_set_put(info->del_set.index);
-+}
-+
-+static struct ipt_target SET_target = {
-+ .name = "SET",
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,21)
-+ .family = AF_INET,
-+#endif
-+ .target = target,
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17)
-+ .targetsize = sizeof(struct ipt_set_info_target),
-+#endif
-+ .checkentry = checkentry,
-+ .destroy = destroy,
-+ .me = THIS_MODULE
-+};
-+
-+MODULE_LICENSE("GPL");
-+MODULE_AUTHOR("Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>");
-+MODULE_DESCRIPTION("iptables IP set target module");
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,21)
-+#define ipt_register_target xt_register_target
-+#define ipt_unregister_target xt_unregister_target
-+#endif
-+
-+static int __init ipt_SET_init(void)
-+{
-+ return ipt_register_target(&SET_target);
-+}
-+
-+static void __exit ipt_SET_fini(void)
-+{
-+ ipt_unregister_target(&SET_target);
-+}
-+
-+module_init(ipt_SET_init);
-+module_exit(ipt_SET_fini);
---- a/net/ipv4/netfilter/Kconfig
-+++ b/net/ipv4/netfilter/Kconfig
-@@ -408,5 +408,122 @@
- Allows altering the ARP packet payload: source and destination
- hardware and network addresses.
-
-+config IP_NF_SET
-+ tristate "IP set support"
-+ depends on INET && NETFILTER
-+ help
-+ This option adds IP set support to the kernel.
-+ In order to define and use sets, you need the userspace utility
-+ ipset(8).
-+
-+ To compile it as a module, choose M here. If unsure, say N.
-+
-+config IP_NF_SET_MAX
-+ int "Maximum number of IP sets"
-+ default 256
-+ range 2 65534
-+ depends on IP_NF_SET
-+ help
-+ You can define here default value of the maximum number
-+ of IP sets for the kernel.
-+
-+ The value can be overriden by the 'max_sets' module
-+ parameter of the 'ip_set' module.
-+
-+config IP_NF_SET_HASHSIZE
-+ int "Hash size for bindings of IP sets"
-+ default 1024
-+ depends on IP_NF_SET
-+ help
-+ You can define here default value of the hash size for
-+ bindings of IP sets.
-+
-+ The value can be overriden by the 'hash_size' module
-+ parameter of the 'ip_set' module.
-+
-+config IP_NF_SET_IPMAP
-+ tristate "ipmap set support"
-+ depends on IP_NF_SET
-+ help
-+ This option adds the ipmap set type support.
-+
-+ To compile it as a module, choose M here. If unsure, say N.
-+
-+config IP_NF_SET_MACIPMAP
-+ tristate "macipmap set support"
-+ depends on IP_NF_SET
-+ help
-+ This option adds the macipmap set type support.
-+
-+ To compile it as a module, choose M here. If unsure, say N.
-+
-+config IP_NF_SET_PORTMAP
-+ tristate "portmap set support"
-+ depends on IP_NF_SET
-+ help
-+ This option adds the portmap set type support.
-+
-+ To compile it as a module, choose M here. If unsure, say N.
-+
-+config IP_NF_SET_IPHASH
-+ tristate "iphash set support"
-+ depends on IP_NF_SET
-+ help
-+ This option adds the iphash set type support.
-+
-+ To compile it as a module, choose M here. If unsure, say N.
-+
-+config IP_NF_SET_NETHASH
-+ tristate "nethash set support"
-+ depends on IP_NF_SET
-+ help
-+ This option adds the nethash set type support.
-+
-+ To compile it as a module, choose M here. If unsure, say N.
-+
-+config IP_NF_SET_IPPORTHASH
-+ tristate "ipporthash set support"
-+ depends on IP_NF_SET
-+ help
-+ This option adds the ipporthash set type support.
-+
-+ To compile it as a module, choose M here. If unsure, say N.
-+
-+config IP_NF_SET_IPTREE
-+ tristate "iptree set support"
-+ depends on IP_NF_SET
-+ help
-+ This option adds the iptree set type support.
-+
-+ To compile it as a module, choose M here. If unsure, say N.
-+
-+config IP_NF_SET_IPTREEMAP
-+ tristate "iptreemap set support"
-+ depends on IP_NF_SET
-+ help
-+ This option adds the iptreemap set type support.
-+
-+ To compile it as a module, choose M here. If unsure, say N.
-+
-+config IP_NF_MATCH_SET
-+ tristate "set match support"
-+ depends on IP_NF_SET
-+ help
-+ Set matching matches against given IP sets.
-+ You need the ipset utility to create and set up the sets.
-+
-+ To compile it as a module, choose M here. If unsure, say N.
-+
-+config IP_NF_TARGET_SET
-+ tristate "SET target support"
-+ depends on IP_NF_SET
-+ help
-+ The SET target makes possible to add/delete entries
-+ in IP sets.
-+ You need the ipset utility to create and set up the sets.
-+
-+ To compile it as a module, choose M here. If unsure, say N.
-+
-+
- endmenu
-
---- a/net/ipv4/netfilter/Makefile
-+++ b/net/ipv4/netfilter/Makefile
-@@ -48,6 +48,7 @@
- obj-$(CONFIG_IP_NF_MATCH_ECN) += ipt_ecn.o
- obj-$(CONFIG_IP_NF_MATCH_AH) += ipt_ah.o
- obj-$(CONFIG_IP_NF_MATCH_TTL) += ipt_ttl.o
-+obj-$(CONFIG_IP_NF_MATCH_SET) += ipt_set.o
- obj-$(CONFIG_IP_NF_MATCH_ADDRTYPE) += ipt_addrtype.o
-
- obj-$(CONFIG_IP_NF_MATCH_IPP2P) += ipt_ipp2p.o
-@@ -64,6 +65,18 @@
- obj-$(CONFIG_IP_NF_TARGET_ULOG) += ipt_ULOG.o
- obj-$(CONFIG_IP_NF_TARGET_CLUSTERIP) += ipt_CLUSTERIP.o
- obj-$(CONFIG_IP_NF_TARGET_TTL) += ipt_TTL.o
-+obj-$(CONFIG_IP_NF_TARGET_SET) += ipt_SET.o
-+
-+# sets
-+obj-$(CONFIG_IP_NF_SET) += ip_set.o
-+obj-$(CONFIG_IP_NF_SET_IPMAP) += ip_set_ipmap.o
-+obj-$(CONFIG_IP_NF_SET_PORTMAP) += ip_set_portmap.o
-+obj-$(CONFIG_IP_NF_SET_MACIPMAP) += ip_set_macipmap.o
-+obj-$(CONFIG_IP_NF_SET_IPHASH) += ip_set_iphash.o
-+obj-$(CONFIG_IP_NF_SET_NETHASH) += ip_set_nethash.o
-+obj-$(CONFIG_IP_NF_SET_IPPORTHASH) += ip_set_ipporthash.o
-+obj-$(CONFIG_IP_NF_SET_IPTREE) += ip_set_iptree.o
-+obj-$(CONFIG_IP_NF_SET_IPTREEMAP) += ip_set_iptreemap.o
-
- # generic ARP tables
- obj-$(CONFIG_IP_NF_ARPTABLES) += arp_tables.o
+++ /dev/null
---- /dev/null
-+++ b/include/linux/netfilter_ipv4/ipt_time.h
-@@ -0,0 +1,18 @@
-+#ifndef __ipt_time_h_included__
-+#define __ipt_time_h_included__
-+
-+
-+struct ipt_time_info {
-+ u_int8_t days_match; /* 1 bit per day. -SMTWTFS */
-+ u_int16_t time_start; /* 0 < time_start < 23*60+59 = 1439 */
-+ u_int16_t time_stop; /* 0:0 < time_stat < 23:59 */
-+
-+ /* FIXME: Keep this one for userspace iptables binary compability: */
-+ u_int8_t kerneltime; /* ignore skb time (and use kerneltime) or not. */
-+
-+ time_t date_start;
-+ time_t date_stop;
-+};
-+
-+
-+#endif /* __ipt_time_h_included__ */
---- /dev/null
-+++ b/net/ipv4/netfilter/ipt_time.c
-@@ -0,0 +1,180 @@
-+/*
-+ This is a module which is used for time matching
-+ It is using some modified code from dietlibc (localtime() function)
-+ that you can find at http://www.fefe.de/dietlibc/
-+ This file is distributed under the terms of the GNU General Public
-+ License (GPL). Copies of the GPL can be obtained from: ftp://prep.ai.mit.edu/pub/gnu/GPL
-+ 2001-05-04 Fabrice MARIE <fabrice@netfilter.org> : initial development.
-+ 2001-21-05 Fabrice MARIE <fabrice@netfilter.org> : bug fix in the match code,
-+ thanks to "Zeng Yu" <zengy@capitel.com.cn> for bug report.
-+ 2001-26-09 Fabrice MARIE <fabrice@netfilter.org> : force the match to be in LOCAL_IN or PRE_ROUTING only.
-+ 2001-30-11 Fabrice : added the possibility to use the match in FORWARD/OUTPUT with a little hack,
-+ added Nguyen Dang Phuoc Dong <dongnd@tlnet.com.vn> patch to support timezones.
-+ 2004-05-02 Fabrice : added support for date matching, from an idea of Fabien COELHO.
-+*/
-+
-+#include <linux/module.h>
-+#include <linux/skbuff.h>
-+#include <linux/netfilter_ipv4/ip_tables.h>
-+#include <linux/netfilter_ipv4/ipt_time.h>
-+#include <linux/time.h>
-+
-+MODULE_AUTHOR("Fabrice MARIE <fabrice@netfilter.org>");
-+MODULE_DESCRIPTION("Match arrival timestamp/date");
-+MODULE_LICENSE("GPL");
-+
-+struct tm
-+{
-+ int tm_sec; /* Seconds. [0-60] (1 leap second) */
-+ int tm_min; /* Minutes. [0-59] */
-+ int tm_hour; /* Hours. [0-23] */
-+ int tm_mday; /* Day. [1-31] */
-+ int tm_mon; /* Month. [0-11] */
-+ int tm_year; /* Year - 1900. */
-+ int tm_wday; /* Day of week. [0-6] */
-+ int tm_yday; /* Days in year.[0-365] */
-+ int tm_isdst; /* DST. [-1/0/1]*/
-+
-+ long int tm_gmtoff; /* we don't care, we count from GMT */
-+ const char *tm_zone; /* we don't care, we count from GMT */
-+};
-+
-+void
-+localtime(const u32 time, struct tm *r);
-+
-+static bool
-+match(const struct sk_buff *skb,
-+ const struct net_device *in,
-+ const struct net_device *out,
-+ const struct xt_match *match,
-+ const void *matchinfo,
-+ int offset,
-+ unsigned int protoff,
-+ bool *hotdrop)
-+{
-+ const struct ipt_time_info *info = matchinfo; /* match info for rule */
-+ struct timeval tv;
-+ struct tm currenttime; /* time human readable */
-+ u_int8_t days_of_week[7] = {64, 32, 16, 8, 4, 2, 1};
-+ u_int16_t packet_time;
-+
-+ /* We might not have a timestamp, get one */
-+ if (skb->tstamp.tv64 == 0)
-+ __net_timestamp((struct sk_buff *)skb);
-+
-+ skb_get_timestamp(skb, &tv);
-+ /* First we make sure we are in the date start-stop boundaries */
-+ if ((tv.tv_sec < info->date_start) || (tv.tv_sec > info->date_stop))
-+ return 0; /* We are outside the date boundaries */
-+
-+ /* Transform the timestamp of the packet, in a human readable form */
-+ localtime(tv.tv_sec, ¤ttime);
-+
-+ /* check if we match this timestamp, we start by the days... */
-+ if ((days_of_week[currenttime.tm_wday] & info->days_match) != days_of_week[currenttime.tm_wday])
-+ return 0; /* the day doesn't match */
-+
-+ /* ... check the time now */
-+ packet_time = (currenttime.tm_hour * 60) + currenttime.tm_min;
-+ if ((packet_time < info->time_start) || (packet_time > info->time_stop))
-+ return 0;
-+
-+ /* here we match ! */
-+ return 1;
-+}
-+
-+static bool
-+checkentry(const char *tablename,
-+ const void *ip,
-+ const struct xt_match *match,
-+ void *matchinfo,
-+ unsigned int hook_mask)
-+{
-+ struct ipt_time_info *info = matchinfo; /* match info for rule */
-+
-+ /* First, check that we are in the correct hooks */
-+ if (hook_mask
-+ & ~((1 << NF_IP_PRE_ROUTING) | (1 << NF_IP_LOCAL_IN) | (1 << NF_IP_FORWARD) | (1 << NF_IP_LOCAL_OUT)))
-+ {
-+ printk("ipt_time: error, only valid for PRE_ROUTING, LOCAL_IN, FORWARD and OUTPUT)\n");
-+ return 0;
-+ }
-+
-+ /* Now check the coherence of the data ... */
-+ if ((info->time_start > 1439) || /* 23*60+59 = 1439*/
-+ (info->time_stop > 1439))
-+ {
-+ printk(KERN_WARNING "ipt_time: invalid argument\n");
-+ return 0;
-+ }
-+
-+ return 1;
-+}
-+
-+static struct ipt_match time_match = {
-+ .name = "time",
-+ .match = &match,
-+ .matchsize = sizeof(struct ipt_time_info),
-+ .checkentry = &checkentry,
-+ .me = THIS_MODULE
-+};
-+
-+static int __init init(void)
-+{
-+ printk("ipt_time loading\n");
-+ return xt_register_match(&time_match);
-+}
-+
-+static void __exit fini(void)
-+{
-+ xt_unregister_match(&time_match);
-+ printk("ipt_time unloaded\n");
-+}
-+
-+module_init(init);
-+module_exit(fini);
-+
-+
-+/* The part below is borowed and modified from dietlibc */
-+
-+/* seconds per day */
-+#define SPD 24*60*60
-+
-+void
-+localtime(const u32 time, struct tm *r) {
-+ u32 i, timep;
-+ extern struct timezone sys_tz;
-+ const unsigned int __spm[12] =
-+ { 0,
-+ (31),
-+ (31+28),
-+ (31+28+31),
-+ (31+28+31+30),
-+ (31+28+31+30+31),
-+ (31+28+31+30+31+30),
-+ (31+28+31+30+31+30+31),
-+ (31+28+31+30+31+30+31+31),
-+ (31+28+31+30+31+30+31+31+30),
-+ (31+28+31+30+31+30+31+31+30+31),
-+ (31+28+31+30+31+30+31+31+30+31+30),
-+ };
-+ register u32 work;
-+
-+ timep = time - (sys_tz.tz_minuteswest * 60);
-+ work=timep%(SPD);
-+ r->tm_sec=work%60; work/=60;
-+ r->tm_min=work%60; r->tm_hour=work/60;
-+ work=timep/(SPD);
-+ r->tm_wday=(4+work)%7;
-+ for (i=1970; ; ++i) {
-+ register time_t k= (!(i%4) && ((i%100) || !(i%400)))?366:365;
-+ if (work>k)
-+ work-=k;
-+ else
-+ break;
-+ }
-+ r->tm_year=i-1900;
-+ for (i=11; i && __spm[i]>work; --i) ;
-+ r->tm_mon=i;
-+ r->tm_mday=work-__spm[i]+1;
-+}
---- a/net/ipv4/netfilter/Kconfig
-+++ b/net/ipv4/netfilter/Kconfig
-@@ -78,6 +78,22 @@
-
- To compile it as a module, choose M here. If unsure, say N.
-
-+
-+config IP_NF_MATCH_TIME
-+ tristate 'TIME match support'
-+ depends on IP_NF_IPTABLES
-+ help
-+ This option adds a `time' match, which allows you
-+ to match based on the packet arrival time/date
-+ (arrival time/date at the machine which netfilter is running on) or
-+ departure time/date (for locally generated packets).
-+
-+ If you say Y here, try iptables -m time --help for more information.
-+ If you want to compile it as a module, say M here and read
-+
-+ Documentation/modules.txt. If unsure, say `N'.
-+
-+
- config IP_NF_MATCH_RECENT
- tristate "recent match support"
- depends on IP_NF_IPTABLES
---- a/net/ipv4/netfilter/Makefile
-+++ b/net/ipv4/netfilter/Makefile
-@@ -44,6 +44,7 @@
- obj-$(CONFIG_IP_NF_MATCH_IPRANGE) += ipt_iprange.o
- obj-$(CONFIG_IP_NF_MATCH_OWNER) += ipt_owner.o
- obj-$(CONFIG_IP_NF_MATCH_TOS) += ipt_tos.o
-+obj-$(CONFIG_IP_NF_MATCH_TIME) += ipt_time.o
- obj-$(CONFIG_IP_NF_MATCH_RECENT) += ipt_recent.o
- obj-$(CONFIG_IP_NF_MATCH_ECN) += ipt_ecn.o
- obj-$(CONFIG_IP_NF_MATCH_AH) += ipt_ah.o
+++ /dev/null
---- /dev/null
-+++ b/drivers/net/imq.c
-@@ -0,0 +1,400 @@
-+/*
-+ * Pseudo-driver for the intermediate queue device.
-+ *
-+ * 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.
-+ *
-+ * Authors: Patrick McHardy, <kaber@trash.net>
-+ *
-+ * The first version was written by Martin Devera, <devik@cdi.cz>
-+ *
-+ * Credits: Jan Rafaj <imq2t@cedric.vabo.cz>
-+ * - Update patch to 2.4.21
-+ * Sebastian Strollo <sstrollo@nortelnetworks.com>
-+ * - Fix "Dead-loop on netdevice imq"-issue
-+ * Marcel Sebek <sebek64@post.cz>
-+ * - Update to 2.6.2-rc1
-+ *
-+ * After some time of inactivity there is a group taking care
-+ * of IMQ again: http://www.linuximq.net
-+ *
-+ *
-+ * 2004/06/30 - New version of IMQ patch to kernels <=2.6.7 including
-+ * the following changes:
-+ *
-+ * - Correction of ipv6 support "+"s issue (Hasso Tepper)
-+ * - Correction of imq_init_devs() issue that resulted in
-+ * kernel OOPS unloading IMQ as module (Norbert Buchmuller)
-+ * - Addition of functionality to choose number of IMQ devices
-+ * during kernel config (Andre Correa)
-+ * - Addition of functionality to choose how IMQ hooks on
-+ * PRE and POSTROUTING (after or before NAT) (Andre Correa)
-+ * - Cosmetic corrections (Norbert Buchmuller) (Andre Correa)
-+ *
-+ *
-+ * 2005/12/16 - IMQ versions between 2.6.7 and 2.6.13 were
-+ * released with almost no problems. 2.6.14-x was released
-+ * with some important changes: nfcache was removed; After
-+ * some weeks of trouble we figured out that some IMQ fields
-+ * in skb were missing in skbuff.c - skb_clone and copy_skb_header.
-+ * These functions are correctly patched by this new patch version.
-+ *
-+ * Thanks for all who helped to figure out all the problems with
-+ * 2.6.14.x: Patrick McHardy, Rune Kock, VeNoMouS, Max CtRiX,
-+ * Kevin Shanahan, Richard Lucassen, Valery Dachev (hopefully
-+ * I didn't forget anybody). I apologize again for my lack of time.
-+ *
-+ * More info at: http://www.linuximq.net/ (Andre Correa)
-+ */
-+
-+#include <linux/module.h>
-+#include <linux/kernel.h>
-+#include <linux/moduleparam.h>
-+#include <linux/skbuff.h>
-+#include <linux/netdevice.h>
-+#include <linux/rtnetlink.h>
-+#include <linux/if_arp.h>
-+#include <linux/netfilter.h>
-+#include <linux/netfilter_ipv4.h>
-+#if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
-+ #include <linux/netfilter_ipv6.h>
-+#endif
-+#include <linux/imq.h>
-+#include <net/pkt_sched.h>
-+
-+extern int qdisc_restart1(struct net_device *dev);
-+
-+static nf_hookfn imq_nf_hook;
-+
-+static struct nf_hook_ops imq_ingress_ipv4 = {
-+ .hook = imq_nf_hook,
-+ .owner = THIS_MODULE,
-+ .pf = PF_INET,
-+ .hooknum = NF_IP_PRE_ROUTING,
-+#if defined(CONFIG_IMQ_BEHAVIOR_BA) || defined(CONFIG_IMQ_BEHAVIOR_BB)
-+ .priority = NF_IP_PRI_MANGLE + 1
-+#else
-+ .priority = NF_IP_PRI_NAT_DST + 1
-+#endif
-+};
-+
-+static struct nf_hook_ops imq_egress_ipv4 = {
-+ .hook = imq_nf_hook,
-+ .owner = THIS_MODULE,
-+ .pf = PF_INET,
-+ .hooknum = NF_IP_POST_ROUTING,
-+#if defined(CONFIG_IMQ_BEHAVIOR_AA) || defined(CONFIG_IMQ_BEHAVIOR_BA)
-+ .priority = NF_IP_PRI_LAST
-+#else
-+ .priority = NF_IP_PRI_NAT_SRC - 1
-+#endif
-+};
-+
-+#if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
-+static struct nf_hook_ops imq_ingress_ipv6 = {
-+ .hook = imq_nf_hook,
-+ .owner = THIS_MODULE,
-+ .pf = PF_INET6,
-+ .hooknum = NF_IP6_PRE_ROUTING,
-+#if defined(CONFIG_IMQ_BEHAVIOR_BA) || defined(CONFIG_IMQ_BEHAVIOR_BB)
-+ .priority = NF_IP6_PRI_MANGLE + 1
-+#else
-+ .priority = NF_IP6_PRI_NAT_DST + 1
-+#endif
-+};
-+
-+static struct nf_hook_ops imq_egress_ipv6 = {
-+ .hook = imq_nf_hook,
-+ .owner = THIS_MODULE,
-+ .pf = PF_INET6,
-+ .hooknum = NF_IP6_POST_ROUTING,
-+#if defined(CONFIG_IMQ_BEHAVIOR_AA) || defined(CONFIG_IMQ_BEHAVIOR_BA)
-+ .priority = NF_IP6_PRI_LAST
-+#else
-+ .priority = NF_IP6_PRI_NAT_SRC - 1
-+#endif
-+};
-+#endif
-+
-+#if defined(CONFIG_IMQ_NUM_DEVS)
-+static unsigned int numdevs = CONFIG_IMQ_NUM_DEVS;
-+#else
-+static unsigned int numdevs = 16;
-+#endif
-+
-+static struct net_device *imq_devs;
-+
-+static struct net_device_stats *imq_get_stats(struct net_device *dev)
-+{
-+ return (struct net_device_stats *)dev->priv;
-+}
-+
-+/* called for packets kfree'd in qdiscs at places other than enqueue */
-+static void imq_skb_destructor(struct sk_buff *skb)
-+{
-+ struct nf_info *info = skb->nf_info;
-+
-+ if (info) {
-+ if (info->indev)
-+ dev_put(info->indev);
-+ if (info->outdev)
-+ dev_put(info->outdev);
-+ kfree(info);
-+ }
-+}
-+
-+static int imq_dev_xmit(struct sk_buff *skb, struct net_device *dev)
-+{
-+ struct net_device_stats *stats = (struct net_device_stats*) dev->priv;
-+
-+ stats->tx_bytes += skb->len;
-+ stats->tx_packets++;
-+
-+ skb->imq_flags = 0;
-+ skb->destructor = NULL;
-+
-+ dev->trans_start = jiffies;
-+ nf_reinject(skb, skb->nf_info, NF_ACCEPT);
-+ return 0;
-+}
-+
-+static int imq_nf_queue(struct sk_buff *skb, struct nf_info *info, unsigned queue_num, void *data)
-+{
-+ struct net_device *dev;
-+ struct net_device_stats *stats;
-+ struct sk_buff *skb2 = NULL;
-+ struct Qdisc *q;
-+ unsigned int index = skb->imq_flags&IMQ_F_IFMASK;
-+ int ret = -1;
-+
-+ if (index > numdevs)
-+ return -1;
-+
-+ dev = imq_devs + index;
-+ if (!(dev->flags & IFF_UP)) {
-+ skb->imq_flags = 0;
-+ nf_reinject(skb, info, NF_ACCEPT);
-+ return 0;
-+ }
-+ dev->last_rx = jiffies;
-+
-+ if (skb->destructor) {
-+ skb2 = skb;
-+ skb = skb_clone(skb, GFP_ATOMIC);
-+ if (!skb)
-+ return -1;
-+ }
-+ skb->nf_info = info;
-+
-+ stats = (struct net_device_stats *)dev->priv;
-+ stats->rx_bytes+= skb->len;
-+ stats->rx_packets++;
-+
-+ spin_lock_bh(&dev->queue_lock);
-+ q = dev->qdisc;
-+ if (q->enqueue) {
-+ q->enqueue(skb_get(skb), q);
-+ if (skb_shared(skb)) {
-+ skb->destructor = imq_skb_destructor;
-+ kfree_skb(skb);
-+ ret = 0;
-+ }
-+ }
-+ if (spin_is_locked(&dev->_xmit_lock))
-+ netif_schedule(dev);
-+ else
-+ while (!netif_queue_stopped(dev) && qdisc_restart1(dev) < 0)
-+ /* NOTHING */;
-+
-+ spin_unlock_bh(&dev->queue_lock);
-+
-+ if (skb2)
-+ kfree_skb(ret ? skb : skb2);
-+
-+ return ret;
-+}
-+
-+static struct nf_queue_handler nfqh = {
-+ .name = "imq",
-+ .outfn = imq_nf_queue,
-+};
-+
-+static unsigned int imq_nf_hook(unsigned int hook, struct sk_buff **pskb,
-+ const struct net_device *indev,
-+ const struct net_device *outdev,
-+ int (*okfn)(struct sk_buff *))
-+{
-+ if ((*pskb)->imq_flags & IMQ_F_ENQUEUE)
-+ return NF_QUEUE;
-+
-+ return NF_ACCEPT;
-+}
-+
-+
-+static int __init imq_init_hooks(void)
-+{
-+ int err;
-+
-+ err = nf_register_queue_handler(PF_INET, &nfqh);
-+ if (err > 0)
-+ goto err1;
-+ if ((err = nf_register_hook(&imq_ingress_ipv4)))
-+ goto err2;
-+ if ((err = nf_register_hook(&imq_egress_ipv4)))
-+ goto err3;
-+#if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
-+ if ((err = nf_register_queue_handler(PF_INET6, &nfqh)))
-+ goto err4;
-+ if ((err = nf_register_hook(&imq_ingress_ipv6)))
-+ goto err5;
-+ if ((err = nf_register_hook(&imq_egress_ipv6)))
-+ goto err6;
-+#endif
-+
-+ return 0;
-+
-+#if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
-+err6:
-+ nf_unregister_hook(&imq_ingress_ipv6);
-+err5:
-+ nf_unregister_queue_handler(PF_INET6, &nfqh);
-+err4:
-+ nf_unregister_hook(&imq_egress_ipv4);
-+#endif
-+err3:
-+ nf_unregister_hook(&imq_ingress_ipv4);
-+err2:
-+ nf_unregister_queue_handler(PF_INET, &nfqh);
-+err1:
-+ return err;
-+}
-+
-+static void __exit imq_unhook(void)
-+{
-+#if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
-+ nf_unregister_hook(&imq_ingress_ipv6);
-+ nf_unregister_hook(&imq_egress_ipv6);
-+ nf_unregister_queue_handler(PF_INET6, &nfqh);
-+#endif
-+ nf_unregister_hook(&imq_ingress_ipv4);
-+ nf_unregister_hook(&imq_egress_ipv4);
-+ nf_unregister_queue_handler(PF_INET, &nfqh);
-+}
-+
-+static int __init imq_dev_init(struct net_device *dev)
-+{
-+ dev->hard_start_xmit = imq_dev_xmit;
-+ dev->type = ARPHRD_VOID;
-+ dev->mtu = 16000;
-+ dev->tx_queue_len = 11000;
-+ dev->flags = IFF_NOARP;
-+ dev->priv = kzalloc(sizeof(struct net_device_stats), GFP_KERNEL);
-+ if (dev->priv == NULL)
-+ return -ENOMEM;
-+ dev->get_stats = imq_get_stats;
-+
-+ return 0;
-+}
-+
-+static void imq_dev_uninit(struct net_device *dev)
-+{
-+ kfree(dev->priv);
-+}
-+
-+static int __init imq_init_devs(void)
-+{
-+ struct net_device *dev;
-+ int i,j;
-+ j = numdevs;
-+
-+ if (!numdevs || numdevs > IMQ_MAX_DEVS) {
-+ printk(KERN_ERR "IMQ: numdevs has to be betweed 1 and %u\n",
-+ IMQ_MAX_DEVS);
-+ return -EINVAL;
-+ }
-+
-+ imq_devs = kzalloc(sizeof(struct net_device) * numdevs, GFP_KERNEL);
-+ if (!imq_devs)
-+ return -ENOMEM;
-+
-+ /* we start counting at zero */
-+ numdevs--;
-+
-+ for (i = 0, dev = imq_devs; i <= numdevs; i++, dev++) {
-+ SET_MODULE_OWNER(dev);
-+ strcpy(dev->name, "imq%d");
-+ dev->init = imq_dev_init;
-+ dev->uninit = imq_dev_uninit;
-+
-+ if (register_netdev(dev) < 0)
-+ goto err_register;
-+ }
-+ printk(KERN_INFO "IMQ starting with %u devices...\n", j);
-+ return 0;
-+
-+err_register:
-+ for (; i; i--)
-+ unregister_netdev(--dev);
-+ kfree(imq_devs);
-+ return -EIO;
-+}
-+
-+static void imq_cleanup_devs(void)
-+{
-+ int i;
-+ struct net_device *dev = imq_devs;
-+
-+ for (i = 0; i <= numdevs; i++)
-+ unregister_netdev(dev++);
-+
-+ kfree(imq_devs);
-+}
-+
-+static int __init imq_init_module(void)
-+{
-+ int err;
-+
-+ if ((err = imq_init_devs())) {
-+ printk(KERN_ERR "IMQ: Error trying imq_init_devs()\n");
-+ return err;
-+ }
-+ if ((err = imq_init_hooks())) {
-+ printk(KERN_ERR "IMQ: Error trying imq_init_hooks()\n");
-+ imq_cleanup_devs();
-+ return err;
-+ }
-+
-+ printk(KERN_INFO "IMQ driver loaded successfully.\n");
-+
-+#if defined(CONFIG_IMQ_BEHAVIOR_BA) || defined(CONFIG_IMQ_BEHAVIOR_BB)
-+ printk(KERN_INFO "\tHooking IMQ before NAT on PREROUTING.\n");
-+#else
-+ printk(KERN_INFO "\tHooking IMQ after NAT on PREROUTING.\n");
-+#endif
-+#if defined(CONFIG_IMQ_BEHAVIOR_AB) || defined(CONFIG_IMQ_BEHAVIOR_BB)
-+ printk(KERN_INFO "\tHooking IMQ before NAT on POSTROUTING.\n");
-+#else
-+ printk(KERN_INFO "\tHooking IMQ after NAT on POSTROUTING.\n");
-+#endif
-+
-+ return 0;
-+}
-+
-+static void __exit imq_cleanup_module(void)
-+{
-+ imq_unhook();
-+ imq_cleanup_devs();
-+ printk(KERN_INFO "IMQ driver unloaded successfully.\n");
-+}
-+
-+
-+module_init(imq_init_module);
-+module_exit(imq_cleanup_module);
-+
-+module_param(numdevs, int, 16);
-+MODULE_PARM_DESC(numdevs, "number of IMQ devices (how many imq* devices will be created)");
-+MODULE_AUTHOR("http://www.linuximq.net");
-+MODULE_DESCRIPTION("Pseudo-driver for the intermediate queue device. See http://www.linuximq.net/ for more information.");
-+MODULE_LICENSE("GPL");
---- a/drivers/net/Kconfig
-+++ b/drivers/net/Kconfig
-@@ -112,6 +112,129 @@
- To compile this driver as a module, choose M here: the module
- will be called eql. If unsure, say N.
-
-+config IMQ
-+ tristate "IMQ (intermediate queueing device) support"
-+ depends on NETDEVICES && NETFILTER
-+ ---help---
-+ The IMQ device(s) is used as placeholder for QoS queueing
-+ disciplines. Every packet entering/leaving the IP stack can be
-+ directed through the IMQ device where it's enqueued/dequeued to the
-+ attached qdisc. This allows you to treat network devices as classes
-+ and distribute bandwidth among them. Iptables is used to specify
-+ through which IMQ device, if any, packets travel.
-+
-+ More information at: http://www.linuximq.net/
-+
-+ To compile this driver as a module, choose M here: the module
-+ will be called imq. If unsure, say N.
-+
-+choice
-+ prompt "IMQ behavior (PRE/POSTROUTING)"
-+ depends on IMQ
-+ default IMQ_BEHAVIOR_AB
-+ help
-+
-+ This settings defines how IMQ behaves in respect to its
-+ hooking in PREROUTING and POSTROUTING.
-+
-+ IMQ can work in any of the following ways:
-+
-+ PREROUTING | POSTROUTING
-+ -----------------|-------------------
-+ #1 After NAT | After NAT
-+ #2 After NAT | Before NAT
-+ #3 Before NAT | After NAT
-+ #4 Before NAT | Before NAT
-+
-+ The default behavior is to hook before NAT on PREROUTING
-+ and after NAT on POSTROUTING (#3).
-+
-+ This settings are specially usefull when trying to use IMQ
-+ to shape NATed clients.
-+
-+ More information can be found at: www.linuximq.net
-+
-+ If not sure leave the default settings alone.
-+
-+config IMQ_BEHAVIOR_AA
-+ bool "IMQ AA"
-+ help
-+ This settings defines how IMQ behaves in respect to its
-+ hooking in PREROUTING and POSTROUTING.
-+
-+ Choosing this option will make IMQ hook like this:
-+
-+ PREROUTING: After NAT
-+ POSTROUTING: After NAT
-+
-+ More information can be found at: www.linuximq.net
-+
-+ If not sure leave the default settings alone.
-+
-+config IMQ_BEHAVIOR_AB
-+ bool "IMQ AB"
-+ help
-+ This settings defines how IMQ behaves in respect to its
-+ hooking in PREROUTING and POSTROUTING.
-+
-+ Choosing this option will make IMQ hook like this:
-+
-+ PREROUTING: After NAT
-+ POSTROUTING: Before NAT
-+
-+ More information can be found at: www.linuximq.net
-+
-+ If not sure leave the default settings alone.
-+
-+config IMQ_BEHAVIOR_BA
-+ bool "IMQ BA"
-+ help
-+ This settings defines how IMQ behaves in respect to its
-+ hooking in PREROUTING and POSTROUTING.
-+
-+ Choosing this option will make IMQ hook like this:
-+
-+ PREROUTING: Before NAT
-+ POSTROUTING: After NAT
-+
-+ More information can be found at: www.linuximq.net
-+
-+ If not sure leave the default settings alone.
-+
-+config IMQ_BEHAVIOR_BB
-+ bool "IMQ BB"
-+ help
-+ This settings defines how IMQ behaves in respect to its
-+ hooking in PREROUTING and POSTROUTING.
-+
-+ Choosing this option will make IMQ hook like this:
-+
-+ PREROUTING: Before NAT
-+ POSTROUTING: Before NAT
-+
-+ More information can be found at: www.linuximq.net
-+
-+ If not sure leave the default settings alone.
-+
-+endchoice
-+
-+config IMQ_NUM_DEVS
-+
-+ int "Number of IMQ devices"
-+ range 2 16
-+ depends on IMQ
-+ default "16"
-+ help
-+
-+ This settings defines how many IMQ devices will be
-+ created.
-+
-+ The default value is 16.
-+
-+ More information can be found at: www.linuximq.net
-+
-+ If not sure leave the default settings alone.
-+
- config TUN
- tristate "Universal TUN/TAP device driver support"
- select CRC32
---- a/drivers/net/Makefile
-+++ b/drivers/net/Makefile
-@@ -131,6 +131,7 @@
- obj-$(CONFIG_XEN_NETDEV_FRONTEND) += xen-netfront.o
-
- obj-$(CONFIG_DUMMY) += dummy.o
-+obj-$(CONFIG_IMQ) += imq.o
- obj-$(CONFIG_IFB) += ifb.o
- obj-$(CONFIG_MACVLAN) += macvlan.o
- obj-$(CONFIG_DE600) += de600.o
---- /dev/null
-+++ b/include/linux/imq.h
-@@ -0,0 +1,9 @@
-+#ifndef _IMQ_H
-+#define _IMQ_H
-+
-+#define IMQ_MAX_DEVS 16
-+
-+#define IMQ_F_IFMASK 0x7f
-+#define IMQ_F_ENQUEUE 0x80
-+
-+#endif /* _IMQ_H */
---- /dev/null
-+++ b/include/linux/netfilter_ipv4/ipt_IMQ.h
-@@ -0,0 +1,8 @@
-+#ifndef _IPT_IMQ_H
-+#define _IPT_IMQ_H
-+
-+struct ipt_imq_info {
-+ unsigned int todev; /* target imq device */
-+};
-+
-+#endif /* _IPT_IMQ_H */
---- /dev/null
-+++ b/include/linux/netfilter_ipv6/ip6t_IMQ.h
-@@ -0,0 +1,8 @@
-+#ifndef _IP6T_IMQ_H
-+#define _IP6T_IMQ_H
-+
-+struct ip6t_imq_info {
-+ unsigned int todev; /* target imq device */
-+};
-+
-+#endif /* _IP6T_IMQ_H */
---- a/include/linux/skbuff.h
-+++ b/include/linux/skbuff.h
-@@ -295,6 +295,10 @@
- struct nf_conntrack *nfct;
- struct sk_buff *nfct_reasm;
- #endif
-+#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
-+ unsigned char imq_flags;
-+ struct nf_info *nf_info;
-+#endif
- #ifdef CONFIG_BRIDGE_NETFILTER
- struct nf_bridge_info *nf_bridge;
- #endif
-@@ -1725,6 +1729,10 @@
- dst->nfct_reasm = src->nfct_reasm;
- nf_conntrack_get_reasm(src->nfct_reasm);
- #endif
-+#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
-+ dst->imq_flags = src->imq_flags;
-+ dst->nf_info = src->nf_info;
-+#endif
- #ifdef CONFIG_BRIDGE_NETFILTER
- dst->nf_bridge = src->nf_bridge;
- nf_bridge_get(src->nf_bridge);
---- a/net/core/dev.c
-+++ b/net/core/dev.c
-@@ -94,6 +94,9 @@
- #include <linux/skbuff.h>
- #include <net/sock.h>
- #include <linux/rtnetlink.h>
-+#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
-+#include <linux/imq.h>
-+#endif
- #include <linux/proc_fs.h>
- #include <linux/seq_file.h>
- #include <linux/stat.h>
-@@ -1462,7 +1465,11 @@
- int dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
- {
- if (likely(!skb->next)) {
-- if (!list_empty(&ptype_all))
-+ if (!list_empty(&ptype_all)
-+#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
-+ && !(skb->imq_flags & IMQ_F_ENQUEUE)
-+#endif
-+ )
- dev_queue_xmit_nit(skb, dev);
-
- if (netif_needs_gso(dev, skb)) {
---- /dev/null
-+++ b/net/ipv4/netfilter/ipt_IMQ.c
-@@ -0,0 +1,69 @@
-+/*
-+ * This target marks packets to be enqueued to an imq device
-+ */
-+#include <linux/module.h>
-+#include <linux/skbuff.h>
-+#include <linux/netfilter_ipv4/ip_tables.h>
-+#include <linux/netfilter_ipv4/ipt_IMQ.h>
-+#include <linux/imq.h>
-+
-+static unsigned int imq_target(struct sk_buff **pskb,
-+ const struct net_device *in,
-+ const struct net_device *out,
-+ unsigned int hooknum,
-+ const struct xt_target *target,
-+ const void *targinfo)
-+{
-+ struct ipt_imq_info *mr = (struct ipt_imq_info*)targinfo;
-+
-+ (*pskb)->imq_flags = mr->todev | IMQ_F_ENQUEUE;
-+
-+ return XT_CONTINUE;
-+}
-+
-+static bool imq_checkentry(const char *tablename,
-+ const void *e,
-+ const struct xt_target *target,
-+ void *targinfo,
-+ unsigned int hook_mask)
-+{
-+ struct ipt_imq_info *mr;
-+
-+ mr = (struct ipt_imq_info*)targinfo;
-+
-+ if (mr->todev > IMQ_MAX_DEVS) {
-+ printk(KERN_WARNING
-+ "IMQ: invalid device specified, highest is %u\n",
-+ IMQ_MAX_DEVS);
-+ return 0;
-+ }
-+
-+ return 1;
-+}
-+
-+static struct xt_target ipt_imq_reg = {
-+ .name = "IMQ",
-+ .family = AF_INET,
-+ .target = imq_target,
-+ .targetsize = sizeof(struct ipt_imq_info),
-+ .checkentry = imq_checkentry,
-+ .me = THIS_MODULE,
-+ .table = "mangle"
-+};
-+
-+static int __init init(void)
-+{
-+ return xt_register_target(&ipt_imq_reg);
-+}
-+
-+static void __exit fini(void)
-+{
-+ xt_unregister_target(&ipt_imq_reg);
-+}
-+
-+module_init(init);
-+module_exit(fini);
-+
-+MODULE_AUTHOR("http://www.linuximq.net");
-+MODULE_DESCRIPTION("Pseudo-driver for the intermediate queue device. See http://www.linuximq.net/ for more information.");
-+MODULE_LICENSE("GPL");
---- a/net/ipv4/netfilter/Kconfig
-+++ b/net/ipv4/netfilter/Kconfig
-@@ -333,6 +333,17 @@
-
- To compile it as a module, choose M here. If unsure, say N.
-
-+config IP_NF_TARGET_IMQ
-+ tristate "IMQ target support"
-+ depends on IP_NF_MANGLE
-+ help
-+ This option adds a `IMQ' target which is used to specify if and
-+ to which IMQ device packets should get enqueued/dequeued.
-+
-+ For more information visit: http://www.linuximq.net/
-+
-+ To compile it as a module, choose M here. If unsure, say N.
-+
- config IP_NF_TARGET_TOS
- tristate "TOS target support"
- depends on IP_NF_MANGLE
---- a/net/ipv4/netfilter/Makefile
-+++ b/net/ipv4/netfilter/Makefile
-@@ -58,6 +58,7 @@
- obj-$(CONFIG_IP_NF_TARGET_REJECT) += ipt_REJECT.o
- obj-$(CONFIG_IP_NF_TARGET_TOS) += ipt_TOS.o
- obj-$(CONFIG_IP_NF_TARGET_ECN) += ipt_ECN.o
-+obj-$(CONFIG_IP_NF_TARGET_IMQ) += ipt_IMQ.o
- obj-$(CONFIG_IP_NF_TARGET_MASQUERADE) += ipt_MASQUERADE.o
- obj-$(CONFIG_IP_NF_TARGET_REDIRECT) += ipt_REDIRECT.o
- obj-$(CONFIG_IP_NF_TARGET_NETMAP) += ipt_NETMAP.o
---- /dev/null
-+++ b/net/ipv6/netfilter/ip6t_IMQ.c
-@@ -0,0 +1,69 @@
-+/*
-+ * This target marks packets to be enqueued to an imq device
-+ */
-+#include <linux/module.h>
-+#include <linux/skbuff.h>
-+#include <linux/netfilter_ipv6/ip6_tables.h>
-+#include <linux/netfilter_ipv6/ip6t_IMQ.h>
-+#include <linux/imq.h>
-+
-+static unsigned int imq_target(struct sk_buff **pskb,
-+ const struct net_device *in,
-+ const struct net_device *out,
-+ unsigned int hooknum,
-+ const struct xt_target *target,
-+ const void *targinfo)
-+{
-+ struct ip6t_imq_info *mr = (struct ip6t_imq_info*)targinfo;
-+
-+ (*pskb)->imq_flags = mr->todev | IMQ_F_ENQUEUE;
-+
-+ return XT_CONTINUE;
-+}
-+
-+static bool imq_checkentry(const char *tablename,
-+ const void *entry,
-+ const struct xt_target *target,
-+ void *targinfo,
-+ unsigned int hook_mask)
-+{
-+ struct ip6t_imq_info *mr;
-+
-+ mr = (struct ip6t_imq_info*)targinfo;
-+
-+ if (mr->todev > IMQ_MAX_DEVS) {
-+ printk(KERN_WARNING
-+ "IMQ: invalid device specified, highest is %u\n",
-+ IMQ_MAX_DEVS);
-+ return 0;
-+ }
-+
-+ return 1;
-+}
-+
-+static struct xt_target ip6t_imq_reg = {
-+ .name = "IMQ",
-+ .family = AF_INET6,
-+ .target = imq_target,
-+ .targetsize = sizeof(struct ip6t_imq_info),
-+ .table = "mangle",
-+ .checkentry = imq_checkentry,
-+ .me = THIS_MODULE
-+};
-+
-+static int __init init(void)
-+{
-+ return xt_register_target(&ip6t_imq_reg);
-+}
-+
-+static void __exit fini(void)
-+{
-+ xt_unregister_target(&ip6t_imq_reg);
-+}
-+
-+module_init(init);
-+module_exit(fini);
-+
-+MODULE_AUTHOR("http://www.linuximq.net");
-+MODULE_DESCRIPTION("Pseudo-driver for the intermediate queue device. See http://www.linuximq.net/ for more information.");
-+MODULE_LICENSE("GPL");
---- a/net/ipv6/netfilter/Kconfig
-+++ b/net/ipv6/netfilter/Kconfig
-@@ -173,6 +173,15 @@
-
- To compile it as a module, choose M here. If unsure, say N.
-
-+config IP6_NF_TARGET_IMQ
-+ tristate "IMQ target support"
-+ depends on IP6_NF_MANGLE
-+ help
-+ This option adds a `IMQ' target which is used to specify if and
-+ to which imq device packets should get enqueued/dequeued.
-+
-+ To compile it as a module, choose M here. If unsure, say N.
-+
- config IP6_NF_TARGET_HL
- tristate 'HL (hoplimit) target support'
- depends on IP6_NF_MANGLE
---- a/net/ipv6/netfilter/Makefile
-+++ b/net/ipv6/netfilter/Makefile
-@@ -13,6 +13,7 @@
- obj-$(CONFIG_IP6_NF_MATCH_OWNER) += ip6t_owner.o
- obj-$(CONFIG_IP6_NF_FILTER) += ip6table_filter.o
- obj-$(CONFIG_IP6_NF_MANGLE) += ip6table_mangle.o
-+obj-$(CONFIG_IP6_NF_TARGET_IMQ) += ip6t_IMQ.o
- obj-$(CONFIG_IP6_NF_TARGET_HL) += ip6t_HL.o
- obj-$(CONFIG_IP6_NF_QUEUE) += ip6_queue.o
- obj-$(CONFIG_IP6_NF_TARGET_LOG) += ip6t_LOG.o
---- a/net/sched/sch_generic.c
-+++ b/net/sched/sch_generic.c
-@@ -191,6 +191,11 @@
- return ret;
- }
-
-+int qdisc_restart1(struct net_device *dev)
-+{
-+ return qdisc_restart(dev);
-+}
-+
- void __qdisc_run(struct net_device *dev)
- {
- do {
-@@ -620,3 +625,4 @@
- EXPORT_SYMBOL(qdisc_reset);
- EXPORT_SYMBOL(qdisc_lock_tree);
- EXPORT_SYMBOL(qdisc_unlock_tree);
-+EXPORT_SYMBOL(qdisc_restart1);
+++ /dev/null
---- /dev/null
-+++ b/include/linux/netfilter_ipv4/ipt_ROUTE.h
-@@ -0,0 +1,23 @@
-+/* Header file for iptables ipt_ROUTE target
-+ *
-+ * (C) 2002 by Cédric de Launois <delaunois@info.ucl.ac.be>
-+ *
-+ * This software is distributed under GNU GPL v2, 1991
-+ */
-+#ifndef _IPT_ROUTE_H_target
-+#define _IPT_ROUTE_H_target
-+
-+#define IPT_ROUTE_IFNAMSIZ 16
-+
-+struct ipt_route_target_info {
-+ char oif[IPT_ROUTE_IFNAMSIZ]; /* Output Interface Name */
-+ char iif[IPT_ROUTE_IFNAMSIZ]; /* Input Interface Name */
-+ u_int32_t gw; /* IP address of gateway */
-+ u_int8_t flags;
-+};
-+
-+/* Values for "flags" field */
-+#define IPT_ROUTE_CONTINUE 0x01
-+#define IPT_ROUTE_TEE 0x02
-+
-+#endif /*_IPT_ROUTE_H_target*/
---- /dev/null
-+++ b/include/linux/netfilter_ipv6/ip6t_ROUTE.h
-@@ -0,0 +1,23 @@
-+/* Header file for iptables ip6t_ROUTE target
-+ *
-+ * (C) 2003 by Cédric de Launois <delaunois@info.ucl.ac.be>
-+ *
-+ * This software is distributed under GNU GPL v2, 1991
-+ */
-+#ifndef _IPT_ROUTE_H_target
-+#define _IPT_ROUTE_H_target
-+
-+#define IP6T_ROUTE_IFNAMSIZ 16
-+
-+struct ip6t_route_target_info {
-+ char oif[IP6T_ROUTE_IFNAMSIZ]; /* Output Interface Name */
-+ char iif[IP6T_ROUTE_IFNAMSIZ]; /* Input Interface Name */
-+ u_int32_t gw[4]; /* IPv6 address of gateway */
-+ u_int8_t flags;
-+};
-+
-+/* Values for "flags" field */
-+#define IP6T_ROUTE_CONTINUE 0x01
-+#define IP6T_ROUTE_TEE 0x02
-+
-+#endif /*_IP6T_ROUTE_H_target*/
---- /dev/null
-+++ b/net/ipv4/netfilter/ipt_ROUTE.c
-@@ -0,0 +1,463 @@
-+/*
-+ * This implements the ROUTE target, which enables you to setup unusual
-+ * routes not supported by the standard kernel routing table.
-+ *
-+ * Copyright (C) 2002 Cedric de Launois <delaunois@info.ucl.ac.be>
-+ *
-+ * v 1.11 2004/11/23
-+ *
-+ * This software is distributed under GNU GPL v2, 1991
-+ */
-+
-+#include <linux/module.h>
-+#include <linux/skbuff.h>
-+#include <linux/ip.h>
-+#include <linux/netfilter_ipv4/ip_tables.h>
-+#include <net/netfilter/nf_conntrack.h>
-+#include <linux/netfilter_ipv4/ipt_ROUTE.h>
-+#include <linux/netdevice.h>
-+#include <linux/route.h>
-+#include <linux/version.h>
-+#include <linux/if_arp.h>
-+#include <net/ip.h>
-+#include <net/route.h>
-+#include <net/icmp.h>
-+#include <net/checksum.h>
-+
-+#if 0
-+#define DEBUGP printk
-+#else
-+#define DEBUGP(format, args...)
-+#endif
-+
-+MODULE_LICENSE("GPL");
-+MODULE_AUTHOR("Cedric de Launois <delaunois@info.ucl.ac.be>");
-+MODULE_DESCRIPTION("iptables ROUTE target module");
-+
-+/* Try to route the packet according to the routing keys specified in
-+ * route_info. Keys are :
-+ * - ifindex :
-+ * 0 if no oif preferred,
-+ * otherwise set to the index of the desired oif
-+ * - route_info->gw :
-+ * 0 if no gateway specified,
-+ * otherwise set to the next host to which the pkt must be routed
-+ * If success, skb->dev is the output device to which the packet must
-+ * be sent and skb->dst is not NULL
-+ *
-+ * RETURN: -1 if an error occured
-+ * 1 if the packet was succesfully routed to the
-+ * destination desired
-+ * 0 if the kernel routing table could not route the packet
-+ * according to the keys specified
-+ */
-+static int route(struct sk_buff *skb,
-+ unsigned int ifindex,
-+ const struct ipt_route_target_info *route_info)
-+{
-+ int err;
-+ struct rtable *rt;
-+ struct iphdr *iph = ip_hdr(skb);
-+ struct flowi fl = {
-+ .oif = ifindex,
-+ .nl_u = {
-+ .ip4_u = {
-+ .daddr = iph->daddr,
-+ .saddr = 0,
-+ .tos = RT_TOS(iph->tos),
-+ .scope = RT_SCOPE_UNIVERSE,
-+ }
-+ }
-+ };
-+
-+ /* The destination address may be overloaded by the target */
-+ if (route_info->gw)
-+ fl.fl4_dst = route_info->gw;
-+
-+ /* Trying to route the packet using the standard routing table. */
-+ if ((err = ip_route_output_key(&rt, &fl))) {
-+ if (net_ratelimit())
-+ DEBUGP("ipt_ROUTE: couldn't route pkt (err: %i)",err);
-+ return -1;
-+ }
-+
-+ /* Drop old route. */
-+ dst_release(skb->dst);
-+ skb->dst = NULL;
-+
-+ /* Success if no oif specified or if the oif correspond to the
-+ * one desired */
-+ if (!ifindex || rt->u.dst.dev->ifindex == ifindex) {
-+ skb->dst = &rt->u.dst;
-+ skb->dev = skb->dst->dev;
-+ skb->protocol = htons(ETH_P_IP);
-+ return 1;
-+ }
-+
-+ /* The interface selected by the routing table is not the one
-+ * specified by the user. This may happen because the dst address
-+ * is one of our own addresses.
-+ */
-+ if (net_ratelimit())
-+ DEBUGP("ipt_ROUTE: failed to route as desired gw=%u.%u.%u.%u oif=%i (got oif=%i)\n",
-+ NIPQUAD(route_info->gw), ifindex, rt->u.dst.dev->ifindex);
-+
-+ return 0;
-+}
-+
-+
-+/* Stolen from ip_finish_output2
-+ * PRE : skb->dev is set to the device we are leaving by
-+ * skb->dst is not NULL
-+ * POST: the packet is sent with the link layer header pushed
-+ * the packet is destroyed
-+ */
-+static void ip_direct_send(struct sk_buff *skb)
-+{
-+ struct dst_entry *dst = skb->dst;
-+ struct hh_cache *hh = dst->hh;
-+ struct net_device *dev = dst->dev;
-+ int hh_len = LL_RESERVED_SPACE(dev);
-+
-+ /* Be paranoid, rather than too clever. */
-+ if (unlikely(skb_headroom(skb) < hh_len && dev->hard_header)) {
-+ struct sk_buff *skb2;
-+
-+ skb2 = skb_realloc_headroom(skb, LL_RESERVED_SPACE(dev));
-+ if (skb2 == NULL) {
-+ kfree_skb(skb);
-+ return;
-+ }
-+ if (skb->sk)
-+ skb_set_owner_w(skb2, skb->sk);
-+ kfree_skb(skb);
-+ skb = skb2;
-+ }
-+
-+ if (hh) {
-+ int hh_alen;
-+
-+ read_lock_bh(&hh->hh_lock);
-+ hh_alen = HH_DATA_ALIGN(hh->hh_len);
-+ memcpy(skb->data - hh_alen, hh->hh_data, hh_alen);
-+ read_unlock_bh(&hh->hh_lock);
-+ skb_push(skb, hh->hh_len);
-+ hh->hh_output(skb);
-+ } else if (dst->neighbour)
-+ dst->neighbour->output(skb);
-+ else {
-+ if (net_ratelimit())
-+ DEBUGP(KERN_DEBUG "ipt_ROUTE: no hdr & no neighbour cache!\n");
-+ kfree_skb(skb);
-+ }
-+}
-+
-+
-+/* PRE : skb->dev is set to the device we are leaving by
-+ * POST: - the packet is directly sent to the skb->dev device, without
-+ * pushing the link layer header.
-+ * - the packet is destroyed
-+ */
-+static inline int dev_direct_send(struct sk_buff *skb)
-+{
-+ return dev_queue_xmit(skb);
-+}
-+
-+
-+static unsigned int route_oif(const struct ipt_route_target_info *route_info,
-+ struct sk_buff *skb)
-+{
-+ unsigned int ifindex = 0;
-+ struct net_device *dev_out = NULL;
-+
-+ /* The user set the interface name to use.
-+ * Getting the current interface index.
-+ */
-+ if ((dev_out = dev_get_by_name(route_info->oif))) {
-+ ifindex = dev_out->ifindex;
-+ } else {
-+ /* Unknown interface name : packet dropped */
-+ if (net_ratelimit())
-+ DEBUGP("ipt_ROUTE: oif interface %s not found\n", route_info->oif);
-+ return NF_DROP;
-+ }
-+
-+ /* Trying the standard way of routing packets */
-+ switch (route(skb, ifindex, route_info)) {
-+ case 1:
-+ dev_put(dev_out);
-+ if (route_info->flags & IPT_ROUTE_CONTINUE)
-+ return IPT_CONTINUE;
-+
-+ ip_direct_send(skb);
-+ return NF_STOLEN;
-+
-+ case 0:
-+ /* Failed to send to oif. Trying the hard way */
-+ if (route_info->flags & IPT_ROUTE_CONTINUE)
-+ return NF_DROP;
-+
-+ if (net_ratelimit())
-+ DEBUGP("ipt_ROUTE: forcing the use of %i\n",
-+ ifindex);
-+
-+ /* We have to force the use of an interface.
-+ * This interface must be a tunnel interface since
-+ * otherwise we can't guess the hw address for
-+ * the packet. For a tunnel interface, no hw address
-+ * is needed.
-+ */
-+ if ((dev_out->type != ARPHRD_TUNNEL)
-+ && (dev_out->type != ARPHRD_IPGRE)) {
-+ if (net_ratelimit())
-+ DEBUGP("ipt_ROUTE: can't guess the hw addr !\n");
-+ dev_put(dev_out);
-+ return NF_DROP;
-+ }
-+
-+ /* Send the packet. This will also free skb
-+ * Do not go through the POST_ROUTING hook because
-+ * skb->dst is not set and because it will probably
-+ * get confused by the destination IP address.
-+ */
-+ skb->dev = dev_out;
-+ dev_direct_send(skb);
-+ dev_put(dev_out);
-+ return NF_STOLEN;
-+
-+ default:
-+ /* Unexpected error */
-+ dev_put(dev_out);
-+ return NF_DROP;
-+ }
-+}
-+
-+
-+static unsigned int route_iif(const struct ipt_route_target_info *route_info,
-+ struct sk_buff *skb)
-+{
-+ struct net_device *dev_in = NULL;
-+
-+ /* Getting the current interface index. */
-+ if (!(dev_in = dev_get_by_name(route_info->iif))) {
-+ if (net_ratelimit())
-+ DEBUGP("ipt_ROUTE: iif interface %s not found\n", route_info->iif);
-+ return NF_DROP;
-+ }
-+
-+ skb->dev = dev_in;
-+ dst_release(skb->dst);
-+ skb->dst = NULL;
-+
-+ netif_rx(skb);
-+ dev_put(dev_in);
-+ return NF_STOLEN;
-+}
-+
-+
-+static unsigned int route_gw(const struct ipt_route_target_info *route_info,
-+ struct sk_buff *skb)
-+{
-+ if (route(skb, 0, route_info)!=1)
-+ return NF_DROP;
-+
-+ if (route_info->flags & IPT_ROUTE_CONTINUE)
-+ return IPT_CONTINUE;
-+
-+ ip_direct_send(skb);
-+ return NF_STOLEN;
-+}
-+
-+
-+/* To detect and deter routed packet loopback when using the --tee option,
-+ * we take a page out of the raw.patch book: on the copied skb, we set up
-+ * a fake ->nfct entry, pointing to the local &route_tee_track. We skip
-+ * routing packets when we see they already have that ->nfct.
-+ */
-+
-+static struct nf_conn route_tee_track;
-+
-+static unsigned int ipt_route_target(struct sk_buff **pskb,
-+ const struct net_device *in,
-+ const struct net_device *out,
-+ unsigned int hooknum,
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17)
-+ const struct xt_target *target,
-+#endif
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
-+ const void *targinfo,
-+ void *userinfo)
-+#else
-+ const void *targinfo)
-+#endif
-+{
-+ const struct ipt_route_target_info *route_info = targinfo;
-+ struct sk_buff *skb = *pskb;
-+ unsigned int res;
-+
-+ if (skb->nfct == &route_tee_track.ct_general) {
-+ /* Loopback - a packet we already routed, is to be
-+ * routed another time. Avoid that, now.
-+ */
-+ if (net_ratelimit())
-+ DEBUGP(KERN_DEBUG "ipt_ROUTE: loopback - DROP!\n");
-+ return NF_DROP;
-+ }
-+
-+ /* If we are at PREROUTING or INPUT hook
-+ * the TTL isn't decreased by the IP stack
-+ */
-+ if (hooknum == NF_IP_PRE_ROUTING ||
-+ hooknum == NF_IP_LOCAL_IN) {
-+
-+ struct iphdr *iph = ip_hdr(skb);
-+
-+ if (iph->ttl <= 1) {
-+ struct rtable *rt;
-+ struct flowi fl = {
-+ .oif = 0,
-+ .nl_u = {
-+ .ip4_u = {
-+ .daddr = iph->daddr,
-+ .saddr = iph->saddr,
-+ .tos = RT_TOS(iph->tos),
-+ .scope = ((iph->tos & RTO_ONLINK) ?
-+ RT_SCOPE_LINK :
-+ RT_SCOPE_UNIVERSE)
-+ }
-+ }
-+ };
-+
-+ if (ip_route_output_key(&rt, &fl)) {
-+ return NF_DROP;
-+ }
-+
-+ if (skb->dev == rt->u.dst.dev) {
-+ /* Drop old route. */
-+ dst_release(skb->dst);
-+ skb->dst = &rt->u.dst;
-+
-+ /* this will traverse normal stack, and
-+ * thus call conntrack on the icmp packet */
-+ icmp_send(skb, ICMP_TIME_EXCEEDED,
-+ ICMP_EXC_TTL, 0);
-+ }
-+
-+ return NF_DROP;
-+ }
-+
-+ /*
-+ * If we are at INPUT the checksum must be recalculated since
-+ * the length could change as the result of a defragmentation.
-+ */
-+ if(hooknum == NF_IP_LOCAL_IN) {
-+ iph->ttl = iph->ttl - 1;
-+ iph->check = 0;
-+ iph->check = ip_fast_csum((unsigned char *)iph, iph->ihl);
-+ } else {
-+ ip_decrease_ttl(iph);
-+ }
-+ }
-+
-+ if ((route_info->flags & IPT_ROUTE_TEE)) {
-+ /*
-+ * Copy the *pskb, and route the copy. Will later return
-+ * IPT_CONTINUE for the original skb, which should continue
-+ * on its way as if nothing happened. The copy should be
-+ * independantly delivered to the ROUTE --gw.
-+ */
-+ skb = skb_copy(*pskb, GFP_ATOMIC);
-+ if (!skb) {
-+ if (net_ratelimit())
-+ DEBUGP(KERN_DEBUG "ipt_ROUTE: copy failed!\n");
-+ return IPT_CONTINUE;
-+ }
-+ }
-+
-+ /* Tell conntrack to forget this packet since it may get confused
-+ * when a packet is leaving with dst address == our address.
-+ * Good idea ? Dunno. Need advice.
-+ *
-+ * NEW: mark the skb with our &route_tee_track, so we avoid looping
-+ * on any already routed packet.
-+ */
-+ if (!(route_info->flags & IPT_ROUTE_CONTINUE)) {
-+ nf_conntrack_put(skb->nfct);
-+ skb->nfct = &route_tee_track.ct_general;
-+ skb->nfctinfo = IP_CT_NEW;
-+ nf_conntrack_get(skb->nfct);
-+ }
-+
-+ if (route_info->oif[0] != '\0') {
-+ res = route_oif(route_info, skb);
-+ } else if (route_info->iif[0] != '\0') {
-+ res = route_iif(route_info, skb);
-+ } else if (route_info->gw) {
-+ res = route_gw(route_info, skb);
-+ } else {
-+ if (net_ratelimit())
-+ DEBUGP(KERN_DEBUG "ipt_ROUTE: no parameter !\n");
-+ res = IPT_CONTINUE;
-+ }
-+
-+ if ((route_info->flags & IPT_ROUTE_TEE))
-+ res = IPT_CONTINUE;
-+
-+ return res;
-+}
-+
-+
-+static bool ipt_route_checkentry(const char *tablename,
-+ const void *e,
-+ const struct xt_target *target,
-+ void *targinfo,
-+ unsigned int hook_mask)
-+{
-+ if (strcmp(tablename, "mangle") != 0) {
-+ printk("ipt_ROUTE: bad table `%s', use the `mangle' table.\n",
-+ tablename);
-+ return 0;
-+ }
-+
-+ if (hook_mask & ~( (1 << NF_IP_PRE_ROUTING)
-+ | (1 << NF_IP_LOCAL_IN)
-+ | (1 << NF_IP_FORWARD)
-+ | (1 << NF_IP_LOCAL_OUT)
-+ | (1 << NF_IP_POST_ROUTING))) {
-+ printk("ipt_ROUTE: bad hook\n");
-+ return 0;
-+ }
-+
-+ return 1;
-+}
-+
-+
-+static struct ipt_target ipt_route_reg = {
-+ .name = "ROUTE",
-+ .target = ipt_route_target,
-+ .targetsize = sizeof(struct ipt_route_target_info),
-+ .checkentry = ipt_route_checkentry,
-+ .me = THIS_MODULE,
-+};
-+
-+static int __init init(void)
-+{
-+ /* Set up fake conntrack (stolen from raw.patch):
-+ - to never be deleted, not in any hashes */
-+ atomic_set(&route_tee_track.ct_general.use, 1);
-+ /* - and look it like as a confirmed connection */
-+ set_bit(IPS_CONFIRMED_BIT, &route_tee_track.status);
-+ /* Initialize fake conntrack so that NAT will skip it */
-+ route_tee_track.status |= IPS_NAT_DONE_MASK;
-+
-+ return xt_register_target(&ipt_route_reg);
-+}
-+
-+
-+static void __exit fini(void)
-+{
-+ xt_unregister_target(&ipt_route_reg);
-+}
-+
-+module_init(init);
-+module_exit(fini);
---- a/net/ipv4/netfilter/Kconfig
-+++ b/net/ipv4/netfilter/Kconfig
-@@ -552,5 +552,22 @@
- To compile it as a module, choose M here. If unsure, say N.
-
-
-+config IP_NF_TARGET_ROUTE
-+ tristate 'ROUTE target support'
-+ depends on IP_NF_MANGLE
-+ help
-+ This option adds a `ROUTE' target, which enables you to setup unusual
-+ routes. For example, the ROUTE lets you route a received packet through
-+ an interface or towards a host, even if the regular destination of the
-+ packet is the router itself. The ROUTE target is also able to change the
-+ incoming interface of a packet.
-+
-+ The target can be or not a final target. It has to be used inside the
-+ mangle table.
-+
-+ If you want to compile it as a module, say M here and read
-+ Documentation/modules.txt. The module will be called ipt_ROUTE.o.
-+ If unsure, say `N'.
-+
- endmenu
-
---- a/net/ipv4/netfilter/Makefile
-+++ b/net/ipv4/netfilter/Makefile
-@@ -61,6 +61,7 @@
- obj-$(CONFIG_IP_NF_TARGET_IMQ) += ipt_IMQ.o
- obj-$(CONFIG_IP_NF_TARGET_MASQUERADE) += ipt_MASQUERADE.o
- obj-$(CONFIG_IP_NF_TARGET_REDIRECT) += ipt_REDIRECT.o
-+obj-$(CONFIG_IP_NF_TARGET_ROUTE) += ipt_ROUTE.o
- obj-$(CONFIG_IP_NF_TARGET_NETMAP) += ipt_NETMAP.o
- obj-$(CONFIG_IP_NF_TARGET_SAME) += ipt_SAME.o
- obj-$(CONFIG_IP_NF_TARGET_LOG) += ipt_LOG.o
---- a/net/ipv6/ndisc.c
-+++ b/net/ipv6/ndisc.c
-@@ -154,6 +154,8 @@
- .gc_thresh3 = 1024,
- };
-
-+EXPORT_SYMBOL(nd_tbl);
-+
- /* ND options */
- struct ndisc_options {
- struct nd_opt_hdr *nd_opt_array[__ND_OPT_ARRAY_MAX];
---- /dev/null
-+++ b/net/ipv6/netfilter/ip6t_ROUTE.c
-@@ -0,0 +1,330 @@
-+/*
-+ * This implements the ROUTE v6 target, which enables you to setup unusual
-+ * routes not supported by the standard kernel routing table.
-+ *
-+ * Copyright (C) 2003 Cedric de Launois <delaunois@info.ucl.ac.be>
-+ *
-+ * v 1.1 2004/11/23
-+ *
-+ * This software is distributed under GNU GPL v2, 1991
-+ */
-+
-+#include <linux/module.h>
-+#include <linux/skbuff.h>
-+#include <linux/ipv6.h>
-+#include <linux/netfilter_ipv6/ip6_tables.h>
-+#include <linux/netfilter_ipv6/ip6t_ROUTE.h>
-+#include <linux/netdevice.h>
-+#include <linux/version.h>
-+#include <net/ipv6.h>
-+#include <net/ndisc.h>
-+#include <net/ip6_route.h>
-+#include <linux/icmpv6.h>
-+
-+#if 1
-+#define DEBUGP printk
-+#else
-+#define DEBUGP(format, args...)
-+#endif
-+
-+#define NIP6(addr) \
-+ ntohs((addr).s6_addr16[0]), \
-+ ntohs((addr).s6_addr16[1]), \
-+ ntohs((addr).s6_addr16[2]), \
-+ ntohs((addr).s6_addr16[3]), \
-+ ntohs((addr).s6_addr16[4]), \
-+ ntohs((addr).s6_addr16[5]), \
-+ ntohs((addr).s6_addr16[6]), \
-+ ntohs((addr).s6_addr16[7])
-+
-+/* Route the packet according to the routing keys specified in
-+ * route_info. Keys are :
-+ * - ifindex :
-+ * 0 if no oif preferred,
-+ * otherwise set to the index of the desired oif
-+ * - route_info->gw :
-+ * 0 if no gateway specified,
-+ * otherwise set to the next host to which the pkt must be routed
-+ * If success, skb->dev is the output device to which the packet must
-+ * be sent and skb->dst is not NULL
-+ *
-+ * RETURN: 1 if the packet was succesfully routed to the
-+ * destination desired
-+ * 0 if the kernel routing table could not route the packet
-+ * according to the keys specified
-+ */
-+static int
-+route6(struct sk_buff *skb,
-+ unsigned int ifindex,
-+ const struct ip6t_route_target_info *route_info)
-+{
-+ struct rt6_info *rt = NULL;
-+ struct ipv6hdr *ipv6h = ipv6_hdr(skb);
-+ struct in6_addr *gw = (struct in6_addr*)&route_info->gw;
-+
-+ DEBUGP("ip6t_ROUTE: called with: ");
-+ DEBUGP("DST=%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x ", NIP6(ipv6h->daddr));
-+ DEBUGP("GATEWAY=%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x ", NIP6(*gw));
-+ DEBUGP("OUT=%s\n", route_info->oif);
-+
-+ if (ipv6_addr_any(gw))
-+ rt = rt6_lookup(&ipv6h->daddr, &ipv6h->saddr, ifindex, 1);
-+ else
-+ rt = rt6_lookup(gw, &ipv6h->saddr, ifindex, 1);
-+
-+ if (!rt)
-+ goto no_route;
-+
-+ DEBUGP("ip6t_ROUTE: routing gives: ");
-+ DEBUGP("DST=%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x ", NIP6(rt->rt6i_dst.addr));
-+ DEBUGP("GATEWAY=%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x ", NIP6(rt->rt6i_gateway));
-+ DEBUGP("OUT=%s\n", rt->rt6i_dev->name);
-+
-+ if (ifindex && rt->rt6i_dev->ifindex!=ifindex)
-+ goto wrong_route;
-+
-+ if (!rt->rt6i_nexthop) {
-+ DEBUGP("ip6t_ROUTE: discovering neighbour\n");
-+ rt->rt6i_nexthop = ndisc_get_neigh(rt->rt6i_dev, &rt->rt6i_dst.addr);
-+ }
-+
-+ /* Drop old route. */
-+ dst_release(skb->dst);
-+ skb->dst = &rt->u.dst;
-+ skb->dev = rt->rt6i_dev;
-+ return 1;
-+
-+ wrong_route:
-+ dst_release(&rt->u.dst);
-+ no_route:
-+ if (!net_ratelimit())
-+ return 0;
-+
-+ printk("ip6t_ROUTE: no explicit route found ");
-+ if (ifindex)
-+ printk("via interface %s ", route_info->oif);
-+ if (!ipv6_addr_any(gw))
-+ printk("via gateway %04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x", NIP6(*gw));
-+ printk("\n");
-+ return 0;
-+}
-+
-+
-+/* Stolen from ip6_output_finish
-+ * PRE : skb->dev is set to the device we are leaving by
-+ * skb->dst is not NULL
-+ * POST: the packet is sent with the link layer header pushed
-+ * the packet is destroyed
-+ */
-+static void ip_direct_send(struct sk_buff *skb)
-+{
-+ struct dst_entry *dst = skb->dst;
-+ struct hh_cache *hh = dst->hh;
-+
-+ if (hh) {
-+ read_lock_bh(&hh->hh_lock);
-+ memcpy(skb->data - 16, hh->hh_data, 16);
-+ read_unlock_bh(&hh->hh_lock);
-+ skb_push(skb, hh->hh_len);
-+ hh->hh_output(skb);
-+ } else if (dst->neighbour)
-+ dst->neighbour->output(skb);
-+ else {
-+ if (net_ratelimit())
-+ DEBUGP(KERN_DEBUG "ip6t_ROUTE: no hdr & no neighbour cache!\n");
-+ kfree_skb(skb);
-+ }
-+}
-+
-+
-+static unsigned int
-+route6_oif(const struct ip6t_route_target_info *route_info,
-+ struct sk_buff *skb)
-+{
-+ unsigned int ifindex = 0;
-+ struct net_device *dev_out = NULL;
-+
-+ /* The user set the interface name to use.
-+ * Getting the current interface index.
-+ */
-+ if ((dev_out = dev_get_by_name(route_info->oif))) {
-+ ifindex = dev_out->ifindex;
-+ } else {
-+ /* Unknown interface name : packet dropped */
-+ if (net_ratelimit())
-+ DEBUGP("ip6t_ROUTE: oif interface %s not found\n", route_info->oif);
-+
-+ if (route_info->flags & IP6T_ROUTE_CONTINUE)
-+ return IP6T_CONTINUE;
-+ else
-+ return NF_DROP;
-+ }
-+
-+ /* Trying the standard way of routing packets */
-+ if (route6(skb, ifindex, route_info)) {
-+ dev_put(dev_out);
-+ if (route_info->flags & IP6T_ROUTE_CONTINUE)
-+ return IP6T_CONTINUE;
-+
-+ ip_direct_send(skb);
-+ return NF_STOLEN;
-+ } else
-+ return NF_DROP;
-+}
-+
-+
-+static unsigned int
-+route6_gw(const struct ip6t_route_target_info *route_info,
-+ struct sk_buff *skb)
-+{
-+ if (route6(skb, 0, route_info)) {
-+ if (route_info->flags & IP6T_ROUTE_CONTINUE)
-+ return IP6T_CONTINUE;
-+
-+ ip_direct_send(skb);
-+ return NF_STOLEN;
-+ } else
-+ return NF_DROP;
-+}
-+
-+
-+static unsigned int
-+ip6t_route_target(struct sk_buff **pskb,
-+ const struct net_device *in,
-+ const struct net_device *out,
-+ unsigned int hooknum,
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17)
-+ const struct xt_target *target,
-+#endif
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
-+ const void *targinfo,
-+ void *userinfo)
-+#else
-+ const void *targinfo)
-+#endif
-+{
-+ const struct ip6t_route_target_info *route_info = targinfo;
-+ struct sk_buff *skb = *pskb;
-+ struct in6_addr *gw = (struct in6_addr*)&route_info->gw;
-+ unsigned int res;
-+
-+ if (route_info->flags & IP6T_ROUTE_CONTINUE)
-+ goto do_it;
-+
-+ /* If we are at PREROUTING or INPUT hook
-+ * the TTL isn't decreased by the IP stack
-+ */
-+ if (hooknum == NF_IP6_PRE_ROUTING ||
-+ hooknum == NF_IP6_LOCAL_IN) {
-+
-+ struct ipv6hdr *ipv6h = ipv6_hdr(skb);
-+
-+ if (ipv6h->hop_limit <= 1) {
-+ /* Force OUTPUT device used as source address */
-+ skb->dev = skb->dst->dev;
-+
-+ icmpv6_send(skb, ICMPV6_TIME_EXCEED,
-+ ICMPV6_EXC_HOPLIMIT, 0, skb->dev);
-+
-+ return NF_DROP;
-+ }
-+
-+ ipv6h->hop_limit--;
-+ }
-+
-+ if ((route_info->flags & IP6T_ROUTE_TEE)) {
-+ /*
-+ * Copy the *pskb, and route the copy. Will later return
-+ * IP6T_CONTINUE for the original skb, which should continue
-+ * on its way as if nothing happened. The copy should be
-+ * independantly delivered to the ROUTE --gw.
-+ */
-+ skb = skb_copy(*pskb, GFP_ATOMIC);
-+ if (!skb) {
-+ if (net_ratelimit())
-+ DEBUGP(KERN_DEBUG "ip6t_ROUTE: copy failed!\n");
-+ return IP6T_CONTINUE;
-+ }
-+ }
-+
-+do_it:
-+ if (route_info->oif[0]) {
-+ res = route6_oif(route_info, skb);
-+ } else if (!ipv6_addr_any(gw)) {
-+ res = route6_gw(route_info, skb);
-+ } else {
-+ if (net_ratelimit())
-+ DEBUGP(KERN_DEBUG "ip6t_ROUTE: no parameter !\n");
-+ res = IP6T_CONTINUE;
-+ }
-+
-+ if ((route_info->flags & IP6T_ROUTE_TEE))
-+ res = IP6T_CONTINUE;
-+
-+ return res;
-+}
-+
-+
-+static int
-+ip6t_route_checkentry(const char *tablename,
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ const void *entry,
-+#else
-+ const struct ip6t_entry *entry
-+#endif
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17)
-+ const struct xt_target *target,
-+#endif
-+ void *targinfo,
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
-+ unsigned int targinfosize,
-+#endif
-+ unsigned int hook_mask)
-+{
-+ if (strcmp(tablename, "mangle") != 0) {
-+ printk("ip6t_ROUTE: can only be called from \"mangle\" table.\n");
-+ return 0;
-+ }
-+
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
-+ if (targinfosize != IP6T_ALIGN(sizeof(struct ip6t_route_target_info))) {
-+ printk(KERN_WARNING "ip6t_ROUTE: targinfosize %u != %Zu\n",
-+ targinfosize,
-+ IP6T_ALIGN(sizeof(struct ip6t_route_target_info)));
-+ return 0;
-+ }
-+#endif
-+
-+ return 1;
-+}
-+
-+
-+static struct ip6t_target ip6t_route_reg = {
-+ .name = "ROUTE",
-+ .target = ip6t_route_target,
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17)
-+ .targetsize = sizeof(struct ip6t_route_target_info),
-+#endif
-+ .checkentry = ip6t_route_checkentry,
-+ .me = THIS_MODULE
-+};
-+
-+
-+static int __init init(void)
-+{
-+ printk(KERN_DEBUG "registering ipv6 ROUTE target\n");
-+ if (xt_register_target(&ip6t_route_reg))
-+ return -EINVAL;
-+
-+ return 0;
-+}
-+
-+
-+static void __exit fini(void)
-+{
-+ xt_unregister_target(&ip6t_route_reg);
-+}
-+
-+module_init(init);
-+module_exit(fini);
-+MODULE_LICENSE("GPL");
---- a/net/ipv6/netfilter/Kconfig
-+++ b/net/ipv6/netfilter/Kconfig
-@@ -209,5 +209,18 @@
- If you want to compile it as a module, say M here and read
- <file:Documentation/kbuild/modules.txt>. If unsure, say `N'.
-
-+config IP6_NF_TARGET_ROUTE
-+ tristate 'ROUTE target support'
-+ depends on IP6_NF_MANGLE
-+ help
-+ This option adds a `ROUTE' target, which enables you to setup unusual
-+ routes. The ROUTE target is also able to change the incoming interface
-+ of a packet.
-+
-+ The target can be or not a final target. It has to be used inside the
-+ mangle table.
-+
-+ Not working as a module.
-+
- endmenu
-
---- a/net/ipv6/netfilter/Makefile
-+++ b/net/ipv6/netfilter/Makefile
-@@ -20,6 +20,7 @@
- obj-$(CONFIG_IP6_NF_RAW) += ip6table_raw.o
- obj-$(CONFIG_IP6_NF_MATCH_HL) += ip6t_hl.o
- obj-$(CONFIG_IP6_NF_TARGET_REJECT) += ip6t_REJECT.o
-+obj-$(CONFIG_IP6_NF_TARGET_ROUTE) += ip6t_ROUTE.o
- obj-$(CONFIG_IP6_NF_MATCH_MH) += ip6t_mh.o
-
- # objects for l3 independent conntrack
+++ /dev/null
---- /dev/null
-+++ b/include/linux/netfilter/oot_conntrack.h
-@@ -0,0 +1,5 @@
-+#if defined(CONFIG_IP_NF_CONNTRACK) || defined(CONFIG_IP_NF_CONNTRACK_MODULE)
-+# include <linux/netfilter_ipv4/ip_conntrack.h>
-+#else /* linux-2.6.20+ */
-+# include <net/netfilter/nf_nat_rule.h>
-+#endif
---- /dev/null
-+++ b/include/linux/netfilter/oot_trans.h
-@@ -0,0 +1,14 @@
-+/* Out of tree workarounds */
-+#include <linux/version.h>
-+#if LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 18)
-+# define HAVE_MATCHINFOSIZE 1
-+# define HAVE_TARGUSERINFO 1
-+# define HAVE_TARGINFOSIZE 1
-+#endif
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 20)
-+# define nfmark mark
-+#endif
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 21)
-+# define tcp_v4_check(tcph, tcph_sz, s, d, csp) \
-+ tcp_v4_check((tcph_sz), (s), (d), (csp))
-+#endif
---- /dev/null
-+++ b/include/linux/netfilter/xt_CHAOS.h
-@@ -0,0 +1,14 @@
-+#ifndef _LINUX_NETFILTER_XT_CHAOS_H
-+#define _LINUX_NETFILTER_XT_CHAOS_H 1
-+
-+enum xt_chaos_target_variant {
-+ XTCHAOS_NORMAL,
-+ XTCHAOS_TARPIT,
-+ XTCHAOS_DELUDE,
-+};
-+
-+struct xt_chaos_target_info {
-+ uint8_t variant;
-+};
-+
-+#endif /* _LINUX_NETFILTER_XT_CHAOS_H */
---- /dev/null
-+++ b/include/linux/netfilter/xt_portscan.h
-@@ -0,0 +1,8 @@
-+#ifndef _LINUX_NETFILTER_XT_PORTSCAN_H
-+#define _LINUX_NETFILTER_XT_PORTSCAN_H 1
-+
-+struct xt_portscan_match_info {
-+ uint8_t match_stealth, match_syn, match_cn, match_gr;
-+};
-+
-+#endif /* _LINUX_NETFILTER_XT_PORTSCAN_H */
---- /dev/null
-+++ b/net/netfilter/find_match.c
-@@ -0,0 +1,39 @@
-+/*
-+ xt_request_find_match
-+ by Jan Engelhardt <jengelh [at] gmx de>, 2006 - 2007
-+
-+ Based upon linux-2.6.18.5/net/netfilter/x_tables.c:
-+ Copyright (C) 2006-2006 Harald Welte <laforge@netfilter.org>
-+ This program is free software; you can redistribute it and/or modify
-+ it under the terms of the GNU General Public License version 2 as
-+ published by the Free Software Foundation.
-+*/
-+#include <linux/err.h>
-+#include <linux/netfilter_arp.h>
-+#include <linux/socket.h>
-+#include <linux/netfilter/x_tables.h>
-+
-+/*
-+ * Yeah this code is sub-optimal, but the function is missing in
-+ * mainline so far. -jengelh
-+ */
-+static struct xt_match *xt_request_find_match_lo(int af, const char *name,
-+ u8 revision)
-+{
-+ static const char *const xt_prefix[] = {
-+ [AF_INET] = "ip",
-+ [AF_INET6] = "ip6",
-+ [NF_ARP] = "arp",
-+ };
-+ struct xt_match *match;
-+
-+ match = try_then_request_module(xt_find_match(af, name, revision),
-+ "%st_%s", xt_prefix[af], name);
-+ if (IS_ERR(match) || match == NULL)
-+ return NULL;
-+
-+ return match;
-+}
-+
-+/* In case it goes into mainline, let this out-of-tree package compile */
-+#define xt_request_find_match xt_request_find_match_lo
---- a/net/netfilter/Kconfig
-+++ b/net/netfilter/Kconfig
-@@ -265,6 +265,14 @@
-
- # alphabetically ordered list of targets
-
-+config NETFILTER_XT_TARGET_CHAOS
-+ tristate '"CHAOS" target support'
-+ depends on NETFILTER_XTABLES
-+ help
-+ This option adds a `CHAOS' target.
-+
-+ To compile it as a module, choose M here. If unsure, say N.
-+
- config NETFILTER_XT_TARGET_CLASSIFY
- tristate '"CLASSIFY" target support'
- depends on NETFILTER_XTABLES
-@@ -292,6 +300,14 @@
- <file:Documentation/kbuild/modules.txt>. The module will be called
- ipt_CONNMARK.ko. If unsure, say `N'.
-
-+config NETFILTER_XT_TARGET_DELUDE
-+ tristate '"DELUDE" target support'
-+ depends on NETFILTER_XTABLES
-+ help
-+ This option adds a `DELUDE' target.
-+
-+ To compile it as a module, choose M here. If unsure, say N.
-+
- config NETFILTER_XT_TARGET_DSCP
- tristate '"DSCP" target support'
- depends on NETFILTER_XTABLES
-@@ -556,6 +572,14 @@
-
- To compile it as a module, choose M here. If unsure, say N.
-
-+config NETFILTER_XT_MATCH_PORTSCAN
-+ tristate '"portscan" match support'
-+ depends on NETFILTER_XTABLES
-+ help
-+ This option adds a 'portscan' match support.
-+
-+ To compile it as a module, choose M here. If unsure, say N.
-+
- config NETFILTER_XT_MATCH_MULTIPORT
- tristate "Multiple port match support"
- depends on NETFILTER_XTABLES
---- a/net/netfilter/Makefile
-+++ b/net/netfilter/Makefile
-@@ -49,6 +49,8 @@
- obj-$(CONFIG_NETFILTER_XT_TARGET_SECMARK) += xt_SECMARK.o
- obj-$(CONFIG_NETFILTER_XT_TARGET_TCPMSS) += xt_TCPMSS.o
- obj-$(CONFIG_NETFILTER_XT_TARGET_CONNSECMARK) += xt_CONNSECMARK.o
-+obj-$(CONFIG_NETFILTER_XT_TARGET_CHAOS) += xt_CHAOS.o
-+obj-$(CONFIG_NETFILTER_XT_TARGET_DELUDE) += xt_DELUDE.o
-
- # matches
- obj-$(CONFIG_NETFILTER_XT_MATCH_COMMENT) += xt_comment.o
-@@ -78,3 +80,4 @@
- obj-$(CONFIG_NETFILTER_XT_MATCH_PHYSDEV) += xt_physdev.o
- obj-$(CONFIG_NETFILTER_XT_MATCH_U32) += xt_u32.o
- obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
-+obj-$(CONFIG_NETFILTER_XT_MATCH_PORTSCAN) += xt_portscan.o
---- /dev/null
-+++ b/net/netfilter/xt_CHAOS.c
-@@ -0,0 +1,200 @@
-+/*
-+ * CHAOS target for netfilter
-+ * Copyright © CC Computer Consultants GmbH, 2006 - 2007
-+ * Contact: Jan Engelhardt <jengelh@computergmbh.de>
-+ *
-+ * This program is free software; you can redistribute it and/or modify
-+ * it under the terms of the GNU General Public License; either version
-+ * 2 or 3 as published by the Free Software Foundation.
-+ */
-+#include <linux/icmp.h>
-+#include <linux/in.h>
-+#include <linux/ip.h>
-+#include <linux/module.h>
-+#include <linux/skbuff.h>
-+#include <linux/stat.h>
-+#include <linux/netfilter/x_tables.h>
-+#include <linux/netfilter/xt_tcpudp.h>
-+#include <linux/netfilter_ipv4/ipt_REJECT.h>
-+#include <net/ip.h>
-+#if defined(_LOCAL)
-+# include "xt_CHAOS.h"
-+# include "find_match.c"
-+#elif defined(CONFIG_NETFILTER_XT_TARGET_CHAOS) || \
-+ defined(CONFIG_NETFILTER_XT_TARGET_CHAOS_MODULE)
-+# include <linux/netfilter/xt_CHAOS.h>
-+# include "find_match.c"
-+#else
-+# include "xt_CHAOS.h"
-+# include "find_match.c"
-+#endif
-+#define PFX KBUILD_MODNAME ": "
-+
-+/* Module parameters */
-+static unsigned int reject_percentage = ~0U * .01;
-+static unsigned int delude_percentage = ~0U * .0101;
-+module_param(reject_percentage, uint, S_IRUGO | S_IWUSR);
-+module_param(delude_percentage, uint, S_IRUGO | S_IWUSR);
-+
-+/* References to other matches/targets */
-+static struct xt_match *xm_tcp;
-+static struct xt_target *xt_delude, *xt_reject, *xt_tarpit;
-+
-+static int have_delude, have_tarpit;
-+
-+/* Static data for other matches/targets */
-+static const struct ipt_reject_info reject_params = {
-+ .with = ICMP_HOST_UNREACH,
-+};
-+
-+static const struct xt_tcp tcp_params = {
-+ .spts = {0, ~0},
-+ .dpts = {0, ~0},
-+};
-+
-+/* CHAOS functions */
-+static void xt_chaos_total(const struct xt_chaos_target_info *info,
-+ struct sk_buff **pskb, const struct net_device *in,
-+ const struct net_device *out, unsigned int hooknum)
-+{
-+ const struct iphdr *iph = ip_hdr(*pskb);
-+ const int protoff = 4 * iph->ihl;
-+ const int offset = ntohs(iph->frag_off) & IP_OFFSET;
-+ const struct xt_target *destiny;
-+ bool hotdrop = false, ret;
-+
-+ ret = xm_tcp->match(*pskb, in, out, xm_tcp, &tcp_params,
-+ offset, protoff, &hotdrop);
-+ if (!ret || hotdrop || (unsigned int)net_random() > delude_percentage)
-+ return;
-+
-+ destiny = (info->variant == XTCHAOS_TARPIT) ? xt_tarpit : xt_delude;
-+ destiny->target(pskb, in, out, hooknum, destiny, NULL);
-+ return;
-+}
-+
-+static unsigned int chaos_tg(struct sk_buff **pskb,
-+ const struct net_device *in, const struct net_device *out,
-+ unsigned int hooknum, const struct xt_target *target, const void *targinfo)
-+{
-+ /*
-+ * Equivalent to:
-+ * -A chaos -m statistic --mode random --probability \
-+ * $reject_percentage -j REJECT --reject-with host-unreach;
-+ * -A chaos -p tcp -m statistic --mode random --probability \
-+ * $delude_percentage -j DELUDE;
-+ * -A chaos -j DROP;
-+ */
-+ const struct xt_chaos_target_info *info = targinfo;
-+ const struct iphdr *iph = ip_hdr(*pskb);
-+
-+ if ((unsigned int)net_random() <= reject_percentage)
-+ return xt_reject->target(pskb, in, out, hooknum, target,
-+ &reject_params);
-+
-+ /* TARPIT/DELUDE may not be called from the OUTPUT chain */
-+ if (iph->protocol == IPPROTO_TCP &&
-+ info->variant != XTCHAOS_NORMAL && hooknum != NF_IP_LOCAL_OUT)
-+ xt_chaos_total(info, pskb, in, out, hooknum);
-+
-+ return NF_DROP;
-+}
-+
-+static bool chaos_tg_check(const char *tablename, const void *entry,
-+ const struct xt_target *target, void *targinfo, unsigned int hook_mask)
-+{
-+ const struct xt_chaos_target_info *info = targinfo;
-+
-+ if (info->variant == XTCHAOS_DELUDE && !have_delude) {
-+ printk(KERN_WARNING PFX "Error: Cannot use --delude when "
-+ "DELUDE module not available\n");
-+ return false;
-+ }
-+ if (info->variant == XTCHAOS_TARPIT && !have_tarpit) {
-+ printk(KERN_WARNING PFX "Error: Cannot use --tarpit when "
-+ "TARPIT module not available\n");
-+ return false;
-+ }
-+
-+ return true;
-+}
-+
-+static struct xt_target chaos_tg_reg = {
-+ .name = "CHAOS",
-+ .family = AF_INET,
-+ .table = "filter",
-+ .hooks = (1 << NF_IP_LOCAL_IN) | (1 << NF_IP_FORWARD) |
-+ (1 << NF_IP_LOCAL_OUT),
-+ .checkentry = chaos_tg_check,
-+ .target = chaos_tg,
-+ .targetsize = sizeof(struct xt_chaos_target_info),
-+ .me = THIS_MODULE,
-+};
-+
-+static int __init chaos_tg_init(void)
-+{
-+ int ret = -EINVAL;
-+
-+ xm_tcp = xt_request_find_match(AF_INET, "tcp", 0);
-+ if (xm_tcp == NULL) {
-+ printk(KERN_WARNING PFX "Error: Could not find or load "
-+ "\"tcp\" match\n");
-+ return -EINVAL;
-+ }
-+
-+ xt_reject = xt_request_find_target(AF_INET, "REJECT", 0);
-+ if (xt_reject == NULL) {
-+ printk(KERN_WARNING PFX "Error: Could not find or load "
-+ "\"REJECT\" target\n");
-+ goto out2;
-+ }
-+
-+ xt_tarpit = xt_request_find_target(AF_INET, "TARPIT", 0);
-+ have_tarpit = xt_tarpit != NULL;
-+ if (!have_tarpit)
-+ printk(KERN_WARNING PFX "Warning: Could not find or load "
-+ "\"TARPIT\" target\n");
-+
-+ xt_delude = xt_request_find_target(AF_INET, "DELUDE", 0);
-+ have_delude = xt_delude != NULL;
-+ if (!have_delude)
-+ printk(KERN_WARNING PFX "Warning: Could not find or load "
-+ "\"DELUDE\" target\n");
-+
-+ if ((ret = xt_register_target(&chaos_tg_reg)) != 0) {
-+ printk(KERN_WARNING PFX "xt_register_target returned "
-+ "error %d\n", ret);
-+ goto out3;
-+ }
-+
-+ return 0;
-+
-+ out3:
-+ if (have_delude)
-+ module_put(xt_delude->me);
-+ if (have_tarpit)
-+ module_put(xt_tarpit->me);
-+ module_put(xt_reject->me);
-+ out2:
-+ module_put(xm_tcp->me);
-+ return ret;
-+}
-+
-+static void __exit chaos_tg_exit(void)
-+{
-+ xt_unregister_target(&chaos_tg_reg);
-+ module_put(xm_tcp->me);
-+ module_put(xt_reject->me);
-+ if (have_delude)
-+ module_put(xt_delude->me);
-+ if (have_tarpit)
-+ module_put(xt_tarpit->me);
-+ return;
-+}
-+
-+module_init(chaos_tg_init);
-+module_exit(chaos_tg_exit);
-+MODULE_AUTHOR("Jan Engelhardt <jengelh@computergmbh.de>");
-+MODULE_DESCRIPTION("netfilter \"CHAOS\" target");
-+MODULE_LICENSE("GPL");
-+MODULE_ALIAS("ipt_CHAOS");
---- /dev/null
-+++ b/net/netfilter/xt_DELUDE.c
-@@ -0,0 +1,197 @@
-+/*
-+ * DELUDE target
-+ * Copyright © CC Computer Consultants GmbH, 2007
-+ * Contact: Jan Engelhardt <jengelh@computergmbh.de>
-+ *
-+ * Based upon linux-2.6.18.5/net/ipv4/netfilter/ipt_REJECT.c:
-+ * (C) 1999-2001 Paul `Rusty' Russell
-+ * (C) 2002-2004 Netfilter Core Team <coreteam@netfilter.org>
-+ *
-+ * xt_DELUDE acts like REJECT, but does reply with SYN-ACK on SYN.
-+ *
-+ * This program is free software; you can redistribute it and/or modify
-+ * it under the terms of the GNU General Public License version 2 as
-+ * published by the Free Software Foundation.
-+ */
-+#include <linux/module.h>
-+#include <linux/skbuff.h>
-+#include <linux/ip.h>
-+#include <linux/tcp.h>
-+#include <linux/netfilter/x_tables.h>
-+#ifdef CONFIG_BRIDGE_NETFILTER
-+# include <linux/netfilter_bridge.h>
-+#endif
-+#include <net/tcp.h>
-+#define PFX KBUILD_MODNAME ": "
-+
-+static void delude_send_reset(struct sk_buff *oldskb, unsigned int hook)
-+{
-+ struct tcphdr _otcph, *oth, *tcph;
-+ unsigned int addr_type;
-+ struct sk_buff *nskb;
-+ u_int16_t tmp_port;
-+ u_int32_t tmp_addr;
-+ struct iphdr *niph;
-+ bool needs_ack;
-+
-+ /* IP header checks: fragment. */
-+ if (ip_hdr(oldskb)->frag_off & htons(IP_OFFSET))
-+ return;
-+
-+ oth = skb_header_pointer(oldskb, ip_hdrlen(oldskb),
-+ sizeof(_otcph), &_otcph);
-+ if (oth == NULL)
-+ return;
-+
-+ /* No RST for RST. */
-+ if (oth->rst)
-+ return;
-+
-+ /* Check checksum */
-+ if (nf_ip_checksum(oldskb, hook, ip_hdrlen(oldskb), IPPROTO_TCP))
-+ return;
-+
-+ /* We need a linear, writeable skb. We also need to expand
-+ headroom in case hh_len of incoming interface < hh_len of
-+ outgoing interface */
-+ nskb = skb_copy_expand(oldskb, LL_MAX_HEADER, skb_tailroom(oldskb),
-+ GFP_ATOMIC);
-+ if (!nskb)
-+ return;
-+
-+ /* This packet will not be the same as the other: clear nf fields */
-+ nf_reset(nskb);
-+ nskb->mark = 0;
-+ skb_init_secmark(nskb);
-+
-+ skb_shinfo(nskb)->gso_size = 0;
-+ skb_shinfo(nskb)->gso_segs = 0;
-+ skb_shinfo(nskb)->gso_type = 0;
-+
-+ tcph = (struct tcphdr *)(skb_network_header(nskb) + ip_hdrlen(nskb));
-+
-+ /* Swap source and dest */
-+ niph = ip_hdr(nskb);
-+ tmp_addr = niph->saddr;
-+ niph->saddr = niph->daddr;
-+ niph->daddr = tmp_addr;
-+ tmp_port = tcph->source;
-+ tcph->source = tcph->dest;
-+ tcph->dest = tmp_port;
-+
-+ /* Truncate to length (no data) */
-+ tcph->doff = sizeof(struct tcphdr) / 4;
-+ skb_trim(nskb, ip_hdrlen(nskb) + sizeof(struct tcphdr));
-+ niph->tot_len = htons(nskb->len);
-+
-+ if (oth->syn && !oth->ack && !oth->rst && !oth->fin) {
-+ /* DELUDE essential part */
-+ tcph->ack_seq = htonl(ntohl(oth->seq) + oth->syn + oth->fin +
-+ oldskb->len - ip_hdrlen(oldskb) -
-+ (oth->doff << 2));
-+ tcph->seq = false;
-+ tcph->ack = true;
-+ } else {
-+ if (!tcph->ack) {
-+ needs_ack = true;
-+ tcph->ack_seq = htonl(ntohl(oth->seq) + oth->syn +
-+ oth->fin + oldskb->len -
-+ ip_hdrlen(oldskb) - (oth->doff<<2));
-+ tcph->seq = false;
-+ } else {
-+ needs_ack = false;
-+ tcph->seq = oth->ack_seq;
-+ tcph->ack_seq = false;
-+ }
-+
-+ /* Reset flags */
-+ ((u_int8_t *)tcph)[13] = 0;
-+ tcph->rst = true;
-+ tcph->ack = needs_ack;
-+ }
-+
-+ tcph->window = 0;
-+ tcph->urg_ptr = 0;
-+
-+ /* Adjust TCP checksum */
-+ tcph->check = 0;
-+ tcph->check = tcp_v4_check(sizeof(struct tcphdr), niph->saddr,
-+ niph->daddr, csum_partial((char *)tcph,
-+ sizeof(struct tcphdr), 0));
-+
-+ /* Set DF, id = 0 */
-+ niph->frag_off = htons(IP_DF);
-+ niph->id = 0;
-+
-+ addr_type = RTN_UNSPEC;
-+#ifdef CONFIG_BRIDGE_NETFILTER
-+ if (hook != NF_IP_FORWARD || (nskb->nf_bridge != NULL &&
-+ nskb->nf_bridge->mask & BRNF_BRIDGED))
-+#else
-+ if (hook != NF_IP_FORWARD)
-+#endif
-+ addr_type = RTN_LOCAL;
-+
-+ if (ip_route_me_harder(&nskb, addr_type))
-+ goto free_nskb;
-+
-+ nskb->ip_summed = CHECKSUM_NONE;
-+
-+ /* Adjust IP TTL */
-+ niph->ttl = dst_metric(nskb->dst, RTAX_HOPLIMIT);
-+
-+ /* Adjust IP checksum */
-+ niph->check = 0;
-+ niph->check = ip_fast_csum(skb_network_header(nskb), niph->ihl);
-+
-+ /* "Never happens" */
-+ if (nskb->len > dst_mtu(nskb->dst))
-+ goto free_nskb;
-+
-+ nf_ct_attach(nskb, oldskb);
-+
-+ NF_HOOK(PF_INET, NF_IP_LOCAL_OUT, nskb, NULL, nskb->dst->dev,
-+ dst_output);
-+ return;
-+
-+ free_nskb:
-+ kfree_skb(nskb);
-+}
-+
-+static unsigned int delude_tg(struct sk_buff **pskb,
-+ const struct net_device *in, const struct net_device *out,
-+ unsigned int hooknum, const struct xt_target *target, const void *targinfo)
-+{
-+ /* WARNING: This code causes reentry within iptables.
-+ This means that the iptables jump stack is now crap. We
-+ must return an absolute verdict. --RR */
-+ delude_send_reset(*pskb, hooknum);
-+ return NF_DROP;
-+}
-+
-+static struct xt_target delude_tg_reg = {
-+ .name = "DELUDE",
-+ .family = AF_INET,
-+ .table = "filter",
-+ .hooks = (1 << NF_IP_LOCAL_IN) | (1 << NF_IP_FORWARD),
-+ .target = delude_tg,
-+ .proto = IPPROTO_TCP,
-+ .me = THIS_MODULE,
-+};
-+
-+static int __init delude_tg_init(void)
-+{
-+ return xt_register_target(&delude_tg_reg);
-+}
-+
-+static void __exit delude_tg_exit(void)
-+{
-+ xt_unregister_target(&delude_tg_reg);
-+}
-+
-+module_init(delude_tg_init);
-+module_exit(delude_tg_exit);
-+MODULE_AUTHOR("Jan Engelhardt <jengelh@computergmbh.de>");
-+MODULE_DESCRIPTION("netfilter \"DELUDE\" target");
-+MODULE_LICENSE("GPL");
-+MODULE_ALIAS("ipt_DELUDE");
---- /dev/null
-+++ b/net/netfilter/xt_portscan.c
-@@ -0,0 +1,269 @@
-+/*
-+ * portscan match for netfilter
-+ * Copyright © CC Computer Consultants GmbH, 2006 - 2007
-+ * Contact: Jan Engelhardt <jengelh@computergmbh.de>
-+ *
-+ * This program is free software; you can redistribute it and/or modify
-+ * it under the terms of the GNU General Public License; either version
-+ * 2 or 3 as published by the Free Software Foundation.
-+ */
-+#include <linux/in.h>
-+#include <linux/ip.h>
-+#include <linux/module.h>
-+#include <linux/moduleparam.h>
-+#include <linux/skbuff.h>
-+#include <linux/stat.h>
-+#include <linux/tcp.h>
-+#include <linux/types.h>
-+#include <linux/version.h>
-+#include <linux/netfilter/x_tables.h>
-+#include <linux/netfilter/xt_tcpudp.h>
-+#include <net/netfilter/nf_nat_rule.h>
-+#if defined(_LOCAL)
-+# include "xt_portscan.h"
-+#elif defined(CONFIG_NETFILTER_XT_MATCH_PORTSCAN) || \
-+ defined(CONFIG_NETFILTER_XT_MATCH_PORTSCAN_MODULE)
-+# include <linux/netfilter/xt_portscan.h>
-+#else
-+# include "xt_portscan.h"
-+#endif
-+#define PFX KBUILD_MODNAME ": "
-+
-+enum {
-+ TCP_FLAGS_ALL3 = TCP_FLAG_FIN | TCP_FLAG_RST | TCP_FLAG_SYN,
-+ TCP_FLAGS_ALL4 = TCP_FLAGS_ALL3 | TCP_FLAG_ACK,
-+ TCP_FLAGS_ALL6 = TCP_FLAGS_ALL4 | TCP_FLAG_PSH | TCP_FLAG_URG,
-+};
-+
-+/* Module parameters */
-+static unsigned int
-+ connmark_mask = ~0,
-+ packet_mask = ~0,
-+ mark_seen = 0x9,
-+ mark_synrcv = 0x1,
-+ mark_closed = 0x2,
-+ mark_synscan = 0x3,
-+ mark_estab1 = 0x4,
-+ mark_estab2 = 0x5,
-+ mark_cnscan = 0x6,
-+ mark_grscan = 0x7,
-+ mark_valid = 0x8;
-+
-+module_param(connmark_mask, uint, S_IRUGO | S_IWUSR);
-+module_param(packet_mask, uint, S_IRUGO | S_IWUSR);
-+module_param(mark_seen, uint, S_IRUGO | S_IWUSR);
-+module_param(mark_synrcv, uint, S_IRUGO | S_IWUSR);
-+module_param(mark_closed, uint, S_IRUGO | S_IWUSR);
-+module_param(mark_synscan, uint, S_IRUGO | S_IWUSR);
-+module_param(mark_estab1, uint, S_IRUGO | S_IWUSR);
-+module_param(mark_estab2, uint, S_IRUGO | S_IWUSR);
-+module_param(mark_cnscan, uint, S_IRUGO | S_IWUSR);
-+module_param(mark_grscan, uint, S_IRUGO | S_IWUSR);
-+module_param(mark_valid, uint, S_IRUGO | S_IWUSR);
-+MODULE_PARM_DESC(connmark_mask, "only set specified bits in connection mark");
-+MODULE_PARM_DESC(packet_mask, "only set specified bits in packet mark");
-+MODULE_PARM_DESC(mark_seen, "nfmark value for packet-seen state");
-+MODULE_PARM_DESC(mark_synrcv, "connmark value for SYN Received state");
-+MODULE_PARM_DESC(mark_closed, "connmark value for closed state");
-+MODULE_PARM_DESC(mark_synscan, "connmark value for SYN Scan state");
-+MODULE_PARM_DESC(mark_estab1, "connmark value for Established-1 state");
-+MODULE_PARM_DESC(mark_estab2, "connmark value for Established-2 state");
-+MODULE_PARM_DESC(mark_cnscan, "connmark value for Connect Scan state");
-+MODULE_PARM_DESC(mark_grscan, "connmark value for Grab Scan state");
-+MODULE_PARM_DESC(mark_valid, "connmark value for Valid state");
-+
-+/* TCP flag functions */
-+static inline bool tflg_ack4(const struct tcphdr *th)
-+{
-+ return (tcp_flag_word(th) & TCP_FLAGS_ALL4) == TCP_FLAG_ACK;
-+}
-+
-+static inline bool tflg_ack6(const struct tcphdr *th)
-+{
-+ return (tcp_flag_word(th) & TCP_FLAGS_ALL6) == TCP_FLAG_ACK;
-+}
-+
-+static inline bool tflg_fin(const struct tcphdr *th)
-+{
-+ return (tcp_flag_word(th) & TCP_FLAGS_ALL3) == TCP_FLAG_FIN;
-+}
-+
-+static inline bool tflg_rst(const struct tcphdr *th)
-+{
-+ return (tcp_flag_word(th) & TCP_FLAGS_ALL3) == TCP_FLAG_RST;
-+}
-+
-+static inline bool tflg_rstack(const struct tcphdr *th)
-+{
-+ return (tcp_flag_word(th) & TCP_FLAGS_ALL4) ==
-+ (TCP_FLAG_ACK | TCP_FLAG_RST);
-+}
-+
-+static inline bool tflg_syn(const struct tcphdr *th)
-+{
-+ return (tcp_flag_word(th) & TCP_FLAGS_ALL4) == TCP_FLAG_SYN;
-+}
-+
-+static inline bool tflg_synack(const struct tcphdr *th)
-+{
-+ return (tcp_flag_word(th) & TCP_FLAGS_ALL4) ==
-+ (TCP_FLAG_SYN | TCP_FLAG_ACK);
-+}
-+
-+/* portscan functions */
-+static inline bool portscan_mt_stealth(const struct tcphdr *th)
-+{
-+ /*
-+ * "Connection refused" replies to our own probes must not be matched.
-+ */
-+ if (tflg_rstack(th))
-+ return false;
-+
-+ if (tflg_rst(th) && printk_ratelimit()) {
-+ printk(KERN_WARNING PFX "Warning: Pure RST received\n");
-+ return false;
-+ }
-+
-+ /*
-+ * -p tcp ! --syn -m conntrack --ctstate INVALID: Looking for non-start
-+ * packets that are not associated with any connection -- this will
-+ * match most scan types (NULL, XMAS, FIN) and ridiculous flag
-+ * combinations (SYN-RST, SYN-FIN, SYN-FIN-RST, FIN-RST, etc.).
-+ */
-+ return !tflg_syn(th);
-+}
-+
-+static inline unsigned int portscan_mt_full(int mark,
-+ enum ip_conntrack_info ctstate, bool loopback, const struct tcphdr *tcph,
-+ unsigned int payload_len)
-+{
-+ if (mark == mark_estab2) {
-+ /*
-+ * -m connmark --mark $ESTAB2
-+ */
-+ if (tflg_ack4(tcph) && payload_len == 0)
-+ return mark; /* keep mark */
-+ else if (tflg_rst(tcph) || tflg_fin(tcph))
-+ return mark_grscan;
-+ else
-+ return mark_valid;
-+ } else if (mark == mark_estab1) {
-+ /*
-+ * -m connmark --mark $ESTAB1
-+ */
-+ if (tflg_rst(tcph) || tflg_fin(tcph))
-+ return mark_cnscan;
-+ else if (!loopback && tflg_ack4(tcph) && payload_len == 0)
-+ return mark_estab2;
-+ else
-+ return mark_valid;
-+ } else if (mark == mark_synrcv) {
-+ /*
-+ * -m connmark --mark $SYN
-+ */
-+ if (loopback && tflg_synack(tcph))
-+ return mark; /* keep mark */
-+ else if (loopback && tflg_rstack(tcph))
-+ return mark_closed;
-+ else if (tflg_ack6(tcph))
-+ return mark_estab1;
-+ else
-+ return mark_synscan;
-+ } else if (ctstate == IP_CT_NEW && tflg_syn(tcph)) {
-+ /*
-+ * -p tcp --syn --ctstate NEW
-+ */
-+ return mark_synrcv;
-+ }
-+ return mark;
-+}
-+
-+static bool portscan_mt(const struct sk_buff *skb,
-+ const struct net_device *in, const struct net_device *out,
-+ const struct xt_match *match, const void *matchinfo, int offset,
-+ unsigned int protoff, bool *hotdrop)
-+{
-+ const struct xt_portscan_match_info *info = matchinfo;
-+ enum ip_conntrack_info ctstate;
-+ const struct tcphdr *tcph;
-+ struct nf_conn *ctdata;
-+ struct tcphdr tcph_buf;
-+
-+ tcph = skb_header_pointer(skb, protoff, sizeof(tcph_buf), &tcph_buf);
-+ if (tcph == NULL)
-+ return false;
-+
-+ /* Check for invalid packets: -m conntrack --ctstate INVALID */
-+ if ((ctdata = nf_ct_get(skb, &ctstate)) == NULL) {
-+ if (info->match_stealth)
-+ return portscan_mt_stealth(tcph);
-+ /*
-+ * If @ctdata is NULL, we cannot match the other scan
-+ * types, return.
-+ */
-+ return false;
-+ }
-+
-+ /*
-+ * If -m portscan was previously applied to this packet, the rules we
-+ * simulate must not be run through again. And for speedup, do not call
-+ * it either when the connection is already VALID.
-+ */
-+ if ((ctdata->mark & connmark_mask) == mark_valid ||
-+ (skb->mark & packet_mask) != mark_seen) {
-+ unsigned int n;
-+
-+ n = portscan_mt_full(ctdata->mark & connmark_mask, ctstate,
-+ in == &loopback_dev, tcph,
-+ skb->len - protoff - 4 * tcph->doff);
-+
-+ ctdata->mark = (ctdata->mark & ~connmark_mask) | n;
-+ ((struct sk_buff *)skb)->mark =
-+ (skb->mark & ~packet_mask) ^ mark_seen;
-+ }
-+
-+ return (info->match_syn && ctdata->mark == mark_synscan) ||
-+ (info->match_cn && ctdata->mark == mark_cnscan) ||
-+ (info->match_gr && ctdata->mark == mark_grscan);
-+}
-+
-+static bool portscan_mt_check(const char *tablename, const void *entry,
-+ const struct xt_match *match, void *matchinfo, unsigned int hook_mask)
-+{
-+ const struct xt_portscan_match_info *info = matchinfo;
-+
-+ if ((info->match_stealth & ~1) || (info->match_syn & ~1) ||
-+ (info->match_cn & ~1) || (info->match_gr & ~1)) {
-+ printk(KERN_WARNING PFX "Invalid flags\n");
-+ return false;
-+ }
-+ return true;
-+}
-+
-+static struct xt_match portscan_mt_reg __read_mostly = {
-+ .name = "portscan",
-+ .family = AF_INET,
-+ .match = portscan_mt,
-+ .checkentry = portscan_mt_check,
-+ .matchsize = sizeof(struct xt_portscan_match_info),
-+ .proto = IPPROTO_TCP,
-+ .me = THIS_MODULE,
-+};
-+
-+static int __init portscan_mt_init(void)
-+{
-+ return xt_register_match(&portscan_mt_reg);
-+}
-+
-+static void __exit portscan_mt_exit(void)
-+{
-+ xt_unregister_match(&portscan_mt_reg);
-+ return;
-+}
-+
-+module_init(portscan_mt_init);
-+module_exit(portscan_mt_exit);
-+MODULE_AUTHOR("Jan Engelhardt <jengelh@computergmbh.de>");
-+MODULE_DESCRIPTION("netfilter \"portscan\" match");
-+MODULE_LICENSE("GPL");
-+MODULE_ALIAS("ipt_portscan");
---- a/drivers/char/random.c
-+++ b/drivers/char/random.c
-@@ -1564,6 +1564,8 @@
- return seq;
- }
-
-+EXPORT_SYMBOL(secure_tcp_sequence_number);
-+
- /* Generate secure starting point for ephemeral IPV4 transport port search */
- u32 secure_ipv4_port_ephemeral(__be32 saddr, __be32 daddr, __be16 dport)
- {
+++ /dev/null
---- a/net/netfilter/Kconfig
-+++ b/net/netfilter/Kconfig
-@@ -401,6 +401,23 @@
-
- To compile it as a module, choose M here. If unsure, say N.
-
-+config NETFILTER_XT_TARGET_TARPIT
-+ tristate '"TARPIT" target support'
-+ depends on NETFILTER_XTABLES
-+ ---help---
-+ Adds a TARPIT target to iptables, which captures and holds
-+ incoming TCP connections using no local per-connection resources.
-+ Connections are accepted, but immediately switched to the persist
-+ state (0 byte window), in which the remote side stops sending data
-+ and asks to continue every 60-240 seconds. Attempts to close the
-+ connection are ignored, forcing the remote side to time out the
-+ connection in 12-24 minutes.
-+
-+ This offers similar functionality to LaBrea
-+ <http://www.hackbusters.net/LaBrea/>, but does not require dedicated
-+ hardware or IPs. Any TCP port that you would normally DROP or REJECT
-+ can instead become a tarpit.
-+
- config NETFILTER_XT_TARGET_TCPMSS
- tristate '"TCPMSS" target support'
- depends on NETFILTER_XTABLES && (IPV6 || IPV6=n)
---- a/net/netfilter/Makefile
-+++ b/net/netfilter/Makefile
-@@ -47,6 +47,7 @@
- obj-$(CONFIG_NETFILTER_XT_TARGET_NOTRACK) += xt_NOTRACK.o
- obj-$(CONFIG_NETFILTER_XT_TARGET_TRACE) += xt_TRACE.o
- obj-$(CONFIG_NETFILTER_XT_TARGET_SECMARK) += xt_SECMARK.o
-+obj-$(CONFIG_NETFILTER_XT_TARGET_TARPIT) += xt_TARPIT.o
- obj-$(CONFIG_NETFILTER_XT_TARGET_TCPMSS) += xt_TCPMSS.o
- obj-$(CONFIG_NETFILTER_XT_TARGET_CONNSECMARK) += xt_CONNSECMARK.o
- obj-$(CONFIG_NETFILTER_XT_TARGET_CHAOS) += xt_CHAOS.o
---- /dev/null
-+++ b/net/netfilter/xt_TARPIT.c
-@@ -0,0 +1,280 @@
-+/*
-+ * Kernel module to capture and hold incoming TCP connections using
-+ * no local per-connection resources.
-+ *
-+ * Based on ipt_REJECT.c and offering functionality similar to
-+ * LaBrea <http://www.hackbusters.net/LaBrea/>.
-+ *
-+ * Copyright (c) 2002 Aaron Hopkins <tools@die.net>
-+ *
-+ * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
-+ *
-+ * Goal:
-+ * - Allow incoming TCP connections to be established.
-+ * - Passing data should result in the connection being switched to the
-+ * persist state (0 byte window), in which the remote side stops sending
-+ * data and asks to continue every 60 seconds.
-+ * - Attempts to shut down the connection should be ignored completely, so
-+ * the remote side ends up having to time it out.
-+ *
-+ * This means:
-+ * - Reply to TCP SYN,!ACK,!RST,!FIN with SYN-ACK, window 5 bytes
-+ * - Reply to TCP SYN,ACK,!RST,!FIN with RST to prevent spoofing
-+ * - Reply to TCP !SYN,!RST,!FIN with ACK, window 0 bytes, rate-limited
-+ */
-+
-+#include <linux/version.h>
-+#include <linux/module.h>
-+#include <linux/skbuff.h>
-+#include <linux/ip.h>
-+#include <net/ip.h>
-+#include <net/tcp.h>
-+#include <net/icmp.h>
-+struct in_device;
-+#include <net/route.h>
-+#include <linux/random.h>
-+#include <linux/netfilter_ipv4/ip_tables.h>
-+
-+#if 0
-+#define DEBUGP printk
-+#else
-+#define DEBUGP(format, args...)
-+#endif
-+
-+/* Stolen from ip_finish_output2 */
-+static int ip_direct_send(struct sk_buff *skb)
-+{
-+ struct dst_entry *dst = skb->dst;
-+
-+ if (dst->hh != NULL)
-+ return neigh_hh_output(dst->hh, skb);
-+ else if (dst->neighbour != NULL)
-+ return dst->neighbour->output(skb);
-+
-+ if (net_ratelimit())
-+ printk(KERN_DEBUG "TARPIT ip_direct_send: no header cache and no neighbor!\n");
-+
-+ kfree_skb(skb);
-+ return -EINVAL;
-+}
-+
-+
-+/* Send reply */
-+static void tarpit_tcp(const struct sk_buff *oskb, struct rtable *ort,
-+ unsigned int local)
-+{
-+ struct sk_buff *nskb;
-+ struct rtable *nrt;
-+ struct tcphdr *otcph, *ntcph;
-+ struct flowi fl = {};
-+ unsigned int otcplen;
-+ u_int16_t tmp;
-+
-+ const struct iphdr *oiph = ip_hdr(oskb);
-+ struct iphdr *niph;
-+
-+ /* A truncated TCP header is not going to be useful */
-+ if (oskb->len < ip_hdrlen(oskb) + sizeof(struct tcphdr))
-+ return;
-+
-+ otcph = (void *)oiph + ip_hdrlen(oskb);
-+ otcplen = oskb->len - ip_hdrlen(oskb);
-+
-+ /* No replies for RST or FIN */
-+ if (otcph->rst || otcph->fin)
-+ return;
-+
-+ /* No reply to !SYN,!ACK. Rate-limit replies to !SYN,ACKs */
-+ if (!otcph->syn && (!otcph->ack || !xrlim_allow(&ort->u.dst, 1*HZ)))
-+ return;
-+
-+ /* Check checksum. */
-+ if (tcp_v4_check(otcplen, oiph->saddr, oiph->daddr,
-+ csum_partial((char *)otcph, otcplen, 0)) != 0)
-+ return;
-+
-+ /*
-+ * Copy skb (even if skb is about to be dropped, we cannot just
-+ * clone it because there may be other things, such as tcpdump,
-+ * interested in it)
-+ */
-+ nskb = skb_copy(oskb, GFP_ATOMIC);
-+ if (nskb == NULL)
-+ return;
-+
-+ niph = ip_hdr(nskb);
-+
-+ /* This packet will not be the same as the other: clear nf fields */
-+ nf_conntrack_put(nskb->nfct);
-+ nskb->nfct = NULL;
-+#ifdef CONFIG_NETFILTER_DEBUG
-+ nskb->nf_debug = 0;
-+#endif
-+
-+ ntcph = (void *)niph + ip_hdrlen(nskb);
-+
-+ /* Truncate to length (no data) */
-+ ntcph->doff = sizeof(struct tcphdr)/4;
-+ skb_trim(nskb, ip_hdrlen(nskb) + sizeof(struct tcphdr));
-+ niph->tot_len = htons(nskb->len);
-+
-+ /* Swap source and dest */
-+ niph->daddr = xchg(&niph->saddr, niph->daddr);
-+ tmp = ntcph->source;
-+ ntcph->source = ntcph->dest;
-+ ntcph->dest = tmp;
-+
-+ /* Use supplied sequence number or make a new one */
-+ ntcph->seq = otcph->ack ? otcph->ack_seq
-+ : htonl(secure_tcp_sequence_number(niph->saddr,
-+ niph->daddr,
-+ ntcph->source,
-+ ntcph->dest));
-+
-+ /* Our SYN-ACKs must have a >0 window */
-+ ntcph->window = (otcph->syn && !otcph->ack) ? htons(5) : 0;
-+
-+ ntcph->urg_ptr = 0;
-+
-+ /* Reset flags */
-+ ((u_int8_t *)ntcph)[13] = 0;
-+
-+ if (otcph->syn && otcph->ack) {
-+ ntcph->rst = 1;
-+ ntcph->ack_seq = 0;
-+ } else {
-+ ntcph->syn = otcph->syn;
-+ ntcph->ack = 1;
-+ ntcph->ack_seq = htonl(ntohl(otcph->seq) + otcph->syn);
-+ }
-+
-+ /* Adjust TCP checksum */
-+ ntcph->check = 0;
-+ ntcph->check = tcp_v4_check(sizeof(struct tcphdr),
-+ niph->saddr,
-+ niph->daddr,
-+ csum_partial((char *)ntcph,
-+ sizeof(struct tcphdr), 0));
-+
-+ fl.nl_u.ip4_u.daddr = niph->daddr;
-+ fl.nl_u.ip4_u.saddr = local ? niph->saddr : 0;
-+ fl.nl_u.ip4_u.tos = RT_TOS(niph->tos) | RTO_CONN;
-+ fl.oif = 0;
-+
-+ if (ip_route_output_key(&nrt, &fl))
-+ goto free_nskb;
-+
-+ dst_release(nskb->dst);
-+ nskb->dst = &nrt->u.dst;
-+
-+ /* Adjust IP TTL */
-+ niph->ttl = dst_metric(nskb->dst, RTAX_HOPLIMIT);
-+
-+ /* Set DF, id = 0 */
-+ niph->frag_off = htons(IP_DF);
-+ niph->id = 0;
-+
-+ /* Adjust IP checksum */
-+ niph->check = 0;
-+ niph->check = ip_fast_csum((unsigned char *)niph, niph->ihl);
-+
-+ /* "Never happens" */
-+ if (nskb->len > dst_mtu(nskb->dst))
-+ goto free_nskb;
-+
-+ ip_direct_send(nskb);
-+ return;
-+
-+ free_nskb:
-+ kfree_skb(nskb);
-+}
-+
-+static unsigned int xt_tarpit_target(struct sk_buff **pskb,
-+ const struct net_device *in,
-+ const struct net_device *out,
-+ unsigned int hooknum,
-+ const struct xt_target *target,
-+ const void *targinfo)
-+{
-+ const struct sk_buff *skb = *pskb;
-+ const struct iphdr *iph = ip_hdr(skb);
-+ struct rtable *rt = (void *)skb->dst;
-+
-+ /* Do we have an input route cache entry? */
-+ if (rt == NULL)
-+ return NF_DROP;
-+
-+ /* No replies to physical multicast/broadcast */
-+ if (skb->pkt_type != PACKET_HOST && skb->pkt_type != PACKET_OTHERHOST)
-+ return NF_DROP;
-+
-+ /* Now check at the protocol level */
-+ if (rt->rt_flags & (RTCF_BROADCAST | RTCF_MULTICAST))
-+ return NF_DROP;
-+
-+ /*
-+ * Our naive response construction does not deal with IP
-+ * options, and probably should not try.
-+ */
-+ if (iph->ihl * 4 != sizeof(struct iphdr))
-+ return NF_DROP;
-+
-+ /* We are not interested in fragments */
-+ if (iph->frag_off & htons(IP_OFFSET))
-+ return NF_DROP;
-+
-+ tarpit_tcp(skb, rt, hooknum == NF_IP_LOCAL_IN);
-+ return NF_DROP;
-+}
-+
-+static bool xt_tarpit_check(const char *tablename, const void *entry,
-+ const struct xt_target *target, void *targinfo,
-+ unsigned int hook_mask)
-+{
-+ bool invalid;
-+
-+ if (strcmp(tablename, "raw") == 0 && hook_mask == NF_IP_PRE_ROUTING)
-+ return true;
-+ if (strcmp(tablename, "filter") != 0)
-+ return false;
-+ invalid = hook_mask & ~((1 << NF_IP_LOCAL_IN) | (1 << NF_IP_FORWARD));
-+ return !invalid;
-+}
-+
-+static struct xt_target xt_tarpit_reg = {
-+ .name = "TARPIT",
-+ .family = AF_INET,
-+ .proto = IPPROTO_TCP,
-+ .target = xt_tarpit_target,
-+ .checkentry = xt_tarpit_check,
-+ .me = THIS_MODULE,
-+};
-+
-+static int __init xt_tarpit_init(void)
-+{
-+ return xt_register_target(&xt_tarpit_reg);
-+}
-+
-+static void __exit xt_tarpit_exit(void)
-+{
-+ xt_unregister_target(&xt_tarpit_reg);
-+}
-+
-+module_init(xt_tarpit_init);
-+module_exit(xt_tarpit_exit);
-+MODULE_DESCRIPTION("netfilter xt_TARPIT target module");
-+MODULE_AUTHOR("Jan Engelhardt <jengelh@gmx.de>");
-+MODULE_LICENSE("GPL");
-+MODULE_ALIAS("ipt_TARPIT");
+++ /dev/null
---- a/net/netfilter/Kconfig
-+++ b/net/netfilter/Kconfig
-@@ -143,7 +143,7 @@
-
- config NF_CONNTRACK_H323
- tristate "H.323 protocol support (EXPERIMENTAL)"
-- depends on EXPERIMENTAL && NF_CONNTRACK && (IPV6 || IPV6=n)
-+ depends on EXPERIMENTAL && NF_CONNTRACK
- help
- H.323 is a VoIP signalling protocol from ITU-T. As one of the most
- important VoIP protocols, it is widely used by voice hardware and
-@@ -420,7 +420,7 @@
-
- config NETFILTER_XT_TARGET_TCPMSS
- tristate '"TCPMSS" target support'
-- depends on NETFILTER_XTABLES && (IPV6 || IPV6=n)
-+ depends on NETFILTER_XTABLES
- ---help---
- This option adds a `TCPMSS' target, which allows you to alter the
- MSS value of TCP SYN packets, to control the maximum size for that
+++ /dev/null
---- /dev/null
-+++ b/include/linux/netfilter/nf_conntrack_rtsp.h
-@@ -0,0 +1,63 @@
-+/*
-+ * RTSP extension for IP connection tracking.
-+ * (C) 2003 by Tom Marshall <tmarshall at real.com>
-+ * based on ip_conntrack_irc.h
-+ *
-+ * 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.
-+ */
-+#ifndef _IP_CONNTRACK_RTSP_H
-+#define _IP_CONNTRACK_RTSP_H
-+
-+//#define IP_NF_RTSP_DEBUG 1
-+#define IP_NF_RTSP_VERSION "0.6.21"
-+
-+#ifdef __KERNEL__
-+/* port block types */
-+typedef enum {
-+ pb_single, /* client_port=x */
-+ pb_range, /* client_port=x-y */
-+ pb_discon /* client_port=x/y (rtspbis) */
-+} portblock_t;
-+
-+/* We record seq number and length of rtsp headers here, all in host order. */
-+
-+/*
-+ * This structure is per expected connection. It is a member of struct
-+ * ip_conntrack_expect. The TCP SEQ for the conntrack expect is stored
-+ * there and we are expected to only store the length of the data which
-+ * needs replaced. If a packet contains multiple RTSP messages, we create
-+ * one expected connection per message.
-+ *
-+ * We use these variables to mark the entire header block. This may seem
-+ * like overkill, but the nature of RTSP requires it. A header may appear
-+ * multiple times in a message. We must treat two Transport headers the
-+ * same as one Transport header with two entries.
-+ */
-+struct ip_ct_rtsp_expect
-+{
-+ u_int32_t len; /* length of header block */
-+ portblock_t pbtype; /* Type of port block that was requested */
-+ u_int16_t loport; /* Port that was requested, low or first */
-+ u_int16_t hiport; /* Port that was requested, high or second */
-+#if 0
-+ uint method; /* RTSP method */
-+ uint cseq; /* CSeq from request */
-+#endif
-+};
-+
-+extern unsigned int (*nf_nat_rtsp_hook)(struct sk_buff **pskb,
-+ enum ip_conntrack_info ctinfo,
-+ unsigned int matchoff, unsigned int matchlen,
-+ struct ip_ct_rtsp_expect *prtspexp,
-+ struct nf_conntrack_expect *exp);
-+
-+extern void (*nf_nat_rtsp_hook_expectfn)(struct nf_conn *ct, struct nf_conntrack_expect *exp);
-+
-+#define RTSP_PORT 554
-+
-+#endif /* __KERNEL__ */
-+
-+#endif /* _IP_CONNTRACK_RTSP_H */
---- /dev/null
-+++ b/include/linux/netfilter_helpers.h
-@@ -0,0 +1,133 @@
-+/*
-+ * Helpers for netfiler modules. This file provides implementations for basic
-+ * functions such as strncasecmp(), etc.
-+ *
-+ * gcc will warn for defined but unused functions, so we only include the
-+ * functions requested. The following macros are used:
-+ * NF_NEED_STRNCASECMP nf_strncasecmp()
-+ * NF_NEED_STRTOU16 nf_strtou16()
-+ * NF_NEED_STRTOU32 nf_strtou32()
-+ */
-+#ifndef _NETFILTER_HELPERS_H
-+#define _NETFILTER_HELPERS_H
-+
-+/* Only include these functions for kernel code. */
-+#ifdef __KERNEL__
-+
-+#include <linux/ctype.h>
-+#define iseol(c) ( (c) == '\r' || (c) == '\n' )
-+
-+/*
-+ * The standard strncasecmp()
-+ */
-+#ifdef NF_NEED_STRNCASECMP
-+static int
-+nf_strncasecmp(const char* s1, const char* s2, u_int32_t len)
-+{
-+ if (s1 == NULL || s2 == NULL)
-+ {
-+ if (s1 == NULL && s2 == NULL)
-+ {
-+ return 0;
-+ }
-+ return (s1 == NULL) ? -1 : 1;
-+ }
-+ while (len > 0 && tolower(*s1) == tolower(*s2))
-+ {
-+ len--;
-+ s1++;
-+ s2++;
-+ }
-+ return ( (len == 0) ? 0 : (tolower(*s1) - tolower(*s2)) );
-+}
-+#endif /* NF_NEED_STRNCASECMP */
-+
-+/*
-+ * Parse a string containing a 16-bit unsigned integer.
-+ * Returns the number of chars used, or zero if no number is found.
-+ */
-+#ifdef NF_NEED_STRTOU16
-+static int
-+nf_strtou16(const char* pbuf, u_int16_t* pval)
-+{
-+ int n = 0;
-+
-+ *pval = 0;
-+ while (isdigit(pbuf[n]))
-+ {
-+ *pval = (*pval * 10) + (pbuf[n] - '0');
-+ n++;
-+ }
-+
-+ return n;
-+}
-+#endif /* NF_NEED_STRTOU16 */
-+
-+/*
-+ * Parse a string containing a 32-bit unsigned integer.
-+ * Returns the number of chars used, or zero if no number is found.
-+ */
-+#ifdef NF_NEED_STRTOU32
-+static int
-+nf_strtou32(const char* pbuf, u_int32_t* pval)
-+{
-+ int n = 0;
-+
-+ *pval = 0;
-+ while (pbuf[n] >= '0' && pbuf[n] <= '9')
-+ {
-+ *pval = (*pval * 10) + (pbuf[n] - '0');
-+ n++;
-+ }
-+
-+ return n;
-+}
-+#endif /* NF_NEED_STRTOU32 */
-+
-+/*
-+ * Given a buffer and length, advance to the next line and mark the current
-+ * line.
-+ */
-+#ifdef NF_NEED_NEXTLINE
-+static int
-+nf_nextline(char* p, uint len, uint* poff, uint* plineoff, uint* plinelen)
-+{
-+ uint off = *poff;
-+ uint physlen = 0;
-+
-+ if (off >= len)
-+ {
-+ return 0;
-+ }
-+
-+ while (p[off] != '\n')
-+ {
-+ if (len-off <= 1)
-+ {
-+ return 0;
-+ }
-+
-+ physlen++;
-+ off++;
-+ }
-+
-+ /* if we saw a crlf, physlen needs adjusted */
-+ if (physlen > 0 && p[off] == '\n' && p[off-1] == '\r')
-+ {
-+ physlen--;
-+ }
-+
-+ /* advance past the newline */
-+ off++;
-+
-+ *plineoff = *poff;
-+ *plinelen = physlen;
-+ *poff = off;
-+
-+ return 1;
-+}
-+#endif /* NF_NEED_NEXTLINE */
-+
-+#endif /* __KERNEL__ */
-+
-+#endif /* _NETFILTER_HELPERS_H */
---- /dev/null
-+++ b/include/linux/netfilter_mime.h
-@@ -0,0 +1,89 @@
-+/*
-+ * MIME functions for netfilter modules. This file provides implementations
-+ * for basic MIME parsing. MIME headers are used in many protocols, such as
-+ * HTTP, RTSP, SIP, etc.
-+ *
-+ * gcc will warn for defined but unused functions, so we only include the
-+ * functions requested. The following macros are used:
-+ * NF_NEED_MIME_NEXTLINE nf_mime_nextline()
-+ */
-+#ifndef _NETFILTER_MIME_H
-+#define _NETFILTER_MIME_H
-+
-+/* Only include these functions for kernel code. */
-+#ifdef __KERNEL__
-+
-+#include <linux/ctype.h>
-+
-+/*
-+ * Given a buffer and length, advance to the next line and mark the current
-+ * line. If the current line is empty, *plinelen will be set to zero. If
-+ * not, it will be set to the actual line length (including CRLF).
-+ *
-+ * 'line' in this context means logical line (includes LWS continuations).
-+ * Returns 1 on success, 0 on failure.
-+ */
-+#ifdef NF_NEED_MIME_NEXTLINE
-+static int
-+nf_mime_nextline(char* p, uint len, uint* poff, uint* plineoff, uint* plinelen)
-+{
-+ uint off = *poff;
-+ uint physlen = 0;
-+ int is_first_line = 1;
-+
-+ if (off >= len)
-+ {
-+ return 0;
-+ }
-+
-+ do
-+ {
-+ while (p[off] != '\n')
-+ {
-+ if (len-off <= 1)
-+ {
-+ return 0;
-+ }
-+
-+ physlen++;
-+ off++;
-+ }
-+
-+ /* if we saw a crlf, physlen needs adjusted */
-+ if (physlen > 0 && p[off] == '\n' && p[off-1] == '\r')
-+ {
-+ physlen--;
-+ }
-+
-+ /* advance past the newline */
-+ off++;
-+
-+ /* check for an empty line */
-+ if (physlen == 0)
-+ {
-+ break;
-+ }
-+
-+ /* check for colon on the first physical line */
-+ if (is_first_line)
-+ {
-+ is_first_line = 0;
-+ if (memchr(p+(*poff), ':', physlen) == NULL)
-+ {
-+ return 0;
-+ }
-+ }
-+ }
-+ while (p[off] == ' ' || p[off] == '\t');
-+
-+ *plineoff = *poff;
-+ *plinelen = (physlen == 0) ? 0 : (off - *poff);
-+ *poff = off;
-+
-+ return 1;
-+}
-+#endif /* NF_NEED_MIME_NEXTLINE */
-+
-+#endif /* __KERNEL__ */
-+
-+#endif /* _NETFILTER_MIME_H */
---- a/net/ipv4/netfilter/Makefile
-+++ b/net/ipv4/netfilter/Makefile
-@@ -23,6 +23,7 @@
- obj-$(CONFIG_NF_NAT_FTP) += nf_nat_ftp.o
- obj-$(CONFIG_NF_NAT_H323) += nf_nat_h323.o
- obj-$(CONFIG_NF_NAT_IRC) += nf_nat_irc.o
-+obj-$(CONFIG_NF_NAT_RTSP) += nf_nat_rtsp.o
- obj-$(CONFIG_NF_NAT_PPTP) += nf_nat_pptp.o
- obj-$(CONFIG_NF_NAT_SIP) += nf_nat_sip.o
- obj-$(CONFIG_NF_NAT_SNMP_BASIC) += nf_nat_snmp_basic.o
---- a/net/netfilter/Kconfig
-+++ b/net/netfilter/Kconfig
-@@ -249,6 +249,16 @@
-
- To compile it as a module, choose M here. If unsure, say N.
-
-+config NF_CONNTRACK_RTSP
-+ tristate "RTSP protocol support"
-+ depends on NF_CONNTRACK
-+ help
-+ Support the RTSP protocol. This allows UDP transports to be setup
-+ properly, including RTP and RDT.
-+
-+ If you want to compile it as a module, say 'M' here and read
-+ Documentation/modules.txt. If unsure, say 'Y'.
-+
- config NF_CT_NETLINK
- tristate 'Connection tracking netlink interface (EXPERIMENTAL)'
- depends on EXPERIMENTAL && NF_CONNTRACK && NETFILTER_NETLINK
---- a/net/netfilter/Makefile
-+++ b/net/netfilter/Makefile
-@@ -33,6 +33,7 @@
- obj-$(CONFIG_NF_CONNTRACK_SANE) += nf_conntrack_sane.o
- obj-$(CONFIG_NF_CONNTRACK_SIP) += nf_conntrack_sip.o
- obj-$(CONFIG_NF_CONNTRACK_TFTP) += nf_conntrack_tftp.o
-+obj-$(CONFIG_NF_CONNTRACK_RTSP) += nf_conntrack_rtsp.o
-
- # generic X tables
- obj-$(CONFIG_NETFILTER_XTABLES) += x_tables.o xt_tcpudp.o
---- a/net/ipv4/netfilter/Kconfig
-+++ b/net/ipv4/netfilter/Kconfig
-@@ -296,6 +296,11 @@
- depends on IP_NF_IPTABLES && NF_CONNTRACK && NF_NAT
- default NF_NAT && NF_CONNTRACK_IRC
-
-+config NF_NAT_RTSP
-+ tristate
-+ depends on IP_NF_IPTABLES && NF_CONNTRACK && NF_NAT
-+ default NF_NAT && NF_CONNTRACK_RTSP
-+
- config NF_NAT_TFTP
- tristate
- depends on IP_NF_IPTABLES && NF_CONNTRACK && NF_NAT
---- /dev/null
-+++ b/net/netfilter/nf_conntrack_rtsp.c
-@@ -0,0 +1,513 @@
-+/*
-+ * RTSP extension for IP connection tracking
-+ * (C) 2003 by Tom Marshall <tmarshall at real.com>
-+ * based on ip_conntrack_irc.c
-+ *
-+ * 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.
-+ *
-+ * Module load syntax:
-+ * insmod nf_conntrack_rtsp.o ports=port1,port2,...port<MAX_PORTS>
-+ * max_outstanding=n setup_timeout=secs
-+ *
-+ * If no ports are specified, the default will be port 554.
-+ *
-+ * With max_outstanding you can define the maximum number of not yet
-+ * answered SETUP requests per RTSP session (default 8).
-+ * With setup_timeout you can specify how long the system waits for
-+ * an expected data channel (default 300 seconds).
-+ *
-+ * 2005-02-13: Harald Welte <laforge at netfilter.org>
-+ * - port to 2.6
-+ * - update to recent post-2.6.11 api changes
-+ * 2006-09-14: Steven Van Acker <deepstar at singularity.be>
-+ * - removed calls to NAT code from conntrack helper: NAT no longer needed to use rtsp-conntrack
-+ * 2007-04-18: Michael Guntsche <mike at it-loops.com>
-+ * - Port to new NF API
-+ */
-+
-+#include <linux/module.h>
-+#include <linux/netfilter.h>
-+#include <linux/ip.h>
-+#include <linux/inet.h>
-+#include <net/tcp.h>
-+
-+#include <net/netfilter/nf_conntrack.h>
-+#include <net/netfilter/nf_conntrack_expect.h>
-+#include <net/netfilter/nf_conntrack_helper.h>
-+#include <linux/netfilter/nf_conntrack_rtsp.h>
-+
-+#define NF_NEED_STRNCASECMP
-+#define NF_NEED_STRTOU16
-+#define NF_NEED_STRTOU32
-+#define NF_NEED_NEXTLINE
-+#include <linux/netfilter_helpers.h>
-+#define NF_NEED_MIME_NEXTLINE
-+#include <linux/netfilter_mime.h>
-+
-+#include <linux/ctype.h>
-+#define MAX_SIMUL_SETUP 8 /* XXX: use max_outstanding */
-+#define INFOP(fmt, args...) printk(KERN_INFO "%s: %s: " fmt, __FILE__, __FUNCTION__ , ## args)
-+#if 0
-+#define DEBUGP(fmt, args...) printk(KERN_DEBUG "%s: %s: " fmt, __FILE__, __FUNCTION__ , ## args)
-+#else
-+#define DEBUGP(fmt, args...)
-+#endif
-+
-+#define MAX_PORTS 8
-+static int ports[MAX_PORTS];
-+static int num_ports = 0;
-+static int max_outstanding = 8;
-+static unsigned int setup_timeout = 300;
-+
-+MODULE_AUTHOR("Tom Marshall <tmarshall at real.com>");
-+MODULE_DESCRIPTION("RTSP connection tracking module");
-+MODULE_LICENSE("GPL");
-+module_param_array(ports, int, &num_ports, 0400);
-+MODULE_PARM_DESC(ports, "port numbers of RTSP servers");
-+module_param(max_outstanding, int, 0400);
-+MODULE_PARM_DESC(max_outstanding, "max number of outstanding SETUP requests per RTSP session");
-+module_param(setup_timeout, int, 0400);
-+MODULE_PARM_DESC(setup_timeout, "timeout on for unestablished data channels");
-+
-+static char *rtsp_buffer;
-+static DEFINE_SPINLOCK(rtsp_buffer_lock);
-+
-+unsigned int (*nf_nat_rtsp_hook)(struct sk_buff **pskb,
-+ enum ip_conntrack_info ctinfo,
-+ unsigned int matchoff, unsigned int matchlen,struct ip_ct_rtsp_expect* prtspexp,
-+ struct nf_conntrack_expect *exp);
-+void (*nf_nat_rtsp_hook_expectfn)(struct nf_conn *ct, struct nf_conntrack_expect *exp);
-+
-+EXPORT_SYMBOL_GPL(nf_nat_rtsp_hook);
-+
-+/*
-+ * Max mappings we will allow for one RTSP connection (for RTP, the number
-+ * of allocated ports is twice this value). Note that SMIL burns a lot of
-+ * ports so keep this reasonably high. If this is too low, you will see a
-+ * lot of "no free client map entries" messages.
-+ */
-+#define MAX_PORT_MAPS 16
-+
-+/*** default port list was here in the masq code: 554, 3030, 4040 ***/
-+
-+#define SKIP_WSPACE(ptr,len,off) while(off < len && isspace(*(ptr+off))) { off++; }
-+
-+/*
-+ * Parse an RTSP packet.
-+ *
-+ * Returns zero if parsing failed.
-+ *
-+ * Parameters:
-+ * IN ptcp tcp data pointer
-+ * IN tcplen tcp data len
-+ * IN/OUT ptcpoff points to current tcp offset
-+ * OUT phdrsoff set to offset of rtsp headers
-+ * OUT phdrslen set to length of rtsp headers
-+ * OUT pcseqoff set to offset of CSeq header
-+ * OUT pcseqlen set to length of CSeq header
-+ */
-+static int
-+rtsp_parse_message(char* ptcp, uint tcplen, uint* ptcpoff,
-+ uint* phdrsoff, uint* phdrslen,
-+ uint* pcseqoff, uint* pcseqlen,
-+ uint* transoff, uint* translen)
-+{
-+ uint entitylen = 0;
-+ uint lineoff;
-+ uint linelen;
-+
-+ if (!nf_nextline(ptcp, tcplen, ptcpoff, &lineoff, &linelen))
-+ return 0;
-+
-+ *phdrsoff = *ptcpoff;
-+ while (nf_mime_nextline(ptcp, tcplen, ptcpoff, &lineoff, &linelen)) {
-+ if (linelen == 0) {
-+ if (entitylen > 0)
-+ *ptcpoff += min(entitylen, tcplen - *ptcpoff);
-+ break;
-+ }
-+ if (lineoff+linelen > tcplen) {
-+ INFOP("!! overrun !!\n");
-+ break;
-+ }
-+
-+ if (nf_strncasecmp(ptcp+lineoff, "CSeq:", 5) == 0) {
-+ *pcseqoff = lineoff;
-+ *pcseqlen = linelen;
-+ }
-+
-+ if (nf_strncasecmp(ptcp+lineoff, "Transport:", 10) == 0) {
-+ *transoff = lineoff;
-+ *translen = linelen;
-+ }
-+
-+ if (nf_strncasecmp(ptcp+lineoff, "Content-Length:", 15) == 0) {
-+ uint off = lineoff+15;
-+ SKIP_WSPACE(ptcp+lineoff, linelen, off);
-+ nf_strtou32(ptcp+off, &entitylen);
-+ }
-+ }
-+ *phdrslen = (*ptcpoff) - (*phdrsoff);
-+
-+ return 1;
-+}
-+
-+/*
-+ * Find lo/hi client ports (if any) in transport header
-+ * In:
-+ * ptcp, tcplen = packet
-+ * tranoff, tranlen = buffer to search
-+ *
-+ * Out:
-+ * pport_lo, pport_hi = lo/hi ports (host endian)
-+ *
-+ * Returns nonzero if any client ports found
-+ *
-+ * Note: it is valid (and expected) for the client to request multiple
-+ * transports, so we need to parse the entire line.
-+ */
-+static int
-+rtsp_parse_transport(char* ptran, uint tranlen,
-+ struct ip_ct_rtsp_expect* prtspexp)
-+{
-+ int rc = 0;
-+ uint off = 0;
-+
-+ if (tranlen < 10 || !iseol(ptran[tranlen-1]) ||
-+ nf_strncasecmp(ptran, "Transport:", 10) != 0) {
-+ INFOP("sanity check failed\n");
-+ return 0;
-+ }
-+
-+ DEBUGP("tran='%.*s'\n", (int)tranlen, ptran);
-+ off += 10;
-+ SKIP_WSPACE(ptran, tranlen, off);
-+
-+ /* Transport: tran;field;field=val,tran;field;field=val,... */
-+ while (off < tranlen) {
-+ const char* pparamend;
-+ uint nextparamoff;
-+
-+ pparamend = memchr(ptran+off, ',', tranlen-off);
-+ pparamend = (pparamend == NULL) ? ptran+tranlen : pparamend+1;
-+ nextparamoff = pparamend-ptran;
-+
-+ while (off < nextparamoff) {
-+ const char* pfieldend;
-+ uint nextfieldoff;
-+
-+ pfieldend = memchr(ptran+off, ';', nextparamoff-off);
-+ nextfieldoff = (pfieldend == NULL) ? nextparamoff : pfieldend-ptran+1;
-+
-+ if (strncmp(ptran+off, "client_port=", 12) == 0) {
-+ u_int16_t port;
-+ uint numlen;
-+
-+ off += 12;
-+ numlen = nf_strtou16(ptran+off, &port);
-+ off += numlen;
-+ if (prtspexp->loport != 0 && prtspexp->loport != port)
-+ DEBUGP("multiple ports found, port %hu ignored\n", port);
-+ else {
-+ DEBUGP("lo port found : %hu\n", port);
-+ prtspexp->loport = prtspexp->hiport = port;
-+ if (ptran[off] == '-') {
-+ off++;
-+ numlen = nf_strtou16(ptran+off, &port);
-+ off += numlen;
-+ prtspexp->pbtype = pb_range;
-+ prtspexp->hiport = port;
-+
-+ // If we have a range, assume rtp:
-+ // loport must be even, hiport must be loport+1
-+ if ((prtspexp->loport & 0x0001) != 0 ||
-+ prtspexp->hiport != prtspexp->loport+1) {
-+ DEBUGP("incorrect range: %hu-%hu, correcting\n",
-+ prtspexp->loport, prtspexp->hiport);
-+ prtspexp->loport &= 0xfffe;
-+ prtspexp->hiport = prtspexp->loport+1;
-+ }
-+ } else if (ptran[off] == '/') {
-+ off++;
-+ numlen = nf_strtou16(ptran+off, &port);
-+ off += numlen;
-+ prtspexp->pbtype = pb_discon;
-+ prtspexp->hiport = port;
-+ }
-+ rc = 1;
-+ }
-+ }
-+
-+ /*
-+ * Note we don't look for the destination parameter here.
-+ * If we are using NAT, the NAT module will handle it. If not,
-+ * and the client is sending packets elsewhere, the expectation
-+ * will quietly time out.
-+ */
-+
-+ off = nextfieldoff;
-+ }
-+
-+ off = nextparamoff;
-+ }
-+
-+ return rc;
-+}
-+
-+void expected(struct nf_conn *ct, struct nf_conntrack_expect *exp)
-+{
-+ if(nf_nat_rtsp_hook_expectfn) {
-+ nf_nat_rtsp_hook_expectfn(ct,exp);
-+ }
-+}
-+
-+/*** conntrack functions ***/
-+
-+/* outbound packet: client->server */
-+
-+static inline int
-+help_out(struct sk_buff **pskb, unsigned char *rb_ptr, unsigned int datalen,
-+ struct nf_conn *ct, enum ip_conntrack_info ctinfo)
-+{
-+ struct ip_ct_rtsp_expect expinfo;
-+
-+ int dir = CTINFO2DIR(ctinfo); /* = IP_CT_DIR_ORIGINAL */
-+ //struct tcphdr* tcph = (void*)iph + iph->ihl * 4;
-+ //uint tcplen = pktlen - iph->ihl * 4;
-+ char* pdata = rb_ptr;
-+ //uint datalen = tcplen - tcph->doff * 4;
-+ uint dataoff = 0;
-+ int ret = NF_ACCEPT;
-+
-+ struct nf_conntrack_expect *exp;
-+
-+ __be16 be_loport;
-+
-+ memset(&expinfo, 0, sizeof(expinfo));
-+
-+ while (dataoff < datalen) {
-+ uint cmdoff = dataoff;
-+ uint hdrsoff = 0;
-+ uint hdrslen = 0;
-+ uint cseqoff = 0;
-+ uint cseqlen = 0;
-+ uint transoff = 0;
-+ uint translen = 0;
-+ uint off;
-+
-+ if (!rtsp_parse_message(pdata, datalen, &dataoff,
-+ &hdrsoff, &hdrslen,
-+ &cseqoff, &cseqlen,
-+ &transoff, &translen))
-+ break; /* not a valid message */
-+
-+ if (strncmp(pdata+cmdoff, "SETUP ", 6) != 0)
-+ continue; /* not a SETUP message */
-+ DEBUGP("found a setup message\n");
-+
-+ off = 0;
-+ if(translen) {
-+ rtsp_parse_transport(pdata+transoff, translen, &expinfo);
-+ }
-+
-+ if (expinfo.loport == 0) {
-+ DEBUGP("no udp transports found\n");
-+ continue; /* no udp transports found */
-+ }
-+
-+ DEBUGP("udp transport found, ports=(%d,%hu,%hu)\n",
-+ (int)expinfo.pbtype, expinfo.loport, expinfo.hiport);
-+
-+ exp = nf_ct_expect_alloc(ct);
-+ if (!exp) {
-+ ret = NF_DROP;
-+ goto out;
-+ }
-+
-+ be_loport = htons(expinfo.loport);
-+
-+ nf_ct_expect_init(exp, ct->tuplehash[!dir].tuple.src.l3num,
-+ &ct->tuplehash[!dir].tuple.src.u3, &ct->tuplehash[!dir].tuple.dst.u3,
-+ IPPROTO_UDP, NULL, &be_loport);
-+
-+ exp->master = ct;
-+
-+ exp->expectfn = expected;
-+ exp->flags = 0;
-+
-+ if (expinfo.pbtype == pb_range) {
-+ DEBUGP("Changing expectation mask to handle multiple ports\n");
-+ exp->mask.src.u.udp.port = 0xfffe;
-+ }
-+
-+ DEBUGP("expect_related %u.%u.%u.%u:%u-%u.%u.%u.%u:%u\n",
-+ NIPQUAD(exp->tuple.src.u3.ip),
-+ ntohs(exp->tuple.src.u.udp.port),
-+ NIPQUAD(exp->tuple.dst.u3.ip),
-+ ntohs(exp->tuple.dst.u.udp.port));
-+
-+ if (nf_nat_rtsp_hook)
-+ /* pass the request off to the nat helper */
-+ ret = nf_nat_rtsp_hook(pskb, ctinfo, hdrsoff, hdrslen, &expinfo, exp);
-+ else if (nf_ct_expect_related(exp) != 0) {
-+ INFOP("nf_ct_expect_related failed\n");
-+ ret = NF_DROP;
-+ }
-+ nf_ct_expect_put(exp);
-+ goto out;
-+ }
-+out:
-+
-+ return ret;
-+}
-+
-+
-+static inline int
-+help_in(struct sk_buff **pskb, size_t pktlen,
-+ struct nf_conn* ct, enum ip_conntrack_info ctinfo)
-+{
-+ return NF_ACCEPT;
-+}
-+
-+static int help(struct sk_buff **pskb, unsigned int protoff,
-+ struct nf_conn *ct, enum ip_conntrack_info ctinfo)
-+{
-+ struct tcphdr _tcph, *th;
-+ unsigned int dataoff, datalen;
-+ char *rb_ptr;
-+ int ret = NF_DROP;
-+
-+ /* Until there's been traffic both ways, don't look in packets. */
-+ if (ctinfo != IP_CT_ESTABLISHED &&
-+ ctinfo != IP_CT_ESTABLISHED + IP_CT_IS_REPLY) {
-+ DEBUGP("conntrackinfo = %u\n", ctinfo);
-+ return NF_ACCEPT;
-+ }
-+
-+ /* Not whole TCP header? */
-+ th = skb_header_pointer(*pskb,protoff, sizeof(_tcph), &_tcph);
-+
-+ if (!th)
-+ return NF_ACCEPT;
-+
-+ /* No data ? */
-+ dataoff = protoff + th->doff*4;
-+ datalen = (*pskb)->len - dataoff;
-+ if (dataoff >= (*pskb)->len)
-+ return NF_ACCEPT;
-+
-+ spin_lock_bh(&rtsp_buffer_lock);
-+ rb_ptr = skb_header_pointer(*pskb, dataoff,
-+ (*pskb)->len - dataoff, rtsp_buffer);
-+ BUG_ON(rb_ptr == NULL);
-+
-+#if 0
-+ /* Checksum invalid? Ignore. */
-+ /* FIXME: Source route IP option packets --RR */
-+ if (tcp_v4_check(tcph, tcplen, iph->saddr, iph->daddr,
-+ csum_partial((char*)tcph, tcplen, 0)))
-+ {
-+ DEBUGP("bad csum: %p %u %u.%u.%u.%u %u.%u.%u.%u\n",
-+ tcph, tcplen, NIPQUAD(iph->saddr), NIPQUAD(iph->daddr));
-+ return NF_ACCEPT;
-+ }
-+#endif
-+
-+ switch (CTINFO2DIR(ctinfo)) {
-+ case IP_CT_DIR_ORIGINAL:
-+ ret = help_out(pskb, rb_ptr, datalen, ct, ctinfo);
-+ break;
-+ case IP_CT_DIR_REPLY:
-+ DEBUGP("IP_CT_DIR_REPLY\n");
-+ /* inbound packet: server->client */
-+ ret = NF_ACCEPT;
-+ break;
-+ }
-+
-+ spin_unlock_bh(&rtsp_buffer_lock);
-+
-+ return ret;
-+}
-+
-+static struct nf_conntrack_helper rtsp_helpers[MAX_PORTS];
-+static char rtsp_names[MAX_PORTS][10];
-+
-+/* This function is intentionally _NOT_ defined as __exit */
-+static void
-+fini(void)
-+{
-+ int i;
-+ for (i = 0; i < num_ports; i++) {
-+ DEBUGP("unregistering port %d\n", ports[i]);
-+ nf_conntrack_helper_unregister(&rtsp_helpers[i]);
-+ }
-+ kfree(rtsp_buffer);
-+}
-+
-+static int __init
-+init(void)
-+{
-+ int i, ret;
-+ struct nf_conntrack_helper *hlpr;
-+ char *tmpname;
-+
-+ printk("nf_conntrack_rtsp v" IP_NF_RTSP_VERSION " loading\n");
-+
-+ if (max_outstanding < 1) {
-+ printk("nf_conntrack_rtsp: max_outstanding must be a positive integer\n");
-+ return -EBUSY;
-+ }
-+ if (setup_timeout < 0) {
-+ printk("nf_conntrack_rtsp: setup_timeout must be a positive integer\n");
-+ return -EBUSY;
-+ }
-+
-+ rtsp_buffer = kmalloc(65536, GFP_KERNEL);
-+ if (!rtsp_buffer)
-+ return -ENOMEM;
-+
-+ /* If no port given, default to standard rtsp port */
-+ if (ports[0] == 0) {
-+ ports[0] = RTSP_PORT;
-+ }
-+
-+ for (i = 0; (i < MAX_PORTS) && ports[i]; i++) {
-+ hlpr = &rtsp_helpers[i];
-+ memset(hlpr, 0, sizeof(struct nf_conntrack_helper));
-+ hlpr->tuple.src.u.tcp.port = htons(ports[i]);
-+ hlpr->tuple.dst.protonum = IPPROTO_TCP;
-+ hlpr->max_expected = max_outstanding;
-+ hlpr->timeout = setup_timeout;
-+ hlpr->me = THIS_MODULE;
-+ hlpr->help = help;
-+
-+ tmpname = &rtsp_names[i][0];
-+ if (ports[i] == RTSP_PORT) {
-+ sprintf(tmpname, "rtsp");
-+ } else {
-+ sprintf(tmpname, "rtsp-%d", i);
-+ }
-+ hlpr->name = tmpname;
-+
-+ DEBUGP("port #%d: %d\n", i, ports[i]);
-+
-+ ret = nf_conntrack_helper_register(hlpr);
-+
-+ if (ret) {
-+ printk("nf_conntrack_rtsp: ERROR registering port %d\n", ports[i]);
-+ fini();
-+ return -EBUSY;
-+ }
-+ num_ports++;
-+ }
-+ return 0;
-+}
-+
-+module_init(init);
-+module_exit(fini);
-+
-+EXPORT_SYMBOL(nf_nat_rtsp_hook_expectfn);
-+
---- /dev/null
-+++ b/net/ipv4/netfilter/nf_nat_rtsp.c
-@@ -0,0 +1,496 @@
-+/*
-+ * RTSP extension for TCP NAT alteration
-+ * (C) 2003 by Tom Marshall <tmarshall at real.com>
-+ * based on ip_nat_irc.c
-+ *
-+ * 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.
-+ *
-+ * Module load syntax:
-+ * insmod nf_nat_rtsp.o ports=port1,port2,...port<MAX_PORTS>
-+ * stunaddr=<address>
-+ * destaction=[auto|strip|none]
-+ *
-+ * If no ports are specified, the default will be port 554 only.
-+ *
-+ * stunaddr specifies the address used to detect that a client is using STUN.
-+ * If this address is seen in the destination parameter, it is assumed that
-+ * the client has already punched a UDP hole in the firewall, so we don't
-+ * mangle the client_port. If none is specified, it is autodetected. It
-+ * only needs to be set if you have multiple levels of NAT. It should be
-+ * set to the external address that the STUN clients detect. Note that in
-+ * this case, it will not be possible for clients to use UDP with servers
-+ * between the NATs.
-+ *
-+ * If no destaction is specified, auto is used.
-+ * destaction=auto: strip destination parameter if it is not stunaddr.
-+ * destaction=strip: always strip destination parameter (not recommended).
-+ * destaction=none: do not touch destination parameter (not recommended).
-+ */
-+
-+#include <linux/module.h>
-+#include <net/tcp.h>
-+#include <net/netfilter/nf_nat_helper.h>
-+#include <net/netfilter/nf_nat_rule.h>
-+#include <linux/netfilter/nf_conntrack_rtsp.h>
-+#include <net/netfilter/nf_conntrack_expect.h>
-+
-+#include <linux/inet.h>
-+#include <linux/ctype.h>
-+#define NF_NEED_STRNCASECMP
-+#define NF_NEED_STRTOU16
-+#include <linux/netfilter_helpers.h>
-+#define NF_NEED_MIME_NEXTLINE
-+#include <linux/netfilter_mime.h>
-+
-+#define INFOP(fmt, args...) printk(KERN_INFO "%s: %s: " fmt, __FILE__, __FUNCTION__ , ## args)
-+#if 0
-+#define DEBUGP(fmt, args...) printk(KERN_DEBUG "%s: %s: " fmt, __FILE__, __FUNCTION__ , ## args)
-+#else
-+#define DEBUGP(fmt, args...)
-+#endif
-+
-+#define MAX_PORTS 8
-+#define DSTACT_AUTO 0
-+#define DSTACT_STRIP 1
-+#define DSTACT_NONE 2
-+
-+static char* stunaddr = NULL;
-+static char* destaction = NULL;
-+
-+static u_int32_t extip = 0;
-+static int dstact = 0;
-+
-+MODULE_AUTHOR("Tom Marshall <tmarshall at real.com>");
-+MODULE_DESCRIPTION("RTSP network address translation module");
-+MODULE_LICENSE("GPL");
-+module_param(stunaddr, charp, 0644);
-+MODULE_PARM_DESC(stunaddr, "Address for detecting STUN");
-+module_param(destaction, charp, 0644);
-+MODULE_PARM_DESC(destaction, "Action for destination parameter (auto/strip/none)");
-+
-+#define SKIP_WSPACE(ptr,len,off) while(off < len && isspace(*(ptr+off))) { off++; }
-+
-+/*** helper functions ***/
-+
-+static void
-+get_skb_tcpdata(struct sk_buff* skb, char** pptcpdata, uint* ptcpdatalen)
-+{
-+ struct iphdr* iph = ip_hdr(skb);
-+ struct tcphdr* tcph = (void *)iph + ip_hdrlen(skb);
-+
-+ *pptcpdata = (char*)tcph + tcph->doff*4;
-+ *ptcpdatalen = ((char*)skb_transport_header(skb) + skb->len) - *pptcpdata;
-+}
-+
-+/*** nat functions ***/
-+
-+/*
-+ * Mangle the "Transport:" header:
-+ * - Replace all occurences of "client_port=<spec>"
-+ * - Handle destination parameter
-+ *
-+ * In:
-+ * ct, ctinfo = conntrack context
-+ * pskb = packet
-+ * tranoff = Transport header offset from TCP data
-+ * tranlen = Transport header length (incl. CRLF)
-+ * rport_lo = replacement low port (host endian)
-+ * rport_hi = replacement high port (host endian)
-+ *
-+ * Returns packet size difference.
-+ *
-+ * Assumes that a complete transport header is present, ending with CR or LF
-+ */
-+static int
-+rtsp_mangle_tran(enum ip_conntrack_info ctinfo,
-+ struct nf_conntrack_expect* exp,
-+ struct ip_ct_rtsp_expect* prtspexp,
-+ struct sk_buff** pskb, uint tranoff, uint tranlen)
-+{
-+ char* ptcp;
-+ uint tcplen;
-+ char* ptran;
-+ char rbuf1[16]; /* Replacement buffer (one port) */
-+ uint rbuf1len; /* Replacement len (one port) */
-+ char rbufa[16]; /* Replacement buffer (all ports) */
-+ uint rbufalen; /* Replacement len (all ports) */
-+ u_int32_t newip;
-+ u_int16_t loport, hiport;
-+ uint off = 0;
-+ uint diff; /* Number of bytes we removed */
-+
-+ struct nf_conn *ct = exp->master;
-+ struct nf_conntrack_tuple *t;
-+
-+ char szextaddr[15+1];
-+ uint extaddrlen;
-+ int is_stun;
-+
-+ get_skb_tcpdata(*pskb, &ptcp, &tcplen);
-+ ptran = ptcp+tranoff;
-+
-+ if (tranoff+tranlen > tcplen || tcplen-tranoff < tranlen ||
-+ tranlen < 10 || !iseol(ptran[tranlen-1]) ||
-+ nf_strncasecmp(ptran, "Transport:", 10) != 0)
-+ {
-+ INFOP("sanity check failed\n");
-+ return 0;
-+ }
-+ off += 10;
-+ SKIP_WSPACE(ptcp+tranoff, tranlen, off);
-+
-+ newip = ct->tuplehash[IP_CT_DIR_REPLY].tuple.dst.u3.ip;
-+ t = &exp->tuple;
-+ t->dst.u3.ip = newip;
-+
-+ extaddrlen = extip ? sprintf(szextaddr, "%u.%u.%u.%u", NIPQUAD(extip))
-+ : sprintf(szextaddr, "%u.%u.%u.%u", NIPQUAD(newip));
-+ DEBUGP("stunaddr=%s (%s)\n", szextaddr, (extip?"forced":"auto"));
-+
-+ rbuf1len = rbufalen = 0;
-+ switch (prtspexp->pbtype)
-+ {
-+ case pb_single:
-+ for (loport = prtspexp->loport; loport != 0; loport++) /* XXX: improper wrap? */
-+ {
-+ t->dst.u.udp.port = htons(loport);
-+ if (nf_ct_expect_related(exp) == 0)
-+ {
-+ DEBUGP("using port %hu\n", loport);
-+ break;
-+ }
-+ }
-+ if (loport != 0)
-+ {
-+ rbuf1len = sprintf(rbuf1, "%hu", loport);
-+ rbufalen = sprintf(rbufa, "%hu", loport);
-+ }
-+ break;
-+ case pb_range:
-+ for (loport = prtspexp->loport; loport != 0; loport += 2) /* XXX: improper wrap? */
-+ {
-+ t->dst.u.udp.port = htons(loport);
-+ if (nf_ct_expect_related(exp) == 0)
-+ {
-+ hiport = loport + ~exp->mask.src.u.udp.port;
-+ DEBUGP("using ports %hu-%hu\n", loport, hiport);
-+ break;
-+ }
-+ }
-+ if (loport != 0)
-+ {
-+ rbuf1len = sprintf(rbuf1, "%hu", loport);
-+ rbufalen = sprintf(rbufa, "%hu-%hu", loport, loport+1);
-+ }
-+ break;
-+ case pb_discon:
-+ for (loport = prtspexp->loport; loport != 0; loport++) /* XXX: improper wrap? */
-+ {
-+ t->dst.u.udp.port = htons(loport);
-+ if (nf_ct_expect_related(exp) == 0)
-+ {
-+ DEBUGP("using port %hu (1 of 2)\n", loport);
-+ break;
-+ }
-+ }
-+ for (hiport = prtspexp->hiport; hiport != 0; hiport++) /* XXX: improper wrap? */
-+ {
-+ t->dst.u.udp.port = htons(hiport);
-+ if (nf_ct_expect_related(exp) == 0)
-+ {
-+ DEBUGP("using port %hu (2 of 2)\n", hiport);
-+ break;
-+ }
-+ }
-+ if (loport != 0 && hiport != 0)
-+ {
-+ rbuf1len = sprintf(rbuf1, "%hu", loport);
-+ if (hiport == loport+1)
-+ {
-+ rbufalen = sprintf(rbufa, "%hu-%hu", loport, hiport);
-+ }
-+ else
-+ {
-+ rbufalen = sprintf(rbufa, "%hu/%hu", loport, hiport);
-+ }
-+ }
-+ break;
-+ }
-+
-+ if (rbuf1len == 0)
-+ {
-+ return 0; /* cannot get replacement port(s) */
-+ }
-+
-+ /* Transport: tran;field;field=val,tran;field;field=val,... */
-+ while (off < tranlen)
-+ {
-+ uint saveoff;
-+ const char* pparamend;
-+ uint nextparamoff;
-+
-+ pparamend = memchr(ptran+off, ',', tranlen-off);
-+ pparamend = (pparamend == NULL) ? ptran+tranlen : pparamend+1;
-+ nextparamoff = pparamend-ptcp;
-+
-+ /*
-+ * We pass over each param twice. On the first pass, we look for a
-+ * destination= field. It is handled by the security policy. If it
-+ * is present, allowed, and equal to our external address, we assume
-+ * that STUN is being used and we leave the client_port= field alone.
-+ */
-+ is_stun = 0;
-+ saveoff = off;
-+ while (off < nextparamoff)
-+ {
-+ const char* pfieldend;
-+ uint nextfieldoff;
-+
-+ pfieldend = memchr(ptran+off, ';', nextparamoff-off);
-+ nextfieldoff = (pfieldend == NULL) ? nextparamoff : pfieldend-ptran+1;
-+
-+ if (dstact != DSTACT_NONE && strncmp(ptran+off, "destination=", 12) == 0)
-+ {
-+ if (strncmp(ptran+off+12, szextaddr, extaddrlen) == 0)
-+ {
-+ is_stun = 1;
-+ }
-+ if (dstact == DSTACT_STRIP || (dstact == DSTACT_AUTO && !is_stun))
-+ {
-+ diff = nextfieldoff-off;
-+ if (!nf_nat_mangle_tcp_packet(pskb, ct, ctinfo,
-+ off, diff, NULL, 0))
-+ {
-+ /* mangle failed, all we can do is bail */
-+ nf_ct_unexpect_related(exp);
-+ return 0;
-+ }
-+ get_skb_tcpdata(*pskb, &ptcp, &tcplen);
-+ ptran = ptcp+tranoff;
-+ tranlen -= diff;
-+ nextparamoff -= diff;
-+ nextfieldoff -= diff;
-+ }
-+ }
-+
-+ off = nextfieldoff;
-+ }
-+ if (is_stun)
-+ {
-+ continue;
-+ }
-+ off = saveoff;
-+ while (off < nextparamoff)
-+ {
-+ const char* pfieldend;
-+ uint nextfieldoff;
-+
-+ pfieldend = memchr(ptran+off, ';', nextparamoff-off);
-+ nextfieldoff = (pfieldend == NULL) ? nextparamoff : pfieldend-ptran+1;
-+
-+ if (strncmp(ptran+off, "client_port=", 12) == 0)
-+ {
-+ u_int16_t port;
-+ uint numlen;
-+ uint origoff;
-+ uint origlen;
-+ char* rbuf = rbuf1;
-+ uint rbuflen = rbuf1len;
-+
-+ off += 12;
-+ origoff = (ptran-ptcp)+off;
-+ origlen = 0;
-+ numlen = nf_strtou16(ptran+off, &port);
-+ off += numlen;
-+ origlen += numlen;
-+ if (port != prtspexp->loport)
-+ {
-+ DEBUGP("multiple ports found, port %hu ignored\n", port);
-+ }
-+ else
-+ {
-+ if (ptran[off] == '-' || ptran[off] == '/')
-+ {
-+ off++;
-+ origlen++;
-+ numlen = nf_strtou16(ptran+off, &port);
-+ off += numlen;
-+ origlen += numlen;
-+ rbuf = rbufa;
-+ rbuflen = rbufalen;
-+ }
-+
-+ /*
-+ * note we cannot just memcpy() if the sizes are the same.
-+ * the mangle function does skb resizing, checks for a
-+ * cloned skb, and updates the checksums.
-+ *
-+ * parameter 4 below is offset from start of tcp data.
-+ */
-+ diff = origlen-rbuflen;
-+ if (!nf_nat_mangle_tcp_packet(pskb, ct, ctinfo,
-+ origoff, origlen, rbuf, rbuflen))
-+ {
-+ /* mangle failed, all we can do is bail */
-+ nf_ct_unexpect_related(exp);
-+ return 0;
-+ }
-+ get_skb_tcpdata(*pskb, &ptcp, &tcplen);
-+ ptran = ptcp+tranoff;
-+ tranlen -= diff;
-+ nextparamoff -= diff;
-+ nextfieldoff -= diff;
-+ }
-+ }
-+
-+ off = nextfieldoff;
-+ }
-+
-+ off = nextparamoff;
-+ }
-+
-+ return 1;
-+}
-+
-+static uint
-+help_out(struct sk_buff **pskb, enum ip_conntrack_info ctinfo,
-+ unsigned int matchoff, unsigned int matchlen, struct ip_ct_rtsp_expect* prtspexp,
-+ struct nf_conntrack_expect* exp)
-+{
-+ char* ptcp;
-+ uint tcplen;
-+ uint hdrsoff;
-+ uint hdrslen;
-+ uint lineoff;
-+ uint linelen;
-+ uint off;
-+
-+ //struct iphdr* iph = (struct iphdr*)(*pskb)->nh.iph;
-+ //struct tcphdr* tcph = (struct tcphdr*)((void*)iph + iph->ihl*4);
-+
-+ get_skb_tcpdata(*pskb, &ptcp, &tcplen);
-+ hdrsoff = matchoff;//exp->seq - ntohl(tcph->seq);
-+ hdrslen = matchlen;
-+ off = hdrsoff;
-+ DEBUGP("NAT rtsp help_out\n");
-+
-+ while (nf_mime_nextline(ptcp, hdrsoff+hdrslen, &off, &lineoff, &linelen))
-+ {
-+ if (linelen == 0)
-+ {
-+ break;
-+ }
-+ if (off > hdrsoff+hdrslen)
-+ {
-+ INFOP("!! overrun !!");
-+ break;
-+ }
-+ DEBUGP("hdr: len=%u, %.*s", linelen, (int)linelen, ptcp+lineoff);
-+
-+ if (nf_strncasecmp(ptcp+lineoff, "Transport:", 10) == 0)
-+ {
-+ uint oldtcplen = tcplen;
-+ DEBUGP("hdr: Transport\n");
-+ if (!rtsp_mangle_tran(ctinfo, exp, prtspexp, pskb, lineoff, linelen))
-+ {
-+ DEBUGP("hdr: Transport mangle failed");
-+ break;
-+ }
-+ get_skb_tcpdata(*pskb, &ptcp, &tcplen);
-+ hdrslen -= (oldtcplen-tcplen);
-+ off -= (oldtcplen-tcplen);
-+ lineoff -= (oldtcplen-tcplen);
-+ linelen -= (oldtcplen-tcplen);
-+ DEBUGP("rep: len=%u, %.*s", linelen, (int)linelen, ptcp+lineoff);
-+ }
-+ }
-+
-+ return NF_ACCEPT;
-+}
-+
-+static unsigned int
-+help(struct sk_buff **pskb, enum ip_conntrack_info ctinfo,
-+ unsigned int matchoff, unsigned int matchlen, struct ip_ct_rtsp_expect* prtspexp,
-+ struct nf_conntrack_expect* exp)
-+{
-+ int dir = CTINFO2DIR(ctinfo);
-+ int rc = NF_ACCEPT;
-+
-+ switch (dir)
-+ {
-+ case IP_CT_DIR_ORIGINAL:
-+ rc = help_out(pskb, ctinfo, matchoff, matchlen, prtspexp, exp);
-+ break;
-+ case IP_CT_DIR_REPLY:
-+ DEBUGP("unmangle ! %u\n", ctinfo);
-+ /* XXX: unmangle */
-+ rc = NF_ACCEPT;
-+ break;
-+ }
-+ //UNLOCK_BH(&ip_rtsp_lock);
-+
-+ return rc;
-+}
-+
-+static void expected(struct nf_conn* ct, struct nf_conntrack_expect *exp)
-+{
-+ struct nf_nat_multi_range_compat mr;
-+ u_int32_t newdstip, newsrcip, newip;
-+
-+ struct nf_conn *master = ct->master;
-+
-+ newdstip = master->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.u3.ip;
-+ newsrcip = ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.u3.ip;
-+ //FIXME (how to port that ?)
-+ //code from 2.4 : newip = (HOOK2MANIP(hooknum) == IP_NAT_MANIP_SRC) ? newsrcip : newdstip;
-+ newip = newdstip;
-+
-+ DEBUGP("newsrcip=%u.%u.%u.%u, newdstip=%u.%u.%u.%u, newip=%u.%u.%u.%u\n",
-+ NIPQUAD(newsrcip), NIPQUAD(newdstip), NIPQUAD(newip));
-+
-+ mr.rangesize = 1;
-+ // We don't want to manip the per-protocol, just the IPs.
-+ mr.range[0].flags = IP_NAT_RANGE_MAP_IPS;
-+ mr.range[0].min_ip = mr.range[0].max_ip = newip;
-+
-+ nf_nat_setup_info(ct, &mr.range[0], NF_IP_PRE_ROUTING);
-+}
-+
-+
-+static void __exit fini(void)
-+{
-+ nf_nat_rtsp_hook = NULL;
-+ nf_nat_rtsp_hook_expectfn = NULL;
-+ synchronize_net();
-+}
-+
-+static int __init init(void)
-+{
-+ printk("nf_nat_rtsp v" IP_NF_RTSP_VERSION " loading\n");
-+
-+ BUG_ON(nf_nat_rtsp_hook);
-+ nf_nat_rtsp_hook = help;
-+ nf_nat_rtsp_hook_expectfn = &expected;
-+
-+ if (stunaddr != NULL)
-+ extip = in_aton(stunaddr);
-+
-+ if (destaction != NULL) {
-+ if (strcmp(destaction, "auto") == 0)
-+ dstact = DSTACT_AUTO;
-+
-+ if (strcmp(destaction, "strip") == 0)
-+ dstact = DSTACT_STRIP;
-+
-+ if (strcmp(destaction, "none") == 0)
-+ dstact = DSTACT_NONE;
-+ }
-+
-+ return 0;
-+}
-+
-+module_init(init);
-+module_exit(fini);
+++ /dev/null
---- a/include/linux/pkt_sched.h
-+++ b/include/linux/pkt_sched.h
-@@ -155,8 +155,37 @@
- *
- * The only reason for this is efficiency, it is possible
- * to change these parameters in compile time.
-+ *
-+ * If you need to play with these values, use esfq instead.
- */
-
-+/* ESFQ section */
-+
-+enum
-+{
-+ /* traditional */
-+ TCA_SFQ_HASH_CLASSIC,
-+ TCA_SFQ_HASH_DST,
-+ TCA_SFQ_HASH_SRC,
-+ TCA_SFQ_HASH_FWMARK,
-+ /* conntrack */
-+ TCA_SFQ_HASH_CTORIGDST,
-+ TCA_SFQ_HASH_CTORIGSRC,
-+ TCA_SFQ_HASH_CTREPLDST,
-+ TCA_SFQ_HASH_CTREPLSRC,
-+ TCA_SFQ_HASH_CTNATCHG,
-+};
-+
-+struct tc_esfq_qopt
-+{
-+ unsigned quantum; /* Bytes per round allocated to flow */
-+ int perturb_period; /* Period of hash perturbation */
-+ __u32 limit; /* Maximal packets in queue */
-+ unsigned divisor; /* Hash divisor */
-+ unsigned flows; /* Maximal number of flows */
-+ unsigned hash_kind; /* Hash function to use for flow identification */
-+};
-+
- /* RED section */
-
- enum
---- a/net/sched/Kconfig
-+++ b/net/sched/Kconfig
-@@ -144,6 +144,37 @@
- To compile this code as a module, choose M here: the
- module will be called sch_sfq.
-
-+config NET_SCH_ESFQ
-+ tristate "Enhanced Stochastic Fairness Queueing (ESFQ)"
-+ ---help---
-+ Say Y here if you want to use the Enhanced Stochastic Fairness
-+ Queueing (ESFQ) packet scheduling algorithm for some of your network
-+ devices or as a leaf discipline for a classful qdisc such as HTB or
-+ CBQ (see the top of <file:net/sched/sch_esfq.c> for details and
-+ references to the SFQ algorithm).
-+
-+ This is an enchanced SFQ version which allows you to control some
-+ hardcoded values in the SFQ scheduler.
-+
-+ ESFQ also adds control of the hash function used to identify packet
-+ flows. The original SFQ discipline hashes by connection; ESFQ add
-+ several other hashing methods, such as by src IP or by dst IP, which
-+ can be more fair to users in some networking situations.
-+
-+ To compile this code as a module, choose M here: the
-+ module will be called sch_esfq.
-+
-+config NET_SCH_ESFQ_NFCT
-+ bool "Connection Tracking Hash Types"
-+ depends on NET_SCH_ESFQ && NF_CONNTRACK
-+ ---help---
-+ Say Y here to enable support for hashing based on netfilter connection
-+ tracking information. This is useful for a router that is also using
-+ NAT to connect privately-addressed hosts to the Internet. If you want
-+ to provide fair distribution of upstream bandwidth, ESFQ must use
-+ connection tracking information, since all outgoing packets will share
-+ the same source address.
-+
- config NET_SCH_TEQL
- tristate "True Link Equalizer (TEQL)"
- ---help---
---- a/net/sched/Makefile
-+++ b/net/sched/Makefile
-@@ -22,6 +22,7 @@
- obj-$(CONFIG_NET_SCH_INGRESS) += sch_ingress.o
- obj-$(CONFIG_NET_SCH_DSMARK) += sch_dsmark.o
- obj-$(CONFIG_NET_SCH_SFQ) += sch_sfq.o
-+obj-$(CONFIG_NET_SCH_ESFQ) += sch_esfq.o
- obj-$(CONFIG_NET_SCH_TBF) += sch_tbf.o
- obj-$(CONFIG_NET_SCH_TEQL) += sch_teql.o
- obj-$(CONFIG_NET_SCH_PRIO) += sch_prio.o
---- /dev/null
-+++ b/net/sched/sch_esfq.c
-@@ -0,0 +1,702 @@
-+/*
-+ * net/sched/sch_esfq.c Extended Stochastic Fairness Queueing discipline.
-+ *
-+ * 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.
-+ *
-+ * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
-+ *
-+ * Changes: Alexander Atanasov, <alex@ssi.bg>
-+ * Added dynamic depth,limit,divisor,hash_kind options.
-+ * Added dst and src hashes.
-+ *
-+ * Alexander Clouter, <alex@digriz.org.uk>
-+ * Ported ESFQ to Linux 2.6.
-+ *
-+ * Corey Hickey, <bugfood-c@fatooh.org>
-+ * Maintenance of the Linux 2.6 port.
-+ * Added fwmark hash (thanks to Robert Kurjata).
-+ * Added usage of jhash.
-+ * Added conntrack support.
-+ * Added ctnatchg hash (thanks to Ben Pfountz).
-+ */
-+
-+#include <linux/module.h>
-+#include <asm/uaccess.h>
-+#include <asm/system.h>
-+#include <linux/bitops.h>
-+#include <linux/types.h>
-+#include <linux/kernel.h>
-+#include <linux/jiffies.h>
-+#include <linux/string.h>
-+#include <linux/mm.h>
-+#include <linux/socket.h>
-+#include <linux/sockios.h>
-+#include <linux/in.h>
-+#include <linux/errno.h>
-+#include <linux/interrupt.h>
-+#include <linux/if_ether.h>
-+#include <linux/inet.h>
-+#include <linux/netdevice.h>
-+#include <linux/etherdevice.h>
-+#include <linux/notifier.h>
-+#include <linux/init.h>
-+#include <net/ip.h>
-+#include <linux/ipv6.h>
-+#include <net/route.h>
-+#include <linux/skbuff.h>
-+#include <net/sock.h>
-+#include <net/pkt_sched.h>
-+#include <linux/jhash.h>
-+#include <net/netfilter/nf_conntrack.h>
-+
-+/* Stochastic Fairness Queuing algorithm.
-+ For more comments look at sch_sfq.c.
-+ The difference is that you can change limit, depth,
-+ hash table size and choose alternate hash types.
-+
-+ classic: same as in sch_sfq.c
-+ dst: destination IP address
-+ src: source IP address
-+ fwmark: netfilter mark value
-+ ctorigdst: original destination IP address
-+ ctorigsrc: original source IP address
-+ ctrepldst: reply destination IP address
-+ ctreplsrc: reply source IP
-+
-+*/
-+
-+#define ESFQ_HEAD 0
-+#define ESFQ_TAIL 1
-+
-+/* This type should contain at least SFQ_DEPTH*2 values */
-+typedef unsigned int esfq_index;
-+
-+struct esfq_head
-+{
-+ esfq_index next;
-+ esfq_index prev;
-+};
-+
-+struct esfq_sched_data
-+{
-+/* Parameters */
-+ int perturb_period;
-+ unsigned quantum; /* Allotment per round: MUST BE >= MTU */
-+ int limit;
-+ unsigned depth;
-+ unsigned hash_divisor;
-+ unsigned hash_kind;
-+/* Variables */
-+ struct timer_list perturb_timer;
-+ int perturbation;
-+ esfq_index tail; /* Index of current slot in round */
-+ esfq_index max_depth; /* Maximal depth */
-+
-+ esfq_index *ht; /* Hash table */
-+ esfq_index *next; /* Active slots link */
-+ short *allot; /* Current allotment per slot */
-+ unsigned short *hash; /* Hash value indexed by slots */
-+ struct sk_buff_head *qs; /* Slot queue */
-+ struct esfq_head *dep; /* Linked list of slots, indexed by depth */
-+};
-+
-+/* This contains the info we will hash. */
-+struct esfq_packet_info
-+{
-+ u32 proto; /* protocol or port */
-+ u32 src; /* source from packet header */
-+ u32 dst; /* destination from packet header */
-+ u32 ctorigsrc; /* original source from conntrack */
-+ u32 ctorigdst; /* original destination from conntrack */
-+ u32 ctreplsrc; /* reply source from conntrack */
-+ u32 ctrepldst; /* reply destination from conntrack */
-+ u32 mark; /* netfilter mark (fwmark) */
-+};
-+
-+static __inline__ unsigned esfq_jhash_1word(struct esfq_sched_data *q,u32 a)
-+{
-+ return jhash_1word(a, q->perturbation) & (q->hash_divisor-1);
-+}
-+
-+static __inline__ unsigned esfq_jhash_2words(struct esfq_sched_data *q, u32 a, u32 b)
-+{
-+ return jhash_2words(a, b, q->perturbation) & (q->hash_divisor-1);
-+}
-+
-+static __inline__ unsigned esfq_jhash_3words(struct esfq_sched_data *q, u32 a, u32 b, u32 c)
-+{
-+ return jhash_3words(a, b, c, q->perturbation) & (q->hash_divisor-1);
-+}
-+
-+static unsigned esfq_hash(struct esfq_sched_data *q, struct sk_buff *skb)
-+{
-+ struct esfq_packet_info info;
-+#ifdef CONFIG_NET_SCH_ESFQ_NFCT
-+ enum ip_conntrack_info ctinfo;
-+ struct nf_conn *ct = nf_ct_get(skb, &ctinfo);
-+#endif
-+
-+ switch (skb->protocol) {
-+ case __constant_htons(ETH_P_IP):
-+ {
-+ struct iphdr *iph = ip_hdr(skb);
-+ info.dst = iph->daddr;
-+ info.src = iph->saddr;
-+ if (!(iph->frag_off&htons(IP_MF|IP_OFFSET)) &&
-+ (iph->protocol == IPPROTO_TCP ||
-+ iph->protocol == IPPROTO_UDP ||
-+ iph->protocol == IPPROTO_SCTP ||
-+ iph->protocol == IPPROTO_DCCP ||
-+ iph->protocol == IPPROTO_ESP))
-+ info.proto = *(((u32*)iph) + iph->ihl);
-+ else
-+ info.proto = iph->protocol;
-+ break;
-+ }
-+ case __constant_htons(ETH_P_IPV6):
-+ {
-+ struct ipv6hdr *iph = ipv6_hdr(skb);
-+ /* Hash ipv6 addresses into a u32. This isn't ideal,
-+ * but the code is simple. */
-+ info.dst = jhash2(iph->daddr.s6_addr32, 4, q->perturbation);
-+ info.src = jhash2(iph->saddr.s6_addr32, 4, q->perturbation);
-+ if (iph->nexthdr == IPPROTO_TCP ||
-+ iph->nexthdr == IPPROTO_UDP ||
-+ iph->nexthdr == IPPROTO_SCTP ||
-+ iph->nexthdr == IPPROTO_DCCP ||
-+ iph->nexthdr == IPPROTO_ESP)
-+ info.proto = *(u32*)&iph[1];
-+ else
-+ info.proto = iph->nexthdr;
-+ break;
-+ }
-+ default:
-+ info.dst = (u32)(unsigned long)skb->dst;
-+ info.src = (u32)(unsigned long)skb->sk;
-+ info.proto = skb->protocol;
-+ }
-+
-+ info.mark = skb->mark;
-+
-+#ifdef CONFIG_NET_SCH_ESFQ_NFCT
-+ /* defaults if there is no conntrack info */
-+ info.ctorigsrc = info.src;
-+ info.ctorigdst = info.dst;
-+ info.ctreplsrc = info.dst;
-+ info.ctrepldst = info.src;
-+ /* collect conntrack info */
-+ if (ct && ct != &nf_conntrack_untracked) {
-+ if (skb->protocol == __constant_htons(ETH_P_IP)) {
-+ info.ctorigsrc = ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.u3.ip;
-+ info.ctorigdst = ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.u3.ip;
-+ info.ctreplsrc = ct->tuplehash[IP_CT_DIR_REPLY].tuple.src.u3.ip;
-+ info.ctrepldst = ct->tuplehash[IP_CT_DIR_REPLY].tuple.dst.u3.ip;
-+ }
-+ else if (skb->protocol == __constant_htons(ETH_P_IPV6)) {
-+ /* Again, hash ipv6 addresses into a single u32. */
-+ info.ctorigsrc = jhash2(ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.u3.ip6, 4, q->perturbation);
-+ info.ctorigdst = jhash2(ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.u3.ip6, 4, q->perturbation);
-+ info.ctreplsrc = jhash2(ct->tuplehash[IP_CT_DIR_REPLY].tuple.src.u3.ip6, 4, q->perturbation);
-+ info.ctrepldst = jhash2(ct->tuplehash[IP_CT_DIR_REPLY].tuple.dst.u3.ip6, 4, q->perturbation);
-+ }
-+
-+ }
-+#endif
-+
-+ switch(q->hash_kind) {
-+ case TCA_SFQ_HASH_CLASSIC:
-+ return esfq_jhash_3words(q, info.dst, info.src, info.proto);
-+ case TCA_SFQ_HASH_DST:
-+ return esfq_jhash_1word(q, info.dst);
-+ case TCA_SFQ_HASH_SRC:
-+ return esfq_jhash_1word(q, info.src);
-+ case TCA_SFQ_HASH_FWMARK:
-+ return esfq_jhash_1word(q, info.mark);
-+#ifdef CONFIG_NET_SCH_ESFQ_NFCT
-+ case TCA_SFQ_HASH_CTORIGDST:
-+ return esfq_jhash_1word(q, info.ctorigdst);
-+ case TCA_SFQ_HASH_CTORIGSRC:
-+ return esfq_jhash_1word(q, info.ctorigsrc);
-+ case TCA_SFQ_HASH_CTREPLDST:
-+ return esfq_jhash_1word(q, info.ctrepldst);
-+ case TCA_SFQ_HASH_CTREPLSRC:
-+ return esfq_jhash_1word(q, info.ctreplsrc);
-+ case TCA_SFQ_HASH_CTNATCHG:
-+ {
-+ if (info.ctorigdst == info.ctreplsrc)
-+ return esfq_jhash_1word(q, info.ctorigsrc);
-+ return esfq_jhash_1word(q, info.ctreplsrc);
-+ }
-+#endif
-+ default:
-+ if (net_ratelimit())
-+ printk(KERN_WARNING "ESFQ: Unknown hash method. Falling back to classic.\n");
-+ }
-+ return esfq_jhash_3words(q, info.dst, info.src, info.proto);
-+}
-+
-+static inline void esfq_link(struct esfq_sched_data *q, esfq_index x)
-+{
-+ esfq_index p, n;
-+ int d = q->qs[x].qlen + q->depth;
-+
-+ p = d;
-+ n = q->dep[d].next;
-+ q->dep[x].next = n;
-+ q->dep[x].prev = p;
-+ q->dep[p].next = q->dep[n].prev = x;
-+}
-+
-+static inline void esfq_dec(struct esfq_sched_data *q, esfq_index x)
-+{
-+ esfq_index p, n;
-+
-+ n = q->dep[x].next;
-+ p = q->dep[x].prev;
-+ q->dep[p].next = n;
-+ q->dep[n].prev = p;
-+
-+ if (n == p && q->max_depth == q->qs[x].qlen + 1)
-+ q->max_depth--;
-+
-+ esfq_link(q, x);
-+}
-+
-+static inline void esfq_inc(struct esfq_sched_data *q, esfq_index x)
-+{
-+ esfq_index p, n;
-+ int d;
-+
-+ n = q->dep[x].next;
-+ p = q->dep[x].prev;
-+ q->dep[p].next = n;
-+ q->dep[n].prev = p;
-+ d = q->qs[x].qlen;
-+ if (q->max_depth < d)
-+ q->max_depth = d;
-+
-+ esfq_link(q, x);
-+}
-+
-+static unsigned int esfq_drop(struct Qdisc *sch)
-+{
-+ struct esfq_sched_data *q = qdisc_priv(sch);
-+ esfq_index d = q->max_depth;
-+ struct sk_buff *skb;
-+ unsigned int len;
-+
-+ /* Queue is full! Find the longest slot and
-+ drop a packet from it */
-+
-+ if (d > 1) {
-+ esfq_index x = q->dep[d+q->depth].next;
-+ skb = q->qs[x].prev;
-+ len = skb->len;
-+ __skb_unlink(skb, &q->qs[x]);
-+ kfree_skb(skb);
-+ esfq_dec(q, x);
-+ sch->q.qlen--;
-+ sch->qstats.drops++;
-+ sch->qstats.backlog -= len;
-+ return len;
-+ }
-+
-+ if (d == 1) {
-+ /* It is difficult to believe, but ALL THE SLOTS HAVE LENGTH 1. */
-+ d = q->next[q->tail];
-+ q->next[q->tail] = q->next[d];
-+ q->allot[q->next[d]] += q->quantum;
-+ skb = q->qs[d].prev;
-+ len = skb->len;
-+ __skb_unlink(skb, &q->qs[d]);
-+ kfree_skb(skb);
-+ esfq_dec(q, d);
-+ sch->q.qlen--;
-+ q->ht[q->hash[d]] = q->depth;
-+ sch->qstats.drops++;
-+ sch->qstats.backlog -= len;
-+ return len;
-+ }
-+
-+ return 0;
-+}
-+
-+static void esfq_q_enqueue(struct sk_buff *skb, struct esfq_sched_data *q, unsigned int end)
-+{
-+ unsigned hash = esfq_hash(q, skb);
-+ unsigned depth = q->depth;
-+ esfq_index x;
-+
-+ x = q->ht[hash];
-+ if (x == depth) {
-+ q->ht[hash] = x = q->dep[depth].next;
-+ q->hash[x] = hash;
-+ }
-+
-+ if (end == ESFQ_TAIL)
-+ __skb_queue_tail(&q->qs[x], skb);
-+ else
-+ __skb_queue_head(&q->qs[x], skb);
-+
-+ esfq_inc(q, x);
-+ if (q->qs[x].qlen == 1) { /* The flow is new */
-+ if (q->tail == depth) { /* It is the first flow */
-+ q->tail = x;
-+ q->next[x] = x;
-+ q->allot[x] = q->quantum;
-+ } else {
-+ q->next[x] = q->next[q->tail];
-+ q->next[q->tail] = x;
-+ q->tail = x;
-+ }
-+ }
-+}
-+
-+static int esfq_enqueue(struct sk_buff *skb, struct Qdisc* sch)
-+{
-+ struct esfq_sched_data *q = qdisc_priv(sch);
-+ esfq_q_enqueue(skb, q, ESFQ_TAIL);
-+ sch->qstats.backlog += skb->len;
-+ if (++sch->q.qlen < q->limit-1) {
-+ sch->bstats.bytes += skb->len;
-+ sch->bstats.packets++;
-+ return 0;
-+ }
-+
-+ sch->qstats.drops++;
-+ esfq_drop(sch);
-+ return NET_XMIT_CN;
-+}
-+
-+
-+static int esfq_requeue(struct sk_buff *skb, struct Qdisc* sch)
-+{
-+ struct esfq_sched_data *q = qdisc_priv(sch);
-+ esfq_q_enqueue(skb, q, ESFQ_HEAD);
-+ sch->qstats.backlog += skb->len;
-+ if (++sch->q.qlen < q->limit - 1) {
-+ sch->qstats.requeues++;
-+ return 0;
-+ }
-+
-+ sch->qstats.drops++;
-+ esfq_drop(sch);
-+ return NET_XMIT_CN;
-+}
-+
-+static struct sk_buff *esfq_q_dequeue(struct esfq_sched_data *q)
-+{
-+ struct sk_buff *skb;
-+ unsigned depth = q->depth;
-+ esfq_index a, old_a;
-+
-+ /* No active slots */
-+ if (q->tail == depth)
-+ return NULL;
-+
-+ a = old_a = q->next[q->tail];
-+
-+ /* Grab packet */
-+ skb = __skb_dequeue(&q->qs[a]);
-+ esfq_dec(q, a);
-+
-+ /* Is the slot empty? */
-+ if (q->qs[a].qlen == 0) {
-+ q->ht[q->hash[a]] = depth;
-+ a = q->next[a];
-+ if (a == old_a) {
-+ q->tail = depth;
-+ return skb;
-+ }
-+ q->next[q->tail] = a;
-+ q->allot[a] += q->quantum;
-+ } else if ((q->allot[a] -= skb->len) <= 0) {
-+ q->tail = a;
-+ a = q->next[a];
-+ q->allot[a] += q->quantum;
-+ }
-+
-+ return skb;
-+}
-+
-+static struct sk_buff *esfq_dequeue(struct Qdisc* sch)
-+{
-+ struct esfq_sched_data *q = qdisc_priv(sch);
-+ struct sk_buff *skb;
-+
-+ skb = esfq_q_dequeue(q);
-+ if (skb == NULL)
-+ return NULL;
-+ sch->q.qlen--;
-+ sch->qstats.backlog -= skb->len;
-+ return skb;
-+}
-+
-+static void esfq_q_destroy(struct esfq_sched_data *q)
-+{
-+ del_timer(&q->perturb_timer);
-+ if(q->ht)
-+ kfree(q->ht);
-+ if(q->dep)
-+ kfree(q->dep);
-+ if(q->next)
-+ kfree(q->next);
-+ if(q->allot)
-+ kfree(q->allot);
-+ if(q->hash)
-+ kfree(q->hash);
-+ if(q->qs)
-+ kfree(q->qs);
-+}
-+
-+static void esfq_destroy(struct Qdisc *sch)
-+{
-+ struct esfq_sched_data *q = qdisc_priv(sch);
-+ esfq_q_destroy(q);
-+}
-+
-+
-+static void esfq_reset(struct Qdisc* sch)
-+{
-+ struct sk_buff *skb;
-+
-+ while ((skb = esfq_dequeue(sch)) != NULL)
-+ kfree_skb(skb);
-+}
-+
-+static void esfq_perturbation(unsigned long arg)
-+{
-+ struct Qdisc *sch = (struct Qdisc*)arg;
-+ struct esfq_sched_data *q = qdisc_priv(sch);
-+
-+ q->perturbation = net_random()&0x1F;
-+
-+ if (q->perturb_period) {
-+ q->perturb_timer.expires = jiffies + q->perturb_period;
-+ add_timer(&q->perturb_timer);
-+ }
-+}
-+
-+static unsigned int esfq_check_hash(unsigned int kind)
-+{
-+ switch (kind) {
-+ case TCA_SFQ_HASH_CTORIGDST:
-+ case TCA_SFQ_HASH_CTORIGSRC:
-+ case TCA_SFQ_HASH_CTREPLDST:
-+ case TCA_SFQ_HASH_CTREPLSRC:
-+ case TCA_SFQ_HASH_CTNATCHG:
-+#ifndef CONFIG_NET_SCH_ESFQ_NFCT
-+ {
-+ if (net_ratelimit())
-+ printk(KERN_WARNING "ESFQ: Conntrack hash types disabled in kernel config. Falling back to classic.\n");
-+ return TCA_SFQ_HASH_CLASSIC;
-+ }
-+#endif
-+ case TCA_SFQ_HASH_CLASSIC:
-+ case TCA_SFQ_HASH_DST:
-+ case TCA_SFQ_HASH_SRC:
-+ case TCA_SFQ_HASH_FWMARK:
-+ return kind;
-+ default:
-+ {
-+ if (net_ratelimit())
-+ printk(KERN_WARNING "ESFQ: Unknown hash type. Falling back to classic.\n");
-+ return TCA_SFQ_HASH_CLASSIC;
-+ }
-+ }
-+}
-+
-+static int esfq_q_init(struct esfq_sched_data *q, struct rtattr *opt)
-+{
-+ struct tc_esfq_qopt *ctl = RTA_DATA(opt);
-+ esfq_index p = ~0U/2;
-+ int i;
-+
-+ if (opt && opt->rta_len < RTA_LENGTH(sizeof(*ctl)))
-+ return -EINVAL;
-+
-+ q->perturbation = 0;
-+ q->hash_kind = TCA_SFQ_HASH_CLASSIC;
-+ q->max_depth = 0;
-+ if (opt == NULL) {
-+ q->perturb_period = 0;
-+ q->hash_divisor = 1024;
-+ q->tail = q->limit = q->depth = 128;
-+
-+ } else {
-+ struct tc_esfq_qopt *ctl = RTA_DATA(opt);
-+ if (ctl->quantum)
-+ q->quantum = ctl->quantum;
-+ q->perturb_period = ctl->perturb_period*HZ;
-+ q->hash_divisor = ctl->divisor ? : 1024;
-+ q->tail = q->limit = q->depth = ctl->flows ? : 128;
-+
-+ if ( q->depth > p - 1 )
-+ return -EINVAL;
-+
-+ if (ctl->limit)
-+ q->limit = min_t(u32, ctl->limit, q->depth);
-+
-+ if (ctl->hash_kind) {
-+ q->hash_kind = esfq_check_hash(ctl->hash_kind);
-+ }
-+ }
-+
-+ q->ht = kmalloc(q->hash_divisor*sizeof(esfq_index), GFP_KERNEL);
-+ if (!q->ht)
-+ goto err_case;
-+ q->dep = kmalloc((1+q->depth*2)*sizeof(struct esfq_head), GFP_KERNEL);
-+ if (!q->dep)
-+ goto err_case;
-+ q->next = kmalloc(q->depth*sizeof(esfq_index), GFP_KERNEL);
-+ if (!q->next)
-+ goto err_case;
-+ q->allot = kmalloc(q->depth*sizeof(short), GFP_KERNEL);
-+ if (!q->allot)
-+ goto err_case;
-+ q->hash = kmalloc(q->depth*sizeof(unsigned short), GFP_KERNEL);
-+ if (!q->hash)
-+ goto err_case;
-+ q->qs = kmalloc(q->depth*sizeof(struct sk_buff_head), GFP_KERNEL);
-+ if (!q->qs)
-+ goto err_case;
-+
-+ for (i=0; i< q->hash_divisor; i++)
-+ q->ht[i] = q->depth;
-+ for (i=0; i<q->depth; i++) {
-+ skb_queue_head_init(&q->qs[i]);
-+ q->dep[i+q->depth].next = i+q->depth;
-+ q->dep[i+q->depth].prev = i+q->depth;
-+ }
-+
-+ for (i=0; i<q->depth; i++)
-+ esfq_link(q, i);
-+ return 0;
-+err_case:
-+ esfq_q_destroy(q);
-+ return -ENOBUFS;
-+}
-+
-+static int esfq_init(struct Qdisc *sch, struct rtattr *opt)
-+{
-+ struct esfq_sched_data *q = qdisc_priv(sch);
-+ int err;
-+
-+ q->quantum = psched_mtu(sch->dev); /* default */
-+ if ((err = esfq_q_init(q, opt)))
-+ return err;
-+
-+ init_timer(&q->perturb_timer);
-+ q->perturb_timer.data = (unsigned long)sch;
-+ q->perturb_timer.function = esfq_perturbation;
-+ if (q->perturb_period) {
-+ q->perturb_timer.expires = jiffies + q->perturb_period;
-+ add_timer(&q->perturb_timer);
-+ }
-+
-+ return 0;
-+}
-+
-+static int esfq_change(struct Qdisc *sch, struct rtattr *opt)
-+{
-+ struct esfq_sched_data *q = qdisc_priv(sch);
-+ struct esfq_sched_data new;
-+ struct sk_buff *skb;
-+ int err;
-+
-+ /* set up new queue */
-+ memset(&new, 0, sizeof(struct esfq_sched_data));
-+ new.quantum = psched_mtu(sch->dev); /* default */
-+ if ((err = esfq_q_init(&new, opt)))
-+ return err;
-+
-+ /* copy all packets from the old queue to the new queue */
-+ sch_tree_lock(sch);
-+ while ((skb = esfq_q_dequeue(q)) != NULL)
-+ esfq_q_enqueue(skb, &new, ESFQ_TAIL);
-+
-+ /* clean up the old queue */
-+ esfq_q_destroy(q);
-+
-+ /* copy elements of the new queue into the old queue */
-+ q->perturb_period = new.perturb_period;
-+ q->quantum = new.quantum;
-+ q->limit = new.limit;
-+ q->depth = new.depth;
-+ q->hash_divisor = new.hash_divisor;
-+ q->hash_kind = new.hash_kind;
-+ q->tail = new.tail;
-+ q->max_depth = new.max_depth;
-+ q->ht = new.ht;
-+ q->dep = new.dep;
-+ q->next = new.next;
-+ q->allot = new.allot;
-+ q->hash = new.hash;
-+ q->qs = new.qs;
-+
-+ /* finish up */
-+ if (q->perturb_period) {
-+ q->perturb_timer.expires = jiffies + q->perturb_period;
-+ add_timer(&q->perturb_timer);
-+ } else {
-+ q->perturbation = 0;
-+ }
-+ sch_tree_unlock(sch);
-+ return 0;
-+}
-+
-+static int esfq_dump(struct Qdisc *sch, struct sk_buff *skb)
-+{
-+ struct esfq_sched_data *q = qdisc_priv(sch);
-+ unsigned char *b = skb->tail;
-+ struct tc_esfq_qopt opt;
-+
-+ opt.quantum = q->quantum;
-+ opt.perturb_period = q->perturb_period/HZ;
-+
-+ opt.limit = q->limit;
-+ opt.divisor = q->hash_divisor;
-+ opt.flows = q->depth;
-+ opt.hash_kind = q->hash_kind;
-+
-+ RTA_PUT(skb, TCA_OPTIONS, sizeof(opt), &opt);
-+
-+ return skb->len;
-+
-+rtattr_failure:
-+ skb_trim(skb, b - skb->data);
-+ return -1;
-+}
-+
-+static struct Qdisc_ops esfq_qdisc_ops =
-+{
-+ .next = NULL,
-+ .cl_ops = NULL,
-+ .id = "esfq",
-+ .priv_size = sizeof(struct esfq_sched_data),
-+ .enqueue = esfq_enqueue,
-+ .dequeue = esfq_dequeue,
-+ .requeue = esfq_requeue,
-+ .drop = esfq_drop,
-+ .init = esfq_init,
-+ .reset = esfq_reset,
-+ .destroy = esfq_destroy,
-+ .change = esfq_change,
-+ .dump = esfq_dump,
-+ .owner = THIS_MODULE,
-+};
-+
-+static int __init esfq_module_init(void)
-+{
-+ return register_qdisc(&esfq_qdisc_ops);
-+}
-+static void __exit esfq_module_exit(void)
-+{
-+ unregister_qdisc(&esfq_qdisc_ops);
-+}
-+module_init(esfq_module_init)
-+module_exit(esfq_module_exit)
-+MODULE_LICENSE("GPL");
+++ /dev/null
---- a/include/linux/rtnetlink.h
-+++ b/include/linux/rtnetlink.h
-@@ -293,6 +293,8 @@
- #define RTNH_F_DEAD 1 /* Nexthop is dead (used by multipath) */
- #define RTNH_F_PERVASIVE 2 /* Do recursive gateway lookup */
- #define RTNH_F_ONLINK 4 /* Gateway is forced on link */
-+#define RTNH_F_SUSPECT 8 /* We don't know the real state */
-+#define RTNH_F_BADSTATE (RTNH_F_DEAD | RTNH_F_SUSPECT)
-
- /* Macros to handle hexthops */
-
---- a/include/net/flow.h
-+++ b/include/net/flow.h
-@@ -19,6 +19,8 @@
- struct {
- __be32 daddr;
- __be32 saddr;
-+ __u32 lsrc;
-+ __u32 gw;
- __u8 tos;
- __u8 scope;
- } ip4_u;
-@@ -43,6 +45,8 @@
- #define fl6_flowlabel nl_u.ip6_u.flowlabel
- #define fl4_dst nl_u.ip4_u.daddr
- #define fl4_src nl_u.ip4_u.saddr
-+#define fl4_lsrc nl_u.ip4_u.lsrc
-+#define fl4_gw nl_u.ip4_u.gw
- #define fl4_tos nl_u.ip4_u.tos
- #define fl4_scope nl_u.ip4_u.scope
-
---- a/net/ipv4/route.c
-+++ b/net/ipv4/route.c
-@@ -1116,6 +1116,7 @@
-
- /* Gateway is different ... */
- rt->rt_gateway = new_gw;
-+ if (rt->fl.fl4_gw) rt->fl.fl4_gw = new_gw;
-
- /* Redirect received -> path was valid */
- dst_confirm(&rth->u.dst);
-@@ -1551,6 +1552,7 @@
- rth->fl.fl4_tos = tos;
- rth->fl.mark = skb->mark;
- rth->fl.fl4_src = saddr;
-+ rth->fl.fl4_lsrc = 0;
- rth->rt_src = saddr;
- #ifdef CONFIG_NET_CLS_ROUTE
- rth->u.dst.tclassid = itag;
-@@ -1561,6 +1563,7 @@
- dev_hold(rth->u.dst.dev);
- rth->idev = in_dev_get(rth->u.dst.dev);
- rth->fl.oif = 0;
-+ rth->fl.fl4_gw = 0;
- rth->rt_gateway = daddr;
- rth->rt_spec_dst= spec_dst;
- rth->rt_type = RTN_MULTICAST;
-@@ -1624,7 +1627,7 @@
- static inline int __mkroute_input(struct sk_buff *skb,
- struct fib_result* res,
- struct in_device *in_dev,
-- __be32 daddr, __be32 saddr, u32 tos,
-+ __be32 daddr, __be32 saddr, u32 tos, u32 lsrc,
- struct rtable **result)
- {
-
-@@ -1659,6 +1662,7 @@
- flags |= RTCF_DIRECTSRC;
-
- if (out_dev == in_dev && err && !(flags & (RTCF_NAT | RTCF_MASQ)) &&
-+ !lsrc &&
- (IN_DEV_SHARED_MEDIA(out_dev) ||
- inet_addr_onlink(out_dev, saddr, FIB_RES_GW(*res))))
- flags |= RTCF_DOREDIRECT;
-@@ -1692,6 +1696,7 @@
- rth->fl.mark = skb->mark;
- rth->fl.fl4_src = saddr;
- rth->rt_src = saddr;
-+ rth->fl.fl4_lsrc = lsrc;
- rth->rt_gateway = daddr;
- rth->rt_iif =
- rth->fl.iif = in_dev->dev->ifindex;
-@@ -1699,6 +1704,7 @@
- dev_hold(rth->u.dst.dev);
- rth->idev = in_dev_get(rth->u.dst.dev);
- rth->fl.oif = 0;
-+ rth->fl.fl4_gw = 0;
- rth->rt_spec_dst= spec_dst;
-
- rth->u.dst.input = ip_forward;
-@@ -1720,19 +1726,21 @@
- struct fib_result* res,
- const struct flowi *fl,
- struct in_device *in_dev,
-- __be32 daddr, __be32 saddr, u32 tos)
-+ __be32 daddr, __be32 saddr, u32 tos,
-+ u32 lsrc)
- {
- struct rtable* rth = NULL;
- int err;
- unsigned hash;
-
-+ fib_select_default(fl, res);
- #ifdef CONFIG_IP_ROUTE_MULTIPATH
-- if (res->fi && res->fi->fib_nhs > 1 && fl->oif == 0)
-+ if (res->fi && res->fi->fib_nhs > 1)
- fib_select_multipath(fl, res);
- #endif
-
- /* create a routing cache entry */
-- err = __mkroute_input(skb, res, in_dev, daddr, saddr, tos, &rth);
-+ err = __mkroute_input(skb, res, in_dev, daddr, saddr, tos, lsrc, &rth);
- if (err)
- return err;
-
-@@ -1752,18 +1760,18 @@
- */
-
- static int ip_route_input_slow(struct sk_buff *skb, __be32 daddr, __be32 saddr,
-- u8 tos, struct net_device *dev)
-+ u8 tos, struct net_device *dev, u32 lsrc)
- {
- struct fib_result res;
- struct in_device *in_dev = in_dev_get(dev);
- struct flowi fl = { .nl_u = { .ip4_u =
- { .daddr = daddr,
-- .saddr = saddr,
-+ .saddr = lsrc ? : saddr,
- .tos = tos,
- .scope = RT_SCOPE_UNIVERSE,
- } },
- .mark = skb->mark,
-- .iif = dev->ifindex };
-+ .iif = lsrc? loopback_dev.ifindex : dev->ifindex };
- unsigned flags = 0;
- u32 itag = 0;
- struct rtable * rth;
-@@ -1796,6 +1804,12 @@
- if (BADCLASS(daddr) || ZERONET(daddr) || LOOPBACK(daddr))
- goto martian_destination;
-
-+ if (lsrc) {
-+ if (MULTICAST(lsrc) || BADCLASS(lsrc) ||
-+ ZERONET(lsrc) || LOOPBACK(lsrc))
-+ goto e_inval;
-+ }
-+
- /*
- * Now we are ready to route packet.
- */
-@@ -1805,6 +1819,10 @@
- goto no_route;
- }
- free_res = 1;
-+ if (lsrc && res.type != RTN_UNICAST && res.type != RTN_NAT)
-+ goto e_inval;
-+ fl.iif = dev->ifindex;
-+ fl.fl4_src = saddr;
-
- RT_CACHE_STAT_INC(in_slow_tot);
-
-@@ -1829,7 +1847,7 @@
- if (res.type != RTN_UNICAST)
- goto martian_destination;
-
-- err = ip_mkroute_input(skb, &res, &fl, in_dev, daddr, saddr, tos);
-+ err = ip_mkroute_input(skb, &res, &fl, in_dev, daddr, saddr, tos, lsrc);
- if (err == -ENOBUFS)
- goto e_nobufs;
- if (err == -EINVAL)
-@@ -1844,6 +1862,8 @@
- brd_input:
- if (skb->protocol != htons(ETH_P_IP))
- goto e_inval;
-+ if (lsrc)
-+ goto e_inval;
-
- if (ZERONET(saddr))
- spec_dst = inet_select_addr(dev, 0, RT_SCOPE_LINK);
-@@ -1884,6 +1904,7 @@
- rth->u.dst.dev = &loopback_dev;
- dev_hold(rth->u.dst.dev);
- rth->idev = in_dev_get(rth->u.dst.dev);
-+ rth->fl.fl4_gw = 0;
- rth->rt_gateway = daddr;
- rth->rt_spec_dst= spec_dst;
- rth->u.dst.input= ip_local_deliver;
-@@ -1933,8 +1954,9 @@
- goto e_inval;
- }
-
--int ip_route_input(struct sk_buff *skb, __be32 daddr, __be32 saddr,
-- u8 tos, struct net_device *dev)
-+static inline int
-+ip_route_input_cached(struct sk_buff *skb, __be32 daddr, __be32 saddr,
-+ u8 tos, struct net_device *dev, u32 lsrc)
- {
- struct rtable * rth;
- unsigned hash;
-@@ -1949,6 +1971,7 @@
- if (rth->fl.fl4_dst == daddr &&
- rth->fl.fl4_src == saddr &&
- rth->fl.iif == iif &&
-+ rth->fl.fl4_lsrc == lsrc &&
- rth->fl.oif == 0 &&
- rth->fl.mark == skb->mark &&
- rth->fl.fl4_tos == tos) {
-@@ -1995,7 +2018,19 @@
- rcu_read_unlock();
- return -EINVAL;
- }
-- return ip_route_input_slow(skb, daddr, saddr, tos, dev);
-+ return ip_route_input_slow(skb, daddr, saddr, tos, dev, lsrc);
-+}
-+
-+int ip_route_input(struct sk_buff *skb, u32 daddr, u32 saddr,
-+ u8 tos, struct net_device *dev)
-+{
-+ return ip_route_input_cached(skb, daddr, saddr, tos, dev, 0);
-+}
-+
-+int ip_route_input_lookup(struct sk_buff *skb, u32 daddr, u32 saddr,
-+ u8 tos, struct net_device *dev, u32 lsrc)
-+{
-+ return ip_route_input_cached(skb, daddr, saddr, tos, dev, lsrc);
- }
-
- static inline int __mkroute_output(struct rtable **result,
-@@ -2067,6 +2102,7 @@
- rth->fl.fl4_tos = tos;
- rth->fl.fl4_src = oldflp->fl4_src;
- rth->fl.oif = oldflp->oif;
-+ rth->fl.fl4_gw = oldflp->fl4_gw;
- rth->fl.mark = oldflp->mark;
- rth->rt_dst = fl->fl4_dst;
- rth->rt_src = fl->fl4_src;
-@@ -2145,6 +2181,7 @@
- struct flowi fl = { .nl_u = { .ip4_u =
- { .daddr = oldflp->fl4_dst,
- .saddr = oldflp->fl4_src,
-+ .gw = oldflp->fl4_gw,
- .tos = tos & IPTOS_RT_MASK,
- .scope = ((tos & RTO_ONLINK) ?
- RT_SCOPE_LINK :
-@@ -2248,6 +2285,7 @@
- dev_out = &loopback_dev;
- dev_hold(dev_out);
- fl.oif = loopback_dev.ifindex;
-+ fl.fl4_gw = 0;
- res.type = RTN_LOCAL;
- flags |= RTCF_LOCAL;
- goto make_route;
-@@ -2255,7 +2293,7 @@
-
- if (fib_lookup(&fl, &res)) {
- res.fi = NULL;
-- if (oldflp->oif) {
-+ if (oldflp->oif && dev_out->flags & IFF_UP) {
- /* Apparently, routing tables are wrong. Assume,
- that the destination is on link.
-
-@@ -2295,6 +2333,7 @@
- dev_out = &loopback_dev;
- dev_hold(dev_out);
- fl.oif = dev_out->ifindex;
-+ fl.fl4_gw = 0;
- if (res.fi)
- fib_info_put(res.fi);
- res.fi = NULL;
-@@ -2302,13 +2341,12 @@
- goto make_route;
- }
-
-+ if (res.type == RTN_UNICAST)
-+ fib_select_default(&fl, &res);
- #ifdef CONFIG_IP_ROUTE_MULTIPATH
-- if (res.fi->fib_nhs > 1 && fl.oif == 0)
-+ if (res.fi->fib_nhs > 1)
- fib_select_multipath(&fl, &res);
-- else
- #endif
-- if (!res.prefixlen && res.type == RTN_UNICAST && !fl.oif)
-- fib_select_default(&fl, &res);
-
- if (!fl.fl4_src)
- fl.fl4_src = FIB_RES_PREFSRC(res);
-@@ -2345,6 +2383,7 @@
- rth->fl.fl4_src == flp->fl4_src &&
- rth->fl.iif == 0 &&
- rth->fl.oif == flp->oif &&
-+ rth->fl.fl4_gw == flp->fl4_gw &&
- rth->fl.mark == flp->mark &&
- !((rth->fl.fl4_tos ^ flp->fl4_tos) &
- (IPTOS_RT_MASK | RTO_ONLINK))) {
-@@ -3030,3 +3069,4 @@
- EXPORT_SYMBOL(__ip_select_ident);
- EXPORT_SYMBOL(ip_route_input);
- EXPORT_SYMBOL(ip_route_output_key);
-+EXPORT_SYMBOL(ip_route_input_lookup);
+++ /dev/null
---- a/arch/mips/Makefile
-+++ b/arch/mips/Makefile
-@@ -565,6 +565,9 @@
- cflags-$(CONFIG_TOSHIBA_RBTX4938) += -Iinclude/asm-mips/mach-tx49xx
- load-$(CONFIG_TOSHIBA_RBTX4938) += 0xffffffff80100000
-
-+# temporary until string.h is fixed
-+cflags-y += -ffreestanding
-+
- cflags-y += -Iinclude/asm-mips/mach-generic
- drivers-$(CONFIG_PCI) += arch/mips/pci/
-
+++ /dev/null
---- a/fs/jffs2/build.c
-+++ b/fs/jffs2/build.c
-@@ -105,6 +105,17 @@
- dbg_fsbuild("scanned flash completely\n");
- jffs2_dbg_dump_block_lists_nolock(c);
-
-+ if (c->flags & (1 << 7)) {
-+ printk("%s(): unlocking the mtd device... ", __func__);
-+ if (c->mtd->unlock)
-+ c->mtd->unlock(c->mtd, 0, c->mtd->size);
-+ printk("done.\n");
-+
-+ printk("%s(): erasing all blocks after the end marker... ", __func__);
-+ jffs2_erase_pending_blocks(c, -1);
-+ printk("done.\n");
-+ }
-+
- dbg_fsbuild("pass 1 starting\n");
- c->flags |= JFFS2_SB_FLAG_BUILDING;
- /* Now scan the directory tree, increasing nlink according to every dirent found. */
---- a/fs/jffs2/scan.c
-+++ b/fs/jffs2/scan.c
-@@ -142,9 +142,12 @@
-
- /* reset summary info for next eraseblock scan */
- jffs2_sum_reset_collected(s);
--
-- ret = jffs2_scan_eraseblock(c, jeb, buf_size?flashbuf:(flashbuf+jeb->offset),
-- buf_size, s);
-+
-+ if (c->flags & (1 << 7))
-+ ret = BLK_STATE_ALLFF;
-+ else
-+ ret = jffs2_scan_eraseblock(c, jeb, buf_size?flashbuf:(flashbuf+jeb->offset),
-+ buf_size, s);
-
- if (ret < 0)
- goto out;
-@@ -545,6 +548,17 @@
- return err;
- }
-
-+ if ((buf[0] == 0xde) &&
-+ (buf[1] == 0xad) &&
-+ (buf[2] == 0xc0) &&
-+ (buf[3] == 0xde)) {
-+ /* end of filesystem. erase everything after this point */
-+ printk("%s(): End of filesystem marker found at 0x%x\n", __func__, jeb->offset);
-+ c->flags |= (1 << 7);
-+
-+ return BLK_STATE_ALLFF;
-+ }
-+
- /* We temporarily use 'ofs' as a pointer into the buffer/jeb */
- ofs = 0;
-
+++ /dev/null
---- /dev/null
-+++ b/include/asm-powerpc/segment.h
-@@ -0,0 +1,6 @@
-+#ifndef _ASM_SEGMENT_H
-+#define _ASM_SEGMENT_H
-+
-+/* Only here because we have some old header files that expect it.. */
-+
-+#endif /* _ASM_SEGMENT_H */
+++ /dev/null
---- a/drivers/net/r8169.c
-+++ b/drivers/net/r8169.c
-@@ -1459,7 +1459,7 @@
- .hw_start = rtl_hw_start_8169,
- .region = 1,
- .align = 0,
-- .intr_event = SYSErr | LinkChg | RxOverflow |
-+ .intr_event = LinkChg | RxOverflow |
- RxFIFOOver | TxErr | TxOK | RxOK | RxErr,
- .napi_event = RxFIFOOver | TxErr | TxOK | RxOK | RxOverflow
- },
-@@ -1467,7 +1467,7 @@
- .hw_start = rtl_hw_start_8168,
- .region = 2,
- .align = 8,
-- .intr_event = SYSErr | LinkChg | RxOverflow |
-+ .intr_event = LinkChg | RxOverflow |
- TxErr | TxOK | RxOK | RxErr,
- .napi_event = TxErr | TxOK | RxOK | RxOverflow
- },
-@@ -1475,7 +1475,7 @@
- .hw_start = rtl_hw_start_8101,
- .region = 2,
- .align = 8,
-- .intr_event = SYSErr | LinkChg | RxOverflow | PCSTimeout |
-+ .intr_event = LinkChg | RxOverflow | PCSTimeout |
- RxFIFOOver | TxErr | TxOK | RxOK | RxErr,
- .napi_event = RxFIFOOver | TxErr | TxOK | RxOK | RxOverflow
- }
-@@ -2779,10 +2779,12 @@
- break;
- }
-
-+#if 0
- if (unlikely(status & SYSErr)) {
- rtl8169_pcierr_interrupt(dev);
- break;
- }
-+#endif
-
- if (status & LinkChg)
- rtl8169_check_link_status(dev, tp, ioaddr);
+++ /dev/null
---- a/fs/Kconfig
-+++ b/fs/Kconfig
-@@ -458,6 +458,9 @@
- This option will enlarge your kernel, but it allows debugging of
- ocfs2 filesystem issues.
-
-+config MINI_FO
-+ tristate "Mini fanout overlay filesystem"
-+
- config MINIX_FS
- tristate "Minix fs support"
- help
---- a/fs/Makefile
-+++ b/fs/Makefile
-@@ -76,6 +76,7 @@
- obj-$(CONFIG_RAMFS) += ramfs/
- obj-$(CONFIG_HUGETLBFS) += hugetlbfs/
- obj-$(CONFIG_CODA_FS) += coda/
-+obj-$(CONFIG_MINI_FO) += mini_fo/
- obj-$(CONFIG_MINIX_FS) += minix/
- obj-$(CONFIG_FAT_FS) += fat/
- obj-$(CONFIG_MSDOS_FS) += msdos/
---- /dev/null
-+++ b/fs/mini_fo/aux.c
-@@ -0,0 +1,577 @@
-+/*
-+ * Copyright (c) 1997-2003 Erez Zadok
-+ * Copyright (c) 2001-2003 Stony Brook University
-+ *
-+ * For specific licensing information, see the COPYING file distributed with
-+ * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
-+ *
-+ * This Copyright notice must be kept intact and distributed with all
-+ * fistgen sources INCLUDING sources generated by fistgen.
-+ */
-+/*
-+ * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
-+ *
-+ * 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.
-+ */
-+/*
-+ * $Id$
-+ */
-+
-+#ifdef HAVE_CONFIG_H
-+# include <config.h>
-+#endif
-+
-+#include "fist.h"
-+#include "mini_fo.h"
-+
-+/* check if file exists in storage */
-+int exists_in_storage(dentry_t *dentry)
-+{
-+ check_mini_fo_dentry(dentry);
-+ if(dtost(dentry) == MODIFIED || dtost(dentry) == CREATED || dtost(dentry) == DEL_REWRITTEN)
-+ return 1;
-+ return 0;
-+}
-+
-+/* check if dentry is in an existing state */
-+int is_mini_fo_existant(dentry_t *dentry)
-+{
-+ check_mini_fo_dentry(dentry);
-+
-+ if(dtost(dentry) == DELETED || dtost(dentry) == NON_EXISTANT)
-+ return 0;
-+ else
-+ return 1;
-+}
-+
-+/*
-+ * This function will create a negative storage dentry for
-+ * dentry, what is required for many create like options.
-+ * It will create the storage structure if necessary.
-+ */
-+int get_neg_sto_dentry(dentry_t *dentry)
-+{
-+ int err = 0;
-+ unsigned int len;
-+ const unsigned char *name;
-+
-+ if(!dentry ||
-+ !dtopd(dentry) ||
-+ !(dtost(dentry) == UNMODIFIED ||
-+ dtost(dentry) == NON_EXISTANT ||
-+ dtost(dentry) == DELETED)) {
-+ printk(KERN_CRIT "mini_fo: get_neg_sto_dentry: invalid dentry passed.\n");
-+ err = -1;
-+ goto out;
-+ }
-+ /* Have we got a neg. dentry already? */
-+ if(dtohd2(dentry)) {
-+ err = 0;
-+ goto out;
-+ }
-+ if(dtost(dentry->d_parent) == UNMODIFIED) {
-+ /* build sto struct */
-+ err = build_sto_structure(dentry->d_parent->d_parent, dentry->d_parent);
-+ if(err ||
-+ dtost(dentry->d_parent) != MODIFIED) {
-+ printk(KERN_CRIT "mini_fo: get_neg_sto_dentry: ERROR building sto structure.\n");
-+ err = -1;
-+ goto out;
-+ }
-+ }
-+
-+ len = dentry->d_name.len;
-+ name = dentry->d_name.name;
-+
-+ dtohd2(dentry) =
-+ lookup_one_len(name, dtohd2(dentry->d_parent), len);
-+
-+ out:
-+ return err;
-+}
-+
-+int check_mini_fo_dentry(dentry_t *dentry)
-+{
-+ ASSERT(dentry != NULL);
-+ ASSERT(dtopd(dentry) != NULL);
-+ ASSERT((dtohd(dentry) != NULL) || (dtohd2(dentry) != NULL));
-+
-+/* if(dtost(dentry) == MODIFIED) { */
-+/* ASSERT(dentry->d_inode != NULL); */
-+/* ASSERT(dtohd(dentry) != NULL); */
-+/* ASSERT(dtohd(dentry)->d_inode != NULL); */
-+/* ASSERT(dtohd2(dentry) != NULL); */
-+/* ASSERT(dtohd2(dentry)->d_inode != NULL); */
-+/* } */
-+/* else if(dtost(dentry) == UNMODIFIED) { */
-+/* ASSERT(dentry->d_inode != NULL); */
-+/* ASSERT( */
-+/* } */
-+ return 0;
-+}
-+
-+int check_mini_fo_file(file_t *file)
-+{
-+ ASSERT(file != NULL);
-+ ASSERT(ftopd(file) != NULL);
-+ ASSERT(file->f_dentry != NULL);
-+
-+ /* violent checking, check depending of state and type
-+ * if(S_ISDIR(file->f_dentry->d_inode->i_mode)) {}
-+ */
-+ ASSERT((ftohf(file) != NULL) || (ftohf2(file) != NULL));
-+ return 0;
-+}
-+
-+int check_mini_fo_inode(inode_t *inode)
-+{
-+ ASSERT(inode != NULL);
-+ ASSERT(itopd(inode) != NULL);
-+ ASSERT((itohi(inode) != NULL) || (itohi2(inode) != NULL));
-+ return 0;
-+}
-+
-+/*
-+ * will walk a base path as provided by get_mini_fo_bpath and return
-+ * the (hopefully ;-) ) positive dentry of the renamed base dir.
-+ *
-+ * This does some work of path_init.
-+ */
-+dentry_t *bpath_walk(super_block_t *sb, char *bpath)
-+{
-+ int err;
-+ struct vfsmount *mnt;
-+ struct nameidata nd;
-+
-+ /* be paranoid */
-+ if(!bpath || bpath[0] != '/') {
-+ printk(KERN_CRIT "mini_fo: bpath_walk: Invalid string.\n");
-+ return NULL;
-+ }
-+ if(!sb || !stopd(sb)) {
-+ printk(KERN_CRIT "mini_fo: bpath_walk: Invalid sb.\n");
-+ return NULL;
-+ }
-+
-+ /* fix this: how do I reach this lock?
-+ * read_lock(¤t->fs->lock); */
-+ mnt = mntget(stopd(sb)->hidden_mnt);
-+ /* read_unlock(¤t->fs->lock); */
-+
-+ err = vfs_path_lookup(mnt->mnt_root, mnt, bpath+1, 0, &nd);
-+
-+ /* validate */
-+ if (err || !nd.dentry || !nd.dentry->d_inode) {
-+ printk(KERN_CRIT "mini_fo: bpath_walk: path_walk failed.\n");
-+ return NULL;
-+ }
-+ return nd.dentry;
-+}
-+
-+
-+/* returns the full path of the basefile incl. its name */
-+int get_mini_fo_bpath(dentry_t *dentry, char **bpath, int *bpath_len)
-+{
-+ char *buf_walker;
-+ int len = 0;
-+ dentry_t *sky_walker;
-+
-+ if(!dentry || !dtohd(dentry)) {
-+ printk(KERN_CRIT "mini_fo: get_mini_fo_bpath: invalid dentry passed.\n");
-+ return -1;
-+ }
-+ sky_walker = dtohd(dentry);
-+
-+ do {
-+ len += sky_walker->d_name.len + 1 ; /* 1 for '/' */
-+ sky_walker = sky_walker->d_parent;
-+ } while(sky_walker != stopd(dentry->d_inode->i_sb)->base_dir_dentry);
-+
-+ /* 1 to oil the loop */
-+ *bpath = (char*) kmalloc(len + 1, GFP_KERNEL);
-+ if(!*bpath) {
-+ printk(KERN_CRIT "mini_fo: get_mini_fo_bpath: out of mem.\n");
-+ return -1;
-+ }
-+ buf_walker = *bpath+len; /* put it on last char */
-+ *buf_walker = '\n';
-+ sky_walker = dtohd(dentry);
-+
-+ do {
-+ buf_walker -= sky_walker->d_name.len;
-+ strncpy(buf_walker,
-+ sky_walker->d_name.name,
-+ sky_walker->d_name.len);
-+ *(--buf_walker) = '/';
-+ sky_walker = sky_walker->d_parent;
-+ } while(sky_walker != stopd(dentry->d_inode->i_sb)->base_dir_dentry);
-+
-+ /* bpath_len doesn't count newline! */
-+ *bpath_len = len;
-+ return 0;
-+}
-+
-+int mini_fo_cp_cont(dentry_t *tgt_dentry, struct vfsmount *tgt_mnt,
-+ dentry_t *src_dentry, struct vfsmount *src_mnt)
-+{
-+ void *buf;
-+ mm_segment_t old_fs;
-+ file_t *tgt_file;
-+ file_t *src_file;
-+ int bytes, len, tmp, err;
-+ err = 0;
-+
-+ if(!(tgt_dentry->d_inode && src_dentry->d_inode)) {
-+ printk(KERN_CRIT "mini_fo_cp_cont: ERROR, neg. dentry passed.\n");
-+ err = -EINVAL;
-+ goto out;
-+ }
-+
-+ dget(tgt_dentry);
-+ dget(src_dentry);
-+ mntget(tgt_mnt);
-+ mntget(src_mnt);
-+
-+ /* open file write only */
-+ tgt_file = dentry_open(tgt_dentry, tgt_mnt, 0x1);
-+ if(!tgt_file || IS_ERR(tgt_file)) {
-+ printk(KERN_CRIT "mini_fo_cp_cont: ERROR opening target file.\n");
-+ err = PTR_ERR(tgt_file);
-+ goto out_err;
-+ }
-+
-+ /* open file read only */
-+ src_file = dentry_open(src_dentry, src_mnt, 0x0);
-+ if(!src_file || IS_ERR(src_file)) {
-+ printk(KERN_CRIT "mini_fo_cp_cont: ERROR opening source file.\n");
-+ err = PTR_ERR(src_file);
-+
-+ /* close target file */
-+ fput(tgt_file);
-+ goto out_err;
-+ }
-+
-+ /* check if the filesystem(s) support read respective write */
-+ if(!src_file->f_op->read || !tgt_file->f_op->write) {
-+ printk(KERN_CRIT "mini_fo_cp_cont: ERROR, no fs read or write support.\n");
-+ err = -EPERM;
-+ goto out_close;
-+ }
-+
-+ /* allocate a page for transfering the data */
-+ buf = (void *) __get_free_page(GFP_KERNEL);
-+ if(!buf) {
-+ printk(KERN_CRIT "mini_fo_cp_cont: ERROR, out of kernel mem.\n");
-+ goto out_err;
-+ }
-+
-+ tgt_file->f_pos = 0;
-+ src_file->f_pos = 0;
-+
-+ old_fs = get_fs();
-+ set_fs(KERNEL_DS);
-+
-+ /* Doing this I assume that a read operation will return a full
-+ * buffer while there is still data to read, and a less than
-+ * full buffer when all data has been read.
-+ */
-+ bytes = len = PAGE_SIZE;
-+ while(bytes == len) {
-+ bytes = src_file->f_op->read(src_file, buf, len,
-+ &src_file->f_pos);
-+ tmp = tgt_file->f_op->write(tgt_file, buf, bytes,
-+ &tgt_file->f_pos);
-+ if(tmp != bytes) {
-+ printk(KERN_CRIT "mini_fo_cp_cont: ERROR writing.\n");
-+ goto out_close_unset;
-+ }
-+ }
-+
-+ free_page((unsigned long) buf);
-+ set_fs(old_fs);
-+ fput(tgt_file);
-+ fput(src_file);
-+ goto out;
-+
-+ out_close_unset:
-+ free_page((unsigned long) buf);
-+ set_fs(old_fs);
-+
-+ out_close:
-+ fput(tgt_file);
-+ fput(src_file);
-+
-+ out_err:
-+ dput(tgt_dentry);
-+ dput(src_dentry);
-+
-+ /* mk: not sure if this need to be done */
-+ mntput(tgt_mnt);
-+ mntput(src_mnt);
-+
-+ out:
-+ return err;
-+}
-+
-+/* mk:
-+ * ndl (no-duplicate list) stuff
-+ * This is used in mini_fo_readdir, to save the storage directory contents
-+ * and later when reading base, match them against the list in order
-+ * to avoid duplicates.
-+ */
-+
-+/* add a file specified by name and len to the ndl
-+ * Return values: 0 on success, <0 on failure.
-+ */
-+int ndl_add_entry(struct readdir_data *rd, const char *name, int len)
-+{
-+ struct ndl_entry *tmp_entry;
-+
-+ tmp_entry = (struct ndl_entry *)
-+ kmalloc(sizeof(struct ndl_entry), GFP_KERNEL);
-+ if(!tmp_entry) {
-+ printk(KERN_CRIT "mini_fo: ndl_add_entry: out of mem.\n");
-+ return -ENOMEM;
-+ }
-+ tmp_entry->name = (char*) kmalloc(len, GFP_KERNEL);
-+ if(!tmp_entry->name) {
-+ printk(KERN_CRIT "mini_fo: ndl_add_entry: out of mem.\n");
-+ return -ENOMEM;
-+ }
-+ strncpy(tmp_entry->name, name, len);
-+ tmp_entry->len = len;
-+
-+ list_add(&tmp_entry->list, &rd->ndl_list);
-+ rd->ndl_size++;
-+ return 0;
-+}
-+
-+/* delete all list entries and free memory */
-+void ndl_put_list(struct readdir_data *rd)
-+{
-+ struct list_head *tmp;
-+ struct ndl_entry *tmp_entry;
-+
-+ if(rd->ndl_size <= 0)
-+ return;
-+ while(!list_empty(&rd->ndl_list)) {
-+ tmp = rd->ndl_list.next;
-+ list_del(tmp);
-+ tmp_entry = list_entry(tmp, struct ndl_entry, list);
-+ kfree(tmp_entry->name);
-+ kfree(tmp_entry);
-+ }
-+ rd->ndl_size = 0;
-+}
-+
-+/* Check if a file specified by name and len is in the ndl
-+ * Return value: 0 if not in list, 1 if file is found in ndl.
-+ */
-+int ndl_check_entry(struct readdir_data *rd, const char *name, int len)
-+{
-+ struct list_head *tmp;
-+ struct ndl_entry *tmp_entry;
-+
-+ if(rd->ndl_size <= 0)
-+ return 0;
-+
-+ list_for_each(tmp, &rd->ndl_list) {
-+ tmp_entry = list_entry(tmp, struct ndl_entry, list);
-+ if(tmp_entry->len != len)
-+ continue;
-+ if(!strncmp(tmp_entry->name, name, len))
-+ return 1;
-+ }
-+ return 0;
-+}
-+
-+/* mk:
-+ * Recursive function to create corresponding directorys in the storage fs.
-+ * The function will build the storage directorys up to dentry.
-+ */
-+int build_sto_structure(dentry_t *dir, dentry_t *dentry)
-+{
-+ int err;
-+ dentry_t *hidden_sto_dentry;
-+ dentry_t *hidden_sto_dir_dentry;
-+
-+ if(dentry->d_parent != dir) {
-+ printk(KERN_CRIT "mini_fo: build_sto_structure: invalid parameter or meta data corruption [1].\n");
-+ return 1;
-+ }
-+
-+ if(dtost(dir) != MODIFIED) {
-+ err = build_sto_structure(dir->d_parent, dentry->d_parent);
-+ if(err)
-+ return err;
-+ }
-+
-+ /* ok, coming back again. */
-+ check_mini_fo_dentry(dentry);
-+ hidden_sto_dentry = dtohd2(dentry);
-+
-+ if(!hidden_sto_dentry) {
-+ /*
-+ * This is the case after creating the first
-+ * hidden_sto_dentry.
-+ * After one negative storage_dentry, all pointers to
-+ * hidden_storage dentries are set to NULL. We need to
-+ * create the negative dentry before we create the storage
-+ * file.
-+ */
-+ unsigned int len;
-+ const unsigned char *name;
-+ len = dtohd(dentry)->d_name.len;
-+ name = dtohd(dentry)->d_name.name;
-+ hidden_sto_dentry = lookup_one_len(name, dtohd2(dir), len);
-+ dtohd2(dentry) = hidden_sto_dentry;
-+ }
-+
-+ /* was: hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry); */
-+ hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
-+#else
-+ down(&hidden_sto_dir_dentry->d_inode->i_sem);
-+#endif
-+ /* lets be safe */
-+ if(dtohd2(dir) != hidden_sto_dir_dentry) {
-+ printk(KERN_CRIT "mini_fo: build_sto_structure: invalid parameter or meta data corruption [2].\n");
-+ return 1;
-+ }
-+
-+ /* check for errors in lock_parent */
-+ err = PTR_ERR(hidden_sto_dir_dentry);
-+ if(IS_ERR(hidden_sto_dir_dentry)) {
-+ printk(KERN_CRIT "mini_fo: build_sto_structure: lock_parent failed.\n");
-+ return err;
-+ }
-+
-+ err = vfs_mkdir(hidden_sto_dir_dentry->d_inode,
-+ hidden_sto_dentry,
-+ dir->d_inode->i_mode);
-+
-+ if(err) {
-+ printk(KERN_CRIT "mini_fo: build_sto_structure: failed to create storage dir [1].\n");
-+ /* was: unlock_dir(dir); */
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_unlock(&dir->d_inode->i_mutex);
-+#else
-+ up(&dir->d_inode->i_sem);
-+#endif
-+ dput(dir);
-+ return err;
-+ }
-+
-+ /* everything ok! */
-+ if(!dtohd2(dentry)->d_inode) {
-+ printk(KERN_CRIT "mini_fo: build_sto_structure: failed to create storage dir [2].\n");
-+ /* was: unlock_dir(dir); */
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_unlock(&dir->d_inode->i_mutex);
-+#else
-+ up(&dir->d_inode->i_sem);
-+#endif
-+ dput(dir);
-+ return 1;
-+ }
-+
-+ /* interpose the new inode and set new state */
-+ itohi2(dentry->d_inode) = igrab(dtohd2(dentry)->d_inode);
-+ dtopd(dentry)->state = MODIFIED;
-+
-+ /* initalize the wol list */
-+ itopd(dentry->d_inode)->deleted_list_size = -1;
-+ itopd(dentry->d_inode)->renamed_list_size = -1;
-+ meta_build_lists(dentry);
-+
-+ fist_copy_attr_all(dentry->d_inode, itohi2(dentry->d_inode));
-+ fist_copy_attr_timesizes(dir->d_inode,
-+ hidden_sto_dir_dentry->d_inode);
-+ dir->d_inode->i_nlink++;
-+ /* was: unlock_dir(hidden_sto_dir_dentry); */
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
-+#else
-+ up(&hidden_sto_dir_dentry->d_inode->i_sem);
-+#endif
-+ dput(hidden_sto_dir_dentry);
-+ return 0;
-+}
-+
-+
-+#if 0 /* unused */
-+
-+/*
-+ * Read "len" bytes from "filename" into "buf".
-+ * "buf" is in kernel space.
-+ */
-+int
-+mini_fo_read_file(const char *filename, void *buf, int len)
-+{
-+ file_t *filp;
-+ mm_segment_t oldfs;
-+ int bytes;
-+ /* Chroot? Maybe NULL isn't right here */
-+ filp = filp_open(filename, O_RDONLY, 0);
-+ if (!filp || IS_ERR(filp)) {
-+ printk("mini_fo_read_file err %d\n", (int) PTR_ERR(filp));
-+ return -1; /* or do something else */
-+ }
-+
-+ if (!filp->f_op->read)
-+ return -2; /* file(system) doesn't allow reads */
-+
-+ /* now read len bytes from offset 0 */
-+ filp->f_pos = 0; /* start offset */
-+ oldfs = get_fs();
-+ set_fs(KERNEL_DS);
-+ bytes = filp->f_op->read(filp, buf, len, &filp->f_pos);
-+ set_fs(oldfs);
-+
-+ /* close the file */
-+ fput(filp);
-+
-+ return bytes;
-+}
-+
-+
-+
-+/*
-+ * Write "len" bytes from "buf" to "filename"
-+ * "buf" is in kernel space.
-+ */
-+int
-+mini_fo_write_file(const char *filename, void *buf, int len)
-+{
-+ file_t *filp;
-+ mm_segment_t oldfs;
-+ int bytes;
-+ /* Chroot? Maybe NULL isn't right here */
-+ filp = filp_open(filename, O_RDWR|O_CREAT, 0640);
-+ if (!filp || IS_ERR(filp)) {
-+ printk("mini_fo_write_file err %d\n", (int) PTR_ERR(filp));
-+ return -1; /* or do something else */
-+ }
-+
-+ if (!filp->f_op->write)
-+ return -2; /* file(system) doesn't allow writes */
-+
-+ /* now write len bytes from offset 0 */
-+ filp->f_pos = 0; /* start offset */
-+ oldfs = get_fs();
-+ set_fs(KERNEL_DS);
-+ bytes = filp->f_op->write(filp, buf, len, &filp->f_pos);
-+ set_fs(oldfs);
-+
-+ /* close the file */
-+ fput(filp);
-+
-+ return bytes;
-+}
-+
-+#endif /* unused */
-+
---- /dev/null
-+++ b/fs/mini_fo/ChangeLog
-@@ -0,0 +1,281 @@
-+2006-01-24 Markus Klotzbuecher <mk@mary.denx.de>
-+
-+ * Add tons of ugly ifdefs to Ed L. Cashin's mutex patch to
-+ retain backwards compatibility.
-+
-+2006-01-24 Ed L. Cashin <ecashin@coraid.com>
-+
-+ * Support for the new mutex infrastructure
-+ (7892f2f48d165a34b0b8130c8a195dfd807b8cb6)
-+
-+2005-10-15 Markus Klotzbuecher <mk@localhost.localdomain>
-+
-+ * Bugfix for a serious memory leak in mini_fo_follow_link.
-+
-+2005-09-21 Markus Klotzbuecher <mk@mary>
-+
-+ * new release 0.6.1
-+
-+ * fix of a compiler warning due to changes in 2.6.13
-+
-+2005-09-21 Klaus Wenninger <klaus.wenninger@siemens.com>
-+
-+ * file.c: readdir: fix for a bug that caused directory entries
-+ to show up twice when using storage filesystems such as
-+ minixfs or pramfs.
-+
-+2005-06-30 Eric Lammerts <eric@lammerts.org>
-+
-+ * fix for an oops when overwriting a binary thats beeing
-+ executed.
-+
-+2005-06-09 <mk@mary>
-+
-+ * Renamed overlay to mini_fo-overlay.
-+
-+ * Added mini_fo-merge script to allow merging of storage and base
-+ after making modifications.
-+
-+2005-05-22 root <mk@mary>
-+
-+ * Added overlay script that allows to easily mount mini_fo ontop
-+ of a given base directory
-+
-+2005-05-10 <mk@mary>
-+
-+ * inode.c: xattr functions return -EOPNOSUPP instead of
-+ -ENOSUPP, what confuses "ls -l"
-+
-+ * Changed license from LGPL to GPL.
-+
-+2005-05-08 root <mk@mary>
-+
-+ * Makefile: clean it up and added make install and make
-+ uninstall.
-+
-+2005-05-06 <mk@mary>
-+
-+ * merged devel branch back to main. [v0-6-0-pre3]
-+
-+ * removed unused files print.c and fist_ioctl. [devel-0-0-18]
-+
-+ * ioctl: removed fist_ioctl stuff, that is not needed for
-+ now.
-+
-+2005-05-03 <mk@mary>
-+
-+ * file.c: simplified mini_fo_open and mini_fo_setattr using
-+ new state changing functions. [devel-0-0-17]
-+
-+ * inode.c: Fixed getattr state bug (see below) in 2.4 function
-+ mini_fo_inode revalidate.
-+
-+ * inode.c: found an other bug in mini_fo_getattr. States are not
-+ reliable in this function, as a file can be opened, unlinked and
-+ the getattr function called. This results in a deleted dentry
-+ with an inode. Fix is to ignore states and simply use the inode
-+ available.
-+
-+2005-04-29 <mk@mary>
-+
-+ * file.c: Bugfix and cleanup in fasync and fsync. [devel-0-0-16]
-+
-+ * file.c: do not use mini_fo_lock so the generic version is
-+ used (I guess).
-+
-+ * inode.c: getattr, never call getattr on lower files, as this
-+ will cause the inum to change.
-+
-+ * inode.c: rename_reg_file renamed to rename_nondir, as it
-+ doesn't matter as long it't not a dir. Removed all
-+ rename_dev_file etc.
-+
-+ * tagged as devel-0-0-15
-+
-+ * inode.c: added support for chosing support for extended
-+ attrs at compile time by XATTR define in mini_fo.h .
-+
-+ * inode.c: fixed mini_fo_getattr to use mini_fo inode and not
-+ lower again, what avoids inode number changes that confused
-+ rm again. This is the proper solution.
-+
-+2005-04-24 <mk@mary>
-+
-+ * all files: updated Copyright notive to 2005. [devel-0-0-14]
-+
-+ * inode.c: fixed mini_fo_getattr to not change the inode
-+ number, even if lower files change.
-+
-+ * super.c: fixed a bug that caused deleted base file to show
-+ up suddenly after some time, or after creating a special
-+ file. The problem was that after some time or after special
-+ file creating sync_sb_inodes is called by the vfs, that
-+ called our mini_fo_put_inode. There was (wrongly) called
-+ __meta_put_lists, that nuked the lists, although the inode
-+ was going to continue its life. Moving __meta_put_lists to
-+ mini_fo_clear_inode, where an inode is really destroyed,
-+ solved the problem.
-+
-+
-+2005-04-23 <mk@mary>
-+
-+ * state.c, aux.c: more cleaning up and
-+ simplifications. [devel-0-0-13]
-+
-+ * inode.c: implemented mini_fo_getattr, that was required for
-+ 2.6 because inode_revalidate has been remove there, and the
-+ old "du" bug returned.
-+
-+
-+2005-04-20 <mk@mary>
-+
-+ * aux.c: get_neg_sto_dentry(): allow to be called for dentries
-+ in state UNMODIFIED, NON_EXISTANT _and_ DELETED.
-+
-+2005-04-19 <mk@mary>
-+
-+ * Fixed a bug under 2.6 that caused files deleted via mini_fo
-+ not to be deleted properly and therefore the fs filled up
-+ untill no memory was left. [devel-0-0-12]
-+
-+ * Added basic hard link support. This means that creating
-+ hardlinks will work, but existing ones will be treated as
-+ individual files. [devel-0-0-11]
-+
-+2005-04-17 <mk@mary>
-+
-+ * Bugfixes
-+
-+2005-04-13 root <mk@mary>
-+
-+ * Added file state.c for the state transition
-+ functions. Doesn't work very well yet, though...
-+
-+2005-04-12 <mk@mary>
-+
-+ * Porting to 2.6 started, which is easier than expected, also
-+ due to Olivier previous work.
-+
-+2005-04-08 <mk@mary>
-+
-+ * Fixed the bug that caused du to return invalid sizes of
-+ directory trees. The problem was that
-+ mini_fo_inode_revalidate didn't always copy the attributes
-+ from the base inode properly.
-+
-+2005-04-01 Markus Klotzbuecher <mk@chasey>
-+
-+ * Merged devel branch back to main trunk and updated the
-+ RELEASE notes. This will be 0-6-0-pre1.
-+
-+2005-03-31 Markus Klotzbuecher <mk@chasey>
-+
-+ * Fixed some bugs in rename_reg_file, that only showed up in
-+ the kernel compile test. Kernel compiles cleanly ontop of
-+ mini_fo, now also make mrproper etc. work. Seems pretty stable.
-+
-+2005-03-28 Markus Klotzbuecher <mk@chasey>
-+
-+ * Many, many directory renaming bugfixes and a lot of other
-+ cleanup. Dir renaming seems to work relatively stable.
-+
-+2005-03-22 Markus Klotzbuecher <mk@chasey>
-+
-+ * Finished implementing lightweight directory renaming. Some
-+ basic testing indicates it works fine.
-+ Next is to implement testcases for the testsuite and confirm
-+ everything is really working ok.
-+
-+2005-03-18 Markus Klotzbuecher <mk@chasey>
-+
-+ * Finished implementing meta.c stuff required for directory
-+ renaming.
-+
-+2005-03-17 Markus Klotzbuecher <mk@chasey>
-+
-+ * Fixed all compile warnings + an extremly old bug that
-+ somehow crept in while reworking the wol stuff to the META
-+ system. Turning on -Werror again... :-)
-+
-+ * Fixed some bugs in the new rename_reg_file function.
-+
-+ * Rewrote mini_fo rename and split it into several
-+ subfunctions, that handle the different types
-+ seperately. Rewrote the regular file function aswell, as it
-+ was implemented somewhat inefficient.
-+
-+2005-03-16 Markus Klotzbuecher <mk@chasey>
-+
-+ * Implemented new META subsystem, removed old WOL stuff in favor
-+ if it.
-+
-+ * After some basic testing everything seems ok...
-+
-+2005-03-11 Markus Klotzbuecher <mk@chasey>
-+
-+ * Renaming a non regular file caused trouble because I always
-+ tried to copy the contents. Now I only do this for regular
-+ files. mini_fo_rename still isn't implemented properly, renaming
-+ of device files, symlinks etc. results in a empty regular file
-+ instead of the proper type.
-+
-+ * Directory renaming suddenly works! What a surprise! I guess
-+ this is because renaming is implemented as making a copy and
-+ removing the original. Still this might not work
-+ everywhere...
-+
-+2005-03-09 Markus Klotzbuecher <mk@chasey>
-+
-+ * Bugfix, when a mini_fo directory that exists in storage
-+ (state: MODIFIED, CREATED and DEL_REWRITTEN) is deleted, a
-+ possibly existing WOL file contained in it needs to be
-+ deleted too.
-+
-+ * Starting cleanup: defined state names in order to get rid of
-+ the state numbers.
-+
-+2005-03-08 Markus Klotzbuecher <mk@chasey>
-+
-+ * Makefile fix, fist_ioctl was built against wrong sources if ARCH=um
-+
-+ * Fixed a bug in dentry.c, mini_fo_d_hash. In state 4 =
-+ DEL_REWRITTEN the hash was calculated from the base dentry,
-+ which was wrong and and caused assertions in
-+ __mini_fo_hidden_dentry to fail.
-+
-+2005-02-21 <mk@mary>
-+
-+ * Implemented directory deleting (inode.c)
-+
-+ * main.c: made mini_fo_parse_options a little more robust.
-+
-+2004-12-22 <mk@mary>
-+
-+ * Makefile cleanup and uml stuff, removed unneccessary files
-+
-+ * Created a new and hopefully more informative README
-+
-+ * CHANGELOG: created a new CHANGELOG and added old entries reversely
-+
-+
-+2004-10-24 Gleb Natapov <gleb@nbase.co.il>
-+
-+ * Fix: owner and group where not correctly copied from base to
-+ storage.
-+
-+
-+2004-10-05 Gleb Natapov <gleb@nbase.co.il>
-+
-+ * Implementation of fsync, fasync and lock mini_fo functions.
-+
-+
-+2004-09-29 Bob Lee <bob@pantasys.com>
-+
-+ * Fix of a serious pointer bug
-+
-+
-+2004-09-28 Gleb Natapov <gleb@nbase.co.il>
-+
-+ * Implementation of mini_fo_mknod and mini_fo_rename, support
-+ for device files.
-+
---- /dev/null
-+++ b/fs/mini_fo/dentry.c
-@@ -0,0 +1,244 @@
-+/*
-+ * Copyright (c) 1997-2003 Erez Zadok
-+ * Copyright (c) 2001-2003 Stony Brook University
-+ *
-+ * For specific licensing information, see the COPYING file distributed with
-+ * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
-+ *
-+ * This Copyright notice must be kept intact and distributed with all
-+ * fistgen sources INCLUDING sources generated by fistgen.
-+ */
-+/*
-+ * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
-+ *
-+ * 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.
-+ */
-+
-+/*
-+ * $Id$
-+ */
-+
-+#ifdef HAVE_CONFIG_H
-+# include <config.h>
-+#endif
-+
-+#include "fist.h"
-+#include "mini_fo.h"
-+
-+/*
-+ * THIS IS A BOOLEAN FUNCTION: returns 1 if valid, 0 otherwise.
-+ */
-+STATIC int
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
-+mini_fo_d_revalidate(dentry_t *dentry, struct nameidata *nd)
-+#else
-+mini_fo_d_revalidate(dentry_t *dentry, int flags)
-+#endif
-+{
-+ int err1 = 1; /* valid = 1, invalid = 0 */
-+ int err2 = 1;
-+ dentry_t *hidden_dentry;
-+ dentry_t *hidden_sto_dentry;
-+
-+
-+ check_mini_fo_dentry(dentry);
-+
-+ hidden_dentry = dtohd(dentry);
-+ hidden_sto_dentry = dtohd2(dentry);
-+
-+ if(hidden_dentry &&
-+ hidden_dentry->d_op &&
-+ hidden_dentry->d_op->d_revalidate) {
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
-+ err1 = hidden_dentry->d_op->d_revalidate(hidden_dentry, nd);
-+#else
-+ err1 = hidden_dentry->d_op->d_revalidate(hidden_dentry, flags);
-+#endif
-+ }
-+ if(hidden_sto_dentry &&
-+ hidden_sto_dentry->d_op &&
-+ hidden_sto_dentry->d_op->d_revalidate) {
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
-+ err2 = hidden_sto_dentry->d_op->d_revalidate(hidden_sto_dentry,
-+ nd);
-+#else
-+ err2 = hidden_sto_dentry->d_op->d_revalidate(hidden_sto_dentry,
-+ flags);
-+#endif
-+ }
-+
-+ /* mk: if one of the lower level dentries are valid,
-+ * the mini_fo dentry is too.
-+ */
-+ return (err1 || err2);
-+}
-+
-+
-+STATIC int
-+mini_fo_d_hash(dentry_t *dentry, qstr_t *name)
-+{
-+ int err = 0;
-+ dentry_t *hidden_dentry;
-+ dentry_t *hidden_sto_dentry;
-+
-+ /* hidden_dentry = mini_fo_hidden_dentry(dentry);
-+ * hidden_sto_dentry = mini_fo_hidden_sto_dentry(dentry); */
-+
-+ /* state 1, 3, 4, 5: build the hash for the storage dentry */
-+ if((dtopd(dentry)->state == MODIFIED) ||
-+ (dtopd(dentry)->state == CREATED) ||
-+ (dtopd(dentry)->state == DEL_REWRITTEN) ||
-+ (dtopd(dentry)->state == DELETED)) {
-+ hidden_sto_dentry = dtohd2(dentry);
-+ if(hidden_sto_dentry &&
-+ hidden_sto_dentry->d_op &&
-+ hidden_sto_dentry->d_op->d_hash) {
-+ err = hidden_sto_dentry->d_op->d_hash(hidden_sto_dentry, name);
-+ }
-+ goto out;
-+ }
-+ /* state 2: build the hash for the base dentry */
-+ if(dtopd(dentry)->state == UNMODIFIED) {
-+ hidden_dentry = dtohd(dentry);
-+ if(hidden_dentry &&
-+ hidden_dentry->d_op &&
-+ hidden_dentry->d_op->d_hash) {
-+ err = hidden_dentry->d_op->d_hash(hidden_dentry, name);
-+ }
-+ goto out;
-+ }
-+ /* state 6: build hash for the dentry that exists */
-+ if(dtopd(dentry)->state == NON_EXISTANT) {
-+ hidden_sto_dentry = dtohd2(dentry);
-+ if(hidden_sto_dentry &&
-+ hidden_sto_dentry->d_op &&
-+ hidden_sto_dentry->d_op->d_hash) {
-+ err = hidden_sto_dentry->d_op->d_hash(hidden_sto_dentry, name);
-+ goto out;
-+ }
-+ hidden_dentry = dtohd(dentry);
-+ if(hidden_dentry &&
-+ hidden_dentry->d_op &&
-+ hidden_dentry->d_op->d_hash) {
-+ err = hidden_dentry->d_op->d_hash(hidden_dentry, name);
-+ goto out;
-+ }
-+ }
-+
-+ printk(KERN_CRIT "mini_fo: d_hash: invalid state detected.\n");
-+
-+ out:
-+ return err;
-+}
-+
-+
-+STATIC int
-+mini_fo_d_compare(dentry_t *dentry, qstr_t *a, qstr_t *b)
-+{
-+ int err;
-+ dentry_t *hidden_dentry=NULL;
-+
-+ /* hidden_dentry = mini_fo_hidden_dentry(dentry); */
-+ if(dtohd2(dentry))
-+ hidden_dentry = dtohd2(dentry);
-+ else if(dtohd(dentry))
-+ hidden_dentry = dtohd(dentry);
-+
-+ if (hidden_dentry && hidden_dentry->d_op && hidden_dentry->d_op->d_compare) {
-+ err = hidden_dentry->d_op->d_compare(hidden_dentry, a, b);
-+ } else {
-+ err = ((a->len != b->len) || memcmp(a->name, b->name, b->len));
-+ }
-+
-+ return err;
-+}
-+
-+
-+int
-+mini_fo_d_delete(dentry_t *dentry)
-+{
-+ dentry_t *hidden_dentry;
-+ dentry_t *hidden_sto_dentry;
-+ int err = 0;
-+
-+ /* this could be a negative dentry, so check first */
-+ if (!dtopd(dentry)) {
-+ printk(KERN_CRIT "mini_fo_d_delete: negative dentry passed.\n");
-+ goto out;
-+ }
-+ hidden_dentry = dtohd(dentry);
-+ hidden_sto_dentry = dtohd2(dentry);
-+
-+ if(hidden_dentry) {
-+ if(hidden_dentry->d_op &&
-+ hidden_dentry->d_op->d_delete) {
-+ err = hidden_dentry->d_op->d_delete(hidden_dentry);
-+ }
-+ }
-+ if(hidden_sto_dentry) {
-+ if(hidden_sto_dentry->d_op &&
-+ hidden_sto_dentry->d_op->d_delete) {
-+ err = hidden_sto_dentry->d_op->d_delete(hidden_sto_dentry);
-+ }
-+ }
-+
-+ out:
-+ return err;
-+}
-+
-+
-+void
-+mini_fo_d_release(dentry_t *dentry)
-+{
-+ dentry_t *hidden_dentry;
-+ dentry_t *hidden_sto_dentry;
-+
-+
-+ /* this could be a negative dentry, so check first */
-+ if (!dtopd(dentry)) {
-+ printk(KERN_CRIT "mini_fo_d_release: no private data.\n");
-+ goto out;
-+ }
-+ hidden_dentry = dtohd(dentry);
-+ hidden_sto_dentry = dtohd2(dentry);
-+
-+ if(hidden_dentry) {
-+ /* decrement hidden dentry's counter and free its inode */
-+ dput(hidden_dentry);
-+ }
-+ if(hidden_sto_dentry) {
-+ /* decrement hidden dentry's counter and free its inode */
-+ dput(hidden_sto_dentry);
-+ }
-+
-+ /* free private data (mini_fo_dentry_info) here */
-+ kfree(dtopd(dentry));
-+ __dtopd(dentry) = NULL; /* just to be safe */
-+ out:
-+ return;
-+}
-+
-+
-+/*
-+ * we don't really need mini_fo_d_iput, because dentry_iput will call iput() if
-+ * mini_fo_d_iput is not defined. We left this implemented for ease of
-+ * tracing/debugging.
-+ */
-+void
-+mini_fo_d_iput(dentry_t *dentry, inode_t *inode)
-+{
-+ iput(inode);
-+}
-+
-+
-+struct dentry_operations mini_fo_dops = {
-+ d_revalidate: mini_fo_d_revalidate,
-+ d_hash: mini_fo_d_hash,
-+ d_compare: mini_fo_d_compare,
-+ d_release: mini_fo_d_release,
-+ d_delete: mini_fo_d_delete,
-+ d_iput: mini_fo_d_iput,
-+};
---- /dev/null
-+++ b/fs/mini_fo/file.c
-@@ -0,0 +1,713 @@
-+/*
-+ * Copyright (c) 1997-2003 Erez Zadok
-+ * Copyright (c) 2001-2003 Stony Brook University
-+ *
-+ * For specific licensing information, see the COPYING file distributed with
-+ * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
-+ *
-+ * This Copyright notice must be kept intact and distributed with all
-+ * fistgen sources INCLUDING sources generated by fistgen.
-+ */
-+/*
-+ * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
-+ *
-+ * 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.
-+ */
-+
-+/*
-+ * $Id$
-+ */
-+
-+#ifdef HAVE_CONFIG_H
-+# include <config.h>
-+#endif
-+
-+#include "fist.h"
-+#include "mini_fo.h"
-+#define ROUND_UP(x) (((x)+sizeof(long)-1) & ~(sizeof(long)-1))
-+
-+/*******************
-+ * File Operations *
-+ *******************/
-+
-+STATIC loff_t
-+mini_fo_llseek(file_t *file, loff_t offset, int origin)
-+{
-+ loff_t err;
-+ file_t *hidden_file = NULL;
-+
-+ if(S_ISDIR(file->f_dentry->d_inode->i_mode)) {
-+ /* Check if trying to llseek from a directory */
-+ err = -EISDIR;
-+ goto out;
-+ }
-+ if (ftopd(file) != NULL) {
-+ if(ftohf2(file)) {
-+ hidden_file = ftohf2(file);
-+ } else {
-+ hidden_file = ftohf(file);
-+ }
-+ }
-+
-+ /* always set hidden position to this one */
-+ hidden_file->f_pos = file->f_pos;
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
-+ memcpy(&(hidden_file->f_ra),
-+ &(file->f_ra),
-+ sizeof(struct file_ra_state));
-+#else
-+ if (file->f_reada) { /* update readahead information if needed */
-+ hidden_file->f_reada = file->f_reada;
-+ hidden_file->f_ramax = file->f_ramax;
-+ hidden_file->f_raend = file->f_raend;
-+ hidden_file->f_ralen = file->f_ralen;
-+ hidden_file->f_rawin = file->f_rawin;
-+ }
-+#endif
-+ if (hidden_file->f_op && hidden_file->f_op->llseek)
-+ err = hidden_file->f_op->llseek(hidden_file, offset, origin);
-+ else
-+ err = generic_file_llseek(hidden_file, offset, origin);
-+
-+ if (err < 0)
-+ goto out;
-+
-+ if (err != file->f_pos) {
-+ file->f_pos = err;
-+ // ION maybe this?
-+ // file->f_pos = hidden_file->f_pos;
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
-+ file->f_reada = 0;
-+#endif
-+ file->f_version++;
-+ }
-+
-+ out:
-+ return err;
-+}
-+
-+
-+/* mk: fanout capable */
-+STATIC ssize_t
-+mini_fo_read(file_t *file, char *buf, size_t count, loff_t *ppos)
-+{
-+ int err = -EINVAL;
-+ file_t *hidden_file = NULL;
-+ loff_t pos = *ppos;
-+
-+ if(S_ISDIR(file->f_dentry->d_inode->i_mode)) {
-+ /* Check if trying to read from a directory */
-+ /* printk(KERN_CRIT "mini_fo_read: ERROR: trying to read data from a directory.\n"); */
-+ err = -EISDIR;
-+ goto out;
-+ }
-+
-+ if (ftopd(file) != NULL) {
-+ if(ftohf2(file)) {
-+ hidden_file = ftohf2(file);
-+ } else {
-+ hidden_file = ftohf(file);
-+ }
-+ }
-+
-+ if (!hidden_file->f_op || !hidden_file->f_op->read)
-+ goto out;
-+
-+ err = hidden_file->f_op->read(hidden_file, buf, count, &pos);
-+ *ppos = pos;
-+
-+ if (err >= 0) {
-+ /* atime should also be updated for reads of size zero or more */
-+ fist_copy_attr_atime(file->f_dentry->d_inode,
-+ hidden_file->f_dentry->d_inode);
-+ }
-+
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
-+ /*
-+ * MAJOR HACK
-+ * because pread() does not have any way to tell us that it is
-+ * our caller, then we don't know for sure if we have to update
-+ * the file positions. This hack relies on read() having passed us
-+ * the "real" pointer of its struct file's f_pos field.
-+ */
-+ if (ppos == &file->f_pos)
-+ hidden_file->f_pos = *ppos = pos;
-+ if (hidden_file->f_reada) { /* update readahead information if needed */
-+ file->f_reada = hidden_file->f_reada;
-+ file->f_ramax = hidden_file->f_ramax;
-+ file->f_raend = hidden_file->f_raend;
-+ file->f_ralen = hidden_file->f_ralen;
-+ file->f_rawin = hidden_file->f_rawin;
-+ }
-+#else
-+ memcpy(&(file->f_ra),&(hidden_file->f_ra),sizeof(struct file_ra_state));
-+#endif
-+
-+ out:
-+ return err;
-+}
-+
-+
-+/* this mini_fo_write() does not modify data pages! */
-+STATIC ssize_t
-+mini_fo_write(file_t *file, const char *buf, size_t count, loff_t *ppos)
-+{
-+ int err = -EINVAL;
-+ file_t *hidden_file = NULL;
-+ inode_t *inode;
-+ inode_t *hidden_inode;
-+ loff_t pos = *ppos;
-+
-+ /* mk: fan out: */
-+ if (ftopd(file) != NULL) {
-+ if(ftohf2(file)) {
-+ hidden_file = ftohf2(file);
-+ } else {
-+ /* This is bad! We have no storage file to write to. This
-+ * should never happen because if a file is opened for
-+ * writing, a copy should have been made earlier.
-+ */
-+ printk(KERN_CRIT "mini_fo: write : ERROR, no storage file to write.\n");
-+ err = -EINVAL;
-+ goto out;
-+ }
-+ }
-+
-+ inode = file->f_dentry->d_inode;
-+ hidden_inode = itohi2(inode);
-+ if(!hidden_inode) {
-+ printk(KERN_CRIT "mini_fo: write: no sto inode found, not good.\n");
-+ goto out;
-+ }
-+
-+ if (!hidden_file->f_op || !hidden_file->f_op->write)
-+ goto out;
-+
-+ /* adjust for append -- seek to the end of the file */
-+ if (file->f_flags & O_APPEND)
-+ pos = inode->i_size;
-+
-+ err = hidden_file->f_op->write(hidden_file, buf, count, &pos);
-+
-+ /*
-+ * copy ctime and mtime from lower layer attributes
-+ * atime is unchanged for both layers
-+ */
-+ if (err >= 0)
-+ fist_copy_attr_times(inode, hidden_inode);
-+
-+ *ppos = pos;
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
-+ /*
-+ * XXX: MAJOR HACK
-+ *
-+ * because pwrite() does not have any way to tell us that it is
-+ * our caller, then we don't know for sure if we have to update
-+ * the file positions. This hack relies on write() having passed us
-+ * the "real" pointer of its struct file's f_pos field.
-+ */
-+ if (ppos == &file->f_pos)
-+ hidden_file->f_pos = *ppos = pos;
-+#endif
-+ /* update this inode's size */
-+ if (pos > inode->i_size)
-+ inode->i_size = pos;
-+
-+ out:
-+ return err;
-+}
-+
-+/* Global variable to hold a file_t pointer.
-+ * This serves to allow mini_fo_filldir function to know which file is
-+ * beeing read, which is required for two reasons:
-+ *
-+ * - be able to call wol functions in order to avoid listing deleted
-+ * base files.
-+ * - if we're reading a directory which is in state 1, we need to
-+ * maintain a list (in mini_fo_filldir) of which files allready
-+ * have been copied to userspace,to detect files existing in base
-+ * and storage and not list them twice.
-+ */
-+filldir_t mini_fo_filldir_orig;
-+file_t *mini_fo_filldir_file;
-+
-+/* mainly copied from fs/readdir.c */
-+STATIC int
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
-+mini_fo_filldir(void * __buf, const char * name, int namlen, loff_t offset,
-+ u64 ino, unsigned int d_type)
-+#else
-+mini_fo_filldir(void * __buf, const char * name, int namlen, loff_t offset,
-+ ino_t ino, unsigned int d_type)
-+#endif
-+{
-+ struct getdents_callback * buf = (struct getdents_callback *) __buf;
-+ file_t* file = mini_fo_filldir_file;
-+
-+ /* In theses states we filter meta files in storage (WOL) */
-+ if(file && (dtopd(file->f_dentry)->state == MODIFIED ||
-+ dtopd(file->f_dentry)->state == CREATED ||
-+ dtopd(file->f_dentry)->state == DEL_REWRITTEN)) {
-+
-+ int tmp = strlen(META_FILENAME);
-+ if(tmp == namlen) {
-+ if(!strncmp(name, META_FILENAME, namlen))
-+ return 0;
-+ }
-+ }
-+
-+ /* check if we are merging the contents of storage and base */
-+ if(file && dtopd(file->f_dentry)->state == MODIFIED) {
-+ /* check if we are still reading storage contents, if
-+ * yes, we just save the name of the file for duplicate
-+ * checking later. */
-+
-+ if(!ftopd(file)->rd.sto_done) {
-+ /* put file into ndl list */
-+ if(ndl_add_entry(&ftopd(file)->rd, name, namlen))
-+ printk(KERN_CRIT "mini_fo_filldir: Error adding to ndl.\n");
-+ } else {
-+ /* check if file has been deleted */
-+ if(meta_check_d_entry(file->f_dentry, name, namlen))
-+ return 0;
-+
-+ /* do duplicate checking */
-+ if(ndl_check_entry(&ftopd(file)->rd, name, namlen))
-+ return 0;
-+ }
-+ }
-+
-+ return mini_fo_filldir_orig(buf, name, namlen, offset, ino, d_type);
-+}
-+
-+
-+STATIC int
-+mini_fo_readdir(file_t *file, void *dirent, filldir_t filldir)
-+{
-+ int err = 0;/* mk: ??? -ENOTDIR; */
-+ file_t *hidden_file = NULL;
-+ file_t *hidden_sto_file = NULL;
-+ inode_t *inode;
-+ struct getdents_callback *buf;
-+ int oldcount;
-+
-+#if defined(FIST_FILTER_NAME) || defined(FIST_FILTER_SCA)
-+ struct mini_fo_getdents_callback buf;
-+#endif /* FIST_FILTER_NAME || FIST_FILTER_SCA */
-+
-+ buf = (struct getdents_callback *) dirent;
-+ oldcount = buf->count;
-+ inode = file->f_dentry->d_inode;
-+ mini_fo_filldir_file = file;
-+ mini_fo_filldir_orig = filldir;
-+
-+ ftopd(file)->rd.sto_done = 0;
-+ do {
-+ if (ftopd(file) != NULL) {
-+ if(ftohf2(file)) {
-+ hidden_sto_file = ftohf2(file);
-+ err = vfs_readdir(hidden_sto_file, mini_fo_filldir, dirent);
-+ file->f_pos = hidden_sto_file->f_pos;
-+ if (err > 0)
-+ fist_copy_attr_atime(inode, hidden_sto_file->f_dentry->d_inode);
-+ /* not finshed yet, we'll be called again */
-+ if (buf->count != oldcount)
-+ break;
-+ }
-+
-+ ftopd(file)->rd.sto_done = 1;
-+
-+ if(ftohf(file)) {
-+ hidden_file = ftohf(file);
-+ err = vfs_readdir(hidden_file, mini_fo_filldir, dirent);
-+ file->f_pos = hidden_file->f_pos;
-+ if (err > 0)
-+ fist_copy_attr_atime(inode, hidden_file->f_dentry->d_inode);
-+ }
-+
-+ }
-+ } while (0);
-+
-+ /* mk:
-+ * we need to check if all the directory data has been copied to userspace,
-+ * or if we will be called again by userspace to complete the operation.
-+ */
-+ if(buf->count == oldcount) {
-+ ndl_put_list(&ftopd(file)->rd);
-+ }
-+
-+ /* unset this, safe */
-+ mini_fo_filldir_file = NULL;
-+ return err;
-+}
-+
-+
-+STATIC unsigned int
-+mini_fo_poll(file_t *file, poll_table *wait)
-+{
-+ unsigned int mask = DEFAULT_POLLMASK;
-+ file_t *hidden_file = NULL;
-+
-+ if (ftopd(file) != NULL) {
-+ if(ftohf2(file)) {
-+ hidden_file = ftohf2(file);
-+ } else {
-+ hidden_file = ftohf(file);
-+ }
-+ }
-+
-+ if (!hidden_file->f_op || !hidden_file->f_op->poll)
-+ goto out;
-+
-+ mask = hidden_file->f_op->poll(hidden_file, wait);
-+
-+ out:
-+ return mask;
-+}
-+
-+/* FIST-LITE special version of mmap */
-+STATIC int
-+mini_fo_mmap(file_t *file, vm_area_t *vma)
-+{
-+ int err = 0;
-+ file_t *hidden_file = NULL;
-+
-+ /* fanout capability */
-+ if (ftopd(file) != NULL) {
-+ if(ftohf2(file)) {
-+ hidden_file = ftohf2(file);
-+ } else {
-+ hidden_file = ftohf(file);
-+ }
-+ }
-+
-+ ASSERT(hidden_file != NULL);
-+ ASSERT(hidden_file->f_op != NULL);
-+ ASSERT(hidden_file->f_op->mmap != NULL);
-+
-+ vma->vm_file = hidden_file;
-+ err = hidden_file->f_op->mmap(hidden_file, vma);
-+ get_file(hidden_file); /* make sure it doesn't get freed on us */
-+ fput(file); /* no need to keep extra ref on ours */
-+
-+ return err;
-+}
-+
-+
-+
-+STATIC int
-+mini_fo_open(inode_t *inode, file_t *file)
-+{
-+ int err = 0;
-+ int hidden_flags;
-+ file_t *hidden_file = NULL;
-+ dentry_t *hidden_dentry = NULL;
-+
-+ /* fanout stuff */
-+ file_t *hidden_sto_file = NULL;
-+ dentry_t *hidden_sto_dentry = NULL;
-+
-+ __ftopd(file) =
-+ kmalloc(sizeof(struct mini_fo_file_info), GFP_KERNEL);
-+ if (!ftopd(file)) {
-+ err = -ENOMEM;
-+ goto out;
-+ }
-+
-+ /* init the readdir_helper structure */
-+ INIT_LIST_HEAD(&ftopd(file)->rd.ndl_list);
-+ ftopd(file)->rd.ndl_size = 0;
-+
-+ /* In certain paths this could stay uninitalized and cause trouble */
-+ ftohf(file) = NULL;
-+ ftohf2(file) = NULL;
-+ hidden_flags = file->f_flags;
-+
-+ /* create storage files? */
-+ if(dtost(file->f_dentry) == UNMODIFIED) {
-+ if(!IS_WRITE_FLAG(file->f_flags)) {
-+ hidden_dentry = dtohd(file->f_dentry);
-+ dget(hidden_dentry);
-+ /* dentry_open will decrement mnt refcnt if err.
-+ * otherwise fput() will do an mntput() for us upon file close. */
-+ mntget(stopd(inode->i_sb)->hidden_mnt);
-+ hidden_file = dentry_open(hidden_dentry,
-+ stopd(inode->i_sb)->hidden_mnt,
-+ hidden_flags);
-+ if (IS_ERR(hidden_file)) {
-+ err = PTR_ERR(hidden_file);
-+ dput(hidden_dentry);
-+ goto out;
-+ }
-+ ftohf(file) = hidden_file; /* link two files */
-+ goto out;
-+ }
-+ else {
-+ if(S_ISDIR(file->f_dentry->d_inode->i_mode)) {
-+ err = dir_unmod_to_mod(file->f_dentry);
-+ } else
-+ err = nondir_unmod_to_mod(file->f_dentry, 1);
-+
-+ if (err) {
-+ printk("mini_fo_open: ERROR creating storage file.\n");
-+ goto out;
-+ }
-+ }
-+ }
-+ hidden_sto_dentry = dtohd2(file->f_dentry);
-+ dget(hidden_sto_dentry);
-+
-+ if(dtopd(file->f_dentry)->state == MODIFIED) {
-+ /* Directorys are special, interpose on both lower level files */
-+ if(S_ISDIR(itohi(inode)->i_mode)) {
-+ /* check for invalid file types of lower level files */
-+ if(!(S_ISDIR(itohi(inode)->i_mode) && S_ISDIR(itohi2(inode)->i_mode))) {
-+ printk(KERN_CRIT "mini_fo_open: meta data corruption detected.\n");
-+ dput(hidden_sto_dentry);
-+ err = -EINVAL;
-+ goto out;
-+ }
-+
-+ /* lower level directorys are ok, open the base file */
-+ hidden_dentry = dtohd(file->f_dentry);
-+ dget(hidden_dentry);
-+
-+ mntget(stopd(inode->i_sb)->hidden_mnt);
-+ hidden_file = dentry_open(hidden_dentry,
-+ stopd(inode->i_sb)->hidden_mnt,
-+ hidden_flags);
-+ if (IS_ERR(hidden_file)) {
-+ err = PTR_ERR(hidden_file);
-+ dput(hidden_dentry);
-+ dput(hidden_sto_dentry);
-+ goto out;
-+ }
-+ ftohf(file) = hidden_file; /* link the two files */
-+ }
-+ }
-+
-+ if(!exists_in_storage(file->f_dentry)) {
-+ printk(KERN_CRIT "mini_fo_open: invalid file state detected.\n");
-+ err = -EINVAL;
-+ dput(hidden_sto_dentry);
-+
-+ /* If the base file has been opened, we need to close it here */
-+ if(ftohf(file)) {
-+ if (hidden_file->f_op && hidden_file->f_op->flush)
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
-+ hidden_file->f_op->flush(hidden_file, NULL);
-+#else
-+ hidden_file->f_op->flush(hidden_file);
-+#endif
-+ dput(hidden_dentry);
-+ }
-+ goto out;
-+ }
-+
-+ /* ok, now we can safely open the storage file */
-+ mntget(stopd(inode->i_sb)->hidden_mnt2);
-+ hidden_sto_file = dentry_open(hidden_sto_dentry,
-+ stopd(inode->i_sb)->hidden_mnt2,
-+ hidden_flags);
-+
-+ /* dentry_open dputs the dentry if it fails */
-+ if (IS_ERR(hidden_sto_file)) {
-+ err = PTR_ERR(hidden_sto_file);
-+ /* close base file if open */
-+ if(ftohf(file)) {
-+ if (hidden_file->f_op && hidden_file->f_op->flush)
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
-+ hidden_file->f_op->flush(hidden_file, NULL);
-+#else
-+ hidden_file->f_op->flush(hidden_file);
-+#endif
-+ dput(hidden_dentry);
-+ }
-+ goto out;
-+ }
-+ ftohf2(file) = hidden_sto_file; /* link storage file */
-+
-+ out:
-+ if (err < 0 && ftopd(file)) {
-+ kfree(ftopd(file));
-+ }
-+ return err;
-+}
-+
-+STATIC int
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
-+mini_fo_flush(file_t *file, fl_owner_t id)
-+#else
-+mini_fo_flush(file_t *file)
-+#endif
-+{
-+ int err1 = 0; /* assume ok (see open.c:close_fp) */
-+ int err2 = 0;
-+ file_t *hidden_file = NULL;
-+
-+ check_mini_fo_file(file);
-+
-+ /* mk: we don't do any state checking here, as its not worth the time.
-+ * Just flush the lower level files if they exist.
-+ */
-+ if(ftopd(file) != NULL) {
-+ if(ftohf(file) != NULL) {
-+ hidden_file = ftohf(file);
-+ if (hidden_file->f_op && hidden_file->f_op->flush)
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
-+ err1 = hidden_file->f_op->flush(hidden_file, id);
-+#else
-+ err1 = hidden_file->f_op->flush(hidden_file);
-+#endif
-+ }
-+ if(ftohf2(file) != NULL) {
-+ hidden_file = ftohf2(file);
-+ if (hidden_file->f_op && hidden_file->f_op->flush)
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
-+ err2 = hidden_file->f_op->flush(hidden_file, id);
-+#else
-+ err2 = hidden_file->f_op->flush(hidden_file);
-+#endif
-+ }
-+ }
-+ return (err1 | err2);
-+}
-+
-+
-+STATIC int
-+mini_fo_release(inode_t *inode, file_t *file)
-+{
-+ int err = 0;
-+ file_t *hidden_file = NULL;
-+
-+ if (ftopd(file) != NULL) {
-+ if(ftohf(file)) {
-+ hidden_file = ftohf(file);
-+ fput(hidden_file);
-+ }
-+ if(ftohf2(file)) {
-+ hidden_file = ftohf2(file);
-+ fput(hidden_file);
-+ }
-+ kfree(ftopd(file));
-+ }
-+ return err;
-+}
-+
-+STATIC int
-+mini_fo_fsync(file_t *file, dentry_t *dentry, int datasync)
-+{
-+ int err1 = 0;
-+ int err2 = 0;
-+ file_t *hidden_file = NULL;
-+ dentry_t *hidden_dentry;
-+
-+ check_mini_fo_file(file);
-+
-+ if ((hidden_file = ftohf(file)) != NULL) {
-+ hidden_dentry = dtohd(dentry);
-+ if (hidden_file->f_op && hidden_file->f_op->fsync) {
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_lock(&hidden_dentry->d_inode->i_mutex);
-+#else
-+ down(&hidden_dentry->d_inode->i_sem);
-+#endif
-+ err1 = hidden_file->f_op->fsync(hidden_file, hidden_dentry, datasync);
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_unlock(&hidden_dentry->d_inode->i_mutex);
-+#else
-+ up(&hidden_dentry->d_inode->i_sem);
-+#endif
-+ }
-+ }
-+
-+ if ((hidden_file = ftohf2(file)) != NULL) {
-+ hidden_dentry = dtohd2(dentry);
-+ if (hidden_file->f_op && hidden_file->f_op->fsync) {
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_lock(&hidden_dentry->d_inode->i_mutex);
-+#else
-+ down(&hidden_dentry->d_inode->i_sem);
-+#endif
-+ err2 = hidden_file->f_op->fsync(hidden_file, hidden_dentry, datasync);
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_unlock(&hidden_dentry->d_inode->i_mutex);
-+#else
-+ up(&hidden_dentry->d_inode->i_sem);
-+#endif
-+ }
-+ }
-+ else
-+ goto err;
-+
-+err:
-+ return (err1 || err2);
-+}
-+
-+
-+STATIC int
-+mini_fo_fasync(int fd, file_t *file, int flag)
-+{
-+ int err1 = 0;
-+ int err2 = 0;
-+
-+ file_t *hidden_file = NULL;
-+
-+ check_mini_fo_file(file);
-+
-+ if((hidden_file = ftohf(file)) != NULL) {
-+ err1 = hidden_file->f_op->fasync(fd, hidden_file, flag);
-+ }
-+ if((hidden_file = ftohf2(file)) != NULL) {
-+ err2 = hidden_file->f_op->fasync(fd, hidden_file, flag);
-+ }
-+
-+ return (err1 || err2);
-+}
-+
-+
-+
-+struct file_operations mini_fo_dir_fops =
-+ {
-+ read: generic_read_dir,
-+ write: mini_fo_write,
-+ readdir: mini_fo_readdir,
-+ poll: mini_fo_poll,
-+ /* ioctl: mini_fo_ioctl, */
-+ mmap: mini_fo_mmap,
-+ open: mini_fo_open,
-+ flush: mini_fo_flush,
-+ release: mini_fo_release,
-+ fsync: mini_fo_fsync,
-+ fasync: mini_fo_fasync,
-+ /* not needed lock: mini_fo_lock, */
-+ /* not needed: readv */
-+ /* not needed: writev */
-+ /* not implemented: sendpage */
-+ /* not implemented: get_unmapped_area */
-+ };
-+
-+struct file_operations mini_fo_main_fops =
-+ {
-+ llseek: mini_fo_llseek,
-+ read: mini_fo_read,
-+ write: mini_fo_write,
-+ readdir: mini_fo_readdir,
-+ poll: mini_fo_poll,
-+ /* ioctl: mini_fo_ioctl, */
-+ mmap: mini_fo_mmap,
-+ open: mini_fo_open,
-+ flush: mini_fo_flush,
-+ release: mini_fo_release,
-+ fsync: mini_fo_fsync,
-+ fasync: mini_fo_fasync,
-+ /* not needed: lock: mini_fo_lock, */
-+ /* not needed: readv */
-+ /* not needed: writev */
-+ /* not implemented: sendpage */
-+ /* not implemented: get_unmapped_area */
-+ };
---- /dev/null
-+++ b/fs/mini_fo/fist.h
-@@ -0,0 +1,252 @@
-+/*
-+ * Copyright (c) 1997-2003 Erez Zadok
-+ * Copyright (c) 2001-2003 Stony Brook University
-+ *
-+ * For specific licensing information, see the COPYING file distributed with
-+ * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
-+ *
-+ * This Copyright notice must be kept intact and distributed with all
-+ * fistgen sources INCLUDING sources generated by fistgen.
-+ */
-+/*
-+ * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
-+ *
-+ * 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.
-+ */
-+
-+
-+/*
-+ * $Id$
-+ */
-+
-+#ifndef __FIST_H_
-+#define __FIST_H_
-+
-+/*
-+ * KERNEL ONLY CODE:
-+ */
-+#ifdef __KERNEL__
-+#include <linux/version.h>
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,19)
-+#include <linux/autoconf.h>
-+#else
-+#include <linux/config.h>
-+#endif
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
-+#ifdef CONFIG_MODVERSIONS
-+# define MODVERSIONS
-+# include <linux/modversions.h>
-+#endif /* CONFIG_MODVERSIONS */
-+#endif /* KERNEL_VERSION < 2.6.0 */
-+#include <linux/sched.h>
-+#include <linux/kernel.h>
-+#include <linux/mm.h>
-+#include <linux/string.h>
-+#include <linux/stat.h>
-+#include <linux/errno.h>
-+#include <linux/wait.h>
-+#include <linux/limits.h>
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
-+#include <linux/locks.h>
-+#else
-+#include <linux/buffer_head.h>
-+#include <linux/pagemap.h>
-+#include <linux/namei.h>
-+#include <linux/module.h>
-+#include <linux/mount.h>
-+#include <linux/page-flags.h>
-+#include <linux/writeback.h>
-+#include <linux/statfs.h>
-+#endif
-+#include <linux/smp.h>
-+#include <linux/smp_lock.h>
-+#include <linux/file.h>
-+#include <linux/slab.h>
-+#include <linux/vmalloc.h>
-+#include <linux/poll.h>
-+#include <linux/list.h>
-+#include <linux/init.h>
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20)
-+#include <linux/xattr.h>
-+#endif
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
-+#include <linux/security.h>
-+#endif
-+
-+#include <linux/swap.h>
-+
-+#include <asm/system.h>
-+/* #include <asm/segment.h> */
-+#include <asm/mman.h>
-+#include <linux/seq_file.h>
-+
-+/*
-+ * MACROS:
-+ */
-+
-+/* those mapped to ATTR_* were copied from linux/fs.h */
-+#define FA_MODE ATTR_MODE
-+#define FA_UID ATTR_UID
-+#define FA_GID ATTR_GID
-+#define FA_SIZE ATTR_SIZE
-+#define FA_ATIME ATTR_ATIME
-+#define FA_MTIME ATTR_MTIME
-+#define FA_CTIME ATTR_CTIME
-+#define FA_ATIME_SET ATTR_ATIME_SET
-+#define FA_MTIME_SET ATTR_MTIME_SET
-+#define FA_FORCE ATTR_FORCE
-+#define FA_ATTR_FLAGS ATTR_ATTR_FLAG
-+
-+/* must be greater than all other ATTR_* flags! */
-+#define FA_NLINK 2048
-+#define FA_BLKSIZE 4096
-+#define FA_BLOCKS 8192
-+#define FA_TIMES (FA_ATIME|FA_MTIME|FA_CTIME)
-+#define FA_ALL 0
-+
-+/* macros to manage changes between kernels */
-+#define INODE_DATA(i) (&(i)->i_data)
-+
-+#define MIN(x,y) ((x < y) ? (x) : (y))
-+#define MAX(x,y) ((x > y) ? (x) : (y))
-+#define MAXPATHLEN PATH_MAX
-+
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,5)
-+# define lookup_one_len(a,b,c) lookup_one(a,b)
-+#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,4,5) */
-+
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,8)
-+# define generic_file_llseek default_llseek
-+#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,4,8) */
-+
-+#ifndef SEEK_SET
-+# define SEEK_SET 0
-+#endif /* not SEEK_SET */
-+
-+#ifndef SEEK_CUR
-+# define SEEK_CUR 1
-+#endif /* not SEEK_CUR */
-+
-+#ifndef SEEK_END
-+# define SEEK_END 2
-+#endif /* not SEEK_END */
-+
-+#ifndef DEFAULT_POLLMASK
-+# define DEFAULT_POLLMASK (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM)
-+#endif /* not DEFAULT_POLLMASK */
-+
-+/* XXX: fix this so fistgen generates kfree() code directly */
-+#define kfree_s(a,b) kfree(a)
-+
-+/*
-+ * TYPEDEFS:
-+ */
-+typedef struct dentry dentry_t;
-+typedef struct file file_t;
-+typedef struct inode inode_t;
-+typedef inode_t vnode_t;
-+typedef struct page page_t;
-+typedef struct qstr qstr_t;
-+typedef struct super_block super_block_t;
-+typedef super_block_t vfs_t;
-+typedef struct vm_area_struct vm_area_t;
-+
-+
-+/*
-+ * EXTERNALS:
-+ */
-+
-+#define FPPF(str,page) printk("PPF %s 0x%x/%d: Lck:%d Err:%d Ref:%d Upd:%d Other::%d:%d:%d:%d:\n", \
-+ str, \
-+ (int) page, \
-+ (int) page->index, \
-+ (PageLocked(page) ? 1 : 0), \
-+ (PageError(page) ? 1 : 0), \
-+ (PageReferenced(page) ? 1 : 0), \
-+ (Page_Uptodate(page) ? 1 : 0), \
-+ (PageDecrAfter(page) ? 1 : 0), \
-+ (PageSlab(page) ? 1 : 0), \
-+ (PageSwapCache(page) ? 1 : 0), \
-+ (PageReserved(page) ? 1 : 0) \
-+ )
-+#define EZKDBG printk("EZK %s:%d:%s\n",__FILE__,__LINE__,__FUNCTION__)
-+#if 0
-+# define EZKDBG1 printk("EZK %s:%d\n",__FILE__,__LINE__)
-+#else
-+# define EZKDBG1
-+#endif
-+
-+extern int fist_get_debug_value(void);
-+extern int fist_set_debug_value(int val);
-+#if 0 /* mini_fo doesn't need these */
-+extern void fist_dprint_internal(int level, char *str,...);
-+extern void fist_print_dentry(char *str, const dentry_t *dentry);
-+extern void fist_print_inode(char *str, const inode_t *inode);
-+extern void fist_print_file(char *str, const file_t *file);
-+extern void fist_print_buffer_flags(char *str, struct buffer_head *buffer);
-+extern void fist_print_page_flags(char *str, page_t *page);
-+extern void fist_print_page_bytes(char *str, page_t *page);
-+extern void fist_print_pte_flags(char *str, const page_t *page);
-+extern void fist_checkinode(inode_t *inode, char *msg);
-+extern void fist_print_sb(char *str, const super_block_t *sb);
-+
-+/* §$% by mk: special debug functions */
-+extern void fist_mk_print_dentry(char *str, const dentry_t *dentry);
-+extern void fist_mk_print_inode(char *str, const inode_t *inode);
-+
-+extern char *add_indent(void);
-+extern char *del_indent(void);
-+#endif/* mini_fo doesn't need these */
-+
-+
-+#define STATIC
-+#define ASSERT(EX) \
-+do { \
-+ if (!(EX)) { \
-+ printk(KERN_CRIT "ASSERTION FAILED: %s at %s:%d (%s)\n", #EX, \
-+ __FILE__, __LINE__, __FUNCTION__); \
-+ (*((char *)0))=0; \
-+ } \
-+} while (0)
-+/* same ASSERT, but tell me who was the caller of the function */
-+#define ASSERT2(EX) \
-+do { \
-+ if (!(EX)) { \
-+ printk(KERN_CRIT "ASSERTION FAILED (caller): %s at %s:%d (%s)\n", #EX, \
-+ file, line, func); \
-+ (*((char *)0))=0; \
-+ } \
-+} while (0)
-+
-+#if 0 /* mini_fo doesn't need these */
-+#define dprintk(format, args...) printk(KERN_DEBUG format, ##args)
-+#define fist_dprint(level, str, args...) fist_dprint_internal(level, KERN_DEBUG str, ## args)
-+#define print_entry_location() fist_dprint(4, "%sIN: %s %s:%d\n", add_indent(), __FUNCTION__, __FILE__, __LINE__)
-+#define print_exit_location() fist_dprint(4, "%s OUT: %s %s:%d\n", del_indent(), __FUNCTION__, __FILE__, __LINE__)
-+#define print_exit_status(status) fist_dprint(4, "%s OUT: %s %s:%d, STATUS: %d\n", del_indent(), __FUNCTION__, __FILE__, __LINE__, status)
-+#define print_exit_pointer(status) \
-+do { \
-+ if (IS_ERR(status)) \
-+ fist_dprint(4, "%s OUT: %s %s:%d, RESULT: %ld\n", del_indent(), __FUNCTION__, __FILE__, __LINE__, PTR_ERR(status)); \
-+ else \
-+ fist_dprint(4, "%s OUT: %s %s:%d, RESULT: 0x%x\n", del_indent(), __FUNCTION__, __FILE__, __LINE__, PTR_ERR(status)); \
-+} while (0)
-+#endif/* mini_fo doesn't need these */
-+
-+#endif /* __KERNEL__ */
-+
-+
-+/*
-+ * DEFINITIONS FOR USER AND KERNEL CODE:
-+ * (Note: ioctl numbers 1--9 are reserved for fistgen, the rest
-+ * are auto-generated automatically based on the user's .fist file.)
-+ */
-+# define FIST_IOCTL_GET_DEBUG_VALUE _IOR(0x15, 1, int)
-+# define FIST_IOCTL_SET_DEBUG_VALUE _IOW(0x15, 2, int)
-+
-+#endif /* not __FIST_H_ */
---- /dev/null
-+++ b/fs/mini_fo/inode.c
-@@ -0,0 +1,1564 @@
-+/*
-+ * Copyright (c) 1997-2003 Erez Zadok
-+ * Copyright (c) 2001-2003 Stony Brook University
-+ *
-+ * For specific licensing information, see the COPYING file distributed with
-+ * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
-+ *
-+ * This Copyright notice must be kept intact and distributed with all
-+ * fistgen sources INCLUDING sources generated by fistgen.
-+ */
-+/*
-+ * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
-+ *
-+ * 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.
-+ */
-+
-+/*
-+ * $Id$
-+ */
-+
-+#ifdef HAVE_CONFIG_H
-+# include <config.h>
-+#endif
-+
-+#include "fist.h"
-+#include "mini_fo.h"
-+
-+STATIC int
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
-+mini_fo_create(inode_t *dir, dentry_t *dentry, int mode, struct nameidata *nd)
-+#else
-+mini_fo_create(inode_t *dir, dentry_t *dentry, int mode)
-+#endif
-+{
-+ int err = 0;
-+
-+ check_mini_fo_dentry(dentry);
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
-+ err = create_sto_reg_file(dentry, mode, nd);
-+#else
-+ err = create_sto_reg_file(dentry, mode);
-+#endif
-+ check_mini_fo_dentry(dentry);
-+ return err;
-+}
-+
-+
-+STATIC dentry_t *
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
-+mini_fo_lookup(inode_t *dir, dentry_t *dentry, struct nameidata* nd)
-+#else
-+mini_fo_lookup(inode_t *dir, dentry_t *dentry)
-+#endif
-+{
-+ int err = 0;
-+ dentry_t *hidden_dir_dentry;
-+ dentry_t *hidden_dentry = NULL;
-+
-+ dentry_t *hidden_sto_dir_dentry;
-+ dentry_t *hidden_sto_dentry = NULL;
-+
-+ /* whiteout flag */
-+ int del_flag = 0;
-+ char *bpath = NULL;
-+
-+ const char *name;
-+ unsigned int namelen;
-+
-+ /* Don't allow lookups of META-files */
-+ namelen = strlen(META_FILENAME);
-+ if(namelen == dentry->d_name.len) {
-+ if(!strncmp(dentry->d_name.name, META_FILENAME, namelen)) {
-+ err = -ENOENT;
-+ goto out;
-+ }
-+ }
-+
-+ hidden_dir_dentry = dtohd(dentry->d_parent);
-+ hidden_sto_dir_dentry = dtohd2(dentry->d_parent);
-+
-+ name = dentry->d_name.name;
-+ namelen = dentry->d_name.len;
-+
-+ /* must initialize dentry operations */
-+ dentry->d_op = &mini_fo_dops;
-+
-+ /* setup the del_flag */
-+ del_flag = __meta_check_d_entry(dir, name, namelen);
-+ bpath = __meta_check_r_entry(dir, name, namelen);
-+
-+ /* perform the lookups of base and storage files:
-+ *
-+ * This caused some serious trouble, as a lookup_one_len passing
-+ * a negative dentry oopses. Solution is to only do the lookup
-+ * if the dentry is positive, else we set it to NULL
-+ * More trouble, who said a *_dir_dentry can't be NULL?
-+ */
-+ if(bpath) {
-+ /* Cross-Interposing (C), yeah! */
-+ hidden_dentry = bpath_walk(dir->i_sb, bpath);
-+ if(!hidden_dentry || !hidden_dentry->d_inode) {
-+ printk(KERN_CRIT "mini_fo_lookup: bpath_walk failed.\n");
-+ err= -EINVAL;
-+ goto out;
-+ }
-+
-+ /* this can be set up safely without fear of spaghetti
-+ * interposing as it is only used for copying times */
-+ hidden_dir_dentry = hidden_dentry->d_parent;
-+ kfree(bpath);
-+ }
-+ else if(hidden_dir_dentry && hidden_dir_dentry->d_inode)
-+ hidden_dentry =
-+ lookup_one_len(name, hidden_dir_dentry, namelen);
-+ else
-+ hidden_dentry = NULL;
-+
-+ if(hidden_sto_dir_dentry && hidden_sto_dir_dentry->d_inode)
-+ hidden_sto_dentry =
-+ lookup_one_len(name, hidden_sto_dir_dentry, namelen);
-+ else
-+ hidden_sto_dentry = NULL;
-+
-+ /* catch error in lookup */
-+ if (IS_ERR(hidden_dentry) || IS_ERR(hidden_sto_dentry)) {
-+ /* mk: we need to call dput on the dentry, whose
-+ * lookup_one_len operation failed, in order to avoid
-+ * unmount trouble.
-+ */
-+ if(IS_ERR(hidden_dentry)) {
-+ printk(KERN_CRIT "mini_fo_lookup: ERR from base dentry, lookup failed.\n");
-+ err = PTR_ERR(hidden_dentry);
-+ } else {
-+ dput(hidden_dentry);
-+ }
-+ if(IS_ERR(hidden_sto_dentry)) {
-+ printk(KERN_CRIT "mini_fo_lookup: ERR from storage dentry, lookup failed.\n");
-+ err = PTR_ERR(hidden_sto_dentry);
-+ } else {
-+ dput(hidden_sto_dentry);
-+ }
-+ goto out;
-+ }
-+
-+ /* allocate dentry private data */
-+ __dtopd(dentry) = (struct mini_fo_dentry_info *)
-+ kmalloc(sizeof(struct mini_fo_dentry_info), GFP_KERNEL);
-+
-+ if (!dtopd(dentry)) {
-+ err = -ENOMEM;
-+ goto out_dput;
-+ }
-+
-+ /* check for different states of the mini_fo file to be looked up. */
-+
-+ /* state 1, file has been modified */
-+ if(hidden_dentry && hidden_sto_dentry &&
-+ hidden_dentry->d_inode && hidden_sto_dentry->d_inode && !del_flag) {
-+
-+ /* update parent directory's atime */
-+ fist_copy_attr_atime(dir, hidden_sto_dir_dentry->d_inode);
-+
-+ dtopd(dentry)->state = MODIFIED;
-+ dtohd(dentry) = hidden_dentry;
-+ dtohd2(dentry) = hidden_sto_dentry;
-+
-+ err = mini_fo_tri_interpose(hidden_dentry,
-+ hidden_sto_dentry,
-+ dentry, dir->i_sb, 1);
-+ if (err) {
-+ printk(KERN_CRIT "mini_fo_lookup: error interposing (state1).\n");
-+ goto out_free;
-+ }
-+ goto out;
-+ }
-+ /* state 2, file is unmodified */
-+ if(hidden_dentry && hidden_dentry->d_inode && !del_flag) {
-+
-+ fist_copy_attr_atime(dir, hidden_dir_dentry->d_inode);
-+
-+ dtopd(dentry)->state = UNMODIFIED;
-+ dtohd(dentry) = hidden_dentry;
-+ dtohd2(dentry) = hidden_sto_dentry; /* could be negative */
-+
-+ err = mini_fo_tri_interpose(hidden_dentry,
-+ hidden_sto_dentry,
-+ dentry, dir->i_sb, 1);
-+ if (err) {
-+ printk(KERN_CRIT "mini_fo_lookup: error interposing (state2).\n");
-+ goto out_free;
-+ }
-+ goto out;
-+ }
-+ /* state 3, file has been newly created */
-+ if(hidden_sto_dentry && hidden_sto_dentry->d_inode && !del_flag) {
-+
-+ fist_copy_attr_atime(dir, hidden_sto_dir_dentry->d_inode);
-+ dtopd(dentry)->state = CREATED;
-+ dtohd(dentry) = hidden_dentry; /* could be negative */
-+ dtohd2(dentry) = hidden_sto_dentry;
-+
-+ err = mini_fo_tri_interpose(hidden_dentry,
-+ hidden_sto_dentry,
-+ dentry, dir->i_sb, 1);
-+ if (err) {
-+ printk(KERN_CRIT "mini_fo_lookup: error interposing (state3).\n");
-+ goto out_free;
-+ }
-+ goto out;
-+ }
-+
-+ /* state 4, file has deleted and created again. */
-+ if(hidden_dentry && hidden_sto_dentry &&
-+ hidden_dentry->d_inode &&
-+ hidden_sto_dentry->d_inode && del_flag) {
-+
-+ fist_copy_attr_atime(dir, hidden_sto_dir_dentry->d_inode);
-+ dtopd(dentry)->state = DEL_REWRITTEN;
-+ dtohd(dentry) = NULL;
-+ dtohd2(dentry) = hidden_sto_dentry;
-+
-+ err = mini_fo_tri_interpose(NULL,
-+ hidden_sto_dentry,
-+ dentry, dir->i_sb, 1);
-+ if (err) {
-+ printk(KERN_CRIT "mini_fo_lookup: error interposing (state4).\n");
-+ goto out_free;
-+ }
-+ /* We will never need this dentry again, as the file has been
-+ * deleted from base */
-+ dput(hidden_dentry);
-+ goto out;
-+ }
-+ /* state 5, file has been deleted in base */
-+ if(hidden_dentry && hidden_sto_dentry &&
-+ hidden_dentry->d_inode &&
-+ !hidden_sto_dentry->d_inode && del_flag) {
-+
-+ /* check which parents atime we need for updating */
-+ if(hidden_sto_dir_dentry->d_inode)
-+ fist_copy_attr_atime(dir,
-+ hidden_sto_dir_dentry->d_inode);
-+ else
-+ fist_copy_attr_atime(dir,
-+ hidden_dir_dentry->d_inode);
-+
-+ dtopd(dentry)->state = DELETED;
-+ dtohd(dentry) = NULL;
-+ dtohd2(dentry) = hidden_sto_dentry;
-+
-+ /* add negative dentry to dcache to speed up lookups */
-+ d_add(dentry, NULL);
-+ dput(hidden_dentry);
-+ goto out;
-+ }
-+ /* state 6, file does not exist */
-+ if(((hidden_dentry && !hidden_dentry->d_inode) ||
-+ (hidden_sto_dentry && !hidden_sto_dentry->d_inode)) && !del_flag)
-+ {
-+ /* check which parents atime we need for updating */
-+ if(hidden_sto_dir_dentry && hidden_sto_dir_dentry->d_inode)
-+ fist_copy_attr_atime(dir, hidden_sto_dir_dentry->d_inode);
-+ else
-+ fist_copy_attr_atime(dir, hidden_dir_dentry->d_inode);
-+
-+ dtopd(dentry)->state = NON_EXISTANT;
-+ dtohd(dentry) = hidden_dentry;
-+ dtohd2(dentry) = hidden_sto_dentry;
-+ d_add(dentry, NULL);
-+ goto out;
-+ }
-+
-+ /* if we get to here, were in an invalid state. bad. */
-+ printk(KERN_CRIT "mini_fo_lookup: ERROR, meta data corruption detected.\n");
-+
-+ /* end state checking */
-+ out_free:
-+ d_drop(dentry); /* so that our bad dentry will get destroyed */
-+ kfree(dtopd(dentry));
-+ __dtopd(dentry) = NULL; /* be safe */
-+
-+ out_dput:
-+ if(hidden_dentry)
-+ dput(hidden_dentry);
-+ if(hidden_sto_dentry)
-+ dput(hidden_sto_dentry); /* drops usage count and marks for release */
-+
-+ out:
-+ /* initalize wol if file exists and is directory */
-+ if(dentry->d_inode) {
-+ if(S_ISDIR(dentry->d_inode->i_mode)) {
-+ itopd(dentry->d_inode)->deleted_list_size = -1;
-+ itopd(dentry->d_inode)->renamed_list_size = -1;
-+ meta_build_lists(dentry);
-+ }
-+ }
-+ return ERR_PTR(err);
-+}
-+
-+
-+STATIC int
-+mini_fo_link(dentry_t *old_dentry, inode_t *dir, dentry_t *new_dentry)
-+{
-+ int err;
-+ dentry_t *hidden_old_dentry;
-+ dentry_t *hidden_new_dentry;
-+ dentry_t *hidden_dir_dentry;
-+
-+
-+ check_mini_fo_dentry(old_dentry);
-+ check_mini_fo_dentry(new_dentry);
-+ check_mini_fo_inode(dir);
-+
-+ /* no links to directorys and existing targets target allowed */
-+ if(S_ISDIR(old_dentry->d_inode->i_mode) ||
-+ is_mini_fo_existant(new_dentry)) {
-+ err = -EPERM;
-+ goto out;
-+ }
-+
-+ /* bring it directly from unmod to del_rew */
-+ if(dtost(old_dentry) == UNMODIFIED) {
-+ err = nondir_unmod_to_mod(old_dentry, 1);
-+ if(err) {
-+ err = -EINVAL;
-+ goto out;
-+ }
-+ err = meta_add_d_entry(old_dentry->d_parent,
-+ old_dentry->d_name.name,
-+ old_dentry->d_name.len);
-+ if(err) {
-+ err = -EINVAL;
-+ goto out;
-+ }
-+ dput(dtohd(old_dentry));
-+ dtohd(old_dentry) = NULL;
-+ dtost(old_dentry) = DEL_REWRITTEN;
-+ }
-+
-+ err = get_neg_sto_dentry(new_dentry);
-+ if(err) {
-+ err = -EINVAL;
-+ goto out;
-+ }
-+
-+ hidden_old_dentry = dtohd2(old_dentry);
-+ hidden_new_dentry = dtohd2(new_dentry);
-+
-+ dget(hidden_old_dentry);
-+ dget(hidden_new_dentry);
-+
-+ /* was: hidden_dir_dentry = lock_parent(hidden_new_dentry); */
-+ hidden_dir_dentry = dget(hidden_new_dentry->d_parent);
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_lock(&hidden_dir_dentry->d_inode->i_mutex);
-+#else
-+ down(&hidden_dir_dentry->d_inode->i_sem);
-+#endif
-+
-+ err = vfs_link(hidden_old_dentry,
-+ hidden_dir_dentry->d_inode,
-+ hidden_new_dentry);
-+ if (err || !hidden_new_dentry->d_inode)
-+ goto out_lock;
-+
-+ dtost(new_dentry) = CREATED;
-+ err = mini_fo_tri_interpose(NULL, hidden_new_dentry, new_dentry, dir->i_sb, 0);
-+ if (err)
-+ goto out_lock;
-+
-+ fist_copy_attr_timesizes(dir, hidden_new_dentry->d_inode);
-+ /* propagate number of hard-links */
-+ old_dentry->d_inode->i_nlink = itohi2(old_dentry->d_inode)->i_nlink;
-+
-+ out_lock:
-+ /* was: unlock_dir(hidden_dir_dentry); */
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_unlock(&hidden_dir_dentry->d_inode->i_mutex);
-+#else
-+ up(&hidden_dir_dentry->d_inode->i_sem);
-+#endif
-+ dput(hidden_dir_dentry);
-+
-+ dput(hidden_new_dentry);
-+ dput(hidden_old_dentry);
-+ if (!new_dentry->d_inode)
-+ d_drop(new_dentry);
-+
-+ out:
-+ return err;
-+}
-+
-+
-+STATIC int
-+mini_fo_unlink(inode_t *dir, dentry_t *dentry)
-+{
-+ int err = 0;
-+
-+ dget(dentry);
-+ if(dtopd(dentry)->state == MODIFIED) {
-+ err = nondir_mod_to_del(dentry);
-+ goto out;
-+ }
-+ else if(dtopd(dentry)->state == UNMODIFIED) {
-+ err = nondir_unmod_to_del(dentry);
-+ goto out;
-+ }
-+ else if(dtopd(dentry)->state == CREATED) {
-+ err = nondir_creat_to_del(dentry);
-+ goto out;
-+ }
-+ else if(dtopd(dentry)->state == DEL_REWRITTEN) {
-+ err = nondir_del_rew_to_del(dentry);
-+ goto out;
-+ }
-+
-+ printk(KERN_CRIT "mini_fo_unlink: ERROR, invalid state detected.\n");
-+
-+ out:
-+ fist_copy_attr_times(dir, itohi2(dentry->d_parent->d_inode));
-+
-+ if(!err) {
-+ /* is this causing my pain? d_delete(dentry); */
-+ d_drop(dentry);
-+ }
-+
-+ dput(dentry);
-+ return err;
-+}
-+
-+
-+STATIC int
-+mini_fo_symlink(inode_t *dir, dentry_t *dentry, const char *symname)
-+{
-+ int err=0;
-+ dentry_t *hidden_sto_dentry;
-+ dentry_t *hidden_sto_dir_dentry;
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
-+ umode_t mode;
-+#endif
-+
-+ /* Fail if the symlink file exists */
-+ if(!(dtost(dentry) == DELETED ||
-+ dtost(dentry) == NON_EXISTANT)) {
-+ err = -EEXIST;
-+ goto out;
-+ }
-+
-+ err = get_neg_sto_dentry(dentry);
-+ if(err) {
-+ err = -EINVAL;
-+ goto out;
-+ }
-+ hidden_sto_dentry = dtohd2(dentry);
-+
-+ dget(hidden_sto_dentry);
-+ /* was: hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry); */
-+ hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
-+#else
-+ down(&hidden_sto_dir_dentry->d_inode->i_sem);
-+#endif
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
-+ mode = S_IALLUGO;
-+ err = vfs_symlink(hidden_sto_dir_dentry->d_inode,
-+ hidden_sto_dentry, symname, mode);
-+#else
-+ err = vfs_symlink(hidden_sto_dir_dentry->d_inode,
-+ hidden_sto_dentry,
-+ symname);
-+#endif
-+ if (err || !hidden_sto_dentry->d_inode)
-+ goto out_lock;
-+
-+ if(dtost(dentry) == DELETED) {
-+ dtost(dentry) = DEL_REWRITTEN;
-+ err = mini_fo_tri_interpose(NULL, hidden_sto_dentry, dentry, dir->i_sb, 0);
-+ if(err)
-+ goto out_lock;
-+ } else if(dtost(dentry) == NON_EXISTANT) {
-+ dtost(dentry) = CREATED;
-+ err = mini_fo_tri_interpose(dtohd(dentry), hidden_sto_dentry, dentry, dir->i_sb, 0);
-+ if(err)
-+ goto out_lock;
-+ }
-+ fist_copy_attr_timesizes(dir, hidden_sto_dir_dentry->d_inode);
-+
-+ out_lock:
-+ /* was: unlock_dir(hidden_sto_dir_dentry); */
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
-+#else
-+ up(&hidden_sto_dir_dentry->d_inode->i_sem);
-+#endif
-+ dput(hidden_sto_dir_dentry);
-+
-+ dput(hidden_sto_dentry);
-+ if (!dentry->d_inode)
-+ d_drop(dentry);
-+ out:
-+ return err;
-+}
-+
-+STATIC int
-+mini_fo_mkdir(inode_t *dir, dentry_t *dentry, int mode)
-+{
-+ int err;
-+
-+ err = create_sto_dir(dentry, mode);
-+
-+ check_mini_fo_dentry(dentry);
-+
-+ return err;
-+}
-+
-+
-+STATIC int
-+mini_fo_rmdir(inode_t *dir, dentry_t *dentry)
-+{
-+ int err = 0;
-+
-+ dentry_t *hidden_sto_dentry;
-+ dentry_t *hidden_sto_dir_dentry;
-+ dentry_t *meta_dentry;
-+ inode_t *hidden_sto_dir = NULL;
-+
-+ check_mini_fo_dentry(dentry);
-+ check_mini_fo_inode(dir);
-+
-+ dget(dentry);
-+ if(dtopd(dentry)->state == MODIFIED) {
-+ /* XXX: disabled, because it does not bother to check files on
-+ * the original filesystem - just a hack, but better than simply
-+ * removing it without testing */
-+ err = -EINVAL;
-+ goto out;
-+
-+ hidden_sto_dir = itohi2(dir);
-+ hidden_sto_dentry = dtohd2(dentry);
-+
-+ /* was:hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry); */
-+ hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
-+#else
-+ down(&hidden_sto_dir_dentry->d_inode->i_sem);
-+#endif
-+
-+ /* Delete an old WOL file contained in the storage dir */
-+ meta_dentry = lookup_one_len(META_FILENAME,
-+ hidden_sto_dentry,
-+ strlen(META_FILENAME));
-+ if(meta_dentry->d_inode) {
-+ err = vfs_unlink(hidden_sto_dentry->d_inode, meta_dentry);
-+ dput(meta_dentry);
-+ if(!err)
-+ d_delete(meta_dentry);
-+ }
-+
-+ err = vfs_rmdir(hidden_sto_dir, hidden_sto_dentry);
-+ dput(hidden_sto_dentry);
-+ if(!err)
-+ d_delete(hidden_sto_dentry);
-+
-+ /* propagate number of hard-links */
-+ dentry->d_inode->i_nlink = itohi2(dentry->d_inode)->i_nlink;
-+
-+ dput(dtohd(dentry));
-+
-+ dtohd(dentry) = NULL;
-+ dtopd(dentry)->state = DELETED;
-+
-+ /* carefull with R files */
-+ if( __meta_is_r_entry(dir,
-+ dentry->d_name.name,
-+ dentry->d_name.len) == 1) {
-+ err = meta_remove_r_entry(dentry->d_parent,
-+ dentry->d_name.name,
-+ dentry->d_name.len);
-+ if(err) {
-+ printk(KERN_CRIT "mini_fo: rmdir: meta_remove_r_entry failed.\n");
-+ goto out;
-+ }
-+ }
-+ else {
-+ /* ok, add deleted file to META */
-+ meta_add_d_entry(dentry->d_parent,
-+ dentry->d_name.name,
-+ dentry->d_name.len);
-+ }
-+ /* was: unlock_dir(hidden_sto_dir_dentry); */
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
-+#else
-+ up(&hidden_sto_dir_dentry->d_inode->i_sem);
-+#endif
-+ dput(hidden_sto_dir_dentry);
-+ goto out;
-+ }
-+ else if(dtopd(dentry)->state == UNMODIFIED) {
-+ /* XXX: simply adding it to the delete list here is fscking dangerous!
-+ * as a temporary hack, i will disable rmdir on unmodified directories
-+ * for now.
-+ */
-+ err = -EINVAL;
-+ goto out;
-+
-+ err = get_neg_sto_dentry(dentry);
-+ if(err) {
-+ err = -EINVAL;
-+ goto out;
-+ }
-+
-+ /* dput base dentry, this will relase the inode and free the
-+ * dentry, as we will never need it again. */
-+ dput(dtohd(dentry));
-+ dtohd(dentry) = NULL;
-+ dtopd(dentry)->state = DELETED;
-+
-+ /* add deleted file to META-file */
-+ meta_add_d_entry(dentry->d_parent,
-+ dentry->d_name.name,
-+ dentry->d_name.len);
-+ goto out;
-+ }
-+ else if(dtopd(dentry)->state == CREATED) {
-+ hidden_sto_dir = itohi2(dir);
-+ hidden_sto_dentry = dtohd2(dentry);
-+
-+ /* was: hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry);*/
-+ hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
-+#else
-+ down(&hidden_sto_dir_dentry->d_inode->i_sem);
-+#endif
-+
-+ /* Delete an old WOL file contained in the storage dir */
-+ meta_dentry = lookup_one_len(META_FILENAME,
-+ hidden_sto_dentry,
-+ strlen(META_FILENAME));
-+ if(meta_dentry->d_inode) {
-+ /* is this necessary? dget(meta_dentry); */
-+ err = vfs_unlink(hidden_sto_dentry->d_inode,
-+ meta_dentry);
-+ dput(meta_dentry);
-+ if(!err)
-+ d_delete(meta_dentry);
-+ }
-+
-+ err = vfs_rmdir(hidden_sto_dir, hidden_sto_dentry);
-+ dput(hidden_sto_dentry);
-+ if(!err)
-+ d_delete(hidden_sto_dentry);
-+
-+ /* propagate number of hard-links */
-+ dentry->d_inode->i_nlink = itohi2(dentry->d_inode)->i_nlink;
-+ dtopd(dentry)->state = NON_EXISTANT;
-+
-+ /* was: unlock_dir(hidden_sto_dir_dentry); */
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
-+#else
-+ up(&hidden_sto_dir_dentry->d_inode->i_sem);
-+#endif
-+ dput(hidden_sto_dir_dentry);
-+
-+ goto out;
-+ }
-+ else if(dtopd(dentry)->state == DEL_REWRITTEN) {
-+ hidden_sto_dir = itohi2(dir);
-+ hidden_sto_dentry = dtohd2(dentry);
-+
-+ /* was: hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry);*/
-+ hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
-+#else
-+ down(&hidden_sto_dir_dentry->d_inode->i_sem);
-+#endif
-+
-+ /* Delete an old WOL file contained in the storage dir */
-+ meta_dentry = lookup_one_len(META_FILENAME,
-+ hidden_sto_dentry,
-+ strlen(META_FILENAME));
-+ if(meta_dentry->d_inode) {
-+ /* is this necessary? dget(meta_dentry); */
-+ err = vfs_unlink(hidden_sto_dentry->d_inode,
-+ meta_dentry);
-+ dput(meta_dentry);
-+ if(!err)
-+ d_delete(meta_dentry);
-+ }
-+
-+ err = vfs_rmdir(hidden_sto_dir, hidden_sto_dentry);
-+ dput(hidden_sto_dentry);
-+ if(!err)
-+ d_delete(hidden_sto_dentry);
-+
-+ /* propagate number of hard-links */
-+ dentry->d_inode->i_nlink = itohi2(dentry->d_inode)->i_nlink;
-+ dtopd(dentry)->state = DELETED;
-+ /* was: unlock_dir(hidden_sto_dir_dentry); */
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
-+#else
-+ up(&hidden_sto_dir_dentry->d_inode->i_sem);
-+#endif
-+ dput(hidden_sto_dir_dentry);
-+ goto out;
-+ }
-+
-+ printk(KERN_CRIT "mini_fo_rmdir: ERROR, invalid state detected.\n");
-+
-+ out:
-+ if(!err) {
-+ d_drop(dentry);
-+ }
-+
-+ fist_copy_attr_times(dir, itohi2(dentry->d_parent->d_inode));
-+ dput(dentry);
-+
-+ return err;
-+}
-+
-+
-+STATIC int
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
-+mini_fo_mknod(inode_t *dir, dentry_t *dentry, int mode, dev_t dev)
-+#else
-+mini_fo_mknod(inode_t *dir, dentry_t *dentry, int mode, int dev)
-+#endif
-+{
-+ int err = 0;
-+
-+ check_mini_fo_dentry(dentry);
-+
-+ err = create_sto_nod(dentry, mode, dev);
-+ if(err) {
-+ printk(KERN_CRIT "mini_fo_mknod: creating sto nod failed.\n");
-+ err = -EINVAL;
-+ }
-+
-+ check_mini_fo_dentry(dentry);
-+ return err;
-+}
-+
-+
-+STATIC int
-+mini_fo_rename(inode_t *old_dir, dentry_t *old_dentry,
-+ inode_t *new_dir, dentry_t *new_dentry)
-+{
-+ /* dispatch */
-+ if(S_ISDIR(old_dentry->d_inode->i_mode))
-+ return rename_directory(old_dir, old_dentry, new_dir, new_dentry);
-+ return rename_nondir(old_dir, old_dentry, new_dir, new_dentry);
-+
-+}
-+
-+int rename_directory(inode_t *old_dir, dentry_t *old_dentry,
-+ inode_t *new_dir, dentry_t *new_dentry)
-+{
-+ int err, bpath_len;
-+ char *bpath;
-+
-+ dentry_t *hidden_old_dentry;
-+ dentry_t *hidden_new_dentry;
-+ dentry_t *hidden_old_dir_dentry;
-+ dentry_t *hidden_new_dir_dentry;
-+
-+ err = 0;
-+ bpath = NULL;
-+ bpath_len = 0;
-+
-+ /* this is a test, chuck out if it works */
-+ if(!(dtopd(new_dentry)->state == DELETED ||
-+ dtopd(new_dentry)->state == NON_EXISTANT)) {
-+ printk(KERN_CRIT "mini_fo: rename_directory: \
-+ uh, ah, new_dentry not negative.\n");
-+ /* return -1; */
-+ }
-+
-+ /* state = UNMODIFIED */
-+ if(dtopd(old_dentry)->state == UNMODIFIED) {
-+ err = dir_unmod_to_mod(old_dentry);
-+ if (err)
-+ goto out;
-+ }
-+
-+ /* state = MODIFIED */
-+ if(dtopd(old_dentry)->state == MODIFIED) {
-+ bpath = meta_check_r_entry(old_dentry->d_parent,
-+ old_dentry->d_name.name,
-+ old_dentry->d_name.len);
-+ if(bpath) {
-+ err = meta_remove_r_entry(old_dentry->d_parent,
-+ old_dentry->d_name.name,
-+ old_dentry->d_name.len);
-+ if(err) {
-+ printk(KERN_CRIT "mini_fo: rename_directory:\
-+ meta_remove_r_entry \
-+ failed.\n");
-+ goto out;
-+ }
-+ err = meta_add_r_entry(new_dentry->d_parent,
-+ bpath,
-+ strlen(bpath),
-+ new_dentry->d_name.name,
-+ new_dentry->d_name.len);
-+ kfree(bpath);
-+ }
-+ else {/* wol it */
-+ err = meta_add_d_entry(old_dentry->d_parent,
-+ old_dentry->d_name.name,
-+ old_dentry->d_name.len);
-+ if (err)
-+ goto out;
-+ /* put it on rename list */
-+ err = get_mini_fo_bpath(old_dentry,
-+ &bpath,
-+ &bpath_len);
-+ if (err)
-+ goto out;
-+ err = meta_add_r_entry(new_dentry->d_parent,
-+ bpath, bpath_len,
-+ new_dentry->d_name.name,
-+ new_dentry->d_name.len);
-+ if (err)
-+ goto out;
-+ }
-+ /* no state change, MODIFIED stays MODIFIED */
-+ }
-+ /* state = CREATED */
-+ if(dtopd(old_dentry)->state == CREATED ||
-+ dtopd(old_dentry)->state == DEL_REWRITTEN) {
-+ if(dtohd(old_dentry))
-+ dput(dtohd(old_dentry));
-+
-+ if(dtopd(new_dentry)->state == DELETED) {
-+ dtopd(old_dentry)->state = DEL_REWRITTEN;
-+ dtohd(old_dentry) = NULL;
-+ }
-+ else if(dtopd(new_dentry)->state == NON_EXISTANT) {
-+ dtopd(old_dentry)->state = CREATED;
-+ /* steal new dentry's neg. base dentry */
-+ dtohd(old_dentry) = dtohd(new_dentry);
-+ dtohd(new_dentry) = NULL;
-+ }
-+ }
-+ if(dtopd(new_dentry)->state == UNMODIFIED ||
-+ dtopd(new_dentry)->state == NON_EXISTANT) {
-+ err = get_neg_sto_dentry(new_dentry);
-+ if(err)
-+ goto out;
-+ }
-+
-+ /* now move sto file */
-+ hidden_old_dentry = dtohd2(old_dentry);
-+ hidden_new_dentry = dtohd2(new_dentry);
-+
-+ dget(hidden_old_dentry);
-+ dget(hidden_new_dentry);
-+
-+ hidden_old_dir_dentry = dget(hidden_old_dentry->d_parent);
-+ hidden_new_dir_dentry = dget(hidden_new_dentry->d_parent);
-+ double_lock(hidden_old_dir_dentry, hidden_new_dir_dentry);
-+
-+ err = vfs_rename(hidden_old_dir_dentry->d_inode, hidden_old_dentry,
-+ hidden_new_dir_dentry->d_inode, hidden_new_dentry);
-+ if(err)
-+ goto out_lock;
-+
-+ fist_copy_attr_all(new_dir, hidden_new_dir_dentry->d_inode);
-+ if (new_dir != old_dir)
-+ fist_copy_attr_all(old_dir,
-+ hidden_old_dir_dentry->d_inode);
-+
-+ out_lock:
-+ /* double_unlock will dput the new/old parent dentries
-+ * whose refcnts were incremented via get_parent above. */
-+ double_unlock(hidden_old_dir_dentry, hidden_new_dir_dentry);
-+ dput(hidden_new_dentry);
-+ dput(hidden_old_dentry);
-+
-+ out:
-+ return err;
-+}
-+
-+int rename_nondir(inode_t *old_dir, dentry_t *old_dentry,
-+ inode_t *new_dir, dentry_t *new_dentry)
-+{
-+ int err=0;
-+
-+ check_mini_fo_dentry(old_dentry);
-+ check_mini_fo_dentry(new_dentry);
-+ check_mini_fo_inode(old_dir);
-+ check_mini_fo_inode(new_dir);
-+
-+ /* state: UNMODIFIED */
-+ if(dtost(old_dentry) == UNMODIFIED) {
-+ err = nondir_unmod_to_mod(old_dentry, 1);
-+ if(err) {
-+ err = -EINVAL;
-+ goto out;
-+ }
-+ }
-+
-+ /* the easy states */
-+ if(exists_in_storage(old_dentry)) {
-+
-+ dentry_t *hidden_old_dentry;
-+ dentry_t *hidden_new_dentry;
-+ dentry_t *hidden_old_dir_dentry;
-+ dentry_t *hidden_new_dir_dentry;
-+
-+ /* if old file is MODIFIED, add it to the deleted_list */
-+ if(dtopd(old_dentry)->state == MODIFIED) {
-+ meta_add_d_entry(old_dentry->d_parent,
-+ old_dentry->d_name.name,
-+ old_dentry->d_name.len);
-+
-+ dput(dtohd(old_dentry));
-+ }
-+ /* if old file is CREATED, we only release the base dentry */
-+ if(dtopd(old_dentry)->state == CREATED) {
-+ if(dtohd(old_dentry))
-+ dput(dtohd(old_dentry));
-+ }
-+
-+ /* now setup the new states (depends on new_dentry state) */
-+ /* new dentry state = MODIFIED */
-+ if(dtopd(new_dentry)->state == MODIFIED) {
-+ meta_add_d_entry(new_dentry->d_parent,
-+ new_dentry->d_name.name,
-+ new_dentry->d_name.len);
-+
-+ /* new dentry will be d_put'ed later by the vfs
-+ * so don't do it here
-+ * dput(dtohd(new_dentry));
-+ */
-+ dtohd(old_dentry) = NULL;
-+ dtopd(old_dentry)->state = DEL_REWRITTEN;
-+ }
-+ /* new dentry state = UNMODIFIED */
-+ else if(dtopd(new_dentry)->state == UNMODIFIED) {
-+ if(get_neg_sto_dentry(new_dentry))
-+ return -EINVAL;
-+
-+ meta_add_d_entry(new_dentry->d_parent,
-+ new_dentry->d_name.name,
-+ new_dentry->d_name.len);
-+
-+ /* is this right??? */
-+ /*dput(dtohd(new_dentry));*/
-+ dtohd(old_dentry) = NULL;
-+ dtopd(old_dentry)->state = DEL_REWRITTEN;
-+ }
-+ /* new dentry state = CREATED */
-+ else if(dtopd(new_dentry)->state == CREATED) {
-+ /* we keep the neg. base dentry (if exists) */
-+ dtohd(old_dentry) = dtohd(new_dentry);
-+ /* ...and set it to Null, or we'll get
-+ * dcache.c:345 if it gets dput twice... */
-+ dtohd(new_dentry) = NULL;
-+ dtopd(old_dentry)->state = CREATED;
-+ }
-+ /* new dentry state = NON_EXISTANT */
-+ else if(dtopd(new_dentry)->state == NON_EXISTANT) {
-+ if(get_neg_sto_dentry(new_dentry))
-+ return -EINVAL;
-+
-+ /* we keep the neg. base dentry (if exists) */
-+ dtohd(old_dentry) = dtohd(new_dentry);
-+ /* ...and set it to Null, or we'll get
-+ * Dr. dcache.c:345 if it gets dput twice... */
-+ dtohd(new_dentry) = NULL;
-+ dtopd(old_dentry)->state = CREATED;
-+ }
-+ /* new dentry state = DEL_REWRITTEN or DELETED */
-+ else if(dtopd(new_dentry)->state == DEL_REWRITTEN ||
-+ dtopd(new_dentry)->state == DELETED) {
-+ dtohd(old_dentry) = NULL;
-+ dtopd(old_dentry)->state = DEL_REWRITTEN;
-+ }
-+ else { /* not possible, uhh, ahh */
-+ printk(KERN_CRIT
-+ "mini_fo: rename_reg_file: invalid state detected [1].\n");
-+ return -1;
-+ }
-+
-+ /* now we definitely have a sto file */
-+ hidden_old_dentry = dtohd2(old_dentry);
-+ hidden_new_dentry = dtohd2(new_dentry);
-+
-+ dget(hidden_old_dentry);
-+ dget(hidden_new_dentry);
-+
-+ hidden_old_dir_dentry = dget(hidden_old_dentry->d_parent);
-+ hidden_new_dir_dentry = dget(hidden_new_dentry->d_parent);
-+ double_lock(hidden_old_dir_dentry, hidden_new_dir_dentry);
-+
-+ err = vfs_rename(hidden_old_dir_dentry->d_inode,
-+ hidden_old_dentry,
-+ hidden_new_dir_dentry->d_inode,
-+ hidden_new_dentry);
-+ if(err)
-+ goto out_lock;
-+
-+ fist_copy_attr_all(new_dir, hidden_new_dir_dentry->d_inode);
-+ if (new_dir != old_dir)
-+ fist_copy_attr_all(old_dir, hidden_old_dir_dentry->d_inode);
-+
-+ out_lock:
-+ /* double_unlock will dput the new/old parent dentries
-+ * whose refcnts were incremented via get_parent above.
-+ */
-+ double_unlock(hidden_old_dir_dentry, hidden_new_dir_dentry);
-+ dput(hidden_new_dentry);
-+ dput(hidden_old_dentry);
-+ out:
-+ return err;
-+ }
-+ else { /* invalid state */
-+ printk(KERN_CRIT "mini_fo: rename_reg_file: ERROR: invalid state detected [2].\n");
-+ return -1;
-+ }
-+}
-+
-+
-+STATIC int
-+mini_fo_readlink(dentry_t *dentry, char *buf, int bufsiz)
-+{
-+ int err=0;
-+ dentry_t *hidden_dentry = NULL;
-+
-+ if(dtohd2(dentry) && dtohd2(dentry)->d_inode) {
-+ hidden_dentry = dtohd2(dentry);
-+ } else if(dtohd(dentry) && dtohd(dentry)->d_inode) {
-+ hidden_dentry = dtohd(dentry);
-+ } else {
-+ goto out;
-+ }
-+
-+ if (!hidden_dentry->d_inode->i_op ||
-+ !hidden_dentry->d_inode->i_op->readlink) {
-+ err = -EINVAL; goto out;
-+ }
-+
-+ err = hidden_dentry->d_inode->i_op->readlink(hidden_dentry,
-+ buf,
-+ bufsiz);
-+ if (err > 0)
-+ fist_copy_attr_atime(dentry->d_inode, hidden_dentry->d_inode);
-+
-+ out:
-+ return err;
-+}
-+
-+
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,13)
-+static int mini_fo_follow_link(dentry_t *dentry, struct nameidata *nd)
-+#else
-+static void* mini_fo_follow_link(dentry_t *dentry, struct nameidata *nd)
-+#endif
-+{
-+ char *buf;
-+ int len = PAGE_SIZE, err;
-+ mm_segment_t old_fs;
-+
-+ /* in 2.6 this is freed by mini_fo_put_link called by __do_follow_link */
-+ buf = kmalloc(len, GFP_KERNEL);
-+ if (!buf) {
-+ err = -ENOMEM;
-+ goto out;
-+ }
-+
-+ /* read the symlink, and then we will follow it */
-+ old_fs = get_fs();
-+ set_fs(KERNEL_DS);
-+ err = dentry->d_inode->i_op->readlink(dentry, buf, len);
-+ set_fs(old_fs);
-+ if (err < 0) {
-+ kfree(buf);
-+ buf = NULL;
-+ goto out;
-+ }
-+ buf[err] = 0;
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
-+ nd_set_link(nd, buf);
-+ err = 0;
-+#else
-+ err = vfs_follow_link(nd, buf);
-+#endif
-+
-+ out:
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
-+ kfree(buf);
-+#endif
-+
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,13)
-+ return err;
-+#else
-+ return ERR_PTR(err);
-+#endif
-+}
-+
-+STATIC
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,13)
-+void mini_fo_put_link(struct dentry *dentry, struct nameidata *nd)
-+#else
-+void mini_fo_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
-+#endif
-+{
-+ char *link;
-+ link = nd_get_link(nd);
-+ kfree(link);
-+}
-+#endif
-+
-+STATIC int
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
-+mini_fo_permission(inode_t *inode, int mask, struct nameidata *nd)
-+#else
-+mini_fo_permission(inode_t *inode, int mask)
-+#endif
-+{
-+ inode_t *hidden_inode;
-+ int mode;
-+ int err;
-+
-+ if(itohi2(inode)) {
-+ hidden_inode = itohi2(inode);
-+ } else {
-+ hidden_inode = itohi(inode);
-+ }
-+ mode = inode->i_mode;
-+
-+ /* not really needed, as permission handles everything:
-+ * err = vfs_permission(inode, mask);
-+ * if (err)
-+ * goto out;
-+ */
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
-+ err = permission(hidden_inode, mask, nd);
-+#else
-+ err = permission(hidden_inode, mask);
-+#endif
-+
-+ /* out: */
-+ return err;
-+}
-+
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
-+STATIC int
-+mini_fo_inode_revalidate(dentry_t *dentry)
-+{
-+ int err = 0;
-+ dentry_t *hidden_dentry;
-+ inode_t *hidden_inode;
-+
-+ ASSERT(dentry->d_inode);
-+ ASSERT(itopd(dentry->d_inode));
-+
-+ if(itohi2(dentry->d_inode)) {
-+ hidden_dentry = dtohd2(dentry);
-+ hidden_inode = hidden_dentry->d_inode;
-+ } else if(itohi(dentry->d_inode)) {
-+ hidden_dentry = dtohd(dentry);
-+ hidden_inode = hidden_dentry->d_inode;
-+ } else {
-+ printk(KERN_CRIT "mini_fo_inode_revalidate: ERROR, invalid state detected.\n");
-+ err = -ENOENT;
-+ goto out;
-+ }
-+ if (hidden_inode && hidden_inode->i_op && hidden_inode->i_op->revalidate){
-+ err = hidden_inode->i_op->revalidate(hidden_dentry);
-+ if (err)
-+ goto out;
-+ }
-+ fist_copy_attr_all(dentry->d_inode, hidden_inode);
-+ out:
-+ return err;
-+}
-+#endif
-+
-+STATIC int
-+mini_fo_setattr(dentry_t *dentry, struct iattr *ia)
-+{
-+ int err = 0;
-+
-+ check_mini_fo_dentry(dentry);
-+
-+ if(!is_mini_fo_existant(dentry)) {
-+ printk(KERN_CRIT "mini_fo_setattr: ERROR, invalid state detected [1].\n");
-+ goto out;
-+ }
-+
-+ if(dtost(dentry) == UNMODIFIED) {
-+ if(!IS_COPY_FLAG(ia->ia_valid))
-+ goto out; /* we ignore these changes to base */
-+
-+ if(S_ISDIR(dentry->d_inode->i_mode)) {
-+ err = dir_unmod_to_mod(dentry);
-+ } else {
-+ /* we copy contents if file is not beeing truncated */
-+ if(S_ISREG(dentry->d_inode->i_mode) &&
-+ !(ia->ia_size == 0 && (ia->ia_valid & ATTR_SIZE))) {
-+ err = nondir_unmod_to_mod(dentry, 1);
-+ } else
-+ err = nondir_unmod_to_mod(dentry, 0);
-+ }
-+ if(err) {
-+ err = -EINVAL;
-+ printk(KERN_CRIT "mini_fo_setattr: ERROR changing states.\n");
-+ goto out;
-+ }
-+ }
-+ if(!exists_in_storage(dentry)) {
-+ printk(KERN_CRIT "mini_fo_setattr: ERROR, invalid state detected [2].\n");
-+ err = -EINVAL;
-+ goto out;
-+ }
-+ ASSERT(dentry->d_inode);
-+ ASSERT(dtohd2(dentry));
-+ ASSERT(itopd(dentry->d_inode));
-+ ASSERT(itohi2(dentry->d_inode));
-+
-+ err = notify_change(dtohd2(dentry), ia);
-+ fist_copy_attr_all(dentry->d_inode, itohi2(dentry->d_inode));
-+ out:
-+ return err;
-+}
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
-+STATIC int
-+mini_fo_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
-+{
-+ int err = 0;
-+ dentry_t *hidden_dentry;
-+
-+ ASSERT(dentry->d_inode);
-+ ASSERT(itopd(dentry->d_inode));
-+
-+ if(itohi2(dentry->d_inode)) {
-+ hidden_dentry = dtohd2(dentry);
-+ } else if(itohi(dentry->d_inode)) {
-+ hidden_dentry = dtohd(dentry);
-+ } else {
-+ printk(KERN_CRIT "mini_fo_getattr: ERROR, invalid state detected.\n");
-+ err = -ENOENT;
-+ goto out;
-+ }
-+ fist_copy_attr_all(dentry->d_inode, hidden_dentry->d_inode);
-+
-+ ASSERT(hidden_dentry);
-+ ASSERT(hidden_dentry->d_inode);
-+ ASSERT(hidden_dentry->d_inode->i_op);
-+
-+ generic_fillattr(dentry->d_inode, stat);
-+ if (!stat->blksize) {
-+ struct super_block *s = hidden_dentry->d_inode->i_sb;
-+ unsigned blocks;
-+ blocks = (stat->size+s->s_blocksize-1) >> s->s_blocksize_bits;
-+ stat->blocks = (s->s_blocksize / 512) * blocks;
-+ stat->blksize = s->s_blocksize;
-+ }
-+ out:
-+ return err;
-+}
-+#endif
-+
-+#if defined(XATTR) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20))
-+#if 0 /* no xattr_alloc() and xattr_free() */
-+/* This is lifted from fs/xattr.c */
-+static void *
-+xattr_alloc(size_t size, size_t limit)
-+{
-+ void *ptr;
-+
-+ if (size > limit)
-+ return ERR_PTR(-E2BIG);
-+
-+ if (!size) /* size request, no buffer is needed */
-+ return NULL;
-+ else if (size <= PAGE_SIZE)
-+ ptr = kmalloc((unsigned long) size, GFP_KERNEL);
-+ else
-+ ptr = vmalloc((unsigned long) size);
-+ if (!ptr)
-+ return ERR_PTR(-ENOMEM);
-+ return ptr;
-+}
-+
-+static void
-+xattr_free(void *ptr, size_t size)
-+{
-+ if (!size) /* size request, no buffer was needed */
-+ return;
-+ else if (size <= PAGE_SIZE)
-+ kfree(ptr);
-+ else
-+ vfree(ptr);
-+}
-+#endif /* no xattr_alloc() and xattr_free() */
-+
-+/* BKL held by caller.
-+ * dentry->d_inode->i_sem down
-+ */
-+STATIC int
-+mini_fo_getxattr(struct dentry *dentry, const char *name, void *value, size_t size) {
-+ struct dentry *hidden_dentry = NULL;
-+ int err = -EOPNOTSUPP;
-+ /* Define these anyway so we don't need as much ifdef'ed code. */
-+ char *encoded_name = NULL;
-+ char *encoded_value = NULL;
-+
-+ check_mini_fo_dentry(dentry);
-+
-+ if(exists_in_storage(dentry))
-+ hidden_dentry = dtohd2(dentry);
-+ else
-+ hidden_dentry = dtohd(dentry);
-+
-+ ASSERT(hidden_dentry);
-+ ASSERT(hidden_dentry->d_inode);
-+ ASSERT(hidden_dentry->d_inode->i_op);
-+
-+ if (hidden_dentry->d_inode->i_op->getxattr) {
-+ encoded_name = (char *)name;
-+ encoded_value = (char *)value;
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_lock(&hidden_dentry->d_inode->i_mutex);
-+#else
-+ down(&hidden_dentry->d_inode->i_sem);
-+#endif
-+ /* lock_kernel() already done by caller. */
-+ err = hidden_dentry->d_inode->i_op->getxattr(hidden_dentry, encoded_name, encoded_value, size);
-+ /* unlock_kernel() will be done by caller. */
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_lock(&hidden_dentry->d_inode->i_mutex);
-+#else
-+ up(&hidden_dentry->d_inode->i_sem);
-+#endif
-+ }
-+ return err;
-+}
-+
-+/* BKL held by caller.
-+ * dentry->d_inode->i_sem down
-+ */
-+STATIC int
-+#if ((LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,21) \
-+ && LINUX_VERSION_CODE <= KERNEL_VERSION(2,4,23)) \
-+ || LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
-+mini_fo_setxattr(struct dentry *dentry, const char *name,
-+ const void *value, size_t size, int flags)
-+#else
-+mini_fo_setxattr(struct dentry *dentry, const char *name,
-+ void *value, size_t size, int flags)
-+#endif
-+
-+{
-+ struct dentry *hidden_dentry = NULL;
-+ int err = -EOPNOTSUPP;
-+
-+ /* Define these anyway, so we don't have as much ifdef'ed code. */
-+ char *encoded_value = NULL;
-+ char *encoded_name = NULL;
-+
-+ check_mini_fo_dentry(dentry);
-+
-+ if(exists_in_storage(dentry))
-+ hidden_dentry = dtohd2(dentry);
-+ else
-+ hidden_dentry = dtohd(dentry);
-+
-+ ASSERT(hidden_dentry);
-+ ASSERT(hidden_dentry->d_inode);
-+ ASSERT(hidden_dentry->d_inode->i_op);
-+
-+ if (hidden_dentry->d_inode->i_op->setxattr) {
-+ encoded_name = (char *)name;
-+ encoded_value = (char *)value;
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_lock(&hidden_dentry->d_inode->i_mutex);
-+#else
-+ down(&hidden_dentry->d_inode->i_sem);
-+#endif
-+ /* lock_kernel() already done by caller. */
-+ err = hidden_dentry->d_inode->i_op->setxattr(hidden_dentry, encoded_name, encoded_value, size, flags);
-+ /* unlock_kernel() will be done by caller. */
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_unlock(&hidden_dentry->d_inode->i_mutex);
-+#else
-+ up(&hidden_dentry->d_inode->i_sem);
-+#endif
-+ }
-+ return err;
-+}
-+
-+/* BKL held by caller.
-+ * dentry->d_inode->i_sem down
-+ */
-+STATIC int
-+mini_fo_removexattr(struct dentry *dentry, const char *name) {
-+ struct dentry *hidden_dentry = NULL;
-+ int err = -EOPNOTSUPP;
-+ char *encoded_name;
-+
-+ check_mini_fo_dentry(dentry);
-+
-+ if(exists_in_storage(dentry))
-+ hidden_dentry = dtohd2(dentry);
-+ else
-+ hidden_dentry = dtohd(dentry);
-+
-+ ASSERT(hidden_dentry);
-+ ASSERT(hidden_dentry->d_inode);
-+ ASSERT(hidden_dentry->d_inode->i_op);
-+
-+ if (hidden_dentry->d_inode->i_op->removexattr) {
-+ encoded_name = (char *)name;
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_lock(&hidden_dentry->d_inode->i_mutex);
-+#else
-+ down(&hidden_dentry->d_inode->i_sem);
-+#endif
-+ /* lock_kernel() already done by caller. */
-+ err = hidden_dentry->d_inode->i_op->removexattr(hidden_dentry, encoded_name);
-+ /* unlock_kernel() will be done by caller. */
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_unlock(&hidden_dentry->d_inode->i_mutex);
-+#else
-+ up(&hidden_dentry->d_inode->i_sem);
-+#endif
-+ }
-+ return err;
-+}
-+
-+/* BKL held by caller.
-+ * dentry->d_inode->i_sem down
-+ */
-+STATIC int
-+mini_fo_listxattr(struct dentry *dentry, char *list, size_t size) {
-+ struct dentry *hidden_dentry = NULL;
-+ int err = -EOPNOTSUPP;
-+ char *encoded_list = NULL;
-+
-+ check_mini_fo_dentry(dentry);
-+
-+ if(exists_in_storage(dentry))
-+ hidden_dentry = dtohd2(dentry);
-+ else
-+ hidden_dentry = dtohd(dentry);
-+
-+ ASSERT(hidden_dentry);
-+ ASSERT(hidden_dentry->d_inode);
-+ ASSERT(hidden_dentry->d_inode->i_op);
-+
-+ if (hidden_dentry->d_inode->i_op->listxattr) {
-+ encoded_list = list;
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_lock(&hidden_dentry->d_inode->i_mutex);
-+#else
-+ down(&hidden_dentry->d_inode->i_sem);
-+#endif
-+ /* lock_kernel() already done by caller. */
-+ err = hidden_dentry->d_inode->i_op->listxattr(hidden_dentry, encoded_list, size);
-+ /* unlock_kernel() will be done by caller. */
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_unlock(&hidden_dentry->d_inode->i_mutex);
-+#else
-+ up(&hidden_dentry->d_inode->i_sem);
-+#endif
-+ }
-+ return err;
-+}
-+# endif /* defined(XATTR) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20)) */
-+
-+struct inode_operations mini_fo_symlink_iops =
-+ {
-+ readlink: mini_fo_readlink,
-+ follow_link: mini_fo_follow_link,
-+ /* mk: permission: mini_fo_permission, */
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
-+ revalidate: mini_fo_inode_revalidate,
-+#endif
-+ setattr: mini_fo_setattr,
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
-+ getattr: mini_fo_getattr,
-+ put_link: mini_fo_put_link,
-+#endif
-+
-+#if defined(XATTR) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20))
-+ setxattr: mini_fo_setxattr,
-+ getxattr: mini_fo_getxattr,
-+ listxattr: mini_fo_listxattr,
-+ removexattr: mini_fo_removexattr
-+# endif /* defined(XATTR) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20)) */
-+ };
-+
-+struct inode_operations mini_fo_dir_iops =
-+ {
-+ create: mini_fo_create,
-+ lookup: mini_fo_lookup,
-+ link: mini_fo_link,
-+ unlink: mini_fo_unlink,
-+ symlink: mini_fo_symlink,
-+ mkdir: mini_fo_mkdir,
-+ rmdir: mini_fo_rmdir,
-+ mknod: mini_fo_mknod,
-+ rename: mini_fo_rename,
-+ /* no readlink/follow_link for non-symlinks */
-+ // off because we have setattr
-+ // truncate: mini_fo_truncate,
-+ /* mk:permission: mini_fo_permission, */
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
-+ revalidate: mini_fo_inode_revalidate,
-+#endif
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
-+ getattr: mini_fo_getattr,
-+#endif
-+ setattr: mini_fo_setattr,
-+#if defined(XATTR) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20))
-+ setxattr: mini_fo_setxattr,
-+ getxattr: mini_fo_getxattr,
-+ listxattr: mini_fo_listxattr,
-+ removexattr: mini_fo_removexattr
-+# endif /* XATTR && LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20) */
-+ };
-+
-+struct inode_operations mini_fo_main_iops =
-+ {
-+ /* permission: mini_fo_permission, */
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
-+ revalidate: mini_fo_inode_revalidate,
-+#endif
-+ setattr: mini_fo_setattr,
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
-+ getattr: mini_fo_getattr,
-+#endif
-+#if defined(XATTR) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20))
-+ setxattr: mini_fo_setxattr,
-+ getxattr: mini_fo_getxattr,
-+ listxattr: mini_fo_listxattr,
-+ removexattr: mini_fo_removexattr
-+# endif /* XATTR && LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20) */
-+ };
---- /dev/null
-+++ b/fs/mini_fo/main.c
-@@ -0,0 +1,423 @@
-+/*
-+ * Copyright (c) 1997-2003 Erez Zadok
-+ * Copyright (c) 2001-2003 Stony Brook University
-+ *
-+ * For specific licensing information, see the COPYING file distributed with
-+ * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
-+ *
-+ * This Copyright notice must be kept intact and distributed with all
-+ * fistgen sources INCLUDING sources generated by fistgen.
-+ */
-+/*
-+ * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
-+ *
-+ * 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.
-+ */
-+
-+/*
-+ * $Id$
-+ */
-+
-+#ifdef HAVE_CONFIG_H
-+# include <config.h>
-+#endif
-+
-+#include "fist.h"
-+#include "mini_fo.h"
-+#include <linux/module.h>
-+
-+/* This definition must only appear after we include <linux/module.h> */
-+#ifndef MODULE_LICENSE
-+# define MODULE_LICENSE(bison)
-+#endif /* not MODULE_LICENSE */
-+
-+/*
-+ * This is the mini_fo tri interpose function, which extends the
-+ * functionality of the regular interpose by interposing a higher
-+ * level inode on top of two lower level ones: the base filesystem
-+ * inode and the storage filesystem inode.
-+ *
-+ * sb we pass is mini_fo's super_block
-+ */
-+int
-+mini_fo_tri_interpose(dentry_t *hidden_dentry,
-+ dentry_t *hidden_sto_dentry,
-+ dentry_t *dentry, super_block_t *sb, int flag)
-+{
-+ inode_t *hidden_inode = NULL;
-+ inode_t *hidden_sto_inode = NULL; /* store corresponding storage inode */
-+ int err = 0;
-+ inode_t *inode;
-+
-+ /* Pointer to hidden_sto_inode if exists, else to hidden_inode.
-+ * This is used to copy the attributes of the correct inode. */
-+ inode_t *master_inode;
-+
-+ if(hidden_dentry)
-+ hidden_inode = hidden_dentry->d_inode;
-+ if(hidden_sto_dentry)
-+ hidden_sto_inode = hidden_sto_dentry->d_inode;
-+
-+ ASSERT(dentry->d_inode == NULL);
-+
-+ /* mk: One of the inodes associated with the dentrys is likely to
-+ * be NULL, so carefull:
-+ */
-+ ASSERT((hidden_inode != NULL) || (hidden_sto_inode != NULL));
-+
-+ if(hidden_sto_inode)
-+ master_inode = hidden_sto_inode;
-+ else
-+ master_inode = hidden_inode;
-+
-+ /*
-+ * We allocate our new inode below, by calling iget.
-+ * iget will call our read_inode which will initialize some
-+ * of the new inode's fields
-+ */
-+
-+ /*
-+ * original: inode = iget(sb, hidden_inode->i_ino);
-+ */
-+ inode = iget(sb, iunique(sb, 25));
-+ if (!inode) {
-+ err = -EACCES; /* should be impossible??? */
-+ goto out;
-+ }
-+
-+ /*
-+ * interpose the inode if not already interposed
-+ * this is possible if the inode is being reused
-+ * XXX: what happens if we get_empty_inode() but there's another already?
-+ * for now, ASSERT() that this can't happen; fix later.
-+ */
-+ if (itohi(inode) != NULL) {
-+ printk(KERN_CRIT "mini_fo_tri_interpose: itohi(inode) != NULL.\n");
-+ }
-+ if (itohi2(inode) != NULL) {
-+ printk(KERN_CRIT "mini_fo_tri_interpose: itohi2(inode) != NULL.\n");
-+ }
-+
-+ /* mk: Carefull, igrab can't handle NULL inodes (ok, why should it?), so
-+ * we need to check here:
-+ */
-+ if(hidden_inode)
-+ itohi(inode) = igrab(hidden_inode);
-+ else
-+ itohi(inode) = NULL;
-+
-+ if(hidden_sto_inode)
-+ itohi2(inode) = igrab(hidden_sto_inode);
-+ else
-+ itohi2(inode) = NULL;
-+
-+
-+ /* Use different set of inode ops for symlinks & directories*/
-+ if (S_ISLNK(master_inode->i_mode))
-+ inode->i_op = &mini_fo_symlink_iops;
-+ else if (S_ISDIR(master_inode->i_mode))
-+ inode->i_op = &mini_fo_dir_iops;
-+
-+ /* Use different set of file ops for directories */
-+ if (S_ISDIR(master_inode->i_mode))
-+ inode->i_fop = &mini_fo_dir_fops;
-+
-+ /* properly initialize special inodes */
-+ if (S_ISBLK(master_inode->i_mode) || S_ISCHR(master_inode->i_mode) ||
-+ S_ISFIFO(master_inode->i_mode) || S_ISSOCK(master_inode->i_mode)) {
-+ init_special_inode(inode, master_inode->i_mode, master_inode->i_rdev);
-+ }
-+
-+ /* Fix our inode's address operations to that of the lower inode */
-+ if (inode->i_mapping->a_ops != master_inode->i_mapping->a_ops) {
-+ inode->i_mapping->a_ops = master_inode->i_mapping->a_ops;
-+ }
-+
-+ /* only (our) lookup wants to do a d_add */
-+ if (flag)
-+ d_add(dentry, inode);
-+ else
-+ d_instantiate(dentry, inode);
-+
-+ ASSERT(dtopd(dentry) != NULL);
-+
-+ /* all well, copy inode attributes */
-+ fist_copy_attr_all(inode, master_inode);
-+
-+ out:
-+ return err;
-+}
-+
-+/* parse mount options "base=" and "sto=" */
-+dentry_t *
-+mini_fo_parse_options(super_block_t *sb, char *options)
-+{
-+ dentry_t *hidden_root = ERR_PTR(-EINVAL);
-+ dentry_t *hidden_root2 = ERR_PTR(-EINVAL);
-+ struct nameidata nd, nd2;
-+ char *name, *tmp, *end;
-+ int err = 0;
-+
-+ /* We don't want to go off the end of our arguments later on. */
-+ for (end = options; *end; end++);
-+
-+ while (options < end) {
-+ tmp = options;
-+ while (*tmp && *tmp != ',')
-+ tmp++;
-+ *tmp = '\0';
-+ if (!strncmp("base=", options, 5)) {
-+ name = options + 5;
-+ printk(KERN_INFO "mini_fo: using base directory: %s\n", name);
-+
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
-+ if (path_init(name, LOOKUP_FOLLOW, &nd))
-+ err = path_walk(name, &nd);
-+#else
-+ err = path_lookup(name, LOOKUP_FOLLOW, &nd);
-+#endif
-+ if (err) {
-+ printk(KERN_CRIT "mini_fo: error accessing hidden directory '%s'\n", name);
-+ hidden_root = ERR_PTR(err);
-+ goto out;
-+ }
-+ hidden_root = nd.dentry;
-+ stopd(sb)->base_dir_dentry = nd.dentry;
-+ stopd(sb)->hidden_mnt = nd.mnt;
-+
-+ } else if(!strncmp("sto=", options, 4)) {
-+ /* parse the storage dir */
-+ name = options + 4;
-+ printk(KERN_INFO "mini_fo: using storage directory: %s\n", name);
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
-+ if(path_init(name, LOOKUP_FOLLOW, &nd2))
-+ err = path_walk(name, &nd2);
-+#else
-+ err = path_lookup(name, LOOKUP_FOLLOW, &nd2);
-+#endif
-+ if(err) {
-+ printk(KERN_CRIT "mini_fo: error accessing hidden storage directory '%s'\n", name);
-+
-+ hidden_root2 = ERR_PTR(err);
-+ goto out;
-+ }
-+ hidden_root2 = nd2.dentry;
-+ stopd(sb)->storage_dir_dentry = nd2.dentry;
-+ stopd(sb)->hidden_mnt2 = nd2.mnt;
-+ stohs2(sb) = hidden_root2->d_sb;
-+
-+ /* validate storage dir, this is done in
-+ * mini_fo_read_super for the base directory.
-+ */
-+ if (IS_ERR(hidden_root2)) {
-+ printk(KERN_WARNING "mini_fo_parse_options: storage dentry lookup failed (err = %ld)\n", PTR_ERR(hidden_root2));
-+ goto out;
-+ }
-+ if (!hidden_root2->d_inode) {
-+ printk(KERN_WARNING "mini_fo_parse_options: no storage dir to interpose on.\n");
-+ goto out;
-+ }
-+ stohs2(sb) = hidden_root2->d_sb;
-+ } else {
-+ printk(KERN_WARNING "mini_fo: unrecognized option '%s'\n", options);
-+ hidden_root = ERR_PTR(-EINVAL);
-+ goto out;
-+ }
-+ options = tmp + 1;
-+ }
-+
-+ out:
-+ if(IS_ERR(hidden_root2))
-+ return hidden_root2;
-+ return hidden_root;
-+}
-+
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
-+static int
-+#else
-+super_block_t *
-+#endif
-+mini_fo_read_super(super_block_t *sb, void *raw_data, int silent)
-+{
-+ dentry_t *hidden_root;
-+ int err = 0;
-+
-+ if (!raw_data) {
-+ printk(KERN_WARNING "mini_fo_read_super: missing argument\n");
-+ err = -EINVAL;
-+ goto out;
-+ }
-+ /*
-+ * Allocate superblock private data
-+ */
-+ __stopd(sb) = kmalloc(sizeof(struct mini_fo_sb_info), GFP_KERNEL);
-+ if (!stopd(sb)) {
-+ printk(KERN_WARNING "%s: out of memory\n", __FUNCTION__);
-+ err = -ENOMEM;
-+ goto out;
-+ }
-+ stohs(sb) = NULL;
-+
-+ hidden_root = mini_fo_parse_options(sb, raw_data);
-+ if (IS_ERR(hidden_root)) {
-+ printk(KERN_WARNING "mini_fo_read_super: lookup_dentry failed (err = %ld)\n", PTR_ERR(hidden_root));
-+ err = PTR_ERR(hidden_root);
-+ goto out_free;
-+ }
-+ if (!hidden_root->d_inode) {
-+ printk(KERN_WARNING "mini_fo_read_super: no directory to interpose on\n");
-+ goto out_free;
-+ }
-+ stohs(sb) = hidden_root->d_sb;
-+
-+ /*
-+ * Linux 2.4.2-ac3 and beyond has code in
-+ * mm/filemap.c:generic_file_write() that requires sb->s_maxbytes
-+ * to be populated. If not set, all write()s under that sb will
-+ * return 0.
-+ *
-+ * Linux 2.4.4+ automatically sets s_maxbytes to MAX_NON_LFS;
-+ * the filesystem should override it only if it supports LFS.
-+ */
-+ /* non-SCA code is good to go with LFS */
-+ sb->s_maxbytes = hidden_root->d_sb->s_maxbytes;
-+
-+ sb->s_op = &mini_fo_sops;
-+ /*
-+ * we can't use d_alloc_root if we want to use
-+ * our own interpose function unchanged,
-+ * so we simply replicate *most* of the code in d_alloc_root here
-+ */
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
-+ sb->s_root = d_alloc(NULL, &(const struct qstr) { "/", 1, 0 });
-+#else
-+ sb->s_root = d_alloc(NULL, &(const struct qstr){hash: 0, name: "/", len : 1});
-+#endif
-+ if (IS_ERR(sb->s_root)) {
-+ printk(KERN_WARNING "mini_fo_read_super: d_alloc failed\n");
-+ err = -ENOMEM;
-+ goto out_dput;
-+ }
-+
-+ sb->s_root->d_op = &mini_fo_dops;
-+ sb->s_root->d_sb = sb;
-+ sb->s_root->d_parent = sb->s_root;
-+
-+ /* link the upper and lower dentries */
-+ __dtopd(sb->s_root) = (struct mini_fo_dentry_info *)
-+ kmalloc(sizeof(struct mini_fo_dentry_info), GFP_KERNEL);
-+ if (!dtopd(sb->s_root)) {
-+ err = -ENOMEM;
-+ goto out_dput2;
-+ }
-+ dtopd(sb->s_root)->state = MODIFIED;
-+ dtohd(sb->s_root) = hidden_root;
-+
-+ /* fanout relevant, interpose on storage root dentry too */
-+ dtohd2(sb->s_root) = stopd(sb)->storage_dir_dentry;
-+
-+ /* ...and call tri-interpose to interpose root dir inodes
-+ * if (mini_fo_interpose(hidden_root, sb->s_root, sb, 0))
-+ */
-+ if(mini_fo_tri_interpose(hidden_root, dtohd2(sb->s_root), sb->s_root, sb, 0))
-+ goto out_dput2;
-+
-+ /* initalize the wol list */
-+ itopd(sb->s_root->d_inode)->deleted_list_size = -1;
-+ itopd(sb->s_root->d_inode)->renamed_list_size = -1;
-+ meta_build_lists(sb->s_root);
-+
-+ goto out;
-+
-+ out_dput2:
-+ dput(sb->s_root);
-+ out_dput:
-+ dput(hidden_root);
-+ dput(dtohd2(sb->s_root)); /* release the hidden_sto_dentry too */
-+ out_free:
-+ kfree(stopd(sb));
-+ __stopd(sb) = NULL;
-+ out:
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
-+ return err;
-+#else
-+ if (err) {
-+ return ERR_PTR(err);
-+ } else {
-+ return sb;
-+ }
-+#endif
-+}
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
-+static int mini_fo_get_sb(struct file_system_type *fs_type,
-+ int flags, const char *dev_name,
-+ void *raw_data, struct vfsmount *mnt)
-+{
-+ return get_sb_nodev(fs_type, flags, raw_data, mini_fo_read_super, mnt);
-+}
-+#else
-+static struct super_block *mini_fo_get_sb(struct file_system_type *fs_type,
-+ int flags, const char *dev_name,
-+ void *raw_data)
-+{
-+ return get_sb_nodev(fs_type, flags, raw_data, mini_fo_read_super);
-+}
-+#endif
-+
-+void mini_fo_kill_block_super(struct super_block *sb)
-+{
-+ generic_shutdown_super(sb);
-+ /*
-+ * XXX: BUG: Halcrow: Things get unstable sometime after this point:
-+ * lib/rwsem-spinlock.c:127: spin_is_locked on uninitialized
-+ * fs/fs-writeback.c:402: spin_lock(fs/super.c:a0381828) already
-+ * locked by fs/fs-writeback.c/402
-+ *
-+ * Apparently, someone's not releasing a lock on sb_lock...
-+ */
-+}
-+
-+static struct file_system_type mini_fo_fs_type = {
-+ .owner = THIS_MODULE,
-+ .name = "mini_fo",
-+ .get_sb = mini_fo_get_sb,
-+ .kill_sb = mini_fo_kill_block_super,
-+ .fs_flags = 0,
-+};
-+
-+
-+#else
-+static DECLARE_FSTYPE(mini_fo_fs_type, "mini_fo", mini_fo_read_super, 0);
-+#endif
-+
-+static int __init init_mini_fo_fs(void)
-+{
-+ printk("Registering mini_fo version $Id$\n");
-+ return register_filesystem(&mini_fo_fs_type);
-+}
-+static void __exit exit_mini_fo_fs(void)
-+{
-+ printk("Unregistering mini_fo version $Id$\n");
-+ unregister_filesystem(&mini_fo_fs_type);
-+}
-+
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
-+EXPORT_NO_SYMBOLS;
-+#endif
-+
-+MODULE_AUTHOR("Erez Zadok <ezk@cs.sunysb.edu>");
-+MODULE_DESCRIPTION("FiST-generated mini_fo filesystem");
-+MODULE_LICENSE("GPL");
-+
-+/* MODULE_PARM(fist_debug_var, "i"); */
-+/* MODULE_PARM_DESC(fist_debug_var, "Debug level"); */
-+
-+module_init(init_mini_fo_fs)
-+module_exit(exit_mini_fo_fs)
---- /dev/null
-+++ b/fs/mini_fo/Makefile
-@@ -0,0 +1,17 @@
-+#
-+# Makefile for mini_fo 2.4 and 2.6 Linux kernels
-+#
-+# Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
-+#
-+# 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.
-+#
-+
-+obj-$(CONFIG_MINI_FO) := mini_fo.o
-+mini_fo-objs := meta.o dentry.o file.o inode.o main.o super.o state.o aux.o
-+
-+# dependencies
-+${mini_fo-objs}: mini_fo.h fist.h
-+
---- /dev/null
-+++ b/fs/mini_fo/meta.c
-@@ -0,0 +1,1000 @@
-+/*
-+ * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
-+ *
-+ * 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.
-+ */
-+
-+#ifdef HAVE_CONFIG_H
-+# include <config.h>
-+#endif /* HAVE_CONFIG_H */
-+#include "fist.h"
-+#include "mini_fo.h"
-+
-+int meta_build_lists(dentry_t *dentry)
-+{
-+ struct mini_fo_inode_info *inode_info;
-+
-+ dentry_t *meta_dentry = 0;
-+ file_t *meta_file = 0;
-+ mm_segment_t old_fs;
-+ void *buf;
-+
-+ int bytes, len;
-+ struct vfsmount *meta_mnt;
-+ char *entry;
-+
-+ inode_info = itopd(dentry->d_inode);
-+ if(!(inode_info->deleted_list_size == -1 &&
-+ inode_info->renamed_list_size == -1)) {
-+ printk(KERN_CRIT "mini_fo: meta_build_lists: \
-+ Error, list(s) not virgin.\n");
-+ return -1;
-+ }
-+
-+ /* init our meta lists */
-+ INIT_LIST_HEAD(&inode_info->deleted_list);
-+ inode_info->deleted_list_size = 0;
-+
-+ INIT_LIST_HEAD(&inode_info->renamed_list);
-+ inode_info->renamed_list_size = 0;
-+
-+ /* might there be a META-file? */
-+ if(dtohd2(dentry) && dtohd2(dentry)->d_inode) {
-+ meta_dentry = lookup_one_len(META_FILENAME,
-+ dtohd2(dentry),
-+ strlen(META_FILENAME));
-+ if(!meta_dentry->d_inode) {
-+ dput(meta_dentry);
-+ goto out_ok;
-+ }
-+ /* $%& err, is this correct? */
-+ meta_mnt = stopd(dentry->d_inode->i_sb)->hidden_mnt2;
-+ mntget(meta_mnt);
-+
-+
-+ /* open META-file for reading */
-+ meta_file = dentry_open(meta_dentry, meta_mnt, 0x0);
-+ if(!meta_file || IS_ERR(meta_file)) {
-+ printk(KERN_CRIT "mini_fo: meta_build_lists: \
-+ ERROR opening META file.\n");
-+ goto out_err;
-+ }
-+
-+ /* check if fs supports reading */
-+ if(!meta_file->f_op->read) {
-+ printk(KERN_CRIT "mini_fo: meta_build_lists: \
-+ ERROR, fs does not support reading.\n");
-+ goto out_err_close;
-+ }
-+
-+ /* allocate a page for transfering the data */
-+ buf = (void *) __get_free_page(GFP_KERNEL);
-+ if(!buf) {
-+ printk(KERN_CRIT "mini_fo: meta_build_lists: \
-+ ERROR, out of mem.\n");
-+ goto out_err_close;
-+ }
-+ meta_file->f_pos = 0;
-+ old_fs = get_fs();
-+ set_fs(KERNEL_DS);
-+ do {
-+ char *c;
-+ bytes = meta_file->f_op->read(meta_file, buf, PAGE_SIZE, &meta_file->f_pos);
-+ if(bytes == PAGE_SIZE) {
-+ /* trim a cut off filename and adjust f_pos to get it next time */
-+ for(c = (char*) buf+PAGE_SIZE;
-+ *c != '\n';
-+ c--, bytes--, meta_file->f_pos--);
-+ }
-+ entry = (char *) buf;
-+ while(entry < (char *) buf+bytes) {
-+
-+ char *old_path;
-+ char *dir_name;
-+ int old_len, new_len;
-+
-+ /* len without '\n'*/
-+ len = (int) (strchr(entry, '\n') - entry);
-+ switch (*entry) {
-+ case 'D':
-+ /* format: "D filename" */
-+ meta_list_add_d_entry(dentry,
-+ entry+2,
-+ len-2);
-+ break;
-+ case 'R':
-+ /* format: "R path/xy/dir newDir" */
-+ old_path = entry+2;
-+ dir_name = strchr(old_path, ' ') + 1;
-+ old_len = dir_name - old_path - 1;
-+ new_len = ((int) entry) + len - ((int ) dir_name);
-+ meta_list_add_r_entry(dentry,
-+ old_path,
-+ old_len,
-+ dir_name,
-+ new_len);
-+ break;
-+ default:
-+ /* unknown entry type detected */
-+ break;
-+ }
-+ entry += len+1;
-+ }
-+
-+ } while(meta_file->f_pos < meta_dentry->d_inode->i_size);
-+
-+ free_page((unsigned long) buf);
-+ set_fs(old_fs);
-+ fput(meta_file);
-+ }
-+ goto out_ok;
-+
-+ out_err_close:
-+ fput(meta_file);
-+ out_err:
-+ mntput(meta_mnt);
-+ dput(meta_dentry);
-+ return -1;
-+ out_ok:
-+ return 1; /* check this!!! inode_info->wol_size; */
-+}
-+
-+/* cleanups up all lists and free's the mem by dentry */
-+int meta_put_lists(dentry_t *dentry)
-+{
-+ if(!dentry || !dentry->d_inode) {
-+ printk("mini_fo: meta_put_lists: invalid dentry passed.\n");
-+ return -1;
-+ }
-+ return __meta_put_lists(dentry->d_inode);
-+}
-+
-+/* cleanups up all lists and free's the mem by inode */
-+int __meta_put_lists(inode_t *inode)
-+{
-+ int err = 0;
-+ if(!inode || !itopd(inode)) {
-+ printk("mini_fo: __meta_put_lists: invalid inode passed.\n");
-+ return -1;
-+ }
-+ err = __meta_put_d_list(inode);
-+ err |= __meta_put_r_list(inode);
-+ return err;
-+}
-+
-+int meta_sync_lists(dentry_t *dentry)
-+{
-+ int err = 0;
-+ if(!dentry || !dentry->d_inode) {
-+ printk("mini_fo: meta_sync_lists: \
-+ invalid dentry passed.\n");
-+ return -1;
-+ }
-+ err = meta_sync_d_list(dentry, 0);
-+ err |= meta_sync_r_list(dentry, 1);
-+ return err;
-+}
-+
-+
-+/* remove all D entries from the renamed list and free the mem */
-+int __meta_put_d_list(inode_t *inode)
-+{
-+ struct list_head *tmp;
-+ struct deleted_entry *del_entry;
-+ struct mini_fo_inode_info *inode_info;
-+
-+ if(!inode || !itopd(inode)) {
-+ printk(KERN_CRIT "mini_fo: __meta_put_d_list: \
-+ invalid inode passed.\n");
-+ return -1;
-+ }
-+ inode_info = itopd(inode);
-+
-+ /* nuke the DELETED-list */
-+ if(inode_info->deleted_list_size <= 0)
-+ return 0;
-+
-+ while(!list_empty(&inode_info->deleted_list)) {
-+ tmp = inode_info->deleted_list.next;
-+ list_del(tmp);
-+ del_entry = list_entry(tmp, struct deleted_entry, list);
-+ kfree(del_entry->name);
-+ kfree(del_entry);
-+ }
-+ inode_info->deleted_list_size = 0;
-+
-+ return 0;
-+}
-+
-+/* remove all R entries from the renamed list and free the mem */
-+int __meta_put_r_list(inode_t *inode)
-+{
-+ struct list_head *tmp;
-+ struct renamed_entry *ren_entry;
-+ struct mini_fo_inode_info *inode_info;
-+
-+ if(!inode || !itopd(inode)) {
-+ printk(KERN_CRIT "mini_fo: meta_put_r_list: invalid inode.\n");
-+ return -1;
-+ }
-+ inode_info = itopd(inode);
-+
-+ /* nuke the RENAMED-list */
-+ if(inode_info->renamed_list_size <= 0)
-+ return 0;
-+
-+ while(!list_empty(&inode_info->renamed_list)) {
-+ tmp = inode_info->renamed_list.next;
-+ list_del(tmp);
-+ ren_entry = list_entry(tmp, struct renamed_entry, list);
-+ kfree(ren_entry->new_name);
-+ kfree(ren_entry->old_name);
-+ kfree(ren_entry);
-+ }
-+ inode_info->renamed_list_size = 0;
-+
-+ return 0;
-+}
-+
-+int meta_add_d_entry(dentry_t *dentry, const char *name, int len)
-+{
-+ int err = 0;
-+ err = meta_list_add_d_entry(dentry, name, len);
-+ err |= meta_write_d_entry(dentry,name,len);
-+ return err;
-+}
-+
-+/* add a D entry to the deleted list */
-+int meta_list_add_d_entry(dentry_t *dentry, const char *name, int len)
-+{
-+ struct deleted_entry *del_entry;
-+ struct mini_fo_inode_info *inode_info;
-+
-+ if(!dentry || !dentry->d_inode) {
-+ printk(KERN_CRIT "mini_fo: meta_list_add_d_entry: \
-+ invalid dentry passed.\n");
-+ return -1;
-+ }
-+ inode_info = itopd(dentry->d_inode);
-+
-+ if(inode_info->deleted_list_size < 0)
-+ return -1;
-+
-+ del_entry = (struct deleted_entry *)
-+ kmalloc(sizeof(struct deleted_entry), GFP_KERNEL);
-+ del_entry->name = (char*) kmalloc(len, GFP_KERNEL);
-+ if(!del_entry || !del_entry->name) {
-+ printk(KERN_CRIT "mini_fo: meta_list_add_d_entry: \
-+ out of mem.\n");
-+ kfree(del_entry->name);
-+ kfree(del_entry);
-+ return -ENOMEM;
-+ }
-+
-+ strncpy(del_entry->name, name, len);
-+ del_entry->len = len;
-+
-+ list_add(&del_entry->list, &inode_info->deleted_list);
-+ inode_info->deleted_list_size++;
-+ return 0;
-+}
-+
-+int meta_add_r_entry(dentry_t *dentry,
-+ const char *old_name, int old_len,
-+ const char *new_name, int new_len)
-+{
-+ int err = 0;
-+ err = meta_list_add_r_entry(dentry,
-+ old_name, old_len,
-+ new_name, new_len);
-+ err |= meta_write_r_entry(dentry,
-+ old_name, old_len,
-+ new_name, new_len);
-+ return err;
-+}
-+
-+/* add a R entry to the renamed list */
-+int meta_list_add_r_entry(dentry_t *dentry,
-+ const char *old_name, int old_len,
-+ const char *new_name, int new_len)
-+{
-+ struct renamed_entry *ren_entry;
-+ struct mini_fo_inode_info *inode_info;
-+
-+ if(!dentry || !dentry->d_inode) {
-+ printk(KERN_CRIT "mini_fo: meta_list_add_r_entry: \
-+ invalid dentry passed.\n");
-+ return -1;
-+ }
-+ inode_info = itopd(dentry->d_inode);
-+
-+ if(inode_info->renamed_list_size < 0)
-+ return -1;
-+
-+ ren_entry = (struct renamed_entry *)
-+ kmalloc(sizeof(struct renamed_entry), GFP_KERNEL);
-+ ren_entry->old_name = (char*) kmalloc(old_len, GFP_KERNEL);
-+ ren_entry->new_name = (char*) kmalloc(new_len, GFP_KERNEL);
-+
-+ if(!ren_entry || !ren_entry->old_name || !ren_entry->new_name) {
-+ printk(KERN_CRIT "mini_fo: meta_list_add_r_entry: \
-+ out of mem.\n");
-+ kfree(ren_entry->new_name);
-+ kfree(ren_entry->old_name);
-+ kfree(ren_entry);
-+ return -ENOMEM;
-+ }
-+
-+ strncpy(ren_entry->old_name, old_name, old_len);
-+ ren_entry->old_len = old_len;
-+ strncpy(ren_entry->new_name, new_name, new_len);
-+ ren_entry->new_len = new_len;
-+
-+ list_add(&ren_entry->list, &inode_info->renamed_list);
-+ inode_info->renamed_list_size++;
-+ return 0;
-+}
-+
-+
-+int meta_remove_r_entry(dentry_t *dentry, const char *name, int len)
-+{
-+ int err = 0;
-+ if(!dentry || !dentry->d_inode) {
-+ printk(KERN_CRIT
-+ "mini_fo: meta_remove_r_entry: \
-+ invalid dentry passed.\n");
-+ return -1;
-+ }
-+
-+ err = meta_list_remove_r_entry(dentry, name, len);
-+ err |= meta_sync_lists(dentry);
-+ return err;
-+}
-+
-+int meta_list_remove_r_entry(dentry_t *dentry, const char *name, int len)
-+{
-+ if(!dentry || !dentry->d_inode) {
-+ printk(KERN_CRIT
-+ "mini_fo: meta_list_remove_r_entry: \
-+ invalid dentry passed.\n");
-+ return -1;
-+ }
-+ return __meta_list_remove_r_entry(dentry->d_inode, name, len);
-+}
-+
-+int __meta_list_remove_r_entry(inode_t *inode, const char *name, int len)
-+{
-+ struct list_head *tmp;
-+ struct renamed_entry *ren_entry;
-+ struct mini_fo_inode_info *inode_info;
-+
-+ if(!inode || !itopd(inode))
-+ printk(KERN_CRIT
-+ "mini_fo: __meta_list_remove_r_entry: \
-+ invalid inode passed.\n");
-+ inode_info = itopd(inode);
-+
-+ if(inode_info->renamed_list_size < 0)
-+ return -1;
-+ if(inode_info->renamed_list_size == 0)
-+ return 1;
-+
-+ list_for_each(tmp, &inode_info->renamed_list) {
-+ ren_entry = list_entry(tmp, struct renamed_entry, list);
-+ if(ren_entry->new_len != len)
-+ continue;
-+
-+ if(!strncmp(ren_entry->new_name, name, len)) {
-+ list_del(tmp);
-+ kfree(ren_entry->new_name);
-+ kfree(ren_entry->old_name);
-+ kfree(ren_entry);
-+ inode_info->renamed_list_size--;
-+ return 0;
-+ }
-+ }
-+ return 1;
-+}
-+
-+
-+/* append a single D entry to the meta file */
-+int meta_write_d_entry(dentry_t *dentry, const char *name, int len)
-+{
-+ dentry_t *meta_dentry = 0;
-+ file_t *meta_file = 0;
-+ mm_segment_t old_fs;
-+
-+ int bytes, err;
-+ struct vfsmount *meta_mnt = 0;
-+ char *buf;
-+
-+ err = 0;
-+
-+ if(itopd(dentry->d_inode)->deleted_list_size < 0) {
-+ err = -1;
-+ goto out;
-+ }
-+
-+ if(dtopd(dentry)->state == UNMODIFIED) {
-+ err = build_sto_structure(dentry->d_parent, dentry);
-+ if(err) {
-+ printk(KERN_CRIT "mini_fo: meta_write_d_entry: \
-+ build_sto_structure failed.\n");
-+ goto out;
-+ }
-+ }
-+ meta_dentry = lookup_one_len(META_FILENAME,
-+ dtohd2(dentry), strlen (META_FILENAME));
-+
-+ /* We need to create a META-file */
-+ if(!meta_dentry->d_inode) {
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
-+ vfs_create(dtohd2(dentry)->d_inode,
-+ meta_dentry,
-+ S_IRUSR | S_IWUSR,
-+ NULL);
-+#else
-+ vfs_create(dtohd2(dentry)->d_inode,
-+ meta_dentry,
-+ S_IRUSR | S_IWUSR);
-+#endif
-+ }
-+ /* open META-file for writing */
-+ meta_file = dentry_open(meta_dentry, meta_mnt, 0x1);
-+ if(!meta_file || IS_ERR(meta_file)) {
-+ printk(KERN_CRIT "mini_fo: meta_write_d_entry: \
-+ ERROR opening meta file.\n");
-+ mntput(meta_mnt); /* $%& is this necessary? */
-+ dput(meta_dentry);
-+ err = -1;
-+ goto out;
-+ }
-+
-+ /* check if fs supports writing */
-+ if(!meta_file->f_op->write) {
-+ printk(KERN_CRIT "mini_fo: meta_write_d_entry: \
-+ ERROR, fs does not support writing.\n");
-+ goto out_err_close;
-+ }
-+
-+ meta_file->f_pos = meta_dentry->d_inode->i_size; /* append */
-+ old_fs = get_fs();
-+ set_fs(KERNEL_DS);
-+
-+ /* size: len for name, 1 for \n and 2 for "D " */
-+ buf = (char *) kmalloc(len+3, GFP_KERNEL);
-+ if (!buf) {
-+ printk(KERN_CRIT "mini_fo: meta_write_d_entry: \
-+ out of mem.\n");
-+ return -ENOMEM;
-+ }
-+
-+ buf[0] = 'D';
-+ buf[1] = ' ';
-+ strncpy(buf+2, name, len);
-+ buf[len+2] = '\n';
-+ bytes = meta_file->f_op->write(meta_file, buf, len+3,
-+ &meta_file->f_pos);
-+ if(bytes != len+3) {
-+ printk(KERN_CRIT "mini_fo: meta_write_d_entry: \
-+ ERROR writing.\n");
-+ err = -1;
-+ }
-+ kfree(buf);
-+ set_fs(old_fs);
-+
-+ out_err_close:
-+ fput(meta_file);
-+ out:
-+ return err;
-+}
-+
-+/* append a single R entry to the meta file */
-+int meta_write_r_entry(dentry_t *dentry,
-+ const char *old_name, int old_len,
-+ const char *new_name, int new_len)
-+{
-+ dentry_t *meta_dentry = 0;
-+ file_t *meta_file = 0;
-+ mm_segment_t old_fs;
-+
-+ int bytes, err, buf_len;
-+ struct vfsmount *meta_mnt = 0;
-+ char *buf;
-+
-+
-+ err = 0;
-+
-+ if(itopd(dentry->d_inode)->renamed_list_size < 0) {
-+ err = -1;
-+ goto out;
-+ }
-+
-+ /* build the storage structure? */
-+ if(dtopd(dentry)->state == UNMODIFIED) {
-+ err = build_sto_structure(dentry->d_parent, dentry);
-+ if(err) {
-+ printk(KERN_CRIT "mini_fo: meta_write_r_entry: \
-+ build_sto_structure failed.\n");
-+ goto out;
-+ }
-+ }
-+ meta_dentry = lookup_one_len(META_FILENAME,
-+ dtohd2(dentry),
-+ strlen (META_FILENAME));
-+ if(!meta_dentry->d_inode) {
-+ /* We need to create a META-file */
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
-+ vfs_create(dtohd2(dentry)->d_inode,
-+ meta_dentry, S_IRUSR | S_IWUSR, NULL);
-+#else
-+ vfs_create(dtohd2(dentry)->d_inode,
-+ meta_dentry, S_IRUSR | S_IWUSR);
-+#endif
-+ }
-+ /* open META-file for writing */
-+ meta_file = dentry_open(meta_dentry, meta_mnt, 0x1);
-+ if(!meta_file || IS_ERR(meta_file)) {
-+ printk(KERN_CRIT "mini_fo: meta_write_r_entry: \
-+ ERROR opening meta file.\n");
-+ mntput(meta_mnt);
-+ dput(meta_dentry);
-+ err = -1;
-+ goto out;
-+ }
-+
-+ /* check if fs supports writing */
-+ if(!meta_file->f_op->write) {
-+ printk(KERN_CRIT "mini_fo: meta_write_r_entry: \
-+ ERROR, fs does not support writing.\n");
-+ goto out_err_close;
-+ }
-+
-+ meta_file->f_pos = meta_dentry->d_inode->i_size; /* append */
-+ old_fs = get_fs();
-+ set_fs(KERNEL_DS);
-+
-+ /* size: 2 for "R ", old_len+new_len for names, 1 blank+1 \n */
-+ buf_len = old_len + new_len + 4;
-+ buf = (char *) kmalloc(buf_len, GFP_KERNEL);
-+ if (!buf) {
-+ printk(KERN_CRIT "mini_fo: meta_write_r_entry: out of mem.\n");
-+ return -ENOMEM;
-+ }
-+
-+ buf[0] = 'R';
-+ buf[1] = ' ';
-+ strncpy(buf + 2, old_name, old_len);
-+ buf[old_len + 2] = ' ';
-+ strncpy(buf + old_len + 3, new_name, new_len);
-+ buf[buf_len -1] = '\n';
-+ bytes = meta_file->f_op->write(meta_file, buf, buf_len, &meta_file->f_pos);
-+ if(bytes != buf_len) {
-+ printk(KERN_CRIT "mini_fo: meta_write_r_entry: ERROR writing.\n");
-+ err = -1;
-+ }
-+
-+ kfree(buf);
-+ set_fs(old_fs);
-+
-+ out_err_close:
-+ fput(meta_file);
-+ out:
-+ return err;
-+}
-+
-+/* sync D list to disk, append data if app_flag is 1 */
-+/* check the meta_mnt, which seems not to be used (properly) */
-+
-+int meta_sync_d_list(dentry_t *dentry, int app_flag)
-+{
-+ dentry_t *meta_dentry;
-+ file_t *meta_file;
-+ mm_segment_t old_fs;
-+
-+ int bytes, err;
-+ struct vfsmount *meta_mnt;
-+ char *buf;
-+
-+ struct list_head *tmp;
-+ struct deleted_entry *del_entry;
-+ struct mini_fo_inode_info *inode_info;
-+
-+ err = 0;
-+ meta_file=0;
-+ meta_mnt=0;
-+
-+ if(!dentry || !dentry->d_inode) {
-+ printk(KERN_CRIT "mini_fo: meta_sync_d_list: \
-+ invalid inode passed.\n");
-+ err = -1;
-+ goto out;
-+ }
-+ inode_info = itopd(dentry->d_inode);
-+
-+ if(inode_info->deleted_list_size < 0) {
-+ err = -1;
-+ goto out;
-+ }
-+
-+ /* ok, there is something to sync */
-+
-+ /* build the storage structure? */
-+ if(!dtohd2(dentry) && !itohi2(dentry->d_inode)) {
-+ err = build_sto_structure(dentry->d_parent, dentry);
-+ if(err) {
-+ printk(KERN_CRIT "mini_fo: meta_sync_d_list: \
-+ build_sto_structure failed.\n");
-+ goto out;
-+ }
-+ }
-+ meta_dentry = lookup_one_len(META_FILENAME,
-+ dtohd2(dentry),
-+ strlen(META_FILENAME));
-+ if(!meta_dentry->d_inode) {
-+ /* We need to create a META-file */
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
-+ vfs_create(dtohd2(dentry)->d_inode,
-+ meta_dentry, S_IRUSR | S_IWUSR, NULL);
-+#else
-+ vfs_create(dtohd2(dentry)->d_inode,
-+ meta_dentry, S_IRUSR | S_IWUSR);
-+#endif
-+ app_flag = 0;
-+ }
-+ /* need we truncate the meta file? */
-+ if(!app_flag) {
-+ struct iattr newattrs;
-+ newattrs.ia_size = 0;
-+ newattrs.ia_valid = ATTR_SIZE | ATTR_CTIME;
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_lock(&meta_dentry->d_inode->i_mutex);
-+#else
-+ down(&meta_dentry->d_inode->i_sem);
-+#endif
-+ err = notify_change(meta_dentry, &newattrs);
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_unlock(&meta_dentry->d_inode->i_mutex);
-+#else
-+ up(&meta_dentry->d_inode->i_sem);
-+#endif
-+
-+ if(err || meta_dentry->d_inode->i_size != 0) {
-+ printk(KERN_CRIT "mini_fo: meta_sync_d_list: \
-+ ERROR truncating meta file.\n");
-+ goto out_err_close;
-+ }
-+ }
-+
-+ /* open META-file for writing */
-+ meta_file = dentry_open(meta_dentry, meta_mnt, 0x1);
-+ if(!meta_file || IS_ERR(meta_file)) {
-+ printk(KERN_CRIT "mini_fo: meta_sync_d_list: \
-+ ERROR opening meta file.\n");
-+ /* we don't mntget so we dont't mntput (for now)
-+ * mntput(meta_mnt);
-+ */
-+ dput(meta_dentry);
-+ err = -1;
-+ goto out;
-+ }
-+
-+ /* check if fs supports writing */
-+ if(!meta_file->f_op->write) {
-+ printk(KERN_CRIT "mini_fo: meta_sync_d_list: \
-+ ERROR, fs does not support writing.\n");
-+ goto out_err_close;
-+ }
-+
-+ meta_file->f_pos = meta_dentry->d_inode->i_size; /* append */
-+ old_fs = get_fs();
-+ set_fs(KERNEL_DS);
-+
-+ /* here we go... */
-+ list_for_each(tmp, &inode_info->deleted_list) {
-+ del_entry = list_entry(tmp, struct deleted_entry, list);
-+
-+ /* size: len for name, 1 for \n and 2 for "D " */
-+ buf = (char *) kmalloc(del_entry->len+3, GFP_KERNEL);
-+ if (!buf) {
-+ printk(KERN_CRIT "mini_fo: meta_sync_d_list: \
-+ out of mem.\n");
-+ return -ENOMEM;
-+ }
-+
-+ buf[0] = 'D';
-+ buf[1] = ' ';
-+ strncpy(buf+2, del_entry->name, del_entry->len);
-+ buf[del_entry->len+2] = '\n';
-+ bytes = meta_file->f_op->write(meta_file, buf,
-+ del_entry->len+3,
-+ &meta_file->f_pos);
-+ if(bytes != del_entry->len+3) {
-+ printk(KERN_CRIT "mini_fo: meta_sync_d_list: \
-+ ERROR writing.\n");
-+ err |= -1;
-+ }
-+ kfree(buf);
-+ }
-+ set_fs(old_fs);
-+
-+ out_err_close:
-+ fput(meta_file);
-+ out:
-+ return err;
-+
-+}
-+
-+int meta_sync_r_list(dentry_t *dentry, int app_flag)
-+{
-+ dentry_t *meta_dentry;
-+ file_t *meta_file;
-+ mm_segment_t old_fs;
-+
-+ int bytes, err, buf_len;
-+ struct vfsmount *meta_mnt;
-+ char *buf;
-+
-+ struct list_head *tmp;
-+ struct renamed_entry *ren_entry;
-+ struct mini_fo_inode_info *inode_info;
-+
-+ err = 0;
-+ meta_file=0;
-+ meta_mnt=0;
-+
-+ if(!dentry || !dentry->d_inode) {
-+ printk(KERN_CRIT "mini_fo: meta_sync_r_list: \
-+ invalid dentry passed.\n");
-+ err = -1;
-+ goto out;
-+ }
-+ inode_info = itopd(dentry->d_inode);
-+
-+ if(inode_info->deleted_list_size < 0) {
-+ err = -1;
-+ goto out;
-+ }
-+
-+ /* ok, there is something to sync */
-+
-+ /* build the storage structure? */
-+ if(!dtohd2(dentry) && !itohi2(dentry->d_inode)) {
-+ err = build_sto_structure(dentry->d_parent, dentry);
-+ if(err) {
-+ printk(KERN_CRIT "mini_fo: meta_sync_r_list: \
-+ build_sto_structure failed.\n");
-+ goto out;
-+ }
-+ }
-+ meta_dentry = lookup_one_len(META_FILENAME,
-+ dtohd2(dentry),
-+ strlen(META_FILENAME));
-+ if(!meta_dentry->d_inode) {
-+ /* We need to create a META-file */
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
-+ vfs_create(dtohd2(dentry)->d_inode,
-+ meta_dentry, S_IRUSR | S_IWUSR, NULL);
-+#else
-+ vfs_create(dtohd2(dentry)->d_inode,
-+ meta_dentry, S_IRUSR | S_IWUSR);
-+#endif
-+ app_flag = 0;
-+ }
-+ /* need we truncate the meta file? */
-+ if(!app_flag) {
-+ struct iattr newattrs;
-+ newattrs.ia_size = 0;
-+ newattrs.ia_valid = ATTR_SIZE | ATTR_CTIME;
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_lock(&meta_dentry->d_inode->i_mutex);
-+#else
-+ down(&meta_dentry->d_inode->i_sem);
-+#endif
-+ err = notify_change(meta_dentry, &newattrs);
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_unlock(&meta_dentry->d_inode->i_mutex);
-+#else
-+ up(&meta_dentry->d_inode->i_sem);
-+#endif
-+ if(err || meta_dentry->d_inode->i_size != 0) {
-+ printk(KERN_CRIT "mini_fo: meta_sync_r_list: \
-+ ERROR truncating meta file.\n");
-+ goto out_err_close;
-+ }
-+ }
-+
-+ /* open META-file for writing */
-+ meta_file = dentry_open(meta_dentry, meta_mnt, 0x1);
-+ if(!meta_file || IS_ERR(meta_file)) {
-+ printk(KERN_CRIT "mini_fo: meta_sync_r_list: \
-+ ERROR opening meta file.\n");
-+ /* we don't mntget so we dont't mntput (for now)
-+ * mntput(meta_mnt);
-+ */
-+ dput(meta_dentry);
-+ err = -1;
-+ goto out;
-+ }
-+
-+ /* check if fs supports writing */
-+ if(!meta_file->f_op->write) {
-+ printk(KERN_CRIT "mini_fo: meta_sync_r_list: \
-+ ERROR, fs does not support writing.\n");
-+ goto out_err_close;
-+ }
-+
-+ meta_file->f_pos = meta_dentry->d_inode->i_size; /* append */
-+ old_fs = get_fs();
-+ set_fs(KERNEL_DS);
-+
-+ /* here we go... */
-+ list_for_each(tmp, &inode_info->renamed_list) {
-+ ren_entry = list_entry(tmp, struct renamed_entry, list);
-+ /* size:
-+ * 2 for "R ", old_len+new_len for names, 1 blank+1 \n */
-+ buf_len = ren_entry->old_len + ren_entry->new_len + 4;
-+ buf = (char *) kmalloc(buf_len, GFP_KERNEL);
-+ if (!buf) {
-+ printk(KERN_CRIT "mini_fo: meta_sync_r_list: \
-+ out of mem.\n");
-+ return -ENOMEM;
-+ }
-+ buf[0] = 'R';
-+ buf[1] = ' ';
-+ strncpy(buf + 2, ren_entry->old_name, ren_entry->old_len);
-+ buf[ren_entry->old_len + 2] = ' ';
-+ strncpy(buf + ren_entry->old_len + 3,
-+ ren_entry->new_name, ren_entry->new_len);
-+ buf[buf_len - 1] = '\n';
-+ bytes = meta_file->f_op->write(meta_file, buf,
-+ buf_len, &meta_file->f_pos);
-+ if(bytes != buf_len) {
-+ printk(KERN_CRIT "mini_fo: meta_sync_r_list: \
-+ ERROR writing.\n");
-+ err |= -1;
-+ }
-+ kfree(buf);
-+ }
-+ set_fs(old_fs);
-+
-+ out_err_close:
-+ fput(meta_file);
-+ out:
-+ return err;
-+}
-+
-+int meta_check_d_entry(dentry_t *dentry, const char *name, int len)
-+{
-+ if(!dentry || !dentry->d_inode)
-+ printk(KERN_CRIT "mini_fo: meta_check_d_dentry: \
-+ invalid dentry passed.\n");
-+ return __meta_check_d_entry(dentry->d_inode, name, len);
-+}
-+
-+int __meta_check_d_entry(inode_t *inode, const char *name, int len)
-+{
-+ struct list_head *tmp;
-+ struct deleted_entry *del_entry;
-+ struct mini_fo_inode_info *inode_info;
-+
-+ if(!inode || !itopd(inode))
-+ printk(KERN_CRIT "mini_fo: __meta_check_d_dentry: \
-+ invalid inode passed.\n");
-+
-+ inode_info = itopd(inode);
-+
-+ if(inode_info->deleted_list_size <= 0)
-+ return 0;
-+
-+ list_for_each(tmp, &inode_info->deleted_list) {
-+ del_entry = list_entry(tmp, struct deleted_entry, list);
-+ if(del_entry->len != len)
-+ continue;
-+
-+ if(!strncmp(del_entry->name, name, len))
-+ return 1;
-+ }
-+ return 0;
-+}
-+
-+/*
-+ * check if file has been renamed and return path to orig. base dir.
-+ * Implements no error return values so far, what of course sucks.
-+ * String is null terminated.'
-+ */
-+char* meta_check_r_entry(dentry_t *dentry, const char *name, int len)
-+{
-+ if(!dentry || !dentry->d_inode) {
-+ printk(KERN_CRIT "mini_fo: meta_check_r_dentry: \
-+ invalid dentry passed.\n");
-+ return NULL;
-+ }
-+ return __meta_check_r_entry(dentry->d_inode, name, len);
-+}
-+
-+char* __meta_check_r_entry(inode_t *inode, const char *name, int len)
-+{
-+ struct list_head *tmp;
-+ struct renamed_entry *ren_entry;
-+ struct mini_fo_inode_info *inode_info;
-+ char *old_path;
-+
-+ if(!inode || !itopd(inode)) {
-+ printk(KERN_CRIT "mini_fo: meta_check_r_dentry: \
-+ invalid inode passed.\n");
-+ return NULL;
-+ }
-+ inode_info = itopd(inode);
-+
-+ if(inode_info->renamed_list_size <= 0)
-+ return NULL;
-+
-+ list_for_each(tmp, &inode_info->renamed_list) {
-+ ren_entry = list_entry(tmp, struct renamed_entry, list);
-+ if(ren_entry->new_len != len)
-+ continue;
-+
-+ if(!strncmp(ren_entry->new_name, name, len)) {
-+ old_path = (char *)
-+ kmalloc(ren_entry->old_len+1, GFP_KERNEL);
-+ strncpy(old_path,
-+ ren_entry->old_name,
-+ ren_entry->old_len);
-+ old_path[ren_entry->old_len]='\0';
-+ return old_path;
-+ }
-+ }
-+ return NULL;
-+}
-+
-+/*
-+ * This version only checks if entry exists and return:
-+ * 1 if exists,
-+ * 0 if not,
-+ * -1 if error.
-+ */
-+int meta_is_r_entry(dentry_t *dentry, const char *name, int len)
-+{
-+ if(!dentry || !dentry->d_inode) {
-+ printk(KERN_CRIT "mini_fo: meta_check_r_dentry [2]: \
-+ invalid dentry passed.\n");
-+ return -1;
-+ }
-+ return __meta_is_r_entry(dentry->d_inode, name, len);
-+}
-+
-+int __meta_is_r_entry(inode_t *inode, const char *name, int len)
-+{
-+ struct list_head *tmp;
-+ struct renamed_entry *ren_entry;
-+ struct mini_fo_inode_info *inode_info;
-+
-+ if(!inode || !itopd(inode)) {
-+ printk(KERN_CRIT "mini_fo: meta_check_r_dentry [2]: \
-+ invalid inode passed.\n");
-+ return -1;
-+ }
-+ inode_info = itopd(inode);
-+
-+ if(inode_info->renamed_list_size <= 0)
-+ return -1;
-+
-+ list_for_each(tmp, &inode_info->renamed_list) {
-+ ren_entry = list_entry(tmp, struct renamed_entry, list);
-+ if(ren_entry->new_len != len)
-+ continue;
-+
-+ if(!strncmp(ren_entry->new_name, name, len))
-+ return 1;
-+ }
-+ return 0;
-+}
-+
---- /dev/null
-+++ b/fs/mini_fo/mini_fo.h
-@@ -0,0 +1,510 @@
-+/*
-+ * Copyright (c) 1997-2003 Erez Zadok
-+ * Copyright (c) 2001-2003 Stony Brook University
-+ *
-+ * For specific licensing information, see the COPYING file distributed with
-+ * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
-+ *
-+ * This Copyright notice must be kept intact and distributed with all
-+ * fistgen sources INCLUDING sources generated by fistgen.
-+ */
-+/*
-+ * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
-+ *
-+ * 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.
-+ */
-+
-+/*
-+ * $Id$
-+ */
-+
-+#ifndef __MINI_FO_H_
-+#define __MINI_FO_H_
-+
-+#ifdef __KERNEL__
-+
-+/* META stuff */
-+#define META_FILENAME "META_dAfFgHE39ktF3HD2sr"
-+
-+/* use xattrs? */
-+#define XATTR
-+
-+/* File attributes that when changed, result in a file beeing copied to storage */
-+#define COPY_FLAGS ATTR_MODE | ATTR_UID | ATTR_GID | ATTR_SIZE
-+
-+/*
-+ * mini_fo filestates
-+ */
-+#define MODIFIED 1
-+#define UNMODIFIED 2
-+#define CREATED 3
-+#define DEL_REWRITTEN 4
-+#define DELETED 5
-+#define NON_EXISTANT 6
-+
-+/* fist file systems superblock magic */
-+# define MINI_FO_SUPER_MAGIC 0xf15f
-+
-+/*
-+ * STRUCTURES:
-+ */
-+
-+/* mini_fo inode data in memory */
-+struct mini_fo_inode_info {
-+ inode_t *wii_inode;
-+ inode_t *wii_inode2; /* pointer to storage inode */
-+
-+ /* META-data lists */
-+ /* deleted list, ex wol */
-+ struct list_head deleted_list;
-+ int deleted_list_size;
-+
-+ /* renamed list */
-+ struct list_head renamed_list;
-+ int renamed_list_size;
-+
-+ /* add other lists here ... */
-+};
-+
-+/* mini_fo dentry data in memory */
-+struct mini_fo_dentry_info {
-+ dentry_t *wdi_dentry;
-+ dentry_t *wdi_dentry2; /* pointer to storage dentry */
-+ unsigned int state; /* state of the mini_fo dentry */
-+};
-+
-+
-+/* mini_fo super-block data in memory */
-+struct mini_fo_sb_info {
-+ super_block_t *wsi_sb, *wsi_sb2; /* mk: might point to the same sb */
-+ struct vfsmount *hidden_mnt, *hidden_mnt2;
-+ dentry_t *base_dir_dentry;
-+ dentry_t *storage_dir_dentry;
-+ ;
-+};
-+
-+/* readdir_data, readdir helper struct */
-+struct readdir_data {
-+ struct list_head ndl_list; /* linked list head ptr */
-+ int ndl_size; /* list size */
-+ int sto_done; /* flag to show that the storage dir entries have
-+ * all been read an now follow base entries */
-+};
-+
-+/* file private data. */
-+struct mini_fo_file_info {
-+ struct file *wfi_file;
-+ struct file *wfi_file2; /* pointer to storage file */
-+ struct readdir_data rd;
-+};
-+
-+/* struct ndl_entry */
-+struct ndl_entry {
-+ struct list_head list;
-+ char *name;
-+ int len;
-+};
-+
-+/********************************
-+ * META-data structures
-+ ********************************/
-+
-+/* deleted entry */
-+struct deleted_entry {
-+ struct list_head list;
-+ char *name;
-+ int len;
-+};
-+
-+/* renamed entry */
-+struct renamed_entry {
-+ struct list_head list;
-+ char *old_name; /* old directory with full path */
-+ int old_len; /* length of above string */
-+ char *new_name; /* new directory name */
-+ int new_len; /* length of above string */
-+};
-+
-+/* attr_change entry */
-+struct attr_change_entry {
-+ struct list_head list;
-+ char *name;
-+ int len;
-+};
-+
-+/* link entry */
-+struct link_entry {
-+ struct list_head list;
-+ int links_moved;
-+ int inum_base;
-+ int inum_sto;
-+ char *weird_name;
-+ int weird_name_len;
-+};
-+
-+
-+/* Some other stuff required for mini_fo_filldir64, copied from
-+ * fs/readdir.c
-+ */
-+
-+#define ROUND_UP64(x) (((x)+sizeof(u64)-1) & ~(sizeof(u64)-1))
-+#define NAME_OFFSET(de) ((int) ((de)->d_name - (char *) (de)))
-+
-+
-+struct linux_dirent64 {
-+ u64 d_ino;
-+ s64 d_off;
-+ unsigned short d_reclen;
-+ unsigned char d_type;
-+ char d_name[0];
-+};
-+
-+
-+struct getdents_callback64 {
-+ struct linux_dirent64 * current_dir;
-+ struct linux_dirent64 * previous;
-+ int count;
-+ int error;
-+};
-+
-+struct linux_dirent {
-+ unsigned long d_ino;
-+ unsigned long d_off;
-+ unsigned short d_reclen;
-+ char d_name[1];
-+};
-+
-+struct getdents_callback {
-+ struct linux_dirent * current_dir;
-+ struct linux_dirent * previous;
-+ int count;
-+ int error;
-+};
-+
-+
-+/*
-+ * MACROS:
-+ */
-+
-+/* file TO private_data */
-+# define ftopd(file) ((struct mini_fo_file_info *)((file)->private_data))
-+# define __ftopd(file) ((file)->private_data)
-+/* file TO hidden_file */
-+# define ftohf(file) ((ftopd(file))->wfi_file)
-+# define ftohf2(file) ((ftopd(file))->wfi_file2)
-+
-+/* inode TO private_data */
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
-+# define itopd(ino) ((struct mini_fo_inode_info *)(ino)->i_private)
-+# define __itopd(ino) ((ino)->i_private)
-+#else
-+# define itopd(ino) ((struct mini_fo_inode_info *)(ino)->u.generic_ip)
-+# define __itopd(ino) ((ino)->u.generic_ip)
-+#endif
-+/* inode TO hidden_inode */
-+# define itohi(ino) (itopd(ino)->wii_inode)
-+# define itohi2(ino) (itopd(ino)->wii_inode2)
-+
-+/* superblock TO private_data */
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
-+# define stopd(super) ((struct mini_fo_sb_info *)(super)->s_fs_info)
-+# define __stopd(super) ((super)->s_fs_info)
-+#else
-+# define stopd(super) ((struct mini_fo_sb_info *)(super)->u.generic_sbp)
-+# define __stopd(super) ((super)->u.generic_sbp)
-+#endif
-+
-+/* unused? # define vfs2priv stopd */
-+/* superblock TO hidden_superblock */
-+
-+# define stohs(super) (stopd(super)->wsi_sb)
-+# define stohs2(super) (stopd(super)->wsi_sb2)
-+
-+/* dentry TO private_data */
-+# define dtopd(dentry) ((struct mini_fo_dentry_info *)(dentry)->d_fsdata)
-+# define __dtopd(dentry) ((dentry)->d_fsdata)
-+/* dentry TO hidden_dentry */
-+# define dtohd(dent) (dtopd(dent)->wdi_dentry)
-+# define dtohd2(dent) (dtopd(dent)->wdi_dentry2)
-+
-+/* dentry to state */
-+# define dtost(dent) (dtopd(dent)->state)
-+# define sbt(sb) ((sb)->s_type->name)
-+
-+#define IS_WRITE_FLAG(flag) (flag & (O_RDWR | O_WRONLY | O_APPEND))
-+#define IS_COPY_FLAG(flag) (flag & (COPY_FLAGS))
-+
-+/* macros to simplify non-SCA code */
-+# define MALLOC_PAGE_POINTERS(hidden_pages, num_hidden_pages)
-+# define MALLOC_PAGEDATA_POINTERS(hidden_pages_data, num_hidden_pages)
-+# define FREE_PAGE_POINTERS(hidden_pages, num)
-+# define FREE_PAGEDATA_POINTERS(hidden_pages_data, num)
-+# define FOR_EACH_PAGE
-+# define CURRENT_HIDDEN_PAGE hidden_page
-+# define CURRENT_HIDDEN_PAGEDATA hidden_page_data
-+# define CURRENT_HIDDEN_PAGEINDEX page->index
-+
-+/*
-+ * EXTERNALS:
-+ */
-+extern struct file_operations mini_fo_main_fops;
-+extern struct file_operations mini_fo_dir_fops;
-+extern struct inode_operations mini_fo_main_iops;
-+extern struct inode_operations mini_fo_dir_iops;
-+extern struct inode_operations mini_fo_symlink_iops;
-+extern struct super_operations mini_fo_sops;
-+extern struct dentry_operations mini_fo_dops;
-+extern struct vm_operations_struct mini_fo_shared_vmops;
-+extern struct vm_operations_struct mini_fo_private_vmops;
-+extern struct address_space_operations mini_fo_aops;
-+
-+#if 0 /* unused by mini_fo */
-+extern int mini_fo_interpose(dentry_t *hidden_dentry, dentry_t *this_dentry, super_block_t *sb, int flag);
-+#if defined(FIST_FILTER_DATA) || defined(FIST_FILTER_SCA)
-+extern page_t *mini_fo_get1page(file_t *file, int index);
-+extern int mini_fo_fill_zeros(file_t *file, page_t *page, unsigned from);
-+# endif /* FIST_FILTER_DATA || FIST_FILTER_SCA */
-+
-+
-+# define mini_fo_hidden_dentry(d) __mini_fo_hidden_dentry(__FILE__,__FUNCTION__,__LINE__,(d))
-+# define mini_fo_hidden_sto_dentry(d) __mini_fo_hidden_sto_dentry(__FILE__,__FUNCTION__,__LINE__,(d))
-+
-+extern dentry_t *__mini_fo_hidden_dentry(char *file, char *func, int line, dentry_t *this_dentry);
-+extern dentry_t *__mini_fo_hidden_sto_dentry(char *file, char *func, int line, dentry_t *this_dentry);
-+
-+extern int mini_fo_read_file(const char *filename, void *buf, int len);
-+extern int mini_fo_write_file(const char *filename, void *buf, int len);
-+extern dentry_t *fist_lookup(dentry_t *dir, const char *name, vnode_t **out, uid_t uid, gid_t gid);
-+#endif /* unused by mini_fo */
-+
-+/* state transition functions */
-+extern int nondir_unmod_to_mod(dentry_t *dentry, int cp_flag);
-+extern int nondir_del_rew_to_del(dentry_t *dentry);
-+extern int nondir_creat_to_del(dentry_t *dentry);
-+extern int nondir_mod_to_del(dentry_t *dentry);
-+extern int nondir_unmod_to_del(dentry_t *dentry);
-+
-+extern int dir_unmod_to_mod(dentry_t *dentry);
-+
-+/* rename specials */
-+extern int rename_directory(inode_t *old_dir, dentry_t *old_dentry, inode_t *new_dir, dentry_t *new_dentry);
-+extern int rename_nondir(inode_t *old_dir, dentry_t *old_dentry, inode_t *new_dir, dentry_t *new_dentry);
-+
-+/* misc stuff */
-+extern int mini_fo_tri_interpose(dentry_t *hidden_dentry,
-+ dentry_t *hidden_sto_dentry,
-+ dentry_t *dentry,
-+ super_block_t *sb, int flag);
-+
-+extern int mini_fo_cp_cont(dentry_t *tgt_dentry, struct vfsmount *tgt_mnt,
-+ dentry_t *src_dentry, struct vfsmount *src_mnt);
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
-+extern int mini_fo_create(inode_t *dir, dentry_t *dentry, int mode, struct nameidata *nd);
-+
-+extern int create_sto_nod(dentry_t *dentry, int mode, dev_t dev);
-+extern int create_sto_reg_file(dentry_t *dentry, int mode, struct nameidata *nd);
-+#else
-+extern int mini_fo_create(inode_t *dir, dentry_t *dentry, int mode);
-+
-+extern int create_sto_nod(dentry_t *dentry, int mode, int dev);
-+extern int create_sto_reg_file(dentry_t *dentry, int mode);
-+#endif
-+
-+extern int create_sto_dir(dentry_t *dentry, int mode);
-+
-+extern int exists_in_storage(dentry_t *dentry);
-+extern int is_mini_fo_existant(dentry_t *dentry);
-+extern int get_neg_sto_dentry(dentry_t *dentry);
-+extern int build_sto_structure(dentry_t *dir, dentry_t *dentry);
-+extern int get_mini_fo_bpath(dentry_t *dentry, char **bpath, int *bpath_len);
-+extern dentry_t *bpath_walk(super_block_t *sb, char *bpath);
-+extern int bpath_put(dentry_t *dentry);
-+
-+/* check_mini_fo types functions */
-+extern int check_mini_fo_dentry(dentry_t *dentry);
-+extern int check_mini_fo_file(file_t *file);
-+extern int check_mini_fo_inode(inode_t *inode);
-+
-+/* General meta functions, can be called from outside of meta.c */
-+extern int meta_build_lists(dentry_t *dentry);
-+extern int meta_put_lists(dentry_t *dentry);
-+extern int __meta_put_lists(inode_t *inode);
-+
-+extern int meta_add_d_entry(dentry_t *dentry, const char *name, int len);
-+extern int meta_add_r_entry(dentry_t *dentry,
-+ const char *old_name, int old_len,
-+ const char *new_name, int new_len);
-+
-+extern int meta_remove_r_entry(dentry_t *dentry, const char *name, int len);
-+
-+extern int meta_check_d_entry(dentry_t *dentry, const char *name, int len);
-+extern int __meta_check_d_entry(inode_t *inode, const char *name, int len);
-+
-+extern char* meta_check_r_entry(dentry_t *dentry, const char *name, int len);
-+extern char* __meta_check_r_entry(inode_t *inode, const char *name, int len);
-+extern int meta_is_r_entry(dentry_t *dentry, const char *name, int len);
-+extern int __meta_is_r_entry(inode_t *inode, const char *name, int len);
-+
-+/* Specific meta functions, should be called only inside meta.c */
-+extern int __meta_put_d_list(inode_t *inode);
-+extern int __meta_put_r_list(inode_t *inode);
-+
-+extern int meta_list_add_d_entry(dentry_t *dentry,
-+ const char *name, int len);
-+extern int meta_list_add_r_entry(dentry_t *dentry,
-+ const char *old_name, int old_len,
-+ const char *new_name, int new_len);
-+
-+extern int meta_list_remove_r_entry(dentry_t *dentry,
-+ const char *name, int len);
-+
-+extern int __meta_list_remove_r_entry(inode_t *inode,
-+ const char *name, int len);
-+
-+extern int meta_write_d_entry(dentry_t *dentry, const char *name, int len);
-+extern int meta_write_r_entry(dentry_t *dentry,
-+ const char *old_name, int old_len,
-+ const char *new_name, int new_len);
-+
-+extern int meta_sync_lists(dentry_t *dentry);
-+extern int meta_sync_d_list(dentry_t *dentry, int app_flag);
-+extern int meta_sync_r_list(dentry_t *dentry, int app_flag);
-+
-+/* ndl stuff */
-+extern int ndl_add_entry(struct readdir_data *rd, const char *name, int len);
-+extern void ndl_put_list(struct readdir_data *rd);
-+extern int ndl_check_entry(struct readdir_data *rd,
-+ const char *name, int len);
-+
-+
-+# define copy_inode_size(dst, src) \
-+ dst->i_size = src->i_size; \
-+ dst->i_blocks = src->i_blocks;
-+
-+static inline void
-+fist_copy_attr_atime(inode_t *dest, const inode_t *src)
-+{
-+ ASSERT(dest != NULL);
-+ ASSERT(src != NULL);
-+ dest->i_atime = src->i_atime;
-+}
-+static inline void
-+fist_copy_attr_times(inode_t *dest, const inode_t *src)
-+{
-+ ASSERT(dest != NULL);
-+ ASSERT(src != NULL);
-+ dest->i_atime = src->i_atime;
-+ dest->i_mtime = src->i_mtime;
-+ dest->i_ctime = src->i_ctime;
-+}
-+static inline void
-+fist_copy_attr_timesizes(inode_t *dest, const inode_t *src)
-+{
-+ ASSERT(dest != NULL);
-+ ASSERT(src != NULL);
-+ dest->i_atime = src->i_atime;
-+ dest->i_mtime = src->i_mtime;
-+ dest->i_ctime = src->i_ctime;
-+ copy_inode_size(dest, src);
-+}
-+static inline void
-+fist_copy_attr_all(inode_t *dest, const inode_t *src)
-+{
-+ ASSERT(dest != NULL);
-+ ASSERT(src != NULL);
-+ dest->i_mode = src->i_mode;
-+ dest->i_nlink = src->i_nlink;
-+ dest->i_uid = src->i_uid;
-+ dest->i_gid = src->i_gid;
-+ dest->i_rdev = src->i_rdev;
-+ dest->i_atime = src->i_atime;
-+ dest->i_mtime = src->i_mtime;
-+ dest->i_ctime = src->i_ctime;
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
-+ dest->i_blksize = src->i_blksize;
-+#endif
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,12)
-+ dest->i_blkbits = src->i_blkbits;
-+# endif /* linux 2.4.12 and newer */
-+ copy_inode_size(dest, src);
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
-+ dest->i_attr_flags = src->i_attr_flags;
-+#else
-+ dest->i_flags = src->i_flags;
-+#endif
-+}
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
-+/* copied from linux/fs.h */
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+static inline void double_lock(struct dentry *d1, struct dentry *d2)
-+{
-+ struct mutex *m1 = &d1->d_inode->i_mutex;
-+ struct mutex *m2 = &d2->d_inode->i_mutex;
-+ if (m1 != m2) {
-+ if ((unsigned long) m1 < (unsigned long) m2) {
-+ struct mutex *tmp = m2;
-+ m2 = m1; m1 = tmp;
-+ }
-+ mutex_lock(m1);
-+ }
-+ mutex_lock(m2);
-+}
-+
-+static inline void double_unlock(struct dentry *d1, struct dentry *d2)
-+{
-+ struct mutex *m1 = &d1->d_inode->i_mutex;
-+ struct mutex *m2 = &d2->d_inode->i_mutex;
-+ mutex_unlock(m1);
-+ if (m1 != m2)
-+ mutex_unlock(m2);
-+ dput(d1);
-+ dput(d2);
-+}
-+
-+#else
-+static inline void double_down(struct semaphore *s1, struct semaphore *s2)
-+{
-+ if (s1 != s2) {
-+ if ((unsigned long) s1 < (unsigned long) s2) {
-+ struct semaphore *tmp = s2;
-+ s2 = s1; s1 = tmp;
-+ }
-+ down(s1);
-+ }
-+ down(s2);
-+}
-+
-+static inline void double_up(struct semaphore *s1, struct semaphore *s2)
-+{
-+ up(s1);
-+ if (s1 != s2)
-+ up(s2);
-+}
-+
-+static inline void double_lock(struct dentry *d1, struct dentry *d2)
-+{
-+ double_down(&d1->d_inode->i_sem, &d2->d_inode->i_sem);
-+}
-+
-+static inline void double_unlock(struct dentry *d1, struct dentry *d2)
-+{
-+ double_up(&d1->d_inode->i_sem,&d2->d_inode->i_sem);
-+ dput(d1);
-+ dput(d2);
-+}
-+#endif /* if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16) */
-+#endif /* if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) */
-+#endif /* __KERNEL__ */
-+
-+/*
-+ * Definitions for user and kernel code
-+ */
-+
-+/* ioctls */
-+
-+#endif /* not __MINI_FO_H_ */
---- /dev/null
-+++ b/fs/mini_fo/mini_fo-merge
-@@ -0,0 +1,180 @@
-+#!/bin/bash
-+#
-+# Copyright (C) 2005 Markus Klotzbuecher <mk@creamnet.de>
-+# 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.
-+#
-+
-+BASE=
-+STO=
-+HELP=
-+DRYRUN=
-+VERBOSE=
-+TMP="/tmp/"
-+META_NAME="META_dAfFgHE39ktF3HD2sr"
-+SKIP_DEL_LIST="skip-delete-list.mini_fo-merge"
-+
-+COMMAND=
-+exec_command()
-+{
-+ if [ x$DRYRUN == "xset" ]; then
-+ echo " would run: $COMMAND"
-+ elif ! [ x$DRYRUN == "xset" ]; then
-+ if [ x$VERBOSE == "xset" ]; then
-+ echo " running: $COMMAND"
-+ fi
-+ eval $COMMAND
-+ fi
-+}
-+
-+usage()
-+{
-+cat <<EOF
-+
-+USAGE: $0 -b <base dir> -s <storage dir>
-+Version 0.1
-+
-+This script merges the contents of a mini_fo storage file system back
-+to the base file system.
-+
-+!!! Warning: This will modify the base filesystem and can destroy data
-+ if used wrongly.
-+
-+Options:
-+ -b <base dir>
-+ the directory of the base file system.
-+
-+ -s <storage dir>
-+ the directory of the storage file system.
-+
-+ -d dry run, will not change anything and print the commands that
-+ would be executed.
-+
-+ -t tmp dir for storing temporary file. default: $TMP
-+
-+ -v show what operations are performed.
-+
-+ -h displays this message.
-+
-+EOF
-+}
-+
-+# parse parameters
-+while getopts hdvt:b:s: OPTS
-+ do
-+ case $OPTS in
-+ h) HELP="set";;
-+ d) DRYRUN="set";;
-+ v) VERBOSE="set";;
-+ b) BASE="$OPTARG";;
-+ s) STO="$OPTARG";;
-+ t) TMP="$OPTARG";;
-+ ?) usage
-+ exit 1;;
-+ esac
-+done
-+
-+if [ "x$HELP" == "xset" ]; then
-+ usage
-+ exit -1
-+fi
-+
-+if ! [ -d "$BASE" ] || ! [ -d "$STO" ]; then
-+ echo -e "$0:\n Error, -s and/or -b argument missing. type $0 -h for help."
-+ exit -1;
-+fi
-+
-+# get full paths
-+pushd $STO; STO=`pwd`; popd
-+pushd $BASE; BASE=`pwd`; popd
-+TMP=${TMP%/}
-+
-+
-+cat<<EOF
-+###############################################################################
-+# mini_fo-merge
-+#
-+# base dir: $BASE
-+# storage dir: $STO
-+# meta filename: $META_NAME
-+# dry run: $DRYRUN
-+# verbose: $VERBOSE
-+# tmp files: $TMP
-+###############################################################################
-+
-+EOF
-+
-+rm $TMP/$SKIP_DEL_LIST
-+
-+# first process all renamed dirs
-+echo "Merging renamed directories..."
-+pushd $STO &> /dev/null
-+find . -name $META_NAME -type f -print0 | xargs -0 -e grep -e '^R ' | tr -s ':R' ' ' | while read ENTRY; do
-+ echo "entry: $ENTRY"
-+ META_FILE=`echo $ENTRY | cut -d ' ' -f 1`
-+ OLD_B_DIR=`echo $ENTRY | cut -d ' ' -f 2 | sed -e 's/\///'`
-+ NEW_NAME=`echo $ENTRY | cut -d ' ' -f 3`
-+ NEW_B_DIR=`echo $META_FILE | sed -e "s/$META_NAME/$NEW_NAME/" | sed -e 's/^\.\///'`
-+ echo "META_FILE: $META_FILE"
-+ echo "OLD_B_DIR: $OLD_B_DIR"
-+ echo "NEW_NAME: $NEW_NAME"
-+ echo "NEW_B_DIR: $NEW_B_DIR"
-+
-+ pushd $BASE &> /dev/null
-+ # remove an existing dir in storage
-+ COMMAND="rm -rf $NEW_B_DIR"; exec_command
-+ COMMAND="cp -R $OLD_B_DIR $NEW_B_DIR"; exec_command
-+ echo ""
-+ popd &> /dev/null
-+
-+ # remember this dir to exclude it from deleting later
-+ echo $NEW_B_DIR >> $TMP/$SKIP_DEL_LIST
-+done
-+
-+# delete all whiteouted files from base
-+echo -e "\nDeleting whiteout'ed files from base file system..."
-+find . -name $META_NAME -type f -print0 | xargs -0 -e grep -e '^D ' | sed -e 's/:D//' | while read ENTRY; do
-+ META_FILE=`echo $ENTRY | cut -d ' ' -f 1`
-+ DEL_NAME=`echo $ENTRY | cut -d ' ' -f 2`
-+ DEL_FILE=`echo $META_FILE | sed -e "s/$META_NAME/$DEL_NAME/" | sed -e 's/^\.\///'`
-+ grep -x $DEL_FILE $TMP/$SKIP_DEL_LIST &> /dev/null
-+ if [ $? -ne 0 ]; then
-+ pushd $BASE &> /dev/null
-+ COMMAND="rm -rf $DEL_FILE"; exec_command
-+ popd &> /dev/null
-+ else
-+ echo " excluding: $DEL_FILE as in skip-del-list."
-+ fi
-+done
-+
-+# create all dirs and update permissions
-+echo -e "\nSetting up directory structures in base file system..."
-+find . -type d | sed -e 's/^\.\///' | while read DIR; do
-+ PERMS=`stat -c %a $DIR`
-+ DIR_UID=`stat -c %u $DIR`
-+ DIR_GID=`stat -c %g $DIR`
-+ pushd $BASE &> /dev/null
-+ if ! [ -d $DIR ]; then
-+ COMMAND="mkdir -p $DIR"; exec_command
-+ fi
-+ COMMAND="chmod $PERMS $DIR"; exec_command
-+ COMMAND="chown $DIR_UID:$DIR_GID $DIR"; exec_command
-+ popd &> /dev/null
-+done
-+
-+# merge all non-directory files
-+echo -e "\nMerging all non-directory files...."
-+for i in b c p f l s; do
-+ find . -type $i | sed -e 's/^\.\///' | grep -v "$META_NAME" | while read FILE; do
-+ pushd $BASE #&> /dev/null
-+ COMMAND="cp -df $STO/$FILE $BASE/$FILE"; exec_command
-+ popd &> /dev/null
-+ done
-+done
-+popd &> /dev/null
-+
-+#rm $TMP/$SKIP_DEL_LIST
-+
-+echo "Done!"
---- /dev/null
-+++ b/fs/mini_fo/mini_fo-overlay
-@@ -0,0 +1,130 @@
-+#!/bin/bash
-+#
-+# Copyright (C) 2005 Markus Klotzbuecher <mk@creamnet.de>
-+# 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.
-+#
-+
-+HELP=
-+SUFF=
-+MNTP=
-+MNT_DIR="/mnt"
-+STO=
-+STO_DIR="/tmp"
-+BASE=
-+
-+usage()
-+{
-+cat <<EOF
-+
-+Usage: $0 [-s suffix] [-d sto_dir_dir] [-m mount point] base_dir
-+Version 0.1
-+
-+This script overlays the given base directory using the mini_fo file
-+system. If only the base directory base_dir is given, $0
-+will use a storage directory called "sto-<base_dir_name>" in $STO_DIR,
-+and mount point "mini_fo-<base_dir_dir>" in $MNT_DIR.
-+
-+Options:
-+ -s <suffix>
-+ add given suffix to storage directory and the mount
-+ point. This is usefull for overlaying one base directory
-+ several times and avoiding conflicts with storage directory
-+ names and mount points.
-+
-+ -d <sto_dir_dir>
-+ change the directory in which the storage directory will be
-+ created (default is currently "$STO_DIR".
-+
-+ -m <mount point>
-+ use an alternative directory to create the mini_fo
-+ mountpoint (default is currently "$MNT_DIR".
-+
-+ -h displays this message.
-+
-+EOF
-+exit 1;
-+}
-+
-+while getopts hm:s:d: OPTS
-+ do
-+ case $OPTS in
-+ s) SUFF="$OPTARG";;
-+ d) STO_DIR="$OPTARG";;
-+ m) MNT_DIR="$OPTARG";;
-+ h) HELP="set";;
-+ ?) usage
-+ exit 1;;
-+ esac
-+done
-+shift $(($OPTIND - 1))
-+
-+BASE="$1"
-+
-+if [ "x$HELP" == "xset" ]; then
-+ usage
-+ exit -1
-+fi
-+
-+# fix suffix
-+if [ "x$SUFF" != "x" ]; then
-+ SUFF="-$SUFF"
-+fi
-+
-+# kill trailing slashes
-+MNT_DIR=${MNT_DIR%/}
-+STO_DIR=${STO_DIR%/}
-+BASE=${BASE%/}
-+
-+
-+if ! [ -d "$BASE" ]; then
-+ echo "invalid base dir $BASE, run $0 -h for help."
-+ exit -1
-+fi
-+
-+# check opts
-+if ! [ -d "$MNT_DIR" ]; then
-+ echo "invalid mount dir $MNT_DIR, run $0 -h for help."
-+ exit -1
-+fi
-+
-+if ! [ -d "$STO_DIR" ]; then
-+ echo "invalid sto_dir_dir $STO_DIR, run $0 -h for help."
-+ exit -1
-+fi
-+
-+MNTP="$MNT_DIR/mini_fo-`basename $BASE`$SUFF"
-+STO="$STO_DIR/sto-`basename $BASE`$SUFF"
-+
-+# create the mount point if it doesn't exist
-+mkdir -p $MNTP
-+if [ $? -ne 0 ]; then
-+ echo "Error, failed to create mount point $MNTP"
-+fi
-+
-+mkdir -p $STO
-+if [ $? -ne 0 ]; then
-+ echo "Error, failed to create storage dir $STO"
-+fi
-+
-+# check if fs is already mounted
-+mount | grep mini_fo | grep $MNTP &> /dev/null
-+if [ $? -eq 0 ]; then
-+ echo "Error, existing mini_fo mount at $MNTP."
-+ exit -1
-+fi
-+
-+mount | grep mini_fo | grep $STO &> /dev/null
-+if [ $? -eq 0 ]; then
-+ echo "Error, $STO seems to be used already."
-+ exit -1
-+fi
-+
-+# mount
-+mount -t mini_fo -o base=$BASE,sto=$STO $BASE $MNTP
-+
-+if [ $? -ne 0 ]; then
-+ echo "Error, mounting failed, maybe no permisson to mount?"
-+fi
---- /dev/null
-+++ b/fs/mini_fo/mmap.c
-@@ -0,0 +1,637 @@
-+/*
-+ * Copyright (c) 1997-2003 Erez Zadok
-+ * Copyright (c) 2001-2003 Stony Brook University
-+ *
-+ * For specific licensing information, see the COPYING file distributed with
-+ * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
-+ *
-+ * This Copyright notice must be kept intact and distributed with all
-+ * fistgen sources INCLUDING sources generated by fistgen.
-+ */
-+/*
-+ * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
-+ *
-+ * 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.
-+ */
-+
-+/*
-+ * $Id$
-+ */
-+
-+#ifdef HAVE_CONFIG_H
-+# include <config.h>
-+#endif /* HAVE_CONFIG_H */
-+
-+#include "fist.h"
-+#include "mini_fo.h"
-+
-+
-+#ifdef FIST_COUNT_WRITES
-+/* for counting writes in the middle vs. regular writes */
-+unsigned long count_writes = 0, count_writes_middle = 0;
-+#endif /* FIST_COUNT_WRITES */
-+
-+/* forward declaration of commit write and prepare write */
-+STATIC int mini_fo_commit_write(file_t *file, page_t *page, unsigned from, unsigned to);
-+STATIC int mini_fo_prepare_write(file_t *file, page_t *page, unsigned from, unsigned to);
-+
-+
-+/*
-+ * Function for handling creation of holes when lseek-ing past the
-+ * end of the file and then writing some data.
-+ */
-+int
-+mini_fo_fill_zeros(file_t* file, page_t *page, unsigned from)
-+{
-+ int err = 0;
-+ dentry_t *dentry = file->f_dentry;
-+ inode_t *inode = dentry->d_inode;
-+ page_t *tmp_page;
-+ int index;
-+
-+ print_entry_location();
-+
-+ for (index = inode->i_size >> PAGE_CACHE_SHIFT; index < page->index; index++) {
-+ tmp_page = mini_fo_get1page(file, index);
-+ if (IS_ERR(tmp_page)) {
-+ err = PTR_ERR(tmp_page);
-+ goto out;
-+ }
-+
-+ /*
-+ * zero out rest of the contents of the page between the appropriate
-+ * offsets.
-+ */
-+ memset((char*)page_address(tmp_page) + (inode->i_size & ~PAGE_CACHE_MASK), 0, PAGE_CACHE_SIZE - (inode->i_size & ~PAGE_CACHE_MASK));
-+
-+ if (! (err = mini_fo_prepare_write(file, tmp_page, 0, PAGE_CACHE_SIZE)))
-+ err = mini_fo_commit_write(file, tmp_page, 0, PAGE_CACHE_SIZE);
-+
-+ page_cache_release(tmp_page);
-+ if (err < 0)
-+ goto out;
-+ if (current->need_resched)
-+ schedule();
-+ }
-+
-+ /* zero out appropriate parts of last page */
-+
-+ /*
-+ * if the encoding type is block, then adjust the 'from' (where the
-+ * zeroing will start) offset appropriately
-+ */
-+ from = from & (~(FIST_ENCODING_BLOCKSIZE - 1));
-+
-+ if ((from - (inode->i_size & ~PAGE_CACHE_MASK)) > 0) {
-+
-+ memset((char*)page_address(page) + (inode->i_size & ~PAGE_CACHE_MASK), 0, from - (inode->i_size & ~PAGE_CACHE_MASK));
-+ if (! (err = mini_fo_prepare_write(file, page, 0, PAGE_CACHE_SIZE)))
-+ err = mini_fo_commit_write(file, page, 0, PAGE_CACHE_SIZE);
-+
-+ if (err < 0)
-+ goto out;
-+ if (current->need_resched)
-+ schedule();
-+ }
-+
-+ out:
-+ print_exit_status(err);
-+ return err;
-+}
-+
-+
-+
-+STATIC int
-+mini_fo_writepage(page_t *page)
-+{
-+ int err = -EIO;
-+ inode_t *inode;
-+ inode_t *hidden_inode;
-+ page_t *hidden_page;
-+ char *kaddr, *hidden_kaddr;
-+
-+ print_entry_location();
-+
-+ inode = page->mapping->host;
-+ hidden_inode = itohi(inode);
-+
-+ /*
-+ * writepage is called when shared mmap'ed files need to write
-+ * their pages, while prepare/commit_write are called from the
-+ * non-paged write() interface. (However, in 2.3 the two interfaces
-+ * share the same cache, while in 2.2 they didn't.)
-+ *
-+ * So we pretty much have to duplicate much of what commit_write does.
-+ */
-+
-+ /* find lower page (returns a locked page) */
-+ hidden_page = grab_cache_page(hidden_inode->i_mapping, page->index);
-+ if (!hidden_page)
-+ goto out;
-+
-+ /* get page address, and encode it */
-+ kaddr = (char *) kmap(page);
-+ hidden_kaddr = (char*) kmap(hidden_page);
-+ mini_fo_encode_block(kaddr, hidden_kaddr, PAGE_CACHE_SIZE, inode, inode->i_sb, page->index);
-+ /* if encode_block could fail, then return error */
-+ kunmap(page);
-+ kunmap(hidden_page);
-+
-+ /* call lower writepage (expects locked page) */
-+ err = hidden_inode->i_mapping->a_ops->writepage(hidden_page);
-+
-+ /*
-+ * update mtime and ctime of lower level file system
-+ * mini_fo' mtime and ctime are updated by generic_file_write
-+ */
-+ hidden_inode->i_mtime = hidden_inode->i_ctime = CURRENT_TIME;
-+
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,1)
-+ UnlockPage(hidden_page); /* b/c grab_cache_page locked it */
-+# endif /* kernel older than 2.4.1 */
-+ page_cache_release(hidden_page); /* b/c grab_cache_page increased refcnt */
-+
-+ if (err)
-+ ClearPageUptodate(page);
-+ else
-+ SetPageUptodate(page);
-+ out:
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,1)
-+ UnlockPage(page);
-+# endif /* kernel 2.4.1 and newer */
-+ print_exit_status(err);
-+ return err;
-+}
-+
-+
-+/*
-+ * get one page from cache or lower f/s, return error otherwise.
-+ * returns unlocked, up-to-date page (if ok), with increased refcnt.
-+ */
-+page_t *
-+mini_fo_get1page(file_t *file, int index)
-+{
-+ page_t *page;
-+ dentry_t *dentry;
-+ inode_t *inode;
-+ struct address_space *mapping;
-+ int err;
-+
-+ print_entry_location();
-+
-+ dentry = file->f_dentry; /* CPW: Moved below print_entry_location */
-+ inode = dentry->d_inode;
-+ mapping = inode->i_mapping;
-+
-+ fist_dprint(8, "%s: read page index %d pid %d\n", __FUNCTION__, index, current->pid);
-+ if (index < 0) {
-+ printk("%s BUG: index=%d\n", __FUNCTION__, index);
-+ page = ERR_PTR(-EIO);
-+ goto out;
-+ }
-+ page = read_cache_page(mapping,
-+ index,
-+ (filler_t *) mapping->a_ops->readpage,
-+ (void *) file);
-+ if (IS_ERR(page))
-+ goto out;
-+ wait_on_page(page);
-+ if (!Page_Uptodate(page)) {
-+ lock_page(page);
-+ err = mapping->a_ops->readpage(file, page);
-+ if (err) {
-+ page = ERR_PTR(err);
-+ goto out;
-+ }
-+ wait_on_page(page);
-+ if (!Page_Uptodate(page)) {
-+ page = ERR_PTR(-EIO);
-+ goto out;
-+ }
-+ }
-+
-+ out:
-+ print_exit_pointer(page);
-+ return page;
-+}
-+
-+
-+/*
-+ * get one page from cache or lower f/s, return error otherwise.
-+ * similar to get1page, but doesn't guarantee that it will return
-+ * an unlocked page.
-+ */
-+page_t *
-+mini_fo_get1page_cached(file_t *file, int index)
-+{
-+ page_t *page;
-+ dentry_t *dentry;
-+ inode_t *inode;
-+ struct address_space *mapping;
-+ int err;
-+
-+ print_entry_location();
-+
-+ dentry = file->f_dentry; /* CPW: Moved below print_entry_location */
-+ inode = dentry->d_inode;
-+ mapping = inode->i_mapping;
-+
-+ fist_dprint(8, "%s: read page index %d pid %d\n", __FUNCTION__, index, current->pid);
-+ if (index < 0) {
-+ printk("%s BUG: index=%d\n", __FUNCTION__, index);
-+ page = ERR_PTR(-EIO);
-+ goto out;
-+ }
-+ page = read_cache_page(mapping,
-+ index,
-+ (filler_t *) mapping->a_ops->readpage,
-+ (void *) file);
-+ if (IS_ERR(page))
-+ goto out;
-+
-+ out:
-+ print_exit_pointer(page);
-+ return page;
-+}
-+
-+
-+/*
-+ * readpage is called from generic_page_read and the fault handler.
-+ * If your file system uses generic_page_read for the read op, it
-+ * must implement readpage.
-+ *
-+ * Readpage expects a locked page, and must unlock it.
-+ */
-+STATIC int
-+mini_fo_do_readpage(file_t *file, page_t *page)
-+{
-+ int err = -EIO;
-+ dentry_t *dentry;
-+ file_t *hidden_file = NULL;
-+ dentry_t *hidden_dentry;
-+ inode_t *inode;
-+ inode_t *hidden_inode;
-+ char *page_data;
-+ page_t *hidden_page;
-+ char *hidden_page_data;
-+ int real_size;
-+
-+ print_entry_location();
-+
-+ dentry = file->f_dentry; /* CPW: Moved below print_entry_location */
-+ if (ftopd(file) != NULL)
-+ hidden_file = ftohf(file);
-+ hidden_dentry = dtohd(dentry);
-+ inode = dentry->d_inode;
-+ hidden_inode = itohi(inode);
-+
-+ fist_dprint(7, "%s: requesting page %d from file %s\n", __FUNCTION__, page->index, dentry->d_name.name);
-+
-+ MALLOC_PAGE_POINTERS(hidden_pages, num_hidden_pages);
-+ MALLOC_PAGEDATA_POINTERS(hidden_pages_data, num_hidden_pages);
-+ FOR_EACH_PAGE
-+ CURRENT_HIDDEN_PAGE = NULL;
-+
-+ /* find lower page (returns a locked page) */
-+ FOR_EACH_PAGE {
-+ fist_dprint(8, "%s: Current page index = %d\n", __FUNCTION__, CURRENT_HIDDEN_PAGEINDEX);
-+ CURRENT_HIDDEN_PAGE = read_cache_page(hidden_inode->i_mapping,
-+ CURRENT_HIDDEN_PAGEINDEX,
-+ (filler_t *) hidden_inode->i_mapping->a_ops->readpage,
-+ (void *) hidden_file);
-+ if (IS_ERR(CURRENT_HIDDEN_PAGE)) {
-+ err = PTR_ERR(CURRENT_HIDDEN_PAGE);
-+ CURRENT_HIDDEN_PAGE = NULL;
-+ goto out_release;
-+ }
-+ }
-+
-+ /*
-+ * wait for the page data to show up
-+ * (signaled by readpage as unlocking the page)
-+ */
-+ FOR_EACH_PAGE {
-+ wait_on_page(CURRENT_HIDDEN_PAGE);
-+ if (!Page_Uptodate(CURRENT_HIDDEN_PAGE)) {
-+ /*
-+ * call readpage() again if we returned from wait_on_page with a
-+ * page that's not up-to-date; that can happen when a partial
-+ * page has a few buffers which are ok, but not the whole
-+ * page.
-+ */
-+ lock_page(CURRENT_HIDDEN_PAGE);
-+ err = hidden_inode->i_mapping->a_ops->readpage(hidden_file,
-+ CURRENT_HIDDEN_PAGE);
-+ if (err) {
-+ CURRENT_HIDDEN_PAGE = NULL;
-+ goto out_release;
-+ }
-+ wait_on_page(CURRENT_HIDDEN_PAGE);
-+ if (!Page_Uptodate(CURRENT_HIDDEN_PAGE)) {
-+ err = -EIO;
-+ goto out_release;
-+ }
-+ }
-+ }
-+
-+ /* map pages, get their addresses */
-+ page_data = (char *) kmap(page);
-+ FOR_EACH_PAGE
-+ CURRENT_HIDDEN_PAGEDATA = (char *) kmap(CURRENT_HIDDEN_PAGE);
-+
-+ /* if decode_block could fail, then return error */
-+ err = 0;
-+ real_size = hidden_inode->i_size - (page->index << PAGE_CACHE_SHIFT);
-+ if (real_size <= 0)
-+ memset(page_data, 0, PAGE_CACHE_SIZE);
-+ else if (real_size < PAGE_CACHE_SIZE) {
-+ mini_fo_decode_block(hidden_page_data, page_data, real_size, inode, inode->i_sb, page->index);
-+ memset(page_data + real_size, 0, PAGE_CACHE_SIZE - real_size);
-+ } else
-+ mini_fo_decode_block(hidden_page_data, page_data, PAGE_CACHE_SIZE, inode, inode->i_sb, page->index);
-+
-+ FOR_EACH_PAGE
-+ kunmap(CURRENT_HIDDEN_PAGE);
-+ kunmap(page);
-+
-+ out_release:
-+ FOR_EACH_PAGE
-+ if (CURRENT_HIDDEN_PAGE)
-+ page_cache_release(CURRENT_HIDDEN_PAGE); /* undo read_cache_page */
-+
-+ FREE_PAGE_POINTERS(hidden_pages, num_hidden_pages);
-+ FREE_PAGEDATA_POINTERS(hidden_pages_data, num_hidden_pages);
-+
-+ out:
-+ if (err == 0)
-+ SetPageUptodate(page);
-+ else
-+ ClearPageUptodate(page);
-+
-+ print_exit_status(err);
-+ return err;
-+}
-+
-+
-+STATIC int
-+mini_fo_readpage(file_t *file, page_t *page)
-+{
-+ int err;
-+ print_entry_location();
-+
-+ err = mini_fo_do_readpage(file, page);
-+
-+ /*
-+ * we have to unlock our page, b/c we _might_ have gotten a locked page.
-+ * but we no longer have to wakeup on our page here, b/c UnlockPage does
-+ * it
-+ */
-+ UnlockPage(page);
-+
-+ print_exit_status(err);
-+ return err;
-+}
-+
-+
-+STATIC int
-+mini_fo_prepare_write(file_t *file, page_t *page, unsigned from, unsigned to)
-+{
-+ int err = 0;
-+
-+ print_entry_location();
-+
-+ /*
-+ * we call kmap(page) only here, and do the kunmap
-+ * and the actual downcalls, including unlockpage and uncache
-+ * in commit_write.
-+ */
-+ kmap(page);
-+
-+ /* fast path for whole page writes */
-+ if (from == 0 && to == PAGE_CACHE_SIZE)
-+ goto out;
-+ /* read the page to "revalidate" our data */
-+ /* call the helper function which doesn't unlock the page */
-+ if (!Page_Uptodate(page))
-+ err = mini_fo_do_readpage(file, page);
-+
-+ out:
-+ print_exit_status(err);
-+ return err;
-+}
-+
-+
-+
-+STATIC int
-+mini_fo_commit_write(file_t *file, page_t *page, unsigned from, unsigned to)
-+{
-+ int err = -ENOMEM;
-+ inode_t *inode;
-+ inode_t *hidden_inode;
-+ page_t *hidden_page;
-+ file_t *hidden_file = NULL;
-+ loff_t pos;
-+ unsigned bytes = to - from;
-+ unsigned hidden_from, hidden_to, hidden_bytes;
-+
-+ print_entry_location();
-+
-+ inode = page->mapping->host; /* CPW: Moved below print_entry_location */
-+ hidden_inode = itohi(inode);
-+
-+ ASSERT(file != NULL);
-+ /*
-+ * here we have a kmapped page, with data from the user copied
-+ * into it. we need to encode_block it, and then call the lower
-+ * commit_write. We also need to simulate same behavior of
-+ * generic_file_write, and call prepare_write on the lower f/s first.
-+ */
-+#ifdef FIST_COUNT_WRITES
-+ count_writes++;
-+# endif /* FIST_COUNT_WRITES */
-+
-+ /* this is append and/or extend -- we can't have holes so fill them in */
-+ if (page->index > (hidden_inode->i_size >> PAGE_CACHE_SHIFT)) {
-+ page_t *tmp_page;
-+ int index;
-+ for (index = hidden_inode->i_size >> PAGE_CACHE_SHIFT; index < page->index; index++) {
-+ tmp_page = mini_fo_get1page(file, index);
-+ if (IS_ERR(tmp_page)) {
-+ err = PTR_ERR(tmp_page);
-+ goto out;
-+ }
-+ /* zero out the contents of the page at the appropriate offsets */
-+ memset((char*)page_address(tmp_page) + (inode->i_size & ~PAGE_CACHE_MASK), 0, PAGE_CACHE_SIZE - (inode->i_size & ~PAGE_CACHE_MASK));
-+ if (!(err = mini_fo_prepare_write(file, tmp_page, 0, PAGE_CACHE_SIZE)))
-+ err = mini_fo_commit_write(file, tmp_page, 0, PAGE_CACHE_SIZE);
-+ page_cache_release(tmp_page);
-+ if (err < 0)
-+ goto out;
-+ if (current->need_resched)
-+ schedule();
-+ }
-+ }
-+
-+ if (ftopd(file) != NULL)
-+ hidden_file = ftohf(file);
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_lock(&hidden_inode->i_mutex);
-+#else
-+ down(&hidden_inode->i_sem);
-+#endif
-+ /* find lower page (returns a locked page) */
-+ hidden_page = grab_cache_page(hidden_inode->i_mapping, page->index);
-+ if (!hidden_page)
-+ goto out;
-+
-+#if FIST_ENCODING_BLOCKSIZE > 1
-+# error encoding_blocksize greater than 1 is not yet supported
-+# endif /* FIST_ENCODING_BLOCKSIZE > 1 */
-+
-+ hidden_from = from & (~(FIST_ENCODING_BLOCKSIZE - 1));
-+ hidden_to = ((to + FIST_ENCODING_BLOCKSIZE - 1) & (~(FIST_ENCODING_BLOCKSIZE - 1)));
-+ if ((page->index << PAGE_CACHE_SHIFT) + to > hidden_inode->i_size) {
-+
-+ /*
-+ * if this call to commit_write had introduced holes and the code
-+ * for handling holes was invoked, then the beginning of this page
-+ * must be zeroed out
-+ * zero out bytes from 'size_of_file%pagesize' to 'from'.
-+ */
-+ if ((hidden_from - (inode->i_size & ~PAGE_CACHE_MASK)) > 0)
-+ memset((char*)page_address(page) + (inode->i_size & ~PAGE_CACHE_MASK), 0, hidden_from - (inode->i_size & ~PAGE_CACHE_MASK));
-+
-+ }
-+ hidden_bytes = hidden_to - hidden_from;
-+
-+ /* call lower prepare_write */
-+ err = -EINVAL;
-+ if (hidden_inode->i_mapping &&
-+ hidden_inode->i_mapping->a_ops &&
-+ hidden_inode->i_mapping->a_ops->prepare_write)
-+ err = hidden_inode->i_mapping->a_ops->prepare_write(hidden_file,
-+ hidden_page,
-+ hidden_from,
-+ hidden_to);
-+ if (err)
-+ /* don't leave locked pages behind, esp. on an ENOSPC */
-+ goto out_unlock;
-+
-+ fist_dprint(8, "%s: encoding %d bytes\n", __FUNCTION__, hidden_bytes);
-+ mini_fo_encode_block((char *) page_address(page) + hidden_from, (char*) page_address(hidden_page) + hidden_from, hidden_bytes, inode, inode->i_sb, page->index);
-+ /* if encode_block could fail, then goto unlock and return error */
-+
-+ /* call lower commit_write */
-+ err = hidden_inode->i_mapping->a_ops->commit_write(hidden_file,
-+ hidden_page,
-+ hidden_from,
-+ hidden_to);
-+
-+ if (err < 0)
-+ goto out_unlock;
-+
-+ err = bytes; /* convert error to no. of bytes */
-+
-+ inode->i_blocks = hidden_inode->i_blocks;
-+ /* we may have to update i_size */
-+ pos = (page->index << PAGE_CACHE_SHIFT) + to;
-+ if (pos > inode->i_size)
-+ inode->i_size = pos;
-+
-+ /*
-+ * update mtime and ctime of lower level file system
-+ * mini_fo' mtime and ctime are updated by generic_file_write
-+ */
-+ hidden_inode->i_mtime = hidden_inode->i_ctime = CURRENT_TIME;
-+
-+ mark_inode_dirty_sync(inode);
-+
-+ out_unlock:
-+ UnlockPage(hidden_page);
-+ page_cache_release(hidden_page);
-+ kunmap(page); /* kmap was done in prepare_write */
-+ out:
-+ /* we must set our page as up-to-date */
-+ if (err < 0)
-+ ClearPageUptodate(page);
-+ else
-+ SetPageUptodate(page);
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_unlock(&hidden_inode->i_mutex);
-+#else
-+ up(&hidden_inode->i_sem);
-+#endif
-+ print_exit_status(err);
-+ return err; /* assume all is ok */
-+}
-+
-+
-+STATIC int
-+mini_fo_bmap(struct address_space *mapping, long block)
-+{
-+ int err = 0;
-+ inode_t *inode;
-+ inode_t *hidden_inode;
-+
-+ print_entry_location();
-+
-+ inode = (inode_t *) mapping->host;
-+ hidden_inode = itohi(inode);
-+
-+ if (hidden_inode->i_mapping->a_ops->bmap)
-+ err = hidden_inode->i_mapping->a_ops->bmap(hidden_inode->i_mapping, block);
-+ print_exit_location();
-+ return err;
-+}
-+
-+
-+/*
-+ * This function is copied verbatim from mm/filemap.c.
-+ * XXX: It should be simply moved to some header file instead -- bug Al about it!
-+ */
-+static inline int sync_page(struct page *page)
-+{
-+ struct address_space *mapping = page->mapping;
-+
-+ if (mapping && mapping->a_ops && mapping->a_ops->sync_page)
-+ return mapping->a_ops->sync_page(page);
-+ return 0;
-+}
-+
-+
-+/*
-+ * XXX: we may not need this function if not FIST_FILTER_DATA.
-+ * FIXME: for FIST_FILTER_SCA, get all lower pages and sync them each.
-+ */
-+STATIC int
-+mini_fo_sync_page(page_t *page)
-+{
-+ int err = 0;
-+ inode_t *inode;
-+ inode_t *hidden_inode;
-+ page_t *hidden_page;
-+
-+ print_entry_location();
-+
-+ inode = page->mapping->host; /* CPW: Moved below print_entry_location */
-+ hidden_inode = itohi(inode);
-+
-+ /* find lower page (returns a locked page) */
-+ hidden_page = grab_cache_page(hidden_inode->i_mapping, page->index);
-+ if (!hidden_page)
-+ goto out;
-+
-+ err = sync_page(hidden_page);
-+
-+ UnlockPage(hidden_page); /* b/c grab_cache_page locked it */
-+ page_cache_release(hidden_page); /* b/c grab_cache_page increased refcnt */
-+
-+ out:
-+ print_exit_status(err);
-+ return err;
-+}
---- /dev/null
-+++ b/fs/mini_fo/README
-@@ -0,0 +1,163 @@
-+README for the mini_fo overlay file system
-+=========================================
-+
-+
-+WHAT IS MINI_FO?
-+----------------
-+
-+mini_fo is a virtual kernel file system that can make read-only
-+file systems writable. This is done by redirecting modifying operations
-+to a writeable location called "storage directory", and leaving the
-+original data in the "base directory" untouched. When reading, the
-+file system merges the modifed and original data so that only the
-+newest versions will appear. This occurs transparently to the user,
-+who can access the data like on any other read-write file system.
-+
-+Base and storage directories may be located on the same or on
-+different partitions and may be of different file system types. While
-+the storage directory obviously needs to be writable, the base may or
-+may not be writable, what doesn't matter as it will no be modified
-+anyway.
-+
-+
-+WHAT IS GOOD FOR?
-+-----------------
-+
-+The primary purpose of the mini_fo file system is to allow easy
-+software updates to embedded systems, that often store their root
-+file system in a read-only flash file system, but there are many
-+more as for example sandboxing, or for allowing live-cds to
-+permanently store information.
-+
-+
-+BUILDING
-+--------
-+This should be simple. Adjust the Makefile to point to the correct
-+kernel headers you want to build the module for. Then:
-+
-+ # make
-+
-+should build "mini_fo.o" for a 2.4 kernel or "mini_fo.ko" for a 2.6
-+kernel.
-+
-+If you are building the module for you current kernel, you can install
-+the module (as root):
-+
-+ # make install
-+
-+or uninstall with
-+
-+ # make uninstall
-+
-+
-+USING THE FILE SYSTEM
-+--------------------
-+
-+the general mount syntax is:
-+
-+ mount -t mini_fo -o base=<base directory>,sto=<storage directory>\
-+ <base directory> <mount point>
-+
-+Example:
-+
-+You have mounted a cdrom to /mnt/cdrom and want to modifiy some files
-+on it:
-+
-+load the module (as root)
-+
-+ # insmod mini_fo.o for a 2.4 kernel or
-+
-+ # insmod mini_fo.ko for a 2.6 kernel
-+
-+
-+create a storage dir in tmp and a mountpoint for mini_fo:
-+
-+ # mkdir /tmp/sto
-+ # mkdir /mnt/mini_fo
-+
-+and mount the mini_fo file system:
-+
-+ # mount -t mini_fo -o base=/mnt/cdrom,sto=/tmp/sto /mnt/cdrom /mnt/mini_fo
-+
-+
-+Now the data stored on the cd can be accessed via the mini_fo
-+mountpoint just like any read-write file system, files can be modified
-+and deleted, new ones can be created and so on. When done unmount the
-+file system:
-+
-+ # unmount /mnt/mini_fo
-+
-+Note that if the file system is mounted again using the same storage
-+file system, of course it will appear in the modified state again. If
-+you remount it using an new empty storage directory, it will be
-+unmodified. Therefore by executing:
-+
-+ # cd /tmp/sto
-+ # rm -rf *
-+
-+you can nuke all the changes you made to the original file system. But
-+ remember NEVER do this while the mini_fo file system is mounted!
-+
-+
-+Alternatively you can use the mini_fo-overlay bash script, that
-+simplifies managing mini_fo mounts. See TOOLS Section.
-+
-+
-+TOOLS
-+-----
-+
-+mini_fo-merge (experimental):
-+
-+This is a bash script that will merge changes contained in the storage
-+directory back to the base directory. This allows mini_fo to function
-+as a cache file system by overlaying a slow (network, ...) file system
-+and using a fast (ramdisk, ...) as storage. When done, changes can be
-+merged back to the (slow) base with mini_fo-merge. See "mini_fo-merge
-+-h" for details.
-+
-+It can be usefull for merging changes back after a successfull test
-+(patches, software updates...)
-+
-+
-+mini_fo-overlay:
-+
-+This bash script simplifies managing one or more mini_fo mounts. For
-+overlaying a directory called "basedir1", you can just call:
-+
-+ # mini_fo-overlay basedir1
-+
-+This will mount mini_fo with "basedir1" as base, "/tmp/sto-basedir1/"
-+as storage to "/mnt/mini_fo-basedir1/". It has more options though,
-+type "mini_fo-overlay -h" for details.
-+
-+
-+DOCUMENTATION, REPORTING BUGS, GETTING HELP
-+-------------------------------------------
-+
-+Please visit the mini_fo project page at:
-+
-+http://www.denx.de/twiki/bin/view/Know/MiniFOHome
-+
-+
-+WARNINGS
-+--------
-+
-+Never modify the base or the storage directorys while the mini_fo
-+file system is mounted, or you might crash you system. Simply accessing
-+and reading should not cause any trouble.
-+
-+Exporting a mini_fo mount point via NFS has not been tested, and may
-+or may not work.
-+
-+Check the RELEASE_NOTES for details on bugs and features.
-+
-+
-+
-+Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
-+
-+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.
-+
-+
---- /dev/null
-+++ b/fs/mini_fo/RELEASE_NOTES
-@@ -0,0 +1,111 @@
-+Release: mini_fo-0.6.1 (v0-6-1)
-+Date: 21.09.2005
-+
-+
-+Changes:
-+--------
-+v0-6-1:
-+
-+- bugfixes (see ChangeLog)
-+
-+- two helper scripts "mini_fo_merge" and "mini_fo_overlay" (see
-+ README for details).
-+
-+v0-6-0:
-+
-+- Support for 2.4 and 2.6 (see Makefile)
-+
-+- Partial hard link support (creating works as expected, but already
-+ existing links in the base file system will be treated as if they
-+ were individual files).
-+
-+- Various bugfixes and cleanups.
-+
-+
-+v0-6-0-pre1:
-+
-+- This is mini_fo-0-6-0-pre1! This release is a complete rewrite of
-+ many vital mini_fo parts such as the old whiteout list code which
-+ has been replaced by the new META subsystem.
-+
-+- Light weight directory renaming implemented. This means if a
-+ directory is renamed via the mini_fo filesystem this will no longer
-+ result in a complete copy in storage, instead only one empty
-+ directory will be created. All base filed contained in the original
-+ directory stay there until modified.
-+
-+- Special files (creating, renaming, deleting etc.) now working.
-+
-+- Many bugfixes and cleanup, mini_fo is now a lot more stable.
-+
-+
-+v0-5-10:
-+
-+- Final release of the 0-5-* versions. Next will be a complete rewrite
-+ of many features. This release contains several bugfixes related to
-+ directory renaming.
-+
-+
-+v0-5-10-pre6:
-+
-+- Lots of cleanup and several bugfixes related to directory deleting
-+
-+- Directory renaming suddenly works, what is most likely due to the
-+ fact tha that "mv" is smart: if the classic rename doesn't work it
-+ will assume that source and target file are on different fs and will
-+ copy the directory and try to remove the source directory. Until
-+ directory removing wasn't implemented, it would fail to do this and
-+ rollback.
-+ So, directory renaming works for now, but it doesn't yet do what you
-+ would expect from a overlay fs, so use with care.
-+
-+
-+v0-5-10-pre5:
-+
-+- implemented directory deleting
-+- made parsing of mount options more stable
-+- New format of mount options! (See README)
-+- I can't reproduce the unknown panic with 2.4.25 anymore, so I'll
-+ happily assume it never existed!
-+
-+
-+Implemented features:
-+---------------------
-+
-+- creating hard links (see BUGS on already existing hard links)
-+- lightweight directory renaming
-+- renaming device files, pipes, sockets, etc.
-+- creating, renaming, deleting of special files
-+- deleting directorys
-+- general directory reading (simple "ls" )
-+- creating files in existing directorys
-+- creating directorys
-+- renaming files.
-+- reading and writing files (involves opening)
-+- appending to files (creates copy in storage)
-+- deleting files
-+- llseek works too, what allows editors to work
-+- persistency (a deleted file stay deleted over remounts)
-+- use of symbolic links
-+- creating of device files
-+
-+
-+Not (yet) implemented features:
-+-------------------------------
-+
-+- full hard link support.
-+
-+
-+
-+BUGS:
-+-----
-+
-+Hard links in the base file system will be treated as individual
-+files, not as links to one inode.
-+
-+The main problem with hard links isn't allowing to create them, but
-+their pure existence. If you modify a base hard link, the changes made
-+will only show up on this link, the other link will remain in the
-+original state. I hope to fix this someday. Please note that this does
-+not effect the special hard links '.' and '..', that are handled
-+seperately by the lower fs.
---- /dev/null
-+++ b/fs/mini_fo/state.c
-@@ -0,0 +1,620 @@
-+/*
-+ * Copyright (C) 2005 Markus Klotzbuecher <mk@creamnet.de>
-+ *
-+ * 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.
-+ */
-+
-+#ifdef HAVE_CONFIG_H
-+# include <config.h>
-+#endif /* HAVE_CONFIG_H */
-+
-+#include "fist.h"
-+#include "mini_fo.h"
-+
-+
-+/* create the storage file, setup new states */
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
-+int create_sto_reg_file(dentry_t *dentry, int mode, struct nameidata *nd)
-+#else
-+int create_sto_reg_file(dentry_t *dentry, int mode)
-+#endif
-+{
-+ int err = 0;
-+ inode_t *dir;
-+ dentry_t *hidden_sto_dentry;
-+ dentry_t *hidden_sto_dir_dentry;
-+
-+ if(exists_in_storage(dentry)) {
-+ printk(KERN_CRIT "mini_fo: create_sto_file: wrong type or state.\n");
-+ err = -EINVAL;
-+ goto out;
-+ }
-+ err = get_neg_sto_dentry(dentry);
-+
-+ if (err) {
-+ printk(KERN_CRIT "mini_fo: create_sto_file: ERROR getting neg. sto dentry.\n");
-+ goto out;
-+ }
-+
-+ dir = dentry->d_parent->d_inode;
-+ hidden_sto_dentry = dtohd2(dentry);
-+
-+ /* lock parent */
-+ hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
-+#else
-+ down(&hidden_sto_dir_dentry->d_inode->i_sem);
-+#endif
-+
-+ err = PTR_ERR(hidden_sto_dir_dentry);
-+ if (IS_ERR(hidden_sto_dir_dentry))
-+ goto out;
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
-+ err = vfs_create(hidden_sto_dir_dentry->d_inode,
-+ hidden_sto_dentry,
-+ mode, nd);
-+#else
-+ err = vfs_create(hidden_sto_dir_dentry->d_inode,
-+ hidden_sto_dentry,
-+ mode);
-+#endif
-+ if(err) {
-+ printk(KERN_CRIT "mini_fo: create_sto_file: ERROR creating sto file.\n");
-+ goto out_lock;
-+ }
-+
-+ if(!dtohd2(dentry)->d_inode) {
-+ printk(KERN_CRIT "mini_fo: create_sto_file: ERROR creating sto file [2].\n");
-+ err = -EINVAL;
-+ goto out_lock;
-+ }
-+
-+ /* interpose the new inode */
-+ if(dtost(dentry) == DELETED) {
-+ dtost(dentry) = DEL_REWRITTEN;
-+ err = mini_fo_tri_interpose(NULL, hidden_sto_dentry, dentry, dir->i_sb, 0);
-+ if(err)
-+ goto out_lock;
-+ }
-+ else if(dtost(dentry) == NON_EXISTANT) {
-+ dtost(dentry) = CREATED;
-+ err = mini_fo_tri_interpose(dtohd(dentry), hidden_sto_dentry, dentry, dir->i_sb, 0);
-+ if(err)
-+ goto out_lock;
-+ }
-+ else if(dtost(dentry) == UNMODIFIED) {
-+ dtost(dentry) = MODIFIED;
-+ /* interpose on new inode */
-+ if(itohi2(dentry->d_inode) != NULL) {
-+ printk(KERN_CRIT "mini_fo: create_sto_file: invalid inode detected.\n");
-+ err = -EINVAL;
-+ goto out_lock;
-+ }
-+ itohi2(dentry->d_inode) = igrab(dtohd2(dentry)->d_inode);
-+ }
-+ fist_copy_attr_timesizes(dentry->d_parent->d_inode,
-+ hidden_sto_dir_dentry->d_inode);
-+
-+ out_lock:
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
-+#else
-+ up(&hidden_sto_dir_dentry->d_inode->i_sem);
-+#endif
-+ dput(hidden_sto_dir_dentry);
-+ out:
-+ return err;
-+}
-+
-+/* create the sto dir, setup states */
-+int create_sto_dir(dentry_t *dentry, int mode)
-+{
-+ int err = 0;
-+ inode_t *dir;
-+ dentry_t *hidden_sto_dentry;
-+ dentry_t *hidden_sto_dir_dentry;
-+
-+ /* had to take the "!S_ISDIR(mode))" check out, because it failed */
-+ if(exists_in_storage(dentry)) {
-+ printk(KERN_CRIT "mini_fo: create_sto_dir: wrong type or state.\\
-+n");
-+ err = -EINVAL;
-+ goto out;
-+ }
-+
-+ err = get_neg_sto_dentry(dentry);
-+ if(err) {
-+ err = -EINVAL;
-+ goto out;
-+ }
-+
-+ dir = dentry->d_parent->d_inode;
-+ hidden_sto_dentry = dtohd2(dentry);
-+
-+ /* was: hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry); */
-+ hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
-+#else
-+ down(&hidden_sto_dir_dentry->d_inode->i_sem);
-+#endif
-+
-+ err = PTR_ERR(hidden_sto_dir_dentry);
-+ if (IS_ERR(hidden_sto_dir_dentry))
-+ goto out;
-+
-+ err = vfs_mkdir(hidden_sto_dir_dentry->d_inode,
-+ hidden_sto_dentry,
-+ mode);
-+ if(err) {
-+ printk(KERN_CRIT "mini_fo: create_sto_dir: ERROR creating sto dir.\n");
-+ goto out_lock;
-+ }
-+
-+ if(!dtohd2(dentry)->d_inode) {
-+ printk(KERN_CRIT "mini_fo: create_sto_dir: ERROR creating sto dir [2].\n");
-+ err = -EINVAL;
-+ goto out_lock;
-+ }
-+
-+ /* interpose the new inode */
-+ if(dtost(dentry) == DELETED) {
-+ dtost(dentry) = DEL_REWRITTEN;
-+ err = mini_fo_tri_interpose(NULL, hidden_sto_dentry, dentry, dir->i_sb, 0);
-+ if(err)
-+ goto out_lock;
-+ }
-+ else if(dtopd(dentry)->state == NON_EXISTANT) {
-+ dtopd(dentry)->state = CREATED;
-+ err = mini_fo_tri_interpose(dtohd(dentry), hidden_sto_dentry, dentry, dir->i_sb, 0);
-+ if(err)
-+ goto out_lock;
-+ }
-+ else if(dtopd(dentry)->state == UNMODIFIED) {
-+ dtopd(dentry)->state = MODIFIED;
-+ /* interpose on new inode */
-+ if(itohi2(dentry->d_inode) != NULL) {
-+ printk(KERN_CRIT "mini_fo: create_sto_dir: ERROR, invalid inode detected.\n");
-+ err = -EINVAL;
-+ goto out_lock;
-+ }
-+ itohi2(dentry->d_inode) = igrab(dtohd2(dentry)->d_inode);
-+ }
-+
-+ fist_copy_attr_timesizes(dir, hidden_sto_dir_dentry->d_inode);
-+
-+ /* initalize the wol list */
-+ itopd(dentry->d_inode)->deleted_list_size = -1;
-+ itopd(dentry->d_inode)->renamed_list_size = -1;
-+ meta_build_lists(dentry);
-+
-+
-+ out_lock:
-+ /* was: unlock_dir(hidden_sto_dir_dentry); */
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
-+#else
-+ up(&hidden_sto_dir_dentry->d_inode->i_sem);
-+#endif
-+ dput(hidden_sto_dir_dentry);
-+ out:
-+ return err;
-+}
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
-+int create_sto_nod(dentry_t *dentry, int mode, dev_t dev)
-+#else
-+int create_sto_nod(dentry_t *dentry, int mode, int dev)
-+#endif
-+{
-+ int err = 0;
-+ inode_t *dir;
-+ dentry_t *hidden_sto_dentry;
-+ dentry_t *hidden_sto_dir_dentry;
-+
-+ if(exists_in_storage(dentry)) {
-+ err = -EEXIST;
-+ goto out;
-+ }
-+ err = get_neg_sto_dentry(dentry);
-+
-+ if (err) {
-+ printk(KERN_CRIT "mini_fo: create_sto_nod: ERROR getting neg. sto dentry.\n");
-+ goto out;
-+ }
-+
-+ dir = dentry->d_parent->d_inode;
-+ hidden_sto_dentry = dtohd2(dentry);
-+
-+ /* lock parent */
-+ hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
-+#else
-+ down(&hidden_sto_dir_dentry->d_inode->i_sem);
-+#endif
-+
-+ err = PTR_ERR(hidden_sto_dir_dentry);
-+ if (IS_ERR(hidden_sto_dir_dentry))
-+ goto out;
-+
-+ err = vfs_mknod(hidden_sto_dir_dentry->d_inode, hidden_sto_dentry, mode, dev);
-+ if(err)
-+ goto out_lock;
-+
-+ if(!dtohd2(dentry)->d_inode) {
-+ printk(KERN_CRIT "mini_fo: create_sto_nod: creating storage inode failed [1].\n");
-+ err = -EINVAL; /* return something indicating failure */
-+ goto out_lock;
-+ }
-+
-+ /* interpose the new inode */
-+ if(dtost(dentry) == DELETED) {
-+ dtost(dentry) = DEL_REWRITTEN;
-+ err = mini_fo_tri_interpose(NULL, hidden_sto_dentry, dentry, dir->i_sb, 0);
-+ if(err)
-+ goto out_lock;
-+ }
-+ else if(dtost(dentry) == NON_EXISTANT) {
-+ dtost(dentry) = CREATED;
-+ err = mini_fo_tri_interpose(dtohd(dentry), hidden_sto_dentry, dentry, dir->i_sb, 0);
-+ if(err)
-+ goto out_lock;
-+ }
-+ else if(dtost(dentry) == UNMODIFIED) {
-+ dtost(dentry) = MODIFIED;
-+ /* interpose on new inode */
-+ if(itohi2(dentry->d_inode) != NULL) {
-+ printk(KERN_CRIT "mini_fo: create_sto_nod: error, invalid inode detected.\n");
-+ err = -EINVAL;
-+ goto out_lock;
-+ }
-+ itohi2(dentry->d_inode) = igrab(dtohd2(dentry)->d_inode);
-+ }
-+
-+ fist_copy_attr_timesizes(dir, hidden_sto_dir_dentry->d_inode);
-+
-+ out_lock:
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
-+#else
-+ up(&hidden_sto_dir_dentry->d_inode->i_sem);
-+#endif
-+ dput(hidden_sto_dir_dentry);
-+ out:
-+ return err;
-+}
-+
-+
-+/* unimplemented (and possibly not usefull):
-+
-+ nondir-del_to_del_rew
-+ nondir-non_exist_to_creat
-+
-+ dir-unmod_to_del
-+ dir-mod_to_del
-+ dir-creat_to_del
-+ dir-del_rew_to_del
-+ dir-del_to_del_rew
-+ dir-non_exist_to_creat
-+*/
-+
-+
-+/* bring a file of any type from state UNMODIFIED to MODIFIED */
-+int nondir_unmod_to_mod(dentry_t *dentry, int cp_flag)
-+{
-+ int err = 0;
-+ struct vfsmount *tgt_mnt;
-+ struct vfsmount *src_mnt;
-+ dentry_t *tgt_dentry;
-+ dentry_t *src_dentry;
-+ dentry_t *hidden_sto_dentry;
-+ dentry_t *hidden_sto_dir_dentry;
-+
-+ check_mini_fo_dentry(dentry);
-+
-+ if((dtost(dentry) != UNMODIFIED) ||
-+ S_ISDIR(dentry->d_inode->i_mode)) {
-+ printk(KERN_CRIT "mini_fo: nondir_unmod_to_mod: \
-+ wrong type or state.\n");
-+ err = -1;
-+ goto out;
-+ }
-+ err = get_neg_sto_dentry(dentry);
-+
-+ if (err) {
-+ printk(KERN_CRIT "mini_fo: nondir_unmod_to_mod: \
-+ ERROR getting neg. sto dentry.\n");
-+ goto out;
-+ }
-+
-+ /* create sto file */
-+ hidden_sto_dentry = dtohd2(dentry);
-+
-+ /* lock parent */
-+ hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
-+#else
-+ down(&hidden_sto_dir_dentry->d_inode->i_sem);
-+#endif
-+
-+ err = PTR_ERR(hidden_sto_dir_dentry);
-+ if (IS_ERR(hidden_sto_dir_dentry))
-+ goto out;
-+
-+ /* handle different types of nondirs */
-+ if(S_ISCHR(dentry->d_inode->i_mode) ||
-+ S_ISBLK(dentry->d_inode->i_mode)) {
-+ err = vfs_mknod(hidden_sto_dir_dentry->d_inode,
-+ hidden_sto_dentry,
-+ dtohd(dentry)->d_inode->i_mode,
-+ dtohd(dentry)->d_inode->i_rdev);
-+ }
-+
-+ else if(S_ISREG(dentry->d_inode->i_mode)) {
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
-+ err = vfs_create(hidden_sto_dir_dentry->d_inode,
-+ hidden_sto_dentry,
-+ dtohd(dentry)->d_inode->i_mode, NULL);
-+#else
-+ err = vfs_create(hidden_sto_dir_dentry->d_inode,
-+ hidden_sto_dentry,
-+ dtohd(dentry)->d_inode->i_mode);
-+#endif
-+ }
-+ if(err) {
-+ printk(KERN_CRIT "mini_fo: nondir_unmod_to_mod: \
-+ ERROR creating sto file.\n");
-+ goto out_lock;
-+ }
-+
-+ /* interpose on new inode */
-+ if(itohi2(dentry->d_inode) != NULL) {
-+ printk(KERN_CRIT "mini_fo: nondir_unmod_to_mod: \
-+ ERROR, invalid inode detected.\n");
-+ err = -EINVAL;
-+ goto out_lock;
-+ }
-+
-+ itohi2(dentry->d_inode) = igrab(dtohd2(dentry)->d_inode);
-+
-+ fist_copy_attr_timesizes(dentry->d_parent->d_inode,
-+ hidden_sto_dir_dentry->d_inode);
-+ dtost(dentry) = MODIFIED;
-+
-+ /* copy contents if regular file and cp_flag = 1 */
-+ if((cp_flag == 1) && S_ISREG(dentry->d_inode->i_mode)) {
-+
-+ /* unlock first */
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
-+#else
-+ up(&hidden_sto_dir_dentry->d_inode->i_sem);
-+#endif
-+
-+ dput(hidden_sto_dir_dentry);
-+
-+ tgt_dentry = dtohd2(dentry);
-+ tgt_mnt = stopd(dentry->d_inode->i_sb)->hidden_mnt2;
-+ src_dentry = dtohd(dentry);
-+ src_mnt = stopd(dentry->d_inode->i_sb)->hidden_mnt;
-+
-+ err = mini_fo_cp_cont(tgt_dentry, tgt_mnt,
-+ src_dentry, src_mnt);
-+ if(err) {
-+ printk(KERN_CRIT "mini_fo: nondir_unmod_to_mod: \
-+ ERROR copying contents.\n");
-+ }
-+ goto out;
-+ }
-+
-+ out_lock:
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
-+#else
-+ up(&hidden_sto_dir_dentry->d_inode->i_sem);
-+#endif
-+ dput(hidden_sto_dir_dentry);
-+ out:
-+ return err;
-+}
-+
-+/* this function is currently identical to nondir_creat_to_del */
-+int nondir_del_rew_to_del(dentry_t *dentry)
-+{
-+ return nondir_creat_to_del(dentry);
-+}
-+
-+int nondir_creat_to_del(dentry_t *dentry)
-+{
-+ int err = 0;
-+
-+ inode_t *hidden_sto_dir_inode;
-+ dentry_t *hidden_sto_dir_dentry;
-+ dentry_t *hidden_sto_dentry;
-+
-+ check_mini_fo_dentry(dentry);
-+
-+ /* for now this function serves for both state DEL_REWRITTEN and
-+ * CREATED */
-+ if(!(dtost(dentry) == CREATED || (dtost(dentry) == DEL_REWRITTEN)) ||
-+ S_ISDIR(dentry->d_inode->i_mode)) {
-+ printk(KERN_CRIT "mini_fo: nondir_mod_to_del/del_rew_to_del: \
-+ wrong type or state.\n");
-+ err = -1;
-+ goto out;
-+ }
-+
-+ hidden_sto_dir_inode = itohi2(dentry->d_parent->d_inode);
-+ hidden_sto_dentry = dtohd2(dentry);
-+
-+ /* was: hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry);*/
-+ hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
-+#else
-+ down(&hidden_sto_dir_dentry->d_inode->i_sem);
-+#endif
-+
-+ /* avoid destroying the hidden inode if the file is in use */
-+ dget(hidden_sto_dentry);
-+ err = vfs_unlink(hidden_sto_dir_inode, hidden_sto_dentry);
-+ dput(hidden_sto_dentry);
-+ if(!err)
-+ d_delete(hidden_sto_dentry);
-+
-+ /* propagate number of hard-links */
-+ dentry->d_inode->i_nlink = itohi2(dentry->d_inode)->i_nlink;
-+
-+ dtost(dentry) = NON_EXISTANT;
-+
-+ /* was: unlock_dir(hidden_sto_dir_dentry); */
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
-+#else
-+ up(&hidden_sto_dir_dentry->d_inode->i_sem);
-+#endif
-+ dput(hidden_sto_dir_dentry);
-+
-+ out:
-+ return err;
-+}
-+
-+int nondir_mod_to_del(dentry_t *dentry)
-+{
-+ int err;
-+ dentry_t *hidden_sto_dentry;
-+ inode_t *hidden_sto_dir_inode;
-+ dentry_t *hidden_sto_dir_dentry;
-+
-+ check_mini_fo_dentry(dentry);
-+
-+ if(dtost(dentry) != MODIFIED ||
-+ S_ISDIR(dentry->d_inode->i_mode)) {
-+ printk(KERN_CRIT "mini_fo: nondir_mod_to_del: \
-+ wrong type or state.\n");
-+ err = -1;
-+ goto out;
-+ }
-+
-+ hidden_sto_dir_inode = itohi2(dentry->d_parent->d_inode);
-+ hidden_sto_dentry = dtohd2(dentry);
-+
-+ /* was hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry); */
-+ hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
-+#else
-+ down(&hidden_sto_dir_dentry->d_inode->i_sem);
-+#endif
-+
-+ /* avoid destroying the hidden inode if the file is in use */
-+ dget(hidden_sto_dentry);
-+ err = vfs_unlink(hidden_sto_dir_inode, hidden_sto_dentry);
-+ dput(hidden_sto_dentry);
-+ if(!err)
-+ d_delete(hidden_sto_dentry);
-+
-+ /* propagate number of hard-links */
-+ dentry->d_inode->i_nlink = itohi2(dentry->d_inode)->i_nlink;
-+
-+ /* dput base dentry, this will relase the inode and free the
-+ * dentry, as we will never need it again. */
-+ dput(dtohd(dentry));
-+ dtohd(dentry) = NULL;
-+ dtost(dentry) = DELETED;
-+
-+ /* add deleted file to META-file */
-+ meta_add_d_entry(dentry->d_parent,
-+ dentry->d_name.name,
-+ dentry->d_name.len);
-+
-+ /* was: unlock_dir(hidden_sto_dir_dentry); */
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
-+ mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
-+#else
-+ up(&hidden_sto_dir_dentry->d_inode->i_sem);
-+#endif
-+ dput(hidden_sto_dir_dentry);
-+
-+ out:
-+ return err;
-+}
-+
-+int nondir_unmod_to_del(dentry_t *dentry)
-+{
-+ int err = 0;
-+
-+ check_mini_fo_dentry(dentry);
-+
-+ if(dtost(dentry) != UNMODIFIED ||
-+ S_ISDIR(dentry->d_inode->i_mode)) {
-+ printk(KERN_CRIT "mini_fo: nondir_unmod_to_del: \
-+ wrong type or state.\n");
-+ err = -1;
-+ goto out;
-+ }
-+
-+ /* next we have to get a negative dentry for the storage file */
-+ err = get_neg_sto_dentry(dentry);
-+
-+ if(err)
-+ goto out;
-+
-+ /* add deleted file to META lists */
-+ err = meta_add_d_entry(dentry->d_parent,
-+ dentry->d_name.name,
-+ dentry->d_name.len);
-+
-+ if(err)
-+ goto out;
-+
-+ /* dput base dentry, this will relase the inode and free the
-+ * dentry, as we will never need it again. */
-+ dput(dtohd(dentry));
-+ dtohd(dentry) = NULL;
-+ dtost(dentry) = DELETED;
-+
-+ out:
-+ return err;
-+}
-+
-+/* bring a dir from state UNMODIFIED to MODIFIED */
-+int dir_unmod_to_mod(dentry_t *dentry)
-+{
-+ int err;
-+
-+ check_mini_fo_dentry(dentry);
-+
-+ if(dtost(dentry) != UNMODIFIED ||
-+ !S_ISDIR(dentry->d_inode->i_mode)) {
-+ printk(KERN_CRIT "mini_fo: dir_unmod_to_mod: \
-+ wrong type or state.\n");
-+ err = -1;
-+ goto out;
-+ }
-+
-+ /* this creates our dir incl. sto. structure */
-+ err = build_sto_structure(dentry->d_parent, dentry);
-+ if(err) {
-+ printk(KERN_CRIT "mini_fo: dir_unmod_to_mod: \
-+ build_sto_structure failed.\n");
-+ goto out;
-+ }
-+ out:
-+ return err;
-+}
-+
---- /dev/null
-+++ b/fs/mini_fo/super.c
-@@ -0,0 +1,281 @@
-+/*
-+ * Copyright (c) 1997-2003 Erez Zadok
-+ * Copyright (c) 2001-2003 Stony Brook University
-+ *
-+ * For specific licensing information, see the COPYING file distributed with
-+ * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
-+ *
-+ * This Copyright notice must be kept intact and distributed with all
-+ * fistgen sources INCLUDING sources generated by fistgen.
-+ */
-+/*
-+ * Copyright (C) 2004, 2005 Markus Klotzbuecher <mk@creamnet.de>
-+ *
-+ * 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.
-+ */
-+
-+/*
-+ * $Id$
-+ */
-+
-+#ifdef HAVE_CONFIG_H
-+# include <config.h>
-+#endif
-+
-+#include "fist.h"
-+#include "mini_fo.h"
-+
-+
-+STATIC void
-+mini_fo_read_inode(inode_t *inode)
-+{
-+ static struct address_space_operations mini_fo_empty_aops;
-+
-+ __itopd(inode) = kmalloc(sizeof(struct mini_fo_inode_info), GFP_KERNEL);
-+ if (!itopd(inode)) {
-+ printk("<0>%s:%s:%d: No kernel memory!\n", __FILE__, __FUNCTION__, __LINE__);
-+ ASSERT(NULL);
-+ }
-+ itohi(inode) = NULL;
-+ itohi2(inode) = NULL;
-+
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
-+ inode->i_version++;
-+#else
-+ inode->i_version = ++event; /* increment inode version */
-+#endif
-+ inode->i_op = &mini_fo_main_iops;
-+ inode->i_fop = &mini_fo_main_fops;
-+#if 0
-+ /*
-+ * XXX: To export a file system via NFS, it has to have the
-+ * FS_REQUIRES_DEV flag, so turn it on. But should we inherit it from
-+ * the lower file system, or can we allow our file system to be exported
-+ * even if the lower one cannot be natively exported.
-+ */
-+ inode->i_sb->s_type->fs_flags |= FS_REQUIRES_DEV;
-+ /*
-+ * OK, the above was a hack, which is now turned off because it may
-+ * cause a panic/oops on some systems. The correct way to export a
-+ * "nodev" filesystem is via using nfs-utils > 1.0 and the "fsid=" export
-+ * parameter, which requires 2.4.20 or later.
-+ */
-+#endif
-+ /* I don't think ->a_ops is ever allowed to be NULL */
-+ inode->i_mapping->a_ops = &mini_fo_empty_aops;
-+}
-+
-+
-+#if defined(FIST_DEBUG) || defined(FIST_FILTER_SCA)
-+/*
-+ * No need to call write_inode() on the lower inode, as it
-+ * will have been marked 'dirty' anyway. But we might need
-+ * to write some of our own stuff to disk.
-+ */
-+STATIC void
-+mini_fo_write_inode(inode_t *inode, int sync)
-+{
-+ print_entry_location();
-+ print_exit_location();
-+}
-+#endif /* defined(FIST_DEBUG) || defined(FIST_FILTER_SCA) */
-+
-+
-+STATIC void
-+mini_fo_put_inode(inode_t *inode)
-+{
-+ /*
-+ * This is really funky stuff:
-+ * Basically, if i_count == 1, iput will then decrement it and this inode will be destroyed.
-+ * It is currently holding a reference to the hidden inode.
-+ * Therefore, it needs to release that reference by calling iput on the hidden inode.
-+ * iput() _will_ do it for us (by calling our clear_inode), but _only_ if i_nlink == 0.
-+ * The problem is, NFS keeps i_nlink == 1 for silly_rename'd files.
-+ * So we must for our i_nlink to 0 here to trick iput() into calling our clear_inode.
-+ */
-+ if (atomic_read(&inode->i_count) == 1)
-+ inode->i_nlink = 0;
-+}
-+
-+
-+#if defined(FIST_DEBUG) || defined(FIST_FILTER_SCA)
-+/*
-+ * we now define delete_inode, because there are two VFS paths that may
-+ * destroy an inode: one of them calls clear inode before doing everything
-+ * else that's needed, and the other is fine. This way we truncate the inode
-+ * size (and its pages) and then clear our own inode, which will do an iput
-+ * on our and the lower inode.
-+ */
-+STATIC void
-+mini_fo_delete_inode(inode_t *inode)
-+{
-+ print_entry_location();
-+
-+ fist_checkinode(inode, "mini_fo_delete_inode IN");
-+ inode->i_size = 0; /* every f/s seems to do that */
-+ clear_inode(inode);
-+
-+ print_exit_location();
-+}
-+#endif /* defined(FIST_DEBUG) || defined(FIST_FILTER_SCA) */
-+
-+
-+/* final actions when unmounting a file system */
-+STATIC void
-+mini_fo_put_super(super_block_t *sb)
-+{
-+ if (stopd(sb)) {
-+ mntput(stopd(sb)->hidden_mnt);
-+ mntput(stopd(sb)->hidden_mnt2);
-+
-+ /* mk: no! dput(stopd(sb)->base_dir_dentry);
-+ dput(stopd(sb)->storage_dir_dentry); */
-+
-+ kfree(stopd(sb));
-+ __stopd(sb) = NULL;
-+ }
-+}
-+
-+
-+#ifdef NOT_NEEDED
-+/*
-+ * This is called in do_umount before put_super.
-+ * The superblock lock is not held yet.
-+ * We probably do not need to define this or call write_super
-+ * on the hidden_sb, because sync_supers() will get to hidden_sb
-+ * sooner or later. But it is also called from file_fsync()...
-+ */
-+STATIC void
-+mini_fo_write_super(super_block_t *sb)
-+{
-+ return;
-+}
-+#endif /* NOT_NEEDED */
-+
-+
-+STATIC int
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
-+mini_fo_statfs(struct dentry *d, struct kstatfs *buf)
-+#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
-+mini_fo_statfs(super_block_t *sb, struct kstatfs *buf)
-+#else
-+mini_fo_statfs(super_block_t *sb, struct statfs *buf)
-+#endif
-+{
-+ int err = 0;
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
-+ struct dentry *hidden_d;
-+
-+ hidden_d = dtohd(d);
-+ err = vfs_statfs(hidden_d, buf);
-+#else
-+ super_block_t *hidden_sb;
-+
-+ hidden_sb = stohs(sb);
-+ err = vfs_statfs(hidden_sb, buf);
-+#endif
-+
-+ return err;
-+}
-+
-+
-+/*
-+ * XXX: not implemented. This is not allowed yet.
-+ * Should we call this on the hidden_sb? Probably not.
-+ */
-+STATIC int
-+mini_fo_remount_fs(super_block_t *sb, int *flags, char *data)
-+{
-+ //printk(KERN_CRIT "mini_fo_remount_fs: WARNING, this function is umimplemented.\n");
-+ return -ENOSYS;
-+}
-+
-+
-+/*
-+ * Called by iput() when the inode reference count reached zero
-+ * and the inode is not hashed anywhere. Used to clear anything
-+ * that needs to be, before the inode is completely destroyed and put
-+ * on the inode free list.
-+ */
-+STATIC void
-+mini_fo_clear_inode(inode_t *inode)
-+{
-+ /*
-+ * Decrement a reference to a hidden_inode, which was incremented
-+ * by our read_inode when it was created initially.
-+ */
-+
-+ /* release the wol_list */
-+ if(S_ISDIR(inode->i_mode)) {
-+ __meta_put_lists(inode);
-+ }
-+
-+ /* mk: fan out fun */
-+ if(itohi(inode))
-+ iput(itohi(inode));
-+ if(itohi2(inode))
-+ iput(itohi2(inode));
-+
-+ // XXX: why this assertion fails?
-+ // because it doesn't like us
-+ // ASSERT((inode->i_state & I_DIRTY) == 0);
-+ kfree(itopd(inode));
-+ __itopd(inode) = NULL;
-+}
-+
-+
-+/*
-+ * Called in do_umount() if the MNT_FORCE flag was used and this
-+ * function is defined. See comment in linux/fs/super.c:do_umount().
-+ * Used only in nfs, to kill any pending RPC tasks, so that subsequent
-+ * code can actually succeed and won't leave tasks that need handling.
-+ *
-+ * PS. I wonder if this is somehow useful to undo damage that was
-+ * left in the kernel after a user level file server (such as amd)
-+ * dies.
-+ */
-+STATIC void
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
-+mini_fo_umount_begin(struct vfsmount *mnt, int flags)
-+{
-+ struct vfsmount *hidden_mnt;
-+
-+ hidden_mnt = stopd(mnt->mnt_sb)->hidden_mnt;
-+
-+ if (hidden_mnt->mnt_sb->s_op->umount_begin)
-+ hidden_mnt->mnt_sb->s_op->umount_begin(hidden_mnt, flags);
-+
-+}
-+#else
-+mini_fo_umount_begin(super_block_t *sb)
-+{
-+ super_block_t *hidden_sb;
-+
-+ hidden_sb = stohs(sb);
-+
-+ if (hidden_sb->s_op->umount_begin)
-+ hidden_sb->s_op->umount_begin(hidden_sb);
-+
-+}
-+#endif
-+
-+
-+struct super_operations mini_fo_sops =
-+{
-+ read_inode: mini_fo_read_inode,
-+#if defined(FIST_DEBUG) || defined(FIST_FILTER_SCA)
-+ write_inode: mini_fo_write_inode,
-+#endif /* defined(FIST_DEBUG) || defined(FIST_FILTER_SCA) */
-+ put_inode: mini_fo_put_inode,
-+#if defined(FIST_DEBUG) || defined(FIST_FILTER_SCA)
-+ delete_inode: mini_fo_delete_inode,
-+#endif /* defined(FIST_DEBUG) || defined(FIST_FILTER_SCA) */
-+ put_super: mini_fo_put_super,
-+ statfs: mini_fo_statfs,
-+ remount_fs: mini_fo_remount_fs,
-+ clear_inode: mini_fo_clear_inode,
-+ umount_begin: mini_fo_umount_begin,
-+};
+++ /dev/null
---- a/include/linux/ieee80211.h
-+++ b/include/linux/ieee80211.h
-@@ -106,6 +106,75 @@
- } __attribute__ ((packed));
-
-
-+struct ieee80211_ht_capability {
-+ __le16 capabilities_info;
-+ u8 mac_ht_params_info;
-+ u8 supported_mcs_set[16];
-+ __le16 extended_ht_capability_info;
-+ __le32 tx_BF_capability_info;
-+ u8 antenna_selection_info;
-+}__attribute__ ((packed));
-+
-+struct ieee80211_ht_additional_info {
-+ u8 control_chan;
-+ u8 ht_param;
-+ __le16 operation_mode;
-+ __le16 stbc_param;
-+ u8 basic_set[16];
-+}__attribute__ ((packed));
-+
-+
-+#define IEEE80211_TSINFO_TYPE(a) ((a.byte1 & 0x01) >> 0)
-+#define IEEE80211_TSINFO_TSID(a) ((a.byte1 & 0x1E) >> 1)
-+#define IEEE80211_TSINFO_DIR(a) ((a.byte1 & 0x60) >> 5)
-+#define IEEE80211_TSINFO_POLICY(a) ((a.byte1 & 0x80) >> 7 + \
-+ (a.byte2 & 0x01) << 1)
-+#define IEEE80211_TSINFO_AGG(a) ((a.byte2 & 0x02) >> 1)
-+#define IEEE80211_TSINFO_APSD(a) ((a.byte2 & 0x04) >> 2)
-+#define IEEE80211_TSINFO_UP(a) ((a.byte2 & 0x38) >> 3)
-+#define IEEE80211_TSINFO_ACK(a) ((a.byte2 & 0xC0) >> 6)
-+#define IEEE80211_TSINFO_SCHEDULE(a) ((a.byte3 & 0x01) >> 0)
-+
-+#define IEEE80211_SET_TSINFO_TYPE(i, d) (i.byte1 |= (d << 0) & 0x01)
-+#define IEEE80211_SET_TSINFO_TSID(i, d) (i.byte1 |= (d << 1) & 0x1E)
-+#define IEEE80211_SET_TSINFO_DIR(i, d) (i.byte1 |= (d << 5) & 0x60)
-+#define IEEE80211_SET_TSINFO_POLICY(i, d) \
-+do { \
-+ i.byte1 |= (d & 0x01) << 7; \
-+ i.byte2 |= (d & 0x02) >> 1; \
-+} while(0)
-+#define IEEE80211_SET_TSINFO_AGG(i, d) (i.byte2 |= (d << 1) & 0x02)
-+#define IEEE80211_SET_TSINFO_APSD(i, d) (i.byte2 |= (d << 2) & 0x04)
-+#define IEEE80211_SET_TSINFO_UP(i, d) (i.byte2 |= (d << 3) & 0x38)
-+#define IEEE80211_SET_TSINFO_ACK(i, d) (i.byte2 |= (d << 6) & 0xC0)
-+#define IEEE80211_SET_TSINFO_SCHEDULE(i, d) (i.byte3 |= (d << 0) & 0x01)
-+
-+struct ieee80211_ts_info {
-+ u8 byte1;
-+ u8 byte2;
-+ u8 byte3;
-+} __attribute__ ((packed));
-+
-+struct ieee80211_elem_tspec {
-+ struct ieee80211_ts_info ts_info;
-+ __le16 nominal_msdu_size;
-+ __le16 max_msdu_size;
-+ __le32 min_service_interval;
-+ __le32 max_service_interval;
-+ __le32 inactivity_interval;
-+ __le32 suspension_interval;
-+ __le32 service_start_time;
-+ __le32 min_data_rate;
-+ __le32 mean_data_rate;
-+ __le32 peak_data_rate;
-+ __le32 burst_size;
-+ __le32 delay_bound;
-+ __le32 min_phy_rate;
-+ __le16 surplus_band_allow;
-+ __le16 medium_time;
-+} __attribute__ ((packed));
-+
-+
- struct ieee80211_mgmt {
- __le16 frame_control;
- __le16 duration;
-@@ -173,9 +242,51 @@
- struct {
- u8 action_code;
- u8 dialog_token;
-+ u8 variable[0];
-+ } __attribute__ ((packed)) addts_req;
-+ struct {
-+ u8 action_code;
-+ u8 dialog_token;
-+ __le16 status_code;
-+ u8 variable[0];
-+ } __attribute__ ((packed)) addts_resp;
-+ struct {
-+ u8 action_code;
-+ struct ieee80211_ts_info ts_info;
-+ __le16 reason_code;
-+ } __attribute__ ((packed)) delts;
-+ struct {
-+ u8 action_code;
-+ u8 dialog_token;
- u8 status_code;
- u8 variable[0];
- } __attribute__ ((packed)) wme_action;
-+ struct {
-+ u8 action_code;
-+ u8 dest[6];
-+ u8 src[6];
-+ __le16 capab_info;
-+ __le16 timeout;
-+ /* Followed by Supported Rates and
-+ * Extended Supported Rates */
-+ u8 variable[0];
-+ } __attribute__ ((packed)) dls_req;
-+ struct {
-+ u8 action_code;
-+ __le16 status_code;
-+ u8 dest[6];
-+ u8 src[6];
-+ /* Followed by Capability Information,
-+ * Supported Rates and Extended
-+ * Supported Rates */
-+ u8 variable[0];
-+ } __attribute__ ((packed)) dls_resp;
-+ struct {
-+ u8 action_code;
-+ u8 dest[6];
-+ u8 src[6];
-+ __le16 reason_code;
-+ } __attribute__ ((packed)) dls_teardown;
- struct{
- u8 action_code;
- u8 element_id;
-@@ -184,6 +295,25 @@
- u8 new_chan;
- u8 switch_count;
- } __attribute__((packed)) chan_switch;
-+ struct{
-+ u8 action_code;
-+ u8 dialog_token;
-+ __le16 capab;
-+ __le16 timeout;
-+ __le16 start_seq_num;
-+ } __attribute__((packed)) addba_req;
-+ struct{
-+ u8 action_code;
-+ u8 dialog_token;
-+ __le16 status;
-+ __le16 capab;
-+ __le16 timeout;
-+ } __attribute__((packed)) addba_resp;
-+ struct{
-+ u8 action_code;
-+ __le16 params;
-+ __le16 reason_code;
-+ }__attribute__((packed)) delba;
- } u;
- } __attribute__ ((packed)) action;
- } u;
-@@ -270,6 +400,18 @@
- WLAN_STATUS_UNSUPP_RSN_VERSION = 44,
- WLAN_STATUS_INVALID_RSN_IE_CAP = 45,
- WLAN_STATUS_CIPHER_SUITE_REJECTED = 46,
-+ /* 802.11e */
-+ WLAN_STATUS_UNSPECIFIED_QOS = 32,
-+ WLAN_STATUS_ASSOC_DENIED_NOBANDWIDTH = 33,
-+ WLAN_STATUS_ASSOC_DENIED_LOWACK = 34,
-+ WLAN_STATUS_ASSOC_DENIED_UNSUPP_QOS = 35,
-+ WLAN_STATUS_REQUEST_DECLINED = 37,
-+ WLAN_STATUS_INVALID_QOS_PARAM = 38,
-+ WLAN_STATUS_CHANGE_TSPEC = 39,
-+ WLAN_STATUS_WAIT_TS_DELAY = 47,
-+ WLAN_STATUS_NO_DIRECT_LINK = 48,
-+ WLAN_STATUS_STA_NOT_PRESENT = 49,
-+ WLAN_STATUS_STA_NOT_QSTA = 50,
- };
-
-
-@@ -300,9 +442,50 @@
- WLAN_REASON_INVALID_RSN_IE_CAP = 22,
- WLAN_REASON_IEEE8021X_FAILED = 23,
- WLAN_REASON_CIPHER_SUITE_REJECTED = 24,
-+ /* 802.11e */
-+ WLAN_REASON_DISASSOC_UNSPECIFIED_QOS = 32,
-+ WLAN_REASON_DISASSOC_QAP_NO_BANDWIDTH = 33,
-+ WLAN_REASON_DISASSOC_LOW_ACK = 34,
-+ WLAN_REASON_DISASSOC_QAP_EXCEED_TXOP = 35,
-+ WLAN_REASON_QSTA_LEAVE_QBSS = 36,
-+ WLAN_REASON_QSTA_NOT_USE = 37,
-+ WLAN_REASON_QSTA_REQUIRE_SETUP = 38,
-+ WLAN_REASON_QSTA_TIMEOUT = 39,
-+ WLAN_REASON_QSTA_CIPHER_NOT_SUPP = 45,
- };
-
-
-+/* Category Code */
-+enum ieee80211_category {
-+ WLAN_CATEGORY_SPECTRUM_MGMT = 0,
-+ WLAN_CATEGORY_QOS = 1,
-+ WLAN_CATEGORY_DLS = 2,
-+ WLAN_CATEGORY_BACK = 3,
-+ WLAN_CATEGORY_WMM = 17,
-+};
-+
-+/* QoS Action Code */
-+enum ieee80211_qos_actioncode {
-+ WLAN_ACTION_QOS_ADDTS_REQ = 0,
-+ WLAN_ACTION_QOS_ADDTS_RESP = 1,
-+ WLAN_ACTION_QOS_DELTS = 2,
-+ WLAN_ACTION_QOS_SCHEDULE = 3,
-+};
-+
-+/* DLS Action Code */
-+enum ieee80211_dls_actioncode {
-+ WLAN_ACTION_DLS_REQ = 0,
-+ WLAN_ACTION_DLS_RESP = 1,
-+ WLAN_ACTION_DLS_TEARDOWN = 2,
-+};
-+
-+/* BACK Action Code */
-+enum ieee80211_back_actioncode {
-+ WLAN_ACTION_ADDBA_REQ = 0,
-+ WLAN_ACTION_ADDBA_RESP = 1,
-+ WLAN_ACTION_DELBA = 2,
-+};
-+
- /* Information Element IDs */
- enum ieee80211_eid {
- WLAN_EID_SSID = 0,
-@@ -318,6 +501,15 @@
- WLAN_EID_HP_PARAMS = 8,
- WLAN_EID_HP_TABLE = 9,
- WLAN_EID_REQUEST = 10,
-+ /* 802.11e */
-+ WLAN_EID_QBSS_LOAD = 11,
-+ WLAN_EID_EDCA_PARAM_SET = 12,
-+ WLAN_EID_TSPEC = 13,
-+ WLAN_EID_TCLAS = 14,
-+ WLAN_EID_SCHEDULE = 15,
-+ WLAN_EID_TS_DELAY = 43,
-+ WLAN_EID_TCLAS_PROCESSING = 44,
-+ WLAN_EID_QOS_CAPA = 46,
- /* 802.11h */
- WLAN_EID_PWR_CONSTRAINT = 32,
- WLAN_EID_PWR_CAPABILITY = 33,
-@@ -332,6 +524,9 @@
- /* 802.11g */
- WLAN_EID_ERP_INFO = 42,
- WLAN_EID_EXT_SUPP_RATES = 50,
-+ /* 802.11n */
-+ WLAN_EID_HT_CAPABILITY = 45,
-+ WLAN_EID_HT_EXTRA_INFO = 61,
- /* 802.11i */
- WLAN_EID_RSN = 48,
- WLAN_EID_WPA = 221,
-@@ -340,6 +535,9 @@
- WLAN_EID_QOS_PARAMETER = 222
- };
-
-+/* 80211n */
-+#define IEEE80211_QOS_CONTROL_A_MSDU_PRESENT 0x0080
-+
- /* cipher suite selectors */
- #define WLAN_CIPHER_SUITE_USE_GROUP 0x000FAC00
- #define WLAN_CIPHER_SUITE_WEP40 0x000FAC01
-@@ -350,4 +548,37 @@
-
- #define WLAN_MAX_KEY_LEN 32
-
-+enum ieee80211_tsinfo_direction {
-+ WLAN_TSINFO_UPLINK = 0,
-+ WLAN_TSINFO_DOWNLINK = 1,
-+ WLAN_TSINFO_DIRECTLINK = 2,
-+ WLAN_TSINFO_BIDIRECTIONAL = 3,
-+};
-+
-+enum ieee80211_tsinfo_access {
-+ WLAN_TSINFO_EDCA = 1,
-+ WLAN_TSINFO_HCCA = 2,
-+ WLAN_TSINFO_HEMM = 3,
-+};
-+
-+enum ieee80211_tsinfo_psb {
-+ WLAN_TSINFO_PSB_LEGACY = 0,
-+ WLAN_TSINFO_PSB_APSD = 1,
-+};
-+
-+
-+/* WI-FI Alliance OUI Type and Subtype */
-+enum wifi_oui_type {
-+ WIFI_OUI_TYPE_WPA = 1,
-+ WIFI_OUI_TYPE_WMM = 2,
-+ WIFI_OUI_TYPE_WSC = 4,
-+ WIFI_OUI_TYPE_PSD = 6,
-+};
-+
-+enum wifi_oui_stype_wmm {
-+ WIFI_OUI_STYPE_WMM_INFO = 0,
-+ WIFI_OUI_STYPE_WMM_PARAM = 1,
-+ WIFI_OUI_STYPE_WMM_TSPEC = 2,
-+};
-+
- #endif /* IEEE80211_H */
---- a/include/linux/nl80211.h
-+++ b/include/linux/nl80211.h
-@@ -7,6 +7,217 @@
- */
-
- /**
-+ * enum nl80211_commands - supported nl80211 commands
-+ * @NL80211_CMD_UNSPEC: unspecified command to catch errors
-+ * @NL80211_CMD_RENAME_WIPHY: rename a wiphy, needs
-+ * %NL80211_ATTR_WIPHY and %NL80211_ATTR_WIPHY_NAME
-+ * @NL80211_CMD_WIPHY_NEWNAME: rename notification
-+ * @NL80211_CMD_GET_CMDLIST: TO BE DEFINED PROPERLY. currently the code makes
-+ * it depend on the wiphy only but it really should depend on the
-+ * interface type too....
-+ * @NL80211_CMD_NEW_CMDLIST: command list result
-+ * @NL80211_CMD_ADD_VIRTUAL_INTERFACE: create a virtual interface for the
-+ * wiphy identified by an %NL80211_ATTR_WIPHY attribute with the given
-+ * %NL80211_ATTR_IFTYPE and %NL80211_ATTR_IFNAME.
-+ * @NL80211_CMD_DEL_VIRTUAL_INTERFACE: destroy a virtual interface identified
-+ * by %NL80211_ATTR_IFINDEX.
-+ * @NL80211_CMD_CHANGE_VIRTUAL_INTERFACE: change type of virtual interface to
-+ * the type given by %NL80211_ATTR_IFTYPE, the interface is identified by
-+ * %NL80211_ATTR_IFINDEX.
-+ * @NL80211_CMD_GET_WIPHYS: request a list of all wiphys present in the system
-+ * @NL80211_CMD_NEW_WIPHYS: returned list of all wiphys
-+ * @NL80211_CMD_GET_INTERFACES: request a list of all interfaces belonging to
-+ * the wiphy identified by %NL80211_ATTR_WIPHY
-+ * @NL80211_CMD_NEW_INTERFACES: result for %NL80211_CMD_GET_INTERFACES
-+ * @NL80211_CMD_INITIATE_SCAN: initiate a scan with the passed parameters. THe
-+ * parameters may contain %NL80211_ATTR_FLAG_SCAN_ACTIVE,
-+ * %NL80211_ATTR_PHYMODE and a list of channels in an
-+ * %NL80211_ATTR_CHANNEL_LIST attribute (an array of nested attributes)
-+ * containing %NL80211_ATTR_CHANNEL, %NL80211_ATTR_PHYMODE, and possibly
-+ * %NL80211_ATTR_FLAG_SCAN_ACTIVE. The outer %NL80211_ATTR_FLAG_SCAN_ACTIVE
-+ * is ignored when a channel list is present.
-+ * @NL80211_CMD_SCAN_RESULT: scan result, contains an array in
-+ * %NL80211_ATTR_BSS_LIST.
-+ * @NL80211_CMD_ASSOCIATE: associate with the given parameters
-+ * (%NL80211_ATTR_SSID is mandatory, %NL80211_ATTR_TIMEOUT_TU,
-+ * %NL80211_ATTR_BSSID, %NL80211_ATTR_CHANNEL, %NL80211_ATTR_PHYMODE,
-+ * and %NL80211_ATTR_IE may be given)
-+ * @NL80211_CMD_ADD_KEY: add a key with given %NL80211_ATTR_KEY_DATA,
-+ * %NL80211_ATTR_KEY_ID, %NL80211_ATTR_KEY_TYPE, %NL80211_ATTR_MAC and
-+ * %NL80211_ATTR_KEY_CIPHER attributes.
-+ * @NL80211_CMD_DEL_KEY: delete a key identified by %NL80211_ATTR_KEY_ID,
-+ * %NL80211_ATTR_KEY_TYPE and %NL80211_ATTR_MAC or all keys.
-+ * @__NL80211_CMD_AFTER_LAST: internal use
-+ */
-+enum nl80211_commands {
-+/* don't change the order or add anything inbetween, this is ABI! */
-+ NL80211_CMD_UNSPEC,
-+ /* %input: wiphy, wiphy_name */
-+ NL80211_CMD_RENAME_WIPHY,
-+ NL80211_CMD_WIPHY_NEWNAME,
-+ /* %input: wiphy|ifindex */
-+ NL80211_CMD_GET_CMDLIST,
-+ NL80211_CMD_NEW_CMDLIST,
-+ /* %input: wiphy, ifname, {iftype} */
-+ NL80211_CMD_ADD_VIRTUAL_INTERFACE,
-+ /* %input: wiphy, ifindex */
-+ NL80211_CMD_DEL_VIRTUAL_INTERFACE,
-+ /* %input: ifindex, iftype */
-+ NL80211_CMD_CHANGE_VIRTUAL_INTERFACE,
-+ /* %input: */
-+ NL80211_CMD_GET_WIPHYS,
-+ NL80211_CMD_NEW_WIPHYS,
-+ /* %input: wiphy */
-+ NL80211_CMD_GET_INTERFACES,
-+ NL80211_CMD_NEW_INTERFACES,
-+ NL80211_CMD_INITIATE_SCAN,
-+ NL80211_CMD_SCAN_RESULT,
-+ NL80211_CMD_GET_ASSOCIATION,
-+ NL80211_CMD_ASSOCIATION_CHANGED,
-+ NL80211_CMD_ASSOCIATE,
-+ NL80211_CMD_DISASSOCIATE,
-+ NL80211_CMD_DEAUTH,
-+ NL80211_CMD_GET_AUTH_LIST,
-+ NL80211_CMD_NEW_AUTH_LIST,
-+ NL80211_CMD_AUTHENTICATION_CHANGED,
-+ NL80211_CMD_AP_SET_BEACON,
-+ NL80211_CMD_AP_ADD_STA,
-+ NL80211_CMD_AP_UPDATE_STA,
-+ NL80211_CMD_AP_GET_STA_INFO,
-+ NL80211_CMD_AP_SET_RATESETS,
-+ NL80211_CMD_ADD_KEY,
-+ NL80211_CMD_DEL_KEY,
-+
-+ /* add commands here */
-+
-+ /* used to define NL80211_CMD_MAX below */
-+ __NL80211_CMD_AFTER_LAST
-+};
-+#define NL80211_CMD_MAX (__NL80211_CMD_AFTER_LAST - 1)
-+
-+
-+/**
-+ * enum nl80211_attrs - nl80211 netlink attributes
-+ * @NL80211_ATTR_UNSPEC: unspecified attribute to catch errors
-+ * @NL80211_ATTR_IFINDEX: network interface index of the device to operate on
-+ * @NL80211_ATTR_IFNAME: network interface name
-+ * @NL80211_ATTR_WIPHY: index of wiphy to operate on, cf.
-+ * /sys/class/ieee80211/<phyname>/index
-+ * @NL80211_ATTR_WIPHY_NAME: wiphy name (used for renaming)
-+ * @NL80211_ATTR_CMDS: list of u8's identifying commands a device supports
-+ * @NL80211_ATTR_IFTYPE: type of virtual interface, see &enum nl80211_iftype
-+ * @NL80211_ATTR_INTERFACE_LIST: interface array, nested netlink attribute
-+ * @NL80211_ATTR_WIPHY_LIST: wiphy array, nested netlink attribute
-+ * @NL80211_ATTR_BSSID: BSSID (must be 6 bytes)
-+ * @NL80211_ATTR_SSID: SSID (1-32 bytes)
-+ * @NL80211_ATTR_CHANNEL: channel number
-+ * @NL80211_ATTR_PHYMODE: PHY mode, see &enum nl80211_phymode
-+ * @NL80211_ATTR_CHANNEL_LIST: netlink nested attribute array containing scan
-+ * parameters for channels
-+ * @NL80211_ATTR_BSS_LIST: nested attribute containing an array
-+ * @NL80211_ATTR_BSSTYPE: BSS type, see &enum nl80211_bsstype
-+ * @NL80211_ATTR_BEACON_PERIOD: beacon period
-+ * @NL80211_ATTR_DTIM_PERIOD: DTIM period
-+ * @NL80211_ATTR_TIMESTAMP: 64-bit timestamp of received beacon/probe response
-+ * @NL80211_ATTR_IE: information element(s), maximum length %NL80211_MAX_IE_LEN
-+ * @NL80211_ATTR_AUTH_ALGORITHM: authentication algorithm
-+ * @NL80211_ATTR_TIMEOUT_TU: timeout in TU (TO BE USED)
-+ * @NL80211_ATTR_REASON_CODE: 802.11 reason code
-+ * @NL80211_ATTR_ASSOCIATION_ID: association ID (u16, 1-2007)
-+ * @NL80211_ATTR_DEAUTHENTICATED: TO BE USED
-+ * @NL80211_ATTR_RX_SENSITIVITY: receiver sensitivity in dBm
-+ * @NL80211_ATTR_TRANSMIT_POWER: transmit power in mW
-+ * @NL80211_ATTR_FRAG_THRESHOLD: fragmentation threshold (bytes)
-+ * @NL80211_ATTR_FLAG_SCAN_ACTIVE: netlink flag indiciating active scan
-+ * @NL80211_ATTR_KEY_DATA: temporal key data
-+ * @NL80211_ATTR_KEY_ID: key ID (u8, 0-3)
-+ * @NL80211_ATTR_KEY_TYPE: key type (see &enum nl80211_keytype)
-+ * @NL80211_ATTR_MAC: MAC address
-+ * @NL80211_ATTR_KEY_CIPHER: key cipher suite (u32)
-+ * @__NL80211_ATTR_AFTER_LAST: internal use
-+ */
-+enum nl80211_attrs {
-+/* don't change the order or add anything inbetween, this is ABI! */
-+ NL80211_ATTR_UNSPEC,
-+ /* %type: u32 */
-+ NL80211_ATTR_IFINDEX,
-+ /* %type: nulstring */
-+ NL80211_ATTR_IFNAME,
-+ /* %type: u32 */
-+ NL80211_ATTR_WIPHY,
-+ /* %type: nulstring */
-+ NL80211_ATTR_WIPHY_NAME,
-+ NL80211_ATTR_CMDS,
-+ /* %type: u32 */
-+ NL80211_ATTR_IFTYPE,
-+ NL80211_ATTR_INTERFACE_LIST,
-+ NL80211_ATTR_WIPHY_LIST,
-+ NL80211_ATTR_BSSID,
-+ NL80211_ATTR_SSID,
-+ NL80211_ATTR_CHANNEL,
-+ NL80211_ATTR_PHYMODE,
-+ NL80211_ATTR_CHANNEL_LIST,
-+ NL80211_ATTR_BSS_LIST,
-+ NL80211_ATTR_BSSTYPE,
-+ NL80211_ATTR_BEACON_PERIOD,
-+ NL80211_ATTR_DTIM_PERIOD,
-+ NL80211_ATTR_TIMESTAMP,
-+ NL80211_ATTR_IE,
-+ NL80211_ATTR_AUTH_ALGORITHM,
-+ NL80211_ATTR_TIMEOUT_TU,
-+ NL80211_ATTR_REASON_CODE,
-+ NL80211_ATTR_ASSOCIATION_ID,
-+ NL80211_ATTR_DEAUTHENTICATED,
-+ NL80211_ATTR_RX_SENSITIVITY,
-+ NL80211_ATTR_TRANSMIT_POWER,
-+ NL80211_ATTR_FRAG_THRESHOLD,
-+ NL80211_ATTR_FLAG_SCAN_ACTIVE,
-+
-+ NL80211_ATTR_KEY_DATA,
-+ NL80211_ATTR_KEY_ID,
-+ NL80211_ATTR_KEY_TYPE,
-+ NL80211_ATTR_MAC,
-+ NL80211_ATTR_KEY_CIPHER,
-+
-+ NL80211_ATTR_BEACON_HEAD,
-+ NL80211_ATTR_BEACON_TAIL,
-+
-+ /* add attributes here, update the policy in nl80211.c */
-+
-+ /* used to define NL80211_ATTR_MAX below */
-+ __NL80211_ATTR_AFTER_LAST,
-+};
-+#define NL80211_ATTR_MAX (__NL80211_ATTR_AFTER_LAST - 1)
-+
-+/**
-+ * enum nl80211_multicast_groups - multicast groups for nl80211
-+ * @NL80211_GROUP_CONFIG: members of this group are notified of
-+ * configuration changes
-+ */
-+enum nl80211_multicast_groups {
-+ /* be notified of configuration changes like wiphy renames */
-+ NL80211_GROUP_CONFIG,
-+
-+ /* add groups here */
-+
-+ /* keep last */
-+ __NL80211_GROUP_AFTER_LAST
-+};
-+#define NL80211_GROUP_MAX (__NL80211_GROUP_AFTER_LAST - 1)
-+
-+/*
-+ * maximum length of IE(s) passed in an NL80211_ATTR_IE.
-+ * this is an arbitrary limit, 774 means three full-length
-+ * IEs would fit... increase if necessary */
-+#define NL80211_MAX_IE_LEN 774
-+
-+/*
-+ * maximum number of items in an ATTR_CHANNEL_LIST,
-+ * just to avoid too large allocations
-+ */
-+#define NL80211_MAX_CHANNEL_LIST_ITEM 200
-+
-+/**
- * enum nl80211_iftype - (virtual) interface types
- * @NL80211_IFTYPE_UNSPECIFIED: unspecified type, driver decides
- * @NL80211_IFTYPE_ADHOC: independent BSS member
-@@ -35,4 +246,56 @@
- };
- #define NL80211_IFTYPE_MAX (__NL80211_IFTYPE_AFTER_LAST - 1)
-
-+/**
-+ * enum nl80211_phymode - PHY modes
-+ * @NL80211_PHYMODE_A: 5 GHz PHY
-+ * @NL80211_PHYMODE_B: 2.4 GHz PHY (B mode)
-+ * @NL80211_PHYMODE_G: 2.4 GHz PHY (G, compatible with B)
-+ * @__NL80211_PHYMODE_AFTER_LAST: internal use
-+ *
-+ * These values are used for %NL80211_ATTR_PHYMODE.
-+ */
-+enum nl80211_phymode {
-+ NL80211_PHYMODE_A,
-+ NL80211_PHYMODE_B,
-+ NL80211_PHYMODE_G,
-+
-+ /* keep last */
-+ __NL80211_PHYMODE_AFTER_LAST
-+};
-+#define NL80211_PHYMODE_MAX (__NL80211_PHYMODE_AFTER_LAST - 1)
-+
-+/**
-+ * enum nl80211_bsstype - BSS types
-+ * @NL80211_BSSTYPE_INFRASTRUCTURE: infrastructure BSS
-+ * @NL80211_BSSTYPE_INDEPENDENT: independent BSS (ad-hoc network)
-+ * @__NL80211_BSSTYPE_AFTER_LAST: internal use
-+ *
-+ * These values are used for %NL80211_ATTR_BSSTYPE.
-+ */
-+enum nl80211_bsstype {
-+ NL80211_BSSTYPE_INFRASTRUCTURE,
-+ NL80211_BSSTYPE_INDEPENDENT,
-+
-+ /* keep last */
-+ __NL80211_BSSTYPE_AFTER_LAST
-+};
-+#define NL80211_BSSTYPE_MAX (__NL80211_BSSTYPE_AFTER_LAST - 1)
-+
-+/**
-+ * enum nl80211_keytype - key types
-+ * @NL80211_KEYTYPE_GROUP: group key
-+ * @NL80211_KEYTYPE_PAIRWISE: pairwise key
-+ * @NL80211_KEYTYPE_PEER: peer key
-+ */
-+enum nl80211_keytype {
-+ NL80211_KEYTYPE_GROUP,
-+ NL80211_KEYTYPE_PAIRWISE,
-+ NL80211_KEYTYPE_PEER,
-+
-+ /* keep last */
-+ __NL80211_KEYTYPE_AFTER_LAST
-+};
-+#define NL80211_KEYTYPE_MAX (__NL80211_KEYTYPE_AFTER_LAST - 1)
-+
- #endif /* __LINUX_NL80211_H */
---- a/include/net/cfg80211.h
-+++ b/include/net/cfg80211.h
-@@ -3,6 +3,7 @@
-
- #include <linux/netlink.h>
- #include <linux/skbuff.h>
-+#include <linux/nl80211.h>
- #include <net/genetlink.h>
-
- /*
-@@ -49,6 +50,69 @@
- struct ieee80211_radiotap_iterator *iterator);
-
-
-+/**
-+ * struct scan_channel - describes a single channel to scan
-+ * @phymode: PHY mode for this channel
-+ * @channel: channel number (1-14, ...)
-+ * @active: scan actively or passively on this channel
-+ */
-+struct scan_channel {
-+ enum nl80211_phymode phymode;
-+ u32 channel;
-+ int active;
-+};
-+
-+/**
-+ * struct scan_params - describes scan parameters
-+ * @n_channels: number of items in @channels array or -1 to indicate all
-+ * channels should be scanned (in that case @channels will be %NULL)
-+ * @active: when n_channels is -1 this determines active/passive scanning.
-+ * @phymode: when n_channels is -1 this determines PHY mode to scan. It is
-+ * not possible to scan different PHY modes in one request w/o giving
-+ * a channel list.
-+ * @channels: array containing @n_channels &struct scan_channel items
-+ */
-+struct scan_params {
-+ int n_channels;
-+ int active;
-+ enum nl80211_phymode phymode;
-+ struct scan_channel *channels;
-+};
-+
-+/**
-+ * struct association_params - describes association parameters
-+ * @valid: this member contains flags which items are valid
-+ * @bssid: the BSSID of the BSS to associate [%ASSOC_PARAMS_BSSID]
-+ * @timeout: timeout (in TU) [%ASSOC_PARAMS_TIMEOUT]
-+ * @ie: information element(s) to include in the association frames [%ASSOC_PARAMS_IE]
-+ * @ie_len: length of the information element(s)
-+ * @ssid: the SSID, always valid.
-+ * @ssid_len: length of the SSID
-+ */
-+struct association_params {
-+ u8 *bssid;
-+ u32 timeout;
-+ u8 *ie;
-+ int ie_len;
-+ u8 *ssid;
-+ int ssid_len;
-+
-+ unsigned int valid;
-+};
-+#define ASSOC_PARAMS_TIMEOUT (1<<0)
-+
-+/**
-+ * struct key_params - key information
-+ */
-+struct key_params {
-+ u8 *key;
-+ int key_len;
-+ int key_id;
-+ u32 key_type;
-+ u8 *macaddress;
-+ u32 cipher;
-+};
-+
- /* from net/wireless.h */
- struct wiphy;
-
-@@ -68,11 +132,62 @@
- * @add_virtual_intf: create a new virtual interface with the given name
- *
- * @del_virtual_intf: remove the virtual interface determined by ifindex.
-+ *
-+ * @change_virtual_intf: change type of virtual interface
-+ *
-+ * @associate: associate with given parameters
-+ *
-+ * @disassociate: disassociate from current AP
-+ *
-+ * @deauth: deauth from current AP
-+ *
-+ * @initiate_scan: scan with the given information (see &struct scan_params above)
-+ *
-+ * @get_association: get BSSID of the BSS that the device is currently
-+ * associated to and return 1, or return 0 if not
-+ * associated (or a negative error code)
-+ * @get_auth_list: get list of BSSIDs of all BSSs the device has
-+ * authenticated with, must call next_bssid for each,
-+ * next_bssid returns non-zero on error, the given data
-+ * is to be passed to that callback
-+ * @add_key: add a key using &struct key_params
-+ * @del_key: delete a key using info from &struct key_params
- */
- struct cfg80211_ops {
- int (*add_virtual_intf)(struct wiphy *wiphy, char *name,
-- unsigned int type);
-+ enum nl80211_iftype type);
- int (*del_virtual_intf)(struct wiphy *wiphy, int ifindex);
-+ int (*change_virtual_intf)(struct wiphy *wiphy, int ifindex,
-+ enum nl80211_iftype type);
-+
-+ int (*associate)(struct wiphy *wiphy, struct net_device *dev,
-+ struct association_params *params);
-+ int (*disassociate)(struct wiphy *wiphy, struct net_device *dev);
-+ int (*deauth)(struct wiphy *wiphy, struct net_device *dev);
-+
-+
-+ int (*initiate_scan)(struct wiphy *wiphy, struct net_device *dev,
-+ struct scan_params *params);
-+
-+
-+ int (*get_association)(struct wiphy *wiphy, struct net_device *dev,
-+ u8 *bssid);
-+
-+ int (*get_auth_list)(struct wiphy *wiphy, struct net_device *dev,
-+ void *data,
-+ int (*next_bssid)(void *data, u8 *bssid));
-+
-+ int (*add_key)(struct wiphy *wiphy, struct net_device *dev,
-+ struct key_params *params);
-+ int (*del_key)(struct wiphy *wiphy, struct net_device *dev,
-+ struct key_params *params);
- };
-
-+
-+/* helper functions specific to nl80211 */
-+extern void *nl80211hdr_put(struct sk_buff *skb, u32 pid,
-+ u32 seq, int flags, u8 cmd);
-+extern void *nl80211msg_new(struct sk_buff **skb, u32 pid,
-+ u32 seq, int flags, u8 cmd);
-+
- #endif /* __NET_CFG80211_H */
---- a/include/net/iw_handler.h
-+++ b/include/net/iw_handler.h
-@@ -431,7 +431,13 @@
- * Those may be called only within the kernel.
- */
-
--/* functions that may be called by driver modules */
-+/* First : function strictly used inside the kernel */
-+
-+/* Handle /proc/net/wireless, called in net/code/dev.c */
-+extern int dev_get_wireless_info(char * buffer, char **start, off_t offset,
-+ int length);
-+
-+/* Second : functions that may be called by driver modules */
-
- /* Send a single event to user space */
- extern void wireless_send_event(struct net_device * dev,
---- a/include/net/mac80211.h
-+++ b/include/net/mac80211.h
-@@ -300,7 +300,6 @@
- /* Following five fields are used for IEEE 802.11H */
- unsigned int radar_detect;
- unsigned int spect_mgmt;
-- /* All following fields are currently unused. */
- unsigned int quiet_duration; /* duration of quiet period */
- unsigned int quiet_offset; /* how far into the beacon is the quiet
- * period */
-@@ -521,6 +520,9 @@
- * per-packet RC4 key with each TX frame when doing hwcrypto */
- #define IEEE80211_HW_TKIP_REQ_PHASE2_KEY (1<<14)
-
-+ /* The device capable of supporting 11n */
-+#define IEEE80211_HW_SUPPORT_HT_MODE (1<<15)
-+
- u32 flags; /* hardware flags defined above */
-
- /* Set to the size of a needed device specific skb headroom for TX skbs. */
-@@ -649,8 +651,7 @@
- * used if the wlan hardware or low-level driver implements PAE.
- * 80211.o module will anyway filter frames based on authorization
- * state, so this function pointer can be NULL if low-level driver does
-- * not require event notification about port state changes.
-- * Currently unused. */
-+ * not require event notification about port state changes. */
- int (*set_port_auth)(struct ieee80211_hw *hw, u8 *addr,
- int authorized);
-
-@@ -702,8 +703,9 @@
- /* Get statistics of the current TX queue status. This is used to get
- * number of currently queued packets (queue length), maximum queue
- * size (limit), and total number of packets sent using each TX queue
-- * (count).
-- * Currently unused. */
-+ * (count). This information is used for WMM to find out which TX
-+ * queues have room for more packets and by hostapd to provide
-+ * statistics about the current queueing state to external programs. */
- int (*get_tx_stats)(struct ieee80211_hw *hw,
- struct ieee80211_tx_queue_stats *stats);
-
-@@ -713,12 +715,25 @@
- * Must be atomic. */
- u64 (*get_tsf)(struct ieee80211_hw *hw);
-
-+ /* Call low level driver with 11n Block Ack action */
-+ int (*handle_ba_action)(struct ieee80211_hw *hw,
-+ struct ieee80211_mgmt *mgmt);
-+
- /* Reset the TSF timer and allow firmware/hardware to synchronize with
- * other STAs in the IBSS. This is only used in IBSS mode. This
- * function is optional if the firmware/hardware takes full care of
- * TSF synchronization. */
- void (*reset_tsf)(struct ieee80211_hw *hw);
-
-+ /* Configure ht parameters. */
-+ int (*conf_ht)(struct ieee80211_hw *hw,
-+ struct ieee80211_ht_capability *ht_cap_param,
-+ struct ieee80211_ht_additional_info *ht_extra_param);
-+
-+ /* Get ht capabilities from the device */
-+ void (*get_ht_capab)(struct ieee80211_hw *hw,
-+ struct ieee80211_ht_capability *ht_cap_param);
-+
- /* Setup beacon data for IBSS beacons. Unlike access point (Master),
- * IBSS uses a fixed beacon frame which is configured using this
- * function. This handler is required only for IBSS mode. */
+++ /dev/null
---- a/lib/kobject_uevent.c
-+++ b/lib/kobject_uevent.c
-@@ -40,9 +40,22 @@
- char uevent_helper[UEVENT_HELPER_PATH_LEN] = "/sbin/hotplug";
- static DEFINE_SPINLOCK(sequence_lock);
- #if defined(CONFIG_NET)
--static struct sock *uevent_sock;
-+struct sock *uevent_sock = NULL;
-+EXPORT_SYMBOL_GPL(uevent_sock);
- #endif
-
-+u64 uevent_next_seqnum(void)
-+{
-+ u64 seq;
-+
-+ spin_lock(&sequence_lock);
-+ seq = ++uevent_seqnum;
-+ spin_unlock(&sequence_lock);
-+
-+ return seq;
-+}
-+EXPORT_SYMBOL_GPL(uevent_next_seqnum);
-+
- /**
- * kobject_uevent_env - send an uevent with environmental data
- *
-@@ -159,9 +172,7 @@
- }
-
- /* we will send an event, request a new sequence number */
-- spin_lock(&sequence_lock);
-- seq = ++uevent_seqnum;
-- spin_unlock(&sequence_lock);
-+ seq = uevent_next_seqnum();
- sprintf(seq_buff, "SEQNUM=%llu", (unsigned long long)seq);
-
- #if defined(CONFIG_NET)
+++ /dev/null
---- a/sound/core/Kconfig
-+++ b/sound/core/Kconfig
-@@ -9,7 +9,7 @@
- depends on SND
-
- config SND_HWDEP
-- tristate
-+ tristate "Sound hardware support"
- depends on SND
-
- config SND_RAWMIDI
+++ /dev/null
---- /dev/null
-+++ b/Documentation/pps/Makefile
-@@ -0,0 +1,27 @@
-+TARGETS = ppstest ppsctl
-+
-+CFLAGS += -Wall -O2 -D_GNU_SOURCE
-+CFLAGS += -I .
-+CFLAGS += -ggdb
-+
-+# -- Actions section ----------------------------------------------------------
-+
-+.PHONY : all depend dep
-+
-+all : .depend $(TARGETS)
-+
-+.depend depend dep :
-+ $(CC) $(CFLAGS) -M $(TARGETS:=.c) > .depend
-+
-+ifeq (.depend,$(wildcard .depend))
-+include .depend
-+endif
-+
-+
-+# -- Clean section ------------------------------------------------------------
-+
-+.PHONY : clean
-+
-+clean :
-+ rm -f *.o *~ core .depend
-+ rm -f ${TARGETS}
---- /dev/null
-+++ b/Documentation/pps/pps.txt
-@@ -0,0 +1,170 @@
-+
-+ PPS - Pulse Per Second
-+ ----------------------
-+
-+(C) Copyright 2007 Rodolfo Giometti <giometti@enneenne.com>
-+
-+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.
-+
-+
-+
-+Overview
-+--------
-+
-+LinuxPPS provides a programming interface (API) to define into the
-+system several PPS sources.
-+
-+PPS means "pulse per second" and a PPS source is just a device which
-+provides a high precision signal each second so that an application
-+can use it to adjust system clock time.
-+
-+A PPS source can be connected to a serial port (usually to the Data
-+Carrier Detect pin) or to a parallel port (ACK-pin) or to a special
-+CPU's GPIOs (this is the common case in embedded systems) but in each
-+case when a new pulse comes the system must apply to it a timestamp
-+and record it for the userland.
-+
-+Common use is the combination of the NTPD as userland program with a
-+GPS receiver as PPS source to obtain a wallclock-time with
-+sub-millisecond synchronisation to UTC.
-+
-+
-+RFC considerations
-+------------------
-+
-+While implementing a PPS API as RFC 2783 defines and using an embedded
-+CPU GPIO-Pin as physical link to the signal, I encountered a deeper
-+problem:
-+
-+ At startup it needs a file descriptor as argument for the function
-+ time_pps_create().
-+
-+This implies that the source has a /dev/... entry. This assumption is
-+ok for the serial and parallel port, where you can do something
-+useful besides(!) the gathering of timestamps as it is the central
-+task for a PPS-API. But this assumption does not work for a single
-+purpose GPIO line. In this case even basic file-related functionality
-+(like read() and write()) makes no sense at all and should not be a
-+precondition for the use of a PPS-API.
-+
-+The problem can be simply solved if you consider that a PPS source is
-+not always connected with a GPS data source.
-+
-+So your programs should check if the GPS data source (the serial port
-+for instance) is a PPS source too, otherwise they should provide the
-+possibility to open another device as PPS source.
-+
-+In LinuxPPS the PPS sources are simply char devices usually mapped
-+into files /dev/pps0, /dev/pps1, etc..
-+
-+
-+Coding example
-+--------------
-+
-+To register a PPS source into the kernel you should define a struct
-+pps_source_info_s as follow:
-+
-+ static struct pps_source_info_s pps_ktimer_info = {
-+ name : "ktimer",
-+ path : "",
-+ mode : PPS_CAPTUREASSERT | PPS_OFFSETASSERT | \
-+ PPS_ECHOASSERT | \
-+ PPS_CANWAIT | PPS_TSFMT_TSPEC,
-+ echo : pps_ktimer_echo,
-+ owner : THIS_MODULE,
-+ };
-+
-+and then calling the function pps_register_source() in your
-+intialization routine as follow:
-+
-+ source = pps_register_source(&pps_ktimer_info,
-+ PPS_CAPTUREASSERT | PPS_OFFSETASSERT);
-+
-+The pps_register_source() prototype is:
-+
-+ int pps_register_source(struct pps_source_info_s *info, int default_params)
-+
-+where "info" is a pointer to a structure that describes a particular
-+PPS source, "default_params" tells the system what the initial default
-+parameters for the device should be (is obvious that these parameters
-+must be a subset of ones defined into the struct
-+pps_source_info_s which describe the capabilities of the driver).
-+
-+Once you have registered a new PPS source into the system you can
-+signal an assert event (for example in the interrupt handler routine)
-+just using:
-+
-+ pps_event(source, PPS_CAPTUREASSERT, ptr);
-+
-+The same function may also run the defined echo function
-+(pps_ktimer_echo(), passing to it the "ptr" pointer) if the user
-+asked for that... etc..
-+
-+Please see the file drivers/pps/clients/ktimer.c for an example code.
-+
-+
-+SYSFS support
-+-------------
-+
-+If the SYSFS filesystem is enabled in the kernel it provides a new class:
-+
-+ $ ls /sys/class/pps/
-+ pps0/ pps1/ pps2/
-+
-+Every directory is the ID of a PPS sources defined into the system and
-+inside you find several files:
-+
-+ $ ls /sys/class/pps/pps0/
-+ assert clear echo mode name path subsystem@ uevent
-+
-+Inside each "assert" and "clear" file you can find the timestamp and a
-+sequence number:
-+
-+ $ cat /sys/class/pps/pps0/assert
-+ 1170026870.983207967#8
-+
-+Where before the "#" is the timestamp in seconds and after it is the
-+sequence number. Other files are:
-+
-+* echo: reports if the PPS source has an echo function or not;
-+
-+* mode: reports available PPS functioning modes;
-+
-+* name: reports the PPS source's name;
-+
-+* path: reports the PPS source's device path, that is the device the
-+ PPS source is connected to (if it exists).
-+
-+
-+Testing the PPS support
-+-----------------------
-+
-+In order to test the PPS support even without specific hardware you can use
-+the ktimer driver (see the client subsection in the PPS configuration menu)
-+and the userland tools provided into Documentaion/pps/ directory.
-+
-+Once you have enabled the compilation of ktimer just modprobe it (if
-+not statically compiled):
-+
-+ # modprobe ktimer
-+
-+and the run ppstest as follow:
-+
-+ $ ./ppstest /dev/pps0
-+ trying PPS source "/dev/pps1"
-+ found PPS source "/dev/pps1"
-+ ok, found 1 source(s), now start fetching data...
-+ source 0 - assert 1186592699.388832443, sequence: 364 - clear 0.000000000, sequence: 0
-+ source 0 - assert 1186592700.388931295, sequence: 365 - clear 0.000000000, sequence: 0
-+ source 0 - assert 1186592701.389032765, sequence: 366 - clear 0.000000000, sequence: 0
-+
-+Please, note that to compile userland programs you need the file timepps.h
-+(see Documentation/pps/).
---- /dev/null
-+++ b/Documentation/pps/ppsctl.c
-@@ -0,0 +1,62 @@
-+#include <stdio.h>
-+#include <unistd.h>
-+#include <stdlib.h>
-+#include <errno.h>
-+#include <sys/ioctl.h>
-+#include <sys/types.h>
-+#include <sys/stat.h>
-+#include <fcntl.h>
-+#include <string.h>
-+#include <linux/serial.h>
-+
-+void usage(char *name)
-+{
-+ fprintf(stderr, "usage: %s <ttyS> [enable|disable]\n", name);
-+
-+ exit(EXIT_FAILURE);
-+}
-+
-+int main(int argc, char *argv[])
-+{
-+ int fd;
-+ int ret;
-+ struct serial_struct ss;
-+
-+ if (argc < 2)
-+ usage(argv[0]);
-+
-+ fd = open(argv[1], O_RDWR);
-+ if (fd < 0) {
-+ perror("open");
-+ exit(EXIT_FAILURE);
-+ }
-+
-+ ret = ioctl(fd, TIOCGSERIAL, &ss);
-+ if (ret < 0) {
-+ perror("ioctl(TIOCGSERIAL)");
-+ exit(EXIT_FAILURE);
-+ }
-+
-+ if (argc < 3) { /* just read PPS status */
-+ printf("PPS is %sabled\n",
-+ ss.flags & ASYNC_HARDPPS_CD ? "en" : "dis");
-+ exit(EXIT_SUCCESS);
-+ }
-+
-+ if (argv[2][0] == 'e' || argv[2][0] == '1')
-+ ss.flags |= ASYNC_HARDPPS_CD;
-+ else if (argv[2][0] == 'd' || argv[2][0] == '0')
-+ ss.flags &= ~ASYNC_HARDPPS_CD;
-+ else {
-+ fprintf(stderr, "invalid state argument \"%s\"\n", argv[2]);
-+ exit(EXIT_FAILURE);
-+ }
-+
-+ ret = ioctl(fd, TIOCSSERIAL, &ss);
-+ if (ret < 0) {
-+ perror("ioctl(TIOCSSERIAL)");
-+ exit(EXIT_FAILURE);
-+ }
-+
-+ return 0;
-+}
---- /dev/null
-+++ b/Documentation/pps/ppsfind
-@@ -0,0 +1,17 @@
-+#!/bin/sh
-+
-+SYS="/sys/class/pps/"
-+
-+if [ $# -lt 1 ] ; then
-+ echo "usage: ppsfind <name>" >&2
-+ exit 1
-+fi
-+
-+for d in $(ls $SYS) ; do
-+ if grep $1 $SYS/$d/name >& /dev/null || \
-+ grep $1 $SYS/$d/path >& /dev/null ; then
-+ echo "$d: name=$(cat $SYS/$d/name) path=$(cat $SYS/$d/path)"
-+ fi
-+done
-+
-+exit 0
---- /dev/null
-+++ b/Documentation/pps/ppstest.c
-@@ -0,0 +1,151 @@
-+#include <stdio.h>
-+#include <stdlib.h>
-+#include <unistd.h>
-+#include <errno.h>
-+#include <string.h>
-+#include <sys/types.h>
-+#include <sys/stat.h>
-+#include <fcntl.h>
-+
-+#include <timepps.h>
-+
-+int find_source(char *path, pps_handle_t *handle, int *avail_mode)
-+{
-+ pps_params_t params;
-+ int ret;
-+
-+ printf("trying PPS source \"%s\"\n", path);
-+
-+ /* Try to find the source by using the supplied "path" name */
-+ ret = open(path, O_RDWR);
-+ if (ret < 0) {
-+ fprintf(stderr, "unable to open device \"%s\" (%m)\n", path);
-+ return ret;
-+ }
-+
-+ /* Open the PPS source (and check the file descriptor) */
-+ ret = time_pps_create(ret, handle);
-+ if (ret < 0) {
-+ fprintf(stderr, "cannot create a PPS source from device "
-+ "\"%s\" (%m)\n", path);
-+ return -1;
-+ }
-+ printf("found PPS source \"%s\"\n", path);
-+
-+ /* Find out what features are supported */
-+ ret = time_pps_getcap(*handle, avail_mode);
-+ if (ret < 0) {
-+ fprintf(stderr, "cannot get capabilities (%m)\n");
-+ return -1;
-+ }
-+ if ((*avail_mode & PPS_CAPTUREASSERT) == 0) {
-+ fprintf(stderr, "cannot CAPTUREASSERT\n");
-+ return -1;
-+ }
-+ if ((*avail_mode & PPS_OFFSETASSERT) == 0) {
-+ fprintf(stderr, "cannot OFFSETASSERT\n");
-+ return -1;
-+ }
-+
-+ /* Capture assert timestamps, and compensate for a 675 nsec
-+ * propagation delay */
-+ ret = time_pps_getparams(*handle, ¶ms);
-+ if (ret < 0) {
-+ fprintf(stderr, "cannot get parameters (%m)\n");
-+ return -1;
-+ }
-+ params.assert_offset.tv_sec = 0;
-+ params.assert_offset.tv_nsec = 675;
-+ params.mode |= PPS_CAPTUREASSERT | PPS_OFFSETASSERT;
-+ ret = time_pps_setparams(*handle, ¶ms);
-+ if (ret < 0) {
-+ fprintf(stderr, "cannot set parameters (%m)\n");
-+ return -1;
-+ }
-+
-+ return 0;
-+}
-+
-+int fetch_source(int i, pps_handle_t *handle, int *avail_mode)
-+{
-+ struct timespec timeout;
-+ pps_info_t infobuf;
-+ int ret;
-+
-+ /* create a zero-valued timeout */
-+ timeout.tv_sec = 3;
-+ timeout.tv_nsec = 0;
-+
-+retry:
-+ if (*avail_mode & PPS_CANWAIT) /* waits for the next event */
-+ ret = time_pps_fetch(*handle, PPS_TSFMT_TSPEC, &infobuf,
-+ &timeout);
-+ else {
-+ sleep(1);
-+ ret = time_pps_fetch(*handle, PPS_TSFMT_TSPEC, &infobuf,
-+ &timeout);
-+ }
-+ if (ret < 0) {
-+ if (ret == -EINTR) {
-+ fprintf(stderr, "time_pps_fetch() got a signal!\n");
-+ goto retry;
-+ }
-+
-+ fprintf(stderr, "time_pps_fetch() error %d (%m)\n", ret);
-+ return -1;
-+ }
-+
-+ printf("source %d - "
-+ "assert %ld.%09ld, sequence: %ld - "
-+ "clear %ld.%09ld, sequence: %ld\n",
-+ i,
-+ infobuf.assert_timestamp.tv_sec,
-+ infobuf.assert_timestamp.tv_nsec,
-+ infobuf.assert_sequence,
-+ infobuf.clear_timestamp.tv_sec,
-+ infobuf.clear_timestamp.tv_nsec, infobuf.clear_sequence);
-+
-+ return 0;
-+}
-+
-+void usage(char *name)
-+{
-+ fprintf(stderr, "usage: %s <ppsdev> [<ppsdev> ...]\n", name);
-+ exit(EXIT_FAILURE);
-+}
-+
-+int main(int argc, char *argv[])
-+{
-+ int num;
-+ pps_handle_t handle[4];
-+ int avail_mode[4];
-+ int i = 0;
-+ int ret;
-+
-+ /* Check the command line */
-+ if (argc < 2)
-+ usage(argv[0]);
-+
-+ for (i = 1; i < argc && i <= 4; i++) {
-+ ret = find_source(argv[i], &handle[i - 1], &avail_mode[i - 1]);
-+ if (ret < 0)
-+ exit(EXIT_FAILURE);
-+ }
-+
-+ num = i - 1;
-+ printf("ok, found %d source(s), now start fetching data...\n", num);
-+
-+ /* loop, printing the most recent timestamp every second or so */
-+ while (1) {
-+ for (i = 0; i < num; i++) {
-+ ret = fetch_source(i, &handle[i], &avail_mode[i]);
-+ if (ret < 0 && errno != ETIMEDOUT)
-+ exit(EXIT_FAILURE);
-+ }
-+ }
-+
-+ for (; i >= 0; i--)
-+ time_pps_destroy(handle[i]);
-+
-+ return 0;
-+}
---- /dev/null
-+++ b/Documentation/pps/timepps.h
-@@ -0,0 +1,193 @@
-+/*
-+ * timepps.h -- PPS API main header
-+ *
-+ * Copyright (C) 2005-2007 Rodolfo Giometti <giometti@linux.it>
-+ *
-+ * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
-+ */
-+
-+#ifndef _SYS_TIMEPPS_H_
-+#define _SYS_TIMEPPS_H_
-+
-+#include <sys/syscall.h>
-+#include <unistd.h>
-+#include <errno.h>
-+#include <linux/pps.h>
-+
-+/*
-+ * New data structures
-+ */
-+
-+struct ntp_fp {
-+ unsigned int integral;
-+ unsigned int fractional;
-+};
-+
-+union pps_timeu {
-+ struct timespec tspec;
-+ struct ntp_fp ntpfp;
-+ unsigned long longpad[3];
-+};
-+
-+struct pps_info {
-+ unsigned long assert_sequence; /* seq. num. of assert event */
-+ unsigned long clear_sequence; /* seq. num. of clear event */
-+ union pps_timeu assert_tu; /* time of assert event */
-+ union pps_timeu clear_tu; /* time of clear event */
-+ int current_mode; /* current mode bits */
-+};
-+
-+struct pps_params {
-+ int api_version; /* API version # */
-+ int mode; /* mode bits */
-+ union pps_timeu assert_off_tu; /* offset compensation for assert */
-+ union pps_timeu clear_off_tu; /* offset compensation for clear */
-+};
-+
-+typedef int pps_handle_t; /* represents a PPS source */
-+typedef unsigned long pps_seq_t; /* sequence number */
-+typedef struct ntp_fp ntp_fp_t; /* NTP-compatible time stamp */
-+typedef union pps_timeu pps_timeu_t; /* generic data type for time stamps */
-+typedef struct pps_info pps_info_t;
-+typedef struct pps_params pps_params_t;
-+
-+#define assert_timestamp assert_tu.tspec
-+#define clear_timestamp clear_tu.tspec
-+
-+#define assert_timestamp_ntpfp assert_tu.ntpfp
-+#define clear_timestamp_ntpfp clear_tu.ntpfp
-+
-+#define assert_offset assert_off_tu.tspec
-+#define clear_offset clear_off_tu.tspec
-+
-+#define assert_offset_ntpfp assert_off_tu.ntpfp
-+#define clear_offset_ntpfp clear_off_tu.ntpfp
-+
-+/*
-+ * The PPS API
-+ */
-+
-+static __inline int time_pps_create(int source, pps_handle_t *handle)
-+{
-+ int ret;
-+
-+ if (!handle) {
-+ errno = EINVAL;
-+ return -1;
-+ }
-+
-+ /* First we check if current device is a PPS valid PPS one...
-+ */
-+ ret = ioctl(source, PPS_CHECK);
-+ if (ret) {
-+ errno = EOPNOTSUPP;
-+ return -1;
-+ }
-+
-+ /* ... then since in LinuxPPS there are no differences between a
-+ * "PPS source" and a "PPS handle", we simply return the same value.
-+ */
-+ *handle = source;
-+
-+ return 0;
-+}
-+
-+static __inline int time_pps_destroy(pps_handle_t handle)
-+{
-+ return close(handle);
-+}
-+
-+static __inline int time_pps_getparams(pps_handle_t handle,
-+ pps_params_t *ppsparams)
-+{
-+ int ret;
-+ struct pps_kparams __ppsparams;
-+
-+ ret = ioctl(handle, PPS_GETPARAMS, &__ppsparams);
-+
-+ ppsparams->api_version = __ppsparams.api_version;
-+ ppsparams->mode = __ppsparams.mode;
-+ ppsparams->assert_off_tu.tspec.tv_sec = __ppsparams.assert_off_tu.sec;
-+ ppsparams->assert_off_tu.tspec.tv_nsec = __ppsparams.assert_off_tu.nsec;
-+ ppsparams->clear_off_tu.tspec.tv_sec = __ppsparams.clear_off_tu.sec;
-+ ppsparams->clear_off_tu.tspec.tv_nsec = __ppsparams.clear_off_tu.nsec;
-+
-+ return ret;
-+}
-+
-+static __inline int time_pps_setparams(pps_handle_t handle,
-+ const pps_params_t *ppsparams)
-+{
-+ struct pps_kparams __ppsparams;
-+
-+ __ppsparams.api_version = ppsparams->api_version;
-+ __ppsparams.mode = ppsparams->mode;
-+ __ppsparams.assert_off_tu.sec = ppsparams->assert_off_tu.tspec.tv_sec;
-+ __ppsparams.assert_off_tu.nsec = ppsparams->assert_off_tu.tspec.tv_nsec;
-+ __ppsparams.clear_off_tu.sec = ppsparams->clear_off_tu.tspec.tv_sec;
-+ __ppsparams.clear_off_tu.nsec = ppsparams->clear_off_tu.tspec.tv_nsec;
-+
-+ return ioctl(handle, PPS_SETPARAMS, &__ppsparams);
-+}
-+
-+/* Get capabilities for handle */
-+static __inline int time_pps_getcap(pps_handle_t handle, int *mode)
-+{
-+ return ioctl(handle, PPS_GETCAP, mode);
-+}
-+
-+static __inline int time_pps_fetch(pps_handle_t handle, const int tsformat,
-+ pps_info_t *ppsinfobuf,
-+ const struct timespec *timeout)
-+{
-+ struct pps_fdata __fdata;
-+ int ret;
-+
-+ /* Sanity checks */
-+ if (tsformat != PPS_TSFMT_TSPEC) {
-+ errno = EINVAL;
-+ return -1;
-+ }
-+
-+ if (timeout) {
-+ __fdata.timeout.sec = timeout->tv_sec;
-+ __fdata.timeout.nsec = timeout->tv_nsec;
-+ __fdata.timeout.flags = ~PPS_TIME_INVALID;
-+ } else
-+ __fdata.timeout.flags = PPS_TIME_INVALID;
-+
-+ ret = ioctl(handle, PPS_FETCH, &__fdata);
-+
-+ ppsinfobuf->assert_sequence = __fdata.info.assert_sequence;
-+ ppsinfobuf->clear_sequence = __fdata.info.clear_sequence;
-+ ppsinfobuf->assert_tu.tspec.tv_sec = __fdata.info.assert_tu.sec;
-+ ppsinfobuf->assert_tu.tspec.tv_nsec = __fdata.info.assert_tu.nsec;
-+ ppsinfobuf->clear_tu.tspec.tv_sec = __fdata.info.clear_tu.sec;
-+ ppsinfobuf->clear_tu.tspec.tv_nsec = __fdata.info.clear_tu.nsec;
-+ ppsinfobuf->current_mode = __fdata.info.current_mode;
-+
-+ return ret;
-+}
-+
-+static __inline int time_pps_kcbind(pps_handle_t handle,
-+ const int kernel_consumer,
-+ const int edge, const int tsformat)
-+{
-+ /* LinuxPPS doesn't implement kernel consumer feature */
-+ errno = EOPNOTSUPP;
-+ return -1;
-+}
-+
-+#endif /* _SYS_TIMEPPS_H_ */
---- a/MAINTAINERS
-+++ b/MAINTAINERS
-@@ -3011,6 +3011,13 @@
- M: jchapman@katalix.com
- S: Maintained
-
-+PPS SUPPORT
-+P: Rodolfo Giometti
-+M: giometti@enneenne.com
-+W: http://wiki.enneenne.com/index.php/LinuxPPS_support
-+L: linuxpps@ml.enneenne.com
-+S: Maintained
-+
- PREEMPTIBLE KERNEL
- P: Robert Love
- M: rml@tech9.net
---- a/drivers/Kconfig
-+++ b/drivers/Kconfig
-@@ -52,6 +52,8 @@
-
- source "drivers/spi/Kconfig"
-
-+source "drivers/pps/Kconfig"
-+
- source "drivers/w1/Kconfig"
-
- source "drivers/power/Kconfig"
---- a/drivers/Makefile
-+++ b/drivers/Makefile
-@@ -63,6 +63,7 @@
- obj-$(CONFIG_I2O) += message/
- obj-$(CONFIG_RTC_LIB) += rtc/
- obj-y += i2c/
-+obj-$(CONFIG_PPS) += pps/
- obj-$(CONFIG_W1) += w1/
- obj-$(CONFIG_POWER_SUPPLY) += power/
- obj-$(CONFIG_HWMON) += hwmon/
---- a/drivers/char/lp.c
-+++ b/drivers/char/lp.c
-@@ -746,6 +746,27 @@
-
- #endif /* console on line printer */
-
-+/* Support for PPS signal on the line printer */
-+
-+#ifdef CONFIG_PPS_CLIENT_LP
-+
-+static void lp_pps_echo(int source, int event, void *data)
-+{
-+ struct parport *port = data;
-+ unsigned char status = parport_read_status(port);
-+
-+ /* echo event via SEL bit */
-+ parport_write_control(port,
-+ parport_read_control(port) | PARPORT_CONTROL_SELECT);
-+
-+ /* signal no event */
-+ if ((status & PARPORT_STATUS_ACK) != 0)
-+ parport_write_control(port,
-+ parport_read_control(port) & ~PARPORT_CONTROL_SELECT);
-+}
-+
-+#endif
-+
- /* --- initialisation code ------------------------------------- */
-
- static int parport_nr[LP_NO] = { [0 ... LP_NO-1] = LP_PARPORT_UNSPEC };
-@@ -817,6 +838,38 @@
- }
- #endif
-
-+#ifdef CONFIG_PPS_CLIENT_LP
-+ port->pps_info.owner = THIS_MODULE;
-+ port->pps_info.dev = port->dev;
-+ snprintf(port->pps_info.path, PPS_MAX_NAME_LEN, "/dev/lp%d", nr);
-+
-+ /* No PPS support if lp port has no IRQ line */
-+ if (port->irq != PARPORT_IRQ_NONE) {
-+ strncpy(port->pps_info.name, port->name, PPS_MAX_NAME_LEN);
-+
-+ port->pps_info.mode = PPS_CAPTUREASSERT | PPS_OFFSETASSERT | \
-+ PPS_ECHOASSERT | \
-+ PPS_CANWAIT | PPS_TSFMT_TSPEC;
-+
-+ port->pps_info.echo = lp_pps_echo;
-+
-+ port->pps_source = pps_register_source(&(port->pps_info),
-+ PPS_CAPTUREASSERT | PPS_OFFSETASSERT);
-+ if (port->pps_source < 0)
-+ dev_err(port->dev,
-+ "cannot register PPS source \"%s\"\n",
-+ port->pps_info.path);
-+ else
-+ dev_info(port->dev, "PPS source #%d \"%s\" added\n",
-+ port->pps_source, port->pps_info.path);
-+ } else {
-+ port->pps_source = -1;
-+ dev_err(port->dev, "PPS support disabled due port \"%s\" is "
-+ "in polling mode\n",
-+ port->pps_info.path);
-+ }
-+#endif
-+
- return 0;
- }
-
-@@ -860,6 +913,14 @@
- console_registered = NULL;
- }
- #endif /* CONFIG_LP_CONSOLE */
-+
-+#ifdef CONFIG_PPS_CLIENT_LP
-+ if (port->pps_source >= 0) {
-+ pps_unregister_source(port->pps_source);
-+ dev_dbg(port->dev, "PPS source #%d \"%s\" removed\n",
-+ port->pps_source, port->pps_info.path);
-+ }
-+#endif
- }
-
- static struct parport_driver lp_driver = {
---- /dev/null
-+++ b/drivers/pps/Kconfig
-@@ -0,0 +1,34 @@
-+#
-+# PPS support configuration
-+#
-+
-+menu "PPS support"
-+
-+config PPS
-+ tristate "PPS support"
-+ depends on EXPERIMENTAL
-+ ---help---
-+ PPS (Pulse Per Second) is a special pulse provided by some GPS
-+ antennae. Userland can use it to get an high time reference.
-+
-+ Some antennae's PPS signals are connected with the CD (Carrier
-+ Detect) pin of the serial line they use to communicate with the
-+ host. In this case use the SERIAL_LINE client support.
-+
-+ Some antennae's PPS signals are connected with some special host
-+ inputs so you have to enable the corresponding client support.
-+
-+ To compile this driver as a module, choose M here: the module
-+ will be called pps_core.ko.
-+
-+config PPS_DEBUG
-+ bool "PPS debugging messages"
-+ depends on PPS
-+ help
-+ Say Y here if you want the PPS support to produce a bunch of debug
-+ messages to the system log. Select this if you are having a
-+ problem with PPS support and want to see more of what is going on.
-+
-+source drivers/pps/clients/Kconfig
-+
-+endmenu
---- /dev/null
-+++ b/drivers/pps/Makefile
-@@ -0,0 +1,11 @@
-+#
-+# Makefile for the PPS core.
-+#
-+
-+pps_core-objs += pps.o kapi.o sysfs.o
-+obj-$(CONFIG_PPS) += pps_core.o
-+obj-y += clients/
-+
-+ifeq ($(CONFIG_PPS_DEBUG),y)
-+EXTRA_CFLAGS += -DDEBUG
-+endif
---- /dev/null
-+++ b/drivers/pps/clients/Kconfig
-@@ -0,0 +1,38 @@
-+#
-+# PPS clients configuration
-+#
-+
-+if PPS
-+
-+comment "PPS clients support"
-+
-+config PPS_CLIENT_KTIMER
-+ tristate "Kernel timer client (Testing client, use for debug)"
-+ help
-+ If you say yes here you get support for a PPS debugging client
-+ which uses a kernel timer to generate the PPS signal.
-+
-+ This driver can also be built as a module. If so, the module
-+ will be called ktimer.ko.
-+
-+comment "UART serial support (forced off)"
-+ depends on ! (SERIAL_CORE != n && !(PPS = m && SERIAL_CORE = y))
-+
-+config PPS_CLIENT_UART
-+ bool "UART serial support"
-+ depends on SERIAL_CORE != n && !(PPS = m && SERIAL_CORE = y)
-+ help
-+ If you say yes here you get support for a PPS source connected
-+ with the CD (Carrier Detect) pin of your serial port.
-+
-+comment "Parallel printer support (forced off)"
-+ depends on !( PRINTER != n && !(PPS = m && PRINTER = y))
-+
-+config PPS_CLIENT_LP
-+ bool "Parallel printer support"
-+ depends on PRINTER != n && !(PPS = m && PRINTER = y)
-+ help
-+ If you say yes here you get support for a PPS source connected
-+ with the interrupt pin of your parallel port.
-+
-+endif
---- /dev/null
-+++ b/drivers/pps/clients/Makefile
-@@ -0,0 +1,9 @@
-+#
-+# Makefile for PPS clients.
-+#
-+
-+obj-$(CONFIG_PPS_CLIENT_KTIMER) += ktimer.o
-+
-+ifeq ($(CONFIG_PPS_DEBUG),y)
-+EXTRA_CFLAGS += -DDEBUG
-+endif
---- /dev/null
-+++ b/drivers/pps/clients/ktimer.c
-@@ -0,0 +1,114 @@
-+/*
-+ * ktimer.c -- kernel timer test client
-+ *
-+ *
-+ * Copyright (C) 2005-2006 Rodolfo Giometti <giometti@linux.it>
-+ *
-+ * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
-+ */
-+
-+
-+#include <linux/kernel.h>
-+#include <linux/module.h>
-+#include <linux/init.h>
-+#include <linux/time.h>
-+#include <linux/timer.h>
-+
-+#include <linux/pps.h>
-+
-+/*
-+ * Global variables
-+ */
-+
-+static int source;
-+static struct timer_list ktimer;
-+
-+/*
-+ * The kernel timer
-+ */
-+
-+static void pps_ktimer_event(unsigned long ptr)
-+{
-+ pr_info("PPS event at %lu\n", jiffies);
-+
-+ pps_event(source, PPS_CAPTUREASSERT, NULL);
-+
-+ mod_timer(&ktimer, jiffies + HZ);
-+}
-+
-+/*
-+ * The echo function
-+ */
-+
-+static void pps_ktimer_echo(int source, int event, void *data)
-+{
-+ pr_info("echo %s %s for source %d\n",
-+ event & PPS_CAPTUREASSERT ? "assert" : "",
-+ event & PPS_CAPTURECLEAR ? "clear" : "",
-+ source);
-+}
-+
-+/*
-+ * The PPS info struct
-+ */
-+
-+static struct pps_source_info pps_ktimer_info = {
-+ name : "ktimer",
-+ path : "",
-+ mode : PPS_CAPTUREASSERT | PPS_OFFSETASSERT | \
-+ PPS_ECHOASSERT | \
-+ PPS_CANWAIT | PPS_TSFMT_TSPEC,
-+ echo : pps_ktimer_echo,
-+ owner : THIS_MODULE,
-+};
-+
-+/*
-+ * Module staff
-+ */
-+
-+static void __exit pps_ktimer_exit(void)
-+{
-+ del_timer_sync(&ktimer);
-+ pps_unregister_source(source);
-+
-+ pr_info("ktimer PPS source unregistered\n");
-+}
-+
-+static int __init pps_ktimer_init(void)
-+{
-+ int ret;
-+
-+ ret = pps_register_source(&pps_ktimer_info,
-+ PPS_CAPTUREASSERT | PPS_OFFSETASSERT);
-+ if (ret < 0) {
-+ printk(KERN_ERR "cannot register ktimer source\n");
-+ return ret;
-+ }
-+ source = ret;
-+
-+ setup_timer(&ktimer, pps_ktimer_event, 0);
-+ mod_timer(&ktimer, jiffies + HZ);
-+
-+ pr_info("ktimer PPS source registered at %d\n", source);
-+
-+ return 0;
-+}
-+
-+module_init(pps_ktimer_init);
-+module_exit(pps_ktimer_exit);
-+
-+MODULE_AUTHOR("Rodolfo Giometti <giometti@linux.it>");
-+MODULE_DESCRIPTION("dummy PPS source by using a kernel timer (just for debug)");
-+MODULE_LICENSE("GPL");
---- /dev/null
-+++ b/drivers/pps/kapi.c
-@@ -0,0 +1,271 @@
-+/*
-+ * kapi.c -- kernel API
-+ *
-+ *
-+ * Copyright (C) 2005-2007 Rodolfo Giometti <giometti@linux.it>
-+ *
-+ * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
-+ */
-+
-+
-+#include <linux/kernel.h>
-+#include <linux/module.h>
-+#include <linux/init.h>
-+#include <linux/sched.h>
-+#include <linux/time.h>
-+#include <linux/spinlock.h>
-+#include <linux/idr.h>
-+#include <linux/fs.h>
-+#include <linux/pps.h>
-+
-+/*
-+ * Local variables
-+ */
-+
-+static spinlock_t idr_lock = SPIN_LOCK_UNLOCKED;
-+static DEFINE_IDR(pps_idr);
-+
-+/*
-+ * Local functions
-+ */
-+
-+static void pps_add_offset(struct pps_ktime *ts, struct pps_ktime *offset)
-+{
-+ ts->nsec += offset->nsec;
-+ if (ts->nsec >= NSEC_PER_SEC) {
-+ ts->nsec -= NSEC_PER_SEC;
-+ ts->sec++;
-+ } else if (ts->nsec < 0) {
-+ ts->nsec += NSEC_PER_SEC;
-+ ts->sec--;
-+ }
-+ ts->sec += offset->sec;
-+}
-+
-+/*
-+ * Exported functions
-+ */
-+
-+int pps_register_source(struct pps_source_info *info, int default_params)
-+{
-+ struct pps_device *pps;
-+ int id;
-+ int err;
-+
-+ /* Sanity checks */
-+ if ((info->mode & default_params) != default_params) {
-+ printk(KERN_ERR "pps: %s: unsupported default parameters\n",
-+ info->name);
-+ err = -EINVAL;
-+ goto pps_register_source_exit;
-+ }
-+ if ((info->mode & (PPS_ECHOASSERT | PPS_ECHOCLEAR)) != 0 &&
-+ info->echo == NULL) {
-+ printk(KERN_ERR "pps: %s: echo function is not defined\n",
-+ info->name);
-+ err = -EINVAL;
-+ goto pps_register_source_exit;
-+ }
-+ if ((info->mode & (PPS_TSFMT_TSPEC | PPS_TSFMT_NTPFP)) == 0) {
-+ printk(KERN_ERR "pps: %s: unspecified time format\n",
-+ info->name);
-+ err = -EINVAL;
-+ goto pps_register_source_exit;
-+ }
-+
-+ /* Allocate memory for the new PPS source struct */
-+ pps = kzalloc(sizeof(struct pps_device), GFP_KERNEL);
-+ if (pps == NULL) {
-+ err = -ENOMEM;
-+ goto pps_register_source_exit;
-+ }
-+
-+ /* Get new ID for the new PPS source */
-+ if (idr_pre_get(&pps_idr, GFP_KERNEL) == 0) {
-+ err = -ENOMEM;
-+ goto kfree_pps;
-+ }
-+
-+ spin_lock_irq(&idr_lock);
-+ err = idr_get_new(&pps_idr, pps, &id);
-+ spin_unlock_irq(&idr_lock);
-+
-+ if (err < 0)
-+ goto kfree_pps;
-+
-+ id = id & MAX_ID_MASK;
-+ if (id >= PPS_MAX_SOURCES) {
-+ printk(KERN_ERR "pps: %s: too much PPS sources in the system\n",
-+ info->name);
-+ err = -EBUSY;
-+ goto free_idr;
-+ }
-+
-+ pps->id = id;
-+ pps->params.api_version = PPS_API_VERS;
-+ pps->params.mode = default_params;
-+ pps->info = *info;
-+
-+ init_waitqueue_head(&pps->queue);
-+ spin_lock_init(&pps->lock);
-+ atomic_set(&pps->usage, 0);
-+ init_waitqueue_head(&pps->usage_queue);
-+
-+ /* Create the char device */
-+ err = pps_register_cdev(pps);
-+ if (err < 0) {
-+ printk(KERN_ERR "pps: %s: unable to create char device\n",
-+ info->name);
-+ goto free_idr;
-+ }
-+
-+ /* Create the sysfs entry */
-+ err = pps_sysfs_create_source_entry(pps);
-+ if (err < 0) {
-+ printk(KERN_ERR "pps: %s: unable to create sysfs entries\n",
-+ info->name);
-+ goto unregister_cdev;
-+ }
-+
-+ pr_info("new PPS source %s at ID %d\n", info->name, id);
-+
-+ return id;
-+
-+unregister_cdev:
-+ pps_unregister_cdev(pps);
-+
-+free_idr:
-+ spin_lock_irq(&idr_lock);
-+ idr_remove(&pps_idr, id);
-+ spin_unlock_irq(&idr_lock);
-+
-+kfree_pps:
-+ kfree(pps);
-+
-+pps_register_source_exit:
-+ printk(KERN_ERR "pps: %s: unable to register source\n", info->name);
-+
-+ return err;
-+}
-+EXPORT_SYMBOL(pps_register_source);
-+
-+void pps_unregister_source(int source)
-+{
-+ struct pps_device *pps;
-+
-+ spin_lock_irq(&idr_lock);
-+ pps = idr_find(&pps_idr, source);
-+
-+ if (!pps) {
-+ spin_unlock_irq(&idr_lock);
-+ return;
-+ }
-+
-+ /* This should be done first in order to deny IRQ handlers
-+ * to access PPS structs
-+ */
-+
-+ idr_remove(&pps_idr, pps->id);
-+ spin_unlock_irq(&idr_lock);
-+
-+ wait_event(pps->usage_queue, atomic_read(&pps->usage) == 0);
-+
-+ pps_sysfs_remove_source_entry(pps);
-+ pps_unregister_cdev(pps);
-+ kfree(pps);
-+}
-+EXPORT_SYMBOL(pps_unregister_source);
-+
-+void pps_event(int source, int event, void *data)
-+{
-+ struct pps_device *pps;
-+ struct timespec __ts;
-+ struct pps_ktime ts;
-+ unsigned long flags;
-+
-+ /* First of all we get the time stamp... */
-+ getnstimeofday(&__ts);
-+
-+ /* ... and translate it to PPS time data struct */
-+ ts.sec = __ts.tv_sec;
-+ ts.nsec = __ts.tv_nsec;
-+
-+ if ((event & (PPS_CAPTUREASSERT | PPS_CAPTURECLEAR)) == 0 ) {
-+ printk(KERN_ERR "pps: unknown event (%x) for source %d\n",
-+ event, source);
-+ return;
-+ }
-+
-+ spin_lock_irqsave(&idr_lock, flags);
-+ pps = idr_find(&pps_idr, source);
-+
-+ /* If we find a valid PPS source we lock it before leaving
-+ * the lock!
-+ */
-+ if (pps)
-+ atomic_inc(&pps->usage);
-+ spin_unlock_irqrestore(&idr_lock, flags);
-+
-+ if (!pps)
-+ return;
-+
-+ pr_debug("PPS event on source %d at at %llu.%06u\n",
-+ pps->id, ts.sec, ts.nsec);
-+
-+ spin_lock_irqsave(&pps->lock, flags);
-+
-+ /* Must call the echo function? */
-+ if ((pps->params.mode & (PPS_ECHOASSERT | PPS_ECHOCLEAR)))
-+ pps->info.echo(source, event, data);
-+
-+ /* Check the event */
-+ pps->current_mode = pps->params.mode;
-+ if (event & PPS_CAPTUREASSERT) {
-+ /* We have to add an offset? */
-+ if (pps->params.mode & PPS_OFFSETASSERT)
-+ pps_add_offset(&ts, &pps->params.assert_off_tu);
-+
-+ /* Save the time stamp */
-+ pps->assert_tu = ts;
-+ pps->assert_sequence++;
-+ pr_debug("capture assert seq #%u for source %d\n",
-+ pps->assert_sequence, source);
-+ }
-+ if (event & PPS_CAPTURECLEAR) {
-+ /* We have to add an offset? */
-+ if (pps->params.mode & PPS_OFFSETCLEAR)
-+ pps_add_offset(&ts, &pps->params.clear_off_tu);
-+
-+ /* Save the time stamp */
-+ pps->clear_tu = ts;
-+ pps->clear_sequence++;
-+ pr_debug("capture clear seq #%u for source %d\n",
-+ pps->clear_sequence, source);
-+ }
-+
-+ pps->go = ~0;
-+ wake_up_interruptible(&pps->queue);
-+
-+ kill_fasync(&pps->async_queue, SIGIO, POLL_IN);
-+
-+ spin_unlock_irqrestore(&pps->lock, flags);
-+
-+ /* Now we can release the PPS source for (possible) deregistration */
-+ spin_lock_irqsave(&idr_lock, flags);
-+ atomic_dec(&pps->usage);
-+ wake_up_all(&pps->usage_queue);
-+ spin_unlock_irqrestore(&idr_lock, flags);
-+}
-+EXPORT_SYMBOL(pps_event);
---- /dev/null
-+++ b/drivers/pps/pps.c
-@@ -0,0 +1,332 @@
-+/*
-+ * pps.c -- Main PPS support file
-+ *
-+ *
-+ * Copyright (C) 2005-2007 Rodolfo Giometti <giometti@linux.it>
-+ *
-+ * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
-+ */
-+
-+
-+#include <linux/kernel.h>
-+#include <linux/version.h>
-+#include <linux/module.h>
-+#include <linux/init.h>
-+#include <linux/sched.h>
-+#include <linux/uaccess.h>
-+#include <linux/cdev.h>
-+#include <linux/poll.h>
-+#include <linux/pps.h>
-+
-+/*
-+ * Local variables
-+ */
-+
-+static dev_t pps_devt;
-+static struct class *pps_class;
-+
-+/*
-+ * Char device methods
-+ */
-+
-+static unsigned int pps_cdev_poll(struct file *file, poll_table *wait)
-+{
-+ struct pps_device *pps = file->private_data;
-+
-+ poll_wait(file, &pps->queue, wait);
-+
-+ return POLLIN | POLLRDNORM;
-+}
-+
-+static int pps_cdev_fasync(int fd, struct file *file, int on)
-+{
-+ struct pps_device *pps = file->private_data;
-+ return fasync_helper(fd, file, on, &pps->async_queue);
-+}
-+
-+static int pps_cdev_ioctl(struct inode *inode, struct file *file,
-+ unsigned int cmd, unsigned long arg)
-+{
-+ struct pps_device *pps = file->private_data;
-+ struct pps_kparams params;
-+ struct pps_fdata fdata;
-+ unsigned long ticks;
-+ void __user *uarg = (void __user *) arg;
-+ int __user *iuarg = (int __user *) arg;
-+ int err;
-+
-+ switch (cmd) {
-+ case PPS_CHECK:
-+
-+ /* This does nothing but signal we are a PPS source... */
-+
-+ return 0;
-+
-+ case PPS_GETPARAMS:
-+ pr_debug("PPS_GETPARAMS: source %d\n", pps->id);
-+
-+ /* Sanity checks */
-+ if (!uarg)
-+ return -EINVAL;
-+
-+ /* Return current parameters */
-+ err = copy_to_user(uarg, &pps->params,
-+ sizeof(struct pps_kparams));
-+ if (err)
-+ return -EFAULT;
-+
-+ break;
-+
-+ case PPS_SETPARAMS:
-+ pr_debug("PPS_SETPARAMS: source %d\n", pps->id);
-+
-+ /* Check the capabilities */
-+ if (!capable(CAP_SYS_TIME))
-+ return -EPERM;
-+
-+ /* Sanity checks */
-+ if (!uarg)
-+ return -EINVAL;
-+ err = copy_from_user(¶ms, uarg, sizeof(struct pps_kparams));
-+ if (err)
-+ return -EFAULT;
-+ if (!(params.mode & (PPS_CAPTUREASSERT | PPS_CAPTURECLEAR))) {
-+ pr_debug("capture mode unspecified (%x)\n",
-+ params.mode);
-+ return -EINVAL;
-+ }
-+
-+ /* Check for supported capabilities */
-+ if ((params.mode & ~pps->info.mode) != 0) {
-+ pr_debug("unsupported capabilities (%x)\n",
-+ params.mode);
-+ return -EINVAL;
-+ }
-+
-+ spin_lock_irq(&pps->lock);
-+
-+ /* Save the new parameters */
-+ pps->params = params;
-+
-+ /* Restore the read only parameters */
-+ if ((params.mode & (PPS_TSFMT_TSPEC | PPS_TSFMT_NTPFP)) == 0) {
-+ /* section 3.3 of RFC 2783 interpreted */
-+ pr_debug("time format unspecified (%x)\n",
-+ params.mode);
-+ pps->params.mode |= PPS_TSFMT_TSPEC;
-+ }
-+ if (pps->info.mode & PPS_CANWAIT)
-+ pps->params.mode |= PPS_CANWAIT;
-+ pps->params.api_version = PPS_API_VERS;
-+
-+ spin_unlock_irq(&pps->lock);
-+
-+ break;
-+
-+ case PPS_GETCAP:
-+ pr_debug("PPS_GETCAP: source %d\n", pps->id);
-+
-+ /* Sanity checks */
-+ if (!uarg)
-+ return -EINVAL;
-+
-+ err = put_user(pps->info.mode, iuarg);
-+ if (err)
-+ return -EFAULT;
-+
-+ break;
-+
-+ case PPS_FETCH:
-+ pr_debug("PPS_FETCH: source %d\n", pps->id);
-+
-+ if (!uarg)
-+ return -EINVAL;
-+ err = copy_from_user(&fdata, uarg, sizeof(struct pps_fdata));
-+ if (err)
-+ return -EFAULT;
-+
-+ pps->go = 0;
-+
-+ /* Manage the timeout */
-+ if (fdata.timeout.flags & PPS_TIME_INVALID)
-+ err = wait_event_interruptible(pps->queue, pps->go);
-+ else {
-+ pr_debug("timeout %lld.%09d\n",
-+ fdata.timeout.sec, fdata.timeout.nsec);
-+ ticks = fdata.timeout.sec * HZ;
-+ ticks += fdata.timeout.nsec / (NSEC_PER_SEC / HZ);
-+
-+ if (ticks != 0) {
-+ err = wait_event_interruptible_timeout(
-+ pps->queue, pps->go, ticks);
-+ if (err == 0)
-+ return -ETIMEDOUT;
-+ }
-+ }
-+
-+ /* Check for pending signals */
-+ if (err == -ERESTARTSYS) {
-+ pr_debug("pending signal caught\n");
-+ return -EINTR;
-+ }
-+
-+ /* Return the fetched timestamp */
-+ spin_lock_irq(&pps->lock);
-+
-+ fdata.info.assert_sequence = pps->assert_sequence;
-+ fdata.info.clear_sequence = pps->clear_sequence;
-+ fdata.info.assert_tu = pps->assert_tu;
-+ fdata.info.clear_tu = pps->clear_tu;
-+ fdata.info.current_mode = pps->current_mode;
-+
-+ spin_unlock_irq(&pps->lock);
-+
-+ err = copy_to_user(uarg, &fdata, sizeof(struct pps_fdata));
-+ if (err)
-+ return -EFAULT;
-+
-+ break;
-+
-+ default:
-+ return -ENOTTY;
-+ break;
-+ }
-+
-+ return 0;
-+}
-+
-+static int pps_cdev_open(struct inode *inode, struct file *file)
-+{
-+ struct pps_device *pps = container_of(inode->i_cdev,
-+ struct pps_device, cdev);
-+
-+ /* Lock the PPS source against (possible) deregistration */
-+ atomic_inc(&pps->usage);
-+
-+ file->private_data = pps;
-+
-+ return 0;
-+}
-+
-+static int pps_cdev_release(struct inode *inode, struct file *file)
-+{
-+ struct pps_device *pps = file->private_data;
-+
-+ /* Free the PPS source and wake up (possible) deregistration */
-+ atomic_dec(&pps->usage);
-+ wake_up_all(&pps->usage_queue);
-+
-+ return 0;
-+}
-+
-+/*
-+ * Char device stuff
-+ */
-+
-+static const struct file_operations pps_cdev_fops = {
-+ .owner = THIS_MODULE,
-+ .llseek = no_llseek,
-+ .poll = pps_cdev_poll,
-+ .fasync = pps_cdev_fasync,
-+ .ioctl = pps_cdev_ioctl,
-+ .open = pps_cdev_open,
-+ .release = pps_cdev_release,
-+};
-+
-+int pps_register_cdev(struct pps_device *pps)
-+{
-+ int err;
-+
-+ pps->devno = MKDEV(MAJOR(pps_devt), pps->id);
-+ cdev_init(&pps->cdev, &pps_cdev_fops);
-+ pps->cdev.owner = pps->info.owner;
-+
-+ err = cdev_add(&pps->cdev, pps->devno, 1);
-+ if (err) {
-+ printk(KERN_ERR "pps: %s: failed to add char device %d:%d\n",
-+ pps->info.name, MAJOR(pps_devt), pps->id);
-+ return err;
-+ }
-+ pps->dev = device_create(pps_class, pps->info.dev, pps->devno,
-+ "pps%d", pps->id);
-+ if (err)
-+ goto del_cdev;
-+ dev_set_drvdata(pps->dev, pps);
-+
-+ pr_debug("source %s got cdev (%d:%d)\n", pps->info.name,
-+ MAJOR(pps_devt), pps->id);
-+
-+ return 0;
-+
-+del_cdev:
-+ cdev_del(&pps->cdev);
-+
-+ return err;
-+}
-+
-+void pps_unregister_cdev(struct pps_device *pps)
-+{
-+ device_destroy(pps_class, pps->devno);
-+ cdev_del(&pps->cdev);
-+}
-+
-+/*
-+ * Module staff
-+ */
-+
-+static void __exit pps_exit(void)
-+{
-+ class_destroy(pps_class);
-+
-+ if (pps_devt)
-+ unregister_chrdev_region(pps_devt, PPS_MAX_SOURCES);
-+
-+ pr_info("LinuxPPS API ver. %d removed\n", PPS_API_VERS);
-+}
-+
-+static int __init pps_init(void)
-+{
-+ int err;
-+
-+ pps_class = class_create(THIS_MODULE, "pps");
-+ if (!pps_class) {
-+ printk(KERN_ERR "pps: ailed to allocate class\n");
-+ return -ENOMEM;
-+ }
-+
-+ err = alloc_chrdev_region(&pps_devt, 0, PPS_MAX_SOURCES, "pps");
-+ if (err < 0) {
-+ printk(KERN_ERR "pps: failed to allocate char device region\n");
-+ goto remove_class;
-+ }
-+
-+ pr_info("LinuxPPS API ver. %d registered\n", PPS_API_VERS);
-+ pr_info("Software ver. %s - Copyright 2005-2007 Rodolfo Giometti "
-+ "<giometti@linux.it>\n", PPS_VERSION);
-+
-+ return 0;
-+
-+remove_class:
-+ class_destroy(pps_class);
-+
-+ return err;
-+}
-+
-+subsys_initcall(pps_init);
-+module_exit(pps_exit);
-+
-+MODULE_AUTHOR("Rodolfo Giometti <giometti@linux.it>");
-+MODULE_DESCRIPTION("LinuxPPS support (RFC 2783) - ver. " PPS_VERSION);
-+MODULE_LICENSE("GPL");
---- /dev/null
-+++ b/drivers/pps/sysfs.c
-@@ -0,0 +1,124 @@
-+/*
-+ * sysfs.c -- sysfs support
-+ *
-+ *
-+ * Copyright (C) 2007 Rodolfo Giometti <giometti@linux.it>
-+ *
-+ * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
-+ */
-+
-+
-+#include <linux/device.h>
-+#include <linux/module.h>
-+#include <linux/string.h>
-+#include <linux/pps.h>
-+
-+/*
-+ * Attribute functions
-+ */
-+
-+static ssize_t pps_show_assert(struct device *dev,
-+ struct device_attribute *attr, char *buf)
-+{
-+ struct pps_device *pps = dev_get_drvdata(dev);
-+
-+ return sprintf(buf, "%lld.%09d#%d\n",
-+ pps->assert_tu.sec, pps->assert_tu.nsec,
-+ pps->assert_sequence);
-+}
-+DEVICE_ATTR(assert, S_IRUGO, pps_show_assert, NULL);
-+
-+static ssize_t pps_show_clear(struct device *dev,
-+ struct device_attribute *attr, char *buf)
-+{
-+ struct pps_device *pps = dev_get_drvdata(dev);
-+
-+ return sprintf(buf, "%lld.%09d#%d\n",
-+ pps->clear_tu.sec, pps->clear_tu.nsec,
-+ pps->clear_sequence);
-+}
-+DEVICE_ATTR(clear, S_IRUGO, pps_show_clear, NULL);
-+
-+static ssize_t pps_show_mode(struct device *dev,
-+ struct device_attribute *attr, char *buf)
-+{
-+ struct pps_device *pps = dev_get_drvdata(dev);
-+
-+ return sprintf(buf, "%4x\n", pps->info.mode);
-+}
-+DEVICE_ATTR(mode, S_IRUGO, pps_show_mode, NULL);
-+
-+static ssize_t pps_show_echo(struct device *dev,
-+ struct device_attribute *attr, char *buf)
-+{
-+ struct pps_device *pps = dev_get_drvdata(dev);
-+
-+ return sprintf(buf, "%d\n", !!pps->info.echo);
-+}
-+DEVICE_ATTR(echo, S_IRUGO, pps_show_echo, NULL);
-+
-+static ssize_t pps_show_name(struct device *dev,
-+ struct device_attribute *attr, char *buf)
-+{
-+ struct pps_device *pps = dev_get_drvdata(dev);
-+
-+ return sprintf(buf, "%s\n", pps->info.name);
-+}
-+DEVICE_ATTR(name, S_IRUGO, pps_show_name, NULL);
-+
-+static ssize_t pps_show_path(struct device *dev,
-+ struct device_attribute *attr, char *buf)
-+{
-+ struct pps_device *pps = dev_get_drvdata(dev);
-+
-+ return sprintf(buf, "%s\n", pps->info.path);
-+}
-+DEVICE_ATTR(path, S_IRUGO, pps_show_path, NULL);
-+
-+/*
-+ * Public functions
-+ */
-+
-+void pps_sysfs_remove_source_entry(struct pps_device *pps)
-+{
-+ /* Delete info files */
-+ if (pps->info.mode & PPS_CAPTUREASSERT)
-+ device_remove_file(pps->dev, &dev_attr_assert);
-+
-+ if (pps->info.mode & PPS_CAPTURECLEAR)
-+ device_remove_file(pps->dev, &dev_attr_clear);
-+
-+ device_remove_file(pps->dev, &dev_attr_mode);
-+ device_remove_file(pps->dev, &dev_attr_echo);
-+ device_remove_file(pps->dev, &dev_attr_name);
-+ device_remove_file(pps->dev, &dev_attr_path);
-+}
-+
-+int pps_sysfs_create_source_entry(struct pps_device *pps)
-+{
-+ /* Create file "assert" and "clear" according to source capability */
-+ if (pps->info.mode & PPS_CAPTUREASSERT)
-+ device_create_file(pps->dev, &dev_attr_assert);
-+
-+ if (pps->info.mode & PPS_CAPTURECLEAR)
-+ device_create_file(pps->dev, &dev_attr_clear);
-+
-+ device_create_file(pps->dev, &dev_attr_mode);
-+ device_create_file(pps->dev, &dev_attr_echo);
-+ device_create_file(pps->dev, &dev_attr_name);
-+ device_create_file(pps->dev, &dev_attr_path);
-+
-+ return 0;
-+}
---- a/drivers/serial/8250.c
-+++ b/drivers/serial/8250.c
-@@ -2118,6 +2118,8 @@
- up->ier |= UART_IER_MSI;
- if (up->capabilities & UART_CAP_UUE)
- up->ier |= UART_IER_UUE | UART_IER_RTOIE;
-+ if (up->port.flags & UPF_HARDPPS_CD)
-+ up->ier |= UART_IER_MSI; /* enable interrupts */
-
- serial_out(up, UART_IER, up->ier);
-
---- a/drivers/serial/serial_core.c
-+++ b/drivers/serial/serial_core.c
-@@ -33,6 +33,7 @@
- #include <linux/serial.h> /* for serial_state and serial_icounter_struct */
- #include <linux/delay.h>
- #include <linux/mutex.h>
-+#include <linux/pps.h>
-
- #include <asm/irq.h>
- #include <asm/uaccess.h>
-@@ -633,6 +634,54 @@
- return 0;
- }
-
-+#ifdef CONFIG_PPS_CLIENT_UART
-+
-+static int
-+uart_register_pps_port(struct uart_state *state, struct uart_port *port)
-+{
-+ struct tty_driver *drv = port->info->tty->driver;
-+ int ret;
-+
-+ state->pps_info.owner = THIS_MODULE;
-+ state->pps_info.dev = port->dev;
-+ snprintf(state->pps_info.name, PPS_MAX_NAME_LEN, "%s%d",
-+ drv->driver_name, port->line);
-+ snprintf(state->pps_info.path, PPS_MAX_NAME_LEN, "/dev/%s%d",
-+ drv->name, port->line);
-+
-+ state->pps_info.mode = PPS_CAPTUREBOTH | \
-+ PPS_OFFSETASSERT | PPS_OFFSETCLEAR | \
-+ PPS_CANWAIT | PPS_TSFMT_TSPEC;
-+
-+ ret = pps_register_source(&state->pps_info, PPS_CAPTUREBOTH | \
-+ PPS_OFFSETASSERT | PPS_OFFSETCLEAR);
-+ if (ret < 0) {
-+ dev_err(port->dev, "cannot register PPS source \"%s\"\n",
-+ state->pps_info.path);
-+ return ret;
-+ }
-+ port->pps_source = ret;
-+ dev_dbg(port->dev, "PPS source #%d \"%s\" added\n",
-+ port->pps_source, state->pps_info.path);
-+
-+ return 0;
-+}
-+
-+static void
-+uart_unregister_pps_port(struct uart_state *state, struct uart_port *port)
-+{
-+ pps_unregister_source(port->pps_source);
-+ dev_dbg(port->dev, "PPS source #%d \"%s\" removed\n",
-+ port->pps_source, state->pps_info.path);
-+}
-+
-+#else
-+
-+#define uart_register_pps_port(state, port) do { } while (0)
-+#define uart_unregister_pps_port(state, port) do { } while (0)
-+
-+#endif /* CONFIG_PPS_CLIENT_UART */
-+
- static int uart_set_info(struct uart_state *state,
- struct serial_struct __user *newinfo)
- {
-@@ -807,11 +856,19 @@
- (port->flags & UPF_LOW_LATENCY) ? 1 : 0;
-
- check_and_exit:
-+ /* PPS support enabled/disabled? */
-+ if ((old_flags & UPF_HARDPPS_CD) != (new_flags & UPF_HARDPPS_CD)) {
-+ if (new_flags & UPF_HARDPPS_CD)
-+ uart_register_pps_port(state, port);
-+ else
-+ uart_unregister_pps_port(state, port);
-+ }
-+
- retval = 0;
- if (port->type == PORT_UNKNOWN)
- goto exit;
- if (state->info->flags & UIF_INITIALIZED) {
-- if (((old_flags ^ port->flags) & UPF_SPD_MASK) ||
-+ if (((old_flags ^ port->flags) & (UPF_SPD_MASK|UPF_HARDPPS_CD)) ||
- old_custom_divisor != port->custom_divisor) {
- /*
- * If they're setting up a custom divisor or speed,
-@@ -2110,6 +2167,12 @@
- port->ops->config_port(port, flags);
- }
-
-+ /*
-+ * Add the PPS support for the current port.
-+ */
-+ if (port->flags & UPF_HARDPPS_CD)
-+ uart_register_pps_port(state, port);
-+
- if (port->type != PORT_UNKNOWN) {
- unsigned long flags;
-
-@@ -2359,6 +2422,12 @@
- mutex_unlock(&state->mutex);
-
- /*
-+ * Remove PPS support from the current port.
-+ */
-+ if (port->flags & UPF_HARDPPS_CD)
-+ uart_unregister_pps_port(state, port);
-+
-+ /*
- * Remove the devices from the tty layer
- */
- tty_unregister_device(drv->tty_driver, port->line);
---- a/include/linux/Kbuild
-+++ b/include/linux/Kbuild
-@@ -295,6 +295,7 @@
- unifdef-y += poll.h
- unifdef-y += ppp_defs.h
- unifdef-y += ppp-comp.h
-+unifdef-y += pps.h
- unifdef-y += ptrace.h
- unifdef-y += qnx4_fs.h
- unifdef-y += quota.h
---- a/include/linux/parport.h
-+++ b/include/linux/parport.h
-@@ -100,6 +100,7 @@
- #include <linux/proc_fs.h>
- #include <linux/spinlock.h>
- #include <linux/wait.h>
-+#include <linux/pps.h>
- #include <asm/system.h>
- #include <asm/ptrace.h>
- #include <asm/semaphore.h>
-@@ -327,6 +328,11 @@
-
- struct list_head full_list;
- struct parport *slaves[3];
-+
-+#ifdef CONFIG_PPS_CLIENT_LP
-+ struct pps_source_info pps_info;
-+ int pps_source; /* PPS source ID */
-+#endif
- };
-
- #define DEFAULT_SPIN_TIME 500 /* us */
-@@ -517,6 +523,12 @@
- /* Lowlevel drivers _can_ call this support function to handle irqs. */
- static __inline__ void parport_generic_irq(int irq, struct parport *port)
- {
-+#ifdef CONFIG_PPS_CLIENT_LP
-+ pps_event(port->pps_source, PPS_CAPTUREASSERT, port);
-+ dev_dbg(port->dev, "PPS assert at %lu on source #%d\n",
-+ jiffies, port->pps_source);
-+#endif
-+
- parport_ieee1284_interrupt (irq, port);
- read_lock(&port->cad_lock);
- if (port->cad && port->cad->irq_func)
---- /dev/null
-+++ b/include/linux/pps.h
-@@ -0,0 +1,196 @@
-+/*
-+ * pps.h -- PPS API kernel header.
-+ *
-+ *
-+ * Copyright (C) 2005-2007 Rodolfo Giometti <giometti@linux.it>
-+ *
-+ * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
-+ */
-+
-+
-+#ifndef _PPS_H_
-+#define _PPS_H_
-+
-+/* Implementation note: the logical states ``assert'' and ``clear''
-+ * are implemented in terms of the chip register, i.e. ``assert''
-+ * means the bit is set. */
-+
-+/*
-+ * 3.2 New data structures
-+ */
-+
-+#ifndef __KERNEL__
-+#include <linux/types.h>
-+#include <sys/time.h>
-+#include <sys/ioctl.h>
-+#else
-+#include <linux/time.h>
-+#endif
-+
-+#define PPS_API_VERS 1
-+#define PPS_MAX_NAME_LEN 32
-+
-+/* 32-bit vs. 64-bit compatibility.
-+ *
-+ * 0n i386, the alignment of a uint64_t is only 4 bytes, while on most other
-+ * architectures it's 8 bytes. On i386, there will be no padding between the
-+ * two consecutive 'struct pps_ktime' members of struct pps_kinfo and struct
-+ * pps_kparams. But on most platforms there will be padding to ensure correct
-+ * alignment.
-+ *
-+ * The simple fix is probably to add an explicit padding.
-+ * [David Woodhouse]
-+ */
-+struct pps_ktime {
-+ __u64 sec;
-+ __u32 nsec;
-+ __u32 flags;
-+};
-+#define PPS_TIME_INVALID (1<<0) /* used to specify timeout==NULL */
-+
-+struct pps_kinfo {
-+ __u32 assert_sequence; /* seq. num. of assert event */
-+ __u32 clear_sequence; /* seq. num. of clear event */
-+ struct pps_ktime assert_tu; /* time of assert event */
-+ struct pps_ktime clear_tu; /* time of clear event */
-+ int current_mode; /* current mode bits */
-+};
-+
-+struct pps_kparams {
-+ int api_version; /* API version # */
-+ int mode; /* mode bits */
-+ struct pps_ktime assert_off_tu; /* offset compensation for assert */
-+ struct pps_ktime clear_off_tu; /* offset compensation for clear */
-+};
-+
-+/*
-+ * 3.3 Mode bit definitions
-+ */
-+
-+/* Device/implementation parameters */
-+#define PPS_CAPTUREASSERT 0x01 /* capture assert events */
-+#define PPS_CAPTURECLEAR 0x02 /* capture clear events */
-+#define PPS_CAPTUREBOTH 0x03 /* capture assert and clear events */
-+
-+#define PPS_OFFSETASSERT 0x10 /* apply compensation for assert ev. */
-+#define PPS_OFFSETCLEAR 0x20 /* apply compensation for clear ev. */
-+
-+#define PPS_CANWAIT 0x100 /* can we wait for an event? */
-+#define PPS_CANPOLL 0x200 /* bit reserved for future use */
-+
-+/* Kernel actions */
-+#define PPS_ECHOASSERT 0x40 /* feed back assert event to output */
-+#define PPS_ECHOCLEAR 0x80 /* feed back clear event to output */
-+
-+/* Timestamp formats */
-+#define PPS_TSFMT_TSPEC 0x1000 /* select timespec format */
-+#define PPS_TSFMT_NTPFP 0x2000 /* select NTP format */
-+
-+/*
-+ * 3.4.4 New functions: disciplining the kernel timebase
-+ */
-+
-+/* Kernel consumers */
-+#define PPS_KC_HARDPPS 0 /* hardpps() (or equivalent) */
-+#define PPS_KC_HARDPPS_PLL 1 /* hardpps() constrained to
-+ use a phase-locked loop */
-+#define PPS_KC_HARDPPS_FLL 2 /* hardpps() constrained to
-+ use a frequency-locked loop */
-+/*
-+ * Here begins the implementation-specific part!
-+ */
-+
-+struct pps_fdata {
-+ struct pps_kinfo info;
-+ struct pps_ktime timeout;
-+};
-+
-+#include <linux/ioctl.h>
-+
-+#define PPS_CHECK _IO('P', 0)
-+#define PPS_GETPARAMS _IOR('P', 1, struct pps_kparams *)
-+#define PPS_SETPARAMS _IOW('P', 2, struct pps_kparams *)
-+#define PPS_GETCAP _IOR('P', 3, int *)
-+#define PPS_FETCH _IOWR('P', 4, struct pps_fdata *)
-+
-+#ifdef __KERNEL__
-+
-+#include <linux/cdev.h>
-+#include <linux/device.h>
-+
-+#define PPS_VERSION "5.0.0-rc2"
-+#define PPS_MAX_SOURCES 16 /* should be enought... */
-+
-+/*
-+ * Global defines
-+ */
-+
-+/* The specific PPS source info */
-+struct pps_source_info {
-+ char name[PPS_MAX_NAME_LEN]; /* simbolic name */
-+ char path[PPS_MAX_NAME_LEN]; /* path of connected device */
-+ int mode; /* PPS's allowed mode */
-+
-+ void (*echo)(int source, int event, void *data); /* PPS echo function */
-+
-+ struct module *owner;
-+ struct device *dev;
-+};
-+
-+/* The main struct */
-+struct pps_device {
-+ struct pps_source_info info; /* PSS source info */
-+
-+ struct pps_kparams params; /* PPS's current params */
-+
-+ __u32 assert_sequence; /* PPS' assert event seq # */
-+ __u32 clear_sequence; /* PPS' clear event seq # */
-+ struct pps_ktime assert_tu;
-+ struct pps_ktime clear_tu;
-+ int current_mode; /* PPS mode at event time */
-+
-+ int go; /* PPS event is arrived? */
-+ wait_queue_head_t queue; /* PPS event queue */
-+
-+ unsigned int id; /* PPS source unique ID */
-+ struct cdev cdev;
-+ struct device *dev;
-+ int devno;
-+ struct fasync_struct *async_queue; /* fasync method */
-+ spinlock_t lock;
-+
-+ atomic_t usage; /* usage count */
-+ wait_queue_head_t usage_queue;
-+
-+ struct class_device class_dev;
-+};
-+
-+/*
-+ * Exported functions
-+ */
-+
-+extern int pps_register_source(struct pps_source_info *info,
-+ int default_params);
-+extern void pps_unregister_source(int source);
-+extern int pps_register_cdev(struct pps_device *pps);
-+extern void pps_unregister_cdev(struct pps_device *pps);
-+extern void pps_event(int source, int event, void *data);
-+
-+extern int pps_sysfs_create_source_entry(struct pps_device *pps);
-+extern void pps_sysfs_remove_source_entry(struct pps_device *pps);
-+
-+#endif /* __KERNEL__ */
-+
-+#endif /* _PPS_H_ */
---- a/include/linux/serial_core.h
-+++ b/include/linux/serial_core.h
-@@ -157,6 +157,7 @@
- #include <linux/tty.h>
- #include <linux/mutex.h>
- #include <linux/sysrq.h>
-+#include <linux/pps.h>
-
- struct uart_port;
- struct uart_info;
-@@ -236,6 +237,9 @@
- unsigned char regshift; /* reg offset shift */
- unsigned char iotype; /* io access style */
- unsigned char unused1;
-+#ifdef CONFIG_PPS_CLIENT_UART
-+ int pps_source; /* PPS source ID */
-+#endif
-
- #define UPIO_PORT (0)
- #define UPIO_HUB6 (1)
-@@ -280,7 +284,8 @@
- #define UPF_IOREMAP ((__force upf_t) (1 << 31))
-
- #define UPF_CHANGE_MASK ((__force upf_t) (0x17fff))
--#define UPF_USR_MASK ((__force upf_t) (UPF_SPD_MASK|UPF_LOW_LATENCY))
-+#define UPF_USR_MASK ((__force upf_t) (UPF_SPD_MASK|UPF_LOW_LATENCY\
-+ |UPF_HARDPPS_CD))
-
- unsigned int mctrl; /* current modem ctrl settings */
- unsigned int timeout; /* character-based timeout */
-@@ -312,6 +317,10 @@
- struct uart_info *info;
- struct uart_port *port;
-
-+#ifdef CONFIG_PPS_CLIENT_UART
-+ struct pps_source_info pps_info;
-+#endif
-+
- struct mutex mutex;
- };
-
-@@ -476,13 +485,22 @@
- {
- struct uart_info *info = port->info;
-
-- port->icount.dcd++;
--
--#ifdef CONFIG_HARD_PPS
-- if ((port->flags & UPF_HARDPPS_CD) && status)
-- hardpps();
-+#ifdef CONFIG_PPS_CLIENT_UART
-+ if (port->flags & UPF_HARDPPS_CD) {
-+ if (status) {
-+ pps_event(port->pps_source, PPS_CAPTUREASSERT, port);
-+ dev_dbg(port->dev, "PPS assert at %lu on source #%d\n",
-+ jiffies, port->pps_source);
-+ } else {
-+ pps_event(port->pps_source, PPS_CAPTURECLEAR, port);
-+ dev_dbg(port->dev, "PPS clear at %lu on source #%d\n",
-+ jiffies, port->pps_source);
-+ }
-+ }
- #endif
-
-+ port->icount.dcd++;
-+
- if (info->flags & UIF_CHECK_CD) {
- if (status)
- wake_up_interruptible(&info->open_wait);
+++ /dev/null
-This is a port of the MMC-SPI driver from 2.6.24.3
---mb
-
-
---- a/drivers/mmc/host/Kconfig
-+++ b/drivers/mmc/host/Kconfig
-@@ -100,3 +100,16 @@
- To compile this driver as a module, choose M here: the
- module will be called tifm_sd.
-
-+config MMC_SPI
-+ tristate "MMC/SD over SPI (EXPERIMENTAL)"
-+ depends on MMC && SPI_MASTER && !HIGHMEM && EXPERIMENTAL
-+ select CRC7
-+ select CRC_ITU_T
-+ help
-+ Some systems accss MMC/SD cards using a SPI controller instead of
-+ using a "native" MMC/SD controller. This has a disadvantage of
-+ being relatively high overhead, but a compensating advantage of
-+ working on many systems without dedicated MMC/SD controllers.
-+
-+ If unsure, or if your system has no SPI master driver, say N.
-+
---- a/drivers/mmc/host/Makefile
-+++ b/drivers/mmc/host/Makefile
-@@ -15,4 +15,5 @@
- obj-$(CONFIG_MMC_OMAP) += omap.o
- obj-$(CONFIG_MMC_AT91) += at91_mci.o
- obj-$(CONFIG_MMC_TIFM_SD) += tifm_sd.o
-+obj-$(CONFIG_MMC_SPI) += mmc_spi.o
-
---- /dev/null
-+++ b/drivers/mmc/host/mmc_spi.c
-@@ -0,0 +1,1419 @@
-+/*
-+ * mmc_spi.c - Access SD/MMC cards through SPI master controllers
-+ *
-+ * (C) Copyright 2005, Intec Automation,
-+ * Mike Lavender (mike@steroidmicros)
-+ * (C) Copyright 2006-2007, David Brownell
-+ * (C) Copyright 2007, Axis Communications,
-+ * Hans-Peter Nilsson (hp@axis.com)
-+ * (C) Copyright 2007, ATRON electronic GmbH,
-+ * Jan Nikitenko <jan.nikitenko@gmail.com>
-+ *
-+ *
-+ * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
-+ */
-+#include <linux/hrtimer.h>
-+#include <linux/delay.h>
-+#include <linux/bio.h>
-+#include <linux/dma-mapping.h>
-+#include <linux/crc7.h>
-+#include <linux/crc-itu-t.h>
-+#include <linux/scatterlist.h>
-+
-+#include <linux/mmc/host.h>
-+#include <linux/mmc/mmc.h> /* for R1_SPI_* bit values */
-+
-+#include <linux/spi/spi.h>
-+#include <linux/spi/mmc_spi.h>
-+
-+#include <asm/unaligned.h>
-+
-+
-+#define sg_page(sg) (sg)->page
-+
-+
-+/* NOTES:
-+ *
-+ * - For now, we won't try to interoperate with a real mmc/sd/sdio
-+ * controller, although some of them do have hardware support for
-+ * SPI protocol. The main reason for such configs would be mmc-ish
-+ * cards like DataFlash, which don't support that "native" protocol.
-+ *
-+ * We don't have a "DataFlash/MMC/SD/SDIO card slot" abstraction to
-+ * switch between driver stacks, and in any case if "native" mode
-+ * is available, it will be faster and hence preferable.
-+ *
-+ * - MMC depends on a different chipselect management policy than the
-+ * SPI interface currently supports for shared bus segments: it needs
-+ * to issue multiple spi_message requests with the chipselect active,
-+ * using the results of one message to decide the next one to issue.
-+ *
-+ * Pending updates to the programming interface, this driver expects
-+ * that it not share the bus with other drivers (precluding conflicts).
-+ *
-+ * - We tell the controller to keep the chipselect active from the
-+ * beginning of an mmc_host_ops.request until the end. So beware
-+ * of SPI controller drivers that mis-handle the cs_change flag!
-+ *
-+ * However, many cards seem OK with chipselect flapping up/down
-+ * during that time ... at least on unshared bus segments.
-+ */
-+
-+
-+/*
-+ * Local protocol constants, internal to data block protocols.
-+ */
-+
-+/* Response tokens used to ack each block written: */
-+#define SPI_MMC_RESPONSE_CODE(x) ((x) & 0x1f)
-+#define SPI_RESPONSE_ACCEPTED ((2 << 1)|1)
-+#define SPI_RESPONSE_CRC_ERR ((5 << 1)|1)
-+#define SPI_RESPONSE_WRITE_ERR ((6 << 1)|1)
-+
-+/* Read and write blocks start with these tokens and end with crc;
-+ * on error, read tokens act like a subset of R2_SPI_* values.
-+ */
-+#define SPI_TOKEN_SINGLE 0xfe /* single block r/w, multiblock read */
-+#define SPI_TOKEN_MULTI_WRITE 0xfc /* multiblock write */
-+#define SPI_TOKEN_STOP_TRAN 0xfd /* terminate multiblock write */
-+
-+#define MMC_SPI_BLOCKSIZE 512
-+
-+
-+/* These fixed timeouts come from the latest SD specs, which say to ignore
-+ * the CSD values. The R1B value is for card erase (e.g. the "I forgot the
-+ * card's password" scenario); it's mostly applied to STOP_TRANSMISSION after
-+ * reads which takes nowhere near that long. Older cards may be able to use
-+ * shorter timeouts ... but why bother?
-+ */
-+#define readblock_timeout ktime_set(0, 100 * 1000 * 1000)
-+#define writeblock_timeout ktime_set(0, 250 * 1000 * 1000)
-+#define r1b_timeout ktime_set(3, 0)
-+
-+
-+/****************************************************************************/
-+
-+/*
-+ * Local Data Structures
-+ */
-+
-+/* "scratch" is per-{command,block} data exchanged with the card */
-+struct scratch {
-+ u8 status[29];
-+ u8 data_token;
-+ __be16 crc_val;
-+};
-+
-+struct mmc_spi_host {
-+ struct mmc_host *mmc;
-+ struct spi_device *spi;
-+
-+ unsigned char power_mode;
-+ u16 powerup_msecs;
-+
-+ struct mmc_spi_platform_data *pdata;
-+
-+ /* for bulk data transfers */
-+ struct spi_transfer token, t, crc, early_status;
-+ struct spi_message m;
-+
-+ /* for status readback */
-+ struct spi_transfer status;
-+ struct spi_message readback;
-+
-+ /* underlying DMA-aware controller, or null */
-+ struct device *dma_dev;
-+
-+ /* buffer used for commands and for message "overhead" */
-+ struct scratch *data;
-+ dma_addr_t data_dma;
-+
-+ /* Specs say to write ones most of the time, even when the card
-+ * has no need to read its input data; and many cards won't care.
-+ * This is our source of those ones.
-+ */
-+ void *ones;
-+ dma_addr_t ones_dma;
-+};
-+
-+
-+/****************************************************************************/
-+
-+/*
-+ * MMC-over-SPI protocol glue, used by the MMC stack interface
-+ */
-+
-+static inline int mmc_cs_off(struct mmc_spi_host *host)
-+{
-+ /* chipselect will always be inactive after setup() */
-+ return spi_setup(host->spi);
-+}
-+
-+static int
-+mmc_spi_readbytes(struct mmc_spi_host *host, unsigned len)
-+{
-+ int status;
-+
-+ if (len > sizeof(*host->data)) {
-+ WARN_ON(1);
-+ return -EIO;
-+ }
-+
-+ host->status.len = len;
-+
-+ if (host->dma_dev)
-+ dma_sync_single_for_device(host->dma_dev,
-+ host->data_dma, sizeof(*host->data),
-+ DMA_FROM_DEVICE);
-+
-+ status = spi_sync(host->spi, &host->readback);
-+
-+ if (host->dma_dev)
-+ dma_sync_single_for_cpu(host->dma_dev,
-+ host->data_dma, sizeof(*host->data),
-+ DMA_FROM_DEVICE);
-+
-+ return status;
-+}
-+
-+static int
-+mmc_spi_skip(struct mmc_spi_host *host, ktime_t timeout, unsigned n, u8 byte)
-+{
-+ u8 *cp = host->data->status;
-+
-+ timeout = ktime_add(timeout, ktime_get());
-+
-+ while (1) {
-+ int status;
-+ unsigned i;
-+
-+ status = mmc_spi_readbytes(host, n);
-+ if (status < 0)
-+ return status;
-+
-+ for (i = 0; i < n; i++) {
-+ if (cp[i] != byte)
-+ return cp[i];
-+ }
-+
-+ /* REVISIT investigate msleep() to avoid busy-wait I/O
-+ * in at least some cases.
-+ */
-+ if (ktime_to_ns(ktime_sub(ktime_get(), timeout)) > 0)
-+ break;
-+ }
-+ return -ETIMEDOUT;
-+}
-+
-+static inline int
-+mmc_spi_wait_unbusy(struct mmc_spi_host *host, ktime_t timeout)
-+{
-+ return mmc_spi_skip(host, timeout, sizeof(host->data->status), 0);
-+}
-+
-+static int mmc_spi_readtoken(struct mmc_spi_host *host)
-+{
-+ return mmc_spi_skip(host, readblock_timeout, 1, 0xff);
-+}
-+
-+
-+/*
-+ * Note that for SPI, cmd->resp[0] is not the same data as "native" protocol
-+ * hosts return! The low byte holds R1_SPI bits. The next byte may hold
-+ * R2_SPI bits ... for SEND_STATUS, or after data read errors.
-+ *
-+ * cmd->resp[1] holds any four-byte response, for R3 (READ_OCR) and on
-+ * newer cards R7 (IF_COND).
-+ */
-+
-+static char *maptype(struct mmc_command *cmd)
-+{
-+ switch (mmc_spi_resp_type(cmd)) {
-+ case MMC_RSP_SPI_R1: return "R1";
-+ case MMC_RSP_SPI_R1B: return "R1B";
-+ case MMC_RSP_SPI_R2: return "R2/R5";
-+ case MMC_RSP_SPI_R3: return "R3/R4/R7";
-+ default: return "?";
-+ }
-+}
-+
-+/* return zero, else negative errno after setting cmd->error */
-+static int mmc_spi_response_get(struct mmc_spi_host *host,
-+ struct mmc_command *cmd, int cs_on)
-+{
-+ u8 *cp = host->data->status;
-+ u8 *end = cp + host->t.len;
-+ int value = 0;
-+ char tag[32];
-+
-+ snprintf(tag, sizeof(tag), " ... CMD%d response SPI_%s",
-+ cmd->opcode, maptype(cmd));
-+
-+ /* Except for data block reads, the whole response will already
-+ * be stored in the scratch buffer. It's somewhere after the
-+ * command and the first byte we read after it. We ignore that
-+ * first byte. After STOP_TRANSMISSION command it may include
-+ * two data bits, but otherwise it's all ones.
-+ */
-+ cp += 8;
-+ while (cp < end && *cp == 0xff)
-+ cp++;
-+
-+ /* Data block reads (R1 response types) may need more data... */
-+ if (cp == end) {
-+ unsigned i;
-+
-+ cp = host->data->status;
-+
-+ /* Card sends N(CR) (== 1..8) bytes of all-ones then one
-+ * status byte ... and we already scanned 2 bytes.
-+ *
-+ * REVISIT block read paths use nasty byte-at-a-time I/O
-+ * so it can always DMA directly into the target buffer.
-+ * It'd probably be better to memcpy() the first chunk and
-+ * avoid extra i/o calls...
-+ */
-+ for (i = 2; i < 9; i++) {
-+ value = mmc_spi_readbytes(host, 1);
-+ if (value < 0)
-+ goto done;
-+ if (*cp != 0xff)
-+ goto checkstatus;
-+ }
-+ value = -ETIMEDOUT;
-+ goto done;
-+ }
-+
-+checkstatus:
-+ if (*cp & 0x80) {
-+ dev_dbg(&host->spi->dev, "%s: INVALID RESPONSE, %02x\n",
-+ tag, *cp);
-+ value = -EBADR;
-+ goto done;
-+ }
-+
-+ cmd->resp[0] = *cp++;
-+ cmd->error = 0;
-+
-+ /* Status byte: the entire seven-bit R1 response. */
-+ if (cmd->resp[0] != 0) {
-+ if ((R1_SPI_PARAMETER | R1_SPI_ADDRESS
-+ | R1_SPI_ILLEGAL_COMMAND)
-+ & cmd->resp[0])
-+ value = -EINVAL;
-+ else if (R1_SPI_COM_CRC & cmd->resp[0])
-+ value = -EILSEQ;
-+ else if ((R1_SPI_ERASE_SEQ | R1_SPI_ERASE_RESET)
-+ & cmd->resp[0])
-+ value = -EIO;
-+ /* else R1_SPI_IDLE, "it's resetting" */
-+ }
-+
-+ switch (mmc_spi_resp_type(cmd)) {
-+
-+ /* SPI R1B == R1 + busy; STOP_TRANSMISSION (for multiblock reads)
-+ * and less-common stuff like various erase operations.
-+ */
-+ case MMC_RSP_SPI_R1B:
-+ /* maybe we read all the busy tokens already */
-+ while (cp < end && *cp == 0)
-+ cp++;
-+ if (cp == end)
-+ mmc_spi_wait_unbusy(host, r1b_timeout);
-+ break;
-+
-+ /* SPI R2 == R1 + second status byte; SEND_STATUS
-+ * SPI R5 == R1 + data byte; IO_RW_DIRECT
-+ */
-+ case MMC_RSP_SPI_R2:
-+ cmd->resp[0] |= *cp << 8;
-+ break;
-+
-+ /* SPI R3, R4, or R7 == R1 + 4 bytes */
-+ case MMC_RSP_SPI_R3:
-+ cmd->resp[1] = be32_to_cpu(get_unaligned((u32 *)cp));
-+ break;
-+
-+ /* SPI R1 == just one status byte */
-+ case MMC_RSP_SPI_R1:
-+ break;
-+
-+ default:
-+ dev_dbg(&host->spi->dev, "bad response type %04x\n",
-+ mmc_spi_resp_type(cmd));
-+ if (value >= 0)
-+ value = -EINVAL;
-+ goto done;
-+ }
-+
-+ if (value < 0)
-+ dev_dbg(&host->spi->dev, "%s: resp %04x %08x\n",
-+ tag, cmd->resp[0], cmd->resp[1]);
-+
-+ /* disable chipselect on errors and some success cases */
-+ if (value >= 0 && cs_on)
-+ return value;
-+done:
-+ if (value < 0)
-+ cmd->error = value;
-+ mmc_cs_off(host);
-+ return value;
-+}
-+
-+/* Issue command and read its response.
-+ * Returns zero on success, negative for error.
-+ *
-+ * On error, caller must cope with mmc core retry mechanism. That
-+ * means immediate low-level resubmit, which affects the bus lock...
-+ */
-+static int
-+mmc_spi_command_send(struct mmc_spi_host *host,
-+ struct mmc_request *mrq,
-+ struct mmc_command *cmd, int cs_on)
-+{
-+ struct scratch *data = host->data;
-+ u8 *cp = data->status;
-+ u32 arg = cmd->arg;
-+ int status;
-+ struct spi_transfer *t;
-+
-+ /* We can handle most commands (except block reads) in one full
-+ * duplex I/O operation before either starting the next transfer
-+ * (data block or command) or else deselecting the card.
-+ *
-+ * First, write 7 bytes:
-+ * - an all-ones byte to ensure the card is ready
-+ * - opcode byte (plus start and transmission bits)
-+ * - four bytes of big-endian argument
-+ * - crc7 (plus end bit) ... always computed, it's cheap
-+ *
-+ * We init the whole buffer to all-ones, which is what we need
-+ * to write while we're reading (later) response data.
-+ */
-+ memset(cp++, 0xff, sizeof(data->status));
-+
-+ *cp++ = 0x40 | cmd->opcode;
-+ *cp++ = (u8)(arg >> 24);
-+ *cp++ = (u8)(arg >> 16);
-+ *cp++ = (u8)(arg >> 8);
-+ *cp++ = (u8)arg;
-+ *cp++ = (crc7(0, &data->status[1], 5) << 1) | 0x01;
-+
-+ /* Then, read up to 13 bytes (while writing all-ones):
-+ * - N(CR) (== 1..8) bytes of all-ones
-+ * - status byte (for all response types)
-+ * - the rest of the response, either:
-+ * + nothing, for R1 or R1B responses
-+ * + second status byte, for R2 responses
-+ * + four data bytes, for R3 and R7 responses
-+ *
-+ * Finally, read some more bytes ... in the nice cases we know in
-+ * advance how many, and reading 1 more is always OK:
-+ * - N(EC) (== 0..N) bytes of all-ones, before deselect/finish
-+ * - N(RC) (== 1..N) bytes of all-ones, before next command
-+ * - N(WR) (== 1..N) bytes of all-ones, before data write
-+ *
-+ * So in those cases one full duplex I/O of at most 21 bytes will
-+ * handle the whole command, leaving the card ready to receive a
-+ * data block or new command. We do that whenever we can, shaving
-+ * CPU and IRQ costs (especially when using DMA or FIFOs).
-+ *
-+ * There are two other cases, where it's not generally practical
-+ * to rely on a single I/O:
-+ *
-+ * - R1B responses need at least N(EC) bytes of all-zeroes.
-+ *
-+ * In this case we can *try* to fit it into one I/O, then
-+ * maybe read more data later.
-+ *
-+ * - Data block reads are more troublesome, since a variable
-+ * number of padding bytes precede the token and data.
-+ * + N(CX) (== 0..8) bytes of all-ones, before CSD or CID
-+ * + N(AC) (== 1..many) bytes of all-ones
-+ *
-+ * In this case we currently only have minimal speedups here:
-+ * when N(CR) == 1 we can avoid I/O in response_get().
-+ */
-+ if (cs_on && (mrq->data->flags & MMC_DATA_READ)) {
-+ cp += 2; /* min(N(CR)) + status */
-+ /* R1 */
-+ } else {
-+ cp += 10; /* max(N(CR)) + status + min(N(RC),N(WR)) */
-+ if (cmd->flags & MMC_RSP_SPI_S2) /* R2/R5 */
-+ cp++;
-+ else if (cmd->flags & MMC_RSP_SPI_B4) /* R3/R4/R7 */
-+ cp += 4;
-+ else if (cmd->flags & MMC_RSP_BUSY) /* R1B */
-+ cp = data->status + sizeof(data->status);
-+ /* else: R1 (most commands) */
-+ }
-+
-+ dev_dbg(&host->spi->dev, " mmc_spi: CMD%d, resp %s\n",
-+ cmd->opcode, maptype(cmd));
-+
-+ /* send command, leaving chipselect active */
-+ spi_message_init(&host->m);
-+
-+ t = &host->t;
-+ memset(t, 0, sizeof(*t));
-+ t->tx_buf = t->rx_buf = data->status;
-+ t->tx_dma = t->rx_dma = host->data_dma;
-+ t->len = cp - data->status;
-+ t->cs_change = 1;
-+ spi_message_add_tail(t, &host->m);
-+
-+ if (host->dma_dev) {
-+ host->m.is_dma_mapped = 1;
-+ dma_sync_single_for_device(host->dma_dev,
-+ host->data_dma, sizeof(*host->data),
-+ DMA_BIDIRECTIONAL);
-+ }
-+ status = spi_sync(host->spi, &host->m);
-+
-+ if (host->dma_dev)
-+ dma_sync_single_for_cpu(host->dma_dev,
-+ host->data_dma, sizeof(*host->data),
-+ DMA_BIDIRECTIONAL);
-+ if (status < 0) {
-+ dev_dbg(&host->spi->dev, " ... write returned %d\n", status);
-+ cmd->error = status;
-+ return status;
-+ }
-+
-+ /* after no-data commands and STOP_TRANSMISSION, chipselect off */
-+ return mmc_spi_response_get(host, cmd, cs_on);
-+}
-+
-+/* Build data message with up to four separate transfers. For TX, we
-+ * start by writing the data token. And in most cases, we finish with
-+ * a status transfer.
-+ *
-+ * We always provide TX data for data and CRC. The MMC/SD protocol
-+ * requires us to write ones; but Linux defaults to writing zeroes;
-+ * so we explicitly initialize it to all ones on RX paths.
-+ *
-+ * We also handle DMA mapping, so the underlying SPI controller does
-+ * not need to (re)do it for each message.
-+ */
-+static void
-+mmc_spi_setup_data_message(
-+ struct mmc_spi_host *host,
-+ int multiple,
-+ enum dma_data_direction direction)
-+{
-+ struct spi_transfer *t;
-+ struct scratch *scratch = host->data;
-+ dma_addr_t dma = host->data_dma;
-+
-+ spi_message_init(&host->m);
-+ if (dma)
-+ host->m.is_dma_mapped = 1;
-+
-+ /* for reads, readblock() skips 0xff bytes before finding
-+ * the token; for writes, this transfer issues that token.
-+ */
-+ if (direction == DMA_TO_DEVICE) {
-+ t = &host->token;
-+ memset(t, 0, sizeof(*t));
-+ t->len = 1;
-+ if (multiple)
-+ scratch->data_token = SPI_TOKEN_MULTI_WRITE;
-+ else
-+ scratch->data_token = SPI_TOKEN_SINGLE;
-+ t->tx_buf = &scratch->data_token;
-+ if (dma)
-+ t->tx_dma = dma + offsetof(struct scratch, data_token);
-+ spi_message_add_tail(t, &host->m);
-+ }
-+
-+ /* Body of transfer is buffer, then CRC ...
-+ * either TX-only, or RX with TX-ones.
-+ */
-+ t = &host->t;
-+ memset(t, 0, sizeof(*t));
-+ t->tx_buf = host->ones;
-+ t->tx_dma = host->ones_dma;
-+ /* length and actual buffer info are written later */
-+ spi_message_add_tail(t, &host->m);
-+
-+ t = &host->crc;
-+ memset(t, 0, sizeof(*t));
-+ t->len = 2;
-+ if (direction == DMA_TO_DEVICE) {
-+ /* the actual CRC may get written later */
-+ t->tx_buf = &scratch->crc_val;
-+ if (dma)
-+ t->tx_dma = dma + offsetof(struct scratch, crc_val);
-+ } else {
-+ t->tx_buf = host->ones;
-+ t->tx_dma = host->ones_dma;
-+ t->rx_buf = &scratch->crc_val;
-+ if (dma)
-+ t->rx_dma = dma + offsetof(struct scratch, crc_val);
-+ }
-+ spi_message_add_tail(t, &host->m);
-+
-+ /*
-+ * A single block read is followed by N(EC) [0+] all-ones bytes
-+ * before deselect ... don't bother.
-+ *
-+ * Multiblock reads are followed by N(AC) [1+] all-ones bytes before
-+ * the next block is read, or a STOP_TRANSMISSION is issued. We'll
-+ * collect that single byte, so readblock() doesn't need to.
-+ *
-+ * For a write, the one-byte data response follows immediately, then
-+ * come zero or more busy bytes, then N(WR) [1+] all-ones bytes.
-+ * Then single block reads may deselect, and multiblock ones issue
-+ * the next token (next data block, or STOP_TRAN). We can try to
-+ * minimize I/O ops by using a single read to collect end-of-busy.
-+ */
-+ if (multiple || direction == DMA_TO_DEVICE) {
-+ t = &host->early_status;
-+ memset(t, 0, sizeof(*t));
-+ t->len = (direction == DMA_TO_DEVICE)
-+ ? sizeof(scratch->status)
-+ : 1;
-+ t->tx_buf = host->ones;
-+ t->tx_dma = host->ones_dma;
-+ t->rx_buf = scratch->status;
-+ if (dma)
-+ t->rx_dma = dma + offsetof(struct scratch, status);
-+ t->cs_change = 1;
-+ spi_message_add_tail(t, &host->m);
-+ }
-+}
-+
-+/*
-+ * Write one block:
-+ * - caller handled preceding N(WR) [1+] all-ones bytes
-+ * - data block
-+ * + token
-+ * + data bytes
-+ * + crc16
-+ * - an all-ones byte ... card writes a data-response byte
-+ * - followed by N(EC) [0+] all-ones bytes, card writes zero/'busy'
-+ *
-+ * Return negative errno, else success.
-+ */
-+static int
-+mmc_spi_writeblock(struct mmc_spi_host *host, struct spi_transfer *t)
-+{
-+ struct spi_device *spi = host->spi;
-+ int status, i;
-+ struct scratch *scratch = host->data;
-+
-+ if (host->mmc->use_spi_crc)
-+ scratch->crc_val = cpu_to_be16(
-+ crc_itu_t(0, t->tx_buf, t->len));
-+ if (host->dma_dev)
-+ dma_sync_single_for_device(host->dma_dev,
-+ host->data_dma, sizeof(*scratch),
-+ DMA_BIDIRECTIONAL);
-+
-+ status = spi_sync(spi, &host->m);
-+
-+ if (status != 0) {
-+ dev_dbg(&spi->dev, "write error (%d)\n", status);
-+ return status;
-+ }
-+
-+ if (host->dma_dev)
-+ dma_sync_single_for_cpu(host->dma_dev,
-+ host->data_dma, sizeof(*scratch),
-+ DMA_BIDIRECTIONAL);
-+
-+ /*
-+ * Get the transmission data-response reply. It must follow
-+ * immediately after the data block we transferred. This reply
-+ * doesn't necessarily tell whether the write operation succeeded;
-+ * it just says if the transmission was ok and whether *earlier*
-+ * writes succeeded; see the standard.
-+ */
-+ switch (SPI_MMC_RESPONSE_CODE(scratch->status[0])) {
-+ case SPI_RESPONSE_ACCEPTED:
-+ status = 0;
-+ break;
-+ case SPI_RESPONSE_CRC_ERR:
-+ /* host shall then issue MMC_STOP_TRANSMISSION */
-+ status = -EILSEQ;
-+ break;
-+ case SPI_RESPONSE_WRITE_ERR:
-+ /* host shall then issue MMC_STOP_TRANSMISSION,
-+ * and should MMC_SEND_STATUS to sort it out
-+ */
-+ status = -EIO;
-+ break;
-+ default:
-+ status = -EPROTO;
-+ break;
-+ }
-+ if (status != 0) {
-+ dev_dbg(&spi->dev, "write error %02x (%d)\n",
-+ scratch->status[0], status);
-+ return status;
-+ }
-+
-+ t->tx_buf += t->len;
-+ if (host->dma_dev)
-+ t->tx_dma += t->len;
-+
-+ /* Return when not busy. If we didn't collect that status yet,
-+ * we'll need some more I/O.
-+ */
-+ for (i = 1; i < sizeof(scratch->status); i++) {
-+ if (scratch->status[i] != 0)
-+ return 0;
-+ }
-+ return mmc_spi_wait_unbusy(host, writeblock_timeout);
-+}
-+
-+/*
-+ * Read one block:
-+ * - skip leading all-ones bytes ... either
-+ * + N(AC) [1..f(clock,CSD)] usually, else
-+ * + N(CX) [0..8] when reading CSD or CID
-+ * - data block
-+ * + token ... if error token, no data or crc
-+ * + data bytes
-+ * + crc16
-+ *
-+ * After single block reads, we're done; N(EC) [0+] all-ones bytes follow
-+ * before dropping chipselect.
-+ *
-+ * For multiblock reads, caller either reads the next block or issues a
-+ * STOP_TRANSMISSION command.
-+ */
-+static int
-+mmc_spi_readblock(struct mmc_spi_host *host, struct spi_transfer *t)
-+{
-+ struct spi_device *spi = host->spi;
-+ int status;
-+ struct scratch *scratch = host->data;
-+
-+ /* At least one SD card sends an all-zeroes byte when N(CX)
-+ * applies, before the all-ones bytes ... just cope with that.
-+ */
-+ status = mmc_spi_readbytes(host, 1);
-+ if (status < 0)
-+ return status;
-+ status = scratch->status[0];
-+ if (status == 0xff || status == 0)
-+ status = mmc_spi_readtoken(host);
-+
-+ if (status == SPI_TOKEN_SINGLE) {
-+ if (host->dma_dev) {
-+ dma_sync_single_for_device(host->dma_dev,
-+ host->data_dma, sizeof(*scratch),
-+ DMA_BIDIRECTIONAL);
-+ dma_sync_single_for_device(host->dma_dev,
-+ t->rx_dma, t->len,
-+ DMA_FROM_DEVICE);
-+ }
-+
-+ status = spi_sync(spi, &host->m);
-+
-+ if (host->dma_dev) {
-+ dma_sync_single_for_cpu(host->dma_dev,
-+ host->data_dma, sizeof(*scratch),
-+ DMA_BIDIRECTIONAL);
-+ dma_sync_single_for_cpu(host->dma_dev,
-+ t->rx_dma, t->len,
-+ DMA_FROM_DEVICE);
-+ }
-+
-+ } else {
-+ dev_dbg(&spi->dev, "read error %02x (%d)\n", status, status);
-+
-+ /* we've read extra garbage, timed out, etc */
-+ if (status < 0)
-+ return status;
-+
-+ /* low four bits are an R2 subset, fifth seems to be
-+ * vendor specific ... map them all to generic error..
-+ */
-+ return -EIO;
-+ }
-+
-+ if (host->mmc->use_spi_crc) {
-+ u16 crc = crc_itu_t(0, t->rx_buf, t->len);
-+
-+ be16_to_cpus(&scratch->crc_val);
-+ if (scratch->crc_val != crc) {
-+ dev_dbg(&spi->dev, "read - crc error: crc_val=0x%04x, "
-+ "computed=0x%04x len=%d\n",
-+ scratch->crc_val, crc, t->len);
-+ return -EILSEQ;
-+ }
-+ }
-+
-+ t->rx_buf += t->len;
-+ if (host->dma_dev)
-+ t->rx_dma += t->len;
-+
-+ return 0;
-+}
-+
-+/*
-+ * An MMC/SD data stage includes one or more blocks, optional CRCs,
-+ * and inline handshaking. That handhaking makes it unlike most
-+ * other SPI protocol stacks.
-+ */
-+static void
-+mmc_spi_data_do(struct mmc_spi_host *host, struct mmc_command *cmd,
-+ struct mmc_data *data, u32 blk_size)
-+{
-+ struct spi_device *spi = host->spi;
-+ struct device *dma_dev = host->dma_dev;
-+ struct spi_transfer *t;
-+ enum dma_data_direction direction;
-+ struct scatterlist *sg;
-+ unsigned n_sg;
-+ int multiple = (data->blocks > 1);
-+
-+ if (data->flags & MMC_DATA_READ)
-+ direction = DMA_FROM_DEVICE;
-+ else
-+ direction = DMA_TO_DEVICE;
-+ mmc_spi_setup_data_message(host, multiple, direction);
-+ t = &host->t;
-+
-+ /* Handle scatterlist segments one at a time, with synch for
-+ * each 512-byte block
-+ */
-+ for (sg = data->sg, n_sg = data->sg_len; n_sg; n_sg--, sg++) {
-+ int status = 0;
-+ dma_addr_t dma_addr = 0;
-+ void *kmap_addr;
-+ unsigned length = sg->length;
-+ enum dma_data_direction dir = direction;
-+
-+ /* set up dma mapping for controller drivers that might
-+ * use DMA ... though they may fall back to PIO
-+ */
-+ if (dma_dev) {
-+ /* never invalidate whole *shared* pages ... */
-+ if ((sg->offset != 0 || length != PAGE_SIZE)
-+ && dir == DMA_FROM_DEVICE)
-+ dir = DMA_BIDIRECTIONAL;
-+
-+ dma_addr = dma_map_page(dma_dev, sg_page(sg), 0,
-+ PAGE_SIZE, dir);
-+ if (direction == DMA_TO_DEVICE)
-+ t->tx_dma = dma_addr + sg->offset;
-+ else
-+ t->rx_dma = dma_addr + sg->offset;
-+ }
-+
-+ /* allow pio too; we don't allow highmem */
-+ kmap_addr = kmap(sg_page(sg));
-+ if (direction == DMA_TO_DEVICE)
-+ t->tx_buf = kmap_addr + sg->offset;
-+ else
-+ t->rx_buf = kmap_addr + sg->offset;
-+
-+ /* transfer each block, and update request status */
-+ while (length) {
-+ t->len = min(length, blk_size);
-+
-+ dev_dbg(&host->spi->dev,
-+ " mmc_spi: %s block, %d bytes\n",
-+ (direction == DMA_TO_DEVICE)
-+ ? "write"
-+ : "read",
-+ t->len);
-+
-+ if (direction == DMA_TO_DEVICE)
-+ status = mmc_spi_writeblock(host, t);
-+ else
-+ status = mmc_spi_readblock(host, t);
-+ if (status < 0)
-+ break;
-+
-+ data->bytes_xfered += t->len;
-+ length -= t->len;
-+
-+ if (!multiple)
-+ break;
-+ }
-+
-+ /* discard mappings */
-+ if (direction == DMA_FROM_DEVICE)
-+ flush_kernel_dcache_page(sg_page(sg));
-+ kunmap(sg_page(sg));
-+ if (dma_dev)
-+ dma_unmap_page(dma_dev, dma_addr, PAGE_SIZE, dir);
-+
-+ if (status < 0) {
-+ data->error = status;
-+ dev_dbg(&spi->dev, "%s status %d\n",
-+ (direction == DMA_TO_DEVICE)
-+ ? "write" : "read",
-+ status);
-+ break;
-+ }
-+ }
-+
-+ /* NOTE some docs describe an MMC-only SET_BLOCK_COUNT (CMD23) that
-+ * can be issued before multiblock writes. Unlike its more widely
-+ * documented analogue for SD cards (SET_WR_BLK_ERASE_COUNT, ACMD23),
-+ * that can affect the STOP_TRAN logic. Complete (and current)
-+ * MMC specs should sort that out before Linux starts using CMD23.
-+ */
-+ if (direction == DMA_TO_DEVICE && multiple) {
-+ struct scratch *scratch = host->data;
-+ int tmp;
-+ const unsigned statlen = sizeof(scratch->status);
-+
-+ dev_dbg(&spi->dev, " mmc_spi: STOP_TRAN\n");
-+
-+ /* Tweak the per-block message we set up earlier by morphing
-+ * it to hold single buffer with the token followed by some
-+ * all-ones bytes ... skip N(BR) (0..1), scan the rest for
-+ * "not busy any longer" status, and leave chip selected.
-+ */
-+ INIT_LIST_HEAD(&host->m.transfers);
-+ list_add(&host->early_status.transfer_list,
-+ &host->m.transfers);
-+
-+ memset(scratch->status, 0xff, statlen);
-+ scratch->status[0] = SPI_TOKEN_STOP_TRAN;
-+
-+ host->early_status.tx_buf = host->early_status.rx_buf;
-+ host->early_status.tx_dma = host->early_status.rx_dma;
-+ host->early_status.len = statlen;
-+
-+ if (host->dma_dev)
-+ dma_sync_single_for_device(host->dma_dev,
-+ host->data_dma, sizeof(*scratch),
-+ DMA_BIDIRECTIONAL);
-+
-+ tmp = spi_sync(spi, &host->m);
-+
-+ if (host->dma_dev)
-+ dma_sync_single_for_cpu(host->dma_dev,
-+ host->data_dma, sizeof(*scratch),
-+ DMA_BIDIRECTIONAL);
-+
-+ if (tmp < 0) {
-+ if (!data->error)
-+ data->error = tmp;
-+ return;
-+ }
-+
-+ /* Ideally we collected "not busy" status with one I/O,
-+ * avoiding wasteful byte-at-a-time scanning... but more
-+ * I/O is often needed.
-+ */
-+ for (tmp = 2; tmp < statlen; tmp++) {
-+ if (scratch->status[tmp] != 0)
-+ return;
-+ }
-+ tmp = mmc_spi_wait_unbusy(host, writeblock_timeout);
-+ if (tmp < 0 && !data->error)
-+ data->error = tmp;
-+ }
-+}
-+
-+/****************************************************************************/
-+
-+/*
-+ * MMC driver implementation -- the interface to the MMC stack
-+ */
-+
-+static void mmc_spi_request(struct mmc_host *mmc, struct mmc_request *mrq)
-+{
-+ struct mmc_spi_host *host = mmc_priv(mmc);
-+ int status = -EINVAL;
-+
-+#ifdef DEBUG
-+ /* MMC core and layered drivers *MUST* issue SPI-aware commands */
-+ {
-+ struct mmc_command *cmd;
-+ int invalid = 0;
-+
-+ cmd = mrq->cmd;
-+ if (!mmc_spi_resp_type(cmd)) {
-+ dev_dbg(&host->spi->dev, "bogus command\n");
-+ cmd->error = -EINVAL;
-+ invalid = 1;
-+ }
-+
-+ cmd = mrq->stop;
-+ if (cmd && !mmc_spi_resp_type(cmd)) {
-+ dev_dbg(&host->spi->dev, "bogus STOP command\n");
-+ cmd->error = -EINVAL;
-+ invalid = 1;
-+ }
-+
-+ if (invalid) {
-+ dump_stack();
-+ mmc_request_done(host->mmc, mrq);
-+ return;
-+ }
-+ }
-+#endif
-+
-+ /* issue command; then optionally data and stop */
-+ status = mmc_spi_command_send(host, mrq, mrq->cmd, mrq->data != NULL);
-+ if (status == 0 && mrq->data) {
-+ mmc_spi_data_do(host, mrq->cmd, mrq->data, mrq->data->blksz);
-+ if (mrq->stop)
-+ status = mmc_spi_command_send(host, mrq, mrq->stop, 0);
-+ else
-+ mmc_cs_off(host);
-+ }
-+
-+ mmc_request_done(host->mmc, mrq);
-+}
-+
-+/* See Section 6.4.1, in SD "Simplified Physical Layer Specification 2.0"
-+ *
-+ * NOTE that here we can't know that the card has just been powered up;
-+ * not all MMC/SD sockets support power switching.
-+ *
-+ * FIXME when the card is still in SPI mode, e.g. from a previous kernel,
-+ * this doesn't seem to do the right thing at all...
-+ */
-+static void mmc_spi_initsequence(struct mmc_spi_host *host)
-+{
-+ /* Try to be very sure any previous command has completed;
-+ * wait till not-busy, skip debris from any old commands.
-+ */
-+ mmc_spi_wait_unbusy(host, r1b_timeout);
-+ mmc_spi_readbytes(host, 10);
-+
-+ /*
-+ * Do a burst with chipselect active-high. We need to do this to
-+ * meet the requirement of 74 clock cycles with both chipselect
-+ * and CMD (MOSI) high before CMD0 ... after the card has been
-+ * powered up to Vdd(min), and so is ready to take commands.
-+ *
-+ * Some cards are particularly needy of this (e.g. Viking "SD256")
-+ * while most others don't seem to care.
-+ *
-+ * Note that this is one of the places MMC/SD plays games with the
-+ * SPI protocol. Another is that when chipselect is released while
-+ * the card returns BUSY status, the clock must issue several cycles
-+ * with chipselect high before the card will stop driving its output.
-+ */
-+ host->spi->mode |= SPI_CS_HIGH;
-+ if (spi_setup(host->spi) != 0) {
-+ /* Just warn; most cards work without it. */
-+ dev_warn(&host->spi->dev,
-+ "can't change chip-select polarity\n");
-+ host->spi->mode &= ~SPI_CS_HIGH;
-+ } else {
-+ mmc_spi_readbytes(host, 18);
-+
-+ host->spi->mode &= ~SPI_CS_HIGH;
-+ if (spi_setup(host->spi) != 0) {
-+ /* Wot, we can't get the same setup we had before? */
-+ dev_err(&host->spi->dev,
-+ "can't restore chip-select polarity\n");
-+ }
-+ }
-+}
-+
-+static char *mmc_powerstring(u8 power_mode)
-+{
-+ switch (power_mode) {
-+ case MMC_POWER_OFF: return "off";
-+ case MMC_POWER_UP: return "up";
-+ case MMC_POWER_ON: return "on";
-+ }
-+ return "?";
-+}
-+
-+static void mmc_spi_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
-+{
-+ struct mmc_spi_host *host = mmc_priv(mmc);
-+
-+ if (host->power_mode != ios->power_mode) {
-+ int canpower;
-+
-+ canpower = host->pdata && host->pdata->setpower;
-+
-+ dev_dbg(&host->spi->dev, "mmc_spi: power %s (%d)%s\n",
-+ mmc_powerstring(ios->power_mode),
-+ ios->vdd,
-+ canpower ? ", can switch" : "");
-+
-+ /* switch power on/off if possible, accounting for
-+ * max 250msec powerup time if needed.
-+ */
-+ if (canpower) {
-+ switch (ios->power_mode) {
-+ case MMC_POWER_OFF:
-+ case MMC_POWER_UP:
-+ host->pdata->setpower(&host->spi->dev,
-+ ios->vdd);
-+ if (ios->power_mode == MMC_POWER_UP)
-+ msleep(host->powerup_msecs);
-+ }
-+ }
-+
-+ /* See 6.4.1 in the simplified SD card physical spec 2.0 */
-+ if (ios->power_mode == MMC_POWER_ON)
-+ mmc_spi_initsequence(host);
-+
-+ /* If powering down, ground all card inputs to avoid power
-+ * delivery from data lines! On a shared SPI bus, this
-+ * will probably be temporary; 6.4.2 of the simplified SD
-+ * spec says this must last at least 1msec.
-+ *
-+ * - Clock low means CPOL 0, e.g. mode 0
-+ * - MOSI low comes from writing zero
-+ * - Chipselect is usually active low...
-+ */
-+ if (canpower && ios->power_mode == MMC_POWER_OFF) {
-+ int mres;
-+
-+ host->spi->mode &= ~(SPI_CPOL|SPI_CPHA);
-+ mres = spi_setup(host->spi);
-+ if (mres < 0)
-+ dev_dbg(&host->spi->dev,
-+ "switch to SPI mode 0 failed\n");
-+
-+ if (spi_w8r8(host->spi, 0x00) < 0)
-+ dev_dbg(&host->spi->dev,
-+ "put spi signals to low failed\n");
-+
-+ /*
-+ * Now clock should be low due to spi mode 0;
-+ * MOSI should be low because of written 0x00;
-+ * chipselect should be low (it is active low)
-+ * power supply is off, so now MMC is off too!
-+ *
-+ * FIXME no, chipselect can be high since the
-+ * device is inactive and SPI_CS_HIGH is clear...
-+ */
-+ msleep(10);
-+ if (mres == 0) {
-+ host->spi->mode |= (SPI_CPOL|SPI_CPHA);
-+ mres = spi_setup(host->spi);
-+ if (mres < 0)
-+ dev_dbg(&host->spi->dev,
-+ "switch back to SPI mode 3"
-+ " failed\n");
-+ }
-+ }
-+
-+ host->power_mode = ios->power_mode;
-+ }
-+
-+ if (host->spi->max_speed_hz != ios->clock && ios->clock != 0) {
-+ int status;
-+
-+ host->spi->max_speed_hz = ios->clock;
-+ status = spi_setup(host->spi);
-+ dev_dbg(&host->spi->dev,
-+ "mmc_spi: clock to %d Hz, %d\n",
-+ host->spi->max_speed_hz, status);
-+ }
-+}
-+
-+static int mmc_spi_get_ro(struct mmc_host *mmc)
-+{
-+ struct mmc_spi_host *host = mmc_priv(mmc);
-+
-+ if (host->pdata && host->pdata->get_ro)
-+ return host->pdata->get_ro(mmc->parent);
-+ /* board doesn't support read only detection; assume writeable */
-+ return 0;
-+}
-+
-+
-+static const struct mmc_host_ops mmc_spi_ops = {
-+ .request = mmc_spi_request,
-+ .set_ios = mmc_spi_set_ios,
-+ .get_ro = mmc_spi_get_ro,
-+};
-+
-+
-+/****************************************************************************/
-+
-+/*
-+ * SPI driver implementation
-+ */
-+
-+static irqreturn_t
-+mmc_spi_detect_irq(int irq, void *mmc)
-+{
-+ struct mmc_spi_host *host = mmc_priv(mmc);
-+ u16 delay_msec = max(host->pdata->detect_delay, (u16)100);
-+
-+ mmc_detect_change(mmc, msecs_to_jiffies(delay_msec));
-+ return IRQ_HANDLED;
-+}
-+
-+struct count_children {
-+ unsigned n;
-+ struct bus_type *bus;
-+};
-+
-+static int maybe_count_child(struct device *dev, void *c)
-+{
-+ struct count_children *ccp = c;
-+
-+ if (dev->bus == ccp->bus) {
-+ if (ccp->n)
-+ return -EBUSY;
-+ ccp->n++;
-+ }
-+ return 0;
-+}
-+
-+static int mmc_spi_probe(struct spi_device *spi)
-+{
-+ void *ones;
-+ struct mmc_host *mmc;
-+ struct mmc_spi_host *host;
-+ int status;
-+
-+ /* MMC and SD specs only seem to care that sampling is on the
-+ * rising edge ... meaning SPI modes 0 or 3. So either SPI mode
-+ * should be legit. We'll use mode 0 since it seems to be a
-+ * bit less troublesome on some hardware ... unclear why.
-+ */
-+ spi->mode = SPI_MODE_0;
-+ spi->bits_per_word = 8;
-+
-+ status = spi_setup(spi);
-+ if (status < 0) {
-+ dev_dbg(&spi->dev, "needs SPI mode %02x, %d KHz; %d\n",
-+ spi->mode, spi->max_speed_hz / 1000,
-+ status);
-+ return status;
-+ }
-+
-+ /* We can use the bus safely iff nobody else will interfere with us.
-+ * Most commands consist of one SPI message to issue a command, then
-+ * several more to collect its response, then possibly more for data
-+ * transfer. Clocking access to other devices during that period will
-+ * corrupt the command execution.
-+ *
-+ * Until we have software primitives which guarantee non-interference,
-+ * we'll aim for a hardware-level guarantee.
-+ *
-+ * REVISIT we can't guarantee another device won't be added later...
-+ */
-+ if (spi->master->num_chipselect > 1) {
-+ struct count_children cc;
-+
-+ cc.n = 0;
-+ cc.bus = spi->dev.bus;
-+ status = device_for_each_child(spi->dev.parent, &cc,
-+ maybe_count_child);
-+ if (status < 0) {
-+ dev_err(&spi->dev, "can't share SPI bus\n");
-+ return status;
-+ }
-+
-+ dev_warn(&spi->dev, "ASSUMING SPI bus stays unshared!\n");
-+ }
-+
-+ /* We need a supply of ones to transmit. This is the only time
-+ * the CPU touches these, so cache coherency isn't a concern.
-+ *
-+ * NOTE if many systems use more than one MMC-over-SPI connector
-+ * it'd save some memory to share this. That's evidently rare.
-+ */
-+ status = -ENOMEM;
-+ ones = kmalloc(MMC_SPI_BLOCKSIZE, GFP_KERNEL);
-+ if (!ones)
-+ goto nomem;
-+ memset(ones, 0xff, MMC_SPI_BLOCKSIZE);
-+
-+ mmc = mmc_alloc_host(sizeof(*host), &spi->dev);
-+ if (!mmc)
-+ goto nomem;
-+
-+ mmc->ops = &mmc_spi_ops;
-+ mmc->max_blk_size = MMC_SPI_BLOCKSIZE;
-+
-+ /* As long as we keep track of the number of successfully
-+ * transmitted blocks, we're good for multiwrite.
-+ */
-+ mmc->caps = MMC_CAP_SPI | MMC_CAP_MULTIWRITE;
-+
-+ /* SPI doesn't need the lowspeed device identification thing for
-+ * MMC or SD cards, since it never comes up in open drain mode.
-+ * That's good; some SPI masters can't handle very low speeds!
-+ *
-+ * However, low speed SDIO cards need not handle over 400 KHz;
-+ * that's the only reason not to use a few MHz for f_min (until
-+ * the upper layer reads the target frequency from the CSD).
-+ */
-+ mmc->f_min = 400000;
-+ mmc->f_max = spi->max_speed_hz;
-+
-+ host = mmc_priv(mmc);
-+ host->mmc = mmc;
-+ host->spi = spi;
-+
-+ host->ones = ones;
-+
-+ /* Platform data is used to hook up things like card sensing
-+ * and power switching gpios.
-+ */
-+ host->pdata = spi->dev.platform_data;
-+ if (host->pdata)
-+ mmc->ocr_avail = host->pdata->ocr_mask;
-+ if (!mmc->ocr_avail) {
-+ dev_warn(&spi->dev, "ASSUMING 3.2-3.4 V slot power\n");
-+ mmc->ocr_avail = MMC_VDD_32_33|MMC_VDD_33_34;
-+ }
-+ if (host->pdata && host->pdata->setpower) {
-+ host->powerup_msecs = host->pdata->powerup_msecs;
-+ if (!host->powerup_msecs || host->powerup_msecs > 250)
-+ host->powerup_msecs = 250;
-+ }
-+
-+ dev_set_drvdata(&spi->dev, mmc);
-+
-+ /* preallocate dma buffers */
-+ host->data = kmalloc(sizeof(*host->data), GFP_KERNEL);
-+ if (!host->data)
-+ goto fail_nobuf1;
-+
-+//FIXME
-+#if 0
-+ if (spi->master->dev.parent->dma_mask) {
-+ struct device *dev = spi->master->dev.parent;
-+
-+ host->dma_dev = dev;
-+ host->ones_dma = dma_map_single(dev, ones,
-+ MMC_SPI_BLOCKSIZE, DMA_TO_DEVICE);
-+ host->data_dma = dma_map_single(dev, host->data,
-+ sizeof(*host->data), DMA_BIDIRECTIONAL);
-+
-+ /* REVISIT in theory those map operations can fail... */
-+
-+ dma_sync_single_for_cpu(host->dma_dev,
-+ host->data_dma, sizeof(*host->data),
-+ DMA_BIDIRECTIONAL);
-+ }
-+#endif
-+
-+ /* setup message for status/busy readback */
-+ spi_message_init(&host->readback);
-+ host->readback.is_dma_mapped = (host->dma_dev != NULL);
-+
-+ spi_message_add_tail(&host->status, &host->readback);
-+ host->status.tx_buf = host->ones;
-+ host->status.tx_dma = host->ones_dma;
-+ host->status.rx_buf = &host->data->status;
-+ host->status.rx_dma = host->data_dma + offsetof(struct scratch, status);
-+ host->status.cs_change = 1;
-+
-+ /* register card detect irq */
-+ if (host->pdata && host->pdata->init) {
-+ status = host->pdata->init(&spi->dev, mmc_spi_detect_irq, mmc);
-+ if (status != 0)
-+ goto fail_glue_init;
-+ }
-+
-+ status = mmc_add_host(mmc);
-+ if (status != 0)
-+ goto fail_add_host;
-+
-+ dev_info(&spi->dev, "SD/MMC host %s%s%s%s\n",
-+ mmc->class_dev.bus_id,
-+ host->dma_dev ? "" : ", no DMA",
-+ (host->pdata && host->pdata->get_ro)
-+ ? "" : ", no WP",
-+ (host->pdata && host->pdata->setpower)
-+ ? "" : ", no poweroff");
-+ return 0;
-+
-+fail_add_host:
-+ mmc_remove_host (mmc);
-+fail_glue_init:
-+ if (host->dma_dev)
-+ dma_unmap_single(host->dma_dev, host->data_dma,
-+ sizeof(*host->data), DMA_BIDIRECTIONAL);
-+ kfree(host->data);
-+
-+fail_nobuf1:
-+ mmc_free_host(mmc);
-+ dev_set_drvdata(&spi->dev, NULL);
-+
-+nomem:
-+ kfree(ones);
-+ return status;
-+}
-+
-+
-+static int __devexit mmc_spi_remove(struct spi_device *spi)
-+{
-+ struct mmc_host *mmc = dev_get_drvdata(&spi->dev);
-+ struct mmc_spi_host *host;
-+
-+ if (mmc) {
-+ host = mmc_priv(mmc);
-+
-+ /* prevent new mmc_detect_change() calls */
-+ if (host->pdata && host->pdata->exit)
-+ host->pdata->exit(&spi->dev, mmc);
-+
-+ mmc_remove_host(mmc);
-+
-+ if (host->dma_dev) {
-+ dma_unmap_single(host->dma_dev, host->ones_dma,
-+ MMC_SPI_BLOCKSIZE, DMA_TO_DEVICE);
-+ dma_unmap_single(host->dma_dev, host->data_dma,
-+ sizeof(*host->data), DMA_BIDIRECTIONAL);
-+ }
-+
-+ kfree(host->data);
-+ kfree(host->ones);
-+
-+ spi->max_speed_hz = mmc->f_max;
-+ mmc_free_host(mmc);
-+ dev_set_drvdata(&spi->dev, NULL);
-+ }
-+ return 0;
-+}
-+
-+
-+static struct spi_driver mmc_spi_driver = {
-+ .driver = {
-+ .name = "mmc_spi",
-+ .bus = &spi_bus_type,
-+ .owner = THIS_MODULE,
-+ },
-+ .probe = mmc_spi_probe,
-+ .remove = __devexit_p(mmc_spi_remove),
-+};
-+
-+
-+static int __init mmc_spi_init(void)
-+{
-+ return spi_register_driver(&mmc_spi_driver);
-+}
-+module_init(mmc_spi_init);
-+
-+
-+static void __exit mmc_spi_exit(void)
-+{
-+ spi_unregister_driver(&mmc_spi_driver);
-+}
-+module_exit(mmc_spi_exit);
-+
-+
-+MODULE_AUTHOR("Mike Lavender, David Brownell, "
-+ "Hans-Peter Nilsson, Jan Nikitenko");
-+MODULE_DESCRIPTION("SPI SD/MMC host driver");
-+MODULE_LICENSE("GPL");
---- /dev/null
-+++ b/include/linux/spi/mmc_spi.h
-@@ -0,0 +1,33 @@
-+#ifndef __LINUX_SPI_MMC_SPI_H
-+#define __LINUX_SPI_MMC_SPI_H
-+
-+struct device;
-+struct mmc_host;
-+
-+/* Put this in platform_data of a device being used to manage an MMC/SD
-+ * card slot. (Modeled after PXA mmc glue; see that for usage examples.)
-+ *
-+ * REVISIT This is not a spi-specific notion. Any card slot should be
-+ * able to handle it. If the MMC core doesn't adopt this kind of notion,
-+ * switch the "struct device *" parameters over to "struct spi_device *".
-+ */
-+struct mmc_spi_platform_data {
-+ /* driver activation and (optional) card detect irq hookup */
-+ int (*init)(struct device *,
-+ irqreturn_t (*)(int, void *),
-+ void *);
-+ void (*exit)(struct device *, void *);
-+
-+ /* sense switch on sd cards */
-+ int (*get_ro)(struct device *);
-+
-+ /* how long to debounce card detect, in msecs */
-+ u16 detect_delay;
-+
-+ /* power management */
-+ u16 powerup_msecs; /* delay of up to 250 msec */
-+ u32 ocr_mask; /* available voltages */
-+ void (*setpower)(struct device *, unsigned int maskval);
-+};
-+
-+#endif /* __LINUX_SPI_MMC_SPI_H */
---- a/drivers/mmc/core/bus.c
-+++ b/drivers/mmc/core/bus.c
-@@ -19,6 +19,7 @@
-
- #include "sysfs.h"
- #include "core.h"
-+#include "sdio_cis.h"
- #include "bus.h"
-
- #define dev_to_mmc_card(d) container_of(d, struct mmc_card, dev)
-@@ -34,6 +35,8 @@
- return sprintf(buf, "MMC\n");
- case MMC_TYPE_SD:
- return sprintf(buf, "SD\n");
-+ case MMC_TYPE_SDIO:
-+ return sprintf(buf, "SDIO\n");
- default:
- return -EFAULT;
- }
-@@ -55,36 +58,37 @@
- }
-
- static int
--mmc_bus_uevent(struct device *dev, char **envp, int num_envp, char *buf,
-- int buf_size)
-+mmc_bus_uevent(struct device *dev, char **envp,
-+ int num_envp, char *buffer, int buffer_size)
- {
- struct mmc_card *card = dev_to_mmc_card(dev);
-- int retval = 0, i = 0, length = 0;
--
--#define add_env(fmt,val) do { \
-- retval = add_uevent_var(envp, num_envp, &i, \
-- buf, buf_size, &length, \
-- fmt, val); \
-- if (retval) \
-- return retval; \
--} while (0);
-+ const char *type;
-+ int retval = 0;
-+ int i = 0, len = 0;
-
- switch (card->type) {
- case MMC_TYPE_MMC:
-- add_env("MMC_TYPE=%s", "MMC");
-+ type = "MMC";
- break;
- case MMC_TYPE_SD:
-- add_env("MMC_TYPE=%s", "SD");
-+ type = "SD";
- break;
-+ case MMC_TYPE_SDIO:
-+ type = "SDIO";
-+ break;
-+ default:
-+ type = NULL;
- }
-
-- add_env("MMC_NAME=%s", mmc_card_name(card));
--
--#undef add_env
-+ if (type) {
-+ retval = add_uevent_var(envp, num_envp, &i, buffer, buffer_size, &len, "MMC_TYPE=%s", type);
-+ if (retval)
-+ return retval;
-+ }
-
-- envp[i] = NULL;
-+ retval = add_uevent_var(envp, num_envp, &i, buffer, buffer_size, &len, "MMC_NAME=%s", mmc_card_name(card));
-
-- return 0;
-+ return retval;
- }
-
- static int mmc_bus_probe(struct device *dev)
-@@ -176,6 +180,11 @@
- {
- struct mmc_card *card = dev_to_mmc_card(dev);
-
-+ sdio_free_common_cis(card);
-+
-+ if (card->info)
-+ kfree(card->info);
-+
- kfree(card);
- }
-
-@@ -221,15 +230,25 @@
- if (mmc_card_blockaddr(card))
- type = "SDHC";
- break;
-+ case MMC_TYPE_SDIO:
-+ type = "SDIO";
-+ break;
- default:
- type = "?";
- break;
- }
-
-- printk(KERN_INFO "%s: new %s%s card at address %04x\n",
-- mmc_hostname(card->host),
-- mmc_card_highspeed(card) ? "high speed " : "",
-- type, card->rca);
-+ if (mmc_host_is_spi(card->host)) {
-+ printk(KERN_INFO "%s: new %s%s card on SPI\n",
-+ mmc_hostname(card->host),
-+ mmc_card_highspeed(card) ? "high speed " : "",
-+ type);
-+ } else {
-+ printk(KERN_INFO "%s: new %s%s card at address %04x\n",
-+ mmc_hostname(card->host),
-+ mmc_card_highspeed(card) ? "high speed " : "",
-+ type, card->rca);
-+ }
-
- card->dev.uevent_suppress = 1;
-
-@@ -261,8 +280,13 @@
- void mmc_remove_card(struct mmc_card *card)
- {
- if (mmc_card_present(card)) {
-- printk(KERN_INFO "%s: card %04x removed\n",
-- mmc_hostname(card->host), card->rca);
-+ if (mmc_host_is_spi(card->host)) {
-+ printk(KERN_INFO "%s: SPI card removed\n",
-+ mmc_hostname(card->host));
-+ } else {
-+ printk(KERN_INFO "%s: card %04x removed\n",
-+ mmc_hostname(card->host), card->rca);
-+ }
-
- if (card->host->bus_ops->sysfs_remove)
- card->host->bus_ops->sysfs_remove(card->host, card);
---- a/drivers/mmc/core/core.c
-+++ b/drivers/mmc/core/core.c
-@@ -18,7 +18,7 @@
- #include <linux/delay.h>
- #include <linux/pagemap.h>
- #include <linux/err.h>
--#include <asm/scatterlist.h>
-+#include <linux/leds.h>
- #include <linux/scatterlist.h>
-
- #include <linux/mmc/card.h>
-@@ -29,16 +29,27 @@
- #include "core.h"
- #include "bus.h"
- #include "host.h"
-+#include "sdio_bus.h"
-
- #include "mmc_ops.h"
- #include "sd_ops.h"
-+#include "sdio_ops.h"
-
- extern int mmc_attach_mmc(struct mmc_host *host, u32 ocr);
- extern int mmc_attach_sd(struct mmc_host *host, u32 ocr);
-+extern int mmc_attach_sdio(struct mmc_host *host, u32 ocr);
-
- static struct workqueue_struct *workqueue;
-
- /*
-+ * Enabling software CRCs on the data blocks can be a significant (30%)
-+ * performance cost, and for other reasons may not always be desired.
-+ * So we allow it it to be disabled.
-+ */
-+int use_spi_crc = 1;
-+module_param(use_spi_crc, bool, 0);
-+
-+/*
- * Internal function. Schedule delayed work in the MMC work queue.
- */
- static int mmc_schedule_delayed_work(struct delayed_work *work,
-@@ -68,6 +79,11 @@
- struct mmc_command *cmd = mrq->cmd;
- int err = cmd->error;
-
-+ if (err && cmd->retries && mmc_host_is_spi(host)) {
-+ if (cmd->resp[0] & R1_SPI_ILLEGAL_COMMAND)
-+ cmd->retries = 0;
-+ }
-+
- if (err && cmd->retries) {
- pr_debug("%s: req failed (CMD%u): %d, retrying...\n",
- mmc_hostname(host), cmd->opcode, err);
-@@ -76,6 +92,8 @@
- cmd->error = 0;
- host->ops->request(host, mrq);
- } else {
-+ led_trigger_event(host->led, LED_OFF);
-+
- pr_debug("%s: req done (CMD%u): %d: %08x %08x %08x %08x\n",
- mmc_hostname(host), cmd->opcode, err,
- cmd->resp[0], cmd->resp[1],
-@@ -118,7 +136,7 @@
- "tsac %d ms nsac %d\n",
- mmc_hostname(host), mrq->data->blksz,
- mrq->data->blocks, mrq->data->flags,
-- mrq->data->timeout_ns / 10000000,
-+ mrq->data->timeout_ns / 1000000,
- mrq->data->timeout_clks);
- }
-
-@@ -130,6 +148,8 @@
-
- WARN_ON(!host->claimed);
-
-+ led_trigger_event(host->led, LED_FULL);
-+
- mrq->cmd->error = 0;
- mrq->cmd->mrq = mrq;
- if (mrq->data) {
-@@ -199,7 +219,7 @@
- {
- struct mmc_request mrq;
-
-- BUG_ON(!host->claimed);
-+ WARN_ON(!host->claimed);
-
- memset(&mrq, 0, sizeof(struct mmc_request));
-
-@@ -220,17 +240,24 @@
- * mmc_set_data_timeout - set the timeout for a data command
- * @data: data phase for command
- * @card: the MMC card associated with the data transfer
-- * @write: flag to differentiate reads from writes
- *
- * Computes the data timeout parameters according to the
- * correct algorithm given the card type.
- */
--void mmc_set_data_timeout(struct mmc_data *data, const struct mmc_card *card,
-- int write)
-+void mmc_set_data_timeout(struct mmc_data *data, const struct mmc_card *card)
- {
- unsigned int mult;
-
- /*
-+ * SDIO cards only define an upper 1 s limit on access.
-+ */
-+ if (mmc_card_sdio(card)) {
-+ data->timeout_ns = 1000000000;
-+ data->timeout_clks = 0;
-+ return;
-+ }
-+
-+ /*
- * SD cards use a 100 multiplier rather than 10
- */
- mult = mmc_card_sd(card) ? 100 : 10;
-@@ -239,7 +266,7 @@
- * Scale up the multiplier (and therefore the timeout) by
- * the r2w factor for writes.
- */
-- if (write)
-+ if (data->flags & MMC_DATA_WRITE)
- mult <<= card->csd.r2w_factor;
-
- data->timeout_ns = card->csd.tacc_ns * mult;
-@@ -255,7 +282,7 @@
- timeout_us += data->timeout_clks * 1000 /
- (card->host->ios.clock / 1000);
-
-- if (write)
-+ if (data->flags & MMC_DATA_WRITE)
- limit_us = 250000;
- else
- limit_us = 100000;
-@@ -272,15 +299,20 @@
- EXPORT_SYMBOL(mmc_set_data_timeout);
-
- /**
-- * mmc_claim_host - exclusively claim a host
-+ * __mmc_claim_host - exclusively claim a host
- * @host: mmc host to claim
-+ * @abort: whether or not the operation should be aborted
- *
-- * Claim a host for a set of operations.
-+ * Claim a host for a set of operations. If @abort is non null and
-+ * dereference a non-zero value then this will return prematurely with
-+ * that non-zero value without acquiring the lock. Returns zero
-+ * with the lock held otherwise.
- */
--void mmc_claim_host(struct mmc_host *host)
-+int __mmc_claim_host(struct mmc_host *host, atomic_t *abort)
- {
- DECLARE_WAITQUEUE(wait, current);
- unsigned long flags;
-+ int stop;
-
- might_sleep();
-
-@@ -288,19 +320,24 @@
- spin_lock_irqsave(&host->lock, flags);
- while (1) {
- set_current_state(TASK_UNINTERRUPTIBLE);
-- if (!host->claimed)
-+ stop = abort ? atomic_read(abort) : 0;
-+ if (stop || !host->claimed)
- break;
- spin_unlock_irqrestore(&host->lock, flags);
- schedule();
- spin_lock_irqsave(&host->lock, flags);
- }
- set_current_state(TASK_RUNNING);
-- host->claimed = 1;
-+ if (!stop)
-+ host->claimed = 1;
-+ else
-+ wake_up(&host->wq);
- spin_unlock_irqrestore(&host->lock, flags);
- remove_wait_queue(&host->wq, &wait);
-+ return stop;
- }
-
--EXPORT_SYMBOL(mmc_claim_host);
-+EXPORT_SYMBOL(__mmc_claim_host);
-
- /**
- * mmc_release_host - release a host
-@@ -313,7 +350,7 @@
- {
- unsigned long flags;
-
-- BUG_ON(!host->claimed);
-+ WARN_ON(!host->claimed);
-
- spin_lock_irqsave(&host->lock, flags);
- host->claimed = 0;
-@@ -433,19 +470,32 @@
- int bit = fls(host->ocr_avail) - 1;
-
- host->ios.vdd = bit;
-- host->ios.bus_mode = MMC_BUSMODE_OPENDRAIN;
-- host->ios.chip_select = MMC_CS_DONTCARE;
-+ if (mmc_host_is_spi(host)) {
-+ host->ios.chip_select = MMC_CS_HIGH;
-+ host->ios.bus_mode = MMC_BUSMODE_PUSHPULL;
-+ } else {
-+ host->ios.chip_select = MMC_CS_DONTCARE;
-+ host->ios.bus_mode = MMC_BUSMODE_OPENDRAIN;
-+ }
- host->ios.power_mode = MMC_POWER_UP;
- host->ios.bus_width = MMC_BUS_WIDTH_1;
- host->ios.timing = MMC_TIMING_LEGACY;
- mmc_set_ios(host);
-
-- mmc_delay(1);
-+ /*
-+ * This delay should be sufficient to allow the power supply
-+ * to reach the minimum voltage.
-+ */
-+ mmc_delay(2);
-
- host->ios.clock = host->f_min;
- host->ios.power_mode = MMC_POWER_ON;
- mmc_set_ios(host);
-
-+ /*
-+ * This delay must be at least 74 clock sizes, or 1 ms, or the
-+ * time required to reach a stable voltage.
-+ */
- mmc_delay(2);
- }
-
-@@ -453,8 +503,10 @@
- {
- host->ios.clock = 0;
- host->ios.vdd = 0;
-- host->ios.bus_mode = MMC_BUSMODE_OPENDRAIN;
-- host->ios.chip_select = MMC_CS_DONTCARE;
-+ if (!mmc_host_is_spi(host)) {
-+ host->ios.bus_mode = MMC_BUSMODE_OPENDRAIN;
-+ host->ios.chip_select = MMC_CS_DONTCARE;
-+ }
- host->ios.power_mode = MMC_POWER_OFF;
- host->ios.bus_width = MMC_BUS_WIDTH_1;
- host->ios.timing = MMC_TIMING_LEGACY;
-@@ -511,7 +563,7 @@
- BUG_ON(!host);
- BUG_ON(!ops);
-
-- BUG_ON(!host->claimed);
-+ WARN_ON(!host->claimed);
-
- spin_lock_irqsave(&host->lock, flags);
-
-@@ -535,8 +587,8 @@
-
- BUG_ON(!host);
-
-- BUG_ON(!host->claimed);
-- BUG_ON(!host->bus_ops);
-+ WARN_ON(!host->claimed);
-+ WARN_ON(!host->bus_ops);
-
- spin_lock_irqsave(&host->lock, flags);
-
-@@ -564,7 +616,7 @@
- #ifdef CONFIG_MMC_DEBUG
- unsigned long flags;
- spin_lock_irqsave(&host->lock, flags);
-- BUG_ON(host->removed);
-+ WARN_ON(host->removed);
- spin_unlock_irqrestore(&host->lock, flags);
- #endif
-
-@@ -597,24 +649,38 @@
-
- mmc_send_if_cond(host, host->ocr_avail);
-
-+ /*
-+ * First we search for SDIO...
-+ */
-+ err = mmc_send_io_op_cond(host, 0, &ocr);
-+ if (!err) {
-+ if (mmc_attach_sdio(host, ocr))
-+ mmc_power_off(host);
-+ return;
-+ }
-+
-+ /*
-+ * ...then normal SD...
-+ */
- err = mmc_send_app_op_cond(host, 0, &ocr);
-- if (err == MMC_ERR_NONE) {
-+ if (!err) {
- if (mmc_attach_sd(host, ocr))
- mmc_power_off(host);
-- } else {
-- /*
-- * If we fail to detect any SD cards then try
-- * searching for MMC cards.
-- */
-- err = mmc_send_op_cond(host, 0, &ocr);
-- if (err == MMC_ERR_NONE) {
-- if (mmc_attach_mmc(host, ocr))
-- mmc_power_off(host);
-- } else {
-+ return;
-+ }
-+
-+ /*
-+ * ...and finally MMC.
-+ */
-+ err = mmc_send_op_cond(host, 0, &ocr);
-+ if (!err) {
-+ if (mmc_attach_mmc(host, ocr))
- mmc_power_off(host);
-- mmc_release_host(host);
-- }
-+ return;
- }
-+
-+ mmc_release_host(host);
-+ mmc_power_off(host);
- } else {
- if (host->bus_ops->detect && !host->bus_dead)
- host->bus_ops->detect(host);
-@@ -725,22 +791,38 @@
- return -ENOMEM;
-
- ret = mmc_register_bus();
-- if (ret == 0) {
-- ret = mmc_register_host_class();
-- if (ret)
-- mmc_unregister_bus();
-- }
-+ if (ret)
-+ goto destroy_workqueue;
-+
-+ ret = mmc_register_host_class();
-+ if (ret)
-+ goto unregister_bus;
-+
-+ ret = sdio_register_bus();
-+ if (ret)
-+ goto unregister_host_class;
-+
-+ return 0;
-+
-+unregister_host_class:
-+ mmc_unregister_host_class();
-+unregister_bus:
-+ mmc_unregister_bus();
-+destroy_workqueue:
-+ destroy_workqueue(workqueue);
-+
- return ret;
- }
-
- static void __exit mmc_exit(void)
- {
-+ sdio_unregister_bus();
- mmc_unregister_host_class();
- mmc_unregister_bus();
- destroy_workqueue(workqueue);
- }
-
--module_init(mmc_init);
-+subsys_initcall(mmc_init);
- module_exit(mmc_exit);
-
- MODULE_LICENSE("GPL");
---- a/drivers/mmc/core/core.h
-+++ b/drivers/mmc/core/core.h
-@@ -48,5 +48,7 @@
- void mmc_start_host(struct mmc_host *host);
- void mmc_stop_host(struct mmc_host *host);
-
-+extern int use_spi_crc;
-+
- #endif
-
---- a/drivers/mmc/core/host.c
-+++ b/drivers/mmc/core/host.c
-@@ -15,6 +15,7 @@
- #include <linux/err.h>
- #include <linux/idr.h>
- #include <linux/pagemap.h>
-+#include <linux/leds.h>
-
- #include <linux/mmc/host.h>
-
-@@ -100,6 +101,9 @@
- {
- int err;
-
-+ WARN_ON((host->caps & MMC_CAP_SDIO_IRQ) &&
-+ !host->ops->enable_sdio_irq);
-+
- if (!idr_pre_get(&mmc_host_idr, GFP_KERNEL))
- return -ENOMEM;
-
-@@ -112,6 +116,8 @@
- snprintf(host->class_dev.bus_id, BUS_ID_SIZE,
- "mmc%d", host->index);
-
-+ led_trigger_register_simple(host->class_dev.bus_id, &host->led);
-+
- err = device_add(&host->class_dev);
- if (err)
- return err;
-@@ -137,6 +143,8 @@
-
- device_del(&host->class_dev);
-
-+ led_trigger_unregister_simple(host->led);
-+
- spin_lock(&mmc_host_lock);
- idr_remove(&mmc_host_idr, host->index);
- spin_unlock(&mmc_host_lock);
---- a/drivers/mmc/core/mmc.c
-+++ b/drivers/mmc/core/mmc.c
-@@ -161,13 +161,12 @@
- {
- int err;
- u8 *ext_csd;
-+ unsigned int ext_csd_struct;
-
- BUG_ON(!card);
-
-- err = MMC_ERR_FAILED;
--
- if (card->csd.mmca_vsn < CSD_SPEC_VER_4)
-- return MMC_ERR_NONE;
-+ return 0;
-
- /*
- * As the ext_csd is so large and mostly unused, we don't store the
-@@ -176,13 +175,19 @@
- ext_csd = kmalloc(512, GFP_KERNEL);
- if (!ext_csd) {
- printk(KERN_ERR "%s: could not allocate a buffer to "
-- "receive the ext_csd. mmc v4 cards will be "
-- "treated as v3.\n", mmc_hostname(card->host));
-- return MMC_ERR_FAILED;
-+ "receive the ext_csd.\n", mmc_hostname(card->host));
-+ return -ENOMEM;
- }
-
- err = mmc_send_ext_csd(card, ext_csd);
-- if (err != MMC_ERR_NONE) {
-+ if (err) {
-+ /*
-+ * We all hosts that cannot perform the command
-+ * to fail more gracefully
-+ */
-+ if (err != -EINVAL)
-+ goto out;
-+
- /*
- * High capacity cards should have this "magic" size
- * stored in their CSD.
-@@ -197,18 +202,30 @@
- "EXT_CSD, performance might "
- "suffer.\n",
- mmc_hostname(card->host));
-- err = MMC_ERR_NONE;
-+ err = 0;
- }
-+
- goto out;
- }
-
-- card->ext_csd.sectors =
-- ext_csd[EXT_CSD_SEC_CNT + 0] << 0 |
-- ext_csd[EXT_CSD_SEC_CNT + 1] << 8 |
-- ext_csd[EXT_CSD_SEC_CNT + 2] << 16 |
-- ext_csd[EXT_CSD_SEC_CNT + 3] << 24;
-- if (card->ext_csd.sectors)
-- mmc_card_set_blockaddr(card);
-+ ext_csd_struct = ext_csd[EXT_CSD_REV];
-+ if (ext_csd_struct > 2) {
-+ printk(KERN_ERR "%s: unrecognised EXT_CSD structure "
-+ "version %d\n", mmc_hostname(card->host),
-+ ext_csd_struct);
-+ err = -EINVAL;
-+ goto out;
-+ }
-+
-+ if (ext_csd_struct >= 2) {
-+ card->ext_csd.sectors =
-+ ext_csd[EXT_CSD_SEC_CNT + 0] << 0 |
-+ ext_csd[EXT_CSD_SEC_CNT + 1] << 8 |
-+ ext_csd[EXT_CSD_SEC_CNT + 2] << 16 |
-+ ext_csd[EXT_CSD_SEC_CNT + 3] << 24;
-+ if (card->ext_csd.sectors)
-+ mmc_card_set_blockaddr(card);
-+ }
-
- switch (ext_csd[EXT_CSD_CARD_TYPE]) {
- case EXT_CSD_CARD_TYPE_52 | EXT_CSD_CARD_TYPE_26:
-@@ -246,7 +263,7 @@
- unsigned int max_dtr;
-
- BUG_ON(!host);
-- BUG_ON(!host->claimed);
-+ WARN_ON(!host->claimed);
-
- /*
- * Since we're changing the OCR value, we seem to
-@@ -258,19 +275,33 @@
-
- /* The extra bit indicates that we support high capacity */
- err = mmc_send_op_cond(host, ocr | (1 << 30), NULL);
-- if (err != MMC_ERR_NONE)
-+ if (err)
- goto err;
-
- /*
-+ * For SPI, enable CRC as appropriate.
-+ */
-+ if (mmc_host_is_spi(host)) {
-+ err = mmc_spi_set_crc(host, use_spi_crc);
-+ if (err)
-+ goto err;
-+ }
-+
-+ /*
- * Fetch CID from card.
- */
-- err = mmc_all_send_cid(host, cid);
-- if (err != MMC_ERR_NONE)
-+ if (mmc_host_is_spi(host))
-+ err = mmc_send_cid(host, cid);
-+ else
-+ err = mmc_all_send_cid(host, cid);
-+ if (err)
- goto err;
-
- if (oldcard) {
-- if (memcmp(cid, oldcard->raw_cid, sizeof(cid)) != 0)
-+ if (memcmp(cid, oldcard->raw_cid, sizeof(cid)) != 0) {
-+ err = -ENOENT;
- goto err;
-+ }
-
- card = oldcard;
- } else {
-@@ -278,8 +309,10 @@
- * Allocate card structure.
- */
- card = mmc_alloc_card(host);
-- if (IS_ERR(card))
-+ if (IS_ERR(card)) {
-+ err = PTR_ERR(card);
- goto err;
-+ }
-
- card->type = MMC_TYPE_MMC;
- card->rca = 1;
-@@ -287,43 +320,47 @@
- }
-
- /*
-- * Set card RCA.
-+ * For native busses: set card RCA and quit open drain mode.
- */
-- err = mmc_set_relative_addr(card);
-- if (err != MMC_ERR_NONE)
-- goto free_card;
-+ if (!mmc_host_is_spi(host)) {
-+ err = mmc_set_relative_addr(card);
-+ if (err)
-+ goto free_card;
-
-- mmc_set_bus_mode(host, MMC_BUSMODE_PUSHPULL);
-+ mmc_set_bus_mode(host, MMC_BUSMODE_PUSHPULL);
-+ }
-
- if (!oldcard) {
- /*
- * Fetch CSD from card.
- */
- err = mmc_send_csd(card, card->raw_csd);
-- if (err != MMC_ERR_NONE)
-+ if (err)
- goto free_card;
-
- err = mmc_decode_csd(card);
-- if (err < 0)
-+ if (err)
- goto free_card;
- err = mmc_decode_cid(card);
-- if (err < 0)
-+ if (err)
- goto free_card;
- }
-
- /*
- * Select card, as all following commands rely on that.
- */
-- err = mmc_select_card(card);
-- if (err != MMC_ERR_NONE)
-- goto free_card;
-+ if (!mmc_host_is_spi(host)) {
-+ err = mmc_select_card(card);
-+ if (err)
-+ goto free_card;
-+ }
-
- if (!oldcard) {
- /*
-- * Fetch and process extened CSD.
-+ * Fetch and process extended CSD.
- */
- err = mmc_read_ext_csd(card);
-- if (err != MMC_ERR_NONE)
-+ if (err)
- goto free_card;
- }
-
-@@ -334,7 +371,7 @@
- (host->caps & MMC_CAP_MMC_HIGHSPEED)) {
- err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
- EXT_CSD_HS_TIMING, 1);
-- if (err != MMC_ERR_NONE)
-+ if (err)
- goto free_card;
-
- mmc_card_set_highspeed(card);
-@@ -363,7 +400,7 @@
- (host->caps & MMC_CAP_4_BIT_DATA)) {
- err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
- EXT_CSD_BUS_WIDTH, EXT_CSD_BUS_WIDTH_4);
-- if (err != MMC_ERR_NONE)
-+ if (err)
- goto free_card;
-
- mmc_set_bus_width(card->host, MMC_BUS_WIDTH_4);
-@@ -372,14 +409,14 @@
- if (!oldcard)
- host->card = card;
-
-- return MMC_ERR_NONE;
-+ return 0;
-
- free_card:
- if (!oldcard)
- mmc_remove_card(card);
- err:
-
-- return MMC_ERR_FAILED;
-+ return err;
- }
-
- /*
-@@ -413,7 +450,7 @@
-
- mmc_release_host(host);
-
-- if (err != MMC_ERR_NONE) {
-+ if (err) {
- mmc_remove(host);
-
- mmc_claim_host(host);
-@@ -480,7 +517,8 @@
- BUG_ON(!host->card);
-
- mmc_claim_host(host);
-- mmc_deselect_cards(host);
-+ if (!mmc_host_is_spi(host))
-+ mmc_deselect_cards(host);
- host->card->state &= ~MMC_STATE_HIGHSPEED;
- mmc_release_host(host);
- }
-@@ -502,7 +540,7 @@
- err = mmc_init_card(host, host->ocr, host->card);
- mmc_release_host(host);
-
-- if (err != MMC_ERR_NONE) {
-+ if (err) {
- mmc_remove(host);
-
- mmc_claim_host(host);
-@@ -536,11 +574,20 @@
- int err;
-
- BUG_ON(!host);
-- BUG_ON(!host->claimed);
-+ WARN_ON(!host->claimed);
-
- mmc_attach_bus(host, &mmc_ops);
-
- /*
-+ * We need to get OCR a different way for SPI.
-+ */
-+ if (mmc_host_is_spi(host)) {
-+ err = mmc_spi_read_ocr(host, 1, &ocr);
-+ if (err)
-+ goto err;
-+ }
-+
-+ /*
- * Sanity check the voltages that the card claims to
- * support.
- */
-@@ -565,7 +612,7 @@
- * Detect and init the card.
- */
- err = mmc_init_card(host, host->ocr, NULL);
-- if (err != MMC_ERR_NONE)
-+ if (err)
- goto err;
-
- mmc_release_host(host);
-@@ -587,6 +634,6 @@
- printk(KERN_ERR "%s: error %d whilst initialising MMC card\n",
- mmc_hostname(host), err);
-
-- return 0;
-+ return err;
- }
-
---- a/drivers/mmc/core/mmc_ops.c
-+++ b/drivers/mmc/core/mmc_ops.c
-@@ -10,7 +10,6 @@
- */
-
- #include <linux/types.h>
--#include <asm/scatterlist.h>
- #include <linux/scatterlist.h>
-
- #include <linux/mmc/host.h>
-@@ -40,10 +39,10 @@
- }
-
- err = mmc_wait_for_cmd(host, &cmd, MMC_CMD_RETRIES);
-- if (err != MMC_ERR_NONE)
-+ if (err)
- return err;
-
-- return MMC_ERR_NONE;
-+ return 0;
- }
-
- int mmc_select_card(struct mmc_card *card)
-@@ -63,23 +62,36 @@
- int err;
- struct mmc_command cmd;
-
-- mmc_set_chip_select(host, MMC_CS_HIGH);
--
-- mmc_delay(1);
-+ /*
-+ * Non-SPI hosts need to prevent chipselect going active during
-+ * GO_IDLE; that would put chips into SPI mode. Remind them of
-+ * that in case of hardware that won't pull up DAT3/nCS otherwise.
-+ *
-+ * SPI hosts ignore ios.chip_select; it's managed according to
-+ * rules that must accomodate non-MMC slaves which this layer
-+ * won't even know about.
-+ */
-+ if (!mmc_host_is_spi(host)) {
-+ mmc_set_chip_select(host, MMC_CS_HIGH);
-+ mmc_delay(1);
-+ }
-
- memset(&cmd, 0, sizeof(struct mmc_command));
-
- cmd.opcode = MMC_GO_IDLE_STATE;
- cmd.arg = 0;
-- cmd.flags = MMC_RSP_NONE | MMC_CMD_BC;
-+ cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_NONE | MMC_CMD_BC;
-
- err = mmc_wait_for_cmd(host, &cmd, 0);
-
- mmc_delay(1);
-
-- mmc_set_chip_select(host, MMC_CS_DONTCARE);
-+ if (!mmc_host_is_spi(host)) {
-+ mmc_set_chip_select(host, MMC_CS_DONTCARE);
-+ mmc_delay(1);
-+ }
-
-- mmc_delay(1);
-+ host->use_spi_crc = 0;
-
- return err;
- }
-@@ -94,23 +106,33 @@
- memset(&cmd, 0, sizeof(struct mmc_command));
-
- cmd.opcode = MMC_SEND_OP_COND;
-- cmd.arg = ocr;
-- cmd.flags = MMC_RSP_R3 | MMC_CMD_BCR;
-+ cmd.arg = mmc_host_is_spi(host) ? 0 : ocr;
-+ cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R3 | MMC_CMD_BCR;
-
- for (i = 100; i; i--) {
- err = mmc_wait_for_cmd(host, &cmd, 0);
-- if (err != MMC_ERR_NONE)
-+ if (err)
- break;
-
-- if (cmd.resp[0] & MMC_CARD_BUSY || ocr == 0)
-+ /* if we're just probing, do a single pass */
-+ if (ocr == 0)
- break;
-
-- err = MMC_ERR_TIMEOUT;
-+ /* otherwise wait until reset completes */
-+ if (mmc_host_is_spi(host)) {
-+ if (!(cmd.resp[0] & R1_SPI_IDLE))
-+ break;
-+ } else {
-+ if (cmd.resp[0] & MMC_CARD_BUSY)
-+ break;
-+ }
-+
-+ err = -ETIMEDOUT;
-
- mmc_delay(10);
- }
-
-- if (rocr)
-+ if (rocr && !mmc_host_is_spi(host))
- *rocr = cmd.resp[0];
-
- return err;
-@@ -131,12 +153,12 @@
- cmd.flags = MMC_RSP_R2 | MMC_CMD_BCR;
-
- err = mmc_wait_for_cmd(host, &cmd, MMC_CMD_RETRIES);
-- if (err != MMC_ERR_NONE)
-+ if (err)
- return err;
-
- memcpy(cid, cmd.resp, sizeof(u32) * 4);
-
-- return MMC_ERR_NONE;
-+ return 0;
- }
-
- int mmc_set_relative_addr(struct mmc_card *card)
-@@ -154,46 +176,52 @@
- cmd.flags = MMC_RSP_R1 | MMC_CMD_AC;
-
- err = mmc_wait_for_cmd(card->host, &cmd, MMC_CMD_RETRIES);
-- if (err != MMC_ERR_NONE)
-+ if (err)
- return err;
-
-- return MMC_ERR_NONE;
-+ return 0;
- }
-
--int mmc_send_csd(struct mmc_card *card, u32 *csd)
-+static int
-+mmc_send_cxd_native(struct mmc_host *host, u32 arg, u32 *cxd, int opcode)
- {
- int err;
- struct mmc_command cmd;
-
-- BUG_ON(!card);
-- BUG_ON(!card->host);
-- BUG_ON(!csd);
-+ BUG_ON(!host);
-+ BUG_ON(!cxd);
-
- memset(&cmd, 0, sizeof(struct mmc_command));
-
-- cmd.opcode = MMC_SEND_CSD;
-- cmd.arg = card->rca << 16;
-+ cmd.opcode = opcode;
-+ cmd.arg = arg;
- cmd.flags = MMC_RSP_R2 | MMC_CMD_AC;
-
-- err = mmc_wait_for_cmd(card->host, &cmd, MMC_CMD_RETRIES);
-- if (err != MMC_ERR_NONE)
-+ err = mmc_wait_for_cmd(host, &cmd, MMC_CMD_RETRIES);
-+ if (err)
- return err;
-
-- memcpy(csd, cmd.resp, sizeof(u32) * 4);
-+ memcpy(cxd, cmd.resp, sizeof(u32) * 4);
-
-- return MMC_ERR_NONE;
-+ return 0;
- }
-
--int mmc_send_ext_csd(struct mmc_card *card, u8 *ext_csd)
-+static int
-+mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
-+ u32 opcode, void *buf, unsigned len)
- {
- struct mmc_request mrq;
- struct mmc_command cmd;
- struct mmc_data data;
- struct scatterlist sg;
-+ void *data_buf;
-
-- BUG_ON(!card);
-- BUG_ON(!card->host);
-- BUG_ON(!ext_csd);
-+ /* dma onto stack is unsafe/nonportable, but callers to this
-+ * routine normally provide temporary on-stack buffers ...
-+ */
-+ data_buf = kmalloc(len, GFP_KERNEL);
-+ if (data_buf == NULL)
-+ return -ENOMEM;
-
- memset(&mrq, 0, sizeof(struct mmc_request));
- memset(&cmd, 0, sizeof(struct mmc_command));
-@@ -202,28 +230,117 @@
- mrq.cmd = &cmd;
- mrq.data = &data;
-
-- cmd.opcode = MMC_SEND_EXT_CSD;
-+ cmd.opcode = opcode;
- cmd.arg = 0;
-- cmd.flags = MMC_RSP_R1 | MMC_CMD_ADTC;
-
-- data.blksz = 512;
-+ /* NOTE HACK: the MMC_RSP_SPI_R1 is always correct here, but we
-+ * rely on callers to never use this with "native" calls for reading
-+ * CSD or CID. Native versions of those commands use the R2 type,
-+ * not R1 plus a data block.
-+ */
-+ cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_ADTC;
-+
-+ data.blksz = len;
- data.blocks = 1;
- data.flags = MMC_DATA_READ;
- data.sg = &sg;
- data.sg_len = 1;
-
-- sg_init_one(&sg, ext_csd, 512);
-+ sg_init_one(&sg, data_buf, len);
-+
-+ if (card)
-+ mmc_set_data_timeout(&data, card);
-
-- mmc_set_data_timeout(&data, card, 0);
-+ mmc_wait_for_req(host, &mrq);
-
-- mmc_wait_for_req(card->host, &mrq);
-+ memcpy(buf, data_buf, len);
-+ kfree(data_buf);
-
-- if (cmd.error != MMC_ERR_NONE)
-+ if (cmd.error)
- return cmd.error;
-- if (data.error != MMC_ERR_NONE)
-+ if (data.error)
- return data.error;
-
-- return MMC_ERR_NONE;
-+ return 0;
-+}
-+
-+int mmc_send_csd(struct mmc_card *card, u32 *csd)
-+{
-+ int ret, i;
-+
-+ if (!mmc_host_is_spi(card->host))
-+ return mmc_send_cxd_native(card->host, card->rca << 16,
-+ csd, MMC_SEND_CSD);
-+
-+ ret = mmc_send_cxd_data(card, card->host, MMC_SEND_CSD, csd, 16);
-+ if (ret)
-+ return ret;
-+
-+ for (i = 0;i < 4;i++)
-+ csd[i] = be32_to_cpu(csd[i]);
-+
-+ return 0;
-+}
-+
-+int mmc_send_cid(struct mmc_host *host, u32 *cid)
-+{
-+ int ret, i;
-+
-+ if (!mmc_host_is_spi(host)) {
-+ if (!host->card)
-+ return -EINVAL;
-+ return mmc_send_cxd_native(host, host->card->rca << 16,
-+ cid, MMC_SEND_CID);
-+ }
-+
-+ ret = mmc_send_cxd_data(NULL, host, MMC_SEND_CID, cid, 16);
-+ if (ret)
-+ return ret;
-+
-+ for (i = 0;i < 4;i++)
-+ cid[i] = be32_to_cpu(cid[i]);
-+
-+ return 0;
-+}
-+
-+int mmc_send_ext_csd(struct mmc_card *card, u8 *ext_csd)
-+{
-+ return mmc_send_cxd_data(card, card->host, MMC_SEND_EXT_CSD,
-+ ext_csd, 512);
-+}
-+
-+int mmc_spi_read_ocr(struct mmc_host *host, int highcap, u32 *ocrp)
-+{
-+ struct mmc_command cmd;
-+ int err;
-+
-+ memset(&cmd, 0, sizeof(struct mmc_command));
-+
-+ cmd.opcode = MMC_SPI_READ_OCR;
-+ cmd.arg = highcap ? (1 << 30) : 0;
-+ cmd.flags = MMC_RSP_SPI_R3;
-+
-+ err = mmc_wait_for_cmd(host, &cmd, 0);
-+
-+ *ocrp = cmd.resp[1];
-+ return err;
-+}
-+
-+int mmc_spi_set_crc(struct mmc_host *host, int use_crc)
-+{
-+ struct mmc_command cmd;
-+ int err;
-+
-+ memset(&cmd, 0, sizeof(struct mmc_command));
-+
-+ cmd.opcode = MMC_SPI_CRC_ON_OFF;
-+ cmd.flags = MMC_RSP_SPI_R1;
-+ cmd.arg = use_crc;
-+
-+ err = mmc_wait_for_cmd(host, &cmd, 0);
-+ if (!err)
-+ host->use_spi_crc = use_crc;
-+ return err;
- }
-
- int mmc_switch(struct mmc_card *card, u8 set, u8 index, u8 value)
-@@ -241,13 +358,13 @@
- (index << 16) |
- (value << 8) |
- set;
-- cmd.flags = MMC_RSP_R1B | MMC_CMD_AC;
-+ cmd.flags = MMC_RSP_SPI_R1B | MMC_RSP_R1B | MMC_CMD_AC;
-
- err = mmc_wait_for_cmd(card->host, &cmd, MMC_CMD_RETRIES);
-- if (err != MMC_ERR_NONE)
-+ if (err)
- return err;
-
-- return MMC_ERR_NONE;
-+ return 0;
- }
-
- int mmc_send_status(struct mmc_card *card, u32 *status)
-@@ -261,16 +378,20 @@
- memset(&cmd, 0, sizeof(struct mmc_command));
-
- cmd.opcode = MMC_SEND_STATUS;
-- cmd.arg = card->rca << 16;
-- cmd.flags = MMC_RSP_R1 | MMC_CMD_AC;
-+ if (!mmc_host_is_spi(card->host))
-+ cmd.arg = card->rca << 16;
-+ cmd.flags = MMC_RSP_SPI_R2 | MMC_RSP_R1 | MMC_CMD_AC;
-
- err = mmc_wait_for_cmd(card->host, &cmd, MMC_CMD_RETRIES);
-- if (err != MMC_ERR_NONE)
-+ if (err)
- return err;
-
-+ /* NOTE: callers are required to understand the difference
-+ * between "native" and SPI format status words!
-+ */
- if (status)
- *status = cmd.resp[0];
-
-- return MMC_ERR_NONE;
-+ return 0;
- }
-
---- a/drivers/mmc/core/mmc_ops.h
-+++ b/drivers/mmc/core/mmc_ops.h
-@@ -22,6 +22,9 @@
- int mmc_send_ext_csd(struct mmc_card *card, u8 *ext_csd);
- int mmc_switch(struct mmc_card *card, u8 set, u8 index, u8 value);
- int mmc_send_status(struct mmc_card *card, u32 *status);
-+int mmc_send_cid(struct mmc_host *host, u32 *cid);
-+int mmc_spi_read_ocr(struct mmc_host *host, int highcap, u32 *ocrp);
-+int mmc_spi_set_crc(struct mmc_host *host, int use_crc);
-
- #endif
-
---- a/drivers/mmc/core/sd.c
-+++ b/drivers/mmc/core/sd.c
-@@ -166,8 +166,6 @@
- unsigned int scr_struct;
- u32 resp[4];
-
-- BUG_ON(!mmc_card_sd(card));
--
- resp[3] = card->raw_scr[1];
- resp[2] = card->raw_scr[0];
-
-@@ -193,30 +191,38 @@
- u8 *status;
-
- if (card->scr.sda_vsn < SCR_SPEC_VER_1)
-- return MMC_ERR_NONE;
-+ return 0;
-
- if (!(card->csd.cmdclass & CCC_SWITCH)) {
- printk(KERN_WARNING "%s: card lacks mandatory switch "
- "function, performance might suffer.\n",
- mmc_hostname(card->host));
-- return MMC_ERR_NONE;
-+ return 0;
- }
-
-- err = MMC_ERR_FAILED;
-+ err = -EIO;
-
- status = kmalloc(64, GFP_KERNEL);
- if (!status) {
- printk(KERN_ERR "%s: could not allocate a buffer for "
- "switch capabilities.\n", mmc_hostname(card->host));
-- return err;
-+ return -ENOMEM;
- }
-
- err = mmc_sd_switch(card, 0, 0, 1, status);
-- if (err != MMC_ERR_NONE) {
-+ if (err) {
-+ /*
-+ * We all hosts that cannot perform the command
-+ * to fail more gracefully
-+ */
-+ if (err != -EINVAL)
-+ goto out;
-+
- printk(KERN_WARNING "%s: problem reading switch "
- "capabilities, performance might suffer.\n",
- mmc_hostname(card->host));
-- err = MMC_ERR_NONE;
-+ err = 0;
-+
- goto out;
- }
-
-@@ -238,28 +244,28 @@
- u8 *status;
-
- if (card->scr.sda_vsn < SCR_SPEC_VER_1)
-- return MMC_ERR_NONE;
-+ return 0;
-
- if (!(card->csd.cmdclass & CCC_SWITCH))
-- return MMC_ERR_NONE;
-+ return 0;
-
- if (!(card->host->caps & MMC_CAP_SD_HIGHSPEED))
-- return MMC_ERR_NONE;
-+ return 0;
-
- if (card->sw_caps.hs_max_dtr == 0)
-- return MMC_ERR_NONE;
-+ return 0;
-
-- err = MMC_ERR_FAILED;
-+ err = -EIO;
-
- status = kmalloc(64, GFP_KERNEL);
- if (!status) {
- printk(KERN_ERR "%s: could not allocate a buffer for "
- "switch capabilities.\n", mmc_hostname(card->host));
-- return err;
-+ return -ENOMEM;
- }
-
- err = mmc_sd_switch(card, 1, 0, 1, status);
-- if (err != MMC_ERR_NONE)
-+ if (err)
- goto out;
-
- if ((status[16] & 0xF) != 1) {
-@@ -292,7 +298,7 @@
- unsigned int max_dtr;
-
- BUG_ON(!host);
-- BUG_ON(!host->claimed);
-+ WARN_ON(!host->claimed);
-
- /*
- * Since we're changing the OCR value, we seem to
-@@ -309,23 +315,37 @@
- * block-addressed SDHC cards.
- */
- err = mmc_send_if_cond(host, ocr);
-- if (err == MMC_ERR_NONE)
-+ if (!err)
- ocr |= 1 << 30;
-
- err = mmc_send_app_op_cond(host, ocr, NULL);
-- if (err != MMC_ERR_NONE)
-+ if (err)
- goto err;
-
- /*
-+ * For SPI, enable CRC as appropriate.
-+ */
-+ if (mmc_host_is_spi(host)) {
-+ err = mmc_spi_set_crc(host, use_spi_crc);
-+ if (err)
-+ goto err;
-+ }
-+
-+ /*
- * Fetch CID from card.
- */
-- err = mmc_all_send_cid(host, cid);
-- if (err != MMC_ERR_NONE)
-+ if (mmc_host_is_spi(host))
-+ err = mmc_send_cid(host, cid);
-+ else
-+ err = mmc_all_send_cid(host, cid);
-+ if (err)
- goto err;
-
- if (oldcard) {
-- if (memcmp(cid, oldcard->raw_cid, sizeof(cid)) != 0)
-+ if (memcmp(cid, oldcard->raw_cid, sizeof(cid)) != 0) {
-+ err = -ENOENT;
- goto err;
-+ }
-
- card = oldcard;
- } else {
-@@ -333,32 +353,36 @@
- * Allocate card structure.
- */
- card = mmc_alloc_card(host);
-- if (IS_ERR(card))
-+ if (IS_ERR(card)) {
-+ err = PTR_ERR(card);
- goto err;
-+ }
-
- card->type = MMC_TYPE_SD;
- memcpy(card->raw_cid, cid, sizeof(card->raw_cid));
- }
-
- /*
-- * Set card RCA.
-+ * For native busses: get card RCA and quit open drain mode.
- */
-- err = mmc_send_relative_addr(host, &card->rca);
-- if (err != MMC_ERR_NONE)
-- goto free_card;
-+ if (!mmc_host_is_spi(host)) {
-+ err = mmc_send_relative_addr(host, &card->rca);
-+ if (err)
-+ goto free_card;
-
-- mmc_set_bus_mode(host, MMC_BUSMODE_PUSHPULL);
-+ mmc_set_bus_mode(host, MMC_BUSMODE_PUSHPULL);
-+ }
-
- if (!oldcard) {
- /*
- * Fetch CSD from card.
- */
- err = mmc_send_csd(card, card->raw_csd);
-- if (err != MMC_ERR_NONE)
-+ if (err)
- goto free_card;
-
- err = mmc_decode_csd(card);
-- if (err < 0)
-+ if (err)
- goto free_card;
-
- mmc_decode_cid(card);
-@@ -367,16 +391,18 @@
- /*
- * Select card, as all following commands rely on that.
- */
-- err = mmc_select_card(card);
-- if (err != MMC_ERR_NONE)
-- goto free_card;
-+ if (!mmc_host_is_spi(host)) {
-+ err = mmc_select_card(card);
-+ if (err)
-+ goto free_card;
-+ }
-
- if (!oldcard) {
- /*
- * Fetch SCR from card.
- */
- err = mmc_app_send_scr(card, card->raw_scr);
-- if (err != MMC_ERR_NONE)
-+ if (err)
- goto free_card;
-
- err = mmc_decode_scr(card);
-@@ -387,7 +413,7 @@
- * Fetch switch information from card.
- */
- err = mmc_read_switch(card);
-- if (err != MMC_ERR_NONE)
-+ if (err)
- goto free_card;
- }
-
-@@ -395,7 +421,7 @@
- * Attempt to change to high-speed (if supported)
- */
- err = mmc_switch_hs(card);
-- if (err != MMC_ERR_NONE)
-+ if (err)
- goto free_card;
-
- /*
-@@ -418,7 +444,7 @@
- if ((host->caps & MMC_CAP_4_BIT_DATA) &&
- (card->scr.bus_widths & SD_SCR_BUS_WIDTH_4)) {
- err = mmc_app_set_bus_width(card, MMC_BUS_WIDTH_4);
-- if (err != MMC_ERR_NONE)
-+ if (err)
- goto free_card;
-
- mmc_set_bus_width(host, MMC_BUS_WIDTH_4);
-@@ -442,14 +468,14 @@
- if (!oldcard)
- host->card = card;
-
-- return MMC_ERR_NONE;
-+ return 0;
-
- free_card:
- if (!oldcard)
- mmc_remove_card(card);
- err:
-
-- return MMC_ERR_FAILED;
-+ return err;
- }
-
- /*
-@@ -483,7 +509,7 @@
-
- mmc_release_host(host);
-
-- if (err != MMC_ERR_NONE) {
-+ if (err) {
- mmc_sd_remove(host);
-
- mmc_claim_host(host);
-@@ -552,7 +578,8 @@
- BUG_ON(!host->card);
-
- mmc_claim_host(host);
-- mmc_deselect_cards(host);
-+ if (!mmc_host_is_spi(host))
-+ mmc_deselect_cards(host);
- host->card->state &= ~MMC_STATE_HIGHSPEED;
- mmc_release_host(host);
- }
-@@ -574,7 +601,7 @@
- err = mmc_sd_init_card(host, host->ocr, host->card);
- mmc_release_host(host);
-
-- if (err != MMC_ERR_NONE) {
-+ if (err) {
- mmc_sd_remove(host);
-
- mmc_claim_host(host);
-@@ -608,11 +635,22 @@
- int err;
-
- BUG_ON(!host);
-- BUG_ON(!host->claimed);
-+ WARN_ON(!host->claimed);
-
- mmc_attach_bus(host, &mmc_sd_ops);
-
- /*
-+ * We need to get OCR a different way for SPI.
-+ */
-+ if (mmc_host_is_spi(host)) {
-+ mmc_go_idle(host);
-+
-+ err = mmc_spi_read_ocr(host, 0, &ocr);
-+ if (err)
-+ goto err;
-+ }
-+
-+ /*
- * Sanity check the voltages that the card claims to
- * support.
- */
-@@ -644,7 +682,7 @@
- * Detect and init the card.
- */
- err = mmc_sd_init_card(host, host->ocr, NULL);
-- if (err != MMC_ERR_NONE)
-+ if (err)
- goto err;
-
- mmc_release_host(host);
-@@ -666,6 +704,6 @@
- printk(KERN_ERR "%s: error %d whilst initialising SD card\n",
- mmc_hostname(host), err);
-
-- return 0;
-+ return err;
- }
-
---- a/drivers/mmc/core/sd_ops.c
-+++ b/drivers/mmc/core/sd_ops.c
-@@ -10,7 +10,6 @@
- */
-
- #include <linux/types.h>
--#include <asm/scatterlist.h>
- #include <linux/scatterlist.h>
-
- #include <linux/mmc/host.h>
-@@ -33,21 +32,21 @@
-
- if (card) {
- cmd.arg = card->rca << 16;
-- cmd.flags = MMC_RSP_R1 | MMC_CMD_AC;
-+ cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_AC;
- } else {
- cmd.arg = 0;
-- cmd.flags = MMC_RSP_R1 | MMC_CMD_BCR;
-+ cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_BCR;
- }
-
- err = mmc_wait_for_cmd(host, &cmd, 0);
-- if (err != MMC_ERR_NONE)
-+ if (err)
- return err;
-
- /* Check that card supported application commands */
-- if (!(cmd.resp[0] & R1_APP_CMD))
-- return MMC_ERR_FAILED;
-+ if (!mmc_host_is_spi(host) && !(cmd.resp[0] & R1_APP_CMD))
-+ return -EOPNOTSUPP;
-
-- return MMC_ERR_NONE;
-+ return 0;
- }
-
- /**
-@@ -73,7 +72,7 @@
- BUG_ON(!cmd);
- BUG_ON(retries < 0);
-
-- err = MMC_ERR_INVALID;
-+ err = -EIO;
-
- /*
- * We have to resend MMC_APP_CMD for each attempt so
-@@ -83,8 +82,14 @@
- memset(&mrq, 0, sizeof(struct mmc_request));
-
- err = mmc_app_cmd(host, card);
-- if (err != MMC_ERR_NONE)
-+ if (err) {
-+ /* no point in retrying; no APP commands allowed */
-+ if (mmc_host_is_spi(host)) {
-+ if (cmd->resp[0] & R1_SPI_ILLEGAL_COMMAND)
-+ break;
-+ }
- continue;
-+ }
-
- memset(&mrq, 0, sizeof(struct mmc_request));
-
-@@ -97,8 +102,14 @@
- mmc_wait_for_req(host, &mrq);
-
- err = cmd->error;
-- if (cmd->error == MMC_ERR_NONE)
-+ if (!cmd->error)
- break;
-+
-+ /* no point in retrying illegal APP commands */
-+ if (mmc_host_is_spi(host)) {
-+ if (cmd->resp[0] & R1_SPI_ILLEGAL_COMMAND)
-+ break;
-+ }
- }
-
- return err;
-@@ -127,14 +138,14 @@
- cmd.arg = SD_BUS_WIDTH_4;
- break;
- default:
-- return MMC_ERR_INVALID;
-+ return -EINVAL;
- }
-
- err = mmc_wait_for_app_cmd(card->host, card, &cmd, MMC_CMD_RETRIES);
-- if (err != MMC_ERR_NONE)
-+ if (err)
- return err;
-
-- return MMC_ERR_NONE;
-+ return 0;
- }
-
- int mmc_send_app_op_cond(struct mmc_host *host, u32 ocr, u32 *rocr)
-@@ -147,23 +158,36 @@
- memset(&cmd, 0, sizeof(struct mmc_command));
-
- cmd.opcode = SD_APP_OP_COND;
-- cmd.arg = ocr;
-- cmd.flags = MMC_RSP_R3 | MMC_CMD_BCR;
-+ if (mmc_host_is_spi(host))
-+ cmd.arg = ocr & (1 << 30); /* SPI only defines one bit */
-+ else
-+ cmd.arg = ocr;
-+ cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R3 | MMC_CMD_BCR;
-
- for (i = 100; i; i--) {
- err = mmc_wait_for_app_cmd(host, NULL, &cmd, MMC_CMD_RETRIES);
-- if (err != MMC_ERR_NONE)
-+ if (err)
- break;
-
-- if (cmd.resp[0] & MMC_CARD_BUSY || ocr == 0)
-+ /* if we're just probing, do a single pass */
-+ if (ocr == 0)
- break;
-
-- err = MMC_ERR_TIMEOUT;
-+ /* otherwise wait until reset completes */
-+ if (mmc_host_is_spi(host)) {
-+ if (!(cmd.resp[0] & R1_SPI_IDLE))
-+ break;
-+ } else {
-+ if (cmd.resp[0] & MMC_CARD_BUSY)
-+ break;
-+ }
-+
-+ err = -ETIMEDOUT;
-
- mmc_delay(10);
- }
-
-- if (rocr)
-+ if (rocr && !mmc_host_is_spi(host))
- *rocr = cmd.resp[0];
-
- return err;
-@@ -174,6 +198,7 @@
- struct mmc_command cmd;
- int err;
- static const u8 test_pattern = 0xAA;
-+ u8 result_pattern;
-
- /*
- * To support SD 2.0 cards, we must always invoke SD_SEND_IF_COND
-@@ -182,16 +207,21 @@
- */
- cmd.opcode = SD_SEND_IF_COND;
- cmd.arg = ((ocr & 0xFF8000) != 0) << 8 | test_pattern;
-- cmd.flags = MMC_RSP_R7 | MMC_CMD_BCR;
-+ cmd.flags = MMC_RSP_SPI_R7 | MMC_RSP_R7 | MMC_CMD_BCR;
-
- err = mmc_wait_for_cmd(host, &cmd, 0);
-- if (err != MMC_ERR_NONE)
-+ if (err)
- return err;
-
-- if ((cmd.resp[0] & 0xFF) != test_pattern)
-- return MMC_ERR_FAILED;
-+ if (mmc_host_is_spi(host))
-+ result_pattern = cmd.resp[1] & 0xFF;
-+ else
-+ result_pattern = cmd.resp[0] & 0xFF;
-+
-+ if (result_pattern != test_pattern)
-+ return -EIO;
-
-- return MMC_ERR_NONE;
-+ return 0;
- }
-
- int mmc_send_relative_addr(struct mmc_host *host, unsigned int *rca)
-@@ -209,12 +239,12 @@
- cmd.flags = MMC_RSP_R6 | MMC_CMD_BCR;
-
- err = mmc_wait_for_cmd(host, &cmd, MMC_CMD_RETRIES);
-- if (err != MMC_ERR_NONE)
-+ if (err)
- return err;
-
- *rca = cmd.resp[0] >> 16;
-
-- return MMC_ERR_NONE;
-+ return 0;
- }
-
- int mmc_app_send_scr(struct mmc_card *card, u32 *scr)
-@@ -229,8 +259,10 @@
- BUG_ON(!card->host);
- BUG_ON(!scr);
-
-+ /* NOTE: caller guarantees scr is heap-allocated */
-+
- err = mmc_app_cmd(card->host, card);
-- if (err != MMC_ERR_NONE)
-+ if (err)
- return err;
-
- memset(&mrq, 0, sizeof(struct mmc_request));
-@@ -242,7 +274,7 @@
-
- cmd.opcode = SD_APP_SEND_SCR;
- cmd.arg = 0;
-- cmd.flags = MMC_RSP_R1 | MMC_CMD_ADTC;
-+ cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_ADTC;
-
- data.blksz = 8;
- data.blocks = 1;
-@@ -252,19 +284,19 @@
-
- sg_init_one(&sg, scr, 8);
-
-- mmc_set_data_timeout(&data, card, 0);
-+ mmc_set_data_timeout(&data, card);
-
- mmc_wait_for_req(card->host, &mrq);
-
-- if (cmd.error != MMC_ERR_NONE)
-+ if (cmd.error)
- return cmd.error;
-- if (data.error != MMC_ERR_NONE)
-+ if (data.error)
- return data.error;
-
-- scr[0] = ntohl(scr[0]);
-- scr[1] = ntohl(scr[1]);
-+ scr[0] = be32_to_cpu(scr[0]);
-+ scr[1] = be32_to_cpu(scr[1]);
-
-- return MMC_ERR_NONE;
-+ return 0;
- }
-
- int mmc_sd_switch(struct mmc_card *card, int mode, int group,
-@@ -278,6 +310,8 @@
- BUG_ON(!card);
- BUG_ON(!card->host);
-
-+ /* NOTE: caller guarantees resp is heap-allocated */
-+
- mode = !!mode;
- value &= 0xF;
-
-@@ -292,7 +326,7 @@
- cmd.arg = mode << 31 | 0x00FFFFFF;
- cmd.arg &= ~(0xF << (group * 4));
- cmd.arg |= value << (group * 4);
-- cmd.flags = MMC_RSP_R1 | MMC_CMD_ADTC;
-+ cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_ADTC;
-
- data.blksz = 64;
- data.blocks = 1;
-@@ -302,15 +336,15 @@
-
- sg_init_one(&sg, resp, 64);
-
-- mmc_set_data_timeout(&data, card, 0);
-+ mmc_set_data_timeout(&data, card);
-
- mmc_wait_for_req(card->host, &mrq);
-
-- if (cmd.error != MMC_ERR_NONE)
-+ if (cmd.error)
- return cmd.error;
-- if (data.error != MMC_ERR_NONE)
-+ if (data.error)
- return data.error;
-
-- return MMC_ERR_NONE;
-+ return 0;
- }
-
---- /dev/null
-+++ b/drivers/mmc/core/sdio.c
-@@ -0,0 +1,395 @@
-+/*
-+ * linux/drivers/mmc/sdio.c
-+ *
-+ * Copyright 2006-2007 Pierre Ossman
-+ *
-+ * 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.
-+ */
-+
-+#include <linux/err.h>
-+
-+#include <linux/mmc/host.h>
-+#include <linux/mmc/card.h>
-+#include <linux/mmc/sdio.h>
-+#include <linux/mmc/sdio_func.h>
-+
-+#include "core.h"
-+#include "bus.h"
-+#include "sdio_bus.h"
-+#include "mmc_ops.h"
-+#include "sd_ops.h"
-+#include "sdio_ops.h"
-+#include "sdio_cis.h"
-+
-+static int sdio_read_fbr(struct sdio_func *func)
-+{
-+ int ret;
-+ unsigned char data;
-+
-+ ret = mmc_io_rw_direct(func->card, 0, 0,
-+ SDIO_FBR_BASE(func->num) + SDIO_FBR_STD_IF, 0, &data);
-+ if (ret)
-+ goto out;
-+
-+ data &= 0x0f;
-+
-+ if (data == 0x0f) {
-+ ret = mmc_io_rw_direct(func->card, 0, 0,
-+ SDIO_FBR_BASE(func->num) + SDIO_FBR_STD_IF_EXT, 0, &data);
-+ if (ret)
-+ goto out;
-+ }
-+
-+ func->class = data;
-+
-+out:
-+ return ret;
-+}
-+
-+static int sdio_init_func(struct mmc_card *card, unsigned int fn)
-+{
-+ int ret;
-+ struct sdio_func *func;
-+
-+ BUG_ON(fn > SDIO_MAX_FUNCS);
-+
-+ func = sdio_alloc_func(card);
-+ if (IS_ERR(func))
-+ return PTR_ERR(func);
-+
-+ func->num = fn;
-+
-+ ret = sdio_read_fbr(func);
-+ if (ret)
-+ goto fail;
-+
-+ ret = sdio_read_func_cis(func);
-+ if (ret)
-+ goto fail;
-+
-+ card->sdio_func[fn - 1] = func;
-+
-+ return 0;
-+
-+fail:
-+ /*
-+ * It is okay to remove the function here even though we hold
-+ * the host lock as we haven't registered the device yet.
-+ */
-+ sdio_remove_func(func);
-+ return ret;
-+}
-+
-+static int sdio_read_cccr(struct mmc_card *card)
-+{
-+ int ret;
-+ int cccr_vsn;
-+ unsigned char data;
-+
-+ memset(&card->cccr, 0, sizeof(struct sdio_cccr));
-+
-+ ret = mmc_io_rw_direct(card, 0, 0, SDIO_CCCR_CCCR, 0, &data);
-+ if (ret)
-+ goto out;
-+
-+ cccr_vsn = data & 0x0f;
-+
-+ if (cccr_vsn > SDIO_CCCR_REV_1_20) {
-+ printk(KERN_ERR "%s: unrecognised CCCR structure version %d\n",
-+ mmc_hostname(card->host), cccr_vsn);
-+ return -EINVAL;
-+ }
-+
-+ card->cccr.sdio_vsn = (data & 0xf0) >> 4;
-+
-+ ret = mmc_io_rw_direct(card, 0, 0, SDIO_CCCR_CAPS, 0, &data);
-+ if (ret)
-+ goto out;
-+
-+ if (data & SDIO_CCCR_CAP_SMB)
-+ card->cccr.multi_block = 1;
-+ if (data & SDIO_CCCR_CAP_LSC)
-+ card->cccr.low_speed = 1;
-+ if (data & SDIO_CCCR_CAP_4BLS)
-+ card->cccr.wide_bus = 1;
-+
-+ if (cccr_vsn >= SDIO_CCCR_REV_1_10) {
-+ ret = mmc_io_rw_direct(card, 0, 0, SDIO_CCCR_POWER, 0, &data);
-+ if (ret)
-+ goto out;
-+
-+ if (data & SDIO_POWER_SMPC)
-+ card->cccr.high_power = 1;
-+ }
-+
-+ if (cccr_vsn >= SDIO_CCCR_REV_1_20) {
-+ ret = mmc_io_rw_direct(card, 0, 0, SDIO_CCCR_SPEED, 0, &data);
-+ if (ret)
-+ goto out;
-+
-+ if (data & SDIO_SPEED_SHS)
-+ card->cccr.high_speed = 1;
-+ }
-+
-+out:
-+ return ret;
-+}
-+
-+static int sdio_enable_wide(struct mmc_card *card)
-+{
-+ int ret;
-+ u8 ctrl;
-+
-+ if (!(card->host->caps & MMC_CAP_4_BIT_DATA))
-+ return 0;
-+
-+ if (card->cccr.low_speed && !card->cccr.wide_bus)
-+ return 0;
-+
-+ ret = mmc_io_rw_direct(card, 0, 0, SDIO_CCCR_IF, 0, &ctrl);
-+ if (ret)
-+ return ret;
-+
-+ ctrl |= SDIO_BUS_WIDTH_4BIT;
-+
-+ ret = mmc_io_rw_direct(card, 1, 0, SDIO_CCCR_IF, ctrl, NULL);
-+ if (ret)
-+ return ret;
-+
-+ mmc_set_bus_width(card->host, MMC_BUS_WIDTH_4);
-+
-+ return 0;
-+}
-+
-+/*
-+ * Host is being removed. Free up the current card.
-+ */
-+static void mmc_sdio_remove(struct mmc_host *host)
-+{
-+ int i;
-+
-+ BUG_ON(!host);
-+ BUG_ON(!host->card);
-+
-+ for (i = 0;i < host->card->sdio_funcs;i++) {
-+ if (host->card->sdio_func[i]) {
-+ sdio_remove_func(host->card->sdio_func[i]);
-+ host->card->sdio_func[i] = NULL;
-+ }
-+ }
-+
-+ mmc_remove_card(host->card);
-+ host->card = NULL;
-+}
-+
-+/*
-+ * Card detection callback from host.
-+ */
-+static void mmc_sdio_detect(struct mmc_host *host)
-+{
-+ int err;
-+
-+ BUG_ON(!host);
-+ BUG_ON(!host->card);
-+
-+ mmc_claim_host(host);
-+
-+ /*
-+ * Just check if our card has been removed.
-+ */
-+ err = mmc_select_card(host->card);
-+
-+ mmc_release_host(host);
-+
-+ if (err) {
-+ mmc_sdio_remove(host);
-+
-+ mmc_claim_host(host);
-+ mmc_detach_bus(host);
-+ mmc_release_host(host);
-+ }
-+}
-+
-+
-+static const struct mmc_bus_ops mmc_sdio_ops = {
-+ .remove = mmc_sdio_remove,
-+ .detect = mmc_sdio_detect,
-+};
-+
-+
-+/*
-+ * Starting point for SDIO card init.
-+ */
-+int mmc_attach_sdio(struct mmc_host *host, u32 ocr)
-+{
-+ int err;
-+ int i, funcs;
-+ struct mmc_card *card;
-+
-+ BUG_ON(!host);
-+ WARN_ON(!host->claimed);
-+
-+ mmc_attach_bus(host, &mmc_sdio_ops);
-+
-+ /*
-+ * Sanity check the voltages that the card claims to
-+ * support.
-+ */
-+ if (ocr & 0x7F) {
-+ printk(KERN_WARNING "%s: card claims to support voltages "
-+ "below the defined range. These will be ignored.\n",
-+ mmc_hostname(host));
-+ ocr &= ~0x7F;
-+ }
-+
-+ if (ocr & MMC_VDD_165_195) {
-+ printk(KERN_WARNING "%s: SDIO card claims to support the "
-+ "incompletely defined 'low voltage range'. This "
-+ "will be ignored.\n", mmc_hostname(host));
-+ ocr &= ~MMC_VDD_165_195;
-+ }
-+
-+ host->ocr = mmc_select_voltage(host, ocr);
-+
-+ /*
-+ * Can we support the voltage(s) of the card(s)?
-+ */
-+ if (!host->ocr) {
-+ err = -EINVAL;
-+ goto err;
-+ }
-+
-+ /*
-+ * Inform the card of the voltage
-+ */
-+ err = mmc_send_io_op_cond(host, host->ocr, &ocr);
-+ if (err)
-+ goto err;
-+
-+ /*
-+ * For SPI, enable CRC as appropriate.
-+ */
-+ if (mmc_host_is_spi(host)) {
-+ err = mmc_spi_set_crc(host, use_spi_crc);
-+ if (err)
-+ goto err;
-+ }
-+
-+ /*
-+ * The number of functions on the card is encoded inside
-+ * the ocr.
-+ */
-+ funcs = (ocr & 0x70000000) >> 28;
-+
-+ /*
-+ * Allocate card structure.
-+ */
-+ card = mmc_alloc_card(host);
-+ if (IS_ERR(card)) {
-+ err = PTR_ERR(card);
-+ goto err;
-+ }
-+
-+ card->type = MMC_TYPE_SDIO;
-+ card->sdio_funcs = funcs;
-+
-+ host->card = card;
-+
-+ /*
-+ * For native busses: set card RCA and quit open drain mode.
-+ */
-+ if (!mmc_host_is_spi(host)) {
-+ err = mmc_send_relative_addr(host, &card->rca);
-+ if (err)
-+ goto remove;
-+
-+ mmc_set_bus_mode(host, MMC_BUSMODE_PUSHPULL);
-+ }
-+
-+ /*
-+ * Select card, as all following commands rely on that.
-+ */
-+ if (!mmc_host_is_spi(host)) {
-+ err = mmc_select_card(card);
-+ if (err)
-+ goto remove;
-+ }
-+
-+ /*
-+ * Read the common registers.
-+ */
-+ err = sdio_read_cccr(card);
-+ if (err)
-+ goto remove;
-+
-+ /*
-+ * Read the common CIS tuples.
-+ */
-+ err = sdio_read_common_cis(card);
-+ if (err)
-+ goto remove;
-+
-+ /*
-+ * No support for high-speed yet, so just set
-+ * the card's maximum speed.
-+ */
-+ mmc_set_clock(host, card->cis.max_dtr);
-+
-+ /*
-+ * Switch to wider bus (if supported).
-+ */
-+ err = sdio_enable_wide(card);
-+ if (err)
-+ goto remove;
-+
-+ /*
-+ * Initialize (but don't add) all present functions.
-+ */
-+ for (i = 0;i < funcs;i++) {
-+ err = sdio_init_func(host->card, i + 1);
-+ if (err)
-+ goto remove;
-+ }
-+
-+ mmc_release_host(host);
-+
-+ /*
-+ * First add the card to the driver model...
-+ */
-+ err = mmc_add_card(host->card);
-+ if (err)
-+ goto remove_added;
-+
-+ /*
-+ * ...then the SDIO functions.
-+ */
-+ for (i = 0;i < funcs;i++) {
-+ err = sdio_add_func(host->card->sdio_func[i]);
-+ if (err)
-+ goto remove_added;
-+ }
-+
-+ return 0;
-+
-+
-+remove_added:
-+ /* Remove without lock if the device has been added. */
-+ mmc_sdio_remove(host);
-+ mmc_claim_host(host);
-+remove:
-+ /* And with lock if it hasn't been added. */
-+ if (host->card)
-+ mmc_sdio_remove(host);
-+err:
-+ mmc_detach_bus(host);
-+ mmc_release_host(host);
-+
-+ printk(KERN_ERR "%s: error %d whilst initialising SDIO card\n",
-+ mmc_hostname(host), err);
-+
-+ return err;
-+}
-+
---- /dev/null
-+++ b/drivers/mmc/core/sdio_bus.c
-@@ -0,0 +1,265 @@
-+/*
-+ * linux/drivers/mmc/core/sdio_bus.c
-+ *
-+ * Copyright 2007 Pierre Ossman
-+ *
-+ * 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.
-+ *
-+ * SDIO function driver model
-+ */
-+
-+#include <linux/device.h>
-+#include <linux/err.h>
-+
-+#include <linux/mmc/card.h>
-+#include <linux/mmc/sdio_func.h>
-+
-+#include "sdio_cis.h"
-+#include "sdio_bus.h"
-+
-+#define dev_to_sdio_func(d) container_of(d, struct sdio_func, dev)
-+#define to_sdio_driver(d) container_of(d, struct sdio_driver, drv)
-+
-+/* show configuration fields */
-+#define sdio_config_attr(field, format_string) \
-+static ssize_t \
-+field##_show(struct device *dev, struct device_attribute *attr, char *buf) \
-+{ \
-+ struct sdio_func *func; \
-+ \
-+ func = dev_to_sdio_func (dev); \
-+ return sprintf (buf, format_string, func->field); \
-+}
-+
-+sdio_config_attr(class, "0x%02x\n");
-+sdio_config_attr(vendor, "0x%04x\n");
-+sdio_config_attr(device, "0x%04x\n");
-+
-+static ssize_t modalias_show(struct device *dev, struct device_attribute *attr, char *buf)
-+{
-+ struct sdio_func *func = dev_to_sdio_func (dev);
-+
-+ return sprintf(buf, "sdio:c%02Xv%04Xd%04X\n",
-+ func->class, func->vendor, func->device);
-+}
-+
-+static struct device_attribute sdio_dev_attrs[] = {
-+ __ATTR_RO(class),
-+ __ATTR_RO(vendor),
-+ __ATTR_RO(device),
-+ __ATTR_RO(modalias),
-+ __ATTR_NULL,
-+};
-+
-+static const struct sdio_device_id *sdio_match_one(struct sdio_func *func,
-+ const struct sdio_device_id *id)
-+{
-+ if (id->class != (__u8)SDIO_ANY_ID && id->class != func->class)
-+ return NULL;
-+ if (id->vendor != (__u16)SDIO_ANY_ID && id->vendor != func->vendor)
-+ return NULL;
-+ if (id->device != (__u16)SDIO_ANY_ID && id->device != func->device)
-+ return NULL;
-+ return id;
-+}
-+
-+static const struct sdio_device_id *sdio_match_device(struct sdio_func *func,
-+ struct sdio_driver *sdrv)
-+{
-+ const struct sdio_device_id *ids;
-+
-+ ids = sdrv->id_table;
-+
-+ if (ids) {
-+ while (ids->class || ids->vendor || ids->device) {
-+ if (sdio_match_one(func, ids))
-+ return ids;
-+ ids++;
-+ }
-+ }
-+
-+ return NULL;
-+}
-+
-+static int sdio_bus_match(struct device *dev, struct device_driver *drv)
-+{
-+ struct sdio_func *func = dev_to_sdio_func(dev);
-+ struct sdio_driver *sdrv = to_sdio_driver(drv);
-+
-+ if (sdio_match_device(func, sdrv))
-+ return 1;
-+
-+ return 0;
-+}
-+
-+static int
-+sdio_bus_uevent(struct device *dev, char **envp,
-+ int num_envp, char *buffer, int buffer_size)
-+{
-+ struct sdio_func *func = dev_to_sdio_func(dev);
-+ int i = 0, len = 0;
-+
-+ if (add_uevent_var(envp, num_envp, &i, buffer, buffer_size, &len,
-+ "SDIO_CLASS=%02X", func->class))
-+ return -ENOMEM;
-+
-+ if (add_uevent_var(envp, num_envp, &i, buffer, buffer_size, &len,
-+ "SDIO_ID=%04X:%04X", func->vendor, func->device))
-+ return -ENOMEM;
-+
-+ if (add_uevent_var(envp, num_envp, &i, buffer, buffer_size, &len,
-+ "MODALIAS=sdio:c%02Xv%04Xd%04X",
-+ func->class, func->vendor, func->device))
-+ return -ENOMEM;
-+
-+ return 0;
-+}
-+
-+static int sdio_bus_probe(struct device *dev)
-+{
-+ struct sdio_driver *drv = to_sdio_driver(dev->driver);
-+ struct sdio_func *func = dev_to_sdio_func(dev);
-+ const struct sdio_device_id *id;
-+ int ret;
-+
-+ id = sdio_match_device(func, drv);
-+ if (!id)
-+ return -ENODEV;
-+
-+ /* Set the default block size so the driver is sure it's something
-+ * sensible. */
-+ sdio_claim_host(func);
-+ ret = sdio_set_block_size(func, 0);
-+ sdio_release_host(func);
-+ if (ret)
-+ return ret;
-+
-+ return drv->probe(func, id);
-+}
-+
-+static int sdio_bus_remove(struct device *dev)
-+{
-+ struct sdio_driver *drv = to_sdio_driver(dev->driver);
-+ struct sdio_func *func = dev_to_sdio_func(dev);
-+
-+ drv->remove(func);
-+
-+ if (func->irq_handler) {
-+ printk(KERN_WARNING "WARNING: driver %s did not remove "
-+ "its interrupt handler!\n", drv->name);
-+ sdio_claim_host(func);
-+ sdio_release_irq(func);
-+ sdio_release_host(func);
-+ }
-+
-+ return 0;
-+}
-+
-+static struct bus_type sdio_bus_type = {
-+ .name = "sdio",
-+ .dev_attrs = sdio_dev_attrs,
-+ .match = sdio_bus_match,
-+ .uevent = sdio_bus_uevent,
-+ .probe = sdio_bus_probe,
-+ .remove = sdio_bus_remove,
-+};
-+
-+int sdio_register_bus(void)
-+{
-+ return bus_register(&sdio_bus_type);
-+}
-+
-+void sdio_unregister_bus(void)
-+{
-+ bus_unregister(&sdio_bus_type);
-+}
-+
-+/**
-+ * sdio_register_driver - register a function driver
-+ * @drv: SDIO function driver
-+ */
-+int sdio_register_driver(struct sdio_driver *drv)
-+{
-+ drv->drv.name = drv->name;
-+ drv->drv.bus = &sdio_bus_type;
-+ return driver_register(&drv->drv);
-+}
-+EXPORT_SYMBOL_GPL(sdio_register_driver);
-+
-+/**
-+ * sdio_unregister_driver - unregister a function driver
-+ * @drv: SDIO function driver
-+ */
-+void sdio_unregister_driver(struct sdio_driver *drv)
-+{
-+ drv->drv.bus = &sdio_bus_type;
-+ driver_unregister(&drv->drv);
-+}
-+EXPORT_SYMBOL_GPL(sdio_unregister_driver);
-+
-+static void sdio_release_func(struct device *dev)
-+{
-+ struct sdio_func *func = dev_to_sdio_func(dev);
-+
-+ sdio_free_func_cis(func);
-+
-+ if (func->info)
-+ kfree(func->info);
-+
-+ kfree(func);
-+}
-+
-+/*
-+ * Allocate and initialise a new SDIO function structure.
-+ */
-+struct sdio_func *sdio_alloc_func(struct mmc_card *card)
-+{
-+ struct sdio_func *func;
-+
-+ func = kzalloc(sizeof(struct sdio_func), GFP_KERNEL);
-+ if (!func)
-+ return ERR_PTR(-ENOMEM);
-+
-+ func->card = card;
-+
-+ device_initialize(&func->dev);
-+
-+ func->dev.parent = &card->dev;
-+ func->dev.bus = &sdio_bus_type;
-+ func->dev.release = sdio_release_func;
-+
-+ return func;
-+}
-+
-+/*
-+ * Register a new SDIO function with the driver model.
-+ */
-+int sdio_add_func(struct sdio_func *func)
-+{
-+ int ret;
-+
-+ snprintf(func->dev.bus_id, sizeof(func->dev.bus_id),
-+ "%s:%d", mmc_card_id(func->card), func->num);
-+
-+ ret = device_add(&func->dev);
-+ if (ret == 0)
-+ sdio_func_set_present(func);
-+
-+ return ret;
-+}
-+
-+/*
-+ * Unregister a SDIO function with the driver model, and
-+ * (eventually) free it.
-+ */
-+void sdio_remove_func(struct sdio_func *func)
-+{
-+ if (sdio_func_present(func))
-+ device_del(&func->dev);
-+
-+ put_device(&func->dev);
-+}
-+
---- /dev/null
-+++ b/drivers/mmc/core/sdio_bus.h
-@@ -0,0 +1,22 @@
-+/*
-+ * linux/drivers/mmc/core/sdio_bus.h
-+ *
-+ * Copyright 2007 Pierre Ossman
-+ *
-+ * 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.
-+ */
-+#ifndef _MMC_CORE_SDIO_BUS_H
-+#define _MMC_CORE_SDIO_BUS_H
-+
-+struct sdio_func *sdio_alloc_func(struct mmc_card *card);
-+int sdio_add_func(struct sdio_func *func);
-+void sdio_remove_func(struct sdio_func *func);
-+
-+int sdio_register_bus(void);
-+void sdio_unregister_bus(void);
-+
-+#endif
-+
---- /dev/null
-+++ b/drivers/mmc/core/sdio_cis.c
-@@ -0,0 +1,346 @@
-+/*
-+ * linux/drivers/mmc/core/sdio_cis.c
-+ *
-+ * Author: Nicolas Pitre
-+ * Created: June 11, 2007
-+ * Copyright: MontaVista Software Inc.
-+ *
-+ * Copyright 2007 Pierre Ossman
-+ *
-+ * 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.
-+ */
-+
-+#include <linux/kernel.h>
-+
-+#include <linux/mmc/host.h>
-+#include <linux/mmc/card.h>
-+#include <linux/mmc/sdio.h>
-+#include <linux/mmc/sdio_func.h>
-+
-+#include "sdio_cis.h"
-+#include "sdio_ops.h"
-+
-+static int cistpl_vers_1(struct mmc_card *card, struct sdio_func *func,
-+ const unsigned char *buf, unsigned size)
-+{
-+ unsigned i, nr_strings;
-+ char **buffer, *string;
-+
-+ buf += 2;
-+ size -= 2;
-+
-+ nr_strings = 0;
-+ for (i = 0; i < size; i++) {
-+ if (buf[i] == 0xff)
-+ break;
-+ if (buf[i] == 0)
-+ nr_strings++;
-+ }
-+
-+ if (buf[i-1] != '\0') {
-+ printk(KERN_WARNING "SDIO: ignoring broken CISTPL_VERS_1\n");
-+ return 0;
-+ }
-+
-+ size = i;
-+
-+ buffer = kzalloc(sizeof(char*) * nr_strings + size, GFP_KERNEL);
-+ if (!buffer)
-+ return -ENOMEM;
-+
-+ string = (char*)(buffer + nr_strings);
-+
-+ for (i = 0; i < nr_strings; i++) {
-+ buffer[i] = string;
-+ strcpy(string, buf);
-+ string += strlen(string) + 1;
-+ buf += strlen(buf) + 1;
-+ }
-+
-+ if (func) {
-+ func->num_info = nr_strings;
-+ func->info = (const char**)buffer;
-+ } else {
-+ card->num_info = nr_strings;
-+ card->info = (const char**)buffer;
-+ }
-+
-+ return 0;
-+}
-+
-+static int cistpl_manfid(struct mmc_card *card, struct sdio_func *func,
-+ const unsigned char *buf, unsigned size)
-+{
-+ unsigned int vendor, device;
-+
-+ /* TPLMID_MANF */
-+ vendor = buf[0] | (buf[1] << 8);
-+
-+ /* TPLMID_CARD */
-+ device = buf[2] | (buf[3] << 8);
-+
-+ if (func) {
-+ func->vendor = vendor;
-+ func->device = device;
-+ } else {
-+ card->cis.vendor = vendor;
-+ card->cis.device = device;
-+ }
-+
-+ return 0;
-+}
-+
-+static const unsigned char speed_val[16] =
-+ { 0, 10, 12, 13, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 70, 80 };
-+static const unsigned int speed_unit[8] =
-+ { 10000, 100000, 1000000, 10000000, 0, 0, 0, 0 };
-+
-+static int cistpl_funce_common(struct mmc_card *card,
-+ const unsigned char *buf, unsigned size)
-+{
-+ if (size < 0x04 || buf[0] != 0)
-+ return -EINVAL;
-+
-+ /* TPLFE_FN0_BLK_SIZE */
-+ card->cis.blksize = buf[1] | (buf[2] << 8);
-+
-+ /* TPLFE_MAX_TRAN_SPEED */
-+ card->cis.max_dtr = speed_val[(buf[3] >> 3) & 15] *
-+ speed_unit[buf[3] & 7];
-+
-+ return 0;
-+}
-+
-+static int cistpl_funce_func(struct sdio_func *func,
-+ const unsigned char *buf, unsigned size)
-+{
-+ unsigned vsn;
-+ unsigned min_size;
-+
-+ vsn = func->card->cccr.sdio_vsn;
-+ min_size = (vsn == SDIO_SDIO_REV_1_00) ? 28 : 42;
-+
-+ if (size < min_size || buf[0] != 1)
-+ return -EINVAL;
-+
-+ /* TPLFE_MAX_BLK_SIZE */
-+ func->max_blksize = buf[12] | (buf[13] << 8);
-+
-+ return 0;
-+}
-+
-+static int cistpl_funce(struct mmc_card *card, struct sdio_func *func,
-+ const unsigned char *buf, unsigned size)
-+{
-+ int ret;
-+
-+ /*
-+ * There should be two versions of the CISTPL_FUNCE tuple,
-+ * one for the common CIS (function 0) and a version used by
-+ * the individual function's CIS (1-7). Yet, the later has a
-+ * different length depending on the SDIO spec version.
-+ */
-+ if (func)
-+ ret = cistpl_funce_func(func, buf, size);
-+ else
-+ ret = cistpl_funce_common(card, buf, size);
-+
-+ if (ret) {
-+ printk(KERN_ERR "%s: bad CISTPL_FUNCE size %u "
-+ "type %u\n", mmc_hostname(card->host), size, buf[0]);
-+ return ret;
-+ }
-+
-+ return 0;
-+}
-+
-+typedef int (tpl_parse_t)(struct mmc_card *, struct sdio_func *,
-+ const unsigned char *, unsigned);
-+
-+struct cis_tpl {
-+ unsigned char code;
-+ unsigned char min_size;
-+ tpl_parse_t *parse;
-+};
-+
-+static const struct cis_tpl cis_tpl_list[] = {
-+ { 0x15, 3, cistpl_vers_1 },
-+ { 0x20, 4, cistpl_manfid },
-+ { 0x21, 2, /* cistpl_funcid */ },
-+ { 0x22, 0, cistpl_funce },
-+};
-+
-+static int sdio_read_cis(struct mmc_card *card, struct sdio_func *func)
-+{
-+ int ret;
-+ struct sdio_func_tuple *this, **prev;
-+ unsigned i, ptr = 0;
-+
-+ /*
-+ * Note that this works for the common CIS (function number 0) as
-+ * well as a function's CIS * since SDIO_CCCR_CIS and SDIO_FBR_CIS
-+ * have the same offset.
-+ */
-+ for (i = 0; i < 3; i++) {
-+ unsigned char x, fn;
-+
-+ if (func)
-+ fn = func->num;
-+ else
-+ fn = 0;
-+
-+ ret = mmc_io_rw_direct(card, 0, 0,
-+ SDIO_FBR_BASE(fn) + SDIO_FBR_CIS + i, 0, &x);
-+ if (ret)
-+ return ret;
-+ ptr |= x << (i * 8);
-+ }
-+
-+ if (func)
-+ prev = &func->tuples;
-+ else
-+ prev = &card->tuples;
-+
-+ BUG_ON(*prev);
-+
-+ do {
-+ unsigned char tpl_code, tpl_link;
-+
-+ ret = mmc_io_rw_direct(card, 0, 0, ptr++, 0, &tpl_code);
-+ if (ret)
-+ break;
-+
-+ /* 0xff means we're done */
-+ if (tpl_code == 0xff)
-+ break;
-+
-+ ret = mmc_io_rw_direct(card, 0, 0, ptr++, 0, &tpl_link);
-+ if (ret)
-+ break;
-+
-+ this = kmalloc(sizeof(*this) + tpl_link, GFP_KERNEL);
-+ if (!this)
-+ return -ENOMEM;
-+
-+ for (i = 0; i < tpl_link; i++) {
-+ ret = mmc_io_rw_direct(card, 0, 0,
-+ ptr + i, 0, &this->data[i]);
-+ if (ret)
-+ break;
-+ }
-+ if (ret) {
-+ kfree(this);
-+ break;
-+ }
-+
-+ for (i = 0; i < ARRAY_SIZE(cis_tpl_list); i++)
-+ if (cis_tpl_list[i].code == tpl_code)
-+ break;
-+ if (i >= ARRAY_SIZE(cis_tpl_list)) {
-+ /* this tuple is unknown to the core */
-+ this->next = NULL;
-+ this->code = tpl_code;
-+ this->size = tpl_link;
-+ *prev = this;
-+ prev = &this->next;
-+ printk(KERN_DEBUG
-+ "%s: queuing CIS tuple 0x%02x length %u\n",
-+ mmc_hostname(card->host), tpl_code, tpl_link);
-+ } else {
-+ const struct cis_tpl *tpl = cis_tpl_list + i;
-+ if (tpl_link < tpl->min_size) {
-+ printk(KERN_ERR
-+ "%s: bad CIS tuple 0x%02x (length = %u, expected >= %u)\n",
-+ mmc_hostname(card->host),
-+ tpl_code, tpl_link, tpl->min_size);
-+ ret = -EINVAL;
-+ } else if (tpl->parse) {
-+ ret = tpl->parse(card, func,
-+ this->data, tpl_link);
-+ }
-+ kfree(this);
-+ }
-+
-+ ptr += tpl_link;
-+ } while (!ret);
-+
-+ /*
-+ * Link in all unknown tuples found in the common CIS so that
-+ * drivers don't have to go digging in two places.
-+ */
-+ if (func)
-+ *prev = card->tuples;
-+
-+ return ret;
-+}
-+
-+int sdio_read_common_cis(struct mmc_card *card)
-+{
-+ return sdio_read_cis(card, NULL);
-+}
-+
-+void sdio_free_common_cis(struct mmc_card *card)
-+{
-+ struct sdio_func_tuple *tuple, *victim;
-+
-+ tuple = card->tuples;
-+
-+ while (tuple) {
-+ victim = tuple;
-+ tuple = tuple->next;
-+ kfree(victim);
-+ }
-+
-+ card->tuples = NULL;
-+}
-+
-+int sdio_read_func_cis(struct sdio_func *func)
-+{
-+ int ret;
-+
-+ ret = sdio_read_cis(func->card, func);
-+ if (ret)
-+ return ret;
-+
-+ /*
-+ * Since we've linked to tuples in the card structure,
-+ * we must make sure we have a reference to it.
-+ */
-+ get_device(&func->card->dev);
-+
-+ /*
-+ * Vendor/device id is optional for function CIS, so
-+ * copy it from the card structure as needed.
-+ */
-+ if (func->vendor == 0) {
-+ func->vendor = func->card->cis.vendor;
-+ func->device = func->card->cis.device;
-+ }
-+
-+ return 0;
-+}
-+
-+void sdio_free_func_cis(struct sdio_func *func)
-+{
-+ struct sdio_func_tuple *tuple, *victim;
-+
-+ tuple = func->tuples;
-+
-+ while (tuple && tuple != func->card->tuples) {
-+ victim = tuple;
-+ tuple = tuple->next;
-+ kfree(victim);
-+ }
-+
-+ func->tuples = NULL;
-+
-+ /*
-+ * We have now removed the link to the tuples in the
-+ * card structure, so remove the reference.
-+ */
-+ put_device(&func->card->dev);
-+}
-+
---- /dev/null
-+++ b/drivers/mmc/core/sdio_cis.h
-@@ -0,0 +1,23 @@
-+/*
-+ * linux/drivers/mmc/core/sdio_cis.h
-+ *
-+ * Author: Nicolas Pitre
-+ * Created: June 11, 2007
-+ * Copyright: MontaVista Software Inc.
-+ *
-+ * 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.
-+ */
-+
-+#ifndef _MMC_SDIO_CIS_H
-+#define _MMC_SDIO_CIS_H
-+
-+int sdio_read_common_cis(struct mmc_card *card);
-+void sdio_free_common_cis(struct mmc_card *card);
-+
-+int sdio_read_func_cis(struct sdio_func *func);
-+void sdio_free_func_cis(struct sdio_func *func);
-+
-+#endif
---- /dev/null
-+++ b/drivers/mmc/core/sdio_io.c
-@@ -0,0 +1,548 @@
-+/*
-+ * linux/drivers/mmc/core/sdio_io.c
-+ *
-+ * Copyright 2007 Pierre Ossman
-+ *
-+ * 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.
-+ */
-+
-+#include <linux/mmc/host.h>
-+#include <linux/mmc/card.h>
-+#include <linux/mmc/sdio.h>
-+#include <linux/mmc/sdio_func.h>
-+
-+#include "sdio_ops.h"
-+
-+/**
-+ * sdio_claim_host - exclusively claim a bus for a certain SDIO function
-+ * @func: SDIO function that will be accessed
-+ *
-+ * Claim a bus for a set of operations. The SDIO function given
-+ * is used to figure out which bus is relevant.
-+ */
-+void sdio_claim_host(struct sdio_func *func)
-+{
-+ BUG_ON(!func);
-+ BUG_ON(!func->card);
-+
-+ mmc_claim_host(func->card->host);
-+}
-+EXPORT_SYMBOL_GPL(sdio_claim_host);
-+
-+/**
-+ * sdio_release_host - release a bus for a certain SDIO function
-+ * @func: SDIO function that was accessed
-+ *
-+ * Release a bus, allowing others to claim the bus for their
-+ * operations.
-+ */
-+void sdio_release_host(struct sdio_func *func)
-+{
-+ BUG_ON(!func);
-+ BUG_ON(!func->card);
-+
-+ mmc_release_host(func->card->host);
-+}
-+EXPORT_SYMBOL_GPL(sdio_release_host);
-+
-+/**
-+ * sdio_enable_func - enables a SDIO function for usage
-+ * @func: SDIO function to enable
-+ *
-+ * Powers up and activates a SDIO function so that register
-+ * access is possible.
-+ */
-+int sdio_enable_func(struct sdio_func *func)
-+{
-+ int ret;
-+ unsigned char reg;
-+ unsigned long timeout;
-+
-+ BUG_ON(!func);
-+ BUG_ON(!func->card);
-+
-+ pr_debug("SDIO: Enabling device %s...\n", sdio_func_id(func));
-+
-+ ret = mmc_io_rw_direct(func->card, 0, 0, SDIO_CCCR_IOEx, 0, ®);
-+ if (ret)
-+ goto err;
-+
-+ reg |= 1 << func->num;
-+
-+ ret = mmc_io_rw_direct(func->card, 1, 0, SDIO_CCCR_IOEx, reg, NULL);
-+ if (ret)
-+ goto err;
-+
-+ /*
-+ * FIXME: This should timeout based on information in the CIS,
-+ * but we don't have card to parse that yet.
-+ */
-+ timeout = jiffies + HZ;
-+
-+ while (1) {
-+ ret = mmc_io_rw_direct(func->card, 0, 0, SDIO_CCCR_IORx, 0, ®);
-+ if (ret)
-+ goto err;
-+ if (reg & (1 << func->num))
-+ break;
-+ ret = -ETIME;
-+ if (time_after(jiffies, timeout))
-+ goto err;
-+ }
-+
-+ pr_debug("SDIO: Enabled device %s\n", sdio_func_id(func));
-+
-+ return 0;
-+
-+err:
-+ pr_debug("SDIO: Failed to enable device %s\n", sdio_func_id(func));
-+ return ret;
-+}
-+EXPORT_SYMBOL_GPL(sdio_enable_func);
-+
-+/**
-+ * sdio_disable_func - disable a SDIO function
-+ * @func: SDIO function to disable
-+ *
-+ * Powers down and deactivates a SDIO function. Register access
-+ * to this function will fail until the function is reenabled.
-+ */
-+int sdio_disable_func(struct sdio_func *func)
-+{
-+ int ret;
-+ unsigned char reg;
-+
-+ BUG_ON(!func);
-+ BUG_ON(!func->card);
-+
-+ pr_debug("SDIO: Disabling device %s...\n", sdio_func_id(func));
-+
-+ ret = mmc_io_rw_direct(func->card, 0, 0, SDIO_CCCR_IOEx, 0, ®);
-+ if (ret)
-+ goto err;
-+
-+ reg &= ~(1 << func->num);
-+
-+ ret = mmc_io_rw_direct(func->card, 1, 0, SDIO_CCCR_IOEx, reg, NULL);
-+ if (ret)
-+ goto err;
-+
-+ pr_debug("SDIO: Disabled device %s\n", sdio_func_id(func));
-+
-+ return 0;
-+
-+err:
-+ pr_debug("SDIO: Failed to disable device %s\n", sdio_func_id(func));
-+ return -EIO;
-+}
-+EXPORT_SYMBOL_GPL(sdio_disable_func);
-+
-+/**
-+ * sdio_set_block_size - set the block size of an SDIO function
-+ * @func: SDIO function to change
-+ * @blksz: new block size or 0 to use the default.
-+ *
-+ * The default block size is the largest supported by both the function
-+ * and the host, with a maximum of 512 to ensure that arbitrarily sized
-+ * data transfer use the optimal (least) number of commands.
-+ *
-+ * A driver may call this to override the default block size set by the
-+ * core. This can be used to set a block size greater than the maximum
-+ * that reported by the card; it is the driver's responsibility to ensure
-+ * it uses a value that the card supports.
-+ *
-+ * Returns 0 on success, -EINVAL if the host does not support the
-+ * requested block size, or -EIO (etc.) if one of the resultant FBR block
-+ * size register writes failed.
-+ *
-+ */
-+int sdio_set_block_size(struct sdio_func *func, unsigned blksz)
-+{
-+ int ret;
-+
-+ if (blksz > func->card->host->max_blk_size)
-+ return -EINVAL;
-+
-+ if (blksz == 0) {
-+ blksz = min(min(
-+ func->max_blksize,
-+ func->card->host->max_blk_size),
-+ 512u);
-+ }
-+
-+ ret = mmc_io_rw_direct(func->card, 1, 0,
-+ SDIO_FBR_BASE(func->num) + SDIO_FBR_BLKSIZE,
-+ blksz & 0xff, NULL);
-+ if (ret)
-+ return ret;
-+ ret = mmc_io_rw_direct(func->card, 1, 0,
-+ SDIO_FBR_BASE(func->num) + SDIO_FBR_BLKSIZE + 1,
-+ (blksz >> 8) & 0xff, NULL);
-+ if (ret)
-+ return ret;
-+ func->cur_blksize = blksz;
-+ return 0;
-+}
-+
-+EXPORT_SYMBOL_GPL(sdio_set_block_size);
-+
-+/* Split an arbitrarily sized data transfer into several
-+ * IO_RW_EXTENDED commands. */
-+static int sdio_io_rw_ext_helper(struct sdio_func *func, int write,
-+ unsigned addr, int incr_addr, u8 *buf, unsigned size)
-+{
-+ unsigned remainder = size;
-+ unsigned max_blocks;
-+ int ret;
-+
-+ /* Do the bulk of the transfer using block mode (if supported). */
-+ if (func->card->cccr.multi_block) {
-+ /* Blocks per command is limited by host count, host transfer
-+ * size (we only use a single sg entry) and the maximum for
-+ * IO_RW_EXTENDED of 511 blocks. */
-+ max_blocks = min(min(
-+ func->card->host->max_blk_count,
-+ func->card->host->max_seg_size / func->cur_blksize),
-+ 511u);
-+
-+ while (remainder > func->cur_blksize) {
-+ unsigned blocks;
-+
-+ blocks = remainder / func->cur_blksize;
-+ if (blocks > max_blocks)
-+ blocks = max_blocks;
-+ size = blocks * func->cur_blksize;
-+
-+ ret = mmc_io_rw_extended(func->card, write,
-+ func->num, addr, incr_addr, buf,
-+ blocks, func->cur_blksize);
-+ if (ret)
-+ return ret;
-+
-+ remainder -= size;
-+ buf += size;
-+ if (incr_addr)
-+ addr += size;
-+ }
-+ }
-+
-+ /* Write the remainder using byte mode. */
-+ while (remainder > 0) {
-+ size = remainder;
-+ if (size > func->cur_blksize)
-+ size = func->cur_blksize;
-+ if (size > 512)
-+ size = 512; /* maximum size for byte mode */
-+
-+ ret = mmc_io_rw_extended(func->card, write, func->num, addr,
-+ incr_addr, buf, 1, size);
-+ if (ret)
-+ return ret;
-+
-+ remainder -= size;
-+ buf += size;
-+ if (incr_addr)
-+ addr += size;
-+ }
-+ return 0;
-+}
-+
-+/**
-+ * sdio_readb - read a single byte from a SDIO function
-+ * @func: SDIO function to access
-+ * @addr: address to read
-+ * @err_ret: optional status value from transfer
-+ *
-+ * Reads a single byte from the address space of a given SDIO
-+ * function. If there is a problem reading the address, 0xff
-+ * is returned and @err_ret will contain the error code.
-+ */
-+unsigned char sdio_readb(struct sdio_func *func, unsigned int addr,
-+ int *err_ret)
-+{
-+ int ret;
-+ unsigned char val;
-+
-+ BUG_ON(!func);
-+
-+ if (err_ret)
-+ *err_ret = 0;
-+
-+ ret = mmc_io_rw_direct(func->card, 0, func->num, addr, 0, &val);
-+ if (ret) {
-+ if (err_ret)
-+ *err_ret = ret;
-+ return 0xFF;
-+ }
-+
-+ return val;
-+}
-+EXPORT_SYMBOL_GPL(sdio_readb);
-+
-+/**
-+ * sdio_writeb - write a single byte to a SDIO function
-+ * @func: SDIO function to access
-+ * @b: byte to write
-+ * @addr: address to write to
-+ * @err_ret: optional status value from transfer
-+ *
-+ * Writes a single byte to the address space of a given SDIO
-+ * function. @err_ret will contain the status of the actual
-+ * transfer.
-+ */
-+void sdio_writeb(struct sdio_func *func, unsigned char b, unsigned int addr,
-+ int *err_ret)
-+{
-+ int ret;
-+
-+ BUG_ON(!func);
-+
-+ ret = mmc_io_rw_direct(func->card, 1, func->num, addr, b, NULL);
-+ if (err_ret)
-+ *err_ret = ret;
-+}
-+EXPORT_SYMBOL_GPL(sdio_writeb);
-+
-+/**
-+ * sdio_memcpy_fromio - read a chunk of memory from a SDIO function
-+ * @func: SDIO function to access
-+ * @dst: buffer to store the data
-+ * @addr: address to begin reading from
-+ * @count: number of bytes to read
-+ *
-+ * Reads from the address space of a given SDIO function. Return
-+ * value indicates if the transfer succeeded or not.
-+ */
-+int sdio_memcpy_fromio(struct sdio_func *func, void *dst,
-+ unsigned int addr, int count)
-+{
-+ return sdio_io_rw_ext_helper(func, 0, addr, 1, dst, count);
-+}
-+EXPORT_SYMBOL_GPL(sdio_memcpy_fromio);
-+
-+/**
-+ * sdio_memcpy_toio - write a chunk of memory to a SDIO function
-+ * @func: SDIO function to access
-+ * @addr: address to start writing to
-+ * @src: buffer that contains the data to write
-+ * @count: number of bytes to write
-+ *
-+ * Writes to the address space of a given SDIO function. Return
-+ * value indicates if the transfer succeeded or not.
-+ */
-+int sdio_memcpy_toio(struct sdio_func *func, unsigned int addr,
-+ void *src, int count)
-+{
-+ return sdio_io_rw_ext_helper(func, 1, addr, 1, src, count);
-+}
-+EXPORT_SYMBOL_GPL(sdio_memcpy_toio);
-+
-+/**
-+ * sdio_readsb - read from a FIFO on a SDIO function
-+ * @func: SDIO function to access
-+ * @dst: buffer to store the data
-+ * @addr: address of (single byte) FIFO
-+ * @count: number of bytes to read
-+ *
-+ * Reads from the specified FIFO of a given SDIO function. Return
-+ * value indicates if the transfer succeeded or not.
-+ */
-+int sdio_readsb(struct sdio_func *func, void *dst, unsigned int addr,
-+ int count)
-+{
-+ return sdio_io_rw_ext_helper(func, 0, addr, 0, dst, count);
-+}
-+
-+EXPORT_SYMBOL_GPL(sdio_readsb);
-+
-+/**
-+ * sdio_writesb - write to a FIFO of a SDIO function
-+ * @func: SDIO function to access
-+ * @addr: address of (single byte) FIFO
-+ * @src: buffer that contains the data to write
-+ * @count: number of bytes to write
-+ *
-+ * Writes to the specified FIFO of a given SDIO function. Return
-+ * value indicates if the transfer succeeded or not.
-+ */
-+int sdio_writesb(struct sdio_func *func, unsigned int addr, void *src,
-+ int count)
-+{
-+ return sdio_io_rw_ext_helper(func, 1, addr, 0, src, count);
-+}
-+EXPORT_SYMBOL_GPL(sdio_writesb);
-+
-+/**
-+ * sdio_readw - read a 16 bit integer from a SDIO function
-+ * @func: SDIO function to access
-+ * @addr: address to read
-+ * @err_ret: optional status value from transfer
-+ *
-+ * Reads a 16 bit integer from the address space of a given SDIO
-+ * function. If there is a problem reading the address, 0xffff
-+ * is returned and @err_ret will contain the error code.
-+ */
-+unsigned short sdio_readw(struct sdio_func *func, unsigned int addr,
-+ int *err_ret)
-+{
-+ int ret;
-+
-+ if (err_ret)
-+ *err_ret = 0;
-+
-+ ret = sdio_memcpy_fromio(func, func->tmpbuf, addr, 2);
-+ if (ret) {
-+ if (err_ret)
-+ *err_ret = ret;
-+ return 0xFFFF;
-+ }
-+
-+ return le16_to_cpu(*(u16*)func->tmpbuf);
-+}
-+EXPORT_SYMBOL_GPL(sdio_readw);
-+
-+/**
-+ * sdio_writew - write a 16 bit integer to a SDIO function
-+ * @func: SDIO function to access
-+ * @b: integer to write
-+ * @addr: address to write to
-+ * @err_ret: optional status value from transfer
-+ *
-+ * Writes a 16 bit integer to the address space of a given SDIO
-+ * function. @err_ret will contain the status of the actual
-+ * transfer.
-+ */
-+void sdio_writew(struct sdio_func *func, unsigned short b, unsigned int addr,
-+ int *err_ret)
-+{
-+ int ret;
-+
-+ *(u16*)func->tmpbuf = cpu_to_le16(b);
-+
-+ ret = sdio_memcpy_toio(func, addr, func->tmpbuf, 2);
-+ if (err_ret)
-+ *err_ret = ret;
-+}
-+EXPORT_SYMBOL_GPL(sdio_writew);
-+
-+/**
-+ * sdio_readl - read a 32 bit integer from a SDIO function
-+ * @func: SDIO function to access
-+ * @addr: address to read
-+ * @err_ret: optional status value from transfer
-+ *
-+ * Reads a 32 bit integer from the address space of a given SDIO
-+ * function. If there is a problem reading the address,
-+ * 0xffffffff is returned and @err_ret will contain the error
-+ * code.
-+ */
-+unsigned long sdio_readl(struct sdio_func *func, unsigned int addr,
-+ int *err_ret)
-+{
-+ int ret;
-+
-+ if (err_ret)
-+ *err_ret = 0;
-+
-+ ret = sdio_memcpy_fromio(func, func->tmpbuf, addr, 4);
-+ if (ret) {
-+ if (err_ret)
-+ *err_ret = ret;
-+ return 0xFFFFFFFF;
-+ }
-+
-+ return le32_to_cpu(*(u32*)func->tmpbuf);
-+}
-+EXPORT_SYMBOL_GPL(sdio_readl);
-+
-+/**
-+ * sdio_writel - write a 32 bit integer to a SDIO function
-+ * @func: SDIO function to access
-+ * @b: integer to write
-+ * @addr: address to write to
-+ * @err_ret: optional status value from transfer
-+ *
-+ * Writes a 32 bit integer to the address space of a given SDIO
-+ * function. @err_ret will contain the status of the actual
-+ * transfer.
-+ */
-+void sdio_writel(struct sdio_func *func, unsigned long b, unsigned int addr,
-+ int *err_ret)
-+{
-+ int ret;
-+
-+ *(u32*)func->tmpbuf = cpu_to_le32(b);
-+
-+ ret = sdio_memcpy_toio(func, addr, func->tmpbuf, 4);
-+ if (err_ret)
-+ *err_ret = ret;
-+}
-+EXPORT_SYMBOL_GPL(sdio_writel);
-+
-+/**
-+ * sdio_f0_readb - read a single byte from SDIO function 0
-+ * @func: an SDIO function of the card
-+ * @addr: address to read
-+ * @err_ret: optional status value from transfer
-+ *
-+ * Reads a single byte from the address space of SDIO function 0.
-+ * If there is a problem reading the address, 0xff is returned
-+ * and @err_ret will contain the error code.
-+ */
-+unsigned char sdio_f0_readb(struct sdio_func *func, unsigned int addr,
-+ int *err_ret)
-+{
-+ int ret;
-+ unsigned char val;
-+
-+ BUG_ON(!func);
-+
-+ if (err_ret)
-+ *err_ret = 0;
-+
-+ ret = mmc_io_rw_direct(func->card, 0, 0, addr, 0, &val);
-+ if (ret) {
-+ if (err_ret)
-+ *err_ret = ret;
-+ return 0xFF;
-+ }
-+
-+ return val;
-+}
-+EXPORT_SYMBOL_GPL(sdio_f0_readb);
-+
-+/**
-+ * sdio_f0_writeb - write a single byte to SDIO function 0
-+ * @func: an SDIO function of the card
-+ * @b: byte to write
-+ * @addr: address to write to
-+ * @err_ret: optional status value from transfer
-+ *
-+ * Writes a single byte to the address space of SDIO function 0.
-+ * @err_ret will contain the status of the actual transfer.
-+ *
-+ * Only writes to the vendor specific CCCR registers (0xF0 -
-+ * 0xFF) are permiited; @err_ret will be set to -EINVAL for *
-+ * writes outside this range.
-+ */
-+void sdio_f0_writeb(struct sdio_func *func, unsigned char b, unsigned int addr,
-+ int *err_ret)
-+{
-+ int ret;
-+
-+ BUG_ON(!func);
-+
-+ if (addr < 0xF0 || addr > 0xFF) {
-+ if (err_ret)
-+ *err_ret = -EINVAL;
-+ return;
-+ }
-+
-+ ret = mmc_io_rw_direct(func->card, 1, 0, addr, b, NULL);
-+ if (err_ret)
-+ *err_ret = ret;
-+}
-+EXPORT_SYMBOL_GPL(sdio_f0_writeb);
---- /dev/null
-+++ b/drivers/mmc/core/sdio_irq.c
-@@ -0,0 +1,267 @@
-+/*
-+ * linux/drivers/mmc/core/sdio_irq.c
-+ *
-+ * Author: Nicolas Pitre
-+ * Created: June 18, 2007
-+ * Copyright: MontaVista Software Inc.
-+ *
-+ * 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.
-+ */
-+
-+#include <linux/kernel.h>
-+#include <linux/sched.h>
-+#include <linux/kthread.h>
-+#include <linux/wait.h>
-+#include <linux/delay.h>
-+
-+#include <linux/mmc/core.h>
-+#include <linux/mmc/host.h>
-+#include <linux/mmc/card.h>
-+#include <linux/mmc/sdio.h>
-+#include <linux/mmc/sdio_func.h>
-+
-+#include "sdio_ops.h"
-+
-+static int process_sdio_pending_irqs(struct mmc_card *card)
-+{
-+ int i, ret, count;
-+ unsigned char pending;
-+
-+ ret = mmc_io_rw_direct(card, 0, 0, SDIO_CCCR_INTx, 0, &pending);
-+ if (ret) {
-+ printk(KERN_DEBUG "%s: error %d reading SDIO_CCCR_INTx\n",
-+ mmc_card_id(card), ret);
-+ return ret;
-+ }
-+
-+ count = 0;
-+ for (i = 1; i <= 7; i++) {
-+ if (pending & (1 << i)) {
-+ struct sdio_func *func = card->sdio_func[i - 1];
-+ if (!func) {
-+ printk(KERN_WARNING "%s: pending IRQ for "
-+ "non-existant function\n",
-+ mmc_card_id(card));
-+ ret = -EINVAL;
-+ } else if (func->irq_handler) {
-+ func->irq_handler(func);
-+ count++;
-+ } else {
-+ printk(KERN_WARNING "%s: pending IRQ with no handler\n",
-+ sdio_func_id(func));
-+ ret = -EINVAL;
-+ }
-+ }
-+ }
-+
-+ if (count)
-+ return count;
-+
-+ return ret;
-+}
-+
-+static int sdio_irq_thread(void *_host)
-+{
-+ struct mmc_host *host = _host;
-+ struct sched_param param = { .sched_priority = 1 };
-+ unsigned long period, idle_period;
-+ int ret;
-+
-+ sched_setscheduler(current, SCHED_FIFO, ¶m);
-+
-+ /*
-+ * We want to allow for SDIO cards to work even on non SDIO
-+ * aware hosts. One thing that non SDIO host cannot do is
-+ * asynchronous notification of pending SDIO card interrupts
-+ * hence we poll for them in that case.
-+ */
-+ idle_period = msecs_to_jiffies(10);
-+ period = (host->caps & MMC_CAP_SDIO_IRQ) ?
-+ MAX_SCHEDULE_TIMEOUT : idle_period;
-+
-+ pr_debug("%s: IRQ thread started (poll period = %lu jiffies)\n",
-+ mmc_hostname(host), period);
-+
-+ do {
-+ /*
-+ * We claim the host here on drivers behalf for a couple
-+ * reasons:
-+ *
-+ * 1) it is already needed to retrieve the CCCR_INTx;
-+ * 2) we want the driver(s) to clear the IRQ condition ASAP;
-+ * 3) we need to control the abort condition locally.
-+ *
-+ * Just like traditional hard IRQ handlers, we expect SDIO
-+ * IRQ handlers to be quick and to the point, so that the
-+ * holding of the host lock does not cover too much work
-+ * that doesn't require that lock to be held.
-+ */
-+ ret = __mmc_claim_host(host, &host->sdio_irq_thread_abort);
-+ if (ret)
-+ break;
-+ ret = process_sdio_pending_irqs(host->card);
-+ mmc_release_host(host);
-+
-+ /*
-+ * Give other threads a chance to run in the presence of
-+ * errors. FIXME: determine if due to card removal and
-+ * possibly exit this thread if so.
-+ */
-+ if (ret < 0)
-+ ssleep(1);
-+
-+ /*
-+ * Adaptive polling frequency based on the assumption
-+ * that an interrupt will be closely followed by more.
-+ * This has a substantial benefit for network devices.
-+ */
-+ if (!(host->caps & MMC_CAP_SDIO_IRQ)) {
-+ if (ret > 0)
-+ period /= 2;
-+ else {
-+ period++;
-+ if (period > idle_period)
-+ period = idle_period;
-+ }
-+ }
-+
-+ set_task_state(current, TASK_INTERRUPTIBLE);
-+ if (host->caps & MMC_CAP_SDIO_IRQ)
-+ host->ops->enable_sdio_irq(host, 1);
-+ if (!kthread_should_stop())
-+ schedule_timeout(period);
-+ set_task_state(current, TASK_RUNNING);
-+ } while (!kthread_should_stop());
-+
-+ if (host->caps & MMC_CAP_SDIO_IRQ)
-+ host->ops->enable_sdio_irq(host, 0);
-+
-+ pr_debug("%s: IRQ thread exiting with code %d\n",
-+ mmc_hostname(host), ret);
-+
-+ return ret;
-+}
-+
-+static int sdio_card_irq_get(struct mmc_card *card)
-+{
-+ struct mmc_host *host = card->host;
-+
-+ WARN_ON(!host->claimed);
-+
-+ if (!host->sdio_irqs++) {
-+ atomic_set(&host->sdio_irq_thread_abort, 0);
-+ host->sdio_irq_thread =
-+ kthread_run(sdio_irq_thread, host, "ksdiorqd");
-+ if (IS_ERR(host->sdio_irq_thread)) {
-+ int err = PTR_ERR(host->sdio_irq_thread);
-+ host->sdio_irqs--;
-+ return err;
-+ }
-+ }
-+
-+ return 0;
-+}
-+
-+static int sdio_card_irq_put(struct mmc_card *card)
-+{
-+ struct mmc_host *host = card->host;
-+
-+ WARN_ON(!host->claimed);
-+ BUG_ON(host->sdio_irqs < 1);
-+
-+ if (!--host->sdio_irqs) {
-+ atomic_set(&host->sdio_irq_thread_abort, 1);
-+ kthread_stop(host->sdio_irq_thread);
-+ }
-+
-+ return 0;
-+}
-+
-+/**
-+ * sdio_claim_irq - claim the IRQ for a SDIO function
-+ * @func: SDIO function
-+ * @handler: IRQ handler callback
-+ *
-+ * Claim and activate the IRQ for the given SDIO function. The provided
-+ * handler will be called when that IRQ is asserted. The host is always
-+ * claimed already when the handler is called so the handler must not
-+ * call sdio_claim_host() nor sdio_release_host().
-+ */
-+int sdio_claim_irq(struct sdio_func *func, sdio_irq_handler_t *handler)
-+{
-+ int ret;
-+ unsigned char reg;
-+
-+ BUG_ON(!func);
-+ BUG_ON(!func->card);
-+
-+ pr_debug("SDIO: Enabling IRQ for %s...\n", sdio_func_id(func));
-+
-+ if (func->irq_handler) {
-+ pr_debug("SDIO: IRQ for %s already in use.\n", sdio_func_id(func));
-+ return -EBUSY;
-+ }
-+
-+ ret = mmc_io_rw_direct(func->card, 0, 0, SDIO_CCCR_IENx, 0, ®);
-+ if (ret)
-+ return ret;
-+
-+ reg |= 1 << func->num;
-+
-+ reg |= 1; /* Master interrupt enable */
-+
-+ ret = mmc_io_rw_direct(func->card, 1, 0, SDIO_CCCR_IENx, reg, NULL);
-+ if (ret)
-+ return ret;
-+
-+ func->irq_handler = handler;
-+ ret = sdio_card_irq_get(func->card);
-+ if (ret)
-+ func->irq_handler = NULL;
-+
-+ return ret;
-+}
-+EXPORT_SYMBOL_GPL(sdio_claim_irq);
-+
-+/**
-+ * sdio_release_irq - release the IRQ for a SDIO function
-+ * @func: SDIO function
-+ *
-+ * Disable and release the IRQ for the given SDIO function.
-+ */
-+int sdio_release_irq(struct sdio_func *func)
-+{
-+ int ret;
-+ unsigned char reg;
-+
-+ BUG_ON(!func);
-+ BUG_ON(!func->card);
-+
-+ pr_debug("SDIO: Disabling IRQ for %s...\n", sdio_func_id(func));
-+
-+ if (func->irq_handler) {
-+ func->irq_handler = NULL;
-+ sdio_card_irq_put(func->card);
-+ }
-+
-+ ret = mmc_io_rw_direct(func->card, 0, 0, SDIO_CCCR_IENx, 0, ®);
-+ if (ret)
-+ return ret;
-+
-+ reg &= ~(1 << func->num);
-+
-+ /* Disable master interrupt with the last function interrupt */
-+ if (!(reg & 0xFE))
-+ reg = 0;
-+
-+ ret = mmc_io_rw_direct(func->card, 1, 0, SDIO_CCCR_IENx, reg, NULL);
-+ if (ret)
-+ return ret;
-+
-+ return 0;
-+}
-+EXPORT_SYMBOL_GPL(sdio_release_irq);
-+
---- /dev/null
-+++ b/drivers/mmc/core/sdio_ops.c
-@@ -0,0 +1,175 @@
-+/*
-+ * linux/drivers/mmc/sdio_ops.c
-+ *
-+ * Copyright 2006-2007 Pierre Ossman
-+ *
-+ * 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.
-+ */
-+
-+#include <linux/scatterlist.h>
-+
-+#include <linux/mmc/host.h>
-+#include <linux/mmc/card.h>
-+#include <linux/mmc/mmc.h>
-+#include <linux/mmc/sdio.h>
-+
-+#include "core.h"
-+
-+int mmc_send_io_op_cond(struct mmc_host *host, u32 ocr, u32 *rocr)
-+{
-+ struct mmc_command cmd;
-+ int i, err = 0;
-+
-+ BUG_ON(!host);
-+
-+ memset(&cmd, 0, sizeof(struct mmc_command));
-+
-+ cmd.opcode = SD_IO_SEND_OP_COND;
-+ cmd.arg = ocr;
-+ cmd.flags = MMC_RSP_SPI_R4 | MMC_RSP_R4 | MMC_CMD_BCR;
-+
-+ for (i = 100; i; i--) {
-+ err = mmc_wait_for_cmd(host, &cmd, MMC_CMD_RETRIES);
-+ if (err)
-+ break;
-+
-+ /* if we're just probing, do a single pass */
-+ if (ocr == 0)
-+ break;
-+
-+ /* otherwise wait until reset completes */
-+ if (mmc_host_is_spi(host)) {
-+ /*
-+ * Both R1_SPI_IDLE and MMC_CARD_BUSY indicate
-+ * an initialized card under SPI, but some cards
-+ * (Marvell's) only behave when looking at this
-+ * one.
-+ */
-+ if (cmd.resp[1] & MMC_CARD_BUSY)
-+ break;
-+ } else {
-+ if (cmd.resp[0] & MMC_CARD_BUSY)
-+ break;
-+ }
-+
-+ err = -ETIMEDOUT;
-+
-+ mmc_delay(10);
-+ }
-+
-+ if (rocr)
-+ *rocr = cmd.resp[mmc_host_is_spi(host) ? 1 : 0];
-+
-+ return err;
-+}
-+
-+int mmc_io_rw_direct(struct mmc_card *card, int write, unsigned fn,
-+ unsigned addr, u8 in, u8* out)
-+{
-+ struct mmc_command cmd;
-+ int err;
-+
-+ BUG_ON(!card);
-+ BUG_ON(fn > 7);
-+
-+ memset(&cmd, 0, sizeof(struct mmc_command));
-+
-+ cmd.opcode = SD_IO_RW_DIRECT;
-+ cmd.arg = write ? 0x80000000 : 0x00000000;
-+ cmd.arg |= fn << 28;
-+ cmd.arg |= (write && out) ? 0x08000000 : 0x00000000;
-+ cmd.arg |= addr << 9;
-+ cmd.arg |= in;
-+ cmd.flags = MMC_RSP_SPI_R5 | MMC_RSP_R5 | MMC_CMD_AC;
-+
-+ err = mmc_wait_for_cmd(card->host, &cmd, 0);
-+ if (err)
-+ return err;
-+
-+ if (mmc_host_is_spi(card->host)) {
-+ /* host driver already reported errors */
-+ } else {
-+ if (cmd.resp[0] & R5_ERROR)
-+ return -EIO;
-+ if (cmd.resp[0] & R5_FUNCTION_NUMBER)
-+ return -EINVAL;
-+ if (cmd.resp[0] & R5_OUT_OF_RANGE)
-+ return -ERANGE;
-+ }
-+
-+ if (out) {
-+ if (mmc_host_is_spi(card->host))
-+ *out = (cmd.resp[0] >> 8) & 0xFF;
-+ else
-+ *out = cmd.resp[0] & 0xFF;
-+ }
-+
-+ return 0;
-+}
-+
-+int mmc_io_rw_extended(struct mmc_card *card, int write, unsigned fn,
-+ unsigned addr, int incr_addr, u8 *buf, unsigned blocks, unsigned blksz)
-+{
-+ struct mmc_request mrq;
-+ struct mmc_command cmd;
-+ struct mmc_data data;
-+ struct scatterlist sg;
-+
-+ BUG_ON(!card);
-+ BUG_ON(fn > 7);
-+ BUG_ON(blocks == 1 && blksz > 512);
-+ WARN_ON(blocks == 0);
-+ WARN_ON(blksz == 0);
-+
-+ memset(&mrq, 0, sizeof(struct mmc_request));
-+ memset(&cmd, 0, sizeof(struct mmc_command));
-+ memset(&data, 0, sizeof(struct mmc_data));
-+
-+ mrq.cmd = &cmd;
-+ mrq.data = &data;
-+
-+ cmd.opcode = SD_IO_RW_EXTENDED;
-+ cmd.arg = write ? 0x80000000 : 0x00000000;
-+ cmd.arg |= fn << 28;
-+ cmd.arg |= incr_addr ? 0x04000000 : 0x00000000;
-+ cmd.arg |= addr << 9;
-+ if (blocks == 1 && blksz <= 512)
-+ cmd.arg |= (blksz == 512) ? 0 : blksz; /* byte mode */
-+ else
-+ cmd.arg |= 0x08000000 | blocks; /* block mode */
-+ cmd.flags = MMC_RSP_SPI_R5 | MMC_RSP_R5 | MMC_CMD_ADTC;
-+
-+ data.blksz = blksz;
-+ data.blocks = blocks;
-+ data.flags = write ? MMC_DATA_WRITE : MMC_DATA_READ;
-+ data.sg = &sg;
-+ data.sg_len = 1;
-+
-+ sg_init_one(&sg, buf, blksz * blocks);
-+
-+ mmc_set_data_timeout(&data, card);
-+
-+ mmc_wait_for_req(card->host, &mrq);
-+
-+ if (cmd.error)
-+ return cmd.error;
-+ if (data.error)
-+ return data.error;
-+
-+ if (mmc_host_is_spi(card->host)) {
-+ /* host driver already reported errors */
-+ } else {
-+ if (cmd.resp[0] & R5_ERROR)
-+ return -EIO;
-+ if (cmd.resp[0] & R5_FUNCTION_NUMBER)
-+ return -EINVAL;
-+ if (cmd.resp[0] & R5_OUT_OF_RANGE)
-+ return -ERANGE;
-+ }
-+
-+ return 0;
-+}
-+
---- /dev/null
-+++ b/drivers/mmc/core/sdio_ops.h
-@@ -0,0 +1,22 @@
-+/*
-+ * linux/drivers/mmc/sdio_ops.c
-+ *
-+ * Copyright 2006-2007 Pierre Ossman
-+ *
-+ * 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.
-+ */
-+
-+#ifndef _MMC_SDIO_OPS_H
-+#define _MMC_SDIO_OPS_H
-+
-+int mmc_send_io_op_cond(struct mmc_host *host, u32 ocr, u32 *rocr);
-+int mmc_io_rw_direct(struct mmc_card *card, int write, unsigned fn,
-+ unsigned addr, u8 in, u8* out);
-+int mmc_io_rw_extended(struct mmc_card *card, int write, unsigned fn,
-+ unsigned addr, int incr_addr, u8 *buf, unsigned blocks, unsigned blksz);
-+
-+#endif
-+
---- a/include/linux/mmc/card.h
-+++ b/include/linux/mmc/card.h
-@@ -55,7 +55,28 @@
- unsigned int hs_max_dtr;
- };
-
-+struct sdio_cccr {
-+ unsigned int sdio_vsn;
-+ unsigned int sd_vsn;
-+ unsigned int multi_block:1,
-+ low_speed:1,
-+ wide_bus:1,
-+ high_power:1,
-+ high_speed:1;
-+};
-+
-+struct sdio_cis {
-+ unsigned short vendor;
-+ unsigned short device;
-+ unsigned short blksize;
-+ unsigned int max_dtr;
-+};
-+
- struct mmc_host;
-+struct sdio_func;
-+struct sdio_func_tuple;
-+
-+#define SDIO_MAX_FUNCS 7
-
- /*
- * MMC device
-@@ -67,11 +88,13 @@
- unsigned int type; /* card type */
- #define MMC_TYPE_MMC 0 /* MMC card */
- #define MMC_TYPE_SD 1 /* SD card */
-+#define MMC_TYPE_SDIO 2 /* SDIO card */
- unsigned int state; /* (our) card state */
- #define MMC_STATE_PRESENT (1<<0) /* present in sysfs */
- #define MMC_STATE_READONLY (1<<1) /* card is read-only */
- #define MMC_STATE_HIGHSPEED (1<<2) /* card is in high speed mode */
- #define MMC_STATE_BLOCKADDR (1<<3) /* card uses block-addressing */
-+
- u32 raw_cid[4]; /* raw card CID */
- u32 raw_csd[4]; /* raw card CSD */
- u32 raw_scr[2]; /* raw card SCR */
-@@ -80,10 +103,19 @@
- struct mmc_ext_csd ext_csd; /* mmc v4 extended card specific */
- struct sd_scr scr; /* extra SD information */
- struct sd_switch_caps sw_caps; /* switch (CMD6) caps */
-+
-+ unsigned int sdio_funcs; /* number of SDIO functions */
-+ struct sdio_cccr cccr; /* common card info */
-+ struct sdio_cis cis; /* common tuple info */
-+ struct sdio_func *sdio_func[SDIO_MAX_FUNCS]; /* SDIO functions (devices) */
-+ unsigned num_info; /* number of info strings */
-+ const char **info; /* info strings */
-+ struct sdio_func_tuple *tuples; /* unknown common tuples */
- };
-
- #define mmc_card_mmc(c) ((c)->type == MMC_TYPE_MMC)
- #define mmc_card_sd(c) ((c)->type == MMC_TYPE_SD)
-+#define mmc_card_sdio(c) ((c)->type == MMC_TYPE_SDIO)
-
- #define mmc_card_present(c) ((c)->state & MMC_STATE_PRESENT)
- #define mmc_card_readonly(c) ((c)->state & MMC_STATE_READONLY)
---- a/include/linux/mmc/core.h
-+++ b/include/linux/mmc/core.h
-@@ -25,14 +25,20 @@
- #define MMC_RSP_CRC (1 << 2) /* expect valid crc */
- #define MMC_RSP_BUSY (1 << 3) /* card may send busy */
- #define MMC_RSP_OPCODE (1 << 4) /* response contains opcode */
--#define MMC_CMD_MASK (3 << 5) /* command type */
-+
-+#define MMC_CMD_MASK (3 << 5) /* non-SPI command type */
- #define MMC_CMD_AC (0 << 5)
- #define MMC_CMD_ADTC (1 << 5)
- #define MMC_CMD_BC (2 << 5)
- #define MMC_CMD_BCR (3 << 5)
-
-+#define MMC_RSP_SPI_S1 (1 << 7) /* one status byte */
-+#define MMC_RSP_SPI_S2 (1 << 8) /* second byte */
-+#define MMC_RSP_SPI_B4 (1 << 9) /* four data bytes */
-+#define MMC_RSP_SPI_BUSY (1 << 10) /* card may send busy */
-+
- /*
-- * These are the response types, and correspond to valid bit
-+ * These are the native response types, and correspond to valid bit
- * patterns of the above flags. One additional valid pattern
- * is all zeros, which means we don't expect a response.
- */
-@@ -41,12 +47,30 @@
- #define MMC_RSP_R1B (MMC_RSP_PRESENT|MMC_RSP_CRC|MMC_RSP_OPCODE|MMC_RSP_BUSY)
- #define MMC_RSP_R2 (MMC_RSP_PRESENT|MMC_RSP_136|MMC_RSP_CRC)
- #define MMC_RSP_R3 (MMC_RSP_PRESENT)
-+#define MMC_RSP_R4 (MMC_RSP_PRESENT)
-+#define MMC_RSP_R5 (MMC_RSP_PRESENT|MMC_RSP_CRC|MMC_RSP_OPCODE)
- #define MMC_RSP_R6 (MMC_RSP_PRESENT|MMC_RSP_CRC|MMC_RSP_OPCODE)
- #define MMC_RSP_R7 (MMC_RSP_PRESENT|MMC_RSP_CRC|MMC_RSP_OPCODE)
-
- #define mmc_resp_type(cmd) ((cmd)->flags & (MMC_RSP_PRESENT|MMC_RSP_136|MMC_RSP_CRC|MMC_RSP_BUSY|MMC_RSP_OPCODE))
-
- /*
-+ * These are the SPI response types for MMC, SD, and SDIO cards.
-+ * Commands return R1, with maybe more info. Zero is an error type;
-+ * callers must always provide the appropriate MMC_RSP_SPI_Rx flags.
-+ */
-+#define MMC_RSP_SPI_R1 (MMC_RSP_SPI_S1)
-+#define MMC_RSP_SPI_R1B (MMC_RSP_SPI_S1|MMC_RSP_SPI_BUSY)
-+#define MMC_RSP_SPI_R2 (MMC_RSP_SPI_S1|MMC_RSP_SPI_S2)
-+#define MMC_RSP_SPI_R3 (MMC_RSP_SPI_S1|MMC_RSP_SPI_B4)
-+#define MMC_RSP_SPI_R4 (MMC_RSP_SPI_S1|MMC_RSP_SPI_B4)
-+#define MMC_RSP_SPI_R5 (MMC_RSP_SPI_S1|MMC_RSP_SPI_S2)
-+#define MMC_RSP_SPI_R7 (MMC_RSP_SPI_S1|MMC_RSP_SPI_B4)
-+
-+#define mmc_spi_resp_type(cmd) ((cmd)->flags & \
-+ (MMC_RSP_SPI_S1|MMC_RSP_SPI_BUSY|MMC_RSP_SPI_S2|MMC_RSP_SPI_B4))
-+
-+/*
- * These are the command types.
- */
- #define mmc_cmd_type(cmd) ((cmd)->flags & MMC_CMD_MASK)
-@@ -54,12 +78,19 @@
- unsigned int retries; /* max number of retries */
- unsigned int error; /* command error */
-
--#define MMC_ERR_NONE 0
--#define MMC_ERR_TIMEOUT 1
--#define MMC_ERR_BADCRC 2
--#define MMC_ERR_FIFO 3
--#define MMC_ERR_FAILED 4
--#define MMC_ERR_INVALID 5
-+/*
-+ * Standard errno values are used for errors, but some have specific
-+ * meaning in the MMC layer:
-+ *
-+ * ETIMEDOUT Card took too long to respond
-+ * EILSEQ Basic format problem with the received or sent data
-+ * (e.g. CRC check failed, incorrect opcode in response
-+ * or bad end bit)
-+ * EINVAL Request cannot be performed because of restrictions
-+ * in hardware and/or the driver
-+ * ENOMEDIUM Host can determine that the slot is empty and is
-+ * actively failing requests
-+ */
-
- struct mmc_data *data; /* data segment associated with cmd */
- struct mmc_request *mrq; /* associated request */
-@@ -76,7 +107,6 @@
- #define MMC_DATA_WRITE (1 << 8)
- #define MMC_DATA_READ (1 << 9)
- #define MMC_DATA_STREAM (1 << 10)
--#define MMC_DATA_MULTI (1 << 11)
-
- unsigned int bytes_xfered;
-
-@@ -104,9 +134,20 @@
- extern int mmc_wait_for_app_cmd(struct mmc_host *, struct mmc_card *,
- struct mmc_command *, int);
-
--extern void mmc_set_data_timeout(struct mmc_data *, const struct mmc_card *, int);
-+extern void mmc_set_data_timeout(struct mmc_data *, const struct mmc_card *);
-
--extern void mmc_claim_host(struct mmc_host *host);
-+extern int __mmc_claim_host(struct mmc_host *host, atomic_t *abort);
- extern void mmc_release_host(struct mmc_host *host);
-
-+/**
-+ * mmc_claim_host - exclusively claim a host
-+ * @host: mmc host to claim
-+ *
-+ * Claim a host for a set of operations.
-+ */
-+static inline void mmc_claim_host(struct mmc_host *host)
-+{
-+ __mmc_claim_host(host, NULL);
-+}
-+
- #endif
---- a/include/linux/mmc/host.h
-+++ b/include/linux/mmc/host.h
-@@ -10,6 +10,8 @@
- #ifndef LINUX_MMC_HOST_H
- #define LINUX_MMC_HOST_H
-
-+#include <linux/leds.h>
-+
- #include <linux/mmc/core.h>
-
- struct mmc_ios {
-@@ -51,6 +53,7 @@
- void (*request)(struct mmc_host *host, struct mmc_request *req);
- void (*set_ios)(struct mmc_host *host, struct mmc_ios *ios);
- int (*get_ro)(struct mmc_host *host);
-+ void (*enable_sdio_irq)(struct mmc_host *host, int enable);
- };
-
- struct mmc_card;
-@@ -87,9 +90,10 @@
-
- #define MMC_CAP_4_BIT_DATA (1 << 0) /* Can the host do 4 bit transfers */
- #define MMC_CAP_MULTIWRITE (1 << 1) /* Can accurately report bytes sent to card on error */
--#define MMC_CAP_BYTEBLOCK (1 << 2) /* Can do non-log2 block sizes */
--#define MMC_CAP_MMC_HIGHSPEED (1 << 3) /* Can do MMC high-speed timing */
--#define MMC_CAP_SD_HIGHSPEED (1 << 4) /* Can do SD high-speed timing */
-+#define MMC_CAP_MMC_HIGHSPEED (1 << 2) /* Can do MMC high-speed timing */
-+#define MMC_CAP_SD_HIGHSPEED (1 << 3) /* Can do SD high-speed timing */
-+#define MMC_CAP_SDIO_IRQ (1 << 4) /* Can signal pending SDIO IRQs */
-+#define MMC_CAP_SPI (1 << 5) /* Talks only SPI protocols */
-
- /* host specific block data */
- unsigned int max_seg_size; /* see blk_queue_max_segment_size */
-@@ -106,23 +110,30 @@
- struct mmc_ios ios; /* current io bus settings */
- u32 ocr; /* the current OCR setting */
-
-- unsigned int mode; /* current card mode of host */
--#define MMC_MODE_MMC 0
--#define MMC_MODE_SD 1
-+ /* group bitfields together to minimize padding */
-+ unsigned int use_spi_crc:1;
-+ unsigned int claimed:1; /* host exclusively claimed */
-+ unsigned int bus_dead:1; /* bus has been released */
-+#ifdef CONFIG_MMC_DEBUG
-+ unsigned int removed:1; /* host is being removed */
-+#endif
-
- struct mmc_card *card; /* device attached to this host */
-
- wait_queue_head_t wq;
-- unsigned int claimed:1; /* host exclusively claimed */
-
- struct delayed_work detect;
--#ifdef CONFIG_MMC_DEBUG
-- unsigned int removed:1; /* host is being removed */
--#endif
-
- const struct mmc_bus_ops *bus_ops; /* current bus driver */
- unsigned int bus_refs; /* reference counter */
-- unsigned int bus_dead:1; /* bus has been released */
-+
-+ unsigned int sdio_irqs;
-+ struct task_struct *sdio_irq_thread;
-+ atomic_t sdio_irq_thread_abort;
-+
-+#ifdef CONFIG_LEDS_TRIGGERS
-+ struct led_trigger *led; /* activity led */
-+#endif
-
- unsigned long private[0] ____cacheline_aligned;
- };
-@@ -137,6 +148,8 @@
- return (void *)host->private;
- }
-
-+#define mmc_host_is_spi(host) ((host)->caps & MMC_CAP_SPI)
-+
- #define mmc_dev(x) ((x)->parent)
- #define mmc_classdev(x) (&(x)->class_dev)
- #define mmc_hostname(x) ((x)->class_dev.bus_id)
-@@ -147,5 +160,11 @@
- extern void mmc_detect_change(struct mmc_host *, unsigned long delay);
- extern void mmc_request_done(struct mmc_host *, struct mmc_request *);
-
-+static inline void mmc_signal_sdio_irq(struct mmc_host *host)
-+{
-+ host->ops->enable_sdio_irq(host, 0);
-+ wake_up_process(host->sdio_irq_thread);
-+}
-+
- #endif
-
---- a/include/linux/mmc/mmc.h
-+++ b/include/linux/mmc/mmc.h
-@@ -27,7 +27,7 @@
-
- /* Standard MMC commands (4.1) type argument response */
- /* class 1 */
--#define MMC_GO_IDLE_STATE 0 /* bc */
-+#define MMC_GO_IDLE_STATE 0 /* bc */
- #define MMC_SEND_OP_COND 1 /* bcr [31:0] OCR R3 */
- #define MMC_ALL_SEND_CID 2 /* bcr R2 */
- #define MMC_SET_RELATIVE_ADDR 3 /* ac [31:16] RCA R1 */
-@@ -39,8 +39,10 @@
- #define MMC_SEND_CID 10 /* ac [31:16] RCA R2 */
- #define MMC_READ_DAT_UNTIL_STOP 11 /* adtc [31:0] dadr R1 */
- #define MMC_STOP_TRANSMISSION 12 /* ac R1b */
--#define MMC_SEND_STATUS 13 /* ac [31:16] RCA R1 */
-+#define MMC_SEND_STATUS 13 /* ac [31:16] RCA R1 */
- #define MMC_GO_INACTIVE_STATE 15 /* ac [31:16] RCA */
-+#define MMC_SPI_READ_OCR 58 /* spi spi_R3 */
-+#define MMC_SPI_CRC_ON_OFF 59 /* spi [0:0] flag spi_R1 */
-
- /* class 2 */
- #define MMC_SET_BLOCKLEN 16 /* ac [31:0] block len R1 */
-@@ -90,15 +92,15 @@
- */
-
- /*
-- MMC status in R1
-+ MMC status in R1, for native mode (SPI bits are different)
- Type
-- e : error bit
-+ e : error bit
- s : status bit
- r : detected and set for the actual command response
- x : detected and set during command execution. the host must poll
- the card by sending status command in order to read these bits.
- Clear condition
-- a : according to the card state
-+ a : according to the card state
- b : always related to the previous command. Reception of
- a valid command will clear it (with a delay of one command)
- c : clear by read
-@@ -124,10 +126,33 @@
- #define R1_CARD_ECC_DISABLED (1 << 14) /* sx, a */
- #define R1_ERASE_RESET (1 << 13) /* sr, c */
- #define R1_STATUS(x) (x & 0xFFFFE000)
--#define R1_CURRENT_STATE(x) ((x & 0x00001E00) >> 9) /* sx, b (4 bits) */
-+#define R1_CURRENT_STATE(x) ((x & 0x00001E00) >> 9) /* sx, b (4 bits) */
- #define R1_READY_FOR_DATA (1 << 8) /* sx, a */
- #define R1_APP_CMD (1 << 5) /* sr, c */
-
-+/*
-+ * MMC/SD in SPI mode reports R1 status always, and R2 for SEND_STATUS
-+ * R1 is the low order byte; R2 is the next highest byte, when present.
-+ */
-+#define R1_SPI_IDLE (1 << 0)
-+#define R1_SPI_ERASE_RESET (1 << 1)
-+#define R1_SPI_ILLEGAL_COMMAND (1 << 2)
-+#define R1_SPI_COM_CRC (1 << 3)
-+#define R1_SPI_ERASE_SEQ (1 << 4)
-+#define R1_SPI_ADDRESS (1 << 5)
-+#define R1_SPI_PARAMETER (1 << 6)
-+/* R1 bit 7 is always zero */
-+#define R2_SPI_CARD_LOCKED (1 << 8)
-+#define R2_SPI_WP_ERASE_SKIP (1 << 9) /* or lock/unlock fail */
-+#define R2_SPI_LOCK_UNLOCK_FAIL R2_SPI_WP_ERASE_SKIP
-+#define R2_SPI_ERROR (1 << 10)
-+#define R2_SPI_CC_ERROR (1 << 11)
-+#define R2_SPI_CARD_ECC_ERROR (1 << 12)
-+#define R2_SPI_WP_VIOLATION (1 << 13)
-+#define R2_SPI_ERASE_PARAM (1 << 14)
-+#define R2_SPI_OUT_OF_RANGE (1 << 15) /* or CSD overwrite */
-+#define R2_SPI_CSD_OVERWRITE R2_SPI_OUT_OF_RANGE
-+
- /* These are unpacked versions of the actual responses */
-
- struct _mmc_csd {
-@@ -182,6 +207,7 @@
- */
- #define CCC_BASIC (1<<0) /* (0) Basic protocol functions */
- /* (CMD0,1,2,3,4,7,9,10,12,13,15) */
-+ /* (and for SPI, CMD58,59) */
- #define CCC_STREAM_READ (1<<1) /* (1) Stream read commands */
- /* (CMD11) */
- #define CCC_BLOCK_READ (1<<2) /* (2) Block read commands */
-@@ -227,6 +253,7 @@
- #define EXT_CSD_BUS_WIDTH 183 /* R/W */
- #define EXT_CSD_HS_TIMING 185 /* R/W */
- #define EXT_CSD_CARD_TYPE 196 /* RO */
-+#define EXT_CSD_REV 192 /* RO */
- #define EXT_CSD_SEC_CNT 212 /* RO, 4 bytes */
-
- /*
---- /dev/null
-+++ b/include/linux/mmc/sdio.h
-@@ -0,0 +1,159 @@
-+/*
-+ * include/linux/mmc/sdio.h
-+ *
-+ * Copyright 2006-2007 Pierre Ossman
-+ *
-+ * 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.
-+ */
-+
-+#ifndef MMC_SDIO_H
-+#define MMC_SDIO_H
-+
-+/* SDIO commands type argument response */
-+#define SD_IO_SEND_OP_COND 5 /* bcr [23:0] OCR R4 */
-+#define SD_IO_RW_DIRECT 52 /* ac [31:0] See below R5 */
-+#define SD_IO_RW_EXTENDED 53 /* adtc [31:0] See below R5 */
-+
-+/*
-+ * SD_IO_RW_DIRECT argument format:
-+ *
-+ * [31] R/W flag
-+ * [30:28] Function number
-+ * [27] RAW flag
-+ * [25:9] Register address
-+ * [7:0] Data
-+ */
-+
-+/*
-+ * SD_IO_RW_EXTENDED argument format:
-+ *
-+ * [31] R/W flag
-+ * [30:28] Function number
-+ * [27] Block mode
-+ * [26] Increment address
-+ * [25:9] Register address
-+ * [8:0] Byte/block count
-+ */
-+
-+/*
-+ SDIO status in R5
-+ Type
-+ e : error bit
-+ s : status bit
-+ r : detected and set for the actual command response
-+ x : detected and set during command execution. the host must poll
-+ the card by sending status command in order to read these bits.
-+ Clear condition
-+ a : according to the card state
-+ b : always related to the previous command. Reception of
-+ a valid command will clear it (with a delay of one command)
-+ c : clear by read
-+ */
-+
-+#define R5_COM_CRC_ERROR (1 << 15) /* er, b */
-+#define R5_ILLEGAL_COMMAND (1 << 14) /* er, b */
-+#define R5_ERROR (1 << 11) /* erx, c */
-+#define R5_FUNCTION_NUMBER (1 << 9) /* er, c */
-+#define R5_OUT_OF_RANGE (1 << 8) /* er, c */
-+#define R5_STATUS(x) (x & 0xCB00)
-+#define R5_IO_CURRENT_STATE(x) ((x & 0x3000) >> 12) /* s, b */
-+
-+/*
-+ * Card Common Control Registers (CCCR)
-+ */
-+
-+#define SDIO_CCCR_CCCR 0x00
-+
-+#define SDIO_CCCR_REV_1_00 0 /* CCCR/FBR Version 1.00 */
-+#define SDIO_CCCR_REV_1_10 1 /* CCCR/FBR Version 1.10 */
-+#define SDIO_CCCR_REV_1_20 2 /* CCCR/FBR Version 1.20 */
-+
-+#define SDIO_SDIO_REV_1_00 0 /* SDIO Spec Version 1.00 */
-+#define SDIO_SDIO_REV_1_10 1 /* SDIO Spec Version 1.10 */
-+#define SDIO_SDIO_REV_1_20 2 /* SDIO Spec Version 1.20 */
-+#define SDIO_SDIO_REV_2_00 3 /* SDIO Spec Version 2.00 */
-+
-+#define SDIO_CCCR_SD 0x01
-+
-+#define SDIO_SD_REV_1_01 0 /* SD Physical Spec Version 1.01 */
-+#define SDIO_SD_REV_1_10 1 /* SD Physical Spec Version 1.10 */
-+#define SDIO_SD_REV_2_00 2 /* SD Physical Spec Version 2.00 */
-+
-+#define SDIO_CCCR_IOEx 0x02
-+#define SDIO_CCCR_IORx 0x03
-+
-+#define SDIO_CCCR_IENx 0x04 /* Function/Master Interrupt Enable */
-+#define SDIO_CCCR_INTx 0x05 /* Function Interrupt Pending */
-+
-+#define SDIO_CCCR_ABORT 0x06 /* function abort/card reset */
-+
-+#define SDIO_CCCR_IF 0x07 /* bus interface controls */
-+
-+#define SDIO_BUS_WIDTH_1BIT 0x00
-+#define SDIO_BUS_WIDTH_4BIT 0x02
-+
-+#define SDIO_BUS_CD_DISABLE 0x80 /* disable pull-up on DAT3 (pin 1) */
-+
-+#define SDIO_CCCR_CAPS 0x08
-+
-+#define SDIO_CCCR_CAP_SDC 0x01 /* can do CMD52 while data transfer */
-+#define SDIO_CCCR_CAP_SMB 0x02 /* can do multi-block xfers (CMD53) */
-+#define SDIO_CCCR_CAP_SRW 0x04 /* supports read-wait protocol */
-+#define SDIO_CCCR_CAP_SBS 0x08 /* supports suspend/resume */
-+#define SDIO_CCCR_CAP_S4MI 0x10 /* interrupt during 4-bit CMD53 */
-+#define SDIO_CCCR_CAP_E4MI 0x20 /* enable ints during 4-bit CMD53 */
-+#define SDIO_CCCR_CAP_LSC 0x40 /* low speed card */
-+#define SDIO_CCCR_CAP_4BLS 0x80 /* 4 bit low speed card */
-+
-+#define SDIO_CCCR_CIS 0x09 /* common CIS pointer (3 bytes) */
-+
-+/* Following 4 regs are valid only if SBS is set */
-+#define SDIO_CCCR_SUSPEND 0x0c
-+#define SDIO_CCCR_SELx 0x0d
-+#define SDIO_CCCR_EXECx 0x0e
-+#define SDIO_CCCR_READYx 0x0f
-+
-+#define SDIO_CCCR_BLKSIZE 0x10
-+
-+#define SDIO_CCCR_POWER 0x12
-+
-+#define SDIO_POWER_SMPC 0x01 /* Supports Master Power Control */
-+#define SDIO_POWER_EMPC 0x02 /* Enable Master Power Control */
-+
-+#define SDIO_CCCR_SPEED 0x13
-+
-+#define SDIO_SPEED_SHS 0x01 /* Supports High-Speed mode */
-+#define SDIO_SPEED_EHS 0x02 /* Enable High-Speed mode */
-+
-+/*
-+ * Function Basic Registers (FBR)
-+ */
-+
-+#define SDIO_FBR_BASE(f) ((f) * 0x100) /* base of function f's FBRs */
-+
-+#define SDIO_FBR_STD_IF 0x00
-+
-+#define SDIO_FBR_SUPPORTS_CSA 0x40 /* supports Code Storage Area */
-+#define SDIO_FBR_ENABLE_CSA 0x80 /* enable Code Storage Area */
-+
-+#define SDIO_FBR_STD_IF_EXT 0x01
-+
-+#define SDIO_FBR_POWER 0x02
-+
-+#define SDIO_FBR_POWER_SPS 0x01 /* Supports Power Selection */
-+#define SDIO_FBR_POWER_EPS 0x02 /* Enable (low) Power Selection */
-+
-+#define SDIO_FBR_CIS 0x09 /* CIS pointer (3 bytes) */
-+
-+
-+#define SDIO_FBR_CSA 0x0C /* CSA pointer (3 bytes) */
-+
-+#define SDIO_FBR_CSA_DATA 0x0F
-+
-+#define SDIO_FBR_BLKSIZE 0x10 /* block size (2 bytes) */
-+
-+#endif
-+
---- /dev/null
-+++ b/include/linux/mmc/sdio_func.h
-@@ -0,0 +1,153 @@
-+/*
-+ * include/linux/mmc/sdio_func.h
-+ *
-+ * Copyright 2007 Pierre Ossman
-+ *
-+ * 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.
-+ */
-+
-+#ifndef MMC_SDIO_FUNC_H
-+#define MMC_SDIO_FUNC_H
-+
-+#include <linux/device.h>
-+#include <linux/mod_devicetable.h>
-+
-+struct mmc_card;
-+struct sdio_func;
-+
-+typedef void (sdio_irq_handler_t)(struct sdio_func *);
-+
-+/*
-+ * SDIO function CIS tuple (unknown to the core)
-+ */
-+struct sdio_func_tuple {
-+ struct sdio_func_tuple *next;
-+ unsigned char code;
-+ unsigned char size;
-+ unsigned char data[0];
-+};
-+
-+/*
-+ * SDIO function devices
-+ */
-+struct sdio_func {
-+ struct mmc_card *card; /* the card this device belongs to */
-+ struct device dev; /* the device */
-+ sdio_irq_handler_t *irq_handler; /* IRQ callback */
-+ unsigned int num; /* function number */
-+
-+ unsigned char class; /* standard interface class */
-+ unsigned short vendor; /* vendor id */
-+ unsigned short device; /* device id */
-+
-+ unsigned max_blksize; /* maximum block size */
-+ unsigned cur_blksize; /* current block size */
-+
-+ unsigned int state; /* function state */
-+#define SDIO_STATE_PRESENT (1<<0) /* present in sysfs */
-+
-+ u8 tmpbuf[4]; /* DMA:able scratch buffer */
-+
-+ unsigned num_info; /* number of info strings */
-+ const char **info; /* info strings */
-+
-+ struct sdio_func_tuple *tuples;
-+};
-+
-+#define sdio_func_present(f) ((f)->state & SDIO_STATE_PRESENT)
-+
-+#define sdio_func_set_present(f) ((f)->state |= SDIO_STATE_PRESENT)
-+
-+#define sdio_func_id(f) ((f)->dev.bus_id)
-+
-+#define sdio_get_drvdata(f) dev_get_drvdata(&(f)->dev)
-+#define sdio_set_drvdata(f,d) dev_set_drvdata(&(f)->dev, d)
-+
-+/*
-+ * SDIO function device driver
-+ */
-+struct sdio_driver {
-+ char *name;
-+ const struct sdio_device_id *id_table;
-+
-+ int (*probe)(struct sdio_func *, const struct sdio_device_id *);
-+ void (*remove)(struct sdio_func *);
-+
-+ struct device_driver drv;
-+};
-+
-+/**
-+ * SDIO_DEVICE - macro used to describe a specific SDIO device
-+ * @vend: the 16 bit manufacturer code
-+ * @dev: the 16 bit function id
-+ *
-+ * This macro is used to create a struct sdio_device_id that matches a
-+ * specific device. The class field will be set to SDIO_ANY_ID.
-+ */
-+#define SDIO_DEVICE(vend,dev) \
-+ .class = SDIO_ANY_ID, \
-+ .vendor = (vend), .device = (dev)
-+
-+/**
-+ * SDIO_DEVICE_CLASS - macro used to describe a specific SDIO device class
-+ * @dev_class: the 8 bit standard interface code
-+ *
-+ * This macro is used to create a struct sdio_device_id that matches a
-+ * specific standard SDIO function type. The vendor and device fields will
-+ * be set to SDIO_ANY_ID.
-+ */
-+#define SDIO_DEVICE_CLASS(dev_class) \
-+ .class = (dev_class), \
-+ .vendor = SDIO_ANY_ID, .device = SDIO_ANY_ID
-+
-+extern int sdio_register_driver(struct sdio_driver *);
-+extern void sdio_unregister_driver(struct sdio_driver *);
-+
-+/*
-+ * SDIO I/O operations
-+ */
-+extern void sdio_claim_host(struct sdio_func *func);
-+extern void sdio_release_host(struct sdio_func *func);
-+
-+extern int sdio_enable_func(struct sdio_func *func);
-+extern int sdio_disable_func(struct sdio_func *func);
-+
-+extern int sdio_set_block_size(struct sdio_func *func, unsigned blksz);
-+
-+extern int sdio_claim_irq(struct sdio_func *func, sdio_irq_handler_t *handler);
-+extern int sdio_release_irq(struct sdio_func *func);
-+
-+extern unsigned char sdio_readb(struct sdio_func *func,
-+ unsigned int addr, int *err_ret);
-+extern unsigned short sdio_readw(struct sdio_func *func,
-+ unsigned int addr, int *err_ret);
-+extern unsigned long sdio_readl(struct sdio_func *func,
-+ unsigned int addr, int *err_ret);
-+
-+extern int sdio_memcpy_fromio(struct sdio_func *func, void *dst,
-+ unsigned int addr, int count);
-+extern int sdio_readsb(struct sdio_func *func, void *dst,
-+ unsigned int addr, int count);
-+
-+extern void sdio_writeb(struct sdio_func *func, unsigned char b,
-+ unsigned int addr, int *err_ret);
-+extern void sdio_writew(struct sdio_func *func, unsigned short b,
-+ unsigned int addr, int *err_ret);
-+extern void sdio_writel(struct sdio_func *func, unsigned long b,
-+ unsigned int addr, int *err_ret);
-+
-+extern int sdio_memcpy_toio(struct sdio_func *func, unsigned int addr,
-+ void *src, int count);
-+extern int sdio_writesb(struct sdio_func *func, unsigned int addr,
-+ void *src, int count);
-+
-+extern unsigned char sdio_f0_readb(struct sdio_func *func,
-+ unsigned int addr, int *err_ret);
-+extern void sdio_f0_writeb(struct sdio_func *func, unsigned char b,
-+ unsigned int addr, int *err_ret);
-+
-+#endif
-+
---- /dev/null
-+++ b/include/linux/mmc/sdio_ids.h
-@@ -0,0 +1,29 @@
-+/*
-+ * SDIO Classes, Interface Types, Manufacturer IDs, etc.
-+ */
-+
-+#ifndef MMC_SDIO_IDS_H
-+#define MMC_SDIO_IDS_H
-+
-+/*
-+ * Standard SDIO Function Interfaces
-+ */
-+
-+#define SDIO_CLASS_NONE 0x00 /* Not a SDIO standard interface */
-+#define SDIO_CLASS_UART 0x01 /* standard UART interface */
-+#define SDIO_CLASS_BT_A 0x02 /* Type-A BlueTooth std interface */
-+#define SDIO_CLASS_BT_B 0x03 /* Type-B BlueTooth std interface */
-+#define SDIO_CLASS_GPS 0x04 /* GPS standard interface */
-+#define SDIO_CLASS_CAMERA 0x05 /* Camera standard interface */
-+#define SDIO_CLASS_PHS 0x06 /* PHS standard interface */
-+#define SDIO_CLASS_WLAN 0x07 /* WLAN interface */
-+#define SDIO_CLASS_ATA 0x08 /* Embedded SDIO-ATA std interface */
-+
-+/*
-+ * Vendors and devices. Sort key: vendor first, device next.
-+ */
-+
-+#define SDIO_VENDOR_ID_MARVELL 0x02df
-+#define SDIO_DEVICE_ID_MARVELL_LIBERTAS 0x9103
-+
-+#endif
---- a/include/linux/mod_devicetable.h
-+++ b/include/linux/mod_devicetable.h
-@@ -22,6 +22,18 @@
- };
-
-
-+/* SDIO */
-+
-+#define SDIO_ANY_ID (~0)
-+
-+struct sdio_device_id {
-+ __u8 class; /* Standard interface or SDIO_ANY_ID */
-+ __u16 vendor; /* Vendor or SDIO_ANY_ID */
-+ __u16 device; /* Device ID or SDIO_ANY_ID */
-+ kernel_ulong_t driver_data; /* Data private to the driver */
-+};
-+
-+
- #define IEEE1394_MATCH_VENDOR_ID 0x0001
- #define IEEE1394_MATCH_MODEL_ID 0x0002
- #define IEEE1394_MATCH_SPECIFIER_ID 0x0004
---- a/drivers/mmc/card/Kconfig
-+++ b/drivers/mmc/card/Kconfig
-@@ -32,3 +32,10 @@
-
- If unsure, say Y here.
-
-+config SDIO_UART
-+ tristate "SDIO UART/GPS class support"
-+ depends on MMC
-+ help
-+ SDIO function driver for SDIO cards that implements the UART
-+ class, as well as the GPS class which appears like a UART.
-+
---- a/drivers/mmc/card/Makefile
-+++ b/drivers/mmc/card/Makefile
-@@ -9,3 +9,5 @@
- obj-$(CONFIG_MMC_BLOCK) += mmc_block.o
- mmc_block-objs := block.o queue.o
-
-+obj-$(CONFIG_SDIO_UART) += sdio_uart.o
-+
---- a/drivers/mmc/card/block.c
-+++ b/drivers/mmc/card/block.c
-@@ -44,6 +44,9 @@
- * max 8 partitions per card
- */
- #define MMC_SHIFT 3
-+#define MMC_NUM_MINORS (256 >> MMC_SHIFT)
-+
-+static unsigned long dev_use[MMC_NUM_MINORS/(8*sizeof(unsigned long))];
-
- /*
- * There is one mmc_blk_data per slot.
-@@ -80,6 +83,9 @@
- mutex_lock(&open_lock);
- md->usage--;
- if (md->usage == 0) {
-+ int devidx = md->disk->first_minor >> MMC_SHIFT;
-+ __clear_bit(devidx, dev_use);
-+
- put_disk(md->disk);
- kfree(md);
- }
-@@ -151,17 +157,19 @@
-
- cmd.opcode = MMC_APP_CMD;
- cmd.arg = card->rca << 16;
-- cmd.flags = MMC_RSP_R1 | MMC_CMD_AC;
-+ cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_AC;
-
- err = mmc_wait_for_cmd(card->host, &cmd, 0);
-- if ((err != MMC_ERR_NONE) || !(cmd.resp[0] & R1_APP_CMD))
-+ if (err)
-+ return (u32)-1;
-+ if (!mmc_host_is_spi(card->host) && !(cmd.resp[0] & R1_APP_CMD))
- return (u32)-1;
-
- memset(&cmd, 0, sizeof(struct mmc_command));
-
- cmd.opcode = SD_APP_SEND_NUM_WR_BLKS;
- cmd.arg = 0;
-- cmd.flags = MMC_RSP_R1 | MMC_CMD_ADTC;
-+ cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_ADTC;
-
- memset(&data, 0, sizeof(struct mmc_data));
-
-@@ -192,7 +200,7 @@
-
- mmc_wait_for_req(card->host, &mrq);
-
-- if (cmd.error != MMC_ERR_NONE || data.error != MMC_ERR_NONE)
-+ if (cmd.error || data.error)
- return (u32)-1;
-
- blocks = ntohl(blocks);
-@@ -220,17 +228,15 @@
- brq.cmd.arg = req->sector;
- if (!mmc_card_blockaddr(card))
- brq.cmd.arg <<= 9;
-- brq.cmd.flags = MMC_RSP_R1 | MMC_CMD_ADTC;
-+ brq.cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_ADTC;
- brq.data.blksz = 1 << md->block_bits;
- brq.stop.opcode = MMC_STOP_TRANSMISSION;
- brq.stop.arg = 0;
-- brq.stop.flags = MMC_RSP_R1B | MMC_CMD_AC;
-+ brq.stop.flags = MMC_RSP_SPI_R1B | MMC_RSP_R1B | MMC_CMD_AC;
- brq.data.blocks = req->nr_sectors >> (md->block_bits - 9);
- if (brq.data.blocks > card->host->max_blk_count)
- brq.data.blocks = card->host->max_blk_count;
-
-- mmc_set_data_timeout(&brq.data, card, rq_data_dir(req) != READ);
--
- /*
- * If the host doesn't support multiple block writes, force
- * block writes to single block. SD cards are excepted from
-@@ -243,8 +249,12 @@
- brq.data.blocks = 1;
-
- if (brq.data.blocks > 1) {
-- brq.data.flags |= MMC_DATA_MULTI;
-- brq.mrq.stop = &brq.stop;
-+ /* SPI multiblock writes terminate using a special
-+ * token, not a STOP_TRANSMISSION request.
-+ */
-+ if (!mmc_host_is_spi(card->host)
-+ || rq_data_dir(req) == READ)
-+ brq.mrq.stop = &brq.stop;
- readcmd = MMC_READ_MULTIPLE_BLOCK;
- writecmd = MMC_WRITE_MULTIPLE_BLOCK;
- } else {
-@@ -261,6 +271,8 @@
- brq.data.flags |= MMC_DATA_WRITE;
- }
-
-+ mmc_set_data_timeout(&brq.data, card);
-+
- brq.data.sg = mq->sg;
- brq.data.sg_len = mmc_queue_map_sg(mq);
-
-@@ -302,7 +314,7 @@
- goto cmd_err;
- }
-
-- if (rq_data_dir(req) != READ) {
-+ if (!mmc_host_is_spi(card->host) && rq_data_dir(req) != READ) {
- do {
- int err;
-
-@@ -315,7 +327,13 @@
- req->rq_disk->disk_name, err);
- goto cmd_err;
- }
-- } while (!(cmd.resp[0] & R1_READY_FOR_DATA));
-+ /*
-+ * Some cards mishandle the status bits,
-+ * so make sure to check both the busy
-+ * indication and the card state.
-+ */
-+ } while (!(cmd.resp[0] & R1_READY_FOR_DATA) ||
-+ (R1_CURRENT_STATE(cmd.resp[0]) == 7));
-
- #if 0
- if (cmd.resp[0] & ~0x00000900)
-@@ -394,9 +412,6 @@
- return 0;
- }
-
--#define MMC_NUM_MINORS (256 >> MMC_SHIFT)
--
--static unsigned long dev_use[MMC_NUM_MINORS/(8*sizeof(unsigned long))];
-
- static inline int mmc_blk_readonly(struct mmc_card *card)
- {
-@@ -510,7 +525,7 @@
- mmc_claim_host(card->host);
- cmd.opcode = MMC_SET_BLOCKLEN;
- cmd.arg = 1 << md->block_bits;
-- cmd.flags = MMC_RSP_R1 | MMC_CMD_AC;
-+ cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_AC;
- err = mmc_wait_for_cmd(card->host, &cmd, 5);
- mmc_release_host(card->host);
-
-@@ -562,17 +577,12 @@
- struct mmc_blk_data *md = mmc_get_drvdata(card);
-
- if (md) {
-- int devidx;
--
- /* Stop new requests from getting into the queue */
- del_gendisk(md->disk);
-
- /* Then flush out any already in there */
- mmc_cleanup_queue(&md->queue);
-
-- devidx = md->disk->first_minor >> MMC_SHIFT;
-- __clear_bit(devidx, dev_use);
--
- mmc_blk_put(md);
- }
- mmc_set_drvdata(card, NULL);
---- a/drivers/mmc/card/queue.c
-+++ b/drivers/mmc/card/queue.c
-@@ -13,6 +13,7 @@
- #include <linux/blkdev.h>
- #include <linux/freezer.h>
- #include <linux/kthread.h>
-+#include <linux/scatterlist.h>
-
- #include <linux/mmc/card.h>
- #include <linux/mmc/host.h>
-@@ -22,6 +23,12 @@
-
- #define MMC_QUEUE_SUSPENDED (1 << 0)
-
-+#define sg_init_table(sg, n) do { \
-+ memset(sg, 0, sizeof(*(sg)) * (n)); \
-+} while (0)
-+
-+#define sg_virt(sg) (page_address((sg)->page) + (sg)->offset)
-+
- /*
- * Prepare a MMC request. This just filters out odd stuff.
- */
-@@ -159,6 +166,7 @@
- ret = -ENOMEM;
- goto cleanup_queue;
- }
-+ sg_init_table(mq->sg, 1);
-
- mq->bounce_sg = kmalloc(sizeof(struct scatterlist) *
- bouncesz / 512, GFP_KERNEL);
-@@ -166,6 +174,7 @@
- ret = -ENOMEM;
- goto cleanup_queue;
- }
-+ sg_init_table(mq->bounce_sg, bouncesz / 512);
- }
- }
- #endif
-@@ -183,6 +192,7 @@
- ret = -ENOMEM;
- goto cleanup_queue;
- }
-+ sg_init_table(mq->sg, host->max_phys_segs);
- }
-
- init_MUTEX(&mq->thread_sem);
-@@ -302,12 +312,12 @@
- BUG_ON(dst_len == 0);
-
- if (dst_size == 0) {
-- dst_buf = page_address(dst->page) + dst->offset;
-+ dst_buf = sg_virt(dst);
- dst_size = dst->length;
- }
-
- if (src_size == 0) {
-- src_buf = page_address(src->page) + src->offset;
-+ src_buf = sg_virt(src);
- src_size = src->length;
- }
-
-@@ -353,9 +363,7 @@
- return 1;
- }
-
-- mq->sg[0].page = virt_to_page(mq->bounce_buf);
-- mq->sg[0].offset = offset_in_page(mq->bounce_buf);
-- mq->sg[0].length = 0;
-+ sg_init_one(mq->sg, mq->bounce_buf, 0);
-
- while (sg_len) {
- mq->sg[0].length += mq->bounce_sg[sg_len - 1].length;
---- /dev/null
-+++ b/drivers/mmc/card/sdio_uart.c
-@@ -0,0 +1,1158 @@
-+/*
-+ * linux/drivers/mmc/card/sdio_uart.c - SDIO UART/GPS driver
-+ *
-+ * Based on drivers/serial/8250.c and drivers/serial/serial_core.c
-+ * by Russell King.
-+ *
-+ * Author: Nicolas Pitre
-+ * Created: June 15, 2007
-+ * Copyright: MontaVista Software, Inc.
-+ *
-+ * 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.
-+ */
-+
-+/*
-+ * Note: Although this driver assumes a 16550A-like UART implementation,
-+ * it is not possible to leverage the common 8250/16550 driver, nor the
-+ * core UART infrastructure, as they assumes direct access to the hardware
-+ * registers, often under a spinlock. This is not possible in the SDIO
-+ * context as SDIO access functions must be able to sleep.
-+ *
-+ * Because we need to lock the SDIO host to ensure an exclusive access to
-+ * the card, we simply rely on that lock to also prevent and serialize
-+ * concurrent access to the same port.
-+ */
-+
-+#include <linux/module.h>
-+#include <linux/init.h>
-+#include <linux/kernel.h>
-+#include <linux/mutex.h>
-+#include <linux/serial_reg.h>
-+#include <linux/circ_buf.h>
-+#include <linux/gfp.h>
-+#include <linux/tty.h>
-+#include <linux/tty_flip.h>
-+
-+#include <linux/mmc/core.h>
-+#include <linux/mmc/card.h>
-+#include <linux/mmc/sdio_func.h>
-+#include <linux/mmc/sdio_ids.h>
-+
-+
-+#define UART_NR 8 /* Number of UARTs this driver can handle */
-+
-+
-+#define UART_XMIT_SIZE PAGE_SIZE
-+#define WAKEUP_CHARS 256
-+
-+#define circ_empty(circ) ((circ)->head == (circ)->tail)
-+#define circ_clear(circ) ((circ)->head = (circ)->tail = 0)
-+
-+#define circ_chars_pending(circ) \
-+ (CIRC_CNT((circ)->head, (circ)->tail, UART_XMIT_SIZE))
-+
-+#define circ_chars_free(circ) \
-+ (CIRC_SPACE((circ)->head, (circ)->tail, UART_XMIT_SIZE))
-+
-+
-+struct uart_icount {
-+ __u32 cts;
-+ __u32 dsr;
-+ __u32 rng;
-+ __u32 dcd;
-+ __u32 rx;
-+ __u32 tx;
-+ __u32 frame;
-+ __u32 overrun;
-+ __u32 parity;
-+ __u32 brk;
-+};
-+
-+struct sdio_uart_port {
-+ struct kref kref;
-+ struct tty_struct *tty;
-+ unsigned int index;
-+ unsigned int opened;
-+ struct mutex open_lock;
-+ struct sdio_func *func;
-+ struct mutex func_lock;
-+ struct task_struct *in_sdio_uart_irq;
-+ unsigned int regs_offset;
-+ struct circ_buf xmit;
-+ spinlock_t write_lock;
-+ struct uart_icount icount;
-+ unsigned int uartclk;
-+ unsigned int mctrl;
-+ unsigned int read_status_mask;
-+ unsigned int ignore_status_mask;
-+ unsigned char x_char;
-+ unsigned char ier;
-+ unsigned char lcr;
-+};
-+
-+static struct sdio_uart_port *sdio_uart_table[UART_NR];
-+static DEFINE_SPINLOCK(sdio_uart_table_lock);
-+
-+static int sdio_uart_add_port(struct sdio_uart_port *port)
-+{
-+ int index, ret = -EBUSY;
-+
-+ kref_init(&port->kref);
-+ mutex_init(&port->open_lock);
-+ mutex_init(&port->func_lock);
-+ spin_lock_init(&port->write_lock);
-+
-+ spin_lock(&sdio_uart_table_lock);
-+ for (index = 0; index < UART_NR; index++) {
-+ if (!sdio_uart_table[index]) {
-+ port->index = index;
-+ sdio_uart_table[index] = port;
-+ ret = 0;
-+ break;
-+ }
-+ }
-+ spin_unlock(&sdio_uart_table_lock);
-+
-+ return ret;
-+}
-+
-+static struct sdio_uart_port *sdio_uart_port_get(unsigned index)
-+{
-+ struct sdio_uart_port *port;
-+
-+ if (index >= UART_NR)
-+ return NULL;
-+
-+ spin_lock(&sdio_uart_table_lock);
-+ port = sdio_uart_table[index];
-+ if (port)
-+ kref_get(&port->kref);
-+ spin_unlock(&sdio_uart_table_lock);
-+
-+ return port;
-+}
-+
-+static void sdio_uart_port_destroy(struct kref *kref)
-+{
-+ struct sdio_uart_port *port =
-+ container_of(kref, struct sdio_uart_port, kref);
-+ kfree(port);
-+}
-+
-+static void sdio_uart_port_put(struct sdio_uart_port *port)
-+{
-+ kref_put(&port->kref, sdio_uart_port_destroy);
-+}
-+
-+static void sdio_uart_port_remove(struct sdio_uart_port *port)
-+{
-+ struct sdio_func *func;
-+
-+ BUG_ON(sdio_uart_table[port->index] != port);
-+
-+ spin_lock(&sdio_uart_table_lock);
-+ sdio_uart_table[port->index] = NULL;
-+ spin_unlock(&sdio_uart_table_lock);
-+
-+ /*
-+ * We're killing a port that potentially still is in use by
-+ * the tty layer. Be careful to prevent any further access
-+ * to the SDIO function and arrange for the tty layer to
-+ * give up on that port ASAP.
-+ * Beware: the lock ordering is critical.
-+ */
-+ mutex_lock(&port->open_lock);
-+ mutex_lock(&port->func_lock);
-+ func = port->func;
-+ sdio_claim_host(func);
-+ port->func = NULL;
-+ mutex_unlock(&port->func_lock);
-+ if (port->opened)
-+ tty_hangup(port->tty);
-+ mutex_unlock(&port->open_lock);
-+ sdio_release_irq(func);
-+ sdio_disable_func(func);
-+ sdio_release_host(func);
-+
-+ sdio_uart_port_put(port);
-+}
-+
-+static int sdio_uart_claim_func(struct sdio_uart_port *port)
-+{
-+ mutex_lock(&port->func_lock);
-+ if (unlikely(!port->func)) {
-+ mutex_unlock(&port->func_lock);
-+ return -ENODEV;
-+ }
-+ if (likely(port->in_sdio_uart_irq != current))
-+ sdio_claim_host(port->func);
-+ mutex_unlock(&port->func_lock);
-+ return 0;
-+}
-+
-+static inline void sdio_uart_release_func(struct sdio_uart_port *port)
-+{
-+ if (likely(port->in_sdio_uart_irq != current))
-+ sdio_release_host(port->func);
-+}
-+
-+static inline unsigned int sdio_in(struct sdio_uart_port *port, int offset)
-+{
-+ unsigned char c;
-+ c = sdio_readb(port->func, port->regs_offset + offset, NULL);
-+ return c;
-+}
-+
-+static inline void sdio_out(struct sdio_uart_port *port, int offset, int value)
-+{
-+ sdio_writeb(port->func, value, port->regs_offset + offset, NULL);
-+}
-+
-+static unsigned int sdio_uart_get_mctrl(struct sdio_uart_port *port)
-+{
-+ unsigned char status;
-+ unsigned int ret;
-+
-+ status = sdio_in(port, UART_MSR);
-+
-+ ret = 0;
-+ if (status & UART_MSR_DCD)
-+ ret |= TIOCM_CAR;
-+ if (status & UART_MSR_RI)
-+ ret |= TIOCM_RNG;
-+ if (status & UART_MSR_DSR)
-+ ret |= TIOCM_DSR;
-+ if (status & UART_MSR_CTS)
-+ ret |= TIOCM_CTS;
-+ return ret;
-+}
-+
-+static void sdio_uart_write_mctrl(struct sdio_uart_port *port, unsigned int mctrl)
-+{
-+ unsigned char mcr = 0;
-+
-+ if (mctrl & TIOCM_RTS)
-+ mcr |= UART_MCR_RTS;
-+ if (mctrl & TIOCM_DTR)
-+ mcr |= UART_MCR_DTR;
-+ if (mctrl & TIOCM_OUT1)
-+ mcr |= UART_MCR_OUT1;
-+ if (mctrl & TIOCM_OUT2)
-+ mcr |= UART_MCR_OUT2;
-+ if (mctrl & TIOCM_LOOP)
-+ mcr |= UART_MCR_LOOP;
-+
-+ sdio_out(port, UART_MCR, mcr);
-+}
-+
-+static inline void sdio_uart_update_mctrl(struct sdio_uart_port *port,
-+ unsigned int set, unsigned int clear)
-+{
-+ unsigned int old;
-+
-+ old = port->mctrl;
-+ port->mctrl = (old & ~clear) | set;
-+ if (old != port->mctrl)
-+ sdio_uart_write_mctrl(port, port->mctrl);
-+}
-+
-+#define sdio_uart_set_mctrl(port, x) sdio_uart_update_mctrl(port, x, 0)
-+#define sdio_uart_clear_mctrl(port, x) sdio_uart_update_mctrl(port, 0, x)
-+
-+static void sdio_uart_change_speed(struct sdio_uart_port *port,
-+ struct ktermios *termios,
-+ struct ktermios *old)
-+{
-+ unsigned char cval, fcr = 0;
-+ unsigned int baud, quot;
-+
-+ switch (termios->c_cflag & CSIZE) {
-+ case CS5:
-+ cval = UART_LCR_WLEN5;
-+ break;
-+ case CS6:
-+ cval = UART_LCR_WLEN6;
-+ break;
-+ case CS7:
-+ cval = UART_LCR_WLEN7;
-+ break;
-+ default:
-+ case CS8:
-+ cval = UART_LCR_WLEN8;
-+ break;
-+ }
-+
-+ if (termios->c_cflag & CSTOPB)
-+ cval |= UART_LCR_STOP;
-+ if (termios->c_cflag & PARENB)
-+ cval |= UART_LCR_PARITY;
-+ if (!(termios->c_cflag & PARODD))
-+ cval |= UART_LCR_EPAR;
-+
-+ for (;;) {
-+ baud = tty_termios_baud_rate(termios);
-+ if (baud == 0)
-+ baud = 9600; /* Special case: B0 rate. */
-+ if (baud <= port->uartclk)
-+ break;
-+ /*
-+ * Oops, the quotient was zero. Try again with the old
-+ * baud rate if possible, otherwise default to 9600.
-+ */
-+ termios->c_cflag &= ~CBAUD;
-+ if (old) {
-+ termios->c_cflag |= old->c_cflag & CBAUD;
-+ old = NULL;
-+ } else
-+ termios->c_cflag |= B9600;
-+ }
-+ quot = (2 * port->uartclk + baud) / (2 * baud);
-+
-+ if (baud < 2400)
-+ fcr = UART_FCR_ENABLE_FIFO | UART_FCR_TRIGGER_1;
-+ else
-+ fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10;
-+
-+ port->read_status_mask = UART_LSR_OE | UART_LSR_THRE | UART_LSR_DR;
-+ if (termios->c_iflag & INPCK)
-+ port->read_status_mask |= UART_LSR_FE | UART_LSR_PE;
-+ if (termios->c_iflag & (BRKINT | PARMRK))
-+ port->read_status_mask |= UART_LSR_BI;
-+
-+ /*
-+ * Characters to ignore
-+ */
-+ port->ignore_status_mask = 0;
-+ if (termios->c_iflag & IGNPAR)
-+ port->ignore_status_mask |= UART_LSR_PE | UART_LSR_FE;
-+ if (termios->c_iflag & IGNBRK) {
-+ port->ignore_status_mask |= UART_LSR_BI;
-+ /*
-+ * If we're ignoring parity and break indicators,
-+ * ignore overruns too (for real raw support).
-+ */
-+ if (termios->c_iflag & IGNPAR)
-+ port->ignore_status_mask |= UART_LSR_OE;
-+ }
-+
-+ /*
-+ * ignore all characters if CREAD is not set
-+ */
-+ if ((termios->c_cflag & CREAD) == 0)
-+ port->ignore_status_mask |= UART_LSR_DR;
-+
-+ /*
-+ * CTS flow control flag and modem status interrupts
-+ */
-+ port->ier &= ~UART_IER_MSI;
-+ if ((termios->c_cflag & CRTSCTS) || !(termios->c_cflag & CLOCAL))
-+ port->ier |= UART_IER_MSI;
-+
-+ port->lcr = cval;
-+
-+ sdio_out(port, UART_IER, port->ier);
-+ sdio_out(port, UART_LCR, cval | UART_LCR_DLAB);
-+ sdio_out(port, UART_DLL, quot & 0xff);
-+ sdio_out(port, UART_DLM, quot >> 8);
-+ sdio_out(port, UART_LCR, cval);
-+ sdio_out(port, UART_FCR, fcr);
-+
-+ sdio_uart_write_mctrl(port, port->mctrl);
-+}
-+
-+static void sdio_uart_start_tx(struct sdio_uart_port *port)
-+{
-+ if (!(port->ier & UART_IER_THRI)) {
-+ port->ier |= UART_IER_THRI;
-+ sdio_out(port, UART_IER, port->ier);
-+ }
-+}
-+
-+static void sdio_uart_stop_tx(struct sdio_uart_port *port)
-+{
-+ if (port->ier & UART_IER_THRI) {
-+ port->ier &= ~UART_IER_THRI;
-+ sdio_out(port, UART_IER, port->ier);
-+ }
-+}
-+
-+static void sdio_uart_stop_rx(struct sdio_uart_port *port)
-+{
-+ port->ier &= ~UART_IER_RLSI;
-+ port->read_status_mask &= ~UART_LSR_DR;
-+ sdio_out(port, UART_IER, port->ier);
-+}
-+
-+static void sdio_uart_receive_chars(struct sdio_uart_port *port, unsigned int *status)
-+{
-+ struct tty_struct *tty = port->tty;
-+ unsigned int ch, flag;
-+ int max_count = 256;
-+
-+ do {
-+ ch = sdio_in(port, UART_RX);
-+ flag = TTY_NORMAL;
-+ port->icount.rx++;
-+
-+ if (unlikely(*status & (UART_LSR_BI | UART_LSR_PE |
-+ UART_LSR_FE | UART_LSR_OE))) {
-+ /*
-+ * For statistics only
-+ */
-+ if (*status & UART_LSR_BI) {
-+ *status &= ~(UART_LSR_FE | UART_LSR_PE);
-+ port->icount.brk++;
-+ } else if (*status & UART_LSR_PE)
-+ port->icount.parity++;
-+ else if (*status & UART_LSR_FE)
-+ port->icount.frame++;
-+ if (*status & UART_LSR_OE)
-+ port->icount.overrun++;
-+
-+ /*
-+ * Mask off conditions which should be ignored.
-+ */
-+ *status &= port->read_status_mask;
-+ if (*status & UART_LSR_BI) {
-+ flag = TTY_BREAK;
-+ } else if (*status & UART_LSR_PE)
-+ flag = TTY_PARITY;
-+ else if (*status & UART_LSR_FE)
-+ flag = TTY_FRAME;
-+ }
-+
-+ if ((*status & port->ignore_status_mask & ~UART_LSR_OE) == 0)
-+ tty_insert_flip_char(tty, ch, flag);
-+
-+ /*
-+ * Overrun is special. Since it's reported immediately,
-+ * it doesn't affect the current character.
-+ */
-+ if (*status & ~port->ignore_status_mask & UART_LSR_OE)
-+ tty_insert_flip_char(tty, 0, TTY_OVERRUN);
-+
-+ *status = sdio_in(port, UART_LSR);
-+ } while ((*status & UART_LSR_DR) && (max_count-- > 0));
-+ tty_flip_buffer_push(tty);
-+}
-+
-+static void sdio_uart_transmit_chars(struct sdio_uart_port *port)
-+{
-+ struct circ_buf *xmit = &port->xmit;
-+ int count;
-+
-+ if (port->x_char) {
-+ sdio_out(port, UART_TX, port->x_char);
-+ port->icount.tx++;
-+ port->x_char = 0;
-+ return;
-+ }
-+ if (circ_empty(xmit) || port->tty->stopped || port->tty->hw_stopped) {
-+ sdio_uart_stop_tx(port);
-+ return;
-+ }
-+
-+ count = 16;
-+ do {
-+ sdio_out(port, UART_TX, xmit->buf[xmit->tail]);
-+ xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
-+ port->icount.tx++;
-+ if (circ_empty(xmit))
-+ break;
-+ } while (--count > 0);
-+
-+ if (circ_chars_pending(xmit) < WAKEUP_CHARS)
-+ tty_wakeup(port->tty);
-+
-+ if (circ_empty(xmit))
-+ sdio_uart_stop_tx(port);
-+}
-+
-+static void sdio_uart_check_modem_status(struct sdio_uart_port *port)
-+{
-+ int status;
-+
-+ status = sdio_in(port, UART_MSR);
-+
-+ if ((status & UART_MSR_ANY_DELTA) == 0)
-+ return;
-+
-+ if (status & UART_MSR_TERI)
-+ port->icount.rng++;
-+ if (status & UART_MSR_DDSR)
-+ port->icount.dsr++;
-+ if (status & UART_MSR_DDCD)
-+ port->icount.dcd++;
-+ if (status & UART_MSR_DCTS) {
-+ port->icount.cts++;
-+ if (port->tty->termios->c_cflag & CRTSCTS) {
-+ int cts = (status & UART_MSR_CTS);
-+ if (port->tty->hw_stopped) {
-+ if (cts) {
-+ port->tty->hw_stopped = 0;
-+ sdio_uart_start_tx(port);
-+ tty_wakeup(port->tty);
-+ }
-+ } else {
-+ if (!cts) {
-+ port->tty->hw_stopped = 1;
-+ sdio_uart_stop_tx(port);
-+ }
-+ }
-+ }
-+ }
-+}
-+
-+/*
-+ * This handles the interrupt from one port.
-+ */
-+static void sdio_uart_irq(struct sdio_func *func)
-+{
-+ struct sdio_uart_port *port = sdio_get_drvdata(func);
-+ unsigned int iir, lsr;
-+
-+ /*
-+ * In a few places sdio_uart_irq() is called directly instead of
-+ * waiting for the actual interrupt to be raised and the SDIO IRQ
-+ * thread scheduled in order to reduce latency. However, some
-+ * interaction with the tty core may end up calling us back
-+ * (serial echo, flow control, etc.) through those same places
-+ * causing undesirable effects. Let's stop the recursion here.
-+ */
-+ if (unlikely(port->in_sdio_uart_irq == current))
-+ return;
-+
-+ iir = sdio_in(port, UART_IIR);
-+ if (iir & UART_IIR_NO_INT)
-+ return;
-+
-+ port->in_sdio_uart_irq = current;
-+ lsr = sdio_in(port, UART_LSR);
-+ if (lsr & UART_LSR_DR)
-+ sdio_uart_receive_chars(port, &lsr);
-+ sdio_uart_check_modem_status(port);
-+ if (lsr & UART_LSR_THRE)
-+ sdio_uart_transmit_chars(port);
-+ port->in_sdio_uart_irq = NULL;
-+}
-+
-+static int sdio_uart_startup(struct sdio_uart_port *port)
-+{
-+ unsigned long page;
-+ int ret;
-+
-+ /*
-+ * Set the TTY IO error marker - we will only clear this
-+ * once we have successfully opened the port.
-+ */
-+ set_bit(TTY_IO_ERROR, &port->tty->flags);
-+
-+ /* Initialise and allocate the transmit buffer. */
-+ page = __get_free_page(GFP_KERNEL);
-+ if (!page)
-+ return -ENOMEM;
-+ port->xmit.buf = (unsigned char *)page;
-+ circ_clear(&port->xmit);
-+
-+ ret = sdio_uart_claim_func(port);
-+ if (ret)
-+ goto err1;
-+ ret = sdio_enable_func(port->func);
-+ if (ret)
-+ goto err2;
-+ ret = sdio_claim_irq(port->func, sdio_uart_irq);
-+ if (ret)
-+ goto err3;
-+
-+ /*
-+ * Clear the FIFO buffers and disable them.
-+ * (they will be reenabled in sdio_change_speed())
-+ */
-+ sdio_out(port, UART_FCR, UART_FCR_ENABLE_FIFO);
-+ sdio_out(port, UART_FCR, UART_FCR_ENABLE_FIFO |
-+ UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT);
-+ sdio_out(port, UART_FCR, 0);
-+
-+ /*
-+ * Clear the interrupt registers.
-+ */
-+ (void) sdio_in(port, UART_LSR);
-+ (void) sdio_in(port, UART_RX);
-+ (void) sdio_in(port, UART_IIR);
-+ (void) sdio_in(port, UART_MSR);
-+
-+ /*
-+ * Now, initialize the UART
-+ */
-+ sdio_out(port, UART_LCR, UART_LCR_WLEN8);
-+
-+ port->ier = UART_IER_RLSI | UART_IER_RDI | UART_IER_RTOIE | UART_IER_UUE;
-+ port->mctrl = TIOCM_OUT2;
-+
-+ sdio_uart_change_speed(port, port->tty->termios, NULL);
-+
-+ if (port->tty->termios->c_cflag & CBAUD)
-+ sdio_uart_set_mctrl(port, TIOCM_RTS | TIOCM_DTR);
-+
-+ if (port->tty->termios->c_cflag & CRTSCTS)
-+ if (!(sdio_uart_get_mctrl(port) & TIOCM_CTS))
-+ port->tty->hw_stopped = 1;
-+
-+ clear_bit(TTY_IO_ERROR, &port->tty->flags);
-+
-+ /* Kick the IRQ handler once while we're still holding the host lock */
-+ sdio_uart_irq(port->func);
-+
-+ sdio_uart_release_func(port);
-+ return 0;
-+
-+err3:
-+ sdio_disable_func(port->func);
-+err2:
-+ sdio_uart_release_func(port);
-+err1:
-+ free_page((unsigned long)port->xmit.buf);
-+ return ret;
-+}
-+
-+static void sdio_uart_shutdown(struct sdio_uart_port *port)
-+{
-+ int ret;
-+
-+ ret = sdio_uart_claim_func(port);
-+ if (ret)
-+ goto skip;
-+
-+ sdio_uart_stop_rx(port);
-+
-+ /* TODO: wait here for TX FIFO to drain */
-+
-+ /* Turn off DTR and RTS early. */
-+ if (port->tty->termios->c_cflag & HUPCL)
-+ sdio_uart_clear_mctrl(port, TIOCM_DTR | TIOCM_RTS);
-+
-+ /* Disable interrupts from this port */
-+ sdio_release_irq(port->func);
-+ port->ier = 0;
-+ sdio_out(port, UART_IER, 0);
-+
-+ sdio_uart_clear_mctrl(port, TIOCM_OUT2);
-+
-+ /* Disable break condition and FIFOs. */
-+ port->lcr &= ~UART_LCR_SBC;
-+ sdio_out(port, UART_LCR, port->lcr);
-+ sdio_out(port, UART_FCR, UART_FCR_ENABLE_FIFO |
-+ UART_FCR_CLEAR_RCVR |
-+ UART_FCR_CLEAR_XMIT);
-+ sdio_out(port, UART_FCR, 0);
-+
-+ sdio_disable_func(port->func);
-+
-+ sdio_uart_release_func(port);
-+
-+skip:
-+ /* Free the transmit buffer page. */
-+ free_page((unsigned long)port->xmit.buf);
-+}
-+
-+static int sdio_uart_open (struct tty_struct *tty, struct file * filp)
-+{
-+ struct sdio_uart_port *port;
-+ int ret;
-+
-+ port = sdio_uart_port_get(tty->index);
-+ if (!port)
-+ return -ENODEV;
-+
-+ mutex_lock(&port->open_lock);
-+
-+ /*
-+ * Make sure not to mess up with a dead port
-+ * which has not been closed yet.
-+ */
-+ if (tty->driver_data && tty->driver_data != port) {
-+ mutex_unlock(&port->open_lock);
-+ sdio_uart_port_put(port);
-+ return -EBUSY;
-+ }
-+
-+ if (!port->opened) {
-+ tty->driver_data = port;
-+ port->tty = tty;
-+ ret = sdio_uart_startup(port);
-+ if (ret) {
-+ tty->driver_data = NULL;
-+ port->tty = NULL;
-+ mutex_unlock(&port->open_lock);
-+ sdio_uart_port_put(port);
-+ return ret;
-+ }
-+ }
-+ port->opened++;
-+ mutex_unlock(&port->open_lock);
-+ return 0;
-+}
-+
-+static void sdio_uart_close(struct tty_struct *tty, struct file * filp)
-+{
-+ struct sdio_uart_port *port = tty->driver_data;
-+
-+ if (!port)
-+ return;
-+
-+ mutex_lock(&port->open_lock);
-+ BUG_ON(!port->opened);
-+
-+ /*
-+ * This is messy. The tty layer calls us even when open()
-+ * returned an error. Ignore this close request if tty->count
-+ * is larger than port->count.
-+ */
-+ if (tty->count > port->opened) {
-+ mutex_unlock(&port->open_lock);
-+ return;
-+ }
-+
-+ if (--port->opened == 0) {
-+ tty->closing = 1;
-+ sdio_uart_shutdown(port);
-+ tty_ldisc_flush(tty);
-+ port->tty = NULL;
-+ tty->driver_data = NULL;
-+ tty->closing = 0;
-+ }
-+ mutex_unlock(&port->open_lock);
-+ sdio_uart_port_put(port);
-+}
-+
-+static int sdio_uart_write(struct tty_struct * tty, const unsigned char *buf,
-+ int count)
-+{
-+ struct sdio_uart_port *port = tty->driver_data;
-+ struct circ_buf *circ = &port->xmit;
-+ int c, ret = 0;
-+
-+ if (!port->func)
-+ return -ENODEV;
-+
-+ spin_lock(&port->write_lock);
-+ while (1) {
-+ c = CIRC_SPACE_TO_END(circ->head, circ->tail, UART_XMIT_SIZE);
-+ if (count < c)
-+ c = count;
-+ if (c <= 0)
-+ break;
-+ memcpy(circ->buf + circ->head, buf, c);
-+ circ->head = (circ->head + c) & (UART_XMIT_SIZE - 1);
-+ buf += c;
-+ count -= c;
-+ ret += c;
-+ }
-+ spin_unlock(&port->write_lock);
-+
-+ if ( !(port->ier & UART_IER_THRI)) {
-+ int err = sdio_uart_claim_func(port);
-+ if (!err) {
-+ sdio_uart_start_tx(port);
-+ sdio_uart_irq(port->func);
-+ sdio_uart_release_func(port);
-+ } else
-+ ret = err;
-+ }
-+
-+ return ret;
-+}
-+
-+static int sdio_uart_write_room(struct tty_struct *tty)
-+{
-+ struct sdio_uart_port *port = tty->driver_data;
-+ return port ? circ_chars_free(&port->xmit) : 0;
-+}
-+
-+static int sdio_uart_chars_in_buffer(struct tty_struct *tty)
-+{
-+ struct sdio_uart_port *port = tty->driver_data;
-+ return port ? circ_chars_pending(&port->xmit) : 0;
-+}
-+
-+static void sdio_uart_send_xchar(struct tty_struct *tty, char ch)
-+{
-+ struct sdio_uart_port *port = tty->driver_data;
-+
-+ port->x_char = ch;
-+ if (ch && !(port->ier & UART_IER_THRI)) {
-+ if (sdio_uart_claim_func(port) != 0)
-+ return;
-+ sdio_uart_start_tx(port);
-+ sdio_uart_irq(port->func);
-+ sdio_uart_release_func(port);
-+ }
-+}
-+
-+static void sdio_uart_throttle(struct tty_struct *tty)
-+{
-+ struct sdio_uart_port *port = tty->driver_data;
-+
-+ if (!I_IXOFF(tty) && !(tty->termios->c_cflag & CRTSCTS))
-+ return;
-+
-+ if (sdio_uart_claim_func(port) != 0)
-+ return;
-+
-+ if (I_IXOFF(tty)) {
-+ port->x_char = STOP_CHAR(tty);
-+ sdio_uart_start_tx(port);
-+ }
-+
-+ if (tty->termios->c_cflag & CRTSCTS)
-+ sdio_uart_clear_mctrl(port, TIOCM_RTS);
-+
-+ sdio_uart_irq(port->func);
-+ sdio_uart_release_func(port);
-+}
-+
-+static void sdio_uart_unthrottle(struct tty_struct *tty)
-+{
-+ struct sdio_uart_port *port = tty->driver_data;
-+
-+ if (!I_IXOFF(tty) && !(tty->termios->c_cflag & CRTSCTS))
-+ return;
-+
-+ if (sdio_uart_claim_func(port) != 0)
-+ return;
-+
-+ if (I_IXOFF(tty)) {
-+ if (port->x_char) {
-+ port->x_char = 0;
-+ } else {
-+ port->x_char = START_CHAR(tty);
-+ sdio_uart_start_tx(port);
-+ }
-+ }
-+
-+ if (tty->termios->c_cflag & CRTSCTS)
-+ sdio_uart_set_mctrl(port, TIOCM_RTS);
-+
-+ sdio_uart_irq(port->func);
-+ sdio_uart_release_func(port);
-+}
-+
-+static void sdio_uart_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
-+{
-+ struct sdio_uart_port *port = tty->driver_data;
-+ unsigned int cflag = tty->termios->c_cflag;
-+
-+#define RELEVANT_IFLAG(iflag) ((iflag) & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK))
-+
-+ if ((cflag ^ old_termios->c_cflag) == 0 &&
-+ RELEVANT_IFLAG(tty->termios->c_iflag ^ old_termios->c_iflag) == 0)
-+ return;
-+
-+ if (sdio_uart_claim_func(port) != 0)
-+ return;
-+
-+ sdio_uart_change_speed(port, tty->termios, old_termios);
-+
-+ /* Handle transition to B0 status */
-+ if ((old_termios->c_cflag & CBAUD) && !(cflag & CBAUD))
-+ sdio_uart_clear_mctrl(port, TIOCM_RTS | TIOCM_DTR);
-+
-+ /* Handle transition away from B0 status */
-+ if (!(old_termios->c_cflag & CBAUD) && (cflag & CBAUD)) {
-+ unsigned int mask = TIOCM_DTR;
-+ if (!(cflag & CRTSCTS) || !test_bit(TTY_THROTTLED, &tty->flags))
-+ mask |= TIOCM_RTS;
-+ sdio_uart_set_mctrl(port, mask);
-+ }
-+
-+ /* Handle turning off CRTSCTS */
-+ if ((old_termios->c_cflag & CRTSCTS) && !(cflag & CRTSCTS)) {
-+ tty->hw_stopped = 0;
-+ sdio_uart_start_tx(port);
-+ }
-+
-+ /* Handle turning on CRTSCTS */
-+ if (!(old_termios->c_cflag & CRTSCTS) && (cflag & CRTSCTS)) {
-+ if (!(sdio_uart_get_mctrl(port) & TIOCM_CTS)) {
-+ tty->hw_stopped = 1;
-+ sdio_uart_stop_tx(port);
-+ }
-+ }
-+
-+ sdio_uart_release_func(port);
-+}
-+
-+static void sdio_uart_break_ctl(struct tty_struct *tty, int break_state)
-+{
-+ struct sdio_uart_port *port = tty->driver_data;
-+
-+ if (sdio_uart_claim_func(port) != 0)
-+ return;
-+
-+ if (break_state == -1)
-+ port->lcr |= UART_LCR_SBC;
-+ else
-+ port->lcr &= ~UART_LCR_SBC;
-+ sdio_out(port, UART_LCR, port->lcr);
-+
-+ sdio_uart_release_func(port);
-+}
-+
-+static int sdio_uart_tiocmget(struct tty_struct *tty, struct file *file)
-+{
-+ struct sdio_uart_port *port = tty->driver_data;
-+ int result;
-+
-+ result = sdio_uart_claim_func(port);
-+ if (!result) {
-+ result = port->mctrl | sdio_uart_get_mctrl(port);
-+ sdio_uart_release_func(port);
-+ }
-+
-+ return result;
-+}
-+
-+static int sdio_uart_tiocmset(struct tty_struct *tty, struct file *file,
-+ unsigned int set, unsigned int clear)
-+{
-+ struct sdio_uart_port *port = tty->driver_data;
-+ int result;
-+
-+ result =sdio_uart_claim_func(port);
-+ if(!result) {
-+ sdio_uart_update_mctrl(port, set, clear);
-+ sdio_uart_release_func(port);
-+ }
-+
-+ return result;
-+}
-+
-+static int sdio_uart_read_proc(char *page, char **start, off_t off,
-+ int count, int *eof, void *data)
-+{
-+ int i, len = 0;
-+ off_t begin = 0;
-+
-+ len += sprintf(page, "serinfo:1.0 driver%s%s revision:%s\n",
-+ "", "", "");
-+ for (i = 0; i < UART_NR && len < PAGE_SIZE - 96; i++) {
-+ struct sdio_uart_port *port = sdio_uart_port_get(i);
-+ if (port) {
-+ len += sprintf(page+len, "%d: uart:SDIO", i);
-+ if(capable(CAP_SYS_ADMIN)) {
-+ len += sprintf(page + len, " tx:%d rx:%d",
-+ port->icount.tx, port->icount.rx);
-+ if (port->icount.frame)
-+ len += sprintf(page + len, " fe:%d",
-+ port->icount.frame);
-+ if (port->icount.parity)
-+ len += sprintf(page + len, " pe:%d",
-+ port->icount.parity);
-+ if (port->icount.brk)
-+ len += sprintf(page + len, " brk:%d",
-+ port->icount.brk);
-+ if (port->icount.overrun)
-+ len += sprintf(page + len, " oe:%d",
-+ port->icount.overrun);
-+ if (port->icount.cts)
-+ len += sprintf(page + len, " cts:%d",
-+ port->icount.cts);
-+ if (port->icount.dsr)
-+ len += sprintf(page + len, " dsr:%d",
-+ port->icount.dsr);
-+ if (port->icount.rng)
-+ len += sprintf(page + len, " rng:%d",
-+ port->icount.rng);
-+ if (port->icount.dcd)
-+ len += sprintf(page + len, " dcd:%d",
-+ port->icount.dcd);
-+ }
-+ strcat(page, "\n");
-+ len++;
-+ sdio_uart_port_put(port);
-+ }
-+
-+ if (len + begin > off + count)
-+ goto done;
-+ if (len + begin < off) {
-+ begin += len;
-+ len = 0;
-+ }
-+ }
-+ *eof = 1;
-+
-+done:
-+ if (off >= len + begin)
-+ return 0;
-+ *start = page + (off - begin);
-+ return (count < begin + len - off) ? count : (begin + len - off);
-+}
-+
-+static const struct tty_operations sdio_uart_ops = {
-+ .open = sdio_uart_open,
-+ .close = sdio_uart_close,
-+ .write = sdio_uart_write,
-+ .write_room = sdio_uart_write_room,
-+ .chars_in_buffer = sdio_uart_chars_in_buffer,
-+ .send_xchar = sdio_uart_send_xchar,
-+ .throttle = sdio_uart_throttle,
-+ .unthrottle = sdio_uart_unthrottle,
-+ .set_termios = sdio_uart_set_termios,
-+ .break_ctl = sdio_uart_break_ctl,
-+ .tiocmget = sdio_uart_tiocmget,
-+ .tiocmset = sdio_uart_tiocmset,
-+ .read_proc = sdio_uart_read_proc,
-+};
-+
-+static struct tty_driver *sdio_uart_tty_driver;
-+
-+static int sdio_uart_probe(struct sdio_func *func,
-+ const struct sdio_device_id *id)
-+{
-+ struct sdio_uart_port *port;
-+ int ret;
-+
-+ port = kzalloc(sizeof(struct sdio_uart_port), GFP_KERNEL);
-+ if (!port)
-+ return -ENOMEM;
-+
-+ if (func->class == SDIO_CLASS_UART) {
-+ printk(KERN_WARNING "%s: need info on UART class basic setup\n",
-+ sdio_func_id(func));
-+ kfree(port);
-+ return -ENOSYS;
-+ } else if (func->class == SDIO_CLASS_GPS) {
-+ /*
-+ * We need tuple 0x91. It contains SUBTPL_SIOREG
-+ * and SUBTPL_RCVCAPS.
-+ */
-+ struct sdio_func_tuple *tpl;
-+ for (tpl = func->tuples; tpl; tpl = tpl->next) {
-+ if (tpl->code != 0x91)
-+ continue;
-+ if (tpl->size < 10)
-+ continue;
-+ if (tpl->data[1] == 0) /* SUBTPL_SIOREG */
-+ break;
-+ }
-+ if (!tpl) {
-+ printk(KERN_WARNING
-+ "%s: can't find tuple 0x91 subtuple 0 (SUBTPL_SIOREG) for GPS class\n",
-+ sdio_func_id(func));
-+ kfree(port);
-+ return -EINVAL;
-+ }
-+ printk(KERN_DEBUG "%s: Register ID = 0x%02x, Exp ID = 0x%02x\n",
-+ sdio_func_id(func), tpl->data[2], tpl->data[3]);
-+ port->regs_offset = (tpl->data[4] << 0) |
-+ (tpl->data[5] << 8) |
-+ (tpl->data[6] << 16);
-+ printk(KERN_DEBUG "%s: regs offset = 0x%x\n",
-+ sdio_func_id(func), port->regs_offset);
-+ port->uartclk = tpl->data[7] * 115200;
-+ if (port->uartclk == 0)
-+ port->uartclk = 115200;
-+ printk(KERN_DEBUG "%s: clk %d baudcode %u 4800-div %u\n",
-+ sdio_func_id(func), port->uartclk,
-+ tpl->data[7], tpl->data[8] | (tpl->data[9] << 8));
-+ } else {
-+ kfree(port);
-+ return -EINVAL;
-+ }
-+
-+ port->func = func;
-+ sdio_set_drvdata(func, port);
-+
-+ ret = sdio_uart_add_port(port);
-+ if (ret) {
-+ kfree(port);
-+ } else {
-+ struct device *dev;
-+ dev = tty_register_device(sdio_uart_tty_driver, port->index, &func->dev);
-+ if (IS_ERR(dev)) {
-+ sdio_uart_port_remove(port);
-+ ret = PTR_ERR(dev);
-+ }
-+ }
-+
-+ return ret;
-+}
-+
-+static void sdio_uart_remove(struct sdio_func *func)
-+{
-+ struct sdio_uart_port *port = sdio_get_drvdata(func);
-+
-+ tty_unregister_device(sdio_uart_tty_driver, port->index);
-+ sdio_uart_port_remove(port);
-+}
-+
-+static const struct sdio_device_id sdio_uart_ids[] = {
-+ { SDIO_DEVICE_CLASS(SDIO_CLASS_UART) },
-+ { SDIO_DEVICE_CLASS(SDIO_CLASS_GPS) },
-+ { /* end: all zeroes */ },
-+};
-+
-+MODULE_DEVICE_TABLE(sdio, sdio_uart_ids);
-+
-+static struct sdio_driver sdio_uart_driver = {
-+ .probe = sdio_uart_probe,
-+ .remove = sdio_uart_remove,
-+ .name = "sdio_uart",
-+ .id_table = sdio_uart_ids,
-+};
-+
-+static int __init sdio_uart_init(void)
-+{
-+ int ret;
-+ struct tty_driver *tty_drv;
-+
-+ sdio_uart_tty_driver = tty_drv = alloc_tty_driver(UART_NR);
-+ if (!tty_drv)
-+ return -ENOMEM;
-+
-+ tty_drv->owner = THIS_MODULE;
-+ tty_drv->driver_name = "sdio_uart";
-+ tty_drv->name = "ttySDIO";
-+ tty_drv->major = 0; /* dynamically allocated */
-+ tty_drv->minor_start = 0;
-+ tty_drv->type = TTY_DRIVER_TYPE_SERIAL;
-+ tty_drv->subtype = SERIAL_TYPE_NORMAL;
-+ tty_drv->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
-+ tty_drv->init_termios = tty_std_termios;
-+ tty_drv->init_termios.c_cflag = B4800 | CS8 | CREAD | HUPCL | CLOCAL;
-+ tty_drv->init_termios.c_ispeed = 4800;
-+ tty_drv->init_termios.c_ospeed = 4800;
-+ tty_set_operations(tty_drv, &sdio_uart_ops);
-+
-+ ret = tty_register_driver(tty_drv);
-+ if (ret)
-+ goto err1;
-+
-+ ret = sdio_register_driver(&sdio_uart_driver);
-+ if (ret)
-+ goto err2;
-+
-+ return 0;
-+
-+err2:
-+ tty_unregister_driver(tty_drv);
-+err1:
-+ put_tty_driver(tty_drv);
-+ return ret;
-+}
-+
-+static void __exit sdio_uart_exit(void)
-+{
-+ sdio_unregister_driver(&sdio_uart_driver);
-+ tty_unregister_driver(sdio_uart_tty_driver);
-+ put_tty_driver(sdio_uart_tty_driver);
-+}
-+
-+module_init(sdio_uart_init);
-+module_exit(sdio_uart_exit);
-+
-+MODULE_AUTHOR("Nicolas Pitre");
-+MODULE_LICENSE("GPL");
---- a/drivers/mmc/core/Makefile
-+++ b/drivers/mmc/core/Makefile
-@@ -8,5 +8,7 @@
-
- obj-$(CONFIG_MMC) += mmc_core.o
- mmc_core-y := core.o sysfs.o bus.o host.o \
-- mmc.o mmc_ops.o sd.o sd_ops.o
-+ mmc.o mmc_ops.o sd.o sd_ops.o \
-+ sdio.o sdio_ops.o sdio_bus.o \
-+ sdio_cis.o sdio_io.o sdio_irq.o
-
+++ /dev/null
---- a/drivers/mmc/host/sdhci.c
-+++ b/drivers/mmc/host/sdhci.c
-@@ -481,16 +481,16 @@
- * Controller doesn't count down when in single block mode.
- */
- if (data->blocks == 1)
-- blocks = (data->error == MMC_ERR_NONE) ? 0 : 1;
-+ blocks = (data->error == 0) ? 0 : 1;
- else
- blocks = readw(host->ioaddr + SDHCI_BLOCK_COUNT);
- data->bytes_xfered = data->blksz * (data->blocks - blocks);
-
-- if ((data->error == MMC_ERR_NONE) && blocks) {
-+ if (!data->error && blocks) {
- printk(KERN_ERR "%s: Controller signalled completion even "
- "though there were blocks left.\n",
- mmc_hostname(host->mmc));
-- data->error = MMC_ERR_FAILED;
-+ data->error = -EIO;
- }
-
- if (data->stop) {
-@@ -498,7 +498,7 @@
- * The controller needs a reset of internal state machines
- * upon error conditions.
- */
-- if (data->error != MMC_ERR_NONE) {
-+ if (data->error) {
- sdhci_reset(host, SDHCI_RESET_CMD);
- sdhci_reset(host, SDHCI_RESET_DATA);
- }
-@@ -533,7 +533,7 @@
- printk(KERN_ERR "%s: Controller never released "
- "inhibit bit(s).\n", mmc_hostname(host->mmc));
- sdhci_dumpregs(host);
-- cmd->error = MMC_ERR_FAILED;
-+ cmd->error = -EIO;
- tasklet_schedule(&host->finish_tasklet);
- return;
- }
-@@ -554,7 +554,7 @@
- if ((cmd->flags & MMC_RSP_136) && (cmd->flags & MMC_RSP_BUSY)) {
- printk(KERN_ERR "%s: Unsupported response type!\n",
- mmc_hostname(host->mmc));
-- cmd->error = MMC_ERR_INVALID;
-+ cmd->error = -EINVAL;
- tasklet_schedule(&host->finish_tasklet);
- return;
- }
-@@ -601,7 +601,7 @@
- }
- }
-
-- host->cmd->error = MMC_ERR_NONE;
-+ host->cmd->error = 0;
-
- if (host->data && host->data_early)
- sdhci_finish_data(host);
-@@ -722,7 +722,7 @@
- host->mrq = mrq;
-
- if (!(readl(host->ioaddr + SDHCI_PRESENT_STATE) & SDHCI_CARD_PRESENT)) {
-- host->mrq->cmd->error = MMC_ERR_TIMEOUT;
-+ host->mrq->cmd->error = -ENOMEDIUM;
- tasklet_schedule(&host->finish_tasklet);
- } else
- sdhci_send_command(host, mrq->cmd);
-@@ -831,7 +831,7 @@
- sdhci_reset(host, SDHCI_RESET_CMD);
- sdhci_reset(host, SDHCI_RESET_DATA);
-
-- host->mrq->cmd->error = MMC_ERR_FAILED;
-+ host->mrq->cmd->error = -ENOMEDIUM;
- tasklet_schedule(&host->finish_tasklet);
- }
- }
-@@ -859,9 +859,9 @@
- * The controller needs a reset of internal state machines
- * upon error conditions.
- */
-- if ((mrq->cmd->error != MMC_ERR_NONE) ||
-- (mrq->data && ((mrq->data->error != MMC_ERR_NONE) ||
-- (mrq->data->stop && (mrq->data->stop->error != MMC_ERR_NONE))))) {
-+ if (mrq->cmd->error ||
-+ (mrq->data && (mrq->data->error ||
-+ (mrq->data->stop && mrq->data->stop->error)))) {
-
- /* Some controllers need this kick or reset won't work here */
- if (host->chip->quirks & SDHCI_QUIRK_CLOCK_BEFORE_RESET) {
-@@ -906,13 +906,13 @@
- sdhci_dumpregs(host);
-
- if (host->data) {
-- host->data->error = MMC_ERR_TIMEOUT;
-+ host->data->error = -ETIMEDOUT;
- sdhci_finish_data(host);
- } else {
- if (host->cmd)
-- host->cmd->error = MMC_ERR_TIMEOUT;
-+ host->cmd->error = -ETIMEDOUT;
- else
-- host->mrq->cmd->error = MMC_ERR_TIMEOUT;
-+ host->mrq->cmd->error = -ETIMEDOUT;
-
- tasklet_schedule(&host->finish_tasklet);
- }
-@@ -941,13 +941,12 @@
- }
-
- if (intmask & SDHCI_INT_TIMEOUT)
-- host->cmd->error = MMC_ERR_TIMEOUT;
-- else if (intmask & SDHCI_INT_CRC)
-- host->cmd->error = MMC_ERR_BADCRC;
-- else if (intmask & (SDHCI_INT_END_BIT | SDHCI_INT_INDEX))
-- host->cmd->error = MMC_ERR_FAILED;
-+ host->cmd->error = -ETIMEDOUT;
-+ else if (intmask & (SDHCI_INT_CRC | SDHCI_INT_END_BIT |
-+ SDHCI_INT_INDEX))
-+ host->cmd->error = -EILSEQ;
-
-- if (host->cmd->error != MMC_ERR_NONE)
-+ if (host->cmd->error)
- tasklet_schedule(&host->finish_tasklet);
- else if (intmask & SDHCI_INT_RESPONSE)
- sdhci_finish_command(host);
-@@ -974,13 +973,11 @@
- }
-
- if (intmask & SDHCI_INT_DATA_TIMEOUT)
-- host->data->error = MMC_ERR_TIMEOUT;
-- else if (intmask & SDHCI_INT_DATA_CRC)
-- host->data->error = MMC_ERR_BADCRC;
-- else if (intmask & SDHCI_INT_DATA_END_BIT)
-- host->data->error = MMC_ERR_FAILED;
-+ host->data->error = -ETIMEDOUT;
-+ else if (intmask & (SDHCI_INT_DATA_CRC | SDHCI_INT_DATA_END_BIT))
-+ host->data->error = -EILSEQ;
-
-- if (host->data->error != MMC_ERR_NONE)
-+ if (host->data->error)
- sdhci_finish_data(host);
- else {
- if (intmask & (SDHCI_INT_DATA_AVAIL | SDHCI_INT_SPACE_AVAIL))
-@@ -1312,7 +1309,7 @@
- mmc->ops = &sdhci_ops;
- mmc->f_min = host->max_clk / 256;
- mmc->f_max = host->max_clk;
-- mmc->caps = MMC_CAP_4_BIT_DATA | MMC_CAP_MULTIWRITE | MMC_CAP_BYTEBLOCK;
-+ mmc->caps = MMC_CAP_4_BIT_DATA | MMC_CAP_MULTIWRITE;
-
- if (caps & SDHCI_CAN_DO_HISPD)
- mmc->caps |= MMC_CAP_SD_HIGHSPEED;
+++ /dev/null
---- a/drivers/leds/Kconfig
-+++ b/drivers/leds/Kconfig
-@@ -133,4 +133,8 @@
- load average.
- If unsure, say Y.
-
-+config LEDS_TRIGGER_MORSE
-+ tristate "LED Morse Trigger"
-+ depends on LEDS_TRIGGERS
-+
- endif # NEW_LEDS
---- a/drivers/leds/Makefile
-+++ b/drivers/leds/Makefile
-@@ -22,3 +22,4 @@
- obj-$(CONFIG_LEDS_TRIGGER_TIMER) += ledtrig-timer.o
- obj-$(CONFIG_LEDS_TRIGGER_IDE_DISK) += ledtrig-ide-disk.o
- obj-$(CONFIG_LEDS_TRIGGER_HEARTBEAT) += ledtrig-heartbeat.o
-+obj-$(CONFIG_LEDS_TRIGGER_MORSE) += ledtrig-morse.o
+++ /dev/null
---- a/drivers/leds/Kconfig
-+++ b/drivers/leds/Kconfig
-@@ -81,6 +81,12 @@
- help
- This option enables support for the PCEngines WRAP programmable LEDs.
-
-+config LEDS_ALIX
-+ tristate "LED Support for the ALIX 2/3 boards"
-+ depends on LEDS_CLASS
-+ help
-+ This option enables support for the three LEDs on the PCEngines ALIX 2/3 boards.
-+
- config LEDS_H1940
- tristate "LED Support for iPAQ H1940 device"
- depends LEDS_CLASS && ARCH_H1940
---- a/drivers/leds/Makefile
-+++ b/drivers/leds/Makefile
-@@ -14,6 +14,7 @@
- obj-$(CONFIG_LEDS_AMS_DELTA) += leds-ams-delta.o
- obj-$(CONFIG_LEDS_NET48XX) += leds-net48xx.o
- obj-$(CONFIG_LEDS_WRAP) += leds-wrap.o
-+obj-$(CONFIG_LEDS_ALIX) += leds-alix.o
- obj-$(CONFIG_LEDS_H1940) += leds-h1940.o
- obj-$(CONFIG_LEDS_COBALT) += leds-cobalt.o
- obj-$(CONFIG_LEDS_GPIO) += leds-gpio.o
+++ /dev/null
---- a/drivers/leds/Kconfig
-+++ b/drivers/leds/Kconfig
-@@ -143,4 +143,11 @@
- tristate "LED Morse Trigger"
- depends on LEDS_TRIGGERS
-
-+config LEDS_TRIGGER_DEFAULT_ON
-+ tristate "LED Default ON Trigger"
-+ depends on LEDS_TRIGGERS
-+ help
-+ This allows LEDs to be initialised in the ON state.
-+ If unsure, say Y.
-+
- endif # NEW_LEDS
---- a/drivers/leds/Makefile
-+++ b/drivers/leds/Makefile
-@@ -24,3 +24,4 @@
- obj-$(CONFIG_LEDS_TRIGGER_IDE_DISK) += ledtrig-ide-disk.o
- obj-$(CONFIG_LEDS_TRIGGER_HEARTBEAT) += ledtrig-heartbeat.o
- obj-$(CONFIG_LEDS_TRIGGER_MORSE) += ledtrig-morse.o
-+obj-$(CONFIG_LEDS_TRIGGER_DEFAULT_ON) += ledtrig-default-on.o
+++ /dev/null
---- a/drivers/leds/Kconfig
-+++ b/drivers/leds/Kconfig
-@@ -150,4 +150,11 @@
- This allows LEDs to be initialised in the ON state.
- If unsure, say Y.
-
-+config LEDS_TRIGGER_NETDEV
-+ tristate "LED Netdev Trigger"
-+ depends on LEDS_TRIGGERS
-+ help
-+ This allows LEDs to be controlled by network device activity.
-+ If unsure, say Y.
-+
- endif # NEW_LEDS
---- a/drivers/leds/Makefile
-+++ b/drivers/leds/Makefile
-@@ -25,3 +25,4 @@
- obj-$(CONFIG_LEDS_TRIGGER_HEARTBEAT) += ledtrig-heartbeat.o
- obj-$(CONFIG_LEDS_TRIGGER_MORSE) += ledtrig-morse.o
- obj-$(CONFIG_LEDS_TRIGGER_DEFAULT_ON) += ledtrig-default-on.o
-+obj-$(CONFIG_LEDS_TRIGGER_NETDEV) += ledtrig-netdev.o
+++ /dev/null
---- a/drivers/input/misc/Kconfig
-+++ b/drivers/input/misc/Kconfig
-@@ -183,4 +183,20 @@
- Say Y here if you want to support the built-in real time clock
- of the HP SDC controller.
-
-+config INPUT_GPIO_BUTTONS
-+ tristate "Polled GPIO buttons interface"
-+ depends on GENERIC_GPIO
-+ select INPUT_POLLDEV
-+ help
-+ This driver implements support for buttons connected
-+ to GPIO pins of various CPUs (and some other chips).
-+
-+ Say Y here if your device has buttons connected
-+ directly to such GPIO pins. Your board-specific
-+ setup logic must also provide a platform device,
-+ with configuration data saying which GPIOs are used.
-+
-+ To compile this driver as a module, choose M here: the
-+ module will be called gpio-buttons.
-+
- endif
---- a/drivers/input/misc/Makefile
-+++ b/drivers/input/misc/Makefile
-@@ -18,3 +18,4 @@
- obj-$(CONFIG_INPUT_YEALINK) += yealink.o
- obj-$(CONFIG_HP_SDC_RTC) += hp_sdc_rtc.o
- obj-$(CONFIG_INPUT_UINPUT) += uinput.o
-+obj-$(CONFIG_INPUT_GPIO_BUTTONS) += gpio_buttons.o
+++ /dev/null
---- a/drivers/char/Kconfig
-+++ b/drivers/char/Kconfig
-@@ -970,6 +970,13 @@
-
- If compiled as a module, it will be called cs5535_gpio.
-
-+config GPIO_DEVICE
-+ tristate "GPIO device support"
-+ depends on GENERIC_GPIO
-+ help
-+ Say Y to enable Linux GPIO device support. This allows control of
-+ GPIO pins using a character device
-+
- config GPIO_VR41XX
- tristate "NEC VR4100 series General-purpose I/O Unit support"
- depends on CPU_VR41XX
---- a/drivers/char/Makefile
-+++ b/drivers/char/Makefile
-@@ -93,6 +93,7 @@
- obj-$(CONFIG_PC8736x_GPIO) += pc8736x_gpio.o
- obj-$(CONFIG_NSC_GPIO) += nsc_gpio.o
- obj-$(CONFIG_CS5535_GPIO) += cs5535_gpio.o
-+obj-$(CONFIG_GPIO_DEVICE) += gpio_dev.o
- obj-$(CONFIG_GPIO_VR41XX) += vr41xx_giu.o
- obj-$(CONFIG_GPIO_TB0219) += tb0219.o
- obj-$(CONFIG_TELCLOCK) += tlclk.o
+++ /dev/null
---- a/fs/Kconfig
-+++ b/fs/Kconfig
-@@ -419,6 +419,7 @@
-
- source "fs/xfs/Kconfig"
- source "fs/gfs2/Kconfig"
-+source "fs/yaffs2/Kconfig"
-
- config OCFS2_FS
- tristate "OCFS2 file system support"
---- a/fs/Makefile
-+++ b/fs/Makefile
-@@ -120,3 +120,4 @@
- obj-$(CONFIG_DEBUG_FS) += debugfs/
- obj-$(CONFIG_OCFS2_FS) += ocfs2/
- obj-$(CONFIG_GFS2_FS) += gfs2/
-+obj-$(CONFIG_YAFFS_FS) += yaffs2/
+++ /dev/null
---- a/drivers/net/phy/phy.c
-+++ b/drivers/net/phy/phy.c
-@@ -344,6 +344,50 @@
- }
- EXPORT_SYMBOL(phy_ethtool_gset);
-
-+int phy_ethtool_ioctl(struct phy_device *phydev, void *useraddr)
-+{
-+ u32 cmd;
-+ int tmp;
-+ struct ethtool_cmd ecmd = { ETHTOOL_GSET };
-+ struct ethtool_value edata = { ETHTOOL_GLINK };
-+
-+ if (get_user(cmd, (u32 *) useraddr))
-+ return -EFAULT;
-+
-+ switch (cmd) {
-+ case ETHTOOL_GSET:
-+ phy_ethtool_gset(phydev, &ecmd);
-+ if (copy_to_user(useraddr, &ecmd, sizeof(ecmd)))
-+ return -EFAULT;
-+ return 0;
-+
-+ case ETHTOOL_SSET:
-+ if (copy_from_user(&ecmd, useraddr, sizeof(ecmd)))
-+ return -EFAULT;
-+ return phy_ethtool_sset(phydev, &ecmd);
-+
-+ case ETHTOOL_NWAY_RST:
-+ /* if autoneg is off, it's an error */
-+ tmp = phy_read(phydev, MII_BMCR);
-+ if (tmp & BMCR_ANENABLE) {
-+ tmp |= (BMCR_ANRESTART);
-+ phy_write(phydev, MII_BMCR, tmp);
-+ return 0;
-+ }
-+ return -EINVAL;
-+
-+ case ETHTOOL_GLINK:
-+ edata.data = (phy_read(phydev,
-+ MII_BMSR) & BMSR_LSTATUS) ? 1 : 0;
-+ if (copy_to_user(useraddr, &edata, sizeof(edata)))
-+ return -EFAULT;
-+ return 0;
-+ }
-+
-+ return -EOPNOTSUPP;
-+}
-+EXPORT_SYMBOL(phy_ethtool_ioctl);
-+
- /**
- * phy_mii_ioctl - generic PHY MII ioctl interface
- * @phydev: the phy_device struct
---- a/include/linux/phy.h
-+++ b/include/linux/phy.h
-@@ -393,6 +393,7 @@
- void phy_stop_machine(struct phy_device *phydev);
- int phy_ethtool_sset(struct phy_device *phydev, struct ethtool_cmd *cmd);
- int phy_ethtool_gset(struct phy_device *phydev, struct ethtool_cmd *cmd);
-+int phy_ethtool_ioctl(struct phy_device *phydev, void *useraddr);
- int phy_mii_ioctl(struct phy_device *phydev,
- struct mii_ioctl_data *mii_data, int cmd);
- int phy_start_interrupts(struct phy_device *phydev);
+++ /dev/null
---- a/drivers/net/phy/mdio_bus.c
-+++ b/drivers/net/phy/mdio_bus.c
-@@ -131,6 +131,9 @@
- struct phy_device *phydev = to_phy_device(dev);
- struct phy_driver *phydrv = to_phy_driver(drv);
-
-+ if (phydrv->detect)
-+ return (phydrv->detect(phydev->bus, phydev->addr));
-+
- return ((phydrv->phy_id & phydrv->phy_id_mask) ==
- (phydev->phy_id & phydrv->phy_id_mask));
- }
---- a/include/linux/phy.h
-+++ b/include/linux/phy.h
-@@ -319,6 +319,11 @@
- u32 features;
- u32 flags;
-
-+ /* Called during discovery to test if the
-+ * device can attach to the bus, even if
-+ * phy id and mask do not match */
-+ bool (*detect)(struct mii_bus *bus, int addr);
-+
- /* Called to initialize the PHY,
- * including after a reset */
- int (*config_init)(struct phy_device *phydev);
+++ /dev/null
---- a/drivers/net/phy/Kconfig
-+++ b/drivers/net/phy/Kconfig
-@@ -60,6 +60,11 @@
- ---help---
- Currently supports the IP175C PHY.
-
-+config ADM6996_PHY
-+ tristate "Driver for ADM6996 switches"
-+ ---help---
-+ Currently supports the ADM6996F switch
-+
- config FIXED_PHY
- tristate "Drivers for PHY emulation on fixed speed/link"
- ---help---
---- a/drivers/net/phy/Makefile
-+++ b/drivers/net/phy/Makefile
-@@ -12,4 +12,5 @@
- obj-$(CONFIG_VITESSE_PHY) += vitesse.o
- obj-$(CONFIG_BROADCOM_PHY) += broadcom.o
- obj-$(CONFIG_ICPLUS_PHY) += icplus.o
-+obj-$(CONFIG_ADM6996_PHY) += adm6996.o
- obj-$(CONFIG_FIXED_PHY) += fixed.o
+++ /dev/null
---- a/drivers/net/phy/phy_device.c
-+++ b/drivers/net/phy/phy_device.c
-@@ -44,6 +44,18 @@
- extern int mdio_bus_init(void);
- extern void mdio_bus_exit(void);
-
-+static int generic_receive_skb(struct sk_buff *skb)
-+{
-+ skb->protocol = eth_type_trans(skb, skb->dev);
-+ return netif_receive_skb(skb);
-+}
-+
-+static int generic_rx(struct sk_buff *skb)
-+{
-+ skb->protocol = eth_type_trans(skb, skb->dev);
-+ return netif_rx(skb);
-+}
-+
- struct phy_device* phy_device_create(struct mii_bus *bus, int addr, int phy_id)
- {
- struct phy_device *dev;
-@@ -67,6 +79,8 @@
- dev->bus = bus;
-
- dev->state = PHY_DOWN;
-+ dev->netif_receive_skb = &generic_receive_skb;
-+ dev->netif_rx = &generic_rx;
-
- spin_lock_init(&dev->lock);
-
---- a/include/linux/phy.h
-+++ b/include/linux/phy.h
-@@ -289,6 +289,17 @@
- void (*adjust_link)(struct net_device *dev);
-
- void (*adjust_state)(struct net_device *dev);
-+
-+ /*
-+ * By default these point to the original functions
-+ * with the same name. adding them to the phy_device
-+ * allows the phy driver to override them for packet
-+ * mangling if the ethernet driver supports it
-+ * This is required to support some really horrible
-+ * switches such as the Marvell 88E6060
-+ */
-+ int (*netif_receive_skb)(struct sk_buff *skb);
-+ int (*netif_rx)(struct sk_buff *skb);
- };
- #define to_phy_device(d) container_of(d, struct phy_device, dev)
-
---- a/include/linux/netdevice.h
-+++ b/include/linux/netdevice.h
-@@ -426,6 +426,7 @@
- void *ax25_ptr; /* AX.25 specific data */
- struct wireless_dev *ieee80211_ptr; /* IEEE 802.11 specific data,
- assign before registering */
-+ void *phy_ptr; /* PHY device specific data */
-
- /*
- * Cache line mostly used on receive path (including eth_type_trans())
+++ /dev/null
---- a/drivers/net/phy/Kconfig
-+++ b/drivers/net/phy/Kconfig
-@@ -65,6 +65,12 @@
- ---help---
- Currently supports the ADM6996F switch
-
-+config MVSWITCH_PHY
-+ tristate "Driver for Marvell switches"
-+ select VLAN_8021Q
-+ ---help---
-+ Currently supports the Marvell 88E6060 switch.
-+
- config FIXED_PHY
- tristate "Drivers for PHY emulation on fixed speed/link"
- ---help---
---- a/drivers/net/phy/Makefile
-+++ b/drivers/net/phy/Makefile
-@@ -13,4 +13,5 @@
- obj-$(CONFIG_BROADCOM_PHY) += broadcom.o
- obj-$(CONFIG_ICPLUS_PHY) += icplus.o
- obj-$(CONFIG_ADM6996_PHY) += adm6996.o
-+obj-$(CONFIG_MVSWITCH_PHY) += mvswitch.o
- obj-$(CONFIG_FIXED_PHY) += fixed.o
---- a/drivers/net/phy/mdio_bus.c
-+++ b/drivers/net/phy/mdio_bus.c
-@@ -35,6 +35,12 @@
- #include <asm/irq.h>
- #include <asm/uaccess.h>
-
-+static void mdio_dev_release(struct device *dev)
-+{
-+ /* nothing to do */
-+}
-+
-+
- /**
- * mdiobus_register - bring up all the PHYs on a given bus and attach them to bus
- * @bus: target mii_bus
-@@ -85,6 +91,7 @@
-
- phydev->dev.parent = bus->dev;
- phydev->dev.bus = &mdio_bus_type;
-+ phydev->dev.release = mdio_dev_release;
- snprintf(phydev->dev.bus_id, BUS_ID_SIZE, PHY_ID_FMT, bus->id, i);
-
- phydev->bus = bus;
+++ /dev/null
---- a/init/main.c
-+++ b/init/main.c
-@@ -780,7 +780,7 @@
- numa_default_policy();
-
- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
-- printk(KERN_WARNING "Warning: unable to open an initial console.\n");
-+ printk(KERN_WARNING "Please be patient, while OpenWrt loads ...\n");
-
- (void) sys_dup(0);
- (void) sys_dup(0);
+++ /dev/null
---- a/drivers/usb/serial/usb-serial.c
-+++ b/drivers/usb/serial/usb-serial.c
-@@ -58,6 +58,7 @@
- drivers depend on it.
- */
-
-+static ushort maxSize = 0;
- static int debug;
- static struct usb_serial *serial_table[SERIAL_TTY_MINORS]; /* initially all NULL */
- static DEFINE_MUTEX(table_lock);
-@@ -866,7 +867,7 @@
- dev_err(&interface->dev, "No free urbs available\n");
- goto probe_error;
- }
-- buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
-+ buffer_size = (endpoint->wMaxPacketSize > maxSize) ? endpoint->wMaxPacketSize : maxSize;
- port->bulk_in_size = buffer_size;
- port->bulk_in_endpointAddress = endpoint->bEndpointAddress;
- port->bulk_in_buffer = kmalloc (buffer_size, GFP_KERNEL);
-@@ -1276,3 +1277,5 @@
-
- module_param(debug, bool, S_IRUGO | S_IWUSR);
- MODULE_PARM_DESC(debug, "Debug enabled or not");
-+module_param(maxSize, ushort,0);
-+MODULE_PARM_DESC(maxSize,"User specified USB endpoint size");
+++ /dev/null
---- a/include/linux/time.h
-+++ b/include/linux/time.h
-@@ -1,6 +1,10 @@
- #ifndef _LINUX_TIME_H
- #define _LINUX_TIME_H
-
-+#ifndef __KERNEL__
-+#include <time.h>
-+#else
-+
- #include <linux/types.h>
-
- #ifdef __KERNEL__
-@@ -227,4 +231,6 @@
- */
- #define TIMER_ABSTIME 0x01
-
-+#endif /* __KERNEL__ DEBIAN */
-+
- #endif
---- a/include/linux/types.h
-+++ b/include/linux/types.h
-@@ -1,6 +1,14 @@
- #ifndef _LINUX_TYPES_H
- #define _LINUX_TYPES_H
-
-+/* Debian: Use userland types instead. */
-+#ifndef __KERNEL__
-+# include <sys/types.h>
-+/* For other kernel headers. */
-+# include <linux/posix_types.h>
-+# include <asm/types.h>
-+#else
-+
- #ifdef __KERNEL__
-
- #define BITS_TO_LONGS(bits) \
-@@ -162,6 +170,8 @@
-
- #endif /* __KERNEL_STRICT_NAMES */
-
-+#endif /* __KERNEL__ DEBIAN */
-+
- /*
- * Below are truly Linux-specific types that should never collide with
- * any application/library that wants linux/types.h.
+++ /dev/null
---- a/scripts/genksyms/parse.c_shipped
-+++ b/scripts/genksyms/parse.c_shipped
-@@ -144,7 +144,9 @@
-
-
- #include <assert.h>
-+#ifndef __APPLE__
- #include <malloc.h>
-+#endif
- #include "genksyms.h"
-
- static int is_typedef;
---- a/scripts/genksyms/parse.y
-+++ b/scripts/genksyms/parse.y
-@@ -24,7 +24,9 @@
- %{
-
- #include <assert.h>
-+#ifndef __APPLE__
- #include <malloc.h>
-+#endif
- #include "genksyms.h"
-
- static int is_typedef;
---- a/scripts/kallsyms.c
-+++ b/scripts/kallsyms.c
-@@ -28,6 +28,35 @@
- #include <stdlib.h>
- #include <string.h>
- #include <ctype.h>
-+#ifdef __APPLE__
-+/* Darwin has no memmem implementation, this one is ripped of the uClibc-0.9.28 source */
-+void *memmem (const void *haystack, size_t haystack_len,
-+ const void *needle, size_t needle_len)
-+{
-+ const char *begin;
-+ const char *const last_possible
-+ = (const char *) haystack + haystack_len - needle_len;
-+
-+ if (needle_len == 0)
-+ /* The first occurrence of the empty string is deemed to occur at
-+ the beginning of the string. */
-+ return (void *) haystack;
-+
-+ /* Sanity check, otherwise the loop might search through the whole
-+ memory. */
-+ if (__builtin_expect (haystack_len < needle_len, 0))
-+ return NULL;
-+
-+ for (begin = (const char *) haystack; begin <= last_possible; ++begin)
-+ if (begin[0] == ((const char *) needle)[0] &&
-+ !memcmp ((const void *) &begin[1],
-+ (const void *) ((const char *) needle + 1),
-+ needle_len - 1))
-+ return (void *) begin;
-+
-+ return NULL;
-+}
-+#endif
-
- #define KSYM_NAME_LEN 128
-
---- a/scripts/kconfig/Makefile
-+++ b/scripts/kconfig/Makefile
-@@ -88,6 +88,9 @@
- # we really need to do so. (Do not call gcc as part of make mrproper)
- HOST_EXTRACFLAGS = $(shell $(CONFIG_SHELL) $(check-lxdialog) -ccflags)
- HOST_LOADLIBES = $(shell $(CONFIG_SHELL) $(check-lxdialog) -ldflags $(HOSTCC))
-+ifeq ($(shell uname -s),Darwin)
-+HOST_LOADLIBES += -lncurses
-+endif
-
- HOST_EXTRACFLAGS += -DLOCALE
-
---- a/scripts/mod/mk_elfconfig.c
-+++ b/scripts/mod/mk_elfconfig.c
-@@ -1,7 +1,11 @@
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
-+#ifndef __APPLE__
- #include <elf.h>
-+#else
-+#include "../../../../../tools/sstrip/include/elf.h"
-+#endif
-
- int
- main(int argc, char **argv)
---- a/scripts/mod/modpost.h
-+++ b/scripts/mod/modpost.h
-@@ -7,7 +7,11 @@
- #include <sys/mman.h>
- #include <fcntl.h>
- #include <unistd.h>
-+#ifndef __APPLE__
- #include <elf.h>
-+#else
-+#include "../../../../../tools/sstrip/include/elf.h"
-+#endif
-
- #include "elfconfig.h"
-
+++ /dev/null
---- a/include/linux/stddef.h
-+++ b/include/linux/stddef.h
-@@ -16,6 +16,7 @@
- false = 0,
- true = 1
- };
-+#endif /* __KERNEL__ */
-
- #undef offsetof
- #ifdef __compiler_offsetof
-@@ -23,6 +24,5 @@
- #else
- #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
- #endif
--#endif /* __KERNEL__ */
-
- #endif
+++ /dev/null
---- a/scripts/gen_initramfs_list.sh
-+++ b/scripts/gen_initramfs_list.sh
-@@ -125,7 +125,7 @@
- str="${ftype} ${name} ${location} ${str}"
- ;;
- "nod")
-- local dev=`LC_ALL=C ls -l "${location}"`
-+ local dev=`LC_ALL=C ls -l --time-style=locale "${location}"`
- local maj=`field 5 ${dev}`
- local min=`field 6 ${dev}`
- maj=${maj%,}
-@@ -135,7 +135,7 @@
- str="${ftype} ${name} ${str} ${dev} ${maj} ${min}"
- ;;
- "slink")
-- local target=`field 11 $(LC_ALL=C ls -l "${location}")`
-+ local target=`field 11 $(LC_ALL=C ls -l --time-style=locale "${location}")`
- str="${ftype} ${name} ${target} ${str}"
- ;;
- *)
+++ /dev/null
---- a/arch/i386/boot/tools/build.c
-+++ b/arch/i386/boot/tools/build.c
-@@ -29,7 +29,6 @@
- #include <stdarg.h>
- #include <sys/types.h>
- #include <sys/stat.h>
--#include <sys/sysmacros.h>
- #include <unistd.h>
- #include <fcntl.h>
- #include <sys/mman.h>
+++ /dev/null
-From: Lennert Buytenhek <buytenh@wantstofly.org>
-Date: Fri, 12 Oct 2007 13:38:54 +0000 (+0100)
-Subject: [ARM] 4600/1: fix kernel build failure with build-id-supporting binutils
-X-Git-Tag: v2.6.24-rc1~1273^2~3
-X-Git-Url: http://git.kernel.org/?p=linux%2Fkernel%2Fgit%2Ftorvalds%2Flinux-2.6.git;a=commitdiff_plain;h=1e621a8e3752367d4aae78a8ab00a18fb2793f34;hp=033b8ffe3f1ea8174d51d125838ac6deea60f63f
-
-[ARM] 4600/1: fix kernel build failure with build-id-supporting binutils
-
-Newer versions of binutils support --build-id, which adds an ELF
-note section called ".note.gnu.build-id" to the output. On the ARM
-kernel build, because there is no explicit mention of this section
-in the shipped ld script, this section is placed at vaddr 0x00000000
-(whereas the normal kernel text/data typically starts at vaddr
-0xc0008000), causing the output of objcopy (Image) to produce a 3G+
-file.
-
-This patch makes objcopy strip the .note.gnu.build-id section from
-the Image file along with all other note sections, which fixes the
-build.
-
-Signed-off-by: Lennert Buytenhek <buytenh@wantstofly.org>
-Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
----
-
---- a/arch/arm/Makefile
-+++ b/arch/arm/Makefile
-@@ -12,7 +12,7 @@
-
- LDFLAGS_vmlinux :=-p --no-undefined -X
- CPPFLAGS_vmlinux.lds = -DTEXT_OFFSET=$(TEXT_OFFSET)
--OBJCOPYFLAGS :=-O binary -R .note -R .comment -S
-+OBJCOPYFLAGS :=-O binary -R .note -R .note.gnu.build-id -R .comment -S
- GZFLAGS :=-9
- #CFLAGS +=-pipe
- # Explicitly specifiy 32-bit ARM ISA since toolchain default can be -mthumb:
+++ /dev/null
-From a.othieno@bluewin.ch Tue Oct 11 07:50:21 2005
-From: Arthur Othieno <a.othieno@bluewin.ch>
-Subject: Big-endian I/O memory accessors.
-Date: Tue, 11 Oct 2005 07:50:21 +1000
-X-Patchwork-ID: 2759
-
-From: Arthur Othieno <a.othieno@bluewin.ch>
-
-I/O memory accessors. Big endian version. For those busses/devices
-that do export big-endian I/O memory.
-
-Of notable relevance/reference:
-
- http://lwn.net/Articles/132804/
- http://ozlabs.org/pipermail/linuxppc-embedded/2005-August/019798.html
- http://ozlabs.org/pipermail/linuxppc-embedded/2005-August/019752.html
-
-Signed-off-by: Arthur Othieno <a.othieno@bluewin.ch>
----
-
-Paulus,
-
-A similar patch for ppc64 made it upstream with your big ppc64 merge.
-This one is still sitting in http://patchwork.ozlabs.org/linuxppc/
-and didn't make it with the ppc32 equivalent. Thanks.
-
-
- include/asm-ppc/io.h | 20 ++++++++++++++++++++
- 1 file changed, 20 insertions(+)
-
-
----
---- a/include/asm-ppc/io.h
-+++ b/include/asm-ppc/io.h
-@@ -453,11 +453,21 @@
- return readw(addr);
- }
-
-+static inline unsigned int ioread16be(void __iomem *addr)
-+{
-+ return in_be16(addr);
-+}
-+
- static inline unsigned int ioread32(void __iomem *addr)
- {
- return readl(addr);
- }
-
-+static inline unsigned int ioread32be(void __iomem *addr)
-+{
-+ return in_be32(addr);
-+}
-+
- static inline void iowrite8(u8 val, void __iomem *addr)
- {
- writeb(val, addr);
-@@ -468,11 +478,21 @@
- writew(val, addr);
- }
-
-+static inline void iowrite16be(u16 val, void __iomem *addr)
-+{
-+ out_be16(addr, val);
-+}
-+
- static inline void iowrite32(u32 val, void __iomem *addr)
- {
- writel(val, addr);
- }
-
-+static inline void iowrite32be(u32 val, void __iomem *addr)
-+{
-+ out_be32(addr, val);
-+}
-+
- static inline void ioread8_rep(void __iomem *addr, void *dst, unsigned long count)
- {
- _insb(addr, dst, count);
+++ /dev/null
---- a/drivers/spi/Kconfig
-+++ b/drivers/spi/Kconfig
-@@ -100,6 +100,11 @@
- inexpensive battery powered microcontroller evaluation board.
- This same cable can be used to flash new firmware.
-
-+config SPI_GPIO
-+ tristate "GPIO API based bitbanging SPI controller"
-+ depends on SPI_MASTER && GENERIC_GPIO && EXPERIMENTAL
-+ select SPI_BITBANG
-+
- config SPI_IMX
- tristate "Freescale iMX SPI controller"
- depends on SPI_MASTER && ARCH_IMX && EXPERIMENTAL
---- a/drivers/spi/Makefile
-+++ b/drivers/spi/Makefile
-@@ -16,6 +16,7 @@
- obj-$(CONFIG_SPI_BITBANG) += spi_bitbang.o
- obj-$(CONFIG_SPI_AU1550) += au1550_spi.o
- obj-$(CONFIG_SPI_BUTTERFLY) += spi_butterfly.o
-+obj-$(CONFIG_SPI_GPIO) += spi_gpio.o
- obj-$(CONFIG_SPI_IMX) += spi_imx.o
- obj-$(CONFIG_SPI_LM70_LLP) += spi_lm70llp.o
- obj-$(CONFIG_SPI_PXA2XX) += pxa2xx_spi.o
+++ /dev/null
---- a/drivers/w1/masters/Kconfig
-+++ b/drivers/w1/masters/Kconfig
-@@ -42,5 +42,15 @@
- in HP iPAQ devices like h5xxx, h2200, and ASIC3-based like
- hx4700.
-
-+config W1_MASTER_GPIO
-+ tristate "GPIO 1-wire busmaster"
-+ depends on GENERIC_GPIO
-+ help
-+ Say Y here if you want to communicate with your 1-wire devices using
-+ GPIO pins. This driver uses the GPIO API to control the wire.
-+
-+ This support is also available as a module. If so, the module
-+ will be called w1-gpio.ko.
-+
- endmenu
-
---- a/drivers/w1/masters/Makefile
-+++ b/drivers/w1/masters/Makefile
-@@ -6,3 +6,4 @@
- obj-$(CONFIG_W1_MASTER_DS2490) += ds2490.o
- obj-$(CONFIG_W1_MASTER_DS2482) += ds2482.o
- obj-$(CONFIG_W1_MASTER_DS1WM) += ds1wm.o
-+obj-$(CONFIG_W1_MASTER_GPIO) += w1-gpio.o
---- /dev/null
-+++ b/drivers/w1/masters/w1-gpio.c
-@@ -0,0 +1,124 @@
-+/*
-+ * w1-gpio - GPIO w1 bus master driver
-+ *
-+ * Copyright (C) 2007 Ville Syrjala <syrjala@sci.fi>
-+ *
-+ * This program is free software; you can redistribute it and/or modify
-+ * it under the terms of the GNU General Public License version 2
-+ * as published by the Free Software Foundation.
-+ */
-+
-+#include <linux/init.h>
-+#include <linux/module.h>
-+#include <linux/platform_device.h>
-+#include <linux/w1-gpio.h>
-+
-+#include "../w1.h"
-+#include "../w1_int.h"
-+
-+#include <asm/gpio.h>
-+
-+static void w1_gpio_write_bit_dir(void *data, u8 bit)
-+{
-+ struct w1_gpio_platform_data *pdata = data;
-+
-+ if (bit)
-+ gpio_direction_input(pdata->pin);
-+ else
-+ gpio_direction_output(pdata->pin, 0);
-+}
-+
-+static void w1_gpio_write_bit_val(void *data, u8 bit)
-+{
-+ struct w1_gpio_platform_data *pdata = data;
-+
-+ gpio_set_value(pdata->pin, bit);
-+}
-+
-+static u8 w1_gpio_read_bit(void *data)
-+{
-+ struct w1_gpio_platform_data *pdata = data;
-+
-+ return gpio_get_value(pdata->pin);
-+}
-+
-+static int __init w1_gpio_probe(struct platform_device *pdev)
-+{
-+ struct w1_bus_master *master;
-+ struct w1_gpio_platform_data *pdata = pdev->dev.platform_data;
-+ int err;
-+
-+ if (!pdata)
-+ return -ENXIO;
-+
-+ master = kzalloc(sizeof(struct w1_bus_master), GFP_KERNEL);
-+ if (!master)
-+ return -ENOMEM;
-+
-+ err = gpio_request(pdata->pin, "w1");
-+ if (err)
-+ goto free_master;
-+
-+ master->data = pdata;
-+ master->read_bit = w1_gpio_read_bit;
-+
-+ if (pdata->is_open_drain) {
-+ gpio_direction_output(pdata->pin, 1);
-+ master->write_bit = w1_gpio_write_bit_val;
-+ } else {
-+ gpio_direction_input(pdata->pin);
-+ master->write_bit = w1_gpio_write_bit_dir;
-+ }
-+
-+ err = w1_add_master_device(master);
-+ if (err)
-+ goto free_gpio;
-+
-+ platform_set_drvdata(pdev, master);
-+
-+ return 0;
-+
-+ free_gpio:
-+ gpio_free(pdata->pin);
-+ free_master:
-+ kfree(master);
-+
-+ return err;
-+}
-+
-+static int __exit w1_gpio_remove(struct platform_device *pdev)
-+{
-+ struct w1_bus_master *master = platform_get_drvdata(pdev);
-+ struct w1_gpio_platform_data *pdata = pdev->dev.platform_data;
-+
-+ w1_remove_master_device(master);
-+ gpio_free(pdata->pin);
-+ kfree(master);
-+
-+ return 0;
-+}
-+
-+static struct platform_driver w1_gpio_driver = {
-+ .driver = {
-+ .name = "w1-gpio",
-+ .owner = THIS_MODULE,
-+ },
-+ .remove = __exit_p(w1_gpio_remove),
-+};
-+
-+static int __init w1_gpio_init(void)
-+{
-+ return platform_driver_probe(&w1_gpio_driver, w1_gpio_probe);
-+}
-+
-+static void __exit w1_gpio_exit(void)
-+{
-+ platform_driver_unregister(&w1_gpio_driver);
-+}
-+
-+module_init(w1_gpio_init);
-+module_exit(w1_gpio_exit);
-+
-+MODULE_DESCRIPTION("GPIO w1 bus master driver");
-+MODULE_AUTHOR("Ville Syrjala <syrjala@sci.fi>");
-+MODULE_LICENSE("GPL");
---- /dev/null
-+++ b/include/linux/w1-gpio.h
-@@ -0,0 +1,23 @@
-+/*
-+ * w1-gpio interface to platform code
-+ *
-+ * Copyright (C) 2007 Ville Syrjala <syrjala@sci.fi>
-+ *
-+ * This program is free software; you can redistribute it and/or modify
-+ * it under the terms of the GNU General Public License version 2
-+ * as published by the Free Software Foundation.
-+ */
-+#ifndef _LINUX_W1_GPIO_H
-+#define _LINUX_W1_GPIO_H
-+
-+/**
-+ * struct w1_gpio_platform_data - Platform-dependent data for w1-gpio
-+ * @pin: GPIO pin to use
-+ * @is_open_drain: GPIO pin is configured as open drain
-+ */
-+struct w1_gpio_platform_data {
-+ unsigned int pin;
-+ unsigned int is_open_drain:1;
-+};
-+
-+#endif /* _LINUX_W1_GPIO_H */
+++ /dev/null
-This patch ports ssb to the 2.6.23 kernel.
-
---- a/drivers/ssb/driver_mipscore.c
-+++ b/drivers/ssb/driver_mipscore.c
-@@ -223,3 +223,5 @@
- ssb_mips_serial_init(mcore);
- ssb_mips_flash_detect(mcore);
- }
-+
-+EXPORT_SYMBOL(ssb_mips_irq);
---- a/include/linux/mod_devicetable.h
-+++ b/include/linux/mod_devicetable.h
-@@ -352,4 +352,19 @@
- #define PA_HVERSION_ANY_ID 0xffff
- #define PA_SVERSION_ANY_ID 0xffffffff
-
-+/* SSB core, see drivers/ssb/ */
-+struct ssb_device_id {
-+ __u16 vendor;
-+ __u16 coreid;
-+ __u8 revision;
-+};
-+#define SSB_DEVICE(_vendor, _coreid, _revision) \
-+ { .vendor = _vendor, .coreid = _coreid, .revision = _revision, }
-+#define SSB_DEVTABLE_END \
-+ { 0, },
-+
-+#define SSB_ANY_VENDOR 0xFFFF
-+#define SSB_ANY_ID 0xFFFF
-+#define SSB_ANY_REV 0xFF
-+
- #endif /* LINUX_MOD_DEVICETABLE_H */
---- a/drivers/ssb/main.c
-+++ b/drivers/ssb/main.c
-@@ -321,14 +321,16 @@
- return 0;
- }
-
--static int ssb_device_uevent(struct device *dev, struct kobj_uevent_env *env)
-+static int ssb_device_uevent(struct device *dev, char **envp,
-+ int num_envp, char *buffer, int buffer_size)
- {
- struct ssb_device *ssb_dev = dev_to_ssb_dev(dev);
-+ int i = 0, len = 0;
-
- if (!dev)
- return -ENODEV;
-
-- return add_uevent_var(env,
-+ return add_uevent_var(envp, num_envp, &i, buffer, buffer_size, &len,
- "MODALIAS=ssb:v%04Xid%04Xrev%02X",
- ssb_dev->id.vendor, ssb_dev->id.coreid,
- ssb_dev->id.revision);
---- a/drivers/ssb/scan.c
-+++ b/drivers/ssb/scan.c
-@@ -391,12 +391,14 @@
- if (bus->bustype == SSB_BUSTYPE_PCI) {
- /* Ignore PCI cores on PCI-E cards.
- * Ignore PCI-E cores on PCI cards. */
-+ //FIXME kernel 2.6.23 doesn't have is_pcie. Add this check back when updating to 2.6.24 or later.
- if (dev->id.coreid == SSB_DEV_PCI) {
-- if (bus->host_pci->is_pcie)
-- continue;
-+//FIXME if (bus->host_pci->is_pcie)
-+//FIXME continue;
- } else {
-- if (!bus->host_pci->is_pcie)
-- continue;
-+ continue; //FIXME
-+//FIXME if (!bus->host_pci->is_pcie)
-+//FIXME continue;
- }
- }
- if (bus->pcicore.dev) {
---- a/drivers/ssb/driver_pcicore.c
-+++ b/drivers/ssb/driver_pcicore.c
-@@ -362,7 +362,7 @@
- chipid_top != 0x5300)
- return 0;
-
-- if (bus->sprom.r1.boardflags_lo & SSB_PCICORE_BFL_NOPCI)
-+ if (bus->sprom.boardflags_lo & SSB_PCICORE_BFL_NOPCI)
- return 0;
-
- /* The 200-pin BCM4712 package does not bond out PCI. Even when
+++ /dev/null
-CONFIG_32BIT=y
-# CONFIG_64BIT is not set
-# CONFIG_8139TOO is not set
-# CONFIG_ARCH_HAS_ILOG2_U32 is not set
-# CONFIG_ARCH_HAS_ILOG2_U64 is not set
-# CONFIG_ARCH_SUPPORTS_MSI is not set
-# CONFIG_ATM is not set
-# CONFIG_AX25 is not set
-CONFIG_BASE_SMALL=0
-CONFIG_BITREVERSE=y
-CONFIG_BLK_DEV_CF_MIPS=y
-# CONFIG_BT is not set
-# CONFIG_CPU_BIG_ENDIAN is not set
-CONFIG_CPU_HAS_LLSC=y
-CONFIG_CPU_HAS_PREFETCH=y
-CONFIG_CPU_HAS_SYNC=y
-CONFIG_CPU_LITTLE_ENDIAN=y
-# CONFIG_CPU_LOONGSON2 is not set
-CONFIG_CPU_MIPS32=y
-CONFIG_CPU_MIPS32_R1=y
-# CONFIG_CPU_MIPS32_R2 is not set
-# CONFIG_CPU_MIPS64_R1 is not set
-# CONFIG_CPU_MIPS64_R2 is not set
-CONFIG_CPU_MIPSR1=y
-# CONFIG_CPU_NEVADA is not set
-# CONFIG_CPU_R10000 is not set
-# CONFIG_CPU_R3000 is not set
-# CONFIG_CPU_R4300 is not set
-# CONFIG_CPU_R4X00 is not set
-# CONFIG_CPU_R5000 is not set
-# CONFIG_CPU_R5432 is not set
-# CONFIG_CPU_R6000 is not set
-# CONFIG_CPU_R8000 is not set
-# CONFIG_CPU_RM7000 is not set
-# CONFIG_CPU_RM9000 is not set
-# CONFIG_CPU_SB1 is not set
-CONFIG_CPU_SUPPORTS_32BIT_KERNEL=y
-CONFIG_CPU_SUPPORTS_HIGHMEM=y
-# CONFIG_CPU_TX39XX is not set
-# CONFIG_CPU_TX49XX is not set
-# CONFIG_CPU_VR41XX is not set
-CONFIG_DEVPORT=y
-# CONFIG_DM9000 is not set
-CONFIG_DMA_NEED_PCI_MAP_STATE=y
-CONFIG_DMA_NONCOHERENT=y
-CONFIG_EXT2_FS=y
-CONFIG_FS_POSIX_ACL=y
-CONFIG_GENERIC_FIND_NEXT_BIT=y
-CONFIG_GENERIC_GPIO=y
-# CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ is not set
-CONFIG_HAS_DMA=y
-CONFIG_HAS_IOMEM=y
-CONFIG_HAS_IOPORT=y
-CONFIG_HID_SUPPORT=y
-CONFIG_HW_HAS_PCI=y
-CONFIG_HW_RANDOM=y
-# CONFIG_I2C is not set
-# CONFIG_IDE is not set
-CONFIG_INITRAMFS_SOURCE=""
-CONFIG_INPUT=y
-CONFIG_INPUT_KEYBOARD=y
-CONFIG_IRQ_CPU=y
-CONFIG_KEXEC=y
-# CONFIG_KEYBOARD_ATKBD is not set
-CONFIG_KEYBOARD_GPIO=y
-# CONFIG_KEYBOARD_LKKBD is not set
-# CONFIG_KEYBOARD_NEWTON is not set
-# CONFIG_KEYBOARD_STOWAWAY is not set
-# CONFIG_KEYBOARD_SUNKBD is not set
-# CONFIG_KEYBOARD_XTKBD is not set
-CONFIG_KORINA=y
-# CONFIG_LEDS_ALIX is not set
-# CONFIG_LEDS_GPIO is not set
-CONFIG_LEDS_RB500=y
-# CONFIG_LEMOTE_FULONG is not set
-# CONFIG_MACH_ALCHEMY is not set
-# CONFIG_MACH_DECSTATION is not set
-# CONFIG_MACH_JAZZ is not set
-# CONFIG_MACH_VR41XX is not set
-CONFIG_MIKROTIK_RB500=y
-CONFIG_MINI_FO=m
-CONFIG_MIPS=y
-# CONFIG_MIPS_ATLAS is not set
-# CONFIG_MIPS_COBALT is not set
-CONFIG_MIPS_L1_CACHE_SHIFT=4
-# CONFIG_MIPS_MALTA is not set
-CONFIG_MIPS_MT_DISABLED=y
-# CONFIG_MIPS_MT_SMP is not set
-# CONFIG_MIPS_MT_SMTC is not set
-# CONFIG_MIPS_SEAD is not set
-# CONFIG_MIPS_SIM is not set
-CONFIG_MTD=y
-# CONFIG_MTD_ABSENT is not set
-CONFIG_MTD_BLKDEVS=y
-CONFIG_MTD_BLOCK=y
-CONFIG_MTD_BLOCK2MTD=y
-# CONFIG_MTD_CFI is not set
-CONFIG_MTD_CFI_I1=y
-CONFIG_MTD_CFI_I2=y
-# CONFIG_MTD_CFI_I4 is not set
-# CONFIG_MTD_CFI_I8 is not set
-CONFIG_MTD_CHAR=y
-# CONFIG_MTD_CMDLINE_PARTS is not set
-# CONFIG_MTD_COMPLEX_MAPPINGS is not set
-# CONFIG_MTD_CONCAT is not set
-# CONFIG_MTD_DEBUG is not set
-# CONFIG_MTD_DOC2000 is not set
-# CONFIG_MTD_DOC2001 is not set
-# CONFIG_MTD_DOC2001PLUS is not set
-# CONFIG_MTD_JEDECPROBE is not set
-CONFIG_MTD_MAP_BANK_WIDTH_1=y
-# CONFIG_MTD_MAP_BANK_WIDTH_16 is not set
-CONFIG_MTD_MAP_BANK_WIDTH_2=y
-# CONFIG_MTD_MAP_BANK_WIDTH_32 is not set
-CONFIG_MTD_MAP_BANK_WIDTH_4=y
-# CONFIG_MTD_MAP_BANK_WIDTH_8 is not set
-# CONFIG_MTD_MTDRAM is not set
-CONFIG_MTD_NAND=y
-# CONFIG_MTD_NAND_CAFE is not set
-# CONFIG_MTD_NAND_DISKONCHIP is not set
-# CONFIG_MTD_NAND_ECC_SMC is not set
-CONFIG_MTD_NAND_IDS=y
-# CONFIG_MTD_NAND_MUSEUM_IDS is not set
-# CONFIG_MTD_NAND_NANDSIM is not set
-CONFIG_MTD_NAND_PLATFORM=y
-CONFIG_MTD_NAND_VERIFY_WRITE=y
-# CONFIG_MTD_ONENAND is not set
-CONFIG_MTD_PARTITIONS=y
-# CONFIG_MTD_PHRAM is not set
-# CONFIG_MTD_PLATRAM is not set
-# CONFIG_MTD_PMC551 is not set
-# CONFIG_MTD_RAM is not set
-# CONFIG_MTD_REDBOOT_PARTS is not set
-# CONFIG_MTD_ROM is not set
-# CONFIG_MTD_SLRAM is not set
-# CONFIG_NATSEMI is not set
-# CONFIG_NE2K_PCI is not set
-# CONFIG_NET_SCH_ESFQ_NFCT is not set
-# CONFIG_NET_VENDOR_3COM is not set
-# CONFIG_NO_IOPORT is not set
-# CONFIG_PAGE_SIZE_16KB is not set
-CONFIG_PAGE_SIZE_4KB=y
-# CONFIG_PAGE_SIZE_64KB is not set
-# CONFIG_PAGE_SIZE_8KB is not set
-# CONFIG_PCIPCWATCHDOG is not set
-CONFIG_PCI=y
-# CONFIG_PMC_MSP is not set
-# CONFIG_PMC_YOSEMITE is not set
-# CONFIG_PNX8550_JBS is not set
-# CONFIG_PNX8550_STB810 is not set
-CONFIG_RC32434_WDT=y
-# CONFIG_RTC is not set
-CONFIG_RWSEM_GENERIC_SPINLOCK=y
-CONFIG_SCHED_NO_NO_OMIT_FRAME_POINTER=y
-CONFIG_SCSI_WAIT_SCAN=m
-# CONFIG_SERIAL_8250_EXTENDED is not set
-# CONFIG_SGI_IP22 is not set
-# CONFIG_SGI_IP27 is not set
-# CONFIG_SGI_IP32 is not set
-# CONFIG_SIBYTE_BIGSUR is not set
-# CONFIG_SIBYTE_CARMEL is not set
-# CONFIG_SIBYTE_CRHINE is not set
-# CONFIG_SIBYTE_CRHONE is not set
-# CONFIG_SIBYTE_LITTLESUR is not set
-# CONFIG_SIBYTE_PTSWARM is not set
-# CONFIG_SIBYTE_RHONE is not set
-# CONFIG_SIBYTE_SENTOSA is not set
-# CONFIG_SIBYTE_SWARM is not set
-# CONFIG_SOFT_WATCHDOG is not set
-# CONFIG_SOUND is not set
-# CONFIG_SPARSEMEM_STATIC is not set
-CONFIG_SWAP_IO_SPACE=y
-CONFIG_SYSVIPC_SYSCTL=y
-CONFIG_SYS_HAS_CPU_MIPS32_R1=y
-CONFIG_SYS_SUPPORTS_32BIT_KERNEL=y
-CONFIG_SYS_SUPPORTS_ARBIT_HZ=y
-CONFIG_SYS_SUPPORTS_LITTLE_ENDIAN=y
-# CONFIG_TC35815 is not set
-# CONFIG_TOSHIBA_JMR3927 is not set
-# CONFIG_TOSHIBA_RBTX4927 is not set
-# CONFIG_TOSHIBA_RBTX4938 is not set
-CONFIG_TRAD_SIGNALS=y
-CONFIG_USB=m
-# CONFIG_USER_NS is not set
-# CONFIG_VGASTATE is not set
-CONFIG_VIA_RHINE=y
-# CONFIG_VIA_RHINE_MMIO is not set
-CONFIG_VIA_RHINE_NAPI=y
-# CONFIG_YAFFS_9BYTE_TAGS is not set
-CONFIG_YAFFS_ALWAYS_CHECK_CHUNK_ERASED=y
-CONFIG_YAFFS_AUTO_YAFFS2=y
-CONFIG_YAFFS_CHECKPOINT_RESERVED_BLOCKS=0
-# CONFIG_YAFFS_DISABLE_LAZY_LOAD is not set
-# CONFIG_YAFFS_DISABLE_WIDE_TNODES is not set
-CONFIG_YAFFS_DOES_ECC=y
-CONFIG_YAFFS_ECC_WRONG_ORDER=y
-CONFIG_YAFFS_FS=y
-CONFIG_YAFFS_SHORT_NAMES_IN_RAM=y
-CONFIG_YAFFS_YAFFS1=y
-CONFIG_YAFFS_YAFFS2=y
-CONFIG_ZONE_DMA_FLAG=0
+++ /dev/null
-/*
- * Copyright 2001 MontaVista Software Inc.
- * Author: MontaVista Software, Inc.
- * stevel@mvista.com or source@mvista.com
- *
- * 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 SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
- * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * 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.,
- * 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-#include <linux/types.h>
-#include <linux/pci.h>
-#include <linux/kernel.h>
-#include <linux/init.h>
-
-#include <asm/pci.h>
-#include <asm/io.h>
-
-#include <asm/rc32434/rc32434.h>
-
-static int __devinitdata irq_map[2][12] = {
- { 0, 0, 2, 3, 2, 3, 0, 0, 0, 0, 0, 1 },
- { 0, 0, 1, 3, 0, 2, 1, 3, 0, 2, 1, 3 }
-};
-
-int __init pcibios_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
-{
- int irq = 0;
-
- if (dev->bus->number < 2 && PCI_SLOT(dev->devfn) < 12) {
- irq = irq_map[dev->bus->number][PCI_SLOT(dev->devfn)];
- }
- return irq + GROUP4_IRQ_BASE + 4;
-}
-
+++ /dev/null
-/**************************************************************************
- *
- * BRIEF MODULE DESCRIPTION
- * pci_ops for IDT EB434 board
- *
- * Copyright 2004 IDT Inc. (rischelp@idt.com)
- * Copyright 2006 Felix Fietkau <nbd@openwrt.org>
- *
- * 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 SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
- * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * 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.,
- * 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- *
- **************************************************************************
- * May 2004 rkt, neb
- *
- * Initial Release
- *
- *
- *
- **************************************************************************
- */
-
-#include <linux/autoconf.h>
-#include <linux/init.h>
-#include <linux/pci.h>
-#include <linux/types.h>
-#include <linux/delay.h>
-
-#include <asm/cpu.h>
-#include <asm/io.h>
-
-#include <asm/rc32434/rc32434.h>
-#include <asm/rc32434/pci.h>
-
-#define PCI_ACCESS_READ 0
-#define PCI_ACCESS_WRITE 1
-
-
-#define PCI_CFG_SET(bus,slot,func,off) \
- (rc32434_pci->pcicfga = (0x80000000 | \
- ((bus) << 16) | ((slot)<<11) | \
- ((func)<<8) | (off)))
-
-static inline int config_access(unsigned char access_type, struct pci_bus *bus,
- unsigned int devfn, unsigned char where,
- u32 * data)
-{
- unsigned int slot = PCI_SLOT(devfn);
- u8 func = PCI_FUNC(devfn);
-
- /* Setup address */
- PCI_CFG_SET(bus->number, slot, func, where);
- rc32434_sync();
-
- if (access_type == PCI_ACCESS_WRITE)
- rc32434_pci->pcicfgd = *data;
- else
- *data = rc32434_pci->pcicfgd;
-
- rc32434_sync();
-
- return 0;
-}
-
-
-/*
- * We can't address 8 and 16 bit words directly. Instead we have to
- * read/write a 32bit word and mask/modify the data we actually want.
- */
-static int read_config_byte(struct pci_bus *bus, unsigned int devfn,
- int where, u8 * val)
-{
- u32 data;
- int ret;
-
- ret = config_access(PCI_ACCESS_READ, bus, devfn, where, &data);
- *val = (data >> ((where & 3) << 3)) & 0xff;
- return ret;
-}
-
-static int read_config_word(struct pci_bus *bus, unsigned int devfn,
- int where, u16 * val)
-{
- u32 data;
- int ret;
-
- ret = config_access(PCI_ACCESS_READ, bus, devfn, where, &data);
- *val = (data >> ((where & 3) << 3)) & 0xffff;
- return ret;
-}
-
-static int read_config_dword(struct pci_bus *bus, unsigned int devfn,
- int where, u32 * val)
-{
- int ret;
- int delay = 1;
-
- if (bus->number == 0 && PCI_SLOT(devfn) > 21)
- return 0;
-
-retry:
- ret = config_access(PCI_ACCESS_READ, bus, devfn, where, val);
-
- /* PCI scan: check for invalid values, device may not have
- * finished initializing */
-
- if (where == PCI_VENDOR_ID) {
- if (ret == 0xffffffff || ret == 0x00000000 ||
- ret == 0x0000ffff || ret == 0xffff0000) {
-
- if (delay > 4)
- return 0;
-
- delay *= 2;
- msleep(delay);
- goto retry;
- }
- }
-
- return ret;
-}
-
-static int
-write_config_byte(struct pci_bus *bus, unsigned int devfn, int where,
- u8 val)
-{
- u32 data = 0;
-
- if (config_access(PCI_ACCESS_READ, bus, devfn, where, &data))
- return -1;
-
- data = (data & ~(0xff << ((where & 3) << 3))) |
- (val << ((where & 3) << 3));
-
- if (config_access(PCI_ACCESS_WRITE, bus, devfn, where, &data))
- return -1;
-
- return PCIBIOS_SUCCESSFUL;
-}
-
-
-static int
-write_config_word(struct pci_bus *bus, unsigned int devfn, int where,
- u16 val)
-{
- u32 data = 0;
-
- if (config_access(PCI_ACCESS_READ, bus, devfn, where, &data))
- return -1;
-
- data = (data & ~(0xffff << ((where & 3) << 3))) |
- (val << ((where & 3) << 3));
-
- if (config_access(PCI_ACCESS_WRITE, bus, devfn, where, &data))
- return -1;
-
-
- return PCIBIOS_SUCCESSFUL;
-}
-
-
-static int
-write_config_dword(struct pci_bus *bus, unsigned int devfn, int where,
- u32 val)
-{
- if (config_access(PCI_ACCESS_WRITE, bus, devfn, where, &val))
- return -1;
-
- return PCIBIOS_SUCCESSFUL;
-}
-
-static int pci_config_read(struct pci_bus *bus, unsigned int devfn,
- int where, int size, u32 * val)
-{
- switch (size) {
- case 1:
- return read_config_byte(bus, devfn, where, (u8 *) val);
- case 2:
- return read_config_word(bus, devfn, where, (u16 *) val);
- default:
- return read_config_dword(bus, devfn, where, val);
- }
-}
-
-static int pci_config_write(struct pci_bus *bus, unsigned int devfn,
- int where, int size, u32 val)
-{
- switch (size) {
- case 1:
- return write_config_byte(bus, devfn, where, (u8) val);
- case 2:
- return write_config_word(bus, devfn, where, (u16) val);
- default:
- return write_config_dword(bus, devfn, where, val);
- }
-}
-
-struct pci_ops rc32434_pci_ops = {
- .read = pci_config_read,
- .write = pci_config_write,
-};
+++ /dev/null
-/**************************************************************************
- *
- * BRIEF MODULE DESCRIPTION
- * PCI initialization for IDT EB434 board
- *
- * Copyright 2004 IDT Inc. (rischelp@idt.com)
- *
- * 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 SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
- * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * 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.,
- * 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- *
- **************************************************************************
- * May 2004 rkt, neb
- *
- * Initial Release
- *
- *
- *
- **************************************************************************
- */
-
-#include <linux/autoconf.h>
-#include <linux/types.h>
-#include <linux/pci.h>
-#include <linux/kernel.h>
-#include <linux/init.h>
-
-#include <asm/rc32434/rc32434.h>
-#include <asm/rc32434/pci.h>
-
-#define PCI_ACCESS_READ 0
-#define PCI_ACCESS_WRITE 1
-
-/* define an unsigned array for the PCI registers */
-unsigned int korinaCnfgRegs[25] = {
- KORINA_CNFG1, KORINA_CNFG2, KORINA_CNFG3, KORINA_CNFG4,
- KORINA_CNFG5, KORINA_CNFG6, KORINA_CNFG7, KORINA_CNFG8,
- KORINA_CNFG9, KORINA_CNFG10, KORINA_CNFG11, KORINA_CNFG12,
- KORINA_CNFG13, KORINA_CNFG14, KORINA_CNFG15, KORINA_CNFG16,
- KORINA_CNFG17, KORINA_CNFG18, KORINA_CNFG19, KORINA_CNFG20,
- KORINA_CNFG21, KORINA_CNFG22, KORINA_CNFG23, KORINA_CNFG24
-};
-static struct resource rc32434_res_pci_mem1;
-static struct resource rc32434_res_pci_mem2;
-
-static struct resource rc32434_res_pci_mem1 = {
- .name = "PCI MEM1",
- .start = 0x50000000,
- .end = 0x5FFFFFFF,
- .flags = IORESOURCE_MEM,
- .parent = &rc32434_res_pci_mem1,
- .sibling = NULL,
- .child = &rc32434_res_pci_mem2
-};
-
-static struct resource rc32434_res_pci_mem2 = {
- .name = "PCI Mem2",
- .start = 0x60000000,
- .end = 0x6FFFFFFF,
- .flags = IORESOURCE_MEM,
- .parent = &rc32434_res_pci_mem1,
- .sibling = NULL,
- .child = NULL
-};
-
-static struct resource rc32434_res_pci_io1 = {
- .name = "PCI I/O1",
- .start = 0x18800000,
- .end = 0x188FFFFF,
- .flags = IORESOURCE_IO,
-};
-
-extern struct pci_ops rc32434_pci_ops;
-
-#define PCI_MEM1_START PCI_ADDR_START
-#define PCI_MEM1_END PCI_ADDR_START + CPUTOPCI_MEM_WIN - 1
-#define PCI_MEM2_START PCI_ADDR_START + CPUTOPCI_MEM_WIN
-#define PCI_MEM2_END PCI_ADDR_START + ( 2* CPUTOPCI_MEM_WIN) - 1
-#define PCI_IO1_START PCI_ADDR_START + (2 * CPUTOPCI_MEM_WIN)
-#define PCI_IO1_END PCI_ADDR_START + (2* CPUTOPCI_MEM_WIN) + CPUTOPCI_IO_WIN -1
-#define PCI_IO2_START PCI_ADDR_START + (2 * CPUTOPCI_MEM_WIN) + CPUTOPCI_IO_WIN
-#define PCI_IO2_END PCI_ADDR_START + (2* CPUTOPCI_MEM_WIN) + (2 * CPUTOPCI_IO_WIN) -1
-
-
-struct pci_controller rc32434_controller2;
-
-struct pci_controller rc32434_controller = {
- .pci_ops = &rc32434_pci_ops,
- .mem_resource = &rc32434_res_pci_mem1,
- .io_resource = &rc32434_res_pci_io1,
- .mem_offset = 0,
- .io_offset = 0,
-
-};
-
-#ifdef __MIPSEB__
-#define PCI_ENDIAN_FLAG PCILBAC_sb_m
-#else
-#define PCI_ENDIAN_FLAG 0
-#endif
-
-static int __init rc32434_pcibridge_init(void)
-{
- unsigned int pcicValue, pcicData = 0;
- unsigned int dummyRead, pciCntlVal;
- int loopCount;
- unsigned int pciConfigAddr;
-
- pcicValue = rc32434_pci->pcic;
- pcicValue = (pcicValue >> PCIM_SHFT) & PCIM_BIT_LEN;
- if (!((pcicValue == PCIM_H_EA) ||
- (pcicValue == PCIM_H_IA_FIX) ||
- (pcicValue == PCIM_H_IA_RR))) {
- printk("PCI init error!!!\n");
- /* Not in Host Mode, return ERROR */
- return -1;
- }
- /* Enables the Idle Grant mode, Arbiter Parking */
- pcicData |=(PCIC_igm_m|PCIC_eap_m|PCIC_en_m);
- rc32434_pci->pcic = pcicData; /* Enable the PCI bus Interface */
- /* Zero out the PCI status & PCI Status Mask */
- for(;;)
- {
- pcicData = rc32434_pci->pcis;
- if (!(pcicData & PCIS_rip_m))
- break;
- }
-
- rc32434_pci->pcis = 0;
- rc32434_pci->pcism = 0xFFFFFFFF;
- /* Zero out the PCI decoupled registers */
- rc32434_pci->pcidac=0; /* disable PCI decoupled accesses at initialization */
- rc32434_pci->pcidas=0; /* clear the status */
- rc32434_pci->pcidasm=0x0000007F; /* Mask all the interrupts */
- /* Mask PCI Messaging Interrupts */
- rc32434_pci_msg->pciiic = 0;
- rc32434_pci_msg->pciiim = 0xFFFFFFFF;
- rc32434_pci_msg->pciioic = 0;
- rc32434_pci_msg->pciioim = 0;
-
-
- /* Setup PCILB0 as Memory Window */
- rc32434_pci->pcilba[0].a = (unsigned int) (PCI_ADDR_START);
-
- /* setup the PCI map address as same as the local address */
-
- rc32434_pci->pcilba[0].m = (unsigned int) (PCI_ADDR_START);
-
-
- /* Setup PCILBA1 as MEM */
- rc32434_pci->pcilba[0].c = ( ((SIZE_256MB & 0x1f) << PCILBAC_size_b) | PCI_ENDIAN_FLAG);
- dummyRead = rc32434_pci->pcilba[0].c; /* flush the CPU write Buffers */
- rc32434_pci->pcilba[1].a = 0x60000000;
- rc32434_pci->pcilba[1].m = 0x60000000;
-
- /* setup PCILBA2 as IO Window*/
- rc32434_pci->pcilba[1].c = (((SIZE_256MB & 0x1f) << PCILBAC_size_b )| PCI_ENDIAN_FLAG);
- dummyRead = rc32434_pci->pcilba[1].c; /* flush the CPU write Buffers */
- rc32434_pci->pcilba[2].a = 0x18C00000;
- rc32434_pci->pcilba[2].m = 0x18FFFFFF;
-
- /* setup PCILBA2 as IO Window*/
- rc32434_pci->pcilba[2].c = (((SIZE_4MB & 0x1f) << PCILBAC_size_b) | PCI_ENDIAN_FLAG );
- dummyRead = rc32434_pci->pcilba[2].c; /* flush the CPU write Buffers */
-
- /* Setup PCILBA3 as IO Window */
- rc32434_pci->pcilba[3].a = 0x18800000;
- rc32434_pci->pcilba[3].m = 0x18800000;
- rc32434_pci->pcilba[3].c = ( (((SIZE_1MB & 0x1ff) << PCILBAC_size_b) | PCILBAC_msi_m) | PCI_ENDIAN_FLAG);
- dummyRead = rc32434_pci->pcilba[3].c; /* flush the CPU write Buffers */
-
- pciConfigAddr=(unsigned int)(0x80000004);
- for(loopCount=0;loopCount<24;loopCount++){
- rc32434_pci->pcicfga=pciConfigAddr;
- dummyRead=rc32434_pci->pcicfga;
- rc32434_pci->pcicfgd = korinaCnfgRegs[loopCount];
- dummyRead=rc32434_pci->pcicfgd;
- pciConfigAddr += 4;
- }
- rc32434_pci->pcitc = (unsigned int)((PCITC_RTIMER_VAL&0xff) << PCITC_rtimer_b)
- | ((PCITC_DTIMER_VAL&0xff) << PCITC_dtimer_b);
-
- pciCntlVal=rc32434_pci->pcic;
- pciCntlVal &=~(PCIC_tnr_m);
- rc32434_pci->pcic = pciCntlVal;
- pciCntlVal=rc32434_pci->pcic;
- return 0;
-}
-
-/* Do platform specific device initialization at pci_enable_device() time */
-int pcibios_plat_dev_init(struct pci_dev *dev)
-{
- if (PCI_SLOT(dev->devfn) == 6 && dev->bus->number == 0) {
- /* disable prefetched memory range */
- pci_write_config_word(dev, PCI_PREF_MEMORY_LIMIT, 0);
- pci_write_config_word(dev, PCI_PREF_MEMORY_BASE, 0x10);
-
- pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE, 4);
- }
- return 0;
-}
-
-static int __init rc32434_pci_init(void)
-{
- printk("PCI: Initializing PCI\n");
-
- ioport_resource.start = rc32434_res_pci_io1.start;
- ioport_resource.end = rc32434_res_pci_io1.end;
-
- rc32434_pcibridge_init();
-
- register_pci_controller(&rc32434_controller);
- rc32434_sync();
-
- return 0;
-}
-
-arch_initcall(rc32434_pci_init);
-
+++ /dev/null
-#
-# Makefile for the RB500 board specific parts of the kernel
-#
-
-obj-y += irq.o time.o setup.o serial.o prom.o gpio.o devices.o
+++ /dev/null
-/*
- * RouterBoard 500 Platform devices
- *
- * Copyright (C) 2006 Felix Fietkau <nbd@openwrt.org>
- * Copyright (C) 2007 Florian Fainelli <florian@openwrt.org>
- *
- * 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.
- */
-#include <linux/kernel.h>
-#include <linux/init.h>
-#include <linux/ctype.h>
-#include <linux/string.h>
-#include <linux/platform_device.h>
-#include <linux/mtd/nand.h>
-#include <linux/mtd/mtd.h>
-#include <linux/mtd/partitions.h>
-#include <linux/gpio_keys.h>
-#include <linux/input.h>
-
-#include <asm/bootinfo.h>
-
-#include <asm/rc32434/rc32434.h>
-#include <asm/rc32434/dma.h>
-#include <asm/rc32434/dma_v.h>
-#include <asm/rc32434/eth.h>
-#include <asm/rc32434/rb.h>
-
-#define ETH0_DMA_RX_IRQ GROUP1_IRQ_BASE + 0
-#define ETH0_DMA_TX_IRQ GROUP1_IRQ_BASE + 1
-#define ETH0_RX_OVR_IRQ GROUP3_IRQ_BASE + 9
-#define ETH0_TX_UND_IRQ GROUP3_IRQ_BASE + 10
-
-#define ETH0_RX_DMA_ADDR (DMA0_PhysicalAddress + 0*DMA_CHAN_OFFSET)
-#define ETH0_TX_DMA_ADDR (DMA0_PhysicalAddress + 1*DMA_CHAN_OFFSET)
-
-/* NAND definitions */
-#define MEM32(x) *((volatile unsigned *) (x))
-
-#define GPIO_RDY (1 << 0x08)
-#define GPIO_WPX (1 << 0x09)
-#define GPIO_ALE (1 << 0x0a)
-#define GPIO_CLE (1 << 0x0b)
-
-extern char* board_type;
-
-static struct resource korina_dev0_res[] = {
- {
- .name = "korina_regs",
- .start = ETH0_PhysicalAddress,
- .end = ETH0_PhysicalAddress + sizeof(ETH_t),
- .flags = IORESOURCE_MEM,
- }, {
- .name = "korina_rx",
- .start = ETH0_DMA_RX_IRQ,
- .end = ETH0_DMA_RX_IRQ,
- .flags = IORESOURCE_IRQ
- }, {
- .name = "korina_tx",
- .start = ETH0_DMA_TX_IRQ,
- .end = ETH0_DMA_TX_IRQ,
- .flags = IORESOURCE_IRQ
- }, {
- .name = "korina_ovr",
- .start = ETH0_RX_OVR_IRQ,
- .end = ETH0_RX_OVR_IRQ,
- .flags = IORESOURCE_IRQ
- }, {
- .name = "korina_und",
- .start = ETH0_TX_UND_IRQ,
- .end = ETH0_TX_UND_IRQ,
- .flags = IORESOURCE_IRQ
- }, {
- .name = "korina_dma_rx",
- .start = ETH0_RX_DMA_ADDR,
- .end = ETH0_RX_DMA_ADDR + DMA_CHAN_OFFSET - 1,
- .flags = IORESOURCE_MEM,
- }, {
- .name = "korina_dma_tx",
- .start = ETH0_TX_DMA_ADDR,
- .end = ETH0_TX_DMA_ADDR + DMA_CHAN_OFFSET - 1,
- .flags = IORESOURCE_MEM,
- }
-};
-
-static struct korina_device korina_dev0_data = {
- .name = "korina0",
- .mac = {0xde, 0xca, 0xff, 0xc0, 0xff, 0xee}
-};
-
-static struct platform_device korina_dev0 = {
- .id = 0,
- .name = "korina",
- .dev.platform_data = &korina_dev0_data,
- .resource = korina_dev0_res,
- .num_resources = ARRAY_SIZE(korina_dev0_res),
-};
-
-#define CF_GPIO_NUM 13
-
-static struct resource cf_slot0_res[] = {
- {
- .name = "cf_membase",
- .flags = IORESOURCE_MEM
- }, {
- .name = "cf_irq",
- .start = (8 + 4 * 32 + CF_GPIO_NUM), /* 149 */
- .end = (8 + 4 * 32 + CF_GPIO_NUM),
- .flags = IORESOURCE_IRQ
- }
-};
-
-static struct cf_device cf_slot0_data = {
- .gpio_pin = 13
-};
-
-static struct platform_device cf_slot0 = {
- .id = 0,
- .name = "rb500-cf",
- .dev.platform_data = &cf_slot0_data,
- .resource = cf_slot0_res,
- .num_resources = ARRAY_SIZE(cf_slot0_res),
-};
-
-/* Resources and device for NAND. There is no data needed and no irqs, so just define the memory used. */
-
-/*
- * We need to use the OLD Yaffs-1 OOB layout, otherwise the RB bootloader
- * will not be able to find the kernel that we load. So set the oobinfo
- * when creating the partitions
- */
-static struct nand_ecclayout rb500_nand_ecclayout = {
- .eccbytes = 6,
- .eccpos = { 8, 9, 10, 13, 14, 15 },
- .oobavail = 9,
- .oobfree = { { 0, 4 }, { 6, 2 }, { 11, 2 }, { 4, 1 } }
-};
-
-int rb500_dev_ready(struct mtd_info *mtd)
-{
- return MEM32(IDT434_REG_BASE + GPIOD) & GPIO_RDY;
-}
-
-void rb500_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl)
-{
- struct nand_chip *chip = mtd->priv;
- unsigned char orbits, nandbits;
-
- if (ctrl & NAND_CTRL_CHANGE) {
-
- orbits = (ctrl & NAND_CLE) << 1;
- orbits |= (ctrl & NAND_ALE) >> 1;
-
- nandbits = (~ctrl & NAND_CLE) << 1;
- nandbits |= (~ctrl & NAND_ALE) >> 1;
-
- changeLatchU5(orbits, nandbits);
- }
- if (cmd != NAND_CMD_NONE)
- writeb(cmd, chip->IO_ADDR_W);
-}
-
-static struct resource nand_slot0_res[] = {
- [0] = {
- .name = "nand_membase",
- .flags = IORESOURCE_MEM
- }
-};
-
-struct platform_nand_data rb500_nand_data = {
- .ctrl.dev_ready = rb500_dev_ready,
- .ctrl.cmd_ctrl = rb500_cmd_ctrl,
-};
-
-static struct platform_device nand_slot0 = {
- .name = "gen_nand",
- .id = -1,
- .resource = nand_slot0_res,
- .num_resources = ARRAY_SIZE(nand_slot0_res),
- .dev.platform_data = &rb500_nand_data,
-};
-
-static struct mtd_partition rb500_partition_info[] = {
- {
- .name = "Routerboard NAND boot",
- .offset = 0,
- .size = 4 * 1024 * 1024,
- }, {
- .name = "rootfs",
- .offset = MTDPART_OFS_NXTBLK,
- .size = MTDPART_SIZ_FULL,
- }
-};
-
-static struct platform_device rb500_led = {
- .name = "rb500-led",
- .id = 0,
-};
-
-static struct gpio_keys_button rb500_gpio_btn[] = {
- {
- .gpio = 1,
- .code = BTN_0,
- .desc = "S1",
- .active_low = 1,
- }
-};
-
-static struct gpio_keys_platform_data rb500_gpio_btn_data = {
- .buttons = rb500_gpio_btn,
- .nbuttons = ARRAY_SIZE(rb500_gpio_btn),
-};
-
-static struct platform_device rb500_button = {
- .name = "gpio-keys",
- .id = -1,
- .dev = {
- .platform_data = &rb500_gpio_btn_data,
- }
-};
-
-static struct platform_device *rb500_devs[] = {
- &korina_dev0,
- &nand_slot0,
- &cf_slot0,
- &rb500_led,
- &rb500_button
-};
-
-static void __init parse_mac_addr(char *macstr)
-{
- int i, j;
- unsigned char result, value;
-
- for (i = 0; i < 6; i++) {
- result = 0;
-
- if (i != 5 && *(macstr + 2) != ':')
- return;
-
- for (j = 0; j < 2; j++) {
- if (isxdigit(*macstr)
- && (value =
- isdigit(*macstr) ? *macstr -
- '0' : toupper(*macstr) - 'A' + 10) < 16) {
- result = result * 16 + value;
- macstr++;
- } else
- return;
- }
-
- macstr++;
- korina_dev0_data.mac[i] = result;
- }
-}
-
-
-/* DEVICE CONTROLLER 1 */
-#define CFG_DC_DEV1 (void*)0xb8010010
-#define CFG_DC_DEV2 (void*)0xb8010020
-#define CFG_DC_DEVBASE 0x0
-#define CFG_DC_DEVMASK 0x4
-#define CFG_DC_DEVC 0x8
-#define CFG_DC_DEVTC 0xC
-
-/* NAND definitions */
-#define NAND_CHIP_DELAY 25
-
-static int rb500_nand_fixup(struct mtd_info *mtd)
-{
- struct nand_chip *chip = mtd->priv;
-
- if (mtd->writesize == 512)
- chip->ecc.layout = &rb500_nand_ecclayout;
-
- return 0;
-}
-
-static void __init rb500_nand_setup(void)
-{
- switch (mips_machtype) {
- case MACH_MIKROTIK_RB532A:
- changeLatchU5(LO_FOFF | LO_CEX, LO_ULED | LO_ALE | LO_CLE | LO_WPX);
- break;
- default:
- changeLatchU5(LO_WPX | LO_FOFF | LO_CEX, LO_ULED | LO_ALE | LO_CLE);
- break;
- }
-
- /* Setup NAND specific settings */
- rb500_nand_data.chip.nr_chips = 1;
- rb500_nand_data.chip.nr_partitions = ARRAY_SIZE(rb500_partition_info);
- rb500_nand_data.chip.partitions = rb500_partition_info;
- rb500_nand_data.chip.chip_delay = NAND_CHIP_DELAY;
- rb500_nand_data.chip.options = NAND_NO_AUTOINCR;
-
- rb500_nand_data.chip.chip_fixup = &rb500_nand_fixup;
-}
-
-
-static int __init plat_setup_devices(void)
-{
- /* Look for the CF card reader */
- if (!readl(CFG_DC_DEV1 + CFG_DC_DEVMASK))
- rb500_devs[1] = NULL;
- else {
- cf_slot0_res[0].start =
- readl(CFG_DC_DEV1 + CFG_DC_DEVBASE);
- cf_slot0_res[0].end = cf_slot0_res[0].start + 0x1000;
- }
-
- /* Read the NAND resources from the device controller */
- nand_slot0_res[0].start = readl(CFG_DC_DEV2 + CFG_DC_DEVBASE);
- nand_slot0_res[0].end = nand_slot0_res[0].start + 0x1000;
-
- /* Initialise the NAND device */
- rb500_nand_setup();
-
- return platform_add_devices(rb500_devs, ARRAY_SIZE(rb500_devs));
-}
-
-static int __init setup_kmac(char *s)
-{
- printk("korina mac = %s\n", s);
- parse_mac_addr(s);
- return 0;
-}
-
-__setup("kmac=", setup_kmac);
-
-arch_initcall(plat_setup_devices);
+++ /dev/null
-/*
- * Miscellaneous functions for IDT EB434 board
- *
- * Copyright 2004 IDT Inc. (rischelp@idt.com)
- * Copyright 2006 Phil Sutter <n0-1@freewrt.org>
- * Copyright 2007 Florian Fainelli <florian@openwrt.org>
- *
- * 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 SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
- * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * 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.,
- * 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-#include <linux/kernel.h>
-#include <linux/init.h>
-#include <linux/types.h>
-#include <linux/pci.h>
-#include <linux/spinlock.h>
-#include <linux/io.h>
-#include <linux/platform_device.h>
-
-#include <asm/addrspace.h>
-#include <asm/gpio.h>
-
-#include <asm/rc32434/rb.h>
-
-#define GPIO_BADDR 0x18050000
-
-static volatile unsigned char *devCtl3Base;
-static unsigned char latchU5State;
-static spinlock_t clu5Lock = SPIN_LOCK_UNLOCKED;
-
-struct rb500_gpio_reg __iomem *rb500_gpio_reg0;
-EXPORT_SYMBOL(rb500_gpio_reg0);
-
-static struct resource rb500_gpio_reg0_res[] = {
- {
- .name = "gpio_reg0",
- .start = GPIO_BADDR,
- .end = GPIO_BADDR + sizeof(struct rb500_gpio_reg),
- .flags = IORESOURCE_MEM,
- }
-};
-
-void set434Reg(unsigned regOffs, unsigned bit, unsigned len, unsigned val)
-{
- unsigned flags, data;
- unsigned i = 0;
-
- spin_lock_irqsave(&clu5Lock, flags);
- data = *(volatile unsigned *) (IDT434_REG_BASE + regOffs);
- for (i = 0; i != len; ++i) {
- if (val & (1 << i))
- data |= (1 << (i + bit));
- else
- data &= ~(1 << (i + bit));
- }
- *(volatile unsigned *) (IDT434_REG_BASE + regOffs) = data;
- spin_unlock_irqrestore(&clu5Lock, flags);
-}
-EXPORT_SYMBOL(set434Reg);
-
-void changeLatchU5(unsigned char orMask, unsigned char nandMask)
-{
- unsigned flags;
-
- spin_lock_irqsave(&clu5Lock, flags);
- latchU5State = (latchU5State | orMask) & ~nandMask;
- if (!devCtl3Base)
- devCtl3Base = (volatile unsigned char *)
- KSEG1ADDR(*(volatile unsigned *)
- KSEG1ADDR(0x18010030));
- *devCtl3Base = latchU5State;
- spin_unlock_irqrestore(&clu5Lock, flags);
-}
-EXPORT_SYMBOL(changeLatchU5);
-
-unsigned char getLatchU5State(void)
-{
- return latchU5State;
-}
-EXPORT_SYMBOL(getLatchU5State);
-
-int rb500_gpio_get_value(unsigned gpio)
-{
- return readl(&rb500_gpio_reg0->gpiod) & (1 << gpio);
-}
-EXPORT_SYMBOL(rb500_gpio_get_value);
-
-void rb500_gpio_set_value(unsigned gpio, int value)
-{
- unsigned tmp;
-
- tmp = readl(&rb500_gpio_reg0->gpiod) & ~(1 << gpio);
- if (value)
- tmp |= 1 << gpio;
-
- writel(tmp, (void *)&rb500_gpio_reg0->gpiod);
-}
-EXPORT_SYMBOL(rb500_gpio_set_value);
-
-int rb500_gpio_direction_input(unsigned gpio)
-{
- writel(readl(&rb500_gpio_reg0->gpiocfg) & ~(1 << gpio), (void *)&rb500_gpio_reg0->gpiocfg);
-
- return 0;
-}
-EXPORT_SYMBOL(rb500_gpio_direction_input);
-
-int rb500_gpio_direction_output(unsigned gpio, int value)
-{
- gpio_set_value(gpio, value);
- writel(readl(&rb500_gpio_reg0->gpiocfg) | (1 << gpio), (void *)&rb500_gpio_reg0->gpiocfg);
-
- return 0;
-}
-EXPORT_SYMBOL(rb500_gpio_direction_output);
-
-void rb500_gpio_set_int_level(unsigned gpio, int value)
-{
- unsigned tmp;
-
- tmp = readl(&rb500_gpio_reg0->gpioilevel) & ~(1 << gpio);
- if (value)
- tmp |= 1 << gpio;
- writel(tmp, (void *)&rb500_gpio_reg0->gpioilevel);
-}
-EXPORT_SYMBOL(rb500_gpio_set_int_level);
-
-int rb500_gpio_get_int_level(unsigned gpio)
-{
- return readl(&rb500_gpio_reg0->gpioilevel) & (1 << gpio);
-}
-EXPORT_SYMBOL(rb500_gpio_get_int_level);
-
-void rb500_gpio_set_int_status(unsigned gpio, int value)
-{
- unsigned tmp;
-
- tmp = readl(&rb500_gpio_reg0->gpioistat);
- if (value)
- tmp |= 1 << gpio;
- writel(tmp, (void *)&rb500_gpio_reg0->gpioistat);
-}
-EXPORT_SYMBOL(rb500_gpio_set_int_status);
-
-int rb500_gpio_get_int_status(unsigned gpio)
-{
- return readl(&rb500_gpio_reg0->gpioistat) & (1 << gpio);
-}
-EXPORT_SYMBOL(rb500_gpio_get_int_status);
-
-void rb500_gpio_set_func(unsigned gpio, int value)
-{
- unsigned tmp;
-
- tmp = readl(&rb500_gpio_reg0->gpiofunc);
- if (value)
- tmp |= 1 << gpio;
- writel(tmp, (void *)&rb500_gpio_reg0->gpiofunc);
-}
-EXPORT_SYMBOL(rb500_gpio_set_func);
-
-int rb500_gpio_get_func(unsigned gpio)
-{
- return readl(&rb500_gpio_reg0->gpiofunc) & (1 << gpio);
-}
-EXPORT_SYMBOL(rb500_gpio_get_func);
-
-int __init rb500_gpio_init(void)
-{
- rb500_gpio_reg0 = ioremap_nocache(rb500_gpio_reg0_res[0].start,
- rb500_gpio_reg0_res[0].end -
- rb500_gpio_reg0_res[0].start);
-
- if (!rb500_gpio_reg0) {
- printk(KERN_ERR "rb500: cannot remap GPIO register 0\n");
- return -ENXIO;
- }
-
- return 0;
-}
-arch_initcall(rb500_gpio_init);
+++ /dev/null
-/*
- * BRIEF MODULE DESCRIPTION
- * RC32434 interrupt routines.
- *
- * Copyright 2002 MontaVista Software Inc.
- * Author: MontaVista Software, Inc.
- * stevel@mvista.com or source@mvista.com
- *
- * 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 SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
- * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * 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.,
- * 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-#include <linux/errno.h>
-#include <linux/init.h>
-#include <linux/kernel_stat.h>
-#include <linux/module.h>
-#include <linux/signal.h>
-#include <linux/sched.h>
-#include <linux/types.h>
-#include <linux/interrupt.h>
-#include <linux/ioport.h>
-#include <linux/timex.h>
-#include <linux/slab.h>
-#include <linux/random.h>
-#include <linux/delay.h>
-
-#include <asm/bitops.h>
-#include <asm/bootinfo.h>
-#include <asm/io.h>
-#include <asm/irq.h>
-#include <asm/time.h>
-#include <asm/mipsregs.h>
-#include <asm/system.h>
-#include <asm/rc32434/rc32434.h>
-#include <asm/rc32434/gpio.h>
-
-extern void set_debug_traps(void);
-extern irq_cpustat_t irq_stat [NR_CPUS];
-unsigned int local_bh_count[NR_CPUS];
-unsigned int local_irq_count[NR_CPUS];
-
-static unsigned int startup_irq(unsigned int irq);
-static void rb500_end_irq(unsigned int irq_nr);
-static void mask_and_ack_irq(unsigned int irq_nr);
-static void rb500_enable_irq(unsigned int irq_nr);
-static void rb500_disable_irq(unsigned int irq_nr);
-
-extern void __init init_generic_irq(void);
-extern struct rb500_gpio_reg __iomem *rb500_gpio_reg0;
-
-typedef struct {
- u32 mask; /* mask of valid bits in pending/mask registers */
- volatile u32 *base_addr;
-} intr_group_t;
-
-#define RC32434_NR_IRQS (GROUP4_IRQ_BASE + 32)
-
-#if (NR_IRQS < RC32434_NR_IRQS)
-#error Too little irqs defined. Did you override <asm/irq.h> ?
-#endif
-
-static const intr_group_t intr_group[NUM_INTR_GROUPS] = {
- { 0x0000efff, (u32 *)KSEG1ADDR(IC_GROUP0_PEND + 0 * IC_GROUP_OFFSET) },
- { 0x00001fff, (u32 *)KSEG1ADDR(IC_GROUP0_PEND + 1 * IC_GROUP_OFFSET) },
- { 0x00000007, (u32 *)KSEG1ADDR(IC_GROUP0_PEND + 2 * IC_GROUP_OFFSET) },
- { 0x0003ffff, (u32 *)KSEG1ADDR(IC_GROUP0_PEND + 3 * IC_GROUP_OFFSET) },
- { 0xffffffff, (u32 *)KSEG1ADDR(IC_GROUP0_PEND + 4 * IC_GROUP_OFFSET) }
-};
-
-#define READ_PEND(base) (*(base))
-#define READ_MASK(base) (*(base + 2))
-#define WRITE_MASK(base, val) (*(base + 2) = (val))
-
-static inline int irq_to_group(unsigned int irq_nr)
-{
- return ((irq_nr - GROUP0_IRQ_BASE) >> 5);
-}
-
-static inline int group_to_ip(unsigned int group)
-{
- return group + 2;
-}
-
-static inline void enable_local_irq(unsigned int ip)
-{
- int ipnum = 0x100 << ip;
- clear_c0_cause(ipnum);
- set_c0_status(ipnum);
-}
-
-static inline void disable_local_irq(unsigned int ip)
-{
- int ipnum = 0x100 << ip;
- clear_c0_status(ipnum);
-}
-
-static inline void ack_local_irq(unsigned int ip)
-{
- int ipnum = 0x100 << ip;
- clear_c0_cause(ipnum);
-}
-
-static void rb500_enable_irq(unsigned int irq_nr)
-{
- int ip = irq_nr - GROUP0_IRQ_BASE;
- unsigned int group, intr_bit;
- volatile unsigned int *addr;
-
-
- if (ip < 0)
- enable_local_irq(irq_nr);
- else {
- group = ip >> 5;
-
- ip &= (1<<5)-1;
- intr_bit = 1 << ip;
-
- enable_local_irq(group_to_ip(group));
-
- addr = intr_group[group].base_addr;
- WRITE_MASK(addr, READ_MASK(addr) & ~intr_bit);
- }
-}
-
-static void rb500_disable_irq(unsigned int irq_nr)
-{
- int ip = irq_nr - GROUP0_IRQ_BASE;
- unsigned int group, intr_bit, mask;
- volatile unsigned int *addr;
-
- if (ip < 0) {
- disable_local_irq(irq_nr);
- }else{
- group = ip >> 5;
-
- ip &= (1<<5) -1;
- intr_bit = 1 << ip;
- addr = intr_group[group].base_addr;
- mask = READ_MASK(addr);
- mask |= intr_bit;
- WRITE_MASK(addr,mask);
-
- /*
- * if there are no more interrupts enabled in this
- * group, disable corresponding IP
- */
- if (mask == intr_group[group].mask)
- disable_local_irq(group_to_ip(group));
- }
-}
-
-static unsigned int startup_irq(unsigned int irq_nr)
-{
- rb500_enable_irq(irq_nr);
- return 0;
-}
-
-static void shutdown_irq(unsigned int irq_nr)
-{
- rb500_disable_irq(irq_nr);
- return;
-}
-
-static void mask_and_ack_irq(unsigned int irq_nr)
-{
- rb500_disable_irq(irq_nr);
- ack_local_irq(group_to_ip(irq_to_group(irq_nr)));
-}
-
-static void rb500_end_irq(unsigned int irq_nr)
-{
-
- int ip = irq_nr - GROUP0_IRQ_BASE;
- unsigned int intr_bit, group;
- volatile unsigned int *addr;
-
- if ((irq_desc[irq_nr].status & (IRQ_DISABLED | IRQ_INPROGRESS))) {
- printk("warning: end_irq %d did not enable (%x)\n",
- irq_nr, irq_desc[irq_nr].status);
- return;
- }
-
- if (ip < 0) {
- enable_local_irq(irq_nr);
- } else {
- group = ip >> 5;
-
- ip &= (1 << 5) - 1;
- intr_bit = 1 << ip;
-
- if (irq_nr >= GROUP4_IRQ_BASE && irq_nr <= (GROUP4_IRQ_BASE + 13)) {
- rb500_gpio_reg0->gpioistat = rb500_gpio_reg0->gpioistat & ~intr_bit;
- }
-
- enable_local_irq(group_to_ip(group));
-
- addr = intr_group[group].base_addr;
- WRITE_MASK(addr, READ_MASK(addr) & ~intr_bit);
- }
-}
-
-static struct hw_interrupt_type rc32434_irq_type = {
- .typename = "RB500",
- .startup = startup_irq,
- .shutdown = shutdown_irq,
- .enable = rb500_enable_irq,
- .disable = rb500_disable_irq,
- .ack = mask_and_ack_irq,
- .end = rb500_end_irq,
-};
-
-
-void __init arch_init_irq(void)
-{
- int i;
-
- printk("Initializing IRQ's: %d out of %d\n", RC32434_NR_IRQS, NR_IRQS);
- memset(irq_desc, 0, sizeof(irq_desc));
-
- for (i = 0; i < RC32434_NR_IRQS; i++) {
- irq_desc[i].status = IRQ_DISABLED;
- irq_desc[i].action = NULL;
- irq_desc[i].depth = 1;
- irq_desc[i].chip = &rc32434_irq_type;
- spin_lock_init(&irq_desc[i].lock);
- }
-}
-
-/* Main Interrupt dispatcher */
-asmlinkage void plat_irq_dispatch(void)
-{
- unsigned int ip, pend, group;
- volatile unsigned int *addr;
- unsigned int cp0_cause = read_c0_cause() & read_c0_status();
-
- if (cp0_cause & CAUSEF_IP7) {
- ll_timer_interrupt(7);
- } else if ((ip = (cp0_cause & 0x7c00))) {
- group = 21 - rc32434_clz(ip);
-
- addr = intr_group[group].base_addr;
-
- pend = READ_PEND(addr);
- pend &= ~READ_MASK(addr); // only unmasked interrupts
- pend = 39 - rc32434_clz(pend);
- do_IRQ((group << 5) + pend);
- }
-}
+++ /dev/null
-/*
-* prom.c
-**********************************************************************
-* P . Sadik Oct 10, 2003
-*
-* Started change log
-* idt_cpu_freq is make a kernel configuration parameter
-* idt_cpu_freq is exported so that other modules can use it.
-* Code cleanup
-**********************************************************************
-* P. Sadik Oct 20, 2003
-*
-* Removed NVRAM code from here, since they are already available under
-* nvram directory.
-* Added serial port initialisation.
-**********************************************************************
-**********************************************************************
-* P. Sadik Oct 30, 2003
-*
-* Added reset_cons_port
-**********************************************************************
-
- P.Christeas, 2005-2006
- Port to 2.6, add 2.6 cmdline parsing
-
-*/
-
-#include <linux/autoconf.h>
-#include <linux/init.h>
-#include <linux/mm.h>
-#include <linux/module.h>
-#include <linux/string.h>
-#include <linux/console.h>
-#include <asm/bootinfo.h>
-#include <linux/bootmem.h>
-#include <linux/ioport.h>
-#include <linux/blkdev.h>
-#include <asm/rc32434/ddr.h>
-
-#define PROM_ENTRY(x) (0xbfc00000+((x)*8))
-extern void __init setup_serial_port(void);
-
-unsigned int idt_cpu_freq = 132000000;
-EXPORT_SYMBOL(idt_cpu_freq);
-unsigned int gpio_bootup_state = 0;
-EXPORT_SYMBOL(gpio_bootup_state);
-
-char mips_mac_address[18] = "08:00:06:05:40:01";
-EXPORT_SYMBOL(mips_mac_address);
-
-/* what to append to cmdline when button is [not] pressed */
-#define GPIO_INIT_NOBUTTON ""
-#define GPIO_INIT_BUTTON " 2"
-
-#ifdef CONFIG_MIKROTIK_RB500
-unsigned soft_reboot = 0;
-EXPORT_SYMBOL(soft_reboot);
-#endif
-
-#define SR_NMI 0x00180000 /* NMI */
-#define SERIAL_SPEED_ENTRY 0x00000001
-
-#ifdef CONFIG_REMOTE_DEBUG
-extern int remote_debug;
-#endif
-
-#define FREQ_TAG "HZ="
-#define GPIO_TAG "gpio="
-#define KMAC_TAG "kmac="
-#define MEM_TAG "mem="
-#define BOARD_TAG "board="
-#define IGNORE_CMDLINE_MEM 1
-#define DEBUG_DDR
-
-#define BOARD_RB532 "500"
-#define BOARD_RB532A "500r5"
-
-void parse_soft_settings(unsigned *ptr, unsigned size);
-void parse_hard_settings(unsigned *ptr, unsigned size);
-
-void __init prom_setup_cmdline(void);
-
-void __init prom_init(void)
-{
- DDR_t ddr = (DDR_t) DDR_VirtualAddress; /* define the pointer to the DDR registers */
- phys_t memsize = 0-ddr->ddrmask;
-
- /* this should be the very first message, even before serial is properly initialized */
- prom_setup_cmdline();
- setup_serial_port();
-
- mips_machgroup = MACH_GROUP_MIKROTIK;
- soft_reboot = read_c0_status() & SR_NMI;
- pm_power_off = NULL;
-
- /*
- * give all RAM to boot allocator,
- * except for the first 0x400 and the last 0x200 bytes
- */
- add_memory_region(ddr->ddrbase + 0x400, memsize - 0x600, BOOT_MEM_RAM);
-}
-
-void __init prom_free_prom_memory(void)
-{
- /* No prom memory to free */
-}
-
-static inline int match_tag(char *arg, const char *tag)
-{
- return (strncmp(arg, tag, strlen(tag)) == 0);
-}
-
-static inline unsigned long tag2ul(char *arg, const char *tag)
-{
- char *num = arg+strlen(tag);
- return simple_strtoul(num, 0, 10);
-}
-
-extern char _image_cmdline;
-void __init prom_setup_cmdline(void){
- char cmd_line[CL_SIZE];
- char *cp;
- int prom_argc;
- char **prom_argv, **prom_envp;
- int i;
-
- prom_argc = fw_arg0;
- prom_argv = (char **) fw_arg1;
- prom_envp = (char **) fw_arg2;
-
- cp=cmd_line;
- /* Note: it is common that parameters start at argv[1] and not argv[0],
- however, our elf loader starts at [0] */
- for(i=0;i<prom_argc;i++){
- if (match_tag(prom_argv[i], FREQ_TAG)) {
- idt_cpu_freq = tag2ul(prom_argv[i], FREQ_TAG);
- continue;
- }
-#ifdef IGNORE_CMDLINE_MEM
- /* parses out the "mem=xx" arg */
- if (match_tag(prom_argv[i], MEM_TAG)) {
- continue;
- }
-#endif
- if (i>0) *(cp++) = ' ';
- if (match_tag(prom_argv[i], BOARD_TAG)) {
- char *board = prom_argv[i] + strlen(BOARD_TAG);
- if (match_tag(board, BOARD_RB532A))
- mips_machtype = MACH_MIKROTIK_RB532A;
- else
- mips_machtype = MACH_MIKROTIK_RB532;
- }
-
- if (match_tag(prom_argv[i], GPIO_TAG)) {
- gpio_bootup_state = tag2ul(prom_argv[i], GPIO_TAG);
- }
- strcpy(cp,prom_argv[i]);
- cp+=strlen(prom_argv[i]);
- }
- *(cp++) = ' ';
- strcpy(cp,(&_image_cmdline + 8));
- cp += strlen(&_image_cmdline);
-
- i=strlen(arcs_cmdline);
- if (i>0){
- *(cp++) = ' ';
- strcpy(cp,arcs_cmdline);
- cp+=strlen(arcs_cmdline);
- }
- if (gpio_bootup_state&0x02)
- strcpy(cp,GPIO_INIT_NOBUTTON);
- else
- strcpy(cp,GPIO_INIT_BUTTON);
- cmd_line[CL_SIZE-1] = '\0';
-
- strcpy(arcs_cmdline,cmd_line);
-}
-
+++ /dev/null
-/**************************************************************************
- *
- * BRIEF MODULE DESCRIPTION
- * Serial port initialisation.
- *
- * Copyright 2004 IDT Inc. (rischelp@idt.com)
- *
- * 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 SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
- * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * 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.,
- * 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- *
- **************************************************************************
- * May 2004 rkt, neb
- *
- * Initial Release
- *
- *
- *
- **************************************************************************
- */
-
-
-#include <linux/autoconf.h>
-#include <linux/init.h>
-#include <linux/sched.h>
-#include <linux/pci.h>
-#include <linux/interrupt.h>
-#include <linux/tty.h>
-#include <linux/serial.h>
-#include <linux/serial_core.h>
-#include <linux/serial_8250.h>
-
-#include <asm/time.h>
-#include <asm/cpu.h>
-#include <asm/bootinfo.h>
-#include <asm/irq.h>
-#include <asm/serial.h>
-#include <asm/rc32434/rc32434.h>
-
-extern unsigned int idt_cpu_freq;
-
-static struct uart_port serial_req = {
- .type = PORT_16550A,
- .line = 0,
- .irq = RC32434_UART0_IRQ,
- //.flags = STD_COM_FLAGS,
- .iotype = UPIO_MEM,
- .membase = (char *) KSEG1ADDR(RC32434_UART0_BASE),
-// .fifosize = 14
- .regshift = 2
-};
-
-int __init setup_serial_port(void)
-{
- serial_req.uartclk = idt_cpu_freq;
-
- if (early_serial_setup(&serial_req))
- return -ENODEV;
-
- return(0);
-}
+++ /dev/null
-/*
- * setup.c - boot time setup code
- */
-
-#include <linux/init.h>
-#include <linux/mm.h>
-#include <linux/sched.h>
-#include <linux/irq.h>
-#include <linux/ioport.h>
-#include <linux/pm.h>
-#include <asm/bootinfo.h>
-#include <asm/mipsregs.h>
-#include <asm/pgtable.h>
-#include <asm/reboot.h>
-#include <asm/addrspace.h> /* for KSEG1ADDR() */
-#include <asm/time.h>
-#include <asm/io.h>
-#include <asm/rc32434/rc32434.h>
-#include <asm/rc32434/pci.h>
-
-#ifdef CONFIG_PCI
-extern void rc32434_time_init(void);
-extern int __init rc32434_pcibridge_init(void);
-#endif
-
-#define epldMask ((volatile unsigned char *)0xB900000d)
-
-static void rb_machine_restart(char *command)
-{
- /* just jump to the reset vector */
- * (volatile unsigned *) KSEG1ADDR(0x18008000) = 0x80000001;
- ((void (*)(void))KSEG1ADDR(0x1FC00000u))();
-}
-
-static void rb_machine_halt(void)
-{
- for(;;) continue;
-}
-
-#ifdef CONFIG_CPU_HAS_WB
-void (*__wbflush) (void);
-
-static void rb_write_buffer_flush(void)
-{
- __asm__ __volatile__
- ("sync\n\t" "nop\n\t" "loop: bc0f loop\n\t" "nop\n\t");
-}
-#endif
-
-void __init plat_mem_setup(void)
-{
- unsigned int pciCntlVal;
-
- board_time_init = rc32434_time_init;
-
-#ifdef CONFIG_CPU_HAS_WB
- __wbflush = rb_write_buffer_flush;
-#endif
- _machine_restart = rb_machine_restart;
- _machine_halt = rb_machine_halt;
- /*_machine_power_off = rb_machine_power_halt;*/
- pm_power_off = rb_machine_halt;
-
- set_io_port_base(KSEG1);
-
- pciCntlVal=rc32434_pci->pcic;
- pciCntlVal &= 0xFFFFFF7;
- rc32434_pci->pcic = pciCntlVal;
-
-#ifdef CONFIG_PCI
- /* Enable PCI interrupts in EPLD Mask register */
- *epldMask = 0x0;
- *(epldMask + 1) = 0x0;
-#endif
- write_c0_wired(0);
-}
-
-const char *get_system_type(void)
-{
- return "MIPS RB500";
-}
+++ /dev/null
-/*
-****************************************************************************
-* Carsten Langgaard, carstenl@mips.com
-* Copyright (C) 1999,2000 MIPS Technologies, Inc. All rights reserved.
-*
-***************************************************************************
-*
-* This program is free software; you can distribute it and/or modify it
-* under the terms of the GNU General Public License (Version 2) as
-* published by the Free Software Foundation.
-*
-* This program is distributed in the hope 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.
-*
-****************************************************************************
-*
-* Setting up the clock on the MIPS boards.
-*
-****************************************************************************
-* P. Sadik Oct 10, 2003
-*
-* Started change log.
-* mips_counter_frequency is now calculated at run time, based on idt_cpu_freq.
-* Code cleanup
-****************************************************************************
-*/
-
-#include <linux/autoconf.h>
-#include <linux/init.h>
-#include <linux/kernel_stat.h>
-#include <linux/sched.h>
-#include <linux/spinlock.h>
-#include <linux/mc146818rtc.h>
-#include <linux/irq.h>
-#include <linux/timex.h>
-
-#include <asm/irq_cpu.h>
-#include <asm/mipsregs.h>
-#include <asm/ptrace.h>
-#include <asm/debug.h>
-#include <asm/rc32434/rc32434.h>
-
-static unsigned long r4k_offset; /* Amount to incr compare reg each time */
-static unsigned long r4k_cur; /* What counter should be at next timer irq */
-extern unsigned int mips_hpt_frequency;
-extern unsigned int idt_cpu_freq;
-
-/*
- * Figure out the r4k offset, the amount to increment the compare
- * register for each time tick. There is no RTC available.
- *
- * The RC32434 counts at half the CPU *core* speed.
- */
-static unsigned long __init cal_r4koff(void)
-{
- mips_hpt_frequency = idt_cpu_freq * IDT_CLOCK_MULT / 2;
- return (mips_hpt_frequency / HZ);
-}
-
-
-void __init rc32434_time_init(void)
-{
- unsigned int est_freq, flags;
-
- local_irq_save(flags);
-
- printk("calculating r4koff... ");
- r4k_offset = cal_r4koff();
- printk("%08lx(%d)\n", r4k_offset, (int) r4k_offset);
-
- est_freq = 2*r4k_offset*HZ;
- est_freq += 5000; /* round */
- est_freq -= est_freq%10000;
- printk("CPU frequency %d.%02d MHz\n", est_freq/1000000,
- (est_freq%1000000)*100/1000000);
- local_irq_restore(flags);
-}
-
-void __init plat_timer_setup(struct irqaction *irq)
-{
- /* we are using the cpu counter for timer interrupts */
- setup_irq(MIPS_CPU_TIMER_IRQ, irq);
-
- /* to generate the first timer interrupt */
- r4k_cur = (read_c0_count() + r4k_offset);
- write_c0_compare(r4k_cur);
-}
-
+++ /dev/null
-## Makefile for the RB532 CF port
-
-obj-y += bdev.o ata.o
+++ /dev/null
-/* CF-mips driver
- This is a block driver for the direct (mmaped) interface to the CF-slot,
- found in Routerboard.com's RB532 board
- See SDK provided from routerboard.com.
-
- Module adapted By P.Christeas <p_christeas@yahoo.com>, 2005-6.
- Cleaned up and adapted to platform_device by Felix Fietkau <nbd@openwrt.org>
-
- This work is redistributed under the terms of the GNU General Public License.
-*/
-
-#include <linux/kernel.h> /* printk() */
-#include <linux/module.h> /* module to be loadable */
-#include <linux/delay.h>
-#include <linux/sched.h>
-#include <linux/pci.h>
-#include <linux/ioport.h> /* request_mem_region() */
-
-#include <asm/gpio.h>
-#include <asm/unaligned.h> /* ioremap() */
-#include <asm/io.h> /* ioremap() */
-#include <asm/rc32434/rb.h>
-
-#include "ata.h"
-
-#define REQUEST_MEM_REGION 0
-#define DEBUG 1
-
-#if DEBUG
-#define DEBUGP printk
-#else
-#define DEBUGP(format, args...)
-#endif
-
-#define SECS 1000000 /* unit for wait_not_busy() is 1us */
-
-unsigned cf_head = 0;
-unsigned cf_cyl = 0;
-unsigned cf_spt = 0;
-unsigned cf_sectors = 0;
-static unsigned cf_block_size = 1;
-static void *baddr = 0;
-
-#define DBUF32 ((volatile u32 *)((unsigned long)dev->baddr | ATA_DBUF_OFFSET))
-
-
-static void cf_do_tasklet(unsigned long dev_l);
-
-
-static inline void wareg(u8 val, unsigned reg, struct cf_mips_dev* dev)
-{
- writeb(val, dev->baddr + ATA_REG_OFFSET + reg);
-}
-
-static inline u8 rareg(unsigned reg, struct cf_mips_dev* dev)
-{
- return readb(dev->baddr + ATA_REG_OFFSET + reg);
-}
-
-static inline int cfrdy(struct cf_mips_dev *dev)
-{
- return gpio_get_value(dev->pin);
-}
-
-static inline void prepare_cf_irq(struct cf_mips_dev *dev)
-{
- rb500_gpio_set_int_level(1, dev->pin); /* interrupt on cf ready (not busy) */
- rb500_gpio_set_int_status(0, dev->pin); /* clear interrupt status */
-}
-
-static inline int cf_present(struct cf_mips_dev* dev)
-{
- /* TODO: read and configure CIS into memory mapped mode
- * TODO: parse CISTPL_CONFIG on CF+ cards to get base address (0x200)
- * TODO: maybe adjust power saving setting for Hitachi Microdrive
- */
- int i;
-
- /* setup CFRDY GPIO as input */
- rb500_gpio_set_func(dev->pin, 0);
- gpio_direction_input(dev->pin);
-
- for (i = 0; i < 0x10; ++i) {
- if (rareg(i,dev) != 0xff)
- return 1;
- }
- return 0;
-}
-
-static inline int is_busy(struct cf_mips_dev *dev)
-{
- return !cfrdy(dev);
-}
-
-static int wait_not_busy(int to_us, int wait_for_busy,struct cf_mips_dev *dev)
-{
- int us_passed = 0;
- if (wait_for_busy && !is_busy(dev)) {
- /* busy must appear within 400ns,
- * but it may dissapear before we see it
- * => must not wait for busy in a loop
- */
- ndelay(400);
- }
-
- do {
- if (us_passed)
- udelay(1); /* never reached in async mode */
- if (!is_busy(dev)) {
- if (us_passed > 1 * SECS) {
- printk(KERN_WARNING "cf-mips: not busy ok (after %dus)"
- ", status 0x%02x\n", us_passed, (unsigned) rareg(ATA_REG_ST,dev));
- }
- return CF_TRANS_OK;
- }
- if (us_passed == 1 * SECS) {
- printk(KERN_WARNING "cf-mips: wait not busy %dus..\n", to_us);
- }
- if (dev->async_mode) {
- dev->to_timer.expires = jiffies + (to_us * HZ / SECS);
- dev->irq_enable_time = jiffies;
- prepare_cf_irq(dev);
- if (is_busy(dev)) {
- add_timer(&dev->to_timer);
- enable_irq(dev->irq);
- return CF_TRANS_IN_PROGRESS;
- }
- continue;
- }
- ++us_passed;
- } while (us_passed < to_us);
-
- printk(KERN_ERR "cf-mips: wait not busy timeout (%dus)"
- ", status 0x%02x, state %d\n",
- to_us, (unsigned) rareg(ATA_REG_ST,dev), dev->tstate);
- return CF_TRANS_FAILED;
-}
-
-static irqreturn_t cf_irq_handler(int irq, void *dev_id)
-{
- /* While tasklet has not disabled irq, irq will be retried all the time
- * because of ILEVEL matching GPIO pin status => deadlock.
- * To avoid this, we change ILEVEL to 0.
- */
- struct cf_mips_dev *dev=dev_id;
-
- rb500_gpio_set_int_level(0, dev->pin);
- rb500_gpio_set_int_status(0, dev->pin);
-
- del_timer(&dev->to_timer);
- tasklet_schedule(&dev->tasklet);
- return IRQ_HANDLED;
-}
-
-static int do_reset(struct cf_mips_dev *dev)
-{
- printk(KERN_INFO "cf-mips: resetting..\n");
-
- wareg(ATA_REG_DC_SRST, ATA_REG_DC,dev);
- udelay(1); /* FIXME: how long should we wait here? */
- wareg(0, ATA_REG_DC,dev);
-
- return wait_not_busy(30 * SECS, 1,dev);
-}
-
-static int set_multiple(struct cf_mips_dev *dev)
-{
- if (dev->block_size <= 1)
- return CF_TRANS_OK;
-
- wareg(dev->block_size, ATA_REG_SC,dev);
- wareg(ATA_REG_DH_BASE | ATA_REG_DH_LBA, ATA_REG_DH,dev);
- wareg(ATA_CMD_SET_MULTIPLE, ATA_REG_CMD,dev);
-
- return wait_not_busy(10 * SECS, 1,dev);
-}
-
-static int set_cmd(struct cf_mips_dev *dev)
-{
- //DEBUGP(KERN_INFO "cf-mips: ata cmd 0x%02x\n", dev->tcmd);
- // sector_count should be <=24 bits..
- BUG_ON(dev->tsect_start>=0x10000000);
- // This way, it addresses 2^24 * 512 = 128G
-
- if (dev->tsector_count) {
- wareg(dev->tsector_count & 0xff, ATA_REG_SC,dev);
- wareg(dev->tsect_start & 0xff, ATA_REG_SN,dev);
- wareg((dev->tsect_start >> 8) & 0xff, ATA_REG_CL,dev);
- wareg((dev->tsect_start >> 16) & 0xff, ATA_REG_CH,dev);
- }
- wareg(((dev->tsect_start >> 24) & 0x0f) | ATA_REG_DH_BASE | ATA_REG_DH_LBA,
- ATA_REG_DH,dev); /* select drive on all commands */
- wareg(dev->tcmd, ATA_REG_CMD,dev);
- return wait_not_busy(10 * SECS, 1,dev);
-}
-
-static int do_trans(struct cf_mips_dev *dev)
-{
- int res;
- unsigned st;
- int transfered;
-
- //printk("do_trans: %d sectors left\n",dev->tsectors_left);
- while (dev->tsectors_left) {
- transfered = 0;
-
- st = rareg(ATA_REG_ST,dev);
- if (!(st & ATA_REG_ST_DRQ)) {
- printk(KERN_ERR "cf-mips: do_trans without DRQ (status 0x%x)!\n", st);
- if (st & ATA_REG_ST_ERR) {
- int errId = rareg(ATA_REG_ERR,dev);
- printk(KERN_ERR "cf-mips: %s error, status 0x%x, errid 0x%x\n",
- (dev->tread ? "read" : "write"), st, errId);
- }
- return CF_TRANS_FAILED;
- }
- do { /* Fill/read the buffer one block */
- u32 *qbuf, *qend;
- qbuf = (u32 *)dev->tbuf;
- qend = qbuf + CF_SECT_SIZE / sizeof(u32);
- if (dev->tread) {
- while (qbuf!=qend)
- put_unaligned(*DBUF32,qbuf++);
- //*(qbuf++) = *DBUF32;
- }
- else {
- while(qbuf!=qend)
- *DBUF32 = get_unaligned(qbuf++);
- }
-
- dev->tsectors_left--;
- dev->tbuf += CF_SECT_SIZE;
- dev->tbuf_size -= CF_SECT_SIZE;
- transfered++;
- } while (transfered != dev->block_size && dev->tsectors_left > 0);
-
- res = wait_not_busy(10 * SECS, 1,dev);
- if (res != CF_TRANS_OK)
- return res;
- };
-
- st = rareg(ATA_REG_ST,dev);
- if (st & (ATA_REG_ST_DRQ | ATA_REG_ST_DWF | ATA_REG_ST_ERR)) {
- if (st & ATA_REG_ST_DRQ) {
- printk(KERN_ERR "cf-mips: DRQ after all %d sectors are %s"
- ", status 0x%x\n", dev->tsector_count, (dev->tread ? "read" : "written"), st);
- } else if (st & ATA_REG_ST_DWF) {
- printk(KERN_ERR "cf-mips: write fault, status 0x%x\n", st);
- } else {
- int errId = rareg(ATA_REG_ERR,dev);
- printk(KERN_ERR "cf-mips: %s error, status 0x%x, errid 0x%x\n",
- (dev->tread ? "read" : "write"), st, errId);
- }
- return CF_TRANS_FAILED;
- }
- return CF_TRANS_OK;
-}
-
-static int cf_do_state(struct cf_mips_dev *dev)
-{
- int res;
- switch (dev->tstate) { /* fall through everywhere */
- case TS_IDLE:
- dev->tstate = TS_READY;
- if (is_busy(dev)) {
- dev->tstate = TS_AFTER_RESET;
- res = do_reset(dev);
- if (res != CF_TRANS_OK)
- break;
- }
- case TS_AFTER_RESET:
- if (dev->tstate == TS_AFTER_RESET) {
- dev->tstate = TS_READY;
- res = set_multiple(dev);
- if (res != CF_TRANS_OK)
- break;
- }
- case TS_READY:
- dev->tstate = TS_CMD;
- res = set_cmd(dev);
- if (res != CF_TRANS_OK)
- break;;
- case TS_CMD:
- dev->tstate = TS_TRANS;
- case TS_TRANS:
- res = do_trans(dev);
- break;
- default:
- printk(KERN_ERR "cf-mips: BUG: unknown tstate %d\n", dev->tstate);
- return CF_TRANS_FAILED;
- }
- if (res != CF_TRANS_IN_PROGRESS)
- dev->tstate = TS_IDLE;
- return res;
-}
-
-static void cf_do_tasklet(unsigned long dev_l)
-{
- struct cf_mips_dev* dev=(struct cf_mips_dev*) dev_l;
- int res;
-
- disable_irq(dev->irq);
-
- if (dev->tstate == TS_IDLE)
- return; /* can happen when irq is first registered */
-
-#if 0
- DEBUGP(KERN_WARNING "cf-mips: not busy ok (tasklet) status 0x%02x\n",
- (unsigned) rareg(ATA_REG_ST,dev));
-#endif
-
- res = cf_do_state(dev);
- if (res == CF_TRANS_IN_PROGRESS)
- return;
- cf_async_trans_done(dev,res);
-}
-
-static void cf_async_timeout(unsigned long dev_l)
-{
- struct cf_mips_dev* dev=(struct cf_mips_dev*) dev_l;
- disable_irq(dev->irq);
- /* Perhaps send abort to the device? */
- printk(KERN_ERR "cf-mips: wait not busy timeout (%lus)"
- ", status 0x%02x, state %d\n",
- jiffies - dev->irq_enable_time, (unsigned) rareg(ATA_REG_ST,dev), dev->tstate);
- dev->tstate = TS_IDLE;
- cf_async_trans_done(dev,CF_TRANS_FAILED);
-}
-
-int cf_do_transfer(struct cf_mips_dev* dev,sector_t sector, unsigned long nsect,
- char* buffer, int is_write)
-{
- BUG_ON(dev->tstate!=TS_IDLE);
- if (nsect > ATA_MAX_SECT_PER_CMD) {
- printk(KERN_WARNING "cf-mips: sector count %lu out of range\n",nsect);
- return CF_TRANS_FAILED;
- }
- if (sector + nsect > dev->sectors) {
- printk(KERN_WARNING "cf-mips: sector %lu out of range\n",sector);
- return CF_TRANS_FAILED;
- }
- dev->tbuf = buffer;
- dev->tbuf_size = nsect*512;
- dev->tsect_start = sector;
- dev->tsector_count = nsect;
- dev->tsectors_left = dev->tsector_count;
- dev->tread = (is_write)?0:1;
-
- dev->tcmd = (dev->block_size == 1 ?
- (is_write ? ATA_CMD_WRITE_SECTORS : ATA_CMD_READ_SECTORS) :
- (is_write ? ATA_CMD_WRITE_MULTIPLE : ATA_CMD_READ_MULTIPLE));
-
- return cf_do_state(dev);
-}
-
-static int do_identify(struct cf_mips_dev *dev)
-{
- u16 sbuf[CF_SECT_SIZE >> 1];
- int res;
- char tstr[17]; //serial
- char tmp;
- int i;
- BUG_ON(dev->tstate!=TS_IDLE);
- dev->tbuf = (char *) sbuf;
- dev->tbuf_size = CF_SECT_SIZE;
- dev->tsect_start = 0;
- dev->tsector_count = 0;
- dev->tsectors_left = 1;
- dev->tread = 1;
- dev->tcmd = ATA_CMD_IDENTIFY_DRIVE;
-
- DEBUGP(KERN_INFO "cf-mips: identify drive..\n");
- res = cf_do_state(dev);
- if (res == CF_TRANS_IN_PROGRESS) {
- printk(KERN_ERR "cf-mips: BUG: async identify cmd\n");
- return CF_TRANS_FAILED;
- }
- if (res != CF_TRANS_OK)
- return 0;
-
- dev->head = sbuf[3];
- dev->cyl = sbuf[1];
- dev->spt = sbuf[6];
- dev->sectors = ((unsigned long) sbuf[7] << 16) | sbuf[8];
- dev->dtype=sbuf[0];
- memcpy(tstr, &sbuf[12], 16);
- tstr[16] = '\0';
-
- /* Byte-swap the serial number */
- for (i = 0; i<8; i++) {
- tmp = tstr[i * 2];
- tstr[i * 2] = tstr[i * 2 +1];
- tstr[i * 2 + 1] = tmp;
- }
-
- printk(KERN_INFO "cf-mips: %s detected, C/H/S=%d/%d/%d sectors=%u (%uMB) Serial=%s\n",
- (sbuf[0] == 0x848A ? "CF card" : "ATA drive"), dev->cyl, dev->head,
- dev->spt, dev->sectors, dev->sectors >> 11, tstr);
- return 1;
-}
-
-static void init_multiple(struct cf_mips_dev * dev)
-{
- int res;
- DEBUGP(KERN_INFO "cf-mips: detecting block size\n");
-
- dev->block_size = 128; /* max block size = 128 sectors (64KB) */
- do {
- wareg(dev->block_size, ATA_REG_SC,dev);
- wareg(ATA_REG_DH_BASE | ATA_REG_DH_LBA, ATA_REG_DH,dev);
- wareg(ATA_CMD_SET_MULTIPLE, ATA_REG_CMD,dev);
-
- res = wait_not_busy(10 * SECS, 1,dev);
- if (res != CF_TRANS_OK) {
- printk(KERN_ERR "cf-mips: failed to detect block size: busy!\n");
- dev->block_size = 1;
- return;
- }
- if ((rareg(ATA_REG_ST,dev) & ATA_REG_ST_ERR) == 0)
- break;
- dev->block_size /= 2;
- } while (dev->block_size > 1);
-
- printk(KERN_INFO "cf-mips: multiple sectors = %d\n", dev->block_size);
-}
-
-int cf_init(struct cf_mips_dev *dev)
-{
- tasklet_init(&dev->tasklet,cf_do_tasklet,(unsigned long)dev);
- dev->baddr = ioremap_nocache((unsigned long)dev->base, CFDEV_BUF_SIZE);
- if (!dev->baddr) {
- printk(KERN_ERR "cf-mips: cf_init: ioremap for (%lx,%x) failed\n",
- (unsigned long) dev->base, CFDEV_BUF_SIZE);
- return -EBUSY;
- }
-
- if (!cf_present(dev)) {
- printk(KERN_WARNING "cf-mips: cf card not present\n");
- iounmap(dev->baddr);
- return -ENODEV;
- }
-
- if (do_reset(dev) != CF_TRANS_OK) {
- printk(KERN_ERR "cf-mips: cf reset failed\n");
- iounmap(dev->baddr);
- return -EBUSY;
- }
-
- if (!do_identify(dev)) {
- printk(KERN_ERR "cf-mips: cf identify failed\n");
- iounmap(dev->baddr);
- return -EBUSY;
- }
-
-/* set_apm_level(ATA_APM_WITH_STANDBY); */
- init_multiple(dev);
-
- init_timer(&dev->to_timer);
- dev->to_timer.function = cf_async_timeout;
- dev->to_timer.data = (unsigned long)dev;
-
- prepare_cf_irq(dev);
- if (request_irq(dev->irq, cf_irq_handler, 0, "CF Mips", dev)) {
- printk(KERN_ERR "cf-mips: failed to get irq\n");
- iounmap(dev->baddr);
- return -EBUSY;
- }
- /* Disable below would be odd, because request will enable, and the tasklet
- will disable it itself */
- //disable_irq(dev->irq);
-
- dev->async_mode = 1;
-
- return 0;
-}
-
-void cf_cleanup(struct cf_mips_dev *dev)
-{
- iounmap(dev->baddr);
- free_irq(dev->irq, NULL);
-#if REQUEST_MEM_REGION
- release_mem_region((unsigned long)dev->base, CFDEV_BUF_SIZE);
-#endif
-}
-
-
-/*eof*/
+++ /dev/null
-/* CF-mips driver
- This is a block driver for the direct (mmaped) interface to the CF-slot,
- found in Routerboard.com's RB532 board
- See SDK provided from routerboard.com.
-
- Module adapted By P.Christeas <p_christeas@yahoo.com>, 2005-6.
- Cleaned up and adapted to platform_device by Felix Fietkau <nbd@openwrt.org>
-
- This work is redistributed under the terms of the GNU General Public License.
-*/
-
-#ifndef __CFMIPS_ATA_H__
-#define __CFMIPS_ATA_H__
-
-#include <linux/interrupt.h>
-
-#define CFG_DC_DEV1 (void*)0xb8010010
-#define CFG_DC_DEVBASE 0x0
-#define CFG_DC_DEVMASK 0x4
-#define CFG_DC_DEVC 0x8
-#define CFG_DC_DEVTC 0xC
-
-#define CFDEV_BUF_SIZE 0x1000
-#define ATA_CIS_OFFSET 0x200
-#define ATA_REG_OFFSET 0x800
-#define ATA_DBUF_OFFSET 0xC00
-
-#define ATA_REG_FEAT 0x1
-#define ATA_REG_SC 0x2
-#define ATA_REG_SN 0x3
-#define ATA_REG_CL 0x4
-#define ATA_REG_CH 0x5
-#define ATA_REG_DH 0x6
-#define ATA_REG_DH_BASE 0xa0
-#define ATA_REG_DH_LBA 0x40
-#define ATA_REG_DH_DRV 0x10
-#define ATA_REG_CMD 0x7
-#define ATA_REG_ST 0x7
-#define ATA_REG_ST_BUSY 0x80
-#define ATA_REG_ST_RDY 0x40
-#define ATA_REG_ST_DWF 0x20
-#define ATA_REG_ST_DSC 0x10
-#define ATA_REG_ST_DRQ 0x08
-#define ATA_REG_ST_CORR 0x04
-#define ATA_REG_ST_ERR 0x01
-#define ATA_REG_ERR 0xd
-#define ATA_REG_DC 0xe
-#define ATA_REG_DC_IEN 0x02
-#define ATA_REG_DC_SRST 0x04
-
-#define ATA_CMD_READ_SECTORS 0x20
-#define ATA_CMD_WRITE_SECTORS 0x30
-#define ATA_CMD_EXEC_DRIVE_DIAG 0x90
-#define ATA_CMD_READ_MULTIPLE 0xC4
-#define ATA_CMD_WRITE_MULTIPLE 0xC5
-#define ATA_CMD_SET_MULTIPLE 0xC6
-#define ATA_CMD_IDENTIFY_DRIVE 0xEC
-#define ATA_CMD_SET_FEATURES 0xEF
-
-#define ATA_FEATURE_ENABLE_APM 0x05
-#define ATA_FEATURE_DISABLE_APM 0x85
-#define ATA_APM_DISABLED 0x00
-#define ATA_APM_MIN_POWER 0x01
-#define ATA_APM_WITH_STANDBY 0x7f
-#define ATA_APM_WITHOUT_STANDBY 0x80
-#define ATA_APM_MAX_PERFORMANCE 0xfe
-
-#define CF_SECT_SIZE 0x200
-/* That is the ratio CF_SECT_SIZE/512 (the kernel sector size) */
-#define CF_KERNEL_MUL 1
-#define ATA_MAX_SECT_PER_CMD 0x100
-
-#define CF_TRANS_FAILED 0
-#define CF_TRANS_OK 1
-#define CF_TRANS_IN_PROGRESS 2
-
-
-enum trans_state {
- TS_IDLE = 0,
- TS_AFTER_RESET,
- TS_READY,
- TS_CMD,
- TS_TRANS
-};
-
-//
-// #if DEBUG
-// static unsigned long busy_time;
-// #endif
-
-/** Struct to hold the cfdev
-Actually, all the data here only has one instance. However, for
-reasons of programming conformity, it is passed around as a pointer
-*/
-struct cf_mips_dev {
- void *base; /* base address for I/O */
- void *baddr; /* remapped address */
-
- int pin; /* gpio pin */
- int irq; /* gpio irq */
-
- unsigned head;
- unsigned cyl;
- unsigned spt;
- unsigned sectors;
-
- unsigned short block_size;
- unsigned dtype ; // ATA or CF
- struct request_queue *queue;
- struct gendisk *gd;
-
- /* Transaction state */
- enum trans_state tstate;
- char *tbuf;
- unsigned long tbuf_size;
- sector_t tsect_start;
- unsigned tsector_count;
- unsigned tsectors_left;
- int tread;
- unsigned tcmd;
- int async_mode;
- unsigned long irq_enable_time;
-
- struct request *active_req; /* A request is being carried out. Is that different from tstate? */
- int users;
- struct timer_list to_timer;
- struct tasklet_struct tasklet;
-
- /** This lock ensures that the requests to this device are all done
- atomically. Transfers can run in parallel, requests are all queued
- one-by-one */
- spinlock_t lock;
-};
-
-int cf_do_transfer(struct cf_mips_dev* dev,sector_t sector, unsigned long nsect,
- char* buffer, int is_write);
-int cf_init(struct cf_mips_dev* dev);
-void cf_cleanup(struct cf_mips_dev* dev);
-
-void cf_async_trans_done(struct cf_mips_dev* dev, int result);
-// void *cf_get_next_buf(unsigned long *buf_size);
-
-#endif
+++ /dev/null
-/* CF-mips driver
- This is a block driver for the direct (mmaped) interface to the CF-slot,
- found in Routerboard.com's RB532 board
- See SDK provided from routerboard.com.
-
- Module adapted By P.Christeas <p_christeas@yahoo.com>, 2005-6.
- Cleaned up and adapted to platform_device by Felix Fietkau <nbd@openwrt.org>
-
- This work is redistributed under the terms of the GNU General Public License.
-*/
-
-#include <linux/kernel.h>
-#include <linux/module.h>
-#include <linux/init.h>
-#include <linux/time.h>
-#include <linux/wait.h>
-#include <linux/fs.h>
-#include <linux/genhd.h>
-#include <linux/blkdev.h>
-#include <linux/blkpg.h>
-#include <linux/hdreg.h>
-#include <linux/platform_device.h>
-
-#include <asm/uaccess.h>
-#include <asm/io.h>
-#include <asm/gpio.h>
-
-#include <asm/rc32434/rb.h>
-
-#ifdef DEBUG
-#define DEBUGP printk
-#define DLEVEL 1
-#else
-#define DEBUGP(format, args...)
-#define DLEVEL 0
-#endif
-
-#define CF_MIPS_MAJOR 13
-#define MAJOR_NR CF_MIPS_MAJOR
-#define CF_MAX_PART 16 /* max 15 partitions */
-
-#include "ata.h"
-
-//extern struct block_device_operations cf_bdops;
-
-// static struct hd_struct cf_parts[CF_MAX_PART];
-// static int cf_part_sizes[CF_MAX_PART];
-// static int cf_hsect_sizes[CF_MAX_PART];
-// static int cf_max_sectors[CF_MAX_PART];
-// static int cf_blksize_sizes[CF_MAX_PART];
-
-// static spinlock_t lock = SPIN_LOCK_UNLOCKED;
-
-// volatile int cf_busy = 0;
-
-static struct request *active_req = NULL;
-
-static int cf_open (struct inode *, struct file *);
-static int cf_release (struct inode *, struct file *);
-static int cf_ioctl (struct inode *, struct file *, unsigned, unsigned long);
-
-static void cf_request(request_queue_t * q);
-static int cf_transfer(const struct request *req);
-
-/*long (*unlocked_ioctl) (struct file *, unsigned, unsigned long);
-long (*compat_ioctl) (struct file *, unsigned, unsigned long);*/
-// int (*direct_access) (struct block_device *, sector_t, unsigned long *);
-// int (*media_changed) (struct gendisk *);
-// int (*revalidate_disk) (struct gendisk *);
-
-static struct block_device_operations cf_bdops = {
- .owner = THIS_MODULE,
- .open = cf_open,
- .release = cf_release,
- .ioctl = cf_ioctl,
- .media_changed = NULL,
- .unlocked_ioctl = NULL,
- .revalidate_disk = NULL,
- .compat_ioctl = NULL,
- .direct_access = NULL
-};
-
-
-int cf_mips_probe(struct platform_device *pdev)
-{
- struct gendisk* cf_gendisk=NULL;
- struct cf_device *cdev = (struct cf_device *) pdev->dev.platform_data;
- struct cf_mips_dev *dev;
- struct resource *r;
- int reg_result;
-
- reg_result = register_blkdev(MAJOR_NR, "cf-mips");
- if (reg_result < 0) {
- printk(KERN_WARNING "cf-mips: can't get major %d\n", MAJOR_NR);
- return reg_result;
- }
-
- dev = (struct cf_mips_dev *)kmalloc(sizeof(struct cf_mips_dev),GFP_KERNEL);
- if (!dev)
- goto out_err;
- memset(dev, 0, sizeof(struct cf_mips_dev));
- cdev->dev = dev;
-
- dev->pin = cdev->gpio_pin;
- dev->irq = platform_get_irq_byname(pdev, "cf_irq");
- r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "cf_membase");
- dev->base = (void *) r->start;
-
- if (cf_init(dev)) goto out_err;
- printk("init done");
-
- spin_lock_init(&dev->lock);
- dev->queue = blk_init_queue(cf_request,&dev->lock);
- if (!dev->queue){
- printk(KERN_ERR "cf-mips: no mem for queue\n");
- goto out_err;
- }
- blk_queue_max_sectors(dev->queue,ATA_MAX_SECT_PER_CMD);
-
- /* For memory devices, it is always better to avoid crossing segments
- inside the same request. */
-/* if (dev->dtype==0x848A){
- printk(KERN_INFO "Setting boundary for cf to 0x%x",(dev->block_size*512)-1);
- blk_queue_segment_boundary(dev->queue, (dev->block_size*512)-1);
- }*/
-
- dev->gd = alloc_disk(CF_MAX_PART);
- cf_gendisk = dev->gd;
- cdev->gd = dev->gd;
- if (!cf_gendisk) goto out_err; /* Last of these goto's */
-
- cf_gendisk->major = MAJOR_NR;
- cf_gendisk->first_minor = 0;
- cf_gendisk->queue=dev->queue;
- BUG_ON(cf_gendisk->minors != CF_MAX_PART);
- strcpy(cf_gendisk->disk_name,"cfa");
- cf_gendisk->fops = &cf_bdops;
- cf_gendisk->flags = 0 ; /* is not yet GENHD_FL_REMOVABLE */
- cf_gendisk->private_data=dev;
-
- set_capacity(cf_gendisk,dev->sectors * CF_KERNEL_MUL);
-
- /* Let the disk go live */
- add_disk(cf_gendisk);
-#if 0
- result = cf_init();
-
- /* default cfg for all partitions */
- memset(cf_parts, 0, sizeof (cf_parts[0]) * CF_MAX_PART);
- memset(cf_part_sizes, 0, sizeof (cf_part_sizes[0]) * CF_MAX_PART);
- for (i = 0; i < CF_MAX_PART; ++i) {
- cf_hsect_sizes[i] = CF_SECT_SIZE;
- cf_max_sectors[i] = ATA_MAX_SECT_PER_CMD;
- cf_blksize_sizes[i] = BLOCK_SIZE;
- }
-
- /* setup info for whole disk (partition 0) */
- cf_part_sizes[0] = cf_sectors / 2;
- cf_parts[0].nr_sects = cf_sectors;
-
- blk_size[MAJOR_NR] = cf_part_sizes;
- blksize_size[MAJOR_NR] = cf_blksize_sizes;
- max_sectors[MAJOR_NR] = cf_max_sectors;
- hardsect_size[MAJOR_NR] = cf_hsect_sizes;
- read_ahead[MAJOR_NR] = 8; /* (4kB) */
-
- blk_init_queue(BLK_DEFAULT_QUEUE(MAJOR_NR), DEVICE_REQUEST);
-
- add_gendisk(&cf_gendisk);
-#endif
-// printk(KERN_INFO "cf-mips partition check: \n");
-// register_disk(cf_gendisk, MKDEV(MAJOR_NR, 0), CF_MAX_PART,
-// &cf_bdops, dev->sectors);
- return 0;
-
-out_err:
- if (dev->queue){
- blk_cleanup_queue(dev->queue);
- }
- if (reg_result) {
- unregister_blkdev(MAJOR_NR, "cf-mips");
- return reg_result;
- }
- if (dev){
- cf_cleanup(dev);
- kfree(dev);
- }
- return 1;
-}
-
-static int
-cf_mips_remove(struct platform_device *pdev)
-{
- struct cf_device *cdev = (struct cf_device *) pdev->dev.platform_data;
- struct cf_mips_dev *dev = (struct cf_mips_dev *) cdev->dev;
-
- unregister_blkdev(MAJOR_NR, "cf-mips");
- blk_cleanup_queue(dev->queue);
-
- del_gendisk(dev->gd);
- cf_cleanup(dev);
- return 0;
-}
-
-
-static struct platform_driver cf_driver = {
- .driver.name = "rb500-cf",
- .probe = cf_mips_probe,
- .remove = cf_mips_remove,
-};
-
-static int __init cf_mips_init(void)
-{
- printk(KERN_INFO "cf-mips module loaded\n");
- return platform_driver_register(&cf_driver);
-}
-
-static void cf_mips_cleanup(void)
-{
- platform_driver_unregister(&cf_driver);
- printk(KERN_INFO "cf-mips module removed\n");
-}
-
-module_init(cf_mips_init);
-module_exit(cf_mips_cleanup);
-
-MODULE_LICENSE("GPL");
-MODULE_ALIAS_BLOCKDEV_MAJOR(CF_MIPS_MAJOR);
-
-
-static int cf_open(struct inode *inode, struct file *filp)
-{
- struct cf_mips_dev *dev=inode->i_bdev->bd_disk->private_data;
- int minor = MINOR(inode->i_rdev);
-
- if (minor >= CF_MAX_PART)
- return -ENODEV;
- //DEBUGP(KERN_INFO "cf-mips module opened, minor %d\n", minor);
- spin_lock(&dev->lock);
- dev->users++;
- spin_unlock(&dev->lock);
- filp->private_data=dev;
-
- /* dirty workaround to set CFRDY GPIO as an input when some other
- program sets it as an output */
- gpio_set_value(dev->pin, 0);
- return 0; /* success */
-}
-
-static int cf_release(struct inode *inode, struct file *filp)
-{
- int minor = MINOR(inode->i_rdev);
- struct cf_mips_dev *dev=inode->i_bdev->bd_disk->private_data;
- spin_lock(&dev->lock);
- dev->users--;
- spin_unlock(&dev->lock);
- return 0;
-}
-
-static int cf_ioctl(struct inode *inode, struct file *filp,
- unsigned int cmd, unsigned long arg)
-{
- unsigned minor = MINOR(inode->i_rdev);
- struct cf_mips_dev *dev=inode->i_bdev->bd_disk->private_data;
-
- DEBUGP(KERN_INFO "cf_ioctl cmd %u\n", cmd);
- switch (cmd) {
- case BLKRRPART: /* re-read partition table */
- if (!capable(CAP_SYS_ADMIN))
- return -EACCES;
- printk(KERN_INFO "cf-mips partition check: \n");
- register_disk(dev->gd);
- return 0;
-
- case HDIO_GETGEO:
- {
- struct hd_geometry geo;
- geo.cylinders = dev->cyl;
- geo.heads = dev->head;
- geo.sectors = dev->spt;
- geo.start = (*dev->gd->part)[minor].start_sect;
- if (copy_to_user((void *) arg, &geo, sizeof (geo)))
- return -EFAULT;
- }
- return 0;
- }
-
- return -EINVAL; /* unknown command */
-}
-
-static void cf_request(request_queue_t * q)
-{
- struct cf_mips_dev* dev;
-
- struct request * req;
- int status;
-
- /* We could have q->queuedata = dev , but haven't yet. */
- if (active_req)
- return;
-
- while ((req=elv_next_request(q))!=NULL){
- dev=req->rq_disk->private_data;
- status=cf_transfer(req);
- if (status==CF_TRANS_IN_PROGRESS){
- active_req=req;
- return;
- }
- end_request(req,status);
- }
-}
-
-static int cf_transfer(const struct request *req)
-{
- struct cf_mips_dev* dev=req->rq_disk->private_data;
-
- if (!blk_fs_request(req)){
- if (printk_ratelimit())
- printk(KERN_WARNING "cf-mips: skipping non-fs request 0x%x\n",req->cmd[0]);
- return CF_TRANS_FAILED;
- }
-
- return cf_do_transfer(dev,req->sector,req->current_nr_sectors,req->buffer,rq_data_dir(req));
-}
-
-void cf_async_trans_done(struct cf_mips_dev * dev,int result)
-{
- struct request *req;
-
- spin_lock(&dev->lock);
- req=active_req;
- active_req=NULL;
- end_request(req,result);
- spin_unlock(&dev->lock);
-
- spin_lock(&dev->lock);
- cf_request(dev->queue);
- spin_unlock(&dev->lock);
-}
-
+++ /dev/null
-/*
- * RC32434_WDT 0.01: IDT Interprise 79RC32434 watchdog driver
- * Copyright (c) Ondrej Zajicek <santiago@crfreenet.org>, 2006
- *
- * based on
- *
- * SoftDog 0.05: A Software Watchdog Device
- *
- * (c) Copyright 1996 Alan Cox <alan@redhat.com>, All Rights Reserved.
- *
- * 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.
- *
- */
-
-#include <linux/module.h>
-#include <linux/types.h>
-#include <linux/kernel.h>
-#include <linux/fs.h>
-#include <linux/mm.h>
-#include <linux/miscdevice.h>
-#include <linux/watchdog.h>
-#include <linux/reboot.h>
-#include <linux/smp_lock.h>
-#include <linux/init.h>
-#include <asm/bootinfo.h>
-#include <asm/time.h>
-#include <asm/uaccess.h>
-#include <asm/rc32434/integ.h>
-
-#define DEFAULT_TIMEOUT 15 /* (secs) Default is 15 seconds */
-#define MAX_TIMEOUT 20
-/*
- * (secs) Max is 20 seconds
- * (max frequency of counter is ~200 MHz, counter is 32-bit unsigned int)
- */
-
-#define NAME "rc32434_wdt"
-#define VERSION "0.1"
-
-static INTEG_t rc_wdt = (INTEG_t) INTEG_VirtualAddress;
-
-static int expect_close = 0;
-static int access = 0;
-static int timeout = 0;
-
-static int nowayout = WATCHDOG_NOWAYOUT;
-module_param(nowayout, int, 0);
-MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
-MODULE_LICENSE("GPL");
-
-
-static inline void start_wdt(void)
-{
- rc_wdt -> wtcount = 0;
- rc_wdt -> errcs |= ERRCS_wre_m;
- rc_wdt -> wtc |= WTC_en_m;
-}
-
-static inline void stop_wdt(void)
-{
- rc_wdt -> wtc &= ~WTC_en_m;
- rc_wdt -> errcs &= ~ERRCS_wre_m;
-}
-
-static inline void set_wdt(int new_timeout)
-{
- u32 cmp = new_timeout * mips_hpt_frequency;
- u32 state;
-
- timeout = new_timeout;
- /*
- * store and disable WTC
- */
- state = rc_wdt -> wtc & WTC_en_m;
- rc_wdt -> wtc &= ~WTC_en_m;
-
- rc_wdt -> wtcount = 0;
- rc_wdt -> wtcompare = cmp;
-
- /*
- * restore WTC
- */
- rc_wdt -> wtc |= state;
-}
-
-static inline void update_wdt(void)
-{
- rc_wdt -> wtcount = 0;
-}
-
-/*
- * Allow only one person to hold it open
- */
-
-static int wdt_open(struct inode *inode, struct file *file)
-{
- if (access)
- return -EBUSY;
- if (nowayout) {
- __module_get(THIS_MODULE);
- }
- /*
- * Activate timer
- */
- start_wdt();
- printk(KERN_INFO NAME ": enabling watchdog timer\n");
- access = 1;
- return 0;
-}
-
-static int wdt_release(struct inode *inode, struct file *file)
-{
- /*
- * Shut off the timer.
- * Lock it in if it's a module and we set nowayout
- */
- if (expect_close && nowayout == 0) {
- stop_wdt ();
- printk(KERN_INFO NAME ": disabling watchdog timer\n");
- module_put(THIS_MODULE);
- } else {
- printk (KERN_CRIT NAME ": device closed unexpectedly. WDT will not stop!\n");
- }
- access = 0;
- return 0;
-}
-
-static ssize_t wdt_write(struct file *file, const char *data, size_t len, loff_t *ppos)
-{
- /*
- * Refresh the timer.
- */
- if (len) {
- if (!nowayout) {
- size_t i;
-
- /* In case it was set long ago */
- expect_close = 0;
-
- for (i = 0; i != len; i++) {
- char c;
- if (get_user(c, data + i))
- return -EFAULT;
- if (c == 'V')
- expect_close = 1;
- }
- }
- update_wdt ();
- return len;
- }
- return 0;
-}
-
-static int wdt_ioctl(struct inode *inode, struct file *file,
- unsigned int cmd, unsigned long arg)
-{
- int new_timeout;
- static struct watchdog_info ident = {
- .options = WDIOF_SETTIMEOUT |
- WDIOF_KEEPALIVEPING |
- WDIOF_MAGICCLOSE,
- .firmware_version = 0,
- .identity = "RC32434_WDT Watchdog",
- };
- switch (cmd) {
- default:
- return -ENOTTY;
- case WDIOC_GETSUPPORT:
- if(copy_to_user((struct watchdog_info *)arg, &ident, sizeof(ident)))
- return -EFAULT;
- return 0;
- case WDIOC_GETSTATUS:
- case WDIOC_GETBOOTSTATUS:
- return put_user(0,(int *)arg);
- case WDIOC_KEEPALIVE:
- update_wdt();
- return 0;
- case WDIOC_SETTIMEOUT:
- if (get_user(new_timeout, (int *)arg))
- return -EFAULT;
- if (new_timeout < 1)
- return -EINVAL;
- if (new_timeout > MAX_TIMEOUT)
- return -EINVAL;
- set_wdt(new_timeout);
- /* Fall */
- case WDIOC_GETTIMEOUT:
- return put_user(timeout, (int *)arg);
- }
-}
-
-static struct file_operations wdt_fops = {
- owner: THIS_MODULE,
- llseek: no_llseek,
- write: wdt_write,
- ioctl: wdt_ioctl,
- open: wdt_open,
- release: wdt_release,
-};
-
-static struct miscdevice wdt_miscdev = {
- minor: WATCHDOG_MINOR,
- name: "watchdog",
- fops: &wdt_fops,
-};
-
-static char banner[] __initdata = KERN_INFO NAME ": Watchdog Timer version " VERSION ", timer margin: %d sec\n";
-
-static int __init watchdog_init(void)
-{
- int ret;
-
- /*
- * There should be check for RC32434 SoC
- */
- if (mips_machgroup != MACH_GROUP_MIKROTIK) return -1;
-
- ret = misc_register(&wdt_miscdev);
-
- if (ret)
- return ret;
-
- stop_wdt();
- set_wdt(DEFAULT_TIMEOUT);
-
- printk(banner, timeout);
-
- return 0;
-}
-
-static void __exit watchdog_exit(void)
-{
- misc_deregister(&wdt_miscdev);
-}
-
-module_init(watchdog_init);
-module_exit(watchdog_exit);
+++ /dev/null
-/*
- * linux/drivers/leds/leds-rb500.c
- *
- * Copyright (C) 2006
- * Twente Institute for Wireless and Mobile Communications BV
- *
- * 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 (see file GPLv2).
- *
- * Author: Tjalling Hattink <tjalling.hattink@ti-wmc.nl>
- */
-
-#include <linux/kernel.h>
-#include <linux/init.h>
-#include <linux/platform_device.h>
-#include <linux/leds.h>
-#include <asm/rc32434/rb.h>
-
-static void rb500led_amber_set(struct led_classdev *led_cdev, enum led_brightness value)
-{
- if (value)
- changeLatchU5(LO_ULED, 0);
- else
- changeLatchU5(0, LO_ULED);
-}
-
-static struct led_classdev rb500_amber_led = {
- .name = "rb500led:amber",
- .default_trigger = "ide-disk",
- .brightness_set = rb500led_amber_set,
-};
-
-static int rb500led_probe(struct platform_device *pdev)
-{
- int ret;
-
- changeLatchU5(0, LO_ULED);
-
- ret = led_classdev_register(&pdev->dev, &rb500_amber_led);
-
- return ret;
-}
-
-static int rb500led_remove(struct platform_device *pdev)
-{
- led_classdev_unregister(&rb500_amber_led);
-
- return 0;
-}
-
-static struct platform_driver rb500led_driver = {
- .probe = rb500led_probe,
- .remove = rb500led_remove,
- .driver = {
- .name = "rb500-led",
- },
-};
-
-static int __init rb500led_init(void)
-{
- return platform_driver_register(&rb500led_driver);
-}
-
-static void __exit rb500led_exit(void)
-{
- platform_driver_unregister(&rb500led_driver);
-}
-
-module_init(rb500led_init);
-module_exit(rb500led_exit);
-
-MODULE_AUTHOR("tjalling.hattink@ti-wmc.nl");
-MODULE_DESCRIPTION("Mikrotik RB500 LED driver");
-MODULE_LICENSE("GPL");
+++ /dev/null
-/**************************************************************************
- *
- * BRIEF MODULE DESCRIPTION
- * Driver for the IDT RC32434 on-chip ethernet controller.
- *
- * Copyright 2004 IDT Inc. (rischelp@idt.com)
- * Copyright 2006 Felix Fietkau <nbd@openwrt.org>
- *
- * 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 SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
- * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * 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.,
- * 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- *
- **************************************************************************
- * May 2004 rkt, neb
- *
- * Based on the driver developed by B. Maruthanayakam, H. Kou and others.
- *
- * Aug 2004 Sadik
- *
- * Added NAPI
- *
- **************************************************************************
- */
-
-#include <linux/autoconf.h>
-#include <linux/module.h>
-#include <linux/kernel.h>
-#include <linux/moduleparam.h>
-#include <linux/sched.h>
-#include <linux/ctype.h>
-#include <linux/types.h>
-#include <linux/fcntl.h>
-#include <linux/interrupt.h>
-#include <linux/ptrace.h>
-#include <linux/init.h>
-#include <linux/ioport.h>
-#include <linux/proc_fs.h>
-#include <linux/in.h>
-#include <linux/slab.h>
-#include <linux/string.h>
-#include <linux/delay.h>
-#include <linux/netdevice.h>
-#include <linux/etherdevice.h>
-#include <linux/skbuff.h>
-#include <linux/errno.h>
-#include <linux/platform_device.h>
-#include <asm/bootinfo.h>
-#include <asm/system.h>
-#include <asm/bitops.h>
-#include <asm/pgtable.h>
-#include <asm/segment.h>
-#include <asm/io.h>
-#include <asm/dma.h>
-
-#include <asm/rc32434/rb.h>
-#include "rc32434_eth.h"
-
-#define DRIVER_VERSION "(mar2904)"
-
-#define DRIVER_NAME "rc32434 Ethernet driver. " DRIVER_VERSION
-
-#define STATION_ADDRESS_HIGH(dev) (((dev)->dev_addr[0] << 8) | \
- ((dev)->dev_addr[1]))
-#define STATION_ADDRESS_LOW(dev) (((dev)->dev_addr[2] << 24) | \
- ((dev)->dev_addr[3] << 16) | \
- ((dev)->dev_addr[4] << 8) | \
- ((dev)->dev_addr[5]))
-
-#define MII_CLOCK 1250000 /* no more than 2.5MHz */
-#define CONFIG_IDT_USE_NAPI 1
-
-
-static inline void rc32434_abort_tx(struct net_device *dev)
-{
- struct rc32434_local *lp = (struct rc32434_local *)dev->priv;
- rc32434_abort_dma(dev, lp->tx_dma_regs);
-
-}
-
-static inline void rc32434_abort_rx(struct net_device *dev)
-{
- struct rc32434_local *lp = (struct rc32434_local *)dev->priv;
- rc32434_abort_dma(dev, lp->rx_dma_regs);
-
-}
-
-static inline void rc32434_start_tx(struct rc32434_local *lp, volatile DMAD_t td)
-{
- rc32434_start_dma(lp->tx_dma_regs, CPHYSADDR(td));
-}
-
-static inline void rc32434_start_rx(struct rc32434_local *lp, volatile DMAD_t rd)
-{
- rc32434_start_dma(lp->rx_dma_regs, CPHYSADDR(rd));
-}
-
-static inline void rc32434_chain_tx(struct rc32434_local *lp, volatile DMAD_t td)
-{
- rc32434_chain_dma(lp->tx_dma_regs, CPHYSADDR(td));
-}
-
-static inline void rc32434_chain_rx(struct rc32434_local *lp, volatile DMAD_t rd)
-{
- rc32434_chain_dma(lp->rx_dma_regs, CPHYSADDR(rd));
-}
-
-#ifdef RC32434_PROC_DEBUG
-static int rc32434_read_proc(char *buf, char **start, off_t fpos,
- int length, int *eof, void *data)
-{
- struct net_device *dev = (struct net_device *)data;
- struct rc32434_local *lp = (struct rc32434_local *)dev->priv;
- int len = 0;
-
- /* print out header */
- len += sprintf(buf + len, "\n\tKorina Ethernet Debug\n\n");
- len += sprintf (buf + len,
- "DMA halt count = %10d, DMA run count = %10d\n",
- lp->dma_halt_cnt, lp->dma_run_cnt);
-
- if (fpos >= len) {
- *start = buf;
- *eof = 1;
- return 0;
- }
- *start = buf + fpos;
-
- if ((len -= fpos) > length)
- return length;
- *eof = 1;
-
- return len;
-
-}
-#endif
-
-
-/*
- * Restart the RC32434 ethernet controller.
- */
-static int rc32434_restart(struct net_device *dev)
-{
- struct rc32434_local *lp = (struct rc32434_local *)dev->priv;
-
- /*
- * Disable interrupts
- */
- disable_irq(lp->rx_irq);
- disable_irq(lp->tx_irq);
-#ifdef RC32434_REVISION
- disable_irq(lp->ovr_irq);
-#endif
- disable_irq(lp->und_irq);
-
- /* Mask F E bit in Tx DMA */
- __raw_writel(__raw_readl(&lp->tx_dma_regs->dmasm) | DMASM_f_m | DMASM_e_m, &lp->tx_dma_regs->dmasm);
- /* Mask D H E bit in Rx DMA */
- __raw_writel(__raw_readl(&lp->rx_dma_regs->dmasm) | DMASM_d_m | DMASM_h_m | DMASM_e_m, &lp->rx_dma_regs->dmasm);
-
- rc32434_init(dev);
- rc32434_multicast_list(dev);
-
- enable_irq(lp->und_irq);
-#ifdef RC32434_REVISION
- enable_irq(lp->ovr_irq);
-#endif
- enable_irq(lp->tx_irq);
- enable_irq(lp->rx_irq);
-
- return 0;
-}
-
-static int rc32434_probe(struct platform_device *pdev)
-{
- struct korina_device *bif = (struct korina_device *) pdev->dev.platform_data;
- struct rc32434_local *lp = NULL;
- struct net_device *dev = NULL;
- struct resource *r;
- int i, retval,err;
-
- dev = alloc_etherdev(sizeof(struct rc32434_local));
- if(!dev) {
- ERR("Korina_eth: alloc_etherdev failed\n");
- return -1;
- }
-
- platform_set_drvdata(pdev, dev);
- SET_MODULE_OWNER(dev);
- bif->dev = dev;
-
- memcpy(dev->dev_addr, bif->mac, 6);
-
- /* Initialize the device structure. */
- if (dev->priv == NULL) {
- lp = (struct rc32434_local *)kmalloc(sizeof(*lp), GFP_KERNEL);
- memset(lp, 0, sizeof(struct rc32434_local));
- }
- else {
- lp = (struct rc32434_local *)dev->priv;
- }
-
- lp->rx_irq = platform_get_irq_byname(pdev, "korina_rx");
- lp->tx_irq = platform_get_irq_byname(pdev, "korina_tx");
- lp->ovr_irq = platform_get_irq_byname(pdev, "korina_ovr");
- lp->und_irq = platform_get_irq_byname(pdev, "korina_und");
-
- r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "korina_regs");
- dev->base_addr = r->start;
- lp->eth_regs = ioremap_nocache(r->start, r->end - r->start);
- if (!lp->eth_regs) {
- ERR("Can't remap eth registers\n");
- retval = -ENXIO;
- goto probe_err_out;
- }
-
- r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "korina_dma_rx");
- lp->rx_dma_regs = ioremap_nocache(r->start, r->end - r->start);
- if (!lp->rx_dma_regs) {
- ERR("Can't remap Rx DMA registers\n");
- retval = -ENXIO;
- goto probe_err_out;
- }
-
- r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "korina_dma_tx");
- lp->tx_dma_regs = ioremap_nocache(r->start, r->end - r->start);
- if (!lp->tx_dma_regs) {
- ERR("Can't remap Tx DMA registers\n");
- retval = -ENXIO;
- goto probe_err_out;
- }
-
-#ifdef RC32434_PROC_DEBUG
- lp->ps = create_proc_read_entry (bif->name, 0, proc_net,
- rc32434_read_proc, dev);
-#endif
-
- lp->td_ring = (DMAD_t)kmalloc(TD_RING_SIZE + RD_RING_SIZE, GFP_KERNEL);
- if (!lp->td_ring) {
- ERR("Can't allocate descriptors\n");
- retval = -ENOMEM;
- goto probe_err_out;
- }
-
- dma_cache_inv((unsigned long)(lp->td_ring), TD_RING_SIZE + RD_RING_SIZE);
-
- /* now convert TD_RING pointer to KSEG1 */
- lp->td_ring = (DMAD_t )KSEG1ADDR(lp->td_ring);
- lp->rd_ring = &lp->td_ring[RC32434_NUM_TDS];
-
-
- spin_lock_init(&lp->lock);
-
- /* just use the rx dma irq */
- dev->irq = lp->rx_irq;
-
- dev->priv = lp;
-
- dev->open = rc32434_open;
- dev->stop = rc32434_close;
- dev->hard_start_xmit = rc32434_send_packet;
- dev->get_stats = rc32434_get_stats;
- dev->set_multicast_list = &rc32434_multicast_list;
- dev->tx_timeout = rc32434_tx_timeout;
- dev->watchdog_timeo = RC32434_TX_TIMEOUT;
-
-#ifdef CONFIG_IDT_USE_NAPI
- dev->poll = rc32434_poll;
- dev->weight = 64;
- printk("Using NAPI with weight %d\n",dev->weight);
-#else
- lp->rx_tasklet = kmalloc(sizeof(struct tasklet_struct), GFP_KERNEL);
- tasklet_init(lp->rx_tasklet, rc32434_rx_tasklet, (unsigned long)dev);
-#endif
- lp->tx_tasklet = kmalloc(sizeof(struct tasklet_struct), GFP_KERNEL);
- tasklet_init(lp->tx_tasklet, rc32434_tx_tasklet, (unsigned long)dev);
-
- if ((err = register_netdev(dev))) {
- printk(KERN_ERR "rc32434 ethernet. Cannot register net device %d\n", err);
- free_netdev(dev);
- retval = -EINVAL;
- goto probe_err_out;
- }
-
- INFO("Rx IRQ %d, Tx IRQ %d, ", lp->rx_irq, lp->tx_irq);
- for (i = 0; i < 6; i++) {
- printk("%2.2x", dev->dev_addr[i]);
- if (i<5)
- printk(":");
- }
- printk("\n");
-
- return 0;
-
- probe_err_out:
- rc32434_cleanup_module();
- ERR(" failed. Returns %d\n", retval);
- return retval;
-
-}
-
-static int rc32434_remove(struct platform_device *pdev)
-{
- struct korina_device *bif = (struct korina_device *) pdev->dev.platform_data;
-
- if (bif->dev != NULL) {
- struct rc32434_local *lp = (struct rc32434_local *)bif->dev->priv;
- if (lp != NULL) {
- if (lp->eth_regs)
- iounmap((void*)lp->eth_regs);
- if (lp->rx_dma_regs)
- iounmap((void*)lp->rx_dma_regs);
- if (lp->tx_dma_regs)
- iounmap((void*)lp->tx_dma_regs);
- if (lp->td_ring)
- kfree((void*)KSEG0ADDR(lp->td_ring));
-
-#ifdef RC32434_PROC_DEBUG
- if (lp->ps) {
- remove_proc_entry(bif->name, proc_net);
- }
-#endif
- kfree(lp);
- }
-
- platform_set_drvdata(pdev, NULL);
- unregister_netdev(bif->dev);
- free_netdev(bif->dev);
- kfree(bif->dev);
- }
- return 0;
-}
-
-
-static int rc32434_open(struct net_device *dev)
-{
- struct rc32434_local *lp = (struct rc32434_local *)dev->priv;
-
- /* Initialize */
- if (rc32434_init(dev)) {
- ERR("Error: cannot open the Ethernet device\n");
- return -EAGAIN;
- }
-
- /* Install the interrupt handler that handles the Done Finished Ovr and Und Events */
- if (request_irq(lp->rx_irq, &rc32434_rx_dma_interrupt,
- SA_SHIRQ | SA_INTERRUPT,
- "Korina ethernet Rx", dev)) {
- ERR(": unable to get Rx DMA IRQ %d\n",
- lp->rx_irq);
- return -EAGAIN;
- }
- if (request_irq(lp->tx_irq, &rc32434_tx_dma_interrupt,
- SA_SHIRQ | SA_INTERRUPT,
- "Korina ethernet Tx", dev)) {
- ERR(": unable to get Tx DMA IRQ %d\n",
- lp->tx_irq);
- free_irq(lp->rx_irq, dev);
- return -EAGAIN;
- }
-
-#ifdef RC32434_REVISION
- /* Install handler for overrun error. */
- if (request_irq(lp->ovr_irq, &rc32434_ovr_interrupt,
- SA_SHIRQ | SA_INTERRUPT,
- "Ethernet Overflow", dev)) {
- ERR(": unable to get OVR IRQ %d\n",
- lp->ovr_irq);
- free_irq(lp->rx_irq, dev);
- free_irq(lp->tx_irq, dev);
- return -EAGAIN;
- }
-#endif
-
- /* Install handler for underflow error. */
- if (request_irq(lp->und_irq, &rc32434_und_interrupt,
- SA_SHIRQ | SA_INTERRUPT,
- "Ethernet Underflow", dev)) {
- ERR(": unable to get UND IRQ %d\n",
- lp->und_irq);
- free_irq(lp->rx_irq, dev);
- free_irq(lp->tx_irq, dev);
-#ifdef RC32434_REVISION
- free_irq(lp->ovr_irq, dev);
-#endif
- return -EAGAIN;
- }
-
-
- return 0;
-}
-
-
-
-
-static int rc32434_close(struct net_device *dev)
-{
- struct rc32434_local *lp = (struct rc32434_local *)dev->priv;
- u32 tmp;
-
- /* Disable interrupts */
- disable_irq(lp->rx_irq);
- disable_irq(lp->tx_irq);
-#ifdef RC32434_REVISION
- disable_irq(lp->ovr_irq);
-#endif
- disable_irq(lp->und_irq);
-
- tmp = __raw_readl(&lp->tx_dma_regs->dmasm);
- tmp = tmp | DMASM_f_m | DMASM_e_m;
- __raw_writel(tmp, &lp->tx_dma_regs->dmasm);
-
- tmp = __raw_readl(&lp->rx_dma_regs->dmasm);
- tmp = tmp | DMASM_d_m | DMASM_h_m | DMASM_e_m;
- __raw_writel(tmp, &lp->rx_dma_regs->dmasm);
-
- free_irq(lp->rx_irq, dev);
- free_irq(lp->tx_irq, dev);
-#ifdef RC32434_REVISION
- free_irq(lp->ovr_irq, dev);
-#endif
- free_irq(lp->und_irq, dev);
- return 0;
-}
-
-
-/* transmit packet */
-static int rc32434_send_packet(struct sk_buff *skb, struct net_device *dev)
-{
- struct rc32434_local *lp = (struct rc32434_local *)dev->priv;
- unsigned long flags;
- u32 length;
- DMAD_t td;
-
-
- spin_lock_irqsave(&lp->lock, flags);
-
- td = &lp->td_ring[lp->tx_chain_tail];
-
- /* stop queue when full, drop pkts if queue already full */
- if(lp->tx_count >= (RC32434_NUM_TDS - 2)) {
- lp->tx_full = 1;
-
- if(lp->tx_count == (RC32434_NUM_TDS - 2)) {
- netif_stop_queue(dev);
- }
- else {
- lp->stats.tx_dropped++;
- dev_kfree_skb_any(skb);
- spin_unlock_irqrestore(&lp->lock, flags);
- return 1;
- }
- }
-
- lp->tx_count ++;
-
- lp->tx_skb[lp->tx_chain_tail] = skb;
-
- length = skb->len;
- dma_cache_wback((u32)skb->data, skb->len);
-
- /* Setup the transmit descriptor. */
- dma_cache_inv((u32) td, sizeof(*td));
- td->ca = CPHYSADDR(skb->data);
-
- if(__raw_readl(&(lp->tx_dma_regs->dmandptr)) == 0) {
- if( lp->tx_chain_status == empty ) {
- td->control = DMA_COUNT(length) |DMAD_cof_m |DMAD_iof_m; /* Update tail */
- lp->tx_chain_tail = (lp->tx_chain_tail + 1) & RC32434_TDS_MASK; /* Move tail */
- __raw_writel(CPHYSADDR(&lp->td_ring[lp->tx_chain_head]), &(lp->tx_dma_regs->dmandptr)); /* Write to NDPTR */
- lp->tx_chain_head = lp->tx_chain_tail; /* Move head to tail */
- }
- else {
- td->control = DMA_COUNT(length) |DMAD_cof_m|DMAD_iof_m; /* Update tail */
- lp->td_ring[(lp->tx_chain_tail-1)& RC32434_TDS_MASK].control &= ~(DMAD_cof_m); /* Link to prev */
- lp->td_ring[(lp->tx_chain_tail-1)& RC32434_TDS_MASK].link = CPHYSADDR(td); /* Link to prev */
- lp->tx_chain_tail = (lp->tx_chain_tail + 1) & RC32434_TDS_MASK; /* Move tail */
- __raw_writel(CPHYSADDR(&lp->td_ring[lp->tx_chain_head]), &(lp->tx_dma_regs->dmandptr)); /* Write to NDPTR */
- lp->tx_chain_head = lp->tx_chain_tail; /* Move head to tail */
- lp->tx_chain_status = empty;
- }
- }
- else {
- if( lp->tx_chain_status == empty ) {
- td->control = DMA_COUNT(length) |DMAD_cof_m |DMAD_iof_m; /* Update tail */
- lp->tx_chain_tail = (lp->tx_chain_tail + 1) & RC32434_TDS_MASK; /* Move tail */
- lp->tx_chain_status = filled;
- }
- else {
- td->control = DMA_COUNT(length) |DMAD_cof_m |DMAD_iof_m; /* Update tail */
- lp->td_ring[(lp->tx_chain_tail-1)& RC32434_TDS_MASK].control &= ~(DMAD_cof_m); /* Link to prev */
- lp->td_ring[(lp->tx_chain_tail-1)& RC32434_TDS_MASK].link = CPHYSADDR(td); /* Link to prev */
- lp->tx_chain_tail = (lp->tx_chain_tail + 1) & RC32434_TDS_MASK; /* Move tail */
- }
- }
- dma_cache_wback((u32) td, sizeof(*td));
-
- dev->trans_start = jiffies;
-
- spin_unlock_irqrestore(&lp->lock, flags);
-
- return 0;
-}
-
-
-/* Ethernet MII-PHY Handler */
-static void rc32434_mii_handler(unsigned long data)
-{
- struct net_device *dev = (struct net_device *)data;
- struct rc32434_local *lp = (struct rc32434_local *)dev->priv;
- unsigned long flags;
- unsigned long duplex_status;
- int port_addr = (lp->rx_irq == 0x2c? 1:0) << 8;
-
- spin_lock_irqsave(&lp->lock, flags);
-
- /* Two ports are using the same MII, the difference is the PHY address */
- __raw_writel(0, &rc32434_eth0_regs->miimcfg);
- __raw_writel(0, &rc32434_eth0_regs->miimcmd);
- __raw_writel(port_addr |0x05, &rc32434_eth0_regs->miimaddr);
- __raw_writel(MIIMCMD_scn_m, &rc32434_eth0_regs->miimcmd);
- while(__raw_readl(&rc32434_eth0_regs->miimind) & MIIMIND_nv_m);
-
- ERR("irq:%x port_addr:%x RDD:%x\n",
- lp->rx_irq, port_addr, __raw_readl(&rc32434_eth0_regs->miimrdd));
- duplex_status = (__raw_readl(&rc32434_eth0_regs->miimrdd) & 0x140)? ETHMAC2_fd_m: 0;
- if(duplex_status != lp->duplex_mode) {
- ERR("The MII-PHY is Auto-negotiated to %s-Duplex mode for Eth-%x\n", duplex_status? "Full":"Half", lp->rx_irq == 0x2c? 1:0);
- lp->duplex_mode = duplex_status;
- rc32434_restart(dev);
- }
-
- lp->mii_phy_timer.expires = jiffies + 10 * HZ;
- add_timer(&lp->mii_phy_timer);
-
- spin_unlock_irqrestore(&lp->lock, flags);
-
-}
-
-#ifdef RC32434_REVISION
-/* Ethernet Rx Overflow interrupt */
-static irqreturn_t
-rc32434_ovr_interrupt(int irq, void *dev_id)
-{
- struct net_device *dev = (struct net_device *)dev_id;
- struct rc32434_local *lp;
- unsigned int ovr;
- irqreturn_t retval = IRQ_NONE;
-
- ASSERT(dev != NULL);
-
- lp = (struct rc32434_local *)dev->priv;
- spin_lock(&lp->lock);
- ovr = __raw_readl(&lp->eth_regs->ethintfc);
-
- if(ovr & ETHINTFC_ovr_m) {
- netif_stop_queue(dev);
-
- /* clear OVR bit */
- __raw_writel((ovr & ~ETHINTFC_ovr_m), &lp->eth_regs->ethintfc);
-
- /* Restart interface */
- rc32434_restart(dev);
- retval = IRQ_HANDLED;
- }
- spin_unlock(&lp->lock);
-
- return retval;
-}
-
-#endif
-
-
-/* Ethernet Tx Underflow interrupt */
-static irqreturn_t
-rc32434_und_interrupt(int irq, void *dev_id)
-{
- struct net_device *dev = (struct net_device *)dev_id;
- struct rc32434_local *lp;
- unsigned int und;
- irqreturn_t retval = IRQ_NONE;
-
- ASSERT(dev != NULL);
-
- lp = (struct rc32434_local *)dev->priv;
-
- spin_lock(&lp->lock);
-
- und = __raw_readl(&lp->eth_regs->ethintfc);
-
- if(und & ETHINTFC_und_m) {
- netif_stop_queue(dev);
-
- __raw_writel((und & ~ETHINTFC_und_m), &lp->eth_regs->ethintfc);
-
- /* Restart interface */
- rc32434_restart(dev);
- retval = IRQ_HANDLED;
- }
-
- spin_unlock(&lp->lock);
-
- return retval;
-}
-
-
-/* Ethernet Rx DMA interrupt */
-static irqreturn_t
-rc32434_rx_dma_interrupt(int irq, void *dev_id)
-{
- struct net_device *dev = (struct net_device *)dev_id;
- struct rc32434_local* lp;
- volatile u32 dmas,dmasm;
- irqreturn_t retval;
-
- ASSERT(dev != NULL);
-
- lp = (struct rc32434_local *)dev->priv;
-
- spin_lock(&lp->lock);
- dmas = __raw_readl(&lp->rx_dma_regs->dmas);
- if(dmas & (DMAS_d_m|DMAS_h_m|DMAS_e_m)) {
- /* Mask D H E bit in Rx DMA */
- dmasm = __raw_readl(&lp->rx_dma_regs->dmasm);
- __raw_writel(dmasm | (DMASM_d_m | DMASM_h_m | DMASM_e_m), &lp->rx_dma_regs->dmasm);
-#ifdef CONFIG_IDT_USE_NAPI
- if(netif_rx_schedule_prep(dev))
- __netif_rx_schedule(dev);
-#else
- tasklet_hi_schedule(lp->rx_tasklet);
-#endif
-
- if (dmas & DMAS_e_m)
- ERR(": DMA error\n");
-
- retval = IRQ_HANDLED;
- }
- else
- retval = IRQ_NONE;
-
- spin_unlock(&lp->lock);
- return retval;
-}
-
-#ifdef CONFIG_IDT_USE_NAPI
-static int rc32434_poll(struct net_device *rx_data_dev, int *budget)
-#else
-static void rc32434_rx_tasklet(unsigned long rx_data_dev)
-#endif
-{
- struct net_device *dev = (struct net_device *)rx_data_dev;
- struct rc32434_local* lp = netdev_priv(dev);
- volatile DMAD_t rd = &lp->rd_ring[lp->rx_next_done];
- struct sk_buff *skb, *skb_new;
- u8* pkt_buf;
- u32 devcs, count, pkt_len, pktuncrc_len;
- volatile u32 dmas;
-#ifdef CONFIG_IDT_USE_NAPI
- u32 received = 0;
- int rx_work_limit = min(*budget,dev->quota);
-#else
- unsigned long flags;
- spin_lock_irqsave(&lp->lock, flags);
-#endif
-
- dma_cache_inv((u32)rd, sizeof(*rd));
- while ( (count = RC32434_RBSIZE - (u32)DMA_COUNT(rd->control)) != 0) {
-#ifdef CONFIG_IDT_USE_NAPI
- if(--rx_work_limit <0)
- {
- break;
- }
-#endif
- /* init the var. used for the later operations within the while loop */
- skb_new = NULL;
- devcs = rd->devcs;
- pkt_len = RCVPKT_LENGTH(devcs);
- skb = lp->rx_skb[lp->rx_next_done];
-
- if (count < 64) {
- lp->stats.rx_errors++;
- lp->stats.rx_dropped++;
- }
- else if ((devcs & ( ETHRX_ld_m)) != ETHRX_ld_m) {
- /* check that this is a whole packet */
- /* WARNING: DMA_FD bit incorrectly set in Rc32434 (errata ref #077) */
- lp->stats.rx_errors++;
- lp->stats.rx_dropped++;
- }
- else if ( (devcs & ETHRX_rok_m) ) {
-
- {
- /* must be the (first and) last descriptor then */
- pkt_buf = (u8*)lp->rx_skb[lp->rx_next_done]->data;
-
- pktuncrc_len = pkt_len - 4;
- /* invalidate the cache */
- dma_cache_inv((unsigned long)pkt_buf, pktuncrc_len);
-
- /* Malloc up new buffer. */
- skb_new = dev_alloc_skb(RC32434_RBSIZE + 2);
-
- if (skb_new != NULL){
- /* Make room */
- skb_put(skb, pktuncrc_len);
-
- skb->protocol = eth_type_trans(skb, dev);
-
- /* pass the packet to upper layers */
-#ifdef CONFIG_IDT_USE_NAPI
- netif_receive_skb(skb);
-#else
- netif_rx(skb);
-#endif
-
- dev->last_rx = jiffies;
- lp->stats.rx_packets++;
- lp->stats.rx_bytes += pktuncrc_len;
-
- if (IS_RCV_MP(devcs))
- lp->stats.multicast++;
-
- /* 16 bit align */
- skb_reserve(skb_new, 2);
-
- skb_new->dev = dev;
- lp->rx_skb[lp->rx_next_done] = skb_new;
- }
- else {
- ERR("no memory, dropping rx packet.\n");
- lp->stats.rx_errors++;
- lp->stats.rx_dropped++;
- }
- }
-
- }
- else {
- /* This should only happen if we enable accepting broken packets */
- lp->stats.rx_errors++;
- lp->stats.rx_dropped++;
-
- /* add statistics counters */
- if (IS_RCV_CRC_ERR(devcs)) {
- DBG(2, "RX CRC error\n");
- lp->stats.rx_crc_errors++;
- }
- else if (IS_RCV_LOR_ERR(devcs)) {
- DBG(2, "RX LOR error\n");
- lp->stats.rx_length_errors++;
- }
- else if (IS_RCV_LE_ERR(devcs)) {
- DBG(2, "RX LE error\n");
- lp->stats.rx_length_errors++;
- }
- else if (IS_RCV_OVR_ERR(devcs)) {
- lp->stats.rx_over_errors++;
- }
- else if (IS_RCV_CV_ERR(devcs)) {
- /* code violation */
- DBG(2, "RX CV error\n");
- lp->stats.rx_frame_errors++;
- }
- else if (IS_RCV_CES_ERR(devcs)) {
- DBG(2, "RX Preamble error\n");
- }
- }
-
- rd->devcs = 0;
-
- /* restore descriptor's curr_addr */
- if(skb_new)
- rd->ca = CPHYSADDR(skb_new->data);
- else
- rd->ca = CPHYSADDR(skb->data);
-
- rd->control = DMA_COUNT(RC32434_RBSIZE) |DMAD_cod_m |DMAD_iod_m;
- lp->rd_ring[(lp->rx_next_done-1)& RC32434_RDS_MASK].control &= ~(DMAD_cod_m);
-
- lp->rx_next_done = (lp->rx_next_done + 1) & RC32434_RDS_MASK;
- dma_cache_wback((u32)rd, sizeof(*rd));
- rd = &lp->rd_ring[lp->rx_next_done];
- __raw_writel( ~DMAS_d_m, &lp->rx_dma_regs->dmas);
- }
-#ifdef CONFIG_IDT_USE_NAPI
- dev->quota -= received;
- *budget =- received;
- if(rx_work_limit < 0)
- goto not_done;
-#endif
-
- dmas = __raw_readl(&lp->rx_dma_regs->dmas);
-
- if(dmas & DMAS_h_m) {
- __raw_writel( ~(DMAS_h_m | DMAS_e_m), &lp->rx_dma_regs->dmas);
-#ifdef RC32434_PROC_DEBUG
- lp->dma_halt_cnt++;
-#endif
- rd->devcs = 0;
- skb = lp->rx_skb[lp->rx_next_done];
- rd->ca = CPHYSADDR(skb->data);
- dma_cache_wback((u32)rd, sizeof(*rd));
- rc32434_chain_rx(lp,rd);
- }
-
-#ifdef CONFIG_IDT_USE_NAPI
- netif_rx_complete(dev);
-#endif
- /* Enable D H E bit in Rx DMA */
- __raw_writel(__raw_readl(&lp->rx_dma_regs->dmasm) & ~(DMASM_d_m | DMASM_h_m |DMASM_e_m), &lp->rx_dma_regs->dmasm);
-#ifdef CONFIG_IDT_USE_NAPI
- return 0;
- not_done:
- return 1;
-#else
- spin_unlock_irqrestore(&lp->lock, flags);
- return;
-#endif
-
-
-}
-
-
-
-/* Ethernet Tx DMA interrupt */
-static irqreturn_t
-rc32434_tx_dma_interrupt(int irq, void *dev_id)
-{
- struct net_device *dev = (struct net_device *)dev_id;
- struct rc32434_local *lp;
- volatile u32 dmas,dmasm;
- irqreturn_t retval;
-
- ASSERT(dev != NULL);
-
- lp = (struct rc32434_local *)dev->priv;
-
- spin_lock(&lp->lock);
-
- dmas = __raw_readl(&lp->tx_dma_regs->dmas);
-
- if (dmas & (DMAS_f_m | DMAS_e_m)) {
- dmasm = __raw_readl(&lp->tx_dma_regs->dmasm);
- /* Mask F E bit in Tx DMA */
- __raw_writel(dmasm | (DMASM_f_m | DMASM_e_m), &lp->tx_dma_regs->dmasm);
-
- tasklet_hi_schedule(lp->tx_tasklet);
-
- if(lp->tx_chain_status == filled && (__raw_readl(&(lp->tx_dma_regs->dmandptr)) == 0)) {
- __raw_writel(CPHYSADDR(&lp->td_ring[lp->tx_chain_head]), &(lp->tx_dma_regs->dmandptr));
- lp->tx_chain_status = empty;
- lp->tx_chain_head = lp->tx_chain_tail;
- dev->trans_start = jiffies;
- }
-
- if (dmas & DMAS_e_m)
- ERR(": DMA error\n");
-
- retval = IRQ_HANDLED;
- }
- else
- retval = IRQ_NONE;
-
- spin_unlock(&lp->lock);
-
- return retval;
-}
-
-
-static void rc32434_tx_tasklet(unsigned long tx_data_dev)
-{
- struct net_device *dev = (struct net_device *)tx_data_dev;
- struct rc32434_local* lp = (struct rc32434_local *)dev->priv;
- volatile DMAD_t td = &lp->td_ring[lp->tx_next_done];
- u32 devcs;
- unsigned long flags;
- volatile u32 dmas;
-
- spin_lock_irqsave(&lp->lock, flags);
-
- /* process all desc that are done */
- while(IS_DMA_FINISHED(td->control)) {
- if(lp->tx_full == 1) {
- netif_wake_queue(dev);
- lp->tx_full = 0;
- }
-
- devcs = lp->td_ring[lp->tx_next_done].devcs;
- if ((devcs & (ETHTX_fd_m | ETHTX_ld_m)) != (ETHTX_fd_m | ETHTX_ld_m)) {
- lp->stats.tx_errors++;
- lp->stats.tx_dropped++;
-
- /* should never happen */
- DBG(1, __FUNCTION__ ": split tx ignored\n");
- }
- else if (IS_TX_TOK(devcs)) {
- lp->stats.tx_packets++;
- lp->stats.tx_bytes+=lp->tx_skb[lp->tx_next_done]->len;
- }
- else {
- lp->stats.tx_errors++;
- lp->stats.tx_dropped++;
-
- /* underflow */
- if (IS_TX_UND_ERR(devcs))
- lp->stats.tx_fifo_errors++;
-
- /* oversized frame */
- if (IS_TX_OF_ERR(devcs))
- lp->stats.tx_aborted_errors++;
-
- /* excessive deferrals */
- if (IS_TX_ED_ERR(devcs))
- lp->stats.tx_carrier_errors++;
-
- /* collisions: medium busy */
- if (IS_TX_EC_ERR(devcs))
- lp->stats.collisions++;
-
- /* late collision */
- if (IS_TX_LC_ERR(devcs))
- lp->stats.tx_window_errors++;
-
- }
-
- /* We must always free the original skb */
- if (lp->tx_skb[lp->tx_next_done] != NULL) {
- dev_kfree_skb_any(lp->tx_skb[lp->tx_next_done]);
- lp->tx_skb[lp->tx_next_done] = NULL;
- }
-
- lp->td_ring[lp->tx_next_done].control = DMAD_iof_m;
- lp->td_ring[lp->tx_next_done].devcs = ETHTX_fd_m | ETHTX_ld_m;
- lp->td_ring[lp->tx_next_done].link = 0;
- lp->td_ring[lp->tx_next_done].ca = 0;
- lp->tx_count --;
-
- /* go on to next transmission */
- lp->tx_next_done = (lp->tx_next_done + 1) & RC32434_TDS_MASK;
- td = &lp->td_ring[lp->tx_next_done];
-
- }
-
- dmas = __raw_readl(&lp->tx_dma_regs->dmas);
- __raw_writel( ~dmas, &lp->tx_dma_regs->dmas);
-
- /* Enable F E bit in Tx DMA */
- __raw_writel(__raw_readl(&lp->tx_dma_regs->dmasm) & ~(DMASM_f_m | DMASM_e_m), &lp->tx_dma_regs->dmasm);
- spin_unlock_irqrestore(&lp->lock, flags);
-
-}
-
-
-static struct net_device_stats * rc32434_get_stats(struct net_device *dev)
-{
- struct rc32434_local *lp = (struct rc32434_local *)dev->priv;
- return &lp->stats;
-}
-
-
-/*
- * Set or clear the multicast filter for this adaptor.
- */
-static void rc32434_multicast_list(struct net_device *dev)
-{
- /* listen to broadcasts always and to treat */
- /* IFF bits independantly */
- struct rc32434_local *lp = (struct rc32434_local *)dev->priv;
- unsigned long flags;
- u32 recognise = ETHARC_ab_m; /* always accept broadcasts */
-
- if (dev->flags & IFF_PROMISC) /* set promiscuous mode */
- recognise |= ETHARC_pro_m;
-
- if ((dev->flags & IFF_ALLMULTI) || (dev->mc_count > 15))
- recognise |= ETHARC_am_m; /* all multicast & bcast */
- else if (dev->mc_count > 0) {
- DBG(2, __FUNCTION__ ": mc_count %d\n", dev->mc_count);
- recognise |= ETHARC_am_m; /* for the time being */
- }
-
- spin_lock_irqsave(&lp->lock, flags);
- __raw_writel(recognise, &lp->eth_regs->etharc);
- spin_unlock_irqrestore(&lp->lock, flags);
-}
-
-
-static void rc32434_tx_timeout(struct net_device *dev)
-{
- struct rc32434_local *lp = (struct rc32434_local *)dev->priv;
- unsigned long flags;
-
- spin_lock_irqsave(&lp->lock, flags);
- rc32434_restart(dev);
- spin_unlock_irqrestore(&lp->lock, flags);
-
-}
-
-
-/*
- * Initialize the RC32434 ethernet controller.
- */
-static int rc32434_init(struct net_device *dev)
-{
- struct rc32434_local *lp = (struct rc32434_local *)dev->priv;
- int i, j;
-
- /* Disable DMA */
- rc32434_abort_tx(dev);
- rc32434_abort_rx(dev);
-
- /* reset ethernet logic */
- __raw_writel(0, &lp->eth_regs->ethintfc);
- while((__raw_readl(&lp->eth_regs->ethintfc) & ETHINTFC_rip_m))
- dev->trans_start = jiffies;
-
- /* Enable Ethernet Interface */
- __raw_writel(ETHINTFC_en_m, &lp->eth_regs->ethintfc);
-
-#ifndef CONFIG_IDT_USE_NAPI
- tasklet_disable(lp->rx_tasklet);
-#endif
- tasklet_disable(lp->tx_tasklet);
-
- /* Initialize the transmit Descriptors */
- for (i = 0; i < RC32434_NUM_TDS; i++) {
- lp->td_ring[i].control = DMAD_iof_m;
- lp->td_ring[i].devcs = ETHTX_fd_m | ETHTX_ld_m;
- lp->td_ring[i].ca = 0;
- lp->td_ring[i].link = 0;
- if (lp->tx_skb[i] != NULL) {
- dev_kfree_skb_any(lp->tx_skb[i]);
- lp->tx_skb[i] = NULL;
- }
- }
- lp->tx_next_done = lp->tx_chain_head = lp->tx_chain_tail = lp->tx_full = lp->tx_count = 0;
- lp-> tx_chain_status = empty;
-
- /*
- * Initialize the receive descriptors so that they
- * become a circular linked list, ie. let the last
- * descriptor point to the first again.
- */
- for (i=0; i<RC32434_NUM_RDS; i++) {
- struct sk_buff *skb = lp->rx_skb[i];
-
- if (lp->rx_skb[i] == NULL) {
- skb = dev_alloc_skb(RC32434_RBSIZE + 2);
- if (skb == NULL) {
- ERR("No memory in the system\n");
- for (j = 0; j < RC32434_NUM_RDS; j ++)
- if (lp->rx_skb[j] != NULL)
- dev_kfree_skb_any(lp->rx_skb[j]);
-
- return 1;
- }
- else {
- skb->dev = dev;
- skb_reserve(skb, 2);
- lp->rx_skb[i] = skb;
- lp->rd_ring[i].ca = CPHYSADDR(skb->data);
-
- }
- }
- lp->rd_ring[i].control = DMAD_iod_m | DMA_COUNT(RC32434_RBSIZE);
- lp->rd_ring[i].devcs = 0;
- lp->rd_ring[i].ca = CPHYSADDR(skb->data);
- lp->rd_ring[i].link = CPHYSADDR(&lp->rd_ring[i+1]);
-
- }
- /* loop back */
- lp->rd_ring[RC32434_NUM_RDS-1].link = CPHYSADDR(&lp->rd_ring[0]);
- lp->rx_next_done = 0;
-
- lp->rd_ring[RC32434_NUM_RDS-1].control |= DMAD_cod_m;
- lp->rx_chain_head = 0;
- lp->rx_chain_tail = 0;
- lp->rx_chain_status = empty;
-
- __raw_writel(0, &lp->rx_dma_regs->dmas);
- /* Start Rx DMA */
- rc32434_start_rx(lp, &lp->rd_ring[0]);
-
- /* Enable F E bit in Tx DMA */
- __raw_writel(__raw_readl(&lp->tx_dma_regs->dmasm) & ~(DMASM_f_m | DMASM_e_m), &lp->tx_dma_regs->dmasm);
- /* Enable D H E bit in Rx DMA */
- __raw_writel(__raw_readl(&lp->rx_dma_regs->dmasm) & ~(DMASM_d_m | DMASM_h_m | DMASM_e_m), &lp->rx_dma_regs->dmasm);
-
- /* Accept only packets destined for this Ethernet device address */
- __raw_writel(ETHARC_ab_m, &lp->eth_regs->etharc);
-
- /* Set all Ether station address registers to their initial values */
- __raw_writel(STATION_ADDRESS_LOW(dev), &lp->eth_regs->ethsal0);
- __raw_writel(STATION_ADDRESS_HIGH(dev), &lp->eth_regs->ethsah0);
-
- __raw_writel(STATION_ADDRESS_LOW(dev), &lp->eth_regs->ethsal1);
- __raw_writel(STATION_ADDRESS_HIGH(dev), &lp->eth_regs->ethsah1);
-
- __raw_writel(STATION_ADDRESS_LOW(dev), &lp->eth_regs->ethsal2);
- __raw_writel(STATION_ADDRESS_HIGH(dev), &lp->eth_regs->ethsah2);
-
- __raw_writel(STATION_ADDRESS_LOW(dev), &lp->eth_regs->ethsal3);
- __raw_writel(STATION_ADDRESS_HIGH(dev), &lp->eth_regs->ethsah3);
-
-
- /* Frame Length Checking, Pad Enable, CRC Enable, Full Duplex set */
- __raw_writel(ETHMAC2_pe_m | ETHMAC2_cen_m | ETHMAC2_fd_m, &lp->eth_regs->ethmac2);
- //ETHMAC2_flc_m ETHMAC2_fd_m lp->duplex_mode
-
- /* Back to back inter-packet-gap */
- __raw_writel(0x15, &lp->eth_regs->ethipgt);
- /* Non - Back to back inter-packet-gap */
- __raw_writel(0x12, &lp->eth_regs->ethipgr);
-
- /* Management Clock Prescaler Divisor */
- /* Clock independent setting */
- __raw_writel(((idt_cpu_freq)/MII_CLOCK+1) & ~1,
- &lp->eth_regs->ethmcp);
-
- /* don't transmit until fifo contains 48b */
- __raw_writel(48, &lp->eth_regs->ethfifott);
-
- __raw_writel(ETHMAC1_re_m, &lp->eth_regs->ethmac1);
-
-#ifndef CONFIG_IDT_USE_NAPI
- tasklet_enable(lp->rx_tasklet);
-#endif
- tasklet_enable(lp->tx_tasklet);
-
- netif_start_queue(dev);
-
- return 0;
-}
-
-static struct platform_driver korina_driver = {
- .driver.name = "korina",
- .probe = rc32434_probe,
- .remove = rc32434_remove,
-};
-
-static int __init rc32434_init_module(void)
-{
- return platform_driver_register(&korina_driver);
-}
-
-static void rc32434_cleanup_module(void)
-{
- return platform_driver_unregister(&korina_driver);
-}
-
-module_init(rc32434_init_module);
-module_exit(rc32434_cleanup_module);
+++ /dev/null
-/**************************************************************************
- *
- * BRIEF MODULE DESCRIPTION
- * Definitions for IDT RC32434 on-chip ethernet controller.
- *
- * Copyright 2004 IDT Inc. (rischelp@idt.com)
- *
- * 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 SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
- * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * 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.,
- * 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- *
- **************************************************************************
- * May 2004 rkt, neb
- *
- * Initial Release
- *
- * Aug 2004
- *
- * Added NAPI
- *
- **************************************************************************
- */
-
-
-#include <asm/rc32434/rc32434.h>
-#include <asm/rc32434/dma_v.h>
-#include <asm/rc32434/eth_v.h>
-
-#define CONFIG_IDT_USE_NAPI 1
-#define RC32434_DEBUG 2
-//#define RC32434_PROC_DEBUG
-#undef RC32434_DEBUG
-
-#ifdef RC32434_DEBUG
-
-/* use 0 for production, 1 for verification, >2 for debug */
-static int rc32434_debug = RC32434_DEBUG;
-#define ASSERT(expr) \
- if(!(expr)) { \
- printk( "Assertion failed! %s,%s,%s,line=%d\n", \
- #expr,__FILE__,__FUNCTION__,__LINE__); }
-#define DBG(lvl, format, arg...) if (rc32434_debug > lvl) printk(KERN_INFO "%s: " format, dev->name , ## arg)
-#else
-#define ASSERT(expr) do {} while (0)
-#define DBG(lvl, format, arg...) do {} while (0)
-#endif
-
-#define INFO(format, arg...) printk(KERN_INFO "%s: " format, dev->name , ## arg)
-#define ERR(format, arg...) printk(KERN_ERR "%s: " format, dev->name , ## arg)
-#define WARN(format, arg...) printk(KERN_WARNING "%s: " format, dev->name , ## arg)
-
-/* the following must be powers of two */
-#ifdef CONFIG_IDT_USE_NAPI
-#define RC32434_NUM_RDS 64 /* number of receive descriptors */
-#define RC32434_NUM_TDS 64 /* number of transmit descriptors */
-#else
-#define RC32434_NUM_RDS 128 /* number of receive descriptors */
-#define RC32434_NUM_TDS 128 /* number of transmit descriptors */
-#endif
-
-#define RC32434_RBSIZE 1536 /* size of one resource buffer = Ether MTU */
-#define RC32434_RDS_MASK (RC32434_NUM_RDS-1)
-#define RC32434_TDS_MASK (RC32434_NUM_TDS-1)
-#define RD_RING_SIZE (RC32434_NUM_RDS * sizeof(struct DMAD_s))
-#define TD_RING_SIZE (RC32434_NUM_TDS * sizeof(struct DMAD_s))
-
-#define RC32434_TX_TIMEOUT HZ * 100
-
-#define rc32434_eth0_regs ((ETH_t)(ETH0_VirtualAddress))
-#define rc32434_eth1_regs ((ETH_t)(ETH1_VirtualAddress))
-
-enum status { filled, empty};
-#define IS_DMA_FINISHED(X) (((X) & (DMAD_f_m)) != 0)
-#define IS_DMA_DONE(X) (((X) & (DMAD_d_m)) != 0)
-
-
-/* Information that need to be kept for each board. */
-struct rc32434_local {
- ETH_t eth_regs;
- DMA_Chan_t rx_dma_regs;
- DMA_Chan_t tx_dma_regs;
- volatile DMAD_t td_ring; /* transmit descriptor ring */
- volatile DMAD_t rd_ring; /* receive descriptor ring */
-
- struct sk_buff* tx_skb[RC32434_NUM_TDS]; /* skbuffs for pkt to trans */
- struct sk_buff* rx_skb[RC32434_NUM_RDS]; /* skbuffs for pkt to trans */
-
-#ifndef CONFIG_IDT_USE_NAPI
- struct tasklet_struct * rx_tasklet;
-#endif
- struct tasklet_struct * tx_tasklet;
-
- int rx_next_done;
- int rx_chain_head;
- int rx_chain_tail;
- enum status rx_chain_status;
-
- int tx_next_done;
- int tx_chain_head;
- int tx_chain_tail;
- enum status tx_chain_status;
- int tx_count;
- int tx_full;
-
- struct timer_list mii_phy_timer;
- unsigned long duplex_mode;
-
- int rx_irq;
- int tx_irq;
- int ovr_irq;
- int und_irq;
-
- struct net_device_stats stats;
- spinlock_t lock;
-
- /* debug /proc entry */
- struct proc_dir_entry *ps;
- int dma_halt_cnt; int dma_run_cnt;
-};
-
-extern unsigned int idt_cpu_freq;
-
-/* Index to functions, as function prototypes. */
-static int rc32434_open(struct net_device *dev);
-static int rc32434_send_packet(struct sk_buff *skb, struct net_device *dev);
-static void rc32434_mii_handler(unsigned long data);
-static irqreturn_t rc32434_und_interrupt(int irq, void *dev_id);
-static irqreturn_t rc32434_rx_dma_interrupt(int irq, void *dev_id);
-static irqreturn_t rc32434_tx_dma_interrupt(int irq, void *dev_id);
-#ifdef RC32434_REVISION
-static irqreturn_t rc32434_ovr_interrupt(int irq, void *dev_id);
-#endif
-static int rc32434_close(struct net_device *dev);
-static struct net_device_stats *rc32434_get_stats(struct net_device *dev);
-static void rc32434_multicast_list(struct net_device *dev);
-static int rc32434_init(struct net_device *dev);
-static void rc32434_tx_timeout(struct net_device *dev);
-
-static void rc32434_tx_tasklet(unsigned long tx_data_dev);
-#ifdef CONFIG_IDT_USE_NAPI
-static int rc32434_poll(struct net_device *rx_data_dev, int *budget);
-#else
-static void rc32434_rx_tasklet(unsigned long rx_data_dev);
-#endif
-static void rc32434_cleanup_module(void);
-
-
-static inline void rc32434_abort_dma(struct net_device *dev, DMA_Chan_t ch)
-{
- if (__raw_readl(&ch->dmac) & DMAC_run_m) {
- __raw_writel(0x10, &ch->dmac);
-
- while (!(__raw_readl(&ch->dmas) & DMAS_h_m))
- dev->trans_start = jiffies;
-
- __raw_writel(0, &ch->dmas);
- }
-
- __raw_writel(0, &ch->dmadptr);
- __raw_writel(0, &ch->dmandptr);
-}
+++ /dev/null
-#ifndef __IDT_DDR_H__
-#define __IDT_DDR_H__
-
-/*******************************************************************************
- *
- * Copyright 2002 Integrated Device Technology, Inc.
- * All rights reserved.
- *
- * DDR register definition.
- *
- * File : $Id: ddr.h,v 1.2 2002/06/06 18:34:03 astichte Exp $
- *
- * Author : ryan.holmQVist@idt.com
- * Date : 20011005
- * Update :
- * $Log: ddr.h,v $
- * Revision 1.2 2002/06/06 18:34:03 astichte
- * Added XXX_PhysicalAddress and XXX_VirtualAddress
- *
- * Revision 1.1 2002/05/29 17:33:21 sysarch
- * jba File moved from vcode/include/idt/acacia
- *
- *
- ******************************************************************************/
-
-enum
-{
- DDR0_PhysicalAddress = 0x18018000,
- DDR_PhysicalAddress = DDR0_PhysicalAddress, // Default
-
- DDR0_VirtualAddress = 0xb8018000,
- DDR_VirtualAddress = DDR0_VirtualAddress, // Default
-} ;
-
-typedef struct DDR_s
-{
- u32 ddrbase ;
- u32 ddrmask ;
- u32 res1;
- u32 res2;
- u32 ddrc ;
- u32 ddrabase ;
- u32 ddramask ;
- u32 ddramap ;
- u32 ddrcust;
- u32 ddrrdc;
- u32 ddrspare;
-} volatile *DDR_t ;
-
-enum
-{
- DDR0BASE_baseaddr_b = 16,
- DDR0BASE_baseaddr_m = 0xffff0000,
-
- DDR0MASK_mask_b = 16,
- DDR0MASK_mask_m = 0xffff0000,
-
- DDR1BASE_baseaddr_b = 16,
- DDR1BASE_baseaddr_m = 0xffff0000,
-
- DDR1MASK_mask_b = 16,
- DDR1MASK_mask_m = 0xffff0000,
-
- DDRC_ata_b = 5,
- DDRC_ata_m = 0x000000E0,
- DDRC_dbw_b = 8,
- DDRC_dbw_m = 0x00000100,
- DDRC_wr_b = 9,
- DDRC_wr_m = 0x00000600,
- DDRC_ps_b = 11,
- DDRC_ps_m = 0x00001800,
- DDRC_dtype_b = 13,
- DDRC_dtype_m = 0x0000e000,
- DDRC_rfc_b = 16,
- DDRC_rfc_m = 0x000f0000,
- DDRC_rp_b = 20,
- DDRC_rp_m = 0x00300000,
- DDRC_ap_b = 22,
- DDRC_ap_m = 0x00400000,
- DDRC_rcd_b = 23,
- DDRC_rcd_m = 0x01800000,
- DDRC_cl_b = 25,
- DDRC_cl_m = 0x06000000,
- DDRC_dbm_b = 27,
- DDRC_dbm_m = 0x08000000,
- DDRC_sds_b = 28,
- DDRC_sds_m = 0x10000000,
- DDRC_atp_b = 29,
- DDRC_atp_m = 0x60000000,
- DDRC_re_b = 31,
- DDRC_re_m = 0x80000000,
-
- DDRRDC_ces_b = 0,
- DDRRDC_ces_m = 0x00000001,
- DDRRDC_ace_b = 1,
- DDRRDC_ace_m = 0x00000002,
-
- DDRABASE_baseaddr_b = 16,
- DDRABASE_baseaddr_m = 0xffff0000,
-
- DDRAMASK_mask_b = 16,
- DDRAMASK_mask_m = 0xffff0000,
-
- DDRAMAP_map_b = 16,
- DDRAMAP_map_m = 0xffff0000,
-
- DDRCUST_cs_b = 0,
- DDRCUST_cs_m = 0x00000003,
- DDRCUST_we_b = 2,
- DDRCUST_we_m = 0x00000004,
- DDRCUST_ras_b = 3,
- DDRCUST_ras_m = 0x00000008,
- DDRCUST_cas_b = 4,
- DDRCUST_cas_m = 0x00000010,
- DDRCUST_cke_b = 5,
- DDRCUST_cke_m = 0x00000020,
- DDRCUST_ba_b = 6,
- DDRCUST_ba_m = 0x000000c0,
-
- RCOUNT_rcount_b = 0,
- RCOUNT_rcount_m = 0x0000ffff,
-
- RCOMPARE_rcompare_b = 0,
- RCOMPARE_rcompare_m = 0x0000ffff,
-
- RTC_ce_b = 0,
- RTC_ce_m = 0x00000001,
- RTC_to_b = 1,
- RTC_to_m = 0x00000002,
- RTC_rqe_b = 2,
- RTC_rqe_m = 0x00000004,
-
- DDRDQSC_dm_b = 0,
- DDRDQSC_dm_m = 0x00000003,
- DDRDQSC_dqsbs_b = 2,
- DDRDQSC_dqsbs_m = 0x000000fc,
- DDRDQSC_db_b = 8,
- DDRDQSC_db_m = 0x00000100,
- DDRDQSC_dbsp_b = 9,
- DDRDQSC_dbsp_m = 0x01fffe00,
- DDRDQSC_bdp_b = 25,
- DDRDQSC_bdp_m = 0x7e000000,
-
- DDRDLLC_eao_b = 0,
- DDRDLLC_eao_m = 0x00000001,
- DDRDLLC_eo_b = 1,
- DDRDLLC_eo_m = 0x0000003e,
- DDRDLLC_fs_b = 6,
- DDRDLLC_fs_m = 0x000000c0,
- DDRDLLC_as_b = 8,
- DDRDLLC_as_m = 0x00000700,
- DDRDLLC_sp_b = 11,
- DDRDLLC_sp_m = 0x001ff800,
-
- DDRDLLFC_men_b = 0,
- DDRDLLFC_men_m = 0x00000001,
- DDRDLLFC_aen_b = 1,
- DDRDLLFC_aen_m = 0x00000002,
- DDRDLLFC_ff_b = 2,
- DDRDLLFC_ff_m = 0x00000004,
-
- DDRDLLTA_addr_b = 2,
- DDRDLLTA_addr_m = 0xfffffffc,
-
- DDRDLLED_dbe_b = 0,
- DDRDLLED_dbe_m = 0x00000001,
- DDRDLLED_dte_b = 1,
- DDRDLLED_dte_m = 0x00000002,
-
-
-} ;
-
-#endif // __IDT_DDR_H__
+++ /dev/null
-#ifndef __IDT_DMA_H__
-#define __IDT_DMA_H__
-
-/*******************************************************************************
- *
- * Copyright 2002 Integrated Device Technology, Inc.
- * All rights reserved.
- *
- * DMA register definition.
- *
- * File : $Id: dma.h,v 1.3 2002/06/06 18:34:03 astichte Exp $
- *
- * Author : ryan.holmQVist@idt.com
- * Date : 20011005
- * Update :
- * $Log: dma.h,v $
- * Revision 1.3 2002/06/06 18:34:03 astichte
- * Added XXX_PhysicalAddress and XXX_VirtualAddress
- *
- * Revision 1.2 2002/06/05 18:30:46 astichte
- * Removed IDTField
- *
- * Revision 1.1 2002/05/29 17:33:21 sysarch
- * jba File moved from vcode/include/idt/acacia
- *
- *
- ******************************************************************************/
-
-enum
-{
- DMA0_PhysicalAddress = 0x18040000,
- DMA_PhysicalAddress = DMA0_PhysicalAddress, // Default
-
- DMA0_VirtualAddress = 0xb8040000,
- DMA_VirtualAddress = DMA0_VirtualAddress, // Default
-} ;
-
-/*
- * DMA descriptor (in physical memory).
- */
-
-typedef struct DMAD_s
-{
- u32 control ; // Control. use DMAD_*
- u32 ca ; // Current Address.
- u32 devcs ; // Device control and status.
- u32 link ; // Next descriptor in chain.
-} volatile *DMAD_t ;
-
-enum
-{
- DMAD_size = sizeof (struct DMAD_s),
- DMAD_count_b = 0, // in DMAD_t -> control
- DMAD_count_m = 0x0003ffff, // in DMAD_t -> control
- DMAD_ds_b = 20, // in DMAD_t -> control
- DMAD_ds_m = 0x00300000, // in DMAD_t -> control
- DMAD_ds_ethRcv_v = 0,
- DMAD_ds_ethXmt_v = 0,
- DMAD_ds_memToFifo_v = 0,
- DMAD_ds_fifoToMem_v = 0,
- DMAD_ds_pciToMem_v = 0,
- DMAD_ds_memToPci_v = 0,
-
- DMAD_devcmd_b = 22, // in DMAD_t -> control
- DMAD_devcmd_m = 0x01c00000, // in DMAD_t -> control
- DMAD_devcmd_byte_v = 0, //memory-to-memory
- DMAD_devcmd_halfword_v = 1, //memory-to-memory
- DMAD_devcmd_word_v = 2, //memory-to-memory
- DMAD_devcmd_2words_v = 3, //memory-to-memory
- DMAD_devcmd_4words_v = 4, //memory-to-memory
- DMAD_devcmd_6words_v = 5, //memory-to-memory
- DMAD_devcmd_8words_v = 6, //memory-to-memory
- DMAD_devcmd_16words_v = 7, //memory-to-memory
- DMAD_cof_b = 25, // chain on finished
- DMAD_cof_m = 0x02000000, //
- DMAD_cod_b = 26, // chain on done
- DMAD_cod_m = 0x04000000, //
- DMAD_iof_b = 27, // interrupt on finished
- DMAD_iof_m = 0x08000000, //
- DMAD_iod_b = 28, // interrupt on done
- DMAD_iod_m = 0x10000000, //
- DMAD_t_b = 29, // terminated
- DMAD_t_m = 0x20000000, //
- DMAD_d_b = 30, // done
- DMAD_d_m = 0x40000000, //
- DMAD_f_b = 31, // finished
- DMAD_f_m = 0x80000000, //
-} ;
-
-/*
- * DMA register (within Internal Register Map).
- */
-
-struct DMA_Chan_s
-{
- u32 dmac ; // Control.
- u32 dmas ; // Status.
- u32 dmasm ; // Mask.
- u32 dmadptr ; // Descriptor pointer.
- u32 dmandptr ; // Next descriptor pointer.
-};
-
-typedef struct DMA_Chan_s volatile *DMA_Chan_t ;
-
-//DMA_Channels use DMACH_count instead
-
-enum
-{
- DMAC_run_b = 0, //
- DMAC_run_m = 0x00000001, //
- DMAC_dm_b = 1, // done mask
- DMAC_dm_m = 0x00000002, //
- DMAC_mode_b = 2, //
- DMAC_mode_m = 0x0000000c, //
- DMAC_mode_auto_v = 0,
- DMAC_mode_burst_v = 1,
- DMAC_mode_transfer_v = 2, //usually used
- DMAC_mode_reserved_v = 3,
- DMAC_a_b = 4, //
- DMAC_a_m = 0x00000010, //
-
- DMAS_f_b = 0, // finished (sticky)
- DMAS_f_m = 0x00000001, //
- DMAS_d_b = 1, // done (sticky)
- DMAS_d_m = 0x00000002, //
- DMAS_c_b = 2, // chain (sticky)
- DMAS_c_m = 0x00000004, //
- DMAS_e_b = 3, // error (sticky)
- DMAS_e_m = 0x00000008, //
- DMAS_h_b = 4, // halt (sticky)
- DMAS_h_m = 0x00000010, //
-
- DMASM_f_b = 0, // finished (1=mask)
- DMASM_f_m = 0x00000001, //
- DMASM_d_b = 1, // done (1=mask)
- DMASM_d_m = 0x00000002, //
- DMASM_c_b = 2, // chain (1=mask)
- DMASM_c_m = 0x00000004, //
- DMASM_e_b = 3, // error (1=mask)
- DMASM_e_m = 0x00000008, //
- DMASM_h_b = 4, // halt (1=mask)
- DMASM_h_m = 0x00000010, //
-} ;
-
-/*
- * DMA channel definitions
- */
-
-enum
-{
- DMACH_ethRcv = 0,
- DMACH_ethXmt = 1,
- DMACH_memToFifo = 2,
- DMACH_fifoToMem = 3,
- DMACH_pciToMem = 4,
- DMACH_memToPci = 5,
-
- DMACH_count //must be last
-};
-
-
-typedef struct DMAC_s
-{
- struct DMA_Chan_s ch [DMACH_count] ; //use ch[DMACH_]
-} volatile *DMA_t ;
-
-#endif // __IDT_DMA_H__
-
+++ /dev/null
-#ifndef __IDT_DMA_V_H__
-#define __IDT_DMA_V_H__
-
-/*******************************************************************************
- *
- * Copyright 2002 Integrated Device Technology, Inc.
- * All rights reserved.
- *
- * DMA register definition.
- *
- * File : $Id: dma.h,v 1.3 2002/06/06 18:34:03 astichte Exp $
- *
- * Author : ryan.holmQVist@idt.com
- * Date : 20011005
- * Update :
- * $Log: dma.h,v $
- * Revision 1.3 2002/06/06 18:34:03 astichte
- * Added XXX_PhysicalAddress and XXX_VirtualAddress
- *
- * Revision 1.2 2002/06/05 18:30:46 astichte
- * Removed IDTField
- *
- * Revision 1.1 2002/05/29 17:33:21 sysarch
- * jba File moved from vcode/include/idt/acacia
- *
- *
- ******************************************************************************/
-#include <asm/rc32434/dma.h>
-#include <asm/rc32434/rc32434.h>
-#define DMA_CHAN_OFFSET 0x14
-#define IS_DMA_USED(X) (((X) & (DMAD_f_m | DMAD_d_m | DMAD_t_m)) != 0)
-#define DMA_COUNT(count) \
- ((count) & DMAD_count_m)
-
-#define DMA_HALT_TIMEOUT 500
-
-
-static inline int rc32434_halt_dma(DMA_Chan_t ch)
-{
- int timeout=1;
- if (local_readl(&ch->dmac) & DMAC_run_m) {
- local_writel(0, &ch->dmac);
- for (timeout = DMA_HALT_TIMEOUT; timeout > 0; timeout--) {
- if (local_readl(&ch->dmas) & DMAS_h_m) {
- local_writel(0, &ch->dmas);
- break;
- }
- }
- }
-
- return timeout ? 0 : 1;
-}
-
-static inline void rc32434_start_dma(DMA_Chan_t ch, u32 dma_addr)
-{
- local_writel(0, &ch->dmandptr);
- local_writel(dma_addr, &ch->dmadptr);
-}
-
-static inline void rc32434_chain_dma(DMA_Chan_t ch, u32 dma_addr)
-{
- local_writel(dma_addr, &ch->dmandptr);
-}
-
-#endif // __IDT_DMA_V_H__
-
-
-
-
-
-
-
+++ /dev/null
-#ifndef __IDT_ETH_H__
-#define __IDT_ETH_H__
-
-/*******************************************************************************
- *
- * Copyright 2002 Integrated Device Technology, Inc.
- * All rights reserved.
- *
- * Ethernet register definition.
- *
- * File : $Id: eth.h,v 1.3 2002/06/06 18:34:04 astichte Exp $
- *
- * Author : Allen.Stichter@idt.com
- * Date : 20020605
- * Update :
- * $Log: eth.h,v $
- * Revision 1.3 2002/06/06 18:34:04 astichte
- * Added XXX_PhysicalAddress and XXX_VirtualAddress
- *
- * Revision 1.2 2002/06/05 18:19:46 astichte
- * Added
- *
- * Revision 1.1 2002/05/29 17:33:22 sysarch
- * jba File moved from vcode/include/idt/acacia
- *
- ******************************************************************************/
-
-enum
-{
- ETH0_PhysicalAddress = 0x18060000,
- ETH_PhysicalAddress = ETH0_PhysicalAddress, // Default
-
- ETH0_VirtualAddress = 0xb8060000,
- ETH_VirtualAddress = ETH0_VirtualAddress, // Default
-} ;
-
-typedef struct
-{
- u32 ethintfc ;
- u32 ethfifott ;
- u32 etharc ;
- u32 ethhash0 ;
- u32 ethhash1 ;
- u32 ethu0 [4] ; // Reserved.
- u32 ethpfs ;
- u32 ethmcp ;
- u32 eth_u1 [10] ; // Reserved.
- u32 ethspare ;
- u32 eth_u2 [42] ; // Reserved.
- u32 ethsal0 ;
- u32 ethsah0 ;
- u32 ethsal1 ;
- u32 ethsah1 ;
- u32 ethsal2 ;
- u32 ethsah2 ;
- u32 ethsal3 ;
- u32 ethsah3 ;
- u32 ethrbc ;
- u32 ethrpc ;
- u32 ethrupc ;
- u32 ethrfc ;
- u32 ethtbc ;
- u32 ethgpf ;
- u32 eth_u9 [50] ; // Reserved.
- u32 ethmac1 ;
- u32 ethmac2 ;
- u32 ethipgt ;
- u32 ethipgr ;
- u32 ethclrt ;
- u32 ethmaxf ;
- u32 eth_u10 ; // Reserved.
- u32 ethmtest ;
- u32 miimcfg ;
- u32 miimcmd ;
- u32 miimaddr ;
- u32 miimwtd ;
- u32 miimrdd ;
- u32 miimind ;
- u32 eth_u11 ; // Reserved.
- u32 eth_u12 ; // Reserved.
- u32 ethcfsa0 ;
- u32 ethcfsa1 ;
- u32 ethcfsa2 ;
-} volatile *ETH_t;
-
-enum
-{
- ETHINTFC_en_b = 0,
- ETHINTFC_en_m = 0x00000001,
- ETHINTFC_its_b = 1,
- ETHINTFC_its_m = 0x00000002,
- ETHINTFC_rip_b = 2,
- ETHINTFC_rip_m = 0x00000004,
- ETHINTFC_jam_b = 3,
- ETHINTFC_jam_m = 0x00000008,
- ETHINTFC_ovr_b = 4,
- ETHINTFC_ovr_m = 0x00000010,
- ETHINTFC_und_b = 5,
- ETHINTFC_und_m = 0x00000020,
- ETHINTFC_iom_b = 6,
- ETHINTFC_iom_m = 0x000000c0,
-
- ETHFIFOTT_tth_b = 0,
- ETHFIFOTT_tth_m = 0x0000007f,
-
- ETHARC_pro_b = 0,
- ETHARC_pro_m = 0x00000001,
- ETHARC_am_b = 1,
- ETHARC_am_m = 0x00000002,
- ETHARC_afm_b = 2,
- ETHARC_afm_m = 0x00000004,
- ETHARC_ab_b = 3,
- ETHARC_ab_m = 0x00000008,
-
- ETHSAL_byte5_b = 0,
- ETHSAL_byte5_m = 0x000000ff,
- ETHSAL_byte4_b = 8,
- ETHSAL_byte4_m = 0x0000ff00,
- ETHSAL_byte3_b = 16,
- ETHSAL_byte3_m = 0x00ff0000,
- ETHSAL_byte2_b = 24,
- ETHSAL_byte2_m = 0xff000000,
-
- ETHSAH_byte1_b = 0,
- ETHSAH_byte1_m = 0x000000ff,
- ETHSAH_byte0_b = 8,
- ETHSAH_byte0_m = 0x0000ff00,
-
- ETHGPF_ptv_b = 0,
- ETHGPF_ptv_m = 0x0000ffff,
-
- ETHPFS_pfd_b = 0,
- ETHPFS_pfd_m = 0x00000001,
-
- ETHCFSA0_cfsa4_b = 0,
- ETHCFSA0_cfsa4_m = 0x000000ff,
- ETHCFSA0_cfsa5_b = 8,
- ETHCFSA0_cfsa5_m = 0x0000ff00,
-
- ETHCFSA1_cfsa2_b = 0,
- ETHCFSA1_cfsa2_m = 0x000000ff,
- ETHCFSA1_cfsa3_b = 8,
- ETHCFSA1_cfsa3_m = 0x0000ff00,
-
- ETHCFSA2_cfsa0_b = 0,
- ETHCFSA2_cfsa0_m = 0x000000ff,
- ETHCFSA2_cfsa1_b = 8,
- ETHCFSA2_cfsa1_m = 0x0000ff00,
-
- ETHMAC1_re_b = 0,
- ETHMAC1_re_m = 0x00000001,
- ETHMAC1_paf_b = 1,
- ETHMAC1_paf_m = 0x00000002,
- ETHMAC1_rfc_b = 2,
- ETHMAC1_rfc_m = 0x00000004,
- ETHMAC1_tfc_b = 3,
- ETHMAC1_tfc_m = 0x00000008,
- ETHMAC1_lb_b = 4,
- ETHMAC1_lb_m = 0x00000010,
- ETHMAC1_mr_b = 31,
- ETHMAC1_mr_m = 0x80000000,
-
- ETHMAC2_fd_b = 0,
- ETHMAC2_fd_m = 0x00000001,
- ETHMAC2_flc_b = 1,
- ETHMAC2_flc_m = 0x00000002,
- ETHMAC2_hfe_b = 2,
- ETHMAC2_hfe_m = 0x00000004,
- ETHMAC2_dc_b = 3,
- ETHMAC2_dc_m = 0x00000008,
- ETHMAC2_cen_b = 4,
- ETHMAC2_cen_m = 0x00000010,
- ETHMAC2_pe_b = 5,
- ETHMAC2_pe_m = 0x00000020,
- ETHMAC2_vpe_b = 6,
- ETHMAC2_vpe_m = 0x00000040,
- ETHMAC2_ape_b = 7,
- ETHMAC2_ape_m = 0x00000080,
- ETHMAC2_ppe_b = 8,
- ETHMAC2_ppe_m = 0x00000100,
- ETHMAC2_lpe_b = 9,
- ETHMAC2_lpe_m = 0x00000200,
- ETHMAC2_nb_b = 12,
- ETHMAC2_nb_m = 0x00001000,
- ETHMAC2_bp_b = 13,
- ETHMAC2_bp_m = 0x00002000,
- ETHMAC2_ed_b = 14,
- ETHMAC2_ed_m = 0x00004000,
-
- ETHIPGT_ipgt_b = 0,
- ETHIPGT_ipgt_m = 0x0000007f,
-
- ETHIPGR_ipgr2_b = 0,
- ETHIPGR_ipgr2_m = 0x0000007f,
- ETHIPGR_ipgr1_b = 8,
- ETHIPGR_ipgr1_m = 0x00007f00,
-
- ETHCLRT_maxret_b = 0,
- ETHCLRT_maxret_m = 0x0000000f,
- ETHCLRT_colwin_b = 8,
- ETHCLRT_colwin_m = 0x00003f00,
-
- ETHMAXF_maxf_b = 0,
- ETHMAXF_maxf_m = 0x0000ffff,
-
- ETHMTEST_tb_b = 2,
- ETHMTEST_tb_m = 0x00000004,
-
- ETHMCP_div_b = 0,
- ETHMCP_div_m = 0x000000ff,
-
- MIIMCFG_rsv_b = 0,
- MIIMCFG_rsv_m = 0x0000000c,
-
- MIIMCMD_rd_b = 0,
- MIIMCMD_rd_m = 0x00000001,
- MIIMCMD_scn_b = 1,
- MIIMCMD_scn_m = 0x00000002,
-
- MIIMADDR_regaddr_b = 0,
- MIIMADDR_regaddr_m = 0x0000001f,
- MIIMADDR_phyaddr_b = 8,
- MIIMADDR_phyaddr_m = 0x00001f00,
-
- MIIMWTD_wdata_b = 0,
- MIIMWTD_wdata_m = 0x0000ffff,
-
- MIIMRDD_rdata_b = 0,
- MIIMRDD_rdata_m = 0x0000ffff,
-
- MIIMIND_bsy_b = 0,
- MIIMIND_bsy_m = 0x00000001,
- MIIMIND_scn_b = 1,
- MIIMIND_scn_m = 0x00000002,
- MIIMIND_nv_b = 2,
- MIIMIND_nv_m = 0x00000004,
-
-} ;
-
-/*
- * Values for the DEVCS field of the Ethernet DMA Rx and Tx descriptors.
- */
-enum
-{
- ETHRX_fd_b = 0,
- ETHRX_fd_m = 0x00000001,
- ETHRX_ld_b = 1,
- ETHRX_ld_m = 0x00000002,
- ETHRX_rok_b = 2,
- ETHRX_rok_m = 0x00000004,
- ETHRX_fm_b = 3,
- ETHRX_fm_m = 0x00000008,
- ETHRX_mp_b = 4,
- ETHRX_mp_m = 0x00000010,
- ETHRX_bp_b = 5,
- ETHRX_bp_m = 0x00000020,
- ETHRX_vlt_b = 6,
- ETHRX_vlt_m = 0x00000040,
- ETHRX_cf_b = 7,
- ETHRX_cf_m = 0x00000080,
- ETHRX_ovr_b = 8,
- ETHRX_ovr_m = 0x00000100,
- ETHRX_crc_b = 9,
- ETHRX_crc_m = 0x00000200,
- ETHRX_cv_b = 10,
- ETHRX_cv_m = 0x00000400,
- ETHRX_db_b = 11,
- ETHRX_db_m = 0x00000800,
- ETHRX_le_b = 12,
- ETHRX_le_m = 0x00001000,
- ETHRX_lor_b = 13,
- ETHRX_lor_m = 0x00002000,
- ETHRX_ces_b = 14,
- ETHRX_ces_m = 0x00004000,
- ETHRX_length_b = 16,
- ETHRX_length_m = 0xffff0000,
-
- ETHTX_fd_b = 0,
- ETHTX_fd_m = 0x00000001,
- ETHTX_ld_b = 1,
- ETHTX_ld_m = 0x00000002,
- ETHTX_oen_b = 2,
- ETHTX_oen_m = 0x00000004,
- ETHTX_pen_b = 3,
- ETHTX_pen_m = 0x00000008,
- ETHTX_cen_b = 4,
- ETHTX_cen_m = 0x00000010,
- ETHTX_hen_b = 5,
- ETHTX_hen_m = 0x00000020,
- ETHTX_tok_b = 6,
- ETHTX_tok_m = 0x00000040,
- ETHTX_mp_b = 7,
- ETHTX_mp_m = 0x00000080,
- ETHTX_bp_b = 8,
- ETHTX_bp_m = 0x00000100,
- ETHTX_und_b = 9,
- ETHTX_und_m = 0x00000200,
- ETHTX_of_b = 10,
- ETHTX_of_m = 0x00000400,
- ETHTX_ed_b = 11,
- ETHTX_ed_m = 0x00000800,
- ETHTX_ec_b = 12,
- ETHTX_ec_m = 0x00001000,
- ETHTX_lc_b = 13,
- ETHTX_lc_m = 0x00002000,
- ETHTX_td_b = 14,
- ETHTX_td_m = 0x00004000,
- ETHTX_crc_b = 15,
- ETHTX_crc_m = 0x00008000,
- ETHTX_le_b = 16,
- ETHTX_le_m = 0x00010000,
- ETHTX_cc_b = 17,
- ETHTX_cc_m = 0x001E0000,
-} ;
-
-#endif // __IDT_ETH_H__
-
-
-
-
+++ /dev/null
-#ifndef __IDT_ETH_V_H__
-#define __IDT_ETH_V_H__
-
-/*******************************************************************************
- *
- * Copyright 2002 Integrated Device Technology, Inc.
- * All rights reserved.
- *
- * Ethernet register definition.
- *
- * File : $Id: eth.h,v 1.3 2002/06/06 18:34:04 astichte Exp $
- *
- * Author : Allen.Stichter@idt.com
- * Date : 20020605
- * Update :
- * $Log: eth.h,v $
- * Revision 1.3 2002/06/06 18:34:04 astichte
- * Added XXX_PhysicalAddress and XXX_VirtualAddress
- *
- * Revision 1.2 2002/06/05 18:19:46 astichte
- * Added
- *
- * Revision 1.1 2002/05/29 17:33:22 sysarch
- * jba File moved from vcode/include/idt/acacia
- *
- ******************************************************************************/
-
-#include <asm/rc32434/eth.h>
-
-#define IS_TX_TOK(X) (((X) & (1<<ETHTX_tok_b)) >> ETHTX_tok_b ) /* Transmit Okay */
-#define IS_TX_MP(X) (((X) & (1<<ETHTX_mp_b)) >> ETHTX_mp_b ) /* Multicast */
-#define IS_TX_BP(X) (((X) & (1<<ETHTX_bp_b)) >> ETHTX_bp_b ) /* Broadcast */
-#define IS_TX_UND_ERR(X) (((X) & (1<<ETHTX_und_b)) >> ETHTX_und_b ) /* Transmit FIFO Underflow */
-#define IS_TX_OF_ERR(X) (((X) & (1<<ETHTX_of_b)) >> ETHTX_of_b ) /* Oversized frame */
-#define IS_TX_ED_ERR(X) (((X) & (1<<ETHTX_ed_b)) >> ETHTX_ed_b ) /* Excessive deferral */
-#define IS_TX_EC_ERR(X) (((X) & (1<<ETHTX_ec_b)) >> ETHTX_ec_b) /* Excessive collisions */
-#define IS_TX_LC_ERR(X) (((X) & (1<<ETHTX_lc_b)) >> ETHTX_lc_b ) /* Late Collision */
-#define IS_TX_TD_ERR(X) (((X) & (1<<ETHTX_td_b)) >> ETHTX_td_b ) /* Transmit deferred*/
-#define IS_TX_CRC_ERR(X) (((X) & (1<<ETHTX_crc_b)) >> ETHTX_crc_b ) /* CRC Error */
-#define IS_TX_LE_ERR(X) (((X) & (1<<ETHTX_le_b)) >> ETHTX_le_b ) /* Length Error */
-
-#define TX_COLLISION_COUNT(X) (((X) & ETHTX_cc_m)>>ETHTX_cc_b) /* Collision Count */
-
-#define IS_RCV_ROK(X) (((X) & (1<<ETHRX_rok_b)) >> ETHRX_rok_b) /* Receive Okay */
-#define IS_RCV_FM(X) (((X) & (1<<ETHRX_fm_b)) >> ETHRX_fm_b) /* Is Filter Match */
-#define IS_RCV_MP(X) (((X) & (1<<ETHRX_mp_b)) >> ETHRX_mp_b) /* Is it MP */
-#define IS_RCV_BP(X) (((X) & (1<<ETHRX_bp_b)) >> ETHRX_bp_b) /* Is it BP */
-#define IS_RCV_VLT(X) (((X) & (1<<ETHRX_vlt_b)) >> ETHRX_vlt_b) /* VLAN Tag Detect */
-#define IS_RCV_CF(X) (((X) & (1<<ETHRX_cf_b)) >> ETHRX_cf_b) /* Control Frame */
-#define IS_RCV_OVR_ERR(X) (((X) & (1<<ETHRX_ovr_b)) >> ETHRX_ovr_b) /* Receive Overflow */
-#define IS_RCV_CRC_ERR(X) (((X) & (1<<ETHRX_crc_b)) >> ETHRX_crc_b) /* CRC Error */
-#define IS_RCV_CV_ERR(X) (((X) & (1<<ETHRX_cv_b)) >> ETHRX_cv_b) /* Code Violation */
-#define IS_RCV_DB_ERR(X) (((X) & (1<<ETHRX_db_b)) >> ETHRX_db_b) /* Dribble Bits */
-#define IS_RCV_LE_ERR(X) (((X) & (1<<ETHRX_le_b)) >> ETHRX_le_b) /* Length error */
-#define IS_RCV_LOR_ERR(X) (((X) & (1<<ETHRX_lor_b)) >> ETHRX_lor_b) /* Length Out of Range */
-#define IS_RCV_CES_ERR(X) (((X) & (1<<ETHRX_ces_b)) >> ETHRX_ces_b) /* Preamble error */
-#define RCVPKT_LENGTH(X) (((X) & ETHRX_length_m) >> ETHRX_length_b) /* Length of the received packet */
-#endif // __IDT_ETH_V_H__
-
-
-
-
-
+++ /dev/null
-/*
- * Copyright 2002 Integrated Device Technology, Inc.
- * All rights reserved.
- *
- * GPIO register definition.
- *
- * Author : ryan.holmQVist@idt.com
- * Date : 20011005
- * Copyright (C) 2001, 2002 Ryan Holm <ryan.holmQVist@idt.com>
- * Copyright (C) 2008 Florian Fainelli <florian@openwrt.org>
- */
-
-#ifndef _RC32434_GPIO_H_
-#define _RC32434_GPIO_H_
-
-#include <linux/types.h>
-
-struct rb500_gpio_reg {
- u32 gpiofunc; /* GPIO Function Register
- * gpiofunc[x]==0 bit = gpio
- * func[x]==1 bit = altfunc
- */
- u32 gpiocfg; /* GPIO Configuration Register
- * gpiocfg[x]==0 bit = input
- * gpiocfg[x]==1 bit = output
- */
- u32 gpiod; /* GPIO Data Register
- * gpiod[x] read/write gpio pinX status
- */
- u32 gpioilevel; /* GPIO Interrupt Status Register
- * interrupt level (see gpioistat)
- */
- u32 gpioistat; /* Gpio Interrupt Status Register
- * istat[x] = (gpiod[x] == level[x])
- * cleared in ISR (STICKY bits)
- */
- u32 gpionmien; /* GPIO Non-maskable Interrupt Enable Register */
-};
-
-/* UART GPIO signals */
-#define RC32434_UART0_SOUT (1 << 0)
-#define RC32434_UART0_SIN (1 << 1)
-#define RC32434_UART0_RTS (1 << 2)
-#define RC32434_UART0_CTS (1 << 3)
-
-/* M & P bus GPIO signals */
-#define RC32434_MP_BIT_22 (1 << 4)
-#define RC32434_MP_BIT_23 (1 << 5)
-#define RC32434_MP_BIT_24 (1 << 6)
-#define RC32434_MP_BIT_25 (1 << 7)
-
-/* CPU GPIO signals */
-#define RC32434_CPU_GPIO (1 << 8)
-
-/* Reserved GPIO signals */
-#define RC32434_AF_SPARE_6 (1 << 9)
-#define RC32434_AF_SPARE_4 (1 << 10)
-#define RC32434_AF_SPARE_3 (1 << 11)
-#define RC32434_AF_SPARE_2 (1 << 12)
-
-/* PCI messaging unit */
-#define RC32434_PCI_MSU_GPIO (1 << 13)
-
-extern int rb500_gpio_get_value(unsigned gpio);
-extern void rb500_gpio_set_value(unsigned gpio, int value);
-extern int rb500_gpio_direction_input(unsigned gpio);
-extern int rb500_gpio_direction_output(unsigned gpio, int value);
-extern void rb500_gpio_set_int_level(unsigned gpio, int value);
-extern int rb500_gpio_get_int_level(unsigned gpio);
-extern void rb500_gpio_set_int_status(unsigned gpio, int value);
-extern int rb500_gpio_get_int_status(unsigned gpio);
-extern void rb500_gpio_set_func(unsigned gpio, int value);
-extern int rb500_gpio_get_func(unsigned gpio);
-
-
-/* Wrappers for the arch-neutral GPIO API */
-
-static inline int gpio_request(unsigned gpio, const char *label)
-{
- /* Not yet implemented */
- return 0;
-}
-
-static inline void gpio_free(unsigned gpio)
-{
- /* Not yet implemented */
-}
-
-static inline int gpio_direction_input(unsigned gpio)
-{
- return rb500_gpio_direction_input(gpio);
-}
-
-static inline int gpio_direction_output(unsigned gpio, int value)
-{
- return rb500_gpio_direction_output(gpio, value);
-}
-
-static inline int gpio_get_value(unsigned gpio)
-{
- return rb500_gpio_get_value(gpio);
-}
-
-static inline void gpio_set_value(unsigned gpio, int value)
-{
- rb500_gpio_set_value(gpio, value);
-}
-
-static inline int gpio_to_irq(unsigned gpio)
-{
- return gpio;
-}
-
-static inline int irq_to_gpio(unsigned irq)
-{
- return irq;
-}
-
-/* For cansleep */
-#include <asm-generic/gpio.h>
-
-#endif /* _RC32434_GPIO_H_ */
+++ /dev/null
-#ifndef __IDT_INTEG_H__
-#define __IDT_INTEG_H__
-
-/*******************************************************************************
- *
- * Copyright 2002 Integrated Device Technology, Inc.
- * All rights reserved.
- *
- * System Integrity register definition.
- *
- * File : $Id: integ.h,v 1.3 2002/06/06 18:34:04 astichte Exp $
- *
- * Author : ryan.holmQVist@idt.com
- * Date : 20011005
- * Update :
- * $Log: integ.h,v $
- * Revision 1.3 2002/06/06 18:34:04 astichte
- * Added XXX_PhysicalAddress and XXX_VirtualAddress
- *
- * Revision 1.2 2002/06/05 18:32:33 astichte
- * Removed IDTField
- *
- * Revision 1.1 2002/05/29 17:33:22 sysarch
- * jba File moved from vcode/include/idt/acacia
- *
- ******************************************************************************/
-
-enum
-{
- INTEG0_PhysicalAddress = 0x18030000,
- INTEG_PhysicalAddress = INTEG0_PhysicalAddress, // Default
-
- INTEG0_VirtualAddress = 0xb8030000,
- INTEG_VirtualAddress = INTEG0_VirtualAddress, // Default
-} ;
-
-// if you are looing for CEA, try rst.h
-typedef struct
-{
- u32 filler [0xc] ; // 0x30 bytes unused.
- u32 errcs ; // sticky use ERRCS_
- u32 wtcount ; // Watchdog timer count reg.
- u32 wtcompare ; // Watchdog timer timeout value.
- u32 wtc ; // Watchdog timer control. use WTC_
-} volatile *INTEG_t ;
-
-enum
-{
- ERRCS_wto_b = 0, // In INTEG_t -> errcs
- ERRCS_wto_m = 0x00000001,
- ERRCS_wne_b = 1, // In INTEG_t -> errcs
- ERRCS_wne_m = 0x00000002,
- ERRCS_ucw_b = 2, // In INTEG_t -> errcs
- ERRCS_ucw_m = 0x00000004,
- ERRCS_ucr_b = 3, // In INTEG_t -> errcs
- ERRCS_ucr_m = 0x00000008,
- ERRCS_upw_b = 4, // In INTEG_t -> errcs
- ERRCS_upw_m = 0x00000010,
- ERRCS_upr_b = 5, // In INTEG_t -> errcs
- ERRCS_upr_m = 0x00000020,
- ERRCS_udw_b = 6, // In INTEG_t -> errcs
- ERRCS_udw_m = 0x00000040,
- ERRCS_udr_b = 7, // In INTEG_t -> errcs
- ERRCS_udr_m = 0x00000080,
- ERRCS_sae_b = 8, // In INTEG_t -> errcs
- ERRCS_sae_m = 0x00000100,
- ERRCS_wre_b = 9, // In INTEG_t -> errcs
- ERRCS_wre_m = 0x00000200,
-
- WTC_en_b = 0, // In INTEG_t -> wtc
- WTC_en_m = 0x00000001,
- WTC_to_b = 1, // In INTEG_t -> wtc
- WTC_to_m = 0x00000002,
-} ;
-
-#endif // __IDT_INTEG_H__
+++ /dev/null
-#ifndef __ASM_MACH_MIPS_IRQ_H
-#define __ASM_MACH_MIPS_IRQ_H
-
-#define NR_IRQS 256
-#include_next <irq.h>
-
-#endif /* __ASM_MACH_MIPS_IRQ_H */
+++ /dev/null
-/**************************************************************************
- *
- * BRIEF MODULE DESCRIPTION
- * PCI register definitio
- *
- * Copyright 2004 IDT Inc. (rischelp@idt.com)
- *
- * 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 SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
- * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * 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.,
- * 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- *
- **************************************************************************
- * May 2004 rkt, neb.
- *
- * Initial Release
- *
- *
- *
- **************************************************************************
- */
-
-#ifndef __IDT_PCI_H__
-#define __IDT_PCI_H__
-
-enum
-{
- PCI0_PhysicalAddress = 0x18080000,
- PCI_PhysicalAddress = PCI0_PhysicalAddress,
-
- PCI0_VirtualAddress = 0xB8080000,
- PCI_VirtualAddress = PCI0_VirtualAddress,
-} ;
-
-enum
-{
- PCI_LbaCount = 4, // Local base addresses.
-} ;
-
-typedef struct
-{
- u32 a ; // Address.
- u32 c ; // Control.
- u32 m ; // mapping.
-} PCI_Map_s ;
-
-typedef struct
-{
- u32 pcic ;
- u32 pcis ;
- u32 pcism ;
- u32 pcicfga ;
- u32 pcicfgd ;
- PCI_Map_s pcilba [PCI_LbaCount] ;
- u32 pcidac ;
- u32 pcidas ;
- u32 pcidasm ;
- u32 pcidad ;
- u32 pcidma8c ;
- u32 pcidma9c ;
- u32 pcitc ;
-} volatile *PCI_t ;
-
-// PCI messaging unit.
-enum
-{
- PCIM_Count = 2,
-} ;
-typedef struct
-{
- u32 pciim [PCIM_Count] ;
- u32 pciom [PCIM_Count] ;
- u32 pciid ;
- u32 pciiic ;
- u32 pciiim ;
- u32 pciiod ;
- u32 pciioic ;
- u32 pciioim ;
-} volatile *PCIM_t ;
-
-/*******************************************************************************
- *
- * PCI Control Register
- *
- ******************************************************************************/
-enum
-{
- PCIC_en_b = 0,
- PCIC_en_m = 0x00000001,
- PCIC_tnr_b = 1,
- PCIC_tnr_m = 0x00000002,
- PCIC_sce_b = 2,
- PCIC_sce_m = 0x00000004,
- PCIC_ien_b = 3,
- PCIC_ien_m = 0x00000008,
- PCIC_aaa_b = 4,
- PCIC_aaa_m = 0x00000010,
- PCIC_eap_b = 5,
- PCIC_eap_m = 0x00000020,
- PCIC_pcim_b = 6,
- PCIC_pcim_m = 0x000001c0,
- PCIC_pcim_disabled_v = 0,
- PCIC_pcim_tnr_v = 1, // Satellite - target not ready
- PCIC_pcim_suspend_v = 2, // Satellite - suspended CPU.
- PCIC_pcim_extern_v = 3, // Host - external arbiter.
- PCIC_pcim_fixed_v = 4, // Host - fixed priority arb.
- PCIC_pcim_roundrobin_v = 5, // Host - round robin priority.
- PCIC_pcim_reserved6_v = 6,
- PCIC_pcim_reserved7_v = 7,
- PCIC_igm_b = 9,
- PCIC_igm_m = 0x00000200,
-} ;
-
-/*******************************************************************************
- *
- * PCI Status Register
- *
- ******************************************************************************/
-enum {
- PCIS_eed_b = 0,
- PCIS_eed_m = 0x00000001,
- PCIS_wr_b = 1,
- PCIS_wr_m = 0x00000002,
- PCIS_nmi_b = 2,
- PCIS_nmi_m = 0x00000004,
- PCIS_ii_b = 3,
- PCIS_ii_m = 0x00000008,
- PCIS_cwe_b = 4,
- PCIS_cwe_m = 0x00000010,
- PCIS_cre_b = 5,
- PCIS_cre_m = 0x00000020,
- PCIS_mdpe_b = 6,
- PCIS_mdpe_m = 0x00000040,
- PCIS_sta_b = 7,
- PCIS_sta_m = 0x00000080,
- PCIS_rta_b = 8,
- PCIS_rta_m = 0x00000100,
- PCIS_rma_b = 9,
- PCIS_rma_m = 0x00000200,
- PCIS_sse_b = 10,
- PCIS_sse_m = 0x00000400,
- PCIS_ose_b = 11,
- PCIS_ose_m = 0x00000800,
- PCIS_pe_b = 12,
- PCIS_pe_m = 0x00001000,
- PCIS_tae_b = 13,
- PCIS_tae_m = 0x00002000,
- PCIS_rle_b = 14,
- PCIS_rle_m = 0x00004000,
- PCIS_bme_b = 15,
- PCIS_bme_m = 0x00008000,
- PCIS_prd_b = 16,
- PCIS_prd_m = 0x00010000,
- PCIS_rip_b = 17,
- PCIS_rip_m = 0x00020000,
-} ;
-
-/*******************************************************************************
- *
- * PCI Status Mask Register
- *
- ******************************************************************************/
-enum {
- PCISM_eed_b = 0,
- PCISM_eed_m = 0x00000001,
- PCISM_wr_b = 1,
- PCISM_wr_m = 0x00000002,
- PCISM_nmi_b = 2,
- PCISM_nmi_m = 0x00000004,
- PCISM_ii_b = 3,
- PCISM_ii_m = 0x00000008,
- PCISM_cwe_b = 4,
- PCISM_cwe_m = 0x00000010,
- PCISM_cre_b = 5,
- PCISM_cre_m = 0x00000020,
- PCISM_mdpe_b = 6,
- PCISM_mdpe_m = 0x00000040,
- PCISM_sta_b = 7,
- PCISM_sta_m = 0x00000080,
- PCISM_rta_b = 8,
- PCISM_rta_m = 0x00000100,
- PCISM_rma_b = 9,
- PCISM_rma_m = 0x00000200,
- PCISM_sse_b = 10,
- PCISM_sse_m = 0x00000400,
- PCISM_ose_b = 11,
- PCISM_ose_m = 0x00000800,
- PCISM_pe_b = 12,
- PCISM_pe_m = 0x00001000,
- PCISM_tae_b = 13,
- PCISM_tae_m = 0x00002000,
- PCISM_rle_b = 14,
- PCISM_rle_m = 0x00004000,
- PCISM_bme_b = 15,
- PCISM_bme_m = 0x00008000,
- PCISM_prd_b = 16,
- PCISM_prd_m = 0x00010000,
- PCISM_rip_b = 17,
- PCISM_rip_m = 0x00020000,
-} ;
-
-/*******************************************************************************
- *
- * PCI Configuration Address Register
- *
- ******************************************************************************/
-enum {
- PCICFGA_reg_b = 2,
- PCICFGA_reg_m = 0x000000fc,
- PCICFGA_reg_id_v = 0x00>>2, //use PCFGID_
- PCICFGA_reg_04_v = 0x04>>2, //use PCFG04_
- PCICFGA_reg_08_v = 0x08>>2, //use PCFG08_
- PCICFGA_reg_0C_v = 0x0C>>2, //use PCFG0C_
- PCICFGA_reg_pba0_v = 0x10>>2, //use PCIPBA_
- PCICFGA_reg_pba1_v = 0x14>>2, //use PCIPBA_
- PCICFGA_reg_pba2_v = 0x18>>2, //use PCIPBA_
- PCICFGA_reg_pba3_v = 0x1c>>2, //use PCIPBA_
- PCICFGA_reg_subsystem_v = 0x2c>>2, //use PCFGSS_
- PCICFGA_reg_3C_v = 0x3C>>2, //use PCFG3C_
- PCICFGA_reg_pba0c_v = 0x44>>2, //use PCIPBAC_
- PCICFGA_reg_pba0m_v = 0x48>>2,
- PCICFGA_reg_pba1c_v = 0x4c>>2, //use PCIPBAC_
- PCICFGA_reg_pba1m_v = 0x50>>2,
- PCICFGA_reg_pba2c_v = 0x54>>2, //use PCIPBAC_
- PCICFGA_reg_pba2m_v = 0x58>>2,
- PCICFGA_reg_pba3c_v = 0x5c>>2, //use PCIPBAC_
- PCICFGA_reg_pba3m_v = 0x60>>2,
- PCICFGA_reg_pmgt_v = 0x64>>2,
- PCICFGA_func_b = 8,
- PCICFGA_func_m = 0x00000700,
- PCICFGA_dev_b = 11,
- PCICFGA_dev_m = 0x0000f800,
- PCICFGA_dev_internal_v = 0,
- PCICFGA_bus_b = 16,
- PCICFGA_bus_m = 0x00ff0000,
- PCICFGA_bus_type0_v = 0, //local bus
- PCICFGA_en_b = 31, // read only
- PCICFGA_en_m = 0x80000000,
-} ;
-
-enum {
- PCFGID_vendor_b = 0,
- PCFGID_vendor_m = 0x0000ffff,
- PCFGID_vendor_IDT_v = 0x111d,
- PCFGID_device_b = 16,
- PCFGID_device_m = 0xffff0000,
- PCFGID_device_Korinade_v = 0x0214,
-
- PCFG04_command_ioena_b = 1,
- PCFG04_command_ioena_m = 0x00000001,
- PCFG04_command_memena_b = 2,
- PCFG04_command_memena_m = 0x00000002,
- PCFG04_command_bmena_b = 3,
- PCFG04_command_bmena_m = 0x00000004,
- PCFG04_command_mwinv_b = 5,
- PCFG04_command_mwinv_m = 0x00000010,
- PCFG04_command_parena_b = 7,
- PCFG04_command_parena_m = 0x00000040,
- PCFG04_command_serrena_b = 9,
- PCFG04_command_serrena_m = 0x00000100,
- PCFG04_command_fastbbena_b = 10,
- PCFG04_command_fastbbena_m = 0x00000200,
- PCFG04_status_b = 16,
- PCFG04_status_m = 0xffff0000,
- PCFG04_status_66MHz_b = 21, // 66 MHz enable
- PCFG04_status_66MHz_m = 0x00200000,
- PCFG04_status_fbb_b = 23,
- PCFG04_status_fbb_m = 0x00800000,
- PCFG04_status_mdpe_b = 24,
- PCFG04_status_mdpe_m = 0x01000000,
- PCFG04_status_dst_b = 25,
- PCFG04_status_dst_m = 0x06000000,
- PCFG04_status_sta_b = 27,
- PCFG04_status_sta_m = 0x08000000,
- PCFG04_status_rta_b = 28,
- PCFG04_status_rta_m = 0x10000000,
- PCFG04_status_rma_b = 29,
- PCFG04_status_rma_m = 0x20000000,
- PCFG04_status_sse_b = 30,
- PCFG04_status_sse_m = 0x40000000,
- PCFG04_status_pe_b = 31,
- PCFG04_status_pe_m = 0x40000000,
-
- PCFG08_revId_b = 0,
- PCFG08_revId_m = 0x000000ff,
- PCFG08_classCode_b = 0,
- PCFG08_classCode_m = 0xffffff00,
- PCFG08_classCode_bridge_v = 06,
- PCFG08_classCode_proc_v = 0x0b3000, // processor-MIPS
- PCFG0C_cacheline_b = 0,
- PCFG0C_cacheline_m = 0x000000ff,
- PCFG0C_masterLatency_b = 8,
- PCFG0C_masterLatency_m = 0x0000ff00,
- PCFG0C_headerType_b = 16,
- PCFG0C_headerType_m = 0x00ff0000,
- PCFG0C_bist_b = 24,
- PCFG0C_bist_m = 0xff000000,
-
- PCIPBA_msi_b = 0,
- PCIPBA_msi_m = 0x00000001,
- PCIPBA_p_b = 3,
- PCIPBA_p_m = 0x00000004,
- PCIPBA_baddr_b = 8,
- PCIPBA_baddr_m = 0xffffff00,
-
- PCFGSS_vendorId_b = 0,
- PCFGSS_vendorId_m = 0x0000ffff,
- PCFGSS_id_b = 16,
- PCFGSS_id_m = 0xffff0000,
-
- PCFG3C_interruptLine_b = 0,
- PCFG3C_interruptLine_m = 0x000000ff,
- PCFG3C_interruptPin_b = 8,
- PCFG3C_interruptPin_m = 0x0000ff00,
- PCFG3C_minGrant_b = 16,
- PCFG3C_minGrant_m = 0x00ff0000,
- PCFG3C_maxLat_b = 24,
- PCFG3C_maxLat_m = 0xff000000,
-
- PCIPBAC_msi_b = 0,
- PCIPBAC_msi_m = 0x00000001,
- PCIPBAC_p_b = 1,
- PCIPBAC_p_m = 0x00000002,
- PCIPBAC_size_b = 2,
- PCIPBAC_size_m = 0x0000007c,
- PCIPBAC_sb_b = 7,
- PCIPBAC_sb_m = 0x00000080,
- PCIPBAC_pp_b = 8,
- PCIPBAC_pp_m = 0x00000100,
- PCIPBAC_mr_b = 9,
- PCIPBAC_mr_m = 0x00000600,
- PCIPBAC_mr_read_v =0, //no prefetching
- PCIPBAC_mr_readLine_v =1,
- PCIPBAC_mr_readMult_v =2,
- PCIPBAC_mrl_b = 11,
- PCIPBAC_mrl_m = 0x00000800,
- PCIPBAC_mrm_b = 12,
- PCIPBAC_mrm_m = 0x00001000,
- PCIPBAC_trp_b = 13,
- PCIPBAC_trp_m = 0x00002000,
-
- PCFG40_trdyTimeout_b = 0,
- PCFG40_trdyTimeout_m = 0x000000ff,
- PCFG40_retryLim_b = 8,
- PCFG40_retryLim_m = 0x0000ff00,
-};
-
-/*******************************************************************************
- *
- * PCI Local Base Address [0|1|2|3] Register
- *
- ******************************************************************************/
-enum {
- PCILBA_baddr_b = 0, // In PCI_t -> pcilba [] .a
- PCILBA_baddr_m = 0xffffff00,
-} ;
-/*******************************************************************************
- *
- * PCI Local Base Address Control Register
- *
- ******************************************************************************/
-enum {
- PCILBAC_msi_b = 0, // In pPci->pcilba[i].c
- PCILBAC_msi_m = 0x00000001,
- PCILBAC_msi_mem_v = 0,
- PCILBAC_msi_io_v = 1,
- PCILBAC_size_b = 2, // In pPci->pcilba[i].c
- PCILBAC_size_m = 0x0000007c,
- PCILBAC_sb_b = 7, // In pPci->pcilba[i].c
- PCILBAC_sb_m = 0x00000080,
- PCILBAC_rt_b = 8, // In pPci->pcilba[i].c
- PCILBAC_rt_m = 0x00000100,
- PCILBAC_rt_noprefetch_v = 0, // mem read
- PCILBAC_rt_prefetch_v = 1, // mem readline
-} ;
-
-/*******************************************************************************
- *
- * PCI Local Base Address [0|1|2|3] Mapping Register
- *
- ******************************************************************************/
-enum {
- PCILBAM_maddr_b = 8,
- PCILBAM_maddr_m = 0xffffff00,
-} ;
-
-/*******************************************************************************
- *
- * PCI Decoupled Access Control Register
- *
- ******************************************************************************/
-enum {
- PCIDAC_den_b = 0,
- PCIDAC_den_m = 0x00000001,
-} ;
-
-/*******************************************************************************
- *
- * PCI Decoupled Access Status Register
- *
- ******************************************************************************/
-enum {
- PCIDAS_d_b = 0,
- PCIDAS_d_m = 0x00000001,
- PCIDAS_b_b = 1,
- PCIDAS_b_m = 0x00000002,
- PCIDAS_e_b = 2,
- PCIDAS_e_m = 0x00000004,
- PCIDAS_ofe_b = 3,
- PCIDAS_ofe_m = 0x00000008,
- PCIDAS_off_b = 4,
- PCIDAS_off_m = 0x00000010,
- PCIDAS_ife_b = 5,
- PCIDAS_ife_m = 0x00000020,
- PCIDAS_iff_b = 6,
- PCIDAS_iff_m = 0x00000040,
-} ;
-
-/*******************************************************************************
- *
- * PCI DMA Channel 8 Configuration Register
- *
- ******************************************************************************/
-enum
-{
- PCIDMA8C_mbs_b = 0, // Maximum Burst Size.
- PCIDMA8C_mbs_m = 0x00000fff, // { pcidma8c }
- PCIDMA8C_our_b = 12, // Optimize Unaligned Burst Reads.
- PCIDMA8C_our_m = 0x00001000, // { pcidma8c }
-} ;
-
-/*******************************************************************************
- *
- * PCI DMA Channel 9 Configuration Register
- *
- ******************************************************************************/
-enum
-{
- PCIDMA9C_mbs_b = 0, // Maximum Burst Size.
- PCIDMA9C_mbs_m = 0x00000fff, // { pcidma9c }
-} ;
-
-/*******************************************************************************
- *
- * PCI to Memory(DMA Channel 8) AND Memory to PCI DMA(DMA Channel 9)Descriptors
- *
- ******************************************************************************/
-enum {
- PCIDMAD_pt_b = 22, // in DEVCMD field (descriptor)
- PCIDMAD_pt_m = 0x00c00000, // preferred transaction field
- // These are for reads (DMA channel 8)
- PCIDMAD_devcmd_mr_v = 0, //memory read
- PCIDMAD_devcmd_mrl_v = 1, //memory read line
- PCIDMAD_devcmd_mrm_v = 2, //memory read multiple
- PCIDMAD_devcmd_ior_v = 3, //I/O read
- // These are for writes (DMA channel 9)
- PCIDMAD_devcmd_mw_v = 0, //memory write
- PCIDMAD_devcmd_mwi_v = 1, //memory write invalidate
- PCIDMAD_devcmd_iow_v = 3, //I/O write
-
- // Swap byte field applies to both DMA channel 8 and 9
- PCIDMAD_sb_b = 24, // in DEVCMD field (descriptor)
- PCIDMAD_sb_m = 0x01000000, // swap byte field
-} ;
-
-
-/*******************************************************************************
- *
- * PCI Target Control Register
- *
- ******************************************************************************/
-enum
-{
- PCITC_rtimer_b = 0, // In PCITC_t -> pcitc
- PCITC_rtimer_m = 0x000000ff,
- PCITC_dtimer_b = 8, // In PCITC_t -> pcitc
- PCITC_dtimer_m = 0x0000ff00,
- PCITC_rdr_b = 18, // In PCITC_t -> pcitc
- PCITC_rdr_m = 0x00040000,
- PCITC_ddt_b = 19, // In PCITC_t -> pcitc
- PCITC_ddt_m = 0x00080000,
-} ;
-/*******************************************************************************
- *
- * PCI messaging unit [applies to both inbound and outbound registers ]
- *
- ******************************************************************************/
-enum
-{
- PCIM_m0_b = 0, // In PCIM_t -> {pci{iic,iim,ioic,ioim}}
- PCIM_m0_m = 0x00000001, // inbound or outbound message 0
- PCIM_m1_b = 1, // In PCIM_t -> {pci{iic,iim,ioic,ioim}}
- PCIM_m1_m = 0x00000002, // inbound or outbound message 1
- PCIM_db_b = 2, // In PCIM_t -> {pci{iic,iim,ioic,ioim}}
- PCIM_db_m = 0x00000004, // inbound or outbound doorbell
-};
-
-
-
-
-
-
-#define PCI_MSG_VirtualAddress 0xB8088010
-#define rc32434_pci ((volatile PCI_t) PCI0_VirtualAddress)
-#define rc32434_pci_msg ((volatile PCIM_t) PCI_MSG_VirtualAddress)
-
-#define PCIM_SHFT 0x6
-#define PCIM_BIT_LEN 0x7
-#define PCIM_H_EA 0x3
-#define PCIM_H_IA_FIX 0x4
-#define PCIM_H_IA_RR 0x5
-
-#define PCI_ADDR_START 0x50000000
-
-#define CPUTOPCI_MEM_WIN 0x02000000
-#define CPUTOPCI_IO_WIN 0x00100000
-#define PCILBA_SIZE_SHFT 2
-#define PCILBA_SIZE_MASK 0x1F
-#define SIZE_256MB 0x1C
-#define SIZE_128MB 0x1B
-#define SIZE_64MB 0x1A
-#define SIZE_32MB 0x19
-#define SIZE_16MB 0x18
-#define SIZE_4MB 0x16
-#define SIZE_2MB 0x15
-#define SIZE_1MB 0x14
-#define KORINA_CONFIG0_ADDR 0x80000000
-#define KORINA_CONFIG1_ADDR 0x80000004
-#define KORINA_CONFIG2_ADDR 0x80000008
-#define KORINA_CONFIG3_ADDR 0x8000000C
-#define KORINA_CONFIG4_ADDR 0x80000010
-#define KORINA_CONFIG5_ADDR 0x80000014
-#define KORINA_CONFIG6_ADDR 0x80000018
-#define KORINA_CONFIG7_ADDR 0x8000001C
-#define KORINA_CONFIG8_ADDR 0x80000020
-#define KORINA_CONFIG9_ADDR 0x80000024
-#define KORINA_CONFIG10_ADDR 0x80000028
-#define KORINA_CONFIG11_ADDR 0x8000002C
-#define KORINA_CONFIG12_ADDR 0x80000030
-#define KORINA_CONFIG13_ADDR 0x80000034
-#define KORINA_CONFIG14_ADDR 0x80000038
-#define KORINA_CONFIG15_ADDR 0x8000003C
-#define KORINA_CONFIG16_ADDR 0x80000040
-#define KORINA_CONFIG17_ADDR 0x80000044
-#define KORINA_CONFIG18_ADDR 0x80000048
-#define KORINA_CONFIG19_ADDR 0x8000004C
-#define KORINA_CONFIG20_ADDR 0x80000050
-#define KORINA_CONFIG21_ADDR 0x80000054
-#define KORINA_CONFIG22_ADDR 0x80000058
-#define KORINA_CONFIG23_ADDR 0x8000005C
-#define KORINA_CONFIG24_ADDR 0x80000060
-#define KORINA_CONFIG25_ADDR 0x80000064
-#define KORINA_CMD (PCFG04_command_ioena_m | \
- PCFG04_command_memena_m | \
- PCFG04_command_bmena_m | \
- PCFG04_command_mwinv_m | \
- PCFG04_command_parena_m | \
- PCFG04_command_serrena_m )
-
-#define KORINA_STAT (PCFG04_status_mdpe_m | \
- PCFG04_status_sta_m | \
- PCFG04_status_rta_m | \
- PCFG04_status_rma_m | \
- PCFG04_status_sse_m | \
- PCFG04_status_pe_m)
-
-#define KORINA_CNFG1 ((KORINA_STAT<<16)|KORINA_CMD)
-
-#define KORINA_REVID 0
-#define KORINA_CLASS_CODE 0
-#define KORINA_CNFG2 ((KORINA_CLASS_CODE<<8) | \
- KORINA_REVID)
-
-#define KORINA_CACHE_LINE_SIZE 4
-#define KORINA_MASTER_LAT 0x3c
-#define KORINA_HEADER_TYPE 0
-#define KORINA_BIST 0
-
-#define KORINA_CNFG3 ((KORINA_BIST << 24) | \
- (KORINA_HEADER_TYPE<<16) | \
- (KORINA_MASTER_LAT<<8) | \
- KORINA_CACHE_LINE_SIZE )
-
-#define KORINA_BAR0 0x00000008 /* 128 MB Memory */
-#define KORINA_BAR1 0x18800001 /* 1 MB IO */
-#define KORINA_BAR2 0x18000001 /* 2 MB IO window for Korina
- internal Registers */
-#define KORINA_BAR3 0x48000008 /* Spare 128 MB Memory */
-
-#define KORINA_CNFG4 KORINA_BAR0
-#define KORINA_CNFG5 KORINA_BAR1
-#define KORINA_CNFG6 KORINA_BAR2
-#define KORINA_CNFG7 KORINA_BAR3
-
-#define KORINA_SUBSYS_VENDOR_ID 0x011d
-#define KORINA_SUBSYSTEM_ID 0x0214
-#define KORINA_CNFG8 0
-#define KORINA_CNFG9 0
-#define KORINA_CNFG10 0
-#define KORINA_CNFG11 ((KORINA_SUBSYS_VENDOR_ID<<16) | \
- KORINA_SUBSYSTEM_ID)
-#define KORINA_INT_LINE 1
-#define KORINA_INT_PIN 1
-#define KORINA_MIN_GNT 8
-#define KORINA_MAX_LAT 0x38
-#define KORINA_CNFG12 0
-#define KORINA_CNFG13 0
-#define KORINA_CNFG14 0
-#define KORINA_CNFG15 ((KORINA_MAX_LAT<<24) | \
- (KORINA_MIN_GNT<<16) | \
- (KORINA_INT_PIN<<8) | \
- KORINA_INT_LINE)
-#define KORINA_RETRY_LIMIT 0x80
-#define KORINA_TRDY_LIMIT 0x80
-#define KORINA_CNFG16 ((KORINA_RETRY_LIMIT<<8) | \
- KORINA_TRDY_LIMIT)
-#define PCI_PBAxC_R 0x0
-#define PCI_PBAxC_RL 0x1
-#define PCI_PBAxC_RM 0x2
-#define SIZE_SHFT 2
-
-#if defined(__MIPSEB__)
-#define KORINA_PBA0C ( PCIPBAC_mrl_m | PCIPBAC_sb_m | \
- ((PCI_PBAxC_RM &0x3) << PCIPBAC_mr_b) | \
- PCIPBAC_pp_m | \
- (SIZE_128MB<<SIZE_SHFT) | \
- PCIPBAC_p_m)
-#else
-#define KORINA_PBA0C ( PCIPBAC_mrl_m | \
- ((PCI_PBAxC_RM &0x3) << PCIPBAC_mr_b) | \
- PCIPBAC_pp_m | \
- (SIZE_128MB<<SIZE_SHFT) | \
- PCIPBAC_p_m)
-#endif
-#define KORINA_CNFG17 KORINA_PBA0C
-#define KORINA_PBA0M 0x0
-#define KORINA_CNFG18 KORINA_PBA0M
-
-#if defined(__MIPSEB__)
-#define KORINA_PBA1C ((SIZE_1MB<<SIZE_SHFT) | PCIPBAC_sb_m | \
- PCIPBAC_msi_m)
-#else
-#define KORINA_PBA1C ((SIZE_1MB<<SIZE_SHFT) | \
- PCIPBAC_msi_m)
-#endif
-#define KORINA_CNFG19 KORINA_PBA1C
-#define KORINA_PBA1M 0x0
-#define KORINA_CNFG20 KORINA_PBA1M
-
-#if defined(__MIPSEB__)
-#define KORINA_PBA2C ((SIZE_2MB<<SIZE_SHFT) | PCIPBAC_sb_m | \
- PCIPBAC_msi_m)
-#else
-#define KORINA_PBA2C ((SIZE_2MB<<SIZE_SHFT) | \
- PCIPBAC_msi_m)
-#endif
-#define KORINA_CNFG21 KORINA_PBA2C
-#define KORINA_PBA2M 0x18000000
-#define KORINA_CNFG22 KORINA_PBA2M
-#define KORINA_PBA3C 0
-#define KORINA_CNFG23 KORINA_PBA3C
-#define KORINA_PBA3M 0
-#define KORINA_CNFG24 KORINA_PBA3M
-
-
-
-#define PCITC_DTIMER_VAL 8
-#define PCITC_RTIMER_VAL 0x10
-
-
-
-
-#endif // __IDT_PCI_H__
-
-
-
+++ /dev/null
-/*
- * Copyright (C) 2004 IDT Inc.
- * Copyright (C) 2006 Felix Fietkau <nbd@openwrt.org>
- *
- * 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.
- *
- */
-#ifndef __MIPS_RB_H__
-#define __MIPS_RB_H__
-#include <linux/genhd.h>
-
-#define IDT434_REG_BASE ((volatile void *) KSEG1ADDR(0x18000000))
-#define DEV0BASE 0x010000
-#define DEV0MASK 0x010004
-#define DEV0C 0x010008
-#define DEV0TC 0x01000C
-#define DEV1BASE 0x010010
-#define DEV1MASK 0x010014
-#define DEV1C 0x010018
-#define DEV1TC 0x01001C
-#define DEV2BASE 0x010020
-#define DEV2MASK 0x010024
-#define DEV2C 0x010028
-#define DEV2TC 0x01002C
-#define DEV3BASE 0x010030
-#define DEV3MASK 0x010034
-#define DEV3C 0x010038
-#define DEV3TC 0x01003C
-#define BTCS 0x010040
-#define BTCOMPARE 0x010044
-#define GPIOFUNC 0x050000
-#define GPIOCFG 0x050004
-#define GPIOD 0x050008
-#define GPIOILEVEL 0x05000C
-#define GPIOISTAT 0x050010
-#define GPIONMIEN 0x050014
-#define IMASK6 0x038038
-
-#define LO_WPX (1 << 0)
-#define LO_ALE (1 << 1)
-#define LO_CLE (1 << 2)
-#define LO_CEX (1 << 3)
-#define LO_FOFF (1 << 5)
-#define LO_SPICS (1 << 6)
-#define LO_ULED (1 << 7)
-
-typedef enum {
- FUNC = 0x00,
- CFG = 0x04,
- DATA = 0x08,
- ILEVEL = 0x0c,
- ISTAT = 0x10,
- NMIEN = 0x14
-} gpio_func;
-
-extern void changeLatchU5(unsigned char orMask, unsigned char nandMask);
-extern unsigned get434Reg(unsigned regOffs);
-extern void set434Reg(unsigned regOffs, unsigned bit, unsigned len, unsigned val);
-extern void gpio_set(gpio_func func, u32 mask, u32 value);
-extern u32 gpio_get(gpio_func func);
-
-#define get434Reg(x) (*(volatile unsigned *) (IDT434_REG_BASE + (x)))
-
-struct korina_device {
- char *name;
- unsigned char mac[6];
- struct net_device *dev;
-};
-
-struct cf_device {
- int gpio_pin;
- void *dev;
- struct gendisk *gd;
-};
-
-#endif
+++ /dev/null
-/*
- ***************************************************************************
- * Definitions for IDT RC323434 CPU.
- *
- ****************************************************************************
- * Kiran Rao
- *
- * Original form
- ****************************************************************************
- * P. Sadik Oct 08, 2003
- *
- * Started revision history
- * Made IDT_BUS_FREQ a kernel configuration parameter
- ****************************************************************************
- * P. Sadik Oct 10, 2003
- *
- * Removed IDT_BUS_FREQ, since this parameter is no longer required. Instead
- * idt_cpu_freq is used everywhere
- ****************************************************************************
- * P. Sadik Oct 20, 2003
- *
- * Removed RC32434_BASE_BAUD
- ****************************************************************************
-*/
-#ifndef _RC32434_H_
-#define _RC32434_H_
-
-#include <linux/autoconf.h>
-#include <linux/delay.h>
-#include <asm/io.h>
-
-#define RC32434_REG_BASE 0x18000000
-
-#define interrupt ((volatile INT_t ) INT0_VirtualAddress)
-
-
-#define IDT_CLOCK_MULT 2
-#define MIPS_CPU_TIMER_IRQ 7
-/* Interrupt Controller */
-#define IC_GROUP0_PEND (RC32434_REG_BASE + 0x38000)
-#define IC_GROUP0_MASK (RC32434_REG_BASE + 0x38008)
-#define IC_GROUP_OFFSET 0x0C
-
-#define NUM_INTR_GROUPS 5
-/* 16550 UARTs */
-
-#define GROUP0_IRQ_BASE 8 /* GRP2 IRQ numbers start here */
-#define GROUP1_IRQ_BASE (GROUP0_IRQ_BASE + 32) /* GRP3 IRQ numbers start here */
-#define GROUP2_IRQ_BASE (GROUP1_IRQ_BASE + 32) /* GRP4 IRQ numbers start here */
-#define GROUP3_IRQ_BASE (GROUP2_IRQ_BASE + 32) /* GRP5 IRQ numbers start here */
-#define GROUP4_IRQ_BASE (GROUP3_IRQ_BASE + 32)
-
-
-#ifdef __MIPSEB__
-#define RC32434_UART0_BASE (RC32434_REG_BASE + 0x58003)
-#else
-#define RC32434_UART0_BASE (RC32434_REG_BASE + 0x58000)
-#endif
-
-#define RC32434_UART0_IRQ GROUP3_IRQ_BASE + 0
-// #define EB434_UART1_IRQ GROUP4_IRQ_BASE + 11
-
-#define local_readl(addr) __raw_readl(addr)
-#define local_writel(l,addr) __raw_writel(l,addr)
-
-/* cpu pipeline flush */
-static inline void rc32434_sync(void)
-{
- __asm__ volatile ("sync");
-}
-
-static inline void rc32434_sync_udelay(int us)
-{
- __asm__ volatile ("sync");
- udelay(us);
-}
-
-static inline void rc32434_sync_delay(int ms)
-{
- __asm__ volatile ("sync");
- mdelay(ms);
-}
-
-/*
- * C access to CLZ and CLO instructions
- * (count leading zeroes/ones).
- */
-static inline int rc32434_clz(unsigned long val)
-{
- int ret;
- __asm__ volatile (
- ".set\tnoreorder\n\t"
- ".set\tnoat\n\t"
- ".set\tmips32\n\t"
- "clz\t%0,%1\n\t"
- ".set\tmips0\n\t"
- ".set\tat\n\t"
- ".set\treorder"
- : "=r" (ret)
- : "r" (val));
-
- return ret;
-}
-static inline int rc32434_clo(unsigned long val)
-{
- int ret;
- __asm__ volatile (
- ".set\tnoreorder\n\t"
- ".set\tnoat\n\t"
- ".set\tmips32\n\t"
- "clo\t%0,%1\n\t"
- ".set\tmips0\n\t"
- ".set\tat\n\t"
- ".set\treorder"
- : "=r" (ret)
- : "r" (val));
-
- return ret;
-}
-
-#endif /* _RC32434_H_ */
+++ /dev/null
-/*
- * This file is subject to the terms and conditions of the GNU General Public
- * License. See the file "COPYING" in the main directory of this archive
- * for more details.
- *
- * Copyright (C) 2002, 2004, 2007 by Ralf Baechle <ralf@linux-mips.org>
- */
-#ifndef __ASM_MIPS_MACH_MIPS_WAR_H
-#define __ASM_MIPS_MACH_MIPS_WAR_H
-
-#define R4600_V1_INDEX_ICACHEOP_WAR 0
-#define R4600_V1_HIT_CACHEOP_WAR 0
-#define R4600_V2_HIT_CACHEOP_WAR 0
-#define R5432_CP0_INTERRUPT_WAR 0
-#define BCM1250_M3_WAR 0
-#define SIBYTE_1956_WAR 0
-#define MIPS4K_ICACHE_REFILL_WAR 1
-#define MIPS_CACHE_SYNC_WAR 0
-#define TX49XX_ICACHE_INDEX_INV_WAR 0
-#define RM9000_CDEX_SMP_WAR 0
-#define ICACHE_REFILLS_WORKAROUND_WAR 0
-#define R10000_LLSC_WAR 0
-#define MIPS34K_MISSED_ITLB_WAR 0
-
-#endif /* __ASM_MIPS_MACH_MIPS_WAR_H */
+++ /dev/null
-Index: linux-2.6.23.17/arch/mips/Kconfig
-===================================================================
---- linux-2.6.23.17.orig/arch/mips/Kconfig
-+++ linux-2.6.23.17/arch/mips/Kconfig
-@@ -595,6 +595,20 @@ config WR_PPMC
- This enables support for the Wind River MIPS32 4KC PPMC evaluation
- board, which is based on GT64120 bridge chip.
-
-+config MIKROTIK_RB500
-+ bool "Support for RB5xx boards"
-+ select HW_HAS_PCI
-+ select IRQ_CPU
-+ select SYS_HAS_CPU_MIPS32_R1
-+ select SYS_SUPPORTS_LITTLE_ENDIAN
-+ select SYS_SUPPORTS_32BIT_KERNEL
-+ select SWAP_IO_SPACE
-+ select DMA_NONCOHERENT
-+ select GENERIC_GPIO
-+ help
-+ Support the Mikrotik(tm) Routerboard 500 series,
-+ such as the RB532.
-+
- endchoice
-
- source "arch/mips/au1000/Kconfig"
-@@ -829,6 +843,7 @@ config MIPS_L1_CACHE_SHIFT
- default "4" if MACH_DECSTATION
- default "7" if SGI_IP27 || SNI_RM
- default "4" if PMC_MSP4200_EVAL
-+ default "4" if MIKROTIK_RB500
- default "5"
-
- config HAVE_STD_PC_SERIAL_PORT
-Index: linux-2.6.23.17/arch/mips/Makefile
-===================================================================
---- linux-2.6.23.17.orig/arch/mips/Makefile
-+++ linux-2.6.23.17/arch/mips/Makefile
-@@ -300,6 +300,13 @@ load-$(CONFIG_LEMOTE_FULONG) +=0xfffffff
- cflags-$(CONFIG_LEMOTE_FULONG) += -Iinclude/asm-mips/mach-lemote
-
- #
-+# Routerboard 532 board
-+#
-+core-$(CONFIG_MIKROTIK_RB500) += arch/mips/rb500/
-+cflags-$(CONFIG_MIKROTIK_RB500) += -Iinclude/asm-mips/rc32434
-+load-$(CONFIG_MIKROTIK_RB500) += 0xffffffff80101000
-+
-+#
- # For all MIPS, Inc. eval boards
- #
- core-$(CONFIG_MIPS_BOARDS_GEN) += arch/mips/mips-boards/generic/
-Index: linux-2.6.23.17/arch/mips/pci/Makefile
-===================================================================
---- linux-2.6.23.17.orig/arch/mips/pci/Makefile
-+++ linux-2.6.23.17/arch/mips/pci/Makefile
-@@ -46,3 +46,4 @@ obj-$(CONFIG_TOSHIBA_RBTX4938) += fixup-
- obj-$(CONFIG_VICTOR_MPC30X) += fixup-mpc30x.o
- obj-$(CONFIG_ZAO_CAPCELLA) += fixup-capcella.o
- obj-$(CONFIG_WR_PPMC) += fixup-wrppmc.o
-+obj-$(CONFIG_MIKROTIK_RB500) += pci-rc32434.o ops-rc32434.o fixup-rb500.o
-Index: linux-2.6.23.17/drivers/pci/Makefile
-===================================================================
---- linux-2.6.23.17.orig/drivers/pci/Makefile
-+++ linux-2.6.23.17/drivers/pci/Makefile
-@@ -32,6 +32,7 @@ obj-$(CONFIG_PPC32) += setup-irq.o
- obj-$(CONFIG_PPC64) += setup-bus.o
- obj-$(CONFIG_MIPS) += setup-bus.o setup-irq.o
- obj-$(CONFIG_X86_VISWS) += setup-irq.o
-+obj-$(CONFIG_MIKROTIK_RB500) += setup-irq.o
-
- #
- # ACPI Related PCI FW Functions
-Index: linux-2.6.23.17/include/asm-mips/bootinfo.h
-===================================================================
---- linux-2.6.23.17.orig/include/asm-mips/bootinfo.h
-+++ linux-2.6.23.17/include/asm-mips/bootinfo.h
-@@ -208,6 +208,11 @@
- #define MACH_GROUP_WINDRIVER 28 /* Windriver boards */
- #define MACH_WRPPMC 1
-
-+
-+#define MACH_GROUP_MIKROTIK 29 /* Mikrotik Boards */
-+#define MACH_MIKROTIK_RB532 0 /* Mikrotik RouterBoard 532 */
-+#define MACH_MIKROTIK_RB532A 1 /* Mikrotik RouterBoard 532A */
-+
- #define CL_SIZE COMMAND_LINE_SIZE
-
- const char *get_system_type(void);
-Index: linux-2.6.23.17/include/asm-mips/cpu.h
-===================================================================
---- linux-2.6.23.17.orig/include/asm-mips/cpu.h
-+++ linux-2.6.23.17/include/asm-mips/cpu.h
-@@ -217,8 +217,9 @@
- #define CPU_R14000 64
- #define CPU_LOONGSON1 65
- #define CPU_LOONGSON2 66
-+#define CPU_RC32300 67
-
--#define CPU_LAST 66
-+#define CPU_LAST 67
-
- /*
- * ISA Level encodings
+++ /dev/null
-Index: linux-2.6.23.17/drivers/net/Kconfig
-===================================================================
---- linux-2.6.23.17.orig/drivers/net/Kconfig
-+++ linux-2.6.23.17/drivers/net/Kconfig
-@@ -348,6 +348,13 @@ config AX88796
- AX88796 driver, using platform bus to provide
- chip detection and resources
-
-+config KORINA
-+ tristate "Korina Local Ethernet support"
-+ depends on NET_ETHERNET && ( IDT_EB434 || MIKROTIK_RB500)
-+ help
-+ IDT RC32434 has one local ethernet port. Say Y here to enable it.
-+ To compile this driver as a module, choose M here.
-+
- config MACE
- tristate "MACE (Power Mac ethernet) support"
- depends on PPC_PMAC && PPC32
-Index: linux-2.6.23.17/drivers/net/Makefile
-===================================================================
---- linux-2.6.23.17.orig/drivers/net/Makefile
-+++ linux-2.6.23.17/drivers/net/Makefile
-@@ -25,6 +25,8 @@ ucc_geth_driver-objs := ucc_geth.o ucc_g
- #
- obj-$(CONFIG_PLIP) += plip.o
-
-+obj-$(CONFIG_KORINA) += korina.o
-+
- obj-$(CONFIG_ROADRUNNER) += rrunner.o
-
- obj-$(CONFIG_HAPPYMEAL) += sunhme.o
+++ /dev/null
-Index: linux-2.6.23.17/drivers/block/Kconfig
-===================================================================
---- linux-2.6.23.17.orig/drivers/block/Kconfig
-+++ linux-2.6.23.17/drivers/block/Kconfig
-@@ -426,6 +426,14 @@ config SUNVDC
- Support for virtual disk devices as a client under Sun
- Logical Domains.
-
-+config BLK_DEV_CF_MIPS
-+ bool "CF slot of RB532 board"
-+ depends on MIKROTIK_RB500
-+ default y
-+ help
-+ The Routerboard 532 has a CF slot on it. Enable the special block
-+ device driver for it.
-+
- source "drivers/s390/block/Kconfig"
-
- config XILINX_SYSACE
-Index: linux-2.6.23.17/drivers/block/Makefile
-===================================================================
---- linux-2.6.23.17.orig/drivers/block/Makefile
-+++ linux-2.6.23.17/drivers/block/Makefile
-@@ -21,6 +21,7 @@ obj-$(CONFIG_BLK_DEV_DAC960) += DAC960.o
- obj-$(CONFIG_XILINX_SYSACE) += xsysace.o
- obj-$(CONFIG_CDROM_PKTCDVD) += pktcdvd.o
- obj-$(CONFIG_SUNVDC) += sunvdc.o
-+obj-$(CONFIG_BLK_DEV_CF_MIPS) += rb500/
-
- obj-$(CONFIG_BLK_DEV_UMEM) += umem.o
- obj-$(CONFIG_BLK_DEV_NBD) += nbd.o
+++ /dev/null
-Index: linux-2.6.23.17/arch/mips/kernel/head.S
-===================================================================
---- linux-2.6.23.17.orig/arch/mips/kernel/head.S
-+++ linux-2.6.23.17/arch/mips/kernel/head.S
-@@ -132,6 +132,10 @@
-
- j kernel_entry
- nop
-+
-+EXPORT(_image_cmdline)
-+ .ascii "CMDLINE:"
-+
- #ifndef CONFIG_NO_EXCEPT_FILL
- /*
- * Reserved space for exception handlers.
+++ /dev/null
-Index: linux-2.6.23.17/arch/mips/pci/pci.c
-===================================================================
---- linux-2.6.23.17.orig/arch/mips/pci/pci.c
-+++ linux-2.6.23.17/arch/mips/pci/pci.c
-@@ -64,8 +64,10 @@ pcibios_align_resource(void *data, struc
- /*
- * Put everything into 0x00-0xff region modulo 0x400
- */
-+#ifndef CONFIG_MIKROTIK_RB500
- if (start & 0x300)
- start = (start + 0x3ff) & ~0x3ff;
-+#endif
- } else if (res->flags & IORESOURCE_MEM) {
- /* Make sure we start at our min on all hoses */
- if (start < PCIBIOS_MIN_MEM + hose->mem_resource->start)
+++ /dev/null
-Index: linux-2.6.23.17/drivers/serial/8250.c
-===================================================================
---- linux-2.6.23.17.orig/drivers/serial/8250.c
-+++ linux-2.6.23.17/drivers/serial/8250.c
-@@ -433,6 +433,13 @@ serial_out(struct uart_8250_port *up, in
- default:
- outb(value, up->port.iobase + offset);
- }
-+
-+#if defined(CONFIG_IDT_EB434) || defined(CONFIG_MIKROTIK_RB500)
-+ __SLOW_DOWN_IO;
-+ __SLOW_DOWN_IO;
-+ __SLOW_DOWN_IO;
-+ __SLOW_DOWN_IO;
-+#endif
- }
-
- static void
+++ /dev/null
-Index: linux-2.6.23.17/drivers/net/via-rhine.c
-===================================================================
---- linux-2.6.23.17.orig/drivers/net/via-rhine.c
-+++ linux-2.6.23.17/drivers/net/via-rhine.c
-@@ -33,6 +33,8 @@
- #define DRV_VERSION "1.4.3"
- #define DRV_RELDATE "2007-03-06"
-
-+#define PKT_ALIGN 1
-+
-
- /* A few user-configurable values.
- These may be modified when a driver module is loaded. */
-@@ -40,6 +42,7 @@
- static int debug = 1; /* 1 normal messages, 0 quiet .. 7 verbose. */
- static int max_interrupt_work = 20;
-
-+#ifndef PKT_ALIGN
- /* Set the copy breakpoint for the copy-only-tiny-frames scheme.
- Setting to > 1518 effectively disables this feature. */
- #if defined(__alpha__) || defined(__arm__) || defined(__hppa__) \
-@@ -49,6 +52,7 @@ static int rx_copybreak = 1518;
- #else
- static int rx_copybreak;
- #endif
-+#endif /* PKT_ALIGN */
-
- /* Work-around for broken BIOSes: they are unable to get the chip back out of
- power state D3 so PXE booting fails. bootparam(7): via-rhine.avoid_D3=1 */
-@@ -111,6 +115,7 @@ static const int multicast_filter_limit
- #include <asm/io.h>
- #include <asm/irq.h>
- #include <asm/uaccess.h>
-+#include <asm/unaligned.h>
- #include <linux/dmi.h>
-
- /* These identify the driver base version and may not be removed. */
-@@ -130,12 +135,14 @@ MODULE_LICENSE("GPL");
-
- module_param(max_interrupt_work, int, 0);
- module_param(debug, int, 0);
--module_param(rx_copybreak, int, 0);
- module_param(avoid_D3, bool, 0);
- MODULE_PARM_DESC(max_interrupt_work, "VIA Rhine maximum events handled per interrupt");
- MODULE_PARM_DESC(debug, "VIA Rhine debug level (0-7)");
--MODULE_PARM_DESC(rx_copybreak, "VIA Rhine copy breakpoint for copy-only-tiny-frames");
- MODULE_PARM_DESC(avoid_D3, "Avoid power state D3 (work-around for broken BIOSes)");
-+#ifndef PKT_ALIGN
-+module_param(rx_copybreak, int, 0);
-+MODULE_PARM_DESC(rx_copybreak, "VIA Rhine copy breakpoint for copy-only-tiny-frames");
-+#endif
-
- /*
- Theory of Operation
-@@ -927,7 +934,7 @@ static void alloc_rbufs(struct net_devic
-
- /* Fill in the Rx buffers. Handle allocation failure gracefully. */
- for (i = 0; i < RX_RING_SIZE; i++) {
-- struct sk_buff *skb = dev_alloc_skb(rp->rx_buf_sz);
-+ struct sk_buff *skb = dev_alloc_skb(rp->rx_buf_sz + 4);
- rp->rx_skbuff[i] = skb;
- if (skb == NULL)
- break;
-@@ -1484,7 +1491,9 @@ static int rhine_rx(struct net_device *d
- struct sk_buff *skb;
- /* Length should omit the CRC */
- int pkt_len = data_size - 4;
--
-+#ifdef PKT_ALIGN
-+ int i;
-+#else
- /* Check if the packet is long enough to accept without
- copying to a minimally-sized skbuff. */
- if (pkt_len < rx_copybreak &&
-@@ -1503,7 +1512,9 @@ static int rhine_rx(struct net_device *d
- rp->rx_skbuff_dma[entry],
- rp->rx_buf_sz,
- PCI_DMA_FROMDEVICE);
-- } else {
-+ } else
-+#endif
-+ {
- skb = rp->rx_skbuff[entry];
- if (skb == NULL) {
- printk(KERN_ERR "%s: Inconsistent Rx "
-@@ -1517,6 +1528,14 @@ static int rhine_rx(struct net_device *d
- rp->rx_skbuff_dma[entry],
- rp->rx_buf_sz,
- PCI_DMA_FROMDEVICE);
-+#ifdef PKT_ALIGN
-+ /* align the data to the ip header - should be faster than copying the entire packet */
-+ for (i = pkt_len - (pkt_len % 4); i >= 0; i -= 4) {
-+ put_unaligned(*((u32 *) (skb->data + i)), (u32 *) (skb->data + i + 2));
-+ }
-+ skb->data += 2;
-+ skb->tail += 2;
-+#endif
- }
- skb->protocol = eth_type_trans(skb, dev);
- #ifdef CONFIG_VIA_RHINE_NAPI
+++ /dev/null
-Index: linux-2.6.23.17/drivers/leds/Kconfig
-===================================================================
---- linux-2.6.23.17.orig/drivers/leds/Kconfig
-+++ linux-2.6.23.17/drivers/leds/Kconfig
-@@ -107,6 +107,12 @@ config LEDS_GPIO
- outputs. To be useful the particular board must have LEDs
- and they must be connected to the GPIO lines.
-
-+config LEDS_RB500
-+ tristate "LED Support for RB5xx boards"
-+ depends LEDS_CLASS && MIKROTIK_RB500
-+ help
-+ This option enables support for the yellow user LED on RB5xx boards.
-+
- comment "LED Triggers"
-
- config LEDS_TRIGGERS
-Index: linux-2.6.23.17/drivers/leds/Makefile
-===================================================================
---- linux-2.6.23.17.orig/drivers/leds/Makefile
-+++ linux-2.6.23.17/drivers/leds/Makefile
-@@ -18,6 +18,7 @@ obj-$(CONFIG_LEDS_ALIX) += leds-alix.o
- obj-$(CONFIG_LEDS_H1940) += leds-h1940.o
- obj-$(CONFIG_LEDS_COBALT) += leds-cobalt.o
- obj-$(CONFIG_LEDS_GPIO) += leds-gpio.o
-+obj-$(CONFIG_LEDS_RB500) += leds-rb500.o
-
- # LED Triggers
- obj-$(CONFIG_LEDS_TRIGGER_TIMER) += ledtrig-timer.o
+++ /dev/null
-Index: linux-2.6.23.17/arch/mips/kernel/time.c
-===================================================================
---- linux-2.6.23.17.orig/arch/mips/kernel/time.c
-+++ linux-2.6.23.17/arch/mips/kernel/time.c
-@@ -479,3 +479,5 @@ EXPORT_SYMBOL(rtc_lock);
- EXPORT_SYMBOL(to_tm);
- EXPORT_SYMBOL(rtc_mips_set_time);
- EXPORT_SYMBOL(rtc_mips_get_time);
-+EXPORT_SYMBOL(mips_hpt_frequency);
-+
-Index: linux-2.6.23.17/drivers/char/watchdog/Kconfig
-===================================================================
---- linux-2.6.23.17.orig/drivers/char/watchdog/Kconfig
-+++ linux-2.6.23.17/drivers/char/watchdog/Kconfig
-@@ -647,6 +647,19 @@ config WATCHDOG_RTAS
- To compile this driver as a module, choose M here. The module
- will be called wdrtas.
-
-+config RC32434_WDT
-+ tristate "IDT Interprise 79RC32434 SoC hardware watchdog"
-+ depends on WATCHDOG && MIKROTIK_RB500
-+ help
-+ This is a driver for hardware watchdog integrated in IDT Interprise
-+ 79RC32434 SoC. This watchdog simply watches your kernel to make sure
-+ it doesn't freeze, and if it does, it reboots your computer after a
-+ certain amount of time.
-+
-+ To compile this driver as a module, choose M here: the module will be
-+ called rc32434_wdt.
-+
-+
- # S390 Architecture
-
- config ZVM_WATCHDOG
-Index: linux-2.6.23.17/drivers/char/watchdog/Makefile
-===================================================================
---- linux-2.6.23.17.orig/drivers/char/watchdog/Makefile
-+++ linux-2.6.23.17/drivers/char/watchdog/Makefile
-@@ -90,6 +90,7 @@ obj-$(CONFIG_SBC_EPX_C3_WATCHDOG) += sbc
- obj-$(CONFIG_INDYDOG) += indydog.o
- obj-$(CONFIG_WDT_MTX1) += mtx-1_wdt.o
- obj-$(CONFIG_WDT_RM9K_GPI) += rm9k_wdt.o
-+obj-$(CONFIG_RC32434_WDT) += rc32434_wdt.o
-
- # PARISC Architecture
-
+++ /dev/null
-# CONFIG_60XX_WDT is not set
-# CONFIG_64BIT is not set
-# CONFIG_8139TOO is not set
-# CONFIG_ACQUIRE_WDT is not set
-# CONFIG_ADVANTECH_WDT is not set
-# CONFIG_AGP is not set
-# CONFIG_ALIM1535_WDT is not set
-# CONFIG_ALIM7101_WDT is not set
-CONFIG_ARCH_DEFCONFIG="arch/x86/configs/i386_defconfig"
-CONFIG_ARCH_HAS_CPU_IDLE_WAIT=y
-CONFIG_ARCH_HAS_CPU_RELAX=y
-# CONFIG_ARCH_HAS_ILOG2_U32 is not set
-# CONFIG_ARCH_HAS_ILOG2_U64 is not set
-CONFIG_ARCH_HIBERNATION_POSSIBLE=y
-CONFIG_ARCH_MAY_HAVE_PC_FDC=y
-CONFIG_ARCH_POPULATES_NODE_MAP=y
-CONFIG_ARCH_SUPPORTS_AOUT=y
-# CONFIG_ARCH_SUPPORTS_MSI is not set
-CONFIG_ARCH_SUSPEND_POSSIBLE=y
-CONFIG_ATA=m
-# CONFIG_ATA_NONSTANDARD is not set
-CONFIG_ATA_PIIX=m
-# CONFIG_AUDIT_ARCH is not set
-CONFIG_BASE_SMALL=0
-CONFIG_BINFMT_AOUT=m
-CONFIG_BINFMT_MISC=m
-CONFIG_BITREVERSE=y
-CONFIG_BLK_DEV_IDE=m
-CONFIG_BLK_DEV_IDEDISK=m
-# CONFIG_BLK_DEV_IDEDMA is not set
-CONFIG_BOUNCE=y
-# CONFIG_BROADCOM_PHY is not set
-CONFIG_CLASSIC_RCU=y
-CONFIG_CLOCKSOURCE_WATCHDOG=y
-# CONFIG_COMPAT_VDSO is not set
-# CONFIG_CPU5_WDT is not set
-# CONFIG_CPU_FREQ is not set
-# CONFIG_CPU_IDLE is not set
-CONFIG_CRYPTO_AEAD=m
-CONFIG_CRYPTO_AES_586=m
-CONFIG_CRYPTO_AUTHENC=m
-CONFIG_CRYPTO_GF128MUL=m
-# CONFIG_CRYPTO_SALSA20_586 is not set
-CONFIG_CRYPTO_TWOFISH_586=m
-# CONFIG_CS5535_GPIO is not set
-# CONFIG_DCDBAS is not set
-# CONFIG_DEBUG_BUGVERBOSE is not set
-CONFIG_DEFAULT_CFQ=y
-# CONFIG_DEFAULT_DEADLINE is not set
-CONFIG_DEFAULT_IOSCHED="cfq"
-CONFIG_DEFAULT_IO_DELAY_TYPE=0
-# CONFIG_DELL_RBU is not set
-CONFIG_DEVPORT=y
-# CONFIG_DMADEVICES is not set
-CONFIG_DMI=y
-CONFIG_DMIID=y
-CONFIG_DOUBLEFAULT=y
-# CONFIG_E100 is not set
-# CONFIG_E1000E_ENABLED is not set
-CONFIG_EARLY_PRINTK=y
-# CONFIG_EDAC is not set
-# CONFIG_EDD is not set
-# CONFIG_EUROTECH_WDT is not set
-CONFIG_FAST_CMPXCHG_LOCAL=y
-# CONFIG_FIXED_PHY is not set
-CONFIG_FIX_EARLYCON_MEM=y
-CONFIG_FS_POSIX_ACL=y
-CONFIG_GENERIC_BUG=y
-CONFIG_GENERIC_CLOCKEVENTS=y
-CONFIG_GENERIC_CLOCKEVENTS_BUILD=y
-CONFIG_GENERIC_CMOS_UPDATE=y
-# CONFIG_GENERIC_CPU is not set
-CONFIG_GENERIC_GPIO=y
-CONFIG_GENERIC_IOMAP=y
-CONFIG_GENERIC_ISA_DMA=y
-# CONFIG_GENERIC_LOCKBREAK is not set
-# CONFIG_GENERIC_TIME_VSYSCALL is not set
-# CONFIG_GEN_RTC is not set
-# CONFIG_HANGCHECK_TIMER is not set
-CONFIG_HAS_DMA=y
-CONFIG_HAS_IOMEM=y
-CONFIG_HAS_IOPORT=y
-CONFIG_HAVE_IDE=y
-CONFIG_HAVE_KPROBES=y
-CONFIG_HAVE_KRETPROBES=y
-CONFIG_HAVE_KVM=y
-CONFIG_HAVE_LATENCYTOP_SUPPORT=y
-CONFIG_HAVE_OPROFILE=y
-# CONFIG_HAVE_SETUP_PER_CPU_AREA is not set
-CONFIG_HID=m
-CONFIG_HID_SUPPORT=y
-# CONFIG_HIGHMEM4G is not set
-# CONFIG_HIGHMEM64G is not set
-# CONFIG_HIGH_RES_TIMERS is not set
-# CONFIG_HPET_TIMER is not set
-# CONFIG_HP_WATCHDOG is not set
-CONFIG_HUGETLBFS=y
-CONFIG_HUGETLB_PAGE=y
-CONFIG_HW_RANDOM=y
-# CONFIG_HW_RANDOM_AMD is not set
-# CONFIG_HW_RANDOM_GEODE is not set
-# CONFIG_HW_RANDOM_INTEL is not set
-# CONFIG_HW_RANDOM_VIA is not set
-CONFIG_HZ=250
-# CONFIG_HZ_100 is not set
-CONFIG_HZ_250=y
-CONFIG_I2C=m
-# CONFIG_I2C_ALGOBIT is not set
-CONFIG_I2C_BOARDINFO=y
-# CONFIG_I6300ESB_WDT is not set
-# CONFIG_I8K is not set
-# CONFIG_IB700_WDT is not set
-# CONFIG_IBMASR is not set
-# CONFIG_IBM_ASM is not set
-# CONFIG_IBM_NEW_EMAC_EMAC4 is not set
-# CONFIG_IBM_NEW_EMAC_RGMII is not set
-# CONFIG_IBM_NEW_EMAC_TAH is not set
-# CONFIG_IBM_NEW_EMAC_ZMII is not set
-CONFIG_ICPLUS_PHY=y
-CONFIG_IDE=m
-CONFIG_IDE_ARCH_OBSOLETE_INIT=y
-# CONFIG_IDE_GENERIC is not set
-# CONFIG_IDE_PROC_FS is not set
-CONFIG_INITRAMFS_SOURCE=""
-CONFIG_INPUT=m
-# CONFIG_INPUT_APANEL is not set
-# CONFIG_INPUT_GPIO_BUTTONS is not set
-CONFIG_INPUT_MISC=y
-CONFIG_INPUT_YEALINK=m
-# CONFIG_IOMMU_HELPER is not set
-CONFIG_IOSCHED_CFQ=y
-# CONFIG_IOSCHED_DEADLINE is not set
-CONFIG_IO_DELAY_0X80=y
-# CONFIG_IO_DELAY_0XED is not set
-# CONFIG_IO_DELAY_NONE is not set
-CONFIG_IO_DELAY_TYPE_0X80=0
-CONFIG_IO_DELAY_TYPE_0XED=1
-CONFIG_IO_DELAY_TYPE_NONE=3
-CONFIG_IO_DELAY_TYPE_UDELAY=2
-# CONFIG_IO_DELAY_UDELAY is not set
-# CONFIG_IPWIRELESS is not set
-# CONFIG_ISA is not set
-CONFIG_ISA_DMA_API=y
-# CONFIG_IT8712F_WDT is not set
-# CONFIG_ITCO_WDT is not set
-CONFIG_JFS_FS=m
-CONFIG_KEXEC=y
-CONFIG_KTIME_SCALAR=y
-# CONFIG_KVM is not set
-# CONFIG_LATENCYTOP is not set
-CONFIG_LBD=y
-# CONFIG_LEDS_ALIX is not set
-CONFIG_LEDS_GPIO=y
-# CONFIG_LGUEST is not set
-CONFIG_LSF=y
-CONFIG_LZO_COMPRESS=m
-CONFIG_LZO_DECOMPRESS=m
-# CONFIG_M386 is not set
-CONFIG_M486=y
-# CONFIG_M586 is not set
-# CONFIG_M586MMX is not set
-# CONFIG_M586TSC is not set
-# CONFIG_M686 is not set
-# CONFIG_MACHZ_WDT is not set
-# CONFIG_MACINTOSH_DRIVERS is not set
-CONFIG_MATH_EMULATION=y
-# CONFIG_MCA is not set
-# CONFIG_MCORE2 is not set
-# CONFIG_MCRUSOE is not set
-# CONFIG_MCYRIXIII is not set
-# CONFIG_MDIO_BITBANG is not set
-# CONFIG_MEFFICEON is not set
-# CONFIG_MEMSTICK is not set
-# CONFIG_MGEODEGX1 is not set
-# CONFIG_MGEODE_LX is not set
-# CONFIG_MICROCODE is not set
-# CONFIG_MK6 is not set
-# CONFIG_MK7 is not set
-# CONFIG_MK8 is not set
-CONFIG_MODULE_FORCE_UNLOAD=y
-# CONFIG_MPENTIUM4 is not set
-# CONFIG_MPENTIUMII is not set
-# CONFIG_MPENTIUMIII is not set
-# CONFIG_MPENTIUMM is not set
-# CONFIG_MPSC is not set
-CONFIG_MTD=y
-# CONFIG_MTD_ABSENT is not set
-CONFIG_MTD_BLKDEVS=y
-CONFIG_MTD_BLOCK=y
-# CONFIG_MTD_BLOCK2MTD is not set
-CONFIG_MTD_CFI=y
-# CONFIG_MTD_CFI_ADV_OPTIONS is not set
-CONFIG_MTD_CFI_AMDSTD=y
-CONFIG_MTD_CFI_I1=y
-CONFIG_MTD_CFI_I2=y
-# CONFIG_MTD_CFI_I4 is not set
-# CONFIG_MTD_CFI_I8 is not set
-# CONFIG_MTD_CFI_INTELEXT is not set
-# CONFIG_MTD_CFI_STAA is not set
-CONFIG_MTD_CFI_UTIL=y
-CONFIG_MTD_CHAR=y
-CONFIG_MTD_CMDLINE_PARTS=y
-# CONFIG_MTD_COMPLEX_MAPPINGS is not set
-CONFIG_MTD_CONCAT=y
-# CONFIG_MTD_DEBUG is not set
-# CONFIG_MTD_DOC2000 is not set
-# CONFIG_MTD_DOC2001 is not set
-# CONFIG_MTD_DOC2001PLUS is not set
-CONFIG_MTD_GEN_PROBE=y
-# CONFIG_MTD_JEDECPROBE is not set
-CONFIG_MTD_MAP_BANK_WIDTH_1=y
-# CONFIG_MTD_MAP_BANK_WIDTH_16 is not set
-CONFIG_MTD_MAP_BANK_WIDTH_2=y
-# CONFIG_MTD_MAP_BANK_WIDTH_32 is not set
-CONFIG_MTD_MAP_BANK_WIDTH_4=y
-# CONFIG_MTD_MAP_BANK_WIDTH_8 is not set
-# CONFIG_MTD_MTDRAM is not set
-# CONFIG_MTD_NETSC520 is not set
-# CONFIG_MTD_ONENAND is not set
-CONFIG_MTD_PARTITIONS=y
-# CONFIG_MTD_PHRAM is not set
-# CONFIG_MTD_PHYSMAP is not set
-# CONFIG_MTD_PLATRAM is not set
-# CONFIG_MTD_PMC551 is not set
-# CONFIG_MTD_RAM is not set
-CONFIG_MTD_RDC3210=y
-CONFIG_MTD_RDC3210_ALLOW_JFFS2=y
-CONFIG_MTD_RDC3210_BUSWIDTH=2
-# CONFIG_MTD_RDC3210_FACTORY_PRESENT is not set
-CONFIG_MTD_RDC3210_SIZE=0x400000
-# CONFIG_MTD_RDC3210_STATIC_MAP is not set
-# CONFIG_MTD_REDBOOT_PARTS is not set
-# CONFIG_MTD_ROM is not set
-# CONFIG_MTD_SC520CDP is not set
-# CONFIG_MTD_SLRAM is not set
-# CONFIG_MTD_TS5500 is not set
-# CONFIG_MTRR is not set
-# CONFIG_MVIAC3_2 is not set
-# CONFIG_MVIAC7 is not set
-# CONFIG_MWINCHIP2 is not set
-# CONFIG_MWINCHIP3D is not set
-# CONFIG_MWINCHIPC6 is not set
-# CONFIG_NATSEMI is not set
-# CONFIG_NE2K_PCI is not set
-# CONFIG_NET_VENDOR_3COM is not set
-CONFIG_NLS_ISO8859_2=m
-CONFIG_NOHIGHMEM=y
-# CONFIG_NSC_GPIO is not set
-CONFIG_NVRAM=y
-CONFIG_PAGE_OFFSET=0xC0000000
-# CONFIG_PARAVIRT_GUEST is not set
-CONFIG_PATA_ARTOP=m
-# CONFIG_PATA_CS5536 is not set
-# CONFIG_PC8736x_GPIO is not set
-# CONFIG_PC87413_WDT is not set
-CONFIG_PCCARD=m
-CONFIG_PCCARD_NONSTATIC=m
-CONFIG_PCI=y
-# CONFIG_PCIEPORTBUS is not set
-# CONFIG_PCIPCWATCHDOG is not set
-CONFIG_PCI_BIOS=y
-CONFIG_PCI_DIRECT=y
-CONFIG_PCI_DOMAINS=y
-CONFIG_PCI_GOANY=y
-# CONFIG_PCI_GOBIOS is not set
-# CONFIG_PCI_GODIRECT is not set
-# CONFIG_PCI_GOMMCONFIG is not set
-CONFIG_PCMCIA=m
-CONFIG_PHYLIB=y
-CONFIG_PHYSICAL_ALIGN=0x100000
-CONFIG_PHYSICAL_START=0x100000
-# CONFIG_PROVIDE_OHCI1394_DMA_INIT is not set
-# CONFIG_QSEMI_PHY is not set
-CONFIG_R6040=m
-# CONFIG_REALTEK_PHY is not set
-# CONFIG_RELOCATABLE is not set
-# CONFIG_RTC is not set
-# CONFIG_RWSEM_GENERIC_SPINLOCK is not set
-CONFIG_RWSEM_XCHGADD_ALGORITHM=y
-# CONFIG_SBC7240_WDT is not set
-# CONFIG_SBC8360_WDT is not set
-# CONFIG_SBC_EPX_C3_WATCHDOG is not set
-# CONFIG_SC1200_WDT is not set
-# CONFIG_SC520_WDT is not set
-# CONFIG_SCHED_HRTICK is not set
-CONFIG_SCHED_NO_NO_OMIT_FRAME_POINTER=y
-# CONFIG_SCSI_LOWLEVEL_PCMCIA is not set
-# CONFIG_SCSI_MULTI_LUN is not set
-CONFIG_SCSI_WAIT_SCAN=m
-# CONFIG_SCx200 is not set
-# CONFIG_SCx200_ACB is not set
-CONFIG_SEMAPHORE_SLEEPERS=y
-# CONFIG_SERIAL_8250_EXTENDED is not set
-CONFIG_SLABINFO=y
-# CONFIG_SMP is not set
-# CONFIG_SMSC37B787_WDT is not set
-# CONFIG_SMSC_PHY is not set
-# CONFIG_SND_SIS7019 is not set
-CONFIG_SOFT_WATCHDOG=m
-# CONFIG_SONYPI is not set
-# CONFIG_SPARSEMEM_STATIC is not set
-# CONFIG_SPARSEMEM_VMEMMAP_ENABLE is not set
-CONFIG_SSB_POSSIBLE=y
-CONFIG_SYSVIPC_SYSCTL=y
-# CONFIG_TELCLOCK is not set
-# CONFIG_THERMAL is not set
-# CONFIG_TICK_ONESHOT is not set
-# CONFIG_TOSHIBA is not set
-CONFIG_UID16=y
-CONFIG_USB=m
-# CONFIG_USBPCWATCHDOG is not set
-CONFIG_USB_EHCI_HCD=m
-# CONFIG_USB_OHCI_BIG_ENDIAN_DESC is not set
-# CONFIG_USB_OHCI_BIG_ENDIAN_MMIO is not set
-CONFIG_USB_OHCI_HCD=m
-CONFIG_USB_PWC=m
-# CONFIG_USB_PWC_DEBUG is not set
-# CONFIG_USB_R8A66597_HCD is not set
-# CONFIG_USB_SERIAL_CH341 is not set
-# CONFIG_USB_SERIAL_OTI6858 is not set
-CONFIG_USB_SUPPORT=y
-# CONFIG_USB_UHCI_HCD is not set
-CONFIG_V4L_USB_DRIVERS=y
-# CONFIG_VGASTATE is not set
-# CONFIG_VIA_RHINE is not set
-CONFIG_VIDEO_CAPTURE_DRIVERS=y
-CONFIG_VIDEO_CPIA2=m
-CONFIG_VIDEO_V4L1=y
-CONFIG_VIDEO_V4L2_COMMON=m
-# CONFIG_VIRTIO_BALLOON is not set
-# CONFIG_VIRTIO_PCI is not set
-CONFIG_VIRTUALIZATION=y
-# CONFIG_VM86 is not set
-# CONFIG_VMSPLIT_1G is not set
-# CONFIG_VMSPLIT_2G is not set
-# CONFIG_VMSPLIT_2G_OPT is not set
-CONFIG_VMSPLIT_3G=y
-# CONFIG_VMSPLIT_3G_OPT is not set
-CONFIG_VM_EVENT_COUNTERS=y
-# CONFIG_WAFER_WDT is not set
-CONFIG_X86=y
-CONFIG_X86_32=y
-# CONFIG_X86_64 is not set
-CONFIG_X86_ALIGNMENT_16=y
-# CONFIG_X86_BIGSMP is not set
-CONFIG_X86_BIOS_REBOOT=y
-CONFIG_X86_BSWAP=y
-CONFIG_X86_CMPXCHG=y
-CONFIG_X86_CPUID=y
-# CONFIG_X86_ELAN is not set
-# CONFIG_X86_ES7000 is not set
-CONFIG_X86_F00F_BUG=y
-# CONFIG_X86_GENERIC is not set
-# CONFIG_X86_GENERICARCH is not set
-CONFIG_X86_INVLPG=y
-CONFIG_X86_L1_CACHE_SHIFT=4
-# CONFIG_X86_MCE is not set
-CONFIG_X86_MINIMUM_CPU_FAMILY=4
-CONFIG_X86_MSR=y
-# CONFIG_X86_NUMAQ is not set
-# CONFIG_X86_PAE is not set
-# CONFIG_X86_PC is not set
-CONFIG_X86_POPAD_OK=y
-CONFIG_X86_PPRO_FENCE=y
-CONFIG_X86_RDC321X=y
-CONFIG_X86_REBOOTFIXUPS=y
-# CONFIG_X86_SUMMIT is not set
-# CONFIG_X86_UP_APIC is not set
-# CONFIG_X86_VISWS is not set
-# CONFIG_X86_VOYAGER is not set
-# CONFIG_X86_VSMP is not set
-CONFIG_X86_WP_WORKS_OK=y
-CONFIG_X86_XADD=y
-# CONFIG_ZONE_DMA32 is not set
+++ /dev/null
---- a/drivers/mtd/maps/Kconfig
-+++ b/drivers/mtd/maps/Kconfig
-@@ -110,6 +110,50 @@
- Sun Microsystems boardsets. This driver will require CFI support
- in the kernel, so if you did not enable CFI previously, do that now.
-
-+config MTD_RDC3210
-+ tristate "CFI Flash device mapped on RDC3210"
-+ depends on X86 && MTD_CFI && MTD_PARTITIONS
-+ help
-+ RDC-3210 is the flash device we find on Ralink reference board.
-+
-+config MTD_RDC3210_STATIC_MAP
-+ bool "Partitions on RDC3210 mapped statically" if MTD_RDC3210
-+ select MTD_RDC3210_FACTORY_PRESENT
-+ help
-+ The mapping driver will use the static partition map for the
-+ RDC-3210 flash device.
-+
-+config MTD_RDC3210_FACTORY_PRESENT
-+ bool "Reserve a partition on RDC3210 for factory presets"
-+ depends on MTD_RDC3210
-+ default y
-+ help
-+ The mapping driver will reserve a partition on the RDC-3210 flash
-+ device for resetting flash contents to factory defaults.
-+
-+config MTD_RDC3210_ALLOW_JFFS2
-+ bool "JFFS2 filesystem usable in a partition on RDC3210"
-+ depends on MTD_RDC3210 && !MTD_RDC3210_STATIC_MAP
-+ help
-+ The mapping driver will align a partition on the RDC-3210 flash
-+ device to an erase-block boundary so that a JFFS2 filesystem may
-+ reside on it.
-+
-+config MTD_RDC3210_SIZE
-+ hex "Amount of flash memory on RDC3210"
-+ depends on MTD_RDC3210
-+ default "0x400000"
-+ help
-+ Total size in bytes of the RDC-3210 flash device
-+
-+config MTD_RDC3210_BUSWIDTH
-+ int "Width of CFI Flash device mapped on RDC3210"
-+ depends on MTD_RDC3210
-+ default "2"
-+ help
-+ Number of bytes addressed on the RDC-3210 flash device before
-+ addressing the same chip again
-+
- config MTD_SC520CDP
- tristate "CFI Flash device mapped on AMD SC520 CDP"
- depends on X86 && MTD_CFI && MTD_CONCAT
---- a/drivers/mtd/maps/Makefile
-+++ b/drivers/mtd/maps/Makefile
-@@ -29,6 +29,7 @@
- obj-$(CONFIG_MTD_PMC_MSP_EVM) += pmcmsp-flash.o
- obj-$(CONFIG_MTD_PMC_MSP_RAMROOT)+= pmcmsp-ramroot.o
- obj-$(CONFIG_MTD_PCMCIA) += pcmciamtd.o
-+obj-$(CONFIG_MTD_RDC3210) += rdc3210.o
- obj-$(CONFIG_MTD_RPXLITE) += rpxlite.o
- obj-$(CONFIG_MTD_TQM8XXL) += tqm8xxl.o
- obj-$(CONFIG_MTD_SA1100) += sa1100-flash.o
+++ /dev/null
---- a/init/do_mounts.c
-+++ b/init/do_mounts.c
-@@ -163,6 +163,8 @@
- {
- char *s = page;
-
-+ if (!root_fs_names)
-+ root_fs_names = "squashfs,jffs2";
- if (root_fs_names) {
- strcpy(page, root_fs_names);
- while (*s++) {
+++ /dev/null
---- a/scripts/Makefile.lib
-+++ b/scripts/Makefile.lib
-@@ -172,4 +172,9 @@
- quiet_cmd_gzip = GZIP $@
- cmd_gzip = gzip -f -9 < $< > $@
-
--
-+# LZMA
-+#
-+quiet_cmd_lzma = LZMA $@
-+cmd_lzma = bash -e scripts/lzma_kern $< $@ -lc7 -lp0 -pb0
-+# to use lzmacomp,
-+# cmd_lzma = lzmacomp $< 700 > $@
---- /dev/null
-+++ b/scripts/lzma_kern
-@@ -0,0 +1,4 @@
-+get-size() { echo "$5" ;}
-+printf -v len '%.8x' "$(get-size $(ls -l "$1"))"
-+lzma e "$@"
-+echo -ne "\x$(echo $len | cut -c 7,8)\x$(echo $len | cut -c 5,6)\x$(echo $len | cut -c 3,4)\x$(echo $len | cut -c 1,2)" >> "$2"
---- a/arch/x86/boot/compressed/Makefile
-+++ b/arch/x86/boot/compressed/Makefile
-@@ -4,7 +4,7 @@
- # create a compressed vmlinux image from the original vmlinux
- #
-
--targets := vmlinux vmlinux.bin vmlinux.bin.gz head_$(BITS).o misc.o piggy.o
-+targets := vmlinux vmlinux.bin vmlinux.bin.lzma head_$(BITS).o lzma_misc.o piggy.o
-
- KBUILD_CFLAGS := -m$(BITS) -D__KERNEL__ $(LINUX_INCLUDE) -O2
- KBUILD_CFLAGS += -fno-strict-aliasing -fPIC
-@@ -18,7 +18,7 @@
- LDFLAGS := -m elf_$(UTS_MACHINE)
- LDFLAGS_vmlinux := -T
-
--$(obj)/vmlinux: $(src)/vmlinux_$(BITS).lds $(obj)/head_$(BITS).o $(obj)/misc.o $(obj)/piggy.o FORCE
-+$(obj)/vmlinux: $(src)/vmlinux_$(BITS).lds $(obj)/head_$(BITS).o $(obj)/lzma_misc.o $(obj)/piggy.o FORCE
- $(call if_changed,ld)
- @:
-
-@@ -44,11 +44,11 @@
- $(call if_changed,relocbin)
-
- ifdef CONFIG_RELOCATABLE
--$(obj)/vmlinux.bin.gz: $(obj)/vmlinux.bin.all FORCE
-- $(call if_changed,gzip)
-+$(obj)/vmlinux.bin.lzma: $(obj)/vmlinux.bin.all FORCE
-+ $(call if_changed,lzma)
- else
--$(obj)/vmlinux.bin.gz: $(obj)/vmlinux.bin FORCE
-- $(call if_changed,gzip)
-+$(obj)/vmlinux.bin.lzma: $(obj)/vmlinux.bin FORCE
-+ $(call if_changed,lzma)
- endif
- LDFLAGS_piggy.o := -r --format binary --oformat elf32-i386 -T
-
-@@ -60,5 +60,5 @@
- endif
-
-
--$(obj)/piggy.o: $(obj)/vmlinux.scr $(obj)/vmlinux.bin.gz FORCE
-+$(obj)/piggy.o: $(obj)/vmlinux.scr $(obj)/vmlinux.bin.lzma FORCE
- $(call if_changed,ld)